@alexkroman1/aai-ui 1.0.6 → 1.2.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.
- package/dist/aai-logo-BqFv6JU6.js +21 -0
- package/dist/components/aai-logo.d.ts +11 -0
- package/dist/components/chat-view.js +2 -5
- package/dist/components/message-list.js +1 -1
- package/dist/components/start-screen.js +2 -1
- package/dist/components/tool-call-block.js +1 -1
- package/dist/default-client/assets/{default-client-BK1ItCvw.css → index-BZqVGR2o.css} +1 -1
- package/dist/default-client/assets/index-D6dL8nYr.js +49 -0
- package/dist/default-client/{default-client.html → index.html} +2 -2
- package/dist/define-client.js +1 -1
- package/dist/hooks.d.ts +1 -0
- package/dist/hooks.js +19 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/session-core.d.ts +11 -0
- package/dist/session-core.js +12 -0
- package/package.json +2 -2
- package/dist/default-client/assets/default-client-AeJhjHfj.js +0 -49
- /package/dist/{tool-call-block-CCuChsFm.js → tool-call-block-wby_jyoY.js} +0 -0
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
<title>aai</title>
|
|
7
7
|
<link rel="icon" href="data:," />
|
|
8
8
|
<style>html, body { background: #101010; margin: 0; }</style>
|
|
9
|
-
<script type="module" crossorigin src="./assets/
|
|
10
|
-
<link rel="stylesheet" crossorigin href="./assets/
|
|
9
|
+
<script type="module" crossorigin src="./assets/index-D6dL8nYr.js"></script>
|
|
10
|
+
<link rel="stylesheet" crossorigin href="./assets/index-BZqVGR2o.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
|
13
13
|
<main id="app"></main>
|
package/dist/define-client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SessionProvider, ThemeProvider } from "./context.js";
|
|
2
|
-
import { n as ToolConfigContext } from "./tool-call-block-
|
|
2
|
+
import { n as ToolConfigContext } from "./tool-call-block-wby_jyoY.js";
|
|
3
3
|
import { ChatView } from "./components/chat-view.js";
|
|
4
4
|
import { SidebarLayout } from "./components/sidebar-layout.js";
|
|
5
5
|
import { StartScreen } from "./components/start-screen.js";
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ToolCallInfo } from "./types.ts";
|
|
2
2
|
export declare function useToolResult<R = unknown>(toolName: string, callback: (result: R, toolCall: ToolCallInfo) => void): void;
|
|
3
3
|
export declare function useToolResult(callback: (name: string, result: unknown, toolCall: ToolCallInfo) => void): void;
|
|
4
|
+
export declare function useEvent<T = unknown>(event: string, callback: (data: T) => void): void;
|
|
4
5
|
export declare function useToolCallStart(toolName: string, callback: (toolCall: ToolCallInfo) => void): void;
|
|
5
6
|
export declare function useToolCallStart(callback: (toolCall: ToolCallInfo) => void): void;
|
package/dist/hooks.js
CHANGED
|
@@ -40,6 +40,24 @@ function useToolResult(...args) {
|
|
|
40
40
|
});
|
|
41
41
|
}, [session.toolCalls, filterName]);
|
|
42
42
|
}
|
|
43
|
+
function useEvent(event, callback) {
|
|
44
|
+
const session = useSession();
|
|
45
|
+
const seenRef = useRef(/* @__PURE__ */ new Set());
|
|
46
|
+
const callbackRef = useRef(callback);
|
|
47
|
+
callbackRef.current = callback;
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (session.customEvents.length === 0) {
|
|
50
|
+
seenRef.current.clear();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
for (const ce of session.customEvents) {
|
|
54
|
+
if (ce.event !== event) continue;
|
|
55
|
+
if (seenRef.current.has(ce.id)) continue;
|
|
56
|
+
seenRef.current.add(ce.id);
|
|
57
|
+
callbackRef.current(ce.data);
|
|
58
|
+
}
|
|
59
|
+
}, [session.customEvents, event]);
|
|
60
|
+
}
|
|
43
61
|
function useToolCallStart(...args) {
|
|
44
62
|
const filterName = typeof args[0] === "string" ? args[0] : null;
|
|
45
63
|
const callback = typeof args[0] === "string" ? args[1] : args[0];
|
|
@@ -52,4 +70,4 @@ function useToolCallStart(...args) {
|
|
|
52
70
|
}, [session.toolCalls, filterName]);
|
|
53
71
|
}
|
|
54
72
|
//#endregion
|
|
55
|
-
export { useToolCallStart, useToolResult };
|
|
73
|
+
export { useEvent, useToolCallStart, useToolResult };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type { Session } from "./context.ts";
|
|
|
9
9
|
export { SessionProvider, ThemeProvider, useSession, useTheme } from "./context.ts";
|
|
10
10
|
export type { ClientConfig, ClientHandle, } from "./define-client.tsx";
|
|
11
11
|
export { client } from "./define-client.tsx";
|
|
12
|
-
export { useToolCallStart, useToolResult } from "./hooks.ts";
|
|
13
|
-
export type { SessionCore, SessionCoreOptions, SessionSnapshot, } from "./session-core.ts";
|
|
12
|
+
export { useEvent, useToolCallStart, useToolResult } from "./hooks.ts";
|
|
13
|
+
export type { CustomEvent, SessionCore, SessionCoreOptions, SessionSnapshot, } from "./session-core.ts";
|
|
14
14
|
export { createSessionCore } from "./session-core.ts";
|
|
15
15
|
export type { AgentState, ChatMessage, ClientTheme, SessionError, SessionErrorCode, ToolCallInfo, VoiceSessionOptions, WebSocketConstructor, } from "./types.ts";
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { SessionProvider, ThemeProvider, useSession, useTheme } from "./context.js";
|
|
2
2
|
import { Button } from "./components/button.js";
|
|
3
|
-
import { n as ToolConfigContext } from "./tool-call-block-
|
|
3
|
+
import { n as ToolConfigContext } from "./tool-call-block-wby_jyoY.js";
|
|
4
4
|
import { MessageList } from "./components/message-list.js";
|
|
5
5
|
import { ChatView } from "./components/chat-view.js";
|
|
6
6
|
import { SidebarLayout } from "./components/sidebar-layout.js";
|
|
7
7
|
import { StartScreen } from "./components/start-screen.js";
|
|
8
8
|
import { createSessionCore } from "./session-core.js";
|
|
9
9
|
import { client } from "./define-client.js";
|
|
10
|
-
import { useToolCallStart, useToolResult } from "./hooks.js";
|
|
11
|
-
export { Button, ChatView, MessageList, SessionProvider, SidebarLayout, StartScreen, ThemeProvider, ToolConfigContext, client, createSessionCore, useSession, useTheme, useToolCallStart, useToolResult };
|
|
10
|
+
import { useEvent, useToolCallStart, useToolResult } from "./hooks.js";
|
|
11
|
+
export { Button, ChatView, MessageList, SessionProvider, SidebarLayout, StartScreen, ThemeProvider, ToolConfigContext, client, createSessionCore, useEvent, useSession, useTheme, useToolCallStart, useToolResult };
|
package/dist/session-core.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import type { AgentState, ChatMessage, SessionError, ToolCallInfo, VoiceSessionOptions } from "./types.ts";
|
|
2
2
|
export type { AgentState, ChatMessage, SessionError, SessionErrorCode, ToolCallInfo, VoiceSessionOptions, WebSocketConstructor, } from "./types.ts";
|
|
3
|
+
/**
|
|
4
|
+
* A custom event emitted by the agent via `ctx.send`.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export type CustomEvent = {
|
|
9
|
+
readonly id: number;
|
|
10
|
+
readonly event: string;
|
|
11
|
+
readonly data: unknown;
|
|
12
|
+
};
|
|
3
13
|
/**
|
|
4
14
|
* Immutable snapshot of the session state.
|
|
5
15
|
*
|
|
@@ -12,6 +22,7 @@ export type SessionSnapshot = {
|
|
|
12
22
|
readonly state: AgentState;
|
|
13
23
|
readonly messages: ChatMessage[];
|
|
14
24
|
readonly toolCalls: ToolCallInfo[];
|
|
25
|
+
readonly customEvents: CustomEvent[];
|
|
15
26
|
readonly userTranscript: string | null;
|
|
16
27
|
readonly agentTranscript: string | null;
|
|
17
28
|
readonly error: SessionError | null;
|
package/dist/session-core.js
CHANGED
|
@@ -93,6 +93,7 @@ function createSessionCore(options) {
|
|
|
93
93
|
state: "disconnected",
|
|
94
94
|
messages: [],
|
|
95
95
|
toolCalls: [],
|
|
96
|
+
customEvents: [],
|
|
96
97
|
userTranscript: null,
|
|
97
98
|
agentTranscript: null,
|
|
98
99
|
error: null,
|
|
@@ -136,6 +137,7 @@ function createSessionCore(options) {
|
|
|
136
137
|
updateState({
|
|
137
138
|
messages: [],
|
|
138
139
|
toolCalls: [],
|
|
140
|
+
customEvents: [],
|
|
139
141
|
userTranscript: null,
|
|
140
142
|
agentTranscript: null,
|
|
141
143
|
error: null
|
|
@@ -154,6 +156,8 @@ function createSessionCore(options) {
|
|
|
154
156
|
};
|
|
155
157
|
/** Incremented on each turn boundary -- stale async callbacks compare against this. */
|
|
156
158
|
let handlerGeneration = 0;
|
|
159
|
+
/** Monotonically increasing counter for custom events -- used by useEvent to deduplicate. */
|
|
160
|
+
let customEventSeq = 0;
|
|
157
161
|
function handleUserTranscriptEvent(text) {
|
|
158
162
|
handlerGeneration++;
|
|
159
163
|
updateState({
|
|
@@ -233,12 +237,20 @@ function createSessionCore(options) {
|
|
|
233
237
|
updateState({
|
|
234
238
|
messages: [],
|
|
235
239
|
toolCalls: [],
|
|
240
|
+
customEvents: [],
|
|
236
241
|
userTranscript: null,
|
|
237
242
|
agentTranscript: null,
|
|
238
243
|
error: null,
|
|
239
244
|
state: "listening"
|
|
240
245
|
});
|
|
241
246
|
break;
|
|
247
|
+
case "custom_event":
|
|
248
|
+
updateState({ customEvents: [...currentSnapshot.customEvents, {
|
|
249
|
+
id: ++customEventSeq,
|
|
250
|
+
event: e.event,
|
|
251
|
+
data: e.data
|
|
252
|
+
}] });
|
|
253
|
+
break;
|
|
242
254
|
case "error":
|
|
243
255
|
console.error("Agent error:", e.message);
|
|
244
256
|
updateState({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexkroman1/aai-ui",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"clsx": "^2.1.1",
|
|
21
|
-
"@alexkroman1/aai": "1.0
|
|
21
|
+
"@alexkroman1/aai": "1.2.0"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"react": "^19.0.0",
|