Feat/ai sdk wrapper#50
Merged
Merged
Conversation
- biller.ai(sdk, opts) returns proxied AI SDK with per-step billing - Auto-injects onStepFinish for streamText, generateText, streamObject, generateObject - Chains user's own callbacks alongside billing (non-blocking) - biller.trackAI() for manual tracking at onStepFinish/onFinish - Supports cached input/output token billing with separate debit config - Per-call overrides for inputDebit/outputDebit/cacheDebit - Zero any types, fully generic over TTags
…ad logic - wrap.ts billingStep now delegates to biller.trackAI() - Removes duplicate buildAIPayload + aiTokenStreamConsumer calls - trackAI is the single canonical billing entry point
- Level 1: biller.ai(ai, {inputDebit, outputDebit}) auto-wrapper
- Level 1b: user's own onStepFinish chained with billing
- Level 2: Manual biller.trackAI() in onStepFinish callback
- Demonstrates both streamText and generateText patterns
- Return Record<string, (params) => Promise<unknown>> instead of Record<string, unknown> - Example now works cleanly without any as casts
- biller.ai() now infers TSDK from the input module via const generic - Returns TSDK & overlay — original types (including return) survive - streamText still returns StreamTextResult, generateText returns GenerateTextResult - Example now has zero casts: no as WrappedFn, no as string, no as unknown - Removed unnecessary BillableAI/StreamTextResult/GenerateTextResult types
- Omit streamText/generateText/streamObject/generateObject from TSDK
- Re-add them with Record<string, unknown> params accepting userId
- Return types preserved: streamText returns {text: Promise<string>}, generateText returns {text: string}
…ct AI SDK types - WithUserId<TSDK> type: Omit wrapped fns, re-add with P & BillableCallParams - Preserves original AI SDK param types (model, prompt, tools, etc.) - Preserves original return types (StreamTextResult, GenerateTextResult) - User gets full AI SDK intellisense + userId
Signed-off-by: Devyash Saini <dysaini2004@gmail.com>
… clean up types - Fix cacheTokens operator precedence (?? vs !==) — input/outputCacheTokens now correctly assigned from usage, not from overrides - Remove onFinish double-billing — per-step via onStepFinish covers usage fully - Remove dead StripScrawnParams type - Make BillableCallParams.userId optional — no wasted '' default
…cation 1. Remove unused TagName type from pricing/types.ts 2. Add formatValidationError helper — removes duplicate Zod issue formatting (3 sites) 3. Add performAIStreamCall helper — removes duplicate gRPC stream call (2 sites) 4. Extract initClient/buildCallOptions into grpc/utils.ts — shared by both builders 5. Replace duplicate client init in requestBuilder + streamRequestBuilder with shared utils 6. Extract isValidPriceExpr helper — deduplicates null/type/kind check in both schemas
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.
No description provided.