@mastra/memory 0.0.0-bundle-recursion-20251030002519 → 0.0.0-bundle-studio-cloud-20251222034739

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 (39) hide show
  1. package/CHANGELOG.md +776 -4
  2. package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +7549 -0
  3. package/dist/chunk-2CIPVDK5.js +250 -0
  4. package/dist/chunk-2CIPVDK5.js.map +1 -0
  5. package/dist/chunk-E53QBCQN.js +84 -0
  6. package/dist/chunk-E53QBCQN.js.map +1 -0
  7. package/dist/chunk-LRWWUW22.cjs +252 -0
  8. package/dist/chunk-LRWWUW22.cjs.map +1 -0
  9. package/dist/chunk-MWO6ARUW.cjs +89 -0
  10. package/dist/chunk-MWO6ARUW.cjs.map +1 -0
  11. package/dist/index.cjs +9293 -202
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.ts +21 -43
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +9262 -205
  16. package/dist/index.js.map +1 -1
  17. package/dist/token-6GSAFR2W-KVDFAJ2M.js +61 -0
  18. package/dist/token-6GSAFR2W-KVDFAJ2M.js.map +1 -0
  19. package/dist/token-6GSAFR2W-RTFFMWTB.cjs +63 -0
  20. package/dist/token-6GSAFR2W-RTFFMWTB.cjs.map +1 -0
  21. package/dist/token-util-NEHG7TUY-7TEUOH7J.cjs +10 -0
  22. package/dist/token-util-NEHG7TUY-7TEUOH7J.cjs.map +1 -0
  23. package/dist/token-util-NEHG7TUY-DJYRKLRD.js +8 -0
  24. package/dist/token-util-NEHG7TUY-DJYRKLRD.js.map +1 -0
  25. package/dist/tools/working-memory.d.ts +10 -14
  26. package/dist/tools/working-memory.d.ts.map +1 -1
  27. package/dist/working-memory-utils.d.ts +20 -0
  28. package/dist/working-memory-utils.d.ts.map +1 -0
  29. package/package.json +20 -30
  30. package/dist/processors/index.cjs +0 -165
  31. package/dist/processors/index.cjs.map +0 -1
  32. package/dist/processors/index.d.ts +0 -3
  33. package/dist/processors/index.d.ts.map +0 -1
  34. package/dist/processors/index.js +0 -158
  35. package/dist/processors/index.js.map +0 -1
  36. package/dist/processors/token-limiter.d.ts +0 -32
  37. package/dist/processors/token-limiter.d.ts.map +0 -1
  38. package/dist/processors/tool-call-filter.d.ts +0 -20
  39. package/dist/processors/tool-call-filter.d.ts.map +0 -1
@@ -0,0 +1,61 @@
1
+ import { require_token_util } from './chunk-2CIPVDK5.js';
2
+ import { __commonJS, require_token_error } from './chunk-E53QBCQN.js';
3
+
4
+ // ../_vendored/ai_v5/dist/token-6GSAFR2W.js
5
+ var require_token = __commonJS({
6
+ "../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/token.js"(exports, module) {
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var token_exports = {};
25
+ __export(token_exports, {
26
+ refreshToken: () => refreshToken
27
+ });
28
+ module.exports = __toCommonJS(token_exports);
29
+ var import_token_error = require_token_error();
30
+ var import_token_util = require_token_util();
31
+ async function refreshToken() {
32
+ const { projectId, teamId } = (0, import_token_util.findProjectInfo)();
33
+ let maybeToken = (0, import_token_util.loadToken)(projectId);
34
+ if (!maybeToken || (0, import_token_util.isExpired)((0, import_token_util.getTokenPayload)(maybeToken.token))) {
35
+ const authToken = (0, import_token_util.getVercelCliToken)();
36
+ if (!authToken) {
37
+ throw new import_token_error.VercelOidcTokenError(
38
+ "Failed to refresh OIDC token: login to vercel cli"
39
+ );
40
+ }
41
+ if (!projectId) {
42
+ throw new import_token_error.VercelOidcTokenError(
43
+ "Failed to refresh OIDC token: project id not found"
44
+ );
45
+ }
46
+ maybeToken = await (0, import_token_util.getVercelOidcToken)(authToken, projectId, teamId);
47
+ if (!maybeToken) {
48
+ throw new import_token_error.VercelOidcTokenError("Failed to refresh OIDC token");
49
+ }
50
+ (0, import_token_util.saveToken)(maybeToken, projectId);
51
+ }
52
+ process.env.VERCEL_OIDC_TOKEN = maybeToken.token;
53
+ return;
54
+ }
55
+ }
56
+ });
57
+ var token6GSAFR2W = require_token();
58
+
59
+ export { token6GSAFR2W as default };
60
+ //# sourceMappingURL=token-6GSAFR2W-KVDFAJ2M.js.map
61
+ //# sourceMappingURL=token-6GSAFR2W-KVDFAJ2M.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/token.js"],"names":[],"mappings":";;;;AAAA,IAAA,gBAAA,UAAA,CAAA;AAAA,EAAA,wFAAA,CAAA,SAAA,MAAA,EAAA;AACA,IAAA,IAAI,YAAY,MAAA,CAAO,cAAA;AACvB,IAAA,IAAI,mBAAmB,MAAA,CAAO,wBAAA;AAC9B,IAAA,IAAI,oBAAoB,MAAA,CAAO,mBAAA;AAC/B,IAAA,IAAI,YAAA,GAAe,OAAO,SAAA,CAAU,cAAA;AACpC,IAAA,IAAI,QAAA,GAAW,CAAC,MAAA,EAAQ,GAAA,KAAQ;AAC9B,MAAA,KAAA,IAAS,IAAA,IAAQ,GAAA;AACf,QAAA,SAAA,CAAU,MAAA,EAAQ,MAAM,EAAE,GAAA,EAAK,IAAI,IAAI,CAAA,EAAG,UAAA,EAAY,IAAA,EAAM,CA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AkB,eAAA,EAAiB,UAAA,CAAW,KAAK,CAAC,CAAA,EAAG;AAC7G,QAAA,MAAM,SAAA,GAAA,IAAgB,iBAAA,CAAkB,iBAAA,GAAA;AACxC,QAAA,IAAI,CAAC,SAAA,EAAW;AACd,UAAA,MAAM,IAAI,kBAAA,CAAmB,oBAAA;AAC3B,YAAA;AAAA,WAAA;AAEJ,QAAA;AACA,QAAA,IAAI,CAAC,SAAA,EAAW;AACd,UAAA,MAAM,IAAI,kBAAA,CAAmB,oBAAA;AAC3B,YAAA;AAAA,WAAA;AAEJ,QAAA;AACA,QAAA,UAAA,GAAa,UAAU,iBAAA,CAAkB,kBAAA,EAAoB,SAAA,EAAW,WAAW,MAAM,CAAA;AACzF,QAAA,IAAI,CAAC,UAAA,EAAY;AACf,UAAA,MAAM,IAAI,kBAAA,CAAmB,oBAAA,CAAqB,8BAA8B,CAAA;AAClF,QAAA;AACA,QAAA,IAAI,iBAAA,CAAkB,SAAA,EAAW,UAAA,EAAY,SAAS,CAAA;AACxD,MAAA;AACA,MAAA,OAAA,CAAQ,GAAA,CAAI,oBAAoB,UAAA,CAAW,KAAA;AAC3C,MAAA;AACF,IAAA;AAAA,EAAA;AAAA,CAAA,CAAA","file":"token-6GSAFR2W-KVDFAJ2M.js","sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar token_exports = {};\n__export(token_exports, {\n refreshToken: () => refreshToken\n});\nmodule.exports = __toCommonJS(token_exports);\nvar import_token_error = require(\"./token-error\");\nvar import_token_util = require(\"./token-util\");\nasync function refreshToken() {\n const { projectId, teamId } = (0, import_token_util.findProjectInfo)();\n let maybeToken = (0, import_token_util.loadToken)(projectId);\n if (!maybeToken || (0, import_token_util.isExpired)((0, import_token_util.getTokenPayload)(maybeToken.token))) {\n const authToken = (0, import_token_util.getVercelCliToken)();\n if (!authToken) {\n throw new import_token_error.VercelOidcTokenError(\n \"Failed to refresh OIDC token: login to vercel cli\"\n );\n }\n if (!projectId) {\n throw new import_token_error.VercelOidcTokenError(\n \"Failed to refresh OIDC token: project id not found\"\n );\n }\n maybeToken = await (0, import_token_util.getVercelOidcToken)(authToken, projectId, teamId);\n if (!maybeToken) {\n throw new import_token_error.VercelOidcTokenError(\"Failed to refresh OIDC token\");\n }\n (0, import_token_util.saveToken)(maybeToken, projectId);\n }\n process.env.VERCEL_OIDC_TOKEN = maybeToken.token;\n return;\n}\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n refreshToken\n});\n"]}
@@ -0,0 +1,63 @@
1
+ 'use strict';
2
+
3
+ var chunkLRWWUW22_cjs = require('./chunk-LRWWUW22.cjs');
4
+ var chunkMWO6ARUW_cjs = require('./chunk-MWO6ARUW.cjs');
5
+
6
+ // ../_vendored/ai_v5/dist/token-6GSAFR2W.js
7
+ var require_token = chunkMWO6ARUW_cjs.__commonJS({
8
+ "../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/token.js"(exports, module) {
9
+ var __defProp = Object.defineProperty;
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __getOwnPropNames = Object.getOwnPropertyNames;
12
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
13
+ var __export = (target, all) => {
14
+ for (var name in all)
15
+ __defProp(target, name, { get: all[name], enumerable: true });
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+ var token_exports = {};
27
+ __export(token_exports, {
28
+ refreshToken: () => refreshToken
29
+ });
30
+ module.exports = __toCommonJS(token_exports);
31
+ var import_token_error = chunkMWO6ARUW_cjs.require_token_error();
32
+ var import_token_util = chunkLRWWUW22_cjs.require_token_util();
33
+ async function refreshToken() {
34
+ const { projectId, teamId } = (0, import_token_util.findProjectInfo)();
35
+ let maybeToken = (0, import_token_util.loadToken)(projectId);
36
+ if (!maybeToken || (0, import_token_util.isExpired)((0, import_token_util.getTokenPayload)(maybeToken.token))) {
37
+ const authToken = (0, import_token_util.getVercelCliToken)();
38
+ if (!authToken) {
39
+ throw new import_token_error.VercelOidcTokenError(
40
+ "Failed to refresh OIDC token: login to vercel cli"
41
+ );
42
+ }
43
+ if (!projectId) {
44
+ throw new import_token_error.VercelOidcTokenError(
45
+ "Failed to refresh OIDC token: project id not found"
46
+ );
47
+ }
48
+ maybeToken = await (0, import_token_util.getVercelOidcToken)(authToken, projectId, teamId);
49
+ if (!maybeToken) {
50
+ throw new import_token_error.VercelOidcTokenError("Failed to refresh OIDC token");
51
+ }
52
+ (0, import_token_util.saveToken)(maybeToken, projectId);
53
+ }
54
+ process.env.VERCEL_OIDC_TOKEN = maybeToken.token;
55
+ return;
56
+ }
57
+ }
58
+ });
59
+ var token6GSAFR2W = require_token();
60
+
61
+ module.exports = token6GSAFR2W;
62
+ //# sourceMappingURL=token-6GSAFR2W-RTFFMWTB.cjs.map
63
+ //# sourceMappingURL=token-6GSAFR2W-RTFFMWTB.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/token.js"],"names":["__commonJS","require_token_error","require_token_util"],"mappings":";;;;;;AAAA,IAAA,gBAAAA,4BAAA,CAAA;AAAA,EAAA,wFAAA,CAAA,SAAA,MAAA,EAAA;AACA,IAAA,IAAI,YAAY,MAAA,CAAO,cAAA;AACvB,IAAA,IAAI,mBAAmB,MAAA,CAAO,wBAAA;AAC9B,IAAA,IAAI,oBAAoB,MAAA,CAAO,mBAAA;AAC/B,IAAA,IAAI,YAAA,GAAe,OAAO,SAAA,CAAU,cAAA;AACpC,IAAA,IAAI,QAAA,GAAW,CAAC,MAAA,EAAQ,GAAA,KAAQ;AAC9B,MAAA,KAAA,IAAS,IAAA,IAAQ,GAAA;AACf,QAAA,SAAA,CAAU,MAAA,EAAQ,MAAM,EAAE,GAAA,EAAK,IAAI,IAAI,CAAA,EAAG,UAAA,EAAY,IAAA,EAAM,CAAA;AAChE,IAAA,CAAA;AACA,IAAA,IAAI,WAAA,GAAc,CAAC,EAAA,EAAI,IAAA,EAAM,QAAQ,IAAA,KAAS;AAC5C,MAAA,IAAI,QAAQ,OAAO,IAAA,KAAS,QAAA,IAAY,OAAO,SAAS,UAAA,EAAY;AAClE,QAAA,KAAA,IAAS,GAAA,IAAO,kBAAkB,IAAI,CAAA;AACpC,UAAA,IAAI,CAAC,YAAA,CAAa,IAAA,CAAK,EAAA,EAAI,GAAG,KAAK,GAAA,KAAQ,MAAA;AACzC,YAAA,SAAA,CAAU,IAAI,GAAA,EAAK,EAAE,GAAA,EAAK,MAAM,KAAK,GAAG,CAAA,EAAG,UAAA,EAAY,EAAE,OAAO,gBAAA,CAAiB,IAAA,EAAM,GAAG,CAAA,CAAA,IAAM,IAAA,CAAK,YAAY,CAAA;AACvH,MAAA;AACA,MAAA,OAAO,EAAA;AACT,IAAA,CAAA;AACA,IAAA,IAAI,YAAA,GAAe,CAAC,GAAA,KAAQ,WAAA,CAAY,SA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xD,MAAA;AACA,MAAA,OAAA,CAAQ,GAAA,CAAI,oBAAoB,UAAA,CAAW,KAAA;AAC3C,MAAA;AACF,IAAA;AAAA,EAAA;AAAA,CAAA,CAAA","file":"token-6GSAFR2W-RTFFMWTB.cjs","sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar token_exports = {};\n__export(token_exports, {\n refreshToken: () => refreshToken\n});\nmodule.exports = __toCommonJS(token_exports);\nvar import_token_error = require(\"./token-error\");\nvar import_token_util = require(\"./token-util\");\nasync function refreshToken() {\n const { projectId, teamId } = (0, import_token_util.findProjectInfo)();\n let maybeToken = (0, import_token_util.loadToken)(projectId);\n if (!maybeToken || (0, import_token_util.isExpired)((0, import_token_util.getTokenPayload)(maybeToken.token))) {\n const authToken = (0, import_token_util.getVercelCliToken)();\n if (!authToken) {\n throw new import_token_error.VercelOidcTokenError(\n \"Failed to refresh OIDC token: login to vercel cli\"\n );\n }\n if (!projectId) {\n throw new import_token_error.VercelOidcTokenError(\n \"Failed to refresh OIDC token: project id not found\"\n );\n }\n maybeToken = await (0, import_token_util.getVercelOidcToken)(authToken, projectId, teamId);\n if (!maybeToken) {\n throw new import_token_error.VercelOidcTokenError(\"Failed to refresh OIDC token\");\n }\n (0, import_token_util.saveToken)(maybeToken, projectId);\n }\n process.env.VERCEL_OIDC_TOKEN = maybeToken.token;\n return;\n}\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n refreshToken\n});\n"]}
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ var chunkLRWWUW22_cjs = require('./chunk-LRWWUW22.cjs');
4
+
5
+ // ../_vendored/ai_v5/dist/token-util-NEHG7TUY.js
6
+ var tokenUtilNEHG7TUY = chunkLRWWUW22_cjs.require_token_util();
7
+
8
+ module.exports = tokenUtilNEHG7TUY;
9
+ //# sourceMappingURL=token-util-NEHG7TUY-7TEUOH7J.cjs.map
10
+ //# sourceMappingURL=token-util-NEHG7TUY-7TEUOH7J.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../_vendored/ai_v5/dist/token-util-NEHG7TUY.js"],"names":["require_token_util"],"mappings":";;;;;AAEA,IAAI,oBAAoBA,oCAAA","file":"token-util-NEHG7TUY-7TEUOH7J.cjs","sourcesContent":["import { require_token_util } from './chunk-OL3SSKUZ.js';\n\nvar tokenUtilNEHG7TUY = require_token_util();\n\nexport { tokenUtilNEHG7TUY as default };\n//# sourceMappingURL=token-util-NEHG7TUY.js.map\n//# sourceMappingURL=token-util-NEHG7TUY.js.map"]}
@@ -0,0 +1,8 @@
1
+ import { require_token_util } from './chunk-2CIPVDK5.js';
2
+
3
+ // ../_vendored/ai_v5/dist/token-util-NEHG7TUY.js
4
+ var tokenUtilNEHG7TUY = require_token_util();
5
+
6
+ export { tokenUtilNEHG7TUY as default };
7
+ //# sourceMappingURL=token-util-NEHG7TUY-DJYRKLRD.js.map
8
+ //# sourceMappingURL=token-util-NEHG7TUY-DJYRKLRD.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../_vendored/ai_v5/dist/token-util-NEHG7TUY.js"],"names":[],"mappings":";;;AAEA,IAAI,oBAAoB,kBAAA","file":"token-util-NEHG7TUY-DJYRKLRD.js","sourcesContent":["import { require_token_util } from './chunk-OL3SSKUZ.js';\n\nvar tokenUtilNEHG7TUY = require_token_util();\n\nexport { tokenUtilNEHG7TUY as default };\n//# sourceMappingURL=token-util-NEHG7TUY.js.map\n//# sourceMappingURL=token-util-NEHG7TUY.js.map"]}
@@ -1,6 +1,14 @@
1
1
  import type { MemoryConfig } from '@mastra/core/memory';
2
2
  import { z } from 'zod';
3
- export declare const updateWorkingMemoryTool: (memoryConfig?: MemoryConfig) => import("@mastra/core/tools").Tool<z.ZodType<any, z.ZodTypeDef, any>, undefined, any, any, import("@mastra/core").ToolExecutionContext<z.ZodType<any, z.ZodTypeDef, any>, any, any>>;
3
+ /**
4
+ * Deep merges two objects, with special handling for null values (delete) and arrays (replace).
5
+ * - Object properties are recursively merged
6
+ * - null values in the update will delete the corresponding property
7
+ * - Arrays are replaced entirely (not merged element-by-element)
8
+ * - Primitive values are overwritten
9
+ */
10
+ export declare function deepMergeWorkingMemory(existing: Record<string, unknown> | null | undefined, update: Record<string, unknown>): Record<string, unknown>;
11
+ export declare const updateWorkingMemoryTool: (memoryConfig?: MemoryConfig) => import("@mastra/core/tools").Tool<z.ZodType<any, z.ZodTypeDef, any>, undefined, any, any, import("@mastra/core/tools").ToolExecutionContext<any, any>, "update-working-memory">;
4
12
  export declare const __experimental_updateWorkingMemoryToolVNext: (config: MemoryConfig) => import("@mastra/core/tools").Tool<z.ZodObject<{
5
13
  newMemory: z.ZodOptional<z.ZodString>;
6
14
  searchString: z.ZodOptional<z.ZodString>;
@@ -13,17 +21,5 @@ export declare const __experimental_updateWorkingMemoryToolVNext: (config: Memor
13
21
  newMemory?: string | undefined;
14
22
  searchString?: string | undefined;
15
23
  updateReason?: "append-new-memory" | "clarify-existing-memory" | "replace-irrelevant-memory" | undefined;
16
- }>, undefined, any, any, import("@mastra/core").ToolExecutionContext<z.ZodObject<{
17
- newMemory: z.ZodOptional<z.ZodString>;
18
- searchString: z.ZodOptional<z.ZodString>;
19
- updateReason: z.ZodOptional<z.ZodEnum<["append-new-memory", "clarify-existing-memory", "replace-irrelevant-memory"]>>;
20
- }, "strip", z.ZodTypeAny, {
21
- newMemory?: string | undefined;
22
- searchString?: string | undefined;
23
- updateReason?: "append-new-memory" | "clarify-existing-memory" | "replace-irrelevant-memory" | undefined;
24
- }, {
25
- newMemory?: string | undefined;
26
- searchString?: string | undefined;
27
- updateReason?: "append-new-memory" | "clarify-existing-memory" | "replace-irrelevant-memory" | undefined;
28
- }>, any, any>>;
24
+ }>, undefined, any, any, import("@mastra/core/tools").ToolExecutionContext<any, any>, "update-working-memory">;
29
25
  //# sourceMappingURL=working-memory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"working-memory.d.ts","sourceRoot":"","sources":["../../src/tools/working-memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAIxD,OAAO,EAAE,CAAC,EAAa,MAAM,KAAK,CAAC;AAGnC,eAAO,MAAM,uBAAuB,GAAI,eAAe,YAAY,wLAyDlE,CAAC;AAEF,eAAO,MAAM,2CAA2C,GAAI,QAAQ,YAAY;;;;;;;;;;;;;;;;;;;;;;;;cAuF/E,CAAC"}
1
+ {"version":3,"file":"working-memory.d.ts","sourceRoot":"","sources":["../../src/tools/working-memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAIxD,OAAO,EAAE,CAAC,EAAa,MAAM,KAAK,CAAC;AAGnC;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,EACpD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAuCzB;AAED,eAAO,MAAM,uBAAuB,GAAI,eAAe,YAAY,oLA8GlE,CAAC;AAEF,eAAO,MAAM,2CAA2C,GAAI,QAAQ,YAAY;;;;;;;;;;;;8GA6F/E,CAAC"}
@@ -0,0 +1,20 @@
1
+ export declare const WORKING_MEMORY_START_TAG = "<working_memory>";
2
+ export declare const WORKING_MEMORY_END_TAG = "</working_memory>";
3
+ /**
4
+ * Extracts all working memory tag contents from text using indexOf-based parsing.
5
+ * This avoids ReDoS vulnerability that exists with regex-based approaches.
6
+ * @returns Array of full matches (including tags) or null if no matches
7
+ */
8
+ export declare function extractWorkingMemoryTags(text: string): string[] | null;
9
+ /**
10
+ * Removes all working memory tags and their contents from text.
11
+ * Uses indexOf-based parsing to avoid ReDoS vulnerability.
12
+ */
13
+ export declare function removeWorkingMemoryTags(text: string): string;
14
+ /**
15
+ * Extracts the content of the first working memory tag (without the tags themselves).
16
+ * Uses indexOf-based parsing to avoid ReDoS vulnerability.
17
+ * @returns The content between the tags, or null if no valid tag pair found
18
+ */
19
+ export declare function extractWorkingMemoryContent(text: string): string | null;
20
+ //# sourceMappingURL=working-memory-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"working-memory-utils.d.ts","sourceRoot":"","sources":["../src/working-memory-utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,qBAAqB,CAAC;AAC3D,eAAO,MAAM,sBAAsB,sBAAsB,CAAC;AAE1D;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAgBtE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAwB5D;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CASvE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/memory",
3
- "version": "0.0.0-bundle-recursion-20251030002519",
3
+ "version": "0.0.0-bundle-studio-cloud-20251222034739",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -20,54 +20,41 @@
20
20
  "default": "./dist/index.cjs"
21
21
  }
22
22
  },
23
- "./processors": {
24
- "import": {
25
- "types": "./dist/processors/index.d.ts",
26
- "default": "./dist/processors/index.js"
27
- },
28
- "require": {
29
- "types": "./dist/processors/index.d.ts",
30
- "default": "./dist/processors/index.cjs"
31
- }
32
- },
33
23
  "./package.json": "./package.json"
34
24
  },
35
25
  "keywords": [],
36
26
  "author": "",
37
27
  "license": "Apache-2.0",
38
28
  "dependencies": {
39
- "@upstash/redis": "^1.35.5",
40
- "ai": "^4.3.19",
41
- "ai-v5": "npm:ai@5.0.60",
29
+ "async-mutex": "^0.5.0",
42
30
  "js-tiktoken": "^1.0.20",
43
31
  "json-schema": "^0.4.0",
44
- "pg": "^8.16.3",
45
- "pg-pool": "^3.10.1",
46
- "postgres": "^3.4.7",
47
- "redis": "^5.8.3",
48
- "async-mutex": "^0.5.0",
32
+ "lru-cache": "^11.2.2",
49
33
  "xxhash-wasm": "^1.1.0",
50
- "zod-to-json-schema": "^3.24.6",
51
- "@mastra/schema-compat": "0.0.0-bundle-recursion-20251030002519"
34
+ "@mastra/schema-compat": "0.0.0-bundle-studio-cloud-20251222034739"
52
35
  },
53
36
  "devDependencies": {
54
37
  "@ai-sdk/openai": "^1.3.24",
55
- "@microsoft/api-extractor": "^7.52.8",
38
+ "@ai-sdk/openai-v5": "npm:@ai-sdk/openai@2.0.53",
56
39
  "@types/json-schema": "^7.0.15",
57
- "@types/node": "^20.19.0",
58
- "@types/pg": "^8.15.5",
40
+ "@types/lru-cache": "^7.10.10",
41
+ "@types/node": "22.13.17",
42
+ "@vitest/coverage-v8": "4.0.12",
43
+ "@vitest/ui": "4.0.12",
59
44
  "eslint": "^9.37.0",
60
45
  "tsup": "^8.5.0",
61
46
  "typescript": "^5.8.3",
62
47
  "typescript-eslint": "^8.38.0",
63
- "vitest": "^3.2.4",
64
- "@internal/lint": "0.0.0-bundle-recursion-20251030002519",
65
- "@mastra/core": "0.0.0-bundle-recursion-20251030002519",
66
- "@internal/types-builder": "0.0.0-bundle-recursion-20251030002519"
48
+ "vitest": "4.0.12",
49
+ "@internal/ai-sdk-v4": "0.0.0-bundle-studio-cloud-20251222034739",
50
+ "@internal/ai-sdk-v5": "0.0.0-bundle-studio-cloud-20251222034739",
51
+ "@internal/lint": "0.0.0-bundle-studio-cloud-20251222034739",
52
+ "@internal/types-builder": "0.0.0-bundle-studio-cloud-20251222034739",
53
+ "@mastra/core": "0.0.0-bundle-studio-cloud-20251222034739"
67
54
  },
68
55
  "peerDependencies": {
69
56
  "zod": "^3.25.0 || ^4.0.0",
70
- "@mastra/core": "0.0.0-bundle-recursion-20251030002519"
57
+ "@mastra/core": "0.0.0-bundle-studio-cloud-20251222034739"
71
58
  },
72
59
  "homepage": "https://mastra.ai",
73
60
  "repository": {
@@ -78,9 +65,12 @@
78
65
  "bugs": {
79
66
  "url": "https://github.com/mastra-ai/mastra/issues"
80
67
  },
68
+ "engines": {
69
+ "node": ">=22.13.0"
70
+ },
81
71
  "scripts": {
82
72
  "check": "tsc --noEmit",
83
- "build": "pnpm run check && tsup --silent --config tsup.config.ts",
73
+ "build": "tsup --silent --config tsup.config.ts",
84
74
  "build:watch": "pnpm build --watch",
85
75
  "test:integration": "cd integration-tests && pnpm run test",
86
76
  "test:unit": "pnpm vitest run ./src/*",
@@ -1,165 +0,0 @@
1
- 'use strict';
2
-
3
- var memory = require('@mastra/core/memory');
4
- var lite = require('js-tiktoken/lite');
5
- var o200k_base = require('js-tiktoken/ranks/o200k_base');
6
-
7
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
-
9
- var o200k_base__default = /*#__PURE__*/_interopDefault(o200k_base);
10
-
11
- // src/processors/token-limiter.ts
12
- var TokenLimiter = class extends memory.MemoryProcessor {
13
- encoder;
14
- maxTokens;
15
- // Token overheads per OpenAI's documentation
16
- // See: https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken#6-counting-tokens-for-chat-completions-api-calls
17
- // Every message follows <|start|>{role/name}\n{content}<|end|>
18
- TOKENS_PER_MESSAGE = 3.8;
19
- // tokens added for each message (start & end tokens)
20
- TOKENS_PER_CONVERSATION = 24;
21
- // fixed overhead for the conversation
22
- /**
23
- * Create a token limiter for messages.
24
- * @param options Either a number (token limit) or a configuration object
25
- */
26
- constructor(options) {
27
- super({
28
- name: "TokenLimiter"
29
- });
30
- if (typeof options === "number") {
31
- this.maxTokens = options;
32
- this.encoder = new lite.Tiktoken(o200k_base__default.default);
33
- } else {
34
- this.maxTokens = options.limit;
35
- this.encoder = new lite.Tiktoken(options.encoding || o200k_base__default.default);
36
- }
37
- }
38
- process(messages, { systemMessage, memorySystemMessage, newMessages } = {}) {
39
- let totalTokens = 0;
40
- totalTokens += this.TOKENS_PER_CONVERSATION;
41
- if (systemMessage) {
42
- totalTokens += this.countTokens(systemMessage);
43
- totalTokens += this.TOKENS_PER_MESSAGE;
44
- }
45
- if (memorySystemMessage) {
46
- totalTokens += this.countTokens(memorySystemMessage);
47
- totalTokens += this.TOKENS_PER_MESSAGE;
48
- }
49
- const allMessages = [...messages, ...newMessages || []];
50
- const result = [];
51
- for (let i = allMessages.length - 1; i >= 0; i--) {
52
- const message = allMessages[i];
53
- if (!message) continue;
54
- const messageTokens = this.countTokens(message);
55
- if (totalTokens + messageTokens <= this.maxTokens) {
56
- if (i < messages.length) {
57
- result.unshift(message);
58
- }
59
- totalTokens += messageTokens;
60
- } else {
61
- this.logger.info(
62
- `filtering ${allMessages.length - result.length}/${allMessages.length} messages, token limit of ${this.maxTokens} exceeded`
63
- );
64
- break;
65
- }
66
- }
67
- return result;
68
- }
69
- countTokens(message) {
70
- if (typeof message === `string`) {
71
- return this.encoder.encode(message).length;
72
- }
73
- let tokenString = message.role;
74
- let overhead = 0;
75
- if (typeof message.content === "string" && message.content) {
76
- tokenString += message.content;
77
- } else if (Array.isArray(message.content)) {
78
- for (const part of message.content) {
79
- if (part.type === "text") {
80
- tokenString += part.text;
81
- } else if (part.type === "tool-call" || part.type === `tool-result`) {
82
- if (`args` in part && part.args && part.type === `tool-call`) {
83
- tokenString += part.toolName;
84
- if (typeof part.args === "string") {
85
- tokenString += part.args;
86
- } else {
87
- tokenString += JSON.stringify(part.args);
88
- overhead -= 12;
89
- }
90
- }
91
- if (`result` in part && part.result !== void 0 && part.type === `tool-result`) {
92
- if (typeof part.result === "string") {
93
- tokenString += part.result;
94
- } else {
95
- tokenString += JSON.stringify(part.result);
96
- overhead -= 12;
97
- }
98
- }
99
- } else {
100
- tokenString += JSON.stringify(part);
101
- }
102
- }
103
- }
104
- if (typeof message.content === `string` || // if the message included non-tool parts, add our message overhead
105
- message.content.some((p) => p.type !== `tool-call` && p.type !== `tool-result`)) {
106
- overhead += this.TOKENS_PER_MESSAGE;
107
- }
108
- return this.encoder.encode(tokenString).length + overhead;
109
- }
110
- };
111
- var ToolCallFilter = class extends memory.MemoryProcessor {
112
- exclude;
113
- /**
114
- * Create a filter for tool calls and results.
115
- * @param options Configuration options
116
- * @param options.exclude List of specific tool names to exclude. If not provided, all tool calls are excluded.
117
- */
118
- constructor(options = {}) {
119
- super({ name: "ToolCallFilter" });
120
- if (!options || !options.exclude) {
121
- this.exclude = "all";
122
- } else {
123
- this.exclude = Array.isArray(options.exclude) ? options.exclude : [];
124
- }
125
- }
126
- process(messages) {
127
- if (this.exclude === "all") {
128
- return messages.filter((message) => {
129
- if (Array.isArray(message.content)) {
130
- return !message.content.some((part) => part.type === "tool-call" || part.type === "tool-result");
131
- }
132
- return true;
133
- });
134
- }
135
- if (this.exclude.length > 0) {
136
- const excludedToolCallIds = /* @__PURE__ */ new Set();
137
- return messages.filter((message) => {
138
- if (!Array.isArray(message.content)) return true;
139
- if (message.role === "assistant") {
140
- let shouldExclude = false;
141
- for (const part of message.content) {
142
- if (part.type === "tool-call" && this.exclude.includes(part.toolName)) {
143
- excludedToolCallIds.add(part.toolCallId);
144
- shouldExclude = true;
145
- }
146
- }
147
- return !shouldExclude;
148
- }
149
- if (message.role === "tool") {
150
- const shouldExclude = message.content.some(
151
- (part) => part.type === "tool-result" && excludedToolCallIds.has(part.toolCallId)
152
- );
153
- return !shouldExclude;
154
- }
155
- return true;
156
- });
157
- }
158
- return messages;
159
- }
160
- };
161
-
162
- exports.TokenLimiter = TokenLimiter;
163
- exports.ToolCallFilter = ToolCallFilter;
164
- //# sourceMappingURL=index.cjs.map
165
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/processors/token-limiter.ts","../../src/processors/tool-call-filter.ts"],"names":["MemoryProcessor","Tiktoken","o200k_base"],"mappings":";;;;;;;;;;;AAsBO,IAAM,YAAA,GAAN,cAA2BA,sBAAA,CAAgB;AAAA,EACxC,OAAA;AAAA,EACA,SAAA;AAAA;AAAA;AAAA;AAAA,EAKD,kBAAA,GAAqB,GAAA;AAAA;AAAA,EACrB,uBAAA,GAA0B,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMjC,YAAY,OAAA,EAAuC;AACjD,IAAA,KAAA,CAAM;AAAA,MACJ,IAAA,EAAM;AAAA,KACP,CAAA;AAED,IAAA,IAAI,OAAO,YAAY,QAAA,EAAU;AAE/B,MAAA,IAAA,CAAK,SAAA,GAAY,OAAA;AACjB,MAAA,IAAA,CAAK,OAAA,GAAU,IAAIC,aAAA,CAASC,2BAAU,CAAA;AAAA,IACxC,CAAA,MAAO;AAEL,MAAA,IAAA,CAAK,YAAY,OAAA,CAAQ,KAAA;AACzB,MAAA,IAAA,CAAK,OAAA,GAAU,IAAID,aAAA,CAAS,OAAA,CAAQ,YAAYC,2BAAU,CAAA;AAAA,IAC5D;AAAA,EACF;AAAA,EAEA,OAAA,CACE,UACA,EAAE,aAAA,EAAe,qBAAqB,WAAA,EAAY,GAAyB,EAAC,EAC7D;AAEf,IAAA,IAAI,WAAA,GAAc,CAAA;AAGlB,IAAA,WAAA,IAAe,IAAA,CAAK,uBAAA;AAEpB,IAAA,IAAI,aAAA,EAAe;AACjB,MAAA,WAAA,IAAe,IAAA,CAAK,Y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GA,IAAA,OAAO,QAAA;AAAA,EACT;AACF","file":"index.cjs","sourcesContent":["import type { CoreMessage } from '@mastra/core/llm';\nimport { MemoryProcessor } from '@mastra/core/memory';\nimport type { MemoryProcessorOpts } from '@mastra/core/memory';\n\nimport { Tiktoken } from 'js-tiktoken/lite';\nimport type { TiktokenBPE } from 'js-tiktoken/lite';\nimport o200k_base from 'js-tiktoken/ranks/o200k_base';\n\n/**\n * Configuration options for TokenLimiter\n */\ninterface TokenLimiterOptions {\n /** Maximum number of tokens to allow */\n limit: number;\n /** Optional encoding to use (defaults to o200k_base which is used by gpt-4o) */\n encoding?: TiktokenBPE;\n}\n\n/**\n * Limits the total number of tokens in the messages.\n * Uses js-tiktoken with o200k_base encoding by default for accurate token counting with modern models.\n */\nexport class TokenLimiter extends MemoryProcessor {\n private encoder: Tiktoken;\n private maxTokens: number;\n\n // Token overheads per OpenAI's documentation\n // See: https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken#6-counting-tokens-for-chat-completions-api-calls\n // Every message follows <|start|>{role/name}\\n{content}<|end|>\n public TOKENS_PER_MESSAGE = 3.8; // tokens added for each message (start & end tokens)\n public TOKENS_PER_CONVERSATION = 24; // fixed overhead for the conversation\n\n /**\n * Create a token limiter for messages.\n * @param options Either a number (token limit) or a configuration object\n */\n constructor(options: number | TokenLimiterOptions) {\n super({\n name: 'TokenLimiter',\n });\n\n if (typeof options === 'number') {\n // Simple number format - just the token limit with default encoding\n this.maxTokens = options;\n this.encoder = new Tiktoken(o200k_base);\n } else {\n // Object format with limit and optional encoding\n this.maxTokens = options.limit;\n this.encoder = new Tiktoken(options.encoding || o200k_base);\n }\n }\n\n process(\n messages: CoreMessage[],\n { systemMessage, memorySystemMessage, newMessages }: MemoryProcessorOpts = {},\n ): CoreMessage[] {\n // Messages are already chronologically ordered - take most recent ones up to the token limit\n let totalTokens = 0;\n\n // Start with the conversation overhead\n totalTokens += this.TOKENS_PER_CONVERSATION;\n\n if (systemMessage) {\n totalTokens += this.countTokens(systemMessage);\n totalTokens += this.TOKENS_PER_MESSAGE; // Add message overhead for system message\n }\n\n if (memorySystemMessage) {\n totalTokens += this.countTokens(memorySystemMessage);\n totalTokens += this.TOKENS_PER_MESSAGE; // Add message overhead for memory system message\n }\n\n const allMessages = [...messages, ...(newMessages || [])];\n\n const result: CoreMessage[] = [];\n\n // Process messages in reverse (newest first) so that we stop estimating tokens on old messages. Once we get to our limit of tokens there's no reason to keep processing older messages\n for (let i = allMessages.length - 1; i >= 0; i--) {\n const message = allMessages[i];\n\n // Skip undefined messages (shouldn't happen, but TypeScript is concerned)\n if (!message) continue;\n\n const messageTokens = this.countTokens(message);\n\n if (totalTokens + messageTokens <= this.maxTokens) {\n // Insert at the beginning to maintain chronological order, but only if it's not a new message\n if (i < messages.length) {\n // less than messages.length because we're iterating in reverse. If the index is greater than messages.length it's a new message\n result.unshift(message);\n }\n totalTokens += messageTokens;\n } else {\n this.logger.info(\n `filtering ${allMessages.length - result.length}/${allMessages.length} messages, token limit of ${this.maxTokens} exceeded`,\n );\n // If we can't fit the message, we stop\n break;\n }\n }\n\n return result;\n }\n\n public countTokens(message: string | CoreMessage): number {\n if (typeof message === `string`) {\n return this.encoder.encode(message).length;\n }\n\n let tokenString = message.role;\n let overhead = 0;\n\n if (typeof message.content === 'string' && message.content) {\n tokenString += message.content;\n } else if (Array.isArray(message.content)) {\n // Calculate tokens for each content part\n for (const part of message.content) {\n if (part.type === 'text') {\n tokenString += part.text;\n } else if (part.type === 'tool-call' || part.type === `tool-result`) {\n if (`args` in part && part.args && part.type === `tool-call`) {\n tokenString += part.toolName as any;\n if (typeof part.args === 'string') {\n tokenString += part.args;\n } else {\n tokenString += JSON.stringify(part.args);\n // minus some tokens for JSON\n overhead -= 12;\n }\n }\n // Token cost for result if present\n if (`result` in part && part.result !== undefined && part.type === `tool-result`) {\n if (typeof part.result === 'string') {\n tokenString += part.result;\n } else {\n tokenString += JSON.stringify(part.result);\n // minus some tokens for JSON\n overhead -= 12;\n }\n }\n } else {\n tokenString += JSON.stringify(part);\n }\n }\n }\n\n if (\n typeof message.content === `string` ||\n // if the message included non-tool parts, add our message overhead\n message.content.some(p => p.type !== `tool-call` && p.type !== `tool-result`)\n ) {\n // Ensure we account for message formatting tokens\n // See: https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken#6-counting-tokens-for-chat-completions-api-calls\n overhead += this.TOKENS_PER_MESSAGE;\n }\n\n return this.encoder.encode(tokenString).length + overhead;\n }\n}\n","import type { CoreMessage } from '@mastra/core/llm';\nimport { MemoryProcessor } from '@mastra/core/memory';\n\n/**\n * Filters out tool calls and results from messages.\n * By default (with no arguments), excludes all tool calls and their results.\n * Can be configured to exclude only specific tools by name.\n */\nexport class ToolCallFilter extends MemoryProcessor {\n private exclude: string[] | 'all';\n\n /**\n * Create a filter for tool calls and results.\n * @param options Configuration options\n * @param options.exclude List of specific tool names to exclude. If not provided, all tool calls are excluded.\n */\n constructor(options: { exclude?: string[] } = {}) {\n super({ name: 'ToolCallFilter' });\n // If no options or exclude is provided, exclude all tools\n if (!options || !options.exclude) {\n this.exclude = 'all'; // Exclude all tools\n } else {\n // Exclude specific tools\n this.exclude = Array.isArray(options.exclude) ? options.exclude : [];\n }\n }\n\n process(messages: CoreMessage[]): CoreMessage[] {\n // Case 1: Exclude all tool calls and tool results\n if (this.exclude === 'all') {\n return messages.filter(message => {\n if (Array.isArray(message.content)) {\n return !message.content.some(part => part.type === 'tool-call' || part.type === 'tool-result');\n }\n return true;\n });\n }\n\n // Case 2: Exclude specific tools by name\n if (this.exclude.length > 0) {\n // Single pass approach - track excluded tool call IDs while filtering\n const excludedToolCallIds = new Set<string>();\n\n return messages.filter(message => {\n if (!Array.isArray(message.content)) return true;\n\n // For assistant messages, check for excluded tool calls and track their IDs\n if (message.role === 'assistant') {\n let shouldExclude = false;\n\n for (const part of message.content) {\n if (part.type === 'tool-call' && this.exclude.includes(part.toolName)) {\n excludedToolCallIds.add(part.toolCallId);\n shouldExclude = true;\n }\n }\n\n return !shouldExclude;\n }\n\n // For tool messages, filter out results for excluded tool calls\n if (message.role === 'tool') {\n const shouldExclude = message.content.some(\n part => part.type === 'tool-result' && excludedToolCallIds.has(part.toolCallId),\n );\n\n return !shouldExclude;\n }\n\n return true;\n });\n }\n\n // Case 3: Empty exclude array, return original messages\n return messages;\n }\n}\n"]}
@@ -1,3 +0,0 @@
1
- export * from './token-limiter.js';
2
- export * from './tool-call-filter.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/processors/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}