@mastra/memory 1.17.6-alpha.0 → 1.18.0-alpha.2

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 (31) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/{chunk-ZUUSLGY6.cjs → chunk-MJNTQ6GP.cjs} +84 -31
  3. package/dist/chunk-MJNTQ6GP.cjs.map +1 -0
  4. package/dist/{chunk-NUYSX3DD.js → chunk-PBZHHKPE.js} +84 -31
  5. package/dist/chunk-PBZHHKPE.js.map +1 -0
  6. package/dist/docs/SKILL.md +1 -1
  7. package/dist/docs/assets/SOURCE_MAP.json +39 -39
  8. package/dist/docs/references/docs-agents-background-tasks.md +62 -2
  9. package/dist/docs/references/docs-memory-observational-memory.md +7 -2
  10. package/dist/docs/references/docs-memory-overview.md +2 -1
  11. package/dist/docs/references/docs-memory-semantic-recall.md +68 -6
  12. package/dist/index.cjs +329 -177
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +320 -168
  16. package/dist/index.js.map +1 -1
  17. package/dist/{observational-memory-KH7G7Y6B.js → observational-memory-IP2RVQQG.js} +3 -3
  18. package/dist/{observational-memory-KH7G7Y6B.js.map → observational-memory-IP2RVQQG.js.map} +1 -1
  19. package/dist/{observational-memory-BOXSRJOR.cjs → observational-memory-TASIB4PH.cjs} +26 -26
  20. package/dist/{observational-memory-BOXSRJOR.cjs.map → observational-memory-TASIB4PH.cjs.map} +1 -1
  21. package/dist/processors/index.cjs +24 -24
  22. package/dist/processors/index.js +1 -1
  23. package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts.map +1 -1
  24. package/dist/processors/observational-memory/observation-turn/load-memory-context.d.ts +9 -0
  25. package/dist/processors/observational-memory/observation-turn/load-memory-context.d.ts.map +1 -0
  26. package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -1
  27. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  28. package/dist/processors/observational-memory/processor.d.ts.map +1 -1
  29. package/package.json +4 -4
  30. package/dist/chunk-NUYSX3DD.js.map +0 -1
  31. package/dist/chunk-ZUUSLGY6.cjs.map +0 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { truncateStringByTokens, resolveToolResultValue, formatToolResultForObserver } from './chunk-NUYSX3DD.js';
2
- export { ModelByInputTokens, getObservationsAsOf } from './chunk-NUYSX3DD.js';
1
+ import { truncateStringByTokens, resolveToolResultValue, formatToolResultForObserver } from './chunk-PBZHHKPE.js';
2
+ export { ModelByInputTokens, getObservationsAsOf } from './chunk-PBZHHKPE.js';
3
3
  import { ZodFirstPartyTypeKind } from 'zod/v3';
4
4
  import { z } from 'zod';
5
5
  import * as z4 from 'zod/v4';
@@ -17,7 +17,7 @@ import { estimateTokenCount } from 'tokenx';
17
17
  import { isStandardSchemaWithJSON as isStandardSchemaWithJSON$1, toStandardSchema as toStandardSchema$1 } from '@mastra/core/schema';
18
18
  export { MessageHistory, SemanticRecall, WorkingMemory } from '@mastra/core/processors';
19
19
 
20
- // ../_vendored/ai_v4/dist/chunk-OPIPXJLE.js
20
+ // ../_vendored/ai_v4/dist/chunk-HB6FLTHO.js
21
21
  var __create = Object.create;
22
22
  var __defProp = Object.defineProperty;
23
23
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -4291,6 +4291,9 @@ var ParseError = class extends Error {
4291
4291
  super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
4292
4292
  }
4293
4293
  };
4294
+ var LF = 10;
4295
+ var CR = 13;
4296
+ var SPACE = 32;
4294
4297
  function noop(_arg) {
4295
4298
  }
4296
4299
  function createParser(callbacks) {
@@ -4298,39 +4301,109 @@ function createParser(callbacks) {
4298
4301
  throw new TypeError(
4299
4302
  "`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
4300
4303
  );
4301
- const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
4302
- let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
4303
- function feed(newChunk) {
4304
- const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
4305
- for (const line of complete)
4306
- parseLine(line);
4307
- incompleteLine = incomplete, isFirstChunk = false;
4308
- }
4309
- function parseLine(line) {
4310
- if (line === "") {
4304
+ const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks, pendingFragments = [];
4305
+ let isFirstChunk = true, id, data = "", dataLines = 0, eventType;
4306
+ function feed(chunk) {
4307
+ if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
4308
+ const trailing2 = processLines(chunk);
4309
+ trailing2 !== "" && pendingFragments.push(trailing2);
4310
+ return;
4311
+ }
4312
+ if (chunk.indexOf(`
4313
+ `) === -1 && chunk.indexOf("\r") === -1) {
4314
+ pendingFragments.push(chunk);
4315
+ return;
4316
+ }
4317
+ pendingFragments.push(chunk);
4318
+ const input = pendingFragments.join("");
4319
+ pendingFragments.length = 0;
4320
+ const trailing = processLines(input);
4321
+ trailing !== "" && pendingFragments.push(trailing);
4322
+ }
4323
+ function processLines(chunk) {
4324
+ let searchIndex = 0;
4325
+ if (chunk.indexOf("\r") === -1) {
4326
+ let lfIndex = chunk.indexOf(`
4327
+ `, searchIndex);
4328
+ for (; lfIndex !== -1; ) {
4329
+ if (searchIndex === lfIndex) {
4330
+ dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
4331
+ `, searchIndex);
4332
+ continue;
4333
+ }
4334
+ const firstCharCode = chunk.charCodeAt(searchIndex);
4335
+ if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
4336
+ const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
4337
+ if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
4338
+ onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
4339
+ `, searchIndex);
4340
+ continue;
4341
+ }
4342
+ data = dataLines === 0 ? value : `${data}
4343
+ ${value}`, dataLines++;
4344
+ } else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
4345
+ chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
4346
+ lfIndex
4347
+ ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
4348
+ searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
4349
+ `, searchIndex);
4350
+ }
4351
+ return chunk.slice(searchIndex);
4352
+ }
4353
+ for (; searchIndex < chunk.length; ) {
4354
+ const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
4355
+ `, searchIndex);
4356
+ let lineEnd = -1;
4357
+ if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
4358
+ break;
4359
+ parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
4360
+ }
4361
+ return chunk.slice(searchIndex);
4362
+ }
4363
+ function parseLine(chunk, start, end) {
4364
+ if (start === end) {
4311
4365
  dispatchEvent();
4312
4366
  return;
4313
4367
  }
4314
- if (line.startsWith(":")) {
4315
- onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
4368
+ const firstCharCode = chunk.charCodeAt(start);
4369
+ if (isDataPrefix(chunk, start, firstCharCode)) {
4370
+ const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
4371
+ data = dataLines === 0 ? value2 : `${data}
4372
+ ${value2}`, dataLines++;
4373
+ return;
4374
+ }
4375
+ if (isEventPrefix(chunk, start, firstCharCode)) {
4376
+ eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
4377
+ return;
4378
+ }
4379
+ if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
4380
+ const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
4381
+ id = value2.includes("\0") ? void 0 : value2;
4382
+ return;
4383
+ }
4384
+ if (firstCharCode === 58) {
4385
+ if (onComment) {
4386
+ const line2 = chunk.slice(start, end);
4387
+ onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
4388
+ }
4316
4389
  return;
4317
4390
  }
4318
- const fieldSeparatorIndex = line.indexOf(":");
4319
- if (fieldSeparatorIndex !== -1) {
4320
- const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
4321
- processField(field, value, line);
4391
+ const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
4392
+ if (fieldSeparatorIndex === -1) {
4393
+ processField(line, "", line);
4322
4394
  return;
4323
4395
  }
4324
- processField(line, "", line);
4396
+ const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
4397
+ processField(field, value, line);
4325
4398
  }
4326
4399
  function processField(field, value, line) {
4327
4400
  switch (field) {
4328
4401
  case "event":
4329
- eventType = value;
4402
+ eventType = value || void 0;
4330
4403
  break;
4331
4404
  case "data":
4332
- data = `${data}${value}
4333
- `;
4405
+ data = dataLines === 0 ? value : `${data}
4406
+ ${value}`, dataLines++;
4334
4407
  break;
4335
4408
  case "id":
4336
4409
  id = value.includes("\0") ? void 0 : value;
@@ -4355,37 +4428,26 @@ function createParser(callbacks) {
4355
4428
  }
4356
4429
  }
4357
4430
  function dispatchEvent() {
4358
- data.length > 0 && onEvent({
4431
+ dataLines > 0 && onEvent({
4359
4432
  id,
4360
- event: eventType || void 0,
4361
- // If the data buffer's last character is a U+000A LINE FEED (LF) character,
4362
- // then remove the last character from the data buffer.
4363
- data: data.endsWith(`
4364
- `) ? data.slice(0, -1) : data
4365
- }), id = void 0, data = "", eventType = "";
4433
+ event: eventType,
4434
+ data
4435
+ }), id = void 0, data = "", dataLines = 0, eventType = void 0;
4366
4436
  }
4367
4437
  function reset(options = {}) {
4368
- incompleteLine && options.consume && parseLine(incompleteLine), isFirstChunk = true, id = void 0, data = "", eventType = "", incompleteLine = "";
4438
+ if (options.consume && pendingFragments.length > 0) {
4439
+ const incompleteLine = pendingFragments.join("");
4440
+ parseLine(incompleteLine, 0, incompleteLine.length);
4441
+ }
4442
+ isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0;
4369
4443
  }
4370
4444
  return { feed, reset };
4371
4445
  }
4372
- function splitLines(chunk) {
4373
- const lines = [];
4374
- let incompleteLine = "", searchIndex = 0;
4375
- for (; searchIndex < chunk.length; ) {
4376
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
4377
- `, searchIndex);
4378
- let lineEnd = -1;
4379
- if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
4380
- incompleteLine = chunk.slice(searchIndex);
4381
- break;
4382
- } else {
4383
- const line = chunk.slice(searchIndex, lineEnd);
4384
- lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
4385
- ` && searchIndex++;
4386
- }
4387
- }
4388
- return [lines, incompleteLine];
4446
+ function isDataPrefix(chunk, i, firstCharCode) {
4447
+ return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
4448
+ }
4449
+ function isEventPrefix(chunk, i, firstCharCode) {
4450
+ return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
4389
4451
  }
4390
4452
  var EventSourceParserStream = class extends TransformStream {
4391
4453
  constructor({ onError, onRetry, onComment } = {}) {
@@ -4561,7 +4623,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
4561
4623
  );
4562
4624
  return Object.fromEntries(normalizedHeaders.entries());
4563
4625
  }
4564
- var VERSION2 = "3.0.23";
4626
+ var VERSION2 = "3.0.25";
4565
4627
  var getOriginalFetch = () => globalThis.fetch;
4566
4628
  var getFromApi = async ({
4567
4629
  url,
@@ -5030,6 +5092,33 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
5030
5092
  rawValue: parsedResult.rawValue
5031
5093
  };
5032
5094
  };
5095
+ var schemaSymbol2 = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
5096
+ function lazySchema(createSchema) {
5097
+ let schema;
5098
+ return () => {
5099
+ if (schema == null) {
5100
+ schema = createSchema();
5101
+ }
5102
+ return schema;
5103
+ };
5104
+ }
5105
+ function jsonSchema2(jsonSchema22, {
5106
+ validate
5107
+ } = {}) {
5108
+ return {
5109
+ [schemaSymbol2]: true,
5110
+ _type: void 0,
5111
+ // should never be used directly
5112
+ [validatorSymbol2]: true,
5113
+ get jsonSchema() {
5114
+ if (typeof jsonSchema22 === "function") {
5115
+ jsonSchema22 = jsonSchema22();
5116
+ }
5117
+ return jsonSchema22;
5118
+ },
5119
+ validate
5120
+ };
5121
+ }
5033
5122
  function addAdditionalPropertiesToJsonSchema(jsonSchema22) {
5034
5123
  if (jsonSchema22.type === "object") {
5035
5124
  jsonSchema22.additionalProperties = false;
@@ -5055,13 +5144,6 @@ function addAdditionalPropertiesToJsonSchema(jsonSchema22) {
5055
5144
  }
5056
5145
  return jsonSchema22;
5057
5146
  }
5058
- var getRelativePath2 = (pathA, pathB) => {
5059
- let i = 0;
5060
- for (; i < pathA.length && i < pathB.length; i++) {
5061
- if (pathA[i] !== pathB[i]) break;
5062
- }
5063
- return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
5064
- };
5065
5147
  var ignoreOverride2 = /* @__PURE__ */ Symbol(
5066
5148
  "Let zodToJsonSchema decide on which parser to use"
5067
5149
  );
@@ -6005,6 +6087,13 @@ var selectParser2 = (def, typeName, refs) => {
6005
6087
  return /* @__PURE__ */ ((_) => void 0)();
6006
6088
  }
6007
6089
  };
6090
+ var getRelativePath2 = (pathA, pathB) => {
6091
+ let i = 0;
6092
+ for (; i < pathA.length && i < pathB.length; i++) {
6093
+ if (pathA[i] !== pathB[i]) break;
6094
+ }
6095
+ return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
6096
+ };
6008
6097
  function parseDef2(def, refs, forceResolution = false) {
6009
6098
  var _a224;
6010
6099
  const seenItem = refs.seen.get(def);
@@ -6184,33 +6273,6 @@ function zodSchema2(zodSchema22, options) {
6184
6273
  return zod3Schema(zodSchema22);
6185
6274
  }
6186
6275
  }
6187
- var schemaSymbol2 = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
6188
- function lazySchema(createSchema) {
6189
- let schema;
6190
- return () => {
6191
- if (schema == null) {
6192
- schema = createSchema();
6193
- }
6194
- return schema;
6195
- };
6196
- }
6197
- function jsonSchema2(jsonSchema22, {
6198
- validate
6199
- } = {}) {
6200
- return {
6201
- [schemaSymbol2]: true,
6202
- _type: void 0,
6203
- // should never be used directly
6204
- [validatorSymbol2]: true,
6205
- get jsonSchema() {
6206
- if (typeof jsonSchema22 === "function") {
6207
- jsonSchema22 = jsonSchema22();
6208
- }
6209
- return jsonSchema22;
6210
- },
6211
- validate
6212
- };
6213
- }
6214
6276
  function isSchema2(value) {
6215
6277
  return typeof value === "object" && value !== null && schemaSymbol2 in value && value[schemaSymbol2] === true && "jsonSchema" in value && "validate" in value;
6216
6278
  }
@@ -6498,6 +6560,19 @@ var gatewayErrorResponseSchema = lazyValidator(
6498
6560
  })
6499
6561
  )
6500
6562
  );
6563
+ function extractApiCallResponse(error) {
6564
+ if (error.data !== void 0) {
6565
+ return error.data;
6566
+ }
6567
+ if (error.responseBody != null) {
6568
+ try {
6569
+ return JSON.parse(error.responseBody);
6570
+ } catch (e) {
6571
+ return error.responseBody;
6572
+ }
6573
+ }
6574
+ return {};
6575
+ }
6501
6576
  var name74 = "GatewayTimeoutError";
6502
6577
  var marker84 = `vercel.ai.gateway.error.${name74}`;
6503
6578
  var symbol84 = Symbol.for(marker84);
@@ -6584,19 +6659,6 @@ async function asGatewayError(error, authMethod) {
6584
6659
  authMethod
6585
6660
  });
6586
6661
  }
6587
- function extractApiCallResponse(error) {
6588
- if (error.data !== void 0) {
6589
- return error.data;
6590
- }
6591
- if (error.responseBody != null) {
6592
- try {
6593
- return JSON.parse(error.responseBody);
6594
- } catch (e) {
6595
- return error.responseBody;
6596
- }
6597
- }
6598
- return {};
6599
- }
6600
6662
  var GATEWAY_AUTH_METHOD_HEADER = "ai-gateway-auth-method";
6601
6663
  async function parseAuthMethod(headers) {
6602
6664
  const result = await safeValidateTypes2({
@@ -7383,7 +7445,7 @@ async function getVercelRequestId() {
7383
7445
  var _a932;
7384
7446
  return (_a932 = getContext().headers) == null ? void 0 : _a932["x-vercel-id"];
7385
7447
  }
7386
- var VERSION3 = "2.0.82";
7448
+ var VERSION3 = "2.0.86";
7387
7449
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
7388
7450
  function createGatewayProvider(options = {}) {
7389
7451
  var _a932, _b93;
@@ -8370,7 +8432,7 @@ function getGlobalProvider() {
8370
8432
  var _a163;
8371
8433
  return (_a163 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a163 : gateway;
8372
8434
  }
8373
- var VERSION32 = "5.0.179";
8435
+ var VERSION32 = "5.0.184";
8374
8436
  var dataContentSchema2 = z$1.union([
8375
8437
  z$1.string(),
8376
8438
  z$1.instanceof(Uint8Array),
@@ -9675,6 +9737,9 @@ var ParseError2 = class extends Error {
9675
9737
  super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
9676
9738
  }
9677
9739
  };
9740
+ var LF2 = 10;
9741
+ var CR2 = 13;
9742
+ var SPACE2 = 32;
9678
9743
  function noop2(_arg) {
9679
9744
  }
9680
9745
  function createParser2(callbacks) {
@@ -9682,39 +9747,109 @@ function createParser2(callbacks) {
9682
9747
  throw new TypeError(
9683
9748
  "`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
9684
9749
  );
9685
- const { onEvent = noop2, onError = noop2, onRetry = noop2, onComment } = callbacks;
9686
- let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
9687
- function feed(newChunk) {
9688
- const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines2(`${incompleteLine}${chunk}`);
9689
- for (const line of complete)
9690
- parseLine(line);
9691
- incompleteLine = incomplete, isFirstChunk = false;
9692
- }
9693
- function parseLine(line) {
9694
- if (line === "") {
9750
+ const { onEvent = noop2, onError = noop2, onRetry = noop2, onComment } = callbacks, pendingFragments = [];
9751
+ let isFirstChunk = true, id, data = "", dataLines = 0, eventType;
9752
+ function feed(chunk) {
9753
+ if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
9754
+ const trailing2 = processLines(chunk);
9755
+ trailing2 !== "" && pendingFragments.push(trailing2);
9756
+ return;
9757
+ }
9758
+ if (chunk.indexOf(`
9759
+ `) === -1 && chunk.indexOf("\r") === -1) {
9760
+ pendingFragments.push(chunk);
9761
+ return;
9762
+ }
9763
+ pendingFragments.push(chunk);
9764
+ const input = pendingFragments.join("");
9765
+ pendingFragments.length = 0;
9766
+ const trailing = processLines(input);
9767
+ trailing !== "" && pendingFragments.push(trailing);
9768
+ }
9769
+ function processLines(chunk) {
9770
+ let searchIndex = 0;
9771
+ if (chunk.indexOf("\r") === -1) {
9772
+ let lfIndex = chunk.indexOf(`
9773
+ `, searchIndex);
9774
+ for (; lfIndex !== -1; ) {
9775
+ if (searchIndex === lfIndex) {
9776
+ dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
9777
+ `, searchIndex);
9778
+ continue;
9779
+ }
9780
+ const firstCharCode = chunk.charCodeAt(searchIndex);
9781
+ if (isDataPrefix2(chunk, searchIndex, firstCharCode)) {
9782
+ const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE2 ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
9783
+ if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF2) {
9784
+ onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
9785
+ `, searchIndex);
9786
+ continue;
9787
+ }
9788
+ data = dataLines === 0 ? value : `${data}
9789
+ ${value}`, dataLines++;
9790
+ } else isEventPrefix2(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
9791
+ chunk.charCodeAt(searchIndex + 6) === SPACE2 ? searchIndex + 7 : searchIndex + 6,
9792
+ lfIndex
9793
+ ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
9794
+ searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
9795
+ `, searchIndex);
9796
+ }
9797
+ return chunk.slice(searchIndex);
9798
+ }
9799
+ for (; searchIndex < chunk.length; ) {
9800
+ const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
9801
+ `, searchIndex);
9802
+ let lineEnd = -1;
9803
+ if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
9804
+ break;
9805
+ parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR2 && chunk.charCodeAt(searchIndex) === LF2 && searchIndex++;
9806
+ }
9807
+ return chunk.slice(searchIndex);
9808
+ }
9809
+ function parseLine(chunk, start, end) {
9810
+ if (start === end) {
9695
9811
  dispatchEvent();
9696
9812
  return;
9697
9813
  }
9698
- if (line.startsWith(":")) {
9699
- onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
9814
+ const firstCharCode = chunk.charCodeAt(start);
9815
+ if (isDataPrefix2(chunk, start, firstCharCode)) {
9816
+ const valueStart = chunk.charCodeAt(start + 5) === SPACE2 ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
9817
+ data = dataLines === 0 ? value2 : `${data}
9818
+ ${value2}`, dataLines++;
9819
+ return;
9820
+ }
9821
+ if (isEventPrefix2(chunk, start, firstCharCode)) {
9822
+ eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE2 ? start + 7 : start + 6, end) || void 0;
9700
9823
  return;
9701
9824
  }
9702
- const fieldSeparatorIndex = line.indexOf(":");
9703
- if (fieldSeparatorIndex !== -1) {
9704
- const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
9705
- processField(field, value, line);
9825
+ if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
9826
+ const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE2 ? start + 4 : start + 3, end);
9827
+ id = value2.includes("\0") ? void 0 : value2;
9706
9828
  return;
9707
9829
  }
9708
- processField(line, "", line);
9830
+ if (firstCharCode === 58) {
9831
+ if (onComment) {
9832
+ const line2 = chunk.slice(start, end);
9833
+ onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE2 ? 2 : 1));
9834
+ }
9835
+ return;
9836
+ }
9837
+ const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
9838
+ if (fieldSeparatorIndex === -1) {
9839
+ processField(line, "", line);
9840
+ return;
9841
+ }
9842
+ const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE2 ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
9843
+ processField(field, value, line);
9709
9844
  }
9710
9845
  function processField(field, value, line) {
9711
9846
  switch (field) {
9712
9847
  case "event":
9713
- eventType = value;
9848
+ eventType = value || void 0;
9714
9849
  break;
9715
9850
  case "data":
9716
- data = `${data}${value}
9717
- `;
9851
+ data = dataLines === 0 ? value : `${data}
9852
+ ${value}`, dataLines++;
9718
9853
  break;
9719
9854
  case "id":
9720
9855
  id = value.includes("\0") ? void 0 : value;
@@ -9739,37 +9874,26 @@ function createParser2(callbacks) {
9739
9874
  }
9740
9875
  }
9741
9876
  function dispatchEvent() {
9742
- data.length > 0 && onEvent({
9877
+ dataLines > 0 && onEvent({
9743
9878
  id,
9744
- event: eventType || void 0,
9745
- // If the data buffer's last character is a U+000A LINE FEED (LF) character,
9746
- // then remove the last character from the data buffer.
9747
- data: data.endsWith(`
9748
- `) ? data.slice(0, -1) : data
9749
- }), id = void 0, data = "", eventType = "";
9879
+ event: eventType,
9880
+ data
9881
+ }), id = void 0, data = "", dataLines = 0, eventType = void 0;
9750
9882
  }
9751
9883
  function reset(options = {}) {
9752
- incompleteLine && options.consume && parseLine(incompleteLine), isFirstChunk = true, id = void 0, data = "", eventType = "", incompleteLine = "";
9884
+ if (options.consume && pendingFragments.length > 0) {
9885
+ const incompleteLine = pendingFragments.join("");
9886
+ parseLine(incompleteLine, 0, incompleteLine.length);
9887
+ }
9888
+ isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0;
9753
9889
  }
9754
9890
  return { feed, reset };
9755
9891
  }
9756
- function splitLines2(chunk) {
9757
- const lines = [];
9758
- let incompleteLine = "", searchIndex = 0;
9759
- for (; searchIndex < chunk.length; ) {
9760
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
9761
- `, searchIndex);
9762
- let lineEnd = -1;
9763
- if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
9764
- incompleteLine = chunk.slice(searchIndex);
9765
- break;
9766
- } else {
9767
- const line = chunk.slice(searchIndex, lineEnd);
9768
- lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
9769
- ` && searchIndex++;
9770
- }
9771
- }
9772
- return [lines, incompleteLine];
9892
+ function isDataPrefix2(chunk, i, firstCharCode) {
9893
+ return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
9894
+ }
9895
+ function isEventPrefix2(chunk, i, firstCharCode) {
9896
+ return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
9773
9897
  }
9774
9898
  var EventSourceParserStream2 = class extends TransformStream {
9775
9899
  constructor({ onError, onRetry, onComment } = {}) {
@@ -9981,7 +10105,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
9981
10105
  );
9982
10106
  return Object.fromEntries(normalizedHeaders.entries());
9983
10107
  }
9984
- var VERSION4 = "4.0.23";
10108
+ var VERSION4 = "4.0.26";
9985
10109
  var getOriginalFetch3 = () => globalThis.fetch;
9986
10110
  var getFromApi2 = async ({
9987
10111
  url,
@@ -11953,6 +12077,19 @@ var gatewayErrorResponseSchema2 = lazySchema2(
11953
12077
  })
11954
12078
  )
11955
12079
  );
12080
+ function extractApiCallResponse2(error) {
12081
+ if (error.data !== void 0) {
12082
+ return error.data;
12083
+ }
12084
+ if (error.responseBody != null) {
12085
+ try {
12086
+ return JSON.parse(error.responseBody);
12087
+ } catch (e) {
12088
+ return error.responseBody;
12089
+ }
12090
+ }
12091
+ return {};
12092
+ }
11956
12093
  var name76 = "GatewayTimeoutError";
11957
12094
  var marker86 = `vercel.ai.gateway.error.${name76}`;
11958
12095
  var symbol86 = Symbol.for(marker86);
@@ -12042,19 +12179,6 @@ async function asGatewayError2(error, authMethod) {
12042
12179
  authMethod
12043
12180
  });
12044
12181
  }
12045
- function extractApiCallResponse2(error) {
12046
- if (error.data !== void 0) {
12047
- return error.data;
12048
- }
12049
- if (error.responseBody != null) {
12050
- try {
12051
- return JSON.parse(error.responseBody);
12052
- } catch (e) {
12053
- return error.responseBody;
12054
- }
12055
- }
12056
- return {};
12057
- }
12058
12182
  var GATEWAY_AUTH_METHOD_HEADER2 = "ai-gateway-auth-method";
12059
12183
  async function parseAuthMethod2(headers) {
12060
12184
  const result = await safeValidateTypes3({
@@ -13148,7 +13272,7 @@ async function getVercelRequestId2() {
13148
13272
  var _a932;
13149
13273
  return (_a932 = getContext2().headers) == null ? void 0 : _a932["x-vercel-id"];
13150
13274
  }
13151
- var VERSION5 = "3.0.104";
13275
+ var VERSION5 = "3.0.110";
13152
13276
  var AI_GATEWAY_PROTOCOL_VERSION2 = "0.0.1";
13153
13277
  function createGatewayProvider2(options = {}) {
13154
13278
  var _a932, _b93;
@@ -14258,7 +14382,7 @@ function getTotalTimeoutMs(timeout) {
14258
14382
  }
14259
14383
  return timeout.totalMs;
14260
14384
  }
14261
- var VERSION33 = "6.0.168";
14385
+ var VERSION33 = "6.0.175";
14262
14386
  var dataContentSchema3 = z$1.union([
14263
14387
  z$1.string(),
14264
14388
  z$1.instanceof(Uint8Array),
@@ -17204,16 +17328,15 @@ var Memory = class extends MastraMemory {
17204
17328
  `Tried to query vector index ${indexName} but this Memory instance doesn't have an attached vector db.`
17205
17329
  );
17206
17330
  }
17331
+ const scopeFilter = resourceScope ? { resource_id: resourceId } : { thread_id: threadId };
17332
+ const userFilter = typeof config.semanticRecall === "object" ? config.semanticRecall.filter : void 0;
17333
+ const combinedFilter = userFilter ? { $and: [scopeFilter, userFilter] } : scopeFilter;
17207
17334
  vectorResults.push(
17208
17335
  ...await this.vector.query({
17209
17336
  indexName,
17210
17337
  queryVector: embedding,
17211
17338
  topK: vectorConfig.topK,
17212
- filter: resourceScope ? {
17213
- resource_id: resourceId
17214
- } : {
17215
- thread_id: threadId
17216
- }
17339
+ filter: combinedFilter
17217
17340
  })
17218
17341
  );
17219
17342
  })
@@ -17602,7 +17725,7 @@ ${workingMemory}`;
17602
17725
  messageCount: messages.length
17603
17726
  });
17604
17727
  try {
17605
- const updatedMessages = messages.map((m) => {
17728
+ const updatedMessages = messages.filter((m) => m.role !== "system").map((m) => {
17606
17729
  return this.updateMessageToHideWorkingMemoryV2(m);
17607
17730
  }).filter((m) => Boolean(m));
17608
17731
  const config = this.getMergedThreadConfig(memoryConfig);
@@ -17615,6 +17738,31 @@ ${workingMemory}`;
17615
17738
  });
17616
17739
  let totalTokens = 0;
17617
17740
  if (this.vector && config.semanticRecall) {
17741
+ const messagesByThread = /* @__PURE__ */ new Map();
17742
+ updatedMessages.forEach((message) => {
17743
+ if (message.threadId) {
17744
+ if (!messagesByThread.has(message.threadId)) {
17745
+ messagesByThread.set(message.threadId, []);
17746
+ }
17747
+ messagesByThread.get(message.threadId).push(message);
17748
+ }
17749
+ });
17750
+ const threadMetadataMap = /* @__PURE__ */ new Map();
17751
+ await Promise.all(
17752
+ Array.from(messagesByThread.keys()).map(async (threadId) => {
17753
+ try {
17754
+ const thread = await memoryStore.getThreadById({ threadId });
17755
+ if (thread?.metadata) {
17756
+ threadMetadataMap.set(threadId, thread.metadata);
17757
+ }
17758
+ } catch (error) {
17759
+ const message = error instanceof Error ? error.message : String(error);
17760
+ throw new Error(
17761
+ `Could not fetch metadata for thread ${threadId} while saving semantic recall embeddings: ${message}`
17762
+ );
17763
+ }
17764
+ })
17765
+ );
17618
17766
  const embeddingData = [];
17619
17767
  let dimension;
17620
17768
  await Promise.all(
@@ -17632,9 +17780,11 @@ ${workingMemory}`;
17632
17780
  if (result2.usage?.tokens) {
17633
17781
  totalTokens += result2.usage.tokens;
17634
17782
  }
17783
+ const threadMetadata = message.threadId ? threadMetadataMap.get(message.threadId) || {} : {};
17635
17784
  embeddingData.push({
17636
17785
  embeddings: result2.embeddings,
17637
17786
  metadata: result2.chunks.map(() => ({
17787
+ ...threadMetadata,
17638
17788
  message_id: message.id,
17639
17789
  thread_id: message.threadId,
17640
17790
  resource_id: message.resourceId
@@ -17917,8 +18067,10 @@ ${workingMemory}`;
17917
18067
  */
17918
18068
  async persistMessages(messages) {
17919
18069
  if (messages.length === 0) return;
18070
+ const persistableMessages = messages.filter((m) => m.role !== "system");
18071
+ if (persistableMessages.length === 0) return;
17920
18072
  const memoryStore = await this.getMemoryStore();
17921
- await memoryStore.saveMessages({ messages });
18073
+ await memoryStore.saveMessages({ messages: persistableMessages });
17922
18074
  }
17923
18075
  /**
17924
18076
  * One-time initialization of the shared ObservationalMemory engine.
@@ -17945,7 +18097,7 @@ ${workingMemory}`;
17945
18097
  "Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
17946
18098
  );
17947
18099
  }
17948
- const { ObservationalMemory: OMClass } = await import('./observational-memory-KH7G7Y6B.js');
18100
+ const { ObservationalMemory: OMClass } = await import('./observational-memory-IP2RVQQG.js');
17949
18101
  const onIndexObservations = this.hasRetrievalSearch(omConfig.retrieval) ? async (observation) => {
17950
18102
  await this.indexObservation(observation);
17951
18103
  } : void 0;
@@ -18871,7 +19023,7 @@ Notes:
18871
19023
  if (!effectiveConfig) return null;
18872
19024
  const engine = await this.omEngine;
18873
19025
  if (!engine) return null;
18874
- const { ObservationalMemoryProcessor } = await import('./observational-memory-KH7G7Y6B.js');
19026
+ const { ObservationalMemoryProcessor } = await import('./observational-memory-IP2RVQQG.js');
18875
19027
  return new ObservationalMemoryProcessor(engine, this, {
18876
19028
  temporalMarkers: effectiveConfig.temporalMarkers
18877
19029
  });