@tryvira/sdk 0.1.66 → 0.1.68

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/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @tryvira/sdk
2
2
 
3
+ Canonical integration helpers use verb-noun names such as `connectAiSystem`,
4
+ `recordUserFeedback`, and `recordBusinessOutcome`. The older `connectOnce`,
5
+ `feedback`, and `outcome` methods remain supported as source-compatible aliases.
6
+
3
7
  The official JavaScript and TypeScript client for Vira. Use it to connect an AI
4
8
  application, record observations, author governed behavior, evaluate changes, release
5
9
  approved behavior, and resolve it at runtime.
package/dist/index.js CHANGED
@@ -48,6 +48,59 @@ var retryAfterMs = (value, now = Date.now()) => {
48
48
  const date = Date.parse(value);
49
49
  return Number.isFinite(date) && date > now ? Math.min(date - now, 12e4) : 0;
50
50
  };
51
+ async function viraHttpRequest(url, options) {
52
+ const timeoutMs = Math.max(1e3, Math.min(options.timeoutMs ?? 15e3, 12e4));
53
+ const retries = Math.max(0, Math.min(options.retries ?? 2, 5));
54
+ const headers = { accept: "application/json", ...options.defaultHeaders ?? {} };
55
+ if (options.body !== void 0) headers["content-type"] = "application/json";
56
+ if (options.apiKey) {
57
+ if (options.apiKey.startsWith("vira_live_")) headers["x-vira-api-key"] = options.apiKey;
58
+ else {
59
+ headers.authorization = `Bearer ${options.apiKey}`;
60
+ headers["x-vira-api-key"] = options.apiKey;
61
+ }
62
+ }
63
+ if (options.idempotencyKey) headers["idempotency-key"] = options.idempotencyKey;
64
+ const retryable = options.method === "GET" || Boolean(options.idempotencyKey);
65
+ const attempts = retryable ? retries + 1 : 1;
66
+ let lastError;
67
+ for (let attempt = 0; attempt < attempts; attempt += 1) {
68
+ const controller = new AbortController();
69
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
70
+ try {
71
+ const response = await (options.fetcher ?? fetch)(url, { method: options.method, headers, body: options.body === void 0 ? void 0 : JSON.stringify(options.body), signal: controller.signal });
72
+ const raw = await response.text();
73
+ let body = null;
74
+ try {
75
+ body = raw ? JSON.parse(raw) : null;
76
+ } catch {
77
+ body = raw;
78
+ }
79
+ const requestId = response.headers.get("x-request-id") ?? "";
80
+ if (!response.ok) {
81
+ const error = new ViraApiError(`VIRA_API_${response.status}`, response.status, body, requestId);
82
+ if ((response.status >= 500 || response.status === 429) && attempt + 1 < attempts) {
83
+ const serverDelay = retryAfterMs(response.headers.get("retry-after"));
84
+ await wait(Math.max(serverDelay, 25 * 2 ** attempt) + Math.floor(Math.random() * 25));
85
+ continue;
86
+ }
87
+ throw error;
88
+ }
89
+ return { status: response.status, body, requestId };
90
+ } catch (error) {
91
+ lastError = error;
92
+ if (error instanceof ViraApiError) throw error;
93
+ if (attempt + 1 < attempts) {
94
+ await wait(25 * 2 ** attempt);
95
+ continue;
96
+ }
97
+ throw error;
98
+ } finally {
99
+ clearTimeout(timer);
100
+ }
101
+ }
102
+ throw lastError;
103
+ }
51
104
  var ViraClient = class {
52
105
  evaluations;
53
106
  teach;
@@ -259,6 +312,10 @@ var ViraClient = class {
259
312
  }
260
313
  };
261
314
  }
315
+ /** Canonical verb-noun name; connectOnce remains for source compatibility. */
316
+ connectAiSystem(input) {
317
+ return this.connectOnce(input);
318
+ }
262
319
  observe(event, options = {}) {
263
320
  buildObservationRequest(event);
264
321
  return (async () => {
@@ -288,6 +345,12 @@ var ViraClient = class {
288
345
  feedback(event, options = {}) {
289
346
  return this.observe({ ...event, eventType: "feedback.user" }, options);
290
347
  }
348
+ recordBusinessOutcome(event, options = {}) {
349
+ return this.outcome(event, options);
350
+ }
351
+ recordUserFeedback(event, options = {}) {
352
+ return this.feedback(event, options);
353
+ }
291
354
  observeBatch(events, options = {}) {
292
355
  if (!Array.isArray(events) || events.length < 1 || events.length > 100)
293
356
  throw new Error("SDK_OBSERVATION_BATCH_INVALID");
@@ -1614,5 +1677,6 @@ export {
1614
1677
  createViraMiddleware,
1615
1678
  redactToolObservation,
1616
1679
  resolveFrameworkBoundary,
1617
- resolveHostToolBinding
1680
+ resolveHostToolBinding,
1681
+ viraHttpRequest
1618
1682
  };
@@ -8,7 +8,7 @@ export interface RuntimeRequest {
8
8
  expiresAt: number;
9
9
  }
10
10
  export interface SdkRequest {
11
- method: "GET" | "POST" | "DELETE";
11
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
12
12
  path: string;
13
13
  query?: Readonly<Record<string, string>>;
14
14
  body?: Readonly<Record<string, unknown>>;
@@ -184,6 +184,18 @@ type ClientObservation = ClientObservationScope & {
184
184
  sessionId?: string;
185
185
  [key: string]: unknown;
186
186
  };
187
+ export interface ViraHttpRequestOptions {
188
+ apiKey?: string;
189
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
190
+ body?: unknown;
191
+ idempotencyKey?: string;
192
+ fetcher?: typeof fetch;
193
+ timeoutMs?: number;
194
+ retries?: number;
195
+ defaultHeaders?: Readonly<Record<string, string>>;
196
+ }
197
+ /** Shared transport policy for SDK-adjacent integrations such as MCP. */
198
+ export declare function viraHttpRequest<T = unknown>(url: string | URL, options: ViraHttpRequestOptions): Promise<ViraResponse<T>>;
187
199
  /** Small, authority-aware client over the existing versioned control API. */
188
200
  export declare class ViraClient {
189
201
  readonly evaluations: ViraLearningNamespaces['evaluations'];
@@ -245,6 +257,8 @@ export declare class ViraClient {
245
257
  idempotencyKey?: string;
246
258
  reuseExistingConnectionOnConflict?: boolean;
247
259
  }): Promise<ViraResponse<ConnectOnceResult> | null>;
260
+ /** Canonical verb-noun name; connectOnce remains for source compatibility. */
261
+ connectAiSystem(input: Parameters<ViraClient['connectOnce']>[0]): Promise<ViraResponse<ConnectOnceResult> | null>;
248
262
  observe(event: ClientObservation, options?: {
249
263
  idempotencyKey?: string;
250
264
  }): Promise<ViraResponse<ClientBody> | null>;
@@ -280,6 +294,12 @@ export declare class ViraClient {
280
294
  }, options?: {
281
295
  idempotencyKey?: string;
282
296
  }): Promise<ViraResponse<ClientBody> | null>;
297
+ recordBusinessOutcome(event: Parameters<ViraClient['outcome']>[0], options?: {
298
+ idempotencyKey?: string;
299
+ }): Promise<ViraResponse<ClientBody> | null>;
300
+ recordUserFeedback(event: Parameters<ViraClient['feedback']>[0], options?: {
301
+ idempotencyKey?: string;
302
+ }): Promise<ViraResponse<ClientBody> | null>;
283
303
  observeBatch(events: readonly (ClientObservationScope & {
284
304
  eventId: string;
285
305
  eventType: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryvira/sdk",
3
- "version": "0.1.66",
3
+ "version": "0.1.68",
4
4
  "description": "Typed Vira SDK for connect-once, observation and governed runtime execution.",
5
5
  "keywords": ["vira", "ai-governance", "ai-runtime", "semantic-routing"],
6
6
  "engines": {"node": ">=20"},