@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
@@ -38,9 +38,9 @@ var __exportAll = (all, no_symbols) => {
38
38
  if (!no_symbols) __defProp$3(target, Symbol.toStringTag, { value: "Module" });
39
39
  return target;
40
40
  };
41
- // ../_vendored/ai_v4/dist/dist-DlRWVOEI.js
41
+ // ../_vendored/ai_v4/dist/dist-BxNtn0K2.js
42
42
  var marker$21 = "vercel.ai.error";
43
- var symbol$12 = Symbol.for(marker$21);
43
+ var symbol$25 = Symbol.for(marker$21);
44
44
  var _a$7;
45
45
  var _AISDKError = class _AISDKError extends Error {
46
46
  /**
@@ -70,7 +70,7 @@ var _AISDKError = class _AISDKError extends Error {
70
70
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
71
71
  }
72
72
  };
73
- _a$7 = symbol$12;
73
+ _a$7 = symbol$25;
74
74
  var AISDKError$3 = _AISDKError;
75
75
  var name$22 = "AI_APICallError";
76
76
  var marker2$7 = `vercel.ai.error.${name$22}`;
@@ -2781,14 +2781,14 @@ var UnsupportedModelVersionError$3 = class extends AISDKError$3 {
2781
2781
  });
2782
2782
  }
2783
2783
  };
2784
- var name$15 = "AI_InvalidArgumentError";
2785
- var marker$10 = `vercel.ai.error.${name$15}`;
2786
- var symbol$25 = Symbol.for(marker$10);
2784
+ var name$21 = "AI_InvalidArgumentError";
2785
+ var marker$10 = `vercel.ai.error.${name$21}`;
2786
+ var symbol$12 = Symbol.for(marker$10);
2787
2787
  var _a$6;
2788
2788
  var InvalidArgumentError$6 = class extends AISDKError$3 {
2789
2789
  constructor({ parameter, value, message }) {
2790
2790
  super({
2791
- name: name$15,
2791
+ name: name$21,
2792
2792
  message: `Invalid argument for parameter ${parameter}: ${message}`
2793
2793
  });
2794
2794
  this[_a$6] = true;
@@ -2799,7 +2799,7 @@ var InvalidArgumentError$6 = class extends AISDKError$3 {
2799
2799
  return AISDKError$3.hasMarker(error, marker$10);
2800
2800
  }
2801
2801
  };
2802
- _a$6 = symbol$25;
2802
+ _a$6 = symbol$12;
2803
2803
  var name2$6 = "AI_RetryError";
2804
2804
  var marker2$6 = `vercel.ai.error.${name2$6}`;
2805
2805
  var symbol2$6 = Symbol.for(marker2$6);
@@ -3689,9 +3689,9 @@ function trimStartOfStream() {
3689
3689
  return text2;
3690
3690
  };
3691
3691
  }
3692
- // ../_vendored/ai_v5/dist/dist-DRvrQv6K.js
3693
- var marker$1$17 = "vercel.ai.error";
3694
- var symbol$1$17 = Symbol.for(marker$1$17);
3692
+ // ../_vendored/ai_v5/dist/dist-DSvOscpb.js
3693
+ var marker$1$16 = "vercel.ai.error";
3694
+ var symbol$1$17 = Symbol.for(marker$1$16);
3695
3695
  var _a$1$2;
3696
3696
  var _b$1$4;
3697
3697
  var AISDKError$2 = class _AISDKError extends (_b$1$4 = Error, _a$1$2 = symbol$1$17, _b$1$4) {
@@ -3715,22 +3715,22 @@ var AISDKError$2 = class _AISDKError extends (_b$1$4 = Error, _a$1$2 = symbol$1$
3715
3715
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
3716
3716
  */
3717
3717
  static isInstance(error) {
3718
- return _AISDKError.hasMarker(error, marker$1$17);
3718
+ return _AISDKError.hasMarker(error, marker$1$16);
3719
3719
  }
3720
3720
  static hasMarker(error, marker15) {
3721
3721
  const markerSymbol = Symbol.for(marker15);
3722
3722
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
3723
3723
  }
3724
3724
  };
3725
- var name$1$16 = "AI_APICallError";
3726
- var marker2$5 = `vercel.ai.error.${name$1$16}`;
3725
+ var name$1$15 = "AI_APICallError";
3726
+ var marker2$5 = `vercel.ai.error.${name$1$15}`;
3727
3727
  var symbol2$5 = Symbol.for(marker2$5);
3728
3728
  var _a2$5;
3729
3729
  var _b2$3;
3730
3730
  var APICallError$2 = class extends (_b2$3 = AISDKError$2, _a2$5 = symbol2$5, _b2$3) {
3731
3731
  constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
3732
3732
  super({
3733
- name: name$1$16,
3733
+ name: name$1$15,
3734
3734
  message,
3735
3735
  cause
3736
3736
  });
@@ -4069,15 +4069,15 @@ function createAbortError$2() {
4069
4069
  function extractResponseHeaders$2(response) {
4070
4070
  return Object.fromEntries([...response.headers]);
4071
4071
  }
4072
- var name$21 = "AI_DownloadError";
4073
- var marker$15 = `vercel.ai.error.${name$21}`;
4074
- var symbol$24 = Symbol.for(marker$15);
4072
+ var name$15 = "AI_DownloadError";
4073
+ var marker$20 = `vercel.ai.error.${name$15}`;
4074
+ var symbol$24 = Symbol.for(marker$20);
4075
4075
  var _a$5;
4076
4076
  var _b$5;
4077
4077
  var DownloadError$2 = class extends (_b$5 = AISDKError$2, _a$5 = symbol$24, _b$5) {
4078
4078
  constructor({ url, statusCode, statusText, cause, message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}` }) {
4079
4079
  super({
4080
- name: name$21,
4080
+ name: name$15,
4081
4081
  message,
4082
4082
  cause
4083
4083
  });
@@ -4087,7 +4087,7 @@ var DownloadError$2 = class extends (_b$5 = AISDKError$2, _a$5 = symbol$24, _b$5
4087
4087
  this.statusText = statusText;
4088
4088
  }
4089
4089
  static isInstance(error) {
4090
- return AISDKError$2.hasMarker(error, marker$15);
4090
+ return AISDKError$2.hasMarker(error, marker$20);
4091
4091
  }
4092
4092
  };
4093
4093
  var EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL$2 = /* @__PURE__ */ Symbol.for("vercel.ai.embeddingModel.maxInputBytesPerCall");
@@ -4250,7 +4250,7 @@ function withUserAgentSuffix$2(headers, ...userAgentSuffixParts) {
4250
4250
  normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
4251
4251
  return Object.fromEntries(normalizedHeaders.entries());
4252
4252
  }
4253
- var VERSION$8 = "3.0.42";
4253
+ var VERSION$8 = "3.0.43";
4254
4254
  var getOriginalFetch$3 = () => globalThis.fetch;
4255
4255
  var getFromApi$2 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch = getOriginalFetch$3() }) => {
4256
4256
  try {
@@ -5677,7 +5677,7 @@ var { btoa: btoa$3, atob: atob$6 } = globalThis;
5677
5677
  function withoutTrailingSlash$2(url) {
5678
5678
  return url == null ? void 0 : url.replace(/\/$/, "");
5679
5679
  }
5680
- // ../_vendored/ai_v5/dist/dist-q105Fieh.js
5680
+ // ../_vendored/ai_v5/dist/dist-I4iGGqeV.js
5681
5681
  function getContext$2() {
5682
5682
  return { headers: {} };
5683
5683
  }
@@ -5685,10 +5685,10 @@ async function getVercelOidcToken$2() {
5685
5685
  if (process.env.VERCEL_OIDC_TOKEN) return process.env.VERCEL_OIDC_TOKEN ?? "";
5686
5686
  throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
5687
5687
  }
5688
- var symbol$22 = Symbol.for("vercel.ai.gateway.error");
5688
+ var symbol$15 = Symbol.for("vercel.ai.gateway.error");
5689
5689
  var _a$4;
5690
5690
  var _b$3;
5691
- var GatewayError$2 = class _GatewayError extends (_b$3 = Error, _a$4 = symbol$22, _b$3) {
5691
+ var GatewayError$2 = class _GatewayError extends (_b$3 = Error, _a$4 = symbol$15, _b$3) {
5692
5692
  constructor({ message, statusCode = 500, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500) }) {
5693
5693
  super(message);
5694
5694
  this[_a$4] = true;
@@ -5705,7 +5705,7 @@ var GatewayError$2 = class _GatewayError extends (_b$3 = Error, _a$4 = symbol$22
5705
5705
  return _GatewayError.hasMarker(error);
5706
5706
  }
5707
5707
  static hasMarker(error) {
5708
- return typeof error === "object" && error !== null && symbol$22 in error && error[symbol$22] === true;
5708
+ return typeof error === "object" && error !== null && symbol$15 in error && error[symbol$15] === true;
5709
5709
  }
5710
5710
  };
5711
5711
  var name$10 = "GatewayAuthenticationError";
@@ -6656,7 +6656,7 @@ async function getVercelRequestId$2() {
6656
6656
  var _a10;
6657
6657
  return (_a10 = getContext$2().headers) == null ? void 0 : _a10["x-vercel-id"];
6658
6658
  }
6659
- var VERSION$7 = "2.0.173";
6659
+ var VERSION$7 = "2.0.174";
6660
6660
  var AI_GATEWAY_PROTOCOL_VERSION$2 = "0.0.1";
6661
6661
  function createGatewayProvider$1(options = {}) {
6662
6662
  var _a10, _b10;
@@ -7691,7 +7691,7 @@ function getGlobalProvider$2() {
7691
7691
  var _a17;
7692
7692
  return (_a17 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a17 : gateway$2;
7693
7693
  }
7694
- var VERSION$6 = "5.0.282";
7694
+ var VERSION$6 = "5.0.283";
7695
7695
  var dataContentSchema$1 = z$1.union([
7696
7696
  z$1.string(),
7697
7697
  z$1.instanceof(Uint8Array),
@@ -8597,12 +8597,12 @@ var object$2 = ({ schema: inputSchema }) => {
8597
8597
  }
8598
8598
  };
8599
8599
  };
8600
- // ../_vendored/ai_v6/dist/dist-Dl1sIpsh.js
8601
- var marker$1$15 = "vercel.ai.error";
8602
- var symbol$1$16 = Symbol.for(marker$1$15);
8600
+ // ../_vendored/ai_v6/dist/dist-B5EfJITb.js
8601
+ var marker$1$14 = "vercel.ai.error";
8602
+ var symbol$1$15 = Symbol.for(marker$1$14);
8603
8603
  var _a$1$1;
8604
8604
  var _b$1;
8605
- var AISDKError$1 = class _AISDKError extends (_b$1 = Error, _a$1$1 = symbol$1$16, _b$1) {
8605
+ var AISDKError$1 = class _AISDKError extends (_b$1 = Error, _a$1$1 = symbol$1$15, _b$1) {
8606
8606
  /**
8607
8607
  * Creates an AI SDK Error.
8608
8608
  *
@@ -8623,22 +8623,22 @@ var AISDKError$1 = class _AISDKError extends (_b$1 = Error, _a$1$1 = symbol$1$16
8623
8623
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
8624
8624
  */
8625
8625
  static isInstance(error) {
8626
- return _AISDKError.hasMarker(error, marker$1$15);
8626
+ return _AISDKError.hasMarker(error, marker$1$14);
8627
8627
  }
8628
8628
  static hasMarker(error, marker15) {
8629
8629
  const markerSymbol = Symbol.for(marker15);
8630
8630
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
8631
8631
  }
8632
8632
  };
8633
- var name$1$15 = "AI_APICallError";
8634
- var marker2$2 = `vercel.ai.error.${name$1$15}`;
8633
+ var name$1$14 = "AI_APICallError";
8634
+ var marker2$2 = `vercel.ai.error.${name$1$14}`;
8635
8635
  var symbol2$2 = Symbol.for(marker2$2);
8636
8636
  var _a2$2;
8637
8637
  var _b2$1;
8638
8638
  var APICallError$1 = class extends (_b2$1 = AISDKError$1, _a2$2 = symbol2$2, _b2$1) {
8639
8639
  constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
8640
8640
  super({
8641
- name: name$1$15,
8641
+ name: name$1$14,
8642
8642
  message,
8643
8643
  cause
8644
8644
  });
@@ -8994,6 +8994,8 @@ function extractResponseHeaders$1(response) {
8994
8994
  }
8995
8995
  var { btoa: btoa$2, atob: atob$4 } = globalThis;
8996
8996
  function convertUint8ArrayToBase64$1(array) {
8997
+ var _a2;
8998
+ if (typeof ((_a2 = globalThis.Buffer) == null ? void 0 : _a2.from) === "function") return globalThis.Buffer.from(array.buffer, array.byteOffset, array.byteLength).toString("base64");
8997
8999
  const chunks = [];
8998
9000
  const chunkSize = 4096;
8999
9001
  for (let i = 0; i < array.length; i += chunkSize) chunks.push(String.fromCodePoint(...array.subarray(i, i + chunkSize)));
@@ -9006,11 +9008,11 @@ async function cancelResponseBody$1(response) {
9006
9008
  } catch (e) {}
9007
9009
  }
9008
9010
  var name$19 = "AI_DownloadError";
9009
- var marker$12 = `vercel.ai.error.${name$19}`;
9010
- var symbol$20 = Symbol.for(marker$12);
9011
+ var marker$15 = `vercel.ai.error.${name$19}`;
9012
+ var symbol$21 = Symbol.for(marker$15);
9011
9013
  var _a$2;
9012
9014
  var _b$2;
9013
- var DownloadError$1 = class extends (_b$2 = AISDKError$1, _a$2 = symbol$20, _b$2) {
9015
+ var DownloadError$1 = class extends (_b$2 = AISDKError$1, _a$2 = symbol$21, _b$2) {
9014
9016
  constructor({ url, statusCode, statusText, cause, message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}` }) {
9015
9017
  super({
9016
9018
  name: name$19,
@@ -9023,7 +9025,7 @@ var DownloadError$1 = class extends (_b$2 = AISDKError$1, _a$2 = symbol$20, _b$2
9023
9025
  this.statusText = statusText;
9024
9026
  }
9025
9027
  static isInstance(error) {
9026
- return AISDKError$1.hasMarker(error, marker$12);
9028
+ return AISDKError$1.hasMarker(error, marker$15);
9027
9029
  }
9028
9030
  };
9029
9031
  function isBrowserRuntime$1(globalThisAny = globalThis) {
@@ -9453,7 +9455,7 @@ function withUserAgentSuffix$1(headers, ...userAgentSuffixParts) {
9453
9455
  normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
9454
9456
  return Object.fromEntries(normalizedHeaders.entries());
9455
9457
  }
9456
- var VERSION$5 = "4.0.62";
9458
+ var VERSION$5 = "4.0.63";
9457
9459
  var getOriginalFetch$1 = () => globalThis.fetch;
9458
9460
  var getFromApi$1 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, validateUrl, credentialedOrigin, trustedOrigin }) => {
9459
9461
  try {
@@ -10929,7 +10931,7 @@ var createJsonResponseHandler$1 = (responseSchema) => async ({ response, url, re
10929
10931
  function withoutTrailingSlash$1(url) {
10930
10932
  return url == null ? void 0 : url.replace(/\/$/, "");
10931
10933
  }
10932
- // ../_vendored/ai_v6/dist/dist-CFYPWO89.js
10934
+ // ../_vendored/ai_v6/dist/dist-BOyF24Gs.js
10933
10935
  function getContext$1() {
10934
10936
  return { headers: {} };
10935
10937
  }
@@ -10937,10 +10939,10 @@ async function getVercelOidcToken$1() {
10937
10939
  if (process.env.VERCEL_OIDC_TOKEN) return process.env.VERCEL_OIDC_TOKEN ?? "";
10938
10940
  throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
10939
10941
  }
10940
- var symbol$15 = Symbol.for("vercel.ai.gateway.error");
10942
+ var symbol$20 = Symbol.for("vercel.ai.gateway.error");
10941
10943
  var _a$1;
10942
10944
  var _b;
10943
- var GatewayError$1 = class _GatewayError extends (_b = Error, _a$1 = symbol$15, _b) {
10945
+ var GatewayError$1 = class _GatewayError extends (_b = Error, _a$1 = symbol$20, _b) {
10944
10946
  constructor({ message, statusCode = 500, cause, generationId, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500) }) {
10945
10947
  super(generationId ? `${message} [${generationId}]` : message);
10946
10948
  this[_a$1] = true;
@@ -10958,7 +10960,7 @@ var GatewayError$1 = class _GatewayError extends (_b = Error, _a$1 = symbol$15,
10958
10960
  return _GatewayError.hasMarker(error);
10959
10961
  }
10960
10962
  static hasMarker(error) {
10961
- return typeof error === "object" && error !== null && symbol$15 in error && error[symbol$15] === true;
10963
+ return typeof error === "object" && error !== null && symbol$20 in error && error[symbol$20] === true;
10962
10964
  }
10963
10965
  };
10964
10966
  var name$18 = "GatewayAuthenticationError";
@@ -12849,7 +12851,7 @@ async function getVercelRequestId$1() {
12849
12851
  var _a11;
12850
12852
  return (_a11 = getContext$1().headers) == null ? void 0 : _a11["x-vercel-id"];
12851
12853
  }
12852
- var VERSION$4 = "3.0.223";
12854
+ var VERSION$4 = "3.0.226";
12853
12855
  var AI_GATEWAY_PROTOCOL_VERSION$1 = "0.0.1";
12854
12856
  function createGatewayProvider(options = {}) {
12855
12857
  var _a11, _b11;
@@ -13872,8 +13874,8 @@ var __export = (target, all) => {
13872
13874
  });
13873
13875
  };
13874
13876
  var name$12 = "AI_InvalidArgumentError";
13875
- var marker$19 = `vercel.ai.error.${name$12}`;
13876
- var symbol$19 = Symbol.for(marker$19);
13877
+ var marker$12 = `vercel.ai.error.${name$12}`;
13878
+ var symbol$19 = Symbol.for(marker$12);
13877
13879
  var _a;
13878
13880
  var InvalidArgumentError$2 = class extends AISDKError$1 {
13879
13881
  constructor({ parameter, value, message }) {
@@ -13886,7 +13888,7 @@ var InvalidArgumentError$2 = class extends AISDKError$1 {
13886
13888
  this.value = value;
13887
13889
  }
13888
13890
  static isInstance(error) {
13889
- return AISDKError$1.hasMarker(error, marker$19);
13891
+ return AISDKError$1.hasMarker(error, marker$12);
13890
13892
  }
13891
13893
  };
13892
13894
  _a = symbol$19;
@@ -14025,7 +14027,7 @@ function getTotalTimeoutMs(timeout) {
14025
14027
  if (typeof timeout === "number") return timeout;
14026
14028
  return timeout.totalMs;
14027
14029
  }
14028
- var VERSION$3 = "6.0.317";
14030
+ var VERSION$3 = "6.0.320";
14029
14031
  var dataContentSchema = z$1.union([
14030
14032
  z$1.string(),
14031
14033
  z$1.instanceof(Uint8Array),
@@ -15221,7 +15223,7 @@ createIdGenerator$1({
15221
15223
  prefix: "aiobj",
15222
15224
  size: 24
15223
15225
  });
15224
- // ../_vendored/ai_v7/dist/dist-5fMURLh0.js
15226
+ // ../_vendored/ai_v7/dist/dist-DcSumJIg.js
15225
15227
  /**
15226
15228
  * Symbol used for identifying AI SDK Error instances.
15227
15229
  * Enables checking if an error is an instance of AISDKError across package versions.
@@ -15361,6 +15363,21 @@ var JSONParseError = class extends AISDKError {
15361
15363
  return AISDKError.hasMarker(error, marker$8$1);
15362
15364
  }
15363
15365
  };
15366
+ const name$7$1 = "AI_LoadAPIKeyError";
15367
+ const marker$7$1 = `vercel.ai.error.${name$7$1}`;
15368
+ const symbol$7$1 = Symbol.for(marker$7$1);
15369
+ var LoadAPIKeyError = class extends AISDKError {
15370
+ constructor({ message }) {
15371
+ super({
15372
+ name: name$7$1,
15373
+ message
15374
+ });
15375
+ this[symbol$7$1] = true;
15376
+ }
15377
+ static isInstance(error) {
15378
+ return AISDKError.hasMarker(error, marker$7$1);
15379
+ }
15380
+ };
15364
15381
  const name$1$1$1 = "AI_TypeValidationError";
15365
15382
  const marker$1$1$1 = `vercel.ai.error.${name$1$1$1}`;
15366
15383
  const symbol$1$1$1 = Symbol.for(marker$1$1$1);
@@ -15891,7 +15908,7 @@ function handleFetchError({ error, url, requestBodyValues }) {
15891
15908
  }
15892
15909
  return error;
15893
15910
  }
15894
- const VERSION$2 = "5.0.70";
15911
+ const VERSION$2 = "5.0.72";
15895
15912
  /**
15896
15913
  * Normalizes different header inputs into a plain record with lower-case keys.
15897
15914
  * Entries with `undefined` or `null` values are removed.
@@ -18382,7 +18399,7 @@ function isSegment(value) {
18382
18399
  function withoutTrailingSlash(url) {
18383
18400
  return url?.replace(/\/$/, "");
18384
18401
  }
18385
- // ../_vendored/ai_v7/dist/dist-DFcOzoAh.js
18402
+ // ../_vendored/ai_v7/dist/dist-fgnmtGCL.js
18386
18403
  /**
18387
18404
  * Symbol used to define custom serialization for user-defined class instances.
18388
18405
  * The static method should accept an instance and return serializable data.
@@ -18936,6 +18953,7 @@ function isTimeoutError(error) {
18936
18953
  return false;
18937
18954
  }
18938
18955
  async function asGatewayError(error, authMethod) {
18956
+ if ((error instanceof Error || typeof DOMException === "function" && error instanceof DOMException) && (error.name === "AbortError" || error.name === "TimeoutError")) throw error;
18939
18957
  if (GatewayError.isInstance(error)) return error;
18940
18958
  if (isTimeoutError(error)) return GatewayTimeoutError.createTimeoutError({
18941
18959
  originalMessage: error instanceof Error ? error.message : "Unknown error",
@@ -20385,7 +20403,7 @@ const gatewayRerankingResponseSchema = lazySchema(() => zodSchema(z$3.object({
20385
20403
  * synchronous, hence this helper.
20386
20404
  */
20387
20405
  async function errorControllerWithGatewayError(controller, error, authMethod) {
20388
- controller.error(await asGatewayError(error, authMethod));
20406
+ controller.error(await asGatewayError(error, authMethod).catch((error) => error));
20389
20407
  }
20390
20408
  /**
20391
20409
  * Extract a human-readable message from an `error` stream part's payload for
@@ -21558,7 +21576,7 @@ const gatewayTools = {
21558
21576
  async function getVercelRequestId() {
21559
21577
  return getContext().headers?.["x-vercel-id"];
21560
21578
  }
21561
- const VERSION$1 = "4.0.128";
21579
+ const VERSION$1 = "4.0.132";
21562
21580
  const AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
21563
21581
  /** Response shape of `POST /v1/realtime/client-secrets`. `expiresAt` is epoch seconds. */
21564
21582
  const gatewayClientSecretResponseSchema = lazySchema(() => zodSchema(z$3.object({
@@ -21581,9 +21599,11 @@ function createGateway(options = {}) {
21581
21599
  ...options.teamIdOrSlug != null ? { [VERCEL_AI_GATEWAY_TEAM_HEADER]: options.teamIdOrSlug } : {},
21582
21600
  ...options.headers
21583
21601
  }, `ai-sdk-gateway/${VERSION$1}`);
21584
- const getHeaders = async () => {
21602
+ const getHeaders = async (onResolved) => {
21585
21603
  try {
21586
- return createAuthHeaders(await getGatewayAuthToken(options));
21604
+ const headers = createAuthHeaders(await getGatewayAuthToken(options));
21605
+ onResolved?.(headers);
21606
+ return headers;
21587
21607
  } catch (error) {
21588
21608
  throw GatewayAuthenticationError.createContextualError({
21589
21609
  apiKeyProvided: false,
@@ -21683,44 +21703,56 @@ function createGateway(options = {}) {
21683
21703
  const now = options._internal?.currentDate?.().getTime() ?? Date.now();
21684
21704
  if (!pendingMetadata || now - lastFetchTime > cacheRefreshMillis) {
21685
21705
  lastFetchTime = now;
21706
+ let resolvedHeaders;
21686
21707
  pendingMetadata = new GatewayFetchMetadata({
21687
21708
  baseURL,
21688
- headers: getHeaders,
21709
+ headers: () => getHeaders((headers) => {
21710
+ resolvedHeaders = headers;
21711
+ }),
21689
21712
  fetch: options.fetch
21690
21713
  }).getAvailableModels().then((metadata) => {
21691
21714
  metadataCache = metadata;
21692
21715
  return metadata;
21693
21716
  }).catch(async (error) => {
21694
- throw await asGatewayError(error, await parseAuthMethod(await getHeaders()));
21717
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders ?? {}));
21695
21718
  });
21696
21719
  }
21697
21720
  return metadataCache ? Promise.resolve(metadataCache) : pendingMetadata;
21698
21721
  };
21699
21722
  const getCredits = async () => {
21723
+ let resolvedHeaders;
21700
21724
  return new GatewayFetchMetadata({
21701
21725
  baseURL,
21702
- headers: getHeaders,
21726
+ headers: () => getHeaders((headers) => {
21727
+ resolvedHeaders = headers;
21728
+ }),
21703
21729
  fetch: options.fetch
21704
21730
  }).getCredits().catch(async (error) => {
21705
- throw await asGatewayError(error, await parseAuthMethod(await getHeaders()));
21731
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders ?? {}));
21706
21732
  });
21707
21733
  };
21708
21734
  const getSpendReport = async (params) => {
21735
+ let resolvedHeaders;
21709
21736
  return new GatewaySpendReport({
21710
21737
  baseURL,
21711
- headers: getHeaders,
21738
+ headers: () => getHeaders((headers) => {
21739
+ resolvedHeaders = headers;
21740
+ }),
21712
21741
  fetch: options.fetch
21713
21742
  }).getSpendReport(params).catch(async (error) => {
21714
- throw await asGatewayError(error, await parseAuthMethod(await getHeaders()));
21743
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders ?? {}));
21715
21744
  });
21716
21745
  };
21717
21746
  const getGenerationInfo = async (params) => {
21747
+ let resolvedHeaders;
21718
21748
  return new GatewayGenerationInfoFetcher({
21719
21749
  baseURL,
21720
- headers: getHeaders,
21750
+ headers: () => getHeaders((headers) => {
21751
+ resolvedHeaders = headers;
21752
+ }),
21721
21753
  fetch: options.fetch
21722
21754
  }).getGenerationInfo(params).catch(async (error) => {
21723
- throw await asGatewayError(error, await parseAuthMethod(await getHeaders()));
21755
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders ?? {}));
21724
21756
  });
21725
21757
  };
21726
21758
  const provider = function(modelId) {
@@ -21859,8 +21891,10 @@ function createGateway(options = {}) {
21859
21891
  }
21860
21892
  const gateway = createGateway();
21861
21893
  async function getGatewayAuthToken(options) {
21894
+ const resolvedApiKey = typeof options.apiKey === "string" || options.apiKey == null ? options.apiKey : await resolve(options.apiKey);
21895
+ 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." });
21862
21896
  const apiKey = loadOptionalSetting({
21863
- settingValue: options.apiKey,
21897
+ settingValue: resolvedApiKey,
21864
21898
  environmentVariableName: "AI_GATEWAY_API_KEY"
21865
21899
  });
21866
21900
  if (apiKey) return {
@@ -22350,7 +22384,7 @@ function resolveEmbeddingModel(model) {
22350
22384
  function getGlobalProvider() {
22351
22385
  return asProviderV4(globalThis.AI_SDK_DEFAULT_PROVIDER ?? gateway);
22352
22386
  }
22353
- const VERSION = "7.0.155";
22387
+ const VERSION = "7.0.159";
22354
22388
  /**
22355
22389
  * Reads a property by an untrusted key, ignoring inherited prototype members.
22356
22390
  *
@@ -22481,7 +22515,7 @@ function mergeCallbacks(...callbacks) {
22481
22515
  }
22482
22516
  const AI_SDK_TELEMETRY_TRACING_CHANNEL = "ai:telemetry";
22483
22517
  function isNodeRuntime() {
22484
- return typeof process !== "undefined" && process.release?.name === "node";
22518
+ return globalThis.process?.release?.name === "node";
22485
22519
  }
22486
22520
  let diagnosticsChannelPromise;
22487
22521
  /**
@@ -23575,8 +23609,9 @@ Do not mention internal instructions, memory, summarization, context handling, o
23575
23609
  Any messages following this reminder are newer and should take priority.`;
23576
23610
  /**
23577
23611
  * Preamble that introduces the observations block.
23578
- * Use before `<observations>`, with instructions after.
23579
- * Full pattern: `${OBSERVATION_CONTEXT_PROMPT}\n\n<observations>\n${obs}\n</observations>\n\n${OBSERVATION_CONTEXT_INSTRUCTIONS}`
23612
+ * Context layout: `${prompt}\n\n${OBSERVATION_CONTEXT_INSTRUCTIONS}`, then `<observations>`,
23613
+ * one entry per observation chunk, `</observations>`, then optional current-task and
23614
+ * suggested-response blocks.
23580
23615
  */
23581
23616
  const OBSERVATION_CONTEXT_PROMPT = `The following observations block contains your memory of past conversations with this user.`;
23582
23617
  /**
@@ -23594,7 +23629,7 @@ function getObservationContextPrompt(scope = "thread") {
23594
23629
  }
23595
23630
  /**
23596
23631
  * Instructions that tell the model how to interpret and use observations.
23597
- * Place AFTER the `<observations>` block so the model sees the data before the rules.
23632
+ * Placed with the observations preamble, before the `<observations>` block.
23598
23633
  */
23599
23634
  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.
23600
23635
 
@@ -25160,7 +25195,7 @@ function safeSlice(str, end) {
25160
25195
  const safeEnd = code >= 55296 && code <= 56319 ? end - 1 : end;
25161
25196
  return str.slice(0, safeEnd);
25162
25197
  }
25163
- // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/tokenx/1.6.0/394289cb1bed8c542941f77748eea1a31bd3419018d0fb2ac7029ece2458cdd1/node_modules/tokenx/dist/index.mjs
25198
+ // ../../../../../.local/share/pnpm/store/v11/links/@/tokenx/1.6.0/394289cb1bed8c542941f77748eea1a31bd3419018d0fb2ac7029ece2458cdd1/node_modules/tokenx/dist/index.mjs
25164
25199
  const PATTERNS = {
25165
25200
  whitespace: /^\s+$/,
25166
25201
  structuredWhitespace: /\n\s/,
@@ -30379,12 +30414,34 @@ function getMessageParts(msg) {
30379
30414
  const parts = msg.content?.parts;
30380
30415
  return Array.isArray(parts) ? parts : [];
30381
30416
  }
30382
- /** Returns true if a message has at least one non-data part with visible content. */
30417
+ /**
30418
+ * Returns true if recall can render at least one visible part of a message.
30419
+ * Mirrors the skip rules in `formatMessageParts` without formatting tool results.
30420
+ */
30383
30421
  function hasVisibleParts(msg) {
30384
- if (typeof msg.content === "string") return msg.content.length > 0;
30422
+ if (typeof msg.content === "string") return true;
30385
30423
  const parts = getMessageParts(msg);
30386
30424
  if (parts.length === 0) return Boolean(msg.content?.content);
30387
- return parts.some((p) => !p.type?.startsWith("data-"));
30425
+ return parts.some(isVisiblePart);
30426
+ }
30427
+ function isVisiblePart(part) {
30428
+ const partType = part?.type;
30429
+ switch (partType) {
30430
+ case void 0:
30431
+ case "":
30432
+ case "reasoning":
30433
+ case "redacted-reasoning":
30434
+ case "step-start": return false;
30435
+ case "text": return Boolean(part.text);
30436
+ case "tool-invocation": {
30437
+ const inv = part.toolInvocation;
30438
+ if (!inv?.toolName) return false;
30439
+ return inv.state !== "partial-call" && inv.args != null || inv.state === "result";
30440
+ }
30441
+ case "tool-call":
30442
+ case "tool-result": return Boolean(part.toolName);
30443
+ default: return !partType.startsWith("data-");
30444
+ }
30388
30445
  }
30389
30446
  function parseRangeFormat(cursor) {
30390
30447
  if (cursor.includes(",")) {
@@ -30498,7 +30555,7 @@ async function listThreadsForResource({ memory, resourceId, currentThreadId, pag
30498
30555
  hasMore
30499
30556
  };
30500
30557
  }
30501
- 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.";
30558
+ 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.";
30502
30559
  async function searchMessagesForResource({ memory, om, resourceId, currentThreadId, query, topK = 10, maxTokens = DEFAULT_MAX_RESULT_TOKENS, before, after, threadScope, includeThreadId = true, currentMessages = [] }) {
30503
30560
  if (!memory.searchMessages) return {
30504
30561
  results: SEARCH_NOT_CONFIGURED_MESSAGE,
@@ -31016,11 +31073,8 @@ function formatMessageParts(msg, detail) {
31016
31073
  const fullText = `[Tool Result: ${toolName}]\n${formatToolResultForObserver(omitInlineMediaPayloads(part.output ?? part.result), { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS })}`;
31017
31074
  parts.push(makePart(msg, i, "tool-result", fullText, detail, toolName));
31018
31075
  }
31019
- } else if (partType === "reasoning") {
31020
- const reasoning = part.reasoning ?? part.text;
31021
- if (reasoning) parts.push(makePart(msg, i, "reasoning", reasoning, detail));
31022
- } else if (partType === "image" || partType === "file") parts.push(makePart(msg, i, partType, formatAttachmentPart(partType, part), detail));
31023
- else if (partType?.startsWith("data-")) {} else if (partType) {
31076
+ } else if (partType === "reasoning" || partType === "redacted-reasoning") {} else if (partType === "image" || partType === "file") parts.push(makePart(msg, i, partType, formatAttachmentPart(partType, part), detail));
31077
+ else if (partType === "step-start" || partType?.startsWith("data-")) {} else if (partType) {
31024
31078
  const fullText = `[${partType}]`;
31025
31079
  parts.push({
31026
31080
  messageId: msg.id,
@@ -31051,12 +31105,29 @@ function buildRenderedText(parts, timestamps) {
31051
31105
  }
31052
31106
  return lines.join("\n");
31053
31107
  }
31108
+ /**
31109
+ * Reads messages until `needed` of them are visible or storage is exhausted, growing the
31110
+ * request each round. Hidden messages (reasoning-only, step boundaries, OM markers) don't
31111
+ * count toward `needed`, so a run of them can't end paging early.
31112
+ */
31113
+ async function recallVisibleMessages(memory, args, needed, perPage = needed) {
31114
+ let previousCount = -1;
31115
+ while (true) {
31116
+ const result = await memory.recall({
31117
+ ...args,
31118
+ page: 0,
31119
+ perPage
31120
+ });
31121
+ const visible = result.messages.filter(hasVisibleParts);
31122
+ if (visible.length >= needed || !result.hasMore || result.messages.length <= previousCount) return visible;
31123
+ previousCount = result.messages.length;
31124
+ perPage *= 2;
31125
+ }
31126
+ }
31054
31127
  async function getNextVisibleMessage({ memory, threadId, resourceId, after }) {
31055
- return (await memory.recall({
31128
+ return (await recallVisibleMessages(memory, {
31056
31129
  threadId,
31057
31130
  resourceId,
31058
- page: 0,
31059
- perPage: 50,
31060
31131
  orderBy: {
31061
31132
  field: "createdAt",
31062
31133
  direction: "ASC"
@@ -31065,7 +31136,7 @@ async function getNextVisibleMessage({ memory, threadId, resourceId, after }) {
31065
31136
  start: after,
31066
31137
  startExclusive: true
31067
31138
  } }
31068
- })).messages.find(hasVisibleParts) ?? null;
31139
+ }, 1, 50))[0] ?? null;
31069
31140
  }
31070
31141
  const MAX_EXPAND_USER_TEXT_TOKENS = 200;
31071
31142
  const MAX_EXPAND_OTHER_TOKENS = 50;
@@ -31075,7 +31146,7 @@ function expandLimit(part) {
31075
31146
  }
31076
31147
  function expandPriority(part) {
31077
31148
  if (part.role === "user" && part.type === "text") return 0;
31078
- if (part.type === "text" || part.type === "reasoning") return 1;
31149
+ if (part.type === "text") return 1;
31079
31150
  if (part.type === "tool-result") return 2;
31080
31151
  if (part.type === "tool-call") return 3;
31081
31152
  return 4;
@@ -31261,11 +31332,9 @@ async function recallMessages({ memory, threadId, resourceId, cursor, page = 1,
31261
31332
  const pageIndex = Math.max(Math.abs(normalizedPage), 1) - 1;
31262
31333
  const skip = pageIndex * normalizedLimit;
31263
31334
  const fetchCount = skip + normalizedLimit + 1;
31264
- const visibleMessages = (await memory.recall({
31335
+ const visibleMessages = await recallVisibleMessages(memory, {
31265
31336
  threadId: resolvedThreadId,
31266
31337
  resourceId,
31267
- page: 0,
31268
- perPage: fetchCount,
31269
31338
  orderBy: {
31270
31339
  field: "createdAt",
31271
31340
  direction: isForward ? "ASC" : "DESC"
@@ -31277,7 +31346,7 @@ async function recallMessages({ memory, threadId, resourceId, cursor, page = 1,
31277
31346
  end: anchor.createdAt,
31278
31347
  endExclusive: true
31279
31348
  } }
31280
- })).messages.filter(hasVisibleParts);
31349
+ }, fetchCount);
31281
31350
  const total = visibleMessages.length;
31282
31351
  const hasMore = total > skip + normalizedLimit;
31283
31352
  let messages;
@@ -31360,17 +31429,15 @@ async function recallThreadFromStart({ memory, threadId, resourceId, page = 1, l
31360
31429
  const normalizedLimit = Math.min(Math.max(limit, 1), MAX_LIMIT);
31361
31430
  const pageIndex = normalizedPage - 1;
31362
31431
  const fetchCount = pageIndex * normalizedLimit + normalizedLimit + 1;
31363
- const result = await memory.recall({
31432
+ const fetched = await recallVisibleMessages(memory, {
31364
31433
  threadId,
31365
31434
  resourceId,
31366
- page: 0,
31367
- perPage: fetchCount,
31368
31435
  orderBy: {
31369
31436
  field: "createdAt",
31370
31437
  direction: anchor === "end" ? "DESC" : "ASC"
31371
31438
  }
31372
- });
31373
- const visibleMessages = anchor === "end" ? result.messages.slice(0, fetchCount).filter(hasVisibleParts).reverse() : result.messages.slice(0, fetchCount).filter(hasVisibleParts);
31439
+ }, fetchCount);
31440
+ const visibleMessages = anchor === "end" ? fetched.reverse() : fetched;
31374
31441
  const skip = pageIndex * normalizedLimit;
31375
31442
  const messages = visibleMessages.slice(skip, skip + normalizedLimit);
31376
31443
  const hasExtraMessage = visibleMessages.length > skip + messages.length;
@@ -31505,7 +31572,6 @@ const recallTool = (_memoryConfig, options) => {
31505
31572
  "text",
31506
31573
  "tool-call",
31507
31574
  "tool-result",
31508
- "reasoning",
31509
31575
  "image",
31510
31576
  "file"
31511
31577
  ],
@@ -37700,7 +37766,7 @@ var ObservationalMemory = class ObservationalMemory {
37700
37766
  const messages = [`${getObservationContextPrompt(this.scope)}\n\n${OBSERVATION_CONTEXT_INSTRUCTIONS}${retrieval ? `\n\n${getRetrievalInstructions(this.retrievalScope, this.retrievalInstructions, this.retrievalSearch, this.storage.supportsObservationalMemoryHistorySearch === true)}` : ""}`];
37701
37767
  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`);
37702
37768
  const observationChunks = this.splitObservationContextChunks(optimized);
37703
- if (observationChunks.length > 0) messages.push("<observations>", ...observationChunks);
37769
+ if (observationChunks.length > 0) messages.push("<observations>", ...observationChunks, "</observations>");
37704
37770
  if (currentTask) messages.push(`<current-task>\n${currentTask}\n</current-task>`);
37705
37771
  if (suggestedResponse) messages.push(`<suggested-response>\n${suggestedResponse}\n</suggested-response>`);
37706
37772
  messages.push(...buildExtractedValueContextSections([...this.observationConfig.extractors, ...this.reflectionConfig.extractors], extractedValues));
@@ -40158,7 +40224,7 @@ var Memory = class Memory extends MastraMemory {
40158
40224
  const omConfig = normalizeObservationalMemoryConfig(mergedConfig.observationalMemory);
40159
40225
  if (omConfig?.retrieval && typeof omConfig.retrieval === "object" && omConfig.retrieval.vector) {
40160
40226
  if (!this.vector) throw new Error("`retrieval: { vector: true }` requires a vector store. Pass a `vector` option to your Memory instance.");
40161
- if (!this.embedder) throw new Error("`retrieval: { vector: true }` requires an embedder. Pass an `embedder` option to your Memory instance.");
40227
+ 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.");
40162
40228
  }
40163
40229
  }
40164
40230
  /**
@@ -41340,8 +41406,9 @@ Notes:
41340
41406
  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.");
41341
41407
  }
41342
41408
  getObservationEmbeddingIndexName(dimensions) {
41343
- const usedDimensions = dimensions ?? 384;
41344
41409
  const separator = this.vector?.indexSeparator ?? "_";
41410
+ if (this.isSelfEmbedding) return `${this.observationIndexPrefix}${separator}selfembed`;
41411
+ const usedDimensions = dimensions ?? 384;
41345
41412
  return `${this.observationIndexPrefix}${separator}${usedDimensions}`;
41346
41413
  }
41347
41414
  async createObservationEmbeddingIndex(dimensions) {
@@ -41350,7 +41417,7 @@ Notes:
41350
41417
  if (typeof this.vector === `undefined`) throw new Error(`Tried to create observation embedding index but no vector db is attached to this Memory instance.`);
41351
41418
  await this.vector.createIndex({
41352
41419
  indexName,
41353
- dimension: usedDimensions,
41420
+ ...this.isSelfEmbedding ? {} : { dimension: usedDimensions },
41354
41421
  metadataIndexes: ["resource_id", "thread_id"]
41355
41422
  });
41356
41423
  return { indexName };
@@ -41361,7 +41428,14 @@ Notes:
41361
41428
  */
41362
41429
  async searchMessages({ query, resourceId, topK = 10, filter }) {
41363
41430
  if (!this.vector) throw new Error("searchMessages requires a vector store. Configure vector and embedder on your Memory instance.");
41364
- const { embeddings, dimension } = await this.embedMessageContent(query);
41431
+ const queries = [];
41432
+ let dimension;
41433
+ if (this.isSelfEmbedding) queries.push({ queryText: query });
41434
+ else {
41435
+ const embedResult = await this.embedMessageContent(query);
41436
+ dimension = embedResult.dimension;
41437
+ queries.push(...embedResult.embeddings.map((queryVector) => ({ queryVector })));
41438
+ }
41365
41439
  const { indexName } = await this.createObservationEmbeddingIndex(dimension);
41366
41440
  const vectorFilter = { resource_id: resourceId };
41367
41441
  if (filter?.threadId) vectorFilter.thread_id = filter.threadId;
@@ -41370,10 +41444,10 @@ Notes:
41370
41444
  ...filter.observedBefore ? { $lt: filter.observedBefore.toISOString() } : {}
41371
41445
  };
41372
41446
  const queryResults = [];
41373
- await Promise.all(embeddings.map(async (embedding) => {
41447
+ await Promise.all(queries.map(async (params) => {
41374
41448
  const results = await this.vector.query({
41375
41449
  indexName,
41376
- queryVector: embedding,
41450
+ ...params,
41377
41451
  topK,
41378
41452
  filter: vectorFilter
41379
41453
  });
@@ -41404,12 +41478,21 @@ Notes:
41404
41478
  * Index a single observation group into the observation vector store.
41405
41479
  */
41406
41480
  async indexObservation({ text, groupId, range, threadId, resourceId, observedAt, recordId }) {
41407
- if (!this.vector || !this.embedder) return;
41408
- const embedResult = await this.embedMessageContent(text);
41409
- if (embedResult.embeddings.length === 0 || embedResult.dimension === void 0) return;
41410
- const { indexName } = await this.createObservationEmbeddingIndex(embedResult.dimension);
41481
+ if (!this.vector || !this.embedder && !this.isSelfEmbedding) return;
41482
+ let chunks;
41483
+ let embeddings = [];
41484
+ let dimension;
41485
+ if (this.isSelfEmbedding) {
41486
+ chunks = this.chunkText(text);
41487
+ if (chunks.length === 0) return;
41488
+ } else {
41489
+ const embedResult = await this.embedMessageContent(text);
41490
+ ({chunks, embeddings, dimension} = embedResult);
41491
+ if (embeddings.length === 0 || dimension === void 0) return;
41492
+ }
41493
+ const { indexName } = await this.createObservationEmbeddingIndex(dimension);
41411
41494
  const ids = [];
41412
- for (const [chunkIndex] of embedResult.chunks.entries()) {
41495
+ for (const [chunkIndex] of chunks.entries()) {
41413
41496
  const hash = Buffer.from(await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify([
41414
41497
  resourceId,
41415
41498
  threadId,
@@ -41421,19 +41504,26 @@ Notes:
41421
41504
  const hex = hash.toString("hex", 0, 16);
41422
41505
  ids.push(`${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`);
41423
41506
  }
41424
- await this.vector.upsert({
41507
+ const metadata = chunks.map((chunk) => ({
41508
+ group_id: groupId,
41509
+ range,
41510
+ thread_id: threadId,
41511
+ resource_id: resourceId,
41512
+ observed_at: observedAt?.toISOString(),
41513
+ ...recordId ? { record_id: recordId } : {},
41514
+ text: chunk
41515
+ }));
41516
+ if (this.isSelfEmbedding) await this.vector.upsert({
41425
41517
  indexName,
41426
41518
  ids,
41427
- vectors: embedResult.embeddings,
41428
- metadata: embedResult.chunks.map((chunk) => ({
41429
- group_id: groupId,
41430
- range,
41431
- thread_id: threadId,
41432
- resource_id: resourceId,
41433
- observed_at: observedAt?.toISOString(),
41434
- ...recordId ? { record_id: recordId } : {},
41435
- text: chunk
41436
- }))
41519
+ documents: chunks,
41520
+ metadata
41521
+ });
41522
+ else await this.vector.upsert({
41523
+ indexName,
41524
+ ids,
41525
+ vectors: embeddings,
41526
+ metadata
41437
41527
  });
41438
41528
  }
41439
41529
  /**
@@ -41590,11 +41680,12 @@ Notes:
41590
41680
  }
41591
41681
  /**
41592
41682
  * Check whether retrieval search (vector-based) is enabled.
41593
- * Returns true when `retrieval: { vector: true }` and Memory has vector + embedder configured.
41683
+ * Returns true when `retrieval: { vector: true }` and Memory has a vector store plus either an
41684
+ * embedder or a store that generates embeddings itself.
41594
41685
  */
41595
41686
  hasRetrievalSearch(retrieval) {
41596
41687
  if (!retrieval || retrieval === true) return false;
41597
- return !!retrieval.vector && !!this.vector && !!this.embedder;
41688
+ return !!retrieval.vector && !!this.vector && (!!this.embedder || this.isSelfEmbedding);
41598
41689
  }
41599
41690
  listTools(config) {
41600
41691
  const mergedConfig = this.getMergedThreadConfig(config);
@@ -42075,15 +42166,22 @@ Notes:
42075
42166
  const vector = this.vector;
42076
42167
  const indexes = await this.getMemoryVectorIndexes([this.observationIndexPrefix]);
42077
42168
  for (const indexName of indexes) {
42078
- const { dimension } = await vector.describeIndex({ indexName });
42079
- const queryVector = Array.from({ length: dimension }, (_, i) => i === 0 ? 1 : 0);
42169
+ const selfEmbedded = this.isSelfEmbedding && indexName === this.getObservationEmbeddingIndexName();
42170
+ let readParams;
42171
+ if (selfEmbedded) readParams = { queryText: "observations" };
42172
+ else {
42173
+ const { dimension } = await vector.describeIndex({ indexName });
42174
+ readParams = {
42175
+ queryVector: Array.from({ length: dimension }, (_, i) => i === 0 ? 1 : 0),
42176
+ includeVector: true
42177
+ };
42178
+ }
42080
42179
  const moved = /* @__PURE__ */ new Set();
42081
42180
  for (;;) {
42082
42181
  const pending = (await vector.query({
42083
42182
  indexName,
42084
- queryVector,
42183
+ ...readParams,
42085
42184
  topK: 20,
42086
- includeVector: true,
42087
42185
  filter: {
42088
42186
  thread_id: threadId,
42089
42187
  resource_id: { $ne: resourceId }
@@ -42429,4 +42527,4 @@ Notes:
42429
42527
  };
42430
42528
  export { summarizeConversation as A, injectAnchorIds as B, wrapInObservationGroup as C, WorkingMemoryExtractor as D, Subconscious as E, extractCurrentTask as F, OBSERVATION_CONTEXT_INSTRUCTIONS as G, stripEphemeralAnchorIds as H, formatMessagesForObserver as I, OBSERVATION_CONTINUATION_HINT as J, OBSERVATION_CONTEXT_PROMPT as K, hasCurrentTaskSection as L, OBSERVER_SYSTEM_PROMPT as M, buildObserverPrompt as N, deepMergeWorkingMemory as O, buildObserverSystemPrompt as P, optimizeObservationsForContext as R, stripObservationGroups as S, StaleKnowledgeSemanticIndexError as T, Extractor as U, parseAnchorId as V, OBSERVATIONAL_MEMORY_DEFAULTS as W, getObservationContextPrompt as Y, combineObservationGroupRanges as _, extractWorkingMemoryContent as a, reconcileObservationGroupsFromReflection as b, getObservationsAsOf as c, AUTO_MODEL_BY_PROVIDER as d, resolveAutoModelId as f, ModelByInputTokens as g, WorkingMemoryStateProcessor as h, WorkingMemory as i, TokenCounter as j, SUMMARIZE_THREAD_DEFAULTS as k, ObservationalMemoryProcessor as l, WORKING_MEMORY_STATE_PROCESSOR_ID as m, MessageHistory$1 as n, extractWorkingMemoryTags as o, WORKING_MEMORY_STATE_ID as p, OBSERVATION_CONTEXT_PROMPT_THREAD as q, SemanticRecall as r, removeWorkingMemoryTags as s, Memory as t, ObservationalMemory as u, deriveObservationGroupProvenance as v, KnowledgeSemanticIndexCoordinator as w, renderObservationGroupsForReflection as x, parseObservationGroups as y, parseObserverOutput as z };
42431
42529
 
42432
- //# sourceMappingURL=src-CBYx0iwC.js.map
42530
+ //# sourceMappingURL=src-DHH_IVZI.js.map