@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
|
@@ -1730,10 +1730,10 @@ function stripReflectionGroupMetadata(body) {
|
|
|
1730
1730
|
function generateAnchorId() {
|
|
1731
1731
|
return randomBytes(8).toString("hex");
|
|
1732
1732
|
}
|
|
1733
|
-
function wrapInObservationGroup(observations, range, id = generateAnchorId(),
|
|
1733
|
+
function wrapInObservationGroup(observations, range, id = generateAnchorId(), _sourceGroupIds, kind) {
|
|
1734
1734
|
const content = observations.trim();
|
|
1735
|
-
const
|
|
1736
|
-
return `<observation-group id="${id}" range="${range}"${
|
|
1735
|
+
const kindAttr = kind ? ` kind="${kind}"` : "";
|
|
1736
|
+
return `<observation-group id="${id}" range="${range}"${kindAttr}>
|
|
1737
1737
|
${content}
|
|
1738
1738
|
</observation-group>`;
|
|
1739
1739
|
}
|
|
@@ -1753,8 +1753,8 @@ function parseObservationGroups(observations) {
|
|
|
1753
1753
|
groups.push({
|
|
1754
1754
|
id,
|
|
1755
1755
|
range,
|
|
1756
|
-
|
|
1757
|
-
|
|
1756
|
+
kind: attributes.kind,
|
|
1757
|
+
content: match[2].trim()
|
|
1758
1758
|
});
|
|
1759
1759
|
}
|
|
1760
1760
|
return groups;
|
|
@@ -1765,12 +1765,22 @@ function stripObservationGroups(observations) {
|
|
|
1765
1765
|
}
|
|
1766
1766
|
return observations.replace(OBSERVATION_GROUP_PATTERN, (_match, _attributes, content) => content.trim()).replace(/\n{3,}/g, "\n\n").trim();
|
|
1767
1767
|
}
|
|
1768
|
+
function getRangeSegments(range) {
|
|
1769
|
+
return range.split(",").map((segment) => segment.trim()).filter(Boolean);
|
|
1770
|
+
}
|
|
1768
1771
|
function combineObservationGroupRanges(groups) {
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1772
|
+
const segments = groups.flatMap((group) => getRangeSegments(group.range));
|
|
1773
|
+
if (segments.length === 0) {
|
|
1774
|
+
return "";
|
|
1775
|
+
}
|
|
1776
|
+
const firstSegment = segments[0];
|
|
1777
|
+
const lastSegment = segments[segments.length - 1];
|
|
1778
|
+
const firstStart = firstSegment?.split(":")[0]?.trim();
|
|
1779
|
+
const lastEnd = lastSegment?.split(":").at(-1)?.trim();
|
|
1780
|
+
if (firstStart && lastEnd) {
|
|
1781
|
+
return `${firstStart}:${lastEnd}`;
|
|
1782
|
+
}
|
|
1783
|
+
return Array.from(new Set(segments)).join(",");
|
|
1774
1784
|
}
|
|
1775
1785
|
function renderObservationGroupsForReflection(observations) {
|
|
1776
1786
|
const groups = parseObservationGroups(observations);
|
|
@@ -1807,15 +1817,12 @@ function deriveObservationGroupProvenance(content, groups) {
|
|
|
1807
1817
|
});
|
|
1808
1818
|
const fallbackGroup = groups[Math.min(index, groups.length - 1)];
|
|
1809
1819
|
const resolvedGroups = matchingGroups.length > 0 ? matchingGroups : fallbackGroup ? [fallbackGroup] : [];
|
|
1810
|
-
const sourceGroupIds = Array.from(
|
|
1811
|
-
new Set(resolvedGroups.flatMap((group) => [group.id, ...group.sourceGroupIds ?? []]))
|
|
1812
|
-
);
|
|
1813
1820
|
const canonicalGroupId = getCanonicalGroupId(section.heading, index);
|
|
1814
1821
|
return {
|
|
1815
1822
|
id: canonicalGroupId,
|
|
1816
1823
|
range: combineObservationGroupRanges(resolvedGroups),
|
|
1817
|
-
|
|
1818
|
-
|
|
1824
|
+
kind: "reflection",
|
|
1825
|
+
content: section.body
|
|
1819
1826
|
};
|
|
1820
1827
|
});
|
|
1821
1828
|
}
|
|
@@ -1830,13 +1837,14 @@ function reconcileObservationGroupsFromReflection(content, sourceObservations) {
|
|
|
1830
1837
|
}
|
|
1831
1838
|
const derivedGroups = deriveObservationGroupProvenance(normalizedContent, sourceGroups);
|
|
1832
1839
|
if (derivedGroups.length > 0) {
|
|
1833
|
-
return derivedGroups.map((group) => wrapInObservationGroup(group.content, group.range, group.id, group.
|
|
1840
|
+
return derivedGroups.map((group) => wrapInObservationGroup(group.content, group.range, group.id, void 0, group.kind)).join("\n\n");
|
|
1834
1841
|
}
|
|
1835
1842
|
return wrapInObservationGroup(
|
|
1836
1843
|
normalizedContent,
|
|
1837
1844
|
combineObservationGroupRanges(sourceGroups),
|
|
1838
1845
|
generateAnchorId(),
|
|
1839
|
-
|
|
1846
|
+
void 0,
|
|
1847
|
+
"reflection"
|
|
1840
1848
|
);
|
|
1841
1849
|
}
|
|
1842
1850
|
function getMaxThreshold(threshold) {
|
|
@@ -1944,7 +1952,11 @@ var ObservationStrategy = class _ObservationStrategy {
|
|
|
1944
1952
|
retrieval;
|
|
1945
1953
|
/** Select the right strategy based on scope and mode. Wired up by index.ts. */
|
|
1946
1954
|
static create;
|
|
1947
|
-
/**
|
|
1955
|
+
/**
|
|
1956
|
+
* Run the full observation lifecycle.
|
|
1957
|
+
* @returns `true` if a full observation cycle completed; `false` if skipped (stale lock) or async-buffer failure was swallowed.
|
|
1958
|
+
* @throws On sync/resource-scoped observer failure after failed markers (same as pre–Option-A contract).
|
|
1959
|
+
*/
|
|
1948
1960
|
async run() {
|
|
1949
1961
|
const { record, threadId, abortSignal, writer, reflectionHooks, requestContext } = this.opts;
|
|
1950
1962
|
const cycleId = this.generateCycleId();
|
|
@@ -1952,7 +1964,7 @@ var ObservationStrategy = class _ObservationStrategy {
|
|
|
1952
1964
|
if (this.needsLock) {
|
|
1953
1965
|
const fresh = await this.storage.getObservationalMemory(record.threadId, record.resourceId);
|
|
1954
1966
|
if (fresh?.lastObservedAt && record.lastObservedAt && fresh.lastObservedAt > record.lastObservedAt) {
|
|
1955
|
-
return;
|
|
1967
|
+
return false;
|
|
1956
1968
|
}
|
|
1957
1969
|
}
|
|
1958
1970
|
const { messages, existingObservations } = await this.prepare();
|
|
@@ -1973,23 +1985,29 @@ var ObservationStrategy = class _ObservationStrategy {
|
|
|
1973
1985
|
observabilityContext: this.opts.observabilityContext
|
|
1974
1986
|
});
|
|
1975
1987
|
}
|
|
1988
|
+
return true;
|
|
1976
1989
|
} catch (error) {
|
|
1977
1990
|
await this.emitFailedMarkers(cycleId, error);
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1991
|
+
if (!this.rethrowOnFailure) {
|
|
1992
|
+
const failedMarkerForStorage = {
|
|
1993
|
+
type: "data-om-observation-failed",
|
|
1994
|
+
data: {
|
|
1995
|
+
cycleId,
|
|
1996
|
+
operationType: "observation",
|
|
1997
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1998
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1999
|
+
recordId: record.id,
|
|
2000
|
+
threadId
|
|
2001
|
+
}
|
|
2002
|
+
};
|
|
2003
|
+
await this.persistMarkerToStorage(failedMarkerForStorage, threadId, this.opts.resourceId).catch(() => {
|
|
2004
|
+
});
|
|
2005
|
+
if (abortSignal?.aborted) throw error;
|
|
2006
|
+
omError("[OM] Observation failed", error);
|
|
2007
|
+
return false;
|
|
2008
|
+
}
|
|
1992
2009
|
omError("[OM] Observation failed", error);
|
|
2010
|
+
throw error;
|
|
1993
2011
|
}
|
|
1994
2012
|
}
|
|
1995
2013
|
// ── Shared helpers ──────────────────────────────────────────
|
|
@@ -2210,6 +2228,9 @@ var SyncObservationStrategy = class extends ObservationStrategy {
|
|
|
2210
2228
|
get needsReflection() {
|
|
2211
2229
|
return true;
|
|
2212
2230
|
}
|
|
2231
|
+
get rethrowOnFailure() {
|
|
2232
|
+
return true;
|
|
2233
|
+
}
|
|
2213
2234
|
async prepare() {
|
|
2214
2235
|
const { record, threadId, messages } = this.opts;
|
|
2215
2236
|
this.deps.emitDebugEvent({
|
|
@@ -2401,6 +2422,9 @@ var AsyncBufferObservationStrategy = class extends ObservationStrategy {
|
|
|
2401
2422
|
get needsReflection() {
|
|
2402
2423
|
return false;
|
|
2403
2424
|
}
|
|
2425
|
+
get rethrowOnFailure() {
|
|
2426
|
+
return false;
|
|
2427
|
+
}
|
|
2404
2428
|
generateCycleId() {
|
|
2405
2429
|
return this.cycleId;
|
|
2406
2430
|
}
|
|
@@ -2537,6 +2561,9 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
|
|
|
2537
2561
|
get needsReflection() {
|
|
2538
2562
|
return true;
|
|
2539
2563
|
}
|
|
2564
|
+
get rethrowOnFailure() {
|
|
2565
|
+
return true;
|
|
2566
|
+
}
|
|
2540
2567
|
async prepare() {
|
|
2541
2568
|
const { record, threadId: currentThreadId, messages: currentThreadMessages } = this.opts;
|
|
2542
2569
|
const { threads: allThreads } = await this.storage.listThreads({ filter: { resourceId: this.resourceId } });
|
|
@@ -4816,11 +4843,10 @@ Aim for a 2/10 detail level. Fewer, more generic observations are better than ma
|
|
|
4816
4843
|
};
|
|
4817
4844
|
function buildReflectorPrompt(observations, manualPrompt, compressionLevel, skipContinuationHints) {
|
|
4818
4845
|
const level = typeof compressionLevel === "number" ? compressionLevel : compressionLevel ? 1 : 0;
|
|
4819
|
-
const reflectionView =
|
|
4820
|
-
const anchoredObservations = injectAnchorIds(reflectionView);
|
|
4846
|
+
const reflectionView = stripObservationGroups(observations);
|
|
4821
4847
|
let prompt = `## OBSERVATIONS TO REFLECT ON
|
|
4822
4848
|
|
|
4823
|
-
${
|
|
4849
|
+
${reflectionView}
|
|
4824
4850
|
|
|
4825
4851
|
---
|
|
4826
4852
|
|
|
@@ -8790,7 +8816,7 @@ ${grouped}` : grouped;
|
|
|
8790
8816
|
}
|
|
8791
8817
|
hooks?.onObservationStart?.();
|
|
8792
8818
|
try {
|
|
8793
|
-
await ObservationStrategy.create(this, {
|
|
8819
|
+
observed = await ObservationStrategy.create(this, {
|
|
8794
8820
|
record: freshRecord,
|
|
8795
8821
|
threadId,
|
|
8796
8822
|
resourceId,
|
|
@@ -8800,7 +8826,6 @@ ${grouped}` : grouped;
|
|
|
8800
8826
|
writer: opts.writer,
|
|
8801
8827
|
observabilityContext: opts.observabilityContext
|
|
8802
8828
|
}).run();
|
|
8803
|
-
observed = true;
|
|
8804
8829
|
} finally {
|
|
8805
8830
|
hooks?.onObservationEnd?.();
|
|
8806
8831
|
}
|
|
@@ -9405,5 +9430,5 @@ function getObservationsAsOf(activeObservations, asOf) {
|
|
|
9405
9430
|
}
|
|
9406
9431
|
|
|
9407
9432
|
export { ModelByInputTokens, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, combineObservationGroupRanges, deriveObservationGroupProvenance, e, estimateTokenCount, extractCurrentTask, formatMessagesForObserver, formatToolResultForObserver, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, reconcileObservationGroupsFromReflection, renderObservationGroupsForReflection, resolveToolResultValue, stripEphemeralAnchorIds, stripObservationGroups, truncateStringByTokens, wrapInObservationGroup };
|
|
9408
|
-
//# sourceMappingURL=chunk-
|
|
9409
|
-
//# sourceMappingURL=chunk-
|
|
9433
|
+
//# sourceMappingURL=chunk-5CDCKTHB.js.map
|
|
9434
|
+
//# sourceMappingURL=chunk-5CDCKTHB.js.map
|