@sixb/core 0.1.8 → 0.1.10
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/index.js +77 -89
- package/dist/actions/index.js.map +1 -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 +3 -3
- 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/index.d.ts +4 -4
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +193 -204
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/message.d.ts +1 -1
- package/dist/agents/message.d.ts.map +1 -1
- package/dist/agents/model-loop.d.ts +2 -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/types.d.ts +1 -1
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/agents/validation.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 -108
- 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/index.js +51 -56
- 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 +14 -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 +80 -88
- package/dist/bootstrap/index.js.map +1 -1
- package/dist/broker/in-memory.d.ts +8 -2
- package/dist/broker/in-memory.d.ts.map +1 -1
- package/dist/broker/index.d.ts +4 -2
- package/dist/broker/index.d.ts.map +1 -1
- package/dist/broker/index.js +12 -10
- package/dist/broker/index.js.map +1 -1
- package/dist/broker/retention.d.ts +4 -0
- package/dist/broker/retention.d.ts.map +1 -0
- package/dist/broker/subscriber.d.ts +10 -0
- package/dist/broker/subscriber.d.ts.map +1 -0
- package/dist/broker/types.d.ts +14 -1
- package/dist/broker/types.d.ts.map +1 -1
- package/dist/chunk-0y39rgsb.js +43 -0
- package/dist/{chunk-c15dr03f.js.map → chunk-0y39rgsb.js.map} +2 -2
- package/dist/{chunk-k522z7v6.js → chunk-17kfctj6.js} +16 -11
- package/dist/chunk-17kfctj6.js.map +10 -0
- package/dist/{chunk-ajnan18g.js → chunk-1824gssz.js} +74 -106
- package/dist/chunk-1824gssz.js.map +12 -0
- package/dist/chunk-28ja2cjs.js +602 -0
- package/dist/chunk-28ja2cjs.js.map +18 -0
- package/dist/{chunk-5gd7tpv6.js → chunk-2c4j899j.js} +4 -4
- package/dist/chunk-2c4j899j.js.map +11 -0
- package/dist/{chunk-rv2hkwwa.js → chunk-358caqf5.js} +157 -180
- package/dist/chunk-358caqf5.js.map +12 -0
- package/dist/{chunk-fvt9rjsa.js → chunk-38zv5rkr.js} +4 -4
- package/dist/{chunk-fvt9rjsa.js.map → chunk-38zv5rkr.js.map} +1 -1
- 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-s5y30bc9.js → chunk-3qms4nax.js} +52 -50
- package/dist/{chunk-s5y30bc9.js.map → chunk-3qms4nax.js.map} +5 -5
- 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-wtf06et8.js → chunk-5c7ga8zz.js} +54 -177
- package/dist/chunk-5c7ga8zz.js.map +12 -0
- 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-xajtptbw.js → chunk-5p1v802y.js} +1401 -445
- package/dist/chunk-5p1v802y.js.map +44 -0
- 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-p1rzczbt.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-xhy826cz.js → chunk-85cd7e8c.js} +8 -7
- package/dist/chunk-85cd7e8c.js.map +10 -0
- package/dist/{chunk-pc7ys28c.js → chunk-860dwwy0.js} +29 -29
- package/dist/{chunk-pc7ys28c.js.map → chunk-860dwwy0.js.map} +2 -2
- 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-rafagrwr.js → chunk-93csa55g.js} +45 -17
- package/dist/chunk-93csa55g.js.map +11 -0
- package/dist/{chunk-aa2pen2v.js → chunk-976rxdpx.js} +188 -175
- package/dist/{chunk-aa2pen2v.js.map → chunk-976rxdpx.js.map} +2 -2
- package/dist/{chunk-d8qkxt2v.js → chunk-98cw09sw.js} +7 -7
- package/dist/chunk-98cw09sw.js.map +10 -0
- package/dist/{chunk-n4khvw9n.js → chunk-9qsh3p5y.js} +17 -17
- package/dist/{chunk-n4khvw9n.js.map → chunk-9qsh3p5y.js.map} +2 -2
- package/dist/{chunk-4a849fr1.js → chunk-9tc8dxmn.js} +1 -1
- package/dist/{chunk-9nbmsvn5.js → chunk-9vx5e9g1.js} +9 -9
- package/dist/{chunk-9nbmsvn5.js.map → chunk-9vx5e9g1.js.map} +2 -2
- package/dist/{chunk-8m5ejdpn.js → chunk-9x8dybsb.js} +5 -5
- package/dist/chunk-9x8dybsb.js.map +10 -0
- package/dist/chunk-aa6z4a19.js +358 -0
- package/dist/chunk-aa6z4a19.js.map +12 -0
- package/dist/{chunk-3xep5cjx.js → chunk-agbbygvh.js} +104 -86
- package/dist/chunk-agbbygvh.js.map +15 -0
- package/dist/{chunk-2dw777qw.js → chunk-ap0g1g74.js} +37 -82
- package/dist/{chunk-2dw777qw.js.map → chunk-ap0g1g74.js.map} +3 -4
- package/dist/{chunk-v4en4jc2.js → chunk-awbhdqyc.js} +7 -7
- package/dist/{chunk-v4en4jc2.js.map → chunk-awbhdqyc.js.map} +2 -2
- package/dist/{chunk-w9tg6yyb.js → chunk-b0ec55a1.js} +54 -37
- package/dist/chunk-b0ec55a1.js.map +12 -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-gbejpkex.js → chunk-bn138h9w.js} +27 -28
- package/dist/{chunk-gbejpkex.js.map → chunk-bn138h9w.js.map} +3 -3
- package/dist/{chunk-nx7k8tpr.js → chunk-br3k6qbf.js} +23 -23
- package/dist/{chunk-nx7k8tpr.js.map → chunk-br3k6qbf.js.map} +2 -2
- 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-5e3pq99w.js → chunk-dmn70ztd.js} +30 -30
- package/dist/chunk-dmn70ztd.js.map +11 -0
- package/dist/{chunk-p1x242ad.js → chunk-dz5h08xv.js} +175 -175
- package/dist/{chunk-p1x242ad.js.map → chunk-dz5h08xv.js.map} +2 -2
- 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-19jp6g9d.js → chunk-f0rwz2vh.js} +54 -33
- 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-f26bck4t.js → chunk-ftv470j8.js} +393 -355
- package/dist/{chunk-f26bck4t.js.map → chunk-ftv470j8.js.map} +7 -7
- package/dist/{chunk-4sm0aznx.js → chunk-g00bfdq6.js} +254 -256
- package/dist/{chunk-4sm0aznx.js.map → chunk-g00bfdq6.js.map} +3 -3
- 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-q0k9nc5a.js → chunk-g7knyczr.js} +98 -98
- package/dist/{chunk-q0k9nc5a.js.map → chunk-g7knyczr.js.map} +2 -2
- 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-8tsf6dmc.js → chunk-gqh45d2n.js} +244 -205
- package/dist/chunk-gqh45d2n.js.map +15 -0
- package/dist/chunk-h3v76ams.js +32 -0
- package/dist/{chunk-08m3b6w8.js.map → chunk-h3v76ams.js.map} +2 -2
- 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-wdage1eb.js → chunk-jmfet9r4.js} +6 -6
- package/dist/{chunk-wdage1eb.js.map → chunk-jmfet9r4.js.map} +2 -2
- package/dist/{chunk-k34z5rvh.js → chunk-kfee1h52.js} +132 -48
- package/dist/chunk-kfee1h52.js.map +13 -0
- 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-4jjp5k14.js → chunk-mmagke4x.js} +6 -6
- package/dist/{chunk-4jjp5k14.js.map → chunk-mmagke4x.js.map} +2 -2
- package/dist/{chunk-359jm1jw.js → chunk-mrp7k0pw.js} +20 -20
- package/dist/{chunk-359jm1jw.js.map → chunk-mrp7k0pw.js.map} +2 -2
- package/dist/{chunk-h0k55pc7.js → chunk-ms2tmn1k.js} +139 -139
- package/dist/{chunk-h0k55pc7.js.map → chunk-ms2tmn1k.js.map} +2 -2
- package/dist/{chunk-h5vqbfmd.js → chunk-nmbxcaqx.js} +117 -117
- package/dist/{chunk-h5vqbfmd.js.map → chunk-nmbxcaqx.js.map} +3 -3
- package/dist/{chunk-n2w475r0.js → chunk-nt99sxd6.js} +82 -82
- package/dist/{chunk-n2w475r0.js.map → chunk-nt99sxd6.js.map} +3 -3
- package/dist/{chunk-v1xppd0y.js → chunk-p5vcsw9c.js} +60 -60
- package/dist/{chunk-v1xppd0y.js.map → chunk-p5vcsw9c.js.map} +2 -2
- package/dist/{chunk-sbzzr4kx.js → chunk-p6a4npdx.js} +1260 -1289
- package/dist/chunk-p6a4npdx.js.map +58 -0
- 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-nn0tekr1.js → chunk-pr2h4bv4.js} +33 -33
- package/dist/{chunk-nn0tekr1.js.map → chunk-pr2h4bv4.js.map} +2 -2
- 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-5ntny1qx.js → chunk-qf954wje.js} +6 -6
- package/dist/{chunk-5ntny1qx.js.map → chunk-qf954wje.js.map} +2 -2
- package/dist/chunk-qma80ych.js +30 -0
- package/dist/chunk-qma80ych.js.map +11 -0
- package/dist/{chunk-mth82m8t.js → chunk-qyeptdyv.js} +171 -77
- package/dist/chunk-qyeptdyv.js.map +15 -0
- 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-mwsxn98e.js → chunk-r7fj830t.js} +253 -200
- package/dist/chunk-r7fj830t.js.map +36 -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-gzasd5b6.js → chunk-rtk71jzp.js} +22 -22
- package/dist/{chunk-gzasd5b6.js.map → chunk-rtk71jzp.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-3z1qec12.js → chunk-t1f4f1ve.js} +107 -64
- package/dist/{chunk-3z1qec12.js.map → chunk-t1f4f1ve.js.map} +3 -3
- package/dist/chunk-v2vcg0w6.js +151 -0
- package/dist/chunk-v2vcg0w6.js.map +11 -0
- package/dist/{chunk-r8jrnexe.js → chunk-v4jbb3rs.js} +4 -4
- package/dist/{chunk-r8jrnexe.js.map → chunk-v4jbb3rs.js.map} +2 -2
- package/dist/{chunk-w1tvjszy.js → chunk-vsj3mdfj.js} +8 -8
- package/dist/{chunk-w1tvjszy.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-z4ccwbkz.js → chunk-x9v4cx1d.js} +1 -1
- 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-yp8ee62z.js → chunk-z30bv4ga.js} +35 -35
- package/dist/{chunk-yp8ee62z.js.map → chunk-z30bv4ga.js.map} +2 -2
- 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-4yqmp43v.js → chunk-z8fx5cgb.js} +12 -12
- package/dist/{chunk-4yqmp43v.js.map → chunk-z8fx5cgb.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/authorizations.d.ts.map +1 -1
- package/dist/connectors/connections/contracts.d.ts +3 -0
- package/dist/connectors/connections/contracts.d.ts.map +1 -1
- package/dist/connectors/connections/internal.js +9 -10
- package/dist/connectors/connections/internal.js.map +1 -1
- package/dist/connectors/connections/request.d.ts +3 -1
- package/dist/connectors/connections/request.d.ts.map +1 -1
- package/dist/connectors/connections/runs.d.ts.map +1 -1
- package/dist/connectors/connections/tokens.d.ts.map +1 -1
- package/dist/connectors/connections/validation.d.ts +5 -1
- package/dist/connectors/connections/validation.d.ts.map +1 -1
- package/dist/connectors/types.d.ts +19 -4
- package/dist/connectors/types.d.ts.map +1 -1
- package/dist/datasets/write.js +8 -12
- package/dist/datasets/write.js.map +1 -1
- 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 +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/service.d.ts +2 -2
- package/dist/events/service.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 +71 -82
- package/dist/execution/agent.js.map +1 -1
- package/dist/execution/durable.d.ts +1 -0
- package/dist/execution/durable.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 +64 -71
- package/dist/execution/primitive.js.map +3 -3
- package/dist/execution/request.d.ts +1 -0
- package/dist/execution/request.d.ts.map +1 -1
- package/dist/execution/request.js +66 -75
- package/dist/execution/request.js.map +3 -3
- package/dist/http/index.js +10 -11
- package/dist/http/index.js.map +1 -1
- package/dist/index.d.ts +17 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +457 -477
- package/dist/index.js.map +1 -1
- package/dist/lake-storage/changes.d.ts +5 -0
- package/dist/lake-storage/changes.d.ts.map +1 -0
- package/dist/lake-storage/in-memory.d.ts +2 -1
- package/dist/lake-storage/in-memory.d.ts.map +1 -1
- package/dist/lake-storage/index.d.ts +2 -1
- package/dist/lake-storage/index.d.ts.map +1 -1
- package/dist/lake-storage/index.js +40 -42
- package/dist/lake-storage/index.js.map +1 -1
- package/dist/lake-storage/types.d.ts +36 -0
- package/dist/lake-storage/types.d.ts.map +1 -1
- 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.d.ts +1 -1
- package/dist/materialization/index.d.ts.map +1 -1
- package/dist/materialization/index.js +46 -49
- package/dist/materialization/index.js.map +1 -1
- package/dist/materialization/model.d.ts +12 -1
- package/dist/materialization/model.d.ts.map +1 -1
- package/dist/materializer/index.d.ts +1 -1
- package/dist/materializer/index.d.ts.map +1 -1
- package/dist/materializer/index.js +137 -145
- package/dist/materializer/index.js.map +1 -1
- package/dist/materializer/materializer.d.ts +5 -1
- package/dist/materializer/materializer.d.ts.map +1 -1
- package/dist/materializer/projections/entry-validator.d.ts +2 -1
- package/dist/materializer/projections/entry-validator.d.ts.map +1 -1
- package/dist/materializer/projections/replace.d.ts.map +1 -1
- package/dist/materializer/projections/source-materialization.d.ts +4 -3
- package/dist/materializer/projections/source-materialization.d.ts.map +1 -1
- package/dist/materializer/shared/normalize.d.ts +2 -1
- package/dist/materializer/shared/normalize.d.ts.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/execution.d.ts.map +1 -1
- package/dist/objects/index.js +75 -87
- package/dist/objects/index.js.map +1 -1
- package/dist/objects/query/index.js +67 -76
- package/dist/objects/query/index.js.map +1 -1
- package/dist/ontology/index.d.ts +1 -2
- package/dist/ontology/index.d.ts.map +1 -1
- package/dist/ontology/index.js +62 -113
- package/dist/ontology/index.js.map +1 -1
- package/dist/ontology/internal.d.ts +7 -0
- package/dist/ontology/internal.d.ts.map +1 -1
- package/dist/ontology/internal.js +65 -116
- package/dist/ontology/internal.js.map +3 -4
- package/dist/pipelines/index.js +57 -66
- package/dist/pipelines/index.js.map +1 -1
- package/dist/pipelines/run-dispatch.d.ts.map +1 -1
- package/dist/projections/internal.js +56 -67
- 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/in-memory.d.ts +7 -3
- package/dist/queues/in-memory.d.ts.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/indexed-heap.d.ts +15 -0
- package/dist/queues/indexed-heap.d.ts.map +1 -0
- package/dist/queues/types.d.ts +3 -20
- package/dist/queues/types.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 +2 -1
- package/dist/runtime/create.d.ts.map +1 -1
- package/dist/runtime/host.d.ts +2 -1
- package/dist/runtime/host.d.ts.map +1 -1
- package/dist/runtime/internal.js +13 -14
- package/dist/runtime/internal.js.map +1 -1
- package/dist/runtime/ontology-mutations.d.ts +3 -1
- package/dist/runtime/ontology-mutations.d.ts.map +1 -1
- package/dist/runtime/sixb.d.ts +2 -0
- package/dist/runtime/sixb.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/index.js +31 -33
- package/dist/schedules/index.js.map +1 -1
- package/dist/shares/internal.js +46 -54
- package/dist/shares/internal.js.map +2 -2
- 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/in-memory.d.ts.map +1 -1
- package/dist/storage/connector-connections/provider/runs.d.ts.map +1 -1
- package/dist/storage/connector-connections/provider.js +35 -37
- package/dist/storage/connector-connections/provider.js.map +3 -3
- package/dist/storage/connector-connections/types.d.ts +3 -2
- package/dist/storage/connector-connections/types.d.ts.map +1 -1
- package/dist/storage/executions/in-memory.d.ts.map +1 -1
- package/dist/storage/executions/provider.d.ts +2 -1
- package/dist/storage/executions/provider.d.ts.map +1 -1
- package/dist/storage/executions/provider.js +14 -11
- package/dist/storage/executions/provider.js.map +3 -3
- 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 +2 -0
- package/dist/storage/executions/validation.d.ts.map +1 -1
- package/dist/storage/in-memory/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +7 -8
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +221 -256
- 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/ontology/in-memory/materializations-state.d.ts.map +1 -1
- package/dist/storage/ontology/in-memory/materializations.d.ts +1 -1
- package/dist/storage/ontology/in-memory/materializations.d.ts.map +1 -1
- package/dist/storage/ontology/in-memory/shared-state.d.ts +15 -2
- package/dist/storage/ontology/in-memory/shared-state.d.ts.map +1 -1
- package/dist/storage/ontology/in-memory/source-roots.d.ts +6 -0
- package/dist/storage/ontology/in-memory/source-roots.d.ts.map +1 -0
- package/dist/storage/ontology/in-memory/sources.d.ts.map +1 -1
- package/dist/storage/ontology/index.d.ts +1 -1
- package/dist/storage/ontology/index.d.ts.map +1 -1
- package/dist/storage/ontology/provider.d.ts +16 -0
- package/dist/storage/ontology/provider.d.ts.map +1 -1
- package/dist/storage/ontology/provider.js +107 -109
- package/dist/storage/ontology/provider.js.map +1 -1
- package/dist/storage/ontology/sources.d.ts +13 -4
- package/dist/storage/ontology/sources.d.ts.map +1 -1
- package/dist/storage/operation-scope.js +18 -19
- 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/lifecycle.d.ts.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/projection-runs/types.d.ts +2 -0
- package/dist/storage/projection-runs/types.d.ts.map +1 -1
- package/dist/storage/share-grants/provider.js +17 -19
- package/dist/storage/share-grants/provider.js.map +1 -1
- package/dist/storage/share-sessions/provider.js +14 -15
- package/dist/storage/share-sessions/provider.js.map +1 -1
- package/dist/storage/sync-runs/provider.js +4 -6
- package/dist/storage/sync-runs/provider.js.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 -21
- 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/index.js +56 -65
- package/dist/syncs/index.js.map +1 -1
- package/dist/syncs/run-dispatch.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/broker-contract.d.ts.map +1 -1
- package/dist/testing/connector-connection-storage-contract.d.ts.map +1 -1
- 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 +1 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +2282 -1662
- package/dist/testing/index.js.map +16 -15
- package/dist/testing/lake-changes-contract.d.ts +6 -0
- package/dist/testing/lake-changes-contract.d.ts.map +1 -0
- package/dist/testing/materializer-storage-contract.d.ts.map +1 -1
- package/dist/testing/ontology-storage-contract.d.ts.map +1 -1
- package/dist/testing/projection-run-storage-contract.d.ts.map +1 -1
- package/dist/testing/workflow-execution.d.ts +1 -0
- package/dist/testing/workflow-execution.d.ts.map +1 -1
- package/dist/webhooks/connections.d.ts +6 -0
- package/dist/webhooks/connections.d.ts.map +1 -0
- package/dist/webhooks/index.d.ts +1 -1
- package/dist/webhooks/index.d.ts.map +1 -1
- package/dist/webhooks/internal.d.ts +2 -0
- package/dist/webhooks/internal.d.ts.map +1 -1
- package/dist/webhooks/internal.js +98 -61
- package/dist/webhooks/internal.js.map +4 -3
- package/dist/webhooks/registry.d.ts +1 -1
- package/dist/webhooks/registry.d.ts.map +1 -1
- package/dist/webhooks/types.d.ts +15 -4
- package/dist/webhooks/types.d.ts.map +1 -1
- package/dist/workers/index.js +11 -13
- package/dist/workers/index.js.map +2 -2
- package/dist/workflows/failure.d.ts +2 -0
- package/dist/workflows/failure.d.ts.map +1 -1
- package/dist/workflows/index.js +136 -147
- package/dist/workflows/index.js.map +1 -1
- package/dist/workflows/request.d.ts.map +1 -1
- package/dist/workflows/run-dispatch.d.ts +3 -2
- 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 +48 -30
- package/src/actions/run-dispatch.ts +2 -6
- package/src/actions/types/context.ts +2 -0
- package/src/actions/validation.ts +2 -1
- package/src/agents/adapters.ts +4 -9
- 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 +1 -1
- package/src/agents/index.ts +4 -4
- package/src/agents/message.ts +1 -1
- package/src/agents/model-loop.ts +8 -0
- package/src/agents/request.ts +11 -26
- 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/types.ts +1 -1
- package/src/agents/validation.ts +3 -7
- package/src/auth/index.ts +0 -1
- package/src/bootstrap/discovery.ts +81 -24
- package/src/bootstrap/index.ts +8 -1
- package/src/broker/in-memory.ts +104 -39
- package/src/broker/index.ts +4 -1
- package/src/broker/retention.ts +28 -0
- package/src/broker/subscriber.ts +21 -0
- package/src/broker/types.ts +15 -1
- package/src/connectors/builders.ts +0 -6
- package/src/connectors/connections/authorizations.ts +11 -5
- package/src/connectors/connections/contracts.ts +3 -0
- package/src/connectors/connections/request.ts +56 -22
- package/src/connectors/connections/runs.ts +1 -0
- package/src/connectors/connections/tokens.ts +4 -0
- package/src/connectors/connections/validation.ts +91 -5
- package/src/connectors/types.ts +19 -4
- 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 +2 -2
- package/src/events/service.ts +3 -3
- package/src/execution/agent.ts +5 -3
- package/src/execution/durable.ts +11 -1
- package/src/execution/primitive.ts +5 -1
- package/src/execution/request.ts +3 -0
- package/src/index.ts +30 -20
- package/src/lake-storage/changes.ts +43 -0
- package/src/lake-storage/in-memory.ts +73 -0
- package/src/lake-storage/index.ts +4 -0
- package/src/lake-storage/types.ts +40 -0
- package/src/logging/index.ts +2 -33
- package/src/logging/internal.ts +43 -0
- package/src/logging/service.ts +1 -1
- package/src/materialization/index.ts +2 -0
- package/src/materialization/model.ts +14 -1
- package/src/materializer/index.ts +2 -0
- package/src/materializer/materializer.ts +10 -0
- package/src/materializer/projections/entry-validator.ts +19 -1
- package/src/materializer/projections/replace.ts +36 -1
- package/src/materializer/projections/source-materialization.ts +26 -6
- package/src/materializer/shared/normalize.ts +1 -1
- 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/execution.ts +1 -1
- package/src/ontology/index.ts +1 -2
- package/src/ontology/internal.ts +35 -0
- package/src/pipelines/run-dispatch.ts +21 -1
- package/src/projections/run-dispatch.ts +31 -68
- package/src/query.ts +0 -1
- package/src/queues/in-memory.ts +105 -62
- package/src/queues/index.ts +4 -2
- package/src/queues/indexed-heap.ts +74 -0
- package/src/queues/types.ts +6 -25
- package/src/runtime/create.ts +2 -1
- package/src/runtime/host.ts +2 -15
- package/src/runtime/ontology-mutations.ts +4 -0
- package/src/runtime/sixb.ts +4 -0
- package/src/sandboxes/errors.ts +5 -0
- package/src/sandboxes/index.ts +3 -0
- package/src/sandboxes/sandbox.ts +35 -7
- 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/connector-connections/in-memory.ts +3 -1
- package/src/storage/connector-connections/provider/runs.ts +3 -1
- package/src/storage/connector-connections/types.ts +3 -2
- package/src/storage/executions/in-memory.ts +4 -9
- package/src/storage/executions/provider.ts +4 -0
- package/src/storage/executions/types.ts +6 -2
- package/src/storage/executions/validation.ts +32 -0
- package/src/storage/in-memory/index.ts +16 -1
- package/src/storage/index.ts +4 -29
- package/src/storage/internal.ts +20 -0
- package/src/storage/ontology/in-memory/materializations-state.ts +5 -18
- package/src/storage/ontology/in-memory/materializations.ts +73 -92
- package/src/storage/ontology/in-memory/shared-state.ts +26 -1
- package/src/storage/ontology/in-memory/source-roots.ts +123 -0
- package/src/storage/ontology/in-memory/sources.ts +78 -23
- package/src/storage/ontology/index.ts +1 -0
- package/src/storage/ontology/provider.ts +70 -0
- package/src/storage/ontology/sources.ts +14 -3
- package/src/storage/projection-runs/lifecycle.ts +5 -2
- package/src/storage/projection-runs/types.ts +4 -3
- package/src/storage/workflow-runs/in-memory.ts +0 -2
- package/src/storage/workflow-runs/types.ts +0 -3
- package/src/syncs/run-dispatch.ts +19 -1
- 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/broker-contract.ts +95 -0
- package/src/testing/connector-connection-storage-contract.ts +18 -1
- package/src/testing/execution-storage-contract.ts +59 -1
- package/src/testing/execution.ts +6 -0
- package/src/testing/index.ts +1 -0
- package/src/testing/lake-changes-contract.ts +240 -0
- package/src/testing/materializer-storage-contract.ts +172 -1
- package/src/testing/ontology-storage-contract.ts +7 -0
- package/src/testing/projection-run-storage-contract.ts +34 -0
- package/src/testing/workflow-execution.ts +4 -0
- package/src/webhooks/connections.ts +56 -0
- package/src/webhooks/index.ts +2 -0
- package/src/webhooks/internal.ts +2 -0
- package/src/webhooks/registry.ts +3 -4
- package/src/webhooks/types.ts +17 -4
- package/src/workflows/failure.ts +62 -1
- package/src/workflows/request.ts +0 -9
- package/src/workflows/run-dispatch.ts +42 -32
- 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-19jp6g9d.js.map +0 -11
- package/dist/chunk-2xns679x.js.map +0 -11
- package/dist/chunk-3xep5cjx.js.map +0 -15
- package/dist/chunk-407j3msh.js +0 -60
- package/dist/chunk-4qfkag59.js +0 -1568
- package/dist/chunk-4qfkag59.js.map +0 -20
- package/dist/chunk-5e3pq99w.js.map +0 -11
- package/dist/chunk-5gd7tpv6.js.map +0 -11
- package/dist/chunk-7y0f6rf1.js.map +0 -10
- package/dist/chunk-8m5ejdpn.js.map +0 -10
- package/dist/chunk-8tsf6dmc.js.map +0 -15
- package/dist/chunk-ajnan18g.js.map +0 -12
- package/dist/chunk-c15dr03f.js +0 -43
- package/dist/chunk-d8qkxt2v.js.map +0 -10
- package/dist/chunk-jq43kdvk.js +0 -50
- package/dist/chunk-k34z5rvh.js.map +0 -11
- package/dist/chunk-k522z7v6.js.map +0 -10
- package/dist/chunk-mth82m8t.js.map +0 -14
- package/dist/chunk-mwsxn98e.js.map +0 -36
- package/dist/chunk-p03r0h5s.js.map +0 -16
- package/dist/chunk-p1rzczbt.js +0 -218
- package/dist/chunk-rafagrwr.js.map +0 -11
- package/dist/chunk-rv2hkwwa.js.map +0 -14
- package/dist/chunk-sbzzr4kx.js.map +0 -63
- package/dist/chunk-tpnd31c1.js +0 -242
- package/dist/chunk-tpnd31c1.js.map +0 -11
- package/dist/chunk-w9tg6yyb.js.map +0 -12
- package/dist/chunk-wtf06et8.js.map +0 -14
- package/dist/chunk-xajtptbw.js.map +0 -40
- package/dist/chunk-xhy826cz.js.map +0 -10
- package/dist/chunk-y64skrwp.js +0 -19
- package/dist/chunk-zcnhxkvd.js +0 -7
- package/dist/logging/types.js +0 -27
- package/dist/logging/types.js.map +0 -9
- /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-j1sbhm7p.js → chunk-ey1nk510.js} +0 -0
- /package/dist/{chunk-j1sbhm7p.js.map → chunk-ey1nk510.js.map} +0 -0
- /package/dist/{chunk-z4ccwbkz.js.map → chunk-x9v4cx1d.js.map} +0 -0
|
@@ -1,139 +1,164 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
agentServiceAccountId2,
|
|
4
|
+
assertObjectReadOutputWithinLimit2,
|
|
5
|
+
createAgentRuntimeAuthorization,
|
|
6
|
+
resolveRuntimeAuthorizationForProject,
|
|
7
|
+
getAuthorizationRef,
|
|
8
|
+
resolveExecutionScopeAuthorization,
|
|
9
|
+
AuthorizationError2,
|
|
10
|
+
isAllowed2,
|
|
11
|
+
assertAuthorized2,
|
|
12
|
+
isRuntimeAllowed2,
|
|
13
|
+
assertCanManageConnector2,
|
|
14
|
+
assertPrivileged2,
|
|
15
|
+
assertProviderAccess2,
|
|
16
|
+
canViewEvent2,
|
|
17
|
+
canViewActionRun2,
|
|
18
|
+
canViewWorkflowRun2,
|
|
19
|
+
canViewWorkflowIntervention2,
|
|
20
|
+
canViewPipelineRun2,
|
|
21
|
+
canViewProjectionRun2,
|
|
22
|
+
canViewProjection2
|
|
23
|
+
} from "./chunk-dz5h08xv.js";
|
|
7
24
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
aiUsageLimitUnavailableError,
|
|
11
|
-
applicableAiLimitPolicyStatuses
|
|
12
|
-
} from "./chunk-c15dr03f.js";
|
|
25
|
+
captureSixbFailure2
|
|
26
|
+
} from "./chunk-f4w3yp4f.js";
|
|
13
27
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
28
|
+
isRecord2,
|
|
29
|
+
normalizeSchemaValue2,
|
|
30
|
+
coerceSchemaValueToTyped2,
|
|
31
|
+
assertObjectTypeRegistered2
|
|
32
|
+
} from "./chunk-ms2tmn1k.js";
|
|
16
33
|
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
34
|
+
isActionDefinition2,
|
|
35
|
+
SYSTEM_PRINCIPAL2,
|
|
36
|
+
principalsEqual2
|
|
37
|
+
} from "./chunk-g00bfdq6.js";
|
|
20
38
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
getTelemetryHistoryBatch,
|
|
25
|
-
listObjects,
|
|
26
|
-
removeLink1 as removeLink,
|
|
27
|
-
upsertLink1 as upsertLink,
|
|
28
|
-
upsertLinkBatch1 as upsertLinkBatch,
|
|
29
|
-
upsertObject1 as upsertObject,
|
|
30
|
-
upsertObjectBatch1 as upsertObjectBatch
|
|
31
|
-
} from "./chunk-aa2pen2v.js";
|
|
39
|
+
isModelReasoning2,
|
|
40
|
+
modelReasoningSupportIssue2
|
|
41
|
+
} from "./chunk-pqajwytd.js";
|
|
32
42
|
import {
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
RuntimeError2,
|
|
44
|
+
ModelProviderError2,
|
|
45
|
+
ModelStreamError2,
|
|
46
|
+
UnsupportedModelFeatureError2,
|
|
47
|
+
StructuredOutputError2,
|
|
48
|
+
estimateModelCall,
|
|
49
|
+
rateModelCall2
|
|
50
|
+
} from "./chunk-e0d1rzef.js";
|
|
35
51
|
import {
|
|
36
|
-
|
|
37
|
-
|
|
52
|
+
AgentStorageError2,
|
|
53
|
+
AGENT_REASONING_LEVELS2
|
|
54
|
+
} from "./chunk-7bs40fe1.js";
|
|
55
|
+
import {
|
|
56
|
+
ObjectNotFoundError2
|
|
57
|
+
} from "./chunk-8vj0rjgs.js";
|
|
38
58
|
import {
|
|
39
|
-
|
|
40
|
-
} from "./chunk-
|
|
59
|
+
ExecutionStorageError2
|
|
60
|
+
} from "./chunk-93csa55g.js";
|
|
41
61
|
import {
|
|
42
|
-
|
|
43
|
-
} from "./chunk-
|
|
62
|
+
WORKFLOW_RUN_FAILURE_CODES2
|
|
63
|
+
} from "./chunk-p6a4npdx.js";
|
|
64
|
+
import {
|
|
65
|
+
WorkflowRunError2
|
|
66
|
+
} from "./chunk-pr2h4bv4.js";
|
|
44
67
|
import {
|
|
45
68
|
assertAuthorizedObjectReaderBinding,
|
|
46
|
-
canDelegationAccessActionRun,
|
|
47
69
|
getAuthorizedOntologyView,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
70
|
+
canDelegationAccessActionRun,
|
|
71
|
+
requestAction3,
|
|
72
|
+
requestActionAndWait2
|
|
73
|
+
} from "./chunk-nmbxcaqx.js";
|
|
51
74
|
import {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
} from "./chunk-k522z7v6.js";
|
|
75
|
+
shareSixbErrorReporter2,
|
|
76
|
+
reportRunFailure2
|
|
77
|
+
} from "./chunk-7apz6hg4.js";
|
|
56
78
|
import {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
79
|
+
aiLimitSubjectsFromAttribution2,
|
|
80
|
+
applicableAiLimitPolicyStatuses2,
|
|
81
|
+
aiUsageLimitExceededError2,
|
|
82
|
+
aiUsageLimitUnavailableError2
|
|
83
|
+
} from "./chunk-0y39rgsb.js";
|
|
60
84
|
import {
|
|
61
|
-
|
|
62
|
-
|
|
85
|
+
AgentRequestError2,
|
|
86
|
+
normalizeAgentContextEntries2
|
|
87
|
+
} from "./chunk-dmn70ztd.js";
|
|
63
88
|
import {
|
|
64
|
-
|
|
65
|
-
} from "./chunk-
|
|
89
|
+
publishAgentRunActivity2
|
|
90
|
+
} from "./chunk-92vk7gta.js";
|
|
66
91
|
import {
|
|
67
|
-
|
|
68
|
-
} from "./chunk-
|
|
92
|
+
registerConnectorConnectionsRuntime
|
|
93
|
+
} from "./chunk-5a4a52tq.js";
|
|
69
94
|
import {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
} from "./chunk-p1rzczbt.js";
|
|
95
|
+
createConnectorRuntime
|
|
96
|
+
} from "./chunk-v2vcg0w6.js";
|
|
73
97
|
import {
|
|
74
|
-
|
|
75
|
-
} from "./chunk-
|
|
98
|
+
writeDataset2
|
|
99
|
+
} from "./chunk-mrp7k0pw.js";
|
|
76
100
|
import {
|
|
77
|
-
|
|
78
|
-
} from "./chunk-
|
|
101
|
+
shareOntologyMutationRuntime2
|
|
102
|
+
} from "./chunk-85cd7e8c.js";
|
|
79
103
|
import {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
} from "./chunk-jq43kdvk.js";
|
|
104
|
+
compileShareAccessPlan
|
|
105
|
+
} from "./chunk-awbhdqyc.js";
|
|
83
106
|
import {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
} from "./chunk-
|
|
107
|
+
SyncValidationError2,
|
|
108
|
+
requestSyncRun2
|
|
109
|
+
} from "./chunk-5c7ga8zz.js";
|
|
87
110
|
import {
|
|
88
|
-
|
|
89
|
-
|
|
111
|
+
getTelemetryHistoryBatch2,
|
|
112
|
+
getLatestTelemetryPoint,
|
|
113
|
+
createObjectSet2,
|
|
114
|
+
upsertLink3,
|
|
115
|
+
upsertLinkBatch3,
|
|
116
|
+
removeLink3,
|
|
117
|
+
listObjects,
|
|
118
|
+
upsertObject3,
|
|
119
|
+
upsertObjectBatch3,
|
|
120
|
+
appendTelemetry
|
|
121
|
+
} from "./chunk-976rxdpx.js";
|
|
90
122
|
import {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
principalsEqual
|
|
94
|
-
} from "./chunk-4sm0aznx.js";
|
|
123
|
+
schemaRecordToJsonSchema2
|
|
124
|
+
} from "./chunk-7zgecwy1.js";
|
|
95
125
|
import {
|
|
96
|
-
|
|
97
|
-
|
|
126
|
+
PipelineError2,
|
|
127
|
+
requestPipelineRun2
|
|
128
|
+
} from "./chunk-b0ec55a1.js";
|
|
98
129
|
import {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
130
|
+
requireAccountingCapabilities,
|
|
131
|
+
aiModelCallOutputTokenAllowance,
|
|
132
|
+
createAiModelCallLimitController2,
|
|
133
|
+
AiModelCallRecorder2,
|
|
134
|
+
enqueueAiModelCallRecovery2,
|
|
135
|
+
resolveLanguageModel2
|
|
136
|
+
} from "./chunk-28ja2cjs.js";
|
|
102
137
|
import {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
canViewActionRun,
|
|
111
|
-
canViewEvent,
|
|
112
|
-
canViewPipelineRun,
|
|
113
|
-
canViewProjection,
|
|
114
|
-
canViewProjectionRun,
|
|
115
|
-
canViewWorkflowIntervention,
|
|
116
|
-
canViewWorkflowRun,
|
|
117
|
-
createAgentRuntimeAuthorization,
|
|
118
|
-
getAuthorizationRef,
|
|
119
|
-
isAllowed,
|
|
120
|
-
isRuntimeAllowed,
|
|
121
|
-
resolveExecutionScopeAuthorization,
|
|
122
|
-
resolveRuntimeAuthorizationForProject
|
|
123
|
-
} from "./chunk-p1x242ad.js";
|
|
138
|
+
getDatasetPrimaryKeyColumns2
|
|
139
|
+
} from "./chunk-9qsh3p5y.js";
|
|
140
|
+
import {
|
|
141
|
+
executionRecordInputFromRuntime,
|
|
142
|
+
ensureExecutionRecord2,
|
|
143
|
+
createPrimitiveExecutionRecord
|
|
144
|
+
} from "./chunk-17kfctj6.js";
|
|
124
145
|
import {
|
|
125
|
-
|
|
126
|
-
} from "./chunk-
|
|
146
|
+
ShareGrantStorageError2
|
|
147
|
+
} from "./chunk-br3k6qbf.js";
|
|
127
148
|
import {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
} from "./chunk-
|
|
149
|
+
isObjectRefSchema2,
|
|
150
|
+
validateSchemaOrRefValue2
|
|
151
|
+
} from "./chunk-f0rwz2vh.js";
|
|
131
152
|
import {
|
|
132
|
-
|
|
133
|
-
|
|
153
|
+
supportsDirectUpload2,
|
|
154
|
+
supportsRangeRead2
|
|
155
|
+
} from "./chunk-h3v76ams.js";
|
|
134
156
|
import {
|
|
157
|
+
isJsonValue2,
|
|
158
|
+
assertJsonValue2,
|
|
159
|
+
assertJsonObject2,
|
|
135
160
|
isPlainRecord
|
|
136
|
-
} from "./chunk-
|
|
161
|
+
} from "./chunk-wy0qdqfm.js";
|
|
137
162
|
|
|
138
163
|
// src/actions/descriptor.ts
|
|
139
164
|
function snapshotActionDescriptor(action) {
|
|
@@ -185,14 +210,14 @@ function createActionsRuntime(runtime, execution) {
|
|
|
185
210
|
}
|
|
186
211
|
if (authorization.type === "unrestricted")
|
|
187
212
|
return true;
|
|
188
|
-
return
|
|
213
|
+
return isAllowed2(authorization.context, { kind: "action.apply", actionId: action.id }) && (action.binding.kind === "global" || isAllowed2(authorization.context, {
|
|
189
214
|
kind: "object.view",
|
|
190
215
|
objectTypeId: action.binding.objectType.id
|
|
191
216
|
}));
|
|
192
217
|
};
|
|
193
218
|
const release = (value) => {
|
|
194
219
|
if (authorization.type === "delegated") {
|
|
195
|
-
|
|
220
|
+
assertObjectReadOutputWithinLimit2(value, authorization.objectRead.limits);
|
|
196
221
|
}
|
|
197
222
|
return value;
|
|
198
223
|
};
|
|
@@ -205,8 +230,8 @@ function createActionsRuntime(runtime, execution) {
|
|
|
205
230
|
},
|
|
206
231
|
listGlobal: () => describeAll(runtime.actionRegistry.listGlobal()),
|
|
207
232
|
listForType: (objectType) => describeAll(runtime.actionRegistry.listForType(objectType).filter((action) => authorization.type !== "delegated" || action.binding.kind === "object" && action.binding.objectType.id === objectType.id)),
|
|
208
|
-
request: (input) =>
|
|
209
|
-
requestAndWait: (input) =>
|
|
233
|
+
request: (input) => requestAction3(runtime, execution, input),
|
|
234
|
+
requestAndWait: (input) => requestActionAndWait2(runtime, execution, input),
|
|
210
235
|
runs: {
|
|
211
236
|
getById: async (runId) => {
|
|
212
237
|
if (authorization.type === "denied" || authorization.type === "delegated" && (!authorization.delegation || authorization.actionApply.length === 0))
|
|
@@ -215,7 +240,7 @@ function createActionsRuntime(runtime, execution) {
|
|
|
215
240
|
projectId,
|
|
216
241
|
id: runId
|
|
217
242
|
}) ?? null;
|
|
218
|
-
return run && (authorization.type === "unrestricted" || authorization.type === "principal" &&
|
|
243
|
+
return run && (authorization.type === "unrestricted" || authorization.type === "principal" && canViewActionRun2(authorization.context, run) || authorization.type === "delegated" && await canDelegationAccessActionRun({
|
|
219
244
|
storage: runtime.storage,
|
|
220
245
|
projectId,
|
|
221
246
|
authority: authorization,
|
|
@@ -271,26 +296,26 @@ async function resolveExecutionUsage(input) {
|
|
|
271
296
|
|
|
272
297
|
// src/agents/ids.ts
|
|
273
298
|
import { createHash, randomUUID } from "crypto";
|
|
274
|
-
function
|
|
299
|
+
function createAgentThreadId2() {
|
|
275
300
|
return `agt_thr_${randomUUID()}`;
|
|
276
301
|
}
|
|
277
|
-
function
|
|
302
|
+
function createAgentRunId2() {
|
|
278
303
|
return `agt_run_${randomUUID()}`;
|
|
279
304
|
}
|
|
280
|
-
function
|
|
305
|
+
function createSubagentRunId2(parentRunId, spawnKey) {
|
|
281
306
|
const digest = createHash("sha256").update(parentRunId).update("\x00").update(spawnKey).digest("hex");
|
|
282
307
|
return `agt_run_child_${digest}`;
|
|
283
308
|
}
|
|
284
|
-
function
|
|
309
|
+
function createSubagentExecutionId2(runId) {
|
|
285
310
|
return `exec_${runId}`;
|
|
286
311
|
}
|
|
287
|
-
function
|
|
312
|
+
function createAgentMessageId2() {
|
|
288
313
|
return `agt_msg_${randomUUID()}`;
|
|
289
314
|
}
|
|
290
|
-
function
|
|
315
|
+
function agentContextCheckpointId2(runId) {
|
|
291
316
|
return `agt_ctx_${runId}`;
|
|
292
317
|
}
|
|
293
|
-
function
|
|
318
|
+
function createAgentRunExecutionToken2() {
|
|
294
319
|
return `agt_exec_${randomUUID()}`;
|
|
295
320
|
}
|
|
296
321
|
|
|
@@ -298,8 +323,8 @@ function createAgentRunExecutionToken() {
|
|
|
298
323
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
299
324
|
|
|
300
325
|
// src/agents/context-resolution.ts
|
|
301
|
-
async function
|
|
302
|
-
const entries =
|
|
326
|
+
async function resolveAgentContextParts2(runtime, input) {
|
|
327
|
+
const entries = normalizeAgentContextEntries2(input);
|
|
303
328
|
for (const entry of entries) {
|
|
304
329
|
if (entry.context.kind !== "object")
|
|
305
330
|
continue;
|
|
@@ -320,20 +345,20 @@ async function resolveAgentContextParts(runtime, input) {
|
|
|
320
345
|
return entries.map((entry) => ({ type: "context", ...entry }));
|
|
321
346
|
}
|
|
322
347
|
function invalidContext(message) {
|
|
323
|
-
throw new
|
|
348
|
+
throw new AgentRequestError2("invalid_context", `[Sixb] Invalid agent context: ${message}.`);
|
|
324
349
|
}
|
|
325
350
|
|
|
326
351
|
// src/agents/dispatch.ts
|
|
327
|
-
function
|
|
352
|
+
function agentRunQueueJobId2(runId) {
|
|
328
353
|
return `agt_job_${runId}`;
|
|
329
354
|
}
|
|
330
|
-
function
|
|
355
|
+
function subagentRunQueueJobId2(runId) {
|
|
331
356
|
return `agt_child_job_${runId}`;
|
|
332
357
|
}
|
|
333
|
-
function
|
|
358
|
+
function workflowAgentNodeQueueJobId2(nodeRunId) {
|
|
334
359
|
return `wfa_job_${nodeRunId}`;
|
|
335
360
|
}
|
|
336
|
-
async function
|
|
361
|
+
async function dispatchQueuedAgentRuns2(input) {
|
|
337
362
|
const limit = normalizeLimit(input.limit);
|
|
338
363
|
const runs = input.runIds ? await input.storage.runs.getByIds({
|
|
339
364
|
projectId: input.projectId,
|
|
@@ -353,14 +378,14 @@ async function dispatchQueuedAgentRuns(input) {
|
|
|
353
378
|
const jobs = await input.queue.enqueue({
|
|
354
379
|
projectId: input.projectId,
|
|
355
380
|
jobs: queued.map((run) => ({
|
|
356
|
-
id:
|
|
381
|
+
id: agentRunQueueJobId2(run.id),
|
|
357
382
|
type: "agent.run.requested",
|
|
358
383
|
payload: { runId: run.id }
|
|
359
384
|
}))
|
|
360
385
|
});
|
|
361
386
|
const jobsById = new Map(jobs.map((job) => [job.id, job]));
|
|
362
387
|
const dispatched = queued.map((run) => {
|
|
363
|
-
const jobId =
|
|
388
|
+
const jobId = agentRunQueueJobId2(run.id);
|
|
364
389
|
if (!jobsById.has(jobId)) {
|
|
365
390
|
throw new Error(`[Sixb] Agent queue did not return job '${jobId}'.`);
|
|
366
391
|
}
|
|
@@ -375,7 +400,7 @@ async function dispatchQueuedAgentRuns(input) {
|
|
|
375
400
|
};
|
|
376
401
|
}
|
|
377
402
|
}
|
|
378
|
-
async function
|
|
403
|
+
async function dispatchQueuedSubagentRuns2(input) {
|
|
379
404
|
const limit = normalizeLimit(input.limit);
|
|
380
405
|
const runs = input.runIds ? await input.storage.runs.getByIds({
|
|
381
406
|
projectId: input.projectId,
|
|
@@ -394,14 +419,14 @@ async function dispatchQueuedSubagentRuns(input) {
|
|
|
394
419
|
const jobs = await input.queue.enqueue({
|
|
395
420
|
projectId: input.projectId,
|
|
396
421
|
jobs: queued.map((run) => ({
|
|
397
|
-
id:
|
|
422
|
+
id: subagentRunQueueJobId2(run.id),
|
|
398
423
|
type: "agent.subagent-run.requested",
|
|
399
424
|
payload: { runId: run.id }
|
|
400
425
|
}))
|
|
401
426
|
});
|
|
402
427
|
const jobsById = new Set(jobs.map((job) => job.id));
|
|
403
428
|
const dispatched = queued.map((run) => {
|
|
404
|
-
const jobId =
|
|
429
|
+
const jobId = subagentRunQueueJobId2(run.id);
|
|
405
430
|
if (!jobsById.has(jobId)) {
|
|
406
431
|
throw new Error(`[Sixb] Subagent queue did not return job '${jobId}'.`);
|
|
407
432
|
}
|
|
@@ -428,37 +453,32 @@ function normalizeLimit(value) {
|
|
|
428
453
|
// src/agents/retired-config.ts
|
|
429
454
|
function assertNoAgentDefinitions(input) {
|
|
430
455
|
if ("agents" in input) {
|
|
431
|
-
throw new
|
|
456
|
+
throw new RuntimeError2("[Sixb] Agent definitions are no longer supported. Configure 'models' and 'tools' on createSixb() instead.");
|
|
432
457
|
}
|
|
433
458
|
}
|
|
434
459
|
function assertNoAgentSelector(input) {
|
|
435
460
|
if ("agentId" in input || "agentIds" in input) {
|
|
436
|
-
throw new
|
|
461
|
+
throw new AgentRequestError2("agent_selector_removed", "[Sixb] There is one project Agent. Remove the agentId selector and use sixb.agent.");
|
|
437
462
|
}
|
|
438
463
|
}
|
|
439
464
|
|
|
440
465
|
// src/agents/request.ts
|
|
441
|
-
async function
|
|
466
|
+
async function requestAgentRun2(runtime, execution, models, input) {
|
|
442
467
|
const authority = resolveExecutionScopeAuthorization(runtime.projectId, {
|
|
443
468
|
execution,
|
|
444
469
|
authorization: runtime.runtimeAuthorization
|
|
445
470
|
});
|
|
446
471
|
assertNoAgentSelector(input);
|
|
447
|
-
|
|
472
|
+
assertAuthorized2(runtime, { kind: "agent.run" });
|
|
448
473
|
assertRequestAuthorityCanRunAgent(runtime);
|
|
449
474
|
const spec = resolveConversationRunSpec({ models, input });
|
|
450
|
-
const contextParts = await
|
|
475
|
+
const contextParts = await resolveAgentContextParts2(runtime, input.context);
|
|
451
476
|
const agents = requireAgentStorage(runtime);
|
|
452
477
|
const projectId = runtime.projectId;
|
|
453
|
-
const principal = authority.type === "principal" ? authority.context.principal : input.principal ??
|
|
454
|
-
const runId =
|
|
478
|
+
const principal = authority.type === "principal" ? authority.context.principal : input.principal ?? SYSTEM_PRINCIPAL2;
|
|
479
|
+
const runId = createAgentRunId2();
|
|
455
480
|
const durableExecution = await prepareDurableAgentExecution(runtime, execution, runId);
|
|
456
|
-
|
|
457
|
-
auth: runtime.storage.auth,
|
|
458
|
-
projectId,
|
|
459
|
-
principal: durableExecution.requestedBy
|
|
460
|
-
}) : [];
|
|
461
|
-
await assertAiLimitPreflight(runtime, durableExecution, requesterGroupIds);
|
|
481
|
+
await assertAiLimitPreflight(runtime, durableExecution);
|
|
462
482
|
const { thread, createdThread } = await resolveThread(agents, {
|
|
463
483
|
projectId,
|
|
464
484
|
threadId: input.threadId,
|
|
@@ -466,18 +486,18 @@ async function requestAgentRun(runtime, execution, models, input) {
|
|
|
466
486
|
principal
|
|
467
487
|
});
|
|
468
488
|
if (thread.activeRunId !== null) {
|
|
469
|
-
throw new
|
|
489
|
+
throw new AgentRequestError2("active_run_exists", `[Sixb] Agent thread '${thread.id}' already has an active run '${thread.activeRunId}'.`);
|
|
470
490
|
}
|
|
471
|
-
const triggerMessageId = input.messageId ??
|
|
491
|
+
const triggerMessageId = input.messageId ?? createAgentMessageId2();
|
|
472
492
|
let run;
|
|
473
493
|
try {
|
|
474
494
|
run = await runtime.storage.transaction(async (tx) => {
|
|
475
|
-
const
|
|
476
|
-
if (!
|
|
477
|
-
throw new
|
|
495
|
+
const agents = tx.agents;
|
|
496
|
+
if (!agents) {
|
|
497
|
+
throw new AgentRequestError2("storage_unavailable", "[Sixb] Agent storage is not configured.");
|
|
478
498
|
}
|
|
479
499
|
await tx.executions.create(durableExecution);
|
|
480
|
-
await
|
|
500
|
+
await agents.messages.append({
|
|
481
501
|
id: triggerMessageId,
|
|
482
502
|
projectId,
|
|
483
503
|
threadId: thread.id,
|
|
@@ -490,19 +510,18 @@ async function requestAgentRun(runtime, execution, models, input) {
|
|
|
490
510
|
],
|
|
491
511
|
authorPrincipal: principal
|
|
492
512
|
});
|
|
493
|
-
return
|
|
513
|
+
return agents.runs.create({
|
|
494
514
|
id: runId,
|
|
495
515
|
projectId,
|
|
496
516
|
executionId: durableExecution.id,
|
|
497
517
|
threadId: thread.id,
|
|
498
518
|
triggerMessageId,
|
|
499
|
-
spec
|
|
500
|
-
requesterGroupIds
|
|
519
|
+
spec
|
|
501
520
|
});
|
|
502
521
|
});
|
|
503
522
|
} catch (error) {
|
|
504
|
-
if (error instanceof
|
|
505
|
-
throw new
|
|
523
|
+
if (error instanceof AgentStorageError2 && error.code === "active_run_exists") {
|
|
524
|
+
throw new AgentRequestError2("active_run_exists", error.message);
|
|
506
525
|
}
|
|
507
526
|
throw error;
|
|
508
527
|
}
|
|
@@ -514,15 +533,15 @@ async function requestAgentRun(runtime, execution, models, input) {
|
|
|
514
533
|
createdThread
|
|
515
534
|
};
|
|
516
535
|
}
|
|
517
|
-
async function
|
|
536
|
+
async function retryAgentRun2(runtime, execution, models, failedRun) {
|
|
518
537
|
resolveExecutionScopeAuthorization(runtime.projectId, {
|
|
519
538
|
execution,
|
|
520
539
|
authorization: runtime.runtimeAuthorization
|
|
521
540
|
});
|
|
522
|
-
|
|
541
|
+
assertAuthorized2(runtime, { kind: "agent.run" });
|
|
523
542
|
assertRequestAuthorityCanRunAgent(runtime);
|
|
524
543
|
if (failedRun.status !== "failed") {
|
|
525
|
-
throw new
|
|
544
|
+
throw new AgentRequestError2("run_not_retryable", `[Sixb] Only failed Agent runs can be retried.`);
|
|
526
545
|
}
|
|
527
546
|
const agents = requireAgentStorage(runtime);
|
|
528
547
|
const thread = await agents.threads.getById({
|
|
@@ -530,28 +549,23 @@ async function retryAgentRun(runtime, execution, models, failedRun) {
|
|
|
530
549
|
id: failedRun.threadId
|
|
531
550
|
});
|
|
532
551
|
if (!thread) {
|
|
533
|
-
throw new
|
|
552
|
+
throw new AgentRequestError2("thread_not_found", `[Sixb] Agent thread '${failedRun.threadId}' was not found.`);
|
|
534
553
|
}
|
|
535
|
-
const runId =
|
|
554
|
+
const runId = createAgentRunId2();
|
|
536
555
|
const durableExecution = await prepareDurableAgentExecution(runtime, execution, runId);
|
|
537
|
-
|
|
538
|
-
auth: runtime.storage.auth,
|
|
539
|
-
projectId: runtime.projectId,
|
|
540
|
-
principal: durableExecution.requestedBy
|
|
541
|
-
}) : [];
|
|
542
|
-
await assertAiLimitPreflight(runtime, durableExecution, requesterGroupIds);
|
|
556
|
+
await assertAiLimitPreflight(runtime, durableExecution);
|
|
543
557
|
const run = await runtime.storage.transaction(async (tx) => {
|
|
544
|
-
const
|
|
545
|
-
if (!
|
|
546
|
-
throw new
|
|
558
|
+
const agents = tx.agents;
|
|
559
|
+
if (!agents) {
|
|
560
|
+
throw new AgentRequestError2("storage_unavailable", "[Sixb] Agent storage is not configured.");
|
|
547
561
|
}
|
|
548
|
-
await
|
|
562
|
+
await agents.messages.deleteByRunId({
|
|
549
563
|
projectId: runtime.projectId,
|
|
550
564
|
threadId: failedRun.threadId,
|
|
551
565
|
runId: failedRun.id
|
|
552
566
|
});
|
|
553
567
|
await tx.executions.create(durableExecution);
|
|
554
|
-
return
|
|
568
|
+
return agents.runs.create({
|
|
555
569
|
id: runId,
|
|
556
570
|
projectId: runtime.projectId,
|
|
557
571
|
executionId: durableExecution.id,
|
|
@@ -560,47 +574,46 @@ async function retryAgentRun(runtime, execution, models, failedRun) {
|
|
|
560
574
|
spec: failedRun.spec ?? resolveConversationRunSpec({
|
|
561
575
|
models,
|
|
562
576
|
input: {}
|
|
563
|
-
})
|
|
564
|
-
requesterGroupIds
|
|
577
|
+
})
|
|
565
578
|
});
|
|
566
579
|
});
|
|
567
580
|
await publishRunActivity(runtime, run);
|
|
568
581
|
const jobId = await dispatchAgentRun(runtime, agents, runId);
|
|
569
582
|
return { run, ...jobId ? { jobId } : {}, createdThread: false };
|
|
570
583
|
}
|
|
571
|
-
async function assertAiLimitPreflight(runtime, execution
|
|
584
|
+
async function assertAiLimitPreflight(runtime, execution) {
|
|
572
585
|
const limits = runtime.storage.aiLimits;
|
|
573
586
|
if (!limits)
|
|
574
|
-
throw
|
|
575
|
-
const subjects =
|
|
587
|
+
throw aiUsageLimitUnavailableError2(["limitStorageUnavailable"]);
|
|
588
|
+
const subjects = aiLimitSubjectsFromAttribution2(execution.requestedBy, execution.requesterGroupIds);
|
|
576
589
|
let applicable;
|
|
577
590
|
try {
|
|
578
|
-
applicable =
|
|
591
|
+
applicable = applicableAiLimitPolicyStatuses2(await limits.listPolicyStatuses({ projectId: runtime.projectId }), subjects);
|
|
579
592
|
} catch {
|
|
580
|
-
throw
|
|
593
|
+
throw aiUsageLimitUnavailableError2(["limitStorageUnavailable"]);
|
|
581
594
|
}
|
|
582
595
|
const unavailable = applicable.filter((status) => status.accountingStatus === "unavailable");
|
|
583
596
|
if (unavailable.length > 0) {
|
|
584
|
-
throw
|
|
597
|
+
throw aiUsageLimitUnavailableError2(["incompleteAccounting"]);
|
|
585
598
|
}
|
|
586
599
|
const exhausted = applicable.filter((status) => status.exhausted);
|
|
587
600
|
if (exhausted.length > 0) {
|
|
588
601
|
const resetAt = new Date(Math.min(...exhausted.map((status) => status.period.resetAt.getTime())));
|
|
589
|
-
throw
|
|
602
|
+
throw aiUsageLimitExceededError2(resetAt);
|
|
590
603
|
}
|
|
591
604
|
}
|
|
592
605
|
function resolveConversationRunSpec(input) {
|
|
593
606
|
if (!input.models) {
|
|
594
|
-
throw new
|
|
607
|
+
throw new AgentRequestError2("model_not_found", "[Sixb] Configure models.language before starting the Agent.");
|
|
595
608
|
}
|
|
596
609
|
const selected = input.input.model ?? input.models.default;
|
|
597
610
|
const model = input.models.getByRef(selected);
|
|
598
611
|
if (model === null) {
|
|
599
|
-
throw new
|
|
612
|
+
throw new AgentRequestError2("model_not_found", `[Sixb] Language model '${selected.provider}/${selected.modelId}' is not in the project model catalog.`);
|
|
600
613
|
}
|
|
601
614
|
const reasoning = input.input.reasoning;
|
|
602
|
-
if (reasoning !== undefined && !
|
|
603
|
-
throw new
|
|
615
|
+
if (reasoning !== undefined && !isModelReasoning2(reasoning)) {
|
|
616
|
+
throw new AgentRequestError2("invalid_model_selection", `[Sixb] Agent reasoning must be one of: ${AGENT_REASONING_LEVELS2.join(", ")}, or a nonnegative budgetTokens object.`);
|
|
604
617
|
}
|
|
605
618
|
return Object.freeze({
|
|
606
619
|
model: Object.freeze({ provider: selected.provider, modelId: selected.modelId }),
|
|
@@ -608,24 +621,24 @@ function resolveConversationRunSpec(input) {
|
|
|
608
621
|
});
|
|
609
622
|
}
|
|
610
623
|
async function prepareDurableAgentExecution(runtime, execution, runId) {
|
|
611
|
-
const parent = await
|
|
624
|
+
const parent = await ensureExecutionRecord2(runtime.storage.executions, executionRecordInputFromRuntime({
|
|
612
625
|
execution,
|
|
613
626
|
runtimeAuthorization: runtime.runtimeAuthorization
|
|
614
627
|
}));
|
|
615
|
-
return
|
|
628
|
+
return createInheritedAgentExecutionRecord2({
|
|
616
629
|
id: `exec_${randomUUID2()}`,
|
|
617
630
|
parent,
|
|
618
631
|
runId
|
|
619
632
|
});
|
|
620
633
|
}
|
|
621
634
|
function assertRequestAuthorityCanRunAgent(runtime) {
|
|
622
|
-
if (!
|
|
623
|
-
throw new
|
|
635
|
+
if (!canInheritAgentRequestAuthorization2(runtime.runtimeAuthorization)) {
|
|
636
|
+
throw new AgentRequestError2("authority_not_inheritable", "[Sixb] The Agent requires an authenticated user request or disabled authorization.");
|
|
624
637
|
}
|
|
625
638
|
}
|
|
626
639
|
async function dispatchAgentRun(runtime, agents, runId) {
|
|
627
640
|
try {
|
|
628
|
-
const dispatch = await
|
|
641
|
+
const dispatch = await dispatchQueuedAgentRuns2({
|
|
629
642
|
projectId: runtime.projectId,
|
|
630
643
|
storage: agents,
|
|
631
644
|
queue: runtime.queues.agents,
|
|
@@ -643,7 +656,7 @@ async function dispatchAgentRun(runtime, agents, runId) {
|
|
|
643
656
|
}
|
|
644
657
|
async function publishRunActivity(runtime, run) {
|
|
645
658
|
try {
|
|
646
|
-
await
|
|
659
|
+
await publishAgentRunActivity2(runtime.broker, run);
|
|
647
660
|
} catch (error) {
|
|
648
661
|
console.error(`[Sixb] Agent run '${run.id}' activity stream publish failed:`, error);
|
|
649
662
|
}
|
|
@@ -659,7 +672,7 @@ async function resolveThread(agents, params) {
|
|
|
659
672
|
}
|
|
660
673
|
}
|
|
661
674
|
const thread = await agents.threads.create({
|
|
662
|
-
id: params.threadId ??
|
|
675
|
+
id: params.threadId ?? createAgentThreadId2(),
|
|
663
676
|
projectId: params.projectId,
|
|
664
677
|
ownerPrincipal: params.principal,
|
|
665
678
|
...params.title === undefined ? {} : { title: params.title }
|
|
@@ -669,7 +682,7 @@ async function resolveThread(agents, params) {
|
|
|
669
682
|
function requireAgentStorage(runtime) {
|
|
670
683
|
const agents = runtime.storage.agents;
|
|
671
684
|
if (!agents) {
|
|
672
|
-
throw new
|
|
685
|
+
throw new AgentRequestError2("storage_unavailable", "[Sixb] Agent storage is not configured.");
|
|
673
686
|
}
|
|
674
687
|
return agents;
|
|
675
688
|
}
|
|
@@ -677,8 +690,8 @@ function requireAgentStorage(runtime) {
|
|
|
677
690
|
// src/agents/execution.ts
|
|
678
691
|
function createAgentRuntime(runtime, execution, models) {
|
|
679
692
|
const authority = resolveRuntimeAuthorizationForProject(runtime);
|
|
680
|
-
const principal = authority.type === "principal" ? authority.context.principal :
|
|
681
|
-
const allowed = () =>
|
|
693
|
+
const principal = authority.type === "principal" ? authority.context.principal : SYSTEM_PRINCIPAL2;
|
|
694
|
+
const allowed = () => isRuntimeAllowed2(runtime, { kind: "agent.run" });
|
|
682
695
|
const getVisibleThreadRecord = async (threadId) => {
|
|
683
696
|
if (authority.type === "denied" || authority.type === "delegated")
|
|
684
697
|
return null;
|
|
@@ -688,7 +701,7 @@ function createAgentRuntime(runtime, execution, models) {
|
|
|
688
701
|
}) ?? null;
|
|
689
702
|
if (!thread || !allowed())
|
|
690
703
|
return null;
|
|
691
|
-
return authority.type === "principal" && !
|
|
704
|
+
return authority.type === "principal" && !principalsEqual2(principal, thread.ownerPrincipal) ? null : thread;
|
|
692
705
|
};
|
|
693
706
|
const getAgent = () => {
|
|
694
707
|
if (authority.type === "denied" || authority.type === "delegated")
|
|
@@ -724,14 +737,14 @@ function createAgentRuntime(runtime, execution, models) {
|
|
|
724
737
|
assertNoAgentSelector(input);
|
|
725
738
|
const agent = getAgent();
|
|
726
739
|
if (!agent) {
|
|
727
|
-
throw new
|
|
740
|
+
throw new AgentRequestError2("agent_not_found", "[Sixb] The project Agent is unavailable.");
|
|
728
741
|
}
|
|
729
742
|
const storage = runtime.storage.agents;
|
|
730
743
|
if (!storage) {
|
|
731
|
-
throw new
|
|
744
|
+
throw new AgentRequestError2("storage_unavailable", "[Sixb] Agent storage is not configured.");
|
|
732
745
|
}
|
|
733
746
|
return storage.threads.create({
|
|
734
|
-
id: input.id ??
|
|
747
|
+
id: input.id ?? createAgentThreadId2(),
|
|
735
748
|
projectId: runtime.projectId,
|
|
736
749
|
ownerPrincipal: principal,
|
|
737
750
|
...input.title === undefined ? {} : { title: input.title }
|
|
@@ -758,13 +771,13 @@ function createAgentRuntime(runtime, execution, models) {
|
|
|
758
771
|
assertNoAgentSelector(input);
|
|
759
772
|
const agent = getAgent();
|
|
760
773
|
if (!agent) {
|
|
761
|
-
throw new
|
|
774
|
+
throw new AgentRequestError2("agent_not_found", "[Sixb] The project Agent is unavailable.");
|
|
762
775
|
}
|
|
763
|
-
|
|
776
|
+
assertAuthorized2(runtime, { kind: "agent.run" });
|
|
764
777
|
if (input.threadId && !await getVisibleThreadRecord(input.threadId)) {
|
|
765
|
-
throw new
|
|
778
|
+
throw new AgentRequestError2("thread_not_found", `[Sixb] Agent thread '${input.threadId}' not found.`);
|
|
766
779
|
}
|
|
767
|
-
const result = await
|
|
780
|
+
const result = await requestAgentRun2(runtime, execution, models?.language, {
|
|
768
781
|
...input,
|
|
769
782
|
principal
|
|
770
783
|
});
|
|
@@ -773,13 +786,13 @@ function createAgentRuntime(runtime, execution, models) {
|
|
|
773
786
|
retry: async (runId) => {
|
|
774
787
|
const failedRun = await getVisibleRunRecord(runId);
|
|
775
788
|
if (!failedRun) {
|
|
776
|
-
throw new
|
|
789
|
+
throw new AgentRequestError2("run_not_found", `[Sixb] Agent run '${runId}' was not found.`);
|
|
777
790
|
}
|
|
778
791
|
const agent = getAgent();
|
|
779
792
|
if (!agent) {
|
|
780
|
-
throw new
|
|
793
|
+
throw new AgentRequestError2("agent_not_found", "[Sixb] The project Agent is unavailable.");
|
|
781
794
|
}
|
|
782
|
-
const result = await
|
|
795
|
+
const result = await retryAgentRun2(runtime, execution, models?.language, failedRun);
|
|
783
796
|
return { ...result, run: await attachRunView(runtime, result.run) };
|
|
784
797
|
},
|
|
785
798
|
getById: getRun,
|
|
@@ -844,10 +857,10 @@ async function attachRunViews(runtime, runs) {
|
|
|
844
857
|
// src/ai-usage/execution.ts
|
|
845
858
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
846
859
|
function createAiUsageRuntime(runtime, security) {
|
|
847
|
-
const assertObservable = () =>
|
|
848
|
-
const assertManageable = () =>
|
|
860
|
+
const assertObservable = () => assertAuthorized2(runtime, { kind: "aiUsage.observe" });
|
|
861
|
+
const assertManageable = () => assertAuthorized2(runtime, { kind: "aiUsage.manage" });
|
|
849
862
|
const assertPolicyReadable = () => {
|
|
850
|
-
if (!
|
|
863
|
+
if (!isRuntimeAllowed2(runtime, { kind: "aiUsage.observe" }) && !isRuntimeAllowed2(runtime, { kind: "aiUsage.manage" })) {
|
|
851
864
|
assertObservable();
|
|
852
865
|
}
|
|
853
866
|
};
|
|
@@ -868,7 +881,7 @@ function createAiUsageRuntime(runtime, security) {
|
|
|
868
881
|
limitsConfigured: runtime.storage.aiLimits !== undefined,
|
|
869
882
|
assertObservable,
|
|
870
883
|
assertManageable,
|
|
871
|
-
canManageLimits: () =>
|
|
884
|
+
canManageLimits: () => isRuntimeAllowed2(runtime, { kind: "aiUsage.manage" }),
|
|
872
885
|
queryOverview: (input) => {
|
|
873
886
|
assertObservable();
|
|
874
887
|
return requireCosts().queryProjectOverview({ ...input, projectId: runtime.projectId });
|
|
@@ -943,7 +956,7 @@ function createAiUsageRuntime(runtime, security) {
|
|
|
943
956
|
}
|
|
944
957
|
// src/blob-storage/execution.ts
|
|
945
958
|
function createBlobsRuntime(runtime, execution, blobStorage) {
|
|
946
|
-
const assertAccess = () =>
|
|
959
|
+
const assertAccess = () => assertProviderAccess2(runtime, execution, "blobs.access");
|
|
947
960
|
const executionBlobs = {
|
|
948
961
|
put: (input) => {
|
|
949
962
|
assertAccess();
|
|
@@ -958,13 +971,13 @@ function createBlobsRuntime(runtime, execution, blobStorage) {
|
|
|
958
971
|
return blobStorage.stat(blobId);
|
|
959
972
|
}
|
|
960
973
|
};
|
|
961
|
-
if (
|
|
974
|
+
if (supportsRangeRead2(blobStorage)) {
|
|
962
975
|
executionBlobs.openRange = (blobId, range) => {
|
|
963
976
|
assertAccess();
|
|
964
977
|
return blobStorage.openRange(blobId, range);
|
|
965
978
|
};
|
|
966
979
|
}
|
|
967
|
-
if (
|
|
980
|
+
if (supportsDirectUpload2(blobStorage)) {
|
|
968
981
|
executionBlobs.createUpload = (input) => {
|
|
969
982
|
assertAccess();
|
|
970
983
|
return blobStorage.createUpload(input);
|
|
@@ -1010,12 +1023,12 @@ function commandContext(runtime, execution, connectorId) {
|
|
|
1010
1023
|
authorization: runtime.runtimeAuthorization
|
|
1011
1024
|
});
|
|
1012
1025
|
if (execution.executor.type !== "request" || resolved.type !== "principal" || resolved.ref.type !== "principal") {
|
|
1013
|
-
throw new
|
|
1026
|
+
throw new AuthorizationError2(`manage:connector:${connectorId}`, "[Sixb] Connector connections can only be managed by an authenticated request.");
|
|
1014
1027
|
}
|
|
1015
1028
|
if (!resolved.ref.credential) {
|
|
1016
|
-
throw new
|
|
1029
|
+
throw new AuthorizationError2(`manage:connector:${connectorId}`, "[Sixb] Connector connection management requires a session or access token.");
|
|
1017
1030
|
}
|
|
1018
|
-
|
|
1031
|
+
assertCanManageConnector2(runtime, connectorId);
|
|
1019
1032
|
return Object.freeze({
|
|
1020
1033
|
execution: Object.freeze(executionRecordInputFromRuntime({
|
|
1021
1034
|
execution,
|
|
@@ -1027,7 +1040,7 @@ function commandContext(runtime, execution, connectorId) {
|
|
|
1027
1040
|
// src/datasets/execution.ts
|
|
1028
1041
|
function createDatasetsRuntime(runtime, execution, source, lakeStorage, blobStorage) {
|
|
1029
1042
|
const authority = resolveRuntimeAuthorizationForProject(runtime);
|
|
1030
|
-
const allowed = (datasetId) =>
|
|
1043
|
+
const allowed = (datasetId) => isRuntimeAllowed2(runtime, { kind: "dataset.view", datasetId });
|
|
1031
1044
|
return {
|
|
1032
1045
|
list: () => authority.type === "denied" || authority.type === "delegated" ? [] : source.list().filter((dataset) => allowed(dataset.id)),
|
|
1033
1046
|
getById: (datasetId) => {
|
|
@@ -1037,18 +1050,18 @@ function createDatasetsRuntime(runtime, execution, source, lakeStorage, blobStor
|
|
|
1037
1050
|
return dataset && allowed(datasetId) ? dataset : null;
|
|
1038
1051
|
},
|
|
1039
1052
|
async ingest(dataset, input) {
|
|
1040
|
-
|
|
1053
|
+
assertPrivileged2(runtime, "datasets.ingest");
|
|
1041
1054
|
const registered = source.getById(dataset.id);
|
|
1042
1055
|
if (!registered)
|
|
1043
1056
|
throw new Error(`[Sixb] Dataset '${dataset.id}' is not registered.`);
|
|
1044
|
-
if (
|
|
1057
|
+
if (getDatasetPrimaryKeyColumns2(registered) === null) {
|
|
1045
1058
|
throw new Error(`[Sixb] Dataset '${dataset.id}' must define a primaryKey before ingestion.`);
|
|
1046
1059
|
}
|
|
1047
1060
|
if (typeof lakeStorage.beginMerge !== "function") {
|
|
1048
1061
|
throw new Error("[Sixb] Dataset ingestion requires a lake provider with merge support.");
|
|
1049
1062
|
}
|
|
1050
1063
|
const producer = { kind: "ingest", id: execution.id };
|
|
1051
|
-
const result = await
|
|
1064
|
+
const result = await writeDataset2({
|
|
1052
1065
|
lakeStorage,
|
|
1053
1066
|
blobStorage,
|
|
1054
1067
|
dataset: registered,
|
|
@@ -1090,7 +1103,7 @@ function createEventsRuntime(runtime) {
|
|
|
1090
1103
|
case "delegated":
|
|
1091
1104
|
return [];
|
|
1092
1105
|
case "principal":
|
|
1093
|
-
return events.filter((event) =>
|
|
1106
|
+
return events.filter((event) => canViewEvent2(authority.context, event));
|
|
1094
1107
|
case "unrestricted":
|
|
1095
1108
|
return [...events];
|
|
1096
1109
|
}
|
|
@@ -1102,17 +1115,17 @@ function createEventsRuntime(runtime) {
|
|
|
1102
1115
|
case "delegated":
|
|
1103
1116
|
return false;
|
|
1104
1117
|
case "principal":
|
|
1105
|
-
return
|
|
1118
|
+
return canViewEvent2(authority.context, event);
|
|
1106
1119
|
case "unrestricted":
|
|
1107
1120
|
return true;
|
|
1108
1121
|
}
|
|
1109
1122
|
},
|
|
1110
1123
|
append: (input) => {
|
|
1111
|
-
|
|
1124
|
+
assertPrivileged2(runtime, "events.append");
|
|
1112
1125
|
return runtime.events.append(input);
|
|
1113
1126
|
},
|
|
1114
1127
|
emit: (input, options) => {
|
|
1115
|
-
|
|
1128
|
+
assertPrivileged2(runtime, "events.emit");
|
|
1116
1129
|
return runtime.events.emit(input, options);
|
|
1117
1130
|
},
|
|
1118
1131
|
read: async (input) => {
|
|
@@ -1149,7 +1162,7 @@ function createEventsRuntime(runtime) {
|
|
|
1149
1162
|
return runtime.events.subscribe(input, (events) => {
|
|
1150
1163
|
const visible = visibleEvents(events);
|
|
1151
1164
|
if (visible.length > 0)
|
|
1152
|
-
handler(visible);
|
|
1165
|
+
return handler(visible);
|
|
1153
1166
|
});
|
|
1154
1167
|
}
|
|
1155
1168
|
};
|
|
@@ -1157,7 +1170,7 @@ function createEventsRuntime(runtime) {
|
|
|
1157
1170
|
|
|
1158
1171
|
// src/logging/execution.ts
|
|
1159
1172
|
function createLogsRuntime(runtime, source) {
|
|
1160
|
-
const assertObservable = () =>
|
|
1173
|
+
const assertObservable = () => assertAuthorized2(runtime, { kind: "logs.observe" });
|
|
1161
1174
|
return {
|
|
1162
1175
|
assertObservable,
|
|
1163
1176
|
read: (input) => {
|
|
@@ -1171,6 +1184,949 @@ function createLogsRuntime(runtime, source) {
|
|
|
1171
1184
|
};
|
|
1172
1185
|
}
|
|
1173
1186
|
|
|
1187
|
+
// src/agents/model-loop.ts
|
|
1188
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
1189
|
+
var MAX_PROVIDER_DATA_BYTES = 256 * 1024;
|
|
1190
|
+
async function runModelLoop2(input) {
|
|
1191
|
+
assertLoopInput(input);
|
|
1192
|
+
const tools = indexTools(input.tools ?? []);
|
|
1193
|
+
const toolSpecifications = [...tools.values()].map((tool) => ({
|
|
1194
|
+
name: tool.name,
|
|
1195
|
+
description: tool.description,
|
|
1196
|
+
inputSchema: tool.inputSchema
|
|
1197
|
+
}));
|
|
1198
|
+
let messages = [...input.messages];
|
|
1199
|
+
const steps = [];
|
|
1200
|
+
const generateCallId = input.generateCallId ?? (() => `model_call_${randomUUID4()}`);
|
|
1201
|
+
const callIds = new Set;
|
|
1202
|
+
for (let stepIndex = 0;stepIndex < input.maxSteps; stepIndex += 1) {
|
|
1203
|
+
if (input.signal.aborted) {
|
|
1204
|
+
return { status: "aborted", steps, partialContent: [] };
|
|
1205
|
+
}
|
|
1206
|
+
await input.onEvent?.({ type: "start-step" });
|
|
1207
|
+
let requestMessages;
|
|
1208
|
+
try {
|
|
1209
|
+
const prepared = await input.prepareStep?.({
|
|
1210
|
+
stepIndex,
|
|
1211
|
+
messages,
|
|
1212
|
+
model: input.model,
|
|
1213
|
+
signal: input.signal
|
|
1214
|
+
});
|
|
1215
|
+
requestMessages = prepared?.messages ?? messages;
|
|
1216
|
+
} catch (error) {
|
|
1217
|
+
if (!input.signal.aborted && !isAbortError(error))
|
|
1218
|
+
throw error;
|
|
1219
|
+
return { status: "aborted", steps, partialContent: [] };
|
|
1220
|
+
}
|
|
1221
|
+
if (input.signal.aborted) {
|
|
1222
|
+
return { status: "aborted", steps, partialContent: [] };
|
|
1223
|
+
}
|
|
1224
|
+
let requestTools = toolSpecifications;
|
|
1225
|
+
if (input.finalStepInstruction !== undefined && stepIndex === input.maxSteps - 1) {
|
|
1226
|
+
requestMessages = [
|
|
1227
|
+
...requestMessages,
|
|
1228
|
+
{ role: "user", content: [{ type: "text", text: input.finalStepInstruction }] }
|
|
1229
|
+
];
|
|
1230
|
+
requestTools = [];
|
|
1231
|
+
}
|
|
1232
|
+
const callId = generateCallId();
|
|
1233
|
+
if (!callId || callIds.has(callId)) {
|
|
1234
|
+
throw new ModelStreamError2(`[SixbModels] Model call IDs must be nonempty and unique.`);
|
|
1235
|
+
}
|
|
1236
|
+
callIds.add(callId);
|
|
1237
|
+
const accumulator = new StreamAccumulator(input.onEvent);
|
|
1238
|
+
let accepted = false;
|
|
1239
|
+
let cost = { status: "unpriceable", reason: "missing-usage" };
|
|
1240
|
+
let terminalStreamError;
|
|
1241
|
+
try {
|
|
1242
|
+
const stream = await input.model.stream({
|
|
1243
|
+
callId,
|
|
1244
|
+
messages: requestMessages,
|
|
1245
|
+
tools: requestTools,
|
|
1246
|
+
...input.reasoning === undefined ? {} : { reasoning: input.reasoning },
|
|
1247
|
+
...input.maxOutputTokens === undefined ? {} : { maxOutputTokens: input.maxOutputTokens },
|
|
1248
|
+
...input.caching === undefined ? {} : { caching: input.caching },
|
|
1249
|
+
...input.output === undefined ? {} : {
|
|
1250
|
+
responseFormat: {
|
|
1251
|
+
type: "json",
|
|
1252
|
+
name: input.output.name,
|
|
1253
|
+
...input.output.description === undefined ? {} : { description: input.output.description },
|
|
1254
|
+
schema: input.output.schema
|
|
1255
|
+
}
|
|
1256
|
+
},
|
|
1257
|
+
signal: input.signal
|
|
1258
|
+
});
|
|
1259
|
+
accepted = true;
|
|
1260
|
+
for await (const event of stream.events) {
|
|
1261
|
+
await accumulator.accept(event);
|
|
1262
|
+
}
|
|
1263
|
+
} catch (error) {
|
|
1264
|
+
const aborted = input.signal.aborted || isAbortError(error);
|
|
1265
|
+
if (accumulator.isFinished()) {
|
|
1266
|
+
if (!aborted)
|
|
1267
|
+
terminalStreamError = { error };
|
|
1268
|
+
} else if (!aborted) {
|
|
1269
|
+
throw error;
|
|
1270
|
+
} else {
|
|
1271
|
+
return {
|
|
1272
|
+
status: "aborted",
|
|
1273
|
+
steps,
|
|
1274
|
+
partialContent: accumulator.partialContent()
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
} finally {
|
|
1278
|
+
if (accepted) {
|
|
1279
|
+
const facts = accumulator.accounting();
|
|
1280
|
+
const estimate = accumulator.isFinished() ? estimateModelCall(input.model, facts) : cost;
|
|
1281
|
+
cost = facts.reportedCost ? rateModelCall2({ usage: facts.usage, reported: facts.reportedCost }) : estimate;
|
|
1282
|
+
await input.onModelCallEnd?.({
|
|
1283
|
+
callId,
|
|
1284
|
+
providerId: input.model.providerId,
|
|
1285
|
+
modelId: input.model.modelId,
|
|
1286
|
+
responseId: facts.responseId ?? `${callId}:response`,
|
|
1287
|
+
providerIds: facts.providerIds,
|
|
1288
|
+
responseModelId: facts.responseModelId,
|
|
1289
|
+
usage: facts.usage,
|
|
1290
|
+
cost,
|
|
1291
|
+
...facts.reportedCost === undefined ? {} : { estimate },
|
|
1292
|
+
...input.reasoning === undefined ? {} : { requestedReasoning: input.reasoning },
|
|
1293
|
+
...facts.route === undefined ? {} : { route: facts.route }
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
if (input.signal.aborted && !accumulator.isFinished()) {
|
|
1298
|
+
return { status: "aborted", steps, partialContent: accumulator.partialContent() };
|
|
1299
|
+
}
|
|
1300
|
+
const response = accumulator.complete();
|
|
1301
|
+
const responseId = response.responseId ?? `${callId}:response`;
|
|
1302
|
+
if (terminalStreamError)
|
|
1303
|
+
throw terminalStreamError.error;
|
|
1304
|
+
if (response.projectionError)
|
|
1305
|
+
throw response.projectionError;
|
|
1306
|
+
if (input.signal.aborted) {
|
|
1307
|
+
return { status: "aborted", steps, partialContent: response.content };
|
|
1308
|
+
}
|
|
1309
|
+
const localCalls = response.toolCalls.filter((call) => call.part.providerExecuted !== true);
|
|
1310
|
+
if (input.rejectLocalToolCalls && (localCalls.length > 0 || response.finishReason === "tool-calls")) {
|
|
1311
|
+
throw new ModelStreamError2("[SixbModels] Direct generation cannot continue local tool calls.");
|
|
1312
|
+
}
|
|
1313
|
+
if (response.finishReason === "pause" && localCalls.length === 0) {
|
|
1314
|
+
const step = modelStep(response, responseId, response.content, cost);
|
|
1315
|
+
steps.push(step);
|
|
1316
|
+
await input.onStepEnd?.(step);
|
|
1317
|
+
messages = [...requestMessages, { role: "assistant", content: response.content }];
|
|
1318
|
+
if (stepIndex + 1 === input.maxSteps) {
|
|
1319
|
+
throw new ModelStreamError2("[SixbModels] Model reached the step limit while a provider continuation was pending.");
|
|
1320
|
+
}
|
|
1321
|
+
continue;
|
|
1322
|
+
}
|
|
1323
|
+
if (localCalls.length === 0) {
|
|
1324
|
+
const step = modelStep(response, responseId, response.content, cost);
|
|
1325
|
+
steps.push(step);
|
|
1326
|
+
await input.onStepEnd?.(step);
|
|
1327
|
+
if (input.output) {
|
|
1328
|
+
const text = responseText(response);
|
|
1329
|
+
if (response.finishReason !== "stop") {
|
|
1330
|
+
throw new StructuredOutputError2(`[SixbModels] Structured output did not complete successfully (${response.finishReason}).`, structuredOutputErrorContext(input, response, responseId, cost, text));
|
|
1331
|
+
}
|
|
1332
|
+
let raw;
|
|
1333
|
+
try {
|
|
1334
|
+
raw = JSON.parse(text);
|
|
1335
|
+
} catch (error) {
|
|
1336
|
+
throw new StructuredOutputError2("[SixbModels] Model did not produce valid JSON output.", {
|
|
1337
|
+
cause: error,
|
|
1338
|
+
...structuredOutputErrorContext(input, response, responseId, cost, text)
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
try {
|
|
1342
|
+
return {
|
|
1343
|
+
status: "completed",
|
|
1344
|
+
output: input.output.validate(raw),
|
|
1345
|
+
steps,
|
|
1346
|
+
finishReason: response.finishReason
|
|
1347
|
+
};
|
|
1348
|
+
} catch (error) {
|
|
1349
|
+
throw new StructuredOutputError2("[SixbModels] Structured output validation failed.", {
|
|
1350
|
+
cause: error,
|
|
1351
|
+
...structuredOutputErrorContext(input, response, responseId, cost, text)
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
const output = responseText(response);
|
|
1356
|
+
return { status: "completed", output, steps, finishReason: response.finishReason };
|
|
1357
|
+
}
|
|
1358
|
+
const toolResults = await Promise.all(localCalls.map((call) => executeToolCall(call, tools, callId, input.signal, input.onEvent)));
|
|
1359
|
+
const step = modelStep(response, responseId, [...response.content, ...toolResults], cost);
|
|
1360
|
+
steps.push(step);
|
|
1361
|
+
await input.onStepEnd?.(step);
|
|
1362
|
+
if (input.signal.aborted) {
|
|
1363
|
+
return {
|
|
1364
|
+
status: "aborted",
|
|
1365
|
+
steps,
|
|
1366
|
+
partialContent: []
|
|
1367
|
+
};
|
|
1368
|
+
}
|
|
1369
|
+
const assistantContent = response.content.filter((part) => part.type !== "tool-result" || part.providerExecuted === true);
|
|
1370
|
+
messages = [
|
|
1371
|
+
...requestMessages,
|
|
1372
|
+
{ role: "assistant", content: assistantContent },
|
|
1373
|
+
{ role: "tool", content: toolResults }
|
|
1374
|
+
];
|
|
1375
|
+
if (stepIndex + 1 === input.maxSteps) {
|
|
1376
|
+
if (input.output) {
|
|
1377
|
+
throw new StructuredOutputError2("[SixbModels] Model reached the step limit without structured output.", structuredOutputErrorContext(input, response, responseId, cost, responseText(response)));
|
|
1378
|
+
}
|
|
1379
|
+
const output = responseText(response);
|
|
1380
|
+
return { status: "completed", output, steps, finishReason: response.finishReason };
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
throw new ModelStreamError2("[SixbModels] Model loop exited without a terminal result.");
|
|
1384
|
+
}
|
|
1385
|
+
function assertLoopInput(input) {
|
|
1386
|
+
if (input.maxOutputTokens !== undefined && (!Number.isSafeInteger(input.maxOutputTokens) || input.maxOutputTokens <= 0)) {
|
|
1387
|
+
throw new TypeError("[SixbModels] maxOutputTokens must be a positive safe integer.");
|
|
1388
|
+
}
|
|
1389
|
+
if (!Number.isInteger(input.maxSteps) || input.maxSteps <= 0) {
|
|
1390
|
+
throw new TypeError("[SixbModels] maxSteps must be a positive integer.");
|
|
1391
|
+
}
|
|
1392
|
+
if (!input.model.providerId.trim() || !input.model.modelId.trim()) {
|
|
1393
|
+
throw new TypeError("[SixbModels] Model providerId and modelId must not be empty.");
|
|
1394
|
+
}
|
|
1395
|
+
if (input.model.definition.providerId !== input.model.providerId || input.model.definition.modelId !== input.model.modelId) {
|
|
1396
|
+
throw new TypeError(`[SixbModels] Model definition for '${input.model.providerId}/${input.model.modelId}' has a different identity.`);
|
|
1397
|
+
}
|
|
1398
|
+
if (input.output) {
|
|
1399
|
+
if (!input.output.name.trim()) {
|
|
1400
|
+
throw new TypeError("[SixbModels] Structured output names must not be empty.");
|
|
1401
|
+
}
|
|
1402
|
+
assertJsonObject2(input.output.schema, "structured output schema");
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
function indexTools(tools) {
|
|
1406
|
+
const result = new Map;
|
|
1407
|
+
for (const tool of tools) {
|
|
1408
|
+
if (!tool.name.trim())
|
|
1409
|
+
throw new TypeError("[SixbModels] Tool names must not be empty.");
|
|
1410
|
+
if (result.has(tool.name)) {
|
|
1411
|
+
throw new TypeError(`[SixbModels] Duplicate tool name '${tool.name}'.`);
|
|
1412
|
+
}
|
|
1413
|
+
assertJsonObject2(tool.inputSchema, `tool '${tool.name}' input schema`);
|
|
1414
|
+
result.set(tool.name, tool);
|
|
1415
|
+
}
|
|
1416
|
+
return result;
|
|
1417
|
+
}
|
|
1418
|
+
function responseText(response) {
|
|
1419
|
+
return response.content.filter((part) => part.type === "text").map((part) => part.text).join("");
|
|
1420
|
+
}
|
|
1421
|
+
function structuredOutputErrorContext(input, response, responseId, cost, text) {
|
|
1422
|
+
return {
|
|
1423
|
+
text,
|
|
1424
|
+
providerId: input.model.providerId,
|
|
1425
|
+
modelId: input.model.modelId,
|
|
1426
|
+
responseId,
|
|
1427
|
+
...response.responseModelId === undefined ? {} : { responseModelId: response.responseModelId },
|
|
1428
|
+
finishReason: response.finishReason,
|
|
1429
|
+
usage: response.usage,
|
|
1430
|
+
cost
|
|
1431
|
+
};
|
|
1432
|
+
}
|
|
1433
|
+
function modelStep(response, responseId, content, cost) {
|
|
1434
|
+
return {
|
|
1435
|
+
content,
|
|
1436
|
+
finishReason: response.finishReason,
|
|
1437
|
+
...response.rawFinishReason === undefined ? {} : { rawFinishReason: response.rawFinishReason },
|
|
1438
|
+
usage: response.usage,
|
|
1439
|
+
responseId,
|
|
1440
|
+
...response.responseModelId === undefined ? {} : { responseModelId: response.responseModelId },
|
|
1441
|
+
cost,
|
|
1442
|
+
...response.route === undefined ? {} : { route: response.route }
|
|
1443
|
+
};
|
|
1444
|
+
}
|
|
1445
|
+
async function executeToolCall(call, tools, callId, signal, onEvent) {
|
|
1446
|
+
const { part } = call;
|
|
1447
|
+
if (call.inputError) {
|
|
1448
|
+
const errorText = `Tool input is not valid JSON: ${call.inputError.message}`;
|
|
1449
|
+
await onEvent?.({
|
|
1450
|
+
type: "tool-input-error",
|
|
1451
|
+
toolCallId: part.toolCallId,
|
|
1452
|
+
toolName: part.toolName,
|
|
1453
|
+
input: part.input,
|
|
1454
|
+
errorText
|
|
1455
|
+
});
|
|
1456
|
+
return toolErrorResult(part, errorText);
|
|
1457
|
+
}
|
|
1458
|
+
const tool = tools.get(part.toolName);
|
|
1459
|
+
if (!tool) {
|
|
1460
|
+
const errorText = `Tool '${part.toolName}' is not available.`;
|
|
1461
|
+
await onEvent?.({
|
|
1462
|
+
type: "tool-output-error",
|
|
1463
|
+
toolCallId: part.toolCallId,
|
|
1464
|
+
toolName: part.toolName,
|
|
1465
|
+
errorText
|
|
1466
|
+
});
|
|
1467
|
+
return toolErrorResult(part, errorText);
|
|
1468
|
+
}
|
|
1469
|
+
let parsed;
|
|
1470
|
+
try {
|
|
1471
|
+
parsed = tool.parseInput(part.input);
|
|
1472
|
+
} catch (error) {
|
|
1473
|
+
const errorText = error instanceof Error ? error.message : "Tool input validation failed.";
|
|
1474
|
+
await onEvent?.({
|
|
1475
|
+
type: "tool-input-error",
|
|
1476
|
+
toolCallId: part.toolCallId,
|
|
1477
|
+
toolName: part.toolName,
|
|
1478
|
+
input: part.input,
|
|
1479
|
+
errorText
|
|
1480
|
+
});
|
|
1481
|
+
return toolErrorResult(part, errorText);
|
|
1482
|
+
}
|
|
1483
|
+
await onEvent?.({
|
|
1484
|
+
type: "tool-input-available",
|
|
1485
|
+
toolCallId: part.toolCallId,
|
|
1486
|
+
toolName: part.toolName,
|
|
1487
|
+
input: part.input
|
|
1488
|
+
});
|
|
1489
|
+
let output;
|
|
1490
|
+
let modelOutput;
|
|
1491
|
+
try {
|
|
1492
|
+
const context = { signal, callId, toolCallId: part.toolCallId };
|
|
1493
|
+
output = await tool.execute(parsed, context);
|
|
1494
|
+
assertJsonValue2(output, `tool '${part.toolName}' output`);
|
|
1495
|
+
modelOutput = tool.toModelOutput ? await tool.toModelOutput(output, context) : modelToolOutput(output);
|
|
1496
|
+
validateModelToolOutput(modelOutput, part.toolName);
|
|
1497
|
+
} catch (error) {
|
|
1498
|
+
const errorText = tool.errorText(error);
|
|
1499
|
+
await onEvent?.({
|
|
1500
|
+
type: "tool-output-error",
|
|
1501
|
+
toolCallId: part.toolCallId,
|
|
1502
|
+
toolName: part.toolName,
|
|
1503
|
+
errorText
|
|
1504
|
+
});
|
|
1505
|
+
return toolErrorResult(part, errorText);
|
|
1506
|
+
}
|
|
1507
|
+
await onEvent?.({
|
|
1508
|
+
type: "tool-output-available",
|
|
1509
|
+
toolCallId: part.toolCallId,
|
|
1510
|
+
toolName: part.toolName,
|
|
1511
|
+
output
|
|
1512
|
+
});
|
|
1513
|
+
return {
|
|
1514
|
+
type: "tool-result",
|
|
1515
|
+
toolCallId: part.toolCallId,
|
|
1516
|
+
toolName: part.toolName,
|
|
1517
|
+
output: modelOutput,
|
|
1518
|
+
...modelOutputMatchesOriginal(modelOutput, output) ? {} : { originalOutput: output }
|
|
1519
|
+
};
|
|
1520
|
+
}
|
|
1521
|
+
function validateModelToolOutput(output, toolName) {
|
|
1522
|
+
if (output.type === "text" || output.type === "error-text") {
|
|
1523
|
+
if (typeof output.value !== "string") {
|
|
1524
|
+
throw new TypeError(`[SixbModels] Tool '${toolName}' model output must contain text.`);
|
|
1525
|
+
}
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
if (output.type !== "json" && output.type !== "error-json") {
|
|
1529
|
+
throw new TypeError(`[SixbModels] Tool '${toolName}' returned an unsupported model output type.`);
|
|
1530
|
+
}
|
|
1531
|
+
assertJsonValue2(output.value, `tool '${toolName}' model output`);
|
|
1532
|
+
}
|
|
1533
|
+
function modelOutputMatchesOriginal(output, original) {
|
|
1534
|
+
if (output.type === "text")
|
|
1535
|
+
return typeof original === "string" && output.value === original;
|
|
1536
|
+
if (output.type === "json")
|
|
1537
|
+
return output.value === original;
|
|
1538
|
+
return false;
|
|
1539
|
+
}
|
|
1540
|
+
function modelToolOutput(value) {
|
|
1541
|
+
return typeof value === "string" ? { type: "text", value } : { type: "json", value };
|
|
1542
|
+
}
|
|
1543
|
+
function toolErrorResult(part, errorText) {
|
|
1544
|
+
if (typeof errorText !== "string") {
|
|
1545
|
+
throw new TypeError(`[SixbModels] Tool '${part.toolName}' error text must be a string.`);
|
|
1546
|
+
}
|
|
1547
|
+
return {
|
|
1548
|
+
type: "tool-result",
|
|
1549
|
+
toolCallId: part.toolCallId,
|
|
1550
|
+
toolName: part.toolName,
|
|
1551
|
+
output: { type: "error-text", value: errorText }
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
class StreamAccumulator {
|
|
1556
|
+
onEvent;
|
|
1557
|
+
parts = [];
|
|
1558
|
+
spans = new Map;
|
|
1559
|
+
toolCalls = new Map;
|
|
1560
|
+
started = false;
|
|
1561
|
+
finished = false;
|
|
1562
|
+
finishReason;
|
|
1563
|
+
rawFinishReason;
|
|
1564
|
+
usage = {};
|
|
1565
|
+
responseId;
|
|
1566
|
+
providerIds;
|
|
1567
|
+
responseModelId;
|
|
1568
|
+
projectionError;
|
|
1569
|
+
reportedCost;
|
|
1570
|
+
route;
|
|
1571
|
+
constructor(onEvent) {
|
|
1572
|
+
this.onEvent = onEvent;
|
|
1573
|
+
}
|
|
1574
|
+
isFinished() {
|
|
1575
|
+
return this.finished;
|
|
1576
|
+
}
|
|
1577
|
+
async accept(event) {
|
|
1578
|
+
if (this.finished) {
|
|
1579
|
+
throw new ModelStreamError2(`[SixbModels] Received '${event.type}' after stream finish.`);
|
|
1580
|
+
}
|
|
1581
|
+
switch (event.type) {
|
|
1582
|
+
case "stream-start":
|
|
1583
|
+
if (this.started)
|
|
1584
|
+
throw new ModelStreamError2("[SixbModels] Duplicate stream-start event.");
|
|
1585
|
+
this.started = true;
|
|
1586
|
+
return;
|
|
1587
|
+
case "response-metadata":
|
|
1588
|
+
this.requireStarted(event.type);
|
|
1589
|
+
this.responseId = event.id ?? this.responseId;
|
|
1590
|
+
if (event.providerIds)
|
|
1591
|
+
this.providerIds = { ...this.providerIds, ...event.providerIds };
|
|
1592
|
+
this.responseModelId = event.modelId ?? this.responseModelId;
|
|
1593
|
+
return;
|
|
1594
|
+
case "text-start":
|
|
1595
|
+
await this.startText(event);
|
|
1596
|
+
return;
|
|
1597
|
+
case "text-delta":
|
|
1598
|
+
await this.appendText(event, "text");
|
|
1599
|
+
return;
|
|
1600
|
+
case "text-end":
|
|
1601
|
+
await this.endText(event, "text");
|
|
1602
|
+
return;
|
|
1603
|
+
case "reasoning-start":
|
|
1604
|
+
await this.startReasoning(event);
|
|
1605
|
+
return;
|
|
1606
|
+
case "reasoning-delta":
|
|
1607
|
+
await this.appendText(event, "reasoning");
|
|
1608
|
+
return;
|
|
1609
|
+
case "reasoning-end":
|
|
1610
|
+
await this.endText(event, "reasoning");
|
|
1611
|
+
return;
|
|
1612
|
+
case "tool-input-start":
|
|
1613
|
+
await this.startTool(event);
|
|
1614
|
+
return;
|
|
1615
|
+
case "tool-input-delta":
|
|
1616
|
+
await this.appendTool(event);
|
|
1617
|
+
return;
|
|
1618
|
+
case "tool-input-end":
|
|
1619
|
+
this.endTool(event);
|
|
1620
|
+
return;
|
|
1621
|
+
case "tool-call":
|
|
1622
|
+
await this.completeTool(event);
|
|
1623
|
+
return;
|
|
1624
|
+
case "tool-result":
|
|
1625
|
+
this.addProviderToolResult(event);
|
|
1626
|
+
return;
|
|
1627
|
+
case "provider-state":
|
|
1628
|
+
if (typeof event.providerId !== "string" || event.providerId.length === 0) {
|
|
1629
|
+
this.captureProjectionError(new ModelStreamError2("[SixbModels] Provider state requires a nonempty provider ID."));
|
|
1630
|
+
return;
|
|
1631
|
+
}
|
|
1632
|
+
if (this.captureProviderState(event.data)) {
|
|
1633
|
+
this.parts.push({
|
|
1634
|
+
type: "provider-state",
|
|
1635
|
+
providerId: event.providerId,
|
|
1636
|
+
data: event.data
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1639
|
+
return;
|
|
1640
|
+
case "finish":
|
|
1641
|
+
this.requireStarted(event.type);
|
|
1642
|
+
validateUsage(event.usage);
|
|
1643
|
+
this.captureProviderData(event.providerData);
|
|
1644
|
+
this.finished = true;
|
|
1645
|
+
this.finishReason = event.finishReason;
|
|
1646
|
+
this.rawFinishReason = event.rawFinishReason;
|
|
1647
|
+
this.usage = event.usage;
|
|
1648
|
+
this.reportedCost = event.reportedCost;
|
|
1649
|
+
this.route = event.route;
|
|
1650
|
+
return;
|
|
1651
|
+
case "error":
|
|
1652
|
+
throw event.error instanceof Error ? event.error : new ModelProviderError2("[SixbModels] Provider stream failed.", "unknown", "unknown", {
|
|
1653
|
+
cause: event.error
|
|
1654
|
+
});
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
complete() {
|
|
1658
|
+
if (!this.started)
|
|
1659
|
+
throw new ModelStreamError2("[SixbModels] Stream did not start.");
|
|
1660
|
+
if (!this.finished || !this.finishReason) {
|
|
1661
|
+
throw new ModelStreamError2("[SixbModels] Stream ended without a finish event.");
|
|
1662
|
+
}
|
|
1663
|
+
for (const part of this.parts) {
|
|
1664
|
+
if ("complete" in part && !part.complete) {
|
|
1665
|
+
throw new ModelStreamError2(`[SixbModels] Stream finished with incomplete ${part.type} content.`);
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
const parsed = this.parseParts(false);
|
|
1669
|
+
return {
|
|
1670
|
+
content: parsed.content,
|
|
1671
|
+
toolCalls: parsed.toolCalls,
|
|
1672
|
+
finishReason: this.finishReason,
|
|
1673
|
+
...this.rawFinishReason === undefined ? {} : { rawFinishReason: this.rawFinishReason },
|
|
1674
|
+
...this.accounting(),
|
|
1675
|
+
...this.projectionError === undefined ? {} : { projectionError: this.projectionError }
|
|
1676
|
+
};
|
|
1677
|
+
}
|
|
1678
|
+
accounting() {
|
|
1679
|
+
return {
|
|
1680
|
+
usage: this.usage,
|
|
1681
|
+
...this.responseId === undefined ? {} : { responseId: this.responseId },
|
|
1682
|
+
...this.providerIds === undefined ? {} : { providerIds: this.providerIds },
|
|
1683
|
+
...this.responseModelId === undefined ? {} : { responseModelId: this.responseModelId },
|
|
1684
|
+
...this.reportedCost === undefined ? {} : { reportedCost: this.reportedCost },
|
|
1685
|
+
...this.route === undefined ? {} : { route: this.route }
|
|
1686
|
+
};
|
|
1687
|
+
}
|
|
1688
|
+
partialContent() {
|
|
1689
|
+
return this.parseParts(true).content;
|
|
1690
|
+
}
|
|
1691
|
+
parseParts(partial) {
|
|
1692
|
+
const content = [];
|
|
1693
|
+
const toolCalls = [];
|
|
1694
|
+
for (const part of this.parts) {
|
|
1695
|
+
if (part.type === "text") {
|
|
1696
|
+
if ((!partial || part.text.length > 0) && (part.complete || partial)) {
|
|
1697
|
+
content.push({
|
|
1698
|
+
type: "text",
|
|
1699
|
+
text: part.text,
|
|
1700
|
+
...part.providerData === undefined ? {} : { providerData: part.providerData }
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
} else if (part.type === "reasoning") {
|
|
1704
|
+
if (part.complete) {
|
|
1705
|
+
content.push({
|
|
1706
|
+
type: "reasoning",
|
|
1707
|
+
text: part.text,
|
|
1708
|
+
...part.providerData === undefined ? {} : { providerData: part.providerData }
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1711
|
+
} else if (part.type === "tool-call") {
|
|
1712
|
+
if (!part.complete)
|
|
1713
|
+
continue;
|
|
1714
|
+
let value = null;
|
|
1715
|
+
let inputError;
|
|
1716
|
+
try {
|
|
1717
|
+
const parsed = JSON.parse(part.inputText);
|
|
1718
|
+
if (!isJsonValue2(parsed))
|
|
1719
|
+
throw new TypeError("input is not a JSON value");
|
|
1720
|
+
value = parsed;
|
|
1721
|
+
} catch (error) {
|
|
1722
|
+
inputError = error instanceof Error ? error : new Error(String(error));
|
|
1723
|
+
}
|
|
1724
|
+
const call = {
|
|
1725
|
+
type: "tool-call",
|
|
1726
|
+
toolCallId: part.toolCallId,
|
|
1727
|
+
toolName: part.toolName,
|
|
1728
|
+
input: value,
|
|
1729
|
+
...part.providerData === undefined ? {} : { providerData: part.providerData },
|
|
1730
|
+
...part.providerExecuted === undefined ? {} : { providerExecuted: part.providerExecuted },
|
|
1731
|
+
...part.dynamic === undefined ? {} : { dynamic: part.dynamic }
|
|
1732
|
+
};
|
|
1733
|
+
content.push(call);
|
|
1734
|
+
toolCalls.push({ part: call, ...inputError === undefined ? {} : { inputError } });
|
|
1735
|
+
} else {
|
|
1736
|
+
content.push(part);
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
return { content, toolCalls };
|
|
1740
|
+
}
|
|
1741
|
+
async startText(event) {
|
|
1742
|
+
this.requireStarted(event.type);
|
|
1743
|
+
this.assertNewSpan(event.id);
|
|
1744
|
+
const providerData = this.captureProviderData(event.providerData);
|
|
1745
|
+
const part = {
|
|
1746
|
+
type: "text",
|
|
1747
|
+
text: "",
|
|
1748
|
+
complete: false,
|
|
1749
|
+
...providerData === undefined ? {} : { providerData }
|
|
1750
|
+
};
|
|
1751
|
+
this.spans.set(event.id, part);
|
|
1752
|
+
this.parts.push(part);
|
|
1753
|
+
await this.onEvent?.({ type: "text-start", id: event.id });
|
|
1754
|
+
}
|
|
1755
|
+
async startReasoning(event) {
|
|
1756
|
+
this.requireStarted(event.type);
|
|
1757
|
+
this.assertNewSpan(event.id);
|
|
1758
|
+
const providerData = this.captureProviderData(event.providerData);
|
|
1759
|
+
const part = {
|
|
1760
|
+
type: "reasoning",
|
|
1761
|
+
text: "",
|
|
1762
|
+
complete: false,
|
|
1763
|
+
...providerData === undefined ? {} : { providerData }
|
|
1764
|
+
};
|
|
1765
|
+
this.spans.set(event.id, part);
|
|
1766
|
+
this.parts.push(part);
|
|
1767
|
+
await this.onEvent?.({ type: "reasoning-start", id: event.id });
|
|
1768
|
+
}
|
|
1769
|
+
async appendText(event, expected) {
|
|
1770
|
+
const part = this.spans.get(event.id);
|
|
1771
|
+
if (!part || part.type !== expected || part.complete) {
|
|
1772
|
+
throw new ModelStreamError2(`[SixbModels] ${event.type} references unopened ${expected} span '${event.id}'.`);
|
|
1773
|
+
}
|
|
1774
|
+
part.text += event.delta;
|
|
1775
|
+
await this.onEvent?.({ type: event.type, id: event.id, delta: event.delta });
|
|
1776
|
+
}
|
|
1777
|
+
async endText(event, expected) {
|
|
1778
|
+
const part = this.spans.get(event.id);
|
|
1779
|
+
if (!part || part.type !== expected || part.complete) {
|
|
1780
|
+
throw new ModelStreamError2(`[SixbModels] ${event.type} references unopened ${expected} span '${event.id}'.`);
|
|
1781
|
+
}
|
|
1782
|
+
part.providerData = mergeProviderData(part.providerData, this.captureProviderData(event.providerData));
|
|
1783
|
+
part.complete = true;
|
|
1784
|
+
this.spans.delete(event.id);
|
|
1785
|
+
await this.onEvent?.({ type: event.type, id: event.id });
|
|
1786
|
+
}
|
|
1787
|
+
async startTool(event) {
|
|
1788
|
+
this.requireStarted(event.type);
|
|
1789
|
+
if (typeof event.id !== "string" || !event.id || typeof event.toolName !== "string" || !event.toolName) {
|
|
1790
|
+
throw new ModelStreamError2("[SixbModels] Tool calls require nonempty IDs and names.");
|
|
1791
|
+
}
|
|
1792
|
+
if (this.toolCalls.has(event.id)) {
|
|
1793
|
+
throw new ModelStreamError2(`[SixbModels] Duplicate tool call ID '${event.id}'.`);
|
|
1794
|
+
}
|
|
1795
|
+
const providerData = this.captureProviderData(event.providerData);
|
|
1796
|
+
const part = {
|
|
1797
|
+
type: "tool-call",
|
|
1798
|
+
toolCallId: event.id,
|
|
1799
|
+
toolName: event.toolName,
|
|
1800
|
+
inputText: "",
|
|
1801
|
+
complete: false,
|
|
1802
|
+
...providerData === undefined ? {} : { providerData },
|
|
1803
|
+
...event.providerExecuted === undefined ? {} : { providerExecuted: event.providerExecuted },
|
|
1804
|
+
...event.dynamic === undefined ? {} : { dynamic: event.dynamic }
|
|
1805
|
+
};
|
|
1806
|
+
this.toolCalls.set(event.id, part);
|
|
1807
|
+
this.parts.push(part);
|
|
1808
|
+
await this.onEvent?.({
|
|
1809
|
+
type: "tool-input-start",
|
|
1810
|
+
toolCallId: event.id,
|
|
1811
|
+
toolName: event.toolName
|
|
1812
|
+
});
|
|
1813
|
+
}
|
|
1814
|
+
async appendTool(event) {
|
|
1815
|
+
const part = this.toolCalls.get(event.id);
|
|
1816
|
+
if (!part || part.complete) {
|
|
1817
|
+
throw new ModelStreamError2(`[SixbModels] tool-input-delta references unopened tool call '${event.id}'.`);
|
|
1818
|
+
}
|
|
1819
|
+
part.inputText += event.delta;
|
|
1820
|
+
await this.onEvent?.({
|
|
1821
|
+
type: "tool-input-delta",
|
|
1822
|
+
toolCallId: event.id,
|
|
1823
|
+
toolName: part.toolName,
|
|
1824
|
+
inputTextDelta: event.delta
|
|
1825
|
+
});
|
|
1826
|
+
}
|
|
1827
|
+
endTool(event) {
|
|
1828
|
+
const part = this.toolCalls.get(event.id);
|
|
1829
|
+
if (!part || part.complete) {
|
|
1830
|
+
throw new ModelStreamError2(`[SixbModels] tool-input-end references unopened tool call '${event.id}'.`);
|
|
1831
|
+
}
|
|
1832
|
+
part.providerData = mergeProviderData(part.providerData, this.captureProviderData(event.providerData));
|
|
1833
|
+
part.complete = true;
|
|
1834
|
+
}
|
|
1835
|
+
async completeTool(event) {
|
|
1836
|
+
await this.startTool({
|
|
1837
|
+
type: "tool-input-start",
|
|
1838
|
+
id: event.toolCallId,
|
|
1839
|
+
toolName: event.toolName,
|
|
1840
|
+
...event.providerData === undefined ? {} : { providerData: event.providerData },
|
|
1841
|
+
...event.providerExecuted === undefined ? {} : { providerExecuted: event.providerExecuted },
|
|
1842
|
+
...event.dynamic === undefined ? {} : { dynamic: event.dynamic }
|
|
1843
|
+
});
|
|
1844
|
+
const part = this.toolCalls.get(event.toolCallId);
|
|
1845
|
+
if (!part)
|
|
1846
|
+
throw new ModelStreamError2("[SixbModels] Failed to index completed tool call.");
|
|
1847
|
+
part.inputText = event.input;
|
|
1848
|
+
part.complete = true;
|
|
1849
|
+
}
|
|
1850
|
+
addProviderToolResult(event) {
|
|
1851
|
+
if (!this.captureJsonValue(event.output, "provider tool result"))
|
|
1852
|
+
return;
|
|
1853
|
+
const providerData = this.captureProviderData(event.providerData);
|
|
1854
|
+
this.parts.push({
|
|
1855
|
+
type: "tool-result",
|
|
1856
|
+
toolCallId: event.toolCallId,
|
|
1857
|
+
toolName: event.toolName,
|
|
1858
|
+
output: event.isError ? { type: "error-json", value: event.output } : modelToolOutput(event.output),
|
|
1859
|
+
providerExecuted: event.providerExecuted ?? true,
|
|
1860
|
+
...event.dynamic === undefined ? {} : { dynamic: event.dynamic },
|
|
1861
|
+
...providerData === undefined ? {} : { providerData }
|
|
1862
|
+
});
|
|
1863
|
+
}
|
|
1864
|
+
captureProviderData(data) {
|
|
1865
|
+
if (data === undefined)
|
|
1866
|
+
return;
|
|
1867
|
+
try {
|
|
1868
|
+
return normalizeProviderData(data);
|
|
1869
|
+
} catch (error) {
|
|
1870
|
+
this.captureProjectionError(error);
|
|
1871
|
+
return;
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
captureProviderState(value) {
|
|
1875
|
+
if (!this.captureJsonValue(value, "provider state"))
|
|
1876
|
+
return false;
|
|
1877
|
+
if (JSON.stringify(value).length > MAX_PROVIDER_DATA_BYTES) {
|
|
1878
|
+
this.captureProjectionError(new ModelStreamError2(`[SixbModels] Provider state exceeds the ${MAX_PROVIDER_DATA_BYTES}-byte response limit.`));
|
|
1879
|
+
return false;
|
|
1880
|
+
}
|
|
1881
|
+
return true;
|
|
1882
|
+
}
|
|
1883
|
+
captureJsonValue(value, label) {
|
|
1884
|
+
try {
|
|
1885
|
+
assertJsonValue2(value, label);
|
|
1886
|
+
return true;
|
|
1887
|
+
} catch (error) {
|
|
1888
|
+
this.captureProjectionError(error);
|
|
1889
|
+
return false;
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
captureProjectionError(error) {
|
|
1893
|
+
this.projectionError ??= error instanceof Error ? error : new Error(String(error));
|
|
1894
|
+
}
|
|
1895
|
+
requireStarted(type) {
|
|
1896
|
+
if (!this.started) {
|
|
1897
|
+
throw new ModelStreamError2(`[SixbModels] Received '${type}' before stream-start.`);
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
assertNewSpan(id) {
|
|
1901
|
+
if (!id)
|
|
1902
|
+
throw new ModelStreamError2("[SixbModels] Content span IDs must not be empty.");
|
|
1903
|
+
if (this.spans.has(id)) {
|
|
1904
|
+
throw new ModelStreamError2(`[SixbModels] Duplicate open content span '${id}'.`);
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
function validateUsage(usage) {
|
|
1909
|
+
for (const [key, value] of Object.entries(usage)) {
|
|
1910
|
+
if (key === "raw") {
|
|
1911
|
+
if (value !== undefined)
|
|
1912
|
+
assertJsonValue2(value, "raw model usage");
|
|
1913
|
+
continue;
|
|
1914
|
+
}
|
|
1915
|
+
if (value !== undefined && (!Number.isSafeInteger(value) || value < 0)) {
|
|
1916
|
+
throw new ModelStreamError2(`[SixbModels] Usage field '${key}' must be a nonnegative integer.`);
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
function normalizeProviderData(value) {
|
|
1921
|
+
const data = omitUndefinedObjectProperties(value);
|
|
1922
|
+
assertJsonValue2(data, "provider data");
|
|
1923
|
+
if (typeof data !== "object" || data === null || Array.isArray(data)) {
|
|
1924
|
+
throw new TypeError("[SixbModels] provider data must be a JSON object.");
|
|
1925
|
+
}
|
|
1926
|
+
if (JSON.stringify(data).length > MAX_PROVIDER_DATA_BYTES) {
|
|
1927
|
+
throw new ModelStreamError2(`[SixbModels] Provider data exceeds the ${MAX_PROVIDER_DATA_BYTES}-byte response limit.`);
|
|
1928
|
+
}
|
|
1929
|
+
return data;
|
|
1930
|
+
}
|
|
1931
|
+
function omitUndefinedObjectProperties(value, seen = new Set) {
|
|
1932
|
+
if (typeof value !== "object" || value === null || seen.has(value))
|
|
1933
|
+
return value;
|
|
1934
|
+
seen.add(value);
|
|
1935
|
+
try {
|
|
1936
|
+
if (Array.isArray(value)) {
|
|
1937
|
+
return value.map((entry) => omitUndefinedObjectProperties(entry, seen));
|
|
1938
|
+
}
|
|
1939
|
+
if (!isPlainRecord(value))
|
|
1940
|
+
return value;
|
|
1941
|
+
return Object.fromEntries(Reflect.ownKeys(value).filter((key) => Object.prototype.propertyIsEnumerable.call(value, key)).map((key) => [key, Reflect.get(value, key)]).filter(([, entry]) => entry !== undefined).map(([key, entry]) => [key, omitUndefinedObjectProperties(entry, seen)]));
|
|
1942
|
+
} finally {
|
|
1943
|
+
seen.delete(value);
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
function mergeProviderData(first, second) {
|
|
1947
|
+
if (first === undefined)
|
|
1948
|
+
return second;
|
|
1949
|
+
if (second === undefined)
|
|
1950
|
+
return first;
|
|
1951
|
+
return { ...first, ...second };
|
|
1952
|
+
}
|
|
1953
|
+
function isAbortError(error) {
|
|
1954
|
+
return error instanceof DOMException && error.name === "AbortError" || error instanceof Error && error.name === "AbortError";
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
// src/models/execution/binding.ts
|
|
1958
|
+
var bindings = new WeakMap;
|
|
1959
|
+
function registerModelExecutionBinding(models, bind) {
|
|
1960
|
+
bindings.set(models, bind);
|
|
1961
|
+
}
|
|
1962
|
+
function bindModelExecutionAttempt(models, input) {
|
|
1963
|
+
const bind = bindings.get(models);
|
|
1964
|
+
if (!bind)
|
|
1965
|
+
throw new Error("[SixbModels] Model runtime has no execution binding.");
|
|
1966
|
+
if (!Number.isSafeInteger(input.attempt) || input.attempt < 1) {
|
|
1967
|
+
throw new TypeError("[SixbModels] Execution attempt must be a positive safe integer.");
|
|
1968
|
+
}
|
|
1969
|
+
bind(input);
|
|
1970
|
+
bindings.delete(models);
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
// src/models/output.ts
|
|
1974
|
+
function languageModelOutput(shape, valueTypesById) {
|
|
1975
|
+
if (!isRecord2(shape))
|
|
1976
|
+
throw new TypeError("[SixbModels] output must be a Sixb schema record.");
|
|
1977
|
+
const schema = schemaRecordToJsonSchema2({ shape, valueTypesById });
|
|
1978
|
+
assertJsonObject2(schema, "model output schema");
|
|
1979
|
+
return {
|
|
1980
|
+
name: "sixb_output",
|
|
1981
|
+
schema,
|
|
1982
|
+
validate(value) {
|
|
1983
|
+
if (!isRecord2(value))
|
|
1984
|
+
throw new TypeError("[SixbModels] Output must be an object.");
|
|
1985
|
+
for (const key of Object.keys(value)) {
|
|
1986
|
+
if (!Object.hasOwn(shape, key)) {
|
|
1987
|
+
throw new TypeError(`[SixbModels] Unknown output field '${key}'.`);
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
return Object.fromEntries(Object.entries(shape).map(([key, field]) => {
|
|
1991
|
+
if (!Object.hasOwn(value, key)) {
|
|
1992
|
+
throw new TypeError(`[SixbModels] Missing output field '${key}'.`);
|
|
1993
|
+
}
|
|
1994
|
+
validateSchemaOrRefValue2(field, value[key], `output.${key}`, valueTypesById);
|
|
1995
|
+
const output = isObjectRefSchema2(field) ? value[key] : coerceSchemaValueToTyped2(field, normalizeSchemaValue2(field, value[key], `output.${key}`, valueTypesById), valueTypesById);
|
|
1996
|
+
return [key, output];
|
|
1997
|
+
}));
|
|
1998
|
+
}
|
|
1999
|
+
};
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
// src/models/execution.ts
|
|
2003
|
+
function createModelsRuntime(runtime, execution, catalog) {
|
|
2004
|
+
let binding;
|
|
2005
|
+
let recorder;
|
|
2006
|
+
async function createRecorder() {
|
|
2007
|
+
const storage = {
|
|
2008
|
+
...requireAccountingCapabilities(runtime.storage),
|
|
2009
|
+
transaction: runtime.storage.transaction.bind(runtime.storage)
|
|
2010
|
+
};
|
|
2011
|
+
if (!binding) {
|
|
2012
|
+
throw new Error("[SixbModels] Generation requires a bound request or worker execution attempt.");
|
|
2013
|
+
}
|
|
2014
|
+
const { requesterGroupIds } = await ensureExecutionRecord2(runtime.storage.executions, executionRecordInputFromRuntime({
|
|
2015
|
+
execution,
|
|
2016
|
+
runtimeAuthorization: runtime.runtimeAuthorization
|
|
2017
|
+
}));
|
|
2018
|
+
return new AiModelCallRecorder2({
|
|
2019
|
+
storage,
|
|
2020
|
+
projectId: runtime.projectId,
|
|
2021
|
+
executionId: execution.id,
|
|
2022
|
+
attempt: binding.attempt,
|
|
2023
|
+
requesterGroupIds,
|
|
2024
|
+
limits: createAiModelCallLimitController2({
|
|
2025
|
+
storage,
|
|
2026
|
+
projectId: runtime.projectId,
|
|
2027
|
+
requestedBy: execution.requestedBy,
|
|
2028
|
+
requesterGroupIds
|
|
2029
|
+
}),
|
|
2030
|
+
recoverAiModelCall: (input) => enqueueAiModelCallRecovery2(runtime.queues.agents, input)
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
async function generate(input) {
|
|
2034
|
+
assertProviderAccess2(runtime, execution, "models.language.generate");
|
|
2035
|
+
const messages = generationMessages(input);
|
|
2036
|
+
if (!binding) {
|
|
2037
|
+
throw new Error("[SixbModels] Generation requires a bound request or worker execution attempt.");
|
|
2038
|
+
}
|
|
2039
|
+
const signal = input.signal ? AbortSignal.any([binding.signal, input.signal]) : binding.signal;
|
|
2040
|
+
signal.throwIfAborted();
|
|
2041
|
+
const selected = input.model ? catalog ? catalog.language.getByRef({
|
|
2042
|
+
provider: input.model.providerId,
|
|
2043
|
+
modelId: input.model.modelId
|
|
2044
|
+
})?.model : input.model : catalog?.language.default.model;
|
|
2045
|
+
if (!selected) {
|
|
2046
|
+
throw new Error(input.model ? `[SixbModels] Model '${input.model.providerId}/${input.model.modelId}' is not configured in models.language.` : "[SixbModels] Configure models.language in createSixb() or supply a model to generate().");
|
|
2047
|
+
}
|
|
2048
|
+
const output = input.output === undefined ? undefined : languageModelOutput(input.output, runtime.ontology.getValueTypesById());
|
|
2049
|
+
const model = await resolveLanguageModel2(selected);
|
|
2050
|
+
const reasoningIssue = modelReasoningSupportIssue2(model.definition.capabilities.reasoning, input.reasoning);
|
|
2051
|
+
if (reasoningIssue)
|
|
2052
|
+
throw new UnsupportedModelFeatureError2(`[SixbModels] ${reasoningIssue}.`);
|
|
2053
|
+
if (output && model.definition.capabilities.nativeStructuredOutput === false) {
|
|
2054
|
+
throw new UnsupportedModelFeatureError2("[SixbModels] Model does not support native structured output.");
|
|
2055
|
+
}
|
|
2056
|
+
const maxOutputTokens = Math.min(aiModelCallOutputTokenAllowance(input.maxOutputTokens ?? model.definition.maxOutputTokens), model.definition.maxOutputTokens ?? Infinity);
|
|
2057
|
+
if (typeof input.reasoning === "object" && input.reasoning.budgetTokens >= maxOutputTokens) {
|
|
2058
|
+
throw new TypeError("[SixbModels] Output allowance must exceed the reasoning token budget.");
|
|
2059
|
+
}
|
|
2060
|
+
recorder ??= createRecorder();
|
|
2061
|
+
const accounting = await recorder;
|
|
2062
|
+
accounting.assertHealthy();
|
|
2063
|
+
signal.throwIfAborted();
|
|
2064
|
+
let event;
|
|
2065
|
+
const options = {
|
|
2066
|
+
model: accounting.wrapModel(model),
|
|
2067
|
+
messages,
|
|
2068
|
+
maxSteps: 1,
|
|
2069
|
+
rejectLocalToolCalls: true,
|
|
2070
|
+
maxOutputTokens,
|
|
2071
|
+
reasoning: input.reasoning,
|
|
2072
|
+
caching: input.caching,
|
|
2073
|
+
signal,
|
|
2074
|
+
onModelCallEnd: async (completed) => {
|
|
2075
|
+
await accounting.onModelCallEnd(completed);
|
|
2076
|
+
event = completed;
|
|
2077
|
+
}
|
|
2078
|
+
};
|
|
2079
|
+
const result = output ? await runModelLoop2({ ...options, output }) : await runModelLoop2(options);
|
|
2080
|
+
if (result.status === "aborted") {
|
|
2081
|
+
signal.throwIfAborted();
|
|
2082
|
+
throw new DOMException("Model generation aborted", "AbortError");
|
|
2083
|
+
}
|
|
2084
|
+
if (result.finishReason === "error" || result.finishReason === "content-filter") {
|
|
2085
|
+
throw new ModelProviderError2(`[SixbModels] Generation ended with '${result.finishReason}'.`, model.providerId, model.modelId);
|
|
2086
|
+
}
|
|
2087
|
+
if (!event)
|
|
2088
|
+
throw new ModelStreamError2("[SixbModels] Generation completed without accounting metadata.");
|
|
2089
|
+
return {
|
|
2090
|
+
output: result.output,
|
|
2091
|
+
usage: event.usage,
|
|
2092
|
+
cost: event.cost,
|
|
2093
|
+
callId: event.callId,
|
|
2094
|
+
finishReason: result.finishReason
|
|
2095
|
+
};
|
|
2096
|
+
}
|
|
2097
|
+
const models = {
|
|
2098
|
+
language: { generate }
|
|
2099
|
+
};
|
|
2100
|
+
registerModelExecutionBinding(models, (input) => {
|
|
2101
|
+
binding = { attempt: input.attempt, signal: input.signal };
|
|
2102
|
+
});
|
|
2103
|
+
return models;
|
|
2104
|
+
}
|
|
2105
|
+
function generationMessages(input) {
|
|
2106
|
+
if (input.prompt === undefined === (input.messages === undefined)) {
|
|
2107
|
+
throw new TypeError("[SixbModels] Supply exactly one of prompt or messages.");
|
|
2108
|
+
}
|
|
2109
|
+
if (input.prompt !== undefined && typeof input.prompt !== "string") {
|
|
2110
|
+
throw new TypeError("[SixbModels] prompt must be a string.");
|
|
2111
|
+
}
|
|
2112
|
+
if (input.messages !== undefined && !Array.isArray(input.messages)) {
|
|
2113
|
+
throw new TypeError("[SixbModels] messages must be an array.");
|
|
2114
|
+
}
|
|
2115
|
+
if (input.instructions !== undefined && typeof input.instructions !== "string") {
|
|
2116
|
+
throw new TypeError("[SixbModels] instructions must be a string.");
|
|
2117
|
+
}
|
|
2118
|
+
if (input.maxOutputTokens !== undefined && (!Number.isSafeInteger(input.maxOutputTokens) || input.maxOutputTokens <= 0)) {
|
|
2119
|
+
throw new TypeError("[SixbModels] maxOutputTokens must be a positive safe integer.");
|
|
2120
|
+
}
|
|
2121
|
+
if (input.caching !== undefined && input.caching !== "auto" && input.caching !== "off") {
|
|
2122
|
+
throw new TypeError("[SixbModels] caching must be 'auto' or 'off'.");
|
|
2123
|
+
}
|
|
2124
|
+
return [
|
|
2125
|
+
...input.instructions === undefined ? [] : [{ role: "system", content: input.instructions }],
|
|
2126
|
+
...input.prompt !== undefined ? [{ role: "user", content: [{ type: "text", text: input.prompt }] }] : input.messages ?? []
|
|
2127
|
+
];
|
|
2128
|
+
}
|
|
2129
|
+
|
|
1174
2130
|
// src/objects/execution.ts
|
|
1175
2131
|
function createObjectsRuntime(runtime, execution) {
|
|
1176
2132
|
const runtimeAuthorization = runtime.runtimeAuthorization;
|
|
@@ -1192,13 +2148,13 @@ function createObjectsRuntime(runtime, execution) {
|
|
|
1192
2148
|
objectReader,
|
|
1193
2149
|
...authorization === undefined ? {} : { authorization }
|
|
1194
2150
|
};
|
|
1195
|
-
|
|
1196
|
-
|
|
2151
|
+
shareOntologyMutationRuntime2(runtime, capturedRuntime);
|
|
2152
|
+
shareSixbErrorReporter2(runtime, capturedRuntime);
|
|
1197
2153
|
Object.freeze(capturedRuntime);
|
|
1198
2154
|
const ontologyView = () => getAuthorizedOntologyView(objectReader);
|
|
1199
2155
|
const objects = Object.assign((objectType) => {
|
|
1200
|
-
|
|
1201
|
-
return
|
|
2156
|
+
assertObjectTypeRegistered2(capturedRuntime.ontology.getObjectTypesById(), objectType);
|
|
2157
|
+
return createObjectSet2({ ...capturedRuntime, execution, objectType });
|
|
1202
2158
|
}, {
|
|
1203
2159
|
listTypes: () => ontologyView().listObjectTypes(),
|
|
1204
2160
|
getTypeById: (objectTypeId) => ontologyView().getObjectTypeById(objectTypeId),
|
|
@@ -1216,7 +2172,7 @@ function createObjectsRuntime(runtime, execution) {
|
|
|
1216
2172
|
},
|
|
1217
2173
|
getTelemetryHistoryBatch: (input) => {
|
|
1218
2174
|
const timeseries = capturedRuntime.storage.timeseries;
|
|
1219
|
-
return
|
|
2175
|
+
return getTelemetryHistoryBatch2(input, { storage: timeseries, objectReader });
|
|
1220
2176
|
},
|
|
1221
2177
|
getTelemetryHistory: async (input) => {
|
|
1222
2178
|
const timeseries = capturedRuntime.storage.timeseries;
|
|
@@ -1227,7 +2183,7 @@ function createObjectsRuntime(runtime, execution) {
|
|
|
1227
2183
|
const to = input.to;
|
|
1228
2184
|
const limit = input.limit;
|
|
1229
2185
|
const order = input.order;
|
|
1230
|
-
const [result] = await
|
|
2186
|
+
const [result] = await getTelemetryHistoryBatch2({
|
|
1231
2187
|
series: [{ objectTypeId, objectId, propertyId }],
|
|
1232
2188
|
...from === undefined ? {} : { from },
|
|
1233
2189
|
...to === undefined ? {} : { to },
|
|
@@ -1248,11 +2204,11 @@ function createObjectsRuntime(runtime, execution) {
|
|
|
1248
2204
|
getPrimaryPropertyId: (objectTypeId) => {
|
|
1249
2205
|
return ontologyView().getPrimaryPropertyId(objectTypeId);
|
|
1250
2206
|
},
|
|
1251
|
-
upsert: (objectTypeId, properties) =>
|
|
1252
|
-
upsertBatch: (objectTypeId, items) =>
|
|
1253
|
-
upsertLink: (objectTypeId, sourceId, linkId, target) =>
|
|
1254
|
-
upsertLinkBatch: (items) =>
|
|
1255
|
-
removeLink: (objectTypeId, sourceId, linkId, target) =>
|
|
2207
|
+
upsert: (objectTypeId, properties) => upsertObject3(capturedRuntime, objectTypeId, properties),
|
|
2208
|
+
upsertBatch: (objectTypeId, items) => upsertObjectBatch3(capturedRuntime, objectTypeId, items),
|
|
2209
|
+
upsertLink: (objectTypeId, sourceId, linkId, target) => upsertLink3(capturedRuntime, objectTypeId, sourceId, linkId, target),
|
|
2210
|
+
upsertLinkBatch: (items) => upsertLinkBatch3(capturedRuntime, items),
|
|
2211
|
+
removeLink: (objectTypeId, sourceId, linkId, target) => removeLink3(capturedRuntime, objectTypeId, sourceId, linkId, target),
|
|
1256
2212
|
appendTelemetry: (objectTypeId, items) => appendTelemetry(capturedRuntime, objectTypeId, items)
|
|
1257
2213
|
});
|
|
1258
2214
|
return objects;
|
|
@@ -1261,7 +2217,7 @@ function createObjectsRuntime(runtime, execution) {
|
|
|
1261
2217
|
// src/pipelines/execution.ts
|
|
1262
2218
|
function createPipelinesRuntime(runtime, execution, source) {
|
|
1263
2219
|
const authority = resolveRuntimeAuthorizationForProject(runtime);
|
|
1264
|
-
const allowed = (pipelineId) =>
|
|
2220
|
+
const allowed = (pipelineId) => isRuntimeAllowed2(runtime, { kind: "pipeline.run", pipelineId });
|
|
1265
2221
|
const visibleIds = () => source.list().filter((pipeline) => allowed(pipeline.id)).map((pipeline) => pipeline.id);
|
|
1266
2222
|
const historyFilterIds = () => authority.type === "unrestricted" ? undefined : authority.type === "principal" ? visibleIds() : [];
|
|
1267
2223
|
const getRun = async (runId) => {
|
|
@@ -1273,7 +2229,7 @@ function createPipelinesRuntime(runtime, execution, source) {
|
|
|
1273
2229
|
}) ?? null;
|
|
1274
2230
|
if (!run)
|
|
1275
2231
|
return null;
|
|
1276
|
-
return authority.type === "unrestricted" ||
|
|
2232
|
+
return authority.type === "unrestricted" || canViewPipelineRun2(authority.context, run) ? run : null;
|
|
1277
2233
|
};
|
|
1278
2234
|
return {
|
|
1279
2235
|
list: () => authority.type === "denied" || authority.type === "delegated" ? [] : source.list().filter((pipeline) => allowed(pipeline.id)),
|
|
@@ -1284,11 +2240,11 @@ function createPipelinesRuntime(runtime, execution, source) {
|
|
|
1284
2240
|
return pipeline && allowed(pipelineId) ? pipeline : null;
|
|
1285
2241
|
},
|
|
1286
2242
|
request: async (input) => {
|
|
1287
|
-
|
|
2243
|
+
assertAuthorized2(runtime, { kind: "pipeline.run", pipelineId: input.pipelineId });
|
|
1288
2244
|
const pipeline = source.getById(input.pipelineId);
|
|
1289
2245
|
if (!pipeline)
|
|
1290
|
-
throw new
|
|
1291
|
-
return
|
|
2246
|
+
throw new PipelineError2(`[Sixb] Unknown pipeline '${input.pipelineId}'`);
|
|
2247
|
+
return requestPipelineRun2(runtime, execution, pipeline, input);
|
|
1292
2248
|
},
|
|
1293
2249
|
runs: {
|
|
1294
2250
|
getById: getRun,
|
|
@@ -1341,7 +2297,7 @@ function createProjectionsRuntime(runtime, source) {
|
|
|
1341
2297
|
case "delegated":
|
|
1342
2298
|
return [];
|
|
1343
2299
|
case "principal":
|
|
1344
|
-
return list().filter((projection) =>
|
|
2300
|
+
return list().filter((projection) => canViewProjection2(authority.context, projection));
|
|
1345
2301
|
case "unrestricted":
|
|
1346
2302
|
return [...list()];
|
|
1347
2303
|
}
|
|
@@ -1352,7 +2308,7 @@ function createProjectionsRuntime(runtime, source) {
|
|
|
1352
2308
|
case "delegated":
|
|
1353
2309
|
return false;
|
|
1354
2310
|
case "principal":
|
|
1355
|
-
return
|
|
2311
|
+
return canViewProjection2(authority.context, projection);
|
|
1356
2312
|
case "unrestricted":
|
|
1357
2313
|
return true;
|
|
1358
2314
|
}
|
|
@@ -1394,7 +2350,7 @@ function createProjectionsRuntime(runtime, source) {
|
|
|
1394
2350
|
}) ?? null;
|
|
1395
2351
|
if (!run)
|
|
1396
2352
|
return null;
|
|
1397
|
-
return authority.type === "unrestricted" ||
|
|
2353
|
+
return authority.type === "unrestricted" || canViewProjectionRun2(authority.context, run.target) ? run : null;
|
|
1398
2354
|
},
|
|
1399
2355
|
list: (input = {}) => {
|
|
1400
2356
|
switch (authority.type) {
|
|
@@ -1439,7 +2395,7 @@ function createRulesRuntime(runtime, source) {
|
|
|
1439
2395
|
const visible = (rule) => {
|
|
1440
2396
|
if (authority.type === "denied" || authority.type === "delegated")
|
|
1441
2397
|
return false;
|
|
1442
|
-
return
|
|
2398
|
+
return isRuntimeAllowed2(runtime, {
|
|
1443
2399
|
kind: "object.view",
|
|
1444
2400
|
objectTypeId: rule.subject.objectTypeId
|
|
1445
2401
|
});
|
|
@@ -1498,10 +2454,10 @@ function createSchedulesRuntime(runtime, schedules) {
|
|
|
1498
2454
|
}
|
|
1499
2455
|
|
|
1500
2456
|
// src/shares/execution.ts
|
|
1501
|
-
import { createHash as createHash2, randomBytes, randomUUID as
|
|
2457
|
+
import { createHash as createHash2, randomBytes, randomUUID as randomUUID5 } from "crypto";
|
|
1502
2458
|
var MAX_CREATE_ATTEMPTS = 5;
|
|
1503
2459
|
|
|
1504
|
-
class
|
|
2460
|
+
class ShareError2 extends Error {
|
|
1505
2461
|
reason;
|
|
1506
2462
|
name = "ShareError";
|
|
1507
2463
|
constructor(reason, message, options) {
|
|
@@ -1516,7 +2472,7 @@ function createSharesRuntime(runtime, execution, definitions) {
|
|
|
1516
2472
|
authorization: runtime.runtimeAuthorization
|
|
1517
2473
|
});
|
|
1518
2474
|
if (authority.type !== "principal" || authority.context.principal.type === "system") {
|
|
1519
|
-
throw new
|
|
2475
|
+
throw new ShareError2("unauthenticated", "[Sixb] Shared access grants require user or service-account authority.");
|
|
1520
2476
|
}
|
|
1521
2477
|
return {
|
|
1522
2478
|
type: authority.context.principal.type,
|
|
@@ -1526,7 +2482,7 @@ function createSharesRuntime(runtime, execution, definitions) {
|
|
|
1526
2482
|
const canManage = (shareId) => {
|
|
1527
2483
|
try {
|
|
1528
2484
|
managementPrincipal();
|
|
1529
|
-
return
|
|
2485
|
+
return isRuntimeAllowed2(runtime, { kind: "share.manage", shareId });
|
|
1530
2486
|
} catch {
|
|
1531
2487
|
return false;
|
|
1532
2488
|
}
|
|
@@ -1550,7 +2506,7 @@ function createSharesRuntime(runtime, execution, definitions) {
|
|
|
1550
2506
|
primaryId: target.primaryId
|
|
1551
2507
|
});
|
|
1552
2508
|
if (!object) {
|
|
1553
|
-
throw new
|
|
2509
|
+
throw new ObjectNotFoundError2(target.objectTypeId, target.primaryId, "Share target not found");
|
|
1554
2510
|
}
|
|
1555
2511
|
const authoritySnapshot = {
|
|
1556
2512
|
version: 1,
|
|
@@ -1565,7 +2521,7 @@ function createSharesRuntime(runtime, execution, definitions) {
|
|
|
1565
2521
|
const secret = randomBytes(32).toString("base64url");
|
|
1566
2522
|
try {
|
|
1567
2523
|
const grant = await storage.create({
|
|
1568
|
-
id: `shr_${
|
|
2524
|
+
id: `shr_${randomUUID5()}`,
|
|
1569
2525
|
projectId: runtime.projectId,
|
|
1570
2526
|
definitionId: definition.id,
|
|
1571
2527
|
target,
|
|
@@ -1578,10 +2534,10 @@ function createSharesRuntime(runtime, execution, definitions) {
|
|
|
1578
2534
|
});
|
|
1579
2535
|
return { grant: publicGrant(grant), secret };
|
|
1580
2536
|
} catch (error) {
|
|
1581
|
-
if (error instanceof
|
|
1582
|
-
throw new
|
|
2537
|
+
if (error instanceof ShareGrantStorageError2 && error.code === "invalid_input") {
|
|
2538
|
+
throw new ShareError2("invalid_input", error.message, { cause: error });
|
|
1583
2539
|
}
|
|
1584
|
-
if (!(error instanceof
|
|
2540
|
+
if (!(error instanceof ShareGrantStorageError2) || error.code !== "duplicate" || attempt === MAX_CREATE_ATTEMPTS - 1) {
|
|
1585
2541
|
throw storageFailure("issue", error);
|
|
1586
2542
|
}
|
|
1587
2543
|
}
|
|
@@ -1607,8 +2563,8 @@ function createSharesRuntime(runtime, execution, definitions) {
|
|
|
1607
2563
|
});
|
|
1608
2564
|
return { ...result, grants: result.grants.map(publicGrant) };
|
|
1609
2565
|
} catch (error) {
|
|
1610
|
-
if (error instanceof
|
|
1611
|
-
throw new
|
|
2566
|
+
if (error instanceof ShareGrantStorageError2 && error.code === "invalid_input") {
|
|
2567
|
+
throw new ShareError2("invalid_input", error.message, { cause: error });
|
|
1612
2568
|
}
|
|
1613
2569
|
throw storageFailure("list", error);
|
|
1614
2570
|
}
|
|
@@ -1650,7 +2606,7 @@ function createSharesRuntime(runtime, execution, definitions) {
|
|
|
1650
2606
|
const actor = managementPrincipal();
|
|
1651
2607
|
const storage = requireShareStorage(runtime);
|
|
1652
2608
|
if (typeof grantId !== "string" || !grantId.trim()) {
|
|
1653
|
-
throw new
|
|
2609
|
+
throw new ShareError2("invalid_input", "[Sixb] Shared access grant id must not be empty.");
|
|
1654
2610
|
}
|
|
1655
2611
|
let current;
|
|
1656
2612
|
try {
|
|
@@ -1682,50 +2638,50 @@ function definitionIdFromReference(value) {
|
|
|
1682
2638
|
}
|
|
1683
2639
|
function assertInputObject(value, label) {
|
|
1684
2640
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
1685
|
-
throw new
|
|
2641
|
+
throw new ShareError2("invalid_input", `[Sixb] ${label} must be an object.`);
|
|
1686
2642
|
}
|
|
1687
2643
|
}
|
|
1688
2644
|
function resolveDefinition(definitions, definitionId) {
|
|
1689
2645
|
const id = validDefinitionId(definitionId);
|
|
1690
2646
|
const definition = definitions.getById(id);
|
|
1691
2647
|
if (!definition) {
|
|
1692
|
-
throw new
|
|
2648
|
+
throw new ShareError2("not_found", `[Sixb] Unknown Share definition '${id}'.`);
|
|
1693
2649
|
}
|
|
1694
2650
|
return definition;
|
|
1695
2651
|
}
|
|
1696
2652
|
function validDefinitionId(value) {
|
|
1697
2653
|
if (typeof value !== "string" || !value.trim()) {
|
|
1698
|
-
throw new
|
|
2654
|
+
throw new ShareError2("invalid_input", "[Sixb] Share definition id must not be empty.");
|
|
1699
2655
|
}
|
|
1700
2656
|
return value;
|
|
1701
2657
|
}
|
|
1702
2658
|
function assertCanManage(runtime, shareId) {
|
|
1703
|
-
|
|
2659
|
+
assertAuthorized2(runtime, { kind: "share.manage", shareId });
|
|
1704
2660
|
}
|
|
1705
2661
|
function requireShareStorage(runtime) {
|
|
1706
2662
|
const storage = runtime.storage.shareGrants;
|
|
1707
2663
|
if (!storage) {
|
|
1708
|
-
throw new
|
|
2664
|
+
throw new ShareError2("storage_unavailable", "[Sixb] Share grant storage is not configured on this runtime.");
|
|
1709
2665
|
}
|
|
1710
2666
|
return storage;
|
|
1711
2667
|
}
|
|
1712
2668
|
function exactTarget(definition, value) {
|
|
1713
2669
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
1714
|
-
throw new
|
|
2670
|
+
throw new ShareError2("invalid_input", "[Sixb] Share target must be an exact object reference.");
|
|
1715
2671
|
}
|
|
1716
2672
|
const objectTypeId = value.objectTypeId;
|
|
1717
2673
|
const primaryId = value.primaryId;
|
|
1718
2674
|
if (typeof objectTypeId !== "string" || typeof primaryId !== "string" || !primaryId.trim()) {
|
|
1719
|
-
throw new
|
|
2675
|
+
throw new ShareError2("invalid_input", "[Sixb] Share target must be an exact object reference.");
|
|
1720
2676
|
}
|
|
1721
2677
|
if (objectTypeId !== definition.target.objectTypeId) {
|
|
1722
|
-
throw new
|
|
2678
|
+
throw new ShareError2("invalid_input", `[Sixb] Share '${definition.id}' targets '${definition.target.objectTypeId}', not '${objectTypeId}'.`);
|
|
1723
2679
|
}
|
|
1724
2680
|
return Object.freeze({ objectTypeId, primaryId });
|
|
1725
2681
|
}
|
|
1726
2682
|
function validFutureDate(value, now) {
|
|
1727
2683
|
if (!(value instanceof Date) || !Number.isFinite(value.getTime()) || value <= now) {
|
|
1728
|
-
throw new
|
|
2684
|
+
throw new ShareError2("invalid_input", "[Sixb] Shared access expiry must be a valid future date.");
|
|
1729
2685
|
}
|
|
1730
2686
|
return new Date(value);
|
|
1731
2687
|
}
|
|
@@ -1743,7 +2699,7 @@ function publicGrant(record) {
|
|
|
1743
2699
|
return structuredClone(grant);
|
|
1744
2700
|
}
|
|
1745
2701
|
function storageFailure(operation, cause) {
|
|
1746
|
-
return new
|
|
2702
|
+
return new ShareError2("storage_failure", `[Sixb] Share grant storage failed to ${operation}.`, {
|
|
1747
2703
|
cause
|
|
1748
2704
|
});
|
|
1749
2705
|
}
|
|
@@ -1751,7 +2707,7 @@ function storageFailure(operation, cause) {
|
|
|
1751
2707
|
// src/syncs/execution.ts
|
|
1752
2708
|
function createSyncsRuntime(runtime, execution, source) {
|
|
1753
2709
|
const authority = resolveRuntimeAuthorizationForProject(runtime);
|
|
1754
|
-
const allowed = (syncId) =>
|
|
2710
|
+
const allowed = (syncId) => isRuntimeAllowed2(runtime, { kind: "sync.run", syncId });
|
|
1755
2711
|
const visibleIds = () => source.list().filter((sync) => allowed(sync.id)).map((sync) => sync.id);
|
|
1756
2712
|
const historyFilterIds = () => authority.type === "unrestricted" ? undefined : authority.type === "principal" ? visibleIds() : [];
|
|
1757
2713
|
return {
|
|
@@ -1763,11 +2719,11 @@ function createSyncsRuntime(runtime, execution, source) {
|
|
|
1763
2719
|
return sync && allowed(syncId) ? sync : null;
|
|
1764
2720
|
},
|
|
1765
2721
|
request: async (input) => {
|
|
1766
|
-
|
|
2722
|
+
assertAuthorized2(runtime, { kind: "sync.run", syncId: input.syncId });
|
|
1767
2723
|
const sync = source.getById(input.syncId);
|
|
1768
2724
|
if (!sync)
|
|
1769
|
-
throw new
|
|
1770
|
-
return
|
|
2725
|
+
throw new SyncValidationError2(`[Sixb] Unknown sync '${input.syncId}'`);
|
|
2726
|
+
return requestSyncRun2(runtime, execution, sync, input);
|
|
1771
2727
|
},
|
|
1772
2728
|
runs: {
|
|
1773
2729
|
getById: async (runId) => {
|
|
@@ -1807,11 +2763,11 @@ function createSyncsRuntime(runtime, execution, source) {
|
|
|
1807
2763
|
}
|
|
1808
2764
|
|
|
1809
2765
|
// src/workflows/errors.ts
|
|
1810
|
-
class
|
|
2766
|
+
class WorkflowDefinitionError2 extends Error {
|
|
1811
2767
|
name = "WorkflowDefinitionError";
|
|
1812
2768
|
}
|
|
1813
2769
|
|
|
1814
|
-
class
|
|
2770
|
+
class WorkflowValidationError2 extends Error {
|
|
1815
2771
|
name = "WorkflowValidationError";
|
|
1816
2772
|
cause;
|
|
1817
2773
|
constructor(message, options) {
|
|
@@ -1821,58 +2777,58 @@ class WorkflowValidationError extends Error {
|
|
|
1821
2777
|
}
|
|
1822
2778
|
|
|
1823
2779
|
// src/workflows/run-dispatch.ts
|
|
1824
|
-
import { randomUUID as
|
|
2780
|
+
import { randomUUID as randomUUID6 } from "crypto";
|
|
1825
2781
|
import { isDeepStrictEqual } from "util";
|
|
1826
2782
|
|
|
1827
2783
|
// src/workflows/validation.ts
|
|
1828
2784
|
function assertNonEmpty(value, subject, field) {
|
|
1829
2785
|
if (!value.trim()) {
|
|
1830
|
-
throw new
|
|
2786
|
+
throw new WorkflowDefinitionError2(`${subject} ${field} must not be empty.`);
|
|
1831
2787
|
}
|
|
1832
2788
|
}
|
|
1833
|
-
function
|
|
2789
|
+
function isStepDefinition2(value) {
|
|
1834
2790
|
return isRecord(value) && value.kind === "step" && typeof value.id === "string" && isRecord(value.input) && isRecord(value.output) && typeof value.handler === "function";
|
|
1835
2791
|
}
|
|
1836
|
-
function
|
|
1837
|
-
return isRecord(value) && value.kind === "agentStep" && typeof value.id === "string" && (value.model === undefined || isLanguageModel(value.model)) && (value.reasoning === undefined ||
|
|
2792
|
+
function isAgentStepDefinition2(value) {
|
|
2793
|
+
return isRecord(value) && value.kind === "agentStep" && typeof value.id === "string" && (value.model === undefined || isLanguageModel(value.model)) && (value.reasoning === undefined || isModelReasoning2(value.reasoning)) && typeof value.instructions === "string" && isStringArray(value.groupIds) && isStringArray(value.toolNames) && isRecord(value.input) && isRecord(value.output) && typeof value.prompt === "function";
|
|
1838
2794
|
}
|
|
1839
|
-
function
|
|
2795
|
+
function isInterventionDefinition2(value) {
|
|
1840
2796
|
return isRecord(value) && value.kind === "intervention" && typeof value.id === "string" && isRecord(value.input) && isRecord(value.response) && (value.defaults === undefined || typeof value.defaults === "function");
|
|
1841
2797
|
}
|
|
1842
|
-
function
|
|
2798
|
+
function isWorkflowDefinition2(value) {
|
|
1843
2799
|
return isRecord(value) && value.kind === "workflow" && typeof value.id === "string" && isRecord(value.input) && Array.isArray(value.triggers) && Array.isArray(value.nodes);
|
|
1844
2800
|
}
|
|
1845
|
-
function
|
|
1846
|
-
if (!
|
|
1847
|
-
throw new
|
|
2801
|
+
function validateWorkflowDefinition2(value) {
|
|
2802
|
+
if (!isWorkflowDefinition2(value)) {
|
|
2803
|
+
throw new WorkflowDefinitionError2("Invalid workflow definition.");
|
|
1848
2804
|
}
|
|
1849
2805
|
assertNonEmpty(value.id, "Workflow", "id");
|
|
1850
2806
|
if (value.nodes.length === 0) {
|
|
1851
|
-
throw new
|
|
2807
|
+
throw new WorkflowDefinitionError2(`Workflow "${value.id}" must contain at least one node.`);
|
|
1852
2808
|
}
|
|
1853
2809
|
const nodeIds = new Set;
|
|
1854
2810
|
const nodeKeys = new Set;
|
|
1855
2811
|
for (const node of value.nodes) {
|
|
1856
2812
|
validateWorkflowNodeDefinition(value.id, node);
|
|
1857
2813
|
if (nodeIds.has(node.id)) {
|
|
1858
|
-
throw new
|
|
2814
|
+
throw new WorkflowDefinitionError2(`Duplicate workflow node id "${node.id}" in workflow "${value.id}".`);
|
|
1859
2815
|
}
|
|
1860
2816
|
nodeIds.add(node.id);
|
|
1861
2817
|
if (nodeKeys.has(node.key)) {
|
|
1862
|
-
throw new
|
|
2818
|
+
throw new WorkflowDefinitionError2(`Duplicate workflow node key "${node.key}" in workflow "${value.id}".`);
|
|
1863
2819
|
}
|
|
1864
2820
|
nodeKeys.add(node.key);
|
|
1865
2821
|
}
|
|
1866
2822
|
}
|
|
1867
|
-
function
|
|
2823
|
+
function validateWorkflowsAtStartup2(options) {
|
|
1868
2824
|
for (const workflow of options.workflows) {
|
|
1869
|
-
|
|
2825
|
+
validateWorkflowDefinition2(workflow);
|
|
1870
2826
|
for (const trigger of workflow.triggers) {
|
|
1871
2827
|
validateWorkflowTriggerAtStartup(workflow.id, trigger, options.registeredSchedules, Object.keys(workflow.input));
|
|
1872
2828
|
}
|
|
1873
2829
|
for (const node of workflow.nodes) {
|
|
1874
2830
|
if (node.type === "action" && !options.registeredActionIds.has(node.action.id)) {
|
|
1875
|
-
throw new
|
|
2831
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflow.id}" references unknown action "${node.action.id}". Add it to 'actions' in createSixb() or export it from 'actions/'.`);
|
|
1876
2832
|
}
|
|
1877
2833
|
if (node.type === "agent") {
|
|
1878
2834
|
validateWorkflowAgentStepRuntimeReferences(workflow.id, node.agentStep, options);
|
|
@@ -1881,14 +2837,14 @@ function validateWorkflowsAtStartup(options) {
|
|
|
1881
2837
|
}
|
|
1882
2838
|
return options.workflows;
|
|
1883
2839
|
}
|
|
1884
|
-
function
|
|
2840
|
+
function validateWorkflowAgentStepGroupReferences2(workflows, security) {
|
|
1885
2841
|
for (const workflow of workflows) {
|
|
1886
2842
|
for (const node of workflow.nodes) {
|
|
1887
2843
|
if (node.type !== "agent")
|
|
1888
2844
|
continue;
|
|
1889
2845
|
for (const groupId of node.agentStep.groupIds) {
|
|
1890
2846
|
if (!security.getGroupById(groupId)) {
|
|
1891
|
-
throw new
|
|
2847
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflow.id}" agent step "${node.id}" references unknown group "${groupId}". Add it to 'security/groups/' or pass it to createSixb({ groups }).`);
|
|
1892
2848
|
}
|
|
1893
2849
|
}
|
|
1894
2850
|
}
|
|
@@ -1896,21 +2852,21 @@ function validateWorkflowAgentStepGroupReferences(workflows, security) {
|
|
|
1896
2852
|
}
|
|
1897
2853
|
function validateWorkflowAgentStepRuntimeReferences(workflowId, step, options) {
|
|
1898
2854
|
if (step.model === undefined && options.models === undefined) {
|
|
1899
|
-
throw new
|
|
2855
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" agent step "${step.id}" needs a model. Configure 'models.language' or pass 'model' to defineAgentStep().`);
|
|
1900
2856
|
}
|
|
1901
2857
|
if (step.model !== undefined && options.models !== undefined) {
|
|
1902
2858
|
const ref = { provider: step.model.providerId, modelId: step.model.modelId };
|
|
1903
2859
|
if (options.models.language.getByRef(ref) === null) {
|
|
1904
|
-
throw new
|
|
2860
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" agent step "${step.id}" uses unknown language model "${ref.provider}/${ref.modelId}". Add it to 'models.language' in createSixb().`);
|
|
1905
2861
|
}
|
|
1906
2862
|
}
|
|
1907
2863
|
for (const toolName of step.toolNames) {
|
|
1908
2864
|
if (options.tools.getByName(toolName) === null) {
|
|
1909
|
-
throw new
|
|
2865
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" agent step "${step.id}" uses unknown project tool "${toolName}". Add it to 'tools' in createSixb().`);
|
|
1910
2866
|
}
|
|
1911
2867
|
}
|
|
1912
2868
|
}
|
|
1913
|
-
function
|
|
2869
|
+
function validateWorkflowInput2(params) {
|
|
1914
2870
|
return validateWorkflowContractRecord({
|
|
1915
2871
|
shape: params.workflow.input,
|
|
1916
2872
|
value: params.value,
|
|
@@ -1918,7 +2874,7 @@ function validateWorkflowInput(params) {
|
|
|
1918
2874
|
valueTypesById: params.valueTypesById
|
|
1919
2875
|
});
|
|
1920
2876
|
}
|
|
1921
|
-
function
|
|
2877
|
+
function validateWorkflowStepInput2(params) {
|
|
1922
2878
|
return validateWorkflowContractRecord({
|
|
1923
2879
|
shape: params.step.input,
|
|
1924
2880
|
value: params.value,
|
|
@@ -1926,7 +2882,7 @@ function validateWorkflowStepInput(params) {
|
|
|
1926
2882
|
valueTypesById: params.valueTypesById
|
|
1927
2883
|
});
|
|
1928
2884
|
}
|
|
1929
|
-
function
|
|
2885
|
+
function validateWorkflowStepOutput2(params) {
|
|
1930
2886
|
return validateWorkflowContractRecord({
|
|
1931
2887
|
shape: params.step.output,
|
|
1932
2888
|
value: params.value,
|
|
@@ -1934,7 +2890,7 @@ function validateWorkflowStepOutput(params) {
|
|
|
1934
2890
|
valueTypesById: params.valueTypesById
|
|
1935
2891
|
});
|
|
1936
2892
|
}
|
|
1937
|
-
function
|
|
2893
|
+
function validateWorkflowInterventionInput2(params) {
|
|
1938
2894
|
return validateWorkflowContractRecord({
|
|
1939
2895
|
shape: params.intervention.input,
|
|
1940
2896
|
value: params.value,
|
|
@@ -1942,7 +2898,7 @@ function validateWorkflowInterventionInput(params) {
|
|
|
1942
2898
|
valueTypesById: params.valueTypesById
|
|
1943
2899
|
});
|
|
1944
2900
|
}
|
|
1945
|
-
function
|
|
2901
|
+
function validateWorkflowInterventionResponse2(params) {
|
|
1946
2902
|
return validateWorkflowInterventionResponseRecord({
|
|
1947
2903
|
response: params.intervention.response,
|
|
1948
2904
|
value: params.value,
|
|
@@ -1951,7 +2907,7 @@ function validateWorkflowInterventionResponse(params) {
|
|
|
1951
2907
|
valueTypesById: params.valueTypesById
|
|
1952
2908
|
});
|
|
1953
2909
|
}
|
|
1954
|
-
function
|
|
2910
|
+
function validateWorkflowInterventionDefaultResponse2(params) {
|
|
1955
2911
|
return validateWorkflowInterventionResponseRecord({
|
|
1956
2912
|
response: params.intervention.response,
|
|
1957
2913
|
value: params.value,
|
|
@@ -1962,31 +2918,31 @@ function validateWorkflowInterventionDefaultResponse(params) {
|
|
|
1962
2918
|
}
|
|
1963
2919
|
function validateWorkflowTriggerAtStartup(workflowId, trigger, registeredSchedules, inputFields) {
|
|
1964
2920
|
if (!isRecord(trigger) || trigger.type !== "schedule") {
|
|
1965
|
-
throw new
|
|
2921
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" contains an unsupported trigger.`);
|
|
1966
2922
|
}
|
|
1967
2923
|
validateScheduleWorkflowTrigger(workflowId, trigger, registeredSchedules, inputFields);
|
|
1968
2924
|
}
|
|
1969
2925
|
function validateScheduleWorkflowTrigger(workflowId, trigger, registeredSchedules, inputFields) {
|
|
1970
2926
|
if (typeof trigger.scheduleId !== "string" || !trigger.scheduleId.trim()) {
|
|
1971
|
-
throw new
|
|
2927
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" contains a schedule trigger with an empty schedule id.`);
|
|
1972
2928
|
}
|
|
1973
2929
|
const schedule = registeredSchedules.get(trigger.scheduleId);
|
|
1974
2930
|
if (!schedule) {
|
|
1975
|
-
throw new
|
|
2931
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" references unknown schedule "${trigger.scheduleId}". Add it to 'schedules' in createSixb() or export it from 'schedules/'.`);
|
|
1976
2932
|
}
|
|
1977
2933
|
if (trigger.mapper !== undefined && typeof trigger.mapper !== "function") {
|
|
1978
|
-
throw new
|
|
2934
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" schedule "${trigger.scheduleId}" mapper must be a function.`);
|
|
1979
2935
|
}
|
|
1980
2936
|
if (trigger.mapper !== undefined && schedule.trigger.type !== "event") {
|
|
1981
|
-
throw new
|
|
2937
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" cron schedule "${trigger.scheduleId}" does not accept a mapper.`);
|
|
1982
2938
|
}
|
|
1983
2939
|
if (trigger.mapper === undefined && inputFields.length > 0) {
|
|
1984
|
-
throw new
|
|
2940
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" schedule "${trigger.scheduleId}" requires a mapper because workflow input is not empty: ${inputFields.join(", ")}.`);
|
|
1985
2941
|
}
|
|
1986
2942
|
}
|
|
1987
2943
|
function validateWorkflowNodeDefinition(workflowId, node) {
|
|
1988
2944
|
if (!isRecord(node)) {
|
|
1989
|
-
throw new
|
|
2945
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" contains an invalid node.`);
|
|
1990
2946
|
}
|
|
1991
2947
|
if (node.type === "step") {
|
|
1992
2948
|
validateStepNodeDefinition(workflowId, node);
|
|
@@ -2004,38 +2960,38 @@ function validateWorkflowNodeDefinition(workflowId, node) {
|
|
|
2004
2960
|
validateActionNodeDefinition(workflowId, node);
|
|
2005
2961
|
return;
|
|
2006
2962
|
}
|
|
2007
|
-
throw new
|
|
2963
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" contains an unsupported node type.`);
|
|
2008
2964
|
}
|
|
2009
2965
|
function validateAgentNodeDefinition(workflowId, node) {
|
|
2010
2966
|
if (typeof node.id !== "string" || !node.id.trim()) {
|
|
2011
|
-
throw new
|
|
2967
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" contains an agent step with an empty id.`);
|
|
2012
2968
|
}
|
|
2013
2969
|
if (typeof node.key !== "string" || !node.key.trim()) {
|
|
2014
|
-
throw new
|
|
2970
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" contains agent step "${node.id}" with an empty derived key.`);
|
|
2015
2971
|
}
|
|
2016
|
-
if (!
|
|
2017
|
-
throw new
|
|
2972
|
+
if (!isAgentStepDefinition2(node.agentStep)) {
|
|
2973
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" contains an invalid agent node "${node.id}".`);
|
|
2018
2974
|
}
|
|
2019
2975
|
if (node.id !== node.agentStep.id) {
|
|
2020
|
-
throw new
|
|
2976
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" agent node id "${node.id}" does not match agent step definition id "${node.agentStep.id}".`);
|
|
2021
2977
|
}
|
|
2022
2978
|
if (!node.agentStep.instructions.trim()) {
|
|
2023
|
-
throw new
|
|
2979
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" agent step "${node.id}" instructions must not be empty.`);
|
|
2024
2980
|
}
|
|
2025
2981
|
assertUniqueNonEmptyAgentStepValues(workflowId, node.id, "group", node.agentStep.groupIds);
|
|
2026
2982
|
assertUniqueNonEmptyAgentStepValues(workflowId, node.id, "tool", node.agentStep.toolNames);
|
|
2027
2983
|
if (node.mapper !== undefined && typeof node.mapper !== "function") {
|
|
2028
|
-
throw new
|
|
2984
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" agent node "${node.id}" mapper must be a function.`);
|
|
2029
2985
|
}
|
|
2030
2986
|
}
|
|
2031
2987
|
function assertUniqueNonEmptyAgentStepValues(workflowId, stepId, kind, values) {
|
|
2032
2988
|
const seen = new Set;
|
|
2033
2989
|
for (const value of values) {
|
|
2034
2990
|
if (!value.trim()) {
|
|
2035
|
-
throw new
|
|
2991
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" agent step "${stepId}" has an empty ${kind} id.`);
|
|
2036
2992
|
}
|
|
2037
2993
|
if (seen.has(value)) {
|
|
2038
|
-
throw new
|
|
2994
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" agent step "${stepId}" has duplicate ${kind} '${value}'.`);
|
|
2039
2995
|
}
|
|
2040
2996
|
seen.add(value);
|
|
2041
2997
|
}
|
|
@@ -2052,7 +3008,7 @@ function isStringArray(value) {
|
|
|
2052
3008
|
}
|
|
2053
3009
|
return true;
|
|
2054
3010
|
}
|
|
2055
|
-
function
|
|
3011
|
+
function validateWorkflowAgentStepInput2(params) {
|
|
2056
3012
|
return validateWorkflowContractRecord({
|
|
2057
3013
|
shape: params.agentStep.input,
|
|
2058
3014
|
value: params.value,
|
|
@@ -2060,7 +3016,7 @@ function validateWorkflowAgentStepInput(params) {
|
|
|
2060
3016
|
valueTypesById: params.valueTypesById
|
|
2061
3017
|
});
|
|
2062
3018
|
}
|
|
2063
|
-
function
|
|
3019
|
+
function validateWorkflowAgentStepOutput2(params) {
|
|
2064
3020
|
return validateWorkflowContractRecord({
|
|
2065
3021
|
shape: params.agentStep.output,
|
|
2066
3022
|
value: params.value,
|
|
@@ -2070,72 +3026,72 @@ function validateWorkflowAgentStepOutput(params) {
|
|
|
2070
3026
|
}
|
|
2071
3027
|
function validateStepNodeDefinition(workflowId, node) {
|
|
2072
3028
|
if (typeof node.id !== "string" || !node.id.trim()) {
|
|
2073
|
-
throw new
|
|
3029
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" contains a step with an empty id.`);
|
|
2074
3030
|
}
|
|
2075
3031
|
if (typeof node.key !== "string" || !node.key.trim()) {
|
|
2076
|
-
throw new
|
|
3032
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" contains step "${node.id}" with an empty derived key.`);
|
|
2077
3033
|
}
|
|
2078
|
-
if (!
|
|
2079
|
-
throw new
|
|
3034
|
+
if (!isStepDefinition2(node.step)) {
|
|
3035
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" contains an invalid step node "${node.id}".`);
|
|
2080
3036
|
}
|
|
2081
3037
|
if (node.id !== node.step.id) {
|
|
2082
|
-
throw new
|
|
3038
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" step node id "${node.id}" does not match step definition id "${node.step.id}".`);
|
|
2083
3039
|
}
|
|
2084
3040
|
if (node.mapper !== undefined && typeof node.mapper !== "function") {
|
|
2085
|
-
throw new
|
|
3041
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" step node "${node.id}" mapper must be a function.`);
|
|
2086
3042
|
}
|
|
2087
3043
|
}
|
|
2088
3044
|
function validateInterventionNodeDefinition(workflowId, node) {
|
|
2089
3045
|
if (typeof node.id !== "string" || !node.id.trim()) {
|
|
2090
|
-
throw new
|
|
3046
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" contains an intervention with an empty id.`);
|
|
2091
3047
|
}
|
|
2092
3048
|
if (typeof node.key !== "string" || !node.key.trim()) {
|
|
2093
|
-
throw new
|
|
3049
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" contains intervention "${node.id}" with an empty derived key.`);
|
|
2094
3050
|
}
|
|
2095
|
-
if (!
|
|
2096
|
-
throw new
|
|
3051
|
+
if (!isInterventionDefinition2(node.intervention)) {
|
|
3052
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" contains an invalid intervention node "${node.id}".`);
|
|
2097
3053
|
}
|
|
2098
3054
|
if (node.id !== node.intervention.id) {
|
|
2099
|
-
throw new
|
|
3055
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" intervention node id "${node.id}" does not match intervention definition id "${node.intervention.id}".`);
|
|
2100
3056
|
}
|
|
2101
3057
|
if (node.mapper !== undefined && typeof node.mapper !== "function") {
|
|
2102
|
-
throw new
|
|
3058
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" intervention node "${node.id}" mapper must be a function.`);
|
|
2103
3059
|
}
|
|
2104
3060
|
}
|
|
2105
3061
|
function validateActionNodeDefinition(workflowId, node) {
|
|
2106
3062
|
if (typeof node.id !== "string" || !node.id.trim()) {
|
|
2107
|
-
throw new
|
|
3063
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" contains an action with an empty id.`);
|
|
2108
3064
|
}
|
|
2109
3065
|
if (typeof node.key !== "string" || !node.key.trim()) {
|
|
2110
|
-
throw new
|
|
3066
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" contains action "${node.id}" with an empty derived key.`);
|
|
2111
3067
|
}
|
|
2112
|
-
if (!
|
|
2113
|
-
throw new
|
|
3068
|
+
if (!isActionDefinition2(node.action)) {
|
|
3069
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" contains an invalid action node "${node.id}".`);
|
|
2114
3070
|
}
|
|
2115
3071
|
if (node.id !== node.action.id) {
|
|
2116
|
-
throw new
|
|
3072
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" action node id "${node.id}" does not match action definition id "${node.action.id}".`);
|
|
2117
3073
|
}
|
|
2118
3074
|
if (node.mapper !== undefined && typeof node.mapper !== "function") {
|
|
2119
|
-
throw new
|
|
3075
|
+
throw new WorkflowDefinitionError2(`Workflow "${workflowId}" action node "${node.id}" mapper must be a function.`);
|
|
2120
3076
|
}
|
|
2121
3077
|
}
|
|
2122
3078
|
function validateWorkflowContractRecord(params) {
|
|
2123
3079
|
if (!isRecord(params.value)) {
|
|
2124
|
-
throw new
|
|
3080
|
+
throw new WorkflowValidationError2(`[Sixb] ${params.path} must be an object`);
|
|
2125
3081
|
}
|
|
2126
3082
|
const fieldIds = new Set(Object.keys(params.shape));
|
|
2127
3083
|
for (const fieldId of Object.keys(params.value)) {
|
|
2128
3084
|
if (!fieldIds.has(fieldId)) {
|
|
2129
|
-
throw new
|
|
3085
|
+
throw new WorkflowValidationError2(`[Sixb] Unknown field '${params.path}.${fieldId}'`);
|
|
2130
3086
|
}
|
|
2131
3087
|
}
|
|
2132
3088
|
for (const [fieldId, schema] of Object.entries(params.shape)) {
|
|
2133
3089
|
const fieldValue = params.value[fieldId];
|
|
2134
3090
|
if (fieldValue === undefined) {
|
|
2135
|
-
throw new
|
|
3091
|
+
throw new WorkflowValidationError2(`[Sixb] Missing required field '${params.path}.${fieldId}'`);
|
|
2136
3092
|
}
|
|
2137
3093
|
try {
|
|
2138
|
-
|
|
3094
|
+
validateSchemaOrRefValue2(schema, fieldValue, `${params.path}.${fieldId}`, params.valueTypesById);
|
|
2139
3095
|
} catch (error) {
|
|
2140
3096
|
throw toWorkflowValidationError(error);
|
|
2141
3097
|
}
|
|
@@ -2144,24 +3100,24 @@ function validateWorkflowContractRecord(params) {
|
|
|
2144
3100
|
}
|
|
2145
3101
|
function validateWorkflowInterventionResponseRecord(params) {
|
|
2146
3102
|
if (!isRecord(params.value)) {
|
|
2147
|
-
throw new
|
|
3103
|
+
throw new WorkflowValidationError2(`[Sixb] ${params.path} must be an object`);
|
|
2148
3104
|
}
|
|
2149
3105
|
const fieldIds = new Set(Object.keys(params.response));
|
|
2150
3106
|
for (const fieldId of Object.keys(params.value)) {
|
|
2151
3107
|
if (!fieldIds.has(fieldId)) {
|
|
2152
|
-
throw new
|
|
3108
|
+
throw new WorkflowValidationError2(`[Sixb] Unknown field '${params.path}.${fieldId}'`);
|
|
2153
3109
|
}
|
|
2154
3110
|
}
|
|
2155
3111
|
for (const [fieldId, field] of Object.entries(params.response)) {
|
|
2156
3112
|
const fieldValue = params.value[fieldId];
|
|
2157
3113
|
if (fieldValue === undefined) {
|
|
2158
3114
|
if (!params.partial && isInterventionResponseFieldRequired(field)) {
|
|
2159
|
-
throw new
|
|
3115
|
+
throw new WorkflowValidationError2(`[Sixb] Missing required field '${params.path}.${fieldId}'`);
|
|
2160
3116
|
}
|
|
2161
3117
|
continue;
|
|
2162
3118
|
}
|
|
2163
3119
|
try {
|
|
2164
|
-
|
|
3120
|
+
validateSchemaOrRefValue2(interventionResponseFieldSchema(field), fieldValue, `${params.path}.${fieldId}`, params.valueTypesById);
|
|
2165
3121
|
} catch (error) {
|
|
2166
3122
|
throw toWorkflowValidationError(error);
|
|
2167
3123
|
}
|
|
@@ -2178,21 +3134,21 @@ function isInterventionResponseFieldRequired(field) {
|
|
|
2178
3134
|
return !isInterventionFieldConfig(field) || field.required !== false;
|
|
2179
3135
|
}
|
|
2180
3136
|
function toWorkflowValidationError(error) {
|
|
2181
|
-
if (error instanceof
|
|
3137
|
+
if (error instanceof WorkflowValidationError2) {
|
|
2182
3138
|
return error;
|
|
2183
3139
|
}
|
|
2184
3140
|
if (error instanceof Error) {
|
|
2185
|
-
return new
|
|
3141
|
+
return new WorkflowValidationError2(error.message, { cause: error });
|
|
2186
3142
|
}
|
|
2187
|
-
return new
|
|
3143
|
+
return new WorkflowValidationError2(String(error), { cause: error });
|
|
2188
3144
|
}
|
|
2189
3145
|
function isRecord(value) {
|
|
2190
3146
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2191
3147
|
}
|
|
2192
3148
|
|
|
2193
3149
|
// src/workflows/snapshot.ts
|
|
2194
|
-
function
|
|
2195
|
-
const value =
|
|
3150
|
+
function snapshotWorkflowAgentStepInput2(params) {
|
|
3151
|
+
const value = validateWorkflowAgentStepInput2(params);
|
|
2196
3152
|
return snapshotWorkflowContractRecord({
|
|
2197
3153
|
shape: params.agentStep.input,
|
|
2198
3154
|
value,
|
|
@@ -2200,8 +3156,8 @@ function snapshotWorkflowAgentStepInput(params) {
|
|
|
2200
3156
|
valueTypesById: params.valueTypesById
|
|
2201
3157
|
});
|
|
2202
3158
|
}
|
|
2203
|
-
function
|
|
2204
|
-
const value =
|
|
3159
|
+
function snapshotWorkflowAgentStepOutput2(params) {
|
|
3160
|
+
const value = validateWorkflowAgentStepOutput2(params);
|
|
2205
3161
|
return snapshotWorkflowContractRecord({
|
|
2206
3162
|
shape: params.agentStep.output,
|
|
2207
3163
|
value,
|
|
@@ -2209,8 +3165,8 @@ function snapshotWorkflowAgentStepOutput(params) {
|
|
|
2209
3165
|
valueTypesById: params.valueTypesById
|
|
2210
3166
|
});
|
|
2211
3167
|
}
|
|
2212
|
-
function
|
|
2213
|
-
const value =
|
|
3168
|
+
function snapshotWorkflowInput2(params) {
|
|
3169
|
+
const value = validateWorkflowInput2(params);
|
|
2214
3170
|
return snapshotWorkflowContractRecord({
|
|
2215
3171
|
shape: params.workflow.input,
|
|
2216
3172
|
value,
|
|
@@ -2218,8 +3174,8 @@ function snapshotWorkflowInput(params) {
|
|
|
2218
3174
|
valueTypesById: params.valueTypesById
|
|
2219
3175
|
});
|
|
2220
3176
|
}
|
|
2221
|
-
function
|
|
2222
|
-
const value =
|
|
3177
|
+
function snapshotWorkflowStepInput2(params) {
|
|
3178
|
+
const value = validateWorkflowStepInput2(params);
|
|
2223
3179
|
return snapshotWorkflowContractRecord({
|
|
2224
3180
|
shape: params.step.input,
|
|
2225
3181
|
value,
|
|
@@ -2227,8 +3183,8 @@ function snapshotWorkflowStepInput(params) {
|
|
|
2227
3183
|
valueTypesById: params.valueTypesById
|
|
2228
3184
|
});
|
|
2229
3185
|
}
|
|
2230
|
-
function
|
|
2231
|
-
const value =
|
|
3186
|
+
function snapshotWorkflowStepOutput2(params) {
|
|
3187
|
+
const value = validateWorkflowStepOutput2(params);
|
|
2232
3188
|
return snapshotWorkflowContractRecord({
|
|
2233
3189
|
shape: params.step.output,
|
|
2234
3190
|
value,
|
|
@@ -2236,8 +3192,8 @@ function snapshotWorkflowStepOutput(params) {
|
|
|
2236
3192
|
valueTypesById: params.valueTypesById
|
|
2237
3193
|
});
|
|
2238
3194
|
}
|
|
2239
|
-
function
|
|
2240
|
-
const value =
|
|
3195
|
+
function snapshotWorkflowInterventionInput2(params) {
|
|
3196
|
+
const value = validateWorkflowInterventionInput2(params);
|
|
2241
3197
|
return snapshotWorkflowContractRecord({
|
|
2242
3198
|
shape: params.intervention.input,
|
|
2243
3199
|
value,
|
|
@@ -2245,8 +3201,8 @@ function snapshotWorkflowInterventionInput(params) {
|
|
|
2245
3201
|
valueTypesById: params.valueTypesById
|
|
2246
3202
|
});
|
|
2247
3203
|
}
|
|
2248
|
-
function
|
|
2249
|
-
const value =
|
|
3204
|
+
function snapshotWorkflowInterventionResponse2(params) {
|
|
3205
|
+
const value = validateWorkflowInterventionResponse2(params);
|
|
2250
3206
|
return snapshotWorkflowInterventionResponseRecord({
|
|
2251
3207
|
response: params.intervention.response,
|
|
2252
3208
|
value,
|
|
@@ -2254,8 +3210,8 @@ function snapshotWorkflowInterventionResponse(params) {
|
|
|
2254
3210
|
valueTypesById: params.valueTypesById
|
|
2255
3211
|
});
|
|
2256
3212
|
}
|
|
2257
|
-
function
|
|
2258
|
-
const value =
|
|
3213
|
+
function snapshotWorkflowInterventionDefaultResponse2(params) {
|
|
3214
|
+
const value = validateWorkflowInterventionDefaultResponse2(params);
|
|
2259
3215
|
return snapshotWorkflowInterventionResponseRecord({
|
|
2260
3216
|
response: params.intervention.response,
|
|
2261
3217
|
value,
|
|
@@ -2263,7 +3219,7 @@ function snapshotWorkflowInterventionDefaultResponse(params) {
|
|
|
2263
3219
|
valueTypesById: params.valueTypesById
|
|
2264
3220
|
});
|
|
2265
3221
|
}
|
|
2266
|
-
function
|
|
3222
|
+
function snapshotWorkflowActionInput2(params) {
|
|
2267
3223
|
const snapshot = {
|
|
2268
3224
|
params: snapshotJsonValue(params.params, "Workflow action params")
|
|
2269
3225
|
};
|
|
@@ -2300,8 +3256,8 @@ function snapshotWorkflowInterventionResponseRecord(params) {
|
|
|
2300
3256
|
return snapshot;
|
|
2301
3257
|
}
|
|
2302
3258
|
function snapshotSchemaOrRefValue(params) {
|
|
2303
|
-
if (
|
|
2304
|
-
if (!
|
|
3259
|
+
if (isObjectRefSchema2(params.schema)) {
|
|
3260
|
+
if (!isRecord3(params.value)) {
|
|
2305
3261
|
throw cannotSerialize(params.path);
|
|
2306
3262
|
}
|
|
2307
3263
|
return {
|
|
@@ -2342,7 +3298,7 @@ function snapshotSchemaValue(params) {
|
|
|
2342
3298
|
}));
|
|
2343
3299
|
}
|
|
2344
3300
|
if (schema.type === "map") {
|
|
2345
|
-
if (!
|
|
3301
|
+
if (!isRecord3(value)) {
|
|
2346
3302
|
throw cannotSerialize(path);
|
|
2347
3303
|
}
|
|
2348
3304
|
const snapshot = {};
|
|
@@ -2357,7 +3313,7 @@ function snapshotSchemaValue(params) {
|
|
|
2357
3313
|
return snapshot;
|
|
2358
3314
|
}
|
|
2359
3315
|
if (schema.type === "object") {
|
|
2360
|
-
if (!
|
|
3316
|
+
if (!isRecord3(value)) {
|
|
2361
3317
|
throw cannotSerialize(path);
|
|
2362
3318
|
}
|
|
2363
3319
|
const snapshot = {};
|
|
@@ -2382,7 +3338,7 @@ function snapshotSchemaValue(params) {
|
|
|
2382
3338
|
if (schema.type === "valueTypeRef") {
|
|
2383
3339
|
const valueType = valueTypesById.get(schema.valueTypeId);
|
|
2384
3340
|
if (!valueType) {
|
|
2385
|
-
throw new
|
|
3341
|
+
throw new WorkflowValidationError2(`[Sixb] Unknown valueTypeRef '${schema.valueTypeId}' at ${path}`);
|
|
2386
3342
|
}
|
|
2387
3343
|
return snapshotSchemaValue({
|
|
2388
3344
|
schema: valueType.schema,
|
|
@@ -2425,14 +3381,14 @@ function snapshotDate(value, path) {
|
|
|
2425
3381
|
return value.toISOString();
|
|
2426
3382
|
}
|
|
2427
3383
|
function cannotSerialize(path) {
|
|
2428
|
-
return new
|
|
3384
|
+
return new WorkflowValidationError2(`[Sixb] ${path} cannot be serialized as workflow IO`);
|
|
2429
3385
|
}
|
|
2430
|
-
function
|
|
3386
|
+
function isRecord3(value) {
|
|
2431
3387
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2432
3388
|
}
|
|
2433
3389
|
|
|
2434
3390
|
// src/workflows/run-dispatch.ts
|
|
2435
|
-
class
|
|
3391
|
+
class WorkflowRunDispatcher2 {
|
|
2436
3392
|
dependencies;
|
|
2437
3393
|
constructor(dependencies) {
|
|
2438
3394
|
this.dependencies = dependencies;
|
|
@@ -2441,9 +3397,9 @@ class WorkflowRunDispatcher {
|
|
|
2441
3397
|
assertAutomaticDispatchInput(input);
|
|
2442
3398
|
const workflow = this.dependencies.definitions.workflows.getById(input.workflowId);
|
|
2443
3399
|
if (!workflow) {
|
|
2444
|
-
throw new
|
|
3400
|
+
throw new WorkflowValidationError2(`[Sixb] Unknown workflow '${input.workflowId}'`);
|
|
2445
3401
|
}
|
|
2446
|
-
|
|
3402
|
+
return dispatchWorkflowRun({
|
|
2447
3403
|
errorReporterHost: this.dependencies,
|
|
2448
3404
|
projectId: this.dependencies.id,
|
|
2449
3405
|
workflow,
|
|
@@ -2457,11 +3413,11 @@ class WorkflowRunDispatcher {
|
|
|
2457
3413
|
type: "schedule",
|
|
2458
3414
|
scheduleId: input.scheduleId,
|
|
2459
3415
|
eventId: input.source.eventId,
|
|
2460
|
-
principal:
|
|
3416
|
+
principal: SYSTEM_PRINCIPAL2
|
|
2461
3417
|
},
|
|
2462
|
-
requesterGroupIds: [],
|
|
2463
3418
|
metadata: input.metadata,
|
|
2464
3419
|
queueJobId: input.runId,
|
|
3420
|
+
validateExistingRun: (run) => assertAutomaticExecutionIdentity(this.dependencies, input, run),
|
|
2465
3421
|
createExecution: async (executionId, runId) => createPrimitiveExecutionRecord({
|
|
2466
3422
|
id: executionId,
|
|
2467
3423
|
primitive: { kind: "workflow", id: workflow.id, runId },
|
|
@@ -2473,24 +3429,25 @@ class WorkflowRunDispatcher {
|
|
|
2473
3429
|
}
|
|
2474
3430
|
})
|
|
2475
3431
|
});
|
|
2476
|
-
if (!result.created) {
|
|
2477
|
-
await assertAutomaticExecutionIdentity(this.dependencies, input, result.runId);
|
|
2478
|
-
}
|
|
2479
|
-
return result;
|
|
2480
3432
|
}
|
|
2481
3433
|
}
|
|
2482
3434
|
async function dispatchWorkflowRun(input) {
|
|
2483
3435
|
const request = prepareWorkflowRun(input);
|
|
2484
3436
|
const persisted = await persistWorkflowRun(input, request);
|
|
2485
|
-
if (!persisted.created)
|
|
3437
|
+
if (!persisted.created) {
|
|
3438
|
+
await input.validateExistingRun?.(persisted.run);
|
|
3439
|
+
if (input.validateExistingRun && persisted.run.status === "queued") {
|
|
3440
|
+
await enqueueWorkflowRun(input, persisted.run);
|
|
3441
|
+
}
|
|
2486
3442
|
return existingWorkflowRunResult(persisted.run);
|
|
3443
|
+
}
|
|
2487
3444
|
return publishWorkflowRun(input, persisted);
|
|
2488
3445
|
}
|
|
2489
3446
|
function prepareWorkflowRun(input) {
|
|
2490
3447
|
const value = input.input ?? {};
|
|
2491
3448
|
return {
|
|
2492
3449
|
runId: resolveWorkflowRunId(input.runId),
|
|
2493
|
-
snapshot:
|
|
3450
|
+
snapshot: snapshotWorkflowInput2({
|
|
2494
3451
|
workflow: input.workflow,
|
|
2495
3452
|
value,
|
|
2496
3453
|
valueTypesById: input.valueTypesById
|
|
@@ -2500,7 +3457,7 @@ function prepareWorkflowRun(input) {
|
|
|
2500
3457
|
async function persistWorkflowRun(input, request) {
|
|
2501
3458
|
const workflowRuns = input.storage.workflowRuns;
|
|
2502
3459
|
if (!workflowRuns) {
|
|
2503
|
-
throw new
|
|
3460
|
+
throw new WorkflowValidationError2("[Sixb] Workflow run storage is not configured.");
|
|
2504
3461
|
}
|
|
2505
3462
|
const existing = await workflowRuns.getById({
|
|
2506
3463
|
projectId: input.projectId,
|
|
@@ -2510,7 +3467,7 @@ async function persistWorkflowRun(input, request) {
|
|
|
2510
3467
|
assertExistingWorkflowRun(existing, input.workflow.id, request.snapshot);
|
|
2511
3468
|
return { run: existing, created: false };
|
|
2512
3469
|
}
|
|
2513
|
-
const execution = await input.createExecution(`exec_${
|
|
3470
|
+
const execution = await input.createExecution(`exec_${randomUUID6()}`, request.runId);
|
|
2514
3471
|
const queuedAt = new Date;
|
|
2515
3472
|
try {
|
|
2516
3473
|
return await input.storage.transaction(async (tx) => {
|
|
@@ -2523,7 +3480,7 @@ async function persistWorkflowRun(input, request) {
|
|
|
2523
3480
|
return { run: raced, created: false };
|
|
2524
3481
|
}
|
|
2525
3482
|
if (!tx.workflowRuns) {
|
|
2526
|
-
throw new
|
|
3483
|
+
throw new WorkflowValidationError2("[Sixb] Workflow run storage is not configured.");
|
|
2527
3484
|
}
|
|
2528
3485
|
await tx.executions.create(execution);
|
|
2529
3486
|
const run = await tx.workflowRuns.queue({
|
|
@@ -2532,13 +3489,12 @@ async function persistWorkflowRun(input, request) {
|
|
|
2532
3489
|
executionId: execution.id,
|
|
2533
3490
|
workflowId: input.workflow.id,
|
|
2534
3491
|
input: request.snapshot,
|
|
2535
|
-
queuedAt
|
|
2536
|
-
requesterGroupIds: input.requesterGroupIds
|
|
3492
|
+
queuedAt
|
|
2537
3493
|
});
|
|
2538
3494
|
return { run, execution, queuedAt, created: true };
|
|
2539
3495
|
}, { isolation: "serializable" });
|
|
2540
3496
|
} catch (error) {
|
|
2541
|
-
if (!(error instanceof
|
|
3497
|
+
if (!(error instanceof WorkflowRunError2))
|
|
2542
3498
|
throw error;
|
|
2543
3499
|
const raced = await workflowRuns.getById({
|
|
2544
3500
|
projectId: input.projectId,
|
|
@@ -2553,20 +3509,10 @@ async function persistWorkflowRun(input, request) {
|
|
|
2553
3509
|
async function publishWorkflowRun(input, persisted) {
|
|
2554
3510
|
let job;
|
|
2555
3511
|
try {
|
|
2556
|
-
|
|
2557
|
-
projectId: input.projectId,
|
|
2558
|
-
jobs: [
|
|
2559
|
-
{
|
|
2560
|
-
...input.queueJobId === undefined ? {} : { id: input.queueJobId },
|
|
2561
|
-
type: "workflow.run.requested",
|
|
2562
|
-
payload: { runId: persisted.run.id },
|
|
2563
|
-
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
2564
|
-
}
|
|
2565
|
-
]
|
|
2566
|
-
});
|
|
2567
|
-
job = jobs[0];
|
|
3512
|
+
job = await enqueueWorkflowRun(input, persisted.run);
|
|
2568
3513
|
} catch (error) {
|
|
2569
|
-
|
|
3514
|
+
if (!input.validateExistingRun)
|
|
3515
|
+
await failWorkflowRunPublication(input, persisted.run, error);
|
|
2570
3516
|
throw error;
|
|
2571
3517
|
}
|
|
2572
3518
|
await input.events.emit({
|
|
@@ -2592,13 +3538,30 @@ async function publishWorkflowRun(input, persisted) {
|
|
|
2592
3538
|
created: true
|
|
2593
3539
|
};
|
|
2594
3540
|
}
|
|
3541
|
+
async function enqueueWorkflowRun(input, run) {
|
|
3542
|
+
const [job] = await input.queue.enqueue({
|
|
3543
|
+
projectId: input.projectId,
|
|
3544
|
+
jobs: [
|
|
3545
|
+
{
|
|
3546
|
+
...input.queueJobId === undefined ? {} : { id: input.queueJobId },
|
|
3547
|
+
type: "workflow.run.requested",
|
|
3548
|
+
payload: { runId: run.id },
|
|
3549
|
+
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
3550
|
+
}
|
|
3551
|
+
]
|
|
3552
|
+
});
|
|
3553
|
+
if (!job || input.queueJobId !== undefined && job.id !== input.queueJobId) {
|
|
3554
|
+
throw new WorkflowRunError2(`[Sixb] Queue did not acknowledge workflow run '${run.id}'.`);
|
|
3555
|
+
}
|
|
3556
|
+
return job;
|
|
3557
|
+
}
|
|
2595
3558
|
async function failWorkflowRunPublication(input, run, error) {
|
|
2596
3559
|
const workflowRuns = input.storage.workflowRuns;
|
|
2597
3560
|
if (!workflowRuns) {
|
|
2598
|
-
throw new
|
|
3561
|
+
throw new WorkflowValidationError2("[Sixb] Workflow run storage is not configured.");
|
|
2599
3562
|
}
|
|
2600
|
-
const failure =
|
|
2601
|
-
allowedCodes:
|
|
3563
|
+
const failure = captureSixbFailure2(error, {
|
|
3564
|
+
allowedCodes: WORKFLOW_RUN_FAILURE_CODES2,
|
|
2602
3565
|
defaultCode: "internal.unexpected",
|
|
2603
3566
|
details: { workflowId: run.workflowId, runId: run.id }
|
|
2604
3567
|
});
|
|
@@ -2608,7 +3571,7 @@ async function failWorkflowRunPublication(input, run, error) {
|
|
|
2608
3571
|
status: "failed",
|
|
2609
3572
|
error: failure
|
|
2610
3573
|
});
|
|
2611
|
-
|
|
3574
|
+
reportRunFailure2(input.errorReporterHost, error, {
|
|
2612
3575
|
projectId: input.projectId,
|
|
2613
3576
|
runKind: "workflow",
|
|
2614
3577
|
run: { runId: run.id, workflowId: run.workflowId },
|
|
@@ -2617,15 +3580,15 @@ async function failWorkflowRunPublication(input, run, error) {
|
|
|
2617
3580
|
}
|
|
2618
3581
|
function resolveWorkflowRunId(runId) {
|
|
2619
3582
|
if (runId === undefined)
|
|
2620
|
-
return `run_${
|
|
3583
|
+
return `run_${randomUUID6()}`;
|
|
2621
3584
|
if (!runId.trim()) {
|
|
2622
|
-
throw new
|
|
3585
|
+
throw new WorkflowValidationError2("[Sixb] Workflow run id must not be empty");
|
|
2623
3586
|
}
|
|
2624
3587
|
return runId;
|
|
2625
3588
|
}
|
|
2626
3589
|
function assertExistingWorkflowRun(existing, workflowId, input) {
|
|
2627
3590
|
if (existing.workflowId !== workflowId || !isDeepStrictEqual(existing.input, input)) {
|
|
2628
|
-
throw new
|
|
3591
|
+
throw new WorkflowValidationError2(`[Sixb] Workflow run '${existing.id}' already exists with a different request payload.`);
|
|
2629
3592
|
}
|
|
2630
3593
|
}
|
|
2631
3594
|
function existingWorkflowRunResult(existing) {
|
|
@@ -2643,36 +3606,27 @@ function assertAutomaticDispatchInput(input) {
|
|
|
2643
3606
|
assertNonBlank(input.source.eventId, "Workflow source event id");
|
|
2644
3607
|
assertNonBlank(input.correlationId, "Workflow correlation id");
|
|
2645
3608
|
}
|
|
2646
|
-
async function assertAutomaticExecutionIdentity(dependencies, input,
|
|
2647
|
-
const
|
|
2648
|
-
projectId: dependencies.id,
|
|
2649
|
-
id: runId
|
|
2650
|
-
});
|
|
2651
|
-
const execution = run ? await dependencies.storage.executions.getById({
|
|
3609
|
+
async function assertAutomaticExecutionIdentity(dependencies, input, run) {
|
|
3610
|
+
const execution = await dependencies.storage.executions.getById({
|
|
2652
3611
|
projectId: dependencies.id,
|
|
2653
3612
|
id: run.executionId
|
|
2654
|
-
})
|
|
3613
|
+
});
|
|
2655
3614
|
if (!execution || execution.source.type !== input.source.type || execution.source.eventId !== input.source.eventId || execution.correlationId !== input.correlationId || execution.requestedBy !== undefined) {
|
|
2656
|
-
throw new
|
|
3615
|
+
throw new WorkflowValidationError2(`[Sixb] Workflow run '${run.id}' already exists with different automatic provenance.`);
|
|
2657
3616
|
}
|
|
2658
3617
|
}
|
|
2659
3618
|
function assertNonBlank(value, label) {
|
|
2660
3619
|
if (!value.trim())
|
|
2661
|
-
throw new
|
|
3620
|
+
throw new WorkflowValidationError2(`[Sixb] ${label} must not be empty.`);
|
|
2662
3621
|
}
|
|
2663
3622
|
|
|
2664
3623
|
// src/workflows/request.ts
|
|
2665
|
-
async function
|
|
3624
|
+
async function requestWorkflowRun2(runtime, execution, workflow, options = {}) {
|
|
2666
3625
|
resolveExecutionScopeAuthorization(runtime.projectId, {
|
|
2667
3626
|
execution,
|
|
2668
3627
|
authorization: runtime.runtimeAuthorization
|
|
2669
3628
|
});
|
|
2670
|
-
|
|
2671
|
-
const requesterGroupIds = execution.requestedBy ? await snapshotRequesterGroupIds({
|
|
2672
|
-
auth: runtime.storage.auth,
|
|
2673
|
-
projectId: runtime.projectId,
|
|
2674
|
-
principal: execution.requestedBy
|
|
2675
|
-
}) : [];
|
|
3629
|
+
assertAuthorized2(runtime, { kind: "workflow.run", workflowId: workflow.id });
|
|
2676
3630
|
return dispatchWorkflowRun({
|
|
2677
3631
|
errorReporterHost: runtime,
|
|
2678
3632
|
projectId: runtime.projectId,
|
|
@@ -2684,9 +3638,8 @@ async function requestWorkflowRun(runtime, execution, workflow, options = {}) {
|
|
|
2684
3638
|
runId: options.runId,
|
|
2685
3639
|
input: options.input,
|
|
2686
3640
|
source: options.source,
|
|
2687
|
-
requesterGroupIds,
|
|
2688
3641
|
createExecution: async (executionId, runId) => {
|
|
2689
|
-
const caller = await
|
|
3642
|
+
const caller = await ensureExecutionRecord2(runtime.storage.executions, executionRecordInputFromRuntime({
|
|
2690
3643
|
execution,
|
|
2691
3644
|
runtimeAuthorization: runtime.runtimeAuthorization
|
|
2692
3645
|
}));
|
|
@@ -2702,7 +3655,7 @@ async function requestWorkflowRun(runtime, execution, workflow, options = {}) {
|
|
|
2702
3655
|
// src/workflows/execution.ts
|
|
2703
3656
|
function createWorkflowsRuntime(runtime, execution, source) {
|
|
2704
3657
|
const authority = resolveRuntimeAuthorizationForProject(runtime);
|
|
2705
|
-
const allowed = (workflowId) =>
|
|
3658
|
+
const allowed = (workflowId) => isRuntimeAllowed2(runtime, { kind: "workflow.run", workflowId });
|
|
2706
3659
|
const canAccessHistory = (workflowId) => {
|
|
2707
3660
|
switch (authority.type) {
|
|
2708
3661
|
case "denied":
|
|
@@ -2725,7 +3678,7 @@ function createWorkflowsRuntime(runtime, execution, source) {
|
|
|
2725
3678
|
}) ?? null;
|
|
2726
3679
|
if (!run || !canAccessHistory(run.workflowId))
|
|
2727
3680
|
return null;
|
|
2728
|
-
return authority.type === "unrestricted" ||
|
|
3681
|
+
return authority.type === "unrestricted" || canViewWorkflowRun2(authority.context, run) ? run : null;
|
|
2729
3682
|
};
|
|
2730
3683
|
const getRun = async (runId) => {
|
|
2731
3684
|
const run = await getVisibleRunRecord(runId);
|
|
@@ -2753,14 +3706,14 @@ function createWorkflowsRuntime(runtime, execution, source) {
|
|
|
2753
3706
|
const workflow = source.getById(workflowId);
|
|
2754
3707
|
return workflow && allowed(workflowId) ? workflow : null;
|
|
2755
3708
|
},
|
|
2756
|
-
request: (workflow, options) =>
|
|
3709
|
+
request: (workflow, options) => requestWorkflowRun2(runtime, execution, workflow, options),
|
|
2757
3710
|
requestById: async (input) => {
|
|
2758
|
-
|
|
3711
|
+
assertAuthorized2(runtime, { kind: "workflow.run", workflowId: input.workflowId });
|
|
2759
3712
|
const workflow = source.getById(input.workflowId);
|
|
2760
3713
|
if (!workflow) {
|
|
2761
|
-
throw new
|
|
3714
|
+
throw new WorkflowValidationError2(`[Sixb] Unknown workflow '${input.workflowId}'`);
|
|
2762
3715
|
}
|
|
2763
|
-
return
|
|
3716
|
+
return requestWorkflowRun2(runtime, execution, workflow, input);
|
|
2764
3717
|
},
|
|
2765
3718
|
runs: {
|
|
2766
3719
|
getById: getRun,
|
|
@@ -2811,7 +3764,7 @@ function createWorkflowsRuntime(runtime, execution, source) {
|
|
|
2811
3764
|
}) ?? null;
|
|
2812
3765
|
if (!intervention || !canAccessHistory(intervention.workflowId))
|
|
2813
3766
|
return null;
|
|
2814
|
-
return authority.type === "unrestricted" ||
|
|
3767
|
+
return authority.type === "unrestricted" || canViewWorkflowIntervention2(authority.context, intervention) ? intervention : null;
|
|
2815
3768
|
},
|
|
2816
3769
|
list: (input = {}) => {
|
|
2817
3770
|
if (authority.type === "denied" || authority.type === "delegated") {
|
|
@@ -2914,7 +3867,7 @@ function createBoundSixb(runtime, dependencies, execution) {
|
|
|
2914
3867
|
execution,
|
|
2915
3868
|
...createExecutionFacades(runtime, execution, dependencies)
|
|
2916
3869
|
};
|
|
2917
|
-
|
|
3870
|
+
shareOntologyMutationRuntime2(runtime, sixb);
|
|
2918
3871
|
if (dependencies.connectorConnections) {
|
|
2919
3872
|
registerConnectorConnectionsRuntime(sixb, createConnectorConnectionsRuntime(runtime, execution, dependencies.connectorConnections));
|
|
2920
3873
|
}
|
|
@@ -2935,6 +3888,7 @@ function createExecutionFacades(runtime, execution, dependencies) {
|
|
|
2935
3888
|
projections: createProjectionsRuntime(runtime, dependencies.definitions.projections),
|
|
2936
3889
|
rules: createRulesRuntime(runtime, dependencies.definitions.rules),
|
|
2937
3890
|
agent: createAgentRuntime(runtime, execution, dependencies.definitions.models),
|
|
3891
|
+
models: createModelsRuntime(runtime, execution, dependencies.definitions.models),
|
|
2938
3892
|
aiUsage: createAiUsageRuntime(runtime, dependencies.definitions.security),
|
|
2939
3893
|
events: createEventsRuntime(runtime),
|
|
2940
3894
|
logs: createLogsRuntime(runtime, dependencies.logging),
|
|
@@ -2945,15 +3899,16 @@ function createExecutionFacades(runtime, execution, dependencies) {
|
|
|
2945
3899
|
};
|
|
2946
3900
|
}
|
|
2947
3901
|
// src/execution/agent.ts
|
|
2948
|
-
function
|
|
3902
|
+
function canInheritAgentRequestAuthorization2(authorization) {
|
|
2949
3903
|
const ref = getAuthorizationRef(authorization);
|
|
2950
3904
|
return ref.type === "disabled" || ref.type === "principal" && ref.principal.type === "user" && ref.credential !== undefined;
|
|
2951
3905
|
}
|
|
2952
|
-
function
|
|
3906
|
+
function createAgentExecutionRecord2(input) {
|
|
2953
3907
|
assertAgentPrincipal(input.actorId, input.principal);
|
|
2954
3908
|
return {
|
|
2955
3909
|
id: input.id,
|
|
2956
3910
|
projectId: input.parent.projectId,
|
|
3911
|
+
requesterGroupIds: [...input.parent.requesterGroupIds],
|
|
2957
3912
|
...input.parent.requestedBy === undefined ? {} : { requestedBy: structuredClone(input.parent.requestedBy) },
|
|
2958
3913
|
executor: { type: "agent", runId: input.runId },
|
|
2959
3914
|
source: { type: "execution", executionId: input.parent.id },
|
|
@@ -2964,14 +3919,15 @@ function createAgentExecutionRecord(input) {
|
|
|
2964
3919
|
}
|
|
2965
3920
|
};
|
|
2966
3921
|
}
|
|
2967
|
-
function
|
|
3922
|
+
function createInheritedAgentExecutionRecord2(input) {
|
|
2968
3923
|
const authority = input.parent.authorizationRef;
|
|
2969
3924
|
if (authority.type !== "disabled" && !(authority.type === "principal" && authority.principal.type === "user" && authority.credential !== undefined)) {
|
|
2970
|
-
throw new
|
|
3925
|
+
throw new ExecutionStorageError2("invalid_input", `[Sixb] Agent run '${input.runId}' requires inheritable user or auth-disabled authority.`);
|
|
2971
3926
|
}
|
|
2972
3927
|
return {
|
|
2973
3928
|
id: input.id,
|
|
2974
3929
|
projectId: input.parent.projectId,
|
|
3930
|
+
requesterGroupIds: [...input.parent.requesterGroupIds],
|
|
2975
3931
|
...input.parent.requestedBy === undefined ? {} : { requestedBy: structuredClone(input.parent.requestedBy) },
|
|
2976
3932
|
executor: { type: "agent", runId: input.runId },
|
|
2977
3933
|
source: { type: "execution", executionId: input.parent.id },
|
|
@@ -2979,16 +3935,16 @@ function createInheritedAgentExecutionRecord(input) {
|
|
|
2979
3935
|
authorizationRef: structuredClone(authority)
|
|
2980
3936
|
};
|
|
2981
3937
|
}
|
|
2982
|
-
function
|
|
2983
|
-
const scope =
|
|
3938
|
+
function bindDurableAgentExecution2(host, input) {
|
|
3939
|
+
const scope = restoreAgentExecutionScope2(input);
|
|
2984
3940
|
const sixb = host.withScope(scope);
|
|
2985
3941
|
if (!isBoundSixb(sixb)) {
|
|
2986
3942
|
throw new Error("[Sixb] Agent execution host returned an invalid bound SDK.");
|
|
2987
3943
|
}
|
|
2988
3944
|
return sixb;
|
|
2989
3945
|
}
|
|
2990
|
-
function
|
|
2991
|
-
|
|
3946
|
+
function restoreAgentExecutionScope2(input) {
|
|
3947
|
+
assertAgentExecutionRecord2(input);
|
|
2992
3948
|
const context = Object.freeze({
|
|
2993
3949
|
id: input.execution.id,
|
|
2994
3950
|
projectId: input.execution.projectId,
|
|
@@ -3013,7 +3969,7 @@ function restoreAgentExecutionScope(input) {
|
|
|
3013
3969
|
})
|
|
3014
3970
|
});
|
|
3015
3971
|
}
|
|
3016
|
-
function
|
|
3972
|
+
function assertAgentExecutionRecord2(input) {
|
|
3017
3973
|
const authority = input.execution.authorizationRef;
|
|
3018
3974
|
if (input.execution.executor.type !== "agent" || input.execution.executor.runId !== input.runId || input.execution.source.type !== "execution") {
|
|
3019
3975
|
invalidAgentExecution(input.execution.id, input.runId);
|
|
@@ -3043,15 +3999,15 @@ function assertInheritedAgentAuthority(execution, runId, authorization) {
|
|
|
3043
3999
|
}
|
|
3044
4000
|
}
|
|
3045
4001
|
function assertAgentPrincipal(actorId, principal) {
|
|
3046
|
-
const expectedId =
|
|
4002
|
+
const expectedId = agentServiceAccountId2(actorId);
|
|
3047
4003
|
if (principal.id !== expectedId) {
|
|
3048
|
-
throw new
|
|
4004
|
+
throw new ExecutionStorageError2("invalid_input", `[Sixb] Agent '${actorId}' execution authority must reference service account '${expectedId}'.`);
|
|
3049
4005
|
}
|
|
3050
4006
|
}
|
|
3051
4007
|
function invalidAgentExecution(executionId, runId) {
|
|
3052
|
-
throw new
|
|
4008
|
+
throw new ExecutionStorageError2("invalid_input", `[Sixb] Execution '${executionId}' does not authorize Agent run '${runId}'.`);
|
|
3053
4009
|
}
|
|
3054
4010
|
|
|
3055
|
-
export {
|
|
4011
|
+
export { resolveAgentContextParts2, agentRunQueueJobId2, subagentRunQueueJobId2, workflowAgentNodeQueueJobId2, dispatchQueuedAgentRuns2, dispatchQueuedSubagentRuns2, createAgentThreadId2, createAgentRunId2, createSubagentRunId2, createSubagentExecutionId2, createAgentMessageId2, agentContextCheckpointId2, createAgentRunExecutionToken2, runModelLoop2, assertNoAgentDefinitions, bindModelExecutionAttempt, ShareError2, WorkflowDefinitionError2, WorkflowValidationError2, assertNonEmpty, isStepDefinition2, isAgentStepDefinition2, isInterventionDefinition2, isWorkflowDefinition2, validateWorkflowDefinition2, validateWorkflowsAtStartup2, validateWorkflowAgentStepGroupReferences2, validateWorkflowInput2, validateWorkflowStepInput2, validateWorkflowStepOutput2, validateWorkflowInterventionInput2, validateWorkflowInterventionResponse2, validateWorkflowInterventionDefaultResponse2, validateWorkflowAgentStepInput2, validateWorkflowAgentStepOutput2, snapshotWorkflowAgentStepInput2, snapshotWorkflowAgentStepOutput2, snapshotWorkflowInput2, snapshotWorkflowStepInput2, snapshotWorkflowStepOutput2, snapshotWorkflowInterventionInput2, snapshotWorkflowInterventionResponse2, snapshotWorkflowInterventionDefaultResponse2, snapshotWorkflowActionInput2, WorkflowRunDispatcher2, requestWorkflowRun2, createBoundSixb, isBoundSixb, canInheritAgentRequestAuthorization2, createAgentExecutionRecord2, createInheritedAgentExecutionRecord2, bindDurableAgentExecution2, restoreAgentExecutionScope2, assertAgentExecutionRecord2, requestAgentRun2, retryAgentRun2 };
|
|
3056
4012
|
|
|
3057
|
-
//# debugId=
|
|
4013
|
+
//# debugId=54032C3CC8C5EB0064756E2164756E21
|