ai package) through two mechanisms:
gatedVercelTool— wraps a single tool definition with Attesta approval beforeexecuteruns.createAttestaMiddleware— returns middleware that intercepts all tool calls ingenerateText/streamTextpipelines.
@kyberon/attesta.
Installation
Tool Wrapper: gatedVercelTool
Wraps a Vercel AI SDKtool() definition. The wrapped tool runs the full Attesta evaluation pipeline before delegating to the original execute function.
API
GatedVercelToolOptions:
Full Example
Behavior on Denial
By default,gatedVercelTool throws an AttestaDenied error when a tool call is denied:
onDenied callback:
gatedVercelTool creates a shallow copy of the original tool with the wrapped execute function. The original tool object is not mutated. If the tool has no execute function, the original tool is returned unchanged.Middleware: createAttestaMiddleware
Returns an object withexperimental_onToolCall that can be spread into generateText or streamText options. This intercepts all tool calls in the pipeline, not just individually wrapped tools.
API
Full Example
Behavior on Denial
The middleware throwsAttestaDenied when a tool call is denied. Unlike gatedVercelTool, there is no onDenied callback — the error propagates to the caller:
Streaming with streamText
The middleware works withstreamText as well:
Custom Action Names
UsegetActionName to derive meaningful action names from tool calls:
query, execute) but the risk depends on the context.
Tool Wrapper vs. Middleware
LangChain (TS)
TypeScript LangChain integration
Integrations Overview
Compare all framework integrations