@openclaw/opencode-provider 2026.8.1-beta.2 → 2026.9.1-beta.1
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 +7 -624
- package/dist/provider-catalog-Dak_lvHJ.js +429 -0
- package/dist/provider-catalog.js +2 -1218
- package/dist/provider-discovery.js +1 -1
- package/dist/provider-policy-api.js +1 -1
- package/dist/session-catalog-plugin.js +168 -327
- package/dist/session-catalog-shared.js +1 -2
- package/dist/session-catalog.js +55 -170
- package/openclaw.plugin.json +34 -491
- package/package.json +4 -4
- package/dist/doctor-contract-api.js +0 -170
- package/dist/session-catalog-terminal.js +0 -104
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { normalizeProviderId, parseModelRef } from "openclaw/plugin-sdk/model-ref-parse";
|
|
2
|
-
import { asObjectRecord } from "openclaw/plugin-sdk/runtime-doctor-migrations";
|
|
3
|
-
//#region extensions/opencode/doctor-contract-api.ts
|
|
4
|
-
const RETIRED_MODEL = "hy3-free";
|
|
5
|
-
const REPLACEMENT_MODEL = "laguna-s-2.1-free";
|
|
6
|
-
const REPLACEMENT_REF = `opencode/${REPLACEMENT_MODEL}`;
|
|
7
|
-
const AGENT_MODEL_KEYS = [
|
|
8
|
-
"model",
|
|
9
|
-
"utilityModel",
|
|
10
|
-
"imageModel",
|
|
11
|
-
"voiceModel",
|
|
12
|
-
"pdfModel"
|
|
13
|
-
];
|
|
14
|
-
function replacementFor(value) {
|
|
15
|
-
if (typeof value !== "string") return;
|
|
16
|
-
const trimmed = value.trim();
|
|
17
|
-
const slash = trimmed.indexOf("/");
|
|
18
|
-
const suffixAt = trimmed.indexOf("@", slash + 1);
|
|
19
|
-
const suffix = suffixAt >= 0 ? trimmed.slice(suffixAt) : "";
|
|
20
|
-
if (suffix === "@" || suffix.includes("/")) return;
|
|
21
|
-
const parsed = parseModelRef(suffixAt >= 0 ? trimmed.slice(0, suffixAt) : trimmed, "");
|
|
22
|
-
if (parsed?.provider.toLowerCase() !== "opencode" || parsed.model.toLowerCase() !== RETIRED_MODEL) return;
|
|
23
|
-
return `${REPLACEMENT_REF}${suffix}`;
|
|
24
|
-
}
|
|
25
|
-
function rewriteString(owner, key, path, changes) {
|
|
26
|
-
if (!owner) return;
|
|
27
|
-
const replacement = replacementFor(owner[key]);
|
|
28
|
-
if (!replacement) return;
|
|
29
|
-
owner[key] = replacement;
|
|
30
|
-
changes.push(`Updated ${path} from the retired OpenCode Zen model to ${REPLACEMENT_REF}.`);
|
|
31
|
-
}
|
|
32
|
-
function rewriteSelector(owner, key, path, changes) {
|
|
33
|
-
if (!owner) return;
|
|
34
|
-
if (typeof owner[key] === "string") {
|
|
35
|
-
rewriteString(owner, key, path, changes);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const selector = asObjectRecord(owner[key]);
|
|
39
|
-
if (!selector) return;
|
|
40
|
-
rewriteString(selector, "primary", `${path}.primary`, changes);
|
|
41
|
-
if (!Array.isArray(selector.fallbacks)) return;
|
|
42
|
-
rewriteStringList(selector.fallbacks, `${path}.fallbacks`, changes);
|
|
43
|
-
}
|
|
44
|
-
function rewriteStringList(values, path, changes) {
|
|
45
|
-
for (const [index, value] of values.entries()) {
|
|
46
|
-
const replacement = replacementFor(value);
|
|
47
|
-
if (!replacement) continue;
|
|
48
|
-
values[index] = replacement;
|
|
49
|
-
changes.push(`Updated ${path}.${index} from the retired OpenCode Zen model to ${REPLACEMENT_REF}.`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
function rewriteModelMap(agent, path, changes) {
|
|
53
|
-
const models = asObjectRecord(agent.models);
|
|
54
|
-
if (!models) return;
|
|
55
|
-
for (const [modelRef, config] of Object.entries(models)) {
|
|
56
|
-
const replacement = replacementFor(modelRef);
|
|
57
|
-
if (!replacement) continue;
|
|
58
|
-
if (!Object.hasOwn(models, replacement)) models[replacement] = config;
|
|
59
|
-
delete models[modelRef];
|
|
60
|
-
changes.push(`Updated a retired OpenCode Zen model key in ${path} to ${REPLACEMENT_REF}.`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function rewriteExecReviewer(owner, path, changes) {
|
|
64
|
-
rewriteSelector(asObjectRecord(asObjectRecord(asObjectRecord(owner.tools)?.exec)?.reviewer), "model", path, changes);
|
|
65
|
-
}
|
|
66
|
-
function rewriteDiscordVoice(value, path, changes) {
|
|
67
|
-
const voice = asObjectRecord(value);
|
|
68
|
-
rewriteString(voice, "model", `${path}.model`, changes);
|
|
69
|
-
rewriteString(asObjectRecord(voice?.tts), "summaryModel", `${path}.tts.summaryModel`, changes);
|
|
70
|
-
}
|
|
71
|
-
function rewriteStructuredMediaModels(root, changes) {
|
|
72
|
-
const models = asObjectRecord(asObjectRecord(root.tools)?.media)?.models;
|
|
73
|
-
if (!Array.isArray(models)) return;
|
|
74
|
-
for (const [index, value] of models.entries()) {
|
|
75
|
-
const entry = asObjectRecord(value);
|
|
76
|
-
if (!entry || entry.type === "cli" || typeof entry.command === "string" && entry.command.trim() || typeof entry.provider !== "string" || normalizeProviderId(entry.provider) !== "opencode" || typeof entry.model !== "string" || entry.model.trim().toLowerCase() !== RETIRED_MODEL) continue;
|
|
77
|
-
entry.provider = "opencode";
|
|
78
|
-
entry.model = REPLACEMENT_MODEL;
|
|
79
|
-
changes.push(`Updated tools.media.models.${index} to the current OpenCode Zen model.`);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
function rewriteAgent(value, path, changes, includeEntrySelectors = false) {
|
|
83
|
-
const agent = asObjectRecord(value);
|
|
84
|
-
if (!agent) return;
|
|
85
|
-
for (const key of AGENT_MODEL_KEYS) rewriteSelector(agent, key, `${path}.${key}`, changes);
|
|
86
|
-
const mediaModels = asObjectRecord(agent.mediaModels);
|
|
87
|
-
for (const capability of [
|
|
88
|
-
"image",
|
|
89
|
-
"video",
|
|
90
|
-
"music"
|
|
91
|
-
]) rewriteSelector(mediaModels, capability, `${path}.mediaModels.${capability}`, changes);
|
|
92
|
-
rewriteString(asObjectRecord(agent.heartbeat), "model", `${path}.heartbeat.model`, changes);
|
|
93
|
-
rewriteSelector(asObjectRecord(agent.subagents), "model", `${path}.subagents.model`, changes);
|
|
94
|
-
const compaction = asObjectRecord(agent.compaction);
|
|
95
|
-
rewriteString(compaction, "model", `${path}.compaction.model`, changes);
|
|
96
|
-
rewriteString(asObjectRecord(compaction?.memoryFlush), "model", `${path}.compaction.memoryFlush.model`, changes);
|
|
97
|
-
rewriteModelMap(agent, `${path}.models`, changes);
|
|
98
|
-
const allow = asObjectRecord(agent.modelPolicy)?.allow;
|
|
99
|
-
if (Array.isArray(allow)) rewriteStringList(allow, `${path}.modelPolicy.allow`, changes);
|
|
100
|
-
if (includeEntrySelectors) {
|
|
101
|
-
rewriteExecReviewer(agent, `${path}.tools.exec.reviewer.model`, changes);
|
|
102
|
-
rewriteString(asObjectRecord(agent.tts), "summaryModel", `${path}.tts.summaryModel`, changes);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
function rewriteNonAgentRefs(root, changes) {
|
|
106
|
-
rewriteExecReviewer(root, "tools.exec.reviewer.model", changes);
|
|
107
|
-
rewriteStructuredMediaModels(root, changes);
|
|
108
|
-
const media = asObjectRecord(asObjectRecord(root.tools)?.media);
|
|
109
|
-
for (const capability of [
|
|
110
|
-
"image",
|
|
111
|
-
"audio",
|
|
112
|
-
"video"
|
|
113
|
-
]) rewriteString(asObjectRecord(media?.[capability]), "preferredModel", `tools.media.${capability}.preferredModel`, changes);
|
|
114
|
-
const channels = asObjectRecord(root.channels);
|
|
115
|
-
const modelByChannel = asObjectRecord(channels?.modelByChannel);
|
|
116
|
-
if (modelByChannel) for (const [channelId, targetsValue] of Object.entries(modelByChannel)) {
|
|
117
|
-
const targets = asObjectRecord(targetsValue);
|
|
118
|
-
if (!targets) continue;
|
|
119
|
-
for (const targetId of Object.keys(targets)) rewriteString(targets, targetId, `channels.modelByChannel.${channelId}.${targetId}`, changes);
|
|
120
|
-
}
|
|
121
|
-
const discord = asObjectRecord(channels?.discord);
|
|
122
|
-
rewriteDiscordVoice(discord?.voice, "channels.discord.voice", changes);
|
|
123
|
-
const accounts = asObjectRecord(discord?.accounts);
|
|
124
|
-
if (accounts) for (const [accountId, account] of Object.entries(accounts)) rewriteDiscordVoice(asObjectRecord(account)?.voice, `channels.discord.accounts.${accountId}.voice`, changes);
|
|
125
|
-
const hooks = asObjectRecord(root.hooks);
|
|
126
|
-
if (Array.isArray(hooks?.mappings)) for (const [index, mapping] of hooks.mappings.entries()) rewriteString(asObjectRecord(mapping), "model", `hooks.mappings.${index}.model`, changes);
|
|
127
|
-
rewriteString(asObjectRecord(hooks?.gmail), "model", "hooks.gmail.model", changes);
|
|
128
|
-
rewriteString(asObjectRecord(root.tts), "summaryModel", "tts.summaryModel", changes);
|
|
129
|
-
}
|
|
130
|
-
function removeRetiredCatalogRows(root, changes) {
|
|
131
|
-
const provider = asObjectRecord(asObjectRecord(asObjectRecord(root.models)?.providers)?.opencode);
|
|
132
|
-
if (!provider || !Array.isArray(provider.models)) return;
|
|
133
|
-
const retained = provider.models.filter((row) => {
|
|
134
|
-
const id = asObjectRecord(row)?.id;
|
|
135
|
-
return typeof id !== "string" || id.trim().toLowerCase() !== RETIRED_MODEL;
|
|
136
|
-
});
|
|
137
|
-
const removed = provider.models.length - retained.length;
|
|
138
|
-
if (removed > 0) {
|
|
139
|
-
provider.models = retained;
|
|
140
|
-
changes.push(`Removed ${removed} retired OpenCode Zen model row(s) from models.providers.opencode.models.`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
function normalizeCompatibilityConfig({ cfg }) {
|
|
144
|
-
const next = structuredClone(cfg);
|
|
145
|
-
const root = asObjectRecord(next);
|
|
146
|
-
if (!root) return {
|
|
147
|
-
config: cfg,
|
|
148
|
-
changes: []
|
|
149
|
-
};
|
|
150
|
-
const changes = [];
|
|
151
|
-
const agents = asObjectRecord(root.agents);
|
|
152
|
-
if (agents) {
|
|
153
|
-
rewriteAgent(agents.defaults, "agents.defaults", changes);
|
|
154
|
-
if (Object.hasOwn(agents, "entries")) {
|
|
155
|
-
const entries = asObjectRecord(agents.entries);
|
|
156
|
-
if (entries) for (const [agentId, entry] of Object.entries(entries)) rewriteAgent(entry, `agents.entries.${agentId}`, changes, true);
|
|
157
|
-
} else if (Array.isArray(agents.list)) for (const [index, entry] of agents.list.entries()) rewriteAgent(entry, `agents.list.${index}`, changes, true);
|
|
158
|
-
}
|
|
159
|
-
rewriteNonAgentRefs(root, changes);
|
|
160
|
-
removeRetiredCatalogRows(root, changes);
|
|
161
|
-
return changes.length > 0 ? {
|
|
162
|
-
config: next,
|
|
163
|
-
changes
|
|
164
|
-
} : {
|
|
165
|
-
config: cfg,
|
|
166
|
-
changes
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
//#endregion
|
|
170
|
-
export { normalizeCompatibilityConfig };
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { OPENCODE_NODE_INVOKE_TIMEOUT_MS, OPENCODE_SESSIONS_CAPABILITY, OPENCODE_SESSIONS_LIST_COMMAND, OPENCODE_SESSION_ID_PATTERN, OPENCODE_TERMINAL_RESUME_COMMAND } from "./session-catalog-shared.js";
|
|
2
|
-
import { listLocalOpenCodeSessionPage } from "./session-catalog.js";
|
|
3
|
-
import { decodeNodePtyResumeParams, resolveNodeHostExecutable, runNodePtyCommand } from "openclaw/plugin-sdk/node-host";
|
|
4
|
-
//#region extensions/opencode/session-catalog-terminal.ts
|
|
5
|
-
function validateOpenCodeThreadId(value) {
|
|
6
|
-
if (typeof value !== "string" || !OPENCODE_SESSION_ID_PATTERN.test(value)) throw new Error("INVALID_REQUEST: threadId is invalid");
|
|
7
|
-
return value;
|
|
8
|
-
}
|
|
9
|
-
async function requireLocalOpenCodeSession(threadId) {
|
|
10
|
-
const record = (await listLocalOpenCodeSessionPage({
|
|
11
|
-
searchTerm: threadId,
|
|
12
|
-
limit: 100
|
|
13
|
-
})).sessions.find((session) => session.threadId === threadId);
|
|
14
|
-
if (!record) throw new Error("OpenCode session is unavailable");
|
|
15
|
-
return record;
|
|
16
|
-
}
|
|
17
|
-
function createOpenCodeTerminalNodeHostCommand(isAvailable) {
|
|
18
|
-
return {
|
|
19
|
-
command: OPENCODE_TERMINAL_RESUME_COMMAND,
|
|
20
|
-
cap: OPENCODE_SESSIONS_CAPABILITY,
|
|
21
|
-
dangerous: false,
|
|
22
|
-
duplex: true,
|
|
23
|
-
isAvailable,
|
|
24
|
-
handle: async (paramsJSON, io) => {
|
|
25
|
-
if (!io) throw new Error("OpenCode terminal command requires duplex transport");
|
|
26
|
-
const params = decodeNodePtyResumeParams(paramsJSON, validateOpenCodeThreadId);
|
|
27
|
-
const record = await requireLocalOpenCodeSession(params.threadId);
|
|
28
|
-
const resolution = resolveNodeHostExecutable("opencode", {
|
|
29
|
-
env: process.env,
|
|
30
|
-
pathEnv: process.env.PATH ?? process.env.Path ?? "",
|
|
31
|
-
strategy: "direct"
|
|
32
|
-
});
|
|
33
|
-
if (!resolution) throw new Error("OpenCode CLI is unavailable");
|
|
34
|
-
return JSON.stringify(await runNodePtyCommand({
|
|
35
|
-
file: resolution.executable,
|
|
36
|
-
args: ["--session", params.threadId],
|
|
37
|
-
cwd: record.cwd,
|
|
38
|
-
cols: params.cols,
|
|
39
|
-
rows: params.rows
|
|
40
|
-
}, io));
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
async function resolveNodeOpenCodeSession(params) {
|
|
45
|
-
const raw = await params.runtime.nodes.invoke({
|
|
46
|
-
nodeId: params.nodeId,
|
|
47
|
-
command: OPENCODE_SESSIONS_LIST_COMMAND,
|
|
48
|
-
params: {
|
|
49
|
-
searchTerm: params.threadId,
|
|
50
|
-
limit: 100
|
|
51
|
-
},
|
|
52
|
-
timeoutMs: OPENCODE_NODE_INVOKE_TIMEOUT_MS,
|
|
53
|
-
scopes: ["operator.write"]
|
|
54
|
-
});
|
|
55
|
-
const record = params.parseNodeSessionPage(params.unwrapNodePayload(raw)).sessions.find((session) => session.threadId === params.threadId);
|
|
56
|
-
if (!record) throw new Error("OpenCode session is unavailable");
|
|
57
|
-
return record;
|
|
58
|
-
}
|
|
59
|
-
async function openOpenCodeCatalogTerminal(params) {
|
|
60
|
-
const title = `opencode --session ${params.threadId.slice(0, 12)}…`;
|
|
61
|
-
if (params.hostId === "gateway") {
|
|
62
|
-
const record = await requireLocalOpenCodeSession(params.threadId);
|
|
63
|
-
const resolution = resolveNodeHostExecutable("opencode", {
|
|
64
|
-
env: process.env,
|
|
65
|
-
pathEnv: process.env.PATH ?? "",
|
|
66
|
-
strategy: "fallback"
|
|
67
|
-
});
|
|
68
|
-
if (!resolution) throw new Error("OpenCode CLI is unavailable");
|
|
69
|
-
return {
|
|
70
|
-
kind: "local",
|
|
71
|
-
argv: [
|
|
72
|
-
resolution.executable,
|
|
73
|
-
"--session",
|
|
74
|
-
params.threadId
|
|
75
|
-
],
|
|
76
|
-
...record.cwd ? { cwd: record.cwd } : {},
|
|
77
|
-
...resolution.pathEnv ? { pathEnv: resolution.pathEnv } : {},
|
|
78
|
-
title
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
if (!params.hostId.startsWith("node:")) throw new Error("hostId is invalid");
|
|
82
|
-
const nodeId = params.hostId.slice(5);
|
|
83
|
-
if (!(await params.runtime.nodes.list()).nodes.find((candidate) => {
|
|
84
|
-
const commands = candidate.invocableCommands ?? candidate.commands;
|
|
85
|
-
return candidate.nodeId === nodeId && candidate.connected === true && commands?.includes("opencode.sessions.list.v1") === true && commands.includes("opencode.terminal.resume.v1");
|
|
86
|
-
})) throw new Error("paired-node OpenCode terminal is unavailable");
|
|
87
|
-
const record = await resolveNodeOpenCodeSession({
|
|
88
|
-
runtime: params.runtime,
|
|
89
|
-
nodeId,
|
|
90
|
-
threadId: params.threadId,
|
|
91
|
-
parseNodeSessionPage: params.parseNodeSessionPage,
|
|
92
|
-
unwrapNodePayload: params.unwrapNodePayload
|
|
93
|
-
});
|
|
94
|
-
return {
|
|
95
|
-
kind: "node",
|
|
96
|
-
nodeId,
|
|
97
|
-
command: OPENCODE_TERMINAL_RESUME_COMMAND,
|
|
98
|
-
paramsJSON: JSON.stringify({ threadId: params.threadId }),
|
|
99
|
-
...record.cwd ? { cwd: record.cwd } : {},
|
|
100
|
-
title
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
//#endregion
|
|
104
|
-
export { createOpenCodeTerminalNodeHostCommand, openOpenCodeCatalogTerminal };
|