@leanmcp/ui 0.3.1 → 0.3.3

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,6 @@
1
1
  <p align="center">
2
2
  <img
3
- src="https://raw.githubusercontent.com/LeanMCP/leanmcp-sdk/refs/heads/main/assets/logo.svg"
3
+ src="https://raw.githubusercontent.com/LeanMCP/leanmcp-sdk/refs/heads/main/assets/logo.png"
4
4
  alt="LeanMCP Logo"
5
5
  width="400"
6
6
  />
@@ -93,6 +93,18 @@ function MyApp() {
93
93
  | `useMessage` | Send messages to host chat |
94
94
  | `useHostContext` | Access host theme and viewport |
95
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
+
96
108
  ## Examples
97
109
 
98
110
  ### ToolButton with Confirmation
@@ -198,6 +210,34 @@ export class SlackService {
198
210
  }
199
211
  ```
200
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
+
201
241
  ## Theming
202
242
 
203
243
  The SDK uses CSS variables compatible with MCP host theming. Import the styles:
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,120 @@ interface UseToolSubscriptionResult<T = unknown> {
1216
1249
  */
1217
1250
  declare function useToolSubscription<T = unknown>(toolName: string, options?: UseToolSubscriptionOptions): UseToolSubscriptionResult<T>;
1218
1251
 
1252
+ /**
1253
+ * useAuth - Authentication hook for GPT Apps
1254
+ *
1255
+ * Provides auth status and triggers ChatGPT's OAuth linking UI
1256
+ * when tools return _meta["mcp/www_authenticate"].
1257
+ */
1258
+ /**
1259
+ * Authenticated user info
1260
+ */
1261
+ interface AuthUser {
1262
+ /** User ID (subject) */
1263
+ id: string;
1264
+ /** Display name */
1265
+ name?: string;
1266
+ /** Email address */
1267
+ email?: string;
1268
+ /** Profile picture URL */
1269
+ picture?: string;
1270
+ }
1271
+ /**
1272
+ * Return type for useAuth hook
1273
+ */
1274
+ interface UseAuthReturn {
1275
+ /** Whether user is authenticated */
1276
+ isAuthenticated: boolean;
1277
+ /** Currently authenticated user (if any) */
1278
+ user: AuthUser | null;
1279
+ /** Loading state */
1280
+ loading: boolean;
1281
+ /** Authentication error (if any) */
1282
+ error: Error | null;
1283
+ /** Trigger an auth-required tool to initiate OAuth flow */
1284
+ triggerAuth: () => Promise<void>;
1285
+ /** Clear auth state (for sign-out UI) */
1286
+ clearAuth: () => void;
1287
+ }
1288
+ /**
1289
+ * Authentication hook for GPT Apps
1290
+ *
1291
+ * In ChatGPT, authentication is triggered automatically when a tool
1292
+ * returns `_meta["mcp/www_authenticate"]`. Use this hook to:
1293
+ *
1294
+ * 1. Check if the user is authenticated
1295
+ * 2. Show loading state during auth
1296
+ * 3. Display user info after auth
1297
+ * 4. Manually trigger auth by calling an auth-required tool
1298
+ *
1299
+ * @example
1300
+ * ```tsx
1301
+ * function MyComponent() {
1302
+ * const { isAuthenticated, user, triggerAuth, loading } = useAuth();
1303
+ *
1304
+ * if (loading) return <div>Authenticating...</div>;
1305
+ *
1306
+ * if (!isAuthenticated) {
1307
+ * return (
1308
+ * <Button onClick={triggerAuth}>
1309
+ * Sign in with GitHub
1310
+ * </Button>
1311
+ * );
1312
+ * }
1313
+ *
1314
+ * return <div>Welcome, {user?.name}!</div>;
1315
+ * }
1316
+ * ```
1317
+ */
1318
+ declare function useAuth(): UseAuthReturn;
1319
+
1320
+ interface OpenAiGlobals {
1321
+ toolInput: Record<string, unknown>;
1322
+ toolOutput: any;
1323
+ toolResponseMetadata: Record<string, unknown>;
1324
+ widgetState: Record<string, unknown>;
1325
+ theme: 'light' | 'dark';
1326
+ displayMode: 'inline' | 'modal' | 'fullscreen';
1327
+ maxHeight: number;
1328
+ safeArea: {
1329
+ top: number;
1330
+ right: number;
1331
+ bottom: number;
1332
+ left: number;
1333
+ };
1334
+ view: 'desktop' | 'mobile';
1335
+ locale: string;
1336
+ }
1337
+ /**
1338
+ * React hook to subscribe to window.openai global values.
1339
+ * Source: https://developers.openai.com/apps-sdk/build/chatgpt-ui#useopenaiglobal
1340
+ */
1341
+ declare function useOpenAiGlobal<K extends keyof OpenAiGlobals>(key: K): OpenAiGlobals[K] | undefined;
1342
+
1343
+ /**
1344
+ * Access the structured content returned by the tool.
1345
+ * Maps to 'structuredContent' in the tool response.
1346
+ */
1347
+ declare function useToolOutput<T = any>(): T | undefined;
1348
+ /**
1349
+ * Access metadata about the tool response.
1350
+ * Maps to '_meta' in the tool response.
1351
+ */
1352
+ declare function useToolResponseMetadata<T = any>(): T | undefined;
1353
+ /**
1354
+ * Access the input arguments passed to the tool.
1355
+ */
1356
+ declare function useToolInput<T = any>(): T | undefined;
1357
+
1358
+ /**
1359
+ * Hook to read and write widget state.
1360
+ * Widget state persists across the session for this specific widget instance.
1361
+ *
1362
+ * @param initialState - Default state if none exists
1363
+ */
1364
+ declare function useWidgetState<T extends Record<string, unknown>>(initialState: T | (() => T)): [T, (newState: T | ((prev: T) => T)) => void];
1365
+
1219
1366
  declare function CardTitle({ className, ...props }: React.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
1220
1367
  declare function CardDescription({ className, ...props }: React.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
1221
1368
 
@@ -1623,4 +1770,4 @@ interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size'>
1623
1770
  */
1624
1771
  declare const Input: React__default.ForwardRefExoticComponent<InputProps & React__default.RefAttributes<HTMLInputElement>>;
1625
1772
 
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 };
1773
+ export { ActionButton, type ActionButtonProps, Alert, AlertDescription, AlertTitle, type AppInfo, type AppOptions, AppProvider, type AppProviderProps, AppShell, type AppShellProps, type AuthUser, 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 UseAuthReturn, 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, useAuth, 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,120 @@ interface UseToolSubscriptionResult<T = unknown> {
1216
1249
  */
1217
1250
  declare function useToolSubscription<T = unknown>(toolName: string, options?: UseToolSubscriptionOptions): UseToolSubscriptionResult<T>;
1218
1251
 
1252
+ /**
1253
+ * useAuth - Authentication hook for GPT Apps
1254
+ *
1255
+ * Provides auth status and triggers ChatGPT's OAuth linking UI
1256
+ * when tools return _meta["mcp/www_authenticate"].
1257
+ */
1258
+ /**
1259
+ * Authenticated user info
1260
+ */
1261
+ interface AuthUser {
1262
+ /** User ID (subject) */
1263
+ id: string;
1264
+ /** Display name */
1265
+ name?: string;
1266
+ /** Email address */
1267
+ email?: string;
1268
+ /** Profile picture URL */
1269
+ picture?: string;
1270
+ }
1271
+ /**
1272
+ * Return type for useAuth hook
1273
+ */
1274
+ interface UseAuthReturn {
1275
+ /** Whether user is authenticated */
1276
+ isAuthenticated: boolean;
1277
+ /** Currently authenticated user (if any) */
1278
+ user: AuthUser | null;
1279
+ /** Loading state */
1280
+ loading: boolean;
1281
+ /** Authentication error (if any) */
1282
+ error: Error | null;
1283
+ /** Trigger an auth-required tool to initiate OAuth flow */
1284
+ triggerAuth: () => Promise<void>;
1285
+ /** Clear auth state (for sign-out UI) */
1286
+ clearAuth: () => void;
1287
+ }
1288
+ /**
1289
+ * Authentication hook for GPT Apps
1290
+ *
1291
+ * In ChatGPT, authentication is triggered automatically when a tool
1292
+ * returns `_meta["mcp/www_authenticate"]`. Use this hook to:
1293
+ *
1294
+ * 1. Check if the user is authenticated
1295
+ * 2. Show loading state during auth
1296
+ * 3. Display user info after auth
1297
+ * 4. Manually trigger auth by calling an auth-required tool
1298
+ *
1299
+ * @example
1300
+ * ```tsx
1301
+ * function MyComponent() {
1302
+ * const { isAuthenticated, user, triggerAuth, loading } = useAuth();
1303
+ *
1304
+ * if (loading) return <div>Authenticating...</div>;
1305
+ *
1306
+ * if (!isAuthenticated) {
1307
+ * return (
1308
+ * <Button onClick={triggerAuth}>
1309
+ * Sign in with GitHub
1310
+ * </Button>
1311
+ * );
1312
+ * }
1313
+ *
1314
+ * return <div>Welcome, {user?.name}!</div>;
1315
+ * }
1316
+ * ```
1317
+ */
1318
+ declare function useAuth(): UseAuthReturn;
1319
+
1320
+ interface OpenAiGlobals {
1321
+ toolInput: Record<string, unknown>;
1322
+ toolOutput: any;
1323
+ toolResponseMetadata: Record<string, unknown>;
1324
+ widgetState: Record<string, unknown>;
1325
+ theme: 'light' | 'dark';
1326
+ displayMode: 'inline' | 'modal' | 'fullscreen';
1327
+ maxHeight: number;
1328
+ safeArea: {
1329
+ top: number;
1330
+ right: number;
1331
+ bottom: number;
1332
+ left: number;
1333
+ };
1334
+ view: 'desktop' | 'mobile';
1335
+ locale: string;
1336
+ }
1337
+ /**
1338
+ * React hook to subscribe to window.openai global values.
1339
+ * Source: https://developers.openai.com/apps-sdk/build/chatgpt-ui#useopenaiglobal
1340
+ */
1341
+ declare function useOpenAiGlobal<K extends keyof OpenAiGlobals>(key: K): OpenAiGlobals[K] | undefined;
1342
+
1343
+ /**
1344
+ * Access the structured content returned by the tool.
1345
+ * Maps to 'structuredContent' in the tool response.
1346
+ */
1347
+ declare function useToolOutput<T = any>(): T | undefined;
1348
+ /**
1349
+ * Access metadata about the tool response.
1350
+ * Maps to '_meta' in the tool response.
1351
+ */
1352
+ declare function useToolResponseMetadata<T = any>(): T | undefined;
1353
+ /**
1354
+ * Access the input arguments passed to the tool.
1355
+ */
1356
+ declare function useToolInput<T = any>(): T | undefined;
1357
+
1358
+ /**
1359
+ * Hook to read and write widget state.
1360
+ * Widget state persists across the session for this specific widget instance.
1361
+ *
1362
+ * @param initialState - Default state if none exists
1363
+ */
1364
+ declare function useWidgetState<T extends Record<string, unknown>>(initialState: T | (() => T)): [T, (newState: T | ((prev: T) => T)) => void];
1365
+
1219
1366
  declare function CardTitle({ className, ...props }: React.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
1220
1367
  declare function CardDescription({ className, ...props }: React.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
1221
1368
 
@@ -1623,4 +1770,4 @@ interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size'>
1623
1770
  */
1624
1771
  declare const Input: React__default.ForwardRefExoticComponent<InputProps & React__default.RefAttributes<HTMLInputElement>>;
1625
1772
 
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 };
1773
+ export { ActionButton, type ActionButtonProps, Alert, AlertDescription, AlertTitle, type AppInfo, type AppOptions, AppProvider, type AppProviderProps, AppShell, type AppShellProps, type AuthUser, 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 UseAuthReturn, 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, useAuth, 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
@@ -2666,6 +2666,134 @@ function useToolSubscription(toolName, options = {}) {
2666
2666
  };
2667
2667
  }
2668
2668
  chunk2HRO6CFU_js.__name(useToolSubscription, "useToolSubscription");
2669
+ function useAuth() {
2670
+ const { callTool, isConnected } = useGptApp();
2671
+ const [isAuthenticated, setIsAuthenticated] = React26.useState(false);
2672
+ const [user, setUser] = React26.useState(null);
2673
+ const [loading, setLoading] = React26.useState(false);
2674
+ const [error, setError] = React26.useState(null);
2675
+ const checkAuthStatus = React26.useCallback(async () => {
2676
+ if (!isConnected) return;
2677
+ try {
2678
+ const result = await callTool("getAuthStatus", {});
2679
+ if (result && result.user) {
2680
+ setIsAuthenticated(true);
2681
+ setUser(result.user);
2682
+ } else {
2683
+ setIsAuthenticated(false);
2684
+ setUser(null);
2685
+ }
2686
+ } catch (err) {
2687
+ setIsAuthenticated(false);
2688
+ setUser(null);
2689
+ }
2690
+ }, [
2691
+ callTool,
2692
+ isConnected
2693
+ ]);
2694
+ const triggerAuth = React26.useCallback(async () => {
2695
+ if (!isConnected) {
2696
+ setError(new Error("Not connected to ChatGPT"));
2697
+ return;
2698
+ }
2699
+ setLoading(true);
2700
+ setError(null);
2701
+ try {
2702
+ const result = await callTool("checkAuth", {});
2703
+ if (result && result.user) {
2704
+ setIsAuthenticated(true);
2705
+ setUser(result.user);
2706
+ } else if (result && result.success) {
2707
+ setIsAuthenticated(true);
2708
+ await checkAuthStatus();
2709
+ }
2710
+ } catch (err) {
2711
+ setError(err);
2712
+ } finally {
2713
+ setLoading(false);
2714
+ }
2715
+ }, [
2716
+ callTool,
2717
+ isConnected,
2718
+ checkAuthStatus
2719
+ ]);
2720
+ const clearAuth = React26.useCallback(() => {
2721
+ setIsAuthenticated(false);
2722
+ setUser(null);
2723
+ setError(null);
2724
+ }, []);
2725
+ React26.useEffect(() => {
2726
+ if (isConnected) {
2727
+ checkAuthStatus().catch(() => {
2728
+ });
2729
+ }
2730
+ }, [
2731
+ isConnected,
2732
+ checkAuthStatus
2733
+ ]);
2734
+ return {
2735
+ isAuthenticated,
2736
+ user,
2737
+ loading,
2738
+ error,
2739
+ triggerAuth,
2740
+ clearAuth
2741
+ };
2742
+ }
2743
+ chunk2HRO6CFU_js.__name(useAuth, "useAuth");
2744
+ var SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
2745
+ function useOpenAiGlobal(key) {
2746
+ return React26.useSyncExternalStore((onChange) => {
2747
+ const handleSetGlobal = /* @__PURE__ */ chunk2HRO6CFU_js.__name((event) => {
2748
+ const customEvent = event;
2749
+ const value = customEvent.detail?.globals?.[key];
2750
+ if (value !== void 0) {
2751
+ onChange();
2752
+ }
2753
+ }, "handleSetGlobal");
2754
+ window.addEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal, {
2755
+ passive: true
2756
+ });
2757
+ return () => {
2758
+ window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);
2759
+ };
2760
+ }, () => window.openai?.[key]);
2761
+ }
2762
+ chunk2HRO6CFU_js.__name(useOpenAiGlobal, "useOpenAiGlobal");
2763
+
2764
+ // src/mcp/useToolData.ts
2765
+ function useToolOutput() {
2766
+ return useOpenAiGlobal("toolOutput");
2767
+ }
2768
+ chunk2HRO6CFU_js.__name(useToolOutput, "useToolOutput");
2769
+ function useToolResponseMetadata() {
2770
+ return useOpenAiGlobal("toolResponseMetadata");
2771
+ }
2772
+ chunk2HRO6CFU_js.__name(useToolResponseMetadata, "useToolResponseMetadata");
2773
+ function useToolInput2() {
2774
+ return useOpenAiGlobal("toolInput");
2775
+ }
2776
+ chunk2HRO6CFU_js.__name(useToolInput2, "useToolInput");
2777
+ function useWidgetState(initialState) {
2778
+ const rawState = useOpenAiGlobal("widgetState");
2779
+ const resolvedInitial = rawState ?? (typeof initialState === "function" ? initialState() : initialState);
2780
+ const setWidgetState = React26.useCallback((newStateOrUpdater) => {
2781
+ if (!window.openai?.setWidgetState) {
2782
+ console.warn("window.openai.setWidgetState is not available");
2783
+ return;
2784
+ }
2785
+ const current = window.openai.widgetState ?? resolvedInitial;
2786
+ const next = typeof newStateOrUpdater === "function" ? newStateOrUpdater(current) : newStateOrUpdater;
2787
+ window.openai.setWidgetState(next);
2788
+ }, [
2789
+ resolvedInitial
2790
+ ]);
2791
+ return [
2792
+ resolvedInitial,
2793
+ setWidgetState
2794
+ ];
2795
+ }
2796
+ chunk2HRO6CFU_js.__name(useWidgetState, "useWidgetState");
2669
2797
 
2670
2798
  // src/types/mcp-types.ts
2671
2799
  function normalizeToolBinding(tool) {
@@ -3599,19 +3727,25 @@ exports.badgeVariants = badgeVariants;
3599
3727
  exports.buttonVariants = buttonVariants;
3600
3728
  exports.cn = cn;
3601
3729
  exports.normalizeToolBinding = normalizeToolBinding;
3730
+ exports.useAuth = useAuth;
3602
3731
  exports.useFormField = useFormField;
3603
3732
  exports.useGptApp = useGptApp;
3604
3733
  exports.useGptTool = useGptTool;
3605
3734
  exports.useHostContext = useHostContext;
3606
3735
  exports.useMcpApp = useMcpApp;
3607
3736
  exports.useMessage = useMessage;
3737
+ exports.useOpenAiGlobal = useOpenAiGlobal;
3608
3738
  exports.useResource = useResource;
3609
3739
  exports.useTool = useTool;
3610
3740
  exports.useToolContext = useToolContext;
3611
3741
  exports.useToolInput = useToolInput;
3612
3742
  exports.useToolInputPartial = useToolInputPartial;
3743
+ exports.useToolInputSpec = useToolInput2;
3744
+ exports.useToolOutput = useToolOutput;
3745
+ exports.useToolResponseMetadata = useToolResponseMetadata;
3613
3746
  exports.useToolResult = useToolResult;
3614
3747
  exports.useToolStream = useToolStream;
3615
3748
  exports.useToolSubscription = useToolSubscription;
3749
+ exports.useWidgetState = useWidgetState;
3616
3750
  //# sourceMappingURL=index.js.map
3617
3751
  //# sourceMappingURL=index.js.map