@tryvira/opencode 0.1.34 → 0.1.35

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 (3) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +26 -23
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # `@tryvira/opencode` 0.1.34
1
+ # `@tryvira/opencode` 0.1.35
2
2
 
3
3
  OpenCode V2 server plugin for Vira host lifecycle governance. The package default
4
4
  exports the V2 setup surface plus a compatibility `server()` transport required
package/dist/index.js CHANGED
@@ -521,7 +521,7 @@ var ViraClient = class {
521
521
  if (!taskKeys.length) taskKeys.push(receipt.taskKey.trim());
522
522
  const firstCapsule = capsules.find((value) => value && typeof value === "object" && String(value.behaviorKey ?? "").trim() === receipt.taskKey) && typeof capsules.find((value) => value && typeof value === "object" && String(value.behaviorKey ?? "").trim() === receipt.taskKey) === "object" ? capsules.find((value) => value && typeof value === "object" && String(value.behaviorKey ?? "").trim() === receipt.taskKey) : capsules[0] && typeof capsules[0] === "object" ? capsules[0] : {};
523
523
  const behaviorPoint = typeof firstCapsule.behaviorKey === "string" && firstCapsule.behaviorKey.trim() ? firstCapsule.behaviorKey : receipt.taskKey;
524
- const runtime = input.executionBoundary ? await this.resolveBoundary({
524
+ const runtime2 = input.executionBoundary ? await this.resolveBoundary({
525
525
  executionBoundary: input.executionBoundary,
526
526
  semanticContext: {
527
527
  taskKey: receipt.taskKey,
@@ -537,7 +537,7 @@ var ViraClient = class {
537
537
  semanticContext: { taskKey: receipt.taskKey, behaviorPoint, capsule: firstCapsule, ...input.revisionId ? { revisionId: input.revisionId } : {}, ...input.requestId ? { requestId: input.requestId } : {}, ...input.sessionId ? { conversationId: input.sessionId } : {}, ...input.signalAttestationRefs ? { signalAttestationRefs: input.signalAttestationRefs } : {} },
538
538
  idempotencyKey: input.idempotencyKey ? `sdk:runtime:${input.idempotencyKey}` : void 0
539
539
  });
540
- return { semantic, runtime, taskKeys, capsules, multiTask: taskKeys.length > 1 };
540
+ return { semantic, runtime: runtime2, taskKeys, capsules, multiTask: taskKeys.length > 1 };
541
541
  }
542
542
  async authorizeHostAction(input) {
543
543
  required(input.scope.organizationId, "SDK_ACTION_ORGANIZATION_REQUIRED");
@@ -1708,7 +1708,7 @@ var v2Plugin = Plugin.define({
1708
1708
  } catch {
1709
1709
  }
1710
1710
  }
1711
- const runtime = createViraHostRuntime(client, { mode, capabilities, authorizeAction: options.authorizeAction ?? (async (proposal) => {
1711
+ const runtime2 = createViraHostRuntime(client, { mode, capabilities, authorizeAction: options.authorizeAction ?? (async (proposal) => {
1712
1712
  const bound = actionContexts.get(contextKey(proposal));
1713
1713
  if (!bound) return { decision: "BLOCK", reasonCode: "RUNTIME_ACTION_CONTEXT_UNAVAILABLE" };
1714
1714
  if (!Number.isFinite(bound.expiresAt) || Date.now() >= bound.expiresAt) {
@@ -1735,8 +1735,8 @@ var v2Plugin = Plugin.define({
1735
1735
  let connectedAiSystemId = bootstrapAiSystemId;
1736
1736
  let connectedConnectionId = bootstrapConnectionId;
1737
1737
  if (!connectedAiSystemId || !connectedConnectionId) {
1738
- await runtime.connectOnce();
1739
- const identity = runtime.getConnectionIdentity();
1738
+ await runtime2.connectOnce();
1739
+ const identity = runtime2.getConnectionIdentity();
1740
1740
  connectedAiSystemId = identity?.aiSystemId ?? "";
1741
1741
  connectedConnectionId = identity?.connectionId ?? "";
1742
1742
  }
@@ -1775,7 +1775,7 @@ var v2Plugin = Plugin.define({
1775
1775
  return;
1776
1776
  }
1777
1777
  const proposal = { ...identity, requestId: text2(event.messageID ?? event.requestId) || `opencode:${Date.now()}`, callId: text2(event.source?.id) || text2(event.messageID) || `permission:${Date.now()}`, toolName, args: asRecord(event.metadata ?? event.resources), traceId: text2(event.traceID), turnId: text2(event.turnID) };
1778
- const decision = await runtime.beforeTool(proposal);
1778
+ const decision = await runtime2.beforeTool(proposal);
1779
1779
  if (decision.decision === "ALLOW") {
1780
1780
  event.effect = "allow";
1781
1781
  event.message = "Vira authorized this tool request.";
@@ -1791,8 +1791,8 @@ var v2Plugin = Plugin.define({
1791
1791
  const identity = sessionIdentity(event);
1792
1792
  if (input) {
1793
1793
  teachPrompts.set(identity.conversationId, input);
1794
- const result = await runtime.beforeModel({ ...identity, requestId: text2(event.messageID ?? event.requestId) || `opencode:${Date.now()}`, input, revisionId: options.revisionId, profile: conversationProfile(event, options), traceId: text2(event.traceID), turnId: text2(event.turnID), signalAttestationRefs: options.signalAttestationRefs });
1795
- const refreshed = runtime.getConnectionIdentity();
1794
+ const result = await runtime2.beforeModel({ ...identity, requestId: text2(event.messageID ?? event.requestId) || `opencode:${Date.now()}`, input, revisionId: options.revisionId, profile: conversationProfile(event, options), traceId: text2(event.traceID), turnId: text2(event.turnID), signalAttestationRefs: options.signalAttestationRefs });
1795
+ const refreshed = runtime2.getConnectionIdentity();
1796
1796
  if (!options.aiSystemId && !options.connectionId && refreshed) {
1797
1797
  connectedAiSystemId = refreshed.aiSystemId;
1798
1798
  connectedConnectionId = refreshed.connectionId;
@@ -1829,7 +1829,7 @@ Assistant: ${output}`, consent: true, privacy: "CONSENTED_TENANT" }, { idempoten
1829
1829
  registrations.push(await ctx.tool.hook("execute.before", async (event) => {
1830
1830
  const identity = sessionIdentity(event);
1831
1831
  const proposal = { ...identity, requestId: text2(event.messageID ?? event.requestId) || `opencode:${Date.now()}`, callId: required2(event.callID ?? event.id, "VIRA_HOST_TOOL_CALL_REQUIRED"), toolName: required2(event.tool ?? event.name, "VIRA_HOST_TOOL_NAME_REQUIRED"), args: asRecord(event.input ?? event.args), traceId: text2(event.traceID), turnId: text2(event.turnID) };
1832
- const decision = await runtime.beforeTool(proposal);
1832
+ const decision = await runtime2.beforeTool(proposal);
1833
1833
  actionDecisions.set(callKey(proposal), decision);
1834
1834
  if (mode === "enforce" && decision.decision !== "ALLOW") throw new ViraOpenCodeActionError(decision.decision, text2(decision.reasonCode) || "VIRA_ACTION_NOT_ALLOWED");
1835
1835
  }));
@@ -1839,7 +1839,7 @@ Assistant: ${output}`, consent: true, privacy: "CONSENTED_TENANT" }, { idempoten
1839
1839
  const decision = actionDecisions.get(callKey(proposal));
1840
1840
  actionDecisions.delete(callKey(proposal));
1841
1841
  try {
1842
- await runtime.afterTool({ ...proposal, ok: toolExecutionSucceeded(event, event), result: event.result ?? event.output, errorCode: text2(asRecord(event.error).code), ...decision?.authorityReceiptDigest ? { authorityReceiptDigest: decision.authorityReceiptDigest } : {}, ...decision?.decisionDigest ? { decisionDigest: decision.decisionDigest } : {} });
1842
+ await runtime2.afterTool({ ...proposal, ok: toolExecutionSucceeded(event, event), result: event.result ?? event.output, errorCode: text2(asRecord(event.error).code), ...decision?.authorityReceiptDigest ? { authorityReceiptDigest: decision.authorityReceiptDigest } : {}, ...decision?.decisionDigest ? { decisionDigest: decision.decisionDigest } : {} });
1843
1843
  } catch (error) {
1844
1844
  if (mode === "enforce") throw error;
1845
1845
  }
@@ -1847,12 +1847,12 @@ Assistant: ${output}`, consent: true, privacy: "CONSENTED_TENANT" }, { idempoten
1847
1847
  registrations.push(await ctx.session.hook("fork", async (event) => {
1848
1848
  await cancelTaskRunForSession(event);
1849
1849
  clearSessionState(event);
1850
- return runtime.endSession({ ...scope, hostName: "opencode", hostVersion: hostVersionFor(options, ctx), aiSystemId: options.aiSystemId ?? "", connectionId: options.connectionId ?? "", conversationId: text2(event.sessionID), sessionId: text2(event.sessionID) || void 0 });
1850
+ return runtime2.endSession({ ...scope, hostName: "opencode", hostVersion: hostVersionFor(options, ctx), aiSystemId: options.aiSystemId ?? "", connectionId: options.connectionId ?? "", conversationId: text2(event.sessionID), sessionId: text2(event.sessionID) || void 0 });
1851
1851
  }));
1852
1852
  registrations.push(await ctx.session.hook("compaction", async (event) => {
1853
1853
  await cancelTaskRunForSession(event);
1854
1854
  clearSessionState(event);
1855
- return runtime.endSession({ ...scope, hostName: "opencode", hostVersion: hostVersionFor(options, ctx), aiSystemId: options.aiSystemId ?? "", connectionId: options.connectionId ?? "", conversationId: text2(event.sessionID ?? event.conversationId), sessionId: text2(event.sessionID ?? event.conversationId) || void 0 });
1855
+ return runtime2.endSession({ ...scope, hostName: "opencode", hostVersion: hostVersionFor(options, ctx), aiSystemId: options.aiSystemId ?? "", connectionId: options.connectionId ?? "", conversationId: text2(event.sessionID ?? event.conversationId), sessionId: text2(event.sessionID ?? event.conversationId) || void 0 });
1856
1856
  }));
1857
1857
  return async () => {
1858
1858
  actionContexts.clear();
@@ -1901,9 +1901,9 @@ var v1Fallback = { async server(rawContext = {}) {
1901
1901
  const options = readHostOptions(rawContext);
1902
1902
  const configured = v1Runtime(options);
1903
1903
  if (!configured) return {};
1904
- const { mode, scope, runtime, actionContexts, actionDecisions, contextKey } = configured;
1905
- if (!options.aiSystemId || !options.connectionId) await runtime.connectOnce();
1906
- let connectedIdentity = runtime.getConnectionIdentity();
1904
+ const { mode, scope, runtime: runtime2, actionContexts, actionDecisions, contextKey } = configured;
1905
+ if (!options.aiSystemId || !options.connectionId) await runtime2.connectOnce();
1906
+ let connectedIdentity = runtime2.getConnectionIdentity();
1907
1907
  const env = envValue;
1908
1908
  const promptCacheTtlMs = Math.max(1e3, Math.min(3e5, Number(options.promptCacheTtlMs ?? envValue("VIRA_V1_PROMPT_CACHE_TTL_MS") ?? 6e4) || 6e4));
1909
1909
  const prompts = createV1PromptCache(promptCacheTtlMs);
@@ -1926,8 +1926,8 @@ var v1Fallback = { async server(rawContext = {}) {
1926
1926
  const direct = text2(input.prompt ?? asRecord(input.message).text ?? input.input ?? output.prompt);
1927
1927
  const prompt = direct || prompts.take(sessionId) || "";
1928
1928
  if (!prompt.trim()) return;
1929
- const result = await runtime.beforeModel({ ...identity(input), requestId: text2(input.messageID ?? input.requestId) || `opencode:${Date.now()}`, input: prompt, profile: conversationProfile(input, options), traceId: text2(input.traceID), turnId: text2(input.turnID), signalAttestationRefs: options.signalAttestationRefs });
1930
- if (!options.aiSystemId && !options.connectionId) connectedIdentity = runtime.getConnectionIdentity();
1929
+ const result = await runtime2.beforeModel({ ...identity(input), requestId: text2(input.messageID ?? input.requestId) || `opencode:${Date.now()}`, input: prompt, profile: conversationProfile(input, options), traceId: text2(input.traceID), turnId: text2(input.turnID), signalAttestationRefs: options.signalAttestationRefs });
1930
+ if (!options.aiSystemId && !options.connectionId) connectedIdentity = runtime2.getConnectionIdentity();
1931
1931
  const responseBody = asRecord(result.response?.body);
1932
1932
  const runtimeContext = asRecord(responseBody.requestContext ?? responseBody.context);
1933
1933
  const executionId = text2(input.executionId ?? responseBody.executionId);
@@ -1946,13 +1946,13 @@ var v1Fallback = { async server(rawContext = {}) {
1946
1946
  if (mode !== "enforce") return;
1947
1947
  const metadata = asRecord(input.metadata);
1948
1948
  const proposal = { ...identity(input), requestId: text2(input.messageID ?? input.requestId) || `opencode:${Date.now()}`, callId: required2(input.callID ?? input.id, "VIRA_HOST_TOOL_CALL_REQUIRED"), toolName: required2(metadata.tool ?? metadata.toolName ?? input.type, "VIRA_HOST_TOOL_NAME_REQUIRED"), args: asRecord(metadata.args ?? metadata.input ?? metadata.arguments), traceId: text2(input.traceID), turnId: text2(input.turnID) };
1949
- const decision = await runtime.beforeTool(proposal);
1949
+ const decision = await runtime2.beforeTool(proposal);
1950
1950
  actionDecisions.set(contextKey(proposal) + ":" + proposal.callId, decision);
1951
1951
  output.status = decision.decision === "ALLOW" ? "allow" : "deny";
1952
1952
  },
1953
1953
  "tool.execute.before": async (input, output) => {
1954
1954
  const proposal = { ...identity(input), requestId: text2(input.messageID ?? input.requestId) || `opencode:${Date.now()}`, callId: required2(input.callID ?? input.id, "VIRA_HOST_TOOL_CALL_REQUIRED"), toolName: required2(input.tool ?? input.name, "VIRA_HOST_TOOL_NAME_REQUIRED"), args: asRecord(output.args ?? input.args ?? input.input), traceId: text2(input.traceID), turnId: text2(input.turnID) };
1955
- const decision = await runtime.beforeTool(proposal);
1955
+ const decision = await runtime2.beforeTool(proposal);
1956
1956
  actionDecisions.set(contextKey(proposal) + ":" + proposal.callId, decision);
1957
1957
  if (mode === "enforce" && decision.decision !== "ALLOW") throw new ViraOpenCodeActionError(decision.decision, text2(decision.reasonCode) || "VIRA_ACTION_NOT_ALLOWED");
1958
1958
  },
@@ -1961,7 +1961,7 @@ var v1Fallback = { async server(rawContext = {}) {
1961
1961
  const decision = actionDecisions.get(contextKey(proposal) + ":" + proposal.callId);
1962
1962
  actionDecisions.delete(contextKey(proposal) + ":" + proposal.callId);
1963
1963
  try {
1964
- await runtime.afterTool({ ...proposal, ok: toolExecutionSucceeded(input, output), result: output.output, errorCode: text2(asRecord(output.error ?? input.error).code), ...decision?.authorityReceiptDigest ? { authorityReceiptDigest: decision.authorityReceiptDigest } : {}, ...decision?.decisionDigest ? { decisionDigest: decision.decisionDigest } : {} });
1964
+ await runtime2.afterTool({ ...proposal, ok: toolExecutionSucceeded(input, output), result: output.output, errorCode: text2(asRecord(output.error ?? input.error).code), ...decision?.authorityReceiptDigest ? { authorityReceiptDigest: decision.authorityReceiptDigest } : {}, ...decision?.decisionDigest ? { decisionDigest: decision.decisionDigest } : {} });
1965
1965
  } catch (error) {
1966
1966
  if (mode === "enforce") throw error;
1967
1967
  }
@@ -1983,14 +1983,17 @@ var server = v1Fallback.server;
1983
1983
  var index_default = legacyDefault;
1984
1984
 
1985
1985
  // src/runtime-entry.ts
1986
- Object.assign(index_default, {
1986
+ var runtime = {
1987
+ id: "vira",
1988
+ setup: index_default.setup,
1989
+ server: index_default.server,
1987
1990
  recordBusinessOutcome,
1988
1991
  recordConversationOutput,
1989
1992
  recordModelMetrics,
1990
1993
  recordModelResponse,
1991
1994
  recordUserCorrection
1992
- });
1993
- var runtime_entry_default = index_default;
1995
+ };
1996
+ var runtime_entry_default = runtime;
1994
1997
  export {
1995
1998
  runtime_entry_default as default
1996
1999
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryvira/opencode",
3
- "version": "0.1.34",
3
+ "version": "0.1.35",
4
4
  "description": "OpenCode host lifecycle integration for Vira",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",