@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
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { AiBillableMeter, AiModelCallCostRecord, AiPricingContext } from "./types"
|
|
2
|
+
import { normalizeAiPricingContext } from "./validation"
|
|
3
|
+
|
|
4
|
+
export interface AiModelCallCostDetails {
|
|
5
|
+
readonly pricingContext: AiPricingContext
|
|
6
|
+
readonly priceSource: Omit<AiModelCallCostRecord["priceSource"], "observedAt"> & {
|
|
7
|
+
readonly observedAt: string
|
|
8
|
+
}
|
|
9
|
+
readonly components?: Extract<AiModelCallCostRecord, { status: "rated" }>["components"]
|
|
10
|
+
readonly missingMeters?: readonly AiBillableMeter[]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function aiModelCallCostDetails(record: AiModelCallCostRecord): AiModelCallCostDetails {
|
|
14
|
+
return {
|
|
15
|
+
pricingContext: record.pricingContext,
|
|
16
|
+
priceSource: { ...record.priceSource, observedAt: record.priceSource.observedAt.toISOString() },
|
|
17
|
+
...(record.status === "rated" ? { components: record.components } : {}),
|
|
18
|
+
...(record.status === "unpriceable" && record.missingMeters
|
|
19
|
+
? { missingMeters: record.missingMeters }
|
|
20
|
+
: {}),
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function parseAiModelCallCostDetails(value: unknown): AiModelCallCostDetails {
|
|
25
|
+
const parsed: unknown = typeof value === "string" ? JSON.parse(value) : value
|
|
26
|
+
if (!isRecord(parsed)) throw invalidDetails()
|
|
27
|
+
const priceSource = parsed.priceSource
|
|
28
|
+
if (!isRecord(priceSource)) throw invalidDetails()
|
|
29
|
+
const components = parsed.components
|
|
30
|
+
const missingMeters = parsed.missingMeters
|
|
31
|
+
return {
|
|
32
|
+
pricingContext: pricingContextFromUnknown(parsed.pricingContext),
|
|
33
|
+
priceSource: {
|
|
34
|
+
sourceId: requiredString(priceSource.sourceId),
|
|
35
|
+
sourceEntryId: requiredString(priceSource.sourceEntryId),
|
|
36
|
+
sourceVersion: requiredString(priceSource.sourceVersion),
|
|
37
|
+
sourceUrl: requiredString(priceSource.sourceUrl),
|
|
38
|
+
observedAt: requiredString(priceSource.observedAt),
|
|
39
|
+
},
|
|
40
|
+
...(components === undefined ? {} : { components: costComponentsFromUnknown(components) }),
|
|
41
|
+
...(missingMeters === undefined ? {} : { missingMeters: metersFromUnknown(missingMeters) }),
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function pricingContextFromUnknown(value: unknown): AiPricingContext {
|
|
46
|
+
if (!isRecord(value)) throw invalidDetails()
|
|
47
|
+
return normalizeAiPricingContext({
|
|
48
|
+
...optionalStringProperty(value, "serviceTier"),
|
|
49
|
+
...optionalBooleanProperty(value, "batch"),
|
|
50
|
+
...optionalStringProperty(value, "region"),
|
|
51
|
+
...optionalStringProperty(value, "inferenceGeo"),
|
|
52
|
+
...optionalStringProperty(value, "routedProviderId"),
|
|
53
|
+
...optionalStringProperty(value, "deploymentId"),
|
|
54
|
+
...optionalStringProperty(value, "inferenceProfileId"),
|
|
55
|
+
...optionalNumberProperty(value, "cacheWriteTtlSeconds"),
|
|
56
|
+
...optionalStringProperty(value, "mode"),
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function costComponentsFromUnknown(
|
|
61
|
+
value: unknown
|
|
62
|
+
): Extract<AiModelCallCostRecord, { status: "rated" }>["components"] {
|
|
63
|
+
if (!Array.isArray(value)) throw invalidDetails()
|
|
64
|
+
return value.map((component) => {
|
|
65
|
+
if (!isRecord(component)) throw invalidDetails()
|
|
66
|
+
return {
|
|
67
|
+
meter: billableMeter(component.meter),
|
|
68
|
+
quantity: requiredString(component.quantity),
|
|
69
|
+
rateAmountNanosPerMillion: requiredString(component.rateAmountNanosPerMillion),
|
|
70
|
+
chargeAmountNanos: requiredString(component.chargeAmountNanos),
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function metersFromUnknown(value: unknown): readonly AiBillableMeter[] {
|
|
76
|
+
if (!Array.isArray(value)) throw invalidDetails()
|
|
77
|
+
return value.map(billableMeter)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function billableMeter(value: unknown): AiBillableMeter {
|
|
81
|
+
if (
|
|
82
|
+
value !== "tokens.input.total" &&
|
|
83
|
+
value !== "tokens.input.uncached" &&
|
|
84
|
+
value !== "tokens.input.cacheRead" &&
|
|
85
|
+
value !== "tokens.input.cacheWrite" &&
|
|
86
|
+
value !== "tokens.output.total" &&
|
|
87
|
+
value !== "tokens.output.text" &&
|
|
88
|
+
value !== "tokens.output.reasoning"
|
|
89
|
+
) {
|
|
90
|
+
throw invalidDetails()
|
|
91
|
+
}
|
|
92
|
+
return value
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function optionalStringProperty(
|
|
96
|
+
value: Record<string, unknown>,
|
|
97
|
+
name: string
|
|
98
|
+
): Record<string, string> {
|
|
99
|
+
const property = value[name]
|
|
100
|
+
if (property === undefined) return {}
|
|
101
|
+
if (typeof property !== "string") throw invalidDetails()
|
|
102
|
+
return { [name]: property }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function optionalBooleanProperty(
|
|
106
|
+
value: Record<string, unknown>,
|
|
107
|
+
name: string
|
|
108
|
+
): Record<string, boolean> {
|
|
109
|
+
const property = value[name]
|
|
110
|
+
if (property === undefined) return {}
|
|
111
|
+
if (typeof property !== "boolean") throw invalidDetails()
|
|
112
|
+
return { [name]: property }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function optionalNumberProperty(
|
|
116
|
+
value: Record<string, unknown>,
|
|
117
|
+
name: string
|
|
118
|
+
): Record<string, number> {
|
|
119
|
+
const property = value[name]
|
|
120
|
+
if (property === undefined) return {}
|
|
121
|
+
if (typeof property !== "number") throw invalidDetails()
|
|
122
|
+
return { [name]: property }
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function requiredString(value: unknown): string {
|
|
126
|
+
if (typeof value !== "string") throw invalidDetails()
|
|
127
|
+
return value
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
131
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function invalidDetails(): Error {
|
|
135
|
+
return new Error("[Sixb] AI valuation details are invalid.")
|
|
136
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type AiCostStorageErrorCode = "missing_usage" | "cost_mismatch"
|
|
2
|
+
|
|
3
|
+
export class AiCostStorageError extends Error {
|
|
4
|
+
readonly name = "AiCostStorageError"
|
|
5
|
+
|
|
6
|
+
constructor(
|
|
7
|
+
readonly code: AiCostStorageErrorCode,
|
|
8
|
+
message: string
|
|
9
|
+
) {
|
|
10
|
+
super(message)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type { AiModelCallUsageRecord, InMemoryAiUsageStorageSnapshot } from "../ai-usage"
|
|
2
|
+
import type { AiAccountingRecordSetItem } from "./analytics"
|
|
3
|
+
import { buildAiAccountingOverview, buildAiModelCallAccountingList } from "./analytics"
|
|
4
|
+
import { AiCostStorageError } from "./errors"
|
|
5
|
+
import type {
|
|
6
|
+
AiAccountingAttribution,
|
|
7
|
+
AiAccountingOverview,
|
|
8
|
+
AiCostStorage,
|
|
9
|
+
AiCostSummary,
|
|
10
|
+
AiModelCallCostRecord,
|
|
11
|
+
AiMoney,
|
|
12
|
+
ListAiModelCallAccountingInput,
|
|
13
|
+
ListAiModelCallAccountingResult,
|
|
14
|
+
QueryAiAccountingOverviewInput,
|
|
15
|
+
SummarizeAiCostExecutionsInput,
|
|
16
|
+
} from "./types"
|
|
17
|
+
import { aiModelCallCostMatchesUsage, normalizeAiModelCallCostRecord } from "./validation"
|
|
18
|
+
|
|
19
|
+
export interface InMemoryAiCostStorageSnapshot {
|
|
20
|
+
readonly recordsByUsage: Map<string, AiModelCallCostRecord>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface InMemoryAiCostUsageSource {
|
|
24
|
+
snapshot(): InMemoryAiUsageStorageSnapshot
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface InMemoryAiAccountingAttributionSource {
|
|
28
|
+
resolve(input: {
|
|
29
|
+
readonly projectId: string
|
|
30
|
+
readonly executionId: string
|
|
31
|
+
}): Promise<AiAccountingAttribution | undefined>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** In-memory immutable model-call costs and accounting reads. */
|
|
35
|
+
export class InMemoryAiCostStorage implements AiCostStorage {
|
|
36
|
+
private readonly recordsByUsage = new Map<string, AiModelCallCostRecord>()
|
|
37
|
+
|
|
38
|
+
constructor(
|
|
39
|
+
private readonly usage: InMemoryAiCostUsageSource,
|
|
40
|
+
private readonly attribution?: InMemoryAiAccountingAttributionSource
|
|
41
|
+
) {}
|
|
42
|
+
|
|
43
|
+
async recordModelCallCost(input: AiModelCallCostRecord): Promise<void> {
|
|
44
|
+
const record = normalizeAiModelCallCostRecord(input)
|
|
45
|
+
const usage = this.usageRecord(record.projectId, record.usageRecordId)
|
|
46
|
+
if (!usage) throw missingUsage(record)
|
|
47
|
+
if (!aiModelCallCostMatchesUsage(record, usage)) {
|
|
48
|
+
throw new AiCostStorageError(
|
|
49
|
+
"cost_mismatch",
|
|
50
|
+
`[Sixb] AI valuation for usage '${record.usageRecordId}' does not match its usage record.`
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
const key = usageRecordKey(record.projectId, record.usageRecordId)
|
|
54
|
+
if (!this.recordsByUsage.has(key)) this.recordsByUsage.set(key, structuredClone(record))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async summarizeExecutions(
|
|
58
|
+
input: SummarizeAiCostExecutionsInput
|
|
59
|
+
): Promise<readonly AiCostSummary[]> {
|
|
60
|
+
assertNonBlank(input.projectId, "cost summary projectId")
|
|
61
|
+
for (const id of input.executionIds) assertNonBlank(id, "cost summary executionId")
|
|
62
|
+
const requested = new Set(input.executionIds)
|
|
63
|
+
const usageByExecution = new Map(input.executionIds.map((id) => [id, [] as string[]]))
|
|
64
|
+
for (const usage of this.usage.snapshot().records.values()) {
|
|
65
|
+
if (usage.projectId === input.projectId && requested.has(usage.executionId)) {
|
|
66
|
+
usageByExecution.get(usage.executionId)!.push(usage.id)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return input.executionIds.map((id) =>
|
|
70
|
+
this.summarizeUsageIds(input.projectId, usageByExecution.get(id) ?? [])
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async queryProjectOverview(input: QueryAiAccountingOverviewInput): Promise<AiAccountingOverview> {
|
|
75
|
+
return buildAiAccountingOverview(input, await this.accountingItems())
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async listModelCalls(
|
|
79
|
+
input: ListAiModelCallAccountingInput
|
|
80
|
+
): Promise<ListAiModelCallAccountingResult> {
|
|
81
|
+
return buildAiModelCallAccountingList(input, await this.accountingItems())
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
snapshot(): InMemoryAiCostStorageSnapshot {
|
|
85
|
+
return structuredClone({ recordsByUsage: this.recordsByUsage })
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
restore(snapshot: InMemoryAiCostStorageSnapshot): void {
|
|
89
|
+
replaceMap(this.recordsByUsage, snapshot.recordsByUsage)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private usageRecord(projectId: string, id: string): AiModelCallUsageRecord | undefined {
|
|
93
|
+
return [...this.usage.snapshot().records.values()].find(
|
|
94
|
+
(record) => record.projectId === projectId && record.id === id
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private async accountingItems(): Promise<readonly AiAccountingRecordSetItem[]> {
|
|
99
|
+
return Promise.all(
|
|
100
|
+
[...this.usage.snapshot().records.values()].map(async (usage) => {
|
|
101
|
+
const cost = this.recordsByUsage.get(usageRecordKey(usage.projectId, usage.id))
|
|
102
|
+
const attribution = await this.attribution?.resolve({
|
|
103
|
+
projectId: usage.projectId,
|
|
104
|
+
executionId: usage.executionId,
|
|
105
|
+
})
|
|
106
|
+
return {
|
|
107
|
+
usage,
|
|
108
|
+
...(attribution ? { attribution } : {}),
|
|
109
|
+
...(cost ? { cost } : {}),
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private summarizeUsageIds(projectId: string, ids: readonly string[]): AiCostSummary {
|
|
116
|
+
const amounts = new Map<string, bigint>()
|
|
117
|
+
let ratedCallCount = 0
|
|
118
|
+
let unpriceableCallCount = 0
|
|
119
|
+
let unvaluedCallCount = 0
|
|
120
|
+
for (const id of ids) {
|
|
121
|
+
const cost = this.recordsByUsage.get(usageRecordKey(projectId, id))
|
|
122
|
+
if (!cost) unvaluedCallCount += 1
|
|
123
|
+
else if (cost.status === "unpriceable") unpriceableCallCount += 1
|
|
124
|
+
else {
|
|
125
|
+
ratedCallCount += 1
|
|
126
|
+
addMoney(amounts, cost.money)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
amounts: [...amounts]
|
|
131
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
132
|
+
.map(([currency, amount]) => ({ currency, amountNanos: amount.toString() })),
|
|
133
|
+
ratedCallCount,
|
|
134
|
+
unpriceableCallCount,
|
|
135
|
+
unvaluedCallCount,
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function missingUsage(record: { readonly projectId: string; readonly usageRecordId: string }) {
|
|
141
|
+
return new AiCostStorageError(
|
|
142
|
+
"missing_usage",
|
|
143
|
+
`[Sixb] AI usage '${record.usageRecordId}' does not exist in project '${record.projectId}'.`
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function addMoney(amounts: Map<string, bigint>, money: AiMoney): void {
|
|
148
|
+
amounts.set(money.currency, (amounts.get(money.currency) ?? 0n) + BigInt(money.amountNanos))
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function usageRecordKey(projectId: string, id: string): string {
|
|
152
|
+
return JSON.stringify([projectId, id])
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function assertNonBlank(value: string, field: string): void {
|
|
156
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
157
|
+
throw new TypeError(`[Sixb] AI ${field} must be nonblank.`)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function replaceMap<TKey, TValue>(target: Map<TKey, TValue>, source: Map<TKey, TValue>): void {
|
|
162
|
+
target.clear()
|
|
163
|
+
for (const [key, value] of structuredClone(source)) target.set(key, value)
|
|
164
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type { AiCostStorageErrorCode } from "./errors"
|
|
2
|
+
export { AiCostStorageError } from "./errors"
|
|
3
|
+
export type {
|
|
4
|
+
InMemoryAiAccountingAttributionSource,
|
|
5
|
+
InMemoryAiCostStorageSnapshot,
|
|
6
|
+
} from "./in-memory"
|
|
7
|
+
export { InMemoryAiCostStorage } from "./in-memory"
|
|
8
|
+
export type {
|
|
9
|
+
AiAccountingAgentBreakdown,
|
|
10
|
+
AiAccountingAggregate,
|
|
11
|
+
AiAccountingAttribution,
|
|
12
|
+
AiAccountingBucket,
|
|
13
|
+
AiAccountingModelBreakdown,
|
|
14
|
+
AiAccountingOverview,
|
|
15
|
+
AiAccountingRange,
|
|
16
|
+
AiAccountingTimeBucket,
|
|
17
|
+
AiAccountingWorkflowBreakdown,
|
|
18
|
+
AiBillableMeter,
|
|
19
|
+
AiBillingIdentity,
|
|
20
|
+
AiCostComponent,
|
|
21
|
+
AiCostStorage,
|
|
22
|
+
AiCostSummary,
|
|
23
|
+
AiModelCallAccountingItem,
|
|
24
|
+
AiModelCallCostRecord,
|
|
25
|
+
AiMoney,
|
|
26
|
+
AiPriceSource,
|
|
27
|
+
AiPricingContext,
|
|
28
|
+
AiRatedModelCallCostRecord,
|
|
29
|
+
AiUnpriceableModelCallCostRecord,
|
|
30
|
+
AiUnpriceableReason,
|
|
31
|
+
ListAiModelCallAccountingInput,
|
|
32
|
+
ListAiModelCallAccountingResult,
|
|
33
|
+
QueryAiAccountingOverviewInput,
|
|
34
|
+
SummarizeAiCostExecutionsInput,
|
|
35
|
+
} from "./types"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** @internal Storage-provider helpers; not part of the app-author API. */
|
|
2
|
+
export type {
|
|
3
|
+
AiAccountingAggregateFragment,
|
|
4
|
+
AiAccountingRecordSetItem,
|
|
5
|
+
NormalizedAiAccountingQuery,
|
|
6
|
+
NormalizedAiModelCallAccountingQuery,
|
|
7
|
+
} from "./analytics"
|
|
8
|
+
export {
|
|
9
|
+
buildAiAccountingOverviewFromFragments,
|
|
10
|
+
normalizeAiAccountingQuery,
|
|
11
|
+
normalizeAiModelCallAccountingQuery,
|
|
12
|
+
toAccountingItem,
|
|
13
|
+
} from "./analytics"
|
|
14
|
+
export type { AiModelCallCostDetails } from "./codec"
|
|
15
|
+
export { aiModelCallCostDetails, parseAiModelCallCostDetails } from "./codec"
|
|
16
|
+
export {
|
|
17
|
+
aiModelCallCostMatchesUsage,
|
|
18
|
+
normalizeAiModelCallCostRecord,
|
|
19
|
+
normalizeAiPricingContext,
|
|
20
|
+
} from "./validation"
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import type { AiModelCallUsageRecord } from "../ai-usage"
|
|
2
|
+
|
|
3
|
+
/** Token meters supported by the deterministic local catalog rater. */
|
|
4
|
+
export type AiBillableMeter =
|
|
5
|
+
| "tokens.input.total"
|
|
6
|
+
| "tokens.input.uncached"
|
|
7
|
+
| "tokens.input.cacheRead"
|
|
8
|
+
| "tokens.input.cacheWrite"
|
|
9
|
+
| "tokens.output.total"
|
|
10
|
+
| "tokens.output.text"
|
|
11
|
+
| "tokens.output.reasoning"
|
|
12
|
+
|
|
13
|
+
/** Exact money in nanounits of a currency's major unit. */
|
|
14
|
+
export interface AiMoney {
|
|
15
|
+
readonly currency: string
|
|
16
|
+
/** Canonical non-negative integer string. One USD is 1,000,000,000 nanounits. */
|
|
17
|
+
readonly amountNanos: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Provider and model key in a pricing catalog. */
|
|
21
|
+
export interface AiBillingIdentity {
|
|
22
|
+
readonly providerId: string
|
|
23
|
+
readonly modelId: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Allowlisted response/request dimensions retained for audit and strict fail-closed pricing. */
|
|
27
|
+
export interface AiPricingContext {
|
|
28
|
+
readonly serviceTier?: string
|
|
29
|
+
readonly batch?: boolean
|
|
30
|
+
readonly region?: string
|
|
31
|
+
readonly inferenceGeo?: string
|
|
32
|
+
readonly routedProviderId?: string
|
|
33
|
+
readonly deploymentId?: string
|
|
34
|
+
readonly inferenceProfileId?: string
|
|
35
|
+
readonly cacheWriteTtlSeconds?: number
|
|
36
|
+
readonly mode?: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Immutable provenance of the compact catalog entry applied to a valuation. */
|
|
40
|
+
export interface AiPriceSource {
|
|
41
|
+
readonly sourceId: string
|
|
42
|
+
readonly sourceEntryId: string
|
|
43
|
+
readonly sourceVersion: string
|
|
44
|
+
readonly sourceUrl: string
|
|
45
|
+
readonly observedAt: Date
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface AiCostComponent {
|
|
49
|
+
readonly meter: AiBillableMeter
|
|
50
|
+
readonly quantity: string
|
|
51
|
+
readonly rateAmountNanosPerMillion: string
|
|
52
|
+
readonly chargeAmountNanos: string
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type AiUnpriceableReason =
|
|
56
|
+
| "missingBillingIdentity"
|
|
57
|
+
| "missingCatalogEntry"
|
|
58
|
+
| "missingUsageMeter"
|
|
59
|
+
| "unsupportedPricingDimension"
|
|
60
|
+
| "invalidUsageForFormula"
|
|
61
|
+
|
|
62
|
+
interface AiModelCallCostRecordBase {
|
|
63
|
+
readonly projectId: string
|
|
64
|
+
readonly usageRecordId: string
|
|
65
|
+
readonly pricingContext: AiPricingContext
|
|
66
|
+
readonly priceSource: AiPriceSource
|
|
67
|
+
readonly ratedAt: Date
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Exact arithmetic under one immutable catalog snapshot; not a provider-settled charge. */
|
|
71
|
+
export interface AiRatedModelCallCostRecord extends AiModelCallCostRecordBase {
|
|
72
|
+
readonly status: "rated"
|
|
73
|
+
readonly billingIdentity: AiBillingIdentity
|
|
74
|
+
readonly money: AiMoney
|
|
75
|
+
readonly components: readonly AiCostComponent[]
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Explicit result when the compact catalog cannot completely and safely value a call. */
|
|
79
|
+
export interface AiUnpriceableModelCallCostRecord extends AiModelCallCostRecordBase {
|
|
80
|
+
readonly status: "unpriceable"
|
|
81
|
+
readonly billingIdentity?: AiBillingIdentity
|
|
82
|
+
readonly reason: AiUnpriceableReason
|
|
83
|
+
readonly missingMeters?: readonly AiBillableMeter[]
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export type AiModelCallCostRecord = AiRatedModelCallCostRecord | AiUnpriceableModelCallCostRecord
|
|
87
|
+
|
|
88
|
+
export interface SummarizeAiCostExecutionsInput {
|
|
89
|
+
readonly projectId: string
|
|
90
|
+
readonly executionIds: readonly string[]
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface AiCostSummary {
|
|
94
|
+
readonly amounts: readonly AiMoney[]
|
|
95
|
+
readonly ratedCallCount: number
|
|
96
|
+
readonly unpriceableCallCount: number
|
|
97
|
+
readonly unvaluedCallCount: number
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export type AiAccountingBucket = "hour" | "day" | "week"
|
|
101
|
+
|
|
102
|
+
/** Inclusive start and exclusive end for project accounting reads. */
|
|
103
|
+
export interface AiAccountingRange {
|
|
104
|
+
readonly from: Date
|
|
105
|
+
readonly to: Date
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface QueryAiAccountingOverviewInput extends AiAccountingRange {
|
|
109
|
+
readonly projectId: string
|
|
110
|
+
readonly bucket: AiAccountingBucket
|
|
111
|
+
readonly providerId?: string
|
|
112
|
+
readonly modelId?: string
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface ListAiModelCallAccountingInput extends AiAccountingRange {
|
|
116
|
+
readonly projectId: string
|
|
117
|
+
readonly providerId?: string
|
|
118
|
+
readonly modelId?: string
|
|
119
|
+
readonly executionId?: string
|
|
120
|
+
readonly valuationStatus?: "rated" | "unpriceable" | "unvalued"
|
|
121
|
+
readonly limit?: number
|
|
122
|
+
readonly offset?: number
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface AiAccountingAggregate {
|
|
126
|
+
readonly modelCallCount: number
|
|
127
|
+
readonly usage: AiModelCallUsageRecord["usage"]
|
|
128
|
+
readonly costs: AiCostSummary
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface AiAccountingTimeBucket extends AiAccountingAggregate {
|
|
132
|
+
readonly start: Date
|
|
133
|
+
readonly end: Date
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface AiAccountingAgentBreakdown extends AiAccountingAggregate {
|
|
137
|
+
readonly agentId: string
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface AiAccountingWorkflowBreakdown extends AiAccountingAggregate {
|
|
141
|
+
readonly workflowId: string
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface AiAccountingModelBreakdown extends AiAccountingAggregate {
|
|
145
|
+
readonly providerId: string
|
|
146
|
+
readonly modelId: string
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface AiAccountingOverview {
|
|
150
|
+
readonly range: AiAccountingRange
|
|
151
|
+
readonly bucket: AiAccountingBucket
|
|
152
|
+
readonly totals: AiAccountingAggregate
|
|
153
|
+
readonly series: readonly AiAccountingTimeBucket[]
|
|
154
|
+
readonly models: readonly AiAccountingModelBreakdown[]
|
|
155
|
+
readonly agents: readonly AiAccountingAgentBreakdown[]
|
|
156
|
+
readonly workflows: readonly AiAccountingWorkflowBreakdown[]
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export type AiAccountingAttribution =
|
|
160
|
+
| {
|
|
161
|
+
readonly kind: "agent"
|
|
162
|
+
readonly agentId: string
|
|
163
|
+
readonly agentRunId: string
|
|
164
|
+
readonly threadId: string
|
|
165
|
+
}
|
|
166
|
+
| {
|
|
167
|
+
readonly kind: "workflowAgent"
|
|
168
|
+
readonly agentId: string
|
|
169
|
+
readonly nodeRunId: string
|
|
170
|
+
readonly workflowId: string
|
|
171
|
+
readonly workflowRunId: string
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface AiModelCallAccountingItem {
|
|
175
|
+
readonly usage: AiModelCallUsageRecord
|
|
176
|
+
readonly attribution?: AiAccountingAttribution
|
|
177
|
+
readonly cost?: AiModelCallCostRecord
|
|
178
|
+
readonly valuationStatus: "rated" | "unpriceable" | "unvalued"
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface ListAiModelCallAccountingResult {
|
|
182
|
+
readonly items: readonly AiModelCallAccountingItem[]
|
|
183
|
+
readonly hasMore: boolean
|
|
184
|
+
readonly total: number
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Immutable model-call costs plus execution and project accounting reads. */
|
|
188
|
+
export interface AiCostStorage {
|
|
189
|
+
recordModelCallCost(input: AiModelCallCostRecord): Promise<void>
|
|
190
|
+
summarizeExecutions(input: SummarizeAiCostExecutionsInput): Promise<readonly AiCostSummary[]>
|
|
191
|
+
queryProjectOverview(input: QueryAiAccountingOverviewInput): Promise<AiAccountingOverview>
|
|
192
|
+
listModelCalls(input: ListAiModelCallAccountingInput): Promise<ListAiModelCallAccountingResult>
|
|
193
|
+
}
|