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
package/lib/pricing.d.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 官网公开模型价格读取。
|
|
3
|
+
*
|
|
4
|
+
* 契约:
|
|
5
|
+
* - 只访问公开官网的固定 origin(`https://corouter.open-design.ai`),不携带任何凭据、
|
|
6
|
+
* 不读宿主 Profile、不触发真实计费或预检。主机与路径由模块常量决定,调用方无法改写。
|
|
7
|
+
* - 官网没有 JSON 接口,价格只存在于服务端渲染的 HTML:
|
|
8
|
+
* - 目录页 `/zh/models/`:每个模型一个 `model-explorer-panel`,`data-model-panel` 是官网的
|
|
9
|
+
* 精确模型 ID,面板内按档位(`model-explorer-tier`)列出输入/输出/缓存读取/缓存写入单价。
|
|
10
|
+
* - 详情页 `/zh/models/<slug>/`:`data-model` 属性内是官网自己的 JSON,含精确 ID 与单价,
|
|
11
|
+
* 可用于交叉核对目录页读到的 ID 与价格。
|
|
12
|
+
* - 单价单位是“美元 / 百万 Token”,币种由价格前的 `$` 符号判定。官网把未列出的价格写成
|
|
13
|
+
* `—`(目录页 `aria-label="工作台未单列价格"`,详情页 `null`),本模块一律记为 `null`,
|
|
14
|
+
* 不用任何方式推算或补齐。
|
|
15
|
+
* - 缺路由时官网会返回首页且 HTTP 200,因此每个页面都用 `data-page-name` 标记与
|
|
16
|
+
* `data-model` 的 ID 校验来识别“拿到的不是目标页”,宁可判失败也不解析错页。
|
|
17
|
+
* - 默认只发一次目录页请求。请求有超时、响应体字节上限与取消处理;失败不抛给调用方,
|
|
18
|
+
* 而是折叠进 `PricingSnapshot.issues` 并区分 `status`。
|
|
19
|
+
*/
|
|
20
|
+
/** 官网固定 origin;公开页面无鉴权,模块不接受调用方替换主机。 */
|
|
21
|
+
export declare const PRICING_ORIGIN = "https://corouter.open-design.ai";
|
|
22
|
+
/** 价格目录页路径(含语言前缀)。 */
|
|
23
|
+
export declare const PRICING_CATALOG_PATH = "/zh/models/";
|
|
24
|
+
/** 单次请求的默认时限(毫秒)。 */
|
|
25
|
+
export declare const PRICING_TIMEOUT_MS = 15000;
|
|
26
|
+
/** 单次响应的默认字节上限;目录页约 0.5 MiB。 */
|
|
27
|
+
export declare const MAX_PRICING_BODY_BYTES: number;
|
|
28
|
+
/** 官网价格使用的币种。 */
|
|
29
|
+
export type PricingCurrency = 'USD';
|
|
30
|
+
/** 官网价格的计价单位。 */
|
|
31
|
+
export type PricingUnit = 'per_1m_tokens' | 'per_1k_tokens';
|
|
32
|
+
/** 目录页与详情页共有的价格分项。 */
|
|
33
|
+
export type PricingMetric = 'input' | 'output' | 'cacheRead' | 'cacheWrite';
|
|
34
|
+
/**
|
|
35
|
+
* 一个价格档位。`null` 表示官网没有列出该分项的价格,不代表零价。
|
|
36
|
+
* `label` 是官网原文,档位之间按官网顺序排列并带 `index`,展示时不得跨档合并。
|
|
37
|
+
*/
|
|
38
|
+
export interface ModelPriceTier {
|
|
39
|
+
/** 档位序号(从 0 开始,按官网顺序)。 */
|
|
40
|
+
index: number;
|
|
41
|
+
/** 官网给出的档位标签,例如 `27.2 万 Token 及以内` / `超过 27.2 万 Token` / `不按输入长度分档`。 */
|
|
42
|
+
label: string;
|
|
43
|
+
input: number | null;
|
|
44
|
+
output: number | null;
|
|
45
|
+
cacheRead: number | null;
|
|
46
|
+
cacheWrite: number | null;
|
|
47
|
+
currency: PricingCurrency | null;
|
|
48
|
+
unit: PricingUnit | null;
|
|
49
|
+
}
|
|
50
|
+
/** 一个模型的官网价格。 */
|
|
51
|
+
export interface ModelPricing {
|
|
52
|
+
/** 官网精确模型 ID,例如 `gpt-6.1-sol`。 */
|
|
53
|
+
id: string;
|
|
54
|
+
/** 官网展示名。 */
|
|
55
|
+
name: string;
|
|
56
|
+
/** 官网标注的厂商。 */
|
|
57
|
+
provider: string | null;
|
|
58
|
+
/** 官网详情页 slug;与模型 ID 不同名,仅用于定位详情页。 */
|
|
59
|
+
slug: string | null;
|
|
60
|
+
/** 详情页绝对地址。 */
|
|
61
|
+
detailUrl: string | null;
|
|
62
|
+
/** 按官网顺序排列的价格档位;长度大于 1 表示该模型按输入长度分档定价。 */
|
|
63
|
+
tiers: ModelPriceTier[];
|
|
64
|
+
}
|
|
65
|
+
/** 价格来源。 */
|
|
66
|
+
export interface PricingSource {
|
|
67
|
+
kind: 'official-website';
|
|
68
|
+
origin: string;
|
|
69
|
+
catalogUrl: string;
|
|
70
|
+
}
|
|
71
|
+
/** 失败分类。 */
|
|
72
|
+
export type PricingErrorKind = 'timeout' | 'aborted' | 'network' | 'status' | 'too-large' | 'invalid-page' | 'invalid-model';
|
|
73
|
+
/** 快照里的一条失败记录。 */
|
|
74
|
+
export interface PricingIssue {
|
|
75
|
+
code: PricingErrorKind;
|
|
76
|
+
message: string;
|
|
77
|
+
url?: string;
|
|
78
|
+
status?: number;
|
|
79
|
+
}
|
|
80
|
+
/** 价格快照。`status` 为 `failed` 时 `models` 为空。 */
|
|
81
|
+
export interface PricingSnapshot {
|
|
82
|
+
status: 'ok' | 'partial' | 'failed';
|
|
83
|
+
source: PricingSource;
|
|
84
|
+
/** 采集时间(ISO 8601)。 */
|
|
85
|
+
fetchedAt: string;
|
|
86
|
+
currency: PricingCurrency | null;
|
|
87
|
+
unit: PricingUnit | null;
|
|
88
|
+
models: ModelPricing[];
|
|
89
|
+
issues: PricingIssue[];
|
|
90
|
+
}
|
|
91
|
+
/** 目录页解析结果。 */
|
|
92
|
+
export interface PricingCatalog {
|
|
93
|
+
models: ModelPricing[];
|
|
94
|
+
currency: PricingCurrency | null;
|
|
95
|
+
unit: PricingUnit | null;
|
|
96
|
+
}
|
|
97
|
+
/** 抓取选项。 */
|
|
98
|
+
export interface PricingFetchOptions {
|
|
99
|
+
/** `fetch` 替换实现(测试与自定义传输)。 */
|
|
100
|
+
fetcher?: typeof fetch;
|
|
101
|
+
/** 单次请求时限(毫秒)。 */
|
|
102
|
+
timeoutMs?: number;
|
|
103
|
+
/** 单次响应字节上限。 */
|
|
104
|
+
maxBytes?: number;
|
|
105
|
+
/** 调用方取消信号。 */
|
|
106
|
+
signal?: AbortSignal;
|
|
107
|
+
/** 采集时间来源。 */
|
|
108
|
+
now?: () => Date;
|
|
109
|
+
}
|
|
110
|
+
/** 价格读取失败。消息为固定文案,不回显响应体。 */
|
|
111
|
+
export declare class PricingError extends Error {
|
|
112
|
+
readonly kind: PricingErrorKind;
|
|
113
|
+
readonly status?: number | undefined;
|
|
114
|
+
constructor(kind: PricingErrorKind, status?: number | undefined);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 解析官网价格目录页。
|
|
118
|
+
*
|
|
119
|
+
* @param html 目录页 HTML。
|
|
120
|
+
* @returns 目录页上的模型价格;每个模型保留官网自己的档位与档位标签。
|
|
121
|
+
* @throws {PricingError} 页面不是价格目录页(`invalid-page`)。
|
|
122
|
+
*/
|
|
123
|
+
export declare function parsePricingCatalog(html: string): PricingCatalog;
|
|
124
|
+
/**
|
|
125
|
+
* 解析官网模型详情页。
|
|
126
|
+
*
|
|
127
|
+
* 详情页把每个模型的价格写成 `data-model` 属性里的官网 JSON;用它可以交叉核对目录页
|
|
128
|
+
* 读到的精确 ID 与单价。此处只做解析,不代替目录页作为常规取数路径。
|
|
129
|
+
*
|
|
130
|
+
* @param html 详情页 HTML。
|
|
131
|
+
* @returns 该模型的价格;两个档位分别是官网的“标准输入”与“长输入”。
|
|
132
|
+
* @throws {PricingError} 页面不含官网模型数据(`invalid-model`)。
|
|
133
|
+
*/
|
|
134
|
+
export declare function parseModelDetailPricing(html: string): ModelPricing;
|
|
135
|
+
/**
|
|
136
|
+
* 拉取官网模型价格。默认只发一次目录页请求。
|
|
137
|
+
*
|
|
138
|
+
* @param options 超时、体积上限、取消与采集时间来源。
|
|
139
|
+
* @returns 价格快照;失败时 `status` 为 `failed` 且 `issues` 说明原因。
|
|
140
|
+
*/
|
|
141
|
+
export declare function fetchPricingSnapshot(options?: PricingFetchOptions): Promise<PricingSnapshot>;
|
|
142
|
+
/**
|
|
143
|
+
* 按官网精确模型 ID 查价格。
|
|
144
|
+
*
|
|
145
|
+
* @param snapshot 价格快照。
|
|
146
|
+
* @param id 精确模型 ID,例如 `gpt-6.1-sol`。
|
|
147
|
+
* @returns 命中的模型价格;没有该 ID 时返回 `undefined`。
|
|
148
|
+
*/
|
|
149
|
+
export declare function findModelPricing(snapshot: PricingSnapshot, id: string): ModelPricing | undefined;
|
package/lib/remote.d.ts
CHANGED
|
@@ -30,6 +30,25 @@ export interface StatusModel {
|
|
|
30
30
|
maxOutputTokens?: number;
|
|
31
31
|
reasoningEfforts?: readonly string[];
|
|
32
32
|
}
|
|
33
|
+
/** Public website quotes, independent of account entitlements and gateway discovery. */
|
|
34
|
+
export interface PriceTier {
|
|
35
|
+
label: string;
|
|
36
|
+
currency: 'USD' | null;
|
|
37
|
+
unit: 'per_1m_tokens' | 'per_1k_tokens' | null;
|
|
38
|
+
input: number | null;
|
|
39
|
+
output: number | null;
|
|
40
|
+
cacheRead: number | null;
|
|
41
|
+
cacheWrite: number | null;
|
|
42
|
+
}
|
|
43
|
+
export interface PriceCatalog {
|
|
44
|
+
state: 'ok' | 'partial' | 'error';
|
|
45
|
+
stale: boolean;
|
|
46
|
+
fetchedAt?: string;
|
|
47
|
+
models: readonly {
|
|
48
|
+
id: string;
|
|
49
|
+
tiers: readonly PriceTier[];
|
|
50
|
+
}[];
|
|
51
|
+
}
|
|
33
52
|
/** Terminal-or-in-flight phases a login job may report. */
|
|
34
53
|
export type LoginPhase = 'idle' | 'launching' | 'waiting' | 'verifying' | 'success' | 'cancelled' | 'error';
|
|
35
54
|
/** Credential-free view of the independent console login. */
|
|
@@ -76,6 +95,8 @@ export interface ActivationOpenState {
|
|
|
76
95
|
code: 'opened' | 'no-link' | 'invalid-url' | 'unavailable' | 'failed';
|
|
77
96
|
opened: boolean;
|
|
78
97
|
}
|
|
98
|
+
/** Only bounded, public pricing fields cross into the Client. */
|
|
99
|
+
export declare function parsePriceCatalog(value: unknown): PriceCatalog;
|
|
79
100
|
/** Rebuild a `QuotaSnapshot` from an allowlist; unknown keys are dropped. */
|
|
80
101
|
export declare function parseQuotaSnapshot(value: unknown): QuotaSnapshot;
|
|
81
102
|
/** Rebuild a `LoginState` from an allowlist; the job's secret material never had a field here. */
|