dsh-opendesign-corouter 0.1.17 → 0.1.18

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.
@@ -1,6 +1,6 @@
1
1
  # 第三方代码与资料
2
2
 
3
- 本项目的消息/图片兼容处理、套餐模型元数据参考 [dsh-opendesign-go 0.1.9](https://github.com/EliteOtaku/dsh-opendesign-go)。额度归一化及登录生命周期的基础处理改编自 [dsh-subusage 0.16.2](https://github.com/KouzakiUmi/dsh-subusage);临时授权窗口的 Chrome 启动策略改编自 [dsh-subusage 0.16.3](https://github.com/KouzakiUmi/dsh-subusage) 的 `lib/cookie-login.js`。空轮判定参考 [dsh-empty-turn-guard 0.4.0](https://github.com/FYTXY/dsh-empty-turn-guard)。设置布局参考 [dsh-code-pill](https://github.com/KouzakiUmi/dsh-code-pill)。
3
+ 本项目的消息/图片兼容处理、套餐模型元数据、思考增量拼写兼容与配置写入的重试策略参考 [dsh-opendesign-go 0.1.11](https://github.com/EliteOtaku/dsh-opendesign-go)。额度归一化及登录生命周期的基础处理改编自 [dsh-subusage 0.16.2](https://github.com/KouzakiUmi/dsh-subusage);临时授权窗口的 Chrome 启动策略改编自 [dsh-subusage 0.16.3](https://github.com/KouzakiUmi/dsh-subusage) 的 `lib/cookie-login.js`。空轮判定参考 [dsh-empty-turn-guard 0.4.0](https://github.com/FYTXY/dsh-empty-turn-guard)。设置布局参考 [dsh-code-pill](https://github.com/KouzakiUmi/dsh-code-pill)。
4
4
 
5
5
  离线主题夹具使用 [DeepSeek Harness 官方主题令牌](https://github.com/deepseek-ai/deepseek-harness/blob/22ddee3792402c3e70ec5f86a63c3e3e895a2f60/packages/client/ui-theme/src/styles/design-platform.css),仅供测试,不随插件安装包分发。
6
6
 
@@ -8,7 +8,8 @@
8
8
  *
9
9
  * The coordinator talks to the Host configuration form only: it projects the value a caller
10
10
  * wants to save, hands the write to the form, and hands the value back to the form snapshot once
11
- * the write is done.
11
+ * the write is done. A clear travels the same queue but asks the form to drop the field, because
12
+ * an empty value and an unnamed field are different states for the Host.
12
13
  */
13
14
  import type { ConfigForm, FormValues } from './client.js';
14
15
  export interface ConfigWriteSnapshot {
@@ -29,6 +30,13 @@ export interface ConfigWrites {
29
30
  * already has a pending write, or when the Host rejects the write.
30
31
  */
31
32
  set(field: string, value: unknown, baseValue?: unknown): Promise<boolean>;
33
+ /**
34
+ * Queue one field clear.
35
+ *
36
+ * A cleared field goes back to being unnamed: the Host drops it from the profile instead of
37
+ * storing an empty value. Returns false when the Host offers no clear path.
38
+ */
39
+ clear(field: string): Promise<boolean>;
32
40
  /** Stop the coordinator: queued writes never start and subscribers are released. */
33
41
  dispose(): void;
34
42
  }
package/lib/client.d.ts CHANGED
@@ -7,6 +7,8 @@ import { type ApiProtocol } from './protocol-options.js';
7
7
  import type { ModelSettings, ModelSettingsMap } from './model-settings.js';
8
8
  import { type ContextWindowPresetId } from './context-budget.js';
9
9
  import { type ModelDirectoryService } from './client-context-quick.js';
10
+ /** Must match `DEFAULT_API_KEY_REF` in src/config.ts; the browser bundle keeps its own copy. */
11
+ export declare const DEFAULT_KEY_REF = "COROUTER_API_KEY";
10
12
  declare const TABS: readonly [{
11
13
  readonly id: "overview";
12
14
  readonly label: "概览";
@@ -46,6 +48,8 @@ export interface ConfigForm {
46
48
  getSnapshot(): FormSnapshot;
47
49
  subscribe(listener: () => void): () => void;
48
50
  set(field: string, value: unknown): Promise<boolean>;
51
+ /** Drop one field back to unnamed; absent on a Host that only writes values. */
52
+ unset?(field: string): Promise<boolean>;
49
53
  }
50
54
  export interface ConfigForms {
51
55
  get(namespace: string): ConfigForm;
@@ -237,9 +241,10 @@ export interface AdvancedProps {
237
241
  status: Status | undefined;
238
242
  formSnapshot: FormSnapshot;
239
243
  setFormField: (field: string, value: unknown) => Promise<boolean>;
244
+ clearFormField: (field: string) => Promise<boolean>;
240
245
  pendingField: readonly string[];
241
246
  }
242
- export declare function Advanced({ status, formSnapshot, setFormField, pendingField }: AdvancedProps): React.FunctionComponentElement<{
247
+ export declare function Advanced({ status, formSnapshot, setFormField, clearFormField, pendingField }: AdvancedProps): React.FunctionComponentElement<{
243
248
  children?: React.ReactNode | undefined;
244
249
  }>;
245
250
  /** Approval is an ordinary official link; the Host may also show it in a temporary window. */
package/lib/client.js CHANGED
@@ -32,6 +32,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
32
32
  var client_exports = {};
33
33
  __export(client_exports, {
34
34
  Advanced: () => Advanced,
35
+ DEFAULT_KEY_REF: () => DEFAULT_KEY_REF,
35
36
  LoginApproval: () => LoginApproval,
36
37
  ModelRow: () => ModelRow,
37
38
  Models: () => Models,
@@ -20238,8 +20239,11 @@ function parseStatusModel(value) {
20238
20239
  }
20239
20240
  function parseStatusConfig(value) {
20240
20241
  if (!record2(value)) throw new Error("\u914D\u7F6E\u89C6\u56FE\u5FC5\u987B\u662F\u5BF9\u8C61");
20241
- const apiKeyEnv = text(value.apiKeyEnv, "\u51ED\u636E\u5F15\u7528\u540D", MAX_ENV_REF);
20242
- if (!ENV_REF.test(apiKeyEnv)) throw new Error("\u51ED\u636E\u5F15\u7528\u540D\u5FC5\u987B\u662F\u5408\u6CD5\u6807\u8BC6\u7B26");
20242
+ if (typeof value.apiKeyEnv !== "string" || value.apiKeyEnv.length > MAX_ENV_REF) {
20243
+ throw new Error(`\u51ED\u636E\u5F15\u7528\u540D\u5FC5\u987B\u662F\u6700\u591A ${MAX_ENV_REF} \u5B57\u7B26\u7684\u5B57\u7B26\u4E32`);
20244
+ }
20245
+ const apiKeyEnv = value.apiKeyEnv;
20246
+ if (apiKeyEnv !== "" && !ENV_REF.test(apiKeyEnv)) throw new Error("\u51ED\u636E\u5F15\u7528\u540D\u5FC5\u987B\u662F\u5408\u6CD5\u6807\u8BC6\u7B26");
20243
20247
  return {
20244
20248
  emptyTurnGuard: flag(value.emptyTurnGuard, "\u7A7A\u8F6E\u4FDD\u62A4\u5F00\u5173"),
20245
20249
  ...value.turnCompletionReview === void 0 ? {} : { turnCompletionReview: flag(value.turnCompletionReview, "\u7ED3\u675F\u56DE\u5408\u6838\u9A8C\u5F00\u5173") },
@@ -20415,18 +20419,24 @@ var ConfigWritesImpl = class {
20415
20419
  };
20416
20420
  }
20417
20421
  async set(field, value, baseValue) {
20422
+ return this.enqueue(field, value, baseValue, false);
20423
+ }
20424
+ async clear(field) {
20425
+ return this.enqueue(field, void 0, void 0, true);
20426
+ }
20427
+ async enqueue(field, value, baseValue, clear) {
20418
20428
  if (this.disposed) return false;
20419
20429
  const current = this.form.getSnapshot();
20420
20430
  if (!writableSnapshot(current)) return false;
20421
20431
  if (this.inflight.has(field)) return false;
20422
20432
  const baseline = baseValue !== void 0 ? baseValue : readField(current.value, field);
20423
- const task = { field, value, baseline, resolve: () => {
20433
+ const task = { field, value, baseline, clear, resolve: () => {
20424
20434
  } };
20425
20435
  const accepted = new Promise((resolve) => {
20426
20436
  task.resolve = resolve;
20427
20437
  });
20428
20438
  this.inflight.set(field, task);
20429
- this.overlay.set(field, value);
20439
+ if (!clear) this.overlay.set(field, value);
20430
20440
  this.publish();
20431
20441
  this.queue.push(task);
20432
20442
  this.drain();
@@ -20469,6 +20479,15 @@ var ConfigWritesImpl = class {
20469
20479
  if (this.disposed) return false;
20470
20480
  const current = this.form.getSnapshot();
20471
20481
  if (!writableSnapshot(current)) return false;
20482
+ if (task.clear) {
20483
+ const unset = this.form.unset;
20484
+ if (unset === void 0) return false;
20485
+ try {
20486
+ return await unset.call(this.form, task.field) === true;
20487
+ } catch {
20488
+ return false;
20489
+ }
20490
+ }
20472
20491
  let payload = task.value;
20473
20492
  if (task.field === "modelSettings") {
20474
20493
  const rebased = rebaseModelSettings(task.baseline, task.value, readField(current.value, "modelSettings"));
@@ -20821,6 +20840,7 @@ function ContextQuickControl({ provider, modelId, selecting, directoryUnavailabl
20821
20840
  // src/client.ts
20822
20841
  var h2 = React2.createElement;
20823
20842
  var SETTINGS_NS = "llm-opendesign-corouter";
20843
+ var DEFAULT_KEY_REF = "COROUTER_API_KEY";
20824
20844
  var OFFICIAL_SITE = "https://corouter.open-design.ai/zh/";
20825
20845
  var TABS = [
20826
20846
  { id: "overview", label: "\u6982\u89C8" },
@@ -22082,13 +22102,14 @@ function NumberField({ id, label, hint, value, min, max, integer: integer2, disa
22082
22102
  }, error62 ?? hint)
22083
22103
  );
22084
22104
  }
22085
- function Advanced({ status, formSnapshot, setFormField, pendingField }) {
22105
+ function Advanced({ status, formSnapshot, setFormField, clearFormField, pendingField }) {
22086
22106
  const [apiKeyEnv, setApiKeyEnv] = React2.useState(status?.config.apiKeyEnv ?? "");
22087
22107
  const [keyNotice, setKeyNotice] = React2.useState(null);
22088
22108
  const mounted = useMounted();
22109
+ const formReady = formSnapshot.status === "ready" && formSnapshot.value !== void 0;
22089
22110
  React2.useEffect(() => {
22090
- setApiKeyEnv(formSnapshot.value?.apiKeyEnv ?? status?.config.apiKeyEnv ?? "");
22091
- }, [formSnapshot.value?.apiKeyEnv, status?.config.apiKeyEnv]);
22111
+ setApiKeyEnv(formReady ? formSnapshot.value?.apiKeyEnv ?? "" : status?.config.apiKeyEnv ?? "");
22112
+ }, [formReady, formSnapshot.value?.apiKeyEnv, status?.config.apiKeyEnv]);
22092
22113
  const writable = formSnapshot.status === "ready" && formSnapshot.value !== void 0 && formSnapshot.writable;
22093
22114
  const configuredProtocol = formSnapshot.value?.apiProtocol ?? status?.config.apiProtocol;
22094
22115
  const protocol = configuredProtocol !== void 0 && API_PROTOCOL_OPTIONS.some((option) => option.id === configuredProtocol) ? configuredProtocol : "chat-completions";
@@ -22104,6 +22125,30 @@ function Advanced({ status, formSnapshot, setFormField, pendingField }) {
22104
22125
  const selected = API_PROTOCOL_OPTIONS.find((option) => option.id === protocol);
22105
22126
  const saveKeyRef = async () => {
22106
22127
  const value = apiKeyEnv.trim();
22128
+ if (value === "") {
22129
+ const saved = formReady ? formSnapshot.value?.apiKeyEnv : void 0;
22130
+ if (saved === void 0) {
22131
+ setKeyNotice({ kind: "status", text: `\u5F53\u524D\u672A\u586B\u5199\u5F15\u7528\u540D\uFF1B\u8BF7\u6C42\u6CBF\u7528\u9ED8\u8BA4\u5F15\u7528 ${DEFAULT_KEY_REF}\uFF0C\u65E0\u9700\u4FDD\u5B58\u3002` });
22132
+ return;
22133
+ }
22134
+ setKeyNotice(null);
22135
+ try {
22136
+ const cleared = await clearFormField("apiKeyEnv");
22137
+ if (mounted.current) {
22138
+ if (cleared) setKeyNotice({ kind: "status", text: `\u5DF2\u6E05\u9664\u5F15\u7528\u540D\uFF1B\u8BF7\u6C42\u6CBF\u7528\u9ED8\u8BA4\u5F15\u7528 ${DEFAULT_KEY_REF}\u3002` });
22139
+ else {
22140
+ setApiKeyEnv(saved);
22141
+ setKeyNotice({ kind: "error", text: "\u5F15\u7528\u540D\u672A\u6E05\u9664\uFF0C\u5DF2\u4FDD\u7559\u539F\u503C\uFF0C\u8BF7\u91CD\u8BD5\u3002" });
22142
+ }
22143
+ }
22144
+ } catch {
22145
+ if (mounted.current) {
22146
+ setApiKeyEnv(saved);
22147
+ setKeyNotice({ kind: "error", text: GENERIC_ERROR });
22148
+ }
22149
+ }
22150
+ return;
22151
+ }
22107
22152
  if (!/^[A-Za-z_][A-Za-z0-9_]{0,127}$/u.test(value)) {
22108
22153
  setKeyNotice({ kind: "error", text: "\u5F15\u7528\u540D\u9700\u4E3A 1\u2013128 \u4F4D\u5B57\u6BCD\u3001\u6570\u5B57\u6216\u4E0B\u5212\u7EBF\uFF0C\u4E14\u4E0D\u80FD\u4EE5\u6570\u5B57\u5F00\u5934\u3002" });
22109
22154
  return;
@@ -22208,7 +22253,7 @@ function Advanced({ status, formSnapshot, setFormField, pendingField }) {
22208
22253
  "section",
22209
22254
  { className: "odc-card" },
22210
22255
  h2("h3", null, "\u51ED\u636E\u4E0E\u7F51\u5173"),
22211
- h2("p", { className: "odc-hint" }, "\u8FD9\u91CC\u53EA\u4FDD\u5B58\u51ED\u636E\u5F15\u7528\u540D\u79F0\uFF0C\u4E0D\u586B\u5199 Key \u672C\u8EAB\uFF1B\u7F51\u5173\u5730\u5740\u7531\u63D2\u4EF6\u914D\u7F6E\u6258\u7BA1\u3002"),
22256
+ h2("p", { className: "odc-hint" }, `\u8FD9\u91CC\u53EA\u4FDD\u5B58\u51ED\u636E\u5F15\u7528\u540D\u79F0\uFF0C\u4E0D\u586B\u5199 Key \u672C\u8EAB\uFF1B\u7F51\u5173\u5730\u5740\u7531\u63D2\u4EF6\u914D\u7F6E\u6258\u7BA1\u3002\u5F15\u7528\u540D\u7559\u7A7A\u65F6\u8BF7\u6C42\u6CBF\u7528 ${DEFAULT_KEY_REF}\uFF0C\u4FDD\u5B58\u7A7A\u503C\u5373\u6E05\u9664\u5DF2\u4FDD\u5B58\u7684\u5F15\u7528\u540D\u3002`),
22212
22257
  h2(
22213
22258
  "div",
22214
22259
  { className: "odc-field" },
@@ -22218,12 +22263,13 @@ function Advanced({ status, formSnapshot, setFormField, pendingField }) {
22218
22263
  className: "odc-input",
22219
22264
  type: "text",
22220
22265
  value: apiKeyEnv,
22266
+ placeholder: DEFAULT_KEY_REF,
22221
22267
  disabled: !writable || pendingField.includes("apiKeyEnv"),
22222
22268
  autoCapitalize: "off",
22223
22269
  spellCheck: false,
22224
22270
  onChange: (event) => setApiKeyEnv(event.target.value)
22225
22271
  }),
22226
- h2("small", { className: "odc-hint" }, "\u5F15\u7528\u540D\u5BF9\u5E94\u7684\u51ED\u636E\u4ECD\u4F18\u5148\u4E8E\u672C\u63D2\u4EF6\u4FDD\u5B58\u7684 Key\u3002")
22272
+ h2("small", { className: "odc-hint" }, "\u5F15\u7528\u540D\u5BF9\u5E94\u7684\u51ED\u636E\u4ECD\u4F18\u5148\u4E8E\u672C\u63D2\u4EF6\u4FDD\u5B58\u7684 Key\uFF1BDSH \u6A21\u578B\u9875\u53EA\u62A5\u544A\u8FD9\u91CC\u8BBE\u7F6E\u7684\u5F15\u7528\u540D\uFF0C\u4E0D\u663E\u793A\u672C\u63D2\u4EF6\u4FDD\u5B58\u7684 Key \u4E0E\u8BBE\u5907\u767B\u5F55\u3002")
22227
22273
  ),
22228
22274
  h2(
22229
22275
  "div",
@@ -22441,7 +22487,7 @@ function Connection({ status, formSnapshot, setFormField, pendingField, caller,
22441
22487
  if (!mounted.current || version2 !== actionVersion.current) return;
22442
22488
  setApiKey("");
22443
22489
  onStatus(next);
22444
- setNotice({ kind: "status", text: next.apiKeySource === "reference" ? `API Key \u5DF2\u4FDD\u5B58\uFF1B\u5F53\u524D\u4ECD\u4F18\u5148\u4F7F\u7528\u73AF\u5883\u6216\u51ED\u636E\u5F15\u7528 ${next.config.apiKeyEnv}\u3002` : next.apiKeySource === "stored" ? "API Key \u5DF2\u4FDD\u5B58\u5E76\u7528\u4E8E\u5F53\u524D\u7F51\u5173\u3002" : "API Key \u5DF2\u4FDD\u5B58\u3002" });
22490
+ setNotice({ kind: "status", text: next.apiKeySource === "reference" ? `API Key \u5DF2\u4FDD\u5B58\uFF1B\u5F53\u524D\u4ECD\u4F18\u5148\u4F7F\u7528\u73AF\u5883\u6216\u51ED\u636E\u5F15\u7528 ${next.config.apiKeyEnv || DEFAULT_KEY_REF}\u3002` : next.apiKeySource === "stored" ? "API Key \u5DF2\u4FDD\u5B58\u5E76\u7528\u4E8E\u5F53\u524D\u7F51\u5173\u3002" : "API Key \u5DF2\u4FDD\u5B58\u3002" });
22445
22491
  } catch {
22446
22492
  if (!mounted.current || version2 !== actionVersion.current) return;
22447
22493
  setApiKey("");
@@ -22477,7 +22523,7 @@ function Connection({ status, formSnapshot, setFormField, pendingField, caller,
22477
22523
  }
22478
22524
  }, [state, login?.jobId, busy, keyBusy, opening, status]);
22479
22525
  const desktopChecked = formSnapshot.value?.useDesktopCredential ?? status?.config.useDesktopCredential ?? true;
22480
- const keySource = status?.apiKeySource === "reference" ? `\u73AF\u5883\u6216\u51ED\u636E\u5F15\u7528\uFF08${status.config.apiKeyEnv}\uFF09` : status?.apiKeySource === "stored" ? "\u5DF2\u4FDD\u5B58\u7684 API Key" : status?.apiKeySource === "device" ? "\u8BBE\u5907\u6388\u6743" : status?.apiKeyConfigured ? "\u5C1A\u672A\u786E\u8BA4" : "\u672A\u914D\u7F6E";
22526
+ const keySource = status?.apiKeySource === "reference" ? `\u73AF\u5883\u6216\u51ED\u636E\u5F15\u7528\uFF08${status.config.apiKeyEnv || DEFAULT_KEY_REF}\uFF09` : status?.apiKeySource === "stored" ? "\u5DF2\u4FDD\u5B58\u7684 API Key" : status?.apiKeySource === "device" ? "\u8BBE\u5907\u6388\u6743" : status?.apiKeyConfigured ? "\u5C1A\u672A\u786E\u8BA4" : "\u672A\u914D\u7F6E";
22481
22527
  return h2(
22482
22528
  React2.Fragment,
22483
22529
  null,
@@ -22697,6 +22743,27 @@ function SettingsPage({ caller, form }) {
22697
22743
  }
22698
22744
  }
22699
22745
  }, [form, mounted, refresh, writes]);
22746
+ const clearFormField = React2.useCallback(async (field) => {
22747
+ const snapshot = form.getSnapshot();
22748
+ if (snapshot.status !== "ready" || snapshot.value === void 0 || !snapshot.writable || writes.getSnapshot().pendingFields.includes(field)) return false;
22749
+ if (writes.getSnapshot().pendingFields.length === 0) batchWriteFailed.current = false;
22750
+ pageBatchActive.current = true;
22751
+ setFormNotice({ kind: "status", text: "\u6B63\u5728\u4FDD\u5B58\u8BBE\u7F6E\u2026" });
22752
+ try {
22753
+ const accepted = await writes.clear(field);
22754
+ if (!accepted) batchWriteFailed.current = true;
22755
+ if (accepted && mounted.current) void loadStatus();
22756
+ return accepted;
22757
+ } catch {
22758
+ batchWriteFailed.current = true;
22759
+ return false;
22760
+ } finally {
22761
+ if (mounted.current && writes.getSnapshot().pendingFields.length === 0) {
22762
+ pageBatchActive.current = false;
22763
+ setFormNotice(batchWriteFailed.current ? { kind: "error", text: "\u8BBE\u7F6E\u672A\u4FDD\u5B58\uFF0C\u5DF2\u6062\u590D\u539F\u503C\uFF0C\u8BF7\u91CD\u8BD5\u3002" } : { kind: "status", text: "\u8BBE\u7F6E\u5DF2\u4FDD\u5B58\u3002" });
22764
+ }
22765
+ }
22766
+ }, [form, mounted, writes, loadStatus]);
22700
22767
  const refreshModelsBusy = React2.useRef(false);
22701
22768
  const refreshModels = React2.useCallback(async () => {
22702
22769
  if (refreshModelsBusy.current) return;
@@ -22820,7 +22887,7 @@ function SettingsPage({ caller, form }) {
22820
22887
  } else if (tab === "connection") {
22821
22888
  content = h2(Connection, { status, formSnapshot, setFormField, pendingField, caller, onLoginStatus: acceptLoginStatus, onStatus: acceptStatus });
22822
22889
  } else {
22823
- content = h2(Advanced, { status, formSnapshot, setFormField, pendingField });
22890
+ content = h2(Advanced, { status, formSnapshot, setFormField, clearFormField, pendingField });
22824
22891
  }
22825
22892
  return h2(
22826
22893
  "div",
package/lib/config.d.ts CHANGED
@@ -7,8 +7,17 @@ export declare const SETTINGS_NS = "llm-opendesign-corouter";
7
7
  export declare const PLAN_PROVIDER = "opendesign-corouter-plan";
8
8
  export declare const PAID_PROVIDER = "opendesign-corouter-paid";
9
9
  export declare const DEFAULT_BASE_URL = "https://amr-link.open-design.ai/v1";
10
+ /**
11
+ * Reference resolved when no profile names one.
12
+ *
13
+ * The Host's model page reads a *named* reference out of this namespace and reports it as
14
+ * missing whenever that reference holds nothing, so an unset owner must stay unset: a schema
15
+ * default would claim the reference on every install and make the native page warn about a key
16
+ * the plugin never asked for. The plugin keeps using this default internally.
17
+ */
18
+ export declare const DEFAULT_API_KEY_REF = "COROUTER_API_KEY";
10
19
  export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
11
- apiKeyEnv: Schema<string, string, "volatile-defined">;
20
+ apiKeyEnv: Schema<string, string, "volatile">;
12
21
  baseURL: Schema<string, string, "volatile-defined">;
13
22
  apiProtocol: Schema<"chat-completions" | "responses" | "messages", "chat-completions" | "responses" | "messages", "volatile-defined">;
14
23
  modelSettings: Schema<NoInfer<import("@deepseek-ai/cosmokit").Dict<unknown, string>>, NoInfer<ModelSettingsMap>, "volatile-defined">;
@@ -23,7 +32,7 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
23
32
  streamIdleTimeoutMs: Schema<number, number, "volatile-defined">;
24
33
  maxRequestImageBytes: Schema<number, number, "volatile-defined">;
25
34
  }>>, Schemastery.ObjectT<NoInfer<{
26
- apiKeyEnv: Schema<string, string, "volatile-defined">;
35
+ apiKeyEnv: Schema<string, string, "volatile">;
27
36
  baseURL: Schema<string, string, "volatile-defined">;
28
37
  apiProtocol: Schema<"chat-completions" | "responses" | "messages", "chat-completions" | "responses" | "messages", "volatile-defined">;
29
38
  modelSettings: Schema<NoInfer<import("@deepseek-ai/cosmokit").Dict<unknown, string>>, NoInfer<ModelSettingsMap>, "volatile-defined">;
@@ -40,7 +49,8 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
40
49
  }>>, "plain">;
41
50
  export type LiveConfig = ReturnType<typeof Config>;
42
51
  export interface RuntimeConfig {
43
- apiKeyEnv: string;
52
+ /** Credential reference this profile names; absent when the profile names none. */
53
+ apiKeyEnv?: string;
44
54
  baseURL: string;
45
55
  useDesktopCredential: boolean;
46
56
  emptyTurnGuard: boolean;
@@ -56,4 +66,11 @@ export interface RuntimeConfig {
56
66
  turnReviewNoProgressLimit?: number;
57
67
  }
58
68
  export declare function assertBaseURL(raw: string): string;
69
+ /**
70
+ * The reference requests resolve when the profile names none; the profile itself stays unnamed.
71
+ *
72
+ * No default and no inherited value: a patch that leaves this field out keeps the profile
73
+ * unnamed, which is also what lets the settings page clear it instead of writing a name back.
74
+ */
75
+ export declare function apiKeyRef(config: RuntimeConfig): string;
59
76
  export declare function readConfig(config: LiveConfig): RuntimeConfig;
@@ -3,7 +3,7 @@ export interface DeviceTokens {
3
3
  runtimeKey: string;
4
4
  }
5
5
  export declare const DEVICE_AUTH_ENDPOINT = "https://amr-api.open-design.ai/api/v1/cli/device-authorizations";
6
- export declare const DEVICE_AUTH_PLUGIN_VERSION = "0.1.17";
6
+ export declare const DEVICE_AUTH_PLUGIN_VERSION = "0.1.18";
7
7
  export declare const DEVICE_REQUEST_TIMEOUT_MS = 20000;
8
8
  /** One bounded launch step of the temporary activation window. */
9
9
  export declare const DEVICE_OPEN_TIMEOUT_MS = 30000;
@@ -279,8 +279,11 @@ function parseStatusModel(value) {
279
279
  }
280
280
  function parseStatusConfig(value) {
281
281
  if (!record(value)) throw new Error("\u914D\u7F6E\u89C6\u56FE\u5FC5\u987B\u662F\u5BF9\u8C61");
282
- const apiKeyEnv = text(value.apiKeyEnv, "\u51ED\u636E\u5F15\u7528\u540D", MAX_ENV_REF);
283
- if (!ENV_REF.test(apiKeyEnv)) throw new Error("\u51ED\u636E\u5F15\u7528\u540D\u5FC5\u987B\u662F\u5408\u6CD5\u6807\u8BC6\u7B26");
282
+ if (typeof value.apiKeyEnv !== "string" || value.apiKeyEnv.length > MAX_ENV_REF) {
283
+ throw new Error(`\u51ED\u636E\u5F15\u7528\u540D\u5FC5\u987B\u662F\u6700\u591A ${MAX_ENV_REF} \u5B57\u7B26\u7684\u5B57\u7B26\u4E32`);
284
+ }
285
+ const apiKeyEnv = value.apiKeyEnv;
286
+ if (apiKeyEnv !== "" && !ENV_REF.test(apiKeyEnv)) throw new Error("\u51ED\u636E\u5F15\u7528\u540D\u5FC5\u987B\u662F\u5408\u6CD5\u6807\u8BC6\u7B26");
284
287
  return {
285
288
  emptyTurnGuard: flag(value.emptyTurnGuard, "\u7A7A\u8F6E\u4FDD\u62A4\u5F00\u5173"),
286
289
  ...value.turnCompletionReview === void 0 ? {} : { turnCompletionReview: flag(value.turnCompletionReview, "\u7ED3\u675F\u56DE\u5408\u6838\u9A8C\u5F00\u5173") },
@@ -279,8 +279,11 @@ function parseStatusModel(value) {
279
279
  }
280
280
  function parseStatusConfig(value) {
281
281
  if (!record(value)) throw new Error("\u914D\u7F6E\u89C6\u56FE\u5FC5\u987B\u662F\u5BF9\u8C61");
282
- const apiKeyEnv = text(value.apiKeyEnv, "\u51ED\u636E\u5F15\u7528\u540D", MAX_ENV_REF);
283
- if (!ENV_REF.test(apiKeyEnv)) throw new Error("\u51ED\u636E\u5F15\u7528\u540D\u5FC5\u987B\u662F\u5408\u6CD5\u6807\u8BC6\u7B26");
282
+ if (typeof value.apiKeyEnv !== "string" || value.apiKeyEnv.length > MAX_ENV_REF) {
283
+ throw new Error(`\u51ED\u636E\u5F15\u7528\u540D\u5FC5\u987B\u662F\u6700\u591A ${MAX_ENV_REF} \u5B57\u7B26\u7684\u5B57\u7B26\u4E32`);
284
+ }
285
+ const apiKeyEnv = value.apiKeyEnv;
286
+ if (apiKeyEnv !== "" && !ENV_REF.test(apiKeyEnv)) throw new Error("\u51ED\u636E\u5F15\u7528\u540D\u5FC5\u987B\u662F\u5408\u6CD5\u6807\u8BC6\u7B26");
284
287
  return {
285
288
  emptyTurnGuard: flag(value.emptyTurnGuard, "\u7A7A\u8F6E\u4FDD\u62A4\u5F00\u5173"),
286
289
  ...value.turnCompletionReview === void 0 ? {} : { turnCompletionReview: flag(value.turnCompletionReview, "\u7ED3\u675F\u56DE\u5408\u6838\u9A8C\u5F00\u5173") },
package/lib/index.d.ts CHANGED
@@ -65,6 +65,10 @@ export declare class OpenDesignCoRouterService extends TypertRemoteService {
65
65
  * Persist the snapshot through the Host form service.
66
66
  * `unsupported` means no settings service is composed (nothing to report);
67
67
  * `unavailable` means the service exists but exposes no writable form for this plugin.
68
+ *
69
+ * A settings write rewrites the whole composed profile and may rebuild the plugin tree, so
70
+ * only a concurrent revision conflict (`SETTINGS_CONFLICT`) is worth re-reading the revision
71
+ * and trying once more. Every other failure repeats identically and is reported immediately.
68
72
  */
69
73
  private _persistModels;
70
74
  /** Serialize snapshot writes so the newest successful refresh is the last one persisted. */
package/lib/index.js CHANGED
@@ -418,8 +418,9 @@ var SETTINGS_NS = "llm-opendesign-corouter";
418
418
  var PLAN_PROVIDER = "opendesign-corouter-plan";
419
419
  var PAID_PROVIDER = "opendesign-corouter-paid";
420
420
  var DEFAULT_BASE_URL = "https://amr-link.open-design.ai/v1";
421
+ var DEFAULT_API_KEY_REF = "COROUTER_API_KEY";
421
422
  var Config = Schema.object({
422
- apiKeyEnv: Schema.string().max(128).pattern(/^[A-Za-z_][A-Za-z0-9_]*$/u).default("COROUTER_API_KEY").description("CoRouter API Key \u7684\u73AF\u5883\u53D8\u91CF\u6216 DSH \u51ED\u636E\u5F15\u7528\u540D").volatile(),
423
+ apiKeyEnv: Schema.string().max(128).pattern(/^[A-Za-z_][A-Za-z0-9_]*$/u).description(`CoRouter API Key \u7684\u73AF\u5883\u53D8\u91CF\u6216 DSH \u51ED\u636E\u5F15\u7528\u540D\uFF1B\u4E0D\u8BBE\u7F6E\u65F6\u4F7F\u7528 ${DEFAULT_API_KEY_REF}`).volatile(),
423
424
  baseURL: Schema.transform(Schema.string(), serializableTransform(assertBaseURL)).default(DEFAULT_BASE_URL).description("CoRouter \u7F51\u5173\u5730\u5740\uFF1B\u4E0D\u7528\u4E8E\u63A7\u5236\u53F0\u767B\u5F55\u6216\u989D\u5EA6\u67E5\u8BE2").volatile(),
424
425
  apiProtocol: Schema.union(API_PROTOCOL_IDS).default("chat-completions").description("\u7F51\u5173\u652F\u6301\u7684\u63A8\u7406\u534F\u8BAE\uFF1B\u6A21\u578B\u76EE\u5F55\u901A\u8FC7\u8BE5\u7F51\u5173\u7684\u517C\u5BB9\u63A5\u53E3\u8BFB\u53D6").volatile(),
425
426
  modelSettings: Schema.transform(Schema.dict(Schema.any()), serializableTransform(parseModelSettingsMap)).default({}).description("\u9010\u6A21\u578B\u542F\u7528\u72B6\u6001\u3001\u56FE\u7247\u8F93\u5165\u548C\u8BF7\u6C42\u53C2\u6570").volatile(),
@@ -448,10 +449,15 @@ function assertBaseURL(raw) {
448
449
  if (normalized.length > 2048) throw new Error("\u63A8\u7406 Base URL \u6700\u591A\u5141\u8BB8 2048 \u5B57\u7B26");
449
450
  return normalized;
450
451
  }
452
+ function apiKeyRef(config) {
453
+ const named = config.apiKeyEnv;
454
+ return named === void 0 || named === "" ? DEFAULT_API_KEY_REF : named;
455
+ }
451
456
  function readConfig(config) {
452
457
  const modelCatalog = parseModelCatalogSnapshot(config.modelCatalog.get());
458
+ const apiKeyEnv = config.apiKeyEnv.get();
453
459
  return {
454
- apiKeyEnv: config.apiKeyEnv.get(),
460
+ ...apiKeyEnv === void 0 ? {} : { apiKeyEnv },
455
461
  baseURL: assertBaseURL(config.baseURL.get()),
456
462
  apiProtocol: config.apiProtocol.get(),
457
463
  modelSettings: parseModelSettingsMap(config.modelSettings.get()),
@@ -824,6 +830,14 @@ function tokenUsage(value) {
824
830
  ...reasoning !== void 0 && reasoning >= 0 && reasoning <= output ? { reasoningTokens: reasoning } : {}
825
831
  };
826
832
  }
833
+ function reasoningDelta(delta) {
834
+ if (typeof delta.reasoning_content === "string" && delta.reasoning_content !== "") return delta.reasoning_content;
835
+ if (typeof delta.reasoning === "string" && delta.reasoning !== "") return delta.reasoning;
836
+ if (!Array.isArray(delta.reasoning_details)) return "";
837
+ let text2 = "";
838
+ for (const part of delta.reasoning_details) if (record(part) && typeof part.text === "string") text2 += part.text;
839
+ return text2;
840
+ }
827
841
  async function* consumeSse(body, signal, idleMs) {
828
842
  let nextIndex = 0, count2 = 0, sawTool = false, done = false;
829
843
  let text2, reasoning;
@@ -861,9 +875,9 @@ async function* consumeSse(body, signal, idleMs) {
861
875
  if (!record(choice)) throw new LlmError4("OpenDesign\uFF1A\u65E0\u6548\u7684\u6D41\u5F0F\u9009\u9879", "INVALID_RESPONSE");
862
876
  const delta = record(choice.delta) ? choice.delta : {};
863
877
  const out = [];
864
- const hasDelta = typeof delta.content === "string" && delta.content !== "" || typeof delta.reasoning_content === "string" && delta.reasoning_content !== "" || Array.isArray(delta.tool_calls) && delta.tool_calls.length > 0;
878
+ const thinking = reasoningDelta(delta);
879
+ const hasDelta = typeof delta.content === "string" && delta.content !== "" || thinking !== "" || Array.isArray(delta.tool_calls) && delta.tool_calls.length > 0;
865
880
  if (finish && hasDelta) throw new LlmError4("OpenDesign\uFF1A\u54CD\u5E94\u7ED3\u675F\u540E\u4ECD\u6536\u5230\u5185\u5BB9", "INVALID_RESPONSE");
866
- const thinking = typeof delta.reasoning_content === "string" ? delta.reasoning_content : typeof delta.reasoning === "string" ? delta.reasoning : "";
867
881
  if (thinking) {
868
882
  if (!reasoning) {
869
883
  reasoning = { index: nextIndex++, text: "" };
@@ -2132,9 +2146,10 @@ var CoRouterAdapter = class extends LlmAdapter {
2132
2146
  validateClaudeSampling(row.id, options.temperature ?? setting.temperature, setting.topP);
2133
2147
  validateClaudeOutput(row.id, options.maxTokens ?? setting.maxTokens);
2134
2148
  }
2135
- const raw = await this.options.apiKey(config.apiKeyEnv, config.baseURL);
2149
+ const keyRef = apiKeyRef(config);
2150
+ const raw = await this.options.apiKey(keyRef, config.baseURL);
2136
2151
  if (!raw) throw new LlmError11("\u672A\u914D\u7F6E\u5F53\u524D\u7F51\u5173\u7684\u63A8\u7406\u51ED\u636E\uFF1B\u8BF7\u5B8C\u6210\u8BBE\u5907\u6388\u6743\u6216\u914D\u7F6E\u5BF9\u5E94 API Key", "MISSING_CREDENTIAL");
2137
- const key = assertUsableApiKey(raw, "dsh-opendesign-corouter", config.apiKeyEnv);
2152
+ const key = assertUsableApiKey(raw, "dsh-opendesign-corouter", keyRef);
2138
2153
  signal.throwIfAborted();
2139
2154
  let credentialIdentity;
2140
2155
  if (protocolId === "messages") {
@@ -3493,7 +3508,7 @@ import { randomUUID as randomUUID2 } from "node:crypto";
3493
3508
 
3494
3509
  // src/device-auth.ts
3495
3510
  var DEVICE_AUTH_ENDPOINT = "https://amr-api.open-design.ai/api/v1/cli/device-authorizations";
3496
- var DEVICE_AUTH_PLUGIN_VERSION = "0.1.17";
3511
+ var DEVICE_AUTH_PLUGIN_VERSION = "0.1.18";
3497
3512
  var DEVICE_REQUEST_TIMEOUT_MS = 2e4;
3498
3513
  var DEVICE_RESPONSE_MAX_BYTES = 65536;
3499
3514
  var DEVICE_POLL_MIN_MS = 1e3;
@@ -4605,8 +4620,11 @@ function parseStatusModel(value) {
4605
4620
  }
4606
4621
  function parseStatusConfig(value) {
4607
4622
  if (!record(value)) throw new Error("\u914D\u7F6E\u89C6\u56FE\u5FC5\u987B\u662F\u5BF9\u8C61");
4608
- const apiKeyEnv = text(value.apiKeyEnv, "\u51ED\u636E\u5F15\u7528\u540D", MAX_ENV_REF);
4609
- if (!ENV_REF.test(apiKeyEnv)) throw new Error("\u51ED\u636E\u5F15\u7528\u540D\u5FC5\u987B\u662F\u5408\u6CD5\u6807\u8BC6\u7B26");
4623
+ if (typeof value.apiKeyEnv !== "string" || value.apiKeyEnv.length > MAX_ENV_REF) {
4624
+ throw new Error(`\u51ED\u636E\u5F15\u7528\u540D\u5FC5\u987B\u662F\u6700\u591A ${MAX_ENV_REF} \u5B57\u7B26\u7684\u5B57\u7B26\u4E32`);
4625
+ }
4626
+ const apiKeyEnv = value.apiKeyEnv;
4627
+ if (apiKeyEnv !== "" && !ENV_REF.test(apiKeyEnv)) throw new Error("\u51ED\u636E\u5F15\u7528\u540D\u5FC5\u987B\u662F\u5408\u6CD5\u6807\u8BC6\u7B26");
4610
4628
  return {
4611
4629
  emptyTurnGuard: flag(value.emptyTurnGuard, "\u7A7A\u8F6E\u4FDD\u62A4\u5F00\u5173"),
4612
4630
  ...value.turnCompletionReview === void 0 ? {} : { turnCompletionReview: flag(value.turnCompletionReview, "\u7ED3\u675F\u56DE\u5408\u6838\u9A8C\u5F00\u5173") },
@@ -4690,6 +4708,8 @@ var name = "llm-opendesign-corouter";
4690
4708
  var inject = ["llm"];
4691
4709
  var API_KEY = credentialKey2(name, "api-key");
4692
4710
  var SESSION = credentialKey2(name, "console");
4711
+ var SETTINGS_CONFLICT = "SETTINGS_CONFLICT";
4712
+ var NATIVE_AUTH = { env: [], oauth: true };
4693
4713
  var hash = (value) => createHash2("sha256").update(JSON.stringify(value) ?? "").digest("hex");
4694
4714
  var stableConfig = (config) => {
4695
4715
  const { modelCatalog: _snapshot, ...rest } = config;
@@ -4809,6 +4829,10 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
4809
4829
  * Persist the snapshot through the Host form service.
4810
4830
  * `unsupported` means no settings service is composed (nothing to report);
4811
4831
  * `unavailable` means the service exists but exposes no writable form for this plugin.
4832
+ *
4833
+ * A settings write rewrites the whole composed profile and may rebuild the plugin tree, so
4834
+ * only a concurrent revision conflict (`SETTINGS_CONFLICT`) is worth re-reading the revision
4835
+ * and trying once more. Every other failure repeats identically and is reported immediately.
4812
4836
  */
4813
4837
  async _persistModels(value) {
4814
4838
  const settings = this.ctx.get("settings");
@@ -4824,7 +4848,8 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
4824
4848
  try {
4825
4849
  await settings.update(SETTINGS_NS, { modelCatalog: value }, descriptor.revision);
4826
4850
  return "saved";
4827
- } catch {
4851
+ } catch (error) {
4852
+ if (attempt > 0 || !record(error) || error.code !== SETTINGS_CONFLICT) return "failed";
4828
4853
  }
4829
4854
  }
4830
4855
  return "failed";
@@ -4861,7 +4886,7 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
4861
4886
  async _state() {
4862
4887
  const credentials = this.ctx.get("credentials"), config = this._config();
4863
4888
  const [apiRecord, sessionRecord] = await Promise.all([credentials?.readRecord(API_KEY), credentials?.readRecord(SESSION)]);
4864
- const resolved = await this._key(config.apiKeyEnv, config.baseURL, apiRecord, sessionRecord);
4889
+ const resolved = await this._key(apiKeyRef(config), config.baseURL, apiRecord, sessionRecord);
4865
4890
  const key = resolved?.key;
4866
4891
  const state = { apiRecord, sessionRecord, key, keySource: resolved?.source, config };
4867
4892
  const modelsFingerprint = hash({ key, baseURL: config.baseURL });
@@ -4904,7 +4929,7 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
4904
4929
  ...this._quota.source ? { sessionSource: this._quota.source } : {},
4905
4930
  quota: this._quota,
4906
4931
  login: this._login.status(),
4907
- config: state.config,
4932
+ config: { ...state.config, apiKeyEnv: state.config.apiKeyEnv ?? "" },
4908
4933
  guardedTurns: this.guardedTurns,
4909
4934
  ...this.turnMonitorStatus ? { turnMonitor: this.turnMonitorStatus() } : {},
4910
4935
  models: this._models.map((row) => {
@@ -5182,7 +5207,7 @@ function apply(ctx, config) {
5182
5207
  ctx.llm.registerModelDiscovery(SETTINGS_NS, async (request, signal) => {
5183
5208
  if (request.provider !== void 0 && ![PLAN_PROVIDER, PAID_PROVIDER].includes(request.provider)) throw new LlmError14("\u4E0D\u662F\u672C\u63D2\u4EF6\u7684\u6A21\u578B\u901A\u9053", "INVALID_REQUEST");
5184
5209
  const config2 = current();
5185
- const key = request.apiKey ?? await service.resolveApiKey(config2.apiKeyEnv, config2.baseURL);
5210
+ const key = request.apiKey ?? await service.resolveApiKey(apiKeyRef(config2), config2.baseURL);
5186
5211
  if (!key) throw new LlmError14("\u8BF7\u5148\u914D\u7F6E CoRouter API Key", "MISSING_CREDENTIAL");
5187
5212
  const models = await fetchModelCatalog(config2.baseURL, key, signal);
5188
5213
  return models.map((row) => {
@@ -5191,8 +5216,8 @@ function apply(ctx, config) {
5191
5216
  });
5192
5217
  });
5193
5218
  ctx.llm.registerConfigurableProviders([
5194
- { provider: PLAN_PROVIDER, displayName: "OpenDesign CoRouter \xB7 \u5957\u9910\u8D60\u9001", settingsNs: SETTINGS_NS, settingsPath: [], defaultBaseURL: current().baseURL },
5195
- { provider: PAID_PROVIDER, displayName: "OpenDesign CoRouter \xB7 \u4ED8\u8D39\u6A21\u578B", settingsNs: SETTINGS_NS, settingsPath: [], defaultBaseURL: current().baseURL }
5219
+ { provider: PLAN_PROVIDER, displayName: "OpenDesign CoRouter \xB7 \u5957\u9910\u8D60\u9001", settingsNs: SETTINGS_NS, settingsPath: [], defaultBaseURL: current().baseURL, nativeAuth: NATIVE_AUTH },
5220
+ { provider: PAID_PROVIDER, displayName: "OpenDesign CoRouter \xB7 \u4ED8\u8D39\u6A21\u578B", settingsNs: SETTINGS_NS, settingsPath: [], defaultBaseURL: current().baseURL, nativeAuth: NATIVE_AUTH }
5196
5221
  ]);
5197
5222
  ctx.effect(() => () => {
5198
5223
  adapter.dispose();