@vorim/sdk 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vorim AI
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,101 @@
1
+ # @vorim/sdk
2
+
3
+ Official TypeScript SDK for **Vorim AI** — the AI Agent Identity & Trust Layer.
4
+
5
+ Register agents with cryptographic identities, enforce fine-grained permissions, emit immutable audit trails, and verify trust scores.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @vorim/sdk
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import createVorim from '@vorim/sdk';
17
+
18
+ const vorim = createVorim({
19
+ apiKey: 'agid_sk_live_your_api_key_here',
20
+ });
21
+
22
+ // Register an agent with Ed25519 keypair
23
+ const { agent, private_key } = await vorim.register({
24
+ name: 'InvoiceBot',
25
+ capabilities: ['api_access', 'email_send'],
26
+ scopes: ['agent:read', 'agent:write'],
27
+ });
28
+
29
+ // Check permissions (sub-5ms via Redis cache)
30
+ const { allowed } = await vorim.check(agent.agent_id, 'agent:write');
31
+
32
+ // Emit audit event
33
+ await vorim.emit({
34
+ agent_id: agent.agent_id,
35
+ event_type: 'api_request',
36
+ action: 'POST /invoices',
37
+ result: 'success',
38
+ });
39
+
40
+ // Verify trust (public API, no auth needed)
41
+ const trust = await vorim.verify(agent.agent_id);
42
+ console.log(trust.trust_score); // 0-100
43
+ ```
44
+
45
+ ## Features
46
+
47
+ - **Cryptographic Identity** — Ed25519 keypairs, SHA-256 fingerprints
48
+ - **7 Permission Scopes** — `agent:read`, `write`, `execute`, `transact`, `communicate`, `delegate`, `elevate`
49
+ - **Immutable Audit Trail** — ULID-ordered events with content hashes
50
+ - **Trust Scoring** — Multi-factor algorithm (0-100)
51
+ - **Payload Signing** — Client-side Ed25519 signatures via Web Crypto or Node.js crypto
52
+ - **Dual Runtime** — Works in Node.js 18+ and modern browsers
53
+
54
+ ## API
55
+
56
+ | Method | Description |
57
+ |---|---|
58
+ | `vorim.register(input)` | Register agent with keypair |
59
+ | `vorim.getAgent(agentId)` | Get agent details |
60
+ | `vorim.listAgents(params?)` | List organisation agents |
61
+ | `vorim.revoke(agentId)` | Permanently revoke agent |
62
+ | `vorim.check(agentId, scope)` | Check permission |
63
+ | `vorim.grant(agentId, scope, options?)` | Grant permission |
64
+ | `vorim.emit(event)` | Emit single audit event |
65
+ | `vorim.emitBatch(events)` | Emit up to 1,000 events |
66
+ | `vorim.verify(agentId)` | Public trust verification |
67
+ | `vorim.sign(payload, privateKey)` | Ed25519 payload signing |
68
+
69
+ ## Configuration
70
+
71
+ ```typescript
72
+ const vorim = createVorim({
73
+ apiKey: 'agid_sk_live_...', // Required — your API key
74
+ baseUrl: 'https://api.vorim.ai', // Optional — API base URL
75
+ timeout: 10000, // Optional — request timeout (ms)
76
+ });
77
+ ```
78
+
79
+ ## Error Handling
80
+
81
+ ```typescript
82
+ import { VorimError } from '@vorim/sdk';
83
+
84
+ try {
85
+ await vorim.check('invalid_id', 'agent:read');
86
+ } catch (err) {
87
+ if (err instanceof VorimError) {
88
+ console.log(err.status); // 404
89
+ console.log(err.code); // 'AGENT_NOT_FOUND'
90
+ console.log(err.message); // 'Agent not found'
91
+ }
92
+ }
93
+ ```
94
+
95
+ ## Documentation
96
+
97
+ Full documentation at [vorim.dev/docs](https://vorim.dev/docs)
98
+
99
+ ## License
100
+
101
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ VorimError: () => VorimError,
34
+ VorimSDK: () => VorimSDK,
35
+ default: () => createVorim
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+ var VorimSDK = class {
39
+ apiKey;
40
+ baseUrl;
41
+ timeout;
42
+ constructor(config) {
43
+ this.apiKey = config.apiKey;
44
+ this.baseUrl = (config.baseUrl || "https://api.vorim.ai").replace(/\/$/, "") + "/v1";
45
+ this.timeout = config.timeout || 1e4;
46
+ }
47
+ // ─── Agent Identity ────────────────────────────────────────────────
48
+ /**
49
+ * Register a new agent with Vorim AI.
50
+ * Returns the agent identity and a private key (shown once).
51
+ */
52
+ async register(input) {
53
+ return this.post("/agents", input);
54
+ }
55
+ /**
56
+ * Verify an agent's identity via the public Trust API.
57
+ */
58
+ async verify(agentId) {
59
+ return this.get(`/trust/verify/${agentId}`);
60
+ }
61
+ /**
62
+ * Get agent details.
63
+ */
64
+ async getAgent(agentId) {
65
+ return this.get(`/agents/${agentId}`);
66
+ }
67
+ /**
68
+ * List all agents in the organisation.
69
+ */
70
+ async listAgents(params) {
71
+ const qs = new URLSearchParams(params).toString();
72
+ return this.get(`/agents${qs ? "?" + qs : ""}`);
73
+ }
74
+ /**
75
+ * Revoke an agent (permanent deactivation).
76
+ */
77
+ async revoke(agentId) {
78
+ await this.delete(`/agents/${agentId}`);
79
+ }
80
+ // ─── Permissions ──────────────────────────────────────────────────
81
+ /**
82
+ * Check if an agent has a specific permission scope.
83
+ * Target: < 5ms response via Redis cache.
84
+ */
85
+ async check(agentId, scope) {
86
+ return this.post(`/agents/${agentId}/permissions/verify`, { scope });
87
+ }
88
+ /**
89
+ * Grant a permission scope to an agent.
90
+ */
91
+ async grant(agentId, scope, options) {
92
+ return this.post(`/agents/${agentId}/permissions`, { scope, ...options });
93
+ }
94
+ // ─── Audit ────────────────────────────────────────────────────────
95
+ /**
96
+ * Emit an audit event for an agent action.
97
+ */
98
+ async emit(event) {
99
+ return this.post("/audit/events", { events: [event] });
100
+ }
101
+ /**
102
+ * Emit a batch of audit events (up to 1,000).
103
+ */
104
+ async emitBatch(events) {
105
+ return this.post("/audit/events", { events });
106
+ }
107
+ // ─── Signing ──────────────────────────────────────────────────────
108
+ /**
109
+ * Sign a payload with an Ed25519 private key (client-side).
110
+ * Uses the Web Crypto API or Node.js crypto.
111
+ */
112
+ async sign(payload, privateKeyPem) {
113
+ if (typeof globalThis.crypto?.subtle !== "undefined") {
114
+ const keyData = this.pemToArrayBuffer(privateKeyPem);
115
+ const key = await globalThis.crypto.subtle.importKey(
116
+ "pkcs8",
117
+ keyData,
118
+ { name: "Ed25519" },
119
+ false,
120
+ ["sign"]
121
+ );
122
+ const signature = await globalThis.crypto.subtle.sign(
123
+ "Ed25519",
124
+ key,
125
+ new TextEncoder().encode(payload)
126
+ );
127
+ return `ed25519:${this.arrayBufferToBase64(signature)}`;
128
+ } else {
129
+ const crypto = await import("crypto");
130
+ const sign = crypto.sign(null, Buffer.from(payload), privateKeyPem);
131
+ return `ed25519:${sign.toString("base64")}`;
132
+ }
133
+ }
134
+ // ─── HTTP Client ──────────────────────────────────────────────────
135
+ async get(path) {
136
+ return this.request("GET", path);
137
+ }
138
+ async post(path, body) {
139
+ return this.request("POST", path, body);
140
+ }
141
+ async delete(path) {
142
+ return this.request("DELETE", path);
143
+ }
144
+ async request(method, path, body) {
145
+ const controller = new AbortController();
146
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
147
+ try {
148
+ const response = await fetch(`${this.baseUrl}${path}`, {
149
+ method,
150
+ headers: {
151
+ "Authorization": `Bearer ${this.apiKey}`,
152
+ "Content-Type": "application/json",
153
+ "User-Agent": "vorim-sdk/1.0.0"
154
+ },
155
+ body: body ? JSON.stringify(body) : void 0,
156
+ signal: controller.signal
157
+ });
158
+ if (!response.ok) {
159
+ const errBody = await response.json().catch(() => ({}));
160
+ throw new VorimError(
161
+ response.status,
162
+ errBody.error?.code || "UNKNOWN_ERROR",
163
+ errBody.error?.message || `HTTP ${response.status}`,
164
+ errBody.error?.details
165
+ );
166
+ }
167
+ const json = await response.json();
168
+ return json.data;
169
+ } finally {
170
+ clearTimeout(timeoutId);
171
+ }
172
+ }
173
+ pemToArrayBuffer(pem) {
174
+ const b64 = pem.replace(/-----[^-]+-----/g, "").replace(/\s/g, "");
175
+ const binary = atob(b64);
176
+ const bytes = new Uint8Array(binary.length);
177
+ for (let i = 0; i < binary.length; i++) {
178
+ bytes[i] = binary.charCodeAt(i);
179
+ }
180
+ return bytes.buffer;
181
+ }
182
+ arrayBufferToBase64(buffer) {
183
+ const bytes = new Uint8Array(buffer);
184
+ let binary = "";
185
+ for (const byte of bytes) {
186
+ binary += String.fromCharCode(byte);
187
+ }
188
+ return btoa(binary);
189
+ }
190
+ };
191
+ var VorimError = class extends Error {
192
+ constructor(status, code, message, details) {
193
+ super(message);
194
+ this.status = status;
195
+ this.code = code;
196
+ this.details = details;
197
+ this.name = "VorimError";
198
+ }
199
+ };
200
+ function createVorim(config) {
201
+ return new VorimSDK(config);
202
+ }
203
+ // Annotate the CommonJS export names for ESM import in node:
204
+ 0 && (module.exports = {
205
+ VorimError,
206
+ VorimSDK
207
+ });
208
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// ============================================================================\n// VORIM SDK — TypeScript\n// Thin client wrapping the Vorim AI REST API\n// ============================================================================\n\nimport type {\n Agent, AgentRegistrationInput, AgentRegistrationResult,\n TrustRecord, AuditEventInput, PermissionScope, PermissionCheckResult,\n} from './types.js';\n\nexport interface VorimConfig {\n apiKey: string;\n baseUrl?: string;\n timeout?: number;\n}\n\nexport class VorimSDK {\n private apiKey: string;\n private baseUrl: string;\n private timeout: number;\n\n constructor(config: VorimConfig) {\n this.apiKey = config.apiKey;\n this.baseUrl = (config.baseUrl || 'https://api.vorim.ai').replace(/\\/$/, '') + '/v1';\n this.timeout = config.timeout || 10000;\n }\n\n // ─── Agent Identity ────────────────────────────────────────────────\n\n /**\n * Register a new agent with Vorim AI.\n * Returns the agent identity and a private key (shown once).\n */\n async register(input: AgentRegistrationInput): Promise<AgentRegistrationResult> {\n return this.post('/agents', input);\n }\n\n /**\n * Verify an agent's identity via the public Trust API.\n */\n async verify(agentId: string): Promise<TrustRecord> {\n return this.get(`/trust/verify/${agentId}`);\n }\n\n /**\n * Get agent details.\n */\n async getAgent(agentId: string): Promise<Agent> {\n return this.get(`/agents/${agentId}`);\n }\n\n /**\n * List all agents in the organisation.\n */\n async listAgents(params?: { page?: number; per_page?: number; status?: string }): Promise<{ agents: Agent[]; meta: any }> {\n const qs = new URLSearchParams(params as any).toString();\n return this.get(`/agents${qs ? '?' + qs : ''}`);\n }\n\n /**\n * Revoke an agent (permanent deactivation).\n */\n async revoke(agentId: string): Promise<void> {\n await this.delete(`/agents/${agentId}`);\n }\n\n // ─── Permissions ──────────────────────────────────────────────────\n\n /**\n * Check if an agent has a specific permission scope.\n * Target: < 5ms response via Redis cache.\n */\n async check(agentId: string, scope: PermissionScope): Promise<PermissionCheckResult> {\n return this.post(`/agents/${agentId}/permissions/verify`, { scope });\n }\n\n /**\n * Grant a permission scope to an agent.\n */\n async grant(agentId: string, scope: PermissionScope, options?: {\n valid_until?: string;\n rate_limit?: { max: number; window: string };\n }): Promise<any> {\n return this.post(`/agents/${agentId}/permissions`, { scope, ...options });\n }\n\n // ─── Audit ────────────────────────────────────────────────────────\n\n /**\n * Emit an audit event for an agent action.\n */\n async emit(event: AuditEventInput): Promise<{ ingested: number }> {\n return this.post('/audit/events', { events: [event] });\n }\n\n /**\n * Emit a batch of audit events (up to 1,000).\n */\n async emitBatch(events: AuditEventInput[]): Promise<{ ingested: number }> {\n return this.post('/audit/events', { events });\n }\n\n // ─── Signing ──────────────────────────────────────────────────────\n\n /**\n * Sign a payload with an Ed25519 private key (client-side).\n * Uses the Web Crypto API or Node.js crypto.\n */\n async sign(payload: string, privateKeyPem: string): Promise<string> {\n if (typeof globalThis.crypto?.subtle !== 'undefined') {\n // Web Crypto API\n const keyData = this.pemToArrayBuffer(privateKeyPem);\n const key = await globalThis.crypto.subtle.importKey(\n 'pkcs8', keyData, { name: 'Ed25519' }, false, ['sign']\n );\n const signature = await globalThis.crypto.subtle.sign(\n 'Ed25519', key, new TextEncoder().encode(payload)\n );\n return `ed25519:${this.arrayBufferToBase64(signature)}`;\n } else {\n // Node.js crypto fallback\n const crypto = await import('node:crypto');\n const sign = crypto.sign(null, Buffer.from(payload), privateKeyPem);\n return `ed25519:${sign.toString('base64')}`;\n }\n }\n\n // ─── HTTP Client ──────────────────────────────────────────────────\n\n private async get(path: string): Promise<any> {\n return this.request('GET', path);\n }\n\n private async post(path: string, body: any): Promise<any> {\n return this.request('POST', path, body);\n }\n\n private async delete(path: string): Promise<any> {\n return this.request('DELETE', path);\n }\n\n private async request(method: string, path: string, body?: any): Promise<any> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n\n try {\n const response = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers: {\n 'Authorization': `Bearer ${this.apiKey}`,\n 'Content-Type': 'application/json',\n 'User-Agent': 'vorim-sdk/1.0.0',\n },\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n\n if (!response.ok) {\n const errBody = await response.json().catch(() => ({})) as Record<string, any>;\n throw new VorimError(\n response.status,\n errBody.error?.code || 'UNKNOWN_ERROR',\n errBody.error?.message || `HTTP ${response.status}`,\n errBody.error?.details\n );\n }\n\n const json = await response.json() as Record<string, any>;\n return json.data;\n } finally {\n clearTimeout(timeoutId);\n }\n }\n\n private pemToArrayBuffer(pem: string): ArrayBuffer {\n const b64 = pem.replace(/-----[^-]+-----/g, '').replace(/\\s/g, '');\n const binary = atob(b64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return bytes.buffer;\n }\n\n private arrayBufferToBase64(buffer: ArrayBuffer): string {\n const bytes = new Uint8Array(buffer);\n let binary = '';\n for (const byte of bytes) {\n binary += String.fromCharCode(byte);\n }\n return btoa(binary);\n }\n}\n\nexport class VorimError extends Error {\n constructor(\n public status: number,\n public code: string,\n message: string,\n public details?: Record<string, unknown>\n ) {\n super(message);\n this.name = 'VorimError';\n }\n}\n\n// ─── Convenience export ──────────────────────────────────────────────\n\nexport default function createVorim(config: VorimConfig): VorimSDK {\n return new VorimSDK(config);\n}\n\n// Re-export types for consumers\nexport type {\n Agent, AgentRegistrationInput, AgentRegistrationResult,\n TrustRecord, AuditEventInput, AuditEventType, AuditResult,\n PermissionScope, PermissionCheckResult, AgentStatus,\n} from './types.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBO,IAAM,WAAN,MAAe;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,QAAqB;AAC/B,SAAK,SAAS,OAAO;AACrB,SAAK,WAAW,OAAO,WAAW,wBAAwB,QAAQ,OAAO,EAAE,IAAI;AAC/E,SAAK,UAAU,OAAO,WAAW;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,SAAS,OAAiE;AAC9E,WAAO,KAAK,KAAK,WAAW,KAAK;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO,SAAuC;AAClD,WAAO,KAAK,IAAI,iBAAiB,OAAO,EAAE;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,SAAS,SAAiC;AAC9C,WAAO,KAAK,IAAI,WAAW,OAAO,EAAE;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAW,QAAyG;AACxH,UAAM,KAAK,IAAI,gBAAgB,MAAa,EAAE,SAAS;AACvD,WAAO,KAAK,IAAI,UAAU,KAAK,MAAM,KAAK,EAAE,EAAE;AAAA,EAChD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UAAM,SAAS,KAAK,GAAG;AACvB,UAAM,QAAQ,IAAI,WAAW,OAAO,MAAM;AAC1C,aAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,YAAM,CAAC,IAAI,OAAO,WAAW,CAAC;AAAA,IAChC;AACA,WAAO,MAAM;AAAA,EACf;AAAA,EAEQ,oBAAoB,QAA6B;AACvD,UAAM,QAAQ,IAAI,WAAW,MAAM;AACnC,QAAI,SAAS;AACb,eAAW,QAAQ,OAAO;AACxB,gBAAU,OAAO,aAAa,IAAI;AAAA,IACpC;AACA,WAAO,KAAK,MAAM;AAAA,EACpB;AACF;AAEO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YACS,QACA,MACP,SACO,SACP;AACA,UAAM,OAAO;AALN;AACA;AAEA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAIe,SAAR,YAA6B,QAA+B;AACjE,SAAO,IAAI,SAAS,MAAM;AAC5B;","names":[]}
@@ -0,0 +1,157 @@
1
+ type AgentStatus = 'pending' | 'active' | 'suspended' | 'revoked' | 'expired';
2
+ interface Agent {
3
+ id: string;
4
+ agent_id: string;
5
+ org_id: string;
6
+ owner_user_id: string;
7
+ name: string;
8
+ description?: string;
9
+ status: AgentStatus;
10
+ public_key: string;
11
+ key_fingerprint: string;
12
+ trust_score: number;
13
+ capabilities: string[];
14
+ metadata: Record<string, unknown>;
15
+ expires_at?: string;
16
+ created_at: string;
17
+ updated_at: string;
18
+ revoked_at?: string;
19
+ revoked_by?: string;
20
+ }
21
+ interface AgentRegistrationInput {
22
+ name: string;
23
+ description?: string;
24
+ capabilities: string[];
25
+ scopes: PermissionScope[];
26
+ }
27
+ interface AgentRegistrationResult {
28
+ agent: Agent;
29
+ private_key: string;
30
+ public_key: string;
31
+ key_fingerprint: string;
32
+ }
33
+ type PermissionScope = 'agent:read' | 'agent:write' | 'agent:execute' | 'agent:transact' | 'agent:communicate' | 'agent:delegate' | 'agent:elevate';
34
+ interface PermissionCheckResult {
35
+ allowed: boolean;
36
+ scope: PermissionScope;
37
+ agent_id: string;
38
+ reason?: string;
39
+ remaining_quota?: number;
40
+ }
41
+ type AuditEventType = 'tool_call' | 'api_request' | 'message_sent' | 'permission_change' | 'status_change' | 'key_rotation' | 'login' | 'export';
42
+ type AuditResult = 'success' | 'denied' | 'error';
43
+ interface AuditEventInput {
44
+ agent_id: string;
45
+ event_type: AuditEventType;
46
+ action: string;
47
+ resource?: string;
48
+ input_hash?: string;
49
+ output_hash?: string;
50
+ permission?: PermissionScope;
51
+ result: AuditResult;
52
+ latency_ms?: number;
53
+ error_code?: string;
54
+ signature?: string;
55
+ metadata?: Record<string, unknown>;
56
+ }
57
+ interface TrustRecord {
58
+ agent_id: string;
59
+ owner: {
60
+ org_name: string;
61
+ verified: boolean;
62
+ };
63
+ trust_score: number;
64
+ status: AgentStatus;
65
+ created_at: string;
66
+ active_scopes: PermissionScope[];
67
+ key_fingerprint: string;
68
+ revocation_status: boolean;
69
+ last_active?: string;
70
+ }
71
+
72
+ interface VorimConfig {
73
+ apiKey: string;
74
+ baseUrl?: string;
75
+ timeout?: number;
76
+ }
77
+ declare class VorimSDK {
78
+ private apiKey;
79
+ private baseUrl;
80
+ private timeout;
81
+ constructor(config: VorimConfig);
82
+ /**
83
+ * Register a new agent with Vorim AI.
84
+ * Returns the agent identity and a private key (shown once).
85
+ */
86
+ register(input: AgentRegistrationInput): Promise<AgentRegistrationResult>;
87
+ /**
88
+ * Verify an agent's identity via the public Trust API.
89
+ */
90
+ verify(agentId: string): Promise<TrustRecord>;
91
+ /**
92
+ * Get agent details.
93
+ */
94
+ getAgent(agentId: string): Promise<Agent>;
95
+ /**
96
+ * List all agents in the organisation.
97
+ */
98
+ listAgents(params?: {
99
+ page?: number;
100
+ per_page?: number;
101
+ status?: string;
102
+ }): Promise<{
103
+ agents: Agent[];
104
+ meta: any;
105
+ }>;
106
+ /**
107
+ * Revoke an agent (permanent deactivation).
108
+ */
109
+ revoke(agentId: string): Promise<void>;
110
+ /**
111
+ * Check if an agent has a specific permission scope.
112
+ * Target: < 5ms response via Redis cache.
113
+ */
114
+ check(agentId: string, scope: PermissionScope): Promise<PermissionCheckResult>;
115
+ /**
116
+ * Grant a permission scope to an agent.
117
+ */
118
+ grant(agentId: string, scope: PermissionScope, options?: {
119
+ valid_until?: string;
120
+ rate_limit?: {
121
+ max: number;
122
+ window: string;
123
+ };
124
+ }): Promise<any>;
125
+ /**
126
+ * Emit an audit event for an agent action.
127
+ */
128
+ emit(event: AuditEventInput): Promise<{
129
+ ingested: number;
130
+ }>;
131
+ /**
132
+ * Emit a batch of audit events (up to 1,000).
133
+ */
134
+ emitBatch(events: AuditEventInput[]): Promise<{
135
+ ingested: number;
136
+ }>;
137
+ /**
138
+ * Sign a payload with an Ed25519 private key (client-side).
139
+ * Uses the Web Crypto API or Node.js crypto.
140
+ */
141
+ sign(payload: string, privateKeyPem: string): Promise<string>;
142
+ private get;
143
+ private post;
144
+ private delete;
145
+ private request;
146
+ private pemToArrayBuffer;
147
+ private arrayBufferToBase64;
148
+ }
149
+ declare class VorimError extends Error {
150
+ status: number;
151
+ code: string;
152
+ details?: Record<string, unknown> | undefined;
153
+ constructor(status: number, code: string, message: string, details?: Record<string, unknown> | undefined);
154
+ }
155
+ declare function createVorim(config: VorimConfig): VorimSDK;
156
+
157
+ export { type Agent, type AgentRegistrationInput, type AgentRegistrationResult, type AgentStatus, type AuditEventInput, type AuditEventType, type AuditResult, type PermissionCheckResult, type PermissionScope, type TrustRecord, type VorimConfig, VorimError, VorimSDK, createVorim as default };
@@ -0,0 +1,157 @@
1
+ type AgentStatus = 'pending' | 'active' | 'suspended' | 'revoked' | 'expired';
2
+ interface Agent {
3
+ id: string;
4
+ agent_id: string;
5
+ org_id: string;
6
+ owner_user_id: string;
7
+ name: string;
8
+ description?: string;
9
+ status: AgentStatus;
10
+ public_key: string;
11
+ key_fingerprint: string;
12
+ trust_score: number;
13
+ capabilities: string[];
14
+ metadata: Record<string, unknown>;
15
+ expires_at?: string;
16
+ created_at: string;
17
+ updated_at: string;
18
+ revoked_at?: string;
19
+ revoked_by?: string;
20
+ }
21
+ interface AgentRegistrationInput {
22
+ name: string;
23
+ description?: string;
24
+ capabilities: string[];
25
+ scopes: PermissionScope[];
26
+ }
27
+ interface AgentRegistrationResult {
28
+ agent: Agent;
29
+ private_key: string;
30
+ public_key: string;
31
+ key_fingerprint: string;
32
+ }
33
+ type PermissionScope = 'agent:read' | 'agent:write' | 'agent:execute' | 'agent:transact' | 'agent:communicate' | 'agent:delegate' | 'agent:elevate';
34
+ interface PermissionCheckResult {
35
+ allowed: boolean;
36
+ scope: PermissionScope;
37
+ agent_id: string;
38
+ reason?: string;
39
+ remaining_quota?: number;
40
+ }
41
+ type AuditEventType = 'tool_call' | 'api_request' | 'message_sent' | 'permission_change' | 'status_change' | 'key_rotation' | 'login' | 'export';
42
+ type AuditResult = 'success' | 'denied' | 'error';
43
+ interface AuditEventInput {
44
+ agent_id: string;
45
+ event_type: AuditEventType;
46
+ action: string;
47
+ resource?: string;
48
+ input_hash?: string;
49
+ output_hash?: string;
50
+ permission?: PermissionScope;
51
+ result: AuditResult;
52
+ latency_ms?: number;
53
+ error_code?: string;
54
+ signature?: string;
55
+ metadata?: Record<string, unknown>;
56
+ }
57
+ interface TrustRecord {
58
+ agent_id: string;
59
+ owner: {
60
+ org_name: string;
61
+ verified: boolean;
62
+ };
63
+ trust_score: number;
64
+ status: AgentStatus;
65
+ created_at: string;
66
+ active_scopes: PermissionScope[];
67
+ key_fingerprint: string;
68
+ revocation_status: boolean;
69
+ last_active?: string;
70
+ }
71
+
72
+ interface VorimConfig {
73
+ apiKey: string;
74
+ baseUrl?: string;
75
+ timeout?: number;
76
+ }
77
+ declare class VorimSDK {
78
+ private apiKey;
79
+ private baseUrl;
80
+ private timeout;
81
+ constructor(config: VorimConfig);
82
+ /**
83
+ * Register a new agent with Vorim AI.
84
+ * Returns the agent identity and a private key (shown once).
85
+ */
86
+ register(input: AgentRegistrationInput): Promise<AgentRegistrationResult>;
87
+ /**
88
+ * Verify an agent's identity via the public Trust API.
89
+ */
90
+ verify(agentId: string): Promise<TrustRecord>;
91
+ /**
92
+ * Get agent details.
93
+ */
94
+ getAgent(agentId: string): Promise<Agent>;
95
+ /**
96
+ * List all agents in the organisation.
97
+ */
98
+ listAgents(params?: {
99
+ page?: number;
100
+ per_page?: number;
101
+ status?: string;
102
+ }): Promise<{
103
+ agents: Agent[];
104
+ meta: any;
105
+ }>;
106
+ /**
107
+ * Revoke an agent (permanent deactivation).
108
+ */
109
+ revoke(agentId: string): Promise<void>;
110
+ /**
111
+ * Check if an agent has a specific permission scope.
112
+ * Target: < 5ms response via Redis cache.
113
+ */
114
+ check(agentId: string, scope: PermissionScope): Promise<PermissionCheckResult>;
115
+ /**
116
+ * Grant a permission scope to an agent.
117
+ */
118
+ grant(agentId: string, scope: PermissionScope, options?: {
119
+ valid_until?: string;
120
+ rate_limit?: {
121
+ max: number;
122
+ window: string;
123
+ };
124
+ }): Promise<any>;
125
+ /**
126
+ * Emit an audit event for an agent action.
127
+ */
128
+ emit(event: AuditEventInput): Promise<{
129
+ ingested: number;
130
+ }>;
131
+ /**
132
+ * Emit a batch of audit events (up to 1,000).
133
+ */
134
+ emitBatch(events: AuditEventInput[]): Promise<{
135
+ ingested: number;
136
+ }>;
137
+ /**
138
+ * Sign a payload with an Ed25519 private key (client-side).
139
+ * Uses the Web Crypto API or Node.js crypto.
140
+ */
141
+ sign(payload: string, privateKeyPem: string): Promise<string>;
142
+ private get;
143
+ private post;
144
+ private delete;
145
+ private request;
146
+ private pemToArrayBuffer;
147
+ private arrayBufferToBase64;
148
+ }
149
+ declare class VorimError extends Error {
150
+ status: number;
151
+ code: string;
152
+ details?: Record<string, unknown> | undefined;
153
+ constructor(status: number, code: string, message: string, details?: Record<string, unknown> | undefined);
154
+ }
155
+ declare function createVorim(config: VorimConfig): VorimSDK;
156
+
157
+ export { type Agent, type AgentRegistrationInput, type AgentRegistrationResult, type AgentStatus, type AuditEventInput, type AuditEventType, type AuditResult, type PermissionCheckResult, type PermissionScope, type TrustRecord, type VorimConfig, VorimError, VorimSDK, createVorim as default };
package/dist/index.js ADDED
@@ -0,0 +1,172 @@
1
+ // src/index.ts
2
+ var VorimSDK = class {
3
+ apiKey;
4
+ baseUrl;
5
+ timeout;
6
+ constructor(config) {
7
+ this.apiKey = config.apiKey;
8
+ this.baseUrl = (config.baseUrl || "https://api.vorim.ai").replace(/\/$/, "") + "/v1";
9
+ this.timeout = config.timeout || 1e4;
10
+ }
11
+ // ─── Agent Identity ────────────────────────────────────────────────
12
+ /**
13
+ * Register a new agent with Vorim AI.
14
+ * Returns the agent identity and a private key (shown once).
15
+ */
16
+ async register(input) {
17
+ return this.post("/agents", input);
18
+ }
19
+ /**
20
+ * Verify an agent's identity via the public Trust API.
21
+ */
22
+ async verify(agentId) {
23
+ return this.get(`/trust/verify/${agentId}`);
24
+ }
25
+ /**
26
+ * Get agent details.
27
+ */
28
+ async getAgent(agentId) {
29
+ return this.get(`/agents/${agentId}`);
30
+ }
31
+ /**
32
+ * List all agents in the organisation.
33
+ */
34
+ async listAgents(params) {
35
+ const qs = new URLSearchParams(params).toString();
36
+ return this.get(`/agents${qs ? "?" + qs : ""}`);
37
+ }
38
+ /**
39
+ * Revoke an agent (permanent deactivation).
40
+ */
41
+ async revoke(agentId) {
42
+ await this.delete(`/agents/${agentId}`);
43
+ }
44
+ // ─── Permissions ──────────────────────────────────────────────────
45
+ /**
46
+ * Check if an agent has a specific permission scope.
47
+ * Target: < 5ms response via Redis cache.
48
+ */
49
+ async check(agentId, scope) {
50
+ return this.post(`/agents/${agentId}/permissions/verify`, { scope });
51
+ }
52
+ /**
53
+ * Grant a permission scope to an agent.
54
+ */
55
+ async grant(agentId, scope, options) {
56
+ return this.post(`/agents/${agentId}/permissions`, { scope, ...options });
57
+ }
58
+ // ─── Audit ────────────────────────────────────────────────────────
59
+ /**
60
+ * Emit an audit event for an agent action.
61
+ */
62
+ async emit(event) {
63
+ return this.post("/audit/events", { events: [event] });
64
+ }
65
+ /**
66
+ * Emit a batch of audit events (up to 1,000).
67
+ */
68
+ async emitBatch(events) {
69
+ return this.post("/audit/events", { events });
70
+ }
71
+ // ─── Signing ──────────────────────────────────────────────────────
72
+ /**
73
+ * Sign a payload with an Ed25519 private key (client-side).
74
+ * Uses the Web Crypto API or Node.js crypto.
75
+ */
76
+ async sign(payload, privateKeyPem) {
77
+ if (typeof globalThis.crypto?.subtle !== "undefined") {
78
+ const keyData = this.pemToArrayBuffer(privateKeyPem);
79
+ const key = await globalThis.crypto.subtle.importKey(
80
+ "pkcs8",
81
+ keyData,
82
+ { name: "Ed25519" },
83
+ false,
84
+ ["sign"]
85
+ );
86
+ const signature = await globalThis.crypto.subtle.sign(
87
+ "Ed25519",
88
+ key,
89
+ new TextEncoder().encode(payload)
90
+ );
91
+ return `ed25519:${this.arrayBufferToBase64(signature)}`;
92
+ } else {
93
+ const crypto = await import("crypto");
94
+ const sign = crypto.sign(null, Buffer.from(payload), privateKeyPem);
95
+ return `ed25519:${sign.toString("base64")}`;
96
+ }
97
+ }
98
+ // ─── HTTP Client ──────────────────────────────────────────────────
99
+ async get(path) {
100
+ return this.request("GET", path);
101
+ }
102
+ async post(path, body) {
103
+ return this.request("POST", path, body);
104
+ }
105
+ async delete(path) {
106
+ return this.request("DELETE", path);
107
+ }
108
+ async request(method, path, body) {
109
+ const controller = new AbortController();
110
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
111
+ try {
112
+ const response = await fetch(`${this.baseUrl}${path}`, {
113
+ method,
114
+ headers: {
115
+ "Authorization": `Bearer ${this.apiKey}`,
116
+ "Content-Type": "application/json",
117
+ "User-Agent": "vorim-sdk/1.0.0"
118
+ },
119
+ body: body ? JSON.stringify(body) : void 0,
120
+ signal: controller.signal
121
+ });
122
+ if (!response.ok) {
123
+ const errBody = await response.json().catch(() => ({}));
124
+ throw new VorimError(
125
+ response.status,
126
+ errBody.error?.code || "UNKNOWN_ERROR",
127
+ errBody.error?.message || `HTTP ${response.status}`,
128
+ errBody.error?.details
129
+ );
130
+ }
131
+ const json = await response.json();
132
+ return json.data;
133
+ } finally {
134
+ clearTimeout(timeoutId);
135
+ }
136
+ }
137
+ pemToArrayBuffer(pem) {
138
+ const b64 = pem.replace(/-----[^-]+-----/g, "").replace(/\s/g, "");
139
+ const binary = atob(b64);
140
+ const bytes = new Uint8Array(binary.length);
141
+ for (let i = 0; i < binary.length; i++) {
142
+ bytes[i] = binary.charCodeAt(i);
143
+ }
144
+ return bytes.buffer;
145
+ }
146
+ arrayBufferToBase64(buffer) {
147
+ const bytes = new Uint8Array(buffer);
148
+ let binary = "";
149
+ for (const byte of bytes) {
150
+ binary += String.fromCharCode(byte);
151
+ }
152
+ return btoa(binary);
153
+ }
154
+ };
155
+ var VorimError = class extends Error {
156
+ constructor(status, code, message, details) {
157
+ super(message);
158
+ this.status = status;
159
+ this.code = code;
160
+ this.details = details;
161
+ this.name = "VorimError";
162
+ }
163
+ };
164
+ function createVorim(config) {
165
+ return new VorimSDK(config);
166
+ }
167
+ export {
168
+ VorimError,
169
+ VorimSDK,
170
+ createVorim as default
171
+ };
172
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// ============================================================================\n// VORIM SDK — TypeScript\n// Thin client wrapping the Vorim AI REST API\n// ============================================================================\n\nimport type {\n Agent, AgentRegistrationInput, AgentRegistrationResult,\n TrustRecord, AuditEventInput, PermissionScope, PermissionCheckResult,\n} from './types.js';\n\nexport interface VorimConfig {\n apiKey: string;\n baseUrl?: string;\n timeout?: number;\n}\n\nexport class VorimSDK {\n private apiKey: string;\n private baseUrl: string;\n private timeout: number;\n\n constructor(config: VorimConfig) {\n this.apiKey = config.apiKey;\n this.baseUrl = (config.baseUrl || 'https://api.vorim.ai').replace(/\\/$/, '') + '/v1';\n this.timeout = config.timeout || 10000;\n }\n\n // ─── Agent Identity ────────────────────────────────────────────────\n\n /**\n * Register a new agent with Vorim AI.\n * Returns the agent identity and a private key (shown once).\n */\n async register(input: AgentRegistrationInput): Promise<AgentRegistrationResult> {\n return this.post('/agents', input);\n }\n\n /**\n * Verify an agent's identity via the public Trust API.\n */\n async verify(agentId: string): Promise<TrustRecord> {\n return this.get(`/trust/verify/${agentId}`);\n }\n\n /**\n * Get agent details.\n */\n async getAgent(agentId: string): Promise<Agent> {\n return this.get(`/agents/${agentId}`);\n }\n\n /**\n * List all agents in the organisation.\n */\n async listAgents(params?: { page?: number; per_page?: number; status?: string }): Promise<{ agents: Agent[]; meta: any }> {\n const qs = new URLSearchParams(params as any).toString();\n return this.get(`/agents${qs ? '?' + qs : ''}`);\n }\n\n /**\n * Revoke an agent (permanent deactivation).\n */\n async revoke(agentId: string): Promise<void> {\n await this.delete(`/agents/${agentId}`);\n }\n\n // ─── Permissions ──────────────────────────────────────────────────\n\n /**\n * Check if an agent has a specific permission scope.\n * Target: < 5ms response via Redis cache.\n */\n async check(agentId: string, scope: PermissionScope): Promise<PermissionCheckResult> {\n return this.post(`/agents/${agentId}/permissions/verify`, { scope });\n }\n\n /**\n * Grant a permission scope to an agent.\n */\n async grant(agentId: string, scope: PermissionScope, options?: {\n valid_until?: string;\n rate_limit?: { max: number; window: string };\n }): Promise<any> {\n return this.post(`/agents/${agentId}/permissions`, { scope, ...options });\n }\n\n // ─── Audit ────────────────────────────────────────────────────────\n\n /**\n * Emit an audit event for an agent action.\n */\n async emit(event: AuditEventInput): Promise<{ ingested: number }> {\n return this.post('/audit/events', { events: [event] });\n }\n\n /**\n * Emit a batch of audit events (up to 1,000).\n */\n async emitBatch(events: AuditEventInput[]): Promise<{ ingested: number }> {\n return this.post('/audit/events', { events });\n }\n\n // ─── Signing ──────────────────────────────────────────────────────\n\n /**\n * Sign a payload with an Ed25519 private key (client-side).\n * Uses the Web Crypto API or Node.js crypto.\n */\n async sign(payload: string, privateKeyPem: string): Promise<string> {\n if (typeof globalThis.crypto?.subtle !== 'undefined') {\n // Web Crypto API\n const keyData = this.pemToArrayBuffer(privateKeyPem);\n const key = await globalThis.crypto.subtle.importKey(\n 'pkcs8', keyData, { name: 'Ed25519' }, false, ['sign']\n );\n const signature = await globalThis.crypto.subtle.sign(\n 'Ed25519', key, new TextEncoder().encode(payload)\n );\n return `ed25519:${this.arrayBufferToBase64(signature)}`;\n } else {\n // Node.js crypto fallback\n const crypto = await import('node:crypto');\n const sign = crypto.sign(null, Buffer.from(payload), privateKeyPem);\n return `ed25519:${sign.toString('base64')}`;\n }\n }\n\n // ─── HTTP Client ──────────────────────────────────────────────────\n\n private async get(path: string): Promise<any> {\n return this.request('GET', path);\n }\n\n private async post(path: string, body: any): Promise<any> {\n return this.request('POST', path, body);\n }\n\n private async delete(path: string): Promise<any> {\n return this.request('DELETE', path);\n }\n\n private async request(method: string, path: string, body?: any): Promise<any> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n\n try {\n const response = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers: {\n 'Authorization': `Bearer ${this.apiKey}`,\n 'Content-Type': 'application/json',\n 'User-Agent': 'vorim-sdk/1.0.0',\n },\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n\n if (!response.ok) {\n const errBody = await response.json().catch(() => ({})) as Record<string, any>;\n throw new VorimError(\n response.status,\n errBody.error?.code || 'UNKNOWN_ERROR',\n errBody.error?.message || `HTTP ${response.status}`,\n errBody.error?.details\n );\n }\n\n const json = await response.json() as Record<string, any>;\n return json.data;\n } finally {\n clearTimeout(timeoutId);\n }\n }\n\n private pemToArrayBuffer(pem: string): ArrayBuffer {\n const b64 = pem.replace(/-----[^-]+-----/g, '').replace(/\\s/g, '');\n const binary = atob(b64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return bytes.buffer;\n }\n\n private arrayBufferToBase64(buffer: ArrayBuffer): string {\n const bytes = new Uint8Array(buffer);\n let binary = '';\n for (const byte of bytes) {\n binary += String.fromCharCode(byte);\n }\n return btoa(binary);\n }\n}\n\nexport class VorimError extends Error {\n constructor(\n public status: number,\n public code: string,\n message: string,\n public details?: Record<string, unknown>\n ) {\n super(message);\n this.name = 'VorimError';\n }\n}\n\n// ─── Convenience export ──────────────────────────────────────────────\n\nexport default function createVorim(config: VorimConfig): VorimSDK {\n return new VorimSDK(config);\n}\n\n// Re-export types for consumers\nexport type {\n Agent, AgentRegistrationInput, AgentRegistrationResult,\n TrustRecord, AuditEventInput, AuditEventType, AuditResult,\n PermissionScope, PermissionCheckResult, AgentStatus,\n} from './types.js';\n"],"mappings":";AAgBO,IAAM,WAAN,MAAe;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,QAAqB;AAC/B,SAAK,SAAS,OAAO;AACrB,SAAK,WAAW,OAAO,WAAW,wBAAwB,QAAQ,OAAO,EAAE,IAAI;AAC/E,SAAK,UAAU,OAAO,WAAW;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,SAAS,OAAiE;AAC9E,WAAO,KAAK,KAAK,WAAW,KAAK;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO,SAAuC;AAClD,WAAO,KAAK,IAAI,iBAAiB,OAAO,EAAE;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,SAAS,SAAiC;AAC9C,WAAO,KAAK,IAAI,WAAW,OAAO,EAAE;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAW,QAAyG;AACxH,UAAM,KAAK,IAAI,gBAAgB,MAAa,EAAE,SAAS;AACvD,WAAO,KAAK,IAAI,UAAU,KAAK,MAAM,KAAK,EAAE,EAAE;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO,SAAgC;AAC3C,UAAM,KAAK,OAAO,WAAW,OAAO,EAAE;AAAA,EACxC;AAAA;AAAA;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AACtC,YAAM,CAAC,IAAI,OAAO,WAAW,CAAC;AAAA,IAChC;AACA,WAAO,MAAM;AAAA,EACf;AAAA,EAEQ,oBAAoB,QAA6B;AACvD,UAAM,QAAQ,IAAI,WAAW,MAAM;AACnC,QAAI,SAAS;AACb,eAAW,QAAQ,OAAO;AACxB,gBAAU,OAAO,aAAa,IAAI;AAAA,IACpC;AACA,WAAO,KAAK,MAAM;AAAA,EACpB;AACF;AAEO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YACS,QACA,MACP,SACO,SACP;AACA,UAAM,OAAO;AALN;AACA;AAEA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAIe,SAAR,YAA6B,QAA+B;AACjE,SAAO,IAAI,SAAS,MAAM;AAC5B;","names":[]}
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@vorim/sdk",
3
+ "version": "1.0.0",
4
+ "description": "Official TypeScript SDK for Vorim AI — AI Agent Identity, Permissions & Audit",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md",
24
+ "LICENSE"
25
+ ],
26
+ "scripts": {
27
+ "build": "tsup",
28
+ "prepublishOnly": "npm run build",
29
+ "typecheck": "tsc --noEmit"
30
+ },
31
+ "dependencies": {},
32
+ "devDependencies": {
33
+ "@vorim/shared-types": "*",
34
+ "tsup": "^8.5.1",
35
+ "typescript": "^5.4.0"
36
+ },
37
+ "keywords": [
38
+ "ai-agent",
39
+ "agent-identity",
40
+ "trust",
41
+ "permissions",
42
+ "audit",
43
+ "ed25519",
44
+ "vorim",
45
+ "typescript"
46
+ ],
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/Kzino/vorim-protocol",
50
+ "directory": "packages/sdk"
51
+ },
52
+ "homepage": "https://vorim.ai",
53
+ "bugs": {
54
+ "url": "https://github.com/Kzino/vorim-protocol/issues"
55
+ },
56
+ "author": "Vorim AI <hello@vorim.ai>",
57
+ "license": "MIT",
58
+ "engines": {
59
+ "node": ">=18.0.0"
60
+ }
61
+ }