qoder 0.2.38: a reply names the model-list entry it was sent with (#413)

Qoder and Qoder CN chat replies name the model-list entry the request was
built from (m.name), in JSON and every SSE chunk, usage included. A blank
name, or one equal to the slot key, keeps the requested id. No extra
model-list fetch per request; keys, X-Model-Key and model_config unchanged.

Run at the reviewed head 6f9813f7bb44ea243007c1da2495d69de6be2de9:
- bun test in packages/qoder: 266 pass, 0 fail.
- model-identity.test.mjs against main's index.mjs: 28 of 28 fail; at the
  head they pass.
- Merges cleanly onto main; npm has 0.2.37, this is 0.2.38.

Not tried: a real Qoder account.

Closes #412 once the reporter confirms.
This commit is contained in:
刘巍峰
2026-10-26 22:45:27 +08:00
committed by GitHub
parent 03f5952a8b
commit c25201d259
4 changed files with 124 additions and 5 deletions
+6 -4
View File
@@ -1685,7 +1685,7 @@ async function opened(res, tools) {
return { it, first: await it.next() }
}
async function answer({ it, first }, chat) {
async function answer({ it, first }, chat, servedName = chat.model) {
const id = "chatcmpl-" + hexID()
const created = Math.floor(Date.now() / 1000)
if (first.value?.error) return errorResponse(first.value.error)
@@ -1708,12 +1708,12 @@ async function answer({ it, first }, chat) {
}
if (reasoning) msg.reasoning_content = reasoning
if (calls.length) msg.tool_calls = calls
return Response.json({ id, object: "chat.completion", created, model: chat.model, choices: [{ index: 0, message: msg, finish_reason: stop }], ...(usage ? { usage } : {}) })
return Response.json({ id, object: "chat.completion", created, model: servedName, choices: [{ index: 0, message: msg, finish_reason: stop }], ...(usage ? { usage } : {}) })
}
const enc = new TextEncoder()
const chunk = (delta, finish_reason = null, extra = {}) =>
enc.encode(`data: ${JSON.stringify({ id, object: "chat.completion.chunk", created, model: chat.model, choices: [{ index: 0, delta, finish_reason }], ...extra })}\n\n`)
enc.encode(`data: ${JSON.stringify({ id, object: "chat.completion.chunk", created, model: servedName, choices: [{ index: 0, delta, finish_reason }], ...extra })}\n\n`)
let pending = first
let began = false
const stream = new ReadableStream({
@@ -2555,6 +2555,8 @@ const makePlugin = (site) => async ({ client }) => {
return errorResponse({ status: 502, message: e?.message ?? String(e) })
}
if (!m) return errorResponse({ status: 400, message: `unknown or disabled model "${chat.model}"` })
const name = m.name?.trim()
const servedName = name && name !== m.key ? name : chat.model
const api = siteOf(site, cred).api
const CHAT_URL = api + CHAT_PATH
const task = taskOf(sessionOf(chat, named), chat)
@@ -2582,7 +2584,7 @@ const makePlugin = (site) => async ({ client }) => {
const f = !res.ok ? failure(res.status, (await res.text()).slice(0, 1 << 20)) : open.first.value?.error
// an answered call moves its task on, as Qoder's client moves it
if (!f) task.answered = true
if (!f?.queue || waited >= QUEUE.recoveries) return f && !res.ok ? errorResponse(f) : answer(open, chat)
if (!f?.queue || waited >= QUEUE.recoveries) return f && !res.ok ? errorResponse(f) : answer(open, chat, servedName)
try {
if (!(await queueWait(api, cred, ask, f.queue, init.signal, deadline, siteOf(site, cred)))) return errorResponse(f)
} catch (e) {