@sixb/core 0.1.7 → 0.1.9
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/dist/actions/delegated-admission.d.ts +24 -0
- package/dist/actions/delegated-admission.d.ts.map +1 -0
- package/dist/actions/descriptor.d.ts +29 -0
- package/dist/actions/descriptor.d.ts.map +1 -0
- package/dist/actions/execution.d.ts +5 -5
- package/dist/actions/execution.d.ts.map +1 -1
- package/dist/actions/index.js +78 -84
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/request.d.ts.map +1 -1
- package/dist/actions/run-authorization.d.ts +20 -0
- package/dist/actions/run-authorization.d.ts.map +1 -0
- package/dist/actions/run-dispatch.d.ts +3 -1
- package/dist/actions/run-dispatch.d.ts.map +1 -1
- package/dist/actions/types/context.d.ts +2 -0
- package/dist/actions/types/context.d.ts.map +1 -1
- package/dist/actions/validation.d.ts +1 -1
- package/dist/actions/validation.d.ts.map +1 -1
- package/dist/actions/worker.js +33 -37
- package/dist/actions/worker.js.map +2 -2
- package/dist/agents/adapters.d.ts +8 -125
- package/dist/agents/adapters.d.ts.map +1 -1
- package/dist/agents/authority.d.ts +1 -1
- package/dist/agents/authority.d.ts.map +1 -1
- package/dist/agents/{context.d.ts → context/entries.d.ts} +3 -3
- package/dist/agents/context/entries.d.ts.map +1 -0
- package/dist/agents/context/index.d.ts +4 -0
- package/dist/agents/context/index.d.ts.map +1 -0
- package/dist/agents/context/index.js +19 -0
- package/dist/agents/{streams.js.map → context/index.js.map} +1 -1
- package/dist/agents/context-model.d.ts +1 -1
- package/dist/agents/context-model.d.ts.map +1 -1
- package/dist/agents/context-resolution.d.ts +1 -1
- package/dist/agents/context-resolution.d.ts.map +1 -1
- package/dist/agents/errors.d.ts +0 -9
- package/dist/agents/errors.d.ts.map +1 -1
- package/dist/agents/execution.d.ts.map +1 -1
- package/dist/agents/identity.d.ts +3 -0
- package/dist/agents/identity.d.ts.map +1 -0
- package/dist/agents/index.d.ts +7 -7
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +193 -205
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/message.d.ts +5 -6
- package/dist/agents/message.d.ts.map +1 -1
- package/dist/agents/model-loop.d.ts +4 -0
- package/dist/agents/model-loop.d.ts.map +1 -1
- package/dist/agents/request.d.ts +1 -1
- package/dist/agents/request.d.ts.map +1 -1
- package/dist/agents/streams/index.d.ts +4 -0
- package/dist/agents/streams/index.d.ts.map +1 -0
- package/dist/agents/streams/index.js +20 -0
- package/dist/{chunk-y64skrwp.js.map → agents/streams/index.js.map} +1 -1
- package/dist/agents/streams/internal.d.ts +3 -0
- package/dist/agents/streams/internal.d.ts.map +1 -0
- package/dist/agents/streams/internal.js +40 -0
- package/dist/agents/{context.js.map → streams/internal.js.map} +1 -1
- package/dist/agents/{streams.d.ts → streams/protocol.d.ts} +5 -5
- package/dist/agents/streams/protocol.d.ts.map +1 -0
- package/dist/agents/tool-definition.d.ts +0 -1
- package/dist/agents/tool-definition.d.ts.map +1 -1
- package/dist/agents/types.d.ts +1 -1
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/agents/validation.d.ts +0 -4
- package/dist/agents/validation.d.ts.map +1 -1
- package/dist/ai-usage/execution.d.ts.map +1 -1
- package/dist/auth/index.d.ts +0 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +96 -105
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/strategy.js +8 -9
- package/dist/auth/strategy.js.map +1 -1
- package/dist/authorization/decision.d.ts +10 -2
- package/dist/authorization/decision.d.ts.map +1 -1
- package/dist/authorization/grant-kinds.d.ts +2 -1
- package/dist/authorization/grant-kinds.d.ts.map +1 -1
- package/dist/authorization/index.d.ts +1 -1
- package/dist/authorization/index.d.ts.map +1 -1
- package/dist/authorization/index.js +51 -53
- package/dist/authorization/index.js.map +1 -1
- package/dist/blob-storage/browser.js +15 -17
- package/dist/blob-storage/browser.js.map +1 -1
- package/dist/blob-storage/index.js +36 -38
- package/dist/blob-storage/index.js.map +1 -1
- package/dist/bootstrap/discovery.d.ts +20 -1
- package/dist/bootstrap/discovery.d.ts.map +1 -1
- package/dist/bootstrap/index.d.ts +2 -2
- package/dist/bootstrap/index.d.ts.map +1 -1
- package/dist/bootstrap/index.js +79 -81
- package/dist/bootstrap/index.js.map +1 -1
- package/dist/bootstrap/ontology-type-manifest.d.ts.map +1 -1
- package/dist/broker/index.js +8 -10
- package/dist/broker/index.js.map +1 -1
- package/dist/{chunk-k34z5rvh.js → chunk-0rdrecsb.js} +18 -18
- package/dist/{chunk-k34z5rvh.js.map → chunk-0rdrecsb.js.map} +2 -2
- package/dist/{chunk-3fqt22c4.js → chunk-0w35wavj.js} +360 -168
- package/dist/chunk-0w35wavj.js.map +14 -0
- package/dist/chunk-0y39rgsb.js +43 -0
- package/dist/{chunk-c15dr03f.js.map → chunk-0y39rgsb.js.map} +2 -2
- package/dist/{chunk-hdz94br2.js → chunk-17kfctj6.js} +23 -13
- package/dist/chunk-17kfctj6.js.map +10 -0
- package/dist/{chunk-e4rvtvpw.js → chunk-1enhpacz.js} +418 -233
- package/dist/chunk-1enhpacz.js.map +34 -0
- package/dist/{chunk-5gd7tpv6.js → chunk-2c4j899j.js} +4 -4
- package/dist/{chunk-5gd7tpv6.js.map → chunk-2c4j899j.js.map} +2 -2
- package/dist/{chunk-7ds9620f.js → chunk-38zv5rkr.js} +24 -8
- package/dist/chunk-38zv5rkr.js.map +10 -0
- package/dist/{chunk-w3e09qqk.js → chunk-39tqv9hz.js} +24 -24
- package/dist/{chunk-w3e09qqk.js.map → chunk-39tqv9hz.js.map} +2 -2
- package/dist/{chunk-04b07a9q.js → chunk-3bh94gbw.js} +13 -13
- package/dist/{chunk-04b07a9q.js.map → chunk-3bh94gbw.js.map} +2 -2
- package/dist/{chunk-8m5ejdpn.js → chunk-3f7veca0.js} +4 -4
- package/dist/{chunk-8m5ejdpn.js.map → chunk-3f7veca0.js.map} +2 -2
- package/dist/chunk-3frsnm7x.js +32 -0
- package/dist/chunk-3frsnm7x.js.map +11 -0
- package/dist/{chunk-n2w475r0.js → chunk-3tgwrcyh.js} +81 -81
- package/dist/{chunk-n2w475r0.js.map → chunk-3tgwrcyh.js.map} +2 -2
- package/dist/{chunk-qv38twt8.js → chunk-52hbv0ak.js} +192 -171
- package/dist/{chunk-qv38twt8.js.map → chunk-52hbv0ak.js.map} +6 -6
- package/dist/{chunk-nf4r78r4.js → chunk-5a4a52tq.js} +4 -4
- package/dist/{chunk-nf4r78r4.js.map → chunk-5a4a52tq.js.map} +2 -2
- package/dist/{chunk-rte5sm3z.js → chunk-5hz0fnca.js} +23 -23
- package/dist/{chunk-rte5sm3z.js.map → chunk-5hz0fnca.js.map} +2 -2
- package/dist/chunk-653vwrzr.js +39 -0
- package/dist/chunk-653vwrzr.js.map +10 -0
- package/dist/{chunk-qw9gvjv5.js → chunk-72w2pxk7.js} +13 -13
- package/dist/{chunk-qw9gvjv5.js.map → chunk-72w2pxk7.js.map} +2 -2
- package/dist/chunk-7apz6hg4.js +50 -0
- package/dist/{chunk-jq43kdvk.js.map → chunk-7apz6hg4.js.map} +2 -2
- package/dist/chunk-7bs40fe1.js +218 -0
- package/dist/{chunk-08twe8m6.js.map → chunk-7bs40fe1.js.map} +3 -3
- package/dist/chunk-7zgecwy1.js +113 -0
- package/dist/chunk-7zgecwy1.js.map +10 -0
- package/dist/{chunk-tn7xcs2n.js → chunk-860dwwy0.js} +93 -30
- package/dist/chunk-860dwwy0.js.map +14 -0
- package/dist/chunk-8vj0rjgs.js +165 -0
- package/dist/chunk-8vj0rjgs.js.map +15 -0
- package/dist/{chunk-7y0f6rf1.js → chunk-92vk7gta.js} +58 -58
- package/dist/chunk-92vk7gta.js.map +10 -0
- package/dist/{chunk-gbrpsx4m.js → chunk-93csa55g.js} +72 -16
- package/dist/chunk-93csa55g.js.map +11 -0
- package/dist/{chunk-d8qkxt2v.js → chunk-98cw09sw.js} +7 -7
- package/dist/chunk-98cw09sw.js.map +10 -0
- package/dist/chunk-9qsh3p5y.js +111 -0
- package/dist/chunk-9qsh3p5y.js.map +11 -0
- package/dist/{chunk-4a849fr1.js → chunk-9tc8dxmn.js} +1 -1
- package/dist/{chunk-z2sery1b.js → chunk-9vx5e9g1.js} +68 -28
- package/dist/chunk-9vx5e9g1.js.map +11 -0
- package/dist/{chunk-9aehf39w.js → chunk-an5tt9y0.js} +353 -353
- package/dist/{chunk-9aehf39w.js.map → chunk-an5tt9y0.js.map} +2 -2
- package/dist/{chunk-x0qhkqje.js → chunk-ap0g1g74.js} +37 -37
- package/dist/{chunk-x0qhkqje.js.map → chunk-ap0g1g74.js.map} +2 -2
- package/dist/chunk-awbhdqyc.js +252 -0
- package/dist/chunk-awbhdqyc.js.map +10 -0
- package/dist/{chunk-ka3a2ft3.js → chunk-b19g04jk.js} +12 -12
- package/dist/{chunk-ka3a2ft3.js.map → chunk-b19g04jk.js.map} +2 -2
- package/dist/chunk-br3k6qbf.js +436 -0
- package/dist/chunk-br3k6qbf.js.map +12 -0
- package/dist/{chunk-dbc80ad7.js → chunk-c5rkjrgp.js} +28 -28
- package/dist/{chunk-dbc80ad7.js.map → chunk-c5rkjrgp.js.map} +2 -2
- package/dist/{chunk-dktq02ne.js → chunk-cqr3acm1.js} +4 -4
- package/dist/{chunk-dktq02ne.js.map → chunk-cqr3acm1.js.map} +2 -2
- package/dist/chunk-d62kjtbg.js +7 -0
- package/dist/{chunk-zcnhxkvd.js.map → chunk-d62kjtbg.js.map} +2 -2
- package/dist/{chunk-74drx9gd.js → chunk-dfm066qg.js} +10 -10
- package/dist/{chunk-74drx9gd.js.map → chunk-dfm066qg.js.map} +2 -2
- package/dist/{chunk-atmkaf60.js → chunk-dmn70ztd.js} +30 -34
- package/dist/chunk-dmn70ztd.js.map +11 -0
- package/dist/chunk-dz5h08xv.js +1887 -0
- package/dist/chunk-dz5h08xv.js.map +25 -0
- package/dist/{chunk-p2vqaxkc.js → chunk-e0d1rzef.js} +27 -22
- package/dist/{chunk-p2vqaxkc.js.map → chunk-e0d1rzef.js.map} +3 -3
- package/dist/{chunk-5sz8ta9r.js → chunk-e1c18xjx.js} +52 -52
- package/dist/{chunk-5sz8ta9r.js.map → chunk-e1c18xjx.js.map} +2 -2
- package/dist/{chunk-ha58tjtt.js → chunk-emyyk7dx.js} +59 -55
- package/dist/{chunk-ha58tjtt.js.map → chunk-emyyk7dx.js.map} +3 -3
- package/dist/{chunk-3kv70xwp.js → chunk-ey1nk510.js} +18 -2
- package/dist/chunk-ey1nk510.js.map +10 -0
- package/dist/chunk-f0rwz2vh.js +152 -0
- package/dist/chunk-f0rwz2vh.js.map +11 -0
- package/dist/{chunk-2xns679x.js → chunk-f4w3yp4f.js} +171 -36
- package/dist/chunk-f4w3yp4f.js.map +12 -0
- package/dist/{chunk-979ww6b3.js → chunk-fb3feg1e.js} +29 -29
- package/dist/{chunk-979ww6b3.js.map → chunk-fb3feg1e.js.map} +2 -2
- package/dist/{chunk-rre42skh.js → chunk-g00bfdq6.js} +729 -296
- package/dist/{chunk-rre42skh.js.map → chunk-g00bfdq6.js.map} +11 -7
- package/dist/{chunk-p03r0h5s.js → chunk-g53f0e4j.js} +76 -202
- package/dist/chunk-g53f0e4j.js.map +15 -0
- package/dist/chunk-g6cke204.js +124 -0
- package/dist/chunk-g6cke204.js.map +10 -0
- package/dist/{chunk-51fjndv0.js → chunk-gfdh9kqa.js} +4 -4
- package/dist/{chunk-51fjndv0.js.map → chunk-gfdh9kqa.js.map} +2 -2
- package/dist/chunk-h1gfhhbh.js +602 -0
- package/dist/chunk-h1gfhhbh.js.map +18 -0
- package/dist/chunk-h3v76ams.js +32 -0
- package/dist/{chunk-08m3b6w8.js.map → chunk-h3v76ams.js.map} +2 -2
- package/dist/chunk-hpr1r6av.js +4006 -0
- package/dist/chunk-hpr1r6av.js.map +44 -0
- package/dist/{chunk-jecn6t54.js → chunk-jgwb25gc.js} +74 -74
- package/dist/{chunk-jecn6t54.js.map → chunk-jgwb25gc.js.map} +2 -2
- package/dist/{chunk-rp1mvzb4.js → chunk-jjy0fhrn.js} +40 -35
- package/dist/{chunk-rp1mvzb4.js.map → chunk-jjy0fhrn.js.map} +3 -3
- package/dist/{chunk-4nxeacx7.js → chunk-jmfet9r4.js} +6 -6
- package/dist/{chunk-4nxeacx7.js.map → chunk-jmfet9r4.js.map} +2 -2
- package/dist/{chunk-64sr682n.js → chunk-k3cqkkn2.js} +61 -55
- package/dist/chunk-k3cqkkn2.js.map +12 -0
- package/dist/{chunk-s5y30bc9.js → chunk-kxwa347f.js} +51 -49
- package/dist/{chunk-s5y30bc9.js.map → chunk-kxwa347f.js.map} +4 -4
- package/dist/{chunk-2ab72m2h.js → chunk-m2ca93my.js} +3 -3
- package/dist/{chunk-2ab72m2h.js.map → chunk-m2ca93my.js.map} +2 -2
- package/dist/{chunk-qjycjdj6.js → chunk-m3z3x9v0.js} +106 -65
- package/dist/{chunk-qjycjdj6.js.map → chunk-m3z3x9v0.js.map} +3 -3
- package/dist/{chunk-6ed5bwnd.js → chunk-mjbk2djy.js} +2092 -1714
- package/dist/chunk-mjbk2djy.js.map +57 -0
- package/dist/{chunk-5jcdmjam.js → chunk-mmagke4x.js} +6 -6
- package/dist/{chunk-5jcdmjam.js.map → chunk-mmagke4x.js.map} +2 -2
- package/dist/chunk-mrp7k0pw.js +147 -0
- package/dist/chunk-mrp7k0pw.js.map +10 -0
- package/dist/{chunk-d63tybny.js → chunk-ms2tmn1k.js} +139 -139
- package/dist/{chunk-d63tybny.js.map → chunk-ms2tmn1k.js.map} +2 -2
- package/dist/{chunk-xdpwpkha.js → chunk-ppytyr6w.js} +156 -179
- package/dist/{chunk-xdpwpkha.js.map → chunk-ppytyr6w.js.map} +3 -5
- package/dist/{chunk-trxxmgnf.js → chunk-pqajwytd.js} +10 -10
- package/dist/{chunk-trxxmgnf.js.map → chunk-pqajwytd.js.map} +3 -3
- package/dist/{chunk-qjzp9xyb.js → chunk-pr2h4bv4.js} +33 -35
- package/dist/chunk-pr2h4bv4.js.map +12 -0
- package/dist/{chunk-xwnf87e1.js → chunk-q5gz3g2j.js} +64 -64
- package/dist/{chunk-xwnf87e1.js.map → chunk-q5gz3g2j.js.map} +2 -2
- package/dist/{chunk-agsvg9ar.js → chunk-qf954wje.js} +6 -6
- package/dist/{chunk-agsvg9ar.js.map → chunk-qf954wje.js.map} +2 -2
- package/dist/{chunk-wjgm6jjt.js → chunk-qhcpj9wc.js} +166 -132
- package/dist/chunk-qhcpj9wc.js.map +14 -0
- package/dist/{chunk-tpnd31c1.js → chunk-r29fxdhn.js} +12 -12
- package/dist/{chunk-tpnd31c1.js.map → chunk-r29fxdhn.js.map} +2 -2
- package/dist/{chunk-b49dgvsj.js → chunk-r2y23egw.js} +3 -3
- package/dist/{chunk-b49dgvsj.js.map → chunk-r2y23egw.js.map} +2 -2
- package/dist/{chunk-2b5qtban.js → chunk-r4tfx1sf.js} +142 -89
- package/dist/chunk-r4tfx1sf.js.map +15 -0
- package/dist/{chunk-4rh2m6zg.js → chunk-rb1xx120.js} +13 -13
- package/dist/{chunk-4rh2m6zg.js.map → chunk-rb1xx120.js.map} +2 -2
- package/dist/chunk-s3csryxe.js +152 -0
- package/dist/chunk-s3csryxe.js.map +11 -0
- package/dist/chunk-s670k14v.js +60 -0
- package/dist/{chunk-407j3msh.js.map → chunk-s670k14v.js.map} +2 -2
- package/dist/chunk-skz0hst3.js +788 -0
- package/dist/chunk-skz0hst3.js.map +19 -0
- package/dist/chunk-v4jbb3rs.js +403 -0
- package/dist/chunk-v4jbb3rs.js.map +10 -0
- package/dist/{chunk-d2ndstdf.js → chunk-vf691g1r.js} +61 -59
- package/dist/{chunk-d2ndstdf.js.map → chunk-vf691g1r.js.map} +2 -2
- package/dist/{chunk-1kamz6j0.js → chunk-vsj3mdfj.js} +8 -8
- package/dist/{chunk-1kamz6j0.js.map → chunk-vsj3mdfj.js.map} +2 -2
- package/dist/{chunk-9dzba0f2.js → chunk-wjasrj67.js} +8 -8
- package/dist/{chunk-9dzba0f2.js.map → chunk-wjasrj67.js.map} +2 -2
- package/dist/{chunk-1evzqhks.js → chunk-wr8qp979.js} +6 -6
- package/dist/{chunk-1evzqhks.js.map → chunk-wr8qp979.js.map} +2 -2
- package/dist/{chunk-n6jxh8sw.js → chunk-wy0qdqfm.js} +18 -18
- package/dist/{chunk-n6jxh8sw.js.map → chunk-wy0qdqfm.js.map} +2 -2
- package/dist/{chunk-8tsf6dmc.js → chunk-x57ycxq0.js} +204 -204
- package/dist/{chunk-8tsf6dmc.js.map → chunk-x57ycxq0.js.map} +2 -2
- package/dist/chunk-x9v4cx1d.js +139 -0
- package/dist/chunk-x9v4cx1d.js.map +10 -0
- package/dist/{chunk-kt81c11h.js → chunk-xfbydgzy.js} +27 -27
- package/dist/{chunk-kt81c11h.js.map → chunk-xfbydgzy.js.map} +2 -2
- package/dist/{chunk-vjjv9mrb.js → chunk-xyr8kppc.js} +22 -22
- package/dist/{chunk-vjjv9mrb.js.map → chunk-xyr8kppc.js.map} +3 -3
- package/dist/chunk-ypbtykv6.js +1537 -0
- package/dist/chunk-ypbtykv6.js.map +19 -0
- package/dist/{chunk-ry24jbr1.js → chunk-yv79ncbv.js} +10 -10
- package/dist/{chunk-ry24jbr1.js.map → chunk-yv79ncbv.js.map} +2 -2
- package/dist/{chunk-xc7hq65b.js → chunk-z30bv4ga.js} +80 -33
- package/dist/chunk-z30bv4ga.js.map +11 -0
- package/dist/{chunk-8ydjhh27.js → chunk-z3y411fq.js} +11 -7
- package/dist/{chunk-8ydjhh27.js.map → chunk-z3y411fq.js.map} +3 -3
- package/dist/{chunk-9t8f5xfx.js → chunk-z5rnrmz1.js} +10 -10
- package/dist/{chunk-9t8f5xfx.js.map → chunk-z5rnrmz1.js.map} +2 -2
- package/dist/{chunk-96swp2wd.js → chunk-z667z3sg.js} +3 -3
- package/dist/{chunk-96swp2wd.js.map → chunk-z667z3sg.js.map} +2 -2
- package/dist/chunk-z8fx5cgb.js +159 -0
- package/dist/chunk-z8fx5cgb.js.map +11 -0
- package/dist/{chunk-xhy826cz.js → chunk-zcnq6105.js} +7 -7
- package/dist/{chunk-xhy826cz.js.map → chunk-zcnq6105.js.map} +2 -2
- package/dist/{chunk-yt8wphsx.js → chunk-zvx7h87b.js} +3 -3
- package/dist/{chunk-yt8wphsx.js.map → chunk-zvx7h87b.js.map} +2 -2
- package/dist/connectors/connections/internal.js +9 -10
- package/dist/connectors/connections/internal.js.map +1 -1
- package/dist/datasets/builders.d.ts +11 -2
- package/dist/datasets/builders.d.ts.map +1 -1
- package/dist/datasets/changes.d.ts +14 -4
- package/dist/datasets/changes.d.ts.map +1 -1
- package/dist/datasets/execution.d.ts +15 -1
- package/dist/datasets/execution.d.ts.map +1 -1
- package/dist/datasets/index.d.ts +1 -0
- package/dist/datasets/index.d.ts.map +1 -1
- package/dist/datasets/sequence.d.ts +7 -0
- package/dist/datasets/sequence.d.ts.map +1 -0
- package/dist/datasets/types.d.ts +1 -0
- package/dist/datasets/types.d.ts.map +1 -1
- package/dist/datasets/validation.d.ts.map +1 -1
- package/dist/datasets/write.d.ts +37 -0
- package/dist/datasets/write.d.ts.map +1 -0
- package/dist/datasets/write.js +13 -0
- package/dist/datasets/write.js.map +9 -0
- package/dist/edits/index.js +7 -8
- package/dist/edits/index.js.map +1 -1
- package/dist/error-reporting/internal.js +22 -24
- package/dist/error-reporting/internal.js.map +1 -1
- package/dist/errors/internal.d.ts +1 -1
- package/dist/errors/internal.d.ts.map +1 -1
- package/dist/errors/internal.js +22 -24
- package/dist/errors/internal.js.map +1 -1
- package/dist/errors/redaction.d.ts +8 -0
- package/dist/errors/redaction.d.ts.map +1 -0
- package/dist/errors/types.d.ts +4 -0
- package/dist/errors/types.d.ts.map +1 -1
- package/dist/events/execution.d.ts.map +1 -1
- package/dist/events/index.js +60 -63
- package/dist/events/index.js.map +1 -1
- package/dist/events/scope.js +4 -5
- package/dist/events/scope.js.map +1 -1
- package/dist/events/selectors/index.js +9 -10
- package/dist/events/selectors/index.js.map +1 -1
- package/dist/events/types/datasets.d.ts +2 -6
- package/dist/events/types/datasets.d.ts.map +1 -1
- package/dist/execution/agent.d.ts +3 -3
- package/dist/execution/agent.d.ts.map +1 -1
- package/dist/execution/agent.js +70 -75
- package/dist/execution/agent.js.map +1 -1
- package/dist/execution/authorization.d.ts +58 -20
- package/dist/execution/authorization.d.ts.map +1 -1
- package/dist/execution/authorized-object-reader.d.ts +69 -0
- package/dist/execution/authorized-object-reader.d.ts.map +1 -0
- package/dist/execution/durable.d.ts +1 -0
- package/dist/execution/durable.d.ts.map +1 -1
- package/dist/execution/index.d.ts +1 -1
- package/dist/execution/index.d.ts.map +1 -1
- package/dist/execution/primitive.d.ts +2 -0
- package/dist/execution/primitive.d.ts.map +1 -1
- package/dist/execution/primitive.js +63 -64
- package/dist/execution/primitive.js.map +3 -3
- package/dist/execution/request.d.ts +12 -0
- package/dist/execution/request.d.ts.map +1 -1
- package/dist/execution/request.js +97 -71
- package/dist/execution/request.js.map +3 -3
- package/dist/execution/scopes.d.ts +16 -0
- package/dist/execution/scopes.d.ts.map +1 -1
- package/dist/execution/types.d.ts +9 -0
- package/dist/execution/types.d.ts.map +1 -1
- package/dist/http/api-routes.d.ts +2 -0
- package/dist/http/api-routes.d.ts.map +1 -1
- package/dist/http/index.js +10 -11
- package/dist/http/index.js.map +1 -1
- package/dist/index.d.ts +21 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +455 -463
- package/dist/index.js.map +1 -1
- package/dist/lake-storage/definition-updates.d.ts.map +1 -1
- package/dist/lake-storage/errors.d.ts +5 -1
- package/dist/lake-storage/errors.d.ts.map +1 -1
- package/dist/lake-storage/in-memory.d.ts +1 -0
- package/dist/lake-storage/in-memory.d.ts.map +1 -1
- package/dist/lake-storage/index.d.ts +6 -1
- package/dist/lake-storage/index.d.ts.map +1 -1
- package/dist/lake-storage/index.js +40 -27
- package/dist/lake-storage/index.js.map +1 -1
- package/dist/lake-storage/merge-validation.d.ts.map +1 -1
- package/dist/lake-storage/merge.d.ts +13 -2
- package/dist/lake-storage/merge.d.ts.map +1 -1
- package/dist/lake-storage/source-ordering.d.ts +19 -0
- package/dist/lake-storage/source-ordering.d.ts.map +1 -0
- package/dist/lake-storage/sql-transforms.d.ts +2 -1
- package/dist/lake-storage/sql-transforms.d.ts.map +1 -1
- package/dist/lake-storage/types.d.ts +10 -5
- package/dist/lake-storage/types.d.ts.map +1 -1
- package/dist/lake-storage/version-inputs.d.ts +4 -0
- package/dist/lake-storage/version-inputs.d.ts.map +1 -0
- package/dist/logging/index.d.ts +3 -4
- package/dist/logging/index.d.ts.map +1 -1
- package/dist/logging/index.js +18 -40
- package/dist/logging/index.js.map +1 -1
- package/dist/logging/internal.d.ts +5 -0
- package/dist/logging/internal.d.ts.map +1 -0
- package/dist/logging/internal.js +43 -0
- package/dist/logging/internal.js.map +9 -0
- package/dist/materialization/index.js +46 -49
- package/dist/materialization/index.js.map +1 -1
- package/dist/materializer/index.js +137 -142
- package/dist/materializer/index.js.map +1 -1
- package/dist/models/errors.d.ts +4 -0
- package/dist/models/errors.d.ts.map +1 -1
- package/dist/models/execution/binding.d.ts +9 -0
- package/dist/models/execution/binding.d.ts.map +1 -0
- package/dist/models/execution/errors.d.ts +9 -0
- package/dist/models/execution/errors.d.ts.map +1 -0
- package/dist/models/execution/index.d.ts +11 -0
- package/dist/models/execution/index.d.ts.map +1 -0
- package/dist/models/execution/index.js +55 -0
- package/dist/models/execution/index.js.map +9 -0
- package/dist/models/execution/model-call-accounting.d.ts +17 -0
- package/dist/models/execution/model-call-accounting.d.ts.map +1 -0
- package/dist/models/execution/model-call-admission.d.ts +47 -0
- package/dist/models/execution/model-call-admission.d.ts.map +1 -0
- package/dist/models/execution/model-call-limits.d.ts +15 -0
- package/dist/models/execution/model-call-limits.d.ts.map +1 -0
- package/dist/models/execution/model-call-recorder.d.ts +40 -0
- package/dist/models/execution/model-call-recorder.d.ts.map +1 -0
- package/dist/models/execution/model-call-recovery.d.ts +12 -0
- package/dist/models/execution/model-call-recovery.d.ts.map +1 -0
- package/dist/models/execution/recovery-queue.d.ts +5 -0
- package/dist/models/execution/recovery-queue.d.ts.map +1 -0
- package/dist/models/execution/types.d.ts +44 -0
- package/dist/models/execution/types.d.ts.map +1 -0
- package/dist/models/execution/usage.d.ts +5 -0
- package/dist/models/execution/usage.d.ts.map +1 -0
- package/dist/models/execution.d.ts +6 -0
- package/dist/models/execution.d.ts.map +1 -0
- package/dist/models/generation-types.d.ts +40 -0
- package/dist/models/generation-types.d.ts.map +1 -0
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +42 -43
- package/dist/models/index.js.map +1 -1
- package/dist/models/language-model.d.ts +3 -0
- package/dist/models/language-model.d.ts.map +1 -1
- package/dist/models/output.d.ts +5 -0
- package/dist/models/output.d.ts.map +1 -0
- package/dist/models/resolve.d.ts +4 -0
- package/dist/models/resolve.d.ts.map +1 -0
- package/dist/objects/authorized-ontology-view.d.ts +25 -0
- package/dist/objects/authorized-ontology-view.d.ts.map +1 -0
- package/dist/objects/execution.d.ts +1 -1
- package/dist/objects/execution.d.ts.map +1 -1
- package/dist/objects/index.js +75 -84
- package/dist/objects/index.js.map +1 -1
- package/dist/objects/link/authorization.d.ts +2 -7
- package/dist/objects/link/authorization.d.ts.map +1 -1
- package/dist/objects/query/executor.d.ts +4 -2
- package/dist/objects/query/executor.d.ts.map +1 -1
- package/dist/objects/query/index.js +67 -73
- package/dist/objects/query/index.js.map +1 -1
- package/dist/objects/query/links.d.ts +22 -1
- package/dist/objects/query/links.d.ts.map +1 -1
- package/dist/objects/query/selected-read-admission.d.ts +27 -0
- package/dist/objects/query/selected-read-admission.d.ts.map +1 -0
- package/dist/objects/query/validate.d.ts +60 -2
- package/dist/objects/query/validate.d.ts.map +1 -1
- package/dist/objects/sdk/object-handle.d.ts.map +1 -1
- package/dist/objects/sdk/object-set.d.ts.map +1 -1
- package/dist/objects/sdk/runtime-query-executor.d.ts +2 -7
- package/dist/objects/sdk/runtime-query-executor.d.ts.map +1 -1
- package/dist/objects/sdk/telemetry-channel.d.ts.map +1 -1
- package/dist/objects/service/list-service.d.ts +2 -3
- package/dist/objects/service/list-service.d.ts.map +1 -1
- package/dist/objects/telemetry/history.d.ts +8 -6
- package/dist/objects/telemetry/history.d.ts.map +1 -1
- package/dist/objects/telemetry/index.d.ts +2 -2
- package/dist/objects/telemetry/index.d.ts.map +1 -1
- package/dist/objects/telemetry/workload.d.ts +11 -0
- package/dist/objects/telemetry/workload.d.ts.map +1 -0
- package/dist/ontology/index.d.ts +2 -2
- package/dist/ontology/index.d.ts.map +1 -1
- package/dist/ontology/index.js +61 -111
- package/dist/ontology/index.js.map +1 -1
- package/dist/ontology/inference/index.d.ts +2 -1
- package/dist/ontology/inference/index.d.ts.map +1 -1
- package/dist/ontology/internal.d.ts +7 -1
- package/dist/ontology/internal.d.ts.map +1 -1
- package/dist/ontology/internal.js +65 -121
- package/dist/ontology/internal.js.map +3 -4
- package/dist/ontology/json-schema.d.ts +10 -6
- package/dist/ontology/json-schema.d.ts.map +1 -1
- package/dist/ontology/link-path-selection.d.ts +35 -0
- package/dist/ontology/link-path-selection.d.ts.map +1 -0
- package/dist/ontology/refs.d.ts +2 -0
- package/dist/ontology/refs.d.ts.map +1 -1
- package/dist/ontology/tokens.d.ts +2 -1
- package/dist/ontology/tokens.d.ts.map +1 -1
- package/dist/pipelines/execution.d.ts.map +1 -1
- package/dist/pipelines/index.js +57 -63
- package/dist/pipelines/index.js.map +1 -1
- package/dist/pipelines/request.d.ts.map +1 -1
- package/dist/projections/execution.d.ts.map +1 -1
- package/dist/projections/internal.js +58 -64
- package/dist/projections/internal.js.map +1 -1
- package/dist/projections/run-dispatch.d.ts.map +1 -1
- package/dist/query.d.ts +0 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +11 -15
- package/dist/query.js.map +1 -1
- package/dist/queues/index.d.ts +2 -1
- package/dist/queues/index.d.ts.map +1 -1
- package/dist/queues/index.js +6 -7
- package/dist/queues/index.js.map +1 -1
- package/dist/queues/types.d.ts +3 -20
- package/dist/queues/types.d.ts.map +1 -1
- package/dist/rules/execution.d.ts.map +1 -1
- package/dist/rules/internal.js +4 -5
- package/dist/rules/internal.js.map +1 -1
- package/dist/runtime/create.d.ts +6 -2
- package/dist/runtime/create.d.ts.map +1 -1
- package/dist/runtime/definitions.d.ts +2 -0
- package/dist/runtime/definitions.d.ts.map +1 -1
- package/dist/runtime/host.d.ts +4 -1
- package/dist/runtime/host.d.ts.map +1 -1
- package/dist/runtime/internal.d.ts +1 -0
- package/dist/runtime/internal.d.ts.map +1 -1
- package/dist/runtime/internal.js +13 -14
- package/dist/runtime/internal.js.map +1 -1
- package/dist/runtime/resolve-definitions.d.ts +2 -0
- package/dist/runtime/resolve-definitions.d.ts.map +1 -1
- package/dist/runtime/sixb.d.ts +6 -0
- package/dist/runtime/sixb.d.ts.map +1 -1
- package/dist/runtime/types.d.ts +3 -0
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/sandboxes/errors.d.ts +4 -0
- package/dist/sandboxes/errors.d.ts.map +1 -1
- package/dist/sandboxes/index.d.ts +2 -2
- package/dist/sandboxes/index.d.ts.map +1 -1
- package/dist/sandboxes/index.js +14 -13
- package/dist/sandboxes/index.js.map +1 -1
- package/dist/sandboxes/sandbox.d.ts +35 -7
- package/dist/sandboxes/sandbox.d.ts.map +1 -1
- package/dist/scheduler/index.js +9 -10
- package/dist/scheduler/index.js.map +1 -1
- package/dist/schedules/execution.d.ts +2 -1
- package/dist/schedules/execution.d.ts.map +1 -1
- package/dist/schedules/index.js +31 -33
- package/dist/schedules/index.js.map +1 -1
- package/dist/security/every.d.ts +4 -1
- package/dist/security/every.d.ts.map +1 -1
- package/dist/security/grants.d.ts +7 -2
- package/dist/security/grants.d.ts.map +1 -1
- package/dist/security/index.d.ts +1 -1
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/registry.d.ts +1 -0
- package/dist/security/registry.d.ts.map +1 -1
- package/dist/security/types.d.ts +7 -1
- package/dist/security/types.d.ts.map +1 -1
- package/dist/security/validation.d.ts +2 -0
- package/dist/security/validation.d.ts.map +1 -1
- package/dist/shares/access-plan.d.ts +22 -0
- package/dist/shares/access-plan.d.ts.map +1 -0
- package/dist/shares/builders.d.ts +14 -0
- package/dist/shares/builders.d.ts.map +1 -0
- package/dist/shares/compiler.d.ts +14 -0
- package/dist/shares/compiler.d.ts.map +1 -0
- package/dist/shares/errors.d.ts +4 -0
- package/dist/shares/errors.d.ts.map +1 -0
- package/dist/shares/execution.d.ts +57 -0
- package/dist/shares/execution.d.ts.map +1 -0
- package/dist/shares/index.d.ts +10 -0
- package/dist/shares/index.d.ts.map +1 -0
- package/dist/shares/internal.d.ts +3 -0
- package/dist/shares/internal.d.ts.map +1 -0
- package/dist/shares/internal.js +231 -0
- package/dist/shares/internal.js.map +10 -0
- package/dist/shares/intersection.d.ts +9 -0
- package/dist/shares/intersection.d.ts.map +1 -0
- package/dist/shares/session-protocol.d.ts +41 -0
- package/dist/shares/session-protocol.d.ts.map +1 -0
- package/dist/shares/types.d.ts +51 -0
- package/dist/shares/types.d.ts.map +1 -0
- package/dist/shares/validation.d.ts +11 -0
- package/dist/shares/validation.d.ts.map +1 -0
- package/dist/storage/action-runs/failure.js +7 -9
- package/dist/storage/action-runs/failure.js.map +1 -1
- package/dist/storage/action-runs/provider.js +4 -8
- package/dist/storage/action-runs/provider.js.map +1 -1
- package/dist/storage/agents/in-memory.d.ts.map +1 -1
- package/dist/storage/agents/provider.js +26 -30
- package/dist/storage/agents/provider.js.map +1 -1
- package/dist/storage/agents/types.d.ts +0 -3
- package/dist/storage/agents/types.d.ts.map +1 -1
- package/dist/storage/ai-cost/attribution.d.ts +4 -0
- package/dist/storage/ai-cost/attribution.d.ts.map +1 -0
- package/dist/storage/ai-cost/groups.d.ts +3 -0
- package/dist/storage/ai-cost/groups.d.ts.map +1 -1
- package/dist/storage/ai-cost/provider.d.ts +1 -0
- package/dist/storage/ai-cost/provider.d.ts.map +1 -1
- package/dist/storage/ai-cost/provider.js +30 -143
- package/dist/storage/ai-cost/provider.js.map +3 -4
- package/dist/storage/ai-cost/types.d.ts +15 -0
- package/dist/storage/ai-cost/types.d.ts.map +1 -1
- package/dist/storage/ai-limits/enforcement.js +14 -16
- package/dist/storage/ai-limits/enforcement.js.map +1 -1
- package/dist/storage/ai-limits/provider.js +56 -57
- package/dist/storage/ai-limits/provider.js.map +1 -1
- package/dist/storage/auth/in-memory.d.ts +1 -1
- package/dist/storage/auth/in-memory.d.ts.map +1 -1
- package/dist/storage/connector-connections/provider.js +34 -36
- package/dist/storage/connector-connections/provider.js.map +2 -2
- package/dist/storage/executions/in-memory.d.ts +3 -0
- package/dist/storage/executions/in-memory.d.ts.map +1 -1
- package/dist/storage/executions/provider.d.ts +6 -2
- package/dist/storage/executions/provider.d.ts.map +1 -1
- package/dist/storage/executions/provider.js +35 -12
- package/dist/storage/executions/provider.js.map +3 -3
- package/dist/storage/executions/run-link.d.ts +7 -0
- package/dist/storage/executions/run-link.d.ts.map +1 -1
- package/dist/storage/executions/types.d.ts +6 -2
- package/dist/storage/executions/types.d.ts.map +1 -1
- package/dist/storage/executions/validation.d.ts +8 -0
- package/dist/storage/executions/validation.d.ts.map +1 -1
- package/dist/storage/in-memory/index.d.ts +8 -0
- package/dist/storage/in-memory/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +14 -9
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +221 -227
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/internal.d.ts +10 -0
- package/dist/storage/internal.d.ts.map +1 -0
- package/dist/storage/internal.js +47 -0
- package/dist/storage/internal.js.map +9 -0
- package/dist/storage/objects/execution-limits.d.ts +25 -0
- package/dist/storage/objects/execution-limits.d.ts.map +1 -0
- package/dist/storage/objects/guard.d.ts +16 -0
- package/dist/storage/objects/guard.d.ts.map +1 -0
- package/dist/storage/objects/in-memory/index.d.ts +3 -0
- package/dist/storage/objects/in-memory/index.d.ts.map +1 -0
- package/dist/storage/objects/in-memory/keys.d.ts +10 -0
- package/dist/storage/objects/in-memory/keys.d.ts.map +1 -0
- package/dist/storage/objects/in-memory/query.d.ts +31 -0
- package/dist/storage/objects/in-memory/query.d.ts.map +1 -0
- package/dist/storage/objects/in-memory/read-scope.d.ts +18 -0
- package/dist/storage/objects/in-memory/read-scope.d.ts.map +1 -0
- package/dist/storage/objects/in-memory/read-source.d.ts +10 -0
- package/dist/storage/objects/in-memory/read-source.d.ts.map +1 -0
- package/dist/storage/objects/in-memory/selected-reader.d.ts +9 -0
- package/dist/storage/objects/in-memory/selected-reader.d.ts.map +1 -0
- package/dist/storage/objects/{in-memory.d.ts → in-memory/storage.d.ts} +13 -10
- package/dist/storage/objects/in-memory/storage.d.ts.map +1 -0
- package/dist/storage/objects/index.d.ts +4 -1
- package/dist/storage/objects/index.d.ts.map +1 -1
- package/dist/storage/objects/keys.d.ts +1 -1
- package/dist/storage/objects/keys.d.ts.map +1 -1
- package/dist/storage/objects/read-scope.d.ts +25 -0
- package/dist/storage/objects/read-scope.d.ts.map +1 -0
- package/dist/storage/objects/types.d.ts +114 -22
- package/dist/storage/objects/types.d.ts.map +1 -1
- package/dist/storage/ontology/provider.js +105 -109
- package/dist/storage/ontology/provider.js.map +1 -1
- package/dist/storage/operation-scope.d.ts +3 -0
- package/dist/storage/operation-scope.d.ts.map +1 -1
- package/dist/storage/operation-scope.js +18 -17
- package/dist/storage/operation-scope.js.map +1 -1
- package/dist/storage/pipeline-runs/provider.js +4 -6
- package/dist/storage/pipeline-runs/provider.js.map +1 -1
- package/dist/storage/projection-runs/provider.js +66 -70
- package/dist/storage/projection-runs/provider.js.map +1 -1
- package/dist/storage/share-grants/errors.d.ts +8 -0
- package/dist/storage/share-grants/errors.d.ts.map +1 -0
- package/dist/storage/share-grants/in-memory.d.ts +11 -0
- package/dist/storage/share-grants/in-memory.d.ts.map +1 -0
- package/dist/storage/share-grants/index.d.ts +5 -0
- package/dist/storage/share-grants/index.d.ts.map +1 -0
- package/dist/storage/share-grants/provider.d.ts +4 -0
- package/dist/storage/share-grants/provider.d.ts.map +1 -0
- package/dist/storage/share-grants/provider.js +22 -0
- package/dist/storage/share-grants/provider.js.map +9 -0
- package/dist/storage/share-grants/record.d.ts +11 -0
- package/dist/storage/share-grants/record.d.ts.map +1 -0
- package/dist/storage/share-grants/types.d.ts +97 -0
- package/dist/storage/share-grants/types.d.ts.map +1 -0
- package/dist/storage/share-sessions/errors.d.ts +8 -0
- package/dist/storage/share-sessions/errors.d.ts.map +1 -0
- package/dist/storage/share-sessions/in-memory.d.ts +14 -0
- package/dist/storage/share-sessions/in-memory.d.ts.map +1 -0
- package/dist/storage/share-sessions/index.d.ts +5 -0
- package/dist/storage/share-sessions/index.d.ts.map +1 -0
- package/dist/storage/share-sessions/provider.d.ts +3 -0
- package/dist/storage/share-sessions/provider.d.ts.map +1 -0
- package/dist/storage/share-sessions/provider.js +19 -0
- package/dist/storage/share-sessions/provider.js.map +9 -0
- package/dist/storage/share-sessions/record.d.ts +8 -0
- package/dist/storage/share-sessions/record.d.ts.map +1 -0
- package/dist/storage/share-sessions/types.d.ts +50 -0
- package/dist/storage/share-sessions/types.d.ts.map +1 -0
- package/dist/storage/sync-runs/provider.js +4 -6
- package/dist/storage/sync-runs/provider.js.map +1 -1
- package/dist/storage/transaction.d.ts +2 -1
- package/dist/storage/transaction.d.ts.map +1 -1
- package/dist/storage/types.d.ts +8 -0
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/storage/webhook-runs/provider.js +4 -6
- package/dist/storage/webhook-runs/provider.js.map +1 -1
- package/dist/storage/workflow-runs/in-memory.d.ts.map +1 -1
- package/dist/storage/workflow-runs/provider.js +13 -18
- package/dist/storage/workflow-runs/provider.js.map +1 -1
- package/dist/storage/workflow-runs/types.d.ts +0 -3
- package/dist/storage/workflow-runs/types.d.ts.map +1 -1
- package/dist/syncs/execution.d.ts.map +1 -1
- package/dist/syncs/index.js +55 -62
- package/dist/syncs/index.js.map +1 -1
- package/dist/syncs/request.d.ts.map +1 -1
- package/dist/testing/action-execution.d.ts +4 -1
- package/dist/testing/action-execution.d.ts.map +1 -1
- package/dist/testing/agent-execution.d.ts +1 -0
- package/dist/testing/agent-execution.d.ts.map +1 -1
- package/dist/testing/agent-storage-contract.d.ts.map +1 -1
- package/dist/testing/ai-model-call-groups-contract.d.ts.map +1 -1
- package/dist/testing/dataset-sequence-contract.d.ts +4 -0
- package/dist/testing/dataset-sequence-contract.d.ts.map +1 -0
- package/dist/testing/effective-storage-contract.d.ts.map +1 -1
- package/dist/testing/execution-storage-contract.d.ts +4 -0
- package/dist/testing/execution-storage-contract.d.ts.map +1 -1
- package/dist/testing/execution.d.ts +1 -0
- package/dist/testing/execution.d.ts.map +1 -1
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +3087 -1328
- package/dist/testing/index.js.map +17 -13
- package/dist/testing/lake-merge-storage-contract.d.ts +1 -0
- package/dist/testing/lake-merge-storage-contract.d.ts.map +1 -1
- package/dist/testing/lake-storage-contract.d.ts.map +1 -1
- package/dist/testing/object-read-scope-contract.d.ts +22 -0
- package/dist/testing/object-read-scope-contract.d.ts.map +1 -0
- package/dist/testing/share-grant-storage-contract.d.ts +10 -0
- package/dist/testing/share-grant-storage-contract.d.ts.map +1 -0
- package/dist/testing/share-session-storage-contract.d.ts +9 -0
- package/dist/testing/share-session-storage-contract.d.ts.map +1 -0
- package/dist/testing/workflow-execution.d.ts +1 -0
- package/dist/testing/workflow-execution.d.ts.map +1 -1
- package/dist/webhooks/internal.js +51 -56
- package/dist/webhooks/internal.js.map +2 -2
- package/dist/workers/index.js +11 -13
- package/dist/workers/index.js.map +2 -2
- package/dist/workflows/execution.d.ts.map +1 -1
- package/dist/workflows/failure.d.ts +2 -0
- package/dist/workflows/failure.d.ts.map +1 -1
- package/dist/workflows/index.js +135 -140
- package/dist/workflows/index.js.map +1 -1
- package/dist/workflows/request.d.ts.map +1 -1
- package/dist/workflows/run-dispatch.d.ts +0 -1
- package/dist/workflows/run-dispatch.d.ts.map +1 -1
- package/dist/workflows/types.d.ts +2 -0
- package/dist/workflows/types.d.ts.map +1 -1
- package/package.json +72 -30
- package/src/actions/delegated-admission.ts +72 -0
- package/src/actions/descriptor.ts +58 -0
- package/src/actions/execution.ts +99 -24
- package/src/actions/request.ts +136 -19
- package/src/actions/run-authorization.ts +53 -0
- package/src/actions/run-dispatch.ts +10 -7
- package/src/actions/types/context.ts +2 -0
- package/src/actions/validation.ts +2 -1
- package/src/agents/adapters.ts +34 -429
- package/src/agents/authority.ts +3 -4
- package/src/agents/{context.ts → context/entries.ts} +4 -4
- package/src/agents/context/index.ts +15 -0
- package/src/agents/context-model.ts +1 -1
- package/src/agents/context-resolution.ts +2 -5
- package/src/agents/errors.ts +0 -10
- package/src/agents/execution.ts +13 -5
- package/src/agents/identity.ts +4 -0
- package/src/agents/index.ts +5 -24
- package/src/agents/message.ts +5 -6
- package/src/agents/model-loop.ts +62 -6
- package/src/agents/request.ts +27 -29
- package/src/agents/streams/index.ts +18 -0
- package/src/agents/streams/internal.ts +19 -0
- package/src/agents/{streams.ts → streams/protocol.ts} +5 -5
- package/src/agents/tool-definition.ts +0 -19
- package/src/agents/types.ts +1 -1
- package/src/agents/validation.ts +9 -72
- package/src/ai-usage/execution.ts +4 -11
- package/src/auth/index.ts +0 -1
- package/src/authorization/decision.ts +29 -14
- package/src/authorization/grant-kinds.ts +10 -0
- package/src/authorization/index.ts +1 -0
- package/src/bootstrap/discovery.ts +84 -24
- package/src/bootstrap/index.ts +8 -1
- package/src/bootstrap/ontology-type-manifest.ts +12 -6
- package/src/datasets/builders.ts +23 -2
- package/src/datasets/changes.ts +16 -4
- package/src/datasets/execution.ts +76 -5
- package/src/datasets/index.ts +1 -0
- package/src/datasets/sequence.ts +77 -0
- package/src/datasets/types.ts +1 -0
- package/src/datasets/validation.ts +26 -0
- package/src/datasets/write.ts +240 -0
- package/src/errors/internal.ts +90 -10
- package/src/errors/redaction.ts +98 -0
- package/src/errors/types.ts +4 -0
- package/src/events/execution.ts +57 -7
- package/src/events/types/datasets.ts +2 -6
- package/src/execution/agent.ts +6 -7
- package/src/execution/authorization.ts +470 -90
- package/src/execution/authorized-object-reader.ts +695 -0
- package/src/execution/durable.ts +21 -3
- package/src/execution/index.ts +1 -0
- package/src/execution/primitive.ts +5 -1
- package/src/execution/request.ts +66 -13
- package/src/execution/scopes.ts +36 -6
- package/src/execution/types.ts +8 -0
- package/src/http/api-routes.ts +45 -0
- package/src/index.ts +56 -33
- package/src/lake-storage/definition-updates.ts +9 -0
- package/src/lake-storage/errors.ts +6 -1
- package/src/lake-storage/in-memory.ts +53 -17
- package/src/lake-storage/index.ts +10 -1
- package/src/lake-storage/merge-validation.ts +12 -2
- package/src/lake-storage/merge.ts +40 -2
- package/src/lake-storage/source-ordering.ts +95 -0
- package/src/lake-storage/sql-transforms.ts +2 -1
- package/src/lake-storage/types.ts +10 -5
- package/src/lake-storage/version-inputs.ts +14 -0
- package/src/logging/index.ts +2 -33
- package/src/logging/internal.ts +43 -0
- package/src/models/errors.ts +12 -0
- package/src/models/execution/binding.ts +29 -0
- package/src/models/execution/errors.ts +18 -0
- package/src/models/execution/index.ts +26 -0
- package/src/models/execution/model-call-accounting.ts +211 -0
- package/src/models/execution/model-call-admission.ts +127 -0
- package/src/models/execution/model-call-limits.ts +135 -0
- package/src/models/execution/model-call-recorder.ts +235 -0
- package/src/models/execution/model-call-recovery.ts +125 -0
- package/src/models/execution/recovery-queue.ts +31 -0
- package/src/models/execution/types.ts +58 -0
- package/src/models/execution/usage.ts +23 -0
- package/src/models/execution.ts +207 -0
- package/src/models/generation-types.ts +50 -0
- package/src/models/index.ts +8 -0
- package/src/models/language-model.ts +3 -0
- package/src/models/output.ts +45 -0
- package/src/models/resolve.ts +27 -0
- package/src/objects/authorized-ontology-view.ts +512 -0
- package/src/objects/execution.ts +99 -144
- package/src/objects/link/authorization.ts +3 -2
- package/src/objects/query/executor.ts +45 -34
- package/src/objects/query/links.ts +84 -25
- package/src/objects/query/selected-read-admission.ts +310 -0
- package/src/objects/query/validate.ts +353 -36
- package/src/objects/sdk/object-handle.ts +2 -8
- package/src/objects/sdk/object-set.ts +10 -11
- package/src/objects/sdk/runtime-query-executor.ts +8 -28
- package/src/objects/sdk/telemetry-channel.ts +11 -7
- package/src/objects/service/list-service.ts +15 -29
- package/src/objects/telemetry/history.ts +297 -17
- package/src/objects/telemetry/index.ts +2 -2
- package/src/objects/telemetry/workload.ts +79 -0
- package/src/ontology/index.ts +7 -2
- package/src/ontology/inference/index.ts +4 -1
- package/src/ontology/internal.ts +35 -1
- package/src/ontology/json-schema.ts +13 -12
- package/src/ontology/link-path-selection.ts +193 -0
- package/src/ontology/refs.ts +19 -0
- package/src/ontology/tokens.ts +15 -8
- package/src/pipelines/execution.ts +30 -7
- package/src/pipelines/request.ts +5 -0
- package/src/projections/execution.ts +72 -11
- package/src/projections/run-dispatch.ts +7 -12
- package/src/query.ts +0 -1
- package/src/queues/index.ts +4 -2
- package/src/queues/types.ts +6 -25
- package/src/rules/execution.ts +20 -8
- package/src/runtime/create.ts +7 -2
- package/src/runtime/definitions.ts +2 -0
- package/src/runtime/host.ts +27 -7
- package/src/runtime/internal.ts +1 -0
- package/src/runtime/resolve-definitions.ts +9 -0
- package/src/runtime/sixb.ts +27 -2
- package/src/runtime/types.ts +3 -0
- package/src/sandboxes/errors.ts +5 -0
- package/src/sandboxes/index.ts +3 -0
- package/src/sandboxes/sandbox.ts +35 -7
- package/src/schedules/execution.ts +24 -2
- package/src/security/every.ts +4 -0
- package/src/security/grants.ts +45 -3
- package/src/security/index.ts +1 -0
- package/src/security/registry.ts +3 -0
- package/src/security/types.ts +8 -0
- package/src/security/validation.ts +3 -0
- package/src/shares/access-plan.ts +225 -0
- package/src/shares/builders.ts +381 -0
- package/src/shares/compiler.ts +359 -0
- package/src/shares/errors.ts +3 -0
- package/src/shares/execution.ts +394 -0
- package/src/shares/index.ts +28 -0
- package/src/shares/internal.ts +9 -0
- package/src/shares/intersection.ts +178 -0
- package/src/shares/session-protocol.ts +258 -0
- package/src/shares/types.ts +76 -0
- package/src/shares/validation.ts +40 -0
- package/src/storage/agents/in-memory.ts +0 -3
- package/src/storage/agents/types.ts +0 -3
- package/src/storage/ai-cost/analytics.ts +1 -1
- package/src/storage/ai-cost/attribution.ts +15 -0
- package/src/storage/ai-cost/groups.ts +5 -1
- package/src/storage/ai-cost/provider.ts +1 -0
- package/src/storage/ai-cost/types.ts +7 -0
- package/src/storage/auth/in-memory.ts +1 -1
- package/src/storage/executions/in-memory.ts +13 -10
- package/src/storage/executions/provider.ts +34 -1
- package/src/storage/executions/run-link.ts +29 -0
- package/src/storage/executions/types.ts +6 -2
- package/src/storage/executions/validation.ts +78 -1
- package/src/storage/in-memory/index.ts +37 -3
- package/src/storage/index.ts +54 -29
- package/src/storage/internal.ts +20 -0
- package/src/storage/objects/execution-limits.ts +283 -0
- package/src/storage/objects/guard.ts +55 -0
- package/src/storage/objects/in-memory/index.ts +2 -0
- package/src/storage/objects/in-memory/keys.ts +46 -0
- package/src/storage/objects/in-memory/query.ts +754 -0
- package/src/storage/objects/in-memory/read-scope.ts +211 -0
- package/src/storage/objects/in-memory/read-source.ts +10 -0
- package/src/storage/objects/in-memory/selected-reader.ts +252 -0
- package/src/storage/objects/in-memory/storage.ts +589 -0
- package/src/storage/objects/index.ts +21 -0
- package/src/storage/objects/keys.ts +1 -1
- package/src/storage/objects/read-scope.ts +672 -0
- package/src/storage/objects/types.ts +123 -19
- package/src/storage/operation-scope.ts +16 -0
- package/src/storage/share-grants/errors.ts +14 -0
- package/src/storage/share-grants/in-memory.ts +107 -0
- package/src/storage/share-grants/index.ts +14 -0
- package/src/storage/share-grants/provider.ts +11 -0
- package/src/storage/share-grants/record.ts +347 -0
- package/src/storage/share-grants/types.ts +112 -0
- package/src/storage/share-sessions/errors.ts +14 -0
- package/src/storage/share-sessions/in-memory.ts +105 -0
- package/src/storage/share-sessions/index.ts +11 -0
- package/src/storage/share-sessions/provider.ts +9 -0
- package/src/storage/share-sessions/record.ts +176 -0
- package/src/storage/share-sessions/types.ts +57 -0
- package/src/storage/transaction.ts +14 -2
- package/src/storage/types.ts +27 -0
- package/src/storage/workflow-runs/in-memory.ts +0 -2
- package/src/storage/workflow-runs/types.ts +0 -3
- package/src/syncs/execution.ts +25 -5
- package/src/syncs/request.ts +5 -0
- package/src/testing/action-execution.ts +9 -2
- package/src/testing/agent-execution.ts +3 -0
- package/src/testing/agent-storage-contract.ts +0 -5
- package/src/testing/ai-model-call-groups-contract.ts +74 -2
- package/src/testing/dataset-sequence-contract.ts +373 -0
- package/src/testing/effective-storage-contract.ts +34 -0
- package/src/testing/execution-storage-contract.ts +138 -1
- package/src/testing/execution.ts +6 -0
- package/src/testing/index.ts +16 -0
- package/src/testing/lake-merge-storage-contract.ts +3 -0
- package/src/testing/lake-storage-contract.ts +58 -0
- package/src/testing/object-read-scope-contract.ts +939 -0
- package/src/testing/share-grant-storage-contract.ts +325 -0
- package/src/testing/share-session-storage-contract.ts +235 -0
- package/src/testing/workflow-execution.ts +4 -0
- package/src/workflows/execution.ts +53 -14
- package/src/workflows/failure.ts +62 -1
- package/src/workflows/request.ts +5 -9
- package/src/workflows/run-dispatch.ts +0 -3
- package/src/workflows/types.ts +2 -0
- package/src/workflows/validation.ts +1 -1
- package/dist/agents/context.d.ts.map +0 -1
- package/dist/agents/context.js +0 -23
- package/dist/agents/streams.d.ts.map +0 -1
- package/dist/agents/streams.js +0 -55
- package/dist/chunk-08m3b6w8.js +0 -32
- package/dist/chunk-08twe8m6.js +0 -218
- package/dist/chunk-2b5qtban.js.map +0 -14
- package/dist/chunk-2xns679x.js.map +0 -11
- package/dist/chunk-37wk412q.js +0 -1370
- package/dist/chunk-37wk412q.js.map +0 -23
- package/dist/chunk-3fqt22c4.js.map +0 -14
- package/dist/chunk-3kv70xwp.js.map +0 -10
- package/dist/chunk-407j3msh.js +0 -60
- package/dist/chunk-64sr682n.js.map +0 -12
- package/dist/chunk-6ed5bwnd.js.map +0 -57
- package/dist/chunk-7ds9620f.js.map +0 -10
- package/dist/chunk-7y0f6rf1.js.map +0 -10
- package/dist/chunk-atmkaf60.js.map +0 -11
- package/dist/chunk-c15dr03f.js +0 -43
- package/dist/chunk-d8qkxt2v.js.map +0 -10
- package/dist/chunk-dqn23610.js +0 -72
- package/dist/chunk-dqn23610.js.map +0 -11
- package/dist/chunk-e4rvtvpw.js.map +0 -34
- package/dist/chunk-gbrpsx4m.js.map +0 -11
- package/dist/chunk-h0knpbz5.js +0 -2486
- package/dist/chunk-h0knpbz5.js.map +0 -38
- package/dist/chunk-hdz94br2.js.map +0 -10
- package/dist/chunk-jq43kdvk.js +0 -50
- package/dist/chunk-n2arzn6e.js +0 -1745
- package/dist/chunk-n2arzn6e.js.map +0 -20
- package/dist/chunk-p03r0h5s.js.map +0 -16
- package/dist/chunk-qjzp9xyb.js.map +0 -12
- package/dist/chunk-tn7xcs2n.js.map +0 -13
- package/dist/chunk-wjgm6jjt.js.map +0 -13
- package/dist/chunk-xc7hq65b.js.map +0 -10
- package/dist/chunk-y35ma3mj.js +0 -551
- package/dist/chunk-y35ma3mj.js.map +0 -15
- package/dist/chunk-y64skrwp.js +0 -19
- package/dist/chunk-z2sery1b.js.map +0 -11
- package/dist/chunk-zcnhxkvd.js +0 -7
- package/dist/logging/types.js +0 -27
- package/dist/logging/types.js.map +0 -9
- package/dist/storage/objects/in-memory.d.ts.map +0 -1
- package/src/storage/objects/in-memory.ts +0 -1241
- /package/dist/{chunk-zqqz8052.js → chunk-7n30ybym.js} +0 -0
- /package/dist/{chunk-zqqz8052.js.map → chunk-7n30ybym.js.map} +0 -0
- /package/dist/{chunk-4a849fr1.js.map → chunk-9tc8dxmn.js.map} +0 -0
package/dist/chunk-n2arzn6e.js
DELETED
|
@@ -1,1745 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import {
|
|
3
|
-
SIXB_API_ROUTES,
|
|
4
|
-
matchesPathPattern,
|
|
5
|
-
normalizeRoutePath
|
|
6
|
-
} from "./chunk-z2sery1b.js";
|
|
7
|
-
import {
|
|
8
|
-
ModelProviderError,
|
|
9
|
-
ModelStreamError,
|
|
10
|
-
StructuredOutputError,
|
|
11
|
-
estimateModelCall,
|
|
12
|
-
rateModelCall
|
|
13
|
-
} from "./chunk-p2vqaxkc.js";
|
|
14
|
-
import {
|
|
15
|
-
AgentDefinitionError,
|
|
16
|
-
AgentMessageAdapterError,
|
|
17
|
-
AgentToolResultValidationError,
|
|
18
|
-
normalizeAgentContextEntries
|
|
19
|
-
} from "./chunk-atmkaf60.js";
|
|
20
|
-
import {
|
|
21
|
-
normalizeSchemaValue,
|
|
22
|
-
validateSchemaValue
|
|
23
|
-
} from "./chunk-d63tybny.js";
|
|
24
|
-
import {
|
|
25
|
-
OntologyValidationError
|
|
26
|
-
} from "./chunk-dktq02ne.js";
|
|
27
|
-
import {
|
|
28
|
-
isFileRef
|
|
29
|
-
} from "./chunk-08m3b6w8.js";
|
|
30
|
-
import {
|
|
31
|
-
assertJsonObject,
|
|
32
|
-
assertJsonValue,
|
|
33
|
-
cloneJsonValue,
|
|
34
|
-
getInvalidJsonValueReason,
|
|
35
|
-
isJsonValue,
|
|
36
|
-
isPlainRecord,
|
|
37
|
-
stableJsonStringify
|
|
38
|
-
} from "./chunk-n6jxh8sw.js";
|
|
39
|
-
|
|
40
|
-
// src/agents/context-model.ts
|
|
41
|
-
function serializeAgentContextForModel(parts) {
|
|
42
|
-
if (parts.length === 0)
|
|
43
|
-
return;
|
|
44
|
-
const lines = ["<sixb_user_context>"];
|
|
45
|
-
for (const part of parts) {
|
|
46
|
-
if (part.context.kind === "object") {
|
|
47
|
-
lines.push(" <object_context>", ` <object_type_id>${escapeXml(part.context.ref.objectTypeId)}</object_type_id>`, ` <primary_id>${escapeXml(part.context.ref.primaryId)}</primary_id>`, " </object_context>");
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
lines.push(" <app_state_context>", ` <id>${escapeXml(part.context.id)}</id>`, ` <description>${escapeXml(part.context.description)}</description>`, ` <value format="json">${escapeXml(stableJsonStringify(part.context.value))}</value>`, " </app_state_context>");
|
|
51
|
-
}
|
|
52
|
-
lines.push("</sixb_user_context>");
|
|
53
|
-
return lines.join(`
|
|
54
|
-
`);
|
|
55
|
-
}
|
|
56
|
-
function escapeXml(value) {
|
|
57
|
-
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// src/agents/tool-result.ts
|
|
61
|
-
function isAgentToolResult(value) {
|
|
62
|
-
return isPlainRecord(value) && value.kind === "agentToolResult" && getInvalidAgentToolResultReason(value) === undefined;
|
|
63
|
-
}
|
|
64
|
-
function getInvalidAgentToolResultReason(value) {
|
|
65
|
-
if (!isPlainRecord(value) || value.kind !== "agentToolResult") {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
if (!Array.isArray(value.content)) {
|
|
69
|
-
return "result.content must be an array";
|
|
70
|
-
}
|
|
71
|
-
const unsupportedKey = Object.keys(value).find((key) => key !== "kind" && key !== "content");
|
|
72
|
-
if (unsupportedKey) {
|
|
73
|
-
return `result.${unsupportedKey} is not supported`;
|
|
74
|
-
}
|
|
75
|
-
if (value.content.length === 0) {
|
|
76
|
-
return "result.content must contain at least one content part";
|
|
77
|
-
}
|
|
78
|
-
for (let index = 0;index < value.content.length; index += 1) {
|
|
79
|
-
const part = value.content[index];
|
|
80
|
-
const path = `result.content[${index}]`;
|
|
81
|
-
if (!isPlainRecord(part)) {
|
|
82
|
-
return `${path} must be a text or file content part`;
|
|
83
|
-
}
|
|
84
|
-
if (part.type === "text") {
|
|
85
|
-
if (typeof part.text !== "string") {
|
|
86
|
-
return `${path}.text must be a string`;
|
|
87
|
-
}
|
|
88
|
-
const unsupportedKey2 = Object.keys(part).find((key) => key !== "type" && key !== "text");
|
|
89
|
-
if (unsupportedKey2) {
|
|
90
|
-
return `${path}.${unsupportedKey2} is not supported`;
|
|
91
|
-
}
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if (part.type === "file") {
|
|
95
|
-
if (!isFileRef(part.fileRef)) {
|
|
96
|
-
return `${path}.fileRef must be a valid FileRef`;
|
|
97
|
-
}
|
|
98
|
-
const unsupportedKey2 = Object.keys(part).find((key) => key !== "type" && key !== "fileRef");
|
|
99
|
-
if (unsupportedKey2) {
|
|
100
|
-
return `${path}.${unsupportedKey2} is not supported`;
|
|
101
|
-
}
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
return `${path}.type must be 'text' or 'file'`;
|
|
105
|
-
}
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// src/agents/adapters.ts
|
|
110
|
-
var TOOL_TYPE_PREFIX = "tool-";
|
|
111
|
-
function assertAdapter(condition, message) {
|
|
112
|
-
if (!condition) {
|
|
113
|
-
throw new AgentMessageAdapterError(`[Sixb] ${message}`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
function requireJson(value, label) {
|
|
117
|
-
const reason = getInvalidJsonValueReason(value, label);
|
|
118
|
-
assertAdapter(reason === undefined, `agent message ${label} must be a JSON value; ${reason}`);
|
|
119
|
-
return value;
|
|
120
|
-
}
|
|
121
|
-
function optionalJson(value, label) {
|
|
122
|
-
if (value === undefined)
|
|
123
|
-
return;
|
|
124
|
-
return requireJson(omitUndefinedObjectProperties(value), label);
|
|
125
|
-
}
|
|
126
|
-
function optionalProviderData(value, label) {
|
|
127
|
-
const json = optionalJson(value, label);
|
|
128
|
-
if (json === undefined)
|
|
129
|
-
return;
|
|
130
|
-
assertAdapter(isPlainRecord(json), `agent message ${label} must be a provider-keyed JSON object`);
|
|
131
|
-
return json;
|
|
132
|
-
}
|
|
133
|
-
function omitUndefinedObjectProperties(value) {
|
|
134
|
-
return omitUndefinedObjectPropertiesInternal(value, new Set);
|
|
135
|
-
}
|
|
136
|
-
function omitUndefinedObjectPropertiesInternal(value, seen) {
|
|
137
|
-
if (typeof value !== "object" || value === null)
|
|
138
|
-
return value;
|
|
139
|
-
if (seen.has(value))
|
|
140
|
-
return value;
|
|
141
|
-
seen.add(value);
|
|
142
|
-
try {
|
|
143
|
-
if (Array.isArray(value)) {
|
|
144
|
-
return value.map((entry) => omitUndefinedObjectPropertiesInternal(entry, seen));
|
|
145
|
-
}
|
|
146
|
-
if (!isPlainRecord(value))
|
|
147
|
-
return value;
|
|
148
|
-
return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined).map(([key, entry]) => [key, omitUndefinedObjectPropertiesInternal(entry, seen)]));
|
|
149
|
-
} finally {
|
|
150
|
-
seen.delete(value);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
function isToolType(type) {
|
|
154
|
-
return type === "dynamic-tool" || type.startsWith(TOOL_TYPE_PREFIX);
|
|
155
|
-
}
|
|
156
|
-
function toolNameFromInbound(part) {
|
|
157
|
-
if (part.type === "dynamic-tool") {
|
|
158
|
-
assertAdapter(typeof part.toolName === "string" && part.toolName.length > 0, "dynamic-tool part is missing a tool name");
|
|
159
|
-
return part.toolName;
|
|
160
|
-
}
|
|
161
|
-
const name = part.type.slice(TOOL_TYPE_PREFIX.length);
|
|
162
|
-
assertAdapter(name.length > 0, `tool part type '${part.type}' is missing a tool name`);
|
|
163
|
-
return name;
|
|
164
|
-
}
|
|
165
|
-
function fromUiMessage(message) {
|
|
166
|
-
const { role } = message;
|
|
167
|
-
assertAdapter(role === "system" || role === "user" || role === "assistant", `unsupported message role '${role}'`);
|
|
168
|
-
const parts = message.parts.map((part) => fromUiMessagePart(part));
|
|
169
|
-
assertAdapter(role === "user" || !parts.some((part) => part.type === "context"), "context parts are only valid on user messages");
|
|
170
|
-
const metadata = optionalJson(message.metadata, "metadata");
|
|
171
|
-
return {
|
|
172
|
-
role,
|
|
173
|
-
parts,
|
|
174
|
-
...metadata === undefined ? {} : { metadata }
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
function fromUiMessagePart(part) {
|
|
178
|
-
switch (part.type) {
|
|
179
|
-
case "text":
|
|
180
|
-
case "reasoning": {
|
|
181
|
-
assertAdapter(typeof part.text === "string", `${part.type} part is missing text`);
|
|
182
|
-
assertAdapter(part.state !== "streaming", `cannot persist a streaming ${part.type} part; messages are written only once finalized`);
|
|
183
|
-
const providerMetadata = optionalProviderData(part.providerMetadata, `${part.type}.providerMetadata`);
|
|
184
|
-
return {
|
|
185
|
-
type: part.type,
|
|
186
|
-
text: part.text,
|
|
187
|
-
...providerMetadata === undefined ? {} : { providerMetadata }
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
case "step-start":
|
|
191
|
-
return { type: "step-start" };
|
|
192
|
-
case "file": {
|
|
193
|
-
assertAdapter(isFileRef(part.fileRef), "file part is missing a valid fileRef");
|
|
194
|
-
const providerMetadata = optionalProviderData(part.providerMetadata, "file.providerMetadata");
|
|
195
|
-
return {
|
|
196
|
-
type: "file",
|
|
197
|
-
fileRef: part.fileRef,
|
|
198
|
-
...providerMetadata === undefined ? {} : { providerMetadata }
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
case "context":
|
|
202
|
-
return fromUiContextPart(part);
|
|
203
|
-
case "provider-state":
|
|
204
|
-
assertAdapter(typeof part.providerId === "string" && part.providerId.length > 0, "provider-state part is missing a provider id");
|
|
205
|
-
return {
|
|
206
|
-
type: "provider-state",
|
|
207
|
-
providerId: part.providerId,
|
|
208
|
-
data: requireJson(part.data, "provider-state data")
|
|
209
|
-
};
|
|
210
|
-
default: {
|
|
211
|
-
assertAdapter(isToolType(part.type), `unsupported message part type '${part.type}'; extend the Sixb message part union to support it`);
|
|
212
|
-
return fromUiToolPart(part);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
function fromUiContextPart(part) {
|
|
217
|
-
try {
|
|
218
|
-
const [entry] = normalizeAgentContextEntries([
|
|
219
|
-
{ context: part.context, origin: part.origin }
|
|
220
|
-
]);
|
|
221
|
-
return { type: "context", ...entry };
|
|
222
|
-
} catch (error) {
|
|
223
|
-
throw new AgentMessageAdapterError(error instanceof Error ? error.message : "[Sixb] Invalid agent context part.");
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
function fromUiToolPart(part) {
|
|
227
|
-
const dynamic = part.type === "dynamic-tool";
|
|
228
|
-
const toolName = toolNameFromInbound(part);
|
|
229
|
-
assertAdapter(typeof part.toolCallId === "string" && part.toolCallId.length > 0, `tool part '${part.type}' is missing a toolCallId`);
|
|
230
|
-
assertAdapter(part.state === "output-available" || part.state === "output-error", `cannot persist tool part '${part.toolCallId}' in transient state '${part.state}'; only terminal states are stored`);
|
|
231
|
-
const input = part.input === undefined ? null : requireJson(part.input, "tool input");
|
|
232
|
-
const providerMetadata = optionalProviderData(part.callProviderMetadata, "tool callProviderMetadata");
|
|
233
|
-
const base = {
|
|
234
|
-
type: "tool-call",
|
|
235
|
-
toolCallId: part.toolCallId,
|
|
236
|
-
toolName,
|
|
237
|
-
input,
|
|
238
|
-
...dynamic ? { dynamic: true } : {},
|
|
239
|
-
...part.providerExecuted === undefined ? {} : { providerExecuted: part.providerExecuted },
|
|
240
|
-
...providerMetadata === undefined ? {} : { providerMetadata }
|
|
241
|
-
};
|
|
242
|
-
if (part.state === "output-available") {
|
|
243
|
-
return { ...base, state: "output-available", output: requireJson(part.output, "tool output") };
|
|
244
|
-
}
|
|
245
|
-
assertAdapter(typeof part.errorText === "string", `tool part '${part.toolCallId}' is missing errorText`);
|
|
246
|
-
return { ...base, state: "output-error", errorText: part.errorText };
|
|
247
|
-
}
|
|
248
|
-
function toUiMessage(message) {
|
|
249
|
-
return {
|
|
250
|
-
role: message.role,
|
|
251
|
-
parts: message.parts.map((part) => toUiPart(part)),
|
|
252
|
-
...message.metadata === undefined ? {} : { metadata: message.metadata }
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
function toUiPart(part) {
|
|
256
|
-
switch (part.type) {
|
|
257
|
-
case "text":
|
|
258
|
-
case "reasoning":
|
|
259
|
-
return {
|
|
260
|
-
type: part.type,
|
|
261
|
-
text: part.text,
|
|
262
|
-
...part.providerMetadata === undefined ? {} : { providerMetadata: part.providerMetadata }
|
|
263
|
-
};
|
|
264
|
-
case "step-start":
|
|
265
|
-
return { type: "step-start" };
|
|
266
|
-
case "file":
|
|
267
|
-
return {
|
|
268
|
-
type: "file",
|
|
269
|
-
fileRef: part.fileRef,
|
|
270
|
-
...part.providerMetadata === undefined ? {} : { providerMetadata: part.providerMetadata }
|
|
271
|
-
};
|
|
272
|
-
case "context":
|
|
273
|
-
return { type: "context", context: part.context, origin: part.origin };
|
|
274
|
-
case "provider-state":
|
|
275
|
-
return {
|
|
276
|
-
type: "provider-state",
|
|
277
|
-
providerId: part.providerId,
|
|
278
|
-
data: part.data
|
|
279
|
-
};
|
|
280
|
-
case "tool-call":
|
|
281
|
-
return toUiToolPart(part);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
function toUiToolPart(part) {
|
|
285
|
-
const body = {
|
|
286
|
-
toolCallId: part.toolCallId,
|
|
287
|
-
...part.providerExecuted === undefined ? {} : { providerExecuted: part.providerExecuted },
|
|
288
|
-
...part.providerMetadata === undefined ? {} : { callProviderMetadata: part.providerMetadata }
|
|
289
|
-
};
|
|
290
|
-
const state = part.state === "output-available" ? { state: "output-available", input: part.input, output: part.output } : { state: "output-error", input: part.input, errorText: part.errorText };
|
|
291
|
-
if (part.dynamic) {
|
|
292
|
-
return { type: "dynamic-tool", toolName: part.toolName, ...body, ...state };
|
|
293
|
-
}
|
|
294
|
-
return { type: `tool-${part.toolName}`, ...body, ...state };
|
|
295
|
-
}
|
|
296
|
-
function toModelMessages(messages, options = {}) {
|
|
297
|
-
const result = [];
|
|
298
|
-
for (const message of messages) {
|
|
299
|
-
switch (message.role) {
|
|
300
|
-
case "system":
|
|
301
|
-
result.push(systemModelMessage(message));
|
|
302
|
-
break;
|
|
303
|
-
case "user":
|
|
304
|
-
result.push(userModelMessage(message, options));
|
|
305
|
-
break;
|
|
306
|
-
case "assistant":
|
|
307
|
-
appendAssistantModelMessages(result, message, options);
|
|
308
|
-
break;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
return result;
|
|
312
|
-
}
|
|
313
|
-
function systemModelMessage(message) {
|
|
314
|
-
const textParts = message.parts.filter(isTextPart);
|
|
315
|
-
const providerData = mergeProviderMetadata(textParts);
|
|
316
|
-
return {
|
|
317
|
-
role: "system",
|
|
318
|
-
content: textParts.map((part) => part.text).join(""),
|
|
319
|
-
...providerData === undefined ? {} : { providerData }
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
function mergeProviderMetadata(parts) {
|
|
323
|
-
let merged;
|
|
324
|
-
for (const part of parts) {
|
|
325
|
-
const meta = part.providerMetadata;
|
|
326
|
-
if (meta !== undefined && typeof meta === "object" && meta !== null && !Array.isArray(meta)) {
|
|
327
|
-
merged = { ...merged ?? {}, ...meta };
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
return merged;
|
|
331
|
-
}
|
|
332
|
-
function userModelMessage(message, options) {
|
|
333
|
-
const content = [];
|
|
334
|
-
const serializedContext = serializeAgentContextForModel(message.parts.filter((part) => part.type === "context"));
|
|
335
|
-
if (serializedContext) {
|
|
336
|
-
content.push({ type: "text", text: `${serializedContext}
|
|
337
|
-
|
|
338
|
-
` });
|
|
339
|
-
}
|
|
340
|
-
message.parts.forEach((part, partIndex) => {
|
|
341
|
-
if (part.type === "text") {
|
|
342
|
-
content.push({
|
|
343
|
-
type: "text",
|
|
344
|
-
text: part.text,
|
|
345
|
-
...part.providerMetadata === undefined ? {} : { providerData: part.providerMetadata }
|
|
346
|
-
});
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
if (part.type === "file") {
|
|
350
|
-
const fileContext = options.fileText?.({ message, part, partIndex });
|
|
351
|
-
if (fileContext) {
|
|
352
|
-
content.push({ type: "text", text: fileContext });
|
|
353
|
-
}
|
|
354
|
-
const resolved = options.fileData?.({ message, part, partIndex });
|
|
355
|
-
if (resolved) {
|
|
356
|
-
const projection = resolved instanceof URL ? { data: resolved } : resolved;
|
|
357
|
-
content.push({
|
|
358
|
-
type: "file",
|
|
359
|
-
data: projection.data,
|
|
360
|
-
mediaType: projection.mediaType ?? part.fileRef.mediaType ?? "application/octet-stream",
|
|
361
|
-
...projection.filename !== undefined ? { filename: projection.filename } : part.fileRef.fileName === undefined ? {} : { filename: part.fileRef.fileName },
|
|
362
|
-
...part.providerMetadata === undefined ? {} : { providerData: part.providerMetadata }
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
return { role: "user", content };
|
|
368
|
-
}
|
|
369
|
-
function appendAssistantModelMessages(result, message, options) {
|
|
370
|
-
let block = [];
|
|
371
|
-
const flush = () => {
|
|
372
|
-
if (block.length === 0) {
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
const current = block;
|
|
376
|
-
block = [];
|
|
377
|
-
const content = [];
|
|
378
|
-
for (const { part, partIndex } of current) {
|
|
379
|
-
if (part.type === "text") {
|
|
380
|
-
content.push({
|
|
381
|
-
type: "text",
|
|
382
|
-
text: part.text,
|
|
383
|
-
...part.providerMetadata === undefined ? {} : { providerData: part.providerMetadata }
|
|
384
|
-
});
|
|
385
|
-
} else if (part.type === "reasoning") {
|
|
386
|
-
content.push({
|
|
387
|
-
type: "reasoning",
|
|
388
|
-
text: part.text,
|
|
389
|
-
...part.providerMetadata === undefined ? {} : { providerData: part.providerMetadata }
|
|
390
|
-
});
|
|
391
|
-
} else if (part.type === "file") {
|
|
392
|
-
const fileContext = options.fileText?.({ message, part, partIndex });
|
|
393
|
-
if (fileContext) {
|
|
394
|
-
content.push({ type: "text", text: fileContext });
|
|
395
|
-
}
|
|
396
|
-
} else if (part.type === "tool-call") {
|
|
397
|
-
content.push(toolCallModelPart(part));
|
|
398
|
-
if (part.providerExecuted === true) {
|
|
399
|
-
content.push(toolResultModelPart(message, part, partIndex, "json", options));
|
|
400
|
-
}
|
|
401
|
-
} else if (part.type === "provider-state") {
|
|
402
|
-
content.push({
|
|
403
|
-
type: "provider-state",
|
|
404
|
-
providerId: part.providerId,
|
|
405
|
-
data: part.data
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
result.push({ role: "assistant", content });
|
|
410
|
-
const toolResults = current.flatMap(({ part, partIndex }) => part.type === "tool-call" && part.providerExecuted !== true ? [toolResultModelPart(message, part, partIndex, "text", options)] : []);
|
|
411
|
-
if (toolResults.length > 0) {
|
|
412
|
-
result.push({ role: "tool", content: toolResults });
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
message.parts.forEach((part, partIndex) => {
|
|
416
|
-
if (part.type === "step-start") {
|
|
417
|
-
flush();
|
|
418
|
-
} else {
|
|
419
|
-
block.push({ part, partIndex });
|
|
420
|
-
}
|
|
421
|
-
});
|
|
422
|
-
flush();
|
|
423
|
-
}
|
|
424
|
-
function toolCallModelPart(part) {
|
|
425
|
-
return {
|
|
426
|
-
type: "tool-call",
|
|
427
|
-
toolCallId: part.toolCallId,
|
|
428
|
-
toolName: part.toolName,
|
|
429
|
-
input: part.input,
|
|
430
|
-
...part.providerExecuted === undefined ? {} : { providerExecuted: part.providerExecuted },
|
|
431
|
-
...part.providerMetadata === undefined ? {} : { providerData: part.providerMetadata }
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
function toolResultModelPart(message, part, partIndex, errorMode, options) {
|
|
435
|
-
return {
|
|
436
|
-
type: "tool-result",
|
|
437
|
-
toolCallId: part.toolCallId,
|
|
438
|
-
toolName: part.toolName,
|
|
439
|
-
output: toolResultOutput(message, part, partIndex, errorMode, options)
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
function toolResultOutput(message, part, partIndex, errorMode, options) {
|
|
443
|
-
if (part.state === "output-error") {
|
|
444
|
-
return errorMode === "json" ? { type: "error-json", value: part.errorText } : { type: "error-text", value: part.errorText };
|
|
445
|
-
}
|
|
446
|
-
if (isAgentToolResult(part.output)) {
|
|
447
|
-
const value = [];
|
|
448
|
-
part.output.content.forEach((contentPart, contentIndex) => {
|
|
449
|
-
if (contentPart.type === "text") {
|
|
450
|
-
value.push(contentPart.text);
|
|
451
|
-
return;
|
|
452
|
-
}
|
|
453
|
-
const fileContext = options.toolResultFileText?.({
|
|
454
|
-
message,
|
|
455
|
-
part,
|
|
456
|
-
partIndex,
|
|
457
|
-
contentPart,
|
|
458
|
-
contentIndex
|
|
459
|
-
});
|
|
460
|
-
value.push(fileContext ?? toolResultFileFallbackText(contentPart));
|
|
461
|
-
});
|
|
462
|
-
return { type: "text", value: value.join(`
|
|
463
|
-
`) };
|
|
464
|
-
}
|
|
465
|
-
return typeof part.output === "string" ? { type: "text", value: part.output } : { type: "json", value: part.output };
|
|
466
|
-
}
|
|
467
|
-
function toolResultFileFallbackText(part) {
|
|
468
|
-
const attributes = [
|
|
469
|
-
part.fileRef.fileName ? `name=${JSON.stringify(part.fileRef.fileName)}` : undefined,
|
|
470
|
-
part.fileRef.mediaType ? `mediaType=${JSON.stringify(part.fileRef.mediaType)}` : undefined,
|
|
471
|
-
`sizeBytes=${part.fileRef.sizeBytes}`
|
|
472
|
-
].filter((value) => value !== undefined);
|
|
473
|
-
return `[Tool-created file: ${attributes.join(" ")}. Contents are not available inline.]`;
|
|
474
|
-
}
|
|
475
|
-
function isTextPart(part) {
|
|
476
|
-
return part.type === "text";
|
|
477
|
-
}
|
|
478
|
-
// src/agents/api-gateway.ts
|
|
479
|
-
import { createHmac, timingSafeEqual } from "crypto";
|
|
480
|
-
var AGENT_API_GATEWAY_PREFIX = "/__sixb/agent-api";
|
|
481
|
-
var AGENT_API_GATEWAY_CAPABILITY_PREFIX = "sixb_agw_v1_";
|
|
482
|
-
var AGENT_API_ROUTES = SIXB_API_ROUTES.filter((route) => route.agentApi).map((route) => ({ method: route.method, path: route.path }));
|
|
483
|
-
function createAgentApiGatewayCapability(input) {
|
|
484
|
-
return `${AGENT_API_GATEWAY_CAPABILITY_PREFIX}${capabilityDigest(input)}`;
|
|
485
|
-
}
|
|
486
|
-
function isValidAgentApiGatewayCapability(input) {
|
|
487
|
-
const expected = createAgentApiGatewayCapability(input);
|
|
488
|
-
const actual = input.capability;
|
|
489
|
-
const expectedBuffer = Buffer.from(expected);
|
|
490
|
-
const actualBuffer = Buffer.from(actual);
|
|
491
|
-
return expectedBuffer.byteLength === actualBuffer.byteLength && timingSafeEqual(expectedBuffer, actualBuffer);
|
|
492
|
-
}
|
|
493
|
-
function isAllowedAgentApiRequest(method, pathname) {
|
|
494
|
-
const normalizedMethod = method.toUpperCase();
|
|
495
|
-
const normalizedPath = normalizeRoutePath(pathname);
|
|
496
|
-
return AGENT_API_ROUTES.some((route) => route.method === normalizedMethod && matchesPathPattern(normalizedPath, route.path));
|
|
497
|
-
}
|
|
498
|
-
function capabilityDigest(input) {
|
|
499
|
-
return createHmac("sha256", input.executionToken).update(`agent-api-gateway:${input.projectId}:${input.runId}`).digest("base64url");
|
|
500
|
-
}
|
|
501
|
-
// src/agents/validation.ts
|
|
502
|
-
var AGENT_TOOL_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]{0,63}$/;
|
|
503
|
-
var AGENT_TOOL_PRIMITIVE_SCHEMAS = new Set([
|
|
504
|
-
"string",
|
|
505
|
-
"integer",
|
|
506
|
-
"double",
|
|
507
|
-
"decimal",
|
|
508
|
-
"boolean",
|
|
509
|
-
"date",
|
|
510
|
-
"timestamp",
|
|
511
|
-
"uuid",
|
|
512
|
-
"fileRef"
|
|
513
|
-
]);
|
|
514
|
-
var AGENT_RESERVED_TOOL_NAMES = [
|
|
515
|
-
"bash",
|
|
516
|
-
"read",
|
|
517
|
-
"view_file",
|
|
518
|
-
"spawn_agent",
|
|
519
|
-
"wait_agent"
|
|
520
|
-
];
|
|
521
|
-
function isAgentToolDefinition(value) {
|
|
522
|
-
return isRecord(value) && value.kind === "agentTool" && typeof value.name === "string" && typeof value.description === "string" && isPlainRecord(value.input) && typeof value.handler === "function";
|
|
523
|
-
}
|
|
524
|
-
function assertValidAgentToolName(name) {
|
|
525
|
-
if (typeof name !== "string" || !AGENT_TOOL_NAME_PATTERN.test(name)) {
|
|
526
|
-
throw new AgentDefinitionError("[Sixb] Agent tool name must be 1-64 characters, start with a letter or underscore, and contain only letters, numbers, underscores, or hyphens.");
|
|
527
|
-
}
|
|
528
|
-
if (AGENT_RESERVED_TOOL_NAMES.includes(name)) {
|
|
529
|
-
throw new AgentDefinitionError(`[Sixb] Agent tool name '${name}' is reserved by the framework.`);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
function assertValidAgentToolDescription(name, description) {
|
|
533
|
-
if (typeof description !== "string" || !description.trim()) {
|
|
534
|
-
throw new AgentDefinitionError(`[Sixb] Agent tool '${name}' description must not be empty.`);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
function assertValidAgentToolInput(name, input) {
|
|
538
|
-
if (!isPlainRecord(input)) {
|
|
539
|
-
throw new AgentDefinitionError(`[Sixb] Agent tool '${name}' input must be a schema object.`);
|
|
540
|
-
}
|
|
541
|
-
for (const [field, schema] of Object.entries(input)) {
|
|
542
|
-
if (!field.trim()) {
|
|
543
|
-
throw new AgentDefinitionError(`[Sixb] Agent tool '${name}' input field names must not be empty.`);
|
|
544
|
-
}
|
|
545
|
-
assertValidAgentToolSchema(name, schema, `input.${field}`, new Set);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
function validateAndSnapshotAgentToolInput(toolName, input) {
|
|
549
|
-
assertValidAgentToolInput(toolName, input);
|
|
550
|
-
try {
|
|
551
|
-
return deepFreeze(structuredClone(input));
|
|
552
|
-
} catch {
|
|
553
|
-
throw new AgentDefinitionError(`[Sixb] Agent tool '${toolName}' input must be safely snapshot-compatible.`);
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
function validateAndNormalizeAgentToolInput(toolName, shape, value, valueTypesById) {
|
|
557
|
-
const label = `Agent tool '${toolName}' input`;
|
|
558
|
-
if (!isPlainRecord(value)) {
|
|
559
|
-
throw new OntologyValidationError(`[Sixb] ${label} must be a JSON object.`);
|
|
560
|
-
}
|
|
561
|
-
const reason = getInvalidJsonValueReason(value, label);
|
|
562
|
-
if (reason) {
|
|
563
|
-
throw new OntologyValidationError(`[Sixb] ${label} must be JSON-compatible; ${reason}.`);
|
|
564
|
-
}
|
|
565
|
-
const schema = {
|
|
566
|
-
type: "object",
|
|
567
|
-
properties: Object.fromEntries(Object.entries(shape).map(([field, fieldSchema]) => [
|
|
568
|
-
field,
|
|
569
|
-
{ schema: fieldSchema, required: true }
|
|
570
|
-
]))
|
|
571
|
-
};
|
|
572
|
-
validateSchemaValue(schema, value, label, valueTypesById);
|
|
573
|
-
return deepFreeze(normalizeSchemaValue(schema, value, label, valueTypesById));
|
|
574
|
-
}
|
|
575
|
-
function assertValidAgentToolSchema(toolName, schema, path, visiting) {
|
|
576
|
-
if (typeof schema === "string") {
|
|
577
|
-
if (AGENT_TOOL_PRIMITIVE_SCHEMAS.has(schema)) {
|
|
578
|
-
return;
|
|
579
|
-
}
|
|
580
|
-
throw invalidAgentToolSchema(toolName, path);
|
|
581
|
-
}
|
|
582
|
-
if (!isPlainRecord(schema) || typeof schema.type !== "string" || visiting.has(schema)) {
|
|
583
|
-
throw invalidAgentToolSchema(toolName, path);
|
|
584
|
-
}
|
|
585
|
-
visiting.add(schema);
|
|
586
|
-
switch (schema.type) {
|
|
587
|
-
case "enum": {
|
|
588
|
-
const values = schema.values;
|
|
589
|
-
const validValues = isValidAgentToolEnumValues(values, schema.valueType);
|
|
590
|
-
if (!validValues || new Set(values).size !== values.length) {
|
|
591
|
-
throw invalidAgentToolSchema(toolName, path);
|
|
592
|
-
}
|
|
593
|
-
break;
|
|
594
|
-
}
|
|
595
|
-
case "array":
|
|
596
|
-
assertValidAgentToolSchema(toolName, schema.items, `${path}.items`, visiting);
|
|
597
|
-
break;
|
|
598
|
-
case "map":
|
|
599
|
-
if (schema.keySchema !== "string") {
|
|
600
|
-
throw invalidAgentToolSchema(toolName, path);
|
|
601
|
-
}
|
|
602
|
-
assertValidAgentToolSchema(toolName, schema.valueSchema, `${path}.valueSchema`, visiting);
|
|
603
|
-
break;
|
|
604
|
-
case "object": {
|
|
605
|
-
if (!isPlainRecord(schema.properties)) {
|
|
606
|
-
throw invalidAgentToolSchema(toolName, path);
|
|
607
|
-
}
|
|
608
|
-
for (const [fieldId, field] of Object.entries(schema.properties)) {
|
|
609
|
-
if (!fieldId.trim() || !isPlainRecord(field) || !("schema" in field)) {
|
|
610
|
-
throw invalidAgentToolSchema(toolName, `${path}.properties.${fieldId}`);
|
|
611
|
-
}
|
|
612
|
-
if (field.required !== undefined && typeof field.required !== "boolean" || field.nullable !== undefined && typeof field.nullable !== "boolean" || field.description !== undefined && (typeof field.description !== "string" || !field.description.trim())) {
|
|
613
|
-
throw invalidAgentToolSchema(toolName, `${path}.properties.${fieldId}`);
|
|
614
|
-
}
|
|
615
|
-
assertValidAgentToolSchema(toolName, field.schema, `${path}.properties.${fieldId}.schema`, visiting);
|
|
616
|
-
}
|
|
617
|
-
break;
|
|
618
|
-
}
|
|
619
|
-
case "valueTypeRef":
|
|
620
|
-
if (typeof schema.valueTypeId !== "string" || !schema.valueTypeId.trim()) {
|
|
621
|
-
throw invalidAgentToolSchema(toolName, path);
|
|
622
|
-
}
|
|
623
|
-
if (schema._resolved !== undefined) {
|
|
624
|
-
assertValidAgentToolSchema(toolName, schema._resolved, `${path}._resolved`, visiting);
|
|
625
|
-
}
|
|
626
|
-
break;
|
|
627
|
-
default:
|
|
628
|
-
throw invalidAgentToolSchema(toolName, path);
|
|
629
|
-
}
|
|
630
|
-
visiting.delete(schema);
|
|
631
|
-
}
|
|
632
|
-
function invalidAgentToolSchema(toolName, path) {
|
|
633
|
-
return new AgentDefinitionError(`[Sixb] Agent tool '${toolName}' ${path} must be a valid Sixb schema.`);
|
|
634
|
-
}
|
|
635
|
-
function assertValidProjectAgentToolDefinitions(tools) {
|
|
636
|
-
assertValidAgentToolDefinitionList(tools, {
|
|
637
|
-
invalidDefinitions: "[Sixb] Project tools must contain only agent tool definitions.",
|
|
638
|
-
duplicateName: (name) => `[Sixb] Project tools contain duplicate tool name '${name}'.`
|
|
639
|
-
});
|
|
640
|
-
}
|
|
641
|
-
function assertValidAgentToolDefinitionList(tools, messages) {
|
|
642
|
-
const seen = new Set;
|
|
643
|
-
for (let index = 0;index < tools.length; index += 1) {
|
|
644
|
-
const tool = tools[index];
|
|
645
|
-
if (!Object.hasOwn(tools, index) || !isAgentToolDefinition(tool)) {
|
|
646
|
-
throw new AgentDefinitionError(messages.invalidDefinitions);
|
|
647
|
-
}
|
|
648
|
-
assertValidAgentToolName(tool.name);
|
|
649
|
-
assertValidAgentToolDescription(tool.name, tool.description);
|
|
650
|
-
assertValidAgentToolInput(tool.name, tool.input);
|
|
651
|
-
if (seen.has(tool.name)) {
|
|
652
|
-
throw new AgentDefinitionError(messages.duplicateName(tool.name));
|
|
653
|
-
}
|
|
654
|
-
seen.add(tool.name);
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
function isValidAgentToolEnumValues(values, valueType) {
|
|
658
|
-
if (!Array.isArray(values) || values.length === 0) {
|
|
659
|
-
return false;
|
|
660
|
-
}
|
|
661
|
-
for (let index = 0;index < values.length; index += 1) {
|
|
662
|
-
if (!Object.hasOwn(values, index)) {
|
|
663
|
-
return false;
|
|
664
|
-
}
|
|
665
|
-
const value = values[index];
|
|
666
|
-
if (valueType === "string" ? typeof value !== "string" : valueType !== "integer" || typeof value !== "number" || !Number.isInteger(value)) {
|
|
667
|
-
return false;
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
return true;
|
|
671
|
-
}
|
|
672
|
-
function deepFreeze(value, seen = new Set) {
|
|
673
|
-
if (value === null || typeof value !== "object" || seen.has(value)) {
|
|
674
|
-
return value;
|
|
675
|
-
}
|
|
676
|
-
seen.add(value);
|
|
677
|
-
for (const key of Reflect.ownKeys(value)) {
|
|
678
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
679
|
-
if (descriptor && "value" in descriptor) {
|
|
680
|
-
deepFreeze(descriptor.value, seen);
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
return Object.freeze(value);
|
|
684
|
-
}
|
|
685
|
-
function isRecord(value) {
|
|
686
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
// src/agents/tool-definition.ts
|
|
690
|
-
var EMPTY_AGENT_TOOLS = Object.freeze([]);
|
|
691
|
-
var normalizedAgentTools = new WeakSet;
|
|
692
|
-
function createAgentToolDefinition(definition) {
|
|
693
|
-
assertValidAgentToolName(definition.name);
|
|
694
|
-
assertValidAgentToolDescription(definition.name, definition.description);
|
|
695
|
-
if (typeof definition.handler !== "function") {
|
|
696
|
-
throw new AgentDefinitionError(`[Sixb] Agent tool '${definition.name}' handler must be a function.`);
|
|
697
|
-
}
|
|
698
|
-
const input = validateAndSnapshotAgentToolInput(definition.name, definition.input);
|
|
699
|
-
const tool = {
|
|
700
|
-
kind: "agentTool",
|
|
701
|
-
name: definition.name,
|
|
702
|
-
description: definition.description,
|
|
703
|
-
input,
|
|
704
|
-
handler: async (context) => {
|
|
705
|
-
const result = await definition.handler(context);
|
|
706
|
-
let snapshot;
|
|
707
|
-
try {
|
|
708
|
-
snapshot = cloneJsonValue(result, "result");
|
|
709
|
-
} catch (cause) {
|
|
710
|
-
throw new AgentToolResultValidationError(definition.name, getInvalidJsonValueReason(result, "result") ?? "result could not be cloned safely", { cause });
|
|
711
|
-
}
|
|
712
|
-
const richResultReason = getInvalidAgentToolResultReason(snapshot);
|
|
713
|
-
if (richResultReason) {
|
|
714
|
-
throw new AgentToolResultValidationError(definition.name, richResultReason);
|
|
715
|
-
}
|
|
716
|
-
return snapshot;
|
|
717
|
-
}
|
|
718
|
-
};
|
|
719
|
-
normalizedAgentTools.add(tool);
|
|
720
|
-
return Object.freeze(tool);
|
|
721
|
-
}
|
|
722
|
-
function toolsFromProjectConfig(tools) {
|
|
723
|
-
if (tools === undefined) {
|
|
724
|
-
return EMPTY_AGENT_TOOLS;
|
|
725
|
-
}
|
|
726
|
-
if (!Array.isArray(tools)) {
|
|
727
|
-
throw new AgentDefinitionError("[Sixb] Project tools must be an array of agent tool definitions.");
|
|
728
|
-
}
|
|
729
|
-
assertValidProjectAgentToolDefinitions(tools);
|
|
730
|
-
return normalizeAgentToolDefinitions(tools);
|
|
731
|
-
}
|
|
732
|
-
function normalizeAgentToolDefinitions(tools) {
|
|
733
|
-
const normalized = [];
|
|
734
|
-
for (const tool of tools) {
|
|
735
|
-
normalized.push(normalizeAgentToolDefinition(tool));
|
|
736
|
-
}
|
|
737
|
-
return Object.freeze(normalized);
|
|
738
|
-
}
|
|
739
|
-
function normalizeAgentToolDefinition(tool) {
|
|
740
|
-
if (normalizedAgentTools.has(tool)) {
|
|
741
|
-
return tool;
|
|
742
|
-
}
|
|
743
|
-
return createAgentToolDefinition({
|
|
744
|
-
name: tool.name,
|
|
745
|
-
description: tool.description,
|
|
746
|
-
input: tool.input,
|
|
747
|
-
handler: (context) => tool.handler(context)
|
|
748
|
-
});
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
// src/agents/builders.ts
|
|
752
|
-
function defineAgentTool(name) {
|
|
753
|
-
assertValidAgentToolName(name);
|
|
754
|
-
return {
|
|
755
|
-
description(description) {
|
|
756
|
-
assertValidAgentToolDescription(name, description);
|
|
757
|
-
return {
|
|
758
|
-
input(input) {
|
|
759
|
-
assertValidAgentToolInput(name, input);
|
|
760
|
-
return {
|
|
761
|
-
run(handler) {
|
|
762
|
-
return createAgentToolDefinition({ name, description, input, handler });
|
|
763
|
-
}
|
|
764
|
-
};
|
|
765
|
-
}
|
|
766
|
-
};
|
|
767
|
-
}
|
|
768
|
-
};
|
|
769
|
-
}
|
|
770
|
-
// src/agents/context-compaction.ts
|
|
771
|
-
var AGENT_CONTEXT_ESTIMATOR_VERSION = 1;
|
|
772
|
-
var CHARS_PER_TOKEN = 4;
|
|
773
|
-
var REQUEST_OVERHEAD_TOKENS = 8;
|
|
774
|
-
var MESSAGE_OVERHEAD_TOKENS = 8;
|
|
775
|
-
var TOOL_OVERHEAD_TOKENS = 16;
|
|
776
|
-
var STEP_OVERHEAD_TOKENS = 2;
|
|
777
|
-
var IMAGE_ALLOWANCE_TOKENS = 1200;
|
|
778
|
-
var FILE_TEXT_INLINE_MAX_BYTES = 50 * 1024;
|
|
779
|
-
var FILE_TEXT_INLINE_TOTAL_MAX_BYTES = 200 * 1024;
|
|
780
|
-
var TOOL_RESULT_SUMMARY_MAX_CHARS = 2000;
|
|
781
|
-
function shouldCompactAgentContext(input) {
|
|
782
|
-
return input.estimatedInputTokens > input.inputBudgetTokens;
|
|
783
|
-
}
|
|
784
|
-
function estimateAgentContextRequestTokens(input) {
|
|
785
|
-
const toolTokens = input.tools.reduce((total, tool) => total + TOOL_OVERHEAD_TOKENS + textTokens(tool.name) + textTokens(tool.description) + textTokens(tool.inputSchema), 0);
|
|
786
|
-
return {
|
|
787
|
-
tokens: REQUEST_OVERHEAD_TOKENS + textTokens(input.systemPrompt) + toolTokens + estimateAgentContextMessagesTokens(input.messages).tokens,
|
|
788
|
-
estimatorVersion: AGENT_CONTEXT_ESTIMATOR_VERSION
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
|
-
function estimateAgentContextMessagesTokens(messages) {
|
|
792
|
-
const attachments = { textBytesRemaining: FILE_TEXT_INLINE_TOTAL_MAX_BYTES };
|
|
793
|
-
let tokens = 0;
|
|
794
|
-
for (const message of messages) {
|
|
795
|
-
tokens += estimateMessageTokens(message, attachments);
|
|
796
|
-
}
|
|
797
|
-
return { tokens, estimatorVersion: AGENT_CONTEXT_ESTIMATOR_VERSION };
|
|
798
|
-
}
|
|
799
|
-
function selectAgentContextCompactionBoundary(input) {
|
|
800
|
-
if (input.messages.length < 2)
|
|
801
|
-
return null;
|
|
802
|
-
let retainedTokens = 0;
|
|
803
|
-
let boundaryIndex = null;
|
|
804
|
-
let closestDistance = Number.POSITIVE_INFINITY;
|
|
805
|
-
for (let index = input.messages.length - 1;index > 0; index -= 1) {
|
|
806
|
-
retainedTokens += estimateAgentContextMessagesTokens([input.messages[index]]).tokens;
|
|
807
|
-
if (input.messages[index]?.role !== "user")
|
|
808
|
-
continue;
|
|
809
|
-
const distance = Math.abs(input.keepRecentTokens - retainedTokens);
|
|
810
|
-
if (distance <= closestDistance) {
|
|
811
|
-
boundaryIndex = index;
|
|
812
|
-
closestDistance = distance;
|
|
813
|
-
}
|
|
814
|
-
if (retainedTokens >= input.keepRecentTokens)
|
|
815
|
-
break;
|
|
816
|
-
}
|
|
817
|
-
if (boundaryIndex === null)
|
|
818
|
-
return null;
|
|
819
|
-
const summarizedThroughSeq = input.messages[boundaryIndex - 1]?.seq;
|
|
820
|
-
if (summarizedThroughSeq === undefined)
|
|
821
|
-
return null;
|
|
822
|
-
return {
|
|
823
|
-
messagesToSummarize: input.messages.slice(0, boundaryIndex),
|
|
824
|
-
retainedMessages: input.messages.slice(boundaryIndex),
|
|
825
|
-
summarizedThroughSeq
|
|
826
|
-
};
|
|
827
|
-
}
|
|
828
|
-
function serializeAgentMessagesForSummary(messages) {
|
|
829
|
-
const lines = ["<sixb_conversation_history>"];
|
|
830
|
-
for (const message of messages) {
|
|
831
|
-
lines.push(` <message id="${escapeXml2(message.id)}" seq="${message.seq}" role="${message.role}">`);
|
|
832
|
-
message.parts.forEach((part, partIndex) => {
|
|
833
|
-
lines.push(...serializeSummaryPart(message, part, partIndex));
|
|
834
|
-
});
|
|
835
|
-
lines.push(" </message>");
|
|
836
|
-
}
|
|
837
|
-
lines.push("</sixb_conversation_history>");
|
|
838
|
-
return lines.join(`
|
|
839
|
-
`);
|
|
840
|
-
}
|
|
841
|
-
function estimateMessageTokens(message, attachments) {
|
|
842
|
-
let tokens = MESSAGE_OVERHEAD_TOKENS;
|
|
843
|
-
for (const part of message.parts) {
|
|
844
|
-
switch (part.type) {
|
|
845
|
-
case "text":
|
|
846
|
-
case "reasoning":
|
|
847
|
-
tokens += textTokens(part.text);
|
|
848
|
-
break;
|
|
849
|
-
case "step-start":
|
|
850
|
-
tokens += STEP_OVERHEAD_TOKENS;
|
|
851
|
-
break;
|
|
852
|
-
case "context":
|
|
853
|
-
tokens += textTokens(stableJsonStringify(part.context));
|
|
854
|
-
break;
|
|
855
|
-
case "provider-state":
|
|
856
|
-
tokens += textTokens(stableJsonStringify(part.data));
|
|
857
|
-
break;
|
|
858
|
-
case "tool-call":
|
|
859
|
-
tokens += TOOL_OVERHEAD_TOKENS + textTokens(part.toolName) + textTokens(stableJsonStringify(part.input)) + (part.state === "output-available" ? textTokens(stableJsonStringify(part.output)) : textTokens(part.errorText));
|
|
860
|
-
break;
|
|
861
|
-
case "file": {
|
|
862
|
-
const file = part.fileRef;
|
|
863
|
-
tokens += textTokens([file.blobId, file.digest, file.fileName, file.mediaType, file.logicalPath].filter((value) => value !== undefined).join(" "));
|
|
864
|
-
if (message.role !== "assistant") {
|
|
865
|
-
if (looksLikeImage(file.mediaType, file.fileName)) {
|
|
866
|
-
tokens += IMAGE_ALLOWANCE_TOKENS;
|
|
867
|
-
} else {
|
|
868
|
-
const inlineBytes = Math.min(file.sizeBytes, FILE_TEXT_INLINE_MAX_BYTES, attachments.textBytesRemaining);
|
|
869
|
-
attachments.textBytesRemaining -= inlineBytes;
|
|
870
|
-
tokens += Math.ceil(inlineBytes / CHARS_PER_TOKEN);
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
break;
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
return tokens;
|
|
878
|
-
}
|
|
879
|
-
function serializeSummaryPart(message, part, partIndex) {
|
|
880
|
-
const indent = " ";
|
|
881
|
-
switch (part.type) {
|
|
882
|
-
case "text":
|
|
883
|
-
return [`${indent}<text>${escapeXml2(part.text)}</text>`];
|
|
884
|
-
case "reasoning":
|
|
885
|
-
case "provider-state":
|
|
886
|
-
case "step-start":
|
|
887
|
-
return [];
|
|
888
|
-
case "context":
|
|
889
|
-
return part.context.kind === "object" ? [
|
|
890
|
-
`${indent}<object_context origin="${part.origin}" object_type_id="${escapeXml2(part.context.ref.objectTypeId)}" primary_id="${escapeXml2(part.context.ref.primaryId)}" />`
|
|
891
|
-
] : [
|
|
892
|
-
`${indent}<app_context origin="${part.origin}" id="${escapeXml2(part.context.id)}" label="${escapeXml2(part.context.label)}">`,
|
|
893
|
-
`${indent} <description>${escapeXml2(part.context.description)}</description>`,
|
|
894
|
-
`${indent} <value format="json">${escapeXml2(stableJsonStringify(part.context.value))}</value>`,
|
|
895
|
-
`${indent}</app_context>`
|
|
896
|
-
];
|
|
897
|
-
case "file": {
|
|
898
|
-
const file = part.fileRef;
|
|
899
|
-
const attributes = [
|
|
900
|
-
`message_id="${escapeXml2(message.id)}"`,
|
|
901
|
-
`part_index="${partIndex}"`,
|
|
902
|
-
`blob_id="${escapeXml2(file.blobId)}"`,
|
|
903
|
-
`digest="${escapeXml2(file.digest)}"`,
|
|
904
|
-
`size_bytes="${file.sizeBytes}"`,
|
|
905
|
-
...file.fileName === undefined ? [] : [`file_name="${escapeXml2(file.fileName)}"`],
|
|
906
|
-
...file.mediaType === undefined ? [] : [`media_type="${escapeXml2(file.mediaType)}"`],
|
|
907
|
-
...file.logicalPath === undefined ? [] : [`logical_path="${escapeXml2(file.logicalPath)}"`]
|
|
908
|
-
];
|
|
909
|
-
return [`${indent}<file ${attributes.join(" ")} />`];
|
|
910
|
-
}
|
|
911
|
-
case "tool-call": {
|
|
912
|
-
const output = part.state === "output-available" ? truncateToolResult(stableJsonStringify(part.output)) : truncateToolResult(part.errorText);
|
|
913
|
-
return [
|
|
914
|
-
`${indent}<tool_call id="${escapeXml2(part.toolCallId)}" name="${escapeXml2(part.toolName)}" state="${part.state}">`,
|
|
915
|
-
`${indent} <input format="json">${escapeXml2(stableJsonStringify(part.input))}</input>`,
|
|
916
|
-
`${indent} <result>${escapeXml2(output)}</result>`,
|
|
917
|
-
`${indent}</tool_call>`
|
|
918
|
-
];
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
function truncateToolResult(value) {
|
|
923
|
-
if (value.length <= TOOL_RESULT_SUMMARY_MAX_CHARS)
|
|
924
|
-
return value;
|
|
925
|
-
return `${value.slice(0, TOOL_RESULT_SUMMARY_MAX_CHARS)}
|
|
926
|
-
[truncated ${value.length - TOOL_RESULT_SUMMARY_MAX_CHARS} characters]`;
|
|
927
|
-
}
|
|
928
|
-
function looksLikeImage(mediaType, fileName) {
|
|
929
|
-
if (mediaType?.toLowerCase().startsWith("image/"))
|
|
930
|
-
return true;
|
|
931
|
-
return /\.(?:avif|gif|jpe?g|png|webp)$/i.test(fileName ?? "");
|
|
932
|
-
}
|
|
933
|
-
function textTokens(value) {
|
|
934
|
-
return Math.ceil(new TextEncoder().encode(value).byteLength / CHARS_PER_TOKEN);
|
|
935
|
-
}
|
|
936
|
-
function escapeXml2(value) {
|
|
937
|
-
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
938
|
-
}
|
|
939
|
-
// src/agents/model-loop.ts
|
|
940
|
-
import { randomUUID } from "crypto";
|
|
941
|
-
var MAX_PROVIDER_DATA_BYTES = 256 * 1024;
|
|
942
|
-
async function runModelLoop(input) {
|
|
943
|
-
assertLoopInput(input);
|
|
944
|
-
const tools = indexTools(input.tools ?? []);
|
|
945
|
-
const toolSpecifications = [...tools.values()].map((tool) => ({
|
|
946
|
-
name: tool.name,
|
|
947
|
-
description: tool.description,
|
|
948
|
-
inputSchema: tool.inputSchema
|
|
949
|
-
}));
|
|
950
|
-
let messages = [...input.messages];
|
|
951
|
-
const steps = [];
|
|
952
|
-
const generateCallId = input.generateCallId ?? (() => `model_call_${randomUUID()}`);
|
|
953
|
-
const callIds = new Set;
|
|
954
|
-
for (let stepIndex = 0;stepIndex < input.maxSteps; stepIndex += 1) {
|
|
955
|
-
if (input.signal.aborted) {
|
|
956
|
-
return { status: "aborted", steps, partialContent: [] };
|
|
957
|
-
}
|
|
958
|
-
await input.onEvent?.({ type: "start-step" });
|
|
959
|
-
let requestMessages;
|
|
960
|
-
try {
|
|
961
|
-
const prepared = await input.prepareStep?.({
|
|
962
|
-
stepIndex,
|
|
963
|
-
messages,
|
|
964
|
-
model: input.model,
|
|
965
|
-
signal: input.signal
|
|
966
|
-
});
|
|
967
|
-
requestMessages = prepared?.messages ?? messages;
|
|
968
|
-
} catch (error) {
|
|
969
|
-
if (!input.signal.aborted && !isAbortError(error))
|
|
970
|
-
throw error;
|
|
971
|
-
return { status: "aborted", steps, partialContent: [] };
|
|
972
|
-
}
|
|
973
|
-
if (input.signal.aborted) {
|
|
974
|
-
return { status: "aborted", steps, partialContent: [] };
|
|
975
|
-
}
|
|
976
|
-
let requestTools = toolSpecifications;
|
|
977
|
-
if (input.finalStepInstruction !== undefined && stepIndex === input.maxSteps - 1) {
|
|
978
|
-
requestMessages = [
|
|
979
|
-
...requestMessages,
|
|
980
|
-
{ role: "user", content: [{ type: "text", text: input.finalStepInstruction }] }
|
|
981
|
-
];
|
|
982
|
-
requestTools = [];
|
|
983
|
-
}
|
|
984
|
-
const callId = generateCallId();
|
|
985
|
-
if (!callId || callIds.has(callId)) {
|
|
986
|
-
throw new ModelStreamError(`[SixbModels] Model call IDs must be nonempty and unique.`);
|
|
987
|
-
}
|
|
988
|
-
callIds.add(callId);
|
|
989
|
-
const accumulator = new StreamAccumulator(input.onEvent);
|
|
990
|
-
let accepted = false;
|
|
991
|
-
let cost = { status: "unpriceable", reason: "missing-usage" };
|
|
992
|
-
let terminalStreamError;
|
|
993
|
-
try {
|
|
994
|
-
const stream = await input.model.stream({
|
|
995
|
-
callId,
|
|
996
|
-
messages: requestMessages,
|
|
997
|
-
tools: requestTools,
|
|
998
|
-
...input.reasoning === undefined ? {} : { reasoning: input.reasoning },
|
|
999
|
-
...input.maxOutputTokens === undefined ? {} : { maxOutputTokens: input.maxOutputTokens },
|
|
1000
|
-
...input.caching === undefined ? {} : { caching: input.caching },
|
|
1001
|
-
...input.output === undefined ? {} : {
|
|
1002
|
-
responseFormat: {
|
|
1003
|
-
type: "json",
|
|
1004
|
-
name: input.output.name,
|
|
1005
|
-
...input.output.description === undefined ? {} : { description: input.output.description },
|
|
1006
|
-
schema: input.output.schema
|
|
1007
|
-
}
|
|
1008
|
-
},
|
|
1009
|
-
signal: input.signal
|
|
1010
|
-
});
|
|
1011
|
-
accepted = true;
|
|
1012
|
-
for await (const event of stream.events) {
|
|
1013
|
-
await accumulator.accept(event);
|
|
1014
|
-
}
|
|
1015
|
-
} catch (error) {
|
|
1016
|
-
const aborted = input.signal.aborted || isAbortError(error);
|
|
1017
|
-
if (accumulator.isFinished()) {
|
|
1018
|
-
if (!aborted)
|
|
1019
|
-
terminalStreamError = { error };
|
|
1020
|
-
} else if (!aborted) {
|
|
1021
|
-
throw error;
|
|
1022
|
-
} else {
|
|
1023
|
-
return {
|
|
1024
|
-
status: "aborted",
|
|
1025
|
-
steps,
|
|
1026
|
-
partialContent: accumulator.partialContent()
|
|
1027
|
-
};
|
|
1028
|
-
}
|
|
1029
|
-
} finally {
|
|
1030
|
-
if (accepted) {
|
|
1031
|
-
const facts = accumulator.accounting();
|
|
1032
|
-
const estimate = accumulator.isFinished() ? estimateModelCall(input.model, facts) : cost;
|
|
1033
|
-
cost = facts.reportedCost ? rateModelCall({ usage: facts.usage, reported: facts.reportedCost }) : estimate;
|
|
1034
|
-
await input.onModelCallEnd?.({
|
|
1035
|
-
callId,
|
|
1036
|
-
providerId: input.model.providerId,
|
|
1037
|
-
modelId: input.model.modelId,
|
|
1038
|
-
responseId: facts.responseId ?? `${callId}:response`,
|
|
1039
|
-
providerIds: facts.providerIds,
|
|
1040
|
-
responseModelId: facts.responseModelId,
|
|
1041
|
-
usage: facts.usage,
|
|
1042
|
-
cost,
|
|
1043
|
-
...facts.reportedCost === undefined ? {} : { estimate },
|
|
1044
|
-
...input.reasoning === undefined ? {} : { requestedReasoning: input.reasoning },
|
|
1045
|
-
...facts.route === undefined ? {} : { route: facts.route }
|
|
1046
|
-
});
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
if (input.signal.aborted && !accumulator.isFinished()) {
|
|
1050
|
-
return { status: "aborted", steps, partialContent: accumulator.partialContent() };
|
|
1051
|
-
}
|
|
1052
|
-
const response = accumulator.complete();
|
|
1053
|
-
const responseId = response.responseId ?? `${callId}:response`;
|
|
1054
|
-
if (terminalStreamError)
|
|
1055
|
-
throw terminalStreamError.error;
|
|
1056
|
-
if (response.projectionError)
|
|
1057
|
-
throw response.projectionError;
|
|
1058
|
-
if (input.signal.aborted) {
|
|
1059
|
-
return { status: "aborted", steps, partialContent: response.content };
|
|
1060
|
-
}
|
|
1061
|
-
const localCalls = response.toolCalls.filter((call) => call.part.providerExecuted !== true);
|
|
1062
|
-
if (response.finishReason === "pause" && localCalls.length === 0) {
|
|
1063
|
-
const step2 = modelStep(response, responseId, response.content, cost);
|
|
1064
|
-
steps.push(step2);
|
|
1065
|
-
await input.onStepEnd?.(step2);
|
|
1066
|
-
messages = [...requestMessages, { role: "assistant", content: response.content }];
|
|
1067
|
-
if (stepIndex + 1 === input.maxSteps) {
|
|
1068
|
-
throw new ModelStreamError("[SixbModels] Model reached the step limit while a provider continuation was pending.");
|
|
1069
|
-
}
|
|
1070
|
-
continue;
|
|
1071
|
-
}
|
|
1072
|
-
if (localCalls.length === 0) {
|
|
1073
|
-
const step2 = modelStep(response, responseId, response.content, cost);
|
|
1074
|
-
steps.push(step2);
|
|
1075
|
-
await input.onStepEnd?.(step2);
|
|
1076
|
-
if (input.output) {
|
|
1077
|
-
const text = responseText(response);
|
|
1078
|
-
if (response.finishReason !== "stop") {
|
|
1079
|
-
throw new StructuredOutputError(`[SixbModels] Structured output did not complete successfully (${response.finishReason}).`, structuredOutputErrorContext(input, response, responseId, cost, text));
|
|
1080
|
-
}
|
|
1081
|
-
let raw;
|
|
1082
|
-
try {
|
|
1083
|
-
raw = JSON.parse(text);
|
|
1084
|
-
} catch (error) {
|
|
1085
|
-
throw new StructuredOutputError("[SixbModels] Model did not produce valid JSON output.", {
|
|
1086
|
-
cause: error,
|
|
1087
|
-
...structuredOutputErrorContext(input, response, responseId, cost, text)
|
|
1088
|
-
});
|
|
1089
|
-
}
|
|
1090
|
-
try {
|
|
1091
|
-
return {
|
|
1092
|
-
status: "completed",
|
|
1093
|
-
output: input.output.validate(raw),
|
|
1094
|
-
steps,
|
|
1095
|
-
finishReason: response.finishReason
|
|
1096
|
-
};
|
|
1097
|
-
} catch (error) {
|
|
1098
|
-
throw new StructuredOutputError("[SixbModels] Structured output validation failed.", {
|
|
1099
|
-
cause: error,
|
|
1100
|
-
...structuredOutputErrorContext(input, response, responseId, cost, text)
|
|
1101
|
-
});
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
const output = responseText(response);
|
|
1105
|
-
return { status: "completed", output, steps, finishReason: response.finishReason };
|
|
1106
|
-
}
|
|
1107
|
-
const toolResults = await Promise.all(localCalls.map((call) => executeToolCall(call, tools, callId, input.signal, input.onEvent)));
|
|
1108
|
-
const step = modelStep(response, responseId, [...response.content, ...toolResults], cost);
|
|
1109
|
-
steps.push(step);
|
|
1110
|
-
await input.onStepEnd?.(step);
|
|
1111
|
-
if (input.signal.aborted) {
|
|
1112
|
-
return {
|
|
1113
|
-
status: "aborted",
|
|
1114
|
-
steps,
|
|
1115
|
-
partialContent: []
|
|
1116
|
-
};
|
|
1117
|
-
}
|
|
1118
|
-
const assistantContent = response.content.filter((part) => part.type !== "tool-result" || part.providerExecuted === true);
|
|
1119
|
-
messages = [
|
|
1120
|
-
...requestMessages,
|
|
1121
|
-
{ role: "assistant", content: assistantContent },
|
|
1122
|
-
{ role: "tool", content: toolResults }
|
|
1123
|
-
];
|
|
1124
|
-
if (stepIndex + 1 === input.maxSteps) {
|
|
1125
|
-
if (input.output) {
|
|
1126
|
-
throw new StructuredOutputError("[SixbModels] Model reached the step limit without structured output.", structuredOutputErrorContext(input, response, responseId, cost, responseText(response)));
|
|
1127
|
-
}
|
|
1128
|
-
const output = responseText(response);
|
|
1129
|
-
return { status: "completed", output, steps, finishReason: response.finishReason };
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
throw new ModelStreamError("[SixbModels] Model loop exited without a terminal result.");
|
|
1133
|
-
}
|
|
1134
|
-
function assertLoopInput(input) {
|
|
1135
|
-
if (input.maxOutputTokens !== undefined && (!Number.isSafeInteger(input.maxOutputTokens) || input.maxOutputTokens <= 0)) {
|
|
1136
|
-
throw new TypeError("[SixbModels] maxOutputTokens must be a positive safe integer.");
|
|
1137
|
-
}
|
|
1138
|
-
if (!Number.isInteger(input.maxSteps) || input.maxSteps <= 0) {
|
|
1139
|
-
throw new TypeError("[SixbModels] maxSteps must be a positive integer.");
|
|
1140
|
-
}
|
|
1141
|
-
if (!input.model.providerId.trim() || !input.model.modelId.trim()) {
|
|
1142
|
-
throw new TypeError("[SixbModels] Model providerId and modelId must not be empty.");
|
|
1143
|
-
}
|
|
1144
|
-
if (input.model.definition.providerId !== input.model.providerId || input.model.definition.modelId !== input.model.modelId) {
|
|
1145
|
-
throw new TypeError(`[SixbModels] Model definition for '${input.model.providerId}/${input.model.modelId}' has a different identity.`);
|
|
1146
|
-
}
|
|
1147
|
-
if (input.output) {
|
|
1148
|
-
if (!input.output.name.trim()) {
|
|
1149
|
-
throw new TypeError("[SixbModels] Structured output names must not be empty.");
|
|
1150
|
-
}
|
|
1151
|
-
assertJsonObject(input.output.schema, "structured output schema");
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
function indexTools(tools) {
|
|
1155
|
-
const result = new Map;
|
|
1156
|
-
for (const tool of tools) {
|
|
1157
|
-
if (!tool.name.trim())
|
|
1158
|
-
throw new TypeError("[SixbModels] Tool names must not be empty.");
|
|
1159
|
-
if (result.has(tool.name)) {
|
|
1160
|
-
throw new TypeError(`[SixbModels] Duplicate tool name '${tool.name}'.`);
|
|
1161
|
-
}
|
|
1162
|
-
assertJsonObject(tool.inputSchema, `tool '${tool.name}' input schema`);
|
|
1163
|
-
result.set(tool.name, tool);
|
|
1164
|
-
}
|
|
1165
|
-
return result;
|
|
1166
|
-
}
|
|
1167
|
-
function responseText(response) {
|
|
1168
|
-
return response.content.filter((part) => part.type === "text").map((part) => part.text).join("");
|
|
1169
|
-
}
|
|
1170
|
-
function structuredOutputErrorContext(input, response, responseId, cost, text) {
|
|
1171
|
-
return {
|
|
1172
|
-
text,
|
|
1173
|
-
providerId: input.model.providerId,
|
|
1174
|
-
modelId: input.model.modelId,
|
|
1175
|
-
responseId,
|
|
1176
|
-
...response.responseModelId === undefined ? {} : { responseModelId: response.responseModelId },
|
|
1177
|
-
finishReason: response.finishReason,
|
|
1178
|
-
usage: response.usage,
|
|
1179
|
-
cost
|
|
1180
|
-
};
|
|
1181
|
-
}
|
|
1182
|
-
function modelStep(response, responseId, content, cost) {
|
|
1183
|
-
return {
|
|
1184
|
-
content,
|
|
1185
|
-
finishReason: response.finishReason,
|
|
1186
|
-
...response.rawFinishReason === undefined ? {} : { rawFinishReason: response.rawFinishReason },
|
|
1187
|
-
usage: response.usage,
|
|
1188
|
-
responseId,
|
|
1189
|
-
...response.responseModelId === undefined ? {} : { responseModelId: response.responseModelId },
|
|
1190
|
-
cost,
|
|
1191
|
-
...response.route === undefined ? {} : { route: response.route }
|
|
1192
|
-
};
|
|
1193
|
-
}
|
|
1194
|
-
async function executeToolCall(call, tools, callId, signal, onEvent) {
|
|
1195
|
-
const { part } = call;
|
|
1196
|
-
if (call.inputError) {
|
|
1197
|
-
const errorText = `Tool input is not valid JSON: ${call.inputError.message}`;
|
|
1198
|
-
await onEvent?.({
|
|
1199
|
-
type: "tool-input-error",
|
|
1200
|
-
toolCallId: part.toolCallId,
|
|
1201
|
-
toolName: part.toolName,
|
|
1202
|
-
input: part.input,
|
|
1203
|
-
errorText
|
|
1204
|
-
});
|
|
1205
|
-
return toolErrorResult(part, errorText);
|
|
1206
|
-
}
|
|
1207
|
-
const tool = tools.get(part.toolName);
|
|
1208
|
-
if (!tool) {
|
|
1209
|
-
const errorText = `Tool '${part.toolName}' is not available.`;
|
|
1210
|
-
await onEvent?.({
|
|
1211
|
-
type: "tool-output-error",
|
|
1212
|
-
toolCallId: part.toolCallId,
|
|
1213
|
-
toolName: part.toolName,
|
|
1214
|
-
errorText
|
|
1215
|
-
});
|
|
1216
|
-
return toolErrorResult(part, errorText);
|
|
1217
|
-
}
|
|
1218
|
-
let parsed;
|
|
1219
|
-
try {
|
|
1220
|
-
parsed = tool.parseInput(part.input);
|
|
1221
|
-
} catch (error) {
|
|
1222
|
-
const errorText = error instanceof Error ? error.message : "Tool input validation failed.";
|
|
1223
|
-
await onEvent?.({
|
|
1224
|
-
type: "tool-input-error",
|
|
1225
|
-
toolCallId: part.toolCallId,
|
|
1226
|
-
toolName: part.toolName,
|
|
1227
|
-
input: part.input,
|
|
1228
|
-
errorText
|
|
1229
|
-
});
|
|
1230
|
-
return toolErrorResult(part, errorText);
|
|
1231
|
-
}
|
|
1232
|
-
await onEvent?.({
|
|
1233
|
-
type: "tool-input-available",
|
|
1234
|
-
toolCallId: part.toolCallId,
|
|
1235
|
-
toolName: part.toolName,
|
|
1236
|
-
input: part.input
|
|
1237
|
-
});
|
|
1238
|
-
let output;
|
|
1239
|
-
let modelOutput;
|
|
1240
|
-
try {
|
|
1241
|
-
const context = { signal, callId, toolCallId: part.toolCallId };
|
|
1242
|
-
output = await tool.execute(parsed, context);
|
|
1243
|
-
assertJsonValue(output, `tool '${part.toolName}' output`);
|
|
1244
|
-
modelOutput = tool.toModelOutput ? await tool.toModelOutput(output, context) : modelToolOutput(output);
|
|
1245
|
-
validateModelToolOutput(modelOutput, part.toolName);
|
|
1246
|
-
} catch (error) {
|
|
1247
|
-
const errorText = tool.errorText(error);
|
|
1248
|
-
await onEvent?.({
|
|
1249
|
-
type: "tool-output-error",
|
|
1250
|
-
toolCallId: part.toolCallId,
|
|
1251
|
-
toolName: part.toolName,
|
|
1252
|
-
errorText
|
|
1253
|
-
});
|
|
1254
|
-
return toolErrorResult(part, errorText);
|
|
1255
|
-
}
|
|
1256
|
-
await onEvent?.({
|
|
1257
|
-
type: "tool-output-available",
|
|
1258
|
-
toolCallId: part.toolCallId,
|
|
1259
|
-
toolName: part.toolName,
|
|
1260
|
-
output
|
|
1261
|
-
});
|
|
1262
|
-
return {
|
|
1263
|
-
type: "tool-result",
|
|
1264
|
-
toolCallId: part.toolCallId,
|
|
1265
|
-
toolName: part.toolName,
|
|
1266
|
-
output: modelOutput,
|
|
1267
|
-
...modelOutputMatchesOriginal(modelOutput, output) ? {} : { originalOutput: output }
|
|
1268
|
-
};
|
|
1269
|
-
}
|
|
1270
|
-
function validateModelToolOutput(output, toolName) {
|
|
1271
|
-
if (output.type === "text" || output.type === "error-text") {
|
|
1272
|
-
if (typeof output.value !== "string") {
|
|
1273
|
-
throw new TypeError(`[SixbModels] Tool '${toolName}' model output must contain text.`);
|
|
1274
|
-
}
|
|
1275
|
-
return;
|
|
1276
|
-
}
|
|
1277
|
-
assertJsonValue(output.value, `tool '${toolName}' model output`);
|
|
1278
|
-
}
|
|
1279
|
-
function modelOutputMatchesOriginal(output, original) {
|
|
1280
|
-
if (output.type === "text")
|
|
1281
|
-
return typeof original === "string" && output.value === original;
|
|
1282
|
-
if (output.type === "json")
|
|
1283
|
-
return output.value === original;
|
|
1284
|
-
return false;
|
|
1285
|
-
}
|
|
1286
|
-
function modelToolOutput(value) {
|
|
1287
|
-
return typeof value === "string" ? { type: "text", value } : { type: "json", value };
|
|
1288
|
-
}
|
|
1289
|
-
function toolErrorResult(part, errorText) {
|
|
1290
|
-
return {
|
|
1291
|
-
type: "tool-result",
|
|
1292
|
-
toolCallId: part.toolCallId,
|
|
1293
|
-
toolName: part.toolName,
|
|
1294
|
-
output: { type: "error-text", value: errorText }
|
|
1295
|
-
};
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
class StreamAccumulator {
|
|
1299
|
-
onEvent;
|
|
1300
|
-
parts = [];
|
|
1301
|
-
spans = new Map;
|
|
1302
|
-
toolCalls = new Map;
|
|
1303
|
-
started = false;
|
|
1304
|
-
finished = false;
|
|
1305
|
-
finishReason;
|
|
1306
|
-
rawFinishReason;
|
|
1307
|
-
usage = {};
|
|
1308
|
-
responseId;
|
|
1309
|
-
providerIds;
|
|
1310
|
-
responseModelId;
|
|
1311
|
-
projectionError;
|
|
1312
|
-
reportedCost;
|
|
1313
|
-
route;
|
|
1314
|
-
constructor(onEvent) {
|
|
1315
|
-
this.onEvent = onEvent;
|
|
1316
|
-
}
|
|
1317
|
-
isFinished() {
|
|
1318
|
-
return this.finished;
|
|
1319
|
-
}
|
|
1320
|
-
async accept(event) {
|
|
1321
|
-
if (this.finished) {
|
|
1322
|
-
throw new ModelStreamError(`[SixbModels] Received '${event.type}' after stream finish.`);
|
|
1323
|
-
}
|
|
1324
|
-
switch (event.type) {
|
|
1325
|
-
case "stream-start":
|
|
1326
|
-
if (this.started)
|
|
1327
|
-
throw new ModelStreamError("[SixbModels] Duplicate stream-start event.");
|
|
1328
|
-
this.started = true;
|
|
1329
|
-
return;
|
|
1330
|
-
case "response-metadata":
|
|
1331
|
-
this.requireStarted(event.type);
|
|
1332
|
-
this.responseId = event.id ?? this.responseId;
|
|
1333
|
-
if (event.providerIds)
|
|
1334
|
-
this.providerIds = { ...this.providerIds, ...event.providerIds };
|
|
1335
|
-
this.responseModelId = event.modelId ?? this.responseModelId;
|
|
1336
|
-
return;
|
|
1337
|
-
case "text-start":
|
|
1338
|
-
await this.startText(event);
|
|
1339
|
-
return;
|
|
1340
|
-
case "text-delta":
|
|
1341
|
-
await this.appendText(event, "text");
|
|
1342
|
-
return;
|
|
1343
|
-
case "text-end":
|
|
1344
|
-
await this.endText(event, "text");
|
|
1345
|
-
return;
|
|
1346
|
-
case "reasoning-start":
|
|
1347
|
-
await this.startReasoning(event);
|
|
1348
|
-
return;
|
|
1349
|
-
case "reasoning-delta":
|
|
1350
|
-
await this.appendText(event, "reasoning");
|
|
1351
|
-
return;
|
|
1352
|
-
case "reasoning-end":
|
|
1353
|
-
await this.endText(event, "reasoning");
|
|
1354
|
-
return;
|
|
1355
|
-
case "tool-input-start":
|
|
1356
|
-
await this.startTool(event);
|
|
1357
|
-
return;
|
|
1358
|
-
case "tool-input-delta":
|
|
1359
|
-
await this.appendTool(event);
|
|
1360
|
-
return;
|
|
1361
|
-
case "tool-input-end":
|
|
1362
|
-
this.endTool(event);
|
|
1363
|
-
return;
|
|
1364
|
-
case "tool-call":
|
|
1365
|
-
await this.completeTool(event);
|
|
1366
|
-
return;
|
|
1367
|
-
case "tool-result":
|
|
1368
|
-
this.addProviderToolResult(event);
|
|
1369
|
-
return;
|
|
1370
|
-
case "provider-state":
|
|
1371
|
-
if (this.captureProviderState(event.data)) {
|
|
1372
|
-
this.parts.push({
|
|
1373
|
-
type: "provider-state",
|
|
1374
|
-
providerId: event.providerId,
|
|
1375
|
-
data: event.data
|
|
1376
|
-
});
|
|
1377
|
-
}
|
|
1378
|
-
return;
|
|
1379
|
-
case "finish":
|
|
1380
|
-
this.requireStarted(event.type);
|
|
1381
|
-
validateUsage(event.usage);
|
|
1382
|
-
this.captureProviderData(event.providerData);
|
|
1383
|
-
this.finished = true;
|
|
1384
|
-
this.finishReason = event.finishReason;
|
|
1385
|
-
this.rawFinishReason = event.rawFinishReason;
|
|
1386
|
-
this.usage = event.usage;
|
|
1387
|
-
this.reportedCost = event.reportedCost;
|
|
1388
|
-
this.route = event.route;
|
|
1389
|
-
return;
|
|
1390
|
-
case "error":
|
|
1391
|
-
throw event.error instanceof Error ? event.error : new ModelProviderError("[SixbModels] Provider stream failed.", "unknown", "unknown", {
|
|
1392
|
-
cause: event.error
|
|
1393
|
-
});
|
|
1394
|
-
}
|
|
1395
|
-
}
|
|
1396
|
-
complete() {
|
|
1397
|
-
if (!this.started)
|
|
1398
|
-
throw new ModelStreamError("[SixbModels] Stream did not start.");
|
|
1399
|
-
if (!this.finished || !this.finishReason) {
|
|
1400
|
-
throw new ModelStreamError("[SixbModels] Stream ended without a finish event.");
|
|
1401
|
-
}
|
|
1402
|
-
for (const part of this.parts) {
|
|
1403
|
-
if ("complete" in part && !part.complete) {
|
|
1404
|
-
throw new ModelStreamError(`[SixbModels] Stream finished with incomplete ${part.type} content.`);
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
const parsed = this.parseParts(false);
|
|
1408
|
-
return {
|
|
1409
|
-
content: parsed.content,
|
|
1410
|
-
toolCalls: parsed.toolCalls,
|
|
1411
|
-
finishReason: this.finishReason,
|
|
1412
|
-
...this.rawFinishReason === undefined ? {} : { rawFinishReason: this.rawFinishReason },
|
|
1413
|
-
...this.accounting(),
|
|
1414
|
-
...this.projectionError === undefined ? {} : { projectionError: this.projectionError }
|
|
1415
|
-
};
|
|
1416
|
-
}
|
|
1417
|
-
accounting() {
|
|
1418
|
-
return {
|
|
1419
|
-
usage: this.usage,
|
|
1420
|
-
...this.responseId === undefined ? {} : { responseId: this.responseId },
|
|
1421
|
-
...this.providerIds === undefined ? {} : { providerIds: this.providerIds },
|
|
1422
|
-
...this.responseModelId === undefined ? {} : { responseModelId: this.responseModelId },
|
|
1423
|
-
...this.reportedCost === undefined ? {} : { reportedCost: this.reportedCost },
|
|
1424
|
-
...this.route === undefined ? {} : { route: this.route }
|
|
1425
|
-
};
|
|
1426
|
-
}
|
|
1427
|
-
partialContent() {
|
|
1428
|
-
return this.parseParts(true).content;
|
|
1429
|
-
}
|
|
1430
|
-
parseParts(partial) {
|
|
1431
|
-
const content = [];
|
|
1432
|
-
const toolCalls = [];
|
|
1433
|
-
for (const part of this.parts) {
|
|
1434
|
-
if (part.type === "text") {
|
|
1435
|
-
if ((!partial || part.text.length > 0) && (part.complete || partial)) {
|
|
1436
|
-
content.push({
|
|
1437
|
-
type: "text",
|
|
1438
|
-
text: part.text,
|
|
1439
|
-
...part.providerData === undefined ? {} : { providerData: part.providerData }
|
|
1440
|
-
});
|
|
1441
|
-
}
|
|
1442
|
-
} else if (part.type === "reasoning") {
|
|
1443
|
-
if (part.complete) {
|
|
1444
|
-
content.push({
|
|
1445
|
-
type: "reasoning",
|
|
1446
|
-
text: part.text,
|
|
1447
|
-
...part.providerData === undefined ? {} : { providerData: part.providerData }
|
|
1448
|
-
});
|
|
1449
|
-
}
|
|
1450
|
-
} else if (part.type === "tool-call") {
|
|
1451
|
-
if (!part.complete)
|
|
1452
|
-
continue;
|
|
1453
|
-
let value = null;
|
|
1454
|
-
let inputError;
|
|
1455
|
-
try {
|
|
1456
|
-
const parsed = JSON.parse(part.inputText);
|
|
1457
|
-
if (!isJsonValue(parsed))
|
|
1458
|
-
throw new TypeError("input is not a JSON value");
|
|
1459
|
-
value = parsed;
|
|
1460
|
-
} catch (error) {
|
|
1461
|
-
inputError = error instanceof Error ? error : new Error(String(error));
|
|
1462
|
-
}
|
|
1463
|
-
const call = {
|
|
1464
|
-
type: "tool-call",
|
|
1465
|
-
toolCallId: part.toolCallId,
|
|
1466
|
-
toolName: part.toolName,
|
|
1467
|
-
input: value,
|
|
1468
|
-
...part.providerData === undefined ? {} : { providerData: part.providerData },
|
|
1469
|
-
...part.providerExecuted === undefined ? {} : { providerExecuted: part.providerExecuted },
|
|
1470
|
-
...part.dynamic === undefined ? {} : { dynamic: part.dynamic }
|
|
1471
|
-
};
|
|
1472
|
-
content.push(call);
|
|
1473
|
-
toolCalls.push({ part: call, ...inputError === undefined ? {} : { inputError } });
|
|
1474
|
-
} else {
|
|
1475
|
-
content.push(part);
|
|
1476
|
-
}
|
|
1477
|
-
}
|
|
1478
|
-
return { content, toolCalls };
|
|
1479
|
-
}
|
|
1480
|
-
async startText(event) {
|
|
1481
|
-
this.requireStarted(event.type);
|
|
1482
|
-
this.assertNewSpan(event.id);
|
|
1483
|
-
const providerData = this.captureProviderData(event.providerData);
|
|
1484
|
-
const part = {
|
|
1485
|
-
type: "text",
|
|
1486
|
-
text: "",
|
|
1487
|
-
complete: false,
|
|
1488
|
-
...providerData === undefined ? {} : { providerData }
|
|
1489
|
-
};
|
|
1490
|
-
this.spans.set(event.id, part);
|
|
1491
|
-
this.parts.push(part);
|
|
1492
|
-
await this.onEvent?.({ type: "text-start", id: event.id });
|
|
1493
|
-
}
|
|
1494
|
-
async startReasoning(event) {
|
|
1495
|
-
this.requireStarted(event.type);
|
|
1496
|
-
this.assertNewSpan(event.id);
|
|
1497
|
-
const providerData = this.captureProviderData(event.providerData);
|
|
1498
|
-
const part = {
|
|
1499
|
-
type: "reasoning",
|
|
1500
|
-
text: "",
|
|
1501
|
-
complete: false,
|
|
1502
|
-
...providerData === undefined ? {} : { providerData }
|
|
1503
|
-
};
|
|
1504
|
-
this.spans.set(event.id, part);
|
|
1505
|
-
this.parts.push(part);
|
|
1506
|
-
await this.onEvent?.({ type: "reasoning-start", id: event.id });
|
|
1507
|
-
}
|
|
1508
|
-
async appendText(event, expected) {
|
|
1509
|
-
const part = this.spans.get(event.id);
|
|
1510
|
-
if (!part || part.type !== expected || part.complete) {
|
|
1511
|
-
throw new ModelStreamError(`[SixbModels] ${event.type} references unopened ${expected} span '${event.id}'.`);
|
|
1512
|
-
}
|
|
1513
|
-
part.text += event.delta;
|
|
1514
|
-
await this.onEvent?.({ type: event.type, id: event.id, delta: event.delta });
|
|
1515
|
-
}
|
|
1516
|
-
async endText(event, expected) {
|
|
1517
|
-
const part = this.spans.get(event.id);
|
|
1518
|
-
if (!part || part.type !== expected || part.complete) {
|
|
1519
|
-
throw new ModelStreamError(`[SixbModels] ${event.type} references unopened ${expected} span '${event.id}'.`);
|
|
1520
|
-
}
|
|
1521
|
-
part.providerData = mergeProviderData(part.providerData, this.captureProviderData(event.providerData));
|
|
1522
|
-
part.complete = true;
|
|
1523
|
-
this.spans.delete(event.id);
|
|
1524
|
-
await this.onEvent?.({ type: event.type, id: event.id });
|
|
1525
|
-
}
|
|
1526
|
-
async startTool(event) {
|
|
1527
|
-
this.requireStarted(event.type);
|
|
1528
|
-
if (!event.id || !event.toolName) {
|
|
1529
|
-
throw new ModelStreamError("[SixbModels] Tool calls require nonempty IDs and names.");
|
|
1530
|
-
}
|
|
1531
|
-
if (this.toolCalls.has(event.id)) {
|
|
1532
|
-
throw new ModelStreamError(`[SixbModels] Duplicate tool call ID '${event.id}'.`);
|
|
1533
|
-
}
|
|
1534
|
-
const providerData = this.captureProviderData(event.providerData);
|
|
1535
|
-
const part = {
|
|
1536
|
-
type: "tool-call",
|
|
1537
|
-
toolCallId: event.id,
|
|
1538
|
-
toolName: event.toolName,
|
|
1539
|
-
inputText: "",
|
|
1540
|
-
complete: false,
|
|
1541
|
-
...providerData === undefined ? {} : { providerData },
|
|
1542
|
-
...event.providerExecuted === undefined ? {} : { providerExecuted: event.providerExecuted },
|
|
1543
|
-
...event.dynamic === undefined ? {} : { dynamic: event.dynamic }
|
|
1544
|
-
};
|
|
1545
|
-
this.toolCalls.set(event.id, part);
|
|
1546
|
-
this.parts.push(part);
|
|
1547
|
-
await this.onEvent?.({
|
|
1548
|
-
type: "tool-input-start",
|
|
1549
|
-
toolCallId: event.id,
|
|
1550
|
-
toolName: event.toolName
|
|
1551
|
-
});
|
|
1552
|
-
}
|
|
1553
|
-
async appendTool(event) {
|
|
1554
|
-
const part = this.toolCalls.get(event.id);
|
|
1555
|
-
if (!part || part.complete) {
|
|
1556
|
-
throw new ModelStreamError(`[SixbModels] tool-input-delta references unopened tool call '${event.id}'.`);
|
|
1557
|
-
}
|
|
1558
|
-
part.inputText += event.delta;
|
|
1559
|
-
await this.onEvent?.({
|
|
1560
|
-
type: "tool-input-delta",
|
|
1561
|
-
toolCallId: event.id,
|
|
1562
|
-
toolName: part.toolName,
|
|
1563
|
-
inputTextDelta: event.delta
|
|
1564
|
-
});
|
|
1565
|
-
}
|
|
1566
|
-
endTool(event) {
|
|
1567
|
-
const part = this.toolCalls.get(event.id);
|
|
1568
|
-
if (!part || part.complete) {
|
|
1569
|
-
throw new ModelStreamError(`[SixbModels] tool-input-end references unopened tool call '${event.id}'.`);
|
|
1570
|
-
}
|
|
1571
|
-
part.providerData = mergeProviderData(part.providerData, this.captureProviderData(event.providerData));
|
|
1572
|
-
part.complete = true;
|
|
1573
|
-
}
|
|
1574
|
-
async completeTool(event) {
|
|
1575
|
-
await this.startTool({
|
|
1576
|
-
type: "tool-input-start",
|
|
1577
|
-
id: event.toolCallId,
|
|
1578
|
-
toolName: event.toolName,
|
|
1579
|
-
...event.providerData === undefined ? {} : { providerData: event.providerData },
|
|
1580
|
-
...event.providerExecuted === undefined ? {} : { providerExecuted: event.providerExecuted },
|
|
1581
|
-
...event.dynamic === undefined ? {} : { dynamic: event.dynamic }
|
|
1582
|
-
});
|
|
1583
|
-
const part = this.toolCalls.get(event.toolCallId);
|
|
1584
|
-
if (!part)
|
|
1585
|
-
throw new ModelStreamError("[SixbModels] Failed to index completed tool call.");
|
|
1586
|
-
part.inputText = event.input;
|
|
1587
|
-
part.complete = true;
|
|
1588
|
-
}
|
|
1589
|
-
addProviderToolResult(event) {
|
|
1590
|
-
if (!this.captureJsonValue(event.output, "provider tool result"))
|
|
1591
|
-
return;
|
|
1592
|
-
const providerData = this.captureProviderData(event.providerData);
|
|
1593
|
-
this.parts.push({
|
|
1594
|
-
type: "tool-result",
|
|
1595
|
-
toolCallId: event.toolCallId,
|
|
1596
|
-
toolName: event.toolName,
|
|
1597
|
-
output: event.isError ? { type: "error-json", value: event.output } : modelToolOutput(event.output),
|
|
1598
|
-
providerExecuted: event.providerExecuted ?? true,
|
|
1599
|
-
...event.dynamic === undefined ? {} : { dynamic: event.dynamic },
|
|
1600
|
-
...providerData === undefined ? {} : { providerData }
|
|
1601
|
-
});
|
|
1602
|
-
}
|
|
1603
|
-
captureProviderData(data) {
|
|
1604
|
-
if (data === undefined)
|
|
1605
|
-
return;
|
|
1606
|
-
try {
|
|
1607
|
-
validateProviderData(data);
|
|
1608
|
-
return data;
|
|
1609
|
-
} catch (error) {
|
|
1610
|
-
this.captureProjectionError(error);
|
|
1611
|
-
return;
|
|
1612
|
-
}
|
|
1613
|
-
}
|
|
1614
|
-
captureProviderState(value) {
|
|
1615
|
-
if (!this.captureJsonValue(value, "provider state"))
|
|
1616
|
-
return false;
|
|
1617
|
-
if (JSON.stringify(value).length > MAX_PROVIDER_DATA_BYTES) {
|
|
1618
|
-
this.captureProjectionError(new ModelStreamError(`[SixbModels] Provider state exceeds the ${MAX_PROVIDER_DATA_BYTES}-byte response limit.`));
|
|
1619
|
-
return false;
|
|
1620
|
-
}
|
|
1621
|
-
return true;
|
|
1622
|
-
}
|
|
1623
|
-
captureJsonValue(value, label) {
|
|
1624
|
-
try {
|
|
1625
|
-
assertJsonValue(value, label);
|
|
1626
|
-
return true;
|
|
1627
|
-
} catch (error) {
|
|
1628
|
-
this.captureProjectionError(error);
|
|
1629
|
-
return false;
|
|
1630
|
-
}
|
|
1631
|
-
}
|
|
1632
|
-
captureProjectionError(error) {
|
|
1633
|
-
this.projectionError ??= error instanceof Error ? error : new Error(String(error));
|
|
1634
|
-
}
|
|
1635
|
-
requireStarted(type) {
|
|
1636
|
-
if (!this.started) {
|
|
1637
|
-
throw new ModelStreamError(`[SixbModels] Received '${type}' before stream-start.`);
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
assertNewSpan(id) {
|
|
1641
|
-
if (!id)
|
|
1642
|
-
throw new ModelStreamError("[SixbModels] Content span IDs must not be empty.");
|
|
1643
|
-
if (this.spans.has(id)) {
|
|
1644
|
-
throw new ModelStreamError(`[SixbModels] Duplicate open content span '${id}'.`);
|
|
1645
|
-
}
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
function validateUsage(usage) {
|
|
1649
|
-
for (const [key, value] of Object.entries(usage)) {
|
|
1650
|
-
if (key === "raw") {
|
|
1651
|
-
if (value !== undefined)
|
|
1652
|
-
assertJsonValue(value, "raw model usage");
|
|
1653
|
-
continue;
|
|
1654
|
-
}
|
|
1655
|
-
if (value !== undefined && (!Number.isSafeInteger(value) || value < 0)) {
|
|
1656
|
-
throw new ModelStreamError(`[SixbModels] Usage field '${key}' must be a nonnegative integer.`);
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
}
|
|
1660
|
-
function validateProviderData(data) {
|
|
1661
|
-
if (data === undefined)
|
|
1662
|
-
return;
|
|
1663
|
-
assertJsonValue(data, "provider data");
|
|
1664
|
-
if (typeof data !== "object" || data === null || Array.isArray(data)) {
|
|
1665
|
-
throw new TypeError("[SixbModels] provider data must be a JSON object.");
|
|
1666
|
-
}
|
|
1667
|
-
if (JSON.stringify(data).length > MAX_PROVIDER_DATA_BYTES) {
|
|
1668
|
-
throw new ModelStreamError(`[SixbModels] Provider data exceeds the ${MAX_PROVIDER_DATA_BYTES}-byte response limit.`);
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
function mergeProviderData(first, second) {
|
|
1672
|
-
if (first === undefined)
|
|
1673
|
-
return second;
|
|
1674
|
-
if (second === undefined)
|
|
1675
|
-
return first;
|
|
1676
|
-
return { ...first, ...second };
|
|
1677
|
-
}
|
|
1678
|
-
function isAbortError(error) {
|
|
1679
|
-
return error instanceof DOMException && error.name === "AbortError" || error instanceof Error && error.name === "AbortError";
|
|
1680
|
-
}
|
|
1681
|
-
// src/agents/reference.ts
|
|
1682
|
-
var agent = Object.freeze({
|
|
1683
|
-
kind: "agent",
|
|
1684
|
-
usage: Object.freeze({ kind: "aiUsage" })
|
|
1685
|
-
});
|
|
1686
|
-
// src/agents/thread-context-projection.ts
|
|
1687
|
-
function projectAgentThreadModelContext(input) {
|
|
1688
|
-
const { checkpoint, messages } = input;
|
|
1689
|
-
if (!checkpoint)
|
|
1690
|
-
return messages;
|
|
1691
|
-
assertConsistentCheckpointProjection(checkpoint, messages);
|
|
1692
|
-
return [
|
|
1693
|
-
{
|
|
1694
|
-
role: "user",
|
|
1695
|
-
parts: [{ type: "text", text: serializeThreadSummary(checkpoint.summary) }]
|
|
1696
|
-
},
|
|
1697
|
-
...messages
|
|
1698
|
-
];
|
|
1699
|
-
}
|
|
1700
|
-
function assertConsistentCheckpointProjection(checkpoint, messages) {
|
|
1701
|
-
if (checkpoint.summaryFormatVersion !== 1 || checkpoint.summary.trim().length === 0) {
|
|
1702
|
-
throw projectionError(checkpoint, "has an invalid summary");
|
|
1703
|
-
}
|
|
1704
|
-
if (checkpoint.summarizedThroughSeq >= checkpoint.observedHeadSeq) {
|
|
1705
|
-
throw projectionError(checkpoint, "does not retain its observed head");
|
|
1706
|
-
}
|
|
1707
|
-
if (messages.length === 0) {
|
|
1708
|
-
throw projectionError(checkpoint, "has no retained messages");
|
|
1709
|
-
}
|
|
1710
|
-
let expectedSeq = checkpoint.summarizedThroughSeq + 1;
|
|
1711
|
-
for (const message of messages) {
|
|
1712
|
-
if (message.projectId !== checkpoint.projectId || message.threadId !== checkpoint.threadId) {
|
|
1713
|
-
throw projectionError(checkpoint, "contains a message from another thread");
|
|
1714
|
-
}
|
|
1715
|
-
if (message.seq !== expectedSeq) {
|
|
1716
|
-
throw projectionError(checkpoint, `has a sequence gap before message '${message.id}'`);
|
|
1717
|
-
}
|
|
1718
|
-
expectedSeq += 1;
|
|
1719
|
-
}
|
|
1720
|
-
if (messages[0]?.role !== "user") {
|
|
1721
|
-
throw projectionError(checkpoint, "does not begin at a user turn boundary");
|
|
1722
|
-
}
|
|
1723
|
-
if ((messages.at(-1)?.seq ?? 0) < checkpoint.observedHeadSeq) {
|
|
1724
|
-
throw projectionError(checkpoint, "ends before the checkpoint's observed head");
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
function serializeThreadSummary(summary) {
|
|
1728
|
-
return [
|
|
1729
|
-
"The earlier conversation was compacted into this continuation summary.",
|
|
1730
|
-
"",
|
|
1731
|
-
"<sixb_thread_summary>",
|
|
1732
|
-
escapeXml3(summary),
|
|
1733
|
-
"</sixb_thread_summary>"
|
|
1734
|
-
].join(`
|
|
1735
|
-
`);
|
|
1736
|
-
}
|
|
1737
|
-
function projectionError(checkpoint, detail) {
|
|
1738
|
-
return new Error(`[Sixb] Agent context checkpoint '${checkpoint.id}' for thread '${checkpoint.threadId}' ${detail}.`);
|
|
1739
|
-
}
|
|
1740
|
-
function escapeXml3(value) {
|
|
1741
|
-
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
1742
|
-
}
|
|
1743
|
-
export { serializeAgentContextForModel, isAgentToolResult, omitUndefinedObjectProperties, fromUiMessage, toUiMessage, toModelMessages, AGENT_API_GATEWAY_PREFIX, AGENT_API_ROUTES, createAgentApiGatewayCapability, isValidAgentApiGatewayCapability, isAllowedAgentApiRequest, AGENT_RESERVED_TOOL_NAMES, isAgentToolDefinition, validateAndNormalizeAgentToolInput, toolsFromProjectConfig, defineAgentTool, AGENT_CONTEXT_ESTIMATOR_VERSION, shouldCompactAgentContext, estimateAgentContextRequestTokens, estimateAgentContextMessagesTokens, selectAgentContextCompactionBoundary, serializeAgentMessagesForSummary, runModelLoop, agent, projectAgentThreadModelContext };
|
|
1744
|
-
|
|
1745
|
-
//# debugId=3D89DCE6FB76677D64756E2164756E21
|