@alexkroman1/aai-ui 0.12.2 → 1.0.2
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/_react-test-utils.d.ts +86 -0
- package/dist/audio.js +4 -5
- package/dist/build-default-client.d.ts +1 -0
- package/dist/{_components → components}/button.d.ts +4 -4
- package/dist/{_components → components}/button.js +28 -5
- package/dist/components/chat-view.d.ts +38 -0
- package/dist/components/chat-view.js +102 -0
- package/dist/{_components → components}/controls.d.ts +1 -1
- package/dist/{_components → components}/controls.js +8 -5
- package/dist/{_components → components}/message-list.d.ts +2 -2
- package/dist/components/message-list.js +149 -0
- package/dist/components/sidebar-layout.d.ts +21 -0
- package/dist/components/sidebar-layout.js +43 -0
- package/dist/{_components → components}/start-screen.d.ts +4 -4
- package/dist/{_components → components}/start-screen.js +17 -8
- package/dist/{_components → components}/tool-call-block.d.ts +5 -6
- package/dist/components/tool-call-block.js +3 -0
- package/dist/components/tool-config-context.d.ts +22 -0
- package/dist/context.d.ts +23 -0
- package/dist/context.js +39 -0
- package/dist/default-client/assets/audio-DH9LpexG.js +1 -0
- package/dist/default-client/assets/capture-processor-C26lSiVr.js +53 -0
- package/dist/default-client/assets/default-client-AeJhjHfj.js +49 -0
- package/dist/default-client/assets/default-client-BK1ItCvw.css +2 -0
- package/dist/default-client/assets/playback-processor-dSA8Im99.js +101 -0
- package/dist/default-client/default-client.html +15 -0
- package/dist/default-client.d.ts +2 -0
- package/dist/define-client.d.ts +72 -24
- package/dist/define-client.js +71 -45
- package/dist/hooks.d.ts +5 -0
- package/dist/hooks.js +55 -0
- package/dist/index.d.ts +15 -37
- package/dist/index.js +11 -18
- package/dist/session-core.d.ts +70 -0
- package/dist/session-core.js +437 -0
- package/dist/tool-call-block-CCuChsFm.js +131 -0
- package/dist/types.d.ts +19 -22
- package/package.json +24 -18
- package/styles.css +3 -33
- package/dist/_components/app.d.ts +0 -23
- package/dist/_components/app.js +0 -41
- package/dist/_components/chat-view.d.ts +0 -29
- package/dist/_components/chat-view.js +0 -61
- package/dist/_components/error-banner.d.ts +0 -21
- package/dist/_components/error-banner.js +0 -27
- package/dist/_components/message-bubble.d.ts +0 -23
- package/dist/_components/message-bubble.js +0 -35
- package/dist/_components/message-list.js +0 -76
- package/dist/_components/sidebar-layout.d.ts +0 -21
- package/dist/_components/sidebar-layout.js +0 -36
- package/dist/_components/state-indicator.d.ts +0 -29
- package/dist/_components/state-indicator.js +0 -37
- package/dist/_components/thinking-indicator.d.ts +0 -16
- package/dist/_components/thinking-indicator.js +0 -34
- package/dist/_components/tool-call-block.js +0 -118
- package/dist/_components/tool-icons.d.ts +0 -17
- package/dist/_components/tool-icons.js +0 -128
- package/dist/_components/transcript.d.ts +0 -25
- package/dist/_components/transcript.js +0 -35
- package/dist/client-context.d.ts +0 -33
- package/dist/client-context.js +0 -15
- package/dist/client-handler.d.ts +0 -43
- package/dist/session-CWB7vmqz.js +0 -429
- package/dist/session.d.ts +0 -69
- package/dist/session.js +0 -2
- package/dist/signals.d.ts +0 -120
- package/dist/signals.js +0 -161
- package/dist/types.test-d.d.ts +0 -7
package/dist/signals.js
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { createContext, h } from "preact";
|
|
2
|
-
import { useContext, useEffect, useRef } from "preact/hooks";
|
|
3
|
-
import { batch, effect, signal, useSignalEffect } from "@preact/signals";
|
|
4
|
-
//#region signals.ts
|
|
5
|
-
/**
|
|
6
|
-
* Wrap a {@link VoiceSession} in Preact signals for reactive UI binding.
|
|
7
|
-
*
|
|
8
|
-
* Creates higher-level controls (start, toggle, reset) on top of the raw
|
|
9
|
-
* session, and automatically sets `running` to `false` when the session
|
|
10
|
-
* enters an error state.
|
|
11
|
-
*
|
|
12
|
-
* @param session - The voice session to wrap.
|
|
13
|
-
* @returns A {@link SessionSignals} object for use in Preact components.
|
|
14
|
-
*
|
|
15
|
-
* @public
|
|
16
|
-
*/
|
|
17
|
-
function createSessionControls(session) {
|
|
18
|
-
const started = signal(false);
|
|
19
|
-
const running = signal(true);
|
|
20
|
-
const dispose = effect(() => {
|
|
21
|
-
if (session.state.value === "error") running.value = false;
|
|
22
|
-
});
|
|
23
|
-
return {
|
|
24
|
-
session,
|
|
25
|
-
started,
|
|
26
|
-
running,
|
|
27
|
-
dispose,
|
|
28
|
-
start() {
|
|
29
|
-
batch(() => {
|
|
30
|
-
started.value = true;
|
|
31
|
-
running.value = true;
|
|
32
|
-
});
|
|
33
|
-
session.connect();
|
|
34
|
-
},
|
|
35
|
-
toggle() {
|
|
36
|
-
if (running.value) {
|
|
37
|
-
session.cancel();
|
|
38
|
-
session.disconnect();
|
|
39
|
-
} else session.connect();
|
|
40
|
-
running.value = !running.value;
|
|
41
|
-
},
|
|
42
|
-
reset() {
|
|
43
|
-
session.reset();
|
|
44
|
-
},
|
|
45
|
-
[Symbol.dispose]() {
|
|
46
|
-
dispose();
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
const Ctx = createContext(null);
|
|
51
|
-
/**
|
|
52
|
-
* Preact context provider that makes session signals available to descendant
|
|
53
|
-
* components via {@link useSession}.
|
|
54
|
-
*
|
|
55
|
-
* @param props - Provider props. `value` is the session signals to provide. `children` are child components that may consume the context.
|
|
56
|
-
* @returns A Preact VNode wrapping children in the session context.
|
|
57
|
-
*
|
|
58
|
-
* @public
|
|
59
|
-
*/
|
|
60
|
-
function SessionProvider({ value, children }) {
|
|
61
|
-
return h(Ctx.Provider, { value }, children);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Hook to access session signals from within a {@link SessionProvider}.
|
|
65
|
-
*
|
|
66
|
-
* @returns The {@link SessionSignals} from the nearest provider.
|
|
67
|
-
* @throws If called outside of a `SessionProvider`.
|
|
68
|
-
*
|
|
69
|
-
* @public
|
|
70
|
-
*/
|
|
71
|
-
function useSession() {
|
|
72
|
-
const ctx = useContext(Ctx);
|
|
73
|
-
if (!ctx) throw new Error("Hook useSession() requires a SessionProvider");
|
|
74
|
-
return ctx;
|
|
75
|
-
}
|
|
76
|
-
function tryParseJSON(str) {
|
|
77
|
-
try {
|
|
78
|
-
return JSON.parse(str);
|
|
79
|
-
} catch {
|
|
80
|
-
return str;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function isNewCompletedCall(tc, seen, filterName) {
|
|
84
|
-
if (tc.status !== "done" || !tc.result) return false;
|
|
85
|
-
if (seen.has(tc.toolCallId)) return false;
|
|
86
|
-
if (filterName && tc.toolName !== filterName) return false;
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Shared helper for hooks that need to fire a callback once per new tool call.
|
|
91
|
-
*
|
|
92
|
-
* Handles deduplication via a `Set<string>` ref, automatic reset when the
|
|
93
|
-
* signal array is cleared, and a stable callback ref to avoid stale closures.
|
|
94
|
-
*
|
|
95
|
-
* @param session - The voice session whose `toolCalls` signal to watch.
|
|
96
|
-
* @param shouldProcess - Predicate that decides whether a tool call is eligible.
|
|
97
|
-
* Called with the tool call and the seen-IDs set. Must NOT mutate the set.
|
|
98
|
-
* @param onNew - Invoked for each eligible tool call that hasn't been seen yet.
|
|
99
|
-
*/
|
|
100
|
-
function useToolCallEffect(session, shouldProcess, onNew) {
|
|
101
|
-
const seenRef = useRef(/* @__PURE__ */ new Set());
|
|
102
|
-
const cbRef = useRef(onNew);
|
|
103
|
-
cbRef.current = onNew;
|
|
104
|
-
const predicateRef = useRef(shouldProcess);
|
|
105
|
-
predicateRef.current = shouldProcess;
|
|
106
|
-
useEffect(() => effect(() => {
|
|
107
|
-
const toolCalls = session.toolCalls.value;
|
|
108
|
-
if (toolCalls.length === 0) {
|
|
109
|
-
seenRef.current.clear();
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
for (const tc of toolCalls) {
|
|
113
|
-
if (!predicateRef.current(tc, seenRef.current)) continue;
|
|
114
|
-
if (seenRef.current.has(tc.toolCallId)) continue;
|
|
115
|
-
seenRef.current.add(tc.toolCallId);
|
|
116
|
-
cbRef.current(tc);
|
|
117
|
-
}
|
|
118
|
-
}), [session]);
|
|
119
|
-
}
|
|
120
|
-
function useToolResult(toolNameOrCallback, maybeCallback) {
|
|
121
|
-
const filterName = typeof toolNameOrCallback === "string" ? toolNameOrCallback : void 0;
|
|
122
|
-
const callback = typeof toolNameOrCallback === "function" ? toolNameOrCallback : (_name, result, tc) => maybeCallback?.(result, tc);
|
|
123
|
-
const { session } = useSession();
|
|
124
|
-
useToolCallEffect(session, (tc, seen) => isNewCompletedCall(tc, seen, filterName), (tc) => callback(tc.toolName, tryParseJSON(tc.result), tc));
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Hook that fires a callback when a new tool call starts (status: "pending").
|
|
128
|
-
*
|
|
129
|
-
* Use this to show a loading/skeleton UI immediately when the agent invokes
|
|
130
|
-
* a tool, rather than waiting for the full result. The callback receives the
|
|
131
|
-
* tool name, parsed arguments, and the full {@link ToolCallInfo}.
|
|
132
|
-
*
|
|
133
|
-
* @param callback - Called once per new tool call at start time.
|
|
134
|
-
*
|
|
135
|
-
* @public
|
|
136
|
-
*/
|
|
137
|
-
function useToolCallStart(callback) {
|
|
138
|
-
const { session } = useSession();
|
|
139
|
-
useToolCallEffect(session, () => true, (tc) => callback(tc.toolName, tc.args, tc));
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Auto-scroll a container to the bottom when messages, tool calls,
|
|
143
|
-
* or utterances change. Returns a ref to attach to a sentinel `<div>`
|
|
144
|
-
* at the bottom of the scrollable area.
|
|
145
|
-
*
|
|
146
|
-
* @public
|
|
147
|
-
*/
|
|
148
|
-
function useAutoScroll() {
|
|
149
|
-
const { session } = useSession();
|
|
150
|
-
const ref = useRef(null);
|
|
151
|
-
useSignalEffect(() => {
|
|
152
|
-
session.messages.value;
|
|
153
|
-
session.toolCalls.value;
|
|
154
|
-
session.userUtterance.value;
|
|
155
|
-
session.agentUtterance.value;
|
|
156
|
-
ref.current?.scrollIntoView({ behavior: "smooth" });
|
|
157
|
-
});
|
|
158
|
-
return ref;
|
|
159
|
-
}
|
|
160
|
-
//#endregion
|
|
161
|
-
export { SessionProvider, createSessionControls, useAutoScroll, useSession, useToolCallStart, useToolResult };
|
package/dist/types.test-d.d.ts
DELETED