@react-grab/cursor 0.0.60 → 0.0.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,46 +18,91 @@ yarn add @react-grab/cursor
18
18
 
19
19
  The server runs on port `5567` by default.
20
20
 
21
+ ### Quick Start (CLI)
22
+
23
+ Start the server in the background before running your dev server:
24
+
25
+ ```bash
26
+ npx @react-grab/cursor && pnpm run dev
27
+ ```
28
+
29
+ The server will run as a detached background process. **Note:** Stopping your dev server (Ctrl+C) won't stop the React Grab server. To stop it:
30
+
31
+ ```bash
32
+ pkill -f "react-grab.*server"
33
+ ```
34
+
35
+ ### Recommended: Config File (Automatic Lifecycle)
36
+
37
+ For better lifecycle management, start the server from your config file. This ensures the server stops when your dev server stops:
38
+
21
39
  ### Vite
22
40
 
23
41
  ```ts
24
42
  // vite.config.ts
25
- import "@react-grab/cursor/server";
43
+ import { startServer } from "@react-grab/cursor/server";
44
+
45
+ if (process.env.NODE_ENV === "development") {
46
+ startServer();
47
+ }
26
48
  ```
27
49
 
28
50
  ### Next.js
29
51
 
30
52
  ```ts
31
53
  // next.config.ts
32
- import "@react-grab/cursor/server";
54
+ import { startServer } from "@react-grab/cursor/server";
55
+
56
+ if (process.env.NODE_ENV === "development") {
57
+ startServer();
58
+ }
33
59
  ```
34
60
 
35
61
  ## Client Usage
36
62
 
37
- ```tsx
38
- import { init } from "react-grab/core";
39
- import { createCursorAgentProvider } from "@react-grab/cursor/client";
40
-
41
- const agentProvider = createCursorAgentProvider();
63
+ ### Script Tag
42
64
 
43
- init({
44
- agent: {
45
- provider: agentProvider,
46
- },
47
- });
65
+ ```html
66
+ <script src="//unpkg.com/react-grab/dist/index.global.js"></script>
67
+ <script src="//unpkg.com/@react-grab/cursor/dist/client.global.js"></script>
48
68
  ```
49
69
 
50
- ## Configuration
70
+ ### Next.js
71
+
72
+ Using the `Script` component in your `app/layout.tsx`:
73
+
74
+ ```jsx
75
+ import Script from "next/script";
76
+
77
+ export default function RootLayout({ children }) {
78
+ return (
79
+ <html>
80
+ <head>
81
+ {process.env.NODE_ENV === "development" && (
82
+ <>
83
+ <Script
84
+ src="//unpkg.com/react-grab/dist/index.global.js"
85
+ strategy="beforeInteractive"
86
+ />
87
+ <Script
88
+ src="//unpkg.com/@react-grab/cursor/dist/client.global.js"
89
+ strategy="lazyOnload"
90
+ />
91
+ </>
92
+ )}
93
+ </head>
94
+ <body>{children}</body>
95
+ </html>
96
+ );
97
+ }
98
+ ```
51
99
 
52
- You can customize the server URL and default options:
100
+ ### ES Module
53
101
 
54
102
  ```tsx
55
- const agentProvider = createCursorAgentProvider({
56
- getOptions: () => ({
57
- model: "composer-1",
58
- workspace: "/path/to/workspace",
59
- }),
60
- });
103
+ import { attachAgent } from "@react-grab/cursor/client";
104
+
105
+ attachAgent();
61
106
  ```
62
107
 
63
108
  ## How It Works
package/dist/cli.cjs ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ var child_process = require('child_process');
5
+ var url = require('url');
6
+ var path = require('path');
7
+
8
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
9
+ var __filename$1 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
10
+ var __dirname$1 = path.dirname(__filename$1);
11
+ var serverPath = path.join(__dirname$1, "server.js");
12
+ child_process.spawn(process.execPath, [serverPath], {
13
+ detached: true,
14
+ stdio: "ignore"
15
+ }).unref();
16
+ console.log("[React Grab] Server starting on port 5567...");
package/dist/cli.d.cts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.js ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from 'child_process';
3
+ import { fileURLToPath } from 'url';
4
+ import { dirname, join } from 'path';
5
+
6
+ var __filename = fileURLToPath(import.meta.url);
7
+ var __dirname = dirname(__filename);
8
+ var serverPath = join(__dirname, "server.js");
9
+ spawn(process.execPath, [serverPath], {
10
+ detached: true,
11
+ stdio: "ignore"
12
+ }).unref();
13
+ console.log("[React Grab] Server starting on port 5567...");
package/dist/client.cjs CHANGED
@@ -66,8 +66,8 @@ var createCursorAgentProvider = (providerOptions = {}) => {
66
66
  };
67
67
  yield* streamFromServer(serverUrl, mergedContext, signal);
68
68
  },
69
- resume: async function* (sessionId, signal) {
70
- const savedSessions = sessionStorage.getItem(STORAGE_KEY);
69
+ resume: async function* (sessionId, signal, storage) {
70
+ const savedSessions = storage.getItem(STORAGE_KEY);
71
71
  if (!savedSessions) {
72
72
  throw new Error("No sessions to resume");
73
73
  }
@@ -104,6 +104,7 @@ var attachAgent = async () => {
104
104
  { once: true }
105
105
  );
106
106
  };
107
+ attachAgent();
107
108
 
108
109
  exports.attachAgent = attachAgent;
109
110
  exports.createCursorAgentProvider = createCursorAgentProvider;
@@ -0,0 +1,4 @@
1
+ var ReactGrabCursor=(function(exports){'use strict';var l=`http://localhost:${5567}`,f="react-grab:agent-sessions",y=n=>{let t="",r="";for(let e of n.split(`
2
+ `))e.startsWith("event:")?t=e.slice(6).trim():e.startsWith("data:")&&(r=e.slice(5).trim());return {eventType:t,data:r}};async function*S(n){let t=n.getReader(),r=new TextDecoder,e="";try{for(;;){let{done:o,value:i}=await t.read();i&&(e+=r.decode(i,{stream:!0}));let s;for(;(s=e.indexOf(`
3
+
4
+ `))!==-1;){let{eventType:a,data:c}=y(e.slice(0,s));if(e=e.slice(s+2),a==="done")return;if(a==="error")throw new Error(c||"Agent error");c&&(yield c);}if(o)break}}finally{t.releaseLock();}}async function*p(n,t,r){let e=await fetch(`${n}/agent`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:r});if(!e.ok)throw new Error(`Server error: ${e.status}`);if(!e.body)throw new Error("No response body");yield*S(e.body);}var E=(n={})=>{let{serverUrl:t=l,getOptions:r}=n,e=o=>({...r?.()??{},...o??{}});return {send:async function*(o,i){let s={...o,options:e(o.options)};yield*p(t,s,i);},resume:async function*(o,i,s){let a=s.getItem(f);if(!a)throw new Error("No sessions to resume");let g=JSON.parse(a)[o];if(!g)throw new Error(`Session ${o} not found`);let d=g.context,u={...d,options:e(d.options)};yield "Resuming...",yield*p(t,u,i);},supportsResume:true}},C=async()=>{if(typeof window>"u")return;let n=E(),t=window.__REACT_GRAB__;if(t){t.setAgent({provider:n});return}window.addEventListener("react-grab:init",r=>{r.detail.setAgent({provider:n});},{once:true});};C();exports.attachAgent=C;exports.createCursorAgentProvider=E;return exports;})({});
package/dist/client.js CHANGED
@@ -64,8 +64,8 @@ var createCursorAgentProvider = (providerOptions = {}) => {
64
64
  };
65
65
  yield* streamFromServer(serverUrl, mergedContext, signal);
66
66
  },
67
- resume: async function* (sessionId, signal) {
68
- const savedSessions = sessionStorage.getItem(STORAGE_KEY);
67
+ resume: async function* (sessionId, signal, storage) {
68
+ const savedSessions = storage.getItem(STORAGE_KEY);
69
69
  if (!savedSessions) {
70
70
  throw new Error("No sessions to resume");
71
71
  }
@@ -102,5 +102,6 @@ var attachAgent = async () => {
102
102
  { once: true }
103
103
  );
104
104
  };
105
+ attachAgent();
105
106
 
106
107
  export { attachAgent, createCursorAgentProvider };
package/dist/server.cjs CHANGED
@@ -7,6 +7,7 @@ var http2 = require('http2');
7
7
  var stream = require('stream');
8
8
  var crypto = require('crypto');
9
9
 
10
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
10
11
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
12
 
12
13
  var net__default = /*#__PURE__*/_interopDefault(net);
@@ -2418,6 +2419,9 @@ var startServer = async (port = DEFAULT_PORT) => {
2418
2419
  serve({ fetch: app.fetch, port });
2419
2420
  console.log(`[React Grab] Server started on port ${port}`);
2420
2421
  };
2422
+ if ((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('server.cjs', document.baseURI).href)) === `file://${process.argv[1]}`) {
2423
+ startServer(DEFAULT_PORT).catch(console.error);
2424
+ }
2421
2425
 
2422
2426
  exports.createServer = createServer;
2423
2427
  exports.startServer = startServer;
package/dist/server.js CHANGED
@@ -2411,5 +2411,8 @@ var startServer = async (port = DEFAULT_PORT) => {
2411
2411
  serve({ fetch: app.fetch, port });
2412
2412
  console.log(`[React Grab] Server started on port ${port}`);
2413
2413
  };
2414
+ if (import.meta.url === `file://${process.argv[1]}`) {
2415
+ startServer(DEFAULT_PORT).catch(console.error);
2416
+ }
2414
2417
 
2415
2418
  export { createServer, startServer };
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "@react-grab/cursor",
3
- "version": "0.0.60",
3
+ "version": "0.0.62",
4
4
  "type": "module",
5
+ "bin": {
6
+ "react-grab-cursor": "./dist/cli.js"
7
+ },
5
8
  "exports": {
6
9
  "./client": {
7
10
  "types": "./dist/client.d.ts",
@@ -12,8 +15,11 @@
12
15
  "types": "./dist/server.d.ts",
13
16
  "import": "./dist/server.js",
14
17
  "require": "./dist/server.cjs"
15
- }
18
+ },
19
+ "./dist/*": "./dist/*.js",
20
+ "./dist/*.js": "./dist/*.js"
16
21
  },
22
+ "browser": "dist/client.global.js",
17
23
  "files": [
18
24
  "dist"
19
25
  ],
@@ -23,10 +29,10 @@
23
29
  "dependencies": {
24
30
  "@hono/node-server": "^1.19.6",
25
31
  "hono": "^4.0.0",
26
- "react-grab": "0.0.60"
32
+ "react-grab": "0.0.62"
27
33
  },
28
34
  "scripts": {
29
35
  "dev": "tsup --watch",
30
- "build": "NODE_ENV=production tsup"
36
+ "build": "rm -rf dist && NODE_ENV=production tsup"
31
37
  }
32
38
  }