@leanmcp/ui 0.3.0 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import { __name } from './chunk-KX75VCMM.mjs';
2
2
  export { GPTApp, UIApp, getGPTAppMetadata, getGPTAppUri, getUIAppMetadata, getUIAppUri } from './chunk-KX75VCMM.mjs';
3
3
  import * as React26 from 'react';
4
- import React26__default, { forwardRef, Component, useState, useRef, useCallback, useEffect, createContext, useContext, useMemo } from 'react';
4
+ import React26__default, { forwardRef, Component, useState, useRef, useCallback, useEffect, createContext, useContext, useMemo, useSyncExternalStore } from 'react';
5
5
  import { applyDocumentTheme, applyHostStyleVariables, applyHostFonts, PostMessageTransport, App } from '@modelcontextprotocol/ext-apps';
6
6
  export { App, PostMessageTransport, RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY, applyDocumentTheme, applyHostFonts, applyHostStyleVariables, getDocumentTheme } from '@modelcontextprotocol/ext-apps';
7
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';
@@ -1657,6 +1657,10 @@ function useResource(uri, options = {}) {
1657
1657
  fetchResource
1658
1658
  ]);
1659
1659
  useEffect(() => {
1660
+ if (intervalRef.current) {
1661
+ clearInterval(intervalRef.current);
1662
+ intervalRef.current = null;
1663
+ }
1660
1664
  if (refreshInterval && refreshInterval > 0 && isConnected && !skip) {
1661
1665
  intervalRef.current = setInterval(() => {
1662
1666
  fetchResource().catch(() => {
@@ -2587,7 +2591,10 @@ function useToolSubscription(toolName, options = {}) {
2587
2591
  setIsPolling(false);
2588
2592
  }, []);
2589
2593
  const start = useCallback(() => {
2590
- stop();
2594
+ if (intervalRef.current) {
2595
+ clearInterval(intervalRef.current);
2596
+ intervalRef.current = null;
2597
+ }
2591
2598
  setIsPolling(true);
2592
2599
  toolHook.call(args).catch(() => {
2593
2600
  });
@@ -2598,8 +2605,7 @@ function useToolSubscription(toolName, options = {}) {
2598
2605
  }, [
2599
2606
  toolHook.call,
2600
2607
  args,
2601
- interval,
2602
- stop
2608
+ interval
2603
2609
  ]);
2604
2610
  const refresh = useCallback(async () => {
2605
2611
  return toolHook.call(args);
@@ -2628,6 +2634,59 @@ function useToolSubscription(toolName, options = {}) {
2628
2634
  };
2629
2635
  }
2630
2636
  __name(useToolSubscription, "useToolSubscription");
2637
+ var SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
2638
+ function useOpenAiGlobal(key) {
2639
+ return useSyncExternalStore((onChange) => {
2640
+ const handleSetGlobal = /* @__PURE__ */ __name((event) => {
2641
+ const customEvent = event;
2642
+ const value = customEvent.detail?.globals?.[key];
2643
+ if (value !== void 0) {
2644
+ onChange();
2645
+ }
2646
+ }, "handleSetGlobal");
2647
+ window.addEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal, {
2648
+ passive: true
2649
+ });
2650
+ return () => {
2651
+ window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);
2652
+ };
2653
+ }, () => window.openai?.[key]);
2654
+ }
2655
+ __name(useOpenAiGlobal, "useOpenAiGlobal");
2656
+
2657
+ // src/mcp/useToolData.ts
2658
+ function useToolOutput() {
2659
+ return useOpenAiGlobal("toolOutput");
2660
+ }
2661
+ __name(useToolOutput, "useToolOutput");
2662
+ function useToolResponseMetadata() {
2663
+ return useOpenAiGlobal("toolResponseMetadata");
2664
+ }
2665
+ __name(useToolResponseMetadata, "useToolResponseMetadata");
2666
+ function useToolInput2() {
2667
+ return useOpenAiGlobal("toolInput");
2668
+ }
2669
+ __name(useToolInput2, "useToolInput");
2670
+ function useWidgetState(initialState) {
2671
+ const rawState = useOpenAiGlobal("widgetState");
2672
+ const resolvedInitial = rawState ?? (typeof initialState === "function" ? initialState() : initialState);
2673
+ const setWidgetState = useCallback((newStateOrUpdater) => {
2674
+ if (!window.openai?.setWidgetState) {
2675
+ console.warn("window.openai.setWidgetState is not available");
2676
+ return;
2677
+ }
2678
+ const current = window.openai.widgetState ?? resolvedInitial;
2679
+ const next = typeof newStateOrUpdater === "function" ? newStateOrUpdater(current) : newStateOrUpdater;
2680
+ window.openai.setWidgetState(next);
2681
+ }, [
2682
+ resolvedInitial
2683
+ ]);
2684
+ return [
2685
+ resolvedInitial,
2686
+ setWidgetState
2687
+ ];
2688
+ }
2689
+ __name(useWidgetState, "useWidgetState");
2631
2690
 
2632
2691
  // src/types/mcp-types.ts
2633
2692
  function normalizeToolBinding(tool) {
@@ -3382,6 +3441,6 @@ var Input2 = /* @__PURE__ */ forwardRef(({ className, label, helperText, error,
3382
3441
  });
3383
3442
  Input2.displayName = "Input";
3384
3443
 
3385
- 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, useFormField, useGptApp, useGptTool, useHostContext, useMcpApp, useMessage, useResource, useTool, useToolContext, useToolInput, useToolInputPartial, useToolResult, useToolStream, useToolSubscription };
3444
+ 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, useFormField, useGptApp, useGptTool, useHostContext, useMcpApp, useMessage, useOpenAiGlobal, useResource, useTool, useToolContext, useToolInput, useToolInputPartial, useToolInput2 as useToolInputSpec, useToolOutput, useToolResponseMetadata, useToolResult, useToolStream, useToolSubscription, useWidgetState };
3386
3445
  //# sourceMappingURL=index.mjs.map
3387
3446
  //# sourceMappingURL=index.mjs.map