fix(ai): handle model output truncation

This commit is contained in:
digua committed 2026-09-18 10:53:06 +08:00
1 parent 02b75f8532
commit 1388aaccf7
13 files changed
+229 -11

No files matched your search

+6 -2
View File
@@ -253,6 +253,8 @@ export async function runServerAgent(options: RunAgentOptions): Promise<void> {
maxToolRounds: DEFAULT_MAX_TOOL_ROUNDS,
abortSignal,
providerSessionId: aiChatId,
locale,
logger: aiLogger ?? undefined,
steerMessage,
thinkingLevel: thinkingLevel as import('@openchatlab/core').ThinkingLevel | undefined,
onConvertToLlm: (filteredMessages) => {
@@ -268,12 +270,14 @@ export async function runServerAgent(options: RunAgentOptions): Promise<void> {
},
})
if (result.error) {
if (result.error && !abortSignal?.aborted) {
const friendlyMessage = formatAIError(result.error)
onEvent({ type: 'error', error: { name: 'AgentError', message: friendlyMessage } })
}
handler.emitStatus('completed', cachedMessages, { force: true })
handler.emitStatus(abortSignal?.aborted ? 'aborted' : result.error ? 'error' : 'completed', cachedMessages, {
force: true,
})
onEvent({ type: 'done', isFinished: true, usage: result.usage })
} catch (error) {
const friendlyMessage = formatAIError(error)