@mastra/server 1.23.0-alpha.3 → 1.23.0-alpha.4
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 +7 -0
- package/dist/{chunk-U6BPUJR3.js → chunk-FLGIOJA5.js} +37 -16
- package/dist/chunk-FLGIOJA5.js.map +1 -0
- package/dist/{chunk-QV52EUDJ.cjs → chunk-PNCR2M6Y.cjs} +37 -16
- package/dist/chunk-PNCR2M6Y.cjs.map +1 -0
- package/dist/{chunk-LO4K2KYO.js → chunk-SZ2FSVP5.js} +5 -5
- package/dist/{chunk-LO4K2KYO.js.map → chunk-SZ2FSVP5.js.map} +1 -1
- package/dist/{chunk-ZBA5KHIF.cjs → chunk-VMA5TY4H.cjs} +19 -19
- package/dist/{chunk-ZBA5KHIF.cjs.map → chunk-VMA5TY4H.cjs.map} +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/{observational-memory-6UPEPMC3-K4VHMYEI.cjs → observational-memory-JQ34KLFS-CNLSTXO3.cjs} +26 -26
- package/dist/{observational-memory-6UPEPMC3-K4VHMYEI.cjs.map → observational-memory-JQ34KLFS-CNLSTXO3.cjs.map} +1 -1
- package/dist/{observational-memory-6UPEPMC3-CQN5KXDK.js → observational-memory-JQ34KLFS-KLWGOGP4.js} +3 -3
- package/dist/{observational-memory-6UPEPMC3-CQN5KXDK.js.map → observational-memory-JQ34KLFS-KLWGOGP4.js.map} +1 -1
- package/dist/server/handlers/agent-builder.cjs +16 -16
- package/dist/server/handlers/agent-builder.js +1 -1
- package/dist/server/handlers.cjs +2 -2
- package/dist/server/handlers.js +1 -1
- package/dist/server/server-adapter/index.cjs +16 -16
- package/dist/server/server-adapter/index.js +1 -1
- package/package.json +4 -4
- package/dist/chunk-QV52EUDJ.cjs.map +0 -1
- package/dist/chunk-U6BPUJR3.js.map +0 -1
|
@@ -1956,7 +1956,7 @@ var ObservationStrategy = class _ObservationStrategy {
|
|
|
1956
1956
|
static create;
|
|
1957
1957
|
/**
|
|
1958
1958
|
* Run the full observation lifecycle.
|
|
1959
|
-
* @returns `
|
|
1959
|
+
* @returns Result with `observed` flag and optional `usage` from the observer LLM call.
|
|
1960
1960
|
* @throws On sync/resource-scoped observer failure after failed markers (same as pre–Option-A contract).
|
|
1961
1961
|
*/
|
|
1962
1962
|
async run() {
|
|
@@ -1966,7 +1966,7 @@ var ObservationStrategy = class _ObservationStrategy {
|
|
|
1966
1966
|
if (this.needsLock) {
|
|
1967
1967
|
const fresh = await this.storage.getObservationalMemory(record.threadId, record.resourceId);
|
|
1968
1968
|
if (fresh?.lastObservedAt && record.lastObservedAt && fresh.lastObservedAt > record.lastObservedAt) {
|
|
1969
|
-
return false;
|
|
1969
|
+
return { observed: false };
|
|
1970
1970
|
}
|
|
1971
1971
|
}
|
|
1972
1972
|
const { messages, existingObservations } = await this.prepare();
|
|
@@ -1987,7 +1987,7 @@ var ObservationStrategy = class _ObservationStrategy {
|
|
|
1987
1987
|
observabilityContext: this.opts.observabilityContext
|
|
1988
1988
|
});
|
|
1989
1989
|
}
|
|
1990
|
-
return true;
|
|
1990
|
+
return { observed: true, usage: output.usage };
|
|
1991
1991
|
} catch (error) {
|
|
1992
1992
|
await this.emitFailedMarkers(cycleId, error);
|
|
1993
1993
|
if (!this.rethrowOnFailure) {
|
|
@@ -2006,7 +2006,7 @@ var ObservationStrategy = class _ObservationStrategy {
|
|
|
2006
2006
|
});
|
|
2007
2007
|
if (abortSignal?.aborted) throw error;
|
|
2008
2008
|
omError("[OM] Observation failed", error);
|
|
2009
|
-
return false;
|
|
2009
|
+
return { observed: false };
|
|
2010
2010
|
}
|
|
2011
2011
|
omError("[OM] Observation failed", error);
|
|
2012
2012
|
throw error;
|
|
@@ -5190,7 +5190,7 @@ var ReflectorRunner = class {
|
|
|
5190
5190
|
/**
|
|
5191
5191
|
* Start an async buffered reflection in the background.
|
|
5192
5192
|
*/
|
|
5193
|
-
startAsyncBufferedReflection(record, observationTokens, lockKey, writer, requestContext, observabilityContext) {
|
|
5193
|
+
startAsyncBufferedReflection(record, observationTokens, lockKey, writer, requestContext, observabilityContext, reflectionHooks) {
|
|
5194
5194
|
const bufferKey = this.buffering.getReflectionBufferKey(lockKey);
|
|
5195
5195
|
if (this.buffering.isAsyncBufferingInProgress(bufferKey)) {
|
|
5196
5196
|
return;
|
|
@@ -5200,7 +5200,10 @@ var ReflectorRunner = class {
|
|
|
5200
5200
|
this.storage.setBufferingReflectionFlag(record.id, true).catch((err) => {
|
|
5201
5201
|
omError("[OM] Failed to set buffering reflection flag", err);
|
|
5202
5202
|
});
|
|
5203
|
-
|
|
5203
|
+
reflectionHooks?.onReflectionStart?.();
|
|
5204
|
+
const asyncOp = this.doAsyncBufferedReflection(record, bufferKey, writer, requestContext, observabilityContext).then((usage) => {
|
|
5205
|
+
reflectionHooks?.onReflectionEnd?.({ usage });
|
|
5206
|
+
}).catch(async (error) => {
|
|
5204
5207
|
if (writer) {
|
|
5205
5208
|
const failedMarker = createBufferingFailedMarker({
|
|
5206
5209
|
cycleId: `reflect-buf-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`,
|
|
@@ -5216,6 +5219,10 @@ var ReflectorRunner = class {
|
|
|
5216
5219
|
await this.persistMarkerToStorage(failedMarker, record.threadId ?? "", record.resourceId ?? void 0);
|
|
5217
5220
|
}
|
|
5218
5221
|
omError("[OM] Async buffered reflection failed", error);
|
|
5222
|
+
reflectionHooks?.onReflectionEnd?.({
|
|
5223
|
+
usage: void 0,
|
|
5224
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
5225
|
+
});
|
|
5219
5226
|
BufferingCoordinator.lastBufferedBoundary.delete(bufferKey);
|
|
5220
5227
|
}).finally(() => {
|
|
5221
5228
|
BufferingCoordinator.asyncBufferingOps.delete(bufferKey);
|
|
@@ -5309,6 +5316,7 @@ var ReflectorRunner = class {
|
|
|
5309
5316
|
});
|
|
5310
5317
|
await this.persistMarkerToStorage(endMarker, currentRecord.threadId ?? "", currentRecord.resourceId ?? void 0);
|
|
5311
5318
|
}
|
|
5319
|
+
return reflectResult.usage;
|
|
5312
5320
|
}
|
|
5313
5321
|
/**
|
|
5314
5322
|
* Try to activate buffered reflection when threshold is reached.
|
|
@@ -5429,7 +5437,8 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5429
5437
|
lockKey,
|
|
5430
5438
|
writer,
|
|
5431
5439
|
requestContext,
|
|
5432
|
-
observabilityContext
|
|
5440
|
+
observabilityContext,
|
|
5441
|
+
reflectionHooks
|
|
5433
5442
|
);
|
|
5434
5443
|
}
|
|
5435
5444
|
}
|
|
@@ -5463,7 +5472,8 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5463
5472
|
lockKey,
|
|
5464
5473
|
writer,
|
|
5465
5474
|
requestContext,
|
|
5466
|
-
observabilityContext
|
|
5475
|
+
observabilityContext,
|
|
5476
|
+
reflectionHooks
|
|
5467
5477
|
);
|
|
5468
5478
|
return;
|
|
5469
5479
|
}
|
|
@@ -5502,6 +5512,8 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5502
5512
|
recordId: record.id,
|
|
5503
5513
|
threadId
|
|
5504
5514
|
} : void 0;
|
|
5515
|
+
let reflectionUsage;
|
|
5516
|
+
let reflectionError;
|
|
5505
5517
|
try {
|
|
5506
5518
|
const compressionStartLevel = await this.getCompressionStartLevel(requestContext);
|
|
5507
5519
|
const reflectResult = await this.call(
|
|
@@ -5515,6 +5527,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5515
5527
|
requestContext,
|
|
5516
5528
|
observabilityContext
|
|
5517
5529
|
);
|
|
5530
|
+
reflectionUsage = reflectResult.usage;
|
|
5518
5531
|
const reflectionTokenCount = this.tokenCounter.countObservations(reflectResult.observations);
|
|
5519
5532
|
await this.storage.createReflectionGeneration({
|
|
5520
5533
|
currentRecord: record,
|
|
@@ -5559,13 +5572,14 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5559
5572
|
await writer.custom(failedMarker).catch(() => {
|
|
5560
5573
|
});
|
|
5561
5574
|
}
|
|
5575
|
+
reflectionError = error instanceof Error ? error : new Error(String(error));
|
|
5562
5576
|
if (abortSignal?.aborted) {
|
|
5563
5577
|
throw error;
|
|
5564
5578
|
}
|
|
5565
5579
|
omError("[OM] Reflection failed", error);
|
|
5566
5580
|
} finally {
|
|
5567
5581
|
await this.storage.setReflectingFlag(record.id, false);
|
|
5568
|
-
reflectionHooks?.onReflectionEnd?.();
|
|
5582
|
+
reflectionHooks?.onReflectionEnd?.({ usage: reflectionUsage, error: reflectionError });
|
|
5569
5583
|
unregisterOp(record.id, "reflecting");
|
|
5570
5584
|
}
|
|
5571
5585
|
}
|
|
@@ -8908,6 +8922,7 @@ ${grouped}` : grouped;
|
|
|
8908
8922
|
const lockKey = this.buffering.getLockKey(threadId, resourceId);
|
|
8909
8923
|
const reflectionHooks = hooks ? { onReflectionStart: hooks.onReflectionStart, onReflectionEnd: hooks.onReflectionEnd } : void 0;
|
|
8910
8924
|
let observed = false;
|
|
8925
|
+
let observationUsage;
|
|
8911
8926
|
let generationBefore = -1;
|
|
8912
8927
|
await this.withLock(lockKey, async () => {
|
|
8913
8928
|
const freshRecord = await this.getOrCreateRecord(threadId, resourceId);
|
|
@@ -8924,8 +8939,9 @@ ${grouped}` : grouped;
|
|
|
8924
8939
|
return;
|
|
8925
8940
|
}
|
|
8926
8941
|
hooks?.onObservationStart?.();
|
|
8942
|
+
let observationError;
|
|
8927
8943
|
try {
|
|
8928
|
-
|
|
8944
|
+
const result = await ObservationStrategy.create(this, {
|
|
8929
8945
|
record: freshRecord,
|
|
8930
8946
|
threadId,
|
|
8931
8947
|
resourceId,
|
|
@@ -8935,8 +8951,13 @@ ${grouped}` : grouped;
|
|
|
8935
8951
|
writer: opts.writer,
|
|
8936
8952
|
observabilityContext: opts.observabilityContext
|
|
8937
8953
|
}).run();
|
|
8954
|
+
observed = result.observed;
|
|
8955
|
+
observationUsage = result.usage;
|
|
8956
|
+
} catch (error) {
|
|
8957
|
+
observationError = error instanceof Error ? error : new Error(String(error));
|
|
8958
|
+
throw error;
|
|
8938
8959
|
} finally {
|
|
8939
|
-
hooks?.onObservationEnd?.();
|
|
8960
|
+
hooks?.onObservationEnd?.({ usage: observationUsage, error: observationError });
|
|
8940
8961
|
}
|
|
8941
8962
|
});
|
|
8942
8963
|
const record = await this.getOrCreateRecord(threadId, resourceId);
|
|
@@ -8957,7 +8978,7 @@ ${grouped}` : grouped;
|
|
|
8957
8978
|
async reflect(threadId, resourceId, prompt, requestContext, observabilityContext) {
|
|
8958
8979
|
const record = await this.getOrCreateRecord(threadId, resourceId);
|
|
8959
8980
|
if (!record.activeObservations) {
|
|
8960
|
-
return { reflected: false, record };
|
|
8981
|
+
return { reflected: false, record, usage: void 0 };
|
|
8961
8982
|
}
|
|
8962
8983
|
await this.storage.setReflectingFlag(record.id, true);
|
|
8963
8984
|
registerOp(record.id, "reflecting");
|
|
@@ -8982,11 +9003,11 @@ ${grouped}` : grouped;
|
|
|
8982
9003
|
tokenCount: reflectionTokenCount
|
|
8983
9004
|
});
|
|
8984
9005
|
const updatedRecord = await this.getOrCreateRecord(threadId, resourceId);
|
|
8985
|
-
return { reflected: true, record: updatedRecord };
|
|
9006
|
+
return { reflected: true, record: updatedRecord, usage: reflectResult.usage };
|
|
8986
9007
|
} catch (error) {
|
|
8987
9008
|
omError("[OM] reflect() failed", error);
|
|
8988
9009
|
const latestRecord = await this.getOrCreateRecord(threadId, resourceId);
|
|
8989
|
-
return { reflected: false, record: latestRecord };
|
|
9010
|
+
return { reflected: false, record: latestRecord, usage: void 0 };
|
|
8990
9011
|
} finally {
|
|
8991
9012
|
await this.storage.setReflectingFlag(record.id, false);
|
|
8992
9013
|
unregisterOp(record.id, "reflecting");
|
|
@@ -9581,5 +9602,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
|
|
|
9581
9602
|
exports.stripObservationGroups = stripObservationGroups;
|
|
9582
9603
|
exports.truncateStringByTokens = truncateStringByTokens;
|
|
9583
9604
|
exports.wrapInObservationGroup = wrapInObservationGroup;
|
|
9584
|
-
//# sourceMappingURL=chunk-
|
|
9585
|
-
//# sourceMappingURL=chunk-
|
|
9605
|
+
//# sourceMappingURL=chunk-PNCR2M6Y.cjs.map
|
|
9606
|
+
//# sourceMappingURL=chunk-PNCR2M6Y.cjs.map
|