@sixb/core 0.1.2 → 0.1.4
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 +19 -17
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/worker.js +4 -4
- package/dist/actions/worker.js.map +1 -1
- package/dist/agents/adapters.d.ts +11 -1
- package/dist/agents/adapters.d.ts.map +1 -1
- package/dist/agents/context-compaction.d.ts +40 -0
- package/dist/agents/context-compaction.d.ts.map +1 -0
- package/dist/agents/context.js +1 -1
- package/dist/agents/errors.d.ts +1 -1
- package/dist/agents/errors.d.ts.map +1 -1
- package/dist/agents/execution.d.ts +3 -0
- package/dist/agents/execution.d.ts.map +1 -1
- package/dist/agents/ids.d.ts +2 -0
- package/dist/agents/ids.d.ts.map +1 -1
- package/dist/agents/index.d.ts +10 -6
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +51 -35
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/request.d.ts.map +1 -1
- package/dist/agents/streams.d.ts +17 -1
- package/dist/agents/streams.d.ts.map +1 -1
- package/dist/agents/streams.js +5 -3
- package/dist/agents/streams.js.map +1 -1
- package/dist/agents/thread-context-projection.d.ts +19 -0
- package/dist/agents/thread-context-projection.d.ts.map +1 -0
- package/dist/agents/tool-definition.d.ts.map +1 -1
- package/dist/agents/tool-result.d.ts +6 -0
- package/dist/agents/tool-result.d.ts.map +1 -0
- package/dist/agents/types.d.ts +46 -1
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/agents/validation.d.ts +2 -2
- package/dist/agents/validation.d.ts.map +1 -1
- package/dist/auth/index.js +11 -5
- package/dist/auth/index.js.map +1 -1
- package/dist/authorization/index.js +6 -2
- package/dist/authorization/index.js.map +1 -1
- package/dist/bootstrap/index.js +33 -31
- package/dist/bootstrap/index.js.map +1 -1
- package/dist/{chunk-ys1nse2v.js → chunk-1wk20wn3.js} +438 -246
- package/dist/{chunk-ys1nse2v.js.map → chunk-1wk20wn3.js.map} +11 -11
- package/dist/{chunk-sa4340y1.js → chunk-1yz3x65y.js} +7 -7
- package/dist/{chunk-gqdd7508.js → chunk-4rh2m6zg.js} +1 -1
- package/dist/{chunk-fmx1sz2h.js → chunk-72q2y8hn.js} +3 -3
- package/dist/{chunk-fmx1sz2h.js.map → chunk-72q2y8hn.js.map} +4 -4
- package/dist/{chunk-nnyp53zt.js → chunk-7gw7mepb.js} +259 -9
- package/dist/chunk-7gw7mepb.js.map +14 -0
- package/dist/{chunk-nten49ta.js → chunk-819wnjz8.js} +11 -5
- package/dist/chunk-819wnjz8.js.map +12 -0
- package/dist/chunk-96swp2wd.js +47 -0
- package/dist/chunk-96swp2wd.js.map +10 -0
- package/dist/{chunk-4x43bkbp.js → chunk-a09jx26t.js} +1 -1
- package/dist/{chunk-st4xgxey.js → chunk-afjpa2hs.js} +205 -48
- package/dist/chunk-afjpa2hs.js.map +45 -0
- package/dist/{chunk-0mbx247x.js → chunk-c43qr6s0.js} +427 -99
- package/dist/chunk-c43qr6s0.js.map +46 -0
- package/dist/{chunk-zg9yryhz.js → chunk-cbkm2vam.js} +3 -3
- package/dist/{chunk-57zpb99z.js → chunk-dm72y8wt.js} +26 -3
- package/dist/chunk-dm72y8wt.js.map +10 -0
- package/dist/chunk-drjqm1aa.js +913 -0
- package/dist/chunk-drjqm1aa.js.map +15 -0
- package/dist/chunk-dysw7nsm.js.map +1 -1
- package/dist/{chunk-8ryen3p3.js → chunk-f6erf2vv.js} +1 -1
- package/dist/{chunk-34bqh420.js → chunk-f83ka50g.js} +188 -44
- package/dist/chunk-f83ka50g.js.map +23 -0
- package/dist/{chunk-bct7hmfc.js → chunk-g13869yf.js} +3 -3
- package/dist/{chunk-0k4avqr2.js → chunk-hbeh8j9w.js} +2 -2
- package/dist/{chunk-qvybnnpe.js → chunk-nzw7sm3b.js} +2 -2
- package/dist/{chunk-k9pts48t.js → chunk-pn8n8sba.js} +16 -15
- package/dist/{chunk-k9pts48t.js.map → chunk-pn8n8sba.js.map} +3 -3
- package/dist/{chunk-63te770v.js → chunk-qewtks41.js} +8 -8
- package/dist/{chunk-63te770v.js.map → chunk-qewtks41.js.map} +2 -2
- package/dist/{chunk-85j5ybfj.js → chunk-rdeagz6b.js} +2 -2
- package/dist/{chunk-85j5ybfj.js.map → chunk-rdeagz6b.js.map} +3 -3
- package/dist/chunk-rhrbz7d4.js +36 -0
- package/dist/chunk-rhrbz7d4.js.map +10 -0
- package/dist/{chunk-bh6k3nc6.js → chunk-rs1wbvy6.js} +1 -1
- package/dist/{chunk-88ppkr54.js → chunk-rte5sm3z.js} +26 -2
- package/dist/chunk-rte5sm3z.js.map +12 -0
- package/dist/{chunk-n8herkry.js → chunk-s31d0qmq.js} +57 -20
- package/dist/{chunk-n8herkry.js.map → chunk-s31d0qmq.js.map} +8 -7
- package/dist/{chunk-7pc8b818.js → chunk-sxwk41qa.js} +1 -1
- package/dist/{chunk-663csy96.js → chunk-t0jjkep3.js} +2 -1
- package/dist/chunk-t0jjkep3.js.map +10 -0
- package/dist/{chunk-c6qd89g5.js → chunk-tek1qwgm.js} +6 -6
- package/dist/{chunk-c6qd89g5.js.map → chunk-tek1qwgm.js.map} +1 -1
- package/dist/{chunk-jaj13078.js → chunk-tkdscva6.js} +3 -33
- package/dist/{chunk-jaj13078.js.map → chunk-tkdscva6.js.map} +3 -4
- package/dist/{chunk-5egfka8j.js → chunk-tycbzedm.js} +2 -2
- package/dist/{chunk-g9t3kdtx.js → chunk-x2yw73hy.js} +1 -1
- package/dist/{chunk-57r1cpxx.js → chunk-xc7hq65b.js} +3 -2
- package/dist/{chunk-57r1cpxx.js.map → chunk-xc7hq65b.js.map} +3 -3
- package/dist/chunk-xdf9yswn.js +133 -0
- package/dist/chunk-xdf9yswn.js.map +11 -0
- package/dist/execution/agent.js +29 -27
- package/dist/execution/agent.js.map +1 -1
- package/dist/execution/primitive.js +29 -27
- package/dist/execution/primitive.js.map +2 -2
- package/dist/execution/request.js +30 -28
- package/dist/execution/request.js.map +2 -2
- package/dist/http/index.js +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +60 -58
- package/dist/index.js.map +1 -1
- package/dist/lake-storage/types.d.ts +2 -1
- package/dist/lake-storage/types.d.ts.map +1 -1
- package/dist/materialization/model.d.ts +4 -0
- package/dist/materialization/model.d.ts.map +1 -1
- package/dist/materializer/edits/apply.d.ts +6 -1
- package/dist/materializer/edits/apply.d.ts.map +1 -1
- package/dist/materializer/edits/working-state.d.ts +2 -0
- package/dist/materializer/edits/working-state.d.ts.map +1 -1
- package/dist/materializer/effective/resolve.d.ts +3 -1
- package/dist/materializer/effective/resolve.d.ts.map +1 -1
- package/dist/materializer/execution/work-records.d.ts.map +1 -1
- package/dist/materializer/index.js +19 -17
- package/dist/materializer/index.js.map +1 -1
- package/dist/materializer/projections/replacement-plan.d.ts.map +1 -1
- package/dist/materializer/shared/normalize.d.ts.map +1 -1
- package/dist/models/index.d.ts +40 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/objects/execution.d.ts +6 -1
- package/dist/objects/execution.d.ts.map +1 -1
- package/dist/objects/index.js +21 -19
- package/dist/objects/index.js.map +1 -1
- package/dist/objects/link/endpoints.d.ts.map +1 -1
- package/dist/objects/query/executor.d.ts +1 -0
- package/dist/objects/query/executor.d.ts.map +1 -1
- package/dist/objects/query/explain.d.ts +1 -0
- package/dist/objects/query/explain.d.ts.map +1 -1
- package/dist/objects/query/index.d.ts +3 -1
- package/dist/objects/query/index.d.ts.map +1 -1
- package/dist/objects/query/index.js +30 -5
- package/dist/objects/query/index.js.map +1 -1
- package/dist/objects/query/ir.d.ts +14 -1
- package/dist/objects/query/ir.d.ts.map +1 -1
- package/dist/objects/query/links.d.ts +25 -0
- package/dist/objects/query/links.d.ts.map +1 -0
- package/dist/objects/query/normalize.d.ts.map +1 -1
- package/dist/objects/query/planner.d.ts.map +1 -1
- package/dist/objects/query/validate.d.ts +1 -0
- package/dist/objects/query/validate.d.ts.map +1 -1
- package/dist/pipelines/index.js +16 -15
- package/dist/pipelines/index.js.map +1 -1
- package/dist/projections/builders.d.ts +52 -10
- package/dist/projections/builders.d.ts.map +1 -1
- package/dist/projections/index.d.ts +2 -1
- package/dist/projections/index.d.ts.map +1 -1
- package/dist/projections/internal.d.ts +4 -1
- package/dist/projections/internal.d.ts.map +1 -1
- package/dist/projections/internal.js +22 -17
- package/dist/projections/internal.js.map +1 -1
- package/dist/projections/run-dispatch.d.ts +1 -0
- package/dist/projections/run-dispatch.d.ts.map +1 -1
- package/dist/projections/timestamp.d.ts +3 -0
- package/dist/projections/timestamp.d.ts.map +1 -0
- package/dist/projections/types.d.ts +21 -9
- package/dist/projections/types.d.ts.map +1 -1
- package/dist/projections/validation.d.ts +6 -5
- package/dist/projections/validation.d.ts.map +1 -1
- package/dist/query.d.ts +2 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +2 -2
- package/dist/queues/index.d.ts +1 -1
- package/dist/queues/index.d.ts.map +1 -1
- package/dist/queues/types.d.ts +7 -0
- package/dist/queues/types.d.ts.map +1 -1
- package/dist/runtime/ai-cost.d.ts +8 -0
- package/dist/runtime/ai-cost.d.ts.map +1 -0
- package/dist/runtime/create.d.ts +3 -0
- package/dist/runtime/create.d.ts.map +1 -1
- package/dist/runtime/definitions.d.ts +3 -0
- package/dist/runtime/definitions.d.ts.map +1 -1
- package/dist/runtime/host.d.ts +2 -0
- package/dist/runtime/host.d.ts.map +1 -1
- package/dist/runtime/resolve-definitions.d.ts +2 -0
- package/dist/runtime/resolve-definitions.d.ts.map +1 -1
- package/dist/storage/agents/in-memory.d.ts +22 -4
- 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 +31 -0
- package/dist/storage/agents/provider.d.ts.map +1 -1
- package/dist/storage/agents/provider.js +22 -7
- package/dist/storage/agents/provider.js.map +1 -1
- package/dist/storage/agents/types.d.ts +75 -4
- package/dist/storage/agents/types.d.ts.map +1 -1
- package/dist/storage/ai-cost/analytics.d.ts +61 -0
- package/dist/storage/ai-cost/analytics.d.ts.map +1 -0
- package/dist/storage/ai-cost/codec.d.ts +14 -0
- package/dist/storage/ai-cost/codec.d.ts.map +1 -0
- package/dist/storage/ai-cost/errors.d.ts +7 -0
- package/dist/storage/ai-cost/errors.d.ts.map +1 -0
- package/dist/storage/ai-cost/in-memory.d.ts +32 -0
- package/dist/storage/ai-cost/in-memory.d.ts.map +1 -0
- package/dist/storage/ai-cost/index.d.ts +6 -0
- package/dist/storage/ai-cost/index.d.ts.map +1 -0
- package/dist/storage/ai-cost/provider.d.ts +7 -0
- package/dist/storage/ai-cost/provider.d.ts.map +1 -0
- package/dist/storage/ai-cost/provider.js +132 -0
- package/dist/storage/ai-cost/provider.js.map +10 -0
- package/dist/storage/ai-cost/types.d.ts +154 -0
- package/dist/storage/ai-cost/types.d.ts.map +1 -0
- package/dist/storage/ai-cost/validation.d.ts +7 -0
- package/dist/storage/ai-cost/validation.d.ts.map +1 -0
- package/dist/storage/ai-usage/in-memory.d.ts +2 -1
- package/dist/storage/ai-usage/in-memory.d.ts.map +1 -1
- package/dist/storage/ai-usage/index.d.ts +1 -1
- package/dist/storage/ai-usage/index.d.ts.map +1 -1
- package/dist/storage/ai-usage/types.d.ts +6 -0
- package/dist/storage/ai-usage/types.d.ts.map +1 -1
- package/dist/storage/in-memory/index.d.ts +5 -0
- package/dist/storage/in-memory/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +6 -3
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +33 -21
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/objects/in-memory.d.ts +6 -3
- package/dist/storage/objects/in-memory.d.ts.map +1 -1
- package/dist/storage/objects/index.d.ts +3 -1
- package/dist/storage/objects/index.d.ts.map +1 -1
- package/dist/storage/objects/keys.d.ts +16 -0
- package/dist/storage/objects/keys.d.ts.map +1 -0
- package/dist/storage/objects/types.d.ts +33 -6
- package/dist/storage/objects/types.d.ts.map +1 -1
- package/dist/storage/ontology/in-memory/materializations.d.ts.map +1 -1
- package/dist/storage/ontology/materializations.d.ts +3 -0
- package/dist/storage/ontology/materializations.d.ts.map +1 -1
- package/dist/storage/ontology/provider.js +1 -1
- package/dist/storage/operation-scope.d.ts.map +1 -1
- package/dist/storage/operation-scope.js +1 -1
- package/dist/storage/types.d.ts +2 -0
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/storage/workflow-runs/provider.js +10 -5
- package/dist/storage/workflow-runs/provider.js.map +1 -1
- package/dist/syncs/index.js +16 -15
- package/dist/syncs/index.js.map +1 -1
- package/dist/testing/agent-storage-contract.d.ts +3 -2
- package/dist/testing/agent-storage-contract.d.ts.map +1 -1
- package/dist/testing/ai-cost-storage-contract.d.ts +12 -0
- package/dist/testing/ai-cost-storage-contract.d.ts.map +1 -0
- package/dist/testing/ai-usage-storage-contract.d.ts.map +1 -1
- package/dist/testing/effective-storage-contract.d.ts +1 -1
- package/dist/testing/effective-storage-contract.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 +2525 -1480
- package/dist/testing/index.js.map +10 -9
- package/dist/testing/lake-storage-contract.d.ts.map +1 -1
- package/dist/testing/materializer-storage-contract.d.ts.map +1 -1
- package/dist/testing/object-query-contract.d.ts +1 -1
- package/dist/testing/object-query-contract.d.ts.map +1 -1
- package/dist/webhooks/internal.js +14 -13
- package/dist/webhooks/internal.js.map +2 -2
- package/dist/workers/index.js +12 -2
- package/dist/workers/index.js.map +3 -3
- package/dist/workers/queue-worker.d.ts +2 -0
- package/dist/workers/queue-worker.d.ts.map +1 -1
- package/dist/workflows/execution.d.ts +3 -0
- package/dist/workflows/execution.d.ts.map +1 -1
- package/dist/workflows/index.js +30 -28
- package/dist/workflows/index.js.map +1 -1
- package/package.json +7 -1
- package/src/agents/adapters.ts +64 -23
- package/src/agents/builders.ts +3 -3
- package/src/agents/context-compaction.ts +261 -0
- package/src/agents/errors.ts +2 -2
- package/src/agents/execution.ts +14 -2
- package/src/agents/ids.ts +5 -0
- package/src/agents/index.ts +32 -6
- package/src/agents/request.ts +5 -0
- package/src/agents/streams.ts +56 -0
- package/src/agents/thread-context-projection.ts +93 -0
- package/src/agents/tool-definition.ts +17 -2
- package/src/agents/tool-result.ts +61 -0
- package/src/agents/types.ts +57 -1
- package/src/agents/validation.ts +36 -6
- package/src/http/api-routes.ts +7 -7
- package/src/index.ts +27 -0
- package/src/lake-storage/types.ts +2 -1
- package/src/materialization/model.ts +4 -0
- package/src/materializer/edits/apply.ts +55 -2
- package/src/materializer/edits/operations.ts +8 -1
- package/src/materializer/edits/working-state.ts +7 -0
- package/src/materializer/effective/resolve.ts +78 -9
- package/src/materializer/execution/work-records.ts +3 -1
- package/src/materializer/projections/entry-validator.ts +23 -1
- package/src/materializer/projections/replacement-plan.ts +2 -0
- package/src/materializer/shared/normalize.ts +16 -0
- package/src/materializer/telemetry/append.ts +33 -16
- package/src/models/index.ts +71 -0
- package/src/objects/execution.ts +20 -0
- package/src/objects/link/endpoints.ts +2 -1
- package/src/objects/query/executor.ts +42 -11
- package/src/objects/query/explain.ts +11 -0
- package/src/objects/query/index.ts +6 -0
- package/src/objects/query/ir.ts +16 -0
- package/src/objects/query/links.ts +308 -0
- package/src/objects/query/normalize.ts +40 -1
- package/src/objects/query/planner.ts +5 -0
- package/src/objects/query/validate.ts +58 -2
- package/src/projections/builders.ts +320 -50
- package/src/projections/index.ts +7 -0
- package/src/projections/internal.ts +4 -1
- package/src/projections/ownership.ts +5 -5
- package/src/projections/registry.ts +16 -3
- package/src/projections/revision.ts +35 -5
- package/src/projections/run-dispatch.ts +10 -1
- package/src/projections/timestamp.ts +66 -0
- package/src/projections/types.ts +20 -9
- package/src/projections/validation.ts +85 -19
- package/src/query.ts +2 -0
- package/src/queues/index.ts +1 -0
- package/src/queues/types.ts +8 -0
- package/src/runtime/ai-cost.ts +15 -0
- package/src/runtime/create.ts +4 -0
- package/src/runtime/definitions.ts +3 -0
- package/src/runtime/host.ts +2 -0
- package/src/runtime/resolve-definitions.ts +28 -0
- package/src/storage/agents/in-memory.ts +186 -4
- package/src/storage/agents/index.ts +5 -0
- package/src/storage/agents/provider.ts +225 -0
- package/src/storage/agents/types.ts +82 -3
- package/src/storage/ai-cost/analytics.ts +602 -0
- package/src/storage/ai-cost/codec.ts +136 -0
- package/src/storage/ai-cost/errors.ts +12 -0
- package/src/storage/ai-cost/in-memory.ts +164 -0
- package/src/storage/ai-cost/index.ts +35 -0
- package/src/storage/ai-cost/provider.ts +20 -0
- package/src/storage/ai-cost/types.ts +193 -0
- package/src/storage/ai-cost/validation.ts +337 -0
- package/src/storage/ai-usage/in-memory.ts +23 -0
- package/src/storage/ai-usage/index.ts +1 -0
- package/src/storage/ai-usage/types.ts +10 -0
- package/src/storage/in-memory/index.ts +50 -0
- package/src/storage/index.ts +48 -0
- package/src/storage/objects/in-memory.ts +103 -16
- package/src/storage/objects/index.ts +9 -0
- package/src/storage/objects/keys.ts +36 -0
- package/src/storage/objects/types.ts +34 -6
- package/src/storage/ontology/in-memory/materializations.ts +1 -0
- package/src/storage/ontology/materializations.ts +3 -0
- package/src/storage/ontology/provider-header-validation.ts +2 -2
- package/src/storage/operation-scope.ts +1 -0
- package/src/storage/types.ts +2 -0
- package/src/testing/agent-storage-contract.ts +353 -2
- package/src/testing/ai-cost-storage-contract.ts +320 -0
- package/src/testing/ai-usage-storage-contract.ts +35 -0
- package/src/testing/effective-storage-contract.ts +194 -4
- package/src/testing/index.ts +5 -0
- package/src/testing/lake-storage-contract.ts +56 -0
- package/src/testing/materializer-storage-contract.ts +120 -2
- package/src/testing/object-query-contract.ts +208 -1
- package/src/workers/queue-worker.ts +14 -1
- package/src/workflows/execution.ts +31 -10
- package/dist/agents/prompt.d.ts +0 -15
- package/dist/agents/prompt.d.ts.map +0 -1
- package/dist/chunk-0mbx247x.js.map +0 -43
- package/dist/chunk-34bqh420.js.map +0 -23
- package/dist/chunk-57zpb99z.js.map +0 -10
- package/dist/chunk-663csy96.js.map +0 -10
- package/dist/chunk-6wetht33.js +0 -89
- package/dist/chunk-6wetht33.js.map +0 -10
- package/dist/chunk-88ppkr54.js.map +0 -12
- package/dist/chunk-nnyp53zt.js.map +0 -13
- package/dist/chunk-nten49ta.js.map +0 -12
- package/dist/chunk-st4xgxey.js.map +0 -45
- package/dist/chunk-vp1vc6ee.js +0 -35
- package/dist/chunk-vp1vc6ee.js.map +0 -11
- package/src/agents/prompt.ts +0 -57
- /package/dist/{chunk-sa4340y1.js.map → chunk-1yz3x65y.js.map} +0 -0
- /package/dist/{chunk-gqdd7508.js.map → chunk-4rh2m6zg.js.map} +0 -0
- /package/dist/{chunk-4x43bkbp.js.map → chunk-a09jx26t.js.map} +0 -0
- /package/dist/{chunk-zg9yryhz.js.map → chunk-cbkm2vam.js.map} +0 -0
- /package/dist/{chunk-8ryen3p3.js.map → chunk-f6erf2vv.js.map} +0 -0
- /package/dist/{chunk-bct7hmfc.js.map → chunk-g13869yf.js.map} +0 -0
- /package/dist/{chunk-0k4avqr2.js.map → chunk-hbeh8j9w.js.map} +0 -0
- /package/dist/{chunk-qvybnnpe.js.map → chunk-nzw7sm3b.js.map} +0 -0
- /package/dist/{chunk-bh6k3nc6.js.map → chunk-rs1wbvy6.js.map} +0 -0
- /package/dist/{chunk-7pc8b818.js.map → chunk-sxwk41qa.js.map} +0 -0
- /package/dist/{chunk-5egfka8j.js.map → chunk-tycbzedm.js.map} +0 -0
- /package/dist/{chunk-g9t3kdtx.js.map → chunk-x2yw73hy.js.map} +0 -0
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
startScopeAccumulator,
|
|
28
28
|
uniqueSorted,
|
|
29
29
|
workUniquenessKey
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-72q2y8hn.js";
|
|
31
31
|
import {
|
|
32
32
|
createAgentOperationScope,
|
|
33
33
|
createAuthOperationScope,
|
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
createOperationScopedFacade,
|
|
36
36
|
createStorageOperationScope,
|
|
37
37
|
createWorkflowRunOperationScope
|
|
38
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-xc7hq65b.js";
|
|
39
39
|
import {
|
|
40
40
|
PipelineRunError,
|
|
41
41
|
assertPipelineRunExecution
|
|
@@ -79,7 +79,7 @@ import {
|
|
|
79
79
|
WorkflowRunError,
|
|
80
80
|
assertWorkflowAgentNodeRunExecution,
|
|
81
81
|
assertWorkflowRunExecution
|
|
82
|
-
} from "./chunk-
|
|
82
|
+
} from "./chunk-a09jx26t.js";
|
|
83
83
|
import {
|
|
84
84
|
parseActionRunFailure
|
|
85
85
|
} from "./chunk-htq0qh7z.js";
|
|
@@ -89,8 +89,20 @@ import {
|
|
|
89
89
|
} from "./chunk-xkthy56g.js";
|
|
90
90
|
import {
|
|
91
91
|
AgentStorageError,
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
agentContextCheckpointMatchesCreateInput,
|
|
93
|
+
assertAgentContextCheckpointAnchors,
|
|
94
|
+
assertAgentContextCheckpointAuthority,
|
|
95
|
+
assertAgentContextCheckpointReplayState,
|
|
96
|
+
assertAgentRunExecution,
|
|
97
|
+
assertCreateAgentContextCheckpointInput
|
|
98
|
+
} from "./chunk-xdf9yswn.js";
|
|
99
|
+
import {
|
|
100
|
+
InMemoryAiUsageStorage,
|
|
101
|
+
aiModelCallCostMatchesUsage,
|
|
102
|
+
buildAiAccountingOverview,
|
|
103
|
+
buildAiModelCallAccountingList,
|
|
104
|
+
normalizeAiModelCallCostRecord
|
|
105
|
+
} from "./chunk-drjqm1aa.js";
|
|
94
106
|
import {
|
|
95
107
|
CONNECTOR_CONNECTION_RUN_FAILURE_CODES,
|
|
96
108
|
ConnectorConnectionStorageError
|
|
@@ -119,28 +131,27 @@ import {
|
|
|
119
131
|
MaterializationConflictError,
|
|
120
132
|
MaterializationValidationError
|
|
121
133
|
} from "./chunk-ry24jbr1.js";
|
|
122
|
-
import {
|
|
123
|
-
compareQueryScalarValues,
|
|
124
|
-
queryScalarValuesEqual
|
|
125
|
-
} from "./chunk-6wetht33.js";
|
|
126
134
|
import {
|
|
127
135
|
AGENT_RUN_FAILURE_CODES
|
|
128
|
-
} from "./chunk-
|
|
136
|
+
} from "./chunk-t0jjkep3.js";
|
|
129
137
|
import {
|
|
130
138
|
InMemoryAuthStorage,
|
|
131
|
-
normalizeRequesterGroupIds,
|
|
132
139
|
paginate,
|
|
133
140
|
principalsEqual
|
|
134
|
-
} from "./chunk-
|
|
141
|
+
} from "./chunk-tkdscva6.js";
|
|
142
|
+
import {
|
|
143
|
+
normalizeRequesterGroupIds
|
|
144
|
+
} from "./chunk-rhrbz7d4.js";
|
|
145
|
+
import {
|
|
146
|
+
compareDecimalValues
|
|
147
|
+
} from "./chunk-04b07a9q.js";
|
|
135
148
|
import {
|
|
136
149
|
createSixbError,
|
|
137
150
|
parseSixbFailure,
|
|
138
151
|
toSixbFailure
|
|
139
152
|
} from "./chunk-0172wgm9.js";
|
|
140
153
|
import {
|
|
141
|
-
assertJsonValue,
|
|
142
154
|
cloneJsonValue,
|
|
143
|
-
isPlainRecord,
|
|
144
155
|
stableJsonStringify
|
|
145
156
|
} from "./chunk-t8t39h7v.js";
|
|
146
157
|
// src/storage/action-runs/idempotency.ts
|
|
@@ -729,6 +740,30 @@ class InMemoryAgentMessageStore {
|
|
|
729
740
|
}));
|
|
730
741
|
return clone(message);
|
|
731
742
|
}
|
|
743
|
+
async deleteByRunId(input) {
|
|
744
|
+
const threadKey = key(input.projectId, input.threadId);
|
|
745
|
+
const thread = this.state.threads.get(threadKey);
|
|
746
|
+
if (!thread) {
|
|
747
|
+
throw new AgentStorageError("thread_not_found", `[Sixb] Agent thread '${input.threadId}' not found for project '${input.projectId}'.`);
|
|
748
|
+
}
|
|
749
|
+
const messages = [...this.state.messages.entries()].filter(([, message]) => message.projectId === input.projectId && message.threadId === input.threadId && message.runId === input.runId);
|
|
750
|
+
if (messages.length === 0) {
|
|
751
|
+
return 0;
|
|
752
|
+
}
|
|
753
|
+
for (const [messageKey] of messages) {
|
|
754
|
+
this.state.messages.delete(messageKey);
|
|
755
|
+
}
|
|
756
|
+
const remainingMessages = [...this.state.messages.values()].filter((message) => message.projectId === input.projectId && message.threadId === input.threadId).sort((left, right) => right.seq - left.seq);
|
|
757
|
+
const latestMessage = remainingMessages[0];
|
|
758
|
+
const updatedAt = new Date;
|
|
759
|
+
this.state.threads.set(threadKey, clone({
|
|
760
|
+
...thread,
|
|
761
|
+
messageCount: remainingMessages.length,
|
|
762
|
+
lastMessageAt: latestMessage?.createdAt,
|
|
763
|
+
updatedAt
|
|
764
|
+
}));
|
|
765
|
+
return messages.length;
|
|
766
|
+
}
|
|
732
767
|
async getById(params) {
|
|
733
768
|
const record = this.state.messages.get(key(params.projectId, params.id));
|
|
734
769
|
return record ? clone(record) : null;
|
|
@@ -736,7 +771,7 @@ class InMemoryAgentMessageStore {
|
|
|
736
771
|
async list(input) {
|
|
737
772
|
const order = input.order ?? "asc";
|
|
738
773
|
const roles = input.roles ? new Set(input.roles) : null;
|
|
739
|
-
const filtered = [...this.state.messages.values()].filter((message) => message.projectId === input.projectId).filter((message) => message.threadId === input.threadId).filter((message) => roles ? roles.has(message.role) : true).sort((a, b) => order === "asc" ? a.seq - b.seq : b.seq - a.seq);
|
|
774
|
+
const filtered = [...this.state.messages.values()].filter((message) => message.projectId === input.projectId).filter((message) => message.threadId === input.threadId).filter((message) => input.afterSeq === undefined ? true : message.seq > input.afterSeq).filter((message) => roles ? roles.has(message.role) : true).sort((a, b) => order === "asc" ? a.seq - b.seq : b.seq - a.seq);
|
|
740
775
|
const { page, hasMore, total } = applyWindow(filtered, input.offset, input.limit);
|
|
741
776
|
return { messages: page.map(clone), hasMore, total };
|
|
742
777
|
}
|
|
@@ -751,31 +786,107 @@ class InMemoryAgentMessageStore {
|
|
|
751
786
|
}
|
|
752
787
|
}
|
|
753
788
|
|
|
789
|
+
class InMemoryAgentContextCheckpointStore {
|
|
790
|
+
state;
|
|
791
|
+
constructor(state) {
|
|
792
|
+
this.state = state;
|
|
793
|
+
}
|
|
794
|
+
async create(input) {
|
|
795
|
+
assertCreateAgentContextCheckpointInput(input);
|
|
796
|
+
const run = this.state.runs.get(key(input.projectId, input.createdByRunId)) ?? null;
|
|
797
|
+
const thread = this.state.threads.get(key(input.projectId, input.threadId)) ?? null;
|
|
798
|
+
assertAgentContextCheckpointAuthority({ create: input, run, thread });
|
|
799
|
+
const messages = [...this.state.messages.values()].filter((message) => message.projectId === input.projectId && message.threadId === input.threadId);
|
|
800
|
+
const headSeq = messages.reduce((head, message) => Math.max(head, message.seq), 0);
|
|
801
|
+
const latest = this.findLatest(input.projectId, input.threadId);
|
|
802
|
+
const existingForRun = [...this.state.checkpoints.values()].find((checkpoint) => checkpoint.projectId === input.projectId && checkpoint.createdByRunId === input.createdByRunId);
|
|
803
|
+
if (existingForRun) {
|
|
804
|
+
if (agentContextCheckpointMatchesCreateInput(existingForRun, input)) {
|
|
805
|
+
assertAgentContextCheckpointReplayState({
|
|
806
|
+
create: input,
|
|
807
|
+
existing: existingForRun,
|
|
808
|
+
latest,
|
|
809
|
+
headSeq
|
|
810
|
+
});
|
|
811
|
+
return clone(existingForRun);
|
|
812
|
+
}
|
|
813
|
+
throw new AgentStorageError("invalid_state", `[Sixb] Agent run '${input.createdByRunId}' already created a different context checkpoint.`);
|
|
814
|
+
}
|
|
815
|
+
if (this.state.checkpoints.has(key(input.projectId, input.id))) {
|
|
816
|
+
throw new AgentStorageError("duplicate_id", `[Sixb] Agent context checkpoint '${input.id}' already exists for project '${input.projectId}'.`);
|
|
817
|
+
}
|
|
818
|
+
const firstRetained = messages.filter((message) => message.seq > input.summarizedThroughSeq).sort((left, right) => left.seq - right.seq)[0] ?? null;
|
|
819
|
+
assertAgentContextCheckpointAnchors({
|
|
820
|
+
create: input,
|
|
821
|
+
latest,
|
|
822
|
+
headSeq,
|
|
823
|
+
firstRetained
|
|
824
|
+
});
|
|
825
|
+
const record = {
|
|
826
|
+
id: input.id,
|
|
827
|
+
projectId: input.projectId,
|
|
828
|
+
threadId: input.threadId,
|
|
829
|
+
createdByRunId: input.createdByRunId,
|
|
830
|
+
...input.expectedPreviousCheckpointId === null ? {} : { previousCheckpointId: input.expectedPreviousCheckpointId },
|
|
831
|
+
reason: input.reason,
|
|
832
|
+
summary: input.summary,
|
|
833
|
+
summaryFormatVersion: input.summaryFormatVersion,
|
|
834
|
+
summarizedThroughSeq: input.summarizedThroughSeq,
|
|
835
|
+
observedHeadSeq: input.observedHeadSeq,
|
|
836
|
+
estimatedInputTokensBefore: input.estimatedInputTokensBefore,
|
|
837
|
+
estimatedInputTokensAfter: input.estimatedInputTokensAfter,
|
|
838
|
+
summaryModelId: input.summaryModelId,
|
|
839
|
+
createdAt: new Date(input.createdAt ?? new Date)
|
|
840
|
+
};
|
|
841
|
+
this.state.checkpoints.set(key(input.projectId, input.id), clone(record));
|
|
842
|
+
return clone(record);
|
|
843
|
+
}
|
|
844
|
+
async getLatest(input) {
|
|
845
|
+
const record = this.findLatest(input.projectId, input.threadId);
|
|
846
|
+
return record ? clone(record) : null;
|
|
847
|
+
}
|
|
848
|
+
async getByRunIds(input) {
|
|
849
|
+
const byRunId = new Map([...this.state.checkpoints.values()].filter((checkpoint) => checkpoint.projectId === input.projectId).map((checkpoint) => [checkpoint.createdByRunId, checkpoint]));
|
|
850
|
+
return [...new Set(input.runIds)].flatMap((runId) => {
|
|
851
|
+
const checkpoint = byRunId.get(runId);
|
|
852
|
+
return checkpoint ? [clone(checkpoint)] : [];
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
findLatest(projectId, threadId) {
|
|
856
|
+
return [...this.state.checkpoints.values()].filter((checkpoint) => checkpoint.projectId === projectId && checkpoint.threadId === threadId).sort((left, right) => right.summarizedThroughSeq - left.summarizedThroughSeq || right.createdAt.getTime() - left.createdAt.getTime() || right.id.localeCompare(left.id))[0] ?? null;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
|
|
754
860
|
class InMemoryAgentStorage {
|
|
755
861
|
state = {
|
|
756
862
|
threads: new Map,
|
|
757
863
|
runs: new Map,
|
|
758
|
-
messages: new Map
|
|
864
|
+
messages: new Map,
|
|
865
|
+
checkpoints: new Map
|
|
759
866
|
};
|
|
760
867
|
threads;
|
|
761
868
|
runs;
|
|
762
869
|
messages;
|
|
870
|
+
checkpoints;
|
|
763
871
|
constructor(executions) {
|
|
764
872
|
this.threads = new InMemoryAgentThreadStore(this.state);
|
|
765
873
|
this.runs = new InMemoryAgentRunStore(this.state, executions);
|
|
766
874
|
this.messages = new InMemoryAgentMessageStore(this.state);
|
|
875
|
+
this.checkpoints = new InMemoryAgentContextCheckpointStore(this.state);
|
|
767
876
|
}
|
|
768
877
|
snapshot() {
|
|
769
878
|
return {
|
|
770
879
|
threads: structuredClone(this.state.threads),
|
|
771
880
|
runs: structuredClone(this.state.runs),
|
|
772
|
-
messages: structuredClone(this.state.messages)
|
|
881
|
+
messages: structuredClone(this.state.messages),
|
|
882
|
+
checkpoints: structuredClone(this.state.checkpoints)
|
|
773
883
|
};
|
|
774
884
|
}
|
|
775
885
|
restore(snapshot) {
|
|
776
886
|
replace(this.state.threads, snapshot.threads);
|
|
777
887
|
replace(this.state.runs, snapshot.runs);
|
|
778
888
|
replace(this.state.messages, snapshot.messages);
|
|
889
|
+
replace(this.state.checkpoints, snapshot.checkpoints);
|
|
779
890
|
}
|
|
780
891
|
}
|
|
781
892
|
function replace(target, source) {
|
|
@@ -784,248 +895,120 @@ function replace(target, source) {
|
|
|
784
895
|
target.set(k, value);
|
|
785
896
|
}
|
|
786
897
|
}
|
|
787
|
-
// src/storage/ai-
|
|
788
|
-
class
|
|
898
|
+
// src/storage/ai-cost/errors.ts
|
|
899
|
+
class AiCostStorageError extends Error {
|
|
789
900
|
code;
|
|
790
|
-
name = "
|
|
901
|
+
name = "AiCostStorageError";
|
|
791
902
|
constructor(code, message) {
|
|
792
903
|
super(message);
|
|
793
904
|
this.code = code;
|
|
794
905
|
}
|
|
795
906
|
}
|
|
796
|
-
// src/storage/ai-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
"reasoningOutputTokens"
|
|
805
|
-
];
|
|
806
|
-
function normalizeAiModelCallUsage(input) {
|
|
807
|
-
for (const field of USAGE_FIELDS) {
|
|
808
|
-
assertUsageCount(input[field], field);
|
|
907
|
+
// src/storage/ai-cost/in-memory.ts
|
|
908
|
+
class InMemoryAiCostStorage {
|
|
909
|
+
usage;
|
|
910
|
+
attribution;
|
|
911
|
+
recordsByUsage = new Map;
|
|
912
|
+
constructor(usage, attribution) {
|
|
913
|
+
this.usage = usage;
|
|
914
|
+
this.attribution = attribution;
|
|
809
915
|
}
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
reportingStatus
|
|
822
|
-
};
|
|
823
|
-
}
|
|
824
|
-
function aggregateAiModelCallUsage(usages) {
|
|
825
|
-
const normalized = Array.from(usages, normalizeAiModelCallUsage);
|
|
826
|
-
const fields = Object.fromEntries(USAGE_FIELDS.map((field) => [field, sumUsageField(normalized, field)]));
|
|
827
|
-
const aggregate = normalizeAiModelCallUsage(fields);
|
|
828
|
-
if (aggregate.reportingStatus === "unavailable" && normalized.some((usage) => usage.reportingStatus !== "unavailable")) {
|
|
829
|
-
return { ...aggregate, reportingStatus: "partial" };
|
|
830
|
-
}
|
|
831
|
-
return aggregate;
|
|
832
|
-
}
|
|
833
|
-
function sumUsageField(usages, field) {
|
|
834
|
-
if (usages.length === 0)
|
|
835
|
-
return;
|
|
836
|
-
let total = 0;
|
|
837
|
-
for (const usage of usages) {
|
|
838
|
-
const value = usage[field];
|
|
839
|
-
if (value === undefined)
|
|
840
|
-
return;
|
|
841
|
-
total = addUsageCounts(total, value, `aggregate ${field}`);
|
|
842
|
-
}
|
|
843
|
-
return total;
|
|
844
|
-
}
|
|
845
|
-
function assertUsageCount(value, field) {
|
|
846
|
-
if (value !== undefined && (!Number.isSafeInteger(value) || value < 0)) {
|
|
847
|
-
throw new TypeError(`[Sixb] AI model-call usage ${field} must be a non-negative safe integer.`);
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
function addUsageCounts(left, right, field) {
|
|
851
|
-
const result = left + right;
|
|
852
|
-
if (!Number.isSafeInteger(result)) {
|
|
853
|
-
throw new TypeError(`[Sixb] AI model-call usage ${field} exceeds the safe integer range.`);
|
|
854
|
-
}
|
|
855
|
-
return result;
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
// src/storage/ai-usage/record.ts
|
|
859
|
-
function normalizeAiModelCallRecord(input) {
|
|
860
|
-
assertNonBlank2(input.id, "id");
|
|
861
|
-
assertNonBlank2(input.projectId, "projectId");
|
|
862
|
-
assertAiUsageExecutionId(input.executionId);
|
|
863
|
-
assertPositiveSafeInteger(input.attempt, "attempt");
|
|
864
|
-
assertNonBlank2(input.callId, "callId");
|
|
865
|
-
assertNonBlank2(input.providerId, "providerId");
|
|
866
|
-
assertNonBlank2(input.requestedModelId, "requestedModelId");
|
|
867
|
-
if (input.responseModelId !== undefined) {
|
|
868
|
-
assertNonBlank2(input.responseModelId, "responseModelId");
|
|
869
|
-
}
|
|
870
|
-
assertNonBlank2(input.responseId, "responseId");
|
|
871
|
-
const occurredAt = cloneValidDate(input.occurredAt, "occurredAt");
|
|
872
|
-
const recordedAt = cloneValidDate(input.recordedAt ?? new Date, "recordedAt");
|
|
873
|
-
const requesterGroupIds = normalizeRequesterGroupIds(input.requesterGroupIds);
|
|
874
|
-
const rawUsage = cloneRawUsage(input.rawUsage);
|
|
875
|
-
return {
|
|
876
|
-
id: input.id,
|
|
877
|
-
projectId: input.projectId,
|
|
878
|
-
executionId: input.executionId,
|
|
879
|
-
attempt: input.attempt,
|
|
880
|
-
callId: input.callId,
|
|
881
|
-
requesterGroupIds,
|
|
882
|
-
providerId: input.providerId,
|
|
883
|
-
requestedModelId: input.requestedModelId,
|
|
884
|
-
...input.responseModelId === undefined ? {} : { responseModelId: input.responseModelId },
|
|
885
|
-
responseId: input.responseId,
|
|
886
|
-
usage: normalizeAiModelCallUsage(input.usage),
|
|
887
|
-
...rawUsage === undefined ? {} : { rawUsage },
|
|
888
|
-
occurredAt,
|
|
889
|
-
recordedAt
|
|
890
|
-
};
|
|
891
|
-
}
|
|
892
|
-
function assertAiUsageExecutionId(executionId) {
|
|
893
|
-
assertNonBlank2(executionId, "executionId");
|
|
894
|
-
}
|
|
895
|
-
function cloneRawUsage(rawUsage) {
|
|
896
|
-
if (rawUsage === undefined)
|
|
897
|
-
return;
|
|
898
|
-
if (!isPlainRecord(rawUsage)) {
|
|
899
|
-
throw new TypeError("[Sixb] AI usage rawUsage must be a JSON object.");
|
|
900
|
-
}
|
|
901
|
-
assertJsonValue(rawUsage, "AI usage rawUsage");
|
|
902
|
-
return structuredClone(rawUsage);
|
|
903
|
-
}
|
|
904
|
-
function assertNonBlank2(value, field) {
|
|
905
|
-
if (typeof value !== "string" || value.trim().length === 0) {
|
|
906
|
-
throw new TypeError(`[Sixb] AI usage ${field} must be nonblank.`);
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
function assertPositiveSafeInteger(value, field) {
|
|
910
|
-
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
911
|
-
throw new TypeError(`[Sixb] AI usage ${field} must be a positive safe integer.`);
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
function cloneValidDate(value, field) {
|
|
915
|
-
if (!(value instanceof Date) || !Number.isFinite(value.getTime())) {
|
|
916
|
-
throw new TypeError(`[Sixb] AI usage ${field} must be a valid Date.`);
|
|
917
|
-
}
|
|
918
|
-
return new Date(value);
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
// src/storage/ai-usage/in-memory.ts
|
|
922
|
-
class InMemoryAiUsageStorage {
|
|
923
|
-
executions;
|
|
924
|
-
records = new Map;
|
|
925
|
-
recordKeysByIdempotencyKey = new Map;
|
|
926
|
-
groupRows = new Map;
|
|
927
|
-
constructor(executions) {
|
|
928
|
-
this.executions = executions;
|
|
916
|
+
async recordModelCallCost(input) {
|
|
917
|
+
const record = normalizeAiModelCallCostRecord(input);
|
|
918
|
+
const usage = this.usageRecord(record.projectId, record.usageRecordId);
|
|
919
|
+
if (!usage)
|
|
920
|
+
throw missingUsage(record);
|
|
921
|
+
if (!aiModelCallCostMatchesUsage(record, usage)) {
|
|
922
|
+
throw new AiCostStorageError("cost_mismatch", `[Sixb] AI valuation for usage '${record.usageRecordId}' does not match its usage record.`);
|
|
923
|
+
}
|
|
924
|
+
const key2 = usageRecordKey(record.projectId, record.usageRecordId);
|
|
925
|
+
if (!this.recordsByUsage.has(key2))
|
|
926
|
+
this.recordsByUsage.set(key2, structuredClone(record));
|
|
929
927
|
}
|
|
930
|
-
async
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
const
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
if (
|
|
938
|
-
|
|
928
|
+
async summarizeExecutions(input) {
|
|
929
|
+
assertNonBlank2(input.projectId, "cost summary projectId");
|
|
930
|
+
for (const id of input.executionIds)
|
|
931
|
+
assertNonBlank2(id, "cost summary executionId");
|
|
932
|
+
const requested = new Set(input.executionIds);
|
|
933
|
+
const usageByExecution = new Map(input.executionIds.map((id) => [id, []]));
|
|
934
|
+
for (const usage of this.usage.snapshot().records.values()) {
|
|
935
|
+
if (usage.projectId === input.projectId && requested.has(usage.executionId)) {
|
|
936
|
+
usageByExecution.get(usage.executionId).push(usage.id);
|
|
939
937
|
}
|
|
940
|
-
return { record: structuredClone(existing), created: false };
|
|
941
|
-
}
|
|
942
|
-
const recordKey = modelCallRecordKey(record.projectId, record.id);
|
|
943
|
-
if (this.records.has(recordKey)) {
|
|
944
|
-
throw new AiUsageStorageError("duplicate_id", `[Sixb] AI usage record '${record.id}' already exists for project '${record.projectId}'.`);
|
|
945
|
-
}
|
|
946
|
-
this.records.set(recordKey, structuredClone(record));
|
|
947
|
-
this.recordKeysByIdempotencyKey.set(idempotencyKey, recordKey);
|
|
948
|
-
for (const groupId of record.requesterGroupIds) {
|
|
949
|
-
const row = {
|
|
950
|
-
projectId: record.projectId,
|
|
951
|
-
usageRecordId: record.id,
|
|
952
|
-
groupId,
|
|
953
|
-
occurredAt: record.occurredAt
|
|
954
|
-
};
|
|
955
|
-
this.groupRows.set(groupRowKey(row), row);
|
|
956
938
|
}
|
|
957
|
-
return
|
|
939
|
+
return input.executionIds.map((id) => this.summarizeUsageIds(input.projectId, usageByExecution.get(id) ?? []));
|
|
958
940
|
}
|
|
959
|
-
async
|
|
960
|
-
|
|
961
|
-
projectId: input.projectId,
|
|
962
|
-
executionIds: [input.executionId]
|
|
963
|
-
});
|
|
964
|
-
return summary;
|
|
941
|
+
async queryProjectOverview(input) {
|
|
942
|
+
return buildAiAccountingOverview(input, await this.accountingItems());
|
|
965
943
|
}
|
|
966
|
-
async
|
|
967
|
-
|
|
968
|
-
throw new TypeError("[Sixb] AI usage projectId must be nonblank.");
|
|
969
|
-
}
|
|
970
|
-
const usageByExecutionId = new Map;
|
|
971
|
-
for (const executionId of input.executionIds) {
|
|
972
|
-
assertAiUsageExecutionId(executionId);
|
|
973
|
-
usageByExecutionId.set(executionId, []);
|
|
974
|
-
}
|
|
975
|
-
if (usageByExecutionId.size === 0)
|
|
976
|
-
return [];
|
|
977
|
-
for (const record of this.records.values()) {
|
|
978
|
-
if (record.projectId !== input.projectId)
|
|
979
|
-
continue;
|
|
980
|
-
usageByExecutionId.get(record.executionId)?.push(record.usage);
|
|
981
|
-
}
|
|
982
|
-
return input.executionIds.map((executionId) => {
|
|
983
|
-
const usages = usageByExecutionId.get(executionId) ?? [];
|
|
984
|
-
return {
|
|
985
|
-
modelCallCount: usages.length,
|
|
986
|
-
usage: aggregateAiModelCallUsage(usages)
|
|
987
|
-
};
|
|
988
|
-
});
|
|
944
|
+
async listModelCalls(input) {
|
|
945
|
+
return buildAiModelCallAccountingList(input, await this.accountingItems());
|
|
989
946
|
}
|
|
990
947
|
snapshot() {
|
|
991
|
-
return structuredClone({
|
|
992
|
-
records: this.records,
|
|
993
|
-
recordKeysByIdempotencyKey: this.recordKeysByIdempotencyKey,
|
|
994
|
-
groupRows: this.groupRows
|
|
995
|
-
});
|
|
948
|
+
return structuredClone({ recordsByUsage: this.recordsByUsage });
|
|
996
949
|
}
|
|
997
950
|
restore(snapshot) {
|
|
998
|
-
replaceMap(this.
|
|
999
|
-
replaceMap(this.recordKeysByIdempotencyKey, snapshot.recordKeysByIdempotencyKey);
|
|
1000
|
-
replaceMap(this.groupRows, snapshot.groupRows);
|
|
951
|
+
replaceMap(this.recordsByUsage, snapshot.recordsByUsage);
|
|
1001
952
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
953
|
+
usageRecord(projectId, id) {
|
|
954
|
+
return [...this.usage.snapshot().records.values()].find((record) => record.projectId === projectId && record.id === id);
|
|
955
|
+
}
|
|
956
|
+
async accountingItems() {
|
|
957
|
+
return Promise.all([...this.usage.snapshot().records.values()].map(async (usage) => {
|
|
958
|
+
const cost = this.recordsByUsage.get(usageRecordKey(usage.projectId, usage.id));
|
|
959
|
+
const attribution = await this.attribution?.resolve({
|
|
960
|
+
projectId: usage.projectId,
|
|
961
|
+
executionId: usage.executionId
|
|
962
|
+
});
|
|
963
|
+
return {
|
|
964
|
+
usage,
|
|
965
|
+
...attribution ? { attribution } : {},
|
|
966
|
+
...cost ? { cost } : {}
|
|
967
|
+
};
|
|
968
|
+
}));
|
|
969
|
+
}
|
|
970
|
+
summarizeUsageIds(projectId, ids) {
|
|
971
|
+
const amounts = new Map;
|
|
972
|
+
let ratedCallCount = 0;
|
|
973
|
+
let unpriceableCallCount = 0;
|
|
974
|
+
let unvaluedCallCount = 0;
|
|
975
|
+
for (const id of ids) {
|
|
976
|
+
const cost = this.recordsByUsage.get(usageRecordKey(projectId, id));
|
|
977
|
+
if (!cost)
|
|
978
|
+
unvaluedCallCount += 1;
|
|
979
|
+
else if (cost.status === "unpriceable")
|
|
980
|
+
unpriceableCallCount += 1;
|
|
981
|
+
else {
|
|
982
|
+
ratedCallCount += 1;
|
|
983
|
+
addMoney(amounts, cost.money);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
return {
|
|
987
|
+
amounts: [...amounts].sort(([left], [right]) => left.localeCompare(right)).map(([currency, amount]) => ({ currency, amountNanos: amount.toString() })),
|
|
988
|
+
ratedCallCount,
|
|
989
|
+
unpriceableCallCount,
|
|
990
|
+
unvaluedCallCount
|
|
991
|
+
};
|
|
1007
992
|
}
|
|
1008
993
|
}
|
|
1009
|
-
function
|
|
1010
|
-
return
|
|
994
|
+
function missingUsage(record) {
|
|
995
|
+
return new AiCostStorageError("missing_usage", `[Sixb] AI usage '${record.usageRecordId}' does not exist in project '${record.projectId}'.`);
|
|
1011
996
|
}
|
|
1012
|
-
function
|
|
1013
|
-
|
|
1014
|
-
record.projectId,
|
|
1015
|
-
record.executionId,
|
|
1016
|
-
record.attempt,
|
|
1017
|
-
record.callId,
|
|
1018
|
-
record.responseId
|
|
1019
|
-
]);
|
|
997
|
+
function addMoney(amounts, money) {
|
|
998
|
+
amounts.set(money.currency, (amounts.get(money.currency) ?? 0n) + BigInt(money.amountNanos));
|
|
1020
999
|
}
|
|
1021
|
-
function
|
|
1022
|
-
return JSON.stringify([
|
|
1000
|
+
function usageRecordKey(projectId, id) {
|
|
1001
|
+
return JSON.stringify([projectId, id]);
|
|
1002
|
+
}
|
|
1003
|
+
function assertNonBlank2(value, field) {
|
|
1004
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
1005
|
+
throw new TypeError(`[Sixb] AI ${field} must be nonblank.`);
|
|
1006
|
+
}
|
|
1023
1007
|
}
|
|
1024
1008
|
function replaceMap(target, source) {
|
|
1025
1009
|
target.clear();
|
|
1026
|
-
for (const [key2, value] of structuredClone(source))
|
|
1010
|
+
for (const [key2, value] of structuredClone(source))
|
|
1027
1011
|
target.set(key2, value);
|
|
1028
|
-
}
|
|
1029
1012
|
}
|
|
1030
1013
|
// src/storage/connector-connections/in-memory.ts
|
|
1031
1014
|
import { timingSafeEqual } from "crypto";
|
|
@@ -2127,6 +2110,110 @@ class InMemoryExecutionStorage {
|
|
|
2127
2110
|
}
|
|
2128
2111
|
}
|
|
2129
2112
|
|
|
2113
|
+
// src/objects/query/scalar-values.ts
|
|
2114
|
+
function compareQueryScalarValues(left, right, scalarKind) {
|
|
2115
|
+
if (left === undefined || right === undefined || left === null || right === null) {
|
|
2116
|
+
return Number.NaN;
|
|
2117
|
+
}
|
|
2118
|
+
if (scalarKind === undefined)
|
|
2119
|
+
return compareRuntimeValues(left, right);
|
|
2120
|
+
switch (scalarKind) {
|
|
2121
|
+
case "string":
|
|
2122
|
+
case "uuid":
|
|
2123
|
+
return typeof left === "string" && typeof right === "string" ? compareStrings(left, right) : Number.NaN;
|
|
2124
|
+
case "boolean":
|
|
2125
|
+
return typeof left === "boolean" && typeof right === "boolean" ? Number(left) - Number(right) : Number.NaN;
|
|
2126
|
+
case "integer":
|
|
2127
|
+
case "double":
|
|
2128
|
+
return typeof left === "number" && typeof right === "number" ? left - right : Number.NaN;
|
|
2129
|
+
case "decimal":
|
|
2130
|
+
return typeof left === "string" && typeof right === "string" ? compareDecimalValues(left, right) : Number.NaN;
|
|
2131
|
+
case "date":
|
|
2132
|
+
case "timestamp":
|
|
2133
|
+
return compareTemporalValues(left, right);
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
function queryScalarValuesEqual(left, right, scalarKind) {
|
|
2137
|
+
if (scalarKind === "decimal") {
|
|
2138
|
+
const comparison = compareQueryScalarValues(left, right, scalarKind);
|
|
2139
|
+
return !Number.isNaN(comparison) && comparison === 0;
|
|
2140
|
+
}
|
|
2141
|
+
if (scalarKind === "date" || scalarKind === "timestamp") {
|
|
2142
|
+
const comparison = compareTemporalValues(left, right);
|
|
2143
|
+
return !Number.isNaN(comparison) && comparison === 0;
|
|
2144
|
+
}
|
|
2145
|
+
if (scalarKind !== undefined)
|
|
2146
|
+
return Object.is(left, right);
|
|
2147
|
+
return runtimeValuesEqual(left, right);
|
|
2148
|
+
}
|
|
2149
|
+
function compareRuntimeValues(left, right) {
|
|
2150
|
+
if (typeof left === "number" && typeof right === "number")
|
|
2151
|
+
return left - right;
|
|
2152
|
+
if (typeof left === "string" && typeof right === "string")
|
|
2153
|
+
return compareStrings(left, right);
|
|
2154
|
+
if (typeof left === "boolean" && typeof right === "boolean") {
|
|
2155
|
+
return Number(left) - Number(right);
|
|
2156
|
+
}
|
|
2157
|
+
if (left instanceof Date || right instanceof Date)
|
|
2158
|
+
return compareTemporalValues(left, right);
|
|
2159
|
+
return Number.NaN;
|
|
2160
|
+
}
|
|
2161
|
+
function runtimeValuesEqual(left, right) {
|
|
2162
|
+
if (left instanceof Date || right instanceof Date) {
|
|
2163
|
+
const comparison = compareTemporalValues(left, right);
|
|
2164
|
+
return !Number.isNaN(comparison) && comparison === 0;
|
|
2165
|
+
}
|
|
2166
|
+
return Object.is(left, right);
|
|
2167
|
+
}
|
|
2168
|
+
function compareTemporalValues(left, right) {
|
|
2169
|
+
const leftTime = dateTime(left);
|
|
2170
|
+
const rightTime = dateTime(right);
|
|
2171
|
+
if (leftTime === null || rightTime === null)
|
|
2172
|
+
return Number.NaN;
|
|
2173
|
+
return leftTime - rightTime;
|
|
2174
|
+
}
|
|
2175
|
+
function dateTime(value) {
|
|
2176
|
+
if (value instanceof Date) {
|
|
2177
|
+
const time = value.getTime();
|
|
2178
|
+
return Number.isNaN(time) ? null : time;
|
|
2179
|
+
}
|
|
2180
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
2181
|
+
const time = new Date(value).getTime();
|
|
2182
|
+
return Number.isNaN(time) ? null : time;
|
|
2183
|
+
}
|
|
2184
|
+
return null;
|
|
2185
|
+
}
|
|
2186
|
+
function compareStrings(left, right) {
|
|
2187
|
+
if (left < right)
|
|
2188
|
+
return -1;
|
|
2189
|
+
if (left > right)
|
|
2190
|
+
return 1;
|
|
2191
|
+
return 0;
|
|
2192
|
+
}
|
|
2193
|
+
|
|
2194
|
+
// src/storage/objects/keys.ts
|
|
2195
|
+
function objectBatchKey(objectTypeId, primaryId) {
|
|
2196
|
+
return JSON.stringify([objectTypeId, primaryId]);
|
|
2197
|
+
}
|
|
2198
|
+
function linkBatchKey(objectTypeId, objectId, linkId) {
|
|
2199
|
+
return JSON.stringify([objectTypeId, objectId, linkId]);
|
|
2200
|
+
}
|
|
2201
|
+
function objectLinkCursor(link) {
|
|
2202
|
+
return [link.sourceTypeId, link.sourceId, link.linkId, link.targetTypeId, link.targetId];
|
|
2203
|
+
}
|
|
2204
|
+
function compareObjectLinkCursors(left, right) {
|
|
2205
|
+
for (let index = 0;index < left.length; index += 1) {
|
|
2206
|
+
if (left[index] < right[index])
|
|
2207
|
+
return -1;
|
|
2208
|
+
if (left[index] > right[index])
|
|
2209
|
+
return 1;
|
|
2210
|
+
}
|
|
2211
|
+
return 0;
|
|
2212
|
+
}
|
|
2213
|
+
function compareObjectLinks(left, right) {
|
|
2214
|
+
return compareObjectLinkCursors(objectLinkCursor(left), objectLinkCursor(right));
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2130
2217
|
// src/storage/objects/in-memory.ts
|
|
2131
2218
|
var IN_MEMORY_OBJECT_QUERY_CAPABILITIES = {
|
|
2132
2219
|
queryObjects: true,
|
|
@@ -2135,6 +2222,7 @@ var IN_MEMORY_OBJECT_QUERY_CAPABILITIES = {
|
|
|
2135
2222
|
facetObjects: true,
|
|
2136
2223
|
nodes: {
|
|
2137
2224
|
start: true,
|
|
2225
|
+
refs: true,
|
|
2138
2226
|
filter: true,
|
|
2139
2227
|
text: true,
|
|
2140
2228
|
vector: true,
|
|
@@ -2188,23 +2276,37 @@ var IN_MEMORY_OBJECT_QUERY_CAPABILITIES = {
|
|
|
2188
2276
|
}
|
|
2189
2277
|
};
|
|
2190
2278
|
function objectRowKey(projectId, objectTypeId) {
|
|
2191
|
-
return
|
|
2279
|
+
return JSON.stringify([projectId, objectTypeId]);
|
|
2192
2280
|
}
|
|
2193
|
-
function
|
|
2281
|
+
function objectRowProjectPrefix(projectId) {
|
|
2282
|
+
return `[${JSON.stringify(projectId)},`;
|
|
2283
|
+
}
|
|
2284
|
+
function compareStrings2(left, right) {
|
|
2194
2285
|
if (left < right)
|
|
2195
2286
|
return -1;
|
|
2196
2287
|
if (left > right)
|
|
2197
2288
|
return 1;
|
|
2198
2289
|
return 0;
|
|
2199
2290
|
}
|
|
2291
|
+
function assertLinkQueryLimit(limit) {
|
|
2292
|
+
if (!Number.isSafeInteger(limit) || limit <= 0) {
|
|
2293
|
+
throw new Error("Object link query limit must be a positive safe integer.");
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2200
2296
|
function sourceLinkBucketKey(projectId, sourceTypeId, sourceId) {
|
|
2201
|
-
return
|
|
2297
|
+
return JSON.stringify([projectId, sourceTypeId, sourceId]);
|
|
2202
2298
|
}
|
|
2203
2299
|
function linkRowKey(linkId, targetTypeId, targetId) {
|
|
2204
|
-
return
|
|
2300
|
+
return JSON.stringify([linkId, targetTypeId, targetId]);
|
|
2205
2301
|
}
|
|
2206
2302
|
function fullLinkRowKey(row) {
|
|
2207
|
-
return
|
|
2303
|
+
return JSON.stringify([
|
|
2304
|
+
row.sourceTypeId,
|
|
2305
|
+
row.sourceId,
|
|
2306
|
+
row.linkId,
|
|
2307
|
+
row.targetTypeId,
|
|
2308
|
+
row.targetId
|
|
2309
|
+
]);
|
|
2208
2310
|
}
|
|
2209
2311
|
var PAGE_TOKEN_PREFIX = "offset:";
|
|
2210
2312
|
var materializerAdapters = new WeakMap;
|
|
@@ -2339,6 +2441,8 @@ class InMemoryObjectStorage {
|
|
|
2339
2441
|
switch (query.kind) {
|
|
2340
2442
|
case "start":
|
|
2341
2443
|
return this.evaluateStart(projectId, query.objectTypeId);
|
|
2444
|
+
case "refs":
|
|
2445
|
+
return this.evaluateRefs(projectId, query.refs);
|
|
2342
2446
|
case "filter": {
|
|
2343
2447
|
const input = this.evaluateObjectQuery(projectId, query.input);
|
|
2344
2448
|
const entries = input.entries.filter((entry) => matchesPredicate(entry.row, query.predicate));
|
|
@@ -2428,6 +2532,18 @@ class InMemoryObjectStorage {
|
|
|
2428
2532
|
}));
|
|
2429
2533
|
return completeEvaluation(entries);
|
|
2430
2534
|
}
|
|
2535
|
+
evaluateRefs(projectId, refs) {
|
|
2536
|
+
const seen = new Set;
|
|
2537
|
+
const entries = refs.flatMap((ref) => {
|
|
2538
|
+
const key2 = JSON.stringify([ref.objectTypeId, ref.primaryId]);
|
|
2539
|
+
if (seen.has(key2))
|
|
2540
|
+
return [];
|
|
2541
|
+
seen.add(key2);
|
|
2542
|
+
const row = this.rows.get(objectRowKey(projectId, ref.objectTypeId))?.get(ref.primaryId);
|
|
2543
|
+
return row ? [row] : [];
|
|
2544
|
+
}).sort((left, right) => compareStrings2(left.objectTypeId, right.objectTypeId) || compareStrings2(left.primaryId, right.primaryId)).map((row, order) => ({ row, score: 0, order }));
|
|
2545
|
+
return completeEvaluation(entries);
|
|
2546
|
+
}
|
|
2431
2547
|
evaluateSet(projectId, op, inputs) {
|
|
2432
2548
|
const evaluations = inputs.map((input) => this.evaluateObjectQuery(projectId, input));
|
|
2433
2549
|
const first = evaluations[0];
|
|
@@ -2535,7 +2651,7 @@ class InMemoryObjectStorage {
|
|
|
2535
2651
|
primaryId: item.primaryId
|
|
2536
2652
|
});
|
|
2537
2653
|
if (row) {
|
|
2538
|
-
result.set(
|
|
2654
|
+
result.set(objectBatchKey(item.objectTypeId, item.primaryId), row);
|
|
2539
2655
|
}
|
|
2540
2656
|
}
|
|
2541
2657
|
return result;
|
|
@@ -2550,11 +2666,39 @@ class InMemoryObjectStorage {
|
|
|
2550
2666
|
linkId: item.linkId
|
|
2551
2667
|
});
|
|
2552
2668
|
if (rows.length > 0) {
|
|
2553
|
-
result.set(
|
|
2669
|
+
result.set(linkBatchKey(item.objectTypeId, item.objectId, item.linkId), [...rows]);
|
|
2554
2670
|
}
|
|
2555
2671
|
}
|
|
2556
2672
|
return result;
|
|
2557
2673
|
}
|
|
2674
|
+
async queryLinks(params) {
|
|
2675
|
+
assertLinkQueryLimit(params.limit);
|
|
2676
|
+
if (params.objectRefs.length === 0 || params.endpointObjectTypeIds?.length === 0) {
|
|
2677
|
+
return { links: [], hasMore: false };
|
|
2678
|
+
}
|
|
2679
|
+
const allowedTypes = params.endpointObjectTypeIds ? new Set(params.endpointObjectTypeIds) : undefined;
|
|
2680
|
+
const deduped = new Map;
|
|
2681
|
+
for (const object of params.objectRefs) {
|
|
2682
|
+
const rows2 = await this.listLinks({
|
|
2683
|
+
projectId: params.projectId,
|
|
2684
|
+
objectTypeId: object.objectTypeId,
|
|
2685
|
+
objectId: object.primaryId,
|
|
2686
|
+
direction: params.direction,
|
|
2687
|
+
...params.linkId === undefined ? {} : { linkId: params.linkId }
|
|
2688
|
+
});
|
|
2689
|
+
for (const row of rows2) {
|
|
2690
|
+
if (allowedTypes && (!allowedTypes.has(row.sourceTypeId) || !allowedTypes.has(row.targetTypeId))) {
|
|
2691
|
+
continue;
|
|
2692
|
+
}
|
|
2693
|
+
if (params.after && compareObjectLinkCursors(objectLinkCursor(row), params.after) <= 0) {
|
|
2694
|
+
continue;
|
|
2695
|
+
}
|
|
2696
|
+
deduped.set(fullLinkRowKey(row), row);
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
const rows = [...deduped.values()].sort(compareObjectLinks).slice(0, params.limit + 1);
|
|
2700
|
+
return { links: rows.slice(0, params.limit), hasMore: rows.length > params.limit };
|
|
2701
|
+
}
|
|
2558
2702
|
async listIncidentLinksBatch(params) {
|
|
2559
2703
|
const deduped = new Map;
|
|
2560
2704
|
for (const item of params.items) {
|
|
@@ -2573,7 +2717,7 @@ class InMemoryObjectStorage {
|
|
|
2573
2717
|
async listByPrimaryIdPage(params) {
|
|
2574
2718
|
assertReconciliationPageLimit(params.limit);
|
|
2575
2719
|
const bucket = this.rows.get(objectRowKey(params.projectId, params.objectTypeId));
|
|
2576
|
-
const rows = [...bucket?.values() ?? []].filter((row) => !params.afterPrimaryId ||
|
|
2720
|
+
const rows = [...bucket?.values() ?? []].filter((row) => !params.afterPrimaryId || compareStrings2(row.primaryId, params.afterPrimaryId) > 0).sort((left, right) => compareStrings2(left.primaryId, right.primaryId)).slice(0, params.limit + 1);
|
|
2577
2721
|
const hasMore = rows.length > params.limit;
|
|
2578
2722
|
const objects = rows.slice(0, params.limit).map((row) => structuredClone(row));
|
|
2579
2723
|
const last = objects.at(-1);
|
|
@@ -2594,7 +2738,7 @@ class InMemoryObjectStorage {
|
|
|
2594
2738
|
}
|
|
2595
2739
|
} else {
|
|
2596
2740
|
for (const [key2, bucket] of this.rows) {
|
|
2597
|
-
if (key2.startsWith(
|
|
2741
|
+
if (key2.startsWith(objectRowProjectPrefix(params.projectId))) {
|
|
2598
2742
|
allRows.push(...bucket.values());
|
|
2599
2743
|
}
|
|
2600
2744
|
}
|
|
@@ -2860,7 +3004,7 @@ function rowIdentityKey(row) {
|
|
|
2860
3004
|
return rowIdentityKeyParts(row.objectTypeId, row.primaryId);
|
|
2861
3005
|
}
|
|
2862
3006
|
function rowIdentityKeyParts(objectTypeId, primaryId) {
|
|
2863
|
-
return
|
|
3007
|
+
return objectBatchKey(objectTypeId, primaryId);
|
|
2864
3008
|
}
|
|
2865
3009
|
function upsertEntry(entriesByKey, entry) {
|
|
2866
3010
|
const key2 = rowIdentityKey(entry.row);
|
|
@@ -3949,6 +4093,7 @@ class InMemoryOntologyMaterializationStorage {
|
|
|
3949
4093
|
projectId,
|
|
3950
4094
|
ref: item.ref,
|
|
3951
4095
|
value: item.value,
|
|
4096
|
+
editedAt: { ...item.editedAt },
|
|
3952
4097
|
lastCommitId: item.lastCommitId,
|
|
3953
4098
|
updatedAt: item.updatedAt
|
|
3954
4099
|
}));
|
|
@@ -6659,6 +6804,9 @@ class InMemoryStorage {
|
|
|
6659
6804
|
executionStorage = new InMemoryExecutionStorage(this.authStorage);
|
|
6660
6805
|
agentStorage = new InMemoryAgentStorage(this.executionStorage);
|
|
6661
6806
|
aiUsageStorage = new InMemoryAiUsageStorage(this.executionStorage);
|
|
6807
|
+
aiCostStorage = new InMemoryAiCostStorage(this.aiUsageStorage, {
|
|
6808
|
+
resolve: (input) => this.resolveAiAccountingAttribution(input)
|
|
6809
|
+
});
|
|
6662
6810
|
actionRunStorage = new InMemoryActionRunStorage(this.executionStorage);
|
|
6663
6811
|
syncRunStorage = new InMemorySyncRunStorage(this.executionStorage);
|
|
6664
6812
|
pipelineRunStorage = new InMemoryPipelineRunStorage(this.executionStorage);
|
|
@@ -6675,6 +6823,7 @@ class InMemoryStorage {
|
|
|
6675
6823
|
executions;
|
|
6676
6824
|
agents;
|
|
6677
6825
|
aiUsage;
|
|
6826
|
+
aiCosts;
|
|
6678
6827
|
actionRuns;
|
|
6679
6828
|
syncRuns;
|
|
6680
6829
|
pipelineRuns;
|
|
@@ -6694,6 +6843,7 @@ class InMemoryStorage {
|
|
|
6694
6843
|
this.executions = createOperationScopedFacade(this.executionStorage, scope);
|
|
6695
6844
|
this.agents = createAgentOperationScope(this.agentStorage, scope);
|
|
6696
6845
|
this.aiUsage = createOperationScopedFacade(this.aiUsageStorage, scope);
|
|
6846
|
+
this.aiCosts = createOperationScopedFacade(this.aiCostStorage, scope);
|
|
6697
6847
|
this.actionRuns = createOperationScopedFacade(this.actionRunStorage, scope);
|
|
6698
6848
|
this.syncRuns = createOperationScopedFacade(this.syncRunStorage, scope);
|
|
6699
6849
|
this.pipelineRuns = createOperationScopedFacade(this.pipelineRunStorage, scope);
|
|
@@ -6715,6 +6865,45 @@ class InMemoryStorage {
|
|
|
6715
6865
|
this.ontologyStorage.registerTestingAlias(this.ontology);
|
|
6716
6866
|
registerInMemoryStorageTestingAdapter(this, { snapshot: () => this.snapshot() });
|
|
6717
6867
|
}
|
|
6868
|
+
async resolveAiAccountingAttribution(input) {
|
|
6869
|
+
const execution = await this.executionStorage.getById({
|
|
6870
|
+
projectId: input.projectId,
|
|
6871
|
+
id: input.executionId
|
|
6872
|
+
});
|
|
6873
|
+
if (!execution || execution.executor.type !== "agent")
|
|
6874
|
+
return;
|
|
6875
|
+
const directRun = await this.agentStorage.runs.getById({
|
|
6876
|
+
projectId: input.projectId,
|
|
6877
|
+
id: execution.executor.runId
|
|
6878
|
+
});
|
|
6879
|
+
if (directRun) {
|
|
6880
|
+
return {
|
|
6881
|
+
kind: "agent",
|
|
6882
|
+
agentId: directRun.agentId,
|
|
6883
|
+
agentRunId: directRun.id,
|
|
6884
|
+
threadId: directRun.threadId
|
|
6885
|
+
};
|
|
6886
|
+
}
|
|
6887
|
+
const agentRun = await this.workflowRunStorage.agentNodes.getByNodeRunId({
|
|
6888
|
+
projectId: input.projectId,
|
|
6889
|
+
nodeRunId: execution.executor.runId
|
|
6890
|
+
});
|
|
6891
|
+
if (!agentRun)
|
|
6892
|
+
return;
|
|
6893
|
+
const node = await this.workflowRunStorage.nodes.getById({
|
|
6894
|
+
projectId: input.projectId,
|
|
6895
|
+
id: agentRun.nodeRunId
|
|
6896
|
+
});
|
|
6897
|
+
if (!node)
|
|
6898
|
+
return;
|
|
6899
|
+
return {
|
|
6900
|
+
kind: "workflowAgent",
|
|
6901
|
+
agentId: agentRun.agentId,
|
|
6902
|
+
nodeRunId: agentRun.nodeRunId,
|
|
6903
|
+
workflowId: node.workflowId,
|
|
6904
|
+
workflowRunId: node.workflowRunId
|
|
6905
|
+
};
|
|
6906
|
+
}
|
|
6718
6907
|
transactionScope = new AsyncLocalStorage;
|
|
6719
6908
|
activeTransactionTokens = new WeakSet;
|
|
6720
6909
|
materializationLifecycles = new WeakMap;
|
|
@@ -6795,6 +6984,7 @@ class InMemoryStorage {
|
|
|
6795
6984
|
executions: this.executionStorage,
|
|
6796
6985
|
agents: this.agentStorage,
|
|
6797
6986
|
aiUsage: this.aiUsageStorage,
|
|
6987
|
+
aiCosts: this.aiCostStorage,
|
|
6798
6988
|
actionRuns: this.actionRunStorage,
|
|
6799
6989
|
syncRuns: this.syncRunStorage,
|
|
6800
6990
|
pipelineRuns: this.pipelineRunStorage,
|
|
@@ -6822,6 +7012,7 @@ class InMemoryStorage {
|
|
|
6822
7012
|
executions: this.executionStorage.snapshot(),
|
|
6823
7013
|
agents: this.agentStorage.snapshot(),
|
|
6824
7014
|
aiUsage: this.aiUsageStorage.snapshot(),
|
|
7015
|
+
aiCosts: this.aiCostStorage.snapshot(),
|
|
6825
7016
|
actionRuns: this.actionRunStorage.snapshot(),
|
|
6826
7017
|
syncRuns: this.syncRunStorage.snapshot(),
|
|
6827
7018
|
pipelineRuns: this.pipelineRunStorage.snapshot(),
|
|
@@ -6842,6 +7033,7 @@ class InMemoryStorage {
|
|
|
6842
7033
|
this.executionStorage.restore(snapshot.executions);
|
|
6843
7034
|
this.agentStorage.restore(snapshot.agents);
|
|
6844
7035
|
this.aiUsageStorage.restore(snapshot.aiUsage);
|
|
7036
|
+
this.aiCostStorage.restore(snapshot.aiCosts);
|
|
6845
7037
|
this.actionRunStorage.restore(snapshot.actionRuns);
|
|
6846
7038
|
this.syncRunStorage.restore(snapshot.syncRuns);
|
|
6847
7039
|
this.pipelineRunStorage.restore(snapshot.pipelineRuns);
|
|
@@ -7063,6 +7255,6 @@ function assertAppliedPrefix(migrations, rows) {
|
|
|
7063
7255
|
}
|
|
7064
7256
|
return [...rows].sort((a, b) => a.version - b.version);
|
|
7065
7257
|
}
|
|
7066
|
-
export { actionSubjectsEqual, actionRunParamsEqual, actionRunPhaseRecordsEqual, finishActionRunPhase, canRequeueActionRunAfterEnqueueFailure, isTerminalActionRun, InMemoryActionRunStorage, AGENT_MESSAGE_CONTENT_VERSION, InMemoryAgentStorage,
|
|
7258
|
+
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 };
|
|
7067
7259
|
|
|
7068
|
-
//# debugId=
|
|
7260
|
+
//# debugId=0AE8BF2E3686BC2F64756E2164756E21
|