@magpie-community/opencode-qoder-auth 0.2.53 → 0.2.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +12 -0
  2. package/index.mjs +39 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -209,6 +209,18 @@ name remain independently selectable. The name describes the catalog
209
209
  entry used for the request, not an attestation of the backend that
210
210
  executed it.
211
211
 
212
+ A request's `model_config` is built as Qoder's own client builds it
213
+ (Qoder CN's CLI 1.1.81, desktop 0.4.3), not sent as the listing entry
214
+ (since 0.2.54): `key`, `display_name`, an empty `model`, `format`,
215
+ `is_vl`, `is_reasoning` (off when thinking is turned off), empty
216
+ `api_key` and `url`, `source` and `max_input_tokens`. The entry's
217
+ `minimal_version`, `strategies`, prices and `thinking_config` are not
218
+ sent. While the whole entry was sent, Qoder CN billed DeepSeek-Flash
219
+ (`dfmodel`, whose entry has a `minimal_version`) as Auto at Auto's rate
220
+ (plugins#638); that the entry was the cause has not been confirmed on a
221
+ Qoder CN account. A model whose entry has no key of its own, or whose key is
222
+ `auto`, is refused with a 400 and nothing is sent, never served as Auto.
223
+
212
224
  The `provider.models` hook reads the account's own list, as Qoder's client
213
225
  asks for it (`/algo/api/v2/model/list`). It keeps the enabled models of the
214
226
  listing's `app` scene, the list Qoder's app shows and the one a request
package/index.mjs CHANGED
@@ -1224,6 +1224,38 @@ function typedUnions(schema) {
1224
1224
  return root
1225
1225
  }
1226
1226
 
1227
+ // modelConfig is the model_config a request carries for model m, built as
1228
+ // Qoder's own client builds it (Qoder CN's CLI 1.1.81 and desktop 0.4.3,
1229
+ // the qoder-agent-sdk worker's model resolution): the listing entry's key,
1230
+ // name, format, image and reasoning flags, source and input size, with an
1231
+ // empty model, api_key and url, and is_reasoning off when thinking is.
1232
+ // Never the listing entry as it came: that also holds minimal_version,
1233
+ // strategies, prices and thinking_config, which no client sends. While it
1234
+ // was sent whole, Qoder CN billed DeepSeek-Flash (dfmodel, whose entry
1235
+ // carries a minimal_version) as Auto at Auto's rate, and Kimi-K3.1-Pro
1236
+ // (none) as itself (magpie-community/plugins#638, square-235); the entry
1237
+ // is the likely cause, not confirmed on a Qoder CN account.
1238
+ // A model with no key of its own is refused: Qoder's worker sends a
1239
+ // request with none as "auto", which is never what was asked for.
1240
+ function modelConfig(m, thinking) {
1241
+ const raw = m.config ?? {}
1242
+ const key = String(raw.key ?? m.key ?? "").trim()
1243
+ if (!key || ["auto", "default"].includes(key) || key !== m.key) throw new Error(`no Qoder model key for "${m.key ?? ""}"`)
1244
+ const max = Number.isInteger(raw.max_input_tokens) && raw.max_input_tokens > 0 ? raw.max_input_tokens : 200_000
1245
+ return {
1246
+ key,
1247
+ display_name: raw.display_name || key,
1248
+ ...(raw.outer_provider ? { outer_provider: raw.outer_provider } : { model: "" }),
1249
+ format: raw.format ?? "openai",
1250
+ is_vl: !!raw.is_vl,
1251
+ is_reasoning: !!raw.is_reasoning && thinking,
1252
+ api_key: "",
1253
+ url: "",
1254
+ source: raw.source || "system",
1255
+ max_input_tokens: max,
1256
+ }
1257
+ }
1258
+
1227
1259
  // qoderBody is the plaintext agent_chat_generation takes for a chat
1228
1260
  // completion request, for model m, in the session the agent named (named,
1229
1261
  // "" when none) and the task it is a call of (taskOf's, a new one when
@@ -1254,7 +1286,7 @@ function qoderBody(chat, m, named = "", task, site) {
1254
1286
  agent_id: "agent_common",
1255
1287
  task_id: "common",
1256
1288
  session_type: site?.sessionType ?? "app",
1257
- model_config: m.config,
1289
+ model_config: modelConfig(m, thinking),
1258
1290
  system: [sys],
1259
1291
  messages: [{ role: "system", content: [sys] }, ...cacheMarked(qoderMessages(chat.messages ?? []))],
1260
1292
  }
@@ -3058,7 +3090,12 @@ const makePlugin = (site) => async ({ client }) => {
3058
3090
  const api = siteOf(site, cred).api
3059
3091
  const CHAT_URL = api + CHAT_PATH
3060
3092
  const task = taskOf(sessionOf(chat, named), chat)
3061
- const body = qoderBody(chat, m, named, task, siteOf(site, cred))
3093
+ let body
3094
+ try {
3095
+ body = qoderBody(chat, m, named, task, siteOf(site, cred))
3096
+ } catch (e) {
3097
+ return errorResponse({ status: 400, message: e?.message ?? String(e) })
3098
+ }
3062
3099
  // Qoder's queue is waited out (queueWait) and the request sent again
3063
3100
  // under the request_set_id the queue knows, with a new request_id and
3064
3101
  // chat_record_id, as Qoder's client sends it (its o4i before each
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-qoder-auth",
3
- "version": "0.2.53",
3
+ "version": "0.2.54",
4
4
  "description": "Qoder and QwenWork (千问办公) subscriptions in OpenCode and magpie: qoder.com, qoder.cn, gateway.qwenwork.cn and the enterprise flagship, VPC and dedicated domains",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",