fix: prompt 路由支持 parts 格式请求体

消费端发送 parts 数组格式([{type:'text', text:'...'}]),
csc 同时支持 content 字符串和 parts 数组两种格式
This commit is contained in:
DoSun 2026-05-07 20:29:49 +08:00
parent d5cfe0aff0
commit 33ad9cd568

View File

@ -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 })
})