dsh-agent-sdk-bridge 1.1.8 → 1.2.1

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/lib/index.js CHANGED
@@ -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
- ...process.env,
379
- PATH: `${cli.nodeDir}${path.delimiter}${process.env.PATH ?? ""}`,
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
- * A `QODERCLI_PATH` that names the other edition, when this one has no CLI.
397
+ * Why this edition has no usable CLI, when `QODERCLI_PATH` explains it.
398
+ *
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.
401
405
  *
402
- * The SDKs read that variable from the parent process before any option this
403
- * plugin can pass, so when it is foreign and this edition has nothing of its
404
- * own, the only honest answer is a configuration error — spawning the other
405
- * edition's CLI would answer with the other edition's account.
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
- push(path.join(dir, "bundle", `${pkg.name}.js`));
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) push(path.join(path.dirname(path.dirname(nodePath)), "lib", "node_modules"));
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
- return path.dirname(createRequire(import.meta.url).resolve(packageName));
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,7 +784,8 @@ var QoderModelCatalog = class {
664
784
  this.failure = void 0;
665
785
  return officialOnly(models);
666
786
  } catch (error) {
667
- this.failure = error instanceof Error ? error.message : String(error);
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
  }
@@ -724,7 +845,18 @@ var QoderModelCatalog = class {
724
845
  }
725
846
  });
726
847
  try {
727
- return await withTimeout$2(q.getAvailableModels({ fetchStrategy: "live" }), readLive(this.fetchTimeoutMs, DEFAULT_FETCH_TIMEOUT_MS));
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 [];
728
860
  } finally {
729
861
  await q.close().catch(() => void 0);
730
862
  }
@@ -2290,7 +2422,7 @@ var QoderSession = class {
2290
2422
  this.endTurn({
2291
2423
  kind: "error",
2292
2424
  failure: {
2293
- message: `qoder session died: ${String(error)}`,
2425
+ message: `qoder session died: ${cliFailureText(String(error), this.brand)}`,
2294
2426
  code: "TRANSPORT"
2295
2427
  }
2296
2428
  });
@@ -2750,6 +2882,10 @@ var QoderUsage = class {
2750
2882
  * @returns the reading; `error` carries a failed lookup instead of throwing.
2751
2883
  */
2752
2884
  async read(fresh = false) {
2885
+ if (resolveQoderCli(this.brand) === void 0) {
2886
+ this.cached = void 0;
2887
+ return this.missingCli();
2888
+ }
2753
2889
  const ttlMs = readLive(this.ttlMs, DEFAULT_USAGE_CACHE_TTL_MS);
2754
2890
  if (!fresh && this.cached !== void 0 && Date.now() - this.cached.at < ttlMs) return this.cached;
2755
2891
  this.inflight ??= this.fetch().finally(() => {
@@ -2763,11 +2899,21 @@ var QoderUsage = class {
2763
2899
  invalidate() {
2764
2900
  this.cached = void 0;
2765
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
+ }
2766
2911
  async fetch() {
2767
2912
  const at = Date.now();
2768
2913
  try {
2769
2914
  if (foreignCliOverride(this.brand) !== void 0) return {
2770
2915
  at,
2916
+ cliMissing: true,
2771
2917
  error: cliConflictMessage(this.brand)
2772
2918
  };
2773
2919
  const sdk = await loadSdk(this.brand);
@@ -2799,7 +2945,7 @@ var QoderUsage = class {
2799
2945
  const command = brandProfile(this.brand).cliCommands[0];
2800
2946
  return {
2801
2947
  at,
2802
- 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)
2803
2949
  };
2804
2950
  }
2805
2951
  }
@@ -3355,6 +3501,17 @@ var QoderAdapter = class extends LlmAdapter {
3355
3501
  }
3356
3502
  return pixels === 0 ? content.map((block) => block.type === "text" ? block.text : "").join("\n\n") : content;
3357
3503
  }
3504
+ /**
3505
+ * Drop every warm inner session without unloading the plugin.
3506
+ *
3507
+ * Signing out has to invalidate them: each holds a CLI process that already
3508
+ * loaded its credentials, so it would keep answering as the account that was
3509
+ * just signed out. The next turn starts a fresh process, which then reports
3510
+ * the signed-out state honestly.
3511
+ */
3512
+ closeSessions() {
3513
+ this.sessions.closeAll();
3514
+ }
3358
3515
  /** Tear down every warm inner session (plugin dispose). */
3359
3516
  close() {
3360
3517
  this.sessions.closeAll();
@@ -8131,11 +8288,12 @@ function scriptNameOf(brand) {
8131
8288
  const FLAGS = {
8132
8289
  configure: "--gui",
8133
8290
  login: "--login",
8291
+ logout: "--logout",
8134
8292
  uninstall: "--uninstall"
8135
8293
  };
8136
8294
  /** Whether a value is one of the modes the page may request. */
8137
8295
  function isSetupMode(value) {
8138
- return value === "configure" || value === "login" || value === "uninstall";
8296
+ return value === "configure" || value === "login" || value === "logout" || value === "uninstall";
8139
8297
  }
8140
8298
  /** Cap on kept output, so a chatty `npm install` cannot grow without bound. */
8141
8299
  const MAX_LINES = 400;
@@ -8189,7 +8347,7 @@ function startSetup(brand, mode, onFinish) {
8189
8347
  return {
8190
8348
  started: false,
8191
8349
  reason: "unsupported",
8192
- error: `一键${mode === "uninstall" ? "卸载" : "配置"}只支持 Windows,请在 CLI 所在机器上手动处理 ${command}。`
8350
+ error: `一键${mode === "uninstall" ? "卸载" : mode === "logout" ? "退出登录" : mode === "login" ? "重新登录" : "配置"}只支持 Windows,请在 CLI 所在机器上手动处理 ${command}。`
8193
8351
  };
8194
8352
  }
8195
8353
  const script = setupScriptPath(brand);
@@ -8253,11 +8411,21 @@ function startSetup(brand, mode, onFinish) {
8253
8411
  * @param brand - which edition's run to report.
8254
8412
  */
8255
8413
  function readSetupStatus(brand = "cn") {
8414
+ const installed = resolveQoderCli(brand) !== void 0;
8415
+ const cliVersion = installed ? installedCliVersion(brand) : void 0;
8416
+ const required = requiredCliVersion(brand);
8417
+ const build = {
8418
+ installed,
8419
+ ...cliVersion === void 0 ? {} : { cliVersion },
8420
+ ...required === void 0 ? {} : { requiredCliVersion: required },
8421
+ ...cliVersion === void 0 || required === void 0 ? {} : { versionMismatch: cliVersion !== required }
8422
+ };
8256
8423
  const run = current.get(brand);
8257
8424
  if (run === void 0) return {
8258
8425
  running: false,
8259
8426
  lines: [],
8260
- truncated: false
8427
+ truncated: false,
8428
+ ...build
8261
8429
  };
8262
8430
  const lines = run.pending.trim() === "" ? run.lines : [...run.lines, run.pending.trim()];
8263
8431
  return {
@@ -8269,10 +8437,35 @@ function readSetupStatus(brand = "cn") {
8269
8437
  code: run.code ?? null
8270
8438
  },
8271
8439
  lines,
8272
- truncated: run.truncated
8440
+ truncated: run.truncated,
8441
+ ...build,
8442
+ ...run.cancelled === true ? { cancelled: true } : {}
8273
8443
  };
8274
8444
  }
8275
8445
  /**
8446
+ * Abandon the running helper for one edition.
8447
+ *
8448
+ * `qodercli login` waits for the browser to finish the callback, so closing
8449
+ * that tab left the page polling a process that would never return. Killing
8450
+ * the run turns it into a finished one (`code` null) so the page can offer the
8451
+ * buttons again instead of showing a spinner forever.
8452
+ *
8453
+ * @param brand - which edition's run to stop.
8454
+ * @returns whether a run was actually in flight.
8455
+ */
8456
+ function cancelSetup(brand) {
8457
+ const run = current.get(brand);
8458
+ if (run === void 0 || run.finishedAt !== void 0) return false;
8459
+ run.lines.push("已取消:这次配置被手动终止,可以重新操作。");
8460
+ run.cancelled = true;
8461
+ try {
8462
+ run.child.kill();
8463
+ } catch {}
8464
+ run.finishedAt = Date.now();
8465
+ run.code = null;
8466
+ return true;
8467
+ }
8468
+ /**
8276
8469
  * Abandon the running helper, if any.
8277
8470
  *
8278
8471
  * Called when the plugin is disposed. Killing `cmd.exe` does not reap the CLI it
@@ -8580,16 +8773,22 @@ async function handleApi(req, res, adapters) {
8580
8773
  send(res, 200, readMinimaxSetupStatus());
8581
8774
  return;
8582
8775
  }
8776
+ if (parsed.mode === "cancel") {
8777
+ cancelSetup(postBrand);
8778
+ send(res, 200, readSetupStatus(postBrand));
8779
+ return;
8780
+ }
8583
8781
  if (!isSetupMode(parsed.mode)) {
8584
- send(res, 400, { error: "mode 只接受 configure、login 或 uninstall" });
8782
+ send(res, 400, { error: "mode 只接受 configure、login、logout、uninstall 或 cancel" });
8585
8783
  return;
8586
8784
  }
8587
8785
  const qoder = adapters[postBrand];
8588
- const result = startSetup(postBrand, parsed.mode, (code) => {
8589
- if (code === 0) {
8590
- qoder.invalidateCatalog();
8591
- qoder.invalidateUsage();
8592
- }
8786
+ const mode = parsed.mode;
8787
+ const result = startSetup(postBrand, mode, (code) => {
8788
+ if (code !== 0) return;
8789
+ qoder.invalidateCatalog();
8790
+ qoder.invalidateUsage();
8791
+ if (mode === "logout") qoder.closeSessions();
8593
8792
  });
8594
8793
  if (!result.started) {
8595
8794
  send(res, result.reason === "busy" ? 409 : result.reason === "unsupported" ? 501 : 500, { error: result.error });
@@ -290,6 +290,15 @@ export declare class QoderAdapter extends LlmAdapter {
290
290
  * still knows the attachment was there.
291
291
  */
292
292
  private buildFeed;
293
+ /**
294
+ * Drop every warm inner session without unloading the plugin.
295
+ *
296
+ * Signing out has to invalidate them: each holds a CLI process that already
297
+ * loaded its credentials, so it would keep answering as the account that was
298
+ * just signed out. The next turn starts a fresh process, which then reports
299
+ * the signed-out state honestly.
300
+ */
301
+ closeSessions(): void;
293
302
  /** Tear down every warm inner session (plugin dispose). */
294
303
  close(): void;
295
304
  }
@@ -90,17 +90,38 @@ export declare function qoderCliOptions(brand?: QoderBrand, lookup?: CliLookup):
90
90
  */
91
91
  export declare function isForeignCliPath(brand: QoderBrand, candidate: string): boolean;
92
92
  /**
93
- * A `QODERCLI_PATH` that names the other edition, when this one has no CLI.
93
+ * Why this edition has no usable CLI, when `QODERCLI_PATH` explains it.
94
94
  *
95
- * The SDKs read that variable from the parent process before any option this
96
- * plugin can pass, so when it is foreign and this edition has nothing of its
97
- * own, the only honest answer is a configuration error — spawning the other
98
- * edition's CLI would answer with the other edition's account.
95
+ * `QODERCLI_PATH` predates the international edition and some installers
96
+ * export it machine-wide. Both SDKs read it from the parent process before any
97
+ * option this plugin can pass, so a value naming the *other* edition would
98
+ * hand this edition's session the other account. The lookup therefore never
99
+ * offers it ({@link isForeignCliPath}), and this reports the case where it is
100
+ * all the machine has, so the page can ask for the right CLI to be installed.
101
+ *
102
+ * This is a diagnosis, not a second rule: an edition that finds its own CLI is
103
+ * unaffected by the variable. That is what keeps one edition's install from
104
+ * blocking the other's sign-in — the earlier code treated any foreign value as
105
+ * fatal, so a machine that had only the intl CLI installed could not sign in
106
+ * to CN even after installing it if the lookup missed the new package.
99
107
  *
100
108
  * @param brand - the edition the caller is about to start.
101
109
  * @param lookup - the machine to inspect; defaults to this process's.
110
+ * @returns the foreign override when this edition has nothing of its own.
102
111
  */
103
112
  export declare function foreignCliOverride(brand: QoderBrand, lookup?: CliLookup): string | undefined;
113
+ /**
114
+ * The environment one session's child process receives.
115
+ *
116
+ * `QODERCLI_PATH` is stripped when it names the other edition: both SDKs read
117
+ * it from the parent before honouring any option, so leaving it in place would
118
+ * hand the intl session the CN CLI (and the CN account). Every other variable
119
+ * is inherited untouched — the CLI keeps its state in `PATH`-relative dirs.
120
+ *
121
+ * @param brand - which edition's child is being started.
122
+ * @param env - the environment to derive from; defaults to this process's.
123
+ */
124
+ export declare function cliChildEnv(brand: QoderBrand, env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
104
125
  /**
105
126
  * The error text for {@link foreignCliOverride}.
106
127
  *
@@ -109,3 +130,42 @@ export declare function foreignCliOverride(brand: QoderBrand, lookup?: CliLookup
109
130
  * plugin's environment plumbing. The technical reason stays in the lookup.
110
131
  */
111
132
  export declare function cliConflictMessage(brand: QoderBrand): string;
133
+ /**
134
+ * Turn a CLI failure into something a user can act on.
135
+ *
136
+ * The SDK reports an outdated CLI as `Qoder CLI process exited with code 42`,
137
+ * which says nothing about the cause: CLI 1.1.81 removed the worker-session
138
+ * handshake the older SDK spoke, and its own log says so
139
+ * (`sdk_worker_removed: … Upgrade to the latest Qoder SDK version, or roll back
140
+ * the CLI`). The only fix available to a user is reinstalling the pair through
141
+ * the bundled helper, so say that instead of echoing the number.
142
+ *
143
+ * @param detail - the error text as the SDK reported it.
144
+ * @param brand - which edition's helper the message should name.
145
+ * @returns the original detail, prefixed with the actionable explanation.
146
+ */
147
+ export declare function cliFailureText(detail: string, brand: QoderBrand): string;
148
+ /**
149
+ * The CLI version the installed SDK expects, read from its runtime manifest.
150
+ *
151
+ * Each SDK release pins one CLI build: the two speak a wire protocol that
152
+ * changes between them, and a mismatch fails every session with a bare exit
153
+ * code. The bundled helper reads the same file, so the page and the helper
154
+ * agree on which build to install.
155
+ *
156
+ * @param brand - which edition's SDK to inspect.
157
+ * @returns the pinned version, or undefined when the manifest is unreadable.
158
+ */
159
+ export declare function requiredCliVersion(brand: QoderBrand): string | undefined;
160
+ /**
161
+ * The version of the installed CLI, read from its own package manifest.
162
+ *
163
+ * Read from disk rather than by running `--version`: a settings-page poll must
164
+ * not spawn a process every second, and the npm package always ships a
165
+ * manifest next to its entry. A native build without one answers undefined,
166
+ * which callers treat as "unknown" and never as a mismatch.
167
+ *
168
+ * @param brand - which edition's CLI to inspect.
169
+ * @returns the installed version, or undefined when it cannot be read.
170
+ */
171
+ export declare function installedCliVersion(brand: QoderBrand): string | undefined;
@@ -21,8 +21,8 @@ import type { QoderBrand } from './brand.ts';
21
21
  export declare const SCRIPT_NAME = "setup-qoderclicn.bat";
22
22
  /** The helper script for one edition. */
23
23
  export declare function scriptNameOf(brand: QoderBrand): string;
24
- /** What the page may ask for: install/sign in, only sign in, or uninstall. */
25
- export type SetupMode = 'configure' | 'login' | 'uninstall';
24
+ /** What the page may ask for: install/sign in, only sign in, sign out, uninstall. */
25
+ export type SetupMode = 'configure' | 'login' | 'logout' | 'uninstall';
26
26
  /** Whether a value is one of the modes the page may request. */
27
27
  export declare function isSetupMode(value: unknown): value is SetupMode;
28
28
  /** Snapshot the page polls. Always safe to render; empty before the first run. */
@@ -35,6 +35,27 @@ export interface SetupStatus {
35
35
  code?: number | null;
36
36
  lines: string[];
37
37
  truncated: boolean;
38
+ /**
39
+ * Whether this edition's CLI is on the machine right now.
40
+ *
41
+ * Read from the same lookup a session uses, not from the last run's exit
42
+ * code: after an uninstall the page must offer "install" again, and a run
43
+ * that ended successfully months ago says nothing about today's machine.
44
+ */
45
+ installed: boolean;
46
+ /** Version of the installed CLI, when its package manifest could be read. */
47
+ cliVersion?: string;
48
+ /** Version this plugin's SDK speaks; the helper installs exactly this one. */
49
+ requiredCliVersion?: string;
50
+ /**
51
+ * The installed CLI speaks a different protocol build than the SDK.
52
+ *
53
+ * Sessions then die with a bare exit code, so the page warns here — before a
54
+ * sign-in — instead of letting the user log in and hit the failure in chat.
55
+ */
56
+ versionMismatch?: boolean;
57
+ /** Whether the last run was stopped from the page rather than finishing. */
58
+ cancelled?: boolean;
38
59
  }
39
60
  /**
40
61
  * Locate one edition's helper inside this package.
@@ -69,6 +90,18 @@ export declare function startSetup(brand: QoderBrand, mode: SetupMode, onFinish?
69
90
  * @param brand - which edition's run to report.
70
91
  */
71
92
  export declare function readSetupStatus(brand?: QoderBrand): SetupStatus;
93
+ /**
94
+ * Abandon the running helper for one edition.
95
+ *
96
+ * `qodercli login` waits for the browser to finish the callback, so closing
97
+ * that tab left the page polling a process that would never return. Killing
98
+ * the run turns it into a finished one (`code` null) so the page can offer the
99
+ * buttons again instead of showing a spinner forever.
100
+ *
101
+ * @param brand - which edition's run to stop.
102
+ * @returns whether a run was actually in flight.
103
+ */
104
+ export declare function cancelSetup(brand: QoderBrand): boolean;
72
105
  /**
73
106
  * Abandon the running helper, if any.
74
107
  *
@@ -31,6 +31,16 @@ export interface UsageSnapshot {
31
31
  account?: AccountInfo;
32
32
  /** Why the quota is missing, in the CLI's own words. */
33
33
  error?: string;
34
+ /**
35
+ * Whether this edition's CLI is absent from the machine right now.
36
+ *
37
+ * The page keeps its last good reading visible while a refresh fails, which
38
+ * is right for a dropped network — but not after an uninstall: the account,
39
+ * plan and credits it shows belong to a CLI that is no longer installed.
40
+ * This flag tells the page to drop that reading instead of labelling it
41
+ * "last reading".
42
+ */
43
+ cliMissing?: boolean;
34
44
  }
35
45
  /** Cached quota reader for one brand. */
36
46
  export declare class QoderUsage {
@@ -54,5 +64,7 @@ export declare class QoderUsage {
54
64
  read(fresh?: boolean): Promise<UsageSnapshot>;
55
65
  /** Drop the cached reading. */
56
66
  invalidate(): void;
67
+ /** The reading for a machine whose CLI is not installed. */
68
+ private missingCli;
57
69
  private fetch;
58
70
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "dsh-agent-sdk-bridge",
3
3
  "displayName": "Agent SDK Bridge",
4
4
  "description": "DeepSeek Harness LLM adapter bridge for Qoder CN, Qoder International, Tencent CodeBuddy and MiniMax Code subscriptions. It reuses each provider's own SDK or official ACP server and CLI login, shows available quota, and exposes per-provider settings pages with independent international and mainland login regions.",
5
- "version": "1.1.8",
5
+ "version": "1.2.1",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "author": "k1-h2",
@@ -85,8 +85,8 @@
85
85
  },
86
86
  "dependencies": {
87
87
  "@agentclientprotocol/sdk": "^1.9.0",
88
- "@qoder-ai/qoder-agent-sdk": "^1.0.56",
89
- "@qodercn-ai/qodercn-agent-sdk": "^1.0.51",
88
+ "@qoder-ai/qoder-agent-sdk": "^1.0.58",
89
+ "@qodercn-ai/qodercn-agent-sdk": "^1.0.58",
90
90
  "@tencent-ai/agent-sdk": "^0.3.289",
91
91
  "zod": "^4.4.3"
92
92
  },