@react-grab/cursor 0.0.78 → 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 = 5567;
109
603
 
110
604
  // src/cli.ts
111
- var VERSION = "0.0.78";
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
@@ -57,19 +57,33 @@ async function* streamSSE(stream, signal) {
57
57
  }
58
58
  }
59
59
  async function* streamFromServer(serverUrl, context, signal) {
60
- const response = await fetch(`${serverUrl}/agent`, {
61
- method: "POST",
62
- headers: { "Content-Type": "application/json" },
63
- body: JSON.stringify(context),
64
- signal
65
- });
66
- if (!response.ok) {
67
- throw new Error(`Server error: ${response.status}`);
68
- }
69
- if (!response.body) {
70
- throw new Error("No response body");
60
+ const sessionId = context.sessionId;
61
+ const handleAbort = () => {
62
+ if (sessionId) {
63
+ fetch(`${serverUrl}/abort/${sessionId}`, { method: "POST" }).catch(
64
+ () => {
65
+ }
66
+ );
67
+ }
68
+ };
69
+ signal.addEventListener("abort", handleAbort);
70
+ try {
71
+ const response = await fetch(`${serverUrl}/agent`, {
72
+ method: "POST",
73
+ headers: { "Content-Type": "application/json" },
74
+ body: JSON.stringify(context),
75
+ signal
76
+ });
77
+ if (!response.ok) {
78
+ throw new Error(`Server error: ${response.status}`);
79
+ }
80
+ if (!response.body) {
81
+ throw new Error("No response body");
82
+ }
83
+ yield* streamSSE(response.body, signal);
84
+ } finally {
85
+ signal.removeEventListener("abort", handleAbort);
71
86
  }
72
- yield* streamSSE(response.body, signal);
73
87
  }
74
88
  var createCursorAgentProvider = (providerOptions = {}) => {
75
89
  const { serverUrl = DEFAULT_SERVER_URL, getOptions } = providerOptions;
@@ -105,6 +119,7 @@ var createCursorAgentProvider = (providerOptions = {}) => {
105
119
  yield* streamFromServer(serverUrl, mergedContext, signal);
106
120
  },
107
121
  supportsResume: true,
122
+ supportsFollowUp: true,
108
123
  checkConnection: async () => {
109
124
  const now = Date.now();
110
125
  if (connectionCache && now - connectionCache.timestamp < CONNECTION_CHECK_TTL_MS) {
@@ -120,9 +135,9 @@ var createCursorAgentProvider = (providerOptions = {}) => {
120
135
  return false;
121
136
  }
122
137
  },
123
- undo: async () => {
138
+ abort: async (sessionId) => {
124
139
  try {
125
- await fetch(`${serverUrl}/undo`, { method: "POST" });
140
+ await fetch(`${serverUrl}/abort/${sessionId}`, { method: "POST" });
126
141
  } catch {
127
142
  }
128
143
  }
@@ -131,19 +146,26 @@ var createCursorAgentProvider = (providerOptions = {}) => {
131
146
  var attachAgent = async () => {
132
147
  if (typeof window === "undefined") return;
133
148
  const provider = createCursorAgentProvider();
149
+ const attach = (api2) => {
150
+ api2.setAgent({ provider, storage: sessionStorage });
151
+ };
134
152
  const api = window.__REACT_GRAB__;
135
153
  if (api) {
136
- api.setAgent({ provider, storage: sessionStorage });
154
+ attach(api);
137
155
  return;
138
156
  }
139
157
  window.addEventListener(
140
158
  "react-grab:init",
141
159
  (event) => {
142
160
  const customEvent = event;
143
- customEvent.detail.setAgent({ provider, storage: sessionStorage });
161
+ attach(customEvent.detail);
144
162
  },
145
163
  { once: true }
146
164
  );
165
+ const apiAfterListener = window.__REACT_GRAB__;
166
+ if (apiAfterListener) {
167
+ attach(apiAfterListener);
168
+ }
147
169
  };
148
170
  attachAgent();
149
171
 
package/dist/client.d.cts CHANGED
@@ -14,8 +14,9 @@ declare const createCursorAgentProvider: (providerOptions?: CursorAgentProviderO
14
14
  send: (context: CursorAgentContext, signal: AbortSignal) => AsyncGenerator<string, void, unknown>;
15
15
  resume: (sessionId: string, signal: AbortSignal, storage: AgentSessionStorage) => AsyncGenerator<string, void, unknown>;
16
16
  supportsResume: boolean;
17
+ supportsFollowUp: boolean;
17
18
  checkConnection: () => Promise<boolean>;
18
- undo: () => Promise<void>;
19
+ abort: (sessionId: string) => Promise<void>;
19
20
  };
20
21
  declare global {
21
22
  interface Window {
package/dist/client.d.ts CHANGED
@@ -14,8 +14,9 @@ declare const createCursorAgentProvider: (providerOptions?: CursorAgentProviderO
14
14
  send: (context: CursorAgentContext, signal: AbortSignal) => AsyncGenerator<string, void, unknown>;
15
15
  resume: (sessionId: string, signal: AbortSignal, storage: AgentSessionStorage) => AsyncGenerator<string, void, unknown>;
16
16
  supportsResume: boolean;
17
+ supportsFollowUp: boolean;
17
18
  checkConnection: () => Promise<boolean>;
18
- undo: () => Promise<void>;
19
+ abort: (sessionId: string) => Promise<void>;
19
20
  };
20
21
  declare global {
21
22
  interface Window {
@@ -1,4 +1,4 @@
1
- var ReactGrabCursor=(function(exports){'use strict';var m=`http://localhost:${5567}`,E="react-grab:agent-sessions",C=o=>{let t="",n="";for(let e of o.split(`
2
- `))e.startsWith("event:")?t=e.slice(6).trim():e.startsWith("data:")&&(n=e.slice(5).trim());return {eventType:t,data:n}};async function*y(o,t){let n=o.getReader(),e=new TextDecoder,s="",r=false,a=()=>{r=true,n.cancel().catch(()=>{});};t.addEventListener("abort",a);try{if(t.aborted)throw new DOMException("Aborted","AbortError");for(;;){let i=await n.read();if(r||t.aborted)throw new DOMException("Aborted","AbortError");let{done:g,value:l}=i;l&&(s+=e.decode(l,{stream:!0}));let c;for(;(c=s.indexOf(`
1
+ var ReactGrabCursor=(function(exports){'use strict';var m=`http://localhost:${5567}`,E="react-grab:agent-sessions",b=s=>{let e="",n="";for(let r of s.split(`
2
+ `))r.startsWith("event:")?e=r.slice(6).trim():r.startsWith("data:")&&(n=r.slice(5).trim());return {eventType:e,data:n}};async function*C(s,e){let n=s.getReader(),r=new TextDecoder,o="",t=false,a=()=>{t=true,n.cancel().catch(()=>{});};e.addEventListener("abort",a);try{if(e.aborted)throw new DOMException("Aborted","AbortError");for(;;){let i=await n.read();if(t||e.aborted)throw new DOMException("Aborted","AbortError");let{done:l,value:u}=i;u&&(o+=r.decode(u,{stream:!0}));let c;for(;(c=o.indexOf(`
3
3
 
4
- `))!==-1;){let{eventType:d,data:u}=C(s.slice(0,c));if(s=s.slice(c+2),d==="done")return;if(d==="error")throw new Error(u||"Agent error");u&&(yield u);}if(g)break}}finally{t.removeEventListener("abort",a);try{n.releaseLock();}catch{}}}async function*p(o,t,n){let e=await fetch(`${o}/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*y(e.body,n);}var S=(o={})=>{let{serverUrl:t=m,getOptions:n}=o,e=null,s=r=>({...n?.()??{},...r??{}});return {send:async function*(r,a){let i={...r,options:s(r.options)};yield*p(t,i,a);},resume:async function*(r,a,i){let g=i.getItem(E);if(!g)throw new Error("No sessions to resume");let c=JSON.parse(g)[r];if(!c)throw new Error(`Session ${r} not found`);let d=c.context,u={...d,options:s(d.options)};yield "Resuming...",yield*p(t,u,a);},supportsResume:true,checkConnection:async()=>{let r=Date.now();if(e&&r-e.timestamp<5e3)return e.result;try{let i=(await fetch(`${t}/health`,{method:"GET"})).ok;return e={result:i,timestamp:r},i}catch{return e={result:false,timestamp:r},false}},undo:async()=>{try{await fetch(`${t}/undo`,{method:"POST"});}catch{}}}},b=async()=>{if(typeof window>"u")return;let o=S(),t=window.__REACT_GRAB__;if(t){t.setAgent({provider:o,storage:sessionStorage});return}window.addEventListener("react-grab:init",n=>{n.detail.setAgent({provider:o,storage:sessionStorage});},{once:true});};b();exports.attachAgent=b;exports.createCursorAgentProvider=S;return exports;})({});
4
+ `))!==-1;){let{eventType:d,data:p}=b(o.slice(0,c));if(o=o.slice(c+2),d==="done")return;if(d==="error")throw new Error(p||"Agent error");p&&(yield p);}if(l)break}}finally{e.removeEventListener("abort",a);try{n.releaseLock();}catch{}}}async function*g(s,e,n){let r=e.sessionId,o=()=>{r&&fetch(`${s}/abort/${r}`,{method:"POST"}).catch(()=>{});};n.addEventListener("abort",o);try{let t=await fetch(`${s}/agent`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),signal:n});if(!t.ok)throw new Error(`Server error: ${t.status}`);if(!t.body)throw new Error("No response body");yield*C(t.body,n);}finally{n.removeEventListener("abort",o);}}var y=(s={})=>{let{serverUrl:e=m,getOptions:n}=s,r=null,o=t=>({...n?.()??{},...t??{}});return {send:async function*(t,a){let i={...t,options:o(t.options)};yield*g(e,i,a);},resume:async function*(t,a,i){let l=i.getItem(E);if(!l)throw new Error("No sessions to resume");let c=JSON.parse(l)[t];if(!c)throw new Error(`Session ${t} not found`);let d=c.context,p={...d,options:o(d.options)};yield "Resuming...",yield*g(e,p,a);},supportsResume:true,supportsFollowUp:true,checkConnection:async()=>{let t=Date.now();if(r&&t-r.timestamp<5e3)return r.result;try{let i=(await fetch(`${e}/health`,{method:"GET"})).ok;return r={result:i,timestamp:t},i}catch{return r={result:false,timestamp:t},false}},abort:async t=>{try{await fetch(`${e}/abort/${t}`,{method:"POST"});}catch{}}}},h=async()=>{if(typeof window>"u")return;let s=y(),e=o=>{o.setAgent({provider:s,storage:sessionStorage});},n=window.__REACT_GRAB__;if(n){e(n);return}window.addEventListener("react-grab:init",o=>{e(o.detail);},{once:true});let r=window.__REACT_GRAB__;r&&e(r);};h();exports.attachAgent=h;exports.createCursorAgentProvider=y;return exports;})({});