@magpie-community/opencode-qoder-auth 0.2.52 → 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.
- package/README.md +49 -0
- package/index.mjs +160 -3
- package/package.json +2 -2
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
|
|
@@ -315,6 +327,43 @@ paths, client id and protocol are the public ones:
|
|
|
315
327
|
The hosts and reply shapes come from a real VPC account's report
|
|
316
328
|
(yetone/magpie#312). This plugin has not been tried with a VPC account.
|
|
317
329
|
|
|
330
|
+
### Enterprise dedicated domain (企业版专属域)
|
|
331
|
+
|
|
332
|
+
An enterprise whose Qoder IDE signs in through 「企业版专属域登录」 with a
|
|
333
|
+
domain of its own (any https host, such as `your-corp.rdc.aliyuncs.com`)
|
|
334
|
+
signs in with **Sign in with Qoder CN Enterprise dedicated domain
|
|
335
|
+
(企业版专属域)** (since 0.2.53). It asks for the domain as it is set in
|
|
336
|
+
Qoder IDE's settings: a host or an https address (a path is dropped).
|
|
337
|
+
|
|
338
|
+
It follows Qoder IDE 1.38.0's own rules for that setting:
|
|
339
|
+
|
|
340
|
+
- It first asks `GET <domain>/algo/api/v1/version`. A 404 means a legacy
|
|
341
|
+
Lingma 1.0 (通义灵码) dedicated domain. Its sign-in goes through another
|
|
342
|
+
protocol, which this plugin doesn't have yet, so the sign-in stops and
|
|
343
|
+
says so. Any other answer means Qoder CN 2.0. A domain that doesn't answer
|
|
344
|
+
is refused.
|
|
345
|
+
- A Qoder CN 2.0 domain uses the VPC protocol on hosts named the IDE's way:
|
|
346
|
+
`-openapi` or `-gateway` after the host's first label. An IP or a host
|
|
347
|
+
with no dot keeps its own origin. The sign-in uses the IDE's client id and
|
|
348
|
+
no `redirect_uri`.
|
|
349
|
+
|
|
350
|
+
| | Dedicated domain `your-corp.rdc.aliyuncs.com` |
|
|
351
|
+
|---|---|
|
|
352
|
+
| Sign-in page | your-corp.rdc.aliyuncs.com/device/selectAccounts |
|
|
353
|
+
| Accounts: poll, tokens, user info, usage | your-corp-openapi.rdc.aliyuncs.com |
|
|
354
|
+
| Models and chat | your-corp-gateway.rdc.aliyuncs.com |
|
|
355
|
+
|
|
356
|
+
- Models and chat use the gateway host when it answers at sign-in.
|
|
357
|
+
Otherwise they use the domain itself, which answered the probe on the
|
|
358
|
+
same `/algo` path. The IDE's language server makes this choice, and its
|
|
359
|
+
rule wasn't read, so this part is inferred.
|
|
360
|
+
- The domain is kept with the account, which is named
|
|
361
|
+
`<email> (<domain>)`. An account whose kept domain isn't one is asked to
|
|
362
|
+
sign in again; it is never sent to the public hosts.
|
|
363
|
+
|
|
364
|
+
The rules come from Qoder IDE's code. This plugin has not been tried with a
|
|
365
|
+
dedicated account.
|
|
366
|
+
|
|
318
367
|
## The card's name
|
|
319
368
|
|
|
320
369
|
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
|
}
|
|
@@ -1120,6 +1224,38 @@ function typedUnions(schema) {
|
|
|
1120
1224
|
return root
|
|
1121
1225
|
}
|
|
1122
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
|
+
|
|
1123
1259
|
// qoderBody is the plaintext agent_chat_generation takes for a chat
|
|
1124
1260
|
// completion request, for model m, in the session the agent named (named,
|
|
1125
1261
|
// "" when none) and the task it is a call of (taskOf's, a new one when
|
|
@@ -1150,7 +1286,7 @@ function qoderBody(chat, m, named = "", task, site) {
|
|
|
1150
1286
|
agent_id: "agent_common",
|
|
1151
1287
|
task_id: "common",
|
|
1152
1288
|
session_type: site?.sessionType ?? "app",
|
|
1153
|
-
model_config: m
|
|
1289
|
+
model_config: modelConfig(m, thinking),
|
|
1154
1290
|
system: [sys],
|
|
1155
1291
|
messages: [{ role: "system", content: [sys] }, ...cacheMarked(qoderMessages(chat.messages ?? []))],
|
|
1156
1292
|
}
|
|
@@ -2954,7 +3090,12 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
2954
3090
|
const api = siteOf(site, cred).api
|
|
2955
3091
|
const CHAT_URL = api + CHAT_PATH
|
|
2956
3092
|
const task = taskOf(sessionOf(chat, named), chat)
|
|
2957
|
-
|
|
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
|
+
}
|
|
2958
3099
|
// Qoder's queue is waited out (queueWait) and the request sent again
|
|
2959
3100
|
// under the request_set_id the queue knows, with a new request_id and
|
|
2960
3101
|
// chat_record_id, as Qoder's client sends it (its o4i before each
|
|
@@ -3167,6 +3308,22 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3167
3308
|
return deviceSignIn(s)
|
|
3168
3309
|
},
|
|
3169
3310
|
},
|
|
3311
|
+
// an enterprise dedicated domain (企业版专属域), as Qoder IDE's
|
|
3312
|
+
// settings take one: any https host, e.g. <corp>.rdc.aliyuncs.com
|
|
3313
|
+
{
|
|
3314
|
+
type: "oauth",
|
|
3315
|
+
label: `Sign in with ${site.name} Enterprise dedicated domain (企业版专属域)`,
|
|
3316
|
+
prompts: [
|
|
3317
|
+
{
|
|
3318
|
+
type: "text",
|
|
3319
|
+
key: "dedicated",
|
|
3320
|
+
message: "Your enterprise's dedicated domain, as set in Qoder IDE (企业版专属域地址)",
|
|
3321
|
+
placeholder: "your-corp.rdc.aliyuncs.com or https://your-corp.rdc.aliyuncs.com",
|
|
3322
|
+
validate: (v) => (dedicatedOrigin(v) ? undefined : "Not a dedicated domain: enter its host or https:// address"),
|
|
3323
|
+
},
|
|
3324
|
+
],
|
|
3325
|
+
authorize: (inputs) => dedicatedSignIn(site, inputs?.dedicated),
|
|
3326
|
+
},
|
|
3170
3327
|
]
|
|
3171
3328
|
: []),
|
|
3172
3329
|
],
|
|
@@ -3302,4 +3459,4 @@ export async function QwenWorkEnterpriseAuthPlugin({ client }) {
|
|
|
3302
3459
|
export const protocol = { makePlugin, deviceSignIn, openapi, siteOf }
|
|
3303
3460
|
|
|
3304
3461
|
// 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 }
|
|
3462
|
+
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.54",
|
|
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",
|