ai-sdk-guardrails 1.0.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.
@@ -0,0 +1,121 @@
1
+ import * as ai from 'ai';
2
+ import { generateText, generateObject, streamText, streamObject, embed } from 'ai';
3
+
4
+ interface GuardrailResult {
5
+ /** Whether the guardrail was triggered (blocked the request) */
6
+ tripwireTriggered: boolean;
7
+ /** Human-readable message describing why the guardrail was triggered */
8
+ message?: string;
9
+ /** Detailed metadata about the guardrail execution */
10
+ metadata?: Record<string, unknown>;
11
+ /** Severity level of the guardrail violation */
12
+ severity?: 'low' | 'medium' | 'high' | 'critical';
13
+ /** Suggested action to resolve the issue */
14
+ suggestion?: string;
15
+ /** Performance metrics for the guardrail execution */
16
+ performance?: {
17
+ executionTimeMs: number;
18
+ memoryUsage?: number;
19
+ };
20
+ /** Additional context information */
21
+ context?: {
22
+ guardrailName: string;
23
+ guardrailVersion?: string;
24
+ executedAt: Date;
25
+ environment?: string;
26
+ };
27
+ }
28
+ type GuardrailsParams = {
29
+ inputGuardrails?: InputGuardrail[];
30
+ outputGuardrails?: OutputGuardrail[];
31
+ onInputBlocked?: (error: GuardrailError) => void;
32
+ onOutputBlocked?: (error: GuardrailError) => void;
33
+ throwOnBlocked?: boolean;
34
+ enablePerformanceMonitoring?: boolean;
35
+ };
36
+ type GenerateTextParams = Parameters<typeof generateText>[0];
37
+ type GenerateObjectParams = Parameters<typeof generateObject>[0];
38
+ type StreamTextParams = Parameters<typeof streamText>[0];
39
+ type StreamObjectParams = Parameters<typeof streamObject>[0];
40
+ type EmbedParams = Parameters<typeof embed>[0];
41
+ type GenerateTextResult = Awaited<ReturnType<typeof generateText>>;
42
+ type GenerateObjectResult = Awaited<ReturnType<typeof generateObject>>;
43
+ type StreamTextResult = ReturnType<typeof streamText>;
44
+ type StreamObjectResult = ReturnType<typeof streamObject>;
45
+ type EmbedResult = ReturnType<typeof embed>;
46
+ type InputGuardrailContext = GenerateTextParams | GenerateObjectParams | StreamTextParams | StreamObjectParams | EmbedParams;
47
+ type AIResult = GenerateTextResult | GenerateObjectResult | StreamTextResult | StreamObjectResult | EmbedResult;
48
+ type OutputGuardrailContext = {
49
+ input: InputGuardrailContext;
50
+ result: AIResult;
51
+ };
52
+ interface InputGuardrail {
53
+ /** Unique identifier for the guardrail */
54
+ name: string;
55
+ /** Human-readable description of what this guardrail does */
56
+ description?: string;
57
+ /** Version of the guardrail for tracking changes */
58
+ version?: string;
59
+ /** Tags for categorizing guardrails */
60
+ tags?: string[];
61
+ /** Whether this guardrail is enabled */
62
+ enabled?: boolean;
63
+ /** Priority level for execution order */
64
+ priority?: 'low' | 'medium' | 'high' | 'critical';
65
+ /** Configuration options for the guardrail */
66
+ config?: Record<string, string | number | boolean>;
67
+ /** The main execution function */
68
+ execute: (context: InputGuardrailContext) => Promise<GuardrailResult> | GuardrailResult;
69
+ /** Optional setup function called once when guardrail is initialized */
70
+ setup?: () => Promise<void> | void;
71
+ /** Optional cleanup function called when guardrail is destroyed */
72
+ cleanup?: () => Promise<void> | void;
73
+ }
74
+ interface OutputGuardrail {
75
+ /** Unique identifier for the guardrail */
76
+ name: string;
77
+ /** Human-readable description of what this guardrail does */
78
+ description?: string;
79
+ /** Version of the guardrail for tracking changes */
80
+ version?: string;
81
+ /** Tags for categorizing guardrails */
82
+ tags?: string[];
83
+ /** Whether this guardrail is enabled */
84
+ enabled?: boolean;
85
+ /** Priority level for execution order */
86
+ priority?: 'low' | 'medium' | 'high' | 'critical';
87
+ /** Configuration options for the guardrail */
88
+ config?: Record<string, string | number | boolean>;
89
+ /** The main execution function */
90
+ execute: (context: OutputGuardrailContext, accumulatedText?: string) => Promise<GuardrailResult> | GuardrailResult;
91
+ /** Optional setup function called once when guardrail is initialized */
92
+ setup?: () => Promise<void> | void;
93
+ /** Optional cleanup function called when guardrail is destroyed */
94
+ cleanup?: () => Promise<void> | void;
95
+ }
96
+
97
+ declare class GuardrailError extends Error {
98
+ guardrailName: string;
99
+ reason: string;
100
+ type: 'input' | 'output';
101
+ issues: Array<{
102
+ guardrail: string;
103
+ message: string;
104
+ metadata?: Record<string, unknown>;
105
+ }>;
106
+ constructor(guardrailName: string, reason: string, type: 'input' | 'output');
107
+ getSummary(): {
108
+ totalIssues: number;
109
+ guardrailsTriggered: string[];
110
+ type: "input" | "output";
111
+ };
112
+ }
113
+ declare function generateTextWithGuardrails(params: Parameters<typeof generateText>[0], guardrailParams: GuardrailsParams): Promise<ai.GenerateTextResult<ai.ToolSet, unknown>>;
114
+ declare function generateObjectWithGuardrails(params: Parameters<typeof generateObject>[0], guardrailParams: GuardrailsParams): Promise<ReturnType<typeof generateObject>>;
115
+ declare function streamTextWithGuardrails(params: StreamTextParams, guardrailParams: GuardrailsParams): Promise<ReturnType<typeof streamText>>;
116
+ declare function streamObjectWithGuardrails(params: StreamObjectParams, guardrailParams: GuardrailsParams): Promise<ReturnType<typeof streamObject>>;
117
+ declare function embedWithGuardrails(params: EmbedParams, guardrailParams: GuardrailsParams): Promise<ai.EmbedResult<unknown>>;
118
+ declare function createInputGuardrail(name: string, description: string, execute: InputGuardrail['execute']): InputGuardrail;
119
+ declare function createOutputGuardrail(name: string, execute: OutputGuardrail['execute']): OutputGuardrail;
120
+
121
+ export { type AIResult as A, GuardrailError as G, type InputGuardrailContext as I, type OutputGuardrail as O, type InputGuardrail as a, generateObjectWithGuardrails as b, streamObjectWithGuardrails as c, createInputGuardrail as d, embedWithGuardrails as e, createOutputGuardrail as f, generateTextWithGuardrails as g, type GuardrailResult as h, type GuardrailsParams as i, streamTextWithGuardrails as s };
@@ -0,0 +1,121 @@
1
+ import * as ai from 'ai';
2
+ import { generateText, generateObject, streamText, streamObject, embed } from 'ai';
3
+
4
+ interface GuardrailResult {
5
+ /** Whether the guardrail was triggered (blocked the request) */
6
+ tripwireTriggered: boolean;
7
+ /** Human-readable message describing why the guardrail was triggered */
8
+ message?: string;
9
+ /** Detailed metadata about the guardrail execution */
10
+ metadata?: Record<string, unknown>;
11
+ /** Severity level of the guardrail violation */
12
+ severity?: 'low' | 'medium' | 'high' | 'critical';
13
+ /** Suggested action to resolve the issue */
14
+ suggestion?: string;
15
+ /** Performance metrics for the guardrail execution */
16
+ performance?: {
17
+ executionTimeMs: number;
18
+ memoryUsage?: number;
19
+ };
20
+ /** Additional context information */
21
+ context?: {
22
+ guardrailName: string;
23
+ guardrailVersion?: string;
24
+ executedAt: Date;
25
+ environment?: string;
26
+ };
27
+ }
28
+ type GuardrailsParams = {
29
+ inputGuardrails?: InputGuardrail[];
30
+ outputGuardrails?: OutputGuardrail[];
31
+ onInputBlocked?: (error: GuardrailError) => void;
32
+ onOutputBlocked?: (error: GuardrailError) => void;
33
+ throwOnBlocked?: boolean;
34
+ enablePerformanceMonitoring?: boolean;
35
+ };
36
+ type GenerateTextParams = Parameters<typeof generateText>[0];
37
+ type GenerateObjectParams = Parameters<typeof generateObject>[0];
38
+ type StreamTextParams = Parameters<typeof streamText>[0];
39
+ type StreamObjectParams = Parameters<typeof streamObject>[0];
40
+ type EmbedParams = Parameters<typeof embed>[0];
41
+ type GenerateTextResult = Awaited<ReturnType<typeof generateText>>;
42
+ type GenerateObjectResult = Awaited<ReturnType<typeof generateObject>>;
43
+ type StreamTextResult = ReturnType<typeof streamText>;
44
+ type StreamObjectResult = ReturnType<typeof streamObject>;
45
+ type EmbedResult = ReturnType<typeof embed>;
46
+ type InputGuardrailContext = GenerateTextParams | GenerateObjectParams | StreamTextParams | StreamObjectParams | EmbedParams;
47
+ type AIResult = GenerateTextResult | GenerateObjectResult | StreamTextResult | StreamObjectResult | EmbedResult;
48
+ type OutputGuardrailContext = {
49
+ input: InputGuardrailContext;
50
+ result: AIResult;
51
+ };
52
+ interface InputGuardrail {
53
+ /** Unique identifier for the guardrail */
54
+ name: string;
55
+ /** Human-readable description of what this guardrail does */
56
+ description?: string;
57
+ /** Version of the guardrail for tracking changes */
58
+ version?: string;
59
+ /** Tags for categorizing guardrails */
60
+ tags?: string[];
61
+ /** Whether this guardrail is enabled */
62
+ enabled?: boolean;
63
+ /** Priority level for execution order */
64
+ priority?: 'low' | 'medium' | 'high' | 'critical';
65
+ /** Configuration options for the guardrail */
66
+ config?: Record<string, string | number | boolean>;
67
+ /** The main execution function */
68
+ execute: (context: InputGuardrailContext) => Promise<GuardrailResult> | GuardrailResult;
69
+ /** Optional setup function called once when guardrail is initialized */
70
+ setup?: () => Promise<void> | void;
71
+ /** Optional cleanup function called when guardrail is destroyed */
72
+ cleanup?: () => Promise<void> | void;
73
+ }
74
+ interface OutputGuardrail {
75
+ /** Unique identifier for the guardrail */
76
+ name: string;
77
+ /** Human-readable description of what this guardrail does */
78
+ description?: string;
79
+ /** Version of the guardrail for tracking changes */
80
+ version?: string;
81
+ /** Tags for categorizing guardrails */
82
+ tags?: string[];
83
+ /** Whether this guardrail is enabled */
84
+ enabled?: boolean;
85
+ /** Priority level for execution order */
86
+ priority?: 'low' | 'medium' | 'high' | 'critical';
87
+ /** Configuration options for the guardrail */
88
+ config?: Record<string, string | number | boolean>;
89
+ /** The main execution function */
90
+ execute: (context: OutputGuardrailContext, accumulatedText?: string) => Promise<GuardrailResult> | GuardrailResult;
91
+ /** Optional setup function called once when guardrail is initialized */
92
+ setup?: () => Promise<void> | void;
93
+ /** Optional cleanup function called when guardrail is destroyed */
94
+ cleanup?: () => Promise<void> | void;
95
+ }
96
+
97
+ declare class GuardrailError extends Error {
98
+ guardrailName: string;
99
+ reason: string;
100
+ type: 'input' | 'output';
101
+ issues: Array<{
102
+ guardrail: string;
103
+ message: string;
104
+ metadata?: Record<string, unknown>;
105
+ }>;
106
+ constructor(guardrailName: string, reason: string, type: 'input' | 'output');
107
+ getSummary(): {
108
+ totalIssues: number;
109
+ guardrailsTriggered: string[];
110
+ type: "input" | "output";
111
+ };
112
+ }
113
+ declare function generateTextWithGuardrails(params: Parameters<typeof generateText>[0], guardrailParams: GuardrailsParams): Promise<ai.GenerateTextResult<ai.ToolSet, unknown>>;
114
+ declare function generateObjectWithGuardrails(params: Parameters<typeof generateObject>[0], guardrailParams: GuardrailsParams): Promise<ReturnType<typeof generateObject>>;
115
+ declare function streamTextWithGuardrails(params: StreamTextParams, guardrailParams: GuardrailsParams): Promise<ReturnType<typeof streamText>>;
116
+ declare function streamObjectWithGuardrails(params: StreamObjectParams, guardrailParams: GuardrailsParams): Promise<ReturnType<typeof streamObject>>;
117
+ declare function embedWithGuardrails(params: EmbedParams, guardrailParams: GuardrailsParams): Promise<ai.EmbedResult<unknown>>;
118
+ declare function createInputGuardrail(name: string, description: string, execute: InputGuardrail['execute']): InputGuardrail;
119
+ declare function createOutputGuardrail(name: string, execute: OutputGuardrail['execute']): OutputGuardrail;
120
+
121
+ export { type AIResult as A, GuardrailError as G, type InputGuardrailContext as I, type OutputGuardrail as O, type InputGuardrail as a, generateObjectWithGuardrails as b, streamObjectWithGuardrails as c, createInputGuardrail as d, embedWithGuardrails as e, createOutputGuardrail as f, generateTextWithGuardrails as g, type GuardrailResult as h, type GuardrailsParams as i, streamTextWithGuardrails as s };
package/dist/index.cjs ADDED
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ GuardrailError: () => GuardrailError,
24
+ createInputGuardrail: () => createInputGuardrail,
25
+ createOutputGuardrail: () => createOutputGuardrail,
26
+ embedWithGuardrails: () => embedWithGuardrails,
27
+ generateObjectWithGuardrails: () => generateObjectWithGuardrails,
28
+ generateTextWithGuardrails: () => generateTextWithGuardrails,
29
+ streamObjectWithGuardrails: () => streamObjectWithGuardrails,
30
+ streamTextWithGuardrails: () => streamTextWithGuardrails
31
+ });
32
+ module.exports = __toCommonJS(index_exports);
33
+
34
+ // src/core.ts
35
+ var import_ai = require("ai");
36
+ var GuardrailError = class extends Error {
37
+ constructor(guardrailName, reason, type) {
38
+ super(`${type} guardrail '${guardrailName}' blocked: ${reason}`);
39
+ this.guardrailName = guardrailName;
40
+ this.reason = reason;
41
+ this.type = type;
42
+ this.name = "GuardrailError";
43
+ this.issues = [{ guardrail: guardrailName, message: reason }];
44
+ }
45
+ issues;
46
+ getSummary() {
47
+ return {
48
+ totalIssues: this.issues.length,
49
+ guardrailsTriggered: this.issues.map((i) => i.guardrail),
50
+ type: this.type
51
+ };
52
+ }
53
+ };
54
+ async function runInputGuardrails(guardrails = [], context) {
55
+ for (const guardrail of guardrails) {
56
+ const result = await guardrail.execute(context);
57
+ if (result.tripwireTriggered) {
58
+ throw new GuardrailError(
59
+ guardrail.name,
60
+ result.message || "Input blocked",
61
+ "input"
62
+ );
63
+ }
64
+ }
65
+ }
66
+ async function runOutputGuardrails(guardrails = [], context, accumulatedText) {
67
+ for (const guardrail of guardrails) {
68
+ const result = await guardrail.execute(context, accumulatedText);
69
+ if (result.tripwireTriggered) {
70
+ throw new GuardrailError(
71
+ guardrail.name,
72
+ result.message || "Output blocked",
73
+ "output"
74
+ );
75
+ }
76
+ }
77
+ }
78
+ async function generateTextWithGuardrails(params, guardrailParams) {
79
+ const { inputGuardrails, outputGuardrails } = guardrailParams;
80
+ const startTime = Date.now();
81
+ const finalInputGuardrails = inputGuardrails;
82
+ const finalOutputGuardrails = outputGuardrails;
83
+ try {
84
+ await runInputGuardrails(finalInputGuardrails, params);
85
+ } catch (error) {
86
+ if (error instanceof GuardrailError && guardrailParams.onInputBlocked) {
87
+ guardrailParams.onInputBlocked(error);
88
+ if (guardrailParams.throwOnBlocked !== false) {
89
+ throw error;
90
+ }
91
+ return (0, import_ai.generateText)(params);
92
+ }
93
+ throw error;
94
+ }
95
+ const result = await (0, import_ai.generateText)(params);
96
+ const generationTimeMs = Date.now() - startTime;
97
+ try {
98
+ await runOutputGuardrails(finalOutputGuardrails, {
99
+ input: params,
100
+ result
101
+ });
102
+ } catch (error) {
103
+ if (error instanceof GuardrailError && guardrailParams.onOutputBlocked) {
104
+ guardrailParams.onOutputBlocked(error);
105
+ if (guardrailParams.throwOnBlocked !== false) {
106
+ throw error;
107
+ }
108
+ return { ...result, text: "" };
109
+ }
110
+ throw error;
111
+ }
112
+ return result;
113
+ }
114
+ async function generateObjectWithGuardrails(params, guardrailParams) {
115
+ const { inputGuardrails, outputGuardrails } = guardrailParams;
116
+ const startTime = Date.now();
117
+ const finalInputGuardrails = inputGuardrails;
118
+ const finalOutputGuardrails = outputGuardrails;
119
+ try {
120
+ await runInputGuardrails(finalInputGuardrails, params);
121
+ } catch (error) {
122
+ if (error instanceof GuardrailError && guardrailParams.onInputBlocked) {
123
+ guardrailParams.onInputBlocked(error);
124
+ if (guardrailParams.throwOnBlocked !== false) {
125
+ throw error;
126
+ }
127
+ return (0, import_ai.generateObject)(params);
128
+ }
129
+ throw error;
130
+ }
131
+ const result = await (0, import_ai.generateObject)(params);
132
+ try {
133
+ await runOutputGuardrails(finalOutputGuardrails, {
134
+ input: params,
135
+ result
136
+ });
137
+ } catch (error) {
138
+ if (error instanceof GuardrailError && guardrailParams.onOutputBlocked) {
139
+ guardrailParams.onOutputBlocked(error);
140
+ if (guardrailParams.throwOnBlocked !== false) {
141
+ throw error;
142
+ }
143
+ return { ...result, object: null };
144
+ }
145
+ throw error;
146
+ }
147
+ return result;
148
+ }
149
+ async function streamTextWithGuardrails(params, guardrailParams) {
150
+ const { inputGuardrails, outputGuardrails } = guardrailParams;
151
+ const finalInputGuardrails = inputGuardrails;
152
+ const finalOutputGuardrails = outputGuardrails;
153
+ try {
154
+ await runInputGuardrails(finalInputGuardrails, params);
155
+ } catch (error) {
156
+ if (error instanceof GuardrailError && guardrailParams.onInputBlocked) {
157
+ guardrailParams.onInputBlocked(error);
158
+ if (guardrailParams.throwOnBlocked !== false) {
159
+ throw error;
160
+ }
161
+ }
162
+ throw error;
163
+ }
164
+ const result = await (0, import_ai.streamText)(params);
165
+ if (!finalOutputGuardrails) {
166
+ return result;
167
+ }
168
+ let accumulatedText = "";
169
+ const transformedStream = new ReadableStream({
170
+ start(controller) {
171
+ const reader = result.textStream.getReader();
172
+ const processChunk = async () => {
173
+ try {
174
+ const { done, value } = await reader.read();
175
+ if (done) {
176
+ controller.close();
177
+ return;
178
+ }
179
+ accumulatedText += value;
180
+ try {
181
+ await runOutputGuardrails(
182
+ finalOutputGuardrails,
183
+ {
184
+ input: params,
185
+ result
186
+ },
187
+ accumulatedText
188
+ );
189
+ controller.enqueue(value);
190
+ processChunk();
191
+ } catch (error) {
192
+ if (error instanceof GuardrailError) {
193
+ if (guardrailParams.onOutputBlocked) {
194
+ guardrailParams.onOutputBlocked(error);
195
+ }
196
+ if (guardrailParams.throwOnBlocked !== false) {
197
+ controller.error(error);
198
+ return;
199
+ }
200
+ } else {
201
+ controller.error(error);
202
+ return;
203
+ }
204
+ }
205
+ } catch (error) {
206
+ controller.error(error);
207
+ }
208
+ };
209
+ processChunk();
210
+ }
211
+ });
212
+ return {
213
+ ...result,
214
+ textStream: transformedStream
215
+ };
216
+ }
217
+ async function streamObjectWithGuardrails(params, guardrailParams) {
218
+ const { inputGuardrails } = guardrailParams;
219
+ await runInputGuardrails(inputGuardrails, params);
220
+ const result = await (0, import_ai.streamObject)(params);
221
+ return result;
222
+ }
223
+ async function embedWithGuardrails(params, guardrailParams) {
224
+ const { inputGuardrails } = guardrailParams;
225
+ await runInputGuardrails(inputGuardrails, params);
226
+ const result = await (0, import_ai.embed)(params);
227
+ return result;
228
+ }
229
+ function createInputGuardrail(name, description, execute) {
230
+ return { name, description, execute };
231
+ }
232
+ function createOutputGuardrail(name, execute) {
233
+ return { name, execute };
234
+ }
235
+ // Annotate the CommonJS export names for ESM import in node:
236
+ 0 && (module.exports = {
237
+ GuardrailError,
238
+ createInputGuardrail,
239
+ createOutputGuardrail,
240
+ embedWithGuardrails,
241
+ generateObjectWithGuardrails,
242
+ generateTextWithGuardrails,
243
+ streamObjectWithGuardrails,
244
+ streamTextWithGuardrails
245
+ });
@@ -0,0 +1,2 @@
1
+ export { G as GuardrailError, h as GuardrailResult, i as GuardrailsParams, a as InputGuardrail, O as OutputGuardrail, d as createInputGuardrail, f as createOutputGuardrail, e as embedWithGuardrails, b as generateObjectWithGuardrails, g as generateTextWithGuardrails, c as streamObjectWithGuardrails, s as streamTextWithGuardrails } from './index-CWIb12lh.cjs';
2
+ import 'ai';
@@ -0,0 +1,2 @@
1
+ export { G as GuardrailError, h as GuardrailResult, i as GuardrailsParams, a as InputGuardrail, O as OutputGuardrail, d as createInputGuardrail, f as createOutputGuardrail, e as embedWithGuardrails, b as generateObjectWithGuardrails, g as generateTextWithGuardrails, c as streamObjectWithGuardrails, s as streamTextWithGuardrails } from './index-CWIb12lh.js';
2
+ import 'ai';
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ import {
2
+ GuardrailError,
3
+ createInputGuardrail,
4
+ createOutputGuardrail,
5
+ embedWithGuardrails,
6
+ generateObjectWithGuardrails,
7
+ generateTextWithGuardrails,
8
+ streamObjectWithGuardrails,
9
+ streamTextWithGuardrails
10
+ } from "./chunk-BNGJDZMX.js";
11
+ export {
12
+ GuardrailError,
13
+ createInputGuardrail,
14
+ createOutputGuardrail,
15
+ embedWithGuardrails,
16
+ generateObjectWithGuardrails,
17
+ generateTextWithGuardrails,
18
+ streamObjectWithGuardrails,
19
+ streamTextWithGuardrails
20
+ };
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "ai-sdk-guardrails",
3
+ "version": "1.0.0",
4
+ "description": "The safest way to build production AI applications with the Vercel AI SDK. Comprehensive TypeScript library for intelligent input/output validation, streaming safety, and enterprise-grade reliability.",
5
+ "keywords": [
6
+ "ai",
7
+ "guardrails",
8
+ "vercel-ai-sdk",
9
+ "typescript",
10
+ "validation",
11
+ "safety",
12
+ "streaming",
13
+ "security",
14
+ "content-filtering",
15
+ "prompt-injection",
16
+ "ai-safety"
17
+ ],
18
+ "main": "dist/index.js",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js",
23
+ "require": "./dist/index.cjs"
24
+ },
25
+ "./guardrails/input": {
26
+ "types": "./dist/guardrails/input.d.ts",
27
+ "import": "./dist/guardrails/input.js",
28
+ "require": "./dist/guardrails/input.cjs"
29
+ },
30
+ "./guardrails/output": {
31
+ "types": "./dist/guardrails/output.d.ts",
32
+ "import": "./dist/guardrails/output.js",
33
+ "require": "./dist/guardrails/output.cjs"
34
+ }
35
+ },
36
+ "homepage": "https://github.com/jagreehal/ai-sdk-guardrails",
37
+ "bugs": {
38
+ "url": "https://github.com/jagreehal/ai-sdk-guardrails/issues"
39
+ },
40
+ "author": "Jag Reehal<jag@jagreehal.com> (https://jagreehal.com)",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/jagreehal/ai-sdk-guardrails.git"
44
+ },
45
+ "license": "MIT",
46
+ "files": [
47
+ "dist"
48
+ ],
49
+ "type": "module",
50
+ "dependencies": {
51
+ "ai": "^4.3.19",
52
+ "zod": "^3.23.8"
53
+ },
54
+ "devDependencies": {
55
+ "@ai-sdk/openai": "^1.3.23",
56
+ "@arethetypeswrong/cli": "^0.18.2",
57
+ "@changesets/cli": "^2.29.5",
58
+ "@total-typescript/ts-reset": "^0.6.1",
59
+ "@total-typescript/tsconfig": "^1.0.4",
60
+ "@types/eslint-config-prettier": "^6.11.3",
61
+ "@types/node": "^24.0.14",
62
+ "@typescript-eslint/eslint-plugin": "^8.37.0",
63
+ "@typescript-eslint/parser": "^8.37.0",
64
+ "autoevals": "^0.0.130",
65
+ "dotenv": "^17.2.0",
66
+ "eslint-config-prettier": "^10.1.5",
67
+ "eslint-plugin-unicorn": "^59.0.1",
68
+ "mathjs": "^14.5.3",
69
+ "ollama": "^0.5.16",
70
+ "ollama-ai-provider": "^1.2.0",
71
+ "openai": "^5.9.2",
72
+ "prettier": "^3.6.2",
73
+ "tsup": "^8.5.0",
74
+ "typescript": "^5.8.3",
75
+ "typescript-eslint": "^8.37.0",
76
+ "vitest": "^3.2.4"
77
+ },
78
+ "scripts": {
79
+ "build": "tsup",
80
+ "ci": "npm run build && npm run check-format && npm run check-exports && npm run lint && npm run test",
81
+ "lint": "eslint src/**/*.ts",
82
+ "lint:fix": "eslint src/**/*.ts --fix",
83
+ "format": "prettier --write src/**/*.ts",
84
+ "format:check": "prettier --check src/**/*.ts",
85
+ "type-check": "tsc --noEmit",
86
+ "test": "vitest run",
87
+ "check-format": "prettier --check .",
88
+ "check-exports": "attw --pack . --ignore-rules false-esm no-resolution",
89
+ "local-release": "npm run ci && changeset version && changeset publish"
90
+ }
91
+ }