@mastra/server 1.23.1-alpha.0 → 1.24.0
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 +48 -0
- package/dist/{chunk-UHWF2UKO.cjs → chunk-73MTRRUV.cjs} +652 -468
- package/dist/chunk-73MTRRUV.cjs.map +1 -0
- package/dist/{chunk-IGUQV25I.js → chunk-7K4TRBNS.js} +10 -4
- package/dist/chunk-7K4TRBNS.js.map +1 -0
- package/dist/{chunk-4HMKXB3Q.js → chunk-7X3JCQ5P.js} +5 -5
- package/dist/{chunk-4HMKXB3Q.js.map → chunk-7X3JCQ5P.js.map} +1 -1
- package/dist/{chunk-NNXDDV3V.cjs → chunk-J5Q6M3YG.cjs} +20 -20
- package/dist/{chunk-NNXDDV3V.cjs.map → chunk-J5Q6M3YG.cjs.map} +1 -1
- package/dist/{chunk-KU4DBPKJ.cjs → chunk-JYST3GVF.cjs} +10 -4
- package/dist/chunk-JYST3GVF.cjs.map +1 -0
- package/dist/{chunk-MO3ZKWYY.js → chunk-LY7C6PVI.js} +654 -470
- package/dist/chunk-LY7C6PVI.js.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/{observational-memory-OVRHDQRG-OCHV6RZ7.cjs → observational-memory-MBL257AG-G63WEV2Z.cjs} +26 -26
- package/dist/{observational-memory-OVRHDQRG-OCHV6RZ7.cjs.map → observational-memory-MBL257AG-G63WEV2Z.cjs.map} +1 -1
- package/dist/{observational-memory-OVRHDQRG-RC3PRA65.js → observational-memory-MBL257AG-K6HOZK3U.js} +3 -3
- package/dist/{observational-memory-OVRHDQRG-RC3PRA65.js.map → observational-memory-MBL257AG-K6HOZK3U.js.map} +1 -1
- package/dist/server/handlers/agent-builder.cjs +16 -16
- package/dist/server/handlers/agent-builder.js +1 -1
- package/dist/server/handlers/agent-versions.cjs +8 -8
- package/dist/server/handlers/agent-versions.d.ts.map +1 -1
- package/dist/server/handlers/agent-versions.js +1 -1
- package/dist/server/handlers.cjs +2 -2
- package/dist/server/handlers.js +1 -1
- package/dist/server/server-adapter/index.cjs +24 -24
- package/dist/server/server-adapter/index.js +2 -2
- package/package.json +8 -8
- package/dist/chunk-IGUQV25I.js.map +0 -1
- package/dist/chunk-KU4DBPKJ.cjs.map +0 -1
- package/dist/chunk-MO3ZKWYY.js.map +0 -1
- package/dist/chunk-UHWF2UKO.cjs.map +0 -1
|
@@ -10,8 +10,8 @@ var path = require('path');
|
|
|
10
10
|
var crypto$1 = require('crypto');
|
|
11
11
|
var agent = require('@mastra/core/agent');
|
|
12
12
|
var observability = require('@mastra/core/observability');
|
|
13
|
-
var async_hooks = require('async_hooks');
|
|
14
13
|
var util = require('util');
|
|
14
|
+
var async_hooks = require('async_hooks');
|
|
15
15
|
|
|
16
16
|
// ../../node_modules/.pnpm/xxhash-wasm@1.1.0/node_modules/xxhash-wasm/esm/xxhash-wasm.js
|
|
17
17
|
var t = new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 48, 8, 96, 3, 127, 127, 127, 1, 127, 96, 3, 127, 127, 127, 0, 96, 2, 127, 127, 0, 96, 1, 127, 1, 127, 96, 3, 127, 127, 126, 1, 126, 96, 3, 126, 127, 127, 1, 126, 96, 2, 127, 126, 0, 96, 1, 127, 1, 126, 3, 11, 10, 0, 0, 2, 1, 3, 4, 5, 6, 1, 7, 5, 3, 1, 0, 1, 7, 85, 9, 3, 109, 101, 109, 2, 0, 5, 120, 120, 104, 51, 50, 0, 0, 6, 105, 110, 105, 116, 51, 50, 0, 2, 8, 117, 112, 100, 97, 116, 101, 51, 50, 0, 3, 8, 100, 105, 103, 101, 115, 116, 51, 50, 0, 4, 5, 120, 120, 104, 54, 52, 0, 5, 6, 105, 110, 105, 116, 54, 52, 0, 7, 8, 117, 112, 100, 97, 116, 101, 54, 52, 0, 8, 8, 100, 105, 103, 101, 115, 116, 54, 52, 0, 9, 10, 251, 22, 10, 242, 1, 1, 4, 127, 32, 0, 32, 1, 106, 33, 3, 32, 1, 65, 16, 79, 4, 127, 32, 3, 65, 16, 107, 33, 6, 32, 2, 65, 168, 136, 141, 161, 2, 106, 33, 3, 32, 2, 65, 137, 235, 208, 208, 7, 107, 33, 4, 32, 2, 65, 207, 140, 162, 142, 6, 106, 33, 5, 3, 64, 32, 3, 32, 0, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 33, 3, 32, 4, 32, 0, 65, 4, 106, 34, 0, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 33, 4, 32, 2, 32, 0, 65, 4, 106, 34, 0, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 33, 2, 32, 5, 32, 0, 65, 4, 106, 34, 0, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 33, 5, 32, 6, 32, 0, 65, 4, 106, 34, 0, 79, 13, 0, 11, 32, 2, 65, 12, 119, 32, 5, 65, 18, 119, 106, 32, 4, 65, 7, 119, 106, 32, 3, 65, 1, 119, 106, 5, 32, 2, 65, 177, 207, 217, 178, 1, 106, 11, 32, 1, 106, 32, 0, 32, 1, 65, 15, 113, 16, 1, 11, 146, 1, 0, 32, 1, 32, 2, 106, 33, 2, 3, 64, 32, 1, 65, 4, 106, 32, 2, 75, 69, 4, 64, 32, 0, 32, 1, 40, 2, 0, 65, 189, 220, 202, 149, 124, 108, 106, 65, 17, 119, 65, 175, 214, 211, 190, 2, 108, 33, 0, 32, 1, 65, 4, 106, 33, 1, 12, 1, 11, 11, 3, 64, 32, 1, 32, 2, 79, 69, 4, 64, 32, 0, 32, 1, 45, 0, 0, 65, 177, 207, 217, 178, 1, 108, 106, 65, 11, 119, 65, 177, 243, 221, 241, 121, 108, 33, 0, 32, 1, 65, 1, 106, 33, 1, 12, 1, 11, 11, 32, 0, 32, 0, 65, 15, 118, 115, 65, 247, 148, 175, 175, 120, 108, 34, 0, 65, 13, 118, 32, 0, 115, 65, 189, 220, 202, 149, 124, 108, 34, 0, 65, 16, 118, 32, 0, 115, 11, 63, 0, 32, 0, 65, 8, 106, 32, 1, 65, 168, 136, 141, 161, 2, 106, 54, 2, 0, 32, 0, 65, 12, 106, 32, 1, 65, 137, 235, 208, 208, 7, 107, 54, 2, 0, 32, 0, 65, 16, 106, 32, 1, 54, 2, 0, 32, 0, 65, 20, 106, 32, 1, 65, 207, 140, 162, 142, 6, 106, 54, 2, 0, 11, 195, 4, 1, 6, 127, 32, 1, 32, 2, 106, 33, 6, 32, 0, 65, 24, 106, 33, 4, 32, 0, 65, 40, 106, 40, 2, 0, 33, 3, 32, 0, 32, 0, 40, 2, 0, 32, 2, 106, 54, 2, 0, 32, 0, 65, 4, 106, 34, 5, 32, 5, 40, 2, 0, 32, 2, 65, 16, 79, 32, 0, 40, 2, 0, 65, 16, 79, 114, 114, 54, 2, 0, 32, 2, 32, 3, 106, 65, 16, 73, 4, 64, 32, 3, 32, 4, 106, 32, 1, 32, 2, 252, 10, 0, 0, 32, 0, 65, 40, 106, 32, 2, 32, 3, 106, 54, 2, 0, 15, 11, 32, 3, 4, 64, 32, 3, 32, 4, 106, 32, 1, 65, 16, 32, 3, 107, 34, 2, 252, 10, 0, 0, 32, 0, 65, 8, 106, 34, 3, 32, 3, 40, 2, 0, 32, 4, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 54, 2, 0, 32, 0, 65, 12, 106, 34, 3, 32, 3, 40, 2, 0, 32, 4, 65, 4, 106, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 54, 2, 0, 32, 0, 65, 16, 106, 34, 3, 32, 3, 40, 2, 0, 32, 4, 65, 8, 106, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 54, 2, 0, 32, 0, 65, 20, 106, 34, 3, 32, 3, 40, 2, 0, 32, 4, 65, 12, 106, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 54, 2, 0, 32, 0, 65, 40, 106, 65, 0, 54, 2, 0, 32, 1, 32, 2, 106, 33, 1, 11, 32, 1, 32, 6, 65, 16, 107, 77, 4, 64, 32, 6, 65, 16, 107, 33, 8, 32, 0, 65, 8, 106, 40, 2, 0, 33, 2, 32, 0, 65, 12, 106, 40, 2, 0, 33, 3, 32, 0, 65, 16, 106, 40, 2, 0, 33, 5, 32, 0, 65, 20, 106, 40, 2, 0, 33, 7, 3, 64, 32, 2, 32, 1, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 33, 2, 32, 3, 32, 1, 65, 4, 106, 34, 1, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 33, 3, 32, 5, 32, 1, 65, 4, 106, 34, 1, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 33, 5, 32, 7, 32, 1, 65, 4, 106, 34, 1, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 33, 7, 32, 8, 32, 1, 65, 4, 106, 34, 1, 79, 13, 0, 11, 32, 0, 65, 8, 106, 32, 2, 54, 2, 0, 32, 0, 65, 12, 106, 32, 3, 54, 2, 0, 32, 0, 65, 16, 106, 32, 5, 54, 2, 0, 32, 0, 65, 20, 106, 32, 7, 54, 2, 0, 11, 32, 1, 32, 6, 73, 4, 64, 32, 4, 32, 1, 32, 6, 32, 1, 107, 34, 1, 252, 10, 0, 0, 32, 0, 65, 40, 106, 32, 1, 54, 2, 0, 11, 11, 97, 1, 1, 127, 32, 0, 65, 16, 106, 40, 2, 0, 33, 1, 32, 0, 65, 4, 106, 40, 2, 0, 4, 127, 32, 1, 65, 12, 119, 32, 0, 65, 20, 106, 40, 2, 0, 65, 18, 119, 106, 32, 0, 65, 12, 106, 40, 2, 0, 65, 7, 119, 106, 32, 0, 65, 8, 106, 40, 2, 0, 65, 1, 119, 106, 5, 32, 1, 65, 177, 207, 217, 178, 1, 106, 11, 32, 0, 40, 2, 0, 106, 32, 0, 65, 24, 106, 32, 0, 65, 40, 106, 40, 2, 0, 16, 1, 11, 255, 3, 2, 3, 126, 1, 127, 32, 0, 32, 1, 106, 33, 6, 32, 1, 65, 32, 79, 4, 126, 32, 6, 65, 32, 107, 33, 6, 32, 2, 66, 214, 235, 130, 238, 234, 253, 137, 245, 224, 0, 124, 33, 3, 32, 2, 66, 177, 169, 172, 193, 173, 184, 212, 166, 61, 125, 33, 4, 32, 2, 66, 249, 234, 208, 208, 231, 201, 161, 228, 225, 0, 124, 33, 5, 3, 64, 32, 3, 32, 0, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 33, 3, 32, 4, 32, 0, 65, 8, 106, 34, 0, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 33, 4, 32, 2, 32, 0, 65, 8, 106, 34, 0, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 33, 2, 32, 5, 32, 0, 65, 8, 106, 34, 0, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 33, 5, 32, 6, 32, 0, 65, 8, 106, 34, 0, 79, 13, 0, 11, 32, 2, 66, 12, 137, 32, 5, 66, 18, 137, 124, 32, 4, 66, 7, 137, 124, 32, 3, 66, 1, 137, 124, 32, 3, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 133, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 66, 157, 163, 181, 234, 131, 177, 141, 138, 250, 0, 125, 32, 4, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 133, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 66, 157, 163, 181, 234, 131, 177, 141, 138, 250, 0, 125, 32, 2, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 133, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 66, 157, 163, 181, 234, 131, 177, 141, 138, 250, 0, 125, 32, 5, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 133, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 66, 157, 163, 181, 234, 131, 177, 141, 138, 250, 0, 125, 5, 32, 2, 66, 197, 207, 217, 178, 241, 229, 186, 234, 39, 124, 11, 32, 1, 173, 124, 32, 0, 32, 1, 65, 31, 113, 16, 6, 11, 134, 2, 0, 32, 1, 32, 2, 106, 33, 2, 3, 64, 32, 2, 32, 1, 65, 8, 106, 79, 4, 64, 32, 1, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 32, 0, 133, 66, 27, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 66, 157, 163, 181, 234, 131, 177, 141, 138, 250, 0, 125, 33, 0, 32, 1, 65, 8, 106, 33, 1, 12, 1, 11, 11, 32, 1, 65, 4, 106, 32, 2, 77, 4, 64, 32, 0, 32, 1, 53, 2, 0, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 133, 66, 23, 137, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 249, 243, 221, 241, 153, 246, 153, 171, 22, 124, 33, 0, 32, 1, 65, 4, 106, 33, 1, 11, 3, 64, 32, 1, 32, 2, 73, 4, 64, 32, 0, 32, 1, 49, 0, 0, 66, 197, 207, 217, 178, 241, 229, 186, 234, 39, 126, 133, 66, 11, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 33, 0, 32, 1, 65, 1, 106, 33, 1, 12, 1, 11, 11, 32, 0, 32, 0, 66, 33, 136, 133, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 34, 0, 32, 0, 66, 29, 136, 133, 66, 249, 243, 221, 241, 153, 246, 153, 171, 22, 126, 34, 0, 32, 0, 66, 32, 136, 133, 11, 77, 0, 32, 0, 65, 8, 106, 32, 1, 66, 214, 235, 130, 238, 234, 253, 137, 245, 224, 0, 124, 55, 3, 0, 32, 0, 65, 16, 106, 32, 1, 66, 177, 169, 172, 193, 173, 184, 212, 166, 61, 125, 55, 3, 0, 32, 0, 65, 24, 106, 32, 1, 55, 3, 0, 32, 0, 65, 32, 106, 32, 1, 66, 249, 234, 208, 208, 231, 201, 161, 228, 225, 0, 124, 55, 3, 0, 11, 244, 4, 2, 3, 127, 4, 126, 32, 1, 32, 2, 106, 33, 5, 32, 0, 65, 40, 106, 33, 4, 32, 0, 65, 200, 0, 106, 40, 2, 0, 33, 3, 32, 0, 32, 0, 41, 3, 0, 32, 2, 173, 124, 55, 3, 0, 32, 2, 32, 3, 106, 65, 32, 73, 4, 64, 32, 3, 32, 4, 106, 32, 1, 32, 2, 252, 10, 0, 0, 32, 0, 65, 200, 0, 106, 32, 2, 32, 3, 106, 54, 2, 0, 15, 11, 32, 3, 4, 64, 32, 3, 32, 4, 106, 32, 1, 65, 32, 32, 3, 107, 34, 2, 252, 10, 0, 0, 32, 0, 65, 8, 106, 34, 3, 32, 3, 41, 3, 0, 32, 4, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 55, 3, 0, 32, 0, 65, 16, 106, 34, 3, 32, 3, 41, 3, 0, 32, 4, 65, 8, 106, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 55, 3, 0, 32, 0, 65, 24, 106, 34, 3, 32, 3, 41, 3, 0, 32, 4, 65, 16, 106, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 55, 3, 0, 32, 0, 65, 32, 106, 34, 3, 32, 3, 41, 3, 0, 32, 4, 65, 24, 106, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 55, 3, 0, 32, 0, 65, 200, 0, 106, 65, 0, 54, 2, 0, 32, 1, 32, 2, 106, 33, 1, 11, 32, 1, 65, 32, 106, 32, 5, 77, 4, 64, 32, 5, 65, 32, 107, 33, 2, 32, 0, 65, 8, 106, 41, 3, 0, 33, 6, 32, 0, 65, 16, 106, 41, 3, 0, 33, 7, 32, 0, 65, 24, 106, 41, 3, 0, 33, 8, 32, 0, 65, 32, 106, 41, 3, 0, 33, 9, 3, 64, 32, 6, 32, 1, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 33, 6, 32, 7, 32, 1, 65, 8, 106, 34, 1, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 33, 7, 32, 8, 32, 1, 65, 8, 106, 34, 1, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 33, 8, 32, 9, 32, 1, 65, 8, 106, 34, 1, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 33, 9, 32, 2, 32, 1, 65, 8, 106, 34, 1, 79, 13, 0, 11, 32, 0, 65, 8, 106, 32, 6, 55, 3, 0, 32, 0, 65, 16, 106, 32, 7, 55, 3, 0, 32, 0, 65, 24, 106, 32, 8, 55, 3, 0, 32, 0, 65, 32, 106, 32, 9, 55, 3, 0, 11, 32, 1, 32, 5, 73, 4, 64, 32, 4, 32, 1, 32, 5, 32, 1, 107, 34, 1, 252, 10, 0, 0, 32, 0, 65, 200, 0, 106, 32, 1, 54, 2, 0, 11, 11, 188, 2, 1, 5, 126, 32, 0, 65, 24, 106, 41, 3, 0, 33, 1, 32, 0, 41, 3, 0, 34, 2, 66, 32, 90, 4, 126, 32, 0, 65, 8, 106, 41, 3, 0, 34, 3, 66, 1, 137, 32, 0, 65, 16, 106, 41, 3, 0, 34, 4, 66, 7, 137, 124, 32, 1, 66, 12, 137, 32, 0, 65, 32, 106, 41, 3, 0, 34, 5, 66, 18, 137, 124, 124, 32, 3, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 133, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 66, 157, 163, 181, 234, 131, 177, 141, 138, 250, 0, 125, 32, 4, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 133, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 66, 157, 163, 181, 234, 131, 177, 141, 138, 250, 0, 125, 32, 1, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 133, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 66, 157, 163, 181, 234, 131, 177, 141, 138, 250, 0, 125, 32, 5, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 133, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 66, 157, 163, 181, 234, 131, 177, 141, 138, 250, 0, 125, 5, 32, 1, 66, 197, 207, 217, 178, 241, 229, 186, 234, 39, 124, 11, 32, 2, 124, 32, 0, 65, 40, 106, 32, 2, 66, 31, 131, 167, 16, 6, 11]);
|
|
@@ -1041,6 +1041,8 @@ function imageSize(input) {
|
|
|
1041
1041
|
}
|
|
1042
1042
|
throw new TypeError(`unsupported file type: ${type}`);
|
|
1043
1043
|
}
|
|
1044
|
+
|
|
1045
|
+
// ../memory/dist/chunk-42AZEBIK.js
|
|
1044
1046
|
var OM_DEBUG_LOG = process.env.OM_DEBUG ? path.join(process.cwd(), "om-debug.log") : null;
|
|
1045
1047
|
function omDebug(msg) {
|
|
1046
1048
|
if (!OM_DEBUG_LOG) return;
|
|
@@ -3925,11 +3927,13 @@ var OBSERVER_IMAGE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
3925
3927
|
"heif",
|
|
3926
3928
|
"avif"
|
|
3927
3929
|
]);
|
|
3928
|
-
function
|
|
3929
|
-
return createdAt ?
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3930
|
+
function formatObserverDate(createdAt) {
|
|
3931
|
+
return createdAt ? `${createdAt.toLocaleDateString("en-US", {
|
|
3932
|
+
month: "short"
|
|
3933
|
+
})} ${createdAt.getDate()} ${createdAt.getFullYear()}` : "";
|
|
3934
|
+
}
|
|
3935
|
+
function formatObserverTime(createdAt) {
|
|
3936
|
+
return createdAt ? createdAt.toLocaleTimeString("en-US", {
|
|
3933
3937
|
hour: "numeric",
|
|
3934
3938
|
minute: "2-digit",
|
|
3935
3939
|
hour12: true
|
|
@@ -4020,19 +4024,72 @@ function formatObserverAttachmentPlaceholder(part, counter) {
|
|
|
4020
4024
|
const label = resolveObserverAttachmentLabel(part);
|
|
4021
4025
|
return label ? `[${attachmentType} #${attachmentId}: ${label}]` : `[${attachmentType} #${attachmentId}]`;
|
|
4022
4026
|
}
|
|
4027
|
+
function formatObserverPartLine(title, body, time, previousTime) {
|
|
4028
|
+
const timeLabel = time && time !== previousTime ? ` (${time})` : "";
|
|
4029
|
+
return `${title}${timeLabel}: ${body}`;
|
|
4030
|
+
}
|
|
4031
|
+
function normalizeObserverCreatedAt(createdAt) {
|
|
4032
|
+
if (createdAt instanceof Date) {
|
|
4033
|
+
if (Number.isNaN(createdAt.getTime())) {
|
|
4034
|
+
return void 0;
|
|
4035
|
+
}
|
|
4036
|
+
return createdAt;
|
|
4037
|
+
}
|
|
4038
|
+
if (typeof createdAt === "number" || typeof createdAt === "string") {
|
|
4039
|
+
const date = new Date(createdAt);
|
|
4040
|
+
if (Number.isNaN(date.getTime())) {
|
|
4041
|
+
return void 0;
|
|
4042
|
+
}
|
|
4043
|
+
return date;
|
|
4044
|
+
}
|
|
4045
|
+
return void 0;
|
|
4046
|
+
}
|
|
4047
|
+
function formatObserverLines(lines, context = {}) {
|
|
4048
|
+
const output = [];
|
|
4049
|
+
let previousDate = context.previousDate;
|
|
4050
|
+
let previousTime = context.previousTime;
|
|
4051
|
+
for (const line of lines) {
|
|
4052
|
+
if (line.date && line.date !== previousDate) {
|
|
4053
|
+
output.push(`${line.date}:`);
|
|
4054
|
+
previousDate = line.date;
|
|
4055
|
+
previousTime = void 0;
|
|
4056
|
+
}
|
|
4057
|
+
output.push(formatObserverPartLine(line.title, line.body, line.time, previousTime));
|
|
4058
|
+
previousTime = line.time || previousTime;
|
|
4059
|
+
}
|
|
4060
|
+
return {
|
|
4061
|
+
text: output.join("\n"),
|
|
4062
|
+
context: { previousDate, previousTime }
|
|
4063
|
+
};
|
|
4064
|
+
}
|
|
4023
4065
|
function formatObserverMessage(msg, counter, options) {
|
|
4024
4066
|
const maxLen = options?.maxPartLength;
|
|
4025
4067
|
const maxToolResultTokens = options?.maxToolResultTokens ?? DEFAULT_OBSERVER_TOOL_RESULT_MAX_TOKENS;
|
|
4026
|
-
const timestamp = formatObserverTimestamp(msg.createdAt);
|
|
4027
4068
|
const role = msg.role.charAt(0).toUpperCase() + msg.role.slice(1);
|
|
4028
|
-
const timestampStr = timestamp ? ` (${timestamp})` : "";
|
|
4029
4069
|
const attachments = [];
|
|
4030
|
-
|
|
4070
|
+
const messageCreatedAt = normalizeObserverCreatedAt(msg.createdAt);
|
|
4071
|
+
let lines = [];
|
|
4072
|
+
const pushLine = (title, body, createdAt) => {
|
|
4073
|
+
if (!body) {
|
|
4074
|
+
return;
|
|
4075
|
+
}
|
|
4076
|
+
const normalizedCreatedAt = normalizeObserverCreatedAt(createdAt) ?? messageCreatedAt;
|
|
4077
|
+
lines.push({
|
|
4078
|
+
date: formatObserverDate(normalizedCreatedAt),
|
|
4079
|
+
time: formatObserverTime(normalizedCreatedAt),
|
|
4080
|
+
title,
|
|
4081
|
+
body
|
|
4082
|
+
});
|
|
4083
|
+
};
|
|
4031
4084
|
if (typeof msg.content === "string") {
|
|
4032
|
-
|
|
4085
|
+
pushLine(role, maybeTruncate(msg.content, maxLen), messageCreatedAt);
|
|
4033
4086
|
} else if (msg.content?.parts && Array.isArray(msg.content.parts) && msg.content.parts.length > 0) {
|
|
4034
|
-
|
|
4035
|
-
|
|
4087
|
+
msg.content.parts.forEach((part) => {
|
|
4088
|
+
const partCreatedAt = normalizeObserverCreatedAt(part.createdAt) ?? messageCreatedAt;
|
|
4089
|
+
if (part.type === "text") {
|
|
4090
|
+
pushLine(role, maybeTruncate(part.text, maxLen), partCreatedAt);
|
|
4091
|
+
return;
|
|
4092
|
+
}
|
|
4036
4093
|
if (part.type === "tool-invocation") {
|
|
4037
4094
|
const inv = part.toolInvocation;
|
|
4038
4095
|
if (inv.state === "result") {
|
|
@@ -4040,19 +4097,24 @@ function formatObserverMessage(msg, counter, options) {
|
|
|
4040
4097
|
part,
|
|
4041
4098
|
inv.result
|
|
4042
4099
|
);
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4100
|
+
pushLine(
|
|
4101
|
+
`Tool Result ${inv.toolName}`,
|
|
4102
|
+
maybeTruncate(formatToolResultForObserver(resultForObserver, { maxTokens: maxToolResultTokens }), maxLen),
|
|
4103
|
+
partCreatedAt
|
|
4104
|
+
);
|
|
4105
|
+
return;
|
|
4046
4106
|
}
|
|
4047
|
-
|
|
4048
|
-
return
|
|
4049
|
-
${maybeTruncate(argsStr, maxLen)}`;
|
|
4107
|
+
pushLine(`Tool Call ${inv.toolName}`, maybeTruncate(JSON.stringify(inv.args, null, 2), maxLen), partCreatedAt);
|
|
4108
|
+
return;
|
|
4050
4109
|
}
|
|
4051
4110
|
const partType = part.type;
|
|
4052
4111
|
if (partType === "reasoning") {
|
|
4053
4112
|
const reasoning = part.reasoning;
|
|
4054
|
-
if (reasoning)
|
|
4055
|
-
|
|
4113
|
+
if (!reasoning) {
|
|
4114
|
+
return;
|
|
4115
|
+
}
|
|
4116
|
+
pushLine("Reasoning", maybeTruncate(reasoning, maxLen), partCreatedAt);
|
|
4117
|
+
return;
|
|
4056
4118
|
}
|
|
4057
4119
|
if (partType === "image" || partType === "file") {
|
|
4058
4120
|
const attachment = part;
|
|
@@ -4060,40 +4122,58 @@ ${maybeTruncate(argsStr, maxLen)}`;
|
|
|
4060
4122
|
if (inputAttachment) {
|
|
4061
4123
|
attachments.push(inputAttachment);
|
|
4062
4124
|
}
|
|
4063
|
-
|
|
4125
|
+
pushLine(
|
|
4126
|
+
partType === "image" ? "Image" : "File",
|
|
4127
|
+
formatObserverAttachmentPlaceholder(attachment, counter),
|
|
4128
|
+
partCreatedAt
|
|
4129
|
+
);
|
|
4064
4130
|
}
|
|
4065
|
-
|
|
4066
|
-
return "";
|
|
4067
|
-
}).filter(Boolean).join("\n");
|
|
4131
|
+
});
|
|
4068
4132
|
} else if (msg.content?.content) {
|
|
4069
|
-
|
|
4133
|
+
pushLine(role, maybeTruncate(msg.content.content, maxLen), messageCreatedAt);
|
|
4070
4134
|
}
|
|
4071
|
-
if (
|
|
4072
|
-
return {
|
|
4135
|
+
if (lines.length === 0 && attachments.length === 0) {
|
|
4136
|
+
return { lines: [], attachments };
|
|
4073
4137
|
}
|
|
4074
4138
|
return {
|
|
4075
|
-
|
|
4076
|
-
${content}`,
|
|
4139
|
+
lines,
|
|
4077
4140
|
attachments
|
|
4078
4141
|
};
|
|
4079
4142
|
}
|
|
4080
4143
|
function formatMessagesForObserver(messages, options) {
|
|
4081
4144
|
const counter = { nextImageId: 1, nextFileId: 1 };
|
|
4082
|
-
|
|
4145
|
+
const sections = [];
|
|
4146
|
+
let context = {};
|
|
4147
|
+
for (const message of messages) {
|
|
4148
|
+
const formatted = formatObserverMessage(message, counter, options);
|
|
4149
|
+
if (formatted.lines.length === 0) {
|
|
4150
|
+
continue;
|
|
4151
|
+
}
|
|
4152
|
+
const rendered = formatObserverLines(formatted.lines, context);
|
|
4153
|
+
if (!rendered.text) {
|
|
4154
|
+
continue;
|
|
4155
|
+
}
|
|
4156
|
+
sections.push(rendered.text);
|
|
4157
|
+
context = rendered.context;
|
|
4158
|
+
}
|
|
4159
|
+
return sections.join("\n");
|
|
4160
|
+
}
|
|
4161
|
+
function appendFormattedObserverMessage(content, formatted, context) {
|
|
4162
|
+
const rendered = formatObserverLines(formatted.lines, context);
|
|
4163
|
+
if (rendered.text) {
|
|
4164
|
+
content.push({ type: "text", text: rendered.text });
|
|
4165
|
+
}
|
|
4166
|
+
content.push(...formatted.attachments);
|
|
4167
|
+
return rendered.context;
|
|
4083
4168
|
}
|
|
4084
4169
|
function buildObserverHistoryMessage(messages, options) {
|
|
4085
4170
|
const counter = { nextImageId: 1, nextFileId: 1 };
|
|
4086
4171
|
const content = [{ type: "text", text: "## New Message History to Observe\n\n" }];
|
|
4087
|
-
let
|
|
4172
|
+
let context = {};
|
|
4088
4173
|
messages.forEach((message) => {
|
|
4089
4174
|
const formatted = formatObserverMessage(message, counter, options);
|
|
4090
|
-
if (
|
|
4091
|
-
|
|
4092
|
-
content.push({ type: "text", text: "\n\n---\n\n" });
|
|
4093
|
-
}
|
|
4094
|
-
content.push({ type: "text", text: formatted.text });
|
|
4095
|
-
content.push(...formatted.attachments);
|
|
4096
|
-
visibleCount++;
|
|
4175
|
+
if (formatted.lines.length === 0 && formatted.attachments.length === 0) return;
|
|
4176
|
+
context = appendFormattedObserverMessage(content, formatted, context);
|
|
4097
4177
|
});
|
|
4098
4178
|
return {
|
|
4099
4179
|
role: "user",
|
|
@@ -4123,18 +4203,15 @@ The following messages are from ${threadOrder.length} different conversation thr
|
|
|
4123
4203
|
const messages = messagesByThread.get(threadId);
|
|
4124
4204
|
if (!messages || messages.length === 0) return;
|
|
4125
4205
|
const threadContent = [];
|
|
4126
|
-
let
|
|
4206
|
+
let context = {};
|
|
4207
|
+
let hasVisibleContent = false;
|
|
4127
4208
|
messages.forEach((message) => {
|
|
4128
4209
|
const formatted = formatObserverMessage(message, counter, options);
|
|
4129
|
-
if (
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
}
|
|
4133
|
-
threadContent.push({ type: "text", text: formatted.text });
|
|
4134
|
-
threadContent.push(...formatted.attachments);
|
|
4135
|
-
visibleCount++;
|
|
4210
|
+
if (formatted.lines.length === 0 && formatted.attachments.length === 0) return;
|
|
4211
|
+
context = appendFormattedObserverMessage(threadContent, formatted, context);
|
|
4212
|
+
hasVisibleContent = true;
|
|
4136
4213
|
});
|
|
4137
|
-
if (
|
|
4214
|
+
if (!hasVisibleContent) return;
|
|
4138
4215
|
content.push({ type: "text", text: `<thread id="${threadId}">
|
|
4139
4216
|
` });
|
|
4140
4217
|
content.push(...threadContent);
|
|
@@ -5046,13 +5123,29 @@ var ReflectorRunner = class {
|
|
|
5046
5123
|
model
|
|
5047
5124
|
});
|
|
5048
5125
|
}
|
|
5049
|
-
getObservationMarkerConfig() {
|
|
5126
|
+
getObservationMarkerConfig(record) {
|
|
5050
5127
|
return {
|
|
5051
5128
|
messageTokens: getMaxThreshold(this.observationConfig.messageTokens),
|
|
5052
|
-
observationTokens: getMaxThreshold(
|
|
5129
|
+
observationTokens: getMaxThreshold(
|
|
5130
|
+
record ? this.getEffectiveReflectionTokens(record) : this.reflectionConfig.observationTokens
|
|
5131
|
+
),
|
|
5053
5132
|
scope: this.scope
|
|
5054
5133
|
};
|
|
5055
5134
|
}
|
|
5135
|
+
/**
|
|
5136
|
+
* Resolve the effective reflection observationTokens for a record.
|
|
5137
|
+
* Only explicit per-record overrides (stored under `_overrides`) win;
|
|
5138
|
+
* the initial config snapshot is ignored so instance-level changes
|
|
5139
|
+
* still take effect for existing records.
|
|
5140
|
+
*/
|
|
5141
|
+
getEffectiveReflectionTokens(record) {
|
|
5142
|
+
const overrides = record.config?._overrides;
|
|
5143
|
+
const recordTokens = overrides?.reflection?.observationTokens;
|
|
5144
|
+
if (recordTokens) {
|
|
5145
|
+
return recordTokens;
|
|
5146
|
+
}
|
|
5147
|
+
return this.reflectionConfig.observationTokens;
|
|
5148
|
+
}
|
|
5056
5149
|
/**
|
|
5057
5150
|
* Call the Reflector agent with escalating compression levels.
|
|
5058
5151
|
*/
|
|
@@ -5241,7 +5334,7 @@ var ReflectorRunner = class {
|
|
|
5241
5334
|
const freshRecord = await this.storage.getObservationalMemory(record.threadId, record.resourceId);
|
|
5242
5335
|
const currentRecord = freshRecord ?? record;
|
|
5243
5336
|
const observationTokens = currentRecord.observationTokenCount ?? 0;
|
|
5244
|
-
const reflectThreshold = getMaxThreshold(this.
|
|
5337
|
+
const reflectThreshold = getMaxThreshold(this.getEffectiveReflectionTokens(currentRecord));
|
|
5245
5338
|
const bufferActivation = this.reflectionConfig.bufferActivation ?? 0.5;
|
|
5246
5339
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
5247
5340
|
const cycleId = `reflect-buf-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
@@ -5270,7 +5363,7 @@ var ReflectorRunner = class {
|
|
|
5270
5363
|
recordId: record.id,
|
|
5271
5364
|
threadId: record.threadId ?? "",
|
|
5272
5365
|
threadIds: record.threadId ? [record.threadId] : [],
|
|
5273
|
-
config: this.getObservationMarkerConfig()
|
|
5366
|
+
config: this.getObservationMarkerConfig(currentRecord)
|
|
5274
5367
|
});
|
|
5275
5368
|
void writer.custom(startMarker).catch(() => {
|
|
5276
5369
|
});
|
|
@@ -5382,7 +5475,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5382
5475
|
threadId: freshRecord.threadId ?? "",
|
|
5383
5476
|
generationCount: afterRecord?.generationCount ?? freshRecord.generationCount ?? 0,
|
|
5384
5477
|
observations: afterRecord?.activeObservations,
|
|
5385
|
-
config: this.getObservationMarkerConfig()
|
|
5478
|
+
config: this.getObservationMarkerConfig(freshRecord)
|
|
5386
5479
|
});
|
|
5387
5480
|
void writer.custom(activationMarker).catch(() => {
|
|
5388
5481
|
});
|
|
@@ -5413,7 +5506,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5413
5506
|
observabilityContext
|
|
5414
5507
|
} = opts;
|
|
5415
5508
|
const lockKey = this.buffering.getLockKey(record.threadId, record.resourceId);
|
|
5416
|
-
const reflectThreshold = getMaxThreshold(this.
|
|
5509
|
+
const reflectThreshold = getMaxThreshold(this.getEffectiveReflectionTokens(record));
|
|
5417
5510
|
if (this.buffering.isAsyncReflectionEnabled() && observationTokens < reflectThreshold) {
|
|
5418
5511
|
const shouldTrigger = (() => {
|
|
5419
5512
|
if (!this.buffering.isAsyncReflectionEnabled()) return false;
|
|
@@ -5492,7 +5585,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5492
5585
|
recordId: record.id,
|
|
5493
5586
|
threadId,
|
|
5494
5587
|
threadIds: [threadId],
|
|
5495
|
-
config: this.getObservationMarkerConfig()
|
|
5588
|
+
config: this.getObservationMarkerConfig(record)
|
|
5496
5589
|
});
|
|
5497
5590
|
await writer.custom(startMarker).catch(() => {
|
|
5498
5591
|
});
|
|
@@ -5584,171 +5677,493 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5584
5677
|
}
|
|
5585
5678
|
}
|
|
5586
5679
|
};
|
|
5587
|
-
|
|
5588
|
-
"
|
|
5589
|
-
"jpg",
|
|
5590
|
-
"jpeg",
|
|
5591
|
-
"webp",
|
|
5592
|
-
"gif",
|
|
5593
|
-
"bmp",
|
|
5594
|
-
"tiff",
|
|
5595
|
-
"tif",
|
|
5596
|
-
"heic",
|
|
5597
|
-
"heif",
|
|
5598
|
-
"avif"
|
|
5599
|
-
]);
|
|
5600
|
-
var TOKEN_ESTIMATE_CACHE_VERSION = 6;
|
|
5601
|
-
var DEFAULT_IMAGE_ESTIMATOR = {
|
|
5602
|
-
baseTokens: 85,
|
|
5603
|
-
tileTokens: 170,
|
|
5604
|
-
fallbackTiles: 4
|
|
5605
|
-
};
|
|
5606
|
-
var GOOGLE_LEGACY_IMAGE_TOKENS_PER_TILE = 258;
|
|
5607
|
-
var GOOGLE_GEMINI_3_IMAGE_TOKENS_BY_RESOLUTION = {
|
|
5608
|
-
low: 280,
|
|
5609
|
-
medium: 560,
|
|
5610
|
-
high: 1120,
|
|
5611
|
-
ultra_high: 2240,
|
|
5612
|
-
unspecified: 1120
|
|
5613
|
-
};
|
|
5614
|
-
var ANTHROPIC_IMAGE_TOKENS_PER_PIXEL = 1 / 750;
|
|
5615
|
-
var ANTHROPIC_IMAGE_MAX_LONG_EDGE = 1568;
|
|
5616
|
-
var GOOGLE_MEDIA_RESOLUTION_VALUES = /* @__PURE__ */ new Set([
|
|
5617
|
-
"low",
|
|
5618
|
-
"medium",
|
|
5619
|
-
"high",
|
|
5620
|
-
"ultra_high",
|
|
5621
|
-
"unspecified"
|
|
5622
|
-
]);
|
|
5623
|
-
var ATTACHMENT_COUNT_TIMEOUT_MS = 2e4;
|
|
5624
|
-
var REMOTE_IMAGE_PROBE_TIMEOUT_MS = 2500;
|
|
5625
|
-
var PROVIDER_API_KEY_ENV_VARS = {
|
|
5626
|
-
openai: ["OPENAI_API_KEY"],
|
|
5627
|
-
google: ["GOOGLE_GENERATIVE_AI_API_KEY", "GOOGLE_API_KEY"],
|
|
5628
|
-
anthropic: ["ANTHROPIC_API_KEY"]
|
|
5629
|
-
};
|
|
5630
|
-
function getPartMastraMetadata(part) {
|
|
5631
|
-
return part.providerMetadata?.mastra;
|
|
5632
|
-
}
|
|
5633
|
-
function ensurePartMastraMetadata(part) {
|
|
5634
|
-
const typedPart = part;
|
|
5635
|
-
typedPart.providerMetadata ??= {};
|
|
5636
|
-
typedPart.providerMetadata.mastra ??= {};
|
|
5637
|
-
return typedPart.providerMetadata.mastra;
|
|
5638
|
-
}
|
|
5639
|
-
function getContentMastraMetadata(content) {
|
|
5640
|
-
if (!content || typeof content !== "object") {
|
|
5641
|
-
return void 0;
|
|
5642
|
-
}
|
|
5643
|
-
return content.metadata?.mastra;
|
|
5644
|
-
}
|
|
5645
|
-
function ensureContentMastraMetadata(content) {
|
|
5646
|
-
if (!content || typeof content !== "object") {
|
|
5647
|
-
return void 0;
|
|
5648
|
-
}
|
|
5649
|
-
const typedContent = content;
|
|
5650
|
-
typedContent.metadata ??= {};
|
|
5651
|
-
typedContent.metadata.mastra ??= {};
|
|
5652
|
-
return typedContent.metadata.mastra;
|
|
5653
|
-
}
|
|
5654
|
-
function getMessageMastraMetadata(message) {
|
|
5655
|
-
return message.metadata?.mastra;
|
|
5656
|
-
}
|
|
5657
|
-
function ensureMessageMastraMetadata(message) {
|
|
5658
|
-
const typedMessage = message;
|
|
5659
|
-
typedMessage.metadata ??= {};
|
|
5660
|
-
typedMessage.metadata.mastra ??= {};
|
|
5661
|
-
return typedMessage.metadata.mastra;
|
|
5662
|
-
}
|
|
5663
|
-
function buildEstimateKey(kind, text) {
|
|
5664
|
-
const payloadHash = crypto$1.createHash("sha1").update(text).digest("hex");
|
|
5665
|
-
return `${kind}:${payloadHash}`;
|
|
5680
|
+
function getOmReproCaptureDir() {
|
|
5681
|
+
return process.env.OM_REPRO_CAPTURE_DIR ?? ".mastra-om-repro";
|
|
5666
5682
|
}
|
|
5667
|
-
function
|
|
5668
|
-
|
|
5683
|
+
function sanitizeCapturePathSegment(value) {
|
|
5684
|
+
const sanitized = value.replace(/[\\/]+/g, "_").replace(/\.{2,}/g, "_").trim();
|
|
5685
|
+
return sanitized.length > 0 ? sanitized : "unknown-thread";
|
|
5669
5686
|
}
|
|
5670
|
-
function
|
|
5671
|
-
|
|
5672
|
-
const entry = value;
|
|
5673
|
-
return typeof entry.v === "number" && typeof entry.source === "string" && typeof entry.key === "string" && typeof entry.tokens === "number";
|
|
5687
|
+
function isOmReproCaptureEnabled() {
|
|
5688
|
+
return process.env.OM_REPRO_CAPTURE === "1";
|
|
5674
5689
|
}
|
|
5675
|
-
function
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5690
|
+
function safeCaptureJson(value) {
|
|
5691
|
+
return JSON.parse(
|
|
5692
|
+
JSON.stringify(value, (_key, current) => {
|
|
5693
|
+
if (typeof current === "bigint") return current.toString();
|
|
5694
|
+
if (typeof current === "function") return "[function]";
|
|
5695
|
+
if (typeof current === "symbol") return current.toString();
|
|
5696
|
+
if (current instanceof Error) return { name: current.name, message: current.message, stack: current.stack };
|
|
5697
|
+
if (current instanceof Set) return { __type: "Set", values: Array.from(current.values()) };
|
|
5698
|
+
if (current instanceof Map) return { __type: "Map", entries: Array.from(current.entries()) };
|
|
5699
|
+
return current;
|
|
5700
|
+
})
|
|
5701
|
+
);
|
|
5682
5702
|
}
|
|
5683
|
-
function
|
|
5684
|
-
|
|
5685
|
-
|
|
5686
|
-
|
|
5687
|
-
}
|
|
5688
|
-
return {
|
|
5689
|
-
[cache.key]: cache,
|
|
5690
|
-
[key]: entry
|
|
5691
|
-
};
|
|
5692
|
-
}
|
|
5693
|
-
if (cache && typeof cache === "object") {
|
|
5703
|
+
function safeCaptureJsonOrError(value) {
|
|
5704
|
+
try {
|
|
5705
|
+
return { ok: true, value: safeCaptureJson(value) };
|
|
5706
|
+
} catch (error) {
|
|
5694
5707
|
return {
|
|
5695
|
-
|
|
5696
|
-
|
|
5708
|
+
ok: false,
|
|
5709
|
+
error: safeCaptureJson({
|
|
5710
|
+
message: error instanceof Error ? error.message : String(error),
|
|
5711
|
+
stack: error instanceof Error ? error.stack : void 0,
|
|
5712
|
+
inspected: util.inspect(value, { depth: 3, maxArrayLength: 20, breakLength: 120 })
|
|
5713
|
+
})
|
|
5697
5714
|
};
|
|
5698
5715
|
}
|
|
5699
|
-
return entry;
|
|
5700
|
-
}
|
|
5701
|
-
function getPartCacheEntry(part, key) {
|
|
5702
|
-
return getCacheEntry(getPartMastraMetadata(part)?.tokenEstimate, key);
|
|
5703
|
-
}
|
|
5704
|
-
function setPartCacheEntry(part, key, entry) {
|
|
5705
|
-
const mastraMetadata = ensurePartMastraMetadata(part);
|
|
5706
|
-
mastraMetadata.tokenEstimate = mergeCacheEntry(mastraMetadata.tokenEstimate, key, entry);
|
|
5707
|
-
}
|
|
5708
|
-
function getMessageCacheEntry(message, key) {
|
|
5709
|
-
const contentLevelEntry = getCacheEntry(getContentMastraMetadata(message.content)?.tokenEstimate, key);
|
|
5710
|
-
if (contentLevelEntry) return contentLevelEntry;
|
|
5711
|
-
return getCacheEntry(getMessageMastraMetadata(message)?.tokenEstimate, key);
|
|
5712
5716
|
}
|
|
5713
|
-
function
|
|
5714
|
-
|
|
5715
|
-
if (
|
|
5716
|
-
|
|
5717
|
-
return;
|
|
5717
|
+
function formatCaptureDate(value) {
|
|
5718
|
+
if (!value) return void 0;
|
|
5719
|
+
if (value instanceof Date) return value.toISOString();
|
|
5720
|
+
try {
|
|
5721
|
+
return new Date(value).toISOString();
|
|
5722
|
+
} catch {
|
|
5723
|
+
return void 0;
|
|
5718
5724
|
}
|
|
5719
|
-
const messageMastraMetadata = ensureMessageMastraMetadata(message);
|
|
5720
|
-
messageMastraMetadata.tokenEstimate = mergeCacheEntry(messageMastraMetadata.tokenEstimate, key, entry);
|
|
5721
5725
|
}
|
|
5722
|
-
function
|
|
5723
|
-
|
|
5724
|
-
|
|
5725
|
-
if (!hasTokenEstimate) {
|
|
5726
|
-
return JSON.stringify(part);
|
|
5727
|
-
}
|
|
5728
|
-
const clonedPart = {
|
|
5729
|
-
...typedPart,
|
|
5730
|
-
providerMetadata: {
|
|
5731
|
-
...typedPart.providerMetadata ?? {},
|
|
5732
|
-
mastra: {
|
|
5733
|
-
...typedPart.providerMetadata?.mastra ?? {}
|
|
5734
|
-
}
|
|
5735
|
-
}
|
|
5736
|
-
};
|
|
5737
|
-
delete clonedPart.providerMetadata.mastra.tokenEstimate;
|
|
5738
|
-
if (Object.keys(clonedPart.providerMetadata.mastra).length === 0) {
|
|
5739
|
-
delete clonedPart.providerMetadata.mastra;
|
|
5740
|
-
}
|
|
5741
|
-
if (Object.keys(clonedPart.providerMetadata).length === 0) {
|
|
5742
|
-
delete clonedPart.providerMetadata;
|
|
5726
|
+
function summarizeOmTurn(value) {
|
|
5727
|
+
if (!value || typeof value !== "object") {
|
|
5728
|
+
return value;
|
|
5743
5729
|
}
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
|
|
5730
|
+
const turn = value;
|
|
5731
|
+
return {
|
|
5732
|
+
__type: "ObservationTurn",
|
|
5733
|
+
threadId: turn.threadId,
|
|
5734
|
+
resourceId: turn.resourceId,
|
|
5735
|
+
started: turn._started,
|
|
5736
|
+
ended: turn._ended,
|
|
5737
|
+
generationCountAtStart: turn._generationCountAtStart,
|
|
5738
|
+
record: turn._record ? {
|
|
5739
|
+
id: turn._record.id,
|
|
5740
|
+
scope: turn._record.scope,
|
|
5741
|
+
threadId: turn._record.threadId,
|
|
5742
|
+
resourceId: turn._record.resourceId,
|
|
5743
|
+
createdAt: formatCaptureDate(turn._record.createdAt),
|
|
5744
|
+
updatedAt: formatCaptureDate(turn._record.updatedAt),
|
|
5745
|
+
lastObservedAt: formatCaptureDate(turn._record.lastObservedAt),
|
|
5746
|
+
generationCount: turn._record.generationCount,
|
|
5747
|
+
observationTokenCount: turn._record.observationTokenCount,
|
|
5748
|
+
pendingMessageTokens: turn._record.pendingMessageTokens,
|
|
5749
|
+
isBufferingObservation: turn._record.isBufferingObservation,
|
|
5750
|
+
isBufferingReflection: turn._record.isBufferingReflection
|
|
5751
|
+
} : void 0,
|
|
5752
|
+
context: turn._context ? {
|
|
5753
|
+
messageCount: Array.isArray(turn._context.messages) ? turn._context.messages.length : void 0,
|
|
5754
|
+
hasSystemMessage: Array.isArray(turn._context.systemMessage) ? turn._context.systemMessage.length > 0 : Boolean(turn._context.systemMessage),
|
|
5755
|
+
continuationId: turn._context.continuation?.id,
|
|
5756
|
+
hasOtherThreadsContext: Boolean(turn._context.otherThreadsContext),
|
|
5757
|
+
recordId: turn._context.record?.id
|
|
5758
|
+
} : void 0,
|
|
5759
|
+
currentStep: turn._currentStep ? {
|
|
5760
|
+
stepNumber: turn._currentStep.stepNumber,
|
|
5761
|
+
prepared: turn._currentStep._prepared,
|
|
5762
|
+
context: turn._currentStep._context ? {
|
|
5763
|
+
activated: turn._currentStep._context.activated,
|
|
5764
|
+
observed: turn._currentStep._context.observed,
|
|
5765
|
+
buffered: turn._currentStep._context.buffered,
|
|
5766
|
+
reflected: turn._currentStep._context.reflected,
|
|
5767
|
+
didThresholdCleanup: turn._currentStep._context.didThresholdCleanup,
|
|
5768
|
+
messageCount: Array.isArray(turn._currentStep._context.messages) ? turn._currentStep._context.messages.length : void 0,
|
|
5769
|
+
systemMessageCount: Array.isArray(turn._currentStep._context.systemMessage) ? turn._currentStep._context.systemMessage.length : void 0
|
|
5770
|
+
} : void 0
|
|
5771
|
+
} : void 0
|
|
5772
|
+
};
|
|
5773
|
+
}
|
|
5774
|
+
function sanitizeCaptureState(rawState) {
|
|
5775
|
+
return Object.fromEntries(
|
|
5776
|
+
Object.entries(rawState).map(([key, value]) => {
|
|
5777
|
+
if (key === "__omTurn") {
|
|
5778
|
+
return [key, summarizeOmTurn(value)];
|
|
5779
|
+
}
|
|
5780
|
+
return [key, value];
|
|
5781
|
+
})
|
|
5782
|
+
);
|
|
5783
|
+
}
|
|
5784
|
+
function buildReproMessageFingerprint(message) {
|
|
5785
|
+
const createdAt = message.createdAt instanceof Date ? message.createdAt.toISOString() : message.createdAt ? new Date(message.createdAt).toISOString() : "";
|
|
5786
|
+
return JSON.stringify({
|
|
5787
|
+
role: message.role,
|
|
5788
|
+
createdAt,
|
|
5789
|
+
content: message.content
|
|
5790
|
+
});
|
|
5791
|
+
}
|
|
5792
|
+
function inferReproIdRemap(preMessages, postMessages) {
|
|
5793
|
+
const preByFingerprint = /* @__PURE__ */ new Map();
|
|
5794
|
+
const postByFingerprint = /* @__PURE__ */ new Map();
|
|
5795
|
+
for (const message of preMessages) {
|
|
5796
|
+
if (!message.id) continue;
|
|
5797
|
+
const fingerprint = buildReproMessageFingerprint(message);
|
|
5798
|
+
const list = preByFingerprint.get(fingerprint) ?? [];
|
|
5799
|
+
list.push(message.id);
|
|
5800
|
+
preByFingerprint.set(fingerprint, list);
|
|
5801
|
+
}
|
|
5802
|
+
for (const message of postMessages) {
|
|
5803
|
+
if (!message.id) continue;
|
|
5804
|
+
const fingerprint = buildReproMessageFingerprint(message);
|
|
5805
|
+
const list = postByFingerprint.get(fingerprint) ?? [];
|
|
5806
|
+
list.push(message.id);
|
|
5807
|
+
postByFingerprint.set(fingerprint, list);
|
|
5808
|
+
}
|
|
5809
|
+
const remap = [];
|
|
5810
|
+
for (const [fingerprint, preIds] of preByFingerprint.entries()) {
|
|
5811
|
+
const postIds = postByFingerprint.get(fingerprint);
|
|
5812
|
+
if (!postIds || preIds.length !== 1 || postIds.length !== 1) continue;
|
|
5813
|
+
const fromId = preIds[0];
|
|
5814
|
+
const toId = postIds[0];
|
|
5815
|
+
if (!fromId || !toId || fromId === toId) {
|
|
5816
|
+
continue;
|
|
5817
|
+
}
|
|
5818
|
+
remap.push({ fromId, toId, fingerprint });
|
|
5819
|
+
}
|
|
5820
|
+
return remap;
|
|
5821
|
+
}
|
|
5822
|
+
function createOmReproCaptureDir(threadId, label) {
|
|
5823
|
+
const sanitizedThreadId = sanitizeCapturePathSegment(threadId);
|
|
5824
|
+
const captureDir = path.join(
|
|
5825
|
+
process.cwd(),
|
|
5826
|
+
getOmReproCaptureDir(),
|
|
5827
|
+
sanitizedThreadId,
|
|
5828
|
+
`${Date.now()}-${label}-${crypto$1.randomUUID()}`
|
|
5829
|
+
);
|
|
5830
|
+
fs.mkdirSync(captureDir, { recursive: true });
|
|
5831
|
+
return captureDir;
|
|
5832
|
+
}
|
|
5833
|
+
function writeObserverExchangeReproCapture(params) {
|
|
5834
|
+
if (!isOmReproCaptureEnabled() || !params.observerExchange) {
|
|
5835
|
+
return;
|
|
5836
|
+
}
|
|
5837
|
+
try {
|
|
5838
|
+
const captureDir = createOmReproCaptureDir(params.threadId, params.label);
|
|
5839
|
+
const payloads = [
|
|
5840
|
+
{
|
|
5841
|
+
fileName: "input.json",
|
|
5842
|
+
data: {
|
|
5843
|
+
threadId: params.threadId,
|
|
5844
|
+
resourceId: params.resourceId,
|
|
5845
|
+
label: params.label
|
|
5846
|
+
}
|
|
5847
|
+
},
|
|
5848
|
+
{
|
|
5849
|
+
fileName: "output.json",
|
|
5850
|
+
data: {
|
|
5851
|
+
details: params.details ?? {}
|
|
5852
|
+
}
|
|
5853
|
+
},
|
|
5854
|
+
{
|
|
5855
|
+
fileName: "observer-exchange.json",
|
|
5856
|
+
data: params.observerExchange
|
|
5857
|
+
}
|
|
5858
|
+
];
|
|
5859
|
+
const captureErrors = [];
|
|
5860
|
+
for (const payload of payloads) {
|
|
5861
|
+
const serialized = safeCaptureJsonOrError(payload.data);
|
|
5862
|
+
if (serialized.ok) {
|
|
5863
|
+
fs.writeFileSync(path.join(captureDir, payload.fileName), `${JSON.stringify(serialized.value, null, 2)}
|
|
5864
|
+
`);
|
|
5865
|
+
continue;
|
|
5866
|
+
}
|
|
5867
|
+
captureErrors.push({ fileName: payload.fileName, error: serialized.error });
|
|
5868
|
+
fs.writeFileSync(
|
|
5869
|
+
path.join(captureDir, payload.fileName),
|
|
5870
|
+
`${JSON.stringify({ __captureError: serialized.error }, null, 2)}
|
|
5871
|
+
`
|
|
5872
|
+
);
|
|
5873
|
+
}
|
|
5874
|
+
if (captureErrors.length > 0) {
|
|
5875
|
+
fs.writeFileSync(path.join(captureDir, "capture-error.json"), `${JSON.stringify(captureErrors, null, 2)}
|
|
5876
|
+
`);
|
|
5877
|
+
params.debug?.(
|
|
5878
|
+
`[OM:repro-capture] wrote ${params.label} capture with ${captureErrors.length} serialization error(s) to ${captureDir}`
|
|
5879
|
+
);
|
|
5880
|
+
return;
|
|
5881
|
+
}
|
|
5882
|
+
params.debug?.(`[OM:repro-capture] wrote ${params.label} capture to ${captureDir}`);
|
|
5883
|
+
} catch (error) {
|
|
5884
|
+
params.debug?.(`[OM:repro-capture] failed to write ${params.label} capture: ${String(error)}`);
|
|
5885
|
+
}
|
|
5886
|
+
}
|
|
5887
|
+
function writeProcessInputStepReproCapture(params) {
|
|
5888
|
+
if (!isOmReproCaptureEnabled()) {
|
|
5889
|
+
return;
|
|
5890
|
+
}
|
|
5891
|
+
try {
|
|
5892
|
+
const captureDir = createOmReproCaptureDir(params.threadId, `step-${params.stepNumber}`);
|
|
5893
|
+
const contextMessages = params.messageList.get.all.db();
|
|
5894
|
+
const memoryContext = memory.parseMemoryRequestContext(params.args.requestContext);
|
|
5895
|
+
const preMessageIds = new Set(params.preMessages.map((message) => message.id));
|
|
5896
|
+
const postMessageIds = new Set(contextMessages.map((message) => message.id));
|
|
5897
|
+
const removedMessageIds = params.preMessages.map((message) => message.id).filter((id) => Boolean(id) && !postMessageIds.has(id));
|
|
5898
|
+
const addedMessageIds = contextMessages.map((message) => message.id).filter((id) => Boolean(id) && !preMessageIds.has(id));
|
|
5899
|
+
const idRemap = inferReproIdRemap(params.preMessages, contextMessages);
|
|
5900
|
+
const rawState = params.args.state ?? {};
|
|
5901
|
+
const sanitizedState = sanitizeCaptureState(rawState);
|
|
5902
|
+
const payloads = [
|
|
5903
|
+
{
|
|
5904
|
+
fileName: "input.json",
|
|
5905
|
+
data: {
|
|
5906
|
+
stepNumber: params.stepNumber,
|
|
5907
|
+
threadId: params.threadId,
|
|
5908
|
+
resourceId: params.resourceId,
|
|
5909
|
+
readOnly: memoryContext?.memoryConfig?.readOnly,
|
|
5910
|
+
messageCount: contextMessages.length,
|
|
5911
|
+
messageIds: contextMessages.map((message) => message.id),
|
|
5912
|
+
stateKeys: Object.keys(rawState),
|
|
5913
|
+
state: sanitizedState,
|
|
5914
|
+
args: {
|
|
5915
|
+
messages: params.args.messages,
|
|
5916
|
+
steps: params.args.steps,
|
|
5917
|
+
systemMessages: params.args.systemMessages,
|
|
5918
|
+
retryCount: params.args.retryCount,
|
|
5919
|
+
toolChoice: params.args.toolChoice,
|
|
5920
|
+
activeTools: params.args.activeTools,
|
|
5921
|
+
modelSettings: params.args.modelSettings,
|
|
5922
|
+
structuredOutput: params.args.structuredOutput
|
|
5923
|
+
}
|
|
5924
|
+
}
|
|
5925
|
+
},
|
|
5926
|
+
{
|
|
5927
|
+
fileName: "pre-state.json",
|
|
5928
|
+
data: {
|
|
5929
|
+
record: params.preRecord,
|
|
5930
|
+
bufferedChunks: params.preBufferedChunks,
|
|
5931
|
+
contextTokenCount: params.preContextTokenCount,
|
|
5932
|
+
messages: params.preMessages,
|
|
5933
|
+
messageList: params.preSerializedMessageList
|
|
5934
|
+
}
|
|
5935
|
+
},
|
|
5936
|
+
{
|
|
5937
|
+
fileName: "output.json",
|
|
5938
|
+
data: {
|
|
5939
|
+
details: params.details,
|
|
5940
|
+
messageDiff: {
|
|
5941
|
+
removedMessageIds,
|
|
5942
|
+
addedMessageIds,
|
|
5943
|
+
idRemap
|
|
5944
|
+
}
|
|
5945
|
+
}
|
|
5946
|
+
},
|
|
5947
|
+
{
|
|
5948
|
+
fileName: "post-state.json",
|
|
5949
|
+
data: {
|
|
5950
|
+
record: params.postRecord,
|
|
5951
|
+
bufferedChunks: params.postBufferedChunks,
|
|
5952
|
+
contextTokenCount: params.postContextTokenCount,
|
|
5953
|
+
messageCount: contextMessages.length,
|
|
5954
|
+
messageIds: contextMessages.map((message) => message.id),
|
|
5955
|
+
messages: contextMessages,
|
|
5956
|
+
messageList: params.messageList.serialize()
|
|
5957
|
+
}
|
|
5958
|
+
}
|
|
5959
|
+
];
|
|
5960
|
+
const captureErrors = [];
|
|
5961
|
+
for (const payload of payloads) {
|
|
5962
|
+
const serialized = safeCaptureJsonOrError(payload.data);
|
|
5963
|
+
if (serialized.ok) {
|
|
5964
|
+
fs.writeFileSync(path.join(captureDir, payload.fileName), `${JSON.stringify(serialized.value, null, 2)}
|
|
5965
|
+
`);
|
|
5966
|
+
continue;
|
|
5967
|
+
}
|
|
5968
|
+
captureErrors.push({ fileName: payload.fileName, error: serialized.error });
|
|
5969
|
+
fs.writeFileSync(
|
|
5970
|
+
path.join(captureDir, payload.fileName),
|
|
5971
|
+
`${JSON.stringify({ __captureError: serialized.error }, null, 2)}
|
|
5972
|
+
`
|
|
5973
|
+
);
|
|
5974
|
+
}
|
|
5975
|
+
if (params.observerExchange) {
|
|
5976
|
+
const serialized = safeCaptureJsonOrError(params.observerExchange);
|
|
5977
|
+
if (serialized.ok) {
|
|
5978
|
+
fs.writeFileSync(path.join(captureDir, "observer-exchange.json"), `${JSON.stringify(serialized.value, null, 2)}
|
|
5979
|
+
`);
|
|
5980
|
+
} else {
|
|
5981
|
+
captureErrors.push({ fileName: "observer-exchange.json", error: serialized.error });
|
|
5982
|
+
fs.writeFileSync(
|
|
5983
|
+
path.join(captureDir, "observer-exchange.json"),
|
|
5984
|
+
`${JSON.stringify({ __captureError: serialized.error }, null, 2)}
|
|
5985
|
+
`
|
|
5986
|
+
);
|
|
5987
|
+
}
|
|
5988
|
+
}
|
|
5989
|
+
if (captureErrors.length > 0) {
|
|
5990
|
+
fs.writeFileSync(path.join(captureDir, "capture-error.json"), `${JSON.stringify(captureErrors, null, 2)}
|
|
5991
|
+
`);
|
|
5992
|
+
params.debug?.(
|
|
5993
|
+
`[OM:repro-capture] wrote processInputStep capture with ${captureErrors.length} serialization error(s) to ${captureDir}`
|
|
5994
|
+
);
|
|
5995
|
+
return;
|
|
5996
|
+
}
|
|
5997
|
+
params.debug?.(`[OM:repro-capture] wrote processInputStep capture to ${captureDir}`);
|
|
5998
|
+
} catch (error) {
|
|
5999
|
+
params.debug?.(`[OM:repro-capture] failed to write processInputStep capture: ${String(error)}`);
|
|
6000
|
+
}
|
|
6001
|
+
}
|
|
6002
|
+
var IMAGE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
6003
|
+
"png",
|
|
6004
|
+
"jpg",
|
|
6005
|
+
"jpeg",
|
|
6006
|
+
"webp",
|
|
6007
|
+
"gif",
|
|
6008
|
+
"bmp",
|
|
6009
|
+
"tiff",
|
|
6010
|
+
"tif",
|
|
6011
|
+
"heic",
|
|
6012
|
+
"heif",
|
|
6013
|
+
"avif"
|
|
6014
|
+
]);
|
|
6015
|
+
var TOKEN_ESTIMATE_CACHE_VERSION = 6;
|
|
6016
|
+
var DEFAULT_IMAGE_ESTIMATOR = {
|
|
6017
|
+
baseTokens: 85,
|
|
6018
|
+
tileTokens: 170,
|
|
6019
|
+
fallbackTiles: 4
|
|
6020
|
+
};
|
|
6021
|
+
var GOOGLE_LEGACY_IMAGE_TOKENS_PER_TILE = 258;
|
|
6022
|
+
var GOOGLE_GEMINI_3_IMAGE_TOKENS_BY_RESOLUTION = {
|
|
6023
|
+
low: 280,
|
|
6024
|
+
medium: 560,
|
|
6025
|
+
high: 1120,
|
|
6026
|
+
ultra_high: 2240,
|
|
6027
|
+
unspecified: 1120
|
|
6028
|
+
};
|
|
6029
|
+
var ANTHROPIC_IMAGE_TOKENS_PER_PIXEL = 1 / 750;
|
|
6030
|
+
var ANTHROPIC_IMAGE_MAX_LONG_EDGE = 1568;
|
|
6031
|
+
var GOOGLE_MEDIA_RESOLUTION_VALUES = /* @__PURE__ */ new Set([
|
|
6032
|
+
"low",
|
|
6033
|
+
"medium",
|
|
6034
|
+
"high",
|
|
6035
|
+
"ultra_high",
|
|
6036
|
+
"unspecified"
|
|
6037
|
+
]);
|
|
6038
|
+
var ATTACHMENT_COUNT_TIMEOUT_MS = 2e4;
|
|
6039
|
+
var REMOTE_IMAGE_PROBE_TIMEOUT_MS = 2500;
|
|
6040
|
+
var PROVIDER_API_KEY_ENV_VARS = {
|
|
6041
|
+
openai: ["OPENAI_API_KEY"],
|
|
6042
|
+
google: ["GOOGLE_GENERATIVE_AI_API_KEY", "GOOGLE_API_KEY"],
|
|
6043
|
+
anthropic: ["ANTHROPIC_API_KEY"]
|
|
6044
|
+
};
|
|
6045
|
+
function getPartMastraMetadata(part) {
|
|
6046
|
+
return part.providerMetadata?.mastra;
|
|
6047
|
+
}
|
|
6048
|
+
function ensurePartMastraMetadata(part) {
|
|
6049
|
+
const typedPart = part;
|
|
6050
|
+
typedPart.providerMetadata ??= {};
|
|
6051
|
+
typedPart.providerMetadata.mastra ??= {};
|
|
6052
|
+
return typedPart.providerMetadata.mastra;
|
|
6053
|
+
}
|
|
6054
|
+
function getContentMastraMetadata(content) {
|
|
6055
|
+
if (!content || typeof content !== "object") {
|
|
6056
|
+
return void 0;
|
|
6057
|
+
}
|
|
6058
|
+
return content.metadata?.mastra;
|
|
6059
|
+
}
|
|
6060
|
+
function ensureContentMastraMetadata(content) {
|
|
6061
|
+
if (!content || typeof content !== "object") {
|
|
6062
|
+
return void 0;
|
|
6063
|
+
}
|
|
6064
|
+
const typedContent = content;
|
|
6065
|
+
typedContent.metadata ??= {};
|
|
6066
|
+
typedContent.metadata.mastra ??= {};
|
|
6067
|
+
return typedContent.metadata.mastra;
|
|
6068
|
+
}
|
|
6069
|
+
function getMessageMastraMetadata(message) {
|
|
6070
|
+
return message.metadata?.mastra;
|
|
6071
|
+
}
|
|
6072
|
+
function ensureMessageMastraMetadata(message) {
|
|
6073
|
+
const typedMessage = message;
|
|
6074
|
+
typedMessage.metadata ??= {};
|
|
6075
|
+
typedMessage.metadata.mastra ??= {};
|
|
6076
|
+
return typedMessage.metadata.mastra;
|
|
6077
|
+
}
|
|
6078
|
+
function buildEstimateKey(kind, text) {
|
|
6079
|
+
const payloadHash = crypto$1.createHash("sha1").update(text).digest("hex");
|
|
6080
|
+
return `${kind}:${payloadHash}`;
|
|
6081
|
+
}
|
|
6082
|
+
function resolveEstimatorId() {
|
|
6083
|
+
return "tokenx";
|
|
6084
|
+
}
|
|
6085
|
+
function isTokenEstimateEntry(value) {
|
|
6086
|
+
if (!value || typeof value !== "object") return false;
|
|
6087
|
+
const entry = value;
|
|
6088
|
+
return typeof entry.v === "number" && typeof entry.source === "string" && typeof entry.key === "string" && typeof entry.tokens === "number";
|
|
6089
|
+
}
|
|
6090
|
+
function getCacheEntry(cache, key) {
|
|
6091
|
+
if (!cache || typeof cache !== "object") return void 0;
|
|
6092
|
+
if (isTokenEstimateEntry(cache)) {
|
|
6093
|
+
return cache.key === key ? cache : void 0;
|
|
6094
|
+
}
|
|
6095
|
+
const keyedEntry = cache[key];
|
|
6096
|
+
return isTokenEstimateEntry(keyedEntry) ? keyedEntry : void 0;
|
|
6097
|
+
}
|
|
6098
|
+
function mergeCacheEntry(cache, key, entry) {
|
|
6099
|
+
if (isTokenEstimateEntry(cache)) {
|
|
6100
|
+
if (cache.key === key) {
|
|
6101
|
+
return entry;
|
|
6102
|
+
}
|
|
6103
|
+
return {
|
|
6104
|
+
[cache.key]: cache,
|
|
6105
|
+
[key]: entry
|
|
6106
|
+
};
|
|
6107
|
+
}
|
|
6108
|
+
if (cache && typeof cache === "object") {
|
|
6109
|
+
return {
|
|
6110
|
+
...cache,
|
|
6111
|
+
[key]: entry
|
|
6112
|
+
};
|
|
6113
|
+
}
|
|
6114
|
+
return entry;
|
|
6115
|
+
}
|
|
6116
|
+
function getPartCacheEntry(part, key) {
|
|
6117
|
+
return getCacheEntry(getPartMastraMetadata(part)?.tokenEstimate, key);
|
|
6118
|
+
}
|
|
6119
|
+
function setPartCacheEntry(part, key, entry) {
|
|
6120
|
+
const mastraMetadata = ensurePartMastraMetadata(part);
|
|
6121
|
+
mastraMetadata.tokenEstimate = mergeCacheEntry(mastraMetadata.tokenEstimate, key, entry);
|
|
6122
|
+
}
|
|
6123
|
+
function getMessageCacheEntry(message, key) {
|
|
6124
|
+
const contentLevelEntry = getCacheEntry(getContentMastraMetadata(message.content)?.tokenEstimate, key);
|
|
6125
|
+
if (contentLevelEntry) return contentLevelEntry;
|
|
6126
|
+
return getCacheEntry(getMessageMastraMetadata(message)?.tokenEstimate, key);
|
|
6127
|
+
}
|
|
6128
|
+
function setMessageCacheEntry(message, key, entry) {
|
|
6129
|
+
const contentMastraMetadata = ensureContentMastraMetadata(message.content);
|
|
6130
|
+
if (contentMastraMetadata) {
|
|
6131
|
+
contentMastraMetadata.tokenEstimate = mergeCacheEntry(contentMastraMetadata.tokenEstimate, key, entry);
|
|
6132
|
+
return;
|
|
6133
|
+
}
|
|
6134
|
+
const messageMastraMetadata = ensureMessageMastraMetadata(message);
|
|
6135
|
+
messageMastraMetadata.tokenEstimate = mergeCacheEntry(messageMastraMetadata.tokenEstimate, key, entry);
|
|
6136
|
+
}
|
|
6137
|
+
function serializePartForTokenCounting(part) {
|
|
6138
|
+
const typedPart = part;
|
|
6139
|
+
const hasTokenEstimate = Boolean(typedPart.providerMetadata?.mastra?.tokenEstimate);
|
|
6140
|
+
if (!hasTokenEstimate) {
|
|
6141
|
+
return JSON.stringify(part);
|
|
6142
|
+
}
|
|
6143
|
+
const clonedPart = {
|
|
6144
|
+
...typedPart,
|
|
6145
|
+
providerMetadata: {
|
|
6146
|
+
...typedPart.providerMetadata ?? {},
|
|
6147
|
+
mastra: {
|
|
6148
|
+
...typedPart.providerMetadata?.mastra ?? {}
|
|
6149
|
+
}
|
|
6150
|
+
}
|
|
6151
|
+
};
|
|
6152
|
+
delete clonedPart.providerMetadata.mastra.tokenEstimate;
|
|
6153
|
+
if (Object.keys(clonedPart.providerMetadata.mastra).length === 0) {
|
|
6154
|
+
delete clonedPart.providerMetadata.mastra;
|
|
6155
|
+
}
|
|
6156
|
+
if (Object.keys(clonedPart.providerMetadata).length === 0) {
|
|
6157
|
+
delete clonedPart.providerMetadata;
|
|
6158
|
+
}
|
|
6159
|
+
return JSON.stringify(clonedPart);
|
|
6160
|
+
}
|
|
6161
|
+
function getFilenameFromAttachmentData(data) {
|
|
6162
|
+
const pathname = data instanceof URL ? data.pathname : typeof data === "string" && isHttpUrlString(data) ? (() => {
|
|
6163
|
+
try {
|
|
6164
|
+
return new URL(data).pathname;
|
|
6165
|
+
} catch {
|
|
6166
|
+
return void 0;
|
|
5752
6167
|
}
|
|
5753
6168
|
})() : void 0;
|
|
5754
6169
|
const filename = pathname?.split("/").filter(Boolean).pop();
|
|
@@ -8781,6 +9196,23 @@ ${grouped}` : grouped;
|
|
|
8781
9196
|
requestContext,
|
|
8782
9197
|
observabilityContext
|
|
8783
9198
|
}).run();
|
|
9199
|
+
if (isOmReproCaptureEnabled()) {
|
|
9200
|
+
writeObserverExchangeReproCapture({
|
|
9201
|
+
threadId,
|
|
9202
|
+
resourceId: record.resourceId ?? void 0,
|
|
9203
|
+
label: `buffer-${cycleId}`,
|
|
9204
|
+
observerExchange: this.observer.lastExchange,
|
|
9205
|
+
details: {
|
|
9206
|
+
cycleId,
|
|
9207
|
+
startedAt,
|
|
9208
|
+
buffered: true,
|
|
9209
|
+
candidateMessageIds: candidateMessages.map((message) => message.id),
|
|
9210
|
+
candidateMessageCount: candidateMessages.length,
|
|
9211
|
+
pendingTokens: currentTokens,
|
|
9212
|
+
newTokens
|
|
9213
|
+
}
|
|
9214
|
+
});
|
|
9215
|
+
}
|
|
8784
9216
|
await this.storage.setBufferingObservationFlag(record.id, false, newTokens).catch(() => {
|
|
8785
9217
|
});
|
|
8786
9218
|
flagCleared = true;
|
|
@@ -9176,264 +9608,6 @@ ${grouped}` : grouped;
|
|
|
9176
9608
|
});
|
|
9177
9609
|
}
|
|
9178
9610
|
};
|
|
9179
|
-
var OM_REPRO_CAPTURE_DIR = process.env.OM_REPRO_CAPTURE_DIR ?? ".mastra-om-repro";
|
|
9180
|
-
function sanitizeCapturePathSegment(value) {
|
|
9181
|
-
const sanitized = value.replace(/[\\/]+/g, "_").replace(/\.{2,}/g, "_").trim();
|
|
9182
|
-
return sanitized.length > 0 ? sanitized : "unknown-thread";
|
|
9183
|
-
}
|
|
9184
|
-
function isOmReproCaptureEnabled() {
|
|
9185
|
-
return process.env.OM_REPRO_CAPTURE === "1";
|
|
9186
|
-
}
|
|
9187
|
-
function safeCaptureJson(value) {
|
|
9188
|
-
return JSON.parse(
|
|
9189
|
-
JSON.stringify(value, (_key, current) => {
|
|
9190
|
-
if (typeof current === "bigint") return current.toString();
|
|
9191
|
-
if (typeof current === "function") return "[function]";
|
|
9192
|
-
if (typeof current === "symbol") return current.toString();
|
|
9193
|
-
if (current instanceof Error) return { name: current.name, message: current.message, stack: current.stack };
|
|
9194
|
-
if (current instanceof Set) return { __type: "Set", values: Array.from(current.values()) };
|
|
9195
|
-
if (current instanceof Map) return { __type: "Map", entries: Array.from(current.entries()) };
|
|
9196
|
-
return current;
|
|
9197
|
-
})
|
|
9198
|
-
);
|
|
9199
|
-
}
|
|
9200
|
-
function safeCaptureJsonOrError(value) {
|
|
9201
|
-
try {
|
|
9202
|
-
return { ok: true, value: safeCaptureJson(value) };
|
|
9203
|
-
} catch (error) {
|
|
9204
|
-
return {
|
|
9205
|
-
ok: false,
|
|
9206
|
-
error: safeCaptureJson({
|
|
9207
|
-
message: error instanceof Error ? error.message : String(error),
|
|
9208
|
-
stack: error instanceof Error ? error.stack : void 0,
|
|
9209
|
-
inspected: util.inspect(value, { depth: 3, maxArrayLength: 20, breakLength: 120 })
|
|
9210
|
-
})
|
|
9211
|
-
};
|
|
9212
|
-
}
|
|
9213
|
-
}
|
|
9214
|
-
function formatCaptureDate(value) {
|
|
9215
|
-
if (!value) return void 0;
|
|
9216
|
-
if (value instanceof Date) return value.toISOString();
|
|
9217
|
-
try {
|
|
9218
|
-
return new Date(value).toISOString();
|
|
9219
|
-
} catch {
|
|
9220
|
-
return void 0;
|
|
9221
|
-
}
|
|
9222
|
-
}
|
|
9223
|
-
function summarizeOmTurn(value) {
|
|
9224
|
-
if (!value || typeof value !== "object") {
|
|
9225
|
-
return value;
|
|
9226
|
-
}
|
|
9227
|
-
const turn = value;
|
|
9228
|
-
return {
|
|
9229
|
-
__type: "ObservationTurn",
|
|
9230
|
-
threadId: turn.threadId,
|
|
9231
|
-
resourceId: turn.resourceId,
|
|
9232
|
-
started: turn._started,
|
|
9233
|
-
ended: turn._ended,
|
|
9234
|
-
generationCountAtStart: turn._generationCountAtStart,
|
|
9235
|
-
record: turn._record ? {
|
|
9236
|
-
id: turn._record.id,
|
|
9237
|
-
scope: turn._record.scope,
|
|
9238
|
-
threadId: turn._record.threadId,
|
|
9239
|
-
resourceId: turn._record.resourceId,
|
|
9240
|
-
createdAt: formatCaptureDate(turn._record.createdAt),
|
|
9241
|
-
updatedAt: formatCaptureDate(turn._record.updatedAt),
|
|
9242
|
-
lastObservedAt: formatCaptureDate(turn._record.lastObservedAt),
|
|
9243
|
-
generationCount: turn._record.generationCount,
|
|
9244
|
-
observationTokenCount: turn._record.observationTokenCount,
|
|
9245
|
-
pendingMessageTokens: turn._record.pendingMessageTokens,
|
|
9246
|
-
isBufferingObservation: turn._record.isBufferingObservation,
|
|
9247
|
-
isBufferingReflection: turn._record.isBufferingReflection
|
|
9248
|
-
} : void 0,
|
|
9249
|
-
context: turn._context ? {
|
|
9250
|
-
messageCount: Array.isArray(turn._context.messages) ? turn._context.messages.length : void 0,
|
|
9251
|
-
hasSystemMessage: Array.isArray(turn._context.systemMessage) ? turn._context.systemMessage.length > 0 : Boolean(turn._context.systemMessage),
|
|
9252
|
-
continuationId: turn._context.continuation?.id,
|
|
9253
|
-
hasOtherThreadsContext: Boolean(turn._context.otherThreadsContext),
|
|
9254
|
-
recordId: turn._context.record?.id
|
|
9255
|
-
} : void 0,
|
|
9256
|
-
currentStep: turn._currentStep ? {
|
|
9257
|
-
stepNumber: turn._currentStep.stepNumber,
|
|
9258
|
-
prepared: turn._currentStep._prepared,
|
|
9259
|
-
context: turn._currentStep._context ? {
|
|
9260
|
-
activated: turn._currentStep._context.activated,
|
|
9261
|
-
observed: turn._currentStep._context.observed,
|
|
9262
|
-
buffered: turn._currentStep._context.buffered,
|
|
9263
|
-
reflected: turn._currentStep._context.reflected,
|
|
9264
|
-
didThresholdCleanup: turn._currentStep._context.didThresholdCleanup,
|
|
9265
|
-
messageCount: Array.isArray(turn._currentStep._context.messages) ? turn._currentStep._context.messages.length : void 0,
|
|
9266
|
-
systemMessageCount: Array.isArray(turn._currentStep._context.systemMessage) ? turn._currentStep._context.systemMessage.length : void 0
|
|
9267
|
-
} : void 0
|
|
9268
|
-
} : void 0
|
|
9269
|
-
};
|
|
9270
|
-
}
|
|
9271
|
-
function sanitizeCaptureState(rawState) {
|
|
9272
|
-
return Object.fromEntries(
|
|
9273
|
-
Object.entries(rawState).map(([key, value]) => {
|
|
9274
|
-
if (key === "__omTurn") {
|
|
9275
|
-
return [key, summarizeOmTurn(value)];
|
|
9276
|
-
}
|
|
9277
|
-
return [key, value];
|
|
9278
|
-
})
|
|
9279
|
-
);
|
|
9280
|
-
}
|
|
9281
|
-
function buildReproMessageFingerprint(message) {
|
|
9282
|
-
const createdAt = message.createdAt instanceof Date ? message.createdAt.toISOString() : message.createdAt ? new Date(message.createdAt).toISOString() : "";
|
|
9283
|
-
return JSON.stringify({
|
|
9284
|
-
role: message.role,
|
|
9285
|
-
createdAt,
|
|
9286
|
-
content: message.content
|
|
9287
|
-
});
|
|
9288
|
-
}
|
|
9289
|
-
function inferReproIdRemap(preMessages, postMessages) {
|
|
9290
|
-
const preByFingerprint = /* @__PURE__ */ new Map();
|
|
9291
|
-
const postByFingerprint = /* @__PURE__ */ new Map();
|
|
9292
|
-
for (const message of preMessages) {
|
|
9293
|
-
if (!message.id) continue;
|
|
9294
|
-
const fingerprint = buildReproMessageFingerprint(message);
|
|
9295
|
-
const list = preByFingerprint.get(fingerprint) ?? [];
|
|
9296
|
-
list.push(message.id);
|
|
9297
|
-
preByFingerprint.set(fingerprint, list);
|
|
9298
|
-
}
|
|
9299
|
-
for (const message of postMessages) {
|
|
9300
|
-
if (!message.id) continue;
|
|
9301
|
-
const fingerprint = buildReproMessageFingerprint(message);
|
|
9302
|
-
const list = postByFingerprint.get(fingerprint) ?? [];
|
|
9303
|
-
list.push(message.id);
|
|
9304
|
-
postByFingerprint.set(fingerprint, list);
|
|
9305
|
-
}
|
|
9306
|
-
const remap = [];
|
|
9307
|
-
for (const [fingerprint, preIds] of preByFingerprint.entries()) {
|
|
9308
|
-
const postIds = postByFingerprint.get(fingerprint);
|
|
9309
|
-
if (!postIds || preIds.length !== 1 || postIds.length !== 1) continue;
|
|
9310
|
-
const fromId = preIds[0];
|
|
9311
|
-
const toId = postIds[0];
|
|
9312
|
-
if (!fromId || !toId || fromId === toId) {
|
|
9313
|
-
continue;
|
|
9314
|
-
}
|
|
9315
|
-
remap.push({ fromId, toId, fingerprint });
|
|
9316
|
-
}
|
|
9317
|
-
return remap;
|
|
9318
|
-
}
|
|
9319
|
-
function writeProcessInputStepReproCapture(params) {
|
|
9320
|
-
if (!isOmReproCaptureEnabled()) {
|
|
9321
|
-
return;
|
|
9322
|
-
}
|
|
9323
|
-
try {
|
|
9324
|
-
const sanitizedThreadId = sanitizeCapturePathSegment(params.threadId);
|
|
9325
|
-
const runId = `${Date.now()}-step-${params.stepNumber}-${crypto$1.randomUUID()}`;
|
|
9326
|
-
const captureDir = path.join(process.cwd(), OM_REPRO_CAPTURE_DIR, sanitizedThreadId, runId);
|
|
9327
|
-
fs.mkdirSync(captureDir, { recursive: true });
|
|
9328
|
-
const contextMessages = params.messageList.get.all.db();
|
|
9329
|
-
const memoryContext = memory.parseMemoryRequestContext(params.args.requestContext);
|
|
9330
|
-
const preMessageIds = new Set(params.preMessages.map((message) => message.id));
|
|
9331
|
-
const postMessageIds = new Set(contextMessages.map((message) => message.id));
|
|
9332
|
-
const removedMessageIds = params.preMessages.map((message) => message.id).filter((id) => Boolean(id) && !postMessageIds.has(id));
|
|
9333
|
-
const addedMessageIds = contextMessages.map((message) => message.id).filter((id) => Boolean(id) && !preMessageIds.has(id));
|
|
9334
|
-
const idRemap = inferReproIdRemap(params.preMessages, contextMessages);
|
|
9335
|
-
const rawState = params.args.state ?? {};
|
|
9336
|
-
const sanitizedState = sanitizeCaptureState(rawState);
|
|
9337
|
-
const payloads = [
|
|
9338
|
-
{
|
|
9339
|
-
fileName: "input.json",
|
|
9340
|
-
data: {
|
|
9341
|
-
stepNumber: params.stepNumber,
|
|
9342
|
-
threadId: params.threadId,
|
|
9343
|
-
resourceId: params.resourceId,
|
|
9344
|
-
readOnly: memoryContext?.memoryConfig?.readOnly,
|
|
9345
|
-
messageCount: contextMessages.length,
|
|
9346
|
-
messageIds: contextMessages.map((message) => message.id),
|
|
9347
|
-
stateKeys: Object.keys(rawState),
|
|
9348
|
-
state: sanitizedState,
|
|
9349
|
-
args: {
|
|
9350
|
-
messages: params.args.messages,
|
|
9351
|
-
steps: params.args.steps,
|
|
9352
|
-
systemMessages: params.args.systemMessages,
|
|
9353
|
-
retryCount: params.args.retryCount,
|
|
9354
|
-
toolChoice: params.args.toolChoice,
|
|
9355
|
-
activeTools: params.args.activeTools,
|
|
9356
|
-
modelSettings: params.args.modelSettings,
|
|
9357
|
-
structuredOutput: params.args.structuredOutput
|
|
9358
|
-
}
|
|
9359
|
-
}
|
|
9360
|
-
},
|
|
9361
|
-
{
|
|
9362
|
-
fileName: "pre-state.json",
|
|
9363
|
-
data: {
|
|
9364
|
-
record: params.preRecord,
|
|
9365
|
-
bufferedChunks: params.preBufferedChunks,
|
|
9366
|
-
contextTokenCount: params.preContextTokenCount,
|
|
9367
|
-
messages: params.preMessages,
|
|
9368
|
-
messageList: params.preSerializedMessageList
|
|
9369
|
-
}
|
|
9370
|
-
},
|
|
9371
|
-
{
|
|
9372
|
-
fileName: "output.json",
|
|
9373
|
-
data: {
|
|
9374
|
-
details: params.details,
|
|
9375
|
-
messageDiff: {
|
|
9376
|
-
removedMessageIds,
|
|
9377
|
-
addedMessageIds,
|
|
9378
|
-
idRemap
|
|
9379
|
-
}
|
|
9380
|
-
}
|
|
9381
|
-
},
|
|
9382
|
-
{
|
|
9383
|
-
fileName: "post-state.json",
|
|
9384
|
-
data: {
|
|
9385
|
-
record: params.postRecord,
|
|
9386
|
-
bufferedChunks: params.postBufferedChunks,
|
|
9387
|
-
contextTokenCount: params.postContextTokenCount,
|
|
9388
|
-
messageCount: contextMessages.length,
|
|
9389
|
-
messageIds: contextMessages.map((message) => message.id),
|
|
9390
|
-
messages: contextMessages,
|
|
9391
|
-
messageList: params.messageList.serialize()
|
|
9392
|
-
}
|
|
9393
|
-
}
|
|
9394
|
-
];
|
|
9395
|
-
const captureErrors = [];
|
|
9396
|
-
for (const payload of payloads) {
|
|
9397
|
-
const serialized = safeCaptureJsonOrError(payload.data);
|
|
9398
|
-
if (serialized.ok) {
|
|
9399
|
-
fs.writeFileSync(path.join(captureDir, payload.fileName), `${JSON.stringify(serialized.value, null, 2)}
|
|
9400
|
-
`);
|
|
9401
|
-
continue;
|
|
9402
|
-
}
|
|
9403
|
-
captureErrors.push({ fileName: payload.fileName, error: serialized.error });
|
|
9404
|
-
fs.writeFileSync(
|
|
9405
|
-
path.join(captureDir, payload.fileName),
|
|
9406
|
-
`${JSON.stringify({ __captureError: serialized.error }, null, 2)}
|
|
9407
|
-
`
|
|
9408
|
-
);
|
|
9409
|
-
}
|
|
9410
|
-
if (params.observerExchange) {
|
|
9411
|
-
const serialized = safeCaptureJsonOrError(params.observerExchange);
|
|
9412
|
-
if (serialized.ok) {
|
|
9413
|
-
fs.writeFileSync(path.join(captureDir, "observer-exchange.json"), `${JSON.stringify(serialized.value, null, 2)}
|
|
9414
|
-
`);
|
|
9415
|
-
} else {
|
|
9416
|
-
captureErrors.push({ fileName: "observer-exchange.json", error: serialized.error });
|
|
9417
|
-
fs.writeFileSync(
|
|
9418
|
-
path.join(captureDir, "observer-exchange.json"),
|
|
9419
|
-
`${JSON.stringify({ __captureError: serialized.error }, null, 2)}
|
|
9420
|
-
`
|
|
9421
|
-
);
|
|
9422
|
-
}
|
|
9423
|
-
}
|
|
9424
|
-
if (captureErrors.length > 0) {
|
|
9425
|
-
fs.writeFileSync(path.join(captureDir, "capture-error.json"), `${JSON.stringify(captureErrors, null, 2)}
|
|
9426
|
-
`);
|
|
9427
|
-
params.debug?.(
|
|
9428
|
-
`[OM:repro-capture] wrote processInputStep capture with ${captureErrors.length} serialization error(s) to ${captureDir}`
|
|
9429
|
-
);
|
|
9430
|
-
return;
|
|
9431
|
-
}
|
|
9432
|
-
params.debug?.(`[OM:repro-capture] wrote processInputStep capture to ${captureDir}`);
|
|
9433
|
-
} catch (error) {
|
|
9434
|
-
params.debug?.(`[OM:repro-capture] failed to write processInputStep capture: ${String(error)}`);
|
|
9435
|
-
}
|
|
9436
|
-
}
|
|
9437
9611
|
function getOmObservabilityContext(args) {
|
|
9438
9612
|
if (!args.tracing || !args.tracingContext || !args.loggerVNext || !args.metrics) {
|
|
9439
9613
|
return void 0;
|
|
@@ -9445,6 +9619,10 @@ function getOmObservabilityContext(args) {
|
|
|
9445
9619
|
metrics: args.metrics
|
|
9446
9620
|
};
|
|
9447
9621
|
}
|
|
9622
|
+
var GATEWAY_STATE_KEY = "__isGatewayModel";
|
|
9623
|
+
function isMastraGatewayModel(model) {
|
|
9624
|
+
return model instanceof llm.ModelRouterLanguageModel && model.gatewayId === "mastra";
|
|
9625
|
+
}
|
|
9448
9626
|
var ObservationalMemoryProcessor = class {
|
|
9449
9627
|
id = "observational-memory";
|
|
9450
9628
|
name = "Observational Memory";
|
|
@@ -9480,6 +9658,11 @@ var ObservationalMemoryProcessor = class {
|
|
|
9480
9658
|
omDebug(`[OM:processInputStep:NO-CONTEXT] getThreadContext returned null \u2014 returning early`);
|
|
9481
9659
|
return messageList;
|
|
9482
9660
|
}
|
|
9661
|
+
if (isMastraGatewayModel(model)) {
|
|
9662
|
+
state[GATEWAY_STATE_KEY] = true;
|
|
9663
|
+
omDebug(`[OM:processInputStep:GATEWAY] gateway handles OM \u2014 skipping local processing`);
|
|
9664
|
+
return messageList;
|
|
9665
|
+
}
|
|
9483
9666
|
const { threadId, resourceId } = context;
|
|
9484
9667
|
const memoryContext = memory.parseMemoryRequestContext(requestContext);
|
|
9485
9668
|
const readOnly = memoryContext?.memoryConfig?.readOnly;
|
|
@@ -9596,6 +9779,7 @@ var ObservationalMemoryProcessor = class {
|
|
|
9596
9779
|
const state = _state ?? {};
|
|
9597
9780
|
const context = this.engine.getThreadContext(requestContext, messageList);
|
|
9598
9781
|
if (!context) return messageList;
|
|
9782
|
+
if (state[GATEWAY_STATE_KEY]) return messageList;
|
|
9599
9783
|
const observabilityContext = getOmObservabilityContext(args);
|
|
9600
9784
|
state.__omObservabilityContext = observabilityContext;
|
|
9601
9785
|
return this.engine.getTokenCounter().runWithModelContext(state.__omActorModelContext, async () => {
|
|
@@ -9672,5 +9856,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
|
|
|
9672
9856
|
exports.stripObservationGroups = stripObservationGroups;
|
|
9673
9857
|
exports.truncateStringByTokens = truncateStringByTokens;
|
|
9674
9858
|
exports.wrapInObservationGroup = wrapInObservationGroup;
|
|
9675
|
-
//# sourceMappingURL=chunk-
|
|
9676
|
-
//# sourceMappingURL=chunk-
|
|
9859
|
+
//# sourceMappingURL=chunk-73MTRRUV.cjs.map
|
|
9860
|
+
//# sourceMappingURL=chunk-73MTRRUV.cjs.map
|