@mastra/memory 1.21.3-alpha.0 → 1.21.3-alpha.2
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 +33 -0
- package/dist/{chunk-LEAP5DKB.cjs → chunk-FQLQMPJY.cjs} +37 -12
- package/dist/chunk-FQLQMPJY.cjs.map +1 -0
- package/dist/{chunk-UHQBCO7I.js → chunk-X7DOZRJK.js} +37 -12
- package/dist/chunk-X7DOZRJK.js.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +39 -39
- package/dist/docs/references/docs-agents-agent-approval.md +38 -0
- package/dist/index.cjs +14 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-WZ6JQ4JY.cjs → observational-memory-2KSGEMXM.cjs} +26 -26
- package/dist/{observational-memory-WZ6JQ4JY.cjs.map → observational-memory-2KSGEMXM.cjs.map} +1 -1
- package/dist/{observational-memory-NC6DQQWD.js → observational-memory-VZDCB747.js} +3 -3
- package/dist/{observational-memory-NC6DQQWD.js.map → observational-memory-VZDCB747.js.map} +1 -1
- package/dist/processors/index.cjs +24 -24
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts +1 -0
- package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts +3 -0
- package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/sync.d.ts +1 -0
- package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/types.d.ts +3 -0
- package/dist/processors/observational-memory/observation-strategies/types.d.ts.map +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/observer-runner.d.ts +3 -0
- package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -1
- package/dist/processors/observational-memory/processor.d.ts.map +1 -1
- package/dist/processors/observational-memory/reflector-runner.d.ts +2 -0
- package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
- package/dist/processors/observational-memory/types.d.ts +18 -0
- package/dist/processors/observational-memory/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/chunk-LEAP5DKB.cjs.map +0 -1
- package/dist/chunk-UHQBCO7I.js.map +0 -1
|
@@ -1107,7 +1107,7 @@ var ObservationStrategy = class _ObservationStrategy {
|
|
|
1107
1107
|
observabilityContext: this.opts.observabilityContext
|
|
1108
1108
|
});
|
|
1109
1109
|
}
|
|
1110
|
-
return { observed: true, usage: output.usage };
|
|
1110
|
+
return { observed: true, usage: output.usage, providerMetadata: output.providerMetadata };
|
|
1111
1111
|
} catch (error) {
|
|
1112
1112
|
await this.emitFailedMarkers(cycleId, error);
|
|
1113
1113
|
if (!this.rethrowOnFailure) {
|
|
@@ -1700,6 +1700,7 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
|
|
|
1700
1700
|
messagesByThread = /* @__PURE__ */ new Map();
|
|
1701
1701
|
multiThreadResults = /* @__PURE__ */ new Map();
|
|
1702
1702
|
totalBatchUsage = { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
|
|
1703
|
+
lastBatchProviderMetadata;
|
|
1703
1704
|
observationResults = [];
|
|
1704
1705
|
priorMetadataByThread = /* @__PURE__ */ new Map();
|
|
1705
1706
|
constructor(deps, opts) {
|
|
@@ -1881,10 +1882,14 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
|
|
|
1881
1882
|
this.totalBatchUsage.outputTokens += batchResult.usage.outputTokens ?? 0;
|
|
1882
1883
|
this.totalBatchUsage.totalTokens += batchResult.usage.totalTokens ?? 0;
|
|
1883
1884
|
}
|
|
1885
|
+
if (batchResult.providerMetadata) {
|
|
1886
|
+
this.lastBatchProviderMetadata = batchResult.providerMetadata;
|
|
1887
|
+
}
|
|
1884
1888
|
}
|
|
1885
1889
|
return {
|
|
1886
1890
|
observations: "",
|
|
1887
|
-
usage: this.totalBatchUsage.totalTokens > 0 ? this.totalBatchUsage : void 0
|
|
1891
|
+
usage: this.totalBatchUsage.totalTokens > 0 ? this.totalBatchUsage : void 0,
|
|
1892
|
+
providerMetadata: this.lastBatchProviderMetadata
|
|
1888
1893
|
};
|
|
1889
1894
|
}
|
|
1890
1895
|
async process(_output, existingObservations) {
|
|
@@ -4268,7 +4273,8 @@ var ObserverRunner = class {
|
|
|
4268
4273
|
currentTask: parsed.currentTask,
|
|
4269
4274
|
suggestedContinuation: parsed.suggestedContinuation,
|
|
4270
4275
|
threadTitle: parsed.threadTitle,
|
|
4271
|
-
usage: usage ? { inputTokens: usage.inputTokens, outputTokens: usage.outputTokens, totalTokens: usage.totalTokens } : void 0
|
|
4276
|
+
usage: usage ? { inputTokens: usage.inputTokens, outputTokens: usage.outputTokens, totalTokens: usage.totalTokens } : void 0,
|
|
4277
|
+
providerMetadata: result.providerMetadata
|
|
4272
4278
|
};
|
|
4273
4279
|
}
|
|
4274
4280
|
/**
|
|
@@ -4382,7 +4388,8 @@ var ObserverRunner = class {
|
|
|
4382
4388
|
const usage = result.totalUsage ?? result.usage;
|
|
4383
4389
|
return {
|
|
4384
4390
|
results,
|
|
4385
|
-
usage: usage ? { inputTokens: usage.inputTokens, outputTokens: usage.outputTokens, totalTokens: usage.totalTokens } : void 0
|
|
4391
|
+
usage: usage ? { inputTokens: usage.inputTokens, outputTokens: usage.outputTokens, totalTokens: usage.totalTokens } : void 0,
|
|
4392
|
+
providerMetadata: result.providerMetadata
|
|
4386
4393
|
};
|
|
4387
4394
|
}
|
|
4388
4395
|
};
|
|
@@ -4762,6 +4769,7 @@ var ReflectorRunner = class {
|
|
|
4762
4769
|
const internalRequestContext = withOmInternalThreadId(requestContext, agent.id);
|
|
4763
4770
|
const targetThreshold = observationTokensThreshold ?? getMaxThreshold(this.reflectionConfig.observationTokens);
|
|
4764
4771
|
let totalUsage = { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
|
|
4772
|
+
let finalProviderMetadata;
|
|
4765
4773
|
const startLevel = compressionStartLevel ?? 0;
|
|
4766
4774
|
let currentLevel = startLevel;
|
|
4767
4775
|
const maxLevel = Math.min(MAX_COMPRESSION_LEVEL, startLevel + 3);
|
|
@@ -4839,6 +4847,7 @@ var ReflectorRunner = class {
|
|
|
4839
4847
|
totalUsage.outputTokens += usage.outputTokens ?? 0;
|
|
4840
4848
|
totalUsage.totalTokens += usage.totalTokens ?? 0;
|
|
4841
4849
|
}
|
|
4850
|
+
finalProviderMetadata = result.providerMetadata ?? finalProviderMetadata;
|
|
4842
4851
|
parsed = parseReflectorOutput(result.text, observations);
|
|
4843
4852
|
if (parsed.degenerate) {
|
|
4844
4853
|
omDebug(
|
|
@@ -4892,7 +4901,8 @@ var ReflectorRunner = class {
|
|
|
4892
4901
|
return {
|
|
4893
4902
|
observations: parsed.observations,
|
|
4894
4903
|
suggestedContinuation: parsed.suggestedContinuation,
|
|
4895
|
-
usage: totalUsage.totalTokens > 0 ? totalUsage : void 0
|
|
4904
|
+
usage: totalUsage.totalTokens > 0 ? totalUsage : void 0,
|
|
4905
|
+
providerMetadata: finalProviderMetadata
|
|
4896
4906
|
};
|
|
4897
4907
|
}
|
|
4898
4908
|
/**
|
|
@@ -4909,8 +4919,11 @@ var ReflectorRunner = class {
|
|
|
4909
4919
|
omError("[OM] Failed to set buffering reflection flag", err);
|
|
4910
4920
|
});
|
|
4911
4921
|
reflectionHooks?.onReflectionStart?.();
|
|
4912
|
-
const asyncOp = this.doAsyncBufferedReflection(record, bufferKey, writer, requestContext, observabilityContext).then((
|
|
4913
|
-
reflectionHooks?.onReflectionEnd?.({
|
|
4922
|
+
const asyncOp = this.doAsyncBufferedReflection(record, bufferKey, writer, requestContext, observabilityContext).then((outcome) => {
|
|
4923
|
+
reflectionHooks?.onReflectionEnd?.({
|
|
4924
|
+
usage: outcome?.usage,
|
|
4925
|
+
...outcome?.providerMetadata ? { providerMetadata: outcome.providerMetadata } : {}
|
|
4926
|
+
});
|
|
4914
4927
|
}).catch(async (error) => {
|
|
4915
4928
|
if (writer) {
|
|
4916
4929
|
const failedMarker = createBufferingFailedMarker({
|
|
@@ -5029,7 +5042,7 @@ var ReflectorRunner = class {
|
|
|
5029
5042
|
});
|
|
5030
5043
|
await this.persistMarkerToStorage(endMarker, currentRecord.threadId ?? "", currentRecord.resourceId ?? void 0);
|
|
5031
5044
|
}
|
|
5032
|
-
return reflectResult.usage;
|
|
5045
|
+
return { usage: reflectResult.usage, providerMetadata: reflectResult.providerMetadata };
|
|
5033
5046
|
}
|
|
5034
5047
|
/**
|
|
5035
5048
|
* Try to activate buffered reflection when threshold is reached.
|
|
@@ -5301,6 +5314,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5301
5314
|
resourceId: record.resourceId ?? void 0
|
|
5302
5315
|
} : void 0;
|
|
5303
5316
|
let reflectionUsage;
|
|
5317
|
+
let reflectionProviderMetadata;
|
|
5304
5318
|
let reflectionError;
|
|
5305
5319
|
try {
|
|
5306
5320
|
const compressionStartLevel = await this.getCompressionStartLevel(requestContext);
|
|
@@ -5316,6 +5330,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5316
5330
|
observabilityContext
|
|
5317
5331
|
);
|
|
5318
5332
|
reflectionUsage = reflectResult.usage;
|
|
5333
|
+
reflectionProviderMetadata = reflectResult.providerMetadata;
|
|
5319
5334
|
const reflectionTokenCount = this.tokenCounter.countObservations(reflectResult.observations);
|
|
5320
5335
|
await this.storage.createReflectionGeneration({
|
|
5321
5336
|
currentRecord: record,
|
|
@@ -5369,7 +5384,11 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5369
5384
|
omError("[OM] Reflection failed", error);
|
|
5370
5385
|
} finally {
|
|
5371
5386
|
await this.storage.setReflectingFlag(record.id, false);
|
|
5372
|
-
reflectionHooks?.onReflectionEnd?.({
|
|
5387
|
+
reflectionHooks?.onReflectionEnd?.({
|
|
5388
|
+
usage: reflectionUsage,
|
|
5389
|
+
error: reflectionError,
|
|
5390
|
+
...reflectionProviderMetadata ? { providerMetadata: reflectionProviderMetadata } : {}
|
|
5391
|
+
});
|
|
5373
5392
|
unregisterOp(record.id, "reflecting");
|
|
5374
5393
|
}
|
|
5375
5394
|
}
|
|
@@ -9424,6 +9443,7 @@ ${grouped}` : grouped;
|
|
|
9424
9443
|
const reflectionHooks = hooks ? { onReflectionStart: hooks.onReflectionStart, onReflectionEnd: hooks.onReflectionEnd } : void 0;
|
|
9425
9444
|
let observed = false;
|
|
9426
9445
|
let observationUsage;
|
|
9446
|
+
let observationProviderMetadata;
|
|
9427
9447
|
let generationBefore = -1;
|
|
9428
9448
|
await this.withLock(lockKey, async () => {
|
|
9429
9449
|
const freshRecord = await this.getOrCreateRecord(threadId, resourceId);
|
|
@@ -9454,11 +9474,16 @@ ${grouped}` : grouped;
|
|
|
9454
9474
|
}).run();
|
|
9455
9475
|
observed = result.observed;
|
|
9456
9476
|
observationUsage = result.usage;
|
|
9477
|
+
observationProviderMetadata = result.providerMetadata;
|
|
9457
9478
|
} catch (error) {
|
|
9458
9479
|
observationError = error instanceof Error ? error : new Error(String(error));
|
|
9459
9480
|
throw error;
|
|
9460
9481
|
} finally {
|
|
9461
|
-
hooks?.onObservationEnd?.({
|
|
9482
|
+
hooks?.onObservationEnd?.({
|
|
9483
|
+
usage: observationUsage,
|
|
9484
|
+
error: observationError,
|
|
9485
|
+
...observationProviderMetadata ? { providerMetadata: observationProviderMetadata } : {}
|
|
9486
|
+
});
|
|
9462
9487
|
}
|
|
9463
9488
|
});
|
|
9464
9489
|
const record = await this.getOrCreateRecord(threadId, resourceId);
|
|
@@ -10013,5 +10038,5 @@ function getObservationsAsOf(activeObservations, asOf) {
|
|
|
10013
10038
|
}
|
|
10014
10039
|
|
|
10015
10040
|
export { ModelByInputTokens, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, combineObservationGroupRanges, deriveObservationGroupProvenance, extractCurrentTask, formatMessagesForObserver, formatToolResultForObserver, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, reconcileObservationGroupsFromReflection, renderObservationGroupsForReflection, resolveToolResultValue, stripEphemeralAnchorIds, stripObservationGroups, truncateStringByTokens, wrapInObservationGroup };
|
|
10016
|
-
//# sourceMappingURL=chunk-
|
|
10017
|
-
//# sourceMappingURL=chunk-
|
|
10041
|
+
//# sourceMappingURL=chunk-X7DOZRJK.js.map
|
|
10042
|
+
//# sourceMappingURL=chunk-X7DOZRJK.js.map
|