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