swellai 1.0.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/README.md +711 -0
- package/dist/agents/linear-agent.d.ts +32 -0
- package/dist/agents/linear-agent.d.ts.map +1 -0
- package/dist/agents/linear-agent.js +263 -0
- package/dist/agents/linear-agent.js.map +1 -0
- package/dist/agents/planning-agent.d.ts +36 -0
- package/dist/agents/planning-agent.d.ts.map +1 -0
- package/dist/agents/planning-agent.js +248 -0
- package/dist/agents/planning-agent.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +102 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/install.d.ts +11 -0
- package/dist/cli/install.d.ts.map +1 -0
- package/dist/cli/install.js +257 -0
- package/dist/cli/install.js.map +1 -0
- package/dist/cli/manifest.d.ts +27 -0
- package/dist/cli/manifest.d.ts.map +1 -0
- package/dist/cli/manifest.js +65 -0
- package/dist/cli/manifest.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/claude-agent-sdk.d.ts +73 -0
- package/dist/lib/claude-agent-sdk.d.ts.map +1 -0
- package/dist/lib/claude-agent-sdk.js +114 -0
- package/dist/lib/claude-agent-sdk.js.map +1 -0
- package/dist/lib/conversation-logger.d.ts +66 -0
- package/dist/lib/conversation-logger.d.ts.map +1 -0
- package/dist/lib/conversation-logger.js +159 -0
- package/dist/lib/conversation-logger.js.map +1 -0
- package/dist/lib/opencode.d.ts +68 -0
- package/dist/lib/opencode.d.ts.map +1 -0
- package/dist/lib/opencode.js +151 -0
- package/dist/lib/opencode.js.map +1 -0
- package/dist/lib/turso-schema.d.ts +13 -0
- package/dist/lib/turso-schema.d.ts.map +1 -0
- package/dist/lib/turso-schema.js +69 -0
- package/dist/lib/turso-schema.js.map +1 -0
- package/dist/lib/turso.d.ts +56 -0
- package/dist/lib/turso.d.ts.map +1 -0
- package/dist/lib/turso.js +144 -0
- package/dist/lib/turso.js.map +1 -0
- package/dist/lib/types.d.ts +31 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +20 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utils.d.ts +34 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +72 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/scripts/build-templates.d.ts +17 -0
- package/dist/scripts/build-templates.d.ts.map +1 -0
- package/dist/scripts/build-templates.js +132 -0
- package/dist/scripts/build-templates.js.map +1 -0
- package/dist/scripts/claude-agent-runner.d.ts +28 -0
- package/dist/scripts/claude-agent-runner.d.ts.map +1 -0
- package/dist/scripts/claude-agent-runner.js +278 -0
- package/dist/scripts/claude-agent-runner.js.map +1 -0
- package/dist/src/agents/linear-agent.d.ts +32 -0
- package/dist/src/agents/linear-agent.d.ts.map +1 -0
- package/dist/src/agents/linear-agent.js +285 -0
- package/dist/src/agents/linear-agent.js.map +1 -0
- package/dist/src/agents/planning-agent.d.ts +36 -0
- package/dist/src/agents/planning-agent.d.ts.map +1 -0
- package/dist/src/agents/planning-agent.js +248 -0
- package/dist/src/agents/planning-agent.js.map +1 -0
- package/dist/src/cli/index.d.ts +3 -0
- package/dist/src/cli/index.d.ts.map +1 -0
- package/dist/src/cli/index.js +102 -0
- package/dist/src/cli/index.js.map +1 -0
- package/dist/src/cli/install.d.ts +11 -0
- package/dist/src/cli/install.d.ts.map +1 -0
- package/dist/src/cli/install.js +257 -0
- package/dist/src/cli/install.js.map +1 -0
- package/dist/src/cli/manifest.d.ts +27 -0
- package/dist/src/cli/manifest.d.ts.map +1 -0
- package/dist/src/cli/manifest.js +65 -0
- package/dist/src/cli/manifest.js.map +1 -0
- package/dist/src/index.d.ts +17 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +17 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/claude-agent-sdk.d.ts +73 -0
- package/dist/src/lib/claude-agent-sdk.d.ts.map +1 -0
- package/dist/src/lib/claude-agent-sdk.js +114 -0
- package/dist/src/lib/claude-agent-sdk.js.map +1 -0
- package/dist/src/lib/conversation-logger.d.ts +66 -0
- package/dist/src/lib/conversation-logger.d.ts.map +1 -0
- package/dist/src/lib/conversation-logger.js +159 -0
- package/dist/src/lib/conversation-logger.js.map +1 -0
- package/dist/src/lib/opencode.d.ts +153 -0
- package/dist/src/lib/opencode.d.ts.map +1 -0
- package/dist/src/lib/opencode.js +153 -0
- package/dist/src/lib/opencode.js.map +1 -0
- package/dist/src/lib/turso-schema.d.ts +13 -0
- package/dist/src/lib/turso-schema.d.ts.map +1 -0
- package/dist/src/lib/turso-schema.js +69 -0
- package/dist/src/lib/turso-schema.js.map +1 -0
- package/dist/src/lib/turso.d.ts +56 -0
- package/dist/src/lib/turso.d.ts.map +1 -0
- package/dist/src/lib/turso.js +144 -0
- package/dist/src/lib/turso.js.map +1 -0
- package/dist/src/lib/types.d.ts +31 -0
- package/dist/src/lib/types.d.ts.map +1 -0
- package/dist/src/lib/types.js +20 -0
- package/dist/src/lib/types.js.map +1 -0
- package/dist/src/lib/utils.d.ts +34 -0
- package/dist/src/lib/utils.d.ts.map +1 -0
- package/dist/src/lib/utils.js +72 -0
- package/dist/src/lib/utils.js.map +1 -0
- package/package.json +63 -0
- package/templates/.env.example +51 -0
- package/templates/agents/codebase-analyzer.md +121 -0
- package/templates/agents/codebase-locator.md +105 -0
- package/templates/agents/coding-agent.md +187 -0
- package/templates/agents/debug-agent.md +300 -0
- package/templates/prompts/consolidate-and-create-linear.md +282 -0
- package/templates/prompts/implementation.md +94 -0
- package/templates/prompts/plan-generation.md +171 -0
- package/templates/prompts/review.md +39 -0
- package/templates/prompts/verify.md +80 -0
- package/templates/scripts/claude-agent-runner.js +12887 -0
- package/templates/scripts/detect-runtime.sh +95 -0
- package/templates/scripts/linear-agent.js +1753 -0
- package/templates/scripts/planning-agent.js +1738 -0
- package/templates/workflows/claude-implement.yml +931 -0
- package/templates/workflows/claude-plan.yml +301 -0
|
@@ -0,0 +1,1753 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/agents/linear-agent.ts
|
|
4
|
+
import { readFile } from "fs/promises";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
|
|
7
|
+
// src/lib/types.ts
|
|
8
|
+
var API_KEY_ENV_VARS = {
|
|
9
|
+
anthropic: ["ANTHROPIC_API_KEY", "CLAUDE_CODE_OAUTH_TOKEN"],
|
|
10
|
+
openai: ["OPENAI_API_KEY"],
|
|
11
|
+
google: ["GOOGLE_GENERATIVE_AI_API_KEY"]
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/lib/utils.ts
|
|
15
|
+
function extractTextFromParts(parts) {
|
|
16
|
+
if (!Array.isArray(parts))
|
|
17
|
+
return "";
|
|
18
|
+
return parts.filter((part) => part.type === "text").map((part) => part.text || "").join(`
|
|
19
|
+
`);
|
|
20
|
+
}
|
|
21
|
+
function validateEnvVars(requiredVars) {
|
|
22
|
+
const missingVars = requiredVars.filter((varName) => !process.env[varName]);
|
|
23
|
+
if (missingVars.length > 0) {
|
|
24
|
+
const errorMsg = [
|
|
25
|
+
"Error: Missing required environment variables:",
|
|
26
|
+
...missingVars.map((varName) => ` - ${varName}`),
|
|
27
|
+
"",
|
|
28
|
+
"Please set all required environment variables and try again."
|
|
29
|
+
].join(`
|
|
30
|
+
`);
|
|
31
|
+
throw new Error(errorMsg);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function getApiKey(provider) {
|
|
35
|
+
const envVars = API_KEY_ENV_VARS[provider];
|
|
36
|
+
for (const envVar of envVars) {
|
|
37
|
+
const apiKey = process.env[envVar];
|
|
38
|
+
if (apiKey) {
|
|
39
|
+
return apiKey;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const errorMsg = [
|
|
43
|
+
`Error: No API key found for provider "${provider}"`,
|
|
44
|
+
`Required environment variables (at least one):`,
|
|
45
|
+
...envVars.map((envVar) => ` - ${envVar}`)
|
|
46
|
+
].join(`
|
|
47
|
+
`);
|
|
48
|
+
throw new Error(errorMsg);
|
|
49
|
+
}
|
|
50
|
+
// node_modules/@opencode-ai/sdk/dist/gen/core/serverSentEvents.gen.js
|
|
51
|
+
var createSseClient = ({ onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) => {
|
|
52
|
+
let lastEventId;
|
|
53
|
+
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
54
|
+
const createStream = async function* () {
|
|
55
|
+
let retryDelay = sseDefaultRetryDelay ?? 3000;
|
|
56
|
+
let attempt = 0;
|
|
57
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
58
|
+
while (true) {
|
|
59
|
+
if (signal.aborted)
|
|
60
|
+
break;
|
|
61
|
+
attempt++;
|
|
62
|
+
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
63
|
+
if (lastEventId !== undefined) {
|
|
64
|
+
headers.set("Last-Event-ID", lastEventId);
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const response = await fetch(url, { ...options, headers, signal });
|
|
68
|
+
if (!response.ok)
|
|
69
|
+
throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
70
|
+
if (!response.body)
|
|
71
|
+
throw new Error("No body in SSE response");
|
|
72
|
+
const reader = response.body.pipeThrough(new TextDecoderStream).getReader();
|
|
73
|
+
let buffer = "";
|
|
74
|
+
const abortHandler = () => {
|
|
75
|
+
try {
|
|
76
|
+
reader.cancel();
|
|
77
|
+
} catch {}
|
|
78
|
+
};
|
|
79
|
+
signal.addEventListener("abort", abortHandler);
|
|
80
|
+
try {
|
|
81
|
+
while (true) {
|
|
82
|
+
const { done, value } = await reader.read();
|
|
83
|
+
if (done)
|
|
84
|
+
break;
|
|
85
|
+
buffer += value;
|
|
86
|
+
const chunks = buffer.split(`
|
|
87
|
+
|
|
88
|
+
`);
|
|
89
|
+
buffer = chunks.pop() ?? "";
|
|
90
|
+
for (const chunk of chunks) {
|
|
91
|
+
const lines = chunk.split(`
|
|
92
|
+
`);
|
|
93
|
+
const dataLines = [];
|
|
94
|
+
let eventName;
|
|
95
|
+
for (const line of lines) {
|
|
96
|
+
if (line.startsWith("data:")) {
|
|
97
|
+
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
98
|
+
} else if (line.startsWith("event:")) {
|
|
99
|
+
eventName = line.replace(/^event:\s*/, "");
|
|
100
|
+
} else if (line.startsWith("id:")) {
|
|
101
|
+
lastEventId = line.replace(/^id:\s*/, "");
|
|
102
|
+
} else if (line.startsWith("retry:")) {
|
|
103
|
+
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
104
|
+
if (!Number.isNaN(parsed)) {
|
|
105
|
+
retryDelay = parsed;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
let data;
|
|
110
|
+
let parsedJson = false;
|
|
111
|
+
if (dataLines.length) {
|
|
112
|
+
const rawData = dataLines.join(`
|
|
113
|
+
`);
|
|
114
|
+
try {
|
|
115
|
+
data = JSON.parse(rawData);
|
|
116
|
+
parsedJson = true;
|
|
117
|
+
} catch {
|
|
118
|
+
data = rawData;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (parsedJson) {
|
|
122
|
+
if (responseValidator) {
|
|
123
|
+
await responseValidator(data);
|
|
124
|
+
}
|
|
125
|
+
if (responseTransformer) {
|
|
126
|
+
data = await responseTransformer(data);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
onSseEvent?.({
|
|
130
|
+
data,
|
|
131
|
+
event: eventName,
|
|
132
|
+
id: lastEventId,
|
|
133
|
+
retry: retryDelay
|
|
134
|
+
});
|
|
135
|
+
if (dataLines.length) {
|
|
136
|
+
yield data;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
} finally {
|
|
141
|
+
signal.removeEventListener("abort", abortHandler);
|
|
142
|
+
reader.releaseLock();
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
} catch (error) {
|
|
146
|
+
onSseError?.(error);
|
|
147
|
+
if (sseMaxRetryAttempts !== undefined && attempt >= sseMaxRetryAttempts) {
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 30000);
|
|
151
|
+
await sleep(backoff);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
const stream = createStream();
|
|
156
|
+
return { stream };
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// node_modules/@opencode-ai/sdk/dist/gen/core/auth.gen.js
|
|
160
|
+
var getAuthToken = async (auth, callback) => {
|
|
161
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
162
|
+
if (!token) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (auth.scheme === "bearer") {
|
|
166
|
+
return `Bearer ${token}`;
|
|
167
|
+
}
|
|
168
|
+
if (auth.scheme === "basic") {
|
|
169
|
+
return `Basic ${btoa(token)}`;
|
|
170
|
+
}
|
|
171
|
+
return token;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// node_modules/@opencode-ai/sdk/dist/gen/core/bodySerializer.gen.js
|
|
175
|
+
var jsonBodySerializer = {
|
|
176
|
+
bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// node_modules/@opencode-ai/sdk/dist/gen/core/pathSerializer.gen.js
|
|
180
|
+
var separatorArrayExplode = (style) => {
|
|
181
|
+
switch (style) {
|
|
182
|
+
case "label":
|
|
183
|
+
return ".";
|
|
184
|
+
case "matrix":
|
|
185
|
+
return ";";
|
|
186
|
+
case "simple":
|
|
187
|
+
return ",";
|
|
188
|
+
default:
|
|
189
|
+
return "&";
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
var separatorArrayNoExplode = (style) => {
|
|
193
|
+
switch (style) {
|
|
194
|
+
case "form":
|
|
195
|
+
return ",";
|
|
196
|
+
case "pipeDelimited":
|
|
197
|
+
return "|";
|
|
198
|
+
case "spaceDelimited":
|
|
199
|
+
return "%20";
|
|
200
|
+
default:
|
|
201
|
+
return ",";
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
var separatorObjectExplode = (style) => {
|
|
205
|
+
switch (style) {
|
|
206
|
+
case "label":
|
|
207
|
+
return ".";
|
|
208
|
+
case "matrix":
|
|
209
|
+
return ";";
|
|
210
|
+
case "simple":
|
|
211
|
+
return ",";
|
|
212
|
+
default:
|
|
213
|
+
return "&";
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
var serializeArrayParam = ({ allowReserved, explode, name, style, value }) => {
|
|
217
|
+
if (!explode) {
|
|
218
|
+
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
219
|
+
switch (style) {
|
|
220
|
+
case "label":
|
|
221
|
+
return `.${joinedValues2}`;
|
|
222
|
+
case "matrix":
|
|
223
|
+
return `;${name}=${joinedValues2}`;
|
|
224
|
+
case "simple":
|
|
225
|
+
return joinedValues2;
|
|
226
|
+
default:
|
|
227
|
+
return `${name}=${joinedValues2}`;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const separator = separatorArrayExplode(style);
|
|
231
|
+
const joinedValues = value.map((v) => {
|
|
232
|
+
if (style === "label" || style === "simple") {
|
|
233
|
+
return allowReserved ? v : encodeURIComponent(v);
|
|
234
|
+
}
|
|
235
|
+
return serializePrimitiveParam({
|
|
236
|
+
allowReserved,
|
|
237
|
+
name,
|
|
238
|
+
value: v
|
|
239
|
+
});
|
|
240
|
+
}).join(separator);
|
|
241
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
242
|
+
};
|
|
243
|
+
var serializePrimitiveParam = ({ allowReserved, name, value }) => {
|
|
244
|
+
if (value === undefined || value === null) {
|
|
245
|
+
return "";
|
|
246
|
+
}
|
|
247
|
+
if (typeof value === "object") {
|
|
248
|
+
throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
|
|
249
|
+
}
|
|
250
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
251
|
+
};
|
|
252
|
+
var serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly }) => {
|
|
253
|
+
if (value instanceof Date) {
|
|
254
|
+
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
255
|
+
}
|
|
256
|
+
if (style !== "deepObject" && !explode) {
|
|
257
|
+
let values = [];
|
|
258
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
259
|
+
values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
|
|
260
|
+
});
|
|
261
|
+
const joinedValues2 = values.join(",");
|
|
262
|
+
switch (style) {
|
|
263
|
+
case "form":
|
|
264
|
+
return `${name}=${joinedValues2}`;
|
|
265
|
+
case "label":
|
|
266
|
+
return `.${joinedValues2}`;
|
|
267
|
+
case "matrix":
|
|
268
|
+
return `;${name}=${joinedValues2}`;
|
|
269
|
+
default:
|
|
270
|
+
return joinedValues2;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const separator = separatorObjectExplode(style);
|
|
274
|
+
const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
|
|
275
|
+
allowReserved,
|
|
276
|
+
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
277
|
+
value: v
|
|
278
|
+
})).join(separator);
|
|
279
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
// node_modules/@opencode-ai/sdk/dist/gen/core/utils.gen.js
|
|
283
|
+
var PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
284
|
+
var defaultPathSerializer = ({ path, url: _url }) => {
|
|
285
|
+
let url = _url;
|
|
286
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
287
|
+
if (matches) {
|
|
288
|
+
for (const match of matches) {
|
|
289
|
+
let explode = false;
|
|
290
|
+
let name = match.substring(1, match.length - 1);
|
|
291
|
+
let style = "simple";
|
|
292
|
+
if (name.endsWith("*")) {
|
|
293
|
+
explode = true;
|
|
294
|
+
name = name.substring(0, name.length - 1);
|
|
295
|
+
}
|
|
296
|
+
if (name.startsWith(".")) {
|
|
297
|
+
name = name.substring(1);
|
|
298
|
+
style = "label";
|
|
299
|
+
} else if (name.startsWith(";")) {
|
|
300
|
+
name = name.substring(1);
|
|
301
|
+
style = "matrix";
|
|
302
|
+
}
|
|
303
|
+
const value = path[name];
|
|
304
|
+
if (value === undefined || value === null) {
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (Array.isArray(value)) {
|
|
308
|
+
url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (typeof value === "object") {
|
|
312
|
+
url = url.replace(match, serializeObjectParam({
|
|
313
|
+
explode,
|
|
314
|
+
name,
|
|
315
|
+
style,
|
|
316
|
+
value,
|
|
317
|
+
valueOnly: true
|
|
318
|
+
}));
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
if (style === "matrix") {
|
|
322
|
+
url = url.replace(match, `;${serializePrimitiveParam({
|
|
323
|
+
name,
|
|
324
|
+
value
|
|
325
|
+
})}`);
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
|
|
329
|
+
url = url.replace(match, replaceValue);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return url;
|
|
333
|
+
};
|
|
334
|
+
var getUrl = ({ baseUrl, path, query, querySerializer, url: _url }) => {
|
|
335
|
+
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
336
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
337
|
+
if (path) {
|
|
338
|
+
url = defaultPathSerializer({ path, url });
|
|
339
|
+
}
|
|
340
|
+
let search = query ? querySerializer(query) : "";
|
|
341
|
+
if (search.startsWith("?")) {
|
|
342
|
+
search = search.substring(1);
|
|
343
|
+
}
|
|
344
|
+
if (search) {
|
|
345
|
+
url += `?${search}`;
|
|
346
|
+
}
|
|
347
|
+
return url;
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
// node_modules/@opencode-ai/sdk/dist/gen/client/utils.gen.js
|
|
351
|
+
var createQuerySerializer = ({ allowReserved, array, object } = {}) => {
|
|
352
|
+
const querySerializer = (queryParams) => {
|
|
353
|
+
const search = [];
|
|
354
|
+
if (queryParams && typeof queryParams === "object") {
|
|
355
|
+
for (const name in queryParams) {
|
|
356
|
+
const value = queryParams[name];
|
|
357
|
+
if (value === undefined || value === null) {
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
if (Array.isArray(value)) {
|
|
361
|
+
const serializedArray = serializeArrayParam({
|
|
362
|
+
allowReserved,
|
|
363
|
+
explode: true,
|
|
364
|
+
name,
|
|
365
|
+
style: "form",
|
|
366
|
+
value,
|
|
367
|
+
...array
|
|
368
|
+
});
|
|
369
|
+
if (serializedArray)
|
|
370
|
+
search.push(serializedArray);
|
|
371
|
+
} else if (typeof value === "object") {
|
|
372
|
+
const serializedObject = serializeObjectParam({
|
|
373
|
+
allowReserved,
|
|
374
|
+
explode: true,
|
|
375
|
+
name,
|
|
376
|
+
style: "deepObject",
|
|
377
|
+
value,
|
|
378
|
+
...object
|
|
379
|
+
});
|
|
380
|
+
if (serializedObject)
|
|
381
|
+
search.push(serializedObject);
|
|
382
|
+
} else {
|
|
383
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
384
|
+
allowReserved,
|
|
385
|
+
name,
|
|
386
|
+
value
|
|
387
|
+
});
|
|
388
|
+
if (serializedPrimitive)
|
|
389
|
+
search.push(serializedPrimitive);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return search.join("&");
|
|
394
|
+
};
|
|
395
|
+
return querySerializer;
|
|
396
|
+
};
|
|
397
|
+
var getParseAs = (contentType) => {
|
|
398
|
+
if (!contentType) {
|
|
399
|
+
return "stream";
|
|
400
|
+
}
|
|
401
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
402
|
+
if (!cleanContent) {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
406
|
+
return "json";
|
|
407
|
+
}
|
|
408
|
+
if (cleanContent === "multipart/form-data") {
|
|
409
|
+
return "formData";
|
|
410
|
+
}
|
|
411
|
+
if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
|
|
412
|
+
return "blob";
|
|
413
|
+
}
|
|
414
|
+
if (cleanContent.startsWith("text/")) {
|
|
415
|
+
return "text";
|
|
416
|
+
}
|
|
417
|
+
return;
|
|
418
|
+
};
|
|
419
|
+
var checkForExistence = (options, name) => {
|
|
420
|
+
if (!name) {
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
|
424
|
+
return true;
|
|
425
|
+
}
|
|
426
|
+
return false;
|
|
427
|
+
};
|
|
428
|
+
var setAuthParams = async ({ security, ...options }) => {
|
|
429
|
+
for (const auth of security) {
|
|
430
|
+
if (checkForExistence(options, auth.name)) {
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
const token = await getAuthToken(auth, options.auth);
|
|
434
|
+
if (!token) {
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
const name = auth.name ?? "Authorization";
|
|
438
|
+
switch (auth.in) {
|
|
439
|
+
case "query":
|
|
440
|
+
if (!options.query) {
|
|
441
|
+
options.query = {};
|
|
442
|
+
}
|
|
443
|
+
options.query[name] = token;
|
|
444
|
+
break;
|
|
445
|
+
case "cookie":
|
|
446
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
447
|
+
break;
|
|
448
|
+
case "header":
|
|
449
|
+
default:
|
|
450
|
+
options.headers.set(name, token);
|
|
451
|
+
break;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
var buildUrl = (options) => getUrl({
|
|
456
|
+
baseUrl: options.baseUrl,
|
|
457
|
+
path: options.path,
|
|
458
|
+
query: options.query,
|
|
459
|
+
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
460
|
+
url: options.url
|
|
461
|
+
});
|
|
462
|
+
var mergeConfigs = (a, b) => {
|
|
463
|
+
const config = { ...a, ...b };
|
|
464
|
+
if (config.baseUrl?.endsWith("/")) {
|
|
465
|
+
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
466
|
+
}
|
|
467
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
468
|
+
return config;
|
|
469
|
+
};
|
|
470
|
+
var mergeHeaders = (...headers) => {
|
|
471
|
+
const mergedHeaders = new Headers;
|
|
472
|
+
for (const header of headers) {
|
|
473
|
+
if (!header || typeof header !== "object") {
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
const iterator = header instanceof Headers ? header.entries() : Object.entries(header);
|
|
477
|
+
for (const [key, value] of iterator) {
|
|
478
|
+
if (value === null) {
|
|
479
|
+
mergedHeaders.delete(key);
|
|
480
|
+
} else if (Array.isArray(value)) {
|
|
481
|
+
for (const v of value) {
|
|
482
|
+
mergedHeaders.append(key, v);
|
|
483
|
+
}
|
|
484
|
+
} else if (value !== undefined) {
|
|
485
|
+
mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return mergedHeaders;
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
class Interceptors {
|
|
493
|
+
_fns;
|
|
494
|
+
constructor() {
|
|
495
|
+
this._fns = [];
|
|
496
|
+
}
|
|
497
|
+
clear() {
|
|
498
|
+
this._fns = [];
|
|
499
|
+
}
|
|
500
|
+
getInterceptorIndex(id) {
|
|
501
|
+
if (typeof id === "number") {
|
|
502
|
+
return this._fns[id] ? id : -1;
|
|
503
|
+
} else {
|
|
504
|
+
return this._fns.indexOf(id);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
exists(id) {
|
|
508
|
+
const index = this.getInterceptorIndex(id);
|
|
509
|
+
return !!this._fns[index];
|
|
510
|
+
}
|
|
511
|
+
eject(id) {
|
|
512
|
+
const index = this.getInterceptorIndex(id);
|
|
513
|
+
if (this._fns[index]) {
|
|
514
|
+
this._fns[index] = null;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
update(id, fn) {
|
|
518
|
+
const index = this.getInterceptorIndex(id);
|
|
519
|
+
if (this._fns[index]) {
|
|
520
|
+
this._fns[index] = fn;
|
|
521
|
+
return id;
|
|
522
|
+
} else {
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
use(fn) {
|
|
527
|
+
this._fns = [...this._fns, fn];
|
|
528
|
+
return this._fns.length - 1;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
var createInterceptors = () => ({
|
|
532
|
+
error: new Interceptors,
|
|
533
|
+
request: new Interceptors,
|
|
534
|
+
response: new Interceptors
|
|
535
|
+
});
|
|
536
|
+
var defaultQuerySerializer = createQuerySerializer({
|
|
537
|
+
allowReserved: false,
|
|
538
|
+
array: {
|
|
539
|
+
explode: true,
|
|
540
|
+
style: "form"
|
|
541
|
+
},
|
|
542
|
+
object: {
|
|
543
|
+
explode: true,
|
|
544
|
+
style: "deepObject"
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
var defaultHeaders = {
|
|
548
|
+
"Content-Type": "application/json"
|
|
549
|
+
};
|
|
550
|
+
var createConfig = (override = {}) => ({
|
|
551
|
+
...jsonBodySerializer,
|
|
552
|
+
headers: defaultHeaders,
|
|
553
|
+
parseAs: "auto",
|
|
554
|
+
querySerializer: defaultQuerySerializer,
|
|
555
|
+
...override
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
// node_modules/@opencode-ai/sdk/dist/gen/client/client.gen.js
|
|
559
|
+
var createClient = (config = {}) => {
|
|
560
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
561
|
+
const getConfig = () => ({ ..._config });
|
|
562
|
+
const setConfig = (config2) => {
|
|
563
|
+
_config = mergeConfigs(_config, config2);
|
|
564
|
+
return getConfig();
|
|
565
|
+
};
|
|
566
|
+
const interceptors = createInterceptors();
|
|
567
|
+
const beforeRequest = async (options) => {
|
|
568
|
+
const opts = {
|
|
569
|
+
..._config,
|
|
570
|
+
...options,
|
|
571
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
572
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
573
|
+
serializedBody: undefined
|
|
574
|
+
};
|
|
575
|
+
if (opts.security) {
|
|
576
|
+
await setAuthParams({
|
|
577
|
+
...opts,
|
|
578
|
+
security: opts.security
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
if (opts.requestValidator) {
|
|
582
|
+
await opts.requestValidator(opts);
|
|
583
|
+
}
|
|
584
|
+
if (opts.body && opts.bodySerializer) {
|
|
585
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
586
|
+
}
|
|
587
|
+
if (opts.serializedBody === undefined || opts.serializedBody === "") {
|
|
588
|
+
opts.headers.delete("Content-Type");
|
|
589
|
+
}
|
|
590
|
+
const url = buildUrl(opts);
|
|
591
|
+
return { opts, url };
|
|
592
|
+
};
|
|
593
|
+
const request = async (options) => {
|
|
594
|
+
const { opts, url } = await beforeRequest(options);
|
|
595
|
+
const requestInit = {
|
|
596
|
+
redirect: "follow",
|
|
597
|
+
...opts,
|
|
598
|
+
body: opts.serializedBody
|
|
599
|
+
};
|
|
600
|
+
let request2 = new Request(url, requestInit);
|
|
601
|
+
for (const fn of interceptors.request._fns) {
|
|
602
|
+
if (fn) {
|
|
603
|
+
request2 = await fn(request2, opts);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
const _fetch = opts.fetch;
|
|
607
|
+
let response = await _fetch(request2);
|
|
608
|
+
for (const fn of interceptors.response._fns) {
|
|
609
|
+
if (fn) {
|
|
610
|
+
response = await fn(response, request2, opts);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
const result = {
|
|
614
|
+
request: request2,
|
|
615
|
+
response
|
|
616
|
+
};
|
|
617
|
+
if (response.ok) {
|
|
618
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
619
|
+
return opts.responseStyle === "data" ? {} : {
|
|
620
|
+
data: {},
|
|
621
|
+
...result
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
625
|
+
let data;
|
|
626
|
+
switch (parseAs) {
|
|
627
|
+
case "arrayBuffer":
|
|
628
|
+
case "blob":
|
|
629
|
+
case "formData":
|
|
630
|
+
case "json":
|
|
631
|
+
case "text":
|
|
632
|
+
data = await response[parseAs]();
|
|
633
|
+
break;
|
|
634
|
+
case "stream":
|
|
635
|
+
return opts.responseStyle === "data" ? response.body : {
|
|
636
|
+
data: response.body,
|
|
637
|
+
...result
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
if (parseAs === "json") {
|
|
641
|
+
if (opts.responseValidator) {
|
|
642
|
+
await opts.responseValidator(data);
|
|
643
|
+
}
|
|
644
|
+
if (opts.responseTransformer) {
|
|
645
|
+
data = await opts.responseTransformer(data);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return opts.responseStyle === "data" ? data : {
|
|
649
|
+
data,
|
|
650
|
+
...result
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
const textError = await response.text();
|
|
654
|
+
let jsonError;
|
|
655
|
+
try {
|
|
656
|
+
jsonError = JSON.parse(textError);
|
|
657
|
+
} catch {}
|
|
658
|
+
const error = jsonError ?? textError;
|
|
659
|
+
let finalError = error;
|
|
660
|
+
for (const fn of interceptors.error._fns) {
|
|
661
|
+
if (fn) {
|
|
662
|
+
finalError = await fn(error, response, request2, opts);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
finalError = finalError || {};
|
|
666
|
+
if (opts.throwOnError) {
|
|
667
|
+
throw finalError;
|
|
668
|
+
}
|
|
669
|
+
return opts.responseStyle === "data" ? undefined : {
|
|
670
|
+
error: finalError,
|
|
671
|
+
...result
|
|
672
|
+
};
|
|
673
|
+
};
|
|
674
|
+
const makeMethod = (method) => {
|
|
675
|
+
const fn = (options) => request({ ...options, method });
|
|
676
|
+
fn.sse = async (options) => {
|
|
677
|
+
const { opts, url } = await beforeRequest(options);
|
|
678
|
+
return createSseClient({
|
|
679
|
+
...opts,
|
|
680
|
+
body: opts.body,
|
|
681
|
+
headers: opts.headers,
|
|
682
|
+
method,
|
|
683
|
+
url
|
|
684
|
+
});
|
|
685
|
+
};
|
|
686
|
+
return fn;
|
|
687
|
+
};
|
|
688
|
+
return {
|
|
689
|
+
buildUrl,
|
|
690
|
+
connect: makeMethod("CONNECT"),
|
|
691
|
+
delete: makeMethod("DELETE"),
|
|
692
|
+
get: makeMethod("GET"),
|
|
693
|
+
getConfig,
|
|
694
|
+
head: makeMethod("HEAD"),
|
|
695
|
+
interceptors,
|
|
696
|
+
options: makeMethod("OPTIONS"),
|
|
697
|
+
patch: makeMethod("PATCH"),
|
|
698
|
+
post: makeMethod("POST"),
|
|
699
|
+
put: makeMethod("PUT"),
|
|
700
|
+
request,
|
|
701
|
+
setConfig,
|
|
702
|
+
trace: makeMethod("TRACE")
|
|
703
|
+
};
|
|
704
|
+
};
|
|
705
|
+
// node_modules/@opencode-ai/sdk/dist/gen/core/params.gen.js
|
|
706
|
+
var extraPrefixesMap = {
|
|
707
|
+
$body_: "body",
|
|
708
|
+
$headers_: "headers",
|
|
709
|
+
$path_: "path",
|
|
710
|
+
$query_: "query"
|
|
711
|
+
};
|
|
712
|
+
var extraPrefixes = Object.entries(extraPrefixesMap);
|
|
713
|
+
// node_modules/@opencode-ai/sdk/dist/gen/client.gen.js
|
|
714
|
+
var client = createClient(createConfig({
|
|
715
|
+
baseUrl: "http://localhost:4096"
|
|
716
|
+
}));
|
|
717
|
+
|
|
718
|
+
// node_modules/@opencode-ai/sdk/dist/gen/sdk.gen.js
|
|
719
|
+
class _HeyApiClient {
|
|
720
|
+
_client = client;
|
|
721
|
+
constructor(args) {
|
|
722
|
+
if (args?.client) {
|
|
723
|
+
this._client = args.client;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
class Global extends _HeyApiClient {
|
|
729
|
+
event(options) {
|
|
730
|
+
return (options?.client ?? this._client).get.sse({
|
|
731
|
+
url: "/global/event",
|
|
732
|
+
...options
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
class Project extends _HeyApiClient {
|
|
738
|
+
list(options) {
|
|
739
|
+
return (options?.client ?? this._client).get({
|
|
740
|
+
url: "/project",
|
|
741
|
+
...options
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
current(options) {
|
|
745
|
+
return (options?.client ?? this._client).get({
|
|
746
|
+
url: "/project/current",
|
|
747
|
+
...options
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
class Pty extends _HeyApiClient {
|
|
753
|
+
list(options) {
|
|
754
|
+
return (options?.client ?? this._client).get({
|
|
755
|
+
url: "/pty",
|
|
756
|
+
...options
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
create(options) {
|
|
760
|
+
return (options?.client ?? this._client).post({
|
|
761
|
+
url: "/pty",
|
|
762
|
+
...options,
|
|
763
|
+
headers: {
|
|
764
|
+
"Content-Type": "application/json",
|
|
765
|
+
...options?.headers
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
remove(options) {
|
|
770
|
+
return (options.client ?? this._client).delete({
|
|
771
|
+
url: "/pty/{id}",
|
|
772
|
+
...options
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
get(options) {
|
|
776
|
+
return (options.client ?? this._client).get({
|
|
777
|
+
url: "/pty/{id}",
|
|
778
|
+
...options
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
update(options) {
|
|
782
|
+
return (options.client ?? this._client).put({
|
|
783
|
+
url: "/pty/{id}",
|
|
784
|
+
...options,
|
|
785
|
+
headers: {
|
|
786
|
+
"Content-Type": "application/json",
|
|
787
|
+
...options.headers
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
connect(options) {
|
|
792
|
+
return (options.client ?? this._client).get({
|
|
793
|
+
url: "/pty/{id}/connect",
|
|
794
|
+
...options
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
class Config extends _HeyApiClient {
|
|
800
|
+
get(options) {
|
|
801
|
+
return (options?.client ?? this._client).get({
|
|
802
|
+
url: "/config",
|
|
803
|
+
...options
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
update(options) {
|
|
807
|
+
return (options?.client ?? this._client).patch({
|
|
808
|
+
url: "/config",
|
|
809
|
+
...options,
|
|
810
|
+
headers: {
|
|
811
|
+
"Content-Type": "application/json",
|
|
812
|
+
...options?.headers
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
providers(options) {
|
|
817
|
+
return (options?.client ?? this._client).get({
|
|
818
|
+
url: "/config/providers",
|
|
819
|
+
...options
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
class Tool extends _HeyApiClient {
|
|
825
|
+
ids(options) {
|
|
826
|
+
return (options?.client ?? this._client).get({
|
|
827
|
+
url: "/experimental/tool/ids",
|
|
828
|
+
...options
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
list(options) {
|
|
832
|
+
return (options.client ?? this._client).get({
|
|
833
|
+
url: "/experimental/tool",
|
|
834
|
+
...options
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
class Instance extends _HeyApiClient {
|
|
840
|
+
dispose(options) {
|
|
841
|
+
return (options?.client ?? this._client).post({
|
|
842
|
+
url: "/instance/dispose",
|
|
843
|
+
...options
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
class Path extends _HeyApiClient {
|
|
849
|
+
get(options) {
|
|
850
|
+
return (options?.client ?? this._client).get({
|
|
851
|
+
url: "/path",
|
|
852
|
+
...options
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
class Vcs extends _HeyApiClient {
|
|
858
|
+
get(options) {
|
|
859
|
+
return (options?.client ?? this._client).get({
|
|
860
|
+
url: "/vcs",
|
|
861
|
+
...options
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
class Session extends _HeyApiClient {
|
|
867
|
+
list(options) {
|
|
868
|
+
return (options?.client ?? this._client).get({
|
|
869
|
+
url: "/session",
|
|
870
|
+
...options
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
create(options) {
|
|
874
|
+
return (options?.client ?? this._client).post({
|
|
875
|
+
url: "/session",
|
|
876
|
+
...options,
|
|
877
|
+
headers: {
|
|
878
|
+
"Content-Type": "application/json",
|
|
879
|
+
...options?.headers
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
status(options) {
|
|
884
|
+
return (options?.client ?? this._client).get({
|
|
885
|
+
url: "/session/status",
|
|
886
|
+
...options
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
delete(options) {
|
|
890
|
+
return (options.client ?? this._client).delete({
|
|
891
|
+
url: "/session/{id}",
|
|
892
|
+
...options
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
get(options) {
|
|
896
|
+
return (options.client ?? this._client).get({
|
|
897
|
+
url: "/session/{id}",
|
|
898
|
+
...options
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
update(options) {
|
|
902
|
+
return (options.client ?? this._client).patch({
|
|
903
|
+
url: "/session/{id}",
|
|
904
|
+
...options,
|
|
905
|
+
headers: {
|
|
906
|
+
"Content-Type": "application/json",
|
|
907
|
+
...options.headers
|
|
908
|
+
}
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
children(options) {
|
|
912
|
+
return (options.client ?? this._client).get({
|
|
913
|
+
url: "/session/{id}/children",
|
|
914
|
+
...options
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
todo(options) {
|
|
918
|
+
return (options.client ?? this._client).get({
|
|
919
|
+
url: "/session/{id}/todo",
|
|
920
|
+
...options
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
init(options) {
|
|
924
|
+
return (options.client ?? this._client).post({
|
|
925
|
+
url: "/session/{id}/init",
|
|
926
|
+
...options,
|
|
927
|
+
headers: {
|
|
928
|
+
"Content-Type": "application/json",
|
|
929
|
+
...options.headers
|
|
930
|
+
}
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
fork(options) {
|
|
934
|
+
return (options.client ?? this._client).post({
|
|
935
|
+
url: "/session/{id}/fork",
|
|
936
|
+
...options,
|
|
937
|
+
headers: {
|
|
938
|
+
"Content-Type": "application/json",
|
|
939
|
+
...options.headers
|
|
940
|
+
}
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
abort(options) {
|
|
944
|
+
return (options.client ?? this._client).post({
|
|
945
|
+
url: "/session/{id}/abort",
|
|
946
|
+
...options
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
unshare(options) {
|
|
950
|
+
return (options.client ?? this._client).delete({
|
|
951
|
+
url: "/session/{id}/share",
|
|
952
|
+
...options
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
share(options) {
|
|
956
|
+
return (options.client ?? this._client).post({
|
|
957
|
+
url: "/session/{id}/share",
|
|
958
|
+
...options
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
diff(options) {
|
|
962
|
+
return (options.client ?? this._client).get({
|
|
963
|
+
url: "/session/{id}/diff",
|
|
964
|
+
...options
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
summarize(options) {
|
|
968
|
+
return (options.client ?? this._client).post({
|
|
969
|
+
url: "/session/{id}/summarize",
|
|
970
|
+
...options,
|
|
971
|
+
headers: {
|
|
972
|
+
"Content-Type": "application/json",
|
|
973
|
+
...options.headers
|
|
974
|
+
}
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
messages(options) {
|
|
978
|
+
return (options.client ?? this._client).get({
|
|
979
|
+
url: "/session/{id}/message",
|
|
980
|
+
...options
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
prompt(options) {
|
|
984
|
+
return (options.client ?? this._client).post({
|
|
985
|
+
url: "/session/{id}/message",
|
|
986
|
+
...options,
|
|
987
|
+
headers: {
|
|
988
|
+
"Content-Type": "application/json",
|
|
989
|
+
...options.headers
|
|
990
|
+
}
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
message(options) {
|
|
994
|
+
return (options.client ?? this._client).get({
|
|
995
|
+
url: "/session/{id}/message/{messageID}",
|
|
996
|
+
...options
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
promptAsync(options) {
|
|
1000
|
+
return (options.client ?? this._client).post({
|
|
1001
|
+
url: "/session/{id}/prompt_async",
|
|
1002
|
+
...options,
|
|
1003
|
+
headers: {
|
|
1004
|
+
"Content-Type": "application/json",
|
|
1005
|
+
...options.headers
|
|
1006
|
+
}
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
command(options) {
|
|
1010
|
+
return (options.client ?? this._client).post({
|
|
1011
|
+
url: "/session/{id}/command",
|
|
1012
|
+
...options,
|
|
1013
|
+
headers: {
|
|
1014
|
+
"Content-Type": "application/json",
|
|
1015
|
+
...options.headers
|
|
1016
|
+
}
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
shell(options) {
|
|
1020
|
+
return (options.client ?? this._client).post({
|
|
1021
|
+
url: "/session/{id}/shell",
|
|
1022
|
+
...options,
|
|
1023
|
+
headers: {
|
|
1024
|
+
"Content-Type": "application/json",
|
|
1025
|
+
...options.headers
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
revert(options) {
|
|
1030
|
+
return (options.client ?? this._client).post({
|
|
1031
|
+
url: "/session/{id}/revert",
|
|
1032
|
+
...options,
|
|
1033
|
+
headers: {
|
|
1034
|
+
"Content-Type": "application/json",
|
|
1035
|
+
...options.headers
|
|
1036
|
+
}
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
unrevert(options) {
|
|
1040
|
+
return (options.client ?? this._client).post({
|
|
1041
|
+
url: "/session/{id}/unrevert",
|
|
1042
|
+
...options
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
class Command extends _HeyApiClient {
|
|
1048
|
+
list(options) {
|
|
1049
|
+
return (options?.client ?? this._client).get({
|
|
1050
|
+
url: "/command",
|
|
1051
|
+
...options
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
class Oauth extends _HeyApiClient {
|
|
1057
|
+
authorize(options) {
|
|
1058
|
+
return (options.client ?? this._client).post({
|
|
1059
|
+
url: "/provider/{id}/oauth/authorize",
|
|
1060
|
+
...options,
|
|
1061
|
+
headers: {
|
|
1062
|
+
"Content-Type": "application/json",
|
|
1063
|
+
...options.headers
|
|
1064
|
+
}
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
callback(options) {
|
|
1068
|
+
return (options.client ?? this._client).post({
|
|
1069
|
+
url: "/provider/{id}/oauth/callback",
|
|
1070
|
+
...options,
|
|
1071
|
+
headers: {
|
|
1072
|
+
"Content-Type": "application/json",
|
|
1073
|
+
...options.headers
|
|
1074
|
+
}
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
class Provider2 extends _HeyApiClient {
|
|
1080
|
+
list(options) {
|
|
1081
|
+
return (options?.client ?? this._client).get({
|
|
1082
|
+
url: "/provider",
|
|
1083
|
+
...options
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
auth(options) {
|
|
1087
|
+
return (options?.client ?? this._client).get({
|
|
1088
|
+
url: "/provider/auth",
|
|
1089
|
+
...options
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
oauth = new Oauth({ client: this._client });
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
class Find extends _HeyApiClient {
|
|
1096
|
+
text(options) {
|
|
1097
|
+
return (options.client ?? this._client).get({
|
|
1098
|
+
url: "/find",
|
|
1099
|
+
...options
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
files(options) {
|
|
1103
|
+
return (options.client ?? this._client).get({
|
|
1104
|
+
url: "/find/file",
|
|
1105
|
+
...options
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
symbols(options) {
|
|
1109
|
+
return (options.client ?? this._client).get({
|
|
1110
|
+
url: "/find/symbol",
|
|
1111
|
+
...options
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
class File extends _HeyApiClient {
|
|
1117
|
+
list(options) {
|
|
1118
|
+
return (options.client ?? this._client).get({
|
|
1119
|
+
url: "/file",
|
|
1120
|
+
...options
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
read(options) {
|
|
1124
|
+
return (options.client ?? this._client).get({
|
|
1125
|
+
url: "/file/content",
|
|
1126
|
+
...options
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
status(options) {
|
|
1130
|
+
return (options?.client ?? this._client).get({
|
|
1131
|
+
url: "/file/status",
|
|
1132
|
+
...options
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
class App extends _HeyApiClient {
|
|
1138
|
+
log(options) {
|
|
1139
|
+
return (options?.client ?? this._client).post({
|
|
1140
|
+
url: "/log",
|
|
1141
|
+
...options,
|
|
1142
|
+
headers: {
|
|
1143
|
+
"Content-Type": "application/json",
|
|
1144
|
+
...options?.headers
|
|
1145
|
+
}
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
agents(options) {
|
|
1149
|
+
return (options?.client ?? this._client).get({
|
|
1150
|
+
url: "/agent",
|
|
1151
|
+
...options
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
class Auth extends _HeyApiClient {
|
|
1157
|
+
remove(options) {
|
|
1158
|
+
return (options.client ?? this._client).delete({
|
|
1159
|
+
url: "/mcp/{name}/auth",
|
|
1160
|
+
...options
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1163
|
+
start(options) {
|
|
1164
|
+
return (options.client ?? this._client).post({
|
|
1165
|
+
url: "/mcp/{name}/auth",
|
|
1166
|
+
...options
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
callback(options) {
|
|
1170
|
+
return (options.client ?? this._client).post({
|
|
1171
|
+
url: "/mcp/{name}/auth/callback",
|
|
1172
|
+
...options,
|
|
1173
|
+
headers: {
|
|
1174
|
+
"Content-Type": "application/json",
|
|
1175
|
+
...options.headers
|
|
1176
|
+
}
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
authenticate(options) {
|
|
1180
|
+
return (options.client ?? this._client).post({
|
|
1181
|
+
url: "/mcp/{name}/auth/authenticate",
|
|
1182
|
+
...options
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
set(options) {
|
|
1186
|
+
return (options.client ?? this._client).put({
|
|
1187
|
+
url: "/auth/{id}",
|
|
1188
|
+
...options,
|
|
1189
|
+
headers: {
|
|
1190
|
+
"Content-Type": "application/json",
|
|
1191
|
+
...options.headers
|
|
1192
|
+
}
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
class Mcp extends _HeyApiClient {
|
|
1198
|
+
status(options) {
|
|
1199
|
+
return (options?.client ?? this._client).get({
|
|
1200
|
+
url: "/mcp",
|
|
1201
|
+
...options
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
add(options) {
|
|
1205
|
+
return (options?.client ?? this._client).post({
|
|
1206
|
+
url: "/mcp",
|
|
1207
|
+
...options,
|
|
1208
|
+
headers: {
|
|
1209
|
+
"Content-Type": "application/json",
|
|
1210
|
+
...options?.headers
|
|
1211
|
+
}
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
connect(options) {
|
|
1215
|
+
return (options.client ?? this._client).post({
|
|
1216
|
+
url: "/mcp/{name}/connect",
|
|
1217
|
+
...options
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
disconnect(options) {
|
|
1221
|
+
return (options.client ?? this._client).post({
|
|
1222
|
+
url: "/mcp/{name}/disconnect",
|
|
1223
|
+
...options
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
auth = new Auth({ client: this._client });
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
class Lsp extends _HeyApiClient {
|
|
1230
|
+
status(options) {
|
|
1231
|
+
return (options?.client ?? this._client).get({
|
|
1232
|
+
url: "/lsp",
|
|
1233
|
+
...options
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
class Formatter extends _HeyApiClient {
|
|
1239
|
+
status(options) {
|
|
1240
|
+
return (options?.client ?? this._client).get({
|
|
1241
|
+
url: "/formatter",
|
|
1242
|
+
...options
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
class Control extends _HeyApiClient {
|
|
1248
|
+
next(options) {
|
|
1249
|
+
return (options?.client ?? this._client).get({
|
|
1250
|
+
url: "/tui/control/next",
|
|
1251
|
+
...options
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
1254
|
+
response(options) {
|
|
1255
|
+
return (options?.client ?? this._client).post({
|
|
1256
|
+
url: "/tui/control/response",
|
|
1257
|
+
...options,
|
|
1258
|
+
headers: {
|
|
1259
|
+
"Content-Type": "application/json",
|
|
1260
|
+
...options?.headers
|
|
1261
|
+
}
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
class Tui extends _HeyApiClient {
|
|
1267
|
+
appendPrompt(options) {
|
|
1268
|
+
return (options?.client ?? this._client).post({
|
|
1269
|
+
url: "/tui/append-prompt",
|
|
1270
|
+
...options,
|
|
1271
|
+
headers: {
|
|
1272
|
+
"Content-Type": "application/json",
|
|
1273
|
+
...options?.headers
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
openHelp(options) {
|
|
1278
|
+
return (options?.client ?? this._client).post({
|
|
1279
|
+
url: "/tui/open-help",
|
|
1280
|
+
...options
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
openSessions(options) {
|
|
1284
|
+
return (options?.client ?? this._client).post({
|
|
1285
|
+
url: "/tui/open-sessions",
|
|
1286
|
+
...options
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
openThemes(options) {
|
|
1290
|
+
return (options?.client ?? this._client).post({
|
|
1291
|
+
url: "/tui/open-themes",
|
|
1292
|
+
...options
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
openModels(options) {
|
|
1296
|
+
return (options?.client ?? this._client).post({
|
|
1297
|
+
url: "/tui/open-models",
|
|
1298
|
+
...options
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1301
|
+
submitPrompt(options) {
|
|
1302
|
+
return (options?.client ?? this._client).post({
|
|
1303
|
+
url: "/tui/submit-prompt",
|
|
1304
|
+
...options
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
clearPrompt(options) {
|
|
1308
|
+
return (options?.client ?? this._client).post({
|
|
1309
|
+
url: "/tui/clear-prompt",
|
|
1310
|
+
...options
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
executeCommand(options) {
|
|
1314
|
+
return (options?.client ?? this._client).post({
|
|
1315
|
+
url: "/tui/execute-command",
|
|
1316
|
+
...options,
|
|
1317
|
+
headers: {
|
|
1318
|
+
"Content-Type": "application/json",
|
|
1319
|
+
...options?.headers
|
|
1320
|
+
}
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
showToast(options) {
|
|
1324
|
+
return (options?.client ?? this._client).post({
|
|
1325
|
+
url: "/tui/show-toast",
|
|
1326
|
+
...options,
|
|
1327
|
+
headers: {
|
|
1328
|
+
"Content-Type": "application/json",
|
|
1329
|
+
...options?.headers
|
|
1330
|
+
}
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
publish(options) {
|
|
1334
|
+
return (options?.client ?? this._client).post({
|
|
1335
|
+
url: "/tui/publish",
|
|
1336
|
+
...options,
|
|
1337
|
+
headers: {
|
|
1338
|
+
"Content-Type": "application/json",
|
|
1339
|
+
...options?.headers
|
|
1340
|
+
}
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1343
|
+
control = new Control({ client: this._client });
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
class Event extends _HeyApiClient {
|
|
1347
|
+
subscribe(options) {
|
|
1348
|
+
return (options?.client ?? this._client).get.sse({
|
|
1349
|
+
url: "/event",
|
|
1350
|
+
...options
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
class OpencodeClient extends _HeyApiClient {
|
|
1356
|
+
postSessionIdPermissionsPermissionId(options) {
|
|
1357
|
+
return (options.client ?? this._client).post({
|
|
1358
|
+
url: "/session/{id}/permissions/{permissionID}",
|
|
1359
|
+
...options,
|
|
1360
|
+
headers: {
|
|
1361
|
+
"Content-Type": "application/json",
|
|
1362
|
+
...options.headers
|
|
1363
|
+
}
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
global = new Global({ client: this._client });
|
|
1367
|
+
project = new Project({ client: this._client });
|
|
1368
|
+
pty = new Pty({ client: this._client });
|
|
1369
|
+
config = new Config({ client: this._client });
|
|
1370
|
+
tool = new Tool({ client: this._client });
|
|
1371
|
+
instance = new Instance({ client: this._client });
|
|
1372
|
+
path = new Path({ client: this._client });
|
|
1373
|
+
vcs = new Vcs({ client: this._client });
|
|
1374
|
+
session = new Session({ client: this._client });
|
|
1375
|
+
command = new Command({ client: this._client });
|
|
1376
|
+
provider = new Provider2({ client: this._client });
|
|
1377
|
+
find = new Find({ client: this._client });
|
|
1378
|
+
file = new File({ client: this._client });
|
|
1379
|
+
app = new App({ client: this._client });
|
|
1380
|
+
mcp = new Mcp({ client: this._client });
|
|
1381
|
+
lsp = new Lsp({ client: this._client });
|
|
1382
|
+
formatter = new Formatter({ client: this._client });
|
|
1383
|
+
tui = new Tui({ client: this._client });
|
|
1384
|
+
auth = new Auth({ client: this._client });
|
|
1385
|
+
event = new Event({ client: this._client });
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
// node_modules/@opencode-ai/sdk/dist/client.js
|
|
1389
|
+
function createOpencodeClient(config) {
|
|
1390
|
+
if (!config?.fetch) {
|
|
1391
|
+
const customFetch = (req) => {
|
|
1392
|
+
req.timeout = false;
|
|
1393
|
+
return fetch(req);
|
|
1394
|
+
};
|
|
1395
|
+
config = {
|
|
1396
|
+
...config,
|
|
1397
|
+
fetch: customFetch
|
|
1398
|
+
};
|
|
1399
|
+
}
|
|
1400
|
+
if (config?.directory) {
|
|
1401
|
+
config.headers = {
|
|
1402
|
+
...config.headers,
|
|
1403
|
+
"x-opencode-directory": config.directory
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
const client2 = createClient(config);
|
|
1407
|
+
return new OpencodeClient({ client: client2 });
|
|
1408
|
+
}
|
|
1409
|
+
// node_modules/@opencode-ai/sdk/dist/server.js
|
|
1410
|
+
import { spawn } from "node:child_process";
|
|
1411
|
+
async function createOpencodeServer(options) {
|
|
1412
|
+
options = Object.assign({
|
|
1413
|
+
hostname: "127.0.0.1",
|
|
1414
|
+
port: 4096,
|
|
1415
|
+
timeout: 5000
|
|
1416
|
+
}, options ?? {});
|
|
1417
|
+
const proc = spawn(`opencode`, [`serve`, `--hostname=${options.hostname}`, `--port=${options.port}`], {
|
|
1418
|
+
signal: options.signal,
|
|
1419
|
+
env: {
|
|
1420
|
+
...process.env,
|
|
1421
|
+
OPENCODE_CONFIG_CONTENT: JSON.stringify(options.config ?? {})
|
|
1422
|
+
}
|
|
1423
|
+
});
|
|
1424
|
+
const url = await new Promise((resolve, reject) => {
|
|
1425
|
+
const id = setTimeout(() => {
|
|
1426
|
+
reject(new Error(`Timeout waiting for server to start after ${options.timeout}ms`));
|
|
1427
|
+
}, options.timeout);
|
|
1428
|
+
let output = "";
|
|
1429
|
+
proc.stdout?.on("data", (chunk) => {
|
|
1430
|
+
output += chunk.toString();
|
|
1431
|
+
const lines = output.split(`
|
|
1432
|
+
`);
|
|
1433
|
+
for (const line of lines) {
|
|
1434
|
+
if (line.startsWith("opencode server listening")) {
|
|
1435
|
+
const match = line.match(/on\s+(https?:\/\/[^\s]+)/);
|
|
1436
|
+
if (!match) {
|
|
1437
|
+
throw new Error(`Failed to parse server url from output: ${line}`);
|
|
1438
|
+
}
|
|
1439
|
+
clearTimeout(id);
|
|
1440
|
+
resolve(match[1]);
|
|
1441
|
+
return;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
});
|
|
1445
|
+
proc.stderr?.on("data", (chunk) => {
|
|
1446
|
+
output += chunk.toString();
|
|
1447
|
+
});
|
|
1448
|
+
proc.on("exit", (code) => {
|
|
1449
|
+
clearTimeout(id);
|
|
1450
|
+
let msg = `Server exited with code ${code}`;
|
|
1451
|
+
if (output.trim()) {
|
|
1452
|
+
msg += `
|
|
1453
|
+
Server output: ${output}`;
|
|
1454
|
+
}
|
|
1455
|
+
reject(new Error(msg));
|
|
1456
|
+
});
|
|
1457
|
+
proc.on("error", (error) => {
|
|
1458
|
+
clearTimeout(id);
|
|
1459
|
+
reject(error);
|
|
1460
|
+
});
|
|
1461
|
+
if (options.signal) {
|
|
1462
|
+
options.signal.addEventListener("abort", () => {
|
|
1463
|
+
clearTimeout(id);
|
|
1464
|
+
reject(new Error("Aborted"));
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
});
|
|
1468
|
+
return {
|
|
1469
|
+
url,
|
|
1470
|
+
close() {
|
|
1471
|
+
proc.kill();
|
|
1472
|
+
}
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
// node_modules/@opencode-ai/sdk/dist/index.js
|
|
1476
|
+
async function createOpencode(options) {
|
|
1477
|
+
const server2 = await createOpencodeServer({
|
|
1478
|
+
...options
|
|
1479
|
+
});
|
|
1480
|
+
const client3 = createOpencodeClient({
|
|
1481
|
+
baseUrl: server2.url
|
|
1482
|
+
});
|
|
1483
|
+
return {
|
|
1484
|
+
client: client3,
|
|
1485
|
+
server: server2
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
// src/lib/opencode.ts
|
|
1490
|
+
async function createOpencodeServer2(options) {
|
|
1491
|
+
const {
|
|
1492
|
+
provider,
|
|
1493
|
+
apiKey,
|
|
1494
|
+
model,
|
|
1495
|
+
agentName,
|
|
1496
|
+
agentDescription,
|
|
1497
|
+
agentPrompt,
|
|
1498
|
+
agentTools = {},
|
|
1499
|
+
agentPermissions = {},
|
|
1500
|
+
maxSteps = 30,
|
|
1501
|
+
linearApiKey
|
|
1502
|
+
} = options;
|
|
1503
|
+
const opcodeConfig = {
|
|
1504
|
+
provider: {
|
|
1505
|
+
[provider]: {
|
|
1506
|
+
options: {
|
|
1507
|
+
apiKey,
|
|
1508
|
+
timeout: false
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
},
|
|
1512
|
+
...linearApiKey && {
|
|
1513
|
+
mcp: {
|
|
1514
|
+
linear: {
|
|
1515
|
+
type: "remote",
|
|
1516
|
+
url: "https://mcp.linear.app/mcp",
|
|
1517
|
+
headers: {
|
|
1518
|
+
Authorization: `Bearer ${linearApiKey}`
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
},
|
|
1523
|
+
agent: {
|
|
1524
|
+
[agentName]: {
|
|
1525
|
+
description: agentDescription,
|
|
1526
|
+
mode: "subagent",
|
|
1527
|
+
model,
|
|
1528
|
+
prompt: agentPrompt,
|
|
1529
|
+
tools: agentTools,
|
|
1530
|
+
maxSteps,
|
|
1531
|
+
permission: agentPermissions
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
};
|
|
1535
|
+
console.error("Starting OpenCode server...");
|
|
1536
|
+
const { client: client3, server: server2 } = await createOpencode({
|
|
1537
|
+
hostname: "127.0.0.1",
|
|
1538
|
+
port: 0,
|
|
1539
|
+
config: opcodeConfig
|
|
1540
|
+
});
|
|
1541
|
+
console.error(`✓ OpenCode server started at ${server2.url}`);
|
|
1542
|
+
return { client: client3, server: server2 };
|
|
1543
|
+
}
|
|
1544
|
+
function setupEventMonitoring(client3) {
|
|
1545
|
+
console.error("Setting up event monitoring...");
|
|
1546
|
+
(async () => {
|
|
1547
|
+
try {
|
|
1548
|
+
const events = await client3.event.subscribe();
|
|
1549
|
+
for await (const event of events.stream) {
|
|
1550
|
+
if (event.type === "message.part.updated") {
|
|
1551
|
+
const part = event.properties.part;
|
|
1552
|
+
if (part.type === "tool") {
|
|
1553
|
+
const status = part.state.status;
|
|
1554
|
+
const toolName = part.tool;
|
|
1555
|
+
if (status === "running") {
|
|
1556
|
+
const input = JSON.stringify(part.state.input || {}, null, 2);
|
|
1557
|
+
console.error(`
|
|
1558
|
+
[TOOL] ${toolName} - RUNNING`);
|
|
1559
|
+
console.error(` Input: ${input}`);
|
|
1560
|
+
} else if (status === "completed") {
|
|
1561
|
+
const output = part.state.output?.slice(0, 200) || "(no output)";
|
|
1562
|
+
const duration = part.state.time?.end && part.state.time?.start ? `${((part.state.time.end - part.state.time.start) / 1000).toFixed(2)}s` : "unknown";
|
|
1563
|
+
console.error(`
|
|
1564
|
+
[TOOL] ${toolName} - COMPLETED (${duration})`);
|
|
1565
|
+
console.error(` Output preview: ${output}${part.state.output && part.state.output.length > 200 ? "..." : ""}`);
|
|
1566
|
+
} else if (status === "error") {
|
|
1567
|
+
console.error(`
|
|
1568
|
+
[TOOL] ${toolName} - ERROR`);
|
|
1569
|
+
console.error(` Error: ${part.state.error}`);
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
if (event.type === "session.status") {
|
|
1574
|
+
const status = event.properties.status;
|
|
1575
|
+
if (String(status) === "idle") {
|
|
1576
|
+
console.error(`
|
|
1577
|
+
[STATUS] Session idle`);
|
|
1578
|
+
} else if (String(status) === "busy") {
|
|
1579
|
+
console.error(`
|
|
1580
|
+
[STATUS] Session busy (processing)`);
|
|
1581
|
+
} else if (typeof status === "object" && "attempt" in status) {
|
|
1582
|
+
console.error(`
|
|
1583
|
+
[STATUS] Session retrying (attempt ${status.attempt})`);
|
|
1584
|
+
if ("message" in status)
|
|
1585
|
+
console.error(` Reason: ${status.message}`);
|
|
1586
|
+
if ("next" in status)
|
|
1587
|
+
console.error(` Next retry in: ${status.next}ms`);
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
if (event.type === "session.error") {
|
|
1591
|
+
const error = event.properties.error;
|
|
1592
|
+
console.error(`
|
|
1593
|
+
[ERROR] Session error:`, error);
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
} catch (err) {
|
|
1597
|
+
console.error("Event monitoring subscription error:", err);
|
|
1598
|
+
}
|
|
1599
|
+
})();
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
// src/agents/linear-agent.ts
|
|
1603
|
+
var AGENT_NAME = "linear-agent";
|
|
1604
|
+
var DEFAULT_MODEL = "claude-opus-4-5";
|
|
1605
|
+
var PROMPT_FILE = join(process.cwd(), ".github", "claude-parallel", "prompts", "consolidate-and-create-linear.md");
|
|
1606
|
+
async function main() {
|
|
1607
|
+
const requiredEnvVars = [
|
|
1608
|
+
"ANTHROPIC_PLAN",
|
|
1609
|
+
"OPENAI_PLAN",
|
|
1610
|
+
"GOOGLE_PLAN",
|
|
1611
|
+
"GITHUB_ISSUE_URL",
|
|
1612
|
+
"ISSUE_TITLE",
|
|
1613
|
+
"LINEAR_TEAM_ID",
|
|
1614
|
+
"LINEAR_API_KEY"
|
|
1615
|
+
];
|
|
1616
|
+
try {
|
|
1617
|
+
validateEnvVars(requiredEnvVars);
|
|
1618
|
+
} catch (error) {
|
|
1619
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
1620
|
+
console.error("");
|
|
1621
|
+
console.error("Usage: Set all required environment variables and run:");
|
|
1622
|
+
console.error(" bun run linear-agent.ts");
|
|
1623
|
+
process.exit(1);
|
|
1624
|
+
}
|
|
1625
|
+
const provider = "anthropic";
|
|
1626
|
+
const apiKey = getApiKey(provider);
|
|
1627
|
+
const anthropicPlan = process.env.ANTHROPIC_PLAN;
|
|
1628
|
+
const openaiPlan = process.env.OPENAI_PLAN;
|
|
1629
|
+
const googlePlan = process.env.GOOGLE_PLAN;
|
|
1630
|
+
const githubIssueUrl = process.env.GITHUB_ISSUE_URL;
|
|
1631
|
+
const issueTitle = process.env.ISSUE_TITLE;
|
|
1632
|
+
const linearTeamId = process.env.LINEAR_TEAM_ID;
|
|
1633
|
+
const linearProjectId = process.env.LINEAR_PROJECT_ID || "";
|
|
1634
|
+
const linearApiKey = process.env.LINEAR_API_KEY;
|
|
1635
|
+
const model = process.env.MODEL || DEFAULT_MODEL;
|
|
1636
|
+
console.error(`
|
|
1637
|
+
${"=".repeat(60)}`);
|
|
1638
|
+
console.error(`Linear Agent - Plan Consolidation`);
|
|
1639
|
+
console.error(`${"=".repeat(60)}`);
|
|
1640
|
+
console.error(`Provider: ${provider}`);
|
|
1641
|
+
console.error(`Model: ${model}`);
|
|
1642
|
+
console.error(`Issue: ${issueTitle}`);
|
|
1643
|
+
console.error(`GitHub URL: ${githubIssueUrl}`);
|
|
1644
|
+
console.error(`Linear Team: ${linearTeamId}`);
|
|
1645
|
+
console.error(`Linear Project: ${linearProjectId || "(none)"}`);
|
|
1646
|
+
console.error("");
|
|
1647
|
+
let promptTemplate;
|
|
1648
|
+
try {
|
|
1649
|
+
promptTemplate = await readFile(PROMPT_FILE, "utf-8");
|
|
1650
|
+
console.error(`✓ Loaded prompt template from ${PROMPT_FILE}`);
|
|
1651
|
+
} catch (error) {
|
|
1652
|
+
console.error(`✗ Failed to read prompt file: ${PROMPT_FILE}`);
|
|
1653
|
+
console.error("Please create consolidate-and-create-linear.md file in the prompts directory");
|
|
1654
|
+
process.exit(1);
|
|
1655
|
+
}
|
|
1656
|
+
const prompt = promptTemplate.replace(/\{\{ANTHROPIC_PLAN\}\}/g, anthropicPlan).replace(/\{\{OPENAI_PLAN\}\}/g, openaiPlan).replace(/\{\{GOOGLE_PLAN\}\}/g, googlePlan).replace(/\{\{GITHUB_ISSUE_URL\}\}/g, githubIssueUrl).replace(/\{\{ISSUE_TITLE\}\}/g, issueTitle).replace(/\{\{LINEAR_TEAM_ID\}\}/g, linearTeamId).replace(/\{\{LINEAR_PROJECT_ID\}\}/g, linearProjectId);
|
|
1657
|
+
console.error(`✓ Filled prompt template with plans and context`);
|
|
1658
|
+
const { client: client3, server: server2 } = await createOpencodeServer2({
|
|
1659
|
+
provider,
|
|
1660
|
+
apiKey,
|
|
1661
|
+
model,
|
|
1662
|
+
agentName: AGENT_NAME,
|
|
1663
|
+
agentDescription: "Consolidate implementation plans and create Linear issues",
|
|
1664
|
+
agentPrompt: prompt,
|
|
1665
|
+
agentTools: {
|
|
1666
|
+
write: false,
|
|
1667
|
+
edit: false,
|
|
1668
|
+
bash: true,
|
|
1669
|
+
read: true,
|
|
1670
|
+
list: true,
|
|
1671
|
+
glob: true,
|
|
1672
|
+
grep: true,
|
|
1673
|
+
webfetch: true,
|
|
1674
|
+
...linearApiKey && { "mcp__linear__*": true }
|
|
1675
|
+
},
|
|
1676
|
+
agentPermissions: {
|
|
1677
|
+
edit: "deny",
|
|
1678
|
+
bash: "allow",
|
|
1679
|
+
webfetch: "allow",
|
|
1680
|
+
...linearApiKey && { "mcp__linear__*": "allow" }
|
|
1681
|
+
},
|
|
1682
|
+
maxSteps: 30,
|
|
1683
|
+
linearApiKey
|
|
1684
|
+
});
|
|
1685
|
+
setupEventMonitoring(client3);
|
|
1686
|
+
try {
|
|
1687
|
+
console.error(`Creating session...`);
|
|
1688
|
+
const sessionResponse = await client3.session.create({
|
|
1689
|
+
body: { title: `Plan consolidation: ${issueTitle}` }
|
|
1690
|
+
});
|
|
1691
|
+
if (!sessionResponse.data) {
|
|
1692
|
+
throw new Error("Failed to create session: no data in response");
|
|
1693
|
+
}
|
|
1694
|
+
const session = sessionResponse.data;
|
|
1695
|
+
console.error(`✓ Session created: ${session.id}`);
|
|
1696
|
+
console.error(`Consolidating plans and creating Linear issues with ${AGENT_NAME}...`);
|
|
1697
|
+
console.error(`This may take a few moments while the AI consolidates the plans...`);
|
|
1698
|
+
const promptResponse = await client3.session.prompt({
|
|
1699
|
+
path: { id: session.id },
|
|
1700
|
+
body: {
|
|
1701
|
+
model: {
|
|
1702
|
+
providerID: provider,
|
|
1703
|
+
modelID: model
|
|
1704
|
+
},
|
|
1705
|
+
agent: AGENT_NAME,
|
|
1706
|
+
parts: [{ type: "text", text: prompt }]
|
|
1707
|
+
}
|
|
1708
|
+
});
|
|
1709
|
+
if (!promptResponse.data) {
|
|
1710
|
+
throw new Error("Failed to get response: no data in response");
|
|
1711
|
+
}
|
|
1712
|
+
const responseInfo = promptResponse.data.info;
|
|
1713
|
+
if (responseInfo?.error) {
|
|
1714
|
+
const err = responseInfo.error;
|
|
1715
|
+
const errorName = err.name;
|
|
1716
|
+
const errorData = "data" in err ? err.data : {};
|
|
1717
|
+
const errorMessage = "message" in errorData ? errorData.message : JSON.stringify(errorData);
|
|
1718
|
+
throw new Error(`Provider error: ${errorName}: ${errorMessage}`);
|
|
1719
|
+
}
|
|
1720
|
+
const resultText = extractTextFromParts(promptResponse.data.parts);
|
|
1721
|
+
if (resultText.length === 0) {
|
|
1722
|
+
throw new Error("Empty response from linear agent");
|
|
1723
|
+
}
|
|
1724
|
+
console.error("");
|
|
1725
|
+
console.error(`${"=".repeat(60)}`);
|
|
1726
|
+
console.error(`SUCCESS!`);
|
|
1727
|
+
console.error(`${"=".repeat(60)}`);
|
|
1728
|
+
console.error(`Consolidated plan and Linear issues: ${resultText.length} characters`);
|
|
1729
|
+
console.error(`Session ID: ${session.id}`);
|
|
1730
|
+
console.error("");
|
|
1731
|
+
console.log(resultText);
|
|
1732
|
+
process.exit(0);
|
|
1733
|
+
} catch (error) {
|
|
1734
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1735
|
+
console.error("");
|
|
1736
|
+
console.error(`${"=".repeat(60)}`);
|
|
1737
|
+
console.error("ERROR!");
|
|
1738
|
+
console.error(`${"=".repeat(60)}`);
|
|
1739
|
+
console.error(`Error: ${errorMessage}`);
|
|
1740
|
+
if (error instanceof Error && error.stack) {
|
|
1741
|
+
console.error("Stack trace:", error.stack);
|
|
1742
|
+
}
|
|
1743
|
+
console.error("");
|
|
1744
|
+
process.exit(1);
|
|
1745
|
+
} finally {
|
|
1746
|
+
console.error("Shutting down OpenCode server...");
|
|
1747
|
+
server2.close();
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
main().catch((error) => {
|
|
1751
|
+
console.error("FATAL ERROR:", error);
|
|
1752
|
+
process.exit(1);
|
|
1753
|
+
});
|