@archboard/codex-realtime-voice 0.5.0 → 0.6.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 (34) hide show
  1. package/README.md +32 -41
  2. package/dist/browser.d.mts +1 -3
  3. package/dist/browser.mjs +67 -66
  4. package/dist/{contract-CDS04znV.d.mts → contract-B2ILifH5.d.mts} +3 -3
  5. package/dist/{contract-qg6q9-vH.d.mts → contract-CkitFygd.d.mts} +97 -3054
  6. package/dist/{contract-DkiXnfc8.d.mts → contract-D9_WuSxD.d.mts} +3 -3
  7. package/dist/contract.d.mts +1 -1
  8. package/dist/controllers.d.mts +221 -6
  9. package/dist/controllers.mjs +3 -3
  10. package/dist/{gateway-envelope-DRBUhFx9.d.mts → gateway-envelope-O67wCRD7.d.mts} +3 -2
  11. package/dist/{realtime-state-CTBmCjt1.mjs → gateway-envelope-jUP82Pq1.mjs} +71 -3
  12. package/dist/identity-capabilities-3Q_2tJiT.d.mts +147 -0
  13. package/dist/instructions-B-6HVmoD.mjs +1024 -0
  14. package/dist/{contract-JI3xv17m.d.mts → instructions-C6TkBWcp.d.mts} +14 -998
  15. package/dist/{model-DnitkA24.mjs → model-MSyAviwx.mjs} +1652 -85
  16. package/dist/react.d.mts +1 -1
  17. package/dist/{realtime-contract-wHmSyUIe.d.mts → realtime-contract-C-1bMn-F.d.mts} +1 -22
  18. package/dist/realtime.d.mts +2 -3
  19. package/dist/realtime.mjs +1 -3
  20. package/dist/runtime.d.mts +3 -18
  21. package/dist/runtime.mjs +2 -2
  22. package/dist/schemas.d.mts +3 -13
  23. package/dist/schemas.mjs +1 -1
  24. package/dist/server.d.mts +977 -217
  25. package/dist/server.mjs +17771 -10076
  26. package/dist/{snapshot-BCrCORmt.d.mts → snapshot-DCl2vsJl.d.mts} +9 -154
  27. package/dist/{transport-Bqb8KE5T.mjs → transport-DVUz3EK0.mjs} +17 -13
  28. package/package.json +1 -1
  29. package/dist/app-server-contract-D4E5bibD.mjs +0 -177
  30. package/dist/gateway-envelope-DXTRMB3q.mjs +0 -45
  31. package/dist/instructions-8ACs49yJ.mjs +0 -8980
  32. package/dist/media-state-CNkFo93s.d.mts +0 -215
  33. package/dist/realtime-contract-DwkCluo2.mjs +0 -1167
  34. package/dist/realtime-state-DT4uvrIV.d.mts +0 -16
package/README.md CHANGED
@@ -35,11 +35,10 @@ The quickstart is two files in the root of your project: a server and a React pa
35
35
  ```ts
36
36
  import { homedir } from "node:os";
37
37
  import path from "node:path";
38
- import { createVoiceAgent, resolveCodexExecutable } from "@archboard/codex-realtime-voice/server";
38
+ import { createVoiceAgent } from "@archboard/codex-realtime-voice/server";
39
39
 
40
40
  const agent = createVoiceAgent({
41
41
  storage: { directory: path.join(homedir(), ".my-voice-agent") },
42
- codex: { executablePath: resolveCodexExecutable() },
43
42
  checkouts: [process.cwd()],
44
43
  instructions: {
45
44
  coordinator: "Answer short questions yourself. Give sustained work to the workhorse.",
@@ -316,23 +315,25 @@ The state directory is the directory that you give as `storage.directory`. It ho
316
315
 
317
316
  ### `createVoiceAgent(options)`
318
317
 
319
- `createVoiceAgent` creates the agent and starts nothing. It throws when a listed checkout is not a readable directory, when an instruction is empty, or when an `identity` value has the wrong shape.
320
-
321
- | Field | Default | What it does |
322
- | -------------------------- | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
323
- | `storage.directory` | Required | The state directory. The package creates it with mode `0700`. An existing directory must have mode `0700`, belong to you, and not be a symbolic link. A link above it that you or root own, in directories no other user can change, such as `/tmp` on macOS, is resolved once. Keep it outside every checkout. |
324
- | `storage.ownerDirectory` | `<directory>/owner` | Where the process-owner lock and records live. |
325
- | `codex.executablePath` | Required | The absolute path of the Codex executable. Use `resolveCodexExecutable()`. |
326
- | `codex.hostEnvironment` | None | Extra environment variables for the Codex process. They replace inherited values, but never `CODEX_HOME` or `CODEX_SQLITE_HOME`. |
327
- | `codex.pathPrefixes` | None | Absolute directories that go first on the `PATH` of the Codex process, in order. |
328
- | `codex.diagnosticSecrets` | None | Strings that the package removes from the Codex output it keeps for diagnostics. |
329
- | `codex.onGroupOwned` | None | Receives the identity of the Codex process group before the process is ready, for a host that cleans up processes itself. |
330
- | `checkouts` | Required | The admitted checkouts: a list of directories, or a function that returns the admitted path for a named checkout and `null` for a refused one. The package resolves each to its real path. |
331
- | `instructions.coordinator` | Required | Your text for the coordinator. The package appends it to the built-in coordinator role. It must not be empty. |
332
- | `instructions.workhorse` | Required | Your text for each workhorse, appended to the built-in workhorse role. It must not be empty. |
333
- | `identity` | See the identity table below | How the agent names itself to Codex and to the person. See the next table. |
334
- | `onFatal` | Required | Receives a fault that the agent cannot recover from. You decide whether to stop. |
335
- | `extensions` | None | Your own context, voice behavior and tools. See [Advanced hosting](#advanced-hosting). |
318
+ `createVoiceAgent` creates the agent and starts nothing. It throws when a listed checkout is not a readable directory, when an instruction is empty, or when an `identity` value has the wrong shape. Without `codex.executablePath`, it also finds the installed Codex and proves it: an absolute, regular, executable file that reports exactly `codex-cli 0.166.0`, never looked up on `PATH`. When the proof fails, it throws a `CodexExecutableError` with a `code`. Each `start()` proves the executable again, a given `executablePath` included.
319
+
320
+ | Field | Default | What it does |
321
+ | -------------------------- | ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
322
+ | `storage.directory` | Required | The state directory. The package creates it with mode `0700`. An existing directory must have mode `0700`, belong to you, and not be a symbolic link. A link above it that you or root own, in directories no other user can change, such as `/tmp` on macOS, is resolved once. Keep it outside every checkout. |
323
+ | `storage.ownerDirectory` | `<directory>/owner` | Where the process-owner lock and records live. |
324
+ | `codex.executablePath` | The installed `@openai/codex` package | An absolute path of the Codex executable, in place of the installed package. `start()` proves it. |
325
+ | `codex.installedIn` | None | Refuses an installed `@openai/codex` that is not in `<installedIn>/node_modules`, such as a global install. It does not apply to `executablePath`. |
326
+ | `codex.releasedIn` | None | For a host's compiled release: the platform package whose `@openai/codex-<os>-<cpu>` dependency holds the native binary. It does not apply to `executablePath`. |
327
+ | `codex.hostEnvironment` | None | Extra environment variables for the Codex process. They replace inherited values, but never `CODEX_HOME` or `CODEX_SQLITE_HOME`. |
328
+ | `codex.pathPrefixes` | None | Absolute directories that go first on the `PATH` of the Codex process, in order. |
329
+ | `codex.diagnosticSecrets` | None | Strings that the package removes from the Codex output it keeps for diagnostics. |
330
+ | `codex.onGroupOwned` | None | Receives the identity of the Codex process group before the process is ready, for a host that cleans up processes itself. |
331
+ | `checkouts` | Required | The admitted checkouts: a list of directories, or a function that returns the admitted path for a named checkout and `null` for a refused one. The package resolves each to its real path. |
332
+ | `instructions.coordinator` | Required | Your text for the coordinator. The package appends it to the built-in coordinator role. It must not be empty. |
333
+ | `instructions.workhorse` | Required | Your text for each workhorse, appended to the built-in workhorse role. It must not be empty. |
334
+ | `identity` | See the identity table below | How the agent names itself to Codex and to the person. See the next table. |
335
+ | `onFatal` | Required | Receives a fault that the agent cannot recover from. You decide whether to stop. |
336
+ | `extensions` | None | Your own context, voice behavior and tools. See [Advanced hosting](#advanced-hosting). |
336
337
 
337
338
  The agent that `createVoiceAgent` returns has these members:
338
339
 
@@ -380,16 +381,6 @@ A socket that arrives before `start()` is ready is closed with `1011`. After `sh
380
381
  agent.attach(server, { path: "/voice", origin: "http://127.0.0.1:4100" });
381
382
  ```
382
383
 
383
- ### `resolveCodexExecutable(options)`
384
-
385
- `resolveCodexExecutable` finds the Codex executable and proves it before anything runs it. It must be an absolute path to a regular, executable file that reports exactly `codex-cli 0.166.0`. It never looks on `PATH`. It returns the absolute path, and throws a `CodexExecutableError` with a `code` when the proof fails.
386
-
387
- | Field | Default | What it does |
388
- | ---------------- | ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
389
- | `executablePath` | The installed `@openai/codex` package | An absolute path to prove in place of the installed package. |
390
- | `installedIn` | None | Refuses an installed `@openai/codex` that is not in `<installedIn>/node_modules`, such as a global install. It does not apply to `executablePath`. |
391
- | `releasedIn` | None | For a host's compiled release: the platform package whose `@openai/codex-<os>-<cpu>` dependency holds the native binary. It does not apply to `executablePath`. |
392
-
393
384
  ### `createVoiceClient(options)`
394
385
 
395
386
  `createVoiceClient` makes the client of one chat. It opens nothing until you call `connect()`.
@@ -532,29 +523,29 @@ In the browser, `@archboard/codex-realtime-voice/controllers` holds the parts un
532
523
 
533
524
  ### Entry points
534
525
 
535
- | Entry | What it holds |
536
- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
537
- | `./server` | `createVoiceAgent`, `resolveCodexExecutable` and their types. The remaining exports are lower-level parts for a host that routes its own sockets. A host that uses `bunHandlers` or `attach` needs none of them. |
538
- | `./browser` | `createVoiceClient` and its types. |
539
- | `./react` | `VoiceClientProvider`, `useVoiceClient` and `useVoiceState`. |
540
- | `./controllers` | The transport, media and conversation parts under the client. |
541
- | `./contract` | The types of the state that the server publishes, such as `BrowserSnapshot`, `BrowserApproval` and `BrowserTimeline`. |
542
- | `./schemas` | The schemas of that state, for a server that extends it and for tests. |
543
- | `./realtime` | The phases and transitions of a voice run. |
544
- | `./runtime` | Lower-level runtime parts, such as coordinator callbacks and the realtime adapter. |
526
+ | Entry | What it holds |
527
+ | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
528
+ | `./server` | `createVoiceAgent` and its types. The remaining exports are lower-level parts for a host that routes its own sockets. A host that uses `bunHandlers` or `attach` needs none of them. |
529
+ | `./browser` | `createVoiceClient` and its types. |
530
+ | `./react` | `VoiceClientProvider`, `useVoiceClient` and `useVoiceState`. |
531
+ | `./controllers` | The transport, media and conversation parts under the client. |
532
+ | `./contract` | The types of the state that the server publishes, such as `BrowserSnapshot`, `BrowserApproval` and `BrowserTimeline`. |
533
+ | `./schemas` | The schemas of that state, for a server that extends it and for tests. |
534
+ | `./realtime` | The phase and state types of a voice run. |
535
+ | `./runtime` | Lower-level runtime parts, such as coordinator callbacks and the wait graph. |
545
536
 
546
537
  ## Troubleshooting
547
538
 
548
539
  ### Codex reports another version
549
540
 
550
- `resolveCodexExecutable` throws `CodexExecutableError` with code `wrong_version` and the message "The configured Codex executable reported an unexpected version; expected codex-cli 0.166.0." The executable it found is not Codex 0.166.0.
541
+ `createVoiceAgent` throws `CodexExecutableError` with code `wrong_version` and the message "The configured Codex executable reported an unexpected version; expected codex-cli 0.166.0." The executable it found is not Codex 0.166.0. When you pass `executablePath`, `start()` rejects instead, with code `startup_failed` and this reason in its `cause`.
551
542
 
552
543
  1. Run `bun add @openai/codex@0.166.0` in your project.
553
544
  2. If you pass `executablePath`, make sure that it names a Codex 0.166.0 executable.
554
545
 
555
546
  ### The Codex executable is not found
556
547
 
557
- `resolveCodexExecutable` throws `CodexExecutableError`. Code `missing` means that `@openai/codex` is not installed where the package can find it, or that `executablePath` names no file. Code `not_absolute` means that `executablePath` is a relative path or a bare name: the package never looks on `PATH`. Code `version_unavailable` means that the executable did not run. With the installed package, the usual cause is that no `node` is on `PATH`.
548
+ `createVoiceAgent` throws `CodexExecutableError`. Code `missing` means that `@openai/codex` is not installed where the package can find it, or that `executablePath` names no file. Code `not_absolute` means that `executablePath` is a relative path or a bare name: the package never looks on `PATH`. Code `version_unavailable` means that the executable did not run. With the installed package, the usual cause is that no `node` is on `PATH`. When you pass `executablePath`, `start()` rejects instead, with code `startup_failed` and the reason in its `cause`.
558
549
 
559
550
  1. Run `bun add @openai/codex@0.166.0` in the project that runs the server. Package managers that skip peer dependencies leave it out.
560
551
  2. If you pass `executablePath`, give an absolute path.
@@ -1,6 +1,4 @@
1
- import "./media-state-CNkFo93s.mjs";
2
- import "./contract-CDS04znV.mjs";
3
- import { a as VoiceClientSnapshot, i as VoiceClientOptions, n as VoiceApprovalResponse, o as VoiceSignIn, r as VoiceClient, t as VoiceApproval } from "./contract-DkiXnfc8.mjs";
1
+ import { a as VoiceClientSnapshot, i as VoiceClientOptions, n as VoiceApprovalResponse, o as VoiceSignIn, r as VoiceClient, t as VoiceApproval } from "./contract-D9_WuSxD.mjs";
4
2
  /**
5
3
  * Connect one page view to the voice server through the real browser.
6
4
  * @param options The socket path and the chat.
package/dist/browser.mjs CHANGED
@@ -1,49 +1,11 @@
1
- import { c as CODEX_REALTIME_MS } from "./model-DnitkA24.mjs";
2
- import { t as INITIAL_REALTIME_STATE } from "./realtime-state-CTBmCjt1.mjs";
3
- import { n as BrowserWorkbenchTransportError, r as createBrowserWorkbenchMediaOwner, t as createBrowserWorkbenchTransport } from "./transport-Bqb8KE5T.mjs";
4
- // src/ui/voice-client/clients/voice-client.ts
1
+ import { o as expiresAt } from "./model-MSyAviwx.mjs";
2
+ import { r as INITIAL_REALTIME_STATE } from "./gateway-envelope-jUP82Pq1.mjs";
3
+ import { n as BrowserWorkbenchTransportError, r as createBrowserWorkbenchMediaOwner, t as createBrowserWorkbenchTransport } from "./transport-DVUz3EK0.mjs";
4
+ // src/ui/voice-client/clients/open-voice-client.ts
5
5
  const UNCERTAIN = "Delivery is uncertain. Refresh the conversation before trying another action.";
6
- const TAB_SESSION_KEY = "codex-realtime-voice:tab";
7
6
  /** The `readyState` of a socket whose close has begun; `CLOSED` is 3. */
8
7
  const SOCKET_CLOSING = 2;
9
8
  /**
10
- * Connect one page view to the voice server through the real browser.
11
- * @param options The socket path and the chat.
12
- * @returns The client. Call `connect()` to open the socket.
13
- */
14
- function createVoiceClient(options) {
15
- return openVoiceClient(options, {
16
- transport: createBrowserWorkbenchTransport(),
17
- media: createBrowserWorkbenchMediaOwner(),
18
- /**
19
- * A browser WebSocket.
20
- * @param url Where it connects.
21
- * @returns The socket.
22
- */
23
- openSocket: (url) => new WebSocket(url),
24
- /**
25
- * The id kept for this tab.
26
- * @returns The id.
27
- */
28
- tabSessionId: () => storedTabSessionId(TAB_SESSION_KEY),
29
- /**
30
- * The page's own location.
31
- * @returns The URL.
32
- */
33
- pageUrl: () => location.href,
34
- /**
35
- * A browser timer.
36
- * @param delayMs How long to wait.
37
- * @param run What runs then.
38
- * @returns How to cancel it.
39
- */
40
- after: (delayMs, run) => {
41
- const timer = setTimeout(run, delayMs);
42
- return () => clearTimeout(timer);
43
- }
44
- });
45
- }
46
- /**
47
9
  * The client over the owners it is given.
48
10
  * @param options The socket path and the chat.
49
11
  * @param owners The transport, the media owner, the socket factory and the tab identity.
@@ -179,13 +141,13 @@ function openVoiceClient(options, owners) {
179
141
  return completed && !disposed;
180
142
  };
181
143
  /**
182
- * Connect again after a delay, unless the socket is connected by then, and
144
+ * Connect again at a time, unless the socket is connected by then, and
183
145
  * try again after each attempt that does not open. One attempt waits at a time.
184
- * @param delayMs How long to wait.
146
+ * @param retryAtMs When to try, in milliseconds since the epoch.
185
147
  */
186
- const reconnectAfter = (delayMs) => {
148
+ const reconnectAt = (retryAtMs) => {
187
149
  if (disposed || cancelReconnect !== null) return;
188
- cancelReconnect = owners.after(Math.max(0, delayMs), () => {
150
+ cancelReconnect = owners.after(Math.max(0, retryAtMs - Date.now()), () => {
189
151
  cancelReconnect = null;
190
152
  if (disposed || transport.state().connection === "connected") return;
191
153
  reconnect();
@@ -218,11 +180,11 @@ function openVoiceClient(options, owners) {
218
180
  publish();
219
181
  return;
220
182
  }
221
- if (!unreadableServer()) reconnectAfter(CODEX_REALTIME_MS.clientReconnect);
183
+ if (!unreadableServer()) reconnectAt(expiresAt("codex.clientReconnect", Date.now()));
222
184
  };
223
185
  const unsubscribeLoss = transport.subscribe(() => {
224
186
  const state = transport.state();
225
- if (state.kind === "connection" && state.state === "backoff") reconnectAfter(state.retryAtMs - Date.now());
187
+ if (state.kind === "connection" && state.state === "backoff") reconnectAt(state.retryAtMs);
226
188
  });
227
189
  /**
228
190
  * Cancel the sign-in the server shows as pending.
@@ -360,24 +322,6 @@ function openVoiceClient(options, owners) {
360
322
  }
361
323
  /** A reconnect attempt that fails leaves the page's failure as it is. */
362
324
  function ignore() {}
363
- /** The id this page names while storage cannot hold one; a reload then starts another. */
364
- let pageTabSessionId = null;
365
- /**
366
- * The tab's session id, minted once and kept in `sessionStorage`. Storage that
367
- * refuses, as a privacy setting can make it, leaves one id for this page.
368
- * @param key The storage key.
369
- * @returns The id.
370
- */
371
- function storedTabSessionId(key) {
372
- try {
373
- const id = sessionStorage.getItem(key) ?? crypto.randomUUID();
374
- sessionStorage.setItem(key, id);
375
- return id;
376
- } catch {
377
- pageTabSessionId ??= crypto.randomUUID();
378
- return pageTabSessionId;
379
- }
380
- }
381
325
  /**
382
326
  * The socket URL with the chat and tab identity.
383
327
  * @param options The socket path and the chat.
@@ -472,4 +416,61 @@ function opened(socket) {
472
416
  socket.addEventListener("close", () => reject(/* @__PURE__ */ new Error("The voice connection closed.")), { once: true });
473
417
  });
474
418
  }
419
+ // src/ui/voice-client/clients/voice-client.ts
420
+ const TAB_SESSION_KEY = "codex-realtime-voice:tab";
421
+ /**
422
+ * Connect one page view to the voice server through the real browser.
423
+ * @param options The socket path and the chat.
424
+ * @returns The client. Call `connect()` to open the socket.
425
+ */
426
+ function createVoiceClient(options) {
427
+ return openVoiceClient(options, {
428
+ transport: createBrowserWorkbenchTransport(),
429
+ media: createBrowserWorkbenchMediaOwner(),
430
+ /**
431
+ * A browser WebSocket.
432
+ * @param url Where it connects.
433
+ * @returns The socket.
434
+ */
435
+ openSocket: (url) => new WebSocket(url),
436
+ /**
437
+ * The id kept for this tab.
438
+ * @returns The id.
439
+ */
440
+ tabSessionId: () => storedTabSessionId(TAB_SESSION_KEY),
441
+ /**
442
+ * The page's own location.
443
+ * @returns The URL.
444
+ */
445
+ pageUrl: () => location.href,
446
+ /**
447
+ * A browser timer.
448
+ * @param delayMs How long to wait.
449
+ * @param run What runs then.
450
+ * @returns How to cancel it.
451
+ */
452
+ after: (delayMs, run) => {
453
+ const timer = setTimeout(run, delayMs);
454
+ return () => clearTimeout(timer);
455
+ }
456
+ });
457
+ }
458
+ /** The id this page names while storage cannot hold one; a reload then starts another. */
459
+ let pageTabSessionId = null;
460
+ /**
461
+ * The tab's session id, minted once and kept in `sessionStorage`. Storage that
462
+ * refuses, as a privacy setting can make it, leaves one id for this page.
463
+ * @param key The storage key.
464
+ * @returns The id.
465
+ */
466
+ function storedTabSessionId(key) {
467
+ try {
468
+ const id = sessionStorage.getItem(key) ?? crypto.randomUUID();
469
+ sessionStorage.setItem(key, id);
470
+ return id;
471
+ } catch {
472
+ pageTabSessionId ??= crypto.randomUUID();
473
+ return pageTabSessionId;
474
+ }
475
+ }
475
476
  export { createVoiceClient };
@@ -1,6 +1,6 @@
1
- import { h as BrowserThreadLink, i as BrowserCommandLease, p as BrowserSnapshot, r as BrowserCommand, u as BrowserReadiness } from "./snapshot-BCrCORmt.mjs";
2
- import { a as CodexServerResponseByMethod, n as CodexLoginAccountParams } from "./contract-qg6q9-vH.mjs";
3
- import { a as BrowserGatewaySnapshotMessage, n as BrowserGatewayCommandResult, t as BrowserGatewayAccountReadResult } from "./gateway-envelope-DRBUhFx9.mjs";
1
+ import { n as CodexLoginAccountParams, r as CodexServerResponseByMethod } from "./contract-CkitFygd.mjs";
2
+ import { a as BrowserReadiness, l as BrowserThreadLink, n as BrowserCommand, r as BrowserCommandLease, s as BrowserSnapshot } from "./snapshot-DCl2vsJl.mjs";
3
+ import { a as BrowserGatewaySnapshotMessage, n as BrowserGatewayCommandResult, t as BrowserGatewayAccountReadResult } from "./gateway-envelope-O67wCRD7.mjs";
4
4
  /**
5
5
  * The browser socket as the transport sees it. The application owns opening and closing it.
6
6
  */