@agi-cli/web-ui 0.1.56 → 0.1.58

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/README.md CHANGED
@@ -35,17 +35,21 @@ import { serveWebUI } from '@agi-cli/web-ui';
35
35
 
36
36
  Bun.serve({
37
37
  port: 3000,
38
+ idleTimeout: 240, // IMPORTANT: prevents SSE timeout
38
39
  fetch: serveWebUI({ prefix: '/ui' })
39
40
  });
40
41
 
41
42
  console.log('Web UI: http://localhost:3000/ui');
42
43
  ```
43
44
 
45
+ > **⚠️ Important**: Always set `idleTimeout: 240` (or higher) in `Bun.serve()` to prevent SSE connection timeouts. The web UI uses Server-Sent Events for real-time streaming, and Bun's default timeout of 10 seconds will cause connections to drop.
46
+
44
47
  That's it! The web UI will be available at `/ui` with:
45
48
  - ✅ Automatic SPA routing
46
49
  - ✅ Asset path handling (both `/ui/assets/*` and `/assets/*`)
47
50
  - ✅ Proper MIME types
48
51
  - ✅ 404 fallbacks
52
+ - ✅ Real-time SSE streaming
49
53
 
50
54
  ### With Custom Routes
51
55
 
@@ -109,6 +113,44 @@ Bun.serve({
109
113
  console.log('Web UI: http://localhost:3000/admin');
110
114
  ```
111
115
 
116
+ ### Custom Server URL
117
+
118
+ When serving both the API and web UI from the same server, you can configure the web UI to connect to your server instead of the default `localhost:9100`:
119
+
120
+ ```typescript
121
+ import { createApp } from '@agi-cli/server';
122
+ import { serveWebUI } from '@agi-cli/web-ui';
123
+
124
+ const port = parseInt(process.env.PORT || '3000', 10);
125
+ const host = process.env.HOST || '127.0.0.1';
126
+
127
+ const app = createApp();
128
+ const handleWebUI = serveWebUI({
129
+ prefix: '/ui',
130
+ serverUrl: `http://${host}:${port}`, // Explicit server URL
131
+ });
132
+
133
+ // Or let it auto-detect (recommended for same-server setup):
134
+ // const handleWebUI = serveWebUI({ prefix: '/ui' });
135
+
136
+ const server = Bun.serve({
137
+ port,
138
+ hostname: host,
139
+ async fetch(req) {
140
+ // Serve web UI first
141
+ const webUIResponse = await handleWebUI(req);
142
+ if (webUIResponse) return webUIResponse;
143
+
144
+ // Then API routes
145
+ return app.fetch(req);
146
+ },
147
+ });
148
+
149
+ console.log(`Server: http://${host}:${server.port}/ui`);
150
+ ```
151
+
152
+ > **Note:** If you don't specify `serverUrl`, the web UI will automatically detect the server URL from the incoming request. This is recommended when serving both the API and UI from the same server.
153
+
112
154
  ## API Reference
113
155
 
114
156
  ### `serveWebUI(options?): (req: Request) => Promise<Response | null>`
@@ -122,6 +164,7 @@ Creates a request handler that serves the web UI.
122
164
  | `prefix` | `string` | `'/ui'` | URL prefix for the web UI |
123
165
  | `redirectRoot` | `boolean` | `false` | Redirect `/` to the prefix |
124
166
  | `onNotFound` | `(req: Request) => Response \| null` | `null` | Custom 404 handler |
167
+ | `serverUrl` | `string` | Auto-detected | API server URL for the web UI to connect to. If not provided, auto-detects from request (e.g., `http://localhost:3000`) |
125
168
 
126
169
  **Returns:** A request handler function that returns:
127
170
  - `Response` if the request matches a web UI route
package/dist/index.d.ts CHANGED
@@ -25,6 +25,13 @@ export interface ServeWebUIOptions {
25
25
  * Custom 404 handler
26
26
  */
27
27
  onNotFound?: (req: Request) => Response | Promise<Response> | null;
28
+ /**
29
+ * API server URL for the web UI to connect to
30
+ * If not provided, will attempt to auto-detect from the request
31
+ * or fall back to localhost:9100
32
+ * @example 'http://localhost:3000', 'https://api.example.com'
33
+ */
34
+ serverUrl?: string;
28
35
  }
29
36
  /**
30
37
  * Create a request handler for serving the web UI
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAa1C;AAED,MAAM,WAAW,iBAAiB;IACjC;;;OAGG;IACH,MAAM,CAAC,EAA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