better-codex 0.1.1 → 0.1.4
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/apps/web/src/config.ts
CHANGED
|
@@ -2,4 +2,28 @@ const FALLBACK_HUB_URL = 'http://127.0.0.1:7711'
|
|
|
2
2
|
|
|
3
3
|
export const HUB_URL =
|
|
4
4
|
import.meta.env.VITE_CODEX_HUB_URL ?? FALLBACK_HUB_URL
|
|
5
|
+
|
|
6
|
+
let cachedToken: string | null = null
|
|
7
|
+
|
|
8
|
+
export const getHubToken = async (): Promise<string> => {
|
|
9
|
+
const envToken = import.meta.env.VITE_CODEX_HUB_TOKEN
|
|
10
|
+
if (envToken) {
|
|
11
|
+
return envToken
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!cachedToken) {
|
|
15
|
+
try {
|
|
16
|
+
const response = await fetch(`${HUB_URL}/config`)
|
|
17
|
+
if (response.ok) {
|
|
18
|
+
const data = (await response.json()) as { token?: string }
|
|
19
|
+
cachedToken = data.token ?? ''
|
|
20
|
+
}
|
|
21
|
+
} catch {
|
|
22
|
+
console.warn('Failed to fetch hub token from backend')
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return cachedToken ?? ''
|
|
27
|
+
}
|
|
28
|
+
|
|
5
29
|
export const HUB_TOKEN = import.meta.env.VITE_CODEX_HUB_TOKEN ?? ''
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getHubToken, HUB_URL } from '../config'
|
|
2
2
|
|
|
3
3
|
export type HubProfile = {
|
|
4
4
|
id: string
|
|
@@ -128,11 +128,12 @@ class HubClient {
|
|
|
128
128
|
if (this.ws?.readyState === WebSocket.OPEN) {
|
|
129
129
|
return
|
|
130
130
|
}
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
const token = await getHubToken()
|
|
132
|
+
if (!token) {
|
|
133
|
+
throw new Error('Missing hub token - backend may not be running')
|
|
133
134
|
}
|
|
134
135
|
|
|
135
|
-
const ws = new WebSocket(toWsUrl(HUB_URL,
|
|
136
|
+
const ws = new WebSocket(toWsUrl(HUB_URL, token))
|
|
136
137
|
this.ws = ws
|
|
137
138
|
|
|
138
139
|
ws.onmessage = (event) => {
|
package/bin/better-codex.cjs
CHANGED
|
@@ -212,7 +212,7 @@ const ensureDeps = (cwd, name) => {
|
|
|
212
212
|
return true;
|
|
213
213
|
}
|
|
214
214
|
log.step(`Installing dependencies for ${c.cyan}${name}${c.reset}...`);
|
|
215
|
-
const result = spawnSync('bun', ['install'], { cwd, stdio: '
|
|
215
|
+
const result = spawnSync('bun', ['install'], { cwd, stdio: 'ignore' });
|
|
216
216
|
if (result.status !== 0) {
|
|
217
217
|
log.error(`Failed to install dependencies in ${cwd}`);
|
|
218
218
|
process.exit(1);
|
|
@@ -265,7 +265,8 @@ const runWeb = (options) => {
|
|
|
265
265
|
CODEX_HUB_TOKEN: token,
|
|
266
266
|
CODEX_HUB_DEFAULT_CWD: process.cwd(),
|
|
267
267
|
},
|
|
268
|
-
stdio: '
|
|
268
|
+
stdio: 'pipe',
|
|
269
|
+
detached: false,
|
|
269
270
|
});
|
|
270
271
|
|
|
271
272
|
const web = spawn(
|
|
@@ -278,10 +279,16 @@ const runWeb = (options) => {
|
|
|
278
279
|
VITE_CODEX_HUB_URL: backendUrl,
|
|
279
280
|
VITE_CODEX_HUB_TOKEN: token,
|
|
280
281
|
},
|
|
281
|
-
stdio: '
|
|
282
|
+
stdio: 'pipe',
|
|
283
|
+
detached: false,
|
|
282
284
|
}
|
|
283
285
|
);
|
|
284
286
|
|
|
287
|
+
backend.stdout?.resume();
|
|
288
|
+
backend.stderr?.resume();
|
|
289
|
+
web.stdout?.resume();
|
|
290
|
+
web.stderr?.resume();
|
|
291
|
+
|
|
285
292
|
setTimeout(() => {
|
|
286
293
|
console.log('');
|
|
287
294
|
console.log(
|