@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/README.md CHANGED
@@ -1,6 +1,42 @@
1
- # @leanmcp/ui
2
-
3
- **MCP-Native UI SDK for React** - Build rich, interactive MCP Apps with first-class tool integration.
1
+ <p align="center">
2
+ <img
3
+ src="https://raw.githubusercontent.com/LeanMCP/leanmcp-sdk/refs/heads/main/assets/logo.svg"
4
+ alt="LeanMCP Logo"
5
+ width="400"
6
+ />
7
+ </p>
8
+
9
+ <p align="center">
10
+ <strong>@leanmcp/ui</strong><br/>
11
+ MCP-Native UI SDK for React — Build rich, interactive MCP Apps with first-class tool integration.
12
+ </p>
13
+
14
+ <p align="center">
15
+ <a href="https://www.npmjs.com/package/@leanmcp/ui">
16
+ <img src="https://img.shields.io/npm/v/@leanmcp/ui" alt="npm version" />
17
+ </a>
18
+ <a href="https://www.npmjs.com/package/@leanmcp/ui">
19
+ <img src="https://img.shields.io/npm/dm/@leanmcp/ui" alt="npm downloads" />
20
+ </a>
21
+ <a href="https://docs.leanmcp.com/sdk/ui">
22
+ <img src="https://img.shields.io/badge/Docs-leanmcp-0A66C2?" />
23
+ </a>
24
+ <a href="https://discord.com/invite/DsRcA3GwPy">
25
+ <img src="https://img.shields.io/badge/Discord-Join-5865F2?logo=discord&logoColor=white" />
26
+ </a>
27
+ <a href="https://x.com/LeanMcp">
28
+ <img src="https://img.shields.io/badge/@LeanMCP-f5f5f5?logo=x&logoColor=000000" />
29
+ </a>
30
+ </p>
31
+
32
+ ## Features
33
+
34
+ - **MCP-Native Components** — ToolButton, ToolSelect, ToolForm, ToolDataGrid, and more
35
+ - **First-Class Tool Integration** — Components that natively call MCP tools
36
+ - **ChatGPT Apps Support** — Build apps that work inside ChatGPT with `@GPTApp`
37
+ - **Streaming Support** — Handle partial/streaming tool responses
38
+ - **Theming** — Automatic host theme adaptation (light/dark)
39
+ - **Testing Utilities** — `MockAppProvider` for unit testing
4
40
 
5
41
  ## Installation
6
42
 
@@ -57,6 +93,18 @@ function MyApp() {
57
93
  | `useMessage` | Send messages to host chat |
58
94
  | `useHostContext` | Access host theme and viewport |
59
95
 
96
+ ### GPT Apps SDK Hooks
97
+
98
+ These hooks provide access to the ChatGPT Apps SDK globals (compatible with OpenAI's `window.openai` API):
99
+
100
+ | Hook | Description |
101
+ |------|-------------|
102
+ | `useToolOutput` | Access `structuredContent` from the tool response |
103
+ | `useToolInput` | Access input arguments passed to the tool |
104
+ | `useWidgetState` | Read/write persistent widget state across sessions |
105
+ | `useToolResponseMetadata` | Access `_meta` from the tool response |
106
+ | `useOpenAiGlobal` | Low-level hook to subscribe to any `window.openai` property |
107
+
60
108
  ## Examples
61
109
 
62
110
  ### ToolButton with Confirmation
@@ -126,6 +174,70 @@ function MyApp() {
126
174
  />
127
175
  ```
128
176
 
177
+ ## Server-Side Integration
178
+
179
+ Use `@UIApp` decorator to register your React component as an MCP resource.
180
+
181
+ > **Note:** Use a relative path string for the `component` property, not an imported component. This avoids importing React components on the server side.
182
+
183
+ ```typescript
184
+ // mcp/dashboard/index.ts
185
+ import { UIApp } from '@leanmcp/core';
186
+
187
+ export class DashboardService {
188
+ @UIApp({
189
+ component: './Dashboard', // Path relative to this file
190
+ name: 'dashboard',
191
+ title: 'Analytics Dashboard'
192
+ })
193
+ dashboard() {}
194
+ }
195
+ ```
196
+
197
+ ## ChatGPT Integration
198
+
199
+ Use `@GPTApp` for ChatGPT-specific apps:
200
+
201
+ ```typescript
202
+ import { GPTApp } from '@leanmcp/ui';
203
+
204
+ export class SlackService {
205
+ @GPTApp({
206
+ component: './SlackApp', // Path relative to this file
207
+ name: 'slack-composer'
208
+ })
209
+ slackComposer() {}
210
+ }
211
+ ```
212
+
213
+ ### GPT Apps SDK Hooks Usage
214
+
215
+ Access tool output (structuredContent) without making additional API calls:
216
+
217
+ ```tsx
218
+ import { useToolOutput, useWidgetState } from '@leanmcp/ui';
219
+
220
+ function ChannelsView() {
221
+ // Access the structured data from the tool response
222
+ const toolOutput = useToolOutput<{ channels: Channel[] }>();
223
+
224
+ // Persist state across the session
225
+ const [state, setState] = useWidgetState({ selectedChannel: null });
226
+
227
+ if (!toolOutput?.channels) return <div>Loading...</div>;
228
+
229
+ return (
230
+ <ul>
231
+ {toolOutput.channels.map(ch => (
232
+ <li key={ch.id} onClick={() => setState({ selectedChannel: ch.id })}>
233
+ {ch.name}
234
+ </li>
235
+ ))}
236
+ </ul>
237
+ );
238
+ }
239
+ ```
240
+
129
241
  ## Theming
130
242
 
131
243
  The SDK uses CSS variables compatible with MCP host theming. Import the styles:
@@ -155,6 +267,19 @@ test('renders tool result', () => {
155
267
  });
156
268
  ```
157
269
 
270
+ ## Documentation
271
+
272
+ - [Full Documentation](https://docs.leanmcp.com/sdk/ui)
273
+ - [Component Reference](https://docs.leanmcp.com/sdk/ui-components)
274
+ - [Hooks Reference](https://docs.leanmcp.com/sdk/ui-hooks)
275
+ - [ChatGPT Apps Guide](https://docs.leanmcp.com/sdk/ui-gpt-apps)
276
+
277
+ ## Related Packages
278
+
279
+ - [@leanmcp/core](https://www.npmjs.com/package/@leanmcp/core) — Core MCP server functionality
280
+ - [@leanmcp/cli](https://www.npmjs.com/package/@leanmcp/cli) — CLI for project scaffolding
281
+ - [@leanmcp/auth](https://www.npmjs.com/package/@leanmcp/auth) — Authentication decorators
282
+
158
283
  ## License
159
284
 
160
285
  MIT
package/dist/index.d.mts CHANGED
@@ -124,11 +124,35 @@ declare function useMcpApp(): McpAppContextValue;
124
124
 
125
125
  /**
126
126
  * ChatGPT's window.openai interface
127
- * Only includes properties that are confirmed to exist in the ChatGPT Apps SDK
127
+ * Based on: https://developers.openai.com/apps-sdk/build/chatgpt-ui#understand-the-windowopenai-api
128
128
  */
129
129
  interface OpenAISDK {
130
+ /** Input arguments for the tool */
131
+ toolInput?: Record<string, unknown>;
132
+ /** Structured content returned by the tool */
133
+ toolOutput?: any;
134
+ /** Metadata returned by the tool */
135
+ toolResponseMetadata?: Record<string, unknown>;
136
+ /** Persisted state for this widget instance */
137
+ widgetState?: Record<string, unknown>;
130
138
  /** Call a server tool */
131
139
  callTool: (name: string, args: Record<string, unknown>) => Promise<any>;
140
+ /** Send a follow-up message to chat */
141
+ sendFollowUpMessage?: (options: {
142
+ prompt: string;
143
+ }) => Promise<void>;
144
+ /** Upload a file */
145
+ uploadFile?: (file: File) => Promise<{
146
+ fileId: string;
147
+ }>;
148
+ /** Get download URL for a file */
149
+ getFileDownloadUrl?: (options: {
150
+ fileId: string;
151
+ }) => Promise<{
152
+ downloadUrl: string;
153
+ }>;
154
+ /** Persist widget state */
155
+ setWidgetState?: (state: Record<string, unknown>) => void;
132
156
  /** Current theme */
133
157
  theme?: 'light' | 'dark';
134
158
  /** Current locale */
@@ -137,6 +161,15 @@ interface OpenAISDK {
137
161
  displayMode?: 'inline' | 'modal' | 'fullscreen';
138
162
  /** Maximum height for the widget */
139
163
  maxHeight?: number;
164
+ /** Safe area insets */
165
+ safeArea?: {
166
+ top: number;
167
+ right: number;
168
+ bottom: number;
169
+ left: number;
170
+ };
171
+ /** View type */
172
+ view?: 'desktop' | 'mobile';
140
173
  }
141
174
  declare global {
142
175
  interface Window {
@@ -1143,7 +1176,7 @@ interface UseToolInputReturn<T = Record<string, unknown>> {
1143
1176
  * }
1144
1177
  * ```
1145
1178
  */
1146
- declare function useToolInput<T = Record<string, unknown>>(): UseToolInputReturn<T>;
1179
+ declare function useToolInput$1<T = Record<string, unknown>>(): UseToolInputReturn<T>;
1147
1180
 
1148
1181
  interface UseToolInputPartialReturn {
1149
1182
  /** Partial arguments currently available */
@@ -1216,6 +1249,52 @@ interface UseToolSubscriptionResult<T = unknown> {
1216
1249
  */
1217
1250
  declare function useToolSubscription<T = unknown>(toolName: string, options?: UseToolSubscriptionOptions): UseToolSubscriptionResult<T>;
1218
1251
 
1252
+ interface OpenAiGlobals {
1253
+ toolInput: Record<string, unknown>;
1254
+ toolOutput: any;
1255
+ toolResponseMetadata: Record<string, unknown>;
1256
+ widgetState: Record<string, unknown>;
1257
+ theme: 'light' | 'dark';
1258
+ displayMode: 'inline' | 'modal' | 'fullscreen';
1259
+ maxHeight: number;
1260
+ safeArea: {
1261
+ top: number;
1262
+ right: number;
1263
+ bottom: number;
1264
+ left: number;
1265
+ };
1266
+ view: 'desktop' | 'mobile';
1267
+ locale: string;
1268
+ }
1269
+ /**
1270
+ * React hook to subscribe to window.openai global values.
1271
+ * Source: https://developers.openai.com/apps-sdk/build/chatgpt-ui#useopenaiglobal
1272
+ */
1273
+ declare function useOpenAiGlobal<K extends keyof OpenAiGlobals>(key: K): OpenAiGlobals[K] | undefined;
1274
+
1275
+ /**
1276
+ * Access the structured content returned by the tool.
1277
+ * Maps to 'structuredContent' in the tool response.
1278
+ */
1279
+ declare function useToolOutput<T = any>(): T | undefined;
1280
+ /**
1281
+ * Access metadata about the tool response.
1282
+ * Maps to '_meta' in the tool response.
1283
+ */
1284
+ declare function useToolResponseMetadata<T = any>(): T | undefined;
1285
+ /**
1286
+ * Access the input arguments passed to the tool.
1287
+ */
1288
+ declare function useToolInput<T = any>(): T | undefined;
1289
+
1290
+ /**
1291
+ * Hook to read and write widget state.
1292
+ * Widget state persists across the session for this specific widget instance.
1293
+ *
1294
+ * @param initialState - Default state if none exists
1295
+ */
1296
+ declare function useWidgetState<T extends Record<string, unknown>>(initialState: T | (() => T)): [T, (newState: T | ((prev: T) => T)) => void];
1297
+
1219
1298
  declare function CardTitle({ className, ...props }: React.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
1220
1299
  declare function CardDescription({ className, ...props }: React.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
1221
1300
 
@@ -1623,4 +1702,4 @@ interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size'>
1623
1702
  */
1624
1703
  declare const Input: React__default.ForwardRefExoticComponent<InputProps & React__default.RefAttributes<HTMLInputElement>>;
1625
1704
 
1626
- export { ActionButton, type ActionButtonProps, Alert, AlertDescription, AlertTitle, type AppInfo, type AppOptions, AppProvider, type AppProviderProps, AppShell, type AppShellProps, Badge, Button, type ButtonProps, Card, CardContent, type CardContentProps, CardDescription, CardFooter, type CardFooterProps, CardHeader, type CardHeaderProps, type CardProps, CardTitle, Chart, type ChartProps, type ChartType, Checkbox, CodeBlock, type CodeBlockProps, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, type ConfirmConfig, DEFAULT_RESULT_CONFIG, DataGrid, type DataGridColumn, type DataGridProps, 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, type GPTAppProviderProps, type GptAppContextValue, INITIAL_TOOL_STATE, Input, type InputProps, Label, type McpActionProps, type McpAppContextValue, Modal, type ModalProps, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, Progress, RequireConnection, type RequireConnectionProps, type ResourceBinding, type ResourceMeta, ResourceView, type ResourceViewProps, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Skeleton, Slider, StreamingContent, type StreamingContentProps, Switch, TabContent, type TabContentProps, type TabItem, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, type TabsProps, TabsTrigger, Textarea, Toaster, type ToolBinding, ToolButton, type ToolButtonProps, type ToolButtonState, type ToolCallState, type ToolContextValue, ToolDataGrid, type ToolDataGridColumn, type ToolDataGridProps, type ToolDataGridRowAction, ToolErrorBoundary, type ToolErrorBoundaryProps, ToolForm, type ToolFormField, type ToolFormProps, ToolInput, type ToolInputProps, type ToolInputSuggestion, ToolProvider, type ToolProviderProps, type ToolResultConfig, ToolSelect, type ToolSelectOption, type ToolSelectProps, type ToolState, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, type UseHostContextReturn, type UseMessageReturn, type UseResourceOptions, type UseResourceReturn, type UseToolInputPartialReturn, type UseToolInputReturn, type UseToolOptions, type UseToolResultReturn, type UseToolReturn, type UseToolStreamOptions, type UseToolStreamReturn, badgeVariants, buttonVariants, cn, normalizeToolBinding, useFormField, useGptApp, useGptTool, useHostContext, useMcpApp, useMessage, useResource, useTool, useToolContext, useToolInput, useToolInputPartial, useToolResult, useToolStream, useToolSubscription };
1705
+ export { ActionButton, type ActionButtonProps, Alert, AlertDescription, AlertTitle, type AppInfo, type AppOptions, AppProvider, type AppProviderProps, AppShell, type AppShellProps, Badge, Button, type ButtonProps, Card, CardContent, type CardContentProps, CardDescription, CardFooter, type CardFooterProps, CardHeader, type CardHeaderProps, type CardProps, CardTitle, Chart, type ChartProps, type ChartType, Checkbox, CodeBlock, type CodeBlockProps, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, type ConfirmConfig, DEFAULT_RESULT_CONFIG, DataGrid, type DataGridColumn, type DataGridProps, 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, type GPTAppProviderProps, type GptAppContextValue, INITIAL_TOOL_STATE, Input, type InputProps, Label, type McpActionProps, type McpAppContextValue, Modal, type ModalProps, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, Progress, RequireConnection, type RequireConnectionProps, type ResourceBinding, type ResourceMeta, ResourceView, type ResourceViewProps, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Skeleton, Slider, StreamingContent, type StreamingContentProps, Switch, TabContent, type TabContentProps, type TabItem, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, type TabsProps, TabsTrigger, Textarea, Toaster, type ToolBinding, ToolButton, type ToolButtonProps, type ToolButtonState, type ToolCallState, type ToolContextValue, ToolDataGrid, type ToolDataGridColumn, type ToolDataGridProps, type ToolDataGridRowAction, ToolErrorBoundary, type ToolErrorBoundaryProps, ToolForm, type ToolFormField, type ToolFormProps, ToolInput, type ToolInputProps, type ToolInputSuggestion, ToolProvider, type ToolProviderProps, type ToolResultConfig, ToolSelect, type ToolSelectOption, type ToolSelectProps, type ToolState, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, type UseHostContextReturn, type UseMessageReturn, type UseResourceOptions, type UseResourceReturn, type UseToolInputPartialReturn, type UseToolInputReturn, type UseToolOptions, type UseToolResultReturn, type UseToolReturn, type UseToolStreamOptions, type UseToolStreamReturn, badgeVariants, buttonVariants, cn, normalizeToolBinding, useFormField, useGptApp, useGptTool, useHostContext, useMcpApp, useMessage, useOpenAiGlobal, useResource, useTool, useToolContext, useToolInput$1 as useToolInput, useToolInputPartial, useToolInput as useToolInputSpec, useToolOutput, useToolResponseMetadata, useToolResult, useToolStream, useToolSubscription, useWidgetState };
package/dist/index.d.ts CHANGED
@@ -124,11 +124,35 @@ declare function useMcpApp(): McpAppContextValue;
124
124
 
125
125
  /**
126
126
  * ChatGPT's window.openai interface
127
- * Only includes properties that are confirmed to exist in the ChatGPT Apps SDK
127
+ * Based on: https://developers.openai.com/apps-sdk/build/chatgpt-ui#understand-the-windowopenai-api
128
128
  */
129
129
  interface OpenAISDK {
130
+ /** Input arguments for the tool */
131
+ toolInput?: Record<string, unknown>;
132
+ /** Structured content returned by the tool */
133
+ toolOutput?: any;
134
+ /** Metadata returned by the tool */
135
+ toolResponseMetadata?: Record<string, unknown>;
136
+ /** Persisted state for this widget instance */
137
+ widgetState?: Record<string, unknown>;
130
138
  /** Call a server tool */
131
139
  callTool: (name: string, args: Record<string, unknown>) => Promise<any>;
140
+ /** Send a follow-up message to chat */
141
+ sendFollowUpMessage?: (options: {
142
+ prompt: string;
143
+ }) => Promise<void>;
144
+ /** Upload a file */
145
+ uploadFile?: (file: File) => Promise<{
146
+ fileId: string;
147
+ }>;
148
+ /** Get download URL for a file */
149
+ getFileDownloadUrl?: (options: {
150
+ fileId: string;
151
+ }) => Promise<{
152
+ downloadUrl: string;
153
+ }>;
154
+ /** Persist widget state */
155
+ setWidgetState?: (state: Record<string, unknown>) => void;
132
156
  /** Current theme */
133
157
  theme?: 'light' | 'dark';
134
158
  /** Current locale */
@@ -137,6 +161,15 @@ interface OpenAISDK {
137
161
  displayMode?: 'inline' | 'modal' | 'fullscreen';
138
162
  /** Maximum height for the widget */
139
163
  maxHeight?: number;
164
+ /** Safe area insets */
165
+ safeArea?: {
166
+ top: number;
167
+ right: number;
168
+ bottom: number;
169
+ left: number;
170
+ };
171
+ /** View type */
172
+ view?: 'desktop' | 'mobile';
140
173
  }
141
174
  declare global {
142
175
  interface Window {
@@ -1143,7 +1176,7 @@ interface UseToolInputReturn<T = Record<string, unknown>> {
1143
1176
  * }
1144
1177
  * ```
1145
1178
  */
1146
- declare function useToolInput<T = Record<string, unknown>>(): UseToolInputReturn<T>;
1179
+ declare function useToolInput$1<T = Record<string, unknown>>(): UseToolInputReturn<T>;
1147
1180
 
1148
1181
  interface UseToolInputPartialReturn {
1149
1182
  /** Partial arguments currently available */
@@ -1216,6 +1249,52 @@ interface UseToolSubscriptionResult<T = unknown> {
1216
1249
  */
1217
1250
  declare function useToolSubscription<T = unknown>(toolName: string, options?: UseToolSubscriptionOptions): UseToolSubscriptionResult<T>;
1218
1251
 
1252
+ interface OpenAiGlobals {
1253
+ toolInput: Record<string, unknown>;
1254
+ toolOutput: any;
1255
+ toolResponseMetadata: Record<string, unknown>;
1256
+ widgetState: Record<string, unknown>;
1257
+ theme: 'light' | 'dark';
1258
+ displayMode: 'inline' | 'modal' | 'fullscreen';
1259
+ maxHeight: number;
1260
+ safeArea: {
1261
+ top: number;
1262
+ right: number;
1263
+ bottom: number;
1264
+ left: number;
1265
+ };
1266
+ view: 'desktop' | 'mobile';
1267
+ locale: string;
1268
+ }
1269
+ /**
1270
+ * React hook to subscribe to window.openai global values.
1271
+ * Source: https://developers.openai.com/apps-sdk/build/chatgpt-ui#useopenaiglobal
1272
+ */
1273
+ declare function useOpenAiGlobal<K extends keyof OpenAiGlobals>(key: K): OpenAiGlobals[K] | undefined;
1274
+
1275
+ /**
1276
+ * Access the structured content returned by the tool.
1277
+ * Maps to 'structuredContent' in the tool response.
1278
+ */
1279
+ declare function useToolOutput<T = any>(): T | undefined;
1280
+ /**
1281
+ * Access metadata about the tool response.
1282
+ * Maps to '_meta' in the tool response.
1283
+ */
1284
+ declare function useToolResponseMetadata<T = any>(): T | undefined;
1285
+ /**
1286
+ * Access the input arguments passed to the tool.
1287
+ */
1288
+ declare function useToolInput<T = any>(): T | undefined;
1289
+
1290
+ /**
1291
+ * Hook to read and write widget state.
1292
+ * Widget state persists across the session for this specific widget instance.
1293
+ *
1294
+ * @param initialState - Default state if none exists
1295
+ */
1296
+ declare function useWidgetState<T extends Record<string, unknown>>(initialState: T | (() => T)): [T, (newState: T | ((prev: T) => T)) => void];
1297
+
1219
1298
  declare function CardTitle({ className, ...props }: React.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
1220
1299
  declare function CardDescription({ className, ...props }: React.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
1221
1300
 
@@ -1623,4 +1702,4 @@ interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size'>
1623
1702
  */
1624
1703
  declare const Input: React__default.ForwardRefExoticComponent<InputProps & React__default.RefAttributes<HTMLInputElement>>;
1625
1704
 
1626
- export { ActionButton, type ActionButtonProps, Alert, AlertDescription, AlertTitle, type AppInfo, type AppOptions, AppProvider, type AppProviderProps, AppShell, type AppShellProps, Badge, Button, type ButtonProps, Card, CardContent, type CardContentProps, CardDescription, CardFooter, type CardFooterProps, CardHeader, type CardHeaderProps, type CardProps, CardTitle, Chart, type ChartProps, type ChartType, Checkbox, CodeBlock, type CodeBlockProps, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, type ConfirmConfig, DEFAULT_RESULT_CONFIG, DataGrid, type DataGridColumn, type DataGridProps, 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, type GPTAppProviderProps, type GptAppContextValue, INITIAL_TOOL_STATE, Input, type InputProps, Label, type McpActionProps, type McpAppContextValue, Modal, type ModalProps, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, Progress, RequireConnection, type RequireConnectionProps, type ResourceBinding, type ResourceMeta, ResourceView, type ResourceViewProps, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Skeleton, Slider, StreamingContent, type StreamingContentProps, Switch, TabContent, type TabContentProps, type TabItem, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, type TabsProps, TabsTrigger, Textarea, Toaster, type ToolBinding, ToolButton, type ToolButtonProps, type ToolButtonState, type ToolCallState, type ToolContextValue, ToolDataGrid, type ToolDataGridColumn, type ToolDataGridProps, type ToolDataGridRowAction, ToolErrorBoundary, type ToolErrorBoundaryProps, ToolForm, type ToolFormField, type ToolFormProps, ToolInput, type ToolInputProps, type ToolInputSuggestion, ToolProvider, type ToolProviderProps, type ToolResultConfig, ToolSelect, type ToolSelectOption, type ToolSelectProps, type ToolState, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, type UseHostContextReturn, type UseMessageReturn, type UseResourceOptions, type UseResourceReturn, type UseToolInputPartialReturn, type UseToolInputReturn, type UseToolOptions, type UseToolResultReturn, type UseToolReturn, type UseToolStreamOptions, type UseToolStreamReturn, badgeVariants, buttonVariants, cn, normalizeToolBinding, useFormField, useGptApp, useGptTool, useHostContext, useMcpApp, useMessage, useResource, useTool, useToolContext, useToolInput, useToolInputPartial, useToolResult, useToolStream, useToolSubscription };
1705
+ export { ActionButton, type ActionButtonProps, Alert, AlertDescription, AlertTitle, type AppInfo, type AppOptions, AppProvider, type AppProviderProps, AppShell, type AppShellProps, Badge, Button, type ButtonProps, Card, CardContent, type CardContentProps, CardDescription, CardFooter, type CardFooterProps, CardHeader, type CardHeaderProps, type CardProps, CardTitle, Chart, type ChartProps, type ChartType, Checkbox, CodeBlock, type CodeBlockProps, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, type ConfirmConfig, DEFAULT_RESULT_CONFIG, DataGrid, type DataGridColumn, type DataGridProps, 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, type GPTAppProviderProps, type GptAppContextValue, INITIAL_TOOL_STATE, Input, type InputProps, Label, type McpActionProps, type McpAppContextValue, Modal, type ModalProps, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, Progress, RequireConnection, type RequireConnectionProps, type ResourceBinding, type ResourceMeta, ResourceView, type ResourceViewProps, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Skeleton, Slider, StreamingContent, type StreamingContentProps, Switch, TabContent, type TabContentProps, type TabItem, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, type TabsProps, TabsTrigger, Textarea, Toaster, type ToolBinding, ToolButton, type ToolButtonProps, type ToolButtonState, type ToolCallState, type ToolContextValue, ToolDataGrid, type ToolDataGridColumn, type ToolDataGridProps, type ToolDataGridRowAction, ToolErrorBoundary, type ToolErrorBoundaryProps, ToolForm, type ToolFormField, type ToolFormProps, ToolInput, type ToolInputProps, type ToolInputSuggestion, ToolProvider, type ToolProviderProps, type ToolResultConfig, ToolSelect, type ToolSelectOption, type ToolSelectProps, type ToolState, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, type UseHostContextReturn, type UseMessageReturn, type UseResourceOptions, type UseResourceReturn, type UseToolInputPartialReturn, type UseToolInputReturn, type UseToolOptions, type UseToolResultReturn, type UseToolReturn, type UseToolStreamOptions, type UseToolStreamReturn, badgeVariants, buttonVariants, cn, normalizeToolBinding, useFormField, useGptApp, useGptTool, useHostContext, useMcpApp, useMessage, useOpenAiGlobal, useResource, useTool, useToolContext, useToolInput$1 as useToolInput, useToolInputPartial, useToolInput as useToolInputSpec, useToolOutput, useToolResponseMetadata, useToolResult, useToolStream, useToolSubscription, useWidgetState };
package/dist/index.js CHANGED
@@ -1689,6 +1689,10 @@ function useResource(uri, options = {}) {
1689
1689
  fetchResource
1690
1690
  ]);
1691
1691
  React26.useEffect(() => {
1692
+ if (intervalRef.current) {
1693
+ clearInterval(intervalRef.current);
1694
+ intervalRef.current = null;
1695
+ }
1692
1696
  if (refreshInterval && refreshInterval > 0 && isConnected && !skip) {
1693
1697
  intervalRef.current = setInterval(() => {
1694
1698
  fetchResource().catch(() => {
@@ -2619,7 +2623,10 @@ function useToolSubscription(toolName, options = {}) {
2619
2623
  setIsPolling(false);
2620
2624
  }, []);
2621
2625
  const start = React26.useCallback(() => {
2622
- stop();
2626
+ if (intervalRef.current) {
2627
+ clearInterval(intervalRef.current);
2628
+ intervalRef.current = null;
2629
+ }
2623
2630
  setIsPolling(true);
2624
2631
  toolHook.call(args).catch(() => {
2625
2632
  });
@@ -2630,8 +2637,7 @@ function useToolSubscription(toolName, options = {}) {
2630
2637
  }, [
2631
2638
  toolHook.call,
2632
2639
  args,
2633
- interval,
2634
- stop
2640
+ interval
2635
2641
  ]);
2636
2642
  const refresh = React26.useCallback(async () => {
2637
2643
  return toolHook.call(args);
@@ -2660,6 +2666,59 @@ function useToolSubscription(toolName, options = {}) {
2660
2666
  };
2661
2667
  }
2662
2668
  chunk2HRO6CFU_js.__name(useToolSubscription, "useToolSubscription");
2669
+ var SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
2670
+ function useOpenAiGlobal(key) {
2671
+ return React26.useSyncExternalStore((onChange) => {
2672
+ const handleSetGlobal = /* @__PURE__ */ chunk2HRO6CFU_js.__name((event) => {
2673
+ const customEvent = event;
2674
+ const value = customEvent.detail?.globals?.[key];
2675
+ if (value !== void 0) {
2676
+ onChange();
2677
+ }
2678
+ }, "handleSetGlobal");
2679
+ window.addEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal, {
2680
+ passive: true
2681
+ });
2682
+ return () => {
2683
+ window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);
2684
+ };
2685
+ }, () => window.openai?.[key]);
2686
+ }
2687
+ chunk2HRO6CFU_js.__name(useOpenAiGlobal, "useOpenAiGlobal");
2688
+
2689
+ // src/mcp/useToolData.ts
2690
+ function useToolOutput() {
2691
+ return useOpenAiGlobal("toolOutput");
2692
+ }
2693
+ chunk2HRO6CFU_js.__name(useToolOutput, "useToolOutput");
2694
+ function useToolResponseMetadata() {
2695
+ return useOpenAiGlobal("toolResponseMetadata");
2696
+ }
2697
+ chunk2HRO6CFU_js.__name(useToolResponseMetadata, "useToolResponseMetadata");
2698
+ function useToolInput2() {
2699
+ return useOpenAiGlobal("toolInput");
2700
+ }
2701
+ chunk2HRO6CFU_js.__name(useToolInput2, "useToolInput");
2702
+ function useWidgetState(initialState) {
2703
+ const rawState = useOpenAiGlobal("widgetState");
2704
+ const resolvedInitial = rawState ?? (typeof initialState === "function" ? initialState() : initialState);
2705
+ const setWidgetState = React26.useCallback((newStateOrUpdater) => {
2706
+ if (!window.openai?.setWidgetState) {
2707
+ console.warn("window.openai.setWidgetState is not available");
2708
+ return;
2709
+ }
2710
+ const current = window.openai.widgetState ?? resolvedInitial;
2711
+ const next = typeof newStateOrUpdater === "function" ? newStateOrUpdater(current) : newStateOrUpdater;
2712
+ window.openai.setWidgetState(next);
2713
+ }, [
2714
+ resolvedInitial
2715
+ ]);
2716
+ return [
2717
+ resolvedInitial,
2718
+ setWidgetState
2719
+ ];
2720
+ }
2721
+ chunk2HRO6CFU_js.__name(useWidgetState, "useWidgetState");
2663
2722
 
2664
2723
  // src/types/mcp-types.ts
2665
2724
  function normalizeToolBinding(tool) {
@@ -3599,13 +3658,18 @@ exports.useGptTool = useGptTool;
3599
3658
  exports.useHostContext = useHostContext;
3600
3659
  exports.useMcpApp = useMcpApp;
3601
3660
  exports.useMessage = useMessage;
3661
+ exports.useOpenAiGlobal = useOpenAiGlobal;
3602
3662
  exports.useResource = useResource;
3603
3663
  exports.useTool = useTool;
3604
3664
  exports.useToolContext = useToolContext;
3605
3665
  exports.useToolInput = useToolInput;
3606
3666
  exports.useToolInputPartial = useToolInputPartial;
3667
+ exports.useToolInputSpec = useToolInput2;
3668
+ exports.useToolOutput = useToolOutput;
3669
+ exports.useToolResponseMetadata = useToolResponseMetadata;
3607
3670
  exports.useToolResult = useToolResult;
3608
3671
  exports.useToolStream = useToolStream;
3609
3672
  exports.useToolSubscription = useToolSubscription;
3673
+ exports.useWidgetState = useWidgetState;
3610
3674
  //# sourceMappingURL=index.js.map
3611
3675
  //# sourceMappingURL=index.js.map