@tryvira/opencode 0.1.54 → 0.1.56
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 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// src/index.ts
|
|
1
|
+
// packages/opencode-plugin/src/index.ts
|
|
2
2
|
import { createHash as createHash2 } from "node:crypto";
|
|
3
3
|
|
|
4
|
-
//
|
|
4
|
+
// sdks/js-client.ts
|
|
5
5
|
var ViraApiError = class extends Error {
|
|
6
6
|
status;
|
|
7
7
|
body;
|
|
@@ -1200,7 +1200,7 @@ function buildObservationRequest(event) {
|
|
|
1200
1200
|
});
|
|
1201
1201
|
}
|
|
1202
1202
|
|
|
1203
|
-
//
|
|
1203
|
+
// sdks/host-lifecycle.ts
|
|
1204
1204
|
import { createHash } from "node:crypto";
|
|
1205
1205
|
var nonEmpty = (value, code) => {
|
|
1206
1206
|
if (typeof value !== "string" || !value.trim()) throw new Error(code);
|
|
@@ -1472,7 +1472,7 @@ function createViraHostRuntime(client, config) {
|
|
|
1472
1472
|
return Object.freeze({ mode, capabilities, connectOnce, reconnect, getConnectionIdentity: () => connectionIdentity, beforeModel, beforeTool, afterTool, executeTool, cancelTool, endSession, getProjection: (identity) => projections.get(sessionKey({ ...identity, requestId: "projection", input: "" })), supportsPostModelVerification: capabilities.canInterceptResponseBeforeDisplay });
|
|
1473
1473
|
}
|
|
1474
1474
|
|
|
1475
|
-
// src/approval.ts
|
|
1475
|
+
// packages/opencode-plugin/src/approval.ts
|
|
1476
1476
|
var text = (value) => typeof value === "string" ? value.trim() : "";
|
|
1477
1477
|
var record = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
1478
1478
|
var errorCode = (error) => {
|
|
@@ -1502,7 +1502,7 @@ async function authorizeWithOneShotCustomerConfirmation(input) {
|
|
|
1502
1502
|
}
|
|
1503
1503
|
}
|
|
1504
1504
|
|
|
1505
|
-
// src/index.ts
|
|
1505
|
+
// packages/opencode-plugin/src/index.ts
|
|
1506
1506
|
var Plugin = { define: (plugin) => plugin };
|
|
1507
1507
|
var text2 = (value) => typeof value === "string" ? value : "";
|
|
1508
1508
|
var required2 = (value, code) => {
|
|
@@ -1511,6 +1511,13 @@ var required2 = (value, code) => {
|
|
|
1511
1511
|
return result;
|
|
1512
1512
|
};
|
|
1513
1513
|
var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
1514
|
+
var safeErrorCode = (error) => {
|
|
1515
|
+
if (error instanceof ViraApiError) {
|
|
1516
|
+
const body = asRecord(error.body);
|
|
1517
|
+
return text2(body.code) || text2(asRecord(body.error).code) || error.message;
|
|
1518
|
+
}
|
|
1519
|
+
return error instanceof Error ? error.message : "unknown";
|
|
1520
|
+
};
|
|
1514
1521
|
var canonical2 = (value) => Array.isArray(value) ? "[" + value.map(canonical2).join(",") + "]" : value && typeof value === "object" ? "{" + Object.entries(value).filter(([, child]) => child !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([key, child]) => JSON.stringify(key) + ":" + canonical2(child)).join(",") + "}" : JSON.stringify(value);
|
|
1515
1522
|
var digest2 = (value) => createHash2("sha256").update(canonical2(value), "utf8").digest("hex");
|
|
1516
1523
|
var messageContentText = (value) => {
|
|
@@ -1776,19 +1783,19 @@ var v2Plugin = Plugin.define({
|
|
|
1776
1783
|
for await (const raw of ctx.event.subscribe({ signal: controller.signal })) {
|
|
1777
1784
|
const event = asRecord(raw);
|
|
1778
1785
|
const props = asRecord(event.properties ?? event.data);
|
|
1779
|
-
const
|
|
1786
|
+
const eventPart = asRecord(props.part ?? props.message ?? props.output);
|
|
1780
1787
|
const feedback = asRecord(event.feedback ?? event.userFeedback);
|
|
1781
1788
|
const outcome = asRecord(event.outcome ?? event.businessOutcome);
|
|
1782
|
-
const conversationId = text2(event.conversationId ?? event.sessionID ?? event.sessionId ?? props.sessionID ?? props.sessionId ??
|
|
1789
|
+
const conversationId = text2(event.conversationId ?? event.sessionID ?? event.sessionId ?? props.sessionID ?? props.sessionId ?? eventPart.sessionID ?? eventPart.sessionId);
|
|
1783
1790
|
if (!conversationId) continue;
|
|
1784
1791
|
try {
|
|
1785
1792
|
const identity = { ...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, sessionId: sessionRef(event) || void 0 };
|
|
1786
1793
|
const eventId = text2(event.eventId ?? event.id ?? event.messageID ?? event.requestId) || `${conversationId}:${text2(event.type) || "event"}:${digest2(event).slice(0, 16)}`;
|
|
1787
|
-
const lineage = { conversationId, requestId: text2(event.requestId ?? event.messageID ??
|
|
1788
|
-
const isCompletedText = (text2(event.type) === "session.text.ended" || text2(event.type) === "message.part.updated") && text2(
|
|
1794
|
+
const lineage = { conversationId, requestId: text2(event.requestId ?? event.messageID ?? eventPart.messageID) || void 0, traceId: text2(event.traceId ?? event.traceID) || void 0, projectionDigest: text2(event.projectionDigest ?? event.projection_digest) || void 0, receiptDigest: text2(event.receiptDigest ?? event.receipt_digest) || void 0, releaseDigest: text2(event.releaseDigest ?? event.release_digest) || void 0, evaluationId: text2(event.evaluationId ?? event.evaluation_id) || void 0 };
|
|
1795
|
+
const isCompletedText = (text2(event.type) === "session.text.ended" || text2(event.type) === "message.part.updated") && text2(eventPart.type) === "text" && Boolean(asRecord(eventPart.time).end);
|
|
1789
1796
|
if (isCompletedText) {
|
|
1790
|
-
const output = text2(props.text ?? props.content ??
|
|
1791
|
-
if (output.trim()) await client.observe({ ...identity, eventId: `${conversationId}:conversation.output:${text2(
|
|
1797
|
+
const output = text2(props.text ?? props.content ?? eventPart.text ?? eventPart.content);
|
|
1798
|
+
if (output.trim()) await client.observe({ ...identity, eventId: `${conversationId}:conversation.output:${text2(eventPart.id) || digest2(output).slice(0, 16)}`, eventType: "conversation.output", conversationId, requestId: lineage.requestId, traceId: lineage.traceId, payload: { outputDigest: digest2(output), minimization: { rawTextSent: false, digestAlgorithm: "sha256" } }, resultDigest: digest2(output) }, { idempotencyKey: `opencode:conversation.output:${conversationId}:${text2(eventPart.id) || digest2(output).slice(0, 16)}` });
|
|
1792
1799
|
}
|
|
1793
1800
|
if (Object.keys(feedback).length) await recordUserCorrection(client, identity, { eventId, ...lineage, correctedText: text2(feedback.correctedText ?? feedback.text), status: text2(feedback.status) || "corrected", reasonCode: text2(feedback.reasonCode) || "OPENCODE_FEEDBACK" });
|
|
1794
1801
|
if (Object.keys(outcome).length) await recordBusinessOutcome(client, identity, { eventId: `${eventId}:outcome`, ...lineage, status: text2(outcome.status) || "unknown", value: outcome.value, reasonCode: text2(outcome.reasonCode) || "OPENCODE_OUTCOME" });
|
|
@@ -1962,11 +1969,11 @@ var v1Fallback = { async server(rawContext = {}) {
|
|
|
1962
1969
|
const envelope = asRecord(raw);
|
|
1963
1970
|
const event = asRecord(envelope.event ?? raw);
|
|
1964
1971
|
const data = asRecord(event.data ?? event.properties);
|
|
1965
|
-
const
|
|
1972
|
+
const eventPart = asRecord(data.part ?? data.message ?? data.output);
|
|
1973
|
+
const isCompletedText = (text2(event.type) === "session.text.ended" || text2(event.type) === "message.part.updated") && text2(eventPart.type) === "text" && Boolean(asRecord(eventPart.time).end);
|
|
1966
1974
|
if (!isCompletedText) return;
|
|
1967
|
-
const
|
|
1968
|
-
const
|
|
1969
|
-
const output = text2(data.text ?? data.content ?? part.text ?? part.content);
|
|
1975
|
+
const sessionID = text2(data.sessionID ?? data.sessionId ?? eventPart.sessionID ?? eventPart.sessionId);
|
|
1976
|
+
const output = text2(data.text ?? data.content ?? eventPart.text ?? eventPart.content);
|
|
1970
1977
|
if (!sessionID || !output.trim()) return;
|
|
1971
1978
|
const current = identity({ sessionID });
|
|
1972
1979
|
const messageID = text2(data.assistantMessageID) || text2(data.textID) || digest2(output).slice(0, 16);
|
|
@@ -2008,7 +2015,7 @@ Assistant: ${output}`, consent: true, privacy: "CONSENTED_TENANT" }, { idempoten
|
|
|
2008
2015
|
console.error("[tryvira] event", text2(observed.type));
|
|
2009
2016
|
await persistCompletedText(event);
|
|
2010
2017
|
} catch (error) {
|
|
2011
|
-
console.error("[tryvira] output event failed", error
|
|
2018
|
+
console.error("[tryvira] output event failed", safeErrorCode(error));
|
|
2012
2019
|
}
|
|
2013
2020
|
},
|
|
2014
2021
|
"experimental.text.complete": async (input, output) => {
|
|
@@ -2025,7 +2032,7 @@ Assistant: ${output}`, consent: true, privacy: "CONSENTED_TENANT" }, { idempoten
|
|
|
2025
2032
|
Assistant: ${completed}`, consent: true, privacy: "CONSENTED_TENANT" }, { idempotencyKey: `opencode:teach:${sessionID}:${messageID}` });
|
|
2026
2033
|
}
|
|
2027
2034
|
} catch (error) {
|
|
2028
|
-
console.error("[tryvira] text complete failed", error
|
|
2035
|
+
console.error("[tryvira] text complete failed", safeErrorCode(error));
|
|
2029
2036
|
}
|
|
2030
2037
|
},
|
|
2031
2038
|
"chat.message": async (input, output) => {
|
|
@@ -2076,7 +2083,7 @@ Object.assign(legacyDefault, v2Plugin, v1Fallback);
|
|
|
2076
2083
|
var server = v1Fallback.server;
|
|
2077
2084
|
var index_default = legacyDefault;
|
|
2078
2085
|
|
|
2079
|
-
// src/runtime-entry.ts
|
|
2086
|
+
// packages/opencode-plugin/src/runtime-entry.ts
|
|
2080
2087
|
var runtime = Object.assign(index_default, {
|
|
2081
2088
|
id: "vira",
|
|
2082
2089
|
setup: index_default.setup,
|