@tryvira/sdk 0.1.56 → 0.1.58
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/host-lifecycle.d.ts +5 -0
- package/dist/index.js +27 -7
- package/dist/js-client.d.ts +10 -0
- package/package.json +1 -1
package/dist/host-lifecycle.d.ts
CHANGED
|
@@ -28,6 +28,11 @@ export interface HostModelRequest extends HostSessionIdentity {
|
|
|
28
28
|
traceId?: string;
|
|
29
29
|
turnId?: string;
|
|
30
30
|
sequence?: number;
|
|
31
|
+
signalAttestationRefs?: readonly {
|
|
32
|
+
stableKey: string;
|
|
33
|
+
mappingId: string;
|
|
34
|
+
eventId: string;
|
|
35
|
+
}[];
|
|
31
36
|
}
|
|
32
37
|
export interface HostToolProposal extends HostSessionIdentity {
|
|
33
38
|
requestId: string;
|
package/dist/index.js
CHANGED
|
@@ -430,7 +430,8 @@ var ViraClient = class {
|
|
|
430
430
|
body: {
|
|
431
431
|
...input.behaviorPoint ? { behaviorPoint: input.behaviorPoint } : {},
|
|
432
432
|
...input.executionBoundary ? { executionBoundary: input.executionBoundary } : {},
|
|
433
|
-
...input.semanticContext ? { semanticContext: input.semanticContext } : {}
|
|
433
|
+
...input.semanticContext ? { semanticContext: input.semanticContext } : {},
|
|
434
|
+
...input.signalAttestationRefs ? { signalAttestationRefs: input.signalAttestationRefs } : {}
|
|
434
435
|
}
|
|
435
436
|
},
|
|
436
437
|
{
|
|
@@ -479,11 +480,12 @@ var ViraClient = class {
|
|
|
479
480
|
behaviorPoint,
|
|
480
481
|
capsule: firstCapsule,
|
|
481
482
|
...input.requestId ? { requestId: input.requestId } : {},
|
|
482
|
-
...input.sessionId ? { conversationId: input.sessionId } : {}
|
|
483
|
+
...input.sessionId ? { conversationId: input.sessionId } : {},
|
|
484
|
+
...input.signalAttestationRefs ? { signalAttestationRefs: input.signalAttestationRefs } : {}
|
|
483
485
|
},
|
|
484
486
|
idempotencyKey: input.idempotencyKey ? `sdk:runtime:${input.idempotencyKey}` : void 0
|
|
485
487
|
}) : await this.resolveRuntime({
|
|
486
|
-
semanticContext: { taskKey: receipt.taskKey, behaviorPoint, capsule: firstCapsule, ...input.requestId ? { requestId: input.requestId } : {}, ...input.sessionId ? { conversationId: input.sessionId } : {} },
|
|
488
|
+
semanticContext: { taskKey: receipt.taskKey, behaviorPoint, capsule: firstCapsule, ...input.requestId ? { requestId: input.requestId } : {}, ...input.sessionId ? { conversationId: input.sessionId } : {}, ...input.signalAttestationRefs ? { signalAttestationRefs: input.signalAttestationRefs } : {} },
|
|
487
489
|
idempotencyKey: input.idempotencyKey ? `sdk:runtime:${input.idempotencyKey}` : void 0
|
|
488
490
|
});
|
|
489
491
|
return { semantic, runtime };
|
|
@@ -1286,6 +1288,7 @@ function createViraHostRuntime(client, config) {
|
|
|
1286
1288
|
let connected = null;
|
|
1287
1289
|
let connectionIdentity = null;
|
|
1288
1290
|
const projections = /* @__PURE__ */ new Map();
|
|
1291
|
+
const activeToolSessions = /* @__PURE__ */ new Set();
|
|
1289
1292
|
const connectOnce = async () => {
|
|
1290
1293
|
if (mode === "off" || !config.connect) return null;
|
|
1291
1294
|
if (!connected) connected = withTimeout(client.connectOnce(config.connect), timeoutMs, "SDK_HOST_CONNECT_TIMEOUT").then((result) => {
|
|
@@ -1306,7 +1309,7 @@ function createViraHostRuntime(client, config) {
|
|
|
1306
1309
|
if (mode === "off") return { status: "off" };
|
|
1307
1310
|
if (!capabilities.canInjectContext) return { status: "unavailable", reasonCode: "HOST_CONTEXT_INJECTION_UNSUPPORTED" };
|
|
1308
1311
|
await connectOnce();
|
|
1309
|
-
const semantic = await withTimeout(client.resolveSemanticRuntime({ input: request.input, sessionId: request.sessionId ?? request.conversationId, requestId: request.requestId }), timeoutMs, "SDK_HOST_RESOLVE_TIMEOUT");
|
|
1312
|
+
const semantic = await withTimeout(client.resolveSemanticRuntime({ input: request.input, sessionId: request.sessionId ?? request.conversationId, requestId: request.requestId, signalAttestationRefs: request.signalAttestationRefs }), timeoutMs, "SDK_HOST_RESOLVE_TIMEOUT");
|
|
1310
1313
|
if (!semantic) return { status: "unavailable", reasonCode: "VIRA_SEMANTIC_UNAVAILABLE" };
|
|
1311
1314
|
const semanticBody = bodyOf(semantic.semantic);
|
|
1312
1315
|
const receipt = semanticBody.receipt && typeof semanticBody.receipt === "object" ? semanticBody.receipt : {};
|
|
@@ -1328,24 +1331,40 @@ function createViraHostRuntime(client, config) {
|
|
|
1328
1331
|
nonEmpty(proposal.callId, "SDK_HOST_TOOL_CALL_ID_REQUIRED");
|
|
1329
1332
|
nonEmpty(proposal.toolName, "SDK_HOST_TOOL_NAME_REQUIRED");
|
|
1330
1333
|
if (mode !== "enforce") return { decision: "ABSTAIN", reasonCode: mode === "off" ? "HOST_MODE_OFF" : "OBSERVE_ONLY" };
|
|
1334
|
+
const toolSessionKey = `${proposal.organizationId}:${proposal.projectId}:${proposal.environmentId}:${proposal.conversationId}:${proposal.sessionId ?? proposal.conversationId}`;
|
|
1335
|
+
if (activeToolSessions.has(toolSessionKey)) return { decision: "BLOCK", reasonCode: "SDK_HOST_TOOL_IN_FLIGHT" };
|
|
1336
|
+
activeToolSessions.add(toolSessionKey);
|
|
1331
1337
|
let decision;
|
|
1332
1338
|
try {
|
|
1333
1339
|
const authorized = await withTimeout(Promise.resolve(config.authorizeAction(proposal)), timeoutMs, "SDK_HOST_ACTION_AUTHORIZATION_TIMEOUT");
|
|
1334
1340
|
const authorizedBody = bodyOf(authorized);
|
|
1335
1341
|
decision = typeof authorizedBody.decision === "string" ? authorizedBody : authorized;
|
|
1336
1342
|
} catch {
|
|
1343
|
+
activeToolSessions.delete(toolSessionKey);
|
|
1337
1344
|
return { decision: "ERROR", reasonCode: "VIRA_ACTION_AUTHORIZATION_TIMEOUT" };
|
|
1338
1345
|
}
|
|
1339
|
-
if (!decision || !["ALLOW", "BLOCK", "ESCALATE", "ABSTAIN", "ERROR"].includes(decision.decision))
|
|
1340
|
-
|
|
1346
|
+
if (!decision || !["ALLOW", "BLOCK", "ESCALATE", "ABSTAIN", "ERROR"].includes(decision.decision)) {
|
|
1347
|
+
activeToolSessions.delete(toolSessionKey);
|
|
1348
|
+
throw new Error("SDK_HOST_ACTION_DECISION_INVALID");
|
|
1349
|
+
}
|
|
1350
|
+
if (decision.decision !== "ALLOW") activeToolSessions.delete(toolSessionKey);
|
|
1351
|
+
if (decision.decision === "ALLOW" && !isAllow(decision)) {
|
|
1352
|
+
activeToolSessions.delete(toolSessionKey);
|
|
1353
|
+
throw new Error("SDK_HOST_ALLOW_RECEIPT_INVALID");
|
|
1354
|
+
}
|
|
1341
1355
|
return decision;
|
|
1342
1356
|
};
|
|
1343
1357
|
const afterTool = async (result) => {
|
|
1344
1358
|
nonEmpty(result.callId, "SDK_HOST_TOOL_CALL_ID_REQUIRED");
|
|
1345
1359
|
if (mode === "off" || !capabilities.canInspectToolAfter) return { status: "off" };
|
|
1360
|
+
const toolSessionKey = `${result.organizationId}:${result.projectId}:${result.environmentId}:${result.conversationId}:${result.sessionId ?? result.conversationId}`;
|
|
1346
1361
|
const observedResult = result.ok ? result.result : { errorCode: result.errorCode ?? "HOST_TOOL_FAILED" };
|
|
1347
1362
|
const evidence = { abi: "vira.host-tool-evidence.v1", eventId: result.callId, callId: result.callId, toolName: result.toolName, argumentsDigest: digest(result.args), resultDigest: result.resultDigest ?? digest(observedResult), outcome: result.ok ? "success" : "failure", ...result.authorityReceiptDigest ? { authorityReceiptDigest: result.authorityReceiptDigest } : {}, ...result.decisionDigest ? { decisionDigest: result.decisionDigest } : {}, requestId: result.requestId, conversationId: result.conversationId, ...result.sessionId ? { sessionId: result.sessionId } : {}, ...result.turnId ? { turnId: result.turnId } : {} };
|
|
1348
|
-
|
|
1363
|
+
try {
|
|
1364
|
+
return await withTimeout(client.observe({ eventId: result.callId, eventType: result.ok ? "tool.result" : "tool.failed", aiSystemId: result.aiSystemId, connectionId: result.connectionId, organizationId: result.organizationId, projectId: result.projectId, environmentId: result.environmentId, conversationId: result.conversationId, requestId: result.requestId, traceId: result.traceId, payload: { result: observedResult, evidence }, resultDigest: evidence.resultDigest }), timeoutMs, "SDK_HOST_OBSERVE_TIMEOUT");
|
|
1365
|
+
} finally {
|
|
1366
|
+
activeToolSessions.delete(toolSessionKey);
|
|
1367
|
+
}
|
|
1349
1368
|
};
|
|
1350
1369
|
const executeTool = async (input) => {
|
|
1351
1370
|
if (!input || typeof input !== "object" || typeof input.execute !== "function") throw new Error("SDK_GOVERNED_TOOL_EXECUTION_REQUIRED");
|
|
@@ -1366,6 +1385,7 @@ function createViraHostRuntime(client, config) {
|
|
|
1366
1385
|
};
|
|
1367
1386
|
const endSession = (identity) => {
|
|
1368
1387
|
projections.delete(sessionKey({ ...identity, requestId: "session-end", input: "" }));
|
|
1388
|
+
activeToolSessions.delete(`${identity.organizationId}:${identity.projectId}:${identity.environmentId}:${identity.conversationId}:${identity.sessionId ?? identity.conversationId}`);
|
|
1369
1389
|
};
|
|
1370
1390
|
return Object.freeze({ mode, capabilities, connectOnce, getConnectionIdentity: () => connectionIdentity, beforeModel, beforeTool, afterTool, executeTool, endSession, getProjection: (identity) => projections.get(sessionKey({ ...identity, requestId: "projection", input: "" })), supportsPostModelVerification: capabilities.canInterceptResponseBeforeDisplay });
|
|
1371
1391
|
}
|
package/dist/js-client.d.ts
CHANGED
|
@@ -339,6 +339,11 @@ export declare class ViraClient {
|
|
|
339
339
|
behaviorPoint?: string;
|
|
340
340
|
executionBoundary?: Record<string, unknown>;
|
|
341
341
|
semanticContext?: Record<string, unknown>;
|
|
342
|
+
signalAttestationRefs?: readonly {
|
|
343
|
+
stableKey: string;
|
|
344
|
+
mappingId: string;
|
|
345
|
+
eventId: string;
|
|
346
|
+
}[];
|
|
342
347
|
idempotencyKey?: string;
|
|
343
348
|
}): Promise<ViraResponse<RuntimeResolution> | null>;
|
|
344
349
|
/** Resolve a runtime route from a governed execution boundary and semantic context. */
|
|
@@ -365,6 +370,11 @@ export declare class ViraClient {
|
|
|
365
370
|
timeoutMs?: number;
|
|
366
371
|
requestId?: string;
|
|
367
372
|
executionBoundary?: Record<string, unknown>;
|
|
373
|
+
signalAttestationRefs?: readonly {
|
|
374
|
+
stableKey: string;
|
|
375
|
+
mappingId: string;
|
|
376
|
+
eventId: string;
|
|
377
|
+
}[];
|
|
368
378
|
idempotencyKey?: string;
|
|
369
379
|
}): Promise<{
|
|
370
380
|
semantic: ViraResponse<ClientBody>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryvira/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.58",
|
|
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"},
|