@tryvira/opencode 0.1.37 → 0.1.39
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/README.md +1 -1
- package/dist/index.js +34 -22
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1883,8 +1883,16 @@ var v1Runtime = (options) => {
|
|
|
1883
1883
|
const actionContexts = /* @__PURE__ */ new Map();
|
|
1884
1884
|
const actionDecisions = /* @__PURE__ */ new Map();
|
|
1885
1885
|
const contextKey = (identity) => identity.organizationId + ":" + identity.projectId + ":" + identity.environmentId + ":" + identity.conversationId + ":" + (identity.sessionId ?? identity.conversationId);
|
|
1886
|
+
const findActionContext = (proposal) => {
|
|
1887
|
+
const exact = actionContexts.get(contextKey(proposal));
|
|
1888
|
+
if (exact) return exact;
|
|
1889
|
+
const sessionId = proposal.sessionId ?? proposal.conversationId;
|
|
1890
|
+
for (const bound of actionContexts.values()) if (bound.sessionId === sessionId && bound.conversationId === proposal.conversationId) return bound;
|
|
1891
|
+
for (const bound of actionContexts.values()) if (bound.sessionId === sessionId) return bound;
|
|
1892
|
+
return void 0;
|
|
1893
|
+
};
|
|
1886
1894
|
const serverAuthorizeAction = async (proposal) => {
|
|
1887
|
-
const bound =
|
|
1895
|
+
const bound = findActionContext(proposal);
|
|
1888
1896
|
if (!bound) return { decision: "BLOCK", reasonCode: "RUNTIME_ACTION_CONTEXT_UNAVAILABLE" };
|
|
1889
1897
|
if (!Number.isFinite(bound.expiresAt) || Date.now() >= bound.expiresAt) {
|
|
1890
1898
|
actionContexts.delete(contextKey(proposal));
|
|
@@ -1924,6 +1932,29 @@ var v1Fallback = { async server(rawContext = {}) {
|
|
|
1924
1932
|
const hostVersion = hostVersionFor(options, rawContext);
|
|
1925
1933
|
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 });
|
|
1926
1934
|
const partsText = (value) => Array.isArray(value) ? value.map((part) => text2(asRecord(part).text)).filter(Boolean).join("\n") : "";
|
|
1935
|
+
const applyModel = async (input, output) => {
|
|
1936
|
+
const sessionId = text2(input.sessionID ?? input.conversationId ?? input.id);
|
|
1937
|
+
const direct = text2(input.prompt ?? asRecord(input.message).text ?? input.input ?? output.prompt);
|
|
1938
|
+
const prompt = direct || prompts.take(sessionId) || "";
|
|
1939
|
+
if (!prompt.trim()) return;
|
|
1940
|
+
const result = await runtime2.beforeModel({ ...identity(input), requestId: text2(input.messageID ?? input.requestId) || `opencode:${Date.now()}`, input: prompt, profile: conversationProfile(input, options), traceId: text2(input.traceID), turnId: text2(input.turnID), signalAttestationRefs: options.signalAttestationRefs });
|
|
1941
|
+
if (!options.aiSystemId && !options.connectionId) connectedIdentity = runtime2.getConnectionIdentity();
|
|
1942
|
+
const responseBody = asRecord(result.response?.body);
|
|
1943
|
+
const runtimeContext = asRecord(responseBody.requestContext ?? responseBody.context);
|
|
1944
|
+
const executionId = text2(input.executionId ?? responseBody.executionId);
|
|
1945
|
+
const expiresAt = Number(runtimeContext.expires_at_unix_ms);
|
|
1946
|
+
const current = identity(input);
|
|
1947
|
+
if (executionId && runtimeContext.abi === "vira.request-behavior-context.v2" && Number.isFinite(expiresAt) && expiresAt > Date.now()) actionContexts.set(contextKey(current), { executionId, context: runtimeContext, sessionId: current.sessionId ?? current.conversationId, conversationId: current.conversationId, expiresAt });
|
|
1948
|
+
else actionContexts.delete(contextKey(current));
|
|
1949
|
+
const modelPolicy = asRecord(responseBody.modelPolicy ?? responseBody.model_policy);
|
|
1950
|
+
const hostOptions = asRecord(output.options ?? input.options);
|
|
1951
|
+
for (const key of ["maxTokens", "temperature", "model", "provider"]) if (Object.hasOwn(modelPolicy, key) && (typeof modelPolicy[key] === "number" && Number.isFinite(modelPolicy[key]) || typeof modelPolicy[key] === "string")) hostOptions[key] = modelPolicy[key];
|
|
1952
|
+
if (Object.keys(hostOptions).length) output.options = hostOptions;
|
|
1953
|
+
if (result.status === "applied" && result.projection) {
|
|
1954
|
+
if (Array.isArray(output.system)) output.system = [...output.system, result.projection];
|
|
1955
|
+
else output.system = [result.projection];
|
|
1956
|
+
}
|
|
1957
|
+
};
|
|
1927
1958
|
return {
|
|
1928
1959
|
"chat.message": async (input, output) => {
|
|
1929
1960
|
const sessionId = text2(input.sessionID ?? input.conversationId ?? input.id);
|
|
@@ -1931,27 +1962,8 @@ var v1Fallback = { async server(rawContext = {}) {
|
|
|
1931
1962
|
const prompt = text2(message.text ?? message.content) || partsText(output.parts ?? input.parts);
|
|
1932
1963
|
if (sessionId && prompt.trim()) prompts.set(sessionId, prompt.trim());
|
|
1933
1964
|
},
|
|
1934
|
-
"chat.params": async (input, output) =>
|
|
1935
|
-
|
|
1936
|
-
const direct = text2(input.prompt ?? asRecord(input.message).text ?? input.input ?? output.prompt);
|
|
1937
|
-
const prompt = direct || prompts.take(sessionId) || "";
|
|
1938
|
-
if (!prompt.trim()) return;
|
|
1939
|
-
const result = await runtime2.beforeModel({ ...identity(input), requestId: text2(input.messageID ?? input.requestId) || `opencode:${Date.now()}`, input: prompt, profile: conversationProfile(input, options), traceId: text2(input.traceID), turnId: text2(input.turnID), signalAttestationRefs: options.signalAttestationRefs });
|
|
1940
|
-
if (!options.aiSystemId && !options.connectionId) connectedIdentity = runtime2.getConnectionIdentity();
|
|
1941
|
-
const responseBody = asRecord(result.response?.body);
|
|
1942
|
-
const runtimeContext = asRecord(responseBody.requestContext ?? responseBody.context);
|
|
1943
|
-
const executionId = text2(input.executionId ?? responseBody.executionId);
|
|
1944
|
-
const expiresAt = Number(runtimeContext.expires_at_unix_ms);
|
|
1945
|
-
const current = identity(input);
|
|
1946
|
-
if (executionId && runtimeContext.abi === "vira.request-behavior-context.v2" && Number.isFinite(expiresAt) && expiresAt > Date.now()) actionContexts.set(contextKey(current), { executionId, context: runtimeContext, sessionId: current.sessionId ?? current.conversationId, conversationId: current.conversationId, expiresAt });
|
|
1947
|
-
else actionContexts.delete(contextKey(current));
|
|
1948
|
-
const policyBody = asRecord(result.response?.body);
|
|
1949
|
-
const modelPolicy = asRecord(policyBody.modelPolicy ?? policyBody.model_policy);
|
|
1950
|
-
const hostOptions = asRecord(output.options ?? input.options);
|
|
1951
|
-
for (const key of ["maxTokens", "temperature", "model", "provider"]) if (Object.hasOwn(modelPolicy, key) && (typeof modelPolicy[key] === "number" && Number.isFinite(modelPolicy[key]) || typeof modelPolicy[key] === "string")) hostOptions[key] = modelPolicy[key];
|
|
1952
|
-
if (Object.keys(hostOptions).length) output.options = hostOptions;
|
|
1953
|
-
if (result.status === "applied" && result.projection) output.system = [...Array.isArray(output.system) ? output.system : [], result.projection];
|
|
1954
|
-
},
|
|
1965
|
+
"chat.params": async (input, output) => applyModel(input, output),
|
|
1966
|
+
"experimental.chat.system.transform": async (input, output) => applyModel(input, output),
|
|
1955
1967
|
"permission.ask": async (input, output) => {
|
|
1956
1968
|
if (mode !== "enforce") return;
|
|
1957
1969
|
const metadata = asRecord(input.metadata);
|