@tryvira/opencode 0.1.4 → 0.1.5
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/index.js +21 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1210,7 +1210,9 @@ function createViraHostRuntime(client, config) {
|
|
|
1210
1210
|
if (mode !== "enforce") return { decision: "ABSTAIN", reasonCode: mode === "off" ? "HOST_MODE_OFF" : "OBSERVE_ONLY" };
|
|
1211
1211
|
let decision;
|
|
1212
1212
|
try {
|
|
1213
|
-
|
|
1213
|
+
const authorized = await withTimeout(Promise.resolve(config.authorizeAction(proposal)), timeoutMs, "SDK_HOST_ACTION_AUTHORIZATION_TIMEOUT");
|
|
1214
|
+
const authorizedBody = bodyOf(authorized);
|
|
1215
|
+
decision = typeof authorizedBody.decision === "string" ? authorizedBody : authorized;
|
|
1214
1216
|
} catch {
|
|
1215
1217
|
return { decision: "ERROR", reasonCode: "VIRA_ACTION_AUTHORIZATION_TIMEOUT" };
|
|
1216
1218
|
}
|
|
@@ -1225,10 +1227,27 @@ function createViraHostRuntime(client, config) {
|
|
|
1225
1227
|
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 } : {} };
|
|
1226
1228
|
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");
|
|
1227
1229
|
};
|
|
1230
|
+
const executeTool = async (input) => {
|
|
1231
|
+
if (!input || typeof input !== "object" || typeof input.execute !== "function") throw new Error("SDK_GOVERNED_TOOL_EXECUTION_REQUIRED");
|
|
1232
|
+
const proposal = input.proposal;
|
|
1233
|
+
const decision = await beforeTool(proposal);
|
|
1234
|
+
if (decision.decision !== "ALLOW") return { decision, executed: false };
|
|
1235
|
+
if (!isAllow(decision)) throw new Error("SDK_HOST_ALLOW_RECEIPT_INVALID");
|
|
1236
|
+
try {
|
|
1237
|
+
const result = await input.execute(proposal.args);
|
|
1238
|
+
const resultDigest = digest(result);
|
|
1239
|
+
const observation = await afterTool({ ...proposal, ok: true, result, resultDigest });
|
|
1240
|
+
return { decision, executed: true, result, observation };
|
|
1241
|
+
} catch (error) {
|
|
1242
|
+
const errorCode = error instanceof Error ? error.message : "GOVERNED_TOOL_FAILED";
|
|
1243
|
+
const observation = await afterTool({ ...proposal, ok: false, errorCode, resultDigest: digest({ errorCode }) });
|
|
1244
|
+
throw Object.assign(error instanceof Error ? error : new Error(errorCode), { decision, observation });
|
|
1245
|
+
}
|
|
1246
|
+
};
|
|
1228
1247
|
const endSession = (identity) => {
|
|
1229
1248
|
projections.delete(sessionKey({ ...identity, requestId: "session-end", input: "" }));
|
|
1230
1249
|
};
|
|
1231
|
-
return Object.freeze({ mode, capabilities, connectOnce, getConnectionIdentity: () => connectionIdentity, beforeModel, beforeTool, afterTool, endSession, getProjection: (identity) => projections.get(sessionKey({ ...identity, requestId: "projection", input: "" })), supportsPostModelVerification: capabilities.canInterceptResponseBeforeDisplay });
|
|
1250
|
+
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 });
|
|
1232
1251
|
}
|
|
1233
1252
|
|
|
1234
1253
|
// src/index.ts
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryvira/opencode",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "OpenCode V2 host lifecycle integration for Vira",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"exports": {".": "./dist/index.js"},
|
|
8
8
|
"files": ["dist", "README.md"],
|
|
9
9
|
"scripts": {"build": "node ../../scripts/build-opencode-plugin.mjs", "pack:check": "npm run build && npm pack --dry-run"},
|
|
10
|
-
"dependencies": {"@tryvira/sdk": "0.1.
|
|
10
|
+
"dependencies": {"@tryvira/sdk": "0.1.51"},
|
|
11
11
|
"peerDependencies": {"effect": "^4.0.0"},
|
|
12
12
|
"engines": {"node": ">=20"},
|
|
13
13
|
"license": "MIT"
|