@tryvira/opencode 0.1.17 → 0.1.18
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 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1184,6 +1184,7 @@ function createViraHostRuntime(client, config) {
|
|
|
1184
1184
|
let connected = null;
|
|
1185
1185
|
let connectionIdentity = null;
|
|
1186
1186
|
const projections = /* @__PURE__ */ new Map();
|
|
1187
|
+
const activeToolSessions = /* @__PURE__ */ new Set();
|
|
1187
1188
|
const connectOnce = async () => {
|
|
1188
1189
|
if (mode === "off" || !config.connect) return null;
|
|
1189
1190
|
if (!connected) connected = withTimeout(client.connectOnce(config.connect), timeoutMs, "SDK_HOST_CONNECT_TIMEOUT").then((result) => {
|
|
@@ -1226,24 +1227,40 @@ function createViraHostRuntime(client, config) {
|
|
|
1226
1227
|
nonEmpty(proposal.callId, "SDK_HOST_TOOL_CALL_ID_REQUIRED");
|
|
1227
1228
|
nonEmpty(proposal.toolName, "SDK_HOST_TOOL_NAME_REQUIRED");
|
|
1228
1229
|
if (mode !== "enforce") return { decision: "ABSTAIN", reasonCode: mode === "off" ? "HOST_MODE_OFF" : "OBSERVE_ONLY" };
|
|
1230
|
+
const toolSessionKey = `${proposal.organizationId}:${proposal.projectId}:${proposal.environmentId}:${proposal.conversationId}:${proposal.sessionId ?? proposal.conversationId}`;
|
|
1231
|
+
if (activeToolSessions.has(toolSessionKey)) return { decision: "BLOCK", reasonCode: "SDK_HOST_TOOL_IN_FLIGHT" };
|
|
1232
|
+
activeToolSessions.add(toolSessionKey);
|
|
1229
1233
|
let decision;
|
|
1230
1234
|
try {
|
|
1231
1235
|
const authorized = await withTimeout(Promise.resolve(config.authorizeAction(proposal)), timeoutMs, "SDK_HOST_ACTION_AUTHORIZATION_TIMEOUT");
|
|
1232
1236
|
const authorizedBody = bodyOf(authorized);
|
|
1233
1237
|
decision = typeof authorizedBody.decision === "string" ? authorizedBody : authorized;
|
|
1234
1238
|
} catch {
|
|
1239
|
+
activeToolSessions.delete(toolSessionKey);
|
|
1235
1240
|
return { decision: "ERROR", reasonCode: "VIRA_ACTION_AUTHORIZATION_TIMEOUT" };
|
|
1236
1241
|
}
|
|
1237
|
-
if (!decision || !["ALLOW", "BLOCK", "ESCALATE", "ABSTAIN", "ERROR"].includes(decision.decision))
|
|
1238
|
-
|
|
1242
|
+
if (!decision || !["ALLOW", "BLOCK", "ESCALATE", "ABSTAIN", "ERROR"].includes(decision.decision)) {
|
|
1243
|
+
activeToolSessions.delete(toolSessionKey);
|
|
1244
|
+
throw new Error("SDK_HOST_ACTION_DECISION_INVALID");
|
|
1245
|
+
}
|
|
1246
|
+
if (decision.decision !== "ALLOW") activeToolSessions.delete(toolSessionKey);
|
|
1247
|
+
if (decision.decision === "ALLOW" && !isAllow(decision)) {
|
|
1248
|
+
activeToolSessions.delete(toolSessionKey);
|
|
1249
|
+
throw new Error("SDK_HOST_ALLOW_RECEIPT_INVALID");
|
|
1250
|
+
}
|
|
1239
1251
|
return decision;
|
|
1240
1252
|
};
|
|
1241
1253
|
const afterTool = async (result) => {
|
|
1242
1254
|
nonEmpty(result.callId, "SDK_HOST_TOOL_CALL_ID_REQUIRED");
|
|
1243
1255
|
if (mode === "off" || !capabilities.canInspectToolAfter) return { status: "off" };
|
|
1256
|
+
const toolSessionKey = `${result.organizationId}:${result.projectId}:${result.environmentId}:${result.conversationId}:${result.sessionId ?? result.conversationId}`;
|
|
1244
1257
|
const observedResult = result.ok ? result.result : { errorCode: result.errorCode ?? "HOST_TOOL_FAILED" };
|
|
1245
1258
|
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 } : {} };
|
|
1246
|
-
|
|
1259
|
+
try {
|
|
1260
|
+
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");
|
|
1261
|
+
} finally {
|
|
1262
|
+
activeToolSessions.delete(toolSessionKey);
|
|
1263
|
+
}
|
|
1247
1264
|
};
|
|
1248
1265
|
const executeTool = async (input) => {
|
|
1249
1266
|
if (!input || typeof input !== "object" || typeof input.execute !== "function") throw new Error("SDK_GOVERNED_TOOL_EXECUTION_REQUIRED");
|
|
@@ -1264,6 +1281,7 @@ function createViraHostRuntime(client, config) {
|
|
|
1264
1281
|
};
|
|
1265
1282
|
const endSession = (identity) => {
|
|
1266
1283
|
projections.delete(sessionKey({ ...identity, requestId: "session-end", input: "" }));
|
|
1284
|
+
activeToolSessions.delete(`${identity.organizationId}:${identity.projectId}:${identity.environmentId}:${identity.conversationId}:${identity.sessionId ?? identity.conversationId}`);
|
|
1267
1285
|
};
|
|
1268
1286
|
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 });
|
|
1269
1287
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryvira/opencode",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
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/index.js", "README.md"],
|
|
9
9
|
"scripts": {"build": "node ../../scripts/build-opencode-plugin.mjs", "pack:check": "npm run build && npm pack --dry-run && node ../../scripts/opencode-plugin-smoke.mjs"},
|
|
10
|
-
"dependencies": {"@tryvira/sdk": "0.1.
|
|
10
|
+
"dependencies": {"@tryvira/sdk": "0.1.58"},
|
|
11
11
|
"peerDependencies": {"effect": "^4.0.0"},
|
|
12
12
|
"engines": {"node": ">=20"},
|
|
13
13
|
"license": "MIT"
|