@desplega.ai/agent-swarm 1.171.0 → 1.172.0
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/{acp-adapter-1z9p3fvx.js → acp-adapter-fpecx1g1.js} +23 -5
- package/dist/{actions-rc2yjk8a.js → actions-pw87a1a8.js} +24 -25
- package/dist/{amp-adapter-ypyf5s1x.js → amp-adapter-8jem2bc0.js} +1 -1
- package/dist/{anthropic-messages-etkbxhhy.js → anthropic-messages-8ee2f22q.js} +55 -22
- package/dist/{app-04ab2s0z.js → app-wmf0m843.js} +7 -8
- package/dist/{assistant-vhmjd8wf.js → assistant-emp1e108.js} +26 -27
- package/dist/{azure-openai-responses-xap57x4b.js → azure-openai-responses-ap1gwxgr.js} +3 -3
- package/dist/{boot-reembed-3p0m259x.js → boot-reembed-1de4f4aj.js} +6 -7
- package/dist/{boot-reembed-wew3gwk8.js → boot-reembed-4ymn9atn.js} +6 -7
- package/dist/{boot-scrub-sweep-5ytwtq24.js → boot-scrub-sweep-adhk1s8c.js} +7 -8
- package/dist/{boot-seeds-s8p2xry8.js → boot-seeds-8q637aew.js} +9 -10
- package/dist/{claude-adapter-akrzg6jh.js → claude-adapter-t26cv8a4.js} +16 -17
- package/dist/{claude-managed-adapter-kqqqhp2q.js → claude-managed-adapter-xgxhqrt2.js} +2 -2
- package/dist/{claude-sdk-session-exq1jadx.js → claude-sdk-session-gsfsh662.js} +16 -17
- package/dist/{cli-n8ybnv1k.js → cli-04emfe2q.js} +1 -1
- package/dist/{cli-w0bwte75.js → cli-104zsxba.js} +2 -1
- package/dist/{cli-x6z90nq9.js → cli-19njxg5g.js} +2 -4
- package/dist/{cli-8mr695sb.js → cli-1hgat6pa.js} +5 -5
- package/dist/{cli-1qtgd1h1.js → cli-1m2xxxe2.js} +2 -2
- package/dist/{cli-231av4y6.js → cli-1x7da0de.js} +2 -4
- package/dist/{cli-x3fy2tgp.js → cli-388egyf6.js} +1 -1
- package/dist/{cli-j0w59p15.js → cli-4fnb6884.js} +4 -4
- package/dist/{cli-y1j1ggbf.js → cli-4nz8p1p5.js} +1372 -588
- package/dist/{cli-s88my3br.js → cli-5rv1j9ga.js} +6 -6
- package/dist/{cli-mn8qkd8v.js → cli-61625k3x.js} +1 -1
- package/dist/{cli-mzj3aqac.js → cli-6jb2rf77.js} +3 -3
- package/dist/{cli-ec7hrgqp.js → cli-8hzfb6xz.js} +8 -8
- package/dist/{cli-n805bb98.js → cli-8vs9trd4.js} +1 -1
- package/dist/{cli-xf713zz0.js → cli-9fxpr83v.js} +1 -1
- package/dist/{cli-q1vnz8wv.js → cli-9s17naqf.js} +1 -1
- package/dist/{cli-nkjwe4z7.js → cli-9xsmdpdt.js} +59 -54
- package/dist/{cli-6xxxb8qt.js → cli-aspcaef3.js} +5 -5
- package/dist/cli-bf7485pm.js +514 -0
- package/dist/{cli-s9y81s7j.js → cli-bt8k5h3s.js} +625 -150
- package/dist/{cli-jxsgrnmq.js → cli-c2pq2rjb.js} +2 -2
- package/dist/{cli-13xwcqvj.js → cli-c5km5znr.js} +2 -2
- package/dist/{cli-5y67yrt6.js → cli-cceskcvt.js} +112 -176
- package/dist/{cli-ph3145b7.js → cli-cf69s3ew.js} +4 -4
- package/dist/{cli-k2v5x13t.js → cli-d603qf86.js} +1 -1
- package/dist/{cli-r455yd58.js → cli-e0a9sk00.js} +1 -1
- package/dist/{cli-cgj4hc12.js → cli-eh1ytktb.js} +1872 -190
- package/dist/{cli-erbp6b4g.js → cli-esnpehf5.js} +7 -8
- package/dist/cli-ev91t6xp.js +148 -0
- package/dist/{cli-e2prcx5m.js → cli-fdvbjtbw.js} +235 -5
- package/dist/{cli-62bwwc2q.js → cli-g4f5pj26.js} +3 -3
- package/dist/{cli-tg8q0b5y.js → cli-g6t9texm.js} +5 -5
- package/dist/{cli-p2pjfq1r.js → cli-gj81e47t.js} +1 -1
- package/dist/{cli-srmej5tp.js → cli-gp1rtyvk.js} +2 -2
- package/dist/{cli-rb9m6rpe.js → cli-h6vtvt5c.js} +139 -1
- package/dist/cli-hd27d2md.js +1057 -0
- package/dist/{cli-hsk5gd15.js → cli-hwwvy36w.js} +3 -3
- package/dist/{cli-2rbt7at8.js → cli-hz99wfxp.js} +1 -1
- package/dist/cli-j1pmc07z.js +706 -0
- package/dist/{cli-01qndrvw.js → cli-j6kpj9az.js} +14 -8
- package/dist/{cli-2qbs2tvf.js → cli-k46r9hmk.js} +6 -6
- package/dist/{cli-wfvedq5w.js → cli-kb4ehzx5.js} +5 -5
- package/dist/{cli-agamgm0p.js → cli-mvzyxwg3.js} +1 -1
- package/dist/{cli-280gnz4v.js → cli-nv4zd0b9.js} +1 -1
- package/dist/{cli-rrbctenq.js → cli-nyhb1r6x.js} +3 -5
- package/dist/{cli-g7k7zbcz.js → cli-p7z6q2m6.js} +2 -1
- package/dist/{cli-yn0a417a.js → cli-phre6gz0.js} +22 -4
- package/dist/{cli-m4csbs67.js → cli-pj6x9qce.js} +1 -1
- package/dist/{cli-w0zx9ya1.js → cli-prrt9fa0.js} +4 -4
- package/dist/{cli-ctret352.js → cli-pstq9888.js} +33 -33
- package/dist/{cli-y195hv1a.js → cli-pxeeyc53.js} +1 -1
- package/dist/{cli-4bm25xtw.js → cli-qsztpfry.js} +1 -1
- package/dist/{cli-5t5my0h8.js → cli-qybkr9n3.js} +278 -1267
- package/dist/{cli-xezn9nkh.js → cli-r44t9wqc.js} +29 -472
- package/dist/{cli-x207g4w1.js → cli-r8smj8b8.js} +1 -1
- package/dist/{cli-bxqez1p0.js → cli-rcp5aqdw.js} +9 -39
- package/dist/{cli-vr5avem2.js → cli-smcrrmhy.js} +14 -18
- package/dist/{cli-0d2rqhvq.js → cli-tgpfnm6r.js} +15 -17
- package/dist/cli-vb8g5x02.js +549 -0
- package/dist/{cli-gt4hxb8p.js → cli-vv0qtfpx.js} +1 -2
- package/dist/{cli-95zs84qw.js → cli-wd0hz6ah.js} +671 -388
- package/dist/{cli-nkqjj42q.js → cli-x4m6feqt.js} +1 -1
- package/dist/{cli-x61srfpp.js → cli-xczpdp9e.js} +2 -2
- package/dist/cli-z1kd834t.js +36 -0
- package/dist/{cli-p8f7dqgt.js → cli-ztrv9y21.js} +48 -33
- package/dist/cli.js +24 -25
- package/dist/{cloudflare-workers-ai-system-one-sta45jf9.js → cloudflare-workers-ai-system-one-vnpyfr7e.js} +3 -3
- package/dist/{codex-adapter-9ag75whm.js → codex-adapter-m4tgdysy.js} +12 -12
- package/dist/{codex-hook-7ba15hjd.js → codex-hook-xch6z5wt.js} +2 -3
- package/dist/{codex-session-runner-9fp7y4cf.js → codex-session-runner-ymwzm6ea.js} +12 -12
- package/dist/{commands-d7eah0y9.js → commands-n0hshcvs.js} +6 -7
- package/dist/{controllers-connect-8t0k65x2.js → controllers-connect-y07cqcvy.js} +24 -25
- package/dist/{cursor-adapter-t4pr1m3c.js → cursor-adapter-q8pgv5qa.js} +2 -3
- package/dist/{db-sp39qv72.js → db-4w7tmt1g.js} +6 -7
- package/dist/{db-2rmd23wq.js → db-hkqvrdcb.js} +7 -8
- package/dist/{dispatcher-g7fsybsd.js → dispatcher-5sd69y14.js} +23 -24
- package/dist/{easter-egg-3d-66zxervv.js → easter-egg-3d-m8rvz40s.js} +4 -3
- package/dist/execute-107xtsp1.js +3745 -0
- package/dist/{google-generative-ai-pvhm0dq1.js → google-generative-ai-7pavrbv7.js} +3 -3
- package/dist/{google-vertex-tek9sqe2.js → google-vertex-3f1jk41f.js} +3 -3
- package/dist/{grok-adapter-1err1me7.js → grok-adapter-8m9yqzbq.js} +24 -6
- package/dist/{handlers-c7yggm37.js → handlers-s20xr10r.js} +26 -27
- package/dist/{heartbeat-dkm924fk.js → heartbeat-3k31q4g2.js} +25 -26
- package/dist/{hook-wgx4exw6.js → hook-gdn6a2fn.js} +13 -14
- package/dist/{hook-g8e7sfnf.js → hook-ygwerrdh.js} +14 -15
- package/dist/{http-1d23k928.js → http-jdteeg81.js} +53 -55
- package/dist/{index-y5vvczrs.js → index-6ksewd5y.js} +20 -18
- package/dist/{index-kkeftv5h.js → index-82rk11v7.js} +4 -4
- package/dist/{index-gm10tmye.js → index-e0snym4t.js} +23 -24
- package/dist/{index-vertaxs1.js → index-ffqzqgwb.js} +6 -7
- package/dist/{index-q7cj9bn2.js → index-tsszt7g9.js} +25 -26
- package/dist/{index-w097eg0x.js → index-vccv018g.js} +1 -1
- package/dist/{index-va4zbvzp.js → index-vm3bm9t7.js} +24 -25
- package/dist/{keepalive-1jc5e7ct.js → keepalive-jekc896t.js} +8 -9
- package/dist/{lead-yxw2f1sg.js → lead-4k9s9szx.js} +40 -41
- package/dist/{maintenance-h7w2m10y.js → maintenance-shazch4n.js} +6 -7
- package/dist/{mistral-conversations-rjxa9s1j.js → mistral-conversations-vjc1ggpd.js} +29 -15
- package/dist/{oauth-refresh-sweep-wh9ypd1b.js → oauth-refresh-sweep-5gb36kn8.js} +7 -8
- package/dist/{onboard-dfr9j762.js → onboard-ydrbnvww.js} +2 -2
- package/dist/{openai-codex-responses-pgvtddvv.js → openai-codex-responses-33qhkkdy.js} +7 -39
- package/dist/{openai-completions-44gb0zsk.js → openai-completions-s88xm3ns.js} +2 -2
- package/dist/{openai-decisions-vj9nkpf8.js → openai-decisions-fctnj8xd.js} +2 -2
- package/dist/{openai-responses-9dyzwzkr.js → openai-responses-7xd2f2e2.js} +3 -3
- package/dist/opencode-adapter-5zh0he20.js +55 -0
- package/dist/{otel-impl-and31m5s.js → otel-impl-6pf5cv86.js} +1 -1
- package/dist/{pi-mono-adapter-fx6k5wwh.js → pi-mono-adapter-ef9wwx9m.js} +25 -500
- package/dist/{pricing-refresh-23zr6j3w.js → pricing-refresh-s52nsa5q.js} +8 -9
- package/dist/{rbac-roles-wnx35x4x.js → rbac-roles-aq3msh4e.js} +6 -7
- package/dist/{rbac-roles-nc7k9d0t.js → rbac-roles-q5gb5e8v.js} +7 -8
- package/dist/{render-v2-81cg1y52.js → render-v2-pd1rg54q.js} +7 -8
- package/dist/{resume-d4b6j2n2.js → resume-gw4a2c6v.js} +14 -15
- package/dist/{runtime-h9ha1mq6.js → runtime-qfry88v2.js} +4 -7
- package/dist/{setup-g68r1w28.js → setup-jda1ksdh.js} +2 -2
- package/dist/{typesafe-system-one-e988vty7.js → typesafe-system-one-zzzcx4s3.js} +3 -3
- package/dist/{virtual-modules-rdjmcg7q.js → virtual-modules-b3ga2m65.js} +13 -12
- package/dist/{work-objects-0zzdnbt9.js → work-objects-tb7ycye8.js} +26 -27
- package/dist/{worker-p1g8qm6h.js → worker-njjccz5d.js} +40 -41
- package/openapi.json +1 -1
- package/package.json +7 -8
- package/src/be/scripts/extract-schema.ts +4 -0
- package/src/github/handlers.ts +61 -18
- package/src/github/types.ts +2 -1
- package/src/prompts/goal-reminder.ts +30 -0
- package/src/prompts/session-templates.ts +22 -0
- package/src/providers/acp-targets.ts +3 -4
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/harness-version.ts +0 -1
- package/src/providers/opencode-adapter.ts +442 -723
- package/src/providers/opencode-swarm-plugin.ts +88 -0
- package/src/providers/pi-mono-extension.ts +58 -37
- package/src/scripts-runtime/executors/native.ts +6 -5
- package/src/scripts-runtime/executors/quickjs-bundle.ts +18 -11
- package/src/scripts-runtime/extract-args-schema.ts +22 -4
- package/src/scripts-runtime/import-allowlist.ts +1 -1
- package/src/scripts-runtime/zod-mini-bundle.ts +5 -0
- package/src/slack/render-v2.ts +2 -2
- package/src/tests/entrypoint-acp-target-binary.test.ts +19 -1
- package/src/tests/github-handlers-inline-comments.test.ts +131 -2
- package/src/tests/github-handlers-reactions.test.ts +9 -0
- package/src/tests/harness-version.test.ts +0 -20
- package/src/tests/opencode-adapter.test.ts +536 -1389
- package/src/tests/opencode-mcp-admission-sdk.test.ts +106 -0
- package/src/tests/opencode-swarm-plugin.test.ts +130 -0
- package/src/tests/pi-mono-extension.test.ts +59 -0
- package/src/tests/prompt-template-session.test.ts +4 -3
- package/src/tests/provider-registration.test.ts +3 -0
- package/src/tests/script-executor-quickjs.test.ts +17 -12
- package/src/tests/scripts-http.test.ts +24 -16
- package/src/tests/scripts-import-allowlist.test.ts +1 -1
- package/src/tests/scripts-runtime.test.ts +78 -40
- package/src/tests/seed-scripts.test.ts +13 -0
- package/src/tests/slack-render-v2.test.ts +4 -2
- package/src/tests/ui-logs-parser.test.ts +28 -0
- package/src/tools/script-upsert.ts +1 -1
- package/src/utils/memory-raters.ts +7 -3
- package/src/utils/openrouter-base-url.ts +0 -2
- package/templates/schedules/weekly-harness-upgrade-check/content.md +4 -6
- package/templates/skills/heartbeat-runbook/content.md +2 -0
- package/templates/skills/swarm-scripts/SKILL.md +1 -0
- package/templates/skills/swarm-scripts/content.md +1 -0
- package/dist/cli-5bfdm1ah.js +0 -462
- package/dist/cli-5c2j5yvx.js +0 -222
- package/dist/cli-rhy7z1rp.js +0 -532
- package/dist/cli-ywh2a87k.js +0 -2359
- package/dist/execute-h4jgevyw.js +0 -1387
- package/dist/opencode-adapter-f1zby94p.js +0 -34
- package/plugin/opencode-plugins/lib/memory-raters.ts +0 -7
- package/src/tests/opencode-plugin.test.ts +0 -580
- package/src/tests/providers/opencode-cost.test.ts +0 -74
package/dist/cli-ywh2a87k.js
DELETED
|
@@ -1,2359 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
readPkgVersion
|
|
3
|
-
} from "./cli-gt4hxb8p.js";
|
|
4
|
-
import {
|
|
5
|
-
require_cross_spawn
|
|
6
|
-
} from "./cli-5bfdm1ah.js";
|
|
7
|
-
import {
|
|
8
|
-
fetchInstalledMcpServers
|
|
9
|
-
} from "./cli-tng3131n.js";
|
|
10
|
-
import {
|
|
11
|
-
CTX_MODE_NUDGE_EVERY
|
|
12
|
-
} from "./cli-zm7njwzd.js";
|
|
13
|
-
import {
|
|
14
|
-
resolveSlashSkillPrompt
|
|
15
|
-
} from "./cli-ptcz1cqy.js";
|
|
16
|
-
import {
|
|
17
|
-
CONTEXT_FORMULA,
|
|
18
|
-
clampContextPercent,
|
|
19
|
-
getContextWindowSize
|
|
20
|
-
} from "./cli-7avy4v8w.js";
|
|
21
|
-
import {
|
|
22
|
-
applyReasoningEffort
|
|
23
|
-
} from "./cli-tmhsxhb8.js";
|
|
24
|
-
import {
|
|
25
|
-
swarmRuntimeInstanceId
|
|
26
|
-
} from "./cli-re8z5p8p.js";
|
|
27
|
-
import {
|
|
28
|
-
init_credentials,
|
|
29
|
-
validateOpencodeCredentials
|
|
30
|
-
} from "./cli-tadfgd0t.js";
|
|
31
|
-
import {
|
|
32
|
-
DEFAULT_OPENROUTER_BASE_URL,
|
|
33
|
-
getOpenRouterAttributionHeaders,
|
|
34
|
-
getOpenRouterBaseUrl,
|
|
35
|
-
init_openrouter_base_url
|
|
36
|
-
} from "./cli-a35hzdve.js";
|
|
37
|
-
import {
|
|
38
|
-
init_env_flag,
|
|
39
|
-
isEnvFlagEnabled
|
|
40
|
-
} from "./cli-ej6gbxfb.js";
|
|
41
|
-
import {
|
|
42
|
-
init_secret_scrubber,
|
|
43
|
-
scrubSecrets
|
|
44
|
-
} from "./cli-d161g69q.js";
|
|
45
|
-
import {
|
|
46
|
-
__toESM
|
|
47
|
-
} from "./cli-bc05qbss.js";
|
|
48
|
-
|
|
49
|
-
// src/providers/opencode-adapter.ts
|
|
50
|
-
import { existsSync, mkdirSync } from "node:fs";
|
|
51
|
-
import { join } from "node:path";
|
|
52
|
-
// node_modules/@opencode-ai/sdk/dist/gen/core/serverSentEvents.gen.js
|
|
53
|
-
var createSseClient = ({ onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) => {
|
|
54
|
-
let lastEventId;
|
|
55
|
-
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
56
|
-
const createStream = async function* () {
|
|
57
|
-
let retryDelay = sseDefaultRetryDelay ?? 3000;
|
|
58
|
-
let attempt = 0;
|
|
59
|
-
const signal = options.signal ?? new AbortController().signal;
|
|
60
|
-
while (true) {
|
|
61
|
-
if (signal.aborted)
|
|
62
|
-
break;
|
|
63
|
-
attempt++;
|
|
64
|
-
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
65
|
-
if (lastEventId !== undefined) {
|
|
66
|
-
headers.set("Last-Event-ID", lastEventId);
|
|
67
|
-
}
|
|
68
|
-
try {
|
|
69
|
-
const response = await fetch(url, { ...options, headers, signal });
|
|
70
|
-
if (!response.ok)
|
|
71
|
-
throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
72
|
-
if (!response.body)
|
|
73
|
-
throw new Error("No body in SSE response");
|
|
74
|
-
const reader = response.body.pipeThrough(new TextDecoderStream).getReader();
|
|
75
|
-
let buffer = "";
|
|
76
|
-
const abortHandler = () => {
|
|
77
|
-
try {
|
|
78
|
-
reader.cancel();
|
|
79
|
-
} catch {}
|
|
80
|
-
};
|
|
81
|
-
signal.addEventListener("abort", abortHandler);
|
|
82
|
-
try {
|
|
83
|
-
while (true) {
|
|
84
|
-
const { done, value } = await reader.read();
|
|
85
|
-
if (done)
|
|
86
|
-
break;
|
|
87
|
-
buffer += value;
|
|
88
|
-
const chunks = buffer.split(`
|
|
89
|
-
|
|
90
|
-
`);
|
|
91
|
-
buffer = chunks.pop() ?? "";
|
|
92
|
-
for (const chunk of chunks) {
|
|
93
|
-
const lines = chunk.split(`
|
|
94
|
-
`);
|
|
95
|
-
const dataLines = [];
|
|
96
|
-
let eventName;
|
|
97
|
-
for (const line of lines) {
|
|
98
|
-
if (line.startsWith("data:")) {
|
|
99
|
-
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
100
|
-
} else if (line.startsWith("event:")) {
|
|
101
|
-
eventName = line.replace(/^event:\s*/, "");
|
|
102
|
-
} else if (line.startsWith("id:")) {
|
|
103
|
-
lastEventId = line.replace(/^id:\s*/, "");
|
|
104
|
-
} else if (line.startsWith("retry:")) {
|
|
105
|
-
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
106
|
-
if (!Number.isNaN(parsed)) {
|
|
107
|
-
retryDelay = parsed;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
let data;
|
|
112
|
-
let parsedJson = false;
|
|
113
|
-
if (dataLines.length) {
|
|
114
|
-
const rawData = dataLines.join(`
|
|
115
|
-
`);
|
|
116
|
-
try {
|
|
117
|
-
data = JSON.parse(rawData);
|
|
118
|
-
parsedJson = true;
|
|
119
|
-
} catch {
|
|
120
|
-
data = rawData;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (parsedJson) {
|
|
124
|
-
if (responseValidator) {
|
|
125
|
-
await responseValidator(data);
|
|
126
|
-
}
|
|
127
|
-
if (responseTransformer) {
|
|
128
|
-
data = await responseTransformer(data);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
onSseEvent?.({
|
|
132
|
-
data,
|
|
133
|
-
event: eventName,
|
|
134
|
-
id: lastEventId,
|
|
135
|
-
retry: retryDelay
|
|
136
|
-
});
|
|
137
|
-
if (dataLines.length) {
|
|
138
|
-
yield data;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
} finally {
|
|
143
|
-
signal.removeEventListener("abort", abortHandler);
|
|
144
|
-
reader.releaseLock();
|
|
145
|
-
}
|
|
146
|
-
break;
|
|
147
|
-
} catch (error) {
|
|
148
|
-
onSseError?.(error);
|
|
149
|
-
if (sseMaxRetryAttempts !== undefined && attempt >= sseMaxRetryAttempts) {
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 30000);
|
|
153
|
-
await sleep(backoff);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
const stream = createStream();
|
|
158
|
-
return { stream };
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
// node_modules/@opencode-ai/sdk/dist/gen/core/auth.gen.js
|
|
162
|
-
var getAuthToken = async (auth, callback) => {
|
|
163
|
-
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
164
|
-
if (!token) {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
if (auth.scheme === "bearer") {
|
|
168
|
-
return `Bearer ${token}`;
|
|
169
|
-
}
|
|
170
|
-
if (auth.scheme === "basic") {
|
|
171
|
-
return `Basic ${btoa(token)}`;
|
|
172
|
-
}
|
|
173
|
-
return token;
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
// node_modules/@opencode-ai/sdk/dist/gen/core/bodySerializer.gen.js
|
|
177
|
-
var jsonBodySerializer = {
|
|
178
|
-
bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
// node_modules/@opencode-ai/sdk/dist/gen/core/pathSerializer.gen.js
|
|
182
|
-
var separatorArrayExplode = (style) => {
|
|
183
|
-
switch (style) {
|
|
184
|
-
case "label":
|
|
185
|
-
return ".";
|
|
186
|
-
case "matrix":
|
|
187
|
-
return ";";
|
|
188
|
-
case "simple":
|
|
189
|
-
return ",";
|
|
190
|
-
default:
|
|
191
|
-
return "&";
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
var separatorArrayNoExplode = (style) => {
|
|
195
|
-
switch (style) {
|
|
196
|
-
case "form":
|
|
197
|
-
return ",";
|
|
198
|
-
case "pipeDelimited":
|
|
199
|
-
return "|";
|
|
200
|
-
case "spaceDelimited":
|
|
201
|
-
return "%20";
|
|
202
|
-
default:
|
|
203
|
-
return ",";
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
var separatorObjectExplode = (style) => {
|
|
207
|
-
switch (style) {
|
|
208
|
-
case "label":
|
|
209
|
-
return ".";
|
|
210
|
-
case "matrix":
|
|
211
|
-
return ";";
|
|
212
|
-
case "simple":
|
|
213
|
-
return ",";
|
|
214
|
-
default:
|
|
215
|
-
return "&";
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
var serializeArrayParam = ({ allowReserved, explode, name, style, value }) => {
|
|
219
|
-
if (!explode) {
|
|
220
|
-
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
221
|
-
switch (style) {
|
|
222
|
-
case "label":
|
|
223
|
-
return `.${joinedValues2}`;
|
|
224
|
-
case "matrix":
|
|
225
|
-
return `;${name}=${joinedValues2}`;
|
|
226
|
-
case "simple":
|
|
227
|
-
return joinedValues2;
|
|
228
|
-
default:
|
|
229
|
-
return `${name}=${joinedValues2}`;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
const separator = separatorArrayExplode(style);
|
|
233
|
-
const joinedValues = value.map((v) => {
|
|
234
|
-
if (style === "label" || style === "simple") {
|
|
235
|
-
return allowReserved ? v : encodeURIComponent(v);
|
|
236
|
-
}
|
|
237
|
-
return serializePrimitiveParam({
|
|
238
|
-
allowReserved,
|
|
239
|
-
name,
|
|
240
|
-
value: v
|
|
241
|
-
});
|
|
242
|
-
}).join(separator);
|
|
243
|
-
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
244
|
-
};
|
|
245
|
-
var serializePrimitiveParam = ({ allowReserved, name, value }) => {
|
|
246
|
-
if (value === undefined || value === null) {
|
|
247
|
-
return "";
|
|
248
|
-
}
|
|
249
|
-
if (typeof value === "object") {
|
|
250
|
-
throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
|
|
251
|
-
}
|
|
252
|
-
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
253
|
-
};
|
|
254
|
-
var serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly }) => {
|
|
255
|
-
if (value instanceof Date) {
|
|
256
|
-
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
257
|
-
}
|
|
258
|
-
if (style !== "deepObject" && !explode) {
|
|
259
|
-
let values = [];
|
|
260
|
-
Object.entries(value).forEach(([key, v]) => {
|
|
261
|
-
values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
|
|
262
|
-
});
|
|
263
|
-
const joinedValues2 = values.join(",");
|
|
264
|
-
switch (style) {
|
|
265
|
-
case "form":
|
|
266
|
-
return `${name}=${joinedValues2}`;
|
|
267
|
-
case "label":
|
|
268
|
-
return `.${joinedValues2}`;
|
|
269
|
-
case "matrix":
|
|
270
|
-
return `;${name}=${joinedValues2}`;
|
|
271
|
-
default:
|
|
272
|
-
return joinedValues2;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
const separator = separatorObjectExplode(style);
|
|
276
|
-
const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
|
|
277
|
-
allowReserved,
|
|
278
|
-
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
279
|
-
value: v
|
|
280
|
-
})).join(separator);
|
|
281
|
-
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
// node_modules/@opencode-ai/sdk/dist/gen/core/utils.gen.js
|
|
285
|
-
var PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
286
|
-
var defaultPathSerializer = ({ path, url: _url }) => {
|
|
287
|
-
let url = _url;
|
|
288
|
-
const matches = _url.match(PATH_PARAM_RE);
|
|
289
|
-
if (matches) {
|
|
290
|
-
for (const match of matches) {
|
|
291
|
-
let explode = false;
|
|
292
|
-
let name = match.substring(1, match.length - 1);
|
|
293
|
-
let style = "simple";
|
|
294
|
-
if (name.endsWith("*")) {
|
|
295
|
-
explode = true;
|
|
296
|
-
name = name.substring(0, name.length - 1);
|
|
297
|
-
}
|
|
298
|
-
if (name.startsWith(".")) {
|
|
299
|
-
name = name.substring(1);
|
|
300
|
-
style = "label";
|
|
301
|
-
} else if (name.startsWith(";")) {
|
|
302
|
-
name = name.substring(1);
|
|
303
|
-
style = "matrix";
|
|
304
|
-
}
|
|
305
|
-
const value = path[name];
|
|
306
|
-
if (value === undefined || value === null) {
|
|
307
|
-
continue;
|
|
308
|
-
}
|
|
309
|
-
if (Array.isArray(value)) {
|
|
310
|
-
url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
|
|
311
|
-
continue;
|
|
312
|
-
}
|
|
313
|
-
if (typeof value === "object") {
|
|
314
|
-
url = url.replace(match, serializeObjectParam({
|
|
315
|
-
explode,
|
|
316
|
-
name,
|
|
317
|
-
style,
|
|
318
|
-
value,
|
|
319
|
-
valueOnly: true
|
|
320
|
-
}));
|
|
321
|
-
continue;
|
|
322
|
-
}
|
|
323
|
-
if (style === "matrix") {
|
|
324
|
-
url = url.replace(match, `;${serializePrimitiveParam({
|
|
325
|
-
name,
|
|
326
|
-
value
|
|
327
|
-
})}`);
|
|
328
|
-
continue;
|
|
329
|
-
}
|
|
330
|
-
const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
|
|
331
|
-
url = url.replace(match, replaceValue);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
return url;
|
|
335
|
-
};
|
|
336
|
-
var getUrl = ({ baseUrl, path, query, querySerializer, url: _url }) => {
|
|
337
|
-
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
338
|
-
let url = (baseUrl ?? "") + pathUrl;
|
|
339
|
-
if (path) {
|
|
340
|
-
url = defaultPathSerializer({ path, url });
|
|
341
|
-
}
|
|
342
|
-
let search = query ? querySerializer(query) : "";
|
|
343
|
-
if (search.startsWith("?")) {
|
|
344
|
-
search = search.substring(1);
|
|
345
|
-
}
|
|
346
|
-
if (search) {
|
|
347
|
-
url += `?${search}`;
|
|
348
|
-
}
|
|
349
|
-
return url;
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
// node_modules/@opencode-ai/sdk/dist/gen/client/utils.gen.js
|
|
353
|
-
var createQuerySerializer = ({ allowReserved, array, object } = {}) => {
|
|
354
|
-
const querySerializer = (queryParams) => {
|
|
355
|
-
const search = [];
|
|
356
|
-
if (queryParams && typeof queryParams === "object") {
|
|
357
|
-
for (const name in queryParams) {
|
|
358
|
-
const value = queryParams[name];
|
|
359
|
-
if (value === undefined || value === null) {
|
|
360
|
-
continue;
|
|
361
|
-
}
|
|
362
|
-
if (Array.isArray(value)) {
|
|
363
|
-
const serializedArray = serializeArrayParam({
|
|
364
|
-
allowReserved,
|
|
365
|
-
explode: true,
|
|
366
|
-
name,
|
|
367
|
-
style: "form",
|
|
368
|
-
value,
|
|
369
|
-
...array
|
|
370
|
-
});
|
|
371
|
-
if (serializedArray)
|
|
372
|
-
search.push(serializedArray);
|
|
373
|
-
} else if (typeof value === "object") {
|
|
374
|
-
const serializedObject = serializeObjectParam({
|
|
375
|
-
allowReserved,
|
|
376
|
-
explode: true,
|
|
377
|
-
name,
|
|
378
|
-
style: "deepObject",
|
|
379
|
-
value,
|
|
380
|
-
...object
|
|
381
|
-
});
|
|
382
|
-
if (serializedObject)
|
|
383
|
-
search.push(serializedObject);
|
|
384
|
-
} else {
|
|
385
|
-
const serializedPrimitive = serializePrimitiveParam({
|
|
386
|
-
allowReserved,
|
|
387
|
-
name,
|
|
388
|
-
value
|
|
389
|
-
});
|
|
390
|
-
if (serializedPrimitive)
|
|
391
|
-
search.push(serializedPrimitive);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
return search.join("&");
|
|
396
|
-
};
|
|
397
|
-
return querySerializer;
|
|
398
|
-
};
|
|
399
|
-
var getParseAs = (contentType) => {
|
|
400
|
-
if (!contentType) {
|
|
401
|
-
return "stream";
|
|
402
|
-
}
|
|
403
|
-
const cleanContent = contentType.split(";")[0]?.trim();
|
|
404
|
-
if (!cleanContent) {
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
408
|
-
return "json";
|
|
409
|
-
}
|
|
410
|
-
if (cleanContent === "multipart/form-data") {
|
|
411
|
-
return "formData";
|
|
412
|
-
}
|
|
413
|
-
if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
|
|
414
|
-
return "blob";
|
|
415
|
-
}
|
|
416
|
-
if (cleanContent.startsWith("text/")) {
|
|
417
|
-
return "text";
|
|
418
|
-
}
|
|
419
|
-
return;
|
|
420
|
-
};
|
|
421
|
-
var checkForExistence = (options, name) => {
|
|
422
|
-
if (!name) {
|
|
423
|
-
return false;
|
|
424
|
-
}
|
|
425
|
-
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
|
426
|
-
return true;
|
|
427
|
-
}
|
|
428
|
-
return false;
|
|
429
|
-
};
|
|
430
|
-
var setAuthParams = async ({ security, ...options }) => {
|
|
431
|
-
for (const auth of security) {
|
|
432
|
-
if (checkForExistence(options, auth.name)) {
|
|
433
|
-
continue;
|
|
434
|
-
}
|
|
435
|
-
const token = await getAuthToken(auth, options.auth);
|
|
436
|
-
if (!token) {
|
|
437
|
-
continue;
|
|
438
|
-
}
|
|
439
|
-
const name = auth.name ?? "Authorization";
|
|
440
|
-
switch (auth.in) {
|
|
441
|
-
case "query":
|
|
442
|
-
if (!options.query) {
|
|
443
|
-
options.query = {};
|
|
444
|
-
}
|
|
445
|
-
options.query[name] = token;
|
|
446
|
-
break;
|
|
447
|
-
case "cookie":
|
|
448
|
-
options.headers.append("Cookie", `${name}=${token}`);
|
|
449
|
-
break;
|
|
450
|
-
case "header":
|
|
451
|
-
default:
|
|
452
|
-
options.headers.set(name, token);
|
|
453
|
-
break;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
var buildUrl = (options) => getUrl({
|
|
458
|
-
baseUrl: options.baseUrl,
|
|
459
|
-
path: options.path,
|
|
460
|
-
query: options.query,
|
|
461
|
-
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
462
|
-
url: options.url
|
|
463
|
-
});
|
|
464
|
-
var mergeConfigs = (a, b) => {
|
|
465
|
-
const config = { ...a, ...b };
|
|
466
|
-
if (config.baseUrl?.endsWith("/")) {
|
|
467
|
-
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
468
|
-
}
|
|
469
|
-
config.headers = mergeHeaders(a.headers, b.headers);
|
|
470
|
-
return config;
|
|
471
|
-
};
|
|
472
|
-
var mergeHeaders = (...headers) => {
|
|
473
|
-
const mergedHeaders = new Headers;
|
|
474
|
-
for (const header of headers) {
|
|
475
|
-
if (!header || typeof header !== "object") {
|
|
476
|
-
continue;
|
|
477
|
-
}
|
|
478
|
-
const iterator = header instanceof Headers ? header.entries() : Object.entries(header);
|
|
479
|
-
for (const [key, value] of iterator) {
|
|
480
|
-
if (value === null) {
|
|
481
|
-
mergedHeaders.delete(key);
|
|
482
|
-
} else if (Array.isArray(value)) {
|
|
483
|
-
for (const v of value) {
|
|
484
|
-
mergedHeaders.append(key, v);
|
|
485
|
-
}
|
|
486
|
-
} else if (value !== undefined) {
|
|
487
|
-
mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
return mergedHeaders;
|
|
492
|
-
};
|
|
493
|
-
|
|
494
|
-
class Interceptors {
|
|
495
|
-
_fns;
|
|
496
|
-
constructor() {
|
|
497
|
-
this._fns = [];
|
|
498
|
-
}
|
|
499
|
-
clear() {
|
|
500
|
-
this._fns = [];
|
|
501
|
-
}
|
|
502
|
-
getInterceptorIndex(id) {
|
|
503
|
-
if (typeof id === "number") {
|
|
504
|
-
return this._fns[id] ? id : -1;
|
|
505
|
-
} else {
|
|
506
|
-
return this._fns.indexOf(id);
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
exists(id) {
|
|
510
|
-
const index = this.getInterceptorIndex(id);
|
|
511
|
-
return !!this._fns[index];
|
|
512
|
-
}
|
|
513
|
-
eject(id) {
|
|
514
|
-
const index = this.getInterceptorIndex(id);
|
|
515
|
-
if (this._fns[index]) {
|
|
516
|
-
this._fns[index] = null;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
update(id, fn) {
|
|
520
|
-
const index = this.getInterceptorIndex(id);
|
|
521
|
-
if (this._fns[index]) {
|
|
522
|
-
this._fns[index] = fn;
|
|
523
|
-
return id;
|
|
524
|
-
} else {
|
|
525
|
-
return false;
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
use(fn) {
|
|
529
|
-
this._fns = [...this._fns, fn];
|
|
530
|
-
return this._fns.length - 1;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
var createInterceptors = () => ({
|
|
534
|
-
error: new Interceptors,
|
|
535
|
-
request: new Interceptors,
|
|
536
|
-
response: new Interceptors
|
|
537
|
-
});
|
|
538
|
-
var defaultQuerySerializer = createQuerySerializer({
|
|
539
|
-
allowReserved: false,
|
|
540
|
-
array: {
|
|
541
|
-
explode: true,
|
|
542
|
-
style: "form"
|
|
543
|
-
},
|
|
544
|
-
object: {
|
|
545
|
-
explode: true,
|
|
546
|
-
style: "deepObject"
|
|
547
|
-
}
|
|
548
|
-
});
|
|
549
|
-
var defaultHeaders = {
|
|
550
|
-
"Content-Type": "application/json"
|
|
551
|
-
};
|
|
552
|
-
var createConfig = (override = {}) => ({
|
|
553
|
-
...jsonBodySerializer,
|
|
554
|
-
headers: defaultHeaders,
|
|
555
|
-
parseAs: "auto",
|
|
556
|
-
querySerializer: defaultQuerySerializer,
|
|
557
|
-
...override
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
// node_modules/@opencode-ai/sdk/dist/gen/client/client.gen.js
|
|
561
|
-
var createClient = (config = {}) => {
|
|
562
|
-
let _config = mergeConfigs(createConfig(), config);
|
|
563
|
-
const getConfig = () => ({ ..._config });
|
|
564
|
-
const setConfig = (config2) => {
|
|
565
|
-
_config = mergeConfigs(_config, config2);
|
|
566
|
-
return getConfig();
|
|
567
|
-
};
|
|
568
|
-
const interceptors = createInterceptors();
|
|
569
|
-
const beforeRequest = async (options) => {
|
|
570
|
-
const opts = {
|
|
571
|
-
..._config,
|
|
572
|
-
...options,
|
|
573
|
-
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
574
|
-
headers: mergeHeaders(_config.headers, options.headers),
|
|
575
|
-
serializedBody: undefined
|
|
576
|
-
};
|
|
577
|
-
if (opts.security) {
|
|
578
|
-
await setAuthParams({
|
|
579
|
-
...opts,
|
|
580
|
-
security: opts.security
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
if (opts.requestValidator) {
|
|
584
|
-
await opts.requestValidator(opts);
|
|
585
|
-
}
|
|
586
|
-
if (opts.body && opts.bodySerializer) {
|
|
587
|
-
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
588
|
-
}
|
|
589
|
-
if (opts.serializedBody === undefined || opts.serializedBody === "") {
|
|
590
|
-
opts.headers.delete("Content-Type");
|
|
591
|
-
}
|
|
592
|
-
const url = buildUrl(opts);
|
|
593
|
-
return { opts, url };
|
|
594
|
-
};
|
|
595
|
-
const request = async (options) => {
|
|
596
|
-
const { opts, url } = await beforeRequest(options);
|
|
597
|
-
const requestInit = {
|
|
598
|
-
redirect: "follow",
|
|
599
|
-
...opts,
|
|
600
|
-
body: opts.serializedBody
|
|
601
|
-
};
|
|
602
|
-
let request2 = new Request(url, requestInit);
|
|
603
|
-
for (const fn of interceptors.request._fns) {
|
|
604
|
-
if (fn) {
|
|
605
|
-
request2 = await fn(request2, opts);
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
const _fetch = opts.fetch;
|
|
609
|
-
let response = await _fetch(request2);
|
|
610
|
-
for (const fn of interceptors.response._fns) {
|
|
611
|
-
if (fn) {
|
|
612
|
-
response = await fn(response, request2, opts);
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
const result = {
|
|
616
|
-
request: request2,
|
|
617
|
-
response
|
|
618
|
-
};
|
|
619
|
-
if (response.ok) {
|
|
620
|
-
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
621
|
-
return opts.responseStyle === "data" ? {} : {
|
|
622
|
-
data: {},
|
|
623
|
-
...result
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
627
|
-
let data;
|
|
628
|
-
switch (parseAs) {
|
|
629
|
-
case "arrayBuffer":
|
|
630
|
-
case "blob":
|
|
631
|
-
case "formData":
|
|
632
|
-
case "json":
|
|
633
|
-
case "text":
|
|
634
|
-
data = await response[parseAs]();
|
|
635
|
-
break;
|
|
636
|
-
case "stream":
|
|
637
|
-
return opts.responseStyle === "data" ? response.body : {
|
|
638
|
-
data: response.body,
|
|
639
|
-
...result
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
if (parseAs === "json") {
|
|
643
|
-
if (opts.responseValidator) {
|
|
644
|
-
await opts.responseValidator(data);
|
|
645
|
-
}
|
|
646
|
-
if (opts.responseTransformer) {
|
|
647
|
-
data = await opts.responseTransformer(data);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
return opts.responseStyle === "data" ? data : {
|
|
651
|
-
data,
|
|
652
|
-
...result
|
|
653
|
-
};
|
|
654
|
-
}
|
|
655
|
-
const textError = await response.text();
|
|
656
|
-
let jsonError;
|
|
657
|
-
try {
|
|
658
|
-
jsonError = JSON.parse(textError);
|
|
659
|
-
} catch {}
|
|
660
|
-
const error = jsonError ?? textError;
|
|
661
|
-
let finalError = error;
|
|
662
|
-
for (const fn of interceptors.error._fns) {
|
|
663
|
-
if (fn) {
|
|
664
|
-
finalError = await fn(error, response, request2, opts);
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
finalError = finalError || {};
|
|
668
|
-
if (opts.throwOnError) {
|
|
669
|
-
throw finalError;
|
|
670
|
-
}
|
|
671
|
-
return opts.responseStyle === "data" ? undefined : {
|
|
672
|
-
error: finalError,
|
|
673
|
-
...result
|
|
674
|
-
};
|
|
675
|
-
};
|
|
676
|
-
const makeMethod = (method) => {
|
|
677
|
-
const fn = (options) => request({ ...options, method });
|
|
678
|
-
fn.sse = async (options) => {
|
|
679
|
-
const { opts, url } = await beforeRequest(options);
|
|
680
|
-
return createSseClient({
|
|
681
|
-
...opts,
|
|
682
|
-
body: opts.body,
|
|
683
|
-
headers: opts.headers,
|
|
684
|
-
method,
|
|
685
|
-
url
|
|
686
|
-
});
|
|
687
|
-
};
|
|
688
|
-
return fn;
|
|
689
|
-
};
|
|
690
|
-
return {
|
|
691
|
-
buildUrl,
|
|
692
|
-
connect: makeMethod("CONNECT"),
|
|
693
|
-
delete: makeMethod("DELETE"),
|
|
694
|
-
get: makeMethod("GET"),
|
|
695
|
-
getConfig,
|
|
696
|
-
head: makeMethod("HEAD"),
|
|
697
|
-
interceptors,
|
|
698
|
-
options: makeMethod("OPTIONS"),
|
|
699
|
-
patch: makeMethod("PATCH"),
|
|
700
|
-
post: makeMethod("POST"),
|
|
701
|
-
put: makeMethod("PUT"),
|
|
702
|
-
request,
|
|
703
|
-
setConfig,
|
|
704
|
-
trace: makeMethod("TRACE")
|
|
705
|
-
};
|
|
706
|
-
};
|
|
707
|
-
// node_modules/@opencode-ai/sdk/dist/gen/core/params.gen.js
|
|
708
|
-
var extraPrefixesMap = {
|
|
709
|
-
$body_: "body",
|
|
710
|
-
$headers_: "headers",
|
|
711
|
-
$path_: "path",
|
|
712
|
-
$query_: "query"
|
|
713
|
-
};
|
|
714
|
-
var extraPrefixes = Object.entries(extraPrefixesMap);
|
|
715
|
-
// node_modules/@opencode-ai/sdk/dist/gen/client.gen.js
|
|
716
|
-
var client = createClient(createConfig({
|
|
717
|
-
baseUrl: "http://localhost:4096"
|
|
718
|
-
}));
|
|
719
|
-
|
|
720
|
-
// node_modules/@opencode-ai/sdk/dist/gen/sdk.gen.js
|
|
721
|
-
class _HeyApiClient {
|
|
722
|
-
_client = client;
|
|
723
|
-
constructor(args) {
|
|
724
|
-
if (args?.client) {
|
|
725
|
-
this._client = args.client;
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
class Global extends _HeyApiClient {
|
|
731
|
-
event(options) {
|
|
732
|
-
return (options?.client ?? this._client).get.sse({
|
|
733
|
-
url: "/global/event",
|
|
734
|
-
...options
|
|
735
|
-
});
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
class Project extends _HeyApiClient {
|
|
740
|
-
list(options) {
|
|
741
|
-
return (options?.client ?? this._client).get({
|
|
742
|
-
url: "/project",
|
|
743
|
-
...options
|
|
744
|
-
});
|
|
745
|
-
}
|
|
746
|
-
current(options) {
|
|
747
|
-
return (options?.client ?? this._client).get({
|
|
748
|
-
url: "/project/current",
|
|
749
|
-
...options
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
class Pty extends _HeyApiClient {
|
|
755
|
-
list(options) {
|
|
756
|
-
return (options?.client ?? this._client).get({
|
|
757
|
-
url: "/pty",
|
|
758
|
-
...options
|
|
759
|
-
});
|
|
760
|
-
}
|
|
761
|
-
create(options) {
|
|
762
|
-
return (options?.client ?? this._client).post({
|
|
763
|
-
url: "/pty",
|
|
764
|
-
...options,
|
|
765
|
-
headers: {
|
|
766
|
-
"Content-Type": "application/json",
|
|
767
|
-
...options?.headers
|
|
768
|
-
}
|
|
769
|
-
});
|
|
770
|
-
}
|
|
771
|
-
remove(options) {
|
|
772
|
-
return (options.client ?? this._client).delete({
|
|
773
|
-
url: "/pty/{id}",
|
|
774
|
-
...options
|
|
775
|
-
});
|
|
776
|
-
}
|
|
777
|
-
get(options) {
|
|
778
|
-
return (options.client ?? this._client).get({
|
|
779
|
-
url: "/pty/{id}",
|
|
780
|
-
...options
|
|
781
|
-
});
|
|
782
|
-
}
|
|
783
|
-
update(options) {
|
|
784
|
-
return (options.client ?? this._client).put({
|
|
785
|
-
url: "/pty/{id}",
|
|
786
|
-
...options,
|
|
787
|
-
headers: {
|
|
788
|
-
"Content-Type": "application/json",
|
|
789
|
-
...options.headers
|
|
790
|
-
}
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
connect(options) {
|
|
794
|
-
return (options.client ?? this._client).get({
|
|
795
|
-
url: "/pty/{id}/connect",
|
|
796
|
-
...options
|
|
797
|
-
});
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
class Config extends _HeyApiClient {
|
|
802
|
-
get(options) {
|
|
803
|
-
return (options?.client ?? this._client).get({
|
|
804
|
-
url: "/config",
|
|
805
|
-
...options
|
|
806
|
-
});
|
|
807
|
-
}
|
|
808
|
-
update(options) {
|
|
809
|
-
return (options?.client ?? this._client).patch({
|
|
810
|
-
url: "/config",
|
|
811
|
-
...options,
|
|
812
|
-
headers: {
|
|
813
|
-
"Content-Type": "application/json",
|
|
814
|
-
...options?.headers
|
|
815
|
-
}
|
|
816
|
-
});
|
|
817
|
-
}
|
|
818
|
-
providers(options) {
|
|
819
|
-
return (options?.client ?? this._client).get({
|
|
820
|
-
url: "/config/providers",
|
|
821
|
-
...options
|
|
822
|
-
});
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
class Tool extends _HeyApiClient {
|
|
827
|
-
ids(options) {
|
|
828
|
-
return (options?.client ?? this._client).get({
|
|
829
|
-
url: "/experimental/tool/ids",
|
|
830
|
-
...options
|
|
831
|
-
});
|
|
832
|
-
}
|
|
833
|
-
list(options) {
|
|
834
|
-
return (options.client ?? this._client).get({
|
|
835
|
-
url: "/experimental/tool",
|
|
836
|
-
...options
|
|
837
|
-
});
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
class Instance extends _HeyApiClient {
|
|
842
|
-
dispose(options) {
|
|
843
|
-
return (options?.client ?? this._client).post({
|
|
844
|
-
url: "/instance/dispose",
|
|
845
|
-
...options
|
|
846
|
-
});
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
class Path extends _HeyApiClient {
|
|
851
|
-
get(options) {
|
|
852
|
-
return (options?.client ?? this._client).get({
|
|
853
|
-
url: "/path",
|
|
854
|
-
...options
|
|
855
|
-
});
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
class Vcs extends _HeyApiClient {
|
|
860
|
-
get(options) {
|
|
861
|
-
return (options?.client ?? this._client).get({
|
|
862
|
-
url: "/vcs",
|
|
863
|
-
...options
|
|
864
|
-
});
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
class Session extends _HeyApiClient {
|
|
869
|
-
list(options) {
|
|
870
|
-
return (options?.client ?? this._client).get({
|
|
871
|
-
url: "/session",
|
|
872
|
-
...options
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
create(options) {
|
|
876
|
-
return (options?.client ?? this._client).post({
|
|
877
|
-
url: "/session",
|
|
878
|
-
...options,
|
|
879
|
-
headers: {
|
|
880
|
-
"Content-Type": "application/json",
|
|
881
|
-
...options?.headers
|
|
882
|
-
}
|
|
883
|
-
});
|
|
884
|
-
}
|
|
885
|
-
status(options) {
|
|
886
|
-
return (options?.client ?? this._client).get({
|
|
887
|
-
url: "/session/status",
|
|
888
|
-
...options
|
|
889
|
-
});
|
|
890
|
-
}
|
|
891
|
-
delete(options) {
|
|
892
|
-
return (options.client ?? this._client).delete({
|
|
893
|
-
url: "/session/{id}",
|
|
894
|
-
...options
|
|
895
|
-
});
|
|
896
|
-
}
|
|
897
|
-
get(options) {
|
|
898
|
-
return (options.client ?? this._client).get({
|
|
899
|
-
url: "/session/{id}",
|
|
900
|
-
...options
|
|
901
|
-
});
|
|
902
|
-
}
|
|
903
|
-
update(options) {
|
|
904
|
-
return (options.client ?? this._client).patch({
|
|
905
|
-
url: "/session/{id}",
|
|
906
|
-
...options,
|
|
907
|
-
headers: {
|
|
908
|
-
"Content-Type": "application/json",
|
|
909
|
-
...options.headers
|
|
910
|
-
}
|
|
911
|
-
});
|
|
912
|
-
}
|
|
913
|
-
children(options) {
|
|
914
|
-
return (options.client ?? this._client).get({
|
|
915
|
-
url: "/session/{id}/children",
|
|
916
|
-
...options
|
|
917
|
-
});
|
|
918
|
-
}
|
|
919
|
-
todo(options) {
|
|
920
|
-
return (options.client ?? this._client).get({
|
|
921
|
-
url: "/session/{id}/todo",
|
|
922
|
-
...options
|
|
923
|
-
});
|
|
924
|
-
}
|
|
925
|
-
init(options) {
|
|
926
|
-
return (options.client ?? this._client).post({
|
|
927
|
-
url: "/session/{id}/init",
|
|
928
|
-
...options,
|
|
929
|
-
headers: {
|
|
930
|
-
"Content-Type": "application/json",
|
|
931
|
-
...options.headers
|
|
932
|
-
}
|
|
933
|
-
});
|
|
934
|
-
}
|
|
935
|
-
fork(options) {
|
|
936
|
-
return (options.client ?? this._client).post({
|
|
937
|
-
url: "/session/{id}/fork",
|
|
938
|
-
...options,
|
|
939
|
-
headers: {
|
|
940
|
-
"Content-Type": "application/json",
|
|
941
|
-
...options.headers
|
|
942
|
-
}
|
|
943
|
-
});
|
|
944
|
-
}
|
|
945
|
-
abort(options) {
|
|
946
|
-
return (options.client ?? this._client).post({
|
|
947
|
-
url: "/session/{id}/abort",
|
|
948
|
-
...options
|
|
949
|
-
});
|
|
950
|
-
}
|
|
951
|
-
unshare(options) {
|
|
952
|
-
return (options.client ?? this._client).delete({
|
|
953
|
-
url: "/session/{id}/share",
|
|
954
|
-
...options
|
|
955
|
-
});
|
|
956
|
-
}
|
|
957
|
-
share(options) {
|
|
958
|
-
return (options.client ?? this._client).post({
|
|
959
|
-
url: "/session/{id}/share",
|
|
960
|
-
...options
|
|
961
|
-
});
|
|
962
|
-
}
|
|
963
|
-
diff(options) {
|
|
964
|
-
return (options.client ?? this._client).get({
|
|
965
|
-
url: "/session/{id}/diff",
|
|
966
|
-
...options
|
|
967
|
-
});
|
|
968
|
-
}
|
|
969
|
-
summarize(options) {
|
|
970
|
-
return (options.client ?? this._client).post({
|
|
971
|
-
url: "/session/{id}/summarize",
|
|
972
|
-
...options,
|
|
973
|
-
headers: {
|
|
974
|
-
"Content-Type": "application/json",
|
|
975
|
-
...options.headers
|
|
976
|
-
}
|
|
977
|
-
});
|
|
978
|
-
}
|
|
979
|
-
messages(options) {
|
|
980
|
-
return (options.client ?? this._client).get({
|
|
981
|
-
url: "/session/{id}/message",
|
|
982
|
-
...options
|
|
983
|
-
});
|
|
984
|
-
}
|
|
985
|
-
prompt(options) {
|
|
986
|
-
return (options.client ?? this._client).post({
|
|
987
|
-
url: "/session/{id}/message",
|
|
988
|
-
...options,
|
|
989
|
-
headers: {
|
|
990
|
-
"Content-Type": "application/json",
|
|
991
|
-
...options.headers
|
|
992
|
-
}
|
|
993
|
-
});
|
|
994
|
-
}
|
|
995
|
-
message(options) {
|
|
996
|
-
return (options.client ?? this._client).get({
|
|
997
|
-
url: "/session/{id}/message/{messageID}",
|
|
998
|
-
...options
|
|
999
|
-
});
|
|
1000
|
-
}
|
|
1001
|
-
promptAsync(options) {
|
|
1002
|
-
return (options.client ?? this._client).post({
|
|
1003
|
-
url: "/session/{id}/prompt_async",
|
|
1004
|
-
...options,
|
|
1005
|
-
headers: {
|
|
1006
|
-
"Content-Type": "application/json",
|
|
1007
|
-
...options.headers
|
|
1008
|
-
}
|
|
1009
|
-
});
|
|
1010
|
-
}
|
|
1011
|
-
command(options) {
|
|
1012
|
-
return (options.client ?? this._client).post({
|
|
1013
|
-
url: "/session/{id}/command",
|
|
1014
|
-
...options,
|
|
1015
|
-
headers: {
|
|
1016
|
-
"Content-Type": "application/json",
|
|
1017
|
-
...options.headers
|
|
1018
|
-
}
|
|
1019
|
-
});
|
|
1020
|
-
}
|
|
1021
|
-
shell(options) {
|
|
1022
|
-
return (options.client ?? this._client).post({
|
|
1023
|
-
url: "/session/{id}/shell",
|
|
1024
|
-
...options,
|
|
1025
|
-
headers: {
|
|
1026
|
-
"Content-Type": "application/json",
|
|
1027
|
-
...options.headers
|
|
1028
|
-
}
|
|
1029
|
-
});
|
|
1030
|
-
}
|
|
1031
|
-
revert(options) {
|
|
1032
|
-
return (options.client ?? this._client).post({
|
|
1033
|
-
url: "/session/{id}/revert",
|
|
1034
|
-
...options,
|
|
1035
|
-
headers: {
|
|
1036
|
-
"Content-Type": "application/json",
|
|
1037
|
-
...options.headers
|
|
1038
|
-
}
|
|
1039
|
-
});
|
|
1040
|
-
}
|
|
1041
|
-
unrevert(options) {
|
|
1042
|
-
return (options.client ?? this._client).post({
|
|
1043
|
-
url: "/session/{id}/unrevert",
|
|
1044
|
-
...options
|
|
1045
|
-
});
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
1048
|
-
|
|
1049
|
-
class Command extends _HeyApiClient {
|
|
1050
|
-
list(options) {
|
|
1051
|
-
return (options?.client ?? this._client).get({
|
|
1052
|
-
url: "/command",
|
|
1053
|
-
...options
|
|
1054
|
-
});
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
class Oauth extends _HeyApiClient {
|
|
1059
|
-
authorize(options) {
|
|
1060
|
-
return (options.client ?? this._client).post({
|
|
1061
|
-
url: "/provider/{id}/oauth/authorize",
|
|
1062
|
-
...options,
|
|
1063
|
-
headers: {
|
|
1064
|
-
"Content-Type": "application/json",
|
|
1065
|
-
...options.headers
|
|
1066
|
-
}
|
|
1067
|
-
});
|
|
1068
|
-
}
|
|
1069
|
-
callback(options) {
|
|
1070
|
-
return (options.client ?? this._client).post({
|
|
1071
|
-
url: "/provider/{id}/oauth/callback",
|
|
1072
|
-
...options,
|
|
1073
|
-
headers: {
|
|
1074
|
-
"Content-Type": "application/json",
|
|
1075
|
-
...options.headers
|
|
1076
|
-
}
|
|
1077
|
-
});
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
class Provider extends _HeyApiClient {
|
|
1082
|
-
list(options) {
|
|
1083
|
-
return (options?.client ?? this._client).get({
|
|
1084
|
-
url: "/provider",
|
|
1085
|
-
...options
|
|
1086
|
-
});
|
|
1087
|
-
}
|
|
1088
|
-
auth(options) {
|
|
1089
|
-
return (options?.client ?? this._client).get({
|
|
1090
|
-
url: "/provider/auth",
|
|
1091
|
-
...options
|
|
1092
|
-
});
|
|
1093
|
-
}
|
|
1094
|
-
oauth = new Oauth({ client: this._client });
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
class Find extends _HeyApiClient {
|
|
1098
|
-
text(options) {
|
|
1099
|
-
return (options.client ?? this._client).get({
|
|
1100
|
-
url: "/find",
|
|
1101
|
-
...options
|
|
1102
|
-
});
|
|
1103
|
-
}
|
|
1104
|
-
files(options) {
|
|
1105
|
-
return (options.client ?? this._client).get({
|
|
1106
|
-
url: "/find/file",
|
|
1107
|
-
...options
|
|
1108
|
-
});
|
|
1109
|
-
}
|
|
1110
|
-
symbols(options) {
|
|
1111
|
-
return (options.client ?? this._client).get({
|
|
1112
|
-
url: "/find/symbol",
|
|
1113
|
-
...options
|
|
1114
|
-
});
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
class File extends _HeyApiClient {
|
|
1119
|
-
list(options) {
|
|
1120
|
-
return (options.client ?? this._client).get({
|
|
1121
|
-
url: "/file",
|
|
1122
|
-
...options
|
|
1123
|
-
});
|
|
1124
|
-
}
|
|
1125
|
-
read(options) {
|
|
1126
|
-
return (options.client ?? this._client).get({
|
|
1127
|
-
url: "/file/content",
|
|
1128
|
-
...options
|
|
1129
|
-
});
|
|
1130
|
-
}
|
|
1131
|
-
status(options) {
|
|
1132
|
-
return (options?.client ?? this._client).get({
|
|
1133
|
-
url: "/file/status",
|
|
1134
|
-
...options
|
|
1135
|
-
});
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
|
|
1139
|
-
class App extends _HeyApiClient {
|
|
1140
|
-
log(options) {
|
|
1141
|
-
return (options?.client ?? this._client).post({
|
|
1142
|
-
url: "/log",
|
|
1143
|
-
...options,
|
|
1144
|
-
headers: {
|
|
1145
|
-
"Content-Type": "application/json",
|
|
1146
|
-
...options?.headers
|
|
1147
|
-
}
|
|
1148
|
-
});
|
|
1149
|
-
}
|
|
1150
|
-
agents(options) {
|
|
1151
|
-
return (options?.client ?? this._client).get({
|
|
1152
|
-
url: "/agent",
|
|
1153
|
-
...options
|
|
1154
|
-
});
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
class Auth extends _HeyApiClient {
|
|
1159
|
-
remove(options) {
|
|
1160
|
-
return (options.client ?? this._client).delete({
|
|
1161
|
-
url: "/mcp/{name}/auth",
|
|
1162
|
-
...options
|
|
1163
|
-
});
|
|
1164
|
-
}
|
|
1165
|
-
start(options) {
|
|
1166
|
-
return (options.client ?? this._client).post({
|
|
1167
|
-
url: "/mcp/{name}/auth",
|
|
1168
|
-
...options
|
|
1169
|
-
});
|
|
1170
|
-
}
|
|
1171
|
-
callback(options) {
|
|
1172
|
-
return (options.client ?? this._client).post({
|
|
1173
|
-
url: "/mcp/{name}/auth/callback",
|
|
1174
|
-
...options,
|
|
1175
|
-
headers: {
|
|
1176
|
-
"Content-Type": "application/json",
|
|
1177
|
-
...options.headers
|
|
1178
|
-
}
|
|
1179
|
-
});
|
|
1180
|
-
}
|
|
1181
|
-
authenticate(options) {
|
|
1182
|
-
return (options.client ?? this._client).post({
|
|
1183
|
-
url: "/mcp/{name}/auth/authenticate",
|
|
1184
|
-
...options
|
|
1185
|
-
});
|
|
1186
|
-
}
|
|
1187
|
-
set(options) {
|
|
1188
|
-
return (options.client ?? this._client).put({
|
|
1189
|
-
url: "/auth/{id}",
|
|
1190
|
-
...options,
|
|
1191
|
-
headers: {
|
|
1192
|
-
"Content-Type": "application/json",
|
|
1193
|
-
...options.headers
|
|
1194
|
-
}
|
|
1195
|
-
});
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
class Mcp extends _HeyApiClient {
|
|
1200
|
-
status(options) {
|
|
1201
|
-
return (options?.client ?? this._client).get({
|
|
1202
|
-
url: "/mcp",
|
|
1203
|
-
...options
|
|
1204
|
-
});
|
|
1205
|
-
}
|
|
1206
|
-
add(options) {
|
|
1207
|
-
return (options?.client ?? this._client).post({
|
|
1208
|
-
url: "/mcp",
|
|
1209
|
-
...options,
|
|
1210
|
-
headers: {
|
|
1211
|
-
"Content-Type": "application/json",
|
|
1212
|
-
...options?.headers
|
|
1213
|
-
}
|
|
1214
|
-
});
|
|
1215
|
-
}
|
|
1216
|
-
connect(options) {
|
|
1217
|
-
return (options.client ?? this._client).post({
|
|
1218
|
-
url: "/mcp/{name}/connect",
|
|
1219
|
-
...options
|
|
1220
|
-
});
|
|
1221
|
-
}
|
|
1222
|
-
disconnect(options) {
|
|
1223
|
-
return (options.client ?? this._client).post({
|
|
1224
|
-
url: "/mcp/{name}/disconnect",
|
|
1225
|
-
...options
|
|
1226
|
-
});
|
|
1227
|
-
}
|
|
1228
|
-
auth = new Auth({ client: this._client });
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
class Lsp extends _HeyApiClient {
|
|
1232
|
-
status(options) {
|
|
1233
|
-
return (options?.client ?? this._client).get({
|
|
1234
|
-
url: "/lsp",
|
|
1235
|
-
...options
|
|
1236
|
-
});
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
class Formatter extends _HeyApiClient {
|
|
1241
|
-
status(options) {
|
|
1242
|
-
return (options?.client ?? this._client).get({
|
|
1243
|
-
url: "/formatter",
|
|
1244
|
-
...options
|
|
1245
|
-
});
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
class Control extends _HeyApiClient {
|
|
1250
|
-
next(options) {
|
|
1251
|
-
return (options?.client ?? this._client).get({
|
|
1252
|
-
url: "/tui/control/next",
|
|
1253
|
-
...options
|
|
1254
|
-
});
|
|
1255
|
-
}
|
|
1256
|
-
response(options) {
|
|
1257
|
-
return (options?.client ?? this._client).post({
|
|
1258
|
-
url: "/tui/control/response",
|
|
1259
|
-
...options,
|
|
1260
|
-
headers: {
|
|
1261
|
-
"Content-Type": "application/json",
|
|
1262
|
-
...options?.headers
|
|
1263
|
-
}
|
|
1264
|
-
});
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
|
-
class Tui extends _HeyApiClient {
|
|
1269
|
-
appendPrompt(options) {
|
|
1270
|
-
return (options?.client ?? this._client).post({
|
|
1271
|
-
url: "/tui/append-prompt",
|
|
1272
|
-
...options,
|
|
1273
|
-
headers: {
|
|
1274
|
-
"Content-Type": "application/json",
|
|
1275
|
-
...options?.headers
|
|
1276
|
-
}
|
|
1277
|
-
});
|
|
1278
|
-
}
|
|
1279
|
-
openHelp(options) {
|
|
1280
|
-
return (options?.client ?? this._client).post({
|
|
1281
|
-
url: "/tui/open-help",
|
|
1282
|
-
...options
|
|
1283
|
-
});
|
|
1284
|
-
}
|
|
1285
|
-
openSessions(options) {
|
|
1286
|
-
return (options?.client ?? this._client).post({
|
|
1287
|
-
url: "/tui/open-sessions",
|
|
1288
|
-
...options
|
|
1289
|
-
});
|
|
1290
|
-
}
|
|
1291
|
-
openThemes(options) {
|
|
1292
|
-
return (options?.client ?? this._client).post({
|
|
1293
|
-
url: "/tui/open-themes",
|
|
1294
|
-
...options
|
|
1295
|
-
});
|
|
1296
|
-
}
|
|
1297
|
-
openModels(options) {
|
|
1298
|
-
return (options?.client ?? this._client).post({
|
|
1299
|
-
url: "/tui/open-models",
|
|
1300
|
-
...options
|
|
1301
|
-
});
|
|
1302
|
-
}
|
|
1303
|
-
submitPrompt(options) {
|
|
1304
|
-
return (options?.client ?? this._client).post({
|
|
1305
|
-
url: "/tui/submit-prompt",
|
|
1306
|
-
...options
|
|
1307
|
-
});
|
|
1308
|
-
}
|
|
1309
|
-
clearPrompt(options) {
|
|
1310
|
-
return (options?.client ?? this._client).post({
|
|
1311
|
-
url: "/tui/clear-prompt",
|
|
1312
|
-
...options
|
|
1313
|
-
});
|
|
1314
|
-
}
|
|
1315
|
-
executeCommand(options) {
|
|
1316
|
-
return (options?.client ?? this._client).post({
|
|
1317
|
-
url: "/tui/execute-command",
|
|
1318
|
-
...options,
|
|
1319
|
-
headers: {
|
|
1320
|
-
"Content-Type": "application/json",
|
|
1321
|
-
...options?.headers
|
|
1322
|
-
}
|
|
1323
|
-
});
|
|
1324
|
-
}
|
|
1325
|
-
showToast(options) {
|
|
1326
|
-
return (options?.client ?? this._client).post({
|
|
1327
|
-
url: "/tui/show-toast",
|
|
1328
|
-
...options,
|
|
1329
|
-
headers: {
|
|
1330
|
-
"Content-Type": "application/json",
|
|
1331
|
-
...options?.headers
|
|
1332
|
-
}
|
|
1333
|
-
});
|
|
1334
|
-
}
|
|
1335
|
-
publish(options) {
|
|
1336
|
-
return (options?.client ?? this._client).post({
|
|
1337
|
-
url: "/tui/publish",
|
|
1338
|
-
...options,
|
|
1339
|
-
headers: {
|
|
1340
|
-
"Content-Type": "application/json",
|
|
1341
|
-
...options?.headers
|
|
1342
|
-
}
|
|
1343
|
-
});
|
|
1344
|
-
}
|
|
1345
|
-
control = new Control({ client: this._client });
|
|
1346
|
-
}
|
|
1347
|
-
|
|
1348
|
-
class Event extends _HeyApiClient {
|
|
1349
|
-
subscribe(options) {
|
|
1350
|
-
return (options?.client ?? this._client).get.sse({
|
|
1351
|
-
url: "/event",
|
|
1352
|
-
...options
|
|
1353
|
-
});
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
class OpencodeClient extends _HeyApiClient {
|
|
1358
|
-
postSessionIdPermissionsPermissionId(options) {
|
|
1359
|
-
return (options.client ?? this._client).post({
|
|
1360
|
-
url: "/session/{id}/permissions/{permissionID}",
|
|
1361
|
-
...options,
|
|
1362
|
-
headers: {
|
|
1363
|
-
"Content-Type": "application/json",
|
|
1364
|
-
...options.headers
|
|
1365
|
-
}
|
|
1366
|
-
});
|
|
1367
|
-
}
|
|
1368
|
-
global = new Global({ client: this._client });
|
|
1369
|
-
project = new Project({ client: this._client });
|
|
1370
|
-
pty = new Pty({ client: this._client });
|
|
1371
|
-
config = new Config({ client: this._client });
|
|
1372
|
-
tool = new Tool({ client: this._client });
|
|
1373
|
-
instance = new Instance({ client: this._client });
|
|
1374
|
-
path = new Path({ client: this._client });
|
|
1375
|
-
vcs = new Vcs({ client: this._client });
|
|
1376
|
-
session = new Session({ client: this._client });
|
|
1377
|
-
command = new Command({ client: this._client });
|
|
1378
|
-
provider = new Provider({ client: this._client });
|
|
1379
|
-
find = new Find({ client: this._client });
|
|
1380
|
-
file = new File({ client: this._client });
|
|
1381
|
-
app = new App({ client: this._client });
|
|
1382
|
-
mcp = new Mcp({ client: this._client });
|
|
1383
|
-
lsp = new Lsp({ client: this._client });
|
|
1384
|
-
formatter = new Formatter({ client: this._client });
|
|
1385
|
-
tui = new Tui({ client: this._client });
|
|
1386
|
-
auth = new Auth({ client: this._client });
|
|
1387
|
-
event = new Event({ client: this._client });
|
|
1388
|
-
}
|
|
1389
|
-
|
|
1390
|
-
// node_modules/@opencode-ai/sdk/dist/error-interceptor.js
|
|
1391
|
-
function wrapClientError(error, response, request, opts) {
|
|
1392
|
-
if (!opts?.throwOnError)
|
|
1393
|
-
return error;
|
|
1394
|
-
if (error instanceof Error)
|
|
1395
|
-
return error;
|
|
1396
|
-
if (typeof error === "object" && error !== null && Object.keys(error).length > 0) {
|
|
1397
|
-
const obj = error;
|
|
1398
|
-
const message = typeof obj.data?.message === "string" && obj.data.message || typeof obj.message === "string" && obj.message || typeof obj.name === "string" && obj.name || describe(request, response);
|
|
1399
|
-
return new Error(message, { cause: { body: error, status: response?.status } });
|
|
1400
|
-
}
|
|
1401
|
-
if (typeof error === "string" && error.length > 0) {
|
|
1402
|
-
return new Error(error, { cause: { body: error, status: response?.status } });
|
|
1403
|
-
}
|
|
1404
|
-
const reason = response ? "(empty response body)" : "network error (no response)";
|
|
1405
|
-
return new Error(`opencode server ${describe(request, response)}: ${reason}`, {
|
|
1406
|
-
cause: { body: error, status: response?.status }
|
|
1407
|
-
});
|
|
1408
|
-
}
|
|
1409
|
-
function describe(request, response) {
|
|
1410
|
-
const method = request?.method ?? "?";
|
|
1411
|
-
const url = request?.url ?? "?";
|
|
1412
|
-
const status = response?.status;
|
|
1413
|
-
const statusText = response?.statusText;
|
|
1414
|
-
return `${method} ${url}${status ? " → " + status : ""}${statusText ? " " + statusText : ""}`;
|
|
1415
|
-
}
|
|
1416
|
-
|
|
1417
|
-
// node_modules/@opencode-ai/sdk/dist/client.js
|
|
1418
|
-
function pick(value, fallback) {
|
|
1419
|
-
if (!value)
|
|
1420
|
-
return;
|
|
1421
|
-
if (!fallback)
|
|
1422
|
-
return value;
|
|
1423
|
-
if (value === fallback)
|
|
1424
|
-
return fallback;
|
|
1425
|
-
if (value === encodeURIComponent(fallback))
|
|
1426
|
-
return fallback;
|
|
1427
|
-
return value;
|
|
1428
|
-
}
|
|
1429
|
-
function rewrite(request, directory) {
|
|
1430
|
-
if (request.method !== "GET" && request.method !== "HEAD")
|
|
1431
|
-
return request;
|
|
1432
|
-
const value = pick(request.headers.get("x-opencode-directory"), directory);
|
|
1433
|
-
if (!value)
|
|
1434
|
-
return request;
|
|
1435
|
-
const url = new URL(request.url);
|
|
1436
|
-
if (!url.searchParams.has("directory")) {
|
|
1437
|
-
url.searchParams.set("directory", value);
|
|
1438
|
-
}
|
|
1439
|
-
const next = new Request(url, request);
|
|
1440
|
-
next.headers.delete("x-opencode-directory");
|
|
1441
|
-
return next;
|
|
1442
|
-
}
|
|
1443
|
-
function createOpencodeClient(config) {
|
|
1444
|
-
if (!config?.fetch) {
|
|
1445
|
-
const customFetch = (req) => {
|
|
1446
|
-
req.timeout = false;
|
|
1447
|
-
return fetch(req);
|
|
1448
|
-
};
|
|
1449
|
-
config = {
|
|
1450
|
-
...config,
|
|
1451
|
-
fetch: customFetch
|
|
1452
|
-
};
|
|
1453
|
-
}
|
|
1454
|
-
if (config?.directory) {
|
|
1455
|
-
config.headers = {
|
|
1456
|
-
...config.headers,
|
|
1457
|
-
"x-opencode-directory": encodeURIComponent(config.directory)
|
|
1458
|
-
};
|
|
1459
|
-
}
|
|
1460
|
-
const client2 = createClient(config);
|
|
1461
|
-
client2.interceptors.request.use((request) => rewrite(request, config?.directory));
|
|
1462
|
-
client2.interceptors.error.use(wrapClientError);
|
|
1463
|
-
return new OpencodeClient({ client: client2 });
|
|
1464
|
-
}
|
|
1465
|
-
// node_modules/@opencode-ai/sdk/dist/server.js
|
|
1466
|
-
var import_cross_spawn = __toESM(require_cross_spawn(), 1);
|
|
1467
|
-
|
|
1468
|
-
// node_modules/@opencode-ai/sdk/dist/process.js
|
|
1469
|
-
import { spawnSync } from "node:child_process";
|
|
1470
|
-
function stop(proc) {
|
|
1471
|
-
if (proc.exitCode !== null || proc.signalCode !== null)
|
|
1472
|
-
return;
|
|
1473
|
-
if (process.platform === "win32" && proc.pid) {
|
|
1474
|
-
const out = spawnSync("taskkill", ["/pid", String(proc.pid), "/T", "/F"], { windowsHide: true });
|
|
1475
|
-
if (!out.error && out.status === 0)
|
|
1476
|
-
return;
|
|
1477
|
-
}
|
|
1478
|
-
proc.kill();
|
|
1479
|
-
}
|
|
1480
|
-
function bindAbort(proc, signal, onAbort) {
|
|
1481
|
-
if (!signal)
|
|
1482
|
-
return () => {};
|
|
1483
|
-
const abort = () => {
|
|
1484
|
-
clear();
|
|
1485
|
-
stop(proc);
|
|
1486
|
-
onAbort?.();
|
|
1487
|
-
};
|
|
1488
|
-
const clear = () => {
|
|
1489
|
-
signal.removeEventListener("abort", abort);
|
|
1490
|
-
proc.off("exit", clear);
|
|
1491
|
-
proc.off("error", clear);
|
|
1492
|
-
};
|
|
1493
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
1494
|
-
proc.on("exit", clear);
|
|
1495
|
-
proc.on("error", clear);
|
|
1496
|
-
if (signal.aborted)
|
|
1497
|
-
abort();
|
|
1498
|
-
return clear;
|
|
1499
|
-
}
|
|
1500
|
-
|
|
1501
|
-
// node_modules/@opencode-ai/sdk/dist/server.js
|
|
1502
|
-
async function createOpencodeServer(options) {
|
|
1503
|
-
options = Object.assign({
|
|
1504
|
-
hostname: "127.0.0.1",
|
|
1505
|
-
port: 4096,
|
|
1506
|
-
timeout: 5000
|
|
1507
|
-
}, options ?? {});
|
|
1508
|
-
const args = [`serve`, `--hostname=${options.hostname}`, `--port=${options.port}`];
|
|
1509
|
-
if (options.config?.logLevel)
|
|
1510
|
-
args.push(`--log-level=${options.config.logLevel}`);
|
|
1511
|
-
const proc = import_cross_spawn.default(`opencode`, args, {
|
|
1512
|
-
env: {
|
|
1513
|
-
...process.env,
|
|
1514
|
-
OPENCODE_CONFIG_CONTENT: JSON.stringify(options.config ?? {})
|
|
1515
|
-
}
|
|
1516
|
-
});
|
|
1517
|
-
let clear = () => {};
|
|
1518
|
-
const url = await new Promise((resolve, reject) => {
|
|
1519
|
-
const id = setTimeout(() => {
|
|
1520
|
-
clear();
|
|
1521
|
-
stop(proc);
|
|
1522
|
-
reject(new Error(`Timeout waiting for server to start after ${options.timeout}ms`));
|
|
1523
|
-
}, options.timeout);
|
|
1524
|
-
let output = "";
|
|
1525
|
-
let resolved = false;
|
|
1526
|
-
proc.stdout?.on("data", (chunk) => {
|
|
1527
|
-
if (resolved)
|
|
1528
|
-
return;
|
|
1529
|
-
output += chunk.toString();
|
|
1530
|
-
const lines = output.split(`
|
|
1531
|
-
`);
|
|
1532
|
-
for (const line of lines) {
|
|
1533
|
-
if (line.startsWith("opencode server listening")) {
|
|
1534
|
-
const match = line.match(/on\s+(https?:\/\/[^\s]+)/);
|
|
1535
|
-
if (!match) {
|
|
1536
|
-
clear();
|
|
1537
|
-
stop(proc);
|
|
1538
|
-
clearTimeout(id);
|
|
1539
|
-
reject(new Error(`Failed to parse server url from output: ${line}`));
|
|
1540
|
-
return;
|
|
1541
|
-
}
|
|
1542
|
-
clearTimeout(id);
|
|
1543
|
-
resolved = true;
|
|
1544
|
-
resolve(match[1]);
|
|
1545
|
-
return;
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
1548
|
-
});
|
|
1549
|
-
proc.stderr?.on("data", (chunk) => {
|
|
1550
|
-
output += chunk.toString();
|
|
1551
|
-
});
|
|
1552
|
-
proc.on("exit", (code) => {
|
|
1553
|
-
clearTimeout(id);
|
|
1554
|
-
let msg = `Server exited with code ${code}`;
|
|
1555
|
-
if (output.trim()) {
|
|
1556
|
-
msg += `
|
|
1557
|
-
Server output: ${output}`;
|
|
1558
|
-
}
|
|
1559
|
-
reject(new Error(msg));
|
|
1560
|
-
});
|
|
1561
|
-
proc.on("error", (error) => {
|
|
1562
|
-
clearTimeout(id);
|
|
1563
|
-
reject(error);
|
|
1564
|
-
});
|
|
1565
|
-
clear = bindAbort(proc, options.signal, () => {
|
|
1566
|
-
clearTimeout(id);
|
|
1567
|
-
reject(options.signal?.reason);
|
|
1568
|
-
});
|
|
1569
|
-
});
|
|
1570
|
-
return {
|
|
1571
|
-
url,
|
|
1572
|
-
close() {
|
|
1573
|
-
clear();
|
|
1574
|
-
stop(proc);
|
|
1575
|
-
}
|
|
1576
|
-
};
|
|
1577
|
-
}
|
|
1578
|
-
// node_modules/@opencode-ai/sdk/dist/index.js
|
|
1579
|
-
async function createOpencode(options) {
|
|
1580
|
-
const server2 = await createOpencodeServer({
|
|
1581
|
-
...options
|
|
1582
|
-
});
|
|
1583
|
-
const client3 = createOpencodeClient({
|
|
1584
|
-
baseUrl: server2.url
|
|
1585
|
-
});
|
|
1586
|
-
return {
|
|
1587
|
-
client: client3,
|
|
1588
|
-
server: server2
|
|
1589
|
-
};
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
|
-
// src/providers/opencode-adapter.ts
|
|
1593
|
-
init_credentials();
|
|
1594
|
-
init_env_flag();
|
|
1595
|
-
init_openrouter_base_url();
|
|
1596
|
-
init_secret_scrubber();
|
|
1597
|
-
function opencodeModelToCredKey(modelStr) {
|
|
1598
|
-
if (!modelStr)
|
|
1599
|
-
return null;
|
|
1600
|
-
if (modelStr.includes("/")) {
|
|
1601
|
-
const provider = modelStr.slice(0, modelStr.indexOf("/")).toLowerCase();
|
|
1602
|
-
if (provider === "anthropic")
|
|
1603
|
-
return "ANTHROPIC_API_KEY";
|
|
1604
|
-
if (provider === "openrouter")
|
|
1605
|
-
return "OPENROUTER_API_KEY";
|
|
1606
|
-
if (provider === "openai")
|
|
1607
|
-
return "OPENAI_API_KEY";
|
|
1608
|
-
}
|
|
1609
|
-
return null;
|
|
1610
|
-
}
|
|
1611
|
-
function checkOpencodeCredentials(env, opts = {}) {
|
|
1612
|
-
const homeDir = opts.homeDir ?? env.HOME ?? "/root";
|
|
1613
|
-
const probe = opts.fs?.existsSync ?? existsSync;
|
|
1614
|
-
const authFile = `${homeDir}/.local/share/opencode/auth.json`;
|
|
1615
|
-
if (probe(authFile)) {
|
|
1616
|
-
return { ready: true, missing: [], satisfiedBy: "file" };
|
|
1617
|
-
}
|
|
1618
|
-
const requiredKey = opencodeModelToCredKey(env.MODEL_OVERRIDE);
|
|
1619
|
-
if (requiredKey) {
|
|
1620
|
-
if (env[requiredKey]) {
|
|
1621
|
-
return { ready: true, missing: [], satisfiedBy: "env" };
|
|
1622
|
-
}
|
|
1623
|
-
return {
|
|
1624
|
-
ready: false,
|
|
1625
|
-
missing: [requiredKey, authFile],
|
|
1626
|
-
hint: `MODEL_OVERRIDE=${env.MODEL_OVERRIDE} requires ${requiredKey}; or run \`opencode auth login\` to create ${authFile}.`
|
|
1627
|
-
};
|
|
1628
|
-
}
|
|
1629
|
-
if (env.OPENROUTER_API_KEY || env.ANTHROPIC_API_KEY || env.OPENAI_API_KEY) {
|
|
1630
|
-
return { ready: true, missing: [], satisfiedBy: "env" };
|
|
1631
|
-
}
|
|
1632
|
-
return {
|
|
1633
|
-
ready: false,
|
|
1634
|
-
missing: ["OPENROUTER_API_KEY", "ANTHROPIC_API_KEY", "OPENAI_API_KEY", authFile],
|
|
1635
|
-
hint: "Set one of OPENROUTER_API_KEY / ANTHROPIC_API_KEY / OPENAI_API_KEY (any one suffices), or run `opencode auth login` to create ~/.local/share/opencode/auth.json."
|
|
1636
|
-
};
|
|
1637
|
-
}
|
|
1638
|
-
function isAssistantMessage(msg) {
|
|
1639
|
-
return typeof msg === "object" && msg !== null && msg.role === "assistant" && typeof msg.cost === "number";
|
|
1640
|
-
}
|
|
1641
|
-
var DOCKER_PLUGIN_PATH = "/home/worker/.config/opencode/plugins/agent-swarm.ts";
|
|
1642
|
-
function defaultOpencodeSkillsDir() {
|
|
1643
|
-
if (process.env.OPENCODE_SKILLS_DIR) {
|
|
1644
|
-
return process.env.OPENCODE_SKILLS_DIR;
|
|
1645
|
-
}
|
|
1646
|
-
return join(process.env.HOME ?? "/home/worker", ".opencode", "skills");
|
|
1647
|
-
}
|
|
1648
|
-
var MODEL_CACHE_REFRESH_TIMEOUT_MS = 15000;
|
|
1649
|
-
var DEFAULT_SERVER_START_TIMEOUT_MS = 30000;
|
|
1650
|
-
var OPENCODE_SSE_MAX_RETRY_ATTEMPTS = 5;
|
|
1651
|
-
function serverStartTimeoutMs() {
|
|
1652
|
-
return Number(process.env.OPENCODE_SERVER_TIMEOUT_MS) || DEFAULT_SERVER_START_TIMEOUT_MS;
|
|
1653
|
-
}
|
|
1654
|
-
async function withTimeout(promise, ms, message) {
|
|
1655
|
-
let timer;
|
|
1656
|
-
const timeout = new Promise((_, reject) => {
|
|
1657
|
-
timer = setTimeout(() => {
|
|
1658
|
-
promise.catch(() => {});
|
|
1659
|
-
reject(new Error(message));
|
|
1660
|
-
}, ms);
|
|
1661
|
-
});
|
|
1662
|
-
try {
|
|
1663
|
-
return await Promise.race([promise, timeout]);
|
|
1664
|
-
} finally {
|
|
1665
|
-
clearTimeout(timer);
|
|
1666
|
-
}
|
|
1667
|
-
}
|
|
1668
|
-
function isOpenRouterModel(model) {
|
|
1669
|
-
return Boolean(model?.toLowerCase().startsWith("openrouter/"));
|
|
1670
|
-
}
|
|
1671
|
-
function isModelNotFoundError(message) {
|
|
1672
|
-
return /model not found:/i.test(message);
|
|
1673
|
-
}
|
|
1674
|
-
async function readSpawnOutput(stream) {
|
|
1675
|
-
if (!stream)
|
|
1676
|
-
return "";
|
|
1677
|
-
return await new Response(stream).text();
|
|
1678
|
-
}
|
|
1679
|
-
function formatUnknownError(err) {
|
|
1680
|
-
return err instanceof Error ? err.message : String(err);
|
|
1681
|
-
}
|
|
1682
|
-
function applyOpenRouterBaseUrlOverride(opencodeConfig, env = process.env) {
|
|
1683
|
-
const openRouterBaseUrl = getOpenRouterBaseUrl(env);
|
|
1684
|
-
const headers = getOpenRouterAttributionHeaders(openRouterBaseUrl, env);
|
|
1685
|
-
const overrideBaseUrl = openRouterBaseUrl !== DEFAULT_OPENROUTER_BASE_URL;
|
|
1686
|
-
if (!overrideBaseUrl && Object.keys(headers).length === 0)
|
|
1687
|
-
return;
|
|
1688
|
-
opencodeConfig.provider = {
|
|
1689
|
-
...opencodeConfig.provider,
|
|
1690
|
-
openrouter: {
|
|
1691
|
-
...opencodeConfig.provider?.openrouter,
|
|
1692
|
-
options: {
|
|
1693
|
-
...opencodeConfig.provider?.openrouter?.options,
|
|
1694
|
-
...overrideBaseUrl ? { baseURL: openRouterBaseUrl } : {},
|
|
1695
|
-
...Object.keys(headers).length > 0 ? {
|
|
1696
|
-
headers: {
|
|
1697
|
-
...opencodeConfig.provider?.openrouter?.options?.headers,
|
|
1698
|
-
...headers,
|
|
1699
|
-
"X-Title": "Agent Swarm"
|
|
1700
|
-
}
|
|
1701
|
-
} : {}
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
};
|
|
1705
|
-
}
|
|
1706
|
-
async function refreshOpenRouterModelCache(opencodeConfig, configFilePath, dataHomePath) {
|
|
1707
|
-
const binary = process.env.OPENCODE_BINARY || "opencode";
|
|
1708
|
-
const proc = Bun.spawn([binary, "models", "--refresh", "openrouter"], {
|
|
1709
|
-
stdout: "pipe",
|
|
1710
|
-
stderr: "pipe",
|
|
1711
|
-
env: {
|
|
1712
|
-
...process.env,
|
|
1713
|
-
OPENCODE_CONFIG: configFilePath,
|
|
1714
|
-
OPENCODE_CONFIG_CONTENT: JSON.stringify(opencodeConfig),
|
|
1715
|
-
OPENCODE_DATA_HOME: dataHomePath
|
|
1716
|
-
}
|
|
1717
|
-
});
|
|
1718
|
-
let timedOut = false;
|
|
1719
|
-
const timeout = setTimeout(() => {
|
|
1720
|
-
timedOut = true;
|
|
1721
|
-
proc.kill();
|
|
1722
|
-
}, MODEL_CACHE_REFRESH_TIMEOUT_MS);
|
|
1723
|
-
const [stdout, stderr, exitCode] = await Promise.all([
|
|
1724
|
-
readSpawnOutput(proc.stdout),
|
|
1725
|
-
readSpawnOutput(proc.stderr),
|
|
1726
|
-
proc.exited
|
|
1727
|
-
]).finally(() => clearTimeout(timeout));
|
|
1728
|
-
if (timedOut) {
|
|
1729
|
-
throw new Error(`opencode models --refresh openrouter timed out after ${MODEL_CACHE_REFRESH_TIMEOUT_MS}ms`);
|
|
1730
|
-
}
|
|
1731
|
-
if (exitCode !== 0) {
|
|
1732
|
-
const detail = scrubSecrets([stderr.trim(), stdout.trim()].filter(Boolean).join(`
|
|
1733
|
-
`));
|
|
1734
|
-
throw new Error(`opencode models --refresh openrouter exited with code ${exitCode}${detail ? `: ${detail}` : ""}`);
|
|
1735
|
-
}
|
|
1736
|
-
}
|
|
1737
|
-
var refreshOpenRouterModelCacheImpl = refreshOpenRouterModelCache;
|
|
1738
|
-
function _setOpenRouterModelCacheRefreshForTests(fn) {
|
|
1739
|
-
refreshOpenRouterModelCacheImpl = fn ?? refreshOpenRouterModelCache;
|
|
1740
|
-
}
|
|
1741
|
-
function resolvePluginPath() {
|
|
1742
|
-
const override = process.env.OPENCODE_SWARM_PLUGIN_PATH;
|
|
1743
|
-
if (override)
|
|
1744
|
-
return override;
|
|
1745
|
-
if (existsSync(DOCKER_PLUGIN_PATH))
|
|
1746
|
-
return DOCKER_PLUGIN_PATH;
|
|
1747
|
-
return join(import.meta.dir, "../../plugin/opencode-plugins/agent-swarm.ts");
|
|
1748
|
-
}
|
|
1749
|
-
var CONTEXT_MODE_GLOBAL_ROOTS = ["/usr/lib/node_modules", "/usr/local/lib/node_modules"];
|
|
1750
|
-
var CONTEXT_MODE_PLUGIN_SUBPATH = "context-mode/build/adapters/opencode/plugin.js";
|
|
1751
|
-
function resolveContextModePluginPath() {
|
|
1752
|
-
const override = process.env.CONTEXT_MODE_OPENCODE_PLUGIN_PATH;
|
|
1753
|
-
if (override)
|
|
1754
|
-
return existsSync(override) ? override : null;
|
|
1755
|
-
for (const root of CONTEXT_MODE_GLOBAL_ROOTS) {
|
|
1756
|
-
const candidate = join(root, CONTEXT_MODE_PLUGIN_SUBPATH);
|
|
1757
|
-
if (existsSync(candidate))
|
|
1758
|
-
return candidate;
|
|
1759
|
-
}
|
|
1760
|
-
return null;
|
|
1761
|
-
}
|
|
1762
|
-
|
|
1763
|
-
class OpencodeSession {
|
|
1764
|
-
_sessionId;
|
|
1765
|
-
listeners = [];
|
|
1766
|
-
pendingEvents = [];
|
|
1767
|
-
completionResolve;
|
|
1768
|
-
completionReject;
|
|
1769
|
-
completionPromise;
|
|
1770
|
-
client;
|
|
1771
|
-
server;
|
|
1772
|
-
aborted = false;
|
|
1773
|
-
completed = false;
|
|
1774
|
-
finalizedMessages = new Map;
|
|
1775
|
-
missingMessageIdCounter = 0;
|
|
1776
|
-
textParts = new Map;
|
|
1777
|
-
assistantMessageIds = new Set;
|
|
1778
|
-
emittedText = new Map;
|
|
1779
|
-
startedAt = Date.now();
|
|
1780
|
-
model;
|
|
1781
|
-
agentId;
|
|
1782
|
-
taskId;
|
|
1783
|
-
agentFilePath;
|
|
1784
|
-
configFilePath;
|
|
1785
|
-
dataHomePath;
|
|
1786
|
-
retryAfterModelRefresh;
|
|
1787
|
-
modelRefreshRecoveryInFlight = false;
|
|
1788
|
-
appliedReasoningEffort;
|
|
1789
|
-
toolStartsEmitted = new Set;
|
|
1790
|
-
constructor(sessionId, client3, server2, model, agentId, taskId, agentFilePath, configFilePath, dataHomePath, retryAfterModelRefresh, appliedReasoningEffort = null) {
|
|
1791
|
-
this._sessionId = sessionId;
|
|
1792
|
-
this.client = client3;
|
|
1793
|
-
this.server = server2;
|
|
1794
|
-
this.model = model;
|
|
1795
|
-
this.agentId = agentId;
|
|
1796
|
-
this.taskId = taskId;
|
|
1797
|
-
this.agentFilePath = agentFilePath;
|
|
1798
|
-
this.configFilePath = configFilePath;
|
|
1799
|
-
this.dataHomePath = dataHomePath;
|
|
1800
|
-
this.retryAfterModelRefresh = retryAfterModelRefresh;
|
|
1801
|
-
this.appliedReasoningEffort = appliedReasoningEffort;
|
|
1802
|
-
this.completionPromise = new Promise((resolve, reject) => {
|
|
1803
|
-
this.completionResolve = resolve;
|
|
1804
|
-
this.completionReject = reject;
|
|
1805
|
-
});
|
|
1806
|
-
}
|
|
1807
|
-
get sessionId() {
|
|
1808
|
-
return this._sessionId;
|
|
1809
|
-
}
|
|
1810
|
-
get isFinished() {
|
|
1811
|
-
return this.completed;
|
|
1812
|
-
}
|
|
1813
|
-
emitSessionInit(provider, harnessVariantMeta) {
|
|
1814
|
-
this.emit({
|
|
1815
|
-
type: "session_init",
|
|
1816
|
-
sessionId: this._sessionId,
|
|
1817
|
-
provider,
|
|
1818
|
-
harnessVariant: "stock",
|
|
1819
|
-
...harnessVariantMeta ? { harnessVariantMeta } : {}
|
|
1820
|
-
});
|
|
1821
|
-
}
|
|
1822
|
-
emitProviderEvent(event) {
|
|
1823
|
-
this.emit(event);
|
|
1824
|
-
}
|
|
1825
|
-
onEvent(listener) {
|
|
1826
|
-
const wasEmpty = this.listeners.length === 0;
|
|
1827
|
-
this.listeners.push(listener);
|
|
1828
|
-
if (wasEmpty && this.pendingEvents.length > 0) {
|
|
1829
|
-
const buffered = this.pendingEvents;
|
|
1830
|
-
this.pendingEvents = [];
|
|
1831
|
-
for (const ev of buffered)
|
|
1832
|
-
listener(ev);
|
|
1833
|
-
}
|
|
1834
|
-
}
|
|
1835
|
-
emit(event) {
|
|
1836
|
-
if (this.listeners.length === 0) {
|
|
1837
|
-
this.pendingEvents.push(event);
|
|
1838
|
-
} else {
|
|
1839
|
-
for (const l of this.listeners)
|
|
1840
|
-
l(event);
|
|
1841
|
-
}
|
|
1842
|
-
if (event.type !== "raw_log") {
|
|
1843
|
-
const raw = scrubSecrets(JSON.stringify(event));
|
|
1844
|
-
this.emitDirect({ type: "raw_log", content: raw });
|
|
1845
|
-
}
|
|
1846
|
-
}
|
|
1847
|
-
emitDirect(event) {
|
|
1848
|
-
if (this.listeners.length === 0) {
|
|
1849
|
-
this.pendingEvents.push(event);
|
|
1850
|
-
return;
|
|
1851
|
-
}
|
|
1852
|
-
for (const l of this.listeners)
|
|
1853
|
-
l(event);
|
|
1854
|
-
}
|
|
1855
|
-
emitModelCacheRefreshProgress() {
|
|
1856
|
-
this.emit({
|
|
1857
|
-
type: "progress",
|
|
1858
|
-
message: "opencode model cache is stale; refreshing OpenRouter models and retrying once"
|
|
1859
|
-
});
|
|
1860
|
-
}
|
|
1861
|
-
emitModelCacheRefreshFailure(message, err) {
|
|
1862
|
-
this.emitError(`${message}; OpenRouter model cache refresh failed: ${formatUnknownError(err)}`);
|
|
1863
|
-
}
|
|
1864
|
-
recoverFromModelNotFound(message) {
|
|
1865
|
-
if (!this.retryAfterModelRefresh || this.modelRefreshRecoveryInFlight) {
|
|
1866
|
-
this.emitError(message);
|
|
1867
|
-
return;
|
|
1868
|
-
}
|
|
1869
|
-
this.modelRefreshRecoveryInFlight = true;
|
|
1870
|
-
this.emitModelCacheRefreshProgress();
|
|
1871
|
-
this.retryAfterModelRefresh().then((retried) => {
|
|
1872
|
-
if (!retried)
|
|
1873
|
-
this.emitError(message);
|
|
1874
|
-
}).catch((err) => {
|
|
1875
|
-
this.emitModelCacheRefreshFailure(message, err);
|
|
1876
|
-
});
|
|
1877
|
-
}
|
|
1878
|
-
async cleanupFiles() {
|
|
1879
|
-
try {
|
|
1880
|
-
await Bun.$`rm -f ${this.agentFilePath}`.quiet().nothrow();
|
|
1881
|
-
} catch {}
|
|
1882
|
-
try {
|
|
1883
|
-
await Bun.$`rm -f ${this.configFilePath}`.quiet().nothrow();
|
|
1884
|
-
} catch {}
|
|
1885
|
-
try {
|
|
1886
|
-
await Bun.$`rm -rf ${this.dataHomePath}`.quiet().nothrow();
|
|
1887
|
-
} catch {}
|
|
1888
|
-
}
|
|
1889
|
-
handleOpencodeEvent(ev) {
|
|
1890
|
-
if (this.aborted || this.completed)
|
|
1891
|
-
return;
|
|
1892
|
-
const rawContent = scrubSecrets(JSON.stringify(ev));
|
|
1893
|
-
this.emitDirect({ type: "raw_log", content: rawContent });
|
|
1894
|
-
switch (ev.type) {
|
|
1895
|
-
case "message.updated": {
|
|
1896
|
-
const msg = ev.properties.info;
|
|
1897
|
-
if (!isAssistantMessage(msg) || msg.sessionID !== this._sessionId)
|
|
1898
|
-
break;
|
|
1899
|
-
if (typeof msg.id === "string")
|
|
1900
|
-
this.assistantMessageIds.add(msg.id);
|
|
1901
|
-
const messageFinalized = msg.time?.completed != null;
|
|
1902
|
-
if (!messageFinalized)
|
|
1903
|
-
break;
|
|
1904
|
-
const messageKey = typeof msg.id === "string" && msg.id.length > 0 ? msg.id : `missing-id-${this.missingMessageIdCounter++}`;
|
|
1905
|
-
this.finalizedMessages.set(messageKey, {
|
|
1906
|
-
cost: msg.cost,
|
|
1907
|
-
inputTokens: msg.tokens?.input ?? 0,
|
|
1908
|
-
outputTokens: msg.tokens?.output ?? 0,
|
|
1909
|
-
reasoningOutputTokens: msg.tokens?.reasoning ?? 0,
|
|
1910
|
-
cacheReadTokens: msg.tokens?.cache?.read ?? 0,
|
|
1911
|
-
cacheWriteTokens: msg.tokens?.cache?.write ?? 0
|
|
1912
|
-
});
|
|
1913
|
-
this.emitAssistantText(msg.id);
|
|
1914
|
-
if (!this.model && msg.modelID)
|
|
1915
|
-
this.model = msg.modelID;
|
|
1916
|
-
const turnInput = msg.tokens?.input ?? 0;
|
|
1917
|
-
const turnOutput = msg.tokens?.output ?? 0;
|
|
1918
|
-
const turnCacheRead = msg.tokens?.cache?.read ?? 0;
|
|
1919
|
-
const turnCacheWrite = msg.tokens?.cache?.write ?? 0;
|
|
1920
|
-
const contextUsed = turnInput + turnCacheRead + turnCacheWrite + turnOutput;
|
|
1921
|
-
const contextTotal = getContextWindowSize(this.model || msg.modelID || "default");
|
|
1922
|
-
if (contextTotal > 0 && contextUsed > 0) {
|
|
1923
|
-
this.emit({
|
|
1924
|
-
type: "context_usage",
|
|
1925
|
-
contextUsedTokens: contextUsed,
|
|
1926
|
-
contextTotalTokens: contextTotal,
|
|
1927
|
-
contextPercent: clampContextPercent(contextUsed, contextTotal) ?? 0,
|
|
1928
|
-
outputTokens: turnOutput,
|
|
1929
|
-
contextFormula: CONTEXT_FORMULA
|
|
1930
|
-
});
|
|
1931
|
-
}
|
|
1932
|
-
break;
|
|
1933
|
-
}
|
|
1934
|
-
case "message.part.updated": {
|
|
1935
|
-
if (ev.properties.part?.type === "text") {
|
|
1936
|
-
this.recordTextPart(ev.properties.part);
|
|
1937
|
-
break;
|
|
1938
|
-
}
|
|
1939
|
-
const props = ev.properties;
|
|
1940
|
-
if (props.sessionID !== this._sessionId)
|
|
1941
|
-
break;
|
|
1942
|
-
const part = props.part;
|
|
1943
|
-
if (!part || part.type !== "tool")
|
|
1944
|
-
break;
|
|
1945
|
-
const callId = part.callID ?? part.id ?? "";
|
|
1946
|
-
if (!callId)
|
|
1947
|
-
break;
|
|
1948
|
-
const toolName = part.tool ?? "tool";
|
|
1949
|
-
if (!this.toolStartsEmitted.has(callId)) {
|
|
1950
|
-
this.toolStartsEmitted.add(callId);
|
|
1951
|
-
this.emit({
|
|
1952
|
-
type: "tool_start",
|
|
1953
|
-
toolCallId: callId,
|
|
1954
|
-
toolName,
|
|
1955
|
-
args: part.state?.input
|
|
1956
|
-
});
|
|
1957
|
-
}
|
|
1958
|
-
if (part.state?.status === "completed") {
|
|
1959
|
-
this.emit({
|
|
1960
|
-
type: "tool_end",
|
|
1961
|
-
toolCallId: callId,
|
|
1962
|
-
toolName,
|
|
1963
|
-
result: part.state.output
|
|
1964
|
-
});
|
|
1965
|
-
}
|
|
1966
|
-
break;
|
|
1967
|
-
}
|
|
1968
|
-
case "session.idle": {
|
|
1969
|
-
if (ev.properties.sessionID !== this._sessionId)
|
|
1970
|
-
break;
|
|
1971
|
-
const cost = this.buildCostData(false);
|
|
1972
|
-
const resultEvent = {
|
|
1973
|
-
type: "result",
|
|
1974
|
-
cost,
|
|
1975
|
-
isError: false
|
|
1976
|
-
};
|
|
1977
|
-
for (const l of this.listeners)
|
|
1978
|
-
l(resultEvent);
|
|
1979
|
-
const raw = scrubSecrets(JSON.stringify(resultEvent));
|
|
1980
|
-
this.emitDirect({ type: "raw_log", content: raw });
|
|
1981
|
-
this.finish({
|
|
1982
|
-
exitCode: 0,
|
|
1983
|
-
sessionId: this._sessionId,
|
|
1984
|
-
cost,
|
|
1985
|
-
isError: false
|
|
1986
|
-
});
|
|
1987
|
-
break;
|
|
1988
|
-
}
|
|
1989
|
-
case "session.error": {
|
|
1990
|
-
if (ev.properties.sessionID !== undefined && ev.properties.sessionID !== this._sessionId)
|
|
1991
|
-
break;
|
|
1992
|
-
const errMsg = ev.properties.error && "message" in ev.properties.error ? String(ev.properties.error.message ?? "unknown error") : "opencode session error";
|
|
1993
|
-
if (isModelNotFoundError(errMsg)) {
|
|
1994
|
-
this.recoverFromModelNotFound(errMsg);
|
|
1995
|
-
break;
|
|
1996
|
-
}
|
|
1997
|
-
this.emitError(errMsg);
|
|
1998
|
-
break;
|
|
1999
|
-
}
|
|
2000
|
-
case "permission.updated": {
|
|
2001
|
-
if (ev.properties.sessionID !== this._sessionId)
|
|
2002
|
-
break;
|
|
2003
|
-
this.emitError(`Permission request received in headless mode (id=${ev.properties.id}); aborting session`);
|
|
2004
|
-
break;
|
|
2005
|
-
}
|
|
2006
|
-
default:
|
|
2007
|
-
break;
|
|
2008
|
-
}
|
|
2009
|
-
}
|
|
2010
|
-
recordTextPart(part) {
|
|
2011
|
-
if (part.sessionID !== this._sessionId || part.synthetic || part.ignored)
|
|
2012
|
-
return;
|
|
2013
|
-
if (typeof part.messageID !== "string" || typeof part.id !== "string")
|
|
2014
|
-
return;
|
|
2015
|
-
let parts = this.textParts.get(part.messageID);
|
|
2016
|
-
if (!parts) {
|
|
2017
|
-
parts = new Map;
|
|
2018
|
-
this.textParts.set(part.messageID, parts);
|
|
2019
|
-
}
|
|
2020
|
-
parts.set(part.id, part.text ?? "");
|
|
2021
|
-
if (this.finalizedMessages.has(part.messageID))
|
|
2022
|
-
this.emitAssistantText(part.messageID);
|
|
2023
|
-
}
|
|
2024
|
-
emitAssistantText(messageId) {
|
|
2025
|
-
if (!this.assistantMessageIds.has(messageId))
|
|
2026
|
-
return;
|
|
2027
|
-
const parts = this.textParts.get(messageId);
|
|
2028
|
-
if (!parts)
|
|
2029
|
-
return;
|
|
2030
|
-
const text = [...parts.values()].join("").trim();
|
|
2031
|
-
if (!text || this.emittedText.get(messageId) === text)
|
|
2032
|
-
return;
|
|
2033
|
-
this.emittedText.set(messageId, text);
|
|
2034
|
-
this.emit({ type: "message", role: "assistant", content: text, messageId });
|
|
2035
|
-
}
|
|
2036
|
-
emitError(message) {
|
|
2037
|
-
const errorEvent = { type: "error", message };
|
|
2038
|
-
for (const l of this.listeners)
|
|
2039
|
-
l(errorEvent);
|
|
2040
|
-
const raw = scrubSecrets(JSON.stringify(errorEvent));
|
|
2041
|
-
this.emitDirect({ type: "raw_log", content: raw });
|
|
2042
|
-
const cost = this.buildCostData(true);
|
|
2043
|
-
this.finish({
|
|
2044
|
-
exitCode: 1,
|
|
2045
|
-
sessionId: this._sessionId,
|
|
2046
|
-
cost,
|
|
2047
|
-
isError: true,
|
|
2048
|
-
failureReason: message
|
|
2049
|
-
});
|
|
2050
|
-
}
|
|
2051
|
-
buildCostData(isError) {
|
|
2052
|
-
let totalCostUsd = 0;
|
|
2053
|
-
let inputTokens = 0;
|
|
2054
|
-
let outputTokens = 0;
|
|
2055
|
-
let reasoningOutputTokens = 0;
|
|
2056
|
-
let cacheReadTokens = 0;
|
|
2057
|
-
let cacheWriteTokens = 0;
|
|
2058
|
-
for (const message of this.finalizedMessages.values()) {
|
|
2059
|
-
totalCostUsd += message.cost;
|
|
2060
|
-
inputTokens += message.inputTokens;
|
|
2061
|
-
outputTokens += message.outputTokens;
|
|
2062
|
-
reasoningOutputTokens += message.reasoningOutputTokens;
|
|
2063
|
-
cacheReadTokens += message.cacheReadTokens;
|
|
2064
|
-
cacheWriteTokens += message.cacheWriteTokens;
|
|
2065
|
-
}
|
|
2066
|
-
return {
|
|
2067
|
-
sessionId: this._sessionId,
|
|
2068
|
-
taskId: this.taskId,
|
|
2069
|
-
agentId: this.agentId,
|
|
2070
|
-
totalCostUsd,
|
|
2071
|
-
inputTokens,
|
|
2072
|
-
outputTokens,
|
|
2073
|
-
reasoningOutputTokens,
|
|
2074
|
-
cacheReadTokens,
|
|
2075
|
-
cacheWriteTokens,
|
|
2076
|
-
durationMs: Date.now() - this.startedAt,
|
|
2077
|
-
numTurns: this.finalizedMessages.size,
|
|
2078
|
-
model: this.model,
|
|
2079
|
-
isError,
|
|
2080
|
-
provider: "opencode"
|
|
2081
|
-
};
|
|
2082
|
-
}
|
|
2083
|
-
async waitForCompletion() {
|
|
2084
|
-
return this.completionPromise;
|
|
2085
|
-
}
|
|
2086
|
-
async finish(result) {
|
|
2087
|
-
if (this.completed)
|
|
2088
|
-
return;
|
|
2089
|
-
this.completed = true;
|
|
2090
|
-
try {
|
|
2091
|
-
this.server.close();
|
|
2092
|
-
} catch {}
|
|
2093
|
-
await this.cleanupFiles();
|
|
2094
|
-
this.completionResolve({ ...result, appliedReasoningEffort: this.appliedReasoningEffort });
|
|
2095
|
-
}
|
|
2096
|
-
async abort() {
|
|
2097
|
-
if (this.aborted)
|
|
2098
|
-
return;
|
|
2099
|
-
this.aborted = true;
|
|
2100
|
-
await this.finish({
|
|
2101
|
-
exitCode: 1,
|
|
2102
|
-
sessionId: this._sessionId,
|
|
2103
|
-
isError: true,
|
|
2104
|
-
failureReason: "aborted"
|
|
2105
|
-
});
|
|
2106
|
-
}
|
|
2107
|
-
async deliverSteering({ mode, text }) {
|
|
2108
|
-
if (this.completed || this.aborted) {
|
|
2109
|
-
return { delivered: false, reason: "opencode session already completed" };
|
|
2110
|
-
}
|
|
2111
|
-
try {
|
|
2112
|
-
await this.client.session.promptAsync({
|
|
2113
|
-
path: { id: this._sessionId },
|
|
2114
|
-
body: { parts: [{ type: "text", text }] }
|
|
2115
|
-
});
|
|
2116
|
-
return { delivered: true, mode: "queue" };
|
|
2117
|
-
} catch (err) {
|
|
2118
|
-
return { delivered: false, reason: String(err) };
|
|
2119
|
-
}
|
|
2120
|
-
}
|
|
2121
|
-
}
|
|
2122
|
-
|
|
2123
|
-
class OpencodeAdapter {
|
|
2124
|
-
name = "opencode";
|
|
2125
|
-
traits = {
|
|
2126
|
-
hasMcp: true,
|
|
2127
|
-
hasToolSearch: false,
|
|
2128
|
-
nativeSkillDiscovery: false,
|
|
2129
|
-
hasLocalEnvironment: true,
|
|
2130
|
-
steerModes: ["queue"]
|
|
2131
|
-
};
|
|
2132
|
-
validateCredentials(env = {}) {
|
|
2133
|
-
return validateOpencodeCredentials(env);
|
|
2134
|
-
}
|
|
2135
|
-
async createSession(config) {
|
|
2136
|
-
const taskId = config.taskId;
|
|
2137
|
-
const agentName = `swarm-${taskId}`;
|
|
2138
|
-
const agentFilePath = join(config.cwd, ".opencode", "agents", `${agentName}.md`);
|
|
2139
|
-
const configFilePath = `/tmp/opencode-${taskId}.json`;
|
|
2140
|
-
const dataHomePath = `/tmp/opencode-data-${taskId}`;
|
|
2141
|
-
try {
|
|
2142
|
-
mkdirSync(join(config.cwd, ".opencode", "agents"), { recursive: true });
|
|
2143
|
-
await Bun.write(agentFilePath, config.systemPrompt ?? "");
|
|
2144
|
-
} catch {}
|
|
2145
|
-
const installedMcp = await fetchInstalledMcpServers(config.apiUrl, config.apiKey, config.agentId, "opencode") ?? {};
|
|
2146
|
-
const runtimeInstanceId = swarmRuntimeInstanceId();
|
|
2147
|
-
const mcpConfig = {
|
|
2148
|
-
swarm: {
|
|
2149
|
-
type: "remote",
|
|
2150
|
-
url: `${config.apiUrl}/mcp`,
|
|
2151
|
-
headers: {
|
|
2152
|
-
Authorization: `Bearer ${config.apiKey}`,
|
|
2153
|
-
"X-Agent-ID": config.agentId,
|
|
2154
|
-
"X-Source-Task-Id": taskId,
|
|
2155
|
-
...config.contextKey ? { "X-Context-Key": config.contextKey } : {},
|
|
2156
|
-
...runtimeInstanceId ? { "X-Runtime-Instance-ID": runtimeInstanceId } : {}
|
|
2157
|
-
}
|
|
2158
|
-
},
|
|
2159
|
-
...installedMcp
|
|
2160
|
-
};
|
|
2161
|
-
const pluginPath = resolvePluginPath();
|
|
2162
|
-
const plugins = [pluginPath];
|
|
2163
|
-
if (!isEnvFlagEnabled("CONTEXT_MODE_DISABLED", false)) {
|
|
2164
|
-
const contextModePluginPath = resolveContextModePluginPath();
|
|
2165
|
-
if (contextModePluginPath) {
|
|
2166
|
-
plugins.push(contextModePluginPath);
|
|
2167
|
-
} else {
|
|
2168
|
-
console.warn("[opencode] context-mode is enabled but its opencode plugin entry was not found on disk; " + "skipping it for this session. Set CONTEXT_MODE_OPENCODE_PLUGIN_PATH to override, or " + "CONTEXT_MODE_DISABLED=true to silence.");
|
|
2169
|
-
}
|
|
2170
|
-
}
|
|
2171
|
-
const opencodeConfig = {
|
|
2172
|
-
$schema: "https://opencode.ai/config.json",
|
|
2173
|
-
model: config.model,
|
|
2174
|
-
mcp: mcpConfig,
|
|
2175
|
-
permission: {
|
|
2176
|
-
edit: "allow",
|
|
2177
|
-
bash: "allow",
|
|
2178
|
-
webfetch: "allow",
|
|
2179
|
-
doom_loop: "allow",
|
|
2180
|
-
external_directory: "allow"
|
|
2181
|
-
},
|
|
2182
|
-
plugin: plugins
|
|
2183
|
-
};
|
|
2184
|
-
const reasoningApplication = applyReasoningEffort("opencode", config.model, config.reasoningEffort);
|
|
2185
|
-
const appliedReasoningEffort = reasoningApplication.kind === "opencode-options" ? config.reasoningEffort ?? null : null;
|
|
2186
|
-
if (reasoningApplication.kind === "opencode-options") {
|
|
2187
|
-
const { providerId, modelId, options } = reasoningApplication;
|
|
2188
|
-
opencodeConfig.provider = {
|
|
2189
|
-
...opencodeConfig.provider,
|
|
2190
|
-
[providerId]: {
|
|
2191
|
-
...opencodeConfig.provider?.[providerId],
|
|
2192
|
-
models: {
|
|
2193
|
-
...opencodeConfig.provider?.[providerId]?.models,
|
|
2194
|
-
[modelId]: {
|
|
2195
|
-
...opencodeConfig.provider?.[providerId]?.models?.[modelId],
|
|
2196
|
-
options: {
|
|
2197
|
-
...opencodeConfig.provider?.[providerId]?.models?.[modelId]?.options,
|
|
2198
|
-
...options
|
|
2199
|
-
}
|
|
2200
|
-
}
|
|
2201
|
-
}
|
|
2202
|
-
}
|
|
2203
|
-
};
|
|
2204
|
-
}
|
|
2205
|
-
applyOpenRouterBaseUrlOverride(opencodeConfig, config.env ?? process.env);
|
|
2206
|
-
try {
|
|
2207
|
-
await Bun.write(configFilePath, JSON.stringify(opencodeConfig, null, 2));
|
|
2208
|
-
} catch {}
|
|
2209
|
-
process.env.OPENCODE_DATA_HOME = dataHomePath;
|
|
2210
|
-
const swarmEnvSnapshot = {
|
|
2211
|
-
SWARM_API_URL: process.env.SWARM_API_URL,
|
|
2212
|
-
SWARM_API_KEY: process.env.SWARM_API_KEY,
|
|
2213
|
-
SWARM_AGENT_ID: process.env.SWARM_AGENT_ID,
|
|
2214
|
-
SWARM_TASK_ID: process.env.SWARM_TASK_ID,
|
|
2215
|
-
SWARM_IS_LEAD: process.env.SWARM_IS_LEAD,
|
|
2216
|
-
OPENROUTER_BASE_URL: process.env.OPENROUTER_BASE_URL
|
|
2217
|
-
};
|
|
2218
|
-
process.env.SWARM_API_URL = config.apiUrl;
|
|
2219
|
-
process.env.SWARM_API_KEY = config.apiKey;
|
|
2220
|
-
process.env.SWARM_AGENT_ID = config.agentId;
|
|
2221
|
-
process.env.SWARM_TASK_ID = config.taskId;
|
|
2222
|
-
process.env.SWARM_IS_LEAD = config.role === "lead" ? "true" : "false";
|
|
2223
|
-
const spawnOpenRouterBaseUrl = getOpenRouterBaseUrl(config.env ?? process.env);
|
|
2224
|
-
if (spawnOpenRouterBaseUrl !== DEFAULT_OPENROUTER_BASE_URL) {
|
|
2225
|
-
process.env.OPENROUTER_BASE_URL = spawnOpenRouterBaseUrl;
|
|
2226
|
-
}
|
|
2227
|
-
process.env.CONTEXT_MODE_EXTERNAL_MCP_NUDGE_EVERY = CTX_MODE_NUDGE_EVERY;
|
|
2228
|
-
const prevOpencodeConfig = process.env.OPENCODE_CONFIG;
|
|
2229
|
-
process.env.OPENCODE_CONFIG = configFilePath;
|
|
2230
|
-
let client3;
|
|
2231
|
-
let server2;
|
|
2232
|
-
try {
|
|
2233
|
-
({ client: client3, server: server2 } = await createOpencode({
|
|
2234
|
-
hostname: "127.0.0.1",
|
|
2235
|
-
port: 0,
|
|
2236
|
-
timeout: serverStartTimeoutMs(),
|
|
2237
|
-
config: opencodeConfig
|
|
2238
|
-
}));
|
|
2239
|
-
} finally {
|
|
2240
|
-
if (prevOpencodeConfig === undefined) {
|
|
2241
|
-
delete process.env.OPENCODE_CONFIG;
|
|
2242
|
-
} else {
|
|
2243
|
-
process.env.OPENCODE_CONFIG = prevOpencodeConfig;
|
|
2244
|
-
}
|
|
2245
|
-
for (const [key, val] of Object.entries(swarmEnvSnapshot)) {
|
|
2246
|
-
if (val === undefined) {
|
|
2247
|
-
delete process.env[key];
|
|
2248
|
-
} else {
|
|
2249
|
-
process.env[key] = val;
|
|
2250
|
-
}
|
|
2251
|
-
}
|
|
2252
|
-
}
|
|
2253
|
-
const sessionCreateTimeoutMs = serverStartTimeoutMs();
|
|
2254
|
-
let createResult;
|
|
2255
|
-
try {
|
|
2256
|
-
createResult = await withTimeout(client3.session.create({ query: { directory: config.cwd } }), sessionCreateTimeoutMs, `opencode session create timed out after ${sessionCreateTimeoutMs}ms`);
|
|
2257
|
-
} catch (err) {
|
|
2258
|
-
server2.close();
|
|
2259
|
-
throw err;
|
|
2260
|
-
}
|
|
2261
|
-
if (!createResult.data) {
|
|
2262
|
-
server2.close();
|
|
2263
|
-
throw new Error("Failed to create opencode session");
|
|
2264
|
-
}
|
|
2265
|
-
const opencodeSession = createResult.data;
|
|
2266
|
-
const sessionId = opencodeSession.id;
|
|
2267
|
-
let promptRefreshAttempted = false;
|
|
2268
|
-
let promptRefreshPromise;
|
|
2269
|
-
let session;
|
|
2270
|
-
const sendPrompt = async () => {
|
|
2271
|
-
const resolvedPrompt = await resolveSlashSkillPrompt(config.prompt, {
|
|
2272
|
-
providerLabel: "opencode",
|
|
2273
|
-
skillsDir: defaultOpencodeSkillsDir(),
|
|
2274
|
-
emit: (event) => session?.emitProviderEvent(event),
|
|
2275
|
-
onInline: config.onPromptSkill
|
|
2276
|
-
});
|
|
2277
|
-
await client3.session.prompt({
|
|
2278
|
-
path: { id: sessionId },
|
|
2279
|
-
query: { directory: config.cwd },
|
|
2280
|
-
body: {
|
|
2281
|
-
agent: agentName,
|
|
2282
|
-
parts: [{ type: "text", text: resolvedPrompt }]
|
|
2283
|
-
}
|
|
2284
|
-
});
|
|
2285
|
-
};
|
|
2286
|
-
const refreshOpenRouterAndRetryPrompt = async () => {
|
|
2287
|
-
if (promptRefreshPromise)
|
|
2288
|
-
return await promptRefreshPromise;
|
|
2289
|
-
if (promptRefreshAttempted || !isOpenRouterModel(config.model))
|
|
2290
|
-
return false;
|
|
2291
|
-
promptRefreshAttempted = true;
|
|
2292
|
-
promptRefreshPromise = (async () => {
|
|
2293
|
-
await refreshOpenRouterModelCacheImpl(opencodeConfig, configFilePath, dataHomePath);
|
|
2294
|
-
await sendPrompt();
|
|
2295
|
-
return true;
|
|
2296
|
-
})();
|
|
2297
|
-
return await promptRefreshPromise;
|
|
2298
|
-
};
|
|
2299
|
-
session = new OpencodeSession(sessionId, client3, server2, config.model, config.agentId, config.taskId, agentFilePath, configFilePath, dataHomePath, isOpenRouterModel(config.model) ? refreshOpenRouterAndRetryPrompt : undefined, appliedReasoningEffort);
|
|
2300
|
-
const opcVersion = readPkgVersion("@opencode-ai/sdk");
|
|
2301
|
-
session.emitSessionInit("opencode", opcVersion ? { version: opcVersion } : undefined);
|
|
2302
|
-
client3.event.subscribe({
|
|
2303
|
-
query: { directory: config.cwd },
|
|
2304
|
-
sseMaxRetryAttempts: OPENCODE_SSE_MAX_RETRY_ATTEMPTS
|
|
2305
|
-
}).then(async ({ stream }) => {
|
|
2306
|
-
for await (const event of stream) {
|
|
2307
|
-
session.handleOpencodeEvent(event);
|
|
2308
|
-
if (session.isFinished)
|
|
2309
|
-
break;
|
|
2310
|
-
}
|
|
2311
|
-
if (!session.isFinished) {
|
|
2312
|
-
session.handleOpencodeEvent({
|
|
2313
|
-
type: "session.error",
|
|
2314
|
-
properties: {
|
|
2315
|
-
sessionID: sessionId,
|
|
2316
|
-
error: {
|
|
2317
|
-
message: "runner exited without result: opencode event stream ended"
|
|
2318
|
-
}
|
|
2319
|
-
}
|
|
2320
|
-
});
|
|
2321
|
-
}
|
|
2322
|
-
}).catch((err) => {
|
|
2323
|
-
session.handleOpencodeEvent({
|
|
2324
|
-
type: "session.error",
|
|
2325
|
-
properties: { sessionID: sessionId, error: { message: String(err) } }
|
|
2326
|
-
});
|
|
2327
|
-
});
|
|
2328
|
-
sendPrompt().catch((err) => {
|
|
2329
|
-
const message = formatUnknownError(err);
|
|
2330
|
-
if (isModelNotFoundError(message) && isOpenRouterModel(config.model)) {
|
|
2331
|
-
session.emitModelCacheRefreshProgress();
|
|
2332
|
-
refreshOpenRouterAndRetryPrompt().then((retried) => {
|
|
2333
|
-
if (retried)
|
|
2334
|
-
return;
|
|
2335
|
-
session.handleOpencodeEvent({
|
|
2336
|
-
type: "session.error",
|
|
2337
|
-
properties: { sessionID: sessionId, error: { message } }
|
|
2338
|
-
});
|
|
2339
|
-
}).catch((retryErr) => {
|
|
2340
|
-
session.emitModelCacheRefreshFailure(message, retryErr);
|
|
2341
|
-
});
|
|
2342
|
-
return;
|
|
2343
|
-
}
|
|
2344
|
-
session.handleOpencodeEvent({
|
|
2345
|
-
type: "session.error",
|
|
2346
|
-
properties: { sessionID: sessionId, error: { message } }
|
|
2347
|
-
});
|
|
2348
|
-
});
|
|
2349
|
-
return session;
|
|
2350
|
-
}
|
|
2351
|
-
async canResume(_sessionId) {
|
|
2352
|
-
return false;
|
|
2353
|
-
}
|
|
2354
|
-
formatCommand(commandName) {
|
|
2355
|
-
return `/${commandName}`;
|
|
2356
|
-
}
|
|
2357
|
-
}
|
|
2358
|
-
|
|
2359
|
-
export { checkOpencodeCredentials, OPENCODE_SSE_MAX_RETRY_ATTEMPTS, applyOpenRouterBaseUrlOverride, _setOpenRouterModelCacheRefreshForTests, resolveContextModePluginPath, OpencodeSession, OpencodeAdapter };
|