@tryvira/opencode 0.1.2 → 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 +25 -5
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1163,10 +1163,20 @@ function createViraHostRuntime(client, config) {
|
|
|
1163
1163
|
if (mode === "enforce" && (!capabilities.canInterceptToolBefore || !capabilities.canPreventSideEffect)) throw new Error("SDK_HOST_ENFORCE_CAPABILITY_REQUIRED");
|
|
1164
1164
|
if (mode === "enforce" && typeof config.authorizeAction !== "function") throw new Error("SDK_HOST_ACTION_AUTHORIZER_REQUIRED");
|
|
1165
1165
|
let connected = null;
|
|
1166
|
+
let connectionIdentity = null;
|
|
1166
1167
|
const projections = /* @__PURE__ */ new Map();
|
|
1167
1168
|
const connectOnce = async () => {
|
|
1168
1169
|
if (mode === "off" || !config.connect) return null;
|
|
1169
|
-
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
|
+
});
|
|
1170
1180
|
return connected;
|
|
1171
1181
|
};
|
|
1172
1182
|
const sessionKey = (request) => `${request.organizationId}:${request.projectId}:${request.environmentId}:${request.conversationId}`;
|
|
@@ -1217,7 +1227,7 @@ function createViraHostRuntime(client, config) {
|
|
|
1217
1227
|
const endSession = (identity) => {
|
|
1218
1228
|
projections.delete(sessionKey({ ...identity, requestId: "session-end", input: "" }));
|
|
1219
1229
|
};
|
|
1220
|
-
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 });
|
|
1221
1231
|
}
|
|
1222
1232
|
|
|
1223
1233
|
// src/index.ts
|
|
@@ -1273,8 +1283,16 @@ var v2Plugin = Plugin.define({
|
|
|
1273
1283
|
return { decision: "ERROR", reasonCode: error instanceof Error ? error.message : "RUNTIME_ACTION_AUTHORIZATION_FAILED" };
|
|
1274
1284
|
}
|
|
1275
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
|
+
}
|
|
1276
1294
|
const registrations = [];
|
|
1277
|
-
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") });
|
|
1278
1296
|
registrations.push(await ctx.session.hook("context", async (event) => {
|
|
1279
1297
|
const identity = sessionIdentity(event);
|
|
1280
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) });
|
|
@@ -1313,15 +1331,17 @@ var v1Runtime = () => {
|
|
|
1313
1331
|
if (mode === "off") return null;
|
|
1314
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") };
|
|
1315
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") });
|
|
1316
|
-
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" }) }) };
|
|
1317
1335
|
};
|
|
1318
1336
|
var index_default = { ...v2Plugin, async server() {
|
|
1319
1337
|
const configured = v1Runtime();
|
|
1320
1338
|
if (!configured) return {};
|
|
1321
1339
|
const { mode, scope, runtime } = configured;
|
|
1340
|
+
await runtime.connectOnce();
|
|
1341
|
+
const connectedIdentity = runtime.getConnectionIdentity();
|
|
1322
1342
|
const env = (name) => typeof process !== "undefined" ? process.env[name] : void 0;
|
|
1323
1343
|
const prompts = /* @__PURE__ */ new Map();
|
|
1324
|
-
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") });
|
|
1325
1345
|
const partsText = (value) => Array.isArray(value) ? value.map((part) => text(asRecord(part).text)).filter(Boolean).join("\n") : "";
|
|
1326
1346
|
return {
|
|
1327
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"
|