@mastra/server 1.18.0 → 1.19.0-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 +23 -0
- package/dist/{chunk-R45HPGYC.js → chunk-3VRBDPB6.js} +131 -16
- package/dist/chunk-3VRBDPB6.js.map +1 -0
- package/dist/{chunk-YUTITKH2.js → chunk-5CDCKTHB.js} +65 -40
- package/dist/chunk-5CDCKTHB.js.map +1 -0
- package/dist/{chunk-HUAXEKGI.cjs → chunk-DAEHQAZC.cjs} +65 -40
- package/dist/chunk-DAEHQAZC.cjs.map +1 -0
- package/dist/{chunk-6XE2BQLU.cjs → chunk-KWEYG4OZ.cjs} +144 -29
- package/dist/chunk-KWEYG4OZ.cjs.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-server-custom-adapters.md +3 -1
- package/dist/{observational-memory-SN7GKMHZ-IWVBFBS6.js → observational-memory-B25SASRW-L4GYD2ZN.js} +3 -3
- package/dist/{observational-memory-SN7GKMHZ-IWVBFBS6.js.map → observational-memory-B25SASRW-L4GYD2ZN.js.map} +1 -1
- package/dist/{observational-memory-SN7GKMHZ-WOK4TGDH.cjs → observational-memory-B25SASRW-T76NSRNU.cjs} +26 -26
- package/dist/{observational-memory-SN7GKMHZ-WOK4TGDH.cjs.map → observational-memory-B25SASRW-T76NSRNU.cjs.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 +24 -16
- package/dist/server/server-adapter/index.cjs.map +1 -1
- package/dist/server/server-adapter/index.js +10 -2
- package/dist/server/server-adapter/index.js.map +1 -1
- package/dist/server/server-adapter/routes/observability.d.ts +881 -119
- package/dist/server/server-adapter/routes/observability.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/chunk-6XE2BQLU.cjs.map +0 -1
- package/dist/chunk-HUAXEKGI.cjs.map +0 -1
- package/dist/chunk-R45HPGYC.js.map +0 -1
- package/dist/chunk-YUTITKH2.js.map +0 -1
|
@@ -1732,10 +1732,10 @@ function stripReflectionGroupMetadata(body) {
|
|
|
1732
1732
|
function generateAnchorId() {
|
|
1733
1733
|
return crypto$1.randomBytes(8).toString("hex");
|
|
1734
1734
|
}
|
|
1735
|
-
function wrapInObservationGroup(observations, range, id = generateAnchorId(),
|
|
1735
|
+
function wrapInObservationGroup(observations, range, id = generateAnchorId(), _sourceGroupIds, kind) {
|
|
1736
1736
|
const content = observations.trim();
|
|
1737
|
-
const
|
|
1738
|
-
return `<observation-group id="${id}" range="${range}"${
|
|
1737
|
+
const kindAttr = kind ? ` kind="${kind}"` : "";
|
|
1738
|
+
return `<observation-group id="${id}" range="${range}"${kindAttr}>
|
|
1739
1739
|
${content}
|
|
1740
1740
|
</observation-group>`;
|
|
1741
1741
|
}
|
|
@@ -1755,8 +1755,8 @@ function parseObservationGroups(observations) {
|
|
|
1755
1755
|
groups.push({
|
|
1756
1756
|
id,
|
|
1757
1757
|
range,
|
|
1758
|
-
|
|
1759
|
-
|
|
1758
|
+
kind: attributes.kind,
|
|
1759
|
+
content: match[2].trim()
|
|
1760
1760
|
});
|
|
1761
1761
|
}
|
|
1762
1762
|
return groups;
|
|
@@ -1767,12 +1767,22 @@ function stripObservationGroups(observations) {
|
|
|
1767
1767
|
}
|
|
1768
1768
|
return observations.replace(OBSERVATION_GROUP_PATTERN, (_match, _attributes, content) => content.trim()).replace(/\n{3,}/g, "\n\n").trim();
|
|
1769
1769
|
}
|
|
1770
|
+
function getRangeSegments(range) {
|
|
1771
|
+
return range.split(",").map((segment) => segment.trim()).filter(Boolean);
|
|
1772
|
+
}
|
|
1770
1773
|
function combineObservationGroupRanges(groups) {
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1774
|
+
const segments = groups.flatMap((group) => getRangeSegments(group.range));
|
|
1775
|
+
if (segments.length === 0) {
|
|
1776
|
+
return "";
|
|
1777
|
+
}
|
|
1778
|
+
const firstSegment = segments[0];
|
|
1779
|
+
const lastSegment = segments[segments.length - 1];
|
|
1780
|
+
const firstStart = firstSegment?.split(":")[0]?.trim();
|
|
1781
|
+
const lastEnd = lastSegment?.split(":").at(-1)?.trim();
|
|
1782
|
+
if (firstStart && lastEnd) {
|
|
1783
|
+
return `${firstStart}:${lastEnd}`;
|
|
1784
|
+
}
|
|
1785
|
+
return Array.from(new Set(segments)).join(",");
|
|
1776
1786
|
}
|
|
1777
1787
|
function renderObservationGroupsForReflection(observations) {
|
|
1778
1788
|
const groups = parseObservationGroups(observations);
|
|
@@ -1809,15 +1819,12 @@ function deriveObservationGroupProvenance(content, groups) {
|
|
|
1809
1819
|
});
|
|
1810
1820
|
const fallbackGroup = groups[Math.min(index, groups.length - 1)];
|
|
1811
1821
|
const resolvedGroups = matchingGroups.length > 0 ? matchingGroups : fallbackGroup ? [fallbackGroup] : [];
|
|
1812
|
-
const sourceGroupIds = Array.from(
|
|
1813
|
-
new Set(resolvedGroups.flatMap((group) => [group.id, ...group.sourceGroupIds ?? []]))
|
|
1814
|
-
);
|
|
1815
1822
|
const canonicalGroupId = getCanonicalGroupId(section.heading, index);
|
|
1816
1823
|
return {
|
|
1817
1824
|
id: canonicalGroupId,
|
|
1818
1825
|
range: combineObservationGroupRanges(resolvedGroups),
|
|
1819
|
-
|
|
1820
|
-
|
|
1826
|
+
kind: "reflection",
|
|
1827
|
+
content: section.body
|
|
1821
1828
|
};
|
|
1822
1829
|
});
|
|
1823
1830
|
}
|
|
@@ -1832,13 +1839,14 @@ function reconcileObservationGroupsFromReflection(content, sourceObservations) {
|
|
|
1832
1839
|
}
|
|
1833
1840
|
const derivedGroups = deriveObservationGroupProvenance(normalizedContent, sourceGroups);
|
|
1834
1841
|
if (derivedGroups.length > 0) {
|
|
1835
|
-
return derivedGroups.map((group) => wrapInObservationGroup(group.content, group.range, group.id, group.
|
|
1842
|
+
return derivedGroups.map((group) => wrapInObservationGroup(group.content, group.range, group.id, void 0, group.kind)).join("\n\n");
|
|
1836
1843
|
}
|
|
1837
1844
|
return wrapInObservationGroup(
|
|
1838
1845
|
normalizedContent,
|
|
1839
1846
|
combineObservationGroupRanges(sourceGroups),
|
|
1840
1847
|
generateAnchorId(),
|
|
1841
|
-
|
|
1848
|
+
void 0,
|
|
1849
|
+
"reflection"
|
|
1842
1850
|
);
|
|
1843
1851
|
}
|
|
1844
1852
|
function getMaxThreshold(threshold) {
|
|
@@ -1946,7 +1954,11 @@ var ObservationStrategy = class _ObservationStrategy {
|
|
|
1946
1954
|
retrieval;
|
|
1947
1955
|
/** Select the right strategy based on scope and mode. Wired up by index.ts. */
|
|
1948
1956
|
static create;
|
|
1949
|
-
/**
|
|
1957
|
+
/**
|
|
1958
|
+
* Run the full observation lifecycle.
|
|
1959
|
+
* @returns `true` if a full observation cycle completed; `false` if skipped (stale lock) or async-buffer failure was swallowed.
|
|
1960
|
+
* @throws On sync/resource-scoped observer failure after failed markers (same as pre–Option-A contract).
|
|
1961
|
+
*/
|
|
1950
1962
|
async run() {
|
|
1951
1963
|
const { record, threadId, abortSignal, writer, reflectionHooks, requestContext } = this.opts;
|
|
1952
1964
|
const cycleId = this.generateCycleId();
|
|
@@ -1954,7 +1966,7 @@ var ObservationStrategy = class _ObservationStrategy {
|
|
|
1954
1966
|
if (this.needsLock) {
|
|
1955
1967
|
const fresh = await this.storage.getObservationalMemory(record.threadId, record.resourceId);
|
|
1956
1968
|
if (fresh?.lastObservedAt && record.lastObservedAt && fresh.lastObservedAt > record.lastObservedAt) {
|
|
1957
|
-
return;
|
|
1969
|
+
return false;
|
|
1958
1970
|
}
|
|
1959
1971
|
}
|
|
1960
1972
|
const { messages, existingObservations } = await this.prepare();
|
|
@@ -1975,23 +1987,29 @@ var ObservationStrategy = class _ObservationStrategy {
|
|
|
1975
1987
|
observabilityContext: this.opts.observabilityContext
|
|
1976
1988
|
});
|
|
1977
1989
|
}
|
|
1990
|
+
return true;
|
|
1978
1991
|
} catch (error) {
|
|
1979
1992
|
await this.emitFailedMarkers(cycleId, error);
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1993
|
+
if (!this.rethrowOnFailure) {
|
|
1994
|
+
const failedMarkerForStorage = {
|
|
1995
|
+
type: "data-om-observation-failed",
|
|
1996
|
+
data: {
|
|
1997
|
+
cycleId,
|
|
1998
|
+
operationType: "observation",
|
|
1999
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2000
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2001
|
+
recordId: record.id,
|
|
2002
|
+
threadId
|
|
2003
|
+
}
|
|
2004
|
+
};
|
|
2005
|
+
await this.persistMarkerToStorage(failedMarkerForStorage, threadId, this.opts.resourceId).catch(() => {
|
|
2006
|
+
});
|
|
2007
|
+
if (abortSignal?.aborted) throw error;
|
|
2008
|
+
omError("[OM] Observation failed", error);
|
|
2009
|
+
return false;
|
|
2010
|
+
}
|
|
1994
2011
|
omError("[OM] Observation failed", error);
|
|
2012
|
+
throw error;
|
|
1995
2013
|
}
|
|
1996
2014
|
}
|
|
1997
2015
|
// ── Shared helpers ──────────────────────────────────────────
|
|
@@ -2212,6 +2230,9 @@ var SyncObservationStrategy = class extends ObservationStrategy {
|
|
|
2212
2230
|
get needsReflection() {
|
|
2213
2231
|
return true;
|
|
2214
2232
|
}
|
|
2233
|
+
get rethrowOnFailure() {
|
|
2234
|
+
return true;
|
|
2235
|
+
}
|
|
2215
2236
|
async prepare() {
|
|
2216
2237
|
const { record, threadId, messages } = this.opts;
|
|
2217
2238
|
this.deps.emitDebugEvent({
|
|
@@ -2403,6 +2424,9 @@ var AsyncBufferObservationStrategy = class extends ObservationStrategy {
|
|
|
2403
2424
|
get needsReflection() {
|
|
2404
2425
|
return false;
|
|
2405
2426
|
}
|
|
2427
|
+
get rethrowOnFailure() {
|
|
2428
|
+
return false;
|
|
2429
|
+
}
|
|
2406
2430
|
generateCycleId() {
|
|
2407
2431
|
return this.cycleId;
|
|
2408
2432
|
}
|
|
@@ -2539,6 +2563,9 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
|
|
|
2539
2563
|
get needsReflection() {
|
|
2540
2564
|
return true;
|
|
2541
2565
|
}
|
|
2566
|
+
get rethrowOnFailure() {
|
|
2567
|
+
return true;
|
|
2568
|
+
}
|
|
2542
2569
|
async prepare() {
|
|
2543
2570
|
const { record, threadId: currentThreadId, messages: currentThreadMessages } = this.opts;
|
|
2544
2571
|
const { threads: allThreads } = await this.storage.listThreads({ filter: { resourceId: this.resourceId } });
|
|
@@ -4818,11 +4845,10 @@ Aim for a 2/10 detail level. Fewer, more generic observations are better than ma
|
|
|
4818
4845
|
};
|
|
4819
4846
|
function buildReflectorPrompt(observations, manualPrompt, compressionLevel, skipContinuationHints) {
|
|
4820
4847
|
const level = typeof compressionLevel === "number" ? compressionLevel : compressionLevel ? 1 : 0;
|
|
4821
|
-
const reflectionView =
|
|
4822
|
-
const anchoredObservations = injectAnchorIds(reflectionView);
|
|
4848
|
+
const reflectionView = stripObservationGroups(observations);
|
|
4823
4849
|
let prompt = `## OBSERVATIONS TO REFLECT ON
|
|
4824
4850
|
|
|
4825
|
-
${
|
|
4851
|
+
${reflectionView}
|
|
4826
4852
|
|
|
4827
4853
|
---
|
|
4828
4854
|
|
|
@@ -8792,7 +8818,7 @@ ${grouped}` : grouped;
|
|
|
8792
8818
|
}
|
|
8793
8819
|
hooks?.onObservationStart?.();
|
|
8794
8820
|
try {
|
|
8795
|
-
await ObservationStrategy.create(this, {
|
|
8821
|
+
observed = await ObservationStrategy.create(this, {
|
|
8796
8822
|
record: freshRecord,
|
|
8797
8823
|
threadId,
|
|
8798
8824
|
resourceId,
|
|
@@ -8802,7 +8828,6 @@ ${grouped}` : grouped;
|
|
|
8802
8828
|
writer: opts.writer,
|
|
8803
8829
|
observabilityContext: opts.observabilityContext
|
|
8804
8830
|
}).run();
|
|
8805
|
-
observed = true;
|
|
8806
8831
|
} finally {
|
|
8807
8832
|
hooks?.onObservationEnd?.();
|
|
8808
8833
|
}
|
|
@@ -9434,5 +9459,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
|
|
|
9434
9459
|
exports.stripObservationGroups = stripObservationGroups;
|
|
9435
9460
|
exports.truncateStringByTokens = truncateStringByTokens;
|
|
9436
9461
|
exports.wrapInObservationGroup = wrapInObservationGroup;
|
|
9437
|
-
//# sourceMappingURL=chunk-
|
|
9438
|
-
//# sourceMappingURL=chunk-
|
|
9462
|
+
//# sourceMappingURL=chunk-DAEHQAZC.cjs.map
|
|
9463
|
+
//# sourceMappingURL=chunk-DAEHQAZC.cjs.map
|