@react-grab/cursor 0.0.55
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/dist/client.cjs +87 -0
- package/dist/client.d.cts +14 -0
- package/dist/client.d.ts +14 -0
- package/dist/client.js +84 -0
- package/dist/server.cjs +2392 -0
- package/dist/server.d.cts +6 -0
- package/dist/server.d.ts +6 -0
- package/dist/server.js +2386 -0
- package/package.json +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Aiden Bai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/client.cjs
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/constants.ts
|
|
4
|
+
var DEFAULT_PORT = 5567;
|
|
5
|
+
|
|
6
|
+
// src/client.ts
|
|
7
|
+
var DEFAULT_SERVER_URL = `http://localhost:${DEFAULT_PORT}`;
|
|
8
|
+
var STORAGE_KEY = "react-grab:agent-sessions";
|
|
9
|
+
var parseSSEEvent = (eventBlock) => {
|
|
10
|
+
let eventType = "";
|
|
11
|
+
let data = "";
|
|
12
|
+
for (const line of eventBlock.split("\n")) {
|
|
13
|
+
if (line.startsWith("event:")) eventType = line.slice(6).trim();
|
|
14
|
+
else if (line.startsWith("data:")) data = line.slice(5).trim();
|
|
15
|
+
}
|
|
16
|
+
return { eventType, data };
|
|
17
|
+
};
|
|
18
|
+
async function* streamSSE(stream) {
|
|
19
|
+
const reader = stream.getReader();
|
|
20
|
+
const decoder = new TextDecoder();
|
|
21
|
+
let buffer = "";
|
|
22
|
+
try {
|
|
23
|
+
while (true) {
|
|
24
|
+
const { done, value } = await reader.read();
|
|
25
|
+
if (value) buffer += decoder.decode(value, { stream: true });
|
|
26
|
+
let boundary;
|
|
27
|
+
while ((boundary = buffer.indexOf("\n\n")) !== -1) {
|
|
28
|
+
const { eventType, data } = parseSSEEvent(buffer.slice(0, boundary));
|
|
29
|
+
buffer = buffer.slice(boundary + 2);
|
|
30
|
+
if (eventType === "done") return;
|
|
31
|
+
if (eventType === "error") throw new Error(data || "Agent error");
|
|
32
|
+
if (data) yield data;
|
|
33
|
+
}
|
|
34
|
+
if (done) break;
|
|
35
|
+
}
|
|
36
|
+
} finally {
|
|
37
|
+
reader.releaseLock();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function* streamFromServer(serverUrl, context, signal) {
|
|
41
|
+
const response = await fetch(`${serverUrl}/agent`, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: { "Content-Type": "application/json" },
|
|
44
|
+
body: JSON.stringify(context),
|
|
45
|
+
signal
|
|
46
|
+
});
|
|
47
|
+
if (!response.ok) {
|
|
48
|
+
throw new Error(`Server error: ${response.status}`);
|
|
49
|
+
}
|
|
50
|
+
if (!response.body) {
|
|
51
|
+
throw new Error("No response body");
|
|
52
|
+
}
|
|
53
|
+
yield* streamSSE(response.body);
|
|
54
|
+
}
|
|
55
|
+
var createCursorAgentProvider = (providerOptions = {}) => {
|
|
56
|
+
const { serverUrl = DEFAULT_SERVER_URL, getOptions } = providerOptions;
|
|
57
|
+
const mergeOptions = (contextOptions) => ({
|
|
58
|
+
...getOptions?.() ?? {},
|
|
59
|
+
...contextOptions ?? {}
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
send: async function* (context, signal) {
|
|
63
|
+
const mergedContext = { ...context, options: mergeOptions(context.options) };
|
|
64
|
+
yield* streamFromServer(serverUrl, mergedContext, signal);
|
|
65
|
+
},
|
|
66
|
+
resume: async function* (sessionId, signal) {
|
|
67
|
+
const savedSessions = sessionStorage.getItem(STORAGE_KEY);
|
|
68
|
+
if (!savedSessions) {
|
|
69
|
+
throw new Error("No sessions to resume");
|
|
70
|
+
}
|
|
71
|
+
const sessionsObject = JSON.parse(savedSessions);
|
|
72
|
+
const session = sessionsObject[sessionId];
|
|
73
|
+
if (!session) {
|
|
74
|
+
throw new Error(`Session ${sessionId} not found`);
|
|
75
|
+
}
|
|
76
|
+
const context = session.context;
|
|
77
|
+
const mergedContext = { ...context, options: mergeOptions(context.options) };
|
|
78
|
+
yield "Resuming...";
|
|
79
|
+
yield* streamFromServer(serverUrl, mergedContext, signal);
|
|
80
|
+
},
|
|
81
|
+
supportsResume: true
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
var defaultCursorAgentProvider = createCursorAgentProvider();
|
|
85
|
+
|
|
86
|
+
exports.createCursorAgentProvider = createCursorAgentProvider;
|
|
87
|
+
exports.defaultCursorAgentProvider = defaultCursorAgentProvider;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AgentProvider } from 'react-grab/core';
|
|
2
|
+
|
|
3
|
+
interface CursorAgentOptions {
|
|
4
|
+
model?: string;
|
|
5
|
+
workspace?: string;
|
|
6
|
+
}
|
|
7
|
+
interface CursorAgentProviderOptions {
|
|
8
|
+
serverUrl?: string;
|
|
9
|
+
getOptions?: () => Partial<CursorAgentOptions>;
|
|
10
|
+
}
|
|
11
|
+
declare const createCursorAgentProvider: (providerOptions?: CursorAgentProviderOptions) => AgentProvider<CursorAgentOptions>;
|
|
12
|
+
declare const defaultCursorAgentProvider: AgentProvider<CursorAgentOptions>;
|
|
13
|
+
|
|
14
|
+
export { createCursorAgentProvider, defaultCursorAgentProvider };
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AgentProvider } from 'react-grab/core';
|
|
2
|
+
|
|
3
|
+
interface CursorAgentOptions {
|
|
4
|
+
model?: string;
|
|
5
|
+
workspace?: string;
|
|
6
|
+
}
|
|
7
|
+
interface CursorAgentProviderOptions {
|
|
8
|
+
serverUrl?: string;
|
|
9
|
+
getOptions?: () => Partial<CursorAgentOptions>;
|
|
10
|
+
}
|
|
11
|
+
declare const createCursorAgentProvider: (providerOptions?: CursorAgentProviderOptions) => AgentProvider<CursorAgentOptions>;
|
|
12
|
+
declare const defaultCursorAgentProvider: AgentProvider<CursorAgentOptions>;
|
|
13
|
+
|
|
14
|
+
export { createCursorAgentProvider, defaultCursorAgentProvider };
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
var DEFAULT_PORT = 5567;
|
|
3
|
+
|
|
4
|
+
// src/client.ts
|
|
5
|
+
var DEFAULT_SERVER_URL = `http://localhost:${DEFAULT_PORT}`;
|
|
6
|
+
var STORAGE_KEY = "react-grab:agent-sessions";
|
|
7
|
+
var parseSSEEvent = (eventBlock) => {
|
|
8
|
+
let eventType = "";
|
|
9
|
+
let data = "";
|
|
10
|
+
for (const line of eventBlock.split("\n")) {
|
|
11
|
+
if (line.startsWith("event:")) eventType = line.slice(6).trim();
|
|
12
|
+
else if (line.startsWith("data:")) data = line.slice(5).trim();
|
|
13
|
+
}
|
|
14
|
+
return { eventType, data };
|
|
15
|
+
};
|
|
16
|
+
async function* streamSSE(stream) {
|
|
17
|
+
const reader = stream.getReader();
|
|
18
|
+
const decoder = new TextDecoder();
|
|
19
|
+
let buffer = "";
|
|
20
|
+
try {
|
|
21
|
+
while (true) {
|
|
22
|
+
const { done, value } = await reader.read();
|
|
23
|
+
if (value) buffer += decoder.decode(value, { stream: true });
|
|
24
|
+
let boundary;
|
|
25
|
+
while ((boundary = buffer.indexOf("\n\n")) !== -1) {
|
|
26
|
+
const { eventType, data } = parseSSEEvent(buffer.slice(0, boundary));
|
|
27
|
+
buffer = buffer.slice(boundary + 2);
|
|
28
|
+
if (eventType === "done") return;
|
|
29
|
+
if (eventType === "error") throw new Error(data || "Agent error");
|
|
30
|
+
if (data) yield data;
|
|
31
|
+
}
|
|
32
|
+
if (done) break;
|
|
33
|
+
}
|
|
34
|
+
} finally {
|
|
35
|
+
reader.releaseLock();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function* streamFromServer(serverUrl, context, signal) {
|
|
39
|
+
const response = await fetch(`${serverUrl}/agent`, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: { "Content-Type": "application/json" },
|
|
42
|
+
body: JSON.stringify(context),
|
|
43
|
+
signal
|
|
44
|
+
});
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
throw new Error(`Server error: ${response.status}`);
|
|
47
|
+
}
|
|
48
|
+
if (!response.body) {
|
|
49
|
+
throw new Error("No response body");
|
|
50
|
+
}
|
|
51
|
+
yield* streamSSE(response.body);
|
|
52
|
+
}
|
|
53
|
+
var createCursorAgentProvider = (providerOptions = {}) => {
|
|
54
|
+
const { serverUrl = DEFAULT_SERVER_URL, getOptions } = providerOptions;
|
|
55
|
+
const mergeOptions = (contextOptions) => ({
|
|
56
|
+
...getOptions?.() ?? {},
|
|
57
|
+
...contextOptions ?? {}
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
send: async function* (context, signal) {
|
|
61
|
+
const mergedContext = { ...context, options: mergeOptions(context.options) };
|
|
62
|
+
yield* streamFromServer(serverUrl, mergedContext, signal);
|
|
63
|
+
},
|
|
64
|
+
resume: async function* (sessionId, signal) {
|
|
65
|
+
const savedSessions = sessionStorage.getItem(STORAGE_KEY);
|
|
66
|
+
if (!savedSessions) {
|
|
67
|
+
throw new Error("No sessions to resume");
|
|
68
|
+
}
|
|
69
|
+
const sessionsObject = JSON.parse(savedSessions);
|
|
70
|
+
const session = sessionsObject[sessionId];
|
|
71
|
+
if (!session) {
|
|
72
|
+
throw new Error(`Session ${sessionId} not found`);
|
|
73
|
+
}
|
|
74
|
+
const context = session.context;
|
|
75
|
+
const mergedContext = { ...context, options: mergeOptions(context.options) };
|
|
76
|
+
yield "Resuming...";
|
|
77
|
+
yield* streamFromServer(serverUrl, mergedContext, signal);
|
|
78
|
+
},
|
|
79
|
+
supportsResume: true
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
var defaultCursorAgentProvider = createCursorAgentProvider();
|
|
83
|
+
|
|
84
|
+
export { createCursorAgentProvider, defaultCursorAgentProvider };
|