@meshagent/meshagent-tailwind 0.43.3 → 0.44.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/CHANGELOG.md +11 -0
- package/dist/cjs/chat/agent-thread-message-status-store.d.ts +107 -0
- package/dist/cjs/chat/agent-thread-message-status-store.js +649 -0
- package/dist/cjs/chat/agent-thread.d.ts +76 -4
- package/dist/cjs/chat/agent-thread.js +1114 -54
- package/dist/cjs/chat/chat-bot-view.d.ts +7 -4
- package/dist/cjs/chat/chat-bot-view.js +33 -525
- package/dist/cjs/chat/chat-hooks.d.ts +6 -5
- package/dist/cjs/chat/chat-hooks.js +21 -466
- package/dist/cjs/chat/chat-typing-indicator.d.ts +15 -1
- package/dist/cjs/chat/chat-typing-indicator.js +35 -5
- package/dist/cjs/chat/file-attachment.d.ts +7 -3
- package/dist/cjs/chat/file-attachment.js +30 -6
- package/dist/cjs/chat/multi-thread-view.d.ts +3 -1
- package/dist/cjs/chat/multi-thread-view.js +4 -2
- package/dist/cjs/chat/new-chat-thread.d.ts +3 -1
- package/dist/cjs/chat/new-chat-thread.js +7 -3
- package/dist/cjs/chat/thread-list-view.d.ts +22 -0
- package/dist/cjs/chat/thread-list-view.js +518 -0
- package/dist/cjs/chat/tool-call-status-accumulator.d.ts +69 -0
- package/dist/cjs/chat/tool-call-status-accumulator.js +268 -0
- package/dist/cjs/components/pane-example.d.ts +1 -1
- package/dist/cjs/components/ui/avatar.d.ts +3 -3
- package/dist/cjs/components/ui/button.d.ts +3 -3
- package/dist/cjs/components/ui/card.d.ts +7 -7
- package/dist/cjs/components/ui/dialog.d.ts +10 -10
- package/dist/cjs/components/ui/form.d.ts +7 -7
- package/dist/cjs/components/ui/input.d.ts +1 -1
- package/dist/cjs/components/ui/label.d.ts +1 -1
- package/dist/cjs/components/ui/progress.d.ts +1 -1
- package/dist/cjs/components/ui/radio-group.d.ts +2 -2
- package/dist/cjs/components/ui/select.d.ts +10 -10
- package/dist/cjs/components/ui/sheet.d.ts +8 -8
- package/dist/cjs/components/ui/skeleton.d.ts +1 -1
- package/dist/cjs/components/ui/sonner.d.ts +1 -1
- package/dist/cjs/components/ui/spinner.d.ts +2 -2
- package/dist/cjs/components/ui/textarea.d.ts +1 -1
- package/dist/cjs/file-preview/file-preview.d.ts +1 -0
- package/dist/cjs/file-preview/file-preview.js +41 -5
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +13 -0
- package/dist/cjs/meetings/camera-grid.d.ts +2 -2
- package/dist/cjs/tools/ask-user-for-file.js +2 -2
- package/dist/cjs/tools/file-dialog.d.ts +2 -1
- package/dist/cjs/tools/form-dialog.d.ts +2 -1
- package/dist/esm/chat/agent-thread-message-status-store.d.ts +107 -0
- package/dist/esm/chat/agent-thread-message-status-store.js +647 -0
- package/dist/esm/chat/agent-thread.d.ts +76 -4
- package/dist/esm/chat/agent-thread.js +1132 -56
- package/dist/esm/chat/chat-bot-view.d.ts +7 -4
- package/dist/esm/chat/chat-bot-view.js +40 -555
- package/dist/esm/chat/chat-hooks.d.ts +6 -5
- package/dist/esm/chat/chat-hooks.js +23 -468
- package/dist/esm/chat/chat-typing-indicator.d.ts +15 -1
- package/dist/esm/chat/chat-typing-indicator.js +35 -5
- package/dist/esm/chat/file-attachment.d.ts +7 -3
- package/dist/esm/chat/file-attachment.js +30 -6
- package/dist/esm/chat/multi-thread-view.d.ts +3 -1
- package/dist/esm/chat/multi-thread-view.js +4 -2
- package/dist/esm/chat/new-chat-thread.d.ts +3 -1
- package/dist/esm/chat/new-chat-thread.js +8 -4
- package/dist/esm/chat/thread-list-view.d.ts +22 -0
- package/dist/esm/chat/thread-list-view.js +514 -0
- package/dist/esm/chat/tool-call-status-accumulator.d.ts +69 -0
- package/dist/esm/chat/tool-call-status-accumulator.js +248 -0
- package/dist/esm/components/pane-example.d.ts +1 -1
- package/dist/esm/components/ui/avatar.d.ts +3 -3
- package/dist/esm/components/ui/button.d.ts +3 -3
- package/dist/esm/components/ui/card.d.ts +7 -7
- package/dist/esm/components/ui/dialog.d.ts +10 -10
- package/dist/esm/components/ui/form.d.ts +7 -7
- package/dist/esm/components/ui/input.d.ts +1 -1
- package/dist/esm/components/ui/label.d.ts +1 -1
- package/dist/esm/components/ui/progress.d.ts +1 -1
- package/dist/esm/components/ui/radio-group.d.ts +2 -2
- package/dist/esm/components/ui/select.d.ts +10 -10
- package/dist/esm/components/ui/sheet.d.ts +8 -8
- package/dist/esm/components/ui/skeleton.d.ts +1 -1
- package/dist/esm/components/ui/sonner.d.ts +1 -1
- package/dist/esm/components/ui/spinner.d.ts +2 -2
- package/dist/esm/components/ui/textarea.d.ts +1 -1
- package/dist/esm/file-preview/file-preview.d.ts +1 -0
- package/dist/esm/file-preview/file-preview.js +29 -3
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/meetings/camera-grid.d.ts +2 -2
- package/dist/esm/tools/ask-user-for-file.js +2 -2
- package/dist/esm/tools/file-dialog.d.ts +2 -1
- package/dist/esm/tools/form-dialog.d.ts +2 -1
- package/dist/index.css +1 -1
- package/package.json +4 -4
- package/dist/cjs/chat/chat-bot-view.test.js +0 -325
- package/dist/cjs/chat/live-chat-widgets.test.js +0 -256
- package/dist/esm/chat/chat-bot-view.test.js +0 -336
- package/dist/esm/chat/live-chat-widgets.test.js +0 -262
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
3
|
-
var import_vitest = require("vitest");
|
|
4
|
-
var import_react = require("react");
|
|
5
|
-
var import_react2 = require("@testing-library/react");
|
|
6
|
-
var import_meshagent = require("@meshagent/meshagent");
|
|
7
|
-
var import_meshagent_agents = require("@meshagent/meshagent-agents");
|
|
8
|
-
var import_agent_thread = require("./agent-thread.js");
|
|
9
|
-
var import_chat_bot_view = require("./chat-bot-view.js");
|
|
10
|
-
const REQUIRED_ENV = [
|
|
11
|
-
"MESHAGENT_TOKEN",
|
|
12
|
-
"MESHAGENT_ROOM",
|
|
13
|
-
"RUN_LIVE_WIDGET_TESTS",
|
|
14
|
-
"TEST_AGENT_NAME"
|
|
15
|
-
];
|
|
16
|
-
const missingEnv = REQUIRED_ENV.filter((name) => process.env[name] == null || process.env[name]?.trim() === "");
|
|
17
|
-
const liveDescribe = missingEnv.length === 0 ? import_vitest.describe : import_vitest.describe.skip;
|
|
18
|
-
liveDescribe("Live chat widgets", () => {
|
|
19
|
-
let room;
|
|
20
|
-
let chatClient;
|
|
21
|
-
const observedMessages = [];
|
|
22
|
-
let previousActEnvironment;
|
|
23
|
-
(0, import_vitest.beforeAll)(async () => {
|
|
24
|
-
previousActEnvironment = globalThis.IS_REACT_ACT_ENVIRONMENT;
|
|
25
|
-
setReactActEnvironment(false);
|
|
26
|
-
room = new import_meshagent.RoomClient();
|
|
27
|
-
await room.start({
|
|
28
|
-
onError: (error) => {
|
|
29
|
-
console.error("live widget room client error", error);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
chatClient = new import_meshagent_agents.MessagingChatClient({
|
|
33
|
-
room,
|
|
34
|
-
agentName: process.env.TEST_AGENT_NAME
|
|
35
|
-
});
|
|
36
|
-
void (async () => {
|
|
37
|
-
for await (const event of chatClient.events) {
|
|
38
|
-
observedMessages.push(event.message);
|
|
39
|
-
}
|
|
40
|
-
})();
|
|
41
|
-
await chatClient.start();
|
|
42
|
-
await withTimeout(
|
|
43
|
-
chatClient.waitForAgentParticipant({ waitKey: "live-chat-widget-agent" }),
|
|
44
|
-
3e4,
|
|
45
|
-
`agent participant '${process.env.TEST_AGENT_NAME}' did not appear`
|
|
46
|
-
);
|
|
47
|
-
});
|
|
48
|
-
(0, import_vitest.afterEach)(() => {
|
|
49
|
-
(0, import_react2.cleanup)();
|
|
50
|
-
});
|
|
51
|
-
(0, import_vitest.afterAll)(async () => {
|
|
52
|
-
await chatClient?.stop().catch(() => void 0);
|
|
53
|
-
room?.dispose();
|
|
54
|
-
setReactActEnvironment(previousActEnvironment);
|
|
55
|
-
});
|
|
56
|
-
(0, import_vitest.it)("renders a live AgentThread pending message and assistant response", async () => {
|
|
57
|
-
const start = await chatClient.startThread({
|
|
58
|
-
message: "Reply with only LIVE_WIDGET_INITIAL_OK.",
|
|
59
|
-
attachments: [],
|
|
60
|
-
senderName: "live-widget-test"
|
|
61
|
-
});
|
|
62
|
-
(0, import_react2.render)(
|
|
63
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
64
|
-
import_agent_thread.AgentThread,
|
|
65
|
-
{
|
|
66
|
-
room,
|
|
67
|
-
path: start.threadPath,
|
|
68
|
-
chatClient,
|
|
69
|
-
agentName: process.env.TEST_AGENT_NAME
|
|
70
|
-
}
|
|
71
|
-
)
|
|
72
|
-
);
|
|
73
|
-
await waitForDocumentText("LIVE_WIDGET_INITIAL_OK", "initial assistant response");
|
|
74
|
-
const pendingMessage = `live widget turn ${liveId()}: reply with only LIVE_WIDGET_TURN_OK.`;
|
|
75
|
-
const beforeObservedCount = observedMessages.length;
|
|
76
|
-
import_react2.fireEvent.change(import_react2.screen.getByPlaceholderText("Type a message"), {
|
|
77
|
-
target: { value: pendingMessage }
|
|
78
|
-
});
|
|
79
|
-
import_react2.fireEvent.click(import_react2.screen.getByTitle("Send"));
|
|
80
|
-
(0, import_vitest.expect)(await import_react2.screen.findByText(pendingMessage)).toBeTruthy();
|
|
81
|
-
await waitForObservedMessage(
|
|
82
|
-
beforeObservedCount,
|
|
83
|
-
(message) => message.type === import_meshagent_agents.agentTurnStartAcceptedType && stringValue(message, "threadId") === start.threadPath,
|
|
84
|
-
"widget turn acceptance"
|
|
85
|
-
);
|
|
86
|
-
await waitForObservedMessage(
|
|
87
|
-
beforeObservedCount,
|
|
88
|
-
(message) => message.type === import_meshagent_agents.agentTurnStartedType && stringValue(message, "threadId") === start.threadPath,
|
|
89
|
-
"widget turn start"
|
|
90
|
-
);
|
|
91
|
-
await waitForObservedMessage(
|
|
92
|
-
beforeObservedCount,
|
|
93
|
-
(message) => message.type === import_meshagent_agents.agentTextContentDeltaType && stringValue(message, "threadId") === start.threadPath,
|
|
94
|
-
"widget turn assistant delta"
|
|
95
|
-
);
|
|
96
|
-
await waitForDocumentText("LIVE_WIDGET_TURN_OK", "turn assistant response");
|
|
97
|
-
}, 18e4);
|
|
98
|
-
(0, import_vitest.it)("creates two live threads through ChatBotView and keeps the second selected", async () => {
|
|
99
|
-
const selectedPaths = [];
|
|
100
|
-
(0, import_react2.render)(
|
|
101
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.StrictMode, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
102
|
-
import_chat_bot_view.ChatBotView,
|
|
103
|
-
{
|
|
104
|
-
room,
|
|
105
|
-
chatClient,
|
|
106
|
-
agentName: process.env.TEST_AGENT_NAME,
|
|
107
|
-
threadDisplayMode: import_chat_bot_view.ChatThreadDisplayMode.MultiThreadComposer,
|
|
108
|
-
threadListPath: `agent://${process.env.TEST_AGENT_NAME}/threads`,
|
|
109
|
-
onSelectedThreadPathChanged: (path) => {
|
|
110
|
-
selectedPaths.push(path);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
) })
|
|
114
|
-
);
|
|
115
|
-
const firstPending = `live widget first thread ${liveId()}: reply with only LIVE_WIDGET_THREAD_ONE_OK.`;
|
|
116
|
-
import_react2.fireEvent.change(await import_react2.screen.findByPlaceholderText(`Type a message or @${process.env.TEST_AGENT_NAME}`), {
|
|
117
|
-
target: { value: firstPending }
|
|
118
|
-
});
|
|
119
|
-
import_react2.fireEvent.click(import_react2.screen.getByTitle("Send"));
|
|
120
|
-
await (0, import_react2.waitFor)(() => (0, import_vitest.expect)(selectedPaths.at(-1)).to.be.a("string").and.not.equal(""), { timeout: 9e4 });
|
|
121
|
-
const firstPath = selectedPaths.at(-1);
|
|
122
|
-
(0, import_vitest.expect)(firstPath).to.be.a("string").and.not.equal("");
|
|
123
|
-
(0, import_vitest.expect)(await import_react2.screen.findByText(firstPending)).toBeTruthy();
|
|
124
|
-
await waitForDocumentText("LIVE_WIDGET_THREAD_ONE_OK", "first ChatBotView assistant response");
|
|
125
|
-
import_react2.fireEvent.click(import_react2.screen.getByText("New thread"));
|
|
126
|
-
await (0, import_react2.waitFor)(() => (0, import_vitest.expect)(selectedPaths.at(-1)).to.equal(null), { timeout: 1e4 });
|
|
127
|
-
const secondPending = `live widget second thread ${liveId()}: reply with only LIVE_WIDGET_THREAD_TWO_OK.`;
|
|
128
|
-
import_react2.fireEvent.change(await import_react2.screen.findByPlaceholderText(`Type a message or @${process.env.TEST_AGENT_NAME}`), {
|
|
129
|
-
target: { value: secondPending }
|
|
130
|
-
});
|
|
131
|
-
import_react2.fireEvent.click(import_react2.screen.getByTitle("Send"));
|
|
132
|
-
await (0, import_react2.waitFor)(() => {
|
|
133
|
-
(0, import_vitest.expect)(selectedPaths.at(-1)).to.be.a("string").and.not.equal("");
|
|
134
|
-
(0, import_vitest.expect)(selectedPaths.at(-1)).to.not.equal(firstPath);
|
|
135
|
-
}, { timeout: 9e4 });
|
|
136
|
-
(0, import_vitest.expect)(await import_react2.screen.findByText(secondPending)).toBeTruthy();
|
|
137
|
-
(0, import_vitest.expect)(import_react2.screen.queryByText(firstPending)).to.equal(null);
|
|
138
|
-
await waitForDocumentText("LIVE_WIDGET_THREAD_TWO_OK", "second ChatBotView assistant response");
|
|
139
|
-
}, 24e4);
|
|
140
|
-
(0, import_vitest.it)("passes client toolkits from widgets into live turn starts", async () => {
|
|
141
|
-
const start = await chatClient.startThread({
|
|
142
|
-
message: "Reply with only LIVE_WIDGET_TOOL_THREAD_OK.",
|
|
143
|
-
attachments: [],
|
|
144
|
-
senderName: "live-widget-test"
|
|
145
|
-
});
|
|
146
|
-
const clientToolkits = [new import_meshagent_agents.ClientToolkitDescription({
|
|
147
|
-
name: "ask_user",
|
|
148
|
-
title: "Ask User",
|
|
149
|
-
description: "Ask the user a short question.",
|
|
150
|
-
inputSchema: {
|
|
151
|
-
type: "object",
|
|
152
|
-
additionalProperties: false,
|
|
153
|
-
required: ["prompt"],
|
|
154
|
-
properties: {
|
|
155
|
-
prompt: { type: "string" }
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
})];
|
|
159
|
-
(0, import_react2.render)(
|
|
160
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
161
|
-
import_agent_thread.AgentThread,
|
|
162
|
-
{
|
|
163
|
-
room,
|
|
164
|
-
path: start.threadPath,
|
|
165
|
-
chatClient,
|
|
166
|
-
agentName: process.env.TEST_AGENT_NAME,
|
|
167
|
-
clientToolkits
|
|
168
|
-
}
|
|
169
|
-
)
|
|
170
|
-
);
|
|
171
|
-
await waitForDocumentText("LIVE_WIDGET_TOOL_THREAD_OK", "tool setup assistant response");
|
|
172
|
-
const beforeObservedCount = observedMessages.length;
|
|
173
|
-
import_react2.fireEvent.change(import_react2.screen.getByPlaceholderText("Type a message"), {
|
|
174
|
-
target: {
|
|
175
|
-
value: "Use the ask_user client tool to ask whether the live widget client toolkit is connected."
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
import_react2.fireEvent.click(import_react2.screen.getByTitle("Send"));
|
|
179
|
-
await waitForObservedMessage(
|
|
180
|
-
beforeObservedCount,
|
|
181
|
-
(message) => stringValue(message, "threadId") === start.threadPath && (message.type === import_meshagent_agents.agentClientToolCallRequestedType || message.type === import_meshagent_agents.agentTextContentDeltaType),
|
|
182
|
-
"widget client toolkit-capable response"
|
|
183
|
-
);
|
|
184
|
-
}, 18e4);
|
|
185
|
-
async function waitForObservedMessage(afterCount, predicate, label, timeoutMs = 9e4) {
|
|
186
|
-
const deadline = Date.now() + timeoutMs;
|
|
187
|
-
while (Date.now() < deadline) {
|
|
188
|
-
const message = observedMessages.slice(afterCount).find(predicate);
|
|
189
|
-
if (message != null) {
|
|
190
|
-
return message;
|
|
191
|
-
}
|
|
192
|
-
await delay(50);
|
|
193
|
-
}
|
|
194
|
-
throw new Error(`${label} was not observed within ${timeoutMs}ms. Observed: ${summarizeMessages(observedMessages)}`);
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
if (missingEnv.length > 0) {
|
|
198
|
-
(0, import_vitest.describe)("Live chat widgets", () => {
|
|
199
|
-
(0, import_vitest.it)(`is skipped unless ${REQUIRED_ENV.join(", ")} are set`, () => {
|
|
200
|
-
(0, import_vitest.expect)(missingEnv.length).to.be.greaterThan(0);
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
async function waitForDocumentText(text, label, timeoutMs = 9e4) {
|
|
205
|
-
await (0, import_react2.waitFor)(() => {
|
|
206
|
-
(0, import_vitest.expect)(document.body.textContent ?? "", label).to.contain(text);
|
|
207
|
-
}, { timeout: timeoutMs });
|
|
208
|
-
}
|
|
209
|
-
async function withTimeout(promise, timeoutMs, label) {
|
|
210
|
-
let timeout;
|
|
211
|
-
try {
|
|
212
|
-
return await Promise.race([
|
|
213
|
-
promise,
|
|
214
|
-
new Promise((_, reject) => {
|
|
215
|
-
timeout = setTimeout(() => reject(new Error(`${label} within ${timeoutMs}ms`)), timeoutMs);
|
|
216
|
-
})
|
|
217
|
-
]);
|
|
218
|
-
} finally {
|
|
219
|
-
if (timeout != null) {
|
|
220
|
-
clearTimeout(timeout);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
function stringValue(value, property) {
|
|
225
|
-
if (value == null || typeof value !== "object" || !Object.prototype.hasOwnProperty.call(value, property)) {
|
|
226
|
-
return void 0;
|
|
227
|
-
}
|
|
228
|
-
const item = value[property];
|
|
229
|
-
return typeof item === "string" && item.trim() !== "" ? item : void 0;
|
|
230
|
-
}
|
|
231
|
-
function summarizeMessages(messages) {
|
|
232
|
-
return messages.map((message) => {
|
|
233
|
-
const threadId = stringValue(message, "threadId");
|
|
234
|
-
const source = stringValue(message, "sourceMessageId");
|
|
235
|
-
const turn = stringValue(message, "turnId");
|
|
236
|
-
return [message.type, threadId == null ? void 0 : `thread=${threadId}`, source == null ? void 0 : `source=${source}`, turn == null ? void 0 : `turn=${turn}`].filter((part) => part != null).join(" ");
|
|
237
|
-
}).join(", ");
|
|
238
|
-
}
|
|
239
|
-
function setReactActEnvironment(value) {
|
|
240
|
-
Object.defineProperty(globalThis, "IS_REACT_ACT_ENVIRONMENT", {
|
|
241
|
-
configurable: true,
|
|
242
|
-
writable: true,
|
|
243
|
-
value
|
|
244
|
-
});
|
|
245
|
-
Object.defineProperty(window, "IS_REACT_ACT_ENVIRONMENT", {
|
|
246
|
-
configurable: true,
|
|
247
|
-
writable: true,
|
|
248
|
-
value
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
function liveId() {
|
|
252
|
-
return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
253
|
-
}
|
|
254
|
-
function delay(ms) {
|
|
255
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
256
|
-
}
|
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { StrictMode } from "react";
|
|
3
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
4
|
-
import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
5
|
-
import {
|
|
6
|
-
AgentTextContentDelta,
|
|
7
|
-
AgentThreadListEntry,
|
|
8
|
-
BaseChatClient,
|
|
9
|
-
ClientToolkitDescription,
|
|
10
|
-
CloseThread,
|
|
11
|
-
ListThreads,
|
|
12
|
-
StartThread,
|
|
13
|
-
ThreadCreated,
|
|
14
|
-
ThreadStarted,
|
|
15
|
-
ThreadsListed,
|
|
16
|
-
TurnStart
|
|
17
|
-
} from "@meshagent/meshagent-agents";
|
|
18
|
-
import { AgentThread } from "./agent-thread.js";
|
|
19
|
-
import { ChatBotView, ChatThreadDisplayMode } from "./chat-bot-view.js";
|
|
20
|
-
class FakeParticipant {
|
|
21
|
-
id;
|
|
22
|
-
role;
|
|
23
|
-
attributes;
|
|
24
|
-
constructor({ id, role, attributes }) {
|
|
25
|
-
this.id = id;
|
|
26
|
-
this.role = role;
|
|
27
|
-
this.attributes = new Map(Object.entries(attributes));
|
|
28
|
-
}
|
|
29
|
-
getAttribute(name) {
|
|
30
|
-
return this.attributes.get(name);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
class FakeMessaging {
|
|
34
|
-
remoteParticipants = [
|
|
35
|
-
new FakeParticipant({
|
|
36
|
-
id: "agent-codex",
|
|
37
|
-
role: "agent",
|
|
38
|
-
attributes: {
|
|
39
|
-
name: "codex",
|
|
40
|
-
supports_agent_messages: true
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
];
|
|
44
|
-
listeners = /* @__PURE__ */ new Map();
|
|
45
|
-
on(event, listener) {
|
|
46
|
-
const listeners = this.listeners.get(event) ?? /* @__PURE__ */ new Set();
|
|
47
|
-
listeners.add(listener);
|
|
48
|
-
this.listeners.set(event, listeners);
|
|
49
|
-
}
|
|
50
|
-
off(event, listener) {
|
|
51
|
-
this.listeners.get(event)?.delete(listener);
|
|
52
|
-
}
|
|
53
|
-
sendMessage() {
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
class FakeElement {
|
|
57
|
-
tagName;
|
|
58
|
-
id;
|
|
59
|
-
attributes;
|
|
60
|
-
children = [];
|
|
61
|
-
constructor(tagName, attributes = {}) {
|
|
62
|
-
this.tagName = tagName;
|
|
63
|
-
this.id = typeof attributes.id === "string" ? attributes.id : crypto.randomUUID();
|
|
64
|
-
this.attributes = new Map(Object.entries(attributes));
|
|
65
|
-
}
|
|
66
|
-
getAttribute(name) {
|
|
67
|
-
return this.attributes.get(name);
|
|
68
|
-
}
|
|
69
|
-
getChildren() {
|
|
70
|
-
return this.children;
|
|
71
|
-
}
|
|
72
|
-
createChildElement(tagName, attributes = {}) {
|
|
73
|
-
const child = new FakeElement(tagName, attributes);
|
|
74
|
-
this.children.push(child);
|
|
75
|
-
return child;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
class FakeDocument {
|
|
79
|
-
root;
|
|
80
|
-
constructor() {
|
|
81
|
-
this.root = new FakeElement("thread");
|
|
82
|
-
this.root.createChildElement("members");
|
|
83
|
-
this.root.createChildElement("messages");
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function neverEndingEvents() {
|
|
87
|
-
return {
|
|
88
|
-
[Symbol.asyncIterator]: () => ({
|
|
89
|
-
next: () => new Promise(() => void 0),
|
|
90
|
-
return: async () => ({ done: true, value: void 0 })
|
|
91
|
-
})
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
function fakeRoom() {
|
|
95
|
-
return {
|
|
96
|
-
localParticipant: new FakeParticipant({
|
|
97
|
-
id: "local",
|
|
98
|
-
role: "user",
|
|
99
|
-
attributes: { name: "Jesse" }
|
|
100
|
-
}),
|
|
101
|
-
messaging: new FakeMessaging(),
|
|
102
|
-
sync: {
|
|
103
|
-
open: async () => new FakeDocument(),
|
|
104
|
-
close: async () => void 0
|
|
105
|
-
},
|
|
106
|
-
listen: neverEndingEvents,
|
|
107
|
-
on: () => void 0,
|
|
108
|
-
off: () => void 0
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
class FakeChatClient extends BaseChatClient {
|
|
112
|
-
sent = [];
|
|
113
|
-
threadEntries = [];
|
|
114
|
-
async sendAgentMessage(message) {
|
|
115
|
-
this.sent.push(message);
|
|
116
|
-
if (message instanceof ListThreads) {
|
|
117
|
-
queueMicrotask(() => {
|
|
118
|
-
this.handleAgentMessage(new ThreadsListed({
|
|
119
|
-
sourceMessageId: message.messageId,
|
|
120
|
-
threads: this.threadEntries,
|
|
121
|
-
total: this.threadEntries.length,
|
|
122
|
-
offset: 0,
|
|
123
|
-
limit: 200
|
|
124
|
-
}));
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
publishThread(path, name) {
|
|
129
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
130
|
-
this.threadEntries.unshift({
|
|
131
|
-
path,
|
|
132
|
-
name,
|
|
133
|
-
createdAt: now,
|
|
134
|
-
modifiedAt: now
|
|
135
|
-
});
|
|
136
|
-
this.handleAgentMessage(new ThreadCreated({
|
|
137
|
-
thread: new AgentThreadListEntry({
|
|
138
|
-
path,
|
|
139
|
-
name,
|
|
140
|
-
createdAt: now,
|
|
141
|
-
modifiedAt: now
|
|
142
|
-
})
|
|
143
|
-
}));
|
|
144
|
-
}
|
|
145
|
-
startThreadMessages() {
|
|
146
|
-
return this.sent.filter((message) => message instanceof StartThread);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
afterEach(() => {
|
|
150
|
-
cleanup();
|
|
151
|
-
});
|
|
152
|
-
describe("ChatBotView multi-thread composer", () => {
|
|
153
|
-
it("renders typed agent messages and selects the second newly-created thread after returning to New thread", async () => {
|
|
154
|
-
const room = fakeRoom();
|
|
155
|
-
const chatClient = new FakeChatClient();
|
|
156
|
-
const selectedPaths = [];
|
|
157
|
-
const clientToolkits = [new ClientToolkitDescription({
|
|
158
|
-
name: "ask_user",
|
|
159
|
-
title: "Ask User",
|
|
160
|
-
description: "Ask the user a short question.",
|
|
161
|
-
inputSchema: {
|
|
162
|
-
type: "object",
|
|
163
|
-
properties: {
|
|
164
|
-
prompt: { type: "string" }
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
})];
|
|
168
|
-
render(
|
|
169
|
-
/* @__PURE__ */ jsx(
|
|
170
|
-
ChatBotView,
|
|
171
|
-
{
|
|
172
|
-
room,
|
|
173
|
-
chatClient,
|
|
174
|
-
agentName: "codex",
|
|
175
|
-
threadDisplayMode: ChatThreadDisplayMode.MultiThreadComposer,
|
|
176
|
-
threadListPath: "agent://codex/threads",
|
|
177
|
-
onSelectedThreadPathChanged: (path) => {
|
|
178
|
-
selectedPaths.push(path);
|
|
179
|
-
},
|
|
180
|
-
clientToolkits
|
|
181
|
-
}
|
|
182
|
-
)
|
|
183
|
-
);
|
|
184
|
-
await waitFor(() => expect(screen.getByText("Start a new thread")).toBeTruthy());
|
|
185
|
-
fireEvent.change(screen.getByPlaceholderText("Type a message or @codex"), {
|
|
186
|
-
target: { value: "first pending message" }
|
|
187
|
-
});
|
|
188
|
-
fireEvent.click(screen.getByTitle("Send"));
|
|
189
|
-
await waitFor(() => expect(chatClient.startThreadMessages()).toHaveLength(1));
|
|
190
|
-
expect(chatClient.startThreadMessages()[0].clientToolkits?.[0].name).to.equal("ask_user");
|
|
191
|
-
await act(async () => {
|
|
192
|
-
chatClient.publishThread("thread-first", "First thread");
|
|
193
|
-
chatClient.handleAgentMessage(new ThreadStarted({
|
|
194
|
-
sourceMessageId: chatClient.startThreadMessages()[0].messageId,
|
|
195
|
-
threadId: "thread-first"
|
|
196
|
-
}));
|
|
197
|
-
});
|
|
198
|
-
await waitFor(() => expect(selectedPaths.at(-1)).to.equal("thread-first"));
|
|
199
|
-
expect(await screen.findByText("first pending message")).toBeTruthy();
|
|
200
|
-
await act(async () => {
|
|
201
|
-
chatClient.handleAgentMessage(new AgentTextContentDelta({
|
|
202
|
-
threadId: "thread-first",
|
|
203
|
-
turnId: "turn-first",
|
|
204
|
-
itemId: "agent-response-first",
|
|
205
|
-
text: "first agent response"
|
|
206
|
-
}));
|
|
207
|
-
});
|
|
208
|
-
expect(await screen.findByText("first agent response")).toBeTruthy();
|
|
209
|
-
fireEvent.click(screen.getByText("New thread"));
|
|
210
|
-
await waitFor(() => expect(screen.getByText("Start a new thread")).toBeTruthy());
|
|
211
|
-
fireEvent.change(screen.getByPlaceholderText("Type a message or @codex"), {
|
|
212
|
-
target: { value: "second pending message" }
|
|
213
|
-
});
|
|
214
|
-
fireEvent.click(screen.getByTitle("Send"));
|
|
215
|
-
await waitFor(() => expect(chatClient.startThreadMessages()).toHaveLength(2));
|
|
216
|
-
expect(chatClient.startThreadMessages()[1].clientToolkits?.[0].name).to.equal("ask_user");
|
|
217
|
-
await act(async () => {
|
|
218
|
-
chatClient.handleAgentMessage(new ThreadStarted({
|
|
219
|
-
sourceMessageId: chatClient.startThreadMessages()[1].messageId,
|
|
220
|
-
threadId: "thread-second"
|
|
221
|
-
}));
|
|
222
|
-
});
|
|
223
|
-
await waitFor(() => expect(selectedPaths.at(-1)).to.equal("thread-second"));
|
|
224
|
-
expect(await screen.findByText("second pending message")).toBeTruthy();
|
|
225
|
-
expect(screen.queryByText("first pending message")).to.equal(null);
|
|
226
|
-
expect(screen.queryByText("first agent response")).to.equal(null);
|
|
227
|
-
});
|
|
228
|
-
it("keeps started sessions alive across StrictMode remounts and renders responses for each redirected thread", async () => {
|
|
229
|
-
const room = fakeRoom();
|
|
230
|
-
const chatClient = new FakeChatClient();
|
|
231
|
-
const selectedPaths = [];
|
|
232
|
-
render(
|
|
233
|
-
/* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsx(
|
|
234
|
-
ChatBotView,
|
|
235
|
-
{
|
|
236
|
-
room,
|
|
237
|
-
chatClient,
|
|
238
|
-
agentName: "codex",
|
|
239
|
-
threadDisplayMode: ChatThreadDisplayMode.MultiThreadComposer,
|
|
240
|
-
threadListPath: "agent://codex/threads",
|
|
241
|
-
onSelectedThreadPathChanged: (path) => {
|
|
242
|
-
selectedPaths.push(path);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
) })
|
|
246
|
-
);
|
|
247
|
-
await waitFor(() => expect(screen.getByText("Start a new thread")).toBeTruthy());
|
|
248
|
-
fireEvent.change(screen.getByPlaceholderText("Type a message or @codex"), {
|
|
249
|
-
target: { value: "first strict pending" }
|
|
250
|
-
});
|
|
251
|
-
fireEvent.click(screen.getByTitle("Send"));
|
|
252
|
-
await waitFor(() => expect(chatClient.startThreadMessages()).toHaveLength(1));
|
|
253
|
-
await act(async () => {
|
|
254
|
-
chatClient.handleAgentMessage(new ThreadStarted({
|
|
255
|
-
sourceMessageId: chatClient.startThreadMessages()[0].messageId,
|
|
256
|
-
threadId: "thread-strict-first"
|
|
257
|
-
}));
|
|
258
|
-
chatClient.handleAgentMessage(new AgentTextContentDelta({
|
|
259
|
-
threadId: "thread-strict-first",
|
|
260
|
-
turnId: "turn-strict-first",
|
|
261
|
-
itemId: "agent-response-strict-first",
|
|
262
|
-
text: "first strict response"
|
|
263
|
-
}));
|
|
264
|
-
});
|
|
265
|
-
await waitFor(() => expect(selectedPaths.at(-1)).to.equal("thread-strict-first"));
|
|
266
|
-
expect(await screen.findByText("first strict pending")).toBeTruthy();
|
|
267
|
-
expect(await screen.findByText("first strict response")).toBeTruthy();
|
|
268
|
-
expect(screen.queryByText(/Starting a thread/i)).to.equal(null);
|
|
269
|
-
expect(chatClient.sent.some((message) => message instanceof CloseThread && message.threadId === "thread-strict-first")).to.equal(false);
|
|
270
|
-
fireEvent.click(screen.getByText("New thread"));
|
|
271
|
-
await waitFor(() => expect(selectedPaths.at(-1)).to.equal(null));
|
|
272
|
-
await waitFor(() => expect(screen.getByText("Start a new thread")).toBeTruthy());
|
|
273
|
-
fireEvent.change(screen.getByPlaceholderText("Type a message or @codex"), {
|
|
274
|
-
target: { value: "second strict pending" }
|
|
275
|
-
});
|
|
276
|
-
fireEvent.click(screen.getByTitle("Send"));
|
|
277
|
-
await waitFor(() => expect(chatClient.startThreadMessages()).toHaveLength(2));
|
|
278
|
-
await act(async () => {
|
|
279
|
-
chatClient.handleAgentMessage(new ThreadStarted({
|
|
280
|
-
sourceMessageId: chatClient.startThreadMessages()[1].messageId,
|
|
281
|
-
threadId: "thread-strict-second"
|
|
282
|
-
}));
|
|
283
|
-
chatClient.handleAgentMessage(new AgentTextContentDelta({
|
|
284
|
-
threadId: "thread-strict-second",
|
|
285
|
-
turnId: "turn-strict-second",
|
|
286
|
-
itemId: "agent-response-strict-second",
|
|
287
|
-
text: "second strict response"
|
|
288
|
-
}));
|
|
289
|
-
});
|
|
290
|
-
await waitFor(() => expect(selectedPaths.at(-1)).to.equal("thread-strict-second"));
|
|
291
|
-
expect(await screen.findByText("second strict pending")).toBeTruthy();
|
|
292
|
-
expect(await screen.findByText("second strict response")).toBeTruthy();
|
|
293
|
-
expect(screen.queryByText("first strict pending")).to.equal(null);
|
|
294
|
-
expect(screen.queryByText("first strict response")).to.equal(null);
|
|
295
|
-
expect(screen.queryByText(/Starting a thread/i)).to.equal(null);
|
|
296
|
-
expect(chatClient.sent.some((message) => message instanceof CloseThread && message.threadId === "thread-strict-second")).to.equal(false);
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
describe("AgentThread", () => {
|
|
300
|
-
it("passes client toolkits on turn starts from the composer", async () => {
|
|
301
|
-
const room = fakeRoom();
|
|
302
|
-
const chatClient = new FakeChatClient();
|
|
303
|
-
const clientToolkits = [new ClientToolkitDescription({
|
|
304
|
-
name: "ask_user",
|
|
305
|
-
title: "Ask User",
|
|
306
|
-
description: "Ask the user a short question.",
|
|
307
|
-
inputSchema: {
|
|
308
|
-
type: "object",
|
|
309
|
-
properties: {
|
|
310
|
-
prompt: { type: "string" }
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
})];
|
|
314
|
-
render(
|
|
315
|
-
/* @__PURE__ */ jsx(
|
|
316
|
-
AgentThread,
|
|
317
|
-
{
|
|
318
|
-
room,
|
|
319
|
-
path: "thread-existing",
|
|
320
|
-
chatClient,
|
|
321
|
-
agentName: "codex",
|
|
322
|
-
clientToolkits
|
|
323
|
-
}
|
|
324
|
-
)
|
|
325
|
-
);
|
|
326
|
-
fireEvent.change(screen.getByPlaceholderText("Type a message"), {
|
|
327
|
-
target: { value: "turn start with a client toolkit" }
|
|
328
|
-
});
|
|
329
|
-
fireEvent.click(screen.getByTitle("Send"));
|
|
330
|
-
await waitFor(() => {
|
|
331
|
-
const turnStarts = chatClient.sent.filter((message) => message instanceof TurnStart);
|
|
332
|
-
expect(turnStarts).toHaveLength(1);
|
|
333
|
-
expect(turnStarts[0].clientToolkits?.[0].name).to.equal("ask_user");
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
});
|