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.
@@ -1,5 +1,5 @@
1
- import { i as DEFAULT_MEMORY_VIEW_BUDGET } from "./contracts-D4ghDRK4.js";
2
- import { a as defineMemoryStrategy, c as jsonClone, d as uniqueIds, f as validateCapabilities, i as defineMemorySource, l as positiveInteger, n as deepFreeze, o as defineMemoryStrategyExtension, p as validateProvenance, r as defineMemoryPlugin, s as id, t as canonicalMemoryJson, u as requiredText } from "./definitions-CSPV0ER1.js";
1
+ import { DEFAULT_MEMORY_VIEW_BUDGET } from "./contracts.js";
2
+ import { a as defineMemoryStrategy, c as jsonClone, d as uniqueIds, f as validateCapabilities, i as defineMemorySource, l as positiveInteger, n as deepFreeze, o as defineMemoryStrategyExtension, p as validateProvenance, r as defineMemoryPlugin, s as id, t as canonicalMemoryJson, u as requiredText } from "./definitions-j9QPbrXb.js";
3
3
  import { createHash } from "node:crypto";
4
4
  import { setMaxListeners } from "node:events";
5
5
  //#region src/core/contributions.ts
@@ -165,13 +165,16 @@ function captureMemoryContributionSnapshot(snapshot) {
165
165
  const strategies = snapshot.strategies.map(captureStrategy);
166
166
  const extensions = (snapshot.strategyExtensions ?? []).map(captureExtension).sort((a, b) => a.instanceKey.localeCompare(b.instanceKey));
167
167
  const plugins = (snapshot.plugins ?? []).map(capturePlugin).sort((a, b) => a.instanceKey.localeCompare(b.instanceKey));
168
- const slots = /* @__PURE__ */ new Map();
168
+ const owners = [];
169
169
  for (const extension of extensions) {
170
- const manifest = extension.definition.manifest;
171
- const slot = `${manifest.strategyTypeId}/${manifest.slot}`;
172
- const occupied = slots.get(slot);
173
- if (occupied !== void 0) throw new Error(`memory Strategy extension slot conflict: ${slot} (${occupied}, ${extension.instanceKey})`);
174
- slots.set(slot, extension.instanceKey);
170
+ const { strategyTypeId, slot } = extension.definition.manifest;
171
+ const owner = owners.find((item) => item.slot === slot && (item.strategyTypeId === strategyTypeId || item.strategyTypeId === "*" || strategyTypeId === "*"));
172
+ if (owner !== void 0) throw new Error(`memory Strategy extension slot conflict: ${strategyTypeId}/${slot} (${owner.instanceKey}, ${extension.instanceKey})`);
173
+ owners.push({
174
+ strategyTypeId,
175
+ slot,
176
+ instanceKey: extension.instanceKey
177
+ });
175
178
  }
176
179
  const keys = /* @__PURE__ */ new Set();
177
180
  for (const contribution of [
@@ -214,6 +217,7 @@ function selectStrategy(strategies, options) {
214
217
  if (options.strategyTypeId !== void 0) {
215
218
  const type = id(options.strategyTypeId, "selected memory Strategy typeId");
216
219
  const matches = strategies.filter((strategy) => strategy.definition.manifest.typeId === type);
220
+ if (matches.length === 0 && options.strategyFallback === "sole-strategy" && strategies.length === 1) return strategies[0];
217
221
  if (matches.length === 0) throw new Error(`selected memory Strategy type is unavailable: ${type}`);
218
222
  if (matches.length > 1) throw new Error(`selected memory Strategy type is ambiguous: ${type}`);
219
223
  return matches[0];
@@ -274,7 +278,8 @@ function normalizeViewSpec(value, strategy, facts, budget) {
274
278
  seen.add(key);
275
279
  const sourceFacts = facts.get(key);
276
280
  if (sourceFacts === void 0) throw new Error(`memory Strategy selected unavailable Source: ${key}`);
277
- if (!strategy.definition.manifest.supportedSourceRoles.includes(sourceFacts.role)) throw new Error(`memory Strategy selected an unsupported Source role: ${sourceFacts.role}`);
281
+ const roles = strategy.definition.manifest.supportedSourceRoles;
282
+ if (!roles.includes("*") && !roles.includes(sourceFacts.role)) throw new Error(`memory Strategy selected an unsupported Source role: ${sourceFacts.role}`);
278
283
  if (source.required !== void 0 && typeof source.required !== "boolean") throw new Error(`memory Source requirement must be boolean: ${key}`);
279
284
  if (sourceFacts.availability === "unavailable") {
280
285
  if (source.required === false) return [];
@@ -490,8 +495,12 @@ var MemoryCompositionGeneration = class {
490
495
  ...snapshot.strategies.length === 0 ? [] : ["strategy"]
491
496
  ]);
492
497
  this.strategy = selectStrategy(snapshot.strategies, options);
493
- this.extensions = (snapshot.strategyExtensions ?? []).filter((extension) => extension.definition.manifest.strategyTypeId === this.strategy.definition.manifest.typeId);
494
- for (const extension of this.extensions) if (!this.strategy.definition.manifest.extensionSlots?.includes(extension.definition.manifest.slot)) throw new Error(`memory Strategy does not support extension slot: ${extension.definition.manifest.slot} (${extension.instanceKey})`);
498
+ const strategyManifest = this.strategy.definition.manifest;
499
+ this.extensions = (snapshot.strategyExtensions ?? []).filter((extension) => extension.definition.manifest.strategyTypeId === strategyManifest.typeId || extension.definition.manifest.strategyTypeId === "*" && strategyManifest.extensionSlots?.includes(extension.definition.manifest.slot) === true);
500
+ for (const extension of this.extensions) {
501
+ const slot = extension.definition.manifest.slot;
502
+ if (!strategyManifest.extensionSlots?.includes(slot)) throw new Error(`memory Strategy does not support extension slot: ${slot} (${extension.instanceKey})`);
503
+ }
495
504
  this.now = options.now ?? (() => /* @__PURE__ */ new Date());
496
505
  this.sourceTimeoutMs = positiveInteger(options.sourceTimeoutMs ?? 1e4, "memory Source timeoutMs", 3e5);
497
506
  const configurations = /* @__PURE__ */ new Map();
@@ -548,11 +557,15 @@ var MemoryCompositionGeneration = class {
548
557
  strategyInstanceKey: this.strategy.instanceKey,
549
558
  ...this.extensions.length === 0 ? {} : { strategyExtensionInstanceKeys: this.extensions.map((extension) => extension.instanceKey) },
550
559
  sourceInstanceKeys: [...this.sources.keys()],
551
- diagnostics: (snapshot.strategyExtensions ?? []).filter((extension) => !this.extensions.includes(extension)).map((extension) => ({
560
+ diagnostics: [...options.strategyTypeId === void 0 || strategyManifest.typeId === options.strategyTypeId ? [] : [{
561
+ code: "strategy-fallback",
562
+ contributionInstanceKey: this.strategy.instanceKey,
563
+ message: `Selected Strategy ${options.strategyTypeId} is unavailable; composing with the only installed Strategy ${strategyManifest.typeId}.`
564
+ }], ...(snapshot.strategyExtensions ?? []).filter((extension) => !this.extensions.includes(extension)).map((extension) => ({
552
565
  code: "strategy-extension-inactive",
553
566
  contributionInstanceKey: extension.instanceKey,
554
- message: `Strategy extension targets ${extension.definition.manifest.strategyTypeId}; selected Strategy is ${this.strategy.definition.manifest.typeId}.`
555
- }))
567
+ message: extension.definition.manifest.strategyTypeId === "*" ? `Selected Strategy ${strategyManifest.typeId} does not accept the ${extension.definition.manifest.slot} slot.` : `Strategy extension targets ${extension.definition.manifest.strategyTypeId}; selected Strategy is ${strategyManifest.typeId}.`
568
+ }))]
556
569
  });
557
570
  }
558
571
  async compose(requestValue, signal) {
@@ -955,6 +968,21 @@ var MemoryCompositionGeneration = class {
955
968
  };
956
969
  //#endregion
957
970
  //#region src/core/generation.ts
971
+ /** No generation serves new work: the composition is incomplete or was rejected. */
972
+ var MemoryCompositionUnavailableError = class extends Error {
973
+ evaluation;
974
+ code = "memory-composition-unavailable";
975
+ constructor(evaluation) {
976
+ const reason = evaluation.diagnostics.map((diagnostic) => diagnostic.message).join("; ");
977
+ super(`no Serving memory generation is available${reason === "" ? "" : `: ${reason}`}`);
978
+ this.evaluation = evaluation;
979
+ this.name = "MemoryCompositionUnavailableError";
980
+ }
981
+ };
982
+ /** Matched by code, so a copy of Core bundled into another entry point still qualifies. */
983
+ function isMemoryCompositionUnavailable(error) {
984
+ return error instanceof Error && error.code === "memory-composition-unavailable";
985
+ }
958
986
  function report(state, snapshot, diagnostics) {
959
987
  return Object.freeze({
960
988
  state,
@@ -1040,10 +1068,7 @@ var MemoryGenerationHost = class {
1040
1068
  acquire(generationId) {
1041
1069
  this.assertOpen();
1042
1070
  const record = generationId === void 0 ? this.serving : this.records.get(generationId);
1043
- if (record === void 0 || generationId === void 0 && record.state !== "serving") {
1044
- const reason = this.evaluation.diagnostics.map((diagnostic) => diagnostic.message).join("; ");
1045
- throw new Error(`no Serving memory generation is available${reason === "" ? "" : `: ${reason}`}`);
1046
- }
1071
+ if (record === void 0 || generationId === void 0 && record.state !== "serving") throw new MemoryCompositionUnavailableError(this.evaluation);
1047
1072
  record.leases += 1;
1048
1073
  let active = true;
1049
1074
  return Object.freeze({
@@ -1313,4 +1338,4 @@ var MemoryRuntime = class {
1313
1338
  }
1314
1339
  };
1315
1340
  //#endregion
1316
- export { prepareMemoryContributions as a, validateMemoryPluginGraph as i, MemoryCompositionGeneration as n, captureMemoryContributionSnapshot as r, provideMemoryRuntime as t };
1341
+ export { validateMemoryPluginGraph as a, captureMemoryContributionSnapshot as i, isMemoryCompositionUnavailable as n, prepareMemoryContributions as o, MemoryCompositionGeneration as r, provideMemoryRuntime as t };
@@ -1,4 +1,4 @@
1
- import { n as deepFreeze, t as canonicalMemoryJson } from "./definitions-CSPV0ER1.js";
1
+ import { n as deepFreeze, t as canonicalMemoryJson } from "./definitions-j9QPbrXb.js";
2
2
  import { resolve } from "node:path";
3
3
  import { createHash, randomUUID } from "node:crypto";
4
4
  //#region src/sdk/storage-lock.ts
package/lib/testing.js CHANGED
@@ -1,6 +1,6 @@
1
- import { t as provideMemoryRuntime } from "./runtime-BEX0sc1z.js";
2
- import { i as DEFAULT_MEMORY_VIEW_BUDGET } from "./contracts-D4ghDRK4.js";
3
- import { c as jsonClone } from "./definitions-CSPV0ER1.js";
1
+ import { t as provideMemoryRuntime } from "./runtime-Bk6lFgxd.js";
2
+ import { DEFAULT_MEMORY_VIEW_BUDGET } from "./contracts.js";
3
+ import { c as jsonClone } from "./definitions-j9QPbrXb.js";
4
4
  import { Context } from "@deepseek-ai/cordis";
5
5
  import { readFileSync } from "node:fs";
6
6
  //#region src/sdk/testing.ts
@@ -0,0 +1,118 @@
1
+ import { type ReactNode } from 'react';
2
+ /**
3
+ * A component's own settings, on its page: keyed by the component's package
4
+ * name, rendered after the page's generated state, relations and options.
5
+ */
6
+ export declare const MNEMON_COMPONENT_SETTINGS_SLOT: "mnemon.component.settings";
7
+ /**
8
+ * What a component's card on the Memory System's Status page says while it
9
+ * runs, keyed by the component's package name. A card that is not running
10
+ * shows the page's own note instead.
11
+ */
12
+ export declare const MNEMON_COMPONENT_STATUS_SLOT: "mnemon.component.status";
13
+ type ComponentRegion = typeof MNEMON_COMPONENT_SETTINGS_SLOT | typeof MNEMON_COMPONENT_STATUS_SLOT;
14
+ /** What the host tells a component's settings about the page they are on. */
15
+ export interface MemoryComponentSettingsProps {
16
+ /** The component the page is about, as the host shows it. */
17
+ component: {
18
+ packageName: string;
19
+ label: string;
20
+ /** Whether the component is switched on. */
21
+ enabled: boolean;
22
+ };
23
+ /** Whether the configuration can be written now; settings stay read-only otherwise. */
24
+ writable: boolean;
25
+ /** The active DSH locale id. */
26
+ language: string;
27
+ /** The conversation and workspace the page was opened for, when there is one. */
28
+ sessionId?: string;
29
+ workspace?: {
30
+ id: string;
31
+ label?: string;
32
+ };
33
+ }
34
+ export type MemoryComponentSettingsComponent = (props: MemoryComponentSettingsProps) => ReactNode;
35
+ /** What the Status page tells a component's card: the component it is about. */
36
+ export interface MemoryComponentStatusProps {
37
+ component: {
38
+ packageName: string;
39
+ label: string;
40
+ enabled: boolean;
41
+ };
42
+ /** The active DSH locale id. */
43
+ language: string;
44
+ /** The conversation and workspace the Memory System shows, when there is one. */
45
+ sessionId?: string;
46
+ workspace?: {
47
+ id: string;
48
+ label?: string;
49
+ };
50
+ }
51
+ export type MemoryComponentStatusComponent = (props: MemoryComponentStatusProps) => ReactNode;
52
+ /** Everything one component adds to dsh-mnemon's interface beyond its declaration. */
53
+ export interface MemoryComponentUIContribution {
54
+ /** The npm package name the component's plugin declaration names. */
55
+ packageName: string;
56
+ /** Its own settings, shown on its page. Each saves on its own. */
57
+ settings?: MemoryComponentSettingsComponent;
58
+ /** What its card on the Status page says while it runs: a headline and one line. */
59
+ status?: MemoryComponentStatusComponent;
60
+ }
61
+ /** The DSH Slot capability narrowed to the component regions. */
62
+ export interface MemoryComponentUIContext {
63
+ slots: {
64
+ inject(name: ComponentRegion, setup: () => () => void): () => void;
65
+ register(options: {
66
+ name: typeof MNEMON_COMPONENT_SETTINGS_SLOT;
67
+ key: string;
68
+ }, component: MemoryComponentSettingsComponent): () => void;
69
+ register(options: {
70
+ name: typeof MNEMON_COMPONENT_STATUS_SLOT;
71
+ key: string;
72
+ }, component: MemoryComponentStatusComponent): () => void;
73
+ };
74
+ }
75
+ /**
76
+ * Register a component's interface into the regions dsh-mnemon declares, the
77
+ * way shipped components do. Registration waits for each region to exist and
78
+ * is released by the returned function.
79
+ */
80
+ export declare function installMemoryComponentUI(ctx: MemoryComponentUIContext, contribution: MemoryComponentUIContribution): () => void;
81
+ interface ComponentRegionDirectoryContext {
82
+ slots: {
83
+ getVersion(name: ComponentRegion): number;
84
+ entriesOfSlot(name: ComponentRegion): readonly {
85
+ options: {
86
+ key?: string;
87
+ };
88
+ }[];
89
+ subscribe(name: ComponentRegion, listener: () => void): () => void;
90
+ };
91
+ }
92
+ /** The components that registered into one region, as the pages that show it need to know. */
93
+ export interface ComponentRegionDirectory {
94
+ getSnapshot(): ReadonlySet<string>;
95
+ subscribe(listener: () => void): () => void;
96
+ }
97
+ /** The components that registered settings. */
98
+ export type ComponentSettingsDirectory = ComponentRegionDirectory;
99
+ /** Thin adapter over a DSH child Slot: it keeps no registry of its own. */
100
+ export declare function createComponentRegionDirectory(ctx: ComponentRegionDirectoryContext, region: ComponentRegion): ComponentRegionDirectory;
101
+ export declare function createComponentSettingsDirectory(ctx: ComponentRegionDirectoryContext): ComponentSettingsDirectory;
102
+ interface ComponentRegionEntriesContext {
103
+ slots: {
104
+ entriesOfSlot(name: ComponentRegion): readonly {
105
+ component: unknown;
106
+ options: {
107
+ key?: string;
108
+ };
109
+ }[];
110
+ };
111
+ }
112
+ /**
113
+ * Render what one component registered into a region, where the page is not
114
+ * the region's declaring owner, as DSH's row page for a component is not:
115
+ * a child slot has one declaring entry, the configuration's.
116
+ */
117
+ export declare function renderComponentRegion<P extends object>(ctx: ComponentRegionEntriesContext, region: ComponentRegion, packageName: string, props: P): ReactNode;
118
+ export {};
@@ -1,5 +1,6 @@
1
1
  export { installMemorySourceUI, memorySourcePageEntryId, MNEMON_SOURCE_PAGE_SLOT, MNEMON_SOURCE_CONFIGURATION_MUTATE, MNEMON_SOURCE_CONFIGURATION_READ, type MemorySourcePageComponent, type MemorySourcePageDefinition, type MemorySourcePageProps, type MemorySourceUIContribution, type MemorySourceUIContext, type MemorySourcePageNavigation, } from './source-pages.tsx';
2
2
  export type { MnemonSourceManagementClient, MemorySourcePageInstance } from './source-contracts.ts';
3
+ export { installMemoryComponentUI, MNEMON_COMPONENT_SETTINGS_SLOT, MNEMON_COMPONENT_STATUS_SLOT, type MemoryComponentSettingsComponent, type MemoryComponentSettingsProps, type MemoryComponentStatusComponent, type MemoryComponentStatusProps, type MemoryComponentUIContext, type MemoryComponentUIContribution, } from './component-ui.tsx';
3
4
  export * from './page-kit.tsx';
4
5
  export * from './page-client.tsx';
5
6
  export { MnemonDialog, type MnemonDialogProps } from './MnemonDialog.tsx';