npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@grantex/vercel-ai

v0.1.2

Published

Vercel AI SDK integration for the Grantex delegated authorization protocol

Readme

@grantex/vercel-ai

Vercel AI SDK integration for the Grantex delegated authorization protocol.

Adds scope-enforced tools and audit logging to any Vercel AI SDK agent.

Homepage | Docs | Sign Up Free | GitHub

Install

npm install @grantex/vercel-ai @grantex/sdk ai zod

Quick Start

Scope-Enforced Tools

Create Vercel AI SDK tools with Grantex authorization. Scope is checked at construction time — if the token is missing the required scope, createGrantexTool throws immediately, before the LLM can invoke the tool:

import { createGrantexTool } from '@grantex/vercel-ai';
import { z } from 'zod';

const readCalendar = createGrantexTool({
  name: 'read_calendar',
  description: 'Read upcoming calendar events',
  parameters: z.object({
    date: z.string().describe('Date in YYYY-MM-DD format'),
  }),
  grantToken,                     // JWT from Grantex token exchange
  requiredScope: 'calendar:read', // checked at construction time
  execute: async (args) => {
    return await getCalendarEvents(args.date);
  },
});

// Use with generateText, streamText, etc.
import { generateText } from 'ai';

const { text } = await generateText({
  model: openai('gpt-4'),
  tools: { read_calendar: readCalendar },
  prompt: 'What meetings do I have today?',
});

Inspect Grant Scopes

Use getGrantScopes to check what scopes a token has before creating tools:

import { getGrantScopes } from '@grantex/vercel-ai';

const scopes = getGrantScopes(grantToken);
// → ['calendar:read', 'email:send']

Audit Logging

Wrap tools with withAuditLogging to log every invocation to the Grantex audit trail:

import { Grantex } from '@grantex/sdk';
import { createGrantexTool, withAuditLogging } from '@grantex/vercel-ai';

const client = new Grantex({ apiKey: process.env.GRANTEX_API_KEY });

const audited = withAuditLogging(readCalendar, client, {
  agentId: 'ag_01ABC...',
  grantId: 'grnt_01XYZ...',
});

// Use audited in place of readCalendar — logs success/failure automatically

API Reference

createGrantexTool(options)

Creates a Vercel AI SDK tool with Grantex scope enforcement.

| Option | Type | Description | |--------|------|-------------| | name | string | Tool name | | description | string | Tool description | | parameters | z.ZodTypeAny | Zod schema for tool arguments | | grantToken | string | Grantex JWT from token exchange | | requiredScope | string | Scope required — checked at construction time | | execute | (args, options) => Promise<Result> | Tool implementation |

Throws GrantexScopeError if scope is missing.

getGrantScopes(grantToken)

Returns the string[] of scopes from the token's scp claim (offline, no network call).

withAuditLogging(tool, client, options)

Wraps a Grantex tool with audit logging.

| Option | Type | Description | |--------|------|-------------| | agentId | string | Agent ID for audit attribution | | grantId | string | Grant ID for the session | | toolName | string? | Override tool name in audit entries |

GrantexScopeError

Error thrown when a grant token is missing the required scope.

| Property | Type | Description | |----------|------|-------------| | requiredScope | string | The scope that was required | | grantedScopes | string[] | The scopes the token actually has |

Requirements

  • Node.js 18+
  • @grantex/sdk >= 0.1.0
  • ai >= 4.0.0 (Vercel AI SDK)
  • zod >= 3.0.0

Links

Grantex Ecosystem

This package is part of the Grantex ecosystem. See also:

License

Apache 2.0