dsh-mnemon-source-memory-spaces 0.5.3 → 0.5.5
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/README.md +3 -1
- package/lib/client.js +201 -178
- package/lib/contracts.d.ts +44 -22
- package/lib/{definitions-CEpa-tvm.d.ts → definitions-C5y84OE6.d.ts} +22 -17
- package/lib/index.d.ts +3 -3
- package/lib/index.js +255 -208
- package/lib/native-cli.d.ts +3 -1
- package/lib/native-cli.js +8 -1
- package/lib/{process-B-t3UflO.js → process-BvrgxPNP.js} +7 -2
- package/lib/provider-sdk.d.ts +11 -9
- package/lib/provider-sdk.js +8 -5
- package/lib/testing.d.ts +3 -3
- package/lib/types/client/api.d.ts +13 -9
- package/lib/types/client/pages.d.ts +8 -6
- package/lib/types/contracts.d.ts +49 -22
- package/package.json +11 -11
- package/presentation/locales.json +80 -60
- package/presentation/page.module.css +7 -3
- package/presentation/sidebar.module.css +6 -1
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { findMnemonCommand, isMnemonExecutable, mnemonNpmLauncher } from "./native-cli.js";
|
|
1
|
+
import { findMnemonCommand, isMnemonExecutable, mnemonNpmLauncher, nodeLauncherEnvironment } from "./native-cli.js";
|
|
2
2
|
import { CATEGORIES as CATEGORIES$1, EDGE_TYPES, INTENTS as INTENTS$1, MNEMON_EMBEDDING_PROTOCOLS, SOURCES as SOURCES$1 } from "./contracts.js";
|
|
3
3
|
import { a as MemoryProviderCatalog, i as EMPTY_MEMORY_PROVIDER_CATALOG, n as PrivateMemorySpaceProviderHost, r as MemoryProviderAdapterRegistry, t as createMemorySpaceProviderPlugin } from "./plugin-DlsNeZbQ.js";
|
|
4
|
-
import { t as runProcess } from "./process-
|
|
4
|
+
import { t as runProcess } from "./process-BvrgxPNP.js";
|
|
5
5
|
import { r as defineMemorySpaceProvider } from "./definitions-DfmOqJjR.js";
|
|
6
6
|
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { homedir, tmpdir } from "node:os";
|
|
@@ -16,7 +16,7 @@ function boundedToolText(value, maximum) {
|
|
|
16
16
|
return value.length <= maximum ? value : `${value.slice(0, maximum - 1)}…`;
|
|
17
17
|
}
|
|
18
18
|
/** Strip control-plane paths, provider settings, and statistics from model output. */
|
|
19
|
-
function
|
|
19
|
+
function modelSpaceCatalog(catalog) {
|
|
20
20
|
const items = catalog.items.slice(0, MODEL_MEMORY_BODY_LIMIT);
|
|
21
21
|
return {
|
|
22
22
|
items: items.map((body) => ({
|
|
@@ -95,7 +95,7 @@ function modelJson(value, maximum) {
|
|
|
95
95
|
return result;
|
|
96
96
|
}
|
|
97
97
|
//#endregion
|
|
98
|
-
//#region src/memory-
|
|
98
|
+
//#region src/memory-spaces.ts
|
|
99
99
|
const NATIVE_REGISTRY_VERSION = 1;
|
|
100
100
|
const PROVIDER_REGISTRY_VERSION = 4;
|
|
101
101
|
const ID_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]*$/;
|
|
@@ -193,7 +193,7 @@ function normalizePlacementDecision(value, providerId, providerCatalog = EMPTY_M
|
|
|
193
193
|
...placement.subagentProvider === void 0 ? {} : { subagentProvider: placement.subagentProvider }
|
|
194
194
|
};
|
|
195
195
|
}
|
|
196
|
-
function
|
|
196
|
+
function validateMemorySpaceId(value) {
|
|
197
197
|
const normalized = value.trim();
|
|
198
198
|
if (!ID_PATTERN.test(normalized)) throw new Error("memoryBodyId must match [a-zA-Z0-9][a-zA-Z0-9_-]*");
|
|
199
199
|
return normalized;
|
|
@@ -205,7 +205,7 @@ function validateMemoryBodyId(value) {
|
|
|
205
205
|
* compatible. External connection metadata lives under state and is never
|
|
206
206
|
* included in Memory Space Packs.
|
|
207
207
|
*/
|
|
208
|
-
var
|
|
208
|
+
var MemorySpaceRegistry = class MemorySpaceRegistry {
|
|
209
209
|
runner;
|
|
210
210
|
persistent;
|
|
211
211
|
now;
|
|
@@ -221,7 +221,7 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
221
221
|
this.now = now;
|
|
222
222
|
this.providerCatalog = providerCatalog;
|
|
223
223
|
this.state = sharedState ?? {
|
|
224
|
-
|
|
224
|
+
spaces: [],
|
|
225
225
|
services: {},
|
|
226
226
|
serviceEnabled: {}
|
|
227
227
|
};
|
|
@@ -230,11 +230,11 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
230
230
|
this.providerRegistryPath = join(runner.effectiveDataDir(), "state", "memory-providers.json");
|
|
231
231
|
if (sharedState === void 0) this.reload();
|
|
232
232
|
}
|
|
233
|
-
get
|
|
234
|
-
return this.state.
|
|
233
|
+
get spaces() {
|
|
234
|
+
return this.state.spaces;
|
|
235
235
|
}
|
|
236
|
-
set
|
|
237
|
-
this.state.
|
|
236
|
+
set spaces(value) {
|
|
237
|
+
this.state.spaces = value;
|
|
238
238
|
}
|
|
239
239
|
get services() {
|
|
240
240
|
return this.state.services;
|
|
@@ -250,7 +250,7 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
250
250
|
}
|
|
251
251
|
/** One generation-local descriptor view over the same persistent authority. */
|
|
252
252
|
withProviderCatalog(providerCatalog) {
|
|
253
|
-
return new
|
|
253
|
+
return new MemorySpaceRegistry(this.runner, this.persistent, this.now, providerCatalog, this.state);
|
|
254
254
|
}
|
|
255
255
|
isNative(providerId) {
|
|
256
256
|
return this.providerTypeId(providerId) === "mnemon-native";
|
|
@@ -262,15 +262,15 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
262
262
|
list() {
|
|
263
263
|
this.refreshIfChanged();
|
|
264
264
|
this.reconcileDiscoveredStores();
|
|
265
|
-
return this.
|
|
265
|
+
return this.spaces.filter((body) => this.providerCatalog.has(body.providerId)).map((body) => this.view(body));
|
|
266
266
|
}
|
|
267
267
|
active() {
|
|
268
268
|
return this.list().filter((body) => body.active && (this.isNative(body.provider.id) || Object.hasOwn(this.services, body.provider.id) && this.serviceEnabled[body.provider.id] === true));
|
|
269
269
|
}
|
|
270
270
|
get(id) {
|
|
271
|
-
const normalized =
|
|
271
|
+
const normalized = validateMemorySpaceId(id);
|
|
272
272
|
const body = this.list().find((entry) => entry.id === normalized);
|
|
273
|
-
if (body === void 0) throw new Error(`unknown memory
|
|
273
|
+
if (body === void 0) throw new Error(`unknown memory space: ${normalized}`);
|
|
274
274
|
return body;
|
|
275
275
|
}
|
|
276
276
|
openVikingConnection(id) {
|
|
@@ -286,10 +286,10 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
286
286
|
}
|
|
287
287
|
providerConnection(id, expectedProviderId) {
|
|
288
288
|
this.refreshIfChanged();
|
|
289
|
-
const normalized =
|
|
290
|
-
const body = this.
|
|
291
|
-
if (body === void 0 || this.isNative(body.providerId)) throw new Error(`memory
|
|
292
|
-
if (expectedProviderId !== void 0 && body.providerId !== expectedProviderId) throw new Error(`memory
|
|
289
|
+
const normalized = validateMemorySpaceId(id);
|
|
290
|
+
const body = this.spaces.find((entry) => entry.id === normalized);
|
|
291
|
+
if (body === void 0 || this.isNative(body.providerId)) throw new Error(`memory space has no external provider connection: ${normalized}`);
|
|
292
|
+
if (expectedProviderId !== void 0 && body.providerId !== expectedProviderId) throw new Error(`memory space ${normalized} uses ${body.providerId}, not ${expectedProviderId}`);
|
|
293
293
|
return this.connectionFor(body);
|
|
294
294
|
}
|
|
295
295
|
/** Used only after a public operation has refreshed the registry authority. */
|
|
@@ -334,7 +334,7 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
334
334
|
const previous = this.services[providerId] ?? {};
|
|
335
335
|
this.services[providerId] = this.providerCatalog.normalizeService(providerId, settings, previous, clearSecrets);
|
|
336
336
|
this.serviceEnabled[providerId] = enabled;
|
|
337
|
-
if (!enabled) this.
|
|
337
|
+
if (!enabled) this.spaces = this.spaces.filter((body) => body.providerId !== providerId);
|
|
338
338
|
this.save();
|
|
339
339
|
return this.providerServices().items.find((item) => item.providerId === providerId);
|
|
340
340
|
}
|
|
@@ -349,8 +349,8 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
349
349
|
if (this.isNative(providerId)) throw new Error("Mnemon Native Stores are discovered from disk");
|
|
350
350
|
let normalizedService = this.providerCatalog.normalizeService(providerId, service);
|
|
351
351
|
const seen = /* @__PURE__ */ new Set();
|
|
352
|
-
const existing = this.
|
|
353
|
-
const reservedIds = new Set(this.
|
|
352
|
+
const existing = this.spaces.filter((body) => body.providerId === providerId);
|
|
353
|
+
const reservedIds = new Set(this.spaces.filter((body) => body.providerId !== providerId).map((body) => body.id));
|
|
354
354
|
const timestamp = this.now().toISOString();
|
|
355
355
|
const projections = discovered.map((candidate) => {
|
|
356
356
|
const externalId = requiredText(candidate.externalId, "provider externalId", 2e3);
|
|
@@ -362,10 +362,10 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
362
362
|
...connection
|
|
363
363
|
});
|
|
364
364
|
const previous = existing.find((body) => body.externalId === externalId);
|
|
365
|
-
let id = previous?.id ??
|
|
365
|
+
let id = previous?.id ?? validateMemorySpaceId(`${providerId}-${createHash("sha256").update(externalId).digest("hex").slice(0, 24)}`);
|
|
366
366
|
let suffix = 1;
|
|
367
367
|
while (reservedIds.has(id)) {
|
|
368
|
-
id =
|
|
368
|
+
id = validateMemorySpaceId(`${providerId}-${createHash("sha256").update(`${externalId}:${suffix}`).digest("hex").slice(0, 24)}`);
|
|
369
369
|
suffix += 1;
|
|
370
370
|
}
|
|
371
371
|
reservedIds.add(id);
|
|
@@ -395,7 +395,7 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
395
395
|
}
|
|
396
396
|
this.services[providerId] = normalizedService;
|
|
397
397
|
this.serviceEnabled[providerId] = true;
|
|
398
|
-
this.
|
|
398
|
+
this.spaces = [...this.spaces.filter((body) => body.providerId !== providerId), ...projections];
|
|
399
399
|
this.save();
|
|
400
400
|
return this.providerServices().items.find((item) => item.providerId === providerId);
|
|
401
401
|
}
|
|
@@ -437,8 +437,8 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
437
437
|
const reservedIds = new Set(this.list().map((body) => body.id));
|
|
438
438
|
const nativeStoreIds = this.nativeStoreIds();
|
|
439
439
|
const nativeProvider = this.isNative(providerId);
|
|
440
|
-
let id = nativeProvider && nativeStoreIds.length === 0 && !reservedIds.has("default") ? "default" :
|
|
441
|
-
while (reservedIds.has(id) || nativeStoreIds.includes(id)) id =
|
|
440
|
+
let id = nativeProvider && nativeStoreIds.length === 0 && !reservedIds.has("default") ? "default" : validateMemorySpaceId(nativeProvider ? randomUUID() : `${providerId}-${randomUUID()}`);
|
|
441
|
+
while (reservedIds.has(id) || nativeStoreIds.includes(id)) id = validateMemorySpaceId(randomUUID());
|
|
442
442
|
const connectionInput = request.providerConnections?.[providerId] ?? (this.providerTypeId(providerId) === "openviking" && request.connection === void 0 && request.openViking !== void 0 ? request.openViking : request.connection);
|
|
443
443
|
let connection;
|
|
444
444
|
if (!nativeProvider) {
|
|
@@ -475,19 +475,19 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
475
475
|
createdAt: timestamp,
|
|
476
476
|
updatedAt: timestamp
|
|
477
477
|
};
|
|
478
|
-
this.
|
|
478
|
+
this.spaces.push(body);
|
|
479
479
|
this.save();
|
|
480
480
|
return this.view(body);
|
|
481
481
|
}
|
|
482
482
|
update(id, request) {
|
|
483
483
|
this.refreshIfChanged();
|
|
484
|
-
const normalized =
|
|
485
|
-
const index = this.
|
|
486
|
-
if (index < 0) throw new Error(`unknown memory
|
|
487
|
-
const current = this.
|
|
488
|
-
if (request.openViking !== void 0 && this.providerTypeId(current.providerId) !== "openviking") throw new Error("OpenViking connection settings only apply to OpenViking memory
|
|
484
|
+
const normalized = validateMemorySpaceId(id);
|
|
485
|
+
const index = this.spaces.findIndex((body) => body.id === normalized);
|
|
486
|
+
if (index < 0) throw new Error(`unknown memory space: ${normalized}`);
|
|
487
|
+
const current = this.spaces[index];
|
|
488
|
+
if (request.openViking !== void 0 && this.providerTypeId(current.providerId) !== "openviking") throw new Error("OpenViking connection settings only apply to OpenViking memory spaces");
|
|
489
489
|
const nativeProvider = this.isNative(current.providerId);
|
|
490
|
-
if ((request.connection !== void 0 || request.clearSecrets !== void 0) && nativeProvider) throw new Error("Mnemon Native memory
|
|
490
|
+
if ((request.connection !== void 0 || request.clearSecrets !== void 0) && nativeProvider) throw new Error("Mnemon Native memory spaces do not have provider connection settings");
|
|
491
491
|
const legacyPatch = request.openViking === void 0 ? void 0 : {
|
|
492
492
|
...request.openViking,
|
|
493
493
|
...request.openViking.clearApiKey === true ? { apiKey: "" } : {}
|
|
@@ -519,7 +519,7 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
519
519
|
...connection === void 0 ? {} : { connection },
|
|
520
520
|
updatedAt: this.nextTimestamp(current.updatedAt)
|
|
521
521
|
};
|
|
522
|
-
this.
|
|
522
|
+
this.spaces[index] = body;
|
|
523
523
|
this.save();
|
|
524
524
|
return this.view(body);
|
|
525
525
|
}
|
|
@@ -529,30 +529,30 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
529
529
|
if (updates.length === 0 || updates.length > 20) throw new Error("metadata maintenance requires 1 through 20 Memory Spaces");
|
|
530
530
|
const seen = /* @__PURE__ */ new Set();
|
|
531
531
|
const replacements = updates.map((update) => {
|
|
532
|
-
const id =
|
|
532
|
+
const id = validateMemorySpaceId(update.memoryBodyId);
|
|
533
533
|
if (seen.has(id)) throw new Error(`duplicate metadata update: ${id}`);
|
|
534
534
|
seen.add(id);
|
|
535
|
-
const index = this.
|
|
536
|
-
if (index < 0) throw new Error(`unknown memory
|
|
535
|
+
const index = this.spaces.findIndex((body) => body.id === id);
|
|
536
|
+
if (index < 0) throw new Error(`unknown memory space: ${id}`);
|
|
537
537
|
return {
|
|
538
538
|
index,
|
|
539
539
|
body: {
|
|
540
|
-
...this.
|
|
540
|
+
...this.spaces[index],
|
|
541
541
|
name: requiredText(update.title, "title", 48),
|
|
542
542
|
description: requiredText(update.description, "description", 200),
|
|
543
543
|
metadataSource: "ai",
|
|
544
|
-
updatedAt: this.nextTimestamp(this.
|
|
544
|
+
updatedAt: this.nextTimestamp(this.spaces[index].updatedAt)
|
|
545
545
|
}
|
|
546
546
|
};
|
|
547
547
|
});
|
|
548
|
-
for (const replacement of replacements) this.
|
|
548
|
+
for (const replacement of replacements) this.spaces[replacement.index] = replacement.body;
|
|
549
549
|
this.save();
|
|
550
550
|
return replacements.map((replacement) => this.view(replacement.body));
|
|
551
551
|
}
|
|
552
552
|
async remove(id, signal) {
|
|
553
553
|
const body = this.get(id);
|
|
554
554
|
if (!this.isNative(body.provider.id)) {
|
|
555
|
-
this.
|
|
555
|
+
this.spaces = this.spaces.filter((entry) => entry.id !== body.id);
|
|
556
556
|
this.save();
|
|
557
557
|
return body;
|
|
558
558
|
}
|
|
@@ -590,7 +590,7 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
590
590
|
}
|
|
591
591
|
});
|
|
592
592
|
await this.runner.runTextBatch(commands);
|
|
593
|
-
this.
|
|
593
|
+
this.spaces = this.spaces.filter((entry) => entry.id !== body.id);
|
|
594
594
|
this.save();
|
|
595
595
|
return body;
|
|
596
596
|
}
|
|
@@ -599,14 +599,14 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
599
599
|
}
|
|
600
600
|
/** Advance the safe catalog checkpoint after provider-backed content changes. */
|
|
601
601
|
touch(id) {
|
|
602
|
-
const normalized =
|
|
603
|
-
const index = this.
|
|
604
|
-
if (index < 0) throw new Error(`unknown memory
|
|
602
|
+
const normalized = validateMemorySpaceId(id);
|
|
603
|
+
const index = this.spaces.findIndex((body) => body.id === normalized);
|
|
604
|
+
if (index < 0) throw new Error(`unknown memory space: ${normalized}`);
|
|
605
605
|
const body = {
|
|
606
|
-
...this.
|
|
607
|
-
updatedAt: this.nextTimestamp(this.
|
|
606
|
+
...this.spaces[index],
|
|
607
|
+
updatedAt: this.nextTimestamp(this.spaces[index].updatedAt)
|
|
608
608
|
};
|
|
609
|
-
this.
|
|
609
|
+
this.spaces[index] = body;
|
|
610
610
|
this.save();
|
|
611
611
|
return this.view(body);
|
|
612
612
|
}
|
|
@@ -614,7 +614,7 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
614
614
|
reload() {
|
|
615
615
|
this.refreshing = true;
|
|
616
616
|
try {
|
|
617
|
-
this.
|
|
617
|
+
this.spaces = [];
|
|
618
618
|
this.services = {};
|
|
619
619
|
this.serviceEnabled = {};
|
|
620
620
|
this.loadAndReconcile();
|
|
@@ -646,7 +646,7 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
646
646
|
const parsed = JSON.parse(readFileSync(this.registryPath, "utf8"));
|
|
647
647
|
if ((parsed.version === NATIVE_REGISTRY_VERSION || parsed.version === 2) && Array.isArray(parsed.bodies)) {
|
|
648
648
|
migratedProviderRegistry = parsed.version === 2;
|
|
649
|
-
this.
|
|
649
|
+
this.spaces = parsed.bodies.filter((body) => ID_PATTERN.test(body.id)).map((body) => {
|
|
650
650
|
const syntheticDefault = body.id === "default" && body.name === "默认记忆体" && body.description === "从现有 Mnemon Store 自动接入。";
|
|
651
651
|
migratedSyntheticDefault ||= syntheticDefault;
|
|
652
652
|
const providerId = "providerId" in body && storedProviderId(body.providerId) ? body.providerId : "mnemon-native";
|
|
@@ -686,7 +686,7 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
686
686
|
});
|
|
687
687
|
}
|
|
688
688
|
} catch {
|
|
689
|
-
this.
|
|
689
|
+
this.spaces = [];
|
|
690
690
|
}
|
|
691
691
|
if (this.persistent && existsSync(this.providerRegistryPath)) try {
|
|
692
692
|
const parsed = JSON.parse(readFileSync(this.providerRegistryPath, "utf8"));
|
|
@@ -698,8 +698,8 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
698
698
|
}
|
|
699
699
|
if ((parsed.version === 1 || parsed.version === 2 || parsed.version === 3 || parsed.version === PROVIDER_REGISTRY_VERSION) && Array.isArray(parsed.bodies)) {
|
|
700
700
|
migratedProviderRegistry ||= parsed.version !== PROVIDER_REGISTRY_VERSION;
|
|
701
|
-
const existingIds = new Set(this.
|
|
702
|
-
this.
|
|
701
|
+
const existingIds = new Set(this.spaces.map((body) => body.id));
|
|
702
|
+
this.spaces.push(...parsed.bodies.filter((body) => storedProviderId(body.providerId) && (!this.providerCatalog.has(body.providerId) || !this.isNative(body.providerId)) && ID_PATTERN.test(body.id) && !existingIds.has(body.id)).map((body) => {
|
|
703
703
|
const providerId = body.providerId;
|
|
704
704
|
if (!this.providerCatalog.has(providerId)) return {
|
|
705
705
|
id: body.id,
|
|
@@ -744,9 +744,9 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
744
744
|
}));
|
|
745
745
|
}
|
|
746
746
|
} catch {}
|
|
747
|
-
const retainedBodies = this.
|
|
748
|
-
if (retainedBodies.length !== this.
|
|
749
|
-
this.
|
|
747
|
+
const retainedBodies = this.spaces.filter((body) => !this.providerCatalog.has(body.providerId) || this.isNative(body.providerId) || this.providerServiceEnabled(body.providerId));
|
|
748
|
+
if (retainedBodies.length !== this.spaces.length) {
|
|
749
|
+
this.spaces = retainedBodies;
|
|
750
750
|
migratedProviderRegistry = true;
|
|
751
751
|
}
|
|
752
752
|
this.reconcileDiscoveredStores();
|
|
@@ -759,12 +759,12 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
759
759
|
let changed = false;
|
|
760
760
|
for (const entry of readdirSync(this.directory, { withFileTypes: true })) {
|
|
761
761
|
if (!entry.isDirectory() || !ID_PATTERN.test(entry.name) || !existsSync(join(this.directory, entry.name, "mnemon.db"))) continue;
|
|
762
|
-
if (this.
|
|
763
|
-
this.
|
|
762
|
+
if (this.spaces.some((body) => body.id === entry.name)) continue;
|
|
763
|
+
this.spaces.push({
|
|
764
764
|
id: entry.name,
|
|
765
765
|
name: entry.name,
|
|
766
766
|
description: "Existing Mnemon Store discovered on disk.",
|
|
767
|
-
active: this.
|
|
767
|
+
active: this.spaces.length === 0 || entry.name === legacyActive,
|
|
768
768
|
providerId: "mnemon-native",
|
|
769
769
|
createdAt: timestamp,
|
|
770
770
|
updatedAt: timestamp
|
|
@@ -820,12 +820,12 @@ var MemoryBodyRegistry = class MemoryBodyRegistry {
|
|
|
820
820
|
recursive: true,
|
|
821
821
|
mode: 448
|
|
822
822
|
});
|
|
823
|
-
const nativeBodies = this.
|
|
823
|
+
const nativeBodies = this.spaces.filter((body) => body.providerId === "mnemon-native" || this.providerCatalog.has(body.providerId) && this.isNative(body.providerId)).map(({ providerId: _providerId, connection: _connection, openViking: _openViking, ...body }) => body);
|
|
824
824
|
this.writeRegistry(this.registryPath, {
|
|
825
825
|
version: NATIVE_REGISTRY_VERSION,
|
|
826
826
|
bodies: nativeBodies
|
|
827
827
|
});
|
|
828
|
-
const providerBodies = this.
|
|
828
|
+
const providerBodies = this.spaces.filter((body) => body.providerId !== "mnemon-native" && (!this.providerCatalog.has(body.providerId) || !this.isNative(body.providerId)));
|
|
829
829
|
if (providerBodies.length === 0 && Object.keys(this.services).length === 0) {
|
|
830
830
|
rmSync(this.providerRegistryPath, { force: true });
|
|
831
831
|
this.state.diskRevision = this.diskRevision();
|
|
@@ -1375,10 +1375,12 @@ var MemorySpacesService = class {
|
|
|
1375
1375
|
config;
|
|
1376
1376
|
recallQualityPolicyRegistry;
|
|
1377
1377
|
providerCatalog;
|
|
1378
|
+
memorySpaces;
|
|
1379
|
+
/** @deprecated Use memorySpaces. Both names share the same registry authority. */
|
|
1378
1380
|
memoryBodies;
|
|
1379
1381
|
providers;
|
|
1380
1382
|
recallQualityPolicy;
|
|
1381
|
-
|
|
1383
|
+
spacesInFlight;
|
|
1382
1384
|
providersDisposed = false;
|
|
1383
1385
|
providerTypeId(providerId) {
|
|
1384
1386
|
const catalog = this.providerCatalog;
|
|
@@ -1389,18 +1391,20 @@ var MemorySpacesService = class {
|
|
|
1389
1391
|
isNativeProvider(providerId) {
|
|
1390
1392
|
return this.providerTypeId(providerId) === "mnemon-native";
|
|
1391
1393
|
}
|
|
1392
|
-
|
|
1394
|
+
isNativeSpace(body) {
|
|
1393
1395
|
return (body.provider.typeId ?? body.provider.id) === "mnemon-native";
|
|
1394
1396
|
}
|
|
1395
|
-
constructor(runner, config,
|
|
1397
|
+
constructor(runner, config, memorySpaces, recallQualityPolicyRegistry = recallQualityPolicies, providerAdapterRegistry = new MemoryProviderAdapterRegistry(), providerCatalog = EMPTY_MEMORY_PROVIDER_CATALOG) {
|
|
1396
1398
|
this.runner = runner;
|
|
1397
1399
|
this.config = config;
|
|
1398
1400
|
this.recallQualityPolicyRegistry = recallQualityPolicyRegistry;
|
|
1399
1401
|
this.providerCatalog = providerCatalog;
|
|
1400
|
-
this.
|
|
1402
|
+
this.memorySpaces = memorySpaces === void 0 ? new MemorySpaceRegistry(runner, true, () => /* @__PURE__ */ new Date(), providerCatalog) : providerCatalog === EMPTY_MEMORY_PROVIDER_CATALOG ? memorySpaces : memorySpaces.withProviderCatalog(providerCatalog);
|
|
1403
|
+
this.memoryBodies = this.memorySpaces;
|
|
1401
1404
|
this.recallQualityPolicy = recallQualityPolicyRegistry.resolve(config.recallQuality.policy);
|
|
1402
1405
|
this.providers = providerAdapterRegistry.create({
|
|
1403
|
-
|
|
1406
|
+
memorySpaces: this.memorySpaces,
|
|
1407
|
+
memoryBodies: this.memorySpaces,
|
|
1404
1408
|
config: this.config,
|
|
1405
1409
|
nativeRunner: this.runner
|
|
1406
1410
|
});
|
|
@@ -1418,20 +1422,20 @@ var MemorySpacesService = class {
|
|
|
1418
1422
|
this.providers.clear();
|
|
1419
1423
|
if (failures.length > 0) throw new AggregateError(failures, "Memory Space Provider disposal failed");
|
|
1420
1424
|
}
|
|
1421
|
-
async
|
|
1422
|
-
if (signal !== void 0) return this.
|
|
1423
|
-
if (this.
|
|
1424
|
-
const pending = this.
|
|
1425
|
-
this.
|
|
1425
|
+
async spaces(signal) {
|
|
1426
|
+
if (signal !== void 0) return this.collectSpaces(signal);
|
|
1427
|
+
if (this.spacesInFlight !== void 0) return this.spacesInFlight;
|
|
1428
|
+
const pending = this.collectSpaces();
|
|
1429
|
+
this.spacesInFlight = pending;
|
|
1426
1430
|
try {
|
|
1427
1431
|
return await pending;
|
|
1428
1432
|
} finally {
|
|
1429
|
-
if (this.
|
|
1433
|
+
if (this.spacesInFlight === pending) this.spacesInFlight = void 0;
|
|
1430
1434
|
}
|
|
1431
1435
|
}
|
|
1432
1436
|
/** Coalesce simultaneous Status/Memory-page probes without caching mutations. */
|
|
1433
|
-
async
|
|
1434
|
-
const directory = this.
|
|
1437
|
+
async collectSpaces(signal) {
|
|
1438
|
+
const directory = this.spaceDirectory();
|
|
1435
1439
|
const items = await Promise.all(directory.items.map(async (body) => {
|
|
1436
1440
|
let status;
|
|
1437
1441
|
if (!(body.providerEnabled !== false)) status = {
|
|
@@ -1460,12 +1464,12 @@ var MemorySpacesService = class {
|
|
|
1460
1464
|
};
|
|
1461
1465
|
}
|
|
1462
1466
|
/** Return the control-plane directory without waiting for provider I/O. */
|
|
1463
|
-
|
|
1467
|
+
spaceDirectory() {
|
|
1464
1468
|
const mnemonDefaultStore = this.runner.persistedStore();
|
|
1465
|
-
const all = this.
|
|
1466
|
-
const enabled = new Set(this.
|
|
1469
|
+
const all = this.memorySpaces.list();
|
|
1470
|
+
const enabled = new Set(this.memorySpaces.providerServices().items.filter((service) => service.enabled).map((service) => service.providerId));
|
|
1467
1471
|
const items = all.map((body) => {
|
|
1468
|
-
const nativeProvider = this.
|
|
1472
|
+
const nativeProvider = this.isNativeSpace(body);
|
|
1469
1473
|
const providerEnabled = nativeProvider || enabled.has(body.provider.id);
|
|
1470
1474
|
return {
|
|
1471
1475
|
...body,
|
|
@@ -1489,7 +1493,7 @@ var MemorySpacesService = class {
|
|
|
1489
1493
|
},
|
|
1490
1494
|
total: items.length,
|
|
1491
1495
|
activeCount: items.filter((body) => body.active && body.providerEnabled !== false).length,
|
|
1492
|
-
directory: this.
|
|
1496
|
+
directory: this.memorySpaces.directory,
|
|
1493
1497
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1494
1498
|
};
|
|
1495
1499
|
}
|
|
@@ -1499,11 +1503,11 @@ var MemorySpacesService = class {
|
|
|
1499
1503
|
}
|
|
1500
1504
|
/** One local metadata observation supplies membership and its revision. */
|
|
1501
1505
|
memoryState() {
|
|
1502
|
-
const all = this.
|
|
1503
|
-
const serviceItems = this.
|
|
1506
|
+
const all = this.memorySpaces.list();
|
|
1507
|
+
const serviceItems = this.memorySpaces.providerServices().items;
|
|
1504
1508
|
const enabled = new Set(serviceItems.filter((service) => service.enabled).map((service) => service.providerId));
|
|
1505
|
-
const active = all.filter((body) => body.active && (this.
|
|
1506
|
-
const
|
|
1509
|
+
const active = all.filter((body) => body.active && (this.isNativeSpace(body) || enabled.has(body.provider.id))).sort((left, right) => left.id.localeCompare(right.id));
|
|
1510
|
+
const spaces = [...all].sort((left, right) => left.id.localeCompare(right.id)).map((body) => ({
|
|
1507
1511
|
id: body.id,
|
|
1508
1512
|
name: body.name,
|
|
1509
1513
|
description: body.description,
|
|
@@ -1521,19 +1525,19 @@ var MemorySpacesService = class {
|
|
|
1521
1525
|
all,
|
|
1522
1526
|
active,
|
|
1523
1527
|
revision: createHash("sha256").update(JSON.stringify({
|
|
1524
|
-
bodies,
|
|
1528
|
+
bodies: spaces,
|
|
1525
1529
|
services
|
|
1526
1530
|
})).digest("hex")
|
|
1527
1531
|
};
|
|
1528
1532
|
}
|
|
1529
1533
|
/** Return a usable system snapshot without waiting for any Provider I/O. */
|
|
1530
1534
|
statusSummary() {
|
|
1531
|
-
const catalog = this.
|
|
1535
|
+
const catalog = this.spaceDirectory();
|
|
1532
1536
|
const dshActiveStores = catalog.items.filter((body) => body.active && body.providerEnabled !== false).map((body) => body.id);
|
|
1533
|
-
const providerServices = this.
|
|
1537
|
+
const providerServices = this.memorySpaces.providerServices().items.map((service) => {
|
|
1534
1538
|
const descriptor = this.providerCatalog.descriptor(service.providerId);
|
|
1535
|
-
const
|
|
1536
|
-
const
|
|
1539
|
+
const spaces = catalog.items.filter((body) => body.provider.id === service.providerId);
|
|
1540
|
+
const activeSpaces = spaces.filter((body) => body.active && body.providerEnabled !== false);
|
|
1537
1541
|
return {
|
|
1538
1542
|
providerId: service.providerId,
|
|
1539
1543
|
label: descriptor.label,
|
|
@@ -1541,8 +1545,8 @@ var MemorySpacesService = class {
|
|
|
1541
1545
|
enabled: service.enabled,
|
|
1542
1546
|
configured: service.configured,
|
|
1543
1547
|
status: !service.enabled ? "disabled" : "idle",
|
|
1544
|
-
memoryBodyCount:
|
|
1545
|
-
activeMemoryBodyCount:
|
|
1548
|
+
memoryBodyCount: spaces.length,
|
|
1549
|
+
activeMemoryBodyCount: activeSpaces.length
|
|
1546
1550
|
};
|
|
1547
1551
|
});
|
|
1548
1552
|
return {
|
|
@@ -1582,9 +1586,9 @@ var MemorySpacesService = class {
|
|
|
1582
1586
|
};
|
|
1583
1587
|
}
|
|
1584
1588
|
async status(signal) {
|
|
1585
|
-
const
|
|
1589
|
+
const hasNativeSpace = this.memorySpaces.list().some((body) => this.isNativeSpace(body));
|
|
1586
1590
|
let versionError;
|
|
1587
|
-
const [catalog, rawVersion] = await Promise.all([this.
|
|
1591
|
+
const [catalog, rawVersion] = await Promise.all([this.spaces(signal), hasNativeSpace ? this.runner.runText(["--version"], signal === void 0 ? { globalFlags: false } : {
|
|
1588
1592
|
signal,
|
|
1589
1593
|
globalFlags: false
|
|
1590
1594
|
}).catch((error) => {
|
|
@@ -1592,12 +1596,12 @@ var MemorySpacesService = class {
|
|
|
1592
1596
|
}) : Promise.resolve(void 0)]);
|
|
1593
1597
|
const active = catalog.items.filter((body) => body.active && body.providerEnabled !== false);
|
|
1594
1598
|
const dshActiveStores = active.map((body) => body.id);
|
|
1595
|
-
const providerServices = this.
|
|
1599
|
+
const providerServices = this.memorySpaces.providerServices().items.map((service) => {
|
|
1596
1600
|
const descriptor = this.providerCatalog.descriptor(service.providerId);
|
|
1597
|
-
const
|
|
1598
|
-
const
|
|
1599
|
-
const failed =
|
|
1600
|
-
const status = !service.enabled ? "disabled" :
|
|
1601
|
+
const spaces = catalog.items.filter((body) => body.provider.id === service.providerId);
|
|
1602
|
+
const activeSpaces = spaces.filter((body) => body.active && body.providerEnabled !== false);
|
|
1603
|
+
const failed = activeSpaces.filter((body) => !body.healthy);
|
|
1604
|
+
const status = !service.enabled ? "disabled" : activeSpaces.length === 0 ? "idle" : failed.length === 0 ? "healthy" : "unhealthy";
|
|
1601
1605
|
return {
|
|
1602
1606
|
providerId: service.providerId,
|
|
1603
1607
|
label: descriptor.label,
|
|
@@ -1605,8 +1609,8 @@ var MemorySpacesService = class {
|
|
|
1605
1609
|
enabled: service.enabled,
|
|
1606
1610
|
configured: service.configured,
|
|
1607
1611
|
status,
|
|
1608
|
-
memoryBodyCount:
|
|
1609
|
-
activeMemoryBodyCount:
|
|
1612
|
+
memoryBodyCount: spaces.length,
|
|
1613
|
+
activeMemoryBodyCount: activeSpaces.length,
|
|
1610
1614
|
...failed.length === 0 ? {} : { error: failed.map((body) => `${body.name}: ${body.error ?? "unavailable"}`).join("; ") }
|
|
1611
1615
|
};
|
|
1612
1616
|
});
|
|
@@ -1627,19 +1631,19 @@ var MemorySpacesService = class {
|
|
|
1627
1631
|
};
|
|
1628
1632
|
try {
|
|
1629
1633
|
if (versionError !== void 0) throw versionError;
|
|
1630
|
-
const
|
|
1634
|
+
const healthySpaces = active.filter((body) => body.healthy && body.stats !== void 0);
|
|
1631
1635
|
const topEntities = /* @__PURE__ */ new Map();
|
|
1632
1636
|
const byCategory = {};
|
|
1633
|
-
for (const body of
|
|
1637
|
+
for (const body of healthySpaces) {
|
|
1634
1638
|
for (const [category, count] of Object.entries(body.stats.byCategory)) byCategory[category] = (byCategory[category] ?? 0) + count;
|
|
1635
1639
|
for (const entity of body.stats.topEntities) topEntities.set(entity.entity, (topEntities.get(entity.entity) ?? 0) + entity.count);
|
|
1636
1640
|
}
|
|
1637
1641
|
const stats = {
|
|
1638
|
-
totalInsights:
|
|
1639
|
-
deletedInsights:
|
|
1640
|
-
edgeCount:
|
|
1641
|
-
oplogCount:
|
|
1642
|
-
dbSizeBytes:
|
|
1642
|
+
totalInsights: healthySpaces.reduce((total, body) => total + body.stats.totalInsights, 0),
|
|
1643
|
+
deletedInsights: healthySpaces.reduce((total, body) => total + body.stats.deletedInsights, 0),
|
|
1644
|
+
edgeCount: healthySpaces.reduce((total, body) => total + body.stats.edgeCount, 0),
|
|
1645
|
+
oplogCount: healthySpaces.reduce((total, body) => total + body.stats.oplogCount, 0),
|
|
1646
|
+
dbSizeBytes: healthySpaces.reduce((total, body) => total + body.stats.dbSizeBytes, 0),
|
|
1643
1647
|
byCategory,
|
|
1644
1648
|
topEntities: [...topEntities].map(([entity, count]) => ({
|
|
1645
1649
|
entity,
|
|
@@ -1663,11 +1667,11 @@ var MemorySpacesService = class {
|
|
|
1663
1667
|
};
|
|
1664
1668
|
}
|
|
1665
1669
|
}
|
|
1666
|
-
async
|
|
1667
|
-
const body = this.
|
|
1668
|
-
if (body === void 0) throw new Error(`unknown memory
|
|
1669
|
-
if (!this.
|
|
1670
|
-
if (!this.
|
|
1670
|
+
async reconnectSpace(id, signal) {
|
|
1671
|
+
const body = this.memorySpaces.list().find((candidate) => candidate.id === id);
|
|
1672
|
+
if (body === void 0) throw new Error(`unknown memory space: ${id}`);
|
|
1673
|
+
if (!this.isNativeSpace(body)) {
|
|
1674
|
+
if (!this.memorySpaces.providerServiceEnabled(body.provider.id)) throw new Error(`${body.provider.label} is disabled in Settings`);
|
|
1671
1675
|
}
|
|
1672
1676
|
const provider = this.providerFor(body);
|
|
1673
1677
|
provider.invalidateStatus?.(body.id);
|
|
@@ -1675,7 +1679,7 @@ var MemorySpacesService = class {
|
|
|
1675
1679
|
return {
|
|
1676
1680
|
...body,
|
|
1677
1681
|
providerEnabled: true,
|
|
1678
|
-
mnemonDefault: this.
|
|
1682
|
+
mnemonDefault: this.isNativeSpace(body) && body.id === this.runner.persistedStore(),
|
|
1679
1683
|
...status
|
|
1680
1684
|
};
|
|
1681
1685
|
}
|
|
@@ -1695,7 +1699,7 @@ var MemorySpacesService = class {
|
|
|
1695
1699
|
const category = allowed(request.category, CATEGORIES$1, "category");
|
|
1696
1700
|
const source = allowed(request.source, SOURCES$1, "source");
|
|
1697
1701
|
const intent = allowed(request.intent, INTENTS$1, "intent");
|
|
1698
|
-
const
|
|
1702
|
+
const spaces = this.readSpaces(request.memoryBodyIds);
|
|
1699
1703
|
const normalizedRequest = {
|
|
1700
1704
|
query,
|
|
1701
1705
|
mode,
|
|
@@ -1704,7 +1708,7 @@ var MemorySpacesService = class {
|
|
|
1704
1708
|
...source === void 0 ? {} : { source },
|
|
1705
1709
|
...intent === void 0 ? {} : { intent }
|
|
1706
1710
|
};
|
|
1707
|
-
let batches = await Promise.all(
|
|
1711
|
+
let batches = await Promise.all(spaces.map(async (body) => {
|
|
1708
1712
|
if (!body.provider.capabilities.search) return {
|
|
1709
1713
|
body,
|
|
1710
1714
|
result: {
|
|
@@ -1748,7 +1752,7 @@ var MemorySpacesService = class {
|
|
|
1748
1752
|
})));
|
|
1749
1753
|
if (result.hint !== void 0) hints.push(`${body.name}: ${result.hint}`);
|
|
1750
1754
|
}
|
|
1751
|
-
const heterogeneous = new Set(
|
|
1755
|
+
const heterogeneous = new Set(spaces.map((body) => body.provider.id)).size > 1;
|
|
1752
1756
|
if (heterogeneous) for (const candidate of candidates) candidate.insight.federatedScore = 1 / (60 + candidate.providerRank);
|
|
1753
1757
|
candidates.sort((left, right) => heterogeneous ? (right.insight.federatedScore ?? 0) - (left.insight.federatedScore ?? 0) || left.bodyOrder - right.bodyOrder : (right.insight.score ?? 0) - (left.insight.score ?? 0));
|
|
1754
1758
|
return {
|
|
@@ -1760,7 +1764,7 @@ var MemorySpacesService = class {
|
|
|
1760
1764
|
const hasRecoveryEvidence = recoveryPlan !== void 0 && evaluation.quality.selected.some((candidate) => recoveryMatchCount(candidate.candidate.insight.content, recoveryPlan) >= recoveryPlan.requiredMatches);
|
|
1761
1765
|
if (recoveryPlan !== void 0 && !hasRecoveryEvidence) {
|
|
1762
1766
|
batches = await Promise.all(batches.map(async (batch) => {
|
|
1763
|
-
if (!this.
|
|
1767
|
+
if (!this.isNativeSpace(batch.body) || batch.source.status === "unsupported" || batch.source.status === "unavailable") return batch;
|
|
1764
1768
|
try {
|
|
1765
1769
|
const recovered = await this.providerFor(batch.body).search(batch.body, {
|
|
1766
1770
|
query: recoveryPlan.query,
|
|
@@ -1830,12 +1834,12 @@ var MemorySpacesService = class {
|
|
|
1830
1834
|
* expansion, and large browse projections before an LLM metadata pass.
|
|
1831
1835
|
*/
|
|
1832
1836
|
async metadataSample(memoryBodyId, signal) {
|
|
1833
|
-
const body = this.
|
|
1837
|
+
const body = this.readSpaces([memoryBodyId])[0];
|
|
1834
1838
|
const provider = this.providerFor(body);
|
|
1835
1839
|
const limit = 6;
|
|
1836
1840
|
let method;
|
|
1837
1841
|
let items;
|
|
1838
|
-
if (this.
|
|
1842
|
+
if (this.isNativeSpace(body)) {
|
|
1839
1843
|
method = "native-basic";
|
|
1840
1844
|
items = provider.metadataSample === void 0 ? await provider.list(body, { limit }, signal) : await provider.metadataSample(body, limit, signal);
|
|
1841
1845
|
} else if (METADATA_SEARCH_FIRST_PROVIDERS.has(body.provider.typeId ?? body.provider.id) || !body.provider.capabilities.browse) {
|
|
@@ -1865,11 +1869,11 @@ var MemorySpacesService = class {
|
|
|
1865
1869
|
};
|
|
1866
1870
|
}
|
|
1867
1871
|
async graph(signal, memoryBodyIds) {
|
|
1868
|
-
const
|
|
1872
|
+
const spaces = this.readSpaces(memoryBodyIds);
|
|
1869
1873
|
const nodes = [];
|
|
1870
1874
|
const edges = [];
|
|
1871
1875
|
const sources = [];
|
|
1872
|
-
const snapshots = await Promise.all(
|
|
1876
|
+
const snapshots = await Promise.all(spaces.map(async (body) => {
|
|
1873
1877
|
const mode = body.provider.capabilities.graph ? "graph" : body.provider.capabilities.browse ? "projection" : body.provider.capabilities.search ? "query-only" : "unsupported";
|
|
1874
1878
|
if (mode === "query-only") return {
|
|
1875
1879
|
body,
|
|
@@ -1922,7 +1926,7 @@ var MemorySpacesService = class {
|
|
|
1922
1926
|
nodes,
|
|
1923
1927
|
edges,
|
|
1924
1928
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1925
|
-
memoryBodies:
|
|
1929
|
+
memoryBodies: spaces.map(({ id, name, active }) => ({
|
|
1926
1930
|
id,
|
|
1927
1931
|
name,
|
|
1928
1932
|
active
|
|
@@ -1936,8 +1940,8 @@ var MemorySpacesService = class {
|
|
|
1936
1940
|
if (rawQuery.length > 500) throw new Error("query is too long (max 500 characters)");
|
|
1937
1941
|
const category = allowed(request.category, CATEGORIES$1, "category");
|
|
1938
1942
|
const limit = boundedInteger(request.limit, 200, 1, 1e3);
|
|
1939
|
-
const
|
|
1940
|
-
const batches = await Promise.all(
|
|
1943
|
+
const spaces = this.readSpaces(request.memoryBodyIds);
|
|
1944
|
+
const batches = await Promise.all(spaces.map(async (body) => {
|
|
1941
1945
|
const mode = body.provider.capabilities.browse ? "enumerable" : body.provider.capabilities.search ? "query-only" : "unsupported";
|
|
1942
1946
|
if (mode === "query-only" && rawQuery === "") return {
|
|
1943
1947
|
body,
|
|
@@ -1983,7 +1987,7 @@ var MemorySpacesService = class {
|
|
|
1983
1987
|
};
|
|
1984
1988
|
}
|
|
1985
1989
|
async entities(entity, limit, signal) {
|
|
1986
|
-
const active = (await this.
|
|
1990
|
+
const active = (await this.spaces(signal)).items.filter((body) => body.active);
|
|
1987
1991
|
const capable = active.filter((body) => body.provider.capabilities.entities);
|
|
1988
1992
|
const entityCounts = /* @__PURE__ */ new Map();
|
|
1989
1993
|
for (const body of capable) for (const item of body.stats?.topEntities ?? []) entityCounts.set(item.entity, (entityCounts.get(item.entity) ?? 0) + item.count);
|
|
@@ -2043,7 +2047,7 @@ var MemorySpacesService = class {
|
|
|
2043
2047
|
const provider = this.providerFor(body);
|
|
2044
2048
|
let providerChanged = false;
|
|
2045
2049
|
const batchWriter = provider.rememberMany;
|
|
2046
|
-
const batch = batchWriter === void 0 ? [] : group.filter((entry) => !this.
|
|
2050
|
+
const batch = batchWriter === void 0 ? [] : group.filter((entry) => !this.isNativeSpace(body) || entry.request.content.length <= 8e3);
|
|
2047
2051
|
if (batchWriter !== void 0 && batch.length > 0) {
|
|
2048
2052
|
const written = await batchWriter.call(provider, body, batch.map((entry) => entry.request), signal);
|
|
2049
2053
|
if (written.length !== batch.length) throw new Error(`batch remember did not return one receipt per request for Memory Space ${body.id}`);
|
|
@@ -2064,7 +2068,7 @@ var MemorySpacesService = class {
|
|
|
2064
2068
|
return results;
|
|
2065
2069
|
}
|
|
2066
2070
|
async related(id, depth = 2, edge, signal, memoryBodyId) {
|
|
2067
|
-
const body = this.
|
|
2071
|
+
const body = this.readSpace(memoryBodyId);
|
|
2068
2072
|
const selectedEdge = allowed(edge, EDGE_TYPES, "edge");
|
|
2069
2073
|
const provider = this.providerFor(body);
|
|
2070
2074
|
if (provider.related === void 0 || !body.provider.capabilities.related) throw new Error(`${body.provider.label} does not support related-memory traversal`);
|
|
@@ -2072,7 +2076,7 @@ var MemorySpacesService = class {
|
|
|
2072
2076
|
}
|
|
2073
2077
|
async link(sourceId, targetId, type = "semantic", weight = .5, reason, signal, memoryBodyId) {
|
|
2074
2078
|
this.assertWritable();
|
|
2075
|
-
const body = this.
|
|
2079
|
+
const body = this.writeSpace(memoryBodyId);
|
|
2076
2080
|
if (!Number.isFinite(weight) || weight < 0 || weight > 1) throw new Error("weight must be within 0..1");
|
|
2077
2081
|
const selectedType = allowed(type, EDGE_TYPES, "type") ?? "semantic";
|
|
2078
2082
|
const provider = this.providerFor(body);
|
|
@@ -2083,35 +2087,35 @@ var MemorySpacesService = class {
|
|
|
2083
2087
|
}
|
|
2084
2088
|
async forget(id, signal, memoryBodyId) {
|
|
2085
2089
|
this.assertWritable();
|
|
2086
|
-
const body = this.
|
|
2090
|
+
const body = this.writeSpace(memoryBodyId);
|
|
2087
2091
|
const provider = this.providerFor(body);
|
|
2088
2092
|
if (provider.forget === void 0 || !body.provider.capabilities.forget) throw new Error(`${body.provider.label} does not expose safe forget semantics in this integration`);
|
|
2089
2093
|
const result = await provider.forget(body, required(id, "id", 2e3), signal);
|
|
2090
2094
|
this.activateAfterWrite(body, mutationResultCommitted(result));
|
|
2091
2095
|
return this.annotateResult(result, body);
|
|
2092
2096
|
}
|
|
2093
|
-
|
|
2097
|
+
prepareSpacePlacement(request) {
|
|
2094
2098
|
if (request.placement === void 0) throw new Error("automatic provider placement request is required");
|
|
2095
2099
|
if (request.providerId !== void 0) throw new Error("automatic provider placement cannot include a fixed providerId");
|
|
2096
|
-
return prepareMemoryPlacement(request.placement, this.
|
|
2100
|
+
return prepareMemoryPlacement(request.placement, this.memorySpaces.placementCandidates(request));
|
|
2097
2101
|
}
|
|
2098
|
-
async
|
|
2102
|
+
async createSpace(request, signal, placement) {
|
|
2099
2103
|
this.assertWritable();
|
|
2100
|
-
return await this.
|
|
2104
|
+
return await this.memorySpaces.create(request, signal, placement);
|
|
2101
2105
|
}
|
|
2102
2106
|
/**
|
|
2103
2107
|
* Create a Memory Space from the configured distillation policy. The model
|
|
2104
2108
|
* may choose only among candidates already filtered by the host; manual mode
|
|
2105
2109
|
* ignores model preference and always uses the configured fixed provider.
|
|
2106
2110
|
*/
|
|
2107
|
-
async
|
|
2111
|
+
async createSpaceForPersistence(body, selection, signal, delegation = {
|
|
2108
2112
|
runId: "memory-write",
|
|
2109
2113
|
provider: "task-agent"
|
|
2110
2114
|
}) {
|
|
2111
2115
|
const strategy = this.config.persistenceStrategy;
|
|
2112
2116
|
if (strategy.mode === "manual") {
|
|
2113
2117
|
const connection = strategy.providerConnections[strategy.providerId];
|
|
2114
|
-
return this.
|
|
2118
|
+
return this.createSpace({
|
|
2115
2119
|
...body,
|
|
2116
2120
|
providerId: strategy.providerId,
|
|
2117
2121
|
...this.isNativeProvider(strategy.providerId) || connection === void 0 ? {} : { connection }
|
|
@@ -2126,45 +2130,45 @@ var MemorySpacesService = class {
|
|
|
2126
2130
|
},
|
|
2127
2131
|
...Object.keys(strategy.providerConnections).length === 0 ? {} : { providerConnections: strategy.providerConnections }
|
|
2128
2132
|
};
|
|
2129
|
-
const prepared = this.
|
|
2133
|
+
const prepared = this.prepareSpacePlacement(request);
|
|
2130
2134
|
const decision = rulesOnlyPlacement(prepared) ?? finalizeLlmPlacement(prepared, selection ?? {
|
|
2131
2135
|
providerId: "",
|
|
2132
2136
|
reason: "",
|
|
2133
2137
|
confidence: ""
|
|
2134
2138
|
}, delegation);
|
|
2135
|
-
return this.
|
|
2139
|
+
return this.createSpace(request, signal, decision);
|
|
2136
2140
|
}
|
|
2137
2141
|
async updateProviderService(providerId, settings, clearSecrets = [], enabled = true, signal) {
|
|
2138
2142
|
this.assertWritable();
|
|
2139
2143
|
if (this.isNativeProvider(providerId)) throw new Error("Mnemon Native service settings are managed by the native configuration");
|
|
2140
|
-
if (!enabled) return this.
|
|
2141
|
-
const connection = this.
|
|
2144
|
+
if (!enabled) return this.memorySpaces.updateProviderService(providerId, settings, clearSecrets, false);
|
|
2145
|
+
const connection = this.memorySpaces.resolveProviderService(providerId, settings, clearSecrets);
|
|
2142
2146
|
const provider = this.providers.get(providerId);
|
|
2143
2147
|
if (provider?.discover === void 0) throw new Error(`${this.providerCatalog.descriptor(providerId).label} does not support Memory Space discovery`);
|
|
2144
2148
|
const discovered = await provider.discover(connection, signal);
|
|
2145
|
-
return this.
|
|
2149
|
+
return this.memorySpaces.syncProviderService(providerId, connection, discovered);
|
|
2146
2150
|
}
|
|
2147
|
-
|
|
2151
|
+
updateSpace(id, request) {
|
|
2148
2152
|
this.assertWritable();
|
|
2149
|
-
return this.
|
|
2153
|
+
return this.memorySpaces.update(id, request);
|
|
2150
2154
|
}
|
|
2151
|
-
|
|
2155
|
+
updateSpaceMetadata(updates) {
|
|
2152
2156
|
this.assertWritable();
|
|
2153
|
-
return this.
|
|
2157
|
+
return this.memorySpaces.updateMetadata(updates);
|
|
2154
2158
|
}
|
|
2155
|
-
async
|
|
2159
|
+
async deleteSpace(id, signal) {
|
|
2156
2160
|
this.assertWritable();
|
|
2157
|
-
return await this.
|
|
2161
|
+
return await this.memorySpaces.remove(id, signal);
|
|
2158
2162
|
}
|
|
2159
|
-
async
|
|
2163
|
+
async mergeSpaces(targetSpaceId, sourceSpaceIds, deactivateSources = true, signal) {
|
|
2160
2164
|
this.assertWritable();
|
|
2161
|
-
const target = this.
|
|
2162
|
-
if (!this.
|
|
2163
|
-
const sourceIds = [...new Set(
|
|
2164
|
-
if (sourceIds.length === 0) throw new Error("sourceMemoryBodyIds requires at least one memory
|
|
2165
|
-
if (sourceIds.includes(target.id)) throw new Error("target memory
|
|
2166
|
-
const sources = sourceIds.map((id) => this.
|
|
2167
|
-
if (sources.some((source) => !this.
|
|
2165
|
+
const target = this.memorySpaces.get(targetSpaceId);
|
|
2166
|
+
if (!this.isNativeSpace(target)) throw new Error("memory-space merge currently requires a Mnemon Native target");
|
|
2167
|
+
const sourceIds = [...new Set(sourceSpaceIds.map((id) => id.trim()).filter((id) => id !== ""))];
|
|
2168
|
+
if (sourceIds.length === 0) throw new Error("sourceMemoryBodyIds requires at least one memory space");
|
|
2169
|
+
if (sourceIds.includes(target.id)) throw new Error("target memory space cannot also be a merge source");
|
|
2170
|
+
const sources = sourceIds.map((id) => this.memorySpaces.get(id));
|
|
2171
|
+
if (sources.some((source) => !this.isNativeSpace(source))) throw new Error("memory-space merge currently supports Mnemon Native sources only");
|
|
2168
2172
|
const insights = [];
|
|
2169
2173
|
const edges = [];
|
|
2170
2174
|
for (const source of sources) {
|
|
@@ -2197,7 +2201,7 @@ var MemorySpacesService = class {
|
|
|
2197
2201
|
if (insights.length === 0) {
|
|
2198
2202
|
if (deactivateSources) for (const source of sources) {
|
|
2199
2203
|
if (!source.active) continue;
|
|
2200
|
-
this.
|
|
2204
|
+
this.memorySpaces.setActive(source.id, false);
|
|
2201
2205
|
}
|
|
2202
2206
|
return {
|
|
2203
2207
|
action: "merged",
|
|
@@ -2234,7 +2238,7 @@ var MemorySpacesService = class {
|
|
|
2234
2238
|
this.activateAfterWrite(target, complete);
|
|
2235
2239
|
if (deactivateSources && complete) for (const source of sources) {
|
|
2236
2240
|
if (!source.active) continue;
|
|
2237
|
-
this.
|
|
2241
|
+
this.memorySpaces.setActive(source.id, false);
|
|
2238
2242
|
}
|
|
2239
2243
|
const completion = mutationResultCompletion(result);
|
|
2240
2244
|
return this.annotateResult({
|
|
@@ -2253,39 +2257,39 @@ var MemorySpacesService = class {
|
|
|
2253
2257
|
if (provider === void 0) throw new Error(`unsupported memory provider: ${body.provider.id}`);
|
|
2254
2258
|
return provider;
|
|
2255
2259
|
}
|
|
2256
|
-
|
|
2257
|
-
const active = this.
|
|
2260
|
+
readSpaces(ids) {
|
|
2261
|
+
const active = this.memorySpaces.active();
|
|
2258
2262
|
if (ids === void 0 || ids.length === 0) return active;
|
|
2259
2263
|
return [...new Set(ids.map((id) => id.trim()).filter((id) => id !== ""))].map((id) => {
|
|
2260
|
-
const body = this.
|
|
2261
|
-
if (!body.active) throw new Error(`memory
|
|
2262
|
-
if (!this.
|
|
2264
|
+
const body = this.memorySpaces.get(id);
|
|
2265
|
+
if (!body.active) throw new Error(`memory space is not active for reading: ${id}`);
|
|
2266
|
+
if (!this.isNativeSpace(body) && !this.memorySpaces.providerServiceEnabled(body.provider.id)) throw new Error(`${body.provider.label} is disabled in Settings`);
|
|
2263
2267
|
return body;
|
|
2264
2268
|
});
|
|
2265
2269
|
}
|
|
2266
|
-
|
|
2270
|
+
readSpace(id) {
|
|
2267
2271
|
if (id !== void 0 && id.trim() !== "") {
|
|
2268
|
-
const body = this.
|
|
2269
|
-
if (!body.active) throw new Error(`memory
|
|
2270
|
-
if (!this.
|
|
2272
|
+
const body = this.memorySpaces.get(id);
|
|
2273
|
+
if (!body.active) throw new Error(`memory space is not active for reading: ${body.id}`);
|
|
2274
|
+
if (!this.isNativeSpace(body) && !this.memorySpaces.providerServiceEnabled(body.provider.id)) throw new Error(`${body.provider.label} is disabled in Settings`);
|
|
2271
2275
|
return body;
|
|
2272
2276
|
}
|
|
2273
|
-
const active = this.
|
|
2274
|
-
if (active.length !== 1) throw new Error("memoryBodyId is required when the number of active memory
|
|
2277
|
+
const active = this.memorySpaces.active();
|
|
2278
|
+
if (active.length !== 1) throw new Error("memoryBodyId is required when the number of active memory spaces is not exactly one");
|
|
2275
2279
|
return active[0];
|
|
2276
2280
|
}
|
|
2277
|
-
|
|
2281
|
+
writeSpace(id) {
|
|
2278
2282
|
if (id !== void 0 && id.trim() !== "") {
|
|
2279
|
-
const body = this.
|
|
2280
|
-
if (!this.
|
|
2283
|
+
const body = this.memorySpaces.get(id);
|
|
2284
|
+
if (!this.isNativeSpace(body) && !this.memorySpaces.providerServiceEnabled(body.provider.id)) throw new Error(`${body.provider.label} is disabled in Settings`);
|
|
2281
2285
|
return body;
|
|
2282
2286
|
}
|
|
2283
|
-
const active = this.
|
|
2284
|
-
if (active.length !== 1) throw new Error("memoryBodyId is required when the number of active memory
|
|
2287
|
+
const active = this.memorySpaces.active();
|
|
2288
|
+
if (active.length !== 1) throw new Error("memoryBodyId is required when the number of active memory spaces is not exactly one");
|
|
2285
2289
|
return active[0];
|
|
2286
2290
|
}
|
|
2287
2291
|
prepareRemember(request) {
|
|
2288
|
-
const body = this.
|
|
2292
|
+
const body = this.writeSpace(request.memoryBodyId);
|
|
2289
2293
|
const content = required(request.content, "content", 8192);
|
|
2290
2294
|
const importance = boundedInteger(request.importance, 3, 1, 5);
|
|
2291
2295
|
const category = allowed(request.category, CATEGORIES$1, "category") ?? "general";
|
|
@@ -2327,12 +2331,52 @@ var MemorySpacesService = class {
|
|
|
2327
2331
|
}
|
|
2328
2332
|
activateAfterWrite(body, providerChanged) {
|
|
2329
2333
|
if (!providerChanged) return;
|
|
2330
|
-
if (!body.active) this.
|
|
2331
|
-
else this.
|
|
2334
|
+
if (!body.active) this.memorySpaces.setActive(body.id, true);
|
|
2335
|
+
else this.memorySpaces.touch(body.id);
|
|
2332
2336
|
}
|
|
2333
2337
|
assertWritable() {
|
|
2334
2338
|
if (!this.config.writeEnabled) throw new Error("dsh-mnemon is configured read-only (writeEnabled: false)");
|
|
2335
2339
|
}
|
|
2340
|
+
/** @deprecated Use spaces. */
|
|
2341
|
+
bodies(...args) {
|
|
2342
|
+
return this.spaces(...args);
|
|
2343
|
+
}
|
|
2344
|
+
/** @deprecated Use spaceDirectory. */
|
|
2345
|
+
bodyDirectory(...args) {
|
|
2346
|
+
return this.spaceDirectory(...args);
|
|
2347
|
+
}
|
|
2348
|
+
/** @deprecated Use reconnectSpace. */
|
|
2349
|
+
reconnectBody(...args) {
|
|
2350
|
+
return this.reconnectSpace(...args);
|
|
2351
|
+
}
|
|
2352
|
+
/** @deprecated Use prepareSpacePlacement. */
|
|
2353
|
+
prepareBodyPlacement(...args) {
|
|
2354
|
+
return this.prepareSpacePlacement(...args);
|
|
2355
|
+
}
|
|
2356
|
+
/** @deprecated Use createSpace. */
|
|
2357
|
+
createBody(...args) {
|
|
2358
|
+
return this.createSpace(...args);
|
|
2359
|
+
}
|
|
2360
|
+
/** @deprecated Use createSpaceForPersistence. */
|
|
2361
|
+
createBodyForPersistence(...args) {
|
|
2362
|
+
return this.createSpaceForPersistence(...args);
|
|
2363
|
+
}
|
|
2364
|
+
/** @deprecated Use updateSpace. */
|
|
2365
|
+
updateBody(...args) {
|
|
2366
|
+
return this.updateSpace(...args);
|
|
2367
|
+
}
|
|
2368
|
+
/** @deprecated Use updateSpaceMetadata. */
|
|
2369
|
+
updateBodyMetadata(...args) {
|
|
2370
|
+
return this.updateSpaceMetadata(...args);
|
|
2371
|
+
}
|
|
2372
|
+
/** @deprecated Use deleteSpace. */
|
|
2373
|
+
deleteBody(...args) {
|
|
2374
|
+
return this.deleteSpace(...args);
|
|
2375
|
+
}
|
|
2376
|
+
/** @deprecated Use mergeSpaces. */
|
|
2377
|
+
mergeBodies(...args) {
|
|
2378
|
+
return this.mergeSpaces(...args);
|
|
2379
|
+
}
|
|
2336
2380
|
};
|
|
2337
2381
|
//#endregion
|
|
2338
2382
|
//#region src/runner.ts
|
|
@@ -2401,7 +2445,10 @@ function createRunner(config, processRunner = runProcess, workspaceRoot) {
|
|
|
2401
2445
|
try {
|
|
2402
2446
|
const command = currentCommand();
|
|
2403
2447
|
const launcher = mnemonNpmLauncher(command);
|
|
2404
|
-
result = await processRunner(launcher === void 0 ? command : process.execPath, launcher === void 0 ? argv : [launcher, ...argv], processOptions
|
|
2448
|
+
result = await processRunner(launcher === void 0 ? command : process.execPath, launcher === void 0 ? argv : [launcher, ...argv], launcher === void 0 ? processOptions : {
|
|
2449
|
+
...processOptions,
|
|
2450
|
+
env: nodeLauncherEnvironment(processOptions.env)
|
|
2451
|
+
});
|
|
2405
2452
|
} catch (error) {
|
|
2406
2453
|
throw new MnemonCliError(`${error instanceof Error ? error.message : String(error)}. ${process.platform === "win32" ? "Install the official Mnemon Windows release, ensure mnemon.exe is on PATH or under %LOCALAPPDATA%\\Programs\\mnemon, or set MNEMON_CLI_PATH or mnemon.cliPath to its absolute path." : "Install Mnemon and ensure \"mnemon\" is on PATH, or set MNEMON_CLI_PATH or mnemon.cliPath."}`);
|
|
2407
2454
|
}
|
|
@@ -2640,7 +2687,7 @@ function providerConnections(value) {
|
|
|
2640
2687
|
const input = memoryInputRecord(value, "providerConnections");
|
|
2641
2688
|
return Object.fromEntries(Object.entries(input).map(([providerId, connection]) => [memoryInputText(providerId, "providerId", 128), scalarRecord(connection, `providerConnections.${providerId}`)]));
|
|
2642
2689
|
}
|
|
2643
|
-
function
|
|
2690
|
+
function createSpaceRequest(value) {
|
|
2644
2691
|
const input = memoryInputRecord(value, "Memory Space body-create request");
|
|
2645
2692
|
const providerId = memoryInputText(input.providerId, "providerId", 128, false);
|
|
2646
2693
|
const connection = scalarRecord(input.connection, "connection");
|
|
@@ -2669,7 +2716,7 @@ function createBodyRequest(value) {
|
|
|
2669
2716
|
...placement === void 0 ? {} : { placement }
|
|
2670
2717
|
};
|
|
2671
2718
|
}
|
|
2672
|
-
function
|
|
2719
|
+
function updateSpaceRequest(value) {
|
|
2673
2720
|
const input = memoryInputRecord(value, "Memory Space body-update request");
|
|
2674
2721
|
const connection = scalarRecord(input.connection, "connection");
|
|
2675
2722
|
return {
|
|
@@ -2711,9 +2758,9 @@ async function manageMemorySpaces(service, request) {
|
|
|
2711
2758
|
case "embedding-status": return managementResult(service, await service.embeddingStatus(request.signal));
|
|
2712
2759
|
case "status-summary": return managementResult(service, service.statusSummary());
|
|
2713
2760
|
case "status": return managementResult(service, await service.status(request.signal));
|
|
2714
|
-
case "body-directory": return managementResult(service, service.
|
|
2715
|
-
case "bodies": return managementResult(service, await service.
|
|
2716
|
-
case "provider-services": return managementResult(service, service.
|
|
2761
|
+
case "body-directory": return managementResult(service, service.spaceDirectory());
|
|
2762
|
+
case "bodies": return managementResult(service, await service.spaces(request.signal));
|
|
2763
|
+
case "provider-services": return managementResult(service, service.memorySpaces.providerServices());
|
|
2717
2764
|
case "graph": return managementResult(service, await service.graph(request.signal, memoryInputStringArray(input.memoryBodyIds, "memoryBodyIds", 1e4)));
|
|
2718
2765
|
case "list": return managementResult(service, await service.list({
|
|
2719
2766
|
...memoryInputText(input.query, "query", 2e3, false) === void 0 ? {} : { query: memoryInputText(input.query, "query", 2e3, false) },
|
|
@@ -2732,8 +2779,8 @@ async function manageMemorySpaces(service, request) {
|
|
|
2732
2779
|
...memoryInputStringArray(input.memoryBodyIds, "memoryBodyIds", 1e4) === void 0 ? {} : { memoryBodyIds: memoryInputStringArray(input.memoryBodyIds, "memoryBodyIds", 1e4) }
|
|
2733
2780
|
}, request.signal));
|
|
2734
2781
|
case "related": return managementResult(service, await service.related(memoryInputText(input.id, "id", 2e3), memoryInputInteger(input.depth, 2, 1, 5), memoryInputText(input.edge, "edge", 30, false), request.signal, memoryInputText(input.memoryBodyId, "memoryBodyId", 300, false)));
|
|
2735
|
-
case "body-reconnect": return managementResult(service, await service.
|
|
2736
|
-
case "prepare-body-placement": return managementResult(service, service.
|
|
2782
|
+
case "body-reconnect": return managementResult(service, await service.reconnectSpace(memoryInputText(input.memoryBodyId, "memoryBodyId", 300), request.signal));
|
|
2783
|
+
case "prepare-body-placement": return managementResult(service, service.prepareSpacePlacement(createSpaceRequest(request.input)));
|
|
2737
2784
|
case "finalize-placement": {
|
|
2738
2785
|
const prepared = memoryInputRecord(input.prepared, "prepared placement");
|
|
2739
2786
|
if (!Array.isArray(prepared.candidates) || prepared.candidates.length === 0) throw new Error("placement candidates are required");
|
|
@@ -2755,7 +2802,7 @@ async function manageMemorySpaces(service, request) {
|
|
|
2755
2802
|
case "provider-service-update": {
|
|
2756
2803
|
const providerId = memoryInputText(input.providerId, "providerId", 128);
|
|
2757
2804
|
await service.updateProviderService(providerId, scalarRecord(input.settings, "settings") ?? {}, memoryInputStringArray(input.clearSecrets, "clearSecrets", 100) ?? [], input.enabled === void 0 ? true : input.enabled === true, request.signal);
|
|
2758
|
-
return managementResult(service, service.
|
|
2805
|
+
return managementResult(service, service.memorySpaces.providerServices().items.find((item) => item.providerId === providerId));
|
|
2759
2806
|
}
|
|
2760
2807
|
case "remember": return managementResult(service, await service.remember({
|
|
2761
2808
|
content: memoryInputText(input.content, "content", 1e5),
|
|
@@ -2770,18 +2817,18 @@ async function manageMemorySpaces(service, request) {
|
|
|
2770
2817
|
case "forget": return managementResult(service, await service.forget(memoryInputText(input.id, "id", 2e3), request.signal, memoryInputText(input.memoryBodyId, "memoryBodyId", 300, false)));
|
|
2771
2818
|
case "body-create": {
|
|
2772
2819
|
const bodyInput = input.request ?? request.input;
|
|
2773
|
-
return managementResult(service, await service.
|
|
2820
|
+
return managementResult(service, await service.createSpace(createSpaceRequest(bodyInput), request.signal, placementDecision(input.placementDecision)));
|
|
2774
2821
|
}
|
|
2775
2822
|
case "body-update": {
|
|
2776
|
-
const parsed =
|
|
2777
|
-
return managementResult(service, service.
|
|
2823
|
+
const parsed = updateSpaceRequest(request.input);
|
|
2824
|
+
return managementResult(service, service.updateSpace(parsed.memoryBodyId, parsed.request));
|
|
2778
2825
|
}
|
|
2779
2826
|
case "remember-many":
|
|
2780
2827
|
if (!Array.isArray(input.requests) || input.requests.length > 1e3) throw new Error("remember-many requires at most 1000 requests");
|
|
2781
2828
|
return managementResult(service, await service.rememberMany(input.requests.map((value) => memoryInputRecord(value, "remember request")), request.signal));
|
|
2782
2829
|
case "body-create-for-persistence": {
|
|
2783
2830
|
const selection = input.selection === void 0 ? void 0 : memoryInputRecord(input.selection, "placement selection");
|
|
2784
|
-
return managementResult(service, await service.
|
|
2831
|
+
return managementResult(service, await service.createSpaceForPersistence(createSpaceRequest(input.request ?? request.input), selection === void 0 ? void 0 : {
|
|
2785
2832
|
providerId: memoryInputText(selection.providerId, "providerId", 128),
|
|
2786
2833
|
reason: memoryInputText(selection.reason, "reason", 4e3),
|
|
2787
2834
|
confidence: memoryInputText(selection.confidence, "confidence", 40)
|
|
@@ -2797,13 +2844,13 @@ async function manageMemorySpaces(service, request) {
|
|
|
2797
2844
|
description: memoryInputText(update.description, "description", 200)
|
|
2798
2845
|
};
|
|
2799
2846
|
});
|
|
2800
|
-
return managementResult(service, service.
|
|
2847
|
+
return managementResult(service, service.updateSpaceMetadata(updates));
|
|
2801
2848
|
}
|
|
2802
|
-
case "body-merge": return managementResult(service, await service.
|
|
2849
|
+
case "body-merge": return managementResult(service, await service.mergeSpaces(memoryInputText(input.targetMemoryBodyId, "targetMemoryBodyId", 300), memoryInputStringArray(input.sourceMemoryBodyIds, "sourceMemoryBodyIds", 1e3) ?? [], input.deactivateSources !== false, request.signal));
|
|
2803
2850
|
case "reload":
|
|
2804
|
-
service.
|
|
2851
|
+
service.memorySpaces.reload();
|
|
2805
2852
|
return managementResult(service, { reloaded: true });
|
|
2806
|
-
case "body-delete": return managementResult(service, await service.
|
|
2853
|
+
case "body-delete": return managementResult(service, await service.deleteSpace(memoryInputText(input.memoryBodyId, "memoryBodyId", 300), request.signal));
|
|
2807
2854
|
default: throw new Error(`unsupported Memory Spaces management mutation operation: ${request.operation}`);
|
|
2808
2855
|
}
|
|
2809
2856
|
}
|
|
@@ -3135,9 +3182,9 @@ function createMemorySpacesSource(providerSnapshot, config = {}) {
|
|
|
3135
3182
|
const known = memoryInputStringArray(memoryInputRecord(request.grant.value, "Memory Spaces scope").knownMemoryBodyIds, "knownMemoryBodyIds", 1e4) ?? allowedBodies;
|
|
3136
3183
|
let value;
|
|
3137
3184
|
if (input.section === "directory") {
|
|
3138
|
-
const catalog = service.
|
|
3185
|
+
const catalog = service.spaceDirectory();
|
|
3139
3186
|
const owned = createdByView.get(request.view.id);
|
|
3140
|
-
value =
|
|
3187
|
+
value = modelSpaceCatalog({
|
|
3141
3188
|
...catalog,
|
|
3142
3189
|
items: catalog.items.filter((body) => known.includes(body.id) || owned?.has(body.id))
|
|
3143
3190
|
});
|
|
@@ -3155,14 +3202,14 @@ function createMemorySpacesSource(providerSnapshot, config = {}) {
|
|
|
3155
3202
|
if (category !== void 0 && !CATEGORIES.has(category)) throw new Error(`unsupported category: ${category}`);
|
|
3156
3203
|
if (source !== void 0 && !SOURCES.has(source)) throw new Error(`unsupported source: ${source}`);
|
|
3157
3204
|
if (intent !== void 0 && !INTENTS.has(intent)) throw new Error(`unsupported intent: ${intent}`);
|
|
3158
|
-
const
|
|
3159
|
-
if (
|
|
3205
|
+
const requestedSpaces = memoryInputStringArray(input.memoryBodyIds, "memoryBodyIds", 1e4) ?? allowedBodies;
|
|
3206
|
+
if (requestedSpaces.some((id) => !allowedBodies.includes(id))) throw new Error("Recall requested a Memory Space outside this View ReadGrant");
|
|
3160
3207
|
const mode = memoryInputText(input.mode, "mode", 20, false);
|
|
3161
3208
|
const result = await service.search({
|
|
3162
3209
|
query: memoryInputText(input.query, "query", 2e3),
|
|
3163
3210
|
...mode === void 0 ? {} : { mode },
|
|
3164
3211
|
limit: Math.min(request.route.maxResults ?? 20, memoryInputInteger(input.limit, 10, 1, 20)),
|
|
3165
|
-
memoryBodyIds:
|
|
3212
|
+
memoryBodyIds: requestedSpaces,
|
|
3166
3213
|
...category === void 0 ? {} : { category },
|
|
3167
3214
|
...source === void 0 ? {} : { source },
|
|
3168
3215
|
...intent === void 0 ? {} : { intent }
|
|
@@ -3171,10 +3218,10 @@ function createMemorySpacesSource(providerSnapshot, config = {}) {
|
|
|
3171
3218
|
}
|
|
3172
3219
|
if (request.route.sourceRouteId === "related") {
|
|
3173
3220
|
const id = memoryInputText(input.id, "id", 2e3);
|
|
3174
|
-
const
|
|
3221
|
+
const requestedSpace = memoryInputText(input.memoryBodyId, "memoryBodyId", 300, false);
|
|
3175
3222
|
const admitted = admittedByView.get(request.view.id);
|
|
3176
3223
|
const owners = [...admitted?.entries() ?? []].filter(([reference]) => reference.endsWith("/" + id)).map(([, bodyId]) => bodyId);
|
|
3177
|
-
const owner =
|
|
3224
|
+
const owner = requestedSpace === void 0 ? owners.length === 1 ? owners[0] : void 0 : admitted?.get(requestedSpace + "/" + id);
|
|
3178
3225
|
if (owner === void 0) throw new Error("related-memory traversal requires evidence already admitted by this View");
|
|
3179
3226
|
if (!allowedBodies.includes(owner)) throw new Error("related-memory owner is outside this View ReadGrant");
|
|
3180
3227
|
const edge = memoryInputText(input.edge, "edge", 30, false);
|
|
@@ -3194,9 +3241,9 @@ function createMemorySpacesSource(providerSnapshot, config = {}) {
|
|
|
3194
3241
|
const created = createdByView.get(request.view.id) ?? /* @__PURE__ */ new Set();
|
|
3195
3242
|
const writeBodies = [.../* @__PURE__ */ new Set([...knownBodies, ...created])];
|
|
3196
3243
|
const admittedOwner = (id) => {
|
|
3197
|
-
const
|
|
3244
|
+
const requestedSpace = memoryInputText(input.memoryBodyId, "memoryBodyId", 300, false);
|
|
3198
3245
|
const entries = admittedByView.get(request.view.id);
|
|
3199
|
-
if (
|
|
3246
|
+
if (requestedSpace !== void 0) return entries?.get(requestedSpace + "/" + id);
|
|
3200
3247
|
const owners = [...entries?.entries() ?? []].filter(([reference]) => reference.endsWith("/" + id)).map(([, owner]) => owner);
|
|
3201
3248
|
return owners.length === 1 ? owners[0] : void 0;
|
|
3202
3249
|
};
|
|
@@ -3205,7 +3252,7 @@ function createMemorySpacesSource(providerSnapshot, config = {}) {
|
|
|
3205
3252
|
if (request.offer.sourceActionId === "manage-spaces") {
|
|
3206
3253
|
if (input.operation === "create") {
|
|
3207
3254
|
const selection = input.selection === void 0 ? void 0 : memoryInputRecord(input.selection, "placement selection");
|
|
3208
|
-
const body = await service.
|
|
3255
|
+
const body = await service.createSpaceForPersistence(createSpaceRequest(input.request), selection === void 0 ? void 0 : {
|
|
3209
3256
|
providerId: memoryInputText(selection.providerId, "providerId", 128),
|
|
3210
3257
|
reason: memoryInputText(selection.reason, "reason", 4e3),
|
|
3211
3258
|
confidence: memoryInputText(selection.confidence, "confidence", 40)
|
|
@@ -3223,7 +3270,7 @@ function createMemorySpacesSource(providerSnapshot, config = {}) {
|
|
|
3223
3270
|
} else if (input.operation === "update") {
|
|
3224
3271
|
bodyId = memoryInputText(input.memoryBodyId, "memoryBodyId", 300);
|
|
3225
3272
|
if (!writeBodies.includes(bodyId)) throw new Error("Memory Space update is outside this View scope");
|
|
3226
|
-
const body = service.
|
|
3273
|
+
const body = service.updateSpace(bodyId, {
|
|
3227
3274
|
...input.name === void 0 ? {} : { name: memoryInputText(input.name, "name", 100) },
|
|
3228
3275
|
...input.description === void 0 ? {} : { description: memoryInputText(input.description, "description", 1e3) },
|
|
3229
3276
|
...typeof input.active === "boolean" ? { active: input.active } : {}
|
|
@@ -3240,7 +3287,7 @@ function createMemorySpacesSource(providerSnapshot, config = {}) {
|
|
|
3240
3287
|
const sources = memoryInputStringArray(input.sourceMemoryBodyIds, "sourceMemoryBodyIds", 20) ?? [];
|
|
3241
3288
|
if ([target, ...sources].some((id) => !writeBodies.includes(id))) throw new Error("Memory Space merge is outside this View scope");
|
|
3242
3289
|
bodyId = target;
|
|
3243
|
-
result = await service.
|
|
3290
|
+
result = await service.mergeSpaces(target, sources, input.deactivateSources !== false, request.signal);
|
|
3244
3291
|
} else throw new Error("unsupported Memory Space management action");
|
|
3245
3292
|
} else if (request.offer.sourceActionId === "remember") {
|
|
3246
3293
|
bodyId = memoryInputText(input.memoryBodyId, "memoryBodyId", 300, false);
|
|
@@ -3266,10 +3313,10 @@ function createMemorySpacesSource(providerSnapshot, config = {}) {
|
|
|
3266
3313
|
} else if (request.offer.sourceActionId === "link") {
|
|
3267
3314
|
const sourceId = memoryInputText(input.sourceId, "sourceId", 2e3);
|
|
3268
3315
|
const targetId = memoryInputText(input.targetId, "targetId", 2e3);
|
|
3269
|
-
const
|
|
3270
|
-
const
|
|
3271
|
-
if (
|
|
3272
|
-
bodyId =
|
|
3316
|
+
const sourceSpace = admittedOwner(sourceId);
|
|
3317
|
+
const targetSpace = admittedOwner(targetId);
|
|
3318
|
+
if (sourceSpace === void 0 || targetSpace === void 0 || sourceSpace !== targetSpace || !allowedBodies.includes(sourceSpace)) throw new Error("link requires two evidence items admitted by this View from the same Memory Space");
|
|
3319
|
+
bodyId = sourceSpace;
|
|
3273
3320
|
const edge = memoryInputText(input.type, "type", 30, false);
|
|
3274
3321
|
if (edge !== void 0 && !EDGES.has(edge)) throw new Error(`unsupported edge: ${edge}`);
|
|
3275
3322
|
const weight = typeof input.weight === "number" ? input.weight : .5;
|