dsh-thinking-levels 4.2.1 → 4.3.1

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
@@ -37,6 +37,7 @@ import type { Context } from '@deepseek-ai/cordis';
37
37
  import type { Volatile } from '@deepseek-ai/cosmokit';
38
38
  import z from '@deepseek-ai/schemastery';
39
39
  import { type EffortId } from './thinking-level.ts';
40
+ import { type PricingPolicy } from './billing-projection.ts';
40
41
  /** One configurer-confirmed capability override for a `provider/model` key. */
41
42
  export interface ModelCapabilityOverride {
42
43
  /** Manual override of the vision-model classification (auto: inputModalities). */
@@ -76,6 +77,11 @@ export interface ThinkingLevelsConfig {
76
77
  takeover: boolean | Volatile<boolean>;
77
78
  /** Configurer-confirmed capability overrides, keyed `provider/model`. */
78
79
  models: Record<string, ModelCapabilityOverride>;
80
+ /**
81
+ * 目录外模型的计价兜底档(price-catalog 未命中时生效):cn/global/custom/off。
82
+ * 缺省 off(未计价,不再拿单一型号价硬算);目录内模型自动按条目地区计价。
83
+ */
84
+ defaultPricing: PricingPolicy | Volatile<PricingPolicy>;
79
85
  }
80
86
  /**
81
87
  * Composition-entry schema: what a dsh profile may configure at assembly
@@ -90,6 +96,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
90
96
  allowDowngrade: z<boolean, boolean, "volatile-defined">;
91
97
  allowUpgrade: z<boolean, boolean, "volatile-defined">;
92
98
  takeover: z<boolean, boolean, "volatile-defined">;
99
+ defaultPricing: z<"cn" | "global" | "custom" | "off", "cn" | "global" | "custom" | "off", "volatile-defined">;
93
100
  models: z<import("@deepseek-ai/cosmokit").Dict<{
94
101
  vision?: boolean | null | undefined;
95
102
  thinking?: boolean | null | undefined;
@@ -107,6 +114,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
107
114
  allowDowngrade: z<boolean, boolean, "volatile-defined">;
108
115
  allowUpgrade: z<boolean, boolean, "volatile-defined">;
109
116
  takeover: z<boolean, boolean, "volatile-defined">;
117
+ defaultPricing: z<"cn" | "global" | "custom" | "off", "cn" | "global" | "custom" | "off", "volatile-defined">;
110
118
  models: z<import("@deepseek-ai/cosmokit").Dict<{
111
119
  vision?: boolean | null | undefined;
112
120
  thinking?: boolean | null | undefined;
@@ -132,6 +140,7 @@ export declare const LegacyConfig: z<Schemastery.ObjectS<NoInfer<{
132
140
  allowDowngrade: z<boolean, boolean, "defined">;
133
141
  allowUpgrade: z<boolean, boolean, "defined">;
134
142
  takeover: z<boolean, boolean, "defined">;
143
+ defaultPricing: z<"cn" | "global" | "custom" | "off", "cn" | "global" | "custom" | "off", "defined">;
135
144
  models: z<import("@deepseek-ai/cosmokit").Dict<{
136
145
  vision?: boolean | null | undefined;
137
146
  thinking?: boolean | null | undefined;
@@ -149,6 +158,7 @@ export declare const LegacyConfig: z<Schemastery.ObjectS<NoInfer<{
149
158
  allowDowngrade: z<boolean, boolean, "defined">;
150
159
  allowUpgrade: z<boolean, boolean, "defined">;
151
160
  takeover: z<boolean, boolean, "defined">;
161
+ defaultPricing: z<"cn" | "global" | "custom" | "off", "cn" | "global" | "custom" | "off", "defined">;
152
162
  models: z<import("@deepseek-ai/cosmokit").Dict<{
153
163
  vision?: boolean | null | undefined;
154
164
  thinking?: boolean | null | undefined;
package/lib/index.js CHANGED
@@ -15,6 +15,8 @@ const modelsSchema = z.dict(z.object({
15
15
  efforts: z.union([z.const(false), z.array(effortId)]),
16
16
  contextWindow: z.number().step(1).min(CONTEXT_WINDOW_MIN).max(CONTEXT_WINDOW_MAX),
17
17
  })).default({});
18
+ /** 计价兜底档:schemastery 枚举,两代 schema 共享(the two must never drift)。 */
19
+ const defaultPricingSchema = z.union(['cn', 'global', 'custom', 'off']).default('off');
18
20
  /**
19
21
  * Composition-entry schema: what a dsh profile may configure at assembly
20
22
  * time (cordis.yml `config:` of the plugin row). The same schema doubles as
@@ -28,6 +30,7 @@ export const Config = z.object({
28
30
  allowDowngrade: z.boolean().default(true).volatile(),
29
31
  allowUpgrade: z.boolean().default(false).volatile(),
30
32
  takeover: z.boolean().default(false).volatile(),
33
+ defaultPricing: defaultPricingSchema.volatile(),
31
34
  models: modelsSchema,
32
35
  });
33
36
  /**
@@ -43,6 +46,7 @@ export const LegacyConfig = z.object({
43
46
  allowDowngrade: z.boolean().default(true),
44
47
  allowUpgrade: z.boolean().default(false),
45
48
  takeover: z.boolean().default(false),
49
+ defaultPricing: defaultPricingSchema,
46
50
  models: modelsSchema,
47
51
  });
48
52
  /** Settings defaults, kept in lockstep with the schema defaults above. */
@@ -52,6 +56,7 @@ export const DEFAULT_CONFIG = {
52
56
  allowDowngrade: true,
53
57
  allowUpgrade: false,
54
58
  takeover: false,
59
+ defaultPricing: 'off',
55
60
  models: {},
56
61
  };
57
62
  /**
@@ -79,6 +84,7 @@ function resolveLiveConfig(config) {
79
84
  allowDowngrade: readVolatile(config.allowDowngrade, true),
80
85
  allowUpgrade: readVolatile(config.allowUpgrade, false),
81
86
  takeover: readVolatile(config.takeover, false),
87
+ defaultPricing: readVolatile(config.defaultPricing, 'off'),
82
88
  models: config.models,
83
89
  };
84
90
  }
@@ -313,18 +319,24 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
313
319
  let source = () => config;
314
320
  installLegacySection(ctx, config, { setSource: (next) => { source = next; } });
315
321
  ctx.inject?.(['sessionProjections'], (scope) => {
316
- const def = buildBillingDefinition();
317
- // 0.1.0-rc.8 是唯一的旧平面契约 registry(snapshot 走 def.schema.parse(def.view(state)),
318
- // 0.1.1+ 全线是 stateSchema/wire 新契约)。旧 registry 对缺 schema 的单元直接
319
- // 「Cannot read properties of undefined (reading 'parse')」——一颗单元毒化全部
320
- // 冷会话历史加载(2026-10-08 五格实证)。镜像 wire 形状为平面键,两代 registry
321
- // 各取所需;新契约线多出的两个键无人消费,行为不变。
322
- const wire = def.wire;
323
- if (wire && def.schema === undefined) {
324
- def.schema = wire.viewSchema;
325
- def.view = wire.view;
322
+ // 注册失败只掉账单面(warn + 隐藏),不得毒化整个插件 fiber(takeover 主面)。
323
+ try {
324
+ const def = buildBillingDefinition(() => ({ defaultPricing: resolveLiveConfig(source()).defaultPricing }));
325
+ // 0.1.0-rc.8 是唯一的旧平面契约 registry(snapshot 走 def.schema.parse(def.view(state)),
326
+ // 0.1.1+ 全线是 stateSchema/wire 新契约)。旧 registry 对缺 schema 的单元直接
327
+ // 「Cannot read properties of undefined (reading 'parse')」——一颗单元毒化全部
328
+ // 冷会话历史加载(2026-10-08 五格实证)。镜像 wire 形状为平面键,两代 registry
329
+ // 各取所需;新契约线多出的两个键无人消费,行为不变。
330
+ const wire = def.wire;
331
+ if (wire && def.schema === undefined) {
332
+ def.schema = wire.viewSchema;
333
+ def.view = wire.view;
334
+ }
335
+ scope.sessionProjections?.register(def);
336
+ }
337
+ catch (error) {
338
+ console.warn(`[dsh-thinking-levels] tlCacheBilling register failed (billing section stays hidden): ${error instanceof Error ? error.message : String(error)}`);
326
339
  }
327
- scope.sessionProjections?.register(def);
328
340
  });
329
341
  const current = () => resolveLiveConfig(source());
330
342
  ctx.on('loader/volatile-update', () => {
@@ -0,0 +1,102 @@
1
+ /**
2
+ * TL price catalog (`tlPriceCatalog`) — the single source of pricing truth.
3
+ *
4
+ * 目录化改造 T1:把 billing-projection 硬编码的 Flash 单表升级为「模型 × 地区」
5
+ * 典型价目目录。三价目位统一口径 inputMiss(非缓存输入)/ inputCacheHit(缓存
6
+ * 命中输入)/ output,单位 每百万 token;币种按目录原样(cn=CNY、global=USD),
7
+ * 不做汇率折算。
8
+ *
9
+ * 数据来源(真实取值口径):
10
+ * - deepseek-v4.1-flash 行:迁移自 4.2.1 BILLING_MODEL(官方定价页,原复核日期
11
+ * 未记载,随本次目录化补记 2026-10-17);
12
+ * - deepseek-v4-* 峰谷行:镜像 .peakref companion price/service.js BUILTIN_SHEET
13
+ * (官方定价页 2026-08-14 快照,2026-08-17 起峰谷分时;峰窗 09-12/14-18 北京);
14
+ * - 国内厂商 flat 行:镜像 .peakref companion price/catalog.js CATALOG_TABLE
15
+ * (各官方定价页人民币站低档价快照;免费行照录 0);
16
+ * - 海外 USD 行:本轮网络侧无法核实(OpenAI 403 / Google 超时 / Anthropic 页无
17
+ * API 表),结构留位、数值留空——宁缺毋伪,核实通道到位后走 golden 门禁补录。
18
+ *
19
+ * 判定链:策略 key 特异性(provider/model > model > provider > *)→ 目录命中
20
+ * (精确 > 最长后缀 > 最长包含)→ 目录外走 snapshot.defaultPricing(缺省 off,
21
+ * source 记 'catalog-miss')。节假日/补班修正表随 isPeakBeijing 一并迁入,
22
+ * billing-projection 只负责记账,不再持有价格与日历。
23
+ * @module dsh-thinking-levels/price-catalog
24
+ */
25
+ /** 币种:目录原样,不折算。 */
26
+ export type Currency = 'CNY' | 'USD';
27
+ /** 三价目位(每百万 token)。 */
28
+ export interface PriceRow {
29
+ inputMiss: number;
30
+ inputCacheHit: number;
31
+ output: number;
32
+ }
33
+ /** 每 API 计价策略四档。 */
34
+ export type PricingPolicy = 'cn' | 'global' | 'custom' | 'off';
35
+ /** 生效来源:四档 + 目录外兜底标记。 */
36
+ export type PricingSource = PricingPolicy | 'catalog-miss';
37
+ /** 峰/谷/平三态;平价条目(无峰谷官方价)与 custom 档用 flat。 */
38
+ export type Tier = 'peak' | 'offPeak' | 'flat';
39
+ /** 自填整行替换价(custom 档携带)。 */
40
+ export interface CustomPrices extends PriceRow {
41
+ currency: Currency;
42
+ }
43
+ /** 一条 API 级策略。 */
44
+ export interface PolicyEntry {
45
+ policy: PricingPolicy;
46
+ custom?: CustomPrices;
47
+ }
48
+ /** 计价快照:投影按事件时刻现读(设置派生),policies/custom 为策略面前置位。 */
49
+ export interface PricingSnapshot {
50
+ defaultPricing: PricingPolicy;
51
+ policies?: Readonly<Record<string, PolicyEntry>>;
52
+ }
53
+ /** 目录条目:cn 为 峰谷对 或 平价行;global 预留平价(当前留空)。 */
54
+ export interface CatalogEntry {
55
+ key: string;
56
+ label: string;
57
+ aliases: readonly string[];
58
+ cn?: {
59
+ peak: PriceRow;
60
+ offPeak: PriceRow;
61
+ } | {
62
+ flat: PriceRow;
63
+ };
64
+ global?: {
65
+ flat: PriceRow;
66
+ };
67
+ /** 复核日期(YYYY-MM-DD)。 */
68
+ asOf: string;
69
+ /** 来源标注(官方定价页或仓内镜像快照路径)。 */
70
+ source: string;
71
+ }
72
+ /** 目录版本(进解析缓存键与审计)。 */
73
+ export declare const CATALOG_VERSION = 1;
74
+ /** 内置典型价目目录(CNY/百万 token)。 */
75
+ export declare const PRICE_CATALOG: readonly CatalogEntry[];
76
+ /**
77
+ * 中国法定节假日修正表(北京时间 YYYY-MM-DD → isOffDay),2026 年国务院安排
78
+ * (holiday-cn 定稿 39 条 = 33 放假日 + 6 调休补班日,与 dsh-session-guard
79
+ * BUILTIN_2026 同源同构):true = 放假日(含落工作日的法定假);false = 调休
80
+ * 补班日(落周末但按工作日计价)。表外日期回退自然周末;表外年份退化为只认周末。
81
+ */
82
+ export declare const HOLIDAY_TABLE_2026: ReadonlyMap<string, boolean>;
83
+ /** 按年索引的修正表(新定稿年份在此追加;2027 待国务院公告后补录)。 */
84
+ export declare const HOLIDAY_TABLES: ReadonlyMap<number, ReadonlyMap<string, boolean>>;
85
+ /** 北京日期是否为工作日:表内条目定乾坤(放假=非工作,补班=工作),表外回退自然周末。 */
86
+ export declare function isWorkdayBeijing(shifted: Date, ymd: string): boolean;
87
+ /** 时刻是否为北京高峰。UTC+8 纯数学换算;无效时间戳用 getUTC* 拼串不抛错。 */
88
+ export declare function isPeakBeijing(timeMs: number): boolean;
89
+ /** 目录匹配:全表精确 > 最长后缀 > 最长包含(沿用 rateOf 三级语义,扩到全目录)。 */
90
+ export declare function findEntry(model: string | null): CatalogEntry | null;
91
+ /** 解析结果:null 行 = 不计价(priced=false 恒随 row==null)。 */
92
+ export interface ResolvedRate {
93
+ row: PriceRow | null;
94
+ tier: Tier | null;
95
+ currency: Currency | null;
96
+ /** 生效来源;目录外兜底记 'catalog-miss'。 */
97
+ source: PricingSource;
98
+ entry: CatalogEntry | null;
99
+ priced: boolean;
100
+ }
101
+ /** 唯一计价解析出口。目录命中且无显式策略时取条目自身地区(cn 优先,仅 global 取 global)。 */
102
+ export declare function resolveRate(model: string | null, provider: string | null, timeMs: number, snapshot: PricingSnapshot): ResolvedRate;
@@ -0,0 +1,232 @@
1
+ /**
2
+ * TL price catalog (`tlPriceCatalog`) — the single source of pricing truth.
3
+ *
4
+ * 目录化改造 T1:把 billing-projection 硬编码的 Flash 单表升级为「模型 × 地区」
5
+ * 典型价目目录。三价目位统一口径 inputMiss(非缓存输入)/ inputCacheHit(缓存
6
+ * 命中输入)/ output,单位 每百万 token;币种按目录原样(cn=CNY、global=USD),
7
+ * 不做汇率折算。
8
+ *
9
+ * 数据来源(真实取值口径):
10
+ * - deepseek-v4.1-flash 行:迁移自 4.2.1 BILLING_MODEL(官方定价页,原复核日期
11
+ * 未记载,随本次目录化补记 2026-10-17);
12
+ * - deepseek-v4-* 峰谷行:镜像 .peakref companion price/service.js BUILTIN_SHEET
13
+ * (官方定价页 2026-08-14 快照,2026-08-17 起峰谷分时;峰窗 09-12/14-18 北京);
14
+ * - 国内厂商 flat 行:镜像 .peakref companion price/catalog.js CATALOG_TABLE
15
+ * (各官方定价页人民币站低档价快照;免费行照录 0);
16
+ * - 海外 USD 行:本轮网络侧无法核实(OpenAI 403 / Google 超时 / Anthropic 页无
17
+ * API 表),结构留位、数值留空——宁缺毋伪,核实通道到位后走 golden 门禁补录。
18
+ *
19
+ * 判定链:策略 key 特异性(provider/model > model > provider > *)→ 目录命中
20
+ * (精确 > 最长后缀 > 最长包含)→ 目录外走 snapshot.defaultPricing(缺省 off,
21
+ * source 记 'catalog-miss')。节假日/补班修正表随 isPeakBeijing 一并迁入,
22
+ * billing-projection 只负责记账,不再持有价格与日历。
23
+ * @module dsh-thinking-levels/price-catalog
24
+ */
25
+ /** 目录版本(进解析缓存键与审计)。 */
26
+ export const CATALOG_VERSION = 1;
27
+ const PEAKOFF = 'DeepSeek 官方峰谷分时(峰窗 09-12/14-18 北京;源 api-docs.deepseek.com/zh-cn/quick_start/pricing/)';
28
+ const PEAKREF = '镜像 .peakref/companion/lib/core/price/catalog.js 官方页快照(低档价)';
29
+ /** 内置典型价目目录(CNY/百万 token)。 */
30
+ export const PRICE_CATALOG = [
31
+ {
32
+ key: 'deepseek-v4.1-flash',
33
+ label: 'DeepSeek-V4.1-Flash',
34
+ aliases: ['deepseek-v4.1-flash', 'deepseek-flash'],
35
+ cn: { peak: { inputCacheHit: 0.04, inputMiss: 2, output: 8 }, offPeak: { inputCacheHit: 0.02, inputMiss: 1, output: 4 } },
36
+ asOf: '2026-10-17',
37
+ source: `迁移自 4.2.1 BILLING_MODEL;${PEAKOFF}`,
38
+ },
39
+ {
40
+ key: 'deepseek-v4-flash',
41
+ label: 'DeepSeek-V4-Flash',
42
+ aliases: ['deepseek-v4-flash', 'deepseek-v4-flash-vision-exp'],
43
+ cn: { peak: { inputCacheHit: 0.1, inputMiss: 3, output: 9 }, offPeak: { inputCacheHit: 0.05, inputMiss: 1.5, output: 4.5 } },
44
+ asOf: '2026-08-14',
45
+ source: PEAKOFF,
46
+ },
47
+ {
48
+ key: 'deepseek-v4-pro',
49
+ label: 'DeepSeek-V4-Pro',
50
+ aliases: ['deepseek-v4-pro'],
51
+ cn: { peak: { inputCacheHit: 0.3, inputMiss: 9, output: 27 }, offPeak: { inputCacheHit: 0.15, inputMiss: 4.5, output: 13.5 } },
52
+ asOf: '2026-08-14',
53
+ source: PEAKOFF,
54
+ },
55
+ {
56
+ key: 'deepseek-chat',
57
+ label: 'DeepSeek-Chat',
58
+ aliases: ['deepseek-chat'],
59
+ cn: { flat: { inputCacheHit: 0.5, inputMiss: 2, output: 8 } },
60
+ asOf: '2026-10-17',
61
+ source: '镜像 peakref BUILTIN_SHEET.current(插件原静态表)',
62
+ },
63
+ {
64
+ key: 'deepseek-coder',
65
+ label: 'DeepSeek-Coder',
66
+ aliases: ['deepseek-coder'],
67
+ // 官方未公布 coder 缓存价:命中按普通输入价。
68
+ cn: { flat: { inputCacheHit: 4, inputMiss: 4, output: 12 } },
69
+ asOf: '2026-10-17',
70
+ source: '镜像 peakref BUILTIN_SHEET.current(缓存价未公布,命中=输入价)',
71
+ },
72
+ // ---- 智谱 GLM(bigmodel 低价档) ----
73
+ { key: 'glm-5.2', label: 'GLM-5.2', aliases: ['glm-5.2'], cn: { flat: { inputCacheHit: 2, inputMiss: 8, output: 28 } }, asOf: '2026-10-17', source: PEAKREF },
74
+ { key: 'glm-5.1', label: 'GLM-5.1', aliases: ['glm-5.1'], cn: { flat: { inputCacheHit: 1.3, inputMiss: 6, output: 24 } }, asOf: '2026-10-17', source: PEAKREF },
75
+ { key: 'glm-5', label: 'GLM-5', aliases: ['glm-5'], cn: { flat: { inputCacheHit: 0.8, inputMiss: 4, output: 18 } }, asOf: '2026-10-17', source: PEAKREF },
76
+ { key: 'glm-4.7', label: 'GLM-4.7', aliases: ['glm-4.7'], cn: { flat: { inputCacheHit: 0.4, inputMiss: 2, output: 8 } }, asOf: '2026-10-17', source: PEAKREF },
77
+ { key: 'glm-4.6', label: 'GLM-4.6', aliases: ['glm-4.6'], cn: { flat: { inputCacheHit: 1, inputMiss: 5, output: 5 } }, asOf: '2026-10-17', source: PEAKREF },
78
+ { key: 'glm-4.5-air', label: 'GLM-4.5-Air', aliases: ['glm-4.5-air'], cn: { flat: { inputCacheHit: 0.16, inputMiss: 0.8, output: 2 } }, asOf: '2026-10-17', source: PEAKREF },
79
+ // ---- 月之暗面 Kimi(人民币站) ----
80
+ { key: 'kimi-k2.7-code-highspeed', label: 'Kimi-K2.7-Code-HighSpeed', aliases: ['kimi-k2.7-code-highspeed'], cn: { flat: { inputCacheHit: 2.6, inputMiss: 13, output: 54 } }, asOf: '2026-10-17', source: PEAKREF },
81
+ { key: 'kimi-k2.7-code', label: 'Kimi-K2.7-Code', aliases: ['kimi-k2.7-code'], cn: { flat: { inputCacheHit: 1.3, inputMiss: 6.5, output: 27 } }, asOf: '2026-10-17', source: PEAKREF },
82
+ { key: 'kimi-k2.6', label: 'Kimi-K2.6', aliases: ['kimi-k2.6'], cn: { flat: { inputCacheHit: 1.1, inputMiss: 6.5, output: 27 } }, asOf: '2026-10-17', source: PEAKREF },
83
+ { key: 'kimi-k2.5', label: 'Kimi-K2.5', aliases: ['kimi-k2.5'], cn: { flat: { inputCacheHit: 0.7, inputMiss: 4, output: 21 } }, asOf: '2026-10-17', source: PEAKREF },
84
+ // ---- 阿里通义千问(百炼中国内地低档) ----
85
+ { key: 'qwen3-max', label: 'Qwen3-Max', aliases: ['qwen3-max'], cn: { flat: { inputCacheHit: 0.5, inputMiss: 2.5, output: 10 } }, asOf: '2026-10-17', source: PEAKREF },
86
+ { key: 'qwen3-coder-plus', label: 'Qwen3-Coder-Plus', aliases: ['qwen3-coder-plus'], cn: { flat: { inputCacheHit: 0.2, inputMiss: 1, output: 4 } }, asOf: '2026-10-17', source: PEAKREF },
87
+ { key: 'qwen3-plus', label: 'Qwen3-Plus', aliases: ['qwen3-plus', 'qwen-plus'], cn: { flat: { inputCacheHit: 0.16, inputMiss: 0.8, output: 2 } }, asOf: '2026-10-17', source: PEAKREF },
88
+ { key: 'qwen3-flash', label: 'Qwen3-Flash', aliases: ['qwen3-flash', 'qwen-flash'], cn: { flat: { inputCacheHit: 0.03, inputMiss: 0.15, output: 1.5 } }, asOf: '2026-10-17', source: PEAKREF },
89
+ { key: 'qwen-turbo', label: 'Qwen-Turbo', aliases: ['qwen-turbo'], cn: { flat: { inputCacheHit: 0.06, inputMiss: 0.3, output: 0.6 } }, asOf: '2026-10-17', source: PEAKREF },
90
+ // ---- 字节豆包(火山方舟输入 0-32K 档) ----
91
+ { key: 'doubao-seed-2.1-pro', label: 'Doubao-Seed-2.1-Pro', aliases: ['doubao-seed-2.1-pro'], cn: { flat: { inputCacheHit: 1.2, inputMiss: 6, output: 30 } }, asOf: '2026-10-17', source: PEAKREF },
92
+ { key: 'doubao-seed-2.1-turbo', label: 'Doubao-Seed-2.1-Turbo', aliases: ['doubao-seed-2.1-turbo'], cn: { flat: { inputCacheHit: 0.6, inputMiss: 3, output: 15 } }, asOf: '2026-10-17', source: PEAKREF },
93
+ { key: 'doubao-seed-2.0-mini', label: 'Doubao-Seed-2.0-Mini', aliases: ['doubao-seed-2.0-mini'], cn: { flat: { inputCacheHit: 0.04, inputMiss: 0.2, output: 2 } }, asOf: '2026-10-17', source: PEAKREF },
94
+ // ---- MiniMax(按量计费) ----
95
+ { key: 'minimax-m2.7-highspeed', label: 'MiniMax-M2.7-HighSpeed', aliases: ['minimax-m2.7-highspeed'], cn: { flat: { inputCacheHit: 0.42, inputMiss: 4.2, output: 16.8 } }, asOf: '2026-10-17', source: PEAKREF },
96
+ { key: 'minimax-m3', label: 'MiniMax-M3', aliases: ['minimax-m3'], cn: { flat: { inputCacheHit: 0.42, inputMiss: 2.1, output: 8.4 } }, asOf: '2026-10-17', source: `${PEAKREF}(≤512K 永久五折后)` },
97
+ { key: 'minimax-m2.7', label: 'MiniMax-M2.7', aliases: ['minimax-m2.7'], cn: { flat: { inputCacheHit: 0.42, inputMiss: 2.1, output: 8.4 } }, asOf: '2026-10-17', source: PEAKREF },
98
+ { key: 'minimax-m2.5', label: 'MiniMax-M2.5', aliases: ['minimax-m2.5'], cn: { flat: { inputCacheHit: 0.21, inputMiss: 2.1, output: 8.4 } }, asOf: '2026-10-17', source: PEAKREF },
99
+ // ---- 百度文心(千帆) ----
100
+ { 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
+ { 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
+ { key: 'ernie-x1', label: 'Ernie-X1', aliases: ['ernie-x1'], cn: { flat: { inputCacheHit: 0.4, inputMiss: 2, output: 8 } }, asOf: '2026-10-17', source: PEAKREF },
103
+ ];
104
+ /**
105
+ * 中国法定节假日修正表(北京时间 YYYY-MM-DD → isOffDay),2026 年国务院安排
106
+ * (holiday-cn 定稿 39 条 = 33 放假日 + 6 调休补班日,与 dsh-session-guard
107
+ * BUILTIN_2026 同源同构):true = 放假日(含落工作日的法定假);false = 调休
108
+ * 补班日(落周末但按工作日计价)。表外日期回退自然周末;表外年份退化为只认周末。
109
+ */
110
+ export const HOLIDAY_TABLE_2026 = new Map([
111
+ // 元旦
112
+ ['2026-01-01', true], ['2026-01-02', true], ['2026-01-03', true], ['2026-01-04', false],
113
+ // 春节
114
+ ['2026-02-14', false],
115
+ ['2026-02-15', true], ['2026-02-16', true], ['2026-02-17', true], ['2026-02-18', true],
116
+ ['2026-02-19', true], ['2026-02-20', true], ['2026-02-21', true], ['2026-02-22', true],
117
+ ['2026-02-23', true], ['2026-02-28', false],
118
+ // 清明
119
+ ['2026-04-04', true], ['2026-04-05', true], ['2026-04-06', true],
120
+ // 劳动节
121
+ ['2026-05-01', true], ['2026-05-02', true], ['2026-05-03', true], ['2026-05-04', true],
122
+ ['2026-05-05', true], ['2026-05-09', false],
123
+ // 端午
124
+ ['2026-06-19', true], ['2026-06-20', true], ['2026-06-21', true],
125
+ // 中秋
126
+ ['2026-09-20', false], ['2026-09-25', true], ['2026-09-26', true], ['2026-09-27', true],
127
+ // 国庆
128
+ ['2026-10-01', true], ['2026-10-02', true], ['2026-10-03', true], ['2026-10-04', true],
129
+ ['2026-10-05', true], ['2026-10-06', true], ['2026-10-07', true], ['2026-10-10', false],
130
+ ]);
131
+ /** 按年索引的修正表(新定稿年份在此追加;2027 待国务院公告后补录)。 */
132
+ export const HOLIDAY_TABLES = new Map([
133
+ [2026, HOLIDAY_TABLE_2026],
134
+ ]);
135
+ /** 北京日期是否为工作日:表内条目定乾坤(放假=非工作,补班=工作),表外回退自然周末。 */
136
+ export function isWorkdayBeijing(shifted, ymd) {
137
+ const correction = HOLIDAY_TABLES.get(shifted.getUTCFullYear())?.get(ymd);
138
+ if (correction !== undefined)
139
+ return !correction;
140
+ const day = shifted.getUTCDay();
141
+ return day !== 0 && day !== 6;
142
+ }
143
+ /** 时刻是否为北京高峰。UTC+8 纯数学换算;无效时间戳用 getUTC* 拼串不抛错。 */
144
+ export function isPeakBeijing(timeMs) {
145
+ const shifted = new Date(timeMs + 8 * 3600 * 1000);
146
+ const month = String(shifted.getUTCMonth() + 1).padStart(2, '0');
147
+ const dayOfMonth = String(shifted.getUTCDate()).padStart(2, '0');
148
+ const ymd = `${shifted.getUTCFullYear()}-${month}-${dayOfMonth}`;
149
+ if (!isWorkdayBeijing(shifted, ymd))
150
+ return false;
151
+ const hour = shifted.getUTCHours();
152
+ return (hour >= 9 && hour < 12) || (hour >= 14 && hour < 18);
153
+ }
154
+ const lower = (s) => (s ?? '').trim().toLowerCase();
155
+ /** 目录匹配:全表精确 > 最长后缀 > 最长包含(沿用 rateOf 三级语义,扩到全目录)。 */
156
+ export function findEntry(model) {
157
+ const key = lower(model);
158
+ if (key === '')
159
+ return null;
160
+ let suffix = null;
161
+ let suffixLen = 0;
162
+ let contains = null;
163
+ let containsLen = 0;
164
+ for (const entry of PRICE_CATALOG) {
165
+ for (const alias of entry.aliases) {
166
+ if (key === alias)
167
+ return entry;
168
+ if (key.endsWith(alias) && alias.length > suffixLen) {
169
+ suffix = entry;
170
+ suffixLen = alias.length;
171
+ }
172
+ if (key.includes(alias) && alias.length > containsLen) {
173
+ contains = entry;
174
+ containsLen = alias.length;
175
+ }
176
+ }
177
+ }
178
+ return suffix ?? contains;
179
+ }
180
+ /** 条目是否有峰谷对。 */
181
+ const hasPeak = (cn) => 'peak' in cn;
182
+ /** 从目录条目按地区取行。 */
183
+ function regionRow(entry, region, timeMs) {
184
+ if (region === 'cn') {
185
+ const cn = entry.cn;
186
+ if (cn === undefined)
187
+ return null;
188
+ if (hasPeak(cn)) {
189
+ const peak = isPeakBeijing(timeMs);
190
+ return { row: peak ? cn.peak : cn.offPeak, tier: peak ? 'peak' : 'offPeak', currency: 'CNY' };
191
+ }
192
+ return { row: cn.flat, tier: 'flat', currency: 'CNY' };
193
+ }
194
+ const g = entry.global;
195
+ if (g === undefined)
196
+ return null;
197
+ return { row: g.flat, tier: 'flat', currency: 'USD' };
198
+ }
199
+ /** 策略 key 匹配:provider/model > model > provider > *。 */
200
+ function policyFor(provider, model, policies) {
201
+ if (policies === undefined)
202
+ return undefined;
203
+ const p = lower(provider);
204
+ const m = lower(model);
205
+ return (p !== '' && m !== '' ? policies[`${p}/${m}`] : undefined)
206
+ ?? (m !== '' ? policies[m] : undefined)
207
+ ?? (p !== '' ? policies[p] : undefined)
208
+ ?? policies['*'];
209
+ }
210
+ /** 唯一计价解析出口。目录命中且无显式策略时取条目自身地区(cn 优先,仅 global 取 global)。 */
211
+ export function resolveRate(model, provider, timeMs, snapshot) {
212
+ const entry = findEntry(model);
213
+ const explicit = policyFor(provider, model, snapshot.policies);
214
+ const viaDefault = entry === null && explicit === undefined;
215
+ const policy = explicit?.policy
216
+ ?? (entry !== undefined && entry !== null
217
+ ? (entry.cn !== undefined ? 'cn' : 'global')
218
+ : snapshot.defaultPricing);
219
+ const miss = (row) => viaDefault ? { ...row, source: 'catalog-miss' } : row;
220
+ if (policy === 'off')
221
+ return miss({ row: null, tier: null, currency: null, source: 'off', entry, priced: false });
222
+ if (policy === 'custom') {
223
+ const custom = explicit?.custom;
224
+ 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 });
227
+ }
228
+ const picked = entry === null ? null : regionRow(entry, policy, timeMs);
229
+ 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 });
232
+ }
@@ -30,6 +30,13 @@ export interface SectionReadout<T = unknown> {
30
30
  value: T;
31
31
  revision: number;
32
32
  }
33
+ /**
34
+ * 形状归一(唯一一处 unwrap):进程内 `describe()` 交回描述符数组;Remote/RPC
35
+ * 信封交回 `{writable, hasDocument, namespaces:[…]}`。其余形状(含 undefined)
36
+ * 一律当「不可用」返回 undefined,不得让 `find is not a function` 这类
37
+ * TypeError 泄到调用方被 catch 吞成静默冻结(同生态 fail-open 坑先例)。
38
+ */
39
+ export declare function normalizeDescriptors(raw: unknown): SettingsDescriptorLike[] | undefined;
33
40
  /** One `describe()` pass over the live settings, or `undefined` when the service is absent. */
34
41
  export declare function describeSettings(ctx: Context): SettingsDescriptorLike[] | undefined;
35
42
  /**
@@ -1,7 +1,22 @@
1
+ /**
2
+ * 形状归一(唯一一处 unwrap):进程内 `describe()` 交回描述符数组;Remote/RPC
3
+ * 信封交回 `{writable, hasDocument, namespaces:[…]}`。其余形状(含 undefined)
4
+ * 一律当「不可用」返回 undefined,不得让 `find is not a function` 这类
5
+ * TypeError 泄到调用方被 catch 吞成静默冻结(同生态 fail-open 坑先例)。
6
+ */
7
+ export function normalizeDescriptors(raw) {
8
+ if (Array.isArray(raw))
9
+ return raw;
10
+ const wrapped = raw;
11
+ if (wrapped !== null && typeof wrapped === 'object' && Array.isArray(wrapped.namespaces)) {
12
+ return wrapped.namespaces;
13
+ }
14
+ return undefined;
15
+ }
1
16
  /** One `describe()` pass over the live settings, or `undefined` when the service is absent. */
2
17
  export function describeSettings(ctx) {
3
18
  const settings = ctx.get('settings');
4
- return settings?.describe?.();
19
+ return normalizeDescriptors(settings?.describe?.());
5
20
  }
6
21
  /**
7
22
  * Read one namespace's live section. `undefined` when the settings service is
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-thinking-levels",
3
- "version": "4.2.1",
3
+ "version": "4.3.1",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org",
6
6
  "access": "public",
@@ -46,17 +46,17 @@
46
46
  },
47
47
  "engines": {
48
48
  "node": ">=22.19.0 || >=24.0.0",
49
- "dsh": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2"
49
+ "dsh": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@deepseek-ai/cordis": "^4.0.1",
53
- "@deepseek-ai/dsh-api-remotes": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2",
54
- "@deepseek-ai/dsh-api-session-controller": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2",
55
- "@deepseek-ai/dsh-client-locale": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2",
56
- "@deepseek-ai/dsh-client-ui-model-selection": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2",
57
- "@deepseek-ai/dsh-client-ui-renderer": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2",
58
- "@deepseek-ai/dsh-client-ui-settings": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2",
59
- "@deepseek-ai/dsh-client-ui-slots": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2"
53
+ "@deepseek-ai/dsh-api-remotes": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
54
+ "@deepseek-ai/dsh-api-session-controller": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
55
+ "@deepseek-ai/dsh-client-locale": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
56
+ "@deepseek-ai/dsh-client-ui-model-selection": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
57
+ "@deepseek-ai/dsh-client-ui-renderer": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
58
+ "@deepseek-ai/dsh-client-ui-settings": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
59
+ "@deepseek-ai/dsh-client-ui-slots": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1"
60
60
  },
61
61
  "peerDependenciesMeta": {
62
62
  "@deepseek-ai/dsh-api-remotes": {
@@ -88,11 +88,11 @@
88
88
  "devDependencies": {
89
89
  "@deepseek-ai/cordis": "^4.0.4",
90
90
  "@deepseek-ai/cosmokit": "^1.8.5",
91
- "@deepseek-ai/dsh-client-locale": "0.2.0-rc.1",
92
- "@deepseek-ai/dsh-client-store": "0.2.0-rc.1",
93
- "@deepseek-ai/dsh-client-ui-renderer": "0.2.0-rc.1",
94
- "@deepseek-ai/dsh-client-ui-settings": "0.2.0-rc.1",
95
- "@deepseek-ai/dsh-client-ui-slots": "0.2.0-rc.1",
91
+ "@deepseek-ai/dsh-client-locale": "0.2.1-rc.1",
92
+ "@deepseek-ai/dsh-client-store": "0.2.1-rc.1",
93
+ "@deepseek-ai/dsh-client-ui-renderer": "0.2.1-rc.1",
94
+ "@deepseek-ai/dsh-client-ui-settings": "0.2.1-rc.1",
95
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.1-rc.1",
96
96
  "@deepseek-ai/schemastery": "^3.18.4",
97
97
  "@eslint/js": "^10.0.1",
98
98
  "@types/node": "^24.0.0",
@@ -107,6 +107,7 @@
107
107
  },
108
108
  "scripts": {
109
109
  "build": "tsc -p tsconfig.build.json && tsdown",
110
+ "prepack": "npm run build",
110
111
  "prepublishOnly": "npm run build",
111
112
  "release:4x": "npm publish --tag dsh-0.2.0 --registry=https://registry.npmjs.org",
112
113
  "typecheck": "tsc --noEmit",