dsh-opendesign-corouter 0.1.17 → 0.1.19

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
@@ -77,7 +77,7 @@ var EFFORTS_GROK = [...EFFORTS_LEVELS, "xhigh"];
77
77
  var EFFORTS_MUSE = ["minimal", ...EFFORTS_REASONING];
78
78
  var MODELS = [
79
79
  // ── OpenAI(8) ─────────────────────────────────────────────
80
- { id: "gpt-6.1-sol", name: "GPT-6.1 Sol", group: "paid", contextWindow: 105e4, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING },
80
+ { id: "gpt-6.1-sol", name: "GPT-6.1 Sol", group: "paid", contextWindow: 105e4, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING, defaultEffort: "medium" },
81
81
  {
82
82
  id: "gpt-6.1-terra",
83
83
  name: "GPT-6.1 Terra",
@@ -85,9 +85,11 @@ var MODELS = [
85
85
  contextWindow: 105e4,
86
86
  maxOutputTokens: 128e3,
87
87
  inputModalities: TEXT_AND_IMAGE,
88
- reasoningEfforts: EFFORTS_OPENAI
88
+ reasoningEfforts: EFFORTS_OPENAI,
89
+ defaultEffort: "medium"
89
90
  },
90
- { id: "gpt-6-astra", name: "GPT-6 Astra", group: "paid", contextWindow: 105e4, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING },
91
+ // 厂商页只列出档位、未声明默认值;low 取自 Codex CLI 模型注册表的默认 effort 与网关记录。
92
+ { id: "gpt-6-astra", name: "GPT-6 Astra", group: "paid", contextWindow: 105e4, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING, defaultEffort: "low" },
91
93
  {
92
94
  id: "gpt-6-luna",
93
95
  name: "GPT-6 Luna",
@@ -95,20 +97,21 @@ var MODELS = [
95
97
  contextWindow: 105e4,
96
98
  maxOutputTokens: 128e3,
97
99
  inputModalities: TEXT_AND_IMAGE,
98
- reasoningEfforts: EFFORTS_OPENAI
100
+ reasoningEfforts: EFFORTS_OPENAI,
101
+ defaultEffort: "medium"
99
102
  },
100
- { id: "gpt-6-sol", name: "GPT-6 Sol", group: "paid", contextWindow: 105e4, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_OPENAI },
101
- { id: "gpt-5.6-luna", name: "GPT-5.6 Luna", group: "paid", contextWindow: 105e4, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_OPENAI },
102
- { id: "gpt-5.6-sol", name: "GPT-5.6 Sol", group: "paid", contextWindow: 105e4, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_OPENAI },
103
- { id: "gpt-5.6-terra", name: "GPT-5.6 Terra", group: "paid", contextWindow: 105e4, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_OPENAI },
103
+ { id: "gpt-6-sol", name: "GPT-6 Sol", group: "paid", contextWindow: 105e4, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_OPENAI, defaultEffort: "medium" },
104
+ { id: "gpt-5.6-luna", name: "GPT-5.6 Luna", group: "paid", contextWindow: 105e4, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_OPENAI, defaultEffort: "medium" },
105
+ { id: "gpt-5.6-sol", name: "GPT-5.6 Sol", group: "paid", contextWindow: 105e4, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_OPENAI, defaultEffort: "medium" },
106
+ { id: "gpt-5.6-terra", name: "GPT-5.6 Terra", group: "paid", contextWindow: 105e4, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_OPENAI, defaultEffort: "medium" },
104
107
  // ── Anthropic(8) ──────────────────────────────────────────
105
- { id: "claude-fable-5.1", name: "Claude Fable 5.1", group: "paid", contextWindow: 1e6, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING },
106
- { id: "claude-fable-5", name: "Claude Fable 5", group: "paid", contextWindow: 1e6, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING },
107
- { id: "claude-opus-5.5", name: "Claude Opus 5.5", group: "paid", contextWindow: 1e6, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING },
108
- { id: "claude-opus-5", name: "Claude Opus 5", group: "paid", contextWindow: 1e6, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING },
109
- { id: "claude-opus-4.8", name: "Claude Opus 4.8", group: "paid", contextWindow: 1e6, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING },
110
- { id: "claude-sonnet-5.5", name: "Claude Sonnet 5.5", group: "paid", contextWindow: 1e6, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING },
111
- { id: "claude-sonnet-5", name: "Claude Sonnet 5", group: "paid", contextWindow: 1e6, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING },
108
+ { id: "claude-fable-5.1", name: "Claude Fable 5.1", group: "paid", contextWindow: 1e6, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING, defaultEffort: "high" },
109
+ { id: "claude-fable-5", name: "Claude Fable 5", group: "paid", contextWindow: 1e6, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING, defaultEffort: "high" },
110
+ { id: "claude-opus-5.5", name: "Claude Opus 5.5", group: "paid", contextWindow: 1e6, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING, defaultEffort: "medium" },
111
+ { id: "claude-opus-5", name: "Claude Opus 5", group: "paid", contextWindow: 1e6, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING, defaultEffort: "high" },
112
+ { id: "claude-opus-4.8", name: "Claude Opus 4.8", group: "paid", contextWindow: 1e6, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING, defaultEffort: "high" },
113
+ { id: "claude-sonnet-5.5", name: "Claude Sonnet 5.5", group: "paid", contextWindow: 1e6, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING, defaultEffort: "high" },
114
+ { id: "claude-sonnet-5", name: "Claude Sonnet 5", group: "paid", contextWindow: 1e6, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING, defaultEffort: "high" },
112
115
  {
113
116
  id: "claude-haiku-5.5",
114
117
  name: "Claude Haiku 5.5",
@@ -116,7 +119,8 @@ var MODELS = [
116
119
  contextWindow: 1e6,
117
120
  maxOutputTokens: 128e3,
118
121
  inputModalities: TEXT_AND_IMAGE,
119
- reasoningEfforts: EFFORTS_REASONING
122
+ reasoningEfforts: EFFORTS_REASONING,
123
+ defaultEffort: "medium"
120
124
  },
121
125
  // ── DeepSeek(4) ───────────────────────────────────────────
122
126
  {
@@ -126,7 +130,8 @@ var MODELS = [
126
130
  contextWindow: 1e6,
127
131
  maxOutputTokens: 384e3,
128
132
  inputModalities: TEXT_AND_IMAGE,
129
- reasoningEfforts: EFFORTS_LOW_HIGH
133
+ reasoningEfforts: EFFORTS_LOW_HIGH,
134
+ defaultEffort: "high"
130
135
  },
131
136
  {
132
137
  id: "deepseek-v4-pro",
@@ -134,7 +139,8 @@ var MODELS = [
134
139
  group: "plan",
135
140
  contextWindow: 1e6,
136
141
  maxOutputTokens: 384e3,
137
- reasoningEfforts: EFFORTS_LOW_HIGH
142
+ reasoningEfforts: EFFORTS_LOW_HIGH,
143
+ defaultEffort: "high"
138
144
  },
139
145
  {
140
146
  id: "deepseek-v4-flash",
@@ -143,7 +149,8 @@ var MODELS = [
143
149
  contextWindow: 1e6,
144
150
  maxOutputTokens: 384e3,
145
151
  inputModalities: TEXT_AND_IMAGE,
146
- reasoningEfforts: EFFORTS_LOW_HIGH
152
+ reasoningEfforts: EFFORTS_LOW_HIGH,
153
+ defaultEffort: "high"
147
154
  },
148
155
  {
149
156
  id: "deepseek-v4-flash-vision-exp",
@@ -152,7 +159,8 @@ var MODELS = [
152
159
  contextWindow: 1e6,
153
160
  maxOutputTokens: 384e3,
154
161
  inputModalities: TEXT_AND_IMAGE,
155
- reasoningEfforts: EFFORTS_LOW_HIGH
162
+ reasoningEfforts: EFFORTS_LOW_HIGH,
163
+ defaultEffort: "high"
156
164
  },
157
165
  // ── Z.ai(3) ───────────────────────────────────────────────
158
166
  {
@@ -162,7 +170,8 @@ var MODELS = [
162
170
  contextWindow: 1e6,
163
171
  maxOutputTokens: 128e3,
164
172
  inputModalities: TEXT_AND_IMAGE,
165
- reasoningEfforts: EFFORTS_LOW_HIGH
173
+ reasoningEfforts: EFFORTS_LOW_HIGH,
174
+ defaultEffort: "max"
166
175
  },
167
176
  {
168
177
  id: "glm-5.3-flash",
@@ -171,9 +180,10 @@ var MODELS = [
171
180
  contextWindow: 1e6,
172
181
  maxOutputTokens: 128e3,
173
182
  inputModalities: TEXT_AND_IMAGE,
174
- reasoningEfforts: EFFORTS_LOW_HIGH
183
+ reasoningEfforts: EFFORTS_LOW_HIGH,
184
+ defaultEffort: "max"
175
185
  },
176
- { id: "glm-5.2", name: "GLM-5.2", group: "paid", contextWindow: 1e6, inputModalities: TEXT_ONLY, reasoningEfforts: EFFORTS_GLM52 },
186
+ { id: "glm-5.2", name: "GLM-5.2", group: "paid", contextWindow: 1e6, inputModalities: TEXT_ONLY, reasoningEfforts: EFFORTS_GLM52, defaultEffort: "max" },
177
187
  // ── Moonshot(3) ───────────────────────────────────────────
178
188
  {
179
189
  id: "kimi-k2.7-code",
@@ -184,16 +194,16 @@ var MODELS = [
184
194
  inputModalities: TEXT_AND_IMAGE,
185
195
  reasoningEfforts: []
186
196
  },
187
- { id: "kimi-k3", name: "Kimi K3", group: "paid", contextWindow: 1048576, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_LOW_HIGH },
188
- { id: "kimi-k3.1-pro", name: "Kimi K3.1 Pro", group: "paid", contextWindow: 1048576, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_LOW_HIGH },
197
+ { id: "kimi-k3", name: "Kimi K3", group: "paid", contextWindow: 1048576, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_LOW_HIGH, defaultEffort: "max" },
198
+ { id: "kimi-k3.1-pro", name: "Kimi K3.1 Pro", group: "paid", contextWindow: 1048576, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_LOW_HIGH, defaultEffort: "max" },
189
199
  // ── Google(3) ─────────────────────────────────────────────
190
- { id: "gemini-4-argon", name: "Gemini 4 Argon", group: "paid", contextWindow: 1048576, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_LEVELS },
191
- { id: "gemini-3.8-flash", name: "Gemini 3.8 Flash", group: "paid", contextWindow: 1048576, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_LEVELS },
192
- { id: "gemini-3.7-flash", name: "Gemini 3.7 Flash", group: "paid", contextWindow: 1048576, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_LEVELS },
200
+ { id: "gemini-4-argon", name: "Gemini 4 Argon", group: "paid", contextWindow: 1048576, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_LEVELS, defaultEffort: "medium" },
201
+ { id: "gemini-3.8-flash", name: "Gemini 3.8 Flash", group: "paid", contextWindow: 1048576, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_LEVELS, defaultEffort: "medium" },
202
+ { id: "gemini-3.7-flash", name: "Gemini 3.7 Flash", group: "paid", contextWindow: 1048576, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_LEVELS, defaultEffort: "medium" },
193
203
  // ── xAI(3) ────────────────────────────────────────────────
194
- { id: "grok-4.7", name: "Grok 4.7", group: "paid", contextWindow: 5e5, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_GROK },
195
- { id: "grok-4.6", name: "Grok 4.6", group: "paid", contextWindow: 5e5, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_GROK },
196
- { id: "grok-4.5", name: "Grok 4.5", group: "paid", contextWindow: 5e5, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_LEVELS },
204
+ { id: "grok-4.7", name: "Grok 4.7", group: "paid", contextWindow: 5e5, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_GROK, defaultEffort: "high" },
205
+ { id: "grok-4.6", name: "Grok 4.6", group: "paid", contextWindow: 5e5, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_GROK, defaultEffort: "high" },
206
+ { id: "grok-4.5", name: "Grok 4.5", group: "paid", contextWindow: 5e5, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_LEVELS, defaultEffort: "high" },
197
207
  // ── Xiaomi(2) ─────────────────────────────────────────────
198
208
  {
199
209
  id: "mimo-v2.6-pro",
@@ -221,13 +231,15 @@ var MODELS = [
221
231
  contextWindow: 1e6,
222
232
  maxOutputTokens: 64e3,
223
233
  inputModalities: TEXT_ONLY,
224
- reasoningEfforts: ["none", "high"]
234
+ reasoningEfforts: ["none", "high"],
235
+ defaultEffort: "high"
225
236
  },
226
237
  // ── Alibaba(1) ────────────────────────────────────────────
227
238
  { id: "qwen3.7-max", name: "Qwen3.7 Max", group: "paid", contextWindow: 1e6, inputModalities: TEXT_ONLY, reasoningEfforts: [] },
228
239
  // Official API additions; display labels for undocumented entries are local formatting.
229
- { id: "minimax-m3.1-flash", name: "MiniMax M3.1 Flash", group: "plan", contextWindow: 1e6, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING },
230
- { id: "muse-spark-1.3", name: "Muse Spark 1.3", group: "paid", contextWindow: 1048576, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_MUSE },
240
+ { id: "minimax-m3.1-flash", name: "MiniMax M3.1 Flash", group: "plan", contextWindow: 1e6, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_REASONING, defaultEffort: "max" },
241
+ // 厂商只说默认“由模型决定”;high 取自 Meta 合作客户端与网关实现的默认 effort。
242
+ { id: "muse-spark-1.3", name: "Muse Spark 1.3", group: "paid", contextWindow: 1048576, inputModalities: TEXT_AND_IMAGE, reasoningEfforts: EFFORTS_MUSE, defaultEffort: "high" },
231
243
  { id: "muse-wonder", name: "Muse Wonder", group: "paid", contextWindow: 1048576 }
232
244
  ];
233
245
  var BY_ID = new Map(MODELS.map((model) => [model.id, model]));
@@ -347,7 +359,7 @@ function serializableTransform(callback) {
347
359
  function parseModelCatalogSnapshot(value) {
348
360
  const MODEL_ID4 = /^[A-Za-z0-9._:/-]{1,128}$/u;
349
361
  const GROUPS = ["plan", "paid"];
350
- const KEYS = ["id", "name", "group", "contextWindow", "maxOutputTokens", "inputModalities", "reasoningEfforts"];
362
+ const KEYS = ["id", "name", "group", "contextWindow", "maxOutputTokens", "inputModalities", "reasoningEfforts", "defaultEffort"];
351
363
  const RESERVED = ["__proto__", "constructor", "prototype"];
352
364
  if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
353
365
  const snapshot = value;
@@ -402,6 +414,11 @@ function parseModelCatalogSnapshot(value) {
402
414
  }
403
415
  model.reasoningEfforts = efforts;
404
416
  }
417
+ if (item.defaultEffort !== void 0) {
418
+ if (typeof item.defaultEffort !== "string" || item.defaultEffort.length === 0 || item.defaultEffort.length > 32) return void 0;
419
+ if (!(model.reasoningEfforts ?? []).includes(item.defaultEffort)) return void 0;
420
+ model.defaultEffort = item.defaultEffort;
421
+ }
405
422
  seen.add(id);
406
423
  models.push(model);
407
424
  }
@@ -418,8 +435,9 @@ var SETTINGS_NS = "llm-opendesign-corouter";
418
435
  var PLAN_PROVIDER = "opendesign-corouter-plan";
419
436
  var PAID_PROVIDER = "opendesign-corouter-paid";
420
437
  var DEFAULT_BASE_URL = "https://amr-link.open-design.ai/v1";
438
+ var DEFAULT_API_KEY_REF = "COROUTER_API_KEY";
421
439
  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(),
440
+ 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
441
  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
442
  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
443
  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 +466,15 @@ function assertBaseURL(raw) {
448
466
  if (normalized.length > 2048) throw new Error("\u63A8\u7406 Base URL \u6700\u591A\u5141\u8BB8 2048 \u5B57\u7B26");
449
467
  return normalized;
450
468
  }
469
+ function apiKeyRef(config) {
470
+ const named = config.apiKeyEnv;
471
+ return named === void 0 || named === "" ? DEFAULT_API_KEY_REF : named;
472
+ }
451
473
  function readConfig(config) {
452
474
  const modelCatalog = parseModelCatalogSnapshot(config.modelCatalog.get());
475
+ const apiKeyEnv = config.apiKeyEnv.get();
453
476
  return {
454
- apiKeyEnv: config.apiKeyEnv.get(),
477
+ ...apiKeyEnv === void 0 ? {} : { apiKeyEnv },
455
478
  baseURL: assertBaseURL(config.baseURL.get()),
456
479
  apiProtocol: config.apiProtocol.get(),
457
480
  modelSettings: parseModelSettingsMap(config.modelSettings.get()),
@@ -824,6 +847,14 @@ function tokenUsage(value) {
824
847
  ...reasoning !== void 0 && reasoning >= 0 && reasoning <= output ? { reasoningTokens: reasoning } : {}
825
848
  };
826
849
  }
850
+ function reasoningDelta(delta) {
851
+ if (typeof delta.reasoning_content === "string" && delta.reasoning_content !== "") return delta.reasoning_content;
852
+ if (typeof delta.reasoning === "string" && delta.reasoning !== "") return delta.reasoning;
853
+ if (!Array.isArray(delta.reasoning_details)) return "";
854
+ let text2 = "";
855
+ for (const part of delta.reasoning_details) if (record(part) && typeof part.text === "string") text2 += part.text;
856
+ return text2;
857
+ }
827
858
  async function* consumeSse(body, signal, idleMs) {
828
859
  let nextIndex = 0, count2 = 0, sawTool = false, done = false;
829
860
  let text2, reasoning;
@@ -861,9 +892,9 @@ async function* consumeSse(body, signal, idleMs) {
861
892
  if (!record(choice)) throw new LlmError4("OpenDesign\uFF1A\u65E0\u6548\u7684\u6D41\u5F0F\u9009\u9879", "INVALID_RESPONSE");
862
893
  const delta = record(choice.delta) ? choice.delta : {};
863
894
  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;
895
+ const thinking = reasoningDelta(delta);
896
+ const hasDelta = typeof delta.content === "string" && delta.content !== "" || thinking !== "" || Array.isArray(delta.tool_calls) && delta.tool_calls.length > 0;
865
897
  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
898
  if (thinking) {
868
899
  if (!reasoning) {
869
900
  reasoning = { index: nextIndex++, text: "" };
@@ -1105,6 +1136,14 @@ function protocolAcceptsEffort(protocol, effort) {
1105
1136
  function modelReasoningEfforts(model, protocol) {
1106
1137
  return model.reasoningEfforts?.filter((effort) => protocolAcceptsEffort(protocol, effort));
1107
1138
  }
1139
+ function vendorDefaultEffort(model, protocol) {
1140
+ const available = modelReasoningEfforts(model, protocol);
1141
+ return model.defaultEffort !== void 0 && available?.includes(model.defaultEffort) === true ? model.defaultEffort : void 0;
1142
+ }
1143
+ function defaultReasoningEffort(model, protocol, configured) {
1144
+ if (configured === void 0) return vendorDefaultEffort(model, protocol);
1145
+ return modelReasoningEfforts(model, protocol)?.includes(configured) === true ? configured : void 0;
1146
+ }
1108
1147
 
1109
1148
  // src/protocols/chat-completions.ts
1110
1149
  function buildChatCompletionsRequest(ctx) {
@@ -2028,10 +2067,11 @@ function outputReserve(model, protocol) {
2028
2067
  }
2029
2068
  function metadata(provider, row, config) {
2030
2069
  const setting = config.modelSettings?.[row.id];
2031
- const proposedReserve = setting?.maxTokens ?? outputReserve(row, config.apiProtocol ?? "chat-completions");
2032
- const reserve = claudeOutputError(row.id, config.apiProtocol ?? "chat-completions", proposedReserve) === void 0 ? proposedReserve : void 0;
2033
- const efforts = modelReasoningEfforts(row, config.apiProtocol ?? "chat-completions");
2034
- const defaultEffort = setting?.reasoningEffort !== void 0 && efforts?.includes(setting.reasoningEffort) ? setting.reasoningEffort : void 0;
2070
+ const protocol = config.apiProtocol ?? "chat-completions";
2071
+ const proposedReserve = setting?.maxTokens ?? outputReserve(row, protocol);
2072
+ const reserve = claudeOutputError(row.id, protocol, proposedReserve) === void 0 ? proposedReserve : void 0;
2073
+ const efforts = modelReasoningEfforts(row, protocol);
2074
+ const defaultEffort = defaultReasoningEffort(row, protocol, setting?.reasoningEffort);
2035
2075
  return {
2036
2076
  provider,
2037
2077
  id: row.id,
@@ -2126,15 +2166,19 @@ var CoRouterAdapter = class extends LlmAdapter {
2126
2166
  signal.throwIfAborted();
2127
2167
  const setting = config.modelSettings?.[row.id] ?? {};
2128
2168
  const protocolId = config.apiProtocol ?? "chat-completions";
2129
- const effort = options.reasoningEffort ?? (setting.reasoningEffort ? ReasoningEffortId(setting.reasoningEffort) : void 0);
2130
- if (effort !== void 0 && !modelReasoningEfforts(row, protocolId)?.includes(effort)) throw new LlmError11("\u6240\u9009\u601D\u8003\u6DF1\u5EA6\u4E0D\u9002\u7528\u4E8E\u5F53\u524D\u6A21\u578B\u6216\u534F\u8BAE\uFF1B\u8BF7\u4FEE\u6539\u9ED8\u8BA4\u503C\u6216\u9009\u62E9\u5176\u4ED6\u6863\u4F4D", "UNSUPPORTED_OPTION");
2169
+ const configured = setting.reasoningEffort;
2170
+ const explicit = options.reasoningEffort ?? (configured === void 0 ? void 0 : ReasoningEffortId(configured));
2171
+ if (explicit !== void 0 && !modelReasoningEfforts(row, protocolId)?.includes(explicit)) throw new LlmError11("\u6240\u9009\u601D\u8003\u6DF1\u5EA6\u4E0D\u9002\u7528\u4E8E\u5F53\u524D\u6A21\u578B\u6216\u534F\u8BAE\uFF1B\u8BF7\u4FEE\u6539\u9ED8\u8BA4\u503C\u6216\u9009\u62E9\u5176\u4ED6\u6863\u4F4D", "UNSUPPORTED_OPTION");
2172
+ const vendorDefault = vendorDefaultEffort(row, protocolId);
2173
+ const effort = explicit ?? (vendorDefault === void 0 ? void 0 : ReasoningEffortId(vendorDefault));
2131
2174
  if (protocolId === "messages") {
2132
2175
  validateClaudeSampling(row.id, options.temperature ?? setting.temperature, setting.topP);
2133
2176
  validateClaudeOutput(row.id, options.maxTokens ?? setting.maxTokens);
2134
2177
  }
2135
- const raw = await this.options.apiKey(config.apiKeyEnv, config.baseURL);
2178
+ const keyRef = apiKeyRef(config);
2179
+ const raw = await this.options.apiKey(keyRef, config.baseURL);
2136
2180
  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);
2181
+ const key = assertUsableApiKey(raw, "dsh-opendesign-corouter", keyRef);
2138
2182
  signal.throwIfAborted();
2139
2183
  let credentialIdentity;
2140
2184
  if (protocolId === "messages") {
@@ -3493,7 +3537,7 @@ import { randomUUID as randomUUID2 } from "node:crypto";
3493
3537
 
3494
3538
  // src/device-auth.ts
3495
3539
  var DEVICE_AUTH_ENDPOINT = "https://amr-api.open-design.ai/api/v1/cli/device-authorizations";
3496
- var DEVICE_AUTH_PLUGIN_VERSION = "0.1.17";
3540
+ var DEVICE_AUTH_PLUGIN_VERSION = "0.1.19";
3497
3541
  var DEVICE_REQUEST_TIMEOUT_MS = 2e4;
3498
3542
  var DEVICE_RESPONSE_MAX_BYTES = 65536;
3499
3543
  var DEVICE_POLL_MIN_MS = 1e3;
@@ -4600,13 +4644,22 @@ function parseStatusModel(value) {
4600
4644
  ...value.inputModalities === void 0 ? {} : { inputModalities: parseModalities(value.inputModalities) },
4601
4645
  ...value.contextWindow === void 0 ? {} : { contextWindow: positiveInteger(value.contextWindow, "\u4E0A\u4E0B\u6587\u9884\u7B97", 1e8) },
4602
4646
  ...value.maxOutputTokens === void 0 ? {} : { maxOutputTokens: positiveInteger(value.maxOutputTokens, "\u6700\u5927\u8F93\u51FA", 1e7) },
4603
- ...value.reasoningEfforts === void 0 ? {} : { reasoningEfforts: parseEfforts(value.reasoningEfforts) }
4647
+ ...value.reasoningEfforts === void 0 ? {} : { reasoningEfforts: parseEfforts(value.reasoningEfforts) },
4648
+ ...value.defaultEffort === void 0 ? {} : { defaultEffort: parseEffort(value.defaultEffort) }
4604
4649
  };
4605
4650
  }
4651
+ function parseEffort(value) {
4652
+ const effort = text(value, "\u9ED8\u8BA4\u601D\u8003\u6863\u4F4D", 32);
4653
+ if (!/^[A-Za-z][A-Za-z0-9_-]*$/u.test(effort)) throw new Error("\u9ED8\u8BA4\u601D\u8003\u6863\u4F4D\u683C\u5F0F\u65E0\u6548");
4654
+ return effort;
4655
+ }
4606
4656
  function parseStatusConfig(value) {
4607
4657
  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");
4658
+ if (typeof value.apiKeyEnv !== "string" || value.apiKeyEnv.length > MAX_ENV_REF) {
4659
+ throw new Error(`\u51ED\u636E\u5F15\u7528\u540D\u5FC5\u987B\u662F\u6700\u591A ${MAX_ENV_REF} \u5B57\u7B26\u7684\u5B57\u7B26\u4E32`);
4660
+ }
4661
+ const apiKeyEnv = value.apiKeyEnv;
4662
+ if (apiKeyEnv !== "" && !ENV_REF.test(apiKeyEnv)) throw new Error("\u51ED\u636E\u5F15\u7528\u540D\u5FC5\u987B\u662F\u5408\u6CD5\u6807\u8BC6\u7B26");
4610
4663
  return {
4611
4664
  emptyTurnGuard: flag(value.emptyTurnGuard, "\u7A7A\u8F6E\u4FDD\u62A4\u5F00\u5173"),
4612
4665
  ...value.turnCompletionReview === void 0 ? {} : { turnCompletionReview: flag(value.turnCompletionReview, "\u7ED3\u675F\u56DE\u5408\u6838\u9A8C\u5F00\u5173") },
@@ -4690,6 +4743,8 @@ var name = "llm-opendesign-corouter";
4690
4743
  var inject = ["llm"];
4691
4744
  var API_KEY = credentialKey2(name, "api-key");
4692
4745
  var SESSION = credentialKey2(name, "console");
4746
+ var SETTINGS_CONFLICT = "SETTINGS_CONFLICT";
4747
+ var NATIVE_AUTH = { env: [], oauth: true };
4693
4748
  var hash = (value) => createHash2("sha256").update(JSON.stringify(value) ?? "").digest("hex");
4694
4749
  var stableConfig = (config) => {
4695
4750
  const { modelCatalog: _snapshot, ...rest } = config;
@@ -4802,13 +4857,21 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
4802
4857
  const config = this._config();
4803
4858
  const snapshot = config.modelCatalog;
4804
4859
  if (!snapshot || snapshot.baseURL !== config.baseURL) return;
4805
- this._models = snapshot.models;
4860
+ this._models = snapshot.models.map((row) => {
4861
+ const known = findModel(row.id);
4862
+ if (known?.defaultEffort === void 0 || row.defaultEffort !== void 0) return row;
4863
+ return (row.reasoningEfforts ?? []).includes(known.defaultEffort) ? { ...row, defaultEffort: known.defaultEffort } : row;
4864
+ });
4806
4865
  this._modelsUpdatedAt = snapshot.updatedAt;
4807
4866
  }
4808
4867
  /**
4809
4868
  * Persist the snapshot through the Host form service.
4810
4869
  * `unsupported` means no settings service is composed (nothing to report);
4811
4870
  * `unavailable` means the service exists but exposes no writable form for this plugin.
4871
+ *
4872
+ * A settings write rewrites the whole composed profile and may rebuild the plugin tree, so
4873
+ * only a concurrent revision conflict (`SETTINGS_CONFLICT`) is worth re-reading the revision
4874
+ * and trying once more. Every other failure repeats identically and is reported immediately.
4812
4875
  */
4813
4876
  async _persistModels(value) {
4814
4877
  const settings = this.ctx.get("settings");
@@ -4824,7 +4887,8 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
4824
4887
  try {
4825
4888
  await settings.update(SETTINGS_NS, { modelCatalog: value }, descriptor.revision);
4826
4889
  return "saved";
4827
- } catch {
4890
+ } catch (error) {
4891
+ if (attempt > 0 || !record(error) || error.code !== SETTINGS_CONFLICT) return "failed";
4828
4892
  }
4829
4893
  }
4830
4894
  return "failed";
@@ -4861,7 +4925,7 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
4861
4925
  async _state() {
4862
4926
  const credentials = this.ctx.get("credentials"), config = this._config();
4863
4927
  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);
4928
+ const resolved = await this._key(apiKeyRef(config), config.baseURL, apiRecord, sessionRecord);
4865
4929
  const key = resolved?.key;
4866
4930
  const state = { apiRecord, sessionRecord, key, keySource: resolved?.source, config };
4867
4931
  const modelsFingerprint = hash({ key, baseURL: config.baseURL });
@@ -4904,12 +4968,14 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
4904
4968
  ...this._quota.source ? { sessionSource: this._quota.source } : {},
4905
4969
  quota: this._quota,
4906
4970
  login: this._login.status(),
4907
- config: state.config,
4971
+ config: { ...state.config, apiKeyEnv: state.config.apiKeyEnv ?? "" },
4908
4972
  guardedTurns: this.guardedTurns,
4909
4973
  ...this.turnMonitorStatus ? { turnMonitor: this.turnMonitorStatus() } : {},
4910
4974
  models: this._models.map((row) => {
4911
4975
  const { id, name: name2, group: group2, contextWindow, maxOutputTokens, inputModalities } = row;
4912
- const reasoningEfforts = modelReasoningEfforts(row, state.config.apiProtocol ?? "chat-completions");
4976
+ const protocol = state.config.apiProtocol ?? "chat-completions";
4977
+ const reasoningEfforts = modelReasoningEfforts(row, protocol);
4978
+ const defaultEffort = vendorDefaultEffort(row, protocol);
4913
4979
  return {
4914
4980
  id,
4915
4981
  name: name2,
@@ -4918,7 +4984,8 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
4918
4984
  ...inputModalities === void 0 ? {} : { inputModalities },
4919
4985
  ...contextWindow === void 0 ? {} : { contextWindow },
4920
4986
  ...maxOutputTokens === void 0 ? {} : { maxOutputTokens },
4921
- ...reasoningEfforts === void 0 ? {} : { reasoningEfforts }
4987
+ ...reasoningEfforts === void 0 ? {} : { reasoningEfforts },
4988
+ ...defaultEffort === void 0 ? {} : { defaultEffort }
4922
4989
  };
4923
4990
  }),
4924
4991
  modelsSource: this._modelsUpdatedAt ? "openai" : "builtin",
@@ -5182,7 +5249,7 @@ function apply(ctx, config) {
5182
5249
  ctx.llm.registerModelDiscovery(SETTINGS_NS, async (request, signal) => {
5183
5250
  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
5251
  const config2 = current();
5185
- const key = request.apiKey ?? await service.resolveApiKey(config2.apiKeyEnv, config2.baseURL);
5252
+ const key = request.apiKey ?? await service.resolveApiKey(apiKeyRef(config2), config2.baseURL);
5186
5253
  if (!key) throw new LlmError14("\u8BF7\u5148\u914D\u7F6E CoRouter API Key", "MISSING_CREDENTIAL");
5187
5254
  const models = await fetchModelCatalog(config2.baseURL, key, signal);
5188
5255
  return models.map((row) => {
@@ -5191,8 +5258,8 @@ function apply(ctx, config) {
5191
5258
  });
5192
5259
  });
5193
5260
  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 }
5261
+ { provider: PLAN_PROVIDER, displayName: "OpenDesign CoRouter \xB7 \u5957\u9910\u8D60\u9001", settingsNs: SETTINGS_NS, settingsPath: [], defaultBaseURL: current().baseURL, nativeAuth: NATIVE_AUTH },
5262
+ { provider: PAID_PROVIDER, displayName: "OpenDesign CoRouter \xB7 \u4ED8\u8D39\u6A21\u578B", settingsNs: SETTINGS_NS, settingsPath: [], defaultBaseURL: current().baseURL, nativeAuth: NATIVE_AUTH }
5196
5263
  ]);
5197
5264
  ctx.effect(() => () => {
5198
5265
  adapter.dispose();