@mastra/memory 0.0.0-error-handler-fix-20251020202607 → 0.0.0-esbuild-bundle-worker-20260807182016
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 +4656 -3
- package/LICENSE.md +15 -0
- package/README.md +26 -1
- package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +7450 -0
- package/dist/docs/SKILL.md +62 -0
- package/dist/docs/assets/SOURCE_MAP.json +11 -0
- package/dist/docs/references/docs-agents-agent-approval.md +664 -0
- package/dist/docs/references/docs-agents-networks.md +184 -0
- package/dist/docs/references/docs-capabilities-subagents.md +454 -0
- package/dist/docs/references/docs-evals-evals-with-memory.md +146 -0
- package/dist/docs/references/docs-long-running-agents-background-tasks.md +382 -0
- package/dist/docs/references/docs-long-running-agents-goals.md +118 -0
- package/dist/docs/references/docs-memory-memory-processors.md +385 -0
- package/dist/docs/references/docs-memory-message-history.md +348 -0
- package/dist/docs/references/docs-memory-multi-user-threads.md +208 -0
- package/dist/docs/references/docs-memory-observational-memory.md +835 -0
- package/dist/docs/references/docs-memory-overview.md +266 -0
- package/dist/docs/references/docs-memory-semantic-recall.md +401 -0
- package/dist/docs/references/docs-memory-working-memory.md +431 -0
- package/dist/docs/references/docs-storage-overview.md +214 -0
- package/dist/docs/references/reference-core-getMemory.md +51 -0
- package/dist/docs/references/reference-core-listMemory.md +57 -0
- package/dist/docs/references/reference-file-based-agents-memory.md +58 -0
- package/dist/docs/references/reference-memory-clone-utilities.md +203 -0
- package/dist/docs/references/reference-memory-cloneThread.md +173 -0
- package/dist/docs/references/reference-memory-createThread.md +70 -0
- package/dist/docs/references/reference-memory-getThreadById.md +26 -0
- package/dist/docs/references/reference-memory-listThreads.md +147 -0
- package/dist/docs/references/reference-memory-memory-class.md +148 -0
- package/dist/docs/references/reference-memory-observational-memory.md +877 -0
- package/dist/docs/references/reference-memory-summarizeConversation.md +99 -0
- package/dist/docs/references/reference-memory-summarizeThread.md +93 -0
- package/dist/docs/references/reference-processors-token-limiter-processor.md +158 -0
- package/dist/docs/references/reference-storage-dsql.md +430 -0
- package/dist/docs/references/reference-storage-dynamodb.md +284 -0
- package/dist/docs/references/reference-storage-libsql.md +143 -0
- package/dist/docs/references/reference-storage-mongodb.md +267 -0
- package/dist/docs/references/reference-storage-postgresql.md +531 -0
- package/dist/docs/references/reference-storage-redis.md +268 -0
- package/dist/docs/references/reference-storage-upstash.md +162 -0
- package/dist/docs/references/reference-vectors-libsql.md +307 -0
- package/dist/docs/references/reference-vectors-mongodb.md +567 -0
- package/dist/docs/references/reference-vectors-pg.md +430 -0
- package/dist/docs/references/reference-vectors-upstash.md +296 -0
- package/dist/index.cjs +35 -893
- package/dist/index.d.ts +465 -62
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -887
- package/dist/processors/index.cjs +32 -165
- package/dist/processors/index.d.ts +1 -2
- package/dist/processors/index.d.ts.map +1 -1
- package/dist/processors/index.js +2 -158
- package/dist/processors/observational-memory/activation-ttl.d.ts +4 -0
- package/dist/processors/observational-memory/activation-ttl.d.ts.map +1 -0
- package/dist/processors/observational-memory/anchor-ids.d.ts +4 -0
- package/dist/processors/observational-memory/anchor-ids.d.ts.map +1 -0
- package/dist/processors/observational-memory/buffering-coordinator.d.ts +61 -0
- package/dist/processors/observational-memory/buffering-coordinator.d.ts.map +1 -0
- package/dist/processors/observational-memory/built-in-extractors.d.ts +15 -0
- package/dist/processors/observational-memory/built-in-extractors.d.ts.map +1 -0
- package/dist/processors/observational-memory/constants.d.ts +74 -0
- package/dist/processors/observational-memory/constants.d.ts.map +1 -0
- package/dist/processors/observational-memory/date-utils.d.ts +41 -0
- package/dist/processors/observational-memory/date-utils.d.ts.map +1 -0
- package/dist/processors/observational-memory/debug.d.ts +3 -0
- package/dist/processors/observational-memory/debug.d.ts.map +1 -0
- package/dist/processors/observational-memory/extracted-values.d.ts +44 -0
- package/dist/processors/observational-memory/extracted-values.d.ts.map +1 -0
- package/dist/processors/observational-memory/extraction-runner.d.ts +22 -0
- package/dist/processors/observational-memory/extraction-runner.d.ts.map +1 -0
- package/dist/processors/observational-memory/extractor.d.ts +76 -0
- package/dist/processors/observational-memory/extractor.d.ts.map +1 -0
- package/dist/processors/observational-memory/index.d.ts +30 -0
- package/dist/processors/observational-memory/index.d.ts.map +1 -0
- package/dist/processors/observational-memory/internal-request-context.d.ts +17 -0
- package/dist/processors/observational-memory/internal-request-context.d.ts.map +1 -0
- package/dist/processors/observational-memory/markers.d.ts +118 -0
- package/dist/processors/observational-memory/markers.d.ts.map +1 -0
- package/dist/processors/observational-memory/message-utils.d.ts +83 -0
- package/dist/processors/observational-memory/message-utils.d.ts.map +1 -0
- package/dist/processors/observational-memory/model-by-input-tokens.d.ts +14 -0
- package/dist/processors/observational-memory/model-by-input-tokens.d.ts.map +1 -0
- package/dist/processors/observational-memory/model-context.d.ts +2 -0
- package/dist/processors/observational-memory/model-context.d.ts.map +1 -0
- package/dist/processors/observational-memory/observation-groups.d.ts +15 -0
- package/dist/processors/observational-memory/observation-groups.d.ts.map +1 -0
- package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts +39 -0
- package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -0
- package/dist/processors/observational-memory/observation-strategies/base.d.ts +122 -0
- package/dist/processors/observational-memory/observation-strategies/base.d.ts.map +1 -0
- package/dist/processors/observational-memory/observation-strategies/index.d.ts +7 -0
- package/dist/processors/observational-memory/observation-strategies/index.d.ts.map +1 -0
- package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts +43 -0
- package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts.map +1 -0
- package/dist/processors/observational-memory/observation-strategies/sync.d.ts +41 -0
- package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -0
- package/dist/processors/observational-memory/observation-strategies/types.d.ts +103 -0
- package/dist/processors/observational-memory/observation-strategies/types.d.ts.map +1 -0
- package/dist/processors/observational-memory/observation-turn/index.d.ts +4 -0
- package/dist/processors/observational-memory/observation-turn/index.d.ts.map +1 -0
- package/dist/processors/observational-memory/observation-turn/load-memory-context.d.ts +9 -0
- package/dist/processors/observational-memory/observation-turn/load-memory-context.d.ts.map +1 -0
- package/dist/processors/observational-memory/observation-turn/step.d.ts +53 -0
- package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -0
- package/dist/processors/observational-memory/observation-turn/turn.d.ts +139 -0
- package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -0
- package/dist/processors/observational-memory/observation-turn/types.d.ts +46 -0
- package/dist/processors/observational-memory/observation-turn/types.d.ts.map +1 -0
- package/dist/processors/observational-memory/observation-utils.d.ts +16 -0
- package/dist/processors/observational-memory/observation-utils.d.ts.map +1 -0
- package/dist/processors/observational-memory/observational-memory.d.ts +930 -0
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -0
- package/dist/processors/observational-memory/observer-agent.d.ts +190 -0
- package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -0
- package/dist/processors/observational-memory/observer-runner.d.ts +141 -0
- package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -0
- 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/processor.d.ts +70 -0
- package/dist/processors/observational-memory/processor.d.ts.map +1 -0
- package/dist/processors/observational-memory/reflector-agent.d.ts +62 -0
- package/dist/processors/observational-memory/reflector-agent.d.ts.map +1 -0
- package/dist/processors/observational-memory/reflector-runner.d.ts +133 -0
- package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -0
- package/dist/processors/observational-memory/repro-capture.d.ts +33 -0
- package/dist/processors/observational-memory/repro-capture.d.ts.map +1 -0
- package/dist/processors/observational-memory/retry.d.ts +63 -0
- package/dist/processors/observational-memory/retry.d.ts.map +1 -0
- package/dist/processors/observational-memory/string-utils.d.ts +13 -0
- package/dist/processors/observational-memory/string-utils.d.ts.map +1 -0
- package/dist/processors/observational-memory/summarize.d.ts +92 -0
- package/dist/processors/observational-memory/summarize.d.ts.map +1 -0
- package/dist/processors/observational-memory/temporal-markers.d.ts +4 -0
- package/dist/processors/observational-memory/temporal-markers.d.ts.map +1 -0
- package/dist/processors/observational-memory/temporary-memory.d.ts +8 -0
- package/dist/processors/observational-memory/temporary-memory.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 +57 -0
- package/dist/processors/observational-memory/token-counter.d.ts.map +1 -0
- package/dist/processors/observational-memory/tool-result-helpers.d.ts +12 -0
- package/dist/processors/observational-memory/tool-result-helpers.d.ts.map +1 -0
- package/dist/processors/observational-memory/tracing.d.ts +17 -0
- package/dist/processors/observational-memory/tracing.d.ts.map +1 -0
- package/dist/processors/observational-memory/types.d.ts +997 -0
- package/dist/processors/observational-memory/types.d.ts.map +1 -0
- package/dist/processors/observational-memory/working-memory-extractor.d.ts +5 -0
- package/dist/processors/observational-memory/working-memory-extractor.d.ts.map +1 -0
- package/dist/processors/working-memory-state/index.d.ts +2 -0
- package/dist/processors/working-memory-state/index.d.ts.map +1 -0
- package/dist/processors/working-memory-state/processor.d.ts +53 -0
- package/dist/processors/working-memory-state/processor.d.ts.map +1 -0
- package/dist/src-C1tlhGeW.js +28559 -0
- package/dist/src-C1tlhGeW.js.map +1 -0
- package/dist/src-DqoifKIy.cjs +28813 -0
- package/dist/src-DqoifKIy.cjs.map +1 -0
- package/dist/tools/om-tools.d.ts +172 -0
- package/dist/tools/om-tools.d.ts.map +1 -0
- package/dist/tools/working-memory.d.ts +33 -28
- package/dist/tools/working-memory.d.ts.map +1 -1
- package/package.json +36 -28
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/processors/index.cjs.map +0 -1
- package/dist/processors/index.js.map +0 -1
- package/dist/processors/token-limiter.d.ts +0 -32
- package/dist/processors/token-limiter.d.ts.map +0 -1
- package/dist/processors/tool-call-filter.d.ts +0 -20
- package/dist/processors/tool-call-filter.d.ts.map +0 -1
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { MessageList } from '@mastra/core/agent';
|
|
2
|
+
import type { Mastra } from '@mastra/core/mastra';
|
|
3
|
+
import type { ObservabilityContext } from '@mastra/core/observability';
|
|
4
|
+
import type { ProcessorContext, ProcessorStreamWriter } from '@mastra/core/processors';
|
|
5
|
+
import type { RequestContext } from '@mastra/core/request-context';
|
|
6
|
+
import type { MemoryStorage, ObservationalMemoryRecord } from '@mastra/core/storage';
|
|
7
|
+
import type { ProviderMetadata } from '@mastra/core/stream';
|
|
8
|
+
import type { Memory } from '../../index.js';
|
|
9
|
+
import { BufferingCoordinator } from './buffering-coordinator.js';
|
|
10
|
+
import type { ModelByInputTokens } from './model-by-input-tokens.js';
|
|
11
|
+
import type { CompressionLevel } from './reflector-agent.js';
|
|
12
|
+
import type { TokenCounter } from './token-counter.js';
|
|
13
|
+
import type { ObservationDebugEvent, ObservationModelContext, ObserveHooks, ResolvedObservationConfig, ResolvedReflectionConfig } from './types.js';
|
|
14
|
+
type ConcreteReflectionModel = Exclude<ResolvedReflectionConfig['model'], ModelByInputTokens>;
|
|
15
|
+
type ReflectionModelResolver = (inputTokens: number) => {
|
|
16
|
+
model: ConcreteReflectionModel;
|
|
17
|
+
selectedThreshold?: number;
|
|
18
|
+
routingStrategy?: 'model-by-input-tokens';
|
|
19
|
+
routingThresholds?: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Runs the Reflector agent for compressing observations.
|
|
23
|
+
* Handles synchronous reflection, async buffered reflection, and activation.
|
|
24
|
+
*/
|
|
25
|
+
export declare class ReflectorRunner {
|
|
26
|
+
private readonly reflectionConfig;
|
|
27
|
+
private readonly observationConfig;
|
|
28
|
+
private readonly tokenCounter;
|
|
29
|
+
private readonly resolveModel;
|
|
30
|
+
private readonly storage;
|
|
31
|
+
private readonly scope;
|
|
32
|
+
private readonly buffering;
|
|
33
|
+
private readonly emitDebugEvent;
|
|
34
|
+
private readonly persistMarkerToStorage;
|
|
35
|
+
private readonly persistMarkerToMessage;
|
|
36
|
+
private readonly getCompressionStartLevel;
|
|
37
|
+
private readonly memory?;
|
|
38
|
+
private mastra?;
|
|
39
|
+
constructor(opts: {
|
|
40
|
+
reflectionConfig: ResolvedReflectionConfig;
|
|
41
|
+
observationConfig: ResolvedObservationConfig;
|
|
42
|
+
tokenCounter: TokenCounter;
|
|
43
|
+
storage: MemoryStorage;
|
|
44
|
+
scope: 'thread' | 'resource';
|
|
45
|
+
buffering: BufferingCoordinator;
|
|
46
|
+
emitDebugEvent: (event: ObservationDebugEvent) => void;
|
|
47
|
+
persistMarkerToStorage: (marker: {
|
|
48
|
+
type: string;
|
|
49
|
+
data: unknown;
|
|
50
|
+
}, threadId: string, resourceId?: string) => Promise<void>;
|
|
51
|
+
persistMarkerToMessage: (marker: {
|
|
52
|
+
type: string;
|
|
53
|
+
data: unknown;
|
|
54
|
+
}, messageList: MessageList | undefined, threadId: string, resourceId?: string) => Promise<void>;
|
|
55
|
+
getCompressionStartLevel: (requestContext?: RequestContext) => Promise<CompressionLevel>;
|
|
56
|
+
resolveModel: ReflectionModelResolver;
|
|
57
|
+
mastra?: Mastra;
|
|
58
|
+
memory?: Memory;
|
|
59
|
+
});
|
|
60
|
+
__registerMastra(mastra: Mastra): void;
|
|
61
|
+
private createAgent;
|
|
62
|
+
private getObservationMarkerConfig;
|
|
63
|
+
/**
|
|
64
|
+
* Resolve the effective reflection observationTokens for a record.
|
|
65
|
+
* Only explicit per-record overrides (stored under `_overrides`) win;
|
|
66
|
+
* the initial config snapshot is ignored so instance-level changes
|
|
67
|
+
* still take effect for existing records.
|
|
68
|
+
*/
|
|
69
|
+
private getEffectiveReflectionTokens;
|
|
70
|
+
/**
|
|
71
|
+
* Call the Reflector agent with escalating compression levels.
|
|
72
|
+
*/
|
|
73
|
+
call(observations: string, manualPrompt?: string, streamContext?: {
|
|
74
|
+
writer?: ProcessorStreamWriter;
|
|
75
|
+
cycleId: string;
|
|
76
|
+
startedAt: string;
|
|
77
|
+
recordId: string;
|
|
78
|
+
threadId: string;
|
|
79
|
+
resourceId?: string;
|
|
80
|
+
}, observationTokensThreshold?: number, abortSignal?: AbortSignal, skipContinuationHints?: boolean, compressionStartLevel?: CompressionLevel, requestContext?: RequestContext, priorExtractedValues?: Record<string, unknown>, observabilityContext?: ObservabilityContext, model?: ConcreteReflectionModel, mainAgent?: ProcessorContext['agent'], sendSignal?: ProcessorContext['sendSignal']): Promise<{
|
|
81
|
+
observations: string;
|
|
82
|
+
suggestedContinuation?: string;
|
|
83
|
+
extractedValues?: Record<string, unknown>;
|
|
84
|
+
extractionFailures?: Array<{
|
|
85
|
+
slug: string;
|
|
86
|
+
error: string;
|
|
87
|
+
}>;
|
|
88
|
+
usage?: {
|
|
89
|
+
inputTokens?: number;
|
|
90
|
+
outputTokens?: number;
|
|
91
|
+
totalTokens?: number;
|
|
92
|
+
};
|
|
93
|
+
providerMetadata?: ProviderMetadata;
|
|
94
|
+
}>;
|
|
95
|
+
/**
|
|
96
|
+
* Start an async buffered reflection in the background.
|
|
97
|
+
*/
|
|
98
|
+
private startAsyncBufferedReflection;
|
|
99
|
+
/**
|
|
100
|
+
* Perform async buffered reflection — reflects observations and stores to bufferedReflection.
|
|
101
|
+
* Does NOT create a new generation or update activeObservations.
|
|
102
|
+
*/
|
|
103
|
+
private doAsyncBufferedReflection;
|
|
104
|
+
/**
|
|
105
|
+
* Try to activate buffered reflection when threshold is reached.
|
|
106
|
+
* Returns a discriminated result so the caller can distinguish between
|
|
107
|
+
* "activated", "no buffer present", and "suppressed by overshoot guard"
|
|
108
|
+
* without re-deriving that state.
|
|
109
|
+
*/
|
|
110
|
+
private tryActivateBufferedReflection;
|
|
111
|
+
/**
|
|
112
|
+
* Check if reflection needed and trigger if so.
|
|
113
|
+
* Supports both synchronous reflection and async buffered reflection.
|
|
114
|
+
* @internal Used by observation strategies. Do not call directly.
|
|
115
|
+
*/
|
|
116
|
+
maybeReflect(opts: {
|
|
117
|
+
record: ObservationalMemoryRecord;
|
|
118
|
+
observationTokens: number;
|
|
119
|
+
threadId?: string;
|
|
120
|
+
writer?: ProcessorStreamWriter;
|
|
121
|
+
abortSignal?: AbortSignal;
|
|
122
|
+
mainAgent?: ProcessorContext['agent'];
|
|
123
|
+
sendSignal?: ProcessorContext['sendSignal'];
|
|
124
|
+
messageList?: MessageList;
|
|
125
|
+
currentModel?: ObservationModelContext;
|
|
126
|
+
reflectionHooks?: Pick<ObserveHooks, 'onReflectionStart' | 'onReflectionEnd'>;
|
|
127
|
+
requestContext?: RequestContext;
|
|
128
|
+
observabilityContext?: ObservabilityContext;
|
|
129
|
+
lastActivityAt?: number;
|
|
130
|
+
}): Promise<void>;
|
|
131
|
+
}
|
|
132
|
+
export {};
|
|
133
|
+
//# sourceMappingURL=reflector-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflector-runner.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/reflector-runner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEpC,OAAO,EAAE,oBAAoB,EAAE,MAA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AE,MAAM,CAAC;QAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,MAAM,CAAC,EAAE,qBAAqB,CAAC;QAC/B,WAAW,CAAC,EAAE,WAAW,CAAC;QAC1B,SAAS,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACtC,UAAU,CAAC,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;QAC5C,WAAW,CAAC,EAAE,WAAW,CAAC;QAC1B,YAAY,CAAC,EAAE,uBAAuB,CAAC;QACvC,eAAe,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,mBAAmB,GAAG,iBAAiB,CAAC,CAAC;QAC9E,cAAc,CAAC,EAAE,cAAc,CAAC;QAChC,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;QAC5C,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,GAAG,OAAO,CAAC,IAAI,CAAC;CAkTlB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { MastraDBMessage, MessageList } from '@mastra/core/agent';
|
|
2
|
+
import type { ProcessInputStepArgs } from '@mastra/core/processors';
|
|
3
|
+
import type { BufferedObservationChunk, ObservationalMemoryRecord } from '@mastra/core/storage';
|
|
4
|
+
import type { ObserverExchange } from './observer-runner.js';
|
|
5
|
+
export declare function isOmReproCaptureEnabled(): boolean;
|
|
6
|
+
export declare function safeCaptureJson(value: unknown): unknown;
|
|
7
|
+
export declare function writeObserverExchangeReproCapture(params: {
|
|
8
|
+
threadId: string;
|
|
9
|
+
resourceId?: string;
|
|
10
|
+
label: string;
|
|
11
|
+
observerExchange?: ObserverExchange;
|
|
12
|
+
details?: Record<string, unknown>;
|
|
13
|
+
debug?: (message: string) => void;
|
|
14
|
+
}): void;
|
|
15
|
+
export declare function writeProcessInputStepReproCapture(params: {
|
|
16
|
+
threadId: string;
|
|
17
|
+
resourceId?: string;
|
|
18
|
+
stepNumber: number;
|
|
19
|
+
args: ProcessInputStepArgs;
|
|
20
|
+
preRecord: ObservationalMemoryRecord;
|
|
21
|
+
postRecord: ObservationalMemoryRecord;
|
|
22
|
+
preMessages: MastraDBMessage[];
|
|
23
|
+
preBufferedChunks: BufferedObservationChunk[];
|
|
24
|
+
preContextTokenCount: number;
|
|
25
|
+
preSerializedMessageList: ReturnType<MessageList['serialize']>;
|
|
26
|
+
postBufferedChunks: BufferedObservationChunk[];
|
|
27
|
+
postContextTokenCount: number;
|
|
28
|
+
messageList: MessageList;
|
|
29
|
+
details: Record<string, unknown>;
|
|
30
|
+
observerExchange?: ObserverExchange;
|
|
31
|
+
debug?: (message: string) => void;
|
|
32
|
+
}): void;
|
|
33
|
+
//# sourceMappingURL=repro-capture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repro-capture.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/repro-capture.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,KAAK,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEhG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAc1D,wBAAgB,uBAAuB,IAAI,OAAO,CAEjD;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAYvD;AAqND,wBAAgB,iCAAiC,CAAC,MAAM,EAAE;IACxD,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC,QAwDA;AAED,wBAAgB,iCAAiC,CAAC,MAAM,EAAE;IACxD,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,oBAAoB,CAAC;IAC3B,SAAS,EAAE,yBAAyB,CAAC;IACrC,UAAU,EAAE,yBAAyB,CAAC;IACtC,WAAW,EAAE,eAAe,EAAE,CAAC;IAC/B,iBAAiB,EAAE,wBAAwB,EAAE,CAAC;IAC9C,oBAAoB,EAAE,MAAM,CAAC;IAC7B,wBAAwB,EAAE,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC;IAC/D,kBAAkB,EAAE,wBAAwB,EAAE,CAAC;IAC/C,qBAAqB,EAAE,MAAM,CAAC;IAC9B,WAAW,EAAE,WAAW,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC,QA2HA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry knobs for the internal OM transport-error retry wrapper.
|
|
3
|
+
* Exported as a mutable object so tests can shrink the backoff schedule
|
|
4
|
+
* without changing public API.
|
|
5
|
+
*
|
|
6
|
+
* With the defaults the per-retry pre-jitter backoff schedule is:
|
|
7
|
+
* 1s, 2s, 4s, 8s, 16s, 32s, 64s, 120s (cap)
|
|
8
|
+
* giving 8 retries / 9 total attempts and ~247s (~4 minutes) of waiting
|
|
9
|
+
* before the final attempt fails. Designed to ride out short provider /
|
|
10
|
+
* network blips without holding the actor turn for much longer than that.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export declare const RETRY_CONFIG: {
|
|
15
|
+
/** Maximum number of retry *attempts* (total tries = maxRetries + 1). */
|
|
16
|
+
maxRetries: number;
|
|
17
|
+
/** Initial backoff delay in milliseconds. */
|
|
18
|
+
initialDelayMs: number;
|
|
19
|
+
/** Multiplier applied to the delay after each failed attempt. */
|
|
20
|
+
backoffFactor: number;
|
|
21
|
+
/** Cap on per-attempt delay (ms). */
|
|
22
|
+
maxDelayMs: number;
|
|
23
|
+
/** Random jitter as a fraction of the computed delay (e.g. 0.2 = ±20%). */
|
|
24
|
+
jitter: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Returns true when the given error looks like a transient transport-class
|
|
28
|
+
* failure that's worth retrying — undici `terminated`, `fetch failed`,
|
|
29
|
+
* `UND_ERR_*` codes, AI SDK `APICallError` with `isRetryable: true`, and
|
|
30
|
+
* common HTTP 408/425/429/5xx statuses. Walks the `error.cause` chain so
|
|
31
|
+
* wrapper errors don't hide the real failure.
|
|
32
|
+
*
|
|
33
|
+
* Never retries on user-initiated aborts.
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export declare function isTransientLLMError(error: unknown): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Compute the backoff delay (ms) for the Nth retry (0-indexed).
|
|
40
|
+
*
|
|
41
|
+
* Exponential growth (`initialDelayMs * backoffFactor^attempt`) capped at
|
|
42
|
+
* `maxDelayMs`, then nudged by ±`jitter` (fractional). Exported for unit
|
|
43
|
+
* tests that lock the schedule against drift.
|
|
44
|
+
*
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
export declare function computeDelay(attempt: number): number;
|
|
48
|
+
export interface WithRetryOptions {
|
|
49
|
+
/** Short label used in debug logs (e.g. 'observer', 'reflector'). */
|
|
50
|
+
label: string;
|
|
51
|
+
/** Optional abort signal — cancels both in-flight attempts and backoff waits. */
|
|
52
|
+
abortSignal?: AbortSignal;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Run `fn` with retries on transient transport-class errors.
|
|
56
|
+
*
|
|
57
|
+
* Non-transient errors (auth, validation, schema, etc.) are rethrown
|
|
58
|
+
* immediately. User-initiated aborts are rethrown without delay.
|
|
59
|
+
*
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
export declare function withRetry<T>(fn: () => Promise<T>, opts: WithRetryOptions): Promise<T>;
|
|
63
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/retry.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY;IACvB,yEAAyE;;IAEzE,6CAA6C;;IAE7C,iEAAiE;;IAEjE,qCAAqC;;IAErC,2EAA2E;;CAE5E,CAAC;AAyDF;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAyB3D;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAQpD;AAsBD,MAAM,WAAW,gBAAgB;IAC/B,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;IACd,iFAAiF;IACjF,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,CAAC,CAAC,CAgC3F"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slice a string up to `end` UTF-16 code units without splitting a surrogate
|
|
3
|
+
* pair. If `end` would land immediately after a lone high surrogate
|
|
4
|
+
* (U+D800..U+DBFF), the slice backs off by one code unit so the pair is
|
|
5
|
+
* dropped as a whole.
|
|
6
|
+
*
|
|
7
|
+
* Lone UTF-16 surrogates are rejected by strict JSON parsers (e.g. Anthropic's
|
|
8
|
+
* with `no low surrogate in string`), so any truncation of observer-facing
|
|
9
|
+
* text that could cut an emoji/astral codepoint in half must go through this
|
|
10
|
+
* helper.
|
|
11
|
+
*/
|
|
12
|
+
export declare function safeSlice(str: string, end: number): string;
|
|
13
|
+
//# sourceMappingURL=string-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-utils.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/string-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAM1D"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { MastraDBMessage } from '@mastra/core/agent';
|
|
2
|
+
import type { Mastra } from '@mastra/core/mastra';
|
|
3
|
+
import type { ObservabilityContext } from '@mastra/core/observability';
|
|
4
|
+
import type { RequestContext } from '@mastra/core/request-context';
|
|
5
|
+
import type { Memory } from '../../index.js';
|
|
6
|
+
import type { ExtractionFailure } from './extracted-values.js';
|
|
7
|
+
import type { Extractor } from './extractor.js';
|
|
8
|
+
import type { ModelByInputTokens } from './model-by-input-tokens.js';
|
|
9
|
+
import type { ObservationalMemoryModel } from './types.js';
|
|
10
|
+
/** A concrete model config — token-based model routing is not supported for one-shot summarization. */
|
|
11
|
+
export type SummarizeModel = Exclude<ObservationalMemoryModel, ModelByInputTokens>;
|
|
12
|
+
/** Defaults for how `Memory.summarizeThread()` loads a thread's messages from storage. */
|
|
13
|
+
export declare const SUMMARIZE_THREAD_DEFAULTS: {
|
|
14
|
+
/** Stop loading older messages once the collected messages exceed this estimated token count. */
|
|
15
|
+
readonly maxInputTokens: 1000000;
|
|
16
|
+
/** Number of messages fetched per storage page while paginating backwards from the newest message. */
|
|
17
|
+
readonly pageSize: 100;
|
|
18
|
+
};
|
|
19
|
+
export interface SummarizeConversationOptions {
|
|
20
|
+
/** Model that runs the summarization (e.g. a router string like `'openai/gpt-4.1-mini'`). */
|
|
21
|
+
model: SummarizeModel;
|
|
22
|
+
/** The conversation to summarize. */
|
|
23
|
+
messages: MastraDBMessage[];
|
|
24
|
+
/** Extra guidance appended to the summarizer's system prompt (e.g. what to focus on, audience). */
|
|
25
|
+
instructions?: string;
|
|
26
|
+
/** Extractors to run over the conversation. Structured (with a schema) or inline. `onExtracted` hooks fire. */
|
|
27
|
+
extract?: Extractor<any>[];
|
|
28
|
+
/** Thread the conversation belongs to. Defaults to the first `threadId` found on `messages`. Passed to extractor contexts. */
|
|
29
|
+
threadId?: string;
|
|
30
|
+
/** Resource (user) the conversation belongs to. Defaults to the first `resourceId` found on `messages`. Passed to extractor contexts. */
|
|
31
|
+
resourceId?: string;
|
|
32
|
+
requestContext?: RequestContext;
|
|
33
|
+
observabilityContext?: ObservabilityContext;
|
|
34
|
+
abortSignal?: AbortSignal;
|
|
35
|
+
/** Memory instance forwarded to extractor contexts (set automatically by `Memory.summarizeThread()`). */
|
|
36
|
+
memory?: Memory;
|
|
37
|
+
/** Mastra instance for custom gateway model resolution (set automatically by `Memory.summarizeThread()`). */
|
|
38
|
+
mastra?: Mastra;
|
|
39
|
+
}
|
|
40
|
+
export interface SummarizeConversationResult {
|
|
41
|
+
/** The distilled observations produced from the conversation (dense bullet form). */
|
|
42
|
+
summary: string;
|
|
43
|
+
/** Values produced by `extract` extractors, keyed by extractor slug (after `onExtracted` hooks ran). */
|
|
44
|
+
extracted: Record<string, unknown>;
|
|
45
|
+
/** Extractors that failed to produce a valid value, with the reason. */
|
|
46
|
+
extractionFailures?: ExtractionFailure[];
|
|
47
|
+
usage?: {
|
|
48
|
+
inputTokens?: number;
|
|
49
|
+
outputTokens?: number;
|
|
50
|
+
totalTokens?: number;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Summarize a conversation in one shot, without Observational Memory attached to an agent.
|
|
55
|
+
*
|
|
56
|
+
* Reuses Observational Memory's Observer plumbing — the same distillation prompt, output
|
|
57
|
+
* parsing, retry handling, and extractor pipeline — as a standalone call over the messages
|
|
58
|
+
* you pass in. Nothing is read from or written to storage: the summary and extracted values
|
|
59
|
+
* are returned to you (and to each extractor's `onExtracted` hook), so you decide where they
|
|
60
|
+
* go.
|
|
61
|
+
*
|
|
62
|
+
* Use this when a session ends and you want a summary or structured extraction of the whole
|
|
63
|
+
* conversation — for example a voice call at hang-up. If Observational Memory is configured
|
|
64
|
+
* on a `Memory` instance and you want to summarize one of its threads, use
|
|
65
|
+
* `memory.summarizeThread()` instead, which loads the messages for you.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { summarizeConversation, Extractor } from '@mastra/memory';
|
|
70
|
+
* import { z } from 'zod';
|
|
71
|
+
*
|
|
72
|
+
* const result = await summarizeConversation({
|
|
73
|
+
* model: 'openai/gpt-4.1-mini',
|
|
74
|
+
* messages,
|
|
75
|
+
* instructions: 'Summarize this voicemail call for the business owner.',
|
|
76
|
+
* extract: [
|
|
77
|
+
* new Extractor({
|
|
78
|
+
* name: 'call-summary',
|
|
79
|
+
* instructions: 'Return a concise summary of the call.',
|
|
80
|
+
* schema: z.object({
|
|
81
|
+
* summary: z.string(),
|
|
82
|
+
* sentiment: z.enum(['positive', 'neutral', 'negative']),
|
|
83
|
+
* }),
|
|
84
|
+
* metadataKeyPath: false,
|
|
85
|
+
* }),
|
|
86
|
+
* ],
|
|
87
|
+
* });
|
|
88
|
+
* result.extracted['call-summary']; // { summary, sentiment }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare function summarizeConversation(opts: SummarizeConversationOptions): Promise<SummarizeConversationResult>;
|
|
92
|
+
//# sourceMappingURL=summarize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summarize.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/summarize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,M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,CAAC;CACjB;AAED,MAAM,WAAW,2BAA2B;IAC1C,qFAAqF;IACrF,OAAO,EAAE,MAAM,CAAC;IAChB,wGAAwG;IACxG,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,wEAAwE;IACxE,kBAAkB,CAAC,EAAE,iBAAiB,EAAE,CAAC;IACzC,KAAK,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,4BAA4B,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAyDpH"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ProcessInputStepArgs } from '@mastra/core/processors';
|
|
2
|
+
export declare const TEMPORAL_GAP_REMINDER_TYPE = "temporal-gap";
|
|
3
|
+
export declare function insertTemporalGapMarkers({ messageList, sendSignal, }: Pick<ProcessInputStepArgs, 'messageList' | 'sendSignal'>): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=temporal-markers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporal-markers.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/temporal-markers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAKpE,eAAO,MAAM,0BAA0B,iBAAiB,CAAC;AA6DzD,wBAAsB,wBAAwB,CAAC,EAC7C,WAAW,EACX,UAAU,GACX,EAAE,IAAI,CAAC,oBAAoB,EAAE,aAAa,GAAG,YAAY,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAoD1E"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AgentMemoryOption } from '@mastra/core/agent';
|
|
2
|
+
import type { MastraMemory } from '@mastra/core/memory';
|
|
3
|
+
export interface TemporaryOmMemoryContext {
|
|
4
|
+
memory: MastraMemory;
|
|
5
|
+
options: AgentMemoryOption;
|
|
6
|
+
}
|
|
7
|
+
export declare function createTemporaryOmMemoryContext(prefix: string): TemporaryOmMemoryContext;
|
|
8
|
+
//# sourceMappingURL=temporary-memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporary-memory.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/temporary-memory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAIxD,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,iBAAiB,CAAC;CAC5B;AAED,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,MAAM,GAAG,wBAAwB,CAmBvF"}
|
|
@@ -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"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { MastraDBMessage } from '@mastra/core/agent';
|
|
2
|
+
export type TokenCounterModelContext = {
|
|
3
|
+
provider?: string;
|
|
4
|
+
modelId?: string;
|
|
5
|
+
};
|
|
6
|
+
type TokenCounterOptions = {
|
|
7
|
+
model?: string | TokenCounterModelContext;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Token counting utility using tokenx for rough local estimation and
|
|
11
|
+
* provider-aware heuristics for image parts so multimodal prompts are not
|
|
12
|
+
* undercounted as generic JSON blobs.
|
|
13
|
+
*/
|
|
14
|
+
export declare class TokenCounter {
|
|
15
|
+
private readonly cacheSource;
|
|
16
|
+
private readonly defaultModelContext?;
|
|
17
|
+
private readonly modelContextStorage;
|
|
18
|
+
private readonly inFlightAttachmentCounts;
|
|
19
|
+
private static readonly TOKENS_PER_MESSAGE;
|
|
20
|
+
private static readonly TOKENS_PER_CONVERSATION;
|
|
21
|
+
constructor(options?: TokenCounterOptions);
|
|
22
|
+
runWithModelContext<T>(model: string | TokenCounterModelContext | undefined, fn: () => T): T;
|
|
23
|
+
private getModelContext;
|
|
24
|
+
/**
|
|
25
|
+
* Count tokens in a plain string
|
|
26
|
+
*/
|
|
27
|
+
countString(text: string): number;
|
|
28
|
+
private readOrPersistPartEstimate;
|
|
29
|
+
private readOrPersistFixedPartEstimate;
|
|
30
|
+
private readOrPersistMessageEstimate;
|
|
31
|
+
private resolveToolResultForTokenCounting;
|
|
32
|
+
private countMultimodalToolResultContent;
|
|
33
|
+
private estimateImageAssetTokens;
|
|
34
|
+
private estimateImageTokens;
|
|
35
|
+
private estimateImageLikeFileTokens;
|
|
36
|
+
private countAttachmentPartSync;
|
|
37
|
+
private buildRemoteAttachmentCachePayload;
|
|
38
|
+
private fetchProviderAttachmentTokenEstimate;
|
|
39
|
+
private countAttachmentPartAsync;
|
|
40
|
+
private countNonAttachmentPart;
|
|
41
|
+
/**
|
|
42
|
+
* Count tokens in a single message
|
|
43
|
+
*/
|
|
44
|
+
countMessage(message: MastraDBMessage): number;
|
|
45
|
+
countMessageAsync(message: MastraDBMessage): Promise<number>;
|
|
46
|
+
/**
|
|
47
|
+
* Count tokens in an array of messages
|
|
48
|
+
*/
|
|
49
|
+
countMessages(messages: MastraDBMessage[]): number;
|
|
50
|
+
countMessagesAsync(messages: MastraDBMessage[]): Promise<number>;
|
|
51
|
+
/**
|
|
52
|
+
* Count tokens in observations string
|
|
53
|
+
*/
|
|
54
|
+
countObservations(observations: string): number;
|
|
55
|
+
}
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=token-counter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-counter.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/token-counter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAa1D,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,KAAK,CAAC,EAAE,MAAM,GAAG,wBAAwB,CAAC;CAC3C,CAAC;AAsqCF;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAA2B;IAChE,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAiE;IACrG,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAkD;IAI3F,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAO;IAEjD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,uBAAuB,CAAM;gBAEzC,OAAO,CAAC,EAAE,mBAAmB;IAKzC,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAI5F,OAAO,CAAC,eAAe;IAIvB;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAKjC,OAAO,CAAC,yBAAyB;IAkBjC,OAAO,CAAC,8BAA8B;IAiBtC,OAAO,CAAC,4BAA4B;IAkBpC,OAAO,CAAC,iCAAiC;IAOzC,OAAO,CAAC,gCAAgC;IAkIxC,OAAO,CAAC,wBAAwB;IAsEhC,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,2BAA2B;IAInC,OAAO,CAAC,uBAAuB;IAkC/B,OAAO,CAAC,iCAAiC;YAiC3B,oCAAoC;YAyBpC,wBAAwB;IAyFtC,OAAO,CAAC,sBAAsB;IAsG9B;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM;IAiCxC,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;IAiClE;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,MAAM;IAU5C,kBAAkB,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAOtE;;OAEG;IACH,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;CAGhD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const DEFAULT_OBSERVER_TOOL_RESULT_MAX_TOKENS = 10000;
|
|
2
|
+
export declare function resolveToolResultValue(part: {
|
|
3
|
+
providerMetadata?: Record<string, any>;
|
|
4
|
+
} | undefined, invocationResult: unknown): {
|
|
5
|
+
value: unknown;
|
|
6
|
+
usingStoredModelOutput: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function truncateStringByTokens(text: string, maxTokens: number): string;
|
|
9
|
+
export declare function formatToolResultForObserver(value: unknown, options?: {
|
|
10
|
+
maxTokens?: number;
|
|
11
|
+
}): string;
|
|
12
|
+
//# sourceMappingURL=tool-result-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-result-helpers.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/tool-result-helpers.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,uCAAuC,QAAS,CAAC;AAwD9D,wBAAgB,sBAAsB,CACpC,IAAI,EAAE;IAAE,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAAE,GAAG,SAAS,EAC5D,gBAAgB,EAAE,OAAO,GACxB;IACD,KAAK,EAAE,OAAO,CAAC;IACf,sBAAsB,EAAE,OAAO,CAAC;CACjC,CAaA;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAiC9E;AAED,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE;IACR,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GACA,MAAM,CAIR"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ObservabilityContext } from '@mastra/core/observability';
|
|
2
|
+
import type { RequestContext } from '@mastra/core/request-context';
|
|
3
|
+
import type { ModelByInputTokens } from './model-by-input-tokens.js';
|
|
4
|
+
import type { ResolvedObservationConfig, ResolvedReflectionConfig } from './types.js';
|
|
5
|
+
type OmTracingModel = Exclude<ResolvedObservationConfig['model'] | ResolvedReflectionConfig['model'], ModelByInputTokens>;
|
|
6
|
+
type OmTracingPhase = 'observer' | 'observer-multi-thread' | 'reflector';
|
|
7
|
+
export declare function withOmTracingSpan<T>({ phase, model, inputTokens, requestContext, observabilityContext, metadata, callback, }: {
|
|
8
|
+
phase: OmTracingPhase;
|
|
9
|
+
model: OmTracingModel;
|
|
10
|
+
inputTokens: number;
|
|
11
|
+
requestContext?: RequestContext;
|
|
12
|
+
observabilityContext?: ObservabilityContext;
|
|
13
|
+
metadata?: Record<string, unknown>;
|
|
14
|
+
callback: (observabilityContext: ObservabilityContext) => Promise<T>;
|
|
15
|
+
}): Promise<T>;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=tracing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/tracing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAEvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAEnF,KAAK,cAAc,GAAG,OAAO,CAC3B,yBAAyB,CAAC,OAAO,CAAC,GAAG,wBAAwB,CAAC,OAAO,CAAC,EACtE,kBAAkB,CACnB,CAAC;AAEF,KAAK,cAAc,GAAG,UAAU,GAAG,uBAAuB,GAAG,WAAW,CAAC;AAuBzE,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,EACzC,KAAK,EACL,KAAK,EACL,WAAW,EACX,cAAc,EACd,oBAAoB,EACpB,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,cAAc,CAAC;IACtB,KAAK,EAAE,cAAc,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,QAAQ,EAAE,CAAC,oBAAoB,EAAE,oBAAoB,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;CACtE,GAAG,OAAO,CAAC,CAAC,CAAC,CAuBb"}
|