dsh-thinking-levels 4.3.2 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -75,11 +75,20 @@ export interface ThinkingLevelsConfig {
75
75
  * flag is the control-layer UI for it.
76
76
  */
77
77
  takeover: boolean | Volatile<boolean>;
78
+ /**
79
+ * UI takeover switch (issues #3/#4): false (default) keeps the official
80
+ * composer model popup — the `auto` mask still arrives through the adapter
81
+ * advertisement below, and the official popup keeps its native search.
82
+ * true seats the plugin's ModelPanel (which carries its own search box and
83
+ * the intent/resolved effort chip).
84
+ */
85
+ takeoverUi: boolean | Volatile<boolean>;
78
86
  /** Configurer-confirmed capability overrides, keyed `provider/model`. */
79
87
  models: Record<string, ModelCapabilityOverride>;
80
88
  /**
81
- * 目录外模型的计价兜底档(price-catalog 未命中时生效):cn/global/custom/off。
82
- * 缺省 off(未计价,不再拿单一型号价硬算);目录内模型自动按条目地区计价。
89
+ * 目录外模型的计价兜底档(price-catalog 未命中时生效):estimate/cn/global/custom/off。
90
+ * 缺省 estimate(典型价兜底估算,显示「未校准·仅供参考」);off 才是真不计价;
91
+ * 目录内模型自动按条目地区计价,不受本项影响。
83
92
  */
84
93
  defaultPricing: PricingPolicy | Volatile<PricingPolicy>;
85
94
  }
@@ -96,7 +105,8 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
96
105
  allowDowngrade: z<boolean, boolean, "volatile-defined">;
97
106
  allowUpgrade: z<boolean, boolean, "volatile-defined">;
98
107
  takeover: z<boolean, boolean, "volatile-defined">;
99
- defaultPricing: z<"cn" | "global" | "custom" | "off", "cn" | "global" | "custom" | "off", "volatile-defined">;
108
+ takeoverUi: z<boolean, boolean, "volatile-defined">;
109
+ defaultPricing: z<"estimate" | "cn" | "global" | "custom" | "off", "estimate" | "cn" | "global" | "custom" | "off", "volatile-defined">;
100
110
  models: z<import("@deepseek-ai/cosmokit").Dict<{
101
111
  vision?: boolean | null | undefined;
102
112
  thinking?: boolean | null | undefined;
@@ -114,7 +124,8 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
114
124
  allowDowngrade: z<boolean, boolean, "volatile-defined">;
115
125
  allowUpgrade: z<boolean, boolean, "volatile-defined">;
116
126
  takeover: z<boolean, boolean, "volatile-defined">;
117
- defaultPricing: z<"cn" | "global" | "custom" | "off", "cn" | "global" | "custom" | "off", "volatile-defined">;
127
+ takeoverUi: z<boolean, boolean, "volatile-defined">;
128
+ defaultPricing: z<"estimate" | "cn" | "global" | "custom" | "off", "estimate" | "cn" | "global" | "custom" | "off", "volatile-defined">;
118
129
  models: z<import("@deepseek-ai/cosmokit").Dict<{
119
130
  vision?: boolean | null | undefined;
120
131
  thinking?: boolean | null | undefined;
@@ -140,7 +151,8 @@ export declare const LegacyConfig: z<Schemastery.ObjectS<NoInfer<{
140
151
  allowDowngrade: z<boolean, boolean, "defined">;
141
152
  allowUpgrade: z<boolean, boolean, "defined">;
142
153
  takeover: z<boolean, boolean, "defined">;
143
- defaultPricing: z<"cn" | "global" | "custom" | "off", "cn" | "global" | "custom" | "off", "defined">;
154
+ takeoverUi: z<boolean, boolean, "defined">;
155
+ defaultPricing: z<"estimate" | "cn" | "global" | "custom" | "off", "estimate" | "cn" | "global" | "custom" | "off", "defined">;
144
156
  models: z<import("@deepseek-ai/cosmokit").Dict<{
145
157
  vision?: boolean | null | undefined;
146
158
  thinking?: boolean | null | undefined;
@@ -158,7 +170,8 @@ export declare const LegacyConfig: z<Schemastery.ObjectS<NoInfer<{
158
170
  allowDowngrade: z<boolean, boolean, "defined">;
159
171
  allowUpgrade: z<boolean, boolean, "defined">;
160
172
  takeover: z<boolean, boolean, "defined">;
161
- defaultPricing: z<"cn" | "global" | "custom" | "off", "cn" | "global" | "custom" | "off", "defined">;
173
+ takeoverUi: z<boolean, boolean, "defined">;
174
+ defaultPricing: z<"estimate" | "cn" | "global" | "custom" | "off", "estimate" | "cn" | "global" | "custom" | "off", "defined">;
162
175
  models: z<import("@deepseek-ai/cosmokit").Dict<{
163
176
  vision?: boolean | null | undefined;
164
177
  thinking?: boolean | null | undefined;
@@ -190,6 +203,45 @@ declare module '@deepseek-ai/cordis' {
190
203
  * the schema default is the fallback.
191
204
  */
192
205
  export declare function readVolatile<T>(value: T | Volatile<T> | undefined, fallback: T): T;
206
+ /** Minimal face of the llm service's adapter registrations (typed locally to avoid a host-package value import). */
207
+ interface LlmRegistration {
208
+ adapter: {
209
+ resolveModel: (provider: string, model: string, signal?: unknown) => Promise<{
210
+ reasoning?: {
211
+ efforts?: {
212
+ id: string;
213
+ name: string;
214
+ }[];
215
+ };
216
+ }>;
217
+ };
218
+ }
219
+ /**
220
+ * Advertise `auto` (and, for configurer-confirmed rc.6-era models, `low`) in
221
+ * the model directory: wrap every registered adapter's `resolveModel` so the
222
+ * returned `reasoning.efforts` include the extra levels. Idempotent per
223
+ * adapter. `auto` is a mask the plugin resolves per request; `low` is only
224
+ * added when the model override confirms the level, so rc.7+ models (which
225
+ * already advertise low) and unconfirmed models stay untouched.
226
+ *
227
+ * A thinking model WITHOUT effort support (Qwen3.6-style, per the llm-pi-ai
228
+ * config: `reasoningEfforts` present but `compat.supportsReasoningEffort` not
229
+ * true) gets its selector collapsed to a plain On/Off toggle: `off` disables
230
+ * thinking, `on` maps to the `high` level, which pi-ai serializes as
231
+ * `enable_thinking: true` under `thinkingFormat: qwen`. No auto/low masks are
232
+ * offered for these — there is nothing to schedule.
233
+ * @param llm - the resolved `llm` service, when present.
234
+ * @param overrideFor - model override lookup, keyed `provider/model`.
235
+ * @param piAiFor - llm-pi-ai config capability lookup, keyed `provider/model`.
236
+ * (exported for the idempotence regression test, issue #4 — same precedent as
237
+ * `installLegacySection`)
238
+ */
239
+ export declare function advertiseModelCapability(llm: {
240
+ adapters?: Map<string, LlmRegistration>;
241
+ } | undefined, overrideFor: (provider: string, model: string) => ModelCapabilityOverride | undefined, piAiFor: (provider: string, model: string) => {
242
+ thinkingOn: boolean;
243
+ supportsEffort: boolean;
244
+ } | undefined): void;
193
245
  /**
194
246
  * Legacy (≤0.1.6) settings registration: on hosts whose settings service
195
247
  * carries the imperative face (`register` present, `describe` absent), install
@@ -207,3 +259,4 @@ export declare function installLegacySection(ctx: Context, config: ThinkingLevel
207
259
  * @param config - resolved plugin configuration.
208
260
  */
209
261
  export declare function apply(ctx: Context, config?: ThinkingLevelsConfig): void;
262
+ export {};
package/lib/index.js CHANGED
@@ -16,7 +16,7 @@ const modelsSchema = z.dict(z.object({
16
16
  contextWindow: z.number().step(1).min(CONTEXT_WINDOW_MIN).max(CONTEXT_WINDOW_MAX),
17
17
  })).default({});
18
18
  /** 计价兜底档:schemastery 枚举,两代 schema 共享(the two must never drift)。 */
19
- const defaultPricingSchema = z.union(['cn', 'global', 'custom', 'off']).default('off');
19
+ const defaultPricingSchema = z.union(['estimate', 'cn', 'global', 'custom', 'off']).default('estimate');
20
20
  /**
21
21
  * Composition-entry schema: what a dsh profile may configure at assembly
22
22
  * time (cordis.yml `config:` of the plugin row). The same schema doubles as
@@ -30,6 +30,7 @@ export const Config = z.object({
30
30
  allowDowngrade: z.boolean().default(true).volatile(),
31
31
  allowUpgrade: z.boolean().default(false).volatile(),
32
32
  takeover: z.boolean().default(false).volatile(),
33
+ takeoverUi: z.boolean().default(false).volatile(),
33
34
  defaultPricing: defaultPricingSchema.volatile(),
34
35
  models: modelsSchema,
35
36
  });
@@ -46,6 +47,7 @@ export const LegacyConfig = z.object({
46
47
  allowDowngrade: z.boolean().default(true),
47
48
  allowUpgrade: z.boolean().default(false),
48
49
  takeover: z.boolean().default(false),
50
+ takeoverUi: z.boolean().default(false),
49
51
  defaultPricing: defaultPricingSchema,
50
52
  models: modelsSchema,
51
53
  });
@@ -56,7 +58,8 @@ export const DEFAULT_CONFIG = {
56
58
  allowDowngrade: true,
57
59
  allowUpgrade: false,
58
60
  takeover: false,
59
- defaultPricing: 'off',
61
+ takeoverUi: false,
62
+ defaultPricing: 'estimate',
60
63
  models: {},
61
64
  };
62
65
  /**
@@ -84,7 +87,8 @@ function resolveLiveConfig(config) {
84
87
  allowDowngrade: readVolatile(config.allowDowngrade, true),
85
88
  allowUpgrade: readVolatile(config.allowUpgrade, false),
86
89
  takeover: readVolatile(config.takeover, false),
87
- defaultPricing: readVolatile(config.defaultPricing, 'off'),
90
+ takeoverUi: readVolatile(config.takeoverUi, false),
91
+ defaultPricing: readVolatile(config.defaultPricing, 'estimate'),
88
92
  models: config.models,
89
93
  };
90
94
  }
@@ -104,6 +108,15 @@ const AUTO_EFFORT = { id: 'auto', name: 'Auto' };
104
108
  * e.g. via `thinkingFormat: qwen` → enable_thinking + thinking_budget).
105
109
  */
106
110
  const LOW_EFFORT = { id: 'low', name: 'Low' };
111
+ /**
112
+ * Adapters whose `resolveModel` is already wrapped — the per-adapter
113
+ * idempotence issue #4 proves was missing: re-running the advertisement on
114
+ * every `llm/adapters-updated` stacked a new wrapper per pass, and every
115
+ * stacked layer re-ran the post-processing on each resolveModel call.
116
+ * Keyed on the adapter object itself, so a genuinely new adapter is wrapped
117
+ * once and retired ones need no cleanup.
118
+ */
119
+ const advertisedAdapters = new WeakSet();
107
120
  /**
108
121
  * Advertise `auto` (and, for configurer-confirmed rc.6-era models, `low`) in
109
122
  * the model directory: wrap every registered adapter's `resolveModel` so the
@@ -121,10 +134,19 @@ const LOW_EFFORT = { id: 'low', name: 'Low' };
121
134
  * @param llm - the resolved `llm` service, when present.
122
135
  * @param overrideFor - model override lookup, keyed `provider/model`.
123
136
  * @param piAiFor - llm-pi-ai config capability lookup, keyed `provider/model`.
137
+ * (exported for the idempotence regression test, issue #4 — same precedent as
138
+ * `installLegacySection`)
124
139
  */
125
- function advertiseModelCapability(llm, overrideFor, piAiFor) {
140
+ export function advertiseModelCapability(llm, overrideFor, piAiFor) {
126
141
  for (const registration of llm?.adapters?.values() ?? []) {
127
142
  const adapter = registration.adapter;
143
+ // Issue #4: the re-run on every `llm/adapters-updated` must NOT stack
144
+ // wrappers — each stacked layer re-ran the post-processing (and a full
145
+ // describeSettings) on every resolveModel call. This WeakSet is the
146
+ // idempotence the JSDoc has always promised.
147
+ if (advertisedAdapters.has(adapter))
148
+ continue;
149
+ advertisedAdapters.add(adapter);
128
150
  const original = adapter.resolveModel.bind(adapter);
129
151
  adapter.resolveModel = async (provider, model, signal) => {
130
152
  const info = await original(provider, model, signal);
@@ -250,6 +272,19 @@ function capabilityResolver(ctx) {
250
272
  }
251
273
  /** The registered settings namespace of the ≤0.1.6 era. */
252
274
  const THINKING_LEVELS_SETTINGS_NAMESPACE = 'thinking-levels';
275
+ /**
276
+ * The settings namespaces whose commits can move the takeover judgment
277
+ * (issue #4): the transport's `enabled` mirror must not be re-synced through
278
+ * a full describeSettings on EVERY unrelated commit — boot fires many.
279
+ * Includes both transport packaging ids and both own namespaces, so the
280
+ * mirror still re-checks whenever its own inputs move.
281
+ */
282
+ const TAKEOVER_SYNC_NAMESPACES = [
283
+ PI_AI_NAMESPACE,
284
+ ...TAKEOVER_NAMESPACE_CANDIDATES,
285
+ 'dsh-thinking-levels',
286
+ THINKING_LEVELS_SETTINGS_NAMESPACE,
287
+ ];
253
288
  /**
254
289
  * Legacy (≤0.1.6) settings registration: on hosts whose settings service
255
290
  * carries the imperative face (`register` present, `describe` absent), install
@@ -287,6 +322,7 @@ export function installLegacySection(ctx, config, hooks) {
287
322
  allowDowngrade: readVolatile(config.allowDowngrade, true),
288
323
  allowUpgrade: readVolatile(config.allowUpgrade, false),
289
324
  takeover: readVolatile(config.takeover, false),
325
+ takeoverUi: readVolatile(config.takeoverUi, false),
290
326
  models: config.models,
291
327
  };
292
328
  const scope = settings.register(THINKING_LEVELS_SETTINGS_NAMESPACE, LegacyConfig, { base: plainBase });
@@ -413,9 +449,11 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
413
449
  onSyncAny('settings/document-updated', (ns) => {
414
450
  if (ns === PI_AI_NAMESPACE)
415
451
  syncDeveloperRole();
416
- // Any settings commit re-checks the mirror (identity-gated); the write we
417
- // just made re-enters here and settles without a second write.
418
- syncTakeover();
452
+ // The mirror re-checks only where a commit can move the takeover
453
+ // judgment (issue #4); the write it just made re-enters here and
454
+ // settles (identity-gated) without a second write.
455
+ if (TAKEOVER_SYNC_NAMESPACES.includes(ns))
456
+ syncTakeover();
419
457
  });
420
458
  // Inject the level decision into every model request of a step.
421
459
  // The 'agent/request' event key is augmented onto cordis Events by the
@@ -476,8 +514,18 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
476
514
  // (Qwen3.6) is collapsed to an On/Off toggle in the selector — but ONLY when
477
515
  // the route is taken over by the openai-completions transport. A pi-ai-served
478
516
  // route (e.g. mimo via xiaomi) keeps its native off/high levels.
517
+ // Readout cache (issue #4): the resolveModel wrapper runs piAiFor on EVERY
518
+ // model resolution, and a full describeSettings per call made the model
519
+ // page cost O(models × adapters). One readout per generation, invalidated
520
+ // with the capability cache on every settings commit below.
521
+ let readoutCache;
522
+ const cachedReadout = () => {
523
+ if (readoutCache === undefined)
524
+ readoutCache = takeoverReadout(ctx);
525
+ return readoutCache;
526
+ };
479
527
  const piAiFor = (provider, model) => {
480
- const readout = takeoverReadout(ctx);
528
+ const readout = cachedReadout();
481
529
  return piAiPosture(readout.piAi, provider, model, readout.routes);
482
530
  };
483
531
  advertiseModelCapability(llm, overrideFor, piAiFor);
@@ -491,5 +539,6 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
491
539
  // toggle folding follows the new posture on the next request.
492
540
  onAny('settings/document-updated', () => {
493
541
  capability.clear();
542
+ readoutCache = undefined;
494
543
  });
495
544
  }
@@ -13,12 +13,15 @@
13
13
  * (官方定价页 2026-08-14 快照,2026-08-17 起峰谷分时;峰窗 09-12/14-18 北京);
14
14
  * - 国内厂商 flat 行:镜像 .peakref companion price/catalog.js CATALOG_TABLE
15
15
  * (各官方定价页人民币站低档价快照;免费行照录 0);
16
- * - 海外 USD 行:本轮网络侧无法核实(OpenAI 403 / Google 超时 / Anthropic 页无
17
- * API 表),结构留位、数值留空——宁缺毋伪,核实通道到位后走 golden 门禁补录。
16
+ * - 海外 USD 行:2026-10-18 补录(CATALOG_VERSION 1→2)——Claude 四行为
17
+ * Anthropic 官方定价页直接抓取;GPT/Gemini 行为 GitHub Copilot 计费文档一手
18
+ * 表(USD/MTok 默认档),并与多家独立报道交叉核实;促销/介绍期价格在 source
19
+ * 注明失效时点,届时按标准价改录并重跑 golden 门禁。
18
20
  *
19
21
  * 判定链:策略 key 特异性(provider/model > model > provider > *)→ 目录命中
20
- * (精确 > 最长后缀 > 最长包含)→ 目录外走 snapshot.defaultPricing(缺省 off,
21
- * source 记 'catalog-miss')。节假日/补班修正表随 isPeakBeijing 一并迁入,
22
+ * (精确 > 最长后缀 > 最长包含)→ 目录外走 snapshot.defaultPricing(缺省
23
+ * estimate = 典型价兜底估算,source 记 'catalog-miss' 且 estimated=true;
24
+ * off 才是真不计价)。节假日/补班修正表随 isPeakBeijing 一并迁入,
22
25
  * billing-projection 只负责记账,不再持有价格与日历。
23
26
  * @module dsh-thinking-levels/price-catalog
24
27
  */
@@ -30,8 +33,8 @@ export interface PriceRow {
30
33
  inputCacheHit: number;
31
34
  output: number;
32
35
  }
33
- /** 每 API 计价策略四档。 */
34
- export type PricingPolicy = 'cn' | 'global' | 'custom' | 'off';
36
+ /** 每 API 计价策略档位(estimate = 目录外典型价兜底估算,未校准仅供参考)。 */
37
+ export type PricingPolicy = 'estimate' | 'cn' | 'global' | 'custom' | 'off';
35
38
  /** 生效来源:四档 + 目录外兜底标记。 */
36
39
  export type PricingSource = PricingPolicy | 'catalog-miss';
37
40
  /** 峰/谷/平三态;平价条目(无峰谷官方价)与 custom 档用 flat。 */
@@ -50,7 +53,7 @@ export interface PricingSnapshot {
50
53
  defaultPricing: PricingPolicy;
51
54
  policies?: Readonly<Record<string, PolicyEntry>>;
52
55
  }
53
- /** 目录条目:cn 为 峰谷对 或 平价行;global 预留平价(当前留空)。 */
56
+ /** 目录条目:cn 为 峰谷对 或 平价行;global 为海外平价行(USD,2026-10-18 起有条目)。 */
54
57
  export interface CatalogEntry {
55
58
  key: string;
56
59
  label: string;
@@ -69,8 +72,17 @@ export interface CatalogEntry {
69
72
  /** 来源标注(官方定价页或仓内镜像快照路径)。 */
70
73
  source: string;
71
74
  }
72
- /** 目录版本(进解析缓存键与审计)。 */
73
- export declare const CATALOG_VERSION = 1;
75
+ /** 目录版本(进解析缓存键与审计)。2 = 2026-10-18 补录海外 USD 行。 */
76
+ export declare const CATALOG_VERSION = 2;
77
+ /**
78
+ * 目录外模型的兜底典型价(CNY/百万 token):取 DeepSeek-V4.1-Flash 谷时行
79
+ * ——主力模型的平价档,数量级最贴近通用网关。仅用于 estimate 档/目录外缺省,
80
+ * 展示侧必须带「未校准·仅供参考」标注,不得伪装成目录条目。
81
+ */
82
+ export declare const BILLING_FALLBACK: {
83
+ row: PriceRow;
84
+ currency: Currency;
85
+ };
74
86
  /** 内置典型价目目录(CNY/百万 token)。 */
75
87
  export declare const PRICE_CATALOG: readonly CatalogEntry[];
76
88
  /**
@@ -97,6 +109,8 @@ export interface ResolvedRate {
97
109
  source: PricingSource;
98
110
  entry: CatalogEntry | null;
99
111
  priced: boolean;
112
+ /** 金额为兜底典型价估算(未校准,仅供参考);恒随 priced。 */
113
+ estimated: boolean;
100
114
  }
101
115
  /** 唯一计价解析出口。目录命中且无显式策略时取条目自身地区(cn 优先,仅 global 取 global)。 */
102
116
  export declare function resolveRate(model: string | null, provider: string | null, timeMs: number, snapshot: PricingSnapshot): ResolvedRate;
@@ -13,19 +13,34 @@
13
13
  * (官方定价页 2026-08-14 快照,2026-08-17 起峰谷分时;峰窗 09-12/14-18 北京);
14
14
  * - 国内厂商 flat 行:镜像 .peakref companion price/catalog.js CATALOG_TABLE
15
15
  * (各官方定价页人民币站低档价快照;免费行照录 0);
16
- * - 海外 USD 行:本轮网络侧无法核实(OpenAI 403 / Google 超时 / Anthropic 页无
17
- * API 表),结构留位、数值留空——宁缺毋伪,核实通道到位后走 golden 门禁补录。
16
+ * - 海外 USD 行:2026-10-18 补录(CATALOG_VERSION 1→2)——Claude 四行为
17
+ * Anthropic 官方定价页直接抓取;GPT/Gemini 行为 GitHub Copilot 计费文档一手
18
+ * 表(USD/MTok 默认档),并与多家独立报道交叉核实;促销/介绍期价格在 source
19
+ * 注明失效时点,届时按标准价改录并重跑 golden 门禁。
18
20
  *
19
21
  * 判定链:策略 key 特异性(provider/model > model > provider > *)→ 目录命中
20
- * (精确 > 最长后缀 > 最长包含)→ 目录外走 snapshot.defaultPricing(缺省 off,
21
- * source 记 'catalog-miss')。节假日/补班修正表随 isPeakBeijing 一并迁入,
22
+ * (精确 > 最长后缀 > 最长包含)→ 目录外走 snapshot.defaultPricing(缺省
23
+ * estimate = 典型价兜底估算,source 记 'catalog-miss' 且 estimated=true;
24
+ * off 才是真不计价)。节假日/补班修正表随 isPeakBeijing 一并迁入,
22
25
  * billing-projection 只负责记账,不再持有价格与日历。
23
26
  * @module dsh-thinking-levels/price-catalog
24
27
  */
25
- /** 目录版本(进解析缓存键与审计)。 */
26
- export const CATALOG_VERSION = 1;
28
+ /** 目录版本(进解析缓存键与审计)。2 = 2026-10-18 补录海外 USD 行。 */
29
+ export const CATALOG_VERSION = 2;
30
+ /**
31
+ * 目录外模型的兜底典型价(CNY/百万 token):取 DeepSeek-V4.1-Flash 谷时行
32
+ * ——主力模型的平价档,数量级最贴近通用网关。仅用于 estimate 档/目录外缺省,
33
+ * 展示侧必须带「未校准·仅供参考」标注,不得伪装成目录条目。
34
+ */
35
+ export const BILLING_FALLBACK = {
36
+ row: { inputCacheHit: 0.02, inputMiss: 1, output: 4 },
37
+ currency: 'CNY',
38
+ };
27
39
  const PEAKOFF = 'DeepSeek 官方峰谷分时(峰窗 09-12/14-18 北京;源 api-docs.deepseek.com/zh-cn/quick_start/pricing/)';
28
40
  const PEAKREF = '镜像 .peakref/companion/lib/core/price/catalog.js 官方页快照(低档价)';
41
+ const ANOFF = 'Anthropic 官方定价页 2026-10-18 抓取快照(USD/MTok 默认档;缓存写入加价不在三价目位内;Haiku 取 ≤100K 低档)';
42
+ const OPAIREF = 'GitHub Copilot 计费文档 2026-10-18 抓取(USD/MTok 默认档,与 OpenAI 公告口径交叉核实;缓存写入价不在三价目位内)';
43
+ const GEOREF = 'GitHub Copilot 计费文档 2026-10-18 抓取(USD/MTok,与 Google 公告口径交叉核实)';
29
44
  /** 内置典型价目目录(CNY/百万 token)。 */
30
45
  export const PRICE_CATALOG = [
31
46
  {
@@ -100,6 +115,64 @@ export const PRICE_CATALOG = [
100
115
  { key: 'ernie-4.5', label: 'Ernie-4.5', aliases: ['ernie-4.5'], cn: { flat: { inputCacheHit: 0.8, inputMiss: 4, output: 16 } }, asOf: '2026-10-17', source: PEAKREF },
101
116
  { key: 'ernie-4.5-turbo', label: 'Ernie-4.5-Turbo', aliases: ['ernie-4.5-turbo'], cn: { flat: { inputCacheHit: 0.16, inputMiss: 0.8, output: 3.2 } }, asOf: '2026-10-17', source: PEAKREF },
102
117
  { key: 'ernie-x1', label: 'Ernie-X1', aliases: ['ernie-x1'], cn: { flat: { inputCacheHit: 0.4, inputMiss: 2, output: 8 } }, asOf: '2026-10-17', source: PEAKREF },
118
+ // ---- 海外 USD 行(2026-10-18 补录;均无峰谷分时,global 平价) ----
119
+ {
120
+ key: 'claude-fable-5.1', label: 'Claude-Fable-5.1', aliases: ['claude-fable-5.1', 'fable-5.1'],
121
+ global: { flat: { inputCacheHit: 0.25, inputMiss: 10, output: 50 } },
122
+ asOf: '2026-10-18', source: ANOFF,
123
+ },
124
+ {
125
+ key: 'claude-opus-5.5', label: 'Claude-Opus-5.5', aliases: ['claude-opus-5.5', 'opus-5.5'],
126
+ global: { flat: { inputCacheHit: 0.2, inputMiss: 4, output: 20 } },
127
+ asOf: '2026-10-18', source: ANOFF,
128
+ },
129
+ {
130
+ key: 'claude-sonnet-5.5', label: 'Claude-Sonnet-5.5', aliases: ['claude-sonnet-5.5', 'sonnet-5.5'],
131
+ global: { flat: { inputCacheHit: 0.1, inputMiss: 2, output: 10 } },
132
+ asOf: '2026-10-18', source: ANOFF,
133
+ },
134
+ {
135
+ key: 'claude-haiku-5.5', label: 'Claude-Haiku-5.5', aliases: ['claude-haiku-5.5', 'haiku-5.5'],
136
+ // 官方两档价:≤100K prompt 取低档(>100K 为 0.05/0.50/2.50)。
137
+ global: { flat: { inputCacheHit: 0.01, inputMiss: 0.1, output: 0.5 } },
138
+ asOf: '2026-10-18', source: `${ANOFF};>100K prompt 档未录`,
139
+ },
140
+ {
141
+ key: 'gpt-6-astra', label: 'GPT-6-Astra', aliases: ['gpt-6-astra'],
142
+ global: { flat: { inputCacheHit: 1, inputMiss: 10, output: 50 } },
143
+ asOf: '2026-10-18', source: OPAIREF,
144
+ },
145
+ {
146
+ key: 'gpt-6-sol', label: 'GPT-6-Sol', aliases: ['gpt-6-sol'],
147
+ global: { flat: { inputCacheHit: 0.2, inputMiss: 2, output: 10 } },
148
+ asOf: '2026-10-18', source: OPAIREF,
149
+ },
150
+ {
151
+ key: 'gpt-6-luna', label: 'GPT-6-Luna', aliases: ['gpt-6-luna'],
152
+ global: { flat: { inputCacheHit: 0.01, inputMiss: 0.1, output: 0.5 } },
153
+ asOf: '2026-10-18', source: OPAIREF,
154
+ },
155
+ {
156
+ key: 'gpt-6.1-sol', label: 'GPT-6.1-Sol', aliases: ['gpt-6.1-sol'],
157
+ global: { flat: { inputCacheHit: 0.1, inputMiss: 2, output: 10 } },
158
+ asOf: '2026-10-18', source: OPAIREF,
159
+ },
160
+ {
161
+ key: 'gemini-4-argon', label: 'Gemini-4-Argon', aliases: ['gemini-4-argon'],
162
+ // 介绍价至 2026-11-30;届后标准价 $4/$0.20/$20 需改录并重跑 golden。
163
+ global: { flat: { inputCacheHit: 0.1, inputMiss: 2, output: 10 } },
164
+ asOf: '2026-10-18', source: `${GEOREF};介绍价止 2026-11-30,后转 $4/0.20/20`,
165
+ },
166
+ {
167
+ key: 'gemini-3.7-flash', label: 'Gemini-3.7-Flash', aliases: ['gemini-3.7-flash'],
168
+ global: { flat: { inputCacheHit: 0.075, inputMiss: 0.75, output: 3.75 } },
169
+ asOf: '2026-10-18', source: `${GEOREF};促销价止 2026-12-31`,
170
+ },
171
+ {
172
+ key: 'gemini-3.8-flash', label: 'Gemini-3.8-Flash', aliases: ['gemini-3.8-flash'],
173
+ global: { flat: { inputCacheHit: 0.075, inputMiss: 0.75, output: 3.75 } },
174
+ asOf: '2026-10-18', source: `${GEOREF};促销价止 2026-12-31`,
175
+ },
103
176
  ];
104
177
  /**
105
178
  * 中国法定节假日修正表(北京时间 YYYY-MM-DD → isOffDay),2026 年国务院安排
@@ -218,15 +291,22 @@ export function resolveRate(model, provider, timeMs, snapshot) {
218
291
  : snapshot.defaultPricing);
219
292
  const miss = (row) => viaDefault ? { ...row, source: 'catalog-miss' } : row;
220
293
  if (policy === 'off')
221
- return miss({ row: null, tier: null, currency: null, source: 'off', entry, priced: false });
294
+ return miss({ row: null, tier: null, currency: null, source: 'off', entry, priced: false, estimated: false });
222
295
  if (policy === 'custom') {
223
296
  const custom = explicit?.custom;
224
297
  if (custom === undefined)
225
- return miss({ row: null, tier: null, currency: null, source: 'custom', entry, priced: false });
226
- return miss({ row: { inputMiss: custom.inputMiss, inputCacheHit: custom.inputCacheHit, output: custom.output }, tier: 'flat', currency: custom.currency, source: 'custom', entry, priced: true });
298
+ return miss({ row: null, tier: null, currency: null, source: 'custom', entry, priced: false, estimated: false });
299
+ return miss({ row: { inputMiss: custom.inputMiss, inputCacheHit: custom.inputCacheHit, output: custom.output }, tier: 'flat', currency: custom.currency, source: 'custom', entry, priced: true, estimated: false });
300
+ }
301
+ // 目录外 + 非 off/custom 档(缺省 estimate,或显式选 cn/global 校准档),
302
+ // 或显式 estimate 命中目录内(取不到地区行):取典型价兜底估算并标
303
+ // estimated——展示侧带「未校准·仅供参考」,不再显示「未计价」。
304
+ // 命中条目但地区无行(如 global 留空期)不回退兜底。
305
+ if (entry === null || policy === 'estimate') {
306
+ return miss({ row: { ...BILLING_FALLBACK.row }, tier: 'flat', currency: BILLING_FALLBACK.currency, source: policy, entry, priced: true, estimated: true });
227
307
  }
228
- const picked = entry === null ? null : regionRow(entry, policy, timeMs);
308
+ const picked = regionRow(entry, policy, timeMs);
229
309
  if (picked === null)
230
- return miss({ row: null, tier: null, currency: null, source: policy, entry, priced: false });
231
- return miss({ ...picked, source: policy, entry, priced: true });
310
+ return miss({ row: null, tier: null, currency: null, source: policy, entry, priced: false, estimated: false });
311
+ return miss({ ...picked, source: policy, entry, priced: true, estimated: false });
232
312
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-thinking-levels",
3
- "version": "4.3.2",
3
+ "version": "4.4.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org",
6
6
  "access": "public",