@magpie-community/opencode-qoder-auth 0.2.75 → 0.2.77

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.
package/README.md CHANGED
@@ -8,6 +8,7 @@ accounts exist only on their own:
8
8
  |---|---|---|---|
9
9
  | `qoder` | qoder.com (international) | Google, GitHub or email | `QoderAuthPlugin` |
10
10
  | `qoder-cn` | qoder.cn ([Qoder CN](#qoder-cn)) | Alibaba Cloud or phone number | `QoderCNAuthPlugin` |
11
+ | `qoder-team` | qoder.com.cn ([Qoder Teams](#qoder-teams)) | a Teams member: phone, email or the organization's SSO | `QoderTeamAuthPlugin` |
11
12
  | `qwenwork` | gateway.qwenwork.cn ([QwenWork](#qwenwork-千问办公)) | phone number or email | `QwenWorkAuthPlugin` |
12
13
  | `qwenwork-enterprise` | the enterprise's own domain ([QwenWork](#qwenwork-千问办公)) | email OTP or enterprise SSO | `QwenWorkEnterpriseAuthPlugin` |
13
14
 
@@ -420,6 +421,42 @@ tests on a real Lingma dedicated domain. The folders and the model names
420
421
  were checked against Qoder CN IDE 1.38.0. This plugin itself has not been
421
422
  tried on one.
422
423
 
424
+ ## Qoder Teams
425
+
426
+ `qoder-team` is for Qoder CN's **Teams (团队版)** seats. An organization is
427
+ bought on Alibaba Cloud and managed on qoder.com.cn; its members are invited
428
+ by email, by phone or through the organization's SSO, and sign in there.
429
+ qoder.com.cn and qoder.cn serve the same app — on 2026-11-27 the same bytes at
430
+ `/` and `/users/sign-in`, and the same `/device/selectAccounts` page — so a
431
+ Teams account speaks the protocol [above](#qoder-cn) on the same hosts:
432
+
433
+ | | `qoder-cn` | `qoder-team` |
434
+ |---|---|---|
435
+ | Sign-in page | qoder.cn | qoder.com.cn |
436
+ | Accounts: poll, tokens, user info, usage | openapi.qoder.com.cn | the same |
437
+ | Models and chat | gateway.qoder.com.cn | the same |
438
+ | Device-flow client id | Qoder CN's CLI's | the same |
439
+
440
+ The sign-in page is the only difference, and it is the domain the
441
+ organization's invitation and SSO links point at.
442
+
443
+ What a Teams account adds:
444
+
445
+ - The organization its user info names (`organization_id` /
446
+ `organization_name`, or a nested `organization`) is kept on the credential
447
+ as `orgId` / `orgName`, and the account is named for it: `dev@acme.cn (Acme)`
448
+ is its `accountId`, `dev@acme.cn · Acme` its card. The same person's
449
+ personal account on `qoder-cn` therefore stays a row of its own, and a PAT
450
+ sign-in names the same account a browser sign-in does.
451
+ - An account whose user info names no organization is named as `qoder-cn`
452
+ names it: the Teams site also serves personal accounts.
453
+ - **Sign in with Qoder Teams Enterprise (VPC)** and **… dedicated domain** are
454
+ offered as they are on Qoder CN: an organization on a VPC instance or a
455
+ dedicated domain belongs to the same Teams plan.
456
+
457
+ Tried with a real Teams seat (Qoder CN, phone sign-in, 2026-11-27): the
458
+ sign-in, the organization read from user info, the model list and chat work.
459
+
423
460
  ## The card's name
424
461
 
425
462
  An account signed in with a phone is shown by that phone — masked, `138****8000` — not by
@@ -430,6 +467,10 @@ QwenWork's phone accounts answer only the last four digits, as `name`, beside a
430
467
  `phone_<uuid>@phone.local` email (measured): the card shows `****8000` and never that email.
431
468
  An email sign-in keeps its email.
432
469
 
470
+ On a Teams site (`qoder-team`) the organization follows the name — `dev@acme.cn · Acme` —
471
+ and the `accountId` carries it too, `dev@acme.cn (Acme)`, so a team seat and the same
472
+ person's personal account are two accounts to magpie.
473
+
433
474
  `accountId` stays the account's identity — what magpie keys the user's own name for
434
475
  it, its proxy, model picks, caps and a gateway key's account list by — so it never
435
476
  changes: it is what a sign-in and every renewal give back. The card's name is usage's
package/index.mjs CHANGED
@@ -2,6 +2,8 @@
2
2
  // sites, whose accounts exist only on their own:
3
3
  // - qoder: the international site, qoder.com
4
4
  // - qoder-cn: Qoder CN, qoder.cn (Alibaba Cloud or phone sign-in)
5
+ // - qoder-team: Qoder CN's Teams (团队版) households, signed in on
6
+ // qoder.com.cn, the domain their organization's console lives on
5
7
  //
6
8
  // Qoder is signed in to the way its desktop client is: a PKCE device flow
7
9
  // (qoder.com's page, then a poll of openapi.qoder.sh for the device token),
@@ -26,6 +28,17 @@
26
28
  // production and no redirect_uri. That CLI chats on the device token itself;
27
29
  // if qoder.cn won't trade it for a job token, the account does the same.
28
30
  //
31
+ // Qoder CN's Teams (团队版) plans are an organization's seats: members are
32
+ // invited by email, phone or the organization's SSO, and the organization is
33
+ // managed on qoder.com.cn. qoder.com.cn and qoder.cn serve the same app
34
+ // (measured 2026-11-27: the same bytes at / and /users/sign-in, and the same
35
+ // device page), so a Teams account speaks the protocol above on the same
36
+ // hosts. qoder-team signs in on qoder.com.cn, where the organization's SSO
37
+ // and its invitation links point, and keeps the organization its user info
38
+ // names (organization_id / organization_name). The account is named for that
39
+ // organization, so the same person's personal account on qoder-cn stays a
40
+ // row of its own.
41
+ //
29
42
  // A Qoder CN enterprise VPC account (yetone/magpie#312) is signed in to with
30
43
  // its own method, which asks for the enterprise's instance name. Its calls go
31
44
  // to the same paths on the instance's own hosts, as Qoder CN's CLI 1.1.64
@@ -723,6 +736,10 @@ async function deviceSignIn(site) {
723
736
  } catch {}
724
737
  if (site.deviceOnly && !String(uid ?? "").trim()) throw new Error(`${site.name}: the sign-in named no user`)
725
738
  if (site.vpc && !String(uid ?? "").trim()) throw new Error(`${site.name} (${site.vpc}): the sign-in named no user`)
739
+ // a Teams account is told apart from the same person's personal one by
740
+ // the organization its user info names
741
+ const team = teamOf(site, user)
742
+ const orgTag = team.orgLabel ? ` (${team.orgLabel})` : ""
726
743
  return {
727
744
  type: "success",
728
745
  ...chat,
@@ -732,18 +749,21 @@ async function deviceSignIn(site) {
732
749
  // model picks and caps all hang off it, and a gateway key keys its
733
750
  // list by it), so it stays exactly what main computes: the phone is a
734
751
  // separate field, shown by usage's `user`, never the identity.
735
- accountId: site.vpc
736
- ? `${email || uid} (${site.vpc})`
737
- : site.deviceOnly
738
- ? email || uid || name || dt.user_id
739
- : email || dt.user_id,
752
+ accountId:
753
+ (site.vpc
754
+ ? `${email || uid} (${site.vpc})`
755
+ : site.deviceOnly
756
+ ? email || uid || name || dt.user_id
757
+ : email || dt.user_id) + orgTag,
740
758
  // the card's names: the phone on its own, and what magpie shows (a
741
759
  // real email first, then the phone) — never the accountId
742
760
  ...(() => {
743
761
  const label = phoneLabelOf(user, email, name)
744
762
  const suffix = (v) => (v ? (site.vpc ? `${v} (${site.vpc})` : v) : "")
745
- return { phoneLabel: suffix(label), cardName: suffix(realEmailOf(email) || label) }
763
+ return { phoneLabel: suffix(label), cardName: cardNameOf(site, user, email, name) }
746
764
  })(),
765
+ ...(team.orgId ? { orgId: team.orgId } : {}),
766
+ ...(team.orgName ? { orgName: team.orgName } : {}),
747
767
  uid,
748
768
  email,
749
769
  name: name || dt.user_name || "",
@@ -792,6 +812,8 @@ async function patSignIn(site, pat) {
792
812
  }
793
813
  } catch {}
794
814
  if (!uid) throw new Error(`${site.name} PAT sign-in: could not determine user id`)
815
+ const team = teamOf(site, user)
816
+ const orgTag = team.orgLabel ? ` (${team.orgLabel})` : ""
795
817
  return {
796
818
  type: "success",
797
819
  ...chat,
@@ -799,9 +821,11 @@ async function patSignIn(site, pat) {
799
821
  // an account on a new sign-in when both the accountId and the uid match,
800
822
  // so a renewed PAT sign-in must keep naming the same account. A suffix
801
823
  // here would add a second row beside the lapsed one instead.
802
- accountId: email || uid,
824
+ accountId: (email || uid) + orgTag,
803
825
  phoneLabel: phoneLabelOf(user, email, name),
804
- cardName: realEmailOf(email) || phoneLabelOf(user, email, name),
826
+ cardName: cardNameOf(site, user, email, name),
827
+ ...(team.orgId ? { orgId: team.orgId } : {}),
828
+ ...(team.orgName ? { orgName: team.orgName } : {}),
805
829
  uid,
806
830
  email,
807
831
  name: name || "",
@@ -2672,9 +2696,25 @@ const NAMELESS = "the model's native tool call has no name; it is not sent on as
2672
2696
  // opened is a chat reply's events and the first of them, read before
2673
2697
  // anything is answered: a refusal in the stream (Qoder's queue among them)
2674
2698
  // comes first.
2675
- async function opened(res, tools) {
2676
- const it = events(res.body, tools)
2677
- return { it, first: await it.next() }
2699
+ async function opened(res, tools, onReader) {
2700
+ const reader = res.body.getReader()
2701
+ onReader?.(reader)
2702
+ const body = async function* () {
2703
+ while (true) {
2704
+ const { done, value } = await reader.read()
2705
+ if (done) {
2706
+ return
2707
+ }
2708
+ yield value
2709
+ }
2710
+ }()
2711
+ const it = events(body, tools)
2712
+ try {
2713
+ const first = await it.next()
2714
+ return { it, first }
2715
+ } finally {
2716
+ onReader?.(undefined)
2717
+ }
2678
2718
  }
2679
2719
 
2680
2720
  async function answer({ it, first }, chat, servedName = chat.model) {
@@ -2794,8 +2834,9 @@ async function refreshedNames(site, token) {
2794
2834
  const user = site.normalizeUser ? site.normalizeUser(ui.json) : ui.json
2795
2835
  const label = phoneLabelOf(user, user?.email, user?.name)
2796
2836
  const suffix = (v) => (v ? (site.vpc ? `${v} (${site.vpc})` : v) : "")
2797
- // built as the sign-in builds it: a real email first, then the phone
2798
- return { phoneLabel: suffix(label), cardName: suffix(realEmailOf(user?.email) || label) }
2837
+ // built as the sign-in builds it: a real email first, then the phone,
2838
+ // then the Teams organization
2839
+ return { phoneLabel: suffix(label), cardName: cardNameOf(site, user, user?.email, user?.name) }
2799
2840
  } catch {
2800
2841
  return {}
2801
2842
  }
@@ -2820,6 +2861,43 @@ function phoneLabelOf(user, email, name) {
2820
2861
  return ""
2821
2862
  }
2822
2863
 
2864
+ /**
2865
+ * The organization a Qoder CN Teams account belongs to, as Qoder CN's CLI
2866
+ * reads it from user info: organization_id / organization_name, or a nested
2867
+ * `organization` object. A personal account names none.
2868
+ */
2869
+ function orgOf(user) {
2870
+ const u = user && typeof user === "object" ? user : {}
2871
+ const org = u.organization && typeof u.organization === "object" ? u.organization : {}
2872
+ const id = String(u.organization_id ?? u.organizationId ?? u.orgId ?? org.id ?? org.org_id ?? org.orgId ?? "").trim()
2873
+ const name = String(u.organization_name ?? u.organizationName ?? org.name ?? org.org_name ?? org.orgName ?? "").trim()
2874
+ return id || name ? { ...(id ? { orgId: id } : {}), ...(name ? { orgName: name } : {}) } : {}
2875
+ }
2876
+
2877
+ /**
2878
+ * What a Teams site adds to an account's names: `orgId`, `orgName`, and the
2879
+ * `orgLabel` its `accountId` and card are suffixed with. A site that isn't a
2880
+ * Teams site (`orgLabel` unset), or an account whose user info names no
2881
+ * organization, adds nothing.
2882
+ */
2883
+ function teamOf(site, user) {
2884
+ if (!site.orgLabel) return {}
2885
+ const org = orgOf(user)
2886
+ return org.orgId || org.orgName ? { ...org, orgLabel: org.orgName || org.orgId } : {}
2887
+ }
2888
+
2889
+ /** The card's name as every path builds it: a real email first, then the
2890
+ * phone, the VPC instance's suffix, then the Teams organization's. */
2891
+ function cardNameOf(site, user, email, name) {
2892
+ const shown = realEmailOf(email) || phoneLabelOf(user, email, name)
2893
+ // nothing to show is no name at all, as before: a bare " (acme)" or
2894
+ // " · Acme" would replace the card's own fallback
2895
+ if (!shown) return ""
2896
+ const vpc = site.vpc ? ` (${site.vpc})` : ""
2897
+ const org = teamOf(site, user).orgLabel
2898
+ return `${shown}${vpc}${org ? ` · ${org}` : ""}`
2899
+ }
2900
+
2823
2901
  // changed is the fields of b that differ from a's: what auth.refresh gives.
2824
2902
  function changed(a, b) {
2825
2903
  const out = {}
@@ -2906,6 +2984,10 @@ const CAMPAIGN_MACHINE_TTL = 60 * 60 * 1000 // Qoder's desktop client renews its
2906
2984
  const RUNTIMES = {
2907
2985
  qoder: { name: "Qoder", environment: "3", override: "QODER_RUNTIME_INFO", app: "Qoder", linux: "Qoder", cli: "QODER_", dir: ".qoder", required: true },
2908
2986
  "qoder-cn": { name: "Qoder CN", environment: "0", override: "QODERCN_RUNTIME_INFO", app: "Qoder CN", linux: "Qoder-CN", cli: "QODERCN_", dir: ".qoder-cn", required: false },
2987
+ // Teams households run Qoder CN's own desktop and CLI, so the identity is
2988
+ // read from the same installs and the same cache (the check-in is Qoder
2989
+ // CN's too)
2990
+ "qoder-team": { name: "Qoder CN", environment: "0", override: "QODERCN_RUNTIME_INFO", app: "Qoder CN", linux: "Qoder-CN", cli: "QODERCN_", dir: ".qoder-cn", required: false },
2909
2991
  }
2910
2992
 
2911
2993
  async function campaignRuntime({ home = homedir(), platform = process.platform, arch = process.arch, env = process.env, opt = "/opt", runtime = RUNTIMES.qoder } = {}) {
@@ -3404,6 +3486,25 @@ const SITES = {
3404
3486
  vpcDomain: "vpc.qoder.com.cn",
3405
3487
  models: CN_MODELS,
3406
3488
  },
3489
+ // Qoder CN's Teams (团队版) households. qoder.com.cn is where an
3490
+ // organization is managed and where its invitations and SSO point; it
3491
+ // serves the same app as qoder.cn (measured 2026-11-27), and the accounts,
3492
+ // hosts and client id are Qoder CN's. The organization is kept on the
3493
+ // account and goes in its name, so a personal account of the same person
3494
+ // stays a row of its own.
3495
+ "qoder-team": {
3496
+ id: "qoder-team",
3497
+ name: "Qoder Teams",
3498
+ clientId: "e883ade2-e6e3-4d6d-adf7-f92ceff5fdcb",
3499
+ web: "https://qoder.com.cn",
3500
+ openapi: "https://openapi.qoder.com.cn",
3501
+ api: "https://gateway.qoder.com.cn",
3502
+ redirect: "",
3503
+ deviceChat: true,
3504
+ vpcDomain: "vpc.qoder.com.cn",
3505
+ orgLabel: true,
3506
+ models: CN_MODELS,
3507
+ },
3407
3508
  // QwenWork's public cloud. QWENWORK_ENT_DOMAIN (the enterprise preset)
3408
3509
  // is the only variable read; the sites are these constants.
3409
3510
  qwenwork: {
@@ -3972,13 +4073,28 @@ const makePlugin = (site) => async ({ client }) => {
3972
4073
  const callSignal = signal ? AbortSignal.any([signal, call.signal]) : call.signal
3973
4074
  let res, open
3974
4075
  let silent = false
4076
+ let pendingRead
3975
4077
  const hush = setTimeout(() => {
3976
4078
  silent = true
3977
4079
  call.abort()
4080
+ pendingRead?.cancel().catch(() => {})
3978
4081
  }, QUEUE.silent)
3979
4082
  try {
3980
4083
  res = await fetch(CHAT_URL, { method: "POST", headers, body: wire, signal: callSignal })
3981
- if (res.ok) open = await opened(res, chat.tool_choice !== "none" ? (chat.tools ?? []).filter((t) => t?.type === "function") : [])
4084
+ if (silent)
4085
+ return errorResponse({
4086
+ status: 504,
4087
+ message: `${siteOf(site, cred).name ?? "Qoder"} sent nothing for ${Math.round(QUEUE.silent / 1000)}s after the request (no first event); the call was dropped`,
4088
+ signIn: "",
4089
+ })
4090
+ if (res.ok)
4091
+ open = await opened(
4092
+ res,
4093
+ chat.tool_choice !== "none" ? (chat.tools ?? []).filter((t) => t?.type === "function") : [],
4094
+ (reader) => {
4095
+ pendingRead = reader
4096
+ },
4097
+ )
3982
4098
  } catch (e) {
3983
4099
  if (silent) {
3984
4100
  const who = siteOf(site, cred).name ?? "Qoder"
@@ -3987,7 +4103,14 @@ const makePlugin = (site) => async ({ client }) => {
3987
4103
  return errorResponse({ status: 502, message: e.message })
3988
4104
  } finally {
3989
4105
  clearTimeout(hush)
4106
+ pendingRead = undefined
3990
4107
  }
4108
+ if (silent)
4109
+ return errorResponse({
4110
+ status: 504,
4111
+ message: `${siteOf(site, cred).name ?? "Qoder"} sent nothing for ${Math.round(QUEUE.silent / 1000)}s after the request (no first event); the call was dropped`,
4112
+ signIn: "",
4113
+ })
3991
4114
  const f = !res.ok ? failure(res.status, (await res.text()).slice(0, 1 << 20)) : open.first.value?.error
3992
4115
  if (f) call.abort()
3993
4116
  // a refused job token: renewed once (or the one renewed meanwhile)
@@ -4383,6 +4506,7 @@ const makePlugin = (site) => async ({ client }) => {
4383
4506
 
4384
4507
  export const QoderAuthPlugin = makePlugin(SITES.qoder)
4385
4508
  export const QoderCNAuthPlugin = makePlugin(SITES["qoder-cn"])
4509
+ export const QoderTeamAuthPlugin = makePlugin(SITES["qoder-team"])
4386
4510
  export const QwenWorkAuthPlugin = makePlugin(SITES.qwenwork)
4387
4511
 
4388
4512
  // enterpriseDomain reads what the user entered as their enterprise's
@@ -4444,4 +4568,4 @@ export async function QwenWorkEnterpriseAuthPlugin({ client }) {
4444
4568
  export const protocol = { makePlugin, deviceSignIn, openapi, siteOf }
4445
4569
 
4446
4570
  // for tests
4447
- export const _internal = { spentOf, OUTPUT_CAPS, LEARNED_CAPS, outputCap, fetchListing, accountIdentity, deviceRefreshBody, qwenworkClientHeaders, freeView, maskPhone, phoneLabelOf, realEmailOf, chatHeaders, machineOS, machineHostname, cosyHeaders, typedUnions, Splitter, campaignRuntime, RUNTIMES, campaignPage, campaignTarget, vpcInstance, vpcSite, dedicatedOrigin, dedicatedHost, dedicatedSite, lingmaRoots, lingmaDecode, lingmaSite, lingmaHeaders, LINGMA_MODELS, parseUsage, gfmt, when, failure, modelInfo, qoderBody, asAgentSDK, harnessComma, qoderMessages, kimiModel, cacheMarked, sessionOf, namedSession, taskOf, TASKS, TASK_MAX, TASK_IDLE, SESSION, SITES, decodeBody, events, QUEUE, queueState, queueReady }
4571
+ export const _internal = { spentOf, OUTPUT_CAPS, LEARNED_CAPS, outputCap, fetchListing, accountIdentity, deviceRefreshBody, qwenworkClientHeaders, freeView, maskPhone, phoneLabelOf, realEmailOf, orgOf, teamOf, cardNameOf, chatHeaders, machineOS, machineHostname, cosyHeaders, typedUnions, Splitter, campaignRuntime, RUNTIMES, campaignPage, campaignTarget, vpcInstance, vpcSite, dedicatedOrigin, dedicatedHost, dedicatedSite, lingmaRoots, lingmaDecode, lingmaSite, lingmaHeaders, LINGMA_MODELS, parseUsage, gfmt, when, failure, modelInfo, qoderBody, asAgentSDK, harnessComma, qoderMessages, kimiModel, cacheMarked, sessionOf, namedSession, taskOf, TASKS, TASK_MAX, TASK_IDLE, SESSION, SITES, decodeBody, events, QUEUE, queueState, queueReady }
package/opencode.mjs CHANGED
@@ -2,4 +2,4 @@
2
2
  // load them: its plugin functions and nothing else (1.x refuses a
3
3
  // package whose exports include anything but plugins). OpenCode 2.x
4
4
  // loads opencode2.mjs, which runs these.
5
- export { QoderAuthPlugin, QoderCNAuthPlugin, QwenWorkAuthPlugin, QwenWorkEnterpriseAuthPlugin } from "./index.mjs"
5
+ export { QoderAuthPlugin, QoderCNAuthPlugin, QoderTeamAuthPlugin, QwenWorkAuthPlugin, QwenWorkEnterpriseAuthPlugin } from "./index.mjs"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-qoder-auth",
3
- "version": "0.2.75",
3
+ "version": "0.2.77",
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": "./opencode.mjs",