Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .changeset/policy-opa-package.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
'@ai-sdk/policy-opa': patch
Comment thread
gr2m marked this conversation as resolved.
Outdated
---

Introduce `@ai-sdk/policy-opa`, an Open Policy Agent adapter for the
`toolApproval` callback on `generateText` / `streamText` / `ToolLoopAgent`.

Everything is exported from the package root. The engine-neutral core is a
`PolicyClient` interface, `shadow()` for safe policy rollout with
fire-and-forget telemetry, and `wrapMcpTools()` for making approval
configuration total over a discovered tool surface. The OPA layer ships
`opaPolicy` / `optionalOpaPolicy` (Rego-as-code authorization),
`wasmPolicyClient` and `httpPolicyClient` backends (lazy-loaded optional peer
deps), `opaCapabilityMiddleware` for fail-closed model-level tool filtering,
and `normalizeOpaDecision` for users who call OPA themselves.

Sits entirely on top of the public SDK surface, with no changes to `ai`,
`@ai-sdk/provider`, or `@ai-sdk/provider-utils`. Transitive enforcement
(coarse dispatchers like `bash` / `http.request` / MCP proxies) is handled
inside the user's `toolApproval` by parsing the dispatcher input and routing
to the same Rego rule that gates the direct tool.
1 change: 1 addition & 0 deletions .github/konsistent.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"!packages/llamaindex",
"!packages/mcp",
"!packages/otel",
"!packages/policy-opa",
"!packages/provider",
"!packages/provider-utils",
"!packages/react",
Expand Down
1 change: 1 addition & 0 deletions packages/policy-opa/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @ai-sdk/policy
Loading
Loading