@react-grab/codex 0.0.81

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 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/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # @react-grab/codex
2
+
3
+ OpenAI Codex provider for React Grab.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @react-grab/codex
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Server
14
+
15
+ The server runs on port `7567` and interfaces with the Codex SDK. Add to your `package.json`:
16
+
17
+ ```json
18
+ {
19
+ "scripts": {
20
+ "dev": "npx @react-grab/codex@latest && next dev"
21
+ }
22
+ }
23
+ ```
24
+
25
+ > **Note:** You must have [Codex](https://github.com/openai/codex) installed (`npm i -g @openai/codex`).
26
+
27
+ ### Client
28
+
29
+ Add the client script to your HTML:
30
+
31
+ ```html
32
+ <script src="//unpkg.com/@react-grab/codex/dist/client.global.js"></script>
33
+ ```
34
+
35
+ Or import programmatically:
36
+
37
+ ```ts
38
+ import "@react-grab/codex/client";
39
+ ```
40
+
41
+ ## Features
42
+
43
+ - **Follow-ups**: Continue conversations with the same thread
44
+ - **Undo**: Undo the last change made by Codex
45
+ - **Streaming**: Real-time status updates during execution
package/dist/cli.cjs ADDED
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ var url = require('url');
5
+ var path = require('path');
6
+ var child_process = require('child_process');
7
+
8
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
9
+ var __create = Object.create;
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __getProtoOf = Object.getPrototypeOf;
14
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
15
+ var __commonJS = (cb, mod) => function __require() {
16
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
+ // If the importer is in node compatibility mode or this is not an ESM
28
+ // file that has been converted to a CommonJS file using a Babel-
29
+ // compatible transform (i.e. "__esModule" has not been set), then set
30
+ // "default" to the CommonJS "module.exports" for node compatibility.
31
+ __defProp(target, "default", { value: mod, enumerable: true }) ,
32
+ mod
33
+ ));
34
+
35
+ // ../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
36
+ var require_picocolors = __commonJS({
37
+ "../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js"(exports, module) {
38
+ var p = process || {};
39
+ var argv = p.argv || [];
40
+ var env = p.env || {};
41
+ 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);
42
+ var formatter = (open, close, replace = open) => (input) => {
43
+ let string = "" + input, index = string.indexOf(close, open.length);
44
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
45
+ };
46
+ var replaceClose = (string, close, replace, index) => {
47
+ let result = "", cursor = 0;
48
+ do {
49
+ result += string.substring(cursor, index) + replace;
50
+ cursor = index + close.length;
51
+ index = string.indexOf(close, cursor);
52
+ } while (~index);
53
+ return result + string.substring(cursor);
54
+ };
55
+ var createColors = (enabled = isColorSupported) => {
56
+ let f = enabled ? formatter : () => String;
57
+ return {
58
+ isColorSupported: enabled,
59
+ reset: f("\x1B[0m", "\x1B[0m"),
60
+ bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
61
+ dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
62
+ italic: f("\x1B[3m", "\x1B[23m"),
63
+ underline: f("\x1B[4m", "\x1B[24m"),
64
+ inverse: f("\x1B[7m", "\x1B[27m"),
65
+ hidden: f("\x1B[8m", "\x1B[28m"),
66
+ strikethrough: f("\x1B[9m", "\x1B[29m"),
67
+ black: f("\x1B[30m", "\x1B[39m"),
68
+ red: f("\x1B[31m", "\x1B[39m"),
69
+ green: f("\x1B[32m", "\x1B[39m"),
70
+ yellow: f("\x1B[33m", "\x1B[39m"),
71
+ blue: f("\x1B[34m", "\x1B[39m"),
72
+ magenta: f("\x1B[35m", "\x1B[39m"),
73
+ cyan: f("\x1B[36m", "\x1B[39m"),
74
+ white: f("\x1B[37m", "\x1B[39m"),
75
+ gray: f("\x1B[90m", "\x1B[39m"),
76
+ bgBlack: f("\x1B[40m", "\x1B[49m"),
77
+ bgRed: f("\x1B[41m", "\x1B[49m"),
78
+ bgGreen: f("\x1B[42m", "\x1B[49m"),
79
+ bgYellow: f("\x1B[43m", "\x1B[49m"),
80
+ bgBlue: f("\x1B[44m", "\x1B[49m"),
81
+ bgMagenta: f("\x1B[45m", "\x1B[49m"),
82
+ bgCyan: f("\x1B[46m", "\x1B[49m"),
83
+ bgWhite: f("\x1B[47m", "\x1B[49m"),
84
+ blackBright: f("\x1B[90m", "\x1B[39m"),
85
+ redBright: f("\x1B[91m", "\x1B[39m"),
86
+ greenBright: f("\x1B[92m", "\x1B[39m"),
87
+ yellowBright: f("\x1B[93m", "\x1B[39m"),
88
+ blueBright: f("\x1B[94m", "\x1B[39m"),
89
+ magentaBright: f("\x1B[95m", "\x1B[39m"),
90
+ cyanBright: f("\x1B[96m", "\x1B[39m"),
91
+ whiteBright: f("\x1B[97m", "\x1B[39m"),
92
+ bgBlackBright: f("\x1B[100m", "\x1B[49m"),
93
+ bgRedBright: f("\x1B[101m", "\x1B[49m"),
94
+ bgGreenBright: f("\x1B[102m", "\x1B[49m"),
95
+ bgYellowBright: f("\x1B[103m", "\x1B[49m"),
96
+ bgBlueBright: f("\x1B[104m", "\x1B[49m"),
97
+ bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
98
+ bgCyanBright: f("\x1B[106m", "\x1B[49m"),
99
+ bgWhiteBright: f("\x1B[107m", "\x1B[49m")
100
+ };
101
+ };
102
+ module.exports = createColors();
103
+ module.exports.createColors = createColors;
104
+ }
105
+ });
106
+
107
+ // src/cli.ts
108
+ var import_picocolors = __toESM(require_picocolors());
109
+
110
+ // src/constants.ts
111
+ var DEFAULT_PORT = 7567;
112
+
113
+ // src/cli.ts
114
+ var VERSION = "0.0.81";
115
+ 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)));
116
+ var __dirname$1 = path.dirname(__filename$1);
117
+ var serverPath = path.join(__dirname$1, "server.js");
118
+ child_process.spawn(process.execPath, [serverPath], {
119
+ detached: true,
120
+ stdio: "ignore"
121
+ }).unref();
122
+ console.log(`${import_picocolors.default.magenta("\u269B")} ${import_picocolors.default.bold("React Grab")} ${import_picocolors.default.gray(VERSION)} ${import_picocolors.default.dim("(Codex)")}`);
123
+ console.log(`- Local: ${import_picocolors.default.cyan(`http://localhost:${DEFAULT_PORT}`)}`);
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,120 @@
1
+ #!/usr/bin/env node
2
+ import { fileURLToPath } from 'url';
3
+ import { dirname, join } from 'path';
4
+ import { spawn } from 'child_process';
5
+
6
+ var __create = Object.create;
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __getProtoOf = Object.getPrototypeOf;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __commonJS = (cb, mod) => function __require() {
13
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ __defProp(target, "default", { value: mod, enumerable: true }) ,
29
+ mod
30
+ ));
31
+
32
+ // ../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
33
+ var require_picocolors = __commonJS({
34
+ "../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js"(exports, module) {
35
+ var p = process || {};
36
+ var argv = p.argv || [];
37
+ var env = p.env || {};
38
+ 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);
39
+ var formatter = (open, close, replace = open) => (input) => {
40
+ let string = "" + input, index = string.indexOf(close, open.length);
41
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
42
+ };
43
+ var replaceClose = (string, close, replace, index) => {
44
+ let result = "", cursor = 0;
45
+ do {
46
+ result += string.substring(cursor, index) + replace;
47
+ cursor = index + close.length;
48
+ index = string.indexOf(close, cursor);
49
+ } while (~index);
50
+ return result + string.substring(cursor);
51
+ };
52
+ var createColors = (enabled = isColorSupported) => {
53
+ let f = enabled ? formatter : () => String;
54
+ return {
55
+ isColorSupported: enabled,
56
+ reset: f("\x1B[0m", "\x1B[0m"),
57
+ bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
58
+ dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
59
+ italic: f("\x1B[3m", "\x1B[23m"),
60
+ underline: f("\x1B[4m", "\x1B[24m"),
61
+ inverse: f("\x1B[7m", "\x1B[27m"),
62
+ hidden: f("\x1B[8m", "\x1B[28m"),
63
+ strikethrough: f("\x1B[9m", "\x1B[29m"),
64
+ black: f("\x1B[30m", "\x1B[39m"),
65
+ red: f("\x1B[31m", "\x1B[39m"),
66
+ green: f("\x1B[32m", "\x1B[39m"),
67
+ yellow: f("\x1B[33m", "\x1B[39m"),
68
+ blue: f("\x1B[34m", "\x1B[39m"),
69
+ magenta: f("\x1B[35m", "\x1B[39m"),
70
+ cyan: f("\x1B[36m", "\x1B[39m"),
71
+ white: f("\x1B[37m", "\x1B[39m"),
72
+ gray: f("\x1B[90m", "\x1B[39m"),
73
+ bgBlack: f("\x1B[40m", "\x1B[49m"),
74
+ bgRed: f("\x1B[41m", "\x1B[49m"),
75
+ bgGreen: f("\x1B[42m", "\x1B[49m"),
76
+ bgYellow: f("\x1B[43m", "\x1B[49m"),
77
+ bgBlue: f("\x1B[44m", "\x1B[49m"),
78
+ bgMagenta: f("\x1B[45m", "\x1B[49m"),
79
+ bgCyan: f("\x1B[46m", "\x1B[49m"),
80
+ bgWhite: f("\x1B[47m", "\x1B[49m"),
81
+ blackBright: f("\x1B[90m", "\x1B[39m"),
82
+ redBright: f("\x1B[91m", "\x1B[39m"),
83
+ greenBright: f("\x1B[92m", "\x1B[39m"),
84
+ yellowBright: f("\x1B[93m", "\x1B[39m"),
85
+ blueBright: f("\x1B[94m", "\x1B[39m"),
86
+ magentaBright: f("\x1B[95m", "\x1B[39m"),
87
+ cyanBright: f("\x1B[96m", "\x1B[39m"),
88
+ whiteBright: f("\x1B[97m", "\x1B[39m"),
89
+ bgBlackBright: f("\x1B[100m", "\x1B[49m"),
90
+ bgRedBright: f("\x1B[101m", "\x1B[49m"),
91
+ bgGreenBright: f("\x1B[102m", "\x1B[49m"),
92
+ bgYellowBright: f("\x1B[103m", "\x1B[49m"),
93
+ bgBlueBright: f("\x1B[104m", "\x1B[49m"),
94
+ bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
95
+ bgCyanBright: f("\x1B[106m", "\x1B[49m"),
96
+ bgWhiteBright: f("\x1B[107m", "\x1B[49m")
97
+ };
98
+ };
99
+ module.exports = createColors();
100
+ module.exports.createColors = createColors;
101
+ }
102
+ });
103
+
104
+ // src/cli.ts
105
+ var import_picocolors = __toESM(require_picocolors());
106
+
107
+ // src/constants.ts
108
+ var DEFAULT_PORT = 7567;
109
+
110
+ // src/cli.ts
111
+ var VERSION = "0.0.81";
112
+ var __filename = fileURLToPath(import.meta.url);
113
+ var __dirname = dirname(__filename);
114
+ var serverPath = join(__dirname, "server.js");
115
+ spawn(process.execPath, [serverPath], {
116
+ detached: true,
117
+ stdio: "ignore"
118
+ }).unref();
119
+ console.log(`${import_picocolors.default.magenta("\u269B")} ${import_picocolors.default.bold("React Grab")} ${import_picocolors.default.gray(VERSION)} ${import_picocolors.default.dim("(Codex)")}`);
120
+ console.log(`- Local: ${import_picocolors.default.cyan(`http://localhost:${DEFAULT_PORT}`)}`);
@@ -0,0 +1,175 @@
1
+ 'use strict';
2
+
3
+ // src/constants.ts
4
+ var DEFAULT_PORT = 7567;
5
+ var CONNECTION_CHECK_TTL_MS = 5e3;
6
+
7
+ // src/client.ts
8
+ var DEFAULT_SERVER_URL = `http://localhost:${DEFAULT_PORT}`;
9
+ var STORAGE_KEY = "react-grab:agent-sessions";
10
+ var parseServerSentEvent = (eventStringBlock) => {
11
+ let eventType = "";
12
+ let data = "";
13
+ for (const line of eventStringBlock.split("\n")) {
14
+ if (line.startsWith("event:")) eventType = line.slice(6).trim();
15
+ else if (line.startsWith("data:")) data = line.slice(5).trim();
16
+ }
17
+ return { eventType, data };
18
+ };
19
+ var streamSSE = async function* (stream, signal) {
20
+ const streamReader = stream.getReader();
21
+ const textDecoder = new TextDecoder();
22
+ let textBuffer = "";
23
+ let aborted = false;
24
+ const onAbort = () => {
25
+ aborted = true;
26
+ streamReader.cancel().catch(() => {
27
+ });
28
+ };
29
+ signal.addEventListener("abort", onAbort);
30
+ try {
31
+ if (signal.aborted) {
32
+ throw new DOMException("Aborted", "AbortError");
33
+ }
34
+ while (true) {
35
+ const result = await streamReader.read();
36
+ if (aborted || signal.aborted) {
37
+ throw new DOMException("Aborted", "AbortError");
38
+ }
39
+ const { done, value } = result;
40
+ if (value) textBuffer += textDecoder.decode(value, { stream: true });
41
+ let boundaryIndex;
42
+ while ((boundaryIndex = textBuffer.indexOf("\n\n")) !== -1) {
43
+ const { eventType, data } = parseServerSentEvent(
44
+ textBuffer.slice(0, boundaryIndex)
45
+ );
46
+ textBuffer = textBuffer.slice(boundaryIndex + 2);
47
+ if (eventType === "done") return;
48
+ if (eventType === "error") throw new Error(data || "Agent error");
49
+ if (data) yield data;
50
+ }
51
+ if (done) break;
52
+ }
53
+ } finally {
54
+ signal.removeEventListener("abort", onAbort);
55
+ try {
56
+ streamReader.releaseLock();
57
+ } catch {
58
+ }
59
+ }
60
+ };
61
+ var streamFromServer = async function* (serverUrl, context, signal) {
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);
88
+ }
89
+ };
90
+ var createCodexAgentProvider = (options = {}) => {
91
+ const { serverUrl = DEFAULT_SERVER_URL, getOptions } = options;
92
+ let connectionCache = null;
93
+ const mergeOptions = (contextOptions) => ({
94
+ ...getOptions?.() ?? {},
95
+ ...contextOptions ?? {}
96
+ });
97
+ return {
98
+ send: async function* (context, signal) {
99
+ const combinedContext = {
100
+ ...context,
101
+ options: mergeOptions(context.options)
102
+ };
103
+ yield* streamFromServer(serverUrl, combinedContext, signal);
104
+ },
105
+ resume: async function* (sessionId, signal, storage) {
106
+ const storedSessions = storage.getItem(STORAGE_KEY);
107
+ if (!storedSessions) {
108
+ throw new Error("No sessions to resume");
109
+ }
110
+ const parsedSessions = JSON.parse(storedSessions);
111
+ const session = parsedSessions[sessionId];
112
+ if (!session) {
113
+ throw new Error(`Session ${sessionId} not found`);
114
+ }
115
+ const context = session.context;
116
+ const combinedContext = {
117
+ ...context,
118
+ options: mergeOptions(context.options)
119
+ };
120
+ yield "Resuming...";
121
+ yield* streamFromServer(serverUrl, combinedContext, signal);
122
+ },
123
+ supportsResume: true,
124
+ supportsFollowUp: true,
125
+ checkConnection: async () => {
126
+ const now = Date.now();
127
+ if (connectionCache && now - connectionCache.timestamp < CONNECTION_CHECK_TTL_MS) {
128
+ return connectionCache.result;
129
+ }
130
+ try {
131
+ const response = await fetch(`${serverUrl}/health`, { method: "GET" });
132
+ const result = response.ok;
133
+ connectionCache = { result, timestamp: now };
134
+ return result;
135
+ } catch {
136
+ connectionCache = { result: false, timestamp: now };
137
+ return false;
138
+ }
139
+ },
140
+ undo: async () => {
141
+ try {
142
+ await fetch(`${serverUrl}/undo`, { method: "POST" });
143
+ } catch {
144
+ }
145
+ }
146
+ };
147
+ };
148
+ var attachAgent = async () => {
149
+ if (typeof window === "undefined") return;
150
+ const provider = createCodexAgentProvider();
151
+ const attach = (api2) => {
152
+ api2.setAgent({ provider, storage: sessionStorage });
153
+ };
154
+ const api = window.__REACT_GRAB__;
155
+ if (api) {
156
+ attach(api);
157
+ return;
158
+ }
159
+ window.addEventListener(
160
+ "react-grab:init",
161
+ (event) => {
162
+ const customEvent = event;
163
+ attach(customEvent.detail);
164
+ },
165
+ { once: true }
166
+ );
167
+ const apiAfterListener = window.__REACT_GRAB__;
168
+ if (apiAfterListener) {
169
+ attach(apiAfterListener);
170
+ }
171
+ };
172
+ attachAgent();
173
+
174
+ exports.attachAgent = attachAgent;
175
+ exports.createCodexAgentProvider = createCodexAgentProvider;
@@ -0,0 +1,28 @@
1
+ import { init, AgentContext, AgentSessionStorage } from 'react-grab/core';
2
+ export { AgentCompleteResult } from 'react-grab/core';
3
+
4
+ interface CodexAgentOptions {
5
+ model?: string;
6
+ workingDirectory?: string;
7
+ }
8
+ type CodexAgentContext = AgentContext<CodexAgentOptions>;
9
+ interface CodexAgentProviderOptions {
10
+ serverUrl?: string;
11
+ getOptions?: () => Partial<CodexAgentOptions>;
12
+ }
13
+ declare const createCodexAgentProvider: (options?: CodexAgentProviderOptions) => {
14
+ send: (context: CodexAgentContext, signal: AbortSignal) => AsyncGenerator<string, void, unknown>;
15
+ resume: (sessionId: string, signal: AbortSignal, storage: AgentSessionStorage) => AsyncGenerator<string, void, unknown>;
16
+ supportsResume: boolean;
17
+ supportsFollowUp: boolean;
18
+ checkConnection: () => Promise<boolean>;
19
+ undo: () => Promise<void>;
20
+ };
21
+ declare global {
22
+ interface Window {
23
+ __REACT_GRAB__?: ReturnType<typeof init>;
24
+ }
25
+ }
26
+ declare const attachAgent: () => Promise<void>;
27
+
28
+ export { type CodexAgentOptions, attachAgent, createCodexAgentProvider };
@@ -0,0 +1,28 @@
1
+ import { init, AgentContext, AgentSessionStorage } from 'react-grab/core';
2
+ export { AgentCompleteResult } from 'react-grab/core';
3
+
4
+ interface CodexAgentOptions {
5
+ model?: string;
6
+ workingDirectory?: string;
7
+ }
8
+ type CodexAgentContext = AgentContext<CodexAgentOptions>;
9
+ interface CodexAgentProviderOptions {
10
+ serverUrl?: string;
11
+ getOptions?: () => Partial<CodexAgentOptions>;
12
+ }
13
+ declare const createCodexAgentProvider: (options?: CodexAgentProviderOptions) => {
14
+ send: (context: CodexAgentContext, signal: AbortSignal) => AsyncGenerator<string, void, unknown>;
15
+ resume: (sessionId: string, signal: AbortSignal, storage: AgentSessionStorage) => AsyncGenerator<string, void, unknown>;
16
+ supportsResume: boolean;
17
+ supportsFollowUp: boolean;
18
+ checkConnection: () => Promise<boolean>;
19
+ undo: () => Promise<void>;
20
+ };
21
+ declare global {
22
+ interface Window {
23
+ __REACT_GRAB__?: ReturnType<typeof init>;
24
+ }
25
+ }
26
+ declare const attachAgent: () => Promise<void>;
27
+
28
+ export { type CodexAgentOptions, attachAgent, createCodexAgentProvider };
@@ -0,0 +1,4 @@
1
+ var ReactGrabCodex=(function(exports){'use strict';var m=`http://localhost:${7567}`,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}},C=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:f}=i;f&&(r+=n.decode(f,{stream:!0}));let c;for(;(c=r.indexOf(`
3
+
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{}}},g=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*C(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*g(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*g(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.createCodexAgentProvider=b;return exports;})({});