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

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 +43 -0
  2. package/index.mjs +164 -2
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -83,6 +83,12 @@ Refreshing:
83
83
  full, the listing can have only the free models on (#484). The same
84
84
  5-minute rule holds, and an id Qoder has never served is said unknown at
85
85
  once, with no renewal.
86
+ - The account's model list (what magpie and its agents see) is read the
87
+ same way (since 0.2.52): a listing with every model that costs credits
88
+ off and the free ones on, which is what Qoder CN answers a caller it
89
+ doesn't take for the account, renews the job token once and is read
90
+ again. A renewed token that still lists only the free models isn't
91
+ renewed again for the list.
86
92
  - The device token, which reads usage, has no end on record: it is rotated
87
93
  when Qoder refuses it. On a [Qoder CN](#qoder-cn) device-token account it
88
94
  is the chat token too, and is renewed as above.
@@ -309,6 +315,43 @@ paths, client id and protocol are the public ones:
309
315
  The hosts and reply shapes come from a real VPC account's report
310
316
  (yetone/magpie#312). This plugin has not been tried with a VPC account.
311
317
 
318
+ ### Enterprise dedicated domain (企业版专属域)
319
+
320
+ An enterprise whose Qoder IDE signs in through 「企业版专属域登录」 with a
321
+ domain of its own (any https host, such as `your-corp.rdc.aliyuncs.com`)
322
+ signs in with **Sign in with Qoder CN Enterprise dedicated domain
323
+ (企业版专属域)** (since 0.2.53). It asks for the domain as it is set in
324
+ Qoder IDE's settings: a host or an https address (a path is dropped).
325
+
326
+ It follows Qoder IDE 1.38.0's own rules for that setting:
327
+
328
+ - It first asks `GET <domain>/algo/api/v1/version`. A 404 means a legacy
329
+ Lingma 1.0 (通义灵码) dedicated domain. Its sign-in goes through another
330
+ protocol, which this plugin doesn't have yet, so the sign-in stops and
331
+ says so. Any other answer means Qoder CN 2.0. A domain that doesn't answer
332
+ is refused.
333
+ - A Qoder CN 2.0 domain uses the VPC protocol on hosts named the IDE's way:
334
+ `-openapi` or `-gateway` after the host's first label. An IP or a host
335
+ with no dot keeps its own origin. The sign-in uses the IDE's client id and
336
+ no `redirect_uri`.
337
+
338
+ | | Dedicated domain `your-corp.rdc.aliyuncs.com` |
339
+ |---|---|
340
+ | Sign-in page | your-corp.rdc.aliyuncs.com/device/selectAccounts |
341
+ | Accounts: poll, tokens, user info, usage | your-corp-openapi.rdc.aliyuncs.com |
342
+ | Models and chat | your-corp-gateway.rdc.aliyuncs.com |
343
+
344
+ - Models and chat use the gateway host when it answers at sign-in.
345
+ Otherwise they use the domain itself, which answered the probe on the
346
+ same `/algo` path. The IDE's language server makes this choice, and its
347
+ rule wasn't read, so this part is inferred.
348
+ - The domain is kept with the account, which is named
349
+ `<email> (<domain>)`. An account whose kept domain isn't one is asked to
350
+ sign in again; it is never sent to the public hosts.
351
+
352
+ The rules come from Qoder IDE's code. This plugin has not been tried with a
353
+ dedicated account.
354
+
312
355
  ## The card's name
313
356
 
314
357
  An account signed in with a phone is shown by that phone — masked, `138****8000` — not by
package/index.mjs CHANGED
@@ -315,6 +315,104 @@ function vpcSite(site, instance) {
315
315
  return { ...site, web: `https://${name}.${d}`, openapi: `https://${name}-openapi.${d}`, api: `https://${name}-gateway.${d}`, vpc: name }
316
316
  }
317
317
 
318
+ // ---- enterprise dedicated domain (Qoder CN 企业版专属域) ----------------------
319
+ //
320
+ // Qoder IDE (1.38.0) signs in to an enterprise's dedicated domain from its
321
+ // config.general.dedicatedUrl (Settings, 「企业版专属域登录」), any https host
322
+ // such as <corp>.rdc.aliyuncs.com, not only <instance>.vpc.qoder.com.cn. It
323
+ // first asks GET <domain>/algo/api/v1/version: a 404 is a legacy Lingma 1.0
324
+ // (通义灵码) dedicated domain, signed in to through another protocol; any
325
+ // other status is Qoder CN 2.0, signed in to with the same device flow as
326
+ // qoder.cn: /device/selectAccounts on the domain's origin, and the poll and
327
+ // user info on an openapi host named by putting "-openapi" after the host's
328
+ // first label (foo.rdc.aliyuncs.com → foo-openapi.rdc.aliyuncs.com; its
329
+ // gateway host is the same with "-gateway"). An IP, a bracketed IPv6 host or
330
+ // a host with no dot keeps its origin. The workbench's client id there is
331
+ // the IDE's production one.
332
+ const DEDICATED_CLIENT = "f5a7f67c-11a8-491e-8b8e-a07f2d0df4b7"
333
+ const DEDICATED_VERSION = "/algo/api/v1/version"
334
+
335
+ // dedicatedOrigin is the https origin of what the user entered as their
336
+ // dedicated domain: a host or an https:// address, a path dropped as the
337
+ // IDE drops it for sign-in. undefined: not one (http://, credentials, no host).
338
+ function dedicatedOrigin(input) {
339
+ let e = String(input ?? "").trim()
340
+ if (!e) return undefined
341
+ if (!/^[a-z][a-z\d+.-]*:\/\//i.test(e)) e = `https://${e}`
342
+ let u
343
+ try {
344
+ u = new URL(e)
345
+ } catch {
346
+ return undefined
347
+ }
348
+ if (u.protocol !== "https:" || u.username || u.password || !u.hostname) return undefined
349
+ return u.origin
350
+ }
351
+
352
+ // dedicatedHost is origin's host with suffix after its first label, as the
353
+ // IDE's helper names a dedicated domain's openapi and gateway hosts; origin
354
+ // itself for an IP, an IPv6 host or a host with no dot.
355
+ function dedicatedHost(origin, suffix) {
356
+ const u = new URL(origin)
357
+ const h = u.hostname
358
+ if (!h || (h.startsWith("[") && h.endsWith("]")) || h.includes(":") || /^\d{1,3}(\.\d{1,3}){3}$/.test(h)) return origin
359
+ const i = h.indexOf(".")
360
+ if (i <= 0 || i === h.length - 1) return origin
361
+ const host = `${h.slice(0, i)}${suffix}.${h.slice(i + 1)}`
362
+ return `${u.protocol}//${u.port ? `${host}:${u.port}` : host}`
363
+ }
364
+
365
+ // dedicatedSite is site served from a dedicated domain (its host, as kept on
366
+ // the account), with api its chat host when the sign-in found the gateway
367
+ // host unreachable and chose the domain's own origin; undefined: not one.
368
+ function dedicatedSite(site, domain, api) {
369
+ const origin = dedicatedOrigin(domain)
370
+ if (!origin) return undefined
371
+ const host = new URL(origin).host
372
+ return {
373
+ ...site,
374
+ web: origin,
375
+ openapi: dedicatedHost(origin, "-openapi"),
376
+ api: api ? dedicatedOrigin(api) ?? dedicatedHost(origin, "-gateway") : dedicatedHost(origin, "-gateway"),
377
+ clientId: DEDICATED_CLIENT,
378
+ redirect: "",
379
+ vpc: host,
380
+ dedicated: host,
381
+ }
382
+ }
383
+
384
+ // dedicatedProbe is the status GET <origin>/algo/api/v1/version answers, as
385
+ // the IDE's probe asks it; undefined when nothing answered.
386
+ async function dedicatedProbe(origin) {
387
+ try {
388
+ const r = await fetch(origin + DEDICATED_VERSION, { headers: { "User-Agent": "Qoder" }, signal: AbortSignal.timeout(10_000) })
389
+ await r.body?.cancel().catch(() => {})
390
+ return r.status
391
+ } catch {
392
+ return undefined
393
+ }
394
+ }
395
+
396
+ // dedicatedSignIn reads the domain as the IDE does and starts its device
397
+ // sign-in. A legacy Lingma domain is refused with what it is: its sign-in
398
+ // (cosy's login/generateUrl, a qoder-cn-ide:// callback) isn't served here.
399
+ // The chat host is the gateway host when it answers at all, else the
400
+ // domain's own origin, which answered the probe on the same /algo path; the
401
+ // IDE leaves this to its language server, whose rule wasn't read (inferred).
402
+ async function dedicatedSignIn(site, input) {
403
+ const origin = dedicatedOrigin(input)
404
+ if (!origin) throw new Error(`Not a dedicated domain: ${String(input ?? "").slice(0, 100)}`)
405
+ const status = await dedicatedProbe(origin)
406
+ if (status === undefined) throw new Error(`${site.name}: ${origin} didn't answer (${DEDICATED_VERSION}); check the address and your network`)
407
+ if (status === 404)
408
+ throw new Error(
409
+ `${site.name}: ${origin} is a Lingma 1.0 (通义灵码) dedicated domain, which this plugin can't sign in to yet; ${new URL(origin).host} answers 404 at ${DEDICATED_VERSION}, as Qoder IDE tells one apart`,
410
+ )
411
+ const gateway = dedicatedHost(origin, "-gateway")
412
+ const api = gateway !== origin && (await dedicatedProbe(gateway)) === undefined ? origin : undefined
413
+ return deviceSignIn(dedicatedSite(site, origin, api))
414
+ }
415
+
318
416
  // siteOf is the site an account is served from: its VPC instance's when it
319
417
  // was signed in to one, else site. An instance on record that names none
320
418
  // is not read as "no VPC", which would send the enterprise's tokens to the
@@ -327,6 +425,11 @@ function siteOf(site, a) {
327
425
  const base = `https://${a.enterpriseHost}`
328
426
  return { ...site, web: base, openapi: base, api: base, vpc: a.enterpriseHost }
329
427
  }
428
+ if (a?.dedicated) {
429
+ const s = dedicatedSite(site, a.dedicated, a.dedicatedApi)
430
+ if (!s) throw new SignInGone(`${site.name}: the account's dedicated domain "${a.dedicated}" isn't one; sign in again`)
431
+ return s
432
+ }
330
433
  if (a?.vpc === undefined || a?.vpc === null || a?.vpc === "") return site
331
434
  const s = vpcSite(site, a.vpc)
332
435
  if (!s) throw new SignInGone(`${site.name}: the account's VPC instance "${a.vpc}" isn't one; sign in again`)
@@ -418,6 +521,7 @@ async function deviceSignIn(site) {
418
521
  deviceRefresh: dt.refresh_token ?? "",
419
522
  ...(site.vpc ? { vpc: site.vpc } : {}),
420
523
  ...(site.enterpriseDomain ? { vpc: site.enterpriseDomain, enterpriseHost: site.enterpriseDomain } : {}),
524
+ ...(site.dedicated ? { dedicated: site.dedicated, ...(site.api !== dedicatedHost(site.web, "-gateway") ? { dedicatedApi: site.api } : {}) } : {}),
421
525
  }
422
526
  },
423
527
  }
@@ -681,6 +785,23 @@ function sceneModels(listing) {
681
785
  // and "default" route inside Qoder and aren't one model. A site with its
682
786
  // own scene reads that scene's list; one that lists all models keeps the
683
787
  // disabled ones too (QwenWork's qwork scene carries its whole catalog).
788
+ // freeView is whether a listing is the one Qoder gives a caller it doesn't
789
+ // take for the account: every model that costs credits off, the free ones
790
+ // on. Qoder CN's gateway answers a caller it doesn't know with that list
791
+ // (2026-11-01: Qwen3.8-Flash on, Auto, Fast, Qwen3.8-Max, DeepSeek, GLM,
792
+ // Kimi and MiniMax off, in every scene), and an enterprise qoder.com
793
+ // account's stale job token was answered the same (plugins#484). A listing
794
+ // with no model that costs credits, or with one of them on, isn't it.
795
+ function freeView(entries) {
796
+ let off = false
797
+ for (const m of entries) {
798
+ if (!m || ["", "auto", "default"].includes(String(m.key ?? "").trim()) || freeOf(m)) continue
799
+ if (m.enable) return false
800
+ off = true
801
+ }
802
+ return off
803
+ }
804
+
684
805
  function modelInfos(listing, site) {
685
806
  if (site?.modelScene) {
686
807
  return (Array.isArray(listing?.[site.modelScene]) ? listing[site.modelScene] : [])
@@ -2653,6 +2774,8 @@ const makePlugin = (site) => async ({ client }) => {
2653
2774
  // the ids Qoder serves: the site's shipped list and every key a listing
2654
2775
  // has named, on or off
2655
2776
  const served = new Set(site.models.map((m) => m.id))
2777
+ // the job tokens a renewal gave that Qoder still listed the free view for
2778
+ const stillFree = new Set()
2656
2779
  const knows = (id) => served.has(id)
2657
2780
  const models = async (cred, again = false) => {
2658
2781
  const key = listingKey(cred)
@@ -2665,6 +2788,7 @@ const makePlugin = (site) => async ({ client }) => {
2665
2788
  if (k) served.add(k)
2666
2789
  }
2667
2790
  l = modelInfos(listing, s)
2791
+ if (!s.modelScene) l.freeView = freeView(sceneModels(listing))
2668
2792
  listings.set(key, l)
2669
2793
  }
2670
2794
  return l
@@ -3147,6 +3271,22 @@ const makePlugin = (site) => async ({ client }) => {
3147
3271
  return deviceSignIn(s)
3148
3272
  },
3149
3273
  },
3274
+ // an enterprise dedicated domain (企业版专属域), as Qoder IDE's
3275
+ // settings take one: any https host, e.g. <corp>.rdc.aliyuncs.com
3276
+ {
3277
+ type: "oauth",
3278
+ label: `Sign in with ${site.name} Enterprise dedicated domain (企业版专属域)`,
3279
+ prompts: [
3280
+ {
3281
+ type: "text",
3282
+ key: "dedicated",
3283
+ message: "Your enterprise's dedicated domain, as set in Qoder IDE (企业版专属域地址)",
3284
+ placeholder: "your-corp.rdc.aliyuncs.com or https://your-corp.rdc.aliyuncs.com",
3285
+ validate: (v) => (dedicatedOrigin(v) ? undefined : "Not a dedicated domain: enter its host or https:// address"),
3286
+ },
3287
+ ],
3288
+ authorize: (inputs) => dedicatedSignIn(site, inputs?.dedicated),
3289
+ },
3150
3290
  ]
3151
3291
  : []),
3152
3292
  ],
@@ -3183,7 +3323,29 @@ const makePlugin = (site) => async ({ client }) => {
3183
3323
  }
3184
3324
  if (renewals.has(cred)) unsaid.add(listingKey(cred))
3185
3325
  try {
3186
- const ms = await models(cred, true)
3326
+ let ms = await models(cred, true)
3327
+ // The free view (freeView) on a job token is what Qoder lists for
3328
+ // a token it no longer takes in full: the token is renewed once,
3329
+ // as a chat for a model the list has off renews it (plugins#484),
3330
+ // and the list read again. Without it the account's list is the
3331
+ // free model alone, and magpie's agents see only that one (Qoder
3332
+ // CN, star21321321124_93024 on Discord, 2026-11-01). A token the
3333
+ // free view came back on after a renewal is not renewed again for
3334
+ // it: that account lists only the free models.
3335
+ if (ms.freeView && !stillFree.has(cred.access)) {
3336
+ let next
3337
+ try {
3338
+ next = await relogin(async () => auth, cred.access)
3339
+ } catch (e) {
3340
+ if (e?.expired) throw Object.assign(new Error(e.message), { signIn: "expired" })
3341
+ }
3342
+ if (next && next.access !== cred.access) {
3343
+ if (renewals.has(next)) unsaid.add(listingKey(next))
3344
+ cred = next
3345
+ ms = await models(cred, true)
3346
+ if (ms.freeView) stillFree.add(cred.access)
3347
+ }
3348
+ }
3187
3349
  if (!ms.length) return provider.models
3188
3350
  const s = siteOf(site, cred)
3189
3351
  return Object.fromEntries(
@@ -3260,4 +3422,4 @@ export async function QwenWorkEnterpriseAuthPlugin({ client }) {
3260
3422
  export const protocol = { makePlugin, deviceSignIn, openapi, siteOf }
3261
3423
 
3262
3424
  // for tests
3263
- export const _internal = { maskPhone, phoneLabelOf, realEmailOf, chatHeaders, machineOS, machineHostname, cosyHeaders, typedUnions, Splitter, campaignRuntime, RUNTIMES, campaignPage, campaignTarget, vpcInstance, vpcSite, parseUsage, gfmt, when, failure, modelInfo, qoderBody, qoderMessages, cacheMarked, sessionOf, namedSession, taskOf, TASKS, TASK_MAX, TASK_IDLE, SESSION, SITES, decodeBody, events, QUEUE, queueState }
3425
+ export const _internal = { freeView, maskPhone, phoneLabelOf, realEmailOf, chatHeaders, machineOS, machineHostname, cosyHeaders, typedUnions, Splitter, campaignRuntime, RUNTIMES, campaignPage, campaignTarget, vpcInstance, vpcSite, dedicatedOrigin, dedicatedHost, dedicatedSite, parseUsage, gfmt, when, failure, modelInfo, qoderBody, qoderMessages, cacheMarked, sessionOf, namedSession, taskOf, TASKS, TASK_MAX, TASK_IDLE, SESSION, SITES, decodeBody, events, QUEUE, queueState }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-qoder-auth",
3
- "version": "0.2.51",
4
- "description": "Qoder and QwenWork (千问办公) subscriptions in OpenCode and magpie: qoder.com, qoder.cn, gateway.qwenwork.cn and the enterprise flagship (VPC)",
3
+ "version": "0.2.53",
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",
7
7
  "exports": "./index.mjs",