mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-26 02:04:37 +08:00
feat(server,web): connect compression config through SSE stream
- Add compressionConfig to SSE agent/stream request body with sensible defaults - Pass compressionConfig from route handler to runServerAgent - Update frontend runStream to forward compressionConfig to the SSE endpoint
This commit is contained in:
1 parent
245a2e39a0
commit
4b1a1e411b
2 files changed
+18
-1
No files matched your search
@@ -379,9 +379,15 @@ export function registerAiRoutes(
|
||||
chatType?: 'group' | 'private'
|
||||
locale?: string
|
||||
assistantId?: string
|
||||
compressionConfig?: {
|
||||
enabled: boolean
|
||||
tokenThresholdPercent?: number
|
||||
bufferSizePercent?: number
|
||||
maxToolResultPercent?: number
|
||||
}
|
||||
}
|
||||
}>('/_web/ai/agent/stream', async (request, reply) => {
|
||||
const { userMessage, conversationId, sessionId, chatType, locale, assistantId } = request.body
|
||||
const { userMessage, conversationId, sessionId, chatType, locale, assistantId, compressionConfig } = request.body
|
||||
|
||||
const requestId = `req_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`
|
||||
const abortController = new AbortController()
|
||||
@@ -450,6 +456,15 @@ export function registerAiRoutes(
|
||||
})
|
||||
|
||||
try {
|
||||
const resolvedCompression = compressionConfig?.enabled
|
||||
? {
|
||||
enabled: true as const,
|
||||
tokenThresholdPercent: compressionConfig.tokenThresholdPercent ?? 75,
|
||||
bufferSizePercent: compressionConfig.bufferSizePercent ?? 20,
|
||||
maxToolResultPercent: compressionConfig.maxToolResultPercent,
|
||||
}
|
||||
: undefined
|
||||
|
||||
await runServerAgent({
|
||||
userMessage,
|
||||
conversationId,
|
||||
@@ -457,6 +472,7 @@ export function registerAiRoutes(
|
||||
locale,
|
||||
assistantSystemPrompt,
|
||||
skillMenu,
|
||||
compressionConfig: resolvedCompression,
|
||||
tools: agentTools,
|
||||
aiDataDir,
|
||||
convManager,
|
||||
|
||||
@@ -264,6 +264,7 @@ async function installAiApiShims(): Promise<void> {
|
||||
chatType: chatType || 'group',
|
||||
locale: locale || 'zh-CN',
|
||||
assistantId,
|
||||
compressionConfig: _compressionConfig,
|
||||
},
|
||||
signal: abortController.signal,
|
||||
onEvent: ({ event, data }) => {
|
||||
|
||||
Reference in new issue
Block a user