@agenttrust/sdk 0.2.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 agenttrust
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,208 @@
1
+ # @agenttrust/sdk
2
+
3
+ Official JavaScript/TypeScript SDK for [AgentTrust](https://agenttrust.ai) — prompt injection detection, agent identity verification, and audit trails for autonomous AI agents.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @agenttrust/sdk
9
+ # or
10
+ yarn add @agenttrust/sdk
11
+ # or
12
+ pnpm add @agenttrust/sdk
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```ts
18
+ import { AgentTrust } from '@agenttrust/sdk'
19
+
20
+ // From environment variable (recommended)
21
+ const at = AgentTrust.fromEnv() // reads AGENTTRUST_API_KEY
22
+
23
+ // Or explicitly
24
+ const at = new AgentTrust({ apiKey: 'atk_YOUR_API_KEY' })
25
+ ```
26
+
27
+ Get your API key at [agenttrust.ai](https://agenttrust.ai/login). Keys are prefixed with `atk_`.
28
+
29
+ ---
30
+
31
+ ## InjectionGuard
32
+
33
+ Scan any text for prompt injection, command execution attempts, and social engineering before your agent acts on it.
34
+
35
+ ```ts
36
+ const result = await at.injectionGuard(text, {
37
+ capabilities: ['send_messages', 'open_links'],
38
+ channel: 'email',
39
+ use_llm_review: true,
40
+ })
41
+
42
+ if (result.blocked) {
43
+ // Hard block — do not proceed
44
+ console.log('Triggers:', result.triggers)
45
+ console.log('Mitigations:', result.mitigations)
46
+ } else if (result.requiresHuman) {
47
+ // Queue for human review
48
+ } else {
49
+ // Safe to execute
50
+ }
51
+ ```
52
+
53
+ ### Options
54
+
55
+ | Option | Type | Required | Description |
56
+ |--------|------|----------|-------------|
57
+ | `capabilities` | `string[]` | ✅ | What your agent can do (e.g. `send_messages`, `open_links`, `data_access`) |
58
+ | `channel` | `'email' \| 'chat' \| 'api'` | — | Source channel for better contextual analysis |
59
+ | `use_llm_review` | `boolean` | — | Enable additional LLM-based risk assessment |
60
+ | `exclusions` | `string[]` | — | Terms that suppress trigger detection |
61
+ | `custom_keywords` | `CustomKeyword[]` | — | Your own keyword triggers with severity |
62
+
63
+ ```ts
64
+ // Custom keywords example
65
+ custom_keywords: [
66
+ { keyword: 'powershell', severity: 'high' },
67
+ { keyword: 'wget', severity: 'medium' },
68
+ ]
69
+ ```
70
+
71
+ > Dashboard-configured keywords and exclusions are automatically merged with request values.
72
+
73
+ ### Response
74
+
75
+ | Field | Type | Description |
76
+ |-------|------|-------------|
77
+ | `risk_level` | `'low' \| 'medium' \| 'high'` | Overall risk assessment |
78
+ | `suggested_mode` | `'allow_execute' \| 'draft_only' \| 'require_human' \| 'block'` | Recommended handling |
79
+ | `triggers` | `string[]` | Rules that matched |
80
+ | `trigger_excerpts` | `Record<string, string[]>` | Supporting excerpts per trigger |
81
+ | `mitigations` | `string[]` | Suggested mitigation actions |
82
+ | `ruleset_version` | `string` | Detection ruleset version |
83
+ | `llm_review` | `LLMReview \| undefined` | AI review block (when `use_llm_review: true`) |
84
+ | `blocked` | `boolean` | Convenience: `true` when `suggested_mode === 'block'` |
85
+ | `requiresHuman` | `boolean` | Convenience: `true` when `suggested_mode === 'require_human'` |
86
+
87
+ ---
88
+
89
+ ## TrustCode — Identity Verification
90
+
91
+ ### Issue a TrustCode
92
+
93
+ Prove your agent's identity when reaching out to users or other systems.
94
+
95
+ ```ts
96
+ const trustCode = await at.issue({
97
+ preset: 'draft_only',
98
+ ttl_seconds: 3600, // 1 hour (default: 86400)
99
+ payload: {
100
+ intent: 'schedule_meeting',
101
+ message: 'Scheduling a meeting on behalf of Acme Corp.',
102
+ },
103
+ })
104
+
105
+ console.log(trustCode.code) // e.g. "gFs2-jbQE-GddW"
106
+ console.log(trustCode.verify_url) // shareable verification link
107
+ console.log(trustCode.badge_html) // embeddable HTML trust badge
108
+ ```
109
+
110
+ ### Verify a TrustCode
111
+
112
+ No API key required — anyone can verify.
113
+
114
+ ```ts
115
+ const identity = await at.verify('gFs2-jbQE-GddW')
116
+
117
+ if (identity.verified) {
118
+ console.log('Agent:', identity.issuer_agent_id)
119
+ console.log('Org:', identity.issuer_org_id)
120
+ console.log('Intent:', identity.payload.intent)
121
+ }
122
+ ```
123
+
124
+ ---
125
+
126
+ ## Framework Examples
127
+
128
+ ### Express middleware
129
+
130
+ ```ts
131
+ import express from 'express'
132
+ import { AgentTrust } from '@agenttrust/sdk'
133
+
134
+ const at = AgentTrust.fromEnv()
135
+ const app = express()
136
+ app.use(express.json())
137
+
138
+ app.post('/agent/run', async (req, res) => {
139
+ const check = await at.injectionGuard(req.body.message, {
140
+ capabilities: ['data_access'],
141
+ channel: 'api',
142
+ })
143
+
144
+ if (check.blocked) {
145
+ return res.status(400).json({
146
+ error: 'Prompt injection detected',
147
+ triggers: check.triggers,
148
+ })
149
+ }
150
+
151
+ if (check.requiresHuman) {
152
+ return res.status(202).json({ status: 'queued_for_review' })
153
+ }
154
+
155
+ // Continue with agent logic...
156
+ })
157
+ ```
158
+
159
+ ### LangChain tool wrapper
160
+
161
+ ```ts
162
+ import { AgentTrust } from '@agenttrust/sdk'
163
+
164
+ const at = AgentTrust.fromEnv()
165
+
166
+ async function secureToolCall(input: string, capabilities: string[]) {
167
+ const check = await at.injectionGuard(input, {
168
+ capabilities,
169
+ use_llm_review: true,
170
+ })
171
+
172
+ if (check.blocked) {
173
+ throw new Error(`Blocked by AgentTrust: ${check.triggers.join(', ')}`)
174
+ }
175
+
176
+ // Call your tool...
177
+ }
178
+ ```
179
+
180
+ ---
181
+
182
+ ## Configuration
183
+
184
+ ```ts
185
+ const at = new AgentTrust({
186
+ apiKey: 'atk_YOUR_API_KEY', // required — get from dashboard
187
+ baseUrl: 'https://agenttrust.ai/api', // optional, override for testing
188
+ })
189
+ ```
190
+
191
+ ### Environment variable
192
+
193
+ Set `AGENTTRUST_API_KEY` and use `AgentTrust.fromEnv()` for cleaner setup.
194
+
195
+ ---
196
+
197
+ ## Requirements
198
+
199
+ - Node.js 18+ (uses native `fetch`)
200
+ - Works with Bun, Deno, and any modern JS/TS runtime
201
+
202
+ ---
203
+
204
+ ## Links
205
+
206
+ - [Dashboard](https://agenttrust.ai)
207
+ - [Documentation](https://agenttrust.ai/docs)
208
+ - [npm](https://npmjs.com/package/@agenttrust/sdk)
@@ -0,0 +1,118 @@
1
+ interface AgentTrustConfig {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ }
5
+ type RiskLevel = 'low' | 'medium' | 'high';
6
+ type SuggestedMode = 'allow_execute' | 'draft_only' | 'require_human' | 'block';
7
+ type Channel = 'email' | 'chat' | 'api';
8
+ type Severity = 'low' | 'medium' | 'high';
9
+ interface CustomKeyword {
10
+ keyword: string;
11
+ severity: Severity;
12
+ }
13
+ interface LLMReview {
14
+ risk_assessment: string;
15
+ confidence: number;
16
+ recommendation: string;
17
+ excerpts: string[];
18
+ }
19
+ interface InjectionGuardOptions {
20
+ /** Capabilities the downstream agent may execute */
21
+ capabilities: string[];
22
+ /** Source channel context */
23
+ channel?: Channel;
24
+ /** Enable additional LLM-based risk assessment */
25
+ use_llm_review?: boolean;
26
+ /** Terms that suppress matching trigger detection */
27
+ exclusions?: string[];
28
+ /** User-defined keyword triggers */
29
+ custom_keywords?: CustomKeyword[];
30
+ }
31
+ interface InjectionGuardResult {
32
+ risk_level: RiskLevel;
33
+ suggested_mode: SuggestedMode;
34
+ triggers: string[];
35
+ trigger_excerpts: Record<string, string[]>;
36
+ mitigations: string[];
37
+ ruleset_version: string;
38
+ llm_review?: LLMReview;
39
+ /** Convenience: true when suggested_mode is 'block' */
40
+ blocked: boolean;
41
+ /** Convenience: true when human review is recommended */
42
+ requiresHuman: boolean;
43
+ }
44
+ interface IssueOptions {
45
+ preset?: 'standard' | 'draft_only' | 'strict' | 'minimal';
46
+ /** Time-to-live in seconds (default: 86400 = 24h) */
47
+ ttl_seconds?: number;
48
+ payload?: {
49
+ /** High-level purpose of the outbound interaction */
50
+ intent?: string;
51
+ /** Human-readable message for the receiver */
52
+ message?: string;
53
+ [key: string]: unknown;
54
+ };
55
+ }
56
+ interface TrustCode {
57
+ code: string;
58
+ expires_at: string;
59
+ verify_url: string;
60
+ badge_html: string;
61
+ }
62
+ interface VerifyResult {
63
+ verified: boolean;
64
+ issuer_org_id: string;
65
+ issuer_agent_id: string;
66
+ preset: string;
67
+ email_verified: boolean;
68
+ risk_level: RiskLevel;
69
+ allowlisted: boolean;
70
+ payload: Record<string, unknown>;
71
+ }
72
+ declare class AgentTrust {
73
+ private apiKey;
74
+ private baseUrl;
75
+ constructor(config: AgentTrustConfig);
76
+ /**
77
+ * Create an AgentTrust client from environment variables.
78
+ * Reads AGENTTRUST_API_KEY automatically.
79
+ *
80
+ * @example
81
+ * const at = AgentTrust.fromEnv()
82
+ */
83
+ static fromEnv(): AgentTrust;
84
+ /**
85
+ * Scan text for prompt injection, command execution, and social engineering.
86
+ *
87
+ * @example
88
+ * const result = await at.injectionGuard(userMessage, {
89
+ * capabilities: ['send_messages', 'open_links'],
90
+ * channel: 'email',
91
+ * use_llm_review: true,
92
+ * })
93
+ * if (result.blocked) throw new Error('Injection detected')
94
+ */
95
+ injectionGuard(text: string, options: InjectionGuardOptions): Promise<InjectionGuardResult>;
96
+ /**
97
+ * Issue a one-time TrustCode that proves your agent's identity.
98
+ *
99
+ * @example
100
+ * const code = await at.issue({
101
+ * preset: 'draft_only',
102
+ * ttl_seconds: 3600,
103
+ * payload: { intent: 'schedule_meeting', message: 'Scheduling on behalf of Acme Corp.' }
104
+ * })
105
+ */
106
+ issue(options?: IssueOptions): Promise<TrustCode>;
107
+ /**
108
+ * Verify a TrustCode. No API key required — anyone can verify.
109
+ *
110
+ * @example
111
+ * const identity = await at.verify('gFs2-jbQE-GddW')
112
+ * if (identity.verified) console.log('Agent:', identity.issuer_agent_id)
113
+ */
114
+ verify(code: string): Promise<VerifyResult>;
115
+ private _post;
116
+ }
117
+
118
+ export { AgentTrust, type AgentTrustConfig, type Channel, type CustomKeyword, type InjectionGuardOptions, type InjectionGuardResult, type IssueOptions, type LLMReview, type RiskLevel, type Severity, type SuggestedMode, type TrustCode, type VerifyResult, AgentTrust as default };
@@ -0,0 +1,118 @@
1
+ interface AgentTrustConfig {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ }
5
+ type RiskLevel = 'low' | 'medium' | 'high';
6
+ type SuggestedMode = 'allow_execute' | 'draft_only' | 'require_human' | 'block';
7
+ type Channel = 'email' | 'chat' | 'api';
8
+ type Severity = 'low' | 'medium' | 'high';
9
+ interface CustomKeyword {
10
+ keyword: string;
11
+ severity: Severity;
12
+ }
13
+ interface LLMReview {
14
+ risk_assessment: string;
15
+ confidence: number;
16
+ recommendation: string;
17
+ excerpts: string[];
18
+ }
19
+ interface InjectionGuardOptions {
20
+ /** Capabilities the downstream agent may execute */
21
+ capabilities: string[];
22
+ /** Source channel context */
23
+ channel?: Channel;
24
+ /** Enable additional LLM-based risk assessment */
25
+ use_llm_review?: boolean;
26
+ /** Terms that suppress matching trigger detection */
27
+ exclusions?: string[];
28
+ /** User-defined keyword triggers */
29
+ custom_keywords?: CustomKeyword[];
30
+ }
31
+ interface InjectionGuardResult {
32
+ risk_level: RiskLevel;
33
+ suggested_mode: SuggestedMode;
34
+ triggers: string[];
35
+ trigger_excerpts: Record<string, string[]>;
36
+ mitigations: string[];
37
+ ruleset_version: string;
38
+ llm_review?: LLMReview;
39
+ /** Convenience: true when suggested_mode is 'block' */
40
+ blocked: boolean;
41
+ /** Convenience: true when human review is recommended */
42
+ requiresHuman: boolean;
43
+ }
44
+ interface IssueOptions {
45
+ preset?: 'standard' | 'draft_only' | 'strict' | 'minimal';
46
+ /** Time-to-live in seconds (default: 86400 = 24h) */
47
+ ttl_seconds?: number;
48
+ payload?: {
49
+ /** High-level purpose of the outbound interaction */
50
+ intent?: string;
51
+ /** Human-readable message for the receiver */
52
+ message?: string;
53
+ [key: string]: unknown;
54
+ };
55
+ }
56
+ interface TrustCode {
57
+ code: string;
58
+ expires_at: string;
59
+ verify_url: string;
60
+ badge_html: string;
61
+ }
62
+ interface VerifyResult {
63
+ verified: boolean;
64
+ issuer_org_id: string;
65
+ issuer_agent_id: string;
66
+ preset: string;
67
+ email_verified: boolean;
68
+ risk_level: RiskLevel;
69
+ allowlisted: boolean;
70
+ payload: Record<string, unknown>;
71
+ }
72
+ declare class AgentTrust {
73
+ private apiKey;
74
+ private baseUrl;
75
+ constructor(config: AgentTrustConfig);
76
+ /**
77
+ * Create an AgentTrust client from environment variables.
78
+ * Reads AGENTTRUST_API_KEY automatically.
79
+ *
80
+ * @example
81
+ * const at = AgentTrust.fromEnv()
82
+ */
83
+ static fromEnv(): AgentTrust;
84
+ /**
85
+ * Scan text for prompt injection, command execution, and social engineering.
86
+ *
87
+ * @example
88
+ * const result = await at.injectionGuard(userMessage, {
89
+ * capabilities: ['send_messages', 'open_links'],
90
+ * channel: 'email',
91
+ * use_llm_review: true,
92
+ * })
93
+ * if (result.blocked) throw new Error('Injection detected')
94
+ */
95
+ injectionGuard(text: string, options: InjectionGuardOptions): Promise<InjectionGuardResult>;
96
+ /**
97
+ * Issue a one-time TrustCode that proves your agent's identity.
98
+ *
99
+ * @example
100
+ * const code = await at.issue({
101
+ * preset: 'draft_only',
102
+ * ttl_seconds: 3600,
103
+ * payload: { intent: 'schedule_meeting', message: 'Scheduling on behalf of Acme Corp.' }
104
+ * })
105
+ */
106
+ issue(options?: IssueOptions): Promise<TrustCode>;
107
+ /**
108
+ * Verify a TrustCode. No API key required — anyone can verify.
109
+ *
110
+ * @example
111
+ * const identity = await at.verify('gFs2-jbQE-GddW')
112
+ * if (identity.verified) console.log('Agent:', identity.issuer_agent_id)
113
+ */
114
+ verify(code: string): Promise<VerifyResult>;
115
+ private _post;
116
+ }
117
+
118
+ export { AgentTrust, type AgentTrustConfig, type Channel, type CustomKeyword, type InjectionGuardOptions, type InjectionGuardResult, type IssueOptions, type LLMReview, type RiskLevel, type Severity, type SuggestedMode, type TrustCode, type VerifyResult, AgentTrust as default };
package/dist/index.js ADDED
@@ -0,0 +1,125 @@
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
+ AgentTrust: () => AgentTrust,
24
+ default: () => index_default
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var BASE_URL = "https://agenttrust.ai/api";
28
+ var AgentTrust = class _AgentTrust {
29
+ constructor(config) {
30
+ if (!config.apiKey) throw new Error("[AgentTrust] apiKey is required");
31
+ this.apiKey = config.apiKey;
32
+ this.baseUrl = config.baseUrl ?? BASE_URL;
33
+ }
34
+ /**
35
+ * Create an AgentTrust client from environment variables.
36
+ * Reads AGENTTRUST_API_KEY automatically.
37
+ *
38
+ * @example
39
+ * const at = AgentTrust.fromEnv()
40
+ */
41
+ static fromEnv() {
42
+ const apiKey = process.env.AGENTTRUST_API_KEY;
43
+ if (!apiKey) throw new Error("[AgentTrust] AGENTTRUST_API_KEY environment variable is not set");
44
+ return new _AgentTrust({ apiKey });
45
+ }
46
+ // ─── InjectionGuard ──────────────────────────────────────────────────────
47
+ /**
48
+ * Scan text for prompt injection, command execution, and social engineering.
49
+ *
50
+ * @example
51
+ * const result = await at.injectionGuard(userMessage, {
52
+ * capabilities: ['send_messages', 'open_links'],
53
+ * channel: 'email',
54
+ * use_llm_review: true,
55
+ * })
56
+ * if (result.blocked) throw new Error('Injection detected')
57
+ */
58
+ async injectionGuard(text, options) {
59
+ const response = await this._post("/injectionGuard", {
60
+ text,
61
+ capabilities: options.capabilities,
62
+ ...options.channel && { channel: options.channel },
63
+ ...options.use_llm_review !== void 0 && { use_llm_review: options.use_llm_review },
64
+ ...options.exclusions && { exclusions: options.exclusions },
65
+ ...options.custom_keywords && { custom_keywords: options.custom_keywords }
66
+ });
67
+ return {
68
+ ...response,
69
+ blocked: response.suggested_mode === "block",
70
+ requiresHuman: response.suggested_mode === "require_human"
71
+ };
72
+ }
73
+ // ─── TrustCode ───────────────────────────────────────────────────────────
74
+ /**
75
+ * Issue a one-time TrustCode that proves your agent's identity.
76
+ *
77
+ * @example
78
+ * const code = await at.issue({
79
+ * preset: 'draft_only',
80
+ * ttl_seconds: 3600,
81
+ * payload: { intent: 'schedule_meeting', message: 'Scheduling on behalf of Acme Corp.' }
82
+ * })
83
+ */
84
+ async issue(options = {}) {
85
+ return this._post("/issue", {
86
+ preset: options.preset ?? "standard",
87
+ ...options.ttl_seconds && { ttl_seconds: options.ttl_seconds },
88
+ ...options.payload && { payload: options.payload }
89
+ });
90
+ }
91
+ /**
92
+ * Verify a TrustCode. No API key required — anyone can verify.
93
+ *
94
+ * @example
95
+ * const identity = await at.verify('gFs2-jbQE-GddW')
96
+ * if (identity.verified) console.log('Agent:', identity.issuer_agent_id)
97
+ */
98
+ async verify(code) {
99
+ return this._post("/verify", { code }, { auth: false });
100
+ }
101
+ // ─── Internal ────────────────────────────────────────────────────────────
102
+ async _post(path, body, opts = { auth: true }) {
103
+ const headers = {
104
+ "Content-Type": "application/json"
105
+ };
106
+ if (opts.auth !== false) {
107
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
108
+ }
109
+ const res = await fetch(`${this.baseUrl}${path}`, {
110
+ method: "POST",
111
+ headers,
112
+ body: JSON.stringify(body)
113
+ });
114
+ if (!res.ok) {
115
+ const error = await res.text();
116
+ throw new Error(`[AgentTrust] API error ${res.status}: ${error}`);
117
+ }
118
+ return res.json();
119
+ }
120
+ };
121
+ var index_default = AgentTrust;
122
+ // Annotate the CommonJS export names for ESM import in node:
123
+ 0 && (module.exports = {
124
+ AgentTrust
125
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,100 @@
1
+ // src/index.ts
2
+ var BASE_URL = "https://agenttrust.ai/api";
3
+ var AgentTrust = class _AgentTrust {
4
+ constructor(config) {
5
+ if (!config.apiKey) throw new Error("[AgentTrust] apiKey is required");
6
+ this.apiKey = config.apiKey;
7
+ this.baseUrl = config.baseUrl ?? BASE_URL;
8
+ }
9
+ /**
10
+ * Create an AgentTrust client from environment variables.
11
+ * Reads AGENTTRUST_API_KEY automatically.
12
+ *
13
+ * @example
14
+ * const at = AgentTrust.fromEnv()
15
+ */
16
+ static fromEnv() {
17
+ const apiKey = process.env.AGENTTRUST_API_KEY;
18
+ if (!apiKey) throw new Error("[AgentTrust] AGENTTRUST_API_KEY environment variable is not set");
19
+ return new _AgentTrust({ apiKey });
20
+ }
21
+ // ─── InjectionGuard ──────────────────────────────────────────────────────
22
+ /**
23
+ * Scan text for prompt injection, command execution, and social engineering.
24
+ *
25
+ * @example
26
+ * const result = await at.injectionGuard(userMessage, {
27
+ * capabilities: ['send_messages', 'open_links'],
28
+ * channel: 'email',
29
+ * use_llm_review: true,
30
+ * })
31
+ * if (result.blocked) throw new Error('Injection detected')
32
+ */
33
+ async injectionGuard(text, options) {
34
+ const response = await this._post("/injectionGuard", {
35
+ text,
36
+ capabilities: options.capabilities,
37
+ ...options.channel && { channel: options.channel },
38
+ ...options.use_llm_review !== void 0 && { use_llm_review: options.use_llm_review },
39
+ ...options.exclusions && { exclusions: options.exclusions },
40
+ ...options.custom_keywords && { custom_keywords: options.custom_keywords }
41
+ });
42
+ return {
43
+ ...response,
44
+ blocked: response.suggested_mode === "block",
45
+ requiresHuman: response.suggested_mode === "require_human"
46
+ };
47
+ }
48
+ // ─── TrustCode ───────────────────────────────────────────────────────────
49
+ /**
50
+ * Issue a one-time TrustCode that proves your agent's identity.
51
+ *
52
+ * @example
53
+ * const code = await at.issue({
54
+ * preset: 'draft_only',
55
+ * ttl_seconds: 3600,
56
+ * payload: { intent: 'schedule_meeting', message: 'Scheduling on behalf of Acme Corp.' }
57
+ * })
58
+ */
59
+ async issue(options = {}) {
60
+ return this._post("/issue", {
61
+ preset: options.preset ?? "standard",
62
+ ...options.ttl_seconds && { ttl_seconds: options.ttl_seconds },
63
+ ...options.payload && { payload: options.payload }
64
+ });
65
+ }
66
+ /**
67
+ * Verify a TrustCode. No API key required — anyone can verify.
68
+ *
69
+ * @example
70
+ * const identity = await at.verify('gFs2-jbQE-GddW')
71
+ * if (identity.verified) console.log('Agent:', identity.issuer_agent_id)
72
+ */
73
+ async verify(code) {
74
+ return this._post("/verify", { code }, { auth: false });
75
+ }
76
+ // ─── Internal ────────────────────────────────────────────────────────────
77
+ async _post(path, body, opts = { auth: true }) {
78
+ const headers = {
79
+ "Content-Type": "application/json"
80
+ };
81
+ if (opts.auth !== false) {
82
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
83
+ }
84
+ const res = await fetch(`${this.baseUrl}${path}`, {
85
+ method: "POST",
86
+ headers,
87
+ body: JSON.stringify(body)
88
+ });
89
+ if (!res.ok) {
90
+ const error = await res.text();
91
+ throw new Error(`[AgentTrust] API error ${res.status}: ${error}`);
92
+ }
93
+ return res.json();
94
+ }
95
+ };
96
+ var index_default = AgentTrust;
97
+ export {
98
+ AgentTrust,
99
+ index_default as default
100
+ };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@agenttrust/sdk",
3
+ "version": "0.2.0",
4
+ "description": "Official SDK for AgentTrust — AI agent security, prompt injection detection, and identity verification",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsup src/index.ts --format cjs,esm --dts",
13
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
14
+ "test": "node --experimental-vm-modules node_modules/.bin/jest"
15
+ },
16
+ "exports": {
17
+ ".": {
18
+ "import": "./dist/index.mjs",
19
+ "require": "./dist/index.js",
20
+ "types": "./dist/index.d.ts"
21
+ }
22
+ },
23
+ "keywords": [
24
+ "agenttrust",
25
+ "prompt-injection",
26
+ "ai-security",
27
+ "agent-security",
28
+ "injection-guard",
29
+ "trustcode"
30
+ ],
31
+ "author": "AgentTrust",
32
+ "license": "MIT",
33
+ "devDependencies": {
34
+ "@types/node": "^25.2.3",
35
+ "tsup": "^8.0.0",
36
+ "typescript": "^5.0.0"
37
+ },
38
+ "engines": {
39
+ "node": ">=18"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://github.com/agenttrust/sdk"
44
+ },
45
+ "homepage": "https://agenttrust.ai"
46
+ }