@meshagent/meshagent-tailwind 0.43.2 → 0.43.3
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 +3 -0
- package/dist/cjs/chat/agent-thread.d.ts +15 -0
- package/dist/cjs/chat/agent-thread.js +613 -0
- package/dist/cjs/chat/chat-bot-view.d.ts +3 -2
- package/dist/cjs/chat/chat-bot-view.js +34 -34
- package/dist/cjs/chat/chat-bot-view.test.js +325 -0
- package/dist/cjs/chat/live-chat-widgets.test.js +256 -0
- package/dist/cjs/chat/multi-thread-view.d.ts +3 -2
- package/dist/cjs/chat/multi-thread-view.js +4 -2
- package/dist/cjs/chat/new-chat-thread.d.ts +3 -2
- package/dist/cjs/chat/new-chat-thread.js +5 -2
- package/dist/cjs/file-preview/file-preview.js +2 -2
- package/dist/cjs/index.d.ts +1 -2
- package/dist/cjs/index.js +1 -2
- package/dist/esm/chat/agent-thread.d.ts +15 -0
- package/dist/esm/chat/agent-thread.js +606 -0
- package/dist/esm/chat/chat-bot-view.d.ts +3 -2
- package/dist/esm/chat/chat-bot-view.js +34 -34
- package/dist/esm/chat/chat-bot-view.test.js +336 -0
- package/dist/esm/chat/live-chat-widgets.test.js +262 -0
- package/dist/esm/chat/multi-thread-view.d.ts +3 -2
- package/dist/esm/chat/multi-thread-view.js +4 -2
- package/dist/esm/chat/new-chat-thread.d.ts +3 -2
- package/dist/esm/chat/new-chat-thread.js +5 -2
- package/dist/esm/file-preview/file-preview.js +2 -2
- package/dist/esm/index.d.ts +1 -2
- package/dist/esm/index.js +1 -2
- package/dist/index.css +1 -1
- package/package.json +10 -5
- package/dist/cjs/chat/chat-thread.d.ts +0 -12
- package/dist/cjs/chat/chat-thread.js +0 -815
- package/dist/cjs/chat/dataset-chat-thread.d.ts +0 -16
- package/dist/cjs/chat/dataset-chat-thread.js +0 -1813
- package/dist/esm/chat/chat-thread.d.ts +0 -12
- package/dist/esm/chat/chat-thread.js +0 -785
- package/dist/esm/chat/dataset-chat-thread.d.ts +0 -16
- package/dist/esm/chat/dataset-chat-thread.js +0 -1811
|
@@ -14,8 +14,7 @@ import {
|
|
|
14
14
|
Pencil
|
|
15
15
|
} from "lucide-react";
|
|
16
16
|
import { useThreadStatus } from "./chat-hooks.js";
|
|
17
|
-
import {
|
|
18
|
-
import { DatasetChatThread } from "./dataset-chat-thread.js";
|
|
17
|
+
import { AgentThread } from "./agent-thread.js";
|
|
19
18
|
import { Button } from "../components/ui/button.js";
|
|
20
19
|
import {
|
|
21
20
|
Dialog,
|
|
@@ -47,9 +46,6 @@ function normalizePath(path) {
|
|
|
47
46
|
const normalized = path?.trim();
|
|
48
47
|
return normalized ? normalized : null;
|
|
49
48
|
}
|
|
50
|
-
function isDatasetBackedThreadPath(path) {
|
|
51
|
-
return path.startsWith("dataset://") || path.startsWith("tmp://");
|
|
52
|
-
}
|
|
53
49
|
function parseDate(value) {
|
|
54
50
|
const parsed = new Date(value);
|
|
55
51
|
return Number.isNaN(parsed.getTime()) ? /* @__PURE__ */ new Date(0) : parsed;
|
|
@@ -375,7 +371,13 @@ function ThreadListPanel({
|
|
|
375
371
|
}) {
|
|
376
372
|
const { entries, error, loading } = threadList;
|
|
377
373
|
const hasSelectedEntry = selectedThreadPath !== null && entries.some((entry) => entry.path === selectedThreadPath);
|
|
378
|
-
const showPendingNewThreadSelection = selectedThreadPath === null
|
|
374
|
+
const showPendingNewThreadSelection = selectedThreadPath === null;
|
|
375
|
+
const pendingSelectedThreadEntry = selectedThreadPath !== null && !hasSelectedEntry ? {
|
|
376
|
+
path: selectedThreadPath,
|
|
377
|
+
name: defaultThreadDisplayNameFromPath(selectedThreadPath),
|
|
378
|
+
createdAt: "",
|
|
379
|
+
modifiedAt: ""
|
|
380
|
+
} : null;
|
|
379
381
|
return /* @__PURE__ */ jsx("div", { className: "h-full flex flex-col rounded-md border", children: loading ? /* @__PURE__ */ jsx("div", { className: "flex min-h-0 flex-1 items-center justify-center p-6", children: /* @__PURE__ */ jsx(Spinner, { size: "lg", className: "text-muted-foreground" }) }) : error ? /* @__PURE__ */ jsx("div", { className: "flex min-h-0 flex-1 items-center justify-center p-6 text-center text-sm text-muted-foreground", children: `Unable to load threads: ${describeError(error)}` }) : /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-1 flex-col overflow-y-auto py-1", children: [
|
|
380
382
|
/* @__PURE__ */ jsx(
|
|
381
383
|
ThreadListRow,
|
|
@@ -387,6 +389,18 @@ function ThreadListPanel({
|
|
|
387
389
|
}
|
|
388
390
|
),
|
|
389
391
|
entries.length === 0 && showPendingNewThreadSelection ? /* @__PURE__ */ jsx("div", { className: "flex min-h-0 flex-1 items-center justify-center px-4 py-6 text-center text-sm text-muted-foreground", children: "No threads yet" }) : null,
|
|
392
|
+
pendingSelectedThreadEntry !== null ? /* @__PURE__ */ jsx(
|
|
393
|
+
ThreadListEntryRow,
|
|
394
|
+
{
|
|
395
|
+
room,
|
|
396
|
+
entry: pendingSelectedThreadEntry,
|
|
397
|
+
agentName,
|
|
398
|
+
selected: true,
|
|
399
|
+
onSelect: onSelectThread,
|
|
400
|
+
onRename: onRenameThread
|
|
401
|
+
},
|
|
402
|
+
pendingSelectedThreadEntry.path
|
|
403
|
+
) : null,
|
|
390
404
|
entries.map((entry) => /* @__PURE__ */ jsx(
|
|
391
405
|
ThreadListEntryRow,
|
|
392
406
|
{
|
|
@@ -481,7 +495,8 @@ function ChatBotView({
|
|
|
481
495
|
newThreadResetVersion = 0,
|
|
482
496
|
showThreadList = true,
|
|
483
497
|
threadListWidth = 280,
|
|
484
|
-
threadListCollapsedHeight = 220
|
|
498
|
+
threadListCollapsedHeight = 220,
|
|
499
|
+
clientToolkits
|
|
485
500
|
}) {
|
|
486
501
|
const isWideLayout = useIsWideLayout(multiThreadLayoutBreakpointPx);
|
|
487
502
|
const resolvedDocumentPath = useMemo(
|
|
@@ -492,7 +507,7 @@ function ChatBotView({
|
|
|
492
507
|
() => resolvedDocumentPath ?? chatDocumentPath(agentName, { threadDir }),
|
|
493
508
|
[agentName, resolvedDocumentPath, threadDir]
|
|
494
509
|
);
|
|
495
|
-
const needsChatClient = chatClient != null || threadDisplayMode === ChatThreadDisplayMode.MultiThreadComposer
|
|
510
|
+
const needsChatClient = chatClient != null || threadDisplayMode === ChatThreadDisplayMode.MultiThreadComposer;
|
|
496
511
|
const ownsChatClient = chatClient == null && needsChatClient;
|
|
497
512
|
const activeChatClient = useMemo(
|
|
498
513
|
() => needsChatClient ? chatClient ?? new MessagingChatClient({ room, agentName }) : null,
|
|
@@ -610,25 +625,17 @@ function ChatBotView({
|
|
|
610
625
|
});
|
|
611
626
|
}, [activeSelectedThreadPath, closeRenameThreadDialog, emitResolvedThread, renameThreadDialog, threadList]);
|
|
612
627
|
if (threadDisplayMode !== ChatThreadDisplayMode.MultiThreadComposer) {
|
|
613
|
-
return
|
|
614
|
-
|
|
628
|
+
return /* @__PURE__ */ jsx(
|
|
629
|
+
AgentThread,
|
|
615
630
|
{
|
|
616
631
|
room,
|
|
617
632
|
path: resolvedSingleThreadPath,
|
|
618
633
|
chatClient: activeChatClient ?? void 0,
|
|
634
|
+
disposeChatClient: false,
|
|
619
635
|
agentName,
|
|
620
636
|
emptyStateTitle,
|
|
621
|
-
emptyStateDescription
|
|
622
|
-
|
|
623
|
-
) : /* @__PURE__ */ jsx(
|
|
624
|
-
ChatThread,
|
|
625
|
-
{
|
|
626
|
-
room,
|
|
627
|
-
path: resolvedSingleThreadPath,
|
|
628
|
-
participants,
|
|
629
|
-
agentName,
|
|
630
|
-
emptyStateTitle,
|
|
631
|
-
emptyStateDescription
|
|
637
|
+
emptyStateDescription,
|
|
638
|
+
clientToolkits
|
|
632
639
|
}
|
|
633
640
|
);
|
|
634
641
|
}
|
|
@@ -649,25 +656,18 @@ function ChatBotView({
|
|
|
649
656
|
onSelectedThreadResolved: emitResolvedThread,
|
|
650
657
|
newThreadResetVersion,
|
|
651
658
|
centerComposer,
|
|
652
|
-
|
|
653
|
-
|
|
659
|
+
clientToolkits,
|
|
660
|
+
builder: (threadPath) => /* @__PURE__ */ jsx(
|
|
661
|
+
AgentThread,
|
|
654
662
|
{
|
|
655
663
|
room,
|
|
656
664
|
path: threadPath,
|
|
657
665
|
chatClient: activeChatClient ?? void 0,
|
|
666
|
+
disposeChatClient: false,
|
|
658
667
|
agentName,
|
|
659
668
|
emptyStateTitle: startNewThreadTitle,
|
|
660
|
-
emptyStateDescription: startNewThreadDescription
|
|
661
|
-
|
|
662
|
-
) : /* @__PURE__ */ jsx(
|
|
663
|
-
ChatThread,
|
|
664
|
-
{
|
|
665
|
-
room,
|
|
666
|
-
path: threadPath,
|
|
667
|
-
participants,
|
|
668
|
-
agentName,
|
|
669
|
-
emptyStateTitle: startNewThreadTitle,
|
|
670
|
-
emptyStateDescription: startNewThreadDescription
|
|
669
|
+
emptyStateDescription: startNewThreadDescription,
|
|
670
|
+
clientToolkits
|
|
671
671
|
}
|
|
672
672
|
)
|
|
673
673
|
}
|
|
@@ -0,0 +1,336 @@
|
|
|
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
|
+
});
|