feat(ai): support editable message branches

This commit is contained in:
CEQ151 authored and digua committed 2026-05-30 14:19:42 +08:00
1 parent 3a8f61fdf0
commit d3c62c4f9d
26 files changed
+1465 -141

No files matched your search

+3 -1
View File
@@ -32,6 +32,7 @@ export type { AgentStreamChunk }
export interface RunAgentOptions {
userMessage: string
conversationId: string
historyLeafMessageId?: string | null
chatType?: 'group' | 'private'
locale?: string
assistantSystemPrompt?: string
@@ -51,6 +52,7 @@ export async function runServerAgent(options: RunAgentOptions): Promise<void> {
const {
userMessage,
conversationId,
historyLeafMessageId,
chatType = 'group',
locale = 'zh-CN',
assistantSystemPrompt,
@@ -135,7 +137,7 @@ export async function runServerAgent(options: RunAgentOptions): Promise<void> {
let history: SimpleHistoryMessage[] = []
try {
history = convManager.getHistoryForAgent(conversationId)
history = convManager.getHistoryForAgent(conversationId, undefined, historyLeafMessageId)
} catch {
// empty history on failure
}
+28
View File
@@ -521,6 +521,31 @@ export function registerAiRoutes(
return convManager.getMessages(request.params.id)
})
server.post<{
Params: { id: string }
Body: {
content: string
assistantContent: string
contentBlocks?: unknown[]
tokenUsage?: { promptTokens: number; completionTokens: number; totalTokens: number }
}
}>('/_web/ai/messages/:id/branches', async (request) => {
return convManager.createMessageBranch(
request.params.id,
request.body.content,
request.body.assistantContent,
request.body.contentBlocks as any,
request.body.tokenUsage
)
})
server.post<{
Params: { id: string }
Body: { messageId: string }
}>('/_web/ai/conversations/:id/branches/switch', async (request) => {
return convManager.switchMessageBranch(request.params.id, request.body.messageId)
})
server.get<{ Params: { id: string } }>('/_web/ai/conversations/:id/token-usage', async (request) => {
return convManager.getConversationTokenUsage(request.params.id)
})
@@ -533,6 +558,7 @@ export function registerAiRoutes(
Body: {
userMessage: string
conversationId: string
historyLeafMessageId?: string | null
sessionId: string
chatType?: 'group' | 'private'
locale?: string
@@ -550,6 +576,7 @@ export function registerAiRoutes(
const {
userMessage,
conversationId,
historyLeafMessageId,
sessionId,
chatType,
locale,
@@ -660,6 +687,7 @@ export function registerAiRoutes(
await runServerAgent({
userMessage,
conversationId,
historyLeafMessageId,
chatType,
locale,
assistantSystemPrompt,