@leanmcp/ui 0.3.2 → 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 +1 -1
- package/dist/index.d.mts +69 -1
- package/dist/index.d.ts +69 -1
- package/dist/index.js +76 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +76 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1249,6 +1249,74 @@ interface UseToolSubscriptionResult<T = unknown> {
|
|
|
1249
1249
|
*/
|
|
1250
1250
|
declare function useToolSubscription<T = unknown>(toolName: string, options?: UseToolSubscriptionOptions): UseToolSubscriptionResult<T>;
|
|
1251
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
|
+
|
|
1252
1320
|
interface OpenAiGlobals {
|
|
1253
1321
|
toolInput: Record<string, unknown>;
|
|
1254
1322
|
toolOutput: any;
|
|
@@ -1702,4 +1770,4 @@ interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size'>
|
|
|
1702
1770
|
*/
|
|
1703
1771
|
declare const Input: React__default.ForwardRefExoticComponent<InputProps & React__default.RefAttributes<HTMLInputElement>>;
|
|
1704
1772
|
|
|
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 };
|
|
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
|
@@ -1249,6 +1249,74 @@ interface UseToolSubscriptionResult<T = unknown> {
|
|
|
1249
1249
|
*/
|
|
1250
1250
|
declare function useToolSubscription<T = unknown>(toolName: string, options?: UseToolSubscriptionOptions): UseToolSubscriptionResult<T>;
|
|
1251
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
|
+
|
|
1252
1320
|
interface OpenAiGlobals {
|
|
1253
1321
|
toolInput: Record<string, unknown>;
|
|
1254
1322
|
toolOutput: any;
|
|
@@ -1702,4 +1770,4 @@ interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size'>
|
|
|
1702
1770
|
*/
|
|
1703
1771
|
declare const Input: React__default.ForwardRefExoticComponent<InputProps & React__default.RefAttributes<HTMLInputElement>>;
|
|
1704
1772
|
|
|
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 };
|
|
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,81 @@ 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");
|
|
2669
2744
|
var SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
|
|
2670
2745
|
function useOpenAiGlobal(key) {
|
|
2671
2746
|
return React26.useSyncExternalStore((onChange) => {
|
|
@@ -3652,6 +3727,7 @@ exports.badgeVariants = badgeVariants;
|
|
|
3652
3727
|
exports.buttonVariants = buttonVariants;
|
|
3653
3728
|
exports.cn = cn;
|
|
3654
3729
|
exports.normalizeToolBinding = normalizeToolBinding;
|
|
3730
|
+
exports.useAuth = useAuth;
|
|
3655
3731
|
exports.useFormField = useFormField;
|
|
3656
3732
|
exports.useGptApp = useGptApp;
|
|
3657
3733
|
exports.useGptTool = useGptTool;
|