fix: remove debug logs, add model fallback, fix prompt_async flow
- Remove process.stderr.write debug logs from sessionHandle and prompt_async - Add model fallback in assistant message (use this._model if msg.model missing) - Add model field to user message emit for adapter consumption - Wait for session ready before setModel/prompt in prompt_async - Return 200 JSON instead of 204 No Content from prompt_async - Set Bun.serve idleTimeout to 255s to prevent connection drops
This commit is contained in:
parent
d7a65170cd
commit
880782b1dd
|
|
@ -365,8 +365,11 @@ export function createSessionRoutes(
|
|||
})
|
||||
.post('/session/:sessionID/prompt_async', async c => {
|
||||
const id = c.req.param('sessionID')
|
||||
|
||||
const handle = sessionManager.getSession(id)
|
||||
if (!handle) throw notFound('session not found')
|
||||
if (!handle) {
|
||||
throw notFound('session not found')
|
||||
}
|
||||
|
||||
const body = await c.req.json<{
|
||||
content?: string
|
||||
|
|
@ -380,17 +383,26 @@ export function createSessionRoutes(
|
|||
?.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')
|
||||
if (!content) {
|
||||
throw badRequest('content is required')
|
||||
}
|
||||
if (handle.prompting) {
|
||||
throw conflict('session is already processing a prompt')
|
||||
}
|
||||
|
||||
void (async () => {
|
||||
if (body.model?.modelID) {
|
||||
try { await handle.setModel(body.model.modelID) } catch {}
|
||||
}
|
||||
handle.prompt(content).catch(() => {})
|
||||
try {
|
||||
if (handle.status !== 'running') {
|
||||
await handle.waitReady()
|
||||
}
|
||||
if (body.model?.modelID) {
|
||||
try { await handle.setModel(body.model.modelID) } catch {}
|
||||
}
|
||||
handle.prompt(content).catch(() => {})
|
||||
} catch {}
|
||||
})()
|
||||
|
||||
return new Response(null, { status: 204 })
|
||||
return c.json({ ok: true }, 200)
|
||||
})
|
||||
.post('/session/:sessionID/abort', async c => {
|
||||
const id = c.req.param('sessionID')
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ export function startServer(
|
|||
hostname: config.host,
|
||||
port: config.port,
|
||||
fetch: app.fetch,
|
||||
idleTimeout: 255,
|
||||
})
|
||||
|
||||
return server
|
||||
|
|
|
|||
|
|
@ -451,6 +451,9 @@ export class SessionHandle {
|
|||
if (msg.uuid && typeof msg.uuid === 'string') {
|
||||
this._lastMessageUuid = msg.uuid
|
||||
}
|
||||
if (!msg.model && this._model) {
|
||||
msg = { ...msg, model: this._model }
|
||||
}
|
||||
this.emitEvent('message', msg)
|
||||
break
|
||||
}
|
||||
|
|
@ -602,6 +605,7 @@ export class SessionHandle {
|
|||
type: 'user',
|
||||
content,
|
||||
session_id: this.sessionId,
|
||||
model: this._model ?? '',
|
||||
})
|
||||
|
||||
this.writeStdin(userMsg)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user