@tryvira/sdk 0.1.51 → 0.1.53
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/framework-adapters.d.ts +34 -0
- package/dist/host-lifecycle.d.ts +4 -0
- package/dist/index.js +27 -4
- package/dist/js-client.d.ts +4 -0
- package/package.json +1 -1
|
@@ -20,6 +20,7 @@ export interface FrameworkObservationAdapter {
|
|
|
20
20
|
observe(event: FrameworkEvent, kind: 'trace' | 'outcome' | 'feedback' | 'observation'): Promise<unknown> | unknown;
|
|
21
21
|
}
|
|
22
22
|
export interface FrameworkLifecycleAdapter extends FrameworkObservationAdapter {
|
|
23
|
+
readonly runtime: FrameworkRuntimeCore;
|
|
23
24
|
resolveBoundary(input: {
|
|
24
25
|
executionBoundary: Record<string, unknown>;
|
|
25
26
|
semanticContext?: Record<string, unknown>;
|
|
@@ -38,6 +39,39 @@ export interface FrameworkLifecycleAdapter extends FrameworkObservationAdapter {
|
|
|
38
39
|
resultDigest?: string;
|
|
39
40
|
}): Promise<unknown> | unknown;
|
|
40
41
|
}
|
|
42
|
+
/** The single framework-independent authority contract. Adapters only translate hooks into this API. */
|
|
43
|
+
export interface FrameworkRuntimeCore {
|
|
44
|
+
resolveBehavior(input: {
|
|
45
|
+
input?: string;
|
|
46
|
+
executionBoundary?: Record<string, unknown>;
|
|
47
|
+
semanticContext?: Record<string, unknown>;
|
|
48
|
+
behaviorPoint?: string;
|
|
49
|
+
sessionId?: string;
|
|
50
|
+
idempotencyKey?: string;
|
|
51
|
+
}): Promise<unknown>;
|
|
52
|
+
authorizeAction(input: {
|
|
53
|
+
executionId: string;
|
|
54
|
+
sessionId: string;
|
|
55
|
+
scope: {
|
|
56
|
+
organizationId: string;
|
|
57
|
+
projectId: string;
|
|
58
|
+
environmentId: string;
|
|
59
|
+
};
|
|
60
|
+
context: Record<string, unknown>;
|
|
61
|
+
proposal: Record<string, unknown>;
|
|
62
|
+
approval?: Record<string, unknown>;
|
|
63
|
+
}): Promise<unknown>;
|
|
64
|
+
recordOutcome(event: FrameworkEvent & {
|
|
65
|
+
outcome?: unknown;
|
|
66
|
+
result?: unknown;
|
|
67
|
+
error?: unknown;
|
|
68
|
+
}): Promise<unknown>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Shared Vira lifecycle. This is intentionally the only place where framework
|
|
72
|
+
* integrations select runtime, authorize effects, or admit outcomes.
|
|
73
|
+
*/
|
|
74
|
+
export declare function createFrameworkRuntimeCore(client: ViraClient): FrameworkRuntimeCore;
|
|
41
75
|
export interface RuntimeHookRequest {
|
|
42
76
|
executionBoundary?: Record<string, unknown>;
|
|
43
77
|
semanticContext?: Record<string, unknown>;
|
package/dist/host-lifecycle.d.ts
CHANGED
|
@@ -42,6 +42,8 @@ export interface HostToolResult extends HostToolProposal {
|
|
|
42
42
|
result?: unknown;
|
|
43
43
|
errorCode?: string;
|
|
44
44
|
resultDigest?: string;
|
|
45
|
+
authorityReceiptDigest?: string;
|
|
46
|
+
decisionDigest?: string;
|
|
45
47
|
}
|
|
46
48
|
export interface HostToolEvidence {
|
|
47
49
|
abi: 'vira.host-tool-evidence.v1';
|
|
@@ -51,6 +53,8 @@ export interface HostToolEvidence {
|
|
|
51
53
|
argumentsDigest: string;
|
|
52
54
|
resultDigest: string;
|
|
53
55
|
outcome: 'success' | 'failure';
|
|
56
|
+
authorityReceiptDigest?: string;
|
|
57
|
+
decisionDigest?: string;
|
|
54
58
|
requestId: string;
|
|
55
59
|
conversationId: string;
|
|
56
60
|
sessionId?: string;
|
package/dist/index.js
CHANGED
|
@@ -360,6 +360,11 @@ var ViraClient = class {
|
|
|
360
360
|
{ idempotencyKey: await contentIdempotencyKey(`sdk:pack:install:${packId}`, body) }
|
|
361
361
|
);
|
|
362
362
|
}
|
|
363
|
+
async diagnosePack(packId, input = {}) {
|
|
364
|
+
required(packId, "SDK_PACK_ID_REQUIRED");
|
|
365
|
+
const body = { runtimeBindings: [...input.runtimeBindings ?? []], knownVerifiers: [...input.knownVerifiers ?? []] };
|
|
366
|
+
return this.request({ method: "POST", path: `/v1/packs/${encodeURIComponent(packId)}/doctor`, body }, { idempotencyKey: await contentIdempotencyKey(`sdk:pack:doctor:${packId}`, body) });
|
|
367
|
+
}
|
|
363
368
|
async evaluatePack(packId, input) {
|
|
364
369
|
required(packId, "SDK_PACK_ID_REQUIRED");
|
|
365
370
|
required(input?.evaluationId, "SDK_EVALUATION_ID_REQUIRED");
|
|
@@ -1138,6 +1143,21 @@ function buildObservationRequest(event) {
|
|
|
1138
1143
|
}
|
|
1139
1144
|
|
|
1140
1145
|
// ../../sdks/framework-adapters.ts
|
|
1146
|
+
function createFrameworkRuntimeCore(client) {
|
|
1147
|
+
if (!client) throw new Error("SDK_FRAMEWORK_CLIENT_REQUIRED");
|
|
1148
|
+
return Object.freeze({
|
|
1149
|
+
async resolveBehavior(input) {
|
|
1150
|
+
if (input.input?.trim()) return client.resolveSemanticRuntime(input);
|
|
1151
|
+
return client.resolveBoundary({ executionBoundary: input.executionBoundary ?? {}, ...input.semanticContext ? { semanticContext: input.semanticContext } : {}, ...input.idempotencyKey ? { idempotencyKey: input.idempotencyKey } : {} });
|
|
1152
|
+
},
|
|
1153
|
+
async authorizeAction(input) {
|
|
1154
|
+
return client.authorizeHostAction(input);
|
|
1155
|
+
},
|
|
1156
|
+
async recordOutcome(event) {
|
|
1157
|
+
return client.observe({ ...event, eventType: event.eventType ?? "business.outcome" });
|
|
1158
|
+
}
|
|
1159
|
+
});
|
|
1160
|
+
}
|
|
1141
1161
|
async function resolveFrameworkBoundary(client, request) {
|
|
1142
1162
|
if (!request || typeof request !== "object") throw new Error("SDK_RUNTIME_REQUEST_REQUIRED");
|
|
1143
1163
|
const resolution = request.executionBoundary ? await client.resolveBoundary({
|
|
@@ -1188,11 +1208,13 @@ function createFrameworkLifecycleAdapter(client, framework, options = {}) {
|
|
|
1188
1208
|
const mode = options.mode ?? "observe";
|
|
1189
1209
|
if (mode !== "observe" && mode !== "enforce") throw new Error("SDK_FRAMEWORK_MODE_INVALID");
|
|
1190
1210
|
const observation = createFrameworkObservationAdapter(client, framework);
|
|
1211
|
+
const runtime = createFrameworkRuntimeCore(client);
|
|
1191
1212
|
const emit = (event, type) => observation.observe({ ...event, eventType: type }, "observation");
|
|
1192
1213
|
return Object.freeze({
|
|
1193
1214
|
...observation,
|
|
1194
1215
|
mode,
|
|
1195
|
-
|
|
1216
|
+
runtime,
|
|
1217
|
+
resolveBoundary: (input) => runtime.resolveBehavior(input),
|
|
1196
1218
|
start: (event) => emit(event, lifecycleType.start),
|
|
1197
1219
|
complete: (event) => emit(event, lifecycleType.complete),
|
|
1198
1220
|
error: (event) => emit(event, lifecycleType.error),
|
|
@@ -1311,7 +1333,7 @@ function createViraHostRuntime(client, config) {
|
|
|
1311
1333
|
nonEmpty(result.callId, "SDK_HOST_TOOL_CALL_ID_REQUIRED");
|
|
1312
1334
|
if (mode === "off" || !capabilities.canInspectToolAfter) return { status: "off" };
|
|
1313
1335
|
const observedResult = result.ok ? result.result : { errorCode: result.errorCode ?? "HOST_TOOL_FAILED" };
|
|
1314
|
-
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", requestId: result.requestId, conversationId: result.conversationId, ...result.sessionId ? { sessionId: result.sessionId } : {}, ...result.turnId ? { turnId: result.turnId } : {} };
|
|
1336
|
+
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 } : {} };
|
|
1315
1337
|
return 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");
|
|
1316
1338
|
};
|
|
1317
1339
|
const executeTool = async (input) => {
|
|
@@ -1323,11 +1345,11 @@ function createViraHostRuntime(client, config) {
|
|
|
1323
1345
|
try {
|
|
1324
1346
|
const result = await input.execute(proposal.args);
|
|
1325
1347
|
const resultDigest = digest(result);
|
|
1326
|
-
const observation = await afterTool({ ...proposal, ok: true, result, resultDigest });
|
|
1348
|
+
const observation = await afterTool({ ...proposal, ok: true, result, resultDigest, ...decision.authorityReceiptDigest ? { authorityReceiptDigest: decision.authorityReceiptDigest } : {}, ...decision.decisionDigest ? { decisionDigest: decision.decisionDigest } : {} });
|
|
1327
1349
|
return { decision, executed: true, result, observation };
|
|
1328
1350
|
} catch (error) {
|
|
1329
1351
|
const errorCode = error instanceof Error ? error.message : "GOVERNED_TOOL_FAILED";
|
|
1330
|
-
const observation = await afterTool({ ...proposal, ok: false, errorCode, resultDigest: digest({ errorCode }) });
|
|
1352
|
+
const observation = await afterTool({ ...proposal, ok: false, errorCode, resultDigest: digest({ errorCode }), ...decision.authorityReceiptDigest ? { authorityReceiptDigest: decision.authorityReceiptDigest } : {}, ...decision.decisionDigest ? { decisionDigest: decision.decisionDigest } : {} });
|
|
1331
1353
|
throw Object.assign(error instanceof Error ? error : new Error(errorCode), { decision, observation });
|
|
1332
1354
|
}
|
|
1333
1355
|
};
|
|
@@ -1347,6 +1369,7 @@ export {
|
|
|
1347
1369
|
createFrameworkAdapters,
|
|
1348
1370
|
createFrameworkLifecycleAdapter,
|
|
1349
1371
|
createFrameworkObservationAdapter,
|
|
1372
|
+
createFrameworkRuntimeCore,
|
|
1350
1373
|
createGenericHttpHooks,
|
|
1351
1374
|
createGenericRuntimeHooks,
|
|
1352
1375
|
createLangGraphHooks,
|
package/dist/js-client.d.ts
CHANGED
|
@@ -321,6 +321,10 @@ export declare class ViraClient {
|
|
|
321
321
|
idempotencyKey?: string;
|
|
322
322
|
}): Promise<ViraResponse<ClientBody> | null>;
|
|
323
323
|
installPack(packId: string, variables?: Record<string, unknown>): Promise<ViraResponse<ClientBody> | null>;
|
|
324
|
+
diagnosePack(packId: string, input?: {
|
|
325
|
+
runtimeBindings?: readonly string[];
|
|
326
|
+
knownVerifiers?: readonly string[];
|
|
327
|
+
}): Promise<ViraResponse<ClientBody> | null>;
|
|
324
328
|
evaluatePack(packId: string, input: {
|
|
325
329
|
evaluationId: string;
|
|
326
330
|
}): Promise<ViraResponse<ClientBody> | null>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryvira/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.53",
|
|
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"},
|