dsh-mnemon 0.5.15 → 0.5.17

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/contracts.js CHANGED
@@ -1,2 +1,45 @@
1
- import { a as MEMORY_PLUGIN_API_VERSION, i as DEFAULT_MEMORY_VIEW_BUDGET, n as MEMORY_SOURCE_MODES, r as COMPOSABLE_MEMORY_API_VERSION, t as MEMORY_CAPABILITIES } from "./contracts-D4ghDRK4.js";
2
- export { COMPOSABLE_MEMORY_API_VERSION, DEFAULT_MEMORY_VIEW_BUDGET, MEMORY_CAPABILITIES, MEMORY_PLUGIN_API_VERSION, MEMORY_SOURCE_MODES };
1
+ //#region src/core/contracts/plugin.ts
2
+ /** Declarative identity and graph relations shared by every Mnemon plugin. */
3
+ const MEMORY_PLUGIN_API_VERSION = "dsh-mnemon/plugin/v1";
4
+ //#endregion
5
+ //#region src/core/contracts/view.ts
6
+ const COMPOSABLE_MEMORY_API_VERSION = "dsh-mnemon/v1";
7
+ /** Extension target for every selected Strategy that declares the extension's standard slot. */
8
+ const ANY_MEMORY_STRATEGY = "*";
9
+ /** Strategy role list entry for a role-agnostic Strategy that may select any Source. */
10
+ const ANY_MEMORY_SOURCE_ROLE = "*";
11
+ /** Standard View extension slots, each with one public value contract any Strategy may accept. */
12
+ const MEMORY_VIEW_EXTENSION_SLOTS = [
13
+ "selection",
14
+ "projection",
15
+ "capture"
16
+ ];
17
+ const DEFAULT_MEMORY_VIEW_BUDGET = Object.freeze({
18
+ maxProjectionCharacters: 65536,
19
+ maxRoutes: 16,
20
+ maxActions: 16,
21
+ maxEvidenceResults: 16,
22
+ maxEvidenceCharacters: 16384
23
+ });
24
+ //#endregion
25
+ //#region src/core/contracts/index.ts
26
+ const MEMORY_CAPABILITIES = [
27
+ "status",
28
+ "project",
29
+ "recall",
30
+ "search",
31
+ "read",
32
+ "browse",
33
+ "write",
34
+ "archive",
35
+ "graph",
36
+ "related",
37
+ "link",
38
+ "forget",
39
+ "maintain",
40
+ "export",
41
+ "import"
42
+ ];
43
+ const MEMORY_SOURCE_MODES = ["eager", "routed"];
44
+ //#endregion
45
+ export { ANY_MEMORY_SOURCE_ROLE, ANY_MEMORY_STRATEGY, COMPOSABLE_MEMORY_API_VERSION, DEFAULT_MEMORY_VIEW_BUDGET, MEMORY_CAPABILITIES, MEMORY_PLUGIN_API_VERSION, MEMORY_SOURCE_MODES, MEMORY_VIEW_EXTENSION_SLOTS };
package/lib/core.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as provideMemoryRuntime } from "./runtime-BEX0sc1z.js";
1
+ import { t as provideMemoryRuntime } from "./runtime-Bk6lFgxd.js";
2
2
  //#region src/core/plugin.ts
3
3
  const name = "dsh-mnemon-core";
4
4
  const provide = ["mnemonMemory"];
@@ -1,4 +1,4 @@
1
- import { a as MEMORY_PLUGIN_API_VERSION, t as MEMORY_CAPABILITIES } from "./contracts-D4ghDRK4.js";
1
+ import { MEMORY_CAPABILITIES, MEMORY_PLUGIN_API_VERSION, MEMORY_VIEW_EXTENSION_SLOTS } from "./contracts.js";
2
2
  //#region src/core/definitions.ts
3
3
  const ID = /^[a-z][a-z0-9-]{0,127}$/u;
4
4
  const PACKAGE = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/u;
@@ -16,6 +16,19 @@ function id(value, label) {
16
16
  if (!ID.test(normalized)) throw new Error(`${label} must match [a-z][a-z0-9-]{0,127}`);
17
17
  return normalized;
18
18
  }
19
+ /** A role-agnostic Strategy names the wildcard alone, never beside specific roles. */
20
+ function sourceRoles(value) {
21
+ if (value.includes("*")) {
22
+ if (value.length !== 1) throw new Error("memory Strategy supported Source roles must list the any-role wildcard alone");
23
+ return ["*"];
24
+ }
25
+ return uniqueIds(value, "memory Strategy supported Source role");
26
+ }
27
+ /** Only standard slots have a value contract every Strategy can share. */
28
+ function anyStrategyTarget(slot) {
29
+ if (!MEMORY_VIEW_EXTENSION_SLOTS.includes(slot)) throw new Error(`memory Strategy extension for any Strategy must use a standard slot: ${String(slot)}`);
30
+ return "*";
31
+ }
19
32
  function positiveInteger(value, label, maximum = 1e6) {
20
33
  if (!Number.isInteger(value) || value < 1 || value > maximum) throw new Error(`${label} must be an integer within 1..${maximum}`);
21
34
  return value;
@@ -216,7 +229,7 @@ function defineMemoryStrategy(definition) {
216
229
  ...manifest,
217
230
  typeId,
218
231
  packageName,
219
- supportedSourceRoles: uniqueIds(manifest.supportedSourceRoles, "memory Strategy supported Source role"),
232
+ supportedSourceRoles: sourceRoles(manifest.supportedSourceRoles),
220
233
  maxSources: positiveInteger(manifest.maxSources, "memory Strategy maxSources", 1e3),
221
234
  maxRoutes: positiveInteger(manifest.maxRoutes, "memory Strategy maxRoutes", 1e3),
222
235
  maxActions: positiveInteger(manifest.maxActions, "memory Strategy maxActions", 1e3),
@@ -241,7 +254,7 @@ function defineMemoryStrategyExtension(definition) {
241
254
  ...manifest,
242
255
  packageName,
243
256
  typeId: id(manifest.typeId, "memory Strategy extension typeId"),
244
- strategyTypeId: id(manifest.strategyTypeId, "memory Strategy extension target"),
257
+ strategyTypeId: manifest.strategyTypeId === "*" ? anyStrategyTarget(manifest.slot) : id(manifest.strategyTypeId, "memory Strategy extension target"),
245
258
  slot: id(manifest.slot, "memory Strategy extension slot")
246
259
  }, "memory Strategy extension manifest"),
247
260
  contribute: definition.contribute
@@ -1,13 +1,12 @@
1
- import { a as memoryConfigurationDigest, c as record, d as truncate, f as withMemoryStorageLock, i as integer, l as stringArray, o as migrationLineage, s as receipt, t as defineMemoryStrategyConfiguration, u as text } from "./strategy-configuration-D8IEKZdS.js";
2
- import { a as defineMemoryStrategy, i as defineMemorySource, o as defineMemoryStrategyExtension, r as defineMemoryPlugin } from "./definitions-CSPV0ER1.js";
1
+ import { a as memoryConfigurationDigest, c as record, d as truncate, f as withMemoryStorageLock, i as integer, l as stringArray, o as migrationLineage, s as receipt, t as defineMemoryStrategyConfiguration, u as text } from "./strategy-configuration-sVkKToSW.js";
2
+ import { COMPOSABLE_MEMORY_API_VERSION, MEMORY_VIEW_EXTENSION_SLOTS } from "./contracts.js";
3
+ import { a as defineMemoryStrategy, i as defineMemorySource, o as defineMemoryStrategyExtension, r as defineMemoryPlugin } from "./definitions-j9QPbrXb.js";
3
4
  //#region src/sdk/install.ts
4
5
  function stableEntryId(ctx, explicit) {
5
6
  const configured = explicit?.trim();
6
7
  if (configured !== void 0 && configured !== "") return configured;
7
8
  const located = ctx.get("loader", false)?.locate(ctx.fiber)?.trim();
8
9
  if (located !== void 0 && located !== "") return located;
9
- const entryId = ctx.fiber.entry?.options?.id;
10
- if (typeof entryId === "string" && entryId.trim() !== "") return entryId.trim();
11
10
  throw new Error("installMemory requires a stable Loader Entry id; pass options.instanceId for direct ctx.plugin() mounts");
12
11
  }
13
12
  /**
@@ -22,4 +21,75 @@ function installMemory(ctx, contribution, options = {}) {
22
21
  }), `dsh-mnemon: install ${entryId}`);
23
22
  }
24
23
  //#endregion
25
- export { receipt as createMemoryMutationReceipt, defineMemoryPlugin, defineMemorySource, defineMemoryStrategy, defineMemoryStrategyConfiguration, defineMemoryStrategyExtension, installMemory, memoryConfigurationDigest, integer as memoryInputInteger, migrationLineage as memoryInputMigrationLineage, record as memoryInputRecord, stringArray as memoryInputStringArray, text as memoryInputText, truncate as truncateMemoryText, withMemoryStorageLock };
24
+ //#region src/sdk/view-extensions.ts
25
+ const SOURCE_KEY = /^source:[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,292}$/u;
26
+ const ACTION_ID = /^[a-z][a-z0-9-]{0,127}$/u;
27
+ const FIELDS = {
28
+ selection: ["sourceKeys", "writableSourceKeys"],
29
+ projection: ["maxProjectionCharacters"],
30
+ capture: [
31
+ "instruction",
32
+ "actionIds",
33
+ "sourceKeys"
34
+ ]
35
+ };
36
+ function sourceKeys(value, label) {
37
+ if (!Array.isArray(value) || value.length > 32 || value.some((key) => typeof key !== "string" || !SOURCE_KEY.test(key))) throw new Error(`${label} must contain at most 32 exact Source instance keys`);
38
+ if (new Set(value).size !== value.length) throw new Error(`${label} contains duplicate Source keys`);
39
+ return [...value];
40
+ }
41
+ /** Validate one standard View extension value; a Strategy validates again before interpreting it. */
42
+ function validateMemoryViewExtension(slot, value) {
43
+ if (!MEMORY_VIEW_EXTENSION_SLOTS.includes(slot)) throw new Error(`unsupported View extension slot: ${String(slot)}`);
44
+ const input = record(value, `View ${slot} contribution`);
45
+ for (const key of Object.keys(input)) if (!FIELDS[slot].includes(key)) throw new Error(`unsupported View ${slot} field: ${key}`);
46
+ let result;
47
+ if (slot === "selection") {
48
+ const selected = sourceKeys(input.sourceKeys, "sourceKeys");
49
+ const writable = input.writableSourceKeys === void 0 ? void 0 : sourceKeys(input.writableSourceKeys, "writableSourceKeys");
50
+ if (writable?.some((key) => !selected.includes(key))) throw new Error("writableSourceKeys must be within selected sourceKeys");
51
+ result = {
52
+ sourceKeys: selected,
53
+ ...writable === void 0 ? {} : { writableSourceKeys: writable }
54
+ };
55
+ } else if (slot === "projection") {
56
+ if (input.maxProjectionCharacters === void 0) throw new Error("maxProjectionCharacters is required");
57
+ result = { maxProjectionCharacters: integer(input.maxProjectionCharacters, 4096, 1, 1e7) };
58
+ } else {
59
+ const actionIds = input.actionIds;
60
+ if (!Array.isArray(actionIds) || actionIds.length === 0 || actionIds.length > 32 || actionIds.some((id) => typeof id !== "string" || !ACTION_ID.test(id)) || new Set(actionIds).size !== actionIds.length) throw new Error("capture actionIds must name 1..32 distinct Source-local recording actions");
61
+ result = {
62
+ instruction: text(input.instruction, "capture instruction", 4e3),
63
+ actionIds: [...actionIds],
64
+ ...input.sourceKeys === void 0 ? {} : { sourceKeys: sourceKeys(input.sourceKeys, "capture sourceKeys") }
65
+ };
66
+ }
67
+ return result;
68
+ }
69
+ /** Standard values contributed to one composition; each slot has at most one owner. */
70
+ function memoryViewExtensionValues(contributions) {
71
+ const output = {};
72
+ for (const contribution of contributions) {
73
+ const slot = contribution.slot;
74
+ if (Object.hasOwn(output, slot)) throw new Error(`duplicate View extension slot: ${slot}`);
75
+ Object.assign(output, { [slot]: validateMemoryViewExtension(slot, contribution.value) });
76
+ }
77
+ return output;
78
+ }
79
+ /** An extension for whichever selected Strategy declares its standard slot. */
80
+ function defineMemoryViewExtension(definition) {
81
+ return defineMemoryStrategyExtension({
82
+ manifest: {
83
+ apiVersion: COMPOSABLE_MEMORY_API_VERSION,
84
+ kind: "strategy-extension",
85
+ typeId: definition.typeId,
86
+ packageName: definition.packageName,
87
+ strategyTypeId: "*",
88
+ slot: definition.slot,
89
+ deterministic: true
90
+ },
91
+ contribute: (request, sources) => validateMemoryViewExtension(definition.slot, definition.contribute(request, sources))
92
+ });
93
+ }
94
+ //#endregion
95
+ export { receipt as createMemoryMutationReceipt, defineMemoryPlugin, defineMemorySource, defineMemoryStrategy, defineMemoryStrategyConfiguration, defineMemoryStrategyExtension, defineMemoryViewExtension, installMemory, memoryConfigurationDigest, integer as memoryInputInteger, migrationLineage as memoryInputMigrationLineage, record as memoryInputRecord, stringArray as memoryInputStringArray, text as memoryInputText, memoryViewExtensionValues, truncate as truncateMemoryText, validateMemoryViewExtension, withMemoryStorageLock };