@mastra/memory 1.21.3-alpha.0 → 1.21.3-alpha.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 +25 -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 +13 -13
- package/dist/index.js +4 -4
- 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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 1.21.3-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Expose `providerMetadata` on Observational Memory `ObserveHooks` results ([#18563](https://github.com/mastra-ai/mastra/pull/18563))
|
|
8
|
+
|
|
9
|
+
`onObservationEnd` and `onReflectionEnd` now receive the OM model call's `providerMetadata` alongside `usage`, so you can read per-call provider details — for example the AI Gateway's cost and generation id — straight from the hook instead of wrapping the observer/reflector models in a model-stream middleware:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const hooks: ObserveHooks = {
|
|
13
|
+
onObservationEnd: ({ usage, providerMetadata }) => {
|
|
14
|
+
const gateway = providerMetadata?.gateway;
|
|
15
|
+
recordCost({ tokens: usage?.totalTokens, cost: gateway?.cost, generationId: gateway?.generationId });
|
|
16
|
+
},
|
|
17
|
+
onReflectionEnd: ({ usage, providerMetadata }) => {
|
|
18
|
+
recordCost({ tokens: usage?.totalTokens, cost: providerMetadata?.gateway?.cost });
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The field is additive and optional, and is omitted entirely when the provider emits no metadata, so existing hook consumers are unaffected. For batched observations and multi-attempt reflections it reflects the last batch/attempt that emitted provider metadata.
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`1917c53`](https://github.com/mastra-ai/mastra/commit/1917c53b19dac43926f29c496893b0686462dca4), [`58e287b`](https://github.com/mastra-ai/mastra/commit/58e287b1edaf978b13745a1795989cad3826e82b)]:
|
|
26
|
+
- @mastra/core@1.48.0-alpha.5
|
|
27
|
+
|
|
3
28
|
## 1.21.3-alpha.0
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
|
@@ -1114,7 +1114,7 @@ var ObservationStrategy = class _ObservationStrategy {
|
|
|
1114
1114
|
observabilityContext: this.opts.observabilityContext
|
|
1115
1115
|
});
|
|
1116
1116
|
}
|
|
1117
|
-
return { observed: true, usage: output.usage };
|
|
1117
|
+
return { observed: true, usage: output.usage, providerMetadata: output.providerMetadata };
|
|
1118
1118
|
} catch (error) {
|
|
1119
1119
|
await this.emitFailedMarkers(cycleId, error);
|
|
1120
1120
|
if (!this.rethrowOnFailure) {
|
|
@@ -1707,6 +1707,7 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
|
|
|
1707
1707
|
messagesByThread = /* @__PURE__ */ new Map();
|
|
1708
1708
|
multiThreadResults = /* @__PURE__ */ new Map();
|
|
1709
1709
|
totalBatchUsage = { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
|
|
1710
|
+
lastBatchProviderMetadata;
|
|
1710
1711
|
observationResults = [];
|
|
1711
1712
|
priorMetadataByThread = /* @__PURE__ */ new Map();
|
|
1712
1713
|
constructor(deps, opts) {
|
|
@@ -1888,10 +1889,14 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
|
|
|
1888
1889
|
this.totalBatchUsage.outputTokens += batchResult.usage.outputTokens ?? 0;
|
|
1889
1890
|
this.totalBatchUsage.totalTokens += batchResult.usage.totalTokens ?? 0;
|
|
1890
1891
|
}
|
|
1892
|
+
if (batchResult.providerMetadata) {
|
|
1893
|
+
this.lastBatchProviderMetadata = batchResult.providerMetadata;
|
|
1894
|
+
}
|
|
1891
1895
|
}
|
|
1892
1896
|
return {
|
|
1893
1897
|
observations: "",
|
|
1894
|
-
usage: this.totalBatchUsage.totalTokens > 0 ? this.totalBatchUsage : void 0
|
|
1898
|
+
usage: this.totalBatchUsage.totalTokens > 0 ? this.totalBatchUsage : void 0,
|
|
1899
|
+
providerMetadata: this.lastBatchProviderMetadata
|
|
1895
1900
|
};
|
|
1896
1901
|
}
|
|
1897
1902
|
async process(_output, existingObservations) {
|
|
@@ -4275,7 +4280,8 @@ var ObserverRunner = class {
|
|
|
4275
4280
|
currentTask: parsed.currentTask,
|
|
4276
4281
|
suggestedContinuation: parsed.suggestedContinuation,
|
|
4277
4282
|
threadTitle: parsed.threadTitle,
|
|
4278
|
-
usage: usage ? { inputTokens: usage.inputTokens, outputTokens: usage.outputTokens, totalTokens: usage.totalTokens } : void 0
|
|
4283
|
+
usage: usage ? { inputTokens: usage.inputTokens, outputTokens: usage.outputTokens, totalTokens: usage.totalTokens } : void 0,
|
|
4284
|
+
providerMetadata: result.providerMetadata
|
|
4279
4285
|
};
|
|
4280
4286
|
}
|
|
4281
4287
|
/**
|
|
@@ -4389,7 +4395,8 @@ var ObserverRunner = class {
|
|
|
4389
4395
|
const usage = result.totalUsage ?? result.usage;
|
|
4390
4396
|
return {
|
|
4391
4397
|
results,
|
|
4392
|
-
usage: usage ? { inputTokens: usage.inputTokens, outputTokens: usage.outputTokens, totalTokens: usage.totalTokens } : void 0
|
|
4398
|
+
usage: usage ? { inputTokens: usage.inputTokens, outputTokens: usage.outputTokens, totalTokens: usage.totalTokens } : void 0,
|
|
4399
|
+
providerMetadata: result.providerMetadata
|
|
4393
4400
|
};
|
|
4394
4401
|
}
|
|
4395
4402
|
};
|
|
@@ -4769,6 +4776,7 @@ var ReflectorRunner = class {
|
|
|
4769
4776
|
const internalRequestContext = withOmInternalThreadId(requestContext, agent.id);
|
|
4770
4777
|
const targetThreshold = observationTokensThreshold ?? getMaxThreshold(this.reflectionConfig.observationTokens);
|
|
4771
4778
|
let totalUsage = { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
|
|
4779
|
+
let finalProviderMetadata;
|
|
4772
4780
|
const startLevel = compressionStartLevel ?? 0;
|
|
4773
4781
|
let currentLevel = startLevel;
|
|
4774
4782
|
const maxLevel = Math.min(MAX_COMPRESSION_LEVEL, startLevel + 3);
|
|
@@ -4846,6 +4854,7 @@ var ReflectorRunner = class {
|
|
|
4846
4854
|
totalUsage.outputTokens += usage.outputTokens ?? 0;
|
|
4847
4855
|
totalUsage.totalTokens += usage.totalTokens ?? 0;
|
|
4848
4856
|
}
|
|
4857
|
+
finalProviderMetadata = result.providerMetadata ?? finalProviderMetadata;
|
|
4849
4858
|
parsed = parseReflectorOutput(result.text, observations);
|
|
4850
4859
|
if (parsed.degenerate) {
|
|
4851
4860
|
omDebug(
|
|
@@ -4899,7 +4908,8 @@ var ReflectorRunner = class {
|
|
|
4899
4908
|
return {
|
|
4900
4909
|
observations: parsed.observations,
|
|
4901
4910
|
suggestedContinuation: parsed.suggestedContinuation,
|
|
4902
|
-
usage: totalUsage.totalTokens > 0 ? totalUsage : void 0
|
|
4911
|
+
usage: totalUsage.totalTokens > 0 ? totalUsage : void 0,
|
|
4912
|
+
providerMetadata: finalProviderMetadata
|
|
4903
4913
|
};
|
|
4904
4914
|
}
|
|
4905
4915
|
/**
|
|
@@ -4916,8 +4926,11 @@ var ReflectorRunner = class {
|
|
|
4916
4926
|
omError("[OM] Failed to set buffering reflection flag", err);
|
|
4917
4927
|
});
|
|
4918
4928
|
reflectionHooks?.onReflectionStart?.();
|
|
4919
|
-
const asyncOp = this.doAsyncBufferedReflection(record, bufferKey, writer, requestContext, observabilityContext).then((
|
|
4920
|
-
reflectionHooks?.onReflectionEnd?.({
|
|
4929
|
+
const asyncOp = this.doAsyncBufferedReflection(record, bufferKey, writer, requestContext, observabilityContext).then((outcome) => {
|
|
4930
|
+
reflectionHooks?.onReflectionEnd?.({
|
|
4931
|
+
usage: outcome?.usage,
|
|
4932
|
+
...outcome?.providerMetadata ? { providerMetadata: outcome.providerMetadata } : {}
|
|
4933
|
+
});
|
|
4921
4934
|
}).catch(async (error) => {
|
|
4922
4935
|
if (writer) {
|
|
4923
4936
|
const failedMarker = createBufferingFailedMarker({
|
|
@@ -5036,7 +5049,7 @@ var ReflectorRunner = class {
|
|
|
5036
5049
|
});
|
|
5037
5050
|
await this.persistMarkerToStorage(endMarker, currentRecord.threadId ?? "", currentRecord.resourceId ?? void 0);
|
|
5038
5051
|
}
|
|
5039
|
-
return reflectResult.usage;
|
|
5052
|
+
return { usage: reflectResult.usage, providerMetadata: reflectResult.providerMetadata };
|
|
5040
5053
|
}
|
|
5041
5054
|
/**
|
|
5042
5055
|
* Try to activate buffered reflection when threshold is reached.
|
|
@@ -5308,6 +5321,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5308
5321
|
resourceId: record.resourceId ?? void 0
|
|
5309
5322
|
} : void 0;
|
|
5310
5323
|
let reflectionUsage;
|
|
5324
|
+
let reflectionProviderMetadata;
|
|
5311
5325
|
let reflectionError;
|
|
5312
5326
|
try {
|
|
5313
5327
|
const compressionStartLevel = await this.getCompressionStartLevel(requestContext);
|
|
@@ -5323,6 +5337,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5323
5337
|
observabilityContext
|
|
5324
5338
|
);
|
|
5325
5339
|
reflectionUsage = reflectResult.usage;
|
|
5340
|
+
reflectionProviderMetadata = reflectResult.providerMetadata;
|
|
5326
5341
|
const reflectionTokenCount = this.tokenCounter.countObservations(reflectResult.observations);
|
|
5327
5342
|
await this.storage.createReflectionGeneration({
|
|
5328
5343
|
currentRecord: record,
|
|
@@ -5376,7 +5391,11 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5376
5391
|
omError("[OM] Reflection failed", error);
|
|
5377
5392
|
} finally {
|
|
5378
5393
|
await this.storage.setReflectingFlag(record.id, false);
|
|
5379
|
-
reflectionHooks?.onReflectionEnd?.({
|
|
5394
|
+
reflectionHooks?.onReflectionEnd?.({
|
|
5395
|
+
usage: reflectionUsage,
|
|
5396
|
+
error: reflectionError,
|
|
5397
|
+
...reflectionProviderMetadata ? { providerMetadata: reflectionProviderMetadata } : {}
|
|
5398
|
+
});
|
|
5380
5399
|
unregisterOp(record.id, "reflecting");
|
|
5381
5400
|
}
|
|
5382
5401
|
}
|
|
@@ -9431,6 +9450,7 @@ ${grouped}` : grouped;
|
|
|
9431
9450
|
const reflectionHooks = hooks ? { onReflectionStart: hooks.onReflectionStart, onReflectionEnd: hooks.onReflectionEnd } : void 0;
|
|
9432
9451
|
let observed = false;
|
|
9433
9452
|
let observationUsage;
|
|
9453
|
+
let observationProviderMetadata;
|
|
9434
9454
|
let generationBefore = -1;
|
|
9435
9455
|
await this.withLock(lockKey, async () => {
|
|
9436
9456
|
const freshRecord = await this.getOrCreateRecord(threadId, resourceId);
|
|
@@ -9461,11 +9481,16 @@ ${grouped}` : grouped;
|
|
|
9461
9481
|
}).run();
|
|
9462
9482
|
observed = result.observed;
|
|
9463
9483
|
observationUsage = result.usage;
|
|
9484
|
+
observationProviderMetadata = result.providerMetadata;
|
|
9464
9485
|
} catch (error) {
|
|
9465
9486
|
observationError = error instanceof Error ? error : new Error(String(error));
|
|
9466
9487
|
throw error;
|
|
9467
9488
|
} finally {
|
|
9468
|
-
hooks?.onObservationEnd?.({
|
|
9489
|
+
hooks?.onObservationEnd?.({
|
|
9490
|
+
usage: observationUsage,
|
|
9491
|
+
error: observationError,
|
|
9492
|
+
...observationProviderMetadata ? { providerMetadata: observationProviderMetadata } : {}
|
|
9493
|
+
});
|
|
9469
9494
|
}
|
|
9470
9495
|
});
|
|
9471
9496
|
const record = await this.getOrCreateRecord(threadId, resourceId);
|
|
@@ -10045,5 +10070,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
|
|
|
10045
10070
|
exports.stripObservationGroups = stripObservationGroups;
|
|
10046
10071
|
exports.truncateStringByTokens = truncateStringByTokens;
|
|
10047
10072
|
exports.wrapInObservationGroup = wrapInObservationGroup;
|
|
10048
|
-
//# sourceMappingURL=chunk-
|
|
10049
|
-
//# sourceMappingURL=chunk-
|
|
10073
|
+
//# sourceMappingURL=chunk-FQLQMPJY.cjs.map
|
|
10074
|
+
//# sourceMappingURL=chunk-FQLQMPJY.cjs.map
|