@magpie-community/opencode-qoder-auth 0.2.76 → 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 +41 -0
- package/index.mjs +97 -11
- package/opencode.mjs +1 -1
- package/package.json +1 -1
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:
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
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:
|
|
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:
|
|
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 || "",
|
|
@@ -2810,8 +2834,9 @@ async function refreshedNames(site, token) {
|
|
|
2810
2834
|
const user = site.normalizeUser ? site.normalizeUser(ui.json) : ui.json
|
|
2811
2835
|
const label = phoneLabelOf(user, user?.email, user?.name)
|
|
2812
2836
|
const suffix = (v) => (v ? (site.vpc ? `${v} (${site.vpc})` : v) : "")
|
|
2813
|
-
// built as the sign-in builds it: a real email first, then the phone
|
|
2814
|
-
|
|
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) }
|
|
2815
2840
|
} catch {
|
|
2816
2841
|
return {}
|
|
2817
2842
|
}
|
|
@@ -2836,6 +2861,43 @@ function phoneLabelOf(user, email, name) {
|
|
|
2836
2861
|
return ""
|
|
2837
2862
|
}
|
|
2838
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
|
+
|
|
2839
2901
|
// changed is the fields of b that differ from a's: what auth.refresh gives.
|
|
2840
2902
|
function changed(a, b) {
|
|
2841
2903
|
const out = {}
|
|
@@ -2922,6 +2984,10 @@ const CAMPAIGN_MACHINE_TTL = 60 * 60 * 1000 // Qoder's desktop client renews its
|
|
|
2922
2984
|
const RUNTIMES = {
|
|
2923
2985
|
qoder: { name: "Qoder", environment: "3", override: "QODER_RUNTIME_INFO", app: "Qoder", linux: "Qoder", cli: "QODER_", dir: ".qoder", required: true },
|
|
2924
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 },
|
|
2925
2991
|
}
|
|
2926
2992
|
|
|
2927
2993
|
async function campaignRuntime({ home = homedir(), platform = process.platform, arch = process.arch, env = process.env, opt = "/opt", runtime = RUNTIMES.qoder } = {}) {
|
|
@@ -3420,6 +3486,25 @@ const SITES = {
|
|
|
3420
3486
|
vpcDomain: "vpc.qoder.com.cn",
|
|
3421
3487
|
models: CN_MODELS,
|
|
3422
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
|
+
},
|
|
3423
3508
|
// QwenWork's public cloud. QWENWORK_ENT_DOMAIN (the enterprise preset)
|
|
3424
3509
|
// is the only variable read; the sites are these constants.
|
|
3425
3510
|
qwenwork: {
|
|
@@ -4421,6 +4506,7 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
4421
4506
|
|
|
4422
4507
|
export const QoderAuthPlugin = makePlugin(SITES.qoder)
|
|
4423
4508
|
export const QoderCNAuthPlugin = makePlugin(SITES["qoder-cn"])
|
|
4509
|
+
export const QoderTeamAuthPlugin = makePlugin(SITES["qoder-team"])
|
|
4424
4510
|
export const QwenWorkAuthPlugin = makePlugin(SITES.qwenwork)
|
|
4425
4511
|
|
|
4426
4512
|
// enterpriseDomain reads what the user entered as their enterprise's
|
|
@@ -4482,4 +4568,4 @@ export async function QwenWorkEnterpriseAuthPlugin({ client }) {
|
|
|
4482
4568
|
export const protocol = { makePlugin, deviceSignIn, openapi, siteOf }
|
|
4483
4569
|
|
|
4484
4570
|
// for tests
|
|
4485
|
-
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.
|
|
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",
|