@mastra/memory 1.6.0 → 1.6.1
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/CHANGELOG.md +54 -0
- package/dist/{chunk-5UYAHJVJ.cjs → chunk-D6II7EP4.cjs} +660 -531
- package/dist/chunk-D6II7EP4.cjs.map +1 -0
- package/dist/{chunk-A62BQK35.js → chunk-GBBQIJQF.js} +660 -531
- package/dist/chunk-GBBQIJQF.js.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +25 -25
- package/dist/docs/references/docs-agents-agent-approval.md +61 -31
- package/dist/docs/references/docs-agents-supervisor-agents.md +1 -1
- package/dist/docs/references/docs-memory-observational-memory.md +9 -0
- package/dist/docs/references/docs-memory-semantic-recall.md +17 -1
- package/dist/docs/references/reference-core-getMemory.md +2 -2
- package/dist/docs/references/reference-core-listMemory.md +1 -1
- package/dist/docs/references/reference-memory-clone-utilities.md +5 -5
- package/dist/docs/references/reference-memory-cloneThread.md +17 -21
- package/dist/docs/references/reference-memory-createThread.md +10 -10
- package/dist/docs/references/reference-memory-getThreadById.md +2 -2
- package/dist/docs/references/reference-memory-listThreads.md +5 -5
- package/dist/docs/references/reference-memory-memory-class.md +12 -14
- package/dist/docs/references/reference-memory-observational-memory.md +102 -94
- package/dist/docs/references/reference-processors-token-limiter-processor.md +11 -13
- package/dist/docs/references/reference-storage-dynamodb.md +9 -9
- package/dist/docs/references/reference-storage-libsql.md +2 -2
- package/dist/docs/references/reference-storage-mongodb.md +5 -5
- package/dist/docs/references/reference-storage-postgresql.md +25 -25
- package/dist/docs/references/reference-storage-upstash.md +3 -3
- package/dist/docs/references/reference-vectors-libsql.md +31 -31
- package/dist/docs/references/reference-vectors-mongodb.md +32 -32
- package/dist/docs/references/reference-vectors-pg.md +60 -44
- package/dist/docs/references/reference-vectors-upstash.md +25 -25
- package/dist/index.cjs +246 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +246 -57
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-MXI54VC7.cjs → observational-memory-AHVELJX4.cjs} +17 -17
- package/dist/{observational-memory-MXI54VC7.cjs.map → observational-memory-AHVELJX4.cjs.map} +1 -1
- package/dist/{observational-memory-SR6G4HN5.js → observational-memory-QFQUF5EY.js} +3 -3
- package/dist/{observational-memory-SR6G4HN5.js.map → observational-memory-QFQUF5EY.js.map} +1 -1
- package/dist/processors/index.cjs +15 -15
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/date-utils.d.ts +35 -0
- package/dist/processors/observational-memory/date-utils.d.ts.map +1 -0
- package/dist/processors/observational-memory/markers.d.ts +94 -0
- package/dist/processors/observational-memory/markers.d.ts.map +1 -0
- package/dist/processors/observational-memory/observational-memory.d.ts +0 -76
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/operation-registry.d.ts +14 -0
- package/dist/processors/observational-memory/operation-registry.d.ts.map +1 -0
- package/dist/processors/observational-memory/thresholds.d.ts +52 -0
- package/dist/processors/observational-memory/thresholds.d.ts.map +1 -0
- package/dist/processors/observational-memory/token-counter.d.ts +4 -0
- package/dist/processors/observational-memory/token-counter.d.ts.map +1 -1
- package/dist/tools/working-memory.d.ts.map +1 -1
- package/package.json +7 -7
- package/dist/chunk-5UYAHJVJ.cjs.map +0 -1
- package/dist/chunk-A62BQK35.js.map +0 -1
|
@@ -1,64 +1,64 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkD6II7EP4_cjs = require('./chunk-D6II7EP4.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "OBSERVATIONAL_MEMORY_DEFAULTS", {
|
|
8
8
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
9
|
+
get: function () { return chunkD6II7EP4_cjs.OBSERVATIONAL_MEMORY_DEFAULTS; }
|
|
10
10
|
});
|
|
11
11
|
Object.defineProperty(exports, "OBSERVATION_CONTEXT_INSTRUCTIONS", {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkD6II7EP4_cjs.OBSERVATION_CONTEXT_INSTRUCTIONS; }
|
|
14
14
|
});
|
|
15
15
|
Object.defineProperty(exports, "OBSERVATION_CONTEXT_PROMPT", {
|
|
16
16
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
17
|
+
get: function () { return chunkD6II7EP4_cjs.OBSERVATION_CONTEXT_PROMPT; }
|
|
18
18
|
});
|
|
19
19
|
Object.defineProperty(exports, "OBSERVATION_CONTINUATION_HINT", {
|
|
20
20
|
enumerable: true,
|
|
21
|
-
get: function () { return
|
|
21
|
+
get: function () { return chunkD6II7EP4_cjs.OBSERVATION_CONTINUATION_HINT; }
|
|
22
22
|
});
|
|
23
23
|
Object.defineProperty(exports, "OBSERVER_SYSTEM_PROMPT", {
|
|
24
24
|
enumerable: true,
|
|
25
|
-
get: function () { return
|
|
25
|
+
get: function () { return chunkD6II7EP4_cjs.OBSERVER_SYSTEM_PROMPT; }
|
|
26
26
|
});
|
|
27
27
|
Object.defineProperty(exports, "ObservationalMemory", {
|
|
28
28
|
enumerable: true,
|
|
29
|
-
get: function () { return
|
|
29
|
+
get: function () { return chunkD6II7EP4_cjs.ObservationalMemory; }
|
|
30
30
|
});
|
|
31
31
|
Object.defineProperty(exports, "TokenCounter", {
|
|
32
32
|
enumerable: true,
|
|
33
|
-
get: function () { return
|
|
33
|
+
get: function () { return chunkD6II7EP4_cjs.TokenCounter; }
|
|
34
34
|
});
|
|
35
35
|
Object.defineProperty(exports, "buildObserverPrompt", {
|
|
36
36
|
enumerable: true,
|
|
37
|
-
get: function () { return
|
|
37
|
+
get: function () { return chunkD6II7EP4_cjs.buildObserverPrompt; }
|
|
38
38
|
});
|
|
39
39
|
Object.defineProperty(exports, "buildObserverSystemPrompt", {
|
|
40
40
|
enumerable: true,
|
|
41
|
-
get: function () { return
|
|
41
|
+
get: function () { return chunkD6II7EP4_cjs.buildObserverSystemPrompt; }
|
|
42
42
|
});
|
|
43
43
|
Object.defineProperty(exports, "extractCurrentTask", {
|
|
44
44
|
enumerable: true,
|
|
45
|
-
get: function () { return
|
|
45
|
+
get: function () { return chunkD6II7EP4_cjs.extractCurrentTask; }
|
|
46
46
|
});
|
|
47
47
|
Object.defineProperty(exports, "formatMessagesForObserver", {
|
|
48
48
|
enumerable: true,
|
|
49
|
-
get: function () { return
|
|
49
|
+
get: function () { return chunkD6II7EP4_cjs.formatMessagesForObserver; }
|
|
50
50
|
});
|
|
51
51
|
Object.defineProperty(exports, "hasCurrentTaskSection", {
|
|
52
52
|
enumerable: true,
|
|
53
|
-
get: function () { return
|
|
53
|
+
get: function () { return chunkD6II7EP4_cjs.hasCurrentTaskSection; }
|
|
54
54
|
});
|
|
55
55
|
Object.defineProperty(exports, "optimizeObservationsForContext", {
|
|
56
56
|
enumerable: true,
|
|
57
|
-
get: function () { return
|
|
57
|
+
get: function () { return chunkD6II7EP4_cjs.optimizeObservationsForContext; }
|
|
58
58
|
});
|
|
59
59
|
Object.defineProperty(exports, "parseObserverOutput", {
|
|
60
60
|
enumerable: true,
|
|
61
|
-
get: function () { return
|
|
61
|
+
get: function () { return chunkD6II7EP4_cjs.parseObserverOutput; }
|
|
62
62
|
});
|
|
63
|
-
//# sourceMappingURL=observational-memory-
|
|
64
|
-
//# sourceMappingURL=observational-memory-
|
|
63
|
+
//# sourceMappingURL=observational-memory-AHVELJX4.cjs.map
|
|
64
|
+
//# sourceMappingURL=observational-memory-AHVELJX4.cjs.map
|
package/dist/{observational-memory-MXI54VC7.cjs.map → observational-memory-AHVELJX4.cjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"observational-memory-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"observational-memory-AHVELJX4.cjs"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, extractCurrentTask, formatMessagesForObserver, hasCurrentTaskSection, optimizeObservationsForContext, parseObserverOutput } from './chunk-
|
|
2
|
-
//# sourceMappingURL=observational-memory-
|
|
3
|
-
//# sourceMappingURL=observational-memory-
|
|
1
|
+
export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, extractCurrentTask, formatMessagesForObserver, hasCurrentTaskSection, optimizeObservationsForContext, parseObserverOutput } from './chunk-GBBQIJQF.js';
|
|
2
|
+
//# sourceMappingURL=observational-memory-QFQUF5EY.js.map
|
|
3
|
+
//# sourceMappingURL=observational-memory-QFQUF5EY.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"observational-memory-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"observational-memory-QFQUF5EY.js"}
|
|
@@ -1,64 +1,64 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkD6II7EP4_cjs = require('../chunk-D6II7EP4.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "OBSERVATIONAL_MEMORY_DEFAULTS", {
|
|
8
8
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
9
|
+
get: function () { return chunkD6II7EP4_cjs.OBSERVATIONAL_MEMORY_DEFAULTS; }
|
|
10
10
|
});
|
|
11
11
|
Object.defineProperty(exports, "OBSERVATION_CONTEXT_INSTRUCTIONS", {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkD6II7EP4_cjs.OBSERVATION_CONTEXT_INSTRUCTIONS; }
|
|
14
14
|
});
|
|
15
15
|
Object.defineProperty(exports, "OBSERVATION_CONTEXT_PROMPT", {
|
|
16
16
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
17
|
+
get: function () { return chunkD6II7EP4_cjs.OBSERVATION_CONTEXT_PROMPT; }
|
|
18
18
|
});
|
|
19
19
|
Object.defineProperty(exports, "OBSERVATION_CONTINUATION_HINT", {
|
|
20
20
|
enumerable: true,
|
|
21
|
-
get: function () { return
|
|
21
|
+
get: function () { return chunkD6II7EP4_cjs.OBSERVATION_CONTINUATION_HINT; }
|
|
22
22
|
});
|
|
23
23
|
Object.defineProperty(exports, "OBSERVER_SYSTEM_PROMPT", {
|
|
24
24
|
enumerable: true,
|
|
25
|
-
get: function () { return
|
|
25
|
+
get: function () { return chunkD6II7EP4_cjs.OBSERVER_SYSTEM_PROMPT; }
|
|
26
26
|
});
|
|
27
27
|
Object.defineProperty(exports, "ObservationalMemory", {
|
|
28
28
|
enumerable: true,
|
|
29
|
-
get: function () { return
|
|
29
|
+
get: function () { return chunkD6II7EP4_cjs.ObservationalMemory; }
|
|
30
30
|
});
|
|
31
31
|
Object.defineProperty(exports, "TokenCounter", {
|
|
32
32
|
enumerable: true,
|
|
33
|
-
get: function () { return
|
|
33
|
+
get: function () { return chunkD6II7EP4_cjs.TokenCounter; }
|
|
34
34
|
});
|
|
35
35
|
Object.defineProperty(exports, "buildObserverPrompt", {
|
|
36
36
|
enumerable: true,
|
|
37
|
-
get: function () { return
|
|
37
|
+
get: function () { return chunkD6II7EP4_cjs.buildObserverPrompt; }
|
|
38
38
|
});
|
|
39
39
|
Object.defineProperty(exports, "buildObserverSystemPrompt", {
|
|
40
40
|
enumerable: true,
|
|
41
|
-
get: function () { return
|
|
41
|
+
get: function () { return chunkD6II7EP4_cjs.buildObserverSystemPrompt; }
|
|
42
42
|
});
|
|
43
43
|
Object.defineProperty(exports, "extractCurrentTask", {
|
|
44
44
|
enumerable: true,
|
|
45
|
-
get: function () { return
|
|
45
|
+
get: function () { return chunkD6II7EP4_cjs.extractCurrentTask; }
|
|
46
46
|
});
|
|
47
47
|
Object.defineProperty(exports, "formatMessagesForObserver", {
|
|
48
48
|
enumerable: true,
|
|
49
|
-
get: function () { return
|
|
49
|
+
get: function () { return chunkD6II7EP4_cjs.formatMessagesForObserver; }
|
|
50
50
|
});
|
|
51
51
|
Object.defineProperty(exports, "hasCurrentTaskSection", {
|
|
52
52
|
enumerable: true,
|
|
53
|
-
get: function () { return
|
|
53
|
+
get: function () { return chunkD6II7EP4_cjs.hasCurrentTaskSection; }
|
|
54
54
|
});
|
|
55
55
|
Object.defineProperty(exports, "optimizeObservationsForContext", {
|
|
56
56
|
enumerable: true,
|
|
57
|
-
get: function () { return
|
|
57
|
+
get: function () { return chunkD6II7EP4_cjs.optimizeObservationsForContext; }
|
|
58
58
|
});
|
|
59
59
|
Object.defineProperty(exports, "parseObserverOutput", {
|
|
60
60
|
enumerable: true,
|
|
61
|
-
get: function () { return
|
|
61
|
+
get: function () { return chunkD6II7EP4_cjs.parseObserverOutput; }
|
|
62
62
|
});
|
|
63
63
|
//# sourceMappingURL=index.cjs.map
|
|
64
64
|
//# sourceMappingURL=index.cjs.map
|
package/dist/processors/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, extractCurrentTask, formatMessagesForObserver, hasCurrentTaskSection, optimizeObservationsForContext, parseObserverOutput } from '../chunk-
|
|
1
|
+
export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, extractCurrentTask, formatMessagesForObserver, hasCurrentTaskSection, optimizeObservationsForContext, parseObserverOutput } from '../chunk-GBBQIJQF.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Date/time utility functions for Observational Memory.
|
|
3
|
+
* Pure functions for formatting relative timestamps and annotating observations.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Format a relative time string like "5 days ago", "2 weeks ago", "today", etc.
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatRelativeTime(date: Date, currentDate: Date): string;
|
|
9
|
+
/**
|
|
10
|
+
* Format the gap between two dates as a human-readable string.
|
|
11
|
+
* Returns null for consecutive days (no gap marker needed).
|
|
12
|
+
*/
|
|
13
|
+
export declare function formatGapBetweenDates(prevDate: Date, currDate: Date): string | null;
|
|
14
|
+
/**
|
|
15
|
+
* Parses a date string like "May 30, 2023", "May 27-28, 2023", "late April 2023", etc.
|
|
16
|
+
* Returns the parsed Date or null if unparseable.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseDateFromContent(dateContent: string): Date | null;
|
|
19
|
+
/**
|
|
20
|
+
* Detects if an observation line indicates future intent (will do, plans to, looking forward to, etc.)
|
|
21
|
+
*/
|
|
22
|
+
export declare function isFutureIntentObservation(line: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Expand inline estimated dates with relative time.
|
|
25
|
+
* Matches patterns like "(estimated May 27-28, 2023)" or "(meaning May 30, 2023)"
|
|
26
|
+
* and expands them to "(meaning May 30, 2023 - which was 3 weeks ago)"
|
|
27
|
+
*/
|
|
28
|
+
export declare function expandInlineEstimatedDates(observations: string, currentDate: Date): string;
|
|
29
|
+
/**
|
|
30
|
+
* Add relative time annotations to observations.
|
|
31
|
+
* Transforms "Date: May 15, 2023" headers to "Date: May 15, 2023 (5 days ago)"
|
|
32
|
+
* and expands inline estimated dates with relative time context.
|
|
33
|
+
*/
|
|
34
|
+
export declare function addRelativeTimeToObservations(observations: string, currentDate: Date): string;
|
|
35
|
+
//# sourceMappingURL=date-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-utils.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/date-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,GAAG,MAAM,CAwBxE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAmBnF;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAuDrE;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAa/D;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,GAAG,MAAM,CAkC1F;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,GAAG,MAAM,CA2D7F"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { DataOmActivationPart, DataOmBufferingEndPart, DataOmBufferingFailedPart, DataOmBufferingStartPart, DataOmObservationEndPart, DataOmObservationFailedPart, DataOmObservationStartPart, ObservationMarkerConfig, OmOperationType } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create a start marker for when observation begins.
|
|
4
|
+
*/
|
|
5
|
+
export declare function createObservationStartMarker(params: {
|
|
6
|
+
cycleId: string;
|
|
7
|
+
operationType: 'observation' | 'reflection';
|
|
8
|
+
tokensToObserve: number;
|
|
9
|
+
recordId: string;
|
|
10
|
+
threadId: string;
|
|
11
|
+
threadIds: string[];
|
|
12
|
+
config: ObservationMarkerConfig;
|
|
13
|
+
}): DataOmObservationStartPart;
|
|
14
|
+
/**
|
|
15
|
+
* Create an end marker for when observation completes successfully.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createObservationEndMarker(params: {
|
|
18
|
+
cycleId: string;
|
|
19
|
+
operationType: 'observation' | 'reflection';
|
|
20
|
+
startedAt: string;
|
|
21
|
+
tokensObserved: number;
|
|
22
|
+
observationTokens: number;
|
|
23
|
+
observations?: string;
|
|
24
|
+
currentTask?: string;
|
|
25
|
+
suggestedResponse?: string;
|
|
26
|
+
recordId: string;
|
|
27
|
+
threadId: string;
|
|
28
|
+
}): DataOmObservationEndPart;
|
|
29
|
+
/**
|
|
30
|
+
* Create a failed marker for when observation fails.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createObservationFailedMarker(params: {
|
|
33
|
+
cycleId: string;
|
|
34
|
+
operationType: 'observation' | 'reflection';
|
|
35
|
+
startedAt: string;
|
|
36
|
+
tokensAttempted: number;
|
|
37
|
+
error: string;
|
|
38
|
+
recordId: string;
|
|
39
|
+
threadId: string;
|
|
40
|
+
}): DataOmObservationFailedPart;
|
|
41
|
+
/**
|
|
42
|
+
* Create a start marker for when async buffering begins.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createBufferingStartMarker(params: {
|
|
45
|
+
cycleId: string;
|
|
46
|
+
operationType: OmOperationType;
|
|
47
|
+
tokensToBuffer: number;
|
|
48
|
+
recordId: string;
|
|
49
|
+
threadId: string;
|
|
50
|
+
threadIds: string[];
|
|
51
|
+
config: ObservationMarkerConfig;
|
|
52
|
+
}): DataOmBufferingStartPart;
|
|
53
|
+
/**
|
|
54
|
+
* Create an end marker for when async buffering completes successfully.
|
|
55
|
+
*/
|
|
56
|
+
export declare function createBufferingEndMarker(params: {
|
|
57
|
+
cycleId: string;
|
|
58
|
+
operationType: OmOperationType;
|
|
59
|
+
startedAt: string;
|
|
60
|
+
tokensBuffered: number;
|
|
61
|
+
bufferedTokens: number;
|
|
62
|
+
recordId: string;
|
|
63
|
+
threadId: string;
|
|
64
|
+
observations?: string;
|
|
65
|
+
}): DataOmBufferingEndPart;
|
|
66
|
+
/**
|
|
67
|
+
* Create a failed marker for when async buffering fails.
|
|
68
|
+
*/
|
|
69
|
+
export declare function createBufferingFailedMarker(params: {
|
|
70
|
+
cycleId: string;
|
|
71
|
+
operationType: OmOperationType;
|
|
72
|
+
startedAt: string;
|
|
73
|
+
tokensAttempted: number;
|
|
74
|
+
error: string;
|
|
75
|
+
recordId: string;
|
|
76
|
+
threadId: string;
|
|
77
|
+
}): DataOmBufferingFailedPart;
|
|
78
|
+
/**
|
|
79
|
+
* Create an activation marker for when buffered observations are activated.
|
|
80
|
+
*/
|
|
81
|
+
export declare function createActivationMarker(params: {
|
|
82
|
+
cycleId: string;
|
|
83
|
+
operationType: OmOperationType;
|
|
84
|
+
chunksActivated: number;
|
|
85
|
+
tokensActivated: number;
|
|
86
|
+
observationTokens: number;
|
|
87
|
+
messagesActivated: number;
|
|
88
|
+
recordId: string;
|
|
89
|
+
threadId: string;
|
|
90
|
+
generationCount: number;
|
|
91
|
+
observations?: string;
|
|
92
|
+
config: ObservationMarkerConfig;
|
|
93
|
+
}): DataOmActivationPart;
|
|
94
|
+
//# sourceMappingURL=markers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markers.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/markers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,yBAAyB,EACzB,wBAAwB,EACxB,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;CACjC,GAAG,oBAAoB,CAkBvB"}
|
|
@@ -345,23 +345,6 @@ export declare class ObservationalMemory implements Processor<'observational-mem
|
|
|
345
345
|
* Handles cases where it might be a JSON string or undefined.
|
|
346
346
|
*/
|
|
347
347
|
private getBufferedChunks;
|
|
348
|
-
/**
|
|
349
|
-
* Resolve bufferActivation config into an absolute retention floor (tokens to keep).
|
|
350
|
-
* - Value in (0, 1]: ratio → retentionFloor = threshold * (1 - value)
|
|
351
|
-
* - Value >= 1000: absolute token count → retentionFloor = value
|
|
352
|
-
*/
|
|
353
|
-
private resolveRetentionFloor;
|
|
354
|
-
/**
|
|
355
|
-
* Convert bufferActivation to the equivalent ratio (0-1) for the storage layer.
|
|
356
|
-
* When bufferActivation >= 1000, it's an absolute retention target, so we compute
|
|
357
|
-
* the equivalent ratio: 1 - (bufferActivation / threshold).
|
|
358
|
-
*/
|
|
359
|
-
private resolveActivationRatio;
|
|
360
|
-
/**
|
|
361
|
-
* Calculate the projected message tokens that would be removed if activation happened now.
|
|
362
|
-
* This replicates the chunk boundary logic in swapBufferedToActive without actually activating.
|
|
363
|
-
*/
|
|
364
|
-
private calculateProjectedMessageRemoval;
|
|
365
348
|
/**
|
|
366
349
|
* Check if we've crossed a new bufferTokens interval boundary.
|
|
367
350
|
* Returns true if async buffering should be triggered.
|
|
@@ -433,37 +416,6 @@ export declare class ObservationalMemory implements Processor<'observational-mem
|
|
|
433
416
|
* Ensures bufferTokens is less than the threshold and bufferActivation is valid.
|
|
434
417
|
*/
|
|
435
418
|
private validateBufferConfig;
|
|
436
|
-
/**
|
|
437
|
-
* Resolve bufferTokens: if it's a fraction (0 < value < 1), multiply by messageTokens threshold.
|
|
438
|
-
* Otherwise return the absolute token count.
|
|
439
|
-
*/
|
|
440
|
-
private resolveBufferTokens;
|
|
441
|
-
/**
|
|
442
|
-
* Resolve blockAfter config value.
|
|
443
|
-
* Values in [1, 100) are treated as multipliers of the threshold.
|
|
444
|
-
* e.g. blockAfter: 1.5 with messageTokens: 20_000 → 30_000
|
|
445
|
-
* Values >= 100 are treated as absolute token counts.
|
|
446
|
-
* Defaults to 1.2 (120% of threshold) when async buffering is enabled but blockAfter is omitted.
|
|
447
|
-
*/
|
|
448
|
-
private resolveBlockAfter;
|
|
449
|
-
/**
|
|
450
|
-
* Get the maximum value from a threshold (simple number or range)
|
|
451
|
-
*/
|
|
452
|
-
private getMaxThreshold;
|
|
453
|
-
/**
|
|
454
|
-
* Calculate dynamic threshold based on observation space.
|
|
455
|
-
* When shareTokenBudget is enabled, the message threshold can expand
|
|
456
|
-
* into unused observation space, up to the total context budget.
|
|
457
|
-
*
|
|
458
|
-
* Total budget = messageTokens + observationTokens
|
|
459
|
-
* Effective threshold = totalBudget - currentObservationTokens
|
|
460
|
-
*
|
|
461
|
-
* Example with 30k:40k thresholds (70k total):
|
|
462
|
-
* - 0 observations → messages can use ~70k
|
|
463
|
-
* - 10k observations → messages can use ~60k
|
|
464
|
-
* - 40k observations → messages back to ~30k
|
|
465
|
-
*/
|
|
466
|
-
private calculateDynamicThreshold;
|
|
467
419
|
/**
|
|
468
420
|
* Check whether the unobserved message tokens meet the observation threshold.
|
|
469
421
|
*/
|
|
@@ -493,34 +445,6 @@ export declare class ObservationalMemory implements Processor<'observational-mem
|
|
|
493
445
|
* Get current config snapshot for observation markers.
|
|
494
446
|
*/
|
|
495
447
|
private getObservationMarkerConfig;
|
|
496
|
-
/**
|
|
497
|
-
* Create a start marker for when observation begins.
|
|
498
|
-
*/
|
|
499
|
-
private createObservationStartMarker;
|
|
500
|
-
/**
|
|
501
|
-
* Create an end marker for when observation completes successfully.
|
|
502
|
-
*/
|
|
503
|
-
private createObservationEndMarker;
|
|
504
|
-
/**
|
|
505
|
-
* Create a failed marker for when observation fails.
|
|
506
|
-
*/
|
|
507
|
-
private createObservationFailedMarker;
|
|
508
|
-
/**
|
|
509
|
-
* Create a start marker for when async buffering begins.
|
|
510
|
-
*/
|
|
511
|
-
private createBufferingStartMarker;
|
|
512
|
-
/**
|
|
513
|
-
* Create an end marker for when async buffering completes successfully.
|
|
514
|
-
*/
|
|
515
|
-
private createBufferingEndMarker;
|
|
516
|
-
/**
|
|
517
|
-
* Create a failed marker for when async buffering fails.
|
|
518
|
-
*/
|
|
519
|
-
private createBufferingFailedMarker;
|
|
520
|
-
/**
|
|
521
|
-
* Create an activation marker for when buffered observations are activated.
|
|
522
|
-
*/
|
|
523
|
-
private createActivationMarker;
|
|
524
448
|
/**
|
|
525
449
|
* Persist a data-om-* marker part on the last assistant message in messageList
|
|
526
450
|
* AND save the updated message to the DB so it survives page reload.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observational-memory.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/observational-memory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGpF,OAAO,KAAK,EACV,SAAS,EAET,oBAAoB,EACpB,uBAAuB,EAExB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB,EAA4B,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"observational-memory.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/observational-memory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGpF,OAAO,KAAK,EACV,SAAS,EAET,oBAAoB,EACpB,uBAAuB,EAExB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB,EAA4B,MAAM,sBAAsB,CAAC;AAkE/G,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,K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AAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAMzF;;OAEG;IACG,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC;IAKjG;;OAEG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,EAAE,CAAC;IAK7G;;OAEG;IACG,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjE;;OAEG;IACH,UAAU,IAAI,aAAa;IAI3B;;OAEG;IACH,eAAe,IAAI,YAAY;IAI/B;;OAEG;IACH,oBAAoB,IAAI,yBAAyB;IAIjD;;OAEG;IACH,mBAAmB,IAAI,wBAAwB;CAGhD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-level operation registry for Observational Memory.
|
|
3
|
+
*
|
|
4
|
+
* Tracks which operations (reflecting, observing, buffering) are actively running
|
|
5
|
+
* in THIS process. Used to detect stale DB flags left by crashed processes.
|
|
6
|
+
*
|
|
7
|
+
* Key format: `${recordId}:${operationType}`
|
|
8
|
+
*/
|
|
9
|
+
export type OmOperationName = 'reflecting' | 'observing' | 'bufferingObservation' | 'bufferingReflection';
|
|
10
|
+
export declare function opKey(recordId: string, op: OmOperationName): string;
|
|
11
|
+
export declare function registerOp(recordId: string, op: OmOperationName): void;
|
|
12
|
+
export declare function unregisterOp(recordId: string, op: OmOperationName): void;
|
|
13
|
+
export declare function isOpActiveInProcess(recordId: string, op: OmOperationName): boolean;
|
|
14
|
+
//# sourceMappingURL=operation-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-registry.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/operation-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,WAAW,GAAG,sBAAsB,GAAG,qBAAqB,CAAC;AAI1G,wBAAgB,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,eAAe,GAAG,MAAM,CAEnE;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,eAAe,GAAG,IAAI,CAGtE;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,eAAe,GAAG,IAAI,CASxE;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,eAAe,GAAG,OAAO,CAElF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { BufferedObservationChunk } from '@mastra/core/storage';
|
|
2
|
+
import type { ThresholdRange } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Get the maximum value from a threshold (simple number or range).
|
|
5
|
+
*/
|
|
6
|
+
export declare function getMaxThreshold(threshold: number | ThresholdRange): number;
|
|
7
|
+
/**
|
|
8
|
+
* Calculate dynamic threshold based on observation space.
|
|
9
|
+
* When shareTokenBudget is enabled, the message threshold can expand
|
|
10
|
+
* into unused observation space, up to the total context budget.
|
|
11
|
+
*
|
|
12
|
+
* Total budget = messageTokens + observationTokens
|
|
13
|
+
* Effective threshold = totalBudget - currentObservationTokens
|
|
14
|
+
*
|
|
15
|
+
* Example with 30k:40k thresholds (70k total):
|
|
16
|
+
* - 0 observations → messages can use ~70k
|
|
17
|
+
* - 10k observations → messages can use ~60k
|
|
18
|
+
* - 40k observations → messages back to ~30k
|
|
19
|
+
*/
|
|
20
|
+
export declare function calculateDynamicThreshold(threshold: number | ThresholdRange, currentObservationTokens: number): number;
|
|
21
|
+
/**
|
|
22
|
+
* Resolve bufferTokens config value.
|
|
23
|
+
* Values in (0, 1) are treated as ratios of the message threshold.
|
|
24
|
+
* e.g. bufferTokens: 0.25 with messageTokens: 20_000 → 5_000
|
|
25
|
+
*/
|
|
26
|
+
export declare function resolveBufferTokens(bufferTokens: number | false | undefined, messageTokens: number | ThresholdRange): number | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Resolve blockAfter config value.
|
|
29
|
+
* Values in [1, 100) are treated as multipliers of the threshold.
|
|
30
|
+
* e.g. blockAfter: 1.5 with messageTokens: 20_000 → 30_000
|
|
31
|
+
* Values >= 100 are treated as absolute token counts.
|
|
32
|
+
* Defaults to 1.2 (120% of threshold) when async buffering is enabled but blockAfter is omitted.
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolveBlockAfter(blockAfter: number | undefined, messageTokens: number | ThresholdRange): number | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Convert bufferActivation to an absolute retention floor (tokens to keep after activation).
|
|
37
|
+
* When bufferActivation >= 1000, it's an absolute retention target.
|
|
38
|
+
* Otherwise it's a ratio: retentionFloor = threshold * (1 - ratio).
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveRetentionFloor(bufferActivation: number, messageTokensThreshold: number): number;
|
|
41
|
+
/**
|
|
42
|
+
* Convert bufferActivation to the equivalent ratio (0-1) for the storage layer.
|
|
43
|
+
* When bufferActivation >= 1000, it's an absolute retention target, so we compute
|
|
44
|
+
* the equivalent ratio: 1 - (bufferActivation / threshold).
|
|
45
|
+
*/
|
|
46
|
+
export declare function resolveActivationRatio(bufferActivation: number, messageTokensThreshold: number): number;
|
|
47
|
+
/**
|
|
48
|
+
* Calculate the projected message tokens that would be removed if activation happened now.
|
|
49
|
+
* This replicates the chunk boundary logic in swapBufferedToActive without actually activating.
|
|
50
|
+
*/
|
|
51
|
+
export declare function calculateProjectedMessageRemoval(chunks: BufferedObservationChunk[], bufferActivation: number, messageTokensThreshold: number, currentPendingTokens: number): number;
|
|
52
|
+
//# sourceMappingURL=thresholds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thresholds.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/thresholds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAErE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;GAEG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,GAAG,MAAM,CAK1E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,MAAM,GAAG,cAAc,EAClC,wBAAwB,EAAE,MAAM,GAC/B,MAAM,CAiBR;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,EACxC,aAAa,EAAE,MAAM,GAAG,cAAc,GACrC,MAAM,GAAG,SAAS,CAOpB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,aAAa,EAAE,MAAM,GAAG,cAAc,GACrC,MAAM,GAAG,SAAS,CASpB;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,GAAG,MAAM,CAItG;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,gBAAgB,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,GAAG,MAAM,CAKvG;AAED;;;GAGG;AACH,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,wBAAwB,EAAE,EAClC,gBAAgB,EAAE,MAAM,EACxB,sBAAsB,EAAE,MAAM,EAC9B,oBAAoB,EAAE,MAAM,GAC3B,MAAM,CAkER"}
|
|
@@ -7,6 +7,7 @@ import type { TiktokenBPE } from 'js-tiktoken/lite';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class TokenCounter {
|
|
9
9
|
private encoder;
|
|
10
|
+
private readonly cacheSource;
|
|
10
11
|
private static readonly TOKENS_PER_MESSAGE;
|
|
11
12
|
private static readonly TOKENS_PER_CONVERSATION;
|
|
12
13
|
constructor(encoding?: TiktokenBPE);
|
|
@@ -14,6 +15,9 @@ export declare class TokenCounter {
|
|
|
14
15
|
* Count tokens in a plain string
|
|
15
16
|
*/
|
|
16
17
|
countString(text: string): number;
|
|
18
|
+
private readOrPersistPartEstimate;
|
|
19
|
+
private readOrPersistMessageEstimate;
|
|
20
|
+
private resolveToolResultForTokenCounting;
|
|
17
21
|
/**
|
|
18
22
|
* Count tokens in a single message
|
|
19
23
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-counter.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/token-counter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"token-counter.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/token-counter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAkJpD;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IAKrC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAO;IAEjD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,uBAAuB,CAAM;gBAEzC,QAAQ,CAAC,EAAE,WAAW;IAKlC;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAMjC,OAAO,CAAC,yBAAyB;IAkBjC,OAAO,CAAC,4BAA4B;IAkBpC,OAAO,CAAC,iCAAiC;IAkBzC;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM;IA0F9C;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,MAAM;IAUlD;;OAEG;IACH,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;CAGhD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"working-memory.d.ts","sourceRoot":"","sources":["../../src/tools/working-memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAOxD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,EACpD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,GACjD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA4CzB;AAED,eAAO,MAAM,uBAAuB,GAAI,eAAe,YAAY;;;;;;
|
|
1
|
+
{"version":3,"file":"working-memory.d.ts","sourceRoot":"","sources":["../../src/tools/working-memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAOxD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,EACpD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,GACjD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA4CzB;AAED,eAAO,MAAM,uBAAuB,GAAI,eAAe,YAAY;;;;;;oIA0JlE,CAAC;AAEF,eAAO,MAAM,2CAA2C,GAAI,QAAQ,YAAY;;;;yIAuG/E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/memory",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
"typescript": "^5.9.3",
|
|
57
57
|
"typescript-eslint": "^8.51.0",
|
|
58
58
|
"vitest": "4.0.18",
|
|
59
|
-
"@internal/ai-sdk-v4": "0.0.
|
|
60
|
-
"@internal/ai-
|
|
61
|
-
"@internal/ai-
|
|
62
|
-
"@internal/lint": "0.0.
|
|
63
|
-
"@internal/types-builder": "0.0.
|
|
64
|
-
"@mastra/core": "1.
|
|
59
|
+
"@internal/ai-sdk-v4": "0.0.13",
|
|
60
|
+
"@internal/ai-v6": "0.0.13",
|
|
61
|
+
"@internal/ai-sdk-v5": "0.0.13",
|
|
62
|
+
"@internal/lint": "0.0.66",
|
|
63
|
+
"@internal/types-builder": "0.0.41",
|
|
64
|
+
"@mastra/core": "1.10.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"@mastra/core": ">=1.4.1-0 <2.0.0-0",
|