feat: expand live chat and work server tools
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
import { db } from '../db/client.js';
|
||||
import { chatRuntimeService } from './chat-runtime-service.js';
|
||||
import { parseChatMessageParts, stringifyChatMessageParts, type ChatMessagePart } from './chat-message-parts.js';
|
||||
|
||||
export const CHAT_CONVERSATION_TABLE = 'chat_conversations';
|
||||
export const CHAT_CONVERSATION_MESSAGE_TABLE = 'chat_conversation_messages';
|
||||
@@ -28,6 +29,7 @@ const conversationMessagePayloadSchema = z.object({
|
||||
text: z.string().max(200000),
|
||||
timestamp: z.string().trim().max(40),
|
||||
clientRequestId: z.string().trim().max(120).nullable().optional(),
|
||||
parts: z.array(z.custom<ChatMessagePart>()).optional(),
|
||||
});
|
||||
|
||||
export type ChatConversationItem = {
|
||||
@@ -57,6 +59,7 @@ export type StoredChatMessage = {
|
||||
text: string;
|
||||
timestamp: string;
|
||||
clientRequestId?: string | null;
|
||||
parts?: ChatMessagePart[];
|
||||
};
|
||||
|
||||
export type ChatConversationRequestStatus =
|
||||
@@ -199,6 +202,7 @@ function mapMessageRow(row: Record<string, unknown>): StoredChatMessage {
|
||||
text: String(row.text ?? ''),
|
||||
timestamp: String(row.display_timestamp ?? ''),
|
||||
clientRequestId: row.client_request_id == null ? null : String(row.client_request_id),
|
||||
parts: parseChatMessageParts(row.parts_json),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -800,6 +804,7 @@ export async function ensureChatConversationTables() {
|
||||
table.bigInteger('message_id').notNullable();
|
||||
table.string('author', 20).notNullable();
|
||||
table.text('text').notNullable();
|
||||
table.text('parts_json').notNullable().defaultTo('[]');
|
||||
table.string('display_timestamp', 40).notNullable().defaultTo('');
|
||||
table.string('client_request_id', 120).nullable();
|
||||
table.timestamp('created_at', { useTz: true }).notNullable().defaultTo(db.fn.now());
|
||||
@@ -812,6 +817,7 @@ export async function ensureChatConversationTables() {
|
||||
['message_id', (table) => table.bigInteger('message_id').notNullable()],
|
||||
['author', (table) => table.string('author', 20).notNullable().defaultTo('codex')],
|
||||
['text', (table) => table.text('text').notNullable().defaultTo('')],
|
||||
['parts_json', (table) => table.text('parts_json').notNullable().defaultTo('[]')],
|
||||
['display_timestamp', (table) => table.string('display_timestamp', 40).notNullable().defaultTo('')],
|
||||
['client_request_id', (table) => table.string('client_request_id', 120).nullable()],
|
||||
['created_at', (table) => table.timestamp('created_at', { useTz: true }).notNullable().defaultTo(db.fn.now())],
|
||||
@@ -1608,6 +1614,7 @@ export async function appendChatConversationMessage(
|
||||
message_id: message.messageId,
|
||||
author: message.author,
|
||||
text: message.text,
|
||||
parts_json: stringifyChatMessageParts(message.parts),
|
||||
display_timestamp: message.timestamp,
|
||||
client_request_id: resolvedClientRequestId,
|
||||
created_at: db.fn.now(),
|
||||
@@ -1616,6 +1623,7 @@ export async function appendChatConversationMessage(
|
||||
.merge({
|
||||
author: message.author,
|
||||
text: message.text,
|
||||
parts_json: stringifyChatMessageParts(message.parts),
|
||||
display_timestamp: message.timestamp,
|
||||
client_request_id: resolvedClientRequestId,
|
||||
});
|
||||
@@ -1971,7 +1979,7 @@ export async function repairChatConversationRequestLinks(sessionId?: string | nu
|
||||
.orderBy('request_id', 'asc');
|
||||
const messageRows = await db(CHAT_CONVERSATION_MESSAGE_TABLE)
|
||||
.where({ session_id: currentSessionId })
|
||||
.select('id', 'message_id', 'author', 'text', 'client_request_id', 'created_at')
|
||||
.select('id', 'message_id', 'author', 'text', 'parts_json', 'client_request_id', 'created_at')
|
||||
.orderBy('created_at', 'asc')
|
||||
.orderBy('message_id', 'asc')
|
||||
.orderBy('id', 'asc');
|
||||
|
||||
Reference in New Issue
Block a user