stable

ai

LLM function-calling adapter — buildToolset(vault) emits permission-scoped tool definitions; invokeToolCall() dispatches and re-checks permissions.

@noy-db/in-ai · pnpm add @noy-db/hub @noy-db/in-ai LLM function-calling adapter for noy-db — ACL-scoped collections as tool definitions.

What it does

buildToolset(vault, options?) walks the vault's accessible collections and emits a tool array in the format of your choice (format: 'openai' | 'anthropic' | 'vercel-ai' | 'json-schema'), gated by the caller's keyring. Only list / get tools ship by default (invoices_list, invoices_get); mutation tools (invoices_put, invoices_delete, invoices_count) require opting in via operations. Collections the keyring cannot decrypt never become tools. invokeToolCall(vault, call, options?) dispatches an LLM-returned { name, args } call back to the vault — it re-checks permissions on every invocation regardless of what was published, throwing ToolDeniedError on a fabricated call or ToolNotFoundError on an unparseable name, so a hostile model can never mutate data it wasn't authorized for.

Usage

import { buildToolset, invokeToolCall } from '@noy-db/in-ai'

const tools = buildToolset(vault, { format: 'anthropic', operations: ['list', 'get'] })
const result = await invokeToolCall(
  vault,
  { name: 'invoices_list', args: {} },
  { allowedOperations: ['list', 'get'] },
)

See also