@leanmcp/ui 0.3.4 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,3521 @@
1
+ import { __name } from './chunk-5RGEQPF3.mjs';
2
+ export { GPTApp, UIApp, getGPTAppMetadata, getGPTAppUri, getUIAppMetadata, getUIAppUri } from './chunk-5RGEQPF3.mjs';
3
+ import * as React26 from 'react';
4
+ import React26__default, { forwardRef, Component, useState, useRef, useCallback, useEffect, createContext, useContext, useMemo, useSyncExternalStore } from 'react';
5
+ import { applyDocumentTheme, applyHostStyleVariables, applyHostFonts, PostMessageTransport, App } from '@modelcontextprotocol/ext-apps';
6
+ export { App, PostMessageTransport, RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY, applyDocumentTheme, applyHostFonts, applyHostStyleVariables, getDocumentTheme } from '@modelcontextprotocol/ext-apps';
7
+ import { XIcon, ChevronDownIcon, CheckIcon, ChevronUpIcon, Loader2, SearchIcon, Search, X, AlertCircle, RefreshCw, ChevronLeft, ChevronRight, WifiOff, CircleIcon, ChevronRightIcon, Check, ArrowUpDown, ArrowUp, ArrowDown, Loader2Icon, OctagonXIcon, TriangleAlertIcon, InfoIcon, CircleCheckIcon } from 'lucide-react';
8
+ import { useTheme } from 'next-themes';
9
+ import { toast, Toaster as Toaster$1 } from 'sonner';
10
+ import { Slot } from '@radix-ui/react-slot';
11
+ import { cva } from 'class-variance-authority';
12
+ import { clsx } from 'clsx';
13
+ import { twMerge } from 'tailwind-merge';
14
+ import * as DialogPrimitive from '@radix-ui/react-dialog';
15
+ import * as SelectPrimitive from '@radix-ui/react-select';
16
+ import { Command as Command$1 } from 'cmdk';
17
+ import * as PopoverPrimitive from '@radix-ui/react-popover';
18
+ import * as LabelPrimitive from '@radix-ui/react-label';
19
+ import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
20
+ import * as SliderPrimitive from '@radix-ui/react-slider';
21
+ import * as SwitchPrimitive from '@radix-ui/react-switch';
22
+ import * as ProgressPrimitive from '@radix-ui/react-progress';
23
+ import { useFormContext, useFormState, FormProvider, Controller } from 'react-hook-form';
24
+ import * as TabsPrimitive2 from '@radix-ui/react-tabs';
25
+ import * as SeparatorPrimitive from '@radix-ui/react-separator';
26
+ import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
27
+ import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
28
+ import * as TooltipPrimitive from '@radix-ui/react-tooltip';
29
+ import { useReactTable, getFilteredRowModel, getSortedRowModel, getCoreRowModel, flexRender } from '@tanstack/react-table';
30
+ import { Chart as Chart$1, CategoryScale, LinearScale, PointElement, LineElement, BarElement, ArcElement, Title, Tooltip as Tooltip$1, Legend } from 'chart.js';
31
+ import { Chart as Chart$2 } from 'react-chartjs-2';
32
+ import { Highlight, themes } from 'prism-react-renderer';
33
+ export { AppBridge } from '@modelcontextprotocol/ext-apps/app-bridge';
34
+
35
+ var McpAppContext = /* @__PURE__ */ createContext(null);
36
+ function AppProvider({ appInfo, capabilities = {}, options = {
37
+ autoResize: true
38
+ }, onTeardown, children }) {
39
+ const [app, setApp] = useState(null);
40
+ const [isConnected, setIsConnected] = useState(false);
41
+ const [error, setError] = useState(null);
42
+ const [hostContext, setHostContext] = useState({});
43
+ const [toolInput, setToolInput] = useState(null);
44
+ const [toolInputPartial, setToolInputPartial] = useState(null);
45
+ const [toolResult, setToolResult] = useState(null);
46
+ const [toolCancelled, setToolCancelled] = useState({
47
+ cancelled: false
48
+ });
49
+ const stylesApplied = useRef(false);
50
+ const applyHostStyles = useCallback((context) => {
51
+ if (context.theme) {
52
+ applyDocumentTheme(context.theme);
53
+ }
54
+ if (context.styles?.variables) {
55
+ applyHostStyleVariables(context.styles.variables);
56
+ }
57
+ if (context.styles?.css?.fonts) {
58
+ applyHostFonts(context.styles.css.fonts);
59
+ }
60
+ }, []);
61
+ useEffect(() => {
62
+ let mounted = true;
63
+ let appInstance = null;
64
+ async function connect() {
65
+ try {
66
+ const transport = new PostMessageTransport(window.parent);
67
+ appInstance = new App(appInfo, capabilities, options);
68
+ appInstance.ontoolinput = (params) => {
69
+ if (mounted) {
70
+ setToolInput(params.arguments);
71
+ setToolCancelled({
72
+ cancelled: false
73
+ });
74
+ }
75
+ };
76
+ appInstance.ontoolinputpartial = (params) => {
77
+ if (mounted) {
78
+ setToolInputPartial(params.arguments);
79
+ }
80
+ };
81
+ appInstance.ontoolresult = (params) => {
82
+ if (mounted) {
83
+ setToolResult(params);
84
+ }
85
+ };
86
+ appInstance.ontoolcancelled = (params) => {
87
+ if (mounted) {
88
+ setToolCancelled({
89
+ cancelled: true,
90
+ reason: params.reason
91
+ });
92
+ }
93
+ };
94
+ appInstance.onhostcontextchanged = (params) => {
95
+ if (mounted) {
96
+ setHostContext((prev) => ({
97
+ ...prev,
98
+ ...params
99
+ }));
100
+ applyHostStyles(params);
101
+ }
102
+ };
103
+ if (onTeardown) {
104
+ appInstance.onteardown = async () => {
105
+ await onTeardown();
106
+ return {};
107
+ };
108
+ }
109
+ await appInstance.connect(transport);
110
+ if (mounted) {
111
+ setApp(appInstance);
112
+ setIsConnected(true);
113
+ setError(null);
114
+ const initialContext = appInstance.getHostContext();
115
+ if (initialContext) {
116
+ setHostContext(initialContext);
117
+ if (!stylesApplied.current) {
118
+ applyHostStyles(initialContext);
119
+ stylesApplied.current = true;
120
+ }
121
+ }
122
+ }
123
+ } catch (err) {
124
+ if (mounted) {
125
+ setError(err instanceof Error ? err : new Error(String(err)));
126
+ setIsConnected(false);
127
+ }
128
+ }
129
+ }
130
+ __name(connect, "connect");
131
+ connect();
132
+ return () => {
133
+ mounted = false;
134
+ if (appInstance) {
135
+ appInstance.close();
136
+ }
137
+ };
138
+ }, [
139
+ appInfo.name,
140
+ appInfo.version,
141
+ applyHostStyles,
142
+ onTeardown
143
+ ]);
144
+ const callTool = useCallback(async (name, args = {}) => {
145
+ if (!app) {
146
+ throw new Error("Not connected to host");
147
+ }
148
+ setToolCancelled({
149
+ cancelled: false
150
+ });
151
+ const result = await app.callServerTool({
152
+ name,
153
+ arguments: args
154
+ });
155
+ setToolResult(result);
156
+ return result;
157
+ }, [
158
+ app
159
+ ]);
160
+ const sendMessage = useCallback(async (text) => {
161
+ if (!app) {
162
+ console.warn("[AppProvider] Not connected - cannot send message");
163
+ return;
164
+ }
165
+ await app.sendMessage({
166
+ role: "user",
167
+ content: [
168
+ {
169
+ type: "text",
170
+ text
171
+ }
172
+ ]
173
+ });
174
+ }, [
175
+ app
176
+ ]);
177
+ const sendLog = useCallback(async (level, data) => {
178
+ if (!app) {
179
+ console.log(`[MCP App] ${level}:`, data);
180
+ return;
181
+ }
182
+ await app.sendLog({
183
+ level,
184
+ data
185
+ });
186
+ }, [
187
+ app
188
+ ]);
189
+ const openLink = useCallback(async (url) => {
190
+ if (!app) {
191
+ window.open(url, "_blank", "noopener,noreferrer");
192
+ return;
193
+ }
194
+ await app.openLink({
195
+ url
196
+ });
197
+ }, [
198
+ app
199
+ ]);
200
+ const requestDisplayMode = useCallback(async (mode) => {
201
+ if (!app) {
202
+ console.warn("[AppProvider] Not connected - cannot request display mode");
203
+ return "inline";
204
+ }
205
+ const result = await app.requestDisplayMode({
206
+ mode
207
+ });
208
+ return result.mode;
209
+ }, [
210
+ app
211
+ ]);
212
+ const value = {
213
+ app,
214
+ isConnected,
215
+ error,
216
+ hostContext,
217
+ toolInput,
218
+ toolInputPartial,
219
+ toolResult,
220
+ toolCancelled,
221
+ callTool,
222
+ sendMessage,
223
+ sendLog,
224
+ openLink,
225
+ requestDisplayMode
226
+ };
227
+ const theme = hostContext.theme ?? "light";
228
+ return /* @__PURE__ */ React26__default.createElement(McpAppContext.Provider, {
229
+ value
230
+ }, /* @__PURE__ */ React26__default.createElement("div", {
231
+ className: "lui-root",
232
+ "data-theme": theme
233
+ }, children));
234
+ }
235
+ __name(AppProvider, "AppProvider");
236
+ var ssrDefaultContext = {
237
+ app: null,
238
+ isConnected: false,
239
+ error: null,
240
+ hostContext: {},
241
+ toolInput: null,
242
+ toolInputPartial: null,
243
+ toolResult: null,
244
+ toolCancelled: {
245
+ cancelled: false
246
+ },
247
+ callTool: /* @__PURE__ */ __name(async () => {
248
+ throw new Error("callTool not available during SSR");
249
+ }, "callTool"),
250
+ sendMessage: /* @__PURE__ */ __name(async () => {
251
+ console.warn("sendMessage not available during SSR");
252
+ }, "sendMessage"),
253
+ sendLog: /* @__PURE__ */ __name(async () => {
254
+ console.warn("sendLog not available during SSR");
255
+ }, "sendLog"),
256
+ openLink: /* @__PURE__ */ __name(async () => {
257
+ console.warn("openLink not available during SSR");
258
+ }, "openLink"),
259
+ requestDisplayMode: /* @__PURE__ */ __name(async () => {
260
+ console.warn("requestDisplayMode not available during SSR");
261
+ return "inline";
262
+ }, "requestDisplayMode")
263
+ };
264
+ function useMcpApp() {
265
+ const context = useContext(McpAppContext);
266
+ if (!context) {
267
+ return ssrDefaultContext;
268
+ }
269
+ return context;
270
+ }
271
+ __name(useMcpApp, "useMcpApp");
272
+ var GptAppContext = /* @__PURE__ */ createContext(null);
273
+ function GPTAppProvider({ appName, children }) {
274
+ const [isConnected, setIsConnected] = useState(false);
275
+ const [error, setError] = useState(null);
276
+ const [theme, setTheme] = useState("light");
277
+ const [displayMode, setDisplayMode] = useState("inline");
278
+ const [locale, setLocale] = useState("en");
279
+ const [maxHeight, setMaxHeight] = useState(600);
280
+ useEffect(() => {
281
+ let mounted = true;
282
+ let checkAttempts = 0;
283
+ const maxAttempts = 50;
284
+ function checkConnection() {
285
+ if (!mounted) return;
286
+ if (window.openai) {
287
+ setIsConnected(true);
288
+ setError(null);
289
+ if (window.openai.theme) setTheme(window.openai.theme);
290
+ if (window.openai.displayMode) setDisplayMode(window.openai.displayMode);
291
+ if (window.openai.locale) setLocale(window.openai.locale);
292
+ if (window.openai.maxHeight) setMaxHeight(window.openai.maxHeight);
293
+ } else {
294
+ checkAttempts++;
295
+ if (checkAttempts < maxAttempts) {
296
+ setTimeout(checkConnection, 100);
297
+ } else {
298
+ setError(new Error("ChatGPT SDK not available"));
299
+ setIsConnected(false);
300
+ }
301
+ }
302
+ }
303
+ __name(checkConnection, "checkConnection");
304
+ checkConnection();
305
+ return () => {
306
+ mounted = false;
307
+ };
308
+ }, [
309
+ appName
310
+ ]);
311
+ const callTool = useCallback(async (name, args = {}) => {
312
+ if (!window.openai?.callTool) {
313
+ throw new Error("ChatGPT SDK not available");
314
+ }
315
+ const result = await window.openai.callTool(name, args);
316
+ return result;
317
+ }, []);
318
+ const value = {
319
+ isConnected,
320
+ error,
321
+ theme,
322
+ displayMode,
323
+ locale,
324
+ maxHeight,
325
+ callTool
326
+ };
327
+ return /* @__PURE__ */ React26__default.createElement(GptAppContext.Provider, {
328
+ value
329
+ }, /* @__PURE__ */ React26__default.createElement("div", {
330
+ className: "lui-root",
331
+ "data-theme": theme
332
+ }, children));
333
+ }
334
+ __name(GPTAppProvider, "GPTAppProvider");
335
+ function useGptApp() {
336
+ const context = useContext(GptAppContext);
337
+ if (!context) {
338
+ return {
339
+ isConnected: false,
340
+ error: new Error("GPTAppProvider not found"),
341
+ theme: "light",
342
+ displayMode: "inline",
343
+ locale: "en",
344
+ maxHeight: 600,
345
+ callTool: /* @__PURE__ */ __name(async () => {
346
+ throw new Error("Not connected to ChatGPT");
347
+ }, "callTool")
348
+ };
349
+ }
350
+ return context;
351
+ }
352
+ __name(useGptApp, "useGptApp");
353
+ function useGptTool(toolName) {
354
+ const { callTool, isConnected } = useGptApp();
355
+ const [result, setResult] = useState(null);
356
+ const [loading, setLoading] = useState(false);
357
+ const [error, setError] = useState(null);
358
+ const call = useCallback(async (args = {}) => {
359
+ if (!isConnected) {
360
+ setError(new Error("Not connected to ChatGPT"));
361
+ return;
362
+ }
363
+ setLoading(true);
364
+ setError(null);
365
+ try {
366
+ const res = await callTool(toolName, args);
367
+ setResult(res);
368
+ return res;
369
+ } catch (err) {
370
+ setError(err);
371
+ throw err;
372
+ } finally {
373
+ setLoading(false);
374
+ }
375
+ }, [
376
+ callTool,
377
+ isConnected,
378
+ toolName
379
+ ]);
380
+ return {
381
+ call,
382
+ result,
383
+ loading,
384
+ error,
385
+ isConnected
386
+ };
387
+ }
388
+ __name(useGptTool, "useGptTool");
389
+ var DEFAULT_CONTEXT = {
390
+ resultDisplay: {
391
+ display: "none"
392
+ },
393
+ showLoading: true
394
+ };
395
+ var ToolContext = /* @__PURE__ */ createContext(DEFAULT_CONTEXT);
396
+ function ToolProvider({ defaults = {}, children }) {
397
+ const parentContext = useContext(ToolContext);
398
+ const value = useMemo(() => ({
399
+ resultDisplay: defaults.resultDisplay ?? parentContext.resultDisplay,
400
+ onError: defaults.onError ?? parentContext.onError,
401
+ showLoading: defaults.showLoading ?? parentContext.showLoading
402
+ }), [
403
+ defaults,
404
+ parentContext
405
+ ]);
406
+ return /* @__PURE__ */ React26.createElement(ToolContext.Provider, {
407
+ value
408
+ }, children);
409
+ }
410
+ __name(ToolProvider, "ToolProvider");
411
+ function useToolContext() {
412
+ return useContext(ToolContext);
413
+ }
414
+ __name(useToolContext, "useToolContext");
415
+ var Toaster = /* @__PURE__ */ __name(({ ...props }) => {
416
+ const { theme = "system" } = useTheme();
417
+ return /* @__PURE__ */ React26__default.createElement(Toaster$1, {
418
+ theme,
419
+ className: "toaster group",
420
+ icons: {
421
+ success: /* @__PURE__ */ React26__default.createElement(CircleCheckIcon, {
422
+ className: "size-4"
423
+ }),
424
+ info: /* @__PURE__ */ React26__default.createElement(InfoIcon, {
425
+ className: "size-4"
426
+ }),
427
+ warning: /* @__PURE__ */ React26__default.createElement(TriangleAlertIcon, {
428
+ className: "size-4"
429
+ }),
430
+ error: /* @__PURE__ */ React26__default.createElement(OctagonXIcon, {
431
+ className: "size-4"
432
+ }),
433
+ loading: /* @__PURE__ */ React26__default.createElement(Loader2Icon, {
434
+ className: "size-4 animate-spin"
435
+ })
436
+ },
437
+ style: {
438
+ "--normal-bg": "var(--popover)",
439
+ "--normal-text": "var(--popover-foreground)",
440
+ "--normal-border": "var(--border)",
441
+ "--border-radius": "var(--radius)"
442
+ },
443
+ ...props
444
+ });
445
+ }, "Toaster");
446
+ function cn(...inputs) {
447
+ return twMerge(clsx(inputs));
448
+ }
449
+ __name(cn, "cn");
450
+
451
+ // src/components/ui/button.tsx
452
+ var buttonVariants = cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive", {
453
+ variants: {
454
+ variant: {
455
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
456
+ destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
457
+ outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
458
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
459
+ ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
460
+ link: "text-primary underline-offset-4 hover:underline"
461
+ },
462
+ size: {
463
+ default: "h-9 px-4 py-2 has-[>svg]:px-3",
464
+ sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
465
+ lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
466
+ icon: "size-9",
467
+ "icon-sm": "size-8",
468
+ "icon-lg": "size-10"
469
+ }
470
+ },
471
+ defaultVariants: {
472
+ variant: "default",
473
+ size: "default"
474
+ }
475
+ });
476
+ function Button({ className, variant = "default", size = "default", asChild = false, ...props }) {
477
+ const Comp = asChild ? Slot : "button";
478
+ return /* @__PURE__ */ React26.createElement(Comp, {
479
+ "data-slot": "button",
480
+ "data-variant": variant,
481
+ "data-size": size,
482
+ className: cn(buttonVariants({
483
+ variant,
484
+ size,
485
+ className
486
+ })),
487
+ ...props
488
+ });
489
+ }
490
+ __name(Button, "Button");
491
+ function Dialog({ ...props }) {
492
+ return /* @__PURE__ */ React26.createElement(DialogPrimitive.Root, {
493
+ "data-slot": "dialog",
494
+ ...props
495
+ });
496
+ }
497
+ __name(Dialog, "Dialog");
498
+ function DialogTrigger({ ...props }) {
499
+ return /* @__PURE__ */ React26.createElement(DialogPrimitive.Trigger, {
500
+ "data-slot": "dialog-trigger",
501
+ ...props
502
+ });
503
+ }
504
+ __name(DialogTrigger, "DialogTrigger");
505
+ function DialogPortal({ ...props }) {
506
+ return /* @__PURE__ */ React26.createElement(DialogPrimitive.Portal, {
507
+ "data-slot": "dialog-portal",
508
+ ...props
509
+ });
510
+ }
511
+ __name(DialogPortal, "DialogPortal");
512
+ function DialogClose({ ...props }) {
513
+ return /* @__PURE__ */ React26.createElement(DialogPrimitive.Close, {
514
+ "data-slot": "dialog-close",
515
+ ...props
516
+ });
517
+ }
518
+ __name(DialogClose, "DialogClose");
519
+ function DialogOverlay({ className, ...props }) {
520
+ return /* @__PURE__ */ React26.createElement(DialogPrimitive.Overlay, {
521
+ "data-slot": "dialog-overlay",
522
+ className: cn("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50", className),
523
+ ...props
524
+ });
525
+ }
526
+ __name(DialogOverlay, "DialogOverlay");
527
+ function DialogContent({ className, children, showCloseButton = true, ...props }) {
528
+ return /* @__PURE__ */ React26.createElement(DialogPortal, {
529
+ "data-slot": "dialog-portal"
530
+ }, /* @__PURE__ */ React26.createElement(DialogOverlay, null), /* @__PURE__ */ React26.createElement(DialogPrimitive.Content, {
531
+ "data-slot": "dialog-content",
532
+ className: cn("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 outline-none sm:max-w-lg", className),
533
+ ...props
534
+ }, children, showCloseButton && /* @__PURE__ */ React26.createElement(DialogPrimitive.Close, {
535
+ "data-slot": "dialog-close",
536
+ className: "ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
537
+ }, /* @__PURE__ */ React26.createElement(XIcon, null), /* @__PURE__ */ React26.createElement("span", {
538
+ className: "sr-only"
539
+ }, "Close"))));
540
+ }
541
+ __name(DialogContent, "DialogContent");
542
+ function DialogHeader({ className, ...props }) {
543
+ return /* @__PURE__ */ React26.createElement("div", {
544
+ "data-slot": "dialog-header",
545
+ className: cn("flex flex-col gap-2 text-center sm:text-left", className),
546
+ ...props
547
+ });
548
+ }
549
+ __name(DialogHeader, "DialogHeader");
550
+ function DialogFooter({ className, ...props }) {
551
+ return /* @__PURE__ */ React26.createElement("div", {
552
+ "data-slot": "dialog-footer",
553
+ className: cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", className),
554
+ ...props
555
+ });
556
+ }
557
+ __name(DialogFooter, "DialogFooter");
558
+ function DialogTitle({ className, ...props }) {
559
+ return /* @__PURE__ */ React26.createElement(DialogPrimitive.Title, {
560
+ "data-slot": "dialog-title",
561
+ className: cn("text-lg leading-none font-semibold", className),
562
+ ...props
563
+ });
564
+ }
565
+ __name(DialogTitle, "DialogTitle");
566
+ function DialogDescription({ className, ...props }) {
567
+ return /* @__PURE__ */ React26.createElement(DialogPrimitive.Description, {
568
+ "data-slot": "dialog-description",
569
+ className: cn("text-muted-foreground text-sm", className),
570
+ ...props
571
+ });
572
+ }
573
+ __name(DialogDescription, "DialogDescription");
574
+ function extractResultData(result) {
575
+ if ("structuredContent" in result && result.structuredContent) {
576
+ return result.structuredContent;
577
+ }
578
+ if (result.content && result.content.length > 0) {
579
+ const textContent = result.content.filter((c) => c.type === "text").map((c) => c.text).join("");
580
+ if (textContent) {
581
+ try {
582
+ const parsed = JSON.parse(textContent);
583
+ if (parsed && typeof parsed === "object" && "content" in parsed && Array.isArray(parsed.content)) {
584
+ const nested = extractResultData(parsed);
585
+ if (nested !== null) {
586
+ return nested;
587
+ }
588
+ }
589
+ return parsed;
590
+ } catch {
591
+ return textContent;
592
+ }
593
+ }
594
+ }
595
+ return result;
596
+ }
597
+ __name(extractResultData, "extractResultData");
598
+ function useTool(toolName, options = {}) {
599
+ const { callTool } = useMcpApp();
600
+ const [state, setState] = useState("idle");
601
+ const [result, setResult] = useState(null);
602
+ const [error, setError] = useState(null);
603
+ const abortControllerRef = useRef(null);
604
+ const lastArgsRef = useRef(void 0);
605
+ const retryCountRef = useRef(0);
606
+ const { defaultArgs, transform, retry, onStart, onSuccess, onError, onComplete } = options;
607
+ const retryConfig = typeof retry === "number" ? {
608
+ count: retry,
609
+ delay: 1e3
610
+ } : retry ?? {
611
+ count: 0,
612
+ delay: 1e3
613
+ };
614
+ const executeCall = useCallback(async (args) => {
615
+ const mergedArgs = {
616
+ ...defaultArgs,
617
+ ...args
618
+ };
619
+ lastArgsRef.current = mergedArgs;
620
+ abortControllerRef.current = new AbortController();
621
+ setState("loading");
622
+ setError(null);
623
+ onStart?.();
624
+ try {
625
+ const response = await callTool(toolName, mergedArgs);
626
+ if (abortControllerRef.current?.signal.aborted) {
627
+ throw new Error("Tool call aborted");
628
+ }
629
+ let data;
630
+ if (transform) {
631
+ data = transform(response);
632
+ } else {
633
+ data = extractResultData(response);
634
+ }
635
+ setState("success");
636
+ setResult(data);
637
+ retryCountRef.current = 0;
638
+ onSuccess?.(data);
639
+ onComplete?.();
640
+ return data;
641
+ } catch (err) {
642
+ const error2 = err instanceof Error ? err : new Error(String(err));
643
+ if (retryCountRef.current < retryConfig.count) {
644
+ retryCountRef.current++;
645
+ await new Promise((resolve) => setTimeout(resolve, retryConfig.delay));
646
+ return executeCall(args);
647
+ }
648
+ setState("error");
649
+ setError(error2);
650
+ retryCountRef.current = 0;
651
+ onError?.(error2);
652
+ onComplete?.();
653
+ throw error2;
654
+ }
655
+ }, [
656
+ callTool,
657
+ toolName,
658
+ defaultArgs,
659
+ transform,
660
+ retryConfig,
661
+ onStart,
662
+ onSuccess,
663
+ onError,
664
+ onComplete
665
+ ]);
666
+ const call = useCallback(async (args) => {
667
+ retryCountRef.current = 0;
668
+ return executeCall(args);
669
+ }, [
670
+ executeCall
671
+ ]);
672
+ const mutate = useCallback(async (args) => {
673
+ return call(args);
674
+ }, [
675
+ call
676
+ ]);
677
+ const reset = useCallback(() => {
678
+ setState("idle");
679
+ setResult(null);
680
+ setError(null);
681
+ retryCountRef.current = 0;
682
+ abortControllerRef.current?.abort();
683
+ }, []);
684
+ const retryCall = useCallback(async () => {
685
+ if (lastArgsRef.current === void 0 && !defaultArgs) {
686
+ return null;
687
+ }
688
+ retryCountRef.current = 0;
689
+ return executeCall(lastArgsRef.current);
690
+ }, [
691
+ executeCall,
692
+ defaultArgs
693
+ ]);
694
+ const abort = useCallback(() => {
695
+ abortControllerRef.current?.abort();
696
+ setState("idle");
697
+ }, []);
698
+ return {
699
+ call,
700
+ mutate,
701
+ state,
702
+ loading: state === "loading",
703
+ result,
704
+ error,
705
+ reset,
706
+ retry: retryCall,
707
+ abort
708
+ };
709
+ }
710
+ __name(useTool, "useTool");
711
+ function ToolButton({ tool, args = {}, resultDisplay = "none", renderResult, resultDuration = 3e3, successMessage, errorMessage, onToolStart, onToolSuccess, onToolError, onToolComplete, loadingText, loadingIcon, disableWhileLoading = true, confirm, children, className, variant = "default", size = "default", disabled, asChild = false, ...props }) {
712
+ const toolConfig = typeof tool === "string" ? {
713
+ name: tool
714
+ } : tool;
715
+ const mergedArgs = {
716
+ ...toolConfig.args,
717
+ ...args
718
+ };
719
+ const { call, state, loading, result, error, reset } = useTool(toolConfig.name, {
720
+ defaultArgs: mergedArgs,
721
+ transform: toolConfig.transform,
722
+ onStart: onToolStart,
723
+ onSuccess: onToolSuccess,
724
+ onError: onToolError,
725
+ onComplete: onToolComplete
726
+ });
727
+ const [showConfirm, setShowConfirm] = useState(false);
728
+ const [showResult, setShowResult] = useState(false);
729
+ const buttonState = {
730
+ loading,
731
+ state,
732
+ result,
733
+ error,
734
+ hasResult: result !== null || error !== null
735
+ };
736
+ const executeCall = useCallback(async () => {
737
+ try {
738
+ const res = await call();
739
+ if (resultDisplay === "toast") {
740
+ const message = typeof successMessage === "function" ? successMessage(res) : successMessage ?? "Success";
741
+ toast.success(message);
742
+ } else if (resultDisplay === "inline") {
743
+ setShowResult(true);
744
+ setTimeout(() => setShowResult(false), resultDuration);
745
+ }
746
+ } catch (err) {
747
+ if (resultDisplay === "toast") {
748
+ const message = typeof errorMessage === "function" ? errorMessage(err instanceof Error ? err : new Error(String(err))) : errorMessage ?? (err instanceof Error ? err.message : "An error occurred");
749
+ toast.error(message);
750
+ } else if (resultDisplay === "inline") {
751
+ setShowResult(true);
752
+ setTimeout(() => setShowResult(false), resultDuration);
753
+ }
754
+ }
755
+ }, [
756
+ call,
757
+ resultDisplay,
758
+ successMessage,
759
+ errorMessage,
760
+ resultDuration
761
+ ]);
762
+ const handleClick = useCallback(() => {
763
+ if (confirm) {
764
+ setShowConfirm(true);
765
+ } else {
766
+ executeCall();
767
+ }
768
+ }, [
769
+ confirm,
770
+ executeCall
771
+ ]);
772
+ const handleConfirm = useCallback(() => {
773
+ setShowConfirm(false);
774
+ executeCall();
775
+ }, [
776
+ executeCall
777
+ ]);
778
+ const confirmConfig = typeof confirm === "object" ? confirm : {
779
+ title: "Confirm Action",
780
+ description: "Are you sure you want to proceed?",
781
+ confirmText: "Confirm",
782
+ cancelText: "Cancel"
783
+ };
784
+ const renderChildren = /* @__PURE__ */ __name(() => {
785
+ if (typeof children === "function") {
786
+ return children(buttonState);
787
+ }
788
+ if (loading) {
789
+ return /* @__PURE__ */ React26.createElement(React26.Fragment, null, loadingIcon ?? /* @__PURE__ */ React26.createElement(Loader2, {
790
+ className: "animate-spin"
791
+ }), loadingText && /* @__PURE__ */ React26.createElement("span", null, loadingText), !loadingText && children);
792
+ }
793
+ if (showResult && resultDisplay === "inline") {
794
+ if (error) {
795
+ return /* @__PURE__ */ React26.createElement(React26.Fragment, null, /* @__PURE__ */ React26.createElement(X, {
796
+ className: "text-destructive"
797
+ }), /* @__PURE__ */ React26.createElement("span", null, error.message));
798
+ }
799
+ if (renderResult) {
800
+ return renderResult(result);
801
+ }
802
+ return /* @__PURE__ */ React26.createElement(React26.Fragment, null, /* @__PURE__ */ React26.createElement(Check, {
803
+ className: "text-success"
804
+ }), /* @__PURE__ */ React26.createElement("span", null, "Done"));
805
+ }
806
+ return children;
807
+ }, "renderChildren");
808
+ return /* @__PURE__ */ React26.createElement(React26.Fragment, null, /* @__PURE__ */ React26.createElement(Button, {
809
+ type: "button",
810
+ variant,
811
+ size,
812
+ className: cn(className),
813
+ disabled: disabled || disableWhileLoading && loading,
814
+ onClick: handleClick,
815
+ asChild,
816
+ ...props
817
+ }, renderChildren()), confirm && /* @__PURE__ */ React26.createElement(Dialog, {
818
+ open: showConfirm,
819
+ onOpenChange: setShowConfirm
820
+ }, /* @__PURE__ */ React26.createElement(DialogContent, null, /* @__PURE__ */ React26.createElement(DialogHeader, null, /* @__PURE__ */ React26.createElement(DialogTitle, null, confirmConfig.title), confirmConfig.description && /* @__PURE__ */ React26.createElement(DialogDescription, null, confirmConfig.description)), /* @__PURE__ */ React26.createElement(DialogFooter, null, /* @__PURE__ */ React26.createElement(Button, {
821
+ variant: "outline",
822
+ onClick: /* @__PURE__ */ __name(() => setShowConfirm(false), "onClick")
823
+ }, confirmConfig.cancelText ?? "Cancel"), /* @__PURE__ */ React26.createElement(Button, {
824
+ variant: confirmConfig.confirmVariant ?? (variant === "destructive" ? "destructive" : "default"),
825
+ onClick: handleConfirm
826
+ }, confirmConfig.confirmText ?? "Confirm")))));
827
+ }
828
+ __name(ToolButton, "ToolButton");
829
+ function Select({ ...props }) {
830
+ return /* @__PURE__ */ React26.createElement(SelectPrimitive.Root, {
831
+ "data-slot": "select",
832
+ ...props
833
+ });
834
+ }
835
+ __name(Select, "Select");
836
+ function SelectGroup({ ...props }) {
837
+ return /* @__PURE__ */ React26.createElement(SelectPrimitive.Group, {
838
+ "data-slot": "select-group",
839
+ ...props
840
+ });
841
+ }
842
+ __name(SelectGroup, "SelectGroup");
843
+ function SelectValue({ ...props }) {
844
+ return /* @__PURE__ */ React26.createElement(SelectPrimitive.Value, {
845
+ "data-slot": "select-value",
846
+ ...props
847
+ });
848
+ }
849
+ __name(SelectValue, "SelectValue");
850
+ function SelectTrigger({ className, size = "default", children, ...props }) {
851
+ return /* @__PURE__ */ React26.createElement(SelectPrimitive.Trigger, {
852
+ "data-slot": "select-trigger",
853
+ "data-size": size,
854
+ className: cn("border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className),
855
+ ...props
856
+ }, children, /* @__PURE__ */ React26.createElement(SelectPrimitive.Icon, {
857
+ asChild: true
858
+ }, /* @__PURE__ */ React26.createElement(ChevronDownIcon, {
859
+ className: "size-4 opacity-50"
860
+ })));
861
+ }
862
+ __name(SelectTrigger, "SelectTrigger");
863
+ function SelectContent({ className, children, position = "item-aligned", align = "center", ...props }) {
864
+ return /* @__PURE__ */ React26.createElement(SelectPrimitive.Portal, null, /* @__PURE__ */ React26.createElement(SelectPrimitive.Content, {
865
+ "data-slot": "select-content",
866
+ className: cn("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md", position === "popper" && "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1", className),
867
+ position,
868
+ align,
869
+ ...props
870
+ }, /* @__PURE__ */ React26.createElement(SelectScrollUpButton, null), /* @__PURE__ */ React26.createElement(SelectPrimitive.Viewport, {
871
+ className: cn("p-1", position === "popper" && "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1")
872
+ }, children), /* @__PURE__ */ React26.createElement(SelectScrollDownButton, null)));
873
+ }
874
+ __name(SelectContent, "SelectContent");
875
+ function SelectLabel({ className, ...props }) {
876
+ return /* @__PURE__ */ React26.createElement(SelectPrimitive.Label, {
877
+ "data-slot": "select-label",
878
+ className: cn("text-muted-foreground px-2 py-1.5 text-xs", className),
879
+ ...props
880
+ });
881
+ }
882
+ __name(SelectLabel, "SelectLabel");
883
+ function SelectItem({ className, children, ...props }) {
884
+ return /* @__PURE__ */ React26.createElement(SelectPrimitive.Item, {
885
+ "data-slot": "select-item",
886
+ className: cn("focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2", className),
887
+ ...props
888
+ }, /* @__PURE__ */ React26.createElement("span", {
889
+ "data-slot": "select-item-indicator",
890
+ className: "absolute right-2 flex size-3.5 items-center justify-center"
891
+ }, /* @__PURE__ */ React26.createElement(SelectPrimitive.ItemIndicator, null, /* @__PURE__ */ React26.createElement(CheckIcon, {
892
+ className: "size-4"
893
+ }))), /* @__PURE__ */ React26.createElement(SelectPrimitive.ItemText, null, children));
894
+ }
895
+ __name(SelectItem, "SelectItem");
896
+ function SelectSeparator({ className, ...props }) {
897
+ return /* @__PURE__ */ React26.createElement(SelectPrimitive.Separator, {
898
+ "data-slot": "select-separator",
899
+ className: cn("bg-border pointer-events-none -mx-1 my-1 h-px", className),
900
+ ...props
901
+ });
902
+ }
903
+ __name(SelectSeparator, "SelectSeparator");
904
+ function SelectScrollUpButton({ className, ...props }) {
905
+ return /* @__PURE__ */ React26.createElement(SelectPrimitive.ScrollUpButton, {
906
+ "data-slot": "select-scroll-up-button",
907
+ className: cn("flex cursor-default items-center justify-center py-1", className),
908
+ ...props
909
+ }, /* @__PURE__ */ React26.createElement(ChevronUpIcon, {
910
+ className: "size-4"
911
+ }));
912
+ }
913
+ __name(SelectScrollUpButton, "SelectScrollUpButton");
914
+ function SelectScrollDownButton({ className, ...props }) {
915
+ return /* @__PURE__ */ React26.createElement(SelectPrimitive.ScrollDownButton, {
916
+ "data-slot": "select-scroll-down-button",
917
+ className: cn("flex cursor-default items-center justify-center py-1", className),
918
+ ...props
919
+ }, /* @__PURE__ */ React26.createElement(ChevronDownIcon, {
920
+ className: "size-4"
921
+ }));
922
+ }
923
+ __name(SelectScrollDownButton, "SelectScrollDownButton");
924
+ function ToolSelect({ onSelectTool, argName = "value", additionalArgs = {}, optionsTool, optionsArgs = {}, transformOptions, options: staticOptions = [], placeholder = "Select an option", loadingPlaceholder = "Loading...", emptyMessage = "No options available", value: controlledValue, defaultValue, onValueChange, onOptionsLoaded, onSelectionSuccess, onSelectionError, showSuccessToast = false, successMessage, className, disabled = false }) {
925
+ const [fetchedOptions, setFetchedOptions] = useState([]);
926
+ const [internalValue, setInternalValue] = useState(defaultValue ?? "");
927
+ const optionsToolConfig = optionsTool ? typeof optionsTool === "string" ? {
928
+ name: optionsTool
929
+ } : optionsTool : null;
930
+ const selectToolConfig = onSelectTool ? typeof onSelectTool === "string" ? {
931
+ name: onSelectTool
932
+ } : onSelectTool : null;
933
+ const optionsHook = useTool(optionsToolConfig?.name ?? "", {
934
+ defaultArgs: {
935
+ ...optionsToolConfig?.args,
936
+ ...optionsArgs
937
+ }
938
+ });
939
+ const selectHook = useTool(selectToolConfig?.name ?? "", {
940
+ onSuccess: /* @__PURE__ */ __name((result) => {
941
+ onSelectionSuccess?.(result);
942
+ if (showSuccessToast) {
943
+ const message = typeof successMessage === "function" ? successMessage(result) : successMessage ?? "Selection saved";
944
+ toast.success(message);
945
+ }
946
+ }, "onSuccess"),
947
+ onError: onSelectionError
948
+ });
949
+ useEffect(() => {
950
+ if (optionsToolConfig) {
951
+ optionsHook.call().then((result) => {
952
+ const options = transformOptions ? transformOptions(result) : result;
953
+ setFetchedOptions(options);
954
+ onOptionsLoaded?.(options);
955
+ }).catch(() => {
956
+ });
957
+ }
958
+ }, [
959
+ optionsToolConfig?.name
960
+ ]);
961
+ const allOptions = [
962
+ ...staticOptions,
963
+ ...fetchedOptions
964
+ ];
965
+ const value = controlledValue ?? internalValue;
966
+ const handleValueChange = useCallback((newValue) => {
967
+ setInternalValue(newValue);
968
+ onValueChange?.(newValue);
969
+ if (selectToolConfig) {
970
+ selectHook.call({
971
+ [argName]: newValue,
972
+ ...additionalArgs
973
+ });
974
+ }
975
+ }, [
976
+ onValueChange,
977
+ selectToolConfig,
978
+ argName,
979
+ additionalArgs,
980
+ selectHook
981
+ ]);
982
+ const isLoading = optionsHook.loading || selectHook.loading;
983
+ const hasError = optionsHook.error || selectHook.error;
984
+ return /* @__PURE__ */ React26.createElement(Select, {
985
+ value,
986
+ onValueChange: handleValueChange,
987
+ disabled: disabled || isLoading
988
+ }, /* @__PURE__ */ React26.createElement(SelectTrigger, {
989
+ className: cn("w-full", className)
990
+ }, isLoading ? /* @__PURE__ */ React26.createElement("div", {
991
+ className: "flex items-center gap-2"
992
+ }, /* @__PURE__ */ React26.createElement(Loader2, {
993
+ className: "h-4 w-4 animate-spin"
994
+ }), /* @__PURE__ */ React26.createElement("span", {
995
+ className: "text-muted-foreground"
996
+ }, optionsHook.loading ? loadingPlaceholder : "Saving...")) : /* @__PURE__ */ React26.createElement(SelectValue, {
997
+ placeholder
998
+ })), /* @__PURE__ */ React26.createElement(SelectContent, null, allOptions.length === 0 ? /* @__PURE__ */ React26.createElement("div", {
999
+ className: "py-6 text-center text-sm text-muted-foreground"
1000
+ }, hasError ? "Error loading options" : emptyMessage) : allOptions.map((option) => /* @__PURE__ */ React26.createElement(SelectItem, {
1001
+ key: option.value,
1002
+ value: option.value,
1003
+ disabled: option.disabled
1004
+ }, /* @__PURE__ */ React26.createElement("div", {
1005
+ className: "flex items-center gap-2"
1006
+ }, option.icon, /* @__PURE__ */ React26.createElement("div", null, /* @__PURE__ */ React26.createElement("div", null, option.label), option.description && /* @__PURE__ */ React26.createElement("div", {
1007
+ className: "text-xs text-muted-foreground"
1008
+ }, option.description)))))));
1009
+ }
1010
+ __name(ToolSelect, "ToolSelect");
1011
+ function Input({ className, type, ...props }) {
1012
+ return /* @__PURE__ */ React26.createElement("input", {
1013
+ type,
1014
+ "data-slot": "input",
1015
+ className: cn("file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm", "focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]", "aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive", className),
1016
+ ...props
1017
+ });
1018
+ }
1019
+ __name(Input, "Input");
1020
+ function Command({ className, ...props }) {
1021
+ return /* @__PURE__ */ React26.createElement(Command$1, {
1022
+ "data-slot": "command",
1023
+ className: cn("bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md", className),
1024
+ ...props
1025
+ });
1026
+ }
1027
+ __name(Command, "Command");
1028
+ function CommandDialog({ title = "Command Palette", description = "Search for a command to run...", children, className, showCloseButton = true, ...props }) {
1029
+ return /* @__PURE__ */ React26.createElement(Dialog, props, /* @__PURE__ */ React26.createElement(DialogHeader, {
1030
+ className: "sr-only"
1031
+ }, /* @__PURE__ */ React26.createElement(DialogTitle, null, title), /* @__PURE__ */ React26.createElement(DialogDescription, null, description)), /* @__PURE__ */ React26.createElement(DialogContent, {
1032
+ className: cn("overflow-hidden p-0", className),
1033
+ showCloseButton
1034
+ }, /* @__PURE__ */ React26.createElement(Command, {
1035
+ className: "[&_[cmdk-group-heading]]:text-muted-foreground **:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5"
1036
+ }, children)));
1037
+ }
1038
+ __name(CommandDialog, "CommandDialog");
1039
+ function CommandInput({ className, ...props }) {
1040
+ return /* @__PURE__ */ React26.createElement("div", {
1041
+ "data-slot": "command-input-wrapper",
1042
+ className: "flex h-9 items-center gap-2 border-b px-3"
1043
+ }, /* @__PURE__ */ React26.createElement(SearchIcon, {
1044
+ className: "size-4 shrink-0 opacity-50"
1045
+ }), /* @__PURE__ */ React26.createElement(Command$1.Input, {
1046
+ "data-slot": "command-input",
1047
+ className: cn("placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50", className),
1048
+ ...props
1049
+ }));
1050
+ }
1051
+ __name(CommandInput, "CommandInput");
1052
+ function CommandList({ className, ...props }) {
1053
+ return /* @__PURE__ */ React26.createElement(Command$1.List, {
1054
+ "data-slot": "command-list",
1055
+ className: cn("max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto", className),
1056
+ ...props
1057
+ });
1058
+ }
1059
+ __name(CommandList, "CommandList");
1060
+ function CommandEmpty({ ...props }) {
1061
+ return /* @__PURE__ */ React26.createElement(Command$1.Empty, {
1062
+ "data-slot": "command-empty",
1063
+ className: "py-6 text-center text-sm",
1064
+ ...props
1065
+ });
1066
+ }
1067
+ __name(CommandEmpty, "CommandEmpty");
1068
+ function CommandGroup({ className, ...props }) {
1069
+ return /* @__PURE__ */ React26.createElement(Command$1.Group, {
1070
+ "data-slot": "command-group",
1071
+ className: cn("text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium", className),
1072
+ ...props
1073
+ });
1074
+ }
1075
+ __name(CommandGroup, "CommandGroup");
1076
+ function CommandSeparator({ className, ...props }) {
1077
+ return /* @__PURE__ */ React26.createElement(Command$1.Separator, {
1078
+ "data-slot": "command-separator",
1079
+ className: cn("bg-border -mx-1 h-px", className),
1080
+ ...props
1081
+ });
1082
+ }
1083
+ __name(CommandSeparator, "CommandSeparator");
1084
+ function CommandItem({ className, ...props }) {
1085
+ return /* @__PURE__ */ React26.createElement(Command$1.Item, {
1086
+ "data-slot": "command-item",
1087
+ className: cn("data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className),
1088
+ ...props
1089
+ });
1090
+ }
1091
+ __name(CommandItem, "CommandItem");
1092
+ function CommandShortcut({ className, ...props }) {
1093
+ return /* @__PURE__ */ React26.createElement("span", {
1094
+ "data-slot": "command-shortcut",
1095
+ className: cn("text-muted-foreground ml-auto text-xs tracking-widest", className),
1096
+ ...props
1097
+ });
1098
+ }
1099
+ __name(CommandShortcut, "CommandShortcut");
1100
+ function Popover({ ...props }) {
1101
+ return /* @__PURE__ */ React26.createElement(PopoverPrimitive.Root, {
1102
+ "data-slot": "popover",
1103
+ ...props
1104
+ });
1105
+ }
1106
+ __name(Popover, "Popover");
1107
+ function PopoverTrigger({ ...props }) {
1108
+ return /* @__PURE__ */ React26.createElement(PopoverPrimitive.Trigger, {
1109
+ "data-slot": "popover-trigger",
1110
+ ...props
1111
+ });
1112
+ }
1113
+ __name(PopoverTrigger, "PopoverTrigger");
1114
+ function PopoverContent({ className, align = "center", sideOffset = 4, ...props }) {
1115
+ return /* @__PURE__ */ React26.createElement(PopoverPrimitive.Portal, null, /* @__PURE__ */ React26.createElement(PopoverPrimitive.Content, {
1116
+ "data-slot": "popover-content",
1117
+ align,
1118
+ sideOffset,
1119
+ className: cn("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden", className),
1120
+ ...props
1121
+ }));
1122
+ }
1123
+ __name(PopoverContent, "PopoverContent");
1124
+ function PopoverAnchor({ ...props }) {
1125
+ return /* @__PURE__ */ React26.createElement(PopoverPrimitive.Anchor, {
1126
+ "data-slot": "popover-anchor",
1127
+ ...props
1128
+ });
1129
+ }
1130
+ __name(PopoverAnchor, "PopoverAnchor");
1131
+
1132
+ // src/mcp/ToolInput.tsx
1133
+ function ToolInput({ searchTool, debounce = 300, minChars = 1, argName = "query", additionalArgs = {}, autocomplete = false, transformSuggestions, onSuggestionSelect, emptyMessage = "No results found", value: controlledValue, onChange, onSearchResults, onSearchError, showSearchIcon = true, showClearButton = true, showLoadingIndicator = true, className, placeholder = "Search...", disabled, ...props }) {
1134
+ const [internalValue, setInternalValue] = useState("");
1135
+ const [suggestions, setSuggestions] = useState([]);
1136
+ const [isOpen, setIsOpen] = useState(false);
1137
+ const debounceRef = useRef(null);
1138
+ const inputRef = useRef(null);
1139
+ const toolConfig = searchTool ? typeof searchTool === "string" ? {
1140
+ name: searchTool
1141
+ } : searchTool : null;
1142
+ const { call, loading, error, reset } = useTool(toolConfig?.name ?? "", {
1143
+ defaultArgs: {
1144
+ ...toolConfig?.args,
1145
+ ...additionalArgs
1146
+ },
1147
+ onSuccess: /* @__PURE__ */ __name((result) => {
1148
+ onSearchResults?.(result);
1149
+ if (autocomplete && transformSuggestions) {
1150
+ const suggestions2 = transformSuggestions(result);
1151
+ setSuggestions(suggestions2);
1152
+ if (suggestions2.length > 0) {
1153
+ setIsOpen(true);
1154
+ }
1155
+ }
1156
+ }, "onSuccess"),
1157
+ onError: onSearchError
1158
+ });
1159
+ const value = controlledValue ?? internalValue;
1160
+ const handleChange = useCallback((e) => {
1161
+ const newValue = e.target.value;
1162
+ setInternalValue(newValue);
1163
+ onChange?.(newValue);
1164
+ if (debounceRef.current) {
1165
+ clearTimeout(debounceRef.current);
1166
+ }
1167
+ if (newValue.length < minChars) {
1168
+ setSuggestions([]);
1169
+ setIsOpen(false);
1170
+ return;
1171
+ }
1172
+ if (toolConfig) {
1173
+ debounceRef.current = setTimeout(() => {
1174
+ call({
1175
+ [argName]: newValue
1176
+ });
1177
+ }, debounce);
1178
+ }
1179
+ }, [
1180
+ onChange,
1181
+ minChars,
1182
+ toolConfig,
1183
+ argName,
1184
+ debounce,
1185
+ call
1186
+ ]);
1187
+ const handleClear = useCallback(() => {
1188
+ setInternalValue("");
1189
+ onChange?.("");
1190
+ setSuggestions([]);
1191
+ setIsOpen(false);
1192
+ reset();
1193
+ inputRef.current?.focus();
1194
+ }, [
1195
+ onChange,
1196
+ reset
1197
+ ]);
1198
+ const handleSelect = useCallback((suggestion) => {
1199
+ setInternalValue(suggestion.label);
1200
+ onChange?.(suggestion.label);
1201
+ setIsOpen(false);
1202
+ onSuggestionSelect?.(suggestion);
1203
+ }, [
1204
+ onChange,
1205
+ onSuggestionSelect
1206
+ ]);
1207
+ useEffect(() => {
1208
+ return () => {
1209
+ if (debounceRef.current) {
1210
+ clearTimeout(debounceRef.current);
1211
+ }
1212
+ };
1213
+ }, []);
1214
+ const inputElement = /* @__PURE__ */ React26.createElement("div", {
1215
+ className: cn("relative", className)
1216
+ }, showSearchIcon && /* @__PURE__ */ React26.createElement(Search, {
1217
+ className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"
1218
+ }), /* @__PURE__ */ React26.createElement(Input, {
1219
+ ref: inputRef,
1220
+ value,
1221
+ onChange: handleChange,
1222
+ placeholder,
1223
+ disabled,
1224
+ className: cn(showSearchIcon && "pl-9", (showClearButton || showLoadingIndicator) && "pr-9"),
1225
+ ...props
1226
+ }), /* @__PURE__ */ React26.createElement("div", {
1227
+ className: "absolute right-3 top-1/2 -translate-y-1/2 flex items-center gap-1"
1228
+ }, showLoadingIndicator && loading && /* @__PURE__ */ React26.createElement(Loader2, {
1229
+ className: "h-4 w-4 animate-spin text-muted-foreground"
1230
+ }), showClearButton && value && !loading && /* @__PURE__ */ React26.createElement("button", {
1231
+ type: "button",
1232
+ onClick: handleClear,
1233
+ className: "h-4 w-4 text-muted-foreground hover:text-foreground transition-colors"
1234
+ }, /* @__PURE__ */ React26.createElement(X, {
1235
+ className: "h-4 w-4"
1236
+ }))));
1237
+ if (!autocomplete) {
1238
+ return inputElement;
1239
+ }
1240
+ return /* @__PURE__ */ React26.createElement(Popover, {
1241
+ open: isOpen,
1242
+ onOpenChange: setIsOpen
1243
+ }, /* @__PURE__ */ React26.createElement(PopoverTrigger, {
1244
+ asChild: true
1245
+ }, inputElement), /* @__PURE__ */ React26.createElement(PopoverContent, {
1246
+ className: "p-0 w-[var(--radix-popover-trigger-width)]",
1247
+ align: "start",
1248
+ onOpenAutoFocus: /* @__PURE__ */ __name((e) => e.preventDefault(), "onOpenAutoFocus")
1249
+ }, /* @__PURE__ */ React26.createElement(Command, null, /* @__PURE__ */ React26.createElement(CommandList, null, /* @__PURE__ */ React26.createElement(CommandEmpty, null, emptyMessage), /* @__PURE__ */ React26.createElement(CommandGroup, null, suggestions.map((suggestion) => /* @__PURE__ */ React26.createElement(CommandItem, {
1250
+ key: suggestion.value,
1251
+ value: suggestion.value,
1252
+ onSelect: /* @__PURE__ */ __name(() => handleSelect(suggestion), "onSelect")
1253
+ }, /* @__PURE__ */ React26.createElement("div", {
1254
+ className: "flex items-center gap-2"
1255
+ }, suggestion.icon, /* @__PURE__ */ React26.createElement("div", null, /* @__PURE__ */ React26.createElement("div", null, suggestion.label), suggestion.description && /* @__PURE__ */ React26.createElement("div", {
1256
+ className: "text-xs text-muted-foreground"
1257
+ }, suggestion.description))))))))));
1258
+ }
1259
+ __name(ToolInput, "ToolInput");
1260
+ function Label2({ className, ...props }) {
1261
+ return /* @__PURE__ */ React26.createElement(LabelPrimitive.Root, {
1262
+ "data-slot": "label",
1263
+ className: cn("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50", className),
1264
+ ...props
1265
+ });
1266
+ }
1267
+ __name(Label2, "Label");
1268
+ function Textarea({ className, ...props }) {
1269
+ return /* @__PURE__ */ React26.createElement("textarea", {
1270
+ "data-slot": "textarea",
1271
+ className: cn("border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm", className),
1272
+ ...props
1273
+ });
1274
+ }
1275
+ __name(Textarea, "Textarea");
1276
+ function Checkbox({ className, ...props }) {
1277
+ return /* @__PURE__ */ React26.createElement(CheckboxPrimitive.Root, {
1278
+ "data-slot": "checkbox",
1279
+ className: cn("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50", className),
1280
+ ...props
1281
+ }, /* @__PURE__ */ React26.createElement(CheckboxPrimitive.Indicator, {
1282
+ "data-slot": "checkbox-indicator",
1283
+ className: "grid place-content-center text-current transition-none"
1284
+ }, /* @__PURE__ */ React26.createElement(CheckIcon, {
1285
+ className: "size-3.5"
1286
+ })));
1287
+ }
1288
+ __name(Checkbox, "Checkbox");
1289
+ function Slider({ className, defaultValue, value, min = 0, max = 100, ...props }) {
1290
+ const _values = React26.useMemo(() => Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [
1291
+ min,
1292
+ max
1293
+ ], [
1294
+ value,
1295
+ defaultValue,
1296
+ min,
1297
+ max
1298
+ ]);
1299
+ return /* @__PURE__ */ React26.createElement(SliderPrimitive.Root, {
1300
+ "data-slot": "slider",
1301
+ defaultValue,
1302
+ value,
1303
+ min,
1304
+ max,
1305
+ className: cn("relative flex w-full touch-none items-center select-none data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col", className),
1306
+ ...props
1307
+ }, /* @__PURE__ */ React26.createElement(SliderPrimitive.Track, {
1308
+ "data-slot": "slider-track",
1309
+ className: cn("bg-muted relative grow overflow-hidden rounded-full data-[orientation=horizontal]:h-1.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5")
1310
+ }, /* @__PURE__ */ React26.createElement(SliderPrimitive.Range, {
1311
+ "data-slot": "slider-range",
1312
+ className: cn("bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full")
1313
+ })), Array.from({
1314
+ length: _values.length
1315
+ }, (_, index) => /* @__PURE__ */ React26.createElement(SliderPrimitive.Thumb, {
1316
+ "data-slot": "slider-thumb",
1317
+ key: index,
1318
+ className: "border-primary ring-ring/50 block size-4 shrink-0 rounded-full border bg-white shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"
1319
+ })));
1320
+ }
1321
+ __name(Slider, "Slider");
1322
+ function Switch({ className, ...props }) {
1323
+ return /* @__PURE__ */ React26.createElement(SwitchPrimitive.Root, {
1324
+ "data-slot": "switch",
1325
+ className: cn("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50", className),
1326
+ ...props
1327
+ }, /* @__PURE__ */ React26.createElement(SwitchPrimitive.Thumb, {
1328
+ "data-slot": "switch-thumb",
1329
+ className: cn("bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0")
1330
+ }));
1331
+ }
1332
+ __name(Switch, "Switch");
1333
+ var alertVariants = cva("relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current", {
1334
+ variants: {
1335
+ variant: {
1336
+ default: "bg-card text-card-foreground",
1337
+ destructive: "text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90"
1338
+ }
1339
+ },
1340
+ defaultVariants: {
1341
+ variant: "default"
1342
+ }
1343
+ });
1344
+ function Alert({ className, variant, ...props }) {
1345
+ return /* @__PURE__ */ React26.createElement("div", {
1346
+ "data-slot": "alert",
1347
+ role: "alert",
1348
+ className: cn(alertVariants({
1349
+ variant
1350
+ }), className),
1351
+ ...props
1352
+ });
1353
+ }
1354
+ __name(Alert, "Alert");
1355
+ function AlertTitle({ className, ...props }) {
1356
+ return /* @__PURE__ */ React26.createElement("div", {
1357
+ "data-slot": "alert-title",
1358
+ className: cn("col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight", className),
1359
+ ...props
1360
+ });
1361
+ }
1362
+ __name(AlertTitle, "AlertTitle");
1363
+ function AlertDescription({ className, ...props }) {
1364
+ return /* @__PURE__ */ React26.createElement("div", {
1365
+ "data-slot": "alert-description",
1366
+ className: cn("text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed", className),
1367
+ ...props
1368
+ });
1369
+ }
1370
+ __name(AlertDescription, "AlertDescription");
1371
+ function ToolForm({ toolName, fields: manualFields, autoSchema = false, submitText = "Submit", loadingText, onSuccess, onError, showResult = false, showSuccessToast = false, successMessage, resetOnSuccess = false, className, layout = "vertical" }) {
1372
+ const { app, isConnected } = useMcpApp();
1373
+ const { call, loading, result, error, reset } = useTool(toolName, {
1374
+ onSuccess: /* @__PURE__ */ __name((result2) => {
1375
+ onSuccess?.(result2);
1376
+ if (showSuccessToast) {
1377
+ const message = typeof successMessage === "function" ? successMessage(result2) : successMessage ?? "Form submitted successfully";
1378
+ toast.success(message);
1379
+ }
1380
+ if (resetOnSuccess) {
1381
+ resetForm();
1382
+ }
1383
+ }, "onSuccess"),
1384
+ onError
1385
+ });
1386
+ const [fields, setFields] = useState(manualFields ?? []);
1387
+ const [schemaLoading, setSchemaLoading] = useState(autoSchema);
1388
+ const [formData, setFormData] = useState({});
1389
+ const initializeFormData = /* @__PURE__ */ __name((fields2) => {
1390
+ const initial = {};
1391
+ fields2.forEach((field) => {
1392
+ if (field.defaultValue !== void 0) {
1393
+ initial[field.name] = field.defaultValue;
1394
+ } else if (field.type === "checkbox" || field.type === "switch") {
1395
+ initial[field.name] = false;
1396
+ } else if (field.type === "number" || field.type === "slider") {
1397
+ initial[field.name] = field.min ?? 0;
1398
+ } else {
1399
+ initial[field.name] = "";
1400
+ }
1401
+ });
1402
+ setFormData(initial);
1403
+ }, "initializeFormData");
1404
+ const resetForm = /* @__PURE__ */ __name(() => {
1405
+ initializeFormData(fields);
1406
+ reset();
1407
+ }, "resetForm");
1408
+ useEffect(() => {
1409
+ if (autoSchema && app && isConnected) {
1410
+ setSchemaLoading(true);
1411
+ const fetchSchema = /* @__PURE__ */ __name(async () => {
1412
+ try {
1413
+ console.warn("[ToolForm] Auto-schema not fully implemented, use manual fields");
1414
+ if (manualFields) {
1415
+ setFields(manualFields);
1416
+ initializeFormData(manualFields);
1417
+ }
1418
+ } catch (err) {
1419
+ console.error("[ToolForm] Failed to fetch schema:", err);
1420
+ } finally {
1421
+ setSchemaLoading(false);
1422
+ }
1423
+ }, "fetchSchema");
1424
+ fetchSchema();
1425
+ } else if (manualFields) {
1426
+ setFields(manualFields);
1427
+ initializeFormData(manualFields);
1428
+ }
1429
+ }, [
1430
+ autoSchema,
1431
+ app,
1432
+ isConnected,
1433
+ manualFields,
1434
+ toolName
1435
+ ]);
1436
+ const handleSubmit = /* @__PURE__ */ __name(async (e) => {
1437
+ e.preventDefault();
1438
+ const args = {};
1439
+ fields.forEach((field) => {
1440
+ let value = formData[field.name];
1441
+ if (field.type === "number" || field.type === "slider") {
1442
+ value = Number(value);
1443
+ }
1444
+ args[field.name] = value;
1445
+ });
1446
+ await call(args);
1447
+ }, "handleSubmit");
1448
+ const handleChange = /* @__PURE__ */ __name((name, value) => {
1449
+ setFormData((prev) => ({
1450
+ ...prev,
1451
+ [name]: value
1452
+ }));
1453
+ }, "handleChange");
1454
+ const renderField = /* @__PURE__ */ __name((field) => {
1455
+ const value = formData[field.name];
1456
+ switch (field.type) {
1457
+ case "textarea":
1458
+ return /* @__PURE__ */ React26.createElement(Textarea, {
1459
+ id: field.name,
1460
+ placeholder: field.placeholder,
1461
+ value: value ?? "",
1462
+ onChange: /* @__PURE__ */ __name((e) => handleChange(field.name, e.target.value), "onChange"),
1463
+ disabled: field.disabled || loading,
1464
+ required: field.required
1465
+ });
1466
+ case "select":
1467
+ return /* @__PURE__ */ React26.createElement(Select, {
1468
+ value: value ?? "",
1469
+ onValueChange: /* @__PURE__ */ __name((v) => handleChange(field.name, v), "onValueChange"),
1470
+ disabled: field.disabled || loading
1471
+ }, /* @__PURE__ */ React26.createElement(SelectTrigger, null, /* @__PURE__ */ React26.createElement(SelectValue, {
1472
+ placeholder: field.placeholder ?? "Select..."
1473
+ })), /* @__PURE__ */ React26.createElement(SelectContent, null, field.options?.map((option) => /* @__PURE__ */ React26.createElement(SelectItem, {
1474
+ key: option.value,
1475
+ value: option.value
1476
+ }, option.label))));
1477
+ case "checkbox":
1478
+ return /* @__PURE__ */ React26.createElement("div", {
1479
+ className: "flex items-center space-x-2"
1480
+ }, /* @__PURE__ */ React26.createElement(Checkbox, {
1481
+ id: field.name,
1482
+ checked: value ?? false,
1483
+ onCheckedChange: /* @__PURE__ */ __name((checked) => handleChange(field.name, checked), "onCheckedChange"),
1484
+ disabled: field.disabled || loading
1485
+ }), /* @__PURE__ */ React26.createElement("label", {
1486
+ htmlFor: field.name,
1487
+ className: "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
1488
+ }, field.label));
1489
+ case "switch":
1490
+ return /* @__PURE__ */ React26.createElement("div", {
1491
+ className: "flex items-center space-x-2"
1492
+ }, /* @__PURE__ */ React26.createElement(Switch, {
1493
+ id: field.name,
1494
+ checked: value ?? false,
1495
+ onCheckedChange: /* @__PURE__ */ __name((checked) => handleChange(field.name, checked), "onCheckedChange"),
1496
+ disabled: field.disabled || loading
1497
+ }), /* @__PURE__ */ React26.createElement(Label2, {
1498
+ htmlFor: field.name
1499
+ }, field.label));
1500
+ case "slider":
1501
+ return /* @__PURE__ */ React26.createElement("div", {
1502
+ className: "space-y-2"
1503
+ }, /* @__PURE__ */ React26.createElement("div", {
1504
+ className: "flex justify-between text-sm"
1505
+ }, /* @__PURE__ */ React26.createElement("span", null, field.min ?? 0), /* @__PURE__ */ React26.createElement("span", null, value ?? field.min ?? 0), /* @__PURE__ */ React26.createElement("span", null, field.max ?? 100)), /* @__PURE__ */ React26.createElement(Slider, {
1506
+ value: [
1507
+ value ?? field.min ?? 0
1508
+ ],
1509
+ onValueChange: /* @__PURE__ */ __name(([v]) => handleChange(field.name, v), "onValueChange"),
1510
+ min: field.min ?? 0,
1511
+ max: field.max ?? 100,
1512
+ step: field.step ?? 1,
1513
+ disabled: field.disabled || loading
1514
+ }));
1515
+ case "number":
1516
+ return /* @__PURE__ */ React26.createElement(Input, {
1517
+ id: field.name,
1518
+ type: "number",
1519
+ placeholder: field.placeholder,
1520
+ value: value ?? "",
1521
+ onChange: /* @__PURE__ */ __name((e) => handleChange(field.name, e.target.value), "onChange"),
1522
+ min: field.min,
1523
+ max: field.max,
1524
+ step: field.step,
1525
+ disabled: field.disabled || loading,
1526
+ required: field.required
1527
+ });
1528
+ default:
1529
+ return /* @__PURE__ */ React26.createElement(Input, {
1530
+ id: field.name,
1531
+ type: field.type ?? "text",
1532
+ placeholder: field.placeholder,
1533
+ value: value ?? "",
1534
+ onChange: /* @__PURE__ */ __name((e) => handleChange(field.name, e.target.value), "onChange"),
1535
+ disabled: field.disabled || loading,
1536
+ required: field.required
1537
+ });
1538
+ }
1539
+ }, "renderField");
1540
+ if (schemaLoading) {
1541
+ return /* @__PURE__ */ React26.createElement("div", {
1542
+ className: "flex items-center justify-center p-8"
1543
+ }, /* @__PURE__ */ React26.createElement(Loader2, {
1544
+ className: "h-6 w-6 animate-spin text-muted-foreground"
1545
+ }));
1546
+ }
1547
+ return /* @__PURE__ */ React26.createElement("form", {
1548
+ className: cn("space-y-4", className),
1549
+ onSubmit: handleSubmit
1550
+ }, /* @__PURE__ */ React26.createElement("div", {
1551
+ className: cn("space-y-4", layout === "horizontal" && "grid grid-cols-2 gap-4")
1552
+ }, fields.map((field) => /* @__PURE__ */ React26.createElement("div", {
1553
+ key: field.name,
1554
+ className: "space-y-2"
1555
+ }, field.type !== "checkbox" && field.type !== "switch" && /* @__PURE__ */ React26.createElement(Label2, {
1556
+ htmlFor: field.name
1557
+ }, field.label, field.required && /* @__PURE__ */ React26.createElement("span", {
1558
+ className: "text-destructive ml-1"
1559
+ }, "*")), renderField(field), field.description && /* @__PURE__ */ React26.createElement("p", {
1560
+ className: "text-sm text-muted-foreground"
1561
+ }, field.description)))), /* @__PURE__ */ React26.createElement("div", {
1562
+ className: "flex items-center gap-2"
1563
+ }, /* @__PURE__ */ React26.createElement(Button, {
1564
+ type: "submit",
1565
+ disabled: loading
1566
+ }, loading ? /* @__PURE__ */ React26.createElement(React26.Fragment, null, /* @__PURE__ */ React26.createElement(Loader2, {
1567
+ className: "h-4 w-4 animate-spin mr-2"
1568
+ }), loadingText ?? "Submitting...") : submitText)), error && /* @__PURE__ */ React26.createElement(Alert, {
1569
+ variant: "destructive"
1570
+ }, /* @__PURE__ */ React26.createElement(AlertDescription, null, error.message)), showResult && result !== null && /* @__PURE__ */ React26.createElement("div", {
1571
+ className: "rounded-md bg-muted p-4"
1572
+ }, /* @__PURE__ */ React26.createElement("pre", {
1573
+ className: "text-sm overflow-auto"
1574
+ }, JSON.stringify(result, null, 2))));
1575
+ }
1576
+ __name(ToolForm, "ToolForm");
1577
+ function useResource(uri, options = {}) {
1578
+ const { app, isConnected } = useMcpApp();
1579
+ const { refreshInterval, subscribe = false, transform, skip = false } = options;
1580
+ const [data, setData] = useState(null);
1581
+ const [loading, setLoading] = useState(!skip);
1582
+ const [error, setError] = useState(null);
1583
+ const [lastUpdated, setLastUpdated] = useState(null);
1584
+ const intervalRef = useRef(null);
1585
+ const mountedRef = useRef(true);
1586
+ const fetchResource = useCallback(async () => {
1587
+ if (!app || !isConnected) {
1588
+ throw new Error("Not connected to MCP host");
1589
+ }
1590
+ setLoading(true);
1591
+ setError(null);
1592
+ try {
1593
+ const result = await app.readResource?.({
1594
+ uri
1595
+ });
1596
+ if (!result) {
1597
+ throw new Error("readResource not supported by host");
1598
+ }
1599
+ let resourceData;
1600
+ if (result.contents && result.contents.length > 0) {
1601
+ const content = result.contents[0];
1602
+ if (content.text) {
1603
+ try {
1604
+ resourceData = JSON.parse(content.text);
1605
+ } catch {
1606
+ resourceData = content.text;
1607
+ }
1608
+ } else if (content.blob) {
1609
+ resourceData = content.blob;
1610
+ } else {
1611
+ resourceData = content;
1612
+ }
1613
+ } else {
1614
+ resourceData = result;
1615
+ }
1616
+ if (transform) {
1617
+ resourceData = transform(resourceData);
1618
+ }
1619
+ if (mountedRef.current) {
1620
+ setData(resourceData);
1621
+ setLastUpdated(/* @__PURE__ */ new Date());
1622
+ setLoading(false);
1623
+ }
1624
+ return resourceData;
1625
+ } catch (err) {
1626
+ const error2 = err instanceof Error ? err : new Error(String(err));
1627
+ if (mountedRef.current) {
1628
+ setError(error2);
1629
+ setLoading(false);
1630
+ }
1631
+ throw error2;
1632
+ }
1633
+ }, [
1634
+ app,
1635
+ isConnected,
1636
+ uri,
1637
+ transform
1638
+ ]);
1639
+ const refresh = useCallback(async () => {
1640
+ return fetchResource();
1641
+ }, [
1642
+ fetchResource
1643
+ ]);
1644
+ useEffect(() => {
1645
+ mountedRef.current = true;
1646
+ if (!skip && isConnected) {
1647
+ fetchResource().catch(() => {
1648
+ });
1649
+ }
1650
+ return () => {
1651
+ mountedRef.current = false;
1652
+ };
1653
+ }, [
1654
+ uri,
1655
+ isConnected,
1656
+ skip,
1657
+ fetchResource
1658
+ ]);
1659
+ useEffect(() => {
1660
+ if (intervalRef.current) {
1661
+ clearInterval(intervalRef.current);
1662
+ intervalRef.current = null;
1663
+ }
1664
+ if (refreshInterval && refreshInterval > 0 && isConnected && !skip) {
1665
+ intervalRef.current = setInterval(() => {
1666
+ fetchResource().catch(() => {
1667
+ });
1668
+ }, refreshInterval);
1669
+ }
1670
+ return () => {
1671
+ if (intervalRef.current) {
1672
+ clearInterval(intervalRef.current);
1673
+ intervalRef.current = null;
1674
+ }
1675
+ };
1676
+ }, [
1677
+ refreshInterval,
1678
+ isConnected,
1679
+ skip,
1680
+ fetchResource
1681
+ ]);
1682
+ useEffect(() => {
1683
+ if (subscribe) {
1684
+ console.warn("[useResource] Subscription support not yet implemented");
1685
+ }
1686
+ }, [
1687
+ subscribe
1688
+ ]);
1689
+ return {
1690
+ data,
1691
+ loading,
1692
+ error,
1693
+ refresh,
1694
+ lastUpdated
1695
+ };
1696
+ }
1697
+ __name(useResource, "useResource");
1698
+ function Skeleton({ className, ...props }) {
1699
+ return /* @__PURE__ */ React26__default.createElement("div", {
1700
+ "data-slot": "skeleton",
1701
+ className: cn("bg-accent animate-pulse rounded-md", className),
1702
+ ...props
1703
+ });
1704
+ }
1705
+ __name(Skeleton, "Skeleton");
1706
+
1707
+ // src/mcp/ResourceView.tsx
1708
+ function DefaultLoading() {
1709
+ return /* @__PURE__ */ React26.createElement("div", {
1710
+ className: "flex flex-col gap-3 p-4"
1711
+ }, /* @__PURE__ */ React26.createElement(Skeleton, {
1712
+ className: "h-4 w-3/4"
1713
+ }), /* @__PURE__ */ React26.createElement(Skeleton, {
1714
+ className: "h-4 w-1/2"
1715
+ }), /* @__PURE__ */ React26.createElement(Skeleton, {
1716
+ className: "h-20 w-full"
1717
+ }));
1718
+ }
1719
+ __name(DefaultLoading, "DefaultLoading");
1720
+ function DefaultError({ error, onRetry }) {
1721
+ return /* @__PURE__ */ React26.createElement(Alert, {
1722
+ variant: "destructive"
1723
+ }, /* @__PURE__ */ React26.createElement(AlertCircle, {
1724
+ className: "h-4 w-4"
1725
+ }), /* @__PURE__ */ React26.createElement(AlertTitle, null, "Error loading resource"), /* @__PURE__ */ React26.createElement(AlertDescription, {
1726
+ className: "flex flex-col gap-2"
1727
+ }, /* @__PURE__ */ React26.createElement("span", null, error.message), /* @__PURE__ */ React26.createElement(Button, {
1728
+ variant: "outline",
1729
+ size: "sm",
1730
+ onClick: onRetry,
1731
+ className: "w-fit"
1732
+ }, /* @__PURE__ */ React26.createElement(RefreshCw, {
1733
+ className: "h-4 w-4 mr-2"
1734
+ }), "Retry")));
1735
+ }
1736
+ __name(DefaultError, "DefaultError");
1737
+ function ResourceView({ uri, refreshInterval, subscribe, transform, loading: loadingContent, error: errorContent, children, className, skip = false }) {
1738
+ const { data, loading, error, refresh, lastUpdated } = useResource(uri, {
1739
+ refreshInterval,
1740
+ subscribe,
1741
+ transform,
1742
+ skip
1743
+ });
1744
+ const meta = {
1745
+ uri,
1746
+ refresh,
1747
+ lastUpdated,
1748
+ isRefreshing: loading && data !== null
1749
+ };
1750
+ if (loading && data === null) {
1751
+ if (loadingContent) {
1752
+ return /* @__PURE__ */ React26.createElement("div", {
1753
+ className
1754
+ }, loadingContent);
1755
+ }
1756
+ return /* @__PURE__ */ React26.createElement("div", {
1757
+ className: cn("flex items-center justify-center p-8", className)
1758
+ }, /* @__PURE__ */ React26.createElement(Loader2, {
1759
+ className: "h-8 w-8 animate-spin text-muted-foreground"
1760
+ }));
1761
+ }
1762
+ if (error && data === null) {
1763
+ if (errorContent) {
1764
+ if (typeof errorContent === "function") {
1765
+ return /* @__PURE__ */ React26.createElement("div", {
1766
+ className
1767
+ }, errorContent(error, refresh));
1768
+ }
1769
+ return /* @__PURE__ */ React26.createElement("div", {
1770
+ className
1771
+ }, errorContent);
1772
+ }
1773
+ return /* @__PURE__ */ React26.createElement("div", {
1774
+ className
1775
+ }, /* @__PURE__ */ React26.createElement(DefaultError, {
1776
+ error,
1777
+ onRetry: refresh
1778
+ }));
1779
+ }
1780
+ if (data !== null) {
1781
+ return /* @__PURE__ */ React26.createElement("div", {
1782
+ className
1783
+ }, children(data, meta));
1784
+ }
1785
+ return /* @__PURE__ */ React26.createElement("div", {
1786
+ className
1787
+ }, loadingContent ?? /* @__PURE__ */ React26.createElement(DefaultLoading, null));
1788
+ }
1789
+ __name(ResourceView, "ResourceView");
1790
+ function useToolStream(options = {}) {
1791
+ const { toolInputPartial, toolInput, toolResult } = useMcpApp();
1792
+ const { onPartial, onComplete } = options;
1793
+ const [partial, setPartial] = useState(null);
1794
+ const [complete, setComplete] = useState(null);
1795
+ const [isStreaming, setIsStreaming] = useState(false);
1796
+ const [isComplete, setIsComplete] = useState(false);
1797
+ useEffect(() => {
1798
+ if (toolInputPartial) {
1799
+ setPartial(toolInputPartial);
1800
+ setIsStreaming(true);
1801
+ setIsComplete(false);
1802
+ onPartial?.(toolInputPartial);
1803
+ }
1804
+ }, [
1805
+ toolInputPartial,
1806
+ onPartial
1807
+ ]);
1808
+ useEffect(() => {
1809
+ if (toolInput) {
1810
+ setComplete(toolInput);
1811
+ setIsStreaming(false);
1812
+ setIsComplete(true);
1813
+ onComplete?.(toolInput);
1814
+ }
1815
+ }, [
1816
+ toolInput,
1817
+ onComplete
1818
+ ]);
1819
+ useEffect(() => {
1820
+ if (toolResult && !toolResult.isError) {
1821
+ setIsStreaming(false);
1822
+ setIsComplete(true);
1823
+ }
1824
+ }, [
1825
+ toolResult
1826
+ ]);
1827
+ return {
1828
+ partial,
1829
+ complete,
1830
+ isStreaming,
1831
+ isComplete
1832
+ };
1833
+ }
1834
+ __name(useToolStream, "useToolStream");
1835
+ function Progress({ className, value, ...props }) {
1836
+ return /* @__PURE__ */ React26.createElement(ProgressPrimitive.Root, {
1837
+ "data-slot": "progress",
1838
+ className: cn("bg-primary/20 relative h-2 w-full overflow-hidden rounded-full", className),
1839
+ ...props
1840
+ }, /* @__PURE__ */ React26.createElement(ProgressPrimitive.Indicator, {
1841
+ "data-slot": "progress-indicator",
1842
+ className: "bg-primary h-full w-full flex-1 transition-all",
1843
+ style: {
1844
+ transform: `translateX(-${100 - (value || 0)}%)`
1845
+ }
1846
+ }));
1847
+ }
1848
+ __name(Progress, "Progress");
1849
+
1850
+ // src/mcp/StreamingContent.tsx
1851
+ function StreamingContent({ fallback, showProgress = false, progress: externalProgress, onPartial, onComplete, children, className, streamingStyle = "opacity" }) {
1852
+ const { partial, complete, isStreaming, isComplete } = useToolStream({
1853
+ onPartial,
1854
+ onComplete
1855
+ });
1856
+ const data = complete ?? partial;
1857
+ if (!data) {
1858
+ if (fallback) {
1859
+ return /* @__PURE__ */ React26.createElement("div", {
1860
+ className
1861
+ }, fallback);
1862
+ }
1863
+ return /* @__PURE__ */ React26.createElement("div", {
1864
+ className: cn("flex items-center justify-center p-8", className)
1865
+ }, /* @__PURE__ */ React26.createElement(Loader2, {
1866
+ className: "h-6 w-6 animate-spin text-muted-foreground"
1867
+ }));
1868
+ }
1869
+ const streamingClasses = cn(streamingStyle === "opacity" && isStreaming && "opacity-70", streamingStyle === "blur" && isStreaming && "blur-[1px]");
1870
+ return /* @__PURE__ */ React26.createElement("div", {
1871
+ className: cn("relative", className)
1872
+ }, showProgress && isStreaming && /* @__PURE__ */ React26.createElement("div", {
1873
+ className: "absolute top-0 left-0 right-0 z-10"
1874
+ }, externalProgress !== void 0 ? /* @__PURE__ */ React26.createElement(Progress, {
1875
+ value: externalProgress,
1876
+ className: "h-1"
1877
+ }) : /* @__PURE__ */ React26.createElement("div", {
1878
+ className: "h-1 bg-primary/20 overflow-hidden"
1879
+ }, /* @__PURE__ */ React26.createElement("div", {
1880
+ className: "h-full w-1/3 bg-primary animate-[shimmer_1s_infinite]"
1881
+ }))), isStreaming && /* @__PURE__ */ React26.createElement("div", {
1882
+ className: "absolute top-2 right-2 z-10"
1883
+ }, /* @__PURE__ */ React26.createElement("div", {
1884
+ className: "flex items-center gap-1 px-2 py-1 rounded-full bg-muted text-muted-foreground text-xs"
1885
+ }, /* @__PURE__ */ React26.createElement(Loader2, {
1886
+ className: "h-3 w-3 animate-spin"
1887
+ }), /* @__PURE__ */ React26.createElement("span", null, "Streaming..."))), /* @__PURE__ */ React26.createElement("div", {
1888
+ className: cn("transition-all duration-200", streamingClasses)
1889
+ }, children(data, isComplete)));
1890
+ }
1891
+ __name(StreamingContent, "StreamingContent");
1892
+ function Table({ className, ...props }) {
1893
+ return /* @__PURE__ */ React26.createElement("div", {
1894
+ "data-slot": "table-container",
1895
+ className: "relative w-full overflow-x-auto"
1896
+ }, /* @__PURE__ */ React26.createElement("table", {
1897
+ "data-slot": "table",
1898
+ className: cn("w-full caption-bottom text-sm", className),
1899
+ ...props
1900
+ }));
1901
+ }
1902
+ __name(Table, "Table");
1903
+ function TableHeader({ className, ...props }) {
1904
+ return /* @__PURE__ */ React26.createElement("thead", {
1905
+ "data-slot": "table-header",
1906
+ className: cn("[&_tr]:border-b", className),
1907
+ ...props
1908
+ });
1909
+ }
1910
+ __name(TableHeader, "TableHeader");
1911
+ function TableBody({ className, ...props }) {
1912
+ return /* @__PURE__ */ React26.createElement("tbody", {
1913
+ "data-slot": "table-body",
1914
+ className: cn("[&_tr:last-child]:border-0", className),
1915
+ ...props
1916
+ });
1917
+ }
1918
+ __name(TableBody, "TableBody");
1919
+ function TableFooter({ className, ...props }) {
1920
+ return /* @__PURE__ */ React26.createElement("tfoot", {
1921
+ "data-slot": "table-footer",
1922
+ className: cn("bg-muted/50 border-t font-medium [&>tr]:last:border-b-0", className),
1923
+ ...props
1924
+ });
1925
+ }
1926
+ __name(TableFooter, "TableFooter");
1927
+ function TableRow({ className, ...props }) {
1928
+ return /* @__PURE__ */ React26.createElement("tr", {
1929
+ "data-slot": "table-row",
1930
+ className: cn("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors", className),
1931
+ ...props
1932
+ });
1933
+ }
1934
+ __name(TableRow, "TableRow");
1935
+ function TableHead({ className, ...props }) {
1936
+ return /* @__PURE__ */ React26.createElement("th", {
1937
+ "data-slot": "table-head",
1938
+ className: cn("text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]", className),
1939
+ ...props
1940
+ });
1941
+ }
1942
+ __name(TableHead, "TableHead");
1943
+ function TableCell({ className, ...props }) {
1944
+ return /* @__PURE__ */ React26.createElement("td", {
1945
+ "data-slot": "table-cell",
1946
+ className: cn("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]", className),
1947
+ ...props
1948
+ });
1949
+ }
1950
+ __name(TableCell, "TableCell");
1951
+ function TableCaption({ className, ...props }) {
1952
+ return /* @__PURE__ */ React26.createElement("caption", {
1953
+ "data-slot": "table-caption",
1954
+ className: cn("text-muted-foreground mt-4 text-sm", className),
1955
+ ...props
1956
+ });
1957
+ }
1958
+ __name(TableCaption, "TableCaption");
1959
+ function getNestedValue(obj, path) {
1960
+ return path.split(".").reduce((current, key) => {
1961
+ if (current && typeof current === "object" && key in current) {
1962
+ return current[key];
1963
+ }
1964
+ return void 0;
1965
+ }, obj);
1966
+ }
1967
+ __name(getNestedValue, "getNestedValue");
1968
+ function ToolDataGrid({ dataTool, columns, transformData, rowActions = [], pagination = true, pageSizes = [
1969
+ 10,
1970
+ 25,
1971
+ 50,
1972
+ 100
1973
+ ], defaultPageSize = 10, defaultSort, refreshInterval, showRefresh = true, onDataLoaded, onError, onRowClick, getRowKey, emptyContent, loadingContent, className }) {
1974
+ if (!dataTool) {
1975
+ throw new Error("ToolDataGrid: dataTool prop is required");
1976
+ }
1977
+ const toolConfig = typeof dataTool === "string" ? {
1978
+ name: dataTool
1979
+ } : dataTool;
1980
+ const [data, setData] = useState({
1981
+ rows: [],
1982
+ total: 0
1983
+ });
1984
+ const [paginationState, setPaginationState] = useState({
1985
+ page: 1,
1986
+ pageSize: defaultPageSize
1987
+ });
1988
+ const [sortState, setSortState] = useState(defaultSort ?? {
1989
+ column: null,
1990
+ direction: "asc"
1991
+ });
1992
+ const { call, loading, error } = useTool(toolConfig.name, {
1993
+ defaultArgs: toolConfig.args,
1994
+ onSuccess: /* @__PURE__ */ __name((result) => {
1995
+ const gridData = transformData ? transformData(result) : result;
1996
+ setData(gridData);
1997
+ onDataLoaded?.(gridData);
1998
+ }, "onSuccess"),
1999
+ onError
2000
+ });
2001
+ const fetchData = useCallback(() => {
2002
+ const args = {};
2003
+ if (pagination) {
2004
+ args.page = paginationState.page;
2005
+ args.pageSize = paginationState.pageSize;
2006
+ args.offset = (paginationState.page - 1) * paginationState.pageSize;
2007
+ args.limit = paginationState.pageSize;
2008
+ }
2009
+ if (sortState.column) {
2010
+ args.sortBy = sortState.column;
2011
+ args.sortDirection = sortState.direction;
2012
+ args.sort = `${sortState.column}:${sortState.direction}`;
2013
+ }
2014
+ call(args);
2015
+ }, [
2016
+ call,
2017
+ pagination,
2018
+ paginationState,
2019
+ sortState
2020
+ ]);
2021
+ const initialFetchDone = React26.useRef(false);
2022
+ const prevStateRef = React26.useRef({
2023
+ pagination: paginationState,
2024
+ sort: sortState
2025
+ });
2026
+ useEffect(() => {
2027
+ if (!initialFetchDone.current) {
2028
+ initialFetchDone.current = true;
2029
+ fetchData();
2030
+ return;
2031
+ }
2032
+ const prevState = prevStateRef.current;
2033
+ const stateChanged = prevState.pagination.page !== paginationState.page || prevState.pagination.pageSize !== paginationState.pageSize || prevState.sort.column !== sortState.column || prevState.sort.direction !== sortState.direction;
2034
+ if (stateChanged) {
2035
+ prevStateRef.current = {
2036
+ pagination: paginationState,
2037
+ sort: sortState
2038
+ };
2039
+ fetchData();
2040
+ }
2041
+ }, [
2042
+ fetchData,
2043
+ paginationState,
2044
+ sortState
2045
+ ]);
2046
+ useEffect(() => {
2047
+ if (refreshInterval && refreshInterval > 0) {
2048
+ const interval = setInterval(fetchData, refreshInterval);
2049
+ return () => clearInterval(interval);
2050
+ }
2051
+ }, [
2052
+ refreshInterval,
2053
+ fetchData
2054
+ ]);
2055
+ const handleSort = useCallback((column) => {
2056
+ setSortState((prev) => ({
2057
+ column,
2058
+ direction: prev.column === column && prev.direction === "asc" ? "desc" : "asc"
2059
+ }));
2060
+ }, []);
2061
+ const handlePageChange = useCallback((page) => {
2062
+ setPaginationState((prev) => ({
2063
+ ...prev,
2064
+ page
2065
+ }));
2066
+ }, []);
2067
+ const handlePageSizeChange = useCallback((pageSize) => {
2068
+ setPaginationState({
2069
+ page: 1,
2070
+ pageSize: parseInt(pageSize, 10)
2071
+ });
2072
+ }, []);
2073
+ const totalPages = Math.ceil(data.total / paginationState.pageSize);
2074
+ const canPreviousPage = paginationState.page > 1;
2075
+ const canNextPage = paginationState.page < totalPages;
2076
+ const getSortIcon = /* @__PURE__ */ __name((column) => {
2077
+ if (sortState.column !== column) {
2078
+ return /* @__PURE__ */ React26.createElement(ArrowUpDown, {
2079
+ className: "h-4 w-4"
2080
+ });
2081
+ }
2082
+ return sortState.direction === "asc" ? /* @__PURE__ */ React26.createElement(ArrowUp, {
2083
+ className: "h-4 w-4"
2084
+ }) : /* @__PURE__ */ React26.createElement(ArrowDown, {
2085
+ className: "h-4 w-4"
2086
+ });
2087
+ }, "getSortIcon");
2088
+ const renderLoading = /* @__PURE__ */ __name(() => {
2089
+ if (loadingContent) return loadingContent;
2090
+ return /* @__PURE__ */ React26.createElement("div", {
2091
+ className: "space-y-2"
2092
+ }, Array.from({
2093
+ length: 5
2094
+ }).map((_, i) => /* @__PURE__ */ React26.createElement(Skeleton, {
2095
+ key: i,
2096
+ className: "h-12 w-full"
2097
+ })));
2098
+ }, "renderLoading");
2099
+ const renderEmpty = /* @__PURE__ */ __name(() => {
2100
+ if (emptyContent) return emptyContent;
2101
+ return /* @__PURE__ */ React26.createElement("div", {
2102
+ className: "flex flex-col items-center justify-center py-12 text-muted-foreground"
2103
+ }, /* @__PURE__ */ React26.createElement("p", {
2104
+ className: "text-lg"
2105
+ }, "No data found"), /* @__PURE__ */ React26.createElement(Button, {
2106
+ variant: "ghost",
2107
+ size: "sm",
2108
+ onClick: fetchData,
2109
+ className: "mt-2"
2110
+ }, /* @__PURE__ */ React26.createElement(RefreshCw, {
2111
+ className: "h-4 w-4 mr-2"
2112
+ }), "Refresh"));
2113
+ }, "renderEmpty");
2114
+ return /* @__PURE__ */ React26.createElement("div", {
2115
+ className: cn("space-y-4", className)
2116
+ }, showRefresh && /* @__PURE__ */ React26.createElement("div", {
2117
+ className: "flex items-center justify-end gap-2"
2118
+ }, /* @__PURE__ */ React26.createElement(Button, {
2119
+ variant: "outline",
2120
+ size: "sm",
2121
+ onClick: fetchData,
2122
+ disabled: loading
2123
+ }, loading ? /* @__PURE__ */ React26.createElement(Loader2, {
2124
+ className: "h-4 w-4 animate-spin"
2125
+ }) : /* @__PURE__ */ React26.createElement(RefreshCw, {
2126
+ className: "h-4 w-4"
2127
+ }), /* @__PURE__ */ React26.createElement("span", {
2128
+ className: "ml-2"
2129
+ }, "Refresh"))), /* @__PURE__ */ React26.createElement("div", {
2130
+ className: "rounded-md border"
2131
+ }, loading && data.rows.length === 0 ? /* @__PURE__ */ React26.createElement("div", {
2132
+ className: "p-4"
2133
+ }, renderLoading()) : data.rows.length === 0 ? renderEmpty() : /* @__PURE__ */ React26.createElement(Table, null, /* @__PURE__ */ React26.createElement(TableHeader, null, /* @__PURE__ */ React26.createElement(TableRow, null, columns.map((column) => /* @__PURE__ */ React26.createElement(TableHead, {
2134
+ key: column.key,
2135
+ style: {
2136
+ width: column.width
2137
+ },
2138
+ className: cn(column.align === "center" && "text-center", column.align === "right" && "text-right", column.hideMobile && "hidden md:table-cell")
2139
+ }, column.sortable ? /* @__PURE__ */ React26.createElement(Button, {
2140
+ variant: "ghost",
2141
+ size: "sm",
2142
+ onClick: /* @__PURE__ */ __name(() => handleSort(column.key), "onClick"),
2143
+ className: "-ml-3"
2144
+ }, column.header, getSortIcon(column.key)) : column.header)), rowActions.length > 0 && /* @__PURE__ */ React26.createElement(TableHead, {
2145
+ className: "w-[100px]"
2146
+ }, "Actions"))), /* @__PURE__ */ React26.createElement(TableBody, null, data.rows.map((row, index) => {
2147
+ const key = getRowKey?.(row, index) ?? String(index);
2148
+ return /* @__PURE__ */ React26.createElement(TableRow, {
2149
+ key,
2150
+ onClick: /* @__PURE__ */ __name(() => onRowClick?.(row, index), "onClick"),
2151
+ className: onRowClick ? "cursor-pointer" : void 0
2152
+ }, columns.map((column) => {
2153
+ const value = getNestedValue(row, column.key);
2154
+ return /* @__PURE__ */ React26.createElement(TableCell, {
2155
+ key: column.key,
2156
+ className: cn(column.align === "center" && "text-center", column.align === "right" && "text-right", column.hideMobile && "hidden md:table-cell")
2157
+ }, column.render ? column.render(value, row, index) : String(value ?? ""));
2158
+ }), rowActions.length > 0 && /* @__PURE__ */ React26.createElement(TableCell, null, /* @__PURE__ */ React26.createElement("div", {
2159
+ className: "flex items-center gap-1"
2160
+ }, rowActions.filter((action) => !action.hidden?.(row)).map((action, actionIndex) => /* @__PURE__ */ React26.createElement(RowActionButton, {
2161
+ key: actionIndex,
2162
+ action,
2163
+ row,
2164
+ onRefresh: fetchData
2165
+ })))));
2166
+ })))), pagination && data.total > 0 && /* @__PURE__ */ React26.createElement("div", {
2167
+ className: "flex items-center justify-between"
2168
+ }, /* @__PURE__ */ React26.createElement("div", {
2169
+ className: "text-sm text-muted-foreground"
2170
+ }, "Showing ", (paginationState.page - 1) * paginationState.pageSize + 1, " to", " ", Math.min(paginationState.page * paginationState.pageSize, data.total), " of", " ", data.total, " results"), /* @__PURE__ */ React26.createElement("div", {
2171
+ className: "flex items-center gap-4"
2172
+ }, /* @__PURE__ */ React26.createElement("div", {
2173
+ className: "flex items-center gap-2"
2174
+ }, /* @__PURE__ */ React26.createElement("span", {
2175
+ className: "text-sm text-muted-foreground"
2176
+ }, "Rows per page"), /* @__PURE__ */ React26.createElement(Select, {
2177
+ value: String(paginationState.pageSize),
2178
+ onValueChange: handlePageSizeChange
2179
+ }, /* @__PURE__ */ React26.createElement(SelectTrigger, {
2180
+ className: "w-[70px]"
2181
+ }, /* @__PURE__ */ React26.createElement(SelectValue, null)), /* @__PURE__ */ React26.createElement(SelectContent, null, pageSizes.map((size) => /* @__PURE__ */ React26.createElement(SelectItem, {
2182
+ key: size,
2183
+ value: String(size)
2184
+ }, size))))), /* @__PURE__ */ React26.createElement("div", {
2185
+ className: "flex items-center gap-2"
2186
+ }, /* @__PURE__ */ React26.createElement(Button, {
2187
+ variant: "outline",
2188
+ size: "sm",
2189
+ onClick: /* @__PURE__ */ __name(() => handlePageChange(paginationState.page - 1), "onClick"),
2190
+ disabled: !canPreviousPage || loading
2191
+ }, /* @__PURE__ */ React26.createElement(ChevronLeft, {
2192
+ className: "h-4 w-4"
2193
+ })), /* @__PURE__ */ React26.createElement("span", {
2194
+ className: "text-sm"
2195
+ }, "Page ", paginationState.page, " of ", totalPages), /* @__PURE__ */ React26.createElement(Button, {
2196
+ variant: "outline",
2197
+ size: "sm",
2198
+ onClick: /* @__PURE__ */ __name(() => handlePageChange(paginationState.page + 1), "onClick"),
2199
+ disabled: !canNextPage || loading
2200
+ }, /* @__PURE__ */ React26.createElement(ChevronRight, {
2201
+ className: "h-4 w-4"
2202
+ }))))));
2203
+ }
2204
+ __name(ToolDataGrid, "ToolDataGrid");
2205
+ function RowActionButton({ action, row, onRefresh }) {
2206
+ if (!action.tool) {
2207
+ throw new Error("ToolDataGrid: rowAction.tool is required");
2208
+ }
2209
+ const toolConfig = typeof action.tool === "string" ? {
2210
+ name: action.tool
2211
+ } : action.tool;
2212
+ const args = action.getArgs?.(row) ?? {
2213
+ id: row.id
2214
+ };
2215
+ const { call, loading } = useTool(toolConfig.name, {
2216
+ onSuccess: /* @__PURE__ */ __name((result) => {
2217
+ action.onSuccess?.(result, row);
2218
+ toast.success("Action completed");
2219
+ onRefresh();
2220
+ }, "onSuccess"),
2221
+ onError: /* @__PURE__ */ __name((error) => {
2222
+ toast.error(error.message);
2223
+ }, "onError")
2224
+ });
2225
+ const handleClick = useCallback((e) => {
2226
+ e.stopPropagation();
2227
+ call(args);
2228
+ }, [
2229
+ call,
2230
+ args
2231
+ ]);
2232
+ return /* @__PURE__ */ React26.createElement(Button, {
2233
+ variant: action.variant ?? "ghost",
2234
+ size: "sm",
2235
+ onClick: handleClick,
2236
+ disabled: loading
2237
+ }, loading ? /* @__PURE__ */ React26.createElement(Loader2, {
2238
+ className: "h-3 w-3 animate-spin"
2239
+ }) : /* @__PURE__ */ React26.createElement(React26.Fragment, null, action.icon, /* @__PURE__ */ React26.createElement("span", {
2240
+ className: action.icon ? "ml-1" : ""
2241
+ }, action.label)));
2242
+ }
2243
+ __name(RowActionButton, "RowActionButton");
2244
+ var Button2 = /* @__PURE__ */ forwardRef(({ className, variant = "primary", size = "md", loading = false, disabled, asChild = false, leftIcon, rightIcon, children, ...props }, ref) => {
2245
+ const Comp = asChild ? Slot : "button";
2246
+ return /* @__PURE__ */ React26__default.createElement(Comp, {
2247
+ ref,
2248
+ className: clsx("lui-button", `lui-button--${variant}`, `lui-button--${size}`, loading && "lui-button--loading", className),
2249
+ disabled: disabled || loading,
2250
+ ...props
2251
+ }, loading && /* @__PURE__ */ React26__default.createElement("span", {
2252
+ className: "lui-button__spinner",
2253
+ "aria-hidden": "true"
2254
+ }, /* @__PURE__ */ React26__default.createElement("svg", {
2255
+ viewBox: "0 0 24 24",
2256
+ fill: "none",
2257
+ className: "lui-spinner-icon"
2258
+ }, /* @__PURE__ */ React26__default.createElement("circle", {
2259
+ cx: "12",
2260
+ cy: "12",
2261
+ r: "10",
2262
+ stroke: "currentColor",
2263
+ strokeWidth: "3",
2264
+ strokeLinecap: "round",
2265
+ strokeDasharray: "32",
2266
+ strokeDashoffset: "12"
2267
+ }))), leftIcon && !loading && /* @__PURE__ */ React26__default.createElement("span", {
2268
+ className: "lui-button__icon"
2269
+ }, leftIcon), /* @__PURE__ */ React26__default.createElement("span", {
2270
+ className: "lui-button__content"
2271
+ }, children), rightIcon && /* @__PURE__ */ React26__default.createElement("span", {
2272
+ className: "lui-button__icon"
2273
+ }, rightIcon));
2274
+ });
2275
+ Button2.displayName = "Button";
2276
+
2277
+ // src/mcp/ActionButton.tsx
2278
+ function ActionButton({ toolName, toolArgs = {}, onToolSuccess, onToolError, showResult = false, renderResult, children, ...buttonProps }) {
2279
+ const { call, loading, result, error } = useTool(toolName);
2280
+ const [hasResult, setHasResult] = useState(false);
2281
+ const handleClick = /* @__PURE__ */ __name(async () => {
2282
+ try {
2283
+ const res = await call(toolArgs);
2284
+ setHasResult(true);
2285
+ onToolSuccess?.(res);
2286
+ } catch (err) {
2287
+ onToolError?.(err instanceof Error ? err : new Error(String(err)));
2288
+ }
2289
+ }, "handleClick");
2290
+ return /* @__PURE__ */ React26__default.createElement("div", {
2291
+ className: "lui-action-button-wrapper"
2292
+ }, /* @__PURE__ */ React26__default.createElement(Button2, {
2293
+ ...buttonProps,
2294
+ loading,
2295
+ onClick: handleClick
2296
+ }, children), showResult && hasResult && result !== null && /* @__PURE__ */ React26__default.createElement("div", {
2297
+ className: "lui-action-button-result"
2298
+ }, renderResult ? renderResult(result) : /* @__PURE__ */ React26__default.createElement("pre", null, JSON.stringify(result, null, 2))), error && /* @__PURE__ */ React26__default.createElement("div", {
2299
+ className: "lui-action-button-error"
2300
+ }, error.message));
2301
+ }
2302
+ __name(ActionButton, "ActionButton");
2303
+ function DefaultLoading2() {
2304
+ return /* @__PURE__ */ React26.createElement("div", {
2305
+ className: "flex items-center justify-center p-8"
2306
+ }, /* @__PURE__ */ React26.createElement(Loader2, {
2307
+ className: "h-6 w-6 animate-spin text-muted-foreground"
2308
+ }));
2309
+ }
2310
+ __name(DefaultLoading2, "DefaultLoading");
2311
+ function DefaultDisconnected() {
2312
+ return /* @__PURE__ */ React26.createElement(Alert, null, /* @__PURE__ */ React26.createElement(WifiOff, {
2313
+ className: "h-4 w-4"
2314
+ }), /* @__PURE__ */ React26.createElement(AlertDescription, null, "Waiting for connection to MCP host..."));
2315
+ }
2316
+ __name(DefaultDisconnected, "DefaultDisconnected");
2317
+ function DefaultError2({ error }) {
2318
+ return /* @__PURE__ */ React26.createElement(Alert, {
2319
+ variant: "destructive"
2320
+ }, /* @__PURE__ */ React26.createElement(AlertCircle, {
2321
+ className: "h-4 w-4"
2322
+ }), /* @__PURE__ */ React26.createElement(AlertDescription, null, "Connection error: ", error.message));
2323
+ }
2324
+ __name(DefaultError2, "DefaultError");
2325
+ function RequireConnection({ loading: loadingContent, error: errorContent, disconnected: disconnectedContent, children, className }) {
2326
+ const { isConnected, error, app } = useMcpApp();
2327
+ console.log("[RequireConnection] State:", {
2328
+ hasApp: !!app,
2329
+ isConnected,
2330
+ hasError: !!error
2331
+ });
2332
+ if (!app && !error && !isConnected) {
2333
+ console.log("[RequireConnection] Rendering: Initial Loading");
2334
+ if (loadingContent) {
2335
+ return /* @__PURE__ */ React26.createElement("div", {
2336
+ className
2337
+ }, loadingContent);
2338
+ }
2339
+ return /* @__PURE__ */ React26.createElement("div", {
2340
+ className
2341
+ }, /* @__PURE__ */ React26.createElement(DefaultLoading2, null));
2342
+ }
2343
+ if (error) {
2344
+ console.log("[RequireConnection] Rendering: Error");
2345
+ if (errorContent) {
2346
+ if (typeof errorContent === "function") {
2347
+ return /* @__PURE__ */ React26.createElement("div", {
2348
+ className
2349
+ }, errorContent(error));
2350
+ }
2351
+ return /* @__PURE__ */ React26.createElement("div", {
2352
+ className
2353
+ }, errorContent);
2354
+ }
2355
+ return /* @__PURE__ */ React26.createElement("div", {
2356
+ className
2357
+ }, /* @__PURE__ */ React26.createElement(DefaultError2, {
2358
+ error
2359
+ }));
2360
+ }
2361
+ if (!isConnected) {
2362
+ console.log("[RequireConnection] Rendering: Disconnected/Loading");
2363
+ if (disconnectedContent) {
2364
+ return /* @__PURE__ */ React26.createElement("div", {
2365
+ className
2366
+ }, disconnectedContent);
2367
+ }
2368
+ if (loadingContent) {
2369
+ return /* @__PURE__ */ React26.createElement("div", {
2370
+ className
2371
+ }, loadingContent);
2372
+ }
2373
+ return /* @__PURE__ */ React26.createElement("div", {
2374
+ className
2375
+ }, /* @__PURE__ */ React26.createElement(DefaultDisconnected, null));
2376
+ }
2377
+ console.log("[RequireConnection] Rendering: Children (Connected)");
2378
+ return /* @__PURE__ */ React26.createElement(React26.Fragment, null, children);
2379
+ }
2380
+ __name(RequireConnection, "RequireConnection");
2381
+ function DefaultFallback({ error, onRetry }) {
2382
+ return /* @__PURE__ */ React26.createElement(Alert, {
2383
+ variant: "destructive"
2384
+ }, /* @__PURE__ */ React26.createElement(AlertCircle, {
2385
+ className: "h-4 w-4"
2386
+ }), /* @__PURE__ */ React26.createElement(AlertTitle, null, "Something went wrong"), /* @__PURE__ */ React26.createElement(AlertDescription, {
2387
+ className: "flex flex-col gap-3"
2388
+ }, /* @__PURE__ */ React26.createElement("p", {
2389
+ className: "text-sm"
2390
+ }, error.message), /* @__PURE__ */ React26.createElement(Button, {
2391
+ variant: "outline",
2392
+ size: "sm",
2393
+ onClick: onRetry,
2394
+ className: "w-fit"
2395
+ }, /* @__PURE__ */ React26.createElement(RefreshCw, {
2396
+ className: "h-4 w-4 mr-2"
2397
+ }), "Try Again")));
2398
+ }
2399
+ __name(DefaultFallback, "DefaultFallback");
2400
+ var ToolErrorBoundary = class extends Component {
2401
+ static {
2402
+ __name(this, "ToolErrorBoundary");
2403
+ }
2404
+ constructor(props) {
2405
+ super(props);
2406
+ this.state = {
2407
+ hasError: false,
2408
+ error: null
2409
+ };
2410
+ }
2411
+ static getDerivedStateFromError(error) {
2412
+ return {
2413
+ hasError: true,
2414
+ error
2415
+ };
2416
+ }
2417
+ componentDidCatch(error, errorInfo) {
2418
+ this.props.onError?.(error, errorInfo);
2419
+ }
2420
+ componentDidUpdate(prevProps) {
2421
+ if (this.state.hasError && this.props.resetKeys && prevProps.resetKeys && this.props.resetKeys.some((key, index) => key !== prevProps.resetKeys?.[index])) {
2422
+ this.reset();
2423
+ }
2424
+ }
2425
+ reset = /* @__PURE__ */ __name(() => {
2426
+ this.setState({
2427
+ hasError: false,
2428
+ error: null
2429
+ });
2430
+ }, "reset");
2431
+ render() {
2432
+ const { hasError, error } = this.state;
2433
+ const { fallback, children } = this.props;
2434
+ if (hasError && error) {
2435
+ if (fallback) {
2436
+ if (typeof fallback === "function") {
2437
+ return fallback(error, this.reset);
2438
+ }
2439
+ return fallback;
2440
+ }
2441
+ return /* @__PURE__ */ React26.createElement(DefaultFallback, {
2442
+ error,
2443
+ onRetry: this.reset
2444
+ });
2445
+ }
2446
+ return children;
2447
+ }
2448
+ };
2449
+ function useMessage() {
2450
+ const { sendMessage: appSendMessage, isConnected } = useMcpApp();
2451
+ const [sending, setSending] = useState(false);
2452
+ const [error, setError] = useState(null);
2453
+ const send = useCallback(async (text) => {
2454
+ if (!isConnected) {
2455
+ console.warn("[useMessage] Not connected to host");
2456
+ return;
2457
+ }
2458
+ setSending(true);
2459
+ setError(null);
2460
+ try {
2461
+ await appSendMessage(text);
2462
+ } catch (err) {
2463
+ const error2 = err instanceof Error ? err : new Error(String(err));
2464
+ setError(error2);
2465
+ throw error2;
2466
+ } finally {
2467
+ setSending(false);
2468
+ }
2469
+ }, [
2470
+ appSendMessage,
2471
+ isConnected
2472
+ ]);
2473
+ const sendContent = useCallback(async (content) => {
2474
+ if (!isConnected) {
2475
+ console.warn("[useMessage] Not connected to host");
2476
+ return;
2477
+ }
2478
+ setSending(true);
2479
+ setError(null);
2480
+ try {
2481
+ const textContent = content.filter((c) => c.type === "text").map((c) => c.text).join("\n");
2482
+ await appSendMessage(textContent);
2483
+ } catch (err) {
2484
+ const error2 = err instanceof Error ? err : new Error(String(err));
2485
+ setError(error2);
2486
+ throw error2;
2487
+ } finally {
2488
+ setSending(false);
2489
+ }
2490
+ }, [
2491
+ appSendMessage,
2492
+ isConnected
2493
+ ]);
2494
+ const requestTool = useCallback(async (toolName, args) => {
2495
+ let message = `Please call the "${toolName}" tool`;
2496
+ if (args && Object.keys(args).length > 0) {
2497
+ message += ` with arguments: ${JSON.stringify(args)}`;
2498
+ }
2499
+ await send(message);
2500
+ }, [
2501
+ send
2502
+ ]);
2503
+ return {
2504
+ send,
2505
+ sendContent,
2506
+ requestTool,
2507
+ sending,
2508
+ error
2509
+ };
2510
+ }
2511
+ __name(useMessage, "useMessage");
2512
+
2513
+ // src/mcp/useHostContext.ts
2514
+ function useHostContext() {
2515
+ const { hostContext } = useMcpApp();
2516
+ return {
2517
+ theme: hostContext.theme ?? "light",
2518
+ displayMode: hostContext.displayMode ?? "inline",
2519
+ availableDisplayModes: hostContext.availableDisplayModes ?? [],
2520
+ viewport: hostContext.viewport ?? null,
2521
+ locale: hostContext.locale ?? null,
2522
+ timeZone: hostContext.timeZone ?? null,
2523
+ platform: hostContext.platform ?? null,
2524
+ userAgent: hostContext.userAgent ?? null,
2525
+ deviceCapabilities: hostContext.deviceCapabilities ?? null,
2526
+ safeAreaInsets: hostContext.safeAreaInsets ?? null,
2527
+ styles: hostContext.styles ?? null,
2528
+ rawContext: hostContext
2529
+ };
2530
+ }
2531
+ __name(useHostContext, "useHostContext");
2532
+
2533
+ // src/mcp/useToolResult.ts
2534
+ function useToolResult() {
2535
+ const { toolResult } = useMcpApp();
2536
+ let result = null;
2537
+ let textContent = null;
2538
+ if (toolResult) {
2539
+ if ("structuredContent" in toolResult && toolResult.structuredContent) {
2540
+ result = toolResult.structuredContent;
2541
+ }
2542
+ if (!result && toolResult.content) {
2543
+ const textItem = toolResult.content.find((c) => c.type === "text");
2544
+ if (textItem) {
2545
+ textContent = textItem.text;
2546
+ try {
2547
+ result = JSON.parse(textItem.text);
2548
+ } catch {
2549
+ }
2550
+ }
2551
+ }
2552
+ }
2553
+ return {
2554
+ result,
2555
+ rawResult: toolResult,
2556
+ hasResult: toolResult !== null,
2557
+ textContent
2558
+ };
2559
+ }
2560
+ __name(useToolResult, "useToolResult");
2561
+
2562
+ // src/mcp/useToolInput.ts
2563
+ function useToolInput() {
2564
+ const { toolInput } = useMcpApp();
2565
+ return {
2566
+ input: toolInput,
2567
+ hasInput: toolInput !== null
2568
+ };
2569
+ }
2570
+ __name(useToolInput, "useToolInput");
2571
+
2572
+ // src/mcp/useToolInputPartial.ts
2573
+ function useToolInputPartial() {
2574
+ const { toolInputPartial } = useMcpApp();
2575
+ return {
2576
+ partialArgs: toolInputPartial,
2577
+ isStreaming: toolInputPartial !== null
2578
+ };
2579
+ }
2580
+ __name(useToolInputPartial, "useToolInputPartial");
2581
+ function useToolSubscription(toolName, options = {}) {
2582
+ const { interval = 1e4, enabled = true, args = {} } = options;
2583
+ const toolHook = useTool(toolName);
2584
+ const intervalRef = useRef(null);
2585
+ const [isPolling, setIsPolling] = useState(false);
2586
+ const stop = useCallback(() => {
2587
+ if (intervalRef.current) {
2588
+ clearInterval(intervalRef.current);
2589
+ intervalRef.current = null;
2590
+ }
2591
+ setIsPolling(false);
2592
+ }, []);
2593
+ const start = useCallback(() => {
2594
+ if (intervalRef.current) {
2595
+ clearInterval(intervalRef.current);
2596
+ intervalRef.current = null;
2597
+ }
2598
+ setIsPolling(true);
2599
+ toolHook.call(args).catch(() => {
2600
+ });
2601
+ intervalRef.current = setInterval(() => {
2602
+ toolHook.call(args).catch(() => {
2603
+ });
2604
+ }, interval);
2605
+ }, [
2606
+ toolHook.call,
2607
+ args,
2608
+ interval
2609
+ ]);
2610
+ const refresh = useCallback(async () => {
2611
+ return toolHook.call(args);
2612
+ }, [
2613
+ toolHook.call,
2614
+ args
2615
+ ]);
2616
+ useEffect(() => {
2617
+ if (enabled) {
2618
+ start();
2619
+ }
2620
+ return () => stop();
2621
+ }, [
2622
+ enabled,
2623
+ start,
2624
+ stop
2625
+ ]);
2626
+ return {
2627
+ result: toolHook.result,
2628
+ loading: toolHook.loading,
2629
+ error: toolHook.error,
2630
+ start,
2631
+ stop,
2632
+ isPolling,
2633
+ refresh
2634
+ };
2635
+ }
2636
+ __name(useToolSubscription, "useToolSubscription");
2637
+ function useAuth() {
2638
+ const { callTool, isConnected } = useGptApp();
2639
+ const [isAuthenticated, setIsAuthenticated] = useState(false);
2640
+ const [user, setUser] = useState(null);
2641
+ const [loading, setLoading] = useState(false);
2642
+ const [error, setError] = useState(null);
2643
+ const checkAuthStatus = useCallback(async () => {
2644
+ if (!isConnected) return;
2645
+ try {
2646
+ const result = await callTool("getAuthStatus", {});
2647
+ if (result && result.user) {
2648
+ setIsAuthenticated(true);
2649
+ setUser(result.user);
2650
+ } else {
2651
+ setIsAuthenticated(false);
2652
+ setUser(null);
2653
+ }
2654
+ } catch (err) {
2655
+ setIsAuthenticated(false);
2656
+ setUser(null);
2657
+ }
2658
+ }, [
2659
+ callTool,
2660
+ isConnected
2661
+ ]);
2662
+ const triggerAuth = useCallback(async () => {
2663
+ if (!isConnected) {
2664
+ setError(new Error("Not connected to ChatGPT"));
2665
+ return;
2666
+ }
2667
+ setLoading(true);
2668
+ setError(null);
2669
+ try {
2670
+ const result = await callTool("checkAuth", {});
2671
+ if (result && result.user) {
2672
+ setIsAuthenticated(true);
2673
+ setUser(result.user);
2674
+ } else if (result && result.success) {
2675
+ setIsAuthenticated(true);
2676
+ await checkAuthStatus();
2677
+ }
2678
+ } catch (err) {
2679
+ setError(err);
2680
+ } finally {
2681
+ setLoading(false);
2682
+ }
2683
+ }, [
2684
+ callTool,
2685
+ isConnected,
2686
+ checkAuthStatus
2687
+ ]);
2688
+ const clearAuth = useCallback(() => {
2689
+ setIsAuthenticated(false);
2690
+ setUser(null);
2691
+ setError(null);
2692
+ }, []);
2693
+ useEffect(() => {
2694
+ if (isConnected) {
2695
+ checkAuthStatus().catch(() => {
2696
+ });
2697
+ }
2698
+ }, [
2699
+ isConnected,
2700
+ checkAuthStatus
2701
+ ]);
2702
+ return {
2703
+ isAuthenticated,
2704
+ user,
2705
+ loading,
2706
+ error,
2707
+ triggerAuth,
2708
+ clearAuth
2709
+ };
2710
+ }
2711
+ __name(useAuth, "useAuth");
2712
+ var SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
2713
+ function useOpenAiGlobal(key) {
2714
+ return useSyncExternalStore((onChange) => {
2715
+ const handleSetGlobal = /* @__PURE__ */ __name((event) => {
2716
+ const customEvent = event;
2717
+ const value = customEvent.detail?.globals?.[key];
2718
+ if (value !== void 0) {
2719
+ onChange();
2720
+ }
2721
+ }, "handleSetGlobal");
2722
+ window.addEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal, {
2723
+ passive: true
2724
+ });
2725
+ return () => {
2726
+ window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);
2727
+ };
2728
+ }, () => window.openai?.[key]);
2729
+ }
2730
+ __name(useOpenAiGlobal, "useOpenAiGlobal");
2731
+
2732
+ // src/mcp/useToolData.ts
2733
+ function useToolOutput() {
2734
+ return useOpenAiGlobal("toolOutput");
2735
+ }
2736
+ __name(useToolOutput, "useToolOutput");
2737
+ function useToolResponseMetadata() {
2738
+ return useOpenAiGlobal("toolResponseMetadata");
2739
+ }
2740
+ __name(useToolResponseMetadata, "useToolResponseMetadata");
2741
+ function useToolInput2() {
2742
+ return useOpenAiGlobal("toolInput");
2743
+ }
2744
+ __name(useToolInput2, "useToolInput");
2745
+ function useWidgetState(initialState) {
2746
+ const rawState = useOpenAiGlobal("widgetState");
2747
+ const resolvedInitial = rawState ?? (typeof initialState === "function" ? initialState() : initialState);
2748
+ const setWidgetState = useCallback((newStateOrUpdater) => {
2749
+ if (!window.openai?.setWidgetState) {
2750
+ console.warn("window.openai.setWidgetState is not available");
2751
+ return;
2752
+ }
2753
+ const current = window.openai.widgetState ?? resolvedInitial;
2754
+ const next = typeof newStateOrUpdater === "function" ? newStateOrUpdater(current) : newStateOrUpdater;
2755
+ window.openai.setWidgetState(next);
2756
+ }, [
2757
+ resolvedInitial
2758
+ ]);
2759
+ return [
2760
+ resolvedInitial,
2761
+ setWidgetState
2762
+ ];
2763
+ }
2764
+ __name(useWidgetState, "useWidgetState");
2765
+
2766
+ // src/types/mcp-types.ts
2767
+ function normalizeToolBinding(tool) {
2768
+ if (typeof tool === "string") {
2769
+ return {
2770
+ name: tool
2771
+ };
2772
+ }
2773
+ return tool;
2774
+ }
2775
+ __name(normalizeToolBinding, "normalizeToolBinding");
2776
+ var DEFAULT_RESULT_CONFIG = {
2777
+ display: "none",
2778
+ autoDismiss: 5e3
2779
+ };
2780
+ var INITIAL_TOOL_STATE = {
2781
+ state: "idle",
2782
+ loading: false,
2783
+ result: null,
2784
+ error: null,
2785
+ hasResult: false
2786
+ };
2787
+ function CardTitle({ className, ...props }) {
2788
+ return /* @__PURE__ */ React26.createElement("div", {
2789
+ "data-slot": "card-title",
2790
+ className: cn("leading-none font-semibold", className),
2791
+ ...props
2792
+ });
2793
+ }
2794
+ __name(CardTitle, "CardTitle");
2795
+ function CardDescription({ className, ...props }) {
2796
+ return /* @__PURE__ */ React26.createElement("div", {
2797
+ "data-slot": "card-description",
2798
+ className: cn("text-muted-foreground text-sm", className),
2799
+ ...props
2800
+ });
2801
+ }
2802
+ __name(CardDescription, "CardDescription");
2803
+ var Form = FormProvider;
2804
+ var FormFieldContext = /* @__PURE__ */ React26.createContext({});
2805
+ var FormField = /* @__PURE__ */ __name(({ ...props }) => {
2806
+ return /* @__PURE__ */ React26.createElement(FormFieldContext.Provider, {
2807
+ value: {
2808
+ name: props.name
2809
+ }
2810
+ }, /* @__PURE__ */ React26.createElement(Controller, props));
2811
+ }, "FormField");
2812
+ var useFormField = /* @__PURE__ */ __name(() => {
2813
+ const fieldContext = React26.useContext(FormFieldContext);
2814
+ const itemContext = React26.useContext(FormItemContext);
2815
+ const { getFieldState } = useFormContext();
2816
+ const formState = useFormState({
2817
+ name: fieldContext.name
2818
+ });
2819
+ const fieldState = getFieldState(fieldContext.name, formState);
2820
+ if (!fieldContext) {
2821
+ throw new Error("useFormField should be used within <FormField>");
2822
+ }
2823
+ const { id } = itemContext;
2824
+ return {
2825
+ id,
2826
+ name: fieldContext.name,
2827
+ formItemId: `${id}-form-item`,
2828
+ formDescriptionId: `${id}-form-item-description`,
2829
+ formMessageId: `${id}-form-item-message`,
2830
+ ...fieldState
2831
+ };
2832
+ }, "useFormField");
2833
+ var FormItemContext = /* @__PURE__ */ React26.createContext({});
2834
+ function FormItem({ className, ...props }) {
2835
+ const id = React26.useId();
2836
+ return /* @__PURE__ */ React26.createElement(FormItemContext.Provider, {
2837
+ value: {
2838
+ id
2839
+ }
2840
+ }, /* @__PURE__ */ React26.createElement("div", {
2841
+ "data-slot": "form-item",
2842
+ className: cn("grid gap-2", className),
2843
+ ...props
2844
+ }));
2845
+ }
2846
+ __name(FormItem, "FormItem");
2847
+ function FormLabel({ className, ...props }) {
2848
+ const { error, formItemId } = useFormField();
2849
+ return /* @__PURE__ */ React26.createElement(Label2, {
2850
+ "data-slot": "form-label",
2851
+ "data-error": !!error,
2852
+ className: cn("data-[error=true]:text-destructive", className),
2853
+ htmlFor: formItemId,
2854
+ ...props
2855
+ });
2856
+ }
2857
+ __name(FormLabel, "FormLabel");
2858
+ function FormControl({ ...props }) {
2859
+ const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
2860
+ return /* @__PURE__ */ React26.createElement(Slot, {
2861
+ "data-slot": "form-control",
2862
+ id: formItemId,
2863
+ "aria-describedby": !error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`,
2864
+ "aria-invalid": !!error,
2865
+ ...props
2866
+ });
2867
+ }
2868
+ __name(FormControl, "FormControl");
2869
+ function FormDescription({ className, ...props }) {
2870
+ const { formDescriptionId } = useFormField();
2871
+ return /* @__PURE__ */ React26.createElement("p", {
2872
+ "data-slot": "form-description",
2873
+ id: formDescriptionId,
2874
+ className: cn("text-muted-foreground text-sm", className),
2875
+ ...props
2876
+ });
2877
+ }
2878
+ __name(FormDescription, "FormDescription");
2879
+ function FormMessage({ className, ...props }) {
2880
+ const { error, formMessageId } = useFormField();
2881
+ const body = error ? String(error?.message ?? "") : props.children;
2882
+ if (!body) {
2883
+ return null;
2884
+ }
2885
+ return /* @__PURE__ */ React26.createElement("p", {
2886
+ "data-slot": "form-message",
2887
+ id: formMessageId,
2888
+ className: cn("text-destructive text-sm", className),
2889
+ ...props
2890
+ }, body);
2891
+ }
2892
+ __name(FormMessage, "FormMessage");
2893
+ var badgeVariants = cva("inline-flex items-center justify-center rounded-full border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden", {
2894
+ variants: {
2895
+ variant: {
2896
+ default: "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
2897
+ secondary: "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
2898
+ destructive: "border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
2899
+ outline: "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"
2900
+ }
2901
+ },
2902
+ defaultVariants: {
2903
+ variant: "default"
2904
+ }
2905
+ });
2906
+ function Badge({ className, variant, asChild = false, ...props }) {
2907
+ const Comp = asChild ? Slot : "span";
2908
+ return /* @__PURE__ */ React26.createElement(Comp, {
2909
+ "data-slot": "badge",
2910
+ className: cn(badgeVariants({
2911
+ variant
2912
+ }), className),
2913
+ ...props
2914
+ });
2915
+ }
2916
+ __name(Badge, "Badge");
2917
+ function TabsList({ className, ...props }) {
2918
+ return /* @__PURE__ */ React26.createElement(TabsPrimitive2.List, {
2919
+ "data-slot": "tabs-list",
2920
+ className: cn("bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]", className),
2921
+ ...props
2922
+ });
2923
+ }
2924
+ __name(TabsList, "TabsList");
2925
+ function TabsTrigger({ className, ...props }) {
2926
+ return /* @__PURE__ */ React26.createElement(TabsPrimitive2.Trigger, {
2927
+ "data-slot": "tabs-trigger",
2928
+ className: cn("data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className),
2929
+ ...props
2930
+ });
2931
+ }
2932
+ __name(TabsTrigger, "TabsTrigger");
2933
+ function TabsContent({ className, ...props }) {
2934
+ return /* @__PURE__ */ React26.createElement(TabsPrimitive2.Content, {
2935
+ "data-slot": "tabs-content",
2936
+ className: cn("flex-1 outline-none", className),
2937
+ ...props
2938
+ });
2939
+ }
2940
+ __name(TabsContent, "TabsContent");
2941
+ function Separator2({ className, orientation = "horizontal", decorative = true, ...props }) {
2942
+ return /* @__PURE__ */ React26.createElement(SeparatorPrimitive.Root, {
2943
+ "data-slot": "separator",
2944
+ decorative,
2945
+ orientation,
2946
+ className: cn("bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px", className),
2947
+ ...props
2948
+ });
2949
+ }
2950
+ __name(Separator2, "Separator");
2951
+ function ScrollArea({ className, children, ...props }) {
2952
+ return /* @__PURE__ */ React26.createElement(ScrollAreaPrimitive.Root, {
2953
+ "data-slot": "scroll-area",
2954
+ className: cn("relative", className),
2955
+ ...props
2956
+ }, /* @__PURE__ */ React26.createElement(ScrollAreaPrimitive.Viewport, {
2957
+ "data-slot": "scroll-area-viewport",
2958
+ className: "focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1"
2959
+ }, children), /* @__PURE__ */ React26.createElement(ScrollBar, null), /* @__PURE__ */ React26.createElement(ScrollAreaPrimitive.Corner, null));
2960
+ }
2961
+ __name(ScrollArea, "ScrollArea");
2962
+ function ScrollBar({ className, orientation = "vertical", ...props }) {
2963
+ return /* @__PURE__ */ React26.createElement(ScrollAreaPrimitive.ScrollAreaScrollbar, {
2964
+ "data-slot": "scroll-area-scrollbar",
2965
+ orientation,
2966
+ className: cn("flex touch-none p-px transition-colors select-none", orientation === "vertical" && "h-full w-2.5 border-l border-l-transparent", orientation === "horizontal" && "h-2.5 flex-col border-t border-t-transparent", className),
2967
+ ...props
2968
+ }, /* @__PURE__ */ React26.createElement(ScrollAreaPrimitive.ScrollAreaThumb, {
2969
+ "data-slot": "scroll-area-thumb",
2970
+ className: "bg-border relative flex-1 rounded-full"
2971
+ }));
2972
+ }
2973
+ __name(ScrollBar, "ScrollBar");
2974
+ function DropdownMenu({ ...props }) {
2975
+ return /* @__PURE__ */ React26.createElement(DropdownMenuPrimitive.Root, {
2976
+ "data-slot": "dropdown-menu",
2977
+ ...props
2978
+ });
2979
+ }
2980
+ __name(DropdownMenu, "DropdownMenu");
2981
+ function DropdownMenuPortal({ ...props }) {
2982
+ return /* @__PURE__ */ React26.createElement(DropdownMenuPrimitive.Portal, {
2983
+ "data-slot": "dropdown-menu-portal",
2984
+ ...props
2985
+ });
2986
+ }
2987
+ __name(DropdownMenuPortal, "DropdownMenuPortal");
2988
+ function DropdownMenuTrigger({ ...props }) {
2989
+ return /* @__PURE__ */ React26.createElement(DropdownMenuPrimitive.Trigger, {
2990
+ "data-slot": "dropdown-menu-trigger",
2991
+ ...props
2992
+ });
2993
+ }
2994
+ __name(DropdownMenuTrigger, "DropdownMenuTrigger");
2995
+ function DropdownMenuContent({ className, sideOffset = 4, ...props }) {
2996
+ return /* @__PURE__ */ React26.createElement(DropdownMenuPrimitive.Portal, null, /* @__PURE__ */ React26.createElement(DropdownMenuPrimitive.Content, {
2997
+ "data-slot": "dropdown-menu-content",
2998
+ sideOffset,
2999
+ className: cn("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md", className),
3000
+ ...props
3001
+ }));
3002
+ }
3003
+ __name(DropdownMenuContent, "DropdownMenuContent");
3004
+ function DropdownMenuGroup({ ...props }) {
3005
+ return /* @__PURE__ */ React26.createElement(DropdownMenuPrimitive.Group, {
3006
+ "data-slot": "dropdown-menu-group",
3007
+ ...props
3008
+ });
3009
+ }
3010
+ __name(DropdownMenuGroup, "DropdownMenuGroup");
3011
+ function DropdownMenuItem({ className, inset, variant = "default", ...props }) {
3012
+ return /* @__PURE__ */ React26.createElement(DropdownMenuPrimitive.Item, {
3013
+ "data-slot": "dropdown-menu-item",
3014
+ "data-inset": inset,
3015
+ "data-variant": variant,
3016
+ className: cn("focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className),
3017
+ ...props
3018
+ });
3019
+ }
3020
+ __name(DropdownMenuItem, "DropdownMenuItem");
3021
+ function DropdownMenuCheckboxItem({ className, children, checked, ...props }) {
3022
+ return /* @__PURE__ */ React26.createElement(DropdownMenuPrimitive.CheckboxItem, {
3023
+ "data-slot": "dropdown-menu-checkbox-item",
3024
+ className: cn("focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className),
3025
+ checked,
3026
+ ...props
3027
+ }, /* @__PURE__ */ React26.createElement("span", {
3028
+ className: "pointer-events-none absolute left-2 flex size-3.5 items-center justify-center"
3029
+ }, /* @__PURE__ */ React26.createElement(DropdownMenuPrimitive.ItemIndicator, null, /* @__PURE__ */ React26.createElement(CheckIcon, {
3030
+ className: "size-4"
3031
+ }))), children);
3032
+ }
3033
+ __name(DropdownMenuCheckboxItem, "DropdownMenuCheckboxItem");
3034
+ function DropdownMenuRadioGroup({ ...props }) {
3035
+ return /* @__PURE__ */ React26.createElement(DropdownMenuPrimitive.RadioGroup, {
3036
+ "data-slot": "dropdown-menu-radio-group",
3037
+ ...props
3038
+ });
3039
+ }
3040
+ __name(DropdownMenuRadioGroup, "DropdownMenuRadioGroup");
3041
+ function DropdownMenuRadioItem({ className, children, ...props }) {
3042
+ return /* @__PURE__ */ React26.createElement(DropdownMenuPrimitive.RadioItem, {
3043
+ "data-slot": "dropdown-menu-radio-item",
3044
+ className: cn("focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className),
3045
+ ...props
3046
+ }, /* @__PURE__ */ React26.createElement("span", {
3047
+ className: "pointer-events-none absolute left-2 flex size-3.5 items-center justify-center"
3048
+ }, /* @__PURE__ */ React26.createElement(DropdownMenuPrimitive.ItemIndicator, null, /* @__PURE__ */ React26.createElement(CircleIcon, {
3049
+ className: "size-2 fill-current"
3050
+ }))), children);
3051
+ }
3052
+ __name(DropdownMenuRadioItem, "DropdownMenuRadioItem");
3053
+ function DropdownMenuLabel({ className, inset, ...props }) {
3054
+ return /* @__PURE__ */ React26.createElement(DropdownMenuPrimitive.Label, {
3055
+ "data-slot": "dropdown-menu-label",
3056
+ "data-inset": inset,
3057
+ className: cn("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8", className),
3058
+ ...props
3059
+ });
3060
+ }
3061
+ __name(DropdownMenuLabel, "DropdownMenuLabel");
3062
+ function DropdownMenuSeparator({ className, ...props }) {
3063
+ return /* @__PURE__ */ React26.createElement(DropdownMenuPrimitive.Separator, {
3064
+ "data-slot": "dropdown-menu-separator",
3065
+ className: cn("bg-border -mx-1 my-1 h-px", className),
3066
+ ...props
3067
+ });
3068
+ }
3069
+ __name(DropdownMenuSeparator, "DropdownMenuSeparator");
3070
+ function DropdownMenuShortcut({ className, ...props }) {
3071
+ return /* @__PURE__ */ React26.createElement("span", {
3072
+ "data-slot": "dropdown-menu-shortcut",
3073
+ className: cn("text-muted-foreground ml-auto text-xs tracking-widest", className),
3074
+ ...props
3075
+ });
3076
+ }
3077
+ __name(DropdownMenuShortcut, "DropdownMenuShortcut");
3078
+ function DropdownMenuSub({ ...props }) {
3079
+ return /* @__PURE__ */ React26.createElement(DropdownMenuPrimitive.Sub, {
3080
+ "data-slot": "dropdown-menu-sub",
3081
+ ...props
3082
+ });
3083
+ }
3084
+ __name(DropdownMenuSub, "DropdownMenuSub");
3085
+ function DropdownMenuSubTrigger({ className, inset, children, ...props }) {
3086
+ return /* @__PURE__ */ React26.createElement(DropdownMenuPrimitive.SubTrigger, {
3087
+ "data-slot": "dropdown-menu-sub-trigger",
3088
+ "data-inset": inset,
3089
+ className: cn("focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className),
3090
+ ...props
3091
+ }, children, /* @__PURE__ */ React26.createElement(ChevronRightIcon, {
3092
+ className: "ml-auto size-4"
3093
+ }));
3094
+ }
3095
+ __name(DropdownMenuSubTrigger, "DropdownMenuSubTrigger");
3096
+ function DropdownMenuSubContent({ className, ...props }) {
3097
+ return /* @__PURE__ */ React26.createElement(DropdownMenuPrimitive.SubContent, {
3098
+ "data-slot": "dropdown-menu-sub-content",
3099
+ className: cn("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg", className),
3100
+ ...props
3101
+ });
3102
+ }
3103
+ __name(DropdownMenuSubContent, "DropdownMenuSubContent");
3104
+ function TooltipProvider({ delayDuration = 0, ...props }) {
3105
+ return /* @__PURE__ */ React26.createElement(TooltipPrimitive.Provider, {
3106
+ "data-slot": "tooltip-provider",
3107
+ delayDuration,
3108
+ ...props
3109
+ });
3110
+ }
3111
+ __name(TooltipProvider, "TooltipProvider");
3112
+ function Tooltip({ ...props }) {
3113
+ return /* @__PURE__ */ React26.createElement(TooltipProvider, null, /* @__PURE__ */ React26.createElement(TooltipPrimitive.Root, {
3114
+ "data-slot": "tooltip",
3115
+ ...props
3116
+ }));
3117
+ }
3118
+ __name(Tooltip, "Tooltip");
3119
+ function TooltipTrigger({ ...props }) {
3120
+ return /* @__PURE__ */ React26.createElement(TooltipPrimitive.Trigger, {
3121
+ "data-slot": "tooltip-trigger",
3122
+ ...props
3123
+ });
3124
+ }
3125
+ __name(TooltipTrigger, "TooltipTrigger");
3126
+ function TooltipContent({ className, sideOffset = 0, children, ...props }) {
3127
+ return /* @__PURE__ */ React26.createElement(TooltipPrimitive.Portal, null, /* @__PURE__ */ React26.createElement(TooltipPrimitive.Content, {
3128
+ "data-slot": "tooltip-content",
3129
+ sideOffset,
3130
+ className: cn("bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance", className),
3131
+ ...props
3132
+ }, children, /* @__PURE__ */ React26.createElement(TooltipPrimitive.Arrow, {
3133
+ className: "bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"
3134
+ })));
3135
+ }
3136
+ __name(TooltipContent, "TooltipContent");
3137
+ function DataGrid({ data, columns, searchable = false, searchPlaceholder = "Search...", onRowClick, loading = false, emptyMessage = "No data", className }) {
3138
+ const [sorting, setSorting] = useState([]);
3139
+ const [globalFilter, setGlobalFilter] = useState("");
3140
+ const tableColumns = useMemo(() => columns.map((col) => ({
3141
+ id: String(col.key),
3142
+ accessorKey: col.key,
3143
+ header: col.header,
3144
+ cell: col.cell ? ({ getValue, row }) => col.cell(getValue(), row.original) : ({ getValue }) => String(getValue() ?? ""),
3145
+ enableSorting: col.sortable ?? true,
3146
+ size: typeof col.width === "number" ? col.width : void 0
3147
+ })), [
3148
+ columns
3149
+ ]);
3150
+ const table = useReactTable({
3151
+ data,
3152
+ columns: tableColumns,
3153
+ state: {
3154
+ sorting,
3155
+ globalFilter
3156
+ },
3157
+ onSortingChange: setSorting,
3158
+ onGlobalFilterChange: setGlobalFilter,
3159
+ getCoreRowModel: getCoreRowModel(),
3160
+ getSortedRowModel: getSortedRowModel(),
3161
+ getFilteredRowModel: getFilteredRowModel()
3162
+ });
3163
+ return /* @__PURE__ */ React26__default.createElement("div", {
3164
+ className: clsx("lui-datagrid", className)
3165
+ }, searchable && /* @__PURE__ */ React26__default.createElement("div", {
3166
+ className: "lui-datagrid-search"
3167
+ }, /* @__PURE__ */ React26__default.createElement("input", {
3168
+ type: "text",
3169
+ value: globalFilter,
3170
+ onChange: /* @__PURE__ */ __name((e) => setGlobalFilter(e.target.value), "onChange"),
3171
+ placeholder: searchPlaceholder,
3172
+ className: "lui-datagrid-search-input"
3173
+ })), /* @__PURE__ */ React26__default.createElement("div", {
3174
+ className: "lui-datagrid-container"
3175
+ }, /* @__PURE__ */ React26__default.createElement("table", {
3176
+ className: "lui-datagrid-table"
3177
+ }, /* @__PURE__ */ React26__default.createElement("thead", null, table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ React26__default.createElement("tr", {
3178
+ key: headerGroup.id
3179
+ }, headerGroup.headers.map((header) => /* @__PURE__ */ React26__default.createElement("th", {
3180
+ key: header.id,
3181
+ className: clsx("lui-datagrid-th", header.column.getCanSort() && "lui-datagrid-th--sortable"),
3182
+ onClick: header.column.getToggleSortingHandler(),
3183
+ style: {
3184
+ width: header.column.getSize()
3185
+ }
3186
+ }, /* @__PURE__ */ React26__default.createElement("div", {
3187
+ className: "lui-datagrid-th-content"
3188
+ }, flexRender(header.column.columnDef.header, header.getContext()), header.column.getIsSorted() && /* @__PURE__ */ React26__default.createElement("span", {
3189
+ className: "lui-datagrid-sort-icon"
3190
+ }, header.column.getIsSorted() === "asc" ? "\u2191" : "\u2193"))))))), /* @__PURE__ */ React26__default.createElement("tbody", null, loading ? /* @__PURE__ */ React26__default.createElement("tr", null, /* @__PURE__ */ React26__default.createElement("td", {
3191
+ colSpan: columns.length,
3192
+ className: "lui-datagrid-loading"
3193
+ }, "Loading...")) : table.getRowModel().rows.length === 0 ? /* @__PURE__ */ React26__default.createElement("tr", null, /* @__PURE__ */ React26__default.createElement("td", {
3194
+ colSpan: columns.length,
3195
+ className: "lui-datagrid-empty"
3196
+ }, emptyMessage)) : table.getRowModel().rows.map((row) => /* @__PURE__ */ React26__default.createElement("tr", {
3197
+ key: row.id,
3198
+ className: clsx("lui-datagrid-row", onRowClick && "lui-datagrid-row--clickable"),
3199
+ onClick: /* @__PURE__ */ __name(() => onRowClick?.(row.original), "onClick")
3200
+ }, row.getVisibleCells().map((cell) => /* @__PURE__ */ React26__default.createElement("td", {
3201
+ key: cell.id,
3202
+ className: "lui-datagrid-td"
3203
+ }, flexRender(cell.column.columnDef.cell, cell.getContext())))))))));
3204
+ }
3205
+ __name(DataGrid, "DataGrid");
3206
+ Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, BarElement, ArcElement, Title, Tooltip$1, Legend);
3207
+ function Chart({ type, data, options, height = 300, width = "100%", className }) {
3208
+ const defaultOptions = {
3209
+ responsive: true,
3210
+ maintainAspectRatio: false,
3211
+ plugins: {
3212
+ legend: {
3213
+ display: true,
3214
+ position: "top",
3215
+ labels: {
3216
+ usePointStyle: true,
3217
+ padding: 16
3218
+ }
3219
+ },
3220
+ tooltip: {
3221
+ mode: "index",
3222
+ intersect: false,
3223
+ backgroundColor: "rgba(15, 23, 42, 0.9)",
3224
+ titleColor: "#f1f5f9",
3225
+ bodyColor: "#cbd5e1",
3226
+ borderColor: "#334155",
3227
+ borderWidth: 1,
3228
+ cornerRadius: 8,
3229
+ padding: 12
3230
+ }
3231
+ },
3232
+ scales: type !== "pie" && type !== "doughnut" ? {
3233
+ x: {
3234
+ grid: {
3235
+ color: "rgba(226, 232, 240, 0.5)"
3236
+ },
3237
+ ticks: {
3238
+ color: "#64748b"
3239
+ }
3240
+ },
3241
+ y: {
3242
+ grid: {
3243
+ color: "rgba(226, 232, 240, 0.5)"
3244
+ },
3245
+ ticks: {
3246
+ color: "#64748b"
3247
+ }
3248
+ }
3249
+ } : void 0
3250
+ };
3251
+ const mergedOptions = {
3252
+ ...defaultOptions,
3253
+ ...options,
3254
+ plugins: {
3255
+ ...defaultOptions.plugins,
3256
+ ...options?.plugins
3257
+ }
3258
+ };
3259
+ return /* @__PURE__ */ React26__default.createElement("div", {
3260
+ className: clsx("lui-chart", className),
3261
+ style: {
3262
+ height,
3263
+ width
3264
+ }
3265
+ }, /* @__PURE__ */ React26__default.createElement(Chart$2, {
3266
+ type,
3267
+ data,
3268
+ options: mergedOptions
3269
+ }));
3270
+ }
3271
+ __name(Chart, "Chart");
3272
+ function AppShell({ header, sidebar, footer, sidebarPosition = "left", sidebarWidth = 240, autoResize = true, padding = "md", className, children, ...props }) {
3273
+ const containerRef = useRef(null);
3274
+ const { app } = useMcpApp();
3275
+ useEffect(() => {
3276
+ if (!autoResize || !containerRef.current) return;
3277
+ if (!app) return;
3278
+ let lastWidth = 0;
3279
+ let lastHeight = 0;
3280
+ let scheduled = false;
3281
+ const sendSizeChanged = /* @__PURE__ */ __name(() => {
3282
+ if (scheduled) return;
3283
+ scheduled = true;
3284
+ requestAnimationFrame(() => {
3285
+ scheduled = false;
3286
+ if (!containerRef.current) return;
3287
+ const rect = containerRef.current.getBoundingClientRect();
3288
+ const width = Math.ceil(rect.width);
3289
+ const height = Math.ceil(rect.height);
3290
+ if (width !== lastWidth || height !== lastHeight) {
3291
+ lastWidth = width;
3292
+ lastHeight = height;
3293
+ app.sendSizeChanged({
3294
+ width,
3295
+ height
3296
+ });
3297
+ }
3298
+ });
3299
+ }, "sendSizeChanged");
3300
+ const resizeObserver = new ResizeObserver(sendSizeChanged);
3301
+ resizeObserver.observe(containerRef.current);
3302
+ sendSizeChanged();
3303
+ return () => {
3304
+ resizeObserver.disconnect();
3305
+ };
3306
+ }, [
3307
+ autoResize,
3308
+ app
3309
+ ]);
3310
+ const sidebarStyle = {
3311
+ width: typeof sidebarWidth === "number" ? `${sidebarWidth}px` : sidebarWidth,
3312
+ flexShrink: 0
3313
+ };
3314
+ return /* @__PURE__ */ React26__default.createElement("div", {
3315
+ ref: containerRef,
3316
+ className: clsx("lui-app-shell", `lui-app-shell--padding-${padding}`, className),
3317
+ ...props
3318
+ }, header && /* @__PURE__ */ React26__default.createElement("header", {
3319
+ className: "lui-app-shell-header"
3320
+ }, header), /* @__PURE__ */ React26__default.createElement("div", {
3321
+ className: "lui-app-shell-body"
3322
+ }, sidebar && sidebarPosition === "left" && /* @__PURE__ */ React26__default.createElement("aside", {
3323
+ className: "lui-app-shell-sidebar",
3324
+ style: sidebarStyle
3325
+ }, sidebar), /* @__PURE__ */ React26__default.createElement("main", {
3326
+ className: "lui-app-shell-main"
3327
+ }, children), sidebar && sidebarPosition === "right" && /* @__PURE__ */ React26__default.createElement("aside", {
3328
+ className: "lui-app-shell-sidebar",
3329
+ style: sidebarStyle
3330
+ }, sidebar)), footer && /* @__PURE__ */ React26__default.createElement("footer", {
3331
+ className: "lui-app-shell-footer"
3332
+ }, footer));
3333
+ }
3334
+ __name(AppShell, "AppShell");
3335
+ function Tabs2({ tabs, defaultValue, value, onValueChange, children, className }) {
3336
+ const defaultTab = defaultValue || tabs[0]?.value;
3337
+ return /* @__PURE__ */ React26__default.createElement(TabsPrimitive2.Root, {
3338
+ className: clsx("lui-tabs", className),
3339
+ defaultValue: defaultTab,
3340
+ value,
3341
+ onValueChange
3342
+ }, /* @__PURE__ */ React26__default.createElement(TabsPrimitive2.List, {
3343
+ className: "lui-tabs-list"
3344
+ }, tabs.map((tab) => /* @__PURE__ */ React26__default.createElement(TabsPrimitive2.Trigger, {
3345
+ key: tab.value,
3346
+ value: tab.value,
3347
+ disabled: tab.disabled,
3348
+ className: "lui-tabs-trigger"
3349
+ }, tab.label))), children);
3350
+ }
3351
+ __name(Tabs2, "Tabs");
3352
+ function TabContent({ value, children, className }) {
3353
+ return /* @__PURE__ */ React26__default.createElement(TabsPrimitive2.Content, {
3354
+ value,
3355
+ className: clsx("lui-tabs-content", className)
3356
+ }, children);
3357
+ }
3358
+ __name(TabContent, "TabContent");
3359
+ function Modal({ open, defaultOpen, onOpenChange, title, description, children, className, trigger }) {
3360
+ return /* @__PURE__ */ React26__default.createElement(DialogPrimitive.Root, {
3361
+ open,
3362
+ defaultOpen,
3363
+ onOpenChange
3364
+ }, trigger && /* @__PURE__ */ React26__default.createElement(DialogPrimitive.Trigger, {
3365
+ asChild: true
3366
+ }, trigger), /* @__PURE__ */ React26__default.createElement(DialogPrimitive.Portal, null, /* @__PURE__ */ React26__default.createElement(DialogPrimitive.Overlay, {
3367
+ className: "lui-modal-overlay"
3368
+ }), /* @__PURE__ */ React26__default.createElement(DialogPrimitive.Content, {
3369
+ className: clsx("lui-modal-content", className)
3370
+ }, title && /* @__PURE__ */ React26__default.createElement(DialogPrimitive.Title, {
3371
+ className: "lui-modal-title"
3372
+ }, title), description && /* @__PURE__ */ React26__default.createElement(DialogPrimitive.Description, {
3373
+ className: "lui-modal-description"
3374
+ }, description), children, /* @__PURE__ */ React26__default.createElement(DialogPrimitive.Close, {
3375
+ className: "lui-modal-close",
3376
+ "aria-label": "Close"
3377
+ }, /* @__PURE__ */ React26__default.createElement(CloseIcon, null)))));
3378
+ }
3379
+ __name(Modal, "Modal");
3380
+ function CloseIcon() {
3381
+ return /* @__PURE__ */ React26__default.createElement("svg", {
3382
+ width: "14",
3383
+ height: "14",
3384
+ viewBox: "0 0 14 14",
3385
+ fill: "none"
3386
+ }, /* @__PURE__ */ React26__default.createElement("path", {
3387
+ d: "M3.5 3.5L10.5 10.5M10.5 3.5L3.5 10.5",
3388
+ stroke: "currentColor",
3389
+ strokeWidth: "1.5",
3390
+ strokeLinecap: "round"
3391
+ }));
3392
+ }
3393
+ __name(CloseIcon, "CloseIcon");
3394
+ function CodeBlock({ code, language = "text", showLineNumbers = false, copyable = true, className }) {
3395
+ const [copied, setCopied] = React26__default.useState(false);
3396
+ const handleCopy = /* @__PURE__ */ __name(async () => {
3397
+ await navigator.clipboard.writeText(code);
3398
+ setCopied(true);
3399
+ setTimeout(() => setCopied(false), 2e3);
3400
+ }, "handleCopy");
3401
+ return /* @__PURE__ */ React26__default.createElement("div", {
3402
+ className: clsx("lui-code-block", className)
3403
+ }, copyable && /* @__PURE__ */ React26__default.createElement("button", {
3404
+ type: "button",
3405
+ className: "lui-code-block-copy",
3406
+ onClick: handleCopy,
3407
+ "aria-label": copied ? "Copied!" : "Copy code"
3408
+ }, copied ? /* @__PURE__ */ React26__default.createElement("svg", {
3409
+ viewBox: "0 0 24 24",
3410
+ fill: "none",
3411
+ stroke: "currentColor",
3412
+ strokeWidth: "2"
3413
+ }, /* @__PURE__ */ React26__default.createElement("polyline", {
3414
+ points: "20,6 9,17 4,12"
3415
+ })) : /* @__PURE__ */ React26__default.createElement("svg", {
3416
+ viewBox: "0 0 24 24",
3417
+ fill: "none",
3418
+ stroke: "currentColor",
3419
+ strokeWidth: "2"
3420
+ }, /* @__PURE__ */ React26__default.createElement("rect", {
3421
+ x: "9",
3422
+ y: "9",
3423
+ width: "13",
3424
+ height: "13",
3425
+ rx: "2",
3426
+ ry: "2"
3427
+ }), /* @__PURE__ */ React26__default.createElement("path", {
3428
+ d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"
3429
+ }))), /* @__PURE__ */ React26__default.createElement(Highlight, {
3430
+ theme: themes.nightOwl,
3431
+ code: code.trim(),
3432
+ language
3433
+ }, ({ className: hlClassName, style, tokens, getLineProps, getTokenProps }) => /* @__PURE__ */ React26__default.createElement("pre", {
3434
+ className: clsx("lui-code-block-pre", hlClassName),
3435
+ style
3436
+ }, tokens.map((line, i) => /* @__PURE__ */ React26__default.createElement("div", {
3437
+ key: i,
3438
+ ...getLineProps({
3439
+ line
3440
+ })
3441
+ }, showLineNumbers && /* @__PURE__ */ React26__default.createElement("span", {
3442
+ className: "lui-code-block-line-number"
3443
+ }, i + 1), line.map((token, key) => /* @__PURE__ */ React26__default.createElement("span", {
3444
+ key,
3445
+ ...getTokenProps({
3446
+ token
3447
+ })
3448
+ })))))));
3449
+ }
3450
+ __name(CodeBlock, "CodeBlock");
3451
+ var Card2 = /* @__PURE__ */ forwardRef(({ className, variant = "default", padding = "md", interactive = false, children, ...props }, ref) => {
3452
+ return /* @__PURE__ */ React26__default.createElement("div", {
3453
+ ref,
3454
+ className: clsx("lui-card", `lui-card--${variant}`, `lui-card--padding-${padding}`, interactive && "lui-card--interactive", className),
3455
+ ...props
3456
+ }, children);
3457
+ });
3458
+ Card2.displayName = "Card";
3459
+ var CardHeader2 = /* @__PURE__ */ forwardRef(({ className, title, description, action, children, ...props }, ref) => {
3460
+ return /* @__PURE__ */ React26__default.createElement("div", {
3461
+ ref,
3462
+ className: clsx("lui-card-header", className),
3463
+ ...props
3464
+ }, (title || description) && /* @__PURE__ */ React26__default.createElement("div", {
3465
+ className: "lui-card-header__text"
3466
+ }, title && /* @__PURE__ */ React26__default.createElement("h3", {
3467
+ className: "lui-card-header__title"
3468
+ }, title), description && /* @__PURE__ */ React26__default.createElement("p", {
3469
+ className: "lui-card-header__description"
3470
+ }, description)), action && /* @__PURE__ */ React26__default.createElement("div", {
3471
+ className: "lui-card-header__action"
3472
+ }, action), children);
3473
+ });
3474
+ CardHeader2.displayName = "CardHeader";
3475
+ var CardContent2 = /* @__PURE__ */ forwardRef(({ className, children, ...props }, ref) => {
3476
+ return /* @__PURE__ */ React26__default.createElement("div", {
3477
+ ref,
3478
+ className: clsx("lui-card-content", className),
3479
+ ...props
3480
+ }, children);
3481
+ });
3482
+ CardContent2.displayName = "CardContent";
3483
+ var CardFooter2 = /* @__PURE__ */ forwardRef(({ className, children, ...props }, ref) => {
3484
+ return /* @__PURE__ */ React26__default.createElement("div", {
3485
+ ref,
3486
+ className: clsx("lui-card-footer", className),
3487
+ ...props
3488
+ }, children);
3489
+ });
3490
+ CardFooter2.displayName = "CardFooter";
3491
+ var Input2 = /* @__PURE__ */ forwardRef(({ className, label, helperText, error, size = "md", leftElement, rightElement, fullWidth = false, id, ...props }, ref) => {
3492
+ const inputId = id || `input-${Math.random().toString(36).substr(2, 9)}`;
3493
+ const hasError = Boolean(error);
3494
+ return /* @__PURE__ */ React26__default.createElement("div", {
3495
+ className: clsx("lui-input-wrapper", fullWidth && "lui-input-wrapper--full-width", className)
3496
+ }, label && /* @__PURE__ */ React26__default.createElement("label", {
3497
+ htmlFor: inputId,
3498
+ className: "lui-input-label"
3499
+ }, label), /* @__PURE__ */ React26__default.createElement("div", {
3500
+ className: clsx("lui-input-container", `lui-input-container--${size}`, hasError && "lui-input-container--error", leftElement && "lui-input-container--has-left", rightElement && "lui-input-container--has-right")
3501
+ }, leftElement && /* @__PURE__ */ React26__default.createElement("span", {
3502
+ className: "lui-input-element lui-input-element--left"
3503
+ }, leftElement), /* @__PURE__ */ React26__default.createElement("input", {
3504
+ ref,
3505
+ id: inputId,
3506
+ className: "lui-input",
3507
+ "aria-invalid": hasError,
3508
+ "aria-describedby": error ? `${inputId}-error` : helperText ? `${inputId}-helper` : void 0,
3509
+ ...props
3510
+ }), rightElement && /* @__PURE__ */ React26__default.createElement("span", {
3511
+ className: "lui-input-element lui-input-element--right"
3512
+ }, rightElement)), (error || helperText) && /* @__PURE__ */ React26__default.createElement("p", {
3513
+ id: error ? `${inputId}-error` : `${inputId}-helper`,
3514
+ className: clsx("lui-input-message", error && "lui-input-message--error")
3515
+ }, error || helperText));
3516
+ });
3517
+ Input2.displayName = "Input";
3518
+
3519
+ export { ActionButton, Alert, AlertDescription, AlertTitle, AppProvider, AppShell, Badge, Button2 as Button, Card2 as Card, CardContent2 as CardContent, CardDescription, CardFooter2 as CardFooter, CardHeader2 as CardHeader, CardTitle, Chart, Checkbox, CodeBlock, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, DEFAULT_RESULT_CONFIG, DataGrid, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, GPTAppProvider, INITIAL_TOOL_STATE, Input2 as Input, Label2 as Label, Modal, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, Progress, RequireConnection, ResourceView, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator2 as Separator, Skeleton, Slider, StreamingContent, Switch, TabContent, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs2 as Tabs, TabsContent, TabsList, TabsTrigger, Textarea, Toaster, ToolButton, ToolDataGrid, ToolErrorBoundary, ToolForm, ToolInput, ToolProvider, ToolSelect, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, buttonVariants, cn, normalizeToolBinding, useAuth, useFormField, useGptApp, useGptTool, useHostContext, useMcpApp, useMessage, useOpenAiGlobal, useResource, useTool, useToolContext, useToolInput, useToolInputPartial, useToolInput2 as useToolInputSpec, useToolOutput, useToolResponseMetadata, useToolResult, useToolStream, useToolSubscription, useWidgetState };
3520
+ //# sourceMappingURL=index.mjs.map
3521
+ //# sourceMappingURL=index.mjs.map