@tryvira/opencode 0.1.1 → 0.1.3
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 +29 -7
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -475,11 +475,13 @@ var ViraClient = class {
|
|
|
475
475
|
semanticContext: {
|
|
476
476
|
taskKey: receipt.taskKey,
|
|
477
477
|
behaviorPoint,
|
|
478
|
-
capsule: firstCapsule
|
|
478
|
+
capsule: firstCapsule,
|
|
479
|
+
...input.requestId ? { requestId: input.requestId } : {},
|
|
480
|
+
...input.sessionId ? { conversationId: input.sessionId } : {}
|
|
479
481
|
},
|
|
480
482
|
idempotencyKey: input.idempotencyKey ? `sdk:runtime:${input.idempotencyKey}` : void 0
|
|
481
483
|
}) : await this.resolveRuntime({
|
|
482
|
-
semanticContext: { taskKey: receipt.taskKey, behaviorPoint, capsule: firstCapsule },
|
|
484
|
+
semanticContext: { taskKey: receipt.taskKey, behaviorPoint, capsule: firstCapsule, ...input.requestId ? { requestId: input.requestId } : {}, ...input.sessionId ? { conversationId: input.sessionId } : {} },
|
|
483
485
|
idempotencyKey: input.idempotencyKey ? `sdk:runtime:${input.idempotencyKey}` : void 0
|
|
484
486
|
});
|
|
485
487
|
return { semantic, runtime };
|
|
@@ -1161,10 +1163,20 @@ function createViraHostRuntime(client, config) {
|
|
|
1161
1163
|
if (mode === "enforce" && (!capabilities.canInterceptToolBefore || !capabilities.canPreventSideEffect)) throw new Error("SDK_HOST_ENFORCE_CAPABILITY_REQUIRED");
|
|
1162
1164
|
if (mode === "enforce" && typeof config.authorizeAction !== "function") throw new Error("SDK_HOST_ACTION_AUTHORIZER_REQUIRED");
|
|
1163
1165
|
let connected = null;
|
|
1166
|
+
let connectionIdentity = null;
|
|
1164
1167
|
const projections = /* @__PURE__ */ new Map();
|
|
1165
1168
|
const connectOnce = async () => {
|
|
1166
1169
|
if (mode === "off" || !config.connect) return null;
|
|
1167
|
-
if (!connected) connected = withTimeout(client.connectOnce(config.connect), timeoutMs, "SDK_HOST_CONNECT_TIMEOUT")
|
|
1170
|
+
if (!connected) connected = withTimeout(client.connectOnce(config.connect), timeoutMs, "SDK_HOST_CONNECT_TIMEOUT").then((result) => {
|
|
1171
|
+
const body = bodyOf(result);
|
|
1172
|
+
const system = body.system && typeof body.system === "object" ? body.system : {};
|
|
1173
|
+
const connection = body.connection && typeof body.connection === "object" ? body.connection : {};
|
|
1174
|
+
const aiSystemId = typeof system.id === "string" ? system.id.trim() : "";
|
|
1175
|
+
const connectionId = typeof connection.id === "string" ? connection.id.trim() : "";
|
|
1176
|
+
if (!aiSystemId || !connectionId) throw new Error("SDK_HOST_CONNECT_IDENTITY_MISSING");
|
|
1177
|
+
connectionIdentity = { aiSystemId, connectionId };
|
|
1178
|
+
return result;
|
|
1179
|
+
});
|
|
1168
1180
|
return connected;
|
|
1169
1181
|
};
|
|
1170
1182
|
const sessionKey = (request) => `${request.organizationId}:${request.projectId}:${request.environmentId}:${request.conversationId}`;
|
|
@@ -1215,7 +1227,7 @@ function createViraHostRuntime(client, config) {
|
|
|
1215
1227
|
const endSession = (identity) => {
|
|
1216
1228
|
projections.delete(sessionKey({ ...identity, requestId: "session-end", input: "" }));
|
|
1217
1229
|
};
|
|
1218
|
-
return Object.freeze({ mode, capabilities, connectOnce, beforeModel, beforeTool, afterTool, endSession, getProjection: (identity) => projections.get(sessionKey({ ...identity, requestId: "projection", input: "" })), supportsPostModelVerification: capabilities.canInterceptResponseBeforeDisplay });
|
|
1230
|
+
return Object.freeze({ mode, capabilities, connectOnce, getConnectionIdentity: () => connectionIdentity, beforeModel, beforeTool, afterTool, endSession, getProjection: (identity) => projections.get(sessionKey({ ...identity, requestId: "projection", input: "" })), supportsPostModelVerification: capabilities.canInterceptResponseBeforeDisplay });
|
|
1219
1231
|
}
|
|
1220
1232
|
|
|
1221
1233
|
// src/index.ts
|
|
@@ -1271,8 +1283,16 @@ var v2Plugin = Plugin.define({
|
|
|
1271
1283
|
return { decision: "ERROR", reasonCode: error instanceof Error ? error.message : "RUNTIME_ACTION_AUTHORIZATION_FAILED" };
|
|
1272
1284
|
}
|
|
1273
1285
|
}), ...(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" } } });
|
|
1286
|
+
let connectedAiSystemId = options.aiSystemId ?? env("VIRA_AI_SYSTEM_ID") ?? "";
|
|
1287
|
+
let connectedConnectionId = options.connectionId ?? env("VIRA_CONNECTION_ID") ?? "";
|
|
1288
|
+
if (!connectedAiSystemId || !connectedConnectionId) {
|
|
1289
|
+
await runtime.connectOnce();
|
|
1290
|
+
const identity = runtime.getConnectionIdentity();
|
|
1291
|
+
connectedAiSystemId = identity?.aiSystemId ?? "";
|
|
1292
|
+
connectedConnectionId = identity?.connectionId ?? "";
|
|
1293
|
+
}
|
|
1274
1294
|
const registrations = [];
|
|
1275
|
-
const sessionIdentity = (event) => ({ ...scope, hostName: options.hostName ?? "opencode", hostVersion: options.hostVersion ?? ctx.app?.version ?? "unknown", aiSystemId: required2(
|
|
1295
|
+
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.sessionID ?? event.conversationId, "VIRA_HOST_SESSION_REQUIRED") });
|
|
1276
1296
|
registrations.push(await ctx.session.hook("context", async (event) => {
|
|
1277
1297
|
const identity = sessionIdentity(event);
|
|
1278
1298
|
const result = await runtime.beforeModel({ ...identity, requestId: text(event.messageID ?? event.requestId) || `opencode:${Date.now()}`, input: required2(lastUserText(event), "VIRA_HOST_MODEL_INPUT_REQUIRED"), traceId: text(event.traceID), turnId: text(event.turnID) });
|
|
@@ -1311,15 +1331,17 @@ var v1Runtime = () => {
|
|
|
1311
1331
|
if (mode === "off") return null;
|
|
1312
1332
|
const scope = { organizationId: required2(env("VIRA_ORGANIZATION_ID"), "VIRA_HOST_ORGANIZATION_REQUIRED"), projectId: required2(env("VIRA_PROJECT_ID"), "VIRA_HOST_PROJECT_REQUIRED"), environmentId: required2(env("VIRA_ENVIRONMENT_ID"), "VIRA_HOST_ENVIRONMENT_REQUIRED") };
|
|
1313
1333
|
const client = new ViraClient({ baseUrl: required2(env("VIRA_CONTROL_URL") ?? env("VIRA_API_URL"), "VIRA_HOST_API_URL_REQUIRED"), apiKey: env("VIRA_API_KEY") });
|
|
1314
|
-
return { mode, scope, client, runtime: createViraHostRuntime(client, { mode, capabilities: { canObserveModel: true, canInjectContext: true, canInterceptToolBefore: true, canInspectToolAfter: true, canPreventSideEffect: mode === "enforce", canInterceptResponseBeforeDisplay: false }, authorizeAction: async () => ({ decision: "BLOCK", reasonCode: "VIRA_V1_ACTION_AUTHORIZER_UNAVAILABLE" }) }) };
|
|
1334
|
+
return { mode, scope, client, runtime: createViraHostRuntime(client, { mode, connect: { ...scope, name: "OpenCode", systemType: "agent", adapterType: "custom-node", adapterVersion: "1.19.5", idempotencyKey: "opencode:vira:connect" }, capabilities: { canObserveModel: true, canInjectContext: true, canInterceptToolBefore: true, canInspectToolAfter: true, canPreventSideEffect: mode === "enforce", canInterceptResponseBeforeDisplay: false }, authorizeAction: async () => ({ decision: "BLOCK", reasonCode: "VIRA_V1_ACTION_AUTHORIZER_UNAVAILABLE" }) }) };
|
|
1315
1335
|
};
|
|
1316
1336
|
var index_default = { ...v2Plugin, async server() {
|
|
1317
1337
|
const configured = v1Runtime();
|
|
1318
1338
|
if (!configured) return {};
|
|
1319
1339
|
const { mode, scope, runtime } = configured;
|
|
1340
|
+
await runtime.connectOnce();
|
|
1341
|
+
const connectedIdentity = runtime.getConnectionIdentity();
|
|
1320
1342
|
const env = (name) => typeof process !== "undefined" ? process.env[name] : void 0;
|
|
1321
1343
|
const prompts = /* @__PURE__ */ new Map();
|
|
1322
|
-
const identity = (input) => ({ ...scope, hostName: "opencode", hostVersion: "1.19.5", aiSystemId: required2(env("VIRA_AI_SYSTEM_ID"), "VIRA_HOST_AI_SYSTEM_REQUIRED"), connectionId: required2(env("VIRA_CONNECTION_ID"), "VIRA_HOST_CONNECTION_REQUIRED"), conversationId: required2(input.sessionID ?? input.conversationId ?? input.id, "VIRA_HOST_SESSION_REQUIRED") });
|
|
1344
|
+
const identity = (input) => ({ ...scope, hostName: "opencode", hostVersion: "1.19.5", aiSystemId: required2(connectedIdentity?.aiSystemId ?? env("VIRA_AI_SYSTEM_ID"), "VIRA_HOST_AI_SYSTEM_REQUIRED"), connectionId: required2(connectedIdentity?.connectionId ?? env("VIRA_CONNECTION_ID"), "VIRA_HOST_CONNECTION_REQUIRED"), conversationId: required2(input.sessionID ?? input.conversationId ?? input.id, "VIRA_HOST_SESSION_REQUIRED") });
|
|
1323
1345
|
const partsText = (value) => Array.isArray(value) ? value.map((part) => text(asRecord(part).text)).filter(Boolean).join("\n") : "";
|
|
1324
1346
|
return {
|
|
1325
1347
|
"chat.message": async (input, output) => {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryvira/opencode",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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", "README.md"],
|
|
9
9
|
"scripts": {"build": "node ../../scripts/build-opencode-plugin.mjs", "pack:check": "npm run build && npm pack --dry-run"},
|
|
10
|
-
"dependencies": {"@tryvira/sdk": "0.1.
|
|
10
|
+
"dependencies": {"@tryvira/sdk": "0.1.49"},
|
|
11
11
|
"peerDependencies": {"effect": "^4.0.0"},
|
|
12
12
|
"engines": {"node": ">=20"},
|
|
13
13
|
"license": "MIT"
|