dsh-agent-sdk-bridge 1.1.7 → 1.2.0
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/DEVELOPMENT.md +46 -1
- package/FAQ.md +40 -5
- package/client.js +103 -13
- package/lib/index.js +332 -39
- package/lib/types/adapter.d.ts +21 -2
- package/lib/types/cli.d.ts +65 -5
- package/lib/types/codebuddy.d.ts +1 -1
- package/lib/types/live.d.ts +2 -2
- package/lib/types/minimax.d.ts +7 -0
- package/lib/types/model-cache.d.ts +27 -0
- package/lib/types/models.d.ts +10 -0
- package/lib/types/setup.d.ts +33 -0
- package/lib/types/usage.d.ts +12 -0
- package/package.json +3 -3
- package/scripts/setup-qodercli.bat +53 -6
- package/scripts/setup-qoderclicn.bat +53 -6
- package/src/adapter.ts +63 -8
- package/src/api.ts +7 -2
- package/src/cli.ts +183 -16
- package/src/codebuddy-adapter.ts +9 -4
- package/src/codebuddy.ts +2 -2
- package/src/config.ts +1 -1
- package/src/live.ts +2 -2
- package/src/minimax-adapter.ts +5 -2
- package/src/minimax.ts +10 -0
- package/src/model-cache.ts +39 -0
- package/src/models.ts +42 -3
- package/src/session.ts +2 -2
- package/src/setup.ts +69 -1
- package/src/usage.ts +33 -3
package/lib/index.js
CHANGED
|
@@ -264,8 +264,8 @@ function readLive(value, fallback) {
|
|
|
264
264
|
* Resolve one {@link Live} option that may legitimately be undefined.
|
|
265
265
|
*
|
|
266
266
|
* Separate from {@link readLive} because an option whose "unset" state is
|
|
267
|
-
* itself meaningful (`defaultReasoningEffort`: empty means "
|
|
268
|
-
* has no fallback to apply.
|
|
267
|
+
* itself meaningful (`defaultReasoningEffort`: empty means "use the model's
|
|
268
|
+
* strongest level") has no fallback to apply.
|
|
269
269
|
*
|
|
270
270
|
* @param value - the plain value or thunk, possibly undefined.
|
|
271
271
|
* @returns the option's current value, or undefined when it is unset.
|
|
@@ -364,20 +364,17 @@ function resolveQoderCli(brand = "cn", lookup = {}) {
|
|
|
364
364
|
function qoderCliOptions(brand = "cn", lookup = {}) {
|
|
365
365
|
const cli = resolveQoderCli(brand, lookup);
|
|
366
366
|
if (cli === void 0) return {};
|
|
367
|
+
const env = cliChildEnv(brand);
|
|
367
368
|
if (cli.nodeDir === void 0) return {
|
|
368
369
|
pathToQoderCLIExecutable: cli.path,
|
|
369
|
-
env
|
|
370
|
-
...process.env,
|
|
371
|
-
...EXPOSE_TOKEN_USAGE
|
|
372
|
-
}
|
|
370
|
+
env
|
|
373
371
|
};
|
|
374
372
|
return {
|
|
375
373
|
pathToQoderCLIExecutable: cli.path,
|
|
376
374
|
executable: "node",
|
|
377
375
|
env: {
|
|
378
|
-
...
|
|
379
|
-
PATH: `${cli.nodeDir}${path.delimiter}${
|
|
380
|
-
...EXPOSE_TOKEN_USAGE
|
|
376
|
+
...env,
|
|
377
|
+
PATH: `${cli.nodeDir}${path.delimiter}${env.PATH ?? ""}`
|
|
381
378
|
}
|
|
382
379
|
};
|
|
383
380
|
}
|
|
@@ -397,15 +394,24 @@ function isForeignCliPath(brand, candidate) {
|
|
|
397
394
|
return brand === "global" ? chinese : global;
|
|
398
395
|
}
|
|
399
396
|
/**
|
|
400
|
-
*
|
|
397
|
+
* Why this edition has no usable CLI, when `QODERCLI_PATH` explains it.
|
|
401
398
|
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
* edition's
|
|
399
|
+
* `QODERCLI_PATH` predates the international edition and some installers
|
|
400
|
+
* export it machine-wide. Both SDKs read it from the parent process before any
|
|
401
|
+
* option this plugin can pass, so a value naming the *other* edition would
|
|
402
|
+
* hand this edition's session the other account. The lookup therefore never
|
|
403
|
+
* offers it ({@link isForeignCliPath}), and this reports the case where it is
|
|
404
|
+
* all the machine has, so the page can ask for the right CLI to be installed.
|
|
405
|
+
*
|
|
406
|
+
* This is a diagnosis, not a second rule: an edition that finds its own CLI is
|
|
407
|
+
* unaffected by the variable. That is what keeps one edition's install from
|
|
408
|
+
* blocking the other's sign-in — the earlier code treated any foreign value as
|
|
409
|
+
* fatal, so a machine that had only the intl CLI installed could not sign in
|
|
410
|
+
* to CN even after installing it if the lookup missed the new package.
|
|
406
411
|
*
|
|
407
412
|
* @param brand - the edition the caller is about to start.
|
|
408
413
|
* @param lookup - the machine to inspect; defaults to this process's.
|
|
414
|
+
* @returns the foreign override when this edition has nothing of its own.
|
|
409
415
|
*/
|
|
410
416
|
function foreignCliOverride(brand, lookup = {}) {
|
|
411
417
|
const override = (lookup.env ?? process.env).QODERCLI_PATH;
|
|
@@ -415,6 +421,26 @@ function foreignCliOverride(brand, lookup = {}) {
|
|
|
415
421
|
return override;
|
|
416
422
|
}
|
|
417
423
|
/**
|
|
424
|
+
* The environment one session's child process receives.
|
|
425
|
+
*
|
|
426
|
+
* `QODERCLI_PATH` is stripped when it names the other edition: both SDKs read
|
|
427
|
+
* it from the parent before honouring any option, so leaving it in place would
|
|
428
|
+
* hand the intl session the CN CLI (and the CN account). Every other variable
|
|
429
|
+
* is inherited untouched — the CLI keeps its state in `PATH`-relative dirs.
|
|
430
|
+
*
|
|
431
|
+
* @param brand - which edition's child is being started.
|
|
432
|
+
* @param env - the environment to derive from; defaults to this process's.
|
|
433
|
+
*/
|
|
434
|
+
function cliChildEnv(brand, env = process.env) {
|
|
435
|
+
const child = {
|
|
436
|
+
...env,
|
|
437
|
+
...EXPOSE_TOKEN_USAGE
|
|
438
|
+
};
|
|
439
|
+
const override = env.QODERCLI_PATH;
|
|
440
|
+
if (override !== void 0 && override.length > 0 && isForeignCliPath(brand, override)) delete child.QODERCLI_PATH;
|
|
441
|
+
return child;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
418
444
|
* The error text for {@link foreignCliOverride}.
|
|
419
445
|
*
|
|
420
446
|
* Deliberately says nothing about the variable or the path that caused it: the
|
|
@@ -424,6 +450,70 @@ function foreignCliOverride(brand, lookup = {}) {
|
|
|
424
450
|
function cliConflictMessage(brand) {
|
|
425
451
|
return `未检测到可用的 ${brandProfile(brand).cliCommands[0]},请先安装并登录后再使用此版本。`;
|
|
426
452
|
}
|
|
453
|
+
/**
|
|
454
|
+
* Turn a CLI failure into something a user can act on.
|
|
455
|
+
*
|
|
456
|
+
* The SDK reports an outdated CLI as `Qoder CLI process exited with code 42`,
|
|
457
|
+
* which says nothing about the cause: CLI 1.1.81 removed the worker-session
|
|
458
|
+
* handshake the older SDK spoke, and its own log says so
|
|
459
|
+
* (`sdk_worker_removed: … Upgrade to the latest Qoder SDK version, or roll back
|
|
460
|
+
* the CLI`). The only fix available to a user is reinstalling the pair through
|
|
461
|
+
* the bundled helper, so say that instead of echoing the number.
|
|
462
|
+
*
|
|
463
|
+
* @param detail - the error text as the SDK reported it.
|
|
464
|
+
* @param brand - which edition's helper the message should name.
|
|
465
|
+
* @returns the original detail, prefixed with the actionable explanation.
|
|
466
|
+
*/
|
|
467
|
+
function cliFailureText(detail, brand) {
|
|
468
|
+
if (!/exit(?:ed)?(?: with)? code 42|sdk_worker_removed/i.test(detail)) return detail;
|
|
469
|
+
const profile = brandProfile(brand);
|
|
470
|
+
const pkg = profile.cliPackages[0];
|
|
471
|
+
const spec = pkg === void 0 ? profile.cliCommands[0] : `${pkg.scope}/${pkg.name}`;
|
|
472
|
+
const required = requiredCliVersion(brand);
|
|
473
|
+
const target = required === void 0 ? spec : `${spec}@${required}`;
|
|
474
|
+
return `本机 ${profile.cliCommands[0]} 与插件使用的 SDK 版本不匹配(CLI 已移除旧版握手,退出码 42)。请在设置页点「一键配置」重新安装配套版本,或手动执行 npm install -g ${target} 后重试。原始信息:${detail}`;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* The CLI version the installed SDK expects, read from its runtime manifest.
|
|
478
|
+
*
|
|
479
|
+
* Each SDK release pins one CLI build: the two speak a wire protocol that
|
|
480
|
+
* changes between them, and a mismatch fails every session with a bare exit
|
|
481
|
+
* code. The bundled helper reads the same file, so the page and the helper
|
|
482
|
+
* agree on which build to install.
|
|
483
|
+
*
|
|
484
|
+
* @param brand - which edition's SDK to inspect.
|
|
485
|
+
* @returns the pinned version, or undefined when the manifest is unreadable.
|
|
486
|
+
*/
|
|
487
|
+
function requiredCliVersion(brand) {
|
|
488
|
+
try {
|
|
489
|
+
const dir = sdkDir(brandProfile(brand).sdkPackage);
|
|
490
|
+
if (dir === void 0) return void 0;
|
|
491
|
+
const manifest = JSON.parse(readFileSync(path.join(dir, "dist", "runtime-manifest.json"), "utf8"));
|
|
492
|
+
return typeof manifest.qoderCliVersion === "string" && manifest.qoderCliVersion.length > 0 ? manifest.qoderCliVersion : void 0;
|
|
493
|
+
} catch {
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* The version of the installed CLI, read from its own package manifest.
|
|
499
|
+
*
|
|
500
|
+
* Read from disk rather than by running `--version`: a settings-page poll must
|
|
501
|
+
* not spawn a process every second, and the npm package always ships a
|
|
502
|
+
* manifest next to its entry. A native build without one answers undefined,
|
|
503
|
+
* which callers treat as "unknown" and never as a mismatch.
|
|
504
|
+
*
|
|
505
|
+
* @param brand - which edition's CLI to inspect.
|
|
506
|
+
* @returns the installed version, or undefined when it cannot be read.
|
|
507
|
+
*/
|
|
508
|
+
function installedCliVersion(brand) {
|
|
509
|
+
const cli = resolveQoderCli(brand);
|
|
510
|
+
if (cli === void 0) return void 0;
|
|
511
|
+
for (const candidate of [path.join(path.dirname(cli.path), "package.json"), path.join(path.dirname(path.dirname(cli.path)), "package.json")]) try {
|
|
512
|
+
const manifest = JSON.parse(readFileSync(candidate, "utf8"));
|
|
513
|
+
if (typeof manifest.name !== "string" || !manifest.name.startsWith("@")) continue;
|
|
514
|
+
if (typeof manifest.version === "string" && manifest.version.length > 0) return manifest.version;
|
|
515
|
+
} catch {}
|
|
516
|
+
}
|
|
427
517
|
/** Paths the CLI may live at, most explicit first. */
|
|
428
518
|
function candidates(brand, env, suffix, nodePath) {
|
|
429
519
|
const profile = brandProfile(brand);
|
|
@@ -435,8 +525,7 @@ function candidates(brand, env, suffix, nodePath) {
|
|
|
435
525
|
if (env.QODERCLI_PATH !== void 0 && !isForeignCliPath(brand, env.QODERCLI_PATH)) push(env.QODERCLI_PATH);
|
|
436
526
|
for (const root of nodeModulesRoots(env, nodePath)) for (const pkg of profile.cliPackages) {
|
|
437
527
|
const dir = path.join(root, pkg.scope, pkg.name);
|
|
438
|
-
|
|
439
|
-
push(path.join(dir, `${pkg.name}.js`));
|
|
528
|
+
for (const entry of packageEntries(dir, pkg.name, suffix)) push(entry);
|
|
440
529
|
}
|
|
441
530
|
const sdk = sdkDir(profile.sdkPackage);
|
|
442
531
|
if (sdk !== void 0) for (const pkg of profile.cliPackages) push(path.join(sdk, "dist", "_bundled", `${pkg.name}${suffix}`));
|
|
@@ -444,6 +533,31 @@ function candidates(brand, env, suffix, nodePath) {
|
|
|
444
533
|
for (const pkg of profile.cliPackages) push(path.join(home, profile.configDirName, "local", `${pkg.name}${suffix}`));
|
|
445
534
|
return found;
|
|
446
535
|
}
|
|
536
|
+
/**
|
|
537
|
+
* Every path one installed npm package can expose as its CLI.
|
|
538
|
+
*
|
|
539
|
+
* `main`/`bin` are read from the package's own manifest rather than guessed:
|
|
540
|
+
* the entry point has changed between CLI releases, and hard-coding only
|
|
541
|
+
* `bundle/<name>.js` reported an installed package as missing whenever it did
|
|
542
|
+
* not match. Unreadable manifests fall back to the conventional entries.
|
|
543
|
+
*/
|
|
544
|
+
function packageEntries(dir, name, suffix) {
|
|
545
|
+
const entries = [
|
|
546
|
+
path.join(dir, "bundle", `${name}.js`),
|
|
547
|
+
path.join(dir, `${name}.js`),
|
|
548
|
+
path.join(dir, "bundle", `${name}${suffix}`)
|
|
549
|
+
];
|
|
550
|
+
try {
|
|
551
|
+
const manifest = JSON.parse(readFileSync(path.join(dir, "package.json"), "utf8"));
|
|
552
|
+
if (typeof manifest.main === "string") entries.push(path.join(dir, manifest.main));
|
|
553
|
+
const bin = manifest.bin;
|
|
554
|
+
if (typeof bin === "string") entries.push(path.join(dir, bin));
|
|
555
|
+
else if (bin !== null && typeof bin === "object") {
|
|
556
|
+
for (const value of Object.values(bin)) if (typeof value === "string") entries.push(path.join(dir, value));
|
|
557
|
+
}
|
|
558
|
+
} catch {}
|
|
559
|
+
return entries;
|
|
560
|
+
}
|
|
447
561
|
/** `node_modules` roots a global install can land in. */
|
|
448
562
|
function nodeModulesRoots(env, nodePath) {
|
|
449
563
|
const roots = [];
|
|
@@ -453,7 +567,11 @@ function nodeModulesRoots(env, nodePath) {
|
|
|
453
567
|
push(env.NPM_CONFIG_PREFIX === void 0 ? void 0 : path.join(env.NPM_CONFIG_PREFIX, "node_modules"));
|
|
454
568
|
push(env.APPDATA === void 0 ? void 0 : path.join(env.APPDATA, "npm", "node_modules"));
|
|
455
569
|
push(path.join(homedir(), ".npm-global", "node_modules"));
|
|
456
|
-
if (nodePath !== void 0)
|
|
570
|
+
if (nodePath !== void 0) {
|
|
571
|
+
const prefix = path.dirname(nodePath);
|
|
572
|
+
push(path.join(prefix, "node_modules"));
|
|
573
|
+
push(path.join(path.dirname(prefix), "lib", "node_modules"));
|
|
574
|
+
}
|
|
457
575
|
return roots;
|
|
458
576
|
}
|
|
459
577
|
/**
|
|
@@ -492,7 +610,9 @@ function resolveNode(lookup) {
|
|
|
492
610
|
*/
|
|
493
611
|
function sdkDir(packageName) {
|
|
494
612
|
try {
|
|
495
|
-
|
|
613
|
+
const entry = createRequire(import.meta.url).resolve(packageName);
|
|
614
|
+
const dir = path.dirname(entry);
|
|
615
|
+
return path.basename(dir) === "dist" ? path.dirname(dir) : dir;
|
|
496
616
|
} catch {
|
|
497
617
|
return;
|
|
498
618
|
}
|
|
@@ -664,10 +784,24 @@ var QoderModelCatalog = class {
|
|
|
664
784
|
this.failure = void 0;
|
|
665
785
|
return officialOnly(models);
|
|
666
786
|
} catch (error) {
|
|
667
|
-
|
|
787
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
788
|
+
this.failure = cliFailureText(detail, this.brand);
|
|
668
789
|
return officialOnly((this.cached ?? sharedSnapshots.get(this.brand))?.models ?? []);
|
|
669
790
|
}
|
|
670
791
|
}
|
|
792
|
+
/**
|
|
793
|
+
* The last successful live list, without fetching.
|
|
794
|
+
*
|
|
795
|
+
* The model picker resolves a route on every switch, and a switch must not
|
|
796
|
+
* wait on a CLI cold start (up to the fetch timeout). Callers that need an
|
|
797
|
+
* immediate answer read this and let {@link liveModels} refresh behind them;
|
|
798
|
+
* `undefined` means nothing has been read yet, which only the first switch
|
|
799
|
+
* has to wait for.
|
|
800
|
+
*/
|
|
801
|
+
snapshot() {
|
|
802
|
+
const cached = this.cached ?? sharedSnapshots.get(this.brand);
|
|
803
|
+
return cached === void 0 ? void 0 : officialOnly(cached.models);
|
|
804
|
+
}
|
|
671
805
|
/** Why the last refresh failed, or undefined when it succeeded. */
|
|
672
806
|
get error() {
|
|
673
807
|
return this.failure;
|
|
@@ -711,7 +845,18 @@ var QoderModelCatalog = class {
|
|
|
711
845
|
}
|
|
712
846
|
});
|
|
713
847
|
try {
|
|
714
|
-
|
|
848
|
+
const timeout = readLive(this.fetchTimeoutMs, DEFAULT_FETCH_TIMEOUT_MS);
|
|
849
|
+
const uid = (await withTimeout$2(q.accountInfo(), timeout).catch(() => void 0))?.userId;
|
|
850
|
+
const models = await withTimeout$2(q.getAvailableModels(uid === void 0 ? {} : { uid }), timeout);
|
|
851
|
+
if (models.length > 0) return models;
|
|
852
|
+
for (const strategy of ["cache", "live"]) {
|
|
853
|
+
const fallback = await withTimeout$2(q.getAvailableModels({
|
|
854
|
+
...uid === void 0 ? {} : { uid },
|
|
855
|
+
fetchStrategy: strategy
|
|
856
|
+
}), timeout).catch(() => []);
|
|
857
|
+
if (fallback.length > 0) return fallback;
|
|
858
|
+
}
|
|
859
|
+
return [];
|
|
715
860
|
} finally {
|
|
716
861
|
await q.close().catch(() => void 0);
|
|
717
862
|
}
|
|
@@ -765,6 +910,41 @@ function withTimeout$2(promise, ms) {
|
|
|
765
910
|
});
|
|
766
911
|
}
|
|
767
912
|
//#endregion
|
|
913
|
+
//#region src/model-cache.ts
|
|
914
|
+
/**
|
|
915
|
+
* Cache-first catalogue reads for the model picker.
|
|
916
|
+
*
|
|
917
|
+
* The harness resolves a route every time the user switches model or reasoning
|
|
918
|
+
* level, and each of the three providers answers that resolution from a
|
|
919
|
+
* catalogue whose fetch is expensive: Qoder cold-starts its CLI (up to the
|
|
920
|
+
* fetch timeout), CodeBuddy boots a process, MiniMax probes over ACP. Awaiting
|
|
921
|
+
* that fetch inside a resolution made the picker freeze for seconds whenever
|
|
922
|
+
* the cache had just expired.
|
|
923
|
+
*
|
|
924
|
+
* So a resolution reads the last successful snapshot when there is one and lets
|
|
925
|
+
* the catalogue refresh behind it; only the very first resolution, where there
|
|
926
|
+
* is nothing to show, waits. A snapshot that is merely stale still describes
|
|
927
|
+
* the same account's models, so answering from it is no less correct than the
|
|
928
|
+
* previous behaviour of answering from a failed fetch's fallback.
|
|
929
|
+
*
|
|
930
|
+
* @module dsh-agent-sdk-bridge/model-cache
|
|
931
|
+
*/
|
|
932
|
+
/**
|
|
933
|
+
* The cached list when one exists, otherwise the awaited fetch.
|
|
934
|
+
*
|
|
935
|
+
* @param snapshot - last successful catalogue, or undefined before the first.
|
|
936
|
+
* @param fetch - the catalogue's normal (TTL-aware, in-flight-sharing) read.
|
|
937
|
+
* @returns the entries to resolve against, never empty-by-surprise when a
|
|
938
|
+
* snapshot exists.
|
|
939
|
+
*/
|
|
940
|
+
async function cachedModels(snapshot, fetch) {
|
|
941
|
+
if (snapshot !== void 0 && snapshot.length > 0) {
|
|
942
|
+
fetch().catch(() => void 0);
|
|
943
|
+
return snapshot;
|
|
944
|
+
}
|
|
945
|
+
return fetch();
|
|
946
|
+
}
|
|
947
|
+
//#endregion
|
|
768
948
|
//#region src/tokens.ts
|
|
769
949
|
/**
|
|
770
950
|
* Script-aware text pricing, shared by the input and output estimators.
|
|
@@ -2242,7 +2422,7 @@ var QoderSession = class {
|
|
|
2242
2422
|
this.endTurn({
|
|
2243
2423
|
kind: "error",
|
|
2244
2424
|
failure: {
|
|
2245
|
-
message: `qoder session died: ${String(error)}`,
|
|
2425
|
+
message: `qoder session died: ${cliFailureText(String(error), this.brand)}`,
|
|
2246
2426
|
code: "TRANSPORT"
|
|
2247
2427
|
}
|
|
2248
2428
|
});
|
|
@@ -2702,6 +2882,10 @@ var QoderUsage = class {
|
|
|
2702
2882
|
* @returns the reading; `error` carries a failed lookup instead of throwing.
|
|
2703
2883
|
*/
|
|
2704
2884
|
async read(fresh = false) {
|
|
2885
|
+
if (resolveQoderCli(this.brand) === void 0) {
|
|
2886
|
+
this.cached = void 0;
|
|
2887
|
+
return this.missingCli();
|
|
2888
|
+
}
|
|
2705
2889
|
const ttlMs = readLive(this.ttlMs, DEFAULT_USAGE_CACHE_TTL_MS);
|
|
2706
2890
|
if (!fresh && this.cached !== void 0 && Date.now() - this.cached.at < ttlMs) return this.cached;
|
|
2707
2891
|
this.inflight ??= this.fetch().finally(() => {
|
|
@@ -2715,11 +2899,21 @@ var QoderUsage = class {
|
|
|
2715
2899
|
invalidate() {
|
|
2716
2900
|
this.cached = void 0;
|
|
2717
2901
|
}
|
|
2902
|
+
/** The reading for a machine whose CLI is not installed. */
|
|
2903
|
+
missingCli() {
|
|
2904
|
+
const command = brandProfile(this.brand).cliCommands[0];
|
|
2905
|
+
return {
|
|
2906
|
+
at: Date.now(),
|
|
2907
|
+
cliMissing: true,
|
|
2908
|
+
error: `未检测到可用的 ${command},请先安装并登录后再使用此版本。`
|
|
2909
|
+
};
|
|
2910
|
+
}
|
|
2718
2911
|
async fetch() {
|
|
2719
2912
|
const at = Date.now();
|
|
2720
2913
|
try {
|
|
2721
2914
|
if (foreignCliOverride(this.brand) !== void 0) return {
|
|
2722
2915
|
at,
|
|
2916
|
+
cliMissing: true,
|
|
2723
2917
|
error: cliConflictMessage(this.brand)
|
|
2724
2918
|
};
|
|
2725
2919
|
const sdk = await loadSdk(this.brand);
|
|
@@ -2751,7 +2945,7 @@ var QoderUsage = class {
|
|
|
2751
2945
|
const command = brandProfile(this.brand).cliCommands[0];
|
|
2752
2946
|
return {
|
|
2753
2947
|
at,
|
|
2754
|
-
error: /ENOENT|not found|Cannot find package|未安装国际版 SDK/i.test(detail) ? `未检测到可用的 ${command},请先安装并登录后再读取额度。` : detail
|
|
2948
|
+
error: /ENOENT|not found|Cannot find package|未安装国际版 SDK/i.test(detail) ? `未检测到可用的 ${command},请先安装并登录后再读取额度。` : cliFailureText(detail, this.brand)
|
|
2755
2949
|
};
|
|
2756
2950
|
}
|
|
2757
2951
|
}
|
|
@@ -2869,22 +3063,72 @@ const EFFORT_NAMES = {
|
|
|
2869
3063
|
max: "Max"
|
|
2870
3064
|
};
|
|
2871
3065
|
/**
|
|
3066
|
+
* Strength order used to pick a model's starting level.
|
|
3067
|
+
*
|
|
3068
|
+
* The three providers spell their levels differently (Qoder publishes
|
|
3069
|
+
* `low|medium|high|max`, MiniMax `low|high`, CodeBuddy whatever its catalog
|
|
3070
|
+
* declares), so the ranking is by name rather than by position in any one
|
|
3071
|
+
* upstream list. An id outside this table ranks below every known one, which is
|
|
3072
|
+
* what several sources agreeing on an unfamiliar spelling should do.
|
|
3073
|
+
*/
|
|
3074
|
+
const EFFORT_ORDER = [
|
|
3075
|
+
"none",
|
|
3076
|
+
"minimal",
|
|
3077
|
+
"low",
|
|
3078
|
+
"medium",
|
|
3079
|
+
"high",
|
|
3080
|
+
"xhigh",
|
|
3081
|
+
"max"
|
|
3082
|
+
];
|
|
3083
|
+
/**
|
|
3084
|
+
* The strongest level a model offers.
|
|
3085
|
+
*
|
|
3086
|
+
* Switching model or level must start at the most capable setting the route
|
|
3087
|
+
* accepts, the same rule the sibling adapter plugin uses; the previous
|
|
3088
|
+
* behaviour of following upstream's own default meant some models silently
|
|
3089
|
+
* started one or two steps down (`CodeBuddy` advertises `high` as its default
|
|
3090
|
+
* even when `max` is selectable).
|
|
3091
|
+
*
|
|
3092
|
+
* @param efforts - the levels the route accepts, in upstream order.
|
|
3093
|
+
* @returns the strongest id, or undefined for a non-reasoning model.
|
|
3094
|
+
*/
|
|
3095
|
+
function strongestEffort(efforts) {
|
|
3096
|
+
if (efforts.length === 0) return void 0;
|
|
3097
|
+
let best;
|
|
3098
|
+
let bestRank = -1;
|
|
3099
|
+
for (const effort of efforts) {
|
|
3100
|
+
const rank = EFFORT_ORDER.indexOf(effort);
|
|
3101
|
+
if (best === void 0 || rank > bestRank) {
|
|
3102
|
+
best = effort;
|
|
3103
|
+
bestRank = rank;
|
|
3104
|
+
}
|
|
3105
|
+
}
|
|
3106
|
+
return best;
|
|
3107
|
+
}
|
|
3108
|
+
/**
|
|
2872
3109
|
* Build the `reasoning` metadata block for a resolved model, or undefined
|
|
2873
3110
|
* when the model does not support reasoning.
|
|
3111
|
+
*
|
|
3112
|
+
* The starting level is the strongest one the model accepts, not the level
|
|
3113
|
+
* upstream happens to name as its default: the user's explicit choice in the
|
|
3114
|
+
* sibling plugin, applied here too. An explicit configuration value still wins
|
|
3115
|
+
* when the model accepts it.
|
|
3116
|
+
*
|
|
2874
3117
|
* @param efforts - CLI-reported effort ids (absent for reasoning-less models).
|
|
2875
|
-
* @param
|
|
3118
|
+
* @param configuredEffort - user-configured starting level, when any.
|
|
2876
3119
|
* @param isReasoning - whether the model supports reasoning per the CLI.
|
|
2877
3120
|
* @returns the harness reasoning metadata, or undefined to omit it.
|
|
2878
3121
|
*/
|
|
2879
|
-
function reasoningInfo(efforts,
|
|
3122
|
+
function reasoningInfo(efforts, configuredEffort, isReasoning) {
|
|
2880
3123
|
if (efforts === void 0 && isReasoning === false) return void 0;
|
|
2881
3124
|
const ids = efforts !== void 0 && efforts.length > 0 ? efforts : DEFAULT_REASONING_EFFORTS;
|
|
3125
|
+
const defaultEffort = configuredEffort !== void 0 && ids.includes(configuredEffort) ? configuredEffort : strongestEffort(ids);
|
|
2882
3126
|
return {
|
|
2883
3127
|
efforts: ids.map((id) => ({
|
|
2884
3128
|
id: ReasoningEffortId(id),
|
|
2885
3129
|
name: EFFORT_NAMES[id] ?? id
|
|
2886
3130
|
})),
|
|
2887
|
-
...defaultEffort
|
|
3131
|
+
...defaultEffort === void 0 ? {} : { defaultEffort: ReasoningEffortId(defaultEffort) }
|
|
2888
3132
|
};
|
|
2889
3133
|
}
|
|
2890
3134
|
/**
|
|
@@ -3078,11 +3322,11 @@ var QoderAdapter = class extends LlmAdapter {
|
|
|
3078
3322
|
}
|
|
3079
3323
|
async resolveModel(provider, model, _signal) {
|
|
3080
3324
|
const target = resolveQoderModelId(model, this.modelAliases);
|
|
3081
|
-
const live = (await this.catalog.liveModels()).find((entry) => entry.value === target);
|
|
3325
|
+
const live = (await cachedModels(this.catalog.snapshot(), () => this.catalog.liveModels())).find((entry) => entry.value === target);
|
|
3082
3326
|
if (live !== void 0) {
|
|
3083
3327
|
const vision = live.isVl === true;
|
|
3084
3328
|
this.knownVision.set(target, vision);
|
|
3085
|
-
const reasoning = reasoningInfo(live.efforts,
|
|
3329
|
+
const reasoning = reasoningInfo(live.efforts, this.defaultReasoningEffort, live.isReasoning);
|
|
3086
3330
|
return {
|
|
3087
3331
|
provider,
|
|
3088
3332
|
id: model,
|
|
@@ -3132,7 +3376,7 @@ var QoderAdapter = class extends LlmAdapter {
|
|
|
3132
3376
|
async capture(provider, model, signal) {
|
|
3133
3377
|
const info = await this.resolveModel(provider, model, signal);
|
|
3134
3378
|
const target = resolveQoderModelId(model, this.modelAliases);
|
|
3135
|
-
const live = (await this.catalog.liveModels()).find((entry) => entry.value === target);
|
|
3379
|
+
const live = (await cachedModels(this.catalog.snapshot(), () => this.catalog.liveModels())).find((entry) => entry.value === target);
|
|
3136
3380
|
const declared = info.context?.contextWindow;
|
|
3137
3381
|
return {
|
|
3138
3382
|
info,
|
|
@@ -3660,7 +3904,7 @@ var CodeBuddyCatalog = class {
|
|
|
3660
3904
|
* context-budget choice) use this instead of awaiting a refresh.
|
|
3661
3905
|
*/
|
|
3662
3906
|
snapshot(requested) {
|
|
3663
|
-
return this.snapshots.get(requested ?? readLive(this.region, "global"))?.models
|
|
3907
|
+
return this.snapshots.get(requested ?? readLive(this.region, "global"))?.models;
|
|
3664
3908
|
}
|
|
3665
3909
|
/** Models for one region; a failed refresh keeps the last good list. */
|
|
3666
3910
|
async models(requested) {
|
|
@@ -4998,7 +5242,7 @@ var CodeBuddyAdapter = class extends LlmAdapter {
|
|
|
4998
5242
|
async modelVision(model) {
|
|
4999
5243
|
const target = resolveCodeBuddyModelId(model, this.aliases);
|
|
5000
5244
|
const key = `${this.region}:${target}`;
|
|
5001
|
-
const live = (await this.catalog.
|
|
5245
|
+
const live = (await cachedModels(this.catalog.snapshot(), () => this.catalog.models())).find((entry) => entry.id === target);
|
|
5002
5246
|
if (live !== void 0) {
|
|
5003
5247
|
this.knownVision.set(key, live.vision);
|
|
5004
5248
|
return live.vision;
|
|
@@ -5085,7 +5329,7 @@ var CodeBuddyAdapter = class extends LlmAdapter {
|
|
|
5085
5329
|
}
|
|
5086
5330
|
/** The catalog snapshot the adapter last read (empty before the first read). */
|
|
5087
5331
|
models(region) {
|
|
5088
|
-
return this.catalog.snapshot(region);
|
|
5332
|
+
return this.catalog.snapshot(region) ?? [];
|
|
5089
5333
|
}
|
|
5090
5334
|
/** Whether this model lets the user pick a context budget at all. */
|
|
5091
5335
|
supportsContextWindowChoice(id, region = this.region) {
|
|
@@ -5102,10 +5346,10 @@ var CodeBuddyAdapter = class extends LlmAdapter {
|
|
|
5102
5346
|
async resolveModel(provider, model) {
|
|
5103
5347
|
const target = resolveCodeBuddyModelId(model, this.aliases);
|
|
5104
5348
|
const key = `${this.region}:${target}`;
|
|
5105
|
-
const live = (await this.catalog.models()).find((entry) => entry.id === target);
|
|
5349
|
+
const live = (await cachedModels(this.catalog.snapshot(), () => this.catalog.models())).find((entry) => entry.id === target);
|
|
5106
5350
|
if (live !== void 0) {
|
|
5107
5351
|
this.knownVision.set(key, live.vision);
|
|
5108
|
-
const reasoning = reasoningInfo(live.reasoningEfforts,
|
|
5352
|
+
const reasoning = reasoningInfo(live.reasoningEfforts, readLiveOptional(this.options.defaultReasoningEffort), (live.reasoningEfforts?.length ?? 0) > 0);
|
|
5109
5353
|
return {
|
|
5110
5354
|
provider,
|
|
5111
5355
|
id: model,
|
|
@@ -6646,6 +6890,15 @@ var MinimaxCatalog = class {
|
|
|
6646
6890
|
return cached?.models ?? [];
|
|
6647
6891
|
}
|
|
6648
6892
|
}
|
|
6893
|
+
/**
|
|
6894
|
+
* The last successful list for a region, without probing.
|
|
6895
|
+
*
|
|
6896
|
+
* The picker resolves a route on every switch; awaiting an ACP probe there
|
|
6897
|
+
* cost a process round-trip whenever the TTL had just expired.
|
|
6898
|
+
*/
|
|
6899
|
+
snapshot(requested) {
|
|
6900
|
+
return this.snapshots.get(requested ?? readLive(this.region, "cn"))?.models;
|
|
6901
|
+
}
|
|
6649
6902
|
/** Why the last refresh failed, or undefined when it succeeded. */
|
|
6650
6903
|
error(requested) {
|
|
6651
6904
|
return this.failures.get(requested ?? readLive(this.region, "cn"));
|
|
@@ -7828,10 +8081,10 @@ var MinimaxAdapter = class extends LlmAdapter {
|
|
|
7828
8081
|
const region = this.region;
|
|
7829
8082
|
const target = resolveMinimaxModelId(model, this.aliases);
|
|
7830
8083
|
const key = `${region}:${target}`;
|
|
7831
|
-
const live = (await this.catalog.models(region)).find((entry) => entry.id === target);
|
|
8084
|
+
const live = (await cachedModels(this.catalog.snapshot(region), () => this.catalog.models(region))).find((entry) => entry.id === target);
|
|
7832
8085
|
if (live !== void 0) {
|
|
7833
8086
|
this.knownVision.set(key, live.vision);
|
|
7834
|
-
const reasoning = reasoningInfo(live.reasoningEfforts,
|
|
8087
|
+
const reasoning = reasoningInfo(live.reasoningEfforts, readLiveOptional(this.options.defaultReasoningEffort), live.reasoning);
|
|
7835
8088
|
return {
|
|
7836
8089
|
provider,
|
|
7837
8090
|
id: model,
|
|
@@ -8146,11 +8399,21 @@ function startSetup(brand, mode, onFinish) {
|
|
|
8146
8399
|
* @param brand - which edition's run to report.
|
|
8147
8400
|
*/
|
|
8148
8401
|
function readSetupStatus(brand = "cn") {
|
|
8402
|
+
const installed = resolveQoderCli(brand) !== void 0;
|
|
8403
|
+
const cliVersion = installed ? installedCliVersion(brand) : void 0;
|
|
8404
|
+
const required = requiredCliVersion(brand);
|
|
8405
|
+
const build = {
|
|
8406
|
+
installed,
|
|
8407
|
+
...cliVersion === void 0 ? {} : { cliVersion },
|
|
8408
|
+
...required === void 0 ? {} : { requiredCliVersion: required },
|
|
8409
|
+
...cliVersion === void 0 || required === void 0 ? {} : { versionMismatch: cliVersion !== required }
|
|
8410
|
+
};
|
|
8149
8411
|
const run = current.get(brand);
|
|
8150
8412
|
if (run === void 0) return {
|
|
8151
8413
|
running: false,
|
|
8152
8414
|
lines: [],
|
|
8153
|
-
truncated: false
|
|
8415
|
+
truncated: false,
|
|
8416
|
+
...build
|
|
8154
8417
|
};
|
|
8155
8418
|
const lines = run.pending.trim() === "" ? run.lines : [...run.lines, run.pending.trim()];
|
|
8156
8419
|
return {
|
|
@@ -8162,10 +8425,35 @@ function readSetupStatus(brand = "cn") {
|
|
|
8162
8425
|
code: run.code ?? null
|
|
8163
8426
|
},
|
|
8164
8427
|
lines,
|
|
8165
|
-
truncated: run.truncated
|
|
8428
|
+
truncated: run.truncated,
|
|
8429
|
+
...build,
|
|
8430
|
+
...run.cancelled === true ? { cancelled: true } : {}
|
|
8166
8431
|
};
|
|
8167
8432
|
}
|
|
8168
8433
|
/**
|
|
8434
|
+
* Abandon the running helper for one edition.
|
|
8435
|
+
*
|
|
8436
|
+
* `qodercli login` waits for the browser to finish the callback, so closing
|
|
8437
|
+
* that tab left the page polling a process that would never return. Killing
|
|
8438
|
+
* the run turns it into a finished one (`code` null) so the page can offer the
|
|
8439
|
+
* buttons again instead of showing a spinner forever.
|
|
8440
|
+
*
|
|
8441
|
+
* @param brand - which edition's run to stop.
|
|
8442
|
+
* @returns whether a run was actually in flight.
|
|
8443
|
+
*/
|
|
8444
|
+
function cancelSetup(brand) {
|
|
8445
|
+
const run = current.get(brand);
|
|
8446
|
+
if (run === void 0 || run.finishedAt !== void 0) return false;
|
|
8447
|
+
run.lines.push("已取消:这次配置被手动终止,可以重新操作。");
|
|
8448
|
+
run.cancelled = true;
|
|
8449
|
+
try {
|
|
8450
|
+
run.child.kill();
|
|
8451
|
+
} catch {}
|
|
8452
|
+
run.finishedAt = Date.now();
|
|
8453
|
+
run.code = null;
|
|
8454
|
+
return true;
|
|
8455
|
+
}
|
|
8456
|
+
/**
|
|
8169
8457
|
* Abandon the running helper, if any.
|
|
8170
8458
|
*
|
|
8171
8459
|
* Called when the plugin is disposed. Killing `cmd.exe` does not reap the CLI it
|
|
@@ -8473,8 +8761,13 @@ async function handleApi(req, res, adapters) {
|
|
|
8473
8761
|
send(res, 200, readMinimaxSetupStatus());
|
|
8474
8762
|
return;
|
|
8475
8763
|
}
|
|
8764
|
+
if (parsed.mode === "cancel") {
|
|
8765
|
+
cancelSetup(postBrand);
|
|
8766
|
+
send(res, 200, readSetupStatus(postBrand));
|
|
8767
|
+
return;
|
|
8768
|
+
}
|
|
8476
8769
|
if (!isSetupMode(parsed.mode)) {
|
|
8477
|
-
send(res, 400, { error: "mode 只接受 configure、login 或
|
|
8770
|
+
send(res, 400, { error: "mode 只接受 configure、login、uninstall 或 cancel" });
|
|
8478
8771
|
return;
|
|
8479
8772
|
}
|
|
8480
8773
|
const qoder = adapters[postBrand];
|
|
@@ -8575,7 +8868,7 @@ const Config$1 = z$1.object({
|
|
|
8575
8868
|
maxSessions: z$1.number().step(1).min(1).max(64).default(8).description("同时保持的内层会话数上限,超出后按最久未使用关闭。每个会话是一个子进程。").volatile(),
|
|
8576
8869
|
modelCacheTtlSeconds: z$1.number().step(1).min(10).max(86400).default(300).description("模型列表缓存时长(秒)。调小可更快看到账号侧变化。").volatile(),
|
|
8577
8870
|
modelAliases: z$1.dict(z$1.string()).default({}).description("额外的模型别名映射:DSH 侧名称 → Qoder 模型 ID。内置 deepseek-v4-* 别名仍然生效。").volatile(),
|
|
8578
|
-
defaultReasoningEffort: z$1.string().default("").description("
|
|
8871
|
+
defaultReasoningEffort: z$1.string().default("").description("默认选用的思考档位;留空则用该模型支持的最强档位。").volatile(),
|
|
8579
8872
|
defaultMaxTokens: z$1.number().step(1).min(1).default(32e3).description("模型未声明输出上限时使用的输出上限。").volatile(),
|
|
8580
8873
|
toolResultTimeoutSeconds: z$1.number().step(1).min(5).max(3600).default(120).description("仅用于未配对 handler 的兜底时限(秒):正常工具调用会等宿主下一次请求携带结果,不按此超时。").volatile(),
|
|
8581
8874
|
catalogFetchTimeoutSeconds: z$1.number().step(1).min(1).max(300).default(20).description("拉取模型列表的时限(秒),超时后回退到内置列表。").volatile(),
|
package/lib/types/adapter.d.ts
CHANGED
|
@@ -131,15 +131,34 @@ export declare function cliContextWindow(live: WindowFacts | undefined, declared
|
|
|
131
131
|
* looked like 10%.
|
|
132
132
|
*/
|
|
133
133
|
export declare function resolveDeclaredWindow(live: WindowFacts | undefined, override: number | undefined, remembered: number | undefined, fallback: number): number;
|
|
134
|
+
/**
|
|
135
|
+
* The strongest level a model offers.
|
|
136
|
+
*
|
|
137
|
+
* Switching model or level must start at the most capable setting the route
|
|
138
|
+
* accepts, the same rule the sibling adapter plugin uses; the previous
|
|
139
|
+
* behaviour of following upstream's own default meant some models silently
|
|
140
|
+
* started one or two steps down (`CodeBuddy` advertises `high` as its default
|
|
141
|
+
* even when `max` is selectable).
|
|
142
|
+
*
|
|
143
|
+
* @param efforts - the levels the route accepts, in upstream order.
|
|
144
|
+
* @returns the strongest id, or undefined for a non-reasoning model.
|
|
145
|
+
*/
|
|
146
|
+
export declare function strongestEffort(efforts: readonly string[]): string | undefined;
|
|
134
147
|
/**
|
|
135
148
|
* Build the `reasoning` metadata block for a resolved model, or undefined
|
|
136
149
|
* when the model does not support reasoning.
|
|
150
|
+
*
|
|
151
|
+
* The starting level is the strongest one the model accepts, not the level
|
|
152
|
+
* upstream happens to name as its default: the user's explicit choice in the
|
|
153
|
+
* sibling plugin, applied here too. An explicit configuration value still wins
|
|
154
|
+
* when the model accepts it.
|
|
155
|
+
*
|
|
137
156
|
* @param efforts - CLI-reported effort ids (absent for reasoning-less models).
|
|
138
|
-
* @param
|
|
157
|
+
* @param configuredEffort - user-configured starting level, when any.
|
|
139
158
|
* @param isReasoning - whether the model supports reasoning per the CLI.
|
|
140
159
|
* @returns the harness reasoning metadata, or undefined to omit it.
|
|
141
160
|
*/
|
|
142
|
-
export declare function reasoningInfo(efforts: readonly string[] | undefined,
|
|
161
|
+
export declare function reasoningInfo(efforts: readonly string[] | undefined, configuredEffort: string | undefined, isReasoning: boolean | undefined): LlmModelReasoningInfo | undefined;
|
|
143
162
|
/**
|
|
144
163
|
* The Qoder-backed adapter. Session continuity, tool parking, and feed
|
|
145
164
|
* planning live here; chunk synthesis lives in the session's consumer.
|