feat(sdk): TypeScript SDK — Vercel AI SDK adapter - #105
Merged
Conversation
Add governMiddleware(run), exposed as @riskkernel/sdk/vercel — an AI SDK language-model middleware whose wrapGenerate/wrapStream hooks tick one governed step per model call. So a run's loop/time budget is enforced and a halt surfaces as BudgetExceeded out of generateText/streamText instead of being swallowed. The daemon decides; the adapter carries no governance logic — the JS analog of the Python LangChain / OpenAI-Agents adapters. The adapter is typed against @ai-sdk/provider via `import type` only, so it's erased at build time and the core stays dependency-free; @ai-sdk/provider is an optional peer, needed only when importing the adapter. Ships as a second tsup entry behind the ./vercel subpath export. Tests cover the enforcement path against the in-process mock daemon: the middleware ticks a step per call, surfaces BudgetExceeded when the loop budget is spent, and never runs the model once the step is rejected (no overspend). A runnable, key-free example (examples/vercel-ai-sdk) halts a looping agent on its loop budget; it typechecks against the real ai@5 package, proving the middleware plugs into wrapLanguageModel. Pinned to AI SDK v5.
prashar32
force-pushed
the
feat/ts-sdk-vercel-adapter
branch
from
June 12, 2026 19:55
3fd2394 to
e9c72be
Compare
Merged
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.
Govern a Vercel AI SDK agent with ~no code change — the JS analog of the Python LangChain / OpenAI-Agents adapters.
governMiddleware(run)(exposed as@riskkernel/sdk/vercel) is an AI SDK language-model middleware: itswrapGenerate/wrapStreamhooks tick one governedrun.step()per model call, so the run's loop/time budget is enforced and a halt surfaces asBudgetExceededout ofgenerateText/streamText— not swallowed. The daemon decides; the adapter carries no governance logic.Keeps the core dependency-free
The adapter is typed against
@ai-sdk/providerviaimport typeonly, so it's erased at build — verified the builtdist/vercel.jshas no runtime import of it.@ai-sdk/provideris an optional peer (tiny, types-only), needed only when you import the adapter; the core client still pulls nothing. Ships as a second tsup entry behind the./vercelsubpath export.Tests
BudgetExceededwhen the loop budget is spent, and does not run the model once the step is rejected (no overspend).examples/vercel-ai-sdk) halts a looping agent on its loop budget. It typechecks against the realai@5package, provinggovernMiddleware(run)is assignable towrapLanguageModel'smiddleware. Pinned + documented to AI SDK v5.Closes #81.
Stacked on #104 (the dev-dep security bumps) so it inherits the vitest 3 / Node 20 baseline. Review base is
chore/ts-sdk-dep-bumps; GitHub will retarget this tomainonce #104 merges.