@tryvira/opencode 0.1.42 → 0.1.44

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.
Files changed (2) hide show
  1. package/dist/index.js +40 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1938,7 +1938,7 @@ var v1Fallback = { async server(rawContext = {}) {
1938
1938
  const options = readHostOptions(rawContext);
1939
1939
  const configured = v1Runtime(options);
1940
1940
  if (!configured) return {};
1941
- const { mode, scope, runtime: runtime2, actionContexts, actionDecisions, contextKey } = configured;
1941
+ const { mode, scope, client, runtime: runtime2, actionContexts, actionDecisions, contextKey } = configured;
1942
1942
  if (!options.aiSystemId || !options.connectionId) await runtime2.connectOnce();
1943
1943
  let connectedIdentity = runtime2.getConnectionIdentity();
1944
1944
  const env = envValue;
@@ -1951,6 +1951,23 @@ var v1Fallback = { async server(rawContext = {}) {
1951
1951
  const hostVersion = hostVersionFor(options, rawContext);
1952
1952
  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 });
1953
1953
  const partsText = (value) => Array.isArray(value) ? value.map((part) => text2(asRecord(part).text)).filter(Boolean).join("\n") : "";
1954
+ const persistCompletedText = async (raw) => {
1955
+ const event = asRecord(raw);
1956
+ const data = asRecord(event.data ?? event.properties);
1957
+ if (text2(event.type) !== "session.next.text.ended") return;
1958
+ const sessionID = text2(data.sessionID);
1959
+ const output = text2(data.text);
1960
+ if (!sessionID || !output.trim()) return;
1961
+ const current = identity({ sessionID });
1962
+ const messageID = text2(data.assistantMessageID) || text2(data.textID) || digest2(output).slice(0, 16);
1963
+ const eventId = `${sessionID}:assistant:${messageID}`;
1964
+ await recordConversationOutput(client, current, { eventId, output, conversationId: sessionID, requestId: messageID, traceId: text2(data.traceID) || void 0 });
1965
+ if (options.teachConsent === true) {
1966
+ const prompt = prompts.take(sessionID);
1967
+ if (prompt) await client.submitTeachConversationEvidence({ id: `opencode-teach:${sessionID}:${messageID}`, conversationId: sessionID, message: `User: ${prompt}
1968
+ Assistant: ${output}`, consent: true, privacy: "CONSENTED_TENANT" }, { idempotencyKey: `opencode:teach:${sessionID}:${messageID}` });
1969
+ }
1970
+ };
1954
1971
  const applyModel = async (input, output) => {
1955
1972
  const sessionId = text2(input.sessionID ?? input.conversationId ?? input.id);
1956
1973
  const direct = text2(input.prompt ?? asRecord(input.message).text ?? input.input ?? output.prompt);
@@ -1975,6 +1992,28 @@ var v1Fallback = { async server(rawContext = {}) {
1975
1992
  }
1976
1993
  };
1977
1994
  return {
1995
+ event: async ({ event }) => {
1996
+ try {
1997
+ await persistCompletedText(event);
1998
+ } catch {
1999
+ }
2000
+ },
2001
+ "experimental.text.complete": async (input, output) => {
2002
+ try {
2003
+ const sessionID = text2(input.sessionID);
2004
+ const completed = text2(output.text);
2005
+ if (!sessionID || !completed.trim()) return;
2006
+ const current = identity({ sessionID });
2007
+ const messageID = text2(input.messageID) || text2(input.partID) || digest2(completed).slice(0, 16);
2008
+ await recordConversationOutput(client, current, { eventId: `${sessionID}:assistant:${messageID}`, output: completed, conversationId: sessionID, requestId: messageID });
2009
+ if (options.teachConsent === true) {
2010
+ const prompt = prompts.take(sessionID);
2011
+ if (prompt) await client.submitTeachConversationEvidence({ id: `opencode-teach:${sessionID}:${messageID}`, conversationId: sessionID, message: `User: ${prompt}
2012
+ Assistant: ${completed}`, consent: true, privacy: "CONSENTED_TENANT" }, { idempotencyKey: `opencode:teach:${sessionID}:${messageID}` });
2013
+ }
2014
+ } catch {
2015
+ }
2016
+ },
1978
2017
  "chat.message": async (input, output) => {
1979
2018
  const sessionId = text2(input.sessionID ?? input.conversationId ?? input.id);
1980
2019
  const message = asRecord(output.message ?? input.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryvira/opencode",
3
- "version": "0.1.42",
3
+ "version": "0.1.44",
4
4
  "description": "OpenCode host lifecycle integration for Vira",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",