@mastra/core 0.24.0 → 1.0.0-beta.1
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 +484 -139
- package/README.md +2 -3
- package/agent/message-list.d.ts +1 -0
- package/dist/action/index.d.ts +0 -2
- package/dist/action/index.d.ts.map +1 -1
- package/dist/agent/__tests__/mock-model.d.ts +3 -1
- package/dist/agent/__tests__/mock-model.d.ts.map +1 -1
- package/dist/agent/agent-legacy.d.ts +176 -0
- package/dist/agent/agent-legacy.d.ts.map +1 -0
- package/dist/agent/agent.d.ts +83 -229
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.types.d.ts +10 -25
- package/dist/agent/agent.types.d.ts.map +1 -1
- package/dist/agent/index.cjs +10 -26
- package/dist/agent/index.d.ts +1 -2
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +2 -2
- package/dist/agent/message-list/index.cjs +16 -0
- package/dist/agent/message-list/index.d.ts +77 -87
- package/dist/agent/message-list/index.d.ts.map +1 -1
- package/dist/agent/message-list/index.js +3 -0
- package/dist/agent/message-list/prompt/attachments-to-parts.d.ts +2 -2
- package/dist/agent/message-list/prompt/attachments-to-parts.d.ts.map +1 -1
- package/dist/agent/message-list/prompt/convert-to-mastra-v1.d.ts +2 -2
- package/dist/agent/message-list/prompt/download-assets.d.ts.map +1 -1
- package/dist/agent/message-list/prompt/invalid-content-error.d.ts +1 -1
- package/dist/agent/message-list/prompt/invalid-content-error.d.ts.map +1 -1
- package/dist/agent/message-list/types.d.ts +2 -1
- package/dist/agent/message-list/types.d.ts.map +1 -1
- package/dist/agent/message-list/utils/ai-v4-v5/core-model-message.d.ts +3 -2
- package/dist/agent/message-list/utils/ai-v4-v5/core-model-message.d.ts.map +1 -1
- package/dist/agent/message-list/utils/ai-v4-v5/ui-message.d.ts +3 -2
- package/dist/agent/message-list/utils/ai-v4-v5/ui-message.d.ts.map +1 -1
- package/dist/agent/message-list/utils/ai-v5/gemini-compatibility.d.ts +1 -1
- package/dist/agent/message-list/utils/ai-v5/gemini-compatibility.d.ts.map +1 -1
- package/dist/agent/message-list/utils/convert-messages.d.ts +4 -4
- package/dist/agent/message-list/utils/convert-messages.d.ts.map +1 -1
- package/dist/agent/test-utils.d.ts +2 -79
- package/dist/agent/test-utils.d.ts.map +1 -1
- package/dist/agent/trip-wire.d.ts +1 -1
- package/dist/agent/trip-wire.d.ts.map +1 -1
- package/dist/agent/types.d.ts +23 -37
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/utils.d.ts +15 -64
- package/dist/agent/utils.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +16 -20
- package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts +5 -7
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +14 -18
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts +6 -6
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/schema.d.ts +10 -12
- package/dist/agent/workflows/prepare-stream/schema.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts +3 -7
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
- package/dist/ai-sdk.types.d.ts +4705 -0
- package/dist/base.cjs +2 -2
- package/dist/base.d.ts +0 -16
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +1 -1
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.d.ts +2 -1
- package/dist/bundler/index.d.ts.map +1 -1
- package/dist/bundler/index.js +1 -1
- package/dist/cache/index.cjs +3 -3
- package/dist/cache/index.js +1 -1
- package/dist/{chunk-7J3XX4AO.cjs → chunk-2ZVKF4HP.cjs} +199 -66
- package/dist/chunk-2ZVKF4HP.cjs.map +1 -0
- package/dist/chunk-4CDL2QJT.js +649 -0
- package/dist/chunk-4CDL2QJT.js.map +1 -0
- package/dist/chunk-5WRI5ZAA.js +29 -0
- package/dist/{chunk-3HXBPDKN.js.map → chunk-5WRI5ZAA.js.map} +1 -1
- package/dist/{chunk-KAEQISOW.js → chunk-76K3IYWM.js} +5 -5
- package/dist/chunk-76K3IYWM.js.map +1 -0
- package/dist/chunk-7AHYOMHJ.js +149 -0
- package/dist/chunk-7AHYOMHJ.js.map +1 -0
- package/dist/{chunk-UZKIGB7M.cjs → chunk-BMAFVZ2D.cjs} +5 -5
- package/dist/chunk-BMAFVZ2D.cjs.map +1 -0
- package/dist/chunk-CB575O6L.cjs +12432 -0
- package/dist/chunk-CB575O6L.cjs.map +1 -0
- package/dist/{chunk-6TEQIYXV.cjs → chunk-CBAB7GOD.cjs} +15 -15
- package/dist/chunk-CBAB7GOD.cjs.map +1 -0
- package/dist/{chunk-ROS5CMJS.cjs → chunk-CD56CXVE.cjs} +63 -50
- package/dist/chunk-CD56CXVE.cjs.map +1 -0
- package/dist/{chunk-Z4RIRDU3.js → chunk-CINNK34N.js} +45 -32
- package/dist/chunk-CINNK34N.js.map +1 -0
- package/dist/{chunk-77JHIM4E.cjs → chunk-DNEURYF3.cjs} +348 -424
- package/dist/chunk-DNEURYF3.cjs.map +1 -0
- package/dist/{chunk-A5KDVZDL.cjs → chunk-DSNPWVIG.cjs} +9 -9
- package/dist/chunk-DSNPWVIG.cjs.map +1 -0
- package/dist/chunk-DZUJEN5N.cjs +32 -0
- package/dist/{chunk-EBVYYC2Q.cjs.map → chunk-DZUJEN5N.cjs.map} +1 -1
- package/dist/chunk-E7K4FTLN.cjs +273 -0
- package/dist/chunk-E7K4FTLN.cjs.map +1 -0
- package/dist/{chunk-MJMID7LX.cjs → chunk-ECFXGXWO.cjs} +609 -644
- package/dist/chunk-ECFXGXWO.cjs.map +1 -0
- package/dist/chunk-ET6UOTTU.cjs +154 -0
- package/dist/chunk-ET6UOTTU.cjs.map +1 -0
- package/dist/chunk-GGYKYORQ.cjs +2060 -0
- package/dist/chunk-GGYKYORQ.cjs.map +1 -0
- package/dist/{chunk-HLRWYUFN.js → chunk-GRBGQ2GE.js} +5 -5
- package/dist/{chunk-HLRWYUFN.js.map → chunk-GRBGQ2GE.js.map} +1 -1
- package/dist/{chunk-3VXXCPKX.js → chunk-H6CZGPZD.js} +334 -410
- package/dist/chunk-H6CZGPZD.js.map +1 -0
- package/dist/chunk-HDJFSJCK.js +2237 -0
- package/dist/chunk-HDJFSJCK.js.map +1 -0
- package/dist/{chunk-34ZCWSUA.js → chunk-I4CXL4SR.js} +6 -9
- package/dist/chunk-I4CXL4SR.js.map +1 -0
- package/dist/{chunk-3JX2Y3WH.cjs → chunk-IQO7ANVS.cjs} +18 -21
- package/dist/chunk-IQO7ANVS.cjs.map +1 -0
- package/dist/{chunk-GPWMM745.cjs → chunk-J7O6WENZ.cjs} +5 -5
- package/dist/{chunk-GPWMM745.cjs.map → chunk-J7O6WENZ.cjs.map} +1 -1
- package/dist/{chunk-PZUZNPFM.js → chunk-JJ5O45LH.js} +3 -4
- package/dist/chunk-JJ5O45LH.js.map +1 -0
- package/dist/chunk-JPGVRWWL.js +12385 -0
- package/dist/chunk-JPGVRWWL.js.map +1 -0
- package/dist/chunk-JUBFO5J3.js +15761 -0
- package/dist/chunk-JUBFO5J3.js.map +1 -0
- package/dist/{chunk-E3PG7G6E.js → chunk-JV2KH24V.js} +599 -633
- package/dist/chunk-JV2KH24V.js.map +1 -0
- package/dist/chunk-KEXGB7FK.cjs +29 -0
- package/dist/chunk-KEXGB7FK.cjs.map +1 -0
- package/dist/chunk-KIZIOFZC.js +265 -0
- package/dist/chunk-KIZIOFZC.js.map +1 -0
- package/dist/{chunk-UXG7PYML.js → chunk-KJ2SW6VA.js} +9 -9
- package/dist/chunk-KJ2SW6VA.js.map +1 -0
- package/dist/{chunk-TTELJD4F.js → chunk-L54GIUCB.js} +2 -2
- package/dist/chunk-L54GIUCB.js.map +1 -0
- package/dist/chunk-LWBQ4P4N.cjs +2240 -0
- package/dist/chunk-LWBQ4P4N.cjs.map +1 -0
- package/dist/{chunk-ABZOBBLL.cjs → chunk-MA7TEM62.cjs} +735 -562
- package/dist/chunk-MA7TEM62.cjs.map +1 -0
- package/dist/{chunk-TSNDVBUU.cjs → chunk-MR7ZWBL6.cjs} +2 -2
- package/dist/chunk-MR7ZWBL6.cjs.map +1 -0
- package/dist/chunk-MSWTA73A.cjs +15825 -0
- package/dist/chunk-MSWTA73A.cjs.map +1 -0
- package/dist/chunk-MV7KHWUT.js +2031 -0
- package/dist/chunk-MV7KHWUT.js.map +1 -0
- package/dist/{chunk-3NTOFNIU.js → chunk-OJNJA5ZI.js} +3 -3
- package/dist/{chunk-3NTOFNIU.js.map → chunk-OJNJA5ZI.js.map} +1 -1
- package/dist/chunk-QM5SRDJX.js +9022 -0
- package/dist/chunk-QM5SRDJX.js.map +1 -0
- package/dist/{chunk-WBAXXG34.cjs → chunk-QUKUN6NR.cjs} +32 -66
- package/dist/chunk-QUKUN6NR.cjs.map +1 -0
- package/dist/chunk-S6URFGCZ.js +27 -0
- package/dist/chunk-S6URFGCZ.js.map +1 -0
- package/dist/chunk-SVLMF4UZ.cjs +9033 -0
- package/dist/chunk-SVLMF4UZ.cjs.map +1 -0
- package/dist/{chunk-ZMELUU72.js → chunk-TQTAMPSC.js} +3 -3
- package/dist/chunk-TQTAMPSC.js.map +1 -0
- package/dist/{chunk-5NTO7S5I.cjs → chunk-TWH4PTDG.cjs} +2 -4
- package/dist/chunk-TWH4PTDG.cjs.map +1 -0
- package/dist/{chunk-WCHE6FJ7.js → chunk-UIZSWUKP.js} +15 -50
- package/dist/chunk-UIZSWUKP.js.map +1 -0
- package/dist/{chunk-BWGXM3D4.js → chunk-VOQ3ULMT.js} +712 -541
- package/dist/chunk-VOQ3ULMT.js.map +1 -0
- package/dist/{chunk-MCASUJWY.cjs → chunk-VOY2RXOC.cjs} +36 -59
- package/dist/chunk-VOY2RXOC.cjs.map +1 -0
- package/dist/{chunk-FHVFGVIO.js → chunk-W7UH2PWL.js} +189 -56
- package/dist/chunk-W7UH2PWL.js.map +1 -0
- package/dist/chunk-WM6CK2F3.cjs +674 -0
- package/dist/chunk-WM6CK2F3.cjs.map +1 -0
- package/dist/{chunk-PFXXH2RP.js → chunk-X7JMA3IY.js} +15 -15
- package/dist/chunk-X7JMA3IY.js.map +1 -0
- package/dist/{chunk-NR77P3TK.js → chunk-XEVG546F.js} +14 -37
- package/dist/chunk-XEVG546F.js.map +1 -0
- package/dist/{chunk-QFF5JUKT.cjs → chunk-Y63IFHEZ.cjs} +4 -4
- package/dist/chunk-Y63IFHEZ.cjs.map +1 -0
- package/dist/{chunk-B7V6NYWH.cjs → chunk-Y6ROD72V.cjs} +4 -4
- package/dist/{chunk-B7V6NYWH.cjs.map → chunk-Y6ROD72V.cjs.map} +1 -1
- package/dist/deployer/index.cjs +8 -6
- package/dist/deployer/index.cjs.map +1 -1
- package/dist/deployer/index.js +10 -1
- package/dist/deployer/index.js.map +1 -1
- package/dist/di/index.cjs +3 -3
- package/dist/di/index.d.ts +1 -1
- package/dist/di/index.js +1 -1
- package/dist/error/index.cjs +6 -6
- package/dist/error/index.d.ts +0 -1
- package/dist/error/index.d.ts.map +1 -1
- package/dist/error/index.js +1 -1
- package/dist/{scores → evals}/base.d.ts +20 -18
- package/dist/evals/base.d.ts.map +1 -0
- package/dist/{scores → evals}/base.test-utils.d.ts +25 -25
- package/dist/evals/base.test-utils.d.ts.map +1 -0
- package/dist/{scores → evals}/hooks.d.ts +3 -3
- package/dist/evals/hooks.d.ts.map +1 -0
- package/dist/evals/index.cjs +37 -0
- package/dist/evals/index.d.ts +4 -0
- package/dist/evals/index.d.ts.map +1 -0
- package/dist/evals/index.js +4 -0
- package/dist/{scores/run-experiment → evals/run}/index.d.ts +18 -18
- package/dist/evals/run/index.d.ts.map +1 -0
- package/dist/evals/run/scorerAccumulator.d.ts.map +1 -0
- package/dist/{scores → evals}/scoreTraces/index.cjs +79 -99
- package/dist/evals/scoreTraces/index.cjs.map +1 -0
- package/dist/evals/scoreTraces/index.d.ts.map +1 -0
- package/dist/{scores → evals}/scoreTraces/index.js +72 -92
- package/dist/evals/scoreTraces/index.js.map +1 -0
- package/dist/{scores → evals}/scoreTraces/scoreTraces.d.ts +2 -2
- package/dist/evals/scoreTraces/scoreTraces.d.ts.map +1 -0
- package/dist/{scores → evals}/scoreTraces/scoreTracesWorkflow.d.ts +11 -11
- package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -0
- package/dist/{scores → evals}/scoreTraces/utils.d.ts +7 -7
- package/dist/evals/scoreTraces/utils.d.ts.map +1 -0
- package/dist/{scores → evals}/types.d.ts +22 -22
- package/dist/evals/types.d.ts.map +1 -0
- package/dist/features/index.cjs +8 -0
- package/dist/features/index.cjs.map +1 -0
- package/dist/features/index.d.ts +17 -0
- package/dist/features/index.d.ts.map +1 -0
- package/dist/features/index.js +6 -0
- package/dist/features/index.js.map +1 -0
- package/dist/hooks/index.cjs +4 -4
- package/dist/hooks/index.d.ts +1 -27
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/index.cjs +2 -340
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -113
- package/dist/index.js.map +1 -1
- package/dist/integration/index.cjs +87 -10
- package/dist/integration/index.cjs.map +1 -1
- package/dist/integration/index.js +88 -1
- package/dist/integration/index.js.map +1 -1
- package/dist/integration/integration.d.ts +3 -3
- package/dist/integration/integration.d.ts.map +1 -1
- package/dist/llm/index.cjs +7 -7
- package/dist/llm/index.d.ts +5 -6
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +1 -1
- package/dist/llm/model/base.types.d.ts +6 -7
- package/dist/llm/model/base.types.d.ts.map +1 -1
- package/dist/llm/model/gateways/constants.d.ts.map +1 -1
- package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
- package/dist/llm/model/model.d.ts +7 -7
- package/dist/llm/model/model.d.ts.map +1 -1
- package/dist/llm/model/model.loop.d.ts +1 -1
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/model.loop.types.d.ts +3 -3
- package/dist/llm/model/model.loop.types.d.ts.map +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +80 -17
- package/dist/llm/model/resolve-model.d.ts +8 -8
- package/dist/llm/model/shared.types.d.ts +2 -2
- package/dist/llm/model/shared.types.d.ts.map +1 -1
- package/dist/logger/constants.d.ts +1 -1
- package/dist/logger/default-logger.d.ts +2 -2
- package/dist/logger/default-logger.d.ts.map +1 -1
- package/dist/logger/index.cjs +11 -11
- package/dist/logger/index.js +2 -2
- package/dist/logger/logger.d.ts +4 -4
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/multi-logger.d.ts +2 -2
- package/dist/logger/multi-logger.d.ts.map +1 -1
- package/dist/logger/transport.d.ts +3 -3
- package/dist/logger/transport.d.ts.map +1 -1
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/loop.d.ts +1 -1
- package/dist/loop/loop.d.ts.map +1 -1
- package/dist/loop/network/index.d.ts +15 -15
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/test-utils/generateText.d.ts.map +1 -1
- package/dist/loop/test-utils/options.d.ts.map +1 -1
- package/dist/loop/test-utils/resultObject.d.ts.map +1 -1
- package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
- package/dist/loop/types.d.ts +4 -7
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +55 -55
- package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +38 -38
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +20 -20
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +2 -2
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts +55 -55
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/loop/workflows/schema.d.ts +19 -20
- package/dist/loop/workflows/schema.d.ts.map +1 -1
- package/dist/loop/workflows/stream.d.ts +1 -1
- package/dist/loop/workflows/stream.d.ts.map +1 -1
- package/dist/mastra/hooks.d.ts +2 -2
- package/dist/mastra/hooks.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +389 -180
- package/dist/mastra/index.d.ts.map +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/mcp/index.cjs +41 -4
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.d.ts +6 -4
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +39 -2
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/types.d.ts +0 -15
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/memory/index.cjs +327 -13
- package/dist/memory/index.cjs.map +1 -1
- package/dist/memory/index.d.ts +1 -0
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +327 -1
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/memory.d.ts +33 -57
- package/dist/memory/memory.d.ts.map +1 -1
- package/dist/memory/mock.d.ts +61 -0
- package/dist/memory/mock.d.ts.map +1 -0
- package/dist/memory/types.d.ts +48 -45
- package/dist/memory/types.d.ts.map +1 -1
- package/dist/models-dev-DNBKXHT4.js +3 -0
- package/dist/{models-dev-4VGIWYS3.js.map → models-dev-DNBKXHT4.js.map} +1 -1
- package/dist/models-dev-YBEEQIX6.cjs +12 -0
- package/dist/{models-dev-AXZASLL2.cjs.map → models-dev-YBEEQIX6.cjs.map} +1 -1
- package/dist/netlify-7G2L5VSH.js +3 -0
- package/dist/{netlify-VJXBII33.js.map → netlify-7G2L5VSH.js.map} +1 -1
- package/dist/netlify-GWNGSIRZ.cjs +12 -0
- package/dist/{netlify-TX6V7SJJ.cjs.map → netlify-GWNGSIRZ.cjs.map} +1 -1
- package/dist/{ai-tracing → observability}/context.d.ts +5 -5
- package/dist/observability/context.d.ts.map +1 -0
- package/dist/observability/index.cjs +36 -0
- package/dist/observability/index.d.ts +11 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +3 -0
- package/dist/observability/no-op.d.ts +22 -0
- package/dist/observability/no-op.d.ts.map +1 -0
- package/dist/observability/types/index.d.ts +2 -0
- package/dist/observability/types/index.d.ts.map +1 -0
- package/dist/{ai-tracing/types.d.ts → observability/types/tracing.d.ts} +161 -107
- package/dist/observability/types/tracing.d.ts.map +1 -0
- package/dist/observability/utils.d.ts +12 -0
- package/dist/observability/utils.d.ts.map +1 -0
- package/dist/processors/index.cjs +11 -11
- package/dist/processors/index.d.ts +10 -9
- package/dist/processors/index.d.ts.map +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/processors/batch-parts.d.ts +2 -1
- package/dist/processors/processors/batch-parts.d.ts.map +1 -1
- package/dist/processors/processors/language-detector.d.ts +6 -5
- package/dist/processors/processors/language-detector.d.ts.map +1 -1
- package/dist/processors/processors/moderation.d.ts +8 -7
- package/dist/processors/processors/moderation.d.ts.map +1 -1
- package/dist/processors/processors/pii-detector.d.ts +8 -7
- package/dist/processors/processors/pii-detector.d.ts.map +1 -1
- package/dist/processors/processors/prompt-injection-detector.d.ts +6 -5
- package/dist/processors/processors/prompt-injection-detector.d.ts.map +1 -1
- package/dist/processors/processors/structured-output.d.ts +3 -2
- package/dist/processors/processors/structured-output.d.ts.map +1 -1
- package/dist/processors/processors/system-prompt-scrubber.d.ts +6 -5
- package/dist/processors/processors/system-prompt-scrubber.d.ts.map +1 -1
- package/dist/processors/processors/token-limiter.d.ts +5 -4
- package/dist/processors/processors/token-limiter.d.ts.map +1 -1
- package/dist/processors/processors/unicode-normalizer.d.ts +5 -4
- package/dist/processors/processors/unicode-normalizer.d.ts.map +1 -1
- package/dist/processors/runner.d.ts +5 -5
- package/dist/processors/runner.d.ts.map +1 -1
- package/dist/provider-registry.json +175 -42
- package/dist/{registry-generator-DXRSYYYT.js → registry-generator-H4YNODDH.js} +2 -2
- package/dist/{registry-generator-DXRSYYYT.js.map → registry-generator-H4YNODDH.js.map} +1 -1
- package/dist/{registry-generator-6WVOHM2L.cjs → registry-generator-MK63POJO.cjs} +2 -2
- package/dist/{registry-generator-6WVOHM2L.cjs.map → registry-generator-MK63POJO.cjs.map} +1 -1
- package/dist/relevance/index.cjs +47 -13
- package/dist/relevance/index.cjs.map +1 -1
- package/dist/relevance/index.d.ts +0 -1
- package/dist/relevance/index.d.ts.map +1 -1
- package/dist/relevance/index.js +49 -1
- package/dist/relevance/index.js.map +1 -1
- package/dist/relevance/mastra-agent/index.d.ts.map +1 -1
- package/dist/request-context/index.cjs +12 -0
- package/dist/{runtime-context → request-context}/index.d.ts +1 -1
- package/dist/{runtime-context → request-context}/index.d.ts.map +1 -1
- package/dist/request-context/index.js +3 -0
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/index.cjs +9 -25
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.js +4 -21
- package/dist/server/index.js.map +1 -1
- package/dist/server/types.d.ts +3 -3
- package/dist/server/types.d.ts.map +1 -1
- package/dist/storage/base.d.ts +75 -143
- package/dist/storage/base.d.ts.map +1 -1
- package/dist/storage/constants.d.ts +3 -4
- package/dist/storage/constants.d.ts.map +1 -1
- package/dist/storage/domains/index.d.ts +0 -2
- package/dist/storage/domains/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/base.d.ts +19 -56
- package/dist/storage/domains/memory/base.d.ts.map +1 -1
- package/dist/storage/domains/memory/inmemory.d.ts +15 -35
- package/dist/storage/domains/memory/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/observability/base.d.ts +24 -24
- package/dist/storage/domains/observability/base.d.ts.map +1 -1
- package/dist/storage/domains/observability/inmemory.d.ts +18 -18
- package/dist/storage/domains/observability/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/operations/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/scores/base.d.ts +5 -5
- package/dist/storage/domains/scores/base.d.ts.map +1 -1
- package/dist/storage/domains/scores/inmemory.d.ts +5 -5
- package/dist/storage/domains/scores/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/workflows/base.d.ts +4 -11
- package/dist/storage/domains/workflows/base.d.ts.map +1 -1
- package/dist/storage/domains/workflows/inmemory.d.ts +4 -11
- package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +74 -1775
- package/dist/storage/index.cjs.map +1 -1
- package/dist/storage/index.js +1 -1744
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/mock.d.ts +35 -92
- package/dist/storage/mock.d.ts.map +1 -1
- package/dist/storage/types.d.ts +77 -75
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/stream/MastraAgentNetworkStream.d.ts +4 -2
- package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
- package/dist/stream/RunOutput.d.ts +1 -0
- package/dist/stream/RunOutput.d.ts.map +1 -1
- package/dist/stream/aisdk/v4/input.d.ts +1 -1
- package/dist/stream/aisdk/v4/input.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/execute.d.ts +4 -11
- package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/output.d.ts +1 -1
- package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
- package/dist/stream/base/output.d.ts +1 -1
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/index.cjs +11 -11
- package/dist/stream/index.d.ts +1 -1
- package/dist/stream/index.d.ts.map +1 -1
- package/dist/stream/index.js +2 -2
- package/dist/stream/types.d.ts +2 -6
- package/dist/stream/types.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.cjs +8 -8
- package/dist/test-utils/llm-mock.cjs.map +1 -1
- package/dist/test-utils/llm-mock.d.ts +1 -1
- package/dist/test-utils/llm-mock.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.js +3 -3
- package/dist/test-utils/llm-mock.js.map +1 -1
- package/dist/tools/index.cjs +4 -4
- package/dist/tools/index.js +1 -1
- package/dist/tools/is-vercel-tool.cjs +2 -2
- package/dist/tools/is-vercel-tool.js +1 -1
- package/dist/tools/tool-builder/builder.d.ts +3 -71
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/tools/tool.d.ts +25 -25
- package/dist/tools/tool.d.ts.map +1 -1
- package/dist/tools/types.d.ts +102 -11
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/validation.d.ts +4 -3
- package/dist/tools/validation.d.ts.map +1 -1
- package/dist/tts/index.cjs +12 -6
- package/dist/tts/index.cjs.map +1 -1
- package/dist/tts/index.d.ts +0 -1
- package/dist/tts/index.d.ts.map +1 -1
- package/dist/tts/index.js +14 -1
- package/dist/tts/index.js.map +1 -1
- package/dist/types/dynamic-argument.d.ts +3 -3
- package/dist/utils/fetchWithRetry.d.ts +9 -0
- package/dist/utils/fetchWithRetry.d.ts.map +1 -0
- package/dist/utils.cjs +33 -17
- package/dist/utils.d.ts +39 -6
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/vector/embed.d.ts +1 -1
- package/dist/vector/embed.d.ts.map +1 -1
- package/dist/vector/index.cjs +80 -8
- package/dist/vector/index.cjs.map +1 -1
- package/dist/vector/index.js +80 -1
- package/dist/vector/index.js.map +1 -1
- package/dist/vector/vector.d.ts +5 -2
- package/dist/vector/vector.d.ts.map +1 -1
- package/dist/voice/composite-voice.d.ts +1 -7
- package/dist/voice/composite-voice.d.ts.map +1 -1
- package/dist/voice/index.cjs +4 -4
- package/dist/voice/index.js +1 -1
- package/dist/voice/voice.d.ts +0 -1
- package/dist/voice/voice.d.ts.map +1 -1
- package/dist/workflows/default.d.ts +35 -43
- package/dist/workflows/default.d.ts.map +1 -1
- package/dist/workflows/evented/execution-engine.d.ts +5 -3
- package/dist/workflows/evented/execution-engine.d.ts.map +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/evented/step-executor.d.ts +15 -13
- package/dist/workflows/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts +5 -5
- package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/loop.d.ts +3 -3
- package/dist/workflows/evented/workflow-event-processor/loop.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/parallel.d.ts +2 -2
- package/dist/workflows/evented/workflow-event-processor/sleep.d.ts +2 -2
- package/dist/workflows/evented/workflow-event-processor/utils.d.ts +2 -7
- package/dist/workflows/evented/workflow-event-processor/utils.d.ts.map +1 -1
- package/dist/workflows/evented/workflow.d.ts +11 -14
- package/dist/workflows/evented/workflow.d.ts.map +1 -1
- package/dist/workflows/execution-engine.d.ts +6 -6
- package/dist/workflows/execution-engine.d.ts.map +1 -1
- package/dist/workflows/index.cjs +22 -14
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/step.d.ts +5 -5
- package/dist/workflows/step.d.ts.map +1 -1
- package/dist/workflows/types.d.ts +21 -44
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/utils.d.ts +14 -0
- package/dist/workflows/utils.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +74 -64
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/evals/scoreTraces.d.ts +1 -0
- package/evals.d.ts +1 -0
- package/features.d.ts +1 -0
- package/observability.d.ts +1 -0
- package/package.json +49 -64
- package/request-context.d.ts +1 -0
- package/src/_types/ai-sdk.types.d.ts +4705 -0
- package/src/llm/model/provider-types.generated.d.ts +80 -17
- package/agent/input-processor/processors.d.ts +0 -1
- package/ai-tracing.d.ts +0 -1
- package/dist/agent/index.warning.d.ts +0 -13
- package/dist/agent/index.warning.d.ts.map +0 -1
- package/dist/agent/input-processor/index.cjs +0 -28
- package/dist/agent/input-processor/index.d.ts +0 -10
- package/dist/agent/input-processor/index.d.ts.map +0 -1
- package/dist/agent/input-processor/index.js +0 -3
- package/dist/agent/input-processor/processors/index.d.ts +0 -6
- package/dist/agent/input-processor/processors/index.d.ts.map +0 -1
- package/dist/agent/input-processor/processors/language-detector.d.ts +0 -18
- package/dist/agent/input-processor/processors/language-detector.d.ts.map +0 -1
- package/dist/agent/input-processor/processors/moderation.d.ts +0 -18
- package/dist/agent/input-processor/processors/moderation.d.ts.map +0 -1
- package/dist/agent/input-processor/processors/pii-detector.d.ts +0 -18
- package/dist/agent/input-processor/processors/pii-detector.d.ts.map +0 -1
- package/dist/agent/input-processor/processors/prompt-injection-detector.d.ts +0 -18
- package/dist/agent/input-processor/processors/prompt-injection-detector.d.ts.map +0 -1
- package/dist/agent/input-processor/processors/unicode-normalizer.d.ts +0 -18
- package/dist/agent/input-processor/processors/unicode-normalizer.d.ts.map +0 -1
- package/dist/ai-tracing/context.d.ts.map +0 -1
- package/dist/ai-tracing/exporters/base.d.ts +0 -111
- package/dist/ai-tracing/exporters/base.d.ts.map +0 -1
- package/dist/ai-tracing/exporters/cloud.d.ts +0 -30
- package/dist/ai-tracing/exporters/cloud.d.ts.map +0 -1
- package/dist/ai-tracing/exporters/console.d.ts +0 -10
- package/dist/ai-tracing/exporters/console.d.ts.map +0 -1
- package/dist/ai-tracing/exporters/default.d.ts +0 -98
- package/dist/ai-tracing/exporters/default.d.ts.map +0 -1
- package/dist/ai-tracing/exporters/index.d.ts +0 -9
- package/dist/ai-tracing/exporters/index.d.ts.map +0 -1
- package/dist/ai-tracing/index.cjs +0 -148
- package/dist/ai-tracing/index.d.ts +0 -13
- package/dist/ai-tracing/index.d.ts.map +0 -1
- package/dist/ai-tracing/index.js +0 -3
- package/dist/ai-tracing/model-tracing.d.ts +0 -63
- package/dist/ai-tracing/model-tracing.d.ts.map +0 -1
- package/dist/ai-tracing/registry.d.ts +0 -51
- package/dist/ai-tracing/registry.d.ts.map +0 -1
- package/dist/ai-tracing/span_processors/index.d.ts +0 -5
- package/dist/ai-tracing/span_processors/index.d.ts.map +0 -1
- package/dist/ai-tracing/span_processors/sensitive-data-filter.d.ts +0 -85
- package/dist/ai-tracing/span_processors/sensitive-data-filter.d.ts.map +0 -1
- package/dist/ai-tracing/spans/base.d.ts +0 -65
- package/dist/ai-tracing/spans/base.d.ts.map +0 -1
- package/dist/ai-tracing/spans/default.d.ts +0 -13
- package/dist/ai-tracing/spans/default.d.ts.map +0 -1
- package/dist/ai-tracing/spans/index.d.ts +0 -7
- package/dist/ai-tracing/spans/index.d.ts.map +0 -1
- package/dist/ai-tracing/spans/no-op.d.ts +0 -15
- package/dist/ai-tracing/spans/no-op.d.ts.map +0 -1
- package/dist/ai-tracing/tracers/base.d.ts +0 -105
- package/dist/ai-tracing/tracers/base.d.ts.map +0 -1
- package/dist/ai-tracing/tracers/default.d.ts +0 -7
- package/dist/ai-tracing/tracers/default.d.ts.map +0 -1
- package/dist/ai-tracing/tracers/index.d.ts +0 -6
- package/dist/ai-tracing/tracers/index.d.ts.map +0 -1
- package/dist/ai-tracing/types.d.ts.map +0 -1
- package/dist/ai-tracing/utils.d.ts +0 -68
- package/dist/ai-tracing/utils.d.ts.map +0 -1
- package/dist/base.warning.d.ts +0 -9
- package/dist/base.warning.d.ts.map +0 -1
- package/dist/bundler/index.warning.d.ts +0 -9
- package/dist/bundler/index.warning.d.ts.map +0 -1
- package/dist/chunk-253FBVD4.cjs +0 -1303
- package/dist/chunk-253FBVD4.cjs.map +0 -1
- package/dist/chunk-2B3VLGTH.js +0 -87
- package/dist/chunk-2B3VLGTH.js.map +0 -1
- package/dist/chunk-34ZCWSUA.js.map +0 -1
- package/dist/chunk-3HXBPDKN.js +0 -105
- package/dist/chunk-3JX2Y3WH.cjs.map +0 -1
- package/dist/chunk-3VXXCPKX.js.map +0 -1
- package/dist/chunk-4R2TBRS7.cjs +0 -191
- package/dist/chunk-4R2TBRS7.cjs.map +0 -1
- package/dist/chunk-5NTO7S5I.cjs.map +0 -1
- package/dist/chunk-6C7VGVK4.js +0 -267
- package/dist/chunk-6C7VGVK4.js.map +0 -1
- package/dist/chunk-6KOL2B3A.cjs +0 -75
- package/dist/chunk-6KOL2B3A.cjs.map +0 -1
- package/dist/chunk-6TEQIYXV.cjs.map +0 -1
- package/dist/chunk-6VOPKVYH.cjs +0 -57
- package/dist/chunk-6VOPKVYH.cjs.map +0 -1
- package/dist/chunk-77JHIM4E.cjs.map +0 -1
- package/dist/chunk-7J3XX4AO.cjs.map +0 -1
- package/dist/chunk-A5KDVZDL.cjs.map +0 -1
- package/dist/chunk-ABZOBBLL.cjs.map +0 -1
- package/dist/chunk-AQGLVU53.cjs +0 -603
- package/dist/chunk-AQGLVU53.cjs.map +0 -1
- package/dist/chunk-BLUDYAPI.js +0 -596
- package/dist/chunk-BLUDYAPI.js.map +0 -1
- package/dist/chunk-BWGXM3D4.js.map +0 -1
- package/dist/chunk-C7OVZMPW.cjs +0 -91
- package/dist/chunk-C7OVZMPW.cjs.map +0 -1
- package/dist/chunk-DMBN72QF.cjs +0 -39
- package/dist/chunk-DMBN72QF.cjs.map +0 -1
- package/dist/chunk-DTTOVV72.js +0 -2880
- package/dist/chunk-DTTOVV72.js.map +0 -1
- package/dist/chunk-E3PG7G6E.js.map +0 -1
- package/dist/chunk-EBVYYC2Q.cjs +0 -111
- package/dist/chunk-FHVFGVIO.js.map +0 -1
- package/dist/chunk-GB5BIA4V.js +0 -167
- package/dist/chunk-GB5BIA4V.js.map +0 -1
- package/dist/chunk-HEQTUMUA.cjs +0 -271
- package/dist/chunk-HEQTUMUA.cjs.map +0 -1
- package/dist/chunk-HF3GZRFP.cjs +0 -9
- package/dist/chunk-HF3GZRFP.cjs.map +0 -1
- package/dist/chunk-JVV5LREI.js +0 -431
- package/dist/chunk-JVV5LREI.js.map +0 -1
- package/dist/chunk-KAEQISOW.js.map +0 -1
- package/dist/chunk-KDX3ZMQ2.js +0 -12
- package/dist/chunk-KDX3ZMQ2.js.map +0 -1
- package/dist/chunk-LG5B3KIW.js +0 -1215
- package/dist/chunk-LG5B3KIW.js.map +0 -1
- package/dist/chunk-LZUSZT7R.cjs +0 -170
- package/dist/chunk-LZUSZT7R.cjs.map +0 -1
- package/dist/chunk-MCASUJWY.cjs.map +0 -1
- package/dist/chunk-MJMID7LX.cjs.map +0 -1
- package/dist/chunk-MKCC5K77.js +0 -90
- package/dist/chunk-MKCC5K77.js.map +0 -1
- package/dist/chunk-NPNGPMT2.js +0 -39
- package/dist/chunk-NPNGPMT2.js.map +0 -1
- package/dist/chunk-NR77P3TK.js.map +0 -1
- package/dist/chunk-NUAURT4I.cjs +0 -82
- package/dist/chunk-NUAURT4I.cjs.map +0 -1
- package/dist/chunk-OIT3PCWA.js +0 -72
- package/dist/chunk-OIT3PCWA.js.map +0 -1
- package/dist/chunk-P35FNLTQ.cjs +0 -2936
- package/dist/chunk-P35FNLTQ.cjs.map +0 -1
- package/dist/chunk-PFXXH2RP.js.map +0 -1
- package/dist/chunk-PZUZNPFM.js.map +0 -1
- package/dist/chunk-QFF5JUKT.cjs.map +0 -1
- package/dist/chunk-RKXWLG33.js +0 -7
- package/dist/chunk-RKXWLG33.js.map +0 -1
- package/dist/chunk-ROS5CMJS.cjs.map +0 -1
- package/dist/chunk-SJMKDSRF.js +0 -179
- package/dist/chunk-SJMKDSRF.js.map +0 -1
- package/dist/chunk-SSULK22X.cjs +0 -14
- package/dist/chunk-SSULK22X.cjs.map +0 -1
- package/dist/chunk-TSNDVBUU.cjs.map +0 -1
- package/dist/chunk-TTELJD4F.js.map +0 -1
- package/dist/chunk-TX4TTPYJ.cjs +0 -436
- package/dist/chunk-TX4TTPYJ.cjs.map +0 -1
- package/dist/chunk-UXG7PYML.js.map +0 -1
- package/dist/chunk-UZKIGB7M.cjs.map +0 -1
- package/dist/chunk-VF676YCO.cjs +0 -150
- package/dist/chunk-VF676YCO.cjs.map +0 -1
- package/dist/chunk-VQASQG5D.js +0 -55
- package/dist/chunk-VQASQG5D.js.map +0 -1
- package/dist/chunk-WBAXXG34.cjs.map +0 -1
- package/dist/chunk-WCHE6FJ7.js.map +0 -1
- package/dist/chunk-WM4RO23J.js +0 -145
- package/dist/chunk-WM4RO23J.js.map +0 -1
- package/dist/chunk-Z4RIRDU3.js.map +0 -1
- package/dist/chunk-ZABG3SZ2.cjs +0 -93
- package/dist/chunk-ZABG3SZ2.cjs.map +0 -1
- package/dist/chunk-ZISECZZO.js +0 -72
- package/dist/chunk-ZISECZZO.js.map +0 -1
- package/dist/chunk-ZMELUU72.js.map +0 -1
- package/dist/deployer/index.warning.d.ts +0 -9
- package/dist/deployer/index.warning.d.ts.map +0 -1
- package/dist/eval/evaluation.d.ts +0 -14
- package/dist/eval/evaluation.d.ts.map +0 -1
- package/dist/eval/index.cjs +0 -16
- package/dist/eval/index.d.ts +0 -4
- package/dist/eval/index.d.ts.map +0 -1
- package/dist/eval/index.js +0 -3
- package/dist/eval/metric.d.ts +0 -8
- package/dist/eval/metric.d.ts.map +0 -1
- package/dist/eval/types.d.ts +0 -9
- package/dist/eval/types.d.ts.map +0 -1
- package/dist/integration/index.warning.d.ts +0 -3
- package/dist/integration/index.warning.d.ts.map +0 -1
- package/dist/integration/integration.warning.d.ts +0 -5
- package/dist/integration/integration.warning.d.ts.map +0 -1
- package/dist/integration/openapi-toolset.warning.d.ts +0 -5
- package/dist/integration/openapi-toolset.warning.d.ts.map +0 -1
- package/dist/loop/telemetry/index.d.ts +0 -36
- package/dist/loop/telemetry/index.d.ts.map +0 -1
- package/dist/loop/telemetry/noop.d.ts +0 -3
- package/dist/loop/telemetry/noop.d.ts.map +0 -1
- package/dist/loop/test-utils/mockTracer.d.ts +0 -47
- package/dist/loop/test-utils/mockTracer.d.ts.map +0 -1
- package/dist/loop/test-utils/telemetry.d.ts +0 -6
- package/dist/loop/test-utils/telemetry.d.ts.map +0 -1
- package/dist/memory/index.warning.d.ts +0 -6
- package/dist/memory/index.warning.d.ts.map +0 -1
- package/dist/models-dev-4VGIWYS3.js +0 -3
- package/dist/models-dev-AXZASLL2.cjs +0 -12
- package/dist/netlify-TX6V7SJJ.cjs +0 -12
- package/dist/netlify-VJXBII33.js +0 -3
- package/dist/relevance/cohere/index.d.ts +0 -9
- package/dist/relevance/cohere/index.d.ts.map +0 -1
- package/dist/runtime-context/index.cjs +0 -12
- package/dist/runtime-context/index.js +0 -3
- package/dist/scores/base.d.ts.map +0 -1
- package/dist/scores/base.test-utils.d.ts.map +0 -1
- package/dist/scores/hooks.d.ts.map +0 -1
- package/dist/scores/index.cjs +0 -37
- package/dist/scores/index.cjs.map +0 -1
- package/dist/scores/index.d.ts +0 -4
- package/dist/scores/index.d.ts.map +0 -1
- package/dist/scores/index.js +0 -4
- package/dist/scores/index.js.map +0 -1
- package/dist/scores/run-experiment/index.d.ts.map +0 -1
- package/dist/scores/run-experiment/scorerAccumulator.d.ts.map +0 -1
- package/dist/scores/scoreTraces/index.cjs.map +0 -1
- package/dist/scores/scoreTraces/index.d.ts.map +0 -1
- package/dist/scores/scoreTraces/index.js.map +0 -1
- package/dist/scores/scoreTraces/scoreTraces.d.ts.map +0 -1
- package/dist/scores/scoreTraces/scoreTracesWorkflow.d.ts.map +0 -1
- package/dist/scores/scoreTraces/utils.d.ts.map +0 -1
- package/dist/scores/types.d.ts.map +0 -1
- package/dist/storage/base.warning.d.ts +0 -8
- package/dist/storage/base.warning.d.ts.map +0 -1
- package/dist/storage/domains/legacy-evals/base.d.ts +0 -13
- package/dist/storage/domains/legacy-evals/base.d.ts.map +0 -1
- package/dist/storage/domains/legacy-evals/index.d.ts +0 -2
- package/dist/storage/domains/legacy-evals/index.d.ts.map +0 -1
- package/dist/storage/domains/legacy-evals/inmemory.d.ts +0 -17
- package/dist/storage/domains/legacy-evals/inmemory.d.ts.map +0 -1
- package/dist/storage/domains/traces/base.d.ts +0 -14
- package/dist/storage/domains/traces/base.d.ts.map +0 -1
- package/dist/storage/domains/traces/index.d.ts +0 -3
- package/dist/storage/domains/traces/index.d.ts.map +0 -1
- package/dist/storage/domains/traces/inmemory.d.ts +0 -22
- package/dist/storage/domains/traces/inmemory.d.ts.map +0 -1
- package/dist/storage/index.warning.d.ts +0 -3
- package/dist/storage/index.warning.d.ts.map +0 -1
- package/dist/telemetry/composite-exporter.d.ts +0 -10
- package/dist/telemetry/composite-exporter.d.ts.map +0 -1
- package/dist/telemetry/index.cjs +0 -32
- package/dist/telemetry/index.cjs.map +0 -1
- package/dist/telemetry/index.d.ts +0 -6
- package/dist/telemetry/index.d.ts.map +0 -1
- package/dist/telemetry/index.js +0 -3
- package/dist/telemetry/index.js.map +0 -1
- package/dist/telemetry/otel-vendor.cjs +0 -105
- package/dist/telemetry/otel-vendor.cjs.map +0 -1
- package/dist/telemetry/otel-vendor.d.ts +0 -11
- package/dist/telemetry/otel-vendor.d.ts.map +0 -1
- package/dist/telemetry/otel-vendor.js +0 -59
- package/dist/telemetry/otel-vendor.js.map +0 -1
- package/dist/telemetry/storage-exporter.d.ts +0 -21
- package/dist/telemetry/storage-exporter.d.ts.map +0 -1
- package/dist/telemetry/telemetry.d.ts +0 -59
- package/dist/telemetry/telemetry.d.ts.map +0 -1
- package/dist/telemetry/telemetry.decorators.d.ts +0 -15
- package/dist/telemetry/telemetry.decorators.d.ts.map +0 -1
- package/dist/telemetry/types.d.ts +0 -74
- package/dist/telemetry/types.d.ts.map +0 -1
- package/dist/telemetry/utility.d.ts +0 -15
- package/dist/telemetry/utility.d.ts.map +0 -1
- package/dist/tools/index.warning.d.ts +0 -8
- package/dist/tools/index.warning.d.ts.map +0 -1
- package/dist/tts/index.warning.d.ts +0 -7
- package/dist/tts/index.warning.d.ts.map +0 -1
- package/dist/vector/index.warning.d.ts +0 -6
- package/dist/vector/index.warning.d.ts.map +0 -1
- package/dist/workflows/index.warning.d.ts +0 -6
- package/dist/workflows/index.warning.d.ts.map +0 -1
- package/dist/workflows/legacy/index.cjs +0 -92
- package/dist/workflows/legacy/index.cjs.map +0 -1
- package/dist/workflows/legacy/index.d.ts +0 -5
- package/dist/workflows/legacy/index.d.ts.map +0 -1
- package/dist/workflows/legacy/index.js +0 -3
- package/dist/workflows/legacy/index.js.map +0 -1
- package/dist/workflows/legacy/machine.d.ts +0 -386
- package/dist/workflows/legacy/machine.d.ts.map +0 -1
- package/dist/workflows/legacy/step.d.ts +0 -15
- package/dist/workflows/legacy/step.d.ts.map +0 -1
- package/dist/workflows/legacy/types.d.ts +0 -397
- package/dist/workflows/legacy/types.d.ts.map +0 -1
- package/dist/workflows/legacy/utils.d.ts +0 -68
- package/dist/workflows/legacy/utils.d.ts.map +0 -1
- package/dist/workflows/legacy/workflow-instance.d.ts +0 -97
- package/dist/workflows/legacy/workflow-instance.d.ts.map +0 -1
- package/dist/workflows/legacy/workflow.d.ts +0 -109
- package/dist/workflows/legacy/workflow.d.ts.map +0 -1
- package/dist/workflows/workflow.warning.d.ts +0 -9
- package/dist/workflows/workflow.warning.d.ts.map +0 -1
- package/eval.d.ts +0 -1
- package/runtime-context.d.ts +0 -1
- package/scores/scoreTraces.d.ts +0 -1
- package/scores.d.ts +0 -1
- package/telemetry/otel-vendor.d.ts +0 -1
- package/telemetry.d.ts +0 -1
- package/workflows/legacy.d.ts +0 -1
- /package/dist/agent/{input-processor → message-list}/index.cjs.map +0 -0
- /package/dist/agent/{input-processor → message-list}/index.js.map +0 -0
- /package/dist/{ai-tracing → evals}/index.cjs.map +0 -0
- /package/dist/{ai-tracing → evals}/index.js.map +0 -0
- /package/dist/{scores/run-experiment → evals/run}/scorerAccumulator.d.ts +0 -0
- /package/dist/{scores → evals}/scoreTraces/index.d.ts +0 -0
- /package/dist/{eval → observability}/index.cjs.map +0 -0
- /package/dist/{eval → observability}/index.js.map +0 -0
- /package/dist/{runtime-context → request-context}/index.cjs.map +0 -0
- /package/dist/{runtime-context → request-context}/index.js.map +0 -0
package/dist/chunk-P35FNLTQ.cjs
DELETED
|
@@ -1,2936 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkGPWMM745_cjs = require('./chunk-GPWMM745.cjs');
|
|
4
|
-
var chunk5NTO7S5I_cjs = require('./chunk-5NTO7S5I.cjs');
|
|
5
|
-
var chunkLRSB62Z6_cjs = require('./chunk-LRSB62Z6.cjs');
|
|
6
|
-
var chunkVF676YCO_cjs = require('./chunk-VF676YCO.cjs');
|
|
7
|
-
var chunk6VOPKVYH_cjs = require('./chunk-6VOPKVYH.cjs');
|
|
8
|
-
var chunkA5KDVZDL_cjs = require('./chunk-A5KDVZDL.cjs');
|
|
9
|
-
var crypto$1 = require('crypto');
|
|
10
|
-
var jsonSchemaToZod = require('json-schema-to-zod');
|
|
11
|
-
var zod = require('zod');
|
|
12
|
-
var schemaCompat = require('@mastra/schema-compat');
|
|
13
|
-
var web = require('stream/web');
|
|
14
|
-
|
|
15
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
-
|
|
17
|
-
var jsonSchemaToZod__default = /*#__PURE__*/_interopDefault(jsonSchemaToZod);
|
|
18
|
-
|
|
19
|
-
// src/ai-tracing/types.ts
|
|
20
|
-
var AISpanType = /* @__PURE__ */ ((AISpanType2) => {
|
|
21
|
-
AISpanType2["AGENT_RUN"] = "agent_run";
|
|
22
|
-
AISpanType2["GENERIC"] = "generic";
|
|
23
|
-
AISpanType2["MODEL_GENERATION"] = "model_generation";
|
|
24
|
-
AISpanType2["MODEL_STEP"] = "model_step";
|
|
25
|
-
AISpanType2["MODEL_CHUNK"] = "model_chunk";
|
|
26
|
-
AISpanType2["MCP_TOOL_CALL"] = "mcp_tool_call";
|
|
27
|
-
AISpanType2["PROCESSOR_RUN"] = "processor_run";
|
|
28
|
-
AISpanType2["TOOL_CALL"] = "tool_call";
|
|
29
|
-
AISpanType2["WORKFLOW_RUN"] = "workflow_run";
|
|
30
|
-
AISpanType2["WORKFLOW_STEP"] = "workflow_step";
|
|
31
|
-
AISpanType2["WORKFLOW_CONDITIONAL"] = "workflow_conditional";
|
|
32
|
-
AISpanType2["WORKFLOW_CONDITIONAL_EVAL"] = "workflow_conditional_eval";
|
|
33
|
-
AISpanType2["WORKFLOW_PARALLEL"] = "workflow_parallel";
|
|
34
|
-
AISpanType2["WORKFLOW_LOOP"] = "workflow_loop";
|
|
35
|
-
AISpanType2["WORKFLOW_SLEEP"] = "workflow_sleep";
|
|
36
|
-
AISpanType2["WORKFLOW_WAIT_EVENT"] = "workflow_wait_event";
|
|
37
|
-
return AISpanType2;
|
|
38
|
-
})(AISpanType || {});
|
|
39
|
-
var InternalSpans = /* @__PURE__ */ ((InternalSpans2) => {
|
|
40
|
-
InternalSpans2[InternalSpans2["NONE"] = 0] = "NONE";
|
|
41
|
-
InternalSpans2[InternalSpans2["WORKFLOW"] = 1] = "WORKFLOW";
|
|
42
|
-
InternalSpans2[InternalSpans2["AGENT"] = 2] = "AGENT";
|
|
43
|
-
InternalSpans2[InternalSpans2["TOOL"] = 4] = "TOOL";
|
|
44
|
-
InternalSpans2[InternalSpans2["MODEL"] = 8] = "MODEL";
|
|
45
|
-
InternalSpans2[InternalSpans2["ALL"] = 15] = "ALL";
|
|
46
|
-
return InternalSpans2;
|
|
47
|
-
})(InternalSpans || {});
|
|
48
|
-
var SamplingStrategyType = /* @__PURE__ */ ((SamplingStrategyType2) => {
|
|
49
|
-
SamplingStrategyType2["ALWAYS"] = "always";
|
|
50
|
-
SamplingStrategyType2["NEVER"] = "never";
|
|
51
|
-
SamplingStrategyType2["RATIO"] = "ratio";
|
|
52
|
-
SamplingStrategyType2["CUSTOM"] = "custom";
|
|
53
|
-
return SamplingStrategyType2;
|
|
54
|
-
})(SamplingStrategyType || {});
|
|
55
|
-
var AITracingEventType = /* @__PURE__ */ ((AITracingEventType2) => {
|
|
56
|
-
AITracingEventType2["SPAN_STARTED"] = "span_started";
|
|
57
|
-
AITracingEventType2["SPAN_UPDATED"] = "span_updated";
|
|
58
|
-
AITracingEventType2["SPAN_ENDED"] = "span_ended";
|
|
59
|
-
return AITracingEventType2;
|
|
60
|
-
})(AITracingEventType || {});
|
|
61
|
-
|
|
62
|
-
// src/ai-tracing/spans/base.ts
|
|
63
|
-
function isSpanInternal(spanType, flags) {
|
|
64
|
-
if (flags === void 0 || flags === 0 /* NONE */) {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
switch (spanType) {
|
|
68
|
-
// Workflow-related spans
|
|
69
|
-
case "workflow_run" /* WORKFLOW_RUN */:
|
|
70
|
-
case "workflow_step" /* WORKFLOW_STEP */:
|
|
71
|
-
case "workflow_conditional" /* WORKFLOW_CONDITIONAL */:
|
|
72
|
-
case "workflow_conditional_eval" /* WORKFLOW_CONDITIONAL_EVAL */:
|
|
73
|
-
case "workflow_parallel" /* WORKFLOW_PARALLEL */:
|
|
74
|
-
case "workflow_loop" /* WORKFLOW_LOOP */:
|
|
75
|
-
case "workflow_sleep" /* WORKFLOW_SLEEP */:
|
|
76
|
-
case "workflow_wait_event" /* WORKFLOW_WAIT_EVENT */:
|
|
77
|
-
return (flags & 1 /* WORKFLOW */) !== 0;
|
|
78
|
-
// Agent-related spans
|
|
79
|
-
case "agent_run" /* AGENT_RUN */:
|
|
80
|
-
return (flags & 2 /* AGENT */) !== 0;
|
|
81
|
-
// Tool-related spans
|
|
82
|
-
case "tool_call" /* TOOL_CALL */:
|
|
83
|
-
case "mcp_tool_call" /* MCP_TOOL_CALL */:
|
|
84
|
-
return (flags & 4 /* TOOL */) !== 0;
|
|
85
|
-
// Model-related spans
|
|
86
|
-
case "model_generation" /* MODEL_GENERATION */:
|
|
87
|
-
case "model_step" /* MODEL_STEP */:
|
|
88
|
-
case "model_chunk" /* MODEL_CHUNK */:
|
|
89
|
-
return (flags & 8 /* MODEL */) !== 0;
|
|
90
|
-
// Default: never internal
|
|
91
|
-
default:
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
var BaseAISpan = class {
|
|
96
|
-
name;
|
|
97
|
-
type;
|
|
98
|
-
attributes;
|
|
99
|
-
parent;
|
|
100
|
-
startTime;
|
|
101
|
-
endTime;
|
|
102
|
-
isEvent;
|
|
103
|
-
isInternal;
|
|
104
|
-
aiTracing;
|
|
105
|
-
input;
|
|
106
|
-
output;
|
|
107
|
-
errorInfo;
|
|
108
|
-
metadata;
|
|
109
|
-
traceState;
|
|
110
|
-
/** Parent span ID (for root spans that are children of external spans) */
|
|
111
|
-
parentSpanId;
|
|
112
|
-
constructor(options, aiTracing) {
|
|
113
|
-
this.name = options.name;
|
|
114
|
-
this.type = options.type;
|
|
115
|
-
this.attributes = deepClean(options.attributes) || {};
|
|
116
|
-
this.metadata = deepClean(options.metadata);
|
|
117
|
-
this.parent = options.parent;
|
|
118
|
-
this.startTime = /* @__PURE__ */ new Date();
|
|
119
|
-
this.aiTracing = aiTracing;
|
|
120
|
-
this.isEvent = options.isEvent ?? false;
|
|
121
|
-
this.isInternal = isSpanInternal(this.type, options.tracingPolicy?.internal);
|
|
122
|
-
this.traceState = options.traceState;
|
|
123
|
-
if (this.isEvent) {
|
|
124
|
-
this.output = deepClean(options.output);
|
|
125
|
-
} else {
|
|
126
|
-
this.input = deepClean(options.input);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
createChildSpan(options) {
|
|
130
|
-
return this.aiTracing.startSpan({ ...options, parent: this, isEvent: false });
|
|
131
|
-
}
|
|
132
|
-
createEventSpan(options) {
|
|
133
|
-
return this.aiTracing.startSpan({ ...options, parent: this, isEvent: true });
|
|
134
|
-
}
|
|
135
|
-
/** Returns `TRUE` if the span is the root span of a trace */
|
|
136
|
-
get isRootSpan() {
|
|
137
|
-
return !this.parent;
|
|
138
|
-
}
|
|
139
|
-
/** Get the closest parent spanId that isn't an internal span */
|
|
140
|
-
getParentSpanId(includeInternalSpans) {
|
|
141
|
-
if (!this.parent) {
|
|
142
|
-
return this.parentSpanId;
|
|
143
|
-
}
|
|
144
|
-
if (includeInternalSpans) return this.parent.id;
|
|
145
|
-
if (this.parent.isInternal) return this.parent.getParentSpanId(includeInternalSpans);
|
|
146
|
-
return this.parent.id;
|
|
147
|
-
}
|
|
148
|
-
/** Find the closest parent span of a specific type by walking up the parent chain */
|
|
149
|
-
findParent(spanType) {
|
|
150
|
-
let current = this.parent;
|
|
151
|
-
while (current) {
|
|
152
|
-
if (current.type === spanType) {
|
|
153
|
-
return current;
|
|
154
|
-
}
|
|
155
|
-
current = current.parent;
|
|
156
|
-
}
|
|
157
|
-
return void 0;
|
|
158
|
-
}
|
|
159
|
-
/** Returns a lightweight span ready for export */
|
|
160
|
-
exportSpan(includeInternalSpans) {
|
|
161
|
-
return {
|
|
162
|
-
id: this.id,
|
|
163
|
-
traceId: this.traceId,
|
|
164
|
-
name: this.name,
|
|
165
|
-
type: this.type,
|
|
166
|
-
attributes: this.attributes,
|
|
167
|
-
metadata: this.metadata,
|
|
168
|
-
startTime: this.startTime,
|
|
169
|
-
endTime: this.endTime,
|
|
170
|
-
input: this.input,
|
|
171
|
-
output: this.output,
|
|
172
|
-
errorInfo: this.errorInfo,
|
|
173
|
-
isEvent: this.isEvent,
|
|
174
|
-
isRootSpan: this.isRootSpan,
|
|
175
|
-
parentSpanId: this.getParentSpanId(includeInternalSpans)
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
var DEFAULT_KEYS_TO_STRIP = /* @__PURE__ */ new Set([
|
|
180
|
-
"logger",
|
|
181
|
-
"experimental_providerMetadata",
|
|
182
|
-
"providerMetadata",
|
|
183
|
-
"steps",
|
|
184
|
-
"tracingContext"
|
|
185
|
-
]);
|
|
186
|
-
function deepClean(value, options = {}, _seen = /* @__PURE__ */ new WeakSet(), _depth = 0) {
|
|
187
|
-
const { keysToStrip = DEFAULT_KEYS_TO_STRIP, maxDepth = 10 } = options;
|
|
188
|
-
if (_depth > maxDepth) {
|
|
189
|
-
return "[MaxDepth]";
|
|
190
|
-
}
|
|
191
|
-
if (value === null || typeof value !== "object") {
|
|
192
|
-
try {
|
|
193
|
-
JSON.stringify(value);
|
|
194
|
-
return value;
|
|
195
|
-
} catch (error) {
|
|
196
|
-
return `[${error instanceof Error ? error.message : String(error)}]`;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
if (_seen.has(value)) {
|
|
200
|
-
return "[Circular]";
|
|
201
|
-
}
|
|
202
|
-
_seen.add(value);
|
|
203
|
-
if (Array.isArray(value)) {
|
|
204
|
-
return value.map((item) => deepClean(item, options, _seen, _depth + 1));
|
|
205
|
-
}
|
|
206
|
-
const cleaned = {};
|
|
207
|
-
for (const [key, val] of Object.entries(value)) {
|
|
208
|
-
if (keysToStrip.has(key)) {
|
|
209
|
-
continue;
|
|
210
|
-
}
|
|
211
|
-
try {
|
|
212
|
-
cleaned[key] = deepClean(val, options, _seen, _depth + 1);
|
|
213
|
-
} catch (error) {
|
|
214
|
-
cleaned[key] = `[${error instanceof Error ? error.message : String(error)}]`;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return cleaned;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// src/ai-tracing/spans/default.ts
|
|
221
|
-
var DefaultAISpan = class extends BaseAISpan {
|
|
222
|
-
id;
|
|
223
|
-
traceId;
|
|
224
|
-
constructor(options, aiTracing) {
|
|
225
|
-
super(options, aiTracing);
|
|
226
|
-
this.id = generateSpanId();
|
|
227
|
-
if (options.parent) {
|
|
228
|
-
this.traceId = options.parent.traceId;
|
|
229
|
-
} else if (options.traceId) {
|
|
230
|
-
if (isValidTraceId(options.traceId)) {
|
|
231
|
-
this.traceId = options.traceId;
|
|
232
|
-
} else {
|
|
233
|
-
console.error(
|
|
234
|
-
`[Mastra Tracing] Invalid traceId: must be 1-32 hexadecimal characters, got "${options.traceId}". Generating new trace ID.`
|
|
235
|
-
);
|
|
236
|
-
this.traceId = generateTraceId();
|
|
237
|
-
}
|
|
238
|
-
} else {
|
|
239
|
-
this.traceId = generateTraceId();
|
|
240
|
-
}
|
|
241
|
-
if (!options.parent && options.parentSpanId) {
|
|
242
|
-
if (isValidSpanId(options.parentSpanId)) {
|
|
243
|
-
this.parentSpanId = options.parentSpanId;
|
|
244
|
-
} else {
|
|
245
|
-
console.error(
|
|
246
|
-
`[Mastra Tracing] Invalid parentSpanId: must be 1-16 hexadecimal characters, got "${options.parentSpanId}". Ignoring parent span ID.`
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
end(options) {
|
|
252
|
-
if (this.isEvent) {
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
this.endTime = /* @__PURE__ */ new Date();
|
|
256
|
-
if (options?.output !== void 0) {
|
|
257
|
-
this.output = deepClean(options.output);
|
|
258
|
-
}
|
|
259
|
-
if (options?.attributes) {
|
|
260
|
-
this.attributes = { ...this.attributes, ...deepClean(options.attributes) };
|
|
261
|
-
}
|
|
262
|
-
if (options?.metadata) {
|
|
263
|
-
this.metadata = { ...this.metadata, ...deepClean(options.metadata) };
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
error(options) {
|
|
267
|
-
if (this.isEvent) {
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
const { error, endSpan = true, attributes, metadata } = options;
|
|
271
|
-
this.errorInfo = error instanceof chunk5NTO7S5I_cjs.MastraError ? {
|
|
272
|
-
id: error.id,
|
|
273
|
-
details: error.details,
|
|
274
|
-
category: error.category,
|
|
275
|
-
domain: error.domain,
|
|
276
|
-
message: error.message
|
|
277
|
-
} : {
|
|
278
|
-
message: error.message
|
|
279
|
-
};
|
|
280
|
-
if (attributes) {
|
|
281
|
-
this.attributes = { ...this.attributes, ...deepClean(attributes) };
|
|
282
|
-
}
|
|
283
|
-
if (metadata) {
|
|
284
|
-
this.metadata = { ...this.metadata, ...deepClean(metadata) };
|
|
285
|
-
}
|
|
286
|
-
if (endSpan) {
|
|
287
|
-
this.end();
|
|
288
|
-
} else {
|
|
289
|
-
this.update({});
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
update(options) {
|
|
293
|
-
if (this.isEvent) {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
if (options.input !== void 0) {
|
|
297
|
-
this.input = deepClean(options.input);
|
|
298
|
-
}
|
|
299
|
-
if (options.output !== void 0) {
|
|
300
|
-
this.output = deepClean(options.output);
|
|
301
|
-
}
|
|
302
|
-
if (options.attributes) {
|
|
303
|
-
this.attributes = { ...this.attributes, ...deepClean(options.attributes) };
|
|
304
|
-
}
|
|
305
|
-
if (options.metadata) {
|
|
306
|
-
this.metadata = { ...this.metadata, ...deepClean(options.metadata) };
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
get isValid() {
|
|
310
|
-
return true;
|
|
311
|
-
}
|
|
312
|
-
async export() {
|
|
313
|
-
return JSON.stringify({
|
|
314
|
-
spanId: this.id,
|
|
315
|
-
traceId: this.traceId,
|
|
316
|
-
startTime: this.startTime,
|
|
317
|
-
endTime: this.endTime,
|
|
318
|
-
attributes: this.attributes,
|
|
319
|
-
metadata: this.metadata
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
function generateSpanId() {
|
|
324
|
-
const bytes = new Uint8Array(8);
|
|
325
|
-
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
326
|
-
crypto.getRandomValues(bytes);
|
|
327
|
-
} else {
|
|
328
|
-
for (let i = 0; i < 8; i++) {
|
|
329
|
-
bytes[i] = Math.floor(Math.random() * 256);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
333
|
-
}
|
|
334
|
-
function generateTraceId() {
|
|
335
|
-
const bytes = new Uint8Array(16);
|
|
336
|
-
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
337
|
-
crypto.getRandomValues(bytes);
|
|
338
|
-
} else {
|
|
339
|
-
for (let i = 0; i < 16; i++) {
|
|
340
|
-
bytes[i] = Math.floor(Math.random() * 256);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
344
|
-
}
|
|
345
|
-
function isValidTraceId(traceId) {
|
|
346
|
-
return /^[0-9a-f]{1,32}$/i.test(traceId);
|
|
347
|
-
}
|
|
348
|
-
function isValidSpanId(spanId) {
|
|
349
|
-
return /^[0-9a-f]{1,16}$/i.test(spanId);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// src/ai-tracing/spans/no-op.ts
|
|
353
|
-
var NoOpAISpan = class extends BaseAISpan {
|
|
354
|
-
id;
|
|
355
|
-
traceId;
|
|
356
|
-
constructor(options, aiTracing) {
|
|
357
|
-
super(options, aiTracing);
|
|
358
|
-
this.id = "no-op";
|
|
359
|
-
this.traceId = "no-op-trace";
|
|
360
|
-
}
|
|
361
|
-
end(_options) {
|
|
362
|
-
}
|
|
363
|
-
error(_options) {
|
|
364
|
-
}
|
|
365
|
-
update(_options) {
|
|
366
|
-
}
|
|
367
|
-
get isValid() {
|
|
368
|
-
return false;
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
// src/ai-tracing/exporters/base.ts
|
|
373
|
-
var BaseExporter = class {
|
|
374
|
-
/** Mastra logger instance */
|
|
375
|
-
logger;
|
|
376
|
-
/** Whether this exporter is disabled */
|
|
377
|
-
isDisabled = false;
|
|
378
|
-
/**
|
|
379
|
-
* Initialize the base exporter with logger
|
|
380
|
-
*/
|
|
381
|
-
constructor(config = {}) {
|
|
382
|
-
const logLevel = this.resolveLogLevel(config.logLevel);
|
|
383
|
-
this.logger = config.logger ?? new chunkA5KDVZDL_cjs.ConsoleLogger({ level: logLevel, name: this.constructor.name });
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Set the logger for the exporter (called by Mastra/AITracing during initialization)
|
|
387
|
-
*/
|
|
388
|
-
__setLogger(logger) {
|
|
389
|
-
this.logger = logger;
|
|
390
|
-
this.logger.debug(`Logger updated for exporter [name=${this.name}]`);
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Convert string log level to LogLevel enum
|
|
394
|
-
*/
|
|
395
|
-
resolveLogLevel(logLevel) {
|
|
396
|
-
if (!logLevel) {
|
|
397
|
-
return chunkA5KDVZDL_cjs.LogLevel.INFO;
|
|
398
|
-
}
|
|
399
|
-
if (typeof logLevel === "number") {
|
|
400
|
-
return logLevel;
|
|
401
|
-
}
|
|
402
|
-
const logLevelMap = {
|
|
403
|
-
debug: chunkA5KDVZDL_cjs.LogLevel.DEBUG,
|
|
404
|
-
info: chunkA5KDVZDL_cjs.LogLevel.INFO,
|
|
405
|
-
warn: chunkA5KDVZDL_cjs.LogLevel.WARN,
|
|
406
|
-
error: chunkA5KDVZDL_cjs.LogLevel.ERROR
|
|
407
|
-
};
|
|
408
|
-
return logLevelMap[logLevel] ?? chunkA5KDVZDL_cjs.LogLevel.INFO;
|
|
409
|
-
}
|
|
410
|
-
/**
|
|
411
|
-
* Mark the exporter as disabled and log a message
|
|
412
|
-
*
|
|
413
|
-
* @param reason - Reason why the exporter is disabled
|
|
414
|
-
*/
|
|
415
|
-
setDisabled(reason) {
|
|
416
|
-
this.isDisabled = true;
|
|
417
|
-
this.logger.warn(`${this.name} disabled: ${reason}`);
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* Export a tracing event
|
|
421
|
-
*
|
|
422
|
-
* This method checks if the exporter is disabled before calling _exportEvent.
|
|
423
|
-
* Subclasses should implement _exportEvent instead of overriding this method.
|
|
424
|
-
*/
|
|
425
|
-
async exportEvent(event) {
|
|
426
|
-
if (this.isDisabled) {
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
await this._exportEvent(event);
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Shutdown the exporter and clean up resources
|
|
433
|
-
*
|
|
434
|
-
* Default implementation just logs. Override to add custom cleanup.
|
|
435
|
-
*/
|
|
436
|
-
async shutdown() {
|
|
437
|
-
this.logger.info(`${this.name} shutdown complete`);
|
|
438
|
-
}
|
|
439
|
-
};
|
|
440
|
-
var CoreToolBuilder = class extends chunk6VOPKVYH_cjs.MastraBase {
|
|
441
|
-
originalTool;
|
|
442
|
-
options;
|
|
443
|
-
logType;
|
|
444
|
-
constructor(input) {
|
|
445
|
-
super({ name: "CoreToolBuilder" });
|
|
446
|
-
this.originalTool = input.originalTool;
|
|
447
|
-
this.options = input.options;
|
|
448
|
-
this.logType = input.logType;
|
|
449
|
-
}
|
|
450
|
-
// Helper to get parameters based on tool type
|
|
451
|
-
getParameters = () => {
|
|
452
|
-
if (chunkVF676YCO_cjs.isVercelTool(this.originalTool)) {
|
|
453
|
-
let schema2 = this.originalTool.parameters ?? ("inputSchema" in this.originalTool ? this.originalTool.inputSchema : void 0) ?? zod.z.object({});
|
|
454
|
-
if (typeof schema2 === "function") {
|
|
455
|
-
schema2 = schema2();
|
|
456
|
-
}
|
|
457
|
-
return schema2;
|
|
458
|
-
}
|
|
459
|
-
let schema = this.originalTool.inputSchema ?? zod.z.object({});
|
|
460
|
-
if (typeof schema === "function") {
|
|
461
|
-
schema = schema();
|
|
462
|
-
}
|
|
463
|
-
return schema;
|
|
464
|
-
};
|
|
465
|
-
getOutputSchema = () => {
|
|
466
|
-
if ("outputSchema" in this.originalTool) {
|
|
467
|
-
let schema = this.originalTool.outputSchema;
|
|
468
|
-
if (typeof schema === "function") {
|
|
469
|
-
schema = schema();
|
|
470
|
-
}
|
|
471
|
-
return schema;
|
|
472
|
-
}
|
|
473
|
-
return null;
|
|
474
|
-
};
|
|
475
|
-
// For provider-defined tools, we need to include all required properties
|
|
476
|
-
buildProviderTool(tool) {
|
|
477
|
-
if ("type" in tool && tool.type === "provider-defined" && "id" in tool && typeof tool.id === "string" && tool.id.includes(".")) {
|
|
478
|
-
const parameters = this.getParameters();
|
|
479
|
-
const outputSchema = this.getOutputSchema();
|
|
480
|
-
return {
|
|
481
|
-
type: "provider-defined",
|
|
482
|
-
id: tool.id,
|
|
483
|
-
args: "args" in this.originalTool ? this.originalTool.args : {},
|
|
484
|
-
description: tool.description,
|
|
485
|
-
parameters: parameters.jsonSchema ? parameters : schemaCompat.convertZodSchemaToAISDKSchema(parameters),
|
|
486
|
-
...outputSchema ? { outputSchema: outputSchema.jsonSchema ? outputSchema : schemaCompat.convertZodSchemaToAISDKSchema(outputSchema) } : {},
|
|
487
|
-
execute: this.originalTool.execute ? this.createExecute(
|
|
488
|
-
this.originalTool,
|
|
489
|
-
{ ...this.options, description: this.originalTool.description },
|
|
490
|
-
this.logType
|
|
491
|
-
) : void 0
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
return void 0;
|
|
495
|
-
}
|
|
496
|
-
createLogMessageOptions({ agentName, toolName, type }) {
|
|
497
|
-
if (!agentName) {
|
|
498
|
-
return {
|
|
499
|
-
start: `Executing tool ${toolName}`,
|
|
500
|
-
error: `Failed tool execution`
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
|
-
const prefix = `[Agent:${agentName}]`;
|
|
504
|
-
const toolType = type === "toolset" ? "toolset" : "tool";
|
|
505
|
-
return {
|
|
506
|
-
start: `${prefix} - Executing ${toolType} ${toolName}`,
|
|
507
|
-
error: `${prefix} - Failed ${toolType} execution`
|
|
508
|
-
};
|
|
509
|
-
}
|
|
510
|
-
createExecute(tool, options, logType, processedSchema) {
|
|
511
|
-
const { logger, mastra: _mastra, memory: _memory, runtimeContext, model, ...rest } = options;
|
|
512
|
-
const logModelObject = {
|
|
513
|
-
modelId: model?.modelId,
|
|
514
|
-
provider: model?.provider,
|
|
515
|
-
specificationVersion: model?.specificationVersion
|
|
516
|
-
};
|
|
517
|
-
const { start, error } = this.createLogMessageOptions({
|
|
518
|
-
agentName: options.agentName,
|
|
519
|
-
toolName: options.name,
|
|
520
|
-
type: logType
|
|
521
|
-
});
|
|
522
|
-
const execFunction = async (args, execOptions) => {
|
|
523
|
-
const tracingContext = execOptions.tracingContext || options.tracingContext;
|
|
524
|
-
const toolSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
525
|
-
type: "tool_call" /* TOOL_CALL */,
|
|
526
|
-
name: `tool: '${options.name}'`,
|
|
527
|
-
input: args,
|
|
528
|
-
attributes: {
|
|
529
|
-
toolId: options.name,
|
|
530
|
-
toolDescription: options.description,
|
|
531
|
-
toolType: logType || "tool"
|
|
532
|
-
},
|
|
533
|
-
tracingPolicy: options.tracingPolicy
|
|
534
|
-
});
|
|
535
|
-
try {
|
|
536
|
-
let result;
|
|
537
|
-
if (chunkVF676YCO_cjs.isVercelTool(tool)) {
|
|
538
|
-
result = await tool?.execute?.(args, execOptions);
|
|
539
|
-
} else {
|
|
540
|
-
const wrappedMastra = options.mastra ? wrapMastra(options.mastra, { currentSpan: toolSpan }) : options.mastra;
|
|
541
|
-
result = await tool?.execute?.(
|
|
542
|
-
{
|
|
543
|
-
context: args,
|
|
544
|
-
threadId: options.threadId,
|
|
545
|
-
resourceId: options.resourceId,
|
|
546
|
-
mastra: wrappedMastra,
|
|
547
|
-
memory: options.memory,
|
|
548
|
-
runId: options.runId,
|
|
549
|
-
runtimeContext: options.runtimeContext ?? new chunkGPWMM745_cjs.RuntimeContext(),
|
|
550
|
-
writer: new chunkLRSB62Z6_cjs.ToolStream(
|
|
551
|
-
{
|
|
552
|
-
prefix: "tool",
|
|
553
|
-
callId: execOptions.toolCallId,
|
|
554
|
-
name: options.name,
|
|
555
|
-
runId: options.runId
|
|
556
|
-
},
|
|
557
|
-
options.writableStream || execOptions.writableStream
|
|
558
|
-
),
|
|
559
|
-
tracingContext: { currentSpan: toolSpan }
|
|
560
|
-
},
|
|
561
|
-
execOptions
|
|
562
|
-
);
|
|
563
|
-
}
|
|
564
|
-
toolSpan?.end({ output: result });
|
|
565
|
-
return result ?? void 0;
|
|
566
|
-
} catch (error2) {
|
|
567
|
-
toolSpan?.error({ error: error2 });
|
|
568
|
-
throw error2;
|
|
569
|
-
}
|
|
570
|
-
};
|
|
571
|
-
return async (args, execOptions) => {
|
|
572
|
-
let logger2 = options.logger || this.logger;
|
|
573
|
-
try {
|
|
574
|
-
logger2.debug(start, { ...rest, model: logModelObject, args });
|
|
575
|
-
const parameters = processedSchema || this.getParameters();
|
|
576
|
-
const { data, error: error2 } = chunkVF676YCO_cjs.validateToolInput(parameters, args, options.name);
|
|
577
|
-
if (error2) {
|
|
578
|
-
logger2.warn(`Tool input validation failed for '${options.name}'`, {
|
|
579
|
-
toolName: options.name,
|
|
580
|
-
errors: error2.validationErrors,
|
|
581
|
-
args
|
|
582
|
-
});
|
|
583
|
-
return error2;
|
|
584
|
-
}
|
|
585
|
-
args = data;
|
|
586
|
-
return await new Promise((resolve, reject) => {
|
|
587
|
-
setImmediate(async () => {
|
|
588
|
-
try {
|
|
589
|
-
const result = await execFunction(args, execOptions);
|
|
590
|
-
resolve(result);
|
|
591
|
-
} catch (err) {
|
|
592
|
-
reject(err);
|
|
593
|
-
}
|
|
594
|
-
});
|
|
595
|
-
});
|
|
596
|
-
} catch (err) {
|
|
597
|
-
const mastraError = new chunk5NTO7S5I_cjs.MastraError(
|
|
598
|
-
{
|
|
599
|
-
id: "TOOL_EXECUTION_FAILED",
|
|
600
|
-
domain: "TOOL" /* TOOL */,
|
|
601
|
-
category: "USER" /* USER */,
|
|
602
|
-
details: {
|
|
603
|
-
errorMessage: String(error),
|
|
604
|
-
argsJson: JSON.stringify(args),
|
|
605
|
-
model: model?.modelId ?? ""
|
|
606
|
-
}
|
|
607
|
-
},
|
|
608
|
-
err
|
|
609
|
-
);
|
|
610
|
-
logger2.trackException(mastraError);
|
|
611
|
-
logger2.error(error, { ...rest, model: logModelObject, error: mastraError, args });
|
|
612
|
-
return mastraError;
|
|
613
|
-
}
|
|
614
|
-
};
|
|
615
|
-
}
|
|
616
|
-
buildV5() {
|
|
617
|
-
const builtTool = this.build();
|
|
618
|
-
if (!builtTool.parameters) {
|
|
619
|
-
throw new Error("Tool parameters are required");
|
|
620
|
-
}
|
|
621
|
-
const base = {
|
|
622
|
-
...builtTool,
|
|
623
|
-
inputSchema: builtTool.parameters,
|
|
624
|
-
onInputStart: "onInputStart" in this.originalTool ? this.originalTool.onInputStart : void 0,
|
|
625
|
-
onInputDelta: "onInputDelta" in this.originalTool ? this.originalTool.onInputDelta : void 0,
|
|
626
|
-
onInputAvailable: "onInputAvailable" in this.originalTool ? this.originalTool.onInputAvailable : void 0
|
|
627
|
-
};
|
|
628
|
-
if (builtTool.type === "provider-defined") {
|
|
629
|
-
const { execute, parameters, ...rest } = base;
|
|
630
|
-
const name = builtTool.id.split(".")[1] || builtTool.id;
|
|
631
|
-
return {
|
|
632
|
-
...rest,
|
|
633
|
-
type: builtTool.type,
|
|
634
|
-
id: builtTool.id,
|
|
635
|
-
name,
|
|
636
|
-
args: builtTool.args
|
|
637
|
-
};
|
|
638
|
-
}
|
|
639
|
-
return base;
|
|
640
|
-
}
|
|
641
|
-
build() {
|
|
642
|
-
const providerTool = this.buildProviderTool(this.originalTool);
|
|
643
|
-
if (providerTool) {
|
|
644
|
-
return providerTool;
|
|
645
|
-
}
|
|
646
|
-
const model = this.options.model;
|
|
647
|
-
const schemaCompatLayers = [];
|
|
648
|
-
if (model) {
|
|
649
|
-
const supportsStructuredOutputs = model.specificationVersion !== "v2" ? model.supportsStructuredOutputs ?? false : false;
|
|
650
|
-
const modelInfo = {
|
|
651
|
-
modelId: model.modelId,
|
|
652
|
-
supportsStructuredOutputs,
|
|
653
|
-
provider: model.provider
|
|
654
|
-
};
|
|
655
|
-
schemaCompatLayers.push(
|
|
656
|
-
new schemaCompat.OpenAIReasoningSchemaCompatLayer(modelInfo),
|
|
657
|
-
new schemaCompat.OpenAISchemaCompatLayer(modelInfo),
|
|
658
|
-
new schemaCompat.GoogleSchemaCompatLayer(modelInfo),
|
|
659
|
-
new schemaCompat.AnthropicSchemaCompatLayer(modelInfo),
|
|
660
|
-
new schemaCompat.DeepSeekSchemaCompatLayer(modelInfo),
|
|
661
|
-
new schemaCompat.MetaSchemaCompatLayer(modelInfo)
|
|
662
|
-
);
|
|
663
|
-
}
|
|
664
|
-
let processedZodSchema;
|
|
665
|
-
let processedSchema;
|
|
666
|
-
const originalSchema = this.getParameters();
|
|
667
|
-
const applicableLayer = schemaCompatLayers.find((layer) => layer.shouldApply());
|
|
668
|
-
if (applicableLayer && originalSchema) {
|
|
669
|
-
processedZodSchema = applicableLayer.processZodType(originalSchema);
|
|
670
|
-
processedSchema = schemaCompat.applyCompatLayer({
|
|
671
|
-
schema: originalSchema,
|
|
672
|
-
compatLayers: schemaCompatLayers,
|
|
673
|
-
mode: "aiSdkSchema"
|
|
674
|
-
});
|
|
675
|
-
} else {
|
|
676
|
-
processedZodSchema = originalSchema;
|
|
677
|
-
processedSchema = schemaCompat.applyCompatLayer({
|
|
678
|
-
schema: originalSchema,
|
|
679
|
-
compatLayers: schemaCompatLayers,
|
|
680
|
-
mode: "aiSdkSchema"
|
|
681
|
-
});
|
|
682
|
-
}
|
|
683
|
-
let processedOutputSchema;
|
|
684
|
-
if (this.getOutputSchema()) {
|
|
685
|
-
processedOutputSchema = schemaCompat.applyCompatLayer({
|
|
686
|
-
schema: this.getOutputSchema(),
|
|
687
|
-
compatLayers: schemaCompatLayers,
|
|
688
|
-
mode: "aiSdkSchema"
|
|
689
|
-
});
|
|
690
|
-
}
|
|
691
|
-
const definition = {
|
|
692
|
-
type: "function",
|
|
693
|
-
description: this.originalTool.description,
|
|
694
|
-
parameters: this.getParameters(),
|
|
695
|
-
outputSchema: this.getOutputSchema(),
|
|
696
|
-
requireApproval: this.options.requireApproval,
|
|
697
|
-
execute: this.originalTool.execute ? this.createExecute(
|
|
698
|
-
this.originalTool,
|
|
699
|
-
{ ...this.options, description: this.originalTool.description },
|
|
700
|
-
this.logType,
|
|
701
|
-
processedZodSchema
|
|
702
|
-
// Pass the processed Zod schema for validation
|
|
703
|
-
) : void 0
|
|
704
|
-
};
|
|
705
|
-
return {
|
|
706
|
-
...definition,
|
|
707
|
-
id: "id" in this.originalTool ? this.originalTool.id : void 0,
|
|
708
|
-
parameters: processedSchema,
|
|
709
|
-
outputSchema: processedOutputSchema
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
};
|
|
713
|
-
|
|
714
|
-
// src/utils.ts
|
|
715
|
-
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
716
|
-
function deepMerge(target, source) {
|
|
717
|
-
const output = { ...target };
|
|
718
|
-
if (!source) return output;
|
|
719
|
-
Object.keys(source).forEach((key) => {
|
|
720
|
-
const targetValue = output[key];
|
|
721
|
-
const sourceValue = source[key];
|
|
722
|
-
if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
|
|
723
|
-
output[key] = sourceValue;
|
|
724
|
-
} else if (sourceValue instanceof Object && targetValue instanceof Object && !Array.isArray(sourceValue) && !Array.isArray(targetValue)) {
|
|
725
|
-
output[key] = deepMerge(targetValue, sourceValue);
|
|
726
|
-
} else if (sourceValue !== void 0) {
|
|
727
|
-
output[key] = sourceValue;
|
|
728
|
-
}
|
|
729
|
-
});
|
|
730
|
-
return output;
|
|
731
|
-
}
|
|
732
|
-
function generateEmptyFromSchema(schema) {
|
|
733
|
-
try {
|
|
734
|
-
const parsedSchema = JSON.parse(schema);
|
|
735
|
-
if (!parsedSchema || parsedSchema.type !== "object" || !parsedSchema.properties) return {};
|
|
736
|
-
const obj = {};
|
|
737
|
-
const TYPE_DEFAULTS = {
|
|
738
|
-
string: "",
|
|
739
|
-
array: [],
|
|
740
|
-
object: {},
|
|
741
|
-
number: 0,
|
|
742
|
-
integer: 0,
|
|
743
|
-
boolean: false
|
|
744
|
-
};
|
|
745
|
-
for (const [key, prop] of Object.entries(parsedSchema.properties)) {
|
|
746
|
-
obj[key] = TYPE_DEFAULTS[prop.type] ?? null;
|
|
747
|
-
}
|
|
748
|
-
return obj;
|
|
749
|
-
} catch {
|
|
750
|
-
return {};
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
async function* maskStreamTags(stream, tag, options = {}) {
|
|
754
|
-
const { onStart, onEnd, onMask } = options;
|
|
755
|
-
const openTag = `<${tag}>`;
|
|
756
|
-
const closeTag = `</${tag}>`;
|
|
757
|
-
let buffer = "";
|
|
758
|
-
let fullContent = "";
|
|
759
|
-
let isMasking = false;
|
|
760
|
-
let isBuffering = false;
|
|
761
|
-
const trimOutsideDelimiter = (text, delimiter, trim) => {
|
|
762
|
-
if (!text.includes(delimiter)) {
|
|
763
|
-
return text;
|
|
764
|
-
}
|
|
765
|
-
const parts = text.split(delimiter);
|
|
766
|
-
if (trim === `before-start`) {
|
|
767
|
-
return `${delimiter}${parts[1]}`;
|
|
768
|
-
}
|
|
769
|
-
return `${parts[0]}${delimiter}`;
|
|
770
|
-
};
|
|
771
|
-
const startsWith = (text, pattern) => {
|
|
772
|
-
if (pattern.includes(openTag.substring(0, 3))) {
|
|
773
|
-
pattern = trimOutsideDelimiter(pattern, `<`, `before-start`);
|
|
774
|
-
}
|
|
775
|
-
return text.trim().startsWith(pattern.trim());
|
|
776
|
-
};
|
|
777
|
-
for await (const chunk of stream) {
|
|
778
|
-
fullContent += chunk;
|
|
779
|
-
if (isBuffering) buffer += chunk;
|
|
780
|
-
const chunkHasTag = startsWith(chunk, openTag);
|
|
781
|
-
const bufferHasTag = !chunkHasTag && isBuffering && startsWith(openTag, buffer);
|
|
782
|
-
let toYieldBeforeMaskedStartTag = ``;
|
|
783
|
-
if (!isMasking && (chunkHasTag || bufferHasTag)) {
|
|
784
|
-
isMasking = true;
|
|
785
|
-
isBuffering = false;
|
|
786
|
-
const taggedTextToMask = trimOutsideDelimiter(buffer, `<`, `before-start`);
|
|
787
|
-
if (taggedTextToMask !== buffer.trim()) {
|
|
788
|
-
toYieldBeforeMaskedStartTag = buffer.replace(taggedTextToMask, ``);
|
|
789
|
-
}
|
|
790
|
-
buffer = "";
|
|
791
|
-
onStart?.();
|
|
792
|
-
}
|
|
793
|
-
if (!isMasking && !isBuffering && startsWith(openTag, chunk) && chunk.trim() !== "") {
|
|
794
|
-
isBuffering = true;
|
|
795
|
-
buffer += chunk;
|
|
796
|
-
continue;
|
|
797
|
-
}
|
|
798
|
-
if (isBuffering && buffer && !startsWith(openTag, buffer)) {
|
|
799
|
-
yield buffer;
|
|
800
|
-
buffer = "";
|
|
801
|
-
isBuffering = false;
|
|
802
|
-
continue;
|
|
803
|
-
}
|
|
804
|
-
if (isMasking && fullContent.includes(closeTag)) {
|
|
805
|
-
onMask?.(chunk);
|
|
806
|
-
onEnd?.();
|
|
807
|
-
isMasking = false;
|
|
808
|
-
const lastFullContent = fullContent;
|
|
809
|
-
fullContent = ``;
|
|
810
|
-
const textUntilEndTag = trimOutsideDelimiter(lastFullContent, closeTag, "after-end");
|
|
811
|
-
if (textUntilEndTag !== lastFullContent) {
|
|
812
|
-
yield lastFullContent.replace(textUntilEndTag, ``);
|
|
813
|
-
}
|
|
814
|
-
continue;
|
|
815
|
-
}
|
|
816
|
-
if (isMasking) {
|
|
817
|
-
onMask?.(chunk);
|
|
818
|
-
if (toYieldBeforeMaskedStartTag) {
|
|
819
|
-
yield toYieldBeforeMaskedStartTag;
|
|
820
|
-
}
|
|
821
|
-
continue;
|
|
822
|
-
}
|
|
823
|
-
yield chunk;
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
function resolveSerializedZodOutput(schema) {
|
|
827
|
-
return Function("z", `"use strict";return (${schema});`)(zod.z);
|
|
828
|
-
}
|
|
829
|
-
function isZodType(value) {
|
|
830
|
-
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
831
|
-
}
|
|
832
|
-
function createDeterministicId(input) {
|
|
833
|
-
return crypto$1.createHash("sha256").update(input).digest("hex").slice(0, 8);
|
|
834
|
-
}
|
|
835
|
-
function setVercelToolProperties(tool) {
|
|
836
|
-
const inputSchema = "inputSchema" in tool ? tool.inputSchema : convertVercelToolParameters(tool);
|
|
837
|
-
const toolId = !("id" in tool) ? tool.description ? `tool-${createDeterministicId(tool.description)}` : `tool-${Math.random().toString(36).substring(2, 9)}` : tool.id;
|
|
838
|
-
return {
|
|
839
|
-
...tool,
|
|
840
|
-
id: toolId,
|
|
841
|
-
inputSchema
|
|
842
|
-
};
|
|
843
|
-
}
|
|
844
|
-
function ensureToolProperties(tools) {
|
|
845
|
-
const toolsWithProperties = Object.keys(tools).reduce((acc, key) => {
|
|
846
|
-
const tool = tools?.[key];
|
|
847
|
-
if (tool) {
|
|
848
|
-
if (chunkVF676YCO_cjs.isVercelTool(tool)) {
|
|
849
|
-
acc[key] = setVercelToolProperties(tool);
|
|
850
|
-
} else {
|
|
851
|
-
acc[key] = tool;
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
return acc;
|
|
855
|
-
}, {});
|
|
856
|
-
return toolsWithProperties;
|
|
857
|
-
}
|
|
858
|
-
function convertVercelToolParameters(tool) {
|
|
859
|
-
let schema = tool.parameters ?? zod.z.object({});
|
|
860
|
-
if (typeof schema === "function") {
|
|
861
|
-
schema = schema();
|
|
862
|
-
}
|
|
863
|
-
return isZodType(schema) ? schema : resolveSerializedZodOutput(jsonSchemaToZod__default.default(schema));
|
|
864
|
-
}
|
|
865
|
-
function makeCoreTool(originalTool, options, logType) {
|
|
866
|
-
return new CoreToolBuilder({ originalTool, options, logType }).build();
|
|
867
|
-
}
|
|
868
|
-
function makeCoreToolV5(originalTool, options, logType) {
|
|
869
|
-
return new CoreToolBuilder({ originalTool, options, logType }).buildV5();
|
|
870
|
-
}
|
|
871
|
-
function createMastraProxy({ mastra, logger }) {
|
|
872
|
-
return new Proxy(mastra, {
|
|
873
|
-
get(target, prop) {
|
|
874
|
-
const hasProp = Reflect.has(target, prop);
|
|
875
|
-
if (hasProp) {
|
|
876
|
-
const value = Reflect.get(target, prop);
|
|
877
|
-
const isFunction = typeof value === "function";
|
|
878
|
-
if (isFunction) {
|
|
879
|
-
return value.bind(target);
|
|
880
|
-
}
|
|
881
|
-
return value;
|
|
882
|
-
}
|
|
883
|
-
if (prop === "logger") {
|
|
884
|
-
logger.warn(`Please use 'getLogger' instead, logger is deprecated`);
|
|
885
|
-
return Reflect.apply(target.getLogger, target, []);
|
|
886
|
-
}
|
|
887
|
-
if (prop === "telemetry") {
|
|
888
|
-
logger.warn(`Please use 'getTelemetry' instead, telemetry is deprecated`);
|
|
889
|
-
return Reflect.apply(target.getTelemetry, target, []);
|
|
890
|
-
}
|
|
891
|
-
if (prop === "storage") {
|
|
892
|
-
logger.warn(`Please use 'getStorage' instead, storage is deprecated`);
|
|
893
|
-
return Reflect.get(target, "storage");
|
|
894
|
-
}
|
|
895
|
-
if (prop === "agents") {
|
|
896
|
-
logger.warn(`Please use 'getAgents' instead, agents is deprecated`);
|
|
897
|
-
return Reflect.apply(target.getAgents, target, []);
|
|
898
|
-
}
|
|
899
|
-
if (prop === "tts") {
|
|
900
|
-
logger.warn(`Please use 'getTTS' instead, tts is deprecated`);
|
|
901
|
-
return Reflect.apply(target.getTTS, target, []);
|
|
902
|
-
}
|
|
903
|
-
if (prop === "vectors") {
|
|
904
|
-
logger.warn(`Please use 'getVectors' instead, vectors is deprecated`);
|
|
905
|
-
return Reflect.apply(target.getVectors, target, []);
|
|
906
|
-
}
|
|
907
|
-
if (prop === "memory") {
|
|
908
|
-
logger.warn(`Please use 'getMemory' instead, memory is deprecated`);
|
|
909
|
-
return Reflect.get(target, "memory");
|
|
910
|
-
}
|
|
911
|
-
return Reflect.get(target, prop);
|
|
912
|
-
}
|
|
913
|
-
});
|
|
914
|
-
}
|
|
915
|
-
function checkEvalStorageFields(traceObject, logger) {
|
|
916
|
-
const missingFields = [];
|
|
917
|
-
if (!traceObject.input) missingFields.push("input");
|
|
918
|
-
if (!traceObject.output) missingFields.push("output");
|
|
919
|
-
if (!traceObject.agentName) missingFields.push("agent_name");
|
|
920
|
-
if (!traceObject.metricName) missingFields.push("metric_name");
|
|
921
|
-
if (!traceObject.instructions) missingFields.push("instructions");
|
|
922
|
-
if (!traceObject.globalRunId) missingFields.push("global_run_id");
|
|
923
|
-
if (!traceObject.runId) missingFields.push("run_id");
|
|
924
|
-
if (missingFields.length > 0) {
|
|
925
|
-
if (logger) {
|
|
926
|
-
logger.warn("Skipping evaluation storage due to missing required fields", {
|
|
927
|
-
missingFields,
|
|
928
|
-
runId: traceObject.runId,
|
|
929
|
-
agentName: traceObject.agentName
|
|
930
|
-
});
|
|
931
|
-
} else {
|
|
932
|
-
console.warn("Skipping evaluation storage due to missing required fields", {
|
|
933
|
-
missingFields,
|
|
934
|
-
runId: traceObject.runId,
|
|
935
|
-
agentName: traceObject.agentName
|
|
936
|
-
});
|
|
937
|
-
}
|
|
938
|
-
return false;
|
|
939
|
-
}
|
|
940
|
-
return true;
|
|
941
|
-
}
|
|
942
|
-
function detectSingleMessageCharacteristics(message) {
|
|
943
|
-
if (typeof message === "object" && message !== null && (message.role === "function" || // UI-only role
|
|
944
|
-
message.role === "data" || // UI-only role
|
|
945
|
-
"toolInvocations" in message || // UI-specific field
|
|
946
|
-
"parts" in message || // UI-specific field
|
|
947
|
-
"experimental_attachments" in message)) {
|
|
948
|
-
return "has-ui-specific-parts";
|
|
949
|
-
} else if (typeof message === "object" && message !== null && "content" in message && (Array.isArray(message.content) || // Core messages can have array content
|
|
950
|
-
"experimental_providerMetadata" in message || "providerOptions" in message)) {
|
|
951
|
-
return "has-core-specific-parts";
|
|
952
|
-
} else if (typeof message === "object" && message !== null && "role" in message && "content" in message && typeof message.content === "string" && ["system", "user", "assistant", "tool"].includes(message.role)) {
|
|
953
|
-
return "message";
|
|
954
|
-
} else {
|
|
955
|
-
return "other";
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
function isUiMessage(message) {
|
|
959
|
-
return detectSingleMessageCharacteristics(message) === `has-ui-specific-parts`;
|
|
960
|
-
}
|
|
961
|
-
function isCoreMessage(message) {
|
|
962
|
-
return [`has-core-specific-parts`, `message`].includes(detectSingleMessageCharacteristics(message));
|
|
963
|
-
}
|
|
964
|
-
var SQL_IDENTIFIER_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
965
|
-
function parseSqlIdentifier(name, kind = "identifier") {
|
|
966
|
-
if (!SQL_IDENTIFIER_PATTERN.test(name) || name.length > 63) {
|
|
967
|
-
throw new Error(
|
|
968
|
-
`Invalid ${kind}: ${name}. Must start with a letter or underscore, contain only letters, numbers, or underscores, and be at most 63 characters long.`
|
|
969
|
-
);
|
|
970
|
-
}
|
|
971
|
-
return name;
|
|
972
|
-
}
|
|
973
|
-
function parseFieldKey(key) {
|
|
974
|
-
if (!key) throw new Error("Field key cannot be empty");
|
|
975
|
-
const segments = key.split(".");
|
|
976
|
-
for (const segment of segments) {
|
|
977
|
-
if (!SQL_IDENTIFIER_PATTERN.test(segment) || segment.length > 63) {
|
|
978
|
-
throw new Error(`Invalid field key segment: ${segment} in ${key}`);
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
return key;
|
|
982
|
-
}
|
|
983
|
-
async function fetchWithRetry(url, options = {}, maxRetries = 3) {
|
|
984
|
-
let retryCount = 0;
|
|
985
|
-
let lastError = null;
|
|
986
|
-
while (retryCount < maxRetries) {
|
|
987
|
-
try {
|
|
988
|
-
const response = await fetch(url, options);
|
|
989
|
-
if (!response.ok) {
|
|
990
|
-
throw new Error(`Request failed with status: ${response.status} ${response.statusText}`);
|
|
991
|
-
}
|
|
992
|
-
return response;
|
|
993
|
-
} catch (error) {
|
|
994
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
995
|
-
retryCount++;
|
|
996
|
-
if (retryCount >= maxRetries) {
|
|
997
|
-
break;
|
|
998
|
-
}
|
|
999
|
-
const delay2 = Math.min(1e3 * Math.pow(2, retryCount) * 1e3, 1e4);
|
|
1000
|
-
await new Promise((resolve) => setTimeout(resolve, delay2));
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
throw lastError || new Error("Request failed after multiple retry attempts");
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
// src/ai-tracing/exporters/cloud.ts
|
|
1007
|
-
var CloudExporter = class extends BaseExporter {
|
|
1008
|
-
name = "mastra-cloud-ai-tracing-exporter";
|
|
1009
|
-
config;
|
|
1010
|
-
buffer;
|
|
1011
|
-
flushTimer = null;
|
|
1012
|
-
constructor(config = {}) {
|
|
1013
|
-
super(config);
|
|
1014
|
-
const accessToken = config.accessToken ?? process.env.MASTRA_CLOUD_ACCESS_TOKEN;
|
|
1015
|
-
if (!accessToken) {
|
|
1016
|
-
this.setDisabled(
|
|
1017
|
-
"MASTRA_CLOUD_ACCESS_TOKEN environment variable not set. \u{1F680} Sign up for Mastra Cloud at https://cloud.mastra.ai to see your AI traces online and obtain your access token."
|
|
1018
|
-
);
|
|
1019
|
-
}
|
|
1020
|
-
const endpoint = config.endpoint ?? process.env.MASTRA_CLOUD_AI_TRACES_ENDPOINT ?? "https://api.mastra.ai/ai/spans/publish";
|
|
1021
|
-
this.config = {
|
|
1022
|
-
logger: this.logger,
|
|
1023
|
-
logLevel: config.logLevel ?? chunkA5KDVZDL_cjs.LogLevel.INFO,
|
|
1024
|
-
maxBatchSize: config.maxBatchSize ?? 1e3,
|
|
1025
|
-
maxBatchWaitMs: config.maxBatchWaitMs ?? 5e3,
|
|
1026
|
-
maxRetries: config.maxRetries ?? 3,
|
|
1027
|
-
accessToken: accessToken || "",
|
|
1028
|
-
endpoint
|
|
1029
|
-
};
|
|
1030
|
-
this.buffer = {
|
|
1031
|
-
spans: [],
|
|
1032
|
-
totalSize: 0
|
|
1033
|
-
};
|
|
1034
|
-
}
|
|
1035
|
-
async _exportEvent(event) {
|
|
1036
|
-
if (event.type !== "span_ended" /* SPAN_ENDED */) {
|
|
1037
|
-
return;
|
|
1038
|
-
}
|
|
1039
|
-
this.addToBuffer(event);
|
|
1040
|
-
if (this.shouldFlush()) {
|
|
1041
|
-
this.flush().catch((error) => {
|
|
1042
|
-
this.logger.error("Batch flush failed", {
|
|
1043
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1044
|
-
});
|
|
1045
|
-
});
|
|
1046
|
-
} else if (this.buffer.totalSize === 1) {
|
|
1047
|
-
this.scheduleFlush();
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
addToBuffer(event) {
|
|
1051
|
-
if (this.buffer.totalSize === 0) {
|
|
1052
|
-
this.buffer.firstEventTime = /* @__PURE__ */ new Date();
|
|
1053
|
-
}
|
|
1054
|
-
const spanRecord = this.formatSpan(event.exportedSpan);
|
|
1055
|
-
this.buffer.spans.push(spanRecord);
|
|
1056
|
-
this.buffer.totalSize++;
|
|
1057
|
-
}
|
|
1058
|
-
formatSpan(span) {
|
|
1059
|
-
const spanRecord = {
|
|
1060
|
-
traceId: span.traceId,
|
|
1061
|
-
spanId: span.id,
|
|
1062
|
-
parentSpanId: span.parentSpanId ?? null,
|
|
1063
|
-
name: span.name,
|
|
1064
|
-
spanType: span.type,
|
|
1065
|
-
attributes: span.attributes ?? null,
|
|
1066
|
-
metadata: span.metadata ?? null,
|
|
1067
|
-
startedAt: span.startTime,
|
|
1068
|
-
endedAt: span.endTime ?? null,
|
|
1069
|
-
input: span.input ?? null,
|
|
1070
|
-
output: span.output ?? null,
|
|
1071
|
-
error: span.errorInfo,
|
|
1072
|
-
isEvent: span.isEvent,
|
|
1073
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
1074
|
-
updatedAt: null
|
|
1075
|
-
};
|
|
1076
|
-
return spanRecord;
|
|
1077
|
-
}
|
|
1078
|
-
shouldFlush() {
|
|
1079
|
-
if (this.buffer.totalSize >= this.config.maxBatchSize) {
|
|
1080
|
-
return true;
|
|
1081
|
-
}
|
|
1082
|
-
if (this.buffer.firstEventTime && this.buffer.totalSize > 0) {
|
|
1083
|
-
const elapsed = Date.now() - this.buffer.firstEventTime.getTime();
|
|
1084
|
-
if (elapsed >= this.config.maxBatchWaitMs) {
|
|
1085
|
-
return true;
|
|
1086
|
-
}
|
|
1087
|
-
}
|
|
1088
|
-
return false;
|
|
1089
|
-
}
|
|
1090
|
-
scheduleFlush() {
|
|
1091
|
-
if (this.flushTimer) {
|
|
1092
|
-
clearTimeout(this.flushTimer);
|
|
1093
|
-
}
|
|
1094
|
-
this.flushTimer = setTimeout(() => {
|
|
1095
|
-
this.flush().catch((error) => {
|
|
1096
|
-
const mastraError = new chunk5NTO7S5I_cjs.MastraError(
|
|
1097
|
-
{
|
|
1098
|
-
id: `CLOUD_AI_TRACING_FAILED_TO_SCHEDULE_FLUSH`,
|
|
1099
|
-
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
1100
|
-
category: "USER" /* USER */
|
|
1101
|
-
},
|
|
1102
|
-
error
|
|
1103
|
-
);
|
|
1104
|
-
this.logger.trackException(mastraError);
|
|
1105
|
-
this.logger.error("Scheduled flush failed", mastraError);
|
|
1106
|
-
});
|
|
1107
|
-
}, this.config.maxBatchWaitMs);
|
|
1108
|
-
}
|
|
1109
|
-
async flush() {
|
|
1110
|
-
if (this.flushTimer) {
|
|
1111
|
-
clearTimeout(this.flushTimer);
|
|
1112
|
-
this.flushTimer = null;
|
|
1113
|
-
}
|
|
1114
|
-
if (this.buffer.totalSize === 0) {
|
|
1115
|
-
return;
|
|
1116
|
-
}
|
|
1117
|
-
const startTime = Date.now();
|
|
1118
|
-
const spansCopy = [...this.buffer.spans];
|
|
1119
|
-
const flushReason = this.buffer.totalSize >= this.config.maxBatchSize ? "size" : "time";
|
|
1120
|
-
this.resetBuffer();
|
|
1121
|
-
try {
|
|
1122
|
-
await this.batchUpload(spansCopy);
|
|
1123
|
-
const elapsed = Date.now() - startTime;
|
|
1124
|
-
this.logger.debug("Batch flushed successfully", {
|
|
1125
|
-
batchSize: spansCopy.length,
|
|
1126
|
-
flushReason,
|
|
1127
|
-
durationMs: elapsed
|
|
1128
|
-
});
|
|
1129
|
-
} catch (error) {
|
|
1130
|
-
const mastraError = new chunk5NTO7S5I_cjs.MastraError(
|
|
1131
|
-
{
|
|
1132
|
-
id: `CLOUD_AI_TRACING_FAILED_TO_BATCH_UPLOAD`,
|
|
1133
|
-
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
1134
|
-
category: "USER" /* USER */,
|
|
1135
|
-
details: {
|
|
1136
|
-
droppedBatchSize: spansCopy.length
|
|
1137
|
-
}
|
|
1138
|
-
},
|
|
1139
|
-
error
|
|
1140
|
-
);
|
|
1141
|
-
this.logger.trackException(mastraError);
|
|
1142
|
-
this.logger.error("Batch upload failed after all retries, dropping batch", mastraError);
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
/**
|
|
1146
|
-
* Uploads spans to cloud API using fetchWithRetry for all retry logic
|
|
1147
|
-
*/
|
|
1148
|
-
async batchUpload(spans) {
|
|
1149
|
-
const headers = {
|
|
1150
|
-
Authorization: `Bearer ${this.config.accessToken}`,
|
|
1151
|
-
"Content-Type": "application/json"
|
|
1152
|
-
};
|
|
1153
|
-
const options = {
|
|
1154
|
-
method: "POST",
|
|
1155
|
-
headers,
|
|
1156
|
-
body: JSON.stringify({ spans })
|
|
1157
|
-
};
|
|
1158
|
-
await fetchWithRetry(this.config.endpoint, options, this.config.maxRetries);
|
|
1159
|
-
}
|
|
1160
|
-
resetBuffer() {
|
|
1161
|
-
this.buffer.spans = [];
|
|
1162
|
-
this.buffer.firstEventTime = void 0;
|
|
1163
|
-
this.buffer.totalSize = 0;
|
|
1164
|
-
}
|
|
1165
|
-
async shutdown() {
|
|
1166
|
-
if (this.isDisabled) {
|
|
1167
|
-
return;
|
|
1168
|
-
}
|
|
1169
|
-
if (this.flushTimer) {
|
|
1170
|
-
clearTimeout(this.flushTimer);
|
|
1171
|
-
this.flushTimer = null;
|
|
1172
|
-
}
|
|
1173
|
-
if (this.buffer.totalSize > 0) {
|
|
1174
|
-
this.logger.info("Flushing remaining events on shutdown", {
|
|
1175
|
-
remainingEvents: this.buffer.totalSize
|
|
1176
|
-
});
|
|
1177
|
-
try {
|
|
1178
|
-
await this.flush();
|
|
1179
|
-
} catch (error) {
|
|
1180
|
-
const mastraError = new chunk5NTO7S5I_cjs.MastraError(
|
|
1181
|
-
{
|
|
1182
|
-
id: `CLOUD_AI_TRACING_FAILED_TO_FLUSH_REMAINING_EVENTS_DURING_SHUTDOWN`,
|
|
1183
|
-
domain: "MASTRA_OBSERVABILITY" /* MASTRA_OBSERVABILITY */,
|
|
1184
|
-
category: "USER" /* USER */,
|
|
1185
|
-
details: {
|
|
1186
|
-
remainingEvents: this.buffer.totalSize
|
|
1187
|
-
}
|
|
1188
|
-
},
|
|
1189
|
-
error
|
|
1190
|
-
);
|
|
1191
|
-
this.logger.trackException(mastraError);
|
|
1192
|
-
this.logger.error("Failed to flush remaining events during shutdown", mastraError);
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
this.logger.info("CloudExporter shutdown complete");
|
|
1196
|
-
}
|
|
1197
|
-
};
|
|
1198
|
-
|
|
1199
|
-
// src/ai-tracing/exporters/console.ts
|
|
1200
|
-
var ConsoleExporter = class extends BaseExporter {
|
|
1201
|
-
name = "tracing-console-exporter";
|
|
1202
|
-
constructor(config = {}) {
|
|
1203
|
-
super(config);
|
|
1204
|
-
}
|
|
1205
|
-
async _exportEvent(event) {
|
|
1206
|
-
const span = event.exportedSpan;
|
|
1207
|
-
const formatAttributes = (attributes) => {
|
|
1208
|
-
try {
|
|
1209
|
-
return JSON.stringify(attributes, null, 2);
|
|
1210
|
-
} catch (error) {
|
|
1211
|
-
const errMsg = error instanceof Error ? error.message : "Unknown formatting error";
|
|
1212
|
-
return `[Unable to serialize attributes: ${errMsg}]`;
|
|
1213
|
-
}
|
|
1214
|
-
};
|
|
1215
|
-
const formatDuration = (startTime, endTime) => {
|
|
1216
|
-
if (!endTime) return "N/A";
|
|
1217
|
-
const duration = endTime.getTime() - startTime.getTime();
|
|
1218
|
-
return `${duration}ms`;
|
|
1219
|
-
};
|
|
1220
|
-
switch (event.type) {
|
|
1221
|
-
case "span_started" /* SPAN_STARTED */:
|
|
1222
|
-
this.logger.info(`\u{1F680} SPAN_STARTED`);
|
|
1223
|
-
this.logger.info(` Type: ${span.type}`);
|
|
1224
|
-
this.logger.info(` Name: ${span.name}`);
|
|
1225
|
-
this.logger.info(` ID: ${span.id}`);
|
|
1226
|
-
this.logger.info(` Trace ID: ${span.traceId}`);
|
|
1227
|
-
if (span.input !== void 0) {
|
|
1228
|
-
this.logger.info(` Input: ${formatAttributes(span.input)}`);
|
|
1229
|
-
}
|
|
1230
|
-
this.logger.info(` Attributes: ${formatAttributes(span.attributes)}`);
|
|
1231
|
-
this.logger.info("\u2500".repeat(80));
|
|
1232
|
-
break;
|
|
1233
|
-
case "span_ended" /* SPAN_ENDED */:
|
|
1234
|
-
const duration = formatDuration(span.startTime, span.endTime);
|
|
1235
|
-
this.logger.info(`\u2705 SPAN_ENDED`);
|
|
1236
|
-
this.logger.info(` Type: ${span.type}`);
|
|
1237
|
-
this.logger.info(` Name: ${span.name}`);
|
|
1238
|
-
this.logger.info(` ID: ${span.id}`);
|
|
1239
|
-
this.logger.info(` Duration: ${duration}`);
|
|
1240
|
-
this.logger.info(` Trace ID: ${span.traceId}`);
|
|
1241
|
-
if (span.input !== void 0) {
|
|
1242
|
-
this.logger.info(` Input: ${formatAttributes(span.input)}`);
|
|
1243
|
-
}
|
|
1244
|
-
if (span.output !== void 0) {
|
|
1245
|
-
this.logger.info(` Output: ${formatAttributes(span.output)}`);
|
|
1246
|
-
}
|
|
1247
|
-
if (span.errorInfo) {
|
|
1248
|
-
this.logger.info(` Error: ${formatAttributes(span.errorInfo)}`);
|
|
1249
|
-
}
|
|
1250
|
-
this.logger.info(` Attributes: ${formatAttributes(span.attributes)}`);
|
|
1251
|
-
this.logger.info("\u2500".repeat(80));
|
|
1252
|
-
break;
|
|
1253
|
-
case "span_updated" /* SPAN_UPDATED */:
|
|
1254
|
-
this.logger.info(`\u{1F4DD} SPAN_UPDATED`);
|
|
1255
|
-
this.logger.info(` Type: ${span.type}`);
|
|
1256
|
-
this.logger.info(` Name: ${span.name}`);
|
|
1257
|
-
this.logger.info(` ID: ${span.id}`);
|
|
1258
|
-
this.logger.info(` Trace ID: ${span.traceId}`);
|
|
1259
|
-
if (span.input !== void 0) {
|
|
1260
|
-
this.logger.info(` Input: ${formatAttributes(span.input)}`);
|
|
1261
|
-
}
|
|
1262
|
-
if (span.output !== void 0) {
|
|
1263
|
-
this.logger.info(` Output: ${formatAttributes(span.output)}`);
|
|
1264
|
-
}
|
|
1265
|
-
if (span.errorInfo) {
|
|
1266
|
-
this.logger.info(` Error: ${formatAttributes(span.errorInfo)}`);
|
|
1267
|
-
}
|
|
1268
|
-
this.logger.info(` Updated Attributes: ${formatAttributes(span.attributes)}`);
|
|
1269
|
-
this.logger.info("\u2500".repeat(80));
|
|
1270
|
-
break;
|
|
1271
|
-
default:
|
|
1272
|
-
this.logger.warn(`Tracing event type not implemented: ${event.type}`);
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
async shutdown() {
|
|
1276
|
-
this.logger.info("ConsoleExporter shutdown");
|
|
1277
|
-
}
|
|
1278
|
-
};
|
|
1279
|
-
|
|
1280
|
-
// src/ai-tracing/exporters/default.ts
|
|
1281
|
-
function resolveStrategy(userConfig, storage, logger) {
|
|
1282
|
-
if (userConfig.strategy && userConfig.strategy !== "auto") {
|
|
1283
|
-
const hints = storage.aiTracingStrategy;
|
|
1284
|
-
if (hints.supported.includes(userConfig.strategy)) {
|
|
1285
|
-
return userConfig.strategy;
|
|
1286
|
-
}
|
|
1287
|
-
logger.warn("User-specified AI tracing strategy not supported by storage adapter, falling back to auto-selection", {
|
|
1288
|
-
userStrategy: userConfig.strategy,
|
|
1289
|
-
storageAdapter: storage.constructor.name,
|
|
1290
|
-
supportedStrategies: hints.supported,
|
|
1291
|
-
fallbackStrategy: hints.preferred
|
|
1292
|
-
});
|
|
1293
|
-
}
|
|
1294
|
-
return storage.aiTracingStrategy.preferred;
|
|
1295
|
-
}
|
|
1296
|
-
var DefaultExporter = class {
|
|
1297
|
-
name = "tracing-default-exporter";
|
|
1298
|
-
logger;
|
|
1299
|
-
mastra = null;
|
|
1300
|
-
config;
|
|
1301
|
-
resolvedStrategy;
|
|
1302
|
-
buffer;
|
|
1303
|
-
flushTimer = null;
|
|
1304
|
-
// Track all spans that have been created, persists across flushes
|
|
1305
|
-
allCreatedSpans = /* @__PURE__ */ new Set();
|
|
1306
|
-
constructor(config = {}, logger) {
|
|
1307
|
-
if (logger) {
|
|
1308
|
-
this.logger = logger;
|
|
1309
|
-
} else {
|
|
1310
|
-
this.logger = new chunkA5KDVZDL_cjs.ConsoleLogger({ level: chunkA5KDVZDL_cjs.LogLevel.INFO });
|
|
1311
|
-
}
|
|
1312
|
-
this.config = {
|
|
1313
|
-
maxBatchSize: config.maxBatchSize ?? 1e3,
|
|
1314
|
-
maxBufferSize: config.maxBufferSize ?? 1e4,
|
|
1315
|
-
maxBatchWaitMs: config.maxBatchWaitMs ?? 5e3,
|
|
1316
|
-
maxRetries: config.maxRetries ?? 4,
|
|
1317
|
-
retryDelayMs: config.retryDelayMs ?? 500,
|
|
1318
|
-
strategy: config.strategy ?? "auto"
|
|
1319
|
-
};
|
|
1320
|
-
this.buffer = {
|
|
1321
|
-
creates: [],
|
|
1322
|
-
updates: [],
|
|
1323
|
-
insertOnly: [],
|
|
1324
|
-
seenSpans: /* @__PURE__ */ new Set(),
|
|
1325
|
-
spanSequences: /* @__PURE__ */ new Map(),
|
|
1326
|
-
completedSpans: /* @__PURE__ */ new Set(),
|
|
1327
|
-
outOfOrderCount: 0,
|
|
1328
|
-
totalSize: 0
|
|
1329
|
-
};
|
|
1330
|
-
this.resolvedStrategy = "batch-with-updates";
|
|
1331
|
-
}
|
|
1332
|
-
strategyInitialized = false;
|
|
1333
|
-
/**
|
|
1334
|
-
* Register the Mastra instance (called after Mastra construction is complete)
|
|
1335
|
-
*/
|
|
1336
|
-
__registerMastra(mastra) {
|
|
1337
|
-
this.mastra = mastra;
|
|
1338
|
-
}
|
|
1339
|
-
/**
|
|
1340
|
-
* Initialize the exporter (called after all dependencies are ready)
|
|
1341
|
-
*/
|
|
1342
|
-
init(_config) {
|
|
1343
|
-
if (!this.mastra) {
|
|
1344
|
-
throw new Error("DefaultExporter: init() called before __registerMastra()");
|
|
1345
|
-
}
|
|
1346
|
-
const storage = this.mastra.getStorage();
|
|
1347
|
-
if (!storage) {
|
|
1348
|
-
this.logger.warn("DefaultExporter disabled: Storage not available. Traces will not be persisted.");
|
|
1349
|
-
return;
|
|
1350
|
-
}
|
|
1351
|
-
this.initializeStrategy(storage);
|
|
1352
|
-
}
|
|
1353
|
-
/**
|
|
1354
|
-
* Initialize the resolved strategy once storage is available
|
|
1355
|
-
*/
|
|
1356
|
-
initializeStrategy(storage) {
|
|
1357
|
-
if (this.strategyInitialized) return;
|
|
1358
|
-
this.resolvedStrategy = resolveStrategy(this.config, storage, this.logger);
|
|
1359
|
-
this.strategyInitialized = true;
|
|
1360
|
-
this.logger.debug("AI tracing exporter initialized", {
|
|
1361
|
-
strategy: this.resolvedStrategy,
|
|
1362
|
-
source: this.config.strategy !== "auto" ? "user" : "auto",
|
|
1363
|
-
storageAdapter: storage.constructor.name,
|
|
1364
|
-
maxBatchSize: this.config.maxBatchSize,
|
|
1365
|
-
maxBatchWaitMs: this.config.maxBatchWaitMs
|
|
1366
|
-
});
|
|
1367
|
-
}
|
|
1368
|
-
/**
|
|
1369
|
-
* Builds a unique span key for tracking
|
|
1370
|
-
*/
|
|
1371
|
-
buildSpanKey(traceId, spanId) {
|
|
1372
|
-
return `${traceId}:${spanId}`;
|
|
1373
|
-
}
|
|
1374
|
-
/**
|
|
1375
|
-
* Gets the next sequence number for a span
|
|
1376
|
-
*/
|
|
1377
|
-
getNextSequence(spanKey) {
|
|
1378
|
-
const current = this.buffer.spanSequences.get(spanKey) || 0;
|
|
1379
|
-
const next = current + 1;
|
|
1380
|
-
this.buffer.spanSequences.set(spanKey, next);
|
|
1381
|
-
return next;
|
|
1382
|
-
}
|
|
1383
|
-
/**
|
|
1384
|
-
* Handles out-of-order span updates by logging and skipping
|
|
1385
|
-
*/
|
|
1386
|
-
handleOutOfOrderUpdate(event) {
|
|
1387
|
-
this.logger.warn("Out-of-order span update detected - skipping event", {
|
|
1388
|
-
spanId: event.exportedSpan.id,
|
|
1389
|
-
traceId: event.exportedSpan.traceId,
|
|
1390
|
-
spanName: event.exportedSpan.name,
|
|
1391
|
-
eventType: event.type
|
|
1392
|
-
});
|
|
1393
|
-
}
|
|
1394
|
-
/**
|
|
1395
|
-
* Adds an event to the appropriate buffer based on strategy
|
|
1396
|
-
*/
|
|
1397
|
-
addToBuffer(event) {
|
|
1398
|
-
const spanKey = this.buildSpanKey(event.exportedSpan.traceId, event.exportedSpan.id);
|
|
1399
|
-
if (this.buffer.totalSize === 0) {
|
|
1400
|
-
this.buffer.firstEventTime = /* @__PURE__ */ new Date();
|
|
1401
|
-
}
|
|
1402
|
-
switch (event.type) {
|
|
1403
|
-
case "span_started" /* SPAN_STARTED */:
|
|
1404
|
-
if (this.resolvedStrategy === "batch-with-updates") {
|
|
1405
|
-
const createRecord = this.buildCreateRecord(event.exportedSpan);
|
|
1406
|
-
this.buffer.creates.push(createRecord);
|
|
1407
|
-
this.buffer.seenSpans.add(spanKey);
|
|
1408
|
-
this.allCreatedSpans.add(spanKey);
|
|
1409
|
-
}
|
|
1410
|
-
break;
|
|
1411
|
-
case "span_updated" /* SPAN_UPDATED */:
|
|
1412
|
-
if (this.resolvedStrategy === "batch-with-updates") {
|
|
1413
|
-
if (this.allCreatedSpans.has(spanKey)) {
|
|
1414
|
-
this.buffer.updates.push({
|
|
1415
|
-
traceId: event.exportedSpan.traceId,
|
|
1416
|
-
spanId: event.exportedSpan.id,
|
|
1417
|
-
updates: this.buildUpdateRecord(event.exportedSpan),
|
|
1418
|
-
sequenceNumber: this.getNextSequence(spanKey)
|
|
1419
|
-
});
|
|
1420
|
-
} else {
|
|
1421
|
-
this.handleOutOfOrderUpdate(event);
|
|
1422
|
-
this.buffer.outOfOrderCount++;
|
|
1423
|
-
}
|
|
1424
|
-
}
|
|
1425
|
-
break;
|
|
1426
|
-
case "span_ended" /* SPAN_ENDED */:
|
|
1427
|
-
if (this.resolvedStrategy === "batch-with-updates") {
|
|
1428
|
-
if (this.allCreatedSpans.has(spanKey)) {
|
|
1429
|
-
this.buffer.updates.push({
|
|
1430
|
-
traceId: event.exportedSpan.traceId,
|
|
1431
|
-
spanId: event.exportedSpan.id,
|
|
1432
|
-
updates: this.buildUpdateRecord(event.exportedSpan),
|
|
1433
|
-
sequenceNumber: this.getNextSequence(spanKey)
|
|
1434
|
-
});
|
|
1435
|
-
this.buffer.completedSpans.add(spanKey);
|
|
1436
|
-
} else if (event.exportedSpan.isEvent) {
|
|
1437
|
-
const createRecord = this.buildCreateRecord(event.exportedSpan);
|
|
1438
|
-
this.buffer.creates.push(createRecord);
|
|
1439
|
-
this.buffer.seenSpans.add(spanKey);
|
|
1440
|
-
this.allCreatedSpans.add(spanKey);
|
|
1441
|
-
this.buffer.completedSpans.add(spanKey);
|
|
1442
|
-
} else {
|
|
1443
|
-
this.handleOutOfOrderUpdate(event);
|
|
1444
|
-
this.buffer.outOfOrderCount++;
|
|
1445
|
-
}
|
|
1446
|
-
} else if (this.resolvedStrategy === "insert-only") {
|
|
1447
|
-
const createRecord = this.buildCreateRecord(event.exportedSpan);
|
|
1448
|
-
this.buffer.insertOnly.push(createRecord);
|
|
1449
|
-
this.buffer.completedSpans.add(spanKey);
|
|
1450
|
-
this.allCreatedSpans.add(spanKey);
|
|
1451
|
-
}
|
|
1452
|
-
break;
|
|
1453
|
-
}
|
|
1454
|
-
this.buffer.totalSize = this.buffer.creates.length + this.buffer.updates.length + this.buffer.insertOnly.length;
|
|
1455
|
-
}
|
|
1456
|
-
/**
|
|
1457
|
-
* Checks if buffer should be flushed based on size or time triggers
|
|
1458
|
-
*/
|
|
1459
|
-
shouldFlush() {
|
|
1460
|
-
if (this.buffer.totalSize >= this.config.maxBufferSize) {
|
|
1461
|
-
return true;
|
|
1462
|
-
}
|
|
1463
|
-
if (this.buffer.totalSize >= this.config.maxBatchSize) {
|
|
1464
|
-
return true;
|
|
1465
|
-
}
|
|
1466
|
-
if (this.buffer.firstEventTime && this.buffer.totalSize > 0) {
|
|
1467
|
-
const elapsed = Date.now() - this.buffer.firstEventTime.getTime();
|
|
1468
|
-
if (elapsed >= this.config.maxBatchWaitMs) {
|
|
1469
|
-
return true;
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
return false;
|
|
1473
|
-
}
|
|
1474
|
-
/**
|
|
1475
|
-
* Resets the buffer after successful flush
|
|
1476
|
-
*/
|
|
1477
|
-
resetBuffer(completedSpansToCleanup = /* @__PURE__ */ new Set()) {
|
|
1478
|
-
this.buffer.creates = [];
|
|
1479
|
-
this.buffer.updates = [];
|
|
1480
|
-
this.buffer.insertOnly = [];
|
|
1481
|
-
this.buffer.seenSpans.clear();
|
|
1482
|
-
this.buffer.spanSequences.clear();
|
|
1483
|
-
this.buffer.completedSpans.clear();
|
|
1484
|
-
this.buffer.outOfOrderCount = 0;
|
|
1485
|
-
this.buffer.firstEventTime = void 0;
|
|
1486
|
-
this.buffer.totalSize = 0;
|
|
1487
|
-
for (const spanKey of completedSpansToCleanup) {
|
|
1488
|
-
this.allCreatedSpans.delete(spanKey);
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
/**
|
|
1492
|
-
* Schedules a flush using setTimeout
|
|
1493
|
-
*/
|
|
1494
|
-
scheduleFlush() {
|
|
1495
|
-
if (this.flushTimer) {
|
|
1496
|
-
clearTimeout(this.flushTimer);
|
|
1497
|
-
}
|
|
1498
|
-
this.flushTimer = setTimeout(() => {
|
|
1499
|
-
this.flush().catch((error) => {
|
|
1500
|
-
this.logger.error("Scheduled flush failed", {
|
|
1501
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1502
|
-
});
|
|
1503
|
-
});
|
|
1504
|
-
}, this.config.maxBatchWaitMs);
|
|
1505
|
-
}
|
|
1506
|
-
/**
|
|
1507
|
-
* Serializes span attributes to storage record format
|
|
1508
|
-
* Handles all AI span types and their specific attributes
|
|
1509
|
-
*/
|
|
1510
|
-
serializeAttributes(span) {
|
|
1511
|
-
if (!span.attributes) {
|
|
1512
|
-
return null;
|
|
1513
|
-
}
|
|
1514
|
-
try {
|
|
1515
|
-
return JSON.parse(
|
|
1516
|
-
JSON.stringify(span.attributes, (_key, value) => {
|
|
1517
|
-
if (value instanceof Date) {
|
|
1518
|
-
return value.toISOString();
|
|
1519
|
-
}
|
|
1520
|
-
if (typeof value === "object" && value !== null) {
|
|
1521
|
-
return value;
|
|
1522
|
-
}
|
|
1523
|
-
return value;
|
|
1524
|
-
})
|
|
1525
|
-
);
|
|
1526
|
-
} catch (error) {
|
|
1527
|
-
this.logger.warn("Failed to serialize span attributes, storing as null", {
|
|
1528
|
-
spanId: span.id,
|
|
1529
|
-
spanType: span.type,
|
|
1530
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1531
|
-
});
|
|
1532
|
-
return null;
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
buildCreateRecord(span) {
|
|
1536
|
-
return {
|
|
1537
|
-
traceId: span.traceId,
|
|
1538
|
-
spanId: span.id,
|
|
1539
|
-
parentSpanId: span.parentSpanId ?? null,
|
|
1540
|
-
name: span.name,
|
|
1541
|
-
scope: null,
|
|
1542
|
-
spanType: span.type,
|
|
1543
|
-
attributes: this.serializeAttributes(span),
|
|
1544
|
-
metadata: span.metadata ?? null,
|
|
1545
|
-
links: null,
|
|
1546
|
-
startedAt: span.startTime,
|
|
1547
|
-
endedAt: span.endTime ?? null,
|
|
1548
|
-
input: span.input,
|
|
1549
|
-
output: span.output,
|
|
1550
|
-
error: span.errorInfo,
|
|
1551
|
-
isEvent: span.isEvent
|
|
1552
|
-
};
|
|
1553
|
-
}
|
|
1554
|
-
buildUpdateRecord(span) {
|
|
1555
|
-
return {
|
|
1556
|
-
name: span.name,
|
|
1557
|
-
scope: null,
|
|
1558
|
-
attributes: this.serializeAttributes(span),
|
|
1559
|
-
metadata: span.metadata ?? null,
|
|
1560
|
-
links: null,
|
|
1561
|
-
endedAt: span.endTime ?? null,
|
|
1562
|
-
input: span.input,
|
|
1563
|
-
output: span.output,
|
|
1564
|
-
error: span.errorInfo
|
|
1565
|
-
};
|
|
1566
|
-
}
|
|
1567
|
-
/**
|
|
1568
|
-
* Handles realtime strategy - processes each event immediately
|
|
1569
|
-
*/
|
|
1570
|
-
async handleRealtimeEvent(event, storage) {
|
|
1571
|
-
const span = event.exportedSpan;
|
|
1572
|
-
const spanKey = this.buildSpanKey(span.traceId, span.id);
|
|
1573
|
-
if (span.isEvent) {
|
|
1574
|
-
if (event.type === "span_ended" /* SPAN_ENDED */) {
|
|
1575
|
-
await storage.createAISpan(this.buildCreateRecord(event.exportedSpan));
|
|
1576
|
-
} else {
|
|
1577
|
-
this.logger.warn(`Tracing event type not implemented for event spans: ${event.type}`);
|
|
1578
|
-
}
|
|
1579
|
-
} else {
|
|
1580
|
-
switch (event.type) {
|
|
1581
|
-
case "span_started" /* SPAN_STARTED */:
|
|
1582
|
-
await storage.createAISpan(this.buildCreateRecord(event.exportedSpan));
|
|
1583
|
-
this.allCreatedSpans.add(spanKey);
|
|
1584
|
-
break;
|
|
1585
|
-
case "span_updated" /* SPAN_UPDATED */:
|
|
1586
|
-
await storage.updateAISpan({
|
|
1587
|
-
traceId: span.traceId,
|
|
1588
|
-
spanId: span.id,
|
|
1589
|
-
updates: this.buildUpdateRecord(span)
|
|
1590
|
-
});
|
|
1591
|
-
break;
|
|
1592
|
-
case "span_ended" /* SPAN_ENDED */:
|
|
1593
|
-
await storage.updateAISpan({
|
|
1594
|
-
traceId: span.traceId,
|
|
1595
|
-
spanId: span.id,
|
|
1596
|
-
updates: this.buildUpdateRecord(span)
|
|
1597
|
-
});
|
|
1598
|
-
this.allCreatedSpans.delete(spanKey);
|
|
1599
|
-
break;
|
|
1600
|
-
default:
|
|
1601
|
-
this.logger.warn(`Tracing event type not implemented for span spans: ${event.type}`);
|
|
1602
|
-
}
|
|
1603
|
-
}
|
|
1604
|
-
}
|
|
1605
|
-
/**
|
|
1606
|
-
* Handles batch-with-updates strategy - buffers events and processes in batches
|
|
1607
|
-
*/
|
|
1608
|
-
handleBatchWithUpdatesEvent(event) {
|
|
1609
|
-
this.addToBuffer(event);
|
|
1610
|
-
if (this.shouldFlush()) {
|
|
1611
|
-
this.flush().catch((error) => {
|
|
1612
|
-
this.logger.error("Batch flush failed", {
|
|
1613
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1614
|
-
});
|
|
1615
|
-
});
|
|
1616
|
-
} else if (this.buffer.totalSize === 1) {
|
|
1617
|
-
this.scheduleFlush();
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
/**
|
|
1621
|
-
* Handles insert-only strategy - only processes SPAN_ENDED events in batches
|
|
1622
|
-
*/
|
|
1623
|
-
handleInsertOnlyEvent(event) {
|
|
1624
|
-
if (event.type === "span_ended" /* SPAN_ENDED */) {
|
|
1625
|
-
this.addToBuffer(event);
|
|
1626
|
-
if (this.shouldFlush()) {
|
|
1627
|
-
this.flush().catch((error) => {
|
|
1628
|
-
this.logger.error("Batch flush failed", {
|
|
1629
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1630
|
-
});
|
|
1631
|
-
});
|
|
1632
|
-
} else if (this.buffer.totalSize === 1) {
|
|
1633
|
-
this.scheduleFlush();
|
|
1634
|
-
}
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
/**
|
|
1638
|
-
* Calculates retry delay using exponential backoff
|
|
1639
|
-
*/
|
|
1640
|
-
calculateRetryDelay(attempt) {
|
|
1641
|
-
return this.config.retryDelayMs * Math.pow(2, attempt);
|
|
1642
|
-
}
|
|
1643
|
-
/**
|
|
1644
|
-
* Flushes the current buffer to storage with retry logic
|
|
1645
|
-
*/
|
|
1646
|
-
async flush() {
|
|
1647
|
-
if (!this.mastra) {
|
|
1648
|
-
this.logger.debug("Cannot flush traces. Mastra instance not registered yet.");
|
|
1649
|
-
return;
|
|
1650
|
-
}
|
|
1651
|
-
const storage = this.mastra.getStorage();
|
|
1652
|
-
if (!storage) {
|
|
1653
|
-
this.logger.debug("Cannot flush traces. Mastra storage is not initialized");
|
|
1654
|
-
return;
|
|
1655
|
-
}
|
|
1656
|
-
if (this.flushTimer) {
|
|
1657
|
-
clearTimeout(this.flushTimer);
|
|
1658
|
-
this.flushTimer = null;
|
|
1659
|
-
}
|
|
1660
|
-
if (this.buffer.totalSize === 0) {
|
|
1661
|
-
return;
|
|
1662
|
-
}
|
|
1663
|
-
const startTime = Date.now();
|
|
1664
|
-
const flushReason = this.buffer.totalSize >= this.config.maxBufferSize ? "overflow" : this.buffer.totalSize >= this.config.maxBatchSize ? "size" : "time";
|
|
1665
|
-
const bufferCopy = {
|
|
1666
|
-
creates: [...this.buffer.creates],
|
|
1667
|
-
updates: [...this.buffer.updates],
|
|
1668
|
-
insertOnly: [...this.buffer.insertOnly],
|
|
1669
|
-
seenSpans: new Set(this.buffer.seenSpans),
|
|
1670
|
-
spanSequences: new Map(this.buffer.spanSequences),
|
|
1671
|
-
completedSpans: new Set(this.buffer.completedSpans),
|
|
1672
|
-
outOfOrderCount: this.buffer.outOfOrderCount,
|
|
1673
|
-
firstEventTime: this.buffer.firstEventTime,
|
|
1674
|
-
totalSize: this.buffer.totalSize
|
|
1675
|
-
};
|
|
1676
|
-
this.resetBuffer();
|
|
1677
|
-
await this.flushWithRetries(storage, bufferCopy, 0);
|
|
1678
|
-
const elapsed = Date.now() - startTime;
|
|
1679
|
-
this.logger.debug("Batch flushed", {
|
|
1680
|
-
strategy: this.resolvedStrategy,
|
|
1681
|
-
batchSize: bufferCopy.totalSize,
|
|
1682
|
-
flushReason,
|
|
1683
|
-
durationMs: elapsed,
|
|
1684
|
-
outOfOrderCount: bufferCopy.outOfOrderCount > 0 ? bufferCopy.outOfOrderCount : void 0
|
|
1685
|
-
});
|
|
1686
|
-
}
|
|
1687
|
-
/**
|
|
1688
|
-
* Attempts to flush with exponential backoff retry logic
|
|
1689
|
-
*/
|
|
1690
|
-
async flushWithRetries(storage, buffer, attempt) {
|
|
1691
|
-
try {
|
|
1692
|
-
if (this.resolvedStrategy === "batch-with-updates") {
|
|
1693
|
-
if (buffer.creates.length > 0) {
|
|
1694
|
-
await storage.batchCreateAISpans({ records: buffer.creates });
|
|
1695
|
-
}
|
|
1696
|
-
if (buffer.updates.length > 0) {
|
|
1697
|
-
const sortedUpdates = buffer.updates.sort((a, b) => {
|
|
1698
|
-
const spanCompare = this.buildSpanKey(a.traceId, a.spanId).localeCompare(
|
|
1699
|
-
this.buildSpanKey(b.traceId, b.spanId)
|
|
1700
|
-
);
|
|
1701
|
-
if (spanCompare !== 0) return spanCompare;
|
|
1702
|
-
return a.sequenceNumber - b.sequenceNumber;
|
|
1703
|
-
});
|
|
1704
|
-
await storage.batchUpdateAISpans({ records: sortedUpdates });
|
|
1705
|
-
}
|
|
1706
|
-
} else if (this.resolvedStrategy === "insert-only") {
|
|
1707
|
-
if (buffer.insertOnly.length > 0) {
|
|
1708
|
-
await storage.batchCreateAISpans({ records: buffer.insertOnly });
|
|
1709
|
-
}
|
|
1710
|
-
}
|
|
1711
|
-
for (const spanKey of buffer.completedSpans) {
|
|
1712
|
-
this.allCreatedSpans.delete(spanKey);
|
|
1713
|
-
}
|
|
1714
|
-
} catch (error) {
|
|
1715
|
-
if (attempt < this.config.maxRetries) {
|
|
1716
|
-
const retryDelay = this.calculateRetryDelay(attempt);
|
|
1717
|
-
this.logger.warn("Batch flush failed, retrying", {
|
|
1718
|
-
attempt: attempt + 1,
|
|
1719
|
-
maxRetries: this.config.maxRetries,
|
|
1720
|
-
nextRetryInMs: retryDelay,
|
|
1721
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1722
|
-
});
|
|
1723
|
-
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
1724
|
-
return this.flushWithRetries(storage, buffer, attempt + 1);
|
|
1725
|
-
} else {
|
|
1726
|
-
this.logger.error("Batch flush failed after all retries, dropping batch", {
|
|
1727
|
-
finalAttempt: attempt + 1,
|
|
1728
|
-
maxRetries: this.config.maxRetries,
|
|
1729
|
-
droppedBatchSize: buffer.totalSize,
|
|
1730
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1731
|
-
});
|
|
1732
|
-
for (const spanKey of buffer.completedSpans) {
|
|
1733
|
-
this.allCreatedSpans.delete(spanKey);
|
|
1734
|
-
}
|
|
1735
|
-
}
|
|
1736
|
-
}
|
|
1737
|
-
}
|
|
1738
|
-
async exportEvent(event) {
|
|
1739
|
-
if (!this.mastra) {
|
|
1740
|
-
this.logger.debug("Cannot export AI tracing event. Mastra instance not registered yet.");
|
|
1741
|
-
return;
|
|
1742
|
-
}
|
|
1743
|
-
const storage = this.mastra.getStorage();
|
|
1744
|
-
if (!storage) {
|
|
1745
|
-
this.logger.debug("Cannot store traces. Mastra storage is not initialized");
|
|
1746
|
-
return;
|
|
1747
|
-
}
|
|
1748
|
-
if (!this.strategyInitialized) {
|
|
1749
|
-
this.initializeStrategy(storage);
|
|
1750
|
-
}
|
|
1751
|
-
switch (this.resolvedStrategy) {
|
|
1752
|
-
case "realtime":
|
|
1753
|
-
await this.handleRealtimeEvent(event, storage);
|
|
1754
|
-
break;
|
|
1755
|
-
case "batch-with-updates":
|
|
1756
|
-
this.handleBatchWithUpdatesEvent(event);
|
|
1757
|
-
break;
|
|
1758
|
-
case "insert-only":
|
|
1759
|
-
this.handleInsertOnlyEvent(event);
|
|
1760
|
-
break;
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
async shutdown() {
|
|
1764
|
-
if (this.flushTimer) {
|
|
1765
|
-
clearTimeout(this.flushTimer);
|
|
1766
|
-
this.flushTimer = null;
|
|
1767
|
-
}
|
|
1768
|
-
if (this.buffer.totalSize > 0) {
|
|
1769
|
-
this.logger.info("Flushing remaining events on shutdown", {
|
|
1770
|
-
remainingEvents: this.buffer.totalSize
|
|
1771
|
-
});
|
|
1772
|
-
try {
|
|
1773
|
-
await this.flush();
|
|
1774
|
-
} catch (error) {
|
|
1775
|
-
this.logger.error("Failed to flush remaining events during shutdown", {
|
|
1776
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1777
|
-
});
|
|
1778
|
-
}
|
|
1779
|
-
}
|
|
1780
|
-
this.logger.info("DefaultExporter shutdown complete");
|
|
1781
|
-
}
|
|
1782
|
-
};
|
|
1783
|
-
|
|
1784
|
-
// src/ai-tracing/span_processors/sensitive-data-filter.ts
|
|
1785
|
-
var SensitiveDataFilter = class {
|
|
1786
|
-
name = "sensitive-data-filter";
|
|
1787
|
-
sensitiveFields;
|
|
1788
|
-
redactionToken;
|
|
1789
|
-
redactionStyle;
|
|
1790
|
-
constructor(options = {}) {
|
|
1791
|
-
this.sensitiveFields = (options.sensitiveFields || [
|
|
1792
|
-
"password",
|
|
1793
|
-
"token",
|
|
1794
|
-
"secret",
|
|
1795
|
-
"key",
|
|
1796
|
-
"apikey",
|
|
1797
|
-
"auth",
|
|
1798
|
-
"authorization",
|
|
1799
|
-
"bearer",
|
|
1800
|
-
"bearertoken",
|
|
1801
|
-
"jwt",
|
|
1802
|
-
"credential",
|
|
1803
|
-
"clientsecret",
|
|
1804
|
-
"privatekey",
|
|
1805
|
-
"refresh",
|
|
1806
|
-
"ssn"
|
|
1807
|
-
]).map((f) => this.normalizeKey(f));
|
|
1808
|
-
this.redactionToken = options.redactionToken ?? "[REDACTED]";
|
|
1809
|
-
this.redactionStyle = options.redactionStyle ?? "full";
|
|
1810
|
-
}
|
|
1811
|
-
/**
|
|
1812
|
-
* Process a span by filtering sensitive data across its key fields.
|
|
1813
|
-
* Fields processed: attributes, metadata, input, output, errorInfo.
|
|
1814
|
-
*
|
|
1815
|
-
* @param span - The input span to filter
|
|
1816
|
-
* @returns A new span with sensitive values redacted
|
|
1817
|
-
*/
|
|
1818
|
-
process(span) {
|
|
1819
|
-
span.attributes = this.tryFilter(span.attributes);
|
|
1820
|
-
span.metadata = this.tryFilter(span.metadata);
|
|
1821
|
-
span.input = this.tryFilter(span.input);
|
|
1822
|
-
span.output = this.tryFilter(span.output);
|
|
1823
|
-
span.errorInfo = this.tryFilter(span.errorInfo);
|
|
1824
|
-
return span;
|
|
1825
|
-
}
|
|
1826
|
-
/**
|
|
1827
|
-
* Recursively filter objects/arrays for sensitive keys.
|
|
1828
|
-
* Handles circular references by replacing with a marker.
|
|
1829
|
-
*/
|
|
1830
|
-
deepFilter(obj, seen = /* @__PURE__ */ new WeakSet()) {
|
|
1831
|
-
if (obj === null || typeof obj !== "object") {
|
|
1832
|
-
return obj;
|
|
1833
|
-
}
|
|
1834
|
-
if (seen.has(obj)) {
|
|
1835
|
-
return "[Circular Reference]";
|
|
1836
|
-
}
|
|
1837
|
-
seen.add(obj);
|
|
1838
|
-
if (Array.isArray(obj)) {
|
|
1839
|
-
return obj.map((item) => this.deepFilter(item, seen));
|
|
1840
|
-
}
|
|
1841
|
-
const filtered = {};
|
|
1842
|
-
for (const key of Object.keys(obj)) {
|
|
1843
|
-
const normKey = this.normalizeKey(key);
|
|
1844
|
-
if (this.isSensitive(normKey)) {
|
|
1845
|
-
if (obj[key] && typeof obj[key] === "object") {
|
|
1846
|
-
filtered[key] = this.deepFilter(obj[key], seen);
|
|
1847
|
-
} else {
|
|
1848
|
-
filtered[key] = this.redactValue(obj[key]);
|
|
1849
|
-
}
|
|
1850
|
-
} else {
|
|
1851
|
-
filtered[key] = this.deepFilter(obj[key], seen);
|
|
1852
|
-
}
|
|
1853
|
-
}
|
|
1854
|
-
return filtered;
|
|
1855
|
-
}
|
|
1856
|
-
tryFilter(value) {
|
|
1857
|
-
try {
|
|
1858
|
-
return this.deepFilter(value);
|
|
1859
|
-
} catch {
|
|
1860
|
-
return { error: { processor: this.name } };
|
|
1861
|
-
}
|
|
1862
|
-
}
|
|
1863
|
-
/**
|
|
1864
|
-
* Normalize keys by lowercasing and stripping non-alphanumeric characters.
|
|
1865
|
-
* Ensures consistent matching for variants like "api-key", "api_key", "Api Key".
|
|
1866
|
-
*/
|
|
1867
|
-
normalizeKey(key) {
|
|
1868
|
-
return key.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
1869
|
-
}
|
|
1870
|
-
/**
|
|
1871
|
-
* Check whether a normalized key exactly matches any sensitive field.
|
|
1872
|
-
* Both key and sensitive fields are normalized by removing all non-alphanumeric
|
|
1873
|
-
* characters and converting to lowercase before comparison.
|
|
1874
|
-
*
|
|
1875
|
-
* Examples:
|
|
1876
|
-
* - "api_key", "api-key", "ApiKey" all normalize to "apikey" → MATCHES "apikey"
|
|
1877
|
-
* - "promptTokens", "prompt_tokens" normalize to "prompttokens" → DOES NOT MATCH "token"
|
|
1878
|
-
*/
|
|
1879
|
-
isSensitive(normalizedKey) {
|
|
1880
|
-
return this.sensitiveFields.some((sensitiveField) => {
|
|
1881
|
-
return normalizedKey === sensitiveField;
|
|
1882
|
-
});
|
|
1883
|
-
}
|
|
1884
|
-
/**
|
|
1885
|
-
* Redact a sensitive value.
|
|
1886
|
-
* - Full style: replaces with a fixed token.
|
|
1887
|
-
* - Partial style: shows 3 chars at start and end, hides the middle.
|
|
1888
|
-
*
|
|
1889
|
-
* Non-string values are converted to strings before partial redaction.
|
|
1890
|
-
*/
|
|
1891
|
-
redactValue(value) {
|
|
1892
|
-
if (this.redactionStyle === "full") {
|
|
1893
|
-
return this.redactionToken;
|
|
1894
|
-
}
|
|
1895
|
-
const str = String(value);
|
|
1896
|
-
const len = str.length;
|
|
1897
|
-
if (len <= 6) {
|
|
1898
|
-
return this.redactionToken;
|
|
1899
|
-
}
|
|
1900
|
-
return str.slice(0, 3) + "\u2026" + str.slice(len - 3);
|
|
1901
|
-
}
|
|
1902
|
-
async shutdown() {
|
|
1903
|
-
}
|
|
1904
|
-
};
|
|
1905
|
-
|
|
1906
|
-
// src/ai-tracing/registry.ts
|
|
1907
|
-
var AITracingRegistry = class {
|
|
1908
|
-
instances = /* @__PURE__ */ new Map();
|
|
1909
|
-
defaultInstance;
|
|
1910
|
-
configSelector;
|
|
1911
|
-
/**
|
|
1912
|
-
* Register a tracing instance
|
|
1913
|
-
*/
|
|
1914
|
-
register(name, instance, isDefault = false) {
|
|
1915
|
-
if (this.instances.has(name)) {
|
|
1916
|
-
throw new Error(`AI Tracing instance '${name}' already registered`);
|
|
1917
|
-
}
|
|
1918
|
-
this.instances.set(name, instance);
|
|
1919
|
-
if (isDefault || !this.defaultInstance) {
|
|
1920
|
-
this.defaultInstance = instance;
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1923
|
-
/**
|
|
1924
|
-
* Get a tracing instance by name
|
|
1925
|
-
*/
|
|
1926
|
-
get(name) {
|
|
1927
|
-
return this.instances.get(name);
|
|
1928
|
-
}
|
|
1929
|
-
/**
|
|
1930
|
-
* Get the default tracing instance
|
|
1931
|
-
*/
|
|
1932
|
-
getDefault() {
|
|
1933
|
-
return this.defaultInstance;
|
|
1934
|
-
}
|
|
1935
|
-
/**
|
|
1936
|
-
* Set the tracing selector function
|
|
1937
|
-
*/
|
|
1938
|
-
setSelector(selector) {
|
|
1939
|
-
this.configSelector = selector;
|
|
1940
|
-
}
|
|
1941
|
-
/**
|
|
1942
|
-
* Get the selected tracing instance based on context
|
|
1943
|
-
*/
|
|
1944
|
-
getSelected(options) {
|
|
1945
|
-
if (this.configSelector) {
|
|
1946
|
-
const selected = this.configSelector(options, this.instances);
|
|
1947
|
-
if (selected && this.instances.has(selected)) {
|
|
1948
|
-
return this.instances.get(selected);
|
|
1949
|
-
}
|
|
1950
|
-
}
|
|
1951
|
-
return this.defaultInstance;
|
|
1952
|
-
}
|
|
1953
|
-
/**
|
|
1954
|
-
* Unregister a tracing instance
|
|
1955
|
-
*/
|
|
1956
|
-
unregister(name) {
|
|
1957
|
-
return this.instances.delete(name);
|
|
1958
|
-
}
|
|
1959
|
-
/**
|
|
1960
|
-
* Shutdown all instances and clear the registry
|
|
1961
|
-
*/
|
|
1962
|
-
async shutdown() {
|
|
1963
|
-
const shutdownPromises = Array.from(this.instances.values()).map((instance) => instance.shutdown());
|
|
1964
|
-
await Promise.allSettled(shutdownPromises);
|
|
1965
|
-
this.instances.clear();
|
|
1966
|
-
}
|
|
1967
|
-
/**
|
|
1968
|
-
* Clear all instances without shutdown
|
|
1969
|
-
*/
|
|
1970
|
-
clear() {
|
|
1971
|
-
this.instances.clear();
|
|
1972
|
-
this.defaultInstance = void 0;
|
|
1973
|
-
this.configSelector = void 0;
|
|
1974
|
-
}
|
|
1975
|
-
/**
|
|
1976
|
-
* Get all registered instances
|
|
1977
|
-
*/
|
|
1978
|
-
getAll() {
|
|
1979
|
-
return new Map(this.instances);
|
|
1980
|
-
}
|
|
1981
|
-
};
|
|
1982
|
-
var aiTracingRegistry = new AITracingRegistry();
|
|
1983
|
-
function registerAITracing(name, instance, isDefault = false) {
|
|
1984
|
-
aiTracingRegistry.register(name, instance, isDefault);
|
|
1985
|
-
}
|
|
1986
|
-
function getAITracing(name) {
|
|
1987
|
-
return aiTracingRegistry.get(name);
|
|
1988
|
-
}
|
|
1989
|
-
function getDefaultAITracing() {
|
|
1990
|
-
return aiTracingRegistry.getDefault();
|
|
1991
|
-
}
|
|
1992
|
-
function setSelector(selector) {
|
|
1993
|
-
aiTracingRegistry.setSelector(selector);
|
|
1994
|
-
}
|
|
1995
|
-
function getSelectedAITracing(options) {
|
|
1996
|
-
return aiTracingRegistry.getSelected(options);
|
|
1997
|
-
}
|
|
1998
|
-
function unregisterAITracing(name) {
|
|
1999
|
-
return aiTracingRegistry.unregister(name);
|
|
2000
|
-
}
|
|
2001
|
-
async function shutdownAITracingRegistry() {
|
|
2002
|
-
await aiTracingRegistry.shutdown();
|
|
2003
|
-
}
|
|
2004
|
-
function clearAITracingRegistry() {
|
|
2005
|
-
aiTracingRegistry.clear();
|
|
2006
|
-
}
|
|
2007
|
-
function getAllAITracing() {
|
|
2008
|
-
return aiTracingRegistry.getAll();
|
|
2009
|
-
}
|
|
2010
|
-
function hasAITracing(name) {
|
|
2011
|
-
const tracing = getAITracing(name);
|
|
2012
|
-
if (!tracing) return false;
|
|
2013
|
-
const config = tracing.getConfig();
|
|
2014
|
-
const sampling = config.sampling;
|
|
2015
|
-
return sampling.type !== "never" /* NEVER */;
|
|
2016
|
-
}
|
|
2017
|
-
function isAITracingInstance(obj) {
|
|
2018
|
-
return obj instanceof BaseAITracing;
|
|
2019
|
-
}
|
|
2020
|
-
function setupAITracing(config) {
|
|
2021
|
-
if (!config) {
|
|
2022
|
-
return;
|
|
2023
|
-
}
|
|
2024
|
-
if (config.default?.enabled && config.configs?.["default"]) {
|
|
2025
|
-
throw new Error(
|
|
2026
|
-
"Cannot use 'default' as a custom config name when default tracing is enabled. Please rename your custom config to avoid conflicts."
|
|
2027
|
-
);
|
|
2028
|
-
}
|
|
2029
|
-
if (config.default?.enabled) {
|
|
2030
|
-
const defaultInstance = new DefaultAITracing({
|
|
2031
|
-
serviceName: "mastra",
|
|
2032
|
-
name: "default",
|
|
2033
|
-
sampling: { type: "always" /* ALWAYS */ },
|
|
2034
|
-
exporters: [new DefaultExporter(), new CloudExporter()],
|
|
2035
|
-
processors: [new SensitiveDataFilter()]
|
|
2036
|
-
});
|
|
2037
|
-
registerAITracing("default", defaultInstance, true);
|
|
2038
|
-
}
|
|
2039
|
-
if (config.configs) {
|
|
2040
|
-
const instances = Object.entries(config.configs);
|
|
2041
|
-
instances.forEach(([name, tracingDef], index) => {
|
|
2042
|
-
const instance = isAITracingInstance(tracingDef) ? tracingDef : new DefaultAITracing({ ...tracingDef, name });
|
|
2043
|
-
const isDefault = !config.default?.enabled && index === 0;
|
|
2044
|
-
registerAITracing(name, instance, isDefault);
|
|
2045
|
-
});
|
|
2046
|
-
}
|
|
2047
|
-
if (config.configSelector) {
|
|
2048
|
-
setSelector(config.configSelector);
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2051
|
-
|
|
2052
|
-
// src/ai-tracing/utils.ts
|
|
2053
|
-
function omitKeys(obj, keysToOmit) {
|
|
2054
|
-
return Object.fromEntries(Object.entries(obj).filter(([key]) => !keysToOmit.includes(key)));
|
|
2055
|
-
}
|
|
2056
|
-
function selectFields(obj, fields) {
|
|
2057
|
-
if (!obj || typeof obj !== "object") {
|
|
2058
|
-
return obj;
|
|
2059
|
-
}
|
|
2060
|
-
const result = {};
|
|
2061
|
-
for (const field of fields) {
|
|
2062
|
-
const value = getNestedValue(obj, field);
|
|
2063
|
-
if (value !== void 0) {
|
|
2064
|
-
setNestedValue(result, field, value);
|
|
2065
|
-
}
|
|
2066
|
-
}
|
|
2067
|
-
return result;
|
|
2068
|
-
}
|
|
2069
|
-
function getNestedValue(obj, path) {
|
|
2070
|
-
return path.split(".").reduce((current, key) => {
|
|
2071
|
-
return current && typeof current === "object" ? current[key] : void 0;
|
|
2072
|
-
}, obj);
|
|
2073
|
-
}
|
|
2074
|
-
function setNestedValue(obj, path, value) {
|
|
2075
|
-
const keys = path.split(".");
|
|
2076
|
-
const lastKey = keys.pop();
|
|
2077
|
-
if (!lastKey) {
|
|
2078
|
-
return;
|
|
2079
|
-
}
|
|
2080
|
-
const target = keys.reduce((current, key) => {
|
|
2081
|
-
if (!current[key] || typeof current[key] !== "object") {
|
|
2082
|
-
current[key] = {};
|
|
2083
|
-
}
|
|
2084
|
-
return current[key];
|
|
2085
|
-
}, obj);
|
|
2086
|
-
target[lastKey] = value;
|
|
2087
|
-
}
|
|
2088
|
-
function getValidTraceId(span) {
|
|
2089
|
-
return span?.isValid ? span.traceId : void 0;
|
|
2090
|
-
}
|
|
2091
|
-
function getOrCreateSpan(options) {
|
|
2092
|
-
const { type, attributes, tracingContext, runtimeContext, tracingOptions, ...rest } = options;
|
|
2093
|
-
const metadata = {
|
|
2094
|
-
...rest.metadata ?? {},
|
|
2095
|
-
...tracingOptions?.metadata ?? {}
|
|
2096
|
-
};
|
|
2097
|
-
if (tracingContext?.currentSpan) {
|
|
2098
|
-
return tracingContext.currentSpan.createChildSpan({
|
|
2099
|
-
type,
|
|
2100
|
-
attributes,
|
|
2101
|
-
...rest,
|
|
2102
|
-
metadata
|
|
2103
|
-
});
|
|
2104
|
-
}
|
|
2105
|
-
const aiTracing = getSelectedAITracing({
|
|
2106
|
-
runtimeContext
|
|
2107
|
-
});
|
|
2108
|
-
return aiTracing?.startSpan({
|
|
2109
|
-
type,
|
|
2110
|
-
attributes,
|
|
2111
|
-
...rest,
|
|
2112
|
-
metadata,
|
|
2113
|
-
runtimeContext,
|
|
2114
|
-
tracingOptions,
|
|
2115
|
-
traceId: tracingOptions?.traceId,
|
|
2116
|
-
parentSpanId: tracingOptions?.parentSpanId,
|
|
2117
|
-
customSamplerOptions: {
|
|
2118
|
-
runtimeContext,
|
|
2119
|
-
metadata
|
|
2120
|
-
}
|
|
2121
|
-
});
|
|
2122
|
-
}
|
|
2123
|
-
|
|
2124
|
-
// src/ai-tracing/tracers/base.ts
|
|
2125
|
-
var BaseAITracing = class extends chunk6VOPKVYH_cjs.MastraBase {
|
|
2126
|
-
config;
|
|
2127
|
-
constructor(config) {
|
|
2128
|
-
super({ component: chunkA5KDVZDL_cjs.RegisteredLogger.AI_TRACING, name: config.serviceName });
|
|
2129
|
-
this.config = {
|
|
2130
|
-
serviceName: config.serviceName,
|
|
2131
|
-
name: config.name,
|
|
2132
|
-
sampling: config.sampling ?? { type: "always" /* ALWAYS */ },
|
|
2133
|
-
exporters: config.exporters ?? [],
|
|
2134
|
-
processors: config.processors ?? [],
|
|
2135
|
-
includeInternalSpans: config.includeInternalSpans ?? false,
|
|
2136
|
-
runtimeContextKeys: config.runtimeContextKeys ?? []
|
|
2137
|
-
};
|
|
2138
|
-
}
|
|
2139
|
-
/**
|
|
2140
|
-
* Override setLogger to add AI tracing specific initialization log
|
|
2141
|
-
* and propagate logger to exporters
|
|
2142
|
-
*/
|
|
2143
|
-
__setLogger(logger) {
|
|
2144
|
-
super.__setLogger(logger);
|
|
2145
|
-
this.exporters.forEach((exporter) => {
|
|
2146
|
-
if (typeof exporter.__setLogger === "function") {
|
|
2147
|
-
exporter.__setLogger(logger);
|
|
2148
|
-
}
|
|
2149
|
-
});
|
|
2150
|
-
this.logger.debug(
|
|
2151
|
-
`[AI Tracing] Initialized [service=${this.config.serviceName}] [instance=${this.config.name}] [sampling=${this.config.sampling.type}]`
|
|
2152
|
-
);
|
|
2153
|
-
}
|
|
2154
|
-
// ============================================================================
|
|
2155
|
-
// Protected getters for clean config access
|
|
2156
|
-
// ============================================================================
|
|
2157
|
-
get exporters() {
|
|
2158
|
-
return this.config.exporters || [];
|
|
2159
|
-
}
|
|
2160
|
-
get processors() {
|
|
2161
|
-
return this.config.processors || [];
|
|
2162
|
-
}
|
|
2163
|
-
// ============================================================================
|
|
2164
|
-
// Public API - Single type-safe span creation method
|
|
2165
|
-
// ============================================================================
|
|
2166
|
-
/**
|
|
2167
|
-
* Start a new span of a specific AISpanType
|
|
2168
|
-
*/
|
|
2169
|
-
startSpan(options) {
|
|
2170
|
-
const { customSamplerOptions, runtimeContext, metadata, tracingOptions, ...rest } = options;
|
|
2171
|
-
if (!this.shouldSample(customSamplerOptions)) {
|
|
2172
|
-
return new NoOpAISpan({ ...rest, metadata }, this);
|
|
2173
|
-
}
|
|
2174
|
-
let traceState;
|
|
2175
|
-
if (options.parent) {
|
|
2176
|
-
traceState = options.parent.traceState;
|
|
2177
|
-
} else {
|
|
2178
|
-
traceState = this.computeTraceState(tracingOptions);
|
|
2179
|
-
}
|
|
2180
|
-
const enrichedMetadata = this.extractMetadataFromRuntimeContext(runtimeContext, metadata, traceState);
|
|
2181
|
-
const span = this.createSpan({
|
|
2182
|
-
...rest,
|
|
2183
|
-
metadata: enrichedMetadata,
|
|
2184
|
-
traceState
|
|
2185
|
-
});
|
|
2186
|
-
if (span.isEvent) {
|
|
2187
|
-
this.emitSpanEnded(span);
|
|
2188
|
-
} else {
|
|
2189
|
-
this.wireSpanLifecycle(span);
|
|
2190
|
-
this.emitSpanStarted(span);
|
|
2191
|
-
}
|
|
2192
|
-
return span;
|
|
2193
|
-
}
|
|
2194
|
-
// ============================================================================
|
|
2195
|
-
// Configuration Management
|
|
2196
|
-
// ============================================================================
|
|
2197
|
-
/**
|
|
2198
|
-
* Get current configuration
|
|
2199
|
-
*/
|
|
2200
|
-
getConfig() {
|
|
2201
|
-
return { ...this.config };
|
|
2202
|
-
}
|
|
2203
|
-
// ============================================================================
|
|
2204
|
-
// Plugin Access
|
|
2205
|
-
// ============================================================================
|
|
2206
|
-
/**
|
|
2207
|
-
* Get all exporters
|
|
2208
|
-
*/
|
|
2209
|
-
getExporters() {
|
|
2210
|
-
return [...this.exporters];
|
|
2211
|
-
}
|
|
2212
|
-
/**
|
|
2213
|
-
* Get all processors
|
|
2214
|
-
*/
|
|
2215
|
-
getProcessors() {
|
|
2216
|
-
return [...this.processors];
|
|
2217
|
-
}
|
|
2218
|
-
/**
|
|
2219
|
-
* Get the logger instance (for exporters and other components)
|
|
2220
|
-
*/
|
|
2221
|
-
getLogger() {
|
|
2222
|
-
return this.logger;
|
|
2223
|
-
}
|
|
2224
|
-
// ============================================================================
|
|
2225
|
-
// Span Lifecycle Management
|
|
2226
|
-
// ============================================================================
|
|
2227
|
-
/**
|
|
2228
|
-
* Automatically wires up AI tracing lifecycle events for any span
|
|
2229
|
-
* This ensures all spans emit events regardless of implementation
|
|
2230
|
-
*/
|
|
2231
|
-
wireSpanLifecycle(span) {
|
|
2232
|
-
if (!this.config.includeInternalSpans && span.isInternal) {
|
|
2233
|
-
return;
|
|
2234
|
-
}
|
|
2235
|
-
const originalEnd = span.end.bind(span);
|
|
2236
|
-
const originalUpdate = span.update.bind(span);
|
|
2237
|
-
span.end = (options) => {
|
|
2238
|
-
if (span.isEvent) {
|
|
2239
|
-
this.logger.warn(`End event is not available on event spans`);
|
|
2240
|
-
return;
|
|
2241
|
-
}
|
|
2242
|
-
originalEnd(options);
|
|
2243
|
-
this.emitSpanEnded(span);
|
|
2244
|
-
};
|
|
2245
|
-
span.update = (options) => {
|
|
2246
|
-
if (span.isEvent) {
|
|
2247
|
-
this.logger.warn(`Update() is not available on event spans`);
|
|
2248
|
-
return;
|
|
2249
|
-
}
|
|
2250
|
-
originalUpdate(options);
|
|
2251
|
-
this.emitSpanUpdated(span);
|
|
2252
|
-
};
|
|
2253
|
-
}
|
|
2254
|
-
// ============================================================================
|
|
2255
|
-
// Utility Methods
|
|
2256
|
-
// ============================================================================
|
|
2257
|
-
/**
|
|
2258
|
-
* Check if an AI trace should be sampled
|
|
2259
|
-
*/
|
|
2260
|
-
shouldSample(options) {
|
|
2261
|
-
const { sampling } = this.config;
|
|
2262
|
-
switch (sampling.type) {
|
|
2263
|
-
case "always" /* ALWAYS */:
|
|
2264
|
-
return true;
|
|
2265
|
-
case "never" /* NEVER */:
|
|
2266
|
-
return false;
|
|
2267
|
-
case "ratio" /* RATIO */:
|
|
2268
|
-
if (sampling.probability === void 0 || sampling.probability < 0 || sampling.probability > 1) {
|
|
2269
|
-
this.logger.warn(
|
|
2270
|
-
`Invalid sampling probability: ${sampling.probability}. Expected value between 0 and 1. Defaulting to no sampling.`
|
|
2271
|
-
);
|
|
2272
|
-
return false;
|
|
2273
|
-
}
|
|
2274
|
-
return Math.random() < sampling.probability;
|
|
2275
|
-
case "custom" /* CUSTOM */:
|
|
2276
|
-
return sampling.sampler(options);
|
|
2277
|
-
default:
|
|
2278
|
-
throw new Error(`Sampling strategy type not implemented: ${sampling.type}`);
|
|
2279
|
-
}
|
|
2280
|
-
}
|
|
2281
|
-
/**
|
|
2282
|
-
* Compute TraceState for a new trace based on configured and per-request keys
|
|
2283
|
-
*/
|
|
2284
|
-
computeTraceState(tracingOptions) {
|
|
2285
|
-
const configuredKeys = this.config.runtimeContextKeys ?? [];
|
|
2286
|
-
const additionalKeys = tracingOptions?.runtimeContextKeys ?? [];
|
|
2287
|
-
const allKeys = [...configuredKeys, ...additionalKeys];
|
|
2288
|
-
if (allKeys.length === 0) {
|
|
2289
|
-
return void 0;
|
|
2290
|
-
}
|
|
2291
|
-
return {
|
|
2292
|
-
runtimeContextKeys: allKeys
|
|
2293
|
-
};
|
|
2294
|
-
}
|
|
2295
|
-
/**
|
|
2296
|
-
* Extract metadata from RuntimeContext using TraceState
|
|
2297
|
-
*/
|
|
2298
|
-
extractMetadataFromRuntimeContext(runtimeContext, explicitMetadata, traceState) {
|
|
2299
|
-
if (!runtimeContext || !traceState || traceState.runtimeContextKeys.length === 0) {
|
|
2300
|
-
return explicitMetadata;
|
|
2301
|
-
}
|
|
2302
|
-
const extracted = this.extractKeys(runtimeContext, traceState.runtimeContextKeys);
|
|
2303
|
-
if (Object.keys(extracted).length === 0 && !explicitMetadata) {
|
|
2304
|
-
return void 0;
|
|
2305
|
-
}
|
|
2306
|
-
return {
|
|
2307
|
-
...extracted,
|
|
2308
|
-
...explicitMetadata
|
|
2309
|
-
// Explicit metadata always wins
|
|
2310
|
-
};
|
|
2311
|
-
}
|
|
2312
|
-
/**
|
|
2313
|
-
* Extract specific keys from RuntimeContext
|
|
2314
|
-
*/
|
|
2315
|
-
extractKeys(runtimeContext, keys) {
|
|
2316
|
-
const result = {};
|
|
2317
|
-
for (const key of keys) {
|
|
2318
|
-
const parts = key.split(".");
|
|
2319
|
-
const rootKey = parts[0];
|
|
2320
|
-
const value = runtimeContext.get(rootKey);
|
|
2321
|
-
if (value !== void 0) {
|
|
2322
|
-
if (parts.length > 1) {
|
|
2323
|
-
const nestedPath = parts.slice(1).join(".");
|
|
2324
|
-
const nestedValue = getNestedValue(value, nestedPath);
|
|
2325
|
-
if (nestedValue !== void 0) {
|
|
2326
|
-
setNestedValue(result, key, nestedValue);
|
|
2327
|
-
}
|
|
2328
|
-
} else {
|
|
2329
|
-
setNestedValue(result, key, value);
|
|
2330
|
-
}
|
|
2331
|
-
}
|
|
2332
|
-
}
|
|
2333
|
-
return result;
|
|
2334
|
-
}
|
|
2335
|
-
/**
|
|
2336
|
-
* Process a span through all processors
|
|
2337
|
-
*/
|
|
2338
|
-
processSpan(span) {
|
|
2339
|
-
for (const processor of this.processors) {
|
|
2340
|
-
if (!span) {
|
|
2341
|
-
break;
|
|
2342
|
-
}
|
|
2343
|
-
try {
|
|
2344
|
-
span = processor.process(span);
|
|
2345
|
-
} catch (error) {
|
|
2346
|
-
this.logger.error(`[AI Tracing] Processor error [name=${processor.name}]`, error);
|
|
2347
|
-
}
|
|
2348
|
-
}
|
|
2349
|
-
return span;
|
|
2350
|
-
}
|
|
2351
|
-
// ============================================================================
|
|
2352
|
-
// Event-driven Export Methods
|
|
2353
|
-
// ============================================================================
|
|
2354
|
-
getSpanForExport(span) {
|
|
2355
|
-
if (!span.isValid) return void 0;
|
|
2356
|
-
if (span.isInternal && !this.config.includeInternalSpans) return void 0;
|
|
2357
|
-
const processedSpan = this.processSpan(span);
|
|
2358
|
-
return processedSpan?.exportSpan(this.config.includeInternalSpans);
|
|
2359
|
-
}
|
|
2360
|
-
/**
|
|
2361
|
-
* Emit a span started event
|
|
2362
|
-
*/
|
|
2363
|
-
emitSpanStarted(span) {
|
|
2364
|
-
const exportedSpan = this.getSpanForExport(span);
|
|
2365
|
-
if (exportedSpan) {
|
|
2366
|
-
this.exportEvent({ type: "span_started" /* SPAN_STARTED */, exportedSpan }).catch((error) => {
|
|
2367
|
-
this.logger.error("[AI Tracing] Failed to export span_started event", error);
|
|
2368
|
-
});
|
|
2369
|
-
}
|
|
2370
|
-
}
|
|
2371
|
-
/**
|
|
2372
|
-
* Emit a span ended event (called automatically when spans end)
|
|
2373
|
-
*/
|
|
2374
|
-
emitSpanEnded(span) {
|
|
2375
|
-
const exportedSpan = this.getSpanForExport(span);
|
|
2376
|
-
if (exportedSpan) {
|
|
2377
|
-
this.exportEvent({ type: "span_ended" /* SPAN_ENDED */, exportedSpan }).catch((error) => {
|
|
2378
|
-
this.logger.error("[AI Tracing] Failed to export span_ended event", error);
|
|
2379
|
-
});
|
|
2380
|
-
}
|
|
2381
|
-
}
|
|
2382
|
-
/**
|
|
2383
|
-
* Emit a span updated event
|
|
2384
|
-
*/
|
|
2385
|
-
emitSpanUpdated(span) {
|
|
2386
|
-
const exportedSpan = this.getSpanForExport(span);
|
|
2387
|
-
if (exportedSpan) {
|
|
2388
|
-
this.exportEvent({ type: "span_updated" /* SPAN_UPDATED */, exportedSpan }).catch((error) => {
|
|
2389
|
-
this.logger.error("[AI Tracing] Failed to export span_updated event", error);
|
|
2390
|
-
});
|
|
2391
|
-
}
|
|
2392
|
-
}
|
|
2393
|
-
/**
|
|
2394
|
-
* Export tracing event through all exporters (realtime mode)
|
|
2395
|
-
*/
|
|
2396
|
-
async exportEvent(event) {
|
|
2397
|
-
const exportPromises = this.exporters.map(async (exporter) => {
|
|
2398
|
-
try {
|
|
2399
|
-
if (exporter.exportEvent) {
|
|
2400
|
-
await exporter.exportEvent(event);
|
|
2401
|
-
this.logger.debug(`[AI Tracing] Event exported [exporter=${exporter.name}] [type=${event.type}]`);
|
|
2402
|
-
}
|
|
2403
|
-
} catch (error) {
|
|
2404
|
-
this.logger.error(`[AI Tracing] Export error [exporter=${exporter.name}]`, error);
|
|
2405
|
-
}
|
|
2406
|
-
});
|
|
2407
|
-
await Promise.allSettled(exportPromises);
|
|
2408
|
-
}
|
|
2409
|
-
// ============================================================================
|
|
2410
|
-
// Lifecycle Management
|
|
2411
|
-
// ============================================================================
|
|
2412
|
-
/**
|
|
2413
|
-
* Initialize AI tracing (called by Mastra during component registration)
|
|
2414
|
-
*/
|
|
2415
|
-
init() {
|
|
2416
|
-
this.logger.debug(`[AI Tracing] Initialization started [name=${this.name}]`);
|
|
2417
|
-
this.logger.info(`[AI Tracing] Initialized successfully [name=${this.name}]`);
|
|
2418
|
-
}
|
|
2419
|
-
/**
|
|
2420
|
-
* Shutdown AI tracing and clean up resources
|
|
2421
|
-
*/
|
|
2422
|
-
async shutdown() {
|
|
2423
|
-
this.logger.debug(`[AI Tracing] Shutdown started [name=${this.name}]`);
|
|
2424
|
-
const shutdownPromises = [...this.exporters.map((e) => e.shutdown()), ...this.processors.map((p) => p.shutdown())];
|
|
2425
|
-
await Promise.allSettled(shutdownPromises);
|
|
2426
|
-
this.logger.info(`[AI Tracing] Shutdown completed [name=${this.name}]`);
|
|
2427
|
-
}
|
|
2428
|
-
};
|
|
2429
|
-
|
|
2430
|
-
// src/ai-tracing/tracers/default.ts
|
|
2431
|
-
var DefaultAITracing = class extends BaseAITracing {
|
|
2432
|
-
constructor(config) {
|
|
2433
|
-
super(config);
|
|
2434
|
-
}
|
|
2435
|
-
createSpan(options) {
|
|
2436
|
-
return new DefaultAISpan(options, this);
|
|
2437
|
-
}
|
|
2438
|
-
};
|
|
2439
|
-
|
|
2440
|
-
// src/ai-tracing/context.ts
|
|
2441
|
-
var AGENT_GETTERS = ["getAgent", "getAgentById"];
|
|
2442
|
-
var AGENT_METHODS_TO_WRAP = ["generate", "stream", "generateLegacy", "streamLegacy"];
|
|
2443
|
-
var WORKFLOW_GETTERS = ["getWorkflow", "getWorkflowById"];
|
|
2444
|
-
var WORKFLOW_METHODS_TO_WRAP = ["execute", "createRun", "createRunAsync"];
|
|
2445
|
-
function isNoOpSpan(span) {
|
|
2446
|
-
return span.constructor.name === "NoOpAISpan" || span.__isNoOp === true;
|
|
2447
|
-
}
|
|
2448
|
-
function isMastra(mastra) {
|
|
2449
|
-
const hasAgentGetters = AGENT_GETTERS.every((method) => typeof mastra?.[method] === "function");
|
|
2450
|
-
const hasWorkflowGetters = WORKFLOW_GETTERS.every((method) => typeof mastra?.[method] === "function");
|
|
2451
|
-
return hasAgentGetters && hasWorkflowGetters;
|
|
2452
|
-
}
|
|
2453
|
-
function wrapMastra(mastra, tracingContext) {
|
|
2454
|
-
if (!tracingContext.currentSpan || isNoOpSpan(tracingContext.currentSpan)) {
|
|
2455
|
-
return mastra;
|
|
2456
|
-
}
|
|
2457
|
-
if (!isMastra(mastra)) {
|
|
2458
|
-
return mastra;
|
|
2459
|
-
}
|
|
2460
|
-
try {
|
|
2461
|
-
return new Proxy(mastra, {
|
|
2462
|
-
get(target, prop) {
|
|
2463
|
-
try {
|
|
2464
|
-
if (AGENT_GETTERS.includes(prop)) {
|
|
2465
|
-
return (...args) => {
|
|
2466
|
-
const agent = target[prop](...args);
|
|
2467
|
-
return wrapAgent(agent, tracingContext);
|
|
2468
|
-
};
|
|
2469
|
-
}
|
|
2470
|
-
if (WORKFLOW_GETTERS.includes(prop)) {
|
|
2471
|
-
return (...args) => {
|
|
2472
|
-
const workflow = target[prop](...args);
|
|
2473
|
-
return wrapWorkflow(workflow, tracingContext);
|
|
2474
|
-
};
|
|
2475
|
-
}
|
|
2476
|
-
const value = target[prop];
|
|
2477
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
2478
|
-
} catch (error) {
|
|
2479
|
-
console.warn("AI Tracing: Failed to wrap method, falling back to original", error);
|
|
2480
|
-
const value = target[prop];
|
|
2481
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
2482
|
-
}
|
|
2483
|
-
}
|
|
2484
|
-
});
|
|
2485
|
-
} catch (error) {
|
|
2486
|
-
console.warn("AI Tracing: Failed to create proxy, using original Mastra instance", error);
|
|
2487
|
-
return mastra;
|
|
2488
|
-
}
|
|
2489
|
-
}
|
|
2490
|
-
function wrapAgent(agent, tracingContext) {
|
|
2491
|
-
if (!tracingContext.currentSpan || isNoOpSpan(tracingContext.currentSpan)) {
|
|
2492
|
-
return agent;
|
|
2493
|
-
}
|
|
2494
|
-
try {
|
|
2495
|
-
return new Proxy(agent, {
|
|
2496
|
-
get(target, prop) {
|
|
2497
|
-
try {
|
|
2498
|
-
if (AGENT_METHODS_TO_WRAP.includes(prop)) {
|
|
2499
|
-
return (input, options = {}) => {
|
|
2500
|
-
return target[prop](input, {
|
|
2501
|
-
...options,
|
|
2502
|
-
tracingContext
|
|
2503
|
-
});
|
|
2504
|
-
};
|
|
2505
|
-
}
|
|
2506
|
-
const value = target[prop];
|
|
2507
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
2508
|
-
} catch (error) {
|
|
2509
|
-
console.warn("AI Tracing: Failed to wrap agent method, falling back to original", error);
|
|
2510
|
-
const value = target[prop];
|
|
2511
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
2512
|
-
}
|
|
2513
|
-
}
|
|
2514
|
-
});
|
|
2515
|
-
} catch (error) {
|
|
2516
|
-
console.warn("AI Tracing: Failed to create agent proxy, using original instance", error);
|
|
2517
|
-
return agent;
|
|
2518
|
-
}
|
|
2519
|
-
}
|
|
2520
|
-
function wrapWorkflow(workflow, tracingContext) {
|
|
2521
|
-
if (!tracingContext.currentSpan || isNoOpSpan(tracingContext.currentSpan)) {
|
|
2522
|
-
return workflow;
|
|
2523
|
-
}
|
|
2524
|
-
try {
|
|
2525
|
-
return new Proxy(workflow, {
|
|
2526
|
-
get(target, prop) {
|
|
2527
|
-
try {
|
|
2528
|
-
if (WORKFLOW_METHODS_TO_WRAP.includes(prop)) {
|
|
2529
|
-
if (prop === "createRun" || prop === "createRunAsync") {
|
|
2530
|
-
return async (options = {}) => {
|
|
2531
|
-
const run = await target[prop](options);
|
|
2532
|
-
return run ? wrapRun(run, tracingContext) : run;
|
|
2533
|
-
};
|
|
2534
|
-
}
|
|
2535
|
-
return (input, options = {}) => {
|
|
2536
|
-
return target[prop](input, {
|
|
2537
|
-
...options,
|
|
2538
|
-
tracingContext
|
|
2539
|
-
});
|
|
2540
|
-
};
|
|
2541
|
-
}
|
|
2542
|
-
const value = target[prop];
|
|
2543
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
2544
|
-
} catch (error) {
|
|
2545
|
-
console.warn("AI Tracing: Failed to wrap workflow method, falling back to original", error);
|
|
2546
|
-
const value = target[prop];
|
|
2547
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
2548
|
-
}
|
|
2549
|
-
}
|
|
2550
|
-
});
|
|
2551
|
-
} catch (error) {
|
|
2552
|
-
console.warn("AI Tracing: Failed to create workflow proxy, using original instance", error);
|
|
2553
|
-
return workflow;
|
|
2554
|
-
}
|
|
2555
|
-
}
|
|
2556
|
-
function wrapRun(run, tracingContext) {
|
|
2557
|
-
if (!tracingContext.currentSpan || isNoOpSpan(tracingContext.currentSpan)) {
|
|
2558
|
-
return run;
|
|
2559
|
-
}
|
|
2560
|
-
try {
|
|
2561
|
-
return new Proxy(run, {
|
|
2562
|
-
get(target, prop) {
|
|
2563
|
-
try {
|
|
2564
|
-
if (prop === "start") {
|
|
2565
|
-
return (startOptions = {}) => {
|
|
2566
|
-
return target.start({
|
|
2567
|
-
...startOptions,
|
|
2568
|
-
tracingContext: startOptions.tracingContext ?? tracingContext
|
|
2569
|
-
});
|
|
2570
|
-
};
|
|
2571
|
-
}
|
|
2572
|
-
const value = target[prop];
|
|
2573
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
2574
|
-
} catch (error) {
|
|
2575
|
-
console.warn("AI Tracing: Failed to wrap run method, falling back to original", error);
|
|
2576
|
-
const value = target[prop];
|
|
2577
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
2578
|
-
}
|
|
2579
|
-
}
|
|
2580
|
-
});
|
|
2581
|
-
} catch (error) {
|
|
2582
|
-
console.warn("AI Tracing: Failed to create run proxy, using original instance", error);
|
|
2583
|
-
return run;
|
|
2584
|
-
}
|
|
2585
|
-
}
|
|
2586
|
-
var ModelSpanTracker = class {
|
|
2587
|
-
#modelSpan;
|
|
2588
|
-
#currentStepSpan;
|
|
2589
|
-
#currentChunkSpan;
|
|
2590
|
-
#accumulator = {};
|
|
2591
|
-
#stepIndex = 0;
|
|
2592
|
-
#chunkSequence = 0;
|
|
2593
|
-
constructor(modelSpan) {
|
|
2594
|
-
this.#modelSpan = modelSpan;
|
|
2595
|
-
}
|
|
2596
|
-
/**
|
|
2597
|
-
* Get the tracing context for creating child spans.
|
|
2598
|
-
* Returns the current step span if active, otherwise the model span.
|
|
2599
|
-
*/
|
|
2600
|
-
getTracingContext() {
|
|
2601
|
-
return {
|
|
2602
|
-
currentSpan: this.#currentStepSpan ?? this.#modelSpan
|
|
2603
|
-
};
|
|
2604
|
-
}
|
|
2605
|
-
/**
|
|
2606
|
-
* Report an error on the generation span
|
|
2607
|
-
*/
|
|
2608
|
-
reportGenerationError(options) {
|
|
2609
|
-
this.#modelSpan?.error(options);
|
|
2610
|
-
}
|
|
2611
|
-
/**
|
|
2612
|
-
* End the generation span
|
|
2613
|
-
*/
|
|
2614
|
-
endGeneration(options) {
|
|
2615
|
-
this.#modelSpan?.end(options);
|
|
2616
|
-
}
|
|
2617
|
-
/**
|
|
2618
|
-
* Update the generation span
|
|
2619
|
-
*/
|
|
2620
|
-
updateGeneration(options) {
|
|
2621
|
-
this.#modelSpan?.update(options);
|
|
2622
|
-
}
|
|
2623
|
-
/**
|
|
2624
|
-
* Start a new Model execution step
|
|
2625
|
-
*/
|
|
2626
|
-
#startStepSpan(payload) {
|
|
2627
|
-
this.#currentStepSpan = this.#modelSpan?.createChildSpan({
|
|
2628
|
-
name: `step: ${this.#stepIndex}`,
|
|
2629
|
-
type: "model_step" /* MODEL_STEP */,
|
|
2630
|
-
attributes: {
|
|
2631
|
-
stepIndex: this.#stepIndex,
|
|
2632
|
-
...payload?.messageId ? { messageId: payload.messageId } : {},
|
|
2633
|
-
...payload?.warnings?.length ? { warnings: payload.warnings } : {}
|
|
2634
|
-
},
|
|
2635
|
-
input: payload?.request
|
|
2636
|
-
});
|
|
2637
|
-
this.#chunkSequence = 0;
|
|
2638
|
-
}
|
|
2639
|
-
/**
|
|
2640
|
-
* End the current Model execution step with token usage, finish reason, output, and metadata
|
|
2641
|
-
*/
|
|
2642
|
-
#endStepSpan(payload) {
|
|
2643
|
-
if (!this.#currentStepSpan) return;
|
|
2644
|
-
const output = payload.output;
|
|
2645
|
-
const { usage, ...otherOutput } = output;
|
|
2646
|
-
const stepResult = payload.stepResult;
|
|
2647
|
-
const metadata = payload.metadata;
|
|
2648
|
-
const cleanMetadata = metadata ? { ...metadata } : void 0;
|
|
2649
|
-
if (cleanMetadata?.request) {
|
|
2650
|
-
delete cleanMetadata.request;
|
|
2651
|
-
}
|
|
2652
|
-
this.#currentStepSpan.end({
|
|
2653
|
-
output: otherOutput,
|
|
2654
|
-
attributes: {
|
|
2655
|
-
usage,
|
|
2656
|
-
isContinued: stepResult.isContinued,
|
|
2657
|
-
finishReason: stepResult.reason,
|
|
2658
|
-
warnings: stepResult.warnings
|
|
2659
|
-
},
|
|
2660
|
-
metadata: {
|
|
2661
|
-
...cleanMetadata
|
|
2662
|
-
}
|
|
2663
|
-
});
|
|
2664
|
-
this.#currentStepSpan = void 0;
|
|
2665
|
-
this.#stepIndex++;
|
|
2666
|
-
}
|
|
2667
|
-
/**
|
|
2668
|
-
* Create a new chunk span (for multi-part chunks like text-start/delta/end)
|
|
2669
|
-
*/
|
|
2670
|
-
#startChunkSpan(chunkType, initialData) {
|
|
2671
|
-
if (!this.#currentStepSpan) {
|
|
2672
|
-
this.#startStepSpan();
|
|
2673
|
-
}
|
|
2674
|
-
this.#currentChunkSpan = this.#currentStepSpan?.createChildSpan({
|
|
2675
|
-
name: `chunk: '${chunkType}'`,
|
|
2676
|
-
type: "model_chunk" /* MODEL_CHUNK */,
|
|
2677
|
-
attributes: {
|
|
2678
|
-
chunkType,
|
|
2679
|
-
sequenceNumber: this.#chunkSequence
|
|
2680
|
-
}
|
|
2681
|
-
});
|
|
2682
|
-
this.#accumulator = initialData || {};
|
|
2683
|
-
}
|
|
2684
|
-
/**
|
|
2685
|
-
* Append string content to a specific field in the accumulator
|
|
2686
|
-
*/
|
|
2687
|
-
#appendToAccumulator(field, text) {
|
|
2688
|
-
if (this.#accumulator[field] === void 0) {
|
|
2689
|
-
this.#accumulator[field] = text;
|
|
2690
|
-
} else {
|
|
2691
|
-
this.#accumulator[field] += text;
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2694
|
-
/**
|
|
2695
|
-
* End the current chunk span.
|
|
2696
|
-
* Safe to call multiple times - will no-op if span already ended.
|
|
2697
|
-
*/
|
|
2698
|
-
#endChunkSpan(output) {
|
|
2699
|
-
if (!this.#currentChunkSpan) return;
|
|
2700
|
-
this.#currentChunkSpan.end({
|
|
2701
|
-
output: output !== void 0 ? output : this.#accumulator
|
|
2702
|
-
});
|
|
2703
|
-
this.#currentChunkSpan = void 0;
|
|
2704
|
-
this.#accumulator = {};
|
|
2705
|
-
this.#chunkSequence++;
|
|
2706
|
-
}
|
|
2707
|
-
/**
|
|
2708
|
-
* Create an event span (for single chunks like tool-call)
|
|
2709
|
-
*/
|
|
2710
|
-
#createEventSpan(chunkType, output) {
|
|
2711
|
-
if (!this.#currentStepSpan) {
|
|
2712
|
-
this.#startStepSpan();
|
|
2713
|
-
}
|
|
2714
|
-
const span = this.#currentStepSpan?.createEventSpan({
|
|
2715
|
-
name: `chunk: '${chunkType}'`,
|
|
2716
|
-
type: "model_chunk" /* MODEL_CHUNK */,
|
|
2717
|
-
attributes: {
|
|
2718
|
-
chunkType,
|
|
2719
|
-
sequenceNumber: this.#chunkSequence
|
|
2720
|
-
},
|
|
2721
|
-
output
|
|
2722
|
-
});
|
|
2723
|
-
if (span) {
|
|
2724
|
-
this.#chunkSequence++;
|
|
2725
|
-
}
|
|
2726
|
-
}
|
|
2727
|
-
/**
|
|
2728
|
-
* Check if there is currently an active chunk span
|
|
2729
|
-
*/
|
|
2730
|
-
#hasActiveChunkSpan() {
|
|
2731
|
-
return !!this.#currentChunkSpan;
|
|
2732
|
-
}
|
|
2733
|
-
/**
|
|
2734
|
-
* Get the current accumulator value
|
|
2735
|
-
*/
|
|
2736
|
-
#getAccumulator() {
|
|
2737
|
-
return this.#accumulator;
|
|
2738
|
-
}
|
|
2739
|
-
/**
|
|
2740
|
-
* Handle text chunk spans (text-start/delta/end)
|
|
2741
|
-
*/
|
|
2742
|
-
#handleTextChunk(chunk) {
|
|
2743
|
-
switch (chunk.type) {
|
|
2744
|
-
case "text-start":
|
|
2745
|
-
this.#startChunkSpan("text");
|
|
2746
|
-
break;
|
|
2747
|
-
case "text-delta":
|
|
2748
|
-
this.#appendToAccumulator("text", chunk.payload.text);
|
|
2749
|
-
break;
|
|
2750
|
-
case "text-end": {
|
|
2751
|
-
this.#endChunkSpan();
|
|
2752
|
-
break;
|
|
2753
|
-
}
|
|
2754
|
-
}
|
|
2755
|
-
}
|
|
2756
|
-
/**
|
|
2757
|
-
* Handle reasoning chunk spans (reasoning-start/delta/end)
|
|
2758
|
-
*/
|
|
2759
|
-
#handleReasoningChunk(chunk) {
|
|
2760
|
-
switch (chunk.type) {
|
|
2761
|
-
case "reasoning-start":
|
|
2762
|
-
this.#startChunkSpan("reasoning");
|
|
2763
|
-
break;
|
|
2764
|
-
case "reasoning-delta":
|
|
2765
|
-
this.#appendToAccumulator("text", chunk.payload.text);
|
|
2766
|
-
break;
|
|
2767
|
-
case "reasoning-end": {
|
|
2768
|
-
this.#endChunkSpan();
|
|
2769
|
-
break;
|
|
2770
|
-
}
|
|
2771
|
-
}
|
|
2772
|
-
}
|
|
2773
|
-
/**
|
|
2774
|
-
* Handle tool call chunk spans (tool-call-input-streaming-start/delta/end, tool-call)
|
|
2775
|
-
*/
|
|
2776
|
-
#handleToolCallChunk(chunk) {
|
|
2777
|
-
switch (chunk.type) {
|
|
2778
|
-
case "tool-call-input-streaming-start":
|
|
2779
|
-
this.#startChunkSpan("tool-call", {
|
|
2780
|
-
toolName: chunk.payload.toolName,
|
|
2781
|
-
toolCallId: chunk.payload.toolCallId
|
|
2782
|
-
});
|
|
2783
|
-
break;
|
|
2784
|
-
case "tool-call-delta":
|
|
2785
|
-
this.#appendToAccumulator("toolInput", chunk.payload.argsTextDelta);
|
|
2786
|
-
break;
|
|
2787
|
-
case "tool-call-input-streaming-end":
|
|
2788
|
-
case "tool-call": {
|
|
2789
|
-
const acc = this.#getAccumulator();
|
|
2790
|
-
let toolInput;
|
|
2791
|
-
try {
|
|
2792
|
-
toolInput = acc.toolInput ? JSON.parse(acc.toolInput) : {};
|
|
2793
|
-
} catch {
|
|
2794
|
-
toolInput = acc.toolInput;
|
|
2795
|
-
}
|
|
2796
|
-
this.#endChunkSpan({
|
|
2797
|
-
toolName: acc.toolName,
|
|
2798
|
-
toolCallId: acc.toolCallId,
|
|
2799
|
-
toolInput
|
|
2800
|
-
});
|
|
2801
|
-
break;
|
|
2802
|
-
}
|
|
2803
|
-
}
|
|
2804
|
-
}
|
|
2805
|
-
/**
|
|
2806
|
-
* Handle object chunk spans (object, object-result)
|
|
2807
|
-
*/
|
|
2808
|
-
#handleObjectChunk(chunk) {
|
|
2809
|
-
switch (chunk.type) {
|
|
2810
|
-
case "object":
|
|
2811
|
-
if (!this.#hasActiveChunkSpan()) {
|
|
2812
|
-
this.#startChunkSpan("object");
|
|
2813
|
-
}
|
|
2814
|
-
break;
|
|
2815
|
-
case "object-result":
|
|
2816
|
-
this.#endChunkSpan(chunk.object);
|
|
2817
|
-
break;
|
|
2818
|
-
}
|
|
2819
|
-
}
|
|
2820
|
-
/**
|
|
2821
|
-
* Wraps a stream with model tracing transform to track MODEL_STEP and MODEL_CHUNK spans.
|
|
2822
|
-
*
|
|
2823
|
-
* This should be added to the stream pipeline to automatically
|
|
2824
|
-
* create MODEL_STEP and MODEL_CHUNK spans for each semantic unit in the stream.
|
|
2825
|
-
*/
|
|
2826
|
-
wrapStream(stream) {
|
|
2827
|
-
return stream.pipeThrough(
|
|
2828
|
-
new web.TransformStream({
|
|
2829
|
-
transform: (chunk, controller) => {
|
|
2830
|
-
controller.enqueue(chunk);
|
|
2831
|
-
switch (chunk.type) {
|
|
2832
|
-
case "text-start":
|
|
2833
|
-
case "text-delta":
|
|
2834
|
-
case "text-end":
|
|
2835
|
-
this.#handleTextChunk(chunk);
|
|
2836
|
-
break;
|
|
2837
|
-
case "tool-call-input-streaming-start":
|
|
2838
|
-
case "tool-call-delta":
|
|
2839
|
-
case "tool-call-input-streaming-end":
|
|
2840
|
-
case "tool-call":
|
|
2841
|
-
this.#handleToolCallChunk(chunk);
|
|
2842
|
-
break;
|
|
2843
|
-
case "reasoning-start":
|
|
2844
|
-
case "reasoning-delta":
|
|
2845
|
-
case "reasoning-end":
|
|
2846
|
-
this.#handleReasoningChunk(chunk);
|
|
2847
|
-
break;
|
|
2848
|
-
case "object":
|
|
2849
|
-
case "object-result":
|
|
2850
|
-
this.#handleObjectChunk(chunk);
|
|
2851
|
-
break;
|
|
2852
|
-
case "step-start":
|
|
2853
|
-
this.#startStepSpan(chunk.payload);
|
|
2854
|
-
break;
|
|
2855
|
-
case "step-finish":
|
|
2856
|
-
this.#endStepSpan(chunk.payload);
|
|
2857
|
-
break;
|
|
2858
|
-
case "raw":
|
|
2859
|
-
// Skip raw chunks as they're redundant
|
|
2860
|
-
case "start":
|
|
2861
|
-
case "finish":
|
|
2862
|
-
break;
|
|
2863
|
-
// Default: auto-create event span for all other chunk types
|
|
2864
|
-
default: {
|
|
2865
|
-
let outputPayload = chunk.payload;
|
|
2866
|
-
if (outputPayload && typeof outputPayload === "object" && "data" in outputPayload) {
|
|
2867
|
-
const typedPayload = outputPayload;
|
|
2868
|
-
outputPayload = { ...typedPayload };
|
|
2869
|
-
if (typedPayload.data) {
|
|
2870
|
-
outputPayload.size = typeof typedPayload.data === "string" ? typedPayload.data.length : typedPayload.data instanceof Uint8Array ? typedPayload.data.length : void 0;
|
|
2871
|
-
delete outputPayload.data;
|
|
2872
|
-
}
|
|
2873
|
-
}
|
|
2874
|
-
this.#createEventSpan(chunk.type, outputPayload);
|
|
2875
|
-
break;
|
|
2876
|
-
}
|
|
2877
|
-
}
|
|
2878
|
-
}
|
|
2879
|
-
})
|
|
2880
|
-
);
|
|
2881
|
-
}
|
|
2882
|
-
};
|
|
2883
|
-
|
|
2884
|
-
exports.AISpanType = AISpanType;
|
|
2885
|
-
exports.AITracingEventType = AITracingEventType;
|
|
2886
|
-
exports.BaseAISpan = BaseAISpan;
|
|
2887
|
-
exports.BaseAITracing = BaseAITracing;
|
|
2888
|
-
exports.BaseExporter = BaseExporter;
|
|
2889
|
-
exports.CloudExporter = CloudExporter;
|
|
2890
|
-
exports.ConsoleExporter = ConsoleExporter;
|
|
2891
|
-
exports.DefaultAISpan = DefaultAISpan;
|
|
2892
|
-
exports.DefaultAITracing = DefaultAITracing;
|
|
2893
|
-
exports.DefaultExporter = DefaultExporter;
|
|
2894
|
-
exports.InternalSpans = InternalSpans;
|
|
2895
|
-
exports.ModelSpanTracker = ModelSpanTracker;
|
|
2896
|
-
exports.NoOpAISpan = NoOpAISpan;
|
|
2897
|
-
exports.SamplingStrategyType = SamplingStrategyType;
|
|
2898
|
-
exports.SensitiveDataFilter = SensitiveDataFilter;
|
|
2899
|
-
exports.checkEvalStorageFields = checkEvalStorageFields;
|
|
2900
|
-
exports.clearAITracingRegistry = clearAITracingRegistry;
|
|
2901
|
-
exports.createMastraProxy = createMastraProxy;
|
|
2902
|
-
exports.deepClean = deepClean;
|
|
2903
|
-
exports.deepMerge = deepMerge;
|
|
2904
|
-
exports.delay = delay;
|
|
2905
|
-
exports.ensureToolProperties = ensureToolProperties;
|
|
2906
|
-
exports.fetchWithRetry = fetchWithRetry;
|
|
2907
|
-
exports.generateEmptyFromSchema = generateEmptyFromSchema;
|
|
2908
|
-
exports.getAITracing = getAITracing;
|
|
2909
|
-
exports.getAllAITracing = getAllAITracing;
|
|
2910
|
-
exports.getDefaultAITracing = getDefaultAITracing;
|
|
2911
|
-
exports.getNestedValue = getNestedValue;
|
|
2912
|
-
exports.getOrCreateSpan = getOrCreateSpan;
|
|
2913
|
-
exports.getSelectedAITracing = getSelectedAITracing;
|
|
2914
|
-
exports.getValidTraceId = getValidTraceId;
|
|
2915
|
-
exports.hasAITracing = hasAITracing;
|
|
2916
|
-
exports.isCoreMessage = isCoreMessage;
|
|
2917
|
-
exports.isMastra = isMastra;
|
|
2918
|
-
exports.isUiMessage = isUiMessage;
|
|
2919
|
-
exports.isZodType = isZodType;
|
|
2920
|
-
exports.makeCoreTool = makeCoreTool;
|
|
2921
|
-
exports.makeCoreToolV5 = makeCoreToolV5;
|
|
2922
|
-
exports.maskStreamTags = maskStreamTags;
|
|
2923
|
-
exports.omitKeys = omitKeys;
|
|
2924
|
-
exports.parseFieldKey = parseFieldKey;
|
|
2925
|
-
exports.parseSqlIdentifier = parseSqlIdentifier;
|
|
2926
|
-
exports.registerAITracing = registerAITracing;
|
|
2927
|
-
exports.resolveSerializedZodOutput = resolveSerializedZodOutput;
|
|
2928
|
-
exports.selectFields = selectFields;
|
|
2929
|
-
exports.setNestedValue = setNestedValue;
|
|
2930
|
-
exports.setSelector = setSelector;
|
|
2931
|
-
exports.setupAITracing = setupAITracing;
|
|
2932
|
-
exports.shutdownAITracingRegistry = shutdownAITracingRegistry;
|
|
2933
|
-
exports.unregisterAITracing = unregisterAITracing;
|
|
2934
|
-
exports.wrapMastra = wrapMastra;
|
|
2935
|
-
//# sourceMappingURL=chunk-P35FNLTQ.cjs.map
|
|
2936
|
-
//# sourceMappingURL=chunk-P35FNLTQ.cjs.map
|