@burdenoff/be-sdk 2026.1110.2 → 2026.1110.3
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/configs/eslint/index.js +1 -1
- package/configs/tsconfig/tsconfig.json +1 -1
- package/dist/EventQueueFactory-9NGZV9jl.js +1457 -0
- package/dist/EventQueueFactory-9NGZV9jl.js.map +1 -0
- package/dist/RedisStreamsConnection-CY8WySJy.js +283 -0
- package/dist/RedisStreamsConnection-CY8WySJy.js.map +1 -0
- package/dist/ai-credits/index.d.ts +2 -3
- package/dist/ai-credits/index.js +3 -4
- package/dist/ai-credits/index.js.map +1 -1
- package/dist/ai-credits-Ca-NNcVx.js +546 -0
- package/dist/ai-credits-Ca-NNcVx.js.map +1 -0
- package/dist/{assistant-session-CJZhF4D6.d.ts → assistant-session-DA5ZKJOr.d.ts} +4 -5
- package/dist/auth/index.d.ts +2 -77
- package/dist/auth/index.js +3 -7
- package/dist/auth/index.js.map +1 -1
- package/dist/auth-CEuBEBQN.js +228 -0
- package/dist/auth-CEuBEBQN.js.map +1 -0
- package/dist/cache/index.d.ts +2 -3
- package/dist/cache/index.js +3 -7
- package/dist/cache/index.js.map +1 -1
- package/dist/cache-CU0uLwcS.js +1837 -0
- package/dist/cache-CU0uLwcS.js.map +1 -0
- package/dist/captcha/index.d.ts +2 -1
- package/dist/captcha/index.js +3 -3
- package/dist/captcha/index.js.map +1 -1
- package/dist/captcha-BT7yh1YS.js +77 -0
- package/dist/captcha-BT7yh1YS.js.map +1 -0
- package/dist/client/internal-client.d.ts +4 -7
- package/dist/client/internal-client.js +172 -4
- package/dist/client/internal-client.js.map +1 -1
- package/dist/client-BgAEvDC2.d.ts +86 -0
- package/dist/client-DcZ3iGES.js +565 -0
- package/dist/client-DcZ3iGES.js.map +1 -0
- package/dist/collector-endpoint-iyQYeI50.js +50 -0
- package/dist/collector-endpoint-iyQYeI50.js.map +1 -0
- package/dist/context-CZnXf2yb.js +247 -0
- package/dist/context-CZnXf2yb.js.map +1 -0
- package/dist/crypto/index.d.ts +2 -1
- package/dist/crypto/index.js +3 -3
- package/dist/crypto/index.js.map +1 -1
- package/dist/crypto-DO9fM0FO.js +145 -0
- package/dist/crypto-DO9fM0FO.js.map +1 -0
- package/dist/database/index.d.ts +104 -108
- package/dist/database/index.js +468 -6
- package/dist/database/index.js.map +1 -1
- package/dist/dataloader/index.d.ts +2 -1
- package/dist/dataloader/index.js +3 -3
- package/dist/dataloader/index.js.map +1 -1
- package/dist/dataloader-DwpT3YoS.js +294 -0
- package/dist/dataloader-DwpT3YoS.js.map +1 -0
- package/dist/deployed-environment-p_Tdl3sT.js +38 -0
- package/dist/deployed-environment-p_Tdl3sT.js.map +1 -0
- package/dist/dist-BGKdXVy3.js +1718 -0
- package/dist/dist-BGKdXVy3.js.map +1 -0
- package/dist/env-DdaoGjIt.js +74 -0
- package/dist/env-DdaoGjIt.js.map +1 -0
- package/dist/event-queue/index.d.ts +2 -7
- package/dist/event-queue/index.js +7 -9
- package/dist/event-queue/index.js.map +1 -1
- package/dist/event-queue-Cw-YJPY_.js +1384 -0
- package/dist/event-queue-Cw-YJPY_.js.map +1 -0
- package/dist/{explicit-activity-scope-CCoxVwAr.d.ts → explicit-activity-scope-D8VeGGpt.d.ts} +1 -2
- package/dist/export/index.d.ts +2 -2
- package/dist/export/index.js +3 -14
- package/dist/export/index.js.map +1 -1
- package/dist/export-B6fphx8a.js +642 -0
- package/dist/export-B6fphx8a.js.map +1 -0
- package/dist/feature-flags/index.d.ts +2 -10
- package/dist/feature-flags/index.js +3 -6
- package/dist/feature-flags/index.js.map +1 -1
- package/dist/feature-flags-71oDkrUe.js +422 -0
- package/dist/feature-flags-71oDkrUe.js.map +1 -0
- package/dist/files/index.d.ts +2 -3
- package/dist/files/index.js +3 -4
- package/dist/files/index.js.map +1 -1
- package/dist/files-DjH0099H.js +830 -0
- package/dist/files-DjH0099H.js.map +1 -0
- package/dist/gateway/index.d.ts +4 -6
- package/dist/gateway/index.js +7 -13
- package/dist/gateway/index.js.map +1 -1
- package/dist/gateway/security/index.d.ts +2 -2
- package/dist/gateway/security/index.js +3 -5
- package/dist/gateway/security/index.js.map +1 -1
- package/dist/gateway-DBFmxWks.js +50 -0
- package/dist/gateway-DBFmxWks.js.map +1 -0
- package/dist/graph/index.d.ts +3 -10
- package/dist/graph/index.js +4 -13
- package/dist/graph/index.js.map +1 -1
- package/dist/graph-DDYgIryR.js +2152 -0
- package/dist/graph-DDYgIryR.js.map +1 -0
- package/dist/graph-emitter-CdOXP7Tn.js +621 -0
- package/dist/graph-emitter-CdOXP7Tn.js.map +1 -0
- package/dist/graphql/index.d.ts +3 -2
- package/dist/graphql/index.js +4 -6
- package/dist/graphql/index.js.map +1 -1
- package/dist/graphql/services/index.d.ts +2 -24
- package/dist/graphql/services/index.js +3 -4
- package/dist/graphql/services/index.js.map +1 -1
- package/dist/graphql-DHAHHcww.js +161 -0
- package/dist/graphql-DHAHHcww.js.map +1 -0
- package/dist/graphql-DNkMkGBZ.d.ts +21 -0
- package/dist/i18n/index.d.ts +3 -3
- package/dist/i18n/index.js +3 -4
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n-BBMYFd0P.js +860 -0
- package/dist/i18n-BBMYFd0P.js.map +1 -0
- package/dist/import-optional-peer-B82VYxeX.js +18 -0
- package/dist/import-optional-peer-B82VYxeX.js.map +1 -0
- package/dist/index-3KOZ1zN9.d.ts +233 -0
- package/dist/index-BBqooJ52.d.ts +45 -0
- package/dist/index-BGzMYJsm.d.ts +209 -0
- package/dist/index-BKwHQtHQ.d.ts +63 -0
- package/dist/index-BMIMnp6T.d.ts +8 -0
- package/dist/index-BQDsNAMR.d.ts +81 -0
- package/dist/index-BVOL7458.d.ts +10 -0
- package/dist/index-BcqQs-Uq.d.ts +69 -0
- package/dist/index-BeVtqGO-.d.ts +208 -0
- package/dist/index-BiTzGUZP.d.ts +114 -0
- package/dist/index-BqYfCQSP.d.ts +500 -0
- package/dist/index-C0qLquY0.d.ts +150 -0
- package/dist/index-C5uEKchX.d.ts +60 -0
- package/dist/index-CDOqxSIi.d.ts +37 -0
- package/dist/index-CG6wj66Y.d.ts +148 -0
- package/dist/index-CIgoeobA.d.ts +145 -0
- package/dist/index-CPQDMSFS.d.ts +103 -0
- package/dist/index-CSRcgkVi.d.ts +23 -0
- package/dist/index-CZTnQIRU.d.ts +341 -0
- package/dist/index-CaM9JUcc.d.ts +144 -0
- package/dist/index-CkT2aUr3.d.ts +704 -0
- package/dist/index-CliOgq6L.d.ts +203 -0
- package/dist/index-CnzbJZP7.d.ts +999 -0
- package/dist/index-D6UeLAye.d.ts +63 -0
- package/dist/index-DGgh9DWn.d.ts +59 -0
- package/dist/index-DY3dNhMN.d.ts +420 -0
- package/dist/index-DZC-2o9R.d.ts +207 -0
- package/dist/index-DqbGqfAy.d.ts +127 -0
- package/dist/index-Dt1HJPTX.d.ts +12 -0
- package/dist/index-DtI6aBtB.d.ts +22 -0
- package/dist/index-FKohsiex.d.ts +38 -0
- package/dist/index-FbXPfen7.d.ts +132 -0
- package/dist/index-MArCb8Aq.d.ts +306 -0
- package/dist/index-N-huORcj.d.ts +303 -0
- package/dist/index-YOShAwkq.d.ts +45 -0
- package/dist/index-bZKZUvBu.d.ts +646 -0
- package/dist/index-yBSjMY32.d.ts +24 -0
- package/dist/index.d.ts +501 -544
- package/dist/index.js +1820 -2171
- package/dist/index.js.map +1 -1
- package/dist/init/index.d.ts +2 -2
- package/dist/init/index.js +3 -16
- package/dist/init/index.js.map +1 -1
- package/dist/init-Dy3KhT6Y.js +325 -0
- package/dist/init-Dy3KhT6Y.js.map +1 -0
- package/dist/instrumentation/index.d.ts +3 -4
- package/dist/instrumentation/index.js +5 -5
- package/dist/instrumentation/index.js.map +1 -1
- package/dist/instrumentation-xkkmDgJ0.js +1678 -0
- package/dist/instrumentation-xkkmDgJ0.js.map +1 -0
- package/dist/lake/index.d.ts +50 -54
- package/dist/lake/index.js +169 -193
- package/dist/lake/index.js.map +1 -1
- package/dist/layer/index.d.ts +3 -2
- package/dist/layer/index.js +4 -5
- package/dist/layer/index.js.map +1 -1
- package/dist/layer-BZBZZWeV.d.ts +69 -0
- package/dist/layer-Bcix-WCl.js +105 -0
- package/dist/layer-Bcix-WCl.js.map +1 -0
- package/dist/layer-CEKy6cm8.js +252 -0
- package/dist/layer-CEKy6cm8.js.map +1 -0
- package/dist/lifecycle/index.d.ts +2 -1
- package/dist/lifecycle/index.js +3 -4
- package/dist/lifecycle/index.js.map +1 -1
- package/dist/lifecycle-DeoLSX0U.js +76 -0
- package/dist/lifecycle-DeoLSX0U.js.map +1 -0
- package/dist/logger/index.d.ts +2 -3
- package/dist/logger/index.js +3 -3
- package/dist/logger/index.js.map +1 -1
- package/dist/logger-B6rCpb7D.js +290 -0
- package/dist/logger-B6rCpb7D.js.map +1 -0
- package/dist/metrics/index.d.ts +13 -14
- package/dist/metrics/index.js +3 -4
- package/dist/metrics/index.js.map +1 -1
- package/dist/metrics-BrLwNUrb.js +52 -0
- package/dist/metrics-BrLwNUrb.js.map +1 -0
- package/dist/metrics-collector-C2eShrlW.js +922 -0
- package/dist/metrics-collector-C2eShrlW.js.map +1 -0
- package/dist/middleware/index.d.ts +3 -3
- package/dist/middleware/index.js +3 -4
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware-CUxJVUpD.js +1243 -0
- package/dist/middleware-CUxJVUpD.js.map +1 -0
- package/dist/middleware-Cq0zFMGp.js +253 -0
- package/dist/middleware-Cq0zFMGp.js.map +1 -0
- package/dist/notifications/index.d.ts +2 -5
- package/dist/notifications/index.js +3 -6
- package/dist/notifications/index.js.map +1 -1
- package/dist/notifications-CdETrtFK.js +869 -0
- package/dist/notifications-CdETrtFK.js.map +1 -0
- package/dist/observability/index.d.ts +2 -3
- package/dist/observability/index.js +3 -4
- package/dist/observability/index.js.map +1 -1
- package/dist/observability-DBDXipTU.js +272 -0
- package/dist/observability-DBDXipTU.js.map +1 -0
- package/dist/platform/index.d.ts +2 -1
- package/dist/platform/index.js +3 -5
- package/dist/platform/index.js.map +1 -1
- package/dist/platform-DZwczW7v.js +1510 -0
- package/dist/platform-DZwczW7v.js.map +1 -0
- package/dist/prisma/generator/index.d.ts +1 -1
- package/dist/prisma/generator/index.js +97 -84
- package/dist/prisma/generator/index.js.map +1 -1
- package/dist/prisma/index.d.ts +4 -7
- package/dist/prisma/index.js +5 -12
- package/dist/prisma/index.js.map +1 -1
- package/dist/prisma-BzOOdt79.js +863 -0
- package/dist/prisma-BzOOdt79.js.map +1 -0
- package/dist/prisma-extension-Cfl09swM.d.ts +172 -0
- package/dist/product-alias/index.d.ts +2 -1
- package/dist/product-alias/index.js +3 -3
- package/dist/product-alias/index.js.map +1 -1
- package/dist/product-alias-BPqtskMq.js +273 -0
- package/dist/product-alias-BPqtskMq.js.map +1 -0
- package/dist/rbac/index.d.ts +2 -122
- package/dist/rbac/index.js +3 -6
- package/dist/rbac/index.js.map +1 -1
- package/dist/rbac-BB9l9Xph.js +1486 -0
- package/dist/rbac-BB9l9Xph.js.map +1 -0
- package/dist/resource-caps/index.d.ts +66 -72
- package/dist/resource-caps/index.js +430 -5
- package/dist/resource-caps/index.js.map +1 -1
- package/dist/rolldown-runtime-ad2WFvuA.js +17 -0
- package/dist/sdk-Dju9o-sq.js +124 -0
- package/dist/sdk-Dju9o-sq.js.map +1 -0
- package/dist/security-DIG-95Ic.js +1647 -0
- package/dist/security-DIG-95Ic.js.map +1 -0
- package/dist/server/index.d.ts +7 -164
- package/dist/server/index.js +2000 -1507
- package/dist/server/index.js.map +1 -1
- package/dist/service-jwt-Bu-WNA_-.js +80 -0
- package/dist/service-jwt-Bu-WNA_-.js.map +1 -0
- package/dist/services-BWzfz7vG.js +102 -0
- package/dist/services-BWzfz7vG.js.map +1 -0
- package/dist/sharding/index.d.ts +41 -44
- package/dist/sharding/index.js +156 -137
- package/dist/sharding/index.js.map +1 -1
- package/dist/sharing/index.d.ts +2 -1
- package/dist/sharing/index.js +3 -4
- package/dist/sharing/index.js.map +1 -1
- package/dist/sharing-CflDsSJ-.js +911 -0
- package/dist/sharing-CflDsSJ-.js.map +1 -0
- package/dist/stub-BqwKn4eh.js +630 -0
- package/dist/stub-BqwKn4eh.js.map +1 -0
- package/dist/tags/index.d.ts +2 -3
- package/dist/tags/index.js +3 -4
- package/dist/tags/index.js.map +1 -1
- package/dist/tags-B5xpbgsk.js +868 -0
- package/dist/{chunk-PBZFAAOM.js.map → tags-B5xpbgsk.js.map} +1 -1
- package/dist/telemetry/index.d.ts +64 -76
- package/dist/telemetry/index.js +369 -201
- package/dist/telemetry/index.js.map +1 -1
- package/dist/temporal/index.d.ts +2 -148
- package/dist/temporal/index.js +3 -5
- package/dist/temporal/index.js.map +1 -1
- package/dist/temporal-B534uYK8.js +706 -0
- package/dist/temporal-B534uYK8.js.map +1 -0
- package/dist/tracker/index.d.ts +5 -11
- package/dist/tracker/index.js +5 -20
- package/dist/tracker/index.js.map +1 -1
- package/dist/tracker-BQVoEFUo.js +839 -0
- package/dist/tracker-BQVoEFUo.js.map +1 -0
- package/dist/types-BYMYND1L.js +44 -0
- package/dist/types-BYMYND1L.js.map +1 -0
- package/dist/types-C6EKaS3V.d.ts +106 -0
- package/dist/types-CWybW61E.d.ts +323 -0
- package/dist/types-C_yfu3XK.d.ts +34 -0
- package/dist/types-Cj2RWXbz.js +90 -0
- package/dist/types-Cj2RWXbz.js.map +1 -0
- package/dist/types-DgaQqvxo.d.ts +70 -0
- package/dist/usage/index.d.ts +2 -213
- package/dist/usage/index.js +3 -15
- package/dist/usage/index.js.map +1 -1
- package/dist/usage-BKFZiWQn.js +682 -0
- package/dist/usage-BKFZiWQn.js.map +1 -0
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +3 -3
- package/dist/utils/index.js.map +1 -1
- package/dist/utils-DL85Tnbn.js +500 -0
- package/dist/utils-DL85Tnbn.js.map +1 -0
- package/dist/validation/index.d.ts +2 -2
- package/dist/validation/index.js +3 -3
- package/dist/validation/index.js.map +1 -1
- package/dist/validation-CPUITdMk.js +762 -0
- package/dist/validation-CPUITdMk.js.map +1 -0
- package/dist/workspace-extension-COrC0dYi.js +979 -0
- package/dist/workspace-extension-COrC0dYi.js.map +1 -0
- package/dist/{workspace-extension-BGwTOV_r.d.ts → workspace-extension-DTFTdGVF.d.ts} +43 -45
- package/package.json +7 -10
- package/dist/EventQueueFactory-GXC3A7DH.js +0 -8
- package/dist/EventQueueFactory-GXC3A7DH.js.map +0 -1
- package/dist/chunk-4XIBXZ6J.js +0 -276
- package/dist/chunk-4XIBXZ6J.js.map +0 -1
- package/dist/chunk-554Z4C2K.js +0 -1006
- package/dist/chunk-554Z4C2K.js.map +0 -1
- package/dist/chunk-5CAFHK2Z.js +0 -107
- package/dist/chunk-5CAFHK2Z.js.map +0 -1
- package/dist/chunk-63ZXJ42X.js +0 -451
- package/dist/chunk-63ZXJ42X.js.map +0 -1
- package/dist/chunk-6XEXJATV.js +0 -304
- package/dist/chunk-6XEXJATV.js.map +0 -1
- package/dist/chunk-726AR6Q7.js +0 -1532
- package/dist/chunk-726AR6Q7.js.map +0 -1
- package/dist/chunk-A5F6Z5UE.js +0 -21
- package/dist/chunk-A5F6Z5UE.js.map +0 -1
- package/dist/chunk-A6DE32ZS.js +0 -1507
- package/dist/chunk-A6DE32ZS.js.map +0 -1
- package/dist/chunk-AXJDGQPE.js +0 -690
- package/dist/chunk-AXJDGQPE.js.map +0 -1
- package/dist/chunk-BJQOGOVW.js +0 -602
- package/dist/chunk-BJQOGOVW.js.map +0 -1
- package/dist/chunk-CFXWH2IS.js +0 -52
- package/dist/chunk-CFXWH2IS.js.map +0 -1
- package/dist/chunk-DRWH5XCJ.js +0 -876
- package/dist/chunk-DRWH5XCJ.js.map +0 -1
- package/dist/chunk-E4QNLVY4.js +0 -909
- package/dist/chunk-E4QNLVY4.js.map +0 -1
- package/dist/chunk-EBDHIL7V.js +0 -774
- package/dist/chunk-EBDHIL7V.js.map +0 -1
- package/dist/chunk-ELU7VL3E.js +0 -245
- package/dist/chunk-ELU7VL3E.js.map +0 -1
- package/dist/chunk-FZRODKIN.js +0 -31
- package/dist/chunk-FZRODKIN.js.map +0 -1
- package/dist/chunk-GCIB76AJ.js +0 -882
- package/dist/chunk-GCIB76AJ.js.map +0 -1
- package/dist/chunk-HC6MPUIH.js +0 -1571
- package/dist/chunk-HC6MPUIH.js.map +0 -1
- package/dist/chunk-HNMHPSAM.js +0 -272
- package/dist/chunk-HNMHPSAM.js.map +0 -1
- package/dist/chunk-HTLEGD3Q.js +0 -1480
- package/dist/chunk-HTLEGD3Q.js.map +0 -1
- package/dist/chunk-I3KOWRT3.js +0 -89
- package/dist/chunk-I3KOWRT3.js.map +0 -1
- package/dist/chunk-ID3WR4JS.js +0 -509
- package/dist/chunk-ID3WR4JS.js.map +0 -1
- package/dist/chunk-JS52ZHTK.js +0 -1346
- package/dist/chunk-JS52ZHTK.js.map +0 -1
- package/dist/chunk-JVMAQOA3.js +0 -521
- package/dist/chunk-JVMAQOA3.js.map +0 -1
- package/dist/chunk-KH4TRQCO.js +0 -1063
- package/dist/chunk-KH4TRQCO.js.map +0 -1
- package/dist/chunk-KJOSPVB2.js +0 -57
- package/dist/chunk-KJOSPVB2.js.map +0 -1
- package/dist/chunk-KO2ZXZ7W.js +0 -61
- package/dist/chunk-KO2ZXZ7W.js.map +0 -1
- package/dist/chunk-KS2HQCJR.js +0 -56
- package/dist/chunk-KS2HQCJR.js.map +0 -1
- package/dist/chunk-LA5KPWZ2.js +0 -413
- package/dist/chunk-LA5KPWZ2.js.map +0 -1
- package/dist/chunk-MESLAC5W.js +0 -574
- package/dist/chunk-MESLAC5W.js.map +0 -1
- package/dist/chunk-MWPYA2HD.js +0 -94
- package/dist/chunk-MWPYA2HD.js.map +0 -1
- package/dist/chunk-NUB5GQTU.js +0 -270
- package/dist/chunk-NUB5GQTU.js.map +0 -1
- package/dist/chunk-OBBCR6WY.js +0 -277
- package/dist/chunk-OBBCR6WY.js.map +0 -1
- package/dist/chunk-OQDSAOG3.js +0 -1908
- package/dist/chunk-OQDSAOG3.js.map +0 -1
- package/dist/chunk-OXNCBE7P.js +0 -971
- package/dist/chunk-OXNCBE7P.js.map +0 -1
- package/dist/chunk-PBZFAAOM.js +0 -941
- package/dist/chunk-PN6GIF3R.js +0 -1185
- package/dist/chunk-PN6GIF3R.js.map +0 -1
- package/dist/chunk-PYD44IHJ.js +0 -728
- package/dist/chunk-PYD44IHJ.js.map +0 -1
- package/dist/chunk-QVPIACWD.js +0 -679
- package/dist/chunk-QVPIACWD.js.map +0 -1
- package/dist/chunk-QWNNFE4P.js +0 -41
- package/dist/chunk-QWNNFE4P.js.map +0 -1
- package/dist/chunk-RU266375.js +0 -327
- package/dist/chunk-RU266375.js.map +0 -1
- package/dist/chunk-RYTSVGGA.js +0 -1624
- package/dist/chunk-RYTSVGGA.js.map +0 -1
- package/dist/chunk-RZOFS2BQ.js +0 -225
- package/dist/chunk-RZOFS2BQ.js.map +0 -1
- package/dist/chunk-SBS4S2PJ.js +0 -100
- package/dist/chunk-SBS4S2PJ.js.map +0 -1
- package/dist/chunk-SPRG6G6G.js +0 -530
- package/dist/chunk-SPRG6G6G.js.map +0 -1
- package/dist/chunk-STWFX5E2.js +0 -233
- package/dist/chunk-STWFX5E2.js.map +0 -1
- package/dist/chunk-UNASM5VJ.js +0 -419
- package/dist/chunk-UNASM5VJ.js.map +0 -1
- package/dist/chunk-VAT66FJA.js +0 -245
- package/dist/chunk-VAT66FJA.js.map +0 -1
- package/dist/chunk-VFCMR5GX.js +0 -49
- package/dist/chunk-VFCMR5GX.js.map +0 -1
- package/dist/chunk-VGAHZKNJ.js +0 -66
- package/dist/chunk-VGAHZKNJ.js.map +0 -1
- package/dist/chunk-VTJTAAXC.js +0 -627
- package/dist/chunk-VTJTAAXC.js.map +0 -1
- package/dist/chunk-VXVLKRU6.js +0 -758
- package/dist/chunk-VXVLKRU6.js.map +0 -1
- package/dist/chunk-WWUU5ETI.js +0 -163
- package/dist/chunk-WWUU5ETI.js.map +0 -1
- package/dist/chunk-XE4OXN2W.js +0 -10
- package/dist/chunk-XE4OXN2W.js.map +0 -1
- package/dist/chunk-XOJORS75.js +0 -1853
- package/dist/chunk-XOJORS75.js.map +0 -1
- package/dist/chunk-YMZEUTD2.js +0 -110
- package/dist/chunk-YMZEUTD2.js.map +0 -1
- package/dist/chunk-Z77BTSOK.js +0 -617
- package/dist/chunk-Z77BTSOK.js.map +0 -1
- package/dist/chunk-ZZK3WEDI.js +0 -181
- package/dist/chunk-ZZK3WEDI.js.map +0 -1
- package/dist/client-CCXpAZ2r.d.ts +0 -89
- package/dist/client-DSI_760t.d.ts +0 -36
- package/dist/client-JU6T3UPB.js +0 -11
- package/dist/client-JU6T3UPB.js.map +0 -1
- package/dist/dist-2X4Q7PJA.js +0 -1491
- package/dist/dist-2X4Q7PJA.js.map +0 -1
- package/dist/env-4UWSUS64.js +0 -4
- package/dist/env-4UWSUS64.js.map +0 -1
- package/dist/graph-emitter-r5TylDBm.d.ts +0 -47
- package/dist/graphql-CMHMQjvd.d.ts +0 -23
- package/dist/i18n-Qm2AkPC-.d.ts +0 -33
- package/dist/index--yvpa6ay.d.ts +0 -83
- package/dist/index-4gKQKZ2B.d.ts +0 -71
- package/dist/index-5x0XMKXN.d.ts +0 -149
- package/dist/index-B70b5mYS.d.ts +0 -33
- package/dist/index-B8KrxO4j.d.ts +0 -755
- package/dist/index-BOuDKnqD.d.ts +0 -201
- package/dist/index-BTMt4OjA.d.ts +0 -201
- package/dist/index-BejbszA7.d.ts +0 -39
- package/dist/index-BkeOYZye.d.ts +0 -198
- package/dist/index-BuAj5nXg.d.ts +0 -83
- package/dist/index-BvkVcW8I.d.ts +0 -349
- package/dist/index-CWmH_-RZ.d.ts +0 -247
- package/dist/index-CbgWNcus.d.ts +0 -258
- package/dist/index-CmfPeQza.d.ts +0 -166
- package/dist/index-CmpG-zak.d.ts +0 -607
- package/dist/index-CoMKgL-p.d.ts +0 -12
- package/dist/index-D8HGwglK.d.ts +0 -541
- package/dist/index-DCaVm66D.d.ts +0 -1101
- package/dist/index-DE2w7E0d.d.ts +0 -83
- package/dist/index-DSOpj8DI.d.ts +0 -17
- package/dist/index-DW9q22GH.d.ts +0 -75
- package/dist/index-DnjJ9CwI.d.ts +0 -347
- package/dist/index-DwMJZ8PP.d.ts +0 -317
- package/dist/index-PaojfSdd.d.ts +0 -71
- package/dist/index-aHtYvc3i.d.ts +0 -284
- package/dist/index-e_18DzAg.d.ts +0 -18
- package/dist/index-ffmipXSA.d.ts +0 -55
- package/dist/index-joONjwLt.d.ts +0 -33
- package/dist/index-kssw5ziY.d.ts +0 -250
- package/dist/index-lFffh5-G.d.ts +0 -125
- package/dist/index-pxYge_6k.d.ts +0 -79
- package/dist/layer-Cv9vSwBx.d.ts +0 -70
- package/dist/pino-logger-H4HPW5P6.js +0 -5
- package/dist/pino-logger-H4HPW5P6.js.map +0 -1
- package/dist/prisma-extension-gYhYriA0.d.ts +0 -174
- package/dist/sdk-L75WWUP3.js +0 -156
- package/dist/sdk-L75WWUP3.js.map +0 -1
- package/dist/shutdown-registry-CW9LryO8.d.ts +0 -10
- package/dist/types-Bo2wkjSP.d.ts +0 -35
- package/dist/types-DVpvrAhd.d.ts +0 -71
- package/dist/types-DgJ4lDYA.d.ts +0 -108
- package/dist/types-USOv09qy.d.ts +0 -327
- package/dist/workspace-guard-NXVYYBVJ.js +0 -5
- package/dist/workspace-guard-NXVYYBVJ.js.map +0 -1
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-ad2WFvuA.js";
|
|
2
|
+
import { a as logger } from "./logger-B6rCpb7D.js";
|
|
3
|
+
|
|
4
|
+
// src/ai-credits/validation.ts
|
|
5
|
+
/**
|
|
6
|
+
* Sanity ceiling for one turn's token counts. Real turns stay far below it even
|
|
7
|
+
* with a large context window; credits price at roughly one credit per input
|
|
8
|
+
* token, so an unbounded count would be an unbounded charge.
|
|
9
|
+
*/
|
|
10
|
+
const AI_CREDIT_MAX_TOKENS_PER_REPORT = 2e6;
|
|
11
|
+
function blank(value) {
|
|
12
|
+
return typeof value !== "string" || value.trim().length === 0;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Validate a reported turn. Returns null when it is acceptable, otherwise the
|
|
16
|
+
* first violation. Does not throw, so callers choose the error type (VC raises
|
|
17
|
+
* an i18n'd BAD_USER_INPUT, HB a client-facing error).
|
|
18
|
+
*
|
|
19
|
+
* `messageId` is required, not optional: without it the idempotency hash
|
|
20
|
+
* collapses to the session and only the first turn of a conversation would ever
|
|
21
|
+
* be charged. `model` is required because it selects the per-token price.
|
|
22
|
+
*/
|
|
23
|
+
function validateAiTokenUsage(report, maxTokensPerReport = AI_CREDIT_MAX_TOKENS_PER_REPORT) {
|
|
24
|
+
const { sessionId, messageId, model, inputTokens, outputTokens } = report;
|
|
25
|
+
const counts = [
|
|
26
|
+
inputTokens,
|
|
27
|
+
outputTokens,
|
|
28
|
+
report.cacheReadTokens ?? 0,
|
|
29
|
+
report.cacheWriteTokens ?? 0
|
|
30
|
+
];
|
|
31
|
+
if (blank(sessionId)) return {
|
|
32
|
+
code: "SESSION_ID_REQUIRED",
|
|
33
|
+
message: "sessionId is required."
|
|
34
|
+
};
|
|
35
|
+
if (blank(messageId)) return {
|
|
36
|
+
code: "MESSAGE_ID_REQUIRED",
|
|
37
|
+
message: "messageId is required."
|
|
38
|
+
};
|
|
39
|
+
if (blank(model)) return {
|
|
40
|
+
code: "MODEL_REQUIRED",
|
|
41
|
+
message: "model is required."
|
|
42
|
+
};
|
|
43
|
+
if (counts.some((count) => !Number.isSafeInteger(count))) return {
|
|
44
|
+
code: "TOKEN_COUNTS_NOT_INTEGERS",
|
|
45
|
+
message: "Token counts must be integers."
|
|
46
|
+
};
|
|
47
|
+
if (counts.some((count) => count < 0)) return {
|
|
48
|
+
code: "TOKEN_COUNTS_NEGATIVE",
|
|
49
|
+
message: "Token counts must be non-negative."
|
|
50
|
+
};
|
|
51
|
+
if (counts.reduce((sum, count) => sum + count, 0) > maxTokensPerReport) return {
|
|
52
|
+
code: "TOKEN_COUNTS_EXCEED_MAXIMUM",
|
|
53
|
+
message: `Reported tokens exceed the per-report maximum of ${maxTokensPerReport}.`
|
|
54
|
+
};
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The quota a product's AI credits draw from: `<productId>.ai.credits`
|
|
59
|
+
* (`vibecontrols.ai.credits`, `healthybowl.ai.credits`, …). Must match what
|
|
60
|
+
* billing seeds exactly — a name mismatch reads as "not provisioned".
|
|
61
|
+
*/
|
|
62
|
+
function aiCreditQuotaName(productId) {
|
|
63
|
+
const id = productId.trim();
|
|
64
|
+
if (!id) throw new Error("aiCreditQuotaName requires a productId");
|
|
65
|
+
return `${id}.ai.credits`;
|
|
66
|
+
}
|
|
67
|
+
/** Default hash prefix for a product: `<productId>:aicredit`. */
|
|
68
|
+
function defaultAiCreditHashPrefix(productId) {
|
|
69
|
+
const id = productId.trim();
|
|
70
|
+
if (!id) throw new Error("defaultAiCreditHashPrefix requires a productId");
|
|
71
|
+
return `${id}:aicredit`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Make a hash component unambiguous when joined with `:`. Ids are `ID!` and may
|
|
75
|
+
* contain colons, so raw joining would let `("a:b","c")` and `("a","b:c")`
|
|
76
|
+
* collide — and activity's unique `usage_records.hash` would then drop the second,
|
|
77
|
+
* genuinely different turn as a replay. `%` is escaped first so the escape itself
|
|
78
|
+
* cannot collide. A no-op for ids containing neither character (uuids, `msg_…`),
|
|
79
|
+
* so existing hashes are reproduced byte-for-byte.
|
|
80
|
+
*/
|
|
81
|
+
function encodeAiCreditHashComponent(value) {
|
|
82
|
+
return value.replaceAll("%", "%25").replaceAll(":", "%3A");
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Idempotency hash for one turn: `<prefix>:<sessionId>:<messageId>`.
|
|
86
|
+
*
|
|
87
|
+
* activity-svc's unique index is on `hash` ALONE, shared by every product, so
|
|
88
|
+
* the prefix must be product-namespaced. Products that already write a different
|
|
89
|
+
* prefix must keep passing it (`aicredit` for VibeControls, `hb-assistant` for
|
|
90
|
+
* HealthyBowl) — changing a prefix re-hashes every in-flight turn, so a client
|
|
91
|
+
* retry across the deploy would be charged twice.
|
|
92
|
+
*/
|
|
93
|
+
function aiCreditIdempotencyHash(prefix, sessionId, messageId) {
|
|
94
|
+
const head = prefix.trim();
|
|
95
|
+
if (!head) throw new Error("aiCreditIdempotencyHash requires a prefix");
|
|
96
|
+
if (blank(sessionId) || blank(messageId)) throw new Error("aiCreditIdempotencyHash requires a sessionId and a messageId");
|
|
97
|
+
return `${head}:${encodeAiCreditHashComponent(sessionId)}:${encodeAiCreditHashComponent(messageId)}`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/ai-credits/errors.ts
|
|
101
|
+
/** A malformed report or missing workspace context. Map it to BAD_USER_INPUT. */
|
|
102
|
+
var AiCreditInputError = class extends Error {
|
|
103
|
+
code;
|
|
104
|
+
/** GraphQL error code products should surface. */
|
|
105
|
+
graphqlCode = "BAD_USER_INPUT";
|
|
106
|
+
constructor(code, message) {
|
|
107
|
+
super(message);
|
|
108
|
+
this.name = "AiCreditInputError";
|
|
109
|
+
this.code = code;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
function isAiCreditInputError(error) {
|
|
113
|
+
return error instanceof AiCreditInputError;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/ai-credits/meter.ts
|
|
117
|
+
const DEFAULT_REQUEST_TIMEOUT_MS = 5e3;
|
|
118
|
+
const QUOTE_AI_CREDITS_QUERY = `query AiCreditMeterQuote($model: String!, $inputTokens: Int!, $outputTokens: Int!) {
|
|
119
|
+
quoteAiCredits(model: $model, inputTokens: $inputTokens, outputTokens: $outputTokens)
|
|
120
|
+
}`;
|
|
121
|
+
const QUOTE_AI_CREDITS_WITH_CACHE_QUERY = `query AiCreditMeterQuoteWithCache($model: String!, $inputTokens: Int!, $outputTokens: Int!, $cacheReadTokens: Int, $cacheWriteTokens: Int) {
|
|
122
|
+
quoteAiCredits(model: $model, inputTokens: $inputTokens, outputTokens: $outputTokens, cacheReadTokens: $cacheReadTokens, cacheWriteTokens: $cacheWriteTokens)
|
|
123
|
+
}`;
|
|
124
|
+
const CACHE_PRICING_CAPABILITY_QUERY = `query AiCreditMeterCachePricingSupported {
|
|
125
|
+
aiCacheTokenPricingSupported
|
|
126
|
+
}`;
|
|
127
|
+
const TRACK_USAGE_MUTATION = `mutation AiCreditMeterTrackUsage($input: TrackUsageInput!) {
|
|
128
|
+
trackUsage(input: $input)
|
|
129
|
+
}`;
|
|
130
|
+
const CHECK_WORKSPACE_QUOTA_QUERY = `query AiCreditMeterCheckQuota($workspaceId: ID!, $quotaName: String!, $amount: Float) {
|
|
131
|
+
checkWorkspaceQuota(workspaceId: $workspaceId, quotaName: $quotaName, amount: $amount) { allowed assignmentId limitLeft noLimit }
|
|
132
|
+
}`;
|
|
133
|
+
/** Amount the pre-flight gate asks activity about: one credit, the smallest chargeable unit. */
|
|
134
|
+
const GATE_PROBE_AMOUNT = 1;
|
|
135
|
+
const WORKSPACE_QUOTA_ASSIGNMENTS_QUERY = `query AiCreditMeterQuotaAssignments($workspaceId: ID!) {
|
|
136
|
+
workspaceQuotaAssignments(workspaceId: $workspaceId) { quotaName used limit noLimit isActive }
|
|
137
|
+
}`;
|
|
138
|
+
function errorMessage(error) {
|
|
139
|
+
return error instanceof Error ? error.message : String(error);
|
|
140
|
+
}
|
|
141
|
+
function requireNonEmpty(value, field) {
|
|
142
|
+
const trimmed = value?.trim() ?? "";
|
|
143
|
+
if (!trimmed) throw new Error(`AiCreditMeter: ${field} is required`);
|
|
144
|
+
return trimmed;
|
|
145
|
+
}
|
|
146
|
+
/** Same-layer auth header the wspace internal gateway expects from in-cluster callers. */
|
|
147
|
+
function internalServiceHeaders() {
|
|
148
|
+
const token = process.env["TRUSTED_GATEWAY_TOKEN"] || process.env["INTERNAL_SERVICE_TOKEN"];
|
|
149
|
+
return token ? { "x-internal-service-token": token } : {};
|
|
150
|
+
}
|
|
151
|
+
var AiCreditMeter = class {
|
|
152
|
+
productId;
|
|
153
|
+
quotaName;
|
|
154
|
+
hashPrefix;
|
|
155
|
+
serviceName;
|
|
156
|
+
activityGatewayUrl;
|
|
157
|
+
billingGatewayUrl;
|
|
158
|
+
pricingOption;
|
|
159
|
+
fetchImpl;
|
|
160
|
+
requestTimeoutMs;
|
|
161
|
+
maxTokensPerReport;
|
|
162
|
+
guard;
|
|
163
|
+
log;
|
|
164
|
+
pricing = null;
|
|
165
|
+
constructor(options) {
|
|
166
|
+
this.productId = requireNonEmpty(options.productId, "productId");
|
|
167
|
+
this.quotaName = options.quotaName?.trim() || aiCreditQuotaName(this.productId);
|
|
168
|
+
this.hashPrefix = options.hashPrefix?.trim() || defaultAiCreditHashPrefix(this.productId);
|
|
169
|
+
this.serviceName = options.serviceName?.trim() || void 0;
|
|
170
|
+
this.activityGatewayUrl = options.activityGatewayUrl?.trim() || void 0;
|
|
171
|
+
this.billingGatewayUrl = options.billingGatewayUrl?.trim() || void 0;
|
|
172
|
+
this.pricingOption = options.pricingClient;
|
|
173
|
+
this.fetchImpl = options.fetch ?? ((url, init) => fetch(url, init));
|
|
174
|
+
this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
175
|
+
if (!Number.isSafeInteger(this.requestTimeoutMs) || this.requestTimeoutMs <= 0) throw new Error("AiCreditMeter: requestTimeoutMs must be a positive integer");
|
|
176
|
+
this.maxTokensPerReport = options.maxTokensPerReport ?? 2e6;
|
|
177
|
+
if (!Number.isSafeInteger(this.maxTokensPerReport) || this.maxTokensPerReport <= 0) throw new Error("AiCreditMeter: maxTokensPerReport must be a positive integer");
|
|
178
|
+
this.guard = options.guard;
|
|
179
|
+
this.log = options.logger ?? logger;
|
|
180
|
+
}
|
|
181
|
+
/** The idempotency hash this meter records a turn under. */
|
|
182
|
+
hashFor(sessionId, messageId) {
|
|
183
|
+
return aiCreditIdempotencyHash(this.hashPrefix, sessionId, messageId);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Server-side price of one model call in credits, from billing's per-model
|
|
187
|
+
* token table. Returns null — after logging why — when it cannot be priced.
|
|
188
|
+
*
|
|
189
|
+
* When the turn reports cache counts, billing is first asked whether it prices
|
|
190
|
+
* them (`aiCacheTokenPricingSupported`). If it does, the cache counts are priced
|
|
191
|
+
* with its cache-token prices; if it does not (an older billing, or the probe
|
|
192
|
+
* fails), the turn is priced on input/output alone. The answer is not cached,
|
|
193
|
+
* so a billing rollback is picked up on the next report.
|
|
194
|
+
*/
|
|
195
|
+
async quote(input) {
|
|
196
|
+
const url = this.billingGatewayUrl ?? process.env["GLOBAL_PUBLIC_GATEWAY_URL"]?.trim();
|
|
197
|
+
if (!url) {
|
|
198
|
+
this.log.warn("[AiCreditMeter] GLOBAL_PUBLIC_GATEWAY_URL not set; cannot price AI credits", {
|
|
199
|
+
productId: this.productId,
|
|
200
|
+
model: input.model
|
|
201
|
+
});
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
try {
|
|
205
|
+
const client = await this.getPricingClient(url);
|
|
206
|
+
const priceCache = (input.cacheReadTokens != null || input.cacheWriteTokens != null) && await this.supportsCachePricing(client, input.model);
|
|
207
|
+
const response = await client.crossLayerQuery({
|
|
208
|
+
...this.pricingRequest(),
|
|
209
|
+
query: priceCache ? QUOTE_AI_CREDITS_WITH_CACHE_QUERY : QUOTE_AI_CREDITS_QUERY,
|
|
210
|
+
variables: {
|
|
211
|
+
model: input.model,
|
|
212
|
+
inputTokens: input.inputTokens,
|
|
213
|
+
outputTokens: input.outputTokens,
|
|
214
|
+
...priceCache ? {
|
|
215
|
+
cacheReadTokens: input.cacheReadTokens ?? 0,
|
|
216
|
+
cacheWriteTokens: input.cacheWriteTokens ?? 0
|
|
217
|
+
} : {}
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
if (response.errors?.length) throw new Error(response.errors.map((error) => error.message).join(", "));
|
|
221
|
+
const credits = response.data?.quoteAiCredits;
|
|
222
|
+
if (typeof credits !== "number" || !Number.isFinite(credits) || credits < 0) throw new Error(`quoteAiCredits returned no usable value (${String(credits)})`);
|
|
223
|
+
return credits;
|
|
224
|
+
} catch (error) {
|
|
225
|
+
this.log.warn("[AiCreditMeter] Failed to quote AI credits; skipping charge", {
|
|
226
|
+
productId: this.productId,
|
|
227
|
+
model: input.model,
|
|
228
|
+
error: errorMessage(error)
|
|
229
|
+
});
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Validate, price and record one completed assistant turn. See the module
|
|
235
|
+
* header for the contract: throws only {@link AiCreditInputError}.
|
|
236
|
+
*/
|
|
237
|
+
async charge(input) {
|
|
238
|
+
const workspaceId = input.workspaceId?.trim() ?? "";
|
|
239
|
+
if (!workspaceId) throw new AiCreditInputError("WORKSPACE_ID_REQUIRED", "This request has no workspace context.");
|
|
240
|
+
const invalid = validateAiTokenUsage(input, this.maxTokensPerReport);
|
|
241
|
+
if (invalid) throw new AiCreditInputError(invalid.code, invalid.message);
|
|
242
|
+
const hash = this.hashFor(input.sessionId, input.messageId);
|
|
243
|
+
const logFields = {
|
|
244
|
+
productId: this.productId,
|
|
245
|
+
quotaName: this.quotaName,
|
|
246
|
+
workspaceId,
|
|
247
|
+
sessionId: input.sessionId,
|
|
248
|
+
messageId: input.messageId,
|
|
249
|
+
model: input.model,
|
|
250
|
+
inputTokens: input.inputTokens,
|
|
251
|
+
outputTokens: input.outputTokens
|
|
252
|
+
};
|
|
253
|
+
const skipped = (reason, credits, detail) => {
|
|
254
|
+
this.log.warn(`[AiCreditMeter] turn not charged (${reason})`, {
|
|
255
|
+
...logFields,
|
|
256
|
+
credits,
|
|
257
|
+
detail
|
|
258
|
+
});
|
|
259
|
+
return {
|
|
260
|
+
status: "skipped",
|
|
261
|
+
reason,
|
|
262
|
+
credits,
|
|
263
|
+
hash,
|
|
264
|
+
quotaName: this.quotaName,
|
|
265
|
+
...detail ? { detail } : {}
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
if (this.guard) try {
|
|
269
|
+
const verdict = await this.guard({
|
|
270
|
+
...input,
|
|
271
|
+
workspaceId
|
|
272
|
+
});
|
|
273
|
+
if (!verdict.allow) return skipped("GUARD_REFUSED", null, verdict.detail);
|
|
274
|
+
} catch (error) {
|
|
275
|
+
this.log.warn("[AiCreditMeter] charge guard threw; charging anyway", {
|
|
276
|
+
...logFields,
|
|
277
|
+
error: errorMessage(error)
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
const credits = await this.quote(input);
|
|
281
|
+
if (credits === null) return skipped("NOT_PRICED", null);
|
|
282
|
+
if (credits <= 0) return skipped("ZERO_COST", credits);
|
|
283
|
+
try {
|
|
284
|
+
await this.trackUsage({
|
|
285
|
+
workspaceId,
|
|
286
|
+
amount: credits,
|
|
287
|
+
description: input.description?.trim() || `AI credits for session ${input.sessionId}`,
|
|
288
|
+
userId: input.userId ?? void 0,
|
|
289
|
+
hash,
|
|
290
|
+
metadata: {
|
|
291
|
+
model: input.model,
|
|
292
|
+
sessionId: input.sessionId,
|
|
293
|
+
messageId: input.messageId,
|
|
294
|
+
inputTokens: input.inputTokens,
|
|
295
|
+
outputTokens: input.outputTokens,
|
|
296
|
+
...input.cacheReadTokens != null || input.cacheWriteTokens != null ? {
|
|
297
|
+
cacheReadTokens: input.cacheReadTokens ?? 0,
|
|
298
|
+
cacheWriteTokens: input.cacheWriteTokens ?? 0
|
|
299
|
+
} : {},
|
|
300
|
+
credits,
|
|
301
|
+
...input.metadata
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
} catch (error) {
|
|
305
|
+
return skipped("RECORD_FAILED", credits, errorMessage(error));
|
|
306
|
+
}
|
|
307
|
+
this.log.info(`[AiCreditMeter] Charged ${credits} AI credits for session ${input.sessionId}`, {
|
|
308
|
+
...logFields,
|
|
309
|
+
credits
|
|
310
|
+
});
|
|
311
|
+
return {
|
|
312
|
+
status: "charged",
|
|
313
|
+
credits,
|
|
314
|
+
hash,
|
|
315
|
+
quotaName: this.quotaName
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Read the quota's ENFORCED usage from wspace-activity-svc — the ledger the
|
|
320
|
+
* charge lands on and the gateway's `@usage` check reads. All active rows are
|
|
321
|
+
* summed, because a workspace can hold several (plan + add-ons, or duplicate
|
|
322
|
+
* rows) and `checkWorkspaceQuota` sums them; a single-row read under-reports.
|
|
323
|
+
*
|
|
324
|
+
* Returns null (never throws) when activity is unreachable or no assignment
|
|
325
|
+
* exists, so a screen can show "not provisioned" instead of a confident zero.
|
|
326
|
+
*/
|
|
327
|
+
async readUsage(workspaceId, quotaName = this.quotaName) {
|
|
328
|
+
try {
|
|
329
|
+
const rows = ((await this.activityRequest(workspaceId, WORKSPACE_QUOTA_ASSIGNMENTS_QUERY, { workspaceId: workspaceId.trim() })).workspaceQuotaAssignments ?? []).filter((row) => row.isActive && row.quotaName === quotaName);
|
|
330
|
+
if (rows.length === 0) return null;
|
|
331
|
+
const used = rows.reduce((sum, row) => sum + (Number.isFinite(row.used) ? row.used : 0), 0);
|
|
332
|
+
const noLimit = rows.some((row) => row.noLimit);
|
|
333
|
+
const limit = noLimit ? null : rows.reduce((sum, row) => sum + (row.limit ?? 0), 0);
|
|
334
|
+
return {
|
|
335
|
+
quotaName,
|
|
336
|
+
used,
|
|
337
|
+
limit,
|
|
338
|
+
noLimit,
|
|
339
|
+
remaining: limit === null ? null : Math.max(limit - used, 0),
|
|
340
|
+
assignments: rows.length
|
|
341
|
+
};
|
|
342
|
+
} catch (error) {
|
|
343
|
+
this.log.warn("[AiCreditMeter] Failed to read workspace quota usage", {
|
|
344
|
+
productId: this.productId,
|
|
345
|
+
quotaName,
|
|
346
|
+
workspaceId,
|
|
347
|
+
error: errorMessage(error)
|
|
348
|
+
});
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Ask wspace-activity-svc whether `amount` of the quota may be spent — the same
|
|
354
|
+
* `checkWorkspaceQuota` the gateway's `@usage` gate runs, so every activity
|
|
355
|
+
* enforcement rule (row aggregation, renamed keys, the
|
|
356
|
+
* `TEST_ENTITLEMENT_WORKSPACE_IDS` entitlement) applies.
|
|
357
|
+
*
|
|
358
|
+
* Returns null (never throws) when activity cannot answer.
|
|
359
|
+
*/
|
|
360
|
+
async checkAllowance(workspaceId, options = {}) {
|
|
361
|
+
const quotaName = options.quotaName ?? this.quotaName;
|
|
362
|
+
const amount = options.amount ?? GATE_PROBE_AMOUNT;
|
|
363
|
+
try {
|
|
364
|
+
if (!Number.isFinite(amount) || amount < 0) throw new Error("amount must be a non-negative finite number");
|
|
365
|
+
const result = (await this.activityRequest(workspaceId, CHECK_WORKSPACE_QUOTA_QUERY, {
|
|
366
|
+
workspaceId: workspaceId.trim(),
|
|
367
|
+
quotaName,
|
|
368
|
+
amount
|
|
369
|
+
})).checkWorkspaceQuota;
|
|
370
|
+
if (!result || typeof result.allowed !== "boolean") throw new Error("checkWorkspaceQuota returned no verdict");
|
|
371
|
+
return {
|
|
372
|
+
quotaName,
|
|
373
|
+
allowed: result.allowed,
|
|
374
|
+
provisioned: result.assignmentId != null,
|
|
375
|
+
noLimit: result.noLimit === true,
|
|
376
|
+
limitLeft: typeof result.limitLeft === "number" && Number.isFinite(result.limitLeft) ? result.limitLeft : null
|
|
377
|
+
};
|
|
378
|
+
} catch (error) {
|
|
379
|
+
this.log.warn("[AiCreditMeter] Failed to check workspace quota allowance", {
|
|
380
|
+
productId: this.productId,
|
|
381
|
+
quotaName,
|
|
382
|
+
workspaceId,
|
|
383
|
+
error: errorMessage(error)
|
|
384
|
+
});
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Pre-flight gate for an AI call. Reads the ledger standing
|
|
390
|
+
* ({@link readUsage}); when it shows a limited budget spent, the refusal is
|
|
391
|
+
* confirmed with activity's {@link checkAllowance} before it is returned.
|
|
392
|
+
*
|
|
393
|
+
* - not provisioned or unreadable -> not exhausted (the call is not gated);
|
|
394
|
+
* - budget left, or no limit -> not exhausted (no second call);
|
|
395
|
+
* - spent and activity refuses -> exhausted;
|
|
396
|
+
* - spent and activity cannot answer -> exhausted (fail closed on a known
|
|
397
|
+
* spent budget, as before this check existed);
|
|
398
|
+
* - spent but activity allows -> not exhausted, `entitled: true`. This
|
|
399
|
+
* is a test-entitled doctor workspace; the call proceeds and
|
|
400
|
+
* {@link charge} still records it.
|
|
401
|
+
*/
|
|
402
|
+
async readGate(workspaceId, quotaName = this.quotaName) {
|
|
403
|
+
const usage = await this.readUsage(workspaceId, quotaName);
|
|
404
|
+
if (!(usage !== null && !usage.noLimit && (usage.remaining ?? 0) <= 0)) return {
|
|
405
|
+
usage,
|
|
406
|
+
exhausted: false,
|
|
407
|
+
entitled: false
|
|
408
|
+
};
|
|
409
|
+
if ((await this.checkAllowance(workspaceId, { quotaName }))?.allowed) {
|
|
410
|
+
this.log.info("[AiCreditMeter] budget spent but activity allows the call (test entitlement); not refused", {
|
|
411
|
+
productId: this.productId,
|
|
412
|
+
quotaName,
|
|
413
|
+
workspaceId,
|
|
414
|
+
used: usage.used,
|
|
415
|
+
limit: usage.limit
|
|
416
|
+
});
|
|
417
|
+
return {
|
|
418
|
+
usage,
|
|
419
|
+
exhausted: false,
|
|
420
|
+
entitled: true
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
return {
|
|
424
|
+
usage,
|
|
425
|
+
exhausted: true,
|
|
426
|
+
entitled: false
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
async trackUsage(record) {
|
|
430
|
+
const data = await this.activityRequest(record.workspaceId, TRACK_USAGE_MUTATION, { input: {
|
|
431
|
+
workspaceId: record.workspaceId,
|
|
432
|
+
quotaName: this.quotaName,
|
|
433
|
+
productId: this.productId,
|
|
434
|
+
amount: record.amount,
|
|
435
|
+
description: record.description,
|
|
436
|
+
userId: record.userId,
|
|
437
|
+
hash: record.hash,
|
|
438
|
+
metadata: record.metadata
|
|
439
|
+
} });
|
|
440
|
+
if (data.trackUsage !== true) throw new Error(`trackUsage did not confirm the record (returned ${String(data.trackUsage)})`);
|
|
441
|
+
}
|
|
442
|
+
async activityRequest(workspaceId, query, variables) {
|
|
443
|
+
const url = this.activityGatewayUrl ?? process.env["WSPACE_INT_GATEWAY_URL"]?.trim();
|
|
444
|
+
if (!url) throw new Error("WSPACE_INT_GATEWAY_URL not set; cannot reach wspace-activity-svc");
|
|
445
|
+
const workspace = workspaceId.trim();
|
|
446
|
+
if (!workspace) throw new Error("workspaceId is required");
|
|
447
|
+
const controller = new AbortController();
|
|
448
|
+
const timeout = setTimeout(() => controller.abort(), this.requestTimeoutMs);
|
|
449
|
+
try {
|
|
450
|
+
const response = await this.fetchImpl(url, {
|
|
451
|
+
method: "POST",
|
|
452
|
+
headers: {
|
|
453
|
+
"Content-Type": "application/json",
|
|
454
|
+
"x-actor-type": "service",
|
|
455
|
+
"x-actor-id": this.resolveServiceName(),
|
|
456
|
+
...internalServiceHeaders(),
|
|
457
|
+
"x-workspace-id": workspace
|
|
458
|
+
},
|
|
459
|
+
body: JSON.stringify({
|
|
460
|
+
query,
|
|
461
|
+
variables
|
|
462
|
+
}),
|
|
463
|
+
signal: controller.signal
|
|
464
|
+
});
|
|
465
|
+
if (!response.ok) {
|
|
466
|
+
const body = await response.text().catch(() => response.statusText);
|
|
467
|
+
throw new Error(`activity request failed with HTTP ${response.status}: ${body.slice(0, 500)}`);
|
|
468
|
+
}
|
|
469
|
+
const result = await response.json();
|
|
470
|
+
if (result.errors?.length) throw new Error(result.errors.map((error) => error.message).join(", "));
|
|
471
|
+
if (!result.data) throw new Error("activity response did not include data");
|
|
472
|
+
return result.data;
|
|
473
|
+
} finally {
|
|
474
|
+
clearTimeout(timeout);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
/** Options shared by every pricing call. */
|
|
478
|
+
pricingRequest() {
|
|
479
|
+
return {
|
|
480
|
+
headers: { "x-actor-type": "service" },
|
|
481
|
+
timeout: this.requestTimeoutMs,
|
|
482
|
+
skipRetry: true,
|
|
483
|
+
skipCircuitBreaker: true
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
/** Whether billing prices cache counts. Any failure reads as "no" and falls back to input/output. */
|
|
487
|
+
async supportsCachePricing(client, model) {
|
|
488
|
+
try {
|
|
489
|
+
if ((await client.crossLayerQuery({
|
|
490
|
+
...this.pricingRequest(),
|
|
491
|
+
query: CACHE_PRICING_CAPABILITY_QUERY,
|
|
492
|
+
variables: {}
|
|
493
|
+
})).data?.aiCacheTokenPricingSupported === true) return true;
|
|
494
|
+
} catch {}
|
|
495
|
+
this.log.warn("[AiCreditMeter] billing does not price cache tokens; quoting input/output only", {
|
|
496
|
+
productId: this.productId,
|
|
497
|
+
model
|
|
498
|
+
});
|
|
499
|
+
return false;
|
|
500
|
+
}
|
|
501
|
+
resolveServiceName() {
|
|
502
|
+
return this.serviceName || process.env["SERVICE_IDENTITY"] || process.env["SERVICE_NAME"] || `wspace-${this.productId}-svc`;
|
|
503
|
+
}
|
|
504
|
+
getPricingClient(url) {
|
|
505
|
+
if (this.pricing && this.pricing.url === url) return this.pricing.client;
|
|
506
|
+
const option = this.pricingOption;
|
|
507
|
+
const client = (async () => {
|
|
508
|
+
if (option && typeof option === "function") return option(url);
|
|
509
|
+
if (option) return option;
|
|
510
|
+
const gateway = await import("./client-DcZ3iGES.js").then((n) => n.n);
|
|
511
|
+
const identity = this.resolveServiceName();
|
|
512
|
+
return new gateway.GatewayClient({
|
|
513
|
+
layer: "wspace",
|
|
514
|
+
serviceName: identity,
|
|
515
|
+
serviceIdentity: identity,
|
|
516
|
+
crossLayerGatewayUrl: url,
|
|
517
|
+
timeout: this.requestTimeoutMs,
|
|
518
|
+
enableLogging: process.env["NODE_ENV"] !== "production"
|
|
519
|
+
});
|
|
520
|
+
})();
|
|
521
|
+
this.pricing = {
|
|
522
|
+
url,
|
|
523
|
+
client
|
|
524
|
+
};
|
|
525
|
+
client.catch(() => {
|
|
526
|
+
if (this.pricing?.client === client) this.pricing = null;
|
|
527
|
+
});
|
|
528
|
+
return client;
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
// src/ai-credits/index.ts
|
|
533
|
+
var ai_credits_exports = /* @__PURE__ */ __exportAll({
|
|
534
|
+
AI_CREDIT_MAX_TOKENS_PER_REPORT: () => AI_CREDIT_MAX_TOKENS_PER_REPORT,
|
|
535
|
+
AiCreditInputError: () => AiCreditInputError,
|
|
536
|
+
AiCreditMeter: () => AiCreditMeter,
|
|
537
|
+
aiCreditIdempotencyHash: () => aiCreditIdempotencyHash,
|
|
538
|
+
aiCreditQuotaName: () => aiCreditQuotaName,
|
|
539
|
+
defaultAiCreditHashPrefix: () => defaultAiCreditHashPrefix,
|
|
540
|
+
encodeAiCreditHashComponent: () => encodeAiCreditHashComponent,
|
|
541
|
+
isAiCreditInputError: () => isAiCreditInputError,
|
|
542
|
+
validateAiTokenUsage: () => validateAiTokenUsage
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
export { AI_CREDIT_MAX_TOKENS_PER_REPORT as a, defaultAiCreditHashPrefix as c, isAiCreditInputError as i, encodeAiCreditHashComponent as l, AiCreditMeter as n, aiCreditIdempotencyHash as o, AiCreditInputError as r, aiCreditQuotaName as s, ai_credits_exports as t, validateAiTokenUsage as u };
|
|
546
|
+
//# sourceMappingURL=ai-credits-Ca-NNcVx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-credits-Ca-NNcVx.js","names":["sdkLogger"],"sources":["../src/ai-credits/validation.ts","../src/ai-credits/errors.ts","../src/ai-credits/meter.ts","../src/ai-credits/index.ts"],"sourcesContent":["/**\n * Pure rules for AI-credit metering: report validation, quota naming and the\n * idempotency hash. Dependency-free so products can unit-test against them.\n */\nimport type { AiTokenUsageReport } from './types.js';\n\n/**\n * Sanity ceiling for one turn's token counts. Real turns stay far below it even\n * with a large context window; credits price at roughly one credit per input\n * token, so an unbounded count would be an unbounded charge.\n */\nexport const AI_CREDIT_MAX_TOKENS_PER_REPORT = 2_000_000;\n\n/** Stable machine-readable reasons a report is rejected. */\nexport type AiTokenUsageViolation =\n | 'SESSION_ID_REQUIRED'\n | 'MESSAGE_ID_REQUIRED'\n | 'MODEL_REQUIRED'\n | 'TOKEN_COUNTS_NOT_INTEGERS'\n | 'TOKEN_COUNTS_NEGATIVE'\n | 'TOKEN_COUNTS_EXCEED_MAXIMUM';\n\nexport interface AiTokenUsageValidationError {\n code: AiTokenUsageViolation;\n /** Operator-readable reason. Products usually map it to their i18n key by `code`. */\n message: string;\n}\n\nfunction blank(value: string | null | undefined): boolean {\n return typeof value !== 'string' || value.trim().length === 0;\n}\n\n/**\n * Validate a reported turn. Returns null when it is acceptable, otherwise the\n * first violation. Does not throw, so callers choose the error type (VC raises\n * an i18n'd BAD_USER_INPUT, HB a client-facing error).\n *\n * `messageId` is required, not optional: without it the idempotency hash\n * collapses to the session and only the first turn of a conversation would ever\n * be charged. `model` is required because it selects the per-token price.\n */\nexport function validateAiTokenUsage(\n report: Partial<Pick<AiTokenUsageReport, 'sessionId' | 'messageId' | 'model'>> &\n Pick<AiTokenUsageReport, 'inputTokens' | 'outputTokens' | 'cacheReadTokens' | 'cacheWriteTokens'>,\n maxTokensPerReport: number = AI_CREDIT_MAX_TOKENS_PER_REPORT\n): AiTokenUsageValidationError | null {\n const { sessionId, messageId, model, inputTokens, outputTokens } = report;\n // Cache counts are optional; an omitted/null count is zero. They are checked and\n // summed with the ordinary counts, because they are priced too.\n const counts = [inputTokens, outputTokens, report.cacheReadTokens ?? 0, report.cacheWriteTokens ?? 0];\n\n if (blank(sessionId)) return { code: 'SESSION_ID_REQUIRED', message: 'sessionId is required.' };\n if (blank(messageId)) return { code: 'MESSAGE_ID_REQUIRED', message: 'messageId is required.' };\n if (blank(model)) return { code: 'MODEL_REQUIRED', message: 'model is required.' };\n if (counts.some((count) => !Number.isSafeInteger(count))) {\n return { code: 'TOKEN_COUNTS_NOT_INTEGERS', message: 'Token counts must be integers.' };\n }\n if (counts.some((count) => count < 0)) {\n return { code: 'TOKEN_COUNTS_NEGATIVE', message: 'Token counts must be non-negative.' };\n }\n if (counts.reduce((sum, count) => sum + count, 0) > maxTokensPerReport) {\n return {\n code: 'TOKEN_COUNTS_EXCEED_MAXIMUM',\n message: `Reported tokens exceed the per-report maximum of ${maxTokensPerReport}.`,\n };\n }\n return null;\n}\n\n/**\n * The quota a product's AI credits draw from: `<productId>.ai.credits`\n * (`vibecontrols.ai.credits`, `healthybowl.ai.credits`, …). Must match what\n * billing seeds exactly — a name mismatch reads as \"not provisioned\".\n */\nexport function aiCreditQuotaName(productId: string): string {\n const id = productId.trim();\n if (!id) throw new Error('aiCreditQuotaName requires a productId');\n return `${id}.ai.credits`;\n}\n\n/** Default hash prefix for a product: `<productId>:aicredit`. */\nexport function defaultAiCreditHashPrefix(productId: string): string {\n const id = productId.trim();\n if (!id) throw new Error('defaultAiCreditHashPrefix requires a productId');\n return `${id}:aicredit`;\n}\n\n/**\n * Make a hash component unambiguous when joined with `:`. Ids are `ID!` and may\n * contain colons, so raw joining would let `(\"a:b\",\"c\")` and `(\"a\",\"b:c\")`\n * collide — and activity's unique `usage_records.hash` would then drop the second,\n * genuinely different turn as a replay. `%` is escaped first so the escape itself\n * cannot collide. A no-op for ids containing neither character (uuids, `msg_…`),\n * so existing hashes are reproduced byte-for-byte.\n */\nexport function encodeAiCreditHashComponent(value: string): string {\n return value.replaceAll('%', '%25').replaceAll(':', '%3A');\n}\n\n/**\n * Idempotency hash for one turn: `<prefix>:<sessionId>:<messageId>`.\n *\n * activity-svc's unique index is on `hash` ALONE, shared by every product, so\n * the prefix must be product-namespaced. Products that already write a different\n * prefix must keep passing it (`aicredit` for VibeControls, `hb-assistant` for\n * HealthyBowl) — changing a prefix re-hashes every in-flight turn, so a client\n * retry across the deploy would be charged twice.\n */\nexport function aiCreditIdempotencyHash(prefix: string, sessionId: string, messageId: string): string {\n const head = prefix.trim();\n if (!head) throw new Error('aiCreditIdempotencyHash requires a prefix');\n if (blank(sessionId) || blank(messageId)) {\n throw new Error('aiCreditIdempotencyHash requires a sessionId and a messageId');\n }\n return `${head}:${encodeAiCreditHashComponent(sessionId)}:${encodeAiCreditHashComponent(messageId)}`;\n}\n","/**\n * Errors raised by the AI-credit meter. Only caller mistakes throw; billing and\n * recording failures are returned as a skipped charge (see `AiCreditMeter.charge`).\n */\nimport type { AiTokenUsageViolation } from './validation.js';\n\nexport type AiCreditInputErrorCode = AiTokenUsageViolation | 'WORKSPACE_ID_REQUIRED';\n\n/** A malformed report or missing workspace context. Map it to BAD_USER_INPUT. */\nexport class AiCreditInputError extends Error {\n readonly code: AiCreditInputErrorCode;\n /** GraphQL error code products should surface. */\n readonly graphqlCode = 'BAD_USER_INPUT';\n\n constructor(code: AiCreditInputErrorCode, message: string) {\n super(message);\n this.name = 'AiCreditInputError';\n this.code = code;\n }\n}\n\nexport function isAiCreditInputError(error: unknown): error is AiCreditInputError {\n return error instanceof AiCreditInputError;\n}\n","/**\n * AiCreditMeter — cost-weighted, idempotent AI-credit charging for an assistant turn.\n *\n * VibeControls (`utils/usage-billing.ts` + `modules/aicredit`) and HealthyBowl\n * (`utils/ai-credit-usage.ts` + `HealthyBowlAiCreditProvider`) each carried their\n * own copy of this path. This is the shared version, built on the path that is\n * proven to record in prod:\n *\n * 1. **Price** — `quoteAiCredits(model, inputTokens, outputTokens[, cacheReadTokens,\n * cacheWriteTokens])` on global-billing-svc, cross-layer through the be-sdk `GatewayClient`\n * (`GLOBAL_PUBLIC_GATEWAY_URL`, which resolves to the peer VPC's internal ALB\n * over the Route53 private zone). The amount is always computed server-side\n * from billing's per-model prices; a client never supplies it.\n * 2. **Record** — wspace-activity-svc `trackUsage` on the workspace's\n * `WorkspaceQuotaAssignment`, same-layer through the wspace INTERNAL gateway\n * (`WSPACE_INT_GATEWAY_URL`) with `x-workspace-id`. Activity resolves the\n * assignment itself and dedupes on the unique `usage_records.hash`, so a\n * replayed report for the same session + message is a no-op charge.\n *\n * Contract:\n * - {@link AiCreditMeter.charge} validates first and THROWS\n * {@link AiCreditInputError} for a malformed report (a caller bug worth\n * surfacing). After that it never throws: the user already has the answer, so a\n * metering failure must not become a user-visible error. Every un-charged\n * outcome is returned as `status: 'skipped'` with a reason AND logged.\n * - A null quote skips the charge: under-charging during an outage is\n * recoverable, charging an invented amount is not.\n * - Recording only counts as success when activity answers `trackUsage: true`.\n *\n * The meter is a METER, not a gate. Products that need a pre-flight gate keep a\n * `@usage(checkQuota: true, trackUsage: false)` field (VC `checkAiCredits`), or\n * call {@link AiCreditMeter.readGate}, which defers the final refusal to the same\n * activity check that `@usage` runs. The charging field must carry NO\n * `@usage(trackUsage)` directive, or the turn is charged twice.\n *\n * Enforcement rules live in wspace-activity-svc only. In particular the\n * `TEST_ENTITLEMENT_WORKSPACE_IDS` doctor-workspace entitlement is applied by\n * activity's `checkWorkspaceQuota`; a gate built on the raw assignment rows\n * ({@link AiCreditMeter.readUsage}) would never see it. The entitlement waives\n * the refusal only: {@link AiCreditMeter.charge} still records every turn.\n *\n * @example\n * ```ts\n * import { AiCreditMeter } from '@burdenoff/be-sdk/ai-credits';\n *\n * const meter = new AiCreditMeter({\n * productId: 'vibecontrols',\n * serviceName: 'wspace-vibecontrols-svc',\n * hashPrefix: 'aicredit', // VC's existing prefix — never change a live prefix\n * });\n *\n * const result = await meter.charge({\n * workspaceId: requireWorkspaceId(ctx.workspace?.id),\n * userId: ctx.actor?.id,\n * sessionId: input.sessionId,\n * messageId: input.messageId,\n * model: input.model,\n * inputTokens: input.inputTokens,\n * outputTokens: input.outputTokens,\n * });\n * ```\n */\nimport type { GraphQLRequestOptions } from '../gateway/types.js';\nimport { logger as sdkLogger } from '../logger/index.js';\n\nimport { AiCreditInputError } from './errors.js';\nimport type {\n AiCreditAllowance,\n AiCreditChargeGuard,\n AiCreditChargeInput,\n AiCreditChargeResult,\n AiCreditFetch,\n AiCreditGate,\n AiCreditLogger,\n AiCreditPricingTransport,\n AiCreditQuoteInput,\n AiCreditSkipReason,\n WorkspaceQuotaUsage,\n} from './types.js';\nimport {\n AI_CREDIT_MAX_TOKENS_PER_REPORT,\n aiCreditIdempotencyHash,\n aiCreditQuotaName,\n defaultAiCreditHashPrefix,\n validateAiTokenUsage,\n} from './validation.js';\n\nconst DEFAULT_REQUEST_TIMEOUT_MS = 5_000;\n\nconst QUOTE_AI_CREDITS_QUERY = `query AiCreditMeterQuote($model: String!, $inputTokens: Int!, $outputTokens: Int!) {\n quoteAiCredits(model: $model, inputTokens: $inputTokens, outputTokens: $outputTokens)\n}`;\n\nconst QUOTE_AI_CREDITS_WITH_CACHE_QUERY = `query AiCreditMeterQuoteWithCache($model: String!, $inputTokens: Int!, $outputTokens: Int!, $cacheReadTokens: Int, $cacheWriteTokens: Int) {\n quoteAiCredits(model: $model, inputTokens: $inputTokens, outputTokens: $outputTokens, cacheReadTokens: $cacheReadTokens, cacheWriteTokens: $cacheWriteTokens)\n}`;\n\nconst CACHE_PRICING_CAPABILITY_QUERY = `query AiCreditMeterCachePricingSupported {\n aiCacheTokenPricingSupported\n}`;\n\nconst TRACK_USAGE_MUTATION = `mutation AiCreditMeterTrackUsage($input: TrackUsageInput!) {\n trackUsage(input: $input)\n}`;\n\nconst CHECK_WORKSPACE_QUOTA_QUERY = `query AiCreditMeterCheckQuota($workspaceId: ID!, $quotaName: String!, $amount: Float) {\n checkWorkspaceQuota(workspaceId: $workspaceId, quotaName: $quotaName, amount: $amount) { allowed assignmentId limitLeft noLimit }\n}`;\n\n/** Amount the pre-flight gate asks activity about: one credit, the smallest chargeable unit. */\nconst GATE_PROBE_AMOUNT = 1;\n\nconst WORKSPACE_QUOTA_ASSIGNMENTS_QUERY = `query AiCreditMeterQuotaAssignments($workspaceId: ID!) {\n workspaceQuotaAssignments(workspaceId: $workspaceId) { quotaName used limit noLimit isActive }\n}`;\n\nexport interface AiCreditMeterOptions {\n /** Product id stamped on usage records, e.g. `vibecontrols`. */\n productId: string;\n /** This service's name; sent as the service identity. Default `SERVICE_IDENTITY` / `SERVICE_NAME` env. */\n serviceName?: string;\n /** Quota to charge. Default `<productId>.ai.credits`. */\n quotaName?: string;\n /**\n * Idempotency-hash prefix. Default `<productId>:aicredit`. A product that already\n * records under another prefix MUST keep it (see {@link aiCreditIdempotencyHash}).\n */\n hashPrefix?: string;\n /** wspace internal gateway URL. Default `WSPACE_INT_GATEWAY_URL` env (read per call). */\n activityGatewayUrl?: string;\n /** Cross-layer global gateway URL for pricing. Default `GLOBAL_PUBLIC_GATEWAY_URL` env (read per call). */\n billingGatewayUrl?: string;\n /**\n * Pricing transport, or a factory for one. Default: a lazily constructed be-sdk\n * `GatewayClient` bound to {@link billingGatewayUrl}, rebuilt if the URL changes.\n */\n pricingClient?:\n AiCreditPricingTransport | ((url: string) => AiCreditPricingTransport | Promise<AiCreditPricingTransport>);\n /** `fetch` for the activity-svc calls. Default: the global `fetch`. */\n fetch?: AiCreditFetch;\n /** Per-request timeout. Default 5s. */\n requestTimeoutMs?: number;\n /** Per-report token ceiling. Default {@link AI_CREDIT_MAX_TOKENS_PER_REPORT}. */\n maxTokensPerReport?: number;\n /** Optional pre-charge hook (e.g. a report-rate ceiling). */\n guard?: AiCreditChargeGuard;\n /** Logger. Default the be-sdk logger. */\n logger?: AiCreditLogger;\n}\n\ninterface GraphQLBody<T> {\n data?: T | null;\n errors?: { message: string }[] | null;\n}\n\ninterface AssignmentRow {\n quotaName: string;\n used: number;\n limit: number | null;\n noLimit: boolean;\n isActive: boolean;\n}\n\nfunction errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\nfunction requireNonEmpty(value: string | undefined, field: string): string {\n const trimmed = value?.trim() ?? '';\n if (!trimmed) throw new Error(`AiCreditMeter: ${field} is required`);\n return trimmed;\n}\n\n/** Same-layer auth header the wspace internal gateway expects from in-cluster callers. */\nfunction internalServiceHeaders(): Record<string, string> {\n const token = process.env['TRUSTED_GATEWAY_TOKEN'] || process.env['INTERNAL_SERVICE_TOKEN'];\n return token ? { 'x-internal-service-token': token } : {};\n}\n\nexport class AiCreditMeter {\n readonly productId: string;\n readonly quotaName: string;\n readonly hashPrefix: string;\n private readonly serviceName: string | undefined;\n private readonly activityGatewayUrl: string | undefined;\n private readonly billingGatewayUrl: string | undefined;\n private readonly pricingOption: AiCreditMeterOptions['pricingClient'];\n private readonly fetchImpl: AiCreditFetch;\n private readonly requestTimeoutMs: number;\n private readonly maxTokensPerReport: number;\n private readonly guard: AiCreditChargeGuard | undefined;\n private readonly log: AiCreditLogger;\n private pricing: { url: string; client: Promise<AiCreditPricingTransport> } | null = null;\n\n constructor(options: AiCreditMeterOptions) {\n this.productId = requireNonEmpty(options.productId, 'productId');\n this.quotaName = options.quotaName?.trim() || aiCreditQuotaName(this.productId);\n this.hashPrefix = options.hashPrefix?.trim() || defaultAiCreditHashPrefix(this.productId);\n this.serviceName = options.serviceName?.trim() || undefined;\n this.activityGatewayUrl = options.activityGatewayUrl?.trim() || undefined;\n this.billingGatewayUrl = options.billingGatewayUrl?.trim() || undefined;\n this.pricingOption = options.pricingClient;\n this.fetchImpl = options.fetch ?? ((url, init) => fetch(url, init));\n this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;\n if (!Number.isSafeInteger(this.requestTimeoutMs) || this.requestTimeoutMs <= 0) {\n throw new Error('AiCreditMeter: requestTimeoutMs must be a positive integer');\n }\n this.maxTokensPerReport = options.maxTokensPerReport ?? AI_CREDIT_MAX_TOKENS_PER_REPORT;\n if (!Number.isSafeInteger(this.maxTokensPerReport) || this.maxTokensPerReport <= 0) {\n throw new Error('AiCreditMeter: maxTokensPerReport must be a positive integer');\n }\n this.guard = options.guard;\n this.log = options.logger ?? sdkLogger;\n }\n\n /** The idempotency hash this meter records a turn under. */\n hashFor(sessionId: string, messageId: string): string {\n return aiCreditIdempotencyHash(this.hashPrefix, sessionId, messageId);\n }\n\n /**\n * Server-side price of one model call in credits, from billing's per-model\n * token table. Returns null — after logging why — when it cannot be priced.\n *\n * When the turn reports cache counts, billing is first asked whether it prices\n * them (`aiCacheTokenPricingSupported`). If it does, the cache counts are priced\n * with its cache-token prices; if it does not (an older billing, or the probe\n * fails), the turn is priced on input/output alone. The answer is not cached,\n * so a billing rollback is picked up on the next report.\n */\n async quote(input: AiCreditQuoteInput): Promise<number | null> {\n const url = this.billingGatewayUrl ?? process.env['GLOBAL_PUBLIC_GATEWAY_URL']?.trim();\n if (!url) {\n this.log.warn('[AiCreditMeter] GLOBAL_PUBLIC_GATEWAY_URL not set; cannot price AI credits', {\n productId: this.productId,\n model: input.model,\n });\n return null;\n }\n try {\n const client = await this.getPricingClient(url);\n const hasCacheCounts = input.cacheReadTokens != null || input.cacheWriteTokens != null;\n const priceCache = hasCacheCounts && (await this.supportsCachePricing(client, input.model));\n const response = await client.crossLayerQuery<{ quoteAiCredits?: number | null }>({\n ...this.pricingRequest(),\n query: priceCache ? QUOTE_AI_CREDITS_WITH_CACHE_QUERY : QUOTE_AI_CREDITS_QUERY,\n variables: {\n model: input.model,\n inputTokens: input.inputTokens,\n outputTokens: input.outputTokens,\n ...(priceCache\n ? { cacheReadTokens: input.cacheReadTokens ?? 0, cacheWriteTokens: input.cacheWriteTokens ?? 0 }\n : {}),\n },\n });\n if (response.errors?.length) {\n throw new Error(response.errors.map((error) => error.message).join(', '));\n }\n const credits = response.data?.quoteAiCredits;\n if (typeof credits !== 'number' || !Number.isFinite(credits) || credits < 0) {\n throw new Error(`quoteAiCredits returned no usable value (${String(credits)})`);\n }\n return credits;\n } catch (error) {\n this.log.warn('[AiCreditMeter] Failed to quote AI credits; skipping charge', {\n productId: this.productId,\n model: input.model,\n error: errorMessage(error),\n });\n return null;\n }\n }\n\n /**\n * Validate, price and record one completed assistant turn. See the module\n * header for the contract: throws only {@link AiCreditInputError}.\n */\n async charge(input: AiCreditChargeInput): Promise<AiCreditChargeResult> {\n const workspaceId = input.workspaceId?.trim() ?? '';\n if (!workspaceId) {\n throw new AiCreditInputError('WORKSPACE_ID_REQUIRED', 'This request has no workspace context.');\n }\n const invalid = validateAiTokenUsage(input, this.maxTokensPerReport);\n if (invalid) throw new AiCreditInputError(invalid.code, invalid.message);\n\n const hash = this.hashFor(input.sessionId, input.messageId);\n const logFields = {\n productId: this.productId,\n quotaName: this.quotaName,\n workspaceId,\n sessionId: input.sessionId,\n messageId: input.messageId,\n model: input.model,\n inputTokens: input.inputTokens,\n outputTokens: input.outputTokens,\n };\n const skipped = (reason: AiCreditSkipReason, credits: number | null, detail?: string): AiCreditChargeResult => {\n this.log.warn(`[AiCreditMeter] turn not charged (${reason})`, { ...logFields, credits, detail });\n return { status: 'skipped', reason, credits, hash, quotaName: this.quotaName, ...(detail ? { detail } : {}) };\n };\n\n if (this.guard) {\n try {\n const verdict = await this.guard({ ...input, workspaceId });\n if (!verdict.allow) return skipped('GUARD_REFUSED', null, verdict.detail);\n } catch (error) {\n // Fail open: a guard's infrastructure blip must not silently stop metering.\n this.log.warn('[AiCreditMeter] charge guard threw; charging anyway', {\n ...logFields,\n error: errorMessage(error),\n });\n }\n }\n\n const credits = await this.quote(input);\n if (credits === null) return skipped('NOT_PRICED', null);\n if (credits <= 0) return skipped('ZERO_COST', credits);\n\n try {\n await this.trackUsage({\n workspaceId,\n amount: credits,\n description: input.description?.trim() || `AI credits for session ${input.sessionId}`,\n userId: input.userId ?? undefined,\n hash,\n metadata: {\n model: input.model,\n sessionId: input.sessionId,\n messageId: input.messageId,\n inputTokens: input.inputTokens,\n outputTokens: input.outputTokens,\n ...(input.cacheReadTokens != null || input.cacheWriteTokens != null\n ? { cacheReadTokens: input.cacheReadTokens ?? 0, cacheWriteTokens: input.cacheWriteTokens ?? 0 }\n : {}),\n credits,\n ...input.metadata,\n },\n });\n } catch (error) {\n return skipped('RECORD_FAILED', credits, errorMessage(error));\n }\n\n this.log.info(`[AiCreditMeter] Charged ${credits} AI credits for session ${input.sessionId}`, {\n ...logFields,\n credits,\n });\n return { status: 'charged', credits, hash, quotaName: this.quotaName };\n }\n\n /**\n * Read the quota's ENFORCED usage from wspace-activity-svc — the ledger the\n * charge lands on and the gateway's `@usage` check reads. All active rows are\n * summed, because a workspace can hold several (plan + add-ons, or duplicate\n * rows) and `checkWorkspaceQuota` sums them; a single-row read under-reports.\n *\n * Returns null (never throws) when activity is unreachable or no assignment\n * exists, so a screen can show \"not provisioned\" instead of a confident zero.\n */\n async readUsage(workspaceId: string, quotaName: string = this.quotaName): Promise<WorkspaceQuotaUsage | null> {\n try {\n const data = await this.activityRequest<{ workspaceQuotaAssignments?: AssignmentRow[] | null }>(\n workspaceId,\n WORKSPACE_QUOTA_ASSIGNMENTS_QUERY,\n { workspaceId: workspaceId.trim() }\n );\n const rows = (data.workspaceQuotaAssignments ?? []).filter((row) => row.isActive && row.quotaName === quotaName);\n if (rows.length === 0) return null;\n const used = rows.reduce((sum, row) => sum + (Number.isFinite(row.used) ? row.used : 0), 0);\n const noLimit = rows.some((row) => row.noLimit);\n const limit = noLimit ? null : rows.reduce((sum, row) => sum + (row.limit ?? 0), 0);\n return {\n quotaName,\n used,\n limit,\n noLimit,\n remaining: limit === null ? null : Math.max(limit - used, 0),\n assignments: rows.length,\n };\n } catch (error) {\n this.log.warn('[AiCreditMeter] Failed to read workspace quota usage', {\n productId: this.productId,\n quotaName,\n workspaceId,\n error: errorMessage(error),\n });\n return null;\n }\n }\n\n /**\n * Ask wspace-activity-svc whether `amount` of the quota may be spent — the same\n * `checkWorkspaceQuota` the gateway's `@usage` gate runs, so every activity\n * enforcement rule (row aggregation, renamed keys, the\n * `TEST_ENTITLEMENT_WORKSPACE_IDS` entitlement) applies.\n *\n * Returns null (never throws) when activity cannot answer.\n */\n async checkAllowance(\n workspaceId: string,\n options: { amount?: number; quotaName?: string } = {}\n ): Promise<AiCreditAllowance | null> {\n const quotaName = options.quotaName ?? this.quotaName;\n const amount = options.amount ?? GATE_PROBE_AMOUNT;\n try {\n if (!Number.isFinite(amount) || amount < 0) throw new Error('amount must be a non-negative finite number');\n const data = await this.activityRequest<{\n checkWorkspaceQuota?: {\n allowed?: boolean | null;\n assignmentId?: string | null;\n limitLeft?: number | null;\n noLimit?: boolean | null;\n } | null;\n }>(workspaceId, CHECK_WORKSPACE_QUOTA_QUERY, { workspaceId: workspaceId.trim(), quotaName, amount });\n const result = data.checkWorkspaceQuota;\n if (!result || typeof result.allowed !== 'boolean') {\n throw new Error('checkWorkspaceQuota returned no verdict');\n }\n return {\n quotaName,\n allowed: result.allowed,\n provisioned: result.assignmentId != null,\n noLimit: result.noLimit === true,\n limitLeft: typeof result.limitLeft === 'number' && Number.isFinite(result.limitLeft) ? result.limitLeft : null,\n };\n } catch (error) {\n this.log.warn('[AiCreditMeter] Failed to check workspace quota allowance', {\n productId: this.productId,\n quotaName,\n workspaceId,\n error: errorMessage(error),\n });\n return null;\n }\n }\n\n /**\n * Pre-flight gate for an AI call. Reads the ledger standing\n * ({@link readUsage}); when it shows a limited budget spent, the refusal is\n * confirmed with activity's {@link checkAllowance} before it is returned.\n *\n * - not provisioned or unreadable -> not exhausted (the call is not gated);\n * - budget left, or no limit -> not exhausted (no second call);\n * - spent and activity refuses -> exhausted;\n * - spent and activity cannot answer -> exhausted (fail closed on a known\n * spent budget, as before this check existed);\n * - spent but activity allows -> not exhausted, `entitled: true`. This\n * is a test-entitled doctor workspace; the call proceeds and\n * {@link charge} still records it.\n */\n async readGate(workspaceId: string, quotaName: string = this.quotaName): Promise<AiCreditGate> {\n const usage = await this.readUsage(workspaceId, quotaName);\n const spent = usage !== null && !usage.noLimit && (usage.remaining ?? 0) <= 0;\n if (!spent) return { usage, exhausted: false, entitled: false };\n\n const allowance = await this.checkAllowance(workspaceId, { quotaName });\n if (allowance?.allowed) {\n this.log.info('[AiCreditMeter] budget spent but activity allows the call (test entitlement); not refused', {\n productId: this.productId,\n quotaName,\n workspaceId,\n used: usage.used,\n limit: usage.limit,\n });\n return { usage, exhausted: false, entitled: true };\n }\n return { usage, exhausted: true, entitled: false };\n }\n\n private async trackUsage(record: {\n workspaceId: string;\n amount: number;\n description: string;\n userId: string | undefined;\n hash: string;\n metadata: Record<string, unknown>;\n }): Promise<void> {\n const data = await this.activityRequest<{ trackUsage?: boolean | null }>(record.workspaceId, TRACK_USAGE_MUTATION, {\n input: {\n // Sent in the input AND as x-workspace-id: activity takes the workspace from request\n // context, and the @rbac directive resolves input.workspaceId.\n workspaceId: record.workspaceId,\n quotaName: this.quotaName,\n productId: this.productId,\n amount: record.amount,\n description: record.description,\n userId: record.userId,\n hash: record.hash,\n metadata: record.metadata,\n },\n });\n if (data.trackUsage !== true) {\n throw new Error(`trackUsage did not confirm the record (returned ${String(data.trackUsage)})`);\n }\n }\n\n private async activityRequest<T>(workspaceId: string, query: string, variables: Record<string, unknown>): Promise<T> {\n const url = this.activityGatewayUrl ?? process.env['WSPACE_INT_GATEWAY_URL']?.trim();\n if (!url) throw new Error('WSPACE_INT_GATEWAY_URL not set; cannot reach wspace-activity-svc');\n const workspace = workspaceId.trim();\n if (!workspace) throw new Error('workspaceId is required');\n\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), this.requestTimeoutMs);\n try {\n const response = await this.fetchImpl(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'x-actor-type': 'service',\n 'x-actor-id': this.resolveServiceName(),\n ...internalServiceHeaders(),\n 'x-workspace-id': workspace,\n },\n body: JSON.stringify({ query, variables }),\n signal: controller.signal,\n });\n if (!response.ok) {\n const body = await response.text().catch(() => response.statusText);\n throw new Error(`activity request failed with HTTP ${response.status}: ${body.slice(0, 500)}`);\n }\n const result = (await response.json()) as GraphQLBody<T>;\n if (result.errors?.length) {\n throw new Error(result.errors.map((error) => error.message).join(', '));\n }\n if (!result.data) throw new Error('activity response did not include data');\n return result.data;\n } finally {\n clearTimeout(timeout);\n }\n }\n\n /** Options shared by every pricing call. */\n private pricingRequest(): Pick<GraphQLRequestOptions, 'headers' | 'timeout' | 'skipRetry' | 'skipCircuitBreaker'> {\n return {\n // Only the actor type: the signed service JWT is the identity. An x-actor-id on a\n // service token is read as \"on behalf of\" and downgrades the actor.\n headers: { 'x-actor-type': 'service' },\n timeout: this.requestTimeoutMs,\n skipRetry: true,\n skipCircuitBreaker: true,\n };\n }\n\n /** Whether billing prices cache counts. Any failure reads as \"no\" and falls back to input/output. */\n private async supportsCachePricing(client: AiCreditPricingTransport, model: string): Promise<boolean> {\n try {\n const response = await client.crossLayerQuery<{ aiCacheTokenPricingSupported?: boolean | null }>({\n ...this.pricingRequest(),\n query: CACHE_PRICING_CAPABILITY_QUERY,\n variables: {},\n });\n if (response.data?.aiCacheTokenPricingSupported === true) return true;\n } catch {\n // Logged below; the turn is still priced on input/output.\n }\n this.log.warn('[AiCreditMeter] billing does not price cache tokens; quoting input/output only', {\n productId: this.productId,\n model,\n });\n return false;\n }\n\n private resolveServiceName(): string {\n return (\n this.serviceName ||\n process.env['SERVICE_IDENTITY'] ||\n process.env['SERVICE_NAME'] ||\n `wspace-${this.productId}-svc`\n );\n }\n\n private getPricingClient(url: string): Promise<AiCreditPricingTransport> {\n // Rebuilt when the URL changes, so a client bound to a stale URL cannot keep failing.\n if (this.pricing && this.pricing.url === url) return this.pricing.client;\n const option = this.pricingOption;\n const client = (async (): Promise<AiCreditPricingTransport> => {\n if (option && typeof option === 'function') return option(url);\n if (option) return option;\n const gateway = await import('../gateway/client.js');\n const identity = this.resolveServiceName();\n return new gateway.GatewayClient({\n // This service's OWN layer; the be-sdk signs the service JWT because the call leaves it.\n layer: 'wspace',\n serviceName: identity,\n serviceIdentity: identity,\n crossLayerGatewayUrl: url,\n timeout: this.requestTimeoutMs,\n enableLogging: process.env['NODE_ENV'] !== 'production',\n });\n })();\n this.pricing = { url, client };\n // A failed construction must not be cached forever.\n client.catch(() => {\n if (this.pricing?.client === client) this.pricing = null;\n });\n return client;\n }\n}\n","/**\n * @burdenoff/be-sdk/ai-credits\n *\n * Shared cost-weighted, idempotent AI-credit metering for assistant turns:\n * billing prices the turn (`quoteAiCredits`), wspace-activity-svc records it on\n * the workspace quota (`trackUsage`, deduped by `<prefix>:<session>:<message>`).\n *\n * - {@link AiCreditMeter} — `charge`, `quote`, `readUsage`, `checkAllowance`,\n * `readGate`, `hashFor`.\n * - {@link validateAiTokenUsage}, {@link aiCreditIdempotencyHash},\n * {@link aiCreditQuotaName} — the pure rules, for products' own tests and resolvers.\n *\n * @example\n * ```ts\n * import { AiCreditMeter, isAiCreditInputError } from '@burdenoff/be-sdk/ai-credits';\n *\n * const meter = new AiCreditMeter({ productId: 'healthybowl', hashPrefix: 'hb-assistant' });\n * const result = await meter.charge({ workspaceId, userId, sessionId, messageId, model, inputTokens, outputTokens });\n * ```\n */\n\nexport {\n AI_CREDIT_MAX_TOKENS_PER_REPORT,\n aiCreditIdempotencyHash,\n aiCreditQuotaName,\n defaultAiCreditHashPrefix,\n encodeAiCreditHashComponent,\n validateAiTokenUsage,\n type AiTokenUsageValidationError,\n type AiTokenUsageViolation,\n} from './validation.js';\n\nexport { AiCreditInputError, isAiCreditInputError, type AiCreditInputErrorCode } from './errors.js';\n\nexport { AiCreditMeter, type AiCreditMeterOptions } from './meter.js';\n\nexport type {\n AiCreditAllowance,\n AiCreditChargeGuard,\n AiCreditChargeInput,\n AiCreditChargeResult,\n AiCreditFetch,\n AiCreditGate,\n AiCreditGuardVerdict,\n AiCreditLogger,\n AiCreditPricingTransport,\n AiCreditQuoteInput,\n AiCreditSkipReason,\n AiTokenUsageReport,\n WorkspaceQuotaUsage,\n} from './types.js';\n"],"mappings":";;;;;;;;;AAWA,MAAa,kCAAkC;AAiB/C,SAAS,MAAM,OAA2C;CACxD,OAAO,OAAO,UAAU,YAAY,MAAM,KAAK,CAAC,CAAC,WAAW;AAC9D;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AI,uBACZ,QAAQ,IAAI,mBACZ,UAAU,KAAK,UAAU;CAE7B;CAEA,AAAQ,iBAAiB,KAAgD;EAEvE,IAAI,KAAK,WAAW,KAAK,QAAQ,QAAQ,KAAK,OAAO,KAAK,QAAQ;EAClE,MAAM,SAAS,KAAK;EACpB,MAAM,UAAU,YAA+C;GAC7D,IAAI,UAAU,OAAO,WAAW,YAAY,OAAO,OAAO,GAAG;GAC7D,IAAI,QAAQ,OAAO;GACnB,MAAM,UAAU,MAAM,OAAO,uBAAuB;GACpD,MAAM,WAAW,KAAK,mBAAmB;GACzC,OAAO,IAAI,QAAQ,cAAc;IAE/B,OAAO;IACP,aAAa;IACb,iBAAiB;IACjB,sBAAsB;IACtB,SAAS,KAAK;IACd,eAAe,QAAQ,IAAI,gBAAgB;GAC7C,CAAC;EACH,EAAC,CAAE;EACH,KAAK,UAAU;GAAE;GAAK;EAAO;EAE7B,OAAO,YAAY;GACjB,IAAI,KAAK,SAAS,WAAW,QAAQ,KAAK,UAAU;EACtD,CAAC;EACD,OAAO;CACT;AACF"}
|
|
@@ -4,12 +4,11 @@ declare const ACTOR_ORIGIN_HEADER = "x-actor-origin";
|
|
|
4
4
|
declare const ASSISTANT_SESSION_ID_HEADER = "x-assistant-session-id";
|
|
5
5
|
declare const ASSISTANT_CORRELATION_ID_HEADER = "x-assistant-correlation-id";
|
|
6
6
|
interface AssistantSessionAttribution {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
actorOrigin: ActorOrigin;
|
|
8
|
+
assistantSessionId: string;
|
|
9
|
+
assistantCorrelationId?: string;
|
|
10
10
|
}
|
|
11
11
|
declare function toAssistantSessionAttribution(actorOrigin: unknown, assistantSessionId: unknown, assistantCorrelationId?: unknown): AssistantSessionAttribution | undefined;
|
|
12
12
|
declare function parseAssistantSessionHeaders(getHeader: (name: string) => string | null | undefined): AssistantSessionAttribution | undefined;
|
|
13
13
|
declare function readAssistantSessionAttribution(value: unknown): AssistantSessionAttribution | undefined;
|
|
14
|
-
|
|
15
|
-
export { type AssistantSessionAttribution as A, AI_ASSISTANT_ACTOR_ORIGIN as a, type ActorOrigin as b, ACTOR_ORIGIN_HEADER as c, ASSISTANT_CORRELATION_ID_HEADER as d, ASSISTANT_SESSION_ID_HEADER as e, parseAssistantSessionHeaders as p, readAssistantSessionAttribution as r, toAssistantSessionAttribution as t };
|
|
14
|
+
export { ActorOrigin as a, readAssistantSessionAttribution as c, ASSISTANT_SESSION_ID_HEADER as i, toAssistantSessionAttribution as l, AI_ASSISTANT_ACTOR_ORIGIN as n, AssistantSessionAttribution as o, ASSISTANT_CORRELATION_ID_HEADER as r, parseAssistantSessionHeaders as s, ACTOR_ORIGIN_HEADER as t };
|