dsh-opendesign-corouter 0.1.9 → 0.1.11
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 +4 -4
- package/lib/client.d.ts +22 -4
- package/lib/client.js +254 -52
- package/lib/device-auth.d.ts +1 -1
- package/lib/empty-turn.d.ts +11 -6
- package/lib/eot-code.d.ts +2 -0
- package/lib/eot-recovery.d.ts +33 -0
- 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 +500 -25
- package/lib/index.js.map +4 -4
- package/lib/pricing.d.ts +149 -0
- package/lib/protocols/errors.d.ts +4 -0
- package/lib/remote.d.ts +21 -0
- package/package.json +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { LlmFailure } from '@deepseek-ai/dsh-llm';
|
|
3
|
+
type RecoveryAction = {
|
|
4
|
+
kind: 'retry';
|
|
5
|
+
} | undefined;
|
|
6
|
+
interface RetrySession {
|
|
7
|
+
append(type: 'llm/retry' | 'llm/retry-started', data: Record<string, unknown>): unknown;
|
|
8
|
+
}
|
|
9
|
+
export interface RecoveryPayload {
|
|
10
|
+
agent: {
|
|
11
|
+
session: RetrySession;
|
|
12
|
+
};
|
|
13
|
+
turn: number;
|
|
14
|
+
step: number;
|
|
15
|
+
provider: string;
|
|
16
|
+
failure: LlmFailure;
|
|
17
|
+
signal: AbortSignal;
|
|
18
|
+
}
|
|
19
|
+
type RecoveryNext = () => Promise<RecoveryAction>;
|
|
20
|
+
type RecoveryListener = (payload: RecoveryPayload, next: RecoveryNext) => Promise<RecoveryAction>;
|
|
21
|
+
declare function cancellableDelay(delay: number, signal: AbortSignal): Promise<boolean>;
|
|
22
|
+
/** Own only the plugin-specific EOT failure; other errors continue down the host waterfall. */
|
|
23
|
+
export declare class EotRecovery {
|
|
24
|
+
#private;
|
|
25
|
+
readonly enabled: () => boolean;
|
|
26
|
+
readonly wait: typeof cancellableDelay;
|
|
27
|
+
constructor(enabled: () => boolean, wait?: typeof cancellableDelay);
|
|
28
|
+
readonly handle: RecoveryListener;
|
|
29
|
+
dispose(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
/** Register against the host's documented scoped recovery waterfall. */
|
|
32
|
+
export declare function installEotRecovery(ctx: Context, enabled: () => boolean): void;
|
|
33
|
+
export {};
|
|
@@ -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;
|