Chat: metadata i meldingsqueries, AI-badge med modellnavn, reaksjons-upsert
- Messages API returnerer metadata-felt (ai_action, ai_label, ai_model) - AI-badge i MessageBox viser label og faktisk modellnavn - Reaksjoner: slett eksisterende før insert (én reaksjon per bruker per melding) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a1e6fa1c6b
commit
58646b1543
4 changed files with 15 additions and 6 deletions
|
|
@ -412,8 +412,9 @@
|
|||
{/if}
|
||||
{/if}
|
||||
{#if message.metadata?.ai_action}
|
||||
{@const promptInfo = aiPrompts.find(p => p.action === message.metadata?.ai_action)}
|
||||
<span class="messagebox__ai-badge">{promptInfo?.icon ?? '✨'} {promptInfo?.label ?? message.metadata.ai_action}</span>
|
||||
<span class="messagebox__ai-badge">
|
||||
✨ {message.metadata.ai_label ?? message.metadata.ai_action}{#if message.metadata.ai_model} · {message.metadata.ai_model}{/if}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ export interface MessageData {
|
|||
ai_processing?: boolean;
|
||||
ai_processed?: boolean;
|
||||
ai_action?: string;
|
||||
ai_label?: string;
|
||||
ai_model?: string;
|
||||
} | null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ export const GET: RequestHandler = async ({ params, url, locals }) => {
|
|||
const rows = after
|
||||
? await sql`
|
||||
SELECT m.id, m.channel_id, m.body, m.message_type, m.title,
|
||||
m.pinned, m.visibility, m.created_at, m.updated_at, m.reply_to,
|
||||
m.pinned, m.visibility, m.created_at, m.updated_at, m.reply_to, m.metadata,
|
||||
u.display_name as author_name, u.authentik_id as author_id,
|
||||
(SELECT count(*)::int FROM messages r WHERE r.reply_to = m.id) as reply_count,
|
||||
pm.body as parent_body, pu.display_name as parent_author_name,
|
||||
|
|
@ -44,7 +44,7 @@ export const GET: RequestHandler = async ({ params, url, locals }) => {
|
|||
`
|
||||
: await sql`
|
||||
SELECT m.id, m.channel_id, m.body, m.message_type, m.title,
|
||||
m.pinned, m.visibility, m.created_at, m.updated_at, m.reply_to,
|
||||
m.pinned, m.visibility, m.created_at, m.updated_at, m.reply_to, m.metadata,
|
||||
u.display_name as author_name, u.authentik_id as author_id,
|
||||
(SELECT count(*)::int FROM messages r WHERE r.reply_to = m.id) as reply_count,
|
||||
pm.body as parent_body, pu.display_name as parent_author_name,
|
||||
|
|
@ -117,7 +117,8 @@ export const GET: RequestHandler = async ({ params, url, locals }) => {
|
|||
ends_at: m.cal_ends_at ?? null,
|
||||
all_day: m.cal_all_day ?? false,
|
||||
color: m.cal_color ?? null
|
||||
} : null
|
||||
} : null,
|
||||
metadata: m.metadata ?? null
|
||||
}));
|
||||
|
||||
return json(messages);
|
||||
|
|
|
|||
|
|
@ -30,10 +30,15 @@ export const POST: RequestHandler = async ({ params, request, locals }) => {
|
|||
`;
|
||||
if (!msg) error(404, 'Melding ikke funnet');
|
||||
|
||||
// Fjern eventuell eksisterende reaksjon fra denne brukeren (én reaksjon per bruker per melding)
|
||||
await sql`
|
||||
DELETE FROM message_reactions
|
||||
WHERE message_id = ${messageId} AND user_id = ${userId}
|
||||
`;
|
||||
|
||||
await sql`
|
||||
INSERT INTO message_reactions (message_id, user_id, reaction)
|
||||
VALUES (${messageId}, ${userId}, ${reaction})
|
||||
ON CONFLICT DO NOTHING
|
||||
`;
|
||||
|
||||
const reactions = await getReactions(messageId, userId);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue