@gea-ai/cli 0.2.261129-alpha.1 → 0.2.261201-alpha.0

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.
Files changed (3) hide show
  1. package/package.json +4 -4
  2. package/runtime.mjs +13 -7
  3. package/vite.mjs +142 -123
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "directory": "packages/gea-cli"
14
14
  },
15
15
  "type": "module",
16
- "version": "0.2.261129-alpha.1",
16
+ "version": "0.2.261201-alpha.0",
17
17
  "bin": {
18
18
  "gea": "gea-launcher.cjs"
19
19
  },
@@ -38,9 +38,9 @@
38
38
  },
39
39
  "name": "@gea-ai/cli",
40
40
  "optionalDependencies": {
41
- "@gea-ai/cli-darwin-arm64": "0.2.261129-alpha.1",
42
- "@gea-ai/cli-win32-x64": "0.2.261129-alpha.1",
43
- "@gea-ai/cli-linux-x64": "0.2.261129-alpha.1"
41
+ "@gea-ai/cli-darwin-arm64": "0.2.261201-alpha.0",
42
+ "@gea-ai/cli-win32-x64": "0.2.261201-alpha.0",
43
+ "@gea-ai/cli-linux-x64": "0.2.261201-alpha.0"
44
44
  },
45
45
  "os": [
46
46
  "darwin",
package/runtime.mjs CHANGED
@@ -1,7 +1,11 @@
1
1
  // src/vite-env.ts
2
- import { existsSync, readFileSync } from "node:fs";
2
+ import { existsSync as existsSync2 } from "node:fs";
3
3
  import { createRequire } from "node:module";
4
- import { dirname, join, resolve } from "node:path";
4
+ import { dirname, join as join2, resolve } from "node:path";
5
+
6
+ // ../agent-sdk/src/vite-environment.ts
7
+ import { existsSync, readFileSync } from "node:fs";
8
+ import { join } from "node:path";
5
9
  import { parseEnv } from "node:util";
6
10
  function developmentEnvironment(root) {
7
11
  const file = join(root, ".dev.vars");
@@ -10,6 +14,8 @@ function developmentEnvironment(root) {
10
14
  ...process.env
11
15
  };
12
16
  }
17
+
18
+ // src/vite-env.ts
13
19
  function geaInstallation(environment = process.env) {
14
20
  let distributionRoot = environment.GEA_CLI_DISTRIBUTION_ROOT;
15
21
  if (!distributionRoot && (!environment.GEA_CLI_BINARY || !environment.GEA_WORKER_RUNTIME_BINARY || !environment.WORKER_RUNTIME_SYSTEM_WORKER_ROOT)) {
@@ -23,17 +29,17 @@ function geaInstallation(environment = process.env) {
23
29
  cliRequire.resolve(`@gea-ai/cli-${target}/package.json`)
24
30
  );
25
31
  }
26
- const cli = environment.GEA_CLI_BINARY ?? join(
32
+ const cli = environment.GEA_CLI_BINARY ?? join2(
27
33
  distributionRoot,
28
34
  process.platform === "win32" ? "gea-windows-x64.exe" : process.platform === "linux" ? "gea-linux-x64" : "gea-darwin-arm64"
29
35
  );
30
- const runtime = environment.GEA_WORKER_RUNTIME_BINARY ?? join(
36
+ const runtime = environment.GEA_WORKER_RUNTIME_BINARY ?? join2(
31
37
  distributionRoot,
32
38
  process.platform === "win32" ? "gea-worker-runtime.exe" : "gea-worker-runtime"
33
39
  );
34
- const systemWorkers = environment.WORKER_RUNTIME_SYSTEM_WORKER_ROOT ?? join(distributionRoot, "system-workers");
35
- for (const path of [cli, runtime, join(systemWorkers, "filesystem.mjs")]) {
36
- if (!existsSync(path))
40
+ const systemWorkers = environment.WORKER_RUNTIME_SYSTEM_WORKER_ROOT ?? join2(distributionRoot, "system-workers");
41
+ for (const path of [cli, runtime, join2(systemWorkers, "filesystem.mjs")]) {
42
+ if (!existsSync2(path))
37
43
  throw new Error(`GEA installation is incomplete: ${path}`);
38
44
  }
39
45
  return {
package/vite.mjs CHANGED
@@ -1,12 +1,13 @@
1
1
  // src/vite.ts
2
2
  import { spawn } from "node:child_process";
3
+
4
+ // ../agent-sdk/src/vite-plugin.ts
3
5
  import { once } from "node:events";
4
6
  import { createServer, request as proxyRequest } from "node:http";
5
7
 
6
- // src/vite-env.ts
8
+ // ../agent-sdk/src/vite-environment.ts
7
9
  import { existsSync, readFileSync } from "node:fs";
8
- import { createRequire } from "node:module";
9
- import { dirname, join, resolve } from "node:path";
10
+ import { join } from "node:path";
10
11
  import { parseEnv } from "node:util";
11
12
  function developmentEnvironment(root) {
12
13
  const file = join(root, ".dev.vars");
@@ -15,40 +16,8 @@ function developmentEnvironment(root) {
15
16
  ...process.env
16
17
  };
17
18
  }
18
- function geaInstallation(environment = process.env) {
19
- let distributionRoot = environment.GEA_CLI_DISTRIBUTION_ROOT;
20
- if (!distributionRoot && (!environment.GEA_CLI_BINARY || !environment.GEA_WORKER_RUNTIME_BINARY || !environment.WORKER_RUNTIME_SYSTEM_WORKER_ROOT)) {
21
- const cliRequire = createRequire(import.meta.url);
22
- const target = process.platform === "darwin" && process.arch === "arm64" ? "darwin-arm64" : process.platform === "win32" && process.arch === "x64" ? "win32-x64" : process.platform === "linux" && process.arch === "x64" ? "linux-x64" : null;
23
- if (!target)
24
- throw new Error(
25
- "Set GEA_CLI_BINARY, GEA_WORKER_RUNTIME_BINARY and WORKER_RUNTIME_SYSTEM_WORKER_ROOT for this platform."
26
- );
27
- distributionRoot = dirname(
28
- cliRequire.resolve(`@gea-ai/cli-${target}/package.json`)
29
- );
30
- }
31
- const cli = environment.GEA_CLI_BINARY ?? join(
32
- distributionRoot,
33
- process.platform === "win32" ? "gea-windows-x64.exe" : process.platform === "linux" ? "gea-linux-x64" : "gea-darwin-arm64"
34
- );
35
- const runtime = environment.GEA_WORKER_RUNTIME_BINARY ?? join(
36
- distributionRoot,
37
- process.platform === "win32" ? "gea-worker-runtime.exe" : "gea-worker-runtime"
38
- );
39
- const systemWorkers = environment.WORKER_RUNTIME_SYSTEM_WORKER_ROOT ?? join(distributionRoot, "system-workers");
40
- for (const path of [cli, runtime, join(systemWorkers, "filesystem.mjs")]) {
41
- if (!existsSync(path))
42
- throw new Error(`GEA installation is incomplete: ${path}`);
43
- }
44
- return {
45
- cli: resolve(cli),
46
- runtime: resolve(runtime),
47
- systemWorkers: resolve(systemWorkers)
48
- };
49
- }
50
19
 
51
- // src/vite.ts
20
+ // ../agent-sdk/src/vite-plugin.ts
52
21
  async function reservePort() {
53
22
  const listener = createServer();
54
23
  listener.listen(0, "127.0.0.1");
@@ -59,7 +28,7 @@ async function reservePort() {
59
28
  await new Promise((resolve2) => listener.close(() => resolve2()));
60
29
  return address.port;
61
30
  }
62
- function geaWorker() {
31
+ function createGeaWorkerPlugin(startWorker, ownedWorker) {
63
32
  let stopWorker;
64
33
  return {
65
34
  async closeBundle() {
@@ -110,107 +79,95 @@ function geaWorker() {
110
79
  },
111
80
  async configureServer(server) {
112
81
  const environment = developmentEnvironment(server.config.root);
113
- const installation = geaInstallation(environment);
114
- const port = await reservePort();
115
- const origin = `http://127.0.0.1:${port}`;
116
82
  const agentEnvironment = environment.AGENT_ENVIRONMENT ?? "local";
117
83
  if (agentEnvironment === "local" && server.config.server.host !== "127.0.0.1")
118
84
  throw new Error(
119
85
  "Local Agents API development must bind Vite to 127.0.0.1."
120
86
  );
121
- const child = spawn(
122
- installation.cli,
123
- [
124
- "agent",
125
- "dev",
126
- "--json",
127
- JSON.stringify({
128
- cwd: server.config.root,
129
- host: "127.0.0.1",
130
- port,
131
- vite: false
132
- })
133
- ],
134
- {
135
- cwd: server.config.root,
136
- env: {
137
- ...environment,
138
- APP_ORIGIN: environment.APP_ORIGIN ?? `http://127.0.0.1:${server.config.server.port ?? 4e3}`,
139
- AGENT_ENVIRONMENT: agentEnvironment,
140
- NODE_ENV: "production",
141
- GEA_WORKER_RUNTIME_BINARY: installation.runtime,
142
- WORKER_RUNTIME_SYSTEM_WORKER_ROOT: installation.systemWorkers
143
- },
144
- stdio: ["ignore", "pipe", "pipe"]
145
- }
146
- );
147
- let output = "";
148
- let stopping;
149
- const stop = () => stopping ??= (async () => {
150
- if (!child.pid || child.exitCode !== null || child.signalCode !== null)
151
- return;
152
- const exited = once(child, "exit");
153
- child.kill("SIGTERM");
154
- await exited;
155
- })();
156
- stopWorker = stop;
157
- const restart = server.restart.bind(server);
158
- server.restart = async (force) => {
159
- await stop();
160
- await restart(force);
161
- };
162
- server.httpServer?.once("close", () => {
163
- void stop();
164
- });
165
- child.stdout.on("data", (chunk) => process.stdout.write(chunk));
166
- child.stderr.on("data", (chunk) => {
167
- process.stderr.write(chunk);
168
- output += chunk;
169
- const lines = output.split("\n");
170
- output = lines.pop();
171
- if (lines.some(
172
- (line) => line.startsWith("[gea] Agent Worker reloaded at deployment ") || line === "[gea] Agent Worker Runtime restarted."
173
- ))
174
- server.ws.send({ type: "full-reload" });
175
- });
176
- let startupError;
177
- child.once("error", (error) => {
178
- startupError = error;
179
- });
180
- try {
181
- const deadline = Date.now() + 6e4;
182
- while (true) {
183
- if (startupError) throw startupError;
184
- if (child.exitCode !== null || child.signalCode !== null)
185
- throw new Error(
186
- "GEA development process exited. See its output above."
187
- );
188
- try {
189
- const response = await fetch(`${origin}/gea/agents/run`, {
190
- method: "OPTIONS"
191
- });
192
- await response.body?.cancel();
193
- if (response.ok) break;
194
- } catch {
87
+ let origin;
88
+ if (ownedWorker) {
89
+ origin = ownedWorker.origin;
90
+ } else {
91
+ const port = await reservePort();
92
+ origin = `http://127.0.0.1:${port}`;
93
+ const child = startWorker(server.config.root, port, {
94
+ ...environment,
95
+ APP_ORIGIN: environment.APP_ORIGIN ?? `http://127.0.0.1:${server.config.server.port ?? 4e3}`,
96
+ AGENT_ENVIRONMENT: agentEnvironment,
97
+ NODE_ENV: "production"
98
+ });
99
+ let output = "";
100
+ let stopping;
101
+ const stop = () => stopping ??= (async () => {
102
+ if (!child.pid || child.exitCode !== null || child.signalCode !== null)
103
+ return;
104
+ const exited = once(child, "exit");
105
+ child.kill("SIGTERM");
106
+ await exited;
107
+ })();
108
+ stopWorker = stop;
109
+ const restart = server.restart.bind(server);
110
+ server.restart = async (force) => {
111
+ await stop();
112
+ await restart(force);
113
+ };
114
+ server.httpServer?.once("close", () => {
115
+ void stop();
116
+ });
117
+ child.stdout.on("data", (chunk) => process.stdout.write(chunk));
118
+ child.stderr.on("data", (chunk) => {
119
+ process.stderr.write(chunk);
120
+ output += chunk;
121
+ const lines = output.split("\n");
122
+ output = lines.pop();
123
+ if (lines.some(
124
+ (line) => line.startsWith("[gea] Agent Worker reloaded at deployment ") || line === "[gea] Agent Worker Runtime restarted." || line.trimEnd() === "[gea] ready"
125
+ ))
126
+ server.ws.send({ type: "full-reload" });
127
+ });
128
+ let startupError;
129
+ child.once("error", (error) => {
130
+ startupError = error;
131
+ });
132
+ try {
133
+ const deadline = Date.now() + 6e4;
134
+ while (true) {
135
+ if (startupError) throw startupError;
136
+ if (child.exitCode !== null || child.signalCode !== null)
137
+ throw new Error(
138
+ "GEA development process exited. See its output above."
139
+ );
140
+ try {
141
+ const response = await fetch(`${origin}/gea/agents/run`, {
142
+ method: "OPTIONS"
143
+ });
144
+ await response.body?.cancel();
145
+ if (response.ok) break;
146
+ } catch {
147
+ }
148
+ if (Date.now() > deadline)
149
+ throw new Error("GEA development startup timed out.");
150
+ await new Promise((resolve2) => setTimeout(resolve2, 200));
195
151
  }
196
- if (Date.now() > deadline)
197
- throw new Error("GEA development startup timed out.");
198
- await new Promise((resolve2) => setTimeout(resolve2, 200));
152
+ } catch (error) {
153
+ await stop();
154
+ throw error;
199
155
  }
200
- } catch (error) {
201
- await stop();
202
- throw error;
203
156
  }
204
157
  server.middlewares.use((request, response, next) => {
205
- const pathname = new URL(request.url ?? "/", origin).pathname;
206
- if (pathname.startsWith("/@vite/") || pathname.startsWith("/@id/") || pathname.startsWith("/node_modules/") && pathname.endsWith("/vite/dist/client/env.mjs"))
158
+ const { pathname, search } = new URL(request.url ?? "/", origin);
159
+ if (pathname.startsWith("/@vite/") || pathname.startsWith("/@id/") || pathname.startsWith("/@fs/") || pathname.startsWith("/node_modules/.vite/") || pathname === "/@react-refresh" || pathname === "/__vite_ping" || pathname.startsWith("/node_modules/") && pathname.endsWith("/vite/dist/client/env.mjs"))
207
160
  return next();
161
+ const target = new URL(origin);
162
+ target.pathname = pathname;
163
+ target.search = search;
208
164
  const upstream = proxyRequest(
209
- new URL(request.url ?? "/", origin),
165
+ target,
210
166
  {
211
167
  method: request.method,
212
168
  headers: {
213
169
  ...request.headers,
170
+ ...ownedWorker ? { "x-gea-vite-worker-token": ownedWorker.token } : {},
214
171
  "x-forwarded-host": request.headers.host ?? "",
215
172
  "x-forwarded-proto": "http"
216
173
  }
@@ -247,6 +204,68 @@ function geaWorker() {
247
204
  }
248
205
  };
249
206
  }
207
+
208
+ // src/vite-env.ts
209
+ import { existsSync as existsSync2 } from "node:fs";
210
+ import { createRequire } from "node:module";
211
+ import { dirname, join as join2, resolve } from "node:path";
212
+ function geaInstallation(environment = process.env) {
213
+ let distributionRoot = environment.GEA_CLI_DISTRIBUTION_ROOT;
214
+ if (!distributionRoot && (!environment.GEA_CLI_BINARY || !environment.GEA_WORKER_RUNTIME_BINARY || !environment.WORKER_RUNTIME_SYSTEM_WORKER_ROOT)) {
215
+ const cliRequire = createRequire(import.meta.url);
216
+ const target = process.platform === "darwin" && process.arch === "arm64" ? "darwin-arm64" : process.platform === "win32" && process.arch === "x64" ? "win32-x64" : process.platform === "linux" && process.arch === "x64" ? "linux-x64" : null;
217
+ if (!target)
218
+ throw new Error(
219
+ "Set GEA_CLI_BINARY, GEA_WORKER_RUNTIME_BINARY and WORKER_RUNTIME_SYSTEM_WORKER_ROOT for this platform."
220
+ );
221
+ distributionRoot = dirname(
222
+ cliRequire.resolve(`@gea-ai/cli-${target}/package.json`)
223
+ );
224
+ }
225
+ const cli = environment.GEA_CLI_BINARY ?? join2(
226
+ distributionRoot,
227
+ process.platform === "win32" ? "gea-windows-x64.exe" : process.platform === "linux" ? "gea-linux-x64" : "gea-darwin-arm64"
228
+ );
229
+ const runtime = environment.GEA_WORKER_RUNTIME_BINARY ?? join2(
230
+ distributionRoot,
231
+ process.platform === "win32" ? "gea-worker-runtime.exe" : "gea-worker-runtime"
232
+ );
233
+ const systemWorkers = environment.WORKER_RUNTIME_SYSTEM_WORKER_ROOT ?? join2(distributionRoot, "system-workers");
234
+ for (const path of [cli, runtime, join2(systemWorkers, "filesystem.mjs")]) {
235
+ if (!existsSync2(path))
236
+ throw new Error(`GEA installation is incomplete: ${path}`);
237
+ }
238
+ return {
239
+ cli: resolve(cli),
240
+ runtime: resolve(runtime),
241
+ systemWorkers: resolve(systemWorkers)
242
+ };
243
+ }
244
+
245
+ // src/vite.ts
246
+ function geaWorker() {
247
+ return createGeaWorkerPlugin((root, port, environment) => {
248
+ const installation = geaInstallation(environment);
249
+ return spawn(
250
+ installation.cli,
251
+ [
252
+ "agent",
253
+ "dev",
254
+ "--json",
255
+ JSON.stringify({ cwd: root, host: "127.0.0.1", port, vite: false })
256
+ ],
257
+ {
258
+ cwd: root,
259
+ env: {
260
+ ...environment,
261
+ GEA_WORKER_RUNTIME_BINARY: installation.runtime,
262
+ WORKER_RUNTIME_SYSTEM_WORKER_ROOT: installation.systemWorkers
263
+ },
264
+ stdio: ["ignore", "pipe", "pipe"]
265
+ }
266
+ );
267
+ });
268
+ }
250
269
  export {
251
270
  geaWorker
252
271
  };