From 33ad9cd568c4c4e840c4c0239796674ee5260388 Mon Sep 17 00:00:00 2001 From: DoSun Date: Thu, 7 May 2026 20:29:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20prompt=20=E8=B7=AF=E7=94=B1=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20parts=20=E6=A0=BC=E5=BC=8F=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 消费端发送 parts 数组格式([{type:'text', text:'...'}]), csc 同时支持 content 字符串和 parts 数组两种格式 --- src/server/routes/session.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/server/routes/session.ts b/src/server/routes/session.ts index 7a052b9c5..4c2a2e5c2 100644 --- a/src/server/routes/session.ts +++ b/src/server/routes/session.ts @@ -213,14 +213,19 @@ export function createSessionRoutes( if (!handle) throw notFound('session not found') const body = await c.req.json<{ - content: string + content?: string + parts?: Array<{ type: string; text?: string }> files?: string[] images?: unknown[] }>() - if (!body.content) throw badRequest('content is required') + const content = body.content ?? body.parts + ?.filter((p) => p.type === 'text' && p.text) + .map((p) => p.text) + .join('\n') ?? '' + if (!content) throw badRequest('content is required') if (handle.prompting) throw conflict('session is already processing a prompt') - return ssePrompt(handle, id, body.content, c) + return ssePrompt(handle, id, content, c) }) .post('/session/:sessionID/prompt_async', async c => { const id = c.req.param('sessionID') @@ -228,15 +233,20 @@ export function createSessionRoutes( if (!handle) throw notFound('session not found') const body = await c.req.json<{ - content: string + content?: string + parts?: Array<{ type: string; text?: string }> files?: string[] images?: unknown[] }>() - if (!body.content) throw badRequest('content is required') + const content = body.content ?? body.parts + ?.filter((p) => p.type === 'text' && p.text) + .map((p) => p.text) + .join('\n') ?? '' + if (!content) throw badRequest('content is required') if (handle.prompting) throw conflict('session is already processing a prompt') - handle.prompt(body.content).catch(() => {}) + handle.prompt(content).catch(() => {}) return new Response(null, { status: 204 }) })