@sixb/core 0.1.6 → 0.1.7
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 +37 -33
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/worker.js +3 -3
- package/dist/agents/adapters.d.ts +33 -76
- package/dist/agents/adapters.d.ts.map +1 -1
- package/dist/agents/authority.d.ts +22 -6
- package/dist/agents/authority.d.ts.map +1 -1
- package/dist/agents/builders.d.ts +3 -11
- package/dist/agents/builders.d.ts.map +1 -1
- package/dist/agents/context.js +2 -2
- package/dist/agents/dispatch.d.ts +9 -1
- package/dist/agents/dispatch.d.ts.map +1 -1
- package/dist/agents/errors.d.ts +2 -2
- package/dist/agents/errors.d.ts.map +1 -1
- package/dist/agents/execution.d.ts +9 -10
- package/dist/agents/execution.d.ts.map +1 -1
- package/dist/agents/ids.d.ts +4 -0
- package/dist/agents/ids.d.ts.map +1 -1
- package/dist/agents/index.d.ts +13 -9
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +80 -68
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/message.d.ts +17 -10
- package/dist/agents/message.d.ts.map +1 -1
- package/dist/agents/model-loop.d.ts +56 -0
- package/dist/agents/model-loop.d.ts.map +1 -0
- package/dist/agents/reference.d.ts +4 -0
- package/dist/agents/reference.d.ts.map +1 -0
- package/dist/agents/request.d.ts +10 -8
- package/dist/agents/request.d.ts.map +1 -1
- package/dist/agents/retired-config.d.ts +4 -0
- package/dist/agents/retired-config.d.ts.map +1 -0
- package/dist/agents/streams.d.ts +13 -8
- package/dist/agents/streams.d.ts.map +1 -1
- package/dist/agents/streams.js +7 -5
- package/dist/agents/streams.js.map +1 -1
- package/dist/agents/tool-catalog.d.ts +9 -0
- package/dist/agents/tool-catalog.d.ts.map +1 -0
- package/dist/agents/tool-definition.d.ts +1 -0
- package/dist/agents/tool-definition.d.ts.map +1 -1
- package/dist/agents/types.d.ts +31 -68
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/agents/validation.d.ts +4 -10
- package/dist/agents/validation.d.ts.map +1 -1
- package/dist/ai-usage/execution.d.ts +53 -0
- package/dist/ai-usage/execution.d.ts.map +1 -0
- package/dist/ai-usage/index.d.ts +3 -0
- package/dist/ai-usage/index.d.ts.map +1 -0
- package/dist/auth/index.js +7 -7
- package/dist/authorization/decision.d.ts +5 -2
- package/dist/authorization/decision.d.ts.map +1 -1
- package/dist/authorization/grant-kinds.d.ts +24 -8
- package/dist/authorization/grant-kinds.d.ts.map +1 -1
- package/dist/authorization/index.d.ts +1 -1
- package/dist/authorization/index.d.ts.map +1 -1
- package/dist/authorization/index.js +8 -6
- package/dist/authorization/index.js.map +1 -1
- package/dist/authorization/resolve.d.ts +3 -3
- package/dist/authorization/resolve.d.ts.map +1 -1
- package/dist/authorization/types.d.ts +7 -5
- package/dist/authorization/types.d.ts.map +1 -1
- package/dist/blob-storage/browser.js +2 -2
- package/dist/blob-storage/index.js +3 -3
- package/dist/bootstrap/discovery.d.ts +1 -7
- package/dist/bootstrap/discovery.d.ts.map +1 -1
- package/dist/bootstrap/index.js +52 -48
- package/dist/bootstrap/index.js.map +1 -1
- package/dist/broker/index.js +2 -2
- package/dist/{chunk-zqysyfjt.js → chunk-08m3b6w8.js} +1 -1
- package/dist/{chunk-1g8negke.js → chunk-08twe8m6.js} +93 -8
- package/dist/chunk-08twe8m6.js.map +12 -0
- package/dist/{chunk-xkthy56g.js → chunk-1kamz6j0.js} +1 -1
- package/dist/{chunk-dy311asx.js → chunk-2b5qtban.js} +12 -12
- package/dist/{chunk-dy311asx.js.map → chunk-2b5qtban.js.map} +3 -3
- package/dist/{chunk-0172wgm9.js → chunk-2xns679x.js} +10 -2
- package/dist/{chunk-0172wgm9.js.map → chunk-2xns679x.js.map} +3 -3
- package/dist/{chunk-f83ka50g.js → chunk-37wk412q.js} +86 -28
- package/dist/{chunk-f83ka50g.js.map → chunk-37wk412q.js.map} +8 -8
- package/dist/{chunk-md8k0r54.js → chunk-3fqt22c4.js} +4 -4
- package/dist/{chunk-t9xghkva.js → chunk-3kv70xwp.js} +3 -2
- package/dist/{chunk-t9xghkva.js.map → chunk-3kv70xwp.js.map} +3 -3
- package/dist/{chunk-z3zp0bj1.js → chunk-407j3msh.js} +1 -1
- package/dist/{chunk-rhrbz7d4.js → chunk-4a849fr1.js} +1 -1
- package/dist/{chunk-62c7t4jc.js → chunk-4nxeacx7.js} +1 -1
- package/dist/{chunk-cy0n5dms.js → chunk-5jcdmjam.js} +1 -1
- package/dist/{chunk-819wnjz8.js → chunk-64sr682n.js} +7 -7
- package/dist/{chunk-t624af60.js → chunk-6ed5bwnd.js} +646 -67
- package/dist/{chunk-t624af60.js.map → chunk-6ed5bwnd.js.map} +10 -9
- package/dist/{chunk-x2yw73hy.js → chunk-7ds9620f.js} +1 -1
- package/dist/{chunk-dm72y8wt.js → chunk-7y0f6rf1.js} +29 -16
- package/dist/chunk-7y0f6rf1.js.map +10 -0
- package/dist/{chunk-72q2y8hn.js → chunk-8tsf6dmc.js} +2 -2
- package/dist/{chunk-nkbfrt0c.js → chunk-9aehf39w.js} +7 -7
- package/dist/{chunk-ezake7g1.js → chunk-agsvg9ar.js} +1 -1
- package/dist/{chunk-rdeagz6b.js → chunk-atmkaf60.js} +1 -1
- package/dist/{chunk-rdeagz6b.js.map → chunk-atmkaf60.js.map} +2 -2
- package/dist/chunk-c15dr03f.js +43 -0
- package/dist/chunk-c15dr03f.js.map +10 -0
- package/dist/{chunk-0hc5j867.js → chunk-d2ndstdf.js} +8 -6
- package/dist/{chunk-0hc5j867.js.map → chunk-d2ndstdf.js.map} +2 -2
- package/dist/{chunk-rnshztfq.js → chunk-d63tybny.js} +2 -2
- package/dist/{chunk-t0jjkep3.js → chunk-d8qkxt2v.js} +4 -2
- package/dist/chunk-d8qkxt2v.js.map +10 -0
- package/dist/{chunk-vybf6pkp.js → chunk-dbc80ad7.js} +1 -1
- package/dist/{chunk-4gz41why.js → chunk-dqn23610.js} +1 -1
- package/dist/{chunk-5sxb1168.js → chunk-e4rvtvpw.js} +13 -11
- package/dist/{chunk-5sxb1168.js.map → chunk-e4rvtvpw.js.map} +2 -2
- package/dist/{chunk-h9kxd41f.js → chunk-gbrpsx4m.js} +19 -6
- package/dist/chunk-gbrpsx4m.js.map +11 -0
- package/dist/{chunk-nva1xkjz.js → chunk-h0knpbz5.js} +468 -1236
- package/dist/chunk-h0knpbz5.js.map +38 -0
- package/dist/{chunk-tg5mee00.js → chunk-ha58tjtt.js} +6 -6
- package/dist/{chunk-f6erf2vv.js → chunk-hdz94br2.js} +2 -2
- package/dist/chunk-jecn6t54.js +307 -0
- package/dist/chunk-jecn6t54.js.map +12 -0
- package/dist/{chunk-dsrkgtnh.js → chunk-jq43kdvk.js} +1 -1
- package/dist/{chunk-wtmzkcht.js → chunk-k34z5rvh.js} +1 -1
- package/dist/{chunk-htq0qh7z.js → chunk-ka3a2ft3.js} +2 -2
- package/dist/{chunk-znagycq7.js → chunk-kt81c11h.js} +2 -2
- package/dist/chunk-n2arzn6e.js +1745 -0
- package/dist/chunk-n2arzn6e.js.map +20 -0
- package/dist/{chunk-f2rt4vkh.js → chunk-n2w475r0.js} +3 -3
- package/dist/{chunk-t8t39h7v.js → chunk-n6jxh8sw.js} +10 -2
- package/dist/chunk-n6jxh8sw.js.map +10 -0
- package/dist/{chunk-drjqm1aa.js → chunk-p03r0h5s.js} +310 -28
- package/dist/chunk-p03r0h5s.js.map +16 -0
- package/dist/chunk-p2vqaxkc.js +528 -0
- package/dist/chunk-p2vqaxkc.js.map +15 -0
- package/dist/{chunk-n4spznws.js → chunk-qjycjdj6.js} +84 -11
- package/dist/chunk-qjycjdj6.js.map +12 -0
- package/dist/chunk-qjzp9xyb.js +286 -0
- package/dist/chunk-qjzp9xyb.js.map +12 -0
- package/dist/{chunk-5gynx4xn.js → chunk-qv38twt8.js} +50 -69
- package/dist/{chunk-5gynx4xn.js.map → chunk-qv38twt8.js.map} +8 -8
- package/dist/{chunk-bhxaq2nn.js → chunk-qw9gvjv5.js} +1 -1
- package/dist/{chunk-8gv5z0zm.js → chunk-rp1mvzb4.js} +6 -6
- package/dist/{chunk-1e8m6yn3.js → chunk-rre42skh.js} +182 -18
- package/dist/chunk-rre42skh.js.map +39 -0
- package/dist/{chunk-ghteq96b.js → chunk-s5y30bc9.js} +2 -2
- package/dist/{chunk-a31h57d5.js → chunk-tn7xcs2n.js} +2 -2
- package/dist/{chunk-6gjqgd3d.js → chunk-tpnd31c1.js} +2 -1
- package/dist/chunk-tpnd31c1.js.map +11 -0
- package/dist/chunk-trxxmgnf.js +68 -0
- package/dist/chunk-trxxmgnf.js.map +11 -0
- package/dist/{chunk-e42bc6m3.js → chunk-vjjv9mrb.js} +2 -2
- package/dist/{chunk-8b55ygje.js → chunk-w3e09qqk.js} +1 -1
- package/dist/{chunk-ckxfnx7f.js → chunk-wjgm6jjt.js} +2 -2
- package/dist/{chunk-3j7573mj.js → chunk-x0qhkqje.js} +2 -2
- package/dist/{chunk-dysw7nsm.js → chunk-xdpwpkha.js} +2 -2
- package/dist/{chunk-a44d5zgd.js → chunk-y35ma3mj.js} +11 -16
- package/dist/{chunk-a44d5zgd.js.map → chunk-y35ma3mj.js.map} +3 -4
- package/dist/{chunk-qewtks41.js → chunk-z2sery1b.js} +64 -1
- package/dist/{chunk-qewtks41.js.map → chunk-z2sery1b.js.map} +3 -3
- package/dist/error-reporting/internal.js +4 -4
- package/dist/error-reporting/types.d.ts +7 -2
- package/dist/error-reporting/types.d.ts.map +1 -1
- package/dist/errors/catalog.d.ts +8 -0
- package/dist/errors/catalog.d.ts.map +1 -1
- package/dist/errors/internal.js +2 -2
- package/dist/events/index.js +4 -4
- package/dist/execution/agent.d.ts +18 -9
- package/dist/execution/agent.d.ts.map +1 -1
- package/dist/execution/agent.js +52 -43
- package/dist/execution/agent.js.map +1 -1
- package/dist/execution/authorization.d.ts +14 -4
- package/dist/execution/authorization.d.ts.map +1 -1
- package/dist/execution/primitive.js +45 -43
- package/dist/execution/primitive.js.map +2 -2
- package/dist/execution/request.d.ts +3 -1
- package/dist/execution/request.d.ts.map +1 -1
- package/dist/execution/request.js +46 -44
- package/dist/execution/request.js.map +3 -3
- package/dist/execution/types.d.ts +1 -1
- package/dist/execution/types.d.ts.map +1 -1
- package/dist/http/api-routes.d.ts.map +1 -1
- package/dist/http/index.js +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +82 -77
- package/dist/index.js.map +1 -1
- package/dist/json.d.ts +2 -0
- package/dist/json.d.ts.map +1 -1
- package/dist/lake-storage/index.js +5 -5
- package/dist/logging/index.js +3 -3
- package/dist/logging/types.js +2 -2
- package/dist/materialization/index.js +2 -2
- package/dist/materializer/index.js +33 -29
- package/dist/materializer/index.js.map +1 -1
- package/dist/models/catalog.d.ts +40 -0
- package/dist/models/catalog.d.ts.map +1 -0
- package/dist/models/definitions.d.ts +25 -0
- package/dist/models/definitions.d.ts.map +1 -0
- package/dist/models/errors.d.ts +52 -0
- package/dist/models/errors.d.ts.map +1 -0
- package/dist/models/events.d.ts +192 -0
- package/dist/models/events.d.ts.map +1 -0
- package/dist/models/index.d.ts +17 -39
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +50 -0
- package/dist/models/index.js.map +9 -0
- package/dist/models/language-model.d.ts +90 -0
- package/dist/models/language-model.d.ts.map +1 -0
- package/dist/models/messages.d.ts +74 -0
- package/dist/models/messages.d.ts.map +1 -0
- package/dist/models/pricing.d.ts +69 -0
- package/dist/models/pricing.d.ts.map +1 -0
- package/dist/models/rate-card.d.ts +24 -0
- package/dist/models/rate-card.d.ts.map +1 -0
- package/dist/models/tools.d.ts +24 -0
- package/dist/models/tools.d.ts.map +1 -0
- package/dist/objects/index.js +38 -34
- package/dist/objects/index.js.map +1 -1
- package/dist/objects/query/index.js +32 -28
- package/dist/objects/query/index.js.map +1 -1
- package/dist/ontology/index.js +5 -5
- package/dist/ontology/internal.js +4 -4
- package/dist/pipelines/index.js +37 -35
- package/dist/pipelines/index.js.map +1 -1
- package/dist/projections/internal.js +35 -31
- package/dist/projections/internal.js.map +1 -1
- package/dist/queues/in-memory.d.ts +3 -2
- package/dist/queues/in-memory.d.ts.map +1 -1
- package/dist/queues/index.d.ts +3 -1
- package/dist/queues/index.d.ts.map +1 -1
- package/dist/queues/index.js +1 -1
- package/dist/queues/types.d.ts +15 -3
- package/dist/queues/types.d.ts.map +1 -1
- package/dist/runtime/create.d.ts +4 -4
- package/dist/runtime/create.d.ts.map +1 -1
- package/dist/runtime/definitions.d.ts +2 -2
- package/dist/runtime/definitions.d.ts.map +1 -1
- package/dist/runtime/host.d.ts +3 -2
- package/dist/runtime/host.d.ts.map +1 -1
- package/dist/runtime/resolve-definitions.d.ts +2 -2
- package/dist/runtime/resolve-definitions.d.ts.map +1 -1
- package/dist/runtime/sixb.d.ts +4 -2
- package/dist/runtime/sixb.d.ts.map +1 -1
- package/dist/security/every.d.ts +1 -4
- package/dist/security/every.d.ts.map +1 -1
- package/dist/security/grants.d.ts +6 -5
- package/dist/security/grants.d.ts.map +1 -1
- package/dist/security/index.d.ts +1 -1
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/registry.d.ts +1 -1
- package/dist/security/registry.d.ts.map +1 -1
- package/dist/security/types.d.ts +13 -5
- package/dist/security/types.d.ts.map +1 -1
- package/dist/security/validation.d.ts +4 -2
- package/dist/security/validation.d.ts.map +1 -1
- package/dist/storage/action-runs/failure.js +3 -3
- package/dist/storage/action-runs/provider.js +2 -2
- package/dist/storage/agents/errors.d.ts +1 -1
- package/dist/storage/agents/errors.d.ts.map +1 -1
- package/dist/storage/agents/in-memory.d.ts +3 -2
- package/dist/storage/agents/in-memory.d.ts.map +1 -1
- package/dist/storage/agents/index.d.ts +1 -1
- package/dist/storage/agents/index.d.ts.map +1 -1
- package/dist/storage/agents/provider.d.ts +11 -4
- package/dist/storage/agents/provider.d.ts.map +1 -1
- package/dist/storage/agents/provider.js +18 -15
- package/dist/storage/agents/provider.js.map +1 -1
- package/dist/storage/agents/types.d.ts +65 -17
- package/dist/storage/agents/types.d.ts.map +1 -1
- package/dist/storage/ai-cost/analytics.d.ts +2 -1
- package/dist/storage/ai-cost/analytics.d.ts.map +1 -1
- package/dist/storage/ai-cost/codec.d.ts +3 -2
- package/dist/storage/ai-cost/codec.d.ts.map +1 -1
- package/dist/storage/ai-cost/groups.d.ts +51 -0
- package/dist/storage/ai-cost/groups.d.ts.map +1 -0
- package/dist/storage/ai-cost/in-memory.d.ts +11 -1
- package/dist/storage/ai-cost/in-memory.d.ts.map +1 -1
- package/dist/storage/ai-cost/index.d.ts +1 -1
- package/dist/storage/ai-cost/index.d.ts.map +1 -1
- package/dist/storage/ai-cost/provider.d.ts +2 -0
- package/dist/storage/ai-cost/provider.d.ts.map +1 -1
- package/dist/storage/ai-cost/provider.js +29 -13
- package/dist/storage/ai-cost/provider.js.map +3 -3
- package/dist/storage/ai-cost/types.d.ts +64 -15
- package/dist/storage/ai-cost/types.d.ts.map +1 -1
- package/dist/storage/ai-cost/validation.d.ts +2 -1
- package/dist/storage/ai-cost/validation.d.ts.map +1 -1
- package/dist/storage/ai-limits/enforcement.d.ts +14 -0
- package/dist/storage/ai-limits/enforcement.d.ts.map +1 -0
- package/dist/storage/ai-limits/enforcement.js +21 -0
- package/dist/storage/ai-limits/enforcement.js.map +9 -0
- package/dist/storage/ai-limits/errors.d.ts +8 -0
- package/dist/storage/ai-limits/errors.d.ts.map +1 -0
- package/dist/storage/ai-limits/in-memory.d.ts +78 -0
- package/dist/storage/ai-limits/in-memory.d.ts.map +1 -0
- package/dist/storage/ai-limits/index.d.ts +7 -0
- package/dist/storage/ai-limits/index.d.ts.map +1 -0
- package/dist/storage/ai-limits/period.d.ts +4 -0
- package/dist/storage/ai-limits/period.d.ts.map +1 -0
- package/dist/storage/ai-limits/provider.d.ts +85 -0
- package/dist/storage/ai-limits/provider.d.ts.map +1 -0
- package/dist/storage/ai-limits/provider.js +62 -0
- package/dist/storage/ai-limits/provider.js.map +9 -0
- package/dist/storage/ai-limits/types.d.ts +175 -0
- package/dist/storage/ai-limits/types.d.ts.map +1 -0
- package/dist/storage/ai-usage/in-memory.d.ts +4 -0
- package/dist/storage/ai-usage/in-memory.d.ts.map +1 -1
- package/dist/storage/ai-usage/record.d.ts.map +1 -1
- package/dist/storage/ai-usage/types.d.ts +6 -2
- package/dist/storage/ai-usage/types.d.ts.map +1 -1
- package/dist/storage/auth/errors.d.ts +1 -1
- package/dist/storage/auth/errors.d.ts.map +1 -1
- package/dist/storage/auth/in-memory/auth-storage.d.ts +4 -1
- package/dist/storage/auth/in-memory/auth-storage.d.ts.map +1 -1
- package/dist/storage/auth/in-memory/device-authorizations.d.ts +29 -0
- package/dist/storage/auth/in-memory/device-authorizations.d.ts.map +1 -0
- package/dist/storage/auth/in-memory/shared.d.ts +3 -1
- package/dist/storage/auth/in-memory/shared.d.ts.map +1 -1
- package/dist/storage/auth/index.d.ts +2 -1
- package/dist/storage/auth/index.d.ts.map +1 -1
- package/dist/storage/auth/types.d.ts +66 -0
- package/dist/storage/auth/types.d.ts.map +1 -1
- package/dist/storage/connector-connections/provider.js +2 -2
- package/dist/storage/executions/provider.js +1 -1
- package/dist/storage/executions/run-link.d.ts +7 -2
- package/dist/storage/executions/run-link.d.ts.map +1 -1
- package/dist/storage/executions/validation.d.ts.map +1 -1
- package/dist/storage/in-memory/index.d.ts +4 -0
- package/dist/storage/in-memory/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +7 -4
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +51 -38
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/ontology/provider.js +3 -3
- package/dist/storage/pipeline-runs/provider.js +2 -2
- package/dist/storage/projection-runs/provider.js +4 -4
- package/dist/storage/sync-runs/provider.js +2 -2
- package/dist/storage/types.d.ts +5 -1
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/storage/webhook-runs/provider.js +2 -2
- package/dist/storage/workflow-runs/provider.d.ts +1 -1
- package/dist/storage/workflow-runs/provider.js +10 -11
- package/dist/storage/workflow-runs/provider.js.map +1 -1
- package/dist/storage/workflow-runs/types.d.ts +5 -4
- package/dist/storage/workflow-runs/types.d.ts.map +1 -1
- package/dist/syncs/index.js +37 -35
- package/dist/syncs/index.js.map +1 -1
- package/dist/testing/agent-execution.d.ts +3 -1
- 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-cost-storage-contract.d.ts.map +1 -1
- package/dist/testing/ai-limit-storage-contract.d.ts +18 -0
- package/dist/testing/ai-limit-storage-contract.d.ts.map +1 -0
- package/dist/testing/ai-model-call-groups-contract.d.ts +6 -0
- package/dist/testing/ai-model-call-groups-contract.d.ts.map +1 -0
- package/dist/testing/ai-usage-storage-contract.d.ts.map +1 -1
- package/dist/testing/auth-storage-contract.d.ts.map +1 -1
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +3637 -1962
- package/dist/testing/index.js.map +14 -12
- package/dist/testing/queues-contract.d.ts.map +1 -1
- package/dist/webhooks/internal.js +32 -28
- package/dist/webhooks/internal.js.map +2 -2
- package/dist/workers/index.js +2 -2
- package/dist/workflows/agent-step-identity.d.ts +3 -0
- package/dist/workflows/agent-step-identity.d.ts.map +1 -0
- package/dist/workflows/builders.d.ts +2 -3
- package/dist/workflows/builders.d.ts.map +1 -1
- package/dist/workflows/execution.d.ts +1 -1
- package/dist/workflows/execution.d.ts.map +1 -1
- package/dist/workflows/failure.d.ts +1 -1
- package/dist/workflows/failure.d.ts.map +1 -1
- package/dist/workflows/index.d.ts +3 -2
- package/dist/workflows/index.d.ts.map +1 -1
- package/dist/workflows/index.js +53 -45
- package/dist/workflows/index.js.map +1 -1
- package/dist/workflows/types.d.ts +26 -11
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/validation.d.ts +7 -1
- package/dist/workflows/validation.d.ts.map +1 -1
- package/package.json +19 -4
- package/src/agents/adapters.ts +109 -115
- package/src/agents/authority.ts +214 -32
- package/src/agents/builders.ts +3 -50
- package/src/agents/context-compaction.ts +4 -0
- package/src/agents/dispatch.ts +59 -2
- package/src/agents/errors.ts +5 -2
- package/src/agents/execution.ts +53 -52
- package/src/agents/ids.ts +16 -1
- package/src/agents/index.ts +23 -11
- package/src/agents/message.ts +18 -9
- package/src/agents/model-loop.ts +1023 -0
- package/src/agents/reference.ts +7 -0
- package/src/agents/request.ts +141 -74
- package/src/agents/retired-config.ts +20 -0
- package/src/agents/streams.ts +45 -19
- package/src/agents/tool-catalog.ts +21 -0
- package/src/agents/tool-definition.ts +23 -0
- package/src/agents/types.ts +39 -81
- package/src/agents/validation.ts +34 -180
- package/src/ai-usage/execution.ts +196 -0
- package/src/ai-usage/index.ts +15 -0
- package/src/authorization/decision.ts +27 -10
- package/src/authorization/grant-kinds.ts +62 -15
- package/src/authorization/index.ts +1 -0
- package/src/authorization/resolve.ts +12 -5
- package/src/authorization/types.ts +7 -5
- package/src/bootstrap/discovery.ts +0 -3
- package/src/error-reporting/types.ts +4 -2
- package/src/errors/catalog.ts +8 -0
- package/src/execution/agent.ts +129 -22
- package/src/execution/authorization.ts +48 -18
- package/src/execution/request.ts +4 -1
- package/src/execution/types.ts +1 -1
- package/src/http/api-routes.ts +63 -0
- package/src/index.ts +36 -7
- package/src/json.ts +9 -0
- package/src/models/catalog.ts +137 -0
- package/src/models/definitions.ts +202 -0
- package/src/models/errors.ts +83 -0
- package/src/models/events.ts +198 -0
- package/src/models/index.ts +89 -71
- package/src/models/language-model.ts +143 -0
- package/src/models/messages.ts +78 -0
- package/src/models/pricing.ts +390 -0
- package/src/models/rate-card.ts +101 -0
- package/src/models/tools.ts +29 -0
- package/src/queues/in-memory.ts +5 -0
- package/src/queues/index.ts +11 -0
- package/src/queues/types.ts +20 -3
- package/src/runtime/create.ts +7 -5
- package/src/runtime/definitions.ts +2 -2
- package/src/runtime/host.ts +3 -2
- package/src/runtime/resolve-definitions.ts +13 -36
- package/src/runtime/sixb.ts +6 -8
- package/src/security/every.ts +0 -4
- package/src/security/grants.ts +55 -11
- package/src/security/index.ts +2 -0
- package/src/security/registry.ts +6 -5
- package/src/security/types.ts +15 -4
- package/src/security/validation.ts +30 -9
- package/src/storage/agents/errors.ts +1 -0
- package/src/storage/agents/in-memory.ts +121 -11
- package/src/storage/agents/index.ts +7 -0
- package/src/storage/agents/provider.ts +150 -6
- package/src/storage/agents/types.ts +73 -16
- package/src/storage/ai-cost/analytics.ts +63 -6
- package/src/storage/ai-cost/codec.ts +37 -12
- package/src/storage/ai-cost/groups.ts +248 -0
- package/src/storage/ai-cost/in-memory.ts +42 -0
- package/src/storage/ai-cost/index.ts +6 -0
- package/src/storage/ai-cost/provider.ts +7 -0
- package/src/storage/ai-cost/types.ts +76 -14
- package/src/storage/ai-cost/validation.ts +147 -17
- package/src/storage/ai-limits/enforcement.ts +68 -0
- package/src/storage/ai-limits/errors.ts +23 -0
- package/src/storage/ai-limits/in-memory.ts +671 -0
- package/src/storage/ai-limits/index.ts +31 -0
- package/src/storage/ai-limits/period.ts +11 -0
- package/src/storage/ai-limits/provider.ts +430 -0
- package/src/storage/ai-limits/types.ts +195 -0
- package/src/storage/ai-usage/in-memory.ts +13 -0
- package/src/storage/ai-usage/record.ts +17 -0
- package/src/storage/ai-usage/types.ts +6 -2
- package/src/storage/auth/errors.ts +6 -0
- package/src/storage/auth/in-memory/auth-storage.ts +69 -0
- package/src/storage/auth/in-memory/device-authorizations.ts +145 -0
- package/src/storage/auth/in-memory/shared.ts +7 -0
- package/src/storage/auth/index.ts +7 -0
- package/src/storage/auth/types.ts +73 -0
- package/src/storage/executions/run-link.ts +16 -6
- package/src/storage/executions/validation.ts +36 -6
- package/src/storage/in-memory/index.ts +48 -4
- package/src/storage/index.ts +51 -1
- package/src/storage/types.ts +37 -0
- package/src/storage/workflow-runs/in-memory.ts +3 -3
- package/src/storage/workflow-runs/provider.ts +2 -2
- package/src/storage/workflow-runs/types.ts +6 -3
- package/src/testing/agent-execution.ts +40 -28
- package/src/testing/agent-storage-contract.ts +249 -28
- package/src/testing/ai-cost-storage-contract.ts +96 -8
- package/src/testing/ai-limit-storage-contract.ts +1134 -0
- package/src/testing/ai-model-call-groups-contract.ts +353 -0
- package/src/testing/ai-usage-storage-contract.ts +31 -0
- package/src/testing/auth-storage-contract.ts +85 -0
- package/src/testing/execution-storage-contract.ts +2 -2
- package/src/testing/index.ts +10 -0
- package/src/testing/queues-contract.ts +36 -1
- package/src/workflows/agent-step-identity.ts +4 -0
- package/src/workflows/builders.ts +95 -9
- package/src/workflows/execution.ts +2 -2
- package/src/workflows/failure.ts +2 -2
- package/src/workflows/index.ts +3 -0
- package/src/workflows/types.ts +23 -11
- package/src/workflows/validation.ts +100 -7
- package/dist/chunk-1e8m6yn3.js.map +0 -37
- package/dist/chunk-1g8negke.js.map +0 -11
- package/dist/chunk-6gjqgd3d.js.map +0 -11
- package/dist/chunk-dm72y8wt.js.map +0 -10
- package/dist/chunk-drjqm1aa.js.map +0 -15
- package/dist/chunk-fe5ev6mr.js +0 -55
- package/dist/chunk-fe5ev6mr.js.map +0 -11
- package/dist/chunk-h9kxd41f.js.map +0 -11
- package/dist/chunk-hceck7dq.js +0 -137
- package/dist/chunk-hceck7dq.js.map +0 -10
- package/dist/chunk-n4spznws.js.map +0 -11
- package/dist/chunk-nva1xkjz.js.map +0 -46
- package/dist/chunk-t0jjkep3.js.map +0 -10
- package/dist/chunk-t8t39h7v.js.map +0 -10
- /package/dist/{chunk-zqysyfjt.js.map → chunk-08m3b6w8.js.map} +0 -0
- /package/dist/{chunk-xkthy56g.js.map → chunk-1kamz6j0.js.map} +0 -0
- /package/dist/{chunk-md8k0r54.js.map → chunk-3fqt22c4.js.map} +0 -0
- /package/dist/{chunk-z3zp0bj1.js.map → chunk-407j3msh.js.map} +0 -0
- /package/dist/{chunk-rhrbz7d4.js.map → chunk-4a849fr1.js.map} +0 -0
- /package/dist/{chunk-62c7t4jc.js.map → chunk-4nxeacx7.js.map} +0 -0
- /package/dist/{chunk-cy0n5dms.js.map → chunk-5jcdmjam.js.map} +0 -0
- /package/dist/{chunk-819wnjz8.js.map → chunk-64sr682n.js.map} +0 -0
- /package/dist/{chunk-x2yw73hy.js.map → chunk-7ds9620f.js.map} +0 -0
- /package/dist/{chunk-72q2y8hn.js.map → chunk-8tsf6dmc.js.map} +0 -0
- /package/dist/{chunk-nkbfrt0c.js.map → chunk-9aehf39w.js.map} +0 -0
- /package/dist/{chunk-ezake7g1.js.map → chunk-agsvg9ar.js.map} +0 -0
- /package/dist/{chunk-rnshztfq.js.map → chunk-d63tybny.js.map} +0 -0
- /package/dist/{chunk-vybf6pkp.js.map → chunk-dbc80ad7.js.map} +0 -0
- /package/dist/{chunk-4gz41why.js.map → chunk-dqn23610.js.map} +0 -0
- /package/dist/{chunk-tg5mee00.js.map → chunk-ha58tjtt.js.map} +0 -0
- /package/dist/{chunk-f6erf2vv.js.map → chunk-hdz94br2.js.map} +0 -0
- /package/dist/{chunk-dsrkgtnh.js.map → chunk-jq43kdvk.js.map} +0 -0
- /package/dist/{chunk-wtmzkcht.js.map → chunk-k34z5rvh.js.map} +0 -0
- /package/dist/{chunk-htq0qh7z.js.map → chunk-ka3a2ft3.js.map} +0 -0
- /package/dist/{chunk-znagycq7.js.map → chunk-kt81c11h.js.map} +0 -0
- /package/dist/{chunk-f2rt4vkh.js.map → chunk-n2w475r0.js.map} +0 -0
- /package/dist/{chunk-bhxaq2nn.js.map → chunk-qw9gvjv5.js.map} +0 -0
- /package/dist/{chunk-8gv5z0zm.js.map → chunk-rp1mvzb4.js.map} +0 -0
- /package/dist/{chunk-ghteq96b.js.map → chunk-s5y30bc9.js.map} +0 -0
- /package/dist/{chunk-a31h57d5.js.map → chunk-tn7xcs2n.js.map} +0 -0
- /package/dist/{chunk-e42bc6m3.js.map → chunk-vjjv9mrb.js.map} +0 -0
- /package/dist/{chunk-8b55ygje.js.map → chunk-w3e09qqk.js.map} +0 -0
- /package/dist/{chunk-ckxfnx7f.js.map → chunk-wjgm6jjt.js.map} +0 -0
- /package/dist/{chunk-3j7573mj.js.map → chunk-x0qhkqje.js.map} +0 -0
- /package/dist/{chunk-dysw7nsm.js.map → chunk-xdpwpkha.js.map} +0 -0
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
import {
|
|
3
|
+
SyncRunError,
|
|
4
|
+
assertSyncRunExecution
|
|
5
|
+
} from "./chunk-4nxeacx7.js";
|
|
6
|
+
import {
|
|
7
|
+
WebhookRunError,
|
|
8
|
+
assertWebhookRunExecution
|
|
9
|
+
} from "./chunk-agsvg9ar.js";
|
|
10
|
+
import {
|
|
11
|
+
WorkflowRunError,
|
|
12
|
+
assertWorkflowAgentNodeRunExecution,
|
|
13
|
+
assertWorkflowRunExecution
|
|
14
|
+
} from "./chunk-qjzp9xyb.js";
|
|
15
|
+
import {
|
|
16
|
+
CONNECTOR_CONNECTION_RUN_FAILURE_CODES,
|
|
17
|
+
ConnectorConnectionStorageError
|
|
18
|
+
} from "./chunk-5gd7tpv6.js";
|
|
19
|
+
import {
|
|
20
|
+
ExecutionStorageError,
|
|
21
|
+
cloneExecutionRecord,
|
|
22
|
+
normalizeExecutionRecord,
|
|
23
|
+
validateExecutionRecordReferences
|
|
24
|
+
} from "./chunk-gbrpsx4m.js";
|
|
2
25
|
import {
|
|
3
26
|
ProviderMaterializationTransactionLifecycle,
|
|
4
27
|
appendScopeSnapshot,
|
|
@@ -27,7 +50,7 @@ import {
|
|
|
27
50
|
startScopeAccumulator,
|
|
28
51
|
uniqueSorted,
|
|
29
52
|
workUniquenessKey
|
|
30
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-8tsf6dmc.js";
|
|
31
54
|
import {
|
|
32
55
|
createAgentOperationScope,
|
|
33
56
|
createAuthOperationScope,
|
|
@@ -39,7 +62,7 @@ import {
|
|
|
39
62
|
import {
|
|
40
63
|
PipelineRunError,
|
|
41
64
|
assertPipelineRunExecution
|
|
42
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-5jcdmjam.js";
|
|
43
66
|
import {
|
|
44
67
|
ProjectionRunError,
|
|
45
68
|
advanceProjectionTelemetry,
|
|
@@ -66,27 +89,14 @@ import {
|
|
|
66
89
|
publicProjectionRunRecord,
|
|
67
90
|
requireTelemetryProjectionRun,
|
|
68
91
|
staleProjectionRunExecution
|
|
69
|
-
} from "./chunk-
|
|
70
|
-
import {
|
|
71
|
-
SyncRunError,
|
|
72
|
-
assertSyncRunExecution
|
|
73
|
-
} from "./chunk-62c7t4jc.js";
|
|
74
|
-
import {
|
|
75
|
-
WebhookRunError,
|
|
76
|
-
assertWebhookRunExecution
|
|
77
|
-
} from "./chunk-ezake7g1.js";
|
|
78
|
-
import {
|
|
79
|
-
WorkflowRunError,
|
|
80
|
-
assertWorkflowAgentNodeRunExecution,
|
|
81
|
-
assertWorkflowRunExecution
|
|
82
|
-
} from "./chunk-fe5ev6mr.js";
|
|
92
|
+
} from "./chunk-xdpwpkha.js";
|
|
83
93
|
import {
|
|
84
94
|
parseActionRunFailure
|
|
85
|
-
} from "./chunk-
|
|
95
|
+
} from "./chunk-ka3a2ft3.js";
|
|
86
96
|
import {
|
|
87
97
|
ActionRunError,
|
|
88
98
|
assertActionRunExecution
|
|
89
|
-
} from "./chunk-
|
|
99
|
+
} from "./chunk-1kamz6j0.js";
|
|
90
100
|
import {
|
|
91
101
|
AgentStorageError,
|
|
92
102
|
agentContextCheckpointMatchesCreateInput,
|
|
@@ -94,25 +104,45 @@ import {
|
|
|
94
104
|
assertAgentContextCheckpointAuthority,
|
|
95
105
|
assertAgentContextCheckpointReplayState,
|
|
96
106
|
assertAgentRunExecution,
|
|
97
|
-
|
|
98
|
-
|
|
107
|
+
assertConversationAgentRunSpec,
|
|
108
|
+
assertCreateAgentContextCheckpointInput,
|
|
109
|
+
assertCreateSubagentRunInput,
|
|
110
|
+
assertSubagentRunResult,
|
|
111
|
+
subagentRunMatchesCreateInput
|
|
112
|
+
} from "./chunk-08twe8m6.js";
|
|
99
113
|
import {
|
|
100
114
|
InMemoryAiUsageStorage,
|
|
101
115
|
aiModelCallCostMatchesUsage,
|
|
102
116
|
buildAiAccountingOverview,
|
|
103
117
|
buildAiModelCallAccountingList,
|
|
118
|
+
buildAiModelCallGroups,
|
|
104
119
|
normalizeAiModelCallCostRecord
|
|
105
|
-
} from "./chunk-
|
|
106
|
-
import {
|
|
107
|
-
CONNECTOR_CONNECTION_RUN_FAILURE_CODES,
|
|
108
|
-
ConnectorConnectionStorageError
|
|
109
|
-
} from "./chunk-5gd7tpv6.js";
|
|
120
|
+
} from "./chunk-p03r0h5s.js";
|
|
110
121
|
import {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
122
|
+
AiLimitOperationLock,
|
|
123
|
+
AiLimitStorageError,
|
|
124
|
+
aiLimitAccountingEntryAppliesToSubject,
|
|
125
|
+
aiLimitAmountKey,
|
|
126
|
+
aiLimitCalendarMonth,
|
|
127
|
+
aiLimitPolicyDimensionKey,
|
|
128
|
+
aiLimitQuantityFromAmount,
|
|
129
|
+
aiLimitReservationBuckets,
|
|
130
|
+
aiLimitReservationRequestKey,
|
|
131
|
+
aiLimitReservationRequestMatches,
|
|
132
|
+
aiLimitSubjectKey,
|
|
133
|
+
aiLimitSubjectsFromAccountingEntry,
|
|
134
|
+
aiModelCallReservationKey,
|
|
135
|
+
assertAiLimitAccountingMatchesReservation,
|
|
136
|
+
assertNonBlank,
|
|
137
|
+
cloneAiLimitPolicy,
|
|
138
|
+
cloneValidDate,
|
|
139
|
+
normalizeAiLimitAmount,
|
|
140
|
+
normalizeAiModelCallReservationIdentity,
|
|
141
|
+
normalizeCreateAiLimitPolicy,
|
|
142
|
+
normalizeReserveAiModelCall,
|
|
143
|
+
normalizeUpdateAiLimitPolicy,
|
|
144
|
+
resolveAiLimitActual
|
|
145
|
+
} from "./chunk-jecn6t54.js";
|
|
116
146
|
import {
|
|
117
147
|
assertPinnedDatasetWatermark
|
|
118
148
|
} from "./chunk-9dzba0f2.js";
|
|
@@ -126,22 +156,22 @@ import {
|
|
|
126
156
|
projectionEntityKey,
|
|
127
157
|
telemetryPointKey,
|
|
128
158
|
telemetryPointSortKey
|
|
129
|
-
} from "./chunk-
|
|
159
|
+
} from "./chunk-dbc80ad7.js";
|
|
130
160
|
import {
|
|
131
161
|
MaterializationConflictError,
|
|
132
162
|
MaterializationValidationError
|
|
133
163
|
} from "./chunk-ry24jbr1.js";
|
|
134
164
|
import {
|
|
135
165
|
AGENT_RUN_FAILURE_CODES
|
|
136
|
-
} from "./chunk-
|
|
166
|
+
} from "./chunk-d8qkxt2v.js";
|
|
137
167
|
import {
|
|
138
168
|
InMemoryAuthStorage,
|
|
139
169
|
paginate,
|
|
140
170
|
principalsEqual
|
|
141
|
-
} from "./chunk-
|
|
171
|
+
} from "./chunk-rre42skh.js";
|
|
142
172
|
import {
|
|
143
173
|
normalizeRequesterGroupIds
|
|
144
|
-
} from "./chunk-
|
|
174
|
+
} from "./chunk-4a849fr1.js";
|
|
145
175
|
import {
|
|
146
176
|
compareDecimalValues
|
|
147
177
|
} from "./chunk-04b07a9q.js";
|
|
@@ -149,11 +179,11 @@ import {
|
|
|
149
179
|
createSixbError,
|
|
150
180
|
parseSixbFailure,
|
|
151
181
|
toSixbFailure
|
|
152
|
-
} from "./chunk-
|
|
182
|
+
} from "./chunk-2xns679x.js";
|
|
153
183
|
import {
|
|
154
184
|
cloneJsonValue,
|
|
155
185
|
stableJsonStringify
|
|
156
|
-
} from "./chunk-
|
|
186
|
+
} from "./chunk-n6jxh8sw.js";
|
|
157
187
|
// src/storage/action-runs/idempotency.ts
|
|
158
188
|
function actionSubjectsEqual(left, right) {
|
|
159
189
|
if (left.kind !== right.kind)
|
|
@@ -191,7 +221,7 @@ var runDirectly = async (run) => run();
|
|
|
191
221
|
function actionRunKey(projectId, id) {
|
|
192
222
|
return JSON.stringify([projectId, id]);
|
|
193
223
|
}
|
|
194
|
-
function
|
|
224
|
+
function assertNonBlank2(value, fieldName) {
|
|
195
225
|
if (typeof value !== "string" || value.trim().length === 0) {
|
|
196
226
|
throw new ActionRunError(`[Sixb] Action materialization ${fieldName} must be nonblank.`);
|
|
197
227
|
}
|
|
@@ -451,9 +481,9 @@ class InMemoryActionRunStorage {
|
|
|
451
481
|
});
|
|
452
482
|
}
|
|
453
483
|
requireMaterializationRun(input) {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
484
|
+
assertNonBlank2(input.projectId, "projectId");
|
|
485
|
+
assertNonBlank2(input.runId, "runId");
|
|
486
|
+
assertNonBlank2(input.actionId, "actionId");
|
|
457
487
|
const existing = this.rows.get(actionRunKey(input.projectId, input.runId));
|
|
458
488
|
if (!existing) {
|
|
459
489
|
throw new ActionRunError(`[Sixb] Action run '${input.runId}' not found for project '${input.projectId}'.`);
|
|
@@ -468,7 +498,7 @@ class InMemoryActionRunStorage {
|
|
|
468
498
|
}
|
|
469
499
|
}
|
|
470
500
|
// src/agents/message.ts
|
|
471
|
-
var AGENT_MESSAGE_CONTENT_VERSION =
|
|
501
|
+
var AGENT_MESSAGE_CONTENT_VERSION = 2;
|
|
472
502
|
|
|
473
503
|
// src/storage/agents/in-memory.ts
|
|
474
504
|
function normalizeFailure(failure) {
|
|
@@ -511,7 +541,6 @@ class InMemoryAgentThreadStore {
|
|
|
511
541
|
const record = {
|
|
512
542
|
id: input.id,
|
|
513
543
|
projectId: input.projectId,
|
|
514
|
-
agentId: input.agentId,
|
|
515
544
|
ownerPrincipal: clone(input.ownerPrincipal),
|
|
516
545
|
...input.title === undefined ? {} : { title: input.title },
|
|
517
546
|
status: input.status ?? "active",
|
|
@@ -530,8 +559,7 @@ class InMemoryAgentThreadStore {
|
|
|
530
559
|
async list(input) {
|
|
531
560
|
const order = input.order ?? "desc";
|
|
532
561
|
const statuses = input.statuses ? new Set(input.statuses) : null;
|
|
533
|
-
const
|
|
534
|
-
const filtered = [...this.state.threads.values()].filter((thread) => thread.projectId === input.projectId).filter((thread) => input.agentId ? thread.agentId === input.agentId : true).filter((thread) => agentIds ? agentIds.has(thread.agentId) : true).filter((thread) => statuses ? statuses.has(thread.status) : true).filter((thread) => input.ownerPrincipal ? principalsEqual(thread.ownerPrincipal, input.ownerPrincipal) : true).sort((a, b) => compareByDate(a.lastMessageAt ?? a.createdAt, b.lastMessageAt ?? b.createdAt, a.id, b.id, order));
|
|
562
|
+
const filtered = [...this.state.threads.values()].filter((thread) => thread.projectId === input.projectId).filter((thread) => statuses ? statuses.has(thread.status) : true).filter((thread) => input.ownerPrincipal ? principalsEqual(thread.ownerPrincipal, input.ownerPrincipal) : true).sort((a, b) => compareByDate(a.lastMessageAt ?? a.createdAt, b.lastMessageAt ?? b.createdAt, a.id, b.id, order));
|
|
535
563
|
const { page, hasMore, total } = applyWindow(filtered, input.offset, input.limit);
|
|
536
564
|
return { threads: page.map(clone), hasMore, total };
|
|
537
565
|
}
|
|
@@ -545,12 +573,12 @@ class InMemoryAgentRunStore {
|
|
|
545
573
|
this.executions = executions;
|
|
546
574
|
}
|
|
547
575
|
async create(input) {
|
|
576
|
+
assertConversationAgentRunSpec(input.spec);
|
|
548
577
|
await assertAgentRunExecution({
|
|
549
578
|
executions: this.executions,
|
|
550
579
|
projectId: input.projectId,
|
|
551
580
|
executionId: input.executionId,
|
|
552
|
-
runId: input.id
|
|
553
|
-
agentId: input.agentId
|
|
581
|
+
runId: input.id
|
|
554
582
|
});
|
|
555
583
|
const threadKey = key(input.projectId, input.threadId);
|
|
556
584
|
const thread = this.state.threads.get(threadKey);
|
|
@@ -569,12 +597,13 @@ class InMemoryAgentRunStore {
|
|
|
569
597
|
}
|
|
570
598
|
const createdAt = new Date(input.createdAt ?? new Date);
|
|
571
599
|
const run = {
|
|
600
|
+
kind: "conversation",
|
|
572
601
|
id: input.id,
|
|
573
602
|
projectId: input.projectId,
|
|
574
603
|
executionId: input.executionId,
|
|
575
604
|
threadId: input.threadId,
|
|
576
|
-
agentId: input.agentId,
|
|
577
605
|
triggerMessageId: input.triggerMessageId,
|
|
606
|
+
spec: clone(input.spec),
|
|
578
607
|
requesterGroupIds: normalizeRequesterGroupIds(input.requesterGroupIds),
|
|
579
608
|
status: "queued",
|
|
580
609
|
attempt: 0,
|
|
@@ -589,6 +618,57 @@ class InMemoryAgentRunStore {
|
|
|
589
618
|
this.state.threads.set(threadKey, clone(updatedThread));
|
|
590
619
|
return clone(run);
|
|
591
620
|
}
|
|
621
|
+
async createSubagent(input) {
|
|
622
|
+
assertCreateSubagentRunInput(input);
|
|
623
|
+
const execution = await assertAgentRunExecution({
|
|
624
|
+
executions: this.executions,
|
|
625
|
+
projectId: input.projectId,
|
|
626
|
+
executionId: input.executionId,
|
|
627
|
+
runId: input.id
|
|
628
|
+
});
|
|
629
|
+
const runKey = key(input.projectId, input.id);
|
|
630
|
+
const existing = this.state.runs.get(runKey);
|
|
631
|
+
if (existing) {
|
|
632
|
+
if (subagentRunMatchesCreateInput(existing, input))
|
|
633
|
+
return clone(existing);
|
|
634
|
+
throw new AgentStorageError("duplicate_id", `[Sixb] Subagent run '${input.id}' already exists with different immutable inputs.`);
|
|
635
|
+
}
|
|
636
|
+
const parent = this.state.runs.get(key(input.projectId, input.parentRunId));
|
|
637
|
+
if (!parent || parent.kind !== "conversation") {
|
|
638
|
+
throw new AgentStorageError("run_not_found", `[Sixb] Parent Agent run '${input.parentRunId}' was not found.`);
|
|
639
|
+
}
|
|
640
|
+
if (parent.status !== "running") {
|
|
641
|
+
throw new AgentStorageError("invalid_state", `[Sixb] Parent Agent run '${parent.id}' is not running (status '${parent.status}').`);
|
|
642
|
+
}
|
|
643
|
+
if (execution.source.type !== "execution" || execution.source.executionId !== parent.executionId) {
|
|
644
|
+
throw new AgentStorageError("invalid_input", `[Sixb] Subagent execution '${execution.id}' is not a child of parent execution '${parent.executionId}'.`);
|
|
645
|
+
}
|
|
646
|
+
if (parent.execution?.token !== input.parentExecutionToken) {
|
|
647
|
+
throw new AgentStorageError("execution_lost", `[Sixb] Parent Agent run '${parent.id}' is no longer owned by this execution.`);
|
|
648
|
+
}
|
|
649
|
+
const activeChildren = [...this.state.runs.values()].filter((run2) => run2.kind === "subagent" && run2.projectId === input.projectId && run2.parentRunId === parent.id && (run2.status === "queued" || run2.status === "running")).length;
|
|
650
|
+
if (activeChildren >= input.maxActiveChildren) {
|
|
651
|
+
throw new AgentStorageError("active_child_limit", `[Sixb] Agent run '${parent.id}' already has ${activeChildren} active subagents.`);
|
|
652
|
+
}
|
|
653
|
+
if ([...this.state.runs.values()].some((run2) => run2.projectId === input.projectId && run2.executionId === input.executionId)) {
|
|
654
|
+
throw new AgentStorageError("duplicate_id", `[Sixb] Execution '${input.executionId}' already belongs to another Agent run.`);
|
|
655
|
+
}
|
|
656
|
+
const run = {
|
|
657
|
+
kind: "subagent",
|
|
658
|
+
id: input.id,
|
|
659
|
+
projectId: input.projectId,
|
|
660
|
+
executionId: input.executionId,
|
|
661
|
+
parentRunId: input.parentRunId,
|
|
662
|
+
spawnKey: input.spawnKey,
|
|
663
|
+
spec: clone(input.spec),
|
|
664
|
+
requesterGroupIds: clone(parent.requesterGroupIds),
|
|
665
|
+
status: "queued",
|
|
666
|
+
attempt: 0,
|
|
667
|
+
createdAt: new Date(input.createdAt ?? new Date)
|
|
668
|
+
};
|
|
669
|
+
this.state.runs.set(runKey, clone(run));
|
|
670
|
+
return clone(run);
|
|
671
|
+
}
|
|
592
672
|
async start(input) {
|
|
593
673
|
const run = this.requireStatus(input.projectId, input.id, "queued");
|
|
594
674
|
const startedAt = new Date(input.startedAt ?? new Date);
|
|
@@ -646,6 +726,12 @@ class InMemoryAgentRunStore {
|
|
|
646
726
|
if (!run.execution || run.execution.token !== input.executionToken) {
|
|
647
727
|
throw new AgentStorageError("execution_lost", `[Sixb] Execution token is no longer current on agent run '${input.id}'.`);
|
|
648
728
|
}
|
|
729
|
+
if (input.status === "succeeded" && run.kind === "subagent") {
|
|
730
|
+
assertSubagentRunResult(input.result, run.id);
|
|
731
|
+
}
|
|
732
|
+
if (input.status === "succeeded" && run.kind === "conversation" && input.result !== undefined) {
|
|
733
|
+
throw new AgentStorageError("invalid_input", `[Sixb] Conversational Agent run '${run.id}' cannot persist a subagent result.`);
|
|
734
|
+
}
|
|
649
735
|
const completedAt = new Date(input.completedAt ?? new Date);
|
|
650
736
|
const next = {
|
|
651
737
|
...run,
|
|
@@ -653,6 +739,7 @@ class InMemoryAgentRunStore {
|
|
|
653
739
|
...input.modelId === undefined ? {} : { modelId: input.modelId },
|
|
654
740
|
...input.finishReason === undefined ? {} : { finishReason: input.finishReason },
|
|
655
741
|
...input.diagnostics === undefined ? {} : { diagnostics: clone(input.diagnostics) },
|
|
742
|
+
...input.status === "succeeded" && input.result !== undefined ? { result: clone(input.result) } : {},
|
|
656
743
|
...input.status === "succeeded" || input.error === undefined ? {} : { error: normalizeFailure(input.error) },
|
|
657
744
|
execution: undefined,
|
|
658
745
|
completedAt
|
|
@@ -671,7 +758,8 @@ class InMemoryAgentRunStore {
|
|
|
671
758
|
async list(input) {
|
|
672
759
|
const order = input.order ?? "desc";
|
|
673
760
|
const statuses = input.statuses ? new Set(input.statuses) : null;
|
|
674
|
-
const
|
|
761
|
+
const kinds = input.kinds ? new Set(input.kinds) : null;
|
|
762
|
+
const filtered = [...this.state.runs.values()].filter((run) => run.projectId === input.projectId).filter((run) => kinds ? kinds.has(run.kind) : true).filter((run) => input.threadId ? run.kind === "conversation" && run.threadId === input.threadId : true).filter((run) => input.parentRunId ? run.kind === "subagent" && run.parentRunId === input.parentRunId : true).filter((run) => statuses ? statuses.has(run.status) : true).filter((run) => input.startedAfter ? (run.startedAt ?? run.createdAt) >= input.startedAfter : true).filter((run) => input.startedBefore ? (run.startedAt ?? run.createdAt) <= input.startedBefore : true).sort((a, b) => compareByDate(a.startedAt ?? a.createdAt, b.startedAt ?? b.createdAt, a.id, b.id, order));
|
|
675
763
|
const { page, hasMore, total } = applyWindow(filtered, input.offset, input.limit);
|
|
676
764
|
return { runs: page.map(clone), hasMore, total };
|
|
677
765
|
}
|
|
@@ -689,6 +777,8 @@ class InMemoryAgentRunStore {
|
|
|
689
777
|
return run;
|
|
690
778
|
}
|
|
691
779
|
releaseThread(run, completedAt) {
|
|
780
|
+
if (run.kind !== "conversation")
|
|
781
|
+
return;
|
|
692
782
|
const threadKey = key(run.projectId, run.threadId);
|
|
693
783
|
const thread = this.state.threads.get(threadKey);
|
|
694
784
|
if (thread && thread.activeRunId === run.id) {
|
|
@@ -926,9 +1016,9 @@ class InMemoryAiCostStorage {
|
|
|
926
1016
|
this.recordsByUsage.set(key2, structuredClone(record));
|
|
927
1017
|
}
|
|
928
1018
|
async summarizeExecutions(input) {
|
|
929
|
-
|
|
1019
|
+
assertNonBlank3(input.projectId, "cost summary projectId");
|
|
930
1020
|
for (const id of input.executionIds)
|
|
931
|
-
|
|
1021
|
+
assertNonBlank3(id, "cost summary executionId");
|
|
932
1022
|
const requested = new Set(input.executionIds);
|
|
933
1023
|
const usageByExecution = new Map(input.executionIds.map((id) => [id, []]));
|
|
934
1024
|
for (const usage of this.usage.snapshot().records.values()) {
|
|
@@ -947,9 +1037,32 @@ class InMemoryAiCostStorage {
|
|
|
947
1037
|
snapshot() {
|
|
948
1038
|
return structuredClone({ recordsByUsage: this.recordsByUsage });
|
|
949
1039
|
}
|
|
1040
|
+
async listModelCallGroups(input) {
|
|
1041
|
+
const items = await this.accountingItems();
|
|
1042
|
+
const roots = new Map;
|
|
1043
|
+
return buildAiModelCallGroups(input, await Promise.all(items.map(async (item) => {
|
|
1044
|
+
const key2 = usageRecordKey(item.usage.projectId, item.usage.executionId);
|
|
1045
|
+
let root = roots.get(key2);
|
|
1046
|
+
if (!root) {
|
|
1047
|
+
root = this.attribution?.resolveGroup?.({
|
|
1048
|
+
projectId: item.usage.projectId,
|
|
1049
|
+
executionId: item.usage.executionId
|
|
1050
|
+
}) ?? Promise.resolve({
|
|
1051
|
+
executionId: item.usage.executionId,
|
|
1052
|
+
attribution: item.attribution
|
|
1053
|
+
});
|
|
1054
|
+
roots.set(key2, root);
|
|
1055
|
+
}
|
|
1056
|
+
return { ...item, root: await root };
|
|
1057
|
+
})));
|
|
1058
|
+
}
|
|
950
1059
|
restore(snapshot) {
|
|
951
1060
|
replaceMap(this.recordsByUsage, snapshot.recordsByUsage);
|
|
952
1061
|
}
|
|
1062
|
+
getRecord(projectId, usageRecordId) {
|
|
1063
|
+
const record = this.recordsByUsage.get(usageRecordKey(projectId, usageRecordId));
|
|
1064
|
+
return record ? structuredClone(record) : null;
|
|
1065
|
+
}
|
|
953
1066
|
usageRecord(projectId, id) {
|
|
954
1067
|
return [...this.usage.snapshot().records.values()].find((record) => record.projectId === projectId && record.id === id);
|
|
955
1068
|
}
|
|
@@ -1000,7 +1113,7 @@ function addMoney(amounts, money) {
|
|
|
1000
1113
|
function usageRecordKey(projectId, id) {
|
|
1001
1114
|
return JSON.stringify([projectId, id]);
|
|
1002
1115
|
}
|
|
1003
|
-
function
|
|
1116
|
+
function assertNonBlank3(value, field) {
|
|
1004
1117
|
if (typeof value !== "string" || value.trim().length === 0) {
|
|
1005
1118
|
throw new TypeError(`[Sixb] AI ${field} must be nonblank.`);
|
|
1006
1119
|
}
|
|
@@ -1010,6 +1123,429 @@ function replaceMap(target, source) {
|
|
|
1010
1123
|
for (const [key2, value] of structuredClone(source))
|
|
1011
1124
|
target.set(key2, value);
|
|
1012
1125
|
}
|
|
1126
|
+
// src/storage/ai-limits/in-memory.ts
|
|
1127
|
+
class InMemoryAiLimitStorage {
|
|
1128
|
+
options;
|
|
1129
|
+
policies = new Map;
|
|
1130
|
+
policyIdsByDimension = new Map;
|
|
1131
|
+
periodStates = new Map;
|
|
1132
|
+
reservations = new Map;
|
|
1133
|
+
operations = new AiLimitOperationLock;
|
|
1134
|
+
constructor(options = {}) {
|
|
1135
|
+
this.options = options;
|
|
1136
|
+
}
|
|
1137
|
+
settleOperations() {
|
|
1138
|
+
return this.operations.settle();
|
|
1139
|
+
}
|
|
1140
|
+
async createPolicy(input) {
|
|
1141
|
+
return this.operations.run(async () => {
|
|
1142
|
+
const policy = normalizeCreateAiLimitPolicy(input);
|
|
1143
|
+
const key2 = policyKey(policy.projectId, policy.id);
|
|
1144
|
+
const dimensionKey = aiLimitPolicyDimensionKey(policy);
|
|
1145
|
+
if (this.policies.has(key2) || this.policyIdsByDimension.has(dimensionKey)) {
|
|
1146
|
+
throw new AiLimitStorageError("duplicate_policy", `[Sixb] An AI limit policy already exists for '${aiLimitSubjectKey(policy.subject)}' and '${aiLimitAmountKey(normalizeAiLimitAmount(policy.limit))}'.`);
|
|
1147
|
+
}
|
|
1148
|
+
this.policies.set(key2, structuredClone(policy));
|
|
1149
|
+
this.policyIdsByDimension.set(dimensionKey, key2);
|
|
1150
|
+
return cloneAiLimitPolicy(policy);
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
async updatePolicy(input) {
|
|
1154
|
+
return this.operations.run(async () => {
|
|
1155
|
+
const update = normalizeUpdateAiLimitPolicy(input);
|
|
1156
|
+
const key2 = policyKey(update.projectId, update.id);
|
|
1157
|
+
const existing = this.policies.get(key2);
|
|
1158
|
+
if (!existing)
|
|
1159
|
+
throw missingPolicy(update.projectId, update.id);
|
|
1160
|
+
if (update.limit !== undefined) {
|
|
1161
|
+
const previous = normalizeAiLimitAmount(existing.limit);
|
|
1162
|
+
const next = normalizeAiLimitAmount(update.limit);
|
|
1163
|
+
if (aiLimitAmountKey(previous) !== aiLimitAmountKey(next)) {
|
|
1164
|
+
throw new TypeError("[Sixb] AI limit policy meter and cost currency are immutable.");
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
const policy = {
|
|
1168
|
+
...existing,
|
|
1169
|
+
...update.limit === undefined ? {} : { limit: update.limit },
|
|
1170
|
+
...update.enabled === undefined ? {} : { enabled: update.enabled },
|
|
1171
|
+
updatedAt: update.updatedAt
|
|
1172
|
+
};
|
|
1173
|
+
this.policies.set(key2, structuredClone(policy));
|
|
1174
|
+
return cloneAiLimitPolicy(policy);
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
async deletePolicy(input) {
|
|
1178
|
+
return this.operations.run(async () => {
|
|
1179
|
+
validatePolicyIdentity(input);
|
|
1180
|
+
const key2 = policyKey(input.projectId, input.id);
|
|
1181
|
+
const existing = this.policies.get(key2);
|
|
1182
|
+
if (!existing)
|
|
1183
|
+
return false;
|
|
1184
|
+
this.policies.delete(key2);
|
|
1185
|
+
this.policyIdsByDimension.delete(aiLimitPolicyDimensionKey(existing));
|
|
1186
|
+
return true;
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
async getPolicy(input) {
|
|
1190
|
+
validatePolicyIdentity(input);
|
|
1191
|
+
const policy = this.policies.get(policyKey(input.projectId, input.id));
|
|
1192
|
+
return policy ? cloneAiLimitPolicy(policy) : null;
|
|
1193
|
+
}
|
|
1194
|
+
async listPolicies(input) {
|
|
1195
|
+
assertNonBlank(input.projectId, "projectId");
|
|
1196
|
+
return [...this.policies.values()].filter((policy) => policy.projectId === input.projectId && (input.includeDisabled || policy.enabled)).sort((left, right) => left.id.localeCompare(right.id)).map(cloneAiLimitPolicy);
|
|
1197
|
+
}
|
|
1198
|
+
async listPolicyStatuses(input) {
|
|
1199
|
+
return this.operations.run(async () => {
|
|
1200
|
+
assertNonBlank(input.projectId, "projectId");
|
|
1201
|
+
const period = aiLimitCalendarMonth(input.at ?? new Date);
|
|
1202
|
+
const existingGroups = input.existingGroupIds === undefined ? undefined : new Set(input.existingGroupIds);
|
|
1203
|
+
const policies = await this.listPolicies({
|
|
1204
|
+
projectId: input.projectId,
|
|
1205
|
+
includeDisabled: input.includeDisabled
|
|
1206
|
+
});
|
|
1207
|
+
return Promise.all(policies.map((policy) => this.policyStatus(policy, period, existingGroups)));
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
async reserveModelCall(input) {
|
|
1211
|
+
return this.operations.run(async () => {
|
|
1212
|
+
const request = normalizeReserveAiModelCall(input);
|
|
1213
|
+
const reservationKey = aiModelCallReservationKey(request.identity);
|
|
1214
|
+
const existing = this.reservations.get(reservationKey);
|
|
1215
|
+
if (existing) {
|
|
1216
|
+
if (!aiLimitReservationRequestMatches(existing, request)) {
|
|
1217
|
+
throw new AiLimitStorageError("reservation_conflict", `[Sixb] AI model-call reservation '${input.callId}' was replayed with different subjects, estimates, or period.`);
|
|
1218
|
+
}
|
|
1219
|
+
if (existing.state !== "active") {
|
|
1220
|
+
return { status: "terminal", reservation: structuredClone(existing), created: false };
|
|
1221
|
+
}
|
|
1222
|
+
return { status: "reserved", reservation: structuredClone(existing), created: false };
|
|
1223
|
+
}
|
|
1224
|
+
await this.assertExecutionExists(request.identity.projectId, request.identity.executionId);
|
|
1225
|
+
const enabledPolicies = [...this.policies.values()].filter((policy) => policy.projectId === request.identity.projectId && policy.enabled);
|
|
1226
|
+
const subjectKeys = new Set(request.subjects.map(aiLimitSubjectKey));
|
|
1227
|
+
const estimates = new Map(request.estimates.map((quantity) => {
|
|
1228
|
+
const amount = normalizeAiLimitAmount(quantity);
|
|
1229
|
+
return [aiLimitAmountKey(amount), amount];
|
|
1230
|
+
}));
|
|
1231
|
+
const exhaustedPolicies = [];
|
|
1232
|
+
const unavailablePolicies = [];
|
|
1233
|
+
const unavailableReasons = new Set;
|
|
1234
|
+
for (const policy of enabledPolicies) {
|
|
1235
|
+
if (!subjectKeys.has(aiLimitSubjectKey(policy.subject)))
|
|
1236
|
+
continue;
|
|
1237
|
+
const limit = normalizeAiLimitAmount(policy.limit);
|
|
1238
|
+
const estimate = estimates.get(aiLimitAmountKey(limit));
|
|
1239
|
+
const status = await this.policyStatus(policy, request.period);
|
|
1240
|
+
if (!estimate || status.accountingStatus === "unavailable") {
|
|
1241
|
+
unavailablePolicies.push(status);
|
|
1242
|
+
if (!estimate)
|
|
1243
|
+
unavailableReasons.add("missingEstimate");
|
|
1244
|
+
if (status.accountingStatus === "unavailable") {
|
|
1245
|
+
unavailableReasons.add("incompleteAccounting");
|
|
1246
|
+
}
|
|
1247
|
+
continue;
|
|
1248
|
+
}
|
|
1249
|
+
const actual = normalizeAiLimitAmount(status.consumption.actual).amount;
|
|
1250
|
+
const reserved = normalizeAiLimitAmount(status.consumption.reserved).amount;
|
|
1251
|
+
const unknown = normalizeAiLimitAmount(status.consumption.unknown).amount;
|
|
1252
|
+
if (actual + reserved + unknown + estimate.amount > limit.amount) {
|
|
1253
|
+
exhaustedPolicies.push(status);
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
if (unavailablePolicies.length > 0) {
|
|
1257
|
+
unavailablePolicies.sort((left, right) => left.policy.id.localeCompare(right.policy.id));
|
|
1258
|
+
return {
|
|
1259
|
+
status: "unavailable",
|
|
1260
|
+
unavailablePolicies,
|
|
1261
|
+
reasons: [...unavailableReasons].sort()
|
|
1262
|
+
};
|
|
1263
|
+
}
|
|
1264
|
+
if (exhaustedPolicies.length > 0) {
|
|
1265
|
+
exhaustedPolicies.sort((left, right) => left.policy.id.localeCompare(right.policy.id));
|
|
1266
|
+
return {
|
|
1267
|
+
status: "denied",
|
|
1268
|
+
exhaustedPolicies,
|
|
1269
|
+
resetAt: new Date(Math.min(...exhaustedPolicies.map((status) => status.period.resetAt.getTime())))
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1272
|
+
const buckets = aiLimitReservationBuckets(enabledPolicies, request.subjects, request.estimates);
|
|
1273
|
+
if (buckets.length === 0)
|
|
1274
|
+
return { status: "notRequired" };
|
|
1275
|
+
for (const bucket of buckets) {
|
|
1276
|
+
const amount = normalizeAiLimitAmount(bucket.estimate);
|
|
1277
|
+
const state = this.requirePeriodState(request.identity.projectId, bucket.subject, amount, request.period);
|
|
1278
|
+
state.reserved += amount.amount;
|
|
1279
|
+
state.updatedAt = new Date(request.reservedAt);
|
|
1280
|
+
}
|
|
1281
|
+
const reservation = {
|
|
1282
|
+
...request.identity,
|
|
1283
|
+
buckets,
|
|
1284
|
+
requestKey: aiLimitReservationRequestKey(request),
|
|
1285
|
+
period: request.period,
|
|
1286
|
+
state: "active",
|
|
1287
|
+
reservedAt: request.reservedAt,
|
|
1288
|
+
updatedAt: new Date(request.reservedAt)
|
|
1289
|
+
};
|
|
1290
|
+
this.reservations.set(reservationKey, structuredClone(reservation));
|
|
1291
|
+
return { status: "reserved", reservation: structuredClone(reservation), created: true };
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
async recordModelCallActuals(input) {
|
|
1295
|
+
return this.operations.run(async () => {
|
|
1296
|
+
assertNonBlank(input.projectId, "projectId");
|
|
1297
|
+
assertNonBlank(input.usageRecordId, "usageRecordId");
|
|
1298
|
+
const recordedAt = cloneValidDate(input.recordedAt ?? new Date, "recordedAt");
|
|
1299
|
+
const entry = await this.requireAccountingEntry(input.projectId, input.usageRecordId);
|
|
1300
|
+
const period = aiLimitCalendarMonth(entry.occurredAt);
|
|
1301
|
+
const subjectKeys = new Set(aiLimitSubjectsFromAccountingEntry(entry).map(aiLimitSubjectKey));
|
|
1302
|
+
for (const state of this.periodStates.values()) {
|
|
1303
|
+
if (state.projectId !== input.projectId || state.period.start.getTime() !== period.start.getTime() || !subjectKeys.has(aiLimitSubjectKey(state.subject))) {
|
|
1304
|
+
continue;
|
|
1305
|
+
}
|
|
1306
|
+
const actual = resolveAiLimitActual([entry], state);
|
|
1307
|
+
state.actual += actual.amount;
|
|
1308
|
+
if (actual.accountingStatus === "unavailable")
|
|
1309
|
+
state.accountingStatus = "unavailable";
|
|
1310
|
+
state.updatedAt = new Date(recordedAt);
|
|
1311
|
+
}
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
async reconcileModelCall(input) {
|
|
1315
|
+
return this.operations.run(async () => {
|
|
1316
|
+
const identity = normalizeAiModelCallReservationIdentity(input);
|
|
1317
|
+
assertNonBlank(input.usageRecordId, "usageRecordId");
|
|
1318
|
+
const reconciledAt = cloneValidDate(input.reconciledAt ?? new Date, "reconciledAt");
|
|
1319
|
+
const key2 = aiModelCallReservationKey(identity);
|
|
1320
|
+
const reservation = this.reservations.get(key2);
|
|
1321
|
+
if (!reservation)
|
|
1322
|
+
throw missingReservation(identity);
|
|
1323
|
+
if (reservation.state === "reconciled") {
|
|
1324
|
+
if (reservation.usageRecordId === input.usageRecordId) {
|
|
1325
|
+
return structuredClone(reservation);
|
|
1326
|
+
}
|
|
1327
|
+
throw new AiLimitStorageError("reconciliation_conflict", `[Sixb] AI model-call reservation '${identity.callId}' was reconciled with a different usage record.`);
|
|
1328
|
+
}
|
|
1329
|
+
const accounting = await this.requireAccountingEntry(identity.projectId, input.usageRecordId);
|
|
1330
|
+
assertAiLimitAccountingMatchesReservation(reservation, accounting);
|
|
1331
|
+
this.reconcileEstimateCounters(reservation, accounting, reconciledAt);
|
|
1332
|
+
const reconciled = {
|
|
1333
|
+
...reservation,
|
|
1334
|
+
state: "reconciled",
|
|
1335
|
+
usageRecordId: input.usageRecordId,
|
|
1336
|
+
updatedAt: reconciledAt
|
|
1337
|
+
};
|
|
1338
|
+
this.reservations.set(key2, structuredClone(reconciled));
|
|
1339
|
+
return structuredClone(reconciled);
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
async markReservationUnknown(input) {
|
|
1343
|
+
return this.operations.run(async () => {
|
|
1344
|
+
const identity = normalizeAiModelCallReservationIdentity(input);
|
|
1345
|
+
const markedAt = cloneValidDate(input.markedAt ?? new Date, "markedAt");
|
|
1346
|
+
const key2 = aiModelCallReservationKey(identity);
|
|
1347
|
+
const reservation = this.reservations.get(key2);
|
|
1348
|
+
if (!reservation)
|
|
1349
|
+
throw missingReservation(identity);
|
|
1350
|
+
if (reservation.state === "unknown")
|
|
1351
|
+
return structuredClone(reservation);
|
|
1352
|
+
if (reservation.state !== "active")
|
|
1353
|
+
throw invalidState(reservation, "mark unknown");
|
|
1354
|
+
this.moveEstimateCounter(reservation, "reserved", -1n, markedAt);
|
|
1355
|
+
this.moveEstimateCounter(reservation, "unknown", 1n, markedAt);
|
|
1356
|
+
const unknown = {
|
|
1357
|
+
...reservation,
|
|
1358
|
+
state: "unknown",
|
|
1359
|
+
updatedAt: markedAt
|
|
1360
|
+
};
|
|
1361
|
+
this.reservations.set(key2, structuredClone(unknown));
|
|
1362
|
+
return structuredClone(unknown);
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
snapshot() {
|
|
1366
|
+
return structuredClone({
|
|
1367
|
+
policies: this.policies,
|
|
1368
|
+
policyIdsByDimension: this.policyIdsByDimension,
|
|
1369
|
+
periodStates: this.periodStates,
|
|
1370
|
+
reservations: this.reservations
|
|
1371
|
+
});
|
|
1372
|
+
}
|
|
1373
|
+
restore(snapshot) {
|
|
1374
|
+
replaceMap2(this.policies, snapshot.policies);
|
|
1375
|
+
replaceMap2(this.policyIdsByDimension, snapshot.policyIdsByDimension);
|
|
1376
|
+
replaceMap2(this.periodStates, snapshot.periodStates);
|
|
1377
|
+
replaceMap2(this.reservations, snapshot.reservations);
|
|
1378
|
+
}
|
|
1379
|
+
async policyStatus(policy, period, existingGroups) {
|
|
1380
|
+
const limit = normalizeAiLimitAmount(policy.limit);
|
|
1381
|
+
const state = await this.ensurePeriodState(policy, period);
|
|
1382
|
+
const reserved = state.reserved;
|
|
1383
|
+
const unknown = state.unknown;
|
|
1384
|
+
const consumed = state.actual + reserved + unknown;
|
|
1385
|
+
const remaining = limit.amount > consumed ? limit.amount - consumed : 0n;
|
|
1386
|
+
const quantity = (amount) => aiLimitQuantityFromAmount({ ...limit, amount });
|
|
1387
|
+
return {
|
|
1388
|
+
policy: cloneAiLimitPolicy(policy),
|
|
1389
|
+
period: structuredClone(period),
|
|
1390
|
+
consumption: {
|
|
1391
|
+
actual: quantity(state.actual),
|
|
1392
|
+
reserved: quantity(reserved),
|
|
1393
|
+
unknown: quantity(unknown),
|
|
1394
|
+
remaining: quantity(remaining)
|
|
1395
|
+
},
|
|
1396
|
+
accountingStatus: state.accountingStatus,
|
|
1397
|
+
exhausted: consumed >= limit.amount,
|
|
1398
|
+
orphaned: policy.subject.type === "group" && existingGroups !== undefined && !existingGroups.has(policy.subject.id)
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
async ensurePeriodState(policy, period) {
|
|
1402
|
+
const amount = normalizeAiLimitAmount(policy.limit);
|
|
1403
|
+
const key2 = periodStateKey(policy.projectId, policy.subject, amount, period);
|
|
1404
|
+
const existing = this.periodStates.get(key2);
|
|
1405
|
+
if (existing?.accountingStatus === "complete")
|
|
1406
|
+
return existing;
|
|
1407
|
+
const actual = await this.resolvePolicyActual(policy, period, amount);
|
|
1408
|
+
if (existing) {
|
|
1409
|
+
existing.actual = actual.amount;
|
|
1410
|
+
existing.accountingStatus = actual.accountingStatus;
|
|
1411
|
+
existing.updatedAt = new Date;
|
|
1412
|
+
return existing;
|
|
1413
|
+
}
|
|
1414
|
+
const state = {
|
|
1415
|
+
projectId: policy.projectId,
|
|
1416
|
+
subject: structuredClone(policy.subject),
|
|
1417
|
+
meter: amount.meter,
|
|
1418
|
+
currency: amount.currency,
|
|
1419
|
+
period: structuredClone(period),
|
|
1420
|
+
actual: actual.amount,
|
|
1421
|
+
reserved: 0n,
|
|
1422
|
+
unknown: 0n,
|
|
1423
|
+
accountingStatus: actual.accountingStatus,
|
|
1424
|
+
updatedAt: new Date
|
|
1425
|
+
};
|
|
1426
|
+
this.periodStates.set(key2, state);
|
|
1427
|
+
return state;
|
|
1428
|
+
}
|
|
1429
|
+
moveEstimateCounter(reservation, counter, direction, updatedAt) {
|
|
1430
|
+
for (const bucket of reservation.buckets) {
|
|
1431
|
+
const amount = normalizeAiLimitAmount(bucket.estimate);
|
|
1432
|
+
const state = this.requirePeriodState(reservation.projectId, bucket.subject, amount, reservation.period);
|
|
1433
|
+
state[counter] += direction * amount.amount;
|
|
1434
|
+
if (state[counter] < 0n) {
|
|
1435
|
+
throw new Error(`[Sixb] In-memory AI limit ${counter} counter became negative.`);
|
|
1436
|
+
}
|
|
1437
|
+
state.updatedAt = new Date(updatedAt);
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
reconcileEstimateCounters(reservation, entry, updatedAt) {
|
|
1441
|
+
for (const bucket of reservation.buckets) {
|
|
1442
|
+
const amount = normalizeAiLimitAmount(bucket.estimate);
|
|
1443
|
+
const state = this.requirePeriodState(reservation.projectId, bucket.subject, amount, reservation.period);
|
|
1444
|
+
const counter = reservation.state === "active" ? "reserved" : "unknown";
|
|
1445
|
+
const actual = resolveAiLimitActual([entry], amount);
|
|
1446
|
+
if (actual.accountingStatus === "complete") {
|
|
1447
|
+
state[counter] -= amount.amount;
|
|
1448
|
+
} else if (reservation.state === "active") {
|
|
1449
|
+
state.reserved -= amount.amount;
|
|
1450
|
+
state.unknown += amount.amount;
|
|
1451
|
+
}
|
|
1452
|
+
if (state.reserved < 0n || state.unknown < 0n) {
|
|
1453
|
+
throw new Error("[Sixb] In-memory AI limit reservation counter became negative.");
|
|
1454
|
+
}
|
|
1455
|
+
state.updatedAt = new Date(updatedAt);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
requirePeriodState(projectId, subject, amount, period) {
|
|
1459
|
+
const state = this.periodStates.get(periodStateKey(projectId, subject, amount, period));
|
|
1460
|
+
if (!state)
|
|
1461
|
+
throw new Error("[Sixb] In-memory AI limit period state is inconsistent.");
|
|
1462
|
+
return state;
|
|
1463
|
+
}
|
|
1464
|
+
async assertExecutionExists(projectId, executionId) {
|
|
1465
|
+
if (this.options.resolveExecution) {
|
|
1466
|
+
if (await this.options.resolveExecution({ projectId, executionId }))
|
|
1467
|
+
return;
|
|
1468
|
+
throw new AiLimitStorageError("missing_execution", `[Sixb] AI limit execution '${executionId}' does not exist in project '${projectId}'.`);
|
|
1469
|
+
}
|
|
1470
|
+
if (this.options.executionExists && await this.options.executionExists({ projectId, executionId })) {
|
|
1471
|
+
return;
|
|
1472
|
+
}
|
|
1473
|
+
throw new AiLimitStorageError("missing_execution", `[Sixb] AI limit execution '${executionId}' does not exist in project '${projectId}'.`);
|
|
1474
|
+
}
|
|
1475
|
+
async resolvePolicyActual(policy, period, dimension) {
|
|
1476
|
+
if (!this.options.listUsageRecords || (policy.subject.type === "user" || policy.subject.type === "serviceAccount") && !this.options.resolveExecution) {
|
|
1477
|
+
return { amount: 0n, accountingStatus: "unavailable" };
|
|
1478
|
+
}
|
|
1479
|
+
const records = await this.options.listUsageRecords({ projectId: policy.projectId });
|
|
1480
|
+
const entries = await Promise.all(records.filter((record) => record.occurredAt.getTime() >= period.start.getTime() && record.occurredAt.getTime() < period.end.getTime()).map((record) => this.accountingEntry(record)));
|
|
1481
|
+
return resolveAiLimitActual(entries.filter((entry) => aiLimitAccountingEntryAppliesToSubject(entry, policy.subject)), dimension);
|
|
1482
|
+
}
|
|
1483
|
+
async requireAccountingEntry(projectId, usageRecordId) {
|
|
1484
|
+
if (!this.options.resolveUsageRecord) {
|
|
1485
|
+
throw new AiLimitStorageError("unavailable_actuals", "[Sixb] In-memory AI limit storage has no immutable accounting source.");
|
|
1486
|
+
}
|
|
1487
|
+
const record = await this.options.resolveUsageRecord({ projectId, usageRecordId });
|
|
1488
|
+
if (!record) {
|
|
1489
|
+
throw new AiLimitStorageError("missing_usage_record", `[Sixb] AI usage record '${usageRecordId}' does not exist in project '${projectId}'.`);
|
|
1490
|
+
}
|
|
1491
|
+
return this.accountingEntry(record);
|
|
1492
|
+
}
|
|
1493
|
+
async accountingEntry(record) {
|
|
1494
|
+
const [execution, cost] = await Promise.all([
|
|
1495
|
+
this.options.resolveExecution?.({
|
|
1496
|
+
projectId: record.projectId,
|
|
1497
|
+
executionId: record.executionId
|
|
1498
|
+
}),
|
|
1499
|
+
this.options.resolveCostRecord?.({
|
|
1500
|
+
projectId: record.projectId,
|
|
1501
|
+
usageRecordId: record.id
|
|
1502
|
+
})
|
|
1503
|
+
]);
|
|
1504
|
+
const requester = execution?.requestedBy;
|
|
1505
|
+
return {
|
|
1506
|
+
projectId: record.projectId,
|
|
1507
|
+
usageRecordId: record.id,
|
|
1508
|
+
executionId: record.executionId,
|
|
1509
|
+
attempt: record.attempt,
|
|
1510
|
+
callId: record.callId,
|
|
1511
|
+
occurredAt: new Date(record.occurredAt),
|
|
1512
|
+
...record.usage.totalTokens === undefined ? {} : { totalTokens: record.usage.totalTokens },
|
|
1513
|
+
requesterGroupIds: [...record.requesterGroupIds],
|
|
1514
|
+
...requester?.type === "user" || requester?.type === "serviceAccount" ? { requester: { type: requester.type, id: requester.id } } : {},
|
|
1515
|
+
...cost?.status === "rated" ? { valuation: { status: "rated", money: structuredClone(cost.money) } } : cost ? { valuation: { status: "unavailable" } } : {}
|
|
1516
|
+
};
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
function policyKey(projectId, id) {
|
|
1520
|
+
return JSON.stringify([projectId, id]);
|
|
1521
|
+
}
|
|
1522
|
+
function periodStateKey(projectId, subject, amount, period) {
|
|
1523
|
+
return JSON.stringify([
|
|
1524
|
+
projectId,
|
|
1525
|
+
aiLimitSubjectKey(subject),
|
|
1526
|
+
amount.meter,
|
|
1527
|
+
amount.currency,
|
|
1528
|
+
period.start.toISOString()
|
|
1529
|
+
]);
|
|
1530
|
+
}
|
|
1531
|
+
function validatePolicyIdentity(input) {
|
|
1532
|
+
assertNonBlank(input.projectId, "projectId");
|
|
1533
|
+
assertNonBlank(input.id, "policy id");
|
|
1534
|
+
}
|
|
1535
|
+
function missingPolicy(projectId, id) {
|
|
1536
|
+
return new AiLimitStorageError("missing_policy", `[Sixb] AI limit policy '${id}' does not exist in project '${projectId}'.`);
|
|
1537
|
+
}
|
|
1538
|
+
function missingReservation(identity) {
|
|
1539
|
+
return new AiLimitStorageError("missing_reservation", `[Sixb] AI model-call reservation '${identity.callId}' does not exist for execution '${identity.executionId}' attempt ${identity.attempt}.`);
|
|
1540
|
+
}
|
|
1541
|
+
function invalidState(reservation, operation) {
|
|
1542
|
+
return new AiLimitStorageError("invalid_reservation_state", `[Sixb] Cannot ${operation} AI model-call reservation '${reservation.callId}' in state '${reservation.state}'.`);
|
|
1543
|
+
}
|
|
1544
|
+
function replaceMap2(target, source) {
|
|
1545
|
+
target.clear();
|
|
1546
|
+
for (const [key2, value] of structuredClone(source))
|
|
1547
|
+
target.set(key2, value);
|
|
1548
|
+
}
|
|
1013
1549
|
// src/storage/connector-connections/in-memory.ts
|
|
1014
1550
|
import { timingSafeEqual } from "crypto";
|
|
1015
1551
|
function connectionRunBase(record, updatedAt) {
|
|
@@ -1699,10 +2235,10 @@ class InMemoryConnectorConnectionStorage {
|
|
|
1699
2235
|
};
|
|
1700
2236
|
}
|
|
1701
2237
|
restore(snapshot) {
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
2238
|
+
replaceMap3(this.attempts, snapshot.attempts);
|
|
2239
|
+
replaceMap3(this.connectionRuns, snapshot.connectionRuns);
|
|
2240
|
+
replaceMap3(this.authorizations, snapshot.authorizations);
|
|
2241
|
+
replaceMap3(this.connections, snapshot.connections);
|
|
1706
2242
|
}
|
|
1707
2243
|
now() {
|
|
1708
2244
|
return new Date(this.options.now?.() ?? new Date);
|
|
@@ -1803,7 +2339,7 @@ function safeEqual(left, right) {
|
|
|
1803
2339
|
function invalidRun() {
|
|
1804
2340
|
return new ConnectorConnectionStorageError("run_invalid", "[Sixb] Connector connection run is invalid, expired, or already used.");
|
|
1805
2341
|
}
|
|
1806
|
-
function
|
|
2342
|
+
function replaceMap3(target, source) {
|
|
1807
2343
|
target.clear();
|
|
1808
2344
|
for (const [key2, value] of structuredClone(source))
|
|
1809
2345
|
target.set(key2, value);
|
|
@@ -6261,7 +6797,9 @@ function compareRequestedAt(left, right, order) {
|
|
|
6261
6797
|
var WORKFLOW_RUN_FAILURE_CODES = [
|
|
6262
6798
|
"internal.unexpected",
|
|
6263
6799
|
"runtime.cancelled",
|
|
6264
|
-
"workflow.node_failed"
|
|
6800
|
+
"workflow.node_failed",
|
|
6801
|
+
"ai.usage_limit_exceeded",
|
|
6802
|
+
"ai.usage_limit_unavailable"
|
|
6265
6803
|
];
|
|
6266
6804
|
|
|
6267
6805
|
// src/storage/workflow-runs/in-memory.ts
|
|
@@ -6670,7 +7208,7 @@ class InMemoryWorkflowAgentNodeRunStorage {
|
|
|
6670
7208
|
projectId: input.projectId,
|
|
6671
7209
|
executionId: input.executionId,
|
|
6672
7210
|
nodeRunId: input.nodeRunId,
|
|
6673
|
-
|
|
7211
|
+
actorId: input.actorId,
|
|
6674
7212
|
workflowExecutionId: workflowRun.executionId
|
|
6675
7213
|
});
|
|
6676
7214
|
if (node.status !== "running") {
|
|
@@ -6687,7 +7225,7 @@ class InMemoryWorkflowAgentNodeRunStorage {
|
|
|
6687
7225
|
projectId: input.projectId,
|
|
6688
7226
|
nodeRunId: input.nodeRunId,
|
|
6689
7227
|
executionId: input.executionId,
|
|
6690
|
-
|
|
7228
|
+
actorId: input.actorId,
|
|
6691
7229
|
status: "queued",
|
|
6692
7230
|
prompt: input.prompt,
|
|
6693
7231
|
attempt: 0,
|
|
@@ -6756,7 +7294,7 @@ class InMemoryWorkflowAgentNodeRunStorage {
|
|
|
6756
7294
|
async list(input) {
|
|
6757
7295
|
const statuses = input.statuses ? new Set(input.statuses) : null;
|
|
6758
7296
|
const order = input.order ?? "desc";
|
|
6759
|
-
const filtered = [...this.runs.values()].filter((run) => run.projectId === input.projectId).filter((run) => input.
|
|
7297
|
+
const filtered = [...this.runs.values()].filter((run) => run.projectId === input.projectId).filter((run) => input.actorId ? run.actorId === input.actorId : true).filter((run) => statuses ? statuses.has(run.status) : true).sort((a, b) => order === "asc" ? a.createdAt.getTime() - b.createdAt.getTime() : b.createdAt.getTime() - a.createdAt.getTime());
|
|
6760
7298
|
const { page, total, hasMore } = paginate(filtered, input);
|
|
6761
7299
|
return { runs: page.map(cloneRecord), total, hasMore };
|
|
6762
7300
|
}
|
|
@@ -6807,7 +7345,31 @@ class InMemoryStorage {
|
|
|
6807
7345
|
agentStorage = new InMemoryAgentStorage(this.executionStorage);
|
|
6808
7346
|
aiUsageStorage = new InMemoryAiUsageStorage(this.executionStorage);
|
|
6809
7347
|
aiCostStorage = new InMemoryAiCostStorage(this.aiUsageStorage, {
|
|
6810
|
-
resolve: (input) => this.resolveAiAccountingAttribution(input)
|
|
7348
|
+
resolve: (input) => this.resolveAiAccountingAttribution(input),
|
|
7349
|
+
resolveGroup: async (input) => {
|
|
7350
|
+
const attribution = await this.resolveAiAccountingAttribution(input);
|
|
7351
|
+
if (attribution?.kind !== "subagent")
|
|
7352
|
+
return { executionId: input.executionId, attribution };
|
|
7353
|
+
const parent = await this.agentStorage.runs.getById({
|
|
7354
|
+
projectId: input.projectId,
|
|
7355
|
+
id: attribution.parentRunId
|
|
7356
|
+
});
|
|
7357
|
+
if (!parent)
|
|
7358
|
+
throw new Error("[Sixb] Subagent accounting parent is missing.");
|
|
7359
|
+
return {
|
|
7360
|
+
executionId: parent.executionId,
|
|
7361
|
+
attribution: await this.resolveAiAccountingAttribution({
|
|
7362
|
+
...input,
|
|
7363
|
+
executionId: parent.executionId
|
|
7364
|
+
})
|
|
7365
|
+
};
|
|
7366
|
+
}
|
|
7367
|
+
});
|
|
7368
|
+
aiLimitStorage = new InMemoryAiLimitStorage({
|
|
7369
|
+
resolveExecution: ({ projectId, executionId }) => this.executionStorage.getById({ projectId, id: executionId }),
|
|
7370
|
+
resolveUsageRecord: ({ projectId, usageRecordId }) => this.aiUsageStorage.getRecord(projectId, usageRecordId),
|
|
7371
|
+
resolveCostRecord: ({ projectId, usageRecordId }) => this.aiCostStorage.getRecord(projectId, usageRecordId),
|
|
7372
|
+
listUsageRecords: ({ projectId }) => this.aiUsageStorage.listRecords(projectId)
|
|
6811
7373
|
});
|
|
6812
7374
|
actionRunStorage = new InMemoryActionRunStorage(this.executionStorage);
|
|
6813
7375
|
syncRunStorage = new InMemorySyncRunStorage(this.executionStorage);
|
|
@@ -6826,6 +7388,7 @@ class InMemoryStorage {
|
|
|
6826
7388
|
agents;
|
|
6827
7389
|
aiUsage;
|
|
6828
7390
|
aiCosts;
|
|
7391
|
+
aiLimits;
|
|
6829
7392
|
actionRuns;
|
|
6830
7393
|
syncRuns;
|
|
6831
7394
|
pipelineRuns;
|
|
@@ -6846,6 +7409,7 @@ class InMemoryStorage {
|
|
|
6846
7409
|
this.agents = createAgentOperationScope(this.agentStorage, scope);
|
|
6847
7410
|
this.aiUsage = createOperationScopedFacade(this.aiUsageStorage, scope);
|
|
6848
7411
|
this.aiCosts = createOperationScopedFacade(this.aiCostStorage, scope);
|
|
7412
|
+
this.aiLimits = createOperationScopedFacade(this.aiLimitStorage, scope);
|
|
6849
7413
|
this.actionRuns = createOperationScopedFacade(this.actionRunStorage, scope);
|
|
6850
7414
|
this.syncRuns = createOperationScopedFacade(this.syncRunStorage, scope);
|
|
6851
7415
|
this.pipelineRuns = createOperationScopedFacade(this.pipelineRunStorage, scope);
|
|
@@ -6878,14 +7442,20 @@ class InMemoryStorage {
|
|
|
6878
7442
|
projectId: input.projectId,
|
|
6879
7443
|
id: execution.executor.runId
|
|
6880
7444
|
});
|
|
6881
|
-
if (directRun) {
|
|
7445
|
+
if (directRun?.kind === "conversation") {
|
|
6882
7446
|
return {
|
|
6883
7447
|
kind: "agent",
|
|
6884
|
-
agentId: directRun.agentId,
|
|
6885
7448
|
agentRunId: directRun.id,
|
|
6886
7449
|
threadId: directRun.threadId
|
|
6887
7450
|
};
|
|
6888
7451
|
}
|
|
7452
|
+
if (directRun?.kind === "subagent") {
|
|
7453
|
+
return {
|
|
7454
|
+
kind: "subagent",
|
|
7455
|
+
subagentRunId: directRun.id,
|
|
7456
|
+
parentRunId: directRun.parentRunId
|
|
7457
|
+
};
|
|
7458
|
+
}
|
|
6889
7459
|
const agentRun = await this.workflowRunStorage.agentNodes.getByNodeRunId({
|
|
6890
7460
|
projectId: input.projectId,
|
|
6891
7461
|
nodeRunId: execution.executor.runId
|
|
@@ -6900,7 +7470,7 @@ class InMemoryStorage {
|
|
|
6900
7470
|
return;
|
|
6901
7471
|
return {
|
|
6902
7472
|
kind: "workflowAgent",
|
|
6903
|
-
|
|
7473
|
+
agentStepId: node.nodeId,
|
|
6904
7474
|
nodeRunId: agentRun.nodeRunId,
|
|
6905
7475
|
workflowId: node.workflowId,
|
|
6906
7476
|
workflowRunId: node.workflowRunId
|
|
@@ -6929,7 +7499,13 @@ class InMemoryStorage {
|
|
|
6929
7499
|
this.activeTransactionTokens.add(transactionToken);
|
|
6930
7500
|
this.materializationLifecycles.set(transactionToken, materializationLifecycle);
|
|
6931
7501
|
try {
|
|
6932
|
-
const result = await this.transactionScope.run(transactionToken, async () =>
|
|
7502
|
+
const result = await this.transactionScope.run(transactionToken, async () => {
|
|
7503
|
+
try {
|
|
7504
|
+
return await run(tx);
|
|
7505
|
+
} finally {
|
|
7506
|
+
await this.aiLimitStorage.settleOperations();
|
|
7507
|
+
}
|
|
7508
|
+
});
|
|
6933
7509
|
materializationLifecycle.assertCommittable();
|
|
6934
7510
|
return result;
|
|
6935
7511
|
} catch (error) {
|
|
@@ -6987,6 +7563,7 @@ class InMemoryStorage {
|
|
|
6987
7563
|
agents: this.agentStorage,
|
|
6988
7564
|
aiUsage: this.aiUsageStorage,
|
|
6989
7565
|
aiCosts: this.aiCostStorage,
|
|
7566
|
+
aiLimits: this.aiLimitStorage,
|
|
6990
7567
|
actionRuns: this.actionRunStorage,
|
|
6991
7568
|
syncRuns: this.syncRunStorage,
|
|
6992
7569
|
pipelineRuns: this.pipelineRunStorage,
|
|
@@ -7015,6 +7592,7 @@ class InMemoryStorage {
|
|
|
7015
7592
|
agents: this.agentStorage.snapshot(),
|
|
7016
7593
|
aiUsage: this.aiUsageStorage.snapshot(),
|
|
7017
7594
|
aiCosts: this.aiCostStorage.snapshot(),
|
|
7595
|
+
aiLimits: this.aiLimitStorage.snapshot(),
|
|
7018
7596
|
actionRuns: this.actionRunStorage.snapshot(),
|
|
7019
7597
|
syncRuns: this.syncRunStorage.snapshot(),
|
|
7020
7598
|
pipelineRuns: this.pipelineRunStorage.snapshot(),
|
|
@@ -7036,6 +7614,7 @@ class InMemoryStorage {
|
|
|
7036
7614
|
this.agentStorage.restore(snapshot.agents);
|
|
7037
7615
|
this.aiUsageStorage.restore(snapshot.aiUsage);
|
|
7038
7616
|
this.aiCostStorage.restore(snapshot.aiCosts);
|
|
7617
|
+
this.aiLimitStorage.restore(snapshot.aiLimits);
|
|
7039
7618
|
this.actionRunStorage.restore(snapshot.actionRuns);
|
|
7040
7619
|
this.syncRunStorage.restore(snapshot.syncRuns);
|
|
7041
7620
|
this.pipelineRunStorage.restore(snapshot.pipelineRuns);
|
|
@@ -7257,6 +7836,6 @@ function assertAppliedPrefix(migrations, rows) {
|
|
|
7257
7836
|
}
|
|
7258
7837
|
return [...rows].sort((a, b) => a.version - b.version);
|
|
7259
7838
|
}
|
|
7260
|
-
export { actionSubjectsEqual, actionRunParamsEqual, actionRunPhaseRecordsEqual, finishActionRunPhase, canRequeueActionRunAfterEnqueueFailure, isTerminalActionRun, InMemoryActionRunStorage, AGENT_MESSAGE_CONTENT_VERSION, InMemoryAgentStorage, AiCostStorageError, InMemoryAiCostStorage, InMemoryConnectorConnectionStorage, ObjectNotFoundError, ObjectStorageError, StorageTransactionError, isStorageSerializationFailure, FileUploadSessionError, DEFAULT_FILE_UPLOAD_SESSION_TTL_MS, DEFAULT_FILE_UPLOAD_TERMINAL_SESSION_TTL_MS, createUploadExpiresAt, createFileUploadId, InMemoryFileUploadSessions, compareQueryScalarValues, queryScalarValuesEqual, objectBatchKey, linkBatchKey, objectLinkCursor, canRequeuePipelineRunAfterEnqueueFailure, PIPELINE_RUN_FAILURE_CODES, InMemoryPipelineRunStorage, InMemoryProjectionRunStorage, InMemoryRulesStorage, canRequeueSyncRunAfterEnqueueFailure, SYNC_RUN_FAILURE_CODES, InMemorySyncRunStorage, createTransactionStorageProxy, assertTransactionActive, throwNestedStorageTransaction, WEBHOOK_RUN_FAILURE_CODES, canRetryWebhookRun, InMemoryWebhookRunStorage, WorkflowInterventionError, InMemoryWorkflowInterventionStorage, WORKFLOW_RUN_FAILURE_CODES, InMemoryWorkflowRunStorage, InMemoryWorkflowNodeRunStorage, InMemoryWorkflowAgentNodeRunStorage, InMemoryStorage, isMigrationCapableStorage, migrateStorage, checkStorageSchema, step, defineMigrations, runMigrationSet, describeMigrationHistory };
|
|
7839
|
+
export { actionSubjectsEqual, actionRunParamsEqual, actionRunPhaseRecordsEqual, finishActionRunPhase, canRequeueActionRunAfterEnqueueFailure, isTerminalActionRun, InMemoryActionRunStorage, AGENT_MESSAGE_CONTENT_VERSION, InMemoryAgentStorage, AiCostStorageError, InMemoryAiCostStorage, InMemoryAiLimitStorage, InMemoryConnectorConnectionStorage, ObjectNotFoundError, ObjectStorageError, StorageTransactionError, isStorageSerializationFailure, FileUploadSessionError, DEFAULT_FILE_UPLOAD_SESSION_TTL_MS, DEFAULT_FILE_UPLOAD_TERMINAL_SESSION_TTL_MS, createUploadExpiresAt, createFileUploadId, InMemoryFileUploadSessions, compareQueryScalarValues, queryScalarValuesEqual, objectBatchKey, linkBatchKey, objectLinkCursor, canRequeuePipelineRunAfterEnqueueFailure, PIPELINE_RUN_FAILURE_CODES, InMemoryPipelineRunStorage, InMemoryProjectionRunStorage, InMemoryRulesStorage, canRequeueSyncRunAfterEnqueueFailure, SYNC_RUN_FAILURE_CODES, InMemorySyncRunStorage, createTransactionStorageProxy, assertTransactionActive, throwNestedStorageTransaction, WEBHOOK_RUN_FAILURE_CODES, canRetryWebhookRun, InMemoryWebhookRunStorage, WorkflowInterventionError, InMemoryWorkflowInterventionStorage, WORKFLOW_RUN_FAILURE_CODES, InMemoryWorkflowRunStorage, InMemoryWorkflowNodeRunStorage, InMemoryWorkflowAgentNodeRunStorage, InMemoryStorage, isMigrationCapableStorage, migrateStorage, checkStorageSchema, step, defineMigrations, runMigrationSet, describeMigrationHistory };
|
|
7261
7840
|
|
|
7262
|
-
//# debugId=
|
|
7841
|
+
//# debugId=472382EF0F10AB3864756E2164756E21
|