@fgv/ts-agent-memory 5.1.0-39 → 5.1.0-41
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/.rush/temp/{b82cf6bdece20481260e6bab946179eeec9d7b46.tar.log → cbbdbe09515171b4eba8f2592be2dace1e4e8142.tar.log} +14 -2
- package/.rush/temp/chunked-rush-logs/ts-agent-memory.build.chunks.jsonl +2 -2
- package/.rush/temp/operation/build/all.log +2 -2
- package/.rush/temp/operation/build/log-chunks.jsonl +2 -2
- package/.rush/temp/operation/build/state.json +1 -1
- package/dist/packlets/converters/envelopeConverter.js +17 -3
- package/dist/packlets/converters/envelopeConverter.js.map +1 -1
- package/dist/packlets/index/memoryIndex.js +58 -10
- package/dist/packlets/index/memoryIndex.js.map +1 -1
- package/dist/packlets/ingest/cycleGuard.js +13 -6
- package/dist/packlets/ingest/cycleGuard.js.map +1 -1
- package/dist/packlets/ingest/hostStages.js.map +1 -1
- package/dist/packlets/ingest/model.js.map +1 -1
- package/dist/packlets/ingest/orchestrator.js +94 -49
- package/dist/packlets/ingest/orchestrator.js.map +1 -1
- package/dist/packlets/retrieve/hybridRetriever.js +13 -2
- package/dist/packlets/retrieve/hybridRetriever.js.map +1 -1
- package/dist/packlets/retrieve/linkTraversalRetriever.js +46 -57
- package/dist/packlets/retrieve/linkTraversalRetriever.js.map +1 -1
- package/dist/packlets/retrieve/recencyRetriever.js +3 -3
- package/dist/packlets/retrieve/recencyRetriever.js.map +1 -1
- package/dist/packlets/retrieve/retriever.js +50 -7
- package/dist/packlets/retrieve/retriever.js.map +1 -1
- package/dist/packlets/retrieve/semanticRetriever.js +9 -3
- package/dist/packlets/retrieve/semanticRetriever.js.map +1 -1
- package/dist/packlets/retrieve/structuredFilterRetriever.js +3 -3
- package/dist/packlets/retrieve/structuredFilterRetriever.js.map +1 -1
- package/dist/packlets/retrieve/tagRetriever.js +3 -3
- package/dist/packlets/retrieve/tagRetriever.js.map +1 -1
- package/dist/packlets/retrieve/temporalRetrievers.js +3 -3
- package/dist/packlets/retrieve/temporalRetrievers.js.map +1 -1
- package/dist/packlets/store/fileTreeMemoryStore.js +72 -16
- package/dist/packlets/store/fileTreeMemoryStore.js.map +1 -1
- package/dist/packlets/tools/memoryTools.js +104 -21
- package/dist/packlets/tools/memoryTools.js.map +1 -1
- package/dist/packlets/types/envelope.js +13 -1
- package/dist/packlets/types/envelope.js.map +1 -1
- package/dist/packlets/vector/inMemoryCosineIndex.js +22 -17
- package/dist/packlets/vector/inMemoryCosineIndex.js.map +1 -1
- package/dist/packlets/vector/vectorIndex.js.map +1 -1
- package/dist/test/unit/converters/antagonistRoundTrip.test.js +3 -3
- package/dist/test/unit/converters/antagonistRoundTrip.test.js.map +1 -1
- package/dist/test/unit/converters/envelopeConverter.test.js +125 -8
- package/dist/test/unit/converters/envelopeConverter.test.js.map +1 -1
- package/dist/test/unit/index/memoryIndex.test.js +87 -25
- package/dist/test/unit/index/memoryIndex.test.js.map +1 -1
- package/dist/test/unit/ingest/antagonistCycleAndParity.test.js +20 -16
- package/dist/test/unit/ingest/antagonistCycleAndParity.test.js.map +1 -1
- package/dist/test/unit/ingest/cycleGuard.test.js +28 -1
- package/dist/test/unit/ingest/cycleGuard.test.js.map +1 -1
- package/dist/test/unit/ingest/orchestrator.test.js +187 -45
- package/dist/test/unit/ingest/orchestrator.test.js.map +1 -1
- package/dist/test/unit/retrieve/linkTraversalRetriever.test.js +106 -31
- package/dist/test/unit/retrieve/linkTraversalRetriever.test.js.map +1 -1
- package/dist/test/unit/retrieve/retrievers.test.js +299 -37
- package/dist/test/unit/retrieve/retrievers.test.js.map +1 -1
- package/dist/test/unit/store/embedOnWrite.test.js +69 -12
- package/dist/test/unit/store/embedOnWrite.test.js.map +1 -1
- package/dist/test/unit/store/listScoped.test.js +109 -0
- package/dist/test/unit/store/listScoped.test.js.map +1 -0
- package/dist/test/unit/store/rankAxis.test.js +254 -0
- package/dist/test/unit/store/rankAxis.test.js.map +1 -0
- package/dist/test/unit/tools/memoryTools.test.js +280 -11
- package/dist/test/unit/tools/memoryTools.test.js.map +1 -1
- package/dist/test/unit/types/writePolicy.test.js +9 -2
- package/dist/test/unit/types/writePolicy.test.js.map +1 -1
- package/dist/test/unit/vector/inMemoryCosineIndex.test.js +95 -35
- package/dist/test/unit/vector/inMemoryCosineIndex.test.js.map +1 -1
- package/dist/test/unit/vector/vectorIndex.test.js +24 -15
- package/dist/test/unit/vector/vectorIndex.test.js.map +1 -1
- package/dist/ts-agent-memory.d.ts +384 -97
- package/etc/ts-agent-memory.api.md +64 -22
- package/lib/packlets/converters/envelopeConverter.d.ts +8 -1
- package/lib/packlets/converters/envelopeConverter.d.ts.map +1 -1
- package/lib/packlets/converters/envelopeConverter.js +18 -4
- package/lib/packlets/converters/envelopeConverter.js.map +1 -1
- package/lib/packlets/index/memoryIndex.d.ts +42 -10
- package/lib/packlets/index/memoryIndex.d.ts.map +1 -1
- package/lib/packlets/index/memoryIndex.js +58 -10
- package/lib/packlets/index/memoryIndex.js.map +1 -1
- package/lib/packlets/ingest/cycleGuard.d.ts +5 -5
- package/lib/packlets/ingest/cycleGuard.d.ts.map +1 -1
- package/lib/packlets/ingest/cycleGuard.js +13 -6
- package/lib/packlets/ingest/cycleGuard.js.map +1 -1
- package/lib/packlets/ingest/hostStages.d.ts +3 -3
- package/lib/packlets/ingest/hostStages.d.ts.map +1 -1
- package/lib/packlets/ingest/hostStages.js.map +1 -1
- package/lib/packlets/ingest/model.d.ts +25 -14
- package/lib/packlets/ingest/model.d.ts.map +1 -1
- package/lib/packlets/ingest/model.js.map +1 -1
- package/lib/packlets/ingest/orchestrator.d.ts +18 -4
- package/lib/packlets/ingest/orchestrator.d.ts.map +1 -1
- package/lib/packlets/ingest/orchestrator.js +93 -48
- package/lib/packlets/ingest/orchestrator.js.map +1 -1
- package/lib/packlets/retrieve/hybridRetriever.d.ts.map +1 -1
- package/lib/packlets/retrieve/hybridRetriever.js +12 -1
- package/lib/packlets/retrieve/hybridRetriever.js.map +1 -1
- package/lib/packlets/retrieve/linkTraversalRetriever.d.ts +18 -23
- package/lib/packlets/retrieve/linkTraversalRetriever.d.ts.map +1 -1
- package/lib/packlets/retrieve/linkTraversalRetriever.js +45 -56
- package/lib/packlets/retrieve/linkTraversalRetriever.js.map +1 -1
- package/lib/packlets/retrieve/recencyRetriever.js +2 -2
- package/lib/packlets/retrieve/recencyRetriever.js.map +1 -1
- package/lib/packlets/retrieve/retriever.d.ts +70 -11
- package/lib/packlets/retrieve/retriever.d.ts.map +1 -1
- package/lib/packlets/retrieve/retriever.js +52 -7
- package/lib/packlets/retrieve/retriever.js.map +1 -1
- package/lib/packlets/retrieve/semanticRetriever.d.ts.map +1 -1
- package/lib/packlets/retrieve/semanticRetriever.js +9 -3
- package/lib/packlets/retrieve/semanticRetriever.js.map +1 -1
- package/lib/packlets/retrieve/structuredFilterRetriever.js +2 -2
- package/lib/packlets/retrieve/structuredFilterRetriever.js.map +1 -1
- package/lib/packlets/retrieve/tagRetriever.js +2 -2
- package/lib/packlets/retrieve/tagRetriever.js.map +1 -1
- package/lib/packlets/retrieve/temporalRetrievers.js +3 -3
- package/lib/packlets/retrieve/temporalRetrievers.js.map +1 -1
- package/lib/packlets/store/fileTreeMemoryStore.d.ts +57 -3
- package/lib/packlets/store/fileTreeMemoryStore.d.ts.map +1 -1
- package/lib/packlets/store/fileTreeMemoryStore.js +72 -16
- package/lib/packlets/store/fileTreeMemoryStore.js.map +1 -1
- package/lib/packlets/tools/memoryTools.d.ts +24 -0
- package/lib/packlets/tools/memoryTools.d.ts.map +1 -1
- package/lib/packlets/tools/memoryTools.js +104 -21
- package/lib/packlets/tools/memoryTools.js.map +1 -1
- package/lib/packlets/types/envelope.d.ts +61 -8
- package/lib/packlets/types/envelope.d.ts.map +1 -1
- package/lib/packlets/types/envelope.js +14 -0
- package/lib/packlets/types/envelope.js.map +1 -1
- package/lib/packlets/vector/inMemoryCosineIndex.d.ts +9 -5
- package/lib/packlets/vector/inMemoryCosineIndex.d.ts.map +1 -1
- package/lib/packlets/vector/inMemoryCosineIndex.js +22 -17
- package/lib/packlets/vector/inMemoryCosineIndex.js.map +1 -1
- package/lib/packlets/vector/vectorIndex.d.ts +46 -20
- package/lib/packlets/vector/vectorIndex.d.ts.map +1 -1
- package/lib/packlets/vector/vectorIndex.js.map +1 -1
- package/lib/test/unit/converters/antagonistRoundTrip.test.js +3 -3
- package/lib/test/unit/converters/antagonistRoundTrip.test.js.map +1 -1
- package/lib/test/unit/converters/envelopeConverter.test.js +124 -7
- package/lib/test/unit/converters/envelopeConverter.test.js.map +1 -1
- package/lib/test/unit/index/memoryIndex.test.js +86 -24
- package/lib/test/unit/index/memoryIndex.test.js.map +1 -1
- package/lib/test/unit/ingest/antagonistCycleAndParity.test.js +20 -16
- package/lib/test/unit/ingest/antagonistCycleAndParity.test.js.map +1 -1
- package/lib/test/unit/ingest/cycleGuard.test.js +28 -1
- package/lib/test/unit/ingest/cycleGuard.test.js.map +1 -1
- package/lib/test/unit/ingest/orchestrator.test.js +186 -44
- package/lib/test/unit/ingest/orchestrator.test.js.map +1 -1
- package/lib/test/unit/retrieve/linkTraversalRetriever.test.js +106 -31
- package/lib/test/unit/retrieve/linkTraversalRetriever.test.js.map +1 -1
- package/lib/test/unit/retrieve/retrievers.test.js +298 -36
- package/lib/test/unit/retrieve/retrievers.test.js.map +1 -1
- package/lib/test/unit/store/embedOnWrite.test.js +68 -11
- package/lib/test/unit/store/embedOnWrite.test.js.map +1 -1
- package/lib/test/unit/store/listScoped.test.d.ts +2 -0
- package/lib/test/unit/store/listScoped.test.d.ts.map +1 -0
- package/lib/test/unit/store/listScoped.test.js +111 -0
- package/lib/test/unit/store/listScoped.test.js.map +1 -0
- package/lib/test/unit/store/rankAxis.test.d.ts +2 -0
- package/lib/test/unit/store/rankAxis.test.d.ts.map +1 -0
- package/lib/test/unit/store/rankAxis.test.js +256 -0
- package/lib/test/unit/store/rankAxis.test.js.map +1 -0
- package/lib/test/unit/tools/memoryTools.test.js +280 -11
- package/lib/test/unit/tools/memoryTools.test.js.map +1 -1
- package/lib/test/unit/types/writePolicy.test.js +9 -2
- package/lib/test/unit/types/writePolicy.test.js.map +1 -1
- package/lib/test/unit/vector/inMemoryCosineIndex.test.js +95 -35
- package/lib/test/unit/vector/inMemoryCosineIndex.test.js.map +1 -1
- package/lib/test/unit/vector/vectorIndex.test.js +24 -15
- package/lib/test/unit/vector/vectorIndex.test.js.map +1 -1
- package/package.json +7 -7
- package/rush-logs/ts-agent-memory.build.cache.log +1 -1
- package/rush-logs/ts-agent-memory.build.log +2 -2
- package/src/packlets/converters/envelopeConverter.ts +27 -4
- package/src/packlets/index/memoryIndex.ts +86 -22
- package/src/packlets/ingest/cycleGuard.ts +22 -11
- package/src/packlets/ingest/hostStages.ts +3 -3
- package/src/packlets/ingest/model.ts +25 -14
- package/src/packlets/ingest/orchestrator.ts +143 -67
- package/src/packlets/retrieve/hybridRetriever.ts +14 -1
- package/src/packlets/retrieve/linkTraversalRetriever.ts +51 -62
- package/src/packlets/retrieve/recencyRetriever.ts +3 -3
- package/src/packlets/retrieve/retriever.ts +97 -13
- package/src/packlets/retrieve/semanticRetriever.ts +10 -5
- package/src/packlets/retrieve/structuredFilterRetriever.ts +3 -3
- package/src/packlets/retrieve/tagRetriever.ts +3 -3
- package/src/packlets/retrieve/temporalRetrievers.ts +3 -3
- package/src/packlets/store/fileTreeMemoryStore.ts +117 -12
- package/src/packlets/tools/memoryTools.ts +152 -25
- package/src/packlets/types/envelope.ts +66 -8
- package/src/packlets/vector/inMemoryCosineIndex.ts +45 -22
- package/src/packlets/vector/vectorIndex.ts +47 -20
- package/src/test/unit/converters/antagonistRoundTrip.test.ts +3 -3
- package/src/test/unit/converters/envelopeConverter.test.ts +168 -11
- package/src/test/unit/index/memoryIndex.test.ts +99 -14
- package/src/test/unit/ingest/antagonistCycleAndParity.test.ts +23 -18
- package/src/test/unit/ingest/cycleGuard.test.ts +44 -2
- package/src/test/unit/ingest/orchestrator.test.ts +234 -41
- package/src/test/unit/retrieve/linkTraversalRetriever.test.ts +134 -35
- package/src/test/unit/retrieve/retrievers.test.ts +381 -25
- package/src/test/unit/store/embedOnWrite.test.ts +83 -11
- package/src/test/unit/store/listScoped.test.ts +138 -0
- package/src/test/unit/store/rankAxis.test.ts +349 -0
- package/src/test/unit/tools/memoryTools.test.ts +362 -13
- package/src/test/unit/types/writePolicy.test.ts +11 -2
- package/src/test/unit/vector/inMemoryCosineIndex.test.ts +115 -39
- package/src/test/unit/vector/vectorIndex.test.ts +33 -17
- package/temp/build/lint/_eslint-5eVG3S6w.json +41 -33
- package/temp/build/typescript/ts_8nwakTlr.json +1 -1
- package/temp/ts-agent-memory.api.json +1080 -136
- package/temp/ts-agent-memory.api.md +64 -22
|
@@ -11,9 +11,11 @@ import {
|
|
|
11
11
|
AdmissionDecision,
|
|
12
12
|
BodyConverterRegistry,
|
|
13
13
|
DEFAULT_MEMORY_TOOLS,
|
|
14
|
+
EntityId,
|
|
14
15
|
FileTreeMemoryStore,
|
|
15
16
|
HybridRetriever,
|
|
16
17
|
IBodyConverterRegistry,
|
|
18
|
+
IEdgeTarget,
|
|
17
19
|
IIdentityCodec,
|
|
18
20
|
IIndexedMemoryRecord,
|
|
19
21
|
IMemoryRecord,
|
|
@@ -111,7 +113,10 @@ function makeEntry(spec: IEntrySpec): IIndexedMemoryRecord {
|
|
|
111
113
|
entityId: spec.entityId ?? spec.id,
|
|
112
114
|
kind: spec.kind ?? 'knowledge',
|
|
113
115
|
tags: spec.tags ?? [],
|
|
114
|
-
links: (spec.links ?? []).map((target) => ({
|
|
116
|
+
links: (spec.links ?? []).map((target) => ({
|
|
117
|
+
type: 'rel',
|
|
118
|
+
target: { scope: spec.scope ?? 'knowledge', id: target }
|
|
119
|
+
})),
|
|
115
120
|
created: 0,
|
|
116
121
|
updated: spec.updated ?? 0,
|
|
117
122
|
seq: 0,
|
|
@@ -285,10 +290,27 @@ describe('createMemoryTools', () => {
|
|
|
285
290
|
entityId: 'doc-1',
|
|
286
291
|
body: 'hello',
|
|
287
292
|
tags: ['a'],
|
|
288
|
-
links: [{ type: 'rel', target: 'doc-2', confidence: 0.5 }]
|
|
293
|
+
links: [{ type: 'rel', target: { id: 'doc-2' }, confidence: 0.5 }]
|
|
294
|
+
})
|
|
295
|
+
).toSucceed();
|
|
296
|
+
expect(
|
|
297
|
+
schema.convert({
|
|
298
|
+
kind: 'knowledge',
|
|
299
|
+
entityId: 'doc-1',
|
|
300
|
+
body: 'hello',
|
|
301
|
+
links: [{ type: 'rel', target: { scope: 'conversations/other', id: 'turn-1' } }]
|
|
289
302
|
})
|
|
290
303
|
).toSucceed();
|
|
291
304
|
expect(schema.convert({ kind: 'knowledge', entityId: 'doc-1' })).toFail();
|
|
305
|
+
// A bare-string target (the pre-scoped format) is rejected at the schema.
|
|
306
|
+
expect(
|
|
307
|
+
schema.convert({
|
|
308
|
+
kind: 'knowledge',
|
|
309
|
+
entityId: 'doc-1',
|
|
310
|
+
body: 'x',
|
|
311
|
+
links: [{ type: 'rel', target: 'doc-2' }]
|
|
312
|
+
})
|
|
313
|
+
).toFail();
|
|
292
314
|
});
|
|
293
315
|
|
|
294
316
|
test('memory_read / memory_delete require kind and entityId', () => {
|
|
@@ -306,10 +328,25 @@ describe('createMemoryTools', () => {
|
|
|
306
328
|
expect(schema.convert({ limit: 'three' })).toFail();
|
|
307
329
|
});
|
|
308
330
|
|
|
309
|
-
test('memory_context requires a from seed', () => {
|
|
331
|
+
test('memory_context requires a from seed with a REQUIRED scope (nested { id, scope })', () => {
|
|
310
332
|
const schema = toolByName(allTools(), 'memory_context').config.parametersSchema;
|
|
311
|
-
expect(schema.convert({ from: 'doc-1' })).toSucceed();
|
|
333
|
+
expect(schema.convert({ from: { id: 'doc-1', scope: 'knowledge' } })).toSucceed();
|
|
334
|
+
// scope is schema-REQUIRED (unlike a write link target) — the wire schema must
|
|
335
|
+
// not advertise an optionality the tool does not honor. Omitting it fails.
|
|
336
|
+
expect(schema.convert({ from: { id: 'doc-1' } })).toFail();
|
|
312
337
|
expect(schema.convert({ hops: 2 })).toFail();
|
|
338
|
+
// A bare-string seed (the pre-scoped format) is rejected at the schema.
|
|
339
|
+
expect(schema.convert({ from: 'doc-1' })).toFail();
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
test('the memory_context wire schema marks from.scope as required', () => {
|
|
343
|
+
// Guards the schema-accuracy contract at the wire level: an LLM reading the
|
|
344
|
+
// tool's `parameters` sees scope in the seed's `required` array.
|
|
345
|
+
const schema = toolByName(allTools(), 'memory_context').config.parametersSchema;
|
|
346
|
+
const wire = schema.toJson() as unknown as {
|
|
347
|
+
properties: { from: { required?: ReadonlyArray<string> } };
|
|
348
|
+
};
|
|
349
|
+
expect(wire.properties.from.required).toContain('scope');
|
|
313
350
|
});
|
|
314
351
|
});
|
|
315
352
|
|
|
@@ -364,14 +401,43 @@ describe('createMemoryTools', () => {
|
|
|
364
401
|
entityId: 'doc-1',
|
|
365
402
|
body: 'linked',
|
|
366
403
|
links: [
|
|
367
|
-
|
|
368
|
-
{ type: 'rel', target: 'doc-
|
|
404
|
+
// scope omitted → defaults to the writing record's own scope (knowledge)
|
|
405
|
+
{ type: 'rel', target: { id: 'doc-2' }, confidence: 0.9 },
|
|
406
|
+
{ type: 'rel', target: { id: 'doc-3' } }
|
|
369
407
|
]
|
|
370
408
|
})
|
|
371
409
|
).toSucceedAndSatisfy((v) => expect((v as IMemoryWriteResult).outcome).toBe('written'));
|
|
410
|
+
// The persisted links carry the writing record's scope on each target.
|
|
411
|
+
expect(await store.get(knowledgeKind, 'doc-1' as EntityId)).toSucceedAndSatisfy((rec) => {
|
|
412
|
+
expect(rec?.envelope.links).toEqual([
|
|
413
|
+
{ type: 'rel', target: { scope: 'knowledge', id: 'doc-2' }, confidence: 0.9 },
|
|
414
|
+
{ type: 'rel', target: { scope: 'knowledge', id: 'doc-3' } }
|
|
415
|
+
]);
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
test('an authored link with an EXPLICIT scope is honored verbatim (cross-scope edge)', async () => {
|
|
420
|
+
const store = makeStore();
|
|
421
|
+
const tools = createMemoryTools({
|
|
422
|
+
store,
|
|
423
|
+
retriever: makeRetriever([]),
|
|
424
|
+
registry: registryWith([{ kind: knowledgeKind }]),
|
|
425
|
+
codecs,
|
|
426
|
+
tools: ['memory_write']
|
|
427
|
+
});
|
|
372
428
|
expect(
|
|
373
|
-
await toolByName(tools, '
|
|
374
|
-
|
|
429
|
+
await toolByName(tools, 'memory_write').execute({
|
|
430
|
+
kind: 'knowledge',
|
|
431
|
+
entityId: 'doc-1',
|
|
432
|
+
body: 'cross',
|
|
433
|
+
links: [{ type: 'mtm-ref', target: { scope: 'conversations/conv-a', id: 'turn-3' } }]
|
|
434
|
+
})
|
|
435
|
+
).toSucceed();
|
|
436
|
+
expect(await store.get(knowledgeKind, 'doc-1' as EntityId)).toSucceedAndSatisfy((rec) => {
|
|
437
|
+
expect(rec?.envelope.links).toEqual([
|
|
438
|
+
{ type: 'mtm-ref', target: { scope: 'conversations/conv-a', id: 'turn-3' } }
|
|
439
|
+
]);
|
|
440
|
+
});
|
|
375
441
|
});
|
|
376
442
|
|
|
377
443
|
test('an identical re-put of the same entity is a dedup no-op (outcome: deduped)', async () => {
|
|
@@ -490,6 +556,8 @@ describe('createMemoryTools', () => {
|
|
|
490
556
|
get: async () => fail('disk fault'),
|
|
491
557
|
getById: async () => fail('unused'),
|
|
492
558
|
list: async () => succeed([]),
|
|
559
|
+
listScoped: async () => succeed([]),
|
|
560
|
+
asRecordSource: () => ({ list: async () => succeed([]) }),
|
|
493
561
|
put: async (record) => succeed(record),
|
|
494
562
|
delete: async () => fail('unused')
|
|
495
563
|
};
|
|
@@ -694,9 +762,13 @@ describe('createMemoryTools', () => {
|
|
|
694
762
|
}),
|
|
695
763
|
'memory_context'
|
|
696
764
|
);
|
|
697
|
-
expect(await tool.execute({ from: 'a' })).toSucceedAndSatisfy((value) => {
|
|
698
|
-
const out = value as {
|
|
699
|
-
|
|
765
|
+
expect(await tool.execute({ from: { id: 'a', scope: 'knowledge' } })).toSucceedAndSatisfy((value) => {
|
|
766
|
+
const out = value as {
|
|
767
|
+
seed: IEdgeTarget;
|
|
768
|
+
count: number;
|
|
769
|
+
results: ReadonlyArray<IMemoryToolResultItem>;
|
|
770
|
+
};
|
|
771
|
+
expect(out.seed).toEqual({ scope: 'knowledge', id: 'a' });
|
|
700
772
|
expect(out.results.map((r) => r.handle)).toEqual(['b', 'c']);
|
|
701
773
|
});
|
|
702
774
|
});
|
|
@@ -716,7 +788,13 @@ describe('createMemoryTools', () => {
|
|
|
716
788
|
'memory_context'
|
|
717
789
|
);
|
|
718
790
|
expect(
|
|
719
|
-
await tool.execute({
|
|
791
|
+
await tool.execute({
|
|
792
|
+
from: { id: 'a', scope: 'knowledge' },
|
|
793
|
+
hops: 2,
|
|
794
|
+
tag: 'keep',
|
|
795
|
+
kind: 'knowledge',
|
|
796
|
+
limit: 5
|
|
797
|
+
})
|
|
720
798
|
).toSucceedAndSatisfy((value) => {
|
|
721
799
|
const out = value as { results: ReadonlyArray<IMemoryToolResultItem> };
|
|
722
800
|
expect(out.results.map((r) => r.handle).sort()).toEqual(['b', 'c']);
|
|
@@ -725,7 +803,40 @@ describe('createMemoryTools', () => {
|
|
|
725
803
|
|
|
726
804
|
test('rejects an invalid seed id', async () => {
|
|
727
805
|
const tool = toolByName(allTools(), 'memory_context');
|
|
728
|
-
expect(await tool.execute({ from: 'a/b' })).toFail();
|
|
806
|
+
expect(await tool.execute({ from: { id: 'a/b', scope: 'knowledge' } })).toFail();
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
test('fails at the schema when the seed omits its required scope', async () => {
|
|
810
|
+
// scope is schema-required, so an omitted scope is rejected as an invalid
|
|
811
|
+
// argument (the wire schema and the runtime contract agree — no lie).
|
|
812
|
+
const tool = toolByName(allTools(), 'memory_context');
|
|
813
|
+
expect(await tool.execute({ from: { id: 'a' } })).toFailWith(/invalid arguments/i);
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
test('a scoped seed reaches ONLY the correctly-scoped graph', async () => {
|
|
817
|
+
// Two conversations reuse the stem `turn-0`; each links a same-scope `turn-1`.
|
|
818
|
+
// Seeding conv-a must reach conv-a's turn-1 and NEVER conv-b's.
|
|
819
|
+
const retriever = makeLinkRetriever([
|
|
820
|
+
{ id: 'turn-0', scope: 'conversations/conv-a', links: ['turn-1'] },
|
|
821
|
+
{ id: 'turn-1', scope: 'conversations/conv-a', tags: ['in-a'] },
|
|
822
|
+
{ id: 'turn-0', scope: 'conversations/conv-b', links: ['turn-1'] },
|
|
823
|
+
{ id: 'turn-1', scope: 'conversations/conv-b', tags: ['in-b'] }
|
|
824
|
+
]);
|
|
825
|
+
const tool = toolByName(
|
|
826
|
+
createMemoryTools({
|
|
827
|
+
store: makeStore(),
|
|
828
|
+
retriever,
|
|
829
|
+
registry: registryWith([{ kind: knowledgeKind }])
|
|
830
|
+
}),
|
|
831
|
+
'memory_context'
|
|
832
|
+
);
|
|
833
|
+
expect(
|
|
834
|
+
await tool.execute({ from: { id: 'turn-0', scope: 'conversations/conv-a' } })
|
|
835
|
+
).toSucceedAndSatisfy((value) => {
|
|
836
|
+
const out = value as { results: ReadonlyArray<IMemoryToolResultItem> };
|
|
837
|
+
expect(out.results).toHaveLength(1);
|
|
838
|
+
expect(out.results[0].tags).toEqual(['in-a']);
|
|
839
|
+
});
|
|
729
840
|
});
|
|
730
841
|
|
|
731
842
|
test('rejects malformed arguments', async () => {
|
|
@@ -769,3 +880,241 @@ describe('createMemoryTools', () => {
|
|
|
769
880
|
});
|
|
770
881
|
});
|
|
771
882
|
});
|
|
883
|
+
|
|
884
|
+
describe('result projection (projectItem host projector + detail tier)', () => {
|
|
885
|
+
interface ISearchOut {
|
|
886
|
+
readonly count: number;
|
|
887
|
+
readonly results: ReadonlyArray<IMemoryToolResultItem>;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* A host projector that bounds the `'gist'` body to a sentinel and passes the
|
|
892
|
+
* full body through only for `'full'` — the shape a real host uses to keep the
|
|
893
|
+
* default (gist) path bounded.
|
|
894
|
+
*/
|
|
895
|
+
const boundingProjector = (
|
|
896
|
+
record: IMemoryRecord<unknown>,
|
|
897
|
+
detail: 'gist' | 'full'
|
|
898
|
+
): IMemoryToolResultItem => ({
|
|
899
|
+
handle: `h:${record.envelope.id}`,
|
|
900
|
+
kind: record.envelope.kind,
|
|
901
|
+
entityId: record.envelope.entityId,
|
|
902
|
+
tags: record.envelope.tags,
|
|
903
|
+
body: detail === 'full' ? record.body : '<<gist>>'
|
|
904
|
+
});
|
|
905
|
+
|
|
906
|
+
function searchToolWith(
|
|
907
|
+
overrides: Partial<Parameters<typeof createMemoryTools>[0]>
|
|
908
|
+
): AiAssist.IAiClientTool {
|
|
909
|
+
return toolByName(
|
|
910
|
+
createMemoryTools({
|
|
911
|
+
store: makeStore(),
|
|
912
|
+
retriever: makeRetriever([{ id: 'doc-1', tags: ['topic'] }]),
|
|
913
|
+
registry: registryWith([{ kind: knowledgeKind }]),
|
|
914
|
+
...overrides
|
|
915
|
+
}),
|
|
916
|
+
'memory_search'
|
|
917
|
+
);
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
describe('schema surface', () => {
|
|
921
|
+
test('memory_search declares optional detail + offset properties', () => {
|
|
922
|
+
const props = schemaProperties(toolByName(allTools(), 'memory_search'));
|
|
923
|
+
expect(props).toContain('detail');
|
|
924
|
+
expect(props).toContain('offset');
|
|
925
|
+
});
|
|
926
|
+
|
|
927
|
+
test('memory_context declares an optional detail property', () => {
|
|
928
|
+
const props = schemaProperties(toolByName(allTools(), 'memory_context'));
|
|
929
|
+
expect(props).toContain('detail');
|
|
930
|
+
});
|
|
931
|
+
|
|
932
|
+
test('memory_read declares an optional detail property', () => {
|
|
933
|
+
const props = schemaProperties(toolByName(allTools(), 'memory_read'));
|
|
934
|
+
expect(props).toContain('detail');
|
|
935
|
+
});
|
|
936
|
+
|
|
937
|
+
test('memory_search accepts detail and offset, and rejects an out-of-enum detail', () => {
|
|
938
|
+
const schema = toolByName(allTools(), 'memory_search').config.parametersSchema;
|
|
939
|
+
expect(schema.convert({ detail: 'full', offset: 2 })).toSucceed();
|
|
940
|
+
expect(schema.convert({ detail: 'gist' })).toSucceed();
|
|
941
|
+
expect(schema.convert({ offset: 'nope' })).toFail();
|
|
942
|
+
// detail is now an enum ('gist' | 'full') at the wire-schema level.
|
|
943
|
+
expect(schema.convert({ detail: 'verbose' })).toFail();
|
|
944
|
+
});
|
|
945
|
+
});
|
|
946
|
+
|
|
947
|
+
describe('absent projector = byte-identical default projection', () => {
|
|
948
|
+
test('returns the full body and the default handle (raw id) when no projector is supplied', async () => {
|
|
949
|
+
const tool = searchToolWith({});
|
|
950
|
+
expect(await tool.execute({ tag: 'topic' })).toSucceedAndSatisfy((value) => {
|
|
951
|
+
const out = value as ISearchOut;
|
|
952
|
+
expect(out.results[0].handle).toBe('doc-1');
|
|
953
|
+
expect(out.results[0].body).toBe('body-doc-1');
|
|
954
|
+
});
|
|
955
|
+
});
|
|
956
|
+
|
|
957
|
+
test('the detail tier is inert without a projector (gist and full both yield the full body)', async () => {
|
|
958
|
+
const tool = searchToolWith({});
|
|
959
|
+
for (const detail of ['gist', 'full'] as const) {
|
|
960
|
+
expect(await tool.execute({ tag: 'topic', detail })).toSucceedAndSatisfy((value) => {
|
|
961
|
+
expect((value as ISearchOut).results[0].body).toBe('body-doc-1');
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
});
|
|
965
|
+
});
|
|
966
|
+
|
|
967
|
+
describe('host projector + detail tier', () => {
|
|
968
|
+
test('defaults to the bounded gist projection when detail is absent', async () => {
|
|
969
|
+
const tool = searchToolWith({ projectItem: boundingProjector });
|
|
970
|
+
expect(await tool.execute({ tag: 'topic' })).toSucceedAndSatisfy((value) => {
|
|
971
|
+
const out = value as ISearchOut;
|
|
972
|
+
expect(out.results[0].handle).toBe('h:doc-1');
|
|
973
|
+
expect(out.results[0].body).toBe('<<gist>>');
|
|
974
|
+
});
|
|
975
|
+
});
|
|
976
|
+
|
|
977
|
+
test('opts into the full body only when detail=full is requested', async () => {
|
|
978
|
+
const tool = searchToolWith({ projectItem: boundingProjector });
|
|
979
|
+
expect(await tool.execute({ tag: 'topic', detail: 'full' })).toSucceedAndSatisfy((value) => {
|
|
980
|
+
expect((value as ISearchOut).results[0].body).toBe('body-doc-1');
|
|
981
|
+
});
|
|
982
|
+
});
|
|
983
|
+
|
|
984
|
+
test('an out-of-enum detail is rejected at the schema boundary', async () => {
|
|
985
|
+
// detail is a JsonSchema.enumOf(['gist','full']); the tool re-validates args
|
|
986
|
+
// on execute, so an out-of-enum value fails loudly rather than reaching the projector.
|
|
987
|
+
const tool = searchToolWith({ projectItem: boundingProjector });
|
|
988
|
+
expect(await tool.execute({ tag: 'topic', detail: 'verbose' })).toFailWith(/invalid arguments/i);
|
|
989
|
+
});
|
|
990
|
+
|
|
991
|
+
test('an explicit detail=gist stays bounded (the non-full branch)', async () => {
|
|
992
|
+
const tool = searchToolWith({ projectItem: boundingProjector });
|
|
993
|
+
expect(await tool.execute({ tag: 'topic', detail: 'gist' })).toSucceedAndSatisfy((value) => {
|
|
994
|
+
expect((value as ISearchOut).results[0].body).toBe('<<gist>>');
|
|
995
|
+
});
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
test('memory_context routes its results through the host projector', async () => {
|
|
999
|
+
const tool = toolByName(
|
|
1000
|
+
createMemoryTools({
|
|
1001
|
+
store: makeStore(),
|
|
1002
|
+
retriever: makeLinkRetriever([{ id: 'a', links: ['b'] }, { id: 'b' }]),
|
|
1003
|
+
registry: registryWith([{ kind: knowledgeKind }]),
|
|
1004
|
+
projectItem: boundingProjector
|
|
1005
|
+
}),
|
|
1006
|
+
'memory_context'
|
|
1007
|
+
);
|
|
1008
|
+
expect(
|
|
1009
|
+
await tool.execute({ from: { id: 'a', scope: 'knowledge' }, detail: 'full' })
|
|
1010
|
+
).toSucceedAndSatisfy((value) => {
|
|
1011
|
+
const out = value as { results: ReadonlyArray<IMemoryToolResultItem> };
|
|
1012
|
+
expect(out.results.map((r) => r.handle)).toEqual(['h:b']);
|
|
1013
|
+
expect(out.results[0].body).toBe('body-b');
|
|
1014
|
+
});
|
|
1015
|
+
});
|
|
1016
|
+
|
|
1017
|
+
test('a throwing host projector degrades to the default full-body projection (does not crash search)', async () => {
|
|
1018
|
+
const tool = searchToolWith({
|
|
1019
|
+
projectItem: () => {
|
|
1020
|
+
throw new Error('host projector blew up');
|
|
1021
|
+
}
|
|
1022
|
+
});
|
|
1023
|
+
expect(await tool.execute({ tag: 'topic' })).toSucceedAndSatisfy((value) => {
|
|
1024
|
+
const out = value as ISearchOut;
|
|
1025
|
+
// Degraded to the built-in default: raw-id handle + full body.
|
|
1026
|
+
expect(out.results[0].handle).toBe('doc-1');
|
|
1027
|
+
expect(out.results[0].body).toBe('body-doc-1');
|
|
1028
|
+
});
|
|
1029
|
+
});
|
|
1030
|
+
|
|
1031
|
+
test('a throwing projector still honors the handleFor hook in the fallback path', async () => {
|
|
1032
|
+
const tool = searchToolWith({
|
|
1033
|
+
handleFor: (r) => `@${r.envelope.id}`,
|
|
1034
|
+
projectItem: () => {
|
|
1035
|
+
throw new Error('nope');
|
|
1036
|
+
}
|
|
1037
|
+
});
|
|
1038
|
+
expect(await tool.execute({ tag: 'topic' })).toSucceedAndSatisfy((value) => {
|
|
1039
|
+
expect((value as ISearchOut).results[0].handle).toBe('@doc-1');
|
|
1040
|
+
});
|
|
1041
|
+
});
|
|
1042
|
+
});
|
|
1043
|
+
|
|
1044
|
+
describe('offset threading (memory_search)', () => {
|
|
1045
|
+
test('threads offset into the query to page the ordered result window', async () => {
|
|
1046
|
+
const tool = toolByName(
|
|
1047
|
+
createMemoryTools({
|
|
1048
|
+
store: makeStore(),
|
|
1049
|
+
retriever: makeRetriever([
|
|
1050
|
+
{ id: 'doc-1', tags: ['topic'], updated: 30 },
|
|
1051
|
+
{ id: 'doc-2', tags: ['topic'], updated: 20 },
|
|
1052
|
+
{ id: 'doc-3', tags: ['topic'], updated: 10 }
|
|
1053
|
+
]),
|
|
1054
|
+
registry: registryWith([{ kind: knowledgeKind }])
|
|
1055
|
+
}),
|
|
1056
|
+
'memory_search'
|
|
1057
|
+
);
|
|
1058
|
+
// Recency-ordered [doc-1, doc-2, doc-3]; offset 1 + limit 1 → [doc-2].
|
|
1059
|
+
expect(await tool.execute({ tag: 'topic', offset: 1, limit: 1 })).toSucceedAndSatisfy((value) => {
|
|
1060
|
+
const out = value as ISearchOut;
|
|
1061
|
+
expect(out.count).toBe(1);
|
|
1062
|
+
expect(out.results.map((r) => r.handle)).toEqual(['doc-2']);
|
|
1063
|
+
});
|
|
1064
|
+
});
|
|
1065
|
+
});
|
|
1066
|
+
|
|
1067
|
+
describe('memory_read detail (explicit drill-in defaults to FULL)', () => {
|
|
1068
|
+
interface IReadOut {
|
|
1069
|
+
readonly found: boolean;
|
|
1070
|
+
readonly item: IMemoryToolResultItem;
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
async function readToolWith(
|
|
1074
|
+
projector?: (record: IMemoryRecord<unknown>, detail: 'gist' | 'full') => IMemoryToolResultItem
|
|
1075
|
+
): Promise<AiAssist.IAiClientTool> {
|
|
1076
|
+
const tools = createMemoryTools({
|
|
1077
|
+
store: makeStore(),
|
|
1078
|
+
retriever: makeRetriever([]),
|
|
1079
|
+
registry: registryWith([{ kind: knowledgeKind }]),
|
|
1080
|
+
codecs,
|
|
1081
|
+
tools: ['memory_write', 'memory_read'],
|
|
1082
|
+
...(projector !== undefined ? { projectItem: projector } : {})
|
|
1083
|
+
});
|
|
1084
|
+
await toolByName(tools, 'memory_write').execute({
|
|
1085
|
+
kind: 'knowledge',
|
|
1086
|
+
entityId: 'doc-1',
|
|
1087
|
+
body: 'FULLBODY'
|
|
1088
|
+
});
|
|
1089
|
+
return toolByName(tools, 'memory_read');
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
test('defaults to the FULL body (drill-in) with a bounding projector', async () => {
|
|
1093
|
+
const tool = await readToolWith(boundingProjector);
|
|
1094
|
+
expect(await tool.execute({ kind: 'knowledge', entityId: 'doc-1' })).toSucceedAndSatisfy((value) => {
|
|
1095
|
+
expect((value as IReadOut).item.body).toBe('FULLBODY');
|
|
1096
|
+
});
|
|
1097
|
+
});
|
|
1098
|
+
|
|
1099
|
+
test('opts down to gist only when detail=gist is requested', async () => {
|
|
1100
|
+
const tool = await readToolWith(boundingProjector);
|
|
1101
|
+
expect(
|
|
1102
|
+
await tool.execute({ kind: 'knowledge', entityId: 'doc-1', detail: 'gist' })
|
|
1103
|
+
).toSucceedAndSatisfy((value) => {
|
|
1104
|
+
expect((value as IReadOut).item.body).toBe('<<gist>>');
|
|
1105
|
+
});
|
|
1106
|
+
});
|
|
1107
|
+
|
|
1108
|
+
test('is byte-identical for a no-projector consumer (full body regardless of detail)', async () => {
|
|
1109
|
+
const tool = await readToolWith(undefined);
|
|
1110
|
+
for (const args of [
|
|
1111
|
+
{ kind: 'knowledge', entityId: 'doc-1' },
|
|
1112
|
+
{ kind: 'knowledge', entityId: 'doc-1', detail: 'gist' }
|
|
1113
|
+
]) {
|
|
1114
|
+
expect(await tool.execute(args)).toSucceedAndSatisfy((value) => {
|
|
1115
|
+
expect((value as IReadOut).item.body).toBe('FULLBODY');
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
1119
|
+
});
|
|
1120
|
+
});
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import '@fgv/ts-utils-jest';
|
|
7
7
|
import {
|
|
8
8
|
EntityId,
|
|
9
|
+
IEdgeTarget,
|
|
9
10
|
IMemoryEnvelope,
|
|
10
11
|
IMemoryRecord,
|
|
11
12
|
IProvenance,
|
|
@@ -13,6 +14,7 @@ import {
|
|
|
13
14
|
KnowledgeLwwPolicy,
|
|
14
15
|
MemoryCapCullPolicy,
|
|
15
16
|
MemoryId,
|
|
17
|
+
MemoryScopeKey,
|
|
16
18
|
Tag
|
|
17
19
|
} from '../../../packlets/types';
|
|
18
20
|
|
|
@@ -275,13 +277,20 @@ describe('MemoryCapCullPolicy', () => {
|
|
|
275
277
|
{
|
|
276
278
|
id: 'turn-0' as MemoryId,
|
|
277
279
|
kind: 'summarized-turn' as Kind,
|
|
278
|
-
links: [
|
|
280
|
+
links: [
|
|
281
|
+
{
|
|
282
|
+
type: 'derived-from' as never,
|
|
283
|
+
target: { scope: 'knowledge' as MemoryScopeKey, id: 'doc-1' as MemoryId } as IEdgeTarget
|
|
284
|
+
}
|
|
285
|
+
]
|
|
279
286
|
},
|
|
280
287
|
{ summary: 'old' }
|
|
281
288
|
);
|
|
282
289
|
expect(narrow.applyUpdate(existing, { body: { summary: 'x' }, links: [] })).toSucceedAndSatisfy(
|
|
283
290
|
(updated) => {
|
|
284
|
-
expect(updated.envelope.links).toEqual([
|
|
291
|
+
expect(updated.envelope.links).toEqual([
|
|
292
|
+
{ type: 'derived-from', target: { scope: 'knowledge', id: 'doc-1' } }
|
|
293
|
+
]);
|
|
285
294
|
expect(updated.body).toEqual({ summary: 'x' });
|
|
286
295
|
}
|
|
287
296
|
);
|