@tryvira/opencode 0.1.12 → 0.1.14

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.
Files changed (2) hide show
  1. package/dist/index.js +16 -4
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -497,12 +497,18 @@ var ViraClient = class {
497
497
  required(input.scope.environmentId, "SDK_ACTION_ENVIRONMENT_REQUIRED");
498
498
  required(input.executionId, "SDK_ACTION_EXECUTION_REQUIRED");
499
499
  required(input.sessionId, "SDK_ACTION_SESSION_REQUIRED");
500
+ required(input.dataVersion, "SDK_ACTION_DATA_VERSION_REQUIRED");
500
501
  return this.request({
501
502
  method: "POST",
502
503
  path: "/v1/runtime/actions/authorize",
503
- body: { executionId: input.executionId, sessionId: input.sessionId, scope: input.scope, context: input.context, proposal: input.proposal, ...input.approval ? { approval: input.approval } : {} }
504
+ body: { executionId: input.executionId, sessionId: input.sessionId, dataVersion: input.dataVersion, scope: input.scope, context: input.context, proposal: input.proposal, ...input.approval ? { approval: input.approval } : {} }
504
505
  });
505
506
  }
507
+ async createHostActionApproval(input) {
508
+ required(input.sessionId, "SDK_ACTION_SESSION_REQUIRED");
509
+ required(input.dataVersion, "SDK_ACTION_DATA_VERSION_REQUIRED");
510
+ return this.request({ method: "POST", path: "/v1/runtime/actions/approvals", body: { sessionId: input.sessionId, dataVersion: input.dataVersion, proposal: input.proposal, confirmed: input.confirmed === true, ...input.ttlSeconds !== void 0 ? { ttlSeconds: input.ttlSeconds } : {} } });
511
+ }
506
512
  listBehaviorStrategies() {
507
513
  return this.request({
508
514
  method: "GET",
@@ -1323,8 +1329,12 @@ var v2Plugin = Plugin.define({
1323
1329
  const bindingDigest = text(bound.context.binding_digest);
1324
1330
  if (!allowedToolIds.includes(proposal.toolName) || !/^[a-f0-9]{64}$/.test(schemaDigest) || !/^[a-f0-9]{64}$/.test(bindingDigest)) return { decision: "BLOCK", reasonCode: "RUNTIME_ACTION_BINDING_UNAVAILABLE" };
1325
1331
  try {
1326
- const approval = asRecord(asRecord(proposal).approval);
1327
- const response = await client.authorizeHostAction({ executionId: bound.executionId, sessionId: proposal.sessionId ?? proposal.conversationId, scope, context: bound.context, proposal: { proposal_id: proposal.conversationId + ":" + proposal.callId, tool_key: proposal.toolName, arguments: proposal.args, arguments_digest: digest2(proposal.args), request_context_digest: digest2(bound.context), schema_digest: String(asRecord(asRecord(bound.context).tools).schema_digest ?? "") }, ...Object.keys(approval).length ? { approval } : {} });
1332
+ const proposalBody = { proposal_id: proposal.conversationId + ":" + proposal.callId, tool_key: proposal.toolName, arguments: proposal.args, arguments_digest: digest2(proposal.args), request_context_digest: digest2(bound.context), schema_digest: String(asRecord(asRecord(bound.context).tools).schema_digest ?? "") };
1333
+ const approvalCandidate = asRecord(asRecord(proposal).approval);
1334
+ const approval = typeof approvalCandidate.approvalId === "string" && approvalCandidate.approvalId.trim() ? { approvalId: approvalCandidate.approvalId.trim() } : void 0;
1335
+ const dataVersion = text(bound.context.release_digest);
1336
+ if (!dataVersion) return { decision: "BLOCK", reasonCode: "RUNTIME_ACTION_DATA_VERSION_UNAVAILABLE" };
1337
+ const response = await client.authorizeHostAction({ executionId: bound.executionId, sessionId: proposal.sessionId ?? proposal.conversationId, dataVersion, scope, context: bound.context, proposal: proposalBody, ...approval ? { approval } : {} });
1328
1338
  const body = asRecord(response?.body);
1329
1339
  return body.allowed === true ? { decision: "ALLOW", authorityReceiptDigest: text(body.authority_receipt_digest), decisionDigest: text(body.decision_digest) } : { decision: "BLOCK", reasonCode: text(body.reason_code) || "POLICY_DENIED", authorityReceiptDigest: text(body.authority_receipt_digest) };
1330
1340
  } catch (error) {
@@ -1408,9 +1418,11 @@ var v1Runtime = () => {
1408
1418
  const allowed = Array.isArray(tools.allowed_tool_ids) ? tools.allowed_tool_ids.map(text) : [];
1409
1419
  const schemaDigest = text(tools.schema_digest);
1410
1420
  const bindingDigest = text(bound.context.binding_digest);
1421
+ const dataVersion = text(bound.context.release_digest);
1422
+ if (!dataVersion) return { decision: "BLOCK", reasonCode: "RUNTIME_ACTION_DATA_VERSION_UNAVAILABLE" };
1411
1423
  if (!allowed.includes(proposal.toolName) || !/^[a-f0-9]{64}$/.test(schemaDigest) || !/^[a-f0-9]{64}$/.test(bindingDigest)) return { decision: "BLOCK", reasonCode: "RUNTIME_ACTION_BINDING_UNAVAILABLE" };
1412
1424
  try {
1413
- const response = await client.authorizeHostAction({ executionId: bound.executionId, sessionId: proposal.sessionId ?? proposal.conversationId, scope, context: bound.context, proposal: { proposal_id: proposal.conversationId + ":" + proposal.callId, tool_key: proposal.toolName, arguments: proposal.args, arguments_digest: digest2(proposal.args), request_context_digest: digest2(bound.context), schema_digest: schemaDigest } });
1425
+ const response = await client.authorizeHostAction({ executionId: bound.executionId, sessionId: proposal.sessionId ?? proposal.conversationId, dataVersion, scope, context: bound.context, proposal: { proposal_id: proposal.conversationId + ":" + proposal.callId, tool_key: proposal.toolName, arguments: proposal.args, arguments_digest: digest2(proposal.args), request_context_digest: digest2(bound.context), schema_digest: schemaDigest } });
1414
1426
  const body = asRecord(response?.body);
1415
1427
  return body.allowed === true ? { decision: "ALLOW", authorityReceiptDigest: text(body.authority_receipt_digest), decisionDigest: text(body.decision_digest) } : { decision: "BLOCK", reasonCode: text(body.reason_code) || "POLICY_DENIED", authorityReceiptDigest: text(body.authority_receipt_digest) };
1416
1428
  } catch (error) {
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@tryvira/opencode",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
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.53"},
10
+ "dependencies": {"@tryvira/sdk": "0.1.55"},
11
11
  "peerDependencies": {"effect": "^4.0.0"},
12
12
  "engines": {"node": ">=20"},
13
13
  "license": "MIT"