@mastra/server 1.33.0-alpha.6 → 1.33.0-alpha.8
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 +159 -0
- package/dist/{api-schema-manifest-KDXQELMU.cjs → api-schema-manifest-CX3NL6JS.cjs} +6 -6
- package/dist/{api-schema-manifest-KDXQELMU.cjs.map → api-schema-manifest-CX3NL6JS.cjs.map} +1 -1
- package/dist/{api-schema-manifest-IWGQ5O45.js → api-schema-manifest-IK5MQPAL.js} +4 -4
- package/dist/{api-schema-manifest-IWGQ5O45.js.map → api-schema-manifest-IK5MQPAL.js.map} +1 -1
- package/dist/{chunk-IT26WLSZ.js → chunk-26PANWAR.js} +7 -7
- package/dist/{chunk-IT26WLSZ.js.map → chunk-26PANWAR.js.map} +1 -1
- package/dist/{chunk-LXNZK6NM.cjs → chunk-27VZ5B4Q.cjs} +77 -77
- package/dist/{chunk-LXNZK6NM.cjs.map → chunk-27VZ5B4Q.cjs.map} +1 -1
- package/dist/{chunk-MAG4W3GZ.cjs → chunk-2PS73C7N.cjs} +8 -8
- package/dist/{chunk-MAG4W3GZ.cjs.map → chunk-2PS73C7N.cjs.map} +1 -1
- package/dist/{chunk-34UYZN53.js → chunk-3AKQRYDF.js} +4 -4
- package/dist/{chunk-34UYZN53.js.map → chunk-3AKQRYDF.js.map} +1 -1
- package/dist/{chunk-5HQXXBTM.js → chunk-3DQGNGSK.js} +4 -4
- package/dist/{chunk-5HQXXBTM.js.map → chunk-3DQGNGSK.js.map} +1 -1
- package/dist/{chunk-WEDFF5FH.js → chunk-3SRLGVLX.js} +44 -44
- package/dist/chunk-3SRLGVLX.js.map +1 -0
- package/dist/{chunk-SX3C7B3A.cjs → chunk-4NVC7TM6.cjs} +28 -28
- package/dist/{chunk-SX3C7B3A.cjs.map → chunk-4NVC7TM6.cjs.map} +1 -1
- package/dist/{chunk-N6HISTTP.cjs → chunk-4ZO2MLW5.cjs} +16 -16
- package/dist/{chunk-N6HISTTP.cjs.map → chunk-4ZO2MLW5.cjs.map} +1 -1
- package/dist/{chunk-EQ27BVOT.js → chunk-5WYCXPDY.js} +4 -4
- package/dist/{chunk-EQ27BVOT.js.map → chunk-5WYCXPDY.js.map} +1 -1
- package/dist/{chunk-EFW6MWXU.cjs → chunk-5XW4MKE6.cjs} +22 -2
- package/dist/chunk-5XW4MKE6.cjs.map +1 -0
- package/dist/{chunk-MCS43WKI.cjs → chunk-6JP6Q64G.cjs} +10 -10
- package/dist/{chunk-MCS43WKI.cjs.map → chunk-6JP6Q64G.cjs.map} +1 -1
- package/dist/{chunk-ZO7SOILM.js → chunk-6V2NUA6I.js} +4 -4
- package/dist/{chunk-ZO7SOILM.js.map → chunk-6V2NUA6I.js.map} +1 -1
- package/dist/{chunk-64YJOWH2.cjs → chunk-72W42JL4.cjs} +5 -5
- package/dist/{chunk-64YJOWH2.cjs.map → chunk-72W42JL4.cjs.map} +1 -1
- package/dist/{chunk-NWD2SPUH.js → chunk-7LGTEZBD.js} +4 -4
- package/dist/{chunk-NWD2SPUH.js.map → chunk-7LGTEZBD.js.map} +1 -1
- package/dist/{chunk-2KDOM6QE.js → chunk-7PDQ67ZY.js} +108 -6
- package/dist/chunk-7PDQ67ZY.js.map +1 -0
- package/dist/{chunk-SOH5VORA.js → chunk-7RLQ6356.js} +3 -3
- package/dist/{chunk-SOH5VORA.js.map → chunk-7RLQ6356.js.map} +1 -1
- package/dist/{chunk-CYLX5SJ4.js → chunk-7SVSAMG4.js} +6 -6
- package/dist/{chunk-CYLX5SJ4.js.map → chunk-7SVSAMG4.js.map} +1 -1
- package/dist/{chunk-OAE7ZFYO.cjs → chunk-ALOM42GR.cjs} +24 -24
- package/dist/{chunk-OAE7ZFYO.cjs.map → chunk-ALOM42GR.cjs.map} +1 -1
- package/dist/{chunk-3EK2EVVE.js → chunk-ANIIJVPR.js} +4 -4
- package/dist/{chunk-3EK2EVVE.js.map → chunk-ANIIJVPR.js.map} +1 -1
- package/dist/chunk-B3CHYE7C.js +549 -0
- package/dist/chunk-B3CHYE7C.js.map +1 -0
- package/dist/{chunk-2HM5SQM5.js → chunk-BK2PTTTN.js} +4 -4
- package/dist/{chunk-2HM5SQM5.js.map → chunk-BK2PTTTN.js.map} +1 -1
- package/dist/{chunk-YN57WYLS.cjs → chunk-BNONPEW6.cjs} +11 -11
- package/dist/{chunk-YN57WYLS.cjs.map → chunk-BNONPEW6.cjs.map} +1 -1
- package/dist/{chunk-XPF4VEXO.js → chunk-BZ3NR3IS.js} +40 -38
- package/dist/chunk-BZ3NR3IS.js.map +1 -0
- package/dist/{chunk-4NPFEKIP.js → chunk-CG3AAC7C.js} +4 -4
- package/dist/{chunk-4NPFEKIP.js.map → chunk-CG3AAC7C.js.map} +1 -1
- package/dist/{chunk-VGNQKFWM.js → chunk-DC7NOATT.js} +3 -3
- package/dist/{chunk-VGNQKFWM.js.map → chunk-DC7NOATT.js.map} +1 -1
- package/dist/{chunk-WMS63TTU.cjs → chunk-DDF3ZASL.cjs} +168 -64
- package/dist/chunk-DDF3ZASL.cjs.map +1 -0
- package/dist/{chunk-NB7LJMYF.js → chunk-DPGNOE7R.js} +3 -3
- package/dist/{chunk-NB7LJMYF.js.map → chunk-DPGNOE7R.js.map} +1 -1
- package/dist/{chunk-KRMMYAXW.cjs → chunk-E7IOQCUP.cjs} +10 -10
- package/dist/{chunk-KRMMYAXW.cjs.map → chunk-E7IOQCUP.cjs.map} +1 -1
- package/dist/{chunk-RVAPXLP2.js → chunk-EFQBRUA4.js} +3 -3
- package/dist/{chunk-RVAPXLP2.js.map → chunk-EFQBRUA4.js.map} +1 -1
- package/dist/{chunk-4KNRG3KO.cjs → chunk-EN45CWWM.cjs} +18 -18
- package/dist/{chunk-4KNRG3KO.cjs.map → chunk-EN45CWWM.cjs.map} +1 -1
- package/dist/chunk-F3HP5HM6.cjs +998 -0
- package/dist/chunk-F3HP5HM6.cjs.map +1 -0
- package/dist/{chunk-Y3OQTZDN.js → chunk-FD3TJOO6.js} +44 -15
- package/dist/chunk-FD3TJOO6.js.map +1 -0
- package/dist/{chunk-PYT4SLHO.js → chunk-FJZ67HHA.js} +3 -3
- package/dist/{chunk-PYT4SLHO.js.map → chunk-FJZ67HHA.js.map} +1 -1
- package/dist/{chunk-TE2PWB67.js → chunk-GIMDOFRR.js} +4 -4
- package/dist/{chunk-TE2PWB67.js.map → chunk-GIMDOFRR.js.map} +1 -1
- package/dist/{chunk-MTKGUIFX.js → chunk-GJ3BKRTZ.js} +6 -6
- package/dist/{chunk-MTKGUIFX.js.map → chunk-GJ3BKRTZ.js.map} +1 -1
- package/dist/{chunk-UMXIU6E3.cjs → chunk-GNQ5SKPB.cjs} +7 -7
- package/dist/{chunk-UMXIU6E3.cjs.map → chunk-GNQ5SKPB.cjs.map} +1 -1
- package/dist/{chunk-AMZMBCKG.cjs → chunk-GOXW7A5J.cjs} +10 -10
- package/dist/{chunk-AMZMBCKG.cjs.map → chunk-GOXW7A5J.cjs.map} +1 -1
- package/dist/{chunk-EKS524LA.js → chunk-GP65L3TF.js} +83 -34
- package/dist/chunk-GP65L3TF.js.map +1 -0
- package/dist/{chunk-SYDZFUZI.js → chunk-GSL72DOW.js} +3 -3
- package/dist/{chunk-SYDZFUZI.js.map → chunk-GSL72DOW.js.map} +1 -1
- package/dist/{chunk-CSG535HL.cjs → chunk-GV2J3XQ4.cjs} +137 -108
- package/dist/chunk-GV2J3XQ4.cjs.map +1 -0
- package/dist/{chunk-VESPCO5X.js → chunk-ITIAC2TC.js} +3 -3
- package/dist/{chunk-VESPCO5X.js.map → chunk-ITIAC2TC.js.map} +1 -1
- package/dist/{chunk-BGRKLLHE.cjs → chunk-J62R54QE.cjs} +6 -6
- package/dist/{chunk-BGRKLLHE.cjs.map → chunk-J62R54QE.cjs.map} +1 -1
- package/dist/{chunk-BLK2XYVU.cjs → chunk-JLH5BHLT.cjs} +10 -10
- package/dist/{chunk-BLK2XYVU.cjs.map → chunk-JLH5BHLT.cjs.map} +1 -1
- package/dist/{chunk-UOC4K3RU.js → chunk-JOUPK2UV.js} +3 -3
- package/dist/{chunk-UOC4K3RU.js.map → chunk-JOUPK2UV.js.map} +1 -1
- package/dist/{chunk-HLDBO2H6.js → chunk-JSHKUN5Y.js} +3 -3
- package/dist/{chunk-HLDBO2H6.js.map → chunk-JSHKUN5Y.js.map} +1 -1
- package/dist/chunk-KUCITIUY.cjs +636 -0
- package/dist/chunk-KUCITIUY.cjs.map +1 -0
- package/dist/{chunk-LRYHYARK.js → chunk-KXZBJDFG.js} +4 -4
- package/dist/{chunk-LRYHYARK.js.map → chunk-KXZBJDFG.js.map} +1 -1
- package/dist/{chunk-MWXGGCHD.cjs → chunk-L742HQNI.cjs} +10 -10
- package/dist/{chunk-MWXGGCHD.cjs.map → chunk-L742HQNI.cjs.map} +1 -1
- package/dist/{chunk-ZOILZWQD.cjs → chunk-LKVE4QAW.cjs} +6 -6
- package/dist/{chunk-ZOILZWQD.cjs.map → chunk-LKVE4QAW.cjs.map} +1 -1
- package/dist/{chunk-6DAZZPVO.cjs → chunk-LNV75BVN.cjs} +38 -38
- package/dist/{chunk-6DAZZPVO.cjs.map → chunk-LNV75BVN.cjs.map} +1 -1
- package/dist/{chunk-S4L4CSQD.js → chunk-LRUC4D2Q.js} +3 -3
- package/dist/{chunk-S4L4CSQD.js.map → chunk-LRUC4D2Q.js.map} +1 -1
- package/dist/{chunk-ANXKF4TA.cjs → chunk-M62Z4EEY.cjs} +147 -147
- package/dist/chunk-M62Z4EEY.cjs.map +1 -0
- package/dist/{chunk-IYEGDP3G.js → chunk-M7DF3D2M.js} +3 -3
- package/dist/{chunk-IYEGDP3G.js.map → chunk-M7DF3D2M.js.map} +1 -1
- package/dist/{chunk-LOZT5NDU.cjs → chunk-MZ3RKQKS.cjs} +6 -6
- package/dist/{chunk-LOZT5NDU.cjs.map → chunk-MZ3RKQKS.cjs.map} +1 -1
- package/dist/{chunk-3OTCA7TP.js → chunk-NKCUF5ZH.js} +3 -3
- package/dist/{chunk-3OTCA7TP.js.map → chunk-NKCUF5ZH.js.map} +1 -1
- package/dist/{chunk-UOBKNRHM.cjs → chunk-NKYIWTT3.cjs} +12 -12
- package/dist/{chunk-UOBKNRHM.cjs.map → chunk-NKYIWTT3.cjs.map} +1 -1
- package/dist/{chunk-R7EB3VDI.cjs → chunk-NOQ45USI.cjs} +13 -13
- package/dist/{chunk-R7EB3VDI.cjs.map → chunk-NOQ45USI.cjs.map} +1 -1
- package/dist/{chunk-YQILRC5Y.cjs → chunk-OB4NE2YX.cjs} +10 -10
- package/dist/{chunk-YQILRC5Y.cjs.map → chunk-OB4NE2YX.cjs.map} +1 -1
- package/dist/{chunk-ICJ2ZVI2.cjs → chunk-OJFDLVAO.cjs} +13 -13
- package/dist/{chunk-ICJ2ZVI2.cjs.map → chunk-OJFDLVAO.cjs.map} +1 -1
- package/dist/{chunk-PM3UPQWH.cjs → chunk-P3TJ7MI6.cjs} +11 -11
- package/dist/{chunk-PM3UPQWH.cjs.map → chunk-P3TJ7MI6.cjs.map} +1 -1
- package/dist/{chunk-HYYXUP35.cjs → chunk-PJDFXAOL.cjs} +2 -2
- package/dist/{chunk-HYYXUP35.cjs.map → chunk-PJDFXAOL.cjs.map} +1 -1
- package/dist/{chunk-AWXCTLMK.cjs → chunk-PPCGMD6N.cjs} +11 -11
- package/dist/{chunk-AWXCTLMK.cjs.map → chunk-PPCGMD6N.cjs.map} +1 -1
- package/dist/{chunk-TWT64BVR.js → chunk-PUAKBO3Q.js} +45 -70
- package/dist/chunk-PUAKBO3Q.js.map +1 -0
- package/dist/{chunk-QEM5P746.cjs → chunk-PYGX3GUB.cjs} +71 -96
- package/dist/chunk-PYGX3GUB.cjs.map +1 -0
- package/dist/{chunk-ZSGVBBC4.js → chunk-QFGTTQFQ.js} +3 -3
- package/dist/{chunk-ZSGVBBC4.js.map → chunk-QFGTTQFQ.js.map} +1 -1
- package/dist/{chunk-HFF6QRLL.cjs → chunk-QISQJJPS.cjs} +6 -6
- package/dist/{chunk-HFF6QRLL.cjs.map → chunk-QISQJJPS.cjs.map} +1 -1
- package/dist/{chunk-IDLB647Y.js → chunk-QLJYRTD2.js} +4 -4
- package/dist/{chunk-IDLB647Y.js.map → chunk-QLJYRTD2.js.map} +1 -1
- package/dist/{chunk-STNEFHHA.js → chunk-RYOD3GP4.js} +4 -4
- package/dist/{chunk-STNEFHHA.js.map → chunk-RYOD3GP4.js.map} +1 -1
- package/dist/{chunk-KSQVYDDO.cjs → chunk-RYXKJ55A.cjs} +11 -11
- package/dist/{chunk-KSQVYDDO.cjs.map → chunk-RYXKJ55A.cjs.map} +1 -1
- package/dist/{chunk-GP45BMSR.js → chunk-SEMTGEAA.js} +3 -3
- package/dist/{chunk-GP45BMSR.js.map → chunk-SEMTGEAA.js.map} +1 -1
- package/dist/{chunk-C7Q5IMST.js → chunk-SFJOG2BT.js} +3 -3
- package/dist/{chunk-C7Q5IMST.js.map → chunk-SFJOG2BT.js.map} +1 -1
- package/dist/chunk-TLLV2JP5.js +983 -0
- package/dist/chunk-TLLV2JP5.js.map +1 -0
- package/dist/chunk-TTJ3DYZH.cjs +557 -0
- package/dist/chunk-TTJ3DYZH.cjs.map +1 -0
- package/dist/{chunk-WE5GUI23.js → chunk-UBOLRYFV.js} +3 -3
- package/dist/{chunk-WE5GUI23.js.map → chunk-UBOLRYFV.js.map} +1 -1
- package/dist/{chunk-GAS277DM.cjs → chunk-UVLX3WSX.cjs} +11 -11
- package/dist/{chunk-GAS277DM.cjs.map → chunk-UVLX3WSX.cjs.map} +1 -1
- package/dist/{chunk-HCIKFLLE.js → chunk-VMF4AV2C.js} +2 -2
- package/dist/{chunk-HCIKFLLE.js.map → chunk-VMF4AV2C.js.map} +1 -1
- package/dist/{chunk-KUBAQ732.cjs → chunk-VOBSGFM5.cjs} +10 -10
- package/dist/{chunk-KUBAQ732.cjs.map → chunk-VOBSGFM5.cjs.map} +1 -1
- package/dist/{chunk-5FHBVBU2.js → chunk-VQSY4I4H.js} +3 -3
- package/dist/{chunk-5FHBVBU2.js.map → chunk-VQSY4I4H.js.map} +1 -1
- package/dist/{chunk-GKN4IFE7.js → chunk-VYXPIZJE.js} +3 -3
- package/dist/{chunk-GKN4IFE7.js.map → chunk-VYXPIZJE.js.map} +1 -1
- package/dist/{chunk-WYQDPZNZ.cjs → chunk-W5B34RLN.cjs} +7 -7
- package/dist/{chunk-WYQDPZNZ.cjs.map → chunk-W5B34RLN.cjs.map} +1 -1
- package/dist/{chunk-VWBVA272.cjs → chunk-W6LHLN5M.cjs} +5 -5
- package/dist/{chunk-VWBVA272.cjs.map → chunk-W6LHLN5M.cjs.map} +1 -1
- package/dist/{chunk-KFEM2S5D.cjs → chunk-WWOML5Y4.cjs} +10 -10
- package/dist/{chunk-KFEM2S5D.cjs.map → chunk-WWOML5Y4.cjs.map} +1 -1
- package/dist/{chunk-Z7FXNI2N.cjs → chunk-XFDVU6GZ.cjs} +52 -52
- package/dist/{chunk-Z7FXNI2N.cjs.map → chunk-XFDVU6GZ.cjs.map} +1 -1
- package/dist/{chunk-BK2PRWVJ.cjs → chunk-Y5LNMKEY.cjs} +5 -5
- package/dist/{chunk-BK2PRWVJ.cjs.map → chunk-Y5LNMKEY.cjs.map} +1 -1
- package/dist/{chunk-OJRAH5VV.js → chunk-YARY4I5U.js} +18 -3
- package/dist/chunk-YARY4I5U.js.map +1 -0
- package/dist/{chunk-OJLXPTSL.cjs → chunk-YE56LUEI.cjs} +18 -18
- package/dist/{chunk-OJLXPTSL.cjs.map → chunk-YE56LUEI.cjs.map} +1 -1
- package/dist/{chunk-RQNN75EV.js → chunk-YGNA75MT.js} +5 -5
- package/dist/{chunk-RQNN75EV.js.map → chunk-YGNA75MT.js.map} +1 -1
- package/dist/{chunk-47U5QTGT.cjs → chunk-YYTMNPB7.cjs} +83 -34
- package/dist/chunk-YYTMNPB7.cjs.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/{observational-memory-HAJ3K5JJ-RB4HNAIV.cjs → observational-memory-2PRVG6BF-3V6S3B2J.cjs} +26 -26
- package/dist/{observational-memory-HAJ3K5JJ-RB4HNAIV.cjs.map → observational-memory-2PRVG6BF-3V6S3B2J.cjs.map} +1 -1
- package/dist/{observational-memory-HAJ3K5JJ-J2PZI56J.js → observational-memory-2PRVG6BF-4MT3GXPA.js} +3 -3
- package/dist/{observational-memory-HAJ3K5JJ-J2PZI56J.js.map → observational-memory-2PRVG6BF-4MT3GXPA.js.map} +1 -1
- package/dist/server/auth/index.cjs +15 -15
- package/dist/server/auth/index.js +1 -1
- package/dist/server/constants.d.ts +5 -0
- package/dist/server/constants.d.ts.map +1 -1
- package/dist/server/handlers/a2a.cjs +14 -14
- package/dist/server/handlers/a2a.js +1 -1
- package/dist/server/handlers/agent-builder.cjs +16 -16
- package/dist/server/handlers/agent-builder.js +1 -1
- package/dist/server/handlers/agent-versions.cjs +8 -8
- package/dist/server/handlers/agent-versions.js +1 -1
- package/dist/server/handlers/agents.cjs +39 -39
- package/dist/server/handlers/agents.d.ts.map +1 -1
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/auth.cjs +11 -11
- package/dist/server/handlers/auth.js +1 -1
- package/dist/server/handlers/background-tasks.cjs +4 -4
- package/dist/server/handlers/background-tasks.js +1 -1
- package/dist/server/handlers/channels.cjs +5 -5
- package/dist/server/handlers/channels.js +1 -1
- package/dist/server/handlers/conversations.cjs +5 -5
- package/dist/server/handlers/conversations.js +1 -1
- package/dist/server/handlers/datasets.cjs +26 -26
- package/dist/server/handlers/datasets.js +1 -1
- package/dist/server/handlers/logs.cjs +4 -4
- package/dist/server/handlers/logs.js +1 -1
- package/dist/server/handlers/mcp-client-versions.cjs +8 -8
- package/dist/server/handlers/mcp-client-versions.js +1 -1
- package/dist/server/handlers/mcp.cjs +11 -11
- package/dist/server/handlers/mcp.js +1 -1
- package/dist/server/handlers/memory.cjs +27 -27
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/observability-new-endpoints.cjs +28 -28
- package/dist/server/handlers/observability-new-endpoints.js +1 -1
- package/dist/server/handlers/observability.cjs +38 -38
- package/dist/server/handlers/observability.js +2 -2
- package/dist/server/handlers/processor-providers.cjs +3 -3
- package/dist/server/handlers/processor-providers.js +1 -1
- package/dist/server/handlers/processors.cjs +4 -4
- package/dist/server/handlers/processors.js +1 -1
- package/dist/server/handlers/prompt-block-versions.cjs +8 -8
- package/dist/server/handlers/prompt-block-versions.js +1 -1
- package/dist/server/handlers/responses.adapter.cjs +18 -14
- package/dist/server/handlers/responses.adapter.d.ts +96 -2
- package/dist/server/handlers/responses.adapter.d.ts.map +1 -1
- package/dist/server/handlers/responses.adapter.js +1 -1
- package/dist/server/handlers/responses.cjs +4 -4
- package/dist/server/handlers/responses.d.ts.map +1 -1
- package/dist/server/handlers/responses.js +1 -1
- package/dist/server/handlers/responses.storage.cjs +8 -8
- package/dist/server/handlers/responses.storage.d.ts +4 -2
- package/dist/server/handlers/responses.storage.d.ts.map +1 -1
- package/dist/server/handlers/responses.storage.js +1 -1
- package/dist/server/handlers/schedules.cjs +6 -6
- package/dist/server/handlers/schedules.js +1 -1
- package/dist/server/handlers/scorer-versions.cjs +8 -8
- package/dist/server/handlers/scorer-versions.js +1 -1
- package/dist/server/handlers/scores.cjs +7 -7
- package/dist/server/handlers/scores.js +1 -1
- package/dist/server/handlers/stored-agents.cjs +7 -7
- package/dist/server/handlers/stored-agents.js +1 -1
- package/dist/server/handlers/stored-mcp-clients.cjs +6 -6
- package/dist/server/handlers/stored-mcp-clients.js +1 -1
- package/dist/server/handlers/stored-prompt-blocks.cjs +6 -6
- package/dist/server/handlers/stored-prompt-blocks.js +1 -1
- package/dist/server/handlers/stored-scorers.cjs +6 -6
- package/dist/server/handlers/stored-scorers.js +1 -1
- package/dist/server/handlers/stored-skills.cjs +7 -7
- package/dist/server/handlers/stored-skills.js +1 -1
- package/dist/server/handlers/stored-workspaces.cjs +6 -6
- package/dist/server/handlers/stored-workspaces.js +1 -1
- package/dist/server/handlers/system.cjs +3 -3
- package/dist/server/handlers/system.js +1 -1
- package/dist/server/handlers/tool-providers.cjs +5 -5
- package/dist/server/handlers/tool-providers.js +1 -1
- package/dist/server/handlers/tools.cjs +6 -6
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/utils.cjs +10 -10
- package/dist/server/handlers/utils.js +1 -1
- package/dist/server/handlers/vector.cjs +16 -16
- package/dist/server/handlers/vector.js +1 -1
- package/dist/server/handlers/voice.cjs +8 -8
- package/dist/server/handlers/voice.js +1 -1
- package/dist/server/handlers/workflows.cjs +32 -24
- package/dist/server/handlers/workflows.d.ts +83 -0
- package/dist/server/handlers/workflows.d.ts.map +1 -1
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers/workspace.cjs +26 -26
- package/dist/server/handlers/workspace.js +1 -1
- package/dist/server/handlers.cjs +30 -30
- package/dist/server/handlers.js +15 -15
- package/dist/server/server-adapter/index.cjs +55 -28
- package/dist/server/server-adapter/index.cjs.map +1 -1
- package/dist/server/server-adapter/index.d.ts +5 -1
- package/dist/server/server-adapter/index.d.ts.map +1 -1
- package/dist/server/server-adapter/index.js +19 -11
- package/dist/server/server-adapter/index.js.map +1 -1
- package/dist/server/server-adapter/routes/workflows.d.ts +66 -1
- package/dist/server/server-adapter/routes/workflows.d.ts.map +1 -1
- package/package.json +6 -6
- package/dist/chunk-2KDOM6QE.js.map +0 -1
- package/dist/chunk-47U5QTGT.cjs.map +0 -1
- package/dist/chunk-AJYJ4H7P.js +0 -438
- package/dist/chunk-AJYJ4H7P.js.map +0 -1
- package/dist/chunk-ANXKF4TA.cjs.map +0 -1
- package/dist/chunk-CSG535HL.cjs.map +0 -1
- package/dist/chunk-DFSUBEGE.js +0 -226
- package/dist/chunk-DFSUBEGE.js.map +0 -1
- package/dist/chunk-EFW6MWXU.cjs.map +0 -1
- package/dist/chunk-EKS524LA.js.map +0 -1
- package/dist/chunk-OJ72T77G.cjs +0 -452
- package/dist/chunk-OJ72T77G.cjs.map +0 -1
- package/dist/chunk-OJRAH5VV.js.map +0 -1
- package/dist/chunk-PJYQMPXT.cjs +0 -234
- package/dist/chunk-PJYQMPXT.cjs.map +0 -1
- package/dist/chunk-QEM5P746.cjs.map +0 -1
- package/dist/chunk-TWT64BVR.js.map +0 -1
- package/dist/chunk-VZNSMKB7.cjs +0 -634
- package/dist/chunk-VZNSMKB7.cjs.map +0 -1
- package/dist/chunk-WEDFF5FH.js.map +0 -1
- package/dist/chunk-WMS63TTU.cjs.map +0 -1
- package/dist/chunk-XPF4VEXO.js.map +0 -1
- package/dist/chunk-Y3OQTZDN.js.map +0 -1
|
@@ -0,0 +1,998 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var crypto = require('crypto');
|
|
4
|
+
var tools = require('@mastra/core/tools');
|
|
5
|
+
var zodToJson = require('@mastra/core/utils/zod-to-json');
|
|
6
|
+
|
|
7
|
+
// src/server/handlers/responses.adapter.ts
|
|
8
|
+
function normalizeMessageContent(content) {
|
|
9
|
+
if (typeof content === "string") {
|
|
10
|
+
return content;
|
|
11
|
+
}
|
|
12
|
+
return content.map((part) => part.text).join("");
|
|
13
|
+
}
|
|
14
|
+
function getMessageText(message) {
|
|
15
|
+
const parts = Array.isArray(message.content?.parts) ? message.content.parts : [];
|
|
16
|
+
return parts.flatMap((part) => part.type === "text" ? [part.text] : []).filter((text) => typeof text === "string").join("");
|
|
17
|
+
}
|
|
18
|
+
function isRecord(value) {
|
|
19
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20
|
+
}
|
|
21
|
+
function getMessageRole(message) {
|
|
22
|
+
return message.role ?? "";
|
|
23
|
+
}
|
|
24
|
+
function getToolKey(toolCallId, messageId, partIndex) {
|
|
25
|
+
return `${messageId}:${partIndex}`;
|
|
26
|
+
}
|
|
27
|
+
function getFunctionCallOutputItemId(toolCallId) {
|
|
28
|
+
return `${toolCallId}:output`;
|
|
29
|
+
}
|
|
30
|
+
function normalizeToolParameters(schema) {
|
|
31
|
+
if (!isRecord(schema)) {
|
|
32
|
+
return schema;
|
|
33
|
+
}
|
|
34
|
+
if (isRecord(schema.json) && Object.keys(schema).length === 1) {
|
|
35
|
+
return schema.json;
|
|
36
|
+
}
|
|
37
|
+
return schema;
|
|
38
|
+
}
|
|
39
|
+
function mapMastraToolsToResponseTools(tools$1) {
|
|
40
|
+
if (!tools$1) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
return Object.values(tools$1).flatMap((tool) => {
|
|
44
|
+
if (!isRecord(tool)) {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
const name = typeof tool.id === "string" ? tool.id : typeof tool.name === "string" ? tool.name : null;
|
|
48
|
+
if (!name) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
const description = typeof tool.description === "string" ? tool.description : void 0;
|
|
52
|
+
let parameters;
|
|
53
|
+
if (tools.isProviderDefinedTool(tool)) {
|
|
54
|
+
const resolvedSchema = typeof tool.inputSchema === "function" ? tool.inputSchema() : tool.inputSchema;
|
|
55
|
+
parameters = isRecord(resolvedSchema) && "jsonSchema" in resolvedSchema ? normalizeToolParameters(resolvedSchema.jsonSchema) : void 0;
|
|
56
|
+
} else if ("inputSchema" in tool && tool.inputSchema) {
|
|
57
|
+
parameters = normalizeToolParameters(zodToJson.zodToJsonSchema(tool.inputSchema));
|
|
58
|
+
}
|
|
59
|
+
return [
|
|
60
|
+
{
|
|
61
|
+
type: "function",
|
|
62
|
+
name,
|
|
63
|
+
...description ? { description } : {},
|
|
64
|
+
...parameters !== void 0 ? { parameters: JSON.parse(JSON.stringify(parameters)) } : {}
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function stringifyToolPayload(value) {
|
|
70
|
+
if (typeof value === "string") {
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
return JSON.stringify(value === void 0 ? {} : value);
|
|
74
|
+
}
|
|
75
|
+
function stringifyToolArguments(value) {
|
|
76
|
+
if (isRecord(value) && typeof value.__raw === "string") {
|
|
77
|
+
return value.__raw;
|
|
78
|
+
}
|
|
79
|
+
return stringifyToolPayload(value === null ? void 0 : value);
|
|
80
|
+
}
|
|
81
|
+
function createOutputMessage({
|
|
82
|
+
messageId,
|
|
83
|
+
status,
|
|
84
|
+
text
|
|
85
|
+
}) {
|
|
86
|
+
const responseStatus = status === "completed" ? "completed" : "incomplete";
|
|
87
|
+
return {
|
|
88
|
+
id: messageId,
|
|
89
|
+
type: "message",
|
|
90
|
+
role: "assistant",
|
|
91
|
+
status: responseStatus,
|
|
92
|
+
content: [createOutputTextPart(text)]
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function createConversationMessage({
|
|
96
|
+
messageId,
|
|
97
|
+
role,
|
|
98
|
+
text
|
|
99
|
+
}) {
|
|
100
|
+
return {
|
|
101
|
+
id: messageId,
|
|
102
|
+
type: "message",
|
|
103
|
+
role,
|
|
104
|
+
status: "completed",
|
|
105
|
+
content: [
|
|
106
|
+
role === "assistant" ? createOutputTextPart(text) : {
|
|
107
|
+
type: "input_text",
|
|
108
|
+
text
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function createFunctionCallItem({
|
|
114
|
+
itemId,
|
|
115
|
+
callId,
|
|
116
|
+
name,
|
|
117
|
+
args
|
|
118
|
+
}) {
|
|
119
|
+
return {
|
|
120
|
+
id: itemId,
|
|
121
|
+
type: "function_call",
|
|
122
|
+
call_id: callId,
|
|
123
|
+
name,
|
|
124
|
+
arguments: stringifyToolArguments(args),
|
|
125
|
+
status: "completed"
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function createFunctionCallOutputItem({ itemId, callId, output }) {
|
|
129
|
+
return {
|
|
130
|
+
id: itemId,
|
|
131
|
+
type: "function_call_output",
|
|
132
|
+
call_id: callId,
|
|
133
|
+
output: stringifyToolPayload(output)
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function collectToolResultCallIds(messages) {
|
|
137
|
+
const toolResultCallIds = /* @__PURE__ */ new Set();
|
|
138
|
+
for (const message of messages) {
|
|
139
|
+
const parts = Array.isArray(message.content?.parts) ? message.content.parts : [];
|
|
140
|
+
for (const [partIndex, part] of parts.entries()) {
|
|
141
|
+
if (!isRecord(part) || part.type !== "tool-invocation" || !isRecord(part.toolInvocation)) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const toolInvocation = part.toolInvocation;
|
|
145
|
+
const toolCallId = typeof toolInvocation.toolCallId === "string" ? toolInvocation.toolCallId : getToolKey(null, message.id, partIndex);
|
|
146
|
+
if (getMessageRole(message) === "tool" && toolInvocation.result !== void 0) {
|
|
147
|
+
toolResultCallIds.add(toolCallId);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return toolResultCallIds;
|
|
152
|
+
}
|
|
153
|
+
function mapMastraMessageToResponseToolItems({
|
|
154
|
+
message,
|
|
155
|
+
toolResultCallIds,
|
|
156
|
+
emittedCallIds,
|
|
157
|
+
emittedResultCallIds
|
|
158
|
+
}) {
|
|
159
|
+
const items = [];
|
|
160
|
+
const parts = Array.isArray(message.content?.parts) ? message.content.parts : [];
|
|
161
|
+
for (const [partIndex, part] of parts.entries()) {
|
|
162
|
+
if (!isRecord(part) || part.type !== "tool-invocation" || !isRecord(part.toolInvocation)) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const toolInvocation = part.toolInvocation;
|
|
166
|
+
const toolName = typeof toolInvocation.toolName === "string" ? toolInvocation.toolName : null;
|
|
167
|
+
const toolCallId = typeof toolInvocation.toolCallId === "string" ? toolInvocation.toolCallId : getToolKey(null, message.id, partIndex);
|
|
168
|
+
if (getMessageRole(message) === "assistant" && toolName && !emittedCallIds.has(toolCallId)) {
|
|
169
|
+
items.push(
|
|
170
|
+
createFunctionCallItem({
|
|
171
|
+
itemId: toolCallId,
|
|
172
|
+
callId: toolCallId,
|
|
173
|
+
name: toolName,
|
|
174
|
+
args: toolInvocation.args
|
|
175
|
+
})
|
|
176
|
+
);
|
|
177
|
+
emittedCallIds.add(toolCallId);
|
|
178
|
+
}
|
|
179
|
+
if (toolInvocation.result !== void 0 && !emittedResultCallIds.has(toolCallId) && (getMessageRole(message) === "tool" || !toolResultCallIds.has(toolCallId))) {
|
|
180
|
+
items.push(
|
|
181
|
+
createFunctionCallOutputItem({
|
|
182
|
+
itemId: getFunctionCallOutputItemId(toolCallId),
|
|
183
|
+
callId: toolCallId,
|
|
184
|
+
output: toolInvocation.result
|
|
185
|
+
})
|
|
186
|
+
);
|
|
187
|
+
emittedResultCallIds.add(toolCallId);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return items;
|
|
191
|
+
}
|
|
192
|
+
function mapMastraMessagesToConversationItems(messages) {
|
|
193
|
+
if (!messages.length) {
|
|
194
|
+
return [];
|
|
195
|
+
}
|
|
196
|
+
const items = [];
|
|
197
|
+
const toolResultCallIds = collectToolResultCallIds(messages);
|
|
198
|
+
const emittedCallIds = /* @__PURE__ */ new Set();
|
|
199
|
+
const emittedResultCallIds = /* @__PURE__ */ new Set();
|
|
200
|
+
for (const message of messages) {
|
|
201
|
+
items.push(
|
|
202
|
+
...mapMastraMessageToResponseToolItems({
|
|
203
|
+
message,
|
|
204
|
+
toolResultCallIds,
|
|
205
|
+
emittedCallIds,
|
|
206
|
+
emittedResultCallIds
|
|
207
|
+
})
|
|
208
|
+
);
|
|
209
|
+
const role = getMessageRole(message);
|
|
210
|
+
const text = getMessageText(message);
|
|
211
|
+
if ((role === "user" || role === "system" || role === "assistant") && text) {
|
|
212
|
+
items.push(
|
|
213
|
+
createConversationMessage({
|
|
214
|
+
messageId: message.id,
|
|
215
|
+
role,
|
|
216
|
+
text
|
|
217
|
+
})
|
|
218
|
+
);
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (role === "assistant" && !text) {
|
|
222
|
+
const parts = Array.isArray(message.content?.parts) ? message.content.parts : [];
|
|
223
|
+
const hasOnlyToolInvocations = parts.every(
|
|
224
|
+
(part) => isRecord(part) && part.type === "tool-invocation" && isRecord(part.toolInvocation)
|
|
225
|
+
);
|
|
226
|
+
if (hasOnlyToolInvocations) {
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (role === "tool") {
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return items;
|
|
235
|
+
}
|
|
236
|
+
function mergeFallbackOutputItems({
|
|
237
|
+
output,
|
|
238
|
+
fallbackOutputItems
|
|
239
|
+
}) {
|
|
240
|
+
if (!fallbackOutputItems.length) {
|
|
241
|
+
return output;
|
|
242
|
+
}
|
|
243
|
+
const outputById = new Map(output.map((item) => [item.id, item]));
|
|
244
|
+
const fallbackIds = new Set(fallbackOutputItems.map((item) => item.id));
|
|
245
|
+
return [
|
|
246
|
+
...fallbackOutputItems.map((item) => outputById.get(item.id) ?? item),
|
|
247
|
+
...output.filter((item) => !fallbackIds.has(item.id))
|
|
248
|
+
];
|
|
249
|
+
}
|
|
250
|
+
function getOutputMessageText(item) {
|
|
251
|
+
return item.content.map((part) => part.text).join("");
|
|
252
|
+
}
|
|
253
|
+
function mapMastraMessagesToResponseOutputItems({
|
|
254
|
+
messages,
|
|
255
|
+
outputMessageId,
|
|
256
|
+
status,
|
|
257
|
+
fallbackText,
|
|
258
|
+
fallbackOutputItems = []
|
|
259
|
+
}) {
|
|
260
|
+
if (!messages?.length) {
|
|
261
|
+
if (fallbackOutputItems.length) {
|
|
262
|
+
return fallbackOutputItems;
|
|
263
|
+
}
|
|
264
|
+
return [createOutputMessage({ messageId: outputMessageId, status, text: fallbackText })];
|
|
265
|
+
}
|
|
266
|
+
const output = [];
|
|
267
|
+
const lastAssistantIndex = [...messages].map((message) => message.role).lastIndexOf("assistant");
|
|
268
|
+
const outputMessageIndex = [...messages].map((message, index) => ({ index, message })).reverse().find(({ message }) => getMessageRole(message) === "assistant" && getMessageText(message))?.index ?? lastAssistantIndex;
|
|
269
|
+
const toolResultCallIds = collectToolResultCallIds(messages);
|
|
270
|
+
const emittedCallIds = /* @__PURE__ */ new Set();
|
|
271
|
+
const emittedResultCallIds = /* @__PURE__ */ new Set();
|
|
272
|
+
const fallbackMessageItems = fallbackOutputItems.filter(
|
|
273
|
+
(item) => item.type === "message"
|
|
274
|
+
);
|
|
275
|
+
const emittedFallbackMessageIds = /* @__PURE__ */ new Set();
|
|
276
|
+
const getOutputMessageId = ({
|
|
277
|
+
message,
|
|
278
|
+
text,
|
|
279
|
+
useOutputMessageId
|
|
280
|
+
}) => {
|
|
281
|
+
const directFallbackItem = fallbackMessageItems.find((item) => item.id === message.id);
|
|
282
|
+
if (directFallbackItem) {
|
|
283
|
+
emittedFallbackMessageIds.add(directFallbackItem.id);
|
|
284
|
+
return directFallbackItem.id;
|
|
285
|
+
}
|
|
286
|
+
if (useOutputMessageId) {
|
|
287
|
+
const matchingFallbackItem = fallbackMessageItems.find(
|
|
288
|
+
(item) => item.id !== outputMessageId && !emittedFallbackMessageIds.has(item.id) && getOutputMessageText(item) === text
|
|
289
|
+
);
|
|
290
|
+
if (matchingFallbackItem) {
|
|
291
|
+
emittedFallbackMessageIds.add(matchingFallbackItem.id);
|
|
292
|
+
return matchingFallbackItem.id;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return useOutputMessageId ? outputMessageId : message.id;
|
|
296
|
+
};
|
|
297
|
+
for (const [messageIndex, message] of messages.entries()) {
|
|
298
|
+
output.push(
|
|
299
|
+
...mapMastraMessageToResponseToolItems({
|
|
300
|
+
message,
|
|
301
|
+
toolResultCallIds,
|
|
302
|
+
emittedCallIds,
|
|
303
|
+
emittedResultCallIds
|
|
304
|
+
})
|
|
305
|
+
);
|
|
306
|
+
const text = getMessageText(message);
|
|
307
|
+
if (getMessageRole(message) === "assistant" && text) {
|
|
308
|
+
const useOutputMessageId = messageIndex === outputMessageIndex;
|
|
309
|
+
output.push(
|
|
310
|
+
createOutputMessage({
|
|
311
|
+
messageId: getOutputMessageId({ message, text, useOutputMessageId }),
|
|
312
|
+
status,
|
|
313
|
+
text
|
|
314
|
+
})
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (!output.some((item) => item.type === "message") && fallbackText) {
|
|
319
|
+
output.push(createOutputMessage({ messageId: outputMessageId, status, text: fallbackText }));
|
|
320
|
+
}
|
|
321
|
+
return mergeFallbackOutputItems({ output, fallbackOutputItems });
|
|
322
|
+
}
|
|
323
|
+
function createMessageId() {
|
|
324
|
+
return `msg_${crypto.randomUUID()}`;
|
|
325
|
+
}
|
|
326
|
+
function mapResponseInputToExecutionMessages(input) {
|
|
327
|
+
if (typeof input === "string") {
|
|
328
|
+
return [{ role: "user", content: input }];
|
|
329
|
+
}
|
|
330
|
+
return input.map((message) => ({
|
|
331
|
+
role: message.role === "developer" ? "system" : message.role,
|
|
332
|
+
content: normalizeMessageContent(message.content)
|
|
333
|
+
}));
|
|
334
|
+
}
|
|
335
|
+
function toResponseUsage(usage) {
|
|
336
|
+
if (!usage) {
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
const inputTokens = usage.inputTokens ?? usage.promptTokens ?? 0;
|
|
340
|
+
const outputTokens = usage.outputTokens ?? usage.completionTokens ?? 0;
|
|
341
|
+
const totalTokens = usage.totalTokens ?? inputTokens + outputTokens;
|
|
342
|
+
return {
|
|
343
|
+
input_tokens: inputTokens,
|
|
344
|
+
output_tokens: outputTokens,
|
|
345
|
+
total_tokens: totalTokens,
|
|
346
|
+
input_tokens_details: {
|
|
347
|
+
cached_tokens: 0
|
|
348
|
+
},
|
|
349
|
+
output_tokens_details: {
|
|
350
|
+
reasoning_tokens: 0
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
function toResponseStatus(finishReason) {
|
|
355
|
+
if (finishReason === "suspended" || finishReason === "error") {
|
|
356
|
+
return "incomplete";
|
|
357
|
+
}
|
|
358
|
+
return "completed";
|
|
359
|
+
}
|
|
360
|
+
function createOutputTextPart(text) {
|
|
361
|
+
return {
|
|
362
|
+
type: "output_text",
|
|
363
|
+
text,
|
|
364
|
+
annotations: [],
|
|
365
|
+
logprobs: []
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
function buildCompletedResponse({
|
|
369
|
+
responseId,
|
|
370
|
+
outputMessageId,
|
|
371
|
+
model,
|
|
372
|
+
createdAt,
|
|
373
|
+
completedAt,
|
|
374
|
+
status,
|
|
375
|
+
text,
|
|
376
|
+
usage,
|
|
377
|
+
instructions,
|
|
378
|
+
textConfig,
|
|
379
|
+
previousResponseId,
|
|
380
|
+
conversationId,
|
|
381
|
+
providerOptions,
|
|
382
|
+
tools,
|
|
383
|
+
store,
|
|
384
|
+
messages,
|
|
385
|
+
fallbackOutputItems
|
|
386
|
+
}) {
|
|
387
|
+
return {
|
|
388
|
+
id: responseId,
|
|
389
|
+
object: "response",
|
|
390
|
+
created_at: createdAt,
|
|
391
|
+
completed_at: completedAt,
|
|
392
|
+
model,
|
|
393
|
+
status,
|
|
394
|
+
output: mapMastraMessagesToResponseOutputItems({
|
|
395
|
+
messages,
|
|
396
|
+
outputMessageId,
|
|
397
|
+
status,
|
|
398
|
+
fallbackText: text,
|
|
399
|
+
fallbackOutputItems
|
|
400
|
+
}),
|
|
401
|
+
usage: toResponseUsage(usage),
|
|
402
|
+
error: null,
|
|
403
|
+
incomplete_details: null,
|
|
404
|
+
instructions: instructions ?? null,
|
|
405
|
+
text: textConfig ?? null,
|
|
406
|
+
previous_response_id: previousResponseId ?? null,
|
|
407
|
+
conversation_id: conversationId ?? null,
|
|
408
|
+
providerOptions,
|
|
409
|
+
tools,
|
|
410
|
+
store
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
function buildInProgressResponse({
|
|
414
|
+
responseId,
|
|
415
|
+
model,
|
|
416
|
+
createdAt,
|
|
417
|
+
instructions,
|
|
418
|
+
textConfig,
|
|
419
|
+
previousResponseId,
|
|
420
|
+
conversationId,
|
|
421
|
+
tools,
|
|
422
|
+
store
|
|
423
|
+
}) {
|
|
424
|
+
return {
|
|
425
|
+
id: responseId,
|
|
426
|
+
object: "response",
|
|
427
|
+
created_at: createdAt,
|
|
428
|
+
completed_at: null,
|
|
429
|
+
model,
|
|
430
|
+
status: "in_progress",
|
|
431
|
+
output: [],
|
|
432
|
+
usage: null,
|
|
433
|
+
error: null,
|
|
434
|
+
incomplete_details: null,
|
|
435
|
+
instructions: instructions ?? null,
|
|
436
|
+
text: textConfig ?? null,
|
|
437
|
+
previous_response_id: previousResponseId ?? null,
|
|
438
|
+
conversation_id: conversationId ?? null,
|
|
439
|
+
tools: tools ?? [],
|
|
440
|
+
store
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
function mapResponseTurnRecordToResponse(match) {
|
|
444
|
+
return {
|
|
445
|
+
id: match.message.id,
|
|
446
|
+
object: "response",
|
|
447
|
+
created_at: match.metadata.createdAt,
|
|
448
|
+
completed_at: match.metadata.completedAt,
|
|
449
|
+
model: match.metadata.model,
|
|
450
|
+
status: match.metadata.status,
|
|
451
|
+
output: mapMastraMessagesToResponseOutputItems({
|
|
452
|
+
messages: match.messages,
|
|
453
|
+
outputMessageId: match.message.id,
|
|
454
|
+
status: match.metadata.status,
|
|
455
|
+
fallbackText: getMessageText(match.message),
|
|
456
|
+
fallbackOutputItems: match.metadata.outputItems
|
|
457
|
+
}),
|
|
458
|
+
usage: match.metadata.usage,
|
|
459
|
+
error: null,
|
|
460
|
+
incomplete_details: null,
|
|
461
|
+
instructions: match.metadata.instructions ?? null,
|
|
462
|
+
text: match.metadata.text ?? null,
|
|
463
|
+
previous_response_id: match.metadata.previousResponseId ?? null,
|
|
464
|
+
conversation_id: match.thread.id,
|
|
465
|
+
providerOptions: match.metadata.providerOptions,
|
|
466
|
+
tools: match.metadata.tools,
|
|
467
|
+
store: match.metadata.store
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
function formatSseEvent(event, data) {
|
|
471
|
+
return new TextEncoder().encode(`event: ${event}
|
|
472
|
+
data: ${JSON.stringify(data)}
|
|
473
|
+
|
|
474
|
+
`);
|
|
475
|
+
}
|
|
476
|
+
function extractTextDelta(value) {
|
|
477
|
+
if (typeof value !== "object" || value === null || !("type" in value)) {
|
|
478
|
+
return null;
|
|
479
|
+
}
|
|
480
|
+
const chunk = value;
|
|
481
|
+
switch (chunk.type) {
|
|
482
|
+
case "text-delta":
|
|
483
|
+
if (typeof chunk.payload?.text === "string") {
|
|
484
|
+
return chunk.payload.text;
|
|
485
|
+
}
|
|
486
|
+
if (typeof chunk.textDelta === "string") {
|
|
487
|
+
return chunk.textDelta;
|
|
488
|
+
}
|
|
489
|
+
if (typeof chunk.text === "string") {
|
|
490
|
+
return chunk.text;
|
|
491
|
+
}
|
|
492
|
+
return null;
|
|
493
|
+
default:
|
|
494
|
+
return null;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
function createResponseSseEvent(payload) {
|
|
498
|
+
return { event: payload.type, payload };
|
|
499
|
+
}
|
|
500
|
+
function getChunkPayload(value) {
|
|
501
|
+
if (!isRecord(value)) {
|
|
502
|
+
return null;
|
|
503
|
+
}
|
|
504
|
+
return isRecord(value.payload) ? value.payload : value;
|
|
505
|
+
}
|
|
506
|
+
function stringifyResponsePayload(value) {
|
|
507
|
+
if (typeof value === "string") {
|
|
508
|
+
return value;
|
|
509
|
+
}
|
|
510
|
+
return JSON.stringify(value === void 0 ? {} : value);
|
|
511
|
+
}
|
|
512
|
+
function stringifyFunctionCallArguments(value, fallback = "") {
|
|
513
|
+
const serialized = value === void 0 || value === null ? fallback : stringifyResponsePayload(value);
|
|
514
|
+
return serialized || fallback || "{}";
|
|
515
|
+
}
|
|
516
|
+
function removeWhitespaceOutsideJsonStrings(value) {
|
|
517
|
+
let inString = false;
|
|
518
|
+
let escaped = false;
|
|
519
|
+
let result = "";
|
|
520
|
+
for (const char of value) {
|
|
521
|
+
if (escaped) {
|
|
522
|
+
escaped = false;
|
|
523
|
+
result += char;
|
|
524
|
+
continue;
|
|
525
|
+
}
|
|
526
|
+
if (char === "\\" && inString) {
|
|
527
|
+
escaped = true;
|
|
528
|
+
result += char;
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
if (char === '"') {
|
|
532
|
+
inString = !inString;
|
|
533
|
+
result += char;
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
if (!inString && /\s/.test(char)) {
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
result += char;
|
|
540
|
+
}
|
|
541
|
+
return result;
|
|
542
|
+
}
|
|
543
|
+
function getRemainingArgumentsDelta(current, canonical) {
|
|
544
|
+
if (!current) {
|
|
545
|
+
return canonical;
|
|
546
|
+
}
|
|
547
|
+
if (canonical.startsWith(current)) {
|
|
548
|
+
return canonical.slice(current.length);
|
|
549
|
+
}
|
|
550
|
+
const compactCurrent = removeWhitespaceOutsideJsonStrings(current);
|
|
551
|
+
const compactCanonical = removeWhitespaceOutsideJsonStrings(canonical);
|
|
552
|
+
if (compactCurrent && compactCanonical.startsWith(compactCurrent)) {
|
|
553
|
+
return compactCanonical.slice(compactCurrent.length);
|
|
554
|
+
}
|
|
555
|
+
return null;
|
|
556
|
+
}
|
|
557
|
+
function isCompleteJsonString(value) {
|
|
558
|
+
if (!value) {
|
|
559
|
+
return true;
|
|
560
|
+
}
|
|
561
|
+
try {
|
|
562
|
+
JSON.parse(value);
|
|
563
|
+
return true;
|
|
564
|
+
} catch {
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
function serializeToolError(error) {
|
|
569
|
+
if (error instanceof Error) {
|
|
570
|
+
return { error: error.message };
|
|
571
|
+
}
|
|
572
|
+
return { error };
|
|
573
|
+
}
|
|
574
|
+
function getToolCallStart(value) {
|
|
575
|
+
if (!isRecord(value) || value.type !== "tool-call-input-streaming-start") {
|
|
576
|
+
return null;
|
|
577
|
+
}
|
|
578
|
+
const payload = getChunkPayload(value);
|
|
579
|
+
const toolCallId = payload?.toolCallId;
|
|
580
|
+
const toolName = payload?.toolName;
|
|
581
|
+
if (typeof toolCallId !== "string" || typeof toolName !== "string") {
|
|
582
|
+
return null;
|
|
583
|
+
}
|
|
584
|
+
return { toolCallId, toolName };
|
|
585
|
+
}
|
|
586
|
+
function getToolCallDelta(value) {
|
|
587
|
+
if (!isRecord(value) || value.type !== "tool-call-delta") {
|
|
588
|
+
return null;
|
|
589
|
+
}
|
|
590
|
+
const payload = getChunkPayload(value);
|
|
591
|
+
const toolCallId = payload?.toolCallId;
|
|
592
|
+
const delta = payload?.argsTextDelta ?? payload?.inputTextDelta ?? payload?.argsDelta ?? payload?.delta;
|
|
593
|
+
if (!payload || typeof toolCallId !== "string" || typeof delta !== "string") {
|
|
594
|
+
return null;
|
|
595
|
+
}
|
|
596
|
+
return {
|
|
597
|
+
toolCallId,
|
|
598
|
+
toolName: typeof payload.toolName === "string" ? payload.toolName : void 0,
|
|
599
|
+
delta
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
function getToolCall(value) {
|
|
603
|
+
if (!isRecord(value) || value.type !== "tool-call") {
|
|
604
|
+
return null;
|
|
605
|
+
}
|
|
606
|
+
const payload = getChunkPayload(value);
|
|
607
|
+
const toolCallId = payload?.toolCallId;
|
|
608
|
+
const toolName = payload?.toolName;
|
|
609
|
+
const args = payload?.args ?? payload?.input;
|
|
610
|
+
if (typeof toolCallId !== "string" || typeof toolName !== "string") {
|
|
611
|
+
return null;
|
|
612
|
+
}
|
|
613
|
+
return { toolCallId, toolName, args };
|
|
614
|
+
}
|
|
615
|
+
function getToolCallEnd(value) {
|
|
616
|
+
if (!isRecord(value) || value.type !== "tool-call-input-streaming-end") {
|
|
617
|
+
return null;
|
|
618
|
+
}
|
|
619
|
+
const payload = getChunkPayload(value);
|
|
620
|
+
const toolCallId = payload?.toolCallId;
|
|
621
|
+
if (typeof toolCallId !== "string") {
|
|
622
|
+
return null;
|
|
623
|
+
}
|
|
624
|
+
return { toolCallId };
|
|
625
|
+
}
|
|
626
|
+
function getToolResult(value) {
|
|
627
|
+
if (!isRecord(value) || value.type !== "tool-result" && value.type !== "tool-error") {
|
|
628
|
+
return null;
|
|
629
|
+
}
|
|
630
|
+
const payload = getChunkPayload(value);
|
|
631
|
+
const toolCallId = payload?.toolCallId;
|
|
632
|
+
if (!payload || typeof toolCallId !== "string") {
|
|
633
|
+
return null;
|
|
634
|
+
}
|
|
635
|
+
const toolName = typeof payload.toolName === "string" ? payload.toolName : void 0;
|
|
636
|
+
const args = payload.args ?? payload.input;
|
|
637
|
+
if (value.type === "tool-error") {
|
|
638
|
+
return { toolCallId, toolName, args, result: serializeToolError(payload.error) };
|
|
639
|
+
}
|
|
640
|
+
const outputValue = payload.result !== void 0 ? payload.result : payload.output;
|
|
641
|
+
const result = payload.isError ? serializeToolError(outputValue) : outputValue;
|
|
642
|
+
return { toolCallId, toolName, args, result };
|
|
643
|
+
}
|
|
644
|
+
function createResponseStreamEventTranslator(responseId) {
|
|
645
|
+
let text = "";
|
|
646
|
+
let nextOutputIndex = 0;
|
|
647
|
+
let textOutputIndex = null;
|
|
648
|
+
const completedToolResultCallIds = /* @__PURE__ */ new Set();
|
|
649
|
+
const pendingToolResults = /* @__PURE__ */ new Map();
|
|
650
|
+
const toolCalls = /* @__PURE__ */ new Map();
|
|
651
|
+
const outputItems = /* @__PURE__ */ new Map();
|
|
652
|
+
const ensureTextOutputItem = () => {
|
|
653
|
+
if (textOutputIndex !== null) {
|
|
654
|
+
return { events: [], outputIndex: textOutputIndex };
|
|
655
|
+
}
|
|
656
|
+
textOutputIndex = nextOutputIndex++;
|
|
657
|
+
return {
|
|
658
|
+
outputIndex: textOutputIndex,
|
|
659
|
+
events: [
|
|
660
|
+
createResponseSseEvent({
|
|
661
|
+
type: "response.output_item.added",
|
|
662
|
+
output_index: textOutputIndex,
|
|
663
|
+
item: {
|
|
664
|
+
id: responseId,
|
|
665
|
+
type: "message",
|
|
666
|
+
role: "assistant",
|
|
667
|
+
status: "in_progress",
|
|
668
|
+
content: []
|
|
669
|
+
}
|
|
670
|
+
}),
|
|
671
|
+
createResponseSseEvent({
|
|
672
|
+
type: "response.content_part.added",
|
|
673
|
+
output_index: textOutputIndex,
|
|
674
|
+
content_index: 0,
|
|
675
|
+
item_id: responseId,
|
|
676
|
+
part: createOutputTextPart("")
|
|
677
|
+
})
|
|
678
|
+
]
|
|
679
|
+
};
|
|
680
|
+
};
|
|
681
|
+
const ensureToolCallItem = ({
|
|
682
|
+
toolCallId,
|
|
683
|
+
toolName
|
|
684
|
+
}) => {
|
|
685
|
+
const existing = toolCalls.get(toolCallId);
|
|
686
|
+
if (existing) {
|
|
687
|
+
if (!existing.completed && toolName && existing.name !== toolName) {
|
|
688
|
+
existing.name = toolName;
|
|
689
|
+
}
|
|
690
|
+
return { events: [], state: existing };
|
|
691
|
+
}
|
|
692
|
+
const state = {
|
|
693
|
+
argumentsText: "",
|
|
694
|
+
completed: false,
|
|
695
|
+
itemId: toolCallId,
|
|
696
|
+
name: toolName,
|
|
697
|
+
outputIndex: nextOutputIndex++,
|
|
698
|
+
zeroArgumentInputEnded: false
|
|
699
|
+
};
|
|
700
|
+
toolCalls.set(toolCallId, state);
|
|
701
|
+
return {
|
|
702
|
+
state,
|
|
703
|
+
events: [
|
|
704
|
+
createResponseSseEvent({
|
|
705
|
+
type: "response.output_item.added",
|
|
706
|
+
output_index: state.outputIndex,
|
|
707
|
+
item: {
|
|
708
|
+
id: state.itemId,
|
|
709
|
+
type: "function_call",
|
|
710
|
+
call_id: toolCallId,
|
|
711
|
+
name: toolName,
|
|
712
|
+
arguments: "",
|
|
713
|
+
status: "in_progress"
|
|
714
|
+
}
|
|
715
|
+
})
|
|
716
|
+
]
|
|
717
|
+
};
|
|
718
|
+
};
|
|
719
|
+
const completeToolCallItem = ({
|
|
720
|
+
events,
|
|
721
|
+
state,
|
|
722
|
+
toolCallId,
|
|
723
|
+
toolName,
|
|
724
|
+
args
|
|
725
|
+
}) => {
|
|
726
|
+
if (state.completed) {
|
|
727
|
+
return events;
|
|
728
|
+
}
|
|
729
|
+
const item = {
|
|
730
|
+
id: state.itemId,
|
|
731
|
+
type: "function_call",
|
|
732
|
+
call_id: toolCallId,
|
|
733
|
+
name: toolName,
|
|
734
|
+
arguments: args,
|
|
735
|
+
status: "completed"
|
|
736
|
+
};
|
|
737
|
+
state.argumentsText = args;
|
|
738
|
+
state.completed = true;
|
|
739
|
+
outputItems.set(state.outputIndex, item);
|
|
740
|
+
return [
|
|
741
|
+
...events,
|
|
742
|
+
createResponseSseEvent({
|
|
743
|
+
type: "response.function_call_arguments.done",
|
|
744
|
+
item_id: state.itemId,
|
|
745
|
+
output_index: state.outputIndex,
|
|
746
|
+
name: toolName,
|
|
747
|
+
arguments: args
|
|
748
|
+
}),
|
|
749
|
+
createResponseSseEvent({
|
|
750
|
+
type: "response.output_item.done",
|
|
751
|
+
output_index: state.outputIndex,
|
|
752
|
+
item
|
|
753
|
+
})
|
|
754
|
+
];
|
|
755
|
+
};
|
|
756
|
+
const completeToolResultItem = ({
|
|
757
|
+
events,
|
|
758
|
+
toolResult
|
|
759
|
+
}) => {
|
|
760
|
+
if (completedToolResultCallIds.has(toolResult.toolCallId)) {
|
|
761
|
+
return events;
|
|
762
|
+
}
|
|
763
|
+
completedToolResultCallIds.add(toolResult.toolCallId);
|
|
764
|
+
pendingToolResults.delete(toolResult.toolCallId);
|
|
765
|
+
const outputIndex = nextOutputIndex++;
|
|
766
|
+
const item = {
|
|
767
|
+
id: getFunctionCallOutputItemId(toolResult.toolCallId),
|
|
768
|
+
type: "function_call_output",
|
|
769
|
+
call_id: toolResult.toolCallId,
|
|
770
|
+
output: stringifyResponsePayload(toolResult.result)
|
|
771
|
+
};
|
|
772
|
+
outputItems.set(outputIndex, item);
|
|
773
|
+
return [
|
|
774
|
+
...events,
|
|
775
|
+
createResponseSseEvent({
|
|
776
|
+
type: "response.output_item.added",
|
|
777
|
+
output_index: outputIndex,
|
|
778
|
+
item
|
|
779
|
+
}),
|
|
780
|
+
createResponseSseEvent({
|
|
781
|
+
type: "response.output_item.done",
|
|
782
|
+
output_index: outputIndex,
|
|
783
|
+
item
|
|
784
|
+
})
|
|
785
|
+
];
|
|
786
|
+
};
|
|
787
|
+
return {
|
|
788
|
+
get text() {
|
|
789
|
+
return text;
|
|
790
|
+
},
|
|
791
|
+
getOutputItems({ text: text2, status }) {
|
|
792
|
+
const items = new Map(outputItems);
|
|
793
|
+
if (text2) {
|
|
794
|
+
const messageOutputIndex = textOutputIndex ?? nextOutputIndex;
|
|
795
|
+
items.set(messageOutputIndex, createOutputMessage({ messageId: responseId, status, text: text2 }));
|
|
796
|
+
}
|
|
797
|
+
return [...items.entries()].sort(([left], [right]) => left - right).map(([, item]) => item);
|
|
798
|
+
},
|
|
799
|
+
consume(value) {
|
|
800
|
+
const textDelta = extractTextDelta(value);
|
|
801
|
+
if (textDelta) {
|
|
802
|
+
const { events, outputIndex } = ensureTextOutputItem();
|
|
803
|
+
text += textDelta;
|
|
804
|
+
return [
|
|
805
|
+
...events,
|
|
806
|
+
createResponseSseEvent({
|
|
807
|
+
type: "response.output_text.delta",
|
|
808
|
+
output_index: outputIndex,
|
|
809
|
+
content_index: 0,
|
|
810
|
+
item_id: responseId,
|
|
811
|
+
delta: textDelta
|
|
812
|
+
})
|
|
813
|
+
];
|
|
814
|
+
}
|
|
815
|
+
const toolCallStart = getToolCallStart(value);
|
|
816
|
+
if (toolCallStart) {
|
|
817
|
+
return ensureToolCallItem(toolCallStart).events;
|
|
818
|
+
}
|
|
819
|
+
const toolCallDelta = getToolCallDelta(value);
|
|
820
|
+
if (toolCallDelta) {
|
|
821
|
+
const existing = toolCalls.get(toolCallDelta.toolCallId);
|
|
822
|
+
if (!existing && !toolCallDelta.toolName) {
|
|
823
|
+
return [];
|
|
824
|
+
}
|
|
825
|
+
if (existing?.completed) {
|
|
826
|
+
return [];
|
|
827
|
+
}
|
|
828
|
+
const ensured = ensureToolCallItem({
|
|
829
|
+
toolCallId: toolCallDelta.toolCallId,
|
|
830
|
+
toolName: toolCallDelta.toolName ?? existing.name
|
|
831
|
+
});
|
|
832
|
+
ensured.state.argumentsText += toolCallDelta.delta;
|
|
833
|
+
ensured.state.zeroArgumentInputEnded = false;
|
|
834
|
+
return [
|
|
835
|
+
...ensured.events,
|
|
836
|
+
createResponseSseEvent({
|
|
837
|
+
type: "response.function_call_arguments.delta",
|
|
838
|
+
item_id: ensured.state.itemId,
|
|
839
|
+
output_index: ensured.state.outputIndex,
|
|
840
|
+
delta: toolCallDelta.delta
|
|
841
|
+
})
|
|
842
|
+
];
|
|
843
|
+
}
|
|
844
|
+
const toolCallEnd = getToolCallEnd(value);
|
|
845
|
+
if (toolCallEnd) {
|
|
846
|
+
const state = toolCalls.get(toolCallEnd.toolCallId);
|
|
847
|
+
if (!state || state.completed) {
|
|
848
|
+
return [];
|
|
849
|
+
}
|
|
850
|
+
state.zeroArgumentInputEnded = !state.argumentsText;
|
|
851
|
+
return [];
|
|
852
|
+
}
|
|
853
|
+
const toolCall = getToolCall(value);
|
|
854
|
+
if (toolCall) {
|
|
855
|
+
const { events, state } = ensureToolCallItem(toolCall);
|
|
856
|
+
const canonicalArgs = stringifyFunctionCallArguments(toolCall.args, state.argumentsText);
|
|
857
|
+
if (state.completed) {
|
|
858
|
+
const nextEvents2 = completeToolCallItem({
|
|
859
|
+
events,
|
|
860
|
+
state,
|
|
861
|
+
toolCallId: toolCall.toolCallId,
|
|
862
|
+
toolName: toolCall.toolName,
|
|
863
|
+
args: canonicalArgs
|
|
864
|
+
});
|
|
865
|
+
const pendingToolResult2 = pendingToolResults.get(toolCall.toolCallId);
|
|
866
|
+
return pendingToolResult2 ? completeToolResultItem({ events: nextEvents2, toolResult: pendingToolResult2 }) : nextEvents2;
|
|
867
|
+
}
|
|
868
|
+
const remainingArgsDelta = getRemainingArgumentsDelta(state.argumentsText, canonicalArgs);
|
|
869
|
+
const args = remainingArgsDelta === null ? (
|
|
870
|
+
// If both strings are valid but disagree, keep the bytes already emitted
|
|
871
|
+
// as deltas so arguments.done and response.output stay consistent.
|
|
872
|
+
isCompleteJsonString(state.argumentsText) ? state.argumentsText : canonicalArgs
|
|
873
|
+
) : state.argumentsText + remainingArgsDelta;
|
|
874
|
+
const nextEvents = remainingArgsDelta ? [
|
|
875
|
+
...events,
|
|
876
|
+
createResponseSseEvent({
|
|
877
|
+
type: "response.function_call_arguments.delta",
|
|
878
|
+
item_id: state.itemId,
|
|
879
|
+
output_index: state.outputIndex,
|
|
880
|
+
delta: remainingArgsDelta
|
|
881
|
+
})
|
|
882
|
+
] : events;
|
|
883
|
+
const completedEvents = completeToolCallItem({
|
|
884
|
+
events: nextEvents,
|
|
885
|
+
state,
|
|
886
|
+
toolCallId: toolCall.toolCallId,
|
|
887
|
+
toolName: toolCall.toolName,
|
|
888
|
+
args
|
|
889
|
+
});
|
|
890
|
+
const pendingToolResult = pendingToolResults.get(toolCall.toolCallId);
|
|
891
|
+
return pendingToolResult ? completeToolResultItem({ events: completedEvents, toolResult: pendingToolResult }) : completedEvents;
|
|
892
|
+
}
|
|
893
|
+
const toolResult = getToolResult(value);
|
|
894
|
+
if (toolResult) {
|
|
895
|
+
const existingToolCallState = toolCalls.get(toolResult.toolCallId);
|
|
896
|
+
if (!existingToolCallState && !toolResult.toolName) {
|
|
897
|
+
return [];
|
|
898
|
+
}
|
|
899
|
+
const { events: toolCallEvents, state: toolCallState } = ensureToolCallItem({
|
|
900
|
+
toolCallId: toolResult.toolCallId,
|
|
901
|
+
toolName: toolResult.toolName ?? existingToolCallState.name
|
|
902
|
+
});
|
|
903
|
+
if (completedToolResultCallIds.has(toolResult.toolCallId)) {
|
|
904
|
+
return [];
|
|
905
|
+
}
|
|
906
|
+
const events = [...toolCallEvents];
|
|
907
|
+
if (!toolCallState.completed) {
|
|
908
|
+
const args = stringifyFunctionCallArguments(toolResult.args, toolCallState.argumentsText || "{}");
|
|
909
|
+
const hasZeroArgumentHint = toolCallState.zeroArgumentInputEnded && !toolCallState.argumentsText;
|
|
910
|
+
if (toolResult.args === void 0 && !hasZeroArgumentHint && (!toolCallState.argumentsText || !isCompleteJsonString(toolCallState.argumentsText))) {
|
|
911
|
+
pendingToolResults.set(toolResult.toolCallId, toolResult);
|
|
912
|
+
return events;
|
|
913
|
+
}
|
|
914
|
+
events.push(
|
|
915
|
+
...completeToolCallItem({
|
|
916
|
+
events: [],
|
|
917
|
+
state: toolCallState,
|
|
918
|
+
toolCallId: toolResult.toolCallId,
|
|
919
|
+
toolName: toolResult.toolName ?? toolCallState.name,
|
|
920
|
+
args
|
|
921
|
+
})
|
|
922
|
+
);
|
|
923
|
+
}
|
|
924
|
+
return completeToolResultItem({ events, toolResult });
|
|
925
|
+
}
|
|
926
|
+
return [];
|
|
927
|
+
},
|
|
928
|
+
flushPendingToolResults() {
|
|
929
|
+
const events = [];
|
|
930
|
+
for (const toolResult of pendingToolResults.values()) {
|
|
931
|
+
const toolCallState = toolCalls.get(toolResult.toolCallId);
|
|
932
|
+
if (!toolCallState) {
|
|
933
|
+
continue;
|
|
934
|
+
}
|
|
935
|
+
if (!toolCallState.completed) {
|
|
936
|
+
const safeFallbackArgs = isCompleteJsonString(toolCallState.argumentsText) ? toolCallState.argumentsText : "{}";
|
|
937
|
+
events.push(
|
|
938
|
+
...completeToolCallItem({
|
|
939
|
+
events: [],
|
|
940
|
+
state: toolCallState,
|
|
941
|
+
toolCallId: toolResult.toolCallId,
|
|
942
|
+
toolName: toolResult.toolName ?? toolCallState.name,
|
|
943
|
+
args: stringifyFunctionCallArguments(toolResult.args, safeFallbackArgs)
|
|
944
|
+
})
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
events.push(...completeToolResultItem({ events: [], toolResult }));
|
|
948
|
+
}
|
|
949
|
+
return events;
|
|
950
|
+
},
|
|
951
|
+
completeText(text2, completedItem) {
|
|
952
|
+
const { events, outputIndex } = ensureTextOutputItem();
|
|
953
|
+
const completedTextItem = {
|
|
954
|
+
...completedItem,
|
|
955
|
+
content: [createOutputTextPart(text2)]
|
|
956
|
+
};
|
|
957
|
+
return [
|
|
958
|
+
...events,
|
|
959
|
+
createResponseSseEvent({
|
|
960
|
+
type: "response.output_text.done",
|
|
961
|
+
output_index: outputIndex,
|
|
962
|
+
content_index: 0,
|
|
963
|
+
item_id: responseId,
|
|
964
|
+
text: text2
|
|
965
|
+
}),
|
|
966
|
+
createResponseSseEvent({
|
|
967
|
+
type: "response.content_part.done",
|
|
968
|
+
output_index: outputIndex,
|
|
969
|
+
content_index: 0,
|
|
970
|
+
item_id: responseId,
|
|
971
|
+
part: createOutputTextPart(text2)
|
|
972
|
+
}),
|
|
973
|
+
createResponseSseEvent({
|
|
974
|
+
type: "response.output_item.done",
|
|
975
|
+
output_index: outputIndex,
|
|
976
|
+
item: completedTextItem
|
|
977
|
+
})
|
|
978
|
+
];
|
|
979
|
+
}
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
exports.buildCompletedResponse = buildCompletedResponse;
|
|
984
|
+
exports.buildInProgressResponse = buildInProgressResponse;
|
|
985
|
+
exports.createMessageId = createMessageId;
|
|
986
|
+
exports.createOutputTextPart = createOutputTextPart;
|
|
987
|
+
exports.createResponseStreamEventTranslator = createResponseStreamEventTranslator;
|
|
988
|
+
exports.extractTextDelta = extractTextDelta;
|
|
989
|
+
exports.formatSseEvent = formatSseEvent;
|
|
990
|
+
exports.mapMastraMessagesToConversationItems = mapMastraMessagesToConversationItems;
|
|
991
|
+
exports.mapMastraMessagesToResponseOutputItems = mapMastraMessagesToResponseOutputItems;
|
|
992
|
+
exports.mapMastraToolsToResponseTools = mapMastraToolsToResponseTools;
|
|
993
|
+
exports.mapResponseInputToExecutionMessages = mapResponseInputToExecutionMessages;
|
|
994
|
+
exports.mapResponseTurnRecordToResponse = mapResponseTurnRecordToResponse;
|
|
995
|
+
exports.toResponseStatus = toResponseStatus;
|
|
996
|
+
exports.toResponseUsage = toResponseUsage;
|
|
997
|
+
//# sourceMappingURL=chunk-F3HP5HM6.cjs.map
|
|
998
|
+
//# sourceMappingURL=chunk-F3HP5HM6.cjs.map
|