@tryvira/opencode 0.1.15 → 0.1.17
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 +17 -9
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -433,7 +433,8 @@ var ViraClient = class {
|
|
|
433
433
|
body: {
|
|
434
434
|
...input.behaviorPoint ? { behaviorPoint: input.behaviorPoint } : {},
|
|
435
435
|
...input.executionBoundary ? { executionBoundary: input.executionBoundary } : {},
|
|
436
|
-
...input.semanticContext ? { semanticContext: input.semanticContext } : {}
|
|
436
|
+
...input.semanticContext ? { semanticContext: input.semanticContext } : {},
|
|
437
|
+
...input.signalAttestationRefs ? { signalAttestationRefs: input.signalAttestationRefs } : {}
|
|
437
438
|
}
|
|
438
439
|
},
|
|
439
440
|
{
|
|
@@ -482,11 +483,12 @@ var ViraClient = class {
|
|
|
482
483
|
behaviorPoint,
|
|
483
484
|
capsule: firstCapsule,
|
|
484
485
|
...input.requestId ? { requestId: input.requestId } : {},
|
|
485
|
-
...input.sessionId ? { conversationId: input.sessionId } : {}
|
|
486
|
+
...input.sessionId ? { conversationId: input.sessionId } : {},
|
|
487
|
+
...input.signalAttestationRefs ? { signalAttestationRefs: input.signalAttestationRefs } : {}
|
|
486
488
|
},
|
|
487
489
|
idempotencyKey: input.idempotencyKey ? `sdk:runtime:${input.idempotencyKey}` : void 0
|
|
488
490
|
}) : await this.resolveRuntime({
|
|
489
|
-
semanticContext: { taskKey: receipt.taskKey, behaviorPoint, capsule: firstCapsule, ...input.requestId ? { requestId: input.requestId } : {}, ...input.sessionId ? { conversationId: input.sessionId } : {} },
|
|
491
|
+
semanticContext: { taskKey: receipt.taskKey, behaviorPoint, capsule: firstCapsule, ...input.requestId ? { requestId: input.requestId } : {}, ...input.sessionId ? { conversationId: input.sessionId } : {}, ...input.signalAttestationRefs ? { signalAttestationRefs: input.signalAttestationRefs } : {} },
|
|
490
492
|
idempotencyKey: input.idempotencyKey ? `sdk:runtime:${input.idempotencyKey}` : void 0
|
|
491
493
|
});
|
|
492
494
|
return { semantic, runtime };
|
|
@@ -507,7 +509,12 @@ var ViraClient = class {
|
|
|
507
509
|
async createHostActionApproval(input) {
|
|
508
510
|
required(input.sessionId, "SDK_ACTION_SESSION_REQUIRED");
|
|
509
511
|
required(input.dataVersion, "SDK_ACTION_DATA_VERSION_REQUIRED");
|
|
510
|
-
|
|
512
|
+
required(input.confirmation.proposalId, "SDK_ACTION_CONFIRMATION_PROPOSAL_REQUIRED");
|
|
513
|
+
required(input.confirmation.toolName, "SDK_ACTION_CONFIRMATION_TOOL_REQUIRED");
|
|
514
|
+
required(input.confirmation.argumentsDigest, "SDK_ACTION_CONFIRMATION_ARGUMENTS_REQUIRED");
|
|
515
|
+
required(input.confirmation.requestContextDigest, "SDK_ACTION_CONFIRMATION_CONTEXT_REQUIRED");
|
|
516
|
+
required(input.confirmation.acknowledgedAt, "SDK_ACTION_CONFIRMATION_TIME_REQUIRED");
|
|
517
|
+
return this.request({ method: "POST", path: "/v1/runtime/actions/approvals", body: { sessionId: input.sessionId, dataVersion: input.dataVersion, proposal: input.proposal, confirmation: input.confirmation, ...input.ttlSeconds !== void 0 ? { ttlSeconds: input.ttlSeconds } : {} } });
|
|
511
518
|
}
|
|
512
519
|
listBehaviorStrategies() {
|
|
513
520
|
return this.request({
|
|
@@ -1197,7 +1204,7 @@ function createViraHostRuntime(client, config) {
|
|
|
1197
1204
|
if (mode === "off") return { status: "off" };
|
|
1198
1205
|
if (!capabilities.canInjectContext) return { status: "unavailable", reasonCode: "HOST_CONTEXT_INJECTION_UNSUPPORTED" };
|
|
1199
1206
|
await connectOnce();
|
|
1200
|
-
const semantic = await withTimeout(client.resolveSemanticRuntime({ input: request.input, sessionId: request.sessionId ?? request.conversationId, requestId: request.requestId }), timeoutMs, "SDK_HOST_RESOLVE_TIMEOUT");
|
|
1207
|
+
const semantic = await withTimeout(client.resolveSemanticRuntime({ input: request.input, sessionId: request.sessionId ?? request.conversationId, requestId: request.requestId, signalAttestationRefs: request.signalAttestationRefs }), timeoutMs, "SDK_HOST_RESOLVE_TIMEOUT");
|
|
1201
1208
|
if (!semantic) return { status: "unavailable", reasonCode: "VIRA_SEMANTIC_UNAVAILABLE" };
|
|
1202
1209
|
const semanticBody = bodyOf(semantic.semantic);
|
|
1203
1210
|
const receipt = semanticBody.receipt && typeof semanticBody.receipt === "object" ? semanticBody.receipt : {};
|
|
@@ -1269,7 +1276,7 @@ var errorCode = (error) => {
|
|
|
1269
1276
|
return text(body.code) || text(record(body.error).code) || (error instanceof Error ? error.message : "");
|
|
1270
1277
|
};
|
|
1271
1278
|
async function authorizeWithOneShotCustomerConfirmation(input) {
|
|
1272
|
-
const authorize = (approvalId) => input.client.authorizeHostAction({ executionId: input.executionId, sessionId: input.sessionId, dataVersion: input.dataVersion, scope: input.scope, context: input.context, proposal: input.proposalBody, ...approvalId ? { approval: { approvalId } } : {} });
|
|
1279
|
+
const authorize = (approvalId) => input.client.authorizeHostAction({ executionId: input.executionId, sessionId: input.sessionId, dataVersion: input.dataVersion, scope: input.scope, context: input.context, proposal: input.proposalBody, ...input.signalAttestationRefs?.length ? { signalAttestationRefs: input.signalAttestationRefs } : {}, ...approvalId ? { approval: { approvalId } } : {} });
|
|
1273
1280
|
try {
|
|
1274
1281
|
const response = await authorize(input.approvalId);
|
|
1275
1282
|
const body = record(response?.body);
|
|
@@ -1277,7 +1284,7 @@ async function authorizeWithOneShotCustomerConfirmation(input) {
|
|
|
1277
1284
|
} catch (error) {
|
|
1278
1285
|
if (errorCode(error) !== "RUNTIME_ACTION_USER_APPROVAL_REQUIRED" || input.approvalId || typeof input.confirmAction !== "function") return { decision: "BLOCK", reasonCode: errorCode(error) || "RUNTIME_ACTION_AUTHORIZATION_FAILED" };
|
|
1279
1286
|
if (await input.confirmAction({ ...input.proposal, approvalRequired: true }) !== true) return { decision: "BLOCK", reasonCode: "RUNTIME_ACTION_CUSTOMER_CONFIRMATION_DENIED" };
|
|
1280
|
-
const issued = await input.client.createHostActionApproval({ sessionId: input.sessionId, dataVersion: input.dataVersion, proposal: input.proposalBody,
|
|
1287
|
+
const issued = await input.client.createHostActionApproval({ sessionId: input.sessionId, dataVersion: input.dataVersion, proposal: input.proposalBody, confirmation: { proposalId: text(input.proposalBody.proposal_id), toolName: text(input.proposalBody.tool_key), argumentsDigest: text(input.proposalBody.arguments_digest), requestContextDigest: text(input.proposalBody.request_context_digest), acknowledgedAt: (/* @__PURE__ */ new Date()).toISOString() } });
|
|
1281
1288
|
const approvalId = text(record(issued?.body).approvalId);
|
|
1282
1289
|
if (!approvalId) return { decision: "ERROR", reasonCode: "RUNTIME_ACTION_APPROVAL_RECEIPT_MISSING" };
|
|
1283
1290
|
try {
|
|
@@ -1362,7 +1369,8 @@ var v2Plugin = Plugin.define({
|
|
|
1362
1369
|
const approval = typeof approvalCandidate.approvalId === "string" && approvalCandidate.approvalId.trim() ? { approvalId: approvalCandidate.approvalId.trim() } : void 0;
|
|
1363
1370
|
const dataVersion = text2(bound.context.release_digest);
|
|
1364
1371
|
if (!dataVersion) return { decision: "BLOCK", reasonCode: "RUNTIME_ACTION_DATA_VERSION_UNAVAILABLE" };
|
|
1365
|
-
|
|
1372
|
+
const refs = Array.isArray(bound.context.signal_attestation_refs) ? bound.context.signal_attestation_refs : [];
|
|
1373
|
+
return authorizeWithOneShotCustomerConfirmation({ client, proposal, proposalBody, signalAttestationRefs: refs, executionId: bound.executionId, sessionId: proposal.sessionId ?? proposal.conversationId, dataVersion, scope, context: bound.context, confirmAction: options.confirmAction, approvalId: approval?.approvalId });
|
|
1366
1374
|
}), ...(options.aiSystemId ?? env("VIRA_AI_SYSTEM_ID")) && (options.connectionId ?? env("VIRA_CONNECTION_ID")) ? {} : { connect: { ...scope, name: "OpenCode", systemType: "agent", adapterType: "custom-node", adapterVersion: options.hostVersion ?? ctx.app?.version ?? "unknown", idempotencyKey: "opencode:vira:connect" } } });
|
|
1367
1375
|
let connectedAiSystemId = options.aiSystemId ?? env("VIRA_AI_SYSTEM_ID") ?? "";
|
|
1368
1376
|
let connectedConnectionId = options.connectionId ?? env("VIRA_CONNECTION_ID") ?? "";
|
|
@@ -1376,7 +1384,7 @@ var v2Plugin = Plugin.define({
|
|
|
1376
1384
|
const sessionIdentity = (event) => ({ ...scope, hostName: options.hostName ?? "opencode", hostVersion: options.hostVersion ?? ctx.app?.version ?? "unknown", aiSystemId: required2(connectedAiSystemId, "VIRA_HOST_AI_SYSTEM_REQUIRED"), connectionId: required2(connectedConnectionId, "VIRA_HOST_CONNECTION_REQUIRED"), conversationId: required2(event.conversationId ?? event.sessionID, "VIRA_HOST_SESSION_REQUIRED"), sessionId: text2(event.sessionId ?? event.sessionID ?? event.conversationId) || void 0 });
|
|
1377
1385
|
registrations.push(await ctx.session.hook("context", async (event) => {
|
|
1378
1386
|
const identity = sessionIdentity(event);
|
|
1379
|
-
const result = await runtime.beforeModel({ ...identity, requestId: text2(event.messageID ?? event.requestId) || `opencode:${Date.now()}`, input: required2(lastUserText(event), "VIRA_HOST_MODEL_INPUT_REQUIRED"), traceId: text2(event.traceID), turnId: text2(event.turnID) });
|
|
1387
|
+
const result = await runtime.beforeModel({ ...identity, requestId: text2(event.messageID ?? event.requestId) || `opencode:${Date.now()}`, input: required2(lastUserText(event), "VIRA_HOST_MODEL_INPUT_REQUIRED"), traceId: text2(event.traceID), turnId: text2(event.turnID), signalAttestationRefs: options.signalAttestationRefs });
|
|
1380
1388
|
const responseBody = asRecord(result.response?.body);
|
|
1381
1389
|
const runtimeContext = asRecord(event.viraRuntimeContext ?? responseBody.requestContext ?? responseBody.context);
|
|
1382
1390
|
const executionId = text2(event.executionId ?? responseBody.executionId);
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryvira/opencode",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
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.57"},
|
|
11
11
|
"peerDependencies": {"effect": "^4.0.0"},
|
|
12
12
|
"engines": {"node": ">=20"},
|
|
13
13
|
"license": "MIT"
|