@mastra/server 1.74.0 → 1.75.0-alpha.1

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.
Files changed (65) hide show
  1. package/dist/{api-schema-manifest-BmraF-WX.js → api-schema-manifest-Cg5BAmJ6.js} +2 -2
  2. package/dist/{api-schema-manifest-BmraF-WX.js.map → api-schema-manifest-Cg5BAmJ6.js.map} +1 -1
  3. package/dist/{api-schema-manifest-Blh5-4VH.cjs → api-schema-manifest-hJw56vOw.cjs} +2 -2
  4. package/dist/{api-schema-manifest-Blh5-4VH.cjs.map → api-schema-manifest-hJw56vOw.cjs.map} +1 -1
  5. package/dist/{dist-D-O086vY.js → dist-BKGwFBci.js} +152 -45
  6. package/dist/{dist-D-O086vY.js.map → dist-BKGwFBci.js.map} +1 -1
  7. package/dist/{dist-BACW0Que.cjs → dist-DL6nu99w.cjs} +152 -45
  8. package/dist/{dist-BACW0Que.cjs.map → dist-DL6nu99w.cjs.map} +1 -1
  9. package/dist/docs/SKILL.md +1 -1
  10. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  11. package/dist/{routes-CcjyQojv.cjs → routes-mJga4N4C.cjs} +2 -2
  12. package/dist/{routes-CcjyQojv.cjs.map → routes-mJga4N4C.cjs.map} +1 -1
  13. package/dist/{routes-Boe1UThy.js → routes-obDo67aE.js} +2 -2
  14. package/dist/{routes-Boe1UThy.js.map → routes-obDo67aE.js.map} +1 -1
  15. package/dist/server/handlers/agent-builder.cjs +1 -1
  16. package/dist/server/handlers/agent-builder.js +1 -1
  17. package/dist/server/handlers/agent-controller.cjs +1 -1
  18. package/dist/server/handlers/agent-controller.js +1 -1
  19. package/dist/server/handlers/agents.cjs +17 -1
  20. package/dist/server/handlers/agents.cjs.map +1 -1
  21. package/dist/server/handlers/agents.d.ts.map +1 -1
  22. package/dist/server/handlers/agents.js +17 -1
  23. package/dist/server/handlers/agents.js.map +1 -1
  24. package/dist/server/handlers/conversations.cjs +1 -1
  25. package/dist/server/handlers/conversations.js +1 -1
  26. package/dist/server/handlers/logs.cjs +1 -1
  27. package/dist/server/handlers/logs.js +1 -1
  28. package/dist/server/handlers/memory.cjs +1 -1
  29. package/dist/server/handlers/memory.js +1 -1
  30. package/dist/server/handlers/plans.cjs +1 -1
  31. package/dist/server/handlers/plans.js +1 -1
  32. package/dist/server/handlers/responses.adapter.cjs +3 -2
  33. package/dist/server/handlers/responses.adapter.cjs.map +1 -1
  34. package/dist/server/handlers/responses.adapter.d.ts.map +1 -1
  35. package/dist/server/handlers/responses.adapter.js +3 -2
  36. package/dist/server/handlers/responses.adapter.js.map +1 -1
  37. package/dist/server/handlers/responses.cjs +1 -1
  38. package/dist/server/handlers/responses.js +1 -1
  39. package/dist/server/handlers/responses.storage.cjs +1 -1
  40. package/dist/server/handlers/responses.storage.js +1 -1
  41. package/dist/server/handlers/system.cjs +1 -1
  42. package/dist/server/handlers/system.js +1 -1
  43. package/dist/server/handlers/tools.cjs +1 -1
  44. package/dist/server/handlers/tools.js +1 -1
  45. package/dist/server/handlers/utils.cjs +2 -1
  46. package/dist/server/handlers/utils.d.ts +6 -0
  47. package/dist/server/handlers/utils.d.ts.map +1 -1
  48. package/dist/server/handlers/utils.js +2 -2
  49. package/dist/server/handlers/workflow-builder.cjs +1 -1
  50. package/dist/server/handlers/workflow-builder.js +1 -1
  51. package/dist/server/handlers/workflows.cjs +1 -1
  52. package/dist/server/handlers/workflows.js +1 -1
  53. package/dist/server/server-adapter/index.cjs +1 -1
  54. package/dist/server/server-adapter/index.js +1 -1
  55. package/dist/{utils-aIu3gkhJ.cjs → utils-HqDZJwRc.cjs} +31 -1
  56. package/dist/utils-HqDZJwRc.cjs.map +1 -0
  57. package/dist/{utils-KsERfbhc.js → utils-KcHk7C0D.js} +26 -2
  58. package/dist/utils-KcHk7C0D.js.map +1 -0
  59. package/dist/{workflow-builder-DTcM8ER3.cjs → workflow-builder-BSjQJCVD.cjs} +2 -2
  60. package/dist/{workflow-builder-DTcM8ER3.cjs.map → workflow-builder-BSjQJCVD.cjs.map} +1 -1
  61. package/dist/{workflow-builder-KRSpDol2.js → workflow-builder-DJ48IzXQ.js} +2 -2
  62. package/dist/{workflow-builder-KRSpDol2.js.map → workflow-builder-DJ48IzXQ.js.map} +1 -1
  63. package/package.json +6 -6
  64. package/dist/utils-KsERfbhc.js.map +0 -1
  65. package/dist/utils-aIu3gkhJ.cjs.map +0 -1
@@ -4637,7 +4637,7 @@ function splitLines(text) {
4637
4637
  return result;
4638
4638
  }
4639
4639
  //#endregion
4640
- //#region ../memory/dist/src-CPCWMt3d.js
4640
+ //#region ../memory/dist/src-CFTlELNa.js
4641
4641
  var __defProp$3 = Object.defineProperty;
4642
4642
  var __exportAll = (all, no_symbols) => {
4643
4643
  let target = {};
@@ -30498,8 +30498,23 @@ function getOpenAIPromptCacheRetention(providerOptions) {
30498
30498
  const openaiOptions = providerOptions?.openai;
30499
30499
  return typeof openaiOptions?.promptCacheRetention === "string" ? openaiOptions.promptCacheRetention.toLowerCase() : void 0;
30500
30500
  }
30501
+ function isActivationTTLMap(activateAfterIdle) {
30502
+ return typeof activateAfterIdle === "object" && activateAfterIdle !== null;
30503
+ }
30504
+ /** The configured TTL for marker payloads. Per-provider maps are omitted; markers only carry scalar values. */
30505
+ function getMarkerActivationTTL(activateAfterIdle) {
30506
+ return isActivationTTLMap(activateAfterIdle) ? void 0 : activateAfterIdle;
30507
+ }
30508
+ /** A map entry applies when its key equals the model's provider before the first `.`, lowercased. */
30509
+ function resolveActivationTTLMapEntry(activateAfterIdle, modelContext) {
30510
+ const providerKey = normalize(modelContext?.provider).split(".")[0];
30511
+ if (providerKey && Object.hasOwn(activateAfterIdle.providers, providerKey)) return activateAfterIdle.providers[providerKey];
30512
+ return activateAfterIdle.default;
30513
+ }
30501
30514
  function resolveActivationTTL(activateAfterIdle, modelContext) {
30502
- if (activateAfterIdle !== "auto") return activateAfterIdle;
30515
+ const ttl = isActivationTTLMap(activateAfterIdle) ? resolveActivationTTLMapEntry(activateAfterIdle, modelContext) : activateAfterIdle;
30516
+ if (ttl === void 0 || ttl === false) return;
30517
+ if (ttl !== "auto") return ttl;
30503
30518
  return resolveAutoActivationTTL(modelContext);
30504
30519
  }
30505
30520
  function resolveAutoActivationTTL(modelContext) {
@@ -33273,7 +33288,7 @@ var ReflectorRunner = class {
33273
33288
  messageTokens: getMaxThreshold(this.observationConfig.messageTokens),
33274
33289
  observationTokens: getMaxThreshold(record ? this.getEffectiveReflectionTokens(record) : this.reflectionConfig.observationTokens),
33275
33290
  scope: this.scope,
33276
- activateAfterIdle: this.reflectionConfig.activateAfterIdle
33291
+ activateAfterIdle: getMarkerActivationTTL(this.reflectionConfig.activateAfterIdle)
33277
33292
  };
33278
33293
  }
33279
33294
  /**
@@ -33704,7 +33719,7 @@ var ReflectorRunner = class {
33704
33719
  currentModel: activationMetadata?.currentModel,
33705
33720
  config: {
33706
33721
  ...this.getObservationMarkerConfig(freshRecord),
33707
- activateAfterIdle: activationMetadata?.activateAfterIdle ?? this.reflectionConfig.activateAfterIdle
33722
+ activateAfterIdle: activationMetadata?.activateAfterIdle ?? getMarkerActivationTTL(this.reflectionConfig.activateAfterIdle)
33708
33723
  }
33709
33724
  });
33710
33725
  writer.custom({
@@ -34389,6 +34404,32 @@ function parseActivationTTL(value, fieldPath) {
34389
34404
  if (!Number.isFinite(amount) || amount < 0) throw new Error(`${fieldPath} must be a non-negative number of milliseconds or a duration string like "5m".`);
34390
34405
  return amount * (unit === "ms" || unit === "msec" || unit === "msecs" || unit === "millisecond" || unit === "milliseconds" ? 1 : unit === "s" || unit === "sec" || unit === "secs" || unit === "second" || unit === "seconds" ? 1e3 : unit === "m" || unit === "min" || unit === "mins" || unit === "minute" || unit === "minutes" ? 6e4 : 36e5);
34391
34406
  }
34407
+ /**
34408
+ * Parse an `activateAfterIdle` config value: a scalar TTL, or a per-provider map
34409
+ * like `{ default: 'auto', anthropic: '1h' }`.
34410
+ */
34411
+ function parseActivationTTLConfig(value, fieldPath) {
34412
+ if (typeof value !== "object") return parseActivationTTL(value, fieldPath);
34413
+ if (value === null || Array.isArray(value)) throw new Error(`${fieldPath} must be a TTL value or an object of per-provider TTLs, e.g. { default: 'auto', anthropic: '1h' }.`);
34414
+ const entries = Object.entries(value).filter(([, entryValue]) => entryValue !== void 0);
34415
+ if (entries.length === 0) throw new Error(`${fieldPath} must set at least one provider or "default" when using per-provider TTLs, e.g. { default: 'auto', anthropic: '1h' }.`);
34416
+ const parsed = { providers: Object.create(null) };
34417
+ const seenKeys = /* @__PURE__ */ new Set();
34418
+ for (const [rawKey, entryValue] of entries) {
34419
+ const key = rawKey.trim().toLowerCase();
34420
+ const entryPath = `${fieldPath}.${rawKey}`;
34421
+ if (!key) throw new Error(`${fieldPath} contains an empty provider key.`);
34422
+ if (key.includes(".") || key.includes("/")) throw new Error(`${entryPath} is not a valid provider key. Use the provider name before the first ".", e.g. "anthropic" instead of "anthropic.messages".`);
34423
+ if (seenKeys.has(key)) throw new Error(`${entryPath} duplicates another key in ${fieldPath}. Provider keys are case-insensitive.`);
34424
+ seenKeys.add(key);
34425
+ if (entryValue !== false && typeof entryValue !== "number" && typeof entryValue !== "string") throw new Error(`${entryPath} must be a non-negative number of milliseconds, a duration string like "5m" or "1hr", "auto", or false.`);
34426
+ const ttl = entryValue === false ? false : parseActivationTTL(entryValue, entryPath);
34427
+ if (key === "default") {
34428
+ if (ttl !== false) parsed.default = ttl;
34429
+ } else parsed.providers[key] = ttl;
34430
+ }
34431
+ return parsed;
34432
+ }
34392
34433
  let hasWarnedResourceScopeDeprecation = false;
34393
34434
  /**
34394
34435
  * ObservationalMemory - A three-agent memory system for long conversations.
@@ -34603,7 +34644,7 @@ var ObservationalMemory = class ObservationalMemory {
34603
34644
  bufferTokens: asyncBufferingDisabled ? void 0 : resolveBufferTokens(config.observation?.bufferTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.bufferTokens, config.observation?.messageTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.messageTokens),
34604
34645
  bufferOnIdle: config.observation?.bufferOnIdle ?? false,
34605
34646
  bufferActivation: asyncBufferingDisabled ? void 0 : config.observation?.bufferActivation ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.bufferActivation,
34606
- activateAfterIdle: parseActivationTTL(observationActivateAfterIdle, observationActivateAfterIdlePath),
34647
+ activateAfterIdle: parseActivationTTLConfig(observationActivateAfterIdle, observationActivateAfterIdlePath),
34607
34648
  activateOnProviderChange: config.observation?.activateOnProviderChange ?? config.activateOnProviderChange ?? false,
34608
34649
  blockAfter: asyncBufferingDisabled ? void 0 : resolveBlockAfter(config.observation?.blockAfter ?? (config.observation?.bufferTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.bufferTokens ? 1.2 : void 0), config.observation?.messageTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.messageTokens),
34609
34650
  previousObserverTokens: config.observation?.previousObserverTokens ?? 2e3,
@@ -34628,7 +34669,7 @@ var ObservationalMemory = class ObservationalMemory {
34628
34669
  },
34629
34670
  providerOptions: config.reflection?.providerOptions ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.providerOptions,
34630
34671
  bufferActivation: asyncBufferingDisabled ? void 0 : config?.reflection?.bufferActivation ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.bufferActivation,
34631
- activateAfterIdle: parseActivationTTL(config.reflection?.activateAfterIdle, "reflection.activateAfterIdle"),
34672
+ activateAfterIdle: parseActivationTTLConfig(config.reflection?.activateAfterIdle, "reflection.activateAfterIdle"),
34632
34673
  activateOnProviderChange: config.reflection?.activateOnProviderChange ?? false,
34633
34674
  blockAfter: asyncBufferingDisabled ? void 0 : resolveBlockAfter(config.reflection?.blockAfter ?? (config.reflection?.bufferActivation ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.bufferActivation ? 1.2 : void 0), config.reflection?.observationTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.observationTokens),
34634
34675
  instruction: config.reflection?.instruction,
@@ -34954,7 +34995,7 @@ var ObservationalMemory = class ObservationalMemory {
34954
34995
  messageTokens: getMaxThreshold(this.observationConfig.messageTokens),
34955
34996
  observationTokens: getMaxThreshold(this.reflectionConfig.observationTokens),
34956
34997
  scope: this.scope,
34957
- activateAfterIdle: this.observationConfig.activateAfterIdle
34998
+ activateAfterIdle: getMarkerActivationTTL(this.observationConfig.activateAfterIdle)
34958
34999
  };
34959
35000
  }
34960
35001
  /**
@@ -36355,7 +36396,7 @@ ${formattedMessages}
36355
36396
  currentModel,
36356
36397
  config: {
36357
36398
  ...this.getObservationMarkerConfig(),
36358
- activateAfterIdle: activationActivateAfterIdle ?? this.observationConfig.activateAfterIdle
36399
+ activateAfterIdle: activationActivateAfterIdle ?? getMarkerActivationTTL(this.observationConfig.activateAfterIdle)
36359
36400
  }
36360
36401
  });
36361
36402
  opts.writer.custom({
@@ -37641,22 +37682,32 @@ var Memory = class Memory extends _mastra_core_memory.MastraMemory {
37641
37682
  if (resourceScope && !resourceId && config?.semanticRecall && vectorSearchString) throw new Error("Memory error: Resource-scoped semantic recall is enabled but no resourceId was provided. Either provide a resourceId or explicitly set semanticRecall.scope to 'thread'.");
37642
37683
  let usage;
37643
37684
  if (config?.semanticRecall && vectorSearchString && this.vector) {
37644
- const result = await this.embedMessageContent(vectorSearchString);
37645
- usage = result.usage;
37646
- const { embeddings, dimension } = result;
37647
- const { indexName } = await this.createEmbeddingIndex(dimension, config);
37648
- await Promise.all(embeddings.map(async (embedding) => {
37649
- if (typeof this.vector === `undefined`) throw new Error(`Tried to query vector index ${indexName} but this Memory instance doesn't have an attached vector db.`);
37650
- const scopeFilter = resourceScope ? { resource_id: resourceId } : { thread_id: threadId };
37651
- const userFilter = typeof config.semanticRecall === "object" ? config.semanticRecall.filter : void 0;
37652
- const combinedFilter = userFilter ? { $and: [scopeFilter, userFilter] } : scopeFilter;
37685
+ const scopeFilter = resourceScope ? { resource_id: resourceId } : { thread_id: threadId };
37686
+ const userFilter = typeof config.semanticRecall === "object" ? config.semanticRecall.filter : void 0;
37687
+ const combinedFilter = userFilter ? { $and: [scopeFilter, userFilter] } : scopeFilter;
37688
+ if (this.isSelfEmbedding) {
37689
+ const { indexName } = await this.createEmbeddingIndex(void 0, config);
37653
37690
  vectorResults.push(...await this.vector.query({
37654
37691
  indexName,
37655
- queryVector: embedding,
37692
+ queryText: vectorSearchString,
37656
37693
  topK: vectorConfig.topK,
37657
37694
  filter: combinedFilter
37658
37695
  }));
37659
- }));
37696
+ } else {
37697
+ const result = await this.embedMessageContent(vectorSearchString);
37698
+ usage = result.usage;
37699
+ const { embeddings, dimension } = result;
37700
+ const { indexName } = await this.createEmbeddingIndex(dimension, config);
37701
+ await Promise.all(embeddings.map(async (embedding) => {
37702
+ if (typeof this.vector === `undefined`) throw new Error(`Tried to query vector index ${indexName} but this Memory instance doesn't have an attached vector db.`);
37703
+ vectorResults.push(...await this.vector.query({
37704
+ indexName,
37705
+ queryVector: embedding,
37706
+ topK: vectorConfig.topK,
37707
+ filter: combinedFilter
37708
+ }));
37709
+ }));
37710
+ }
37660
37711
  }
37661
37712
  const threshold = (typeof config.semanticRecall === "object" ? config.semanticRecall : void 0)?.threshold;
37662
37713
  const filteredVectorResults = threshold !== void 0 ? vectorResults.filter((r) => r.score >= threshold) : vectorResults;
@@ -37814,11 +37865,13 @@ var Memory = class Memory extends _mastra_core_memory.MastraMemory {
37814
37865
  if (this.vector) this.trackVectorCleanup(this.deleteThreadVectors(threadId));
37815
37866
  }
37816
37867
  /**
37817
- * Prefix shared by every message index. The index for the default embedding
37818
- * dimension is named with the bare prefix; other dimensions add a suffix.
37868
+ * Prefix shared by every message index. The index for the default embedding dimension is named
37869
+ * with the bare prefix; other dimensions add a dimension suffix, and a store that embeds the
37870
+ * text itself adds its own. Built here rather than read from `getEmbeddingIndexName()`, which
37871
+ * answers for one configuration and so would not match indexes written under another.
37819
37872
  */
37820
37873
  get messageIndexPrefix() {
37821
- return this.getEmbeddingIndexName();
37874
+ return `memory${this.vector?.indexSeparator ?? "_"}messages`;
37822
37875
  }
37823
37876
  /**
37824
37877
  * Prefix shared by every observation index. Each observation index adds a dimension suffix.
@@ -38103,13 +38156,24 @@ ${workingMemory}`;
38103
38156
  if (joined) textForEmbedding = joined;
38104
38157
  }
38105
38158
  if (!textForEmbedding) return;
38106
- const result = await this.embedMessageContent(textForEmbedding);
38107
- dimension = result.dimension;
38108
- if (result.usage?.tokens) totalTokens += result.usage.tokens;
38159
+ let embeddings = [];
38160
+ let documents;
38161
+ let chunks;
38162
+ if (this.isSelfEmbedding) {
38163
+ chunks = this.chunkText(textForEmbedding);
38164
+ documents = chunks;
38165
+ } else {
38166
+ const result = await this.embedMessageContent(textForEmbedding);
38167
+ dimension = result.dimension;
38168
+ if (result.usage?.tokens) totalTokens += result.usage.tokens;
38169
+ embeddings = result.embeddings;
38170
+ chunks = result.chunks;
38171
+ }
38109
38172
  const threadMetadata = message.threadId ? threadMetadataMap.get(message.threadId) || {} : {};
38110
38173
  embeddingData.push({
38111
- embeddings: result.embeddings,
38112
- metadata: result.chunks.map(() => ({
38174
+ embeddings,
38175
+ documents,
38176
+ metadata: chunks.map(() => ({
38113
38177
  ...threadMetadata,
38114
38178
  message_id: message.id,
38115
38179
  thread_id: message.threadId,
@@ -38120,16 +38184,23 @@ ${workingMemory}`;
38120
38184
  }))
38121
38185
  });
38122
38186
  }));
38123
- if (embeddingData.length > 0 && dimension !== void 0) {
38187
+ if (embeddingData.length > 0 && (this.isSelfEmbedding || dimension !== void 0)) {
38124
38188
  if (typeof this.vector === `undefined`) throw new Error(`Tried to upsert embeddings but this Memory instance doesn't have an attached vector db.`);
38125
38189
  const { indexName } = await this.createEmbeddingIndex(dimension, config);
38126
38190
  const allVectors = [];
38127
38191
  const allMetadata = [];
38192
+ const allDocuments = [];
38128
38193
  for (const data of embeddingData) {
38129
38194
  allVectors.push(...data.embeddings);
38195
+ if (data.documents) allDocuments.push(...data.documents);
38130
38196
  allMetadata.push(...data.metadata);
38131
38197
  }
38132
- await this.vector.upsert({
38198
+ if (this.isSelfEmbedding) await this.vector.upsert({
38199
+ indexName,
38200
+ documents: allDocuments,
38201
+ metadata: allMetadata
38202
+ });
38203
+ else await this.vector.upsert({
38133
38204
  indexName,
38134
38205
  vectors: allVectors,
38135
38206
  metadata: allMetadata
@@ -38914,11 +38985,22 @@ Notes:
38914
38985
  }
38915
38986
  }
38916
38987
  if (textForEmbedding) {
38917
- const result = await this.embedMessageContent(textForEmbedding);
38918
- dimension = result.dimension;
38988
+ let embeddings = [];
38989
+ let documents;
38990
+ let chunks;
38991
+ if (this.isSelfEmbedding) {
38992
+ chunks = this.chunkText(textForEmbedding);
38993
+ documents = chunks;
38994
+ } else {
38995
+ const result = await this.embedMessageContent(textForEmbedding);
38996
+ dimension = result.dimension;
38997
+ embeddings = result.embeddings;
38998
+ chunks = result.chunks;
38999
+ }
38919
39000
  embeddingData.push({
38920
- embeddings: result.embeddings,
38921
- metadata: result.chunks.map(() => ({
39001
+ embeddings,
39002
+ documents,
39003
+ metadata: chunks.map(() => ({
38922
39004
  message_id: message.id,
38923
39005
  thread_id: existingMessage.threadId,
38924
39006
  resource_id: existingMessage.resourceId,
@@ -38953,15 +39035,22 @@ Notes:
38953
39035
  } catch {
38954
39036
  this.logger.debug("Failed to clean up old vectors during message update");
38955
39037
  }
38956
- if (embeddingData.length > 0 && dimension !== void 0) {
39038
+ if (embeddingData.length > 0 && (this.isSelfEmbedding || dimension !== void 0)) {
38957
39039
  const { indexName } = await this.createEmbeddingIndex(dimension, config);
38958
39040
  const allVectors = [];
38959
39041
  const allMetadata = [];
39042
+ const allDocuments = [];
38960
39043
  for (const data of embeddingData) {
38961
39044
  allVectors.push(...data.embeddings);
39045
+ if (data.documents) allDocuments.push(...data.documents);
38962
39046
  allMetadata.push(...data.metadata);
38963
39047
  }
38964
- await this.vector.upsert({
39048
+ if (this.isSelfEmbedding) await this.vector.upsert({
39049
+ indexName,
39050
+ documents: allDocuments,
39051
+ metadata: allMetadata
39052
+ });
39053
+ else await this.vector.upsert({
38965
39054
  indexName,
38966
39055
  vectors: allVectors,
38967
39056
  metadata: allMetadata
@@ -39148,7 +39237,7 @@ Notes:
39148
39237
  await this.rollbackCopiedThread(memoryStore, result.thread, "OM clone", false, priorDestinationResourceWm);
39149
39238
  throw error;
39150
39239
  }
39151
- if (this.vector && this.embedder && config.semanticRecall) try {
39240
+ if (this.vector && (this.embedder || this.isSelfEmbedding) && config.semanticRecall) try {
39152
39241
  await this.embedCopiedMessagesInBatches(memoryStore, result, config);
39153
39242
  } catch (error) {
39154
39243
  await this.rollbackCopiedThread(memoryStore, result.thread, "embedding", true, priorDestinationResourceWm);
@@ -39217,7 +39306,7 @@ Notes:
39217
39306
  async updateThreadResourceId({ threadId, resourceId, memoryConfig }) {
39218
39307
  const memoryStore = await this.getMemoryStore();
39219
39308
  const config = this.getMergedThreadConfig(memoryConfig);
39220
- const migratesVectors = Boolean(this.vector && this.embedder && config.semanticRecall);
39309
+ const migratesVectors = Boolean(this.vector && (this.embedder || this.isSelfEmbedding) && config.semanticRecall);
39221
39310
  if (!migratesVectors) {
39222
39311
  const existing = await memoryStore.getThreadById({ threadId });
39223
39312
  if (existing && existing.resourceId === resourceId) return existing;
@@ -39323,7 +39412,7 @@ Notes:
39323
39412
  * This is similar to the embedding logic in saveMessages but operates on already-saved messages.
39324
39413
  */
39325
39414
  async embedClonedMessages(messages, config) {
39326
- if (!this.vector || !this.embedder) return;
39415
+ if (!this.vector || !this.embedder && !this.isSelfEmbedding) return;
39327
39416
  const embeddingData = [];
39328
39417
  let dimension;
39329
39418
  await Promise.all(messages.map(async (message) => {
@@ -39334,11 +39423,22 @@ Notes:
39334
39423
  if (joined) textForEmbedding = joined;
39335
39424
  }
39336
39425
  if (!textForEmbedding) return;
39337
- const result = await this.embedMessageContent(textForEmbedding);
39338
- dimension = result.dimension;
39426
+ let embeddings = [];
39427
+ let documents;
39428
+ let chunks;
39429
+ if (this.isSelfEmbedding) {
39430
+ chunks = this.chunkText(textForEmbedding);
39431
+ documents = chunks;
39432
+ } else {
39433
+ const result = await this.embedMessageContent(textForEmbedding);
39434
+ dimension = result.dimension;
39435
+ embeddings = result.embeddings;
39436
+ chunks = result.chunks;
39437
+ }
39339
39438
  embeddingData.push({
39340
- embeddings: result.embeddings,
39341
- metadata: result.chunks.map(() => ({
39439
+ embeddings,
39440
+ documents,
39441
+ metadata: chunks.map(() => ({
39342
39442
  message_id: message.id,
39343
39443
  thread_id: message.threadId,
39344
39444
  resource_id: message.resourceId,
@@ -39348,15 +39448,22 @@ Notes:
39348
39448
  }))
39349
39449
  });
39350
39450
  }));
39351
- if (embeddingData.length > 0 && dimension !== void 0) {
39451
+ if (embeddingData.length > 0 && (this.isSelfEmbedding || dimension !== void 0)) {
39352
39452
  const { indexName } = await this.createEmbeddingIndex(dimension, config);
39353
39453
  const allVectors = [];
39354
39454
  const allMetadata = [];
39455
+ const allDocuments = [];
39355
39456
  for (const data of embeddingData) {
39356
39457
  allVectors.push(...data.embeddings);
39458
+ if (data.documents) allDocuments.push(...data.documents);
39357
39459
  allMetadata.push(...data.metadata);
39358
39460
  }
39359
- await this.vector.upsert({
39461
+ if (this.isSelfEmbedding) await this.vector.upsert({
39462
+ indexName,
39463
+ documents: allDocuments,
39464
+ metadata: allMetadata
39465
+ });
39466
+ else await this.vector.upsert({
39360
39467
  indexName,
39361
39468
  vectors: allVectors,
39362
39469
  metadata: allMetadata
@@ -50333,4 +50440,4 @@ const agentBuilderWorkflows = {
50333
50440
  //#endregion
50334
50441
  exports.agentBuilderWorkflows = agentBuilderWorkflows;
50335
50442
 
50336
- //# sourceMappingURL=dist-BACW0Que.cjs.map
50443
+ //# sourceMappingURL=dist-DL6nu99w.cjs.map