@truefoundry/trueforge-ui 0.2.4 → 0.3.0-rc.1

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.
Files changed (113) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/README.md +55 -23
  3. package/dist/AgentCodeSnippets-NZOFJE57.js +74 -0
  4. package/dist/AgentCodeSnippets-NZOFJE57.js.map +1 -0
  5. package/dist/AgentMetricChart-JPU3MFQ2.js +15 -0
  6. package/dist/AgentOverview-EEBHJC32.js +167 -0
  7. package/dist/AgentOverview-EEBHJC32.js.map +1 -0
  8. package/dist/AgentSessionEventTimeline-26Z6IB3B.js +79 -0
  9. package/dist/AgentSessionEventTimeline-26Z6IB3B.js.map +1 -0
  10. package/dist/AgentSessionEventTimelineChart-CGCU7WBK.js +504 -0
  11. package/dist/AgentSessionEventTimelineChart-CGCU7WBK.js.map +1 -0
  12. package/dist/AgentSessions-3MPDZASK.js +275 -0
  13. package/dist/AgentSessions-3MPDZASK.js.map +1 -0
  14. package/dist/{ConnectorSettings-ODC3LVHN.js → ConnectorSettings-MXFRWWR6.js} +8 -6
  15. package/dist/{ConnectorSettings-ODC3LVHN.js.map → ConnectorSettings-MXFRWWR6.js.map} +1 -1
  16. package/dist/{DockLayout-TEOWEMSV.js → DockLayout-LM4AFMFY.js} +12 -11
  17. package/dist/{DockLayout-TEOWEMSV.js.map → DockLayout-LM4AFMFY.js.map} +1 -1
  18. package/dist/DrawerLayout-JR3O6RRB.js +184 -0
  19. package/dist/DrawerLayout-JR3O6RRB.js.map +1 -0
  20. package/dist/{ModelSettings-CKQ5CVAC.js → ModelSettings-G7IFNC2Y.js} +8 -6
  21. package/dist/{ModelSettings-CKQ5CVAC.js.map → ModelSettings-G7IFNC2Y.js.map} +1 -1
  22. package/dist/OpenUiFenceBlock-2TV5TQ6P.js +9 -0
  23. package/dist/OpenUiFenceBlock-2TV5TQ6P.js.map +1 -0
  24. package/dist/{SandboxSettings-HSCPYUOC.js → SandboxSettings-NXAANMAX.js} +8 -6
  25. package/dist/{SandboxSettings-HSCPYUOC.js.map → SandboxSettings-NXAANMAX.js.map} +1 -1
  26. package/dist/SchedulesPage-KKLUDO6B.js +15 -0
  27. package/dist/SchedulesPage-KKLUDO6B.js.map +1 -0
  28. package/dist/{SettingsBuilder-MYWRFXRI.js → SettingsBuilder-L34IQ56S.js} +26 -22
  29. package/dist/SettingsBuilder-L34IQ56S.js.map +1 -0
  30. package/dist/{ShellRouteSync-T4WLY57Q.js → ShellRouteSync-CEBETGEJ.js} +95 -22
  31. package/dist/ShellRouteSync-CEBETGEJ.js.map +1 -0
  32. package/dist/SidebarLayout-A2HJPPHS.js +308 -0
  33. package/dist/SidebarLayout-A2HJPPHS.js.map +1 -0
  34. package/dist/{SkillSettings-ECH6SHZ7.js → SkillSettings-FGGMSUNO.js} +8 -6
  35. package/dist/{SkillSettings-ECH6SHZ7.js.map → SkillSettings-FGGMSUNO.js.map} +1 -1
  36. package/dist/{TrueForgeUIWithRouter-KMHPOKLN.js → TrueForgeUIWithRouter-MZVJWJMB.js} +15 -11
  37. package/dist/{TrueForgeUIWithRouter-KMHPOKLN.js.map → TrueForgeUIWithRouter-MZVJWJMB.js.map} +1 -1
  38. package/dist/{WidgetLayout-4ZIG3RXV.js → WidgetLayout-6QM45OQQ.js} +19 -15
  39. package/dist/WidgetLayout-6QM45OQQ.js.map +1 -0
  40. package/dist/chunk-2XPPBEYF.js +74 -0
  41. package/dist/chunk-2XPPBEYF.js.map +1 -0
  42. package/dist/chunk-6O6FWUDW.js +1376 -0
  43. package/dist/chunk-6O6FWUDW.js.map +1 -0
  44. package/dist/chunk-7Z2C2K7F.js +578 -0
  45. package/dist/chunk-7Z2C2K7F.js.map +1 -0
  46. package/dist/{chunk-FXCYLEFB.js → chunk-BSIPI3KV.js} +18 -2
  47. package/dist/chunk-BSIPI3KV.js.map +1 -0
  48. package/dist/{chunk-255AE5NI.js → chunk-CYHJDKFB.js} +118 -33
  49. package/dist/chunk-CYHJDKFB.js.map +1 -0
  50. package/dist/chunk-DJUFS2BW.js +27 -0
  51. package/dist/chunk-DJUFS2BW.js.map +1 -0
  52. package/dist/chunk-DMMZSZTN.js +252 -0
  53. package/dist/chunk-DMMZSZTN.js.map +1 -0
  54. package/dist/chunk-FJW36PD7.js +180 -0
  55. package/dist/chunk-FJW36PD7.js.map +1 -0
  56. package/dist/chunk-M62XY4NC.js +555 -0
  57. package/dist/chunk-M62XY4NC.js.map +1 -0
  58. package/dist/{chunk-JRRCAKEP.js → chunk-MPNSO7E6.js} +2 -2
  59. package/dist/{chunk-CFLVPV5M.js → chunk-QC42MLAK.js} +7 -2
  60. package/dist/chunk-QC42MLAK.js.map +1 -0
  61. package/dist/chunk-RDXBMTP5.js +32 -0
  62. package/dist/chunk-RDXBMTP5.js.map +1 -0
  63. package/dist/chunk-SFZNIO6U.js +18 -0
  64. package/dist/chunk-SFZNIO6U.js.map +1 -0
  65. package/dist/chunk-U7KURWW3.js +840 -0
  66. package/dist/chunk-U7KURWW3.js.map +1 -0
  67. package/dist/chunk-WVE3F724.js +200 -0
  68. package/dist/chunk-WVE3F724.js.map +1 -0
  69. package/dist/{chunk-IFLE7OMM.js → chunk-XAU7QFG3.js} +180 -38
  70. package/dist/chunk-XAU7QFG3.js.map +1 -0
  71. package/dist/chunk-Y6S4OVVQ.js +16 -0
  72. package/dist/chunk-Y6S4OVVQ.js.map +1 -0
  73. package/dist/chunk-ZKNUMH2M.js +119 -0
  74. package/dist/chunk-ZKNUMH2M.js.map +1 -0
  75. package/dist/chunk-ZTMKFZQ3.js +13214 -0
  76. package/dist/chunk-ZTMKFZQ3.js.map +1 -0
  77. package/dist/{createTrueFoundryServer-B72bU-J7.d.ts → createTrueFoundryServer-CmZnBh_l.d.ts} +15 -4
  78. package/dist/index.d.ts +1199 -161
  79. package/dist/index.js +699 -69
  80. package/dist/index.js.map +1 -1
  81. package/dist/plugins/trueforge-agent-server-adapter/index.d.ts +552 -12
  82. package/dist/plugins/trueforge-agent-server-adapter/index.js +506 -188
  83. package/dist/plugins/trueforge-agent-server-adapter/index.js.map +1 -1
  84. package/dist/styles.css +1 -1
  85. package/package.json +11 -10
  86. package/dist/DrawerLayout-2JOQ4EDZ.js +0 -159
  87. package/dist/DrawerLayout-2JOQ4EDZ.js.map +0 -1
  88. package/dist/OpenUiFenceBlock-3EFPY4JW.js +0 -9
  89. package/dist/SettingsBuilder-MYWRFXRI.js.map +0 -1
  90. package/dist/ShellRouteSync-T4WLY57Q.js.map +0 -1
  91. package/dist/SidebarLayout-6MHQYW45.js +0 -239
  92. package/dist/SidebarLayout-6MHQYW45.js.map +0 -1
  93. package/dist/WidgetLayout-4ZIG3RXV.js.map +0 -1
  94. package/dist/chunk-255AE5NI.js.map +0 -1
  95. package/dist/chunk-72LC2M3R.js +0 -567
  96. package/dist/chunk-72LC2M3R.js.map +0 -1
  97. package/dist/chunk-CFLVPV5M.js.map +0 -1
  98. package/dist/chunk-FXCYLEFB.js.map +0 -1
  99. package/dist/chunk-IFLE7OMM.js.map +0 -1
  100. package/dist/chunk-IWPDSPVA.js +0 -2068
  101. package/dist/chunk-IWPDSPVA.js.map +0 -1
  102. package/dist/chunk-OZTNBS6V.js +0 -75
  103. package/dist/chunk-OZTNBS6V.js.map +0 -1
  104. package/dist/chunk-PUFYHFND.js +0 -91
  105. package/dist/chunk-PUFYHFND.js.map +0 -1
  106. package/dist/chunk-WQULF5AT.js +0 -460
  107. package/dist/chunk-WQULF5AT.js.map +0 -1
  108. package/dist/chunk-XRTTKGKN.js +0 -6825
  109. package/dist/chunk-XRTTKGKN.js.map +0 -1
  110. package/dist/chunk-YIWUG6MC.js +0 -101
  111. package/dist/chunk-YIWUG6MC.js.map +0 -1
  112. /package/dist/{OpenUiFenceBlock-3EFPY4JW.js.map → AgentMetricChart-JPU3MFQ2.js.map} +0 -0
  113. /package/dist/{chunk-JRRCAKEP.js.map → chunk-MPNSO7E6.js.map} +0 -0
@@ -1,2068 +0,0 @@
1
- import {
2
- ComposerBusyProvider,
3
- useComposerBusyState
4
- } from "./chunk-FXCYLEFB.js";
5
- import {
6
- useAui,
7
- useAuiState
8
- } from "./chunk-M6MHLVSO.js";
9
- import {
10
- ASK_USER_CUSTOM_OPTION,
11
- BottomSheet,
12
- Button,
13
- SearchInput_default,
14
- SlotsProvider,
15
- USER_MESSAGE_ATTACHMENT_PREVIEW_REM,
16
- canReuseMutableShell,
17
- preloadMarkdownOpenUI,
18
- readThreadAgentName,
19
- threadListIndicesByRecency,
20
- threadListItemIsMutable,
21
- useIsMobile,
22
- useMCPAuth,
23
- useSearchAgentsList,
24
- useSlot,
25
- useSlotIsDefault,
26
- useToasterOptional
27
- } from "./chunk-XRTTKGKN.js";
28
- import {
29
- DraftCatalogProvider,
30
- Icon,
31
- auiButtonClass,
32
- useCompactLayout,
33
- useDraftCatalog
34
- } from "./chunk-IFLE7OMM.js";
35
- import {
36
- libraryAgentId,
37
- useOptionalCatalogServer,
38
- useOptionalServer,
39
- useOptionalShellMode
40
- } from "./chunk-WQULF5AT.js";
41
- import {
42
- cn
43
- } from "./chunk-72LC2M3R.js";
44
-
45
- // src/containers/AgentStepsContainer.tsx
46
- import { useEffect, useRef, useState } from "react";
47
- import { jsx } from "react/jsx-runtime";
48
- function AgentStepsContainer({
49
- children,
50
- toolCount,
51
- thinkingCount,
52
- hasFinal
53
- }) {
54
- const AgentStepsCard = useSlot("AgentStepsCard");
55
- const [expanded, setExpanded] = useState(true);
56
- const collapsedByFinal = useRef(false);
57
- useEffect(() => {
58
- if (hasFinal && !collapsedByFinal.current) {
59
- collapsedByFinal.current = true;
60
- setExpanded(false);
61
- }
62
- }, [hasFinal]);
63
- return /* @__PURE__ */ jsx(
64
- AgentStepsCard,
65
- {
66
- toolCount,
67
- thinkingCount,
68
- expanded,
69
- onToggle: () => setExpanded((prev) => !prev),
70
- children
71
- }
72
- );
73
- }
74
-
75
- // src/containers/AskUserContainer.tsx
76
- import { useThreadIsRunning } from "@assistant-ui/core/react";
77
- import { useTrueFoundryToolResponses } from "@truefoundry/assistant-ui-runtime";
78
- import { useCallback, useEffect as useEffect2, useMemo, useState as useState2 } from "react";
79
- import { jsx as jsx2 } from "react/jsx-runtime";
80
- var EMPTY_ANSWER = { radioValue: "", custom: "" };
81
- function AskUserContainer() {
82
- const AskUserPrompt = useSlot("AskUserPrompt");
83
- const { pending, respond } = useTrueFoundryToolResponses();
84
- const isRunning = useThreadIsRunning();
85
- const item = pending[0];
86
- const questions = useMemo(
87
- () => item == null ? [] : [
88
- {
89
- id: item.toolCallId,
90
- question: item.question ?? "Answer required",
91
- options: item.options ?? []
92
- }
93
- ],
94
- [item]
95
- );
96
- const [currentQuestionIndex, setCurrentQuestionIndex] = useState2(0);
97
- const [answers, setAnswers] = useState2({});
98
- useEffect2(() => {
99
- setCurrentQuestionIndex(0);
100
- setAnswers({});
101
- }, [item?.toolCallId]);
102
- const safeIndex = Math.min(currentQuestionIndex, Math.max(questions.length - 1, 0));
103
- const currentQuestion = questions[safeIndex];
104
- const currentAnswer = currentQuestion == null ? EMPTY_ANSWER : answers[currentQuestion.id] ?? EMPTY_ANSWER;
105
- const getResponseForQuestion = useCallback(
106
- (questionId) => {
107
- const answer = answers[questionId] ?? EMPTY_ANSWER;
108
- return answer.radioValue === ASK_USER_CUSTOM_OPTION ? answer.custom.trim() : answer.radioValue.trim();
109
- },
110
- [answers]
111
- );
112
- const allQuestionsAnswered = useMemo(
113
- () => questions.every((question) => getResponseForQuestion(question.id)),
114
- [getResponseForQuestion, questions]
115
- );
116
- const selectedResponse = currentAnswer.radioValue === ASK_USER_CUSTOM_OPTION ? currentAnswer.custom.trim() : currentAnswer.radioValue.trim();
117
- const isSubmitDisabled = isRunning || currentQuestion == null || selectedResponse.length === 0;
118
- const isSubmitAllDisabled = isSubmitDisabled || !allQuestionsAnswered;
119
- const onCurrentAnswerChange = useCallback((questionId, update) => {
120
- setAnswers((previous) => ({
121
- ...previous,
122
- [questionId]: {
123
- ...previous[questionId] ?? EMPTY_ANSWER,
124
- ...update
125
- }
126
- }));
127
- }, []);
128
- const onSubmit = useCallback(() => {
129
- if (item == null || !allQuestionsAnswered) return;
130
- const content = getResponseForQuestion(item.toolCallId);
131
- if (!content) return;
132
- respond({ toolCallId: item.toolCallId, content });
133
- }, [allQuestionsAnswered, getResponseForQuestion, item, respond]);
134
- if (item == null || currentQuestion == null) return null;
135
- return /* @__PURE__ */ jsx2(
136
- AskUserPrompt,
137
- {
138
- questions,
139
- readOnly: isRunning,
140
- currentQuestion,
141
- currentQuestionIndex: safeIndex,
142
- currentAnswer,
143
- totalQuestions: questions.length,
144
- isMultiQuestion: questions.length > 1,
145
- isLastQuestion: safeIndex === questions.length - 1,
146
- allQuestionsAnswered,
147
- isSubmitDisabled,
148
- isSubmitAllDisabled,
149
- onCurrentQuestionIndexChange: setCurrentQuestionIndex,
150
- onCurrentAnswerChange,
151
- onSubmit
152
- }
153
- );
154
- }
155
-
156
- // src/utils/computeAgentStepsSplit.ts
157
- function computeAgentStepsSplit(parts, isRunning) {
158
- const finalTexts = [];
159
- let cutIdx = parts.length;
160
- for (let i = parts.length - 1; i >= 0; i--) {
161
- const part = parts[i];
162
- if (!part) continue;
163
- if (part.type === "text") {
164
- const text = part.text ?? "";
165
- const trimmed = text.trim();
166
- if (trimmed) {
167
- finalTexts.unshift({ index: i, content: text });
168
- cutIdx = i;
169
- } else {
170
- cutIdx = i;
171
- }
172
- } else {
173
- break;
174
- }
175
- }
176
- const trailingChars = finalTexts.reduce((sum, t) => sum + t.content.length, 0);
177
- const hasAgentStepsBeforeCut = parts.slice(0, cutIdx).some((p) => p.type === "tool-call" || p.type === "reasoning");
178
- const finalConfirmed = finalTexts.length > 0 && (!isRunning || trailingChars >= 500 || !hasAgentStepsBeforeCut);
179
- const actualCutIndex = finalConfirmed ? cutIdx : parts.length;
180
- let toolCount = 0;
181
- let thinkingCount = 0;
182
- for (let i = 0; i < actualCutIndex; i++) {
183
- const part = parts[i];
184
- if (!part) continue;
185
- if (part.type === "tool-call") {
186
- toolCount++;
187
- } else if (part.type === "reasoning") {
188
- thinkingCount++;
189
- }
190
- }
191
- return {
192
- cutIndex: actualCutIndex,
193
- hasFinal: finalConfirmed,
194
- toolCount,
195
- thinkingCount
196
- };
197
- }
198
-
199
- // src/containers/AssistantTextContainer.tsx
200
- import {
201
- useAuiState as useAuiState2,
202
- useSmooth
203
- } from "@assistant-ui/react";
204
- import { useTrueFoundryDownloadSandboxFile } from "@truefoundry/assistant-ui-runtime";
205
- import { useCallback as useCallback2, useMemo as useMemo2, useRef as useRef3 } from "react";
206
-
207
- // src/hooks/useThrottledMarkdownText.ts
208
- import { useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
209
- var MARKDOWN_SMOOTH_BACKLOG_CHARS = 4 * 1024;
210
- var LARGE_MARKDOWN_THROTTLE_MS = 100;
211
- function useThrottledMarkdownText(text, {
212
- isComplete,
213
- enabled,
214
- throttleMs = LARGE_MARKDOWN_THROTTLE_MS
215
- }) {
216
- const [committed, setCommitted] = useState3(text);
217
- const lastCommittedRef = useRef2(text);
218
- const lastCommitAtRef = useRef2(Date.now());
219
- const pendingRef = useRef2(text);
220
- const wasEnabledRef = useRef2(enabled);
221
- useEffect3(() => {
222
- pendingRef.current = text;
223
- const commit = (value) => {
224
- if (value.length < lastCommittedRef.current.length && value !== lastCommittedRef.current) {
225
- return;
226
- }
227
- lastCommittedRef.current = value;
228
- lastCommitAtRef.current = Date.now();
229
- setCommitted(value);
230
- };
231
- if (!enabled) {
232
- wasEnabledRef.current = false;
233
- lastCommittedRef.current = text;
234
- lastCommitAtRef.current = Date.now();
235
- setCommitted(text);
236
- return;
237
- }
238
- if (!wasEnabledRef.current) {
239
- wasEnabledRef.current = true;
240
- commit(text);
241
- return;
242
- }
243
- if (lastCommittedRef.current === text) return;
244
- if (isComplete) {
245
- commit(text);
246
- return;
247
- }
248
- const elapsed = Date.now() - lastCommitAtRef.current;
249
- if (elapsed >= throttleMs) {
250
- commit(text);
251
- return;
252
- }
253
- const id = setTimeout(() => {
254
- commit(pendingRef.current);
255
- }, throttleMs - elapsed);
256
- return () => clearTimeout(id);
257
- }, [text, isComplete, enabled, throttleMs]);
258
- return enabled ? committed : text;
259
- }
260
-
261
- // src/containers/AssistantTextContainer.tsx
262
- import { jsx as jsx3 } from "react/jsx-runtime";
263
- function filenameFromPath(path) {
264
- return path.split("/").pop() || "download";
265
- }
266
- function triggerBrowserDownload(blob, filename) {
267
- if (typeof document === "undefined") return;
268
- const url = URL.createObjectURL(blob);
269
- const anchor = document.createElement("a");
270
- anchor.href = url;
271
- anchor.download = filename;
272
- anchor.click();
273
- URL.revokeObjectURL(url);
274
- }
275
- function AssistantTextContainer() {
276
- const Markdown = useSlot("Markdown");
277
- const toaster = useToasterOptional();
278
- const downloadSandboxFile = useTrueFoundryDownloadSandboxFile();
279
- const downloadRef = useRef3({ downloadSandboxFile, toaster });
280
- downloadRef.current = { downloadSandboxFile, toaster };
281
- const partState = useAuiState2((s) => s.part);
282
- const pacedModeRef = useRef3(false);
283
- const smoothedPart = useSmooth(
284
- partState,
285
- pacedModeRef.current ? false : {
286
- drainMs: 150,
287
- maxCharIntervalMs: 4,
288
- maxCharsPerFrame: 128,
289
- minCommitMs: 48
290
- }
291
- );
292
- const networkComplete = partState.status?.type !== "running";
293
- const smoothLag = partState.text.length - smoothedPart.text.length;
294
- if (!pacedModeRef.current && !networkComplete && smoothLag >= MARKDOWN_SMOOTH_BACKLOG_CHARS) {
295
- pacedModeRef.current = true;
296
- }
297
- const usePacedMode = pacedModeRef.current;
298
- const pacedText = useThrottledMarkdownText(partState.text, {
299
- enabled: usePacedMode,
300
- isComplete: networkComplete
301
- });
302
- const text = usePacedMode ? pacedText : smoothedPart.text;
303
- const isStreaming = usePacedMode ? !networkComplete || text !== partState.text : smoothedPart.status?.type === "running";
304
- const handleDownloadArtifact = useCallback2(async (path) => {
305
- const { downloadSandboxFile: downloadSandboxFile2, toaster: toaster2 } = downloadRef.current;
306
- try {
307
- triggerBrowserDownload(await downloadSandboxFile2(path), filenameFromPath(path));
308
- } catch (error) {
309
- if (toaster2 != null) {
310
- toaster2.showError(error);
311
- } else {
312
- console.error("Failed to download sandbox artifact", error);
313
- }
314
- }
315
- }, []);
316
- return useMemo2(
317
- () => /* @__PURE__ */ jsx3(Markdown, { content: text, isStreaming, onDownloadArtifact: handleDownloadArtifact }),
318
- [Markdown, text, isStreaming, handleDownloadArtifact]
319
- );
320
- }
321
-
322
- // src/containers/ReasoningContainer.tsx
323
- import { useAuiState as useAuiState3 } from "@assistant-ui/react";
324
- import { useCallback as useCallback3, useRef as useRef4, useState as useState4 } from "react";
325
- import { jsx as jsx4 } from "react/jsx-runtime";
326
- function ReasoningContainer({ group }) {
327
- const ReasoningCard = useSlot("ReasoningCard");
328
- const content = useAuiState3(
329
- (s) => group.indices.map((i) => s.message.parts[i]).filter((p) => p != null && p.type === "reasoning").map((p) => p.text ?? "").join("")
330
- );
331
- const streaming = useAuiState3((s) => {
332
- if (s.message.status?.type !== "running") return false;
333
- const lastIndex = s.message.parts.length - 1;
334
- if (lastIndex < 0) return false;
335
- if (s.message.parts[lastIndex]?.type !== "reasoning") return false;
336
- const lastGroupIndex = group.indices[group.indices.length - 1];
337
- return lastGroupIndex !== void 0 && lastIndex >= group.indices[0] && lastIndex <= lastGroupIndex;
338
- });
339
- const [expanded, setExpanded] = useState4(streaming);
340
- const [prevStreaming, setPrevStreaming] = useState4(streaming);
341
- const [isMultiLine, setIsMultiLine] = useState4(false);
342
- const observerRef = useRef4(null);
343
- if (streaming !== prevStreaming) {
344
- setPrevStreaming(streaming);
345
- if (streaming) setExpanded(true);
346
- }
347
- const contentRef = useCallback3(
348
- (node) => {
349
- observerRef.current?.disconnect();
350
- observerRef.current = null;
351
- if (node == null || streaming) return;
352
- const check = () => {
353
- const lineHeight = Number.parseFloat(getComputedStyle(node).lineHeight) || 24;
354
- setIsMultiLine(node.scrollHeight > lineHeight * 1.5);
355
- };
356
- check();
357
- observerRef.current = new ResizeObserver(check);
358
- observerRef.current.observe(node);
359
- },
360
- [streaming]
361
- );
362
- const reasoningTimeText = null;
363
- const previewText = content.replace(/\s+/g, " ").trim();
364
- const isShortText = !streaming && content.length > 0 && !isMultiLine;
365
- const headingText = "Reasoning";
366
- return /* @__PURE__ */ jsx4(
367
- ReasoningCard,
368
- {
369
- content,
370
- isStreaming: streaming,
371
- expanded,
372
- isMultiLine,
373
- reasoningTimeText,
374
- previewText,
375
- headingText,
376
- contentRef: isShortText ? contentRef : void 0,
377
- onToggle: () => setExpanded((prev) => !prev)
378
- }
379
- );
380
- }
381
-
382
- // src/containers/ToolApprovalContainer.tsx
383
- import { useCallback as useCallback4, useMemo as useMemo3, useState as useState5 } from "react";
384
- import { jsx as jsx5 } from "react/jsx-runtime";
385
- function ToolApprovalContainer({ toolName = "", options, onSelectOption }) {
386
- const ToolApprovalBar = useSlot("ToolApprovalBar");
387
- const [selectedDenyOptionId, setSelectedDenyOptionId] = useState5(null);
388
- const [denialReason, setDenialReason] = useState5("");
389
- const [showReasonError, setShowReasonError] = useState5(false);
390
- const approveOptions = useMemo3(
391
- () => options.filter((option) => option.isAllow).map((option, index) => ({
392
- ...option,
393
- variant: index === 0 ? "primary" : "secondary",
394
- requiresReason: false
395
- })),
396
- [options]
397
- );
398
- const denyOptions = useMemo3(
399
- () => options.filter((option) => !option.isAllow).map((option) => ({
400
- ...option,
401
- variant: "secondary",
402
- requiresReason: option.confirm != null
403
- })),
404
- [options]
405
- );
406
- const selectedDenyOption = denyOptions.find((option) => option.id === selectedDenyOptionId);
407
- const onDenyOptionChange = useCallback4((optionId) => {
408
- setSelectedDenyOptionId(optionId);
409
- setDenialReason("");
410
- setShowReasonError(false);
411
- }, []);
412
- const onDenialReasonChange = useCallback4((reason) => {
413
- setDenialReason(reason);
414
- setShowReasonError(false);
415
- }, []);
416
- const onReasonSubmit = useCallback4(() => {
417
- const reason = denialReason.trim();
418
- if (!reason) {
419
- setShowReasonError(true);
420
- return;
421
- }
422
- if (selectedDenyOptionId) {
423
- onSelectOption(selectedDenyOptionId, reason);
424
- onDenyOptionChange(null);
425
- }
426
- }, [denialReason, onDenyOptionChange, onSelectOption, selectedDenyOptionId]);
427
- return /* @__PURE__ */ jsx5(
428
- ToolApprovalBar,
429
- {
430
- toolName,
431
- approveOptions: approveOptions.length > 0 ? approveOptions : void 0,
432
- denyOptions: denyOptions.length > 0 ? denyOptions : void 0,
433
- selectedDenyOption,
434
- denialReason,
435
- showReasonError,
436
- onSelect: onSelectOption,
437
- onDenyOptionChange,
438
- onDenialReasonChange,
439
- onReasonSubmit
440
- }
441
- );
442
- }
443
-
444
- // src/containers/ToolCallContentBlockContainer.tsx
445
- import { useCallback as useCallback5, useEffect as useEffect4, useRef as useRef5, useState as useState6 } from "react";
446
- import { jsx as jsx6 } from "react/jsx-runtime";
447
- function ToolCallContentBlockContainer(props) {
448
- const ToolCallContentBlock = useSlot("ToolCallContentBlock");
449
- const { isJson, onContentHeightChange: notifyContentHeightChange, resizable } = props;
450
- const [fullscreen, setFullscreen] = useState6(false);
451
- const [contentHeightRem, setContentHeightRem] = useState6();
452
- const observerRef = useRef5(null);
453
- const contentNodeRef = useRef5(null);
454
- const hasMeasuredRef = useRef5(false);
455
- const contentRef = useCallback5(
456
- (node) => {
457
- observerRef.current?.disconnect();
458
- observerRef.current = null;
459
- contentNodeRef.current = node;
460
- hasMeasuredRef.current = false;
461
- if (node == null) return;
462
- setContentHeightRem(void 0);
463
- if (!resizable) return;
464
- const updateHeight = () => {
465
- if (!hasMeasuredRef.current && isJson !== false) return;
466
- const renderedHeight = node.getBoundingClientRect().height;
467
- const height = hasMeasuredRef.current && renderedHeight > 0 ? renderedHeight : node.scrollHeight;
468
- hasMeasuredRef.current = true;
469
- setContentHeightRem(height / 16);
470
- };
471
- updateHeight();
472
- observerRef.current = new ResizeObserver(updateHeight);
473
- observerRef.current.observe(node);
474
- },
475
- [isJson, resizable]
476
- );
477
- const onContentHeightChange = useCallback5(
478
- (height) => {
479
- const node = contentNodeRef.current;
480
- if (node == null) return;
481
- const renderedHeight = node.getBoundingClientRect().height;
482
- hasMeasuredRef.current = true;
483
- setContentHeightRem((renderedHeight > 0 ? renderedHeight : Math.max(height, node.scrollHeight)) / 16);
484
- notifyContentHeightChange?.(height);
485
- },
486
- [notifyContentHeightChange]
487
- );
488
- useEffect4(
489
- () => () => {
490
- observerRef.current?.disconnect();
491
- },
492
- []
493
- );
494
- return /* @__PURE__ */ jsx6(
495
- ToolCallContentBlock,
496
- {
497
- ...props,
498
- fullscreen,
499
- onFullscreenChange: setFullscreen,
500
- contentHeightRem,
501
- contentRef,
502
- onContentHeightChange
503
- }
504
- );
505
- }
506
-
507
- // src/containers/ToolCallContainer.tsx
508
- import {
509
- MessagePartPrimitive,
510
- MessagePrimitive,
511
- useToolCallElapsed
512
- } from "@assistant-ui/react";
513
- import { useTrueFoundryRespondToToolApproval } from "@truefoundry/assistant-ui-runtime";
514
- import { useState as useState8 } from "react";
515
-
516
- // src/utils/toolCallParsing.ts
517
- import { parse as parsePartialJson } from "partial-json";
518
- var SUB_AGENT_TOOL_NAME = "create_sub_agent";
519
- var ASK_USER_TOOL_NAME = "ask_user_question";
520
- var SANDBOX_TOOL_NAMES = /* @__PURE__ */ new Set(["exec", "sandbox_exec"]);
521
- var MCP_META_TOOLS = /* @__PURE__ */ new Set(["call_tool", "list_tools", "get_tool_info"]);
522
- var APPROVAL_OPTION_DEFAULT_LABELS = {
523
- "allow-once": "Allow",
524
- "allow-always": "Always allow",
525
- "reject-once": "Deny",
526
- "reject-always": "Always deny"
527
- };
528
- var isAllowKind = (kind) => kind === "allow-once" || kind === "allow-always";
529
- function parseJsonIncrementally(content) {
530
- try {
531
- return { success: true, value: JSON.parse(content), isPartial: false };
532
- } catch {
533
- const trimmed = content.trim();
534
- if (trimmed[0] !== "{" && trimmed[0] !== "[") return { success: false };
535
- try {
536
- return { success: true, value: parsePartialJson(content), isPartial: true };
537
- } catch {
538
- return { success: false };
539
- }
540
- }
541
- }
542
- function isUnknownRecord(value) {
543
- return value != null && typeof value === "object" && !Array.isArray(value);
544
- }
545
- function parseAskUserQuestionArgs(argsText) {
546
- if (!argsText) return {};
547
- try {
548
- const parsed = JSON.parse(argsText);
549
- if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
550
- return {};
551
- }
552
- const record = parsed;
553
- const question = typeof record.question === "string" ? record.question : void 0;
554
- const options = Array.isArray(record.options) ? record.options.filter((item) => typeof item === "string") : void 0;
555
- return { question, options };
556
- } catch {
557
- return {};
558
- }
559
- }
560
- function getAskUserAnswerResult(result) {
561
- if (result === void 0 || result === null) return void 0;
562
- if (typeof result === "string") {
563
- const trimmed = result.trim();
564
- return trimmed.length > 0 ? trimmed : void 0;
565
- }
566
- if (typeof result === "object" && "content" in result) {
567
- const content = result.content;
568
- if (typeof content === "string" && content.trim()) {
569
- return content.trim();
570
- }
571
- }
572
- return void 0;
573
- }
574
- function hasPendingAskUserResponse(part) {
575
- return part.interrupt != null && part.result === void 0;
576
- }
577
- function hasPendingToolApproval(approval) {
578
- return approval != null && approval.approved === void 0 && approval.resolution === void 0;
579
- }
580
- function buildApprovalOptions(options) {
581
- const declared = options?.filter((o) => Object.hasOwn(APPROVAL_OPTION_DEFAULT_LABELS, o.kind));
582
- if (declared && declared.length > 0) {
583
- const allow = declared.filter((o) => isAllowKind(o.kind));
584
- const reject = declared.filter((o) => !isAllowKind(o.kind));
585
- const mapped = [...allow, ...reject].map((o) => ({
586
- id: o.id,
587
- label: o.label ?? APPROVAL_OPTION_DEFAULT_LABELS[o.kind] ?? o.id,
588
- isAllow: isAllowKind(o.kind),
589
- grants: o.grants,
590
- confirm: o.confirm != null ? typeof o.confirm === "object" ? o.confirm : {} : void 0
591
- }));
592
- if (reject.length === 0) {
593
- mapped.push({ id: "__deny", label: "Deny", isAllow: false, confirm: {} });
594
- }
595
- return mapped;
596
- }
597
- return [
598
- { id: "__allow", label: "Allow", isAllow: true },
599
- { id: "__deny", label: "Deny", isAllow: false, confirm: {} }
600
- ];
601
- }
602
- function formatDuration(ms) {
603
- if (ms < 1e3) return "<1s";
604
- const seconds = ms / 1e3;
605
- if (seconds < 10) return `${(Math.floor(seconds * 10) / 10).toFixed(1)}s`;
606
- if (seconds < 60) return `${Math.floor(seconds)}s`;
607
- return `${Math.floor(seconds / 60)}m ${Math.floor(seconds % 60)}s`;
608
- }
609
- function toStatus(statusType) {
610
- if (statusType === "complete") return "success";
611
- if (statusType === "incomplete") return "error";
612
- return "running";
613
- }
614
- function parseSandboxArgs(argsText) {
615
- if (!argsText) return {};
616
- const parsed = parseJsonIncrementally(argsText);
617
- if (!parsed.success || !isUnknownRecord(parsed.value)) return { argsJson: argsText };
618
- return {
619
- command: typeof parsed.value.command === "string" ? parsed.value.command : void 0,
620
- intent: typeof parsed.value.intent === "string" ? parsed.value.intent : void 0,
621
- argsJson: parsed.isPartial ? argsText : JSON.stringify(parsed.value, null, 2)
622
- };
623
- }
624
- function parseSandboxResult(result) {
625
- if (result === void 0) return {};
626
- const parsed = parseJsonIncrementally(result);
627
- if (!parsed.success || !isUnknownRecord(parsed.value)) return { resultText: result };
628
- const response = isUnknownRecord(parsed.value.response) ? parsed.value.response : void 0;
629
- const exitCode = typeof response?.exitCode === "number" ? response.exitCode : null;
630
- const resultText = typeof response?.result === "string" ? response.result : void 0;
631
- return {
632
- exitCode,
633
- resultText,
634
- resultJson: parsed.isPartial ? result : JSON.stringify(parsed.value, null, 2)
635
- };
636
- }
637
- function parseMcpToolArgs(argsText) {
638
- if (!argsText) return {};
639
- try {
640
- const parsed = JSON.parse(argsText);
641
- return {
642
- mcpServer: parsed.mcp_server,
643
- innerToolName: parsed.tool_name,
644
- input: parsed.input
645
- };
646
- } catch {
647
- return {};
648
- }
649
- }
650
- function getJsonDisplayValue(content) {
651
- if (!content?.trim()) return { value: "", isJson: false };
652
- const trimmed = content.trim();
653
- if (trimmed[0] !== "{" && trimmed[0] !== "[") {
654
- return { value: content, isJson: false };
655
- }
656
- try {
657
- const parsed = JSON.parse(content);
658
- return { value: JSON.stringify(parsed, null, 2), isJson: true };
659
- } catch {
660
- return { value: content, isJson: false };
661
- }
662
- }
663
- function getToolResultContent(content) {
664
- try {
665
- if (!content) return { isJson: false, data: "" };
666
- const parsedResult = typeof content === "string" && content.trim().startsWith("{") ? JSON.parse(content) : content;
667
- if (typeof parsedResult === "object" && parsedResult != null && Array.isArray(parsedResult.content)) {
668
- const text = parsedResult.content[0]?.text || "";
669
- const display2 = getJsonDisplayValue(typeof text === "string" ? text : JSON.stringify(text));
670
- return { data: display2.value, isJson: display2.isJson };
671
- }
672
- const display = getJsonDisplayValue(typeof parsedResult === "string" ? parsedResult : JSON.stringify(parsedResult));
673
- return { data: display.value, isJson: display.isJson };
674
- } catch {
675
- return { data: String(content), isJson: false };
676
- }
677
- }
678
- function resolveSubAgentMeta(part) {
679
- const artifactSubAgent = part.artifact?.subAgents?.[0];
680
- const firstNested = part.messages?.[0];
681
- const subAgent = firstNested?.metadata?.custom?.subAgent;
682
- return {
683
- agentName: subAgent?.title ?? subAgent?.name ?? artifactSubAgent?.title ?? artifactSubAgent?.agentInfo?.name ?? part.toolName,
684
- instruction: subAgent?.input ?? artifactSubAgent?.agentInfo?.input ?? "",
685
- stepCount: part.messages?.length ?? 0
686
- };
687
- }
688
- function mcpDisplayName(toolName, mcpServer, innerToolName) {
689
- if (toolName === "call_tool" && innerToolName) {
690
- return mcpServer ? `call_tool: ${innerToolName} (${mcpServer})` : `call_tool: ${innerToolName}`;
691
- }
692
- if (toolName === "get_tool_info" && innerToolName && mcpServer) {
693
- return `get_tool_info: ${innerToolName} (${mcpServer})`;
694
- }
695
- return toolName;
696
- }
697
-
698
- // src/containers/nestedApprovalBridge.ts
699
- import { createContext, useContext } from "react";
700
- var NestedApprovalBridgeContext = createContext(false);
701
- function useNestedApprovalBridge() {
702
- return useContext(NestedApprovalBridgeContext);
703
- }
704
-
705
- // src/containers/SandboxToolCallContainer.tsx
706
- import { useMemo as useMemo4, useState as useState7 } from "react";
707
- import { jsx as jsx7 } from "react/jsx-runtime";
708
- function SandboxToolCallContainer(props) {
709
- const SandboxToolCallCard = useSlot("SandboxToolCallCard");
710
- const [viewMode, setViewMode] = useState7("terminal");
711
- const hasContent = useMemo4(() => {
712
- if (viewMode === "code") return Boolean(props.argsJson || props.resultJson);
713
- return Boolean(props.command || props.resultText || props.resultJson);
714
- }, [props.argsJson, props.command, props.resultJson, props.resultText, viewMode]);
715
- return /* @__PURE__ */ jsx7(SandboxToolCallCard, { ...props, viewMode, hasContent, onViewModeChange: setViewMode });
716
- }
717
-
718
- // src/containers/ToolCallContainer.tsx
719
- import { jsx as jsx8 } from "react/jsx-runtime";
720
- function NestedSubAgentAssistantMessage() {
721
- const AssistantMessageBubble = useSlot("AssistantMessageBubble");
722
- return /* @__PURE__ */ jsx8("div", { className: "mb-3 min-w-0", children: /* @__PURE__ */ jsx8(MessagePrimitive.Root, { "data-role": "assistant", children: /* @__PURE__ */ jsx8(AssistantMessageBubble, { children: /* @__PURE__ */ jsx8(
723
- MessagePrimitive.Parts,
724
- {
725
- components: {
726
- Text: AssistantTextContainer,
727
- Reasoning: AssistantTextContainer,
728
- tools: { Fallback: ToolCallContainer }
729
- }
730
- }
731
- ) }) }) });
732
- }
733
- function ToolApprovalSlot({ part }) {
734
- const isNestedReadonly = useNestedApprovalBridge();
735
- const respondToNestedApproval = useTrueFoundryRespondToToolApproval();
736
- const respond = (response) => {
737
- if (!isNestedReadonly) {
738
- part.respondToApproval(response);
739
- return;
740
- }
741
- if (part.approval == null) return;
742
- let approved;
743
- let optionId;
744
- if ("approved" in response) {
745
- approved = response.approved;
746
- } else if ("optionId" in response) {
747
- const option = buildApprovalOptions(part.approval.options).find((o) => o.id === response.optionId);
748
- if (option == null) return;
749
- approved = option.isAllow;
750
- optionId = response.optionId;
751
- }
752
- if (approved === void 0) return;
753
- respondToNestedApproval({
754
- approvalId: part.approval.id,
755
- approved,
756
- ...optionId != null && optionId !== "__allow" && optionId !== "__deny" ? { optionId } : {},
757
- ..."reason" in response && response.reason != null ? { reason: response.reason } : {}
758
- });
759
- };
760
- const onSelectOption = (optionId, reason) => {
761
- if (optionId === "__allow") return respond({ approved: true });
762
- if (optionId === "__deny") return respond({ approved: false, reason });
763
- return respond({ optionId, reason });
764
- };
765
- return /* @__PURE__ */ jsx8(
766
- ToolApprovalContainer,
767
- {
768
- toolName: part.toolName,
769
- options: buildApprovalOptions(part.approval?.options),
770
- onSelectOption
771
- }
772
- );
773
- }
774
- function RequestResponseSlots({
775
- request,
776
- response
777
- }) {
778
- return {
779
- requestSlot: request.value ? /* @__PURE__ */ jsx8(
780
- ToolCallContentBlockContainer,
781
- {
782
- title: "Request",
783
- content: request.value,
784
- isJson: request.isJson,
785
- maxHeight: "10.5rem"
786
- }
787
- ) : response.data ? /* @__PURE__ */ jsx8(ToolCallContentBlockContainer, { title: "Request", content: "{}", isJson: true, maxHeight: "10.5rem" }) : void 0,
788
- responseSlot: response.data ? /* @__PURE__ */ jsx8(ToolCallContentBlockContainer, { title: "Response", content: response.data, isJson: response.isJson, resizable: true }) : void 0
789
- };
790
- }
791
- var ToolCallContainer = (part) => {
792
- const ToolCallCard = useSlot("ToolCallCard");
793
- const SubAgentCard = useSlot("SubAgentCard");
794
- const AskUserPrompt = useSlot("AskUserPrompt");
795
- const elapsedMs = useToolCallElapsed();
796
- const isRequiresAction = part.status?.type === "requires-action";
797
- const isSubAgent = part.toolName === SUB_AGENT_TOOL_NAME;
798
- const isSandbox = SANDBOX_TOOL_NAMES.has(part.toolName);
799
- const [expanded, setExpanded] = useState8(isRequiresAction);
800
- const [prevRequiresAction, setPrevRequiresAction] = useState8(isRequiresAction);
801
- if (isRequiresAction !== prevRequiresAction) {
802
- setPrevRequiresAction(isRequiresAction);
803
- if (isRequiresAction) setExpanded(true);
804
- }
805
- const showApproval = isRequiresAction && hasPendingToolApproval(part.approval);
806
- const durationText = elapsedMs === void 0 ? void 0 : formatDuration(elapsedMs);
807
- const status = toStatus(part.status?.type);
808
- const onToggle = () => setExpanded((prev) => !prev);
809
- if (part.toolName === ASK_USER_TOOL_NAME) {
810
- if (hasPendingAskUserResponse(part)) {
811
- return null;
812
- }
813
- const answer = getAskUserAnswerResult(part.result);
814
- if (answer == null) {
815
- return null;
816
- }
817
- const { question, options = [] } = parseAskUserQuestionArgs(part.argsText);
818
- const isCustom = options.length > 0 && !options.includes(answer);
819
- return /* @__PURE__ */ jsx8(
820
- AskUserPrompt,
821
- {
822
- questions: [],
823
- answeredQuestions: [
824
- {
825
- id: part.toolCallId,
826
- question: question ?? "Question",
827
- options,
828
- answer,
829
- isCustom
830
- }
831
- ],
832
- onSubmit: () => {
833
- },
834
- readOnly: true
835
- }
836
- );
837
- }
838
- if (isSubAgent) {
839
- const { agentName, instruction, stepCount } = resolveSubAgentMeta(part);
840
- return /* @__PURE__ */ jsx8("div", { "data-slot": "tool-call-card", "data-variant": "sub-agent", className: "w-full", children: /* @__PURE__ */ jsx8(
841
- SubAgentCard,
842
- {
843
- status,
844
- expanded,
845
- onToggle,
846
- durationText,
847
- agentName,
848
- instruction,
849
- stepCount,
850
- children: /* @__PURE__ */ jsx8(NestedApprovalBridgeContext.Provider, { value: true, children: /* @__PURE__ */ jsx8(
851
- MessagePartPrimitive.Messages,
852
- {
853
- components: {
854
- AssistantMessage: NestedSubAgentAssistantMessage,
855
- UserMessage: () => null
856
- }
857
- }
858
- ) })
859
- }
860
- ) });
861
- }
862
- const resultString = part.result === void 0 ? void 0 : typeof part.result === "string" ? part.result : JSON.stringify(part.result, null, 2);
863
- if (isSandbox) {
864
- const { command, intent, argsJson } = parseSandboxArgs(part.argsText);
865
- const { exitCode, resultText, resultJson } = parseSandboxResult(resultString);
866
- return /* @__PURE__ */ jsx8(
867
- SandboxToolCallContainer,
868
- {
869
- name: part.toolName,
870
- intent,
871
- status,
872
- expanded,
873
- onToggle,
874
- durationText,
875
- command,
876
- exitCode,
877
- argsJson,
878
- resultText,
879
- resultJson
880
- }
881
- );
882
- }
883
- if (MCP_META_TOOLS.has(part.toolName)) {
884
- const { mcpServer, innerToolName, input } = parseMcpToolArgs(part.argsText);
885
- const argsDisplay2 = getJsonDisplayValue(part.argsText);
886
- const resultDisplay2 = getToolResultContent(part.result);
887
- if (part.toolName === "list_tools" && mcpServer) {
888
- const slots3 = RequestResponseSlots({
889
- request: argsDisplay2,
890
- response: resultDisplay2
891
- });
892
- return /* @__PURE__ */ jsx8(
893
- ToolCallCard,
894
- {
895
- toolName: `Listing tools \xB7 ${mcpServer}`,
896
- icon: "mcp-server",
897
- expanded,
898
- onToggle,
899
- awaiting: status === "running",
900
- awaitingText: durationText ?? "Awaiting Response\u2026",
901
- showResponseLine: status !== "running" && !!resultDisplay2.data,
902
- mcpServerName: mcpServer,
903
- ...slots3
904
- }
905
- );
906
- }
907
- const inputDisplay = input !== void 0 ? getJsonDisplayValue(JSON.stringify(input, null, 2)) : argsDisplay2;
908
- const slots2 = RequestResponseSlots({
909
- request: inputDisplay,
910
- response: resultDisplay2
911
- });
912
- return /* @__PURE__ */ jsx8(
913
- ToolCallCard,
914
- {
915
- toolName: mcpDisplayName(part.toolName, mcpServer, innerToolName),
916
- icon: "mcp-server",
917
- expanded,
918
- onToggle,
919
- awaiting: status === "running",
920
- awaitingText: durationText ?? "Awaiting Response\u2026",
921
- showResponseLine: status !== "running" && resultDisplay2.data !== void 0,
922
- mcpServerName: mcpServer,
923
- ...slots2,
924
- approvalSlot: showApproval ? /* @__PURE__ */ jsx8(ToolApprovalSlot, { part }) : void 0
925
- }
926
- );
927
- }
928
- const argsDisplay = getJsonDisplayValue(part.argsText);
929
- const resultDisplay = getToolResultContent(part.result);
930
- const slots = RequestResponseSlots({
931
- request: argsDisplay,
932
- response: resultDisplay
933
- });
934
- return /* @__PURE__ */ jsx8(
935
- ToolCallCard,
936
- {
937
- toolName: part.toolName,
938
- expanded,
939
- onToggle,
940
- awaiting: status === "running",
941
- awaitingText: durationText ?? "Awaiting Response\u2026",
942
- showResponseLine: status !== "running" && resultDisplay.data !== void 0,
943
- ...slots,
944
- approvalSlot: showApproval ? /* @__PURE__ */ jsx8(ToolApprovalSlot, { part }) : void 0
945
- }
946
- );
947
- };
948
-
949
- // src/containers/AssistantMessageContainer.tsx
950
- import { useActionBarCopy, useMessageError, useThreadIsRunning as useThreadIsRunning2 } from "@assistant-ui/core/react";
951
- import { MessagePrimitive as MessagePrimitive2, useAuiState as useAuiState5 } from "@assistant-ui/react";
952
- import { useTrueFoundryResumeUnavailable } from "@truefoundry/assistant-ui-runtime";
953
-
954
- // src/containers/MessageImageContainer.tsx
955
- import { useAuiState as useAuiState4 } from "@assistant-ui/react";
956
- import { jsx as jsx9 } from "react/jsx-runtime";
957
- function MessageImageContainer() {
958
- const AttachmentCard = useSlot("AttachmentCard");
959
- const AttachmentPreviewDialog = useSlot("AttachmentPreviewDialog");
960
- const image = useAuiState4((s) => s.part.type === "image" ? s.part.image : "");
961
- const filename = useAuiState4((s) => s.part.type === "image" ? s.part.filename : void 0);
962
- if (!image) {
963
- return null;
964
- }
965
- const card = /* @__PURE__ */ jsx9(
966
- AttachmentCard,
967
- {
968
- name: filename ?? "image",
969
- previewSrc: image,
970
- isImage: true,
971
- size: "preview",
972
- previewRem: USER_MESSAGE_ATTACHMENT_PREVIEW_REM
973
- }
974
- );
975
- return /* @__PURE__ */ jsx9(AttachmentPreviewDialog, { previewSrc: image, children: /* @__PURE__ */ jsx9("div", { className: "aui-message-image", children: card }) });
976
- }
977
-
978
- // src/containers/AssistantMessageContainer.tsx
979
- import { jsx as jsx10 } from "react/jsx-runtime";
980
- function AssistantLeafPartContainer({ part }) {
981
- switch (part.type) {
982
- case "text":
983
- case "reasoning":
984
- return /* @__PURE__ */ jsx10(AssistantTextContainer, {});
985
- case "image":
986
- return /* @__PURE__ */ jsx10(MessageImageContainer, {});
987
- case "tool-call":
988
- return /* @__PURE__ */ jsx10(ToolCallContainer, { ...part });
989
- default:
990
- return null;
991
- }
992
- }
993
- function AssistantMessageContainer() {
994
- const AssistantMessageBubble = useSlot("AssistantMessageBubble");
995
- const MessageActionBar = useSlot("MessageActionBar");
996
- const MessageErrorBanner = useSlot("MessageErrorBanner");
997
- const MessageIndicator = useSlot("MessageIndicator");
998
- const isThreadRunning = useThreadIsRunning2();
999
- const resumeUnavailable = useTrueFoundryResumeUnavailable();
1000
- const error = useMessageError();
1001
- const createdAt = useAuiState5((s) => s.message.createdAt);
1002
- const isMessageRunning = useAuiState5((s) => s.message.status?.type === "running");
1003
- const { copy, isCopied } = useActionBarCopy({
1004
- copyToClipboard: (text) => navigator.clipboard.writeText(text)
1005
- });
1006
- const parts = useAuiState5((s) => s.message.parts);
1007
- const { cutIndex, hasFinal, toolCount, thinkingCount } = computeAgentStepsSplit(parts, isMessageRunning);
1008
- const groupBy = (part, _context) => {
1009
- const index = parts.findIndex((p) => p === part);
1010
- if (index === -1) return null;
1011
- if (part.type === "text" && index >= cutIndex) {
1012
- return null;
1013
- }
1014
- if (index < cutIndex) {
1015
- if (part.type === "reasoning") {
1016
- return ["group-agentSteps", "group-reasoning"];
1017
- }
1018
- return ["group-agentSteps"];
1019
- }
1020
- return null;
1021
- };
1022
- return /* @__PURE__ */ jsx10(MessagePrimitive2.Root, { "data-role": "assistant", children: /* @__PURE__ */ jsx10(
1023
- AssistantMessageBubble,
1024
- {
1025
- error: error !== void 0 ? /* @__PURE__ */ jsx10(MessageErrorBanner, { message: String(error) }) : void 0,
1026
- actionBar: !isThreadRunning ? /* @__PURE__ */ jsx10(MessageActionBar, { isCopied, onCopy: copy, createdAt }) : void 0,
1027
- children: /* @__PURE__ */ jsx10(MessagePrimitive2.GroupedParts, { groupBy, children: ({ part, children }) => {
1028
- switch (part.type) {
1029
- case "group-agentSteps":
1030
- return /* @__PURE__ */ jsx10(AgentStepsContainer, { toolCount, thinkingCount, hasFinal, children });
1031
- case "group-reasoning":
1032
- return /* @__PURE__ */ jsx10(ReasoningContainer, { group: part });
1033
- case "text": {
1034
- const index = parts.findIndex((p) => p === part);
1035
- if (index >= 0 && index < cutIndex) {
1036
- return /* @__PURE__ */ jsx10("div", { className: "mb-2 ml-[1.75rem] text-xs text-text-secondary [&_.markdown-body]:text-inherit", children: /* @__PURE__ */ jsx10(AssistantTextContainer, {}) });
1037
- }
1038
- return /* @__PURE__ */ jsx10(AssistantTextContainer, {});
1039
- }
1040
- case "reasoning":
1041
- case "tool-call":
1042
- case "image":
1043
- case "data":
1044
- return /* @__PURE__ */ jsx10(AssistantLeafPartContainer, { part });
1045
- case "indicator":
1046
- return resumeUnavailable ? null : /* @__PURE__ */ jsx10(MessageIndicator, {});
1047
- default:
1048
- return null;
1049
- }
1050
- } })
1051
- }
1052
- ) });
1053
- }
1054
-
1055
- // src/containers/AttachmentsContainer.tsx
1056
- import { ComposerPrimitive, MessagePrimitive as MessagePrimitive3, useAui as useAui2, useAuiState as useAuiState7 } from "@assistant-ui/react";
1057
-
1058
- // src/containers/useAttachmentPreviewSrc.ts
1059
- import { useAuiState as useAuiState6 } from "@assistant-ui/react";
1060
- import { useEffect as useEffect5, useState as useState9 } from "react";
1061
- function isImageAttachment(type, contentType) {
1062
- return type === "image" || (contentType?.startsWith("image/") ?? false);
1063
- }
1064
- function useFileObjectUrl(file) {
1065
- const [src, setSrc] = useState9(void 0);
1066
- useEffect5(() => {
1067
- if (!file) {
1068
- setSrc(void 0);
1069
- return;
1070
- }
1071
- const objectUrl = URL.createObjectURL(file);
1072
- setSrc(objectUrl);
1073
- return () => URL.revokeObjectURL(objectUrl);
1074
- }, [file]);
1075
- return src;
1076
- }
1077
- function useAttachmentPreviewSrc() {
1078
- const type = useAuiState6((s) => s.attachment.type);
1079
- const contentType = useAuiState6((s) => s.attachment.contentType);
1080
- const file = useAuiState6((s) => "file" in s.attachment ? s.attachment.file : void 0);
1081
- const contentSrc = useAuiState6((s) => {
1082
- if (!isImageAttachment(s.attachment.type, s.attachment.contentType)) return void 0;
1083
- const imagePart = s.attachment.content?.find((part) => part.type === "image");
1084
- if (imagePart?.type === "image" && imagePart.image) return imagePart.image;
1085
- return void 0;
1086
- });
1087
- const image = isImageAttachment(type, contentType);
1088
- const fileSrc = useFileObjectUrl(image ? file : void 0);
1089
- if (!image) return void 0;
1090
- return fileSrc ?? contentSrc;
1091
- }
1092
-
1093
- // src/containers/AttachmentsContainer.tsx
1094
- import { jsx as jsx11 } from "react/jsx-runtime";
1095
- function ComposerAttachmentItem() {
1096
- const AttachmentPreviewDialog = useSlot("AttachmentPreviewDialog");
1097
- const AttachmentCard = useSlot("AttachmentCard");
1098
- const aui = useAui2();
1099
- const name = useAuiState7((s) => s.attachment.name);
1100
- const contentType = useAuiState7((s) => s.attachment.contentType);
1101
- const type = useAuiState7((s) => s.attachment.type);
1102
- const isImage = isImageAttachment(type, contentType);
1103
- const previewSrc = useAttachmentPreviewSrc();
1104
- return /* @__PURE__ */ jsx11(AttachmentPreviewDialog, { previewSrc, children: /* @__PURE__ */ jsx11(
1105
- AttachmentCard,
1106
- {
1107
- name,
1108
- contentType,
1109
- previewSrc,
1110
- isImage,
1111
- size: "chip",
1112
- onRemove: () => void aui.attachment().remove()
1113
- }
1114
- ) });
1115
- }
1116
- function MessageAttachmentItem() {
1117
- const AttachmentPreviewDialog = useSlot("AttachmentPreviewDialog");
1118
- const AttachmentCard = useSlot("AttachmentCard");
1119
- const name = useAuiState7((s) => s.attachment.name);
1120
- const contentType = useAuiState7((s) => s.attachment.contentType);
1121
- const type = useAuiState7((s) => s.attachment.type);
1122
- const isImage = isImageAttachment(type, contentType);
1123
- const previewSrc = useAttachmentPreviewSrc();
1124
- const card = /* @__PURE__ */ jsx11(
1125
- AttachmentCard,
1126
- {
1127
- name,
1128
- contentType,
1129
- previewSrc,
1130
- isImage,
1131
- size: isImage ? "preview" : "chip",
1132
- previewRem: USER_MESSAGE_ATTACHMENT_PREVIEW_REM
1133
- }
1134
- );
1135
- if (isImage && previewSrc) {
1136
- return /* @__PURE__ */ jsx11(AttachmentPreviewDialog, { previewSrc, children: card });
1137
- }
1138
- return card;
1139
- }
1140
- function ComposerAttachmentsContainer() {
1141
- return /* @__PURE__ */ jsx11("div", { className: "aui-composer-attachments flex w-full flex-row flex-wrap items-center gap-2 empty:hidden", children: /* @__PURE__ */ jsx11(ComposerPrimitive.Attachments, { children: () => /* @__PURE__ */ jsx11(ComposerAttachmentItem, {}) }) });
1142
- }
1143
- function MessageAttachmentsContainer() {
1144
- return /* @__PURE__ */ jsx11("div", { className: "aui-user-message-attachments-end col-span-full col-start-1 row-start-1 flex w-full flex-row justify-end gap-2", children: /* @__PURE__ */ jsx11(MessagePrimitive3.Attachments, { children: () => /* @__PURE__ */ jsx11(MessageAttachmentItem, {}) }) });
1145
- }
1146
- function ComposerAttachmentPickerContainer() {
1147
- const AttachmentPickerButton = useSlot("AttachmentPickerButton");
1148
- return /* @__PURE__ */ jsx11(ComposerPrimitive.AddAttachment, { asChild: true, children: /* @__PURE__ */ jsx11(AttachmentPickerButton, {}) });
1149
- }
1150
-
1151
- // src/hooks/useComposerPauseView.ts
1152
- import { useAuiState as useAuiState8 } from "@assistant-ui/react";
1153
- import { useTrueFoundryToolResponses as useTrueFoundryToolResponses2 } from "@truefoundry/assistant-ui-runtime";
1154
- function threadHasPendingMcpAuth(s) {
1155
- const messages = s.thread.messages;
1156
- const last = messages[messages.length - 1];
1157
- if (last?.role !== "assistant") return false;
1158
- if (last.status?.type !== "requires-action") return false;
1159
- return last.metadata?.custom?.pendingMcpAuth === true;
1160
- }
1161
- function useComposerPauseView() {
1162
- const mcpPending = useAuiState8(threadHasPendingMcpAuth);
1163
- const { pending: toolResponsesPending } = useTrueFoundryToolResponses2();
1164
- if (mcpPending) {
1165
- return { kind: "mcp" };
1166
- }
1167
- if (toolResponsesPending.length > 0) {
1168
- return { kind: "ask-user" };
1169
- }
1170
- return { kind: "compose" };
1171
- }
1172
-
1173
- // src/containers/McpAuthContainer.tsx
1174
- import { useThreadIsRunning as useThreadIsRunning3 } from "@assistant-ui/core/react";
1175
- import { useTrueFoundryMcpAuth } from "@truefoundry/assistant-ui-runtime";
1176
- import { jsx as jsx12 } from "react/jsx-runtime";
1177
- function CatalogMcpAuthPrompt({ servers, onContinue, readOnly }) {
1178
- const McpAuthPrompt = useSlot("McpAuthPrompt");
1179
- const { handleAuthorize } = useMCPAuth();
1180
- const { refreshConnectors } = useDraftCatalog();
1181
- const handleConnect = (serverId) => {
1182
- void handleAuthorize(serverId, (isSuccess) => {
1183
- if (isSuccess) {
1184
- void refreshConnectors();
1185
- }
1186
- });
1187
- };
1188
- return /* @__PURE__ */ jsx12(McpAuthPrompt, { servers, onConnect: handleConnect, onContinue, readOnly });
1189
- }
1190
- function McpAuthContainer() {
1191
- const McpAuthPrompt = useSlot("McpAuthPrompt");
1192
- const { pending, resume } = useTrueFoundryMcpAuth();
1193
- const isRunning = useThreadIsRunning3();
1194
- const catalog = useOptionalCatalogServer();
1195
- if (!pending) return null;
1196
- if (catalog) {
1197
- return /* @__PURE__ */ jsx12(CatalogMcpAuthPrompt, { servers: pending.mcpServers, onContinue: () => void resume(), readOnly: isRunning });
1198
- }
1199
- const handleConnect = (serverId) => {
1200
- const server = pending.mcpServers.find((s) => s.id === serverId);
1201
- if (server?.authUrl) {
1202
- window.open(server.authUrl, "_blank", "noopener,noreferrer");
1203
- }
1204
- };
1205
- return /* @__PURE__ */ jsx12(
1206
- McpAuthPrompt,
1207
- {
1208
- servers: pending.mcpServers,
1209
- onConnect: handleConnect,
1210
- onContinue: () => void resume(),
1211
- readOnly: isRunning
1212
- }
1213
- );
1214
- }
1215
-
1216
- // src/containers/ComposerContainer.tsx
1217
- import { ComposerPrimitive as ComposerPrimitive2, useAui as useAui3, useAuiState as useAuiState9 } from "@assistant-ui/react";
1218
- import { useTrueFoundryAgentSpec, useTrueFoundryCancel } from "@truefoundry/assistant-ui-runtime";
1219
- import { useRef as useRef6 } from "react";
1220
- import { Fragment, jsx as jsx13, jsxs } from "react/jsx-runtime";
1221
- function ComposerBody({ placeholder }) {
1222
- const ComposerShell = useSlot("ComposerShell");
1223
- const aui = useAui3();
1224
- const shell = useOptionalShellMode();
1225
- const hasText = useAuiState9((s) => s.composer.text.trim().length > 0);
1226
- const { agentSpec } = useTrueFoundryAgentSpec();
1227
- const requiresModel = shell == null || shell.mode.status === "active" && shell.mode.isMutable;
1228
- const hasModel = Boolean(agentSpec?.model?.name?.trim());
1229
- const { isBusy, send, resetBusy } = useComposerBusyState();
1230
- const cancel = useTrueFoundryCancel();
1231
- const fileInputRef = useRef6(null);
1232
- const canSubmit = !isBusy && hasText && (!requiresModel || hasModel);
1233
- const submit = () => {
1234
- if (!canSubmit) return;
1235
- send(() => aui.composer().send());
1236
- };
1237
- return /* @__PURE__ */ jsxs(Fragment, { children: [
1238
- /* @__PURE__ */ jsx13(
1239
- "input",
1240
- {
1241
- ref: fileInputRef,
1242
- type: "file",
1243
- multiple: true,
1244
- hidden: true,
1245
- onChange: (event) => {
1246
- const files = event.target.files;
1247
- if (files) {
1248
- for (const file of files) {
1249
- void aui.composer().addAttachment(file);
1250
- }
1251
- }
1252
- event.target.value = "";
1253
- }
1254
- }
1255
- ),
1256
- /* @__PURE__ */ jsx13(
1257
- ComposerPrimitive2.AttachmentDropzone,
1258
- {
1259
- disabled: isBusy,
1260
- "data-slot": "aui_composer-attachment-dropzone",
1261
- className: "w-full rounded-[var(--composer-radius,1.5rem)] transition-[box-shadow] data-[dragging=true]:ring-focus-ring/20 data-[dragging=true]:ring-3",
1262
- children: /* @__PURE__ */ jsx13(
1263
- ComposerPrimitive2.Root,
1264
- {
1265
- "data-slot": "aui_composer-root",
1266
- className: "w-full",
1267
- onSubmit: (event) => {
1268
- event.preventDefault();
1269
- submit();
1270
- },
1271
- children: /* @__PURE__ */ jsx13(
1272
- ComposerShell,
1273
- {
1274
- attachments: /* @__PURE__ */ jsx13(ComposerAttachmentsContainer, {}),
1275
- input: /* @__PURE__ */ jsx13(
1276
- ComposerPrimitive2.Input,
1277
- {
1278
- "data-slot": "aui_composer-input",
1279
- placeholder,
1280
- disabled: isBusy,
1281
- submitMode: "enter",
1282
- "aria-label": "Message input",
1283
- className: "text-text-primary placeholder:text-text-secondary/80 max-h-[10lh] min-h-10 w-full resize-none overflow-y-auto rounded-lg border-none bg-transparent px-1 py-1 text-base leading-normal shadow-none outline-none disabled:cursor-not-allowed"
1284
- }
1285
- ),
1286
- disabled: isBusy,
1287
- canSubmit,
1288
- isRunning: isBusy,
1289
- onSubmit: submit,
1290
- onCancel: () => {
1291
- resetBusy();
1292
- void cancel();
1293
- },
1294
- onAttach: () => fileInputRef.current?.click()
1295
- }
1296
- )
1297
- }
1298
- )
1299
- }
1300
- )
1301
- ] });
1302
- }
1303
- function ComposerContainer({
1304
- placeholder = "Ask anything... (Shift+Enter for new line)"
1305
- }) {
1306
- const pauseView = useComposerPauseView();
1307
- const shell = useOptionalShellMode();
1308
- const parentLeftSection = useSlot("ComposerLeftSection");
1309
- const parentRightSection = useSlot("ComposerRightSection");
1310
- const usesDefaultLeftSection = useSlotIsDefault("ComposerLeftSection");
1311
- const usesDefaultRightSection = useSlotIsDefault("ComposerRightSection");
1312
- const DraftComposerLeftSection = useSlot("DraftComposerLeftSection");
1313
- const DraftComposerRightSection = useSlot("DraftComposerRightSection");
1314
- const canMutateSpec = shell?.mode.status === "active" && shell.mode.isMutable;
1315
- if (pauseView.kind === "mcp") {
1316
- return /* @__PURE__ */ jsx13(McpAuthContainer, {});
1317
- }
1318
- if (pauseView.kind === "ask-user") {
1319
- return /* @__PURE__ */ jsx13(AskUserContainer, {});
1320
- }
1321
- if (canMutateSpec) {
1322
- return /* @__PURE__ */ jsx13(DraftCatalogProvider, { children: /* @__PURE__ */ jsx13(
1323
- SlotsProvider,
1324
- {
1325
- overrides: {
1326
- ComposerLeftSection: usesDefaultLeftSection ? DraftComposerLeftSection : parentLeftSection,
1327
- ComposerRightSection: usesDefaultRightSection ? DraftComposerRightSection : parentRightSection
1328
- },
1329
- children: /* @__PURE__ */ jsx13(ComposerBody, { placeholder })
1330
- }
1331
- ) });
1332
- }
1333
- return /* @__PURE__ */ jsx13(ComposerBody, { placeholder });
1334
- }
1335
-
1336
- // src/containers/HistoryLoaderContainer.tsx
1337
- import { useTrueFoundryHistoryPagination } from "@truefoundry/assistant-ui-runtime";
1338
- import { useCallback as useCallback6, useEffect as useEffect6, useRef as useRef7, useState as useState10 } from "react";
1339
- import { jsx as jsx14 } from "react/jsx-runtime";
1340
- var TOP_THRESHOLD_PX = 200;
1341
- var VIEWPORT_SELECTOR = '[data-slot="aui_thread-viewport"]';
1342
- function HistoryLoaderContainer() {
1343
- const HistoryLoader = useSlot("HistoryLoader");
1344
- const { hasOlderHistory, isLoadingOlderHistory, loadOlderHistory } = useTrueFoundryHistoryPagination();
1345
- const [sentinel, setSentinel] = useState10(null);
1346
- const inflightRef = useRef7(false);
1347
- const maybeLoadOlder = useCallback6(async () => {
1348
- if (inflightRef.current) return;
1349
- inflightRef.current = true;
1350
- const viewport = sentinel?.closest(VIEWPORT_SELECTOR) ?? null;
1351
- const prevScrollHeight = viewport?.scrollHeight ?? 0;
1352
- const prevScrollTop = viewport?.scrollTop ?? 0;
1353
- try {
1354
- await loadOlderHistory();
1355
- requestAnimationFrame(() => {
1356
- if (viewport == null) return;
1357
- const delta = viewport.scrollHeight - prevScrollHeight;
1358
- if (delta > 0) {
1359
- viewport.scrollTo({ top: prevScrollTop + delta, behavior: "instant" });
1360
- }
1361
- });
1362
- } catch {
1363
- } finally {
1364
- inflightRef.current = false;
1365
- }
1366
- }, [sentinel, loadOlderHistory]);
1367
- useEffect6(() => {
1368
- if (sentinel == null || !hasOlderHistory) return;
1369
- const viewport = sentinel.closest(VIEWPORT_SELECTOR);
1370
- const observer = new IntersectionObserver(
1371
- (entries) => {
1372
- if (entries.some((entry) => entry.isIntersecting)) {
1373
- void maybeLoadOlder();
1374
- }
1375
- },
1376
- { root: viewport, rootMargin: `${TOP_THRESHOLD_PX}px 0px 0px 0px` }
1377
- );
1378
- observer.observe(sentinel);
1379
- return () => observer.disconnect();
1380
- }, [sentinel, hasOlderHistory, maybeLoadOlder]);
1381
- if (!hasOlderHistory) return null;
1382
- return /* @__PURE__ */ jsx14(HistoryLoader, { ref: setSentinel, isLoading: isLoadingOlderHistory });
1383
- }
1384
-
1385
- // src/containers/ResumeUnavailableContainer.tsx
1386
- import { useTrueFoundryResumeUnavailable as useTrueFoundryResumeUnavailable2 } from "@truefoundry/assistant-ui-runtime";
1387
- import { jsx as jsx15 } from "react/jsx-runtime";
1388
- function ResumeUnavailableContainer() {
1389
- const ResumeUnavailable = useSlot("ResumeUnavailable");
1390
- const resumeUnavailable = useTrueFoundryResumeUnavailable2();
1391
- if (!resumeUnavailable) return null;
1392
- return /* @__PURE__ */ jsx15(ResumeUnavailable, {});
1393
- }
1394
-
1395
- // src/containers/UserEditComposerContainer.tsx
1396
- import { useComposerCancel, useComposerSend, useThreadIsRunning as useThreadIsRunning4 } from "@assistant-ui/core/react";
1397
- import { ComposerPrimitive as ComposerPrimitive3, MessagePrimitive as MessagePrimitive4, useAuiState as useAuiState10 } from "@assistant-ui/react";
1398
- import { jsx as jsx16, jsxs as jsxs2 } from "react/jsx-runtime";
1399
- function ReadOnlyMessageAttachments() {
1400
- const hasAttachments = useAuiState10((s) => (s.message.attachments?.length ?? 0) > 0);
1401
- if (!hasAttachments) {
1402
- return null;
1403
- }
1404
- return /* @__PURE__ */ jsx16("div", { className: "pointer-events-none mb-2 opacity-90", children: /* @__PURE__ */ jsx16(MessageAttachmentsContainer, {}) });
1405
- }
1406
- function UserEditComposerContainer() {
1407
- const UserMessageEdit = useSlot("UserMessageEdit");
1408
- const MessageTimestamp = useSlot("MessageTimestamp");
1409
- const isRunning = useThreadIsRunning4();
1410
- const createdAt = useAuiState10((s) => s.message.createdAt);
1411
- const { cancel, disabled: cancelDisabled } = useComposerCancel();
1412
- const { disabled: sendDisabled } = useComposerSend();
1413
- return /* @__PURE__ */ jsx16(MessagePrimitive4.Root, { "data-role": "user", children: /* @__PURE__ */ jsx16(
1414
- ComposerPrimitive3.Root,
1415
- {
1416
- "data-slot": "aui_user-edit-composer-root",
1417
- className: "fade-in slide-in-from-bottom-1 animate-in flex w-full justify-end px-2 duration-150",
1418
- children: /* @__PURE__ */ jsx16(
1419
- UserMessageEdit,
1420
- {
1421
- timestamp: /* @__PURE__ */ jsx16(MessageTimestamp, { createdAt }),
1422
- attachments: /* @__PURE__ */ jsx16(ReadOnlyMessageAttachments, {}),
1423
- input: /* @__PURE__ */ jsx16("div", { className: "mt-1 rounded border border-border bg-secondary-bg p-2 text-text-primary", children: /* @__PURE__ */ jsx16(
1424
- ComposerPrimitive3.Input,
1425
- {
1426
- "data-slot": "aui_user-edit-input",
1427
- disabled: isRunning,
1428
- submitMode: "enter",
1429
- "aria-label": "Edit message",
1430
- className: "max-h-32 min-h-10 w-full resize-none border-none bg-transparent p-0 text-base leading-[1.34] outline-none focus:shadow-none"
1431
- }
1432
- ) }),
1433
- footer: /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-end gap-2", children: [
1434
- /* @__PURE__ */ jsx16(Button, { variant: "secondary", type: "button", disabled: cancelDisabled, onClick: cancel, children: "Cancel" }),
1435
- /* @__PURE__ */ jsx16(ComposerPrimitive3.Send, { asChild: true, children: /* @__PURE__ */ jsx16(Button, { type: "submit", disabled: sendDisabled || isRunning, children: "Save & Rerun" }) })
1436
- ] })
1437
- }
1438
- )
1439
- }
1440
- ) });
1441
- }
1442
-
1443
- // src/containers/UserMessageContainer.tsx
1444
- import { useActionBarCopy as useActionBarCopy2, useActionBarEdit, useThreadIsRunning as useThreadIsRunning5 } from "@assistant-ui/core/react";
1445
- import { MessagePrimitive as MessagePrimitive5, useAui as useAui4, useAuiState as useAuiState11 } from "@assistant-ui/react";
1446
- import { jsx as jsx17 } from "react/jsx-runtime";
1447
- function UserMessageContainer() {
1448
- const UserMessageBubble = useSlot("UserMessageBubble");
1449
- const UserMessageActionBar = useSlot("UserMessageActionBar");
1450
- const isRunning = useThreadIsRunning5();
1451
- const aui = useAui4();
1452
- const createdAt = useAuiState11((s) => s.message.createdAt);
1453
- const text = useAuiState11(
1454
- (s) => s.message.content.filter((part) => part.type === "text").map((part) => part.text).join("\n")
1455
- );
1456
- const { edit, disabled: editDisabled } = useActionBarEdit();
1457
- const { copy, isCopied } = useActionBarCopy2({
1458
- copyToClipboard: (value) => navigator.clipboard.writeText(value)
1459
- });
1460
- return /* @__PURE__ */ jsx17(MessagePrimitive5.Root, { "data-role": "user", children: /* @__PURE__ */ jsx17(
1461
- UserMessageBubble,
1462
- {
1463
- text,
1464
- attachments: /* @__PURE__ */ jsx17(MessageAttachmentsContainer, {}),
1465
- editAction: !isRunning ? /* @__PURE__ */ jsx17(
1466
- UserMessageActionBar,
1467
- {
1468
- isCopied,
1469
- editDisabled,
1470
- createdAt,
1471
- onCopy: copy,
1472
- onEdit: edit,
1473
- onRetry: () => {
1474
- aui.message().composer().beginEdit();
1475
- aui.message().composer().send({ startRun: true });
1476
- }
1477
- }
1478
- ) : void 0
1479
- }
1480
- ) });
1481
- }
1482
-
1483
- // src/containers/ThreadContainer.tsx
1484
- import { ThreadPrimitive, useAuiState as useAuiState12 } from "@assistant-ui/react";
1485
- import { useEffect as useEffect8 } from "react";
1486
-
1487
- // src/hooks/useSyncSessionTitle.ts
1488
- import { useThreadIsRunning as useThreadIsRunning6 } from "@assistant-ui/core/react";
1489
- import { useEffect as useEffect7, useRef as useRef8 } from "react";
1490
- function useSyncSessionTitle() {
1491
- const server = useOptionalServer();
1492
- const aui = useAui();
1493
- const remoteId = useAuiState((s) => s.threadListItem.remoteId);
1494
- const title = useAuiState((s) => s.threadListItem.title);
1495
- const isRunning = useThreadIsRunning6();
1496
- const wasRunningRef = useRef8(false);
1497
- const syncedRemoteIdRef = useRef8(void 0);
1498
- useEffect7(() => {
1499
- syncedRemoteIdRef.current = void 0;
1500
- }, [remoteId]);
1501
- useEffect7(() => {
1502
- const finishedTurn = wasRunningRef.current && !isRunning;
1503
- wasRunningRef.current = isRunning;
1504
- if (!finishedTurn || server == null || remoteId == null) {
1505
- return;
1506
- }
1507
- if (syncedRemoteIdRef.current === remoteId) {
1508
- return;
1509
- }
1510
- if (title != null && title.trim() !== "") {
1511
- syncedRemoteIdRef.current = remoteId;
1512
- return;
1513
- }
1514
- let cancelled = false;
1515
- void server.getSession({ sessionId: remoteId }).then((session) => {
1516
- if (cancelled) return;
1517
- const nextTitle = typeof session.title === "string" ? session.title.trim() : "";
1518
- if (nextTitle.length === 0) return;
1519
- syncedRemoteIdRef.current = remoteId;
1520
- return aui.threadListItem().rename(nextTitle);
1521
- }).catch(() => void 0);
1522
- return () => {
1523
- cancelled = true;
1524
- };
1525
- }, [aui, isRunning, remoteId, server, title]);
1526
- }
1527
-
1528
- // src/utils/isNewChatView.ts
1529
- var isNewChatView = (s) => s.thread.messages.length === 0 && (!s.thread.isLoading || s.threads.isLoading) && s.threadListItem.remoteId == null;
1530
-
1531
- // src/containers/ThreadContainer.tsx
1532
- import { Fragment as Fragment2, jsx as jsx18, jsxs as jsxs3 } from "react/jsx-runtime";
1533
- function AnimatedMessageShell({ children }) {
1534
- return /* @__PURE__ */ jsx18("div", { className: "animate-in fade-in slide-in-from-bottom-1 fill-mode-both duration-200", children });
1535
- }
1536
- function ThreadMessage({ isEditing }) {
1537
- const role = useAuiState12((s) => s.message.role);
1538
- if (role === "user") {
1539
- if (isEditing) {
1540
- return /* @__PURE__ */ jsx18(UserEditComposerContainer, {});
1541
- }
1542
- return /* @__PURE__ */ jsx18(UserMessageContainer, {});
1543
- }
1544
- return /* @__PURE__ */ jsx18(AssistantMessageContainer, {});
1545
- }
1546
- function ThreadContainer({ composer }) {
1547
- useEffect8(() => {
1548
- void preloadMarkdownOpenUI();
1549
- }, []);
1550
- useSyncSessionTitle();
1551
- const shell = useOptionalShellMode();
1552
- const WelcomeScreen = useSlot("WelcomeScreen");
1553
- const MessageListSkeleton = useSlot("MessageListSkeleton");
1554
- const ScrollToBottomButton = useSlot("ScrollToBottomButton");
1555
- const MessageGroup = useSlot("MessageGroup");
1556
- const ThreadComposerAreaShell = useSlot("ThreadComposerAreaShell");
1557
- const ThreadRootShell = useSlot("ThreadRootShell");
1558
- const ThreadViewportShell = useSlot("ThreadViewportShell");
1559
- const isEmpty = useAuiState12(isNewChatView);
1560
- const isLoading = useAuiState12((s) => s.thread.isLoading);
1561
- const welcomeHeading = shell?.mode.status === "active" ? shell.mode.agentName : void 0;
1562
- return /* @__PURE__ */ jsx18(ComposerBusyProvider, { children: /* @__PURE__ */ jsx18(ThreadPrimitive.Root, { asChild: true, children: /* @__PURE__ */ jsxs3(ThreadRootShell, { children: [
1563
- /* @__PURE__ */ jsx18(ThreadPrimitive.Viewport, { asChild: true, autoScroll: true, children: /* @__PURE__ */ jsxs3(ThreadViewportShell, { isEmpty, children: [
1564
- isEmpty && /* @__PURE__ */ jsx18(WelcomeScreen, { heading: welcomeHeading }),
1565
- isEmpty && !isLoading && composer,
1566
- isLoading ? /* @__PURE__ */ jsx18(MessageListSkeleton, {}) : !isEmpty && /* @__PURE__ */ jsxs3(Fragment2, { children: [
1567
- /* @__PURE__ */ jsx18(HistoryLoaderContainer, {}),
1568
- /* @__PURE__ */ jsxs3(MessageGroup, { children: [
1569
- /* @__PURE__ */ jsx18(ThreadPrimitive.Messages, { children: ({ message }) => /* @__PURE__ */ jsx18(AnimatedMessageShell, { children: /* @__PURE__ */ jsx18(ThreadMessage, { isEditing: message.role === "user" && message.composer.isEditing }) }) }),
1570
- /* @__PURE__ */ jsx18(ResumeUnavailableContainer, {})
1571
- ] })
1572
- ] })
1573
- ] }) }),
1574
- !isLoading && !isEmpty && /* @__PURE__ */ jsxs3(ThreadComposerAreaShell, { isEmpty, children: [
1575
- /* @__PURE__ */ jsx18(ThreadPrimitive.ScrollToBottom, { asChild: true, children: /* @__PURE__ */ jsx18(ScrollToBottomButton, {}) }),
1576
- composer
1577
- ] })
1578
- ] }) }) });
1579
- }
1580
-
1581
- // src/containers/Thread.tsx
1582
- import { jsx as jsx19 } from "react/jsx-runtime";
1583
- function Thread() {
1584
- return /* @__PURE__ */ jsx19(ThreadContainer, { composer: /* @__PURE__ */ jsx19(ComposerContainer, {}) });
1585
- }
1586
-
1587
- // src/containers/ThreadListContainer.tsx
1588
- import {
1589
- ThreadListItemByIndexProvider,
1590
- ThreadListItemMorePrimitive,
1591
- ThreadListItemPrimitive,
1592
- ThreadListPrimitive,
1593
- useAui as useAui5,
1594
- useAuiState as useAuiState13
1595
- } from "@assistant-ui/react";
1596
- import { useEffect as useEffect11, useMemo as useMemo5, useRef as useRef11, useState as useState13 } from "react";
1597
-
1598
- // src/atoms/AgentHistoryFilterButton.tsx
1599
- import { useEffect as useEffect10, useId as useId2, useLayoutEffect, useRef as useRef10, useState as useState12 } from "react";
1600
- import { createPortal } from "react-dom";
1601
-
1602
- // src/atoms/primitives/DropdownMenu.tsx
1603
- import React, { useEffect as useEffect9, useId, useRef as useRef9, useState as useState11 } from "react";
1604
- import { jsx as jsx20, jsxs as jsxs4 } from "react/jsx-runtime";
1605
- function DropdownMenuItem({ className, ...props }) {
1606
- return /* @__PURE__ */ jsx20(
1607
- "button",
1608
- {
1609
- role: "menuitem",
1610
- type: "button",
1611
- className: cn(
1612
- "flex w-full cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none",
1613
- "transition-colors hover:bg-ghost-button-hover",
1614
- "focus:bg-dropdown-selected-item-bg focus:text-dropdown-selected-item-text",
1615
- "aria-selected:bg-dropdown-selected-item-bg aria-selected:text-dropdown-selected-item-text",
1616
- "disabled:pointer-events-none disabled:opacity-50",
1617
- className
1618
- ),
1619
- ...props
1620
- }
1621
- );
1622
- }
1623
-
1624
- // src/atoms/AgentHistoryFilterButton.tsx
1625
- import { Fragment as Fragment3, jsx as jsx21, jsxs as jsxs5 } from "react/jsx-runtime";
1626
- function themePortalRoot(from) {
1627
- return from?.closest(".aui-theme-root") ?? document.body;
1628
- }
1629
- function AgentHistoryFilterButton() {
1630
- const shell = useOptionalShellMode();
1631
- const server = useOptionalServer();
1632
- const isMobile = useIsMobile();
1633
- const compact = useCompactLayout();
1634
- const useSheet = isMobile || compact;
1635
- const [open, setOpen] = useState12(false);
1636
- const [query, setQuery] = useState12("");
1637
- const [menuPos, setMenuPos] = useState12(null);
1638
- const buttonRef = useRef10(null);
1639
- const menuRef = useRef10(null);
1640
- const menuId = useId2();
1641
- const enabled = shell?.isLibraryEnabled === true && server != null;
1642
- const selected = shell?.historyAgentFilter ?? null;
1643
- useEffect10(() => {
1644
- if (!open) setQuery("");
1645
- }, [open]);
1646
- const { agents, isInitialLoading, isSearching, loadingMore, hasMore, listRef, sentinelRef } = useSearchAgentsList({
1647
- enabled: open && enabled,
1648
- query
1649
- });
1650
- useLayoutEffect(() => {
1651
- if (!open || useSheet) {
1652
- setMenuPos(null);
1653
- return;
1654
- }
1655
- const update = () => {
1656
- const rect = buttonRef.current?.getBoundingClientRect();
1657
- if (!rect) return;
1658
- setMenuPos({ top: rect.top, left: rect.right + 4 });
1659
- };
1660
- update();
1661
- window.addEventListener("resize", update);
1662
- window.addEventListener("scroll", update, true);
1663
- return () => {
1664
- window.removeEventListener("resize", update);
1665
- window.removeEventListener("scroll", update, true);
1666
- };
1667
- }, [open, useSheet]);
1668
- useEffect10(() => {
1669
- if (!open || useSheet) return;
1670
- const handler = (e) => {
1671
- const target = e.target;
1672
- if (buttonRef.current?.contains(target) || menuRef.current?.contains(target)) return;
1673
- setOpen(false);
1674
- };
1675
- document.addEventListener("mousedown", handler);
1676
- return () => document.removeEventListener("mousedown", handler);
1677
- }, [open, useSheet]);
1678
- if (!enabled) return null;
1679
- const pick = (agentId) => {
1680
- shell?.setHistoryAgentFilter(agentId);
1681
- setOpen(false);
1682
- };
1683
- const filterBody = /* @__PURE__ */ jsxs5(Fragment3, { children: [
1684
- /* @__PURE__ */ jsxs5("div", { className: "p-1", onMouseDown: (e) => e.stopPropagation(), children: [
1685
- /* @__PURE__ */ jsx21(SearchInput_default, { query, setQuery, placeholder: "Search agents" }),
1686
- isSearching ? /* @__PURE__ */ jsx21("p", { className: "text-text-secondary px-1 pt-1 text-[11px]", role: "status", children: "Searching\u2026" }) : null
1687
- ] }),
1688
- /* @__PURE__ */ jsxs5(
1689
- "div",
1690
- {
1691
- ref: listRef,
1692
- className: cn("mt-1 overflow-y-auto", useSheet ? "min-h-0 flex-1 px-1 pb-2" : "min-h-48 max-h-64"),
1693
- children: [
1694
- query.trim() === "" ? /* @__PURE__ */ jsxs5(
1695
- DropdownMenuItem,
1696
- {
1697
- className: cn(
1698
- "justify-between",
1699
- selected == null && "bg-dropdown-selected-item-bg text-dropdown-selected-item-text"
1700
- ),
1701
- onClick: () => pick(null),
1702
- children: [
1703
- "All chats",
1704
- selected == null ? /* @__PURE__ */ jsx21(Icon, { name: "check", className: "size-3.5 shrink-0" }) : null
1705
- ]
1706
- }
1707
- ) : null,
1708
- isInitialLoading ? /* @__PURE__ */ jsx21("p", { className: "px-2 py-3 text-center text-xs text-text-secondary", children: "Loading\u2026" }) : agents.length === 0 ? /* @__PURE__ */ jsx21("p", { className: "text-text-secondary px-2 py-6 text-center text-xs", role: "status", children: query.trim() ? `No agents match "${query.trim()}".` : "No agents yet." }) : /* @__PURE__ */ jsxs5(Fragment3, { children: [
1709
- agents.map((agent) => {
1710
- const id = libraryAgentId(agent);
1711
- const active = selected === id;
1712
- return /* @__PURE__ */ jsxs5(
1713
- DropdownMenuItem,
1714
- {
1715
- className: cn(
1716
- "justify-between gap-2 text-left",
1717
- active && "bg-dropdown-selected-item-bg text-dropdown-selected-item-text"
1718
- ),
1719
- onClick: () => pick(id),
1720
- children: [
1721
- /* @__PURE__ */ jsx21("span", { className: "min-w-0 truncate", children: agent.name }),
1722
- active ? /* @__PURE__ */ jsx21(Icon, { name: "check", className: "size-3.5 shrink-0" }) : null
1723
- ]
1724
- },
1725
- id
1726
- );
1727
- }),
1728
- hasMore ? /* @__PURE__ */ jsx21("div", { ref: sentinelRef, className: "flex h-6 shrink-0 items-center justify-center", "aria-hidden": true, children: loadingMore ? /* @__PURE__ */ jsx21("span", { className: "text-text-secondary text-[11px]", role: "status", children: "Loading more\u2026" }) : null }) : null
1729
- ] })
1730
- ]
1731
- }
1732
- )
1733
- ] });
1734
- return /* @__PURE__ */ jsxs5("div", { className: "relative shrink-0", children: [
1735
- /* @__PURE__ */ jsxs5(
1736
- "button",
1737
- {
1738
- ref: buttonRef,
1739
- type: "button",
1740
- "aria-label": selected != null ? `Filter chat history by agent (${selected})` : "Filter chat history by agent",
1741
- "aria-haspopup": useSheet ? "dialog" : "menu",
1742
- "aria-expanded": open,
1743
- "aria-controls": open ? menuId : void 0,
1744
- title: "Filter by agent",
1745
- className: auiButtonClass({
1746
- variant: "ghost",
1747
- size: "icon",
1748
- className: cn(
1749
- "relative size-7 shrink-0 text-text-secondary hover:bg-ghost-button-hover hover:text-ghost-button-text",
1750
- selected != null && "text-text-primary"
1751
- )
1752
- }),
1753
- onClick: () => setOpen((v) => !v),
1754
- children: [
1755
- /* @__PURE__ */ jsx21(Icon, { name: "funnel", className: "size-3.5" }),
1756
- selected != null ? /* @__PURE__ */ jsx21(
1757
- "span",
1758
- {
1759
- className: "bg-primary-button-bg absolute top-1 right-1 size-1.5 rounded-full",
1760
- "aria-hidden": true,
1761
- "data-testid": "history-filter-active-dot"
1762
- }
1763
- ) : null
1764
- ]
1765
- }
1766
- ),
1767
- useSheet && open ? /* @__PURE__ */ jsx21(BottomSheet, { open: true, onOpenChange: setOpen, id: menuId, "aria-label": "Filter agents", children: /* @__PURE__ */ jsx21("div", { className: "flex min-h-0 flex-1 flex-col p-2", role: "menu", children: filterBody }) }) : null,
1768
- !useSheet && open && menuPos != null ? createPortal(
1769
- /* @__PURE__ */ jsx21(
1770
- "div",
1771
- {
1772
- ref: menuRef,
1773
- id: menuId,
1774
- role: "menu",
1775
- "aria-label": "Filter agents",
1776
- style: { top: menuPos.top, left: menuPos.left },
1777
- className: "font-sans-flex fixed z-50 w-56 rounded-md border border-border bg-card-bg p-1 text-text-primary shadow-md",
1778
- children: filterBody
1779
- }
1780
- ),
1781
- themePortalRoot(buttonRef.current)
1782
- ) : null
1783
- ] });
1784
- }
1785
-
1786
- // src/containers/ThreadListContainer.tsx
1787
- import { Fragment as Fragment4, jsx as jsx22, jsxs as jsxs6 } from "react/jsx-runtime";
1788
- var deleteItemClass = "flex w-full cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none text-failure-bg hover:bg-ghost-button-hover hover:text-failure-bg focus:bg-ghost-button-hover focus:text-failure-bg data-[highlighted]:bg-ghost-button-hover data-[highlighted]:text-failure-bg";
1789
- function ThreadListItemDeleteMenu() {
1790
- const compact = useCompactLayout();
1791
- const isMobile = useIsMobile();
1792
- const [sheetOpen, setSheetOpen] = useState13(false);
1793
- const useSheet = isMobile || compact;
1794
- const moreButtonClass = auiButtonClass({
1795
- variant: "ghost",
1796
- size: "icon",
1797
- className: "size-7 shrink-0 text-text-secondary hover:bg-transparent hover:text-text-primary"
1798
- });
1799
- if (useSheet) {
1800
- return /* @__PURE__ */ jsxs6(Fragment4, { children: [
1801
- /* @__PURE__ */ jsx22(
1802
- "button",
1803
- {
1804
- type: "button",
1805
- "aria-label": "Session actions",
1806
- title: "Session actions",
1807
- "aria-haspopup": "dialog",
1808
- "aria-expanded": sheetOpen,
1809
- className: moreButtonClass,
1810
- onClick: () => setSheetOpen(true),
1811
- children: /* @__PURE__ */ jsx22(Icon, { name: "ellipsis", className: "size-3.5" })
1812
- }
1813
- ),
1814
- sheetOpen ? /* @__PURE__ */ jsx22(BottomSheet, { open: true, onOpenChange: setSheetOpen, "aria-label": "Session actions", children: /* @__PURE__ */ jsx22("div", { className: "flex flex-col gap-1 p-2", role: "menu", children: /* @__PURE__ */ jsxs6(ThreadListItemPrimitive.Delete, { className: deleteItemClass, onClick: () => setSheetOpen(false), children: [
1815
- /* @__PURE__ */ jsx22(Icon, { name: "trash", className: "size-3.5" }),
1816
- "Delete"
1817
- ] }) }) }) : null
1818
- ] });
1819
- }
1820
- return /* @__PURE__ */ jsxs6(ThreadListItemMorePrimitive.Root, { sharedFocusGroup: true, children: [
1821
- /* @__PURE__ */ jsx22(
1822
- ThreadListItemMorePrimitive.Trigger,
1823
- {
1824
- "aria-label": "Session actions",
1825
- title: "Session actions",
1826
- className: moreButtonClass,
1827
- children: /* @__PURE__ */ jsx22(Icon, { name: "ellipsis", className: "size-3.5" })
1828
- }
1829
- ),
1830
- /* @__PURE__ */ jsx22(
1831
- ThreadListItemMorePrimitive.Content,
1832
- {
1833
- align: "end",
1834
- sideOffset: 4,
1835
- className: "z-50 min-w-[8rem] rounded-md border border-border bg-card-bg p-1 text-text-primary shadow-md",
1836
- children: /* @__PURE__ */ jsx22(ThreadListItemPrimitive.Delete, { asChild: true, children: /* @__PURE__ */ jsxs6(ThreadListItemMorePrimitive.Item, { className: deleteItemClass, children: [
1837
- /* @__PURE__ */ jsx22(Icon, { name: "trash", className: "size-3.5" }),
1838
- "Delete"
1839
- ] }) })
1840
- }
1841
- )
1842
- ] });
1843
- }
1844
- function ThreadListItemRow({
1845
- onThreadOpen,
1846
- canDeleteSession
1847
- }) {
1848
- const aui = useAui5();
1849
- const shell = useOptionalShellMode();
1850
- const ThreadListRow = useSlot("ThreadListRow");
1851
- const id = useAuiState13((s) => s.threadListItem.id);
1852
- const remoteId = useAuiState13((s) => s.threadListItem.remoteId);
1853
- const title = useAuiState13((s) => s.threadListItem.title);
1854
- const lastMessageAt = useAuiState13((s) => s.threadListItem.lastMessageAt);
1855
- const custom = useAuiState13((s) => s.threadListItem.custom);
1856
- const mainThreadId = useAuiState13((s) => s.threads.mainThreadId);
1857
- const agentName = readThreadAgentName(custom);
1858
- const showDelete = canDeleteSession && remoteId != null;
1859
- return /* @__PURE__ */ jsx22(ThreadListItemPrimitive.Root, { className: "min-w-0", children: /* @__PURE__ */ jsx22(
1860
- ThreadListRow,
1861
- {
1862
- title: title ?? "New Chat",
1863
- active: id === mainThreadId,
1864
- agentName,
1865
- lastMessageAt,
1866
- onSelect: () => {
1867
- onThreadOpen?.();
1868
- shell?.setSettingsOpen(false);
1869
- const sessionMutable = threadListItemIsMutable(custom);
1870
- const sameImmutable = !sessionMutable && shell?.mode.status === "active" && !shell.mode.isMutable && (agentName == null ? shell.mode.agentName == null && shell.mode.agentId == null : shell.mode.agentName === agentName || shell.mode.agentId === agentName);
1871
- const sameMutable = canReuseMutableShell({
1872
- sessionMutable,
1873
- shellMutable: shell?.mode.status === "active" && shell.mode.isMutable,
1874
- ...shell?.mode.status === "active" && shell.mode.isMutable ? { shellAgentName: shell.mode.agentName, shellAgentId: shell.mode.agentId } : {},
1875
- remoteId,
1876
- pendingSessionId: shell?.pendingSessionId
1877
- });
1878
- if ((sameImmutable || sameMutable) && remoteId != null) {
1879
- void Promise.resolve(aui.threads().switchToThread(id)).catch(() => void 0);
1880
- return;
1881
- }
1882
- if (remoteId != null) {
1883
- shell?.openHistorySession({
1884
- sessionId: remoteId,
1885
- isMutable: sessionMutable,
1886
- ...agentName != null ? { agentName } : {}
1887
- });
1888
- return;
1889
- }
1890
- void Promise.resolve(aui.threads().switchToThread(id)).catch(() => void 0);
1891
- },
1892
- actions: showDelete ? /* @__PURE__ */ jsx22(ThreadListItemDeleteMenu, {}) : void 0
1893
- }
1894
- ) });
1895
- }
1896
- function useThreadListIndicesByRecency() {
1897
- const threadIds = useAuiState13((s) => s.threads.threadIds);
1898
- const threadItems = useAuiState13((s) => s.threads.threadItems);
1899
- return useMemo5(() => threadListIndicesByRecency({ threadIds, threadItems }), [threadIds, threadItems]);
1900
- }
1901
- function ThreadListItemsByRecency({
1902
- onThreadOpen,
1903
- canDeleteSession
1904
- }) {
1905
- const indices = useThreadListIndicesByRecency();
1906
- const threadIds = useAuiState13((s) => s.threads.threadIds);
1907
- return /* @__PURE__ */ jsx22(Fragment4, { children: indices.map((index) => {
1908
- const key = threadIds[index] ?? String(index);
1909
- return /* @__PURE__ */ jsx22(ThreadListItemByIndexProvider, { index, archived: false, children: /* @__PURE__ */ jsx22(ThreadListItemRow, { onThreadOpen, canDeleteSession }) }, key);
1910
- }) });
1911
- }
1912
- var THREAD_LIST_VIEWPORT_SLOT = "aui_thread-list-viewport";
1913
- var LOAD_MORE_BOTTOM_PX = 80;
1914
- function ChatHistorySection({ children, viewportRef }) {
1915
- const [expanded, setExpanded] = useState13(true);
1916
- const shell = useOptionalShellMode();
1917
- const showFilter = shell?.isLibraryEnabled === true;
1918
- return /* @__PURE__ */ jsxs6("div", { className: "flex min-h-0 flex-1 flex-col", children: [
1919
- /* @__PURE__ */ jsxs6("div", { className: "flex shrink-0 items-center gap-1 px-1 py-1", children: [
1920
- /* @__PURE__ */ jsxs6(
1921
- "button",
1922
- {
1923
- type: "button",
1924
- "aria-expanded": expanded,
1925
- className: "flex min-w-0 flex-1 items-center gap-1 rounded-md px-1.5 py-1 text-left text-sm font-medium text-text-secondary hover:bg-ghost-button-hover hover:text-text-primary",
1926
- onClick: () => setExpanded((v) => !v),
1927
- children: [
1928
- /* @__PURE__ */ jsx22("span", { className: "truncate", children: "Chat History" }),
1929
- /* @__PURE__ */ jsx22(
1930
- Icon,
1931
- {
1932
- name: "chevron-down",
1933
- className: cn("size-3.5 shrink-0 transition-transform", !expanded && "-rotate-90")
1934
- }
1935
- )
1936
- ]
1937
- }
1938
- ),
1939
- showFilter ? /* @__PURE__ */ jsx22(AgentHistoryFilterButton, {}) : null
1940
- ] }),
1941
- expanded ? /* @__PURE__ */ jsx22(
1942
- "div",
1943
- {
1944
- ref: viewportRef,
1945
- "data-slot": THREAD_LIST_VIEWPORT_SLOT,
1946
- className: "flex min-h-0 flex-1 flex-col gap-0.5 overflow-y-auto",
1947
- children
1948
- }
1949
- ) : null
1950
- ] });
1951
- }
1952
- function ThreadListContainer({ onThreadOpen } = {}) {
1953
- const aui = useAui5();
1954
- const server = useOptionalServer();
1955
- const isLoading = useAuiState13((s) => s.threads.isLoading);
1956
- const isLoadingMore = useAuiState13((s) => s.threads.isLoadingMore);
1957
- const hasMore = useAuiState13((s) => s.threads.hasMore);
1958
- const threadIds = useAuiState13((s) => s.threads.threadIds);
1959
- const shell = useOptionalShellMode();
1960
- const ThreadListShell = useSlot("ThreadListShell");
1961
- const ThreadListNewButton = useSlot("ThreadListNewButton");
1962
- const AgentsLibraryButton = useSlot("AgentsLibraryButton");
1963
- const ThreadListRowSkeleton = useSlot("ThreadListRowSkeleton");
1964
- const ThreadListEmptyState = useSlot("ThreadListEmptyState");
1965
- const viewportRef = useRef11(null);
1966
- const hasMoreRef = useRef11(hasMore);
1967
- const auiRef = useRef11(aui);
1968
- hasMoreRef.current = hasMore;
1969
- auiRef.current = aui;
1970
- const showNewChat = shell?.isNewChatEnabled !== false;
1971
- const isIdle = shell?.mode.status === "idle";
1972
- const canDeleteSession = typeof server?.deleteSession === "function";
1973
- useEffect11(() => {
1974
- if (isIdle || isLoading || isLoadingMore) return;
1975
- const viewport = viewportRef.current;
1976
- if (!viewport) return;
1977
- let cancelled = false;
1978
- const tryLoadMore = () => {
1979
- if (cancelled || !hasMoreRef.current) return;
1980
- if (viewport.clientHeight <= 0) return;
1981
- const remaining = viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight;
1982
- if (viewport.scrollHeight > viewport.clientHeight && remaining > LOAD_MORE_BOTTOM_PX) return;
1983
- void auiRef.current.threads().loadMore();
1984
- };
1985
- viewport.addEventListener("scroll", tryLoadMore, { passive: true });
1986
- const resizeObserver = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(() => tryLoadMore());
1987
- if (resizeObserver) {
1988
- resizeObserver.observe(viewport);
1989
- } else {
1990
- window.addEventListener("resize", tryLoadMore);
1991
- }
1992
- tryLoadMore();
1993
- return () => {
1994
- cancelled = true;
1995
- viewport.removeEventListener("scroll", tryLoadMore);
1996
- resizeObserver?.disconnect();
1997
- if (!resizeObserver) {
1998
- window.removeEventListener("resize", tryLoadMore);
1999
- }
2000
- };
2001
- }, [hasMore, isIdle, isLoading, isLoadingMore, threadIds.length]);
2002
- const handleNewChat = () => {
2003
- onThreadOpen?.();
2004
- if (shell?.isComposerEnabled) {
2005
- shell.openDraft();
2006
- return;
2007
- }
2008
- shell?.setSettingsOpen(false);
2009
- void Promise.resolve(aui.threads().switchToNewThread()).catch(() => void 0);
2010
- };
2011
- let listBody;
2012
- if (isIdle) {
2013
- listBody = /* @__PURE__ */ jsx22(ThreadListEmptyState, {});
2014
- } else if (isLoading) {
2015
- listBody = /* @__PURE__ */ jsx22(ThreadListRowSkeleton, {});
2016
- } else if (threadIds.length === 0) {
2017
- listBody = /* @__PURE__ */ jsx22(ThreadListEmptyState, {});
2018
- } else {
2019
- listBody = /* @__PURE__ */ jsx22(ThreadListPrimitive.Root, { className: "flex min-h-0 flex-col gap-0.5", children: /* @__PURE__ */ jsx22(ThreadListItemsByRecency, { onThreadOpen, canDeleteSession }) });
2020
- }
2021
- return /* @__PURE__ */ jsx22(
2022
- ThreadListShell,
2023
- {
2024
- header: /* @__PURE__ */ jsxs6("div", { className: "flex flex-col gap-1", children: [
2025
- showNewChat ? /* @__PURE__ */ jsx22(ThreadListNewButton, { onClick: handleNewChat }) : null,
2026
- /* @__PURE__ */ jsx22(
2027
- AgentsLibraryButton,
2028
- {
2029
- onSelectAgent: () => {
2030
- onThreadOpen?.();
2031
- }
2032
- }
2033
- )
2034
- ] }),
2035
- children: /* @__PURE__ */ jsxs6(ChatHistorySection, { viewportRef, children: [
2036
- listBody,
2037
- !isIdle && hasMore ? /* @__PURE__ */ jsx22("div", { className: "h-4 shrink-0", "aria-hidden": true }) : null
2038
- ] })
2039
- }
2040
- );
2041
- }
2042
-
2043
- export {
2044
- AgentStepsContainer,
2045
- AskUserContainer,
2046
- computeAgentStepsSplit,
2047
- AssistantTextContainer,
2048
- ReasoningContainer,
2049
- ToolApprovalContainer,
2050
- ToolCallContentBlockContainer,
2051
- ToolCallContainer,
2052
- AssistantMessageContainer,
2053
- ComposerAttachmentsContainer,
2054
- MessageAttachmentsContainer,
2055
- ComposerAttachmentPickerContainer,
2056
- threadHasPendingMcpAuth,
2057
- useComposerPauseView,
2058
- McpAuthContainer,
2059
- ComposerContainer,
2060
- HistoryLoaderContainer,
2061
- ResumeUnavailableContainer,
2062
- UserEditComposerContainer,
2063
- UserMessageContainer,
2064
- ThreadContainer,
2065
- Thread,
2066
- ThreadListContainer
2067
- };
2068
- //# sourceMappingURL=chunk-IWPDSPVA.js.map