@tryvira/sdk 0.1.40 → 0.1.43

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
@@ -7,7 +7,7 @@ approved behavior, and resolve it at runtime.
7
7
  ## Install
8
8
 
9
9
  ```bash
10
- npm install @tryvira/sdk@0.1.31
10
+ npm install @tryvira/sdk@0.1.43
11
11
  ```
12
12
 
13
13
  Configure the organization, project, and environment for every request. Keep the API
@@ -48,6 +48,7 @@ const connected = await vira.connectOnce({
48
48
  });
49
49
 
50
50
  await vira.observe({
51
+ ...scope,
51
52
  eventId: randomUUID(),
52
53
  eventType: "model.response",
53
54
  aiSystemId: String(connected.body.system.id),
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // ../../sdks/js-client.ts
1
+ // sdks/js-client.ts
2
2
  var ViraApiError = class extends Error {
3
3
  status;
4
4
  body;
@@ -15,6 +15,31 @@ var required = (value, code) => {
15
15
  if (typeof value !== "string" || !value.trim()) throw new Error(code);
16
16
  return value;
17
17
  };
18
+ var normalizeBaseUrl = (value, allowInsecureLocalhost = false) => {
19
+ let url;
20
+ try {
21
+ url = new URL(required(value, "SDK_BASE_URL_REQUIRED"));
22
+ } catch {
23
+ throw new Error("SDK_BASE_URL_INVALID");
24
+ }
25
+ const hostname = url.hostname.toLowerCase();
26
+ const loopback = hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
27
+ if (url.username || url.password || url.search || url.hash) throw new Error("SDK_BASE_URL_INVALID");
28
+ if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback && allowInsecureLocalhost))
29
+ throw new Error("SDK_HTTPS_REQUIRED");
30
+ return value.replace(/\/$/, "");
31
+ };
32
+ var canonicalJson = (value) => JSON.stringify(
33
+ value,
34
+ (_key, item) => item && typeof item === "object" && !Array.isArray(item) ? Object.fromEntries(Object.entries(item).sort(([left], [right]) => left.localeCompare(right))) : item
35
+ );
36
+ var contentIdempotencyKey = async (operation, request) => {
37
+ if (!globalThis.crypto?.subtle) throw new Error("SDK_IDEMPOTENCY_CRYPTO_UNAVAILABLE");
38
+ const bytes = new TextEncoder().encode(canonicalJson(request));
39
+ const digest = await globalThis.crypto.subtle.digest("SHA-256", bytes);
40
+ const hex = [...new Uint8Array(digest)].map((value) => value.toString(16).padStart(2, "0")).join("");
41
+ return `${operation}:${hex}`;
42
+ };
18
43
  var wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
19
44
  var ViraClient = class {
20
45
  evaluations;
@@ -28,10 +53,7 @@ var ViraClient = class {
28
53
  failureMode;
29
54
  defaultHeaders;
30
55
  constructor(options) {
31
- this.baseUrl = required(options.baseUrl, "SDK_BASE_URL_REQUIRED").replace(
32
- /\/$/,
33
- ""
34
- );
56
+ this.baseUrl = normalizeBaseUrl(options.baseUrl, options.allowInsecureLocalhost === true);
35
57
  this.apiKey = options.apiKey;
36
58
  this.fetcher = options.fetcher ?? fetch;
37
59
  this.timeoutMs = Math.max(
@@ -139,13 +161,15 @@ var ViraClient = class {
139
161
  listAISystems() {
140
162
  return this.request({ method: "GET", path: "/v1/ai-systems" });
141
163
  }
142
- deleteAISystem(systemId, options = {}) {
164
+ async deleteAISystem(systemId, options = {}) {
143
165
  required(systemId, "SDK_SYSTEM_ID_REQUIRED");
144
- return this.request({ method: "DELETE", path: `/v1/ai-systems/${encodeURIComponent(systemId)}`, body: { confirm: options.confirm === true } }, { idempotencyKey: options.idempotencyKey ?? `sdk:delete:ai-system:${systemId}` });
166
+ const path = `/v1/ai-systems/${encodeURIComponent(systemId)}`, body = { confirm: options.confirm === true };
167
+ return this.request({ method: "DELETE", path, body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:delete:ai-system:${systemId}`, { path, body }) });
145
168
  }
146
- deleteAISystemCascade(systemId, options = {}) {
169
+ async deleteAISystemCascade(systemId, options = {}) {
147
170
  required(systemId, "SDK_SYSTEM_ID_REQUIRED");
148
- return this.request({ method: "DELETE", path: `/v1/ai-systems/${encodeURIComponent(systemId)}/cleanup`, body: { confirm: options.confirm === true, deleteObservations: options.deleteObservations === true } }, { idempotencyKey: options.idempotencyKey ?? `sdk:delete:ai-system-cascade:${systemId}` });
171
+ const path = `/v1/ai-systems/${encodeURIComponent(systemId)}/cleanup`, body = { confirm: options.confirm === true, deleteObservations: options.deleteObservations === true };
172
+ return this.request({ method: "DELETE", path, body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:delete:ai-system-cascade:${systemId}`, { path, body }) });
149
173
  }
150
174
  getAISystem(systemId) {
151
175
  required(systemId, "SDK_SYSTEM_ID_REQUIRED");
@@ -212,6 +236,8 @@ var ViraClient = class {
212
236
  observeBatch(events, options = {}) {
213
237
  if (!Array.isArray(events) || events.length < 1 || events.length > 100)
214
238
  throw new Error("SDK_OBSERVATION_BATCH_INVALID");
239
+ if (events.some((event) => !event.organizationId?.trim() || !event.projectId?.trim() || !event.environmentId?.trim()))
240
+ throw new Error("SDK_OBSERVATION_SCOPE_REQUIRED");
215
241
  return this.request(
216
242
  {
217
243
  method: "POST",
@@ -234,27 +260,30 @@ var ViraClient = class {
234
260
  query: reviewState ? { reviewState } : void 0
235
261
  });
236
262
  }
237
- createSignalDiscoveryProposal(input, options = {}) {
238
- return this.request({ method: "POST", path: "/v1/signals/discovery-proposals", body: input }, { idempotencyKey: options.idempotencyKey ?? String(input.signalStableKey ?? "") });
263
+ async createSignalDiscoveryProposal(input, options = {}) {
264
+ return this.request({ method: "POST", path: "/v1/signals/discovery-proposals", body: input }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey("sdk:signal-discovery-proposal", input) });
239
265
  }
240
- reviewSignalDiscoveryProposal(proposalId, decision, options = {}) {
266
+ async reviewSignalDiscoveryProposal(proposalId, decision, options = {}) {
241
267
  required(proposalId, "SDK_SIGNAL_PROPOSAL_ID_REQUIRED");
242
- return this.request({ method: "POST", path: `/v1/signals/discovery-proposals/${encodeURIComponent(proposalId)}/review`, body: { decision } }, { idempotencyKey: options.idempotencyKey ?? `signal-review:${proposalId}` });
268
+ const path = `/v1/signals/discovery-proposals/${encodeURIComponent(proposalId)}/review`, body = { decision };
269
+ return this.request({ method: "POST", path, body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`signal-review:${proposalId}`, body) });
243
270
  }
244
- materializeSignalDiscovery(proposalId, input = {}, options = {}) {
271
+ async materializeSignalDiscovery(proposalId, input = {}, options = {}) {
245
272
  required(proposalId, "SDK_SIGNAL_PROPOSAL_ID_REQUIRED");
246
- return this.request({ method: "POST", path: `/v1/signals/discovery-proposals/${encodeURIComponent(proposalId)}/materialize`, body: input }, { idempotencyKey: options.idempotencyKey ?? `signal-materialize:${proposalId}` });
273
+ const path = `/v1/signals/discovery-proposals/${encodeURIComponent(proposalId)}/materialize`;
274
+ return this.request({ method: "POST", path, body: input }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`signal-materialize:${proposalId}`, input) });
247
275
  }
248
- createSignalMapping(input, options = {}) {
249
- return this.request({ method: "POST", path: "/v1/signals/mappings", body: input }, { idempotencyKey: options.idempotencyKey ?? String(input.signalStableKey ?? "") });
276
+ async createSignalMapping(input, options = {}) {
277
+ return this.request({ method: "POST", path: "/v1/signals/mappings", body: input }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey("sdk:signal-mapping", input) });
250
278
  }
251
279
  getSignalMapping(mappingId) {
252
280
  required(mappingId, "SDK_SIGNAL_MAPPING_ID_REQUIRED");
253
281
  return this.request({ method: "GET", path: `/v1/signals/mappings/${encodeURIComponent(mappingId)}` });
254
282
  }
255
- reviewSignalMapping(mappingId, input = {}, options = {}) {
283
+ async reviewSignalMapping(mappingId, input = {}, options = {}) {
256
284
  required(mappingId, "SDK_SIGNAL_MAPPING_ID_REQUIRED");
257
- return this.request({ method: "POST", path: `/v1/signals/mappings/${encodeURIComponent(mappingId)}/review`, body: input }, { idempotencyKey: options.idempotencyKey ?? `signal-mapping-review:${mappingId}` });
285
+ const path = `/v1/signals/mappings/${encodeURIComponent(mappingId)}/review`;
286
+ return this.request({ method: "POST", path, body: input }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`signal-mapping-review:${mappingId}`, input) });
258
287
  }
259
288
  connectionHealth(connectionId) {
260
289
  required(connectionId, "SDK_CONNECTION_ID_REQUIRED");
@@ -290,48 +319,48 @@ var ViraClient = class {
290
319
  path: "/v1/packs"
291
320
  });
292
321
  }
293
- importPack(input) {
322
+ async deletePack(packId, options = {}) {
323
+ required(packId, "SDK_PACK_ID_REQUIRED");
324
+ const path = `/v1/packs/${encodeURIComponent(packId)}`;
325
+ const body = { confirm: options.confirm === true };
326
+ return this.request({ method: "DELETE", path, body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:delete:pack:${packId}`, { path, body }) });
327
+ }
328
+ async importPack(input) {
294
329
  if (!input?.manifest && !input?.archiveBase64)
295
330
  throw new Error("SDK_PACK_MANIFEST_OR_ARCHIVE_REQUIRED");
296
331
  if (input.archiveBase64 && !input.fileName)
297
332
  throw new Error("SDK_PACK_FILE_NAME_REQUIRED");
333
+ const body = {
334
+ ...input.manifest ? { manifest: input.manifest } : {},
335
+ objects: input.objects ?? {},
336
+ ...input.archiveBase64 ? { archiveBase64: input.archiveBase64, fileName: input.fileName } : {}
337
+ };
298
338
  return this.request(
299
339
  {
300
340
  method: "POST",
301
341
  path: "/v1/packs/import",
302
- body: {
303
- ...input.manifest ? { manifest: input.manifest } : {},
304
- objects: input.objects ?? {},
305
- ...input.archiveBase64 ? { archiveBase64: input.archiveBase64, fileName: input.fileName } : {}
306
- }
342
+ body
307
343
  },
308
- { idempotencyKey: input.idempotencyKey ?? `sdk:pack:${Date.now()}` }
344
+ { idempotencyKey: input.idempotencyKey ?? await contentIdempotencyKey("sdk:pack:import", body) }
309
345
  );
310
346
  }
311
- installPack(packId, variables = {}) {
347
+ async installPack(packId, variables = {}) {
312
348
  required(packId, "SDK_PACK_ID_REQUIRED");
349
+ const path = `/v1/packs/${encodeURIComponent(packId)}/install`;
350
+ const body = { variables };
313
351
  return this.request(
314
- {
315
- method: "POST",
316
- path: `/v1/packs/${encodeURIComponent(packId)}/install`,
317
- body: { variables }
318
- },
319
- { idempotencyKey: `sdk:pack:install:${packId}` }
352
+ { method: "POST", path, body },
353
+ { idempotencyKey: await contentIdempotencyKey(`sdk:pack:install:${packId}`, body) }
320
354
  );
321
355
  }
322
- evaluatePack(packId, input) {
356
+ async evaluatePack(packId, input) {
323
357
  required(packId, "SDK_PACK_ID_REQUIRED");
324
358
  required(input?.evaluationId, "SDK_EVALUATION_ID_REQUIRED");
325
- return this.request(
326
- {
327
- method: "POST",
328
- path: `/v1/packs/${encodeURIComponent(packId)}/evaluate`,
329
- body: { evaluationId: input.evaluationId }
330
- },
331
- { idempotencyKey: `sdk:pack:evaluate:${packId}` }
332
- );
359
+ const path = `/v1/packs/${encodeURIComponent(packId)}/evaluate`;
360
+ const body = { evaluationId: input.evaluationId };
361
+ return this.request({ method: "POST", path, body }, { idempotencyKey: await contentIdempotencyKey(`sdk:pack:evaluate:${packId}`, body) });
333
362
  }
334
- approvePack(packId, options = {}) {
363
+ async approvePack(packId, options = {}) {
335
364
  required(packId, "SDK_PACK_ID_REQUIRED");
336
365
  const body = options.manualApproval ? { manualApproval: true, reason: required(options.reason ?? "", "SDK_MANUAL_PACK_APPROVAL_REASON_REQUIRED") } : {};
337
366
  return this.request(
@@ -340,10 +369,10 @@ var ViraClient = class {
340
369
  path: `/v1/packs/${encodeURIComponent(packId)}/approve`,
341
370
  body
342
371
  },
343
- { idempotencyKey: `sdk:pack:approve:${packId}` }
372
+ { idempotencyKey: await contentIdempotencyKey(`sdk:pack:approve:${packId}`, body) }
344
373
  );
345
374
  }
346
- releasePack(packId) {
375
+ async releasePack(packId) {
347
376
  required(packId, "SDK_PACK_ID_REQUIRED");
348
377
  return this.request(
349
378
  {
@@ -351,10 +380,10 @@ var ViraClient = class {
351
380
  path: `/v1/packs/${encodeURIComponent(packId)}/release`,
352
381
  body: {}
353
382
  },
354
- { idempotencyKey: `sdk:pack:release:${packId}` }
383
+ { idempotencyKey: await contentIdempotencyKey(`sdk:pack:release:${packId}`, {}) }
355
384
  );
356
385
  }
357
- previewPackUpgrade(packId, incoming) {
386
+ async previewPackUpgrade(packId, incoming) {
358
387
  required(packId, "SDK_PACK_ID_REQUIRED");
359
388
  if (!incoming || typeof incoming !== "object")
360
389
  throw new Error("SDK_PACK_UPGRADE_INPUT_REQUIRED");
@@ -364,7 +393,7 @@ var ViraClient = class {
364
393
  path: `/v1/packs/${encodeURIComponent(packId)}/upgrade-preview`,
365
394
  body: { incoming }
366
395
  },
367
- { idempotencyKey: `sdk:pack:upgrade-preview:${packId}` }
396
+ { idempotencyKey: await contentIdempotencyKey(`sdk:pack:upgrade-preview:${packId}`, { incoming }) }
368
397
  );
369
398
  }
370
399
  executeRuntime(input) {
@@ -451,9 +480,10 @@ var ViraClient = class {
451
480
  path: "/v1/behavior-strategies"
452
481
  });
453
482
  }
454
- deleteBehaviorStrategy(strategyId, options = {}) {
483
+ async deleteBehaviorStrategy(strategyId, options = {}) {
455
484
  required(strategyId, "SDK_STRATEGY_ID_REQUIRED");
456
- return this.request({ method: "DELETE", path: `/v1/behavior-strategies/${encodeURIComponent(strategyId)}`, body: { confirm: options.confirm === true } }, { idempotencyKey: options.idempotencyKey ?? `sdk:delete:strategy:${strategyId}` });
485
+ const path = `/v1/behavior-strategies/${encodeURIComponent(strategyId)}`, body = { confirm: options.confirm === true };
486
+ return this.request({ method: "DELETE", path, body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:delete:strategy:${strategyId}`, { path, body }) });
457
487
  }
458
488
  getBehaviorStrategy(strategyId) {
459
489
  required(strategyId, "SDK_STRATEGY_ID_REQUIRED");
@@ -473,25 +503,29 @@ var ViraClient = class {
473
503
  listSemanticTasks() {
474
504
  return this.request({ method: "GET", path: "/v1/semantic-tasks" });
475
505
  }
476
- deleteSemanticTask(taskId, options = {}) {
506
+ async deleteSemanticTask(taskId, options = {}) {
477
507
  required(taskId, "SDK_SEMANTIC_TASK_ID_REQUIRED");
478
- return this.request({ method: "DELETE", path: `/v1/semantic-tasks/${encodeURIComponent(taskId)}`, body: { confirm: options.confirm === true } }, { idempotencyKey: options.idempotencyKey ?? `sdk:delete:semantic-task:${taskId}` });
508
+ const path = `/v1/semantic-tasks/${encodeURIComponent(taskId)}`, body = { confirm: options.confirm === true };
509
+ return this.request({ method: "DELETE", path, body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:delete:semantic-task:${taskId}`, { path, body }) });
479
510
  }
480
- createSemanticTask(task, options = {}) {
511
+ async createSemanticTask(task, options = {}) {
481
512
  required(task?.taskKey, "SDK_SEMANTIC_TASK_KEY_REQUIRED");
482
- return this.request({ method: "POST", path: "/v1/semantic-tasks", body: { ...task, ...options.id ? { id: options.id } : {} } }, { idempotencyKey: options.idempotencyKey ?? `sdk:semantic-task:${task.taskKey}` });
513
+ const body = { ...task, ...options.id ? { id: options.id } : {} };
514
+ return this.request({ method: "POST", path: "/v1/semantic-tasks", body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:semantic-task:${task.taskKey}`, body) });
483
515
  }
484
516
  listBehaviorPoints() {
485
517
  return this.request({ method: "GET", path: "/v1/behavior-points" });
486
518
  }
487
- deleteBehaviorPoint(pointId, options = {}) {
519
+ async deleteBehaviorPoint(pointId, options = {}) {
488
520
  required(pointId, "SDK_BEHAVIOR_POINT_ID_REQUIRED");
489
- return this.request({ method: "DELETE", path: `/v1/behavior-points/${encodeURIComponent(pointId)}`, body: { confirm: options.confirm === true } }, { idempotencyKey: options.idempotencyKey ?? `sdk:delete:behavior-point:${pointId}` });
521
+ const path = `/v1/behavior-points/${encodeURIComponent(pointId)}`, body = { confirm: options.confirm === true };
522
+ return this.request({ method: "DELETE", path, body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:delete:behavior-point:${pointId}`, { path, body }) });
490
523
  }
491
- createBehaviorPoint(point, options = {}) {
524
+ async createBehaviorPoint(point, options = {}) {
492
525
  required(point?.key, "SDK_BEHAVIOR_POINT_KEY_REQUIRED");
493
526
  if (!point.taskId && !point.taskIds?.length) throw new Error("SDK_BEHAVIOR_POINT_TASK_REQUIRED");
494
- return this.request({ method: "POST", path: "/v1/behavior-points", body: { ...point, ...options.id ? { id: options.id } : {} } }, { idempotencyKey: options.idempotencyKey ?? `sdk:behavior-point:${point.key}` });
527
+ const body = { ...point, ...options.id ? { id: options.id } : {} };
528
+ return this.request({ method: "POST", path: "/v1/behavior-points", body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:behavior-point:${point.key}`, body) });
495
529
  }
496
530
  createBehaviorStrategyVariant(strategyId, variant, options = {}) {
497
531
  required(strategyId, "SDK_STRATEGY_ID_REQUIRED");
@@ -611,13 +645,15 @@ var ViraClient = class {
611
645
  path: `/v1/behavior-programs/${encodeURIComponent(programId)}`
612
646
  });
613
647
  }
614
- deleteBehaviorProgram(programId, options = {}) {
648
+ async deleteBehaviorProgram(programId, options = {}) {
615
649
  required(programId, "SDK_PROGRAM_ID_REQUIRED");
616
- return this.request({ method: "DELETE", path: `/v1/behavior-programs/${encodeURIComponent(programId)}`, body: { confirm: options.confirm === true } }, { idempotencyKey: options.idempotencyKey ?? `sdk:delete:behavior-program:${programId}` });
650
+ const path = `/v1/behavior-programs/${encodeURIComponent(programId)}`, body = { confirm: options.confirm === true };
651
+ return this.request({ method: "DELETE", path, body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:delete:behavior-program:${programId}`, { path, body }) });
617
652
  }
618
- deleteBehaviorProgramCascade(programId, options = {}) {
653
+ async deleteBehaviorProgramCascade(programId, options = {}) {
619
654
  required(programId, "SDK_PROGRAM_ID_REQUIRED");
620
- return this.request({ method: "DELETE", path: `/v1/behavior-programs/${encodeURIComponent(programId)}/cascade`, body: { confirm: options.confirm === true, purgeRuntime: options.purgeRuntime === true } }, { idempotencyKey: options.idempotencyKey ?? `sdk:delete:behavior-program-cascade:${programId}` });
655
+ const path = `/v1/behavior-programs/${encodeURIComponent(programId)}/cascade`, body = { confirm: options.confirm === true, purgeRuntime: options.purgeRuntime === true };
656
+ return this.request({ method: "DELETE", path, body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:delete:behavior-program-cascade:${programId}`, { path, body }) });
621
657
  }
622
658
  createBehaviorProgram(program, options = {}) {
623
659
  if (!program || typeof program !== "object")
@@ -892,31 +928,35 @@ var ViraClient = class {
892
928
  { idempotencyKey: options.idempotencyKey }
893
929
  );
894
930
  }
895
- compileBehaviorCapsule(input) {
931
+ async compileBehaviorCapsule(input) {
896
932
  required(input.programId, "SDK_PROGRAM_ID_REQUIRED");
897
933
  required(input.input, "SDK_RUNTIME_INPUT_REQUIRED");
934
+ const body = { ...input };
898
935
  return this.request(
899
936
  {
900
937
  method: "POST",
901
938
  path: "/v1/runtime/behavior-capsule",
902
- body: { ...input }
939
+ body
903
940
  },
904
941
  {
905
- idempotencyKey: input.idempotencyKey ?? `sdk:capsule:${input.programId}`
942
+ idempotencyKey: input.idempotencyKey ?? await contentIdempotencyKey(`sdk:capsule:${input.programId}`, body),
943
+ enforcing: true
906
944
  }
907
945
  );
908
946
  }
909
- serveBehaviorProjection(input) {
947
+ async serveBehaviorProjection(input) {
910
948
  required(input.input, "SDK_RUNTIME_INPUT_REQUIRED");
911
949
  required(input.provider, "SDK_PROVIDER_REQUIRED");
950
+ const body = { ...input };
912
951
  return this.request(
913
952
  {
914
953
  method: "POST",
915
954
  path: "/v1/runtime/behavior-projection",
916
- body: { ...input }
955
+ body
917
956
  },
918
957
  {
919
- idempotencyKey: input.idempotencyKey ?? `sdk:projection:${input.programId ?? "active"}`
958
+ idempotencyKey: input.idempotencyKey ?? await contentIdempotencyKey(`sdk:projection:${input.programId ?? "active"}`, body),
959
+ enforcing: true
920
960
  }
921
961
  );
922
962
  }
@@ -1024,6 +1064,8 @@ function buildAISystemRequest(input) {
1024
1064
  });
1025
1065
  }
1026
1066
  function buildObservationRequest(event) {
1067
+ if (!event?.organizationId?.trim() || !event?.projectId?.trim() || !event?.environmentId?.trim())
1068
+ throw new Error("SDK_OBSERVATION_SCOPE_REQUIRED");
1027
1069
  if (!event?.eventId || !event.eventType || !event.aiSystemId || !event.connectionId)
1028
1070
  throw new Error("SDK_OBSERVATION_FIELD_REQUIRED");
1029
1071
  return Object.freeze({
@@ -16,6 +16,8 @@ export interface SdkRequest {
16
16
  export type SdkFailureMode = "throw" | "open";
17
17
  export interface ViraClientOptions {
18
18
  baseUrl: string;
19
+ /** Explicit opt-in for plain HTTP on loopback during local development only. */
20
+ allowInsecureLocalhost?: boolean;
19
21
  apiKey?: string;
20
22
  fetcher?: typeof fetch;
21
23
  timeoutMs?: number;
@@ -105,7 +107,12 @@ export declare class ViraApiError extends Error {
105
107
  constructor(message: string, status: number, body: unknown, requestId: string);
106
108
  }
107
109
  type ClientBody = Record<string, unknown>;
108
- type ClientObservation = {
110
+ type ClientObservationScope = {
111
+ organizationId: string;
112
+ projectId: string;
113
+ environmentId: string;
114
+ };
115
+ type ClientObservation = ClientObservationScope & {
109
116
  eventId: string;
110
117
  eventType: string;
111
118
  aiSystemId: string;
@@ -172,7 +179,7 @@ export declare class ViraClient {
172
179
  observe(event: ClientObservation, options?: {
173
180
  idempotencyKey?: string;
174
181
  }): Promise<ViraResponse<ClientBody> | null>;
175
- trace(event: {
182
+ trace(event: ClientObservationScope & {
176
183
  eventId: string;
177
184
  aiSystemId: string;
178
185
  connectionId: string;
@@ -188,7 +195,7 @@ export declare class ViraClient {
188
195
  query?: string;
189
196
  event?: string;
190
197
  }): Promise<ViraResponse<ClientBody> | null>;
191
- outcome(event: {
198
+ outcome(event: ClientObservationScope & {
192
199
  eventId: string;
193
200
  aiSystemId: string;
194
201
  connectionId: string;
@@ -196,7 +203,7 @@ export declare class ViraClient {
196
203
  }, options?: {
197
204
  idempotencyKey?: string;
198
205
  }): Promise<ViraResponse<ClientBody> | null>;
199
- feedback(event: {
206
+ feedback(event: ClientObservationScope & {
200
207
  eventId: string;
201
208
  aiSystemId: string;
202
209
  connectionId: string;
@@ -204,13 +211,13 @@ export declare class ViraClient {
204
211
  }, options?: {
205
212
  idempotencyKey?: string;
206
213
  }): Promise<ViraResponse<ClientBody> | null>;
207
- observeBatch(events: readonly {
214
+ observeBatch(events: readonly (ClientObservationScope & {
208
215
  eventId: string;
209
216
  eventType: string;
210
217
  aiSystemId: string;
211
218
  connectionId: string;
212
219
  [key: string]: unknown;
213
- }[], options?: {
220
+ })[], options?: {
214
221
  idempotencyKey?: string;
215
222
  }): Promise<ViraResponse<ClientBody> | null>;
216
223
  observeSdk(delivery: ClientBody, options?: {
@@ -242,6 +249,10 @@ export declare class ViraClient {
242
249
  listPacks(): Promise<ViraResponse<{
243
250
  packs: readonly ClientBody[];
244
251
  }> | null>;
252
+ deletePack(packId: string, options?: {
253
+ confirm?: boolean;
254
+ idempotencyKey?: string;
255
+ }): Promise<ViraResponse<ClientBody> | null>;
245
256
  importPack(input: {
246
257
  manifest?: unknown;
247
258
  objects?: Record<string, unknown>;
@@ -576,6 +587,9 @@ export declare function buildAISystemRequest(input: {
576
587
  environmentId: string;
577
588
  }): SdkRequest;
578
589
  export declare function buildObservationRequest(event: {
590
+ organizationId: string;
591
+ projectId: string;
592
+ environmentId: string;
579
593
  eventId: string;
580
594
  eventType: string;
581
595
  aiSystemId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryvira/sdk",
3
- "version": "0.1.40",
3
+ "version": "0.1.43",
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"},