@truefoundry/trueforge-ui 0.3.0-rc.0 → 0.3.0-rc.10

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 (115) hide show
  1. package/CHANGELOG.md +191 -0
  2. package/README.md +35 -12
  3. package/dist/AgentCodeSnippets-RJBB4DDE.js +89 -0
  4. package/dist/AgentCodeSnippets-RJBB4DDE.js.map +1 -0
  5. package/dist/AgentMetricChart-UPGSJ2WP.js +15 -0
  6. package/dist/AgentOverview-U5WIQXZN.js +169 -0
  7. package/dist/AgentOverview-U5WIQXZN.js.map +1 -0
  8. package/dist/AgentSessionEventTimeline-GRGIQTRE.js +88 -0
  9. package/dist/AgentSessionEventTimeline-GRGIQTRE.js.map +1 -0
  10. package/dist/AgentSessionEventTimelineChart-GNF4VOUT.js +591 -0
  11. package/dist/AgentSessionEventTimelineChart-GNF4VOUT.js.map +1 -0
  12. package/dist/AgentSessions-5OTF2BUW.js +323 -0
  13. package/dist/AgentSessions-5OTF2BUW.js.map +1 -0
  14. package/dist/{ConnectorSettings-FXQ5B7TN.js → ConnectorSettings-HDKGLDCY.js} +163 -125
  15. package/dist/ConnectorSettings-HDKGLDCY.js.map +1 -0
  16. package/dist/{DockLayout-LBNQJZNF.js → DockLayout-D2FPQCAL.js} +11 -10
  17. package/dist/{DockLayout-LBNQJZNF.js.map → DockLayout-D2FPQCAL.js.map} +1 -1
  18. package/dist/DrawerLayout-HUV7RAWL.js +186 -0
  19. package/dist/DrawerLayout-HUV7RAWL.js.map +1 -0
  20. package/dist/{ModelSettings-4L4LOQJA.js → ModelSettings-VNQ7HPKH.js} +23 -27
  21. package/dist/ModelSettings-VNQ7HPKH.js.map +1 -0
  22. package/dist/OpenUiFenceBlock-KPZFLUSC.js +9 -0
  23. package/dist/OpenUiFenceBlock-KPZFLUSC.js.map +1 -0
  24. package/dist/{SandboxSettings-Z4ZG6ZX4.js → SandboxSettings-ZLXGMFBF.js} +18 -20
  25. package/dist/SandboxSettings-ZLXGMFBF.js.map +1 -0
  26. package/dist/SchedulesPage-QKYI2Z3A.js +15 -0
  27. package/dist/SchedulesPage-QKYI2Z3A.js.map +1 -0
  28. package/dist/{SettingsBuilder-WF7ZWKQW.js → SettingsBuilder-RVVYXOJW.js} +27 -23
  29. package/dist/SettingsBuilder-RVVYXOJW.js.map +1 -0
  30. package/dist/ShellRouteSync-SJXFKUAJ.js +390 -0
  31. package/dist/ShellRouteSync-SJXFKUAJ.js.map +1 -0
  32. package/dist/SidebarLayout-KYA76FQ7.js +330 -0
  33. package/dist/SidebarLayout-KYA76FQ7.js.map +1 -0
  34. package/dist/{SkillSettings-3EPPC3IT.js → SkillSettings-7OHT7FPI.js} +25 -21
  35. package/dist/SkillSettings-7OHT7FPI.js.map +1 -0
  36. package/dist/{TrueForgeUIWithRouter-NZ4FGPE4.js → TrueForgeUIWithRouter-LKG4XLW6.js} +14 -10
  37. package/dist/{TrueForgeUIWithRouter-NZ4FGPE4.js.map → TrueForgeUIWithRouter-LKG4XLW6.js.map} +1 -1
  38. package/dist/{WidgetLayout-3QZ357FL.js → WidgetLayout-W2RGGOQ3.js} +17 -13
  39. package/dist/WidgetLayout-W2RGGOQ3.js.map +1 -0
  40. package/dist/chunk-2GIZY3JJ.js +1062 -0
  41. package/dist/chunk-2GIZY3JJ.js.map +1 -0
  42. package/dist/chunk-2QTH6JHX.js +217 -0
  43. package/dist/chunk-2QTH6JHX.js.map +1 -0
  44. package/dist/{chunk-FJ5RSSMA.js → chunk-3ZW74FHC.js} +118 -164
  45. package/dist/chunk-3ZW74FHC.js.map +1 -0
  46. package/dist/chunk-67ZO7Z2W.js +184 -0
  47. package/dist/chunk-67ZO7Z2W.js.map +1 -0
  48. package/dist/{chunk-CFLVPV5M.js → chunk-7AAO4UDQ.js} +8 -2
  49. package/dist/chunk-7AAO4UDQ.js.map +1 -0
  50. package/dist/{chunk-B52K63AW.js → chunk-CG75X77Q.js} +2 -2
  51. package/dist/chunk-DJUFS2BW.js +27 -0
  52. package/dist/chunk-DJUFS2BW.js.map +1 -0
  53. package/dist/chunk-DPPOEFBD.js +517 -0
  54. package/dist/chunk-DPPOEFBD.js.map +1 -0
  55. package/dist/chunk-EPAL2HD5.js +1629 -0
  56. package/dist/chunk-EPAL2HD5.js.map +1 -0
  57. package/dist/chunk-GG23N2GW.js +15018 -0
  58. package/dist/chunk-GG23N2GW.js.map +1 -0
  59. package/dist/chunk-JCL3Q7RW.js +587 -0
  60. package/dist/chunk-JCL3Q7RW.js.map +1 -0
  61. package/dist/chunk-JKEBMGLH.js +682 -0
  62. package/dist/chunk-JKEBMGLH.js.map +1 -0
  63. package/dist/chunk-KSGNKS2D.js +296 -0
  64. package/dist/chunk-KSGNKS2D.js.map +1 -0
  65. package/dist/{chunk-WREC7D54.js → chunk-PCI6VMB5.js} +268 -48
  66. package/dist/chunk-PCI6VMB5.js.map +1 -0
  67. package/dist/chunk-PQ7VWBQQ.js +121 -0
  68. package/dist/chunk-PQ7VWBQQ.js.map +1 -0
  69. package/dist/chunk-RDXBMTP5.js +32 -0
  70. package/dist/chunk-RDXBMTP5.js.map +1 -0
  71. package/dist/chunk-T6QQV5LK.js +238 -0
  72. package/dist/chunk-T6QQV5LK.js.map +1 -0
  73. package/dist/chunk-Y6S4OVVQ.js +16 -0
  74. package/dist/chunk-Y6S4OVVQ.js.map +1 -0
  75. package/dist/{createTrueFoundryServer-B72bU-J7.d.ts → createTrueFoundryServer-B_FYhSdn.d.ts} +18 -4
  76. package/dist/index.d.ts +1287 -46
  77. package/dist/index.js +266 -63
  78. package/dist/index.js.map +1 -1
  79. package/dist/plugins/trueforge-agent-server-adapter/index.d.ts +590 -11
  80. package/dist/plugins/trueforge-agent-server-adapter/index.js +607 -204
  81. package/dist/plugins/trueforge-agent-server-adapter/index.js.map +1 -1
  82. package/dist/styles.css +1 -1
  83. package/package.json +10 -8
  84. package/dist/ConnectorSettings-FXQ5B7TN.js.map +0 -1
  85. package/dist/DrawerLayout-Q6UK4VMI.js +0 -159
  86. package/dist/DrawerLayout-Q6UK4VMI.js.map +0 -1
  87. package/dist/ModelSettings-4L4LOQJA.js.map +0 -1
  88. package/dist/OpenUiFenceBlock-6UIIAVBX.js +0 -9
  89. package/dist/SandboxSettings-Z4ZG6ZX4.js.map +0 -1
  90. package/dist/SettingsBuilder-WF7ZWKQW.js.map +0 -1
  91. package/dist/ShellRouteSync-T4WLY57Q.js +0 -172
  92. package/dist/ShellRouteSync-T4WLY57Q.js.map +0 -1
  93. package/dist/SidebarLayout-3WZ3CVON.js +0 -256
  94. package/dist/SidebarLayout-3WZ3CVON.js.map +0 -1
  95. package/dist/SkillSettings-3EPPC3IT.js.map +0 -1
  96. package/dist/WidgetLayout-3QZ357FL.js.map +0 -1
  97. package/dist/chunk-36KOSC2J.js +0 -567
  98. package/dist/chunk-36KOSC2J.js.map +0 -1
  99. package/dist/chunk-3S6KHO7H.js +0 -2121
  100. package/dist/chunk-3S6KHO7H.js.map +0 -1
  101. package/dist/chunk-7L63OK3O.js +0 -91
  102. package/dist/chunk-7L63OK3O.js.map +0 -1
  103. package/dist/chunk-CFLVPV5M.js.map +0 -1
  104. package/dist/chunk-FJ5RSSMA.js.map +0 -1
  105. package/dist/chunk-OSV3HI5M.js +0 -6891
  106. package/dist/chunk-OSV3HI5M.js.map +0 -1
  107. package/dist/chunk-WQULF5AT.js +0 -460
  108. package/dist/chunk-WQULF5AT.js.map +0 -1
  109. package/dist/chunk-WREC7D54.js.map +0 -1
  110. package/dist/chunk-YIWUG6MC.js +0 -101
  111. package/dist/chunk-YIWUG6MC.js.map +0 -1
  112. package/dist/chunk-ZXOADNF3.js +0 -75
  113. package/dist/chunk-ZXOADNF3.js.map +0 -1
  114. /package/dist/{OpenUiFenceBlock-6UIIAVBX.js.map → AgentMetricChart-UPGSJ2WP.js.map} +0 -0
  115. /package/dist/{chunk-B52K63AW.js.map → chunk-CG75X77Q.js.map} +0 -0
@@ -0,0 +1,682 @@
1
+ import {
2
+ ComposerBusyProvider,
3
+ useComposerBusyState,
4
+ useOptionalCustomActionRenderers
5
+ } from "./chunk-BSIPI3KV.js";
6
+ import {
7
+ ASK_USER_CUSTOM_OPTION,
8
+ ApprovalFocusProvider,
9
+ AssistantMessageContainer,
10
+ Button,
11
+ ComposerAttachmentsContainer,
12
+ MessageAttachmentsContainer,
13
+ SlotsProvider,
14
+ UserMessageContainer,
15
+ isNewChatView,
16
+ preloadMarkdownOpenUI,
17
+ useActiveSessionCanManage,
18
+ useMCPAuth,
19
+ useOptionalApprovalFocus,
20
+ useSlot,
21
+ useSlotIsDefault
22
+ } from "./chunk-GG23N2GW.js";
23
+ import {
24
+ DraftCatalogProvider,
25
+ useDraftCatalog
26
+ } from "./chunk-3ZW74FHC.js";
27
+ import {
28
+ useOptionalCatalogServer,
29
+ useOptionalServer,
30
+ useOptionalShellMode
31
+ } from "./chunk-2GIZY3JJ.js";
32
+ import {
33
+ useAui,
34
+ useAuiState
35
+ } from "./chunk-M6MHLVSO.js";
36
+
37
+ // src/hooks/useApprovalNav.ts
38
+ import { useTrueFoundryApprovals } from "@truefoundry/assistant-ui-runtime";
39
+ import { useCallback, useEffect, useRef, useState } from "react";
40
+ function useApprovalNav() {
41
+ const { pending } = useTrueFoundryApprovals();
42
+ const focusApi = useOptionalApprovalFocus();
43
+ const [selection, setSelection] = useState({
44
+ approvalId: null,
45
+ index: 0
46
+ });
47
+ const focusedIdRef = useRef(null);
48
+ const count = pending.length;
49
+ const matchedIndex = selection.approvalId == null ? -1 : pending.findIndex((item) => item.approvalId === selection.approvalId);
50
+ const safeIndex = matchedIndex >= 0 ? matchedIndex : count === 0 ? 0 : Math.min(selection.index, count - 1);
51
+ const currentId = pending[safeIndex]?.approvalId;
52
+ useEffect(() => {
53
+ const approvalId = currentId ?? null;
54
+ if (selection.approvalId === approvalId && selection.index === safeIndex) return;
55
+ setSelection({ approvalId, index: safeIndex });
56
+ }, [currentId, safeIndex, selection.approvalId, selection.index]);
57
+ useEffect(() => {
58
+ if (currentId == null || focusApi == null) {
59
+ if (currentId == null) focusedIdRef.current = null;
60
+ return;
61
+ }
62
+ if (focusedIdRef.current === currentId) return;
63
+ focusedIdRef.current = currentId;
64
+ focusApi.focus(currentId);
65
+ }, [currentId, focusApi]);
66
+ const goPrev = useCallback(() => {
67
+ const index = Math.max(0, safeIndex - 1);
68
+ setSelection({ approvalId: pending[index]?.approvalId ?? null, index });
69
+ }, [pending, safeIndex]);
70
+ const goNext = useCallback(() => {
71
+ const index = Math.min(Math.max(count - 1, 0), safeIndex + 1);
72
+ setSelection({ approvalId: pending[index]?.approvalId ?? null, index });
73
+ }, [count, pending, safeIndex]);
74
+ const focusCurrent = useCallback(() => {
75
+ if (currentId == null || focusApi == null) return;
76
+ focusApi.focus(currentId);
77
+ }, [currentId, focusApi]);
78
+ return {
79
+ count,
80
+ index: safeIndex,
81
+ canPrev: safeIndex > 0,
82
+ canNext: safeIndex < count - 1,
83
+ goPrev,
84
+ goNext,
85
+ focusCurrent
86
+ };
87
+ }
88
+
89
+ // src/containers/ApprovalNavContainer.tsx
90
+ import { jsx } from "react/jsx-runtime";
91
+ function ApprovalNavContainer() {
92
+ const ApprovalNavBanner = useSlot("ApprovalNavBanner");
93
+ const { count, index, canPrev, canNext, goPrev, goNext, focusCurrent } = useApprovalNav();
94
+ if (count === 0) return null;
95
+ return /* @__PURE__ */ jsx(
96
+ ApprovalNavBanner,
97
+ {
98
+ total: count,
99
+ current: index + 1,
100
+ canPrev,
101
+ canNext,
102
+ onPrev: goPrev,
103
+ onNext: goNext,
104
+ onFocusCurrent: focusCurrent
105
+ }
106
+ );
107
+ }
108
+
109
+ // src/containers/AskUserContainer.tsx
110
+ import { useThreadIsRunning } from "@assistant-ui/core/react";
111
+ import { useTrueFoundryToolResponses } from "@truefoundry/assistant-ui-runtime";
112
+ import { useCallback as useCallback2, useEffect as useEffect2, useMemo, useState as useState2 } from "react";
113
+ import { jsx as jsx2 } from "react/jsx-runtime";
114
+ var EMPTY_ANSWER = { radioValue: "", custom: "" };
115
+ function AskUserContainer({ disabled = false }) {
116
+ const AskUserPrompt = useSlot("AskUserPrompt");
117
+ const { pending, respond } = useTrueFoundryToolResponses();
118
+ const isRunning = useThreadIsRunning();
119
+ const item = pending[0];
120
+ const questions = useMemo(
121
+ () => item == null ? [] : [
122
+ {
123
+ id: item.toolCallId,
124
+ question: item.question ?? "Answer required",
125
+ options: item.options ?? []
126
+ }
127
+ ],
128
+ [item]
129
+ );
130
+ const [currentQuestionIndex, setCurrentQuestionIndex] = useState2(0);
131
+ const [answers, setAnswers] = useState2({});
132
+ useEffect2(() => {
133
+ setCurrentQuestionIndex(0);
134
+ setAnswers({});
135
+ }, [item?.toolCallId]);
136
+ const safeIndex = Math.min(currentQuestionIndex, Math.max(questions.length - 1, 0));
137
+ const currentQuestion = questions[safeIndex];
138
+ const currentAnswer = currentQuestion == null ? EMPTY_ANSWER : answers[currentQuestion.id] ?? EMPTY_ANSWER;
139
+ const getResponseForQuestion = useCallback2(
140
+ (questionId) => {
141
+ const answer = answers[questionId] ?? EMPTY_ANSWER;
142
+ return answer.radioValue === ASK_USER_CUSTOM_OPTION ? answer.custom.trim() : answer.radioValue.trim();
143
+ },
144
+ [answers]
145
+ );
146
+ const allQuestionsAnswered = useMemo(
147
+ () => questions.every((question) => getResponseForQuestion(question.id)),
148
+ [getResponseForQuestion, questions]
149
+ );
150
+ const selectedResponse = currentAnswer.radioValue === ASK_USER_CUSTOM_OPTION ? currentAnswer.custom.trim() : currentAnswer.radioValue.trim();
151
+ const isSubmitDisabled = isRunning || disabled || currentQuestion == null || selectedResponse.length === 0;
152
+ const isSubmitAllDisabled = isSubmitDisabled || !allQuestionsAnswered;
153
+ const onCurrentAnswerChange = useCallback2((questionId, update) => {
154
+ setAnswers((previous) => ({
155
+ ...previous,
156
+ [questionId]: {
157
+ ...previous[questionId] ?? EMPTY_ANSWER,
158
+ ...update
159
+ }
160
+ }));
161
+ }, []);
162
+ const onSubmit = useCallback2(() => {
163
+ if (disabled || item == null || !allQuestionsAnswered) return;
164
+ const content = getResponseForQuestion(item.toolCallId);
165
+ if (!content) return;
166
+ respond({ toolCallId: item.toolCallId, content });
167
+ }, [allQuestionsAnswered, disabled, getResponseForQuestion, item, respond]);
168
+ if (item == null || currentQuestion == null) return null;
169
+ return /* @__PURE__ */ jsx2(
170
+ AskUserPrompt,
171
+ {
172
+ questions,
173
+ readOnly: isRunning || disabled,
174
+ currentQuestion,
175
+ currentQuestionIndex: safeIndex,
176
+ currentAnswer,
177
+ totalQuestions: questions.length,
178
+ isMultiQuestion: questions.length > 1,
179
+ isLastQuestion: safeIndex === questions.length - 1,
180
+ allQuestionsAnswered,
181
+ isSubmitDisabled,
182
+ isSubmitAllDisabled,
183
+ onCurrentQuestionIndexChange: setCurrentQuestionIndex,
184
+ onCurrentAnswerChange,
185
+ onSubmit
186
+ }
187
+ );
188
+ }
189
+
190
+ // src/hooks/useComposerPauseView.ts
191
+ import { useAuiState as useAuiState2 } from "@assistant-ui/react";
192
+ import { useTrueFoundryApprovals as useTrueFoundryApprovals2, useTrueFoundryToolResponses as useTrueFoundryToolResponses2 } from "@truefoundry/assistant-ui-runtime";
193
+ function threadHasPendingMcpAuth(s) {
194
+ const messages = s.thread.messages;
195
+ const last = messages[messages.length - 1];
196
+ if (last?.role !== "assistant") return false;
197
+ if (last.status?.type !== "requires-action") return false;
198
+ return last.metadata?.custom?.pendingMcpAuth === true;
199
+ }
200
+ function useComposerPauseView() {
201
+ const mcpPending = useAuiState2(threadHasPendingMcpAuth);
202
+ const { pending: toolResponsesPending } = useTrueFoundryToolResponses2();
203
+ const { pending: approvalsPending } = useTrueFoundryApprovals2();
204
+ const customActionRenderers = useOptionalCustomActionRenderers();
205
+ if (mcpPending) {
206
+ return { kind: "mcp" };
207
+ }
208
+ const firstPending = toolResponsesPending[0];
209
+ if (firstPending != null) {
210
+ const toolName = firstPending.toolName;
211
+ if (toolName != null && customActionRenderers?.[toolName] != null) {
212
+ return { kind: "custom", toolName };
213
+ }
214
+ return { kind: "ask-user" };
215
+ }
216
+ if (approvalsPending.length > 0) {
217
+ return { kind: "approval" };
218
+ }
219
+ return { kind: "compose" };
220
+ }
221
+
222
+ // src/containers/CustomActionContainer.tsx
223
+ import { useThreadIsRunning as useThreadIsRunning2 } from "@assistant-ui/core/react";
224
+ import { useTrueFoundryToolResponses as useTrueFoundryToolResponses3 } from "@truefoundry/assistant-ui-runtime";
225
+ import { useCallback as useCallback3 } from "react";
226
+ import { jsx as jsx3 } from "react/jsx-runtime";
227
+ function CustomActionContainer({ disabled = false }) {
228
+ const renderers = useOptionalCustomActionRenderers();
229
+ const { pending, respond } = useTrueFoundryToolResponses3();
230
+ const isRunning = useThreadIsRunning2();
231
+ const item = pending[0];
232
+ const onSubmit = useCallback3(
233
+ (content) => {
234
+ if (disabled || item == null) return;
235
+ const trimmed = content.trim();
236
+ if (!trimmed) return;
237
+ respond({ toolCallId: item.toolCallId, content: trimmed });
238
+ },
239
+ [disabled, item, respond]
240
+ );
241
+ if (item == null || item.toolName == null) return null;
242
+ const Renderer = renderers?.[item.toolName];
243
+ if (Renderer == null) return null;
244
+ return /* @__PURE__ */ jsx3(Renderer, { args: item.args ?? {}, disabled: isRunning || disabled, onSubmit });
245
+ }
246
+
247
+ // src/containers/McpAuthContainer.tsx
248
+ import { useThreadIsRunning as useThreadIsRunning3 } from "@assistant-ui/core/react";
249
+ import { useTrueFoundryMcpAuth } from "@truefoundry/assistant-ui-runtime";
250
+ import { jsx as jsx4 } from "react/jsx-runtime";
251
+ function CatalogMcpAuthPrompt({ servers, onContinue, readOnly }) {
252
+ const McpAuthPrompt = useSlot("McpAuthPrompt");
253
+ const { handleAuthorize } = useMCPAuth();
254
+ const { refreshConnectors } = useDraftCatalog();
255
+ const handleConnect = (serverId) => {
256
+ void handleAuthorize(serverId, (isSuccess) => {
257
+ if (isSuccess) {
258
+ void refreshConnectors();
259
+ }
260
+ });
261
+ };
262
+ return /* @__PURE__ */ jsx4(McpAuthPrompt, { servers, onConnect: handleConnect, onContinue, readOnly });
263
+ }
264
+ function McpAuthContainer({ disabled = false }) {
265
+ const McpAuthPrompt = useSlot("McpAuthPrompt");
266
+ const { pending, resume } = useTrueFoundryMcpAuth();
267
+ const isRunning = useThreadIsRunning3();
268
+ const catalog = useOptionalCatalogServer();
269
+ if (!pending) return null;
270
+ if (catalog) {
271
+ return /* @__PURE__ */ jsx4(
272
+ CatalogMcpAuthPrompt,
273
+ {
274
+ servers: pending.mcpServers,
275
+ onContinue: () => {
276
+ if (!disabled) void resume();
277
+ },
278
+ readOnly: isRunning || disabled
279
+ }
280
+ );
281
+ }
282
+ const handleConnect = (serverId) => {
283
+ const server = pending.mcpServers.find((s) => s.id === serverId);
284
+ if (server?.authUrl) {
285
+ window.open(server.authUrl, "_blank", "noopener,noreferrer");
286
+ }
287
+ };
288
+ return /* @__PURE__ */ jsx4(
289
+ McpAuthPrompt,
290
+ {
291
+ servers: pending.mcpServers,
292
+ onConnect: handleConnect,
293
+ onContinue: () => {
294
+ if (!disabled) void resume();
295
+ },
296
+ readOnly: isRunning || disabled
297
+ }
298
+ );
299
+ }
300
+
301
+ // src/containers/ComposerContainer.tsx
302
+ import { ComposerPrimitive, useAui as useAui2, useAuiState as useAuiState3 } from "@assistant-ui/react";
303
+ import { useTrueFoundryAgentSpec, useTrueFoundryCancel } from "@truefoundry/assistant-ui-runtime";
304
+ import { useRef as useRef2 } from "react";
305
+ import { Fragment, jsx as jsx5, jsxs } from "react/jsx-runtime";
306
+ function canSubmitComposer({
307
+ disabled,
308
+ hasText,
309
+ hasAttachments,
310
+ requiresModel,
311
+ hasModel
312
+ }) {
313
+ return !disabled && (hasText || hasAttachments) && (!requiresModel || hasModel);
314
+ }
315
+ function ComposerBody({
316
+ placeholder,
317
+ forceDisabled = false,
318
+ connectedToBanner = false
319
+ }) {
320
+ const ComposerShell = useSlot("ComposerShell");
321
+ const aui = useAui2();
322
+ const shell = useOptionalShellMode();
323
+ const hasText = useAuiState3((s) => s.composer.text.trim().length > 0);
324
+ const hasAttachments = useAuiState3((s) => s.composer.attachments.length > 0);
325
+ const { agentSpec } = useTrueFoundryAgentSpec();
326
+ const requiresModel = shell == null || shell.mode.status === "active" && shell.mode.isMutable;
327
+ const hasModel = Boolean(agentSpec?.model?.name?.trim());
328
+ const { isBusy, send, resetBusy } = useComposerBusyState();
329
+ const canManageSession = useActiveSessionCanManage();
330
+ const cancel = useTrueFoundryCancel();
331
+ const fileInputRef = useRef2(null);
332
+ const disabled = isBusy || forceDisabled || !canManageSession;
333
+ const canSubmit = canSubmitComposer({ disabled, hasText, hasAttachments, requiresModel, hasModel });
334
+ const submit = () => {
335
+ if (!canSubmit) return;
336
+ send(() => aui.composer().send());
337
+ };
338
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
339
+ /* @__PURE__ */ jsx5(
340
+ "input",
341
+ {
342
+ ref: fileInputRef,
343
+ type: "file",
344
+ multiple: true,
345
+ hidden: true,
346
+ onChange: (event) => {
347
+ const files = event.target.files;
348
+ if (files) {
349
+ for (const file of files) {
350
+ void aui.composer().addAttachment(file);
351
+ }
352
+ }
353
+ event.target.value = "";
354
+ }
355
+ }
356
+ ),
357
+ /* @__PURE__ */ jsx5(
358
+ ComposerPrimitive.AttachmentDropzone,
359
+ {
360
+ disabled,
361
+ "data-slot": "aui_composer-attachment-dropzone",
362
+ className: "w-full rounded-[0.75rem] transition-[box-shadow] data-[dragging=true]:ring-focus-ring/20 data-[dragging=true]:ring-3",
363
+ children: /* @__PURE__ */ jsx5(
364
+ ComposerPrimitive.Root,
365
+ {
366
+ "data-slot": "aui_composer-root",
367
+ className: "w-full",
368
+ onSubmit: (event) => {
369
+ event.preventDefault();
370
+ submit();
371
+ },
372
+ children: /* @__PURE__ */ jsx5(
373
+ ComposerShell,
374
+ {
375
+ className: connectedToBanner ? (
376
+ // Banner owns the top accent; composer keeps its normal chrome without a shared blue frame.
377
+ "rounded-t-none border-t-0 focus-within:ring-0"
378
+ ) : void 0,
379
+ attachments: /* @__PURE__ */ jsx5(ComposerAttachmentsContainer, {}),
380
+ input: /* @__PURE__ */ jsx5(
381
+ ComposerPrimitive.Input,
382
+ {
383
+ "data-slot": "aui_composer-input",
384
+ placeholder,
385
+ disabled,
386
+ submitMode: "enter",
387
+ "aria-label": "Message input",
388
+ 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"
389
+ }
390
+ ),
391
+ disabled,
392
+ canSubmit,
393
+ isRunning: isBusy && !forceDisabled,
394
+ onSubmit: submit,
395
+ onCancel: canManageSession ? () => {
396
+ resetBusy();
397
+ void cancel();
398
+ } : void 0,
399
+ onAttach: canManageSession ? () => fileInputRef.current?.click() : void 0
400
+ }
401
+ )
402
+ }
403
+ )
404
+ }
405
+ )
406
+ ] });
407
+ }
408
+ function ComposerWithOptionalDraft({
409
+ placeholder,
410
+ forceDisabled = false,
411
+ connectedToBanner = false
412
+ }) {
413
+ const shell = useOptionalShellMode();
414
+ const parentLeftSection = useSlot("ComposerLeftSection");
415
+ const parentRightSection = useSlot("ComposerRightSection");
416
+ const usesDefaultLeftSection = useSlotIsDefault("ComposerLeftSection");
417
+ const usesDefaultRightSection = useSlotIsDefault("ComposerRightSection");
418
+ const DraftComposerLeftSection = useSlot("DraftComposerLeftSection");
419
+ const DraftComposerRightSection = useSlot("DraftComposerRightSection");
420
+ const canMutateSpec = shell?.mode.status === "active" && shell.mode.isMutable;
421
+ if (canMutateSpec) {
422
+ return /* @__PURE__ */ jsx5(DraftCatalogProvider, { children: /* @__PURE__ */ jsx5(
423
+ SlotsProvider,
424
+ {
425
+ overrides: {
426
+ ComposerLeftSection: usesDefaultLeftSection ? DraftComposerLeftSection : parentLeftSection,
427
+ ComposerRightSection: usesDefaultRightSection ? DraftComposerRightSection : parentRightSection
428
+ },
429
+ children: /* @__PURE__ */ jsx5(ComposerBody, { placeholder, forceDisabled, connectedToBanner })
430
+ }
431
+ ) });
432
+ }
433
+ return /* @__PURE__ */ jsx5(ComposerBody, { placeholder, forceDisabled, connectedToBanner });
434
+ }
435
+ function ComposerContainer({
436
+ placeholder = "Ask anything... (Shift+Enter for new line)"
437
+ }) {
438
+ const pauseView = useComposerPauseView();
439
+ const canManageSession = useActiveSessionCanManage();
440
+ if (pauseView.kind === "mcp") {
441
+ return /* @__PURE__ */ jsx5(McpAuthContainer, { disabled: !canManageSession });
442
+ }
443
+ if (pauseView.kind === "custom") {
444
+ return /* @__PURE__ */ jsx5(CustomActionContainer, { disabled: !canManageSession });
445
+ }
446
+ if (pauseView.kind === "ask-user") {
447
+ return /* @__PURE__ */ jsx5(AskUserContainer, { disabled: !canManageSession });
448
+ }
449
+ if (pauseView.kind === "approval") {
450
+ return /* @__PURE__ */ jsxs("div", { "data-slot": "aui_composer-approval-pause", className: "flex w-full flex-col", children: [
451
+ /* @__PURE__ */ jsx5(ApprovalNavContainer, {}),
452
+ /* @__PURE__ */ jsx5(ComposerWithOptionalDraft, { placeholder, forceDisabled: true, connectedToBanner: true })
453
+ ] });
454
+ }
455
+ return /* @__PURE__ */ jsx5(ComposerWithOptionalDraft, { placeholder });
456
+ }
457
+
458
+ // src/containers/HistoryLoaderContainer.tsx
459
+ import { useTrueFoundryHistoryPagination } from "@truefoundry/assistant-ui-runtime";
460
+ import { useCallback as useCallback4, useEffect as useEffect3, useRef as useRef3, useState as useState3 } from "react";
461
+ import { jsx as jsx6 } from "react/jsx-runtime";
462
+ var TOP_THRESHOLD_PX = 200;
463
+ var VIEWPORT_SELECTOR = '[data-slot="aui_thread-viewport"]';
464
+ function HistoryLoaderContainer() {
465
+ const HistoryLoader = useSlot("HistoryLoader");
466
+ const { hasOlderHistory, isLoadingOlderHistory, loadOlderHistory } = useTrueFoundryHistoryPagination();
467
+ const [sentinel, setSentinel] = useState3(null);
468
+ const inflightRef = useRef3(false);
469
+ const maybeLoadOlder = useCallback4(async () => {
470
+ if (inflightRef.current) return;
471
+ inflightRef.current = true;
472
+ const viewport = sentinel?.closest(VIEWPORT_SELECTOR) ?? null;
473
+ const prevScrollHeight = viewport?.scrollHeight ?? 0;
474
+ const prevScrollTop = viewport?.scrollTop ?? 0;
475
+ try {
476
+ await loadOlderHistory();
477
+ requestAnimationFrame(() => {
478
+ if (viewport == null) return;
479
+ const delta = viewport.scrollHeight - prevScrollHeight;
480
+ if (delta > 0) {
481
+ viewport.scrollTo({ top: prevScrollTop + delta, behavior: "instant" });
482
+ }
483
+ });
484
+ } catch {
485
+ } finally {
486
+ inflightRef.current = false;
487
+ }
488
+ }, [sentinel, loadOlderHistory]);
489
+ useEffect3(() => {
490
+ if (sentinel == null || !hasOlderHistory) return;
491
+ const viewport = sentinel.closest(VIEWPORT_SELECTOR);
492
+ const observer = new IntersectionObserver(
493
+ (entries) => {
494
+ if (entries.some((entry) => entry.isIntersecting)) {
495
+ void maybeLoadOlder();
496
+ }
497
+ },
498
+ { root: viewport, rootMargin: `${TOP_THRESHOLD_PX}px 0px 0px 0px` }
499
+ );
500
+ observer.observe(sentinel);
501
+ return () => observer.disconnect();
502
+ }, [sentinel, hasOlderHistory, maybeLoadOlder]);
503
+ if (!hasOlderHistory) return null;
504
+ return /* @__PURE__ */ jsx6(HistoryLoader, { ref: setSentinel, isLoading: isLoadingOlderHistory });
505
+ }
506
+
507
+ // src/containers/ResumeUnavailableContainer.tsx
508
+ import { useTrueFoundryResumeUnavailable } from "@truefoundry/assistant-ui-runtime";
509
+ import { jsx as jsx7 } from "react/jsx-runtime";
510
+ function ResumeUnavailableContainer() {
511
+ const ResumeUnavailable = useSlot("ResumeUnavailable");
512
+ const resumeUnavailable = useTrueFoundryResumeUnavailable();
513
+ if (!resumeUnavailable) return null;
514
+ return /* @__PURE__ */ jsx7(ResumeUnavailable, {});
515
+ }
516
+
517
+ // src/containers/UserEditComposerContainer.tsx
518
+ import { useComposerCancel, useComposerSend, useThreadIsRunning as useThreadIsRunning4 } from "@assistant-ui/core/react";
519
+ import { ComposerPrimitive as ComposerPrimitive2, MessagePrimitive, useAuiState as useAuiState4 } from "@assistant-ui/react";
520
+ import { jsx as jsx8, jsxs as jsxs2 } from "react/jsx-runtime";
521
+ function ReadOnlyMessageAttachments() {
522
+ const hasAttachments = useAuiState4((s) => (s.message.attachments?.length ?? 0) > 0);
523
+ if (!hasAttachments) {
524
+ return null;
525
+ }
526
+ return /* @__PURE__ */ jsx8("div", { className: "pointer-events-none mb-2 opacity-90", children: /* @__PURE__ */ jsx8(MessageAttachmentsContainer, {}) });
527
+ }
528
+ function UserEditComposerContainer() {
529
+ const UserMessageEdit = useSlot("UserMessageEdit");
530
+ const MessageTimestamp = useSlot("MessageTimestamp");
531
+ const isRunning = useThreadIsRunning4();
532
+ const canManageSession = useActiveSessionCanManage();
533
+ const createdAt = useAuiState4((s) => s.message.createdAt);
534
+ const { cancel, disabled: cancelDisabled } = useComposerCancel();
535
+ const { disabled: sendDisabled } = useComposerSend();
536
+ return /* @__PURE__ */ jsx8(MessagePrimitive.Root, { "data-role": "user", children: /* @__PURE__ */ jsx8(
537
+ ComposerPrimitive2.Root,
538
+ {
539
+ "data-slot": "aui_user-edit-composer-root",
540
+ className: "fade-in slide-in-from-bottom-1 animate-in flex w-full justify-end px-2 duration-150",
541
+ children: /* @__PURE__ */ jsx8(
542
+ UserMessageEdit,
543
+ {
544
+ timestamp: /* @__PURE__ */ jsx8(MessageTimestamp, { createdAt }),
545
+ attachments: /* @__PURE__ */ jsx8(ReadOnlyMessageAttachments, {}),
546
+ input: /* @__PURE__ */ jsx8("div", { className: "mt-1 rounded border border-border bg-secondary-bg p-2 text-text-primary", children: /* @__PURE__ */ jsx8(
547
+ ComposerPrimitive2.Input,
548
+ {
549
+ "data-slot": "aui_user-edit-input",
550
+ disabled: isRunning || !canManageSession,
551
+ submitMode: "enter",
552
+ "aria-label": "Edit message",
553
+ 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"
554
+ }
555
+ ) }),
556
+ footer: /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-end gap-2", children: [
557
+ /* @__PURE__ */ jsx8(Button.Secondary, { type: "button", disabled: cancelDisabled, onClick: cancel, children: "Cancel" }),
558
+ /* @__PURE__ */ jsx8(ComposerPrimitive2.Send, { asChild: true, children: /* @__PURE__ */ jsx8(Button.Primary, { type: "submit", disabled: sendDisabled || isRunning || !canManageSession, children: "Save & Rerun" }) })
559
+ ] })
560
+ }
561
+ )
562
+ }
563
+ ) });
564
+ }
565
+
566
+ // src/containers/ThreadContainer.tsx
567
+ import { ThreadPrimitive, useAuiState as useAuiState5 } from "@assistant-ui/react";
568
+ import { useEffect as useEffect5 } from "react";
569
+
570
+ // src/hooks/useSyncSessionTitle.ts
571
+ import { useThreadIsRunning as useThreadIsRunning5 } from "@assistant-ui/core/react";
572
+ import { useEffect as useEffect4, useRef as useRef4 } from "react";
573
+ function useSyncSessionTitle() {
574
+ const server = useOptionalServer();
575
+ const aui = useAui();
576
+ const remoteId = useAuiState((s) => s.threadListItem.remoteId);
577
+ const title = useAuiState((s) => s.threadListItem.title);
578
+ const isRunning = useThreadIsRunning5();
579
+ const wasRunningRef = useRef4(false);
580
+ const syncedRemoteIdRef = useRef4(void 0);
581
+ useEffect4(() => {
582
+ syncedRemoteIdRef.current = void 0;
583
+ }, [remoteId]);
584
+ useEffect4(() => {
585
+ const finishedTurn = wasRunningRef.current && !isRunning;
586
+ wasRunningRef.current = isRunning;
587
+ if (!finishedTurn || server == null || remoteId == null) {
588
+ return;
589
+ }
590
+ if (syncedRemoteIdRef.current === remoteId) {
591
+ return;
592
+ }
593
+ if (title != null && title.trim() !== "") {
594
+ syncedRemoteIdRef.current = remoteId;
595
+ return;
596
+ }
597
+ let cancelled = false;
598
+ void server.getSession({ sessionId: remoteId }).then((session) => {
599
+ if (cancelled) return;
600
+ const nextTitle = typeof session.title === "string" ? session.title.trim() : "";
601
+ if (nextTitle.length === 0) return;
602
+ syncedRemoteIdRef.current = remoteId;
603
+ return aui.threadListItem().rename(nextTitle);
604
+ }).catch(() => void 0);
605
+ return () => {
606
+ cancelled = true;
607
+ };
608
+ }, [aui, isRunning, remoteId, server, title]);
609
+ }
610
+
611
+ // src/containers/ThreadContainer.tsx
612
+ import { Fragment as Fragment2, jsx as jsx9, jsxs as jsxs3 } from "react/jsx-runtime";
613
+ function AnimatedMessageShell({ children }) {
614
+ return /* @__PURE__ */ jsx9("div", { className: "animate-in fade-in slide-in-from-bottom-1 fill-mode-both duration-200", children });
615
+ }
616
+ function ThreadMessage({ isEditing }) {
617
+ const role = useAuiState5((s) => s.message.role);
618
+ if (role === "user") {
619
+ if (isEditing) {
620
+ return /* @__PURE__ */ jsx9(UserEditComposerContainer, {});
621
+ }
622
+ return /* @__PURE__ */ jsx9(UserMessageContainer, {});
623
+ }
624
+ return /* @__PURE__ */ jsx9(AssistantMessageContainer, {});
625
+ }
626
+ function ThreadContainer({ composer }) {
627
+ useEffect5(() => {
628
+ void preloadMarkdownOpenUI();
629
+ }, []);
630
+ useSyncSessionTitle();
631
+ const shell = useOptionalShellMode();
632
+ const WelcomeScreen = useSlot("WelcomeScreen");
633
+ const MessageListSkeleton = useSlot("MessageListSkeleton");
634
+ const ScrollToBottomButton = useSlot("ScrollToBottomButton");
635
+ const MessageGroup = useSlot("MessageGroup");
636
+ const ThreadComposerAreaShell = useSlot("ThreadComposerAreaShell");
637
+ const ThreadRootShell = useSlot("ThreadRootShell");
638
+ const ThreadViewportShell = useSlot("ThreadViewportShell");
639
+ const isEmpty = useAuiState5(isNewChatView);
640
+ const isLoading = useAuiState5((s) => s.thread.isLoading);
641
+ const welcomeHeading = shell?.mode.status === "active" ? shell.mode.agentName != null && shell.mode.agentName.length > 0 ? shell.mode.agentName : shell.mode.isMutable && shell.mode.isCreateAgent ? "Start building a new Agent" : void 0 : void 0;
642
+ return /* @__PURE__ */ jsx9(ComposerBusyProvider, { children: /* @__PURE__ */ jsx9(ApprovalFocusProvider, { children: /* @__PURE__ */ jsx9(ThreadPrimitive.Root, { asChild: true, children: /* @__PURE__ */ jsxs3(ThreadRootShell, { children: [
643
+ /* @__PURE__ */ jsx9(ThreadPrimitive.Viewport, { asChild: true, autoScroll: true, children: /* @__PURE__ */ jsxs3(ThreadViewportShell, { isEmpty, children: [
644
+ isEmpty && /* @__PURE__ */ jsx9(WelcomeScreen, { heading: welcomeHeading }),
645
+ isEmpty && !isLoading && composer,
646
+ isLoading ? /* @__PURE__ */ jsx9(MessageListSkeleton, {}) : !isEmpty && /* @__PURE__ */ jsxs3(Fragment2, { children: [
647
+ /* @__PURE__ */ jsx9(HistoryLoaderContainer, {}),
648
+ /* @__PURE__ */ jsxs3(MessageGroup, { children: [
649
+ /* @__PURE__ */ jsx9(ThreadPrimitive.Messages, { children: ({ message }) => /* @__PURE__ */ jsx9(AnimatedMessageShell, { children: /* @__PURE__ */ jsx9(ThreadMessage, { isEditing: message.role === "user" && message.composer.isEditing }) }) }),
650
+ /* @__PURE__ */ jsx9(ResumeUnavailableContainer, {})
651
+ ] })
652
+ ] })
653
+ ] }) }),
654
+ !isLoading && !isEmpty && /* @__PURE__ */ jsxs3(ThreadComposerAreaShell, { isEmpty, children: [
655
+ /* @__PURE__ */ jsx9(ThreadPrimitive.ScrollToBottom, { asChild: true, children: /* @__PURE__ */ jsx9(ScrollToBottomButton, {}) }),
656
+ composer
657
+ ] })
658
+ ] }) }) }) });
659
+ }
660
+
661
+ // src/containers/Thread.tsx
662
+ import { jsx as jsx10 } from "react/jsx-runtime";
663
+ function Thread() {
664
+ return /* @__PURE__ */ jsx10(ThreadContainer, { composer: /* @__PURE__ */ jsx10(ComposerContainer, {}) });
665
+ }
666
+
667
+ export {
668
+ useApprovalNav,
669
+ ApprovalNavContainer,
670
+ AskUserContainer,
671
+ threadHasPendingMcpAuth,
672
+ useComposerPauseView,
673
+ CustomActionContainer,
674
+ McpAuthContainer,
675
+ ComposerContainer,
676
+ HistoryLoaderContainer,
677
+ ResumeUnavailableContainer,
678
+ UserEditComposerContainer,
679
+ ThreadContainer,
680
+ Thread
681
+ };
682
+ //# sourceMappingURL=chunk-JKEBMGLH.js.map