@surf-kit/agent 0.1.1 → 0.2.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 (74) hide show
  1. package/README.md +19 -1
  2. package/dist/agent-BNSmiexZ.d.cts +44 -0
  3. package/dist/agent-BNSmiexZ.d.ts +44 -0
  4. package/dist/agent-identity/index.cjs +157 -0
  5. package/dist/agent-identity/index.cjs.map +1 -0
  6. package/dist/agent-identity/index.d.cts +35 -0
  7. package/dist/agent-identity/index.d.ts +35 -0
  8. package/dist/agent-identity/index.js +127 -0
  9. package/dist/agent-identity/index.js.map +1 -0
  10. package/dist/chat/index.cjs +1281 -0
  11. package/dist/chat/index.cjs.map +1 -0
  12. package/dist/chat/index.d.cts +72 -0
  13. package/dist/chat/index.d.ts +72 -0
  14. package/dist/chat/index.js +1239 -0
  15. package/dist/chat/index.js.map +1 -0
  16. package/dist/chat--OifhIRe.d.ts +24 -0
  17. package/dist/chat-ChYl2XjV.d.cts +24 -0
  18. package/dist/confidence/index.cjs +253 -0
  19. package/dist/confidence/index.cjs.map +1 -0
  20. package/dist/confidence/index.d.cts +40 -0
  21. package/dist/confidence/index.d.ts +40 -0
  22. package/dist/confidence/index.js +222 -0
  23. package/dist/confidence/index.js.map +1 -0
  24. package/dist/feedback/index.cjs +186 -0
  25. package/dist/feedback/index.cjs.map +1 -0
  26. package/dist/feedback/index.d.cts +27 -0
  27. package/dist/feedback/index.d.ts +27 -0
  28. package/dist/feedback/index.js +157 -0
  29. package/dist/feedback/index.js.map +1 -0
  30. package/dist/{hooks-B8CSeOsn.d.cts → hooks-BGs8-4GK.d.ts} +4 -99
  31. package/dist/{hooks-B8CSeOsn.d.ts → hooks-DLfF18IU.d.cts} +4 -99
  32. package/dist/hooks.d.cts +4 -1
  33. package/dist/hooks.d.ts +4 -1
  34. package/dist/index-BazLnae1.d.cts +67 -0
  35. package/dist/index-BazLnae1.d.ts +67 -0
  36. package/dist/index.cjs +889 -144
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.d.cts +15 -321
  39. package/dist/index.d.ts +15 -321
  40. package/dist/index.js +879 -142
  41. package/dist/index.js.map +1 -1
  42. package/dist/layouts/index.cjs +1588 -0
  43. package/dist/layouts/index.cjs.map +1 -0
  44. package/dist/layouts/index.d.cts +46 -0
  45. package/dist/layouts/index.d.ts +46 -0
  46. package/dist/layouts/index.js +1548 -0
  47. package/dist/layouts/index.js.map +1 -0
  48. package/dist/mcp/index.cjs +522 -0
  49. package/dist/mcp/index.cjs.map +1 -0
  50. package/dist/mcp/index.d.cts +2 -0
  51. package/dist/mcp/index.d.ts +2 -0
  52. package/dist/mcp/index.js +492 -0
  53. package/dist/mcp/index.js.map +1 -0
  54. package/dist/response/index.cjs +519 -0
  55. package/dist/response/index.cjs.map +1 -0
  56. package/dist/response/index.d.cts +44 -0
  57. package/dist/response/index.d.ts +44 -0
  58. package/dist/response/index.js +478 -0
  59. package/dist/response/index.js.map +1 -0
  60. package/dist/sources/index.cjs +243 -0
  61. package/dist/sources/index.cjs.map +1 -0
  62. package/dist/sources/index.d.cts +44 -0
  63. package/dist/sources/index.d.ts +44 -0
  64. package/dist/sources/index.js +212 -0
  65. package/dist/sources/index.js.map +1 -0
  66. package/dist/streaming/index.cjs +531 -0
  67. package/dist/streaming/index.cjs.map +1 -0
  68. package/dist/streaming/index.d.cts +81 -0
  69. package/dist/streaming/index.d.ts +81 -0
  70. package/dist/streaming/index.js +495 -0
  71. package/dist/streaming/index.js.map +1 -0
  72. package/dist/streaming-DbQxScpi.d.ts +39 -0
  73. package/dist/streaming-DfT22A0z.d.cts +39 -0
  74. package/package.json +62 -17
@@ -0,0 +1,1239 @@
1
+ // src/chat/AgentChat/AgentChat.tsx
2
+ import { twMerge as twMerge8 } from "tailwind-merge";
3
+
4
+ // src/hooks/useAgentChat.ts
5
+ import { useReducer, useCallback, useRef } from "react";
6
+ var initialState = {
7
+ messages: [],
8
+ conversationId: null,
9
+ isLoading: false,
10
+ error: null,
11
+ inputValue: "",
12
+ streamPhase: "idle",
13
+ streamingContent: ""
14
+ };
15
+ function reducer(state, action) {
16
+ switch (action.type) {
17
+ case "SET_INPUT":
18
+ return { ...state, inputValue: action.value };
19
+ case "SEND_START":
20
+ return {
21
+ ...state,
22
+ messages: [...state.messages, action.message],
23
+ isLoading: true,
24
+ error: null,
25
+ inputValue: "",
26
+ streamPhase: "thinking",
27
+ streamingContent: ""
28
+ };
29
+ case "STREAM_PHASE":
30
+ return { ...state, streamPhase: action.phase };
31
+ case "STREAM_CONTENT":
32
+ return { ...state, streamingContent: state.streamingContent + action.content };
33
+ case "SEND_SUCCESS":
34
+ return {
35
+ ...state,
36
+ messages: [...state.messages, action.message],
37
+ conversationId: action.conversationId ?? state.conversationId,
38
+ isLoading: false,
39
+ streamPhase: "idle",
40
+ streamingContent: ""
41
+ };
42
+ case "SEND_ERROR":
43
+ return {
44
+ ...state,
45
+ isLoading: false,
46
+ error: action.error,
47
+ streamPhase: "idle",
48
+ streamingContent: ""
49
+ };
50
+ case "LOAD_CONVERSATION":
51
+ return {
52
+ ...state,
53
+ conversationId: action.conversationId,
54
+ messages: action.messages,
55
+ error: null
56
+ };
57
+ case "RESET":
58
+ return { ...initialState };
59
+ case "CLEAR_ERROR":
60
+ return { ...state, error: null };
61
+ default:
62
+ return state;
63
+ }
64
+ }
65
+ var msgIdCounter = 0;
66
+ function generateMessageId() {
67
+ return `msg-${Date.now()}-${++msgIdCounter}`;
68
+ }
69
+ function useAgentChat(config) {
70
+ const [state, dispatch] = useReducer(reducer, initialState);
71
+ const configRef = useRef(config);
72
+ configRef.current = config;
73
+ const lastUserMessageRef = useRef(null);
74
+ const sendMessage = useCallback(
75
+ async (content) => {
76
+ const { apiUrl, streamPath = "/chat/stream", headers = {}, timeout = 3e4 } = configRef.current;
77
+ lastUserMessageRef.current = content;
78
+ const userMessage = {
79
+ id: generateMessageId(),
80
+ role: "user",
81
+ content,
82
+ timestamp: /* @__PURE__ */ new Date()
83
+ };
84
+ dispatch({ type: "SEND_START", message: userMessage });
85
+ const controller = new AbortController();
86
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
87
+ try {
88
+ const response = await fetch(`${apiUrl}${streamPath}`, {
89
+ method: "POST",
90
+ headers: {
91
+ "Content-Type": "application/json",
92
+ Accept: "text/event-stream",
93
+ ...headers
94
+ },
95
+ body: JSON.stringify({
96
+ message: content,
97
+ conversation_id: state.conversationId
98
+ }),
99
+ signal: controller.signal
100
+ });
101
+ clearTimeout(timeoutId);
102
+ if (!response.ok) {
103
+ dispatch({
104
+ type: "SEND_ERROR",
105
+ error: {
106
+ code: "API_ERROR",
107
+ message: `HTTP ${response.status}: ${response.statusText}`,
108
+ retryable: response.status >= 500
109
+ }
110
+ });
111
+ return;
112
+ }
113
+ const reader = response.body?.getReader();
114
+ if (!reader) {
115
+ dispatch({
116
+ type: "SEND_ERROR",
117
+ error: { code: "STREAM_ERROR", message: "No response body", retryable: true }
118
+ });
119
+ return;
120
+ }
121
+ const decoder = new TextDecoder();
122
+ let buffer = "";
123
+ let accumulatedContent = "";
124
+ let agentResponse = null;
125
+ let capturedAgent = null;
126
+ let capturedConversationId = null;
127
+ while (true) {
128
+ const { done, value } = await reader.read();
129
+ if (done) break;
130
+ buffer += decoder.decode(value, { stream: true });
131
+ const lines = buffer.split("\n");
132
+ buffer = lines.pop() ?? "";
133
+ for (const line of lines) {
134
+ if (!line.startsWith("data: ")) continue;
135
+ const data = line.slice(6).trim();
136
+ if (data === "[DONE]") continue;
137
+ try {
138
+ const event = JSON.parse(data);
139
+ switch (event.type) {
140
+ case "agent":
141
+ capturedAgent = event.agent;
142
+ break;
143
+ case "phase":
144
+ dispatch({ type: "STREAM_PHASE", phase: event.phase });
145
+ break;
146
+ case "delta":
147
+ accumulatedContent += event.content;
148
+ dispatch({ type: "STREAM_CONTENT", content: event.content });
149
+ break;
150
+ case "done":
151
+ agentResponse = event.response;
152
+ capturedConversationId = event.conversation_id ?? null;
153
+ break;
154
+ case "error":
155
+ dispatch({ type: "SEND_ERROR", error: event.error });
156
+ return;
157
+ }
158
+ } catch {
159
+ }
160
+ }
161
+ }
162
+ const assistantMessage = {
163
+ id: generateMessageId(),
164
+ role: "assistant",
165
+ content: agentResponse?.message ?? accumulatedContent,
166
+ response: agentResponse ?? void 0,
167
+ agent: capturedAgent ?? void 0,
168
+ timestamp: /* @__PURE__ */ new Date()
169
+ };
170
+ dispatch({
171
+ type: "SEND_SUCCESS",
172
+ message: assistantMessage,
173
+ streamingContent: accumulatedContent,
174
+ conversationId: capturedConversationId
175
+ });
176
+ } catch (err) {
177
+ clearTimeout(timeoutId);
178
+ if (err.name === "AbortError") {
179
+ dispatch({
180
+ type: "SEND_ERROR",
181
+ error: { code: "TIMEOUT", message: "Request timed out", retryable: true }
182
+ });
183
+ } else {
184
+ dispatch({
185
+ type: "SEND_ERROR",
186
+ error: {
187
+ code: "NETWORK_ERROR",
188
+ message: err.message ?? "Network error",
189
+ retryable: true
190
+ }
191
+ });
192
+ }
193
+ }
194
+ },
195
+ [state.conversationId]
196
+ );
197
+ const setInputValue = useCallback((value) => {
198
+ dispatch({ type: "SET_INPUT", value });
199
+ }, []);
200
+ const loadConversation = useCallback((conversationId, messages) => {
201
+ dispatch({ type: "LOAD_CONVERSATION", conversationId, messages });
202
+ }, []);
203
+ const submitFeedback = useCallback(
204
+ async (messageId, rating, comment) => {
205
+ const { apiUrl, feedbackPath = "/feedback", headers = {} } = configRef.current;
206
+ await fetch(`${apiUrl}${feedbackPath}`, {
207
+ method: "POST",
208
+ headers: { "Content-Type": "application/json", ...headers },
209
+ body: JSON.stringify({ messageId, rating, comment })
210
+ });
211
+ },
212
+ []
213
+ );
214
+ const retry = useCallback(async () => {
215
+ if (lastUserMessageRef.current) {
216
+ await sendMessage(lastUserMessageRef.current);
217
+ }
218
+ }, [sendMessage]);
219
+ const reset = useCallback(() => {
220
+ dispatch({ type: "RESET" });
221
+ lastUserMessageRef.current = null;
222
+ }, []);
223
+ const actions = {
224
+ sendMessage,
225
+ setInputValue,
226
+ loadConversation,
227
+ submitFeedback,
228
+ retry,
229
+ reset
230
+ };
231
+ return { state, actions };
232
+ }
233
+
234
+ // src/chat/MessageThread/MessageThread.tsx
235
+ import { twMerge as twMerge5 } from "tailwind-merge";
236
+ import { useEffect, useRef as useRef2 } from "react";
237
+
238
+ // src/chat/MessageBubble/MessageBubble.tsx
239
+ import { twMerge as twMerge4 } from "tailwind-merge";
240
+
241
+ // src/response/AgentResponse/AgentResponse.tsx
242
+ import { Badge as Badge2 } from "@surf-kit/core";
243
+
244
+ // src/response/ResponseMessage/ResponseMessage.tsx
245
+ import ReactMarkdown from "react-markdown";
246
+ import rehypeSanitize from "rehype-sanitize";
247
+ import { twMerge } from "tailwind-merge";
248
+ import { jsx } from "react/jsx-runtime";
249
+ function normalizeMarkdownLists(content) {
250
+ return content.replace(/:\s+-\s+/g, ":\n\n- ");
251
+ }
252
+ function ResponseMessage({ content, className }) {
253
+ return /* @__PURE__ */ jsx(
254
+ "div",
255
+ {
256
+ className: twMerge(
257
+ "text-sm leading-relaxed text-text-primary",
258
+ "[&_p]:my-2",
259
+ "[&_ul]:my-2 [&_ul]:list-disc [&_ul]:pl-6",
260
+ "[&_ol]:my-2 [&_ol]:list-decimal [&_ol]:pl-6",
261
+ "[&_li]:my-1",
262
+ "[&_strong]:text-text-primary [&_strong]:font-semibold",
263
+ "[&_em]:text-text-secondary",
264
+ "[&_h1]:text-lg [&_h1]:font-semibold [&_h1]:text-text-primary [&_h1]:mt-4 [&_h1]:mb-2",
265
+ "[&_h2]:text-base [&_h2]:font-semibold [&_h2]:text-text-primary [&_h2]:mt-3 [&_h2]:mb-1.5",
266
+ "[&_h3]:text-sm [&_h3]:font-semibold [&_h3]:text-accent [&_h3]:mt-2 [&_h3]:mb-1",
267
+ "[&_code]:bg-surface-raised [&_code]:text-accent [&_code]:px-1.5 [&_code]:py-0.5 [&_code]:rounded [&_code]:text-xs [&_code]:font-mono",
268
+ "[&_pre]:bg-surface-raised [&_pre]:border [&_pre]:border-border [&_pre]:rounded-xl [&_pre]:p-4 [&_pre]:overflow-x-auto",
269
+ "[&_blockquote]:border-l-2 [&_blockquote]:border-border-strong [&_blockquote]:pl-4 [&_blockquote]:text-text-secondary",
270
+ "[&_a]:text-accent [&_a]:underline-offset-2 [&_a]:hover:text-accent/80",
271
+ className
272
+ ),
273
+ "data-testid": "response-message",
274
+ children: /* @__PURE__ */ jsx(
275
+ ReactMarkdown,
276
+ {
277
+ rehypePlugins: [rehypeSanitize],
278
+ components: {
279
+ script: () => null,
280
+ iframe: () => null,
281
+ p: ({ children }) => /* @__PURE__ */ jsx("p", { className: "my-2", children }),
282
+ ul: ({ children }) => /* @__PURE__ */ jsx("ul", { className: "my-2 list-disc pl-6", children }),
283
+ ol: ({ children }) => /* @__PURE__ */ jsx("ol", { className: "my-2 list-decimal pl-6", children }),
284
+ li: ({ children }) => /* @__PURE__ */ jsx("li", { className: "my-1", children }),
285
+ strong: ({ children }) => /* @__PURE__ */ jsx("strong", { className: "font-semibold", children }),
286
+ h1: ({ children }) => /* @__PURE__ */ jsx("h1", { className: "text-base font-bold mt-4 mb-2", children }),
287
+ h2: ({ children }) => /* @__PURE__ */ jsx("h2", { className: "text-sm font-bold mt-3 mb-1", children }),
288
+ h3: ({ children }) => /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold mt-2 mb-1", children }),
289
+ code: ({ children }) => /* @__PURE__ */ jsx("code", { className: "bg-surface-sunken rounded px-1 py-0.5 text-xs font-mono", children })
290
+ },
291
+ children: normalizeMarkdownLists(content)
292
+ }
293
+ )
294
+ }
295
+ );
296
+ }
297
+
298
+ // src/response/StructuredResponse/StructuredResponse.tsx
299
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
300
+ function tryParse(value) {
301
+ if (value === void 0 || value === null) return null;
302
+ if (typeof value === "string") {
303
+ try {
304
+ return JSON.parse(value);
305
+ } catch {
306
+ return null;
307
+ }
308
+ }
309
+ return value;
310
+ }
311
+ function renderSteps(data) {
312
+ const steps = tryParse(data.steps);
313
+ if (!steps || !Array.isArray(steps)) return null;
314
+ return /* @__PURE__ */ jsx2("ol", { className: "flex flex-col gap-2", "data-testid": "structured-steps", children: steps.map((step, i) => /* @__PURE__ */ jsxs("li", { className: "flex items-start gap-3", children: [
315
+ /* @__PURE__ */ jsx2(
316
+ "span",
317
+ {
318
+ className: "mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-accent text-[11px] font-semibold text-white",
319
+ "aria-hidden": "true",
320
+ children: i + 1
321
+ }
322
+ ),
323
+ /* @__PURE__ */ jsx2("span", { className: "text-sm text-text-primary leading-relaxed", children: step })
324
+ ] }, i)) });
325
+ }
326
+ function renderTable(data) {
327
+ const columns = tryParse(data.columns);
328
+ const rawRows = tryParse(data.rows);
329
+ if (columns && rawRows && Array.isArray(columns) && Array.isArray(rawRows)) {
330
+ return /* @__PURE__ */ jsx2("div", { className: "overflow-x-auto rounded-lg border border-border", "data-testid": "structured-table", children: /* @__PURE__ */ jsxs("table", { role: "table", className: "w-full border-collapse text-sm", children: [
331
+ /* @__PURE__ */ jsx2("thead", { className: "bg-surface-raised", children: /* @__PURE__ */ jsx2("tr", { children: columns.map((col) => /* @__PURE__ */ jsx2(
332
+ "th",
333
+ {
334
+ className: "text-left px-4 py-2.5 font-semibold text-text-primary border-b border-border",
335
+ children: col
336
+ },
337
+ col
338
+ )) }) }),
339
+ /* @__PURE__ */ jsx2("tbody", { children: rawRows.map((row, i) => {
340
+ const cells = Array.isArray(row) ? row : columns.map((col) => row[col]);
341
+ return /* @__PURE__ */ jsx2("tr", { className: "even:bg-surface-raised/40", children: cells.map((cell, j) => /* @__PURE__ */ jsx2("td", { className: "px-4 py-2 text-text-secondary border-b border-border", children: String(cell ?? "") }, j)) }, i);
342
+ }) })
343
+ ] }) });
344
+ }
345
+ const entries = Object.entries(data);
346
+ return /* @__PURE__ */ jsx2("div", { className: "overflow-x-auto rounded-lg border border-border", "data-testid": "structured-table", children: /* @__PURE__ */ jsx2("table", { role: "table", className: "w-full border-collapse text-sm", children: /* @__PURE__ */ jsx2("tbody", { children: entries.map(([key, value]) => /* @__PURE__ */ jsxs("tr", { className: "even:bg-surface-raised/40", children: [
347
+ /* @__PURE__ */ jsx2("td", { className: "px-4 py-2 text-text-primary font-medium border-b border-border w-1/3", children: key }),
348
+ /* @__PURE__ */ jsx2("td", { className: "px-4 py-2 text-text-secondary border-b border-border", children: typeof value === "object" ? JSON.stringify(value) : String(value ?? "") })
349
+ ] }, key)) }) }) });
350
+ }
351
+ function renderCard(data) {
352
+ const title = typeof data.title === "string" ? data.title : null;
353
+ const body = typeof data.body === "string" ? data.body : null;
354
+ const link = typeof data.link === "string" ? data.link : null;
355
+ const linkLabel = typeof data.link_label === "string" ? data.link_label : "Learn more";
356
+ return /* @__PURE__ */ jsxs(
357
+ "div",
358
+ {
359
+ className: "rounded-xl border border-border bg-surface-raised p-4 flex flex-col gap-2",
360
+ "data-testid": "structured-card",
361
+ children: [
362
+ title && /* @__PURE__ */ jsx2("p", { className: "text-sm font-semibold text-text-primary", children: title }),
363
+ body && /* @__PURE__ */ jsx2("p", { className: "text-sm text-text-secondary leading-relaxed", children: body }),
364
+ link && /* @__PURE__ */ jsxs(
365
+ "a",
366
+ {
367
+ href: link,
368
+ target: "_blank",
369
+ rel: "noopener noreferrer",
370
+ className: "mt-1 inline-flex items-center gap-1 text-xs font-medium text-accent hover:text-accent/80 underline-offset-2 hover:underline transition-colors",
371
+ children: [
372
+ linkLabel,
373
+ /* @__PURE__ */ jsx2("svg", { className: "h-3 w-3", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 2, children: /* @__PURE__ */ jsx2("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" }) })
374
+ ]
375
+ }
376
+ )
377
+ ]
378
+ }
379
+ );
380
+ }
381
+ function renderList(data) {
382
+ const items = tryParse(data.items);
383
+ const title = typeof data.title === "string" ? data.title : null;
384
+ if (!items || !Array.isArray(items)) return null;
385
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", "data-testid": "structured-list", children: [
386
+ title && /* @__PURE__ */ jsx2("p", { className: "text-xs font-semibold uppercase tracking-wider text-text-secondary mb-1", children: title }),
387
+ /* @__PURE__ */ jsx2("ul", { className: "flex flex-col gap-1.5", children: items.map((item, i) => /* @__PURE__ */ jsxs("li", { className: "flex items-start gap-2.5", children: [
388
+ /* @__PURE__ */ jsx2("span", { className: "mt-1.5 h-1.5 w-1.5 shrink-0 rounded-full bg-accent", "aria-hidden": "true" }),
389
+ /* @__PURE__ */ jsx2("span", { className: "text-sm text-text-primary leading-relaxed", children: item })
390
+ ] }, i)) })
391
+ ] });
392
+ }
393
+ function renderWarning(data) {
394
+ const severity = typeof data.severity === "string" ? data.severity : "medium";
395
+ const action = typeof data.action === "string" ? data.action : null;
396
+ const details = typeof data.details === "string" ? data.details : null;
397
+ const isHigh = severity === "high";
398
+ return /* @__PURE__ */ jsxs(
399
+ "div",
400
+ {
401
+ role: "alert",
402
+ className: `rounded-xl border p-4 flex gap-3 ${isHigh ? "border-red-200 bg-red-50 dark:border-red-900/50 dark:bg-red-950/30" : "border-amber-200 bg-amber-50 dark:border-amber-900/50 dark:bg-amber-950/30"}`,
403
+ "data-testid": "structured-warning",
404
+ children: [
405
+ /* @__PURE__ */ jsx2(
406
+ "svg",
407
+ {
408
+ className: `mt-0.5 h-5 w-5 shrink-0 ${isHigh ? "text-red-500" : "text-amber-500"}`,
409
+ fill: "none",
410
+ viewBox: "0 0 24 24",
411
+ stroke: "currentColor",
412
+ strokeWidth: 2,
413
+ children: /* @__PURE__ */ jsx2("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z" })
414
+ }
415
+ ),
416
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
417
+ action && /* @__PURE__ */ jsx2("p", { className: `text-sm font-semibold ${isHigh ? "text-red-700 dark:text-red-300" : "text-amber-700 dark:text-amber-300"}`, children: action }),
418
+ details && /* @__PURE__ */ jsx2("p", { className: `text-sm ${isHigh ? "text-red-600 dark:text-red-400" : "text-amber-600 dark:text-amber-400"}`, children: details })
419
+ ] })
420
+ ]
421
+ }
422
+ );
423
+ }
424
+ function StructuredResponse({ uiHint, data, className }) {
425
+ if (!data) return null;
426
+ let content;
427
+ switch (uiHint) {
428
+ case "steps":
429
+ content = renderSteps(data);
430
+ break;
431
+ case "table":
432
+ content = renderTable(data);
433
+ break;
434
+ case "card":
435
+ content = renderCard(data);
436
+ break;
437
+ case "list":
438
+ content = renderList(data);
439
+ break;
440
+ case "warning":
441
+ content = renderWarning(data);
442
+ break;
443
+ case "text":
444
+ content = typeof data.text === "string" ? /* @__PURE__ */ jsx2("p", { "data-testid": "structured-text", children: data.text }) : null;
445
+ break;
446
+ default:
447
+ content = null;
448
+ }
449
+ if (!content) return null;
450
+ return /* @__PURE__ */ jsx2("div", { className, "data-testid": "structured-response", children: content });
451
+ }
452
+
453
+ // src/sources/SourceList/SourceList.tsx
454
+ import { useState } from "react";
455
+
456
+ // src/sources/SourceCard/SourceCard.tsx
457
+ import { Badge } from "@surf-kit/core";
458
+ import { twMerge as twMerge2 } from "tailwind-merge";
459
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
460
+ function getConfidenceIntent(confidence) {
461
+ if (confidence >= 0.8) return "success";
462
+ if (confidence >= 0.5) return "warning";
463
+ return "error";
464
+ }
465
+ function getConfidenceLabel(confidence) {
466
+ if (confidence >= 0.8) return "High";
467
+ if (confidence >= 0.5) return "Medium";
468
+ return "Low";
469
+ }
470
+ function SourceCard({ source, variant = "compact", onNavigate, className }) {
471
+ const handleClick = () => {
472
+ if (onNavigate) {
473
+ onNavigate(source);
474
+ }
475
+ };
476
+ const isCompact = variant === "compact";
477
+ return /* @__PURE__ */ jsx3(
478
+ "div",
479
+ {
480
+ className: twMerge2(
481
+ "rounded-xl border transition-all duration-200",
482
+ "bg-surface border-border",
483
+ onNavigate && "cursor-pointer hover:border-border-strong",
484
+ className
485
+ ),
486
+ "data-document-id": source.document_id,
487
+ "data-testid": "source-card",
488
+ children: /* @__PURE__ */ jsxs2(
489
+ "div",
490
+ {
491
+ className: isCompact ? "px-4 py-3" : "px-6 py-4",
492
+ onClick: handleClick,
493
+ role: onNavigate ? "button" : void 0,
494
+ tabIndex: onNavigate ? 0 : void 0,
495
+ onKeyDown: onNavigate ? (e) => {
496
+ if (e.key === "Enter" || e.key === " ") {
497
+ e.preventDefault();
498
+ handleClick();
499
+ }
500
+ } : void 0,
501
+ children: [
502
+ /* @__PURE__ */ jsxs2("div", { className: "flex items-start justify-between gap-2", children: [
503
+ /* @__PURE__ */ jsxs2("div", { className: "flex-1 min-w-0", children: [
504
+ /* @__PURE__ */ jsx3("p", { className: "text-sm font-medium text-text-primary truncate", children: source.title }),
505
+ source.section && /* @__PURE__ */ jsx3("p", { className: "text-[11px] font-semibold uppercase tracking-wider text-text-secondary truncate mt-0.5", children: source.section })
506
+ ] }),
507
+ /* @__PURE__ */ jsx3(
508
+ Badge,
509
+ {
510
+ intent: getConfidenceIntent(source.confidence),
511
+ size: "sm",
512
+ children: getConfidenceLabel(source.confidence)
513
+ }
514
+ )
515
+ ] }),
516
+ !isCompact && /* @__PURE__ */ jsx3("p", { className: "text-xs text-text-secondary mt-2 line-clamp-3 leading-relaxed", children: source.snippet })
517
+ ]
518
+ }
519
+ )
520
+ }
521
+ );
522
+ }
523
+
524
+ // src/sources/SourceList/SourceList.tsx
525
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
526
+ function SourceList({
527
+ sources,
528
+ variant = "compact",
529
+ collapsible = false,
530
+ defaultExpanded = true,
531
+ onNavigate,
532
+ className
533
+ }) {
534
+ const [isExpanded, setIsExpanded] = useState(defaultExpanded);
535
+ if (sources.length === 0) return null;
536
+ const content = /* @__PURE__ */ jsx4("div", { className: "flex flex-col gap-1.5", "data-testid": "source-list-items", children: sources.map((source) => /* @__PURE__ */ jsx4(
537
+ SourceCard,
538
+ {
539
+ source,
540
+ variant,
541
+ onNavigate
542
+ },
543
+ source.document_id
544
+ )) });
545
+ if (!collapsible) {
546
+ return /* @__PURE__ */ jsx4("div", { className, "data-testid": "source-list", children: content });
547
+ }
548
+ return /* @__PURE__ */ jsxs3("div", { className, "data-testid": "source-list", children: [
549
+ /* @__PURE__ */ jsxs3(
550
+ "button",
551
+ {
552
+ type: "button",
553
+ onClick: () => setIsExpanded((prev) => !prev),
554
+ "aria-expanded": isExpanded,
555
+ className: "flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wider text-text-secondary hover:text-accent mb-2 transition-colors duration-200",
556
+ children: [
557
+ /* @__PURE__ */ jsx4(
558
+ "svg",
559
+ {
560
+ className: `w-4 h-4 transition-transform ${isExpanded ? "rotate-180" : ""}`,
561
+ fill: "none",
562
+ viewBox: "0 0 24 24",
563
+ stroke: "currentColor",
564
+ strokeWidth: 2,
565
+ children: /* @__PURE__ */ jsx4("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19 9l-7 7-7-7" })
566
+ }
567
+ ),
568
+ "Sources (",
569
+ sources.length,
570
+ ")"
571
+ ]
572
+ }
573
+ ),
574
+ isExpanded && content
575
+ ] });
576
+ }
577
+
578
+ // src/response/FollowUpChips/FollowUpChips.tsx
579
+ import { twMerge as twMerge3 } from "tailwind-merge";
580
+ import { jsx as jsx5 } from "react/jsx-runtime";
581
+ function FollowUpChips({ suggestions, onSelect, className }) {
582
+ if (suggestions.length === 0) return null;
583
+ return /* @__PURE__ */ jsx5(
584
+ "div",
585
+ {
586
+ className: twMerge3("flex flex-wrap gap-2 py-1", className),
587
+ role: "group",
588
+ "aria-label": "Follow-up suggestions",
589
+ "data-testid": "follow-up-chips",
590
+ children: suggestions.map((suggestion) => /* @__PURE__ */ jsx5(
591
+ "button",
592
+ {
593
+ type: "button",
594
+ onClick: () => onSelect(suggestion),
595
+ className: twMerge3(
596
+ "px-4 py-1.5 rounded-full text-sm whitespace-nowrap",
597
+ "border border-border bg-transparent text-text-secondary",
598
+ "hover:bg-accent/10 hover:border-interactive hover:text-text-primary",
599
+ "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent",
600
+ "transition-all duration-200"
601
+ ),
602
+ children: suggestion
603
+ },
604
+ suggestion
605
+ ))
606
+ }
607
+ );
608
+ }
609
+
610
+ // src/response/AgentResponse/AgentResponse.tsx
611
+ import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
612
+ function getConfidenceIntent2(overall) {
613
+ if (overall === "high") return "success";
614
+ if (overall === "medium") return "warning";
615
+ return "error";
616
+ }
617
+ function getVerificationIntent(status) {
618
+ if (status === "passed") return "success";
619
+ if (status === "flagged") return "warning";
620
+ return "error";
621
+ }
622
+ function getVerificationLabel(status) {
623
+ if (status === "passed") return "Verified";
624
+ if (status === "flagged") return "Flagged";
625
+ return "Failed";
626
+ }
627
+ function AgentResponse({
628
+ response,
629
+ showSources = true,
630
+ showConfidence = false,
631
+ showVerification = false,
632
+ onFollowUp,
633
+ onNavigateSource,
634
+ className
635
+ }) {
636
+ return /* @__PURE__ */ jsxs4("div", { className: `flex flex-col gap-4 ${className ?? ""}`, "data-testid": "agent-response", children: [
637
+ /* @__PURE__ */ jsx6(ResponseMessage, { content: response.message }),
638
+ response.ui_hint !== "text" && response.structured_data && /* @__PURE__ */ jsx6(
639
+ StructuredResponse,
640
+ {
641
+ uiHint: response.ui_hint,
642
+ data: response.structured_data
643
+ }
644
+ ),
645
+ (showConfidence || showVerification) && /* @__PURE__ */ jsxs4("div", { className: "flex flex-wrap items-center gap-2 mt-1", "data-testid": "response-meta", children: [
646
+ showConfidence && /* @__PURE__ */ jsxs4(
647
+ Badge2,
648
+ {
649
+ intent: getConfidenceIntent2(response.confidence.overall),
650
+ size: "sm",
651
+ children: [
652
+ response.confidence.overall,
653
+ " confidence"
654
+ ]
655
+ }
656
+ ),
657
+ showVerification && /* @__PURE__ */ jsxs4(
658
+ Badge2,
659
+ {
660
+ intent: getVerificationIntent(response.verification.status),
661
+ size: "sm",
662
+ children: [
663
+ getVerificationLabel(response.verification.status),
664
+ " (",
665
+ response.verification.claims_verified,
666
+ "/",
667
+ response.verification.claims_checked,
668
+ ")"
669
+ ]
670
+ }
671
+ )
672
+ ] }),
673
+ showSources && response.sources.length > 0 && /* @__PURE__ */ jsx6(
674
+ SourceList,
675
+ {
676
+ sources: response.sources,
677
+ variant: "compact",
678
+ collapsible: true,
679
+ defaultExpanded: false,
680
+ onNavigate: onNavigateSource
681
+ }
682
+ ),
683
+ response.follow_up_suggestions.length > 0 && onFollowUp && /* @__PURE__ */ jsx6(
684
+ FollowUpChips,
685
+ {
686
+ suggestions: response.follow_up_suggestions,
687
+ onSelect: onFollowUp
688
+ }
689
+ )
690
+ ] });
691
+ }
692
+
693
+ // src/chat/MessageBubble/MessageBubble.tsx
694
+ import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
695
+ function MessageBubble({
696
+ message,
697
+ showAgent,
698
+ showSources = true,
699
+ showConfidence = true,
700
+ showVerification = true,
701
+ animated = true,
702
+ className
703
+ }) {
704
+ const isUser = message.role === "user";
705
+ if (isUser) {
706
+ return /* @__PURE__ */ jsx7(
707
+ "div",
708
+ {
709
+ "data-message-id": message.id,
710
+ className: twMerge4("flex w-full justify-end", className),
711
+ children: /* @__PURE__ */ jsx7(
712
+ "div",
713
+ {
714
+ className: twMerge4(
715
+ "max-w-[70%] rounded-[18px] rounded-br-[4px] px-4 py-2.5 bg-accent text-brand-cream break-words whitespace-pre-wrap text-sm leading-relaxed",
716
+ animated && "motion-safe:animate-slideFromRight"
717
+ ),
718
+ children: message.content
719
+ }
720
+ )
721
+ }
722
+ );
723
+ }
724
+ return /* @__PURE__ */ jsxs5(
725
+ "div",
726
+ {
727
+ "data-message-id": message.id,
728
+ className: twMerge4("flex w-full flex-col items-start gap-1.5", className),
729
+ children: [
730
+ showAgent && message.agent && /* @__PURE__ */ jsx7("div", { className: "text-[11px] font-semibold uppercase tracking-[0.08em] text-text-muted px-1", children: message.agent.replace("_agent", "").replace("_", " ") }),
731
+ /* @__PURE__ */ jsx7(
732
+ "div",
733
+ {
734
+ className: twMerge4(
735
+ "max-w-[88%] rounded-[18px] rounded-tl-[4px] px-4 py-3 bg-surface border border-border",
736
+ animated && "motion-safe:animate-springFromLeft"
737
+ ),
738
+ children: message.response ? /* @__PURE__ */ jsx7(
739
+ AgentResponse,
740
+ {
741
+ response: message.response,
742
+ showSources,
743
+ showConfidence,
744
+ showVerification
745
+ }
746
+ ) : /* @__PURE__ */ jsx7(ResponseMessage, { content: message.content })
747
+ }
748
+ )
749
+ ]
750
+ }
751
+ );
752
+ }
753
+
754
+ // src/chat/MessageThread/MessageThread.tsx
755
+ import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
756
+ function MessageThread({ messages, streamingSlot, showSources, showConfidence, showVerification, className }) {
757
+ const bottomRef = useRef2(null);
758
+ useEffect(() => {
759
+ bottomRef.current?.scrollIntoView?.({ behavior: "smooth" });
760
+ }, [messages.length, streamingSlot]);
761
+ return /* @__PURE__ */ jsxs6(
762
+ "div",
763
+ {
764
+ role: "log",
765
+ "aria-live": "polite",
766
+ "aria-label": "Message thread",
767
+ className: twMerge5(
768
+ "flex flex-col gap-4 overflow-y-auto flex-1 px-4 py-6",
769
+ className
770
+ ),
771
+ children: [
772
+ messages.map((message) => /* @__PURE__ */ jsx8(
773
+ MessageBubble,
774
+ {
775
+ message,
776
+ showSources,
777
+ showConfidence,
778
+ showVerification
779
+ },
780
+ message.id
781
+ )),
782
+ streamingSlot,
783
+ /* @__PURE__ */ jsx8("div", { ref: bottomRef })
784
+ ]
785
+ }
786
+ );
787
+ }
788
+
789
+ // src/chat/MessageComposer/MessageComposer.tsx
790
+ import { twMerge as twMerge6 } from "tailwind-merge";
791
+ import { useState as useState2, useRef as useRef3, useCallback as useCallback2 } from "react";
792
+ import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
793
+ function MessageComposer({
794
+ onSend,
795
+ isLoading = false,
796
+ placeholder = "Type a message...",
797
+ className
798
+ }) {
799
+ const [value, setValue] = useState2("");
800
+ const textareaRef = useRef3(null);
801
+ const canSend = value.trim().length > 0 && !isLoading;
802
+ const resetHeight = useCallback2(() => {
803
+ const el = textareaRef.current;
804
+ if (el) {
805
+ el.style.height = "auto";
806
+ el.style.overflowY = "hidden";
807
+ }
808
+ }, []);
809
+ const handleSend = useCallback2(() => {
810
+ if (!canSend) return;
811
+ onSend(value.trim());
812
+ setValue("");
813
+ resetHeight();
814
+ textareaRef.current?.focus();
815
+ }, [canSend, onSend, value, resetHeight]);
816
+ const handleKeyDown = useCallback2(
817
+ (e) => {
818
+ if (e.key === "Enter" && !e.shiftKey) {
819
+ e.preventDefault();
820
+ handleSend();
821
+ }
822
+ },
823
+ [handleSend]
824
+ );
825
+ const handleChange = useCallback2(
826
+ (e) => {
827
+ setValue(e.target.value);
828
+ const el = e.target;
829
+ el.style.height = "auto";
830
+ const capped = Math.min(el.scrollHeight, 128);
831
+ el.style.height = `${capped}px`;
832
+ el.style.overflowY = el.scrollHeight > 128 ? "auto" : "hidden";
833
+ },
834
+ []
835
+ );
836
+ return /* @__PURE__ */ jsxs7(
837
+ "div",
838
+ {
839
+ className: twMerge6(
840
+ "flex items-end gap-3 shrink-0 border-t border-border px-4 py-3",
841
+ className
842
+ ),
843
+ children: [
844
+ /* @__PURE__ */ jsx9(
845
+ "textarea",
846
+ {
847
+ ref: textareaRef,
848
+ value,
849
+ onChange: handleChange,
850
+ onKeyDown: handleKeyDown,
851
+ placeholder,
852
+ rows: 1,
853
+ disabled: isLoading,
854
+ className: twMerge6(
855
+ "flex-1 resize-none rounded-xl border border-border bg-surface/80",
856
+ "px-4 py-2.5 text-sm text-text-primary placeholder:text-text-muted",
857
+ "focus:border-transparent focus:ring-2 focus:ring-accent/40 focus:outline-none",
858
+ "disabled:opacity-50 disabled:cursor-not-allowed",
859
+ "overflow-hidden",
860
+ "transition-all duration-200"
861
+ ),
862
+ style: { colorScheme: "dark" },
863
+ "aria-label": "Message input"
864
+ }
865
+ ),
866
+ /* @__PURE__ */ jsx9(
867
+ "button",
868
+ {
869
+ type: "button",
870
+ onClick: handleSend,
871
+ disabled: !value.trim() || isLoading,
872
+ "aria-label": "Send message",
873
+ className: twMerge6(
874
+ "inline-flex items-center justify-center rounded-xl px-5 py-2.5",
875
+ "text-sm font-semibold text-white shrink-0",
876
+ "transition-all duration-200",
877
+ "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent",
878
+ value.trim() && !isLoading ? "bg-accent hover:bg-accent-hover hover:scale-[1.02] hover:shadow-glow-cyan active:scale-[0.98]" : "bg-accent/30 text-text-muted cursor-not-allowed"
879
+ ),
880
+ children: "Send"
881
+ }
882
+ )
883
+ ]
884
+ }
885
+ );
886
+ }
887
+
888
+ // src/chat/WelcomeScreen/WelcomeScreen.tsx
889
+ import { twMerge as twMerge7 } from "tailwind-merge";
890
+ import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
891
+ function WelcomeScreen({
892
+ title = "Welcome",
893
+ message = "How can I help you today?",
894
+ icon,
895
+ suggestedQuestions = [],
896
+ onQuestionSelect,
897
+ className
898
+ }) {
899
+ return /* @__PURE__ */ jsxs8(
900
+ "div",
901
+ {
902
+ className: twMerge7(
903
+ "flex flex-1 flex-col items-center justify-center gap-8 p-8 text-center motion-safe:animate-fadeUp",
904
+ className
905
+ ),
906
+ children: [
907
+ /* @__PURE__ */ jsx10(
908
+ "div",
909
+ {
910
+ className: "w-14 h-14 rounded-2xl bg-accent/10 border border-border flex items-center justify-center pulse-glow",
911
+ "aria-hidden": "true",
912
+ children: icon ?? /* @__PURE__ */ jsx10("span", { className: "text-2xl", children: "\u2726" })
913
+ }
914
+ ),
915
+ /* @__PURE__ */ jsxs8("div", { className: "flex flex-col gap-2", children: [
916
+ title && /* @__PURE__ */ jsx10("h2", { className: "text-3xl font-bold text-text-primary", children: title }),
917
+ /* @__PURE__ */ jsx10("p", { className: "text-text-secondary text-base leading-relaxed max-w-md", children: message })
918
+ ] }),
919
+ suggestedQuestions.length > 0 && /* @__PURE__ */ jsx10(
920
+ "div",
921
+ {
922
+ className: "flex flex-wrap justify-center gap-2 max-w-md",
923
+ role: "group",
924
+ "aria-label": "Suggested questions",
925
+ children: suggestedQuestions.map((question) => /* @__PURE__ */ jsx10(
926
+ "button",
927
+ {
928
+ type: "button",
929
+ onClick: () => onQuestionSelect?.(question),
930
+ className: twMerge7(
931
+ "px-4 py-2 rounded-full text-sm",
932
+ "border border-border bg-transparent text-text-secondary",
933
+ "hover:bg-accent/10 hover:border-interactive hover:text-text-primary",
934
+ "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent",
935
+ "transition-colors duration-200"
936
+ ),
937
+ children: question
938
+ },
939
+ question
940
+ ))
941
+ }
942
+ )
943
+ ]
944
+ }
945
+ );
946
+ }
947
+
948
+ // src/streaming/StreamingMessage/StreamingMessage.tsx
949
+ import { useEffect as useEffect3, useRef as useRef5 } from "react";
950
+ import { Spinner } from "@surf-kit/core";
951
+
952
+ // src/hooks/useCharacterDrain.ts
953
+ import { useState as useState3, useRef as useRef4, useEffect as useEffect2 } from "react";
954
+ function useCharacterDrain(target, msPerChar = 15) {
955
+ const [displayed, setDisplayed] = useState3("");
956
+ const indexRef = useRef4(0);
957
+ const lastTimeRef = useRef4(0);
958
+ const rafRef = useRef4(null);
959
+ const drainTargetRef = useRef4("");
960
+ const msPerCharRef = useRef4(msPerChar);
961
+ msPerCharRef.current = msPerChar;
962
+ if (target !== "") {
963
+ drainTargetRef.current = target;
964
+ }
965
+ const drainTarget = drainTargetRef.current;
966
+ const isDraining = displayed.length < drainTarget.length;
967
+ const tickRef = useRef4(() => {
968
+ });
969
+ tickRef.current = (now) => {
970
+ const currentTarget = drainTargetRef.current;
971
+ if (currentTarget === "") {
972
+ rafRef.current = null;
973
+ return;
974
+ }
975
+ if (lastTimeRef.current === 0) lastTimeRef.current = now;
976
+ const elapsed = now - lastTimeRef.current;
977
+ const charsToAdvance = Math.floor(elapsed / msPerCharRef.current);
978
+ if (charsToAdvance > 0 && indexRef.current < currentTarget.length) {
979
+ const nextIndex = Math.min(indexRef.current + charsToAdvance, currentTarget.length);
980
+ indexRef.current = nextIndex;
981
+ lastTimeRef.current = now;
982
+ setDisplayed(currentTarget.slice(0, nextIndex));
983
+ }
984
+ if (indexRef.current < currentTarget.length) {
985
+ rafRef.current = requestAnimationFrame((t) => tickRef.current(t));
986
+ } else {
987
+ rafRef.current = null;
988
+ }
989
+ };
990
+ useEffect2(() => {
991
+ if (drainTargetRef.current !== "" && indexRef.current < drainTargetRef.current.length && rafRef.current === null) {
992
+ rafRef.current = requestAnimationFrame((t) => tickRef.current(t));
993
+ }
994
+ }, [drainTarget]);
995
+ useEffect2(() => {
996
+ if (target === "" && !isDraining && displayed !== "") {
997
+ indexRef.current = 0;
998
+ lastTimeRef.current = 0;
999
+ drainTargetRef.current = "";
1000
+ setDisplayed("");
1001
+ }
1002
+ }, [target, isDraining, displayed]);
1003
+ useEffect2(() => {
1004
+ return () => {
1005
+ if (rafRef.current !== null) {
1006
+ cancelAnimationFrame(rafRef.current);
1007
+ rafRef.current = null;
1008
+ }
1009
+ };
1010
+ }, []);
1011
+ return { displayed, isDraining };
1012
+ }
1013
+
1014
+ // src/streaming/StreamingMessage/StreamingMessage.tsx
1015
+ import { jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
1016
+ var phaseLabels = {
1017
+ idle: "",
1018
+ waiting: "Waiting...",
1019
+ thinking: "Thinking...",
1020
+ retrieving: "Searching...",
1021
+ generating: "Writing...",
1022
+ verifying: "Verifying..."
1023
+ };
1024
+ function StreamingMessage({
1025
+ stream,
1026
+ onComplete,
1027
+ showPhases = true,
1028
+ className
1029
+ }) {
1030
+ const onCompleteRef = useRef5(onComplete);
1031
+ onCompleteRef.current = onComplete;
1032
+ const wasActiveRef = useRef5(stream.active);
1033
+ useEffect3(() => {
1034
+ if (wasActiveRef.current && !stream.active) {
1035
+ onCompleteRef.current?.();
1036
+ }
1037
+ wasActiveRef.current = stream.active;
1038
+ }, [stream.active]);
1039
+ const phaseLabel = phaseLabels[stream.phase];
1040
+ const { displayed: displayedContent } = useCharacterDrain(stream.content);
1041
+ return /* @__PURE__ */ jsxs9("div", { className, "data-testid": "streaming-message", children: [
1042
+ /* @__PURE__ */ jsxs9("div", { "aria-live": "assertive", className: "sr-only", children: [
1043
+ stream.active && stream.phase !== "idle" && "Response started",
1044
+ !stream.active && stream.content && "Response complete"
1045
+ ] }),
1046
+ /* @__PURE__ */ jsxs9("div", { className: "max-w-[88%] px-4 py-3 rounded-[18px] rounded-tl-[4px] bg-surface border border-border motion-safe:animate-springFromLeft", children: [
1047
+ showPhases && stream.active && stream.phase !== "idle" && /* @__PURE__ */ jsxs9(
1048
+ "div",
1049
+ {
1050
+ className: "flex items-center gap-2 mb-2 text-sm text-text-secondary",
1051
+ "data-testid": "phase-indicator",
1052
+ children: [
1053
+ /* @__PURE__ */ jsx11("span", { "aria-hidden": "true", children: /* @__PURE__ */ jsx11(Spinner, { size: "sm" }) }),
1054
+ /* @__PURE__ */ jsx11("span", { children: phaseLabel })
1055
+ ]
1056
+ }
1057
+ ),
1058
+ /* @__PURE__ */ jsxs9("div", { className: "text-sm leading-relaxed text-text-primary whitespace-pre-wrap", children: [
1059
+ displayedContent,
1060
+ stream.active && /* @__PURE__ */ jsx11(
1061
+ "span",
1062
+ {
1063
+ className: "inline-block w-0.5 h-4 bg-accent align-text-bottom animate-pulse ml-0.5",
1064
+ "aria-hidden": "true",
1065
+ "data-testid": "streaming-cursor"
1066
+ }
1067
+ )
1068
+ ] })
1069
+ ] })
1070
+ ] });
1071
+ }
1072
+
1073
+ // src/chat/AgentChat/AgentChat.tsx
1074
+ import { jsx as jsx12, jsxs as jsxs10 } from "react/jsx-runtime";
1075
+ function AgentChat({
1076
+ endpoint,
1077
+ title = "Chat",
1078
+ welcomeTitle,
1079
+ welcomeMessage = "How can I help you today?",
1080
+ suggestedQuestions = [],
1081
+ showHeader = true,
1082
+ showWelcomeTitle = true,
1083
+ showSources,
1084
+ showConfidence,
1085
+ showVerification,
1086
+ className
1087
+ }) {
1088
+ const { state, actions } = useAgentChat({ apiUrl: endpoint });
1089
+ const hasMessages = state.messages.length > 0;
1090
+ const handleSend = (content) => {
1091
+ void actions.sendMessage(content);
1092
+ };
1093
+ const handleQuestionSelect = (question) => {
1094
+ void actions.sendMessage(question);
1095
+ };
1096
+ return /* @__PURE__ */ jsxs10(
1097
+ "div",
1098
+ {
1099
+ className: twMerge8(
1100
+ "flex flex-col h-full bg-canvas border border-border rounded-xl overflow-hidden",
1101
+ className
1102
+ ),
1103
+ children: [
1104
+ showHeader && /* @__PURE__ */ jsx12("div", { className: "flex items-center justify-between border-b border-border px-4 py-3 bg-surface-raised shrink-0", children: /* @__PURE__ */ jsx12("h1", { className: "text-base font-semibold text-text-primary", children: title }) }),
1105
+ hasMessages ? /* @__PURE__ */ jsx12(
1106
+ MessageThread,
1107
+ {
1108
+ messages: state.messages,
1109
+ streamingSlot: state.isLoading ? /* @__PURE__ */ jsx12(
1110
+ StreamingMessage,
1111
+ {
1112
+ stream: {
1113
+ active: state.isLoading,
1114
+ phase: state.streamPhase,
1115
+ content: state.streamingContent,
1116
+ sources: [],
1117
+ agent: null,
1118
+ agentLabel: null
1119
+ }
1120
+ }
1121
+ ) : void 0,
1122
+ showSources,
1123
+ showConfidence,
1124
+ showVerification
1125
+ }
1126
+ ) : /* @__PURE__ */ jsx12(
1127
+ WelcomeScreen,
1128
+ {
1129
+ title: showWelcomeTitle ? welcomeTitle ?? title : "",
1130
+ message: welcomeMessage,
1131
+ suggestedQuestions,
1132
+ onQuestionSelect: handleQuestionSelect
1133
+ }
1134
+ ),
1135
+ /* @__PURE__ */ jsx12(MessageComposer, { onSend: handleSend, isLoading: state.isLoading })
1136
+ ]
1137
+ }
1138
+ );
1139
+ }
1140
+
1141
+ // src/chat/ConversationList/ConversationList.tsx
1142
+ import { twMerge as twMerge9 } from "tailwind-merge";
1143
+ import { jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
1144
+ function ConversationList({
1145
+ conversations,
1146
+ activeId,
1147
+ onSelect,
1148
+ onDelete,
1149
+ onNew,
1150
+ className
1151
+ }) {
1152
+ return /* @__PURE__ */ jsxs11(
1153
+ "nav",
1154
+ {
1155
+ "aria-label": "Conversation list",
1156
+ className: twMerge9("flex flex-col h-full bg-canvas", className),
1157
+ children: [
1158
+ onNew && /* @__PURE__ */ jsx13("div", { className: "p-3 border-b border-border", children: /* @__PURE__ */ jsx13(
1159
+ "button",
1160
+ {
1161
+ type: "button",
1162
+ onClick: onNew,
1163
+ className: "w-full px-4 py-2.5 rounded-xl text-sm font-semibold bg-accent text-white hover:bg-accent-hover transition-all duration-200",
1164
+ children: "New conversation"
1165
+ }
1166
+ ) }),
1167
+ /* @__PURE__ */ jsxs11("ul", { role: "list", className: "flex-1 overflow-y-auto", children: [
1168
+ conversations.map((conversation) => {
1169
+ const isActive = conversation.id === activeId;
1170
+ return /* @__PURE__ */ jsxs11(
1171
+ "li",
1172
+ {
1173
+ className: twMerge9(
1174
+ "flex items-start border-b border-border transition-colors duration-200",
1175
+ "hover:bg-surface",
1176
+ isActive && "bg-surface-raised border-l-2 border-l-accent"
1177
+ ),
1178
+ children: [
1179
+ /* @__PURE__ */ jsxs11(
1180
+ "button",
1181
+ {
1182
+ type: "button",
1183
+ onClick: () => onSelect(conversation.id),
1184
+ "aria-current": isActive ? "true" : void 0,
1185
+ className: "flex-1 min-w-0 text-left px-4 py-3",
1186
+ children: [
1187
+ /* @__PURE__ */ jsx13("div", { className: "text-sm font-medium text-brand-cream truncate", children: conversation.title }),
1188
+ /* @__PURE__ */ jsx13("div", { className: "text-xs text-brand-cream/40 truncate mt-0.5 leading-relaxed", children: conversation.lastMessage })
1189
+ ]
1190
+ }
1191
+ ),
1192
+ onDelete && /* @__PURE__ */ jsx13(
1193
+ "button",
1194
+ {
1195
+ type: "button",
1196
+ onClick: () => onDelete(conversation.id),
1197
+ "aria-label": `Delete ${conversation.title}`,
1198
+ className: "shrink-0 p-1.5 m-2 rounded-lg text-brand-cream/25 hover:text-brand-watermelon hover:bg-brand-watermelon/10 transition-colors duration-200",
1199
+ children: /* @__PURE__ */ jsxs11(
1200
+ "svg",
1201
+ {
1202
+ xmlns: "http://www.w3.org/2000/svg",
1203
+ width: "14",
1204
+ height: "14",
1205
+ viewBox: "0 0 24 24",
1206
+ fill: "none",
1207
+ stroke: "currentColor",
1208
+ strokeWidth: "2",
1209
+ strokeLinecap: "round",
1210
+ strokeLinejoin: "round",
1211
+ "aria-hidden": "true",
1212
+ children: [
1213
+ /* @__PURE__ */ jsx13("polyline", { points: "3 6 5 6 21 6" }),
1214
+ /* @__PURE__ */ jsx13("path", { d: "M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" })
1215
+ ]
1216
+ }
1217
+ )
1218
+ }
1219
+ )
1220
+ ]
1221
+ },
1222
+ conversation.id
1223
+ );
1224
+ }),
1225
+ conversations.length === 0 && /* @__PURE__ */ jsx13("li", { className: "px-4 py-8 text-center", children: /* @__PURE__ */ jsx13("span", { className: "text-sm text-brand-cream/30 font-body", children: "No conversations yet" }) })
1226
+ ] })
1227
+ ]
1228
+ }
1229
+ );
1230
+ }
1231
+ export {
1232
+ AgentChat,
1233
+ ConversationList,
1234
+ MessageBubble,
1235
+ MessageComposer,
1236
+ MessageThread,
1237
+ WelcomeScreen
1238
+ };
1239
+ //# sourceMappingURL=index.js.map