dsh-layered-memory 0.8.6 → 0.8.8

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/dist/config.d.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  * 默认数据目录:$DSH_HOME/memory(用官方 dshHomePath 解析,DSH_HOME 缺省 ~/.dsh)。
5
5
  */
6
6
  import Schema from '@deepseek-ai/schemastery';
7
+ import type { StaticFallbackEntry } from './contract.js';
7
8
  import type { ExtractMode } from './types.js';
8
9
  /**
9
10
  * 蒸馏思考档位全词汇表(唯一事实源):'' = 自动(模型默认档 → high),
@@ -96,10 +97,19 @@ export interface MemoryConfig {
96
97
  provider: string;
97
98
  /** 蒸馏用的模型;留空用当前默认选择。 */
98
99
  model: string;
100
+ /** 回退链(#31):主路由失败(报错/掐断/网络异常/空输出)后按序降级的备用路由,
101
+ * 条目顺序即优先级。与主路由完全相同的条目自动跳过;provider/model 缺失的条目剔除;
102
+ * 条目 reasoningEffort 非空时覆盖全局档位(未配置运行时链 distillChain 时,
103
+ * 旧档位键 reasoningEffort 的整体接管——含给条目盖章——仍对存量值生效);
104
+ * 空数组(缺省)= 单路由行为不变。 */
105
+ fallbacks?: StaticFallbackEntry[];
99
106
  /** 单次蒸馏调用的输出 token 上限(推理模型的 reasoning 与正文共享该预算)。 */
100
107
  maxTokens: number;
101
108
  /** 蒸馏调用的思考档位;空串不传(跟随模型默认)。 */
102
109
  reasoningEffort: string;
110
+ /** 运行时主路由显式档位(distillChain[0].reasoningEffort 经 effectiveCfg 注入);
111
+ * 非静态 schema——'' = 跟随全局静态 reasoningEffort,仅供链模式传递主路由档位。 */
112
+ primaryEffort?: string;
103
113
  temperature: number;
104
114
  /** 单次蒸馏调用的用户 prompt 字符预算(≈token 数,按中文 1 字≈1 token 保守估算)。 */
105
115
  maxInputChars: number;
@@ -114,6 +124,10 @@ export interface MemoryConfig {
114
124
  l3: number;
115
125
  }>;
116
126
  };
127
+ tokenCost: {
128
+ /** token_cost 明细保留天数;写入时滚动清理更早行。0 = 永久保留。 */
129
+ retentionDays: number;
130
+ };
117
131
  /** 是否注册模型可调用的记忆工具。 */
118
132
  tools: boolean;
119
133
  /** 注册 bench 控制服务(dsh-memory-bench,进程内 rebuild 触发面)。
@@ -171,7 +185,7 @@ export declare const memorySchema: Schema<Schemastery.ObjectS<{
171
185
  timeoutMs: Schema<number, number>;
172
186
  includePersona: Schema<boolean, boolean>;
173
187
  includeSceneNav: Schema<boolean, boolean>;
174
- strategy: Schema<"keyword" | "embedding" | "hybrid", "keyword" | "embedding" | "hybrid">;
188
+ strategy: Schema<"hybrid" | "keyword" | "embedding", "hybrid" | "keyword" | "embedding">;
175
189
  scoreThreshold: Schema<number, number>;
176
190
  decayHalfLifeDays: Schema<number, number>;
177
191
  }>, Schemastery.ObjectT<{
@@ -182,7 +196,7 @@ export declare const memorySchema: Schema<Schemastery.ObjectS<{
182
196
  timeoutMs: Schema<number, number>;
183
197
  includePersona: Schema<boolean, boolean>;
184
198
  includeSceneNav: Schema<boolean, boolean>;
185
- strategy: Schema<"keyword" | "embedding" | "hybrid", "keyword" | "embedding" | "hybrid">;
199
+ strategy: Schema<"hybrid" | "keyword" | "embedding", "hybrid" | "keyword" | "embedding">;
186
200
  scoreThreshold: Schema<number, number>;
187
201
  decayHalfLifeDays: Schema<number, number>;
188
202
  }>>;
@@ -212,6 +226,15 @@ export declare const memorySchema: Schema<Schemastery.ObjectS<{
212
226
  llm: Schema<Schemastery.ObjectS<{
213
227
  provider: Schema<string, string>;
214
228
  model: Schema<string, string>;
229
+ fallbacks: Schema<({
230
+ provider?: string | null | undefined;
231
+ model?: string | null | undefined;
232
+ reasoningEffort?: "" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | null | undefined;
233
+ } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<{
234
+ provider: Schema<string, string>;
235
+ model: Schema<string, string>;
236
+ reasoningEffort: Schema<"" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max", "" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max">;
237
+ }>[]>;
215
238
  maxTokens: Schema<number, number>;
216
239
  reasoningEffort: Schema<"" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max", "" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max">;
217
240
  temperature: Schema<number, number>;
@@ -220,12 +243,26 @@ export declare const memorySchema: Schema<Schemastery.ObjectS<{
220
243
  }>, Schemastery.ObjectT<{
221
244
  provider: Schema<string, string>;
222
245
  model: Schema<string, string>;
246
+ fallbacks: Schema<({
247
+ provider?: string | null | undefined;
248
+ model?: string | null | undefined;
249
+ reasoningEffort?: "" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | null | undefined;
250
+ } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<{
251
+ provider: Schema<string, string>;
252
+ model: Schema<string, string>;
253
+ reasoningEffort: Schema<"" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max", "" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max">;
254
+ }>[]>;
223
255
  maxTokens: Schema<number, number>;
224
256
  reasoningEffort: Schema<"" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max", "" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max">;
225
257
  temperature: Schema<number, number>;
226
258
  maxInputChars: Schema<number, number>;
227
259
  timeoutMs: Schema<number, number>;
228
260
  }>>;
261
+ tokenCost: Schema<Schemastery.ObjectS<{
262
+ retentionDays: Schema<number, number>;
263
+ }>, Schemastery.ObjectT<{
264
+ retentionDays: Schema<number, number>;
265
+ }>>;
229
266
  tools: Schema<boolean, boolean>;
230
267
  benchControl: Schema<boolean, boolean>;
231
268
  }>, Schemastery.ObjectT<{
@@ -279,7 +316,7 @@ export declare const memorySchema: Schema<Schemastery.ObjectS<{
279
316
  timeoutMs: Schema<number, number>;
280
317
  includePersona: Schema<boolean, boolean>;
281
318
  includeSceneNav: Schema<boolean, boolean>;
282
- strategy: Schema<"keyword" | "embedding" | "hybrid", "keyword" | "embedding" | "hybrid">;
319
+ strategy: Schema<"hybrid" | "keyword" | "embedding", "hybrid" | "keyword" | "embedding">;
283
320
  scoreThreshold: Schema<number, number>;
284
321
  decayHalfLifeDays: Schema<number, number>;
285
322
  }>, Schemastery.ObjectT<{
@@ -290,7 +327,7 @@ export declare const memorySchema: Schema<Schemastery.ObjectS<{
290
327
  timeoutMs: Schema<number, number>;
291
328
  includePersona: Schema<boolean, boolean>;
292
329
  includeSceneNav: Schema<boolean, boolean>;
293
- strategy: Schema<"keyword" | "embedding" | "hybrid", "keyword" | "embedding" | "hybrid">;
330
+ strategy: Schema<"hybrid" | "keyword" | "embedding", "hybrid" | "keyword" | "embedding">;
294
331
  scoreThreshold: Schema<number, number>;
295
332
  decayHalfLifeDays: Schema<number, number>;
296
333
  }>>;
@@ -320,6 +357,15 @@ export declare const memorySchema: Schema<Schemastery.ObjectS<{
320
357
  llm: Schema<Schemastery.ObjectS<{
321
358
  provider: Schema<string, string>;
322
359
  model: Schema<string, string>;
360
+ fallbacks: Schema<({
361
+ provider?: string | null | undefined;
362
+ model?: string | null | undefined;
363
+ reasoningEffort?: "" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | null | undefined;
364
+ } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<{
365
+ provider: Schema<string, string>;
366
+ model: Schema<string, string>;
367
+ reasoningEffort: Schema<"" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max", "" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max">;
368
+ }>[]>;
323
369
  maxTokens: Schema<number, number>;
324
370
  reasoningEffort: Schema<"" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max", "" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max">;
325
371
  temperature: Schema<number, number>;
@@ -328,12 +374,26 @@ export declare const memorySchema: Schema<Schemastery.ObjectS<{
328
374
  }>, Schemastery.ObjectT<{
329
375
  provider: Schema<string, string>;
330
376
  model: Schema<string, string>;
377
+ fallbacks: Schema<({
378
+ provider?: string | null | undefined;
379
+ model?: string | null | undefined;
380
+ reasoningEffort?: "" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | null | undefined;
381
+ } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<{
382
+ provider: Schema<string, string>;
383
+ model: Schema<string, string>;
384
+ reasoningEffort: Schema<"" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max", "" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max">;
385
+ }>[]>;
331
386
  maxTokens: Schema<number, number>;
332
387
  reasoningEffort: Schema<"" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max", "" | "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max">;
333
388
  temperature: Schema<number, number>;
334
389
  maxInputChars: Schema<number, number>;
335
390
  timeoutMs: Schema<number, number>;
336
391
  }>>;
392
+ tokenCost: Schema<Schemastery.ObjectS<{
393
+ retentionDays: Schema<number, number>;
394
+ }>, Schemastery.ObjectT<{
395
+ retentionDays: Schema<number, number>;
396
+ }>>;
337
397
  tools: Schema<boolean, boolean>;
338
398
  benchControl: Schema<boolean, boolean>;
339
399
  }>>;
package/dist/config.js CHANGED
@@ -11,6 +11,7 @@ import { dshHomePath } from '@deepseek-ai/dsh-home-paths';
11
11
  * schema(config/settings)、运行时解析(settings.resolveSettings)与 RPC
12
12
  * 写入门(stats.settings-set)共用,勿在别处再抄字面量表。
13
13
  */
14
+ // satisfies 反向锁定:词汇表扩词必须同步契约的 EffortChoice 联合(host 与 TS 化的 client 共用)
14
15
  export const EFFORT_CHOICES = ['', 'off', 'none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
15
16
  export const memorySchema = Schema.object({
16
17
  dataDir: Schema.string().default(''),
@@ -68,6 +69,13 @@ export const memorySchema = Schema.object({
68
69
  llm: Schema.object({
69
70
  provider: Schema.string().default(''),
70
71
  model: Schema.string().default(''),
72
+ // 回退链(#31):主路由失败后按序降级;每条路由各享全额 timeoutMs(慢 TTFT 模型的
73
+ // 回退位正是要给它留足首包时间,共享预算会让回退链失效);条目档位经能力钳制后发送
74
+ fallbacks: Schema.array(Schema.object({
75
+ provider: Schema.string().default(''),
76
+ model: Schema.string().default(''),
77
+ reasoningEffort: Schema.union([...EFFORT_CHOICES]).default(''),
78
+ })).default([]),
71
79
  // 推理模型(如 v4-flash)的 reasoning 计入输出预算:预算不足会被思考吃光导致正文 0 字符。
72
80
  // 0.8.0 起各蒸馏层显式传分层预算(见 llm.ts LAYER_MAX_TOKENS_*),本值为未分层调用的兜底总闸
73
81
  maxTokens: Schema.number().min(1024).max(1_000_000).default(65_536),
@@ -80,6 +88,10 @@ export const memorySchema = Schema.object({
80
88
  maxInputChars: Schema.number().min(1000).max(1_000_000).default(700_000),
81
89
  timeoutMs: Schema.number().min(1000).max(600_000).default(120_000),
82
90
  }),
91
+ // token_cost 明细保留期(写入时滚动清理;0 = 永久保留)。成本看板的「近 N 天」窗口上限也取此值
92
+ tokenCost: Schema.object({
93
+ retentionDays: Schema.number().min(0).max(3650).default(365),
94
+ }),
83
95
  tools: Schema.boolean().default(true),
84
96
  benchControl: Schema.boolean().default(false),
85
97
  });