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
dac6501aab
commit
2a0c5769f3
1 changed files with 26 additions and 1 deletions
|
|
@ -137,7 +137,7 @@ export function chatService(db: Db) {
|
||||||
|
|
||||||
async addMessage(
|
async addMessage(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
data: { role: string; content: string; agentId?: string },
|
data: { role: string; content: string; agentId?: string; messageType?: string },
|
||||||
) {
|
) {
|
||||||
const [message] = await db
|
const [message] = await db
|
||||||
.insert(chatMessages)
|
.insert(chatMessages)
|
||||||
|
|
@ -146,6 +146,7 @@ export function chatService(db: Db) {
|
||||||
role: data.role,
|
role: data.role,
|
||||||
content: data.content,
|
content: data.content,
|
||||||
agentId: data.agentId ?? null,
|
agentId: data.agentId ?? null,
|
||||||
|
messageType: data.messageType ?? null,
|
||||||
})
|
})
|
||||||
.returning();
|
.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) {
|
async *streamEcho(content: string, signal: AbortSignal) {
|
||||||
const words = content.split(/\s+/);
|
const words = content.split(/\s+/);
|
||||||
for (const word of words) {
|
for (const word of words) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue