dsh-mnemon-strategy-default-three-tier 0.5.6 → 0.5.7

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.
@@ -1,24 +1,12 @@
1
- import { MemoryAvailableSource, MemoryJsonValue, MemoryStrategyContribution, MemoryStrategyExtensionDefinition, MemoryViewRequest } from "dsh-mnemon/contracts";
1
+ import { MemoryAvailableSource, MemoryJsonValue, MemoryStrategyContribution, MemoryStrategyExtensionDefinition, MemoryViewExtensionSlot, MemoryViewExtensionValues, MemoryViewRequest } from "dsh-mnemon/contracts";
2
2
  //#region src/extension-sdk.d.ts
3
- /** These slots belong to the three-tier product. Core does not interpret them. */
4
- type ThreeTierExtensionValues = {
5
- selection: {
6
- sourceKeys: string[];
7
- writableSourceKeys?: string[];
8
- };
9
- projection: {
10
- maxProjectionCharacters: number;
11
- };
12
- capture: {
13
- instruction: string;
14
- actionIds: string[];
15
- sourceKeys?: string[];
16
- };
17
- };
18
- type ThreeTierExtensionSlot = keyof ThreeTierExtensionValues;
3
+ /** The three-tier slots are Core's standard View extension slots. */
4
+ type ThreeTierExtensionValues = MemoryViewExtensionValues;
5
+ type ThreeTierExtensionSlot = MemoryViewExtensionSlot;
19
6
  /** Pure default-product policy. The Host executes it through public Source protocols. */
20
7
  declare function threeTierActionWorkflow(strategyTypeId: string, sourceTypeId: string, actionId: string): 'runtime-capacity' | undefined;
21
8
  declare function validateThreeTierExtension<K extends ThreeTierExtensionSlot>(slot: K, value: MemoryJsonValue): ThreeTierExtensionValues[K];
9
+ /** An extension only for this Strategy; `defineMemoryViewExtension` also follows other Strategies. */
22
10
  declare function defineThreeTierExtension<K extends ThreeTierExtensionSlot>(definition: {
23
11
  typeId: string;
24
12
  packageName: string;
@@ -1,46 +1,14 @@
1
- import { defineMemoryStrategyExtension, memoryInputInteger, memoryInputRecord, memoryInputText } from "dsh-mnemon/extension-sdk";
1
+ import { defineMemoryStrategyExtension, memoryViewExtensionValues, validateMemoryViewExtension } from "dsh-mnemon/extension-sdk";
2
2
  import { COMPOSABLE_MEMORY_API_VERSION } from "dsh-mnemon/contracts";
3
3
  //#region src/extension-sdk.ts
4
4
  /** Pure default-product policy. The Host executes it through public Source protocols. */
5
5
  function threeTierActionWorkflow(strategyTypeId, sourceTypeId, actionId) {
6
6
  return strategyTypeId === "default-three-tier" && sourceTypeId === "runtime" && actionId === "mutate" ? "runtime-capacity" : void 0;
7
7
  }
8
- function keys(value, label) {
9
- if (!Array.isArray(value) || value.length > 32 || value.some((key) => typeof key !== "string" || !/^source:[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,292}$/u.test(key))) throw new Error(`${label} must contain at most 32 exact Source instance keys`);
10
- if (new Set(value).size !== value.length) throw new Error(`${label} contains duplicate Source keys`);
11
- return [...value];
12
- }
13
8
  function validateThreeTierExtension(slot, value) {
14
- const input = memoryInputRecord(value, `three-tier ${slot} contribution`);
15
- const allowed = slot === "selection" ? ["sourceKeys", "writableSourceKeys"] : slot === "projection" ? ["maxProjectionCharacters"] : slot === "capture" ? [
16
- "instruction",
17
- "actionIds",
18
- "sourceKeys"
19
- ] : [];
20
- if (allowed.length === 0) throw new Error(`unsupported three-tier extension slot: ${String(slot)}`);
21
- for (const key of Object.keys(input)) if (!allowed.includes(key)) throw new Error(`unsupported three-tier ${slot} field: ${key}`);
22
- let result;
23
- if (slot === "selection") {
24
- const sourceKeys = keys(input.sourceKeys, "sourceKeys");
25
- const writableSourceKeys = input.writableSourceKeys === void 0 ? void 0 : keys(input.writableSourceKeys, "writableSourceKeys");
26
- if (writableSourceKeys?.some((key) => !sourceKeys.includes(key))) throw new Error("writableSourceKeys must be within selected sourceKeys");
27
- result = {
28
- sourceKeys,
29
- ...writableSourceKeys === void 0 ? {} : { writableSourceKeys }
30
- };
31
- } else if (slot === "projection") {
32
- if (input.maxProjectionCharacters === void 0) throw new Error("maxProjectionCharacters is required");
33
- result = { maxProjectionCharacters: memoryInputInteger(input.maxProjectionCharacters, 4096, 1, 1e7) };
34
- } else {
35
- if (!Array.isArray(input.actionIds) || input.actionIds.length === 0 || input.actionIds.length > 32 || input.actionIds.some((id) => typeof id !== "string" || !/^[a-z][a-z0-9-]{0,127}$/u.test(id)) || new Set(input.actionIds).size !== input.actionIds.length) throw new Error("capture actionIds must name 1..32 distinct Source-local recording actions");
36
- result = {
37
- instruction: memoryInputText(input.instruction, "capture instruction", 4e3),
38
- actionIds: [...input.actionIds],
39
- ...input.sourceKeys === void 0 ? {} : { sourceKeys: keys(input.sourceKeys, "capture sourceKeys") }
40
- };
41
- }
42
- return result;
9
+ return validateMemoryViewExtension(slot, value);
43
10
  }
11
+ /** An extension only for this Strategy; `defineMemoryViewExtension` also follows other Strategies. */
44
12
  function defineThreeTierExtension(definition) {
45
13
  return defineMemoryStrategyExtension({
46
14
  manifest: {
@@ -52,18 +20,11 @@ function defineThreeTierExtension(definition) {
52
20
  slot: definition.slot,
53
21
  deterministic: true
54
22
  },
55
- contribute: (request, sources) => validateThreeTierExtension(definition.slot, definition.contribute(request, sources))
23
+ contribute: (request, sources) => validateMemoryViewExtension(definition.slot, definition.contribute(request, sources))
56
24
  });
57
25
  }
58
26
  function threeTierContributions(values) {
59
- const output = {};
60
- for (const contribution of values) {
61
- const slot = contribution.slot;
62
- if (Object.hasOwn(output, slot)) throw new Error(`duplicate three-tier extension slot: ${slot}`);
63
- const value = validateThreeTierExtension(slot, contribution.value);
64
- Object.assign(output, { [slot]: value });
65
- }
66
- return output;
27
+ return memoryViewExtensionValues(values);
67
28
  }
68
29
  //#endregion
69
30
  export { defineThreeTierExtension, threeTierActionWorkflow, threeTierContributions, validateThreeTierExtension };
package/lib/index.js CHANGED
@@ -54,13 +54,6 @@ const MODEL_RECALL_MEDIUM_LIMIT_PER_ATTEMPT = 1;
54
54
  const MODEL_RECALL_UNKNOWN_LIMIT_PER_ATTEMPT = 1;
55
55
  const MODEL_RECALL_LIST_LIMIT = 8;
56
56
  const MODEL_RECALL_METADATA_LIMIT = 300;
57
- function boundedModelText(value, maximum) {
58
- if (maximum <= 0) return "";
59
- if (value.length <= maximum) return value;
60
- let end = maximum - 1;
61
- if (end > 0 && /[\uD800-\uDBFF]/u.test(value[end - 1])) end -= 1;
62
- return `${value.slice(0, end)}…`;
63
- }
64
57
  function insightDigest(result) {
65
58
  return sha256(result.content.trim().replace(/\s+/gu, " "));
66
59
  }
@@ -109,7 +102,7 @@ function boundedModelInsights(results, admission = {}) {
109
102
  if (seenReferences.has(reference) || seenDigests.has(digest)) continue;
110
103
  const remainingContent = totalContentLimit - contentCharacters;
111
104
  if (remainingContent <= 0) break;
112
- const content = boundedModelText(result.content, Math.min(contentLimit, remainingContent));
105
+ const content = truncateMemoryText(result.content, Math.min(contentLimit, remainingContent));
113
106
  if (content === "") continue;
114
107
  seenReferences.add(reference);
115
108
  seenDigests.add(digest);
@@ -119,19 +112,19 @@ function boundedModelInsights(results, admission = {}) {
119
112
  admitted.push({
120
113
  id: result.id,
121
114
  content,
122
- ...result.category === void 0 ? {} : { category: boundedModelText(result.category, MODEL_RECALL_METADATA_LIMIT) },
115
+ ...result.category === void 0 ? {} : { category: truncateMemoryText(result.category, MODEL_RECALL_METADATA_LIMIT) },
123
116
  ...typeof result.importance !== "number" || !Number.isFinite(result.importance) ? {} : { importance: result.importance },
124
- ...result.tags === void 0 ? {} : { tags: result.tags.slice(0, MODEL_RECALL_LIST_LIMIT).map((tag) => boundedModelText(tag, MODEL_RECALL_METADATA_LIMIT)) },
125
- ...result.entities === void 0 ? {} : { entities: result.entities.slice(0, MODEL_RECALL_LIST_LIMIT).map((entity) => boundedModelText(entity, MODEL_RECALL_METADATA_LIMIT)) },
126
- ...result.source === void 0 ? {} : { source: boundedModelText(result.source, MODEL_RECALL_METADATA_LIMIT) },
127
- ...result.createdAt === void 0 ? {} : { createdAt: boundedModelText(result.createdAt, MODEL_RECALL_METADATA_LIMIT) },
117
+ ...result.tags === void 0 ? {} : { tags: result.tags.slice(0, MODEL_RECALL_LIST_LIMIT).map((tag) => truncateMemoryText(tag, MODEL_RECALL_METADATA_LIMIT)) },
118
+ ...result.entities === void 0 ? {} : { entities: result.entities.slice(0, MODEL_RECALL_LIST_LIMIT).map((entity) => truncateMemoryText(entity, MODEL_RECALL_METADATA_LIMIT)) },
119
+ ...result.source === void 0 ? {} : { source: truncateMemoryText(result.source, MODEL_RECALL_METADATA_LIMIT) },
120
+ ...result.createdAt === void 0 ? {} : { createdAt: truncateMemoryText(result.createdAt, MODEL_RECALL_METADATA_LIMIT) },
128
121
  ...typeof result.depth !== "number" || !Number.isFinite(result.depth) ? {} : { depth: result.depth },
129
- ...result.edgeType === void 0 ? {} : { edgeType: boundedModelText(result.edgeType, MODEL_RECALL_METADATA_LIMIT) },
130
- ...result.memoryBodyId === void 0 ? {} : { memoryBodyId: boundedModelText(result.memoryBodyId, 1e3) },
131
- ...result.memoryBodyName === void 0 ? {} : { memoryBodyName: boundedModelText(result.memoryBodyName, MODEL_RECALL_METADATA_LIMIT) },
122
+ ...result.edgeType === void 0 ? {} : { edgeType: truncateMemoryText(result.edgeType, MODEL_RECALL_METADATA_LIMIT) },
123
+ ...result.memoryBodyId === void 0 ? {} : { memoryBodyId: truncateMemoryText(result.memoryBodyId, 1e3) },
124
+ ...result.memoryBodyName === void 0 ? {} : { memoryBodyName: truncateMemoryText(result.memoryBodyName, MODEL_RECALL_METADATA_LIMIT) },
132
125
  ...result.memoryProviderId === void 0 ? {} : { memoryProviderId: result.memoryProviderId },
133
126
  ...result.memoryCapabilities === void 0 ? {} : { memoryCapabilities: structuredClone(result.memoryCapabilities) },
134
- ...result.externalUri === void 0 ? {} : { externalUri: boundedModelText(result.externalUri, 2e3) }
127
+ ...result.externalUri === void 0 ? {} : { externalUri: truncateMemoryText(result.externalUri, 2e3) }
135
128
  });
136
129
  }
137
130
  return { results: admitted };
@@ -604,12 +597,12 @@ const inject = ["mnemonMemory"];
604
597
  const memoryPlugin = defineMemoryPlugin({
605
598
  packageName: name,
606
599
  label: {
607
- en: "Default three-tier",
608
- "zh-CN": "默认三层"
600
+ en: "Layered strategy",
601
+ "zh-CN": "分层策略"
609
602
  },
610
603
  description: {
611
- en: "Compile available runtime, document and durable Sources into one View.",
612
- "zh-CN": "将可用的运行时、档案与长期 Source 编译为一个 View。"
604
+ en: "Resident runtime memory, on-demand documents and durable memory.",
605
+ "zh-CN": "运行时记忆常驻,档案与长期记忆按需读取。"
613
606
  },
614
607
  roles: ["strategy"],
615
608
  provides: [{ id: "strategy" }, { id: "strategy.default-three-tier" }],
@@ -618,10 +611,7 @@ const memoryPlugin = defineMemoryPlugin({
618
611
  const memoryStrategyConfiguration = defineMemoryStrategyConfiguration({
619
612
  kind: "strategy",
620
613
  typeId: "default-three-tier",
621
- label: {
622
- en: "Default three-tier",
623
- "zh-CN": "默认三层"
624
- },
614
+ label: memoryPlugin.label,
625
615
  description: {
626
616
  en: "Compose runtime context, documents and durable memory.",
627
617
  "zh-CN": "组合运行时、档案与长期记忆。"
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Layered strategy",
4
+ "description": "Resident runtime memory, on-demand documents and durable memory."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "分层策略",
4
+ "description": "运行时记忆常驻,档案与长期记忆按需读取。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mnemon-strategy-default-three-tier",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "description": "Explicit three-tier View Strategy for Composable View Memory.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,10 +16,12 @@
16
16
  "types": "./lib/extension-sdk.d.ts",
17
17
  "default": "./lib/extension-sdk.js"
18
18
  },
19
- "./package.json": "./package.json"
19
+ "./package.json": "./package.json",
20
+ "./locale/*.json": "./locale/*.json"
20
21
  },
21
22
  "files": [
22
23
  "lib",
24
+ "locale",
23
25
  "README.md"
24
26
  ],
25
27
  "scripts": {
@@ -30,11 +32,11 @@
30
32
  },
31
33
  "peerDependencies": {
32
34
  "@deepseek-ai/cordis": "^4.0.1",
33
- "dsh-mnemon": "^0.5.1"
35
+ "dsh-mnemon": "^0.5.17"
34
36
  },
35
37
  "devDependencies": {
36
38
  "@types/node": "^22.0.0",
37
- "dsh-mnemon": "^0.5.15",
39
+ "dsh-mnemon": "^0.5.17",
38
40
  "tsdown": "^0.22.0",
39
41
  "typescript": "^5.9.0",
40
42
  "vitest": "^3.2.0"