feat(23-01): extend chat service with messageType support and addSystemMessage
- addMessage now accepts optional messageType parameter - addSystemMessage helper inserts system-role messages with typed messageType - Both methods bump conversation updatedAt for correct sort order
This commit is contained in:
parent
1fe00d1798
commit
b2038e1884
1 changed files with 26 additions and 1 deletions
|
|
@ -137,7 +137,7 @@ export function chatService(db: Db) {
|
|||
|
||||
async addMessage(
|
||||
conversationId: string,
|
||||
data: { role: string; content: string; agentId?: string },
|
||||
data: { role: string; content: string; agentId?: string; messageType?: string },
|
||||
) {
|
||||
const [message] = await db
|
||||
.insert(chatMessages)
|
||||
|
|
@ -146,6 +146,7 @@ export function chatService(db: Db) {
|
|||
role: data.role,
|
||||
content: data.content,
|
||||
agentId: data.agentId ?? null,
|
||||
messageType: data.messageType ?? null,
|
||||
})
|
||||
.returning();
|
||||
|
||||
|
|
@ -192,6 +193,30 @@ export function chatService(db: Db) {
|
|||
);
|
||||
},
|
||||
|
||||
async addSystemMessage(
|
||||
conversationId: string,
|
||||
data: { content: string; messageType: string; agentId?: string },
|
||||
) {
|
||||
const [message] = await db
|
||||
.insert(chatMessages)
|
||||
.values({
|
||||
conversationId,
|
||||
role: "system",
|
||||
content: data.content,
|
||||
agentId: data.agentId ?? null,
|
||||
messageType: data.messageType,
|
||||
})
|
||||
.returning();
|
||||
|
||||
// Bump conversation updatedAt (same pattern as addMessage)
|
||||
await db
|
||||
.update(chatConversations)
|
||||
.set({ updatedAt: new Date() })
|
||||
.where(eq(chatConversations.id, conversationId));
|
||||
|
||||
return message!;
|
||||
},
|
||||
|
||||
async *streamEcho(content: string, signal: AbortSignal) {
|
||||
const words = content.split(/\s+/);
|
||||
for (const word of words) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue