@alexkroman1/aai-ui 4.0.0 → 5.0.1
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/dist/client-config.d.ts +22 -4
- package/dist/default-client/assets/{audio-DQseUQnN.js → audio-BdEKgLwT.js} +1 -1
- package/dist/default-client/assets/{capture-processor-DKFNcEhw.js → capture-processor-_QJe3nzY.js} +1 -1
- package/dist/default-client/assets/index-RQnhfgSS.js +192 -0
- package/dist/default-client/assets/{playback-processor-HeyncQUX.js → playback-processor-C_F19eUJ.js} +1 -1
- package/dist/default-client/index.html +1 -1
- package/dist/define-client.d.ts +12 -1
- package/dist/define-client.js +120 -4
- package/dist/hooks.d.ts +40 -2
- package/dist/hooks.js +24 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/{session-core-CkZ8LyEA.js → session-core-ByBLnLfW.js} +126 -35
- package/dist/session-core-messages.d.ts +2 -1
- package/dist/session-core-reconnect.d.ts +4 -3
- package/dist/session-core-types.d.ts +11 -3
- package/dist/session-core-url.d.ts +5 -0
- package/dist/session-core.js +1 -1
- package/dist/types.d.ts +17 -1
- package/package.json +2 -2
- package/dist/default-client/assets/index-CkZ6t_eJ.js +0 -417
- package/dist/define-client-DqRs1XPd.js +0 -150
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { SessionProvider, ThemeProvider } from "./context.js";
|
|
2
|
-
import { t as ChatView } from "./chat-view-CW-tZCMm.js";
|
|
3
|
-
import { n as ToolConfigContext } from "./tool-call-block-DIxpG8GM.js";
|
|
4
|
-
import { SidebarLayout } from "./components/sidebar-layout.js";
|
|
5
|
-
import { StartScreen } from "./components/start-screen.js";
|
|
6
|
-
import { t as createSessionCore } from "./session-core-CkZ8LyEA.js";
|
|
7
|
-
import { CLIENT_CONFIG_PATH, ClientConfigResponseSchema } from "@alexkroman1/aai/protocol";
|
|
8
|
-
import { createElement, useEffect, useState } from "react";
|
|
9
|
-
import { jsx } from "react/jsx-runtime";
|
|
10
|
-
import { flushSync } from "react-dom";
|
|
11
|
-
import { createRoot } from "react-dom/client";
|
|
12
|
-
//#region client-config.ts
|
|
13
|
-
/**
|
|
14
|
-
* Pre-connection client-config lookup.
|
|
15
|
-
*
|
|
16
|
-
* `GET client-config` (relative to the agent's base URL — see
|
|
17
|
-
* `sdk/client-config.ts` in `@alexkroman1/aai`) gives the default client the
|
|
18
|
-
* agent's display name and greeting before any connection exists. Every
|
|
19
|
-
* failure path — network error, 404 from an older server, malformed body —
|
|
20
|
-
* degrades to the empty default, so this lookup can never break an existing
|
|
21
|
-
* agent.
|
|
22
|
-
*/
|
|
23
|
-
/** Resolve a relative endpoint path against the agent's base URL. */
|
|
24
|
-
function buildAgentUrl(platformUrl, endpointPath) {
|
|
25
|
-
return new URL(endpointPath, platformUrl.endsWith("/") ? platformUrl : `${platformUrl}/`);
|
|
26
|
-
}
|
|
27
|
-
const AGENT_DEFAULT = {};
|
|
28
|
-
/** Fetch the agent's client config; any failure yields the agent default. */
|
|
29
|
-
async function fetchClientConfig(platformUrl, fetchFn) {
|
|
30
|
-
const doFetch = fetchFn ?? ((input, init) => globalThis.fetch(input, init));
|
|
31
|
-
try {
|
|
32
|
-
const resp = await doFetch(buildAgentUrl(platformUrl, CLIENT_CONFIG_PATH).href);
|
|
33
|
-
if (!resp.ok) return AGENT_DEFAULT;
|
|
34
|
-
const parsed = ClientConfigResponseSchema.safeParse(await resp.json());
|
|
35
|
-
return parsed.success ? parsed.data : AGENT_DEFAULT;
|
|
36
|
-
} catch {
|
|
37
|
-
return AGENT_DEFAULT;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region define-client.tsx
|
|
42
|
-
/** @jsxImportSource react */
|
|
43
|
-
function resolveContainer(target = "#app") {
|
|
44
|
-
if (typeof target !== "string") return target;
|
|
45
|
-
const el = document.querySelector(target);
|
|
46
|
-
if (!el) throw new Error(`Element not found: ${target}`);
|
|
47
|
-
return el;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Default shell rendered in config tier.
|
|
51
|
-
* Wraps StartScreen → (SidebarLayout →) ChatView.
|
|
52
|
-
*/
|
|
53
|
-
function DefaultShell({ name, Sidebar, sidebarWidth }) {
|
|
54
|
-
const chat = /* @__PURE__ */ jsx(ChatView, { title: name });
|
|
55
|
-
return /* @__PURE__ */ jsx(StartScreen, {
|
|
56
|
-
title: name,
|
|
57
|
-
children: Sidebar ? /* @__PURE__ */ jsx(SidebarLayout, {
|
|
58
|
-
sidebar: /* @__PURE__ */ jsx(Sidebar, {}),
|
|
59
|
-
sidebarWidth,
|
|
60
|
-
children: chat
|
|
61
|
-
}) : chat
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Config-tier root: fetches the server-declared display name via
|
|
66
|
-
* `GET client-config` and renders the chat shell. The shell renders
|
|
67
|
-
* immediately — optimistically — while the lookup is in flight; servers
|
|
68
|
-
* without the endpoint (every lookup failure resolves to the empty default)
|
|
69
|
-
* work exactly as before.
|
|
70
|
-
*/
|
|
71
|
-
function DefaultRoot({ platformUrl, name, Sidebar, sidebarWidth }) {
|
|
72
|
-
const [resolved, setResolved] = useState(null);
|
|
73
|
-
useEffect(() => {
|
|
74
|
-
let cancelled = false;
|
|
75
|
-
fetchClientConfig(platformUrl).then((cfg) => {
|
|
76
|
-
if (!cancelled) setResolved(cfg);
|
|
77
|
-
});
|
|
78
|
-
return () => {
|
|
79
|
-
cancelled = true;
|
|
80
|
-
};
|
|
81
|
-
}, [platformUrl]);
|
|
82
|
-
return /* @__PURE__ */ jsx(DefaultShell, {
|
|
83
|
-
name: name ?? resolved?.name,
|
|
84
|
-
Sidebar,
|
|
85
|
-
sidebarWidth
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Define and mount a client UI for a voice agent.
|
|
90
|
-
*
|
|
91
|
-
* **Tier 1 (config-only):** Pass options without `component` to get the
|
|
92
|
-
* default shell (StartScreen + ChatView, optional sidebar).
|
|
93
|
-
*
|
|
94
|
-
* **Tier 2 (custom component):** Pass `component` to render a fully custom
|
|
95
|
-
* root component inside the providers.
|
|
96
|
-
*
|
|
97
|
-
* @example Tier 1
|
|
98
|
-
* ```tsx
|
|
99
|
-
* client({
|
|
100
|
-
* name: "Pizza Ordering",
|
|
101
|
-
* theme: { bg: "#1a1a1a", primary: "#e55" },
|
|
102
|
-
* sidebar: OrderPanel,
|
|
103
|
-
* tools: { add_pizza: { icon: "🍕", label: "Adding pizza" } },
|
|
104
|
-
* });
|
|
105
|
-
* ```
|
|
106
|
-
*
|
|
107
|
-
* @example Tier 2
|
|
108
|
-
* ```tsx
|
|
109
|
-
* client({ component: MyCustomApp });
|
|
110
|
-
* ```
|
|
111
|
-
*
|
|
112
|
-
* @returns A {@link ClientHandle} for cleanup.
|
|
113
|
-
* @throws If the target element is not found in the DOM.
|
|
114
|
-
*
|
|
115
|
-
* @public
|
|
116
|
-
*/
|
|
117
|
-
function client(config) {
|
|
118
|
-
const container = resolveContainer(config.target);
|
|
119
|
-
const platformUrl = config.platformUrl ?? globalThis.location.origin + globalThis.location.pathname;
|
|
120
|
-
const session = createSessionCore({
|
|
121
|
-
platformUrl,
|
|
122
|
-
onSessionId: config.onSessionId,
|
|
123
|
-
resumeSessionId: config.resumeSessionId,
|
|
124
|
-
WebSocket: config.WebSocket
|
|
125
|
-
});
|
|
126
|
-
const rootNode = config.component ? createElement(config.component) : createElement(DefaultRoot, {
|
|
127
|
-
platformUrl,
|
|
128
|
-
name: config.name,
|
|
129
|
-
Sidebar: config.sidebar,
|
|
130
|
-
sidebarWidth: config.sidebarWidth
|
|
131
|
-
});
|
|
132
|
-
const toolConfig = config.tools ?? {};
|
|
133
|
-
const root = createRoot(container);
|
|
134
|
-
flushSync(() => {
|
|
135
|
-
root.render(createElement(ToolConfigContext.Provider, { value: toolConfig }, createElement(ThemeProvider, { value: config.theme }, createElement(SessionProvider, { value: session }, rootNode))));
|
|
136
|
-
});
|
|
137
|
-
const handle = {
|
|
138
|
-
session,
|
|
139
|
-
dispose() {
|
|
140
|
-
root.unmount();
|
|
141
|
-
session[Symbol.dispose]();
|
|
142
|
-
},
|
|
143
|
-
[Symbol.dispose]() {
|
|
144
|
-
handle.dispose();
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
return handle;
|
|
148
|
-
}
|
|
149
|
-
//#endregion
|
|
150
|
-
export { buildAgentUrl as n, fetchClientConfig as r, client as t };
|