@anvia/core 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +226 -0
- package/dist/agent/agent-stream.js +7 -0
- package/dist/agent/agent-stream.js.map +1 -0
- package/dist/agent/agent-tool.js +24 -0
- package/dist/agent/agent-tool.js.map +1 -0
- package/dist/agent/agent.js +89 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/errors.js +17 -0
- package/dist/agent/errors.js.map +1 -0
- package/dist/agent/ids.js +7 -0
- package/dist/agent/ids.js.map +1 -0
- package/dist/agent/index.d.ts +127 -9
- package/dist/agent/index.js +103 -21
- package/dist/agent/interactions/index.js +2 -2
- package/dist/agent/interactions.js +22 -0
- package/dist/agent/interactions.js.map +1 -0
- package/dist/agent/lifecycle.js +9 -0
- package/dist/agent/lifecycle.js.map +1 -0
- package/dist/agent/output-schema.js +10 -0
- package/dist/agent/output-schema.js.map +1 -0
- package/dist/agent/resolve-options.js +46 -0
- package/dist/agent/resolve-options.js.map +1 -0
- package/dist/agent/resolved-agent.js +92 -0
- package/dist/agent/resolved-agent.js.map +1 -0
- package/dist/agent/run-types.js +1 -0
- package/dist/agent/run-types.js.map +1 -0
- package/dist/agent/snapshot.js +17 -0
- package/dist/agent/snapshot.js.map +1 -0
- package/dist/agent/team/agent-team.js +98 -0
- package/dist/agent/team/agent-team.js.map +1 -0
- package/dist/agent/team/errors.js +9 -0
- package/dist/agent/team/errors.js.map +1 -0
- package/dist/agent/team/index.js +104 -0
- package/dist/agent/team/index.js.map +1 -0
- package/dist/agent/team/types.js +1 -0
- package/dist/agent/team/types.js.map +1 -0
- package/dist/agent/tool-catalog.js +37 -0
- package/dist/agent/tool-catalog.js.map +1 -0
- package/dist/agent/tool-state.js +11 -0
- package/dist/agent/tool-state.js.map +1 -0
- package/dist/agent/types.js +1 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/agent/vector-context.js +10 -0
- package/dist/agent/vector-context.js.map +1 -0
- package/dist/{agent-DTmzs1Qr.d.ts → agent-C9VhENdj.d.ts} +2 -3
- package/dist/{chunk-2QZJTG2E.js → chunk-23GEYG2X.js} +11 -71
- package/dist/chunk-23GEYG2X.js.map +1 -0
- package/dist/{chunk-I3Q7XSBB.js → chunk-23LRXKQX.js} +6 -4
- package/dist/{chunk-I3Q7XSBB.js.map → chunk-23LRXKQX.js.map} +1 -1
- package/dist/{chunk-YK4WAAS4.js → chunk-2NLINXRF.js} +1 -1
- package/dist/{chunk-SPD4XVR7.js → chunk-2XSMGVBG.js} +1 -1
- package/dist/chunk-3J2CSVPR.js +1 -0
- package/dist/chunk-3J2CSVPR.js.map +1 -0
- package/dist/chunk-3P3YVJ7V.js +1 -0
- package/dist/chunk-3P3YVJ7V.js.map +1 -0
- package/dist/chunk-3TAQXJBC.js +107 -0
- package/dist/chunk-3TAQXJBC.js.map +1 -0
- package/dist/chunk-47NTHIVB.js +76 -0
- package/dist/chunk-47NTHIVB.js.map +1 -0
- package/dist/chunk-4AW2633B.js +9 -0
- package/dist/chunk-4AW2633B.js.map +1 -0
- package/dist/{chunk-3XQGVDU5.js → chunk-4C7AXYOM.js} +1 -1
- package/dist/{chunk-IZNOP6JG.js → chunk-4FIVU53H.js} +1 -1
- package/dist/chunk-4ITAV7YA.js +1 -0
- package/dist/chunk-4ITAV7YA.js.map +1 -0
- package/dist/{chunk-7JLAIN6E.js → chunk-4ONUNWGC.js} +2 -2
- package/dist/chunk-4UUIGAIX.js +1 -0
- package/dist/chunk-4UUIGAIX.js.map +1 -0
- package/dist/chunk-53TPAXYR.js +1 -0
- package/dist/chunk-53TPAXYR.js.map +1 -0
- package/dist/chunk-5AETKC4L.js +107 -0
- package/dist/chunk-5AETKC4L.js.map +1 -0
- package/dist/chunk-5I2NVRHC.js +146 -0
- package/dist/chunk-5I2NVRHC.js.map +1 -0
- package/dist/chunk-5IURMWFN.js +53 -0
- package/dist/chunk-5IURMWFN.js.map +1 -0
- package/dist/chunk-5M6GTA3T.js +1 -0
- package/dist/chunk-5M6GTA3T.js.map +1 -0
- package/dist/chunk-5N5W7CX7.js +18 -0
- package/dist/chunk-5N5W7CX7.js.map +1 -0
- package/dist/chunk-5P2YOQSA.js +355 -0
- package/dist/chunk-5P2YOQSA.js.map +1 -0
- package/dist/chunk-5S7T2URX.js +1 -0
- package/dist/chunk-5S7T2URX.js.map +1 -0
- package/dist/chunk-5V533R7F.js +19 -0
- package/dist/chunk-5V533R7F.js.map +1 -0
- package/dist/chunk-5WLIHNNJ.js +56 -0
- package/dist/chunk-5WLIHNNJ.js.map +1 -0
- package/dist/chunk-6BTJC3ES.js +37 -0
- package/dist/chunk-6BTJC3ES.js.map +1 -0
- package/dist/chunk-6N4ENZO4.js +24 -0
- package/dist/chunk-6N4ENZO4.js.map +1 -0
- package/dist/{chunk-4UQALF5Y.js → chunk-6RQYWZI3.js} +2 -36
- package/dist/chunk-6RQYWZI3.js.map +1 -0
- package/dist/chunk-6TAWRKFK.js +86 -0
- package/dist/chunk-6TAWRKFK.js.map +1 -0
- package/dist/chunk-7F53DOML.js +53 -0
- package/dist/chunk-7F53DOML.js.map +1 -0
- package/dist/chunk-7KAGWJ5M.js +112 -0
- package/dist/chunk-7KAGWJ5M.js.map +1 -0
- package/dist/chunk-7LBPRXZP.js +1 -0
- package/dist/chunk-7LBPRXZP.js.map +1 -0
- package/dist/chunk-A7BXVZXZ.js +25 -0
- package/dist/chunk-A7BXVZXZ.js.map +1 -0
- package/dist/chunk-B47EXUHL.js +67 -0
- package/dist/chunk-B47EXUHL.js.map +1 -0
- package/dist/chunk-B5JQDR33.js +14 -0
- package/dist/chunk-B5JQDR33.js.map +1 -0
- package/dist/chunk-B5YTCKUJ.js +158 -0
- package/dist/chunk-B5YTCKUJ.js.map +1 -0
- package/dist/chunk-BDDC72GF.js +189 -0
- package/dist/chunk-BDDC72GF.js.map +1 -0
- package/dist/chunk-BDKFFFVX.js +342 -0
- package/dist/chunk-BDKFFFVX.js.map +1 -0
- package/dist/{chunk-QGX73TSQ.js → chunk-BONQTXRQ.js} +3 -12
- package/dist/chunk-BONQTXRQ.js.map +1 -0
- package/dist/chunk-BUPC72Y2.js +1007 -0
- package/dist/chunk-BUPC72Y2.js.map +1 -0
- package/dist/chunk-CKKNO4XB.js +70 -0
- package/dist/chunk-CKKNO4XB.js.map +1 -0
- package/dist/chunk-CX7ZVTO5.js +22 -0
- package/dist/chunk-CX7ZVTO5.js.map +1 -0
- package/dist/chunk-DU4WA6LQ.js +1 -0
- package/dist/chunk-DU4WA6LQ.js.map +1 -0
- package/dist/chunk-EJR6VVB3.js +63 -0
- package/dist/chunk-EJR6VVB3.js.map +1 -0
- package/dist/chunk-EKZRAWBP.js +110 -0
- package/dist/chunk-EKZRAWBP.js.map +1 -0
- package/dist/chunk-ENZ2XX27.js +26 -0
- package/dist/chunk-ENZ2XX27.js.map +1 -0
- package/dist/chunk-EOAJBBII.js +1 -0
- package/dist/chunk-EOAJBBII.js.map +1 -0
- package/dist/chunk-ERN7P6Q4.js +1 -0
- package/dist/chunk-ERN7P6Q4.js.map +1 -0
- package/dist/chunk-ESOFEAYK.js +57 -0
- package/dist/chunk-ESOFEAYK.js.map +1 -0
- package/dist/chunk-ETYB5JO6.js +175 -0
- package/dist/chunk-ETYB5JO6.js.map +1 -0
- package/dist/chunk-EZR5AV3J.js +74 -0
- package/dist/chunk-EZR5AV3J.js.map +1 -0
- package/dist/chunk-F2OKLHGB.js +9 -0
- package/dist/chunk-F2OKLHGB.js.map +1 -0
- package/dist/chunk-F3E2RLC7.js +342 -0
- package/dist/chunk-F3E2RLC7.js.map +1 -0
- package/dist/chunk-FAPIZJS2.js +54 -0
- package/dist/chunk-FAPIZJS2.js.map +1 -0
- package/dist/chunk-GDJNOZ47.js +1 -0
- package/dist/chunk-GDJNOZ47.js.map +1 -0
- package/dist/chunk-GDY2Z2SZ.js +83 -0
- package/dist/chunk-GDY2Z2SZ.js.map +1 -0
- package/dist/chunk-GLMYZ6OA.js +20 -0
- package/dist/chunk-GLMYZ6OA.js.map +1 -0
- package/dist/{chunk-XEVOC433.js → chunk-GPVXCY5I.js} +2 -73
- package/dist/chunk-GPVXCY5I.js.map +1 -0
- package/dist/{chunk-KSKST3KP.js → chunk-H3H74RWJ.js} +1 -1
- package/dist/chunk-HAAGSIZH.js +89 -0
- package/dist/chunk-HAAGSIZH.js.map +1 -0
- package/dist/{chunk-K5L7R7XM.js → chunk-HHMLE3TZ.js} +6 -54
- package/dist/chunk-HHMLE3TZ.js.map +1 -0
- package/dist/{chunk-JLJMVRRE.js → chunk-HP34GRQX.js} +10 -83
- package/dist/chunk-HP34GRQX.js.map +1 -0
- package/dist/chunk-HTI343NP.js +1 -0
- package/dist/chunk-HTI343NP.js.map +1 -0
- package/dist/{chunk-T2C3CGDQ.js → chunk-HTI7DZJM.js} +6 -4
- package/dist/{chunk-T2C3CGDQ.js.map → chunk-HTI7DZJM.js.map} +1 -1
- package/dist/chunk-IDNL6IH4.js +294 -0
- package/dist/chunk-IDNL6IH4.js.map +1 -0
- package/dist/chunk-IV6YQTY2.js +47 -0
- package/dist/chunk-IV6YQTY2.js.map +1 -0
- package/dist/chunk-J4SINPUA.js +939 -0
- package/dist/chunk-J4SINPUA.js.map +1 -0
- package/dist/chunk-J6S6MT7O.js +32 -0
- package/dist/chunk-J6S6MT7O.js.map +1 -0
- package/dist/chunk-JB3RFK6K.js +168 -0
- package/dist/chunk-JB3RFK6K.js.map +1 -0
- package/dist/chunk-JBQNCUXA.js +34 -0
- package/dist/chunk-JBQNCUXA.js.map +1 -0
- package/dist/chunk-JMJFK3A4.js +1 -0
- package/dist/chunk-JMJFK3A4.js.map +1 -0
- package/dist/chunk-JMMZICU7.js +74 -0
- package/dist/chunk-JMMZICU7.js.map +1 -0
- package/dist/chunk-JOQ2T3QP.js +663 -0
- package/dist/chunk-JOQ2T3QP.js.map +1 -0
- package/dist/chunk-K4IBS7VB.js +55 -0
- package/dist/chunk-K4IBS7VB.js.map +1 -0
- package/dist/chunk-KBBQSP4M.js +16 -0
- package/dist/chunk-KBBQSP4M.js.map +1 -0
- package/dist/chunk-KFAVEL5F.js +68 -0
- package/dist/chunk-KFAVEL5F.js.map +1 -0
- package/dist/chunk-KITX3HDN.js +17 -0
- package/dist/chunk-KITX3HDN.js.map +1 -0
- package/dist/chunk-KO5NMTAM.js +1 -0
- package/dist/chunk-KO5NMTAM.js.map +1 -0
- package/dist/chunk-KY4VXIN2.js +118 -0
- package/dist/chunk-KY4VXIN2.js.map +1 -0
- package/dist/chunk-KZGSXJKU.js +29 -0
- package/dist/chunk-KZGSXJKU.js.map +1 -0
- package/dist/chunk-LAIATEUB.js +24 -0
- package/dist/chunk-LAIATEUB.js.map +1 -0
- package/dist/{chunk-OJBFDBLG.js → chunk-LBYJPMHC.js} +2 -2
- package/dist/chunk-LKIABZNR.js +49 -0
- package/dist/chunk-LKIABZNR.js.map +1 -0
- package/dist/chunk-LQJ4KHMY.js +23 -0
- package/dist/chunk-LQJ4KHMY.js.map +1 -0
- package/dist/chunk-MEN4AFDZ.js +1 -0
- package/dist/chunk-MEN4AFDZ.js.map +1 -0
- package/dist/chunk-MHOJJYDK.js +93 -0
- package/dist/chunk-MHOJJYDK.js.map +1 -0
- package/dist/chunk-MJCMKZFP.js +30 -0
- package/dist/chunk-MJCMKZFP.js.map +1 -0
- package/dist/chunk-MT3BLVYN.js +31 -0
- package/dist/chunk-MT3BLVYN.js.map +1 -0
- package/dist/chunk-NF6WBPFG.js +37 -0
- package/dist/chunk-NF6WBPFG.js.map +1 -0
- package/dist/chunk-NNEKBZSM.js +66 -0
- package/dist/chunk-NNEKBZSM.js.map +1 -0
- package/dist/chunk-NPJ2T3L5.js +19 -0
- package/dist/chunk-NPJ2T3L5.js.map +1 -0
- package/dist/chunk-NVALGVQG.js +150 -0
- package/dist/chunk-NVALGVQG.js.map +1 -0
- package/dist/chunk-OJF67RNM.js +1 -0
- package/dist/chunk-OJF67RNM.js.map +1 -0
- package/dist/chunk-PHLGGRHC.js +89 -0
- package/dist/chunk-PHLGGRHC.js.map +1 -0
- package/dist/chunk-PIMD4DYG.js +104 -0
- package/dist/chunk-PIMD4DYG.js.map +1 -0
- package/dist/chunk-PJNE75WC.js +1 -0
- package/dist/chunk-PJNE75WC.js.map +1 -0
- package/dist/{chunk-J6LVLV6P.js → chunk-PLDJCCVL.js} +1 -1
- package/dist/{chunk-3RWESPUG.js → chunk-POXHJF3H.js} +6 -51
- package/dist/chunk-POXHJF3H.js.map +1 -0
- package/dist/chunk-PPJ7SYQL.js +81 -0
- package/dist/chunk-PPJ7SYQL.js.map +1 -0
- package/dist/chunk-PT777EQ3.js +48 -0
- package/dist/chunk-PT777EQ3.js.map +1 -0
- package/dist/chunk-PYLPLFJZ.js +318 -0
- package/dist/chunk-PYLPLFJZ.js.map +1 -0
- package/dist/chunk-QEPBHHAP.js +41 -0
- package/dist/chunk-QEPBHHAP.js.map +1 -0
- package/dist/chunk-QHGYCYV6.js +91 -0
- package/dist/chunk-QHGYCYV6.js.map +1 -0
- package/dist/chunk-R6722CIU.js +28 -0
- package/dist/chunk-R6722CIU.js.map +1 -0
- package/dist/chunk-RA4YVN43.js +1 -0
- package/dist/chunk-RA4YVN43.js.map +1 -0
- package/dist/chunk-RT5LUEO3.js +2339 -0
- package/dist/chunk-RT5LUEO3.js.map +1 -0
- package/dist/chunk-RXKUIJ77.js +236 -0
- package/dist/chunk-RXKUIJ77.js.map +1 -0
- package/dist/chunk-SC4SUIEY.js +1 -0
- package/dist/chunk-SC4SUIEY.js.map +1 -0
- package/dist/chunk-SQAAVYJG.js +12 -0
- package/dist/chunk-SQAAVYJG.js.map +1 -0
- package/dist/chunk-SXE4J43E.js +59 -0
- package/dist/chunk-SXE4J43E.js.map +1 -0
- package/dist/{chunk-EFLT7XZD.js → chunk-SYULMZGL.js} +6 -4
- package/dist/{chunk-EFLT7XZD.js.map → chunk-SYULMZGL.js.map} +1 -1
- package/dist/chunk-T4KS577P.js +58 -0
- package/dist/chunk-T4KS577P.js.map +1 -0
- package/dist/chunk-TFIOU6UR.js +78 -0
- package/dist/chunk-TFIOU6UR.js.map +1 -0
- package/dist/chunk-TIZGADU4.js +375 -0
- package/dist/chunk-TIZGADU4.js.map +1 -0
- package/dist/chunk-TP3MCUXS.js +1 -0
- package/dist/chunk-TP3MCUXS.js.map +1 -0
- package/dist/chunk-TSPQD5HW.js +613 -0
- package/dist/chunk-TSPQD5HW.js.map +1 -0
- package/dist/{chunk-JTJU56ZV.js → chunk-UOGM62JL.js} +11 -7
- package/dist/{chunk-JTJU56ZV.js.map → chunk-UOGM62JL.js.map} +1 -1
- package/dist/chunk-USRKPEQN.js +55 -0
- package/dist/chunk-USRKPEQN.js.map +1 -0
- package/dist/chunk-UTAB3XQI.js +667 -0
- package/dist/chunk-UTAB3XQI.js.map +1 -0
- package/dist/chunk-V3FFZWF3.js +182 -0
- package/dist/chunk-V3FFZWF3.js.map +1 -0
- package/dist/chunk-V4OZ7ISA.js +9 -0
- package/dist/chunk-V4OZ7ISA.js.map +1 -0
- package/dist/chunk-VZ5ZZBNX.js +139 -0
- package/dist/chunk-VZ5ZZBNX.js.map +1 -0
- package/dist/{chunk-AHLKV6KP.js → chunk-WN6AVBO4.js} +1 -1
- package/dist/chunk-WXR5CWSC.js +1 -0
- package/dist/chunk-WXR5CWSC.js.map +1 -0
- package/dist/chunk-X6WS3XWL.js +36 -0
- package/dist/chunk-X6WS3XWL.js.map +1 -0
- package/dist/{chunk-Q5BCNYED.js → chunk-XJRNBTIV.js} +7 -4
- package/dist/chunk-XQV3XNVT.js +225 -0
- package/dist/chunk-XQV3XNVT.js.map +1 -0
- package/dist/chunk-XV3DH5GC.js +58 -0
- package/dist/chunk-XV3DH5GC.js.map +1 -0
- package/dist/chunk-YWRXOPHC.js +43 -0
- package/dist/chunk-YWRXOPHC.js.map +1 -0
- package/dist/chunk-YZVFIW5D.js +27 -0
- package/dist/chunk-YZVFIW5D.js.map +1 -0
- package/dist/chunk-ZHC5CD6J.js +33 -0
- package/dist/chunk-ZHC5CD6J.js.map +1 -0
- package/dist/chunk-ZPJFXRQZ.js +23 -0
- package/dist/chunk-ZPJFXRQZ.js.map +1 -0
- package/dist/chunk-ZPXOBQDS.js +57 -0
- package/dist/chunk-ZPXOBQDS.js.map +1 -0
- package/dist/chunk-ZUFS6R7L.js +155 -0
- package/dist/chunk-ZUFS6R7L.js.map +1 -0
- package/dist/chunk-ZXLCTQUX.js +62 -0
- package/dist/chunk-ZXLCTQUX.js.map +1 -0
- package/dist/chunk-ZYXMWEL4.js +59 -0
- package/dist/chunk-ZYXMWEL4.js.map +1 -0
- package/dist/completion/controls.js +11 -0
- package/dist/completion/controls.js.map +1 -0
- package/dist/completion/documents.js +9 -0
- package/dist/completion/documents.js.map +1 -0
- package/dist/completion/generate-completion.js +23 -0
- package/dist/completion/generate-completion.js.map +1 -0
- package/dist/completion/index.js +23 -12
- package/dist/completion/json.js +7 -0
- package/dist/completion/json.js.map +1 -0
- package/dist/completion/message-schema.js +18 -0
- package/dist/completion/message-schema.js.map +1 -0
- package/dist/completion/provider-output-error.js +12 -0
- package/dist/completion/provider-output-error.js.map +1 -0
- package/dist/completion/stream-accumulator.js +10 -0
- package/dist/completion/stream-accumulator.js.map +1 -0
- package/dist/completion/types.js +28 -0
- package/dist/completion/types.js.map +1 -0
- package/dist/documents/chunk-text.js +7 -0
- package/dist/documents/chunk-text.js.map +1 -0
- package/dist/documents/index.js +5 -2
- package/dist/documents/text-document.js +8 -0
- package/dist/documents/text-document.js.map +1 -0
- package/dist/embeddings/distance.js +17 -0
- package/dist/embeddings/distance.js.map +1 -0
- package/dist/embeddings/embed.js +18 -0
- package/dist/embeddings/embed.js.map +1 -0
- package/dist/embeddings/index.js +11 -6
- package/dist/embeddings/types.js +2 -0
- package/dist/embeddings/types.js.map +1 -0
- package/dist/evals/advanced-metrics.js +46 -0
- package/dist/evals/advanced-metrics.js.map +1 -0
- package/dist/evals/agent-target.js +10 -0
- package/dist/evals/agent-target.js.map +1 -0
- package/dist/evals/cli.js +40 -0
- package/dist/evals/cli.js.map +1 -0
- package/dist/evals/execution.js +15 -0
- package/dist/evals/execution.js.map +1 -0
- package/dist/evals/format.js +13 -0
- package/dist/evals/format.js.map +1 -0
- package/dist/evals/index.d.ts +4 -4
- package/dist/evals/index.js +87 -2660
- package/dist/evals/index.js.map +1 -1
- package/dist/evals/judge.js +27 -0
- package/dist/evals/judge.js.map +1 -0
- package/dist/evals/metric.js +7 -0
- package/dist/evals/metric.js.map +1 -0
- package/dist/evals/metrics.js +53 -0
- package/dist/evals/metrics.js.map +1 -0
- package/dist/evals/outcome.js +7 -0
- package/dist/evals/outcome.js.map +1 -0
- package/dist/evals/reporting.js +11 -0
- package/dist/evals/reporting.js.map +1 -0
- package/dist/evals/runner.js +29 -0
- package/dist/evals/runner.js.map +1 -0
- package/dist/evals/selectors.js +18 -0
- package/dist/evals/selectors.js.map +1 -0
- package/dist/evals/suite.js +11 -0
- package/dist/evals/suite.js.map +1 -0
- package/dist/evals/types.js +1 -0
- package/dist/evals/types.js.map +1 -0
- package/dist/extractor/extractor.js +23 -0
- package/dist/extractor/extractor.js.map +1 -0
- package/dist/extractor/index.js +16 -7
- package/dist/guardrails/actions.js +13 -0
- package/dist/guardrails/actions.js.map +1 -0
- package/dist/guardrails/index.d.ts +3 -4
- package/dist/guardrails/index.js +15 -7
- package/dist/guardrails/message.js +9 -0
- package/dist/guardrails/message.js.map +1 -0
- package/dist/guardrails/policy.js +17 -0
- package/dist/guardrails/policy.js.map +1 -0
- package/dist/guardrails/runtime.js +11 -0
- package/dist/guardrails/runtime.js.map +1 -0
- package/dist/guardrails/text.js +9 -0
- package/dist/guardrails/text.js.map +1 -0
- package/dist/guardrails/types.js +1 -0
- package/dist/guardrails/types.js.map +1 -0
- package/dist/hooks/control.js +17 -0
- package/dist/hooks/control.js.map +1 -0
- package/dist/hooks/index.js +19 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/types.js +2 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/image-generation/generate-image.js +11 -0
- package/dist/image-generation/generate-image.js.map +1 -0
- package/dist/image-generation/index.js +7 -4
- package/dist/image-generation/types.js +2 -0
- package/dist/image-generation/types.js.map +1 -0
- package/dist/index.d.ts +5 -7
- package/dist/index.js +163 -57
- package/dist/internal/abort.js +13 -0
- package/dist/internal/abort.js.map +1 -0
- package/dist/internal/agent-runtime/agent-run.js +81 -0
- package/dist/internal/agent-runtime/agent-run.js.map +1 -0
- package/dist/internal/agent-runtime/approval-request.js +1 -0
- package/dist/internal/agent-runtime/approval-request.js.map +1 -0
- package/dist/internal/agent-runtime/approval-requirement.js +9 -0
- package/dist/internal/agent-runtime/approval-requirement.js.map +1 -0
- package/dist/internal/agent-runtime/continuation-state.js +26 -0
- package/dist/internal/agent-runtime/continuation-state.js.map +1 -0
- package/dist/internal/agent-runtime/interaction-suspension.js +25 -0
- package/dist/internal/agent-runtime/interaction-suspension.js.map +1 -0
- package/dist/internal/agent-runtime/memory-scope.js +8 -0
- package/dist/internal/agent-runtime/memory-scope.js.map +1 -0
- package/dist/internal/agent-runtime/memory.js +24 -0
- package/dist/internal/agent-runtime/memory.js.map +1 -0
- package/dist/internal/agent-runtime/prepared-tool-call.js +19 -0
- package/dist/internal/agent-runtime/prepared-tool-call.js.map +1 -0
- package/dist/internal/agent-runtime/retrieval.js +35 -0
- package/dist/internal/agent-runtime/retrieval.js.map +1 -0
- package/dist/internal/agent-runtime/run-options.js +9 -0
- package/dist/internal/agent-runtime/run-options.js.map +1 -0
- package/dist/internal/agent-runtime/run-validation.js +9 -0
- package/dist/internal/agent-runtime/run-validation.js.map +1 -0
- package/dist/internal/agent-runtime/stream-events.js +11 -0
- package/dist/internal/agent-runtime/stream-events.js.map +1 -0
- package/dist/internal/agent-runtime/structured-output.js +13 -0
- package/dist/internal/agent-runtime/structured-output.js.map +1 -0
- package/dist/internal/agent-runtime/tool-execution.js +55 -0
- package/dist/internal/agent-runtime/tool-execution.js.map +1 -0
- package/dist/internal/agent.d.ts +5 -5
- package/dist/internal/agent.js +93 -57
- package/dist/internal/agent.js.map +1 -1
- package/dist/internal/async-queue.js +7 -0
- package/dist/internal/async-queue.js.map +1 -0
- package/dist/internal/completion-request.js +11 -0
- package/dist/internal/completion-request.js.map +1 -0
- package/dist/internal/concurrency.js +7 -0
- package/dist/internal/concurrency.js.map +1 -0
- package/dist/internal/json-object.js +8 -0
- package/dist/internal/json-object.js.map +1 -0
- package/dist/internal/rag-text.js +7 -0
- package/dist/internal/rag-text.js.map +1 -0
- package/dist/internal/record.js +7 -0
- package/dist/internal/record.js.map +1 -0
- package/dist/internal/team-runtime/coordination.js +12 -0
- package/dist/internal/team-runtime/coordination.js.map +1 -0
- package/dist/internal/team-runtime/member.js +26 -0
- package/dist/internal/team-runtime/member.js.map +1 -0
- package/dist/internal/team-runtime/policy.js +7 -0
- package/dist/internal/team-runtime/policy.js.map +1 -0
- package/dist/internal/team-runtime/run.js +95 -0
- package/dist/internal/team-runtime/run.js.map +1 -0
- package/dist/internal/team-runtime/stream.js +9 -0
- package/dist/internal/team-runtime/stream.js.map +1 -0
- package/dist/internal/team-runtime/tools.js +17 -0
- package/dist/internal/team-runtime/tools.js.map +1 -0
- package/dist/internal/type-utils.js +1 -0
- package/dist/internal/type-utils.js.map +1 -0
- package/dist/internal/vector-search-options.js +9 -0
- package/dist/internal/vector-search-options.js.map +1 -0
- package/dist/mcp/index.js +3 -1
- package/dist/mcp/tool.js +7 -0
- package/dist/mcp/tool.js.map +1 -0
- package/dist/mcp/types.js +2 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/memory/assert.js +11 -0
- package/dist/memory/assert.js.map +1 -0
- package/dist/memory/compaction.js +26 -0
- package/dist/memory/compaction.js.map +1 -0
- package/dist/memory/errors.js +9 -0
- package/dist/memory/errors.js.map +1 -0
- package/dist/memory/index.js +23 -10
- package/dist/memory/options.js +10 -0
- package/dist/memory/options.js.map +1 -0
- package/dist/memory/scope-key.js +7 -0
- package/dist/memory/scope-key.js.map +1 -0
- package/dist/memory/types.js +2 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/{types-CRda8x7p.d.ts → middleware-CWjnMbiH.d.ts} +64 -5
- package/dist/model-call-options.js +1 -0
- package/dist/model-call-options.js.map +1 -0
- package/dist/model-listing/errors.js +7 -0
- package/dist/model-listing/errors.js.map +1 -0
- package/dist/model-listing/index.js +4 -13
- package/dist/model-listing/index.js.map +1 -1
- package/dist/model-listing/types.js +2 -0
- package/dist/model-listing/types.js.map +1 -0
- package/dist/observability/group.js +30 -0
- package/dist/observability/group.js.map +1 -0
- package/dist/observability/index.d.ts +4 -6
- package/dist/observability/index.js +16 -8
- package/dist/observability/snapshot.js +7 -0
- package/dist/observability/snapshot.js.map +1 -0
- package/dist/observability/types.js +1 -0
- package/dist/observability/types.js.map +1 -0
- package/dist/pipeline/errors.js +9 -0
- package/dist/pipeline/errors.js.map +1 -0
- package/dist/pipeline/graph.js +21 -0
- package/dist/pipeline/graph.js.map +1 -0
- package/dist/pipeline/index.d.ts +4 -6
- package/dist/pipeline/index.js +27 -805
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/observability.js +15 -0
- package/dist/pipeline/observability.js.map +1 -0
- package/dist/pipeline/pipeline.js +30 -0
- package/dist/pipeline/pipeline.js.map +1 -0
- package/dist/pipeline/runtime.js +17 -0
- package/dist/pipeline/runtime.js.map +1 -0
- package/dist/pipeline/types.js +1 -0
- package/dist/pipeline/types.js.map +1 -0
- package/dist/retry.js +20 -0
- package/dist/retry.js.map +1 -0
- package/dist/schema/index.js +1 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/zod-schema.js +7 -0
- package/dist/schema/zod-schema.js.map +1 -0
- package/dist/skills/index.js +41 -12
- package/dist/skills/instructions.js +7 -0
- package/dist/skills/instructions.js.map +1 -0
- package/dist/skills/load.js +39 -0
- package/dist/skills/load.js.map +1 -0
- package/dist/skills/local.js +9 -0
- package/dist/skills/local.js.map +1 -0
- package/dist/skills/tools.js +37 -0
- package/dist/skills/tools.js.map +1 -0
- package/dist/skills/types.js +7 -0
- package/dist/skills/types.js.map +1 -0
- package/dist/speech-generation/generate-speech.js +11 -0
- package/dist/speech-generation/generate-speech.js.map +1 -0
- package/dist/speech-generation/index.js +7 -4
- package/dist/speech-generation/types.js +2 -0
- package/dist/speech-generation/types.js.map +1 -0
- package/dist/streaming/index.js +3 -37
- package/dist/streaming/index.js.map +1 -1
- package/dist/streaming/readable-stream.js +7 -0
- package/dist/streaming/readable-stream.js.map +1 -0
- package/dist/{text-CmjXxakS.d.ts → text-GbW4WYMg.d.ts} +1 -1
- package/dist/tool/create-tool.js +14 -0
- package/dist/tool/create-tool.js.map +1 -0
- package/dist/tool/dynamic-tools.js +35 -0
- package/dist/tool/dynamic-tools.js.map +1 -0
- package/dist/tool/errors.js +11 -0
- package/dist/tool/errors.js.map +1 -0
- package/dist/tool/index.d.ts +3 -2
- package/dist/tool/index.js +41 -15
- package/dist/tool/middleware.js +7 -0
- package/dist/tool/middleware.js.map +1 -0
- package/dist/tool/question-tool.js +17 -0
- package/dist/tool/question-tool.js.map +1 -0
- package/dist/tool/skill-tool-marker.js +9 -0
- package/dist/tool/skill-tool-marker.js.map +1 -0
- package/dist/tool/think-tool.js +15 -0
- package/dist/tool/think-tool.js.map +1 -0
- package/dist/tool/tool.js +17 -0
- package/dist/tool/tool.js.map +1 -0
- package/dist/transcription/index.js +7 -4
- package/dist/transcription/transcribe.js +11 -0
- package/dist/transcription/transcribe.js.map +1 -0
- package/dist/transcription/types.js +2 -0
- package/dist/transcription/types.js.map +1 -0
- package/dist/{types-h0EL6Xn0.d.ts → types-Bqw0AuFl.d.ts} +6 -2
- package/dist/vector-store/filter.js +9 -0
- package/dist/vector-store/filter.js.map +1 -0
- package/dist/vector-store/index.js +31 -11
- package/dist/vector-store/ingest.js +19 -0
- package/dist/vector-store/ingest.js.map +1 -0
- package/dist/vector-store/lsh.js +7 -0
- package/dist/vector-store/lsh.js.map +1 -0
- package/dist/vector-store/retrieve.js +15 -0
- package/dist/vector-store/retrieve.js.map +1 -0
- package/dist/vector-store/types.js +1 -0
- package/dist/vector-store/types.js.map +1 -0
- package/package.json +8 -5
- package/dist/chunk-2QZJTG2E.js.map +0 -1
- package/dist/chunk-3RWESPUG.js.map +0 -1
- package/dist/chunk-4UQALF5Y.js.map +0 -1
- package/dist/chunk-AZB6N7P4.js +0 -320
- package/dist/chunk-AZB6N7P4.js.map +0 -1
- package/dist/chunk-JLJMVRRE.js.map +0 -1
- package/dist/chunk-K5L7R7XM.js.map +0 -1
- package/dist/chunk-OI3LSMJG.js +0 -1545
- package/dist/chunk-OI3LSMJG.js.map +0 -1
- package/dist/chunk-QGX73TSQ.js.map +0 -1
- package/dist/chunk-XC3LVC4K.js +0 -753
- package/dist/chunk-XC3LVC4K.js.map +0 -1
- package/dist/chunk-XEVOC433.js.map +0 -1
- package/dist/chunk-XSV5C4R5.js +0 -400
- package/dist/chunk-XSV5C4R5.js.map +0 -1
- package/dist/chunk-XU54PLSD.js +0 -4786
- package/dist/chunk-XU54PLSD.js.map +0 -1
- package/dist/middleware-mY_lpjDp.d.ts +0 -59
- package/dist/type-utils-CtHVDRn_.d.ts +0 -6
- /package/dist/{chunk-YK4WAAS4.js.map → chunk-2NLINXRF.js.map} +0 -0
- /package/dist/{chunk-SPD4XVR7.js.map → chunk-2XSMGVBG.js.map} +0 -0
- /package/dist/{chunk-3XQGVDU5.js.map → chunk-4C7AXYOM.js.map} +0 -0
- /package/dist/{chunk-IZNOP6JG.js.map → chunk-4FIVU53H.js.map} +0 -0
- /package/dist/{chunk-7JLAIN6E.js.map → chunk-4ONUNWGC.js.map} +0 -0
- /package/dist/{chunk-KSKST3KP.js.map → chunk-H3H74RWJ.js.map} +0 -0
- /package/dist/{chunk-OJBFDBLG.js.map → chunk-LBYJPMHC.js.map} +0 -0
- /package/dist/{chunk-J6LVLV6P.js.map → chunk-PLDJCCVL.js.map} +0 -0
- /package/dist/{chunk-AHLKV6KP.js.map → chunk-WN6AVBO4.js.map} +0 -0
- /package/dist/{chunk-Q5BCNYED.js.map → chunk-XJRNBTIV.js.map} +0 -0
|
@@ -0,0 +1,939 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgentInteractionSignal,
|
|
3
|
+
ToolExecutionSuspension
|
|
4
|
+
} from "./chunk-5IURMWFN.js";
|
|
5
|
+
import {
|
|
6
|
+
isQuestionTool
|
|
7
|
+
} from "./chunk-IV6YQTY2.js";
|
|
8
|
+
import {
|
|
9
|
+
isSkillTool
|
|
10
|
+
} from "./chunk-2NLINXRF.js";
|
|
11
|
+
import {
|
|
12
|
+
runControl,
|
|
13
|
+
toolCallControl
|
|
14
|
+
} from "./chunk-FAPIZJS2.js";
|
|
15
|
+
import {
|
|
16
|
+
parseAgentQuestionPrompts
|
|
17
|
+
} from "./chunk-LBYJPMHC.js";
|
|
18
|
+
import {
|
|
19
|
+
lifecycleSnapshot
|
|
20
|
+
} from "./chunk-KFAVEL5F.js";
|
|
21
|
+
import {
|
|
22
|
+
isMcpTool
|
|
23
|
+
} from "./chunk-PLDJCCVL.js";
|
|
24
|
+
import {
|
|
25
|
+
mapWithConcurrency
|
|
26
|
+
} from "./chunk-4FIVU53H.js";
|
|
27
|
+
import {
|
|
28
|
+
assertCompletionResponseIntegrity
|
|
29
|
+
} from "./chunk-XQV3XNVT.js";
|
|
30
|
+
import {
|
|
31
|
+
assertToolApprovalRequirement,
|
|
32
|
+
toolMayRequireApproval
|
|
33
|
+
} from "./chunk-YZVFIW5D.js";
|
|
34
|
+
import {
|
|
35
|
+
prepareToolCall,
|
|
36
|
+
prepareToolCallFromInput
|
|
37
|
+
} from "./chunk-MHOJJYDK.js";
|
|
38
|
+
import {
|
|
39
|
+
ToolOutput,
|
|
40
|
+
normalizeToolResultOutput,
|
|
41
|
+
parseToolArgs,
|
|
42
|
+
toolResultContentToText
|
|
43
|
+
} from "./chunk-47NTHIVB.js";
|
|
44
|
+
import {
|
|
45
|
+
Usage
|
|
46
|
+
} from "./chunk-IDNL6IH4.js";
|
|
47
|
+
import {
|
|
48
|
+
isJsonValue
|
|
49
|
+
} from "./chunk-4C7AXYOM.js";
|
|
50
|
+
import {
|
|
51
|
+
throwIfAborted
|
|
52
|
+
} from "./chunk-USRKPEQN.js";
|
|
53
|
+
|
|
54
|
+
// src/internal/agent-runtime/tool-execution.ts
|
|
55
|
+
var ToolCallExecutor = class {
|
|
56
|
+
constructor(agent, activeHook, approvalHandler, lifecycle, runContext, concurrency, requestMiddlewares, abortSignal, cancel) {
|
|
57
|
+
this.agent = agent;
|
|
58
|
+
this.activeHook = activeHook;
|
|
59
|
+
this.approvalHandler = approvalHandler;
|
|
60
|
+
this.lifecycle = lifecycle;
|
|
61
|
+
this.runContext = runContext;
|
|
62
|
+
this.concurrency = concurrency;
|
|
63
|
+
this.requestMiddlewares = requestMiddlewares;
|
|
64
|
+
this.abortSignal = abortSignal;
|
|
65
|
+
this.cancel = cancel;
|
|
66
|
+
}
|
|
67
|
+
agent;
|
|
68
|
+
activeHook;
|
|
69
|
+
approvalHandler;
|
|
70
|
+
lifecycle;
|
|
71
|
+
runContext;
|
|
72
|
+
concurrency;
|
|
73
|
+
requestMiddlewares;
|
|
74
|
+
abortSignal;
|
|
75
|
+
cancel;
|
|
76
|
+
async execute(toolCalls, onResult, onStreamEvent, observation) {
|
|
77
|
+
assertCompletionResponseIntegrity({
|
|
78
|
+
response: {
|
|
79
|
+
choice: [...toolCalls],
|
|
80
|
+
usage: Usage.empty(),
|
|
81
|
+
rawResponse: void 0
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
const executeOne = async (toolCall) => {
|
|
85
|
+
throwIfAborted(this.abortSignal);
|
|
86
|
+
const args = JSON.stringify(toolCall.input);
|
|
87
|
+
const internalCallId = globalThis.crypto.randomUUID();
|
|
88
|
+
const hookArgs = {
|
|
89
|
+
toolName: toolCall.toolName,
|
|
90
|
+
toolCallId: toolCall.toolCallId,
|
|
91
|
+
internalCallId,
|
|
92
|
+
args
|
|
93
|
+
};
|
|
94
|
+
if (toolCall.callId !== void 0) {
|
|
95
|
+
hookArgs.callId = toolCall.callId;
|
|
96
|
+
}
|
|
97
|
+
const tool = this.agent.getTool(toolCall.toolName);
|
|
98
|
+
const toolDefinition = observation?.toolDefinitions?.find(
|
|
99
|
+
(definition) => definition.name === toolCall.toolName
|
|
100
|
+
);
|
|
101
|
+
const toolMetadata = toolTraceMetadata(tool);
|
|
102
|
+
let toolStartArgs = {
|
|
103
|
+
turn: observation?.turn ?? 0,
|
|
104
|
+
toolCall,
|
|
105
|
+
toolName: toolCall.toolName,
|
|
106
|
+
internalCallId,
|
|
107
|
+
args
|
|
108
|
+
};
|
|
109
|
+
if (toolCall.callId !== void 0) {
|
|
110
|
+
toolStartArgs = { ...toolStartArgs, toolCallId: toolCall.callId };
|
|
111
|
+
}
|
|
112
|
+
if (toolDefinition !== void 0) toolStartArgs = { ...toolStartArgs, toolDefinition };
|
|
113
|
+
if (toolMetadata !== void 0) toolStartArgs = { ...toolStartArgs, toolMetadata };
|
|
114
|
+
const toolObservers = await observation?.runObservers.startTool(toolStartArgs);
|
|
115
|
+
const toolObservation = new ToolObserverScope(toolObservers);
|
|
116
|
+
let output;
|
|
117
|
+
let skipped = false;
|
|
118
|
+
let toolExecutionFailed = false;
|
|
119
|
+
let effectiveArgs = args;
|
|
120
|
+
try {
|
|
121
|
+
const callAction = await this.activeHook?.onToolCall?.({
|
|
122
|
+
...hookArgs,
|
|
123
|
+
tool: toolCallControl
|
|
124
|
+
});
|
|
125
|
+
if (callAction?.type === "terminate") {
|
|
126
|
+
throw this.cancel(callAction.reason);
|
|
127
|
+
}
|
|
128
|
+
if (callAction?.type === "skip") {
|
|
129
|
+
output = { type: "text", value: callAction.reason };
|
|
130
|
+
skipped = true;
|
|
131
|
+
} else {
|
|
132
|
+
try {
|
|
133
|
+
effectiveArgs = await this.runToolInputMiddlewares({
|
|
134
|
+
...hookArgs,
|
|
135
|
+
turn: observation?.turn ?? 0,
|
|
136
|
+
originalArgs: args
|
|
137
|
+
});
|
|
138
|
+
hookArgs.args = effectiveArgs;
|
|
139
|
+
let prepared;
|
|
140
|
+
try {
|
|
141
|
+
prepared = this.prepareToolCall(tool, toolCall.toolName, effectiveArgs);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
const outcome = await this.handleToolError(
|
|
144
|
+
toolCall,
|
|
145
|
+
hookArgs,
|
|
146
|
+
effectiveArgs,
|
|
147
|
+
error,
|
|
148
|
+
toolObservation,
|
|
149
|
+
observation
|
|
150
|
+
);
|
|
151
|
+
output = outcome.output;
|
|
152
|
+
toolExecutionFailed = outcome.failed;
|
|
153
|
+
}
|
|
154
|
+
if (prepared !== void 0 && isQuestionTool(tool)) {
|
|
155
|
+
try {
|
|
156
|
+
const questions = parseAgentQuestionPrompts(
|
|
157
|
+
prepared.input.questions
|
|
158
|
+
);
|
|
159
|
+
const interaction = {
|
|
160
|
+
type: "tool-question",
|
|
161
|
+
id: globalThis.crypto.randomUUID(),
|
|
162
|
+
toolName: toolCall.toolName,
|
|
163
|
+
toolCallId: toolCall.toolCallId,
|
|
164
|
+
internalCallId,
|
|
165
|
+
questions
|
|
166
|
+
};
|
|
167
|
+
if (toolCall.callId !== void 0) {
|
|
168
|
+
Object.assign(interaction, { callId: toolCall.callId });
|
|
169
|
+
}
|
|
170
|
+
throw new AgentInteractionSignal(interaction);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
if (error instanceof AgentInteractionSignal) throw error;
|
|
173
|
+
const outcome = await this.handleToolError(
|
|
174
|
+
toolCall,
|
|
175
|
+
hookArgs,
|
|
176
|
+
effectiveArgs,
|
|
177
|
+
error,
|
|
178
|
+
toolObservation,
|
|
179
|
+
observation
|
|
180
|
+
);
|
|
181
|
+
output = outcome.output;
|
|
182
|
+
toolExecutionFailed = outcome.failed;
|
|
183
|
+
prepared = void 0;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (prepared !== void 0) {
|
|
187
|
+
const approvalContext = createApprovalContext(
|
|
188
|
+
prepared.input,
|
|
189
|
+
hookArgs,
|
|
190
|
+
this.agent,
|
|
191
|
+
this.runContext
|
|
192
|
+
);
|
|
193
|
+
const approvalDecision = callAction?.type === "approval_request" ? await this.requestApproval(approvalContext, callAction, observation) : await this.evaluateToolApproval(tool, approvalContext, observation) ?? {
|
|
194
|
+
approved: true
|
|
195
|
+
};
|
|
196
|
+
if (!approvalDecision.approved) {
|
|
197
|
+
output = { type: "execution-denied", reason: approvalDecision.result };
|
|
198
|
+
skipped = true;
|
|
199
|
+
} else {
|
|
200
|
+
const step = observation?.turn ?? 0;
|
|
201
|
+
const lifecycleEvent = {
|
|
202
|
+
runId: this.runContext.runId,
|
|
203
|
+
step,
|
|
204
|
+
toolName: toolCall.toolName,
|
|
205
|
+
input: lifecycleSnapshot(prepared.input)
|
|
206
|
+
};
|
|
207
|
+
if (toolCall.callId !== void 0) {
|
|
208
|
+
Object.assign(lifecycleEvent, { toolCallId: toolCall.callId });
|
|
209
|
+
}
|
|
210
|
+
await this.lifecycle?.onToolStart?.(lifecycleEvent);
|
|
211
|
+
const startedAt = Date.now();
|
|
212
|
+
const outcome = await this.runApprovedToolCall(
|
|
213
|
+
prepared,
|
|
214
|
+
toolCall,
|
|
215
|
+
hookArgs,
|
|
216
|
+
effectiveArgs,
|
|
217
|
+
toolObservation,
|
|
218
|
+
observation,
|
|
219
|
+
onStreamEvent
|
|
220
|
+
);
|
|
221
|
+
output = outcome.output;
|
|
222
|
+
toolExecutionFailed = outcome.failed;
|
|
223
|
+
const durationMs = Date.now() - startedAt;
|
|
224
|
+
await this.lifecycle?.onToolFinish?.(
|
|
225
|
+
outcome.failed ? {
|
|
226
|
+
...lifecycleEvent,
|
|
227
|
+
durationMs,
|
|
228
|
+
success: false,
|
|
229
|
+
error: lifecycleSnapshot(outcome.error)
|
|
230
|
+
} : {
|
|
231
|
+
...lifecycleEvent,
|
|
232
|
+
durationMs,
|
|
233
|
+
success: true,
|
|
234
|
+
output: lifecycleSnapshot(output)
|
|
235
|
+
}
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
} catch (error) {
|
|
240
|
+
if (error instanceof AgentInteractionSignal) {
|
|
241
|
+
await toolObservation.suspend({
|
|
242
|
+
...toolStartArgs,
|
|
243
|
+
interaction: error.interaction
|
|
244
|
+
});
|
|
245
|
+
throw error;
|
|
246
|
+
}
|
|
247
|
+
await toolObservation.error(
|
|
248
|
+
toolErrorArgs(observation?.turn ?? 0, toolCall, internalCallId, effectiveArgs, error)
|
|
249
|
+
);
|
|
250
|
+
throw error;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (output === void 0) {
|
|
254
|
+
throw new Error(`Tool "${toolCall.toolName}" did not produce an execution result.`);
|
|
255
|
+
}
|
|
256
|
+
let result = toolOutputToText(output);
|
|
257
|
+
let structuredResult = toolOutputToStructuredResult(output);
|
|
258
|
+
if (!isSkillTool(tool)) {
|
|
259
|
+
const middlewareReplacement = await this.runToolResultMiddlewares({
|
|
260
|
+
...hookArgs,
|
|
261
|
+
args: effectiveArgs,
|
|
262
|
+
result,
|
|
263
|
+
originalResult: result,
|
|
264
|
+
structuredResult,
|
|
265
|
+
originalStructuredResult: structuredResult,
|
|
266
|
+
turn: observation?.turn ?? 0
|
|
267
|
+
});
|
|
268
|
+
if (middlewareReplacement !== void 0) {
|
|
269
|
+
output = middlewareReplacement;
|
|
270
|
+
result = toolOutputToText(middlewareReplacement);
|
|
271
|
+
structuredResult = toolOutputToStructuredResult(middlewareReplacement);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const resultAction = await this.activeHook?.onToolResult?.({
|
|
275
|
+
...hookArgs,
|
|
276
|
+
args: effectiveArgs,
|
|
277
|
+
result,
|
|
278
|
+
structuredResult,
|
|
279
|
+
run: runControl
|
|
280
|
+
});
|
|
281
|
+
if (!toolExecutionFailed) {
|
|
282
|
+
await toolObservation.end({
|
|
283
|
+
turn: observation?.turn ?? 0,
|
|
284
|
+
toolCall,
|
|
285
|
+
toolName: toolCall.toolName,
|
|
286
|
+
internalCallId,
|
|
287
|
+
args: effectiveArgs,
|
|
288
|
+
result,
|
|
289
|
+
structuredResult,
|
|
290
|
+
skipped,
|
|
291
|
+
toolCallId: toolCall.callId
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
if (resultAction?.type === "terminate") {
|
|
295
|
+
throw this.cancel(resultAction.reason);
|
|
296
|
+
}
|
|
297
|
+
const resultPayload = {
|
|
298
|
+
type: "tool_result",
|
|
299
|
+
toolName: toolCall.toolName,
|
|
300
|
+
toolCallId: toolCall.toolCallId,
|
|
301
|
+
internalCallId,
|
|
302
|
+
args: effectiveArgs,
|
|
303
|
+
output,
|
|
304
|
+
result,
|
|
305
|
+
structuredResult
|
|
306
|
+
};
|
|
307
|
+
if (toolCall.callId !== void 0) resultPayload.callId = toolCall.callId;
|
|
308
|
+
onResult?.(resultPayload);
|
|
309
|
+
let resultPart = {
|
|
310
|
+
type: "tool-result",
|
|
311
|
+
toolCallId: toolCall.toolCallId,
|
|
312
|
+
toolName: toolCall.toolName,
|
|
313
|
+
output
|
|
314
|
+
};
|
|
315
|
+
if (toolCall.callId !== void 0) {
|
|
316
|
+
resultPart = { ...resultPart, callId: toolCall.callId };
|
|
317
|
+
}
|
|
318
|
+
return resultPart;
|
|
319
|
+
} catch (error) {
|
|
320
|
+
if (error instanceof AgentInteractionSignal) {
|
|
321
|
+
const pending = {
|
|
322
|
+
toolCall,
|
|
323
|
+
effectiveArgs,
|
|
324
|
+
input: error.interaction.type === "tool-approval" ? error.interaction.input : parseToolArgs(effectiveArgs),
|
|
325
|
+
internalCallId
|
|
326
|
+
};
|
|
327
|
+
if (error.rejectMessage !== void 0) pending.rejectMessage = error.rejectMessage;
|
|
328
|
+
throw new ToolExecutionSuspension(error.interaction, pending);
|
|
329
|
+
}
|
|
330
|
+
await toolObservation.error(
|
|
331
|
+
toolErrorArgs(observation?.turn ?? 0, toolCall, internalCallId, effectiveArgs, error)
|
|
332
|
+
);
|
|
333
|
+
throw error;
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
if (this.concurrency === 1) {
|
|
337
|
+
const results = [];
|
|
338
|
+
for (const toolCall of toolCalls) {
|
|
339
|
+
try {
|
|
340
|
+
results.push(await executeOne(toolCall));
|
|
341
|
+
} catch (error) {
|
|
342
|
+
if (error instanceof ToolExecutionSuspension) {
|
|
343
|
+
error.completedResults = [...results];
|
|
344
|
+
error.remainingToolCalls = toolCalls.slice(results.length + 1);
|
|
345
|
+
}
|
|
346
|
+
throw error;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return results;
|
|
350
|
+
}
|
|
351
|
+
return mapWithConcurrency(toolCalls, this.concurrency, executeOne);
|
|
352
|
+
}
|
|
353
|
+
async executeResumed(pending, onResult, onStreamEvent, observation) {
|
|
354
|
+
throwIfAborted(this.abortSignal);
|
|
355
|
+
const { toolCall, internalCallId, effectiveArgs } = pending;
|
|
356
|
+
const tool = this.agent.getTool(toolCall.toolName);
|
|
357
|
+
if (tool === void 0) {
|
|
358
|
+
throw new Error(
|
|
359
|
+
`Cannot resume tool interaction because tool "${toolCall.toolName}" is no longer registered.`
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
if (isQuestionTool(tool)) {
|
|
363
|
+
throw new TypeError("Question interactions are resolved from their submitted answers.");
|
|
364
|
+
}
|
|
365
|
+
const hookArgs = {
|
|
366
|
+
toolName: toolCall.toolName,
|
|
367
|
+
toolCallId: toolCall.toolCallId,
|
|
368
|
+
internalCallId,
|
|
369
|
+
args: effectiveArgs
|
|
370
|
+
};
|
|
371
|
+
if (toolCall.callId !== void 0) hookArgs.callId = toolCall.callId;
|
|
372
|
+
const toolDefinition = observation?.toolDefinitions?.find(
|
|
373
|
+
(definition) => definition.name === toolCall.toolName
|
|
374
|
+
);
|
|
375
|
+
const toolMetadata = toolTraceMetadata(tool);
|
|
376
|
+
let toolStartArgs = {
|
|
377
|
+
turn: observation?.turn ?? 0,
|
|
378
|
+
toolCall,
|
|
379
|
+
toolName: toolCall.toolName,
|
|
380
|
+
internalCallId,
|
|
381
|
+
args: effectiveArgs
|
|
382
|
+
};
|
|
383
|
+
if (toolCall.callId !== void 0) {
|
|
384
|
+
toolStartArgs = { ...toolStartArgs, toolCallId: toolCall.callId };
|
|
385
|
+
}
|
|
386
|
+
if (toolDefinition !== void 0) toolStartArgs = { ...toolStartArgs, toolDefinition };
|
|
387
|
+
if (toolMetadata !== void 0) toolStartArgs = { ...toolStartArgs, toolMetadata };
|
|
388
|
+
const observers = await observation?.runObservers.startTool(toolStartArgs);
|
|
389
|
+
const toolObservation = new ToolObserverScope(observers);
|
|
390
|
+
let output;
|
|
391
|
+
let failed = false;
|
|
392
|
+
try {
|
|
393
|
+
const prepared = prepareToolCallFromInput(tool, pending.input);
|
|
394
|
+
const step = observation?.turn ?? 0;
|
|
395
|
+
const lifecycleEvent = {
|
|
396
|
+
runId: this.runContext.runId,
|
|
397
|
+
step,
|
|
398
|
+
toolName: toolCall.toolName,
|
|
399
|
+
input: lifecycleSnapshot(prepared.input)
|
|
400
|
+
};
|
|
401
|
+
if (toolCall.callId !== void 0) {
|
|
402
|
+
Object.assign(lifecycleEvent, { toolCallId: toolCall.callId });
|
|
403
|
+
}
|
|
404
|
+
await this.lifecycle?.onToolStart?.(lifecycleEvent);
|
|
405
|
+
const startedAt = Date.now();
|
|
406
|
+
const outcome = await this.runApprovedToolCall(
|
|
407
|
+
prepared,
|
|
408
|
+
toolCall,
|
|
409
|
+
hookArgs,
|
|
410
|
+
effectiveArgs,
|
|
411
|
+
toolObservation,
|
|
412
|
+
observation,
|
|
413
|
+
onStreamEvent
|
|
414
|
+
);
|
|
415
|
+
output = outcome.output;
|
|
416
|
+
failed = outcome.failed;
|
|
417
|
+
const durationMs = Date.now() - startedAt;
|
|
418
|
+
await this.lifecycle?.onToolFinish?.(
|
|
419
|
+
outcome.failed ? {
|
|
420
|
+
...lifecycleEvent,
|
|
421
|
+
durationMs,
|
|
422
|
+
success: false,
|
|
423
|
+
error: lifecycleSnapshot(outcome.error)
|
|
424
|
+
} : {
|
|
425
|
+
...lifecycleEvent,
|
|
426
|
+
durationMs,
|
|
427
|
+
success: true,
|
|
428
|
+
output: lifecycleSnapshot(output)
|
|
429
|
+
}
|
|
430
|
+
);
|
|
431
|
+
let result = toolOutputToText(output);
|
|
432
|
+
let structuredResult = toolOutputToStructuredResult(output);
|
|
433
|
+
if (!isSkillTool(tool)) {
|
|
434
|
+
const replacement = await this.runToolResultMiddlewares({
|
|
435
|
+
...hookArgs,
|
|
436
|
+
args: effectiveArgs,
|
|
437
|
+
result,
|
|
438
|
+
originalResult: result,
|
|
439
|
+
structuredResult,
|
|
440
|
+
originalStructuredResult: structuredResult,
|
|
441
|
+
turn: step
|
|
442
|
+
});
|
|
443
|
+
if (replacement !== void 0) {
|
|
444
|
+
output = replacement;
|
|
445
|
+
result = toolOutputToText(replacement);
|
|
446
|
+
structuredResult = toolOutputToStructuredResult(replacement);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
const resultAction = await this.activeHook?.onToolResult?.({
|
|
450
|
+
...hookArgs,
|
|
451
|
+
result,
|
|
452
|
+
structuredResult,
|
|
453
|
+
run: runControl
|
|
454
|
+
});
|
|
455
|
+
if (!failed) {
|
|
456
|
+
await toolObservation.end({
|
|
457
|
+
turn: step,
|
|
458
|
+
toolCall,
|
|
459
|
+
toolName: toolCall.toolName,
|
|
460
|
+
internalCallId,
|
|
461
|
+
args: effectiveArgs,
|
|
462
|
+
result,
|
|
463
|
+
structuredResult,
|
|
464
|
+
skipped: false,
|
|
465
|
+
toolCallId: toolCall.callId
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
if (resultAction?.type === "terminate") {
|
|
469
|
+
throw this.cancel(resultAction.reason);
|
|
470
|
+
}
|
|
471
|
+
const resultPayload = {
|
|
472
|
+
type: "tool_result",
|
|
473
|
+
toolName: toolCall.toolName,
|
|
474
|
+
toolCallId: toolCall.toolCallId,
|
|
475
|
+
internalCallId,
|
|
476
|
+
args: effectiveArgs,
|
|
477
|
+
output,
|
|
478
|
+
result,
|
|
479
|
+
structuredResult
|
|
480
|
+
};
|
|
481
|
+
if (toolCall.callId !== void 0) resultPayload.callId = toolCall.callId;
|
|
482
|
+
onResult?.(resultPayload);
|
|
483
|
+
let resultPart = {
|
|
484
|
+
type: "tool-result",
|
|
485
|
+
toolName: toolCall.toolName,
|
|
486
|
+
toolCallId: toolCall.toolCallId,
|
|
487
|
+
output
|
|
488
|
+
};
|
|
489
|
+
if (toolCall.callId !== void 0) resultPart = { ...resultPart, callId: toolCall.callId };
|
|
490
|
+
return resultPart;
|
|
491
|
+
} catch (error) {
|
|
492
|
+
await toolObservation.error(
|
|
493
|
+
toolErrorArgs(observation?.turn ?? 0, toolCall, internalCallId, effectiveArgs, error)
|
|
494
|
+
);
|
|
495
|
+
throw error;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
async resolveResumed(pending, initialOutput, onResult, observation) {
|
|
499
|
+
throwIfAborted(this.abortSignal);
|
|
500
|
+
const { toolCall, internalCallId, effectiveArgs } = pending;
|
|
501
|
+
const tool = this.agent.getTool(toolCall.toolName);
|
|
502
|
+
if (tool === void 0) {
|
|
503
|
+
throw new Error(
|
|
504
|
+
`Cannot resume tool interaction because tool "${toolCall.toolName}" is no longer registered.`
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
const hookArgs = {
|
|
508
|
+
toolName: toolCall.toolName,
|
|
509
|
+
toolCallId: toolCall.toolCallId,
|
|
510
|
+
internalCallId,
|
|
511
|
+
args: effectiveArgs
|
|
512
|
+
};
|
|
513
|
+
if (toolCall.callId !== void 0) hookArgs.callId = toolCall.callId;
|
|
514
|
+
const toolDefinition = observation?.toolDefinitions?.find(
|
|
515
|
+
(definition) => definition.name === toolCall.toolName
|
|
516
|
+
);
|
|
517
|
+
const toolMetadata = toolTraceMetadata(tool);
|
|
518
|
+
let toolStartArgs = {
|
|
519
|
+
turn: observation?.turn ?? 0,
|
|
520
|
+
toolCall,
|
|
521
|
+
toolName: toolCall.toolName,
|
|
522
|
+
internalCallId,
|
|
523
|
+
args: effectiveArgs
|
|
524
|
+
};
|
|
525
|
+
if (toolCall.callId !== void 0) {
|
|
526
|
+
toolStartArgs = { ...toolStartArgs, toolCallId: toolCall.callId };
|
|
527
|
+
}
|
|
528
|
+
if (toolDefinition !== void 0) toolStartArgs = { ...toolStartArgs, toolDefinition };
|
|
529
|
+
if (toolMetadata !== void 0) toolStartArgs = { ...toolStartArgs, toolMetadata };
|
|
530
|
+
const observers = await observation?.runObservers.startTool(toolStartArgs);
|
|
531
|
+
const toolObservation = new ToolObserverScope(observers);
|
|
532
|
+
try {
|
|
533
|
+
let output = initialOutput;
|
|
534
|
+
let result = toolOutputToText(output);
|
|
535
|
+
let structuredResult = toolOutputToStructuredResult(output);
|
|
536
|
+
if (!isSkillTool(tool)) {
|
|
537
|
+
const replacement = await this.runToolResultMiddlewares({
|
|
538
|
+
...hookArgs,
|
|
539
|
+
args: effectiveArgs,
|
|
540
|
+
result,
|
|
541
|
+
originalResult: result,
|
|
542
|
+
structuredResult,
|
|
543
|
+
originalStructuredResult: structuredResult,
|
|
544
|
+
turn: observation?.turn ?? 0
|
|
545
|
+
});
|
|
546
|
+
if (replacement !== void 0) {
|
|
547
|
+
output = replacement;
|
|
548
|
+
result = toolOutputToText(replacement);
|
|
549
|
+
structuredResult = toolOutputToStructuredResult(replacement);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
const resultAction = await this.activeHook?.onToolResult?.({
|
|
553
|
+
...hookArgs,
|
|
554
|
+
result,
|
|
555
|
+
structuredResult,
|
|
556
|
+
run: runControl
|
|
557
|
+
});
|
|
558
|
+
await toolObservation.end({
|
|
559
|
+
turn: observation?.turn ?? 0,
|
|
560
|
+
toolCall,
|
|
561
|
+
toolName: toolCall.toolName,
|
|
562
|
+
internalCallId,
|
|
563
|
+
args: effectiveArgs,
|
|
564
|
+
result,
|
|
565
|
+
structuredResult,
|
|
566
|
+
skipped: true,
|
|
567
|
+
toolCallId: toolCall.callId
|
|
568
|
+
});
|
|
569
|
+
if (resultAction?.type === "terminate") {
|
|
570
|
+
throw this.cancel(resultAction.reason);
|
|
571
|
+
}
|
|
572
|
+
const resultPayload = {
|
|
573
|
+
type: "tool_result",
|
|
574
|
+
toolName: toolCall.toolName,
|
|
575
|
+
toolCallId: toolCall.toolCallId,
|
|
576
|
+
internalCallId,
|
|
577
|
+
args: effectiveArgs,
|
|
578
|
+
output,
|
|
579
|
+
result,
|
|
580
|
+
structuredResult
|
|
581
|
+
};
|
|
582
|
+
if (toolCall.callId !== void 0) resultPayload.callId = toolCall.callId;
|
|
583
|
+
onResult?.(resultPayload);
|
|
584
|
+
let resultPart = {
|
|
585
|
+
type: "tool-result",
|
|
586
|
+
toolName: toolCall.toolName,
|
|
587
|
+
toolCallId: toolCall.toolCallId,
|
|
588
|
+
output
|
|
589
|
+
};
|
|
590
|
+
if (toolCall.callId !== void 0) resultPart = { ...resultPart, callId: toolCall.callId };
|
|
591
|
+
return resultPart;
|
|
592
|
+
} catch (error) {
|
|
593
|
+
await toolObservation.error(
|
|
594
|
+
toolErrorArgs(observation?.turn ?? 0, toolCall, internalCallId, effectiveArgs, error)
|
|
595
|
+
);
|
|
596
|
+
throw error;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
async runApprovedToolCall(prepared, toolCall, hookArgs, effectiveArgs, toolObservation, observation, onStreamEvent) {
|
|
600
|
+
try {
|
|
601
|
+
const toolContext = {
|
|
602
|
+
abortSignal: this.abortSignal,
|
|
603
|
+
emitStreamEvent: async (event) => {
|
|
604
|
+
let streamEventArgs = {
|
|
605
|
+
turn: observation?.turn ?? 0,
|
|
606
|
+
toolCall,
|
|
607
|
+
toolName: toolCall.toolName,
|
|
608
|
+
internalCallId: hookArgs.internalCallId,
|
|
609
|
+
args: effectiveArgs,
|
|
610
|
+
event
|
|
611
|
+
};
|
|
612
|
+
if (toolCall.callId !== void 0) {
|
|
613
|
+
streamEventArgs = { ...streamEventArgs, toolCallId: toolCall.callId };
|
|
614
|
+
}
|
|
615
|
+
await toolObservation.streamEvent(streamEventArgs);
|
|
616
|
+
const payload = agentToolEventPayload(toolCall, hookArgs.internalCallId, event);
|
|
617
|
+
if (payload !== void 0) {
|
|
618
|
+
onStreamEvent?.(payload);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
return {
|
|
623
|
+
output: await prepared.call(toolContext),
|
|
624
|
+
failed: false
|
|
625
|
+
};
|
|
626
|
+
} catch (error) {
|
|
627
|
+
return this.handleToolError(
|
|
628
|
+
toolCall,
|
|
629
|
+
hookArgs,
|
|
630
|
+
effectiveArgs,
|
|
631
|
+
error,
|
|
632
|
+
toolObservation,
|
|
633
|
+
observation
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
prepareToolCall(tool, toolName, args) {
|
|
638
|
+
if (tool !== void 0) {
|
|
639
|
+
return prepareToolCall(tool, args);
|
|
640
|
+
}
|
|
641
|
+
const input = parseToolArgs(args);
|
|
642
|
+
return {
|
|
643
|
+
input,
|
|
644
|
+
call: (context) => this.agent.callTool(toolName, args, context)
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
async handleToolError(toolCall, hookArgs, args, error, toolObservation, observation) {
|
|
648
|
+
const errorAction = await this.activeHook?.onToolError?.({
|
|
649
|
+
...hookArgs,
|
|
650
|
+
args,
|
|
651
|
+
error,
|
|
652
|
+
run: runControl
|
|
653
|
+
});
|
|
654
|
+
await toolObservation.error(
|
|
655
|
+
toolErrorArgs(observation?.turn ?? 0, toolCall, hookArgs.internalCallId, args, error)
|
|
656
|
+
);
|
|
657
|
+
if (errorAction?.type === "terminate") {
|
|
658
|
+
throw this.cancel(errorAction.reason);
|
|
659
|
+
}
|
|
660
|
+
return {
|
|
661
|
+
output: {
|
|
662
|
+
type: "error-text",
|
|
663
|
+
value: error instanceof Error ? error.toString() : String(error)
|
|
664
|
+
},
|
|
665
|
+
failed: true,
|
|
666
|
+
error
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
async runToolResultMiddlewares(args) {
|
|
670
|
+
let result = args.result;
|
|
671
|
+
let structuredResult = args.structuredResult;
|
|
672
|
+
let replaced = false;
|
|
673
|
+
for (const middleware of this.activeMiddlewares()) {
|
|
674
|
+
const outputReplacement = await middleware.onToolOutput?.({
|
|
675
|
+
...args,
|
|
676
|
+
result,
|
|
677
|
+
structuredResult
|
|
678
|
+
});
|
|
679
|
+
if (outputReplacement !== void 0) {
|
|
680
|
+
const normalized = normalizeToolOutputMiddlewareResult(outputReplacement);
|
|
681
|
+
if (normalized.result !== void 0) {
|
|
682
|
+
result = normalized.result;
|
|
683
|
+
structuredResult = void 0;
|
|
684
|
+
}
|
|
685
|
+
if (normalized.structuredResult !== void 0) {
|
|
686
|
+
structuredResult = normalized.structuredResult;
|
|
687
|
+
result = toolResultContentToText(normalized.structuredResult);
|
|
688
|
+
}
|
|
689
|
+
replaced = true;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
return replaced ? structuredResult === void 0 ? { type: "text", value: result } : { type: "content", value: structuredResult } : void 0;
|
|
693
|
+
}
|
|
694
|
+
async runToolInputMiddlewares(args) {
|
|
695
|
+
let current = args.args;
|
|
696
|
+
for (const middleware of this.activeMiddlewares()) {
|
|
697
|
+
const replacement = await middleware.onToolInput?.({
|
|
698
|
+
...args,
|
|
699
|
+
args: current
|
|
700
|
+
});
|
|
701
|
+
if (replacement?.args !== void 0) {
|
|
702
|
+
if (typeof replacement.args === "string") {
|
|
703
|
+
current = replacement.args;
|
|
704
|
+
} else {
|
|
705
|
+
if (!isJsonValue(replacement.args)) {
|
|
706
|
+
throw new TypeError("Tool input middleware args must be a strict JSON value.");
|
|
707
|
+
}
|
|
708
|
+
current = JSON.stringify(replacement.args);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
return current;
|
|
713
|
+
}
|
|
714
|
+
activeMiddlewares() {
|
|
715
|
+
return [...this.agent.middlewares, ...this.requestMiddlewares];
|
|
716
|
+
}
|
|
717
|
+
async evaluateToolApproval(tool, context, observation) {
|
|
718
|
+
const requirement = tool?.requiresApproval;
|
|
719
|
+
if (requirement === void 0) return void 0;
|
|
720
|
+
const resolved = typeof requirement === "function" ? await requirement(context.args, context) : requirement;
|
|
721
|
+
assertToolApprovalRequirement(resolved, { allowFunction: false });
|
|
722
|
+
if (resolved === false) return { approved: true };
|
|
723
|
+
const reason = resolved === true ? void 0 : resolved.reason;
|
|
724
|
+
return this.requestApproval(context, reason === void 0 ? {} : { reason }, observation);
|
|
725
|
+
}
|
|
726
|
+
async requestApproval(context, options, observation) {
|
|
727
|
+
const request = {
|
|
728
|
+
...context,
|
|
729
|
+
id: globalThis.crypto.randomUUID()
|
|
730
|
+
};
|
|
731
|
+
if (options.reason !== void 0) {
|
|
732
|
+
request.reason = options.reason;
|
|
733
|
+
}
|
|
734
|
+
if (options.rejectMessage !== void 0) {
|
|
735
|
+
request.rejectMessage = options.rejectMessage;
|
|
736
|
+
}
|
|
737
|
+
await observation?.runObservers.event({
|
|
738
|
+
name: "tool.approval_requested",
|
|
739
|
+
attributes: approvalEventAttributes(request, observation.turn)
|
|
740
|
+
});
|
|
741
|
+
let decision;
|
|
742
|
+
try {
|
|
743
|
+
decision = await this.approvalHandler(request);
|
|
744
|
+
} catch (error) {
|
|
745
|
+
if (error instanceof AgentInteractionSignal) {
|
|
746
|
+
throw error;
|
|
747
|
+
}
|
|
748
|
+
await observation?.runObservers.event({
|
|
749
|
+
name: "tool.approval_failed",
|
|
750
|
+
level: "ERROR",
|
|
751
|
+
attributes: {
|
|
752
|
+
...approvalEventAttributes(request, observation.turn),
|
|
753
|
+
errorName: error instanceof Error ? error.name : typeof error
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
throw error;
|
|
757
|
+
}
|
|
758
|
+
const attributes = {
|
|
759
|
+
...approvalEventAttributes(request, observation?.turn ?? 0),
|
|
760
|
+
approved: decision.approved
|
|
761
|
+
};
|
|
762
|
+
if (decision.reason !== void 0) attributes.decisionReason = decision.reason;
|
|
763
|
+
await observation?.runObservers.event({
|
|
764
|
+
name: "tool.approval_resolved",
|
|
765
|
+
attributes
|
|
766
|
+
});
|
|
767
|
+
if (decision.approved) {
|
|
768
|
+
return { approved: true };
|
|
769
|
+
}
|
|
770
|
+
return {
|
|
771
|
+
approved: false,
|
|
772
|
+
result: decision.reason ?? request.rejectMessage ?? "Tool approval was rejected."
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
function createApprovalContext(input, hookArgs, agent, run) {
|
|
777
|
+
const approvalRun = {
|
|
778
|
+
agentId: agent.id,
|
|
779
|
+
runId: run.runId
|
|
780
|
+
};
|
|
781
|
+
if (run.sessionId !== void 0) {
|
|
782
|
+
approvalRun.sessionId = run.sessionId;
|
|
783
|
+
}
|
|
784
|
+
if (run.metadata !== void 0) {
|
|
785
|
+
approvalRun.metadata = run.metadata;
|
|
786
|
+
}
|
|
787
|
+
const context = {
|
|
788
|
+
toolName: hookArgs.toolName,
|
|
789
|
+
args: lifecycleSnapshot(input),
|
|
790
|
+
rawArgs: hookArgs.args,
|
|
791
|
+
toolCallId: hookArgs.toolCallId,
|
|
792
|
+
internalCallId: hookArgs.internalCallId,
|
|
793
|
+
run: approvalRun
|
|
794
|
+
};
|
|
795
|
+
if (hookArgs.callId !== void 0) {
|
|
796
|
+
context.callId = hookArgs.callId;
|
|
797
|
+
}
|
|
798
|
+
return context;
|
|
799
|
+
}
|
|
800
|
+
function approvalEventAttributes(request, turn) {
|
|
801
|
+
const attributes = {
|
|
802
|
+
turn,
|
|
803
|
+
approvalId: request.id,
|
|
804
|
+
toolName: request.toolName,
|
|
805
|
+
internalCallId: request.internalCallId
|
|
806
|
+
};
|
|
807
|
+
if (request.toolCallId !== void 0) attributes.toolCallId = request.toolCallId;
|
|
808
|
+
if (request.reason !== void 0) attributes.reason = request.reason;
|
|
809
|
+
return attributes;
|
|
810
|
+
}
|
|
811
|
+
function normalizeToolOutputMiddlewareResult(result) {
|
|
812
|
+
if (typeof result === "string") {
|
|
813
|
+
return { result };
|
|
814
|
+
}
|
|
815
|
+
if (typeof result !== "object" || result === null) {
|
|
816
|
+
throw new TypeError("Tool output middleware must return text or structured content.");
|
|
817
|
+
}
|
|
818
|
+
const prototype = Object.getPrototypeOf(result);
|
|
819
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
820
|
+
throw new TypeError("Tool output middleware must return text or structured content.");
|
|
821
|
+
}
|
|
822
|
+
const keys = Reflect.ownKeys(result);
|
|
823
|
+
const hasResult = keys.includes("result");
|
|
824
|
+
const hasStructuredResult = keys.includes("structuredResult");
|
|
825
|
+
if (hasResult === hasStructuredResult || keys.some((key) => key !== "result" && key !== "structuredResult")) {
|
|
826
|
+
throw new TypeError(
|
|
827
|
+
"Tool output middleware must return exactly one of result or structuredResult."
|
|
828
|
+
);
|
|
829
|
+
}
|
|
830
|
+
if (hasResult) {
|
|
831
|
+
const descriptor2 = Object.getOwnPropertyDescriptor(result, "result");
|
|
832
|
+
if (descriptor2 === void 0 || !("value" in descriptor2) || typeof descriptor2.value !== "string") {
|
|
833
|
+
throw new TypeError("Tool output middleware result must be a string.");
|
|
834
|
+
}
|
|
835
|
+
return { result: descriptor2.value };
|
|
836
|
+
}
|
|
837
|
+
const descriptor = Object.getOwnPropertyDescriptor(result, "structuredResult");
|
|
838
|
+
if (descriptor === void 0 || !("value" in descriptor)) {
|
|
839
|
+
throw new TypeError("Tool output middleware structuredResult must be valid tool content.");
|
|
840
|
+
}
|
|
841
|
+
const normalized = normalizeToolResultOutput(ToolOutput.content(descriptor.value));
|
|
842
|
+
if (normalized.type !== "content") {
|
|
843
|
+
throw new TypeError("Tool output middleware structuredResult must be valid tool content.");
|
|
844
|
+
}
|
|
845
|
+
return { structuredResult: normalized.value };
|
|
846
|
+
}
|
|
847
|
+
function toolTraceMetadata(tool) {
|
|
848
|
+
if (tool === void 0) {
|
|
849
|
+
return void 0;
|
|
850
|
+
}
|
|
851
|
+
const result = {
|
|
852
|
+
approvalRequired: toolMayRequireApproval(tool.requiresApproval)
|
|
853
|
+
};
|
|
854
|
+
if (isMcpTool(tool)) {
|
|
855
|
+
result.mcpServerName = tool.mcp.serverName;
|
|
856
|
+
result.mcpRemoteName = tool.mcp.remoteName;
|
|
857
|
+
}
|
|
858
|
+
return result;
|
|
859
|
+
}
|
|
860
|
+
function toolErrorArgs(turn, toolCall, internalCallId, args, error) {
|
|
861
|
+
let observerArgs = {
|
|
862
|
+
turn,
|
|
863
|
+
toolCall,
|
|
864
|
+
toolName: toolCall.toolName,
|
|
865
|
+
internalCallId,
|
|
866
|
+
args,
|
|
867
|
+
error
|
|
868
|
+
};
|
|
869
|
+
if (toolCall.callId !== void 0) {
|
|
870
|
+
observerArgs = { ...observerArgs, toolCallId: toolCall.callId };
|
|
871
|
+
}
|
|
872
|
+
return observerArgs;
|
|
873
|
+
}
|
|
874
|
+
var ToolObserverScope = class {
|
|
875
|
+
constructor(observers) {
|
|
876
|
+
this.observers = observers;
|
|
877
|
+
}
|
|
878
|
+
observers;
|
|
879
|
+
terminal = false;
|
|
880
|
+
streamEvent(args) {
|
|
881
|
+
return this.observers?.streamEvent(args);
|
|
882
|
+
}
|
|
883
|
+
async end(args) {
|
|
884
|
+
if (this.terminal) return;
|
|
885
|
+
this.terminal = true;
|
|
886
|
+
await this.observers?.end(args);
|
|
887
|
+
}
|
|
888
|
+
async suspend(args) {
|
|
889
|
+
if (this.terminal) return;
|
|
890
|
+
this.terminal = true;
|
|
891
|
+
await this.observers?.suspend(args);
|
|
892
|
+
}
|
|
893
|
+
async error(args) {
|
|
894
|
+
if (this.terminal) return;
|
|
895
|
+
this.terminal = true;
|
|
896
|
+
await this.observers?.error(args);
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
function toolOutputToText(output) {
|
|
900
|
+
switch (output.type) {
|
|
901
|
+
case "text":
|
|
902
|
+
case "error-text":
|
|
903
|
+
return output.value;
|
|
904
|
+
case "json":
|
|
905
|
+
case "error-json":
|
|
906
|
+
return JSON.stringify(output.value);
|
|
907
|
+
case "content":
|
|
908
|
+
return toolResultContentToText(output.value);
|
|
909
|
+
case "execution-denied":
|
|
910
|
+
return output.reason ?? "Tool execution was denied.";
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
function toolOutputToStructuredResult(output) {
|
|
914
|
+
return output.type === "content" ? output.value : void 0;
|
|
915
|
+
}
|
|
916
|
+
function agentToolEventPayload(toolCall, internalCallId, event) {
|
|
917
|
+
if (typeof event.agentId !== "string" || event.agentId.length === 0) {
|
|
918
|
+
return void 0;
|
|
919
|
+
}
|
|
920
|
+
const payload = {
|
|
921
|
+
type: "agent_tool_event",
|
|
922
|
+
toolName: toolCall.toolName,
|
|
923
|
+
internalCallId,
|
|
924
|
+
agentId: event.agentId,
|
|
925
|
+
event: event.event
|
|
926
|
+
};
|
|
927
|
+
if (toolCall.callId !== void 0) {
|
|
928
|
+
payload.toolCallId = toolCall.callId;
|
|
929
|
+
}
|
|
930
|
+
if (event.agentName !== void 0) {
|
|
931
|
+
payload.agentName = event.agentName;
|
|
932
|
+
}
|
|
933
|
+
return payload;
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
export {
|
|
937
|
+
ToolCallExecutor
|
|
938
|
+
};
|
|
939
|
+
//# sourceMappingURL=chunk-J4SINPUA.js.map
|