@vorionsys/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,380 @@
1
+ /**
2
+ * @vorionsys/sdk - Vorion SDK
3
+ *
4
+ * Simple, developer-friendly interface for AI agent governance.
5
+ * Supports both local mode (in-memory) and remote mode (cognigate-api).
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import * as crypto from 'node:crypto';
10
+ /**
11
+ * API Client for cognigate-api
12
+ */
13
+ class ApiClient {
14
+ baseUrl;
15
+ apiKey;
16
+ timeout;
17
+ constructor(baseUrl, apiKey, timeout = 30000) {
18
+ this.baseUrl = baseUrl.replace(/\/$/, ''); // Remove trailing slash
19
+ this.apiKey = apiKey;
20
+ this.timeout = timeout;
21
+ }
22
+ async request(method, path, body) {
23
+ const controller = new AbortController();
24
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
25
+ try {
26
+ const response = await fetch(`${this.baseUrl}${path}`, {
27
+ method,
28
+ headers: {
29
+ 'Content-Type': 'application/json',
30
+ 'Authorization': `Bearer ${this.apiKey}`,
31
+ },
32
+ body: body ? JSON.stringify(body) : undefined,
33
+ signal: controller.signal,
34
+ });
35
+ if (!response.ok) {
36
+ const errorData = await response.json().catch(() => ({ error: 'Unknown error' }));
37
+ throw new Error(`API error ${response.status}: ${errorData.error || errorData.message || 'Unknown'}`);
38
+ }
39
+ return await response.json();
40
+ }
41
+ finally {
42
+ clearTimeout(timeoutId);
43
+ }
44
+ }
45
+ // Intent endpoints
46
+ async submitIntent(payload) {
47
+ return this.request('POST', '/api/v1/intents', payload);
48
+ }
49
+ async checkIntent(payload) {
50
+ return this.request('POST', '/api/v1/intents/check', payload);
51
+ }
52
+ // Trust endpoints
53
+ async admitAgent(payload) {
54
+ return this.request('POST', '/api/v1/trust/admit', payload);
55
+ }
56
+ async getTrustInfo(agentId) {
57
+ return this.request('GET', `/api/v1/trust/${agentId}`);
58
+ }
59
+ async recordSignal(agentId, payload) {
60
+ return this.request('POST', `/api/v1/trust/${agentId}/signal`, payload);
61
+ }
62
+ // Health check
63
+ async health() {
64
+ return this.request('GET', '/api/v1/health');
65
+ }
66
+ }
67
+ /**
68
+ * Vorion SDK Client
69
+ *
70
+ * Simple interface for agent governance.
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * // Local mode (in-memory, for testing)
75
+ * const vorion = new Vorion({ localMode: true });
76
+ *
77
+ * // Remote mode (cognigate-api)
78
+ * const vorion = new Vorion({
79
+ * apiEndpoint: 'http://localhost:3000',
80
+ * apiKey: 'vorion-dev-key-12345',
81
+ * });
82
+ *
83
+ * const agent = vorion.registerAgent({
84
+ * agentId: 'my-agent',
85
+ * name: 'My AI Agent',
86
+ * capabilities: ['read:*', 'write:*'],
87
+ * });
88
+ *
89
+ * const result = await agent.requestAction({
90
+ * type: 'read',
91
+ * resource: 'documents/report.pdf',
92
+ * });
93
+ *
94
+ * if (result.allowed) {
95
+ * // Perform the action
96
+ * await agent.reportSuccess('read');
97
+ * } else {
98
+ * console.log('Denied:', result.reason);
99
+ * }
100
+ * ```
101
+ */
102
+ export class Vorion {
103
+ config;
104
+ agents = new Map();
105
+ apiClient = null;
106
+ constructor(config = {}) {
107
+ this.config = {
108
+ localMode: !config.apiEndpoint,
109
+ defaultObservationTier: 'GRAY_BOX',
110
+ timeout: 30000,
111
+ ...config,
112
+ };
113
+ // Initialize API client for remote mode
114
+ if (!this.config.localMode && this.config.apiEndpoint) {
115
+ if (!this.config.apiKey) {
116
+ throw new Error('apiKey is required for remote mode');
117
+ }
118
+ this.apiClient = new ApiClient(this.config.apiEndpoint, this.config.apiKey, this.config.timeout);
119
+ }
120
+ }
121
+ /**
122
+ * Register an agent with the governance system
123
+ */
124
+ async registerAgent(options) {
125
+ const agent = new Agent(this, options);
126
+ // In remote mode, admit the agent via API
127
+ if (this.apiClient) {
128
+ await this.apiClient.admitAgent({
129
+ agentId: options.agentId,
130
+ name: options.name,
131
+ capabilities: options.capabilities ?? [],
132
+ observationTier: options.observationTier ?? this.config.defaultObservationTier ?? 'GRAY_BOX',
133
+ });
134
+ }
135
+ this.agents.set(options.agentId, agent);
136
+ return agent;
137
+ }
138
+ /**
139
+ * Get a registered agent by ID
140
+ */
141
+ getAgent(agentId) {
142
+ return this.agents.get(agentId);
143
+ }
144
+ /**
145
+ * Get all registered agents
146
+ */
147
+ getAllAgents() {
148
+ return Array.from(this.agents.values());
149
+ }
150
+ /**
151
+ * Get SDK configuration
152
+ */
153
+ getConfig() {
154
+ return { ...this.config };
155
+ }
156
+ /**
157
+ * Get the API client (for advanced use)
158
+ */
159
+ getApiClient() {
160
+ return this.apiClient;
161
+ }
162
+ /**
163
+ * Check if running in local mode
164
+ */
165
+ isLocalMode() {
166
+ return this.config.localMode ?? true;
167
+ }
168
+ /**
169
+ * Health check (remote mode only)
170
+ */
171
+ async healthCheck() {
172
+ if (!this.apiClient) {
173
+ return { status: 'healthy', version: 'local' };
174
+ }
175
+ return this.apiClient.health();
176
+ }
177
+ }
178
+ /**
179
+ * Agent wrapper for simplified governance interactions
180
+ */
181
+ export class Agent {
182
+ sdk;
183
+ options;
184
+ localTrustScore = 500; // Start at T3 (Monitored) for local mode
185
+ actionHistory = [];
186
+ constructor(sdk, options) {
187
+ this.sdk = sdk;
188
+ this.options = {
189
+ observationTier: sdk.getConfig().defaultObservationTier,
190
+ capabilities: [],
191
+ ...options,
192
+ };
193
+ }
194
+ /**
195
+ * Request permission to perform an action
196
+ */
197
+ async requestAction(action) {
198
+ const apiClient = this.sdk.getApiClient();
199
+ // Remote mode: call cognigate-api
200
+ if (apiClient) {
201
+ const result = await apiClient.submitIntent({
202
+ agentId: this.options.agentId,
203
+ agentName: this.options.name,
204
+ capabilities: this.options.capabilities,
205
+ observationTier: this.options.observationTier,
206
+ action,
207
+ });
208
+ this.actionHistory.push({
209
+ action: action.type,
210
+ allowed: result.allowed,
211
+ timestamp: Date.now(),
212
+ });
213
+ return {
214
+ allowed: result.allowed,
215
+ tier: result.tier,
216
+ reason: result.reason,
217
+ proofId: result.proofId,
218
+ constraints: result.constraints,
219
+ processingTimeMs: result.processingTimeMs,
220
+ };
221
+ }
222
+ // Local mode: simple capability check
223
+ const proofId = crypto.randomUUID();
224
+ const hasCapability = this.options.capabilities?.some(cap => cap === '*' ||
225
+ cap === action.type || // Simple capability (e.g., 'read')
226
+ cap === `${action.type}:*` ||
227
+ cap === `${action.type}:${action.resource.split('/')[0]}`) ?? false;
228
+ const allowed = hasCapability && this.localTrustScore >= 200;
229
+ if (allowed) {
230
+ this.localTrustScore = Math.min(1000, this.localTrustScore + 1);
231
+ }
232
+ this.actionHistory.push({
233
+ action: action.type,
234
+ allowed,
235
+ timestamp: Date.now(),
236
+ });
237
+ return {
238
+ allowed,
239
+ tier: allowed ? 'GREEN' : 'RED',
240
+ reason: allowed
241
+ ? 'Action permitted'
242
+ : hasCapability
243
+ ? 'Trust score too low'
244
+ : `Missing capability: ${action.type}:${action.resource.split('/')[0]}`,
245
+ proofId,
246
+ constraints: allowed ? this.getConstraintsForTier() : undefined,
247
+ };
248
+ }
249
+ /**
250
+ * Report action completion (positive signal)
251
+ */
252
+ async reportSuccess(actionType) {
253
+ const apiClient = this.sdk.getApiClient();
254
+ if (apiClient) {
255
+ await apiClient.recordSignal(this.options.agentId, {
256
+ type: 'success',
257
+ source: 'sdk',
258
+ weight: 0.1,
259
+ context: { actionType },
260
+ });
261
+ }
262
+ else {
263
+ this.localTrustScore = Math.min(1000, this.localTrustScore + 2);
264
+ }
265
+ }
266
+ /**
267
+ * Report action failure (negative signal)
268
+ */
269
+ async reportFailure(actionType, reason) {
270
+ const apiClient = this.sdk.getApiClient();
271
+ if (apiClient) {
272
+ await apiClient.recordSignal(this.options.agentId, {
273
+ type: 'failure',
274
+ source: 'sdk',
275
+ weight: 0.5,
276
+ context: { actionType, reason },
277
+ });
278
+ }
279
+ else {
280
+ this.localTrustScore = Math.max(0, this.localTrustScore - 20);
281
+ }
282
+ }
283
+ /**
284
+ * Get current trust information
285
+ */
286
+ async getTrustInfo() {
287
+ const apiClient = this.sdk.getApiClient();
288
+ if (apiClient) {
289
+ const info = await apiClient.getTrustInfo(this.options.agentId);
290
+ return {
291
+ score: info.score ?? 0,
292
+ tierName: info.tierName ?? 'Unknown',
293
+ tierNumber: info.tier ?? 0,
294
+ observationTier: this.options.observationTier ?? 'GRAY_BOX',
295
+ };
296
+ }
297
+ return {
298
+ score: this.localTrustScore,
299
+ tierName: this.getTierName(),
300
+ tierNumber: this.getTierNumber(),
301
+ observationTier: this.options.observationTier ?? 'GRAY_BOX',
302
+ };
303
+ }
304
+ /**
305
+ * Get agent ID
306
+ */
307
+ getId() {
308
+ return this.options.agentId;
309
+ }
310
+ /**
311
+ * Get agent name
312
+ */
313
+ getName() {
314
+ return this.options.name;
315
+ }
316
+ /**
317
+ * Get agent capabilities
318
+ */
319
+ getCapabilities() {
320
+ return [...(this.options.capabilities ?? [])];
321
+ }
322
+ /**
323
+ * Get action history
324
+ */
325
+ getActionHistory() {
326
+ return [...this.actionHistory];
327
+ }
328
+ getTierNumber() {
329
+ if (this.localTrustScore < 200)
330
+ return 0;
331
+ if (this.localTrustScore < 350)
332
+ return 1;
333
+ if (this.localTrustScore < 500)
334
+ return 2;
335
+ if (this.localTrustScore < 650)
336
+ return 3;
337
+ if (this.localTrustScore < 800)
338
+ return 4;
339
+ if (this.localTrustScore < 876)
340
+ return 5;
341
+ if (this.localTrustScore < 951)
342
+ return 6;
343
+ return 7;
344
+ }
345
+ getTierName() {
346
+ const names = [
347
+ 'Sandbox', // T0
348
+ 'Observed', // T1
349
+ 'Provisional', // T2
350
+ 'Monitored', // T3
351
+ 'Standard', // T4
352
+ 'Trusted', // T5
353
+ 'Certified', // T6
354
+ 'Autonomous', // T7
355
+ ];
356
+ return names[this.getTierNumber()] ?? 'Unknown';
357
+ }
358
+ getConstraintsForTier() {
359
+ const tier = this.getTierNumber();
360
+ if (tier <= 1) {
361
+ return ['rate_limit:10/min', 'audit:full', 'sandbox:true'];
362
+ }
363
+ if (tier <= 3) {
364
+ return ['rate_limit:100/min', 'audit:standard'];
365
+ }
366
+ if (tier <= 5) {
367
+ return ['rate_limit:1000/min', 'audit:light'];
368
+ }
369
+ return []; // T6-T7: minimal constraints
370
+ }
371
+ }
372
+ /**
373
+ * Create a new Vorion SDK instance
374
+ */
375
+ export function createVorion(config) {
376
+ return new Vorion(config);
377
+ }
378
+ // Default export
379
+ export default Vorion;
380
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AA2EtC;;GAEG;AACH,MAAM,SAAS;IACL,OAAO,CAAS;IAChB,MAAM,CAAS;IACf,OAAO,CAAS;IAExB,YAAY,OAAe,EAAE,MAAc,EAAE,UAAkB,KAAK;QAClE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,wBAAwB;QACnE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,OAAO,CAAI,MAAc,EAAE,IAAY,EAAE,IAAc;QAC3D,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAErE,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,EAAE,EAAE;gBACrD,MAAM;gBACN,OAAO,EAAE;oBACP,cAAc,EAAE,kBAAkB;oBAClC,eAAe,EAAE,UAAU,IAAI,CAAC,MAAM,EAAE;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AAO,CAAC,CAAC;IACX,CAAC;IAEO,WAAW;QACjB,MAAM,KAAK,GAAG;YACZ,SAAS,EAAO,KAAK;YACrB,UAAU,EAAM,KAAK;YACrB,aAAa,EAAG,KAAK;YACrB,WAAW,EAAK,KAAK;YACrB,UAAU,EAAM,KAAK;YACrB,SAAS,EAAO,KAAK;YACrB,WAAW,EAAK,KAAK;YACrB,YAAY,EAAI,KAAK;SACtB,CAAC;QACF,OAAO,KAAK,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,IAAI,SAAS,CAAC;IAClD,CAAC;IAEO,qBAAqB;QAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QAClC,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;YACd,OAAO,CAAC,mBAAmB,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC;QAC7D,CAAC;QACD,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;YACd,OAAO,CAAC,oBAAoB,EAAE,gBAAgB,CAAC,CAAC;QAClD,CAAC;QACD,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;YACd,OAAO,CAAC,qBAAqB,EAAE,aAAa,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,EAAE,CAAC,CAAC,6BAA6B;IAC1C,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,MAAqB;IAChD,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC;AAED,iBAAiB;AACjB,eAAe,MAAM,CAAC"}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@vorionsys/sdk",
3
+ "version": "0.1.0",
4
+ "description": "Vorion SDK - Simple interface for AI agent governance",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "main": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ }
16
+ },
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "test": "vitest run",
20
+ "test:watch": "vitest"
21
+ },
22
+ "dependencies": {
23
+ "pino": "^9.0.0"
24
+ },
25
+ "peerDependencies": {
26
+ "@vorionsys/runtime": ">=0.1.0",
27
+ "typescript": "^5.0.0"
28
+ },
29
+ "peerDependenciesMeta": {
30
+ "@vorionsys/runtime": {
31
+ "optional": false
32
+ },
33
+ "typescript": {
34
+ "optional": true
35
+ }
36
+ },
37
+ "devDependencies": {
38
+ "vitest": "^2.0.0"
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "src"
43
+ ],
44
+ "license": "MIT",
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "https://github.com/vorionsys/vorion.git",
48
+ "directory": "packages/sdk"
49
+ },
50
+ "keywords": [
51
+ "ai",
52
+ "agent",
53
+ "governance",
54
+ "trust",
55
+ "sdk"
56
+ ]
57
+ }
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Vorion SDK Tests
3
+ */
4
+
5
+ import { describe, it, expect, beforeEach } from 'vitest';
6
+ import { Vorion, createVorion, Agent } from '../index.js';
7
+
8
+ describe('Vorion SDK', () => {
9
+ let vorion: Vorion;
10
+
11
+ beforeEach(() => {
12
+ vorion = createVorion({ localMode: true });
13
+ });
14
+
15
+ describe('Vorion', () => {
16
+ it('should create SDK instance', () => {
17
+ expect(vorion).toBeInstanceOf(Vorion);
18
+ });
19
+
20
+ it('should register agents', async () => {
21
+ const agent = await vorion.registerAgent({
22
+ agentId: 'test-agent',
23
+ name: 'Test Agent',
24
+ capabilities: ['read', 'write'],
25
+ });
26
+
27
+ expect(agent).toBeInstanceOf(Agent);
28
+ expect(agent.getId()).toBe('test-agent');
29
+ expect(agent.getName()).toBe('Test Agent');
30
+ });
31
+
32
+ it('should retrieve registered agents', async () => {
33
+ await vorion.registerAgent({
34
+ agentId: 'agent-1',
35
+ name: 'Agent 1',
36
+ });
37
+
38
+ const retrieved = vorion.getAgent('agent-1');
39
+ expect(retrieved).toBeDefined();
40
+ expect(retrieved?.getId()).toBe('agent-1');
41
+ });
42
+
43
+ it('should list all agents', async () => {
44
+ await vorion.registerAgent({ agentId: 'agent-1', name: 'Agent 1' });
45
+ await vorion.registerAgent({ agentId: 'agent-2', name: 'Agent 2' });
46
+
47
+ const agents = vorion.getAllAgents();
48
+ expect(agents.length).toBe(2);
49
+ });
50
+
51
+ it('should return config', () => {
52
+ const config = vorion.getConfig();
53
+ expect(config.localMode).toBe(true);
54
+ expect(config.defaultObservationTier).toBe('GRAY_BOX');
55
+ });
56
+ });
57
+
58
+ describe('Agent', () => {
59
+ let agent: Agent;
60
+
61
+ beforeEach(async () => {
62
+ agent = await vorion.registerAgent({
63
+ agentId: 'test-agent',
64
+ name: 'Test Agent',
65
+ capabilities: ['read', 'write'],
66
+ observationTier: 'GRAY_BOX',
67
+ });
68
+ });
69
+
70
+ it('should request actions with capability', async () => {
71
+ const result = await agent.requestAction({
72
+ type: 'read',
73
+ resource: 'documents/test.pdf',
74
+ });
75
+
76
+ expect(result.allowed).toBe(true);
77
+ expect(result.tier).toBe('GREEN');
78
+ expect(result.proofId).toBeDefined();
79
+ });
80
+
81
+ it('should deny actions without capability', async () => {
82
+ const result = await agent.requestAction({
83
+ type: 'delete', // Not in capabilities
84
+ resource: 'documents/test.pdf',
85
+ });
86
+
87
+ expect(result.allowed).toBe(false);
88
+ expect(result.reason).toContain('Missing capability');
89
+ });
90
+
91
+ it('should track action history', async () => {
92
+ await agent.requestAction({ type: 'read', resource: 'file1.txt' });
93
+ await agent.requestAction({ type: 'write', resource: 'file2.txt' });
94
+
95
+ const history = agent.getActionHistory();
96
+ expect(history.length).toBe(2);
97
+ expect(history[0].action).toBe('read');
98
+ expect(history[1].action).toBe('write');
99
+ });
100
+
101
+ it('should provide trust info', async () => {
102
+ const trustInfo = await agent.getTrustInfo();
103
+
104
+ expect(trustInfo.score).toBe(500); // Default start
105
+ expect(trustInfo.tierName).toBe('Monitored'); // T3
106
+ expect(trustInfo.tierNumber).toBe(3);
107
+ expect(trustInfo.observationTier).toBe('GRAY_BOX');
108
+ });
109
+
110
+ it('should increase trust on success', async () => {
111
+ const initialTrustInfo = await agent.getTrustInfo();
112
+ const initialScore = initialTrustInfo.score;
113
+
114
+ await agent.reportSuccess('read');
115
+
116
+ const newTrustInfo = await agent.getTrustInfo();
117
+ expect(newTrustInfo.score).toBeGreaterThan(initialScore);
118
+ });
119
+
120
+ it('should decrease trust on failure (asymmetric)', async () => {
121
+ const initialTrustInfo = await agent.getTrustInfo();
122
+ const initialScore = initialTrustInfo.score;
123
+
124
+ await agent.reportFailure('write', 'Permission denied');
125
+
126
+ const newTrustInfo = await agent.getTrustInfo();
127
+ expect(newTrustInfo.score).toBeLessThan(initialScore);
128
+ // Asymmetric: failure should decrease more than success increases
129
+ expect(initialScore - newTrustInfo.score).toBeGreaterThan(10);
130
+ });
131
+
132
+ it('should apply constraints based on tier', async () => {
133
+ const result = await agent.requestAction({
134
+ type: 'read',
135
+ resource: 'documents/test.pdf',
136
+ });
137
+
138
+ expect(result.constraints).toBeDefined();
139
+ expect(result.constraints?.some((c) => c.includes('rate_limit'))).toBe(true);
140
+ });
141
+
142
+ it('should return capabilities', () => {
143
+ const caps = agent.getCapabilities();
144
+ expect(caps).toContain('read');
145
+ expect(caps).toContain('write');
146
+ });
147
+ });
148
+
149
+ describe('Trust Tiers', () => {
150
+ it('should correctly identify tier from score', async () => {
151
+ const agent = await vorion.registerAgent({
152
+ agentId: 'tier-test',
153
+ name: 'Tier Test',
154
+ capabilities: ['read'],
155
+ });
156
+
157
+ // Default is 500 = T3 Monitored
158
+ const initialTrustInfo = await agent.getTrustInfo();
159
+ expect(initialTrustInfo.tierName).toBe('Monitored');
160
+
161
+ // Decrease trust significantly
162
+ for (let i = 0; i < 20; i++) {
163
+ await agent.reportFailure('read');
164
+ }
165
+
166
+ // Should be at lower tier now
167
+ const newTrustInfo = await agent.getTrustInfo();
168
+ expect(newTrustInfo.tierNumber).toBeLessThan(3);
169
+ });
170
+ });
171
+
172
+ describe('Remote mode configuration', () => {
173
+ it('should require apiKey for remote mode', () => {
174
+ expect(() => {
175
+ new Vorion({
176
+ apiEndpoint: 'http://localhost:3000',
177
+ // No apiKey provided
178
+ });
179
+ }).toThrow('apiKey is required for remote mode');
180
+ });
181
+
182
+ it('should default to local mode without apiEndpoint', () => {
183
+ const v = new Vorion({});
184
+ expect(v.isLocalMode()).toBe(true);
185
+ });
186
+
187
+ it('should enable remote mode with apiEndpoint and apiKey', () => {
188
+ const v = new Vorion({
189
+ apiEndpoint: 'http://localhost:3000',
190
+ apiKey: 'test-key',
191
+ });
192
+ expect(v.isLocalMode()).toBe(false);
193
+ });
194
+
195
+ it('should return local health check in local mode', async () => {
196
+ const health = await vorion.healthCheck();
197
+ expect(health.status).toBe('healthy');
198
+ expect(health.version).toBe('local');
199
+ });
200
+ });
201
+ });