@mastra/memory 1.41.0-alpha.1 → 1.41.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.
Files changed (66) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.d.ts +3 -2
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/processors/index.cjs +1 -1
  6. package/dist/processors/index.js +1 -1
  7. package/dist/processors/observational-memory/constants.d.ts +4 -3
  8. package/dist/processors/observational-memory/constants.d.ts.map +1 -1
  9. package/dist/{src-GDwZ0vzw.cjs → src-B4WjMcwZ.cjs} +223 -125
  10. package/dist/src-B4WjMcwZ.cjs.map +1 -0
  11. package/dist/{src-CBYx0iwC.js → src-DHH_IVZI.js} +223 -125
  12. package/dist/src-DHH_IVZI.js.map +1 -0
  13. package/dist/tools/om-tools.d.ts +17 -1
  14. package/dist/tools/om-tools.d.ts.map +1 -1
  15. package/package.json +9 -9
  16. package/dist/docs/SKILL.md +0 -72
  17. package/dist/docs/assets/SOURCE_MAP.json +0 -210
  18. package/dist/docs/references/docs-agents-human-in-the-loop.md +0 -773
  19. package/dist/docs/references/docs-agents-networks.md +0 -186
  20. package/dist/docs/references/docs-evals-evals-with-memory.md +0 -151
  21. package/dist/docs/references/docs-guides-context-engineering.md +0 -304
  22. package/dist/docs/references/docs-harness-background-tasks.md +0 -492
  23. package/dist/docs/references/docs-harness-goals.md +0 -144
  24. package/dist/docs/references/docs-memory-memory-processors.md +0 -442
  25. package/dist/docs/references/docs-memory-message-history.md +0 -424
  26. package/dist/docs/references/docs-memory-multi-user-threads.md +0 -210
  27. package/dist/docs/references/docs-memory-observational-memory.md +0 -1054
  28. package/dist/docs/references/docs-memory-overview.md +0 -305
  29. package/dist/docs/references/docs-memory-semantic-recall.md +0 -485
  30. package/dist/docs/references/docs-memory-working-memory.md +0 -450
  31. package/dist/docs/references/docs-signals-overview.md +0 -94
  32. package/dist/docs/references/docs-storage.md +0 -224
  33. package/dist/docs/references/docs-subagents.md +0 -554
  34. package/dist/docs/references/integrations-channels-github.md +0 -156
  35. package/dist/docs/references/integrations-databases-aurora-dsql.md +0 -432
  36. package/dist/docs/references/integrations-databases-dynamodb.md +0 -286
  37. package/dist/docs/references/integrations-databases-elasticsearch.md +0 -158
  38. package/dist/docs/references/integrations-databases-libsql.md +0 -161
  39. package/dist/docs/references/integrations-databases-mongodb.md +0 -269
  40. package/dist/docs/references/integrations-databases-oracledb.md +0 -241
  41. package/dist/docs/references/integrations-databases-postgresql.md +0 -592
  42. package/dist/docs/references/integrations-databases-redis.md +0 -250
  43. package/dist/docs/references/integrations-databases-upstash.md +0 -164
  44. package/dist/docs/references/integrations-databases-valkey.md +0 -103
  45. package/dist/docs/references/reference-core-getMemory.md +0 -53
  46. package/dist/docs/references/reference-core-listMemory.md +0 -59
  47. package/dist/docs/references/reference-file-based-agents-memory.md +0 -60
  48. package/dist/docs/references/reference-memory-clone-utilities.md +0 -205
  49. package/dist/docs/references/reference-memory-cloneThread.md +0 -177
  50. package/dist/docs/references/reference-memory-copyThread.md +0 -65
  51. package/dist/docs/references/reference-memory-createThread.md +0 -72
  52. package/dist/docs/references/reference-memory-getThreadById.md +0 -28
  53. package/dist/docs/references/reference-memory-listThreads.md +0 -149
  54. package/dist/docs/references/reference-memory-memory-class.md +0 -237
  55. package/dist/docs/references/reference-memory-observational-memory.md +0 -978
  56. package/dist/docs/references/reference-memory-settled.md +0 -67
  57. package/dist/docs/references/reference-memory-summarizeConversation.md +0 -101
  58. package/dist/docs/references/reference-memory-summarizeThread.md +0 -95
  59. package/dist/docs/references/reference-memory-updateThreadResourceId.md +0 -46
  60. package/dist/docs/references/reference-migrations-agentnetwork.md +0 -102
  61. package/dist/docs/references/reference-migrations-upgrade-to-v1-memory.md +0 -290
  62. package/dist/docs/references/reference-processors-token-limiter-processor.md +0 -169
  63. package/dist/src-CBYx0iwC.js.map +0 -1
  64. package/dist/src-GDwZ0vzw.cjs.map +0 -1
  65. /package/dist/_types/{@internal_ai-sdk-v4 → @internal_ai-sdk-v4@0.0.94}/dist/index.d.ts +0 -0
  66. /package/dist/_types/{@internal_ai-sdk-v4 → @internal_ai-sdk-v4@0.0.94}/package.json +0 -0
@@ -59,9 +59,9 @@ let _mastra_core_schema = require("@mastra/core/schema");
59
59
  let _mastra_core_tools = require("@mastra/core/tools");
60
60
  let diff = require("diff");
61
61
  let util = require("util");
62
- // ../_vendored/ai_v4/dist/dist-DlRWVOEI.js
62
+ // ../_vendored/ai_v4/dist/dist-BxNtn0K2.js
63
63
  var marker$21 = "vercel.ai.error";
64
- var symbol$12 = Symbol.for(marker$21);
64
+ var symbol$25 = Symbol.for(marker$21);
65
65
  var _a$7;
66
66
  var _AISDKError = class _AISDKError extends Error {
67
67
  /**
@@ -91,7 +91,7 @@ var _AISDKError = class _AISDKError extends Error {
91
91
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
92
92
  }
93
93
  };
94
- _a$7 = symbol$12;
94
+ _a$7 = symbol$25;
95
95
  var AISDKError$3 = _AISDKError;
96
96
  var name$22 = "AI_APICallError";
97
97
  var marker2$7 = `vercel.ai.error.${name$22}`;
@@ -2802,14 +2802,14 @@ var UnsupportedModelVersionError$3 = class extends AISDKError$3 {
2802
2802
  });
2803
2803
  }
2804
2804
  };
2805
- var name$15 = "AI_InvalidArgumentError";
2806
- var marker$10 = `vercel.ai.error.${name$15}`;
2807
- var symbol$25 = Symbol.for(marker$10);
2805
+ var name$21 = "AI_InvalidArgumentError";
2806
+ var marker$10 = `vercel.ai.error.${name$21}`;
2807
+ var symbol$12 = Symbol.for(marker$10);
2808
2808
  var _a$6;
2809
2809
  var InvalidArgumentError$6 = class extends AISDKError$3 {
2810
2810
  constructor({ parameter, value, message }) {
2811
2811
  super({
2812
- name: name$15,
2812
+ name: name$21,
2813
2813
  message: `Invalid argument for parameter ${parameter}: ${message}`
2814
2814
  });
2815
2815
  this[_a$6] = true;
@@ -2820,7 +2820,7 @@ var InvalidArgumentError$6 = class extends AISDKError$3 {
2820
2820
  return AISDKError$3.hasMarker(error, marker$10);
2821
2821
  }
2822
2822
  };
2823
- _a$6 = symbol$25;
2823
+ _a$6 = symbol$12;
2824
2824
  var name2$6 = "AI_RetryError";
2825
2825
  var marker2$6 = `vercel.ai.error.${name2$6}`;
2826
2826
  var symbol2$6 = Symbol.for(marker2$6);
@@ -3710,9 +3710,9 @@ function trimStartOfStream() {
3710
3710
  return text2;
3711
3711
  };
3712
3712
  }
3713
- // ../_vendored/ai_v5/dist/dist-DRvrQv6K.js
3714
- var marker$1$17 = "vercel.ai.error";
3715
- var symbol$1$17 = Symbol.for(marker$1$17);
3713
+ // ../_vendored/ai_v5/dist/dist-DSvOscpb.js
3714
+ var marker$1$16 = "vercel.ai.error";
3715
+ var symbol$1$17 = Symbol.for(marker$1$16);
3716
3716
  var _a$1$2;
3717
3717
  var _b$1$4;
3718
3718
  var AISDKError$2 = class _AISDKError extends (_b$1$4 = Error, _a$1$2 = symbol$1$17, _b$1$4) {
@@ -3736,22 +3736,22 @@ var AISDKError$2 = class _AISDKError extends (_b$1$4 = Error, _a$1$2 = symbol$1$
3736
3736
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
3737
3737
  */
3738
3738
  static isInstance(error) {
3739
- return _AISDKError.hasMarker(error, marker$1$17);
3739
+ return _AISDKError.hasMarker(error, marker$1$16);
3740
3740
  }
3741
3741
  static hasMarker(error, marker15) {
3742
3742
  const markerSymbol = Symbol.for(marker15);
3743
3743
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
3744
3744
  }
3745
3745
  };
3746
- var name$1$16 = "AI_APICallError";
3747
- var marker2$5 = `vercel.ai.error.${name$1$16}`;
3746
+ var name$1$15 = "AI_APICallError";
3747
+ var marker2$5 = `vercel.ai.error.${name$1$15}`;
3748
3748
  var symbol2$5 = Symbol.for(marker2$5);
3749
3749
  var _a2$5;
3750
3750
  var _b2$3;
3751
3751
  var APICallError$2 = class extends (_b2$3 = AISDKError$2, _a2$5 = symbol2$5, _b2$3) {
3752
3752
  constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
3753
3753
  super({
3754
- name: name$1$16,
3754
+ name: name$1$15,
3755
3755
  message,
3756
3756
  cause
3757
3757
  });
@@ -4090,15 +4090,15 @@ function createAbortError$2() {
4090
4090
  function extractResponseHeaders$2(response) {
4091
4091
  return Object.fromEntries([...response.headers]);
4092
4092
  }
4093
- var name$21 = "AI_DownloadError";
4094
- var marker$15 = `vercel.ai.error.${name$21}`;
4095
- var symbol$24 = Symbol.for(marker$15);
4093
+ var name$15 = "AI_DownloadError";
4094
+ var marker$20 = `vercel.ai.error.${name$15}`;
4095
+ var symbol$24 = Symbol.for(marker$20);
4096
4096
  var _a$5;
4097
4097
  var _b$5;
4098
4098
  var DownloadError$2 = class extends (_b$5 = AISDKError$2, _a$5 = symbol$24, _b$5) {
4099
4099
  constructor({ url, statusCode, statusText, cause, message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}` }) {
4100
4100
  super({
4101
- name: name$21,
4101
+ name: name$15,
4102
4102
  message,
4103
4103
  cause
4104
4104
  });
@@ -4108,7 +4108,7 @@ var DownloadError$2 = class extends (_b$5 = AISDKError$2, _a$5 = symbol$24, _b$5
4108
4108
  this.statusText = statusText;
4109
4109
  }
4110
4110
  static isInstance(error) {
4111
- return AISDKError$2.hasMarker(error, marker$15);
4111
+ return AISDKError$2.hasMarker(error, marker$20);
4112
4112
  }
4113
4113
  };
4114
4114
  var EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL$2 = /* @__PURE__ */ Symbol.for("vercel.ai.embeddingModel.maxInputBytesPerCall");
@@ -4271,7 +4271,7 @@ function withUserAgentSuffix$2(headers, ...userAgentSuffixParts) {
4271
4271
  normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
4272
4272
  return Object.fromEntries(normalizedHeaders.entries());
4273
4273
  }
4274
- var VERSION$8 = "3.0.42";
4274
+ var VERSION$8 = "3.0.43";
4275
4275
  var getOriginalFetch$3 = () => globalThis.fetch;
4276
4276
  var getFromApi$2 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch = getOriginalFetch$3() }) => {
4277
4277
  try {
@@ -5698,7 +5698,7 @@ var { btoa: btoa$3, atob: atob$6 } = globalThis;
5698
5698
  function withoutTrailingSlash$2(url) {
5699
5699
  return url == null ? void 0 : url.replace(/\/$/, "");
5700
5700
  }
5701
- // ../_vendored/ai_v5/dist/dist-q105Fieh.js
5701
+ // ../_vendored/ai_v5/dist/dist-I4iGGqeV.js
5702
5702
  function getContext$2() {
5703
5703
  return { headers: {} };
5704
5704
  }
@@ -5706,10 +5706,10 @@ async function getVercelOidcToken$2() {
5706
5706
  if (process.env.VERCEL_OIDC_TOKEN) return process.env.VERCEL_OIDC_TOKEN ?? "";
5707
5707
  throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
5708
5708
  }
5709
- var symbol$22 = Symbol.for("vercel.ai.gateway.error");
5709
+ var symbol$15 = Symbol.for("vercel.ai.gateway.error");
5710
5710
  var _a$4;
5711
5711
  var _b$3;
5712
- var GatewayError$2 = class _GatewayError extends (_b$3 = Error, _a$4 = symbol$22, _b$3) {
5712
+ var GatewayError$2 = class _GatewayError extends (_b$3 = Error, _a$4 = symbol$15, _b$3) {
5713
5713
  constructor({ message, statusCode = 500, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500) }) {
5714
5714
  super(message);
5715
5715
  this[_a$4] = true;
@@ -5726,7 +5726,7 @@ var GatewayError$2 = class _GatewayError extends (_b$3 = Error, _a$4 = symbol$22
5726
5726
  return _GatewayError.hasMarker(error);
5727
5727
  }
5728
5728
  static hasMarker(error) {
5729
- return typeof error === "object" && error !== null && symbol$22 in error && error[symbol$22] === true;
5729
+ return typeof error === "object" && error !== null && symbol$15 in error && error[symbol$15] === true;
5730
5730
  }
5731
5731
  };
5732
5732
  var name$10 = "GatewayAuthenticationError";
@@ -6677,7 +6677,7 @@ async function getVercelRequestId$2() {
6677
6677
  var _a10;
6678
6678
  return (_a10 = getContext$2().headers) == null ? void 0 : _a10["x-vercel-id"];
6679
6679
  }
6680
- var VERSION$7 = "2.0.173";
6680
+ var VERSION$7 = "2.0.174";
6681
6681
  var AI_GATEWAY_PROTOCOL_VERSION$2 = "0.0.1";
6682
6682
  function createGatewayProvider$1(options = {}) {
6683
6683
  var _a10, _b10;
@@ -7712,7 +7712,7 @@ function getGlobalProvider$2() {
7712
7712
  var _a17;
7713
7713
  return (_a17 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a17 : gateway$2;
7714
7714
  }
7715
- var VERSION$6 = "5.0.282";
7715
+ var VERSION$6 = "5.0.283";
7716
7716
  var dataContentSchema$1 = zod_v4.z.union([
7717
7717
  zod_v4.z.string(),
7718
7718
  zod_v4.z.instanceof(Uint8Array),
@@ -8618,12 +8618,12 @@ var object$3 = ({ schema: inputSchema }) => {
8618
8618
  }
8619
8619
  };
8620
8620
  };
8621
- // ../_vendored/ai_v6/dist/dist-Dl1sIpsh.js
8622
- var marker$1$15 = "vercel.ai.error";
8623
- var symbol$1$16 = Symbol.for(marker$1$15);
8621
+ // ../_vendored/ai_v6/dist/dist-B5EfJITb.js
8622
+ var marker$1$14 = "vercel.ai.error";
8623
+ var symbol$1$15 = Symbol.for(marker$1$14);
8624
8624
  var _a$1$1;
8625
8625
  var _b$1;
8626
- var AISDKError$1 = class _AISDKError extends (_b$1 = Error, _a$1$1 = symbol$1$16, _b$1) {
8626
+ var AISDKError$1 = class _AISDKError extends (_b$1 = Error, _a$1$1 = symbol$1$15, _b$1) {
8627
8627
  /**
8628
8628
  * Creates an AI SDK Error.
8629
8629
  *
@@ -8644,22 +8644,22 @@ var AISDKError$1 = class _AISDKError extends (_b$1 = Error, _a$1$1 = symbol$1$16
8644
8644
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
8645
8645
  */
8646
8646
  static isInstance(error) {
8647
- return _AISDKError.hasMarker(error, marker$1$15);
8647
+ return _AISDKError.hasMarker(error, marker$1$14);
8648
8648
  }
8649
8649
  static hasMarker(error, marker15) {
8650
8650
  const markerSymbol = Symbol.for(marker15);
8651
8651
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
8652
8652
  }
8653
8653
  };
8654
- var name$1$15 = "AI_APICallError";
8655
- var marker2$2 = `vercel.ai.error.${name$1$15}`;
8654
+ var name$1$14 = "AI_APICallError";
8655
+ var marker2$2 = `vercel.ai.error.${name$1$14}`;
8656
8656
  var symbol2$2 = Symbol.for(marker2$2);
8657
8657
  var _a2$2;
8658
8658
  var _b2$1;
8659
8659
  var APICallError$1 = class extends (_b2$1 = AISDKError$1, _a2$2 = symbol2$2, _b2$1) {
8660
8660
  constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
8661
8661
  super({
8662
- name: name$1$15,
8662
+ name: name$1$14,
8663
8663
  message,
8664
8664
  cause
8665
8665
  });
@@ -9015,6 +9015,8 @@ function extractResponseHeaders$1(response) {
9015
9015
  }
9016
9016
  var { btoa: btoa$2, atob: atob$4 } = globalThis;
9017
9017
  function convertUint8ArrayToBase64$1(array) {
9018
+ var _a2;
9019
+ if (typeof ((_a2 = globalThis.Buffer) == null ? void 0 : _a2.from) === "function") return globalThis.Buffer.from(array.buffer, array.byteOffset, array.byteLength).toString("base64");
9018
9020
  const chunks = [];
9019
9021
  const chunkSize = 4096;
9020
9022
  for (let i = 0; i < array.length; i += chunkSize) chunks.push(String.fromCodePoint(...array.subarray(i, i + chunkSize)));
@@ -9027,11 +9029,11 @@ async function cancelResponseBody$1(response) {
9027
9029
  } catch (e) {}
9028
9030
  }
9029
9031
  var name$19 = "AI_DownloadError";
9030
- var marker$12 = `vercel.ai.error.${name$19}`;
9031
- var symbol$20 = Symbol.for(marker$12);
9032
+ var marker$15 = `vercel.ai.error.${name$19}`;
9033
+ var symbol$21 = Symbol.for(marker$15);
9032
9034
  var _a$2;
9033
9035
  var _b$2;
9034
- var DownloadError$1 = class extends (_b$2 = AISDKError$1, _a$2 = symbol$20, _b$2) {
9036
+ var DownloadError$1 = class extends (_b$2 = AISDKError$1, _a$2 = symbol$21, _b$2) {
9035
9037
  constructor({ url, statusCode, statusText, cause, message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}` }) {
9036
9038
  super({
9037
9039
  name: name$19,
@@ -9044,7 +9046,7 @@ var DownloadError$1 = class extends (_b$2 = AISDKError$1, _a$2 = symbol$20, _b$2
9044
9046
  this.statusText = statusText;
9045
9047
  }
9046
9048
  static isInstance(error) {
9047
- return AISDKError$1.hasMarker(error, marker$12);
9049
+ return AISDKError$1.hasMarker(error, marker$15);
9048
9050
  }
9049
9051
  };
9050
9052
  function isBrowserRuntime$1(globalThisAny = globalThis) {
@@ -9474,7 +9476,7 @@ function withUserAgentSuffix$1(headers, ...userAgentSuffixParts) {
9474
9476
  normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
9475
9477
  return Object.fromEntries(normalizedHeaders.entries());
9476
9478
  }
9477
- var VERSION$5 = "4.0.62";
9479
+ var VERSION$5 = "4.0.63";
9478
9480
  var getOriginalFetch$1 = () => globalThis.fetch;
9479
9481
  var getFromApi$1 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, validateUrl, credentialedOrigin, trustedOrigin }) => {
9480
9482
  try {
@@ -10950,7 +10952,7 @@ var createJsonResponseHandler$1 = (responseSchema) => async ({ response, url, re
10950
10952
  function withoutTrailingSlash$1(url) {
10951
10953
  return url == null ? void 0 : url.replace(/\/$/, "");
10952
10954
  }
10953
- // ../_vendored/ai_v6/dist/dist-CFYPWO89.js
10955
+ // ../_vendored/ai_v6/dist/dist-BOyF24Gs.js
10954
10956
  function getContext$1() {
10955
10957
  return { headers: {} };
10956
10958
  }
@@ -10958,10 +10960,10 @@ async function getVercelOidcToken$1() {
10958
10960
  if (process.env.VERCEL_OIDC_TOKEN) return process.env.VERCEL_OIDC_TOKEN ?? "";
10959
10961
  throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
10960
10962
  }
10961
- var symbol$15 = Symbol.for("vercel.ai.gateway.error");
10963
+ var symbol$20 = Symbol.for("vercel.ai.gateway.error");
10962
10964
  var _a$1;
10963
10965
  var _b;
10964
- var GatewayError$1 = class _GatewayError extends (_b = Error, _a$1 = symbol$15, _b) {
10966
+ var GatewayError$1 = class _GatewayError extends (_b = Error, _a$1 = symbol$20, _b) {
10965
10967
  constructor({ message, statusCode = 500, cause, generationId, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500) }) {
10966
10968
  super(generationId ? `${message} [${generationId}]` : message);
10967
10969
  this[_a$1] = true;
@@ -10979,7 +10981,7 @@ var GatewayError$1 = class _GatewayError extends (_b = Error, _a$1 = symbol$15,
10979
10981
  return _GatewayError.hasMarker(error);
10980
10982
  }
10981
10983
  static hasMarker(error) {
10982
- return typeof error === "object" && error !== null && symbol$15 in error && error[symbol$15] === true;
10984
+ return typeof error === "object" && error !== null && symbol$20 in error && error[symbol$20] === true;
10983
10985
  }
10984
10986
  };
10985
10987
  var name$18 = "GatewayAuthenticationError";
@@ -12870,7 +12872,7 @@ async function getVercelRequestId$1() {
12870
12872
  var _a11;
12871
12873
  return (_a11 = getContext$1().headers) == null ? void 0 : _a11["x-vercel-id"];
12872
12874
  }
12873
- var VERSION$4 = "3.0.223";
12875
+ var VERSION$4 = "3.0.226";
12874
12876
  var AI_GATEWAY_PROTOCOL_VERSION$1 = "0.0.1";
12875
12877
  function createGatewayProvider(options = {}) {
12876
12878
  var _a11, _b11;
@@ -13893,8 +13895,8 @@ var __export = (target, all) => {
13893
13895
  });
13894
13896
  };
13895
13897
  var name$12 = "AI_InvalidArgumentError";
13896
- var marker$19 = `vercel.ai.error.${name$12}`;
13897
- var symbol$19 = Symbol.for(marker$19);
13898
+ var marker$12 = `vercel.ai.error.${name$12}`;
13899
+ var symbol$19 = Symbol.for(marker$12);
13898
13900
  var _a;
13899
13901
  var InvalidArgumentError$2 = class extends AISDKError$1 {
13900
13902
  constructor({ parameter, value, message }) {
@@ -13907,7 +13909,7 @@ var InvalidArgumentError$2 = class extends AISDKError$1 {
13907
13909
  this.value = value;
13908
13910
  }
13909
13911
  static isInstance(error) {
13910
- return AISDKError$1.hasMarker(error, marker$19);
13912
+ return AISDKError$1.hasMarker(error, marker$12);
13911
13913
  }
13912
13914
  };
13913
13915
  _a = symbol$19;
@@ -14046,7 +14048,7 @@ function getTotalTimeoutMs(timeout) {
14046
14048
  if (typeof timeout === "number") return timeout;
14047
14049
  return timeout.totalMs;
14048
14050
  }
14049
- var VERSION$3 = "6.0.317";
14051
+ var VERSION$3 = "6.0.320";
14050
14052
  var dataContentSchema = zod_v4.z.union([
14051
14053
  zod_v4.z.string(),
14052
14054
  zod_v4.z.instanceof(Uint8Array),
@@ -15242,7 +15244,7 @@ createIdGenerator$1({
15242
15244
  prefix: "aiobj",
15243
15245
  size: 24
15244
15246
  });
15245
- // ../_vendored/ai_v7/dist/dist-5fMURLh0.js
15247
+ // ../_vendored/ai_v7/dist/dist-DcSumJIg.js
15246
15248
  /**
15247
15249
  * Symbol used for identifying AI SDK Error instances.
15248
15250
  * Enables checking if an error is an instance of AISDKError across package versions.
@@ -15382,6 +15384,21 @@ var JSONParseError = class extends AISDKError {
15382
15384
  return AISDKError.hasMarker(error, marker$8$1);
15383
15385
  }
15384
15386
  };
15387
+ const name$7$1 = "AI_LoadAPIKeyError";
15388
+ const marker$7$1 = `vercel.ai.error.${name$7$1}`;
15389
+ const symbol$7$1 = Symbol.for(marker$7$1);
15390
+ var LoadAPIKeyError = class extends AISDKError {
15391
+ constructor({ message }) {
15392
+ super({
15393
+ name: name$7$1,
15394
+ message
15395
+ });
15396
+ this[symbol$7$1] = true;
15397
+ }
15398
+ static isInstance(error) {
15399
+ return AISDKError.hasMarker(error, marker$7$1);
15400
+ }
15401
+ };
15385
15402
  const name$1$1$1 = "AI_TypeValidationError";
15386
15403
  const marker$1$1$1 = `vercel.ai.error.${name$1$1$1}`;
15387
15404
  const symbol$1$1$1 = Symbol.for(marker$1$1$1);
@@ -15912,7 +15929,7 @@ function handleFetchError({ error, url, requestBodyValues }) {
15912
15929
  }
15913
15930
  return error;
15914
15931
  }
15915
- const VERSION$2 = "5.0.70";
15932
+ const VERSION$2 = "5.0.72";
15916
15933
  /**
15917
15934
  * Normalizes different header inputs into a plain record with lower-case keys.
15918
15935
  * Entries with `undefined` or `null` values are removed.
@@ -18403,7 +18420,7 @@ function isSegment(value) {
18403
18420
  function withoutTrailingSlash(url) {
18404
18421
  return url?.replace(/\/$/, "");
18405
18422
  }
18406
- // ../_vendored/ai_v7/dist/dist-DFcOzoAh.js
18423
+ // ../_vendored/ai_v7/dist/dist-fgnmtGCL.js
18407
18424
  /**
18408
18425
  * Symbol used to define custom serialization for user-defined class instances.
18409
18426
  * The static method should accept an instance and return serializable data.
@@ -18957,6 +18974,7 @@ function isTimeoutError(error) {
18957
18974
  return false;
18958
18975
  }
18959
18976
  async function asGatewayError(error, authMethod) {
18977
+ if ((error instanceof Error || typeof DOMException === "function" && error instanceof DOMException) && (error.name === "AbortError" || error.name === "TimeoutError")) throw error;
18960
18978
  if (GatewayError.isInstance(error)) return error;
18961
18979
  if (isTimeoutError(error)) return GatewayTimeoutError.createTimeoutError({
18962
18980
  originalMessage: error instanceof Error ? error.message : "Unknown error",
@@ -20406,7 +20424,7 @@ const gatewayRerankingResponseSchema = lazySchema(() => zodSchema(z$5.object({
20406
20424
  * synchronous, hence this helper.
20407
20425
  */
20408
20426
  async function errorControllerWithGatewayError(controller, error, authMethod) {
20409
- controller.error(await asGatewayError(error, authMethod));
20427
+ controller.error(await asGatewayError(error, authMethod).catch((error) => error));
20410
20428
  }
20411
20429
  /**
20412
20430
  * Extract a human-readable message from an `error` stream part's payload for
@@ -21579,7 +21597,7 @@ const gatewayTools = {
21579
21597
  async function getVercelRequestId() {
21580
21598
  return getContext().headers?.["x-vercel-id"];
21581
21599
  }
21582
- const VERSION$1 = "4.0.128";
21600
+ const VERSION$1 = "4.0.132";
21583
21601
  const AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
21584
21602
  /** Response shape of `POST /v1/realtime/client-secrets`. `expiresAt` is epoch seconds. */
21585
21603
  const gatewayClientSecretResponseSchema = lazySchema(() => zodSchema(z$5.object({
@@ -21602,9 +21620,11 @@ function createGateway(options = {}) {
21602
21620
  ...options.teamIdOrSlug != null ? { [VERCEL_AI_GATEWAY_TEAM_HEADER]: options.teamIdOrSlug } : {},
21603
21621
  ...options.headers
21604
21622
  }, `ai-sdk-gateway/${VERSION$1}`);
21605
- const getHeaders = async () => {
21623
+ const getHeaders = async (onResolved) => {
21606
21624
  try {
21607
- return createAuthHeaders(await getGatewayAuthToken(options));
21625
+ const headers = createAuthHeaders(await getGatewayAuthToken(options));
21626
+ onResolved?.(headers);
21627
+ return headers;
21608
21628
  } catch (error) {
21609
21629
  throw GatewayAuthenticationError.createContextualError({
21610
21630
  apiKeyProvided: false,
@@ -21704,44 +21724,56 @@ function createGateway(options = {}) {
21704
21724
  const now = options._internal?.currentDate?.().getTime() ?? Date.now();
21705
21725
  if (!pendingMetadata || now - lastFetchTime > cacheRefreshMillis) {
21706
21726
  lastFetchTime = now;
21727
+ let resolvedHeaders;
21707
21728
  pendingMetadata = new GatewayFetchMetadata({
21708
21729
  baseURL,
21709
- headers: getHeaders,
21730
+ headers: () => getHeaders((headers) => {
21731
+ resolvedHeaders = headers;
21732
+ }),
21710
21733
  fetch: options.fetch
21711
21734
  }).getAvailableModels().then((metadata) => {
21712
21735
  metadataCache = metadata;
21713
21736
  return metadata;
21714
21737
  }).catch(async (error) => {
21715
- throw await asGatewayError(error, await parseAuthMethod(await getHeaders()));
21738
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders ?? {}));
21716
21739
  });
21717
21740
  }
21718
21741
  return metadataCache ? Promise.resolve(metadataCache) : pendingMetadata;
21719
21742
  };
21720
21743
  const getCredits = async () => {
21744
+ let resolvedHeaders;
21721
21745
  return new GatewayFetchMetadata({
21722
21746
  baseURL,
21723
- headers: getHeaders,
21747
+ headers: () => getHeaders((headers) => {
21748
+ resolvedHeaders = headers;
21749
+ }),
21724
21750
  fetch: options.fetch
21725
21751
  }).getCredits().catch(async (error) => {
21726
- throw await asGatewayError(error, await parseAuthMethod(await getHeaders()));
21752
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders ?? {}));
21727
21753
  });
21728
21754
  };
21729
21755
  const getSpendReport = async (params) => {
21756
+ let resolvedHeaders;
21730
21757
  return new GatewaySpendReport({
21731
21758
  baseURL,
21732
- headers: getHeaders,
21759
+ headers: () => getHeaders((headers) => {
21760
+ resolvedHeaders = headers;
21761
+ }),
21733
21762
  fetch: options.fetch
21734
21763
  }).getSpendReport(params).catch(async (error) => {
21735
- throw await asGatewayError(error, await parseAuthMethod(await getHeaders()));
21764
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders ?? {}));
21736
21765
  });
21737
21766
  };
21738
21767
  const getGenerationInfo = async (params) => {
21768
+ let resolvedHeaders;
21739
21769
  return new GatewayGenerationInfoFetcher({
21740
21770
  baseURL,
21741
- headers: getHeaders,
21771
+ headers: () => getHeaders((headers) => {
21772
+ resolvedHeaders = headers;
21773
+ }),
21742
21774
  fetch: options.fetch
21743
21775
  }).getGenerationInfo(params).catch(async (error) => {
21744
- throw await asGatewayError(error, await parseAuthMethod(await getHeaders()));
21776
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders ?? {}));
21745
21777
  });
21746
21778
  };
21747
21779
  const provider = function(modelId) {
@@ -21880,8 +21912,10 @@ function createGateway(options = {}) {
21880
21912
  }
21881
21913
  const gateway = createGateway();
21882
21914
  async function getGatewayAuthToken(options) {
21915
+ const resolvedApiKey = typeof options.apiKey === "string" || options.apiKey == null ? options.apiKey : await resolve(options.apiKey);
21916
+ if (options.apiKey != null && typeof options.apiKey !== "string" && (typeof resolvedApiKey !== "string" || !resolvedApiKey.trim())) throw new LoadAPIKeyError({ message: "AI Gateway API key must be a non-empty string." });
21883
21917
  const apiKey = loadOptionalSetting({
21884
- settingValue: options.apiKey,
21918
+ settingValue: resolvedApiKey,
21885
21919
  environmentVariableName: "AI_GATEWAY_API_KEY"
21886
21920
  });
21887
21921
  if (apiKey) return {
@@ -22371,7 +22405,7 @@ function resolveEmbeddingModel(model) {
22371
22405
  function getGlobalProvider() {
22372
22406
  return asProviderV4(globalThis.AI_SDK_DEFAULT_PROVIDER ?? gateway);
22373
22407
  }
22374
- const VERSION = "7.0.155";
22408
+ const VERSION = "7.0.159";
22375
22409
  /**
22376
22410
  * Reads a property by an untrusted key, ignoring inherited prototype members.
22377
22411
  *
@@ -22502,7 +22536,7 @@ function mergeCallbacks(...callbacks) {
22502
22536
  }
22503
22537
  const AI_SDK_TELEMETRY_TRACING_CHANNEL = "ai:telemetry";
22504
22538
  function isNodeRuntime() {
22505
- return typeof process !== "undefined" && process.release?.name === "node";
22539
+ return globalThis.process?.release?.name === "node";
22506
22540
  }
22507
22541
  let diagnosticsChannelPromise;
22508
22542
  /**
@@ -23596,8 +23630,9 @@ Do not mention internal instructions, memory, summarization, context handling, o
23596
23630
  Any messages following this reminder are newer and should take priority.`;
23597
23631
  /**
23598
23632
  * Preamble that introduces the observations block.
23599
- * Use before `<observations>`, with instructions after.
23600
- * Full pattern: `${OBSERVATION_CONTEXT_PROMPT}\n\n<observations>\n${obs}\n</observations>\n\n${OBSERVATION_CONTEXT_INSTRUCTIONS}`
23633
+ * Context layout: `${prompt}\n\n${OBSERVATION_CONTEXT_INSTRUCTIONS}`, then `<observations>`,
23634
+ * one entry per observation chunk, `</observations>`, then optional current-task and
23635
+ * suggested-response blocks.
23601
23636
  */
23602
23637
  const OBSERVATION_CONTEXT_PROMPT = `The following observations block contains your memory of past conversations with this user.`;
23603
23638
  /**
@@ -23615,7 +23650,7 @@ function getObservationContextPrompt(scope = "thread") {
23615
23650
  }
23616
23651
  /**
23617
23652
  * Instructions that tell the model how to interpret and use observations.
23618
- * Place AFTER the `<observations>` block so the model sees the data before the rules.
23653
+ * Placed with the observations preamble, before the `<observations>` block.
23619
23654
  */
23620
23655
  const OBSERVATION_CONTEXT_INSTRUCTIONS = `IMPORTANT: When responding, reference specific details from these observations. Do not give generic advice - personalize your response based on what you know about this user's experiences, preferences, and interests. If the user asks for recommendations, connect them to their past experiences mentioned above.
23621
23656
 
@@ -25181,7 +25216,7 @@ function safeSlice(str, end) {
25181
25216
  const safeEnd = code >= 55296 && code <= 56319 ? end - 1 : end;
25182
25217
  return str.slice(0, safeEnd);
25183
25218
  }
25184
- // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/tokenx/1.6.0/394289cb1bed8c542941f77748eea1a31bd3419018d0fb2ac7029ece2458cdd1/node_modules/tokenx/dist/index.mjs
25219
+ // ../../../../../.local/share/pnpm/store/v11/links/@/tokenx/1.6.0/394289cb1bed8c542941f77748eea1a31bd3419018d0fb2ac7029ece2458cdd1/node_modules/tokenx/dist/index.mjs
25185
25220
  const PATTERNS = {
25186
25221
  whitespace: /^\s+$/,
25187
25222
  structuredWhitespace: /\n\s/,
@@ -30400,12 +30435,34 @@ function getMessageParts(msg) {
30400
30435
  const parts = msg.content?.parts;
30401
30436
  return Array.isArray(parts) ? parts : [];
30402
30437
  }
30403
- /** Returns true if a message has at least one non-data part with visible content. */
30438
+ /**
30439
+ * Returns true if recall can render at least one visible part of a message.
30440
+ * Mirrors the skip rules in `formatMessageParts` without formatting tool results.
30441
+ */
30404
30442
  function hasVisibleParts(msg) {
30405
- if (typeof msg.content === "string") return msg.content.length > 0;
30443
+ if (typeof msg.content === "string") return true;
30406
30444
  const parts = getMessageParts(msg);
30407
30445
  if (parts.length === 0) return Boolean(msg.content?.content);
30408
- return parts.some((p) => !p.type?.startsWith("data-"));
30446
+ return parts.some(isVisiblePart);
30447
+ }
30448
+ function isVisiblePart(part) {
30449
+ const partType = part?.type;
30450
+ switch (partType) {
30451
+ case void 0:
30452
+ case "":
30453
+ case "reasoning":
30454
+ case "redacted-reasoning":
30455
+ case "step-start": return false;
30456
+ case "text": return Boolean(part.text);
30457
+ case "tool-invocation": {
30458
+ const inv = part.toolInvocation;
30459
+ if (!inv?.toolName) return false;
30460
+ return inv.state !== "partial-call" && inv.args != null || inv.state === "result";
30461
+ }
30462
+ case "tool-call":
30463
+ case "tool-result": return Boolean(part.toolName);
30464
+ default: return !partType.startsWith("data-");
30465
+ }
30409
30466
  }
30410
30467
  function parseRangeFormat(cursor) {
30411
30468
  if (cursor.includes(",")) {
@@ -30519,7 +30576,7 @@ async function listThreadsForResource({ memory, resourceId, currentThreadId, pag
30519
30576
  hasMore
30520
30577
  };
30521
30578
  }
30522
- const SEARCH_NOT_CONFIGURED_MESSAGE = "Search is not configured. Enable it with `retrieval: { vector: true }` and configure a vector store and embedder on your Memory instance.";
30579
+ const SEARCH_NOT_CONFIGURED_MESSAGE = "Search is not configured. Enable it with `retrieval: { vector: true }` and configure a vector store and an embedder, or a vector store that generates embeddings itself, on your Memory instance.";
30523
30580
  async function searchMessagesForResource({ memory, om, resourceId, currentThreadId, query, topK = 10, maxTokens = DEFAULT_MAX_RESULT_TOKENS, before, after, threadScope, includeThreadId = true, currentMessages = [] }) {
30524
30581
  if (!memory.searchMessages) return {
30525
30582
  results: SEARCH_NOT_CONFIGURED_MESSAGE,
@@ -31037,11 +31094,8 @@ function formatMessageParts(msg, detail) {
31037
31094
  const fullText = `[Tool Result: ${toolName}]\n${formatToolResultForObserver(omitInlineMediaPayloads(part.output ?? part.result), { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS })}`;
31038
31095
  parts.push(makePart(msg, i, "tool-result", fullText, detail, toolName));
31039
31096
  }
31040
- } else if (partType === "reasoning") {
31041
- const reasoning = part.reasoning ?? part.text;
31042
- if (reasoning) parts.push(makePart(msg, i, "reasoning", reasoning, detail));
31043
- } else if (partType === "image" || partType === "file") parts.push(makePart(msg, i, partType, formatAttachmentPart(partType, part), detail));
31044
- else if (partType?.startsWith("data-")) {} else if (partType) {
31097
+ } else if (partType === "reasoning" || partType === "redacted-reasoning") {} else if (partType === "image" || partType === "file") parts.push(makePart(msg, i, partType, formatAttachmentPart(partType, part), detail));
31098
+ else if (partType === "step-start" || partType?.startsWith("data-")) {} else if (partType) {
31045
31099
  const fullText = `[${partType}]`;
31046
31100
  parts.push({
31047
31101
  messageId: msg.id,
@@ -31072,12 +31126,29 @@ function buildRenderedText(parts, timestamps) {
31072
31126
  }
31073
31127
  return lines.join("\n");
31074
31128
  }
31129
+ /**
31130
+ * Reads messages until `needed` of them are visible or storage is exhausted, growing the
31131
+ * request each round. Hidden messages (reasoning-only, step boundaries, OM markers) don't
31132
+ * count toward `needed`, so a run of them can't end paging early.
31133
+ */
31134
+ async function recallVisibleMessages(memory, args, needed, perPage = needed) {
31135
+ let previousCount = -1;
31136
+ while (true) {
31137
+ const result = await memory.recall({
31138
+ ...args,
31139
+ page: 0,
31140
+ perPage
31141
+ });
31142
+ const visible = result.messages.filter(hasVisibleParts);
31143
+ if (visible.length >= needed || !result.hasMore || result.messages.length <= previousCount) return visible;
31144
+ previousCount = result.messages.length;
31145
+ perPage *= 2;
31146
+ }
31147
+ }
31075
31148
  async function getNextVisibleMessage({ memory, threadId, resourceId, after }) {
31076
- return (await memory.recall({
31149
+ return (await recallVisibleMessages(memory, {
31077
31150
  threadId,
31078
31151
  resourceId,
31079
- page: 0,
31080
- perPage: 50,
31081
31152
  orderBy: {
31082
31153
  field: "createdAt",
31083
31154
  direction: "ASC"
@@ -31086,7 +31157,7 @@ async function getNextVisibleMessage({ memory, threadId, resourceId, after }) {
31086
31157
  start: after,
31087
31158
  startExclusive: true
31088
31159
  } }
31089
- })).messages.find(hasVisibleParts) ?? null;
31160
+ }, 1, 50))[0] ?? null;
31090
31161
  }
31091
31162
  const MAX_EXPAND_USER_TEXT_TOKENS = 200;
31092
31163
  const MAX_EXPAND_OTHER_TOKENS = 50;
@@ -31096,7 +31167,7 @@ function expandLimit(part) {
31096
31167
  }
31097
31168
  function expandPriority(part) {
31098
31169
  if (part.role === "user" && part.type === "text") return 0;
31099
- if (part.type === "text" || part.type === "reasoning") return 1;
31170
+ if (part.type === "text") return 1;
31100
31171
  if (part.type === "tool-result") return 2;
31101
31172
  if (part.type === "tool-call") return 3;
31102
31173
  return 4;
@@ -31282,11 +31353,9 @@ async function recallMessages({ memory, threadId, resourceId, cursor, page = 1,
31282
31353
  const pageIndex = Math.max(Math.abs(normalizedPage), 1) - 1;
31283
31354
  const skip = pageIndex * normalizedLimit;
31284
31355
  const fetchCount = skip + normalizedLimit + 1;
31285
- const visibleMessages = (await memory.recall({
31356
+ const visibleMessages = await recallVisibleMessages(memory, {
31286
31357
  threadId: resolvedThreadId,
31287
31358
  resourceId,
31288
- page: 0,
31289
- perPage: fetchCount,
31290
31359
  orderBy: {
31291
31360
  field: "createdAt",
31292
31361
  direction: isForward ? "ASC" : "DESC"
@@ -31298,7 +31367,7 @@ async function recallMessages({ memory, threadId, resourceId, cursor, page = 1,
31298
31367
  end: anchor.createdAt,
31299
31368
  endExclusive: true
31300
31369
  } }
31301
- })).messages.filter(hasVisibleParts);
31370
+ }, fetchCount);
31302
31371
  const total = visibleMessages.length;
31303
31372
  const hasMore = total > skip + normalizedLimit;
31304
31373
  let messages;
@@ -31381,17 +31450,15 @@ async function recallThreadFromStart({ memory, threadId, resourceId, page = 1, l
31381
31450
  const normalizedLimit = Math.min(Math.max(limit, 1), MAX_LIMIT);
31382
31451
  const pageIndex = normalizedPage - 1;
31383
31452
  const fetchCount = pageIndex * normalizedLimit + normalizedLimit + 1;
31384
- const result = await memory.recall({
31453
+ const fetched = await recallVisibleMessages(memory, {
31385
31454
  threadId,
31386
31455
  resourceId,
31387
- page: 0,
31388
- perPage: fetchCount,
31389
31456
  orderBy: {
31390
31457
  field: "createdAt",
31391
31458
  direction: anchor === "end" ? "DESC" : "ASC"
31392
31459
  }
31393
- });
31394
- const visibleMessages = anchor === "end" ? result.messages.slice(0, fetchCount).filter(hasVisibleParts).reverse() : result.messages.slice(0, fetchCount).filter(hasVisibleParts);
31460
+ }, fetchCount);
31461
+ const visibleMessages = anchor === "end" ? fetched.reverse() : fetched;
31395
31462
  const skip = pageIndex * normalizedLimit;
31396
31463
  const messages = visibleMessages.slice(skip, skip + normalizedLimit);
31397
31464
  const hasExtraMessage = visibleMessages.length > skip + messages.length;
@@ -31526,7 +31593,6 @@ const recallTool = (_memoryConfig, options) => {
31526
31593
  "text",
31527
31594
  "tool-call",
31528
31595
  "tool-result",
31529
- "reasoning",
31530
31596
  "image",
31531
31597
  "file"
31532
31598
  ],
@@ -37721,7 +37787,7 @@ var ObservationalMemory = class ObservationalMemory {
37721
37787
  const messages = [`${getObservationContextPrompt(this.scope)}\n\n${OBSERVATION_CONTEXT_INSTRUCTIONS}${retrieval ? `\n\n${getRetrievalInstructions(this.retrievalScope, this.retrievalInstructions, this.retrievalSearch, this.storage.supportsObservationalMemoryHistorySearch === true)}` : ""}`];
37722
37788
  if (unobservedContextBlocks) messages.push(`The following content is from OTHER conversations different from the current conversation, they're here for reference, but they're not necessarily your focus:\nSTART_OTHER_CONVERSATIONS_BLOCK\n${unobservedContextBlocks}\nEND_OTHER_CONVERSATIONS_BLOCK`);
37723
37789
  const observationChunks = this.splitObservationContextChunks(optimized);
37724
- if (observationChunks.length > 0) messages.push("<observations>", ...observationChunks);
37790
+ if (observationChunks.length > 0) messages.push("<observations>", ...observationChunks, "</observations>");
37725
37791
  if (currentTask) messages.push(`<current-task>\n${currentTask}\n</current-task>`);
37726
37792
  if (suggestedResponse) messages.push(`<suggested-response>\n${suggestedResponse}\n</suggested-response>`);
37727
37793
  messages.push(...buildExtractedValueContextSections([...this.observationConfig.extractors, ...this.reflectionConfig.extractors], extractedValues));
@@ -40179,7 +40245,7 @@ var Memory = class Memory extends _mastra_core_memory.MastraMemory {
40179
40245
  const omConfig = normalizeObservationalMemoryConfig(mergedConfig.observationalMemory);
40180
40246
  if (omConfig?.retrieval && typeof omConfig.retrieval === "object" && omConfig.retrieval.vector) {
40181
40247
  if (!this.vector) throw new Error("`retrieval: { vector: true }` requires a vector store. Pass a `vector` option to your Memory instance.");
40182
- if (!this.embedder) throw new Error("`retrieval: { vector: true }` requires an embedder. Pass an `embedder` option to your Memory instance.");
40248
+ if (!this.embedder && !this.isSelfEmbedding) throw new Error("`retrieval: { vector: true }` requires an embedder, or a vector store that generates embeddings itself. Pass an `embedder` option to your Memory instance.");
40183
40249
  }
40184
40250
  }
40185
40251
  /**
@@ -41361,8 +41427,9 @@ Notes:
41361
41427
  if (config?.workingMemory?.useStateSignals === true && this.isVNextWorkingMemoryConfig(config)) throw new Error("workingMemory.useStateSignals is not supported with workingMemory.version: 'vnext'. Use stable template working memory or disable useStateSignals.");
41362
41428
  }
41363
41429
  getObservationEmbeddingIndexName(dimensions) {
41364
- const usedDimensions = dimensions ?? 384;
41365
41430
  const separator = this.vector?.indexSeparator ?? "_";
41431
+ if (this.isSelfEmbedding) return `${this.observationIndexPrefix}${separator}selfembed`;
41432
+ const usedDimensions = dimensions ?? 384;
41366
41433
  return `${this.observationIndexPrefix}${separator}${usedDimensions}`;
41367
41434
  }
41368
41435
  async createObservationEmbeddingIndex(dimensions) {
@@ -41371,7 +41438,7 @@ Notes:
41371
41438
  if (typeof this.vector === `undefined`) throw new Error(`Tried to create observation embedding index but no vector db is attached to this Memory instance.`);
41372
41439
  await this.vector.createIndex({
41373
41440
  indexName,
41374
- dimension: usedDimensions,
41441
+ ...this.isSelfEmbedding ? {} : { dimension: usedDimensions },
41375
41442
  metadataIndexes: ["resource_id", "thread_id"]
41376
41443
  });
41377
41444
  return { indexName };
@@ -41382,7 +41449,14 @@ Notes:
41382
41449
  */
41383
41450
  async searchMessages({ query, resourceId, topK = 10, filter }) {
41384
41451
  if (!this.vector) throw new Error("searchMessages requires a vector store. Configure vector and embedder on your Memory instance.");
41385
- const { embeddings, dimension } = await this.embedMessageContent(query);
41452
+ const queries = [];
41453
+ let dimension;
41454
+ if (this.isSelfEmbedding) queries.push({ queryText: query });
41455
+ else {
41456
+ const embedResult = await this.embedMessageContent(query);
41457
+ dimension = embedResult.dimension;
41458
+ queries.push(...embedResult.embeddings.map((queryVector) => ({ queryVector })));
41459
+ }
41386
41460
  const { indexName } = await this.createObservationEmbeddingIndex(dimension);
41387
41461
  const vectorFilter = { resource_id: resourceId };
41388
41462
  if (filter?.threadId) vectorFilter.thread_id = filter.threadId;
@@ -41391,10 +41465,10 @@ Notes:
41391
41465
  ...filter.observedBefore ? { $lt: filter.observedBefore.toISOString() } : {}
41392
41466
  };
41393
41467
  const queryResults = [];
41394
- await Promise.all(embeddings.map(async (embedding) => {
41468
+ await Promise.all(queries.map(async (params) => {
41395
41469
  const results = await this.vector.query({
41396
41470
  indexName,
41397
- queryVector: embedding,
41471
+ ...params,
41398
41472
  topK,
41399
41473
  filter: vectorFilter
41400
41474
  });
@@ -41425,12 +41499,21 @@ Notes:
41425
41499
  * Index a single observation group into the observation vector store.
41426
41500
  */
41427
41501
  async indexObservation({ text, groupId, range, threadId, resourceId, observedAt, recordId }) {
41428
- if (!this.vector || !this.embedder) return;
41429
- const embedResult = await this.embedMessageContent(text);
41430
- if (embedResult.embeddings.length === 0 || embedResult.dimension === void 0) return;
41431
- const { indexName } = await this.createObservationEmbeddingIndex(embedResult.dimension);
41502
+ if (!this.vector || !this.embedder && !this.isSelfEmbedding) return;
41503
+ let chunks;
41504
+ let embeddings = [];
41505
+ let dimension;
41506
+ if (this.isSelfEmbedding) {
41507
+ chunks = this.chunkText(text);
41508
+ if (chunks.length === 0) return;
41509
+ } else {
41510
+ const embedResult = await this.embedMessageContent(text);
41511
+ ({chunks, embeddings, dimension} = embedResult);
41512
+ if (embeddings.length === 0 || dimension === void 0) return;
41513
+ }
41514
+ const { indexName } = await this.createObservationEmbeddingIndex(dimension);
41432
41515
  const ids = [];
41433
- for (const [chunkIndex] of embedResult.chunks.entries()) {
41516
+ for (const [chunkIndex] of chunks.entries()) {
41434
41517
  const hash = Buffer.from(await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify([
41435
41518
  resourceId,
41436
41519
  threadId,
@@ -41442,19 +41525,26 @@ Notes:
41442
41525
  const hex = hash.toString("hex", 0, 16);
41443
41526
  ids.push(`${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`);
41444
41527
  }
41445
- await this.vector.upsert({
41528
+ const metadata = chunks.map((chunk) => ({
41529
+ group_id: groupId,
41530
+ range,
41531
+ thread_id: threadId,
41532
+ resource_id: resourceId,
41533
+ observed_at: observedAt?.toISOString(),
41534
+ ...recordId ? { record_id: recordId } : {},
41535
+ text: chunk
41536
+ }));
41537
+ if (this.isSelfEmbedding) await this.vector.upsert({
41446
41538
  indexName,
41447
41539
  ids,
41448
- vectors: embedResult.embeddings,
41449
- metadata: embedResult.chunks.map((chunk) => ({
41450
- group_id: groupId,
41451
- range,
41452
- thread_id: threadId,
41453
- resource_id: resourceId,
41454
- observed_at: observedAt?.toISOString(),
41455
- ...recordId ? { record_id: recordId } : {},
41456
- text: chunk
41457
- }))
41540
+ documents: chunks,
41541
+ metadata
41542
+ });
41543
+ else await this.vector.upsert({
41544
+ indexName,
41545
+ ids,
41546
+ vectors: embeddings,
41547
+ metadata
41458
41548
  });
41459
41549
  }
41460
41550
  /**
@@ -41611,11 +41701,12 @@ Notes:
41611
41701
  }
41612
41702
  /**
41613
41703
  * Check whether retrieval search (vector-based) is enabled.
41614
- * Returns true when `retrieval: { vector: true }` and Memory has vector + embedder configured.
41704
+ * Returns true when `retrieval: { vector: true }` and Memory has a vector store plus either an
41705
+ * embedder or a store that generates embeddings itself.
41615
41706
  */
41616
41707
  hasRetrievalSearch(retrieval) {
41617
41708
  if (!retrieval || retrieval === true) return false;
41618
- return !!retrieval.vector && !!this.vector && !!this.embedder;
41709
+ return !!retrieval.vector && !!this.vector && (!!this.embedder || this.isSelfEmbedding);
41619
41710
  }
41620
41711
  listTools(config) {
41621
41712
  const mergedConfig = this.getMergedThreadConfig(config);
@@ -42096,15 +42187,22 @@ Notes:
42096
42187
  const vector = this.vector;
42097
42188
  const indexes = await this.getMemoryVectorIndexes([this.observationIndexPrefix]);
42098
42189
  for (const indexName of indexes) {
42099
- const { dimension } = await vector.describeIndex({ indexName });
42100
- const queryVector = Array.from({ length: dimension }, (_, i) => i === 0 ? 1 : 0);
42190
+ const selfEmbedded = this.isSelfEmbedding && indexName === this.getObservationEmbeddingIndexName();
42191
+ let readParams;
42192
+ if (selfEmbedded) readParams = { queryText: "observations" };
42193
+ else {
42194
+ const { dimension } = await vector.describeIndex({ indexName });
42195
+ readParams = {
42196
+ queryVector: Array.from({ length: dimension }, (_, i) => i === 0 ? 1 : 0),
42197
+ includeVector: true
42198
+ };
42199
+ }
42101
42200
  const moved = /* @__PURE__ */ new Set();
42102
42201
  for (;;) {
42103
42202
  const pending = (await vector.query({
42104
42203
  indexName,
42105
- queryVector,
42204
+ ...readParams,
42106
42205
  topK: 20,
42107
- includeVector: true,
42108
42206
  filter: {
42109
42207
  thread_id: threadId,
42110
42208
  resource_id: { $ne: resourceId }
@@ -42725,4 +42823,4 @@ Object.defineProperty(exports, "wrapInObservationGroup", {
42725
42823
  }
42726
42824
  });
42727
42825
 
42728
- //# sourceMappingURL=src-GDwZ0vzw.cjs.map
42826
+ //# sourceMappingURL=src-B4WjMcwZ.cjs.map