feat(express-context): add shared BillingClient abstraction#1289
Merged
Conversation
- Add billing-client.ts with BillingClient interface (checkQuota, recordUsage, logInference) - Add useBilling() to ConstructiveContext (lazy, cached per request) - Refactor agentic-server to use ctx.useBilling() instead of local billing.ts - Delete agentic-server/src/billing.ts (replaced by shared client) - Refactor graphile-llm metering to delegate to shared BillingClient via adapter - Both packages now share the same billing SQL logic from express-context Closes constructive-io/constructive-planning#1054
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extracts billing operations (
checkQuota,recordUsage,logInference) into a sharedBillingClientin@constructive-io/express-context, eliminating duplication betweenagentic-serverandgraphile-llm.Before: Both packages implemented identical SQL calls for billing quota checks and usage recording independently.
After: Single source of truth via
ctx.useBilling():Key design decisions:
useBilling()is lazy + cached per request — only resolves billing/inferenceLog loaders on first call, returns same instance on subsequent callsnullif billing_module not provisioned or noentity_idin JWT (graceful no-op)graphile-llmadapts Graphile's 2-argwithPgClient(pgSettings, fn)to the 1-arg pattern viabillingClientFromCtx()helperagentic-server/src/billing.tsdeleted entirely — router callsctx.useBilling()directlyRelates to constructive-io/constructive-planning#1054
Link to Devin session: https://app.devin.ai/sessions/4a9f098c74fb4cb6a9b6868fcff321db
Requested by: @pyramation