@mastra/server 1.84.0-alpha.2 → 1.84.0-alpha.3
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/dist/{agent-builder-DYu--54x.js → agent-builder-D9rubwk0.js} +2 -2
- package/dist/{agent-builder-DYu--54x.js.map → agent-builder-D9rubwk0.js.map} +1 -1
- package/dist/{agent-builder-CMAT5xu8.cjs → agent-builder-DHqHFO5d.cjs} +2 -2
- package/dist/{agent-builder-CMAT5xu8.cjs.map → agent-builder-DHqHFO5d.cjs.map} +1 -1
- package/dist/{api-schema-manifest-DyOyIk-C.cjs → api-schema-manifest-AltoM-cn.cjs} +2 -2
- package/dist/{api-schema-manifest-DyOyIk-C.cjs.map → api-schema-manifest-AltoM-cn.cjs.map} +1 -1
- package/dist/{api-schema-manifest-MtnJy994.js → api-schema-manifest-D1A2zfm3.js} +2 -2
- package/dist/{api-schema-manifest-MtnJy994.js.map → api-schema-manifest-D1A2zfm3.js.map} +1 -1
- package/dist/{catalogue-oK_QSBRh.cjs → catalogue-BW2a1gu4.cjs} +3 -3
- package/dist/{catalogue-oK_QSBRh.cjs.map → catalogue-BW2a1gu4.cjs.map} +1 -1
- package/dist/{catalogue-BdR5h6fv.js → catalogue-DPLsw3zE.js} +3 -3
- package/dist/{catalogue-BdR5h6fv.js.map → catalogue-DPLsw3zE.js.map} +1 -1
- package/dist/{dist-4o3EGZcG.js → dist-CMgUx8hS.js} +102 -22
- package/dist/{dist-4o3EGZcG.js.map → dist-CMgUx8hS.js.map} +1 -1
- package/dist/{dist-p7VXVmE_.cjs → dist-D2zyg15_.cjs} +102 -22
- package/dist/{dist-p7VXVmE_.cjs.map → dist-D2zyg15_.cjs.map} +1 -1
- package/dist/dist-HNpJc8bT.js +1 -0
- package/dist/{dist-DXhZqfZZ.cjs → dist-ToffHjwd.cjs} +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/{probe-image-size-DmttstPc.cjs → probe-image-size--ACsCqf-.cjs} +2 -2
- package/dist/{probe-image-size-DmttstPc.cjs.map → probe-image-size--ACsCqf-.cjs.map} +1 -1
- package/dist/{probe-image-size-IIGl_zRY.js → probe-image-size-CxVMV0gk.js} +2 -2
- package/dist/{probe-image-size-IIGl_zRY.js.map → probe-image-size-CxVMV0gk.js.map} +1 -1
- package/dist/{routes-DAnFdADa.js → routes-CH5SQLu2.js} +3 -3
- package/dist/{routes-DAnFdADa.js.map → routes-CH5SQLu2.js.map} +1 -1
- package/dist/{routes-6lsEmZwB.cjs → routes-bWCQflz5.cjs} +3 -3
- package/dist/{routes-6lsEmZwB.cjs.map → routes-bWCQflz5.cjs.map} +1 -1
- package/dist/server/handlers/agent-builder.cjs +1 -1
- package/dist/server/handlers/agent-builder.js +1 -1
- package/dist/server/handlers/system.cjs +1 -1
- package/dist/server/handlers/system.js +1 -1
- package/dist/server/handlers.cjs +1 -1
- package/dist/server/handlers.js +1 -1
- package/dist/server/server-adapter/index.cjs +2 -2
- package/dist/server/server-adapter/index.js +2 -2
- package/dist/{server-adapter-Dgy-iIqA.js → server-adapter-B3kR1OJs.js} +2 -2
- package/dist/{server-adapter-Dgy-iIqA.js.map → server-adapter-B3kR1OJs.js.map} +1 -1
- package/dist/{server-adapter-CbxRgDBh.cjs → server-adapter-SLljXCyr.cjs} +2 -2
- package/dist/{server-adapter-CbxRgDBh.cjs.map → server-adapter-SLljXCyr.cjs.map} +1 -1
- package/package.json +5 -5
- package/dist/dist-CecsVJCw.js +0 -1
|
@@ -8654,7 +8654,7 @@ function splitLines(text) {
|
|
|
8654
8654
|
else result.push(result.pop().slice(0, -1));
|
|
8655
8655
|
return result;
|
|
8656
8656
|
}
|
|
8657
|
-
// ../memory/dist/src-
|
|
8657
|
+
// ../memory/dist/src-Xhctgeae.js
|
|
8658
8658
|
var __defProp$3 = Object.defineProperty;
|
|
8659
8659
|
var __exportAll = (all, no_symbols) => {
|
|
8660
8660
|
let target = {};
|
|
@@ -36785,7 +36785,7 @@ async function resolveImageDimensionsAsync(part) {
|
|
|
36785
36785
|
const url = resolveHttpAssetUrl(getObjectValue(part, "image") ?? getObjectValue(part, "data"));
|
|
36786
36786
|
if (!url) return existing;
|
|
36787
36787
|
try {
|
|
36788
|
-
const probeImageSize = (await Promise.resolve().then(() => /* @__PURE__ */ require_rolldown_runtime.__toESM(require("./probe-image-size
|
|
36788
|
+
const probeImageSize = (await Promise.resolve().then(() => /* @__PURE__ */ require_rolldown_runtime.__toESM(require("./probe-image-size--ACsCqf-.cjs").default, 1))).default;
|
|
36789
36789
|
const probed = await probeImageSize(url, {
|
|
36790
36790
|
open_timeout: REMOTE_IMAGE_PROBE_TIMEOUT_MS,
|
|
36791
36791
|
response_timeout: REMOTE_IMAGE_PROBE_TIMEOUT_MS,
|
|
@@ -48155,12 +48155,25 @@ function getOmObservabilityContext(args) {
|
|
|
48155
48155
|
metrics: args.metrics
|
|
48156
48156
|
};
|
|
48157
48157
|
}
|
|
48158
|
-
/** Key used to store gateway
|
|
48159
|
-
const GATEWAY_STATE_KEY = "
|
|
48158
|
+
/** Key used to store whether the gateway manages memory for the current step in per-processor state. */
|
|
48159
|
+
const GATEWAY_STATE_KEY = "__isGatewayMemoryManaged";
|
|
48160
48160
|
/** Step number OM last recovered from a context-overflow error, so each step retries at most once. */
|
|
48161
48161
|
const CONTEXT_OVERFLOW_STEP_KEY = "__omContextOverflowStep";
|
|
48162
|
-
/**
|
|
48163
|
-
|
|
48162
|
+
/**
|
|
48163
|
+
* Whether the Mastra gateway serves Observational Memory for this step's model.
|
|
48164
|
+
*
|
|
48165
|
+
* Gateway models only get memory from the gateway when the credential is a Gateway project
|
|
48166
|
+
* key. Organization keys (`msk-gateway-…`, `mskv2_…`) are served by a gateway without the
|
|
48167
|
+
* memory API, so memory has to stay local. Newer `@mastra/core` exposes that decision on the
|
|
48168
|
+
* router model; when it is absent (older core, or a plain model) fall back to the historical
|
|
48169
|
+
* `mastra/` prefix check so gateway-side memory is never double-processed.
|
|
48170
|
+
*
|
|
48171
|
+
* A model that fails the check is not treated as local. Core answers `false` only for a model
|
|
48172
|
+
* that isn't on the gateway, and throws when the credential can't be resolved — including when it
|
|
48173
|
+
* is missing; letting that through keeps the two sides in agreement.
|
|
48174
|
+
*/
|
|
48175
|
+
async function isGatewayMemoryManaged(model) {
|
|
48176
|
+
if (typeof model === "object" && model !== null && typeof model.isGatewayMemoryManaged === "function") return Boolean(await model.isGatewayMemoryManaged());
|
|
48164
48177
|
return typeof model === "object" && model !== null && "gatewayId" in model && model.gatewayId === "mastra";
|
|
48165
48178
|
}
|
|
48166
48179
|
function injectObservationContextMessages({ messageList, systemMessages, continuationMessage, hasObservations, threadId, resourceId }) {
|
|
@@ -48226,6 +48239,34 @@ var ObservationalMemoryProcessor = class {
|
|
|
48226
48239
|
this.memory = memory;
|
|
48227
48240
|
this.temporalMarkers = options?.temporalMarkers ?? false;
|
|
48228
48241
|
}
|
|
48242
|
+
/**
|
|
48243
|
+
* End any locally started turn without leaving it dangling.
|
|
48244
|
+
*
|
|
48245
|
+
* A gateway-managed step short-circuits both processor phases, so a turn started on an
|
|
48246
|
+
* earlier step of the same run — a delegation run whose model changed, or a run whose key
|
|
48247
|
+
* changed — would otherwise never be ended and its messages never persisted. `end()` with
|
|
48248
|
+
* no arguments flushes what the turn already tracked; finalization passes the accepted
|
|
48249
|
+
* terminal list for the same reason the regular output path does.
|
|
48250
|
+
*
|
|
48251
|
+
* A rejected write is not swallowed. `end()` marks the turn ended before it persists, so a
|
|
48252
|
+
* failed write leaves the turn unusable and its messages would be lost silently while the run
|
|
48253
|
+
* reported success. The drain persists those messages directly and rethrows, so a storage
|
|
48254
|
+
* failure surfaces instead of dropping the turn.
|
|
48255
|
+
*/
|
|
48256
|
+
async endActiveTurn(state, messageList) {
|
|
48257
|
+
const activeTurn = asLiveTurn(state.__omTurn) ?? this.turn;
|
|
48258
|
+
this.turn = void 0;
|
|
48259
|
+
state.__omTurn = void 0;
|
|
48260
|
+
if (!activeTurn || activeTurn.ended) return;
|
|
48261
|
+
const terminalList = messageList ?? activeTurn.messageList;
|
|
48262
|
+
const unsavedMessages = [...terminalList.get.input.db(), ...terminalList.get.response.db()];
|
|
48263
|
+
try {
|
|
48264
|
+
await activeTurn.end(terminalList);
|
|
48265
|
+
} catch (error) {
|
|
48266
|
+
if (unsavedMessages.length > 0) await this.engine.persistMessages(unsavedMessages, activeTurn.threadId, activeTurn.resourceId).catch(() => {});
|
|
48267
|
+
throw error;
|
|
48268
|
+
}
|
|
48269
|
+
}
|
|
48229
48270
|
async processInputStep(args) {
|
|
48230
48271
|
const { messageList, requestContext, stepNumber, state: _state, writer, model, abortSignal, abort, messageId, rotateResponseMessageId } = args;
|
|
48231
48272
|
const state = _state ?? {};
|
|
@@ -48235,9 +48276,11 @@ var ObservationalMemoryProcessor = class {
|
|
|
48235
48276
|
omDebug(`[OM:processInputStep:NO-CONTEXT] getThreadContext returned null — returning early`);
|
|
48236
48277
|
return messageList;
|
|
48237
48278
|
}
|
|
48238
|
-
|
|
48239
|
-
|
|
48240
|
-
|
|
48279
|
+
const gatewayMemoryManaged = await isGatewayMemoryManaged(model);
|
|
48280
|
+
state[GATEWAY_STATE_KEY] = gatewayMemoryManaged;
|
|
48281
|
+
if (gatewayMemoryManaged) {
|
|
48282
|
+
await this.endActiveTurn(state);
|
|
48283
|
+
omDebug(`[OM:processInputStep:GATEWAY] gateway manages memory — skipping local processing`);
|
|
48241
48284
|
return messageList;
|
|
48242
48285
|
}
|
|
48243
48286
|
const { threadId, resourceId } = context;
|
|
@@ -48427,7 +48470,10 @@ var ObservationalMemoryProcessor = class {
|
|
|
48427
48470
|
const state = _state ?? {};
|
|
48428
48471
|
const context = this.engine.getThreadContext(requestContext, messageList);
|
|
48429
48472
|
if (!context) return messageList;
|
|
48430
|
-
if (state[GATEWAY_STATE_KEY])
|
|
48473
|
+
if (state[GATEWAY_STATE_KEY]) {
|
|
48474
|
+
await this.endActiveTurn(state, messageList.cloneForPersistence());
|
|
48475
|
+
return messageList;
|
|
48476
|
+
}
|
|
48431
48477
|
state.__omObservabilityContext = getOmObservabilityContext(args);
|
|
48432
48478
|
return this.engine.getTokenCounter().runWithModelContext(state.__omActorModelContext, async () => {
|
|
48433
48479
|
if ((0, _mastra_core_memory.parseMemoryRequestContext)(requestContext)?.memoryConfig?.readOnly) return messageList;
|
|
@@ -48900,7 +48946,7 @@ var Memory = class Memory extends _mastra_core_memory.MastraMemory {
|
|
|
48900
48946
|
}
|
|
48901
48947
|
}
|
|
48902
48948
|
const threshold = (typeof config.semanticRecall === "object" ? config.semanticRecall : void 0)?.threshold;
|
|
48903
|
-
const filteredVectorResults =
|
|
48949
|
+
const filteredVectorResults = vectorResults.filter((r) => (threshold === void 0 || r.score >= threshold) && (resourceScope ? r.metadata?.resource_id === resourceId : r.metadata?.thread_id === threadId));
|
|
48904
48950
|
const memoryStore = await this.getMemoryStore();
|
|
48905
48951
|
const include = filteredVectorResults.map((r) => ({
|
|
48906
48952
|
id: r.metadata?.message_id,
|
|
@@ -48964,6 +49010,7 @@ var Memory = class Memory extends _mastra_core_memory.MastraMemory {
|
|
|
48964
49010
|
rawMessages = shouldGetNewestAndReverse ? paginatedResult.messages.reverse() : paginatedResult.messages;
|
|
48965
49011
|
({total, page: resultPage, perPage: resultPerPage, hasMore} = paginatedResult);
|
|
48966
49012
|
}
|
|
49013
|
+
if (include.length) rawMessages = rawMessages.filter((message) => message.threadId === threadId || resourceScope && message.resourceId === resourceId);
|
|
48967
49014
|
const messages = filterSystemReminderMessages(new _mastra_core_agent.MessageList({
|
|
48968
49015
|
threadId,
|
|
48969
49016
|
resourceId
|
|
@@ -49314,42 +49361,74 @@ ${workingMemory}`;
|
|
|
49314
49361
|
this.embeddingCache.set(key, result);
|
|
49315
49362
|
return result;
|
|
49316
49363
|
}
|
|
49364
|
+
chunkEmbeddingCache = new I({ max: DEFAULT_EMBEDDING_CACHE_MAX_SIZE });
|
|
49365
|
+
chunkEmbeddingCacheOwner = {};
|
|
49366
|
+
/**
|
|
49367
|
+
* Embeds one message's chunks, reusing vectors already produced for the same chunks. Usage is
|
|
49368
|
+
* returned only for a call that reached the embedder.
|
|
49369
|
+
*/
|
|
49370
|
+
async embedMessageChunks(chunks) {
|
|
49371
|
+
const producer = {
|
|
49372
|
+
embedder: this.embedder,
|
|
49373
|
+
embedderOptions: this.embedderOptions
|
|
49374
|
+
};
|
|
49375
|
+
const key = (await this.hasher).h64(JSON.stringify(chunks));
|
|
49376
|
+
if (producer.embedder !== this.embedder || producer.embedderOptions !== this.embedderOptions) return this.embedValues(chunks, producer);
|
|
49377
|
+
const owner = this.chunkEmbeddingCacheOwner;
|
|
49378
|
+
if (owner.embedder !== producer.embedder || owner.embedderOptions !== producer.embedderOptions) {
|
|
49379
|
+
this.chunkEmbeddingCache.clear();
|
|
49380
|
+
this.chunkEmbeddingCacheOwner = producer;
|
|
49381
|
+
}
|
|
49382
|
+
const cached = this.chunkEmbeddingCache.get(key);
|
|
49383
|
+
if (cached) return { embeddings: await cached };
|
|
49384
|
+
const result = this.embedValues(chunks, producer);
|
|
49385
|
+
const embeddings = result.then(({ embeddings }) => {
|
|
49386
|
+
if (embeddings.length !== chunks.length) evict();
|
|
49387
|
+
return embeddings;
|
|
49388
|
+
});
|
|
49389
|
+
const evict = () => {
|
|
49390
|
+
if (this.chunkEmbeddingCache.get(key) === embeddings) this.chunkEmbeddingCache.delete(key);
|
|
49391
|
+
};
|
|
49392
|
+
embeddings.catch(evict);
|
|
49393
|
+
this.chunkEmbeddingCache.set(key, embeddings);
|
|
49394
|
+
return result;
|
|
49395
|
+
}
|
|
49317
49396
|
/** Sends texts to the embedder through the AI SDK version that matches its spec. */
|
|
49318
|
-
async embedValues(values) {
|
|
49319
|
-
if (typeof
|
|
49320
|
-
const isFastEmbed =
|
|
49397
|
+
async embedValues(values, { embedder, embedderOptions } = this) {
|
|
49398
|
+
if (typeof embedder === `undefined`) throw new Error(`Tried to embed message content but this Memory instance doesn't have an attached embedder.`);
|
|
49399
|
+
const isFastEmbed = embedder.provider === `fastembed`;
|
|
49321
49400
|
if (isFastEmbed && this.firstEmbed instanceof Promise) await this.firstEmbed;
|
|
49322
49401
|
const options = {
|
|
49323
49402
|
values,
|
|
49324
49403
|
maxRetries: 3
|
|
49325
49404
|
};
|
|
49326
|
-
const model =
|
|
49405
|
+
const model = embedder;
|
|
49327
49406
|
let promise;
|
|
49328
49407
|
switch (model.specificationVersion) {
|
|
49329
49408
|
case "v4":
|
|
49330
49409
|
promise = embedMany({
|
|
49331
49410
|
...options,
|
|
49332
|
-
...
|
|
49411
|
+
...embedderOptions,
|
|
49333
49412
|
model
|
|
49334
49413
|
});
|
|
49335
49414
|
break;
|
|
49336
49415
|
case "v3":
|
|
49337
49416
|
promise = embedMany$1({
|
|
49338
49417
|
...options,
|
|
49339
|
-
...
|
|
49418
|
+
...embedderOptions,
|
|
49340
49419
|
model
|
|
49341
49420
|
});
|
|
49342
49421
|
break;
|
|
49343
49422
|
case "v2":
|
|
49344
49423
|
promise = embedMany$2({
|
|
49345
49424
|
...options,
|
|
49346
|
-
...
|
|
49425
|
+
...embedderOptions,
|
|
49347
49426
|
model
|
|
49348
49427
|
});
|
|
49349
49428
|
break;
|
|
49350
49429
|
default: promise = embedMany$3({
|
|
49351
49430
|
...options,
|
|
49352
|
-
...
|
|
49431
|
+
...embedderOptions,
|
|
49353
49432
|
model
|
|
49354
49433
|
});
|
|
49355
49434
|
}
|
|
@@ -49391,7 +49470,7 @@ ${workingMemory}`;
|
|
|
49391
49470
|
if (!this.embedder && !this.isSelfEmbedding) throw new Error(`Tried to embed message content but this Memory instance doesn't have an attached embedder.`);
|
|
49392
49471
|
return (0, _mastra_core_memory.buildMessageEmbeddingRows)({
|
|
49393
49472
|
items,
|
|
49394
|
-
embed: this.isSelfEmbedding ? void 0 : (chunks) => this.
|
|
49473
|
+
embed: this.isSelfEmbedding ? void 0 : (chunks) => this.embedMessageChunks(chunks),
|
|
49395
49474
|
maxChunkChars: (0, _mastra_core_memory.resolveMaxChunkChars)({
|
|
49396
49475
|
maxChunkChars: this.configuredMaxChunkChars,
|
|
49397
49476
|
embedder: this.embedder
|
|
@@ -49977,6 +50056,7 @@ Notes:
|
|
|
49977
50056
|
});
|
|
49978
50057
|
for (const r of results) {
|
|
49979
50058
|
if (!r.metadata?.thread_id) continue;
|
|
50059
|
+
if (r.metadata.resource_id !== resourceId || filter?.threadId && r.metadata.thread_id !== filter.threadId) continue;
|
|
49980
50060
|
const groupId = typeof r.metadata.group_id === "string" ? r.metadata.group_id : void 0;
|
|
49981
50061
|
if (!groupId) continue;
|
|
49982
50062
|
queryResults.push({
|
|
@@ -52026,7 +52106,7 @@ const createModelInstance = async (provider, modelId, version = "v2") => {
|
|
|
52026
52106
|
try {
|
|
52027
52107
|
const providerFn = version === `v1` ? { v1: {
|
|
52028
52108
|
openai: async () => {
|
|
52029
|
-
const { openai } = await Promise.resolve().then(() => require("./dist-
|
|
52109
|
+
const { openai } = await Promise.resolve().then(() => require("./dist-ToffHjwd.cjs"));
|
|
52030
52110
|
return openai(modelId);
|
|
52031
52111
|
},
|
|
52032
52112
|
anthropic: async () => {
|
|
@@ -59856,4 +59936,4 @@ Object.defineProperty(exports, "require_webp", {
|
|
|
59856
59936
|
}
|
|
59857
59937
|
});
|
|
59858
59938
|
|
|
59859
|
-
//# sourceMappingURL=dist-
|
|
59939
|
+
//# sourceMappingURL=dist-D2zyg15_.cjs.map
|