@react-grab/opencode 0.0.68
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/LICENSE +21 -0
- package/README.md +142 -0
- package/dist/cli.cjs +123 -0
- package/dist/cli.js +120 -0
- package/dist/client.cjs +119 -0
- package/dist/client.global.js +4 -0
- package/dist/client.js +116 -0
- package/dist/server.cjs +3989 -0
- package/dist/server.js +3980 -0
- package/package.json +40 -0
package/dist/server.cjs
ADDED
|
@@ -0,0 +1,3989 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var net = require('net');
|
|
4
|
+
var child_process = require('child_process');
|
|
5
|
+
var http = require('http');
|
|
6
|
+
var http2 = require('http2');
|
|
7
|
+
var stream = require('stream');
|
|
8
|
+
var crypto = require('crypto');
|
|
9
|
+
var url = require('url');
|
|
10
|
+
|
|
11
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
|
|
14
|
+
var net__default = /*#__PURE__*/_interopDefault(net);
|
|
15
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
16
|
+
|
|
17
|
+
var __create = Object.create;
|
|
18
|
+
var __defProp = Object.defineProperty;
|
|
19
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
20
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
21
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
22
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
23
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
24
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
25
|
+
};
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
+
}
|
|
32
|
+
return to;
|
|
33
|
+
};
|
|
34
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
35
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
36
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
37
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
38
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
39
|
+
__defProp(target, "default", { value: mod, enumerable: true }) ,
|
|
40
|
+
mod
|
|
41
|
+
));
|
|
42
|
+
|
|
43
|
+
// ../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
|
|
44
|
+
var require_picocolors = __commonJS({
|
|
45
|
+
"../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js"(exports, module) {
|
|
46
|
+
var p = process || {};
|
|
47
|
+
var argv = p.argv || [];
|
|
48
|
+
var env = p.env || {};
|
|
49
|
+
var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
50
|
+
var formatter = (open, close, replace = open) => (input) => {
|
|
51
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
52
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
53
|
+
};
|
|
54
|
+
var replaceClose = (string, close, replace, index) => {
|
|
55
|
+
let result = "", cursor = 0;
|
|
56
|
+
do {
|
|
57
|
+
result += string.substring(cursor, index) + replace;
|
|
58
|
+
cursor = index + close.length;
|
|
59
|
+
index = string.indexOf(close, cursor);
|
|
60
|
+
} while (~index);
|
|
61
|
+
return result + string.substring(cursor);
|
|
62
|
+
};
|
|
63
|
+
var createColors = (enabled = isColorSupported) => {
|
|
64
|
+
let f = enabled ? formatter : () => String;
|
|
65
|
+
return {
|
|
66
|
+
isColorSupported: enabled,
|
|
67
|
+
reset: f("\x1B[0m", "\x1B[0m"),
|
|
68
|
+
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
69
|
+
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
70
|
+
italic: f("\x1B[3m", "\x1B[23m"),
|
|
71
|
+
underline: f("\x1B[4m", "\x1B[24m"),
|
|
72
|
+
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
73
|
+
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
74
|
+
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
75
|
+
black: f("\x1B[30m", "\x1B[39m"),
|
|
76
|
+
red: f("\x1B[31m", "\x1B[39m"),
|
|
77
|
+
green: f("\x1B[32m", "\x1B[39m"),
|
|
78
|
+
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
79
|
+
blue: f("\x1B[34m", "\x1B[39m"),
|
|
80
|
+
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
81
|
+
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
82
|
+
white: f("\x1B[37m", "\x1B[39m"),
|
|
83
|
+
gray: f("\x1B[90m", "\x1B[39m"),
|
|
84
|
+
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
85
|
+
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
86
|
+
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
87
|
+
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
88
|
+
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
89
|
+
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
90
|
+
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
91
|
+
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
92
|
+
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
93
|
+
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
94
|
+
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
95
|
+
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
96
|
+
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
97
|
+
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
98
|
+
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
99
|
+
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
100
|
+
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
101
|
+
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
102
|
+
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
103
|
+
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
104
|
+
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
105
|
+
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
106
|
+
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
107
|
+
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
module.exports = createColors();
|
|
111
|
+
module.exports.createColors = createColors;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// ../../node_modules/.pnpm/@opencode-ai+sdk@1.0.132/node_modules/@opencode-ai/sdk/dist/gen/core/serverSentEvents.gen.js
|
|
116
|
+
var createSseClient = ({ onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) => {
|
|
117
|
+
let lastEventId;
|
|
118
|
+
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
119
|
+
const createStream = async function* () {
|
|
120
|
+
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
121
|
+
let attempt = 0;
|
|
122
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
123
|
+
while (true) {
|
|
124
|
+
if (signal.aborted)
|
|
125
|
+
break;
|
|
126
|
+
attempt++;
|
|
127
|
+
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
128
|
+
if (lastEventId !== void 0) {
|
|
129
|
+
headers.set("Last-Event-ID", lastEventId);
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
const response = await fetch(url, { ...options, headers, signal });
|
|
133
|
+
if (!response.ok)
|
|
134
|
+
throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
135
|
+
if (!response.body)
|
|
136
|
+
throw new Error("No body in SSE response");
|
|
137
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
138
|
+
let buffer = "";
|
|
139
|
+
const abortHandler = () => {
|
|
140
|
+
try {
|
|
141
|
+
reader.cancel();
|
|
142
|
+
} catch {
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
signal.addEventListener("abort", abortHandler);
|
|
146
|
+
try {
|
|
147
|
+
while (true) {
|
|
148
|
+
const { done, value } = await reader.read();
|
|
149
|
+
if (done)
|
|
150
|
+
break;
|
|
151
|
+
buffer += value;
|
|
152
|
+
const chunks = buffer.split("\n\n");
|
|
153
|
+
buffer = chunks.pop() ?? "";
|
|
154
|
+
for (const chunk of chunks) {
|
|
155
|
+
const lines = chunk.split("\n");
|
|
156
|
+
const dataLines = [];
|
|
157
|
+
let eventName;
|
|
158
|
+
for (const line of lines) {
|
|
159
|
+
if (line.startsWith("data:")) {
|
|
160
|
+
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
161
|
+
} else if (line.startsWith("event:")) {
|
|
162
|
+
eventName = line.replace(/^event:\s*/, "");
|
|
163
|
+
} else if (line.startsWith("id:")) {
|
|
164
|
+
lastEventId = line.replace(/^id:\s*/, "");
|
|
165
|
+
} else if (line.startsWith("retry:")) {
|
|
166
|
+
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
167
|
+
if (!Number.isNaN(parsed)) {
|
|
168
|
+
retryDelay = parsed;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
let data;
|
|
173
|
+
let parsedJson = false;
|
|
174
|
+
if (dataLines.length) {
|
|
175
|
+
const rawData = dataLines.join("\n");
|
|
176
|
+
try {
|
|
177
|
+
data = JSON.parse(rawData);
|
|
178
|
+
parsedJson = true;
|
|
179
|
+
} catch {
|
|
180
|
+
data = rawData;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (parsedJson) {
|
|
184
|
+
if (responseValidator) {
|
|
185
|
+
await responseValidator(data);
|
|
186
|
+
}
|
|
187
|
+
if (responseTransformer) {
|
|
188
|
+
data = await responseTransformer(data);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
onSseEvent?.({
|
|
192
|
+
data,
|
|
193
|
+
event: eventName,
|
|
194
|
+
id: lastEventId,
|
|
195
|
+
retry: retryDelay
|
|
196
|
+
});
|
|
197
|
+
if (dataLines.length) {
|
|
198
|
+
yield data;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
} finally {
|
|
203
|
+
signal.removeEventListener("abort", abortHandler);
|
|
204
|
+
reader.releaseLock();
|
|
205
|
+
}
|
|
206
|
+
break;
|
|
207
|
+
} catch (error) {
|
|
208
|
+
onSseError?.(error);
|
|
209
|
+
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
|
|
213
|
+
await sleep(backoff);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
const stream2 = createStream();
|
|
218
|
+
return { stream: stream2 };
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
// ../../node_modules/.pnpm/@opencode-ai+sdk@1.0.132/node_modules/@opencode-ai/sdk/dist/gen/core/auth.gen.js
|
|
222
|
+
var getAuthToken = async (auth, callback) => {
|
|
223
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
224
|
+
if (!token) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (auth.scheme === "bearer") {
|
|
228
|
+
return `Bearer ${token}`;
|
|
229
|
+
}
|
|
230
|
+
if (auth.scheme === "basic") {
|
|
231
|
+
return `Basic ${btoa(token)}`;
|
|
232
|
+
}
|
|
233
|
+
return token;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
// ../../node_modules/.pnpm/@opencode-ai+sdk@1.0.132/node_modules/@opencode-ai/sdk/dist/gen/core/bodySerializer.gen.js
|
|
237
|
+
var jsonBodySerializer = {
|
|
238
|
+
bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
// ../../node_modules/.pnpm/@opencode-ai+sdk@1.0.132/node_modules/@opencode-ai/sdk/dist/gen/core/pathSerializer.gen.js
|
|
242
|
+
var separatorArrayExplode = (style) => {
|
|
243
|
+
switch (style) {
|
|
244
|
+
case "label":
|
|
245
|
+
return ".";
|
|
246
|
+
case "matrix":
|
|
247
|
+
return ";";
|
|
248
|
+
case "simple":
|
|
249
|
+
return ",";
|
|
250
|
+
default:
|
|
251
|
+
return "&";
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
var separatorArrayNoExplode = (style) => {
|
|
255
|
+
switch (style) {
|
|
256
|
+
case "form":
|
|
257
|
+
return ",";
|
|
258
|
+
case "pipeDelimited":
|
|
259
|
+
return "|";
|
|
260
|
+
case "spaceDelimited":
|
|
261
|
+
return "%20";
|
|
262
|
+
default:
|
|
263
|
+
return ",";
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
var separatorObjectExplode = (style) => {
|
|
267
|
+
switch (style) {
|
|
268
|
+
case "label":
|
|
269
|
+
return ".";
|
|
270
|
+
case "matrix":
|
|
271
|
+
return ";";
|
|
272
|
+
case "simple":
|
|
273
|
+
return ",";
|
|
274
|
+
default:
|
|
275
|
+
return "&";
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
var serializeArrayParam = ({ allowReserved, explode, name, style, value }) => {
|
|
279
|
+
if (!explode) {
|
|
280
|
+
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
281
|
+
switch (style) {
|
|
282
|
+
case "label":
|
|
283
|
+
return `.${joinedValues2}`;
|
|
284
|
+
case "matrix":
|
|
285
|
+
return `;${name}=${joinedValues2}`;
|
|
286
|
+
case "simple":
|
|
287
|
+
return joinedValues2;
|
|
288
|
+
default:
|
|
289
|
+
return `${name}=${joinedValues2}`;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const separator = separatorArrayExplode(style);
|
|
293
|
+
const joinedValues = value.map((v) => {
|
|
294
|
+
if (style === "label" || style === "simple") {
|
|
295
|
+
return allowReserved ? v : encodeURIComponent(v);
|
|
296
|
+
}
|
|
297
|
+
return serializePrimitiveParam({
|
|
298
|
+
allowReserved,
|
|
299
|
+
name,
|
|
300
|
+
value: v
|
|
301
|
+
});
|
|
302
|
+
}).join(separator);
|
|
303
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
304
|
+
};
|
|
305
|
+
var serializePrimitiveParam = ({ allowReserved, name, value }) => {
|
|
306
|
+
if (value === void 0 || value === null) {
|
|
307
|
+
return "";
|
|
308
|
+
}
|
|
309
|
+
if (typeof value === "object") {
|
|
310
|
+
throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");
|
|
311
|
+
}
|
|
312
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
313
|
+
};
|
|
314
|
+
var serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly }) => {
|
|
315
|
+
if (value instanceof Date) {
|
|
316
|
+
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
317
|
+
}
|
|
318
|
+
if (style !== "deepObject" && !explode) {
|
|
319
|
+
let values = [];
|
|
320
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
321
|
+
values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
|
|
322
|
+
});
|
|
323
|
+
const joinedValues2 = values.join(",");
|
|
324
|
+
switch (style) {
|
|
325
|
+
case "form":
|
|
326
|
+
return `${name}=${joinedValues2}`;
|
|
327
|
+
case "label":
|
|
328
|
+
return `.${joinedValues2}`;
|
|
329
|
+
case "matrix":
|
|
330
|
+
return `;${name}=${joinedValues2}`;
|
|
331
|
+
default:
|
|
332
|
+
return joinedValues2;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
const separator = separatorObjectExplode(style);
|
|
336
|
+
const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
|
|
337
|
+
allowReserved,
|
|
338
|
+
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
339
|
+
value: v
|
|
340
|
+
})).join(separator);
|
|
341
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
// ../../node_modules/.pnpm/@opencode-ai+sdk@1.0.132/node_modules/@opencode-ai/sdk/dist/gen/core/utils.gen.js
|
|
345
|
+
var PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
346
|
+
var defaultPathSerializer = ({ path, url: _url }) => {
|
|
347
|
+
let url = _url;
|
|
348
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
349
|
+
if (matches) {
|
|
350
|
+
for (const match2 of matches) {
|
|
351
|
+
let explode = false;
|
|
352
|
+
let name = match2.substring(1, match2.length - 1);
|
|
353
|
+
let style = "simple";
|
|
354
|
+
if (name.endsWith("*")) {
|
|
355
|
+
explode = true;
|
|
356
|
+
name = name.substring(0, name.length - 1);
|
|
357
|
+
}
|
|
358
|
+
if (name.startsWith(".")) {
|
|
359
|
+
name = name.substring(1);
|
|
360
|
+
style = "label";
|
|
361
|
+
} else if (name.startsWith(";")) {
|
|
362
|
+
name = name.substring(1);
|
|
363
|
+
style = "matrix";
|
|
364
|
+
}
|
|
365
|
+
const value = path[name];
|
|
366
|
+
if (value === void 0 || value === null) {
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (Array.isArray(value)) {
|
|
370
|
+
url = url.replace(match2, serializeArrayParam({ explode, name, style, value }));
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if (typeof value === "object") {
|
|
374
|
+
url = url.replace(match2, serializeObjectParam({
|
|
375
|
+
explode,
|
|
376
|
+
name,
|
|
377
|
+
style,
|
|
378
|
+
value,
|
|
379
|
+
valueOnly: true
|
|
380
|
+
}));
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
if (style === "matrix") {
|
|
384
|
+
url = url.replace(match2, `;${serializePrimitiveParam({
|
|
385
|
+
name,
|
|
386
|
+
value
|
|
387
|
+
})}`);
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
|
|
391
|
+
url = url.replace(match2, replaceValue);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return url;
|
|
395
|
+
};
|
|
396
|
+
var getUrl = ({ baseUrl, path, query, querySerializer, url: _url }) => {
|
|
397
|
+
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
398
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
399
|
+
if (path) {
|
|
400
|
+
url = defaultPathSerializer({ path, url });
|
|
401
|
+
}
|
|
402
|
+
let search = query ? querySerializer(query) : "";
|
|
403
|
+
if (search.startsWith("?")) {
|
|
404
|
+
search = search.substring(1);
|
|
405
|
+
}
|
|
406
|
+
if (search) {
|
|
407
|
+
url += `?${search}`;
|
|
408
|
+
}
|
|
409
|
+
return url;
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
// ../../node_modules/.pnpm/@opencode-ai+sdk@1.0.132/node_modules/@opencode-ai/sdk/dist/gen/client/utils.gen.js
|
|
413
|
+
var createQuerySerializer = ({ allowReserved, array, object } = {}) => {
|
|
414
|
+
const querySerializer = (queryParams) => {
|
|
415
|
+
const search = [];
|
|
416
|
+
if (queryParams && typeof queryParams === "object") {
|
|
417
|
+
for (const name in queryParams) {
|
|
418
|
+
const value = queryParams[name];
|
|
419
|
+
if (value === void 0 || value === null) {
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
if (Array.isArray(value)) {
|
|
423
|
+
const serializedArray = serializeArrayParam({
|
|
424
|
+
allowReserved,
|
|
425
|
+
explode: true,
|
|
426
|
+
name,
|
|
427
|
+
style: "form",
|
|
428
|
+
value,
|
|
429
|
+
...array
|
|
430
|
+
});
|
|
431
|
+
if (serializedArray)
|
|
432
|
+
search.push(serializedArray);
|
|
433
|
+
} else if (typeof value === "object") {
|
|
434
|
+
const serializedObject = serializeObjectParam({
|
|
435
|
+
allowReserved,
|
|
436
|
+
explode: true,
|
|
437
|
+
name,
|
|
438
|
+
style: "deepObject",
|
|
439
|
+
value,
|
|
440
|
+
...object
|
|
441
|
+
});
|
|
442
|
+
if (serializedObject)
|
|
443
|
+
search.push(serializedObject);
|
|
444
|
+
} else {
|
|
445
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
446
|
+
allowReserved,
|
|
447
|
+
name,
|
|
448
|
+
value
|
|
449
|
+
});
|
|
450
|
+
if (serializedPrimitive)
|
|
451
|
+
search.push(serializedPrimitive);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
return search.join("&");
|
|
456
|
+
};
|
|
457
|
+
return querySerializer;
|
|
458
|
+
};
|
|
459
|
+
var getParseAs = (contentType) => {
|
|
460
|
+
if (!contentType) {
|
|
461
|
+
return "stream";
|
|
462
|
+
}
|
|
463
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
464
|
+
if (!cleanContent) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
468
|
+
return "json";
|
|
469
|
+
}
|
|
470
|
+
if (cleanContent === "multipart/form-data") {
|
|
471
|
+
return "formData";
|
|
472
|
+
}
|
|
473
|
+
if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
|
|
474
|
+
return "blob";
|
|
475
|
+
}
|
|
476
|
+
if (cleanContent.startsWith("text/")) {
|
|
477
|
+
return "text";
|
|
478
|
+
}
|
|
479
|
+
return;
|
|
480
|
+
};
|
|
481
|
+
var checkForExistence = (options, name) => {
|
|
482
|
+
if (!name) {
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
|
486
|
+
return true;
|
|
487
|
+
}
|
|
488
|
+
return false;
|
|
489
|
+
};
|
|
490
|
+
var setAuthParams = async ({ security, ...options }) => {
|
|
491
|
+
for (const auth of security) {
|
|
492
|
+
if (checkForExistence(options, auth.name)) {
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
const token = await getAuthToken(auth, options.auth);
|
|
496
|
+
if (!token) {
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
const name = auth.name ?? "Authorization";
|
|
500
|
+
switch (auth.in) {
|
|
501
|
+
case "query":
|
|
502
|
+
if (!options.query) {
|
|
503
|
+
options.query = {};
|
|
504
|
+
}
|
|
505
|
+
options.query[name] = token;
|
|
506
|
+
break;
|
|
507
|
+
case "cookie":
|
|
508
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
509
|
+
break;
|
|
510
|
+
case "header":
|
|
511
|
+
default:
|
|
512
|
+
options.headers.set(name, token);
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
var buildUrl = (options) => getUrl({
|
|
518
|
+
baseUrl: options.baseUrl,
|
|
519
|
+
path: options.path,
|
|
520
|
+
query: options.query,
|
|
521
|
+
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
522
|
+
url: options.url
|
|
523
|
+
});
|
|
524
|
+
var mergeConfigs = (a, b) => {
|
|
525
|
+
const config = { ...a, ...b };
|
|
526
|
+
if (config.baseUrl?.endsWith("/")) {
|
|
527
|
+
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
528
|
+
}
|
|
529
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
530
|
+
return config;
|
|
531
|
+
};
|
|
532
|
+
var mergeHeaders = (...headers) => {
|
|
533
|
+
const mergedHeaders = new Headers();
|
|
534
|
+
for (const header of headers) {
|
|
535
|
+
if (!header || typeof header !== "object") {
|
|
536
|
+
continue;
|
|
537
|
+
}
|
|
538
|
+
const iterator = header instanceof Headers ? header.entries() : Object.entries(header);
|
|
539
|
+
for (const [key, value] of iterator) {
|
|
540
|
+
if (value === null) {
|
|
541
|
+
mergedHeaders.delete(key);
|
|
542
|
+
} else if (Array.isArray(value)) {
|
|
543
|
+
for (const v of value) {
|
|
544
|
+
mergedHeaders.append(key, v);
|
|
545
|
+
}
|
|
546
|
+
} else if (value !== void 0) {
|
|
547
|
+
mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
return mergedHeaders;
|
|
552
|
+
};
|
|
553
|
+
var Interceptors = class {
|
|
554
|
+
_fns;
|
|
555
|
+
constructor() {
|
|
556
|
+
this._fns = [];
|
|
557
|
+
}
|
|
558
|
+
clear() {
|
|
559
|
+
this._fns = [];
|
|
560
|
+
}
|
|
561
|
+
getInterceptorIndex(id) {
|
|
562
|
+
if (typeof id === "number") {
|
|
563
|
+
return this._fns[id] ? id : -1;
|
|
564
|
+
} else {
|
|
565
|
+
return this._fns.indexOf(id);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
exists(id) {
|
|
569
|
+
const index = this.getInterceptorIndex(id);
|
|
570
|
+
return !!this._fns[index];
|
|
571
|
+
}
|
|
572
|
+
eject(id) {
|
|
573
|
+
const index = this.getInterceptorIndex(id);
|
|
574
|
+
if (this._fns[index]) {
|
|
575
|
+
this._fns[index] = null;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
update(id, fn) {
|
|
579
|
+
const index = this.getInterceptorIndex(id);
|
|
580
|
+
if (this._fns[index]) {
|
|
581
|
+
this._fns[index] = fn;
|
|
582
|
+
return id;
|
|
583
|
+
} else {
|
|
584
|
+
return false;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
use(fn) {
|
|
588
|
+
this._fns = [...this._fns, fn];
|
|
589
|
+
return this._fns.length - 1;
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
var createInterceptors = () => ({
|
|
593
|
+
error: new Interceptors(),
|
|
594
|
+
request: new Interceptors(),
|
|
595
|
+
response: new Interceptors()
|
|
596
|
+
});
|
|
597
|
+
var defaultQuerySerializer = createQuerySerializer({
|
|
598
|
+
allowReserved: false,
|
|
599
|
+
array: {
|
|
600
|
+
explode: true,
|
|
601
|
+
style: "form"
|
|
602
|
+
},
|
|
603
|
+
object: {
|
|
604
|
+
explode: true,
|
|
605
|
+
style: "deepObject"
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
var defaultHeaders = {
|
|
609
|
+
"Content-Type": "application/json"
|
|
610
|
+
};
|
|
611
|
+
var createConfig = (override = {}) => ({
|
|
612
|
+
...jsonBodySerializer,
|
|
613
|
+
headers: defaultHeaders,
|
|
614
|
+
parseAs: "auto",
|
|
615
|
+
querySerializer: defaultQuerySerializer,
|
|
616
|
+
...override
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
// ../../node_modules/.pnpm/@opencode-ai+sdk@1.0.132/node_modules/@opencode-ai/sdk/dist/gen/client/client.gen.js
|
|
620
|
+
var createClient = (config = {}) => {
|
|
621
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
622
|
+
const getConfig = () => ({ ..._config });
|
|
623
|
+
const setConfig = (config2) => {
|
|
624
|
+
_config = mergeConfigs(_config, config2);
|
|
625
|
+
return getConfig();
|
|
626
|
+
};
|
|
627
|
+
const interceptors = createInterceptors();
|
|
628
|
+
const beforeRequest = async (options) => {
|
|
629
|
+
const opts = {
|
|
630
|
+
..._config,
|
|
631
|
+
...options,
|
|
632
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
633
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
634
|
+
serializedBody: void 0
|
|
635
|
+
};
|
|
636
|
+
if (opts.security) {
|
|
637
|
+
await setAuthParams({
|
|
638
|
+
...opts,
|
|
639
|
+
security: opts.security
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
if (opts.requestValidator) {
|
|
643
|
+
await opts.requestValidator(opts);
|
|
644
|
+
}
|
|
645
|
+
if (opts.body && opts.bodySerializer) {
|
|
646
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
647
|
+
}
|
|
648
|
+
if (opts.serializedBody === void 0 || opts.serializedBody === "") {
|
|
649
|
+
opts.headers.delete("Content-Type");
|
|
650
|
+
}
|
|
651
|
+
const url = buildUrl(opts);
|
|
652
|
+
return { opts, url };
|
|
653
|
+
};
|
|
654
|
+
const request = async (options) => {
|
|
655
|
+
const { opts, url } = await beforeRequest(options);
|
|
656
|
+
const requestInit = {
|
|
657
|
+
redirect: "follow",
|
|
658
|
+
...opts,
|
|
659
|
+
body: opts.serializedBody
|
|
660
|
+
};
|
|
661
|
+
let request2 = new Request(url, requestInit);
|
|
662
|
+
for (const fn of interceptors.request._fns) {
|
|
663
|
+
if (fn) {
|
|
664
|
+
request2 = await fn(request2, opts);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
const _fetch = opts.fetch;
|
|
668
|
+
let response = await _fetch(request2);
|
|
669
|
+
for (const fn of interceptors.response._fns) {
|
|
670
|
+
if (fn) {
|
|
671
|
+
response = await fn(response, request2, opts);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
const result = {
|
|
675
|
+
request: request2,
|
|
676
|
+
response
|
|
677
|
+
};
|
|
678
|
+
if (response.ok) {
|
|
679
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
680
|
+
return opts.responseStyle === "data" ? {} : {
|
|
681
|
+
data: {},
|
|
682
|
+
...result
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
686
|
+
let data;
|
|
687
|
+
switch (parseAs) {
|
|
688
|
+
case "arrayBuffer":
|
|
689
|
+
case "blob":
|
|
690
|
+
case "formData":
|
|
691
|
+
case "json":
|
|
692
|
+
case "text":
|
|
693
|
+
data = await response[parseAs]();
|
|
694
|
+
break;
|
|
695
|
+
case "stream":
|
|
696
|
+
return opts.responseStyle === "data" ? response.body : {
|
|
697
|
+
data: response.body,
|
|
698
|
+
...result
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
if (parseAs === "json") {
|
|
702
|
+
if (opts.responseValidator) {
|
|
703
|
+
await opts.responseValidator(data);
|
|
704
|
+
}
|
|
705
|
+
if (opts.responseTransformer) {
|
|
706
|
+
data = await opts.responseTransformer(data);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
return opts.responseStyle === "data" ? data : {
|
|
710
|
+
data,
|
|
711
|
+
...result
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
const textError = await response.text();
|
|
715
|
+
let jsonError;
|
|
716
|
+
try {
|
|
717
|
+
jsonError = JSON.parse(textError);
|
|
718
|
+
} catch {
|
|
719
|
+
}
|
|
720
|
+
const error = jsonError ?? textError;
|
|
721
|
+
let finalError = error;
|
|
722
|
+
for (const fn of interceptors.error._fns) {
|
|
723
|
+
if (fn) {
|
|
724
|
+
finalError = await fn(error, response, request2, opts);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
finalError = finalError || {};
|
|
728
|
+
if (opts.throwOnError) {
|
|
729
|
+
throw finalError;
|
|
730
|
+
}
|
|
731
|
+
return opts.responseStyle === "data" ? void 0 : {
|
|
732
|
+
error: finalError,
|
|
733
|
+
...result
|
|
734
|
+
};
|
|
735
|
+
};
|
|
736
|
+
const makeMethod = (method) => {
|
|
737
|
+
const fn = (options) => request({ ...options, method });
|
|
738
|
+
fn.sse = async (options) => {
|
|
739
|
+
const { opts, url } = await beforeRequest(options);
|
|
740
|
+
return createSseClient({
|
|
741
|
+
...opts,
|
|
742
|
+
body: opts.body,
|
|
743
|
+
headers: opts.headers,
|
|
744
|
+
method,
|
|
745
|
+
url
|
|
746
|
+
});
|
|
747
|
+
};
|
|
748
|
+
return fn;
|
|
749
|
+
};
|
|
750
|
+
return {
|
|
751
|
+
buildUrl,
|
|
752
|
+
connect: makeMethod("CONNECT"),
|
|
753
|
+
delete: makeMethod("DELETE"),
|
|
754
|
+
get: makeMethod("GET"),
|
|
755
|
+
getConfig,
|
|
756
|
+
head: makeMethod("HEAD"),
|
|
757
|
+
interceptors,
|
|
758
|
+
options: makeMethod("OPTIONS"),
|
|
759
|
+
patch: makeMethod("PATCH"),
|
|
760
|
+
post: makeMethod("POST"),
|
|
761
|
+
put: makeMethod("PUT"),
|
|
762
|
+
request,
|
|
763
|
+
setConfig,
|
|
764
|
+
trace: makeMethod("TRACE")
|
|
765
|
+
};
|
|
766
|
+
};
|
|
767
|
+
|
|
768
|
+
// ../../node_modules/.pnpm/@opencode-ai+sdk@1.0.132/node_modules/@opencode-ai/sdk/dist/gen/client.gen.js
|
|
769
|
+
var client = createClient(createConfig({
|
|
770
|
+
baseUrl: "http://localhost:4096"
|
|
771
|
+
}));
|
|
772
|
+
|
|
773
|
+
// ../../node_modules/.pnpm/@opencode-ai+sdk@1.0.132/node_modules/@opencode-ai/sdk/dist/gen/sdk.gen.js
|
|
774
|
+
var _HeyApiClient = class {
|
|
775
|
+
_client = client;
|
|
776
|
+
constructor(args) {
|
|
777
|
+
if (args?.client) {
|
|
778
|
+
this._client = args.client;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
var Global = class extends _HeyApiClient {
|
|
783
|
+
/**
|
|
784
|
+
* Get events
|
|
785
|
+
*/
|
|
786
|
+
event(options) {
|
|
787
|
+
return (options?.client ?? this._client).get.sse({
|
|
788
|
+
url: "/global/event",
|
|
789
|
+
...options
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
var Project = class extends _HeyApiClient {
|
|
794
|
+
/**
|
|
795
|
+
* List all projects
|
|
796
|
+
*/
|
|
797
|
+
list(options) {
|
|
798
|
+
return (options?.client ?? this._client).get({
|
|
799
|
+
url: "/project",
|
|
800
|
+
...options
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Get the current project
|
|
805
|
+
*/
|
|
806
|
+
current(options) {
|
|
807
|
+
return (options?.client ?? this._client).get({
|
|
808
|
+
url: "/project/current",
|
|
809
|
+
...options
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
var Config = class extends _HeyApiClient {
|
|
814
|
+
/**
|
|
815
|
+
* Get config info
|
|
816
|
+
*/
|
|
817
|
+
get(options) {
|
|
818
|
+
return (options?.client ?? this._client).get({
|
|
819
|
+
url: "/config",
|
|
820
|
+
...options
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Update config
|
|
825
|
+
*/
|
|
826
|
+
update(options) {
|
|
827
|
+
return (options?.client ?? this._client).patch({
|
|
828
|
+
url: "/config",
|
|
829
|
+
...options,
|
|
830
|
+
headers: {
|
|
831
|
+
"Content-Type": "application/json",
|
|
832
|
+
...options?.headers
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* List all providers
|
|
838
|
+
*/
|
|
839
|
+
providers(options) {
|
|
840
|
+
return (options?.client ?? this._client).get({
|
|
841
|
+
url: "/config/providers",
|
|
842
|
+
...options
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
var Tool = class extends _HeyApiClient {
|
|
847
|
+
/**
|
|
848
|
+
* List all tool IDs (including built-in and dynamically registered)
|
|
849
|
+
*/
|
|
850
|
+
ids(options) {
|
|
851
|
+
return (options?.client ?? this._client).get({
|
|
852
|
+
url: "/experimental/tool/ids",
|
|
853
|
+
...options
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* List tools with JSON schema parameters for a provider/model
|
|
858
|
+
*/
|
|
859
|
+
list(options) {
|
|
860
|
+
return (options.client ?? this._client).get({
|
|
861
|
+
url: "/experimental/tool",
|
|
862
|
+
...options
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
var Instance = class extends _HeyApiClient {
|
|
867
|
+
/**
|
|
868
|
+
* Dispose the current instance
|
|
869
|
+
*/
|
|
870
|
+
dispose(options) {
|
|
871
|
+
return (options?.client ?? this._client).post({
|
|
872
|
+
url: "/instance/dispose",
|
|
873
|
+
...options
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
};
|
|
877
|
+
var Path = class extends _HeyApiClient {
|
|
878
|
+
/**
|
|
879
|
+
* Get the current path
|
|
880
|
+
*/
|
|
881
|
+
get(options) {
|
|
882
|
+
return (options?.client ?? this._client).get({
|
|
883
|
+
url: "/path",
|
|
884
|
+
...options
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
};
|
|
888
|
+
var Vcs = class extends _HeyApiClient {
|
|
889
|
+
/**
|
|
890
|
+
* Get VCS info for the current instance
|
|
891
|
+
*/
|
|
892
|
+
get(options) {
|
|
893
|
+
return (options?.client ?? this._client).get({
|
|
894
|
+
url: "/vcs",
|
|
895
|
+
...options
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
var Session = class extends _HeyApiClient {
|
|
900
|
+
/**
|
|
901
|
+
* List all sessions
|
|
902
|
+
*/
|
|
903
|
+
list(options) {
|
|
904
|
+
return (options?.client ?? this._client).get({
|
|
905
|
+
url: "/session",
|
|
906
|
+
...options
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* Create a new session
|
|
911
|
+
*/
|
|
912
|
+
create(options) {
|
|
913
|
+
return (options?.client ?? this._client).post({
|
|
914
|
+
url: "/session",
|
|
915
|
+
...options,
|
|
916
|
+
headers: {
|
|
917
|
+
"Content-Type": "application/json",
|
|
918
|
+
...options?.headers
|
|
919
|
+
}
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Get session status
|
|
924
|
+
*/
|
|
925
|
+
status(options) {
|
|
926
|
+
return (options?.client ?? this._client).get({
|
|
927
|
+
url: "/session/status",
|
|
928
|
+
...options
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Delete a session and all its data
|
|
933
|
+
*/
|
|
934
|
+
delete(options) {
|
|
935
|
+
return (options.client ?? this._client).delete({
|
|
936
|
+
url: "/session/{id}",
|
|
937
|
+
...options
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* Get session
|
|
942
|
+
*/
|
|
943
|
+
get(options) {
|
|
944
|
+
return (options.client ?? this._client).get({
|
|
945
|
+
url: "/session/{id}",
|
|
946
|
+
...options
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Update session properties
|
|
951
|
+
*/
|
|
952
|
+
update(options) {
|
|
953
|
+
return (options.client ?? this._client).patch({
|
|
954
|
+
url: "/session/{id}",
|
|
955
|
+
...options,
|
|
956
|
+
headers: {
|
|
957
|
+
"Content-Type": "application/json",
|
|
958
|
+
...options.headers
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* Get a session's children
|
|
964
|
+
*/
|
|
965
|
+
children(options) {
|
|
966
|
+
return (options.client ?? this._client).get({
|
|
967
|
+
url: "/session/{id}/children",
|
|
968
|
+
...options
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* Get the todo list for a session
|
|
973
|
+
*/
|
|
974
|
+
todo(options) {
|
|
975
|
+
return (options.client ?? this._client).get({
|
|
976
|
+
url: "/session/{id}/todo",
|
|
977
|
+
...options
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
/**
|
|
981
|
+
* Analyze the app and create an AGENTS.md file
|
|
982
|
+
*/
|
|
983
|
+
init(options) {
|
|
984
|
+
return (options.client ?? this._client).post({
|
|
985
|
+
url: "/session/{id}/init",
|
|
986
|
+
...options,
|
|
987
|
+
headers: {
|
|
988
|
+
"Content-Type": "application/json",
|
|
989
|
+
...options.headers
|
|
990
|
+
}
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
/**
|
|
994
|
+
* Fork an existing session at a specific message
|
|
995
|
+
*/
|
|
996
|
+
fork(options) {
|
|
997
|
+
return (options.client ?? this._client).post({
|
|
998
|
+
url: "/session/{id}/fork",
|
|
999
|
+
...options,
|
|
1000
|
+
headers: {
|
|
1001
|
+
"Content-Type": "application/json",
|
|
1002
|
+
...options.headers
|
|
1003
|
+
}
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Abort a session
|
|
1008
|
+
*/
|
|
1009
|
+
abort(options) {
|
|
1010
|
+
return (options.client ?? this._client).post({
|
|
1011
|
+
url: "/session/{id}/abort",
|
|
1012
|
+
...options
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Unshare the session
|
|
1017
|
+
*/
|
|
1018
|
+
unshare(options) {
|
|
1019
|
+
return (options.client ?? this._client).delete({
|
|
1020
|
+
url: "/session/{id}/share",
|
|
1021
|
+
...options
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Share a session
|
|
1026
|
+
*/
|
|
1027
|
+
share(options) {
|
|
1028
|
+
return (options.client ?? this._client).post({
|
|
1029
|
+
url: "/session/{id}/share",
|
|
1030
|
+
...options
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
/**
|
|
1034
|
+
* Get the diff for this session
|
|
1035
|
+
*/
|
|
1036
|
+
diff(options) {
|
|
1037
|
+
return (options.client ?? this._client).get({
|
|
1038
|
+
url: "/session/{id}/diff",
|
|
1039
|
+
...options
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Summarize the session
|
|
1044
|
+
*/
|
|
1045
|
+
summarize(options) {
|
|
1046
|
+
return (options.client ?? this._client).post({
|
|
1047
|
+
url: "/session/{id}/summarize",
|
|
1048
|
+
...options,
|
|
1049
|
+
headers: {
|
|
1050
|
+
"Content-Type": "application/json",
|
|
1051
|
+
...options.headers
|
|
1052
|
+
}
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
/**
|
|
1056
|
+
* List messages for a session
|
|
1057
|
+
*/
|
|
1058
|
+
messages(options) {
|
|
1059
|
+
return (options.client ?? this._client).get({
|
|
1060
|
+
url: "/session/{id}/message",
|
|
1061
|
+
...options
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* Create and send a new message to a session
|
|
1066
|
+
*/
|
|
1067
|
+
prompt(options) {
|
|
1068
|
+
return (options.client ?? this._client).post({
|
|
1069
|
+
url: "/session/{id}/message",
|
|
1070
|
+
...options,
|
|
1071
|
+
headers: {
|
|
1072
|
+
"Content-Type": "application/json",
|
|
1073
|
+
...options.headers
|
|
1074
|
+
}
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Get a message from a session
|
|
1079
|
+
*/
|
|
1080
|
+
message(options) {
|
|
1081
|
+
return (options.client ?? this._client).get({
|
|
1082
|
+
url: "/session/{id}/message/{messageID}",
|
|
1083
|
+
...options
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* Create and send a new message to a session, start if needed and return immediately
|
|
1088
|
+
*/
|
|
1089
|
+
promptAsync(options) {
|
|
1090
|
+
return (options.client ?? this._client).post({
|
|
1091
|
+
url: "/session/{id}/prompt_async",
|
|
1092
|
+
...options,
|
|
1093
|
+
headers: {
|
|
1094
|
+
"Content-Type": "application/json",
|
|
1095
|
+
...options.headers
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Send a new command to a session
|
|
1101
|
+
*/
|
|
1102
|
+
command(options) {
|
|
1103
|
+
return (options.client ?? this._client).post({
|
|
1104
|
+
url: "/session/{id}/command",
|
|
1105
|
+
...options,
|
|
1106
|
+
headers: {
|
|
1107
|
+
"Content-Type": "application/json",
|
|
1108
|
+
...options.headers
|
|
1109
|
+
}
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
/**
|
|
1113
|
+
* Run a shell command
|
|
1114
|
+
*/
|
|
1115
|
+
shell(options) {
|
|
1116
|
+
return (options.client ?? this._client).post({
|
|
1117
|
+
url: "/session/{id}/shell",
|
|
1118
|
+
...options,
|
|
1119
|
+
headers: {
|
|
1120
|
+
"Content-Type": "application/json",
|
|
1121
|
+
...options.headers
|
|
1122
|
+
}
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
* Revert a message
|
|
1127
|
+
*/
|
|
1128
|
+
revert(options) {
|
|
1129
|
+
return (options.client ?? this._client).post({
|
|
1130
|
+
url: "/session/{id}/revert",
|
|
1131
|
+
...options,
|
|
1132
|
+
headers: {
|
|
1133
|
+
"Content-Type": "application/json",
|
|
1134
|
+
...options.headers
|
|
1135
|
+
}
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
/**
|
|
1139
|
+
* Restore all reverted messages
|
|
1140
|
+
*/
|
|
1141
|
+
unrevert(options) {
|
|
1142
|
+
return (options.client ?? this._client).post({
|
|
1143
|
+
url: "/session/{id}/unrevert",
|
|
1144
|
+
...options
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
};
|
|
1148
|
+
var Command = class extends _HeyApiClient {
|
|
1149
|
+
/**
|
|
1150
|
+
* List all commands
|
|
1151
|
+
*/
|
|
1152
|
+
list(options) {
|
|
1153
|
+
return (options?.client ?? this._client).get({
|
|
1154
|
+
url: "/command",
|
|
1155
|
+
...options
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
};
|
|
1159
|
+
var Oauth = class extends _HeyApiClient {
|
|
1160
|
+
/**
|
|
1161
|
+
* Authorize a provider using OAuth
|
|
1162
|
+
*/
|
|
1163
|
+
authorize(options) {
|
|
1164
|
+
return (options.client ?? this._client).post({
|
|
1165
|
+
url: "/provider/{id}/oauth/authorize",
|
|
1166
|
+
...options,
|
|
1167
|
+
headers: {
|
|
1168
|
+
"Content-Type": "application/json",
|
|
1169
|
+
...options.headers
|
|
1170
|
+
}
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
/**
|
|
1174
|
+
* Handle OAuth callback for a provider
|
|
1175
|
+
*/
|
|
1176
|
+
callback(options) {
|
|
1177
|
+
return (options.client ?? this._client).post({
|
|
1178
|
+
url: "/provider/{id}/oauth/callback",
|
|
1179
|
+
...options,
|
|
1180
|
+
headers: {
|
|
1181
|
+
"Content-Type": "application/json",
|
|
1182
|
+
...options.headers
|
|
1183
|
+
}
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
};
|
|
1187
|
+
var Provider = class extends _HeyApiClient {
|
|
1188
|
+
/**
|
|
1189
|
+
* List all providers
|
|
1190
|
+
*/
|
|
1191
|
+
list(options) {
|
|
1192
|
+
return (options?.client ?? this._client).get({
|
|
1193
|
+
url: "/provider",
|
|
1194
|
+
...options
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
/**
|
|
1198
|
+
* Get provider authentication methods
|
|
1199
|
+
*/
|
|
1200
|
+
auth(options) {
|
|
1201
|
+
return (options?.client ?? this._client).get({
|
|
1202
|
+
url: "/provider/auth",
|
|
1203
|
+
...options
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
oauth = new Oauth({ client: this._client });
|
|
1207
|
+
};
|
|
1208
|
+
var Find = class extends _HeyApiClient {
|
|
1209
|
+
/**
|
|
1210
|
+
* Find text in files
|
|
1211
|
+
*/
|
|
1212
|
+
text(options) {
|
|
1213
|
+
return (options.client ?? this._client).get({
|
|
1214
|
+
url: "/find",
|
|
1215
|
+
...options
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* Find files
|
|
1220
|
+
*/
|
|
1221
|
+
files(options) {
|
|
1222
|
+
return (options.client ?? this._client).get({
|
|
1223
|
+
url: "/find/file",
|
|
1224
|
+
...options
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Find workspace symbols
|
|
1229
|
+
*/
|
|
1230
|
+
symbols(options) {
|
|
1231
|
+
return (options.client ?? this._client).get({
|
|
1232
|
+
url: "/find/symbol",
|
|
1233
|
+
...options
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
};
|
|
1237
|
+
var File2 = class extends _HeyApiClient {
|
|
1238
|
+
/**
|
|
1239
|
+
* List files and directories
|
|
1240
|
+
*/
|
|
1241
|
+
list(options) {
|
|
1242
|
+
return (options.client ?? this._client).get({
|
|
1243
|
+
url: "/file",
|
|
1244
|
+
...options
|
|
1245
|
+
});
|
|
1246
|
+
}
|
|
1247
|
+
/**
|
|
1248
|
+
* Read a file
|
|
1249
|
+
*/
|
|
1250
|
+
read(options) {
|
|
1251
|
+
return (options.client ?? this._client).get({
|
|
1252
|
+
url: "/file/content",
|
|
1253
|
+
...options
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
/**
|
|
1257
|
+
* Get file status
|
|
1258
|
+
*/
|
|
1259
|
+
status(options) {
|
|
1260
|
+
return (options?.client ?? this._client).get({
|
|
1261
|
+
url: "/file/status",
|
|
1262
|
+
...options
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
};
|
|
1266
|
+
var App = class extends _HeyApiClient {
|
|
1267
|
+
/**
|
|
1268
|
+
* Write a log entry to the server logs
|
|
1269
|
+
*/
|
|
1270
|
+
log(options) {
|
|
1271
|
+
return (options?.client ?? this._client).post({
|
|
1272
|
+
url: "/log",
|
|
1273
|
+
...options,
|
|
1274
|
+
headers: {
|
|
1275
|
+
"Content-Type": "application/json",
|
|
1276
|
+
...options?.headers
|
|
1277
|
+
}
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
/**
|
|
1281
|
+
* List all agents
|
|
1282
|
+
*/
|
|
1283
|
+
agents(options) {
|
|
1284
|
+
return (options?.client ?? this._client).get({
|
|
1285
|
+
url: "/agent",
|
|
1286
|
+
...options
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
};
|
|
1290
|
+
var Mcp = class extends _HeyApiClient {
|
|
1291
|
+
/**
|
|
1292
|
+
* Get MCP server status
|
|
1293
|
+
*/
|
|
1294
|
+
status(options) {
|
|
1295
|
+
return (options?.client ?? this._client).get({
|
|
1296
|
+
url: "/mcp",
|
|
1297
|
+
...options
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
/**
|
|
1301
|
+
* Add MCP server dynamically
|
|
1302
|
+
*/
|
|
1303
|
+
add(options) {
|
|
1304
|
+
return (options?.client ?? this._client).post({
|
|
1305
|
+
url: "/mcp",
|
|
1306
|
+
...options,
|
|
1307
|
+
headers: {
|
|
1308
|
+
"Content-Type": "application/json",
|
|
1309
|
+
...options?.headers
|
|
1310
|
+
}
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
};
|
|
1314
|
+
var Lsp = class extends _HeyApiClient {
|
|
1315
|
+
/**
|
|
1316
|
+
* Get LSP server status
|
|
1317
|
+
*/
|
|
1318
|
+
status(options) {
|
|
1319
|
+
return (options?.client ?? this._client).get({
|
|
1320
|
+
url: "/lsp",
|
|
1321
|
+
...options
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
};
|
|
1325
|
+
var Formatter = class extends _HeyApiClient {
|
|
1326
|
+
/**
|
|
1327
|
+
* Get formatter status
|
|
1328
|
+
*/
|
|
1329
|
+
status(options) {
|
|
1330
|
+
return (options?.client ?? this._client).get({
|
|
1331
|
+
url: "/formatter",
|
|
1332
|
+
...options
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1335
|
+
};
|
|
1336
|
+
var Control = class extends _HeyApiClient {
|
|
1337
|
+
/**
|
|
1338
|
+
* Get the next TUI request from the queue
|
|
1339
|
+
*/
|
|
1340
|
+
next(options) {
|
|
1341
|
+
return (options?.client ?? this._client).get({
|
|
1342
|
+
url: "/tui/control/next",
|
|
1343
|
+
...options
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
/**
|
|
1347
|
+
* Submit a response to the TUI request queue
|
|
1348
|
+
*/
|
|
1349
|
+
response(options) {
|
|
1350
|
+
return (options?.client ?? this._client).post({
|
|
1351
|
+
url: "/tui/control/response",
|
|
1352
|
+
...options,
|
|
1353
|
+
headers: {
|
|
1354
|
+
"Content-Type": "application/json",
|
|
1355
|
+
...options?.headers
|
|
1356
|
+
}
|
|
1357
|
+
});
|
|
1358
|
+
}
|
|
1359
|
+
};
|
|
1360
|
+
var Tui = class extends _HeyApiClient {
|
|
1361
|
+
/**
|
|
1362
|
+
* Append prompt to the TUI
|
|
1363
|
+
*/
|
|
1364
|
+
appendPrompt(options) {
|
|
1365
|
+
return (options?.client ?? this._client).post({
|
|
1366
|
+
url: "/tui/append-prompt",
|
|
1367
|
+
...options,
|
|
1368
|
+
headers: {
|
|
1369
|
+
"Content-Type": "application/json",
|
|
1370
|
+
...options?.headers
|
|
1371
|
+
}
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* Open the help dialog
|
|
1376
|
+
*/
|
|
1377
|
+
openHelp(options) {
|
|
1378
|
+
return (options?.client ?? this._client).post({
|
|
1379
|
+
url: "/tui/open-help",
|
|
1380
|
+
...options
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
/**
|
|
1384
|
+
* Open the session dialog
|
|
1385
|
+
*/
|
|
1386
|
+
openSessions(options) {
|
|
1387
|
+
return (options?.client ?? this._client).post({
|
|
1388
|
+
url: "/tui/open-sessions",
|
|
1389
|
+
...options
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* Open the theme dialog
|
|
1394
|
+
*/
|
|
1395
|
+
openThemes(options) {
|
|
1396
|
+
return (options?.client ?? this._client).post({
|
|
1397
|
+
url: "/tui/open-themes",
|
|
1398
|
+
...options
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
/**
|
|
1402
|
+
* Open the model dialog
|
|
1403
|
+
*/
|
|
1404
|
+
openModels(options) {
|
|
1405
|
+
return (options?.client ?? this._client).post({
|
|
1406
|
+
url: "/tui/open-models",
|
|
1407
|
+
...options
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Submit the prompt
|
|
1412
|
+
*/
|
|
1413
|
+
submitPrompt(options) {
|
|
1414
|
+
return (options?.client ?? this._client).post({
|
|
1415
|
+
url: "/tui/submit-prompt",
|
|
1416
|
+
...options
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
/**
|
|
1420
|
+
* Clear the prompt
|
|
1421
|
+
*/
|
|
1422
|
+
clearPrompt(options) {
|
|
1423
|
+
return (options?.client ?? this._client).post({
|
|
1424
|
+
url: "/tui/clear-prompt",
|
|
1425
|
+
...options
|
|
1426
|
+
});
|
|
1427
|
+
}
|
|
1428
|
+
/**
|
|
1429
|
+
* Execute a TUI command (e.g. agent_cycle)
|
|
1430
|
+
*/
|
|
1431
|
+
executeCommand(options) {
|
|
1432
|
+
return (options?.client ?? this._client).post({
|
|
1433
|
+
url: "/tui/execute-command",
|
|
1434
|
+
...options,
|
|
1435
|
+
headers: {
|
|
1436
|
+
"Content-Type": "application/json",
|
|
1437
|
+
...options?.headers
|
|
1438
|
+
}
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
/**
|
|
1442
|
+
* Show a toast notification in the TUI
|
|
1443
|
+
*/
|
|
1444
|
+
showToast(options) {
|
|
1445
|
+
return (options?.client ?? this._client).post({
|
|
1446
|
+
url: "/tui/show-toast",
|
|
1447
|
+
...options,
|
|
1448
|
+
headers: {
|
|
1449
|
+
"Content-Type": "application/json",
|
|
1450
|
+
...options?.headers
|
|
1451
|
+
}
|
|
1452
|
+
});
|
|
1453
|
+
}
|
|
1454
|
+
/**
|
|
1455
|
+
* Publish a TUI event
|
|
1456
|
+
*/
|
|
1457
|
+
publish(options) {
|
|
1458
|
+
return (options?.client ?? this._client).post({
|
|
1459
|
+
url: "/tui/publish",
|
|
1460
|
+
...options,
|
|
1461
|
+
headers: {
|
|
1462
|
+
"Content-Type": "application/json",
|
|
1463
|
+
...options?.headers
|
|
1464
|
+
}
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
control = new Control({ client: this._client });
|
|
1468
|
+
};
|
|
1469
|
+
var Auth = class extends _HeyApiClient {
|
|
1470
|
+
/**
|
|
1471
|
+
* Set authentication credentials
|
|
1472
|
+
*/
|
|
1473
|
+
set(options) {
|
|
1474
|
+
return (options.client ?? this._client).put({
|
|
1475
|
+
url: "/auth/{id}",
|
|
1476
|
+
...options,
|
|
1477
|
+
headers: {
|
|
1478
|
+
"Content-Type": "application/json",
|
|
1479
|
+
...options.headers
|
|
1480
|
+
}
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
};
|
|
1484
|
+
var Event = class extends _HeyApiClient {
|
|
1485
|
+
/**
|
|
1486
|
+
* Get events
|
|
1487
|
+
*/
|
|
1488
|
+
subscribe(options) {
|
|
1489
|
+
return (options?.client ?? this._client).get.sse({
|
|
1490
|
+
url: "/event",
|
|
1491
|
+
...options
|
|
1492
|
+
});
|
|
1493
|
+
}
|
|
1494
|
+
};
|
|
1495
|
+
var OpencodeClient = class extends _HeyApiClient {
|
|
1496
|
+
/**
|
|
1497
|
+
* Respond to a permission request
|
|
1498
|
+
*/
|
|
1499
|
+
postSessionIdPermissionsPermissionId(options) {
|
|
1500
|
+
return (options.client ?? this._client).post({
|
|
1501
|
+
url: "/session/{id}/permissions/{permissionID}",
|
|
1502
|
+
...options,
|
|
1503
|
+
headers: {
|
|
1504
|
+
"Content-Type": "application/json",
|
|
1505
|
+
...options.headers
|
|
1506
|
+
}
|
|
1507
|
+
});
|
|
1508
|
+
}
|
|
1509
|
+
global = new Global({ client: this._client });
|
|
1510
|
+
project = new Project({ client: this._client });
|
|
1511
|
+
config = new Config({ client: this._client });
|
|
1512
|
+
tool = new Tool({ client: this._client });
|
|
1513
|
+
instance = new Instance({ client: this._client });
|
|
1514
|
+
path = new Path({ client: this._client });
|
|
1515
|
+
vcs = new Vcs({ client: this._client });
|
|
1516
|
+
session = new Session({ client: this._client });
|
|
1517
|
+
command = new Command({ client: this._client });
|
|
1518
|
+
provider = new Provider({ client: this._client });
|
|
1519
|
+
find = new Find({ client: this._client });
|
|
1520
|
+
file = new File2({ client: this._client });
|
|
1521
|
+
app = new App({ client: this._client });
|
|
1522
|
+
mcp = new Mcp({ client: this._client });
|
|
1523
|
+
lsp = new Lsp({ client: this._client });
|
|
1524
|
+
formatter = new Formatter({ client: this._client });
|
|
1525
|
+
tui = new Tui({ client: this._client });
|
|
1526
|
+
auth = new Auth({ client: this._client });
|
|
1527
|
+
event = new Event({ client: this._client });
|
|
1528
|
+
};
|
|
1529
|
+
|
|
1530
|
+
// ../../node_modules/.pnpm/@opencode-ai+sdk@1.0.132/node_modules/@opencode-ai/sdk/dist/client.js
|
|
1531
|
+
function createOpencodeClient(config) {
|
|
1532
|
+
if (!config?.fetch) {
|
|
1533
|
+
config = {
|
|
1534
|
+
...config,
|
|
1535
|
+
fetch: (req) => {
|
|
1536
|
+
req.timeout = false;
|
|
1537
|
+
return fetch(req);
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1541
|
+
if (config?.directory) {
|
|
1542
|
+
config.headers = {
|
|
1543
|
+
...config.headers,
|
|
1544
|
+
"x-opencode-directory": config.directory
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1547
|
+
const client2 = createClient(config);
|
|
1548
|
+
return new OpencodeClient({ client: client2 });
|
|
1549
|
+
}
|
|
1550
|
+
async function createOpencodeServer(options) {
|
|
1551
|
+
options = Object.assign({
|
|
1552
|
+
hostname: "127.0.0.1",
|
|
1553
|
+
port: 4096,
|
|
1554
|
+
timeout: 5e3
|
|
1555
|
+
}, options ?? {});
|
|
1556
|
+
const proc = child_process.spawn(`opencode`, [`serve`, `--hostname=${options.hostname}`, `--port=${options.port}`], {
|
|
1557
|
+
signal: options.signal,
|
|
1558
|
+
env: {
|
|
1559
|
+
...process.env,
|
|
1560
|
+
OPENCODE_CONFIG_CONTENT: JSON.stringify(options.config ?? {})
|
|
1561
|
+
}
|
|
1562
|
+
});
|
|
1563
|
+
const url = await new Promise((resolve, reject) => {
|
|
1564
|
+
const id = setTimeout(() => {
|
|
1565
|
+
reject(new Error(`Timeout waiting for server to start after ${options.timeout}ms`));
|
|
1566
|
+
}, options.timeout);
|
|
1567
|
+
let output = "";
|
|
1568
|
+
proc.stdout?.on("data", (chunk) => {
|
|
1569
|
+
output += chunk.toString();
|
|
1570
|
+
const lines = output.split("\n");
|
|
1571
|
+
for (const line of lines) {
|
|
1572
|
+
if (line.startsWith("opencode server listening")) {
|
|
1573
|
+
const match2 = line.match(/on\s+(https?:\/\/[^\s]+)/);
|
|
1574
|
+
if (!match2) {
|
|
1575
|
+
throw new Error(`Failed to parse server url from output: ${line}`);
|
|
1576
|
+
}
|
|
1577
|
+
clearTimeout(id);
|
|
1578
|
+
resolve(match2[1]);
|
|
1579
|
+
return;
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
});
|
|
1583
|
+
proc.stderr?.on("data", (chunk) => {
|
|
1584
|
+
output += chunk.toString();
|
|
1585
|
+
});
|
|
1586
|
+
proc.on("exit", (code) => {
|
|
1587
|
+
clearTimeout(id);
|
|
1588
|
+
let msg = `Server exited with code ${code}`;
|
|
1589
|
+
if (output.trim()) {
|
|
1590
|
+
msg += `
|
|
1591
|
+
Server output: ${output}`;
|
|
1592
|
+
}
|
|
1593
|
+
reject(new Error(msg));
|
|
1594
|
+
});
|
|
1595
|
+
proc.on("error", (error) => {
|
|
1596
|
+
clearTimeout(id);
|
|
1597
|
+
reject(error);
|
|
1598
|
+
});
|
|
1599
|
+
if (options.signal) {
|
|
1600
|
+
options.signal.addEventListener("abort", () => {
|
|
1601
|
+
clearTimeout(id);
|
|
1602
|
+
reject(new Error("Aborted"));
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
});
|
|
1606
|
+
return {
|
|
1607
|
+
url,
|
|
1608
|
+
close() {
|
|
1609
|
+
proc.kill();
|
|
1610
|
+
}
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
// ../../node_modules/.pnpm/@opencode-ai+sdk@1.0.132/node_modules/@opencode-ai/sdk/dist/index.js
|
|
1615
|
+
async function createOpencode(options) {
|
|
1616
|
+
const server = await createOpencodeServer({
|
|
1617
|
+
...options
|
|
1618
|
+
});
|
|
1619
|
+
const client2 = createOpencodeClient({
|
|
1620
|
+
baseUrl: server.url
|
|
1621
|
+
});
|
|
1622
|
+
return {
|
|
1623
|
+
client: client2,
|
|
1624
|
+
server
|
|
1625
|
+
};
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/compose.js
|
|
1629
|
+
var compose = (middleware, onError, onNotFound) => {
|
|
1630
|
+
return (context, next) => {
|
|
1631
|
+
let index = -1;
|
|
1632
|
+
return dispatch(0);
|
|
1633
|
+
async function dispatch(i) {
|
|
1634
|
+
if (i <= index) {
|
|
1635
|
+
throw new Error("next() called multiple times");
|
|
1636
|
+
}
|
|
1637
|
+
index = i;
|
|
1638
|
+
let res;
|
|
1639
|
+
let isError = false;
|
|
1640
|
+
let handler;
|
|
1641
|
+
if (middleware[i]) {
|
|
1642
|
+
handler = middleware[i][0][0];
|
|
1643
|
+
context.req.routeIndex = i;
|
|
1644
|
+
} else {
|
|
1645
|
+
handler = i === middleware.length && next || void 0;
|
|
1646
|
+
}
|
|
1647
|
+
if (handler) {
|
|
1648
|
+
try {
|
|
1649
|
+
res = await handler(context, () => dispatch(i + 1));
|
|
1650
|
+
} catch (err) {
|
|
1651
|
+
if (err instanceof Error && onError) {
|
|
1652
|
+
context.error = err;
|
|
1653
|
+
res = await onError(err, context);
|
|
1654
|
+
isError = true;
|
|
1655
|
+
} else {
|
|
1656
|
+
throw err;
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
} else {
|
|
1660
|
+
if (context.finalized === false && onNotFound) {
|
|
1661
|
+
res = await onNotFound(context);
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
if (res && (context.finalized === false || isError)) {
|
|
1665
|
+
context.res = res;
|
|
1666
|
+
}
|
|
1667
|
+
return context;
|
|
1668
|
+
}
|
|
1669
|
+
};
|
|
1670
|
+
};
|
|
1671
|
+
|
|
1672
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/request/constants.js
|
|
1673
|
+
var GET_MATCH_RESULT = Symbol();
|
|
1674
|
+
|
|
1675
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/utils/body.js
|
|
1676
|
+
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
1677
|
+
const { all = false, dot = false } = options;
|
|
1678
|
+
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
|
|
1679
|
+
const contentType = headers.get("Content-Type");
|
|
1680
|
+
if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
|
|
1681
|
+
return parseFormData(request, { all, dot });
|
|
1682
|
+
}
|
|
1683
|
+
return {};
|
|
1684
|
+
};
|
|
1685
|
+
async function parseFormData(request, options) {
|
|
1686
|
+
const formData = await request.formData();
|
|
1687
|
+
if (formData) {
|
|
1688
|
+
return convertFormDataToBodyData(formData, options);
|
|
1689
|
+
}
|
|
1690
|
+
return {};
|
|
1691
|
+
}
|
|
1692
|
+
function convertFormDataToBodyData(formData, options) {
|
|
1693
|
+
const form = /* @__PURE__ */ Object.create(null);
|
|
1694
|
+
formData.forEach((value, key) => {
|
|
1695
|
+
const shouldParseAllValues = options.all || key.endsWith("[]");
|
|
1696
|
+
if (!shouldParseAllValues) {
|
|
1697
|
+
form[key] = value;
|
|
1698
|
+
} else {
|
|
1699
|
+
handleParsingAllValues(form, key, value);
|
|
1700
|
+
}
|
|
1701
|
+
});
|
|
1702
|
+
if (options.dot) {
|
|
1703
|
+
Object.entries(form).forEach(([key, value]) => {
|
|
1704
|
+
const shouldParseDotValues = key.includes(".");
|
|
1705
|
+
if (shouldParseDotValues) {
|
|
1706
|
+
handleParsingNestedValues(form, key, value);
|
|
1707
|
+
delete form[key];
|
|
1708
|
+
}
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1711
|
+
return form;
|
|
1712
|
+
}
|
|
1713
|
+
var handleParsingAllValues = (form, key, value) => {
|
|
1714
|
+
if (form[key] !== void 0) {
|
|
1715
|
+
if (Array.isArray(form[key])) {
|
|
1716
|
+
form[key].push(value);
|
|
1717
|
+
} else {
|
|
1718
|
+
form[key] = [form[key], value];
|
|
1719
|
+
}
|
|
1720
|
+
} else {
|
|
1721
|
+
if (!key.endsWith("[]")) {
|
|
1722
|
+
form[key] = value;
|
|
1723
|
+
} else {
|
|
1724
|
+
form[key] = [value];
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
};
|
|
1728
|
+
var handleParsingNestedValues = (form, key, value) => {
|
|
1729
|
+
let nestedForm = form;
|
|
1730
|
+
const keys = key.split(".");
|
|
1731
|
+
keys.forEach((key2, index) => {
|
|
1732
|
+
if (index === keys.length - 1) {
|
|
1733
|
+
nestedForm[key2] = value;
|
|
1734
|
+
} else {
|
|
1735
|
+
if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
|
|
1736
|
+
nestedForm[key2] = /* @__PURE__ */ Object.create(null);
|
|
1737
|
+
}
|
|
1738
|
+
nestedForm = nestedForm[key2];
|
|
1739
|
+
}
|
|
1740
|
+
});
|
|
1741
|
+
};
|
|
1742
|
+
|
|
1743
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/utils/url.js
|
|
1744
|
+
var splitPath = (path) => {
|
|
1745
|
+
const paths = path.split("/");
|
|
1746
|
+
if (paths[0] === "") {
|
|
1747
|
+
paths.shift();
|
|
1748
|
+
}
|
|
1749
|
+
return paths;
|
|
1750
|
+
};
|
|
1751
|
+
var splitRoutingPath = (routePath) => {
|
|
1752
|
+
const { groups, path } = extractGroupsFromPath(routePath);
|
|
1753
|
+
const paths = splitPath(path);
|
|
1754
|
+
return replaceGroupMarks(paths, groups);
|
|
1755
|
+
};
|
|
1756
|
+
var extractGroupsFromPath = (path) => {
|
|
1757
|
+
const groups = [];
|
|
1758
|
+
path = path.replace(/\{[^}]+\}/g, (match2, index) => {
|
|
1759
|
+
const mark = `@${index}`;
|
|
1760
|
+
groups.push([mark, match2]);
|
|
1761
|
+
return mark;
|
|
1762
|
+
});
|
|
1763
|
+
return { groups, path };
|
|
1764
|
+
};
|
|
1765
|
+
var replaceGroupMarks = (paths, groups) => {
|
|
1766
|
+
for (let i = groups.length - 1; i >= 0; i--) {
|
|
1767
|
+
const [mark] = groups[i];
|
|
1768
|
+
for (let j = paths.length - 1; j >= 0; j--) {
|
|
1769
|
+
if (paths[j].includes(mark)) {
|
|
1770
|
+
paths[j] = paths[j].replace(mark, groups[i][1]);
|
|
1771
|
+
break;
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
return paths;
|
|
1776
|
+
};
|
|
1777
|
+
var patternCache = {};
|
|
1778
|
+
var getPattern = (label, next) => {
|
|
1779
|
+
if (label === "*") {
|
|
1780
|
+
return "*";
|
|
1781
|
+
}
|
|
1782
|
+
const match2 = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
1783
|
+
if (match2) {
|
|
1784
|
+
const cacheKey2 = `${label}#${next}`;
|
|
1785
|
+
if (!patternCache[cacheKey2]) {
|
|
1786
|
+
if (match2[2]) {
|
|
1787
|
+
patternCache[cacheKey2] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey2, match2[1], new RegExp(`^${match2[2]}(?=/${next})`)] : [label, match2[1], new RegExp(`^${match2[2]}$`)];
|
|
1788
|
+
} else {
|
|
1789
|
+
patternCache[cacheKey2] = [label, match2[1], true];
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
return patternCache[cacheKey2];
|
|
1793
|
+
}
|
|
1794
|
+
return null;
|
|
1795
|
+
};
|
|
1796
|
+
var tryDecode = (str, decoder) => {
|
|
1797
|
+
try {
|
|
1798
|
+
return decoder(str);
|
|
1799
|
+
} catch {
|
|
1800
|
+
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match2) => {
|
|
1801
|
+
try {
|
|
1802
|
+
return decoder(match2);
|
|
1803
|
+
} catch {
|
|
1804
|
+
return match2;
|
|
1805
|
+
}
|
|
1806
|
+
});
|
|
1807
|
+
}
|
|
1808
|
+
};
|
|
1809
|
+
var tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
|
1810
|
+
var getPath = (request) => {
|
|
1811
|
+
const url = request.url;
|
|
1812
|
+
const start = url.indexOf("/", url.indexOf(":") + 4);
|
|
1813
|
+
let i = start;
|
|
1814
|
+
for (; i < url.length; i++) {
|
|
1815
|
+
const charCode = url.charCodeAt(i);
|
|
1816
|
+
if (charCode === 37) {
|
|
1817
|
+
const queryIndex = url.indexOf("?", i);
|
|
1818
|
+
const path = url.slice(start, queryIndex === -1 ? void 0 : queryIndex);
|
|
1819
|
+
return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
|
|
1820
|
+
} else if (charCode === 63) {
|
|
1821
|
+
break;
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
return url.slice(start, i);
|
|
1825
|
+
};
|
|
1826
|
+
var getPathNoStrict = (request) => {
|
|
1827
|
+
const result = getPath(request);
|
|
1828
|
+
return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
|
|
1829
|
+
};
|
|
1830
|
+
var mergePath = (base, sub, ...rest) => {
|
|
1831
|
+
if (rest.length) {
|
|
1832
|
+
sub = mergePath(sub, ...rest);
|
|
1833
|
+
}
|
|
1834
|
+
return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
|
|
1835
|
+
};
|
|
1836
|
+
var checkOptionalParameter = (path) => {
|
|
1837
|
+
if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) {
|
|
1838
|
+
return null;
|
|
1839
|
+
}
|
|
1840
|
+
const segments = path.split("/");
|
|
1841
|
+
const results = [];
|
|
1842
|
+
let basePath = "";
|
|
1843
|
+
segments.forEach((segment) => {
|
|
1844
|
+
if (segment !== "" && !/\:/.test(segment)) {
|
|
1845
|
+
basePath += "/" + segment;
|
|
1846
|
+
} else if (/\:/.test(segment)) {
|
|
1847
|
+
if (/\?/.test(segment)) {
|
|
1848
|
+
if (results.length === 0 && basePath === "") {
|
|
1849
|
+
results.push("/");
|
|
1850
|
+
} else {
|
|
1851
|
+
results.push(basePath);
|
|
1852
|
+
}
|
|
1853
|
+
const optionalSegment = segment.replace("?", "");
|
|
1854
|
+
basePath += "/" + optionalSegment;
|
|
1855
|
+
results.push(basePath);
|
|
1856
|
+
} else {
|
|
1857
|
+
basePath += "/" + segment;
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
});
|
|
1861
|
+
return results.filter((v, i, a) => a.indexOf(v) === i);
|
|
1862
|
+
};
|
|
1863
|
+
var _decodeURI = (value) => {
|
|
1864
|
+
if (!/[%+]/.test(value)) {
|
|
1865
|
+
return value;
|
|
1866
|
+
}
|
|
1867
|
+
if (value.indexOf("+") !== -1) {
|
|
1868
|
+
value = value.replace(/\+/g, " ");
|
|
1869
|
+
}
|
|
1870
|
+
return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
|
|
1871
|
+
};
|
|
1872
|
+
var _getQueryParam = (url, key, multiple) => {
|
|
1873
|
+
let encoded;
|
|
1874
|
+
if (!multiple && key && !/[%+]/.test(key)) {
|
|
1875
|
+
let keyIndex2 = url.indexOf("?", 8);
|
|
1876
|
+
if (keyIndex2 === -1) {
|
|
1877
|
+
return void 0;
|
|
1878
|
+
}
|
|
1879
|
+
if (!url.startsWith(key, keyIndex2 + 1)) {
|
|
1880
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
1881
|
+
}
|
|
1882
|
+
while (keyIndex2 !== -1) {
|
|
1883
|
+
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
|
1884
|
+
if (trailingKeyCode === 61) {
|
|
1885
|
+
const valueIndex = keyIndex2 + key.length + 2;
|
|
1886
|
+
const endIndex = url.indexOf("&", valueIndex);
|
|
1887
|
+
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
|
|
1888
|
+
} else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
|
|
1889
|
+
return "";
|
|
1890
|
+
}
|
|
1891
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
1892
|
+
}
|
|
1893
|
+
encoded = /[%+]/.test(url);
|
|
1894
|
+
if (!encoded) {
|
|
1895
|
+
return void 0;
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
const results = {};
|
|
1899
|
+
encoded ??= /[%+]/.test(url);
|
|
1900
|
+
let keyIndex = url.indexOf("?", 8);
|
|
1901
|
+
while (keyIndex !== -1) {
|
|
1902
|
+
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
|
1903
|
+
let valueIndex = url.indexOf("=", keyIndex);
|
|
1904
|
+
if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
|
|
1905
|
+
valueIndex = -1;
|
|
1906
|
+
}
|
|
1907
|
+
let name = url.slice(
|
|
1908
|
+
keyIndex + 1,
|
|
1909
|
+
valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex
|
|
1910
|
+
);
|
|
1911
|
+
if (encoded) {
|
|
1912
|
+
name = _decodeURI(name);
|
|
1913
|
+
}
|
|
1914
|
+
keyIndex = nextKeyIndex;
|
|
1915
|
+
if (name === "") {
|
|
1916
|
+
continue;
|
|
1917
|
+
}
|
|
1918
|
+
let value;
|
|
1919
|
+
if (valueIndex === -1) {
|
|
1920
|
+
value = "";
|
|
1921
|
+
} else {
|
|
1922
|
+
value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex);
|
|
1923
|
+
if (encoded) {
|
|
1924
|
+
value = _decodeURI(value);
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
if (multiple) {
|
|
1928
|
+
if (!(results[name] && Array.isArray(results[name]))) {
|
|
1929
|
+
results[name] = [];
|
|
1930
|
+
}
|
|
1931
|
+
results[name].push(value);
|
|
1932
|
+
} else {
|
|
1933
|
+
results[name] ??= value;
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
return key ? results[key] : results;
|
|
1937
|
+
};
|
|
1938
|
+
var getQueryParam = _getQueryParam;
|
|
1939
|
+
var getQueryParams = (url, key) => {
|
|
1940
|
+
return _getQueryParam(url, key, true);
|
|
1941
|
+
};
|
|
1942
|
+
var decodeURIComponent_ = decodeURIComponent;
|
|
1943
|
+
|
|
1944
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/request.js
|
|
1945
|
+
var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
|
|
1946
|
+
var HonoRequest = class {
|
|
1947
|
+
raw;
|
|
1948
|
+
#validatedData;
|
|
1949
|
+
#matchResult;
|
|
1950
|
+
routeIndex = 0;
|
|
1951
|
+
path;
|
|
1952
|
+
bodyCache = {};
|
|
1953
|
+
constructor(request, path = "/", matchResult = [[]]) {
|
|
1954
|
+
this.raw = request;
|
|
1955
|
+
this.path = path;
|
|
1956
|
+
this.#matchResult = matchResult;
|
|
1957
|
+
this.#validatedData = {};
|
|
1958
|
+
}
|
|
1959
|
+
param(key) {
|
|
1960
|
+
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
|
|
1961
|
+
}
|
|
1962
|
+
#getDecodedParam(key) {
|
|
1963
|
+
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
|
1964
|
+
const param = this.#getParamValue(paramKey);
|
|
1965
|
+
return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
|
|
1966
|
+
}
|
|
1967
|
+
#getAllDecodedParams() {
|
|
1968
|
+
const decoded = {};
|
|
1969
|
+
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
|
1970
|
+
for (const key of keys) {
|
|
1971
|
+
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
1972
|
+
if (value !== void 0) {
|
|
1973
|
+
decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
return decoded;
|
|
1977
|
+
}
|
|
1978
|
+
#getParamValue(paramKey) {
|
|
1979
|
+
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
1980
|
+
}
|
|
1981
|
+
query(key) {
|
|
1982
|
+
return getQueryParam(this.url, key);
|
|
1983
|
+
}
|
|
1984
|
+
queries(key) {
|
|
1985
|
+
return getQueryParams(this.url, key);
|
|
1986
|
+
}
|
|
1987
|
+
header(name) {
|
|
1988
|
+
if (name) {
|
|
1989
|
+
return this.raw.headers.get(name) ?? void 0;
|
|
1990
|
+
}
|
|
1991
|
+
const headerData = {};
|
|
1992
|
+
this.raw.headers.forEach((value, key) => {
|
|
1993
|
+
headerData[key] = value;
|
|
1994
|
+
});
|
|
1995
|
+
return headerData;
|
|
1996
|
+
}
|
|
1997
|
+
async parseBody(options) {
|
|
1998
|
+
return this.bodyCache.parsedBody ??= await parseBody(this, options);
|
|
1999
|
+
}
|
|
2000
|
+
#cachedBody = (key) => {
|
|
2001
|
+
const { bodyCache, raw: raw2 } = this;
|
|
2002
|
+
const cachedBody = bodyCache[key];
|
|
2003
|
+
if (cachedBody) {
|
|
2004
|
+
return cachedBody;
|
|
2005
|
+
}
|
|
2006
|
+
const anyCachedKey = Object.keys(bodyCache)[0];
|
|
2007
|
+
if (anyCachedKey) {
|
|
2008
|
+
return bodyCache[anyCachedKey].then((body) => {
|
|
2009
|
+
if (anyCachedKey === "json") {
|
|
2010
|
+
body = JSON.stringify(body);
|
|
2011
|
+
}
|
|
2012
|
+
return new Response(body)[key]();
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
return bodyCache[key] = raw2[key]();
|
|
2016
|
+
};
|
|
2017
|
+
json() {
|
|
2018
|
+
return this.#cachedBody("text").then((text) => JSON.parse(text));
|
|
2019
|
+
}
|
|
2020
|
+
text() {
|
|
2021
|
+
return this.#cachedBody("text");
|
|
2022
|
+
}
|
|
2023
|
+
arrayBuffer() {
|
|
2024
|
+
return this.#cachedBody("arrayBuffer");
|
|
2025
|
+
}
|
|
2026
|
+
blob() {
|
|
2027
|
+
return this.#cachedBody("blob");
|
|
2028
|
+
}
|
|
2029
|
+
formData() {
|
|
2030
|
+
return this.#cachedBody("formData");
|
|
2031
|
+
}
|
|
2032
|
+
addValidatedData(target, data) {
|
|
2033
|
+
this.#validatedData[target] = data;
|
|
2034
|
+
}
|
|
2035
|
+
valid(target) {
|
|
2036
|
+
return this.#validatedData[target];
|
|
2037
|
+
}
|
|
2038
|
+
get url() {
|
|
2039
|
+
return this.raw.url;
|
|
2040
|
+
}
|
|
2041
|
+
get method() {
|
|
2042
|
+
return this.raw.method;
|
|
2043
|
+
}
|
|
2044
|
+
get [GET_MATCH_RESULT]() {
|
|
2045
|
+
return this.#matchResult;
|
|
2046
|
+
}
|
|
2047
|
+
get matchedRoutes() {
|
|
2048
|
+
return this.#matchResult[0].map(([[, route]]) => route);
|
|
2049
|
+
}
|
|
2050
|
+
get routePath() {
|
|
2051
|
+
return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
|
|
2052
|
+
}
|
|
2053
|
+
};
|
|
2054
|
+
|
|
2055
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/utils/html.js
|
|
2056
|
+
var HtmlEscapedCallbackPhase = {
|
|
2057
|
+
Stringify: 1};
|
|
2058
|
+
var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
|
|
2059
|
+
if (typeof str === "object" && !(str instanceof String)) {
|
|
2060
|
+
if (!(str instanceof Promise)) {
|
|
2061
|
+
str = str.toString();
|
|
2062
|
+
}
|
|
2063
|
+
if (str instanceof Promise) {
|
|
2064
|
+
str = await str;
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
const callbacks = str.callbacks;
|
|
2068
|
+
if (!callbacks?.length) {
|
|
2069
|
+
return Promise.resolve(str);
|
|
2070
|
+
}
|
|
2071
|
+
if (buffer) {
|
|
2072
|
+
buffer[0] += str;
|
|
2073
|
+
} else {
|
|
2074
|
+
buffer = [str];
|
|
2075
|
+
}
|
|
2076
|
+
const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context }))).then(
|
|
2077
|
+
(res) => Promise.all(
|
|
2078
|
+
res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))
|
|
2079
|
+
).then(() => buffer[0])
|
|
2080
|
+
);
|
|
2081
|
+
{
|
|
2082
|
+
return resStr;
|
|
2083
|
+
}
|
|
2084
|
+
};
|
|
2085
|
+
|
|
2086
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/context.js
|
|
2087
|
+
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
2088
|
+
var setDefaultContentType = (contentType, headers) => {
|
|
2089
|
+
return {
|
|
2090
|
+
"Content-Type": contentType,
|
|
2091
|
+
...headers
|
|
2092
|
+
};
|
|
2093
|
+
};
|
|
2094
|
+
var Context = class {
|
|
2095
|
+
#rawRequest;
|
|
2096
|
+
#req;
|
|
2097
|
+
env = {};
|
|
2098
|
+
#var;
|
|
2099
|
+
finalized = false;
|
|
2100
|
+
error;
|
|
2101
|
+
#status;
|
|
2102
|
+
#executionCtx;
|
|
2103
|
+
#res;
|
|
2104
|
+
#layout;
|
|
2105
|
+
#renderer;
|
|
2106
|
+
#notFoundHandler;
|
|
2107
|
+
#preparedHeaders;
|
|
2108
|
+
#matchResult;
|
|
2109
|
+
#path;
|
|
2110
|
+
constructor(req, options) {
|
|
2111
|
+
this.#rawRequest = req;
|
|
2112
|
+
if (options) {
|
|
2113
|
+
this.#executionCtx = options.executionCtx;
|
|
2114
|
+
this.env = options.env;
|
|
2115
|
+
this.#notFoundHandler = options.notFoundHandler;
|
|
2116
|
+
this.#path = options.path;
|
|
2117
|
+
this.#matchResult = options.matchResult;
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
get req() {
|
|
2121
|
+
this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
|
|
2122
|
+
return this.#req;
|
|
2123
|
+
}
|
|
2124
|
+
get event() {
|
|
2125
|
+
if (this.#executionCtx && "respondWith" in this.#executionCtx) {
|
|
2126
|
+
return this.#executionCtx;
|
|
2127
|
+
} else {
|
|
2128
|
+
throw Error("This context has no FetchEvent");
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
get executionCtx() {
|
|
2132
|
+
if (this.#executionCtx) {
|
|
2133
|
+
return this.#executionCtx;
|
|
2134
|
+
} else {
|
|
2135
|
+
throw Error("This context has no ExecutionContext");
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
get res() {
|
|
2139
|
+
return this.#res ||= new Response(null, {
|
|
2140
|
+
headers: this.#preparedHeaders ??= new Headers()
|
|
2141
|
+
});
|
|
2142
|
+
}
|
|
2143
|
+
set res(_res) {
|
|
2144
|
+
if (this.#res && _res) {
|
|
2145
|
+
_res = new Response(_res.body, _res);
|
|
2146
|
+
for (const [k, v] of this.#res.headers.entries()) {
|
|
2147
|
+
if (k === "content-type") {
|
|
2148
|
+
continue;
|
|
2149
|
+
}
|
|
2150
|
+
if (k === "set-cookie") {
|
|
2151
|
+
const cookies = this.#res.headers.getSetCookie();
|
|
2152
|
+
_res.headers.delete("set-cookie");
|
|
2153
|
+
for (const cookie of cookies) {
|
|
2154
|
+
_res.headers.append("set-cookie", cookie);
|
|
2155
|
+
}
|
|
2156
|
+
} else {
|
|
2157
|
+
_res.headers.set(k, v);
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
this.#res = _res;
|
|
2162
|
+
this.finalized = true;
|
|
2163
|
+
}
|
|
2164
|
+
render = (...args) => {
|
|
2165
|
+
this.#renderer ??= (content) => this.html(content);
|
|
2166
|
+
return this.#renderer(...args);
|
|
2167
|
+
};
|
|
2168
|
+
setLayout = (layout) => this.#layout = layout;
|
|
2169
|
+
getLayout = () => this.#layout;
|
|
2170
|
+
setRenderer = (renderer) => {
|
|
2171
|
+
this.#renderer = renderer;
|
|
2172
|
+
};
|
|
2173
|
+
header = (name, value, options) => {
|
|
2174
|
+
if (this.finalized) {
|
|
2175
|
+
this.#res = new Response(this.#res.body, this.#res);
|
|
2176
|
+
}
|
|
2177
|
+
const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers();
|
|
2178
|
+
if (value === void 0) {
|
|
2179
|
+
headers.delete(name);
|
|
2180
|
+
} else if (options?.append) {
|
|
2181
|
+
headers.append(name, value);
|
|
2182
|
+
} else {
|
|
2183
|
+
headers.set(name, value);
|
|
2184
|
+
}
|
|
2185
|
+
};
|
|
2186
|
+
status = (status) => {
|
|
2187
|
+
this.#status = status;
|
|
2188
|
+
};
|
|
2189
|
+
set = (key, value) => {
|
|
2190
|
+
this.#var ??= /* @__PURE__ */ new Map();
|
|
2191
|
+
this.#var.set(key, value);
|
|
2192
|
+
};
|
|
2193
|
+
get = (key) => {
|
|
2194
|
+
return this.#var ? this.#var.get(key) : void 0;
|
|
2195
|
+
};
|
|
2196
|
+
get var() {
|
|
2197
|
+
if (!this.#var) {
|
|
2198
|
+
return {};
|
|
2199
|
+
}
|
|
2200
|
+
return Object.fromEntries(this.#var);
|
|
2201
|
+
}
|
|
2202
|
+
#newResponse(data, arg, headers) {
|
|
2203
|
+
const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers();
|
|
2204
|
+
if (typeof arg === "object" && "headers" in arg) {
|
|
2205
|
+
const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
|
|
2206
|
+
for (const [key, value] of argHeaders) {
|
|
2207
|
+
if (key.toLowerCase() === "set-cookie") {
|
|
2208
|
+
responseHeaders.append(key, value);
|
|
2209
|
+
} else {
|
|
2210
|
+
responseHeaders.set(key, value);
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
if (headers) {
|
|
2215
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
2216
|
+
if (typeof v === "string") {
|
|
2217
|
+
responseHeaders.set(k, v);
|
|
2218
|
+
} else {
|
|
2219
|
+
responseHeaders.delete(k);
|
|
2220
|
+
for (const v2 of v) {
|
|
2221
|
+
responseHeaders.append(k, v2);
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
|
|
2227
|
+
return new Response(data, { status, headers: responseHeaders });
|
|
2228
|
+
}
|
|
2229
|
+
newResponse = (...args) => this.#newResponse(...args);
|
|
2230
|
+
body = (data, arg, headers) => this.#newResponse(data, arg, headers);
|
|
2231
|
+
text = (text, arg, headers) => {
|
|
2232
|
+
return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse(
|
|
2233
|
+
text,
|
|
2234
|
+
arg,
|
|
2235
|
+
setDefaultContentType(TEXT_PLAIN, headers)
|
|
2236
|
+
);
|
|
2237
|
+
};
|
|
2238
|
+
json = (object, arg, headers) => {
|
|
2239
|
+
return this.#newResponse(
|
|
2240
|
+
JSON.stringify(object),
|
|
2241
|
+
arg,
|
|
2242
|
+
setDefaultContentType("application/json", headers)
|
|
2243
|
+
);
|
|
2244
|
+
};
|
|
2245
|
+
html = (html, arg, headers) => {
|
|
2246
|
+
const res = (html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers));
|
|
2247
|
+
return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
|
|
2248
|
+
};
|
|
2249
|
+
redirect = (location, status) => {
|
|
2250
|
+
const locationString = String(location);
|
|
2251
|
+
this.header(
|
|
2252
|
+
"Location",
|
|
2253
|
+
!/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString)
|
|
2254
|
+
);
|
|
2255
|
+
return this.newResponse(null, status ?? 302);
|
|
2256
|
+
};
|
|
2257
|
+
notFound = () => {
|
|
2258
|
+
this.#notFoundHandler ??= () => new Response();
|
|
2259
|
+
return this.#notFoundHandler(this);
|
|
2260
|
+
};
|
|
2261
|
+
};
|
|
2262
|
+
|
|
2263
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/router.js
|
|
2264
|
+
var METHOD_NAME_ALL = "ALL";
|
|
2265
|
+
var METHOD_NAME_ALL_LOWERCASE = "all";
|
|
2266
|
+
var METHODS = ["get", "post", "put", "delete", "options", "patch"];
|
|
2267
|
+
var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
2268
|
+
var UnsupportedPathError = class extends Error {
|
|
2269
|
+
};
|
|
2270
|
+
|
|
2271
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/utils/constants.js
|
|
2272
|
+
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
|
2273
|
+
|
|
2274
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/hono-base.js
|
|
2275
|
+
var notFoundHandler = (c) => {
|
|
2276
|
+
return c.text("404 Not Found", 404);
|
|
2277
|
+
};
|
|
2278
|
+
var errorHandler = (err, c) => {
|
|
2279
|
+
if ("getResponse" in err) {
|
|
2280
|
+
const res = err.getResponse();
|
|
2281
|
+
return c.newResponse(res.body, res);
|
|
2282
|
+
}
|
|
2283
|
+
console.error(err);
|
|
2284
|
+
return c.text("Internal Server Error", 500);
|
|
2285
|
+
};
|
|
2286
|
+
var Hono = class {
|
|
2287
|
+
get;
|
|
2288
|
+
post;
|
|
2289
|
+
put;
|
|
2290
|
+
delete;
|
|
2291
|
+
options;
|
|
2292
|
+
patch;
|
|
2293
|
+
all;
|
|
2294
|
+
on;
|
|
2295
|
+
use;
|
|
2296
|
+
router;
|
|
2297
|
+
getPath;
|
|
2298
|
+
_basePath = "/";
|
|
2299
|
+
#path = "/";
|
|
2300
|
+
routes = [];
|
|
2301
|
+
constructor(options = {}) {
|
|
2302
|
+
const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE];
|
|
2303
|
+
allMethods.forEach((method) => {
|
|
2304
|
+
this[method] = (args1, ...args) => {
|
|
2305
|
+
if (typeof args1 === "string") {
|
|
2306
|
+
this.#path = args1;
|
|
2307
|
+
} else {
|
|
2308
|
+
this.#addRoute(method, this.#path, args1);
|
|
2309
|
+
}
|
|
2310
|
+
args.forEach((handler) => {
|
|
2311
|
+
this.#addRoute(method, this.#path, handler);
|
|
2312
|
+
});
|
|
2313
|
+
return this;
|
|
2314
|
+
};
|
|
2315
|
+
});
|
|
2316
|
+
this.on = (method, path, ...handlers) => {
|
|
2317
|
+
for (const p of [path].flat()) {
|
|
2318
|
+
this.#path = p;
|
|
2319
|
+
for (const m of [method].flat()) {
|
|
2320
|
+
handlers.map((handler) => {
|
|
2321
|
+
this.#addRoute(m.toUpperCase(), this.#path, handler);
|
|
2322
|
+
});
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
return this;
|
|
2326
|
+
};
|
|
2327
|
+
this.use = (arg1, ...handlers) => {
|
|
2328
|
+
if (typeof arg1 === "string") {
|
|
2329
|
+
this.#path = arg1;
|
|
2330
|
+
} else {
|
|
2331
|
+
this.#path = "*";
|
|
2332
|
+
handlers.unshift(arg1);
|
|
2333
|
+
}
|
|
2334
|
+
handlers.forEach((handler) => {
|
|
2335
|
+
this.#addRoute(METHOD_NAME_ALL, this.#path, handler);
|
|
2336
|
+
});
|
|
2337
|
+
return this;
|
|
2338
|
+
};
|
|
2339
|
+
const { strict, ...optionsWithoutStrict } = options;
|
|
2340
|
+
Object.assign(this, optionsWithoutStrict);
|
|
2341
|
+
this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
|
|
2342
|
+
}
|
|
2343
|
+
#clone() {
|
|
2344
|
+
const clone = new Hono({
|
|
2345
|
+
router: this.router,
|
|
2346
|
+
getPath: this.getPath
|
|
2347
|
+
});
|
|
2348
|
+
clone.errorHandler = this.errorHandler;
|
|
2349
|
+
clone.#notFoundHandler = this.#notFoundHandler;
|
|
2350
|
+
clone.routes = this.routes;
|
|
2351
|
+
return clone;
|
|
2352
|
+
}
|
|
2353
|
+
#notFoundHandler = notFoundHandler;
|
|
2354
|
+
errorHandler = errorHandler;
|
|
2355
|
+
route(path, app) {
|
|
2356
|
+
const subApp = this.basePath(path);
|
|
2357
|
+
app.routes.map((r) => {
|
|
2358
|
+
let handler;
|
|
2359
|
+
if (app.errorHandler === errorHandler) {
|
|
2360
|
+
handler = r.handler;
|
|
2361
|
+
} else {
|
|
2362
|
+
handler = async (c, next) => (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res;
|
|
2363
|
+
handler[COMPOSED_HANDLER] = r.handler;
|
|
2364
|
+
}
|
|
2365
|
+
subApp.#addRoute(r.method, r.path, handler);
|
|
2366
|
+
});
|
|
2367
|
+
return this;
|
|
2368
|
+
}
|
|
2369
|
+
basePath(path) {
|
|
2370
|
+
const subApp = this.#clone();
|
|
2371
|
+
subApp._basePath = mergePath(this._basePath, path);
|
|
2372
|
+
return subApp;
|
|
2373
|
+
}
|
|
2374
|
+
onError = (handler) => {
|
|
2375
|
+
this.errorHandler = handler;
|
|
2376
|
+
return this;
|
|
2377
|
+
};
|
|
2378
|
+
notFound = (handler) => {
|
|
2379
|
+
this.#notFoundHandler = handler;
|
|
2380
|
+
return this;
|
|
2381
|
+
};
|
|
2382
|
+
mount(path, applicationHandler, options) {
|
|
2383
|
+
let replaceRequest;
|
|
2384
|
+
let optionHandler;
|
|
2385
|
+
if (options) {
|
|
2386
|
+
if (typeof options === "function") {
|
|
2387
|
+
optionHandler = options;
|
|
2388
|
+
} else {
|
|
2389
|
+
optionHandler = options.optionHandler;
|
|
2390
|
+
if (options.replaceRequest === false) {
|
|
2391
|
+
replaceRequest = (request) => request;
|
|
2392
|
+
} else {
|
|
2393
|
+
replaceRequest = options.replaceRequest;
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
const getOptions = optionHandler ? (c) => {
|
|
2398
|
+
const options2 = optionHandler(c);
|
|
2399
|
+
return Array.isArray(options2) ? options2 : [options2];
|
|
2400
|
+
} : (c) => {
|
|
2401
|
+
let executionContext = void 0;
|
|
2402
|
+
try {
|
|
2403
|
+
executionContext = c.executionCtx;
|
|
2404
|
+
} catch {
|
|
2405
|
+
}
|
|
2406
|
+
return [c.env, executionContext];
|
|
2407
|
+
};
|
|
2408
|
+
replaceRequest ||= (() => {
|
|
2409
|
+
const mergedPath = mergePath(this._basePath, path);
|
|
2410
|
+
const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
|
|
2411
|
+
return (request) => {
|
|
2412
|
+
const url = new URL(request.url);
|
|
2413
|
+
url.pathname = url.pathname.slice(pathPrefixLength) || "/";
|
|
2414
|
+
return new Request(url, request);
|
|
2415
|
+
};
|
|
2416
|
+
})();
|
|
2417
|
+
const handler = async (c, next) => {
|
|
2418
|
+
const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
|
|
2419
|
+
if (res) {
|
|
2420
|
+
return res;
|
|
2421
|
+
}
|
|
2422
|
+
await next();
|
|
2423
|
+
};
|
|
2424
|
+
this.#addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
|
|
2425
|
+
return this;
|
|
2426
|
+
}
|
|
2427
|
+
#addRoute(method, path, handler) {
|
|
2428
|
+
method = method.toUpperCase();
|
|
2429
|
+
path = mergePath(this._basePath, path);
|
|
2430
|
+
const r = { basePath: this._basePath, path, method, handler };
|
|
2431
|
+
this.router.add(method, path, [handler, r]);
|
|
2432
|
+
this.routes.push(r);
|
|
2433
|
+
}
|
|
2434
|
+
#handleError(err, c) {
|
|
2435
|
+
if (err instanceof Error) {
|
|
2436
|
+
return this.errorHandler(err, c);
|
|
2437
|
+
}
|
|
2438
|
+
throw err;
|
|
2439
|
+
}
|
|
2440
|
+
#dispatch(request, executionCtx, env, method) {
|
|
2441
|
+
if (method === "HEAD") {
|
|
2442
|
+
return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
|
|
2443
|
+
}
|
|
2444
|
+
const path = this.getPath(request, { env });
|
|
2445
|
+
const matchResult = this.router.match(method, path);
|
|
2446
|
+
const c = new Context(request, {
|
|
2447
|
+
path,
|
|
2448
|
+
matchResult,
|
|
2449
|
+
env,
|
|
2450
|
+
executionCtx,
|
|
2451
|
+
notFoundHandler: this.#notFoundHandler
|
|
2452
|
+
});
|
|
2453
|
+
if (matchResult[0].length === 1) {
|
|
2454
|
+
let res;
|
|
2455
|
+
try {
|
|
2456
|
+
res = matchResult[0][0][0][0](c, async () => {
|
|
2457
|
+
c.res = await this.#notFoundHandler(c);
|
|
2458
|
+
});
|
|
2459
|
+
} catch (err) {
|
|
2460
|
+
return this.#handleError(err, c);
|
|
2461
|
+
}
|
|
2462
|
+
return res instanceof Promise ? res.then(
|
|
2463
|
+
(resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c))
|
|
2464
|
+
).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c);
|
|
2465
|
+
}
|
|
2466
|
+
const composed = compose(matchResult[0], this.errorHandler, this.#notFoundHandler);
|
|
2467
|
+
return (async () => {
|
|
2468
|
+
try {
|
|
2469
|
+
const context = await composed(c);
|
|
2470
|
+
if (!context.finalized) {
|
|
2471
|
+
throw new Error(
|
|
2472
|
+
"Context is not finalized. Did you forget to return a Response object or `await next()`?"
|
|
2473
|
+
);
|
|
2474
|
+
}
|
|
2475
|
+
return context.res;
|
|
2476
|
+
} catch (err) {
|
|
2477
|
+
return this.#handleError(err, c);
|
|
2478
|
+
}
|
|
2479
|
+
})();
|
|
2480
|
+
}
|
|
2481
|
+
fetch = (request, ...rest) => {
|
|
2482
|
+
return this.#dispatch(request, rest[1], rest[0], request.method);
|
|
2483
|
+
};
|
|
2484
|
+
request = (input, requestInit, Env, executionCtx) => {
|
|
2485
|
+
if (input instanceof Request) {
|
|
2486
|
+
return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
|
|
2487
|
+
}
|
|
2488
|
+
input = input.toString();
|
|
2489
|
+
return this.fetch(
|
|
2490
|
+
new Request(
|
|
2491
|
+
/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`,
|
|
2492
|
+
requestInit
|
|
2493
|
+
),
|
|
2494
|
+
Env,
|
|
2495
|
+
executionCtx
|
|
2496
|
+
);
|
|
2497
|
+
};
|
|
2498
|
+
fire = () => {
|
|
2499
|
+
addEventListener("fetch", (event) => {
|
|
2500
|
+
event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method));
|
|
2501
|
+
});
|
|
2502
|
+
};
|
|
2503
|
+
};
|
|
2504
|
+
|
|
2505
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/router/reg-exp-router/matcher.js
|
|
2506
|
+
var emptyParam = [];
|
|
2507
|
+
function match(method, path) {
|
|
2508
|
+
const matchers = this.buildAllMatchers();
|
|
2509
|
+
const match2 = (method2, path2) => {
|
|
2510
|
+
const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
|
|
2511
|
+
const staticMatch = matcher[2][path2];
|
|
2512
|
+
if (staticMatch) {
|
|
2513
|
+
return staticMatch;
|
|
2514
|
+
}
|
|
2515
|
+
const match3 = path2.match(matcher[0]);
|
|
2516
|
+
if (!match3) {
|
|
2517
|
+
return [[], emptyParam];
|
|
2518
|
+
}
|
|
2519
|
+
const index = match3.indexOf("", 1);
|
|
2520
|
+
return [matcher[1][index], match3];
|
|
2521
|
+
};
|
|
2522
|
+
this.match = match2;
|
|
2523
|
+
return match2(method, path);
|
|
2524
|
+
}
|
|
2525
|
+
|
|
2526
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
2527
|
+
var LABEL_REG_EXP_STR = "[^/]+";
|
|
2528
|
+
var ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
2529
|
+
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
2530
|
+
var PATH_ERROR = Symbol();
|
|
2531
|
+
var regExpMetaChars = new Set(".\\+*[^]$()");
|
|
2532
|
+
function compareKey(a, b) {
|
|
2533
|
+
if (a.length === 1) {
|
|
2534
|
+
return b.length === 1 ? a < b ? -1 : 1 : -1;
|
|
2535
|
+
}
|
|
2536
|
+
if (b.length === 1) {
|
|
2537
|
+
return 1;
|
|
2538
|
+
}
|
|
2539
|
+
if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
|
|
2540
|
+
return 1;
|
|
2541
|
+
} else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
|
|
2542
|
+
return -1;
|
|
2543
|
+
}
|
|
2544
|
+
if (a === LABEL_REG_EXP_STR) {
|
|
2545
|
+
return 1;
|
|
2546
|
+
} else if (b === LABEL_REG_EXP_STR) {
|
|
2547
|
+
return -1;
|
|
2548
|
+
}
|
|
2549
|
+
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
|
2550
|
+
}
|
|
2551
|
+
var Node = class {
|
|
2552
|
+
#index;
|
|
2553
|
+
#varIndex;
|
|
2554
|
+
#children = /* @__PURE__ */ Object.create(null);
|
|
2555
|
+
insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
|
|
2556
|
+
if (tokens.length === 0) {
|
|
2557
|
+
if (this.#index !== void 0) {
|
|
2558
|
+
throw PATH_ERROR;
|
|
2559
|
+
}
|
|
2560
|
+
if (pathErrorCheckOnly) {
|
|
2561
|
+
return;
|
|
2562
|
+
}
|
|
2563
|
+
this.#index = index;
|
|
2564
|
+
return;
|
|
2565
|
+
}
|
|
2566
|
+
const [token, ...restTokens] = tokens;
|
|
2567
|
+
const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
2568
|
+
let node;
|
|
2569
|
+
if (pattern) {
|
|
2570
|
+
const name = pattern[1];
|
|
2571
|
+
let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
|
|
2572
|
+
if (name && pattern[2]) {
|
|
2573
|
+
if (regexpStr === ".*") {
|
|
2574
|
+
throw PATH_ERROR;
|
|
2575
|
+
}
|
|
2576
|
+
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
|
|
2577
|
+
if (/\((?!\?:)/.test(regexpStr)) {
|
|
2578
|
+
throw PATH_ERROR;
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
node = this.#children[regexpStr];
|
|
2582
|
+
if (!node) {
|
|
2583
|
+
if (Object.keys(this.#children).some(
|
|
2584
|
+
(k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
|
|
2585
|
+
)) {
|
|
2586
|
+
throw PATH_ERROR;
|
|
2587
|
+
}
|
|
2588
|
+
if (pathErrorCheckOnly) {
|
|
2589
|
+
return;
|
|
2590
|
+
}
|
|
2591
|
+
node = this.#children[regexpStr] = new Node();
|
|
2592
|
+
if (name !== "") {
|
|
2593
|
+
node.#varIndex = context.varIndex++;
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
if (!pathErrorCheckOnly && name !== "") {
|
|
2597
|
+
paramMap.push([name, node.#varIndex]);
|
|
2598
|
+
}
|
|
2599
|
+
} else {
|
|
2600
|
+
node = this.#children[token];
|
|
2601
|
+
if (!node) {
|
|
2602
|
+
if (Object.keys(this.#children).some(
|
|
2603
|
+
(k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
|
|
2604
|
+
)) {
|
|
2605
|
+
throw PATH_ERROR;
|
|
2606
|
+
}
|
|
2607
|
+
if (pathErrorCheckOnly) {
|
|
2608
|
+
return;
|
|
2609
|
+
}
|
|
2610
|
+
node = this.#children[token] = new Node();
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
|
|
2614
|
+
}
|
|
2615
|
+
buildRegExpStr() {
|
|
2616
|
+
const childKeys = Object.keys(this.#children).sort(compareKey);
|
|
2617
|
+
const strList = childKeys.map((k) => {
|
|
2618
|
+
const c = this.#children[k];
|
|
2619
|
+
return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
|
|
2620
|
+
});
|
|
2621
|
+
if (typeof this.#index === "number") {
|
|
2622
|
+
strList.unshift(`#${this.#index}`);
|
|
2623
|
+
}
|
|
2624
|
+
if (strList.length === 0) {
|
|
2625
|
+
return "";
|
|
2626
|
+
}
|
|
2627
|
+
if (strList.length === 1) {
|
|
2628
|
+
return strList[0];
|
|
2629
|
+
}
|
|
2630
|
+
return "(?:" + strList.join("|") + ")";
|
|
2631
|
+
}
|
|
2632
|
+
};
|
|
2633
|
+
|
|
2634
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/router/reg-exp-router/trie.js
|
|
2635
|
+
var Trie = class {
|
|
2636
|
+
#context = { varIndex: 0 };
|
|
2637
|
+
#root = new Node();
|
|
2638
|
+
insert(path, index, pathErrorCheckOnly) {
|
|
2639
|
+
const paramAssoc = [];
|
|
2640
|
+
const groups = [];
|
|
2641
|
+
for (let i = 0; ; ) {
|
|
2642
|
+
let replaced = false;
|
|
2643
|
+
path = path.replace(/\{[^}]+\}/g, (m) => {
|
|
2644
|
+
const mark = `@\\${i}`;
|
|
2645
|
+
groups[i] = [mark, m];
|
|
2646
|
+
i++;
|
|
2647
|
+
replaced = true;
|
|
2648
|
+
return mark;
|
|
2649
|
+
});
|
|
2650
|
+
if (!replaced) {
|
|
2651
|
+
break;
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
|
2655
|
+
for (let i = groups.length - 1; i >= 0; i--) {
|
|
2656
|
+
const [mark] = groups[i];
|
|
2657
|
+
for (let j = tokens.length - 1; j >= 0; j--) {
|
|
2658
|
+
if (tokens[j].indexOf(mark) !== -1) {
|
|
2659
|
+
tokens[j] = tokens[j].replace(mark, groups[i][1]);
|
|
2660
|
+
break;
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
|
|
2665
|
+
return paramAssoc;
|
|
2666
|
+
}
|
|
2667
|
+
buildRegExp() {
|
|
2668
|
+
let regexp = this.#root.buildRegExpStr();
|
|
2669
|
+
if (regexp === "") {
|
|
2670
|
+
return [/^$/, [], []];
|
|
2671
|
+
}
|
|
2672
|
+
let captureIndex = 0;
|
|
2673
|
+
const indexReplacementMap = [];
|
|
2674
|
+
const paramReplacementMap = [];
|
|
2675
|
+
regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
|
|
2676
|
+
if (handlerIndex !== void 0) {
|
|
2677
|
+
indexReplacementMap[++captureIndex] = Number(handlerIndex);
|
|
2678
|
+
return "$()";
|
|
2679
|
+
}
|
|
2680
|
+
if (paramIndex !== void 0) {
|
|
2681
|
+
paramReplacementMap[Number(paramIndex)] = ++captureIndex;
|
|
2682
|
+
return "";
|
|
2683
|
+
}
|
|
2684
|
+
return "";
|
|
2685
|
+
});
|
|
2686
|
+
return [new RegExp(`^${regexp}`), indexReplacementMap, paramReplacementMap];
|
|
2687
|
+
}
|
|
2688
|
+
};
|
|
2689
|
+
|
|
2690
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/router/reg-exp-router/router.js
|
|
2691
|
+
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
|
2692
|
+
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
2693
|
+
function buildWildcardRegExp(path) {
|
|
2694
|
+
return wildcardRegExpCache[path] ??= new RegExp(
|
|
2695
|
+
path === "*" ? "" : `^${path.replace(
|
|
2696
|
+
/\/\*$|([.\\+*[^\]$()])/g,
|
|
2697
|
+
(_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)"
|
|
2698
|
+
)}$`
|
|
2699
|
+
);
|
|
2700
|
+
}
|
|
2701
|
+
function clearWildcardRegExpCache() {
|
|
2702
|
+
wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
2703
|
+
}
|
|
2704
|
+
function buildMatcherFromPreprocessedRoutes(routes) {
|
|
2705
|
+
const trie = new Trie();
|
|
2706
|
+
const handlerData = [];
|
|
2707
|
+
if (routes.length === 0) {
|
|
2708
|
+
return nullMatcher;
|
|
2709
|
+
}
|
|
2710
|
+
const routesWithStaticPathFlag = routes.map(
|
|
2711
|
+
(route) => [!/\*|\/:/.test(route[0]), ...route]
|
|
2712
|
+
).sort(
|
|
2713
|
+
([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length
|
|
2714
|
+
);
|
|
2715
|
+
const staticMap = /* @__PURE__ */ Object.create(null);
|
|
2716
|
+
for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
|
|
2717
|
+
const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
|
|
2718
|
+
if (pathErrorCheckOnly) {
|
|
2719
|
+
staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
|
|
2720
|
+
} else {
|
|
2721
|
+
j++;
|
|
2722
|
+
}
|
|
2723
|
+
let paramAssoc;
|
|
2724
|
+
try {
|
|
2725
|
+
paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
|
|
2726
|
+
} catch (e) {
|
|
2727
|
+
throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
|
|
2728
|
+
}
|
|
2729
|
+
if (pathErrorCheckOnly) {
|
|
2730
|
+
continue;
|
|
2731
|
+
}
|
|
2732
|
+
handlerData[j] = handlers.map(([h, paramCount]) => {
|
|
2733
|
+
const paramIndexMap = /* @__PURE__ */ Object.create(null);
|
|
2734
|
+
paramCount -= 1;
|
|
2735
|
+
for (; paramCount >= 0; paramCount--) {
|
|
2736
|
+
const [key, value] = paramAssoc[paramCount];
|
|
2737
|
+
paramIndexMap[key] = value;
|
|
2738
|
+
}
|
|
2739
|
+
return [h, paramIndexMap];
|
|
2740
|
+
});
|
|
2741
|
+
}
|
|
2742
|
+
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
2743
|
+
for (let i = 0, len = handlerData.length; i < len; i++) {
|
|
2744
|
+
for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
|
|
2745
|
+
const map = handlerData[i][j]?.[1];
|
|
2746
|
+
if (!map) {
|
|
2747
|
+
continue;
|
|
2748
|
+
}
|
|
2749
|
+
const keys = Object.keys(map);
|
|
2750
|
+
for (let k = 0, len3 = keys.length; k < len3; k++) {
|
|
2751
|
+
map[keys[k]] = paramReplacementMap[map[keys[k]]];
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
2754
|
+
}
|
|
2755
|
+
const handlerMap = [];
|
|
2756
|
+
for (const i in indexReplacementMap) {
|
|
2757
|
+
handlerMap[i] = handlerData[indexReplacementMap[i]];
|
|
2758
|
+
}
|
|
2759
|
+
return [regexp, handlerMap, staticMap];
|
|
2760
|
+
}
|
|
2761
|
+
function findMiddleware(middleware, path) {
|
|
2762
|
+
if (!middleware) {
|
|
2763
|
+
return void 0;
|
|
2764
|
+
}
|
|
2765
|
+
for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
|
|
2766
|
+
if (buildWildcardRegExp(k).test(path)) {
|
|
2767
|
+
return [...middleware[k]];
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
return void 0;
|
|
2771
|
+
}
|
|
2772
|
+
var RegExpRouter = class {
|
|
2773
|
+
name = "RegExpRouter";
|
|
2774
|
+
#middleware;
|
|
2775
|
+
#routes;
|
|
2776
|
+
constructor() {
|
|
2777
|
+
this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
2778
|
+
this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
2779
|
+
}
|
|
2780
|
+
add(method, path, handler) {
|
|
2781
|
+
const middleware = this.#middleware;
|
|
2782
|
+
const routes = this.#routes;
|
|
2783
|
+
if (!middleware || !routes) {
|
|
2784
|
+
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
2785
|
+
}
|
|
2786
|
+
if (!middleware[method]) {
|
|
2787
|
+
[middleware, routes].forEach((handlerMap) => {
|
|
2788
|
+
handlerMap[method] = /* @__PURE__ */ Object.create(null);
|
|
2789
|
+
Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
|
|
2790
|
+
handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
|
|
2791
|
+
});
|
|
2792
|
+
});
|
|
2793
|
+
}
|
|
2794
|
+
if (path === "/*") {
|
|
2795
|
+
path = "*";
|
|
2796
|
+
}
|
|
2797
|
+
const paramCount = (path.match(/\/:/g) || []).length;
|
|
2798
|
+
if (/\*$/.test(path)) {
|
|
2799
|
+
const re = buildWildcardRegExp(path);
|
|
2800
|
+
if (method === METHOD_NAME_ALL) {
|
|
2801
|
+
Object.keys(middleware).forEach((m) => {
|
|
2802
|
+
middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
2803
|
+
});
|
|
2804
|
+
} else {
|
|
2805
|
+
middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
2806
|
+
}
|
|
2807
|
+
Object.keys(middleware).forEach((m) => {
|
|
2808
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
2809
|
+
Object.keys(middleware[m]).forEach((p) => {
|
|
2810
|
+
re.test(p) && middleware[m][p].push([handler, paramCount]);
|
|
2811
|
+
});
|
|
2812
|
+
}
|
|
2813
|
+
});
|
|
2814
|
+
Object.keys(routes).forEach((m) => {
|
|
2815
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
2816
|
+
Object.keys(routes[m]).forEach(
|
|
2817
|
+
(p) => re.test(p) && routes[m][p].push([handler, paramCount])
|
|
2818
|
+
);
|
|
2819
|
+
}
|
|
2820
|
+
});
|
|
2821
|
+
return;
|
|
2822
|
+
}
|
|
2823
|
+
const paths = checkOptionalParameter(path) || [path];
|
|
2824
|
+
for (let i = 0, len = paths.length; i < len; i++) {
|
|
2825
|
+
const path2 = paths[i];
|
|
2826
|
+
Object.keys(routes).forEach((m) => {
|
|
2827
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
2828
|
+
routes[m][path2] ||= [
|
|
2829
|
+
...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
|
|
2830
|
+
];
|
|
2831
|
+
routes[m][path2].push([handler, paramCount - len + i + 1]);
|
|
2832
|
+
}
|
|
2833
|
+
});
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
match = match;
|
|
2837
|
+
buildAllMatchers() {
|
|
2838
|
+
const matchers = /* @__PURE__ */ Object.create(null);
|
|
2839
|
+
Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
|
|
2840
|
+
matchers[method] ||= this.#buildMatcher(method);
|
|
2841
|
+
});
|
|
2842
|
+
this.#middleware = this.#routes = void 0;
|
|
2843
|
+
clearWildcardRegExpCache();
|
|
2844
|
+
return matchers;
|
|
2845
|
+
}
|
|
2846
|
+
#buildMatcher(method) {
|
|
2847
|
+
const routes = [];
|
|
2848
|
+
let hasOwnRoute = method === METHOD_NAME_ALL;
|
|
2849
|
+
[this.#middleware, this.#routes].forEach((r) => {
|
|
2850
|
+
const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
|
|
2851
|
+
if (ownRoute.length !== 0) {
|
|
2852
|
+
hasOwnRoute ||= true;
|
|
2853
|
+
routes.push(...ownRoute);
|
|
2854
|
+
} else if (method !== METHOD_NAME_ALL) {
|
|
2855
|
+
routes.push(
|
|
2856
|
+
...Object.keys(r[METHOD_NAME_ALL]).map((path) => [path, r[METHOD_NAME_ALL][path]])
|
|
2857
|
+
);
|
|
2858
|
+
}
|
|
2859
|
+
});
|
|
2860
|
+
if (!hasOwnRoute) {
|
|
2861
|
+
return null;
|
|
2862
|
+
} else {
|
|
2863
|
+
return buildMatcherFromPreprocessedRoutes(routes);
|
|
2864
|
+
}
|
|
2865
|
+
}
|
|
2866
|
+
};
|
|
2867
|
+
|
|
2868
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/router/smart-router/router.js
|
|
2869
|
+
var SmartRouter = class {
|
|
2870
|
+
name = "SmartRouter";
|
|
2871
|
+
#routers = [];
|
|
2872
|
+
#routes = [];
|
|
2873
|
+
constructor(init) {
|
|
2874
|
+
this.#routers = init.routers;
|
|
2875
|
+
}
|
|
2876
|
+
add(method, path, handler) {
|
|
2877
|
+
if (!this.#routes) {
|
|
2878
|
+
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
2879
|
+
}
|
|
2880
|
+
this.#routes.push([method, path, handler]);
|
|
2881
|
+
}
|
|
2882
|
+
match(method, path) {
|
|
2883
|
+
if (!this.#routes) {
|
|
2884
|
+
throw new Error("Fatal error");
|
|
2885
|
+
}
|
|
2886
|
+
const routers = this.#routers;
|
|
2887
|
+
const routes = this.#routes;
|
|
2888
|
+
const len = routers.length;
|
|
2889
|
+
let i = 0;
|
|
2890
|
+
let res;
|
|
2891
|
+
for (; i < len; i++) {
|
|
2892
|
+
const router = routers[i];
|
|
2893
|
+
try {
|
|
2894
|
+
for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) {
|
|
2895
|
+
router.add(...routes[i2]);
|
|
2896
|
+
}
|
|
2897
|
+
res = router.match(method, path);
|
|
2898
|
+
} catch (e) {
|
|
2899
|
+
if (e instanceof UnsupportedPathError) {
|
|
2900
|
+
continue;
|
|
2901
|
+
}
|
|
2902
|
+
throw e;
|
|
2903
|
+
}
|
|
2904
|
+
this.match = router.match.bind(router);
|
|
2905
|
+
this.#routers = [router];
|
|
2906
|
+
this.#routes = void 0;
|
|
2907
|
+
break;
|
|
2908
|
+
}
|
|
2909
|
+
if (i === len) {
|
|
2910
|
+
throw new Error("Fatal error");
|
|
2911
|
+
}
|
|
2912
|
+
this.name = `SmartRouter + ${this.activeRouter.name}`;
|
|
2913
|
+
return res;
|
|
2914
|
+
}
|
|
2915
|
+
get activeRouter() {
|
|
2916
|
+
if (this.#routes || this.#routers.length !== 1) {
|
|
2917
|
+
throw new Error("No active router has been determined yet.");
|
|
2918
|
+
}
|
|
2919
|
+
return this.#routers[0];
|
|
2920
|
+
}
|
|
2921
|
+
};
|
|
2922
|
+
|
|
2923
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/router/trie-router/node.js
|
|
2924
|
+
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
2925
|
+
var Node2 = class {
|
|
2926
|
+
#methods;
|
|
2927
|
+
#children;
|
|
2928
|
+
#patterns;
|
|
2929
|
+
#order = 0;
|
|
2930
|
+
#params = emptyParams;
|
|
2931
|
+
constructor(method, handler, children) {
|
|
2932
|
+
this.#children = children || /* @__PURE__ */ Object.create(null);
|
|
2933
|
+
this.#methods = [];
|
|
2934
|
+
if (method && handler) {
|
|
2935
|
+
const m = /* @__PURE__ */ Object.create(null);
|
|
2936
|
+
m[method] = { handler, possibleKeys: [], score: 0 };
|
|
2937
|
+
this.#methods = [m];
|
|
2938
|
+
}
|
|
2939
|
+
this.#patterns = [];
|
|
2940
|
+
}
|
|
2941
|
+
insert(method, path, handler) {
|
|
2942
|
+
this.#order = ++this.#order;
|
|
2943
|
+
let curNode = this;
|
|
2944
|
+
const parts = splitRoutingPath(path);
|
|
2945
|
+
const possibleKeys = [];
|
|
2946
|
+
for (let i = 0, len = parts.length; i < len; i++) {
|
|
2947
|
+
const p = parts[i];
|
|
2948
|
+
const nextP = parts[i + 1];
|
|
2949
|
+
const pattern = getPattern(p, nextP);
|
|
2950
|
+
const key = Array.isArray(pattern) ? pattern[0] : p;
|
|
2951
|
+
if (key in curNode.#children) {
|
|
2952
|
+
curNode = curNode.#children[key];
|
|
2953
|
+
if (pattern) {
|
|
2954
|
+
possibleKeys.push(pattern[1]);
|
|
2955
|
+
}
|
|
2956
|
+
continue;
|
|
2957
|
+
}
|
|
2958
|
+
curNode.#children[key] = new Node2();
|
|
2959
|
+
if (pattern) {
|
|
2960
|
+
curNode.#patterns.push(pattern);
|
|
2961
|
+
possibleKeys.push(pattern[1]);
|
|
2962
|
+
}
|
|
2963
|
+
curNode = curNode.#children[key];
|
|
2964
|
+
}
|
|
2965
|
+
curNode.#methods.push({
|
|
2966
|
+
[method]: {
|
|
2967
|
+
handler,
|
|
2968
|
+
possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
|
|
2969
|
+
score: this.#order
|
|
2970
|
+
}
|
|
2971
|
+
});
|
|
2972
|
+
return curNode;
|
|
2973
|
+
}
|
|
2974
|
+
#getHandlerSets(node, method, nodeParams, params) {
|
|
2975
|
+
const handlerSets = [];
|
|
2976
|
+
for (let i = 0, len = node.#methods.length; i < len; i++) {
|
|
2977
|
+
const m = node.#methods[i];
|
|
2978
|
+
const handlerSet = m[method] || m[METHOD_NAME_ALL];
|
|
2979
|
+
const processedSet = {};
|
|
2980
|
+
if (handlerSet !== void 0) {
|
|
2981
|
+
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
|
2982
|
+
handlerSets.push(handlerSet);
|
|
2983
|
+
if (nodeParams !== emptyParams || params && params !== emptyParams) {
|
|
2984
|
+
for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
|
|
2985
|
+
const key = handlerSet.possibleKeys[i2];
|
|
2986
|
+
const processed = processedSet[handlerSet.score];
|
|
2987
|
+
handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
|
|
2988
|
+
processedSet[handlerSet.score] = true;
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
return handlerSets;
|
|
2994
|
+
}
|
|
2995
|
+
search(method, path) {
|
|
2996
|
+
const handlerSets = [];
|
|
2997
|
+
this.#params = emptyParams;
|
|
2998
|
+
const curNode = this;
|
|
2999
|
+
let curNodes = [curNode];
|
|
3000
|
+
const parts = splitPath(path);
|
|
3001
|
+
const curNodesQueue = [];
|
|
3002
|
+
for (let i = 0, len = parts.length; i < len; i++) {
|
|
3003
|
+
const part = parts[i];
|
|
3004
|
+
const isLast = i === len - 1;
|
|
3005
|
+
const tempNodes = [];
|
|
3006
|
+
for (let j = 0, len2 = curNodes.length; j < len2; j++) {
|
|
3007
|
+
const node = curNodes[j];
|
|
3008
|
+
const nextNode = node.#children[part];
|
|
3009
|
+
if (nextNode) {
|
|
3010
|
+
nextNode.#params = node.#params;
|
|
3011
|
+
if (isLast) {
|
|
3012
|
+
if (nextNode.#children["*"]) {
|
|
3013
|
+
handlerSets.push(
|
|
3014
|
+
...this.#getHandlerSets(nextNode.#children["*"], method, node.#params)
|
|
3015
|
+
);
|
|
3016
|
+
}
|
|
3017
|
+
handlerSets.push(...this.#getHandlerSets(nextNode, method, node.#params));
|
|
3018
|
+
} else {
|
|
3019
|
+
tempNodes.push(nextNode);
|
|
3020
|
+
}
|
|
3021
|
+
}
|
|
3022
|
+
for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
|
|
3023
|
+
const pattern = node.#patterns[k];
|
|
3024
|
+
const params = node.#params === emptyParams ? {} : { ...node.#params };
|
|
3025
|
+
if (pattern === "*") {
|
|
3026
|
+
const astNode = node.#children["*"];
|
|
3027
|
+
if (astNode) {
|
|
3028
|
+
handlerSets.push(...this.#getHandlerSets(astNode, method, node.#params));
|
|
3029
|
+
astNode.#params = params;
|
|
3030
|
+
tempNodes.push(astNode);
|
|
3031
|
+
}
|
|
3032
|
+
continue;
|
|
3033
|
+
}
|
|
3034
|
+
const [key, name, matcher] = pattern;
|
|
3035
|
+
if (!part && !(matcher instanceof RegExp)) {
|
|
3036
|
+
continue;
|
|
3037
|
+
}
|
|
3038
|
+
const child = node.#children[key];
|
|
3039
|
+
const restPathString = parts.slice(i).join("/");
|
|
3040
|
+
if (matcher instanceof RegExp) {
|
|
3041
|
+
const m = matcher.exec(restPathString);
|
|
3042
|
+
if (m) {
|
|
3043
|
+
params[name] = m[0];
|
|
3044
|
+
handlerSets.push(...this.#getHandlerSets(child, method, node.#params, params));
|
|
3045
|
+
if (Object.keys(child.#children).length) {
|
|
3046
|
+
child.#params = params;
|
|
3047
|
+
const componentCount = m[0].match(/\//)?.length ?? 0;
|
|
3048
|
+
const targetCurNodes = curNodesQueue[componentCount] ||= [];
|
|
3049
|
+
targetCurNodes.push(child);
|
|
3050
|
+
}
|
|
3051
|
+
continue;
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
if (matcher === true || matcher.test(part)) {
|
|
3055
|
+
params[name] = part;
|
|
3056
|
+
if (isLast) {
|
|
3057
|
+
handlerSets.push(...this.#getHandlerSets(child, method, params, node.#params));
|
|
3058
|
+
if (child.#children["*"]) {
|
|
3059
|
+
handlerSets.push(
|
|
3060
|
+
...this.#getHandlerSets(child.#children["*"], method, params, node.#params)
|
|
3061
|
+
);
|
|
3062
|
+
}
|
|
3063
|
+
} else {
|
|
3064
|
+
child.#params = params;
|
|
3065
|
+
tempNodes.push(child);
|
|
3066
|
+
}
|
|
3067
|
+
}
|
|
3068
|
+
}
|
|
3069
|
+
}
|
|
3070
|
+
curNodes = tempNodes.concat(curNodesQueue.shift() ?? []);
|
|
3071
|
+
}
|
|
3072
|
+
if (handlerSets.length > 1) {
|
|
3073
|
+
handlerSets.sort((a, b) => {
|
|
3074
|
+
return a.score - b.score;
|
|
3075
|
+
});
|
|
3076
|
+
}
|
|
3077
|
+
return [handlerSets.map(({ handler, params }) => [handler, params])];
|
|
3078
|
+
}
|
|
3079
|
+
};
|
|
3080
|
+
|
|
3081
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/router/trie-router/router.js
|
|
3082
|
+
var TrieRouter = class {
|
|
3083
|
+
name = "TrieRouter";
|
|
3084
|
+
#node;
|
|
3085
|
+
constructor() {
|
|
3086
|
+
this.#node = new Node2();
|
|
3087
|
+
}
|
|
3088
|
+
add(method, path, handler) {
|
|
3089
|
+
const results = checkOptionalParameter(path);
|
|
3090
|
+
if (results) {
|
|
3091
|
+
for (let i = 0, len = results.length; i < len; i++) {
|
|
3092
|
+
this.#node.insert(method, results[i], handler);
|
|
3093
|
+
}
|
|
3094
|
+
return;
|
|
3095
|
+
}
|
|
3096
|
+
this.#node.insert(method, path, handler);
|
|
3097
|
+
}
|
|
3098
|
+
match(method, path) {
|
|
3099
|
+
return this.#node.search(method, path);
|
|
3100
|
+
}
|
|
3101
|
+
};
|
|
3102
|
+
|
|
3103
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/hono.js
|
|
3104
|
+
var Hono2 = class extends Hono {
|
|
3105
|
+
constructor(options = {}) {
|
|
3106
|
+
super(options);
|
|
3107
|
+
this.router = options.router ?? new SmartRouter({
|
|
3108
|
+
routers: [new RegExpRouter(), new TrieRouter()]
|
|
3109
|
+
});
|
|
3110
|
+
}
|
|
3111
|
+
};
|
|
3112
|
+
|
|
3113
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/middleware/cors/index.js
|
|
3114
|
+
var cors = (options) => {
|
|
3115
|
+
const defaults = {
|
|
3116
|
+
origin: "*",
|
|
3117
|
+
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"],
|
|
3118
|
+
allowHeaders: [],
|
|
3119
|
+
exposeHeaders: []
|
|
3120
|
+
};
|
|
3121
|
+
const opts = {
|
|
3122
|
+
...defaults,
|
|
3123
|
+
...options
|
|
3124
|
+
};
|
|
3125
|
+
const findAllowOrigin = ((optsOrigin) => {
|
|
3126
|
+
if (typeof optsOrigin === "string") {
|
|
3127
|
+
if (optsOrigin === "*") {
|
|
3128
|
+
return () => optsOrigin;
|
|
3129
|
+
} else {
|
|
3130
|
+
return (origin) => optsOrigin === origin ? origin : null;
|
|
3131
|
+
}
|
|
3132
|
+
} else if (typeof optsOrigin === "function") {
|
|
3133
|
+
return optsOrigin;
|
|
3134
|
+
} else {
|
|
3135
|
+
return (origin) => optsOrigin.includes(origin) ? origin : null;
|
|
3136
|
+
}
|
|
3137
|
+
})(opts.origin);
|
|
3138
|
+
const findAllowMethods = ((optsAllowMethods) => {
|
|
3139
|
+
if (typeof optsAllowMethods === "function") {
|
|
3140
|
+
return optsAllowMethods;
|
|
3141
|
+
} else if (Array.isArray(optsAllowMethods)) {
|
|
3142
|
+
return () => optsAllowMethods;
|
|
3143
|
+
} else {
|
|
3144
|
+
return () => [];
|
|
3145
|
+
}
|
|
3146
|
+
})(opts.allowMethods);
|
|
3147
|
+
return async function cors2(c, next) {
|
|
3148
|
+
function set(key, value) {
|
|
3149
|
+
c.res.headers.set(key, value);
|
|
3150
|
+
}
|
|
3151
|
+
const allowOrigin = await findAllowOrigin(c.req.header("origin") || "", c);
|
|
3152
|
+
if (allowOrigin) {
|
|
3153
|
+
set("Access-Control-Allow-Origin", allowOrigin);
|
|
3154
|
+
}
|
|
3155
|
+
if (opts.credentials) {
|
|
3156
|
+
set("Access-Control-Allow-Credentials", "true");
|
|
3157
|
+
}
|
|
3158
|
+
if (opts.exposeHeaders?.length) {
|
|
3159
|
+
set("Access-Control-Expose-Headers", opts.exposeHeaders.join(","));
|
|
3160
|
+
}
|
|
3161
|
+
if (c.req.method === "OPTIONS") {
|
|
3162
|
+
if (opts.origin !== "*") {
|
|
3163
|
+
set("Vary", "Origin");
|
|
3164
|
+
}
|
|
3165
|
+
if (opts.maxAge != null) {
|
|
3166
|
+
set("Access-Control-Max-Age", opts.maxAge.toString());
|
|
3167
|
+
}
|
|
3168
|
+
const allowMethods = await findAllowMethods(c.req.header("origin") || "", c);
|
|
3169
|
+
if (allowMethods.length) {
|
|
3170
|
+
set("Access-Control-Allow-Methods", allowMethods.join(","));
|
|
3171
|
+
}
|
|
3172
|
+
let headers = opts.allowHeaders;
|
|
3173
|
+
if (!headers?.length) {
|
|
3174
|
+
const requestHeaders = c.req.header("Access-Control-Request-Headers");
|
|
3175
|
+
if (requestHeaders) {
|
|
3176
|
+
headers = requestHeaders.split(/\s*,\s*/);
|
|
3177
|
+
}
|
|
3178
|
+
}
|
|
3179
|
+
if (headers?.length) {
|
|
3180
|
+
set("Access-Control-Allow-Headers", headers.join(","));
|
|
3181
|
+
c.res.headers.append("Vary", "Access-Control-Request-Headers");
|
|
3182
|
+
}
|
|
3183
|
+
c.res.headers.delete("Content-Length");
|
|
3184
|
+
c.res.headers.delete("Content-Type");
|
|
3185
|
+
return new Response(null, {
|
|
3186
|
+
headers: c.res.headers,
|
|
3187
|
+
status: 204,
|
|
3188
|
+
statusText: "No Content"
|
|
3189
|
+
});
|
|
3190
|
+
}
|
|
3191
|
+
await next();
|
|
3192
|
+
if (opts.origin !== "*") {
|
|
3193
|
+
c.header("Vary", "Origin", { append: true });
|
|
3194
|
+
}
|
|
3195
|
+
};
|
|
3196
|
+
};
|
|
3197
|
+
|
|
3198
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/utils/stream.js
|
|
3199
|
+
var StreamingApi = class {
|
|
3200
|
+
writer;
|
|
3201
|
+
encoder;
|
|
3202
|
+
writable;
|
|
3203
|
+
abortSubscribers = [];
|
|
3204
|
+
responseReadable;
|
|
3205
|
+
aborted = false;
|
|
3206
|
+
closed = false;
|
|
3207
|
+
constructor(writable, _readable) {
|
|
3208
|
+
this.writable = writable;
|
|
3209
|
+
this.writer = writable.getWriter();
|
|
3210
|
+
this.encoder = new TextEncoder();
|
|
3211
|
+
const reader = _readable.getReader();
|
|
3212
|
+
this.abortSubscribers.push(async () => {
|
|
3213
|
+
await reader.cancel();
|
|
3214
|
+
});
|
|
3215
|
+
this.responseReadable = new ReadableStream({
|
|
3216
|
+
async pull(controller) {
|
|
3217
|
+
const { done, value } = await reader.read();
|
|
3218
|
+
done ? controller.close() : controller.enqueue(value);
|
|
3219
|
+
},
|
|
3220
|
+
cancel: () => {
|
|
3221
|
+
this.abort();
|
|
3222
|
+
}
|
|
3223
|
+
});
|
|
3224
|
+
}
|
|
3225
|
+
async write(input) {
|
|
3226
|
+
try {
|
|
3227
|
+
if (typeof input === "string") {
|
|
3228
|
+
input = this.encoder.encode(input);
|
|
3229
|
+
}
|
|
3230
|
+
await this.writer.write(input);
|
|
3231
|
+
} catch {
|
|
3232
|
+
}
|
|
3233
|
+
return this;
|
|
3234
|
+
}
|
|
3235
|
+
async writeln(input) {
|
|
3236
|
+
await this.write(input + "\n");
|
|
3237
|
+
return this;
|
|
3238
|
+
}
|
|
3239
|
+
sleep(ms) {
|
|
3240
|
+
return new Promise((res) => setTimeout(res, ms));
|
|
3241
|
+
}
|
|
3242
|
+
async close() {
|
|
3243
|
+
try {
|
|
3244
|
+
await this.writer.close();
|
|
3245
|
+
} catch {
|
|
3246
|
+
}
|
|
3247
|
+
this.closed = true;
|
|
3248
|
+
}
|
|
3249
|
+
async pipe(body) {
|
|
3250
|
+
this.writer.releaseLock();
|
|
3251
|
+
await body.pipeTo(this.writable, { preventClose: true });
|
|
3252
|
+
this.writer = this.writable.getWriter();
|
|
3253
|
+
}
|
|
3254
|
+
onAbort(listener) {
|
|
3255
|
+
this.abortSubscribers.push(listener);
|
|
3256
|
+
}
|
|
3257
|
+
abort() {
|
|
3258
|
+
if (!this.aborted) {
|
|
3259
|
+
this.aborted = true;
|
|
3260
|
+
this.abortSubscribers.forEach((subscriber) => subscriber());
|
|
3261
|
+
}
|
|
3262
|
+
}
|
|
3263
|
+
};
|
|
3264
|
+
|
|
3265
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/helper/streaming/utils.js
|
|
3266
|
+
var isOldBunVersion = () => {
|
|
3267
|
+
const version = typeof Bun !== "undefined" ? Bun.version : void 0;
|
|
3268
|
+
if (version === void 0) {
|
|
3269
|
+
return false;
|
|
3270
|
+
}
|
|
3271
|
+
const result = version.startsWith("1.1") || version.startsWith("1.0") || version.startsWith("0.");
|
|
3272
|
+
isOldBunVersion = () => result;
|
|
3273
|
+
return result;
|
|
3274
|
+
};
|
|
3275
|
+
|
|
3276
|
+
// ../../node_modules/.pnpm/hono@4.10.7/node_modules/hono/dist/helper/streaming/sse.js
|
|
3277
|
+
var SSEStreamingApi = class extends StreamingApi {
|
|
3278
|
+
constructor(writable, readable) {
|
|
3279
|
+
super(writable, readable);
|
|
3280
|
+
}
|
|
3281
|
+
async writeSSE(message) {
|
|
3282
|
+
const data = await resolveCallback(message.data, HtmlEscapedCallbackPhase.Stringify, false, {});
|
|
3283
|
+
const dataLines = data.split("\n").map((line) => {
|
|
3284
|
+
return `data: ${line}`;
|
|
3285
|
+
}).join("\n");
|
|
3286
|
+
const sseData = [
|
|
3287
|
+
message.event && `event: ${message.event}`,
|
|
3288
|
+
dataLines,
|
|
3289
|
+
message.id && `id: ${message.id}`,
|
|
3290
|
+
message.retry && `retry: ${message.retry}`
|
|
3291
|
+
].filter(Boolean).join("\n") + "\n\n";
|
|
3292
|
+
await this.write(sseData);
|
|
3293
|
+
}
|
|
3294
|
+
};
|
|
3295
|
+
var run = async (stream2, cb, onError) => {
|
|
3296
|
+
try {
|
|
3297
|
+
await cb(stream2);
|
|
3298
|
+
} catch (e) {
|
|
3299
|
+
{
|
|
3300
|
+
console.error(e);
|
|
3301
|
+
}
|
|
3302
|
+
} finally {
|
|
3303
|
+
stream2.close();
|
|
3304
|
+
}
|
|
3305
|
+
};
|
|
3306
|
+
var contextStash = /* @__PURE__ */ new WeakMap();
|
|
3307
|
+
var streamSSE = (c, cb, onError) => {
|
|
3308
|
+
const { readable, writable } = new TransformStream();
|
|
3309
|
+
const stream2 = new SSEStreamingApi(writable, readable);
|
|
3310
|
+
if (isOldBunVersion()) {
|
|
3311
|
+
c.req.raw.signal.addEventListener("abort", () => {
|
|
3312
|
+
if (!stream2.closed) {
|
|
3313
|
+
stream2.abort();
|
|
3314
|
+
}
|
|
3315
|
+
});
|
|
3316
|
+
}
|
|
3317
|
+
contextStash.set(stream2.responseReadable, c);
|
|
3318
|
+
c.header("Transfer-Encoding", "chunked");
|
|
3319
|
+
c.header("Content-Type", "text/event-stream");
|
|
3320
|
+
c.header("Cache-Control", "no-cache");
|
|
3321
|
+
c.header("Connection", "keep-alive");
|
|
3322
|
+
run(stream2, cb);
|
|
3323
|
+
return c.newResponse(stream2.responseReadable);
|
|
3324
|
+
};
|
|
3325
|
+
var RequestError = class extends Error {
|
|
3326
|
+
constructor(message, options) {
|
|
3327
|
+
super(message, options);
|
|
3328
|
+
this.name = "RequestError";
|
|
3329
|
+
}
|
|
3330
|
+
};
|
|
3331
|
+
var toRequestError = (e) => {
|
|
3332
|
+
if (e instanceof RequestError) {
|
|
3333
|
+
return e;
|
|
3334
|
+
}
|
|
3335
|
+
return new RequestError(e.message, { cause: e });
|
|
3336
|
+
};
|
|
3337
|
+
var GlobalRequest = global.Request;
|
|
3338
|
+
var Request2 = class extends GlobalRequest {
|
|
3339
|
+
constructor(input, options) {
|
|
3340
|
+
if (typeof input === "object" && getRequestCache in input) {
|
|
3341
|
+
input = input[getRequestCache]();
|
|
3342
|
+
}
|
|
3343
|
+
if (typeof options?.body?.getReader !== "undefined") {
|
|
3344
|
+
options.duplex ??= "half";
|
|
3345
|
+
}
|
|
3346
|
+
super(input, options);
|
|
3347
|
+
}
|
|
3348
|
+
};
|
|
3349
|
+
var newHeadersFromIncoming = (incoming) => {
|
|
3350
|
+
const headerRecord = [];
|
|
3351
|
+
const rawHeaders = incoming.rawHeaders;
|
|
3352
|
+
for (let i = 0; i < rawHeaders.length; i += 2) {
|
|
3353
|
+
const { [i]: key, [i + 1]: value } = rawHeaders;
|
|
3354
|
+
if (key.charCodeAt(0) !== /*:*/
|
|
3355
|
+
58) {
|
|
3356
|
+
headerRecord.push([key, value]);
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
3359
|
+
return new Headers(headerRecord);
|
|
3360
|
+
};
|
|
3361
|
+
var wrapBodyStream = Symbol("wrapBodyStream");
|
|
3362
|
+
var newRequestFromIncoming = (method, url, headers, incoming, abortController) => {
|
|
3363
|
+
const init = {
|
|
3364
|
+
method,
|
|
3365
|
+
headers,
|
|
3366
|
+
signal: abortController.signal
|
|
3367
|
+
};
|
|
3368
|
+
if (method === "TRACE") {
|
|
3369
|
+
init.method = "GET";
|
|
3370
|
+
const req = new Request2(url, init);
|
|
3371
|
+
Object.defineProperty(req, "method", {
|
|
3372
|
+
get() {
|
|
3373
|
+
return "TRACE";
|
|
3374
|
+
}
|
|
3375
|
+
});
|
|
3376
|
+
return req;
|
|
3377
|
+
}
|
|
3378
|
+
if (!(method === "GET" || method === "HEAD")) {
|
|
3379
|
+
if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) {
|
|
3380
|
+
init.body = new ReadableStream({
|
|
3381
|
+
start(controller) {
|
|
3382
|
+
controller.enqueue(incoming.rawBody);
|
|
3383
|
+
controller.close();
|
|
3384
|
+
}
|
|
3385
|
+
});
|
|
3386
|
+
} else if (incoming[wrapBodyStream]) {
|
|
3387
|
+
let reader;
|
|
3388
|
+
init.body = new ReadableStream({
|
|
3389
|
+
async pull(controller) {
|
|
3390
|
+
try {
|
|
3391
|
+
reader ||= stream.Readable.toWeb(incoming).getReader();
|
|
3392
|
+
const { done, value } = await reader.read();
|
|
3393
|
+
if (done) {
|
|
3394
|
+
controller.close();
|
|
3395
|
+
} else {
|
|
3396
|
+
controller.enqueue(value);
|
|
3397
|
+
}
|
|
3398
|
+
} catch (error) {
|
|
3399
|
+
controller.error(error);
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
});
|
|
3403
|
+
} else {
|
|
3404
|
+
init.body = stream.Readable.toWeb(incoming);
|
|
3405
|
+
}
|
|
3406
|
+
}
|
|
3407
|
+
return new Request2(url, init);
|
|
3408
|
+
};
|
|
3409
|
+
var getRequestCache = Symbol("getRequestCache");
|
|
3410
|
+
var requestCache = Symbol("requestCache");
|
|
3411
|
+
var incomingKey = Symbol("incomingKey");
|
|
3412
|
+
var urlKey = Symbol("urlKey");
|
|
3413
|
+
var headersKey = Symbol("headersKey");
|
|
3414
|
+
var abortControllerKey = Symbol("abortControllerKey");
|
|
3415
|
+
var getAbortController = Symbol("getAbortController");
|
|
3416
|
+
var requestPrototype = {
|
|
3417
|
+
get method() {
|
|
3418
|
+
return this[incomingKey].method || "GET";
|
|
3419
|
+
},
|
|
3420
|
+
get url() {
|
|
3421
|
+
return this[urlKey];
|
|
3422
|
+
},
|
|
3423
|
+
get headers() {
|
|
3424
|
+
return this[headersKey] ||= newHeadersFromIncoming(this[incomingKey]);
|
|
3425
|
+
},
|
|
3426
|
+
[getAbortController]() {
|
|
3427
|
+
this[getRequestCache]();
|
|
3428
|
+
return this[abortControllerKey];
|
|
3429
|
+
},
|
|
3430
|
+
[getRequestCache]() {
|
|
3431
|
+
this[abortControllerKey] ||= new AbortController();
|
|
3432
|
+
return this[requestCache] ||= newRequestFromIncoming(
|
|
3433
|
+
this.method,
|
|
3434
|
+
this[urlKey],
|
|
3435
|
+
this.headers,
|
|
3436
|
+
this[incomingKey],
|
|
3437
|
+
this[abortControllerKey]
|
|
3438
|
+
);
|
|
3439
|
+
}
|
|
3440
|
+
};
|
|
3441
|
+
[
|
|
3442
|
+
"body",
|
|
3443
|
+
"bodyUsed",
|
|
3444
|
+
"cache",
|
|
3445
|
+
"credentials",
|
|
3446
|
+
"destination",
|
|
3447
|
+
"integrity",
|
|
3448
|
+
"mode",
|
|
3449
|
+
"redirect",
|
|
3450
|
+
"referrer",
|
|
3451
|
+
"referrerPolicy",
|
|
3452
|
+
"signal",
|
|
3453
|
+
"keepalive"
|
|
3454
|
+
].forEach((k) => {
|
|
3455
|
+
Object.defineProperty(requestPrototype, k, {
|
|
3456
|
+
get() {
|
|
3457
|
+
return this[getRequestCache]()[k];
|
|
3458
|
+
}
|
|
3459
|
+
});
|
|
3460
|
+
});
|
|
3461
|
+
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
3462
|
+
Object.defineProperty(requestPrototype, k, {
|
|
3463
|
+
value: function() {
|
|
3464
|
+
return this[getRequestCache]()[k]();
|
|
3465
|
+
}
|
|
3466
|
+
});
|
|
3467
|
+
});
|
|
3468
|
+
Object.setPrototypeOf(requestPrototype, Request2.prototype);
|
|
3469
|
+
var newRequest = (incoming, defaultHostname) => {
|
|
3470
|
+
const req = Object.create(requestPrototype);
|
|
3471
|
+
req[incomingKey] = incoming;
|
|
3472
|
+
const incomingUrl = incoming.url || "";
|
|
3473
|
+
if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL.
|
|
3474
|
+
(incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
|
|
3475
|
+
if (incoming instanceof http2.Http2ServerRequest) {
|
|
3476
|
+
throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
|
|
3477
|
+
}
|
|
3478
|
+
try {
|
|
3479
|
+
const url2 = new URL(incomingUrl);
|
|
3480
|
+
req[urlKey] = url2.href;
|
|
3481
|
+
} catch (e) {
|
|
3482
|
+
throw new RequestError("Invalid absolute URL", { cause: e });
|
|
3483
|
+
}
|
|
3484
|
+
return req;
|
|
3485
|
+
}
|
|
3486
|
+
const host = (incoming instanceof http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
|
|
3487
|
+
if (!host) {
|
|
3488
|
+
throw new RequestError("Missing host header");
|
|
3489
|
+
}
|
|
3490
|
+
let scheme;
|
|
3491
|
+
if (incoming instanceof http2.Http2ServerRequest) {
|
|
3492
|
+
scheme = incoming.scheme;
|
|
3493
|
+
if (!(scheme === "http" || scheme === "https")) {
|
|
3494
|
+
throw new RequestError("Unsupported scheme");
|
|
3495
|
+
}
|
|
3496
|
+
} else {
|
|
3497
|
+
scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
|
|
3498
|
+
}
|
|
3499
|
+
const url = new URL(`${scheme}://${host}${incomingUrl}`);
|
|
3500
|
+
if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
|
|
3501
|
+
throw new RequestError("Invalid host header");
|
|
3502
|
+
}
|
|
3503
|
+
req[urlKey] = url.href;
|
|
3504
|
+
return req;
|
|
3505
|
+
};
|
|
3506
|
+
var responseCache = Symbol("responseCache");
|
|
3507
|
+
var getResponseCache = Symbol("getResponseCache");
|
|
3508
|
+
var cacheKey = Symbol("cache");
|
|
3509
|
+
var GlobalResponse = global.Response;
|
|
3510
|
+
var Response2 = class _Response {
|
|
3511
|
+
#body;
|
|
3512
|
+
#init;
|
|
3513
|
+
[getResponseCache]() {
|
|
3514
|
+
delete this[cacheKey];
|
|
3515
|
+
return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
|
|
3516
|
+
}
|
|
3517
|
+
constructor(body, init) {
|
|
3518
|
+
let headers;
|
|
3519
|
+
this.#body = body;
|
|
3520
|
+
if (init instanceof _Response) {
|
|
3521
|
+
const cachedGlobalResponse = init[responseCache];
|
|
3522
|
+
if (cachedGlobalResponse) {
|
|
3523
|
+
this.#init = cachedGlobalResponse;
|
|
3524
|
+
this[getResponseCache]();
|
|
3525
|
+
return;
|
|
3526
|
+
} else {
|
|
3527
|
+
this.#init = init.#init;
|
|
3528
|
+
headers = new Headers(init.#init.headers);
|
|
3529
|
+
}
|
|
3530
|
+
} else {
|
|
3531
|
+
this.#init = init;
|
|
3532
|
+
}
|
|
3533
|
+
if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
|
|
3534
|
+
headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
|
|
3535
|
+
this[cacheKey] = [init?.status || 200, body, headers];
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
get headers() {
|
|
3539
|
+
const cache = this[cacheKey];
|
|
3540
|
+
if (cache) {
|
|
3541
|
+
if (!(cache[2] instanceof Headers)) {
|
|
3542
|
+
cache[2] = new Headers(cache[2]);
|
|
3543
|
+
}
|
|
3544
|
+
return cache[2];
|
|
3545
|
+
}
|
|
3546
|
+
return this[getResponseCache]().headers;
|
|
3547
|
+
}
|
|
3548
|
+
get status() {
|
|
3549
|
+
return this[cacheKey]?.[0] ?? this[getResponseCache]().status;
|
|
3550
|
+
}
|
|
3551
|
+
get ok() {
|
|
3552
|
+
const status = this.status;
|
|
3553
|
+
return status >= 200 && status < 300;
|
|
3554
|
+
}
|
|
3555
|
+
};
|
|
3556
|
+
["body", "bodyUsed", "redirected", "statusText", "trailers", "type", "url"].forEach((k) => {
|
|
3557
|
+
Object.defineProperty(Response2.prototype, k, {
|
|
3558
|
+
get() {
|
|
3559
|
+
return this[getResponseCache]()[k];
|
|
3560
|
+
}
|
|
3561
|
+
});
|
|
3562
|
+
});
|
|
3563
|
+
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
3564
|
+
Object.defineProperty(Response2.prototype, k, {
|
|
3565
|
+
value: function() {
|
|
3566
|
+
return this[getResponseCache]()[k]();
|
|
3567
|
+
}
|
|
3568
|
+
});
|
|
3569
|
+
});
|
|
3570
|
+
Object.setPrototypeOf(Response2, GlobalResponse);
|
|
3571
|
+
Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
|
|
3572
|
+
async function readWithoutBlocking(readPromise) {
|
|
3573
|
+
return Promise.race([readPromise, Promise.resolve().then(() => Promise.resolve(void 0))]);
|
|
3574
|
+
}
|
|
3575
|
+
function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromise) {
|
|
3576
|
+
const cancel = (error) => {
|
|
3577
|
+
reader.cancel(error).catch(() => {
|
|
3578
|
+
});
|
|
3579
|
+
};
|
|
3580
|
+
writable.on("close", cancel);
|
|
3581
|
+
writable.on("error", cancel);
|
|
3582
|
+
(currentReadPromise ?? reader.read()).then(flow, handleStreamError);
|
|
3583
|
+
return reader.closed.finally(() => {
|
|
3584
|
+
writable.off("close", cancel);
|
|
3585
|
+
writable.off("error", cancel);
|
|
3586
|
+
});
|
|
3587
|
+
function handleStreamError(error) {
|
|
3588
|
+
if (error) {
|
|
3589
|
+
writable.destroy(error);
|
|
3590
|
+
}
|
|
3591
|
+
}
|
|
3592
|
+
function onDrain() {
|
|
3593
|
+
reader.read().then(flow, handleStreamError);
|
|
3594
|
+
}
|
|
3595
|
+
function flow({ done, value }) {
|
|
3596
|
+
try {
|
|
3597
|
+
if (done) {
|
|
3598
|
+
writable.end();
|
|
3599
|
+
} else if (!writable.write(value)) {
|
|
3600
|
+
writable.once("drain", onDrain);
|
|
3601
|
+
} else {
|
|
3602
|
+
return reader.read().then(flow, handleStreamError);
|
|
3603
|
+
}
|
|
3604
|
+
} catch (e) {
|
|
3605
|
+
handleStreamError(e);
|
|
3606
|
+
}
|
|
3607
|
+
}
|
|
3608
|
+
}
|
|
3609
|
+
function writeFromReadableStream(stream2, writable) {
|
|
3610
|
+
if (stream2.locked) {
|
|
3611
|
+
throw new TypeError("ReadableStream is locked.");
|
|
3612
|
+
} else if (writable.destroyed) {
|
|
3613
|
+
return;
|
|
3614
|
+
}
|
|
3615
|
+
return writeFromReadableStreamDefaultReader(stream2.getReader(), writable);
|
|
3616
|
+
}
|
|
3617
|
+
var buildOutgoingHttpHeaders = (headers) => {
|
|
3618
|
+
const res = {};
|
|
3619
|
+
if (!(headers instanceof Headers)) {
|
|
3620
|
+
headers = new Headers(headers ?? void 0);
|
|
3621
|
+
}
|
|
3622
|
+
const cookies = [];
|
|
3623
|
+
for (const [k, v] of headers) {
|
|
3624
|
+
if (k === "set-cookie") {
|
|
3625
|
+
cookies.push(v);
|
|
3626
|
+
} else {
|
|
3627
|
+
res[k] = v;
|
|
3628
|
+
}
|
|
3629
|
+
}
|
|
3630
|
+
if (cookies.length > 0) {
|
|
3631
|
+
res["set-cookie"] = cookies;
|
|
3632
|
+
}
|
|
3633
|
+
res["content-type"] ??= "text/plain; charset=UTF-8";
|
|
3634
|
+
return res;
|
|
3635
|
+
};
|
|
3636
|
+
var X_ALREADY_SENT = "x-hono-already-sent";
|
|
3637
|
+
var webFetch = global.fetch;
|
|
3638
|
+
if (typeof global.crypto === "undefined") {
|
|
3639
|
+
global.crypto = crypto__default.default;
|
|
3640
|
+
}
|
|
3641
|
+
global.fetch = (info, init) => {
|
|
3642
|
+
init = {
|
|
3643
|
+
// Disable compression handling so people can return the result of a fetch
|
|
3644
|
+
// directly in the loader without messing with the Content-Encoding header.
|
|
3645
|
+
compress: false,
|
|
3646
|
+
...init
|
|
3647
|
+
};
|
|
3648
|
+
return webFetch(info, init);
|
|
3649
|
+
};
|
|
3650
|
+
var outgoingEnded = Symbol("outgoingEnded");
|
|
3651
|
+
var handleRequestError = () => new Response(null, {
|
|
3652
|
+
status: 400
|
|
3653
|
+
});
|
|
3654
|
+
var handleFetchError = (e) => new Response(null, {
|
|
3655
|
+
status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500
|
|
3656
|
+
});
|
|
3657
|
+
var handleResponseError = (e, outgoing) => {
|
|
3658
|
+
const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
|
|
3659
|
+
if (err.code === "ERR_STREAM_PREMATURE_CLOSE") {
|
|
3660
|
+
console.info("The user aborted a request.");
|
|
3661
|
+
} else {
|
|
3662
|
+
console.error(e);
|
|
3663
|
+
if (!outgoing.headersSent) {
|
|
3664
|
+
outgoing.writeHead(500, { "Content-Type": "text/plain" });
|
|
3665
|
+
}
|
|
3666
|
+
outgoing.end(`Error: ${err.message}`);
|
|
3667
|
+
outgoing.destroy(err);
|
|
3668
|
+
}
|
|
3669
|
+
};
|
|
3670
|
+
var flushHeaders = (outgoing) => {
|
|
3671
|
+
if ("flushHeaders" in outgoing && outgoing.writable) {
|
|
3672
|
+
outgoing.flushHeaders();
|
|
3673
|
+
}
|
|
3674
|
+
};
|
|
3675
|
+
var responseViaCache = async (res, outgoing) => {
|
|
3676
|
+
let [status, body, header] = res[cacheKey];
|
|
3677
|
+
if (header instanceof Headers) {
|
|
3678
|
+
header = buildOutgoingHttpHeaders(header);
|
|
3679
|
+
}
|
|
3680
|
+
if (typeof body === "string") {
|
|
3681
|
+
header["Content-Length"] = Buffer.byteLength(body);
|
|
3682
|
+
} else if (body instanceof Uint8Array) {
|
|
3683
|
+
header["Content-Length"] = body.byteLength;
|
|
3684
|
+
} else if (body instanceof Blob) {
|
|
3685
|
+
header["Content-Length"] = body.size;
|
|
3686
|
+
}
|
|
3687
|
+
outgoing.writeHead(status, header);
|
|
3688
|
+
if (typeof body === "string" || body instanceof Uint8Array) {
|
|
3689
|
+
outgoing.end(body);
|
|
3690
|
+
} else if (body instanceof Blob) {
|
|
3691
|
+
outgoing.end(new Uint8Array(await body.arrayBuffer()));
|
|
3692
|
+
} else {
|
|
3693
|
+
flushHeaders(outgoing);
|
|
3694
|
+
await writeFromReadableStream(body, outgoing)?.catch(
|
|
3695
|
+
(e) => handleResponseError(e, outgoing)
|
|
3696
|
+
);
|
|
3697
|
+
}
|
|
3698
|
+
outgoing[outgoingEnded]?.();
|
|
3699
|
+
};
|
|
3700
|
+
var isPromise = (res) => typeof res.then === "function";
|
|
3701
|
+
var responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
3702
|
+
if (isPromise(res)) {
|
|
3703
|
+
if (options.errorHandler) {
|
|
3704
|
+
try {
|
|
3705
|
+
res = await res;
|
|
3706
|
+
} catch (err) {
|
|
3707
|
+
const errRes = await options.errorHandler(err);
|
|
3708
|
+
if (!errRes) {
|
|
3709
|
+
return;
|
|
3710
|
+
}
|
|
3711
|
+
res = errRes;
|
|
3712
|
+
}
|
|
3713
|
+
} else {
|
|
3714
|
+
res = await res.catch(handleFetchError);
|
|
3715
|
+
}
|
|
3716
|
+
}
|
|
3717
|
+
if (cacheKey in res) {
|
|
3718
|
+
return responseViaCache(res, outgoing);
|
|
3719
|
+
}
|
|
3720
|
+
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
3721
|
+
if (res.body) {
|
|
3722
|
+
const reader = res.body.getReader();
|
|
3723
|
+
const values = [];
|
|
3724
|
+
let done = false;
|
|
3725
|
+
let currentReadPromise = void 0;
|
|
3726
|
+
if (resHeaderRecord["transfer-encoding"] !== "chunked") {
|
|
3727
|
+
let maxReadCount = 2;
|
|
3728
|
+
for (let i = 0; i < maxReadCount; i++) {
|
|
3729
|
+
currentReadPromise ||= reader.read();
|
|
3730
|
+
const chunk = await readWithoutBlocking(currentReadPromise).catch((e) => {
|
|
3731
|
+
console.error(e);
|
|
3732
|
+
done = true;
|
|
3733
|
+
});
|
|
3734
|
+
if (!chunk) {
|
|
3735
|
+
if (i === 1) {
|
|
3736
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
3737
|
+
maxReadCount = 3;
|
|
3738
|
+
continue;
|
|
3739
|
+
}
|
|
3740
|
+
break;
|
|
3741
|
+
}
|
|
3742
|
+
currentReadPromise = void 0;
|
|
3743
|
+
if (chunk.value) {
|
|
3744
|
+
values.push(chunk.value);
|
|
3745
|
+
}
|
|
3746
|
+
if (chunk.done) {
|
|
3747
|
+
done = true;
|
|
3748
|
+
break;
|
|
3749
|
+
}
|
|
3750
|
+
}
|
|
3751
|
+
if (done && !("content-length" in resHeaderRecord)) {
|
|
3752
|
+
resHeaderRecord["content-length"] = values.reduce((acc, value) => acc + value.length, 0);
|
|
3753
|
+
}
|
|
3754
|
+
}
|
|
3755
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
3756
|
+
values.forEach((value) => {
|
|
3757
|
+
outgoing.write(value);
|
|
3758
|
+
});
|
|
3759
|
+
if (done) {
|
|
3760
|
+
outgoing.end();
|
|
3761
|
+
} else {
|
|
3762
|
+
if (values.length === 0) {
|
|
3763
|
+
flushHeaders(outgoing);
|
|
3764
|
+
}
|
|
3765
|
+
await writeFromReadableStreamDefaultReader(reader, outgoing, currentReadPromise);
|
|
3766
|
+
}
|
|
3767
|
+
} else if (resHeaderRecord[X_ALREADY_SENT]) ; else {
|
|
3768
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
3769
|
+
outgoing.end();
|
|
3770
|
+
}
|
|
3771
|
+
outgoing[outgoingEnded]?.();
|
|
3772
|
+
};
|
|
3773
|
+
var getRequestListener = (fetchCallback, options = {}) => {
|
|
3774
|
+
const autoCleanupIncoming = options.autoCleanupIncoming ?? true;
|
|
3775
|
+
if (options.overrideGlobalObjects !== false && global.Request !== Request2) {
|
|
3776
|
+
Object.defineProperty(global, "Request", {
|
|
3777
|
+
value: Request2
|
|
3778
|
+
});
|
|
3779
|
+
Object.defineProperty(global, "Response", {
|
|
3780
|
+
value: Response2
|
|
3781
|
+
});
|
|
3782
|
+
}
|
|
3783
|
+
return async (incoming, outgoing) => {
|
|
3784
|
+
let res, req;
|
|
3785
|
+
try {
|
|
3786
|
+
req = newRequest(incoming, options.hostname);
|
|
3787
|
+
let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD";
|
|
3788
|
+
if (!incomingEnded) {
|
|
3789
|
+
;
|
|
3790
|
+
incoming[wrapBodyStream] = true;
|
|
3791
|
+
incoming.on("end", () => {
|
|
3792
|
+
incomingEnded = true;
|
|
3793
|
+
});
|
|
3794
|
+
if (incoming instanceof http2.Http2ServerRequest) {
|
|
3795
|
+
;
|
|
3796
|
+
outgoing[outgoingEnded] = () => {
|
|
3797
|
+
if (!incomingEnded) {
|
|
3798
|
+
setTimeout(() => {
|
|
3799
|
+
if (!incomingEnded) {
|
|
3800
|
+
setTimeout(() => {
|
|
3801
|
+
incoming.destroy();
|
|
3802
|
+
outgoing.destroy();
|
|
3803
|
+
});
|
|
3804
|
+
}
|
|
3805
|
+
});
|
|
3806
|
+
}
|
|
3807
|
+
};
|
|
3808
|
+
}
|
|
3809
|
+
}
|
|
3810
|
+
outgoing.on("close", () => {
|
|
3811
|
+
const abortController = req[abortControllerKey];
|
|
3812
|
+
if (abortController) {
|
|
3813
|
+
if (incoming.errored) {
|
|
3814
|
+
req[abortControllerKey].abort(incoming.errored.toString());
|
|
3815
|
+
} else if (!outgoing.writableFinished) {
|
|
3816
|
+
req[abortControllerKey].abort("Client connection prematurely closed.");
|
|
3817
|
+
}
|
|
3818
|
+
}
|
|
3819
|
+
if (!incomingEnded) {
|
|
3820
|
+
setTimeout(() => {
|
|
3821
|
+
if (!incomingEnded) {
|
|
3822
|
+
setTimeout(() => {
|
|
3823
|
+
incoming.destroy();
|
|
3824
|
+
});
|
|
3825
|
+
}
|
|
3826
|
+
});
|
|
3827
|
+
}
|
|
3828
|
+
});
|
|
3829
|
+
res = fetchCallback(req, { incoming, outgoing });
|
|
3830
|
+
if (cacheKey in res) {
|
|
3831
|
+
return responseViaCache(res, outgoing);
|
|
3832
|
+
}
|
|
3833
|
+
} catch (e) {
|
|
3834
|
+
if (!res) {
|
|
3835
|
+
if (options.errorHandler) {
|
|
3836
|
+
res = await options.errorHandler(req ? e : toRequestError(e));
|
|
3837
|
+
if (!res) {
|
|
3838
|
+
return;
|
|
3839
|
+
}
|
|
3840
|
+
} else if (!req) {
|
|
3841
|
+
res = handleRequestError();
|
|
3842
|
+
} else {
|
|
3843
|
+
res = handleFetchError(e);
|
|
3844
|
+
}
|
|
3845
|
+
} else {
|
|
3846
|
+
return handleResponseError(e, outgoing);
|
|
3847
|
+
}
|
|
3848
|
+
}
|
|
3849
|
+
try {
|
|
3850
|
+
return await responseViaResponseObject(res, outgoing, options);
|
|
3851
|
+
} catch (e) {
|
|
3852
|
+
return handleResponseError(e, outgoing);
|
|
3853
|
+
}
|
|
3854
|
+
};
|
|
3855
|
+
};
|
|
3856
|
+
var createAdaptorServer = (options) => {
|
|
3857
|
+
const fetchCallback = options.fetch;
|
|
3858
|
+
const requestListener = getRequestListener(fetchCallback, {
|
|
3859
|
+
hostname: options.hostname,
|
|
3860
|
+
overrideGlobalObjects: options.overrideGlobalObjects,
|
|
3861
|
+
autoCleanupIncoming: options.autoCleanupIncoming
|
|
3862
|
+
});
|
|
3863
|
+
const createServer2 = options.createServer || http.createServer;
|
|
3864
|
+
const server = createServer2(options.serverOptions || {}, requestListener);
|
|
3865
|
+
return server;
|
|
3866
|
+
};
|
|
3867
|
+
var serve = (options, listeningListener) => {
|
|
3868
|
+
const server = createAdaptorServer(options);
|
|
3869
|
+
server.listen(options?.port ?? 3e3, options.hostname, () => {
|
|
3870
|
+
server.address();
|
|
3871
|
+
});
|
|
3872
|
+
return server;
|
|
3873
|
+
};
|
|
3874
|
+
|
|
3875
|
+
// src/server.ts
|
|
3876
|
+
var import_picocolors = __toESM(require_picocolors());
|
|
3877
|
+
|
|
3878
|
+
// src/constants.ts
|
|
3879
|
+
var DEFAULT_PORT = 6567;
|
|
3880
|
+
var VERSION = "0.0.68";
|
|
3881
|
+
var opencodeInstance = null;
|
|
3882
|
+
var getOpencodeClient = async () => {
|
|
3883
|
+
if (!opencodeInstance) {
|
|
3884
|
+
const instance = await createOpencode({
|
|
3885
|
+
hostname: "127.0.0.1",
|
|
3886
|
+
port: 4096
|
|
3887
|
+
});
|
|
3888
|
+
opencodeInstance = instance;
|
|
3889
|
+
}
|
|
3890
|
+
return opencodeInstance.client;
|
|
3891
|
+
};
|
|
3892
|
+
var executeOpencodePrompt = async (prompt, options, onStatus) => {
|
|
3893
|
+
const client2 = await getOpencodeClient();
|
|
3894
|
+
onStatus?.("Planning next moves...");
|
|
3895
|
+
const sessionResponse = await client2.session.create({
|
|
3896
|
+
body: { title: "React Grab Session" }
|
|
3897
|
+
});
|
|
3898
|
+
if (sessionResponse.error || !sessionResponse.data) {
|
|
3899
|
+
throw new Error("Failed to create session");
|
|
3900
|
+
}
|
|
3901
|
+
const sessionId = sessionResponse.data.id;
|
|
3902
|
+
const modelConfig = options?.model ? {
|
|
3903
|
+
providerID: options.model.split("/")[0],
|
|
3904
|
+
modelID: options.model.split("/")[1] || options.model
|
|
3905
|
+
} : void 0;
|
|
3906
|
+
const promptResponse = await client2.session.prompt({
|
|
3907
|
+
path: { id: sessionId },
|
|
3908
|
+
body: {
|
|
3909
|
+
...modelConfig && { model: modelConfig },
|
|
3910
|
+
parts: [{ type: "text", text: prompt }]
|
|
3911
|
+
}
|
|
3912
|
+
});
|
|
3913
|
+
if (promptResponse.data?.parts) {
|
|
3914
|
+
for (const part of promptResponse.data.parts) {
|
|
3915
|
+
if (part.type === "text" && part.text) {
|
|
3916
|
+
onStatus?.(part.text);
|
|
3917
|
+
}
|
|
3918
|
+
}
|
|
3919
|
+
}
|
|
3920
|
+
};
|
|
3921
|
+
var createServer = () => {
|
|
3922
|
+
const honoApplication = new Hono2();
|
|
3923
|
+
honoApplication.use("/*", cors());
|
|
3924
|
+
honoApplication.post("/agent", async (context) => {
|
|
3925
|
+
const requestBody = await context.req.json();
|
|
3926
|
+
const { content, prompt, options } = requestBody;
|
|
3927
|
+
const formattedPrompt = `
|
|
3928
|
+
User Request: ${prompt}
|
|
3929
|
+
|
|
3930
|
+
Context:
|
|
3931
|
+
${content}
|
|
3932
|
+
`;
|
|
3933
|
+
return streamSSE(context, async (stream2) => {
|
|
3934
|
+
try {
|
|
3935
|
+
await executeOpencodePrompt(
|
|
3936
|
+
formattedPrompt,
|
|
3937
|
+
options,
|
|
3938
|
+
(text) => {
|
|
3939
|
+
stream2.writeSSE({
|
|
3940
|
+
data: text,
|
|
3941
|
+
event: "status"
|
|
3942
|
+
}).catch(() => {
|
|
3943
|
+
});
|
|
3944
|
+
}
|
|
3945
|
+
);
|
|
3946
|
+
await stream2.writeSSE({
|
|
3947
|
+
data: "Completed successfully",
|
|
3948
|
+
event: "status"
|
|
3949
|
+
});
|
|
3950
|
+
await stream2.writeSSE({ data: "", event: "done" });
|
|
3951
|
+
} catch (error) {
|
|
3952
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
3953
|
+
await stream2.writeSSE({
|
|
3954
|
+
data: `Error: ${errorMessage}`,
|
|
3955
|
+
event: "error"
|
|
3956
|
+
});
|
|
3957
|
+
await stream2.writeSSE({ data: "", event: "done" });
|
|
3958
|
+
}
|
|
3959
|
+
});
|
|
3960
|
+
});
|
|
3961
|
+
honoApplication.get("/health", (context) => {
|
|
3962
|
+
return context.json({ status: "ok", provider: "opencode" });
|
|
3963
|
+
});
|
|
3964
|
+
return honoApplication;
|
|
3965
|
+
};
|
|
3966
|
+
var isPortInUse = (port) => new Promise((resolve) => {
|
|
3967
|
+
const netServer = net__default.default.createServer();
|
|
3968
|
+
netServer.once("error", () => resolve(true));
|
|
3969
|
+
netServer.once("listening", () => {
|
|
3970
|
+
netServer.close();
|
|
3971
|
+
resolve(false);
|
|
3972
|
+
});
|
|
3973
|
+
netServer.listen(port);
|
|
3974
|
+
});
|
|
3975
|
+
var startServer = async (port = DEFAULT_PORT) => {
|
|
3976
|
+
if (await isPortInUse(port)) {
|
|
3977
|
+
return;
|
|
3978
|
+
}
|
|
3979
|
+
const honoApplication = createServer();
|
|
3980
|
+
serve({ fetch: honoApplication.fetch, port });
|
|
3981
|
+
console.log(`${import_picocolors.default.magenta("\u269B")} ${import_picocolors.default.bold("React Grab")} ${import_picocolors.default.gray(VERSION)} ${import_picocolors.default.dim("(Opencode)")}`);
|
|
3982
|
+
console.log(`- Local: ${import_picocolors.default.cyan(`http://localhost:${port}`)}`);
|
|
3983
|
+
};
|
|
3984
|
+
if ((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('server.cjs', document.baseURI).href)) === url.pathToFileURL(process.argv[1]).href) {
|
|
3985
|
+
startServer(DEFAULT_PORT).catch(console.error);
|
|
3986
|
+
}
|
|
3987
|
+
|
|
3988
|
+
exports.createServer = createServer;
|
|
3989
|
+
exports.startServer = startServer;
|