@tryvira/opencode 0.1.58 → 0.1.60
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/README.md +1 -1
- package/dist/index.js +132 -48
- package/package.json +25 -8
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -44,6 +44,13 @@ var contentIdempotencyKey = async (operation, request) => {
|
|
|
44
44
|
return `${operation}:${hex}`;
|
|
45
45
|
};
|
|
46
46
|
var wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
47
|
+
var retryAfterMs = (value, now = Date.now()) => {
|
|
48
|
+
if (!value) return 0;
|
|
49
|
+
const seconds = Number(value);
|
|
50
|
+
if (Number.isFinite(seconds) && seconds >= 0) return Math.min(seconds * 1e3, 12e4);
|
|
51
|
+
const date = Date.parse(value);
|
|
52
|
+
return Number.isFinite(date) && date > now ? Math.min(date - now, 12e4) : 0;
|
|
53
|
+
};
|
|
47
54
|
var ViraClient = class {
|
|
48
55
|
evaluations;
|
|
49
56
|
teach;
|
|
@@ -134,8 +141,7 @@ var ViraClient = class {
|
|
|
134
141
|
requestId
|
|
135
142
|
);
|
|
136
143
|
if ((response.status >= 500 || response.status === 429) && attempt + 1 < attempts) {
|
|
137
|
-
const
|
|
138
|
-
const serverDelay = Number.isFinite(retryAfter) && retryAfter >= 0 ? Math.min(retryAfter * 1e3, 12e4) : 0;
|
|
144
|
+
const serverDelay = retryAfterMs(response.headers.get("retry-after"));
|
|
139
145
|
const jitter = Math.floor(Math.random() * 25);
|
|
140
146
|
await wait(Math.max(serverDelay, 25 * 2 ** attempt) + jitter);
|
|
141
147
|
continue;
|
|
@@ -1316,7 +1322,8 @@ function createViraHostRuntime(client, config) {
|
|
|
1316
1322
|
return connected;
|
|
1317
1323
|
};
|
|
1318
1324
|
const reconnect = async () => connectOnce({ force: true });
|
|
1319
|
-
const
|
|
1325
|
+
const scopeMemberKey = (identity) => `${identity.workspaceId ?? ""}:${identity.userId ?? ""}`;
|
|
1326
|
+
const sessionKey = (request) => `${request.organizationId}:${request.projectId}:${request.environmentId}:${scopeMemberKey(request)}:${request.conversationId}`;
|
|
1320
1327
|
const beforeModel = async (request) => {
|
|
1321
1328
|
nonEmpty(request.input, "SDK_HOST_MODEL_INPUT_REQUIRED");
|
|
1322
1329
|
if (mode === "off") return { status: "off" };
|
|
@@ -1326,7 +1333,10 @@ function createViraHostRuntime(client, config) {
|
|
|
1326
1333
|
void client.observe({ eventId: `${request.conversationId}:model.request:${request.requestId}`, eventType: "model.request", aiSystemId: request.aiSystemId, connectionId: request.connectionId, organizationId: request.organizationId, projectId: request.projectId, environmentId: request.environmentId, conversationId: request.conversationId, requestId: request.requestId, traceId: request.traceId, payload: { inputDigest: digest(request.input), minimization: { rawTextSent: false, digestAlgorithm: "sha256" } } }, { idempotencyKey: `sdk:model.request:${request.conversationId}:${request.requestId}` }).catch(() => void 0);
|
|
1327
1334
|
}
|
|
1328
1335
|
await connectOnce();
|
|
1329
|
-
const
|
|
1336
|
+
const profile = request.profile || {};
|
|
1337
|
+
const existingHierarchy = profile.scopeHierarchy && typeof profile.scopeHierarchy === "object" && !Array.isArray(profile.scopeHierarchy) ? profile.scopeHierarchy : {};
|
|
1338
|
+
const scopedProfile = request.workspaceId || request.userId ? { ...profile, scopeHierarchy: { ...existingHierarchy, ...request.workspaceId ? { workspaceId: request.workspaceId } : {}, ...request.userId ? { userId: request.userId } : {}, sessionId: request.sessionId ?? request.conversationId } } : request.profile;
|
|
1339
|
+
const semantic = await withTimeout(client.resolveSemanticRuntime({ input: request.input, profile: scopedProfile, revisionId: request.revisionId, sessionId: request.sessionId ?? request.conversationId, requestId: request.requestId, signalAttestationRefs: request.signalAttestationRefs }), timeoutMs, "SDK_HOST_RESOLVE_TIMEOUT");
|
|
1330
1340
|
if (!semantic) return { status: "unavailable", reasonCode: "VIRA_SEMANTIC_UNAVAILABLE" };
|
|
1331
1341
|
if (semantic.multiTask === true && semantic.taskKeys?.length > 1 && typeof client.startTaskRunFromPrompt === "function") {
|
|
1332
1342
|
try {
|
|
@@ -1367,7 +1377,7 @@ function createViraHostRuntime(client, config) {
|
|
|
1367
1377
|
nonEmpty(proposal.callId, "SDK_HOST_TOOL_CALL_ID_REQUIRED");
|
|
1368
1378
|
nonEmpty(proposal.toolName, "SDK_HOST_TOOL_NAME_REQUIRED");
|
|
1369
1379
|
if (mode !== "enforce") return { decision: "ABSTAIN", reasonCode: mode === "off" ? "HOST_MODE_OFF" : "OBSERVE_ONLY" };
|
|
1370
|
-
const toolSessionKey = `${proposal.organizationId}:${proposal.projectId}:${proposal.environmentId}:${proposal.conversationId}:${proposal.sessionId ?? proposal.conversationId}`;
|
|
1380
|
+
const toolSessionKey = `${proposal.organizationId}:${proposal.projectId}:${proposal.environmentId}:${scopeMemberKey(proposal)}:${proposal.conversationId}:${proposal.sessionId ?? proposal.conversationId}`;
|
|
1371
1381
|
const current = activeToolSessions.get(toolSessionKey);
|
|
1372
1382
|
if (current && current.expiresAt > Date.now()) return { decision: "BLOCK", reasonCode: "SDK_HOST_TOOL_IN_FLIGHT" };
|
|
1373
1383
|
if (current) {
|
|
@@ -1423,7 +1433,7 @@ function createViraHostRuntime(client, config) {
|
|
|
1423
1433
|
nonEmpty(result.callId, "SDK_HOST_TOOL_CALL_ID_REQUIRED");
|
|
1424
1434
|
if (mode === "off") return { status: "off" };
|
|
1425
1435
|
if (!capabilities.canInspectToolAfter) return { status: "skipped", executionCommitted: true };
|
|
1426
|
-
const toolSessionKey = `${result.organizationId}:${result.projectId}:${result.environmentId}:${result.conversationId}:${result.sessionId ?? result.conversationId}`;
|
|
1436
|
+
const toolSessionKey = `${result.organizationId}:${result.projectId}:${result.environmentId}:${scopeMemberKey(result)}:${result.conversationId}:${result.sessionId ?? result.conversationId}`;
|
|
1427
1437
|
const minimized = result.ok ? redactToolObservation(result.result, { maxBytes: toolObservationMaxBytes, redactKeys: toolObservationRedactKeys }) : { value: { errorCode: result.errorCode ?? "HOST_TOOL_FAILED" }, redacted: false, truncated: false };
|
|
1428
1438
|
const observedResult = minimized.value;
|
|
1429
1439
|
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 } : {} };
|
|
@@ -1458,7 +1468,7 @@ function createViraHostRuntime(client, config) {
|
|
|
1458
1468
|
}
|
|
1459
1469
|
};
|
|
1460
1470
|
const cancelTool = (identity, callId) => {
|
|
1461
|
-
const key = `${identity.organizationId}:${identity.projectId}:${identity.environmentId}:${identity.conversationId}:${identity.sessionId ?? identity.conversationId}`;
|
|
1471
|
+
const key = `${identity.organizationId}:${identity.projectId}:${identity.environmentId}:${scopeMemberKey(identity)}:${identity.conversationId}:${identity.sessionId ?? identity.conversationId}`;
|
|
1462
1472
|
const held = activeToolSessions.get(key);
|
|
1463
1473
|
if (!held || callId && held.callId !== callId) return false;
|
|
1464
1474
|
clearTimeout(held.timer);
|
|
@@ -1542,7 +1552,16 @@ var lastUserText = (event) => {
|
|
|
1542
1552
|
};
|
|
1543
1553
|
var latestAssistantText = (event) => {
|
|
1544
1554
|
const messages = Array.isArray(event.messages) ? event.messages : [];
|
|
1555
|
+
let lastUserIndex = -1;
|
|
1545
1556
|
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
1557
|
+
const message2 = asRecord(messages[index]);
|
|
1558
|
+
const role = text2(message2.role ?? asRecord(message2.info).role);
|
|
1559
|
+
if (role === "user") {
|
|
1560
|
+
lastUserIndex = index;
|
|
1561
|
+
break;
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
for (let index = messages.length - 1; index > lastUserIndex; index -= 1) {
|
|
1546
1565
|
const message2 = asRecord(messages[index]);
|
|
1547
1566
|
const role = text2(message2.role ?? asRecord(message2.info).role);
|
|
1548
1567
|
if (role === "assistant") {
|
|
@@ -1551,7 +1570,12 @@ var latestAssistantText = (event) => {
|
|
|
1551
1570
|
}
|
|
1552
1571
|
}
|
|
1553
1572
|
const message = asRecord(event.message);
|
|
1554
|
-
return text2(message.role ?? asRecord(message.info).role) === "assistant" ? messageContentText(message.content ?? message.parts ?? message.text) : "";
|
|
1573
|
+
return lastUserIndex < 0 && text2(message.role ?? asRecord(message.info).role) === "assistant" ? messageContentText(message.content ?? message.parts ?? message.text) : "";
|
|
1574
|
+
};
|
|
1575
|
+
var scopeMembers = (event, options = {}) => {
|
|
1576
|
+
const workspaceId = text2(options.workspaceId ?? event.workspaceId ?? asRecord(event.workspace).id);
|
|
1577
|
+
const userId = text2(options.userId ?? event.userId ?? asRecord(event.user).id);
|
|
1578
|
+
return { ...workspaceId ? { workspaceId } : {}, ...userId ? { userId } : {} };
|
|
1555
1579
|
};
|
|
1556
1580
|
var conversationProfile = (event, options = {}) => {
|
|
1557
1581
|
const messages = Array.isArray(event.messages) ? event.messages.slice(-20).map((value) => {
|
|
@@ -1573,6 +1597,7 @@ var modelMetadata = (event) => {
|
|
|
1573
1597
|
var modelObservationPayload = (event, extra = {}) => ({ model: modelMetadata(event), ...extra, minimization: { rawTextSent: false, digestAlgorithm: "sha256" } });
|
|
1574
1598
|
var recordModelResponse = (client, identity, event, input) => client.observe({ ...identity, eventId: input.eventId, eventType: "model.response", conversationId: input.conversationId, requestId: input.requestId, traceId: input.traceId, payload: modelObservationPayload(event, { outputDigest: digest2(input.output), status: input.status ?? "completed", ...Number.isFinite(input.latencyMs) ? { latencyMs: input.latencyMs } : {}, ...input.projectionDigest ? { projectionDigest: input.projectionDigest } : {}, ...input.receiptDigest ? { receiptDigest: input.receiptDigest } : {}, ...input.releaseDigest ? { releaseDigest: input.releaseDigest } : {}, ...input.evaluationId ? { evaluationId: input.evaluationId } : {} }), resultDigest: digest2(input.output) }, { idempotencyKey: `opencode:model.response:${input.eventId}` });
|
|
1575
1599
|
var recordConversationOutput = (client, identity, input) => client.observe({ ...identity, eventId: input.eventId, eventType: "conversation.output", conversationId: input.conversationId, requestId: input.requestId, traceId: input.traceId, payload: { outputDigest: digest2(input.output), ...Number.isFinite(input.latencyMs) ? { latencyMs: input.latencyMs } : {}, ...input.projectionDigest ? { projectionDigest: input.projectionDigest } : {}, ...input.receiptDigest ? { receiptDigest: input.receiptDigest } : {}, ...input.releaseDigest ? { releaseDigest: input.releaseDigest } : {}, ...input.evaluationId ? { evaluationId: input.evaluationId } : {}, minimization: { rawTextSent: false, digestAlgorithm: "sha256" } }, resultDigest: digest2(input.output) }, { idempotencyKey: `opencode:conversation.output:${input.eventId}` });
|
|
1600
|
+
var conversationOutputObservationPayload = (output) => ({ outputDigest: digest2(output), minimization: { rawTextSent: false, digestAlgorithm: "sha256" } });
|
|
1576
1601
|
var recordModelMetrics = (client, identity, input) => {
|
|
1577
1602
|
const common = { ...identity, conversationId: input.conversationId, requestId: input.requestId, traceId: input.traceId };
|
|
1578
1603
|
const lineage = { ...input.releaseDigest ? { releaseDigest: input.releaseDigest } : {}, ...input.evaluationId ? { evaluationId: input.evaluationId } : {}, minimization: { rawTextSent: false, digestAlgorithm: "sha256" } };
|
|
@@ -1607,6 +1632,8 @@ var createV1PromptCache = (ttlMs) => {
|
|
|
1607
1632
|
clear(sessionId);
|
|
1608
1633
|
const timer = setTimeout(() => entries.delete(sessionId), ttl);
|
|
1609
1634
|
entries.set(sessionId, { prompt, timer });
|
|
1635
|
+
}, peek(sessionId) {
|
|
1636
|
+
return entries.get(sessionId)?.prompt;
|
|
1610
1637
|
}, take(sessionId) {
|
|
1611
1638
|
const entry = entries.get(sessionId);
|
|
1612
1639
|
if (!entry) return void 0;
|
|
@@ -1614,6 +1641,25 @@ var createV1PromptCache = (ttlMs) => {
|
|
|
1614
1641
|
return entry.prompt;
|
|
1615
1642
|
}, clear, has: (sessionId) => entries.has(sessionId), size: () => entries.size };
|
|
1616
1643
|
};
|
|
1644
|
+
var createTeachTurnLedger = () => {
|
|
1645
|
+
const entries = /* @__PURE__ */ new Map();
|
|
1646
|
+
const put = (conversationId, prompt, requestId, turnId) => {
|
|
1647
|
+
const list = entries.get(conversationId) ?? [];
|
|
1648
|
+
list.push({ prompt, requestId, turnId });
|
|
1649
|
+
entries.set(conversationId, list.slice(-20));
|
|
1650
|
+
};
|
|
1651
|
+
const take = (conversationId, requestId, turnId) => {
|
|
1652
|
+
const list = entries.get(conversationId) ?? [];
|
|
1653
|
+
const exact = list.findIndex((item2) => requestId && item2.requestId === requestId || turnId && item2.turnId === turnId);
|
|
1654
|
+
const index = exact >= 0 ? exact : list.length === 1 ? 0 : -1;
|
|
1655
|
+
if (index < 0) return void 0;
|
|
1656
|
+
const [item] = list.splice(index, 1);
|
|
1657
|
+
if (list.length) entries.set(conversationId, list);
|
|
1658
|
+
else entries.delete(conversationId);
|
|
1659
|
+
return item?.prompt;
|
|
1660
|
+
};
|
|
1661
|
+
return { put, take, clear: (conversationId) => entries.delete(conversationId), size: () => [...entries.values()].reduce((sum, list) => sum + list.length, 0) };
|
|
1662
|
+
};
|
|
1617
1663
|
var readHostOptions = (rawContext) => {
|
|
1618
1664
|
const raw = asRecord(rawContext);
|
|
1619
1665
|
const nested = asRecord(raw.options);
|
|
@@ -1632,6 +1678,7 @@ var resolveOpenCodeToolBinding = (tools, toolName) => {
|
|
|
1632
1678
|
const binding = bindings.find((value) => text2(value.host_action_name) === toolName || Array.isArray(value.aliases) && value.aliases.map(text2).includes(toolName));
|
|
1633
1679
|
return { allowedToolIds, bindings, binding, canonicalToolId: text2(binding?.tool_id) || toolName, schemaDigest: text2(binding?.schema_digest) || text2(tools.schema_digest) };
|
|
1634
1680
|
};
|
|
1681
|
+
var buildOpenCodeActionProposal = (proposal, binding, requestContext) => ({ proposal_id: proposal.conversationId + ":" + proposal.callId, tool_key: binding.canonicalToolId, arguments: proposal.args, arguments_digest: digest2(proposal.args), request_context_digest: digest2(requestContext), schema_digest: binding.schemaDigest });
|
|
1635
1682
|
var createDesktopPermissionBridge = () => {
|
|
1636
1683
|
const pending = /* @__PURE__ */ new Map();
|
|
1637
1684
|
const evaluate = (event) => {
|
|
@@ -1668,7 +1715,8 @@ var ViraOpenCodeActionError = class extends Error {
|
|
|
1668
1715
|
};
|
|
1669
1716
|
var v2Plugin = Plugin.define({
|
|
1670
1717
|
id: "vira",
|
|
1671
|
-
async setup(
|
|
1718
|
+
async setup(openCodeContext) {
|
|
1719
|
+
const ctx = openCodeContext;
|
|
1672
1720
|
const options = ctx.options ?? {};
|
|
1673
1721
|
const env = envValue;
|
|
1674
1722
|
const mode = options.mode ?? env("VIRA_HOST_MODE") ?? "off";
|
|
@@ -1681,21 +1729,34 @@ var v2Plugin = Plugin.define({
|
|
|
1681
1729
|
const capabilities = { canObserveModel: true, canInjectContext: true, canInterceptToolBefore: true, canInspectToolAfter: true, canPreventSideEffect: mode === "enforce", canInterceptResponseBeforeDisplay: false, ...options.capabilities ?? {} };
|
|
1682
1730
|
const actionContexts = /* @__PURE__ */ new Map();
|
|
1683
1731
|
const taskRuns = /* @__PURE__ */ new Map();
|
|
1684
|
-
const teachPrompts =
|
|
1732
|
+
const teachPrompts = createTeachTurnLedger();
|
|
1685
1733
|
const actionDecisions = /* @__PURE__ */ new Map();
|
|
1734
|
+
const actionDecisionDigests = /* @__PURE__ */ new Map();
|
|
1686
1735
|
const desktopPermission = createDesktopPermissionBridge();
|
|
1687
|
-
const contextKey = (identity) => identity.organizationId + ":" + identity.projectId + ":" + identity.environmentId + ":" + identity.conversationId + ":" + (identity.sessionId ?? identity.conversationId);
|
|
1736
|
+
const contextKey = (identity) => identity.organizationId + ":" + identity.projectId + ":" + identity.environmentId + ":" + (identity.workspaceId ?? "") + ":" + (identity.userId ?? "") + ":" + identity.conversationId + ":" + (identity.sessionId ?? identity.conversationId);
|
|
1688
1737
|
const findActionContext = (proposal) => {
|
|
1689
1738
|
const exact = actionContexts.get(contextKey(proposal));
|
|
1690
1739
|
if (exact) return exact;
|
|
1691
1740
|
const sessionId = proposal.sessionId ?? proposal.conversationId;
|
|
1692
1741
|
for (const bound of actionContexts.values()) {
|
|
1693
|
-
if (bound.sessionId === sessionId && bound.conversationId === proposal.conversationId) return bound;
|
|
1742
|
+
if (bound.sessionId === sessionId && bound.conversationId === proposal.conversationId && bound.workspaceId === proposal.workspaceId && bound.userId === proposal.userId) return bound;
|
|
1694
1743
|
}
|
|
1695
|
-
for (const bound of actionContexts.values()) if (bound.sessionId === sessionId) return bound;
|
|
1744
|
+
for (const bound of actionContexts.values()) if (bound.sessionId === sessionId && bound.workspaceId === proposal.workspaceId && bound.userId === proposal.userId) return bound;
|
|
1696
1745
|
return void 0;
|
|
1697
1746
|
};
|
|
1698
1747
|
const callKey = (proposal) => contextKey(proposal) + ":" + proposal.callId;
|
|
1748
|
+
const proposalDigest = (proposal) => digest2({ toolName: proposal.toolName, args: proposal.args, sessionId: proposal.sessionId, conversationId: proposal.conversationId });
|
|
1749
|
+
const cachedDecision = (proposal) => {
|
|
1750
|
+
const key = callKey(proposal);
|
|
1751
|
+
const cached = actionDecisions.get(key);
|
|
1752
|
+
return cached && actionDecisionDigests.get(key) === proposalDigest(proposal) ? cached : void 0;
|
|
1753
|
+
};
|
|
1754
|
+
const cacheDecision = (proposal, decision) => {
|
|
1755
|
+
const key = callKey(proposal);
|
|
1756
|
+
actionDecisions.set(key, decision);
|
|
1757
|
+
actionDecisionDigests.set(key, proposalDigest(proposal));
|
|
1758
|
+
return decision;
|
|
1759
|
+
};
|
|
1699
1760
|
const clearSessionState = (event) => {
|
|
1700
1761
|
const sessionId = text2(event.sessionID ?? event.sessionId);
|
|
1701
1762
|
const conversationId = text2(event.conversationId ?? event.sessionID ?? event.sessionId);
|
|
@@ -1706,8 +1767,8 @@ var v2Plugin = Plugin.define({
|
|
|
1706
1767
|
if (sessionId && key.includes(":" + sessionId + ":") || conversationId && key.includes(":" + conversationId + ":")) actionDecisions.delete(key);
|
|
1707
1768
|
}
|
|
1708
1769
|
for (const key of taskRuns.keys()) if (key === conversationId || key === sessionId) taskRuns.delete(key);
|
|
1709
|
-
teachPrompts.
|
|
1710
|
-
teachPrompts.
|
|
1770
|
+
teachPrompts.clear(conversationId);
|
|
1771
|
+
if (sessionId && sessionId !== conversationId) teachPrompts.clear(sessionId);
|
|
1711
1772
|
desktopPermission.clear();
|
|
1712
1773
|
};
|
|
1713
1774
|
const cancelTaskRunForSession = async (event) => {
|
|
@@ -1760,13 +1821,15 @@ var v2Plugin = Plugin.define({
|
|
|
1760
1821
|
const schemaDigest = binding.schemaDigest;
|
|
1761
1822
|
const bindingDigest = text2(bound.context.binding_digest);
|
|
1762
1823
|
if (toolBindings.length && !mappedTool || !allowedToolIds.includes(canonicalToolId) || !/^[a-f0-9]{64}$/.test(schemaDigest) || !/^[a-f0-9]{64}$/.test(bindingDigest)) return { decision: "BLOCK", reasonCode: "RUNTIME_ACTION_BINDING_UNAVAILABLE" };
|
|
1763
|
-
const proposalBody =
|
|
1824
|
+
const proposalBody = buildOpenCodeActionProposal(proposal, { canonicalToolId, schemaDigest }, bound.context);
|
|
1764
1825
|
const approvalCandidate = asRecord(asRecord(proposal).approval);
|
|
1765
1826
|
const approval = typeof approvalCandidate.approvalId === "string" && approvalCandidate.approvalId.trim() ? { approvalId: approvalCandidate.approvalId.trim() } : void 0;
|
|
1766
1827
|
const dataVersion = text2(bound.context.release_digest);
|
|
1767
1828
|
if (!dataVersion) return { decision: "BLOCK", reasonCode: "RUNTIME_ACTION_DATA_VERSION_UNAVAILABLE" };
|
|
1768
1829
|
const refs = Array.isArray(bound.context.signal_attestation_refs) ? bound.context.signal_attestation_refs : [];
|
|
1769
|
-
|
|
1830
|
+
const nativeAccepted = desktopPermission.confirm(proposal);
|
|
1831
|
+
const confirmAction = async () => nativeAccepted || typeof options.confirmAction === "function" && await options.confirmAction(proposal);
|
|
1832
|
+
return authorizeWithOneShotCustomerConfirmation({ client, proposal, proposalBody, signalAttestationRefs: refs, executionId: bound.executionId, sessionId: proposal.sessionId ?? proposal.conversationId, dataVersion, scope, context: bound.context, confirmAction, approvalId: approval?.approvalId });
|
|
1770
1833
|
}), ...bootstrapAiSystemId && bootstrapConnectionId ? {} : { connect: openCodeConnectConfig(scope, options) } });
|
|
1771
1834
|
let connectedAiSystemId = bootstrapAiSystemId;
|
|
1772
1835
|
let connectedConnectionId = bootstrapConnectionId;
|
|
@@ -1807,25 +1870,24 @@ var v2Plugin = Plugin.define({
|
|
|
1807
1870
|
}
|
|
1808
1871
|
const sessionIdentity = (event) => {
|
|
1809
1872
|
const sessionId = sessionRef(event);
|
|
1810
|
-
return { ...scope, hostName: options.hostName ?? "opencode", hostVersion: hostVersionFor(options, ctx), aiSystemId: required2(connectedAiSystemId, "VIRA_HOST_AI_SYSTEM_REQUIRED"), connectionId: required2(connectedConnectionId, "VIRA_HOST_CONNECTION_REQUIRED"), conversationId: required2(event.conversationId ?? event.sessionID ?? event.sessionId ?? asRecord(event.session).id, "VIRA_HOST_SESSION_REQUIRED"), sessionId: sessionId || void 0 };
|
|
1873
|
+
return { ...scope, ...scopeMembers(event, options), hostName: options.hostName ?? "opencode", hostVersion: hostVersionFor(options, ctx), aiSystemId: required2(connectedAiSystemId, "VIRA_HOST_AI_SYSTEM_REQUIRED"), connectionId: required2(connectedConnectionId, "VIRA_HOST_CONNECTION_REQUIRED"), conversationId: required2(event.conversationId ?? event.sessionID ?? event.sessionId ?? asRecord(event.session).id, "VIRA_HOST_SESSION_REQUIRED"), sessionId: sessionId || void 0 };
|
|
1811
1874
|
};
|
|
1812
1875
|
if (mode === "enforce" && options.permissionMode !== "deny" && ctx.permission?.hook) registrations.push(await ctx.permission.hook("evaluate", async (event) => {
|
|
1813
|
-
const identity = sessionIdentity(event);
|
|
1814
1876
|
const toolName = text2(event.action);
|
|
1877
|
+
const callId = text2(event.source?.id) || text2(event.messageID) || `permission:${Date.now()}`;
|
|
1815
1878
|
if (!toolName) {
|
|
1816
1879
|
event.effect = "deny";
|
|
1817
1880
|
event.message = "Vira denied an unidentifiable tool request.";
|
|
1818
1881
|
return;
|
|
1819
1882
|
}
|
|
1820
|
-
const
|
|
1821
|
-
|
|
1822
|
-
if (decision.decision === "ALLOW") {
|
|
1823
|
-
event.effect = "allow";
|
|
1824
|
-
event.message = "Vira authorized this tool request.";
|
|
1825
|
-
} else {
|
|
1883
|
+
const asked = desktopPermission.evaluate({ sessionID: text2(event.sessionID ?? event.sessionId), action: toolName, source: { id: callId } });
|
|
1884
|
+
if (!asked) {
|
|
1826
1885
|
event.effect = "deny";
|
|
1827
|
-
event.message =
|
|
1886
|
+
event.message = "Vira denied this tool request because the native confirmation context was unavailable.";
|
|
1887
|
+
return;
|
|
1828
1888
|
}
|
|
1889
|
+
event.effect = "ask";
|
|
1890
|
+
event.message = `Vira requires one-time confirmation for ${toolName}. Confirm the exact tool and arguments in OpenCode.`;
|
|
1829
1891
|
}));
|
|
1830
1892
|
registrations.push(await ctx.session.hook("context", async (event) => {
|
|
1831
1893
|
const input = lastUserText(event);
|
|
@@ -1833,7 +1895,7 @@ var v2Plugin = Plugin.define({
|
|
|
1833
1895
|
if (!input && !output) return;
|
|
1834
1896
|
const identity = sessionIdentity(event);
|
|
1835
1897
|
if (input) {
|
|
1836
|
-
teachPrompts.
|
|
1898
|
+
teachPrompts.put(identity.conversationId, input, text2(event.messageID ?? event.requestId) || void 0, text2(event.turnID) || void 0);
|
|
1837
1899
|
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 });
|
|
1838
1900
|
const refreshed = runtime2.getConnectionIdentity();
|
|
1839
1901
|
if (!options.aiSystemId && !options.connectionId && refreshed) {
|
|
@@ -1858,13 +1920,12 @@ var v2Plugin = Plugin.define({
|
|
|
1858
1920
|
}
|
|
1859
1921
|
if (output) {
|
|
1860
1922
|
const eventId = `${identity.conversationId}:assistant:${text2(event.messageID ?? event.requestId) || digest2(output).slice(0, 16)}`;
|
|
1861
|
-
void client.observe({ ...identity, eventId, eventType: "conversation.output", traceId: text2(event.traceID), requestId: text2(event.requestId ?? event.messageID) || eventId, payload:
|
|
1923
|
+
void client.observe({ ...identity, eventId, eventType: "conversation.output", traceId: text2(event.traceID), requestId: text2(event.requestId ?? event.messageID) || eventId, payload: conversationOutputObservationPayload(output), attributes: { source: "opencode.context" } }, { idempotencyKey: `opencode:conversation.output:${eventId}` }).catch(() => void 0);
|
|
1862
1924
|
if (options.teachConsent === true) {
|
|
1863
|
-
const prompt = teachPrompts.
|
|
1925
|
+
const prompt = teachPrompts.take(identity.conversationId, text2(event.messageID ?? event.requestId) || void 0, text2(event.turnID) || void 0) || "";
|
|
1864
1926
|
if (prompt) {
|
|
1865
1927
|
void client.submitTeachConversationEvidence({ id: `opencode-teach:${identity.conversationId}:${text2(event.messageID ?? event.requestId) || digest2(output).slice(0, 16)}`, conversationId: identity.conversationId, message: `User: ${prompt}
|
|
1866
1928
|
Assistant: ${output}`, consent: true, privacy: "CONSENTED_TENANT" }, { idempotencyKey: `opencode:teach:${identity.conversationId}:${text2(event.messageID ?? event.requestId) || digest2(output).slice(0, 16)}` }).catch(() => void 0);
|
|
1867
|
-
teachPrompts.delete(identity.conversationId);
|
|
1868
1929
|
}
|
|
1869
1930
|
}
|
|
1870
1931
|
}
|
|
@@ -1872,15 +1933,16 @@ Assistant: ${output}`, consent: true, privacy: "CONSENTED_TENANT" }, { idempoten
|
|
|
1872
1933
|
registrations.push(await ctx.tool.hook("execute.before", async (event) => {
|
|
1873
1934
|
const identity = sessionIdentity(event);
|
|
1874
1935
|
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) };
|
|
1875
|
-
const decision = await runtime2.beforeTool(proposal);
|
|
1876
|
-
actionDecisions.set(callKey(proposal), decision);
|
|
1936
|
+
const decision = cachedDecision(proposal) ?? cacheDecision(proposal, await runtime2.beforeTool(proposal));
|
|
1877
1937
|
if (mode === "enforce" && decision.decision !== "ALLOW") throw new ViraOpenCodeActionError(decision.decision, text2(decision.reasonCode) || "VIRA_ACTION_NOT_ALLOWED");
|
|
1878
1938
|
}));
|
|
1879
1939
|
registrations.push(await ctx.tool.hook("execute.after", async (event) => {
|
|
1880
1940
|
const identity = sessionIdentity(event);
|
|
1881
1941
|
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) };
|
|
1882
|
-
const
|
|
1883
|
-
|
|
1942
|
+
const key = callKey(proposal);
|
|
1943
|
+
const decision = cachedDecision(proposal);
|
|
1944
|
+
actionDecisions.delete(key);
|
|
1945
|
+
actionDecisionDigests.delete(key);
|
|
1884
1946
|
try {
|
|
1885
1947
|
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 } : {} });
|
|
1886
1948
|
} catch (error) {
|
|
@@ -1900,6 +1962,7 @@ Assistant: ${output}`, consent: true, privacy: "CONSENTED_TENANT" }, { idempoten
|
|
|
1900
1962
|
return async () => {
|
|
1901
1963
|
actionContexts.clear();
|
|
1902
1964
|
actionDecisions.clear();
|
|
1965
|
+
actionDecisionDigests.clear();
|
|
1903
1966
|
desktopPermission.clear();
|
|
1904
1967
|
for (const registration of registrations) await registration.dispose?.();
|
|
1905
1968
|
};
|
|
@@ -1915,7 +1978,21 @@ var v1Runtime = (options) => {
|
|
|
1915
1978
|
const client = new ViraClient({ baseUrl: required2(options.apiUrl ?? env("VIRA_CONTROL_URL") ?? env("VIRA_API_URL"), "VIRA_HOST_API_URL_REQUIRED"), apiKey: options.apiKey ?? env("VIRA_API_KEY"), timeoutMs, allowInsecureLocalhost: options.allowInsecureLocalhost ?? env("VIRA_ALLOW_INSECURE_LOCALHOST") === "true" });
|
|
1916
1979
|
const actionContexts = /* @__PURE__ */ new Map();
|
|
1917
1980
|
const actionDecisions = /* @__PURE__ */ new Map();
|
|
1981
|
+
const actionDecisionDigests = /* @__PURE__ */ new Map();
|
|
1918
1982
|
const contextKey = (identity) => identity.organizationId + ":" + identity.projectId + ":" + identity.environmentId + ":" + identity.conversationId + ":" + (identity.sessionId ?? identity.conversationId);
|
|
1983
|
+
const callKey = (proposal) => contextKey(proposal) + ":" + proposal.callId;
|
|
1984
|
+
const proposalDigest = (proposal) => digest2({ toolName: proposal.toolName, args: proposal.args, sessionId: proposal.sessionId, conversationId: proposal.conversationId });
|
|
1985
|
+
const cachedDecision = (proposal) => {
|
|
1986
|
+
const key = callKey(proposal);
|
|
1987
|
+
const cached = actionDecisions.get(key);
|
|
1988
|
+
return cached && actionDecisionDigests.get(key) === proposalDigest(proposal) ? cached : void 0;
|
|
1989
|
+
};
|
|
1990
|
+
const cacheDecision = (proposal, decision) => {
|
|
1991
|
+
const key = callKey(proposal);
|
|
1992
|
+
actionDecisions.set(key, decision);
|
|
1993
|
+
actionDecisionDigests.set(key, proposalDigest(proposal));
|
|
1994
|
+
return decision;
|
|
1995
|
+
};
|
|
1919
1996
|
const findActionContext = (proposal) => {
|
|
1920
1997
|
const exact = actionContexts.get(contextKey(proposal));
|
|
1921
1998
|
if (exact) return exact;
|
|
@@ -1938,7 +2015,7 @@ var v1Runtime = (options) => {
|
|
|
1938
2015
|
if (!dataVersion) return { decision: "BLOCK", reasonCode: "RUNTIME_ACTION_DATA_VERSION_UNAVAILABLE" };
|
|
1939
2016
|
if (binding.bindings.length && !binding.binding || !binding.allowedToolIds.includes(binding.canonicalToolId) || !/^[a-f0-9]{64}$/.test(binding.schemaDigest) || !/^[a-f0-9]{64}$/.test(bindingDigest)) return { decision: "BLOCK", reasonCode: "RUNTIME_ACTION_BINDING_UNAVAILABLE" };
|
|
1940
2017
|
try {
|
|
1941
|
-
const response = await client.authorizeHostAction({ executionId: bound.executionId, sessionId: proposal.sessionId ?? proposal.conversationId, dataVersion, scope, context: bound.context, proposal:
|
|
2018
|
+
const response = await client.authorizeHostAction({ executionId: bound.executionId, sessionId: proposal.sessionId ?? proposal.conversationId, dataVersion, scope, context: bound.context, proposal: buildOpenCodeActionProposal(proposal, binding, bound.context) });
|
|
1942
2019
|
const body = asRecord(response?.body);
|
|
1943
2020
|
return body.allowed === true ? { decision: "ALLOW", authorityReceiptDigest: text2(body.authority_receipt_digest), decisionDigest: text2(body.decision_digest) } : { decision: "BLOCK", reasonCode: text2(body.reason_code) || "POLICY_DENIED", authorityReceiptDigest: text2(body.authority_receipt_digest) };
|
|
1944
2021
|
} catch (error) {
|
|
@@ -1946,21 +2023,25 @@ var v1Runtime = (options) => {
|
|
|
1946
2023
|
}
|
|
1947
2024
|
};
|
|
1948
2025
|
const authorizeAction = options.authorizeAction ?? serverAuthorizeAction;
|
|
1949
|
-
return { mode, scope, client, actionContexts, actionDecisions, contextKey, runtime: createViraHostRuntime(client, { mode, timeoutMs, ...(options.aiSystemId ?? env("VIRA_AI_SYSTEM_ID")) && (options.connectionId ?? env("VIRA_CONNECTION_ID")) ? {} : { connect: openCodeConnectConfig(scope, options) }, capabilities: { canObserveModel: true, canInjectContext: true, canInterceptToolBefore: true, canInspectToolAfter: true, canPreventSideEffect: mode === "enforce", canInterceptResponseBeforeDisplay: false, ...options.capabilities ?? {} }, authorizeAction }) };
|
|
2026
|
+
return { mode, scope, client, actionContexts, actionDecisions, actionDecisionDigests, contextKey, cachedDecision, cacheDecision, runtime: createViraHostRuntime(client, { mode, timeoutMs, ...(options.aiSystemId ?? env("VIRA_AI_SYSTEM_ID")) && (options.connectionId ?? env("VIRA_CONNECTION_ID")) ? {} : { connect: openCodeConnectConfig(scope, options) }, capabilities: { canObserveModel: true, canInjectContext: true, canInterceptToolBefore: true, canInspectToolAfter: true, canPreventSideEffect: mode === "enforce", canInterceptResponseBeforeDisplay: false, ...options.capabilities ?? {} }, authorizeAction }) };
|
|
1950
2027
|
};
|
|
1951
2028
|
var v1Fallback = { async server(rawContext = {}) {
|
|
1952
2029
|
const options = readHostOptions(rawContext);
|
|
1953
2030
|
const configured = v1Runtime(options);
|
|
1954
2031
|
if (!configured) return {};
|
|
1955
|
-
const { mode, scope, client, runtime: runtime2, actionContexts, actionDecisions, contextKey } = configured;
|
|
2032
|
+
const { mode, scope, client, runtime: runtime2, actionContexts, actionDecisions, actionDecisionDigests, contextKey, cachedDecision, cacheDecision } = configured;
|
|
1956
2033
|
if (!options.aiSystemId || !options.connectionId) await runtime2.connectOnce();
|
|
1957
2034
|
let connectedIdentity = runtime2.getConnectionIdentity();
|
|
1958
2035
|
const env = envValue;
|
|
1959
2036
|
const promptCacheTtlMs = Math.max(1e3, Math.min(3e5, Number(options.promptCacheTtlMs ?? envValue("VIRA_V1_PROMPT_CACHE_TTL_MS") ?? 6e4) || 6e4));
|
|
1960
2037
|
const prompts = createV1PromptCache(promptCacheTtlMs);
|
|
2038
|
+
const teachPrompts = createTeachTurnLedger();
|
|
1961
2039
|
const clearSessionPrompts = (event) => {
|
|
1962
2040
|
const sessionId = text2(event.sessionID ?? event.sessionId ?? event.conversationId ?? event.id);
|
|
1963
|
-
if (sessionId)
|
|
2041
|
+
if (sessionId) {
|
|
2042
|
+
prompts.clear(sessionId);
|
|
2043
|
+
teachPrompts.clear(sessionId);
|
|
2044
|
+
}
|
|
1964
2045
|
};
|
|
1965
2046
|
const hostVersion = hostVersionFor(options, rawContext);
|
|
1966
2047
|
const identity = (input) => ({ ...scope, hostName: options.hostName ?? "opencode", hostVersion, aiSystemId: required2(connectedIdentity?.aiSystemId ?? options.aiSystemId ?? env("VIRA_AI_SYSTEM_ID"), "VIRA_HOST_AI_SYSTEM_REQUIRED"), connectionId: required2(connectedIdentity?.connectionId ?? options.connectionId ?? env("VIRA_CONNECTION_ID"), "VIRA_HOST_CONNECTION_REQUIRED"), conversationId: required2(input.sessionID ?? input.conversationId ?? input.id, "VIRA_HOST_SESSION_REQUIRED"), sessionId: text2(input.sessionID ?? input.sessionId ?? input.conversationId) || void 0 });
|
|
@@ -1980,7 +2061,7 @@ var v1Fallback = { async server(rawContext = {}) {
|
|
|
1980
2061
|
const eventId = `${sessionID}:assistant:${messageID}`;
|
|
1981
2062
|
await recordConversationOutput(client, current, { eventId, output, conversationId: sessionID, requestId: messageID, traceId: text2(data.traceID) || void 0 });
|
|
1982
2063
|
if (options.teachConsent === true) {
|
|
1983
|
-
const prompt =
|
|
2064
|
+
const prompt = teachPrompts.take(sessionID, messageID);
|
|
1984
2065
|
if (prompt) await client.submitTeachConversationEvidence({ id: `opencode-teach:${sessionID}:${messageID}`, conversationId: sessionID, message: `User: ${prompt}
|
|
1985
2066
|
Assistant: ${output}`, consent: true, privacy: "CONSENTED_TENANT" }, { idempotencyKey: `opencode:teach:${sessionID}:${messageID}` });
|
|
1986
2067
|
}
|
|
@@ -1988,7 +2069,7 @@ Assistant: ${output}`, consent: true, privacy: "CONSENTED_TENANT" }, { idempoten
|
|
|
1988
2069
|
const applyModel = async (input, output) => {
|
|
1989
2070
|
const sessionId = text2(input.sessionID ?? input.conversationId ?? input.id);
|
|
1990
2071
|
const direct = text2(input.prompt ?? asRecord(input.message).text ?? input.input ?? output.prompt);
|
|
1991
|
-
const prompt = direct || prompts.
|
|
2072
|
+
const prompt = direct || prompts.peek(sessionId) || "";
|
|
1992
2073
|
if (!prompt.trim()) return;
|
|
1993
2074
|
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 });
|
|
1994
2075
|
if (!options.aiSystemId && !options.connectionId) connectedIdentity = runtime2.getConnectionIdentity();
|
|
@@ -2027,7 +2108,7 @@ Assistant: ${output}`, consent: true, privacy: "CONSENTED_TENANT" }, { idempoten
|
|
|
2027
2108
|
const messageID = text2(input.messageID) || text2(input.partID) || digest2(completed).slice(0, 16);
|
|
2028
2109
|
await recordConversationOutput(client, current, { eventId: `${sessionID}:assistant:${messageID}`, output: completed, conversationId: sessionID, requestId: messageID });
|
|
2029
2110
|
if (options.teachConsent === true) {
|
|
2030
|
-
const prompt =
|
|
2111
|
+
const prompt = teachPrompts.take(sessionID, messageID);
|
|
2031
2112
|
if (prompt) await client.submitTeachConversationEvidence({ id: `opencode-teach:${sessionID}:${messageID}`, conversationId: sessionID, message: `User: ${prompt}
|
|
2032
2113
|
Assistant: ${completed}`, consent: true, privacy: "CONSENTED_TENANT" }, { idempotencyKey: `opencode:teach:${sessionID}:${messageID}` });
|
|
2033
2114
|
}
|
|
@@ -2039,7 +2120,10 @@ Assistant: ${completed}`, consent: true, privacy: "CONSENTED_TENANT" }, { idempo
|
|
|
2039
2120
|
const sessionId = text2(input.sessionID ?? input.conversationId ?? input.id);
|
|
2040
2121
|
const message = asRecord(output.message ?? input.message);
|
|
2041
2122
|
const prompt = text2(message.text ?? message.content) || partsText(output.parts ?? input.parts);
|
|
2042
|
-
if (sessionId && prompt.trim())
|
|
2123
|
+
if (sessionId && prompt.trim()) {
|
|
2124
|
+
prompts.set(sessionId, prompt.trim());
|
|
2125
|
+
teachPrompts.put(sessionId, prompt.trim(), text2(input.messageID ?? input.requestId) || void 0, text2(input.turnID) || void 0);
|
|
2126
|
+
}
|
|
2043
2127
|
},
|
|
2044
2128
|
"chat.params": async (input, output) => applyModel(input, output),
|
|
2045
2129
|
"experimental.chat.system.transform": async (input, output) => applyModel(input, output),
|
|
@@ -2047,20 +2131,20 @@ Assistant: ${completed}`, consent: true, privacy: "CONSENTED_TENANT" }, { idempo
|
|
|
2047
2131
|
if (mode !== "enforce") return;
|
|
2048
2132
|
const metadata = asRecord(input.metadata);
|
|
2049
2133
|
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) };
|
|
2050
|
-
const decision = await runtime2.beforeTool(proposal);
|
|
2051
|
-
actionDecisions.set(contextKey(proposal) + ":" + proposal.callId, decision);
|
|
2134
|
+
const decision = cachedDecision(proposal) ?? cacheDecision(proposal, await runtime2.beforeTool(proposal));
|
|
2052
2135
|
output.status = decision.decision === "ALLOW" ? "allow" : "deny";
|
|
2053
2136
|
},
|
|
2054
2137
|
"tool.execute.before": async (input, output) => {
|
|
2055
2138
|
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) };
|
|
2056
|
-
const decision = await runtime2.beforeTool(proposal);
|
|
2057
|
-
actionDecisions.set(contextKey(proposal) + ":" + proposal.callId, decision);
|
|
2139
|
+
const decision = cachedDecision(proposal) ?? cacheDecision(proposal, await runtime2.beforeTool(proposal));
|
|
2058
2140
|
if (mode === "enforce" && decision.decision !== "ALLOW") throw new ViraOpenCodeActionError(decision.decision, text2(decision.reasonCode) || "VIRA_ACTION_NOT_ALLOWED");
|
|
2059
2141
|
},
|
|
2060
2142
|
"tool.execute.after": async (input, output) => {
|
|
2061
2143
|
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(input.args ?? input.input), traceId: text2(input.traceID), turnId: text2(input.turnID) };
|
|
2062
|
-
const
|
|
2063
|
-
|
|
2144
|
+
const key = contextKey(proposal) + ":" + proposal.callId;
|
|
2145
|
+
const decision = cachedDecision(proposal);
|
|
2146
|
+
actionDecisions.delete(key);
|
|
2147
|
+
actionDecisionDigests.delete(key);
|
|
2064
2148
|
try {
|
|
2065
2149
|
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 } : {} });
|
|
2066
2150
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryvira/opencode",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.60",
|
|
4
4
|
"description": "OpenCode host lifecycle integration for Vira",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
|
-
"exports": {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist/index.js",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "node ../../scripts/build-opencode-plugin.mjs",
|
|
16
|
+
"pack:check": "npm run build && node ../../scripts/opencode-plugin-smoke.mjs && node ../../scripts/opencode-plugin-host-acceptance.mjs"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@tryvira/sdk": "0.1.66"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"effect": "^4.0.0"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=20"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@opencode/plugin": "^2.3.2"
|
|
30
|
+
}
|
|
14
31
|
}
|