@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.
- package/CHANGELOG.md +22 -0
- package/dist/{chunk-ZUUSLGY6.cjs → chunk-MJNTQ6GP.cjs} +84 -31
- package/dist/chunk-MJNTQ6GP.cjs.map +1 -0
- package/dist/{chunk-NUYSX3DD.js → chunk-PBZHHKPE.js} +84 -31
- package/dist/chunk-PBZHHKPE.js.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +39 -39
- package/dist/docs/references/docs-agents-background-tasks.md +62 -2
- package/dist/docs/references/docs-memory-observational-memory.md +7 -2
- package/dist/docs/references/docs-memory-overview.md +2 -1
- package/dist/docs/references/docs-memory-semantic-recall.md +68 -6
- package/dist/index.cjs +329 -177
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +320 -168
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-KH7G7Y6B.js → observational-memory-IP2RVQQG.js} +3 -3
- package/dist/{observational-memory-KH7G7Y6B.js.map → observational-memory-IP2RVQQG.js.map} +1 -1
- package/dist/{observational-memory-BOXSRJOR.cjs → observational-memory-TASIB4PH.cjs} +26 -26
- package/dist/{observational-memory-BOXSRJOR.cjs.map → observational-memory-TASIB4PH.cjs.map} +1 -1
- package/dist/processors/index.cjs +24 -24
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-turn/load-memory-context.d.ts +9 -0
- package/dist/processors/observational-memory/observation-turn/load-memory-context.d.ts.map +1 -0
- package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/processor.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/chunk-NUYSX3DD.js.map +0 -1
- package/dist/chunk-ZUUSLGY6.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkMJNTQ6GP_cjs = require('./chunk-MJNTQ6GP.cjs');
|
|
4
4
|
var v3 = require('zod/v3');
|
|
5
5
|
var zod = require('zod');
|
|
6
6
|
var z4 = require('zod/v4');
|
|
@@ -40,7 +40,7 @@ function _interopNamespace(e) {
|
|
|
40
40
|
var z4__namespace = /*#__PURE__*/_interopNamespace(z4);
|
|
41
41
|
var xxhash__default = /*#__PURE__*/_interopDefault(xxhash);
|
|
42
42
|
|
|
43
|
-
// ../_vendored/ai_v4/dist/chunk-
|
|
43
|
+
// ../_vendored/ai_v4/dist/chunk-HB6FLTHO.js
|
|
44
44
|
var __create = Object.create;
|
|
45
45
|
var __defProp = Object.defineProperty;
|
|
46
46
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -4314,6 +4314,9 @@ var ParseError = class extends Error {
|
|
|
4314
4314
|
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
4315
4315
|
}
|
|
4316
4316
|
};
|
|
4317
|
+
var LF = 10;
|
|
4318
|
+
var CR = 13;
|
|
4319
|
+
var SPACE = 32;
|
|
4317
4320
|
function noop(_arg) {
|
|
4318
4321
|
}
|
|
4319
4322
|
function createParser(callbacks) {
|
|
@@ -4321,39 +4324,109 @@ function createParser(callbacks) {
|
|
|
4321
4324
|
throw new TypeError(
|
|
4322
4325
|
"`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
|
|
4323
4326
|
);
|
|
4324
|
-
const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
|
|
4325
|
-
let
|
|
4326
|
-
function feed(
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4327
|
+
const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks, pendingFragments = [];
|
|
4328
|
+
let isFirstChunk = true, id, data = "", dataLines = 0, eventType;
|
|
4329
|
+
function feed(chunk) {
|
|
4330
|
+
if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
|
|
4331
|
+
const trailing2 = processLines(chunk);
|
|
4332
|
+
trailing2 !== "" && pendingFragments.push(trailing2);
|
|
4333
|
+
return;
|
|
4334
|
+
}
|
|
4335
|
+
if (chunk.indexOf(`
|
|
4336
|
+
`) === -1 && chunk.indexOf("\r") === -1) {
|
|
4337
|
+
pendingFragments.push(chunk);
|
|
4338
|
+
return;
|
|
4339
|
+
}
|
|
4340
|
+
pendingFragments.push(chunk);
|
|
4341
|
+
const input = pendingFragments.join("");
|
|
4342
|
+
pendingFragments.length = 0;
|
|
4343
|
+
const trailing = processLines(input);
|
|
4344
|
+
trailing !== "" && pendingFragments.push(trailing);
|
|
4345
|
+
}
|
|
4346
|
+
function processLines(chunk) {
|
|
4347
|
+
let searchIndex = 0;
|
|
4348
|
+
if (chunk.indexOf("\r") === -1) {
|
|
4349
|
+
let lfIndex = chunk.indexOf(`
|
|
4350
|
+
`, searchIndex);
|
|
4351
|
+
for (; lfIndex !== -1; ) {
|
|
4352
|
+
if (searchIndex === lfIndex) {
|
|
4353
|
+
dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
4354
|
+
`, searchIndex);
|
|
4355
|
+
continue;
|
|
4356
|
+
}
|
|
4357
|
+
const firstCharCode = chunk.charCodeAt(searchIndex);
|
|
4358
|
+
if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
|
|
4359
|
+
const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
|
|
4360
|
+
if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
|
|
4361
|
+
onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
|
|
4362
|
+
`, searchIndex);
|
|
4363
|
+
continue;
|
|
4364
|
+
}
|
|
4365
|
+
data = dataLines === 0 ? value : `${data}
|
|
4366
|
+
${value}`, dataLines++;
|
|
4367
|
+
} else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
|
|
4368
|
+
chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
|
|
4369
|
+
lfIndex
|
|
4370
|
+
) || void 0 : parseLine(chunk, searchIndex, lfIndex);
|
|
4371
|
+
searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
4372
|
+
`, searchIndex);
|
|
4373
|
+
}
|
|
4374
|
+
return chunk.slice(searchIndex);
|
|
4375
|
+
}
|
|
4376
|
+
for (; searchIndex < chunk.length; ) {
|
|
4377
|
+
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
4378
|
+
`, searchIndex);
|
|
4379
|
+
let lineEnd = -1;
|
|
4380
|
+
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)
|
|
4381
|
+
break;
|
|
4382
|
+
parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
|
|
4383
|
+
}
|
|
4384
|
+
return chunk.slice(searchIndex);
|
|
4385
|
+
}
|
|
4386
|
+
function parseLine(chunk, start, end) {
|
|
4387
|
+
if (start === end) {
|
|
4334
4388
|
dispatchEvent();
|
|
4335
4389
|
return;
|
|
4336
4390
|
}
|
|
4337
|
-
|
|
4338
|
-
|
|
4391
|
+
const firstCharCode = chunk.charCodeAt(start);
|
|
4392
|
+
if (isDataPrefix(chunk, start, firstCharCode)) {
|
|
4393
|
+
const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
|
|
4394
|
+
data = dataLines === 0 ? value2 : `${data}
|
|
4395
|
+
${value2}`, dataLines++;
|
|
4396
|
+
return;
|
|
4397
|
+
}
|
|
4398
|
+
if (isEventPrefix(chunk, start, firstCharCode)) {
|
|
4399
|
+
eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
|
|
4400
|
+
return;
|
|
4401
|
+
}
|
|
4402
|
+
if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
|
|
4403
|
+
const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
|
|
4404
|
+
id = value2.includes("\0") ? void 0 : value2;
|
|
4405
|
+
return;
|
|
4406
|
+
}
|
|
4407
|
+
if (firstCharCode === 58) {
|
|
4408
|
+
if (onComment) {
|
|
4409
|
+
const line2 = chunk.slice(start, end);
|
|
4410
|
+
onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
|
|
4411
|
+
}
|
|
4339
4412
|
return;
|
|
4340
4413
|
}
|
|
4341
|
-
const fieldSeparatorIndex = line.indexOf(":");
|
|
4342
|
-
if (fieldSeparatorIndex
|
|
4343
|
-
|
|
4344
|
-
processField(field, value, line);
|
|
4414
|
+
const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
|
|
4415
|
+
if (fieldSeparatorIndex === -1) {
|
|
4416
|
+
processField(line, "", line);
|
|
4345
4417
|
return;
|
|
4346
4418
|
}
|
|
4347
|
-
|
|
4419
|
+
const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
|
|
4420
|
+
processField(field, value, line);
|
|
4348
4421
|
}
|
|
4349
4422
|
function processField(field, value, line) {
|
|
4350
4423
|
switch (field) {
|
|
4351
4424
|
case "event":
|
|
4352
|
-
eventType = value;
|
|
4425
|
+
eventType = value || void 0;
|
|
4353
4426
|
break;
|
|
4354
4427
|
case "data":
|
|
4355
|
-
data = `${data}
|
|
4356
|
-
|
|
4428
|
+
data = dataLines === 0 ? value : `${data}
|
|
4429
|
+
${value}`, dataLines++;
|
|
4357
4430
|
break;
|
|
4358
4431
|
case "id":
|
|
4359
4432
|
id = value.includes("\0") ? void 0 : value;
|
|
@@ -4378,37 +4451,26 @@ function createParser(callbacks) {
|
|
|
4378
4451
|
}
|
|
4379
4452
|
}
|
|
4380
4453
|
function dispatchEvent() {
|
|
4381
|
-
|
|
4454
|
+
dataLines > 0 && onEvent({
|
|
4382
4455
|
id,
|
|
4383
|
-
event: eventType
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
data: data.endsWith(`
|
|
4387
|
-
`) ? data.slice(0, -1) : data
|
|
4388
|
-
}), id = void 0, data = "", eventType = "";
|
|
4456
|
+
event: eventType,
|
|
4457
|
+
data
|
|
4458
|
+
}), id = void 0, data = "", dataLines = 0, eventType = void 0;
|
|
4389
4459
|
}
|
|
4390
4460
|
function reset(options = {}) {
|
|
4391
|
-
|
|
4461
|
+
if (options.consume && pendingFragments.length > 0) {
|
|
4462
|
+
const incompleteLine = pendingFragments.join("");
|
|
4463
|
+
parseLine(incompleteLine, 0, incompleteLine.length);
|
|
4464
|
+
}
|
|
4465
|
+
isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0;
|
|
4392
4466
|
}
|
|
4393
4467
|
return { feed, reset };
|
|
4394
4468
|
}
|
|
4395
|
-
function
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
`, searchIndex);
|
|
4401
|
-
let lineEnd = -1;
|
|
4402
|
-
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) {
|
|
4403
|
-
incompleteLine = chunk.slice(searchIndex);
|
|
4404
|
-
break;
|
|
4405
|
-
} else {
|
|
4406
|
-
const line = chunk.slice(searchIndex, lineEnd);
|
|
4407
|
-
lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
|
|
4408
|
-
` && searchIndex++;
|
|
4409
|
-
}
|
|
4410
|
-
}
|
|
4411
|
-
return [lines, incompleteLine];
|
|
4469
|
+
function isDataPrefix(chunk, i, firstCharCode) {
|
|
4470
|
+
return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
|
|
4471
|
+
}
|
|
4472
|
+
function isEventPrefix(chunk, i, firstCharCode) {
|
|
4473
|
+
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;
|
|
4412
4474
|
}
|
|
4413
4475
|
var EventSourceParserStream = class extends TransformStream {
|
|
4414
4476
|
constructor({ onError, onRetry, onComment } = {}) {
|
|
@@ -4584,7 +4646,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
4584
4646
|
);
|
|
4585
4647
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
4586
4648
|
}
|
|
4587
|
-
var VERSION2 = "3.0.
|
|
4649
|
+
var VERSION2 = "3.0.25";
|
|
4588
4650
|
var getOriginalFetch = () => globalThis.fetch;
|
|
4589
4651
|
var getFromApi = async ({
|
|
4590
4652
|
url,
|
|
@@ -5053,6 +5115,33 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
5053
5115
|
rawValue: parsedResult.rawValue
|
|
5054
5116
|
};
|
|
5055
5117
|
};
|
|
5118
|
+
var schemaSymbol2 = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
5119
|
+
function lazySchema(createSchema) {
|
|
5120
|
+
let schema;
|
|
5121
|
+
return () => {
|
|
5122
|
+
if (schema == null) {
|
|
5123
|
+
schema = createSchema();
|
|
5124
|
+
}
|
|
5125
|
+
return schema;
|
|
5126
|
+
};
|
|
5127
|
+
}
|
|
5128
|
+
function jsonSchema2(jsonSchema22, {
|
|
5129
|
+
validate
|
|
5130
|
+
} = {}) {
|
|
5131
|
+
return {
|
|
5132
|
+
[schemaSymbol2]: true,
|
|
5133
|
+
_type: void 0,
|
|
5134
|
+
// should never be used directly
|
|
5135
|
+
[validatorSymbol2]: true,
|
|
5136
|
+
get jsonSchema() {
|
|
5137
|
+
if (typeof jsonSchema22 === "function") {
|
|
5138
|
+
jsonSchema22 = jsonSchema22();
|
|
5139
|
+
}
|
|
5140
|
+
return jsonSchema22;
|
|
5141
|
+
},
|
|
5142
|
+
validate
|
|
5143
|
+
};
|
|
5144
|
+
}
|
|
5056
5145
|
function addAdditionalPropertiesToJsonSchema(jsonSchema22) {
|
|
5057
5146
|
if (jsonSchema22.type === "object") {
|
|
5058
5147
|
jsonSchema22.additionalProperties = false;
|
|
@@ -5078,13 +5167,6 @@ function addAdditionalPropertiesToJsonSchema(jsonSchema22) {
|
|
|
5078
5167
|
}
|
|
5079
5168
|
return jsonSchema22;
|
|
5080
5169
|
}
|
|
5081
|
-
var getRelativePath2 = (pathA, pathB) => {
|
|
5082
|
-
let i = 0;
|
|
5083
|
-
for (; i < pathA.length && i < pathB.length; i++) {
|
|
5084
|
-
if (pathA[i] !== pathB[i]) break;
|
|
5085
|
-
}
|
|
5086
|
-
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
5087
|
-
};
|
|
5088
5170
|
var ignoreOverride2 = /* @__PURE__ */ Symbol(
|
|
5089
5171
|
"Let zodToJsonSchema decide on which parser to use"
|
|
5090
5172
|
);
|
|
@@ -6028,6 +6110,13 @@ var selectParser2 = (def, typeName, refs) => {
|
|
|
6028
6110
|
return /* @__PURE__ */ ((_) => void 0)();
|
|
6029
6111
|
}
|
|
6030
6112
|
};
|
|
6113
|
+
var getRelativePath2 = (pathA, pathB) => {
|
|
6114
|
+
let i = 0;
|
|
6115
|
+
for (; i < pathA.length && i < pathB.length; i++) {
|
|
6116
|
+
if (pathA[i] !== pathB[i]) break;
|
|
6117
|
+
}
|
|
6118
|
+
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
6119
|
+
};
|
|
6031
6120
|
function parseDef2(def, refs, forceResolution = false) {
|
|
6032
6121
|
var _a224;
|
|
6033
6122
|
const seenItem = refs.seen.get(def);
|
|
@@ -6207,33 +6296,6 @@ function zodSchema2(zodSchema22, options) {
|
|
|
6207
6296
|
return zod3Schema(zodSchema22);
|
|
6208
6297
|
}
|
|
6209
6298
|
}
|
|
6210
|
-
var schemaSymbol2 = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
6211
|
-
function lazySchema(createSchema) {
|
|
6212
|
-
let schema;
|
|
6213
|
-
return () => {
|
|
6214
|
-
if (schema == null) {
|
|
6215
|
-
schema = createSchema();
|
|
6216
|
-
}
|
|
6217
|
-
return schema;
|
|
6218
|
-
};
|
|
6219
|
-
}
|
|
6220
|
-
function jsonSchema2(jsonSchema22, {
|
|
6221
|
-
validate
|
|
6222
|
-
} = {}) {
|
|
6223
|
-
return {
|
|
6224
|
-
[schemaSymbol2]: true,
|
|
6225
|
-
_type: void 0,
|
|
6226
|
-
// should never be used directly
|
|
6227
|
-
[validatorSymbol2]: true,
|
|
6228
|
-
get jsonSchema() {
|
|
6229
|
-
if (typeof jsonSchema22 === "function") {
|
|
6230
|
-
jsonSchema22 = jsonSchema22();
|
|
6231
|
-
}
|
|
6232
|
-
return jsonSchema22;
|
|
6233
|
-
},
|
|
6234
|
-
validate
|
|
6235
|
-
};
|
|
6236
|
-
}
|
|
6237
6299
|
function isSchema2(value) {
|
|
6238
6300
|
return typeof value === "object" && value !== null && schemaSymbol2 in value && value[schemaSymbol2] === true && "jsonSchema" in value && "validate" in value;
|
|
6239
6301
|
}
|
|
@@ -6521,6 +6583,19 @@ var gatewayErrorResponseSchema = lazyValidator(
|
|
|
6521
6583
|
})
|
|
6522
6584
|
)
|
|
6523
6585
|
);
|
|
6586
|
+
function extractApiCallResponse(error) {
|
|
6587
|
+
if (error.data !== void 0) {
|
|
6588
|
+
return error.data;
|
|
6589
|
+
}
|
|
6590
|
+
if (error.responseBody != null) {
|
|
6591
|
+
try {
|
|
6592
|
+
return JSON.parse(error.responseBody);
|
|
6593
|
+
} catch (e) {
|
|
6594
|
+
return error.responseBody;
|
|
6595
|
+
}
|
|
6596
|
+
}
|
|
6597
|
+
return {};
|
|
6598
|
+
}
|
|
6524
6599
|
var name74 = "GatewayTimeoutError";
|
|
6525
6600
|
var marker84 = `vercel.ai.gateway.error.${name74}`;
|
|
6526
6601
|
var symbol84 = Symbol.for(marker84);
|
|
@@ -6607,19 +6682,6 @@ async function asGatewayError(error, authMethod) {
|
|
|
6607
6682
|
authMethod
|
|
6608
6683
|
});
|
|
6609
6684
|
}
|
|
6610
|
-
function extractApiCallResponse(error) {
|
|
6611
|
-
if (error.data !== void 0) {
|
|
6612
|
-
return error.data;
|
|
6613
|
-
}
|
|
6614
|
-
if (error.responseBody != null) {
|
|
6615
|
-
try {
|
|
6616
|
-
return JSON.parse(error.responseBody);
|
|
6617
|
-
} catch (e) {
|
|
6618
|
-
return error.responseBody;
|
|
6619
|
-
}
|
|
6620
|
-
}
|
|
6621
|
-
return {};
|
|
6622
|
-
}
|
|
6623
6685
|
var GATEWAY_AUTH_METHOD_HEADER = "ai-gateway-auth-method";
|
|
6624
6686
|
async function parseAuthMethod(headers) {
|
|
6625
6687
|
const result = await safeValidateTypes2({
|
|
@@ -7406,7 +7468,7 @@ async function getVercelRequestId() {
|
|
|
7406
7468
|
var _a932;
|
|
7407
7469
|
return (_a932 = getContext().headers) == null ? void 0 : _a932["x-vercel-id"];
|
|
7408
7470
|
}
|
|
7409
|
-
var VERSION3 = "2.0.
|
|
7471
|
+
var VERSION3 = "2.0.86";
|
|
7410
7472
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
7411
7473
|
function createGatewayProvider(options = {}) {
|
|
7412
7474
|
var _a932, _b93;
|
|
@@ -8393,7 +8455,7 @@ function getGlobalProvider() {
|
|
|
8393
8455
|
var _a163;
|
|
8394
8456
|
return (_a163 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a163 : gateway;
|
|
8395
8457
|
}
|
|
8396
|
-
var VERSION32 = "5.0.
|
|
8458
|
+
var VERSION32 = "5.0.184";
|
|
8397
8459
|
var dataContentSchema2 = z4.z.union([
|
|
8398
8460
|
z4.z.string(),
|
|
8399
8461
|
z4.z.instanceof(Uint8Array),
|
|
@@ -9698,6 +9760,9 @@ var ParseError2 = class extends Error {
|
|
|
9698
9760
|
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
9699
9761
|
}
|
|
9700
9762
|
};
|
|
9763
|
+
var LF2 = 10;
|
|
9764
|
+
var CR2 = 13;
|
|
9765
|
+
var SPACE2 = 32;
|
|
9701
9766
|
function noop2(_arg) {
|
|
9702
9767
|
}
|
|
9703
9768
|
function createParser2(callbacks) {
|
|
@@ -9705,39 +9770,109 @@ function createParser2(callbacks) {
|
|
|
9705
9770
|
throw new TypeError(
|
|
9706
9771
|
"`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
|
|
9707
9772
|
);
|
|
9708
|
-
const { onEvent = noop2, onError = noop2, onRetry = noop2, onComment } = callbacks;
|
|
9709
|
-
let
|
|
9710
|
-
function feed(
|
|
9711
|
-
|
|
9712
|
-
|
|
9713
|
-
|
|
9714
|
-
|
|
9715
|
-
|
|
9716
|
-
|
|
9717
|
-
|
|
9773
|
+
const { onEvent = noop2, onError = noop2, onRetry = noop2, onComment } = callbacks, pendingFragments = [];
|
|
9774
|
+
let isFirstChunk = true, id, data = "", dataLines = 0, eventType;
|
|
9775
|
+
function feed(chunk) {
|
|
9776
|
+
if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
|
|
9777
|
+
const trailing2 = processLines(chunk);
|
|
9778
|
+
trailing2 !== "" && pendingFragments.push(trailing2);
|
|
9779
|
+
return;
|
|
9780
|
+
}
|
|
9781
|
+
if (chunk.indexOf(`
|
|
9782
|
+
`) === -1 && chunk.indexOf("\r") === -1) {
|
|
9783
|
+
pendingFragments.push(chunk);
|
|
9784
|
+
return;
|
|
9785
|
+
}
|
|
9786
|
+
pendingFragments.push(chunk);
|
|
9787
|
+
const input = pendingFragments.join("");
|
|
9788
|
+
pendingFragments.length = 0;
|
|
9789
|
+
const trailing = processLines(input);
|
|
9790
|
+
trailing !== "" && pendingFragments.push(trailing);
|
|
9791
|
+
}
|
|
9792
|
+
function processLines(chunk) {
|
|
9793
|
+
let searchIndex = 0;
|
|
9794
|
+
if (chunk.indexOf("\r") === -1) {
|
|
9795
|
+
let lfIndex = chunk.indexOf(`
|
|
9796
|
+
`, searchIndex);
|
|
9797
|
+
for (; lfIndex !== -1; ) {
|
|
9798
|
+
if (searchIndex === lfIndex) {
|
|
9799
|
+
dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
9800
|
+
`, searchIndex);
|
|
9801
|
+
continue;
|
|
9802
|
+
}
|
|
9803
|
+
const firstCharCode = chunk.charCodeAt(searchIndex);
|
|
9804
|
+
if (isDataPrefix2(chunk, searchIndex, firstCharCode)) {
|
|
9805
|
+
const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE2 ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
|
|
9806
|
+
if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF2) {
|
|
9807
|
+
onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
|
|
9808
|
+
`, searchIndex);
|
|
9809
|
+
continue;
|
|
9810
|
+
}
|
|
9811
|
+
data = dataLines === 0 ? value : `${data}
|
|
9812
|
+
${value}`, dataLines++;
|
|
9813
|
+
} else isEventPrefix2(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
|
|
9814
|
+
chunk.charCodeAt(searchIndex + 6) === SPACE2 ? searchIndex + 7 : searchIndex + 6,
|
|
9815
|
+
lfIndex
|
|
9816
|
+
) || void 0 : parseLine(chunk, searchIndex, lfIndex);
|
|
9817
|
+
searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
9818
|
+
`, searchIndex);
|
|
9819
|
+
}
|
|
9820
|
+
return chunk.slice(searchIndex);
|
|
9821
|
+
}
|
|
9822
|
+
for (; searchIndex < chunk.length; ) {
|
|
9823
|
+
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
9824
|
+
`, searchIndex);
|
|
9825
|
+
let lineEnd = -1;
|
|
9826
|
+
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)
|
|
9827
|
+
break;
|
|
9828
|
+
parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR2 && chunk.charCodeAt(searchIndex) === LF2 && searchIndex++;
|
|
9829
|
+
}
|
|
9830
|
+
return chunk.slice(searchIndex);
|
|
9831
|
+
}
|
|
9832
|
+
function parseLine(chunk, start, end) {
|
|
9833
|
+
if (start === end) {
|
|
9718
9834
|
dispatchEvent();
|
|
9719
9835
|
return;
|
|
9720
9836
|
}
|
|
9721
|
-
|
|
9722
|
-
|
|
9837
|
+
const firstCharCode = chunk.charCodeAt(start);
|
|
9838
|
+
if (isDataPrefix2(chunk, start, firstCharCode)) {
|
|
9839
|
+
const valueStart = chunk.charCodeAt(start + 5) === SPACE2 ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
|
|
9840
|
+
data = dataLines === 0 ? value2 : `${data}
|
|
9841
|
+
${value2}`, dataLines++;
|
|
9842
|
+
return;
|
|
9843
|
+
}
|
|
9844
|
+
if (isEventPrefix2(chunk, start, firstCharCode)) {
|
|
9845
|
+
eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE2 ? start + 7 : start + 6, end) || void 0;
|
|
9723
9846
|
return;
|
|
9724
9847
|
}
|
|
9725
|
-
|
|
9726
|
-
|
|
9727
|
-
|
|
9728
|
-
processField(field, value, line);
|
|
9848
|
+
if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
|
|
9849
|
+
const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE2 ? start + 4 : start + 3, end);
|
|
9850
|
+
id = value2.includes("\0") ? void 0 : value2;
|
|
9729
9851
|
return;
|
|
9730
9852
|
}
|
|
9731
|
-
|
|
9853
|
+
if (firstCharCode === 58) {
|
|
9854
|
+
if (onComment) {
|
|
9855
|
+
const line2 = chunk.slice(start, end);
|
|
9856
|
+
onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE2 ? 2 : 1));
|
|
9857
|
+
}
|
|
9858
|
+
return;
|
|
9859
|
+
}
|
|
9860
|
+
const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
|
|
9861
|
+
if (fieldSeparatorIndex === -1) {
|
|
9862
|
+
processField(line, "", line);
|
|
9863
|
+
return;
|
|
9864
|
+
}
|
|
9865
|
+
const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE2 ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
|
|
9866
|
+
processField(field, value, line);
|
|
9732
9867
|
}
|
|
9733
9868
|
function processField(field, value, line) {
|
|
9734
9869
|
switch (field) {
|
|
9735
9870
|
case "event":
|
|
9736
|
-
eventType = value;
|
|
9871
|
+
eventType = value || void 0;
|
|
9737
9872
|
break;
|
|
9738
9873
|
case "data":
|
|
9739
|
-
data = `${data}
|
|
9740
|
-
|
|
9874
|
+
data = dataLines === 0 ? value : `${data}
|
|
9875
|
+
${value}`, dataLines++;
|
|
9741
9876
|
break;
|
|
9742
9877
|
case "id":
|
|
9743
9878
|
id = value.includes("\0") ? void 0 : value;
|
|
@@ -9762,37 +9897,26 @@ function createParser2(callbacks) {
|
|
|
9762
9897
|
}
|
|
9763
9898
|
}
|
|
9764
9899
|
function dispatchEvent() {
|
|
9765
|
-
|
|
9900
|
+
dataLines > 0 && onEvent({
|
|
9766
9901
|
id,
|
|
9767
|
-
event: eventType
|
|
9768
|
-
|
|
9769
|
-
|
|
9770
|
-
data: data.endsWith(`
|
|
9771
|
-
`) ? data.slice(0, -1) : data
|
|
9772
|
-
}), id = void 0, data = "", eventType = "";
|
|
9902
|
+
event: eventType,
|
|
9903
|
+
data
|
|
9904
|
+
}), id = void 0, data = "", dataLines = 0, eventType = void 0;
|
|
9773
9905
|
}
|
|
9774
9906
|
function reset(options = {}) {
|
|
9775
|
-
|
|
9907
|
+
if (options.consume && pendingFragments.length > 0) {
|
|
9908
|
+
const incompleteLine = pendingFragments.join("");
|
|
9909
|
+
parseLine(incompleteLine, 0, incompleteLine.length);
|
|
9910
|
+
}
|
|
9911
|
+
isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0;
|
|
9776
9912
|
}
|
|
9777
9913
|
return { feed, reset };
|
|
9778
9914
|
}
|
|
9779
|
-
function
|
|
9780
|
-
|
|
9781
|
-
|
|
9782
|
-
|
|
9783
|
-
|
|
9784
|
-
`, searchIndex);
|
|
9785
|
-
let lineEnd = -1;
|
|
9786
|
-
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) {
|
|
9787
|
-
incompleteLine = chunk.slice(searchIndex);
|
|
9788
|
-
break;
|
|
9789
|
-
} else {
|
|
9790
|
-
const line = chunk.slice(searchIndex, lineEnd);
|
|
9791
|
-
lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
|
|
9792
|
-
` && searchIndex++;
|
|
9793
|
-
}
|
|
9794
|
-
}
|
|
9795
|
-
return [lines, incompleteLine];
|
|
9915
|
+
function isDataPrefix2(chunk, i, firstCharCode) {
|
|
9916
|
+
return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
|
|
9917
|
+
}
|
|
9918
|
+
function isEventPrefix2(chunk, i, firstCharCode) {
|
|
9919
|
+
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;
|
|
9796
9920
|
}
|
|
9797
9921
|
var EventSourceParserStream2 = class extends TransformStream {
|
|
9798
9922
|
constructor({ onError, onRetry, onComment } = {}) {
|
|
@@ -10004,7 +10128,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
|
|
|
10004
10128
|
);
|
|
10005
10129
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
10006
10130
|
}
|
|
10007
|
-
var VERSION4 = "4.0.
|
|
10131
|
+
var VERSION4 = "4.0.26";
|
|
10008
10132
|
var getOriginalFetch3 = () => globalThis.fetch;
|
|
10009
10133
|
var getFromApi2 = async ({
|
|
10010
10134
|
url,
|
|
@@ -11976,6 +12100,19 @@ var gatewayErrorResponseSchema2 = lazySchema2(
|
|
|
11976
12100
|
})
|
|
11977
12101
|
)
|
|
11978
12102
|
);
|
|
12103
|
+
function extractApiCallResponse2(error) {
|
|
12104
|
+
if (error.data !== void 0) {
|
|
12105
|
+
return error.data;
|
|
12106
|
+
}
|
|
12107
|
+
if (error.responseBody != null) {
|
|
12108
|
+
try {
|
|
12109
|
+
return JSON.parse(error.responseBody);
|
|
12110
|
+
} catch (e) {
|
|
12111
|
+
return error.responseBody;
|
|
12112
|
+
}
|
|
12113
|
+
}
|
|
12114
|
+
return {};
|
|
12115
|
+
}
|
|
11979
12116
|
var name76 = "GatewayTimeoutError";
|
|
11980
12117
|
var marker86 = `vercel.ai.gateway.error.${name76}`;
|
|
11981
12118
|
var symbol86 = Symbol.for(marker86);
|
|
@@ -12065,19 +12202,6 @@ async function asGatewayError2(error, authMethod) {
|
|
|
12065
12202
|
authMethod
|
|
12066
12203
|
});
|
|
12067
12204
|
}
|
|
12068
|
-
function extractApiCallResponse2(error) {
|
|
12069
|
-
if (error.data !== void 0) {
|
|
12070
|
-
return error.data;
|
|
12071
|
-
}
|
|
12072
|
-
if (error.responseBody != null) {
|
|
12073
|
-
try {
|
|
12074
|
-
return JSON.parse(error.responseBody);
|
|
12075
|
-
} catch (e) {
|
|
12076
|
-
return error.responseBody;
|
|
12077
|
-
}
|
|
12078
|
-
}
|
|
12079
|
-
return {};
|
|
12080
|
-
}
|
|
12081
12205
|
var GATEWAY_AUTH_METHOD_HEADER2 = "ai-gateway-auth-method";
|
|
12082
12206
|
async function parseAuthMethod2(headers) {
|
|
12083
12207
|
const result = await safeValidateTypes3({
|
|
@@ -13171,7 +13295,7 @@ async function getVercelRequestId2() {
|
|
|
13171
13295
|
var _a932;
|
|
13172
13296
|
return (_a932 = getContext2().headers) == null ? void 0 : _a932["x-vercel-id"];
|
|
13173
13297
|
}
|
|
13174
|
-
var VERSION5 = "3.0.
|
|
13298
|
+
var VERSION5 = "3.0.110";
|
|
13175
13299
|
var AI_GATEWAY_PROTOCOL_VERSION2 = "0.0.1";
|
|
13176
13300
|
function createGatewayProvider2(options = {}) {
|
|
13177
13301
|
var _a932, _b93;
|
|
@@ -14281,7 +14405,7 @@ function getTotalTimeoutMs(timeout) {
|
|
|
14281
14405
|
}
|
|
14282
14406
|
return timeout.totalMs;
|
|
14283
14407
|
}
|
|
14284
|
-
var VERSION33 = "6.0.
|
|
14408
|
+
var VERSION33 = "6.0.175";
|
|
14285
14409
|
var dataContentSchema3 = z4.z.union([
|
|
14286
14410
|
z4.z.string(),
|
|
14287
14411
|
z4.z.instanceof(Uint8Array),
|
|
@@ -15986,7 +16110,7 @@ function formatTimestamp(date) {
|
|
|
15986
16110
|
}
|
|
15987
16111
|
function truncateByTokens(text4, maxTokens, hint) {
|
|
15988
16112
|
if (tokenx.estimateTokenCount(text4) <= maxTokens) return { text: text4, wasTruncated: false };
|
|
15989
|
-
const truncated =
|
|
16113
|
+
const truncated = chunkMJNTQ6GP_cjs.truncateStringByTokens(text4, maxTokens);
|
|
15990
16114
|
const suffix = hint ? ` [${hint} for more]` : "";
|
|
15991
16115
|
return { text: truncated + suffix, wasTruncated: true };
|
|
15992
16116
|
}
|
|
@@ -16038,11 +16162,11 @@ ${JSON.stringify(inv.args, null, 2)}`;
|
|
|
16038
16162
|
});
|
|
16039
16163
|
}
|
|
16040
16164
|
if (inv.state === "result") {
|
|
16041
|
-
const { value: resultValue } =
|
|
16165
|
+
const { value: resultValue } = chunkMJNTQ6GP_cjs.resolveToolResultValue(
|
|
16042
16166
|
part,
|
|
16043
16167
|
inv.result
|
|
16044
16168
|
);
|
|
16045
|
-
const resultStr =
|
|
16169
|
+
const resultStr = chunkMJNTQ6GP_cjs.formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
|
|
16046
16170
|
const fullText = `[Tool Result: ${inv.toolName}]
|
|
16047
16171
|
${resultStr}`;
|
|
16048
16172
|
parts.push(makePart(msg, i, "tool-result", fullText, detail, inv.toolName));
|
|
@@ -16069,7 +16193,7 @@ ${typeof rawArgs === "string" ? rawArgs : JSON.stringify(rawArgs, null, 2)}`;
|
|
|
16069
16193
|
const toolName = part.toolName;
|
|
16070
16194
|
if (toolName) {
|
|
16071
16195
|
const rawResult = part.output ?? part.result;
|
|
16072
|
-
const resultStr =
|
|
16196
|
+
const resultStr = chunkMJNTQ6GP_cjs.formatToolResultForObserver(rawResult, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
|
|
16073
16197
|
const fullText = `[Tool Result: ${toolName}]
|
|
16074
16198
|
${resultStr}`;
|
|
16075
16199
|
parts.push(makePart(msg, i, "tool-result", fullText, detail, toolName));
|
|
@@ -16148,7 +16272,7 @@ function renderFormattedParts(parts, timestamps, options) {
|
|
|
16148
16272
|
const text4 = buildRenderedText(parts, timestamps);
|
|
16149
16273
|
let totalTokens = tokenx.estimateTokenCount(text4);
|
|
16150
16274
|
if (totalTokens > options.maxTokens) {
|
|
16151
|
-
const truncated =
|
|
16275
|
+
const truncated = chunkMJNTQ6GP_cjs.truncateStringByTokens(text4, options.maxTokens);
|
|
16152
16276
|
return { text: truncated, truncated: true, tokenOffset: totalTokens - options.maxTokens };
|
|
16153
16277
|
}
|
|
16154
16278
|
const truncatedIndices = parts.map((p, i) => ({ part: p, index: i })).filter(({ part }) => part.text !== part.fullText).sort((a, b) => expandPriority(a.part) - expandPriority(b.part));
|
|
@@ -16181,7 +16305,7 @@ function renderFormattedParts(parts, timestamps, options) {
|
|
|
16181
16305
|
if (expandedTokens <= options.maxTokens) {
|
|
16182
16306
|
return { text: expanded, truncated: false, tokenOffset: 0 };
|
|
16183
16307
|
}
|
|
16184
|
-
const hardTruncated =
|
|
16308
|
+
const hardTruncated = chunkMJNTQ6GP_cjs.truncateStringByTokens(expanded, options.maxTokens);
|
|
16185
16309
|
return { text: hardTruncated, truncated: true, tokenOffset: expandedTokens - options.maxTokens };
|
|
16186
16310
|
}
|
|
16187
16311
|
async function recallPart({
|
|
@@ -16232,7 +16356,7 @@ async function recallPart({
|
|
|
16232
16356
|
|
|
16233
16357
|
`;
|
|
16234
16358
|
const fallbackText = `${fallbackNote}${firstNextPart.text}`;
|
|
16235
|
-
const truncatedText2 =
|
|
16359
|
+
const truncatedText2 = chunkMJNTQ6GP_cjs.truncateStringByTokens(fallbackText, maxTokens);
|
|
16236
16360
|
const wasTruncated2 = truncatedText2 !== fallbackText;
|
|
16237
16361
|
return {
|
|
16238
16362
|
text: truncatedText2,
|
|
@@ -16247,7 +16371,7 @@ async function recallPart({
|
|
|
16247
16371
|
}
|
|
16248
16372
|
throw new Error(`Part index ${partIndex} not found in message ${cursor}. Available indices: ${availableIndices}`);
|
|
16249
16373
|
}
|
|
16250
|
-
const truncatedText =
|
|
16374
|
+
const truncatedText = chunkMJNTQ6GP_cjs.truncateStringByTokens(target.text, maxTokens);
|
|
16251
16375
|
const wasTruncated = truncatedText !== target.text;
|
|
16252
16376
|
return {
|
|
16253
16377
|
text: truncatedText,
|
|
@@ -17227,16 +17351,15 @@ var Memory = class extends memory.MastraMemory {
|
|
|
17227
17351
|
`Tried to query vector index ${indexName} but this Memory instance doesn't have an attached vector db.`
|
|
17228
17352
|
);
|
|
17229
17353
|
}
|
|
17354
|
+
const scopeFilter = resourceScope ? { resource_id: resourceId } : { thread_id: threadId };
|
|
17355
|
+
const userFilter = typeof config.semanticRecall === "object" ? config.semanticRecall.filter : void 0;
|
|
17356
|
+
const combinedFilter = userFilter ? { $and: [scopeFilter, userFilter] } : scopeFilter;
|
|
17230
17357
|
vectorResults.push(
|
|
17231
17358
|
...await this.vector.query({
|
|
17232
17359
|
indexName,
|
|
17233
17360
|
queryVector: embedding,
|
|
17234
17361
|
topK: vectorConfig.topK,
|
|
17235
|
-
filter:
|
|
17236
|
-
resource_id: resourceId
|
|
17237
|
-
} : {
|
|
17238
|
-
thread_id: threadId
|
|
17239
|
-
}
|
|
17362
|
+
filter: combinedFilter
|
|
17240
17363
|
})
|
|
17241
17364
|
);
|
|
17242
17365
|
})
|
|
@@ -17625,7 +17748,7 @@ ${workingMemory}`;
|
|
|
17625
17748
|
messageCount: messages.length
|
|
17626
17749
|
});
|
|
17627
17750
|
try {
|
|
17628
|
-
const updatedMessages = messages.map((m) => {
|
|
17751
|
+
const updatedMessages = messages.filter((m) => m.role !== "system").map((m) => {
|
|
17629
17752
|
return this.updateMessageToHideWorkingMemoryV2(m);
|
|
17630
17753
|
}).filter((m) => Boolean(m));
|
|
17631
17754
|
const config = this.getMergedThreadConfig(memoryConfig);
|
|
@@ -17638,6 +17761,31 @@ ${workingMemory}`;
|
|
|
17638
17761
|
});
|
|
17639
17762
|
let totalTokens = 0;
|
|
17640
17763
|
if (this.vector && config.semanticRecall) {
|
|
17764
|
+
const messagesByThread = /* @__PURE__ */ new Map();
|
|
17765
|
+
updatedMessages.forEach((message) => {
|
|
17766
|
+
if (message.threadId) {
|
|
17767
|
+
if (!messagesByThread.has(message.threadId)) {
|
|
17768
|
+
messagesByThread.set(message.threadId, []);
|
|
17769
|
+
}
|
|
17770
|
+
messagesByThread.get(message.threadId).push(message);
|
|
17771
|
+
}
|
|
17772
|
+
});
|
|
17773
|
+
const threadMetadataMap = /* @__PURE__ */ new Map();
|
|
17774
|
+
await Promise.all(
|
|
17775
|
+
Array.from(messagesByThread.keys()).map(async (threadId) => {
|
|
17776
|
+
try {
|
|
17777
|
+
const thread = await memoryStore.getThreadById({ threadId });
|
|
17778
|
+
if (thread?.metadata) {
|
|
17779
|
+
threadMetadataMap.set(threadId, thread.metadata);
|
|
17780
|
+
}
|
|
17781
|
+
} catch (error) {
|
|
17782
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
17783
|
+
throw new Error(
|
|
17784
|
+
`Could not fetch metadata for thread ${threadId} while saving semantic recall embeddings: ${message}`
|
|
17785
|
+
);
|
|
17786
|
+
}
|
|
17787
|
+
})
|
|
17788
|
+
);
|
|
17641
17789
|
const embeddingData = [];
|
|
17642
17790
|
let dimension;
|
|
17643
17791
|
await Promise.all(
|
|
@@ -17655,9 +17803,11 @@ ${workingMemory}`;
|
|
|
17655
17803
|
if (result2.usage?.tokens) {
|
|
17656
17804
|
totalTokens += result2.usage.tokens;
|
|
17657
17805
|
}
|
|
17806
|
+
const threadMetadata = message.threadId ? threadMetadataMap.get(message.threadId) || {} : {};
|
|
17658
17807
|
embeddingData.push({
|
|
17659
17808
|
embeddings: result2.embeddings,
|
|
17660
17809
|
metadata: result2.chunks.map(() => ({
|
|
17810
|
+
...threadMetadata,
|
|
17661
17811
|
message_id: message.id,
|
|
17662
17812
|
thread_id: message.threadId,
|
|
17663
17813
|
resource_id: message.resourceId
|
|
@@ -17940,8 +18090,10 @@ ${workingMemory}`;
|
|
|
17940
18090
|
*/
|
|
17941
18091
|
async persistMessages(messages) {
|
|
17942
18092
|
if (messages.length === 0) return;
|
|
18093
|
+
const persistableMessages = messages.filter((m) => m.role !== "system");
|
|
18094
|
+
if (persistableMessages.length === 0) return;
|
|
17943
18095
|
const memoryStore = await this.getMemoryStore();
|
|
17944
|
-
await memoryStore.saveMessages({ messages });
|
|
18096
|
+
await memoryStore.saveMessages({ messages: persistableMessages });
|
|
17945
18097
|
}
|
|
17946
18098
|
/**
|
|
17947
18099
|
* One-time initialization of the shared ObservationalMemory engine.
|
|
@@ -17968,7 +18120,7 @@ ${workingMemory}`;
|
|
|
17968
18120
|
"Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
|
|
17969
18121
|
);
|
|
17970
18122
|
}
|
|
17971
|
-
const { ObservationalMemory: OMClass } = await import('./observational-memory-
|
|
18123
|
+
const { ObservationalMemory: OMClass } = await import('./observational-memory-TASIB4PH.cjs');
|
|
17972
18124
|
const onIndexObservations = this.hasRetrievalSearch(omConfig.retrieval) ? async (observation) => {
|
|
17973
18125
|
await this.indexObservation(observation);
|
|
17974
18126
|
} : void 0;
|
|
@@ -18894,7 +19046,7 @@ Notes:
|
|
|
18894
19046
|
if (!effectiveConfig) return null;
|
|
18895
19047
|
const engine = await this.omEngine;
|
|
18896
19048
|
if (!engine) return null;
|
|
18897
|
-
const { ObservationalMemoryProcessor } = await import('./observational-memory-
|
|
19049
|
+
const { ObservationalMemoryProcessor } = await import('./observational-memory-TASIB4PH.cjs');
|
|
18898
19050
|
return new ObservationalMemoryProcessor(engine, this, {
|
|
18899
19051
|
temporalMarkers: effectiveConfig.temporalMarkers
|
|
18900
19052
|
});
|
|
@@ -18903,11 +19055,11 @@ Notes:
|
|
|
18903
19055
|
|
|
18904
19056
|
Object.defineProperty(exports, "ModelByInputTokens", {
|
|
18905
19057
|
enumerable: true,
|
|
18906
|
-
get: function () { return
|
|
19058
|
+
get: function () { return chunkMJNTQ6GP_cjs.ModelByInputTokens; }
|
|
18907
19059
|
});
|
|
18908
19060
|
Object.defineProperty(exports, "getObservationsAsOf", {
|
|
18909
19061
|
enumerable: true,
|
|
18910
|
-
get: function () { return
|
|
19062
|
+
get: function () { return chunkMJNTQ6GP_cjs.getObservationsAsOf; }
|
|
18911
19063
|
});
|
|
18912
19064
|
Object.defineProperty(exports, "MessageHistory", {
|
|
18913
19065
|
enumerable: true,
|