-
Notifications
You must be signed in to change notification settings - Fork 5k
feat(policy): add @ai-sdk/policy-opa package (OPA adapter for toolApproval) #15732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2710983
feat(policy): add @ai-sdk/policy-opa package (OPA adapter for toolApp…
dnukumamras 8875801
Merge branch 'main' into dnukumamras/policy-package-prompt-context
dnukumamras 2ab1a03
docs(policy-opa): add runnable git-in-bash example policy
dnukumamras 0f7318d
chore: exclude @ai-sdk/policy-opa from provider-export konsistent rule
dnukumamras 09d4367
fix(policy-opa): match provider tools by id or name in capability mid…
dnukumamras 985c8da
fix(policy-opa): address code-review findings
dnukumamras 223f0f4
refactor(policy-opa): centralize fail-closed evaluate; flatten exampl…
dnukumamras 737984f
Apply suggestions from code review
gr2m a4b9166
Merge branch 'main' into dnukumamras/policy-package-prompt-context
gr2m File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| --- | ||
| '@ai-sdk/policy-opa': patch | ||
| --- | ||
|
|
||
| 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. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # @ai-sdk/policy |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.