dsh-opendesign-corouter 0.1.15 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/lib/client-config-writes.d.ts +36 -0
- package/lib/client-context-quick.d.ts +35 -0
- package/lib/client.d.ts +29 -6
- package/lib/client.js +1042 -446
- package/lib/config.d.ts +7 -0
- package/lib/context-budget.d.ts +23 -0
- package/lib/device-auth.d.ts +1 -1
- package/lib/generated/typert.host.js +9 -1
- package/lib/generated/typert.remote-client.js +9 -1
- package/lib/index.d.ts +12 -0
- package/lib/index.js +168 -16
- package/lib/index.js.map +4 -4
- package/lib/model-catalog-snapshot.d.ts +22 -0
- package/lib/model-settings.d.ts +7 -4
- package/lib/remote.d.ts +2 -0
- package/package.json +3 -1
package/lib/config.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Schema from '@deepseek-ai/schemastery';
|
|
2
2
|
import { type ApiProtocol } from './protocol-options.js';
|
|
3
3
|
import { type ModelSettingsMap } from './model-settings.js';
|
|
4
|
+
import { type ModelCatalogSnapshot } from './model-catalog-snapshot.js';
|
|
4
5
|
export { DEFAULT_MAX_REQUEST_IMAGE_BYTES } from './image-budget.js';
|
|
5
6
|
export declare const SETTINGS_NS = "llm-opendesign-corouter";
|
|
6
7
|
export declare const PLAN_PROVIDER = "opendesign-corouter-plan";
|
|
@@ -11,8 +12,10 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
|
|
|
11
12
|
baseURL: Schema<string, string, "volatile-defined">;
|
|
12
13
|
apiProtocol: Schema<"chat-completions" | "responses" | "messages", "chat-completions" | "responses" | "messages", "volatile-defined">;
|
|
13
14
|
modelSettings: Schema<NoInfer<import("@deepseek-ai/cosmokit").Dict<unknown, string>>, NoInfer<ModelSettingsMap>, "volatile-defined">;
|
|
15
|
+
modelCatalog: Schema<unknown, NoInfer<ModelCatalogSnapshot | undefined>, "volatile">;
|
|
14
16
|
useDesktopCredential: Schema<boolean, boolean, "volatile-defined">;
|
|
15
17
|
emptyTurnGuard: Schema<boolean, boolean, "volatile-defined">;
|
|
18
|
+
turnCompletionReview: Schema<boolean, boolean, "volatile-defined">;
|
|
16
19
|
turnReviewMaxContinuations: Schema<number, number, "volatile-defined">;
|
|
17
20
|
turnReviewNoProgressLimit: Schema<number, number, "volatile-defined">;
|
|
18
21
|
quotaRefreshSeconds: Schema<number, number, "volatile-defined">;
|
|
@@ -24,8 +27,10 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
|
|
|
24
27
|
baseURL: Schema<string, string, "volatile-defined">;
|
|
25
28
|
apiProtocol: Schema<"chat-completions" | "responses" | "messages", "chat-completions" | "responses" | "messages", "volatile-defined">;
|
|
26
29
|
modelSettings: Schema<NoInfer<import("@deepseek-ai/cosmokit").Dict<unknown, string>>, NoInfer<ModelSettingsMap>, "volatile-defined">;
|
|
30
|
+
modelCatalog: Schema<unknown, NoInfer<ModelCatalogSnapshot | undefined>, "volatile">;
|
|
27
31
|
useDesktopCredential: Schema<boolean, boolean, "volatile-defined">;
|
|
28
32
|
emptyTurnGuard: Schema<boolean, boolean, "volatile-defined">;
|
|
33
|
+
turnCompletionReview: Schema<boolean, boolean, "volatile-defined">;
|
|
29
34
|
turnReviewMaxContinuations: Schema<number, number, "volatile-defined">;
|
|
30
35
|
turnReviewNoProgressLimit: Schema<number, number, "volatile-defined">;
|
|
31
36
|
quotaRefreshSeconds: Schema<number, number, "volatile-defined">;
|
|
@@ -43,8 +48,10 @@ export interface RuntimeConfig {
|
|
|
43
48
|
streamIdleTimeoutMs: number;
|
|
44
49
|
apiProtocol?: ApiProtocol;
|
|
45
50
|
modelSettings?: ModelSettingsMap;
|
|
51
|
+
modelCatalog?: ModelCatalogSnapshot;
|
|
46
52
|
quotaRefreshSeconds?: number;
|
|
47
53
|
maxRequestImageBytes?: number;
|
|
54
|
+
turnCompletionReview?: boolean;
|
|
48
55
|
turnReviewMaxContinuations?: number;
|
|
49
56
|
turnReviewNoProgressLimit?: number;
|
|
50
57
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Client working windows, including both input and reserved output tokens. */
|
|
2
|
+
export declare const CONTEXT_WINDOW_PRESETS: readonly [{
|
|
3
|
+
readonly id: "default";
|
|
4
|
+
readonly label: "默认";
|
|
5
|
+
readonly tokens: 272000;
|
|
6
|
+
}, {
|
|
7
|
+
readonly id: "extended";
|
|
8
|
+
readonly label: "扩展";
|
|
9
|
+
readonly tokens: 500000;
|
|
10
|
+
}, {
|
|
11
|
+
readonly id: "maximum";
|
|
12
|
+
readonly label: "最大";
|
|
13
|
+
readonly tokens: 872000;
|
|
14
|
+
}];
|
|
15
|
+
export type ContextWindowPresetId = typeof CONTEXT_WINDOW_PRESETS[number]['id'];
|
|
16
|
+
/** Saved numbers are always legacy custom windows; only an explicit tier selects a preset. */
|
|
17
|
+
export declare function contextWindowPreset(legacyOverride: number | undefined, tier?: ContextWindowPresetId): ContextWindowPresetId | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Presets never increase a known catalog/gateway reference. Historical custom
|
|
20
|
+
* numbers retain their prior meaning until the user explicitly chooses a preset.
|
|
21
|
+
* An unknown reference does not imply model capacity: the preset is a local budget.
|
|
22
|
+
*/
|
|
23
|
+
export declare function effectiveContextWindow(reference: number | undefined, override?: number, tier?: ContextWindowPresetId): number;
|
package/lib/device-auth.d.ts
CHANGED
|
@@ -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.
|
|
6
|
+
export declare const DEVICE_AUTH_PLUGIN_VERSION = "0.1.17";
|
|
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;
|
|
@@ -43,7 +43,7 @@ function parseModelSettingsMap(value) {
|
|
|
43
43
|
if (value === null || typeof value !== "object" || Array.isArray(value)) throw new Error("\u6A21\u578B\u8BBE\u7F6E\u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
44
44
|
const keys = Object.keys(value);
|
|
45
45
|
if (keys.length > 512) throw new Error("\u6A21\u578B\u8BBE\u7F6E\u6700\u591A\u5141\u8BB8 512 \u4E2A\u6A21\u578B");
|
|
46
|
-
const fields = /* @__PURE__ */ new Set(["enabled", "imageInput", "temperature", "topP", "maxTokens", "contextWindow", "reasoningEffort"]);
|
|
46
|
+
const fields = /* @__PURE__ */ new Set(["enabled", "imageInput", "temperature", "topP", "maxTokens", "contextWindow", "contextTier", "reasoningEffort"]);
|
|
47
47
|
const efforts = ["none", "minimal", "low", "medium", "high", "xhigh", "ultra", "max"];
|
|
48
48
|
const out = {};
|
|
49
49
|
for (const id of keys) {
|
|
@@ -76,6 +76,13 @@ function parseModelSettingsMap(value) {
|
|
|
76
76
|
if (typeof item !== "number" || !Number.isSafeInteger(item) || item < 1 || item > max) throw new Error(`\u6A21\u578B\u8BBE\u7F6E\u7684 ${field} \u5FC5\u987B\u662F 1 \u5230 ${max} \u4E4B\u95F4\u7684\u6574\u6570`);
|
|
77
77
|
parsed[field] = item;
|
|
78
78
|
}
|
|
79
|
+
if (settings.contextTier !== void 0) {
|
|
80
|
+
if (settings.contextTier !== "default" && settings.contextTier !== "extended" && settings.contextTier !== "maximum") throw new Error("\u6A21\u578B\u8BBE\u7F6E\u7684 contextTier \u4E0D\u5728\u5141\u8BB8\u7684\u53D6\u503C\u5185");
|
|
81
|
+
if (parsed.contextWindow !== void 0) throw new Error("\u4E0A\u4E0B\u6587\u6863\u4F4D\u4E0E\u65E7\u81EA\u5B9A\u4E49\u7A97\u53E3\u4E0D\u80FD\u540C\u65F6\u8BBE\u7F6E");
|
|
82
|
+
parsed.contextTier = settings.contextTier;
|
|
83
|
+
const window = parsed.contextTier === "default" ? 272e3 : parsed.contextTier === "extended" ? 5e5 : 872e3;
|
|
84
|
+
if (parsed.maxTokens !== void 0 && parsed.maxTokens >= window) throw new Error("\u6A21\u578B\u8BBE\u7F6E\u7684 maxTokens \u5FC5\u987B\u5C0F\u4E8E\u6863\u4F4D\u603B\u7A97\u53E3");
|
|
85
|
+
}
|
|
79
86
|
if (settings.reasoningEffort !== void 0) {
|
|
80
87
|
if (typeof settings.reasoningEffort !== "string" || !efforts.includes(settings.reasoningEffort)) throw new Error("\u6A21\u578B\u8BBE\u7F6E\u7684 reasoningEffort \u4E0D\u5728\u5141\u8BB8\u7684\u53D6\u503C\u5185");
|
|
81
88
|
parsed.reasoningEffort = settings.reasoningEffort;
|
|
@@ -276,6 +283,7 @@ function parseStatusConfig(value) {
|
|
|
276
283
|
if (!ENV_REF.test(apiKeyEnv)) throw new Error("\u51ED\u636E\u5F15\u7528\u540D\u5FC5\u987B\u662F\u5408\u6CD5\u6807\u8BC6\u7B26");
|
|
277
284
|
return {
|
|
278
285
|
emptyTurnGuard: flag(value.emptyTurnGuard, "\u7A7A\u8F6E\u4FDD\u62A4\u5F00\u5173"),
|
|
286
|
+
...value.turnCompletionReview === void 0 ? {} : { turnCompletionReview: flag(value.turnCompletionReview, "\u7ED3\u675F\u56DE\u5408\u6838\u9A8C\u5F00\u5173") },
|
|
279
287
|
useDesktopCredential: flag(value.useDesktopCredential, "\u684C\u9762\u767B\u5F55\u6001\u5F00\u5173"),
|
|
280
288
|
baseURL: text(value.baseURL, "\u63A8\u7406\u5730\u5740", MAX_BASE_URL),
|
|
281
289
|
apiKeyEnv,
|
|
@@ -43,7 +43,7 @@ function parseModelSettingsMap(value) {
|
|
|
43
43
|
if (value === null || typeof value !== "object" || Array.isArray(value)) throw new Error("\u6A21\u578B\u8BBE\u7F6E\u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
44
44
|
const keys = Object.keys(value);
|
|
45
45
|
if (keys.length > 512) throw new Error("\u6A21\u578B\u8BBE\u7F6E\u6700\u591A\u5141\u8BB8 512 \u4E2A\u6A21\u578B");
|
|
46
|
-
const fields = /* @__PURE__ */ new Set(["enabled", "imageInput", "temperature", "topP", "maxTokens", "contextWindow", "reasoningEffort"]);
|
|
46
|
+
const fields = /* @__PURE__ */ new Set(["enabled", "imageInput", "temperature", "topP", "maxTokens", "contextWindow", "contextTier", "reasoningEffort"]);
|
|
47
47
|
const efforts = ["none", "minimal", "low", "medium", "high", "xhigh", "ultra", "max"];
|
|
48
48
|
const out = {};
|
|
49
49
|
for (const id of keys) {
|
|
@@ -76,6 +76,13 @@ function parseModelSettingsMap(value) {
|
|
|
76
76
|
if (typeof item !== "number" || !Number.isSafeInteger(item) || item < 1 || item > max) throw new Error(`\u6A21\u578B\u8BBE\u7F6E\u7684 ${field} \u5FC5\u987B\u662F 1 \u5230 ${max} \u4E4B\u95F4\u7684\u6574\u6570`);
|
|
77
77
|
parsed[field] = item;
|
|
78
78
|
}
|
|
79
|
+
if (settings.contextTier !== void 0) {
|
|
80
|
+
if (settings.contextTier !== "default" && settings.contextTier !== "extended" && settings.contextTier !== "maximum") throw new Error("\u6A21\u578B\u8BBE\u7F6E\u7684 contextTier \u4E0D\u5728\u5141\u8BB8\u7684\u53D6\u503C\u5185");
|
|
81
|
+
if (parsed.contextWindow !== void 0) throw new Error("\u4E0A\u4E0B\u6587\u6863\u4F4D\u4E0E\u65E7\u81EA\u5B9A\u4E49\u7A97\u53E3\u4E0D\u80FD\u540C\u65F6\u8BBE\u7F6E");
|
|
82
|
+
parsed.contextTier = settings.contextTier;
|
|
83
|
+
const window = parsed.contextTier === "default" ? 272e3 : parsed.contextTier === "extended" ? 5e5 : 872e3;
|
|
84
|
+
if (parsed.maxTokens !== void 0 && parsed.maxTokens >= window) throw new Error("\u6A21\u578B\u8BBE\u7F6E\u7684 maxTokens \u5FC5\u987B\u5C0F\u4E8E\u6863\u4F4D\u603B\u7A97\u53E3");
|
|
85
|
+
}
|
|
79
86
|
if (settings.reasoningEffort !== void 0) {
|
|
80
87
|
if (typeof settings.reasoningEffort !== "string" || !efforts.includes(settings.reasoningEffort)) throw new Error("\u6A21\u578B\u8BBE\u7F6E\u7684 reasoningEffort \u4E0D\u5728\u5141\u8BB8\u7684\u53D6\u503C\u5185");
|
|
81
88
|
parsed.reasoningEffort = settings.reasoningEffort;
|
|
@@ -276,6 +283,7 @@ function parseStatusConfig(value) {
|
|
|
276
283
|
if (!ENV_REF.test(apiKeyEnv)) throw new Error("\u51ED\u636E\u5F15\u7528\u540D\u5FC5\u987B\u662F\u5408\u6CD5\u6807\u8BC6\u7B26");
|
|
277
284
|
return {
|
|
278
285
|
emptyTurnGuard: flag(value.emptyTurnGuard, "\u7A7A\u8F6E\u4FDD\u62A4\u5F00\u5173"),
|
|
286
|
+
...value.turnCompletionReview === void 0 ? {} : { turnCompletionReview: flag(value.turnCompletionReview, "\u7ED3\u675F\u56DE\u5408\u6838\u9A8C\u5F00\u5173") },
|
|
279
287
|
useDesktopCredential: flag(value.useDesktopCredential, "\u684C\u9762\u767B\u5F55\u6001\u5F00\u5173"),
|
|
280
288
|
baseURL: text(value.baseURL, "\u63A8\u7406\u5730\u5740", MAX_BASE_URL),
|
|
281
289
|
apiKeyEnv,
|
package/lib/index.d.ts
CHANGED
|
@@ -50,6 +50,8 @@ export declare class OpenDesignCoRouterService extends TypertRemoteService {
|
|
|
50
50
|
private _modelsEpoch;
|
|
51
51
|
private _modelsPending;
|
|
52
52
|
private _modelsController;
|
|
53
|
+
private _modelsWriteSerial;
|
|
54
|
+
private _modelsWrite;
|
|
53
55
|
private _prices;
|
|
54
56
|
private _pricesPending;
|
|
55
57
|
modelCatalog(): readonly CatalogModel[];
|
|
@@ -57,6 +59,16 @@ export declare class OpenDesignCoRouterService extends TypertRemoteService {
|
|
|
57
59
|
private _credentials;
|
|
58
60
|
private _key;
|
|
59
61
|
resolveApiKey(ref: string, baseURL?: string): Promise<string | undefined>;
|
|
62
|
+
/** Restore the persisted gateway catalog when it belongs to the active gateway. */
|
|
63
|
+
private _restoreModels;
|
|
64
|
+
/**
|
|
65
|
+
* Persist the snapshot through the Host form service.
|
|
66
|
+
* `unsupported` means no settings service is composed (nothing to report);
|
|
67
|
+
* `unavailable` means the service exists but exposes no writable form for this plugin.
|
|
68
|
+
*/
|
|
69
|
+
private _persistModels;
|
|
70
|
+
/** Serialize snapshot writes so the newest successful refresh is the last one persisted. */
|
|
71
|
+
private _queueModelsWrite;
|
|
60
72
|
private _invalidateModels;
|
|
61
73
|
private _state;
|
|
62
74
|
private _conflict;
|
package/lib/index.js
CHANGED
|
@@ -249,13 +249,25 @@ function inferenceEndpoint(baseURL, protocol) {
|
|
|
249
249
|
return baseURL.trim() === "" ? suffix : `${openAiBaseURL(baseURL.trim())}${suffix}`;
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
+
// src/context-budget.ts
|
|
253
|
+
var CONTEXT_WINDOW_PRESETS = [
|
|
254
|
+
{ id: "default", label: "\u9ED8\u8BA4", tokens: 272e3 },
|
|
255
|
+
{ id: "extended", label: "\u6269\u5C55", tokens: 5e5 },
|
|
256
|
+
{ id: "maximum", label: "\u6700\u5927", tokens: 872e3 }
|
|
257
|
+
];
|
|
258
|
+
function effectiveContextWindow(reference, override, tier) {
|
|
259
|
+
if (tier === void 0 && override !== void 0) return override;
|
|
260
|
+
const requested = (CONTEXT_WINDOW_PRESETS.find((preset) => preset.id === (tier ?? "default")) ?? CONTEXT_WINDOW_PRESETS[0]).tokens;
|
|
261
|
+
return reference === void 0 ? requested : Math.min(requested, reference);
|
|
262
|
+
}
|
|
263
|
+
|
|
252
264
|
// src/model-settings.ts
|
|
253
265
|
var RESERVED_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
254
266
|
function parseModelSettingsMap(value) {
|
|
255
267
|
if (value === null || typeof value !== "object" || Array.isArray(value)) throw new Error("\u6A21\u578B\u8BBE\u7F6E\u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
256
268
|
const keys = Object.keys(value);
|
|
257
269
|
if (keys.length > 512) throw new Error("\u6A21\u578B\u8BBE\u7F6E\u6700\u591A\u5141\u8BB8 512 \u4E2A\u6A21\u578B");
|
|
258
|
-
const fields = /* @__PURE__ */ new Set(["enabled", "imageInput", "temperature", "topP", "maxTokens", "contextWindow", "reasoningEffort"]);
|
|
270
|
+
const fields = /* @__PURE__ */ new Set(["enabled", "imageInput", "temperature", "topP", "maxTokens", "contextWindow", "contextTier", "reasoningEffort"]);
|
|
259
271
|
const efforts = ["none", "minimal", "low", "medium", "high", "xhigh", "ultra", "max"];
|
|
260
272
|
const out = {};
|
|
261
273
|
for (const id of keys) {
|
|
@@ -288,6 +300,13 @@ function parseModelSettingsMap(value) {
|
|
|
288
300
|
if (typeof item !== "number" || !Number.isSafeInteger(item) || item < 1 || item > max) throw new Error(`\u6A21\u578B\u8BBE\u7F6E\u7684 ${field} \u5FC5\u987B\u662F 1 \u5230 ${max} \u4E4B\u95F4\u7684\u6574\u6570`);
|
|
289
301
|
parsed[field] = item;
|
|
290
302
|
}
|
|
303
|
+
if (settings.contextTier !== void 0) {
|
|
304
|
+
if (settings.contextTier !== "default" && settings.contextTier !== "extended" && settings.contextTier !== "maximum") throw new Error("\u6A21\u578B\u8BBE\u7F6E\u7684 contextTier \u4E0D\u5728\u5141\u8BB8\u7684\u53D6\u503C\u5185");
|
|
305
|
+
if (parsed.contextWindow !== void 0) throw new Error("\u4E0A\u4E0B\u6587\u6863\u4F4D\u4E0E\u65E7\u81EA\u5B9A\u4E49\u7A97\u53E3\u4E0D\u80FD\u540C\u65F6\u8BBE\u7F6E");
|
|
306
|
+
parsed.contextTier = settings.contextTier;
|
|
307
|
+
const window = parsed.contextTier === "default" ? 272e3 : parsed.contextTier === "extended" ? 5e5 : 872e3;
|
|
308
|
+
if (parsed.maxTokens !== void 0 && parsed.maxTokens >= window) throw new Error("\u6A21\u578B\u8BBE\u7F6E\u7684 maxTokens \u5FC5\u987B\u5C0F\u4E8E\u6863\u4F4D\u603B\u7A97\u53E3");
|
|
309
|
+
}
|
|
291
310
|
if (settings.reasoningEffort !== void 0) {
|
|
292
311
|
if (typeof settings.reasoningEffort !== "string" || !efforts.includes(settings.reasoningEffort)) throw new Error("\u6A21\u578B\u8BBE\u7F6E\u7684 reasoningEffort \u4E0D\u5728\u5141\u8BB8\u7684\u53D6\u503C\u5185");
|
|
293
312
|
parsed.reasoningEffort = settings.reasoningEffort;
|
|
@@ -298,14 +317,14 @@ function parseModelSettingsMap(value) {
|
|
|
298
317
|
return out;
|
|
299
318
|
}
|
|
300
319
|
function applyModelSettings(row, settings) {
|
|
301
|
-
const { contextWindow, maxTokens, imageInput } = settings ?? {};
|
|
302
|
-
if (contextWindow === void 0 && maxTokens === void 0 && imageInput === void 0) return { ...row };
|
|
320
|
+
const { contextWindow, contextTier, maxTokens, imageInput } = settings ?? {};
|
|
303
321
|
if (contextWindow !== void 0) parseModelSettingsMap({ model: { contextWindow } });
|
|
322
|
+
if (contextTier !== void 0) parseModelSettingsMap({ model: { contextTier, ...contextWindow === void 0 ? {} : { contextWindow } } });
|
|
304
323
|
if (maxTokens !== void 0) parseModelSettingsMap({ model: { maxTokens } });
|
|
305
324
|
if (imageInput !== void 0) parseModelSettingsMap({ model: { imageInput } });
|
|
306
325
|
return {
|
|
307
326
|
...row,
|
|
308
|
-
|
|
327
|
+
contextWindow: effectiveContextWindow(row.contextWindow, contextWindow, contextTier),
|
|
309
328
|
...maxTokens === void 0 ? {} : { maxOutputTokens: maxTokens },
|
|
310
329
|
...imageInput === void 0 ? {} : { inputModalities: imageInput ? ["text", "image"] : ["text"] }
|
|
311
330
|
};
|
|
@@ -324,6 +343,71 @@ function serializableTransform(callback) {
|
|
|
324
343
|
});
|
|
325
344
|
}
|
|
326
345
|
|
|
346
|
+
// src/model-catalog-snapshot.ts
|
|
347
|
+
function parseModelCatalogSnapshot(value) {
|
|
348
|
+
const MODEL_ID4 = /^[A-Za-z0-9._:/-]{1,128}$/u;
|
|
349
|
+
const GROUPS = ["plan", "paid"];
|
|
350
|
+
const KEYS = ["id", "name", "group", "contextWindow", "maxOutputTokens", "inputModalities", "reasoningEfforts"];
|
|
351
|
+
const RESERVED = ["__proto__", "constructor", "prototype"];
|
|
352
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
353
|
+
const snapshot = value;
|
|
354
|
+
if (typeof snapshot.baseURL !== "string" || snapshot.baseURL.length === 0 || snapshot.baseURL.length > 2048) return void 0;
|
|
355
|
+
let base;
|
|
356
|
+
try {
|
|
357
|
+
base = new URL(snapshot.baseURL);
|
|
358
|
+
} catch {
|
|
359
|
+
return void 0;
|
|
360
|
+
}
|
|
361
|
+
if (!["https:", "http:"].includes(base.protocol) || base.username || base.password || base.search || base.hash) return void 0;
|
|
362
|
+
if (base.protocol === "http:" && !["localhost", "127.0.0.1", "[::1]"].includes(base.hostname)) return void 0;
|
|
363
|
+
const baseURL = base.href.replace(/\/+$/u, "");
|
|
364
|
+
if (baseURL.length === 0 || baseURL.length > 2048) return void 0;
|
|
365
|
+
if (typeof snapshot.updatedAt !== "string" || snapshot.updatedAt.length === 0 || snapshot.updatedAt.length > 64 || !Number.isFinite(Date.parse(snapshot.updatedAt))) return void 0;
|
|
366
|
+
if (!Array.isArray(snapshot.models) || snapshot.models.length === 0 || snapshot.models.length > 512) return void 0;
|
|
367
|
+
const seen = /* @__PURE__ */ new Set();
|
|
368
|
+
const models = [];
|
|
369
|
+
for (const entry of snapshot.models) {
|
|
370
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) return void 0;
|
|
371
|
+
const item = entry;
|
|
372
|
+
for (const key of Object.keys(item)) if (!KEYS.includes(key)) return void 0;
|
|
373
|
+
const id = item.id, name2 = item.name, group2 = item.group;
|
|
374
|
+
if (typeof id !== "string" || id.length === 0 || id.length > 128 || !MODEL_ID4.test(id) || seen.has(id) || RESERVED.includes(id)) return void 0;
|
|
375
|
+
if (typeof name2 !== "string" || name2.trim().length === 0 || name2.length > 128) return void 0;
|
|
376
|
+
if (typeof group2 !== "string" || !GROUPS.includes(group2)) return void 0;
|
|
377
|
+
const model = { id, name: name2, group: group2 };
|
|
378
|
+
if (item.contextWindow !== void 0) {
|
|
379
|
+
if (!Number.isSafeInteger(item.contextWindow) || item.contextWindow <= 0 || item.contextWindow > 1e8) return void 0;
|
|
380
|
+
model.contextWindow = item.contextWindow;
|
|
381
|
+
}
|
|
382
|
+
if (item.maxOutputTokens !== void 0) {
|
|
383
|
+
if (!Number.isSafeInteger(item.maxOutputTokens) || item.maxOutputTokens <= 0 || item.maxOutputTokens > 1e7) return void 0;
|
|
384
|
+
model.maxOutputTokens = item.maxOutputTokens;
|
|
385
|
+
}
|
|
386
|
+
if (item.inputModalities !== void 0) {
|
|
387
|
+
if (!Array.isArray(item.inputModalities) || item.inputModalities.length < 1 || item.inputModalities.length > 2) return void 0;
|
|
388
|
+
const modalities = [];
|
|
389
|
+
for (const modality of item.inputModalities) {
|
|
390
|
+
if (modality !== "text" && modality !== "image") return void 0;
|
|
391
|
+
modalities.push(modality);
|
|
392
|
+
}
|
|
393
|
+
if (!modalities.includes("text") || new Set(modalities).size !== modalities.length) return void 0;
|
|
394
|
+
model.inputModalities = modalities;
|
|
395
|
+
}
|
|
396
|
+
if (item.reasoningEfforts !== void 0) {
|
|
397
|
+
if (!Array.isArray(item.reasoningEfforts) || item.reasoningEfforts.length > 16) return void 0;
|
|
398
|
+
const efforts = [];
|
|
399
|
+
for (const effort of item.reasoningEfforts) {
|
|
400
|
+
if (typeof effort !== "string" || effort.length === 0 || effort.length > 32) return void 0;
|
|
401
|
+
efforts.push(effort);
|
|
402
|
+
}
|
|
403
|
+
model.reasoningEfforts = efforts;
|
|
404
|
+
}
|
|
405
|
+
seen.add(id);
|
|
406
|
+
models.push(model);
|
|
407
|
+
}
|
|
408
|
+
return { baseURL, updatedAt: snapshot.updatedAt, models };
|
|
409
|
+
}
|
|
410
|
+
|
|
327
411
|
// src/image-budget.ts
|
|
328
412
|
var MIN_REQUEST_IMAGE_BYTES = 1024 * 1024;
|
|
329
413
|
var DEFAULT_MAX_REQUEST_IMAGE_BYTES = 20 * 1024 * 1024;
|
|
@@ -339,8 +423,10 @@ var Config = Schema.object({
|
|
|
339
423
|
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(),
|
|
340
424
|
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(),
|
|
341
425
|
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(),
|
|
426
|
+
modelCatalog: Schema.transform(Schema.any(), serializableTransform(parseModelCatalogSnapshot)).description("\u4E0A\u6B21\u6210\u529F\u8BFB\u53D6\u7684\u7F51\u5173\u6A21\u578B\u76EE\u5F55\u5FEB\u7167\uFF1B\u91CD\u542F\u540E\u7EE7\u7EED\u4F7F\u7528\uFF0C\u76F4\u5230\u518D\u6B21\u5237\u65B0").volatile(),
|
|
342
427
|
useDesktopCredential: Schema.boolean().default(true).description("\u4F18\u5148\u8BFB\u53D6 OpenDesign \u684C\u9762\u7AEF\u767B\u5F55\u6001\u67E5\u8BE2\u989D\u5EA6").volatile(),
|
|
343
|
-
emptyTurnGuard: Schema.boolean().default(true).description("\u4FDD\u62A4 DeepSeek V4.1 Flash \u5DE5\u5177\u5BF9\u8BDD\uFF1A\u6062\u590D\u7A7A\u56DE\u7B54\
|
|
428
|
+
emptyTurnGuard: Schema.boolean().default(true).description("\u4FDD\u62A4 DeepSeek V4.1 Flash \u5DE5\u5177\u5BF9\u8BDD\uFF1A\u6062\u590D\u7A7A\u56DE\u7B54\u4E0E\u5DF2\u77E5\u534F\u8BAE\u6B8B\u7559\u7ED3\u675F").volatile(),
|
|
429
|
+
turnCompletionReview: Schema.boolean().default(false).description("\u56DE\u590D\u7ED3\u675F\u540E\u8FFD\u52A0\u6709\u754C\u7684\u7ED3\u6784\u5316\u6536\u5C3E\u6838\u9A8C\uFF0C\u8981\u6C42\u6A21\u578B\u8C03\u7528\u6536\u5C3E\u5DE5\u5177\u62A5\u544A\u72B6\u6001").volatile(),
|
|
344
430
|
turnReviewMaxContinuations: Schema.natural().min(1).max(10).default(3).description("\u6BCF\u8F6E\u4EFB\u52A1\u7684\u6536\u5C3E\u6838\u9A8C\u6700\u591A\u7EED\u529E\u6B21\u6570").volatile(),
|
|
345
431
|
turnReviewNoProgressLimit: Schema.natural().min(1).max(5).default(2).description("\u8FDE\u7EED\u7F3A\u5C11\u65B0\u6210\u529F\u5DE5\u5177\u7ED3\u679C\u65F6\u505C\u6B62\u6536\u5C3E\u7EED\u529E\u7684\u6B21\u6570").volatile(),
|
|
346
432
|
quotaRefreshSeconds: Schema.natural().min(5).max(3600).default(60).description("\u989D\u5EA6\u81EA\u52A8\u5237\u65B0\u95F4\u9694\uFF08\u79D2\uFF09").volatile(),
|
|
@@ -363,17 +449,20 @@ function assertBaseURL(raw) {
|
|
|
363
449
|
return normalized;
|
|
364
450
|
}
|
|
365
451
|
function readConfig(config) {
|
|
452
|
+
const modelCatalog = parseModelCatalogSnapshot(config.modelCatalog.get());
|
|
366
453
|
return {
|
|
367
454
|
apiKeyEnv: config.apiKeyEnv.get(),
|
|
368
455
|
baseURL: assertBaseURL(config.baseURL.get()),
|
|
369
456
|
apiProtocol: config.apiProtocol.get(),
|
|
370
457
|
modelSettings: parseModelSettingsMap(config.modelSettings.get()),
|
|
458
|
+
...modelCatalog === void 0 ? {} : { modelCatalog },
|
|
371
459
|
quotaRefreshSeconds: config.quotaRefreshSeconds.get(),
|
|
372
460
|
useDesktopCredential: config.useDesktopCredential.get(),
|
|
373
461
|
emptyTurnGuard: config.emptyTurnGuard.get(),
|
|
374
462
|
requestTimeoutMs: config.requestTimeoutMs.get(),
|
|
375
463
|
streamIdleTimeoutMs: config.streamIdleTimeoutMs.get(),
|
|
376
464
|
maxRequestImageBytes: config.maxRequestImageBytes.get(),
|
|
465
|
+
turnCompletionReview: config.turnCompletionReview.get(),
|
|
377
466
|
turnReviewMaxContinuations: config.turnReviewMaxContinuations.get(),
|
|
378
467
|
turnReviewNoProgressLimit: config.turnReviewNoProgressLimit.get()
|
|
379
468
|
};
|
|
@@ -2008,7 +2097,7 @@ var CoRouterAdapter = class extends LlmAdapter {
|
|
|
2008
2097
|
if (!isModelEnabled(id, config.modelSettings)) throw new LlmError11("\u8BE5\u6A21\u578B\u5DF2\u5728 CoRouter \u8BBE\u7F6E\u4E2D\u505C\u7528", "MODEL_DISABLED");
|
|
2009
2098
|
const configured = applyModelSettings(row, config.modelSettings?.[id]);
|
|
2010
2099
|
const output = config.modelSettings?.[id]?.maxTokens;
|
|
2011
|
-
if (output !== void 0 && configured.contextWindow !== void 0 && output >= configured.contextWindow) throw new LlmError11("\u6A21\u578B\u6700\u5927\u8F93\u51FA\u5FC5\u987B\u5C0F\u4E8E\
|
|
2100
|
+
if (output !== void 0 && configured.contextWindow !== void 0 && output >= configured.contextWindow) throw new LlmError11("\u6A21\u578B\u6700\u5927\u8F93\u51FA\u5FC5\u987B\u5C0F\u4E8E\u5F53\u524D\u603B\u7A97\u53E3\uFF08\u542B\u8F93\u51FA\u9884\u7559\uFF09\uFF0C\u8BF7\u8C03\u6574\u6A21\u578B\u53C2\u6570", "INVALID_REQUEST");
|
|
2012
2101
|
return configured;
|
|
2013
2102
|
}
|
|
2014
2103
|
async listModels(provider) {
|
|
@@ -2446,6 +2535,11 @@ var TurnMonitor = class {
|
|
|
2446
2535
|
#report(decision, reason) {
|
|
2447
2536
|
this.#last = { at: new Date(this.now()).toISOString(), decision, reason };
|
|
2448
2537
|
}
|
|
2538
|
+
/** The completion handshake is opt-in; the empty-turn guard stays the outer switch. */
|
|
2539
|
+
#reviewing() {
|
|
2540
|
+
const config = this.config();
|
|
2541
|
+
return config.emptyTurnGuard === true && config.turnCompletionReview === true;
|
|
2542
|
+
}
|
|
2449
2543
|
#release(state) {
|
|
2450
2544
|
const remove = state.removeTool;
|
|
2451
2545
|
state.removeTool = void 0;
|
|
@@ -2466,7 +2560,7 @@ var TurnMonitor = class {
|
|
|
2466
2560
|
this.#active.delete(state);
|
|
2467
2561
|
}
|
|
2468
2562
|
configurationChanged() {
|
|
2469
|
-
if (this
|
|
2563
|
+
if (this.#reviewing()) return;
|
|
2470
2564
|
for (const state of [...this.#active]) {
|
|
2471
2565
|
state.settled = true;
|
|
2472
2566
|
this.#release(state);
|
|
@@ -2584,7 +2678,7 @@ var TurnMonitor = class {
|
|
|
2584
2678
|
output: { schema: outcomeSchema, render: (_args, value) => [{ type: "text", text: JSON.stringify(value) }] },
|
|
2585
2679
|
execute: async (args, exec) => {
|
|
2586
2680
|
exec.signal.throwIfAborted();
|
|
2587
|
-
if (this.#disposed || !this
|
|
2681
|
+
if (this.#disposed || !this.#reviewing() || state.settled || exec.agent !== state.agent || !state.removeTool || !exec.agent || this.#states.get(exec.agent.session) !== state || !monitored(exec.agent.session)) {
|
|
2588
2682
|
throw new LlmError13("\u5F53\u524D\u6CA1\u6709\u53EF\u63D0\u4EA4\u7684\u6536\u5C3E\u6838\u9A8C", "INVALID_REQUEST");
|
|
2589
2683
|
}
|
|
2590
2684
|
const outcome = parseOutcome(args);
|
|
@@ -2624,7 +2718,7 @@ var TurnMonitor = class {
|
|
|
2624
2718
|
stopping = ({ agent, turn, signal }) => {
|
|
2625
2719
|
const state = this.#states.get(agent.session);
|
|
2626
2720
|
if (!state || state.turn !== turn || state.settled || state.assistantSeq < 0 || state.checkedSeq === state.assistantSeq) return;
|
|
2627
|
-
if (this.#disposed || !this
|
|
2721
|
+
if (this.#disposed || !this.#reviewing() || !monitored(agent.session) || !state.assistantMonitored) {
|
|
2628
2722
|
this.#release(state);
|
|
2629
2723
|
return;
|
|
2630
2724
|
}
|
|
@@ -3399,7 +3493,7 @@ import { randomUUID as randomUUID2 } from "node:crypto";
|
|
|
3399
3493
|
|
|
3400
3494
|
// src/device-auth.ts
|
|
3401
3495
|
var DEVICE_AUTH_ENDPOINT = "https://amr-api.open-design.ai/api/v1/cli/device-authorizations";
|
|
3402
|
-
var DEVICE_AUTH_PLUGIN_VERSION = "0.1.
|
|
3496
|
+
var DEVICE_AUTH_PLUGIN_VERSION = "0.1.17";
|
|
3403
3497
|
var DEVICE_REQUEST_TIMEOUT_MS = 2e4;
|
|
3404
3498
|
var DEVICE_RESPONSE_MAX_BYTES = 65536;
|
|
3405
3499
|
var DEVICE_POLL_MIN_MS = 1e3;
|
|
@@ -4515,6 +4609,7 @@ function parseStatusConfig(value) {
|
|
|
4515
4609
|
if (!ENV_REF.test(apiKeyEnv)) throw new Error("\u51ED\u636E\u5F15\u7528\u540D\u5FC5\u987B\u662F\u5408\u6CD5\u6807\u8BC6\u7B26");
|
|
4516
4610
|
return {
|
|
4517
4611
|
emptyTurnGuard: flag(value.emptyTurnGuard, "\u7A7A\u8F6E\u4FDD\u62A4\u5F00\u5173"),
|
|
4612
|
+
...value.turnCompletionReview === void 0 ? {} : { turnCompletionReview: flag(value.turnCompletionReview, "\u7ED3\u675F\u56DE\u5408\u6838\u9A8C\u5F00\u5173") },
|
|
4518
4613
|
useDesktopCredential: flag(value.useDesktopCredential, "\u684C\u9762\u767B\u5F55\u6001\u5F00\u5173"),
|
|
4519
4614
|
baseURL: text(value.baseURL, "\u63A8\u7406\u5730\u5740", MAX_BASE_URL),
|
|
4520
4615
|
apiKeyEnv,
|
|
@@ -4596,6 +4691,10 @@ var inject = ["llm"];
|
|
|
4596
4691
|
var API_KEY = credentialKey2(name, "api-key");
|
|
4597
4692
|
var SESSION = credentialKey2(name, "console");
|
|
4598
4693
|
var hash = (value) => createHash2("sha256").update(JSON.stringify(value) ?? "").digest("hex");
|
|
4694
|
+
var stableConfig = (config) => {
|
|
4695
|
+
const { modelCatalog: _snapshot, ...rest } = config;
|
|
4696
|
+
return rest;
|
|
4697
|
+
};
|
|
4599
4698
|
var needLogin = () => ({ state: "need-login", updatedAt: (/* @__PURE__ */ new Date()).toISOString(), windows: [], balances: {}, note: "\u8BF7\u5728\u8FDE\u63A5\u4E0E\u767B\u5F55\u9875\u5B8C\u6210\u8D26\u53F7\u6388\u6743\u540E\u8BFB\u53D6\u989D\u5EA6\u3002" });
|
|
4600
4699
|
var unreadQuota = () => ({ state: "partial", updatedAt: (/* @__PURE__ */ new Date()).toISOString(), windows: [], balances: {}, note: "\u989D\u5EA6\u5C1A\u672A\u8BFB\u53D6\uFF0C\u8BF7\u5237\u65B0\u989D\u5EA6\u3002" });
|
|
4601
4700
|
function grantOf(value) {
|
|
@@ -4632,15 +4731,18 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
|
|
|
4632
4731
|
__publicField(this, "_modelsEpoch", 0);
|
|
4633
4732
|
__publicField(this, "_modelsPending");
|
|
4634
4733
|
__publicField(this, "_modelsController");
|
|
4734
|
+
__publicField(this, "_modelsWriteSerial", 0);
|
|
4735
|
+
__publicField(this, "_modelsWrite", Promise.resolve());
|
|
4635
4736
|
__publicField(this, "_prices");
|
|
4636
4737
|
__publicField(this, "_pricesPending");
|
|
4637
4738
|
this._config = config;
|
|
4739
|
+
this._restoreModels();
|
|
4638
4740
|
this._login = new ConsoleLogin({
|
|
4639
4741
|
capture: async (expectedRevision) => {
|
|
4640
4742
|
const state = await this._state();
|
|
4641
4743
|
this._expect(expectedRevision);
|
|
4642
4744
|
this._credentials();
|
|
4643
|
-
return { revision: expectedRevision, sessionHash: hash(state.sessionRecord), configHash: hash(state.config) };
|
|
4745
|
+
return { revision: expectedRevision, sessionHash: hash(state.sessionRecord), configHash: hash(stableConfig(state.config)) };
|
|
4644
4746
|
},
|
|
4645
4747
|
commit: async (tokens, captured, signal) => {
|
|
4646
4748
|
if (!record(captured) || typeof captured.revision !== "string" || typeof captured.sessionHash !== "string" || typeof captured.configHash !== "string") throw this._conflict();
|
|
@@ -4649,7 +4751,7 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
|
|
|
4649
4751
|
signal.throwIfAborted();
|
|
4650
4752
|
await this._credentials().modifyRecord(SESSION, async (current) => {
|
|
4651
4753
|
signal.throwIfAborted();
|
|
4652
|
-
if (hash(current) !== captured.sessionHash || hash(this._config()) !== captured.configHash) throw this._conflict();
|
|
4754
|
+
if (hash(current) !== captured.sessionHash || hash(stableConfig(this._config())) !== captured.configHash) throw this._conflict();
|
|
4653
4755
|
const grant = deviceGrant({ kind: "device", ...tokens });
|
|
4654
4756
|
if (!grant) throw new ConsoleError("auth");
|
|
4655
4757
|
return { kind: "grant", payload: { ...grant, savedAt: (/* @__PURE__ */ new Date()).toISOString() } };
|
|
@@ -4695,6 +4797,51 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
|
|
|
4695
4797
|
const [apiRecord, sessionRecord] = await Promise.all([credentials?.readRecord(API_KEY), credentials?.readRecord(SESSION)]);
|
|
4696
4798
|
return (await this._key(ref, baseURL, apiRecord, sessionRecord))?.key;
|
|
4697
4799
|
}
|
|
4800
|
+
/** Restore the persisted gateway catalog when it belongs to the active gateway. */
|
|
4801
|
+
_restoreModels() {
|
|
4802
|
+
const config = this._config();
|
|
4803
|
+
const snapshot = config.modelCatalog;
|
|
4804
|
+
if (!snapshot || snapshot.baseURL !== config.baseURL) return;
|
|
4805
|
+
this._models = snapshot.models;
|
|
4806
|
+
this._modelsUpdatedAt = snapshot.updatedAt;
|
|
4807
|
+
}
|
|
4808
|
+
/**
|
|
4809
|
+
* Persist the snapshot through the Host form service.
|
|
4810
|
+
* `unsupported` means no settings service is composed (nothing to report);
|
|
4811
|
+
* `unavailable` means the service exists but exposes no writable form for this plugin.
|
|
4812
|
+
*/
|
|
4813
|
+
async _persistModels(value) {
|
|
4814
|
+
const settings = this.ctx.get("settings");
|
|
4815
|
+
if (!settings) return "unsupported";
|
|
4816
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
4817
|
+
let descriptor;
|
|
4818
|
+
try {
|
|
4819
|
+
descriptor = settings.describe().find((item) => item.ns === SETTINGS_NS);
|
|
4820
|
+
} catch {
|
|
4821
|
+
return "unavailable";
|
|
4822
|
+
}
|
|
4823
|
+
if (!descriptor) return "unavailable";
|
|
4824
|
+
try {
|
|
4825
|
+
await settings.update(SETTINGS_NS, { modelCatalog: value }, descriptor.revision);
|
|
4826
|
+
return "saved";
|
|
4827
|
+
} catch {
|
|
4828
|
+
}
|
|
4829
|
+
}
|
|
4830
|
+
return "failed";
|
|
4831
|
+
}
|
|
4832
|
+
/** Serialize snapshot writes so the newest successful refresh is the last one persisted. */
|
|
4833
|
+
_queueModelsWrite(snapshot, epoch) {
|
|
4834
|
+
const serial = ++this._modelsWriteSerial;
|
|
4835
|
+
this._modelsWrite = this._modelsWrite.then(async () => {
|
|
4836
|
+
const result = await this._persistModels(snapshot);
|
|
4837
|
+
if (serial !== this._modelsWriteSerial || epoch !== this._modelsEpoch) return;
|
|
4838
|
+
if (result === "unavailable") this._modelsError = "\u6A21\u578B\u76EE\u5F55\u5DF2\u66F4\u65B0\uFF0C\u4F46\u5F53\u524D\u914D\u7F6E\u670D\u52A1\u4E0D\u53EF\u5199\uFF1B\u91CD\u542F\u540E\u9700\u8981\u91CD\u65B0\u5237\u65B0\u3002";
|
|
4839
|
+
else if (result === "failed") this._modelsError = "\u6A21\u578B\u76EE\u5F55\u5DF2\u66F4\u65B0\uFF0C\u4F46\u4FDD\u5B58\u5931\u8D25\uFF1B\u91CD\u542F\u540E\u9700\u8981\u91CD\u65B0\u5237\u65B0\u3002";
|
|
4840
|
+
}).catch(() => {
|
|
4841
|
+
if (serial !== this._modelsWriteSerial || epoch !== this._modelsEpoch) return;
|
|
4842
|
+
this._modelsError = "\u6A21\u578B\u76EE\u5F55\u5DF2\u66F4\u65B0\uFF0C\u4F46\u4FDD\u5B58\u5931\u8D25\uFF1B\u91CD\u542F\u540E\u9700\u8981\u91CD\u65B0\u5237\u65B0\u3002";
|
|
4843
|
+
});
|
|
4844
|
+
}
|
|
4698
4845
|
_invalidateModels() {
|
|
4699
4846
|
const changed = this._modelsUpdatedAt !== void 0;
|
|
4700
4847
|
this._modelsEpoch++;
|
|
@@ -4703,7 +4850,8 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
|
|
|
4703
4850
|
this._models = MODELS;
|
|
4704
4851
|
this._modelsUpdatedAt = void 0;
|
|
4705
4852
|
this._modelsError = void 0;
|
|
4706
|
-
|
|
4853
|
+
this._restoreModels();
|
|
4854
|
+
if (changed || this._modelsUpdatedAt !== void 0) {
|
|
4707
4855
|
try {
|
|
4708
4856
|
this.dependencies.modelsChanged?.();
|
|
4709
4857
|
} catch {
|
|
@@ -4721,7 +4869,7 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
|
|
|
4721
4869
|
this._modelsFingerprint = modelsFingerprint;
|
|
4722
4870
|
this._invalidateModels();
|
|
4723
4871
|
}
|
|
4724
|
-
const fingerprint = hash(state);
|
|
4872
|
+
const fingerprint = hash({ ...state, config: stableConfig(state.config) });
|
|
4725
4873
|
if (fingerprint !== this._fingerprint) {
|
|
4726
4874
|
this._fingerprint = fingerprint;
|
|
4727
4875
|
this._revision = randomUUID3();
|
|
@@ -4797,16 +4945,20 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
|
|
|
4797
4945
|
if (signal.aborted || epoch !== this._modelsEpoch) return this.status();
|
|
4798
4946
|
const previousModels = this._models;
|
|
4799
4947
|
const previousUpdatedAt = this._modelsUpdatedAt;
|
|
4948
|
+
const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
4800
4949
|
this._models = models;
|
|
4801
|
-
this._modelsUpdatedAt =
|
|
4950
|
+
this._modelsUpdatedAt = updatedAt;
|
|
4802
4951
|
this._modelsError = void 0;
|
|
4952
|
+
let accepted = true;
|
|
4803
4953
|
try {
|
|
4804
4954
|
this.dependencies.modelsChanged?.();
|
|
4805
4955
|
} catch {
|
|
4956
|
+
accepted = false;
|
|
4806
4957
|
this._models = previousModels;
|
|
4807
4958
|
this._modelsUpdatedAt = previousUpdatedAt;
|
|
4808
4959
|
this._modelsError = "\u6A21\u578B\u76EE\u5F55\u5DF2\u8BFB\u53D6\uFF0C\u4F46\u6A21\u578B\u9009\u62E9\u5668\u66F4\u65B0\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002";
|
|
4809
4960
|
}
|
|
4961
|
+
if (accepted) this._queueModelsWrite({ baseURL: state.config.baseURL, updatedAt, models }, epoch);
|
|
4810
4962
|
} catch (error) {
|
|
4811
4963
|
if (!signal.aborted && epoch === this._modelsEpoch) this._modelsError = error instanceof ModelDiscoveryError ? error.message : "\u6A21\u578B\u5217\u8868\u66F4\u65B0\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002";
|
|
4812
4964
|
}
|
|
@@ -4974,7 +5126,7 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
|
|
|
4974
5126
|
this._expect(request.expectedRevision);
|
|
4975
5127
|
const expected = hash(state.apiRecord);
|
|
4976
5128
|
await this._credentials().modifyRecord(API_KEY, async (current) => {
|
|
4977
|
-
if (hash(current) !== expected || hash(this._config()) !== hash(state.config)) throw this._conflict();
|
|
5129
|
+
if (hash(current) !== expected || hash(stableConfig(this._config())) !== hash(stableConfig(state.config))) throw this._conflict();
|
|
4978
5130
|
return { kind: "api-key", key: request.value };
|
|
4979
5131
|
});
|
|
4980
5132
|
return this.status();
|