@mastra/server 1.83.0-alpha.1 → 1.83.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/{a2a-CQlJ-SZr.js → a2a-BnWFvgiU.js} +2 -2
- package/dist/{a2a-CQlJ-SZr.js.map → a2a-BnWFvgiU.js.map} +1 -1
- package/dist/{a2a-mDspNbWX.cjs → a2a-Cu87JDM2.cjs} +2 -2
- package/dist/{a2a-mDspNbWX.cjs.map → a2a-Cu87JDM2.cjs.map} +1 -1
- package/dist/{agent-builder-B9gEkbch.cjs → agent-builder-73cAYGts.cjs} +2 -2
- package/dist/{agent-builder-B9gEkbch.cjs.map → agent-builder-73cAYGts.cjs.map} +1 -1
- package/dist/{agent-builder-BF7OAl_R.js → agent-builder-pQaGXyFz.js} +2 -2
- package/dist/{agent-builder-BF7OAl_R.js.map → agent-builder-pQaGXyFz.js.map} +1 -1
- package/dist/{agents-DXlVewzD.js → agents-BA-MmcJN.js} +56 -33
- package/dist/agents-BA-MmcJN.js.map +1 -0
- package/dist/{agents-CMEeZr5y.cjs → agents-BMxHcsO7.cjs} +56 -33
- package/dist/agents-BMxHcsO7.cjs.map +1 -0
- package/dist/{api-schema-manifest-BKnghL_k.cjs → api-schema-manifest-CDJEhBm9.cjs} +2 -2
- package/dist/{api-schema-manifest-BKnghL_k.cjs.map → api-schema-manifest-CDJEhBm9.cjs.map} +1 -1
- package/dist/{api-schema-manifest-DOuSq4rG.js → api-schema-manifest-DvyXrvvK.js} +2 -2
- package/dist/{api-schema-manifest-DOuSq4rG.js.map → api-schema-manifest-DvyXrvvK.js.map} +1 -1
- package/dist/{background-tasks-BXTIp0QV.cjs → background-tasks-CIXrANYT.cjs} +5 -1
- package/dist/background-tasks-CIXrANYT.cjs.map +1 -0
- package/dist/{background-tasks-BIuEr2of.js → background-tasks-S__xU_pa.js} +5 -1
- package/dist/background-tasks-S__xU_pa.js.map +1 -0
- package/dist/{conversations-CFj4BnNb.cjs → conversations-CsyE18Yj.cjs} +2 -2
- package/dist/{conversations-CFj4BnNb.cjs.map → conversations-CsyE18Yj.cjs.map} +1 -1
- package/dist/{conversations-DjTKtaUi.js → conversations-DtbEa1l_.js} +2 -2
- package/dist/{conversations-DjTKtaUi.js.map → conversations-DtbEa1l_.js.map} +1 -1
- package/dist/dist-CQGBYe6U.js +1 -0
- package/dist/{dist-OKFDPspq.js → dist-CXxA_Jnu.js} +122 -281
- package/dist/dist-CXxA_Jnu.js.map +1 -0
- package/dist/{dist-Ctfk9X6u.cjs → dist-DIeKEdwH.cjs} +121 -280
- package/dist/dist-DIeKEdwH.cjs.map +1 -0
- package/dist/{dist-ZYvqJK9p.cjs → dist-Dhi6UZwv.cjs} +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-resumable-streams.md +3 -3
- package/dist/docs/references/docs-server-custom-adapters.md +40 -11
- package/dist/docs/references/docs-server-middleware.md +1 -1
- package/dist/{editor-builder-o9xJHa96.js → editor-builder-B4-g7fu_.js} +2 -2
- package/dist/{editor-builder-o9xJHa96.js.map → editor-builder-B4-g7fu_.js.map} +1 -1
- package/dist/{editor-builder-CBBZxQhO.cjs → editor-builder-BTi2EIB1.cjs} +2 -2
- package/dist/{editor-builder-CBBZxQhO.cjs.map → editor-builder-BTi2EIB1.cjs.map} +1 -1
- package/dist/{plans-DVx9N2re.js → plans-BLqnqqE0.js} +2 -2
- package/dist/{plans-DVx9N2re.js.map → plans-BLqnqqE0.js.map} +1 -1
- package/dist/{plans-CQijj_Am.cjs → plans-LbsK1Bj0.cjs} +2 -2
- package/dist/{plans-CQijj_Am.cjs.map → plans-LbsK1Bj0.cjs.map} +1 -1
- package/dist/{probe-image-size-bDuzMW0E.cjs → probe-image-size-C2efNs3R.cjs} +2 -2
- package/dist/{probe-image-size-bDuzMW0E.cjs.map → probe-image-size-C2efNs3R.cjs.map} +1 -1
- package/dist/{probe-image-size-Cxm5QtwO.js → probe-image-size-CO02-278.js} +2 -2
- package/dist/{probe-image-size-Cxm5QtwO.js.map → probe-image-size-CO02-278.js.map} +1 -1
- package/dist/{responses-DYGS0aiI.cjs → responses-7obXjZaq.cjs} +2 -2
- package/dist/{responses-DYGS0aiI.cjs.map → responses-7obXjZaq.cjs.map} +1 -1
- package/dist/{responses-NM-kLq8b.js → responses-DYPwRZ7Z.js} +2 -2
- package/dist/{responses-NM-kLq8b.js.map → responses-DYPwRZ7Z.js.map} +1 -1
- package/dist/{routes-CWrdLnBc.cjs → routes-B9pnPvQx.cjs} +11 -11
- package/dist/{routes-CWrdLnBc.cjs.map → routes-B9pnPvQx.cjs.map} +1 -1
- package/dist/{routes-B2XGdvlv.js → routes-CHctVPfy.js} +11 -11
- package/dist/{routes-B2XGdvlv.js.map → routes-CHctVPfy.js.map} +1 -1
- package/dist/{scores-CWx6H3Z8.cjs → scores-DxLiiwPT.cjs} +2 -2
- package/dist/{scores-CWx6H3Z8.cjs.map → scores-DxLiiwPT.cjs.map} +1 -1
- package/dist/{scores-DTVV_OaX.js → scores-qTduRPeX.js} +2 -2
- package/dist/{scores-DTVV_OaX.js.map → scores-qTduRPeX.js.map} +1 -1
- package/dist/server/handlers/a2a.cjs +1 -1
- package/dist/server/handlers/a2a.js +1 -1
- package/dist/server/handlers/agent-builder.cjs +1 -1
- package/dist/server/handlers/agent-builder.js +1 -1
- package/dist/server/handlers/agent-controller.cjs +4 -0
- package/dist/server/handlers/agent-controller.cjs.map +1 -1
- package/dist/server/handlers/agent-controller.d.ts.map +1 -1
- package/dist/server/handlers/agent-controller.js +4 -0
- package/dist/server/handlers/agent-controller.js.map +1 -1
- package/dist/server/handlers/agents.cjs +1 -1
- package/dist/server/handlers/agents.d.ts.map +1 -1
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/background-tasks.cjs +1 -1
- package/dist/server/handlers/background-tasks.d.ts.map +1 -1
- package/dist/server/handlers/background-tasks.js +1 -1
- package/dist/server/handlers/conversations.cjs +1 -1
- package/dist/server/handlers/conversations.js +1 -1
- package/dist/server/handlers/editor-builder.cjs +1 -1
- package/dist/server/handlers/editor-builder.js +1 -1
- package/dist/server/handlers/error.cjs +1 -0
- package/dist/server/handlers/error.cjs.map +1 -1
- package/dist/server/handlers/error.d.ts.map +1 -1
- package/dist/server/handlers/error.js +1 -0
- package/dist/server/handlers/error.js.map +1 -1
- package/dist/server/handlers/favorites-enrichment.cjs +1 -1
- package/dist/server/handlers/favorites-enrichment.js +1 -1
- package/dist/server/handlers/plans.cjs +1 -1
- package/dist/server/handlers/plans.js +1 -1
- package/dist/server/handlers/responses.cjs +1 -1
- package/dist/server/handlers/responses.js +1 -1
- package/dist/server/handlers/scores.cjs +1 -1
- package/dist/server/handlers/scores.js +1 -1
- package/dist/server/handlers/stored-agent-favorites.cjs +1 -1
- package/dist/server/handlers/stored-agent-favorites.js +1 -1
- package/dist/server/handlers/stored-agents.cjs +1 -1
- package/dist/server/handlers/stored-agents.js +1 -1
- package/dist/server/handlers/stored-skill-favorites.cjs +1 -1
- package/dist/server/handlers/stored-skill-favorites.js +1 -1
- package/dist/server/handlers/stored-skills.cjs +1 -1
- package/dist/server/handlers/stored-skills.js +1 -1
- package/dist/server/handlers/system.cjs +1 -1
- package/dist/server/handlers/system.js +1 -1
- package/dist/server/handlers/tools.cjs +1 -1
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers.cjs +8 -8
- package/dist/server/handlers.js +8 -8
- package/dist/server/server-adapter/index.cjs +47 -1
- package/dist/server/server-adapter/index.cjs.map +1 -1
- package/dist/server/server-adapter/index.d.ts +1 -0
- package/dist/server/server-adapter/index.d.ts.map +1 -1
- package/dist/server/server-adapter/index.js +46 -2
- package/dist/server/server-adapter/index.js.map +1 -1
- package/dist/server/server-adapter/routes/responses.d.ts +11 -11
- package/dist/server/server-adapter/stream-disconnect.d.ts +24 -0
- package/dist/server/server-adapter/stream-disconnect.d.ts.map +1 -0
- package/dist/{tools-Bf3vq-HD.js → tools-DeHsVuWZ.js} +2 -2
- package/dist/{tools-Bf3vq-HD.js.map → tools-DeHsVuWZ.js.map} +1 -1
- package/dist/{tools-7O8cd_4u.cjs → tools-DszNVjKC.cjs} +2 -2
- package/dist/{tools-7O8cd_4u.cjs.map → tools-DszNVjKC.cjs.map} +1 -1
- package/package.json +3 -3
- package/dist/agents-CMEeZr5y.cjs.map +0 -1
- package/dist/agents-DXlVewzD.js.map +0 -1
- package/dist/background-tasks-BIuEr2of.js.map +0 -1
- package/dist/background-tasks-BXTIp0QV.cjs.map +0 -1
- package/dist/dist-Ctfk9X6u.cjs.map +0 -1
- package/dist/dist-DJjVMQiv.js +0 -1
- package/dist/dist-OKFDPspq.js.map +0 -1
|
@@ -8,7 +8,7 @@ import { any, array, boolean, custom, discriminatedUnion, enum as enum$1, instan
|
|
|
8
8
|
import { isStandardSchemaWithJSON, toStandardSchema } from "@mastra/core/schema";
|
|
9
9
|
import { ZodFirstPartyTypeKind } from "zod/v3";
|
|
10
10
|
import { z as z$2 } from "zod";
|
|
11
|
-
import { MastraMemory, getMemoryTokenBoundary, getThreadOMMetadata, isAfterMemoryTokenBoundary, isThreadTitlePinned, loadMessageHistory, normalizeMessageHistoryConfig, parseMemoryRequestContext, setThreadOMMetadata } from "@mastra/core/memory";
|
|
11
|
+
import { MESSAGE_EMBEDDING_CHARS_PER_TOKEN, MastraMemory, buildMessageEmbeddingRows, chunkMessageText, getMemoryTokenBoundary, getThreadOMMetadata, isAfterMemoryTokenBoundary, isThreadTitlePinned, loadMessageHistory, normalizeMessageHistoryConfig, parseMemoryRequestContext, resolveMaxChunkChars, setThreadOMMetadata, upsertMessageVectors } from "@mastra/core/memory";
|
|
12
12
|
import { Agent, MessageList, isSupportedLanguageModel, tryGenerateWithJsonFallback, tryStreamWithJsonFallback } from "@mastra/core/agent";
|
|
13
13
|
import { ErrorCategory, ErrorDomain, MastraError, classifyProviderError } from "@mastra/core/error";
|
|
14
14
|
import { ModelRouterLanguageModel, modelSupportsAttachments, modelSupportsTemperature, resolveModelConfig } from "@mastra/core/llm";
|
|
@@ -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-BL6KZcyR.js
|
|
8658
8658
|
var __defProp$3 = Object.defineProperty;
|
|
8659
8659
|
var __exportAll = (all, no_symbols) => {
|
|
8660
8660
|
let target = {};
|
|
@@ -36735,7 +36735,7 @@ async function resolveImageDimensionsAsync(part) {
|
|
|
36735
36735
|
const url = resolveHttpAssetUrl(getObjectValue(part, "image") ?? getObjectValue(part, "data"));
|
|
36736
36736
|
if (!url) return existing;
|
|
36737
36737
|
try {
|
|
36738
|
-
const probeImageSize = (await import("./probe-image-size-
|
|
36738
|
+
const probeImageSize = (await import("./probe-image-size-CO02-278.js").then((m) => /* @__PURE__ */ __toESM$1(m.default, 1))).default;
|
|
36739
36739
|
const probed = await probeImageSize(url, {
|
|
36740
36740
|
open_timeout: REMOTE_IMAGE_PROBE_TIMEOUT_MS,
|
|
36741
36741
|
response_timeout: REMOTE_IMAGE_PROBE_TIMEOUT_MS,
|
|
@@ -48289,7 +48289,8 @@ var ObservationalMemoryProcessor = class {
|
|
|
48289
48289
|
ctx = await step.prepare();
|
|
48290
48290
|
} catch (error) {
|
|
48291
48291
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
48292
|
-
const
|
|
48292
|
+
const abortReason = abortSignal?.reason;
|
|
48293
|
+
const abortMessage = abortSignal?.aborted ? abortReason instanceof Error && abortReason.name !== "AbortError" ? `Agent execution was aborted: ${abortReason.message}` : "Agent execution was aborted" : `Encountered error during memory observation: ${err.message}`;
|
|
48293
48294
|
const failedTurn = this.turn;
|
|
48294
48295
|
await failedTurn.end().catch(() => {});
|
|
48295
48296
|
if (this.turn === failedTurn) this.turn = void 0;
|
|
@@ -48549,7 +48550,6 @@ function normalizeObservationalMemoryConfig(config) {
|
|
|
48549
48550
|
function hasWorkingMemoryExtractor(extractors) {
|
|
48550
48551
|
return !!extractors?.some((extractor) => extractor.slug === "working-memory");
|
|
48551
48552
|
}
|
|
48552
|
-
const CHARS_PER_TOKEN = 4;
|
|
48553
48553
|
const DEFAULT_MESSAGE_RANGE = {
|
|
48554
48554
|
before: 1,
|
|
48555
48555
|
after: 1
|
|
@@ -48692,6 +48692,7 @@ var Memory = class Memory extends MastraMemory {
|
|
|
48692
48692
|
});
|
|
48693
48693
|
this.assertWorkingMemoryStateSignalsCompatibility(mergedConfig);
|
|
48694
48694
|
this.threadConfig = mergedConfig;
|
|
48695
|
+
resolveMaxChunkChars({ maxChunkChars: this.configuredMaxChunkChars });
|
|
48695
48696
|
const omConfig = normalizeObservationalMemoryConfig(mergedConfig.observationalMemory);
|
|
48696
48697
|
if (omConfig?.retrieval && typeof omConfig.retrieval === "object" && omConfig.retrieval.vector) {
|
|
48697
48698
|
if (!this.vector) throw new Error("`retrieval: { vector: true }` requires a vector store. Pass a `vector` option to your Memory instance.");
|
|
@@ -49207,28 +49208,9 @@ ${workingMemory}`;
|
|
|
49207
49208
|
release();
|
|
49208
49209
|
}
|
|
49209
49210
|
}
|
|
49211
|
+
/** Splits text into chunks of at most `tokenSize` English tokens, measured as characters. */
|
|
49210
49212
|
chunkText(text, tokenSize = 4096) {
|
|
49211
|
-
|
|
49212
|
-
const chunks = [];
|
|
49213
|
-
let currentChunk = "";
|
|
49214
|
-
const words = text.split(/\s+/);
|
|
49215
|
-
for (const word of words) {
|
|
49216
|
-
if (word.length > charSize) {
|
|
49217
|
-
if (currentChunk) {
|
|
49218
|
-
chunks.push(currentChunk);
|
|
49219
|
-
currentChunk = "";
|
|
49220
|
-
}
|
|
49221
|
-
for (let i = 0; i < word.length; i += charSize) chunks.push(word.slice(i, i + charSize));
|
|
49222
|
-
continue;
|
|
49223
|
-
}
|
|
49224
|
-
const wordWithSpace = currentChunk ? " " + word : word;
|
|
49225
|
-
if (currentChunk.length + wordWithSpace.length > charSize) {
|
|
49226
|
-
if (currentChunk) chunks.push(currentChunk);
|
|
49227
|
-
currentChunk = word;
|
|
49228
|
-
} else currentChunk += wordWithSpace;
|
|
49229
|
-
}
|
|
49230
|
-
if (currentChunk) chunks.push(currentChunk);
|
|
49231
|
-
return chunks;
|
|
49213
|
+
return chunkMessageText(text, tokenSize * MESSAGE_EMBEDDING_CHARS_PER_TOKEN);
|
|
49232
49214
|
}
|
|
49233
49215
|
hasher = e();
|
|
49234
49216
|
embeddingCache = new I({ max: DEFAULT_EMBEDDING_CACHE_MAX_SIZE });
|
|
@@ -49244,11 +49226,23 @@ ${workingMemory}`;
|
|
|
49244
49226
|
return cached;
|
|
49245
49227
|
}
|
|
49246
49228
|
const chunks = this.chunkText(content);
|
|
49229
|
+
const { embeddings, usage } = await this.embedValues(chunks);
|
|
49230
|
+
const result = {
|
|
49231
|
+
embeddings,
|
|
49232
|
+
chunks,
|
|
49233
|
+
usage,
|
|
49234
|
+
dimension: embeddings[0]?.length
|
|
49235
|
+
};
|
|
49236
|
+
this.embeddingCache.set(key, result);
|
|
49237
|
+
return result;
|
|
49238
|
+
}
|
|
49239
|
+
/** Sends texts to the embedder through the AI SDK version that matches its spec. */
|
|
49240
|
+
async embedValues(values) {
|
|
49247
49241
|
if (typeof this.embedder === `undefined`) throw new Error(`Tried to embed message content but this Memory instance doesn't have an attached embedder.`);
|
|
49248
49242
|
const isFastEmbed = this.embedder.provider === `fastembed`;
|
|
49249
49243
|
if (isFastEmbed && this.firstEmbed instanceof Promise) await this.firstEmbed;
|
|
49250
49244
|
const options = {
|
|
49251
|
-
values
|
|
49245
|
+
values,
|
|
49252
49246
|
maxRetries: 3
|
|
49253
49247
|
};
|
|
49254
49248
|
const model = this.embedder;
|
|
@@ -49283,106 +49277,87 @@ ${workingMemory}`;
|
|
|
49283
49277
|
}
|
|
49284
49278
|
if (isFastEmbed && !this.firstEmbed) this.firstEmbed = promise;
|
|
49285
49279
|
const { embeddings, usage } = await promise;
|
|
49286
|
-
|
|
49280
|
+
return {
|
|
49287
49281
|
embeddings,
|
|
49288
|
-
|
|
49289
|
-
usage,
|
|
49290
|
-
dimension: embeddings[0]?.length
|
|
49282
|
+
usage
|
|
49291
49283
|
};
|
|
49292
|
-
this.embeddingCache.set(key, result);
|
|
49293
|
-
return result;
|
|
49294
49284
|
}
|
|
49295
|
-
|
|
49285
|
+
/**
|
|
49286
|
+
* Metadata of each thread, spread onto that thread's vector rows so `semanticRecall.filter`
|
|
49287
|
+
* can match thread attributes.
|
|
49288
|
+
*/
|
|
49289
|
+
async loadThreadMetadata(threadIds) {
|
|
49290
|
+
const memoryStore = await this.getMemoryStore();
|
|
49291
|
+
const metadataByThread = /* @__PURE__ */ new Map();
|
|
49292
|
+
await Promise.all(threadIds.map(async (threadId) => {
|
|
49293
|
+
try {
|
|
49294
|
+
const thread = await memoryStore.getThreadById({ threadId });
|
|
49295
|
+
if (thread?.metadata) metadataByThread.set(threadId, thread.metadata);
|
|
49296
|
+
} catch (error) {
|
|
49297
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
49298
|
+
throw new Error(`Could not fetch metadata for thread ${threadId} while writing semantic recall embeddings: ${message}`);
|
|
49299
|
+
}
|
|
49300
|
+
}));
|
|
49301
|
+
return metadataByThread;
|
|
49302
|
+
}
|
|
49303
|
+
/**
|
|
49304
|
+
* Embeds messages into vector rows in the shared format, without writing them. Every
|
|
49305
|
+
* message-vector write in this class builds its rows here.
|
|
49306
|
+
*/
|
|
49307
|
+
async buildMessageVectorRows({ items, embeddedMessages }) {
|
|
49308
|
+
if (items.length === 0) return {
|
|
49309
|
+
ids: [],
|
|
49310
|
+
metadata: [],
|
|
49311
|
+
embeddedEntries: []
|
|
49312
|
+
};
|
|
49313
|
+
if (!this.embedder && !this.isSelfEmbedding) throw new Error(`Tried to embed message content but this Memory instance doesn't have an attached embedder.`);
|
|
49314
|
+
return buildMessageEmbeddingRows({
|
|
49315
|
+
items,
|
|
49316
|
+
embed: this.isSelfEmbedding ? void 0 : (chunks) => this.embedValues(chunks),
|
|
49317
|
+
maxChunkChars: resolveMaxChunkChars({
|
|
49318
|
+
maxChunkChars: this.configuredMaxChunkChars,
|
|
49319
|
+
embedder: this.embedder
|
|
49320
|
+
}),
|
|
49321
|
+
loadThreadMetadata: (threadIds) => this.loadThreadMetadata(threadIds),
|
|
49322
|
+
embeddedMessages,
|
|
49323
|
+
indexName: embeddedMessages ? this.getEmbeddingIndexName(this.isSelfEmbedding ? void 0 : await this.getEmbeddingDimension()) : void 0
|
|
49324
|
+
});
|
|
49325
|
+
}
|
|
49326
|
+
/** Writes rows from {@link buildMessageVectorRows} into the message index for `config`. */
|
|
49327
|
+
async writeMessageVectorRows({ rows, config, embeddedMessages }) {
|
|
49328
|
+
if (!this.vector || rows.ids.length === 0) return;
|
|
49329
|
+
const { indexName } = await this.createEmbeddingIndex(rows.dimension, config);
|
|
49330
|
+
await upsertMessageVectors(this.vector, indexName, rows, embeddedMessages);
|
|
49331
|
+
}
|
|
49332
|
+
/**
|
|
49333
|
+
* Embeds messages and writes their vector rows.
|
|
49334
|
+
*
|
|
49335
|
+
* @returns Tokens billed by the embedder, if any.
|
|
49336
|
+
*/
|
|
49337
|
+
async writeMessageVectors(args) {
|
|
49338
|
+
if (!this.vector) return void 0;
|
|
49339
|
+
const rows = await this.buildMessageVectorRows(args);
|
|
49340
|
+
await this.writeMessageVectorRows({
|
|
49341
|
+
...args,
|
|
49342
|
+
rows
|
|
49343
|
+
});
|
|
49344
|
+
return rows.usage;
|
|
49345
|
+
}
|
|
49346
|
+
async saveMessages({ messages, memoryConfig, observabilityContext, embeddedMessages }) {
|
|
49296
49347
|
const span = this.createMemorySpan("save", observabilityContext, void 0, { messageCount: messages.length });
|
|
49297
49348
|
try {
|
|
49298
49349
|
const updatedMessages = this.prepareMessagesForPersistence(messages);
|
|
49299
49350
|
const config = this.getMergedThreadConfig(memoryConfig);
|
|
49300
49351
|
const dbMessages = new MessageList({ generateMessageId: () => this.generateId() }).add(updatedMessages, "memory").get.all.db();
|
|
49301
|
-
const
|
|
49302
|
-
const
|
|
49303
|
-
|
|
49304
|
-
|
|
49305
|
-
|
|
49306
|
-
|
|
49307
|
-
if (message.threadId) {
|
|
49308
|
-
if (!messagesByThread.has(message.threadId)) messagesByThread.set(message.threadId, []);
|
|
49309
|
-
messagesByThread.get(message.threadId).push(message);
|
|
49310
|
-
}
|
|
49311
|
-
});
|
|
49312
|
-
const threadMetadataMap = /* @__PURE__ */ new Map();
|
|
49313
|
-
await Promise.all(Array.from(messagesByThread.keys()).map(async (threadId) => {
|
|
49314
|
-
try {
|
|
49315
|
-
const thread = await memoryStore.getThreadById({ threadId });
|
|
49316
|
-
if (thread?.metadata) threadMetadataMap.set(threadId, thread.metadata);
|
|
49317
|
-
} catch (error) {
|
|
49318
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
49319
|
-
throw new Error(`Could not fetch metadata for thread ${threadId} while saving semantic recall embeddings: ${message}`);
|
|
49320
|
-
}
|
|
49321
|
-
}));
|
|
49322
|
-
const embeddingData = [];
|
|
49323
|
-
let dimension;
|
|
49324
|
-
await Promise.all(updatedMessages.map(async (message) => {
|
|
49325
|
-
let textForEmbedding = null;
|
|
49326
|
-
if (message.content.content && typeof message.content.content === "string" && message.content.content.trim() !== "") textForEmbedding = message.content.content;
|
|
49327
|
-
else if (message.content.parts && message.content.parts.length > 0) {
|
|
49328
|
-
const joined = message.content.parts.filter((part) => part.type === "text").map((part) => part.text).join(" ").trim();
|
|
49329
|
-
if (joined) textForEmbedding = joined;
|
|
49330
|
-
}
|
|
49331
|
-
if (!textForEmbedding) return;
|
|
49332
|
-
let embeddings = [];
|
|
49333
|
-
let documents;
|
|
49334
|
-
let chunks;
|
|
49335
|
-
if (this.isSelfEmbedding) {
|
|
49336
|
-
chunks = this.chunkText(textForEmbedding);
|
|
49337
|
-
documents = chunks;
|
|
49338
|
-
} else {
|
|
49339
|
-
const result = await this.embedMessageContent(textForEmbedding);
|
|
49340
|
-
dimension = result.dimension;
|
|
49341
|
-
if (result.usage?.tokens) totalTokens += result.usage.tokens;
|
|
49342
|
-
embeddings = result.embeddings;
|
|
49343
|
-
chunks = result.chunks;
|
|
49344
|
-
}
|
|
49345
|
-
const threadMetadata = message.threadId ? threadMetadataMap.get(message.threadId) || {} : {};
|
|
49346
|
-
embeddingData.push({
|
|
49347
|
-
embeddings,
|
|
49348
|
-
documents,
|
|
49349
|
-
metadata: chunks.map(() => ({
|
|
49350
|
-
...threadMetadata,
|
|
49351
|
-
message_id: message.id,
|
|
49352
|
-
thread_id: message.threadId,
|
|
49353
|
-
resource_id: message.resourceId,
|
|
49354
|
-
role: message.role,
|
|
49355
|
-
content: textForEmbedding,
|
|
49356
|
-
created_at: message.createdAt instanceof Date ? message.createdAt.toISOString() : String(message.createdAt)
|
|
49357
|
-
}))
|
|
49358
|
-
});
|
|
49359
|
-
}));
|
|
49360
|
-
if (embeddingData.length > 0 && (this.isSelfEmbedding || dimension !== void 0)) {
|
|
49361
|
-
if (typeof this.vector === `undefined`) throw new Error(`Tried to upsert embeddings but this Memory instance doesn't have an attached vector db.`);
|
|
49362
|
-
const { indexName } = await this.createEmbeddingIndex(dimension, config);
|
|
49363
|
-
const allVectors = [];
|
|
49364
|
-
const allMetadata = [];
|
|
49365
|
-
const allDocuments = [];
|
|
49366
|
-
for (const data of embeddingData) {
|
|
49367
|
-
allVectors.push(...data.embeddings);
|
|
49368
|
-
if (data.documents) allDocuments.push(...data.documents);
|
|
49369
|
-
allMetadata.push(...data.metadata);
|
|
49370
|
-
}
|
|
49371
|
-
if (this.isSelfEmbedding) await this.vector.upsert({
|
|
49372
|
-
indexName,
|
|
49373
|
-
documents: allDocuments,
|
|
49374
|
-
metadata: allMetadata
|
|
49375
|
-
});
|
|
49376
|
-
else await this.vector.upsert({
|
|
49377
|
-
indexName,
|
|
49378
|
-
vectors: allVectors,
|
|
49379
|
-
metadata: allMetadata
|
|
49380
|
-
});
|
|
49381
|
-
}
|
|
49382
|
-
}
|
|
49352
|
+
const result = await (await this.getMemoryStore()).saveMessages({ messages: dbMessages });
|
|
49353
|
+
const usage = this.vector && config.semanticRecall ? await this.writeMessageVectors({
|
|
49354
|
+
items: updatedMessages.map((message) => ({ message })),
|
|
49355
|
+
config,
|
|
49356
|
+
embeddedMessages
|
|
49357
|
+
}) : void 0;
|
|
49383
49358
|
const saveResult = {
|
|
49384
49359
|
...result,
|
|
49385
|
-
usage
|
|
49360
|
+
usage
|
|
49386
49361
|
};
|
|
49387
49362
|
span?.end({
|
|
49388
49363
|
output: { success: true },
|
|
@@ -50105,51 +50080,6 @@ Notes:
|
|
|
50105
50080
|
return collected;
|
|
50106
50081
|
}
|
|
50107
50082
|
/**
|
|
50108
|
-
* Index a list of messages directly (without querying storage).
|
|
50109
|
-
* Used by observe-time indexing to vectorize newly-observed messages.
|
|
50110
|
-
*/
|
|
50111
|
-
async indexMessagesList(messages) {
|
|
50112
|
-
if (!this.vector || !this.embedder) return;
|
|
50113
|
-
const embeddingData = [];
|
|
50114
|
-
let dimension;
|
|
50115
|
-
await Promise.all(messages.map(async (message) => {
|
|
50116
|
-
let textForEmbedding = null;
|
|
50117
|
-
if (message.content.content && typeof message.content.content === "string" && message.content.content.trim() !== "") textForEmbedding = message.content.content;
|
|
50118
|
-
else if (message.content.parts && message.content.parts.length > 0) {
|
|
50119
|
-
const joined = message.content.parts.filter((part) => part.type === "text").map((part) => part.text).join(" ").trim();
|
|
50120
|
-
if (joined) textForEmbedding = joined;
|
|
50121
|
-
}
|
|
50122
|
-
if (!textForEmbedding) return;
|
|
50123
|
-
const embedResult = await this.embedMessageContent(textForEmbedding);
|
|
50124
|
-
dimension = embedResult.dimension;
|
|
50125
|
-
embeddingData.push({
|
|
50126
|
-
embeddings: embedResult.embeddings,
|
|
50127
|
-
metadata: embedResult.chunks.map(() => ({
|
|
50128
|
-
message_id: message.id,
|
|
50129
|
-
thread_id: message.threadId,
|
|
50130
|
-
resource_id: message.resourceId,
|
|
50131
|
-
role: message.role,
|
|
50132
|
-
content: textForEmbedding,
|
|
50133
|
-
created_at: message.createdAt instanceof Date ? message.createdAt.toISOString() : String(message.createdAt)
|
|
50134
|
-
}))
|
|
50135
|
-
});
|
|
50136
|
-
}));
|
|
50137
|
-
if (embeddingData.length > 0 && dimension !== void 0) {
|
|
50138
|
-
const { indexName } = await this.createEmbeddingIndex(dimension);
|
|
50139
|
-
const allVectors = [];
|
|
50140
|
-
const allMetadata = [];
|
|
50141
|
-
for (const data of embeddingData) {
|
|
50142
|
-
allVectors.push(...data.embeddings);
|
|
50143
|
-
allMetadata.push(...data.metadata);
|
|
50144
|
-
}
|
|
50145
|
-
await this.vector.upsert({
|
|
50146
|
-
indexName,
|
|
50147
|
-
vectors: allVectors,
|
|
50148
|
-
metadata: allMetadata
|
|
50149
|
-
});
|
|
50150
|
-
}
|
|
50151
|
-
}
|
|
50152
|
-
/**
|
|
50153
50083
|
* Check whether retrieval search (vector-based) is enabled.
|
|
50154
50084
|
* Returns true when `retrieval: { vector: true }` and Memory has a vector store plus either an
|
|
50155
50085
|
* embedder or a store that generates embeddings itself.
|
|
@@ -50255,43 +50185,19 @@ Notes:
|
|
|
50255
50185
|
const messagesWithTextUpdates = [...textForEmbeddingById.keys()].map((id) => ({ id }));
|
|
50256
50186
|
if (messagesWithTextUpdates.length > 0) {
|
|
50257
50187
|
const existingMessagesMap = new Map(existing.messages.map((m) => [m.id, m]));
|
|
50258
|
-
const
|
|
50259
|
-
|
|
50260
|
-
const
|
|
50261
|
-
|
|
50262
|
-
|
|
50263
|
-
|
|
50264
|
-
|
|
50265
|
-
|
|
50266
|
-
|
|
50267
|
-
|
|
50268
|
-
|
|
50269
|
-
|
|
50270
|
-
|
|
50271
|
-
chunks = this.chunkText(textForEmbedding);
|
|
50272
|
-
documents = chunks;
|
|
50273
|
-
} else {
|
|
50274
|
-
const result = await this.embedMessageContent(textForEmbedding);
|
|
50275
|
-
dimension = result.dimension;
|
|
50276
|
-
embeddings = result.embeddings;
|
|
50277
|
-
chunks = result.chunks;
|
|
50278
|
-
}
|
|
50279
|
-
embeddingData.push({
|
|
50280
|
-
embeddings,
|
|
50281
|
-
documents,
|
|
50282
|
-
metadata: chunks.map(() => ({
|
|
50283
|
-
message_id: message.id,
|
|
50284
|
-
thread_id: existingMessage.threadId,
|
|
50285
|
-
resource_id: existingMessage.resourceId,
|
|
50286
|
-
role: existingMessage.role,
|
|
50287
|
-
content: textForEmbedding,
|
|
50288
|
-
created_at: existingMessage.createdAt instanceof Date ? existingMessage.createdAt.toISOString() : String(existingMessage.createdAt)
|
|
50289
|
-
}))
|
|
50290
|
-
});
|
|
50291
|
-
messageIdsWithNewEmbeddings.add(message.id);
|
|
50292
|
-
} else messageIdsWithClearedContent.add(message.id);
|
|
50293
|
-
}));
|
|
50294
|
-
const messageIdsNeedingDeletion = /* @__PURE__ */ new Set([...messageIdsWithClearedContent, ...messageIdsWithNewEmbeddings]);
|
|
50188
|
+
const messageIdsNeedingDeletion = /* @__PURE__ */ new Set();
|
|
50189
|
+
const items = [];
|
|
50190
|
+
for (const { id } of messagesWithTextUpdates) {
|
|
50191
|
+
const existingMessage = existingMessagesMap.get(id);
|
|
50192
|
+
if (!existingMessage) continue;
|
|
50193
|
+
messageIdsNeedingDeletion.add(id);
|
|
50194
|
+
const text = textForEmbeddingById.get(id);
|
|
50195
|
+
if (text) items.push({
|
|
50196
|
+
message: existingMessage,
|
|
50197
|
+
text
|
|
50198
|
+
});
|
|
50199
|
+
}
|
|
50200
|
+
const rows = await this.buildMessageVectorRows({ items });
|
|
50295
50201
|
if (messageIdsNeedingDeletion.size > 0) try {
|
|
50296
50202
|
const memoryIndexes = await this.getMemoryVectorIndexes([this.messageIndexPrefix]);
|
|
50297
50203
|
const idsToDelete = [...messageIdsNeedingDeletion];
|
|
@@ -50314,27 +50220,10 @@ Notes:
|
|
|
50314
50220
|
} catch {
|
|
50315
50221
|
this.logger.debug("Failed to clean up old vectors during message update");
|
|
50316
50222
|
}
|
|
50317
|
-
|
|
50318
|
-
|
|
50319
|
-
|
|
50320
|
-
|
|
50321
|
-
const allDocuments = [];
|
|
50322
|
-
for (const data of embeddingData) {
|
|
50323
|
-
allVectors.push(...data.embeddings);
|
|
50324
|
-
if (data.documents) allDocuments.push(...data.documents);
|
|
50325
|
-
allMetadata.push(...data.metadata);
|
|
50326
|
-
}
|
|
50327
|
-
if (this.isSelfEmbedding) await this.vector.upsert({
|
|
50328
|
-
indexName,
|
|
50329
|
-
documents: allDocuments,
|
|
50330
|
-
metadata: allMetadata
|
|
50331
|
-
});
|
|
50332
|
-
else await this.vector.upsert({
|
|
50333
|
-
indexName,
|
|
50334
|
-
vectors: allVectors,
|
|
50335
|
-
metadata: allMetadata
|
|
50336
|
-
});
|
|
50337
|
-
}
|
|
50223
|
+
await this.writeMessageVectorRows({
|
|
50224
|
+
rows,
|
|
50225
|
+
config
|
|
50226
|
+
});
|
|
50338
50227
|
}
|
|
50339
50228
|
}
|
|
50340
50229
|
return memoryStore.updateMessages({ messages });
|
|
@@ -50599,6 +50488,7 @@ Notes:
|
|
|
50599
50488
|
threadId,
|
|
50600
50489
|
perPage: false
|
|
50601
50490
|
});
|
|
50491
|
+
const rows = await this.buildMessageVectorRows({ items: messages.map((message) => ({ message })) });
|
|
50602
50492
|
const messageIndexes = await this.getMemoryVectorIndexes([this.messageIndexPrefix]);
|
|
50603
50493
|
await Promise.all(messageIndexes.map(async (indexName) => {
|
|
50604
50494
|
await this.vector.deleteVectors({
|
|
@@ -50606,7 +50496,10 @@ Notes:
|
|
|
50606
50496
|
filter: { thread_id: threadId }
|
|
50607
50497
|
});
|
|
50608
50498
|
}));
|
|
50609
|
-
|
|
50499
|
+
await this.writeMessageVectorRows({
|
|
50500
|
+
rows,
|
|
50501
|
+
config
|
|
50502
|
+
});
|
|
50610
50503
|
} catch (error) {
|
|
50611
50504
|
this.logger.error("Failed to migrate semantic-recall vectors during thread transfer", {
|
|
50612
50505
|
threadId,
|
|
@@ -50754,67 +50647,15 @@ Notes:
|
|
|
50754
50647
|
return cloned;
|
|
50755
50648
|
}
|
|
50756
50649
|
/**
|
|
50757
|
-
* Embed cloned messages for semantic recall.
|
|
50758
|
-
*
|
|
50650
|
+
* Embed cloned messages for semantic recall. Cloned messages have new ids, so they get rows of
|
|
50651
|
+
* their own next to the source thread's rows.
|
|
50759
50652
|
*/
|
|
50760
50653
|
async embedClonedMessages(messages, config) {
|
|
50761
50654
|
if (!this.vector || !this.embedder && !this.isSelfEmbedding) return;
|
|
50762
|
-
|
|
50763
|
-
|
|
50764
|
-
|
|
50765
|
-
|
|
50766
|
-
if (message.content?.content && typeof message.content.content === "string" && message.content.content.trim() !== "") textForEmbedding = message.content.content;
|
|
50767
|
-
else if (message.content?.parts && message.content.parts.length > 0) {
|
|
50768
|
-
const joined = message.content.parts.filter((part) => part.type === "text").map((part) => part.text).join(" ").trim();
|
|
50769
|
-
if (joined) textForEmbedding = joined;
|
|
50770
|
-
}
|
|
50771
|
-
if (!textForEmbedding) return;
|
|
50772
|
-
let embeddings = [];
|
|
50773
|
-
let documents;
|
|
50774
|
-
let chunks;
|
|
50775
|
-
if (this.isSelfEmbedding) {
|
|
50776
|
-
chunks = this.chunkText(textForEmbedding);
|
|
50777
|
-
documents = chunks;
|
|
50778
|
-
} else {
|
|
50779
|
-
const result = await this.embedMessageContent(textForEmbedding);
|
|
50780
|
-
dimension = result.dimension;
|
|
50781
|
-
embeddings = result.embeddings;
|
|
50782
|
-
chunks = result.chunks;
|
|
50783
|
-
}
|
|
50784
|
-
embeddingData.push({
|
|
50785
|
-
embeddings,
|
|
50786
|
-
documents,
|
|
50787
|
-
metadata: chunks.map(() => ({
|
|
50788
|
-
message_id: message.id,
|
|
50789
|
-
thread_id: message.threadId,
|
|
50790
|
-
resource_id: message.resourceId,
|
|
50791
|
-
role: message.role,
|
|
50792
|
-
content: textForEmbedding,
|
|
50793
|
-
created_at: message.createdAt instanceof Date ? message.createdAt.toISOString() : String(message.createdAt)
|
|
50794
|
-
}))
|
|
50795
|
-
});
|
|
50796
|
-
}));
|
|
50797
|
-
if (embeddingData.length > 0 && (this.isSelfEmbedding || dimension !== void 0)) {
|
|
50798
|
-
const { indexName } = await this.createEmbeddingIndex(dimension, config);
|
|
50799
|
-
const allVectors = [];
|
|
50800
|
-
const allMetadata = [];
|
|
50801
|
-
const allDocuments = [];
|
|
50802
|
-
for (const data of embeddingData) {
|
|
50803
|
-
allVectors.push(...data.embeddings);
|
|
50804
|
-
if (data.documents) allDocuments.push(...data.documents);
|
|
50805
|
-
allMetadata.push(...data.metadata);
|
|
50806
|
-
}
|
|
50807
|
-
if (this.isSelfEmbedding) await this.vector.upsert({
|
|
50808
|
-
indexName,
|
|
50809
|
-
documents: allDocuments,
|
|
50810
|
-
metadata: allMetadata
|
|
50811
|
-
});
|
|
50812
|
-
else await this.vector.upsert({
|
|
50813
|
-
indexName,
|
|
50814
|
-
vectors: allVectors,
|
|
50815
|
-
metadata: allMetadata
|
|
50816
|
-
});
|
|
50817
|
-
}
|
|
50655
|
+
await this.writeMessageVectors({
|
|
50656
|
+
items: messages.map((message) => ({ message })),
|
|
50657
|
+
config
|
|
50658
|
+
});
|
|
50818
50659
|
}
|
|
50819
50660
|
/**
|
|
50820
50661
|
* Get the clone metadata from a thread if it was cloned from another thread.
|
|
@@ -52105,7 +51946,7 @@ const createModelInstance = async (provider, modelId, version = "v2") => {
|
|
|
52105
51946
|
try {
|
|
52106
51947
|
const providerFn = version === `v1` ? { v1: {
|
|
52107
51948
|
openai: async () => {
|
|
52108
|
-
const { openai } = await import("./dist-
|
|
51949
|
+
const { openai } = await import("./dist-CQGBYe6U.js");
|
|
52109
51950
|
return openai(modelId);
|
|
52110
51951
|
},
|
|
52111
51952
|
anthropic: async () => {
|
|
@@ -59861,4 +59702,4 @@ function createAgentBuilderWorkflows() {
|
|
|
59861
59702
|
}
|
|
59862
59703
|
export { require_tiff as a, require_png as c, createAgentBuilderWorkflows, require_gif as d, require_bmp as f, require_webp as i, require_jpeg as l, require_utils as m, openai as n, require_svg as o, require_avif as p, require_sync as r, require_psd as s, createOpenAI as t, require_ico as u };
|
|
59863
59704
|
|
|
59864
|
-
//# sourceMappingURL=dist-
|
|
59705
|
+
//# sourceMappingURL=dist-CXxA_Jnu.js.map
|