@magpie-community/opencode-qoder-auth 0.2.52 → 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.
- package/README.md +37 -0
- package/index.mjs +121 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -315,6 +315,43 @@ paths, client id and protocol are the public ones:
|
|
|
315
315
|
The hosts and reply shapes come from a real VPC account's report
|
|
316
316
|
(yetone/magpie#312). This plugin has not been tried with a VPC account.
|
|
317
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
|
+
|
|
318
355
|
## The card's name
|
|
319
356
|
|
|
320
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
|
}
|
|
@@ -3167,6 +3271,22 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3167
3271
|
return deviceSignIn(s)
|
|
3168
3272
|
},
|
|
3169
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
|
+
},
|
|
3170
3290
|
]
|
|
3171
3291
|
: []),
|
|
3172
3292
|
],
|
|
@@ -3302,4 +3422,4 @@ export async function QwenWorkEnterpriseAuthPlugin({ client }) {
|
|
|
3302
3422
|
export const protocol = { makePlugin, deviceSignIn, openapi, siteOf }
|
|
3303
3423
|
|
|
3304
3424
|
// for tests
|
|
3305
|
-
export const _internal = { freeView, 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.
|
|
4
|
-
"description": "Qoder and QwenWork (千问办公) subscriptions in OpenCode and magpie: qoder.com, qoder.cn, gateway.qwenwork.cn and the enterprise flagship
|
|
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",
|