@agentproto/adapter-opencode 1.0.1 → 1.1.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.mjs +42 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,34 @@
|
|
|
1
1
|
import { defineAgentCli, createAgentCliRuntime } from '@agentproto/driver-agent-cli';
|
|
2
|
+
import { listModels } from '@agentproto/model-catalog';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @agentproto/adapter-opencode v0.1.0-alpha
|
|
5
6
|
* AIP-45 adapter for sst/opencode via its built-in `opencode acp` mode.
|
|
6
7
|
*/
|
|
7
8
|
|
|
9
|
+
function buildOpencodeModelMenu() {
|
|
10
|
+
const supported = [
|
|
11
|
+
{ provider: "anthropic", prefix: "anthropic" },
|
|
12
|
+
{ provider: "openai", prefix: "openai" },
|
|
13
|
+
{ provider: "openrouter", prefix: "openrouter" }
|
|
14
|
+
];
|
|
15
|
+
const seen = /* @__PURE__ */ new Set();
|
|
16
|
+
const out = [];
|
|
17
|
+
for (const { provider, prefix } of supported) {
|
|
18
|
+
for (const model of listModels({ kind: "llm", provider })) {
|
|
19
|
+
const bareId = model.id;
|
|
20
|
+
const canonicalId = bareId.includes("/") ? bareId : `${prefix}/${bareId}`;
|
|
21
|
+
const id = provider === "openrouter" ? `openrouter/${bareId}` : canonicalId;
|
|
22
|
+
if (seen.has(id)) continue;
|
|
23
|
+
seen.add(id);
|
|
24
|
+
out.push({ id, provider });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return out.sort((a, b) => {
|
|
28
|
+
if (a.provider !== b.provider) return a.provider.localeCompare(b.provider);
|
|
29
|
+
return a.id.localeCompare(b.id);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
8
32
|
var opencode = defineAgentCli({
|
|
9
33
|
name: "opencode",
|
|
10
34
|
id: "opencode",
|
|
@@ -42,21 +66,25 @@ var opencode = defineAgentCli({
|
|
|
42
66
|
idle_timeout_ms: 18e5,
|
|
43
67
|
context_carryover: true
|
|
44
68
|
},
|
|
69
|
+
// opencode routes by the model id's own `<provider>/<id>` prefix itself, no
|
|
70
|
+
// adapter mode — unlike claude-sdk/claude-code, which need ANTHROPIC_BASE_URL
|
|
71
|
+
// pre-wired by a mode. So the route falls out of the chosen model →
|
|
72
|
+
// derived-from-model. The API key env var is also derived from the model's
|
|
73
|
+
// provider prefix, so the runtime must know to present api-key auth on the
|
|
74
|
+
// model-derived direct endpoint.
|
|
75
|
+
routeSelection: "derived-from-model",
|
|
76
|
+
modelDerivedApiKey: true,
|
|
45
77
|
models: {
|
|
46
|
-
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
allowed:
|
|
56
|
-
{ id: "anthropic/claude-sonnet-4-6", provider: "anthropic" },
|
|
57
|
-
{ id: "openai/gpt-5", provider: "openai" },
|
|
58
|
-
{ id: "openai/gpt-5-mini", provider: "openai" }
|
|
59
|
-
],
|
|
78
|
+
// Default to a canonical catalog model (claude-sonnet-4-5). The legacy
|
|
79
|
+
// alias `claude-sonnet-4-6` still resolves to the same model, but the
|
|
80
|
+
// generated menu uses canonical ids from the shared catalog.
|
|
81
|
+
default: "anthropic/claude-sonnet-4-5",
|
|
82
|
+
// Generated from the shared provider catalog so the Configuration Lab /
|
|
83
|
+
// harness picker shows genuinely runnable Anthropic / OpenAI / OpenRouter
|
|
84
|
+
// models instead of a hardcoded 3-item list. Groq and OpenCode-hosted are
|
|
85
|
+
// omitted because they are not represented in the catalog/profile system
|
|
86
|
+
// today; the free-form `model` option and `models.env` still support them.
|
|
87
|
+
allowed: buildOpencodeModelMenu(),
|
|
60
88
|
env: {
|
|
61
89
|
anthropic: "ANTHROPIC_API_KEY",
|
|
62
90
|
openai: "OPENAI_API_KEY",
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QAAQ,CAAA;AACvC","file":"index.mjs","sourcesContent":["/**\n * @agentproto/adapter-opencode — AIP-45 adapter for sst/opencode.\n *\n * OpenCode ships first-party ACP support (`opencode acp`) so no\n * third-party wrapper is needed. We spawn it via `npx -y opencode-ai\n * acp` and drive it over stdio JSON-RPC the same way the claude-code\n * adapter drives @agentclientprotocol/claude-agent-acp.\n *\n * import { opencode, opencodeRuntime } from \"@agentproto/adapter-opencode\"\n * const session = await opencodeRuntime().start({\n * env: { ANTHROPIC_API_KEY: \"sk-...\" },\n * })\n * for await (const evt of session.send({ role: \"user\", content: \"...\" })) {\n * console.log(evt)\n * }\n * await session.close()\n */\n\nimport {\n createAgentCliRuntime,\n defineAgentCli,\n type AgentCliHandle,\n type AgentCliRuntime,\n} from \"@agentproto/driver-agent-cli\"\n\nexport const opencode: AgentCliHandle = defineAgentCli({\n name: \"opencode\",\n id: \"opencode\",\n description:\n \"sst/opencode — open-source coding agent with first-party ACP mode. Spawned via `npx -y opencode-ai acp` and driven over stdio JSON-RPC. Multi-provider (Anthropic / OpenAI / OpenRouter / Groq / OpenCode hosted).\",\n version: \"0.1.0\",\n bin: \"npx\",\n bin_args: [\"-y\", \"opencode-ai\", \"acp\"],\n install: [\n { method: \"npm\", package: \"opencode-ai\", global: true },\n { method: \"curl\", url: \"https://opencode.ai/install\" },\n ],\n version_check: {\n cmd: \"npm view opencode-ai version\",\n parse: \"(\\\\d+\\\\.\\\\d+\\\\.\\\\d+)\",\n range: \">=1.0.0\",\n timeout_ms: 15_000,\n },\n auth: {\n ref: \"./SECRETS.md\",\n state: {\n env: [\n \"OPENCODE_API_KEY\",\n \"ANTHROPIC_API_KEY\",\n \"OPENAI_API_KEY\",\n \"OPENROUTER_API_KEY\",\n \"GROQ_API_KEY\",\n ],\n },\n },\n sandbox: \"./SANDBOX.md\",\n protocol: \"acp\",\n acp: \"./opencode-acp.ACP.md\",\n session: {\n mode: \"persistent\",\n idle_timeout_ms: 1_800_000,\n context_carryover: true,\n },\n models: {\n default: \"anthropic/claude-sonnet-4-6\",\n // Anthropic is no longer advertised as a pickable escalation — only the\n // adapter's own default Claude model stays listed (repointing the default\n // is out of scope). Premium Anthropic (Opus/Haiku) and the redundant\n // gateway dupe are dropped from the menu so orchestrators don't select\n // them here; the free-form `model` option still accepts any id.\n // `provider` is read straight off each id's own prefix — opencode routes\n // by that prefix itself, no adapter mode needed (unlike claude-sdk /\n // claude-code, which need ANTHROPIC_BASE_URL pre-wired by a mode).\n allowed: [\n { id: \"anthropic/claude-sonnet-4-6\", provider: \"anthropic\" },\n { id: \"openai/gpt-5\", provider: \"openai\" },\n { id: \"openai/gpt-5-mini\", provider: \"openai\" },\n ],\n env: {\n anthropic: \"ANTHROPIC_API_KEY\",\n openai: \"OPENAI_API_KEY\",\n openrouter: \"OPENROUTER_API_KEY\",\n opencode: \"OPENCODE_API_KEY\",\n groq: \"GROQ_API_KEY\",\n },\n },\n capabilities: {\n streaming: true,\n tool_calls: true,\n sub_agents: false,\n file_io: true,\n // OpenCode forwards ACP image content blocks to the underlying\n // provider (Anthropic Messages API for Claude models, OpenAI vision\n // for GPT-5). Hosts SHOULD send `{type: \"image\", data, mimeType}`\n // blocks alongside text in `session.send`.\n multimodal: true,\n // OpenCode persists session state internally and the ACP server\n // implements newSession/loadSession/resumeSession. Pair with the\n // `native-resume` continuation strategy for cold-start reattach.\n resumable: true,\n bidirectional: true,\n },\n // No manifest `modes[]`: opencode's operation profiles (default / plan /\n // build) are POSTURE, which no longer lives in the manifest (SPEC §3.4a).\n // opencode's own ACP server already advertises these as native session modes\n // and switches them on the wire via `session/set_config_option`\n // (configId:\"mode\") / `session/set_mode` — precisely the harness ACP mode\n // registry (`SessionModeState.availableModes`) posture is now sourced from,\n // so declaring them here would only duplicate the harness's own truth. route\n // comes from the model catalog and opencode has no context mode, so the array\n // would be empty — omit it.\n options: [\n {\n id: \"model\",\n type: \"string\",\n description:\n \"Provider/model override for this operator binding (e.g. `openrouter/anthropic/claude-sonnet-4-6`). Applied via ACP \" +\n \"session/set_config_option after the session is created (see \" +\n \"`models.apply`, default \\\"config\\\"); no CLI flag for this exists on \" +\n \"`opencode acp`. An id the server can't resolve is warned about and \" +\n \"ignored (the session keeps the server's default model).\",\n },\n ],\n continuation: {\n default: \"native-resume\",\n supported: [\"native-resume\", \"pinned-session\", \"transcript\", \"none\"],\n pinned_session: {\n idle_timeout_ms: 1_800_000,\n key_scope: [\"conversation\", \"operator\"],\n },\n },\n tags: [\"opencode\", \"sst\", \"acp\", \"agent-runtime\", \"coding\"],\n})\n\nexport function opencodeRuntime(): AgentCliRuntime {\n return createAgentCliRuntime(opencode)\n}\n\nexport type { AgentCliHandle, AgentCliRuntime }\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;AAyCA,SAAS,sBAAA,GAAkE;AACzE,EAAA,MAAM,SAAA,GAAY;AAAA,IAChB,EAAE,QAAA,EAAU,WAAA,EAAa,MAAA,EAAQ,WAAA,EAAY;AAAA,IAC7C,EAAE,QAAA,EAAU,QAAA,EAAU,MAAA,EAAQ,QAAA,EAAS;AAAA,IACvC,EAAE,QAAA,EAAU,YAAA,EAAc,MAAA,EAAQ,YAAA;AAAa,GACjD;AAEA,EAAA,MAAM,IAAA,uBAAW,GAAA,EAAY;AAC7B,EAAA,MAAM,MAA+C,EAAC;AAEtD,EAAA,KAAA,MAAW,EAAE,QAAA,EAAU,MAAA,EAAO,IAAK,SAAA,EAAW;AAC5C,IAAA,KAAA,MAAW,SAAS,UAAA,CAAW,EAAE,MAAM,KAAA,EAAO,QAAA,EAAU,CAAA,EAAG;AACzD,MAAA,MAAM,SAAS,KAAA,CAAM,EAAA;AACrB,MAAA,MAAM,WAAA,GAAc,OAAO,QAAA,CAAS,GAAG,IAAI,MAAA,GAAS,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,MAAM,CAAA,CAAA;AACvE,MAAA,MAAM,EAAA,GAAK,QAAA,KAAa,YAAA,GAAe,CAAA,WAAA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A;AAAA,IACT,SAAA,EAAW,CAAC,eAAA,EAAiB,gBAAA,EAAkB,cAAc,MAAM,CAAA;AAAA,IACnE,cAAA,EAAgB;AAAA,MACd,eAAA,EAAiB,IAAA;AAAA,MACjB,SAAA,EAAW,CAAC,cAAA,EAAgB,UAAU;AAAA;AACxC,GACF;AAAA,EACA,MAAM,CAAC,UAAA,EAAY,KAAA,EAAO,KAAA,EAAO,iBAAiB,QAAQ;AAC5D,CAAC;AAEM,SAAS,eAAA,GAAmC;AACjD,EAAA,OAAO,sBAAsB,QAAQ,CAAA;AACvC","file":"index.mjs","sourcesContent":["/**\n * @agentproto/adapter-opencode — AIP-45 adapter for sst/opencode.\n *\n * OpenCode ships first-party ACP support (`opencode acp`) so no\n * third-party wrapper is needed. We spawn it via `npx -y opencode-ai\n * acp` and drive it over stdio JSON-RPC the same way the claude-code\n * adapter drives @agentclientprotocol/claude-agent-acp.\n *\n * import { opencode, opencodeRuntime } from \"@agentproto/adapter-opencode\"\n * const session = await opencodeRuntime().start({\n * env: { ANTHROPIC_API_KEY: \"sk-...\" },\n * })\n * for await (const evt of session.send({ role: \"user\", content: \"...\" })) {\n * console.log(evt)\n * }\n * await session.close()\n */\n\nimport {\n createAgentCliRuntime,\n defineAgentCli,\n type AgentCliHandle,\n type AgentCliRuntime,\n} from \"@agentproto/driver-agent-cli\"\nimport { listModels } from \"@agentproto/model-catalog\"\n\n/**\n * Build OpenCode's model menu from the shared provider catalog instead of a\n * hand-maintained allowlist. OpenCode routes by the model id's own\n * `<provider>/<id>` prefix, so every entry carries the billing provider the\n * runtime's eligibility projection needs.\n *\n * Only providers OpenCode genuinely supports today are included:\n * - Anthropic and OpenAI (direct vendor prefixes)\n * - OpenRouter (`openrouter/<vendor>/<id>` router prefix)\n *\n * Groq and OpenCode-hosted are omitted from the generated menu because they\n * are not represented in the shared catalog / profile system today. The\n * `models.env` map still carries their key env vars, so free-form `model`\n * overrides and manually-curated profiles continue to work.\n */\nfunction buildOpencodeModelMenu(): Array<{ id: string; provider: string }> {\n const supported = [\n { provider: \"anthropic\", prefix: \"anthropic\" },\n { provider: \"openai\", prefix: \"openai\" },\n { provider: \"openrouter\", prefix: \"openrouter\" },\n ] as const\n\n const seen = new Set<string>()\n const out: Array<{ id: string; provider: string }> = []\n\n for (const { provider, prefix } of supported) {\n for (const model of listModels({ kind: \"llm\", provider })) {\n const bareId = model.id\n const canonicalId = bareId.includes(\"/\") ? bareId : `${prefix}/${bareId}`\n const id = provider === \"openrouter\" ? `openrouter/${bareId}` : canonicalId\n if (seen.has(id)) continue\n seen.add(id)\n out.push({ id, provider })\n }\n }\n\n return out.sort((a, b) => {\n if (a.provider !== b.provider) return a.provider.localeCompare(b.provider)\n return a.id.localeCompare(b.id)\n })\n}\n\nexport const opencode: AgentCliHandle = defineAgentCli({\n name: \"opencode\",\n id: \"opencode\",\n description:\n \"sst/opencode — open-source coding agent with first-party ACP mode. Spawned via `npx -y opencode-ai acp` and driven over stdio JSON-RPC. Multi-provider (Anthropic / OpenAI / OpenRouter / Groq / OpenCode hosted).\",\n version: \"0.1.0\",\n bin: \"npx\",\n bin_args: [\"-y\", \"opencode-ai\", \"acp\"],\n install: [\n { method: \"npm\", package: \"opencode-ai\", global: true },\n { method: \"curl\", url: \"https://opencode.ai/install\" },\n ],\n version_check: {\n cmd: \"npm view opencode-ai version\",\n parse: \"(\\\\d+\\\\.\\\\d+\\\\.\\\\d+)\",\n range: \">=1.0.0\",\n timeout_ms: 15_000,\n },\n auth: {\n ref: \"./SECRETS.md\",\n state: {\n env: [\n \"OPENCODE_API_KEY\",\n \"ANTHROPIC_API_KEY\",\n \"OPENAI_API_KEY\",\n \"OPENROUTER_API_KEY\",\n \"GROQ_API_KEY\",\n ],\n },\n },\n sandbox: \"./SANDBOX.md\",\n protocol: \"acp\",\n acp: \"./opencode-acp.ACP.md\",\n session: {\n mode: \"persistent\",\n idle_timeout_ms: 1_800_000,\n context_carryover: true,\n },\n // opencode routes by the model id's own `<provider>/<id>` prefix itself, no\n // adapter mode — unlike claude-sdk/claude-code, which need ANTHROPIC_BASE_URL\n // pre-wired by a mode. So the route falls out of the chosen model →\n // derived-from-model. The API key env var is also derived from the model's\n // provider prefix, so the runtime must know to present api-key auth on the\n // model-derived direct endpoint.\n routeSelection: \"derived-from-model\",\n modelDerivedApiKey: true,\n models: {\n // Default to a canonical catalog model (claude-sonnet-4-5). The legacy\n // alias `claude-sonnet-4-6` still resolves to the same model, but the\n // generated menu uses canonical ids from the shared catalog.\n default: \"anthropic/claude-sonnet-4-5\",\n // Generated from the shared provider catalog so the Configuration Lab /\n // harness picker shows genuinely runnable Anthropic / OpenAI / OpenRouter\n // models instead of a hardcoded 3-item list. Groq and OpenCode-hosted are\n // omitted because they are not represented in the catalog/profile system\n // today; the free-form `model` option and `models.env` still support them.\n allowed: buildOpencodeModelMenu(),\n env: {\n anthropic: \"ANTHROPIC_API_KEY\",\n openai: \"OPENAI_API_KEY\",\n openrouter: \"OPENROUTER_API_KEY\",\n opencode: \"OPENCODE_API_KEY\",\n groq: \"GROQ_API_KEY\",\n },\n },\n capabilities: {\n streaming: true,\n tool_calls: true,\n sub_agents: false,\n file_io: true,\n // OpenCode forwards ACP image content blocks to the underlying\n // provider (Anthropic Messages API for Claude models, OpenAI vision\n // for GPT-5). Hosts SHOULD send `{type: \"image\", data, mimeType}`\n // blocks alongside text in `session.send`.\n multimodal: true,\n // OpenCode persists session state internally and the ACP server\n // implements newSession/loadSession/resumeSession. Pair with the\n // `native-resume` continuation strategy for cold-start reattach.\n resumable: true,\n bidirectional: true,\n },\n // No manifest `modes[]`: opencode's operation profiles (default / plan /\n // build) are POSTURE, which no longer lives in the manifest (SPEC §3.4a).\n // opencode's own ACP server already advertises these as native session modes\n // and switches them on the wire via `session/set_config_option`\n // (configId:\"mode\") / `session/set_mode` — precisely the harness ACP mode\n // registry (`SessionModeState.availableModes`) posture is now sourced from,\n // so declaring them here would only duplicate the harness's own truth. route\n // comes from the model catalog and opencode has no context mode, so the array\n // would be empty — omit it.\n options: [\n {\n id: \"model\",\n type: \"string\",\n description:\n \"Provider/model override for this operator binding (e.g. `openrouter/anthropic/claude-sonnet-4-6`). Applied via ACP \" +\n \"session/set_config_option after the session is created (see \" +\n \"`models.apply`, default \\\"config\\\"); no CLI flag for this exists on \" +\n \"`opencode acp`. An id the server can't resolve is warned about and \" +\n \"ignored (the session keeps the server's default model).\",\n },\n ],\n continuation: {\n default: \"native-resume\",\n supported: [\"native-resume\", \"pinned-session\", \"transcript\", \"none\"],\n pinned_session: {\n idle_timeout_ms: 1_800_000,\n key_scope: [\"conversation\", \"operator\"],\n },\n },\n tags: [\"opencode\", \"sst\", \"acp\", \"agent-runtime\", \"coding\"],\n})\n\nexport function opencodeRuntime(): AgentCliRuntime {\n return createAgentCliRuntime(opencode)\n}\n\nexport type { AgentCliHandle, AgentCliRuntime }\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentproto/adapter-opencode",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "@agentproto/adapter-opencode — AIP-45 AGENT-CLI adapter for sst/opencode. Spawns `opencode acp` (via npx -y opencode-ai) and drives OpenCode as an agentproto agent CLI over stdio JSON-RPC.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentproto",
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@agentproto/driver-agent-cli": "2.0
|
|
44
|
+
"@agentproto/driver-agent-cli": "2.1.0",
|
|
45
|
+
"@agentproto/model-catalog": "0.8.0"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@types/node": "^25.6.2",
|