better-codex 0.1.3 → 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.
@@ -39,6 +39,7 @@ const sendWsEvent = (event: WsEvent) => {
39
39
  const app = new Elysia()
40
40
  .use(cors({ origin: true }))
41
41
  .get('/health', () => ({ ok: true }))
42
+ .get('/config', () => ({ token: config.authToken }))
42
43
  .get(
43
44
  '/analytics/daily',
44
45
  ({ query }) => {
@@ -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 { HUB_TOKEN, HUB_URL } from '../config'
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
- if (!HUB_TOKEN) {
132
- throw new Error('Missing VITE_CODEX_HUB_TOKEN')
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, HUB_TOKEN))
136
+ const ws = new WebSocket(toWsUrl(HUB_URL, token))
136
137
  this.ws = ws
137
138
 
138
139
  ws.onmessage = (event) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-codex",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Web launcher for Codex Hub",
5
5
  "bin": {
6
6
  "better-codex": "bin/better-codex.cjs"