@anvia/core 1.1.2 → 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 +2 -2
- 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,175 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PipelineObserverDispatchError
|
|
3
|
+
} from "./chunk-R6722CIU.js";
|
|
4
|
+
import {
|
|
5
|
+
observerSnapshot
|
|
6
|
+
} from "./chunk-H3H74RWJ.js";
|
|
7
|
+
|
|
8
|
+
// src/pipeline/observability.ts
|
|
9
|
+
function resolvePrimaryTrace(observers, primaryTrace) {
|
|
10
|
+
if (primaryTrace === void 0) return void 0;
|
|
11
|
+
const primary = observers.find((entry) => entry.name === primaryTrace);
|
|
12
|
+
return primary?.observer.trace === void 0 ? void 0 : Object.freeze({ observer: primary.name, ...primary.observer.trace });
|
|
13
|
+
}
|
|
14
|
+
function snapshotPipelineObservability(observability) {
|
|
15
|
+
if (observability === void 0) return void 0;
|
|
16
|
+
const observers = {};
|
|
17
|
+
for (const [name, observer] of Object.entries(observability.observers)) {
|
|
18
|
+
if (name.trim().length === 0) {
|
|
19
|
+
throw new TypeError("Pipeline observer names must not be empty.");
|
|
20
|
+
}
|
|
21
|
+
if (typeof observer !== "object" || observer === null || typeof observer.startRun !== "function") {
|
|
22
|
+
throw new TypeError(`Pipeline observer "${name}" must implement startRun().`);
|
|
23
|
+
}
|
|
24
|
+
observers[name] = observer;
|
|
25
|
+
}
|
|
26
|
+
if (observability.primaryTrace !== void 0 && !(observability.primaryTrace in observers)) {
|
|
27
|
+
throw new TypeError(
|
|
28
|
+
`Pipeline primaryTrace "${observability.primaryTrace}" must name a configured observer.`
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
const errorPolicy = observability.errorPolicy ?? "ignore";
|
|
32
|
+
if (errorPolicy !== "ignore" && errorPolicy !== "throw") {
|
|
33
|
+
throw new TypeError('Pipeline observability.errorPolicy must be "ignore" or "throw".');
|
|
34
|
+
}
|
|
35
|
+
const snapshot = {
|
|
36
|
+
observers: Object.freeze(observers),
|
|
37
|
+
errorPolicy,
|
|
38
|
+
...observability.primaryTrace === void 0 ? {} : { primaryTrace: observability.primaryTrace }
|
|
39
|
+
};
|
|
40
|
+
return Object.freeze(snapshot);
|
|
41
|
+
}
|
|
42
|
+
async function startPipelineRunObservers(observers, args, options) {
|
|
43
|
+
const runObservers = [];
|
|
44
|
+
const failures = [];
|
|
45
|
+
for (const [name, observer] of Object.entries(observers)) {
|
|
46
|
+
try {
|
|
47
|
+
const runObserver = await observer.startRun(observerSnapshot(args));
|
|
48
|
+
if (runObserver !== void 0) {
|
|
49
|
+
runObservers.push({ name, observer: runObserver, terminal: false });
|
|
50
|
+
}
|
|
51
|
+
} catch (error) {
|
|
52
|
+
failures.push({ observer: name, error });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (options.errorPolicy === "throw" && failures.length > 0) {
|
|
56
|
+
const startupError = new PipelineObserverDispatchError("startRun", failures);
|
|
57
|
+
const cleanupFailures = await terminateObservers(
|
|
58
|
+
runObservers,
|
|
59
|
+
(observer) => observer.error?.(
|
|
60
|
+
observerSnapshot({
|
|
61
|
+
runId: args.runId,
|
|
62
|
+
pipelineId: args.pipelineId,
|
|
63
|
+
status: "failed",
|
|
64
|
+
error: startupError,
|
|
65
|
+
durationMs: 0
|
|
66
|
+
})
|
|
67
|
+
)
|
|
68
|
+
);
|
|
69
|
+
throw new PipelineObserverDispatchError("startRun", [...failures, ...cleanupFailures]);
|
|
70
|
+
}
|
|
71
|
+
return new ActivePipelineRunObservers(runObservers, options);
|
|
72
|
+
}
|
|
73
|
+
var ActivePipelineRunObservers = class {
|
|
74
|
+
constructor(observers, options) {
|
|
75
|
+
this.observers = observers;
|
|
76
|
+
this.options = options;
|
|
77
|
+
this.trace = resolvePrimaryTrace(observers, options.primaryTrace);
|
|
78
|
+
}
|
|
79
|
+
observers;
|
|
80
|
+
options;
|
|
81
|
+
trace;
|
|
82
|
+
async startStage(args) {
|
|
83
|
+
const stageObservers = [];
|
|
84
|
+
const failures = [];
|
|
85
|
+
for (const entry of this.observers) {
|
|
86
|
+
if (entry.observer.startStage === void 0) continue;
|
|
87
|
+
try {
|
|
88
|
+
const observer = await entry.observer.startStage(observerSnapshot(args));
|
|
89
|
+
if (observer !== void 0) {
|
|
90
|
+
stageObservers.push({ name: entry.name, observer, terminal: false });
|
|
91
|
+
}
|
|
92
|
+
} catch (error) {
|
|
93
|
+
failures.push({ observer: entry.name, error });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (this.options.errorPolicy === "throw" && failures.length > 0) {
|
|
97
|
+
const startupError = new PipelineObserverDispatchError("startStage", failures);
|
|
98
|
+
const cleanupFailures = await terminateObservers(
|
|
99
|
+
stageObservers,
|
|
100
|
+
(observer) => observer.error?.(observerSnapshot({ ...args, error: startupError, durationMs: 0 }))
|
|
101
|
+
);
|
|
102
|
+
throw new PipelineObserverDispatchError("startStage", [...failures, ...cleanupFailures]);
|
|
103
|
+
}
|
|
104
|
+
return new ActivePipelineStageObservers(stageObservers, this.options);
|
|
105
|
+
}
|
|
106
|
+
async end(args) {
|
|
107
|
+
await dispatchTerminalObservers(
|
|
108
|
+
this.observers,
|
|
109
|
+
"end",
|
|
110
|
+
(observer) => observer.end(observerSnapshot(args)),
|
|
111
|
+
this.options.errorPolicy
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
async error(args) {
|
|
115
|
+
await dispatchTerminalObservers(
|
|
116
|
+
this.observers,
|
|
117
|
+
"error",
|
|
118
|
+
(observer) => observer.error?.(observerSnapshot(args)),
|
|
119
|
+
"ignore"
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
var ActivePipelineStageObservers = class {
|
|
124
|
+
constructor(observers, options) {
|
|
125
|
+
this.observers = observers;
|
|
126
|
+
this.options = options;
|
|
127
|
+
this.trace = resolvePrimaryTrace(observers, options.primaryTrace);
|
|
128
|
+
}
|
|
129
|
+
observers;
|
|
130
|
+
options;
|
|
131
|
+
trace;
|
|
132
|
+
async end(args) {
|
|
133
|
+
await dispatchTerminalObservers(
|
|
134
|
+
this.observers,
|
|
135
|
+
"stage.end",
|
|
136
|
+
(observer) => observer.end(observerSnapshot(args)),
|
|
137
|
+
this.options.errorPolicy
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
async error(args) {
|
|
141
|
+
await dispatchTerminalObservers(
|
|
142
|
+
this.observers,
|
|
143
|
+
"stage.error",
|
|
144
|
+
(observer) => observer.error?.(observerSnapshot(args)),
|
|
145
|
+
"ignore"
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
async function dispatchTerminalObservers(observers, phase, dispatch, errorPolicy) {
|
|
150
|
+
const failures = await terminateObservers(observers, dispatch);
|
|
151
|
+
if (errorPolicy === "throw" && failures.length > 0) {
|
|
152
|
+
throw new PipelineObserverDispatchError(phase, failures);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
async function terminateObservers(observers, dispatch) {
|
|
156
|
+
const failures = [];
|
|
157
|
+
for (const entry of observers) {
|
|
158
|
+
if (entry.terminal) continue;
|
|
159
|
+
entry.terminal = true;
|
|
160
|
+
try {
|
|
161
|
+
await dispatch(entry.observer);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
failures.push({ observer: entry.name, error });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return failures;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export {
|
|
170
|
+
snapshotPipelineObservability,
|
|
171
|
+
startPipelineRunObservers,
|
|
172
|
+
ActivePipelineRunObservers,
|
|
173
|
+
ActivePipelineStageObservers
|
|
174
|
+
};
|
|
175
|
+
//# sourceMappingURL=chunk-ETYB5JO6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/pipeline/observability.ts"],"sourcesContent":["import { observerSnapshot } from \"../observability/snapshot\";\nimport { PipelineObserverDispatchError, type PipelineObserverFailure } from \"./errors\";\nimport type {\n PipelineObservabilityOptions,\n PipelineObserverErrorPolicy,\n PipelineObserverMap,\n PipelineObserverTraceInfo,\n PipelineRunEndArgs,\n PipelineRunErrorArgs,\n PipelineRunObservation,\n PipelineRunStartArgs,\n PipelineStageEndArgs,\n PipelineStageErrorArgs,\n PipelineStageObservation,\n PipelineStageStartArgs,\n PipelineTraceInfo,\n} from \"./types\";\n\ntype NamedObserver<T> = {\n readonly name: string;\n readonly observer: T;\n};\n\ntype ActiveNamedObserver<T> = NamedObserver<T> & {\n terminal: boolean;\n};\n\nfunction resolvePrimaryTrace<T extends { readonly trace?: PipelineObserverTraceInfo | undefined }>(\n observers: readonly ActiveNamedObserver<T>[],\n primaryTrace: string | undefined,\n): PipelineTraceInfo | undefined {\n if (primaryTrace === undefined) return undefined;\n const primary = observers.find((entry) => entry.name === primaryTrace);\n return primary?.observer.trace === undefined\n ? undefined\n : Object.freeze({ observer: primary.name, ...primary.observer.trace });\n}\n\nexport function snapshotPipelineObservability(\n observability: PipelineObservabilityOptions | undefined,\n): PipelineObservabilityOptions | undefined {\n if (observability === undefined) return undefined;\n const observers: Record<string, PipelineObserverMap[string]> = {};\n for (const [name, observer] of Object.entries(observability.observers)) {\n if (name.trim().length === 0) {\n throw new TypeError(\"Pipeline observer names must not be empty.\");\n }\n if (\n typeof observer !== \"object\" ||\n observer === null ||\n typeof observer.startRun !== \"function\"\n ) {\n throw new TypeError(`Pipeline observer \"${name}\" must implement startRun().`);\n }\n observers[name] = observer;\n }\n if (observability.primaryTrace !== undefined && !(observability.primaryTrace in observers)) {\n throw new TypeError(\n `Pipeline primaryTrace \"${observability.primaryTrace}\" must name a configured observer.`,\n );\n }\n const errorPolicy = observability.errorPolicy ?? \"ignore\";\n if (errorPolicy !== \"ignore\" && errorPolicy !== \"throw\") {\n throw new TypeError('Pipeline observability.errorPolicy must be \"ignore\" or \"throw\".');\n }\n const snapshot: PipelineObservabilityOptions = {\n observers: Object.freeze(observers),\n errorPolicy,\n ...(observability.primaryTrace === undefined\n ? {}\n : { primaryTrace: observability.primaryTrace }),\n };\n return Object.freeze(snapshot);\n}\n\nexport async function startPipelineRunObservers(\n observers: PipelineObserverMap,\n args: PipelineRunStartArgs,\n options: {\n readonly primaryTrace?: string | undefined;\n readonly errorPolicy: PipelineObserverErrorPolicy;\n },\n): Promise<ActivePipelineRunObservers> {\n const runObservers: ActiveNamedObserver<PipelineRunObservation>[] = [];\n const failures: PipelineObserverFailure[] = [];\n for (const [name, observer] of Object.entries(observers)) {\n try {\n const runObserver = await observer.startRun(observerSnapshot(args));\n if (runObserver !== undefined) {\n runObservers.push({ name, observer: runObserver, terminal: false });\n }\n } catch (error) {\n failures.push({ observer: name, error });\n }\n }\n if (options.errorPolicy === \"throw\" && failures.length > 0) {\n const startupError = new PipelineObserverDispatchError(\"startRun\", failures);\n const cleanupFailures = await terminateObservers(runObservers, (observer) =>\n observer.error?.(\n observerSnapshot({\n runId: args.runId,\n pipelineId: args.pipelineId,\n status: \"failed\",\n error: startupError,\n durationMs: 0,\n }),\n ),\n );\n throw new PipelineObserverDispatchError(\"startRun\", [...failures, ...cleanupFailures]);\n }\n return new ActivePipelineRunObservers(runObservers, options);\n}\n\nexport class ActivePipelineRunObservers {\n readonly trace: PipelineTraceInfo | undefined;\n\n constructor(\n private readonly observers: readonly ActiveNamedObserver<PipelineRunObservation>[],\n private readonly options: {\n readonly primaryTrace?: string | undefined;\n readonly errorPolicy: PipelineObserverErrorPolicy;\n },\n ) {\n this.trace = resolvePrimaryTrace(observers, options.primaryTrace);\n }\n\n async startStage(args: PipelineStageStartArgs): Promise<ActivePipelineStageObservers> {\n const stageObservers: ActiveNamedObserver<PipelineStageObservation>[] = [];\n const failures: PipelineObserverFailure[] = [];\n for (const entry of this.observers) {\n if (entry.observer.startStage === undefined) continue;\n try {\n const observer = await entry.observer.startStage(observerSnapshot(args));\n if (observer !== undefined) {\n stageObservers.push({ name: entry.name, observer, terminal: false });\n }\n } catch (error) {\n failures.push({ observer: entry.name, error });\n }\n }\n if (this.options.errorPolicy === \"throw\" && failures.length > 0) {\n const startupError = new PipelineObserverDispatchError(\"startStage\", failures);\n const cleanupFailures = await terminateObservers(stageObservers, (observer) =>\n observer.error?.(observerSnapshot({ ...args, error: startupError, durationMs: 0 })),\n );\n throw new PipelineObserverDispatchError(\"startStage\", [...failures, ...cleanupFailures]);\n }\n return new ActivePipelineStageObservers(stageObservers, this.options);\n }\n\n async end(args: PipelineRunEndArgs): Promise<void> {\n await dispatchTerminalObservers(\n this.observers,\n \"end\",\n (observer) => observer.end(observerSnapshot(args)),\n this.options.errorPolicy,\n );\n }\n\n async error(args: PipelineRunErrorArgs): Promise<void> {\n await dispatchTerminalObservers(\n this.observers,\n \"error\",\n (observer) => observer.error?.(observerSnapshot(args)),\n \"ignore\",\n );\n }\n}\n\nexport class ActivePipelineStageObservers {\n readonly trace: PipelineTraceInfo | undefined;\n\n constructor(\n private readonly observers: readonly ActiveNamedObserver<PipelineStageObservation>[],\n private readonly options: {\n readonly primaryTrace?: string | undefined;\n readonly errorPolicy: PipelineObserverErrorPolicy;\n },\n ) {\n this.trace = resolvePrimaryTrace(observers, options.primaryTrace);\n }\n\n async end(args: PipelineStageEndArgs): Promise<void> {\n await dispatchTerminalObservers(\n this.observers,\n \"stage.end\",\n (observer) => observer.end(observerSnapshot(args)),\n this.options.errorPolicy,\n );\n }\n\n async error(args: PipelineStageErrorArgs): Promise<void> {\n await dispatchTerminalObservers(\n this.observers,\n \"stage.error\",\n (observer) => observer.error?.(observerSnapshot(args)),\n \"ignore\",\n );\n }\n}\n\nasync function dispatchTerminalObservers<T>(\n observers: readonly ActiveNamedObserver<T>[],\n phase: string,\n dispatch: (observer: T) => void | Promise<void> | undefined,\n errorPolicy: PipelineObserverErrorPolicy,\n): Promise<void> {\n const failures = await terminateObservers(observers, dispatch);\n if (errorPolicy === \"throw\" && failures.length > 0) {\n throw new PipelineObserverDispatchError(phase, failures);\n }\n}\n\nasync function terminateObservers<T>(\n observers: readonly ActiveNamedObserver<T>[],\n dispatch: (observer: T) => void | Promise<void> | undefined,\n): Promise<PipelineObserverFailure[]> {\n const failures: PipelineObserverFailure[] = [];\n for (const entry of observers) {\n if (entry.terminal) continue;\n entry.terminal = true;\n try {\n await dispatch(entry.observer);\n } catch (error) {\n failures.push({ observer: entry.name, error });\n }\n }\n return failures;\n}\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/internal/async-queue.ts
|
|
2
|
+
function createAsyncQueue() {
|
|
3
|
+
const values = [];
|
|
4
|
+
const waiters = [];
|
|
5
|
+
let closed = false;
|
|
6
|
+
let error;
|
|
7
|
+
function flush() {
|
|
8
|
+
while (waiters.length > 0 && values.length > 0) {
|
|
9
|
+
const waiter = waiters.shift();
|
|
10
|
+
const value = values.shift();
|
|
11
|
+
if (waiter !== void 0) {
|
|
12
|
+
waiter.resolve({ value, done: false });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (values.length > 0 || waiters.length === 0 || !closed) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
while (waiters.length > 0) {
|
|
19
|
+
const waiter = waiters.shift();
|
|
20
|
+
if (waiter === void 0) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (error !== void 0) {
|
|
24
|
+
waiter.reject(error);
|
|
25
|
+
} else {
|
|
26
|
+
waiter.resolve({ value: void 0, done: true });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
enqueue(value) {
|
|
32
|
+
if (closed) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
values.push(value);
|
|
36
|
+
flush();
|
|
37
|
+
},
|
|
38
|
+
close(options) {
|
|
39
|
+
if (options?.discardPending) values.length = 0;
|
|
40
|
+
closed = true;
|
|
41
|
+
flush();
|
|
42
|
+
},
|
|
43
|
+
throw(thrown, options) {
|
|
44
|
+
if (options?.discardPending) values.length = 0;
|
|
45
|
+
closed = true;
|
|
46
|
+
error = thrown;
|
|
47
|
+
flush();
|
|
48
|
+
},
|
|
49
|
+
[Symbol.asyncIterator]() {
|
|
50
|
+
return {
|
|
51
|
+
next() {
|
|
52
|
+
if (values.length > 0) {
|
|
53
|
+
const value = values.shift();
|
|
54
|
+
return Promise.resolve({ value, done: false });
|
|
55
|
+
}
|
|
56
|
+
if (error !== void 0) {
|
|
57
|
+
return Promise.reject(error);
|
|
58
|
+
}
|
|
59
|
+
if (closed) {
|
|
60
|
+
return Promise.resolve({ value: void 0, done: true });
|
|
61
|
+
}
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
waiters.push({ resolve, reject });
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export {
|
|
72
|
+
createAsyncQueue
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=chunk-EZR5AV3J.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal/async-queue.ts"],"sourcesContent":["type AsyncQueueWaiter<T> = {\n resolve: (result: IteratorResult<T>) => void;\n reject: (error: unknown) => void;\n};\n\ntype QueueCloseOptions = { discardPending?: boolean };\n\nexport type AsyncQueue<T> = AsyncIterable<T> & {\n enqueue(value: T): void;\n close(options?: QueueCloseOptions): void;\n throw(error: unknown, options?: QueueCloseOptions): void;\n};\n\nexport function createAsyncQueue<T>(): AsyncQueue<T> {\n const values: T[] = [];\n const waiters: AsyncQueueWaiter<T>[] = [];\n let closed = false;\n let error: unknown;\n\n function flush(): void {\n while (waiters.length > 0 && values.length > 0) {\n const waiter = waiters.shift();\n const value = values.shift() as T;\n if (waiter !== undefined) {\n waiter.resolve({ value, done: false });\n }\n }\n\n if (values.length > 0 || waiters.length === 0 || !closed) {\n return;\n }\n\n while (waiters.length > 0) {\n const waiter = waiters.shift();\n if (waiter === undefined) {\n continue;\n }\n if (error !== undefined) {\n waiter.reject(error);\n } else {\n waiter.resolve({ value: undefined, done: true });\n }\n }\n }\n\n return {\n enqueue(value: T): void {\n if (closed) {\n return;\n }\n values.push(value);\n flush();\n },\n close(options?: QueueCloseOptions): void {\n if (options?.discardPending) values.length = 0;\n closed = true;\n flush();\n },\n throw(thrown: unknown, options?: QueueCloseOptions): void {\n if (options?.discardPending) values.length = 0;\n closed = true;\n error = thrown;\n flush();\n },\n [Symbol.asyncIterator](): AsyncIterator<T> {\n return {\n next(): Promise<IteratorResult<T>> {\n if (values.length > 0) {\n const value = values.shift() as T;\n return Promise.resolve({ value, done: false });\n }\n if (error !== undefined) {\n return Promise.reject(error);\n }\n if (closed) {\n return Promise.resolve({ value: undefined, done: true });\n }\n return new Promise((resolve, reject) => {\n waiters.push({ resolve, reject });\n });\n },\n };\n },\n };\n}\n"],"mappings":";AAaO,SAAS,mBAAqC;AACnD,QAAM,SAAc,CAAC;AACrB,QAAM,UAAiC,CAAC;AACxC,MAAI,SAAS;AACb,MAAI;AAEJ,WAAS,QAAc;AACrB,WAAO,QAAQ,SAAS,KAAK,OAAO,SAAS,GAAG;AAC9C,YAAM,SAAS,QAAQ,MAAM;AAC7B,YAAM,QAAQ,OAAO,MAAM;AAC3B,UAAI,WAAW,QAAW;AACxB,eAAO,QAAQ,EAAE,OAAO,MAAM,MAAM,CAAC;AAAA,MACvC;AAAA,IACF;AAEA,QAAI,OAAO,SAAS,KAAK,QAAQ,WAAW,KAAK,CAAC,QAAQ;AACxD;AAAA,IACF;AAEA,WAAO,QAAQ,SAAS,GAAG;AACzB,YAAM,SAAS,QAAQ,MAAM;AAC7B,UAAI,WAAW,QAAW;AACxB;AAAA,MACF;AACA,UAAI,UAAU,QAAW;AACvB,eAAO,OAAO,KAAK;AAAA,MACrB,OAAO;AACL,eAAO,QAAQ,EAAE,OAAO,QAAW,MAAM,KAAK,CAAC;AAAA,MACjD;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,QAAQ,OAAgB;AACtB,UAAI,QAAQ;AACV;AAAA,MACF;AACA,aAAO,KAAK,KAAK;AACjB,YAAM;AAAA,IACR;AAAA,IACA,MAAM,SAAmC;AACvC,UAAI,SAAS,eAAgB,QAAO,SAAS;AAC7C,eAAS;AACT,YAAM;AAAA,IACR;AAAA,IACA,MAAM,QAAiB,SAAmC;AACxD,UAAI,SAAS,eAAgB,QAAO,SAAS;AAC7C,eAAS;AACT,cAAQ;AACR,YAAM;AAAA,IACR;AAAA,IACA,CAAC,OAAO,aAAa,IAAsB;AACzC,aAAO;AAAA,QACL,OAAmC;AACjC,cAAI,OAAO,SAAS,GAAG;AACrB,kBAAM,QAAQ,OAAO,MAAM;AAC3B,mBAAO,QAAQ,QAAQ,EAAE,OAAO,MAAM,MAAM,CAAC;AAAA,UAC/C;AACA,cAAI,UAAU,QAAW;AACvB,mBAAO,QAAQ,OAAO,KAAK;AAAA,UAC7B;AACA,cAAI,QAAQ;AACV,mBAAO,QAAQ,QAAQ,EAAE,OAAO,QAAW,MAAM,KAAK,CAAC;AAAA,UACzD;AACA,iBAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,oBAAQ,KAAK,EAAE,SAAS,OAAO,CAAC;AAAA,UAClC,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/evals/metric.ts"],"sourcesContent":["import type { EvalMetric } from \"./types\";\n\nexport function defineMetric<Input, Output, Score, Expected, const Name extends string = string>(\n metric: EvalMetric<Input, Output, Score, Expected, Name>,\n): EvalMetric<Input, Output, Score, Expected, Name> {\n return metric;\n}\n"],"mappings":";AAEO,SAAS,aACd,QACkD;AAClD,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createMemoryCompactionSummary,
|
|
3
|
+
cumulativeCompactedMessageCount
|
|
4
|
+
} from "./chunk-HP34GRQX.js";
|
|
5
|
+
import {
|
|
6
|
+
MemoryCompactionConflictError,
|
|
7
|
+
MemoryCompactionError
|
|
8
|
+
} from "./chunk-LQJ4KHMY.js";
|
|
9
|
+
import {
|
|
10
|
+
Usage
|
|
11
|
+
} from "./chunk-IDNL6IH4.js";
|
|
12
|
+
import {
|
|
13
|
+
throwIfAborted
|
|
14
|
+
} from "./chunk-USRKPEQN.js";
|
|
15
|
+
|
|
16
|
+
// src/internal/agent-runtime/memory.ts
|
|
17
|
+
var AgentRunMemory = class {
|
|
18
|
+
constructor(agent, memoryScope, initialHistory) {
|
|
19
|
+
this.agent = agent;
|
|
20
|
+
this.memoryScope = memoryScope;
|
|
21
|
+
this.initialHistory = initialHistory;
|
|
22
|
+
}
|
|
23
|
+
agent;
|
|
24
|
+
memoryScope;
|
|
25
|
+
initialHistory;
|
|
26
|
+
memoryPolicy() {
|
|
27
|
+
return this.memory()?.savePolicy;
|
|
28
|
+
}
|
|
29
|
+
pendingTurnMessages(newMessages) {
|
|
30
|
+
return this.memoryPolicy() === "turn" ? [...newMessages] : [];
|
|
31
|
+
}
|
|
32
|
+
async prepareHistory(runId, incomingMessages, abortSignal) {
|
|
33
|
+
const memory = this.memory();
|
|
34
|
+
if (memory === void 0 || this.memoryScope === void 0) {
|
|
35
|
+
return {
|
|
36
|
+
history: this.initialHistory,
|
|
37
|
+
usage: Usage.empty()
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const preparation = await this.prepareStoredHistory(
|
|
41
|
+
memory,
|
|
42
|
+
runId,
|
|
43
|
+
incomingMessages,
|
|
44
|
+
abortSignal
|
|
45
|
+
);
|
|
46
|
+
const memoryHistory = preparation.history;
|
|
47
|
+
const chatHistory = [...memoryHistory, ...this.initialHistory];
|
|
48
|
+
return {
|
|
49
|
+
...preparation,
|
|
50
|
+
history: chatHistory
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async compact(runId, abortSignal) {
|
|
54
|
+
const memory = this.memory();
|
|
55
|
+
const scope = this.memoryScope;
|
|
56
|
+
if (memory === void 0 || scope === void 0) {
|
|
57
|
+
throw new TypeError("Manual memory compaction requires an Agent with configured memory.");
|
|
58
|
+
}
|
|
59
|
+
if (memory.compaction === void 0 || memory.store.compaction === void 0) {
|
|
60
|
+
throw new TypeError("Manual memory compaction requires a configured compaction policy.");
|
|
61
|
+
}
|
|
62
|
+
const preparation = await this.prepareStoredHistory(memory, runId, [], abortSignal, true);
|
|
63
|
+
if (preparation.compaction !== void 0) {
|
|
64
|
+
return { type: "compacted", ...preparation.compaction };
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
type: "skipped",
|
|
68
|
+
reason: "nothing_to_compact",
|
|
69
|
+
originalMessageCount: preparation.history.length,
|
|
70
|
+
originalTokenCount: preparation.originalTokenCount ?? await countTokens(memory.compaction.tokenCounter, preparation.history)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async commitAcceptedInput(runId, messages) {
|
|
74
|
+
const memory = this.memory();
|
|
75
|
+
if (memory === void 0 || this.memoryScope === void 0 || memory.savePolicy !== "message" || messages.length === 0) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
await memory.store.append({
|
|
79
|
+
scope: this.memoryScope,
|
|
80
|
+
runId,
|
|
81
|
+
turn: 1,
|
|
82
|
+
messages
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
async commitMessages(runId, turn, messages, pendingTurnMessages) {
|
|
86
|
+
const memory = this.memory();
|
|
87
|
+
if (memory === void 0 || this.memoryScope === void 0 || messages.length === 0) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (memory.savePolicy === "message") {
|
|
91
|
+
await memory.store.append({
|
|
92
|
+
scope: this.memoryScope,
|
|
93
|
+
runId,
|
|
94
|
+
turn,
|
|
95
|
+
messages
|
|
96
|
+
});
|
|
97
|
+
} else if (memory.savePolicy === "turn") {
|
|
98
|
+
pendingTurnMessages.push(...messages);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async commitCompletedTurn(runId, turn, pendingTurnMessages) {
|
|
102
|
+
const memory = this.memory();
|
|
103
|
+
if (memory === void 0 || this.memoryScope === void 0 || memory.savePolicy !== "turn" || pendingTurnMessages.length === 0) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
await memory.store.append({
|
|
107
|
+
scope: this.memoryScope,
|
|
108
|
+
runId,
|
|
109
|
+
turn,
|
|
110
|
+
messages: [...pendingTurnMessages]
|
|
111
|
+
});
|
|
112
|
+
pendingTurnMessages.length = 0;
|
|
113
|
+
}
|
|
114
|
+
async commitCompletedRun(runId, turn, newMessages, pendingTurnMessages) {
|
|
115
|
+
await this.commitCompletedTurn(runId, turn, pendingTurnMessages);
|
|
116
|
+
const memory = this.memory();
|
|
117
|
+
if (memory === void 0 || this.memoryScope === void 0 || memory.savePolicy !== "run") {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
await memory.store.append({
|
|
121
|
+
scope: this.memoryScope,
|
|
122
|
+
runId,
|
|
123
|
+
turn,
|
|
124
|
+
messages: [...newMessages]
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
async recordError(runId, error, newMessages) {
|
|
128
|
+
const memory = this.memory();
|
|
129
|
+
if (memory === void 0 || this.memoryScope === void 0) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
await memory.store.recordError?.({
|
|
133
|
+
scope: this.memoryScope,
|
|
134
|
+
runId,
|
|
135
|
+
error,
|
|
136
|
+
messages: [...newMessages]
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
memory() {
|
|
140
|
+
return this.memoryScope === void 0 ? void 0 : this.agent.memory;
|
|
141
|
+
}
|
|
142
|
+
async prepareStoredHistory(memory, runId, incomingMessages, abortSignal, force = false) {
|
|
143
|
+
const scope = this.memoryScope;
|
|
144
|
+
if (scope === void 0) {
|
|
145
|
+
return { history: [], usage: Usage.empty() };
|
|
146
|
+
}
|
|
147
|
+
const options = memory.compaction;
|
|
148
|
+
const capability = memory.store.compaction;
|
|
149
|
+
if (options === void 0 || capability === void 0) {
|
|
150
|
+
return {
|
|
151
|
+
history: await memory.store.load({ scope }),
|
|
152
|
+
usage: Usage.empty()
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
let usage = Usage.empty();
|
|
156
|
+
const maxAttempts = options.conflictRetries === false ? 1 : options.conflictRetries.maxAttempts;
|
|
157
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
158
|
+
throwIfAborted(abortSignal);
|
|
159
|
+
const snapshot = await capability.snapshot({ scope });
|
|
160
|
+
throwIfAborted(abortSignal);
|
|
161
|
+
const selection = await selectCompactionPrefix(
|
|
162
|
+
snapshot.messages,
|
|
163
|
+
incomingMessages,
|
|
164
|
+
options.trigger.afterTokens,
|
|
165
|
+
options.retention.recentTokens,
|
|
166
|
+
options.tokenCounter,
|
|
167
|
+
force
|
|
168
|
+
);
|
|
169
|
+
throwIfAborted(abortSignal);
|
|
170
|
+
const compactedMessageCount = selection.compactedMessageCount;
|
|
171
|
+
if (compactedMessageCount === 0) {
|
|
172
|
+
return {
|
|
173
|
+
history: snapshot.messages,
|
|
174
|
+
usage,
|
|
175
|
+
originalTokenCount: selection.originalTokenCount
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
const prefix = snapshot.messages.slice(0, compactedMessageCount);
|
|
179
|
+
let result;
|
|
180
|
+
try {
|
|
181
|
+
result = await options.compactor({
|
|
182
|
+
scope,
|
|
183
|
+
messages: prefix,
|
|
184
|
+
abortSignal
|
|
185
|
+
});
|
|
186
|
+
} catch (error) {
|
|
187
|
+
throw remappedCompactorError(error, usage);
|
|
188
|
+
}
|
|
189
|
+
if (result.usage !== void 0) {
|
|
190
|
+
usage = Usage.add(usage, result.usage);
|
|
191
|
+
}
|
|
192
|
+
if (typeof result?.summary !== "string") {
|
|
193
|
+
throw new MemoryCompactionError("Memory compactor must return a summary string.", {
|
|
194
|
+
usage
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
const summaryText = result.summary.trim();
|
|
198
|
+
if (summaryText.length === 0) {
|
|
199
|
+
throw new MemoryCompactionError("Memory compactor returned an empty summary.", {
|
|
200
|
+
usage
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
const summary = createMemoryCompactionSummary(
|
|
204
|
+
summaryText,
|
|
205
|
+
cumulativeCompactedMessageCount(prefix)
|
|
206
|
+
);
|
|
207
|
+
const retained = snapshot.messages.slice(compactedMessageCount);
|
|
208
|
+
let resultTokenCount;
|
|
209
|
+
try {
|
|
210
|
+
resultTokenCount = await countTokens(options.tokenCounter, [summary, ...retained]);
|
|
211
|
+
} catch (error) {
|
|
212
|
+
throw remappedCompactorError(error, usage);
|
|
213
|
+
}
|
|
214
|
+
throwIfAborted(abortSignal);
|
|
215
|
+
let replacement;
|
|
216
|
+
try {
|
|
217
|
+
replacement = await capability.replacePrefix({
|
|
218
|
+
scope,
|
|
219
|
+
revision: snapshot.revision,
|
|
220
|
+
messageCount: compactedMessageCount,
|
|
221
|
+
replacement: summary,
|
|
222
|
+
runId: `memory-compaction:${runId}:${attempt}`
|
|
223
|
+
});
|
|
224
|
+
} catch (error) {
|
|
225
|
+
throw new MemoryCompactionError("Memory compaction prefix replacement failed.", {
|
|
226
|
+
cause: error,
|
|
227
|
+
usage
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
if (replacement.status === "committed") {
|
|
231
|
+
return {
|
|
232
|
+
history: [summary, ...retained],
|
|
233
|
+
usage,
|
|
234
|
+
compaction: {
|
|
235
|
+
originalMessageCount: snapshot.messages.length,
|
|
236
|
+
compactedMessageCount,
|
|
237
|
+
retainedMessageCount: retained.length,
|
|
238
|
+
originalTokenCount: selection.originalTokenCount,
|
|
239
|
+
compactedTokenCount: selection.compactedTokenCount,
|
|
240
|
+
retainedTokenCount: selection.retainedTokenCount,
|
|
241
|
+
resultTokenCount,
|
|
242
|
+
attempts: attempt,
|
|
243
|
+
usage
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
throwIfAborted(abortSignal);
|
|
248
|
+
}
|
|
249
|
+
throw new MemoryCompactionConflictError(maxAttempts, usage);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
async function selectCompactionPrefix(messages, incomingMessages, afterTokens, recentTokens, tokenCounter, force) {
|
|
253
|
+
const originalTokenCount = await countTokens(tokenCounter, messages);
|
|
254
|
+
const incomingTokenCount = incomingMessages.length === 0 ? 0 : await countTokens(tokenCounter, incomingMessages);
|
|
255
|
+
const none = {
|
|
256
|
+
compactedMessageCount: 0,
|
|
257
|
+
originalTokenCount,
|
|
258
|
+
compactedTokenCount: 0,
|
|
259
|
+
retainedTokenCount: originalTokenCount
|
|
260
|
+
};
|
|
261
|
+
if (!force && originalTokenCount + incomingTokenCount <= afterTokens) {
|
|
262
|
+
return none;
|
|
263
|
+
}
|
|
264
|
+
const userMessageIndexes = messages.flatMap(
|
|
265
|
+
(message, index) => message.role === "user" ? [index] : []
|
|
266
|
+
);
|
|
267
|
+
if (userMessageIndexes.length <= 1) {
|
|
268
|
+
return none;
|
|
269
|
+
}
|
|
270
|
+
const tailTokenCounts = /* @__PURE__ */ new Map();
|
|
271
|
+
const countTail = async (messageIndex) => {
|
|
272
|
+
const cached = tailTokenCounts.get(messageIndex);
|
|
273
|
+
if (cached !== void 0) return cached;
|
|
274
|
+
const count = await countTokens(tokenCounter, messages.slice(messageIndex));
|
|
275
|
+
tailTokenCounts.set(messageIndex, count);
|
|
276
|
+
return count;
|
|
277
|
+
};
|
|
278
|
+
let lower = 0;
|
|
279
|
+
let upper = userMessageIndexes.length - 1;
|
|
280
|
+
let retainedBoundary = upper;
|
|
281
|
+
while (lower <= upper) {
|
|
282
|
+
const middle = Math.floor((lower + upper) / 2);
|
|
283
|
+
const candidate = userMessageIndexes[middle] ?? 0;
|
|
284
|
+
if (await countTail(candidate) <= recentTokens) {
|
|
285
|
+
retainedBoundary = middle;
|
|
286
|
+
upper = middle - 1;
|
|
287
|
+
} else {
|
|
288
|
+
lower = middle + 1;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
const compactedMessageCount = userMessageIndexes[retainedBoundary] ?? 0;
|
|
292
|
+
if (compactedMessageCount === 0) {
|
|
293
|
+
return none;
|
|
294
|
+
}
|
|
295
|
+
const compactedTokenCount = await countTokens(
|
|
296
|
+
tokenCounter,
|
|
297
|
+
messages.slice(0, compactedMessageCount)
|
|
298
|
+
);
|
|
299
|
+
const retainedTokenCount = tailTokenCounts.get(compactedMessageCount) ?? await countTokens(tokenCounter, messages.slice(compactedMessageCount));
|
|
300
|
+
return {
|
|
301
|
+
compactedMessageCount,
|
|
302
|
+
originalTokenCount,
|
|
303
|
+
compactedTokenCount,
|
|
304
|
+
retainedTokenCount
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
async function countTokens(tokenCounter, messages) {
|
|
308
|
+
let count;
|
|
309
|
+
try {
|
|
310
|
+
count = await tokenCounter(messages);
|
|
311
|
+
} catch (error) {
|
|
312
|
+
throw new MemoryCompactionError("Memory token counter failed.", { cause: error });
|
|
313
|
+
}
|
|
314
|
+
if (!Number.isSafeInteger(count) || count < 0) {
|
|
315
|
+
throw new MemoryCompactionError("Memory token counter must return a nonnegative safe integer.");
|
|
316
|
+
}
|
|
317
|
+
return count;
|
|
318
|
+
}
|
|
319
|
+
function remappedCompactorError(error, usage) {
|
|
320
|
+
if (error instanceof MemoryCompactionError) {
|
|
321
|
+
const mergedUsage = error.usage === void 0 ? usage : isEmptyUsage(usage) ? error.usage : Usage.add(usage, error.usage);
|
|
322
|
+
if (mergedUsage === error.usage || error.usage === void 0 && isEmptyUsage(usage)) {
|
|
323
|
+
return error;
|
|
324
|
+
}
|
|
325
|
+
return new MemoryCompactionError(error.message, {
|
|
326
|
+
cause: error,
|
|
327
|
+
usage: mergedUsage
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
return new MemoryCompactionError("Memory compactor failed.", {
|
|
331
|
+
cause: error,
|
|
332
|
+
usage
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
function isEmptyUsage(usage) {
|
|
336
|
+
return usage.inputTokens === 0 && usage.outputTokens === 0 && usage.totalTokens === 0 && usage.cachedInputTokens === 0 && usage.cacheCreationInputTokens === 0;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export {
|
|
340
|
+
AgentRunMemory
|
|
341
|
+
};
|
|
342
|
+
//# sourceMappingURL=chunk-F3E2RLC7.js.map
|