@vienna-os/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.mjs ADDED
@@ -0,0 +1,824 @@
1
+ // src/errors.ts
2
+ var ViennaError = class extends Error {
3
+ /** Machine-readable error code from the API (e.g. `POLICY_VIOLATION`). */
4
+ code;
5
+ /** HTTP status code. */
6
+ status;
7
+ /** Additional error details from the API response. */
8
+ details;
9
+ constructor(message, status, code, details) {
10
+ super(message);
11
+ this.name = "ViennaError";
12
+ this.status = status;
13
+ this.code = code;
14
+ this.details = details;
15
+ Object.setPrototypeOf(this, new.target.prototype);
16
+ }
17
+ };
18
+ var ViennaAuthError = class extends ViennaError {
19
+ constructor(message, code = "UNAUTHORIZED", details) {
20
+ super(message, 401, code, details);
21
+ this.name = "ViennaAuthError";
22
+ }
23
+ };
24
+ var ViennaForbiddenError = class extends ViennaError {
25
+ constructor(message, code = "FORBIDDEN", details) {
26
+ super(message, 403, code, details);
27
+ this.name = "ViennaForbiddenError";
28
+ }
29
+ };
30
+ var ViennaNotFoundError = class extends ViennaError {
31
+ constructor(message, code = "NOT_FOUND", details) {
32
+ super(message, 404, code, details);
33
+ this.name = "ViennaNotFoundError";
34
+ }
35
+ };
36
+ var ViennaRateLimitError = class extends ViennaError {
37
+ /** Seconds to wait before retrying. */
38
+ retryAfter;
39
+ constructor(message, retryAfter, code = "RATE_LIMITED", details) {
40
+ super(message, 429, code, details);
41
+ this.name = "ViennaRateLimitError";
42
+ this.retryAfter = retryAfter;
43
+ }
44
+ };
45
+ var ViennaValidationError = class extends ViennaError {
46
+ /** Field-level validation errors. */
47
+ fields;
48
+ constructor(message, code = "VALIDATION_ERROR", fields, details) {
49
+ super(message, 400, code, details);
50
+ this.name = "ViennaValidationError";
51
+ this.fields = fields;
52
+ }
53
+ };
54
+ var ViennaServerError = class extends ViennaError {
55
+ constructor(message, status = 500, code = "SERVER_ERROR", details) {
56
+ super(message, status, code, details);
57
+ this.name = "ViennaServerError";
58
+ }
59
+ };
60
+
61
+ // src/utils.ts
62
+ var SDK_VERSION = "0.1.0";
63
+ var DEFAULT_BASE_URL = "https://vienna-os.fly.dev";
64
+ var DEFAULT_TIMEOUT = 3e4;
65
+ var DEFAULT_RETRIES = 3;
66
+ function sleep(ms) {
67
+ return new Promise((resolve) => setTimeout(resolve, ms));
68
+ }
69
+ function backoffDelay(attempt, baseMs = 1e3) {
70
+ const exponential = baseMs * Math.pow(2, attempt);
71
+ const jitter = Math.random() * baseMs;
72
+ return Math.min(exponential + jitter, 3e4);
73
+ }
74
+ function isRetryable(status) {
75
+ return status === 429 || status >= 500;
76
+ }
77
+ async function parseResponse(response) {
78
+ const contentType = response.headers.get("content-type") ?? "";
79
+ if (!contentType.includes("application/json")) {
80
+ if (!response.ok) {
81
+ throwHttpError(response.status, response.statusText, "NON_JSON_ERROR");
82
+ }
83
+ return void 0;
84
+ }
85
+ const body = await response.json();
86
+ if (!response.ok || !body.success) {
87
+ const message = body.error ?? response.statusText ?? "Unknown error";
88
+ const code = body.code ?? "UNKNOWN";
89
+ throwHttpError(response.status, message, code, body.data);
90
+ }
91
+ return body.data;
92
+ }
93
+ function throwHttpError(status, message, code, details) {
94
+ switch (status) {
95
+ case 400:
96
+ throw new ViennaValidationError(
97
+ message,
98
+ code,
99
+ typeof details === "object" && details !== null ? details : void 0,
100
+ details
101
+ );
102
+ case 401:
103
+ throw new ViennaAuthError(message, code, details);
104
+ case 403:
105
+ throw new ViennaForbiddenError(message, code, details);
106
+ case 404:
107
+ throw new ViennaNotFoundError(message, code, details);
108
+ case 429:
109
+ throw new ViennaRateLimitError(message, 0, code, details);
110
+ default:
111
+ if (status >= 500) {
112
+ throw new ViennaServerError(message, status, code, details);
113
+ }
114
+ throw new ViennaError(message, status, code, details);
115
+ }
116
+ }
117
+ function buildQuery(params) {
118
+ const entries = Object.entries(params).filter(([, v]) => v !== void 0 && v !== null).map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`);
119
+ return entries.length > 0 ? `?${entries.join("&")}` : "";
120
+ }
121
+
122
+ // src/intent.ts
123
+ var IntentModule = class {
124
+ constructor(client) {
125
+ this.client = client;
126
+ }
127
+ /**
128
+ * Submit an agent intent for governance evaluation and execution.
129
+ *
130
+ * @param intent - The intent request describing the action.
131
+ * @param options - Optional request options (signal, timeout).
132
+ * @returns The intent result including status, risk tier, and policy matches.
133
+ */
134
+ async submit(intent, options) {
135
+ return this.client.request("POST", "/api/v1/intents", intent, options);
136
+ }
137
+ /**
138
+ * Check the current status of a previously submitted intent.
139
+ *
140
+ * @param intentId - The intent identifier (e.g. `int-abc123`).
141
+ * @param options - Optional request options.
142
+ * @returns Full intent status including audit trail references.
143
+ */
144
+ async status(intentId, options) {
145
+ return this.client.request("GET", `/api/v1/intents/${encodeURIComponent(intentId)}`, void 0, options);
146
+ }
147
+ /**
148
+ * Simulate an intent without executing it (dry-run).
149
+ * Useful for testing policy configurations and understanding governance outcomes.
150
+ *
151
+ * @param intent - The intent to simulate.
152
+ * @param options - Optional request options.
153
+ * @returns Simulation result showing what would happen.
154
+ */
155
+ async simulate(intent, options) {
156
+ return this.client.request("POST", "/api/v1/intents/simulate", intent, options);
157
+ }
158
+ };
159
+
160
+ // src/policies.ts
161
+ var PoliciesModule = class {
162
+ constructor(client) {
163
+ this.client = client;
164
+ }
165
+ /**
166
+ * List all policies, optionally filtered.
167
+ *
168
+ * @param params - Filter parameters.
169
+ * @param options - Optional request options.
170
+ * @returns Array of policy rules.
171
+ */
172
+ async list(params, options) {
173
+ const query = buildQuery(params ?? {});
174
+ return this.client.request("GET", `/api/v1/policies${query}`, void 0, options);
175
+ }
176
+ /**
177
+ * Get a single policy by ID.
178
+ *
179
+ * @param policyId - The policy identifier.
180
+ * @param options - Optional request options.
181
+ * @returns The policy rule.
182
+ */
183
+ async get(policyId, options) {
184
+ return this.client.request("GET", `/api/v1/policies/${encodeURIComponent(policyId)}`, void 0, options);
185
+ }
186
+ /**
187
+ * Create a new governance policy.
188
+ *
189
+ * @param params - Policy creation parameters.
190
+ * @param options - Optional request options.
191
+ * @returns The created policy rule.
192
+ */
193
+ async create(params, options) {
194
+ return this.client.request("POST", "/api/v1/policies", params, options);
195
+ }
196
+ /**
197
+ * Update an existing policy.
198
+ *
199
+ * @param policyId - The policy identifier.
200
+ * @param params - Fields to update.
201
+ * @param options - Optional request options.
202
+ * @returns The updated policy rule.
203
+ */
204
+ async update(policyId, params, options) {
205
+ return this.client.request("PATCH", `/api/v1/policies/${encodeURIComponent(policyId)}`, params, options);
206
+ }
207
+ /**
208
+ * Delete a policy.
209
+ *
210
+ * @param policyId - The policy identifier.
211
+ * @param options - Optional request options.
212
+ */
213
+ async delete(policyId, options) {
214
+ await this.client.request("DELETE", `/api/v1/policies/${encodeURIComponent(policyId)}`, void 0, options);
215
+ }
216
+ /**
217
+ * Evaluate policies against a test payload (dry-run).
218
+ * Returns which policies would match and what action would be taken.
219
+ *
220
+ * @param payload - The test payload to evaluate.
221
+ * @param options - Optional request options.
222
+ * @returns Evaluation result with matched policies and final action.
223
+ */
224
+ async evaluate(payload, options) {
225
+ return this.client.request("POST", "/api/v1/policies/evaluate", payload, options);
226
+ }
227
+ /**
228
+ * List available industry policy templates.
229
+ *
230
+ * @param options - Optional request options.
231
+ * @returns Array of policy templates.
232
+ */
233
+ async templates(options) {
234
+ return this.client.request("GET", "/api/v1/policies/templates", void 0, options);
235
+ }
236
+ };
237
+
238
+ // src/fleet.ts
239
+ var FleetModule = class {
240
+ constructor(client) {
241
+ this.client = client;
242
+ }
243
+ /**
244
+ * List all agents in the fleet.
245
+ *
246
+ * @param options - Optional request options.
247
+ * @returns Array of fleet agents.
248
+ */
249
+ async list(options) {
250
+ return this.client.request("GET", "/api/v1/fleet", void 0, options);
251
+ }
252
+ /**
253
+ * Get a single agent by ID.
254
+ *
255
+ * @param agentId - The agent identifier.
256
+ * @param options - Optional request options.
257
+ * @returns The fleet agent.
258
+ */
259
+ async get(agentId, options) {
260
+ return this.client.request("GET", `/api/v1/fleet/${encodeURIComponent(agentId)}`, void 0, options);
261
+ }
262
+ /**
263
+ * Get metrics for a specific agent.
264
+ *
265
+ * @param agentId - The agent identifier.
266
+ * @param options - Optional request options.
267
+ * @returns Agent performance metrics.
268
+ */
269
+ async metrics(agentId, options) {
270
+ return this.client.request("GET", `/api/v1/fleet/${encodeURIComponent(agentId)}/metrics`, void 0, options);
271
+ }
272
+ /**
273
+ * Get paginated activity log for an agent.
274
+ *
275
+ * @param agentId - The agent identifier.
276
+ * @param pagination - Pagination parameters.
277
+ * @param options - Optional request options.
278
+ * @returns Paginated list of agent activities.
279
+ */
280
+ async activity(agentId, pagination, options) {
281
+ const query = buildQuery(pagination ?? {});
282
+ return this.client.request(
283
+ "GET",
284
+ `/api/v1/fleet/${encodeURIComponent(agentId)}/activity${query}`,
285
+ void 0,
286
+ options
287
+ );
288
+ }
289
+ /**
290
+ * Suspend an agent, preventing it from submitting intents.
291
+ *
292
+ * @param agentId - The agent identifier.
293
+ * @param params - Suspension details.
294
+ * @param options - Optional request options.
295
+ * @returns The updated agent.
296
+ */
297
+ async suspend(agentId, params, options) {
298
+ return this.client.request(
299
+ "POST",
300
+ `/api/v1/fleet/${encodeURIComponent(agentId)}/suspend`,
301
+ params,
302
+ options
303
+ );
304
+ }
305
+ /**
306
+ * Reactivate a suspended agent.
307
+ *
308
+ * @param agentId - The agent identifier.
309
+ * @param options - Optional request options.
310
+ * @returns The updated agent.
311
+ */
312
+ async activate(agentId, options) {
313
+ return this.client.request(
314
+ "POST",
315
+ `/api/v1/fleet/${encodeURIComponent(agentId)}/activate`,
316
+ void 0,
317
+ options
318
+ );
319
+ }
320
+ /**
321
+ * Manually adjust an agent's trust score.
322
+ *
323
+ * @param agentId - The agent identifier.
324
+ * @param params - New trust score and reason.
325
+ * @param options - Optional request options.
326
+ * @returns The updated agent.
327
+ */
328
+ async setTrust(agentId, params, options) {
329
+ return this.client.request(
330
+ "PUT",
331
+ `/api/v1/fleet/${encodeURIComponent(agentId)}/trust`,
332
+ params,
333
+ options
334
+ );
335
+ }
336
+ /**
337
+ * List fleet-wide alerts.
338
+ *
339
+ * @param params - Filter parameters.
340
+ * @param options - Optional request options.
341
+ * @returns Array of fleet alerts.
342
+ */
343
+ async alerts(params, options) {
344
+ const query = buildQuery(params ?? {});
345
+ return this.client.request("GET", `/api/v1/fleet/alerts${query}`, void 0, options);
346
+ }
347
+ /**
348
+ * Resolve a fleet alert.
349
+ *
350
+ * @param alertId - The alert identifier.
351
+ * @param params - Resolution details.
352
+ * @param options - Optional request options.
353
+ * @returns The resolved alert.
354
+ */
355
+ async resolveAlert(alertId, params, options) {
356
+ return this.client.request(
357
+ "POST",
358
+ `/api/v1/fleet/alerts/${encodeURIComponent(alertId)}/resolve`,
359
+ params,
360
+ options
361
+ );
362
+ }
363
+ };
364
+
365
+ // src/approvals.ts
366
+ var ApprovalsModule = class {
367
+ constructor(client) {
368
+ this.client = client;
369
+ }
370
+ /**
371
+ * List approvals, optionally filtered by status or source.
372
+ *
373
+ * @param params - Filter parameters.
374
+ * @param options - Optional request options.
375
+ * @returns Array of approvals.
376
+ */
377
+ async list(params, options) {
378
+ const query = buildQuery(params ?? {});
379
+ return this.client.request("GET", `/api/v1/approvals${query}`, void 0, options);
380
+ }
381
+ /**
382
+ * Get a single approval by ID.
383
+ *
384
+ * @param approvalId - The approval identifier.
385
+ * @param options - Optional request options.
386
+ * @returns The approval.
387
+ */
388
+ async get(approvalId, options) {
389
+ return this.client.request("GET", `/api/v1/approvals/${encodeURIComponent(approvalId)}`, void 0, options);
390
+ }
391
+ /**
392
+ * Approve a pending action.
393
+ *
394
+ * @param approvalId - The approval identifier.
395
+ * @param params - Approval details (operator, optional notes).
396
+ * @param options - Optional request options.
397
+ * @returns The updated approval.
398
+ */
399
+ async approve(approvalId, params, options) {
400
+ return this.client.request(
401
+ "POST",
402
+ `/api/v1/approvals/${encodeURIComponent(approvalId)}/approve`,
403
+ params,
404
+ options
405
+ );
406
+ }
407
+ /**
408
+ * Deny a pending action.
409
+ *
410
+ * @param approvalId - The approval identifier.
411
+ * @param params - Denial details (operator, reason).
412
+ * @param options - Optional request options.
413
+ * @returns The updated approval.
414
+ */
415
+ async deny(approvalId, params, options) {
416
+ return this.client.request(
417
+ "POST",
418
+ `/api/v1/approvals/${encodeURIComponent(approvalId)}/deny`,
419
+ params,
420
+ options
421
+ );
422
+ }
423
+ };
424
+
425
+ // src/integrations.ts
426
+ var IntegrationsModule = class {
427
+ constructor(client) {
428
+ this.client = client;
429
+ }
430
+ /**
431
+ * List all configured integrations.
432
+ *
433
+ * @param options - Optional request options.
434
+ * @returns Array of integrations.
435
+ */
436
+ async list(options) {
437
+ return this.client.request("GET", "/api/v1/integrations", void 0, options);
438
+ }
439
+ /**
440
+ * Get a single integration by ID.
441
+ *
442
+ * @param integrationId - The integration identifier.
443
+ * @param options - Optional request options.
444
+ * @returns The integration.
445
+ */
446
+ async get(integrationId, options) {
447
+ return this.client.request(
448
+ "GET",
449
+ `/api/v1/integrations/${encodeURIComponent(integrationId)}`,
450
+ void 0,
451
+ options
452
+ );
453
+ }
454
+ /**
455
+ * Create a new integration.
456
+ *
457
+ * @param params - Integration configuration.
458
+ * @param options - Optional request options.
459
+ * @returns The created integration.
460
+ */
461
+ async create(params, options) {
462
+ return this.client.request("POST", "/api/v1/integrations", params, options);
463
+ }
464
+ /**
465
+ * Update an existing integration.
466
+ *
467
+ * @param integrationId - The integration identifier.
468
+ * @param params - Fields to update.
469
+ * @param options - Optional request options.
470
+ * @returns The updated integration.
471
+ */
472
+ async update(integrationId, params, options) {
473
+ return this.client.request(
474
+ "PATCH",
475
+ `/api/v1/integrations/${encodeURIComponent(integrationId)}`,
476
+ params,
477
+ options
478
+ );
479
+ }
480
+ /**
481
+ * Delete an integration.
482
+ *
483
+ * @param integrationId - The integration identifier.
484
+ * @param options - Optional request options.
485
+ */
486
+ async delete(integrationId, options) {
487
+ await this.client.request(
488
+ "DELETE",
489
+ `/api/v1/integrations/${encodeURIComponent(integrationId)}`,
490
+ void 0,
491
+ options
492
+ );
493
+ }
494
+ /**
495
+ * Send a test event to an integration to verify connectivity.
496
+ *
497
+ * @param integrationId - The integration identifier.
498
+ * @param options - Optional request options.
499
+ * @returns Test result with success status and latency.
500
+ */
501
+ async test(integrationId, options) {
502
+ return this.client.request(
503
+ "POST",
504
+ `/api/v1/integrations/${encodeURIComponent(integrationId)}/test`,
505
+ void 0,
506
+ options
507
+ );
508
+ }
509
+ /**
510
+ * Toggle an integration's enabled/disabled state.
511
+ *
512
+ * @param integrationId - The integration identifier.
513
+ * @param params - Enable or disable.
514
+ * @param options - Optional request options.
515
+ * @returns The updated integration.
516
+ */
517
+ async toggle(integrationId, params, options) {
518
+ return this.client.request(
519
+ "PATCH",
520
+ `/api/v1/integrations/${encodeURIComponent(integrationId)}`,
521
+ params,
522
+ options
523
+ );
524
+ }
525
+ };
526
+
527
+ // src/compliance.ts
528
+ var ComplianceModule = class {
529
+ constructor(client) {
530
+ this.client = client;
531
+ }
532
+ /**
533
+ * Generate a new compliance report.
534
+ *
535
+ * @param params - Report parameters (type, period).
536
+ * @param options - Optional request options.
537
+ * @returns The created report (may still be generating).
538
+ */
539
+ async generate(params, options) {
540
+ return this.client.request("POST", "/api/v1/compliance/reports", params, options);
541
+ }
542
+ /**
543
+ * Get a compliance report by ID.
544
+ *
545
+ * @param reportId - The report identifier.
546
+ * @param options - Optional request options.
547
+ * @returns The compliance report with summary data.
548
+ */
549
+ async get(reportId, options) {
550
+ return this.client.request(
551
+ "GET",
552
+ `/api/v1/compliance/reports/${encodeURIComponent(reportId)}`,
553
+ void 0,
554
+ options
555
+ );
556
+ }
557
+ /**
558
+ * List all compliance reports.
559
+ *
560
+ * @param options - Optional request options.
561
+ * @returns Array of compliance reports.
562
+ */
563
+ async list(options) {
564
+ return this.client.request("GET", "/api/v1/compliance/reports", void 0, options);
565
+ }
566
+ /**
567
+ * Get quick compliance statistics for a rolling window.
568
+ *
569
+ * @param params - Stats parameters (number of days).
570
+ * @param options - Optional request options.
571
+ * @returns Compliance summary statistics.
572
+ */
573
+ async quickStats(params, options) {
574
+ const query = buildQuery(params);
575
+ return this.client.request("GET", `/api/v1/compliance/stats${query}`, void 0, options);
576
+ }
577
+ };
578
+
579
+ // src/client.ts
580
+ var ViennaClient = class {
581
+ apiKey;
582
+ baseUrl;
583
+ timeout;
584
+ retries;
585
+ onError;
586
+ /** Intent submission and status. */
587
+ intent;
588
+ /** Policy management. */
589
+ policies;
590
+ /** Fleet and agent management. */
591
+ fleet;
592
+ /** Approval workflows. */
593
+ approvals;
594
+ /** External integrations. */
595
+ integrations;
596
+ /** Compliance reporting. */
597
+ compliance;
598
+ constructor(config) {
599
+ if (!config.apiKey) {
600
+ throw new Error("Vienna SDK: apiKey is required");
601
+ }
602
+ this.apiKey = config.apiKey;
603
+ this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
604
+ this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
605
+ this.retries = config.retries ?? DEFAULT_RETRIES;
606
+ this.onError = config.onError;
607
+ this.intent = new IntentModule(this);
608
+ this.policies = new PoliciesModule(this);
609
+ this.fleet = new FleetModule(this);
610
+ this.approvals = new ApprovalsModule(this);
611
+ this.integrations = new IntegrationsModule(this);
612
+ this.compliance = new ComplianceModule(this);
613
+ }
614
+ /**
615
+ * Make an authenticated request to the Vienna API.
616
+ *
617
+ * @param method - HTTP method.
618
+ * @param path - API path (e.g. `/api/v1/intents`).
619
+ * @param body - Optional JSON request body.
620
+ * @param options - Per-request options (signal, timeout override).
621
+ * @returns Parsed response data.
622
+ */
623
+ async request(method, path, body, options) {
624
+ const url = `${this.baseUrl}${path}`;
625
+ const requestTimeout = options?.timeout ?? this.timeout;
626
+ let lastError;
627
+ for (let attempt = 0; attempt <= this.retries; attempt++) {
628
+ const controller = new AbortController();
629
+ const timeoutId = setTimeout(() => controller.abort(), requestTimeout);
630
+ if (options?.signal) {
631
+ if (options.signal.aborted) {
632
+ clearTimeout(timeoutId);
633
+ controller.abort();
634
+ } else {
635
+ options.signal.addEventListener("abort", () => controller.abort(), { once: true });
636
+ }
637
+ }
638
+ try {
639
+ const headers = {
640
+ "X-Vienna-Api-Key": this.apiKey,
641
+ "X-Vienna-SDK-Version": SDK_VERSION,
642
+ "Accept": "application/json"
643
+ };
644
+ if (body !== void 0) {
645
+ headers["Content-Type"] = "application/json";
646
+ }
647
+ const response = await fetch(url, {
648
+ method,
649
+ headers,
650
+ body: body !== void 0 ? JSON.stringify(body) : void 0,
651
+ signal: controller.signal
652
+ });
653
+ clearTimeout(timeoutId);
654
+ if (isRetryable(response.status) && attempt < this.retries) {
655
+ const retryAfter = response.headers.get("retry-after");
656
+ const delay = retryAfter ? parseInt(retryAfter, 10) * 1e3 : backoffDelay(attempt);
657
+ await sleep(delay);
658
+ continue;
659
+ }
660
+ return await parseResponse(response);
661
+ } catch (error) {
662
+ clearTimeout(timeoutId);
663
+ lastError = error instanceof Error ? error : new Error(String(error));
664
+ const isAbort = lastError.name === "AbortError";
665
+ const isRateLimit = lastError instanceof ViennaRateLimitError;
666
+ if (isAbort || !isRateLimit && attempt >= this.retries) {
667
+ this.onError?.(lastError);
668
+ throw lastError;
669
+ }
670
+ if (attempt < this.retries) {
671
+ await sleep(backoffDelay(attempt));
672
+ }
673
+ }
674
+ }
675
+ const finalError = lastError ?? new Error("Vienna SDK: request failed after retries");
676
+ this.onError?.(finalError);
677
+ throw finalError;
678
+ }
679
+ };
680
+
681
+ // src/frameworks.ts
682
+ var BaseFrameworkAdapter = class {
683
+ vienna;
684
+ agentId;
685
+ constructor(config, frameworkName) {
686
+ this.vienna = new ViennaClient({
687
+ apiKey: config.apiKey,
688
+ baseUrl: config.baseUrl
689
+ });
690
+ this.agentId = config.agentId || `${frameworkName}-${Date.now()}`;
691
+ }
692
+ async submitIntent(action, payload) {
693
+ return await this.vienna.intent.submit({
694
+ action,
695
+ source: this.agentId,
696
+ payload
697
+ });
698
+ }
699
+ async waitForApproval(intentId, timeoutMs = 3e5) {
700
+ const startTime = Date.now();
701
+ while (Date.now() - startTime < timeoutMs) {
702
+ const status = await this.vienna.intent.status(intentId);
703
+ if (status.status === "executed" || status.status === "denied" || status.status === "cancelled") {
704
+ return status.status;
705
+ }
706
+ await new Promise((resolve) => setTimeout(resolve, 2e3));
707
+ }
708
+ throw new Error(`Approval timeout after ${timeoutMs}ms for intent ${intentId}`);
709
+ }
710
+ async reportExecution(intentId, result, details) {
711
+ const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
712
+ console.log(`Execution report for intent ${intentId}: ${result}`, details);
713
+ await this.vienna.compliance.generate({
714
+ type: "custom",
715
+ periodStart: today,
716
+ periodEnd: today
717
+ });
718
+ }
719
+ async register(metadata) {
720
+ try {
721
+ console.log(`Registering agent ${this.agentId} with metadata:`, metadata);
722
+ await this.vienna.fleet.activate(this.agentId);
723
+ } catch (error) {
724
+ console.warn(`Failed to register agent ${this.agentId}:`, error);
725
+ }
726
+ }
727
+ };
728
+ var LangChainAdapter = class extends BaseFrameworkAdapter {
729
+ constructor(config) {
730
+ super(config, "langchain");
731
+ }
732
+ getFrameworkName() {
733
+ return "langchain";
734
+ }
735
+ /** Enhanced submitIntent with LangChain tool context */
736
+ async submitToolIntent(toolName, toolArgs, chainContext) {
737
+ return await this.submitIntent(`tool_${toolName}`, {
738
+ tool_name: toolName,
739
+ tool_args: toolArgs,
740
+ chain_context: chainContext
741
+ });
742
+ }
743
+ };
744
+ var CrewAIAdapter = class extends BaseFrameworkAdapter {
745
+ constructor(config) {
746
+ super(config, "crewai");
747
+ }
748
+ getFrameworkName() {
749
+ return "crewai";
750
+ }
751
+ /** Enhanced submitIntent with CrewAI task context */
752
+ async submitTaskIntent(taskType, taskPayload, crewContext) {
753
+ return await this.submitIntent(`crew_${taskType}`, {
754
+ task_type: taskType,
755
+ task_payload: taskPayload,
756
+ crew_context: crewContext
757
+ });
758
+ }
759
+ };
760
+ var AutoGenAdapter = class extends BaseFrameworkAdapter {
761
+ constructor(config) {
762
+ super(config, "autogen");
763
+ }
764
+ getFrameworkName() {
765
+ return "autogen";
766
+ }
767
+ /** Enhanced submitIntent with AutoGen conversation context */
768
+ async submitConversationIntent(functionName, functionArgs, conversationContext) {
769
+ return await this.submitIntent(`function_${functionName}`, {
770
+ function_name: functionName,
771
+ function_args: functionArgs,
772
+ conversation_context: conversationContext
773
+ });
774
+ }
775
+ };
776
+ var OpenClawAdapter = class extends BaseFrameworkAdapter {
777
+ constructor(config) {
778
+ super(config, "openclaw");
779
+ }
780
+ getFrameworkName() {
781
+ return "openclaw";
782
+ }
783
+ /** Enhanced submitIntent with OpenClaw skill context */
784
+ async submitSkillIntent(skillName, skillArgs, sessionContext) {
785
+ return await this.submitIntent(`skill_${skillName}`, {
786
+ skill_name: skillName,
787
+ skill_args: skillArgs,
788
+ session_context: sessionContext
789
+ });
790
+ }
791
+ };
792
+ function createForLangChain(config) {
793
+ return new LangChainAdapter(config);
794
+ }
795
+ function createForCrewAI(config) {
796
+ return new CrewAIAdapter(config);
797
+ }
798
+ function createForAutoGen(config) {
799
+ return new AutoGenAdapter(config);
800
+ }
801
+ function createForOpenClaw(config) {
802
+ return new OpenClawAdapter(config);
803
+ }
804
+ export {
805
+ ApprovalsModule,
806
+ ComplianceModule,
807
+ FleetModule,
808
+ IntegrationsModule,
809
+ IntentModule,
810
+ PoliciesModule,
811
+ ViennaAuthError,
812
+ ViennaClient,
813
+ ViennaError,
814
+ ViennaForbiddenError,
815
+ ViennaNotFoundError,
816
+ ViennaRateLimitError,
817
+ ViennaServerError,
818
+ ViennaValidationError,
819
+ createForAutoGen,
820
+ createForCrewAI,
821
+ createForLangChain,
822
+ createForOpenClaw
823
+ };
824
+ //# sourceMappingURL=index.mjs.map