@axiorank/ai-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AxioRank
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,142 @@
1
+ # @axiorank/ai-sdk
2
+
3
+ AxioRank guardrail middleware for the [Vercel AI SDK](https://ai-sdk.dev). One
4
+ `wrapLanguageModel` call governs every `generateText`, `streamText`, and
5
+ `generateObject` through a model: the prompt is inspected before it is sent, the
6
+ completion is inspected and optionally redacted before your app sees it, and the
7
+ tool calls the model proposes are inspected before the SDK executes them.
8
+
9
+ It catches leaked secrets, prompt injection, PII, and destructive tool calls,
10
+ using the same detectors and risk scoring as the rest of AxioRank, the security
11
+ gateway for AI agents.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install @axiorank/ai-sdk ai
17
+ ```
18
+
19
+ `ai` (v7 or later) is a peer dependency.
20
+
21
+ ## Quickstart
22
+
23
+ ```ts
24
+ import { wrapLanguageModel } from "ai";
25
+ import { openai } from "@ai-sdk/openai";
26
+ import { createAxioRankMiddleware } from "@axiorank/ai-sdk";
27
+
28
+ const model = wrapLanguageModel({
29
+ model: openai("gpt-4o"),
30
+ middleware: createAxioRankMiddleware({ apiKey: process.env.AXIORANK_KEY }),
31
+ });
32
+
33
+ // governed: prompt, completion, and proposed tool calls are all inspected
34
+ const { text } = await generateText({ model, prompt: "..." });
35
+ ```
36
+
37
+ Streaming works the same way:
38
+
39
+ ```ts
40
+ const { textStream } = await streamText({ model, prompt: "..." });
41
+ ```
42
+
43
+ ## Try it with no key
44
+
45
+ Leave the API key off and the middleware runs the detectors in-process (no
46
+ signup, no network) as an advisory guard:
47
+
48
+ ```ts
49
+ const model = wrapLanguageModel({
50
+ model: openai("gpt-4o"),
51
+ middleware: createAxioRankMiddleware(), // local mode
52
+ });
53
+ ```
54
+
55
+ ## What it inspects
56
+
57
+ | Surface | When | Default action on a block |
58
+ | --- | --- | --- |
59
+ | Prompt | Before the model is called | Return a refusal (the model is never called) |
60
+ | Completion | After the model responds | Redact (hosted policy) or replace with a refusal |
61
+ | Tool calls | On the calls the model proposes | Strip the denied call so the SDK never runs it |
62
+
63
+ A denied call is handled gracefully by default (`onDeny: "block"`): the surface
64
+ is refused, redacted, or stripped, and generation continues. Set
65
+ `onDeny: "throw"` to raise `AxioRankDeniedError` instead.
66
+
67
+ ## Hosted vs local
68
+
69
+ * **Hosted** (an API key is present): calls the AxioRank gateway, so your
70
+ workspace's real policy applies, every call lands in the audit log, and the
71
+ gateway can return a redacted completion. Enable model I/O enforcement in your
72
+ workspace settings so prompt and completion governance is active; otherwise the
73
+ gateway inspects but does not block them.
74
+ * **Local** (no API key): runs the bundled detectors in-process against the
75
+ default posture. Advisory and block-on-deny only (no policy, no redaction).
76
+
77
+ ## Streaming
78
+
79
+ `streamText` forwards tokens as they arrive, so a secret that appears mid-stream
80
+ would reach the client before it could be caught. The `stream` option controls
81
+ the trade-off:
82
+
83
+ * `"buffer"` (default): accumulate the streamed text, inspect it, then release
84
+ it. Redaction and blocking are correct, at the cost of some first-token
85
+ latency.
86
+ * `"passthrough"`: stream tokens live and inspect at the end for audit only. It
87
+ cannot retract text that has already been sent, so it never redacts.
88
+
89
+ ## Options
90
+
91
+ ```ts
92
+ createAxioRankMiddleware({
93
+ apiKey, // else AXIORANK_API_KEY, then AXIORANK_KEY
94
+ baseUrl, // else AXIORANK_BASE_URL, then https://app.axiorank.com
95
+ mode, // "hosted" | "local" (auto: hosted when a key is present)
96
+ onDeny, // "block" (default) | "throw"
97
+ failOpen, // default true: an AxioRank outage never breaks your app
98
+ inspectPrompts, // default true
99
+ inspectCompletions,// default true
100
+ inspectToolCalls, // default true
101
+ stream, // "buffer" (default) | "passthrough"
102
+ refusal, // text substituted for a blocked prompt or completion
103
+ onDecision, // (phase, verdict) => void, for logging and metrics
104
+ timeoutMs, // default 10000
105
+ model, // model label sent to the gateway (defaults to the call's id)
106
+ });
107
+ ```
108
+
109
+ ## Relationship to `@axiorank/sdk`
110
+
111
+ This middleware guards the **model**: its prompts, its completions, and the tool
112
+ calls it proposes. To guard tool **execution** (the code your tools actually
113
+ run), use `guardTools` from `@axiorank/sdk/vercel`. The two are complementary and
114
+ compose:
115
+
116
+ ```ts
117
+ import { AxioRank } from "@axiorank/sdk";
118
+ import { guardTools } from "@axiorank/sdk/vercel";
119
+ import { createAxioRankMiddleware } from "@axiorank/ai-sdk";
120
+
121
+ const axio = new AxioRank({ apiKey: process.env.AXIORANK_KEY });
122
+
123
+ const model = wrapLanguageModel({
124
+ model: openai("gpt-4o"),
125
+ middleware: createAxioRankMiddleware({ apiKey: process.env.AXIORANK_KEY }),
126
+ });
127
+
128
+ await generateText({
129
+ model,
130
+ tools: guardTools(myTools, axio),
131
+ prompt: "...",
132
+ });
133
+ ```
134
+
135
+ `AxioRankDeniedError` is re-exported here and is the same class `@axiorank/sdk`
136
+ throws, so a single `catch` handles both.
137
+
138
+ ## Links
139
+
140
+ * [axiorank.com](https://axiorank.com)
141
+ * [Documentation](https://axiorank.com/docs)
142
+ * [Issues](https://github.com/frostyhand/AxioRank/issues)