@tryvira/sdk 0.1.51 → 0.1.52
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 +22 -4
- 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
|
@@ -1138,6 +1138,21 @@ function buildObservationRequest(event) {
|
|
|
1138
1138
|
}
|
|
1139
1139
|
|
|
1140
1140
|
// ../../sdks/framework-adapters.ts
|
|
1141
|
+
function createFrameworkRuntimeCore(client) {
|
|
1142
|
+
if (!client) throw new Error("SDK_FRAMEWORK_CLIENT_REQUIRED");
|
|
1143
|
+
return Object.freeze({
|
|
1144
|
+
async resolveBehavior(input) {
|
|
1145
|
+
if (input.input?.trim()) return client.resolveSemanticRuntime(input);
|
|
1146
|
+
return client.resolveBoundary({ executionBoundary: input.executionBoundary ?? {}, ...input.semanticContext ? { semanticContext: input.semanticContext } : {}, ...input.idempotencyKey ? { idempotencyKey: input.idempotencyKey } : {} });
|
|
1147
|
+
},
|
|
1148
|
+
async authorizeAction(input) {
|
|
1149
|
+
return client.authorizeHostAction(input);
|
|
1150
|
+
},
|
|
1151
|
+
async recordOutcome(event) {
|
|
1152
|
+
return client.observe({ ...event, eventType: event.eventType ?? "business.outcome" });
|
|
1153
|
+
}
|
|
1154
|
+
});
|
|
1155
|
+
}
|
|
1141
1156
|
async function resolveFrameworkBoundary(client, request) {
|
|
1142
1157
|
if (!request || typeof request !== "object") throw new Error("SDK_RUNTIME_REQUEST_REQUIRED");
|
|
1143
1158
|
const resolution = request.executionBoundary ? await client.resolveBoundary({
|
|
@@ -1188,11 +1203,13 @@ function createFrameworkLifecycleAdapter(client, framework, options = {}) {
|
|
|
1188
1203
|
const mode = options.mode ?? "observe";
|
|
1189
1204
|
if (mode !== "observe" && mode !== "enforce") throw new Error("SDK_FRAMEWORK_MODE_INVALID");
|
|
1190
1205
|
const observation = createFrameworkObservationAdapter(client, framework);
|
|
1206
|
+
const runtime = createFrameworkRuntimeCore(client);
|
|
1191
1207
|
const emit = (event, type) => observation.observe({ ...event, eventType: type }, "observation");
|
|
1192
1208
|
return Object.freeze({
|
|
1193
1209
|
...observation,
|
|
1194
1210
|
mode,
|
|
1195
|
-
|
|
1211
|
+
runtime,
|
|
1212
|
+
resolveBoundary: (input) => runtime.resolveBehavior(input),
|
|
1196
1213
|
start: (event) => emit(event, lifecycleType.start),
|
|
1197
1214
|
complete: (event) => emit(event, lifecycleType.complete),
|
|
1198
1215
|
error: (event) => emit(event, lifecycleType.error),
|
|
@@ -1311,7 +1328,7 @@ function createViraHostRuntime(client, config) {
|
|
|
1311
1328
|
nonEmpty(result.callId, "SDK_HOST_TOOL_CALL_ID_REQUIRED");
|
|
1312
1329
|
if (mode === "off" || !capabilities.canInspectToolAfter) return { status: "off" };
|
|
1313
1330
|
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 } : {} };
|
|
1331
|
+
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
1332
|
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
1333
|
};
|
|
1317
1334
|
const executeTool = async (input) => {
|
|
@@ -1323,11 +1340,11 @@ function createViraHostRuntime(client, config) {
|
|
|
1323
1340
|
try {
|
|
1324
1341
|
const result = await input.execute(proposal.args);
|
|
1325
1342
|
const resultDigest = digest(result);
|
|
1326
|
-
const observation = await afterTool({ ...proposal, ok: true, result, resultDigest });
|
|
1343
|
+
const observation = await afterTool({ ...proposal, ok: true, result, resultDigest, ...decision.authorityReceiptDigest ? { authorityReceiptDigest: decision.authorityReceiptDigest } : {}, ...decision.decisionDigest ? { decisionDigest: decision.decisionDigest } : {} });
|
|
1327
1344
|
return { decision, executed: true, result, observation };
|
|
1328
1345
|
} catch (error) {
|
|
1329
1346
|
const errorCode = error instanceof Error ? error.message : "GOVERNED_TOOL_FAILED";
|
|
1330
|
-
const observation = await afterTool({ ...proposal, ok: false, errorCode, resultDigest: digest({ errorCode }) });
|
|
1347
|
+
const observation = await afterTool({ ...proposal, ok: false, errorCode, resultDigest: digest({ errorCode }), ...decision.authorityReceiptDigest ? { authorityReceiptDigest: decision.authorityReceiptDigest } : {}, ...decision.decisionDigest ? { decisionDigest: decision.decisionDigest } : {} });
|
|
1331
1348
|
throw Object.assign(error instanceof Error ? error : new Error(errorCode), { decision, observation });
|
|
1332
1349
|
}
|
|
1333
1350
|
};
|
|
@@ -1347,6 +1364,7 @@ export {
|
|
|
1347
1364
|
createFrameworkAdapters,
|
|
1348
1365
|
createFrameworkLifecycleAdapter,
|
|
1349
1366
|
createFrameworkObservationAdapter,
|
|
1367
|
+
createFrameworkRuntimeCore,
|
|
1350
1368
|
createGenericHttpHooks,
|
|
1351
1369
|
createGenericRuntimeHooks,
|
|
1352
1370
|
createLangGraphHooks,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryvira/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.52",
|
|
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"},
|