dsh-opendesign-corouter 0.1.9 → 0.1.10
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 +1 -1
- package/lib/client.d.ts +22 -4
- package/lib/client.js +250 -48
- package/lib/device-auth.d.ts +1 -1
- package/lib/generated/typert.host.js +36 -0
- package/lib/generated/typert.remote-client.d.ts +2 -1
- package/lib/generated/typert.remote-client.js +36 -0
- package/lib/index.d.ts +7 -1
- package/lib/index.js +367 -5
- package/lib/index.js.map +4 -4
- package/lib/pricing.d.ts +149 -0
- package/lib/remote.d.ts +21 -0
- package/package.json +1 -1
|
@@ -136,6 +136,40 @@ function member(value, allowed, label) {
|
|
|
136
136
|
if (hit === void 0) throw new Error(`${label} \u4E0D\u5728\u5141\u8BB8\u7684\u53D6\u503C\u5185`);
|
|
137
137
|
return hit;
|
|
138
138
|
}
|
|
139
|
+
function parsePriceCatalog(value) {
|
|
140
|
+
if (!record(value) || !Array.isArray(value.models) || value.models.length > MAX_MODELS) throw new Error("\u4EF7\u683C\u76EE\u5F55\u683C\u5F0F\u65E0\u6548");
|
|
141
|
+
const state = member(value.state, ["ok", "partial", "error"], "\u4EF7\u683C\u76EE\u5F55\u72B6\u6001");
|
|
142
|
+
const stale = flag(value.stale, "\u4EF7\u683C\u7F13\u5B58\u72B6\u6001");
|
|
143
|
+
const fetchedAt = value.fetchedAt === void 0 ? void 0 : isoTime(value.fetchedAt, "\u4EF7\u683C\u66F4\u65B0\u65F6\u95F4");
|
|
144
|
+
if (stale && fetchedAt === void 0) throw new Error("\u8FC7\u671F\u4EF7\u683C\u5FC5\u987B\u6807\u6CE8\u66F4\u65B0\u65F6\u95F4");
|
|
145
|
+
const ids = /* @__PURE__ */ new Set();
|
|
146
|
+
const nullableAmount = (item) => {
|
|
147
|
+
if (item === null) return null;
|
|
148
|
+
const result = amount(item, "\u4EF7\u683C");
|
|
149
|
+
if (result > 1e6) throw new Error("\u4EF7\u683C\u8D85\u51FA\u8303\u56F4");
|
|
150
|
+
return result;
|
|
151
|
+
};
|
|
152
|
+
const models = value.models.map((model) => {
|
|
153
|
+
if (!record(model) || !Array.isArray(model.tiers) || model.tiers.length === 0 || model.tiers.length > 8) throw new Error("\u6A21\u578B\u4EF7\u683C\u683C\u5F0F\u65E0\u6548");
|
|
154
|
+
const id = text(model.id, "\u6A21\u578B id", 128);
|
|
155
|
+
if (!MODEL_ID.test(id) || ids.has(id)) throw new Error("\u6A21\u578B\u4EF7\u683C id \u65E0\u6548\u6216\u91CD\u590D");
|
|
156
|
+
ids.add(id);
|
|
157
|
+
const tiers = model.tiers.map((tier) => {
|
|
158
|
+
if (!record(tier)) throw new Error("\u4EF7\u683C\u6863\u4F4D\u683C\u5F0F\u65E0\u6548");
|
|
159
|
+
return {
|
|
160
|
+
label: text(tier.label, "\u4EF7\u683C\u6863\u4F4D", 128),
|
|
161
|
+
currency: tier.currency === null ? null : member(tier.currency, ["USD"], "\u4EF7\u683C\u5E01\u79CD"),
|
|
162
|
+
unit: tier.unit === null ? null : member(tier.unit, ["per_1m_tokens", "per_1k_tokens"], "\u4EF7\u683C\u5355\u4F4D"),
|
|
163
|
+
input: nullableAmount(tier.input),
|
|
164
|
+
output: nullableAmount(tier.output),
|
|
165
|
+
cacheRead: nullableAmount(tier.cacheRead),
|
|
166
|
+
cacheWrite: nullableAmount(tier.cacheWrite)
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
return { id, tiers };
|
|
170
|
+
});
|
|
171
|
+
return { state, stale, ...fetchedAt === void 0 ? {} : { fetchedAt }, models };
|
|
172
|
+
}
|
|
139
173
|
function parseQuotaWindow(value) {
|
|
140
174
|
if (!record(value)) throw new Error("\u989D\u5EA6\u7A97\u53E3\u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
141
175
|
const durationSeconds = amount(value.durationSeconds, "\u989D\u5EA6\u7A97\u53E3\u65F6\u957F");
|
|
@@ -283,6 +317,7 @@ function parseActivationOpenState(value) {
|
|
|
283
317
|
|
|
284
318
|
// src/generated/typert.remote-client.ts
|
|
285
319
|
var StatusCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#Status", create: () => z.unknown().transform((value) => parseStatus(value)) };
|
|
320
|
+
var PriceCatalogCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#PriceCatalog", create: () => z.unknown().transform((value) => parsePriceCatalog(value)) };
|
|
286
321
|
var QuotaSnapshotCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#QuotaSnapshot", create: () => z.unknown().transform((value) => parseQuotaSnapshot(value)) };
|
|
287
322
|
var LoginStateCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#LoginState", create: () => z.unknown().transform((value) => parseLoginState(value)) };
|
|
288
323
|
var StartLoginRequestCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#StartLoginRequest", create: () => z.unknown().transform((value) => parseStartLoginRequest(value)) };
|
|
@@ -292,6 +327,7 @@ var SaveApiKeyRequestCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corou
|
|
|
292
327
|
var TYPERT_REMOTE = createTypertRemoteInfo({ package: "dsh-opendesign-corouter", methods: {
|
|
293
328
|
"openDesignCoRouter/status": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: StatusCodec },
|
|
294
329
|
"openDesignCoRouter/refreshModels": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: StatusCodec },
|
|
330
|
+
"openDesignCoRouter/refreshPrices": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: PriceCatalogCodec },
|
|
295
331
|
"openDesignCoRouter/refreshQuota": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: QuotaSnapshotCodec },
|
|
296
332
|
"openDesignCoRouter/refreshQuotaNow": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: QuotaSnapshotCodec },
|
|
297
333
|
"openDesignCoRouter/startLogin": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [{ name: "input", source: "json", codec: StartLoginRequestCodec, strictCodec: StartLoginRequestCodec }], result: LoginStateCodec },
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { RemoteResult } from '@deepseek-ai/dsh-typert-protocol';
|
|
2
|
-
import type { Status, QuotaSnapshot, LoginState, StartLoginRequest, CancelLoginRequest, ActivationOpenState, SaveApiKeyRequest } from '../remote.js';
|
|
2
|
+
import type { Status, PriceCatalog, QuotaSnapshot, LoginState, StartLoginRequest, CancelLoginRequest, ActivationOpenState, SaveApiKeyRequest } from '../remote.js';
|
|
3
3
|
export type CoRouterRemote = {
|
|
4
4
|
status: () => Promise<RemoteResult<Status>>;
|
|
5
5
|
refreshModels: () => Promise<RemoteResult<Status>>;
|
|
6
|
+
refreshPrices: () => Promise<RemoteResult<PriceCatalog>>;
|
|
6
7
|
refreshQuota: () => Promise<RemoteResult<QuotaSnapshot>>;
|
|
7
8
|
refreshQuotaNow: () => Promise<RemoteResult<QuotaSnapshot>>;
|
|
8
9
|
startLogin: (input: StartLoginRequest) => Promise<RemoteResult<LoginState>>;
|
|
@@ -136,6 +136,40 @@ function member(value, allowed, label) {
|
|
|
136
136
|
if (hit === void 0) throw new Error(`${label} \u4E0D\u5728\u5141\u8BB8\u7684\u53D6\u503C\u5185`);
|
|
137
137
|
return hit;
|
|
138
138
|
}
|
|
139
|
+
function parsePriceCatalog(value) {
|
|
140
|
+
if (!record(value) || !Array.isArray(value.models) || value.models.length > MAX_MODELS) throw new Error("\u4EF7\u683C\u76EE\u5F55\u683C\u5F0F\u65E0\u6548");
|
|
141
|
+
const state = member(value.state, ["ok", "partial", "error"], "\u4EF7\u683C\u76EE\u5F55\u72B6\u6001");
|
|
142
|
+
const stale = flag(value.stale, "\u4EF7\u683C\u7F13\u5B58\u72B6\u6001");
|
|
143
|
+
const fetchedAt = value.fetchedAt === void 0 ? void 0 : isoTime(value.fetchedAt, "\u4EF7\u683C\u66F4\u65B0\u65F6\u95F4");
|
|
144
|
+
if (stale && fetchedAt === void 0) throw new Error("\u8FC7\u671F\u4EF7\u683C\u5FC5\u987B\u6807\u6CE8\u66F4\u65B0\u65F6\u95F4");
|
|
145
|
+
const ids = /* @__PURE__ */ new Set();
|
|
146
|
+
const nullableAmount = (item) => {
|
|
147
|
+
if (item === null) return null;
|
|
148
|
+
const result = amount(item, "\u4EF7\u683C");
|
|
149
|
+
if (result > 1e6) throw new Error("\u4EF7\u683C\u8D85\u51FA\u8303\u56F4");
|
|
150
|
+
return result;
|
|
151
|
+
};
|
|
152
|
+
const models = value.models.map((model) => {
|
|
153
|
+
if (!record(model) || !Array.isArray(model.tiers) || model.tiers.length === 0 || model.tiers.length > 8) throw new Error("\u6A21\u578B\u4EF7\u683C\u683C\u5F0F\u65E0\u6548");
|
|
154
|
+
const id = text(model.id, "\u6A21\u578B id", 128);
|
|
155
|
+
if (!MODEL_ID.test(id) || ids.has(id)) throw new Error("\u6A21\u578B\u4EF7\u683C id \u65E0\u6548\u6216\u91CD\u590D");
|
|
156
|
+
ids.add(id);
|
|
157
|
+
const tiers = model.tiers.map((tier) => {
|
|
158
|
+
if (!record(tier)) throw new Error("\u4EF7\u683C\u6863\u4F4D\u683C\u5F0F\u65E0\u6548");
|
|
159
|
+
return {
|
|
160
|
+
label: text(tier.label, "\u4EF7\u683C\u6863\u4F4D", 128),
|
|
161
|
+
currency: tier.currency === null ? null : member(tier.currency, ["USD"], "\u4EF7\u683C\u5E01\u79CD"),
|
|
162
|
+
unit: tier.unit === null ? null : member(tier.unit, ["per_1m_tokens", "per_1k_tokens"], "\u4EF7\u683C\u5355\u4F4D"),
|
|
163
|
+
input: nullableAmount(tier.input),
|
|
164
|
+
output: nullableAmount(tier.output),
|
|
165
|
+
cacheRead: nullableAmount(tier.cacheRead),
|
|
166
|
+
cacheWrite: nullableAmount(tier.cacheWrite)
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
return { id, tiers };
|
|
170
|
+
});
|
|
171
|
+
return { state, stale, ...fetchedAt === void 0 ? {} : { fetchedAt }, models };
|
|
172
|
+
}
|
|
139
173
|
function parseQuotaWindow(value) {
|
|
140
174
|
if (!record(value)) throw new Error("\u989D\u5EA6\u7A97\u53E3\u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
141
175
|
const durationSeconds = amount(value.durationSeconds, "\u989D\u5EA6\u7A97\u53E3\u65F6\u957F");
|
|
@@ -283,6 +317,7 @@ function parseActivationOpenState(value) {
|
|
|
283
317
|
|
|
284
318
|
// src/generated/typert.remote-client.ts
|
|
285
319
|
var StatusCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#Status", create: () => z.unknown().transform((value) => parseStatus(value)) };
|
|
320
|
+
var PriceCatalogCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#PriceCatalog", create: () => z.unknown().transform((value) => parsePriceCatalog(value)) };
|
|
286
321
|
var QuotaSnapshotCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#QuotaSnapshot", create: () => z.unknown().transform((value) => parseQuotaSnapshot(value)) };
|
|
287
322
|
var LoginStateCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#LoginState", create: () => z.unknown().transform((value) => parseLoginState(value)) };
|
|
288
323
|
var StartLoginRequestCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#StartLoginRequest", create: () => z.unknown().transform((value) => parseStartLoginRequest(value)) };
|
|
@@ -292,6 +327,7 @@ var SaveApiKeyRequestCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corou
|
|
|
292
327
|
var TYPERT_REMOTE = createTypertRemoteInfo({ package: "dsh-opendesign-corouter", methods: {
|
|
293
328
|
"openDesignCoRouter/status": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: StatusCodec },
|
|
294
329
|
"openDesignCoRouter/refreshModels": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: StatusCodec },
|
|
330
|
+
"openDesignCoRouter/refreshPrices": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: PriceCatalogCodec },
|
|
295
331
|
"openDesignCoRouter/refreshQuota": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: QuotaSnapshotCodec },
|
|
296
332
|
"openDesignCoRouter/refreshQuotaNow": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: QuotaSnapshotCodec },
|
|
297
333
|
"openDesignCoRouter/startLogin": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [{ name: "input", source: "json", codec: StartLoginRequestCodec, strictCodec: StartLoginRequestCodec }], result: LoginStateCodec },
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Context } from '@deepseek-ai/cordis';
|
|
2
2
|
import { TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
|
|
3
3
|
import { fetchModelCatalog } from './model-discovery.js';
|
|
4
|
+
import { fetchPricingSnapshot } from './pricing.js';
|
|
4
5
|
import type { CatalogModel } from './catalog.js';
|
|
5
6
|
import { readConfig, type LiveConfig } from './config.js';
|
|
6
7
|
import { resolveSession } from './auth.js';
|
|
@@ -8,7 +9,7 @@ import { type LoginOptions } from './login.js';
|
|
|
8
9
|
import { type ActivationLauncherOptions } from './browser-open.js';
|
|
9
10
|
import { readQuota, type QuotaSnapshot } from './quota.js';
|
|
10
11
|
import { readDesktopQuota } from './desktop-quota.js';
|
|
11
|
-
import { type Status, type LoginState, type StartLoginRequest, type CancelLoginRequest, type SaveApiKeyRequest, type ActivationOpenState } from './remote.js';
|
|
12
|
+
import { type Status, type PriceCatalog, type LoginState, type StartLoginRequest, type CancelLoginRequest, type SaveApiKeyRequest, type ActivationOpenState } from './remote.js';
|
|
12
13
|
export { Config } from './config.js';
|
|
13
14
|
export { CoRouterAdapter } from './adapter.js';
|
|
14
15
|
export { MODELS } from './catalog.js';
|
|
@@ -19,6 +20,7 @@ export interface HostDependencies {
|
|
|
19
20
|
readQuota: typeof readQuota;
|
|
20
21
|
readDesktopQuota: typeof readDesktopQuota;
|
|
21
22
|
fetchModels?: typeof fetchModelCatalog;
|
|
23
|
+
fetchPrices?: typeof fetchPricingSnapshot;
|
|
22
24
|
modelsChanged?: () => void;
|
|
23
25
|
loginOptions?: LoginOptions;
|
|
24
26
|
activationOptions?: ActivationLauncherOptions;
|
|
@@ -46,6 +48,8 @@ export declare class OpenDesignCoRouterService extends TypertRemoteService {
|
|
|
46
48
|
private _modelsEpoch;
|
|
47
49
|
private _modelsPending;
|
|
48
50
|
private _modelsController;
|
|
51
|
+
private _prices;
|
|
52
|
+
private _pricesPending;
|
|
49
53
|
modelCatalog(): readonly CatalogModel[];
|
|
50
54
|
constructor(ctx: Context, config: () => ReturnType<typeof readConfig>, dependencies?: HostDependencies);
|
|
51
55
|
private _credentials;
|
|
@@ -58,6 +62,8 @@ export declare class OpenDesignCoRouterService extends TypertRemoteService {
|
|
|
58
62
|
private _invalidateQuota;
|
|
59
63
|
status(): Promise<Status>;
|
|
60
64
|
refreshModels(): Promise<Status>;
|
|
65
|
+
/** Public website prices do not use gateway credentials or alter the model catalog. */
|
|
66
|
+
refreshPrices(): Promise<PriceCatalog>;
|
|
61
67
|
refreshQuota(): Promise<QuotaSnapshot>;
|
|
62
68
|
refreshQuotaNow(): Promise<QuotaSnapshot>;
|
|
63
69
|
private _refreshQuota;
|
package/lib/index.js
CHANGED
|
@@ -2030,6 +2030,306 @@ async function fetchModelCatalog(openAiBaseURL2, key, signal, fetcher) {
|
|
|
2030
2030
|
return normalize(await boundedJson(response, signal, deadline));
|
|
2031
2031
|
}
|
|
2032
2032
|
|
|
2033
|
+
// src/pricing.ts
|
|
2034
|
+
var PRICING_ORIGIN = "https://corouter.open-design.ai";
|
|
2035
|
+
var PRICING_CATALOG_PATH = "/zh/models/";
|
|
2036
|
+
var PRICING_TIMEOUT_MS = 15e3;
|
|
2037
|
+
var MAX_PRICING_BODY_BYTES = 4 * 1024 * 1024;
|
|
2038
|
+
var MESSAGES3 = {
|
|
2039
|
+
timeout: "\u5B98\u7F51\u4EF7\u683C\u8BF7\u6C42\u8D85\u8FC7\u65F6\u9650",
|
|
2040
|
+
aborted: "\u5B98\u7F51\u4EF7\u683C\u8BF7\u6C42\u5DF2\u53D6\u6D88",
|
|
2041
|
+
network: "\u65E0\u6CD5\u8FDE\u63A5\u5B98\u7F51",
|
|
2042
|
+
status: "\u5B98\u7F51\u8FD4\u56DE\u4E86\u975E 200 \u72B6\u6001",
|
|
2043
|
+
"too-large": "\u5B98\u7F51\u4EF7\u683C\u54CD\u5E94\u4F53\u8D85\u8FC7\u4E0A\u9650",
|
|
2044
|
+
"invalid-page": "\u62FF\u5230\u7684\u9875\u9762\u4E0D\u662F\u5B98\u7F51\u6A21\u578B\u4EF7\u683C\u9875",
|
|
2045
|
+
"invalid-model": "\u62FF\u5230\u7684\u9875\u9762\u4E0D\u662F\u5B98\u7F51\u6A21\u578B\u4EF7\u683C\u8BE6\u60C5\u9875"
|
|
2046
|
+
};
|
|
2047
|
+
var PricingError = class extends Error {
|
|
2048
|
+
constructor(kind, status) {
|
|
2049
|
+
super(MESSAGES3[kind]);
|
|
2050
|
+
this.kind = kind;
|
|
2051
|
+
this.status = status;
|
|
2052
|
+
this.name = "PricingError";
|
|
2053
|
+
}
|
|
2054
|
+
kind;
|
|
2055
|
+
status;
|
|
2056
|
+
};
|
|
2057
|
+
var ENTITIES = {
|
|
2058
|
+
""": '"',
|
|
2059
|
+
"&": "&",
|
|
2060
|
+
"<": "<",
|
|
2061
|
+
">": ">",
|
|
2062
|
+
"'": "'",
|
|
2063
|
+
" ": " ",
|
|
2064
|
+
"—": "\u2014",
|
|
2065
|
+
"–": "\u2013"
|
|
2066
|
+
};
|
|
2067
|
+
function decodeEntities(text2) {
|
|
2068
|
+
return text2.replace(/&(?:quot|amp|lt|gt|apos|nbsp|mdash|ndash);/gu, (match) => ENTITIES[match] ?? match).replace(/&#(\d+);/gu, (_match, code) => {
|
|
2069
|
+
const point = Number(code);
|
|
2070
|
+
return Number.isInteger(point) && point > 0 && point <= 1114111 ? String.fromCodePoint(point) : "";
|
|
2071
|
+
});
|
|
2072
|
+
}
|
|
2073
|
+
function stripTags(text2) {
|
|
2074
|
+
return decodeEntities(text2.replace(/<[^>]*>/gu, " ")).replace(/\s+/gu, " ").trim();
|
|
2075
|
+
}
|
|
2076
|
+
function metricOf(label) {
|
|
2077
|
+
if (/缓存读取|cache\s+read/iu.test(label)) return "cacheRead";
|
|
2078
|
+
if (/缓存写入|cache\s+write/iu.test(label)) return "cacheWrite";
|
|
2079
|
+
if (/^\s*(?:输入|input)/iu.test(label)) return "input";
|
|
2080
|
+
if (/^\s*(?:输出|output)/iu.test(label)) return "output";
|
|
2081
|
+
return void 0;
|
|
2082
|
+
}
|
|
2083
|
+
function unitOf(label) {
|
|
2084
|
+
if (/百万\s*token|1m\s*tokens?/iu.test(label)) return "per_1m_tokens";
|
|
2085
|
+
if (/千\s*token|1k\s*tokens?/iu.test(label)) return "per_1k_tokens";
|
|
2086
|
+
return null;
|
|
2087
|
+
}
|
|
2088
|
+
function currencyOf(value) {
|
|
2089
|
+
if (value.includes("$")) return "USD";
|
|
2090
|
+
return null;
|
|
2091
|
+
}
|
|
2092
|
+
function priceOf(value) {
|
|
2093
|
+
const text2 = value.replace(/[$\u20ac\u00a3\u00a5\u00a4,\s]/gu, "");
|
|
2094
|
+
if (text2 === "" || /^[–—−\-]+$/u.test(text2)) return null;
|
|
2095
|
+
const parsed = Number(text2);
|
|
2096
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
2097
|
+
}
|
|
2098
|
+
var MODEL_ID2 = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u;
|
|
2099
|
+
var SLUG = /^[a-z0-9][a-z0-9-]{0,127}$/u;
|
|
2100
|
+
function slugOf(href) {
|
|
2101
|
+
const match = /\/models\/([A-Za-z0-9._-]+)\/?(?:#.*)?$/u.exec(href);
|
|
2102
|
+
if (!match) return null;
|
|
2103
|
+
const slug = match[1];
|
|
2104
|
+
return SLUG.test(slug) ? slug : null;
|
|
2105
|
+
}
|
|
2106
|
+
function trimPanelBody(body) {
|
|
2107
|
+
const anchor = /<a\b[^>]*class="[^"]*\bmodel-explorer-detail-link\b[^"]*"[^>]*>/u.exec(body);
|
|
2108
|
+
if (!anchor) return body;
|
|
2109
|
+
const close = body.indexOf("</a>", anchor.index + anchor[0].length);
|
|
2110
|
+
if (close < 0) return body.slice(0, anchor.index);
|
|
2111
|
+
return body.slice(0, close + 4);
|
|
2112
|
+
}
|
|
2113
|
+
function collectPanels(html) {
|
|
2114
|
+
const openTag = /<div\b[^>]*class="[^"]*\bmodel-explorer-panel\b[^"]*"[^>]*>/gu;
|
|
2115
|
+
const opens = [];
|
|
2116
|
+
for (const match of html.matchAll(openTag)) {
|
|
2117
|
+
const id = /data-model-panel="([^"]*)"/u.exec(match[0])?.[1];
|
|
2118
|
+
if (!id || !MODEL_ID2.test(id)) continue;
|
|
2119
|
+
opens.push({ id, start: match.index, end: match.index + match[0].length });
|
|
2120
|
+
}
|
|
2121
|
+
const panels = [];
|
|
2122
|
+
for (let index = 0; index < opens.length; index += 1) {
|
|
2123
|
+
const open = opens[index];
|
|
2124
|
+
const next = opens[index + 1];
|
|
2125
|
+
const body = html.slice(open.end, next ? next.start : html.length);
|
|
2126
|
+
panels.push({ id: open.id, body: trimPanelBody(body) });
|
|
2127
|
+
}
|
|
2128
|
+
return panels;
|
|
2129
|
+
}
|
|
2130
|
+
function collectProviders(html) {
|
|
2131
|
+
const providers = /* @__PURE__ */ new Map();
|
|
2132
|
+
for (const match of html.matchAll(/<button\b[^>]*>/gu)) {
|
|
2133
|
+
const tag = match[0];
|
|
2134
|
+
const id = /data-model-tab="([^"]*)"/u.exec(tag)?.[1];
|
|
2135
|
+
const provider = /data-provider="([^"]*)"/u.exec(tag)?.[1];
|
|
2136
|
+
if (!id || !provider) continue;
|
|
2137
|
+
providers.set(id, provider.trim());
|
|
2138
|
+
}
|
|
2139
|
+
return providers;
|
|
2140
|
+
}
|
|
2141
|
+
function collectTiers(body) {
|
|
2142
|
+
const marker = /<div\b[^>]*class="[^"]*\bmodel-explorer-tier\b[^"]*"[^>]*>/gu;
|
|
2143
|
+
const starts = [];
|
|
2144
|
+
for (const match of body.matchAll(marker)) starts.push(match.index);
|
|
2145
|
+
const tiers = [];
|
|
2146
|
+
for (let index = 0; index < starts.length; index += 1) {
|
|
2147
|
+
const start = starts[index];
|
|
2148
|
+
const end = index + 1 < starts.length ? starts[index + 1] : body.length;
|
|
2149
|
+
const chunk = body.slice(start, end);
|
|
2150
|
+
const label = stripTags(/<h4[^>]*>([\s\S]*?)<\/h4>/u.exec(chunk)?.[1] ?? "");
|
|
2151
|
+
const metrics = /* @__PURE__ */ new Map();
|
|
2152
|
+
for (const metric of chunk.matchAll(/<dt[^>]*>([\s\S]*?)<\/dt>\s*<dd([^>]*)>([\s\S]*?)<\/dd>/gu)) {
|
|
2153
|
+
const labelText = stripTags(metric[1] ?? "");
|
|
2154
|
+
const key = metricOf(labelText);
|
|
2155
|
+
if (!key) continue;
|
|
2156
|
+
const value = stripTags(metric[3] ?? "");
|
|
2157
|
+
metrics.set(key, { price: priceOf(value), currency: currencyOf(value), unit: unitOf(labelText) });
|
|
2158
|
+
}
|
|
2159
|
+
tiers.push({ label, metrics });
|
|
2160
|
+
}
|
|
2161
|
+
return tiers;
|
|
2162
|
+
}
|
|
2163
|
+
function hasCatalogMarker(html) {
|
|
2164
|
+
return /data-page-name="corouter_models"/u.test(html);
|
|
2165
|
+
}
|
|
2166
|
+
function commonCurrency(values) {
|
|
2167
|
+
const seen = new Set(values.filter((value) => value !== null));
|
|
2168
|
+
if (seen.size !== 1) return null;
|
|
2169
|
+
return seen.values().next().value ?? null;
|
|
2170
|
+
}
|
|
2171
|
+
function commonUnit(values) {
|
|
2172
|
+
const seen = new Set(values.filter((value) => value !== null));
|
|
2173
|
+
if (seen.size !== 1) return null;
|
|
2174
|
+
return seen.values().next().value ?? null;
|
|
2175
|
+
}
|
|
2176
|
+
function parsePricingCatalog(html) {
|
|
2177
|
+
if (!hasCatalogMarker(html)) throw new PricingError("invalid-page");
|
|
2178
|
+
const panels = collectPanels(html);
|
|
2179
|
+
if (panels.length === 0) throw new PricingError("invalid-page");
|
|
2180
|
+
const providers = collectProviders(html);
|
|
2181
|
+
const models = [];
|
|
2182
|
+
for (const panel of panels) {
|
|
2183
|
+
const name2 = stripTags(/<h3[^>]*>([\s\S]*?)<\/h3>/u.exec(panel.body)?.[1] ?? "");
|
|
2184
|
+
const href = /<a\b[^>]*class="[^"]*\bmodel-explorer-detail-link\b[^"]*"[^>]*href="([^"]*)"/u.exec(panel.body)?.[1] ?? "";
|
|
2185
|
+
const slug = slugOf(href);
|
|
2186
|
+
const tiers = collectTiers(panel.body).map((draft, index) => {
|
|
2187
|
+
const input = draft.metrics.get("input");
|
|
2188
|
+
const output = draft.metrics.get("output");
|
|
2189
|
+
const cacheRead = draft.metrics.get("cacheRead");
|
|
2190
|
+
const cacheWrite = draft.metrics.get("cacheWrite");
|
|
2191
|
+
const priced = [input, output, cacheRead, cacheWrite].filter((value) => value !== void 0 && value.price !== null);
|
|
2192
|
+
if (!draft.label || new Set(priced.map((value) => value.currency)).size > 1 || new Set(priced.map((value) => value.unit)).size > 1) throw new PricingError("invalid-page");
|
|
2193
|
+
return {
|
|
2194
|
+
index,
|
|
2195
|
+
label: draft.label,
|
|
2196
|
+
input: input?.price ?? null,
|
|
2197
|
+
output: output?.price ?? null,
|
|
2198
|
+
cacheRead: cacheRead?.price ?? null,
|
|
2199
|
+
cacheWrite: cacheWrite?.price ?? null,
|
|
2200
|
+
currency: input?.currency ?? output?.currency ?? cacheRead?.currency ?? cacheWrite?.currency ?? null,
|
|
2201
|
+
unit: input?.unit ?? output?.unit ?? cacheRead?.unit ?? cacheWrite?.unit ?? null
|
|
2202
|
+
};
|
|
2203
|
+
});
|
|
2204
|
+
models.push({
|
|
2205
|
+
id: panel.id,
|
|
2206
|
+
name: name2 === "" ? panel.id : name2,
|
|
2207
|
+
provider: providers.get(panel.id) ?? null,
|
|
2208
|
+
slug,
|
|
2209
|
+
detailUrl: slug ? `${PRICING_ORIGIN}${PRICING_CATALOG_PATH}${slug}/` : null,
|
|
2210
|
+
tiers
|
|
2211
|
+
});
|
|
2212
|
+
}
|
|
2213
|
+
return {
|
|
2214
|
+
models,
|
|
2215
|
+
currency: commonCurrency(models.flatMap((model) => model.tiers.map((tier) => tier.currency))),
|
|
2216
|
+
unit: commonUnit(models.flatMap((model) => model.tiers.map((tier) => tier.unit)))
|
|
2217
|
+
};
|
|
2218
|
+
}
|
|
2219
|
+
function classify2(error, signal, combined) {
|
|
2220
|
+
if (error instanceof PricingError) return error;
|
|
2221
|
+
const name2 = error?.name;
|
|
2222
|
+
if (signal?.aborted) return new PricingError("aborted");
|
|
2223
|
+
if (name2 === "TimeoutError" || combined.aborted) return new PricingError("timeout");
|
|
2224
|
+
return new PricingError("network");
|
|
2225
|
+
}
|
|
2226
|
+
async function readBounded(response, maxBytes, signal, combined) {
|
|
2227
|
+
const reader = response.body?.getReader();
|
|
2228
|
+
if (!reader) throw new PricingError("invalid-page");
|
|
2229
|
+
const declared = Number(response.headers.get("content-length"));
|
|
2230
|
+
if (Number.isFinite(declared) && declared > maxBytes) {
|
|
2231
|
+
void reader.cancel().catch(() => void 0);
|
|
2232
|
+
reader.releaseLock();
|
|
2233
|
+
throw new PricingError("too-large");
|
|
2234
|
+
}
|
|
2235
|
+
let size = 0;
|
|
2236
|
+
let raw = "";
|
|
2237
|
+
const decoder = new TextDecoder();
|
|
2238
|
+
const cancel = () => {
|
|
2239
|
+
void reader.cancel().catch(() => void 0);
|
|
2240
|
+
};
|
|
2241
|
+
combined.addEventListener("abort", cancel, { once: true });
|
|
2242
|
+
try {
|
|
2243
|
+
if (combined.aborted) throw classify2(combined.reason, signal, combined);
|
|
2244
|
+
while (true) {
|
|
2245
|
+
const chunk = await reader.read();
|
|
2246
|
+
if (combined.aborted) throw classify2(combined.reason, signal, combined);
|
|
2247
|
+
if (chunk.done) break;
|
|
2248
|
+
size += chunk.value.byteLength;
|
|
2249
|
+
if (size > maxBytes) throw new PricingError("too-large");
|
|
2250
|
+
raw += decoder.decode(chunk.value, { stream: true });
|
|
2251
|
+
}
|
|
2252
|
+
raw += decoder.decode();
|
|
2253
|
+
} catch (error) {
|
|
2254
|
+
if (error instanceof PricingError) throw error;
|
|
2255
|
+
throw classify2(error, signal, combined);
|
|
2256
|
+
} finally {
|
|
2257
|
+
combined.removeEventListener("abort", cancel);
|
|
2258
|
+
cancel();
|
|
2259
|
+
reader.releaseLock();
|
|
2260
|
+
}
|
|
2261
|
+
return raw;
|
|
2262
|
+
}
|
|
2263
|
+
async function fetchHtml(url, options, timeoutMs, maxBytes) {
|
|
2264
|
+
const request = options.fetcher ?? fetch;
|
|
2265
|
+
const combined = combinedSignal(options.signal, timeoutMs);
|
|
2266
|
+
let response;
|
|
2267
|
+
try {
|
|
2268
|
+
response = await request(url, {
|
|
2269
|
+
method: "GET",
|
|
2270
|
+
headers: { accept: "text/html" },
|
|
2271
|
+
signal: combined,
|
|
2272
|
+
redirect: "error",
|
|
2273
|
+
credentials: "omit"
|
|
2274
|
+
});
|
|
2275
|
+
} catch (error) {
|
|
2276
|
+
throw classify2(error, options.signal, combined);
|
|
2277
|
+
}
|
|
2278
|
+
if (combined.aborted) {
|
|
2279
|
+
void response.body?.cancel().catch(() => void 0);
|
|
2280
|
+
throw classify2(combined.reason, options.signal, combined);
|
|
2281
|
+
}
|
|
2282
|
+
if (response.redirected || response.url && response.url !== url) {
|
|
2283
|
+
void response.body?.cancel().catch(() => void 0);
|
|
2284
|
+
throw new PricingError("invalid-page");
|
|
2285
|
+
}
|
|
2286
|
+
if (!response.ok) {
|
|
2287
|
+
void response.body?.cancel().catch(() => void 0);
|
|
2288
|
+
throw new PricingError("status", response.status);
|
|
2289
|
+
}
|
|
2290
|
+
const contentType = response.headers.get("content-type");
|
|
2291
|
+
if (contentType !== null && !/text\/html|application\/xhtml\+xml/iu.test(contentType)) {
|
|
2292
|
+
void response.body?.cancel().catch(() => void 0);
|
|
2293
|
+
throw new PricingError("invalid-page");
|
|
2294
|
+
}
|
|
2295
|
+
return readBounded(response, maxBytes, options.signal, combined);
|
|
2296
|
+
}
|
|
2297
|
+
async function fetchPricingSnapshot(options = {}) {
|
|
2298
|
+
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
2299
|
+
const timeoutMs = options.timeoutMs ?? PRICING_TIMEOUT_MS;
|
|
2300
|
+
const maxBytes = options.maxBytes ?? MAX_PRICING_BODY_BYTES;
|
|
2301
|
+
const catalogUrl = `${PRICING_ORIGIN}${PRICING_CATALOG_PATH}`;
|
|
2302
|
+
const source = { kind: "official-website", origin: PRICING_ORIGIN, catalogUrl };
|
|
2303
|
+
const deadline = combinedSignal(options.signal, timeoutMs);
|
|
2304
|
+
let rejectAbort = () => void 0;
|
|
2305
|
+
const aborted = new Promise((_resolve, reject) => {
|
|
2306
|
+
rejectAbort = reject;
|
|
2307
|
+
});
|
|
2308
|
+
const onAbort = () => rejectAbort(new PricingError(options.signal?.aborted ? "aborted" : "timeout"));
|
|
2309
|
+
deadline.addEventListener("abort", onAbort, { once: true });
|
|
2310
|
+
try {
|
|
2311
|
+
if (deadline.aborted) throw classify2(deadline.reason, options.signal, deadline);
|
|
2312
|
+
const html = await Promise.race([fetchHtml(catalogUrl, { ...options, signal: deadline }, timeoutMs, maxBytes), aborted]);
|
|
2313
|
+
const catalog = parsePricingCatalog(html);
|
|
2314
|
+
return {
|
|
2315
|
+
status: "ok",
|
|
2316
|
+
source,
|
|
2317
|
+
fetchedAt: now().toISOString(),
|
|
2318
|
+
currency: catalog.currency,
|
|
2319
|
+
unit: catalog.unit,
|
|
2320
|
+
models: catalog.models,
|
|
2321
|
+
issues: []
|
|
2322
|
+
};
|
|
2323
|
+
} catch (error) {
|
|
2324
|
+
const failure = deadline.aborted && !options.signal?.aborted ? new PricingError("timeout") : classify2(error, options.signal, deadline);
|
|
2325
|
+
const issue = { code: failure.kind, message: failure.message, url: catalogUrl };
|
|
2326
|
+
if (failure.status !== void 0) issue.status = failure.status;
|
|
2327
|
+
return { status: "failed", source, fetchedAt: now().toISOString(), currency: null, unit: null, models: [], issues: [issue] };
|
|
2328
|
+
} finally {
|
|
2329
|
+
deadline.removeEventListener("abort", onAbort);
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2033
2333
|
// src/auth.ts
|
|
2034
2334
|
import { readFile as fsReadFile } from "node:fs/promises";
|
|
2035
2335
|
import { homedir as osHomedir } from "node:os";
|
|
@@ -2239,7 +2539,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2239
2539
|
|
|
2240
2540
|
// src/device-auth.ts
|
|
2241
2541
|
var DEVICE_AUTH_ENDPOINT = "https://amr-api.open-design.ai/api/v1/cli/device-authorizations";
|
|
2242
|
-
var DEVICE_AUTH_PLUGIN_VERSION = "0.1.
|
|
2542
|
+
var DEVICE_AUTH_PLUGIN_VERSION = "0.1.10";
|
|
2243
2543
|
var DEVICE_REQUEST_TIMEOUT_MS = 2e4;
|
|
2244
2544
|
var DEVICE_RESPONSE_MAX_BYTES = 65536;
|
|
2245
2545
|
var DEVICE_POLL_MIN_MS = 1e3;
|
|
@@ -3183,7 +3483,7 @@ var MAX_WINDOWS = 64;
|
|
|
3183
3483
|
var MAX_API_KEY = 16384;
|
|
3184
3484
|
var HTTP_ASCII = /^[\x21-\x7e]+$/u;
|
|
3185
3485
|
var ENV_REF = /^[A-Za-z_][A-Za-z0-9_]*$/u;
|
|
3186
|
-
var
|
|
3486
|
+
var MODEL_ID3 = /^[A-Za-z0-9._:/-]{1,128}$/u;
|
|
3187
3487
|
var ACTIVATION_OPEN_CODES = ["opened", "no-link", "invalid-url", "unavailable", "failed"];
|
|
3188
3488
|
var LOGIN_PHASES = ["idle", "launching", "waiting", "verifying", "success", "cancelled", "error"];
|
|
3189
3489
|
var QUOTA_STATES = ["ok", "partial", "need-login", "error"];
|
|
@@ -3224,6 +3524,40 @@ function member(value, allowed, label) {
|
|
|
3224
3524
|
if (hit === void 0) throw new Error(`${label} \u4E0D\u5728\u5141\u8BB8\u7684\u53D6\u503C\u5185`);
|
|
3225
3525
|
return hit;
|
|
3226
3526
|
}
|
|
3527
|
+
function parsePriceCatalog(value) {
|
|
3528
|
+
if (!record(value) || !Array.isArray(value.models) || value.models.length > MAX_MODELS2) throw new Error("\u4EF7\u683C\u76EE\u5F55\u683C\u5F0F\u65E0\u6548");
|
|
3529
|
+
const state = member(value.state, ["ok", "partial", "error"], "\u4EF7\u683C\u76EE\u5F55\u72B6\u6001");
|
|
3530
|
+
const stale = flag(value.stale, "\u4EF7\u683C\u7F13\u5B58\u72B6\u6001");
|
|
3531
|
+
const fetchedAt = value.fetchedAt === void 0 ? void 0 : isoTime(value.fetchedAt, "\u4EF7\u683C\u66F4\u65B0\u65F6\u95F4");
|
|
3532
|
+
if (stale && fetchedAt === void 0) throw new Error("\u8FC7\u671F\u4EF7\u683C\u5FC5\u987B\u6807\u6CE8\u66F4\u65B0\u65F6\u95F4");
|
|
3533
|
+
const ids = /* @__PURE__ */ new Set();
|
|
3534
|
+
const nullableAmount = (item) => {
|
|
3535
|
+
if (item === null) return null;
|
|
3536
|
+
const result = amount(item, "\u4EF7\u683C");
|
|
3537
|
+
if (result > 1e6) throw new Error("\u4EF7\u683C\u8D85\u51FA\u8303\u56F4");
|
|
3538
|
+
return result;
|
|
3539
|
+
};
|
|
3540
|
+
const models = value.models.map((model) => {
|
|
3541
|
+
if (!record(model) || !Array.isArray(model.tiers) || model.tiers.length === 0 || model.tiers.length > 8) throw new Error("\u6A21\u578B\u4EF7\u683C\u683C\u5F0F\u65E0\u6548");
|
|
3542
|
+
const id = text(model.id, "\u6A21\u578B id", 128);
|
|
3543
|
+
if (!MODEL_ID3.test(id) || ids.has(id)) throw new Error("\u6A21\u578B\u4EF7\u683C id \u65E0\u6548\u6216\u91CD\u590D");
|
|
3544
|
+
ids.add(id);
|
|
3545
|
+
const tiers = model.tiers.map((tier) => {
|
|
3546
|
+
if (!record(tier)) throw new Error("\u4EF7\u683C\u6863\u4F4D\u683C\u5F0F\u65E0\u6548");
|
|
3547
|
+
return {
|
|
3548
|
+
label: text(tier.label, "\u4EF7\u683C\u6863\u4F4D", 128),
|
|
3549
|
+
currency: tier.currency === null ? null : member(tier.currency, ["USD"], "\u4EF7\u683C\u5E01\u79CD"),
|
|
3550
|
+
unit: tier.unit === null ? null : member(tier.unit, ["per_1m_tokens", "per_1k_tokens"], "\u4EF7\u683C\u5355\u4F4D"),
|
|
3551
|
+
input: nullableAmount(tier.input),
|
|
3552
|
+
output: nullableAmount(tier.output),
|
|
3553
|
+
cacheRead: nullableAmount(tier.cacheRead),
|
|
3554
|
+
cacheWrite: nullableAmount(tier.cacheWrite)
|
|
3555
|
+
};
|
|
3556
|
+
});
|
|
3557
|
+
return { id, tiers };
|
|
3558
|
+
});
|
|
3559
|
+
return { state, stale, ...fetchedAt === void 0 ? {} : { fetchedAt }, models };
|
|
3560
|
+
}
|
|
3227
3561
|
function parseQuotaWindow(value) {
|
|
3228
3562
|
if (!record(value)) throw new Error("\u989D\u5EA6\u7A97\u53E3\u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
3229
3563
|
const durationSeconds = amount(value.durationSeconds, "\u989D\u5EA6\u7A97\u53E3\u65F6\u957F");
|
|
@@ -3293,7 +3627,7 @@ function parseLoginState(value) {
|
|
|
3293
3627
|
function parseStatusModel(value) {
|
|
3294
3628
|
if (!record(value)) throw new Error("\u6A21\u578B\u6761\u76EE\u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
3295
3629
|
const id = text(value.id, "\u6A21\u578B id", 128);
|
|
3296
|
-
if (!
|
|
3630
|
+
if (!MODEL_ID3.test(id)) throw new Error("\u6A21\u578B id \u542B\u4E0D\u5141\u8BB8\u7684\u5B57\u7B26");
|
|
3297
3631
|
return {
|
|
3298
3632
|
id,
|
|
3299
3633
|
name: text(value.name, "\u6A21\u578B\u540D", 128),
|
|
@@ -3383,8 +3717,8 @@ function grantOf(value) {
|
|
|
3383
3717
|
if (typeof value.payload.cookie !== "string") return;
|
|
3384
3718
|
return { cookie: value.payload.cookie, ...typeof value.payload.expiresAt === "number" ? { expiresAt: value.payload.expiresAt } : {} };
|
|
3385
3719
|
}
|
|
3386
|
-
var _saveApiKey_dec, _openActivationPage_dec, _cancelLogin_dec, _loginStatus_dec, _startLogin_dec, _refreshQuotaNow_dec, _refreshQuota_dec, _refreshModels_dec, _status_dec, _a, _init;
|
|
3387
|
-
var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status_dec = [Remote("status")], _refreshModels_dec = [Remote("refreshModels")], _refreshQuota_dec = [Remote("refreshQuota")], _refreshQuotaNow_dec = [Remote("refreshQuotaNow")], _startLogin_dec = [Remote("startLogin")], _loginStatus_dec = [Remote("loginStatus")], _cancelLogin_dec = [Remote("cancelLogin")], _openActivationPage_dec = [Remote("openActivationPage")], _saveApiKey_dec = [Remote("saveApiKey")], _a) {
|
|
3720
|
+
var _saveApiKey_dec, _openActivationPage_dec, _cancelLogin_dec, _loginStatus_dec, _startLogin_dec, _refreshQuotaNow_dec, _refreshQuota_dec, _refreshPrices_dec, _refreshModels_dec, _status_dec, _a, _init;
|
|
3721
|
+
var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status_dec = [Remote("status")], _refreshModels_dec = [Remote("refreshModels")], _refreshPrices_dec = [Remote("refreshPrices")], _refreshQuota_dec = [Remote("refreshQuota")], _refreshQuotaNow_dec = [Remote("refreshQuotaNow")], _startLogin_dec = [Remote("startLogin")], _loginStatus_dec = [Remote("loginStatus")], _cancelLogin_dec = [Remote("cancelLogin")], _openActivationPage_dec = [Remote("openActivationPage")], _saveApiKey_dec = [Remote("saveApiKey")], _a) {
|
|
3388
3722
|
constructor(ctx, config, dependencies = { resolveSession, readQuota, readDesktopQuota }) {
|
|
3389
3723
|
super(ctx, "openDesignCoRouter");
|
|
3390
3724
|
this.dependencies = dependencies;
|
|
@@ -3410,6 +3744,8 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
|
|
|
3410
3744
|
__publicField(this, "_modelsEpoch", 0);
|
|
3411
3745
|
__publicField(this, "_modelsPending");
|
|
3412
3746
|
__publicField(this, "_modelsController");
|
|
3747
|
+
__publicField(this, "_prices");
|
|
3748
|
+
__publicField(this, "_pricesPending");
|
|
3413
3749
|
this._config = config;
|
|
3414
3750
|
this._login = new ConsoleLogin({
|
|
3415
3751
|
capture: async (expectedRevision) => {
|
|
@@ -3593,6 +3929,31 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
|
|
|
3593
3929
|
if (this._modelsPending === run) this._modelsPending = void 0;
|
|
3594
3930
|
}
|
|
3595
3931
|
}
|
|
3932
|
+
async refreshPrices() {
|
|
3933
|
+
if (this._pricesPending) return this._pricesPending;
|
|
3934
|
+
const run = (async () => {
|
|
3935
|
+
try {
|
|
3936
|
+
const result = await (this.dependencies.fetchPrices ?? fetchPricingSnapshot)({ signal: this._lifetime.signal });
|
|
3937
|
+
if (this._lifetime.signal.aborted || result.status === "failed") throw new Error("price unavailable");
|
|
3938
|
+
const next = parsePriceCatalog({
|
|
3939
|
+
state: result.status,
|
|
3940
|
+
stale: false,
|
|
3941
|
+
fetchedAt: result.fetchedAt,
|
|
3942
|
+
models: result.models.map(({ id, tiers }) => ({ id, tiers }))
|
|
3943
|
+
});
|
|
3944
|
+
this._prices = next;
|
|
3945
|
+
return next;
|
|
3946
|
+
} catch {
|
|
3947
|
+
return this._prices === void 0 ? { state: "error", stale: false, models: [] } : { ...this._prices, state: "error", stale: true };
|
|
3948
|
+
}
|
|
3949
|
+
})();
|
|
3950
|
+
this._pricesPending = run;
|
|
3951
|
+
try {
|
|
3952
|
+
return await run;
|
|
3953
|
+
} finally {
|
|
3954
|
+
if (this._pricesPending === run) this._pricesPending = void 0;
|
|
3955
|
+
}
|
|
3956
|
+
}
|
|
3596
3957
|
async refreshQuota() {
|
|
3597
3958
|
return this._refreshQuota(false);
|
|
3598
3959
|
}
|
|
@@ -3732,6 +4093,7 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
|
|
|
3732
4093
|
_init = __decoratorStart(_a);
|
|
3733
4094
|
__decorateElement(_init, 1, "status", _status_dec, OpenDesignCoRouterService);
|
|
3734
4095
|
__decorateElement(_init, 1, "refreshModels", _refreshModels_dec, OpenDesignCoRouterService);
|
|
4096
|
+
__decorateElement(_init, 1, "refreshPrices", _refreshPrices_dec, OpenDesignCoRouterService);
|
|
3735
4097
|
__decorateElement(_init, 1, "refreshQuota", _refreshQuota_dec, OpenDesignCoRouterService);
|
|
3736
4098
|
__decorateElement(_init, 1, "refreshQuotaNow", _refreshQuotaNow_dec, OpenDesignCoRouterService);
|
|
3737
4099
|
__decorateElement(_init, 1, "startLogin", _startLogin_dec, OpenDesignCoRouterService);
|