{"_id":"@authensor/vercel-ai-sdk","_rev":"2-c9cc29ec9d2be47cc06644c521f1e986","name":"@authensor/vercel-ai-sdk","dist-tags":{"latest":"0.1.0"},"versions":{"0.0.1":{"name":"@authensor/vercel-ai-sdk","version":"0.0.1","keywords":["authensor","vercel","vercel-ai-sdk","ai-sdk","guardrail","ai-safety","agent-safety","agentic-ai","action-authorization","tool-governance","policy-enforcement","vercel-guardrail","vercel-safety"],"license":"MIT","_id":"@authensor/vercel-ai-sdk@0.0.1","maintainers":[{"name":"jkearn","email":"john@authensor.com"}],"homepage":"https://github.com/authensor/authensor","bugs":{"url":"https://github.com/authensor/authensor/issues"},"dist":{"shasum":"0fa7709b0bb6c72809f53e71181353f7402df466","tarball":"https://registry.npmjs.org/@authensor/vercel-ai-sdk/-/vercel-ai-sdk-0.0.1.tgz","fileCount":6,"integrity":"sha512-/6OWvK3o5jT7kEUn21/ZOq2YSrQpensdds1IR84kiC0XwaBw2W5g0hQN9VE4wAvgMDQxE9DuhNXnKn+zgDquPw==","signatures":[{"sig":"MEUCIDqXim6N53xI6N39DSADyJzC44cV43dvupw18AhA71SoAiEA7qJe9lQ9hVtmiSWiwC4aNVh/4OoWwIDi0vei3pZUwf4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":21659},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"gitHead":"814d74dd7e0ad287ca74bfdd1730ec5aa768165b","scripts":{"dev":"tsc --watch","test":"vitest run --passWithNoTests","build":"tsc","clean":"rm -rf dist","typecheck":"tsc --noEmit","test:watch":"vitest"},"_npmUser":{"name":"jkearn","email":"john@authensor.com"},"repository":{"url":"git+https://github.com/authensor/authensor.git","type":"git","directory":"adapters/vercel-ai-sdk"},"_npmVersion":"10.8.2","description":"Authensor guardrail adapter for Vercel AI SDK","directories":{},"_nodeVersion":"20.20.0","dependencies":{"@authensor/sdk":"workspace:*"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^1.1.0","typescript":"^5.3.0","@types/node":"^20.10.0"},"peerDependencies":{"ai":">=3.0.0"},"peerDependenciesMeta":{"ai":{"optional":false}},"_npmOperationalInternal":{"tmp":"tmp/vercel-ai-sdk_0.0.1_1773535387738_0.49586996006427975","host":"s3://npm-registry-packages-npm-production"}},"0.1.0":{"name":"@authensor/vercel-ai-sdk","version":"0.1.0","description":"Authensor guardrail adapter for Vercel AI SDK","type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"dependencies":{"@authensor/sdk":"0.1.0"},"peerDependencies":{"ai":">=3.0.0"},"peerDependenciesMeta":{"ai":{"optional":false}},"devDependencies":{"@types/node":"^20.10.0","typescript":"^5.3.0","vitest":"^1.1.0"},"keywords":["authensor","vercel","vercel-ai-sdk","ai-sdk","guardrail","ai-safety","agent-safety","agentic-ai","action-authorization","tool-governance","policy-enforcement","vercel-guardrail","vercel-safety"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/authensor/authensor.git","directory":"adapters/vercel-ai-sdk"},"homepage":"https://github.com/authensor/authensor","publishConfig":{"access":"public"},"scripts":{"build":"tsc","dev":"tsc --watch","test":"vitest run --passWithNoTests","test:watch":"vitest","typecheck":"tsc --noEmit","clean":"rm -rf dist"},"_id":"@authensor/vercel-ai-sdk@0.1.0","bugs":{"url":"https://github.com/authensor/authensor/issues"},"_integrity":"sha512-8rJKp7Iiajno6gjm3xfGGmFhFFbvUXEOW6CXDg/qeAEGMFkyWmyUO0LNZyi94zynMEKPeX6GiSL/5RCaaoPLGw==","_resolved":"/private/var/folders/_h/xdjfwx_n3qxc_plpqltl399m0000gn/T/a35165b6e32878734f005454e1e99560/authensor-vercel-ai-sdk-0.1.0.tgz","_from":"file:authensor-vercel-ai-sdk-0.1.0.tgz","_nodeVersion":"20.20.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-8rJKp7Iiajno6gjm3xfGGmFhFFbvUXEOW6CXDg/qeAEGMFkyWmyUO0LNZyi94zynMEKPeX6GiSL/5RCaaoPLGw==","shasum":"2bd4a6b67b67bd28045f6a4fb57da875552696fb","tarball":"https://registry.npmjs.org/@authensor/vercel-ai-sdk/-/vercel-ai-sdk-0.1.0.tgz","fileCount":7,"unpackedSize":22721,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIGN5aiKjKpCZIdpsL3v0yftPwzLvi0WFEJYbI/d0EyEnAiEA4yQTsROLzuIxPTVKT/VnOaoiZZiW94HA8qRyKKuY0CU="}]},"_npmUser":{"name":"jkearn","email":"john@authensor.com"},"directories":{},"maintainers":[{"name":"jkearn","email":"john@authensor.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/vercel-ai-sdk_0.1.0_1781250064098_0.27017289072996653"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-15T00:43:07.659Z","modified":"2026-06-12T07:41:04.401Z","0.0.1":"2026-03-15T00:43:07.893Z","0.1.0":"2026-06-12T07:41:04.235Z"},"bugs":{"url":"https://github.com/authensor/authensor/issues"},"license":"MIT","homepage":"https://github.com/authensor/authensor","keywords":["authensor","vercel","vercel-ai-sdk","ai-sdk","guardrail","ai-safety","agent-safety","agentic-ai","action-authorization","tool-governance","policy-enforcement","vercel-guardrail","vercel-safety"],"repository":{"type":"git","url":"git+https://github.com/authensor/authensor.git","directory":"adapters/vercel-ai-sdk"},"description":"Authensor guardrail adapter for Vercel AI SDK","maintainers":[{"name":"jkearn","email":"john@authensor.com"}],"readme":"# @authensor/vercel-ai-sdk\n\nAuthensor guardrail adapter for the [Vercel AI SDK](https://sdk.vercel.ai). Evaluates tool calls against Authensor policies, integrating with the AI SDK's tool execution flow and `experimental_needsApproval` flag.\n\n## Installation\n\n```bash\nnpm install @authensor/vercel-ai-sdk ai\n```\n\n## Quick Start\n\n```typescript\nimport { generateText, tool } from 'ai';\nimport { openai } from '@ai-sdk/openai';\nimport { z } from 'zod';\nimport { AuthensorVercelGuard } from '@authensor/vercel-ai-sdk';\n\nconst guard = new AuthensorVercelGuard({\n  controlPlaneUrl: 'http://localhost:3000',\n  apiKey: process.env.AUTHENSOR_API_KEY,\n});\n\n// Wrap your tools — execute is gated by Authensor\nconst tools = guard.wrapTools({\n  getWeather: tool({\n    description: 'Get the weather for a city',\n    parameters: z.object({ city: z.string() }),\n    execute: async ({ city }) => {\n      const response = await fetch(`https://api.weather.com/${city}`);\n      return response.json();\n    },\n  }),\n  sendEmail: tool({\n    description: 'Send an email',\n    parameters: z.object({\n      to: z.string(),\n      subject: z.string(),\n      body: z.string(),\n    }),\n    execute: async ({ to, subject, body }) => {\n      return await emailService.send({ to, subject, body });\n    },\n  }),\n});\n\nconst { text } = await generateText({\n  model: openai('gpt-4o'),\n  tools,\n  prompt: 'What is the weather in Dublin?',\n});\n```\n\n## Using `needsApproval`\n\nDelegate approval decisions to Authensor using the AI SDK's built-in human-in-the-loop:\n\n```typescript\nimport { generateText, tool } from 'ai';\nimport { z } from 'zod';\nimport { AuthensorVercelGuard } from '@authensor/vercel-ai-sdk';\n\nconst guard = new AuthensorVercelGuard('http://localhost:3000');\n\nconst tools = {\n  sendEmail: tool({\n    description: 'Send an email',\n    parameters: z.object({ to: z.string(), body: z.string() }),\n    execute: async ({ to, body }) => emailService.send({ to, body }),\n    // Authensor decides if this tool needs human approval\n    experimental_needsApproval: guard.needsApproval('sendEmail'),\n  }),\n};\n\nconst result = await generateText({\n  model: openai('gpt-4o'),\n  tools,\n  prompt: 'Send a welcome email to new-user@example.com',\n  maxSteps: 5,\n});\n```\n\n## Wrapping Individual Tools\n\n```typescript\nconst weatherTool = guard.wrapTool('getWeather', {\n  description: 'Get weather',\n  parameters: z.object({ city: z.string() }),\n  execute: async ({ city }) => fetchWeather(city),\n});\n```\n\n## Manual Evaluation\n\nFor full control over the policy decision:\n\n```typescript\nconst result = await guard.evaluate('sendEmail', { to: 'admin@company.com' });\n\nif (result.allowed) {\n  await sendEmail({ to: 'admin@company.com' });\n} else if (result.requiresApproval) {\n  // Present to user for approval\n  console.log(`Approval required: ${result.reason}`);\n} else {\n  console.error(`Denied: ${result.reason}`);\n}\n```\n\n## Options\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `controlPlaneUrl` | `string` | (required) | Authensor control plane URL |\n| `apiKey` | `string` | `AUTHENSOR_API_KEY` env | API key for authentication |\n| `principalId` | `string` | `'vercel-ai-agent'` | Identifier for this agent |\n| `principalType` | `string` | `'agent'` | One of: user, agent, service, system |\n| `environment` | `string` | `NODE_ENV` | One of: development, staging, production |\n\n## Error Handling\n\n```typescript\nimport { AuthensorDeniedError } from '@authensor/vercel-ai-sdk';\n\ntry {\n  await guard.guard('dangerous_action', { target: 'production' });\n} catch (err) {\n  if (err instanceof AuthensorDeniedError) {\n    console.log(err.toolName);   // 'dangerous_action'\n    console.log(err.outcome);    // 'deny'\n    console.log(err.receiptId);  // 'receipt-...'\n  }\n}\n```\n\n## How It Works\n\n1. **`wrapTools`** — Intercepts the `execute` function on each tool. Before the original handler runs, Authensor evaluates the tool name and arguments against active policies.\n2. **`needsApproval`** — Returns a function compatible with the AI SDK's `experimental_needsApproval`. It calls Authensor's evaluate endpoint and returns `true` if the policy says `require_approval` or `deny`.\n3. **Fail-closed** — If the Authensor control plane is unreachable, the tool call is blocked. This matches Authensor's core principle of failing safe.\n\n## License\n\nMIT\n","readmeFilename":"README.md"}