@meshagent/meshagent-tailwind 0.47.1 → 0.48.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 +10 -0
- package/dist/cjs/chat/agent-thread.d.ts +24 -24
- package/dist/cjs/chat/agent-thread.js +575 -808
- package/dist/cjs/chat/chat-bot-view.d.ts +18 -6
- package/dist/cjs/chat/chat-bot-view.js +29 -7
- package/dist/cjs/chat/chat-feed-widget-view.d.ts +7 -0
- package/dist/cjs/chat/chat-feed-widget-view.js +50 -0
- package/dist/cjs/chat/chat-feed-widget.d.ts +16 -0
- package/dist/cjs/chat/chat-feed-widget.js +51 -0
- package/dist/cjs/chat/chat-hooks.d.ts +2 -2
- package/dist/cjs/chat/chat-input.d.ts +3 -3
- package/dist/cjs/chat/chat-input.js +9 -4
- package/dist/cjs/chat/chat-scroller.d.ts +21 -0
- package/dist/cjs/chat/chat-scroller.js +139 -0
- package/dist/cjs/chat/chat-thread-timeline.d.ts +66 -0
- package/dist/cjs/chat/chat-thread-timeline.js +595 -0
- package/dist/cjs/chat/dataset-agent-thread.d.ts +16 -4
- package/dist/cjs/chat/dataset-agent-thread.js +112 -292
- package/dist/cjs/chat/multi-thread-view.d.ts +8 -3
- package/dist/cjs/chat/multi-thread-view.js +10 -2
- package/dist/cjs/chat/new-chat-thread.d.ts +8 -3
- package/dist/cjs/chat/new-chat-thread.js +63 -24
- package/dist/cjs/chat/thread-view.d.ts +18 -5
- package/dist/cjs/chat/thread-view.js +67 -9
- package/dist/cjs/chat/use-chat-virtualizer.d.ts +47 -0
- package/dist/cjs/chat/use-chat-virtualizer.js +336 -0
- package/dist/cjs/chat/virtualization.d.ts +44 -0
- package/dist/cjs/chat/virtualization.js +143 -0
- package/dist/cjs/components/ui/button.d.ts +2 -2
- package/dist/cjs/components/ui/dialog.d.ts +1 -1
- package/dist/cjs/components/ui/dialog.js +11 -1
- package/dist/cjs/components/ui/portal-container.d.ts +7 -0
- package/dist/cjs/components/ui/portal-container.js +46 -0
- package/dist/cjs/file-preview/file-preview.js +1 -1
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/meetings/meeting-scope.d.ts +2 -1
- package/dist/cjs/meetings/meeting-scope.js +1 -0
- package/dist/cjs/react-syntax-highlighter.d.js +1 -0
- package/dist/esm/chat/agent-thread.d.ts +24 -24
- package/dist/esm/chat/agent-thread.js +574 -838
- package/dist/esm/chat/chat-bot-view.d.ts +18 -6
- package/dist/esm/chat/chat-bot-view.js +29 -7
- package/dist/esm/chat/chat-feed-widget-view.d.ts +7 -0
- package/dist/esm/chat/chat-feed-widget-view.js +30 -0
- package/dist/esm/chat/chat-feed-widget.d.ts +16 -0
- package/dist/esm/chat/chat-feed-widget.js +31 -0
- package/dist/esm/chat/chat-hooks.d.ts +2 -2
- package/dist/esm/chat/chat-input.d.ts +3 -3
- package/dist/esm/chat/chat-input.js +9 -4
- package/dist/esm/chat/chat-scroller.d.ts +21 -0
- package/dist/esm/chat/chat-scroller.js +122 -0
- package/dist/esm/chat/chat-thread-timeline.d.ts +66 -0
- package/dist/esm/chat/chat-thread-timeline.js +605 -0
- package/dist/esm/chat/dataset-agent-thread.d.ts +16 -4
- package/dist/esm/chat/dataset-agent-thread.js +114 -307
- package/dist/esm/chat/multi-thread-view.d.ts +8 -3
- package/dist/esm/chat/multi-thread-view.js +10 -2
- package/dist/esm/chat/new-chat-thread.d.ts +8 -3
- package/dist/esm/chat/new-chat-thread.js +64 -25
- package/dist/esm/chat/thread-view.d.ts +18 -5
- package/dist/esm/chat/thread-view.js +67 -9
- package/dist/esm/chat/use-chat-virtualizer.d.ts +47 -0
- package/dist/esm/chat/use-chat-virtualizer.js +331 -0
- package/dist/esm/chat/virtualization.d.ts +44 -0
- package/dist/esm/chat/virtualization.js +123 -0
- package/dist/esm/components/ui/button.d.ts +2 -2
- package/dist/esm/components/ui/dialog.d.ts +1 -1
- package/dist/esm/components/ui/dialog.js +11 -1
- package/dist/esm/components/ui/portal-container.d.ts +7 -0
- package/dist/esm/components/ui/portal-container.js +16 -0
- package/dist/esm/file-preview/file-preview.js +1 -1
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/meetings/meeting-scope.d.ts +2 -1
- package/dist/esm/meetings/meeting-scope.js +1 -0
- package/dist/esm/react-syntax-highlighter.d.js +0 -0
- package/dist/index.css +1 -1
- package/package.json +6 -5
|
@@ -31,7 +31,7 @@ __export(agent_thread_exports, {
|
|
|
31
31
|
AgentThread: () => AgentThread,
|
|
32
32
|
AgentToolChoice: () => AgentToolChoice,
|
|
33
33
|
AgentUsageFooter: () => AgentUsageFooter,
|
|
34
|
-
AgentUsageSnapshot: () => AgentUsageSnapshot,
|
|
34
|
+
AgentUsageSnapshot: () => import_chat_thread_timeline2.AgentUsageSnapshot,
|
|
35
35
|
ChatThreadPreview: () => ChatThreadPreview,
|
|
36
36
|
EventLine: () => EventLine,
|
|
37
37
|
ReasoningTrace: () => ReasoningTrace,
|
|
@@ -39,24 +39,32 @@ __export(agent_thread_exports, {
|
|
|
39
39
|
formatAgentUsageFooter: () => formatAgentUsageFooter,
|
|
40
40
|
formatAgentUsageTokenCount: () => formatAgentUsageTokenCount,
|
|
41
41
|
formatAgentUsageTooltip: () => formatAgentUsageTooltip,
|
|
42
|
-
shouldReplaceAgentUsageSnapshot: () => shouldReplaceAgentUsageSnapshot
|
|
42
|
+
shouldReplaceAgentUsageSnapshot: () => import_chat_thread_timeline2.shouldReplaceAgentUsageSnapshot
|
|
43
43
|
});
|
|
44
44
|
module.exports = __toCommonJS(agent_thread_exports);
|
|
45
45
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
46
46
|
var import_react = require("react");
|
|
47
|
+
var import_meshagent = require("@meshagent/meshagent");
|
|
47
48
|
var import_meshagent_agents = require("@meshagent/meshagent-agents");
|
|
49
|
+
var import_chat_thread_timeline = require("./chat-thread-timeline.js");
|
|
50
|
+
var import_chat_thread_timeline2 = require("./chat-thread-timeline.js");
|
|
48
51
|
var import_lucide_react = require("lucide-react");
|
|
49
52
|
var import_react_markdown = __toESM(require("react-markdown"));
|
|
50
53
|
var import_rehype_highlight = __toESM(require("rehype-highlight"));
|
|
51
54
|
var import_rehype_sanitize = __toESM(require("rehype-sanitize"));
|
|
52
55
|
var import_remark_gfm = __toESM(require("remark-gfm"));
|
|
53
|
-
var
|
|
54
|
-
var
|
|
55
|
-
var
|
|
56
|
-
var
|
|
57
|
-
var
|
|
56
|
+
var import_uuid = require("uuid");
|
|
57
|
+
var import_button = require("../components/ui/button.js");
|
|
58
|
+
var import_spinner = require("../components/ui/spinner.js");
|
|
59
|
+
var import_utils = require("../lib/utils.js");
|
|
60
|
+
var import_chat_input = require("./chat-input.js");
|
|
61
|
+
var import_chat_message = require("./chat-message.js");
|
|
62
|
+
var import_chat_scroller = require("./chat-scroller.js");
|
|
63
|
+
var import_chat_typing_indicator = require("./chat-typing-indicator.js");
|
|
64
|
+
var import_file_attachment = require("./file-attachment.js");
|
|
58
65
|
var import_file_preview = require("../file-preview/file-preview.js");
|
|
59
|
-
|
|
66
|
+
var import_chat_feed_widget = require("./chat-feed-widget.js");
|
|
67
|
+
var import_chat_feed_widget_view = require("./chat-feed-widget-view.js");
|
|
60
68
|
class AgentToolChoice {
|
|
61
69
|
toolkitName;
|
|
62
70
|
toolName;
|
|
@@ -68,162 +76,24 @@ class AgentToolChoice {
|
|
|
68
76
|
return { toolkit_name: this.toolkitName, tool_name: this.toolName };
|
|
69
77
|
}
|
|
70
78
|
}
|
|
71
|
-
function
|
|
72
|
-
return typeof value === "
|
|
73
|
-
}
|
|
74
|
-
function integerNumber(value) {
|
|
75
|
-
const numeric = finiteNumber(value);
|
|
76
|
-
return numeric == null ? null : Math.trunc(numeric);
|
|
77
|
-
}
|
|
78
|
-
function usageKeyMatches(key, names) {
|
|
79
|
-
for (const name of names) {
|
|
80
|
-
if (key === name || key.endsWith(`.${name}`)) {
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return false;
|
|
79
|
+
function stringValue(value) {
|
|
80
|
+
return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
85
81
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
found = true;
|
|
99
|
-
}
|
|
100
|
-
return found ? total : null;
|
|
101
|
-
}
|
|
102
|
-
function usageTotalTokens(rawUsage) {
|
|
103
|
-
const explicitTotal = sumUsageKeys(rawUsage, /* @__PURE__ */ new Set(["total_tokens"]));
|
|
104
|
-
if (explicitTotal != null) {
|
|
105
|
-
return explicitTotal;
|
|
106
|
-
}
|
|
107
|
-
const inputTokens = sumUsageKeys(rawUsage, /* @__PURE__ */ new Set([
|
|
108
|
-
"input_tokens",
|
|
109
|
-
"audio_input_tokens",
|
|
110
|
-
"image_input_tokens",
|
|
111
|
-
"cache_creation_input_tokens",
|
|
112
|
-
"cache_read_input_tokens"
|
|
113
|
-
]));
|
|
114
|
-
const outputTokens = sumUsageKeys(rawUsage, /* @__PURE__ */ new Set(["output_tokens", "audio_output_tokens", "image_output_tokens"]));
|
|
115
|
-
const cachedTokens = sumUsageKeys(rawUsage, /* @__PURE__ */ new Set(["cached_tokens", "audio_cached_tokens", "image_cached_tokens"]));
|
|
116
|
-
const reasoningTokens = sumUsageKeys(rawUsage, /* @__PURE__ */ new Set(["reasoning_tokens"]));
|
|
117
|
-
let total = 0;
|
|
118
|
-
let hasTotal = false;
|
|
119
|
-
if (inputTokens != null) {
|
|
120
|
-
total += inputTokens;
|
|
121
|
-
hasTotal = true;
|
|
122
|
-
} else if (cachedTokens != null) {
|
|
123
|
-
total += cachedTokens;
|
|
124
|
-
hasTotal = true;
|
|
125
|
-
}
|
|
126
|
-
if (outputTokens != null) {
|
|
127
|
-
total += outputTokens;
|
|
128
|
-
hasTotal = true;
|
|
129
|
-
} else if (reasoningTokens != null) {
|
|
130
|
-
total += reasoningTokens;
|
|
131
|
-
hasTotal = true;
|
|
132
|
-
}
|
|
133
|
-
return hasTotal ? total : null;
|
|
134
|
-
}
|
|
135
|
-
function usageValues(rawUsage) {
|
|
136
|
-
const usage = {};
|
|
137
|
-
for (const [key, value] of Object.entries(rawUsage)) {
|
|
138
|
-
const trimmedKey = key.trim();
|
|
139
|
-
const numeric = finiteNumber(value);
|
|
140
|
-
if (trimmedKey === "" || numeric == null) {
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
usage[trimmedKey] = numeric;
|
|
144
|
-
}
|
|
145
|
-
return Object.freeze(usage);
|
|
146
|
-
}
|
|
147
|
-
class AgentUsageSnapshot {
|
|
148
|
-
threadPath;
|
|
149
|
-
turnId;
|
|
150
|
-
contextUsedTokens;
|
|
151
|
-
contextTotalTokens;
|
|
152
|
-
compactionMode;
|
|
153
|
-
compactionThreshold;
|
|
154
|
-
totalTokens;
|
|
155
|
-
usage;
|
|
156
|
-
constructor({
|
|
157
|
-
threadPath,
|
|
158
|
-
turnId,
|
|
159
|
-
contextUsedTokens,
|
|
160
|
-
contextTotalTokens,
|
|
161
|
-
compactionMode,
|
|
162
|
-
compactionThreshold,
|
|
163
|
-
totalTokens,
|
|
164
|
-
usage
|
|
165
|
-
}) {
|
|
166
|
-
this.threadPath = threadPath;
|
|
167
|
-
this.turnId = turnId;
|
|
168
|
-
this.contextUsedTokens = contextUsedTokens;
|
|
169
|
-
this.contextTotalTokens = contextTotalTokens;
|
|
170
|
-
this.compactionMode = compactionMode;
|
|
171
|
-
this.compactionThreshold = compactionThreshold;
|
|
172
|
-
this.totalTokens = totalTokens;
|
|
173
|
-
this.usage = Object.freeze({ ...usage });
|
|
174
|
-
}
|
|
175
|
-
static fromMessage(message) {
|
|
176
|
-
if (!isTypedMessage(message, import_meshagent_agents.AgentUsageUpdated)) {
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
179
|
-
return AgentUsageSnapshot.fromPayload(message.toJson());
|
|
180
|
-
}
|
|
181
|
-
static fromPayload(payload) {
|
|
182
|
-
if (payload.type !== "meshagent.agent.usage.updated") {
|
|
183
|
-
return null;
|
|
184
|
-
}
|
|
185
|
-
const rawThreadPath = payload.thread_id;
|
|
186
|
-
if (typeof rawThreadPath !== "string" || rawThreadPath.trim() === "") {
|
|
187
|
-
return null;
|
|
188
|
-
}
|
|
189
|
-
const rawContextWindow = payload.context_window;
|
|
190
|
-
if (rawContextWindow == null || typeof rawContextWindow !== "object") {
|
|
191
|
-
return null;
|
|
192
|
-
}
|
|
193
|
-
const contextWindow = rawContextWindow;
|
|
194
|
-
const usedTokens = integerNumber(contextWindow.used_tokens);
|
|
195
|
-
if (usedTokens == null) {
|
|
196
|
-
return null;
|
|
82
|
+
function mergeAgentMessageEvents(persistedEvents, liveEvents) {
|
|
83
|
+
const merged = [...persistedEvents];
|
|
84
|
+
const indexByMessageId = new Map(
|
|
85
|
+
merged.map((event, index) => [event.message.messageId, index])
|
|
86
|
+
);
|
|
87
|
+
for (const event of liveEvents) {
|
|
88
|
+
const existingIndex = indexByMessageId.get(event.message.messageId);
|
|
89
|
+
if (existingIndex === void 0) {
|
|
90
|
+
indexByMessageId.set(event.message.messageId, merged.length);
|
|
91
|
+
merged.push(event);
|
|
92
|
+
} else {
|
|
93
|
+
merged[existingIndex] = event;
|
|
197
94
|
}
|
|
198
|
-
const totalContextTokens = contextWindow.total_tokens == null ? void 0 : integerNumber(contextWindow.total_tokens) ?? void 0;
|
|
199
|
-
const rawCompactionMode = contextWindow.compaction_mode;
|
|
200
|
-
const compactionMode = typeof rawCompactionMode === "string" && rawCompactionMode.trim() !== "" ? rawCompactionMode.trim() : void 0;
|
|
201
|
-
const compactionThreshold = contextWindow.compaction_threshold == null ? void 0 : integerNumber(contextWindow.compaction_threshold) ?? void 0;
|
|
202
|
-
const rawUsage = payload.usage != null && typeof payload.usage === "object" ? payload.usage : {};
|
|
203
|
-
const rawTurnId = payload.turn_id;
|
|
204
|
-
return new AgentUsageSnapshot({
|
|
205
|
-
threadPath: rawThreadPath.trim(),
|
|
206
|
-
turnId: typeof rawTurnId === "string" && rawTurnId.trim() !== "" ? rawTurnId.trim() : void 0,
|
|
207
|
-
contextUsedTokens: usedTokens,
|
|
208
|
-
contextTotalTokens: totalContextTokens,
|
|
209
|
-
compactionMode,
|
|
210
|
-
compactionThreshold,
|
|
211
|
-
totalTokens: usageTotalTokens(rawUsage) ?? void 0,
|
|
212
|
-
usage: usageValues(rawUsage)
|
|
213
|
-
});
|
|
214
95
|
}
|
|
215
|
-
|
|
216
|
-
function shouldReplaceAgentUsageSnapshot(current, next) {
|
|
217
|
-
if (current != null && current.contextUsedTokens > 0 && next.contextUsedTokens === 0 && Object.keys(next.usage).length === 0) {
|
|
218
|
-
return false;
|
|
219
|
-
}
|
|
220
|
-
return true;
|
|
221
|
-
}
|
|
222
|
-
function isTypedMessage(message, ctor) {
|
|
223
|
-
return message instanceof ctor;
|
|
224
|
-
}
|
|
225
|
-
function stringValue(value) {
|
|
226
|
-
return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
96
|
+
return merged;
|
|
227
97
|
}
|
|
228
98
|
function displayParticipantName(name) {
|
|
229
99
|
const normalized = name?.trim();
|
|
@@ -250,526 +120,15 @@ function findAgentParticipant(room, agentName) {
|
|
|
250
120
|
}
|
|
251
121
|
function timeAgo(date) {
|
|
252
122
|
const seconds = Math.max(0, Math.floor((Date.now() - date.getTime()) / 1e3));
|
|
253
|
-
if (seconds < 60)
|
|
254
|
-
return "now";
|
|
255
|
-
}
|
|
123
|
+
if (seconds < 60) return "now";
|
|
256
124
|
const minutes = Math.floor(seconds / 60);
|
|
257
|
-
if (minutes < 60)
|
|
258
|
-
return `${minutes}m`;
|
|
259
|
-
}
|
|
125
|
+
if (minutes < 60) return String(minutes) + "m";
|
|
260
126
|
const hours = Math.floor(minutes / 60);
|
|
261
|
-
|
|
262
|
-
return `${hours}h`;
|
|
263
|
-
}
|
|
264
|
-
return `${Math.floor(hours / 24)}d`;
|
|
265
|
-
}
|
|
266
|
-
function distanceFromBottom(element) {
|
|
267
|
-
return Math.max(element.scrollHeight - element.clientHeight - element.scrollTop, 0);
|
|
268
|
-
}
|
|
269
|
-
function isNearBottom(element) {
|
|
270
|
-
return distanceFromBottom(element) <= stickyBottomThresholdPx;
|
|
271
|
-
}
|
|
272
|
-
function inputContent(message) {
|
|
273
|
-
const textParts = [];
|
|
274
|
-
const attachments = [];
|
|
275
|
-
for (const item of message.content ?? []) {
|
|
276
|
-
if (item.type === "text" && item.text.trim() !== "") {
|
|
277
|
-
textParts.push(item.text);
|
|
278
|
-
} else if (item.type === "file" && item.url.trim() !== "") {
|
|
279
|
-
attachments.push(item.url);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
return { text: textParts.join("\n"), attachments };
|
|
283
|
-
}
|
|
284
|
-
function inputItemFromMessage(message, createdAt) {
|
|
285
|
-
if (isTypedMessage(message, import_meshagent_agents.StartThread) || isTypedMessage(message, import_meshagent_agents.TurnStart) || isTypedMessage(message, import_meshagent_agents.TurnSteer)) {
|
|
286
|
-
const content = inputContent(message);
|
|
287
|
-
if (content.text.trim() === "" && content.attachments.length === 0) {
|
|
288
|
-
return null;
|
|
289
|
-
}
|
|
290
|
-
return {
|
|
291
|
-
id: message.messageId,
|
|
292
|
-
kind: "message",
|
|
293
|
-
role: "user",
|
|
294
|
-
text: content.text,
|
|
295
|
-
attachments: content.attachments,
|
|
296
|
-
authorName: message.senderName,
|
|
297
|
-
createdAt
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
if (isTypedMessage(message, import_meshagent_agents.TurnStartAccepted) || isTypedMessage(message, import_meshagent_agents.TurnSteerAccepted)) {
|
|
301
|
-
const content = inputContent(message);
|
|
302
|
-
if (content.text.trim() === "" && content.attachments.length === 0) {
|
|
303
|
-
return null;
|
|
304
|
-
}
|
|
305
|
-
return {
|
|
306
|
-
id: message.sourceMessageId,
|
|
307
|
-
kind: "message",
|
|
308
|
-
role: "user",
|
|
309
|
-
text: content.text,
|
|
310
|
-
attachments: content.attachments,
|
|
311
|
-
authorName: message.senderName,
|
|
312
|
-
createdAt
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
return null;
|
|
316
|
-
}
|
|
317
|
-
function pendingItemFromInput(pending) {
|
|
318
|
-
const item = inputItemFromMessage(pending.payload, pending.createdAt);
|
|
319
|
-
if (item === null) {
|
|
320
|
-
return null;
|
|
321
|
-
}
|
|
322
|
-
return { ...item, id: pending.messageId };
|
|
323
|
-
}
|
|
324
|
-
function upsertItem(items, item) {
|
|
325
|
-
items.set(item.id, { ...items.get(item.id), ...item });
|
|
326
|
-
}
|
|
327
|
-
function appendText(items, itemId, base, text) {
|
|
328
|
-
if (text === "") {
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
const existing = items.get(itemId);
|
|
332
|
-
upsertItem(items, {
|
|
333
|
-
...base,
|
|
334
|
-
id: itemId,
|
|
335
|
-
text: `${existing?.text ?? ""}${text}`,
|
|
336
|
-
attachments: existing?.attachments ?? []
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
function imageStatus(message) {
|
|
340
|
-
if (isTypedMessage(message, import_meshagent_agents.AgentImageGenerationCompleted)) {
|
|
341
|
-
return "completed";
|
|
342
|
-
}
|
|
343
|
-
if (isTypedMessage(message, import_meshagent_agents.AgentImageGenerationFailed)) {
|
|
344
|
-
return "failed";
|
|
345
|
-
}
|
|
346
|
-
return "in_progress";
|
|
347
|
-
}
|
|
348
|
-
function agentErrorIsCancellation(error) {
|
|
349
|
-
const values = [error.code, error.message].filter((value) => typeof value === "string");
|
|
350
|
-
return values.some((value) => {
|
|
351
|
-
const normalized = value.trim().toLowerCase();
|
|
352
|
-
return normalized.includes("cancel") || normalized.includes("interrupt") || normalized.includes("abort");
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
function toolCallLabel(message) {
|
|
356
|
-
return [message.toolkit, message.tool].filter((part) => part?.trim()).join(".") || "Tool call";
|
|
357
|
-
}
|
|
358
|
-
function toolArgumentString(argumentsValue, keys) {
|
|
359
|
-
if (argumentsValue == null) {
|
|
360
|
-
return void 0;
|
|
361
|
-
}
|
|
362
|
-
for (const key of keys) {
|
|
363
|
-
const value = argumentsValue[key];
|
|
364
|
-
if (typeof value === "string" && value.trim() !== "") {
|
|
365
|
-
return value.trim();
|
|
366
|
-
}
|
|
367
|
-
if (Array.isArray(value) && value.every((item) => typeof item === "string")) {
|
|
368
|
-
const joined = value.join(" ").trim();
|
|
369
|
-
if (joined !== "") {
|
|
370
|
-
return joined;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
return void 0;
|
|
375
|
-
}
|
|
376
|
-
function toolCommandText(message) {
|
|
377
|
-
return toolArgumentString(message.arguments, ["command", "cmd", "script", "input", "query"]);
|
|
378
|
-
}
|
|
379
|
-
function contentText(value) {
|
|
380
|
-
if (typeof value === "string" && value.trim() !== "") {
|
|
381
|
-
return value.trim();
|
|
382
|
-
}
|
|
383
|
-
if (value == null || typeof value !== "object") {
|
|
384
|
-
return void 0;
|
|
385
|
-
}
|
|
386
|
-
const obj = value;
|
|
387
|
-
for (const key of ["text", "result", "output", "stdout", "stderr"]) {
|
|
388
|
-
const candidate = obj[key];
|
|
389
|
-
if (typeof candidate === "string" && candidate.trim() !== "") {
|
|
390
|
-
return candidate.trim();
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
const json = obj["json"];
|
|
394
|
-
if (json != null) {
|
|
395
|
-
return JSON.stringify(json, null, 2);
|
|
396
|
-
}
|
|
397
|
-
return void 0;
|
|
398
|
-
}
|
|
399
|
-
function shellOutputFields(message) {
|
|
400
|
-
const result = message.result;
|
|
401
|
-
const resultObject = result != null && typeof result === "object" ? result : void 0;
|
|
402
|
-
return {
|
|
403
|
-
result: contentText(result),
|
|
404
|
-
stdout: resultObject == null ? void 0 : contentText(resultObject["stdout"]),
|
|
405
|
-
stderr: message.error?.message.trim() || (resultObject == null ? void 0 : contentText(resultObject["stderr"]))
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
function formatJsonValue(value) {
|
|
409
|
-
if (value == null) {
|
|
410
|
-
return void 0;
|
|
411
|
-
}
|
|
412
|
-
try {
|
|
413
|
-
return JSON.stringify(value, null, 2);
|
|
414
|
-
} catch {
|
|
415
|
-
return void 0;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
function toolArgumentsText(argumentsValue) {
|
|
419
|
-
return argumentsValue == null ? void 0 : formatJsonValue(argumentsValue);
|
|
420
|
-
}
|
|
421
|
-
function appendToolArgumentsDelta(existing, delta) {
|
|
422
|
-
if (delta.trim() === "") {
|
|
423
|
-
return existing?.argumentsText;
|
|
424
|
-
}
|
|
425
|
-
return `${existing?.argumentsText ?? ""}${delta}`;
|
|
426
|
-
}
|
|
427
|
-
function formatToolLogLine(line) {
|
|
428
|
-
const text = line.text.trim();
|
|
429
|
-
if (text === "") {
|
|
430
|
-
return null;
|
|
431
|
-
}
|
|
432
|
-
const source = line.source.trim();
|
|
433
|
-
return source === "" ? text : `${source}: ${text}`;
|
|
434
|
-
}
|
|
435
|
-
function appendToolLogs(existing, lines) {
|
|
436
|
-
const logs = [...existing?.logs ?? []];
|
|
437
|
-
for (const line of lines) {
|
|
438
|
-
const formatted = formatToolLogLine(line);
|
|
439
|
-
if (formatted !== null) {
|
|
440
|
-
logs.push(formatted);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
return logs;
|
|
444
|
-
}
|
|
445
|
-
function toolCallState(message) {
|
|
446
|
-
if (isTypedMessage(message, import_meshagent_agents.AgentToolCallEnded)) {
|
|
447
|
-
return message.error == null ? "completed" : "failed";
|
|
448
|
-
}
|
|
449
|
-
if (isTypedMessage(message, import_meshagent_agents.AgentToolCallPending)) {
|
|
450
|
-
return "queued";
|
|
451
|
-
}
|
|
452
|
-
return "in_progress";
|
|
453
|
-
}
|
|
454
|
-
function toolCallHeadline(message) {
|
|
455
|
-
const label = toolCallLabel(message);
|
|
456
|
-
if (toolCallFailed(message)) {
|
|
457
|
-
return `Failed ${label}`;
|
|
458
|
-
}
|
|
459
|
-
if (isTypedMessage(message, import_meshagent_agents.AgentToolCallPending)) {
|
|
460
|
-
return `Preparing ${label}`;
|
|
461
|
-
}
|
|
462
|
-
if (isTypedMessage(message, import_meshagent_agents.AgentToolCallEnded)) {
|
|
463
|
-
return `Ran ${label}`;
|
|
464
|
-
}
|
|
465
|
-
return `Running ${label}`;
|
|
466
|
-
}
|
|
467
|
-
function modelChangedText(message) {
|
|
468
|
-
const model = [message.provider, message.model].filter((part) => part.trim() !== "").join(" / ");
|
|
469
|
-
const voice = message.voice?.trim();
|
|
470
|
-
return voice ? `Model changed to ${model} (${voice})` : `Model changed to ${model}`;
|
|
471
|
-
}
|
|
472
|
-
function rejectionText(message, fallback) {
|
|
473
|
-
const error = message.error?.message.trim();
|
|
474
|
-
return error ? `${fallback}: ${error}` : fallback;
|
|
475
|
-
}
|
|
476
|
-
function lifecycleEventItem(message, createdAt) {
|
|
477
|
-
const turnId = stringValue(message.turnId);
|
|
478
|
-
const base = {
|
|
479
|
-
id: ["event", message.type, turnId ?? message.sourceMessageId ?? message.messageId].join(":"),
|
|
480
|
-
kind: "event",
|
|
481
|
-
role: "agent",
|
|
482
|
-
attachments: [],
|
|
483
|
-
createdAt,
|
|
484
|
-
turnId
|
|
485
|
-
};
|
|
486
|
-
if (isTypedMessage(message, import_meshagent_agents.TurnStartAccepted)) {
|
|
487
|
-
return { ...base, text: "Turn accepted", state: "queued" };
|
|
488
|
-
}
|
|
489
|
-
if (isTypedMessage(message, import_meshagent_agents.TurnStarted)) {
|
|
490
|
-
return { ...base, text: "Turn started", state: "running" };
|
|
491
|
-
}
|
|
492
|
-
if (isTypedMessage(message, import_meshagent_agents.TurnStartRejected)) {
|
|
493
|
-
return { ...base, text: rejectionText(message, "Turn rejected"), state: "failed", failed: true };
|
|
494
|
-
}
|
|
495
|
-
if (isTypedMessage(message, import_meshagent_agents.TurnSteerAccepted)) {
|
|
496
|
-
return { ...base, text: "Steer accepted", state: "queued" };
|
|
497
|
-
}
|
|
498
|
-
if (isTypedMessage(message, import_meshagent_agents.TurnSteered)) {
|
|
499
|
-
return { ...base, text: "Turn steered", state: "running" };
|
|
500
|
-
}
|
|
501
|
-
if (isTypedMessage(message, import_meshagent_agents.TurnSteerRejected)) {
|
|
502
|
-
return { ...base, text: rejectionText(message, "Steer rejected"), state: "failed", failed: true };
|
|
503
|
-
}
|
|
504
|
-
if (isTypedMessage(message, import_meshagent_agents.TurnInterruptAccepted)) {
|
|
505
|
-
return { ...base, text: "Interrupt accepted", state: "cancelled" };
|
|
506
|
-
}
|
|
507
|
-
if (isTypedMessage(message, import_meshagent_agents.TurnInterrupted)) {
|
|
508
|
-
return { ...base, text: "Turn interrupted", state: "cancelled" };
|
|
509
|
-
}
|
|
510
|
-
return null;
|
|
127
|
+
return hours < 24 ? String(hours) + "h" : String(Math.floor(hours / 24)) + "d";
|
|
511
128
|
}
|
|
512
129
|
function isShellTool(message) {
|
|
513
130
|
const values = [message.toolkit, message.tool].filter((value) => typeof value === "string").map((value) => value.trim().toLowerCase());
|
|
514
|
-
return
|
|
515
|
-
}
|
|
516
|
-
function toolCallFailed(message) {
|
|
517
|
-
return isTypedMessage(message, import_meshagent_agents.AgentToolCallEnded) && message.error != null;
|
|
518
|
-
}
|
|
519
|
-
function turnEndedErrorItem(message, createdAt) {
|
|
520
|
-
const error = message.error;
|
|
521
|
-
if (error == null || agentErrorIsCancellation(error)) {
|
|
522
|
-
return null;
|
|
523
|
-
}
|
|
524
|
-
const text = error.message.trim();
|
|
525
|
-
if (text === "") {
|
|
526
|
-
return null;
|
|
527
|
-
}
|
|
528
|
-
const turnId = stringValue(message.turnId);
|
|
529
|
-
return {
|
|
530
|
-
id: ["turn-error", turnId ?? message.messageId].join(":"),
|
|
531
|
-
kind: "error",
|
|
532
|
-
role: "agent",
|
|
533
|
-
text,
|
|
534
|
-
attachments: [],
|
|
535
|
-
createdAt,
|
|
536
|
-
turnId
|
|
537
|
-
};
|
|
538
|
-
}
|
|
539
|
-
function feedFromSession(session) {
|
|
540
|
-
if (session === null) {
|
|
541
|
-
return [];
|
|
542
|
-
}
|
|
543
|
-
const items = /* @__PURE__ */ new Map();
|
|
544
|
-
for (const event of session.messages) {
|
|
545
|
-
const message = event.message;
|
|
546
|
-
const createdAt = event.createdAt;
|
|
547
|
-
const inputItem = inputItemFromMessage(message, createdAt);
|
|
548
|
-
if (inputItem !== null && !items.has(inputItem.id)) {
|
|
549
|
-
upsertItem(items, inputItem);
|
|
550
|
-
continue;
|
|
551
|
-
}
|
|
552
|
-
const lifecycleItem = lifecycleEventItem(message, createdAt);
|
|
553
|
-
if (lifecycleItem !== null) {
|
|
554
|
-
upsertItem(items, lifecycleItem);
|
|
555
|
-
continue;
|
|
556
|
-
}
|
|
557
|
-
if (isTypedMessage(message, import_meshagent_agents.AgentModelChanged)) {
|
|
558
|
-
upsertItem(items, {
|
|
559
|
-
id: ["model", message.messageId].join(":"),
|
|
560
|
-
kind: "event",
|
|
561
|
-
role: "agent",
|
|
562
|
-
text: modelChangedText(message),
|
|
563
|
-
attachments: [],
|
|
564
|
-
createdAt,
|
|
565
|
-
state: "completed"
|
|
566
|
-
});
|
|
567
|
-
continue;
|
|
568
|
-
}
|
|
569
|
-
if (isTypedMessage(message, import_meshagent_agents.AgentTextContentStarted)) {
|
|
570
|
-
upsertItem(items, {
|
|
571
|
-
id: message.itemId,
|
|
572
|
-
kind: "message",
|
|
573
|
-
role: "agent",
|
|
574
|
-
text: "",
|
|
575
|
-
attachments: [],
|
|
576
|
-
createdAt,
|
|
577
|
-
phase: message.phase,
|
|
578
|
-
turnId: message.turnId
|
|
579
|
-
});
|
|
580
|
-
} else if (isTypedMessage(message, import_meshagent_agents.AgentTextContentDelta)) {
|
|
581
|
-
appendText(items, message.itemId, {
|
|
582
|
-
id: message.itemId,
|
|
583
|
-
kind: "message",
|
|
584
|
-
role: "agent",
|
|
585
|
-
createdAt,
|
|
586
|
-
phase: message.phase,
|
|
587
|
-
turnId: message.turnId
|
|
588
|
-
}, message.text);
|
|
589
|
-
} else if (isTypedMessage(message, import_meshagent_agents.AgentTextContentEnded)) {
|
|
590
|
-
if (!items.has(message.itemId)) {
|
|
591
|
-
upsertItem(items, {
|
|
592
|
-
id: message.itemId,
|
|
593
|
-
kind: "message",
|
|
594
|
-
role: "agent",
|
|
595
|
-
text: "",
|
|
596
|
-
attachments: [],
|
|
597
|
-
createdAt,
|
|
598
|
-
phase: message.phase,
|
|
599
|
-
turnId: message.turnId
|
|
600
|
-
});
|
|
601
|
-
}
|
|
602
|
-
} else if (isTypedMessage(message, import_meshagent_agents.AgentReasoningContentStarted)) {
|
|
603
|
-
upsertItem(items, {
|
|
604
|
-
id: message.itemId,
|
|
605
|
-
kind: "reasoning",
|
|
606
|
-
role: "agent",
|
|
607
|
-
text: "",
|
|
608
|
-
attachments: [],
|
|
609
|
-
createdAt,
|
|
610
|
-
turnId: message.turnId
|
|
611
|
-
});
|
|
612
|
-
} else if (isTypedMessage(message, import_meshagent_agents.AgentReasoningContentDelta)) {
|
|
613
|
-
appendText(items, message.itemId, {
|
|
614
|
-
id: message.itemId,
|
|
615
|
-
kind: "reasoning",
|
|
616
|
-
role: "agent",
|
|
617
|
-
createdAt,
|
|
618
|
-
turnId: message.turnId
|
|
619
|
-
}, message.text);
|
|
620
|
-
} else if (isTypedMessage(message, import_meshagent_agents.AgentReasoningContentEnded)) {
|
|
621
|
-
if (!items.has(message.itemId)) {
|
|
622
|
-
upsertItem(items, {
|
|
623
|
-
id: message.itemId,
|
|
624
|
-
kind: "reasoning",
|
|
625
|
-
role: "agent",
|
|
626
|
-
text: "",
|
|
627
|
-
attachments: [],
|
|
628
|
-
createdAt,
|
|
629
|
-
turnId: message.turnId
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
} else if (isTypedMessage(message, import_meshagent_agents.AgentFileContentStarted) || isTypedMessage(message, import_meshagent_agents.AgentFileContentDelta) || isTypedMessage(message, import_meshagent_agents.AgentFileContentEnded)) {
|
|
633
|
-
const existing = items.get(message.itemId);
|
|
634
|
-
const attachments = [...existing?.attachments ?? []];
|
|
635
|
-
if (isTypedMessage(message, import_meshagent_agents.AgentFileContentDelta) && !attachments.includes(message.url)) {
|
|
636
|
-
attachments.push(message.url);
|
|
637
|
-
}
|
|
638
|
-
upsertItem(items, {
|
|
639
|
-
id: message.itemId,
|
|
640
|
-
kind: "message",
|
|
641
|
-
role: "agent",
|
|
642
|
-
text: existing?.text ?? "",
|
|
643
|
-
attachments,
|
|
644
|
-
createdAt,
|
|
645
|
-
turnId: message.turnId,
|
|
646
|
-
state: isTypedMessage(message, import_meshagent_agents.AgentFileContentEnded) ? "completed" : "in_progress"
|
|
647
|
-
});
|
|
648
|
-
} else if (isTypedMessage(message, import_meshagent_agents.AgentToolCallPending) || isTypedMessage(message, import_meshagent_agents.AgentToolCallInProgress) || isTypedMessage(message, import_meshagent_agents.AgentToolCallStarted) || isTypedMessage(message, import_meshagent_agents.AgentToolCallEnded)) {
|
|
649
|
-
const existing = items.get(message.itemId);
|
|
650
|
-
const command = toolCommandText(message) ?? existing?.command;
|
|
651
|
-
const endedFields = isTypedMessage(message, import_meshagent_agents.AgentToolCallEnded) ? shellOutputFields(message) : {};
|
|
652
|
-
const argumentsText = toolArgumentsText(message.arguments) ?? existing?.argumentsText;
|
|
653
|
-
upsertItem(items, {
|
|
654
|
-
id: message.itemId,
|
|
655
|
-
kind: "tool_call",
|
|
656
|
-
role: "agent",
|
|
657
|
-
text: toolCallHeadline(message),
|
|
658
|
-
attachments: [],
|
|
659
|
-
createdAt,
|
|
660
|
-
turnId: message.turnId,
|
|
661
|
-
toolkit: message.toolkit ?? existing?.toolkit,
|
|
662
|
-
tool: message.tool ?? existing?.tool,
|
|
663
|
-
command,
|
|
664
|
-
argumentsText,
|
|
665
|
-
logs: existing?.logs,
|
|
666
|
-
result: endedFields.result ?? existing?.result,
|
|
667
|
-
stdout: endedFields.stdout ?? existing?.stdout,
|
|
668
|
-
stderr: endedFields.stderr ?? existing?.stderr,
|
|
669
|
-
state: toolCallState(message),
|
|
670
|
-
failed: toolCallFailed(message)
|
|
671
|
-
});
|
|
672
|
-
} else if (isTypedMessage(message, import_meshagent_agents.AgentToolCallArgumentsDelta)) {
|
|
673
|
-
const existing = items.get(message.itemId);
|
|
674
|
-
upsertItem(items, {
|
|
675
|
-
id: message.itemId,
|
|
676
|
-
kind: "tool_call",
|
|
677
|
-
role: "agent",
|
|
678
|
-
text: existing?.text ?? "Running tool",
|
|
679
|
-
attachments: [],
|
|
680
|
-
createdAt,
|
|
681
|
-
turnId: message.turnId,
|
|
682
|
-
toolkit: existing?.toolkit,
|
|
683
|
-
tool: existing?.tool,
|
|
684
|
-
command: existing?.command,
|
|
685
|
-
argumentsText: appendToolArgumentsDelta(existing, message.delta),
|
|
686
|
-
logs: existing?.logs,
|
|
687
|
-
result: existing?.result,
|
|
688
|
-
stdout: existing?.stdout,
|
|
689
|
-
stderr: existing?.stderr,
|
|
690
|
-
state: existing?.state ?? "in_progress",
|
|
691
|
-
failed: existing?.failed
|
|
692
|
-
});
|
|
693
|
-
} else if (isTypedMessage(message, import_meshagent_agents.AgentToolCallLogDelta)) {
|
|
694
|
-
const existing = items.get(message.itemId);
|
|
695
|
-
upsertItem(items, {
|
|
696
|
-
id: message.itemId,
|
|
697
|
-
kind: "tool_call",
|
|
698
|
-
role: "agent",
|
|
699
|
-
text: existing?.text ?? "Running tool",
|
|
700
|
-
attachments: [],
|
|
701
|
-
createdAt,
|
|
702
|
-
turnId: message.turnId,
|
|
703
|
-
toolkit: existing?.toolkit,
|
|
704
|
-
tool: existing?.tool,
|
|
705
|
-
command: existing?.command,
|
|
706
|
-
argumentsText: existing?.argumentsText,
|
|
707
|
-
logs: appendToolLogs(existing, message.lines),
|
|
708
|
-
result: existing?.result,
|
|
709
|
-
stdout: existing?.stdout,
|
|
710
|
-
stderr: existing?.stderr,
|
|
711
|
-
state: existing?.state ?? "in_progress",
|
|
712
|
-
failed: existing?.failed
|
|
713
|
-
});
|
|
714
|
-
} else if (isTypedMessage(message, import_meshagent_agents.AgentClientToolCallRequested)) {
|
|
715
|
-
const argumentsText = toolArgumentsText(message.arguments);
|
|
716
|
-
upsertItem(items, {
|
|
717
|
-
id: message.itemId,
|
|
718
|
-
kind: "tool_call",
|
|
719
|
-
role: "agent",
|
|
720
|
-
text: "Waiting for client tool " + toolCallLabel(message),
|
|
721
|
-
attachments: [],
|
|
722
|
-
createdAt,
|
|
723
|
-
turnId: message.turnId,
|
|
724
|
-
toolkit: message.toolkit,
|
|
725
|
-
tool: message.tool,
|
|
726
|
-
argumentsText,
|
|
727
|
-
state: "queued"
|
|
728
|
-
});
|
|
729
|
-
} else if (isTypedMessage(message, import_meshagent_agents.AgentSecretRequested)) {
|
|
730
|
-
const scope = message.scope?.trim();
|
|
731
|
-
upsertItem(items, {
|
|
732
|
-
id: message.itemId,
|
|
733
|
-
kind: "event",
|
|
734
|
-
role: "agent",
|
|
735
|
-
text: scope ? "Secret requested: " + message.name + " (" + scope + ")" : "Secret requested: " + message.name,
|
|
736
|
-
attachments: [],
|
|
737
|
-
createdAt,
|
|
738
|
-
turnId: message.turnId,
|
|
739
|
-
state: "queued"
|
|
740
|
-
});
|
|
741
|
-
} else if (isTypedMessage(message, import_meshagent_agents.AgentImageGenerationStarted) || isTypedMessage(message, import_meshagent_agents.AgentImageGenerationPartial) || isTypedMessage(message, import_meshagent_agents.AgentImageGenerationCompleted) || isTypedMessage(message, import_meshagent_agents.AgentImageGenerationFailed)) {
|
|
742
|
-
const images = isTypedMessage(message, import_meshagent_agents.AgentImageGenerationCompleted) ? message.images : [];
|
|
743
|
-
const image = isTypedMessage(message, import_meshagent_agents.AgentImageGenerationPartial) ? message.image : images[0];
|
|
744
|
-
upsertItem(items, {
|
|
745
|
-
id: message.itemId,
|
|
746
|
-
kind: "image_generation",
|
|
747
|
-
role: "agent",
|
|
748
|
-
text: "",
|
|
749
|
-
attachments: [],
|
|
750
|
-
createdAt,
|
|
751
|
-
turnId: message.turnId,
|
|
752
|
-
image: {
|
|
753
|
-
uri: image?.uri,
|
|
754
|
-
status: image?.status ?? imageStatus(message),
|
|
755
|
-
statusDetail: isTypedMessage(message, import_meshagent_agents.AgentImageGenerationFailed) ? message.error.message : void 0,
|
|
756
|
-
images
|
|
757
|
-
}
|
|
758
|
-
});
|
|
759
|
-
} else if (isTypedMessage(message, import_meshagent_agents.TurnEnded)) {
|
|
760
|
-
const errorItem = turnEndedErrorItem(message, createdAt);
|
|
761
|
-
if (errorItem !== null) {
|
|
762
|
-
upsertItem(items, errorItem);
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
for (const pending of session.pendingInputs) {
|
|
767
|
-
const item = pendingItemFromInput(pending);
|
|
768
|
-
if (item !== null && !items.has(item.id)) {
|
|
769
|
-
upsertItem(items, item);
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
return [...items.values()].filter((item) => item.text.trim() !== "" || item.attachments.length > 0 || item.image != null || item.kind === "tool_call" || item.kind === "event" || item.kind === "error");
|
|
131
|
+
return values.some((value) => value === "shell" || value === "exec" || value === "local_shell" || value === "local_shell_call" || value.includes("shell") || value.includes("exec"));
|
|
773
132
|
}
|
|
774
133
|
function firstNonEmptyLine(text) {
|
|
775
134
|
for (const line of text.split(/\r?\n/)) {
|
|
@@ -799,8 +158,52 @@ function canRenderAsFinalAnswer(message) {
|
|
|
799
158
|
}
|
|
800
159
|
return message.text.trim() !== "" || message.attachments.length > 0 || message.image != null;
|
|
801
160
|
}
|
|
802
|
-
function
|
|
803
|
-
return message.kind === "
|
|
161
|
+
function isChatFeedWidgetCall(message, chatFeedWidgetsByName) {
|
|
162
|
+
return message.kind === "tool_call" && message.toolkit === "client" && message.tool != null && chatFeedWidgetsByName.has(message.tool);
|
|
163
|
+
}
|
|
164
|
+
function isFollowUpSuggestionCall(message, chatFeedWidgetsByName) {
|
|
165
|
+
if (!isChatFeedWidgetCall(message, chatFeedWidgetsByName) || message.tool == null) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
return chatFeedWidgetsByName.get(message.tool)?.getFollowUpSuggestions != null;
|
|
169
|
+
}
|
|
170
|
+
function latestTurnFollowUpSuggestions(messages, chatFeedWidgetsByName) {
|
|
171
|
+
let latestUserIndex = -1;
|
|
172
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
173
|
+
const message = messages[index];
|
|
174
|
+
if (message.kind === "message" && message.role === "user") {
|
|
175
|
+
latestUserIndex = index;
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (latestUserIndex === -1) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
const latestTurnMessages = messages.slice(latestUserIndex + 1);
|
|
183
|
+
if (!latestTurnMessages.some(canRenderAsFinalAnswer)) {
|
|
184
|
+
return [];
|
|
185
|
+
}
|
|
186
|
+
for (let index = latestTurnMessages.length - 1; index >= 0; index -= 1) {
|
|
187
|
+
const message = latestTurnMessages[index];
|
|
188
|
+
if (message.kind !== "tool_call" || message.state !== "completed" || message.tool == null || !isFollowUpSuggestionCall(message, chatFeedWidgetsByName)) {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const widget = chatFeedWidgetsByName.get(message.tool);
|
|
192
|
+
try {
|
|
193
|
+
return widget?.getFollowUpSuggestions?.({
|
|
194
|
+
status: "completed",
|
|
195
|
+
input: message.input ?? {},
|
|
196
|
+
output: message.output
|
|
197
|
+
}) ?? [];
|
|
198
|
+
} catch (error) {
|
|
199
|
+
console.error("ChatFeedWidget follow-up suggestion extraction failed", error);
|
|
200
|
+
return [];
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
205
|
+
function isIntrinsicDetail(message, chatFeedWidgetsByName) {
|
|
206
|
+
return message.kind === "reasoning" || message.kind === "event" || message.kind === "tool_call" && message.failed !== true && !isChatFeedWidgetCall(message, chatFeedWidgetsByName) || canCollapseAsCommentary(message) && message.phase === "commentary";
|
|
804
207
|
}
|
|
805
208
|
function nextUserMessageIndex(messages, start) {
|
|
806
209
|
for (let index = start; index < messages.length; index += 1) {
|
|
@@ -830,11 +233,11 @@ function finalAgentMessageIndexForSegment(messages, start, end) {
|
|
|
830
233
|
}
|
|
831
234
|
return inferredFinalIndex;
|
|
832
235
|
}
|
|
833
|
-
function addDetailIndexesForSegment(messages, start, end, detailIndexes) {
|
|
236
|
+
function addDetailIndexesForSegment(messages, start, end, detailIndexes, chatFeedWidgetsByName) {
|
|
834
237
|
const finalAgentMessageIndex = finalAgentMessageIndexForSegment(messages, start, end);
|
|
835
238
|
for (let index = start; index < end; index += 1) {
|
|
836
239
|
const message = messages[index];
|
|
837
|
-
if (isIntrinsicDetail(message)) {
|
|
240
|
+
if (isIntrinsicDetail(message, chatFeedWidgetsByName)) {
|
|
838
241
|
detailIndexes.add(index);
|
|
839
242
|
continue;
|
|
840
243
|
}
|
|
@@ -903,13 +306,13 @@ function detailGroupForMessages(messages, nextMessage, expandedIds, localPartici
|
|
|
903
306
|
expanded: expandedIds.has(id)
|
|
904
307
|
};
|
|
905
308
|
}
|
|
906
|
-
function
|
|
309
|
+
function groupThreadItems(messages, expandedIds, localParticipantName, agentName, chatFeedWidgetsByName) {
|
|
907
310
|
const items = [];
|
|
908
311
|
let index = 0;
|
|
909
312
|
while (index < messages.length) {
|
|
910
313
|
const segmentEnd = nextUserMessageIndex(messages, index + 1) ?? messages.length;
|
|
911
314
|
const detailIndexes = /* @__PURE__ */ new Set();
|
|
912
|
-
addDetailIndexesForSegment(messages, index, segmentEnd, detailIndexes);
|
|
315
|
+
addDetailIndexesForSegment(messages, index, segmentEnd, detailIndexes, chatFeedWidgetsByName);
|
|
913
316
|
const groupedMessages = [...detailIndexes].sort((left, right) => left - right).map((detailIndex) => messages[detailIndex]);
|
|
914
317
|
let insertedDetailGroup = false;
|
|
915
318
|
for (let segmentIndex = index; segmentIndex < segmentEnd; segmentIndex += 1) {
|
|
@@ -933,7 +336,7 @@ function threadFeedItems(messages, expandedIds, localParticipantName, agentName)
|
|
|
933
336
|
}
|
|
934
337
|
return items;
|
|
935
338
|
}
|
|
936
|
-
function
|
|
339
|
+
function previousMessageItem(items, index) {
|
|
937
340
|
for (let cursor = index - 1; cursor >= 0; cursor -= 1) {
|
|
938
341
|
const item = items[cursor];
|
|
939
342
|
if (item.kind !== "detail_group") {
|
|
@@ -942,32 +345,6 @@ function previousMessageFeedItem(items, index) {
|
|
|
942
345
|
}
|
|
943
346
|
return null;
|
|
944
347
|
}
|
|
945
|
-
function latestThreadStatus(session) {
|
|
946
|
-
if (session === null) {
|
|
947
|
-
return null;
|
|
948
|
-
}
|
|
949
|
-
const status = session.threadStatus;
|
|
950
|
-
if (status !== void 0 && isTypedMessage(status, import_meshagent_agents.AgentThreadStatus)) {
|
|
951
|
-
return status;
|
|
952
|
-
}
|
|
953
|
-
return null;
|
|
954
|
-
}
|
|
955
|
-
function latestUsageSnapshot(session) {
|
|
956
|
-
if (session === null) {
|
|
957
|
-
return null;
|
|
958
|
-
}
|
|
959
|
-
let usage = null;
|
|
960
|
-
for (const event of session.messages) {
|
|
961
|
-
const next = AgentUsageSnapshot.fromMessage(event.message);
|
|
962
|
-
if (next === null) {
|
|
963
|
-
continue;
|
|
964
|
-
}
|
|
965
|
-
if (shouldReplaceAgentUsageSnapshot(usage, next)) {
|
|
966
|
-
usage = next;
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
return usage;
|
|
970
|
-
}
|
|
971
348
|
function formatAgentUsageTokenCount(value) {
|
|
972
349
|
const magnitude = Math.abs(value);
|
|
973
350
|
if (magnitude >= 1e6) {
|
|
@@ -1294,7 +671,8 @@ function ExpandedDetailGroup({
|
|
|
1294
671
|
room,
|
|
1295
672
|
item,
|
|
1296
673
|
localParticipantName,
|
|
1297
|
-
agentName
|
|
674
|
+
agentName,
|
|
675
|
+
chatFeedWidgetsByName
|
|
1298
676
|
}) {
|
|
1299
677
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-3", children: [
|
|
1300
678
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex w-full justify-start", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "max-w-[85%] px-1 text-left sm:max-w-2xl", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground", children: [
|
|
@@ -1309,6 +687,7 @@ function ExpandedDetailGroup({
|
|
|
1309
687
|
previous: index > 0 ? item.messages[index - 1] : null,
|
|
1310
688
|
localParticipantName,
|
|
1311
689
|
agentName,
|
|
690
|
+
chatFeedWidgetsByName,
|
|
1312
691
|
forceHideHeader: true
|
|
1313
692
|
},
|
|
1314
693
|
message.id
|
|
@@ -1353,6 +732,7 @@ function ThreadMessageView({
|
|
|
1353
732
|
previous,
|
|
1354
733
|
localParticipantName,
|
|
1355
734
|
agentName,
|
|
735
|
+
chatFeedWidgetsByName,
|
|
1356
736
|
forceHideHeader = false
|
|
1357
737
|
}) {
|
|
1358
738
|
if (message.kind === "error") {
|
|
@@ -1380,6 +760,23 @@ function ThreadMessageView({
|
|
|
1380
760
|
}
|
|
1381
761
|
);
|
|
1382
762
|
}
|
|
763
|
+
const widget = message.toolkit === "client" && message.tool != null ? chatFeedWidgetsByName.get(message.tool) : void 0;
|
|
764
|
+
if (widget != null) {
|
|
765
|
+
const status = message.failed === true || message.state === "failed" ? "failed" : message.state === "completed" ? "completed" : message.state === "in_progress" ? "in_progress" : "queued";
|
|
766
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
767
|
+
import_chat_feed_widget_view.ChatFeedWidgetView,
|
|
768
|
+
{
|
|
769
|
+
widget,
|
|
770
|
+
toolCall: {
|
|
771
|
+
status,
|
|
772
|
+
input: message.input ?? {},
|
|
773
|
+
output: message.output
|
|
774
|
+
},
|
|
775
|
+
fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToolCallLine, { message })
|
|
776
|
+
},
|
|
777
|
+
[message.id, status].join(":")
|
|
778
|
+
);
|
|
779
|
+
}
|
|
1383
780
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToolCallLine, { message });
|
|
1384
781
|
}
|
|
1385
782
|
const mine = message.role === "user";
|
|
@@ -1405,8 +802,14 @@ function EmptyState({ title, description }) {
|
|
|
1405
802
|
function LoadingState() {
|
|
1406
803
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "h-full mx-auto flex max-w-2xl flex-col items-center justify-center px-6 py-20 text-muted-foreground", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_spinner.Spinner, { size: "lg" }) });
|
|
1407
804
|
}
|
|
1408
|
-
function ErrorBanner({
|
|
1409
|
-
|
|
805
|
+
function ErrorBanner({
|
|
806
|
+
message,
|
|
807
|
+
onRetry
|
|
808
|
+
}) {
|
|
809
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "mx-auto flex w-full max-w-[912px] items-center justify-between gap-3 whitespace-pre-wrap rounded-md border border-destructive/30 bg-destructive/5 px-4 py-3 text-sm text-destructive", children: [
|
|
810
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: message }),
|
|
811
|
+
onRetry ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.Button, { type: "button", variant: "outline", size: "sm", onClick: onRetry, children: "Retry restore" }) : null
|
|
812
|
+
] });
|
|
1410
813
|
}
|
|
1411
814
|
function describeError(error) {
|
|
1412
815
|
if (error instanceof Error && error.message.trim() !== "") {
|
|
@@ -1414,6 +817,11 @@ function describeError(error) {
|
|
|
1414
817
|
}
|
|
1415
818
|
return String(error);
|
|
1416
819
|
}
|
|
820
|
+
function hasAgentParticipantWaiter(chatClient) {
|
|
821
|
+
return "waitForAgentParticipant" in chatClient && typeof chatClient.waitForAgentParticipant === "function";
|
|
822
|
+
}
|
|
823
|
+
const persistedEventsParticipantWaitTimeoutMs = 3e4;
|
|
824
|
+
const threadLoadTimeoutMs = 3e4;
|
|
1417
825
|
function normalizeAgentAttachmentUrl(path) {
|
|
1418
826
|
const trimmedPath = path.trim();
|
|
1419
827
|
if (trimmedPath === "") {
|
|
@@ -1429,6 +837,100 @@ function normalizeAgentAttachmentUrl(path) {
|
|
|
1429
837
|
const roomPath = trimmedPath.startsWith("/") ? trimmedPath.slice(1) : trimmedPath;
|
|
1430
838
|
return roomPath === "" ? null : `room:///${roomPath}`;
|
|
1431
839
|
}
|
|
840
|
+
const handledChatFeedWidgetRequests = /* @__PURE__ */ new WeakMap();
|
|
841
|
+
const initializedChatFeedWidgetSessions = /* @__PURE__ */ new WeakSet();
|
|
842
|
+
const replayingChatFeedWidgetSessions = /* @__PURE__ */ new WeakSet();
|
|
843
|
+
function handledRequestsForSession(session) {
|
|
844
|
+
const existing = handledChatFeedWidgetRequests.get(session);
|
|
845
|
+
if (existing != null) {
|
|
846
|
+
return existing;
|
|
847
|
+
}
|
|
848
|
+
const created = /* @__PURE__ */ new Set();
|
|
849
|
+
handledChatFeedWidgetRequests.set(session, created);
|
|
850
|
+
return created;
|
|
851
|
+
}
|
|
852
|
+
function chatFeedWidgetCallKey(threadPath, itemId) {
|
|
853
|
+
return [threadPath, itemId].join("\0");
|
|
854
|
+
}
|
|
855
|
+
function processChatFeedWidgetRequests({
|
|
856
|
+
session,
|
|
857
|
+
widgetsByName,
|
|
858
|
+
updateCall,
|
|
859
|
+
executeRequests
|
|
860
|
+
}) {
|
|
861
|
+
if (widgetsByName.size === 0) {
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
const requests = session.messages.map((event) => event.message).filter((message) => message instanceof import_meshagent_agents.AgentClientToolCallRequested).filter((message) => message.toolkit === "client" && widgetsByName.has(message.tool));
|
|
865
|
+
const handledRequests = handledRequestsForSession(session);
|
|
866
|
+
if (!initializedChatFeedWidgetSessions.has(session)) {
|
|
867
|
+
initializedChatFeedWidgetSessions.add(session);
|
|
868
|
+
if (session.isLoading || session.loadState.requestMessageId != null) {
|
|
869
|
+
replayingChatFeedWidgetSessions.add(session);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
if (!executeRequests) {
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
875
|
+
if (replayingChatFeedWidgetSessions.has(session)) {
|
|
876
|
+
if (session.isLoading) {
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
replayingChatFeedWidgetSessions.delete(session);
|
|
880
|
+
const completedItemIds = new Set(session.messages.map((event) => event.message).filter((message) => message instanceof import_meshagent_agents.AgentToolCallEnded && message.toolkit === "client").map((message) => message.itemId));
|
|
881
|
+
for (const request of requests) {
|
|
882
|
+
if (completedItemIds.has(request.requestId)) {
|
|
883
|
+
handledRequests.add(request.requestId);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
for (const request of requests) {
|
|
888
|
+
if (handledRequests.has(request.requestId)) {
|
|
889
|
+
continue;
|
|
890
|
+
}
|
|
891
|
+
const widget = widgetsByName.get(request.tool);
|
|
892
|
+
if (widget == null) {
|
|
893
|
+
continue;
|
|
894
|
+
}
|
|
895
|
+
if (!session.claimClientToolCall(request.requestId)) {
|
|
896
|
+
handledRequests.add(request.requestId);
|
|
897
|
+
continue;
|
|
898
|
+
}
|
|
899
|
+
handledRequests.add(request.requestId);
|
|
900
|
+
updateCall(chatFeedWidgetCallKey(session.threadPath, request.requestId), {
|
|
901
|
+
status: "in_progress"
|
|
902
|
+
});
|
|
903
|
+
void (async () => {
|
|
904
|
+
let response;
|
|
905
|
+
let status;
|
|
906
|
+
try {
|
|
907
|
+
response = await widget.execute(request.arguments);
|
|
908
|
+
status = response instanceof import_meshagent.ErrorContent ? "failed" : "completed";
|
|
909
|
+
} catch (error) {
|
|
910
|
+
response = new import_meshagent.ErrorContent({ text: describeError(error) });
|
|
911
|
+
status = "failed";
|
|
912
|
+
}
|
|
913
|
+
updateCall(chatFeedWidgetCallKey(session.threadPath, request.requestId), {
|
|
914
|
+
status,
|
|
915
|
+
output: response
|
|
916
|
+
});
|
|
917
|
+
try {
|
|
918
|
+
await session.respondToClientToolCall({
|
|
919
|
+
turnId: request.turnId,
|
|
920
|
+
requestId: request.requestId,
|
|
921
|
+
response
|
|
922
|
+
});
|
|
923
|
+
session.finishClientToolCall(request.requestId, { responseSent: true });
|
|
924
|
+
} catch (error) {
|
|
925
|
+
session.finishClientToolCall(request.requestId, { responseSent: false });
|
|
926
|
+
updateCall(chatFeedWidgetCallKey(session.threadPath, request.requestId), {
|
|
927
|
+
status: "failed",
|
|
928
|
+
output: new import_meshagent.ErrorContent({ text: describeError(error) })
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
})();
|
|
932
|
+
}
|
|
933
|
+
}
|
|
1432
934
|
function AgentThread({
|
|
1433
935
|
room,
|
|
1434
936
|
path,
|
|
@@ -1438,24 +940,65 @@ function AgentThread({
|
|
|
1438
940
|
emptyStateTitle = "Chat to get started",
|
|
1439
941
|
emptyStateDescription,
|
|
1440
942
|
clientToolkits,
|
|
1441
|
-
|
|
1442
|
-
collapseMessages = true
|
|
943
|
+
chatFeedWidgets,
|
|
944
|
+
collapseMessages = true,
|
|
945
|
+
suggestions,
|
|
946
|
+
enableFileUpload = false,
|
|
947
|
+
persistedEvents,
|
|
948
|
+
deferLiveEvents = false,
|
|
949
|
+
loadThread = true,
|
|
950
|
+
injectPersistedEvents = false,
|
|
951
|
+
composerDisabled: composerDisabledProp = false,
|
|
952
|
+
closeThreadOnUnmount = false,
|
|
953
|
+
onPersistedEventsInjectionStarted,
|
|
954
|
+
onPersistedEventsInjected,
|
|
955
|
+
onEventsChanged
|
|
1443
956
|
}) {
|
|
1444
957
|
const [attachments, setAttachments] = (0, import_react.useState)([]);
|
|
1445
958
|
const [sendError, setSendError] = (0, import_react.useState)(null);
|
|
959
|
+
const [restorationError, setRestorationError] = (0, import_react.useState)(null);
|
|
960
|
+
const [restorationAttempt, setRestorationAttempt] = (0, import_react.useState)(0);
|
|
1446
961
|
const [version, setVersion] = (0, import_react.useState)(0);
|
|
1447
962
|
const [expandedDetailGroupIds, setExpandedDetailGroupIds] = (0, import_react.useState)(() => /* @__PURE__ */ new Set());
|
|
1448
|
-
const
|
|
1449
|
-
const contentRef = (0, import_react.useRef)(null);
|
|
1450
|
-
const stickToBottomRef = (0, import_react.useRef)(true);
|
|
963
|
+
const [chatFeedWidgetCallOverrides, setChatFeedWidgetCallOverrides] = (0, import_react.useState)(() => /* @__PURE__ */ new Map());
|
|
1451
964
|
const sessionRef = (0, import_react.useRef)(null);
|
|
965
|
+
const mountedRef = (0, import_react.useRef)(true);
|
|
966
|
+
const persistedEventsRef = (0, import_react.useRef)(persistedEvents);
|
|
967
|
+
persistedEventsRef.current = persistedEvents;
|
|
968
|
+
const restoredPathRef = (0, import_react.useRef)(null);
|
|
969
|
+
const restorationReadyRef = (0, import_react.useRef)(!injectPersistedEvents);
|
|
970
|
+
const pendingCloseRef = (0, import_react.useRef)(null);
|
|
1452
971
|
const ownsChatClient = chatClient == null;
|
|
1453
972
|
const activeChatClient = (0, import_react.useMemo)(
|
|
1454
973
|
() => chatClient ?? new import_meshagent_agents.MessagingChatClient({ room, agentName }),
|
|
1455
974
|
[agentName, chatClient, room]
|
|
1456
975
|
);
|
|
976
|
+
const resolvedClientToolkits = (0, import_react.useMemo)(
|
|
977
|
+
() => (0, import_chat_feed_widget.resolveClientToolkitDescriptions)(clientToolkits, chatFeedWidgets),
|
|
978
|
+
[chatFeedWidgets, clientToolkits]
|
|
979
|
+
);
|
|
980
|
+
const chatFeedWidgetsByName = (0, import_react.useMemo)(
|
|
981
|
+
() => new Map((chatFeedWidgets ?? []).map((widget) => [widget.name, widget])),
|
|
982
|
+
[chatFeedWidgets]
|
|
983
|
+
);
|
|
984
|
+
const updateChatFeedWidgetCall = (0, import_react.useCallback)((callKey, override) => {
|
|
985
|
+
if (!mountedRef.current) {
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
setChatFeedWidgetCallOverrides((current) => {
|
|
989
|
+
const next = new Map(current);
|
|
990
|
+
next.set(callKey, override);
|
|
991
|
+
return next;
|
|
992
|
+
});
|
|
993
|
+
}, []);
|
|
1457
994
|
const localParticipantName = getParticipantName(room.localParticipant);
|
|
1458
995
|
const agentParticipant = activeChatClient.agentParticipant() ?? findAgentParticipant(room, agentName);
|
|
996
|
+
(0, import_react.useEffect)(() => {
|
|
997
|
+
mountedRef.current = true;
|
|
998
|
+
return () => {
|
|
999
|
+
mountedRef.current = false;
|
|
1000
|
+
};
|
|
1001
|
+
}, []);
|
|
1459
1002
|
(0, import_react.useEffect)(() => {
|
|
1460
1003
|
void activeChatClient.start();
|
|
1461
1004
|
const handleChange = () => {
|
|
@@ -1470,63 +1013,262 @@ function AgentThread({
|
|
|
1470
1013
|
};
|
|
1471
1014
|
}, [activeChatClient, disposeChatClient, ownsChatClient]);
|
|
1472
1015
|
(0, import_react.useEffect)(() => {
|
|
1473
|
-
|
|
1016
|
+
restorationReadyRef.current = !loadThread && (!injectPersistedEvents || restoredPathRef.current === path);
|
|
1017
|
+
const session2 = activeChatClient.openThread(path, {
|
|
1018
|
+
load: loadThread,
|
|
1019
|
+
reloadIfOpen: loadThread && restorationAttempt > 0
|
|
1020
|
+
});
|
|
1021
|
+
if (pendingCloseRef.current?.session === session2) {
|
|
1022
|
+
clearTimeout(pendingCloseRef.current.timer);
|
|
1023
|
+
pendingCloseRef.current = null;
|
|
1024
|
+
}
|
|
1474
1025
|
sessionRef.current = session2;
|
|
1026
|
+
let threadLoadTimeout = null;
|
|
1027
|
+
let loadParticipantAbortController = null;
|
|
1028
|
+
const clearThreadLoadTimeout = () => {
|
|
1029
|
+
if (threadLoadTimeout != null) {
|
|
1030
|
+
clearTimeout(threadLoadTimeout);
|
|
1031
|
+
threadLoadTimeout = null;
|
|
1032
|
+
}
|
|
1033
|
+
};
|
|
1034
|
+
const synchronizeThreadLoadState = () => {
|
|
1035
|
+
if (!loadThread) {
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
if (session2.isLoading) {
|
|
1039
|
+
restorationReadyRef.current = false;
|
|
1040
|
+
if (activeChatClient.agentParticipant() == null && hasAgentParticipantWaiter(activeChatClient)) {
|
|
1041
|
+
clearThreadLoadTimeout();
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
1044
|
+
if (threadLoadTimeout == null) {
|
|
1045
|
+
threadLoadTimeout = setTimeout(() => {
|
|
1046
|
+
threadLoadTimeout = null;
|
|
1047
|
+
if (sessionRef.current !== session2 || !session2.isLoading) {
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
restorationReadyRef.current = false;
|
|
1051
|
+
setRestorationError("Unable to restore conversation context: the server thread did not finish loading within 30 seconds.");
|
|
1052
|
+
setVersion((current) => current + 1);
|
|
1053
|
+
}, threadLoadTimeoutMs);
|
|
1054
|
+
}
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
clearThreadLoadTimeout();
|
|
1058
|
+
const loadError = session2.loadState.error;
|
|
1059
|
+
if (loadError != null) {
|
|
1060
|
+
restorationReadyRef.current = false;
|
|
1061
|
+
if (activeChatClient.agentParticipant() == null && hasAgentParticipantWaiter(activeChatClient)) {
|
|
1062
|
+
setRestorationError(null);
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
setRestorationError(`Unable to restore conversation context: ${loadError}`);
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
restorationReadyRef.current = !injectPersistedEvents || restoredPathRef.current === path;
|
|
1069
|
+
setRestorationError(null);
|
|
1070
|
+
};
|
|
1475
1071
|
const handleChange = () => {
|
|
1072
|
+
synchronizeThreadLoadState();
|
|
1073
|
+
processChatFeedWidgetRequests({
|
|
1074
|
+
session: session2,
|
|
1075
|
+
widgetsByName: chatFeedWidgetsByName,
|
|
1076
|
+
updateCall: updateChatFeedWidgetCall,
|
|
1077
|
+
executeRequests: !deferLiveEvents && restorationReadyRef.current
|
|
1078
|
+
});
|
|
1079
|
+
const latestMessage = session2.messages[session2.messages.length - 1]?.message;
|
|
1080
|
+
onEventsChanged?.(
|
|
1081
|
+
session2.threadPath,
|
|
1082
|
+
mergeAgentMessageEvents(persistedEventsRef.current ?? [], session2.messages),
|
|
1083
|
+
latestMessage ?? null
|
|
1084
|
+
);
|
|
1476
1085
|
setVersion((current) => current + 1);
|
|
1477
1086
|
};
|
|
1478
1087
|
session2.addListener(handleChange);
|
|
1479
1088
|
handleChange();
|
|
1089
|
+
if (loadThread && activeChatClient.agentParticipant() == null && hasAgentParticipantWaiter(activeChatClient)) {
|
|
1090
|
+
loadParticipantAbortController = new AbortController();
|
|
1091
|
+
const { signal } = loadParticipantAbortController;
|
|
1092
|
+
void (async () => {
|
|
1093
|
+
try {
|
|
1094
|
+
await activeChatClient.waitForAgentParticipant({
|
|
1095
|
+
waitKey: `thread-load:${path}:${restorationAttempt}:${(0, import_uuid.v4)()}`,
|
|
1096
|
+
signal,
|
|
1097
|
+
timeoutMs: persistedEventsParticipantWaitTimeoutMs
|
|
1098
|
+
});
|
|
1099
|
+
if (signal.aborted || sessionRef.current !== session2) {
|
|
1100
|
+
return;
|
|
1101
|
+
}
|
|
1102
|
+
if (session2.loadState.error != null) {
|
|
1103
|
+
setRestorationError(null);
|
|
1104
|
+
activeChatClient.openThread(path, {
|
|
1105
|
+
load: true,
|
|
1106
|
+
reloadIfOpen: true
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
handleChange();
|
|
1110
|
+
} catch (error) {
|
|
1111
|
+
if (signal.aborted || sessionRef.current !== session2) {
|
|
1112
|
+
return;
|
|
1113
|
+
}
|
|
1114
|
+
restorationReadyRef.current = false;
|
|
1115
|
+
setRestorationError(`Unable to restore conversation context: ${describeError(error)}`);
|
|
1116
|
+
setVersion((current) => current + 1);
|
|
1117
|
+
}
|
|
1118
|
+
})();
|
|
1119
|
+
}
|
|
1120
|
+
let restorationAbortController = null;
|
|
1121
|
+
const eventsToInject = persistedEventsRef.current;
|
|
1122
|
+
if (injectPersistedEvents && eventsToInject != null && restoredPathRef.current !== path) {
|
|
1123
|
+
restorationAbortController = new AbortController();
|
|
1124
|
+
const { signal } = restorationAbortController;
|
|
1125
|
+
setRestorationError(null);
|
|
1126
|
+
onPersistedEventsInjectionStarted?.();
|
|
1127
|
+
void (async () => {
|
|
1128
|
+
try {
|
|
1129
|
+
await Promise.resolve();
|
|
1130
|
+
if (signal.aborted || sessionRef.current !== session2) {
|
|
1131
|
+
return;
|
|
1132
|
+
}
|
|
1133
|
+
if (activeChatClient.agentParticipant() == null && hasAgentParticipantWaiter(activeChatClient)) {
|
|
1134
|
+
await activeChatClient.waitForAgentParticipant({
|
|
1135
|
+
waitKey: `persisted-events:${path}:${restorationAttempt}:${(0, import_uuid.v4)()}`,
|
|
1136
|
+
signal,
|
|
1137
|
+
timeoutMs: persistedEventsParticipantWaitTimeoutMs
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1140
|
+
if (signal.aborted || sessionRef.current !== session2) {
|
|
1141
|
+
return;
|
|
1142
|
+
}
|
|
1143
|
+
await session2.injectMessages(eventsToInject.map((event) => event.message));
|
|
1144
|
+
if (signal.aborted || sessionRef.current !== session2) {
|
|
1145
|
+
return;
|
|
1146
|
+
}
|
|
1147
|
+
restoredPathRef.current = path;
|
|
1148
|
+
restorationReadyRef.current = true;
|
|
1149
|
+
setRestorationError(null);
|
|
1150
|
+
onPersistedEventsInjected?.(null);
|
|
1151
|
+
handleChange();
|
|
1152
|
+
} catch (error) {
|
|
1153
|
+
if (signal.aborted || sessionRef.current !== session2) {
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
if (restoredPathRef.current === path) {
|
|
1157
|
+
restoredPathRef.current = null;
|
|
1158
|
+
}
|
|
1159
|
+
restorationReadyRef.current = false;
|
|
1160
|
+
setRestorationError(`Unable to restore conversation context: ${describeError(error)}`);
|
|
1161
|
+
onPersistedEventsInjected?.(error);
|
|
1162
|
+
setVersion((current) => current + 1);
|
|
1163
|
+
}
|
|
1164
|
+
})();
|
|
1165
|
+
} else if (!injectPersistedEvents && !loadThread) {
|
|
1166
|
+
setRestorationError(null);
|
|
1167
|
+
}
|
|
1480
1168
|
return () => {
|
|
1169
|
+
clearThreadLoadTimeout();
|
|
1170
|
+
loadParticipantAbortController?.abort();
|
|
1171
|
+
restorationAbortController?.abort();
|
|
1481
1172
|
session2.removeListener(handleChange);
|
|
1482
1173
|
if (sessionRef.current === session2) {
|
|
1483
1174
|
sessionRef.current = null;
|
|
1484
1175
|
}
|
|
1176
|
+
if (closeThreadOnUnmount) {
|
|
1177
|
+
const timer = setTimeout(() => {
|
|
1178
|
+
if (pendingCloseRef.current?.timer === timer) {
|
|
1179
|
+
pendingCloseRef.current = null;
|
|
1180
|
+
}
|
|
1181
|
+
if (sessionRef.current !== session2) {
|
|
1182
|
+
void session2.close();
|
|
1183
|
+
}
|
|
1184
|
+
}, 0);
|
|
1185
|
+
pendingCloseRef.current = { session: session2, timer };
|
|
1186
|
+
}
|
|
1485
1187
|
};
|
|
1486
|
-
}, [
|
|
1188
|
+
}, [
|
|
1189
|
+
activeChatClient,
|
|
1190
|
+
chatFeedWidgetsByName,
|
|
1191
|
+
closeThreadOnUnmount,
|
|
1192
|
+
deferLiveEvents,
|
|
1193
|
+
injectPersistedEvents,
|
|
1194
|
+
loadThread,
|
|
1195
|
+
onEventsChanged,
|
|
1196
|
+
onPersistedEventsInjectionStarted,
|
|
1197
|
+
onPersistedEventsInjected,
|
|
1198
|
+
path,
|
|
1199
|
+
restorationAttempt,
|
|
1200
|
+
updateChatFeedWidgetCall
|
|
1201
|
+
]);
|
|
1202
|
+
const retryRestoration = (0, import_react.useCallback)(() => {
|
|
1203
|
+
restoredPathRef.current = null;
|
|
1204
|
+
restorationReadyRef.current = false;
|
|
1205
|
+
setRestorationError(null);
|
|
1206
|
+
setRestorationAttempt((current) => current + 1);
|
|
1207
|
+
}, []);
|
|
1487
1208
|
const normalizedPath = path.trim();
|
|
1488
1209
|
const session = sessionRef.current?.threadPath === normalizedPath ? sessionRef.current : null;
|
|
1489
|
-
const
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
const status = (0, import_react.useMemo)(() => latestThreadStatus(session), [session, version]);
|
|
1493
|
-
const usage = (0, import_react.useMemo)(() => latestUsageSnapshot(session), [session, version]);
|
|
1494
|
-
const statusText = status?.status?.trim() || null;
|
|
1495
|
-
const turnId = stringValue(status?.turnId);
|
|
1496
|
-
const canInterruptActiveTurn = turnId != null && (agentParticipant != null || chatClient != null);
|
|
1497
|
-
const lastItem = feedItems.length > 0 ? feedItems[feedItems.length - 1] : void 0;
|
|
1498
|
-
const lastMessageKey = `${lastItem?.id ?? ""}:${lastItem?.text.length ?? 0}:${feedItems.length}:${version}`;
|
|
1499
|
-
(0, import_react.useEffect)(() => {
|
|
1500
|
-
const container = scrollContainerRef.current;
|
|
1501
|
-
if (!container) {
|
|
1502
|
-
return;
|
|
1210
|
+
const timeline = (0, import_react.useMemo)(() => {
|
|
1211
|
+
if (session == null) {
|
|
1212
|
+
return null;
|
|
1503
1213
|
}
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
}, [path]);
|
|
1507
|
-
(0, import_react.useEffect)(() => {
|
|
1508
|
-
const container = scrollContainerRef.current;
|
|
1509
|
-
if (!container || !stickToBottomRef.current) {
|
|
1510
|
-
return;
|
|
1214
|
+
if (deferLiveEvents) {
|
|
1215
|
+
return (0, import_chat_thread_timeline.buildChatThreadTimeline)(persistedEvents ?? []);
|
|
1511
1216
|
}
|
|
1512
|
-
|
|
1513
|
-
}, [
|
|
1514
|
-
(0, import_react.
|
|
1515
|
-
const
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
return;
|
|
1217
|
+
return persistedEvents == null ? (0, import_chat_thread_timeline.buildChatThreadTimeline)(session.messages, session.pendingInputs) : (0, import_chat_thread_timeline.buildMergedChatThreadTimeline)(persistedEvents, session.messages, session.pendingInputs);
|
|
1218
|
+
}, [deferLiveEvents, persistedEvents, session, version]);
|
|
1219
|
+
const timelineItems = (0, import_react.useMemo)(() => (timeline?.items ?? []).map((item) => {
|
|
1220
|
+
const override = session == null ? void 0 : chatFeedWidgetCallOverrides.get(chatFeedWidgetCallKey(session.threadPath, item.id));
|
|
1221
|
+
if (override == null || item.kind !== "tool_call" || (item.state === "completed" || item.state === "failed")) {
|
|
1222
|
+
return item;
|
|
1519
1223
|
}
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1224
|
+
return {
|
|
1225
|
+
...item,
|
|
1226
|
+
state: override.status,
|
|
1227
|
+
failed: override.status === "failed",
|
|
1228
|
+
output: override.output ?? item.output
|
|
1229
|
+
};
|
|
1230
|
+
}), [chatFeedWidgetCallOverrides, session, timeline]);
|
|
1231
|
+
const showThreadLoading = (deferLiveEvents || session === null || session.isLoading) && timelineItems.length === 0;
|
|
1232
|
+
const followUpSuggestions = (0, import_react.useMemo)(
|
|
1233
|
+
() => latestTurnFollowUpSuggestions(timelineItems, chatFeedWidgetsByName),
|
|
1234
|
+
[chatFeedWidgetsByName, timelineItems]
|
|
1235
|
+
);
|
|
1236
|
+
const feedTimelineItems = (0, import_react.useMemo)(
|
|
1237
|
+
() => timelineItems.filter((item) => !isFollowUpSuggestionCall(item, chatFeedWidgetsByName)),
|
|
1238
|
+
[chatFeedWidgetsByName, timelineItems]
|
|
1239
|
+
);
|
|
1240
|
+
const renderedItems = (0, import_react.useMemo)(() => collapseMessages ? groupThreadItems(feedTimelineItems, expandedDetailGroupIds, localParticipantName, agentName, chatFeedWidgetsByName) : feedTimelineItems, [agentName, chatFeedWidgetsByName, collapseMessages, expandedDetailGroupIds, feedTimelineItems, localParticipantName]);
|
|
1241
|
+
const status = (0, import_react.useMemo)(() => {
|
|
1242
|
+
if (session == null) return null;
|
|
1243
|
+
let current = null;
|
|
1244
|
+
for (const event of session.messages) {
|
|
1245
|
+
const message = event.message;
|
|
1246
|
+
if (message instanceof import_meshagent_agents.AgentThreadStatus) {
|
|
1247
|
+
current = stringValue(message.status) == null ? null : message;
|
|
1248
|
+
continue;
|
|
1249
|
+
}
|
|
1250
|
+
if (message instanceof import_meshagent_agents.TurnStarted || message instanceof import_meshagent_agents.TurnEnded) {
|
|
1251
|
+
const statusTurnId = stringValue(current?.turnId);
|
|
1252
|
+
const messageTurnId = stringValue(message.turnId);
|
|
1253
|
+
if (statusTurnId == null || statusTurnId === messageTurnId) current = null;
|
|
1523
1254
|
}
|
|
1255
|
+
}
|
|
1256
|
+
return current;
|
|
1257
|
+
}, [session, version]);
|
|
1258
|
+
const usage = timeline?.usage ?? null;
|
|
1259
|
+
const statusText = status?.status?.trim() || null;
|
|
1260
|
+
const turnId = stringValue(status?.turnId);
|
|
1261
|
+
const canInterruptActiveTurn = turnId != null && (agentParticipant != null || chatClient != null);
|
|
1262
|
+
const renderedItemsNewestFirst = (0, import_react.useMemo)(() => [...renderedItems].reverse(), [renderedItems]);
|
|
1263
|
+
const firstRenderedItemId = renderedItems[0]?.id;
|
|
1264
|
+
const lastRenderedItemId = renderedItems[renderedItems.length - 1]?.id;
|
|
1265
|
+
const previousItemById = (0, import_react.useMemo)(() => {
|
|
1266
|
+
const previousById = /* @__PURE__ */ new Map();
|
|
1267
|
+
renderedItems.forEach((item, index) => {
|
|
1268
|
+
previousById.set(item.id, previousMessageItem(renderedItems, index));
|
|
1524
1269
|
});
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
observer.disconnect();
|
|
1528
|
-
};
|
|
1529
|
-
}, []);
|
|
1270
|
+
return previousById;
|
|
1271
|
+
}, [renderedItems]);
|
|
1530
1272
|
const selectAttachments = (0, import_react.useCallback)((files) => {
|
|
1531
1273
|
const nextAttachments = files.map((file) => new import_file_attachment.MeshagentFileUpload(
|
|
1532
1274
|
room,
|
|
@@ -1554,19 +1296,33 @@ function AgentThread({
|
|
|
1554
1296
|
await openSession.sendText({
|
|
1555
1297
|
messageId: message.id,
|
|
1556
1298
|
text: message.text,
|
|
1557
|
-
attachments: normalizedAttachments,
|
|
1299
|
+
attachments: normalizedAttachments.map((url) => new import_meshagent_agents.AgentFileContent({ url })),
|
|
1558
1300
|
turnId,
|
|
1559
1301
|
steer: status?.mode === "steerable" && turnId != null,
|
|
1560
1302
|
senderName: localParticipantName.trim() || void 0,
|
|
1561
|
-
clientToolkits
|
|
1562
|
-
toolChoice: toolChoice == null ? void 0 : new import_meshagent_agents.ToolChoice({ toolkitName: toolChoice.toolkitName, toolName: toolChoice.toolName })
|
|
1303
|
+
clientToolkits: resolvedClientToolkits
|
|
1563
1304
|
});
|
|
1564
1305
|
setSendError(null);
|
|
1565
1306
|
setVersion((current) => current + 1);
|
|
1566
1307
|
} catch (error) {
|
|
1567
1308
|
setSendError(describeError(error));
|
|
1568
1309
|
}
|
|
1569
|
-
}, [agentParticipant, chatClient,
|
|
1310
|
+
}, [agentParticipant, chatClient, resolvedClientToolkits, localParticipantName, status?.mode, turnId]);
|
|
1311
|
+
const visibleSuggestions = (0, import_react.useMemo)(
|
|
1312
|
+
() => (followUpSuggestions ?? suggestions ?? []).filter((suggestion) => suggestion.label.trim() !== ""),
|
|
1313
|
+
[followUpSuggestions, suggestions]
|
|
1314
|
+
);
|
|
1315
|
+
const composerDisabled = composerDisabledProp || loadThread && !restorationReadyRef.current || injectPersistedEvents && restoredPathRef.current !== path || agentParticipant == null && chatClient == null;
|
|
1316
|
+
const handleSuggestionClick = (0, import_react.useCallback)((suggestion) => {
|
|
1317
|
+
const text = suggestion.prompt?.trim() || suggestion.label.trim();
|
|
1318
|
+
if (text === "") {
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
void handleSend(new import_chat_message.ChatMessage({
|
|
1322
|
+
id: (0, import_uuid.v4)(),
|
|
1323
|
+
text
|
|
1324
|
+
}));
|
|
1325
|
+
}, [handleSend]);
|
|
1570
1326
|
const cancelTurn = (0, import_react.useCallback)(async () => {
|
|
1571
1327
|
const openSession = sessionRef.current;
|
|
1572
1328
|
if (openSession === null || turnId == null) {
|
|
@@ -1587,55 +1343,40 @@ function AgentThread({
|
|
|
1587
1343
|
}, []);
|
|
1588
1344
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex h-full min-h-0 flex-1 flex-col", children: [
|
|
1589
1345
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "relative flex h-full min-h-0 flex-1 flex-col", children: [
|
|
1590
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1591
|
-
|
|
1346
|
+
showThreadLoading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "min-h-0 flex-1 overflow-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoadingState, {}) }) : timelineItems.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "min-h-0 flex-1 overflow-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyState, { title: emptyStateTitle, description: emptyStateDescription }) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1347
|
+
import_chat_scroller.ChatScroller,
|
|
1592
1348
|
{
|
|
1593
|
-
|
|
1594
|
-
className: "
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
"div",
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
item.id
|
|
1625
|
-
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1626
|
-
ThreadMessageView,
|
|
1627
|
-
{
|
|
1628
|
-
room,
|
|
1629
|
-
message: item,
|
|
1630
|
-
previous: previousMessageFeedItem(renderedFeedItems, index),
|
|
1631
|
-
localParticipantName,
|
|
1632
|
-
agentName
|
|
1633
|
-
},
|
|
1634
|
-
item.id
|
|
1635
|
-
))
|
|
1636
|
-
]
|
|
1637
|
-
}
|
|
1638
|
-
)
|
|
1349
|
+
bottomThresholdPx: 24,
|
|
1350
|
+
className: "flex-1 overflow-x-hidden",
|
|
1351
|
+
currentUserId: "user",
|
|
1352
|
+
getMessageAuthorId: (item) => item.kind === "detail_group" ? "agent" : item.role,
|
|
1353
|
+
messages: renderedItemsNewestFirst,
|
|
1354
|
+
renderMessage: (item) => {
|
|
1355
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_utils.cn)(
|
|
1356
|
+
"mx-auto w-full max-w-[912px] px-1 py-3",
|
|
1357
|
+
item.id === firstRenderedItemId ? "pt-6" : null,
|
|
1358
|
+
item.id === lastRenderedItemId ? statusText ? "pb-24" : "pb-6" : null
|
|
1359
|
+
), children: item.kind === "detail_group" ? item.expanded ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1360
|
+
ExpandedDetailGroup,
|
|
1361
|
+
{
|
|
1362
|
+
room,
|
|
1363
|
+
item,
|
|
1364
|
+
localParticipantName,
|
|
1365
|
+
agentName,
|
|
1366
|
+
chatFeedWidgetsByName
|
|
1367
|
+
}
|
|
1368
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DetailGroupLine, { item, onToggle: () => toggleDetailGroup(item.id) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1369
|
+
ThreadMessageView,
|
|
1370
|
+
{
|
|
1371
|
+
room,
|
|
1372
|
+
message: item,
|
|
1373
|
+
previous: previousItemById.get(item.id) ?? null,
|
|
1374
|
+
localParticipantName,
|
|
1375
|
+
agentName,
|
|
1376
|
+
chatFeedWidgetsByName
|
|
1377
|
+
}
|
|
1378
|
+
) });
|
|
1379
|
+
}
|
|
1639
1380
|
}
|
|
1640
1381
|
),
|
|
1641
1382
|
statusText ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pointer-events-none absolute inset-x-0 bottom-0 flex justify-center px-4 pb-4", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pointer-events-auto w-full max-w-[912px]", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
@@ -1654,8 +1395,33 @@ function AgentThread({
|
|
|
1654
1395
|
}
|
|
1655
1396
|
) }) }) : null
|
|
1656
1397
|
] }),
|
|
1398
|
+
restorationError ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "px-4 pb-2", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1399
|
+
ErrorBanner,
|
|
1400
|
+
{
|
|
1401
|
+
message: restorationError,
|
|
1402
|
+
onRetry: retryRestoration
|
|
1403
|
+
}
|
|
1404
|
+
) }) : null,
|
|
1657
1405
|
sendError ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "px-4 pb-2", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorBanner, { message: sendError }) }) : null,
|
|
1658
1406
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-1", children: [
|
|
1407
|
+
visibleSuggestions.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1408
|
+
"ul",
|
|
1409
|
+
{
|
|
1410
|
+
"aria-label": "Follow-up suggestions",
|
|
1411
|
+
className: "mx-auto flex flex-wrap w-full max-w-[912px] gap-2 overflow-x-auto px-4 pt-2 pb-1",
|
|
1412
|
+
children: visibleSuggestions.map((suggestion, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { className: "shrink-0", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1413
|
+
import_button.Button,
|
|
1414
|
+
{
|
|
1415
|
+
type: "button",
|
|
1416
|
+
variant: "outline",
|
|
1417
|
+
className: "h-auto min-h-8 rounded-full px-3 py-1.5",
|
|
1418
|
+
disabled: composerDisabled,
|
|
1419
|
+
onClick: () => handleSuggestionClick(suggestion),
|
|
1420
|
+
children: suggestion.label
|
|
1421
|
+
}
|
|
1422
|
+
) }, index))
|
|
1423
|
+
}
|
|
1424
|
+
) : null,
|
|
1659
1425
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1660
1426
|
import_chat_input.ChatInput,
|
|
1661
1427
|
{
|
|
@@ -1663,7 +1429,8 @@ function AgentThread({
|
|
|
1663
1429
|
attachments,
|
|
1664
1430
|
onFilesSelected: selectAttachments,
|
|
1665
1431
|
setAttachments,
|
|
1666
|
-
|
|
1432
|
+
enableFileUpload,
|
|
1433
|
+
disabled: composerDisabled,
|
|
1667
1434
|
placeholder: agentParticipant || chatClient ? "Type a message" : `Waiting for ${displayParticipantName(agentName)}`
|
|
1668
1435
|
}
|
|
1669
1436
|
),
|