@react-grab/opencode 0.0.77 → 0.0.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import { spawn } from 'child_process';
3
2
  import { fileURLToPath } from 'url';
4
3
  import { dirname, join } from 'path';
5
4
 
@@ -9,7 +8,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
8
  var __getOwnPropNames = Object.getOwnPropertyNames;
10
9
  var __getProtoOf = Object.getPrototypeOf;
11
10
  var __hasOwnProp = Object.prototype.hasOwnProperty;
12
- var __commonJS = (cb, mod) => function __require() {
11
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
12
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
13
+ }) : x)(function(x) {
14
+ if (typeof require !== "undefined") return require.apply(this, arguments);
15
+ throw Error('Dynamic require of "' + x + '" is not supported');
16
+ });
17
+ var __commonJS = (cb, mod) => function __require2() {
13
18
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
14
19
  };
15
20
  var __copyProps = (to, from, except, desc) => {
@@ -29,6 +34,494 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
34
  mod
30
35
  ));
31
36
 
37
+ // ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js
38
+ var require_windows = __commonJS({
39
+ "../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js"(exports, module) {
40
+ module.exports = isexe;
41
+ isexe.sync = sync;
42
+ var fs = __require("fs");
43
+ function checkPathExt(path, options) {
44
+ var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT;
45
+ if (!pathext) {
46
+ return true;
47
+ }
48
+ pathext = pathext.split(";");
49
+ if (pathext.indexOf("") !== -1) {
50
+ return true;
51
+ }
52
+ for (var i = 0; i < pathext.length; i++) {
53
+ var p = pathext[i].toLowerCase();
54
+ if (p && path.substr(-p.length).toLowerCase() === p) {
55
+ return true;
56
+ }
57
+ }
58
+ return false;
59
+ }
60
+ function checkStat(stat, path, options) {
61
+ if (!stat.isSymbolicLink() && !stat.isFile()) {
62
+ return false;
63
+ }
64
+ return checkPathExt(path, options);
65
+ }
66
+ function isexe(path, options, cb) {
67
+ fs.stat(path, function(er, stat) {
68
+ cb(er, er ? false : checkStat(stat, path, options));
69
+ });
70
+ }
71
+ function sync(path, options) {
72
+ return checkStat(fs.statSync(path), path, options);
73
+ }
74
+ }
75
+ });
76
+
77
+ // ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js
78
+ var require_mode = __commonJS({
79
+ "../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js"(exports, module) {
80
+ module.exports = isexe;
81
+ isexe.sync = sync;
82
+ var fs = __require("fs");
83
+ function isexe(path, options, cb) {
84
+ fs.stat(path, function(er, stat) {
85
+ cb(er, er ? false : checkStat(stat, options));
86
+ });
87
+ }
88
+ function sync(path, options) {
89
+ return checkStat(fs.statSync(path), options);
90
+ }
91
+ function checkStat(stat, options) {
92
+ return stat.isFile() && checkMode(stat, options);
93
+ }
94
+ function checkMode(stat, options) {
95
+ var mod = stat.mode;
96
+ var uid = stat.uid;
97
+ var gid = stat.gid;
98
+ var myUid = options.uid !== void 0 ? options.uid : process.getuid && process.getuid();
99
+ var myGid = options.gid !== void 0 ? options.gid : process.getgid && process.getgid();
100
+ var u = parseInt("100", 8);
101
+ var g = parseInt("010", 8);
102
+ var o = parseInt("001", 8);
103
+ var ug = u | g;
104
+ var ret = mod & o || mod & g && gid === myGid || mod & u && uid === myUid || mod & ug && myUid === 0;
105
+ return ret;
106
+ }
107
+ }
108
+ });
109
+
110
+ // ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js
111
+ var require_isexe = __commonJS({
112
+ "../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js"(exports, module) {
113
+ __require("fs");
114
+ var core;
115
+ if (process.platform === "win32" || global.TESTING_WINDOWS) {
116
+ core = require_windows();
117
+ } else {
118
+ core = require_mode();
119
+ }
120
+ module.exports = isexe;
121
+ isexe.sync = sync;
122
+ function isexe(path, options, cb) {
123
+ if (typeof options === "function") {
124
+ cb = options;
125
+ options = {};
126
+ }
127
+ if (!cb) {
128
+ if (typeof Promise !== "function") {
129
+ throw new TypeError("callback not provided");
130
+ }
131
+ return new Promise(function(resolve, reject) {
132
+ isexe(path, options || {}, function(er, is) {
133
+ if (er) {
134
+ reject(er);
135
+ } else {
136
+ resolve(is);
137
+ }
138
+ });
139
+ });
140
+ }
141
+ core(path, options || {}, function(er, is) {
142
+ if (er) {
143
+ if (er.code === "EACCES" || options && options.ignoreErrors) {
144
+ er = null;
145
+ is = false;
146
+ }
147
+ }
148
+ cb(er, is);
149
+ });
150
+ }
151
+ function sync(path, options) {
152
+ try {
153
+ return core.sync(path, options || {});
154
+ } catch (er) {
155
+ if (options && options.ignoreErrors || er.code === "EACCES") {
156
+ return false;
157
+ } else {
158
+ throw er;
159
+ }
160
+ }
161
+ }
162
+ }
163
+ });
164
+
165
+ // ../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js
166
+ var require_which = __commonJS({
167
+ "../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js"(exports, module) {
168
+ var isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
169
+ var path = __require("path");
170
+ var COLON = isWindows ? ";" : ":";
171
+ var isexe = require_isexe();
172
+ var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" });
173
+ var getPathInfo = (cmd, opt) => {
174
+ const colon = opt.colon || COLON;
175
+ const pathEnv = cmd.match(/\//) || isWindows && cmd.match(/\\/) ? [""] : [
176
+ // windows always checks the cwd first
177
+ ...isWindows ? [process.cwd()] : [],
178
+ ...(opt.path || process.env.PATH || /* istanbul ignore next: very unusual */
179
+ "").split(colon)
180
+ ];
181
+ const pathExtExe = isWindows ? opt.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "";
182
+ const pathExt = isWindows ? pathExtExe.split(colon) : [""];
183
+ if (isWindows) {
184
+ if (cmd.indexOf(".") !== -1 && pathExt[0] !== "")
185
+ pathExt.unshift("");
186
+ }
187
+ return {
188
+ pathEnv,
189
+ pathExt,
190
+ pathExtExe
191
+ };
192
+ };
193
+ var which = (cmd, opt, cb) => {
194
+ if (typeof opt === "function") {
195
+ cb = opt;
196
+ opt = {};
197
+ }
198
+ if (!opt)
199
+ opt = {};
200
+ const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
201
+ const found = [];
202
+ const step = (i) => new Promise((resolve, reject) => {
203
+ if (i === pathEnv.length)
204
+ return opt.all && found.length ? resolve(found) : reject(getNotFoundError(cmd));
205
+ const ppRaw = pathEnv[i];
206
+ const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
207
+ const pCmd = path.join(pathPart, cmd);
208
+ const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
209
+ resolve(subStep(p, i, 0));
210
+ });
211
+ const subStep = (p, i, ii) => new Promise((resolve, reject) => {
212
+ if (ii === pathExt.length)
213
+ return resolve(step(i + 1));
214
+ const ext = pathExt[ii];
215
+ isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
216
+ if (!er && is) {
217
+ if (opt.all)
218
+ found.push(p + ext);
219
+ else
220
+ return resolve(p + ext);
221
+ }
222
+ return resolve(subStep(p, i, ii + 1));
223
+ });
224
+ });
225
+ return cb ? step(0).then((res) => cb(null, res), cb) : step(0);
226
+ };
227
+ var whichSync = (cmd, opt) => {
228
+ opt = opt || {};
229
+ const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
230
+ const found = [];
231
+ for (let i = 0; i < pathEnv.length; i++) {
232
+ const ppRaw = pathEnv[i];
233
+ const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
234
+ const pCmd = path.join(pathPart, cmd);
235
+ const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
236
+ for (let j = 0; j < pathExt.length; j++) {
237
+ const cur = p + pathExt[j];
238
+ try {
239
+ const is = isexe.sync(cur, { pathExt: pathExtExe });
240
+ if (is) {
241
+ if (opt.all)
242
+ found.push(cur);
243
+ else
244
+ return cur;
245
+ }
246
+ } catch (ex) {
247
+ }
248
+ }
249
+ }
250
+ if (opt.all && found.length)
251
+ return found;
252
+ if (opt.nothrow)
253
+ return null;
254
+ throw getNotFoundError(cmd);
255
+ };
256
+ module.exports = which;
257
+ which.sync = whichSync;
258
+ }
259
+ });
260
+
261
+ // ../../node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.js
262
+ var require_path_key = __commonJS({
263
+ "../../node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.js"(exports, module) {
264
+ var pathKey = (options = {}) => {
265
+ const environment = options.env || process.env;
266
+ const platform = options.platform || process.platform;
267
+ if (platform !== "win32") {
268
+ return "PATH";
269
+ }
270
+ return Object.keys(environment).reverse().find((key) => key.toUpperCase() === "PATH") || "Path";
271
+ };
272
+ module.exports = pathKey;
273
+ module.exports.default = pathKey;
274
+ }
275
+ });
276
+
277
+ // ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js
278
+ var require_resolveCommand = __commonJS({
279
+ "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js"(exports, module) {
280
+ var path = __require("path");
281
+ var which = require_which();
282
+ var getPathKey = require_path_key();
283
+ function resolveCommandAttempt(parsed, withoutPathExt) {
284
+ const env = parsed.options.env || process.env;
285
+ const cwd = process.cwd();
286
+ const hasCustomCwd = parsed.options.cwd != null;
287
+ const shouldSwitchCwd = hasCustomCwd && process.chdir !== void 0 && !process.chdir.disabled;
288
+ if (shouldSwitchCwd) {
289
+ try {
290
+ process.chdir(parsed.options.cwd);
291
+ } catch (err) {
292
+ }
293
+ }
294
+ let resolved;
295
+ try {
296
+ resolved = which.sync(parsed.command, {
297
+ path: env[getPathKey({ env })],
298
+ pathExt: withoutPathExt ? path.delimiter : void 0
299
+ });
300
+ } catch (e) {
301
+ } finally {
302
+ if (shouldSwitchCwd) {
303
+ process.chdir(cwd);
304
+ }
305
+ }
306
+ if (resolved) {
307
+ resolved = path.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
308
+ }
309
+ return resolved;
310
+ }
311
+ function resolveCommand(parsed) {
312
+ return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true);
313
+ }
314
+ module.exports = resolveCommand;
315
+ }
316
+ });
317
+
318
+ // ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js
319
+ var require_escape = __commonJS({
320
+ "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js"(exports, module) {
321
+ var metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
322
+ function escapeCommand(arg) {
323
+ arg = arg.replace(metaCharsRegExp, "^$1");
324
+ return arg;
325
+ }
326
+ function escapeArgument(arg, doubleEscapeMetaChars) {
327
+ arg = `${arg}`;
328
+ arg = arg.replace(/(?=(\\+?)?)\1"/g, '$1$1\\"');
329
+ arg = arg.replace(/(?=(\\+?)?)\1$/, "$1$1");
330
+ arg = `"${arg}"`;
331
+ arg = arg.replace(metaCharsRegExp, "^$1");
332
+ if (doubleEscapeMetaChars) {
333
+ arg = arg.replace(metaCharsRegExp, "^$1");
334
+ }
335
+ return arg;
336
+ }
337
+ module.exports.command = escapeCommand;
338
+ module.exports.argument = escapeArgument;
339
+ }
340
+ });
341
+
342
+ // ../../node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.js
343
+ var require_shebang_regex = __commonJS({
344
+ "../../node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.js"(exports, module) {
345
+ module.exports = /^#!(.*)/;
346
+ }
347
+ });
348
+
349
+ // ../../node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.js
350
+ var require_shebang_command = __commonJS({
351
+ "../../node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.js"(exports, module) {
352
+ var shebangRegex = require_shebang_regex();
353
+ module.exports = (string = "") => {
354
+ const match = string.match(shebangRegex);
355
+ if (!match) {
356
+ return null;
357
+ }
358
+ const [path, argument] = match[0].replace(/#! ?/, "").split(" ");
359
+ const binary = path.split("/").pop();
360
+ if (binary === "env") {
361
+ return argument;
362
+ }
363
+ return argument ? `${binary} ${argument}` : binary;
364
+ };
365
+ }
366
+ });
367
+
368
+ // ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js
369
+ var require_readShebang = __commonJS({
370
+ "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js"(exports, module) {
371
+ var fs = __require("fs");
372
+ var shebangCommand = require_shebang_command();
373
+ function readShebang(command) {
374
+ const size = 150;
375
+ const buffer = Buffer.alloc(size);
376
+ let fd;
377
+ try {
378
+ fd = fs.openSync(command, "r");
379
+ fs.readSync(fd, buffer, 0, size, 0);
380
+ fs.closeSync(fd);
381
+ } catch (e) {
382
+ }
383
+ return shebangCommand(buffer.toString());
384
+ }
385
+ module.exports = readShebang;
386
+ }
387
+ });
388
+
389
+ // ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js
390
+ var require_parse = __commonJS({
391
+ "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js"(exports, module) {
392
+ var path = __require("path");
393
+ var resolveCommand = require_resolveCommand();
394
+ var escape = require_escape();
395
+ var readShebang = require_readShebang();
396
+ var isWin = process.platform === "win32";
397
+ var isExecutableRegExp = /\.(?:com|exe)$/i;
398
+ var isCmdShimRegExp = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
399
+ function detectShebang(parsed) {
400
+ parsed.file = resolveCommand(parsed);
401
+ const shebang = parsed.file && readShebang(parsed.file);
402
+ if (shebang) {
403
+ parsed.args.unshift(parsed.file);
404
+ parsed.command = shebang;
405
+ return resolveCommand(parsed);
406
+ }
407
+ return parsed.file;
408
+ }
409
+ function parseNonShell(parsed) {
410
+ if (!isWin) {
411
+ return parsed;
412
+ }
413
+ const commandFile = detectShebang(parsed);
414
+ const needsShell = !isExecutableRegExp.test(commandFile);
415
+ if (parsed.options.forceShell || needsShell) {
416
+ const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
417
+ parsed.command = path.normalize(parsed.command);
418
+ parsed.command = escape.command(parsed.command);
419
+ parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
420
+ const shellCommand = [parsed.command].concat(parsed.args).join(" ");
421
+ parsed.args = ["/d", "/s", "/c", `"${shellCommand}"`];
422
+ parsed.command = process.env.comspec || "cmd.exe";
423
+ parsed.options.windowsVerbatimArguments = true;
424
+ }
425
+ return parsed;
426
+ }
427
+ function parse(command, args, options) {
428
+ if (args && !Array.isArray(args)) {
429
+ options = args;
430
+ args = null;
431
+ }
432
+ args = args ? args.slice(0) : [];
433
+ options = Object.assign({}, options);
434
+ const parsed = {
435
+ command,
436
+ args,
437
+ options,
438
+ file: void 0,
439
+ original: {
440
+ command,
441
+ args
442
+ }
443
+ };
444
+ return options.shell ? parsed : parseNonShell(parsed);
445
+ }
446
+ module.exports = parse;
447
+ }
448
+ });
449
+
450
+ // ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js
451
+ var require_enoent = __commonJS({
452
+ "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js"(exports, module) {
453
+ var isWin = process.platform === "win32";
454
+ function notFoundError(original, syscall) {
455
+ return Object.assign(new Error(`${syscall} ${original.command} ENOENT`), {
456
+ code: "ENOENT",
457
+ errno: "ENOENT",
458
+ syscall: `${syscall} ${original.command}`,
459
+ path: original.command,
460
+ spawnargs: original.args
461
+ });
462
+ }
463
+ function hookChildProcess(cp, parsed) {
464
+ if (!isWin) {
465
+ return;
466
+ }
467
+ const originalEmit = cp.emit;
468
+ cp.emit = function(name, arg1) {
469
+ if (name === "exit") {
470
+ const err = verifyENOENT(arg1, parsed);
471
+ if (err) {
472
+ return originalEmit.call(cp, "error", err);
473
+ }
474
+ }
475
+ return originalEmit.apply(cp, arguments);
476
+ };
477
+ }
478
+ function verifyENOENT(status, parsed) {
479
+ if (isWin && status === 1 && !parsed.file) {
480
+ return notFoundError(parsed.original, "spawn");
481
+ }
482
+ return null;
483
+ }
484
+ function verifyENOENTSync(status, parsed) {
485
+ if (isWin && status === 1 && !parsed.file) {
486
+ return notFoundError(parsed.original, "spawnSync");
487
+ }
488
+ return null;
489
+ }
490
+ module.exports = {
491
+ hookChildProcess,
492
+ verifyENOENT,
493
+ verifyENOENTSync,
494
+ notFoundError
495
+ };
496
+ }
497
+ });
498
+
499
+ // ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js
500
+ var require_cross_spawn = __commonJS({
501
+ "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js"(exports, module) {
502
+ var cp = __require("child_process");
503
+ var parse = require_parse();
504
+ var enoent = require_enoent();
505
+ function spawn2(command, args, options) {
506
+ const parsed = parse(command, args, options);
507
+ const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
508
+ enoent.hookChildProcess(spawned, parsed);
509
+ return spawned;
510
+ }
511
+ function spawnSync(command, args, options) {
512
+ const parsed = parse(command, args, options);
513
+ const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
514
+ result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
515
+ return result;
516
+ }
517
+ module.exports = spawn2;
518
+ module.exports.spawn = spawn2;
519
+ module.exports.sync = spawnSync;
520
+ module.exports._parse = parse;
521
+ module.exports._enoent = enoent;
522
+ }
523
+ });
524
+
32
525
  // ../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
33
526
  var require_picocolors = __commonJS({
34
527
  "../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js"(exports, module) {
@@ -102,17 +595,18 @@ var require_picocolors = __commonJS({
102
595
  });
103
596
 
104
597
  // src/cli.ts
598
+ var import_cross_spawn = __toESM(require_cross_spawn());
105
599
  var import_picocolors = __toESM(require_picocolors());
106
600
 
107
601
  // src/constants.ts
108
602
  var DEFAULT_PORT = 6567;
109
603
 
110
604
  // src/cli.ts
111
- var VERSION = "0.0.77";
605
+ var VERSION = "0.0.80";
112
606
  var __filename = fileURLToPath(import.meta.url);
113
607
  var __dirname = dirname(__filename);
114
608
  var serverPath = join(__dirname, "server.js");
115
- spawn(process.execPath, [serverPath], {
609
+ (0, import_cross_spawn.default)(process.execPath, [serverPath], {
116
610
  detached: true,
117
611
  stdio: "ignore"
118
612
  }).unref();
package/dist/client.cjs CHANGED
@@ -59,19 +59,33 @@ var streamSSE = async function* (stream, signal) {
59
59
  }
60
60
  };
61
61
  var streamFromServer = async function* (serverUrl, context, signal) {
62
- const response = await fetch(`${serverUrl}/agent`, {
63
- method: "POST",
64
- headers: { "Content-Type": "application/json" },
65
- body: JSON.stringify(context),
66
- signal
67
- });
68
- if (!response.ok) {
69
- throw new Error(`Server error: ${response.status}`);
70
- }
71
- if (!response.body) {
72
- throw new Error("No response body");
62
+ const sessionId = context.sessionId;
63
+ const handleAbort = () => {
64
+ if (sessionId) {
65
+ fetch(`${serverUrl}/abort/${sessionId}`, { method: "POST" }).catch(
66
+ () => {
67
+ }
68
+ );
69
+ }
70
+ };
71
+ signal.addEventListener("abort", handleAbort);
72
+ try {
73
+ const response = await fetch(`${serverUrl}/agent`, {
74
+ method: "POST",
75
+ headers: { "Content-Type": "application/json" },
76
+ body: JSON.stringify(context),
77
+ signal
78
+ });
79
+ if (!response.ok) {
80
+ throw new Error(`Server error: ${response.status}`);
81
+ }
82
+ if (!response.body) {
83
+ throw new Error("No response body");
84
+ }
85
+ yield* streamSSE(response.body, signal);
86
+ } finally {
87
+ signal.removeEventListener("abort", handleAbort);
73
88
  }
74
- yield* streamSSE(response.body, signal);
75
89
  };
76
90
  var createOpencodeAgentProvider = (options = {}) => {
77
91
  const { serverUrl = DEFAULT_SERVER_URL, getOptions } = options;
@@ -107,6 +121,7 @@ var createOpencodeAgentProvider = (options = {}) => {
107
121
  yield* streamFromServer(serverUrl, combinedContext, signal);
108
122
  },
109
123
  supportsResume: true,
124
+ supportsFollowUp: true,
110
125
  checkConnection: async () => {
111
126
  const now = Date.now();
112
127
  if (connectionCache && now - connectionCache.timestamp < CONNECTION_CHECK_TTL_MS) {
@@ -133,26 +148,26 @@ var createOpencodeAgentProvider = (options = {}) => {
133
148
  var attachAgent = async () => {
134
149
  if (typeof window === "undefined") return;
135
150
  const provider = createOpencodeAgentProvider();
151
+ const attach = (api2) => {
152
+ api2.setAgent({ provider, storage: sessionStorage });
153
+ };
136
154
  const api = window.__REACT_GRAB__;
137
155
  if (api) {
138
- api.setAgent({ provider, storage: sessionStorage });
156
+ attach(api);
139
157
  return;
140
158
  }
141
159
  window.addEventListener(
142
160
  "react-grab:init",
143
161
  (event) => {
144
- if (event instanceof CustomEvent) {
145
- const customEvent = event;
146
- if (customEvent.detail && typeof customEvent.detail.setAgent === "function") {
147
- customEvent.detail.setAgent({
148
- provider,
149
- storage: sessionStorage
150
- });
151
- }
152
- }
162
+ const customEvent = event;
163
+ attach(customEvent.detail);
153
164
  },
154
165
  { once: true }
155
166
  );
167
+ const apiAfterListener = window.__REACT_GRAB__;
168
+ if (apiAfterListener) {
169
+ attach(apiAfterListener);
170
+ }
156
171
  };
157
172
  attachAgent();
158
173
 
@@ -1,4 +1,4 @@
1
- var ReactGrabOpencode=(function(exports){'use strict';var m=`http://localhost:${6567}`,y="react-grab:agent-sessions",O=r=>{let t="",n="";for(let e of r.split(`
2
- `))e.startsWith("event:")?t=e.slice(6).trim():e.startsWith("data:")&&(n=e.slice(5).trim());return {eventType:t,data:n}},E=async function*(r,t){let n=r.getReader(),e=new TextDecoder,s="",o=false,a=()=>{o=true,n.cancel().catch(()=>{});};t.addEventListener("abort",a);try{if(t.aborted)throw new DOMException("Aborted","AbortError");for(;;){let i=await n.read();if(o||t.aborted)throw new DOMException("Aborted","AbortError");let{done:l,value:g}=i;g&&(s+=e.decode(g,{stream:!0}));let c;for(;(c=s.indexOf(`
1
+ var ReactGrabOpencode=(function(exports){'use strict';var m=`http://localhost:${6567}`,E="react-grab:agent-sessions",y=s=>{let t="",o="";for(let n of s.split(`
2
+ `))n.startsWith("event:")?t=n.slice(6).trim():n.startsWith("data:")&&(o=n.slice(5).trim());return {eventType:t,data:o}},O=async function*(s,t){let o=s.getReader(),n=new TextDecoder,r="",e=false,a=()=>{e=true,o.cancel().catch(()=>{});};t.addEventListener("abort",a);try{if(t.aborted)throw new DOMException("Aborted","AbortError");for(;;){let i=await o.read();if(e||t.aborted)throw new DOMException("Aborted","AbortError");let{done:l,value:g}=i;g&&(r+=n.decode(g,{stream:!0}));let c;for(;(c=r.indexOf(`
3
3
 
4
- `))!==-1;){let{eventType:d,data:p}=O(s.slice(0,c));if(s=s.slice(c+2),d==="done")return;if(d==="error")throw new Error(p||"Agent error");p&&(yield p);}if(l)break}}finally{t.removeEventListener("abort",a);try{n.releaseLock();}catch{}}},f=async function*(r,t,n){let e=await fetch(`${r}/agent`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:n});if(!e.ok)throw new Error(`Server error: ${e.status}`);if(!e.body)throw new Error("No response body");yield*E(e.body,n);},S=(r={})=>{let{serverUrl:t=m,getOptions:n}=r,e=null,s=o=>({...n?.()??{},...o??{}});return {send:async function*(o,a){let i={...o,options:s(o.options)};yield*f(t,i,a);},resume:async function*(o,a,i){let l=i.getItem(y);if(!l)throw new Error("No sessions to resume");let c=JSON.parse(l)[o];if(!c)throw new Error(`Session ${o} not found`);let d=c.context,p={...d,options:s(d.options)};yield "Resuming...",yield*f(t,p,a);},supportsResume:true,checkConnection:async()=>{let o=Date.now();if(e&&o-e.timestamp<5e3)return e.result;try{let i=(await fetch(`${t}/health`,{method:"GET"})).ok;return e={result:i,timestamp:o},i}catch{return e={result:false,timestamp:o},false}},undo:async()=>{try{await fetch(`${t}/undo`,{method:"POST"});}catch{}}}},b=async()=>{if(typeof window>"u")return;let r=S(),t=window.__REACT_GRAB__;if(t){t.setAgent({provider:r,storage:sessionStorage});return}window.addEventListener("react-grab:init",n=>{if(n instanceof CustomEvent){let e=n;e.detail&&typeof e.detail.setAgent=="function"&&e.detail.setAgent({provider:r,storage:sessionStorage});}},{once:true});};b();exports.attachAgent=b;exports.createOpencodeAgentProvider=S;return exports;})({});
4
+ `))!==-1;){let{eventType:d,data:p}=y(r.slice(0,c));if(r=r.slice(c+2),d==="done")return;if(d==="error")throw new Error(p||"Agent error");p&&(yield p);}if(l)break}}finally{t.removeEventListener("abort",a);try{o.releaseLock();}catch{}}},A=async function*(s,t,o){let n=t.sessionId,r=()=>{n&&fetch(`${s}/abort/${n}`,{method:"POST"}).catch(()=>{});};o.addEventListener("abort",r);try{let e=await fetch(`${s}/agent`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:o});if(!e.ok)throw new Error(`Server error: ${e.status}`);if(!e.body)throw new Error("No response body");yield*O(e.body,o);}finally{o.removeEventListener("abort",r);}},b=(s={})=>{let{serverUrl:t=m,getOptions:o}=s,n=null,r=e=>({...o?.()??{},...e??{}});return {send:async function*(e,a){let i={...e,options:r(e.options)};yield*A(t,i,a);},resume:async function*(e,a,i){let l=i.getItem(E);if(!l)throw new Error("No sessions to resume");let c=JSON.parse(l)[e];if(!c)throw new Error(`Session ${e} not found`);let d=c.context,p={...d,options:r(d.options)};yield "Resuming...",yield*A(t,p,a);},supportsResume:true,supportsFollowUp:true,checkConnection:async()=>{let e=Date.now();if(n&&e-n.timestamp<5e3)return n.result;try{let i=(await fetch(`${t}/health`,{method:"GET"})).ok;return n={result:i,timestamp:e},i}catch{return n={result:false,timestamp:e},false}},undo:async()=>{try{await fetch(`${t}/undo`,{method:"POST"});}catch{}}}},S=async()=>{if(typeof window>"u")return;let s=b(),t=r=>{r.setAgent({provider:s,storage:sessionStorage});},o=window.__REACT_GRAB__;if(o){t(o);return}window.addEventListener("react-grab:init",r=>{t(r.detail);},{once:true});let n=window.__REACT_GRAB__;n&&t(n);};S();exports.attachAgent=S;exports.createOpencodeAgentProvider=b;return exports;})({});