@alexkroman1/aai-ui 0.12.2 → 0.13.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 (215) hide show
  1. package/README.md +257 -0
  2. package/dist/_colors-CpZO-88A.js +78 -0
  3. package/dist/_module-url-C13kAJ87.js +15 -0
  4. package/dist/_page-shell.d.ts +11 -0
  5. package/dist/_recover-run.d.ts +79 -0
  6. package/dist/_repeat-until.d.ts +30 -0
  7. package/dist/_run-controls.d.ts +33 -0
  8. package/dist/_submission-state.d.ts +92 -0
  9. package/dist/_tap-to-talk-state.d.ts +88 -0
  10. package/dist/_utils-Mi-SCFA1.js +47 -0
  11. package/dist/_utils.d.ts +26 -0
  12. package/dist/_web-storage.d.ts +43 -0
  13. package/dist/_workflow-api-ref.d.ts +37 -0
  14. package/dist/_workflow-files.d.ts +34 -0
  15. package/dist/_workflow-test-defs.d.ts +38 -0
  16. package/dist/aai-logo-D8pMVn9_.js +85 -0
  17. package/dist/agent-state-labels.d.ts +65 -0
  18. package/dist/agent-state.d.ts +108 -0
  19. package/dist/audio/capture.d.ts +44 -0
  20. package/dist/audio/index.d.ts +18 -0
  21. package/dist/audio/index.js +431 -0
  22. package/dist/audio/preconnect.d.ts +87 -0
  23. package/dist/audio/voice-io.d.ts +112 -0
  24. package/dist/build-default-client.d.ts +1 -0
  25. package/dist/chat-view-BCbI7gD4.js +396 -0
  26. package/dist/client-config-C7fQrioM.js +139 -0
  27. package/dist/client-config.d.ts +119 -0
  28. package/dist/client-dir.d.ts +44 -0
  29. package/dist/client-dir.js +58 -0
  30. package/dist/client-identity.d.ts +131 -0
  31. package/dist/client-tool.d.ts +51 -0
  32. package/dist/components/_colors.d.ts +73 -0
  33. package/dist/components/_form-readiness.d.ts +56 -0
  34. package/dist/components/_form-values.d.ts +19 -0
  35. package/dist/components/aai-logo.d.ts +12 -0
  36. package/dist/components/audio-result.d.ts +94 -0
  37. package/dist/components/auto-scroll.d.ts +74 -0
  38. package/dist/components/bullet-list.d.ts +74 -0
  39. package/dist/components/button.d.ts +58 -0
  40. package/dist/components/button.js +85 -0
  41. package/dist/components/chat-view.d.ts +35 -0
  42. package/dist/components/chat-view.js +3 -0
  43. package/dist/components/console-shell.d.ts +85 -0
  44. package/dist/components/controls.d.ts +33 -0
  45. package/dist/components/controls.js +49 -0
  46. package/dist/components/conversation-view.d.ts +130 -0
  47. package/dist/components/eyebrow.d.ts +12 -0
  48. package/dist/components/facts.d.ts +81 -0
  49. package/dist/components/form-fields.d.ts +142 -0
  50. package/dist/components/form-types.d.ts +73 -0
  51. package/dist/components/form.d.ts +96 -0
  52. package/dist/components/markdown.d.ts +57 -0
  53. package/dist/components/message-list.d.ts +48 -0
  54. package/dist/components/message-list.js +3 -0
  55. package/dist/components/session-controls.d.ts +125 -0
  56. package/dist/components/session-error-banner.d.ts +69 -0
  57. package/dist/components/session-state-dot.d.ts +111 -0
  58. package/dist/components/sidebar-layout.d.ts +42 -0
  59. package/dist/components/sidebar-layout.js +56 -0
  60. package/dist/components/start-screen.d.ts +37 -0
  61. package/dist/components/start-screen.js +71 -0
  62. package/dist/components/tool-call-block.d.ts +28 -0
  63. package/dist/components/tool-call-block.js +3 -0
  64. package/dist/components/tool-call-row.d.ts +75 -0
  65. package/dist/components/tool-config-context.d.ts +22 -0
  66. package/dist/components/upload-progress.d.ts +76 -0
  67. package/dist/components/url-chips.d.ts +29 -0
  68. package/dist/components/workflow-fields.d.ts +46 -0
  69. package/dist/components/workflow-pending-note.d.ts +81 -0
  70. package/dist/components/workflow-progress.d.ts +81 -0
  71. package/dist/components/workflow-run-error.d.ts +48 -0
  72. package/dist/components/workflow-run-panel.d.ts +79 -0
  73. package/dist/context.d.ts +288 -0
  74. package/dist/context.js +382 -0
  75. package/dist/conversation-log.d.ts +88 -0
  76. package/dist/default-client/assets/_module-url-BX0RuRU2.js +1 -0
  77. package/dist/default-client/assets/audio-cGFGID-2.js +1 -0
  78. package/dist/default-client/assets/capture-processor-BUABoo3_.js +90 -0
  79. package/dist/default-client/assets/index-8ihb1Urm.css +2 -0
  80. package/dist/default-client/assets/index-BQURVARl.js +126 -0
  81. package/dist/default-client/assets/playback-processor-ABOa11j0.js +314 -0
  82. package/dist/default-client/favicon.ico +0 -0
  83. package/dist/default-client/index.html +15 -0
  84. package/dist/default-client.d.ts +23 -0
  85. package/dist/define-client.d.ts +162 -26
  86. package/dist/define-client.js +201 -55
  87. package/dist/eyebrow-UfmSz9yy.js +27 -0
  88. package/dist/hooks-DN4gHYsj.js +182 -0
  89. package/dist/hooks.d.ts +172 -0
  90. package/dist/hooks.js +3 -0
  91. package/dist/hooks.test-d.d.ts +14 -0
  92. package/dist/inbox-protocol.d.ts +128 -0
  93. package/dist/inbox.d.ts +132 -0
  94. package/dist/index.d.ts +129 -32
  95. package/dist/index.js +5503 -18
  96. package/dist/internal.d.ts +43 -0
  97. package/dist/internal.js +8 -0
  98. package/dist/linked-client.d.ts +70 -0
  99. package/dist/message-list-DHZcLhRA.js +682 -0
  100. package/dist/notice-player.d.ts +70 -0
  101. package/dist/page.d.ts +114 -0
  102. package/dist/phone.d.ts +50 -0
  103. package/dist/route-fetch.d.ts +79 -0
  104. package/dist/session/audio-effects.d.ts +31 -0
  105. package/dist/session/audio-setup.d.ts +57 -0
  106. package/dist/session/audio-state.d.ts +157 -0
  107. package/dist/session/browser-session.d.ts +30 -0
  108. package/dist/session/close.d.ts +26 -0
  109. package/dist/session/dial.d.ts +65 -0
  110. package/dist/session/handshake.d.ts +60 -0
  111. package/dist/session/index.d.ts +17 -0
  112. package/dist/session/index.js +2 -0
  113. package/dist/session/messages.d.ts +63 -0
  114. package/dist/session/mic.d.ts +64 -0
  115. package/dist/session/preconnect.d.ts +48 -0
  116. package/dist/session/reconnect.d.ts +25 -0
  117. package/dist/session/resume-store.d.ts +57 -0
  118. package/dist/session/state.d.ts +146 -0
  119. package/dist/session/ticket.d.ts +44 -0
  120. package/dist/session/types.d.ts +476 -0
  121. package/dist/session/url.d.ts +17 -0
  122. package/dist/session/user-turn.d.ts +55 -0
  123. package/dist/session-CE0Ipsb3.js +2129 -0
  124. package/dist/stored-value.d.ts +103 -0
  125. package/dist/tool-call-block-uXtMOUWN.js +204 -0
  126. package/dist/tool-config-context-Es4YUzV2.js +19 -0
  127. package/dist/types.d.ts +272 -34
  128. package/dist/types.js +35 -4
  129. package/dist/upload/files.d.ts +83 -0
  130. package/dist/upload/index.d.ts +15 -0
  131. package/dist/upload/pause.d.ts +31 -0
  132. package/dist/upload/recall.d.ts +67 -0
  133. package/dist/upload/report.d.ts +26 -0
  134. package/dist/upload/session.d.ts +99 -0
  135. package/dist/url-chips-oyy_Eiqh.js +239 -0
  136. package/dist/use-client-runs.d.ts +87 -0
  137. package/dist/use-conversation-log.d.ts +86 -0
  138. package/dist/use-conversation.d.ts +131 -0
  139. package/dist/use-copy.d.ts +74 -0
  140. package/dist/use-download-url.d.ts +84 -0
  141. package/dist/use-flash.d.ts +61 -0
  142. package/dist/use-inbox.d.ts +101 -0
  143. package/dist/use-push-to-talk.d.ts +105 -0
  144. package/dist/use-route-mutation.d.ts +113 -0
  145. package/dist/use-route.d.ts +82 -0
  146. package/dist/use-run-key.d.ts +133 -0
  147. package/dist/use-session-controls.d.ts +69 -0
  148. package/dist/use-session-id.d.ts +57 -0
  149. package/dist/use-tap-to-talk.d.ts +138 -0
  150. package/dist/use-user-transcript-uyHhzy4d.js +73 -0
  151. package/dist/use-user-transcript.d.ts +75 -0
  152. package/dist/use-workflow-form.d.ts +285 -0
  153. package/dist/use-workflow-progress.d.ts +137 -0
  154. package/dist/use-workflow-run-DdhWmbx-.js +697 -0
  155. package/dist/use-workflow-run.d.ts +100 -0
  156. package/dist/use-workflow-runs.d.ts +71 -0
  157. package/dist/use-workflow-stream.d.ts +154 -0
  158. package/dist/use-workflows.d.ts +77 -0
  159. package/dist/workflow-client.d.ts +136 -0
  160. package/dist/workflow-def-types.d.ts +31 -0
  161. package/dist/workflow-events.d.ts +39 -0
  162. package/dist/workflow-field-kind.d.ts +95 -0
  163. package/dist/workflow-status-labels.d.ts +35 -0
  164. package/dist/worklets/_module-url.d.ts +10 -0
  165. package/dist/worklets/_playback-bench-harness.d.ts +181 -0
  166. package/dist/worklets/_playback-bench-host.d.ts +63 -0
  167. package/dist/worklets/_playback-bench-page.d.ts +65 -0
  168. package/dist/worklets/_tts-trace-harness.d.ts +142 -0
  169. package/dist/worklets/_worklet-test-utils.d.ts +27 -0
  170. package/dist/worklets/capture-processor.d.ts +4 -2
  171. package/dist/worklets/capture-processor.js +73 -33
  172. package/dist/worklets/playback-processor.d.ts +4 -2
  173. package/dist/worklets/playback-processor.js +258 -42
  174. package/package.json +58 -31
  175. package/styles.css +152 -30
  176. package/dist/_components/app.d.ts +0 -23
  177. package/dist/_components/app.js +0 -41
  178. package/dist/_components/button.d.ts +0 -50
  179. package/dist/_components/button.js +0 -46
  180. package/dist/_components/chat-view.d.ts +0 -29
  181. package/dist/_components/chat-view.js +0 -61
  182. package/dist/_components/controls.d.ts +0 -18
  183. package/dist/_components/controls.js +0 -37
  184. package/dist/_components/error-banner.d.ts +0 -21
  185. package/dist/_components/error-banner.js +0 -27
  186. package/dist/_components/message-bubble.d.ts +0 -23
  187. package/dist/_components/message-bubble.js +0 -35
  188. package/dist/_components/message-list.d.ts +0 -21
  189. package/dist/_components/message-list.js +0 -76
  190. package/dist/_components/sidebar-layout.d.ts +0 -21
  191. package/dist/_components/sidebar-layout.js +0 -36
  192. package/dist/_components/start-screen.d.ts +0 -26
  193. package/dist/_components/start-screen.js +0 -51
  194. package/dist/_components/state-indicator.d.ts +0 -29
  195. package/dist/_components/state-indicator.js +0 -37
  196. package/dist/_components/thinking-indicator.d.ts +0 -16
  197. package/dist/_components/thinking-indicator.js +0 -34
  198. package/dist/_components/tool-call-block.d.ts +0 -27
  199. package/dist/_components/tool-call-block.js +0 -118
  200. package/dist/_components/tool-icons.d.ts +0 -17
  201. package/dist/_components/tool-icons.js +0 -128
  202. package/dist/_components/transcript.d.ts +0 -25
  203. package/dist/_components/transcript.js +0 -35
  204. package/dist/audio.d.ts +0 -45
  205. package/dist/audio.js +0 -121
  206. package/dist/client-context.d.ts +0 -33
  207. package/dist/client-context.js +0 -15
  208. package/dist/client-handler.d.ts +0 -43
  209. package/dist/session-CWB7vmqz.js +0 -429
  210. package/dist/session.d.ts +0 -69
  211. package/dist/session.js +0 -2
  212. package/dist/signals.d.ts +0 -120
  213. package/dist/signals.js +0 -161
  214. package/dist/tsdown.config.d.ts +0 -2
  215. package/dist/types.test-d.d.ts +0 -7
@@ -0,0 +1,128 @@
1
+ /**
2
+ * The browser half of the `WS /inbox` wire, without the socket: frames in, what
3
+ * to play and what to answer out.
4
+ *
5
+ * The server half is `aai-runtime`'s `aai-runtime/src/inbox/inbox.ts`, and the frames are
6
+ * declared once, as `InboxServerFrame` / `InboxClientFrame` on
7
+ * `@alexkroman1/aai/protocol`, which both ends are typed against: a notice
8
+ * header followed by `bytes` of audio in binary frames, answered with an ack or
9
+ * a busy. What this module adds are the
10
+ * CLIENT's rules, which the wire cannot state and which a firmware client
11
+ * (`inbox.c` on an ESP32 speaker) worked out first:
12
+ *
13
+ * - **A repeat is acked, never replayed.** Delivery is at-least-once — an ack
14
+ * lost on the way back is the same notice again, by id — so the last
15
+ * {@link RECENT_NOTICE_IDS} acked ids are remembered and a repeat of one is
16
+ * acked without being played.
17
+ * - **A repeat is acked EVEN WHILE BUSY.** Busy means "try again later", and for
18
+ * a notice already played there is no later: answering busy would have the
19
+ * run resend it until its attempts run out. And since the server settles a
20
+ * notice as busy if ANY holder was busy, a busy repeat also re-offers it to
21
+ * every other holder of the client.
22
+ * - **A header mid-notice cuts the last one short, UNACKED.** The server sends
23
+ * one notice per client at a time, so a new header means the old one's socket
24
+ * write was abandoned; it will be resent, and acking what arrived would lose
25
+ * the rest.
26
+ * - **Audio past `bytes` is dropped; bytes with no header are dropped.** A
27
+ * header that is not one this can take is left UNANSWERED (the server's ack
28
+ * timeout settles it) — the same as the device, which cannot answer an id it
29
+ * could not parse.
30
+ *
31
+ * The live-conversation frames a holder asked for with `?events=1`
32
+ * (`aai-runtime/src/inbox/event-feed.ts` server-side) share the text channel and are told apart
33
+ * by {@link parseInboxEvent}.
34
+ */
35
+ import { type InboxClientFrame, type InboxServerFrame } from "@alexkroman1/aai/protocol";
36
+ /**
37
+ * One notice from the agent — what a workflow step sent with
38
+ * `stepNotifyClient`, e.g. a reminder coming due.
39
+ *
40
+ * @public
41
+ */
42
+ export type InboxNotice = {
43
+ /** Identifies the DELIVERY (usually the run id); a repeat carries the same one. */
44
+ readonly id: string;
45
+ /** What the notice is, as the step named it — `"reminder"`, say. */
46
+ readonly event: string;
47
+ /** The step's `data`, when it sent an object. */
48
+ readonly data?: Readonly<Record<string, unknown>>;
49
+ /**
50
+ * The notice's audio as sent: `stepSpeak`'s PCM16LE mono, which `useInbox`'s
51
+ * built-in playback plays at 16 kHz. Empty for a notice with no audio.
52
+ */
53
+ readonly pcm: Uint8Array;
54
+ };
55
+ /**
56
+ * One frame of the client's live conversation, sent to a holder that asked
57
+ * for events: every session bound to the client, this tab's own included —
58
+ * filter on `sessionId` (`useSessionId()`) to show only the OTHER ones.
59
+ *
60
+ * @public
61
+ */
62
+ export type InboxEvent = {
63
+ readonly type: "session_event";
64
+ readonly sessionId: string;
65
+ /** The session event as the session socket would carry it (`type`, then its fields). */
66
+ readonly event: {
67
+ readonly type: string;
68
+ } & Readonly<Record<string, unknown>>;
69
+ } | {
70
+ readonly type: "session_ended";
71
+ readonly sessionId: string;
72
+ };
73
+ /**
74
+ * The largest notice taken: 60 s of 16 kHz PCM16, the firmware's
75
+ * `PROTO_NOTICE_MAX_BYTES`. A header claiming more is refused rather than
76
+ * buffered — a page holds the whole notice in memory before it plays.
77
+ */
78
+ export declare const MAX_NOTICE_BYTES: number;
79
+ /** How many acked ids are remembered to drop a repeat — the firmware's `RECENT_IDS`. */
80
+ export declare const RECENT_NOTICE_IDS = 8;
81
+ /** The wire's notice header, as the server sends it. */
82
+ type NoticeFrame = Extract<InboxServerFrame, {
83
+ type: "notice";
84
+ }>;
85
+ /**
86
+ * A notice header this client can take: the wire's, minus its `type`, with
87
+ * `data` kept only when it is an object.
88
+ */
89
+ export type NoticeHeader = Omit<NoticeFrame, "type" | "data"> & {
90
+ data?: Record<string, unknown>;
91
+ };
92
+ /** What the client answers — the wire's client→server frame. */
93
+ export type NoticeReply = InboxClientFrame;
94
+ /** What one frame produced: a notice to play (not for a repeat), and the reply. */
95
+ export type AssemblerOutput = {
96
+ notice?: InboxNotice;
97
+ reply: NoticeReply;
98
+ };
99
+ /**
100
+ * A notice header this client can take, or undefined — for anything that is
101
+ * not one, and for a header it must refuse (odd byte count: not PCM16; more
102
+ * than {@link MAX_NOTICE_BYTES}).
103
+ */
104
+ export declare function parseNoticeHeader(json: string): NoticeHeader | undefined;
105
+ /**
106
+ * A live-event frame, or undefined for anything else (a notice header, say).
107
+ * The wire's live frames are returned as the published {@link InboxEvent}, so
108
+ * that view cannot drift from what the server sends without this failing to
109
+ * compile.
110
+ */
111
+ export declare function parseInboxEvent(json: string): InboxEvent | undefined;
112
+ /**
113
+ * The receiving state machine of one socket — see the module doc for its four
114
+ * rules. `busy()` is asked when a NEW notice's header arrives, never for a
115
+ * repeat.
116
+ */
117
+ export declare function createNoticeAssembler(busy: () => boolean): {
118
+ /** A text frame that is not a live event. A header mid-notice drops the last one, unacked. */
119
+ text(json: string): AssemblerOutput | undefined;
120
+ /**
121
+ * Forget a notice half-received (its socket closed), keeping the repeat
122
+ * memory — the redelivery after a lost ack comes on the NEXT socket.
123
+ */
124
+ reset(): void;
125
+ /** A binary frame of the pending notice's audio. */
126
+ bytes(chunk: Uint8Array): AssemblerOutput | undefined;
127
+ };
128
+ export {};
@@ -0,0 +1,132 @@
1
+ /**
2
+ * `createInbox()` — hold this client's `WS /inbox?client=` socket open, so a
3
+ * workflow run can reach the page after the voice session that started it has
4
+ * closed: a reminder coming due, a research job finishing.
5
+ *
6
+ * The framework-agnostic core `useInbox()` wraps; the receiving rules (acks,
7
+ * repeats, busy, a notice cut short) are `inbox-protocol.ts`, and the server
8
+ * half is `aai-runtime`'s `aai-runtime/src/inbox/inbox.ts`.
9
+ *
10
+ * - **Held from creation, reconnected until `close()`**, on a jittered backoff
11
+ * from 1 s doubling to 30 s (`jitteredBackoff`), reset by every open. The
12
+ * jitter matters here more than for most loops: an agent restart drops every
13
+ * open inbox at once, and every tab of every user comes back together.
14
+ * - **Its own socket, not partysocket.** The session's reconnecting socket
15
+ * re-brokers and resumes; the inbox has nothing to resume — a notice in
16
+ * flight when the socket drops settles `"disconnected"` server-side and the
17
+ * step resends it — so a plain `WebSocket` and a timer are the whole job.
18
+ * - **The client id is asked per ATTEMPT**, like the session's `?client=`, so a
19
+ * page that changes it (joining a speaker) is heard on the next reconnect. No
20
+ * valid id means no socket this attempt — the loop keeps asking on its
21
+ * backoff, so a getter that answers later is picked up.
22
+ * - **`?holder=` names this TAB** (`session.identity.holderId()`), so the page
23
+ * coexists with the device and the other tabs holding the same client rather
24
+ * than replacing their sockets.
25
+ * - **A gated server checks a ticket here exactly as on `/websocket`**, so the
26
+ * inbox presents one the same way (`token`, asked per attempt, carried by
27
+ * `session/ticket.ts`). `useInbox()` passes the session's
28
+ * (`session.identity.ticket()`). A token answered synchronously (or none)
29
+ * dials at once; a Promise dials when it settles.
30
+ * - **The URL is the agent's base URL + `inbox`**, like the session's
31
+ * `websocket`. On the managed platform the route is DIRECT-DIAL (served on the
32
+ * sandbox URL, not proxied at `/:slug/inbox`), so today this reaches an agent
33
+ * under `aai dev`, `aai start` or a self-hosted server.
34
+ *
35
+ * @module
36
+ */
37
+ import { type InboxEvent, type InboxNotice } from "./inbox-protocol.ts";
38
+ import type { VoiceSessionOptions, WebSocketConstructor } from "./types.ts";
39
+ /** The first reconnect window; each failure doubles it. */
40
+ export declare const INBOX_RECONNECT_BASE_MS = 1000;
41
+ /** The largest reconnect window. */
42
+ export declare const INBOX_RECONNECT_MAX_MS = 30000;
43
+ /**
44
+ * Options for {@link createInbox}.
45
+ *
46
+ * @public
47
+ */
48
+ export type CreateInboxOptions = {
49
+ /** The agent's base URL — the socket is `<platformUrl>/inbox`. */
50
+ platformUrl: string;
51
+ /**
52
+ * This client's id, as the session sends it: a string, or a getter asked on
53
+ * every connection attempt. An answer that is not a valid client id (letters,
54
+ * digits, `-`, `_`, at most 64) opens no socket that attempt.
55
+ */
56
+ client: string | (() => string | undefined);
57
+ /**
58
+ * This page's holder id among the client's holders — per TAB (see
59
+ * `session.identity.holderId()`). Same rule as a client id.
60
+ */
61
+ holder: string;
62
+ /**
63
+ * Asked when a new notice arrives: `true` answers `busy` and the step sends it
64
+ * again later. Default: never busy. Not asked for a repeat, which is acked.
65
+ */
66
+ busy?: (() => boolean) | undefined;
67
+ /** A notice arrived whole — once per delivery id; a repeat is acked, not delivered. */
68
+ onNotice?: ((notice: InboxNotice) => void) | undefined;
69
+ /** A frame of the client's live conversation — only with `events`. */
70
+ onEvent?: ((event: InboxEvent) => void) | undefined;
71
+ /**
72
+ * Ask for the client's live conversation (`?events=1`). Default: whether an
73
+ * `onEvent` was given.
74
+ */
75
+ events?: boolean | undefined;
76
+ /**
77
+ * The session ticket to present, for a server that requires one — the same
78
+ * option, with the same rules, as `VoiceSessionOptions.token`: a string, or a
79
+ * getter asked on EVERY connection attempt (told `sessionId: undefined`; the
80
+ * inbox resumes no session). A getter that throws or rejects presents none.
81
+ * `useInbox()` fills it in from the session.
82
+ */
83
+ token?: VoiceSessionOptions["token"];
84
+ /** WebSocket constructor override, for tests. Default: the page's `WebSocket`. */
85
+ WebSocket?: WebSocketConstructor | undefined;
86
+ };
87
+ /**
88
+ * A held inbox socket — see {@link createInbox}.
89
+ *
90
+ * @sealed Only `createInbox` produces one.
91
+ *
92
+ * @public
93
+ */
94
+ export type Inbox = {
95
+ /** Whether the socket is open now. */
96
+ connected(): boolean;
97
+ /** Called whenever `connected()` changes. Returns the unsubscribe. */
98
+ subscribe(callback: () => void): () => void;
99
+ /** Close the socket for good and stop reconnecting. */
100
+ close(): void;
101
+ };
102
+ /**
103
+ * Hold `WS /inbox?client=&holder=` open, reconnecting with backoff, and answer
104
+ * every notice the way the protocol requires — `ack` once it has arrived whole,
105
+ * `busy` when `busy()` says so, a repeat acked without being delivered twice.
106
+ *
107
+ * Most clients call `useInbox()`, which fills in the client, holder and base URL
108
+ * from the session and plays each notice. This is the same thing for a page
109
+ * with no React, or for an inbox held under a different client than the
110
+ * session's.
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * import { createInbox } from "@alexkroman1/aai-ui";
115
+ *
116
+ * const inbox = createInbox({
117
+ * platformUrl: "https://speaker.example/",
118
+ * client: "kitchen-speaker",
119
+ * holder: "kitchen-speaker-tab1",
120
+ * onNotice: (notice) => console.log(notice.event, notice.data),
121
+ * });
122
+ * // later
123
+ * inbox.close();
124
+ * ```
125
+ *
126
+ * @param options - Where to connect, as whom, and what to do with a notice.
127
+ * @returns The {@link Inbox} handle.
128
+ * @throws RangeError when `holder` is not a valid holder id.
129
+ *
130
+ * @public
131
+ */
132
+ export declare function createInbox(options: CreateInboxOptions): Inbox;
package/dist/index.d.ts CHANGED
@@ -1,37 +1,134 @@
1
1
  /**
2
- * Browser client library for AAI voice agents.
2
+ * The browser client for aai agents — React 19 hooks and components over a
3
+ * framework-agnostic session core (WebSocket + microphone + playback).
3
4
  *
4
- * Provides WebSocket session management, audio capture/playback,
5
- * and Preact UI components. For a narrower import without the Preact
6
- * dependency, use `@aai/ui/session`.
5
+ * ## Start with a mount
7
6
  *
8
- * @example
9
- * ```tsx
10
- * import { App, defineClient } from "@aai/ui";
7
+ * A client is one `client.tsx` calling one mount, and WHICH mount is the only
8
+ * structural decision on this surface — it follows the agent's front door:
11
9
  *
12
- * defineClient(App, { target: "#app" });
13
- * ```
10
+ * | The agent is | The page calls | It talks to |
11
+ * | --- | --- | --- |
12
+ * | a voice agent (the default) | {@link mountClient} | a live session: socket, microphone, playback |
13
+ * | a `workflowApp()` / `agent({ mode: "workflow-app" })` | {@link mountPage} | the workflow HTTP API — no session, no socket, no mic |
14
+ *
15
+ * There is no route to write and no glue file: the agent server already serves
16
+ * both, so a component talks to a live agent directly. {@link createBrowserSession}
17
+ * is the same session core with no React, for a page built on something else.
18
+ *
19
+ * ## Then the hook that answers your question
20
+ *
21
+ * The hooks are grouped by what they read, and within a group the narrow one
22
+ * exists so a component re-renders on its own slice rather than on every frame:
23
+ *
24
+ * | Reading | Hooks |
25
+ * | --- | --- |
26
+ * | the call itself | {@link useSession} (everything), {@link useSessionStatus}, {@link useSessionError}, {@link useSessionActions}, {@link useSessionSelector} |
27
+ * | who the client is | {@link useSessionId}, {@link useClientId}, {@link browserClientId}, {@link createLinkedClient} |
28
+ * | a run reaching the page later | {@link useInbox} (a reminder, a finished job — played when it lands) |
29
+ * | what was said | {@link useConversation}, {@link useUserTranscript}, {@link useConversationLog} (across sessions, persisted) |
30
+ * | the talk button | {@link useTapToTalk} (tap on, tap off), {@link usePushToTalk} (hold, for `turnTaking: { detection: "manual" }`) |
31
+ * | the agent's own `/api` routes | {@link useRoute}, {@link useRouteMutation}, {@link routeFetch}, {@link useClientRuns} (a `clientRunsRoutes()` pair) |
32
+ * | what this browser remembers | {@link useStoredValue} / {@link createStoredValue}, {@link phoneE164} |
33
+ * | what the agent projects | {@link useAgentState} — pass the `slot.projected` the agent declared in `syncState`, and it selects that slot, types it AND supplies the frame rendered before the first push; {@link selectAgentState} is the same slot as a `useSessionSelector` selector |
34
+ * | tools, as they run | {@link useToolCallStart}, {@link useToolResult}, {@link useEvent} |
35
+ * | a durable run | {@link useWorkflowSubmit} (start one), {@link useWorkflowRun} (watch one), {@link useWorkflowRuns} / {@link useWorkflows} (list), {@link useWorkflowProgress} / {@link useWorkflowStream} (its output as it arrives) |
36
+ * | page chrome | {@link useTheme}, {@link useCopy}, {@link useFlash}, {@link useDownloadUrl}, {@link useRunKey} |
37
+ *
38
+ * Everything else here is a COMPONENT — chat chrome ({@link MessageList},
39
+ * {@link ChatView}, {@link Controls}, {@link StartScreen}), workflow forms
40
+ * ({@link Form}, {@link WorkflowFields}, the `*Field` set), and the small
41
+ * primitives pages kept re-writing ({@link AutoScroll}, {@link Markdown},
42
+ * {@link Facts}, {@link ToolCallRow}). None is required: the hooks are the API
43
+ * and the components are one rendering of it.
44
+ *
45
+ * ## Two things worth knowing before the reference below
46
+ *
47
+ * **Several names are re-exported from `@alexkroman1/aai`** —
48
+ * {@link WorkflowInputOf}, {@link WorkflowOutputOf}, {@link WorkflowSummary} and
49
+ * {@link AgentClient}, plus {@link isTerminal} and {@link ClientConfigResponse}.
50
+ * They are one declaration with two reference pages, not two types; a page takes
51
+ * them from here, an `agent.ts` from there.
52
+ *
53
+ * **{@link createWorkflowApi} is the browser's client, and there is one other.**
54
+ * `createAgentClient` (`@alexkroman1/aai/workflow-api`) is the same
55
+ * {@link AgentClient} for a caller with no page to default its base URL from — a
56
+ * script, a cron job, a server. Reach for the one here whenever the code runs in
57
+ * a page the agent serves; it delegates to that factory, so there is one
58
+ * implementation of the routes and one `config()`. (It used to answer the
59
+ * narrower `WorkflowApi`, which made a page wanting the agent's own name build a
60
+ * second client for one read.)
61
+ *
62
+ * @module
14
63
  */
15
- export { App } from "./_components/app.tsx";
16
- export type { ButtonSize, ButtonVariant } from "./_components/button.tsx";
17
- export { Button } from "./_components/button.tsx";
18
- export { ChatView } from "./_components/chat-view.tsx";
19
- export { Controls } from "./_components/controls.tsx";
20
- export { ErrorBanner } from "./_components/error-banner.tsx";
21
- export { MessageBubble } from "./_components/message-bubble.tsx";
22
- export { MessageList } from "./_components/message-list.tsx";
23
- export { SidebarLayout } from "./_components/sidebar-layout.tsx";
24
- export { StartScreen } from "./_components/start-screen.tsx";
25
- export { StateIndicator } from "./_components/state-indicator.tsx";
26
- export { ThinkingIndicator } from "./_components/thinking-indicator.tsx";
27
- export { ToolCallBlock } from "./_components/tool-call-block.tsx";
28
- export { Transcript } from "./_components/transcript.tsx";
29
- export type { ClientConfig, ClientTheme } from "./client-context.ts";
30
- export { useClientConfig } from "./client-context.ts";
31
- export type { ClientHandle, ClientOptions } from "./define-client.tsx";
32
- export { defineClient } from "./define-client.tsx";
33
- export type { VoiceSession } from "./session.ts";
34
- export { createVoiceSession } from "./session.ts";
35
- export type { SessionSignals } from "./signals.ts";
36
- export { createSessionControls, SessionProvider, useAutoScroll, useSession, useToolCallStart, useToolResult, } from "./signals.ts";
37
- export type { AgentState, ChatMessage, Reactive, SessionError, SessionErrorCode, ToolCallInfo, VoiceSessionOptions, } from "./types.ts";
64
+ export { type ClientRun, type ClientRunStatus, type ClientRunsResponse, errorMessage, } from "@alexkroman1/aai";
65
+ export { AGENT_STATE_LABELS } from "./agent-state-labels.ts";
66
+ export { type ClientConfigResponse, fetchClientConfig, } from "./client-config.ts";
67
+ export { browserClientId, type SessionIdentity } from "./client-identity.ts";
68
+ export { useClientTool } from "./client-tool.ts";
69
+ export { AudioResult, type AudioResultCaptions, type AudioResultProps, } from "./components/audio-result.tsx";
70
+ export { AutoScroll } from "./components/auto-scroll.tsx";
71
+ export { BulletList, type BulletListProps } from "./components/bullet-list.tsx";
72
+ export { Button, type ButtonSize, type ButtonVariant } from "./components/button.tsx";
73
+ export { ChatView } from "./components/chat-view.tsx";
74
+ export { ConsoleShell, type ConsoleShellProps } from "./components/console-shell.tsx";
75
+ export { Controls, type ControlsProps } from "./components/controls.tsx";
76
+ export { ConversationView, type ConversationViewProps, } from "./components/conversation-view.tsx";
77
+ export { Facts, type FactsProps } from "./components/facts.tsx";
78
+ export { CheckboxField, Field, type FieldShell, FileField, type FileReadMode, type FileValue, Form, type FormProps, type FormValues, NumberField, SelectField, SubmitButton, TextAreaField, TextField, } from "./components/form.tsx";
79
+ export { Markdown, type MarkdownProps, type MarkdownVariant } from "./components/markdown.tsx";
80
+ export { MessageList, type MessageListProps } from "./components/message-list.tsx";
81
+ export { type SessionControlAction, type SessionControlButton, SessionControls, type SessionControlsLabels, type SessionControlsProps, } from "./components/session-controls.tsx";
82
+ export { SessionErrorBanner, type SessionErrorBannerProps, } from "./components/session-error-banner.tsx";
83
+ export { SessionStateDot, type SessionStateDotProps, } from "./components/session-state-dot.tsx";
84
+ export { SidebarLayout } from "./components/sidebar-layout.tsx";
85
+ export { StartScreen } from "./components/start-screen.tsx";
86
+ export { ToolCallRow, type ToolCallRowProps, type ToolCallRowVariant, } from "./components/tool-call-row.tsx";
87
+ export type { ToolDisplayConfig } from "./components/tool-config-context.ts";
88
+ export { UploadProgressBar } from "./components/upload-progress.tsx";
89
+ export { WorkflowFields } from "./components/workflow-fields.tsx";
90
+ export { WorkflowPendingNote, type WorkflowPendingNoteProps, } from "./components/workflow-pending-note.tsx";
91
+ export { WorkflowProgress } from "./components/workflow-progress.tsx";
92
+ export { WorkflowRunError, type WorkflowRunErrorProps, } from "./components/workflow-run-error.tsx";
93
+ export { WorkflowRunPanel, type WorkflowRunPanelProps, } from "./components/workflow-run-panel.tsx";
94
+ export type { Session, SessionActions } from "./context.ts";
95
+ export { useSession, useSessionActions, useSessionError, useSessionSelector, useSessionStatus, useTheme, } from "./context.ts";
96
+ export { type ConversationLogEntry, inboxEventToItem } from "./conversation-log.ts";
97
+ export type { ClientConfig, ClientHandle } from "./define-client.tsx";
98
+ export { mountClient } from "./define-client.tsx";
99
+ export { selectAgentState, useAgentState, useEvent, useToolCallStart, useToolResult, } from "./hooks.ts";
100
+ export { type CreateInboxOptions, createInbox, type Inbox } from "./inbox.ts";
101
+ export type { InboxEvent, InboxNotice } from "./inbox-protocol.ts";
102
+ export { createLinkedClient, type LinkedClient, type LinkedClientOptions, } from "./linked-client.ts";
103
+ export { mountPage, type PageConfig, type PageHandle } from "./page.tsx";
104
+ export { type PhoneE164Options, phoneE164 } from "./phone.ts";
105
+ export { type RouteFetchOptions, type RouteMethod, routeFetch } from "./route-fetch.ts";
106
+ export type { AgentCustomEvent, AgentStateFrame, BrowserSession, browserSessionBrand, SendTextOptions, SessionSnapshot, ToolCallOutcome, UserTurnControls, } from "./session/index.ts";
107
+ export { createBrowserSession } from "./session/index.ts";
108
+ export { createStoredValue, type StoredValue, type StoredValueOptions, useStoredValue, } from "./stored-value.ts";
109
+ export type { AgentState, ChatMessage, ClientTheme, SessionError, SessionErrorCode, ToolCallInfo, VoiceSessionOptions, WebSocketConstructor, } from "./types.ts";
110
+ export { type UseClientRunsOptions, type UseClientRunsResult, useClientRuns, } from "./use-client-runs.ts";
111
+ export { type ConversationItem, type UseConversationResult, useConversation, } from "./use-conversation.ts";
112
+ export { type UseConversationLogOptions, type UseConversationLogResult, useConversationLog, } from "./use-conversation-log.ts";
113
+ export { type UseCopyResult, useCopy } from "./use-copy.ts";
114
+ export { type UseDownloadUrlOptions, type UseDownloadUrlResult, useDownloadUrl, } from "./use-download-url.ts";
115
+ export { type UseFlashResult, useFlash } from "./use-flash.ts";
116
+ export { type UseInboxOptions, type UseInboxResult, useInbox } from "./use-inbox.ts";
117
+ export { type UsePushToTalkOptions, type UsePushToTalkResult, usePushToTalk, } from "./use-push-to-talk.ts";
118
+ export { type UseRouteOptions, type UseRouteResult, useRoute } from "./use-route.ts";
119
+ export { type RouteMutationRunOptions, type UseRouteMutationOptions, type UseRouteMutationResult, useRouteMutation, } from "./use-route-mutation.ts";
120
+ export { useRunKey } from "./use-run-key.ts";
121
+ export { type UseSessionControlsResult, useSessionControls } from "./use-session-controls.ts";
122
+ export { useClientId, useSessionId } from "./use-session-id.ts";
123
+ export { type UseTapToTalkOptions, type UseTapToTalkResult, useTapToTalk, } from "./use-tap-to-talk.ts";
124
+ export { type UseUserTranscriptResult, useUserTranscript } from "./use-user-transcript.ts";
125
+ export { type UploadStatus, type UseWorkflowSubmitOptions, useWorkflowSubmit, type WorkflowSubmission, } from "./use-workflow-form.ts";
126
+ export { type UseWorkflowProgressResult, useWorkflowProgress, } from "./use-workflow-progress.ts";
127
+ export { type UseWorkflowRunResult, useWorkflowRun } from "./use-workflow-run.ts";
128
+ export { type UseWorkflowRunsOptions, type UseWorkflowRunsResult, useWorkflowRuns, } from "./use-workflow-runs.ts";
129
+ export { type UseWorkflowStreamOptions, useWorkflowStream, type WorkflowStreamSubmission, } from "./use-workflow-stream.ts";
130
+ export { type UseWorkflowsOptions, type UseWorkflowsResult, useWorkflows, } from "./use-workflows.ts";
131
+ export { type AgentClient, createWorkflowApi, isTerminal, type WorkflowApi, type WorkflowApiOptions, type WorkflowInputOf, type WorkflowOutputOf, type WorkflowRun, type WorkflowRunStatus, type WorkflowSummary, } from "./workflow-client.ts";
132
+ export type { SubmitInputOf } from "./workflow-def-types.ts";
133
+ export { fieldKindFor, type WorkflowFieldKind } from "./workflow-field-kind.ts";
134
+ export { WORKFLOW_STATUS_LABELS } from "./workflow-status-labels.ts";