@waniwani/sdk 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-OVQDB7QX.js +3 -0
- package/dist/chunk-OVQDB7QX.js.map +1 -0
- package/dist/chunk-SCDEAZN4.js +3 -0
- package/dist/chunk-SCDEAZN4.js.map +1 -0
- package/dist/mcp/index.d.ts +367 -0
- package/dist/mcp/index.js +2 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/react.d.ts +435 -0
- package/dist/mcp/react.js +68 -0
- package/dist/mcp/react.js.map +1 -0
- package/dist/mcp-apps-client-BU7EN3Z2.js +3 -0
- package/dist/mcp-apps-client-BU7EN3Z2.js.map +1 -0
- package/dist/openai-client-UL6T463M.js +3 -0
- package/dist/openai-client-UL6T463M.js.map +1 -0
- package/dist/platform-4QZXTYT5.js +3 -0
- package/dist/platform-4QZXTYT5.js.map +1 -0
- package/package.json +40 -6
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React$1, { ReactNode, SetStateAction } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* Initializes & patches Next.js functionalities
|
|
7
|
+
* so it can be run inside the ChatGPT iframe:
|
|
8
|
+
* - history.pushState / history.replaceState - Prevents full-origin URLs in history
|
|
9
|
+
* - window.fetch - Rewrites same-origin requests to use the correct base URL
|
|
10
|
+
* - html attribute observer - Prevents ChatGPT from modifying the root element
|
|
11
|
+
*
|
|
12
|
+
* More information about this component can be found here:
|
|
13
|
+
*
|
|
14
|
+
* https://vercel.com/blog/running-next-js-inside-chatgpt-a-deep-dive-into-native-app-integration
|
|
15
|
+
*/
|
|
16
|
+
declare function InitializeNextJsInChatGpt({ baseUrl }: {
|
|
17
|
+
baseUrl: string;
|
|
18
|
+
}): react_jsx_runtime.JSX.Element;
|
|
19
|
+
|
|
20
|
+
interface DevControlsProps {
|
|
21
|
+
defaultProps?: Record<string, unknown>;
|
|
22
|
+
widgetPaths?: string[];
|
|
23
|
+
}
|
|
24
|
+
declare function DevModeProvider({ defaultProps, widgetPaths, children, }: DevControlsProps & {
|
|
25
|
+
children: React.ReactNode;
|
|
26
|
+
}): react_jsx_runtime.JSX.Element | null;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Source: https://github.com/openai/openai-apps-sdk-examples/tree/main/src
|
|
30
|
+
*/
|
|
31
|
+
type OpenAIGlobals<ToolInput = UnknownObject, ToolOutput = UnknownObject, ToolResponseMetadata = UnknownObject, WidgetState = UnknownObject> = {
|
|
32
|
+
theme: Theme;
|
|
33
|
+
userAgent: UserAgent;
|
|
34
|
+
locale: string;
|
|
35
|
+
maxHeight: number;
|
|
36
|
+
displayMode: DisplayMode;
|
|
37
|
+
safeArea: SafeArea;
|
|
38
|
+
toolInput: ToolInput;
|
|
39
|
+
toolOutput: ToolOutput | null;
|
|
40
|
+
toolResponseMetadata: ToolResponseMetadata | null;
|
|
41
|
+
widgetState: WidgetState | null;
|
|
42
|
+
setWidgetState: (state: WidgetState) => Promise<void>;
|
|
43
|
+
};
|
|
44
|
+
type API = {
|
|
45
|
+
callTool: CallTool;
|
|
46
|
+
sendFollowUpMessage: (args: {
|
|
47
|
+
prompt: string;
|
|
48
|
+
}) => Promise<void>;
|
|
49
|
+
openExternal(payload: {
|
|
50
|
+
href: string;
|
|
51
|
+
}): void;
|
|
52
|
+
requestDisplayMode: RequestDisplayMode;
|
|
53
|
+
};
|
|
54
|
+
type UnknownObject = Record<string, unknown>;
|
|
55
|
+
type Theme = "light" | "dark";
|
|
56
|
+
type SafeAreaInsets = {
|
|
57
|
+
top: number;
|
|
58
|
+
bottom: number;
|
|
59
|
+
left: number;
|
|
60
|
+
right: number;
|
|
61
|
+
};
|
|
62
|
+
type SafeArea = {
|
|
63
|
+
insets: SafeAreaInsets;
|
|
64
|
+
};
|
|
65
|
+
type DeviceType = "mobile" | "tablet" | "desktop" | "unknown";
|
|
66
|
+
type UserAgent = {
|
|
67
|
+
device: {
|
|
68
|
+
type: DeviceType;
|
|
69
|
+
};
|
|
70
|
+
capabilities: {
|
|
71
|
+
hover: boolean;
|
|
72
|
+
touch: boolean;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
/** Display mode */
|
|
76
|
+
type DisplayMode = "pip" | "inline" | "fullscreen";
|
|
77
|
+
type RequestDisplayMode = (args: {
|
|
78
|
+
mode: DisplayMode;
|
|
79
|
+
}) => Promise<{
|
|
80
|
+
/**
|
|
81
|
+
* The granted display mode. The host may reject the request.
|
|
82
|
+
* For mobile, PiP is always coerced to fullscreen.
|
|
83
|
+
*/
|
|
84
|
+
mode: DisplayMode;
|
|
85
|
+
}>;
|
|
86
|
+
type CallToolResponse = {
|
|
87
|
+
result: string;
|
|
88
|
+
};
|
|
89
|
+
/** Calling APIs */
|
|
90
|
+
type CallTool = (name: string, args: Record<string, unknown>) => Promise<CallToolResponse>;
|
|
91
|
+
/** Extra events */
|
|
92
|
+
declare const SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
|
|
93
|
+
declare class SetGlobalsEvent extends CustomEvent<{
|
|
94
|
+
globals: Partial<OpenAIGlobals>;
|
|
95
|
+
}> {
|
|
96
|
+
constructor(detail: {
|
|
97
|
+
globals: Partial<OpenAIGlobals>;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Global oai object injected by the web sandbox for communicating with chatgpt host page.
|
|
102
|
+
*/
|
|
103
|
+
declare global {
|
|
104
|
+
interface Window {
|
|
105
|
+
openai: API & OpenAIGlobals;
|
|
106
|
+
innerBaseUrl: string;
|
|
107
|
+
}
|
|
108
|
+
interface WindowEventMap {
|
|
109
|
+
[SET_GLOBALS_EVENT_TYPE]: SetGlobalsEvent;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
declare let mockState: Omit<OpenAIGlobals, "setWidgetState">;
|
|
114
|
+
declare function initializeMockOpenAI(initialToolOutput?: Record<string, unknown>): void;
|
|
115
|
+
declare function updateMockGlobal<K extends keyof OpenAIGlobals>(key: K, value: OpenAIGlobals[K]): void;
|
|
116
|
+
declare function getMockState(): typeof mockState;
|
|
117
|
+
declare function updateMockToolOutput(props: Record<string, unknown>): void;
|
|
118
|
+
declare function updateMockDisplayMode(mode: DisplayMode): void;
|
|
119
|
+
declare function updateMockTheme(theme: Theme): void;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Result from calling a tool
|
|
123
|
+
*/
|
|
124
|
+
type ToolCallResult = {
|
|
125
|
+
content?: Array<{
|
|
126
|
+
type: string;
|
|
127
|
+
text?: string;
|
|
128
|
+
}>;
|
|
129
|
+
structuredContent?: Record<string, unknown>;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Tool result notification (what the host pushes to the widget)
|
|
133
|
+
*/
|
|
134
|
+
type ToolResult = {
|
|
135
|
+
content?: Array<{
|
|
136
|
+
type: string;
|
|
137
|
+
text?: string;
|
|
138
|
+
}>;
|
|
139
|
+
structuredContent?: Record<string, unknown>;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Unified widget client interface that works on both OpenAI and MCP Apps.
|
|
143
|
+
*
|
|
144
|
+
* Platform-specific behavior:
|
|
145
|
+
* - Display mode: OpenAI-only. MCP Apps returns "inline" and requestDisplayMode is a no-op.
|
|
146
|
+
* - Follow-up messages: Unified API, different underlying implementations.
|
|
147
|
+
*/
|
|
148
|
+
interface UnifiedWidgetClient {
|
|
149
|
+
/**
|
|
150
|
+
* Connect to the host. Must be called before using other methods.
|
|
151
|
+
* On OpenAI, this is a no-op (already connected via window.openai).
|
|
152
|
+
* On MCP Apps, this establishes the postMessage connection.
|
|
153
|
+
*/
|
|
154
|
+
connect(): Promise<void>;
|
|
155
|
+
/**
|
|
156
|
+
* Get the tool output (structured content returned by the tool handler).
|
|
157
|
+
* This is the main data source for widget rendering.
|
|
158
|
+
*/
|
|
159
|
+
getToolOutput<T = Record<string, unknown>>(): T | null;
|
|
160
|
+
/**
|
|
161
|
+
* Register a callback for when tool results are received.
|
|
162
|
+
* On OpenAI, this subscribes to toolOutput changes.
|
|
163
|
+
* On MCP Apps, this sets app.ontoolresult.
|
|
164
|
+
*/
|
|
165
|
+
onToolResult(callback: (result: ToolResult) => void): () => void;
|
|
166
|
+
/**
|
|
167
|
+
* Call another tool on the server.
|
|
168
|
+
*/
|
|
169
|
+
callTool(name: string, args: Record<string, unknown>): Promise<ToolCallResult>;
|
|
170
|
+
/**
|
|
171
|
+
* Open an external URL.
|
|
172
|
+
* On OpenAI: openai.openExternal({ href })
|
|
173
|
+
* On MCP Apps: app.sendOpenLink(url)
|
|
174
|
+
*/
|
|
175
|
+
openExternal(url: string): void;
|
|
176
|
+
/**
|
|
177
|
+
* Send a follow-up message to the AI.
|
|
178
|
+
* On OpenAI: openai.sendFollowUpMessage({ prompt })
|
|
179
|
+
* On MCP Apps: app.sendMessages([{ role: 'user', content: { type: 'text', text: prompt } }])
|
|
180
|
+
*/
|
|
181
|
+
sendFollowUp(prompt: string): void;
|
|
182
|
+
/**
|
|
183
|
+
* Get the current theme.
|
|
184
|
+
*/
|
|
185
|
+
getTheme(): Theme;
|
|
186
|
+
/**
|
|
187
|
+
* Subscribe to theme changes.
|
|
188
|
+
*/
|
|
189
|
+
onThemeChange(callback: (theme: Theme) => void): () => void;
|
|
190
|
+
/**
|
|
191
|
+
* Get the current locale.
|
|
192
|
+
*/
|
|
193
|
+
getLocale(): string;
|
|
194
|
+
/**
|
|
195
|
+
* Get the current display mode.
|
|
196
|
+
* OpenAI-only: returns "pip" | "inline" | "fullscreen"
|
|
197
|
+
* MCP Apps: always returns "inline"
|
|
198
|
+
*/
|
|
199
|
+
getDisplayMode(): DisplayMode;
|
|
200
|
+
/**
|
|
201
|
+
* Request a display mode change.
|
|
202
|
+
* OpenAI-only: requests the mode from the host.
|
|
203
|
+
* MCP Apps: no-op (returns current mode).
|
|
204
|
+
*/
|
|
205
|
+
requestDisplayMode(mode: DisplayMode): Promise<DisplayMode>;
|
|
206
|
+
/**
|
|
207
|
+
* Subscribe to display mode changes.
|
|
208
|
+
* OpenAI-only: subscribes to displayMode changes.
|
|
209
|
+
* MCP Apps: callback is never called.
|
|
210
|
+
*/
|
|
211
|
+
onDisplayModeChange(callback: (mode: DisplayMode) => void): () => void;
|
|
212
|
+
/**
|
|
213
|
+
* Get the safe area insets.
|
|
214
|
+
* OpenAI-only: returns insets from window.openai.safeArea.
|
|
215
|
+
* MCP Apps: returns null.
|
|
216
|
+
*/
|
|
217
|
+
getSafeArea(): SafeArea | null;
|
|
218
|
+
/**
|
|
219
|
+
* Subscribe to safe area changes.
|
|
220
|
+
* OpenAI-only: subscribes to safeArea changes.
|
|
221
|
+
* MCP Apps: callback is never called.
|
|
222
|
+
*/
|
|
223
|
+
onSafeAreaChange(callback: (safeArea: SafeArea | null) => void): () => void;
|
|
224
|
+
/**
|
|
225
|
+
* Get the max height constraint.
|
|
226
|
+
* OpenAI-only: returns maxHeight from window.openai.maxHeight.
|
|
227
|
+
* MCP Apps: returns null.
|
|
228
|
+
*/
|
|
229
|
+
getMaxHeight(): number | null;
|
|
230
|
+
/**
|
|
231
|
+
* Subscribe to max height changes.
|
|
232
|
+
* OpenAI-only: subscribes to maxHeight changes.
|
|
233
|
+
* MCP Apps: callback is never called.
|
|
234
|
+
*/
|
|
235
|
+
onMaxHeightChange(callback: (maxHeight: number | null) => void): () => void;
|
|
236
|
+
/**
|
|
237
|
+
* Get the tool response metadata.
|
|
238
|
+
* OpenAI-only: returns metadata from window.openai.toolResponseMetadata.
|
|
239
|
+
* MCP Apps: returns null.
|
|
240
|
+
*/
|
|
241
|
+
getToolResponseMetadata(): UnknownObject | null;
|
|
242
|
+
/**
|
|
243
|
+
* Subscribe to tool response metadata changes.
|
|
244
|
+
* OpenAI-only: subscribes to toolResponseMetadata changes.
|
|
245
|
+
* MCP Apps: callback is never called.
|
|
246
|
+
*/
|
|
247
|
+
onToolResponseMetadataChange(callback: (metadata: UnknownObject | null) => void): () => void;
|
|
248
|
+
/**
|
|
249
|
+
* Get the widget state.
|
|
250
|
+
* OpenAI-only: returns state from window.openai.widgetState.
|
|
251
|
+
* MCP Apps: returns null.
|
|
252
|
+
*/
|
|
253
|
+
getWidgetState(): UnknownObject | null;
|
|
254
|
+
/**
|
|
255
|
+
* Subscribe to widget state changes.
|
|
256
|
+
* OpenAI-only: subscribes to widgetState changes.
|
|
257
|
+
* MCP Apps: callback is never called.
|
|
258
|
+
*/
|
|
259
|
+
onWidgetStateChange(callback: (state: UnknownObject | null) => void): () => void;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Get a function to call other tools.
|
|
264
|
+
* Works on both OpenAI widgets and MCP Apps.
|
|
265
|
+
*
|
|
266
|
+
* @returns A function to call tools with their name and arguments
|
|
267
|
+
*/
|
|
268
|
+
declare function useCallTool(): (name: string, args: Record<string, unknown>) => Promise<ToolCallResult>;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Get the current display mode.
|
|
272
|
+
* Works on both OpenAI widgets and MCP Apps.
|
|
273
|
+
*
|
|
274
|
+
* @returns The current display mode ("pip" | "inline" | "fullscreen")
|
|
275
|
+
*/
|
|
276
|
+
declare function useDisplayMode(): DisplayMode;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Check if running in ChatGPT app (OpenAI-only).
|
|
280
|
+
* Returns false on MCP Apps.
|
|
281
|
+
*
|
|
282
|
+
* @returns Whether the widget is running in ChatGPT app
|
|
283
|
+
*/
|
|
284
|
+
declare function useIsChatGptApp(): boolean;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Get the current locale.
|
|
288
|
+
* Works on both OpenAI widgets and MCP Apps.
|
|
289
|
+
*
|
|
290
|
+
* @returns The current locale string (e.g., "en-US")
|
|
291
|
+
*/
|
|
292
|
+
declare function useLocale(): string;
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Get the maximum height available for the widget (OpenAI-only).
|
|
296
|
+
* Useful for responsive layouts that need to adapt to container constraints.
|
|
297
|
+
* Returns null on MCP Apps.
|
|
298
|
+
*
|
|
299
|
+
* @returns The maximum height in pixels, or null if not available
|
|
300
|
+
*/
|
|
301
|
+
declare function useMaxHeight(): number | null;
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Get a function to open external URLs.
|
|
305
|
+
* Works on both OpenAI widgets and MCP Apps.
|
|
306
|
+
*
|
|
307
|
+
* @returns A function that opens external URLs
|
|
308
|
+
*/
|
|
309
|
+
declare function useOpenExternal(): (url: string) => void;
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Get a function to request display mode changes.
|
|
313
|
+
* On MCP Apps, this may be a no-op depending on host support.
|
|
314
|
+
*
|
|
315
|
+
* @returns A function to request a specific display mode
|
|
316
|
+
*/
|
|
317
|
+
declare function useRequestDisplayMode(): (mode: DisplayMode) => Promise<DisplayMode>;
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Get safe area insets (OpenAI-only).
|
|
321
|
+
* Useful for ensuring UI elements don't get hidden behind the chat input.
|
|
322
|
+
* Returns null on MCP Apps.
|
|
323
|
+
*
|
|
324
|
+
* @returns The safe area insets, or null if not available
|
|
325
|
+
*/
|
|
326
|
+
declare function useSafeArea(): SafeArea | null;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Get a function to send follow-up messages to the AI.
|
|
330
|
+
* Works on both OpenAI widgets and MCP Apps.
|
|
331
|
+
*
|
|
332
|
+
* @returns A function that sends a follow-up message
|
|
333
|
+
*/
|
|
334
|
+
declare function useSendFollowUp(): (prompt: string) => void;
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Get the current theme.
|
|
338
|
+
* Works on both OpenAI widgets and MCP Apps.
|
|
339
|
+
*
|
|
340
|
+
* @returns The current theme ("light" | "dark")
|
|
341
|
+
*/
|
|
342
|
+
declare function useTheme(): Theme;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Get the tool output (structured content returned by the tool handler).
|
|
346
|
+
* Works on both OpenAI widgets and MCP Apps.
|
|
347
|
+
*
|
|
348
|
+
* @returns The tool output or null
|
|
349
|
+
*/
|
|
350
|
+
declare function useToolOutput<T extends Record<string, unknown>>(): T | null;
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Get tool response metadata (OpenAI-only).
|
|
354
|
+
* Contains identifiers like `openai/widgetSessionId` for correlating
|
|
355
|
+
* multiple tool calls or logs for the same widget instance.
|
|
356
|
+
* Returns null on MCP Apps.
|
|
357
|
+
*
|
|
358
|
+
* @returns The tool response metadata object or null if not available
|
|
359
|
+
*/
|
|
360
|
+
declare function useToolResponseMetadata(): UnknownObject | null;
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Provider props
|
|
364
|
+
*/
|
|
365
|
+
interface WidgetProviderProps {
|
|
366
|
+
children: ReactNode;
|
|
367
|
+
/** Optional loading component while connecting */
|
|
368
|
+
loading?: ReactNode;
|
|
369
|
+
/** Optional error component */
|
|
370
|
+
onError?: (error: Error) => ReactNode;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Provider component that initializes the correct widget client based on platform.
|
|
374
|
+
* Wrap your widget component with this provider.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```tsx
|
|
378
|
+
* function App() {
|
|
379
|
+
* return (
|
|
380
|
+
* <WidgetProvider loading={<Spinner />}>
|
|
381
|
+
* <MyWidget />
|
|
382
|
+
* </WidgetProvider>
|
|
383
|
+
* );
|
|
384
|
+
* }
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
declare function WidgetProvider({ children, loading, onError, }: WidgetProviderProps): React$1.FunctionComponentElement<React$1.FragmentProps> | React$1.FunctionComponentElement<React$1.ProviderProps<UnifiedWidgetClient | null>>;
|
|
388
|
+
/**
|
|
389
|
+
* Keys that can be selected from the widget client.
|
|
390
|
+
*/
|
|
391
|
+
type WidgetKey = "toolOutput" | "theme" | "displayMode" | "locale" | "safeArea" | "maxHeight" | "toolResponseMetadata" | "widgetState";
|
|
392
|
+
/**
|
|
393
|
+
* Value types for each widget key.
|
|
394
|
+
*/
|
|
395
|
+
type WidgetKeyValues = {
|
|
396
|
+
toolOutput: Record<string, unknown> | null;
|
|
397
|
+
theme: Theme;
|
|
398
|
+
displayMode: DisplayMode;
|
|
399
|
+
locale: string;
|
|
400
|
+
safeArea: SafeArea | null;
|
|
401
|
+
maxHeight: number | null;
|
|
402
|
+
toolResponseMetadata: UnknownObject | null;
|
|
403
|
+
widgetState: UnknownObject | null;
|
|
404
|
+
};
|
|
405
|
+
/**
|
|
406
|
+
* Get the unified widget client instance.
|
|
407
|
+
* Must be used within a WidgetProvider.
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* ```tsx
|
|
411
|
+
* // Full client for actions
|
|
412
|
+
* const client = useWidgetClient();
|
|
413
|
+
* client.callTool("foo", {});
|
|
414
|
+
*
|
|
415
|
+
* // Key selector for reactive values
|
|
416
|
+
* const toolOutput = useWidgetClient("toolOutput");
|
|
417
|
+
* const theme = useWidgetClient("theme");
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
420
|
+
declare function useWidgetClient(): UnifiedWidgetClient;
|
|
421
|
+
declare function useWidgetClient<K extends WidgetKey>(key: K): WidgetKeyValues[K];
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Widget state that persists across widget lifecycles (OpenAI-only).
|
|
425
|
+
* State is synchronized with the ChatGPT parent window and survives widget minimize/restore.
|
|
426
|
+
* On MCP Apps, returns [null, no-op].
|
|
427
|
+
*
|
|
428
|
+
* @param defaultState - Initial state value or function to compute it
|
|
429
|
+
* @returns A tuple of [state, setState] similar to useState
|
|
430
|
+
*/
|
|
431
|
+
declare function useWidgetState<T extends UnknownObject>(defaultState?: T | (() => T | null) | null): readonly [T | null, (state: SetStateAction<T | null>) => void];
|
|
432
|
+
|
|
433
|
+
declare const LoadingWidget: () => react_jsx_runtime.JSX.Element;
|
|
434
|
+
|
|
435
|
+
export { DevModeProvider, type DeviceType, type DisplayMode, InitializeNextJsInChatGpt, LoadingWidget, type SafeArea, type SafeAreaInsets, type Theme, type UnknownObject, type UserAgent, WidgetProvider, getMockState, initializeMockOpenAI, updateMockDisplayMode, updateMockGlobal, updateMockTheme, updateMockToolOutput, useCallTool, useDisplayMode, useIsChatGptApp, useLocale, useMaxHeight, useOpenExternal, useRequestDisplayMode, useSafeArea, useSendFollowUp, useTheme, useToolOutput, useToolResponseMetadata, useWidgetClient, useWidgetState };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import{a as $}from"../chunk-SCDEAZN4.js";import{b as T}from"../chunk-OVQDB7QX.js";import{Fragment as Ce,jsx as E,jsxs as Se}from"react/jsx-runtime";function Me({baseUrl:e}){return Se(Ce,{children:[E("base",{href:e}),E("script",{children:`window.innerBaseUrl = ${JSON.stringify(e)}`}),E("script",{children:'window.__isChatGptApp = typeof window.openai !== "undefined";'}),E("script",{children:"("+(()=>{let t=window.innerBaseUrl,i=document.documentElement;new MutationObserver(p=>{p.forEach(n=>{if(n.type==="attributes"&&n.target===i){let d=n.attributeName;d&&d!=="suppresshydrationwarning"&&i.removeAttribute(d)}})}).observe(i,{attributes:!0,attributeOldValue:!0});let u=history.replaceState;history.replaceState=(p,n,d)=>{let r=new URL(d??"",window.location.href),h=r.pathname+r.search+r.hash;u.call(history,n,h)};let c=history.pushState;history.pushState=(p,n,d)=>{let r=new URL(d??"",window.location.href),h=r.pathname+r.search+r.hash;c.call(history,n,h)};let g=new URL(t).origin,f=window.self!==window.top;if(window.addEventListener("click",p=>{let n=p?.target?.closest("a");if(!n||!n.href)return;let d=new URL(n.href,window.location.href);if(d.origin!==window.location.origin&&d.origin!==g)try{window.openai&&(window.openai?.openExternal({href:n.href}),p.preventDefault())}catch{console.warn("openExternal failed, likely not in OpenAI client")}},!0),f&&window.location.origin!==g){let p=window.fetch;window.fetch=(n,d)=>{let r;if(typeof n=="string"||n instanceof URL?r=new URL(n,window.location.href):r=new URL(n.url,window.location.href),r.origin===g)return typeof n=="string"||n instanceof URL?n=r.toString():n=new Request(r.toString(),n),p.call(window,n,{...d,mode:"cors"});if(r.origin===window.location.origin){let h=new URL(t);return h.pathname=r.pathname,h.search=r.search,h.hash=r.hash,r=h,typeof n=="string"||n instanceof URL?n=r.toString():n=new Request(r.toString(),n),p.call(window,n,{...d,mode:"cors"})}return p.call(window,n,d)}}}).toString()+")()"})]})}import{useCallback as w,useEffect as M,useRef as K,useState as b}from"react";var J={theme:"dark",userAgent:{device:{type:"desktop"},capabilities:{hover:!0,touch:!1}},locale:"en",maxHeight:800,displayMode:"inline",safeArea:{insets:{top:0,bottom:0,left:0,right:0}},toolInput:{},toolOutput:null,toolResponseMetadata:null,widgetState:null},N={...J};function R(e){typeof window>"u"||window.openai||(N={...J,toolOutput:e??null},window.openai={...N,requestDisplayMode:async({mode:t})=>(v("displayMode",t),{mode:t}),callTool:async(t,i)=>(console.log(`[DevMode] callTool: ${t}`,i),{result:JSON.stringify({mock:!0,tool:t,args:i})}),sendFollowUpMessage:async({prompt:t})=>{console.log(`[DevMode] sendFollowUpMessage: ${t}`)},openExternal:({href:t})=>{console.log(`[DevMode] openExternal: ${t}`),window.open(t,"_blank")},setWidgetState:async t=>{v("widgetState",t)}},window.dispatchEvent(new T({globals:N})))}function v(e,t){typeof window>"u"||!window.openai||(N[e]=t,window.openai[e]=t,window.dispatchEvent(new T({globals:{[e]:t}})))}function U(){return{...N}}function W(e){v("toolOutput",e)}function O(e){v("displayMode",e)}function A(e){v("theme",e)}import{Fragment as B,jsx as o,jsxs as s}from"react/jsx-runtime";var L=150;function q({className:e}){return s("svg",{className:e,viewBox:"0 0 24 24",fill:"none",role:"img","aria-label":"Dev Controls",children:[o("rect",{x:"4",y:"4",width:"10",height:"10",rx:"2",stroke:"currentColor",strokeWidth:"1.5"}),o("rect",{x:"10",y:"10",width:"10",height:"10",rx:"2",stroke:"currentColor",strokeWidth:"1.5",fill:"currentColor",fillOpacity:"0.15"})]})}function Te({className:e}){return o("svg",{"aria-hidden":"true",className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:o("path",{d:"M18 6L6 18M6 6l12 12"})})}function Ne({className:e}){return o("svg",{"aria-hidden":"true",className:e,viewBox:"0 0 16 16",fill:"none",children:o("rect",{x:"2",y:"4",width:"12",height:"8",rx:"1.5",stroke:"currentColor",strokeWidth:"1.25"})})}function Re({className:e}){return s("svg",{"aria-hidden":"true",className:e,viewBox:"0 0 16 16",fill:"none",children:[o("rect",{x:"1.5",y:"3",width:"13",height:"10",rx:"1.5",stroke:"currentColor",strokeWidth:"1.25"}),o("rect",{x:"8.5",y:"7",width:"5",height:"4",rx:"0.75",fill:"currentColor"})]})}function We({className:e}){return o("svg",{"aria-hidden":"true",className:e,viewBox:"0 0 16 16",fill:"none",children:o("path",{d:"M2 5.5V3.5C2 2.95 2.45 2.5 3 2.5H5.5M10.5 2.5H13C13.55 2.5 14 2.95 14 3.5V5.5M14 10.5V12.5C14 13.05 13.55 13.5 13 13.5H10.5M5.5 13.5H3C2.45 13.5 2 13.05 2 12.5V10.5",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})})}function Oe({className:e}){return s("svg",{"aria-hidden":"true",className:e,viewBox:"0 0 16 16",fill:"none",children:[o("circle",{cx:"8",cy:"8",r:"2.5",stroke:"currentColor",strokeWidth:"1.25"}),o("path",{d:"M8 2v1.5M8 12.5V14M2 8h1.5M12.5 8H14M4.11 4.11l1.06 1.06M10.83 10.83l1.06 1.06M4.11 11.89l1.06-1.06M10.83 5.17l1.06-1.06",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round"})]})}function Ae({className:e}){return o("svg",{"aria-hidden":"true",className:e,viewBox:"0 0 16 16",fill:"none",children:o("path",{d:"M13.5 9.5a5.5 5.5 0 01-7-7 5.5 5.5 0 107 7z",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})})}function De({className:e}){return s("svg",{"aria-hidden":"true",className:e,viewBox:"0 0 16 16",fill:"none",children:[o("path",{d:"M2.5 8a5.5 5.5 0 019.37-3.9M13.5 8a5.5 5.5 0 01-9.37 3.9",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round"}),o("path",{d:"M12.5 2v3h-3M3.5 14v-3h3",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})]})}var Ie=`
|
|
3
|
+
@keyframes devPanelSlideIn {
|
|
4
|
+
0% {
|
|
5
|
+
opacity: 0;
|
|
6
|
+
transform: translateY(12px) scale(0.98);
|
|
7
|
+
}
|
|
8
|
+
100% {
|
|
9
|
+
opacity: 1;
|
|
10
|
+
transform: translateY(0) scale(1);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@keyframes devPanelSlideOut {
|
|
15
|
+
0% {
|
|
16
|
+
opacity: 1;
|
|
17
|
+
transform: translateY(0) scale(1);
|
|
18
|
+
}
|
|
19
|
+
100% {
|
|
20
|
+
opacity: 0;
|
|
21
|
+
transform: translateY(8px) scale(0.98);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.dev-panel-enter {
|
|
26
|
+
animation: devPanelSlideIn 200ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.dev-panel-exit {
|
|
30
|
+
animation: devPanelSlideOut 150ms cubic-bezier(0.4, 0, 1, 1) forwards;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.dev-json-editor::-webkit-scrollbar {
|
|
34
|
+
width: 6px;
|
|
35
|
+
height: 6px;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.dev-json-editor::-webkit-scrollbar-track {
|
|
39
|
+
background: transparent;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.dev-json-editor::-webkit-scrollbar-thumb {
|
|
43
|
+
background: rgba(255, 255, 255, 0.1);
|
|
44
|
+
border-radius: 3px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.dev-json-editor::-webkit-scrollbar-thumb:hover {
|
|
48
|
+
background: rgba(255, 255, 255, 0.15);
|
|
49
|
+
}
|
|
50
|
+
`;function Y({defaultProps:e,widgetPaths:t,children:i}){let[m,u]=b(!1),[c,g]=b(!1);return M(()=>{if(new URLSearchParams(window.location.search).get("platform")==="mcp-apps"){u(!0);return}if(t&&t.length>0){let p=window.location.pathname,n=t.some(d=>p===d||p.startsWith(`${d}/`));g(n),n&&R(e)}else R(e),g(!0);u(!0)},[e,t]),m?c?s(B,{children:[o(Ee,{children:i}),o(Ue,{defaultProps:e})]}):o(B,{children:i}):null}function Ee({children:e}){return o("div",{className:"min-h-screen bg-[#212121] flex items-center justify-center p-8",children:o("div",{className:"relative w-full max-w-md overflow-hidden rounded-2xl sm:rounded-3xl border border-[#414141]",style:{boxShadow:"0px 0px 0px 1px #414141, 0px 4px 14px rgba(0,0,0,0.24)"},children:e})})}function V({options:e,value:t,onChange:i}){let m=e.findIndex(u=>u.value===t);return s("div",{className:"relative flex p-0.5 rounded-lg",style:{background:"rgba(255, 255, 255, 0.04)",border:"1px solid rgba(255, 255, 255, 0.06)"},children:[o("div",{className:"absolute top-0.5 bottom-0.5 rounded-md transition-transform duration-150 ease-out",style:{width:`calc(${100/e.length}% - 2px)`,left:"2px",transform:`translateX(calc(${m*100}% + ${m*2}px))`,background:"rgba(255, 255, 255, 0.1)"}}),e.map(u=>s("button",{type:"button",onClick:()=>i(u.value),className:`
|
|
51
|
+
relative z-10 flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5
|
|
52
|
+
text-xs font-medium rounded-md transition-colors duration-150
|
|
53
|
+
${t===u.value?"text-white":"text-gray-400 hover:text-gray-300"}
|
|
54
|
+
`,children:[u.icon,o("span",{className:"capitalize",children:u.label})]},u.value))]})}function Ue({defaultProps:e}){let[t,i]=b(()=>typeof window>"u"?!1:localStorage.getItem("dev-controls-open")==="true"),[m,u]=b(!1),[c,g]=b(t),[f,p]=b("inline"),[n,d]=b("dark"),[r,h]=b(!1),[P,z]=b(()=>JSON.stringify(e??{},null,2)),[C,H]=b(null),S=K(null),fe=K(null),j=K(null);M(()=>{let a=U();p(a.displayMode),d(a.theme)},[]),M(()=>{typeof window>"u"||(window.openai||(window.openai={}),window.openai.safeArea={insets:{top:0,bottom:r?L:0,left:0,right:0}},window.dispatchEvent(new T({globals:{safeArea:window.openai.safeArea}})))},[r]),M(()=>{localStorage.setItem("dev-controls-open",String(t))},[t]);let G=w(()=>{g(!0),requestAnimationFrame(()=>{i(!0)})},[]),y=w(()=>{u(!0),i(!1),setTimeout(()=>{g(!1),u(!1)},150)},[]),F=w(()=>{t?y():G()},[t,G,y]);M(()=>{let a=x=>{(x.metaKey||x.ctrlKey)&&x.shiftKey&&x.key==="d"&&(x.preventDefault(),F()),x.key==="Escape"&&t&&y()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[t,F,y]),M(()=>{if(!t)return;let a=x=>{j.current&&!j.current.contains(x.target)&&y()};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[t,y]);let he=w(a=>{p(a),O(a)},[]),xe=w(a=>{d(a),A(a)},[]),I=w(a=>{try{let x=JSON.parse(a);H(null),W(x)}catch{H("Invalid JSON")}},[]),be=w(a=>{z(a),S.current&&clearTimeout(S.current),S.current=setTimeout(()=>{I(a)},500)},[I]),we=w(()=>{S.current&&clearTimeout(S.current),I(P)},[I,P]),ye=w(()=>{let a=JSON.stringify(e??{},null,2);z(a),H(null),W(e??{}),p("inline"),O("inline"),d("dark"),A("dark")},[e]),ve=[{value:"inline",label:"inline",icon:o(Ne,{className:"w-3.5 h-3.5"})},{value:"pip",label:"pip",icon:o(Re,{className:"w-3.5 h-3.5"})},{value:"fullscreen",label:"full",icon:o(We,{className:"w-3.5 h-3.5"})}],ke=[{value:"light",label:"light",icon:o(Oe,{className:"w-3.5 h-3.5"})},{value:"dark",label:"dark",icon:o(Ae,{className:"w-3.5 h-3.5"})}];return s(B,{children:[o("style",{dangerouslySetInnerHTML:{__html:Ie}}),s("div",{ref:j,className:"fixed bottom-4 right-4 z-[9999] font-['Inter',_system-ui,_sans-serif]",children:[s("button",{type:"button",onClick:F,className:"group relative flex items-center justify-center w-11 h-11 rounded-xl transition-all duration-200 ease-out hover:scale-105 active:scale-95",style:{background:"rgba(14, 14, 16, 0.95)",backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",border:"1px solid rgba(255, 255, 255, 0.08)",boxShadow:`
|
|
55
|
+
0 4px 12px rgba(0, 0, 0, 0.4),
|
|
56
|
+
0 0 0 1px rgba(255, 255, 255, 0.05),
|
|
57
|
+
inset 0 1px 0 rgba(255, 255, 255, 0.04)
|
|
58
|
+
`},"aria-label":"Toggle Dev Controls","aria-expanded":t,children:[o(q,{className:`w-5 h-5 transition-all duration-200 ${t?"text-indigo-400 scale-110":"text-gray-300 group-hover:text-white"}`}),o("div",{className:"absolute inset-0 rounded-xl opacity-0 group-hover:opacity-100 transition-opacity duration-200 pointer-events-none",style:{background:"radial-gradient(circle at center, rgba(99, 102, 241, 0.15) 0%, transparent 70%)"}})]}),c&&s("div",{ref:fe,className:`absolute bottom-14 right-0 w-80 ${t&&!m?"dev-panel-enter":"dev-panel-exit"}`,style:{maxHeight:"calc(100vh - 120px)",background:"rgba(14, 14, 16, 0.92)",backdropFilter:"blur(24px)",WebkitBackdropFilter:"blur(24px)",border:"1px solid rgba(255, 255, 255, 0.06)",borderRadius:"16px",boxShadow:`
|
|
59
|
+
0 25px 50px -12px rgba(0, 0, 0, 0.6),
|
|
60
|
+
0 0 0 1px rgba(255, 255, 255, 0.05),
|
|
61
|
+
inset 0 1px 0 rgba(255, 255, 255, 0.04)
|
|
62
|
+
`},children:[s("div",{className:"flex items-center justify-between px-4 py-3",style:{borderBottom:"1px solid rgba(255, 255, 255, 0.06)"},children:[s("div",{className:"flex items-center gap-2",children:[o(q,{className:"w-4 h-4 text-gray-400"}),o("span",{className:"text-sm font-medium text-white",children:"Dev Controls"})]}),s("div",{className:"flex items-center gap-2",children:[o("span",{className:"text-[10px] font-medium text-gray-500 px-1.5 py-0.5 rounded",style:{background:"rgba(255, 255, 255, 0.04)",border:"1px solid rgba(255, 255, 255, 0.06)"},children:typeof navigator<"u"&&navigator.platform?.includes("Mac")?"\u2318\u21E7D":"Ctrl+Shift+D"}),o("button",{type:"button",onClick:y,className:"p-1 rounded-md text-gray-500 hover:text-gray-300 hover:bg-white/5 transition-colors",children:o(Te,{className:"w-4 h-4"})})]})]}),s("div",{className:"p-4 space-y-5 overflow-y-auto",style:{maxHeight:"calc(100vh - 200px)"},children:[s("div",{children:[o("label",{htmlFor:"display-mode",className:"text-[11px] font-medium uppercase tracking-wider text-gray-500 block mb-2",children:"Display Mode"}),o(V,{options:ve,value:f,onChange:he})]}),s("div",{children:[o("label",{htmlFor:"theme",className:"text-[11px] font-medium uppercase tracking-wider text-gray-500 block mb-2",children:"Theme"}),o(V,{options:ke,value:n,onChange:xe})]}),s("div",{children:[o("label",{htmlFor:"safe-area",className:"text-[11px] font-medium uppercase tracking-wider text-gray-500 block mb-2",children:"Safe Area (Chat Input)"}),s("button",{type:"button",onClick:()=>h(!r),className:`w-full flex items-center justify-between px-3 py-2.5 rounded-lg text-xs font-medium transition-all duration-150 ${r?"text-emerald-400":"text-gray-400"}`,style:{background:r?"rgba(34, 197, 94, 0.1)":"rgba(255, 255, 255, 0.04)",border:r?"1px solid rgba(34, 197, 94, 0.3)":"1px solid rgba(255, 255, 255, 0.06)"},children:[o("span",{children:"Mock ChatGPT Input Bar"}),o("span",{className:`px-2 py-0.5 rounded text-[10px] font-semibold ${r?"bg-emerald-500/20 text-emerald-400":"bg-gray-500/20 text-gray-500"}`,children:r?"ON":"OFF"})]}),r&&s("p",{className:"text-[10px] text-gray-500 mt-1.5",children:["bottom: ",L,"px"]})]}),s("div",{children:[o("label",{htmlFor:"widget-props",className:"text-[11px] font-medium uppercase tracking-wider text-gray-500 block mb-2",children:"Widget Props"}),o("textarea",{value:P,onChange:a=>be(a.target.value),onBlur:we,className:"dev-json-editor w-full min-h-[160px] text-xs text-gray-200 p-3 rounded-lg resize-none focus:outline-none transition-colors",style:{background:"rgba(0, 0, 0, 0.3)",border:C?"1px solid rgba(239, 68, 68, 0.5)":"1px solid rgba(255, 255, 255, 0.06)",fontFamily:"'JetBrains Mono', 'SF Mono', 'Fira Code', monospace",lineHeight:1.6},onFocus:a=>{C||(a.target.style.borderColor="rgba(99, 102, 241, 0.5)")},onBlurCapture:a=>{C||(a.target.style.borderColor="rgba(255, 255, 255, 0.06)")},spellCheck:!1}),C&&s("p",{className:"text-red-400 text-[11px] mt-1.5 flex items-center gap-1",children:[o("svg",{"aria-hidden":"true","aria-label":"Error",className:"w-3 h-3",viewBox:"0 0 16 16",fill:"currentColor",children:o("path",{d:"M8 1.5a6.5 6.5 0 100 13 6.5 6.5 0 000-13zM7 4.5h2v4H7v-4zm0 5h2v2H7v-2z"})}),C]})]}),s("button",{type:"button",onClick:ye,className:"w-full flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-xs font-medium text-gray-400 transition-all duration-150 hover:text-gray-200",style:{background:"rgba(255, 255, 255, 0.04)",border:"1px solid rgba(255, 255, 255, 0.06)"},onMouseEnter:a=>{a.currentTarget.style.background="rgba(255, 255, 255, 0.08)",a.currentTarget.style.borderColor="rgba(255, 255, 255, 0.1)"},onMouseLeave:a=>{a.currentTarget.style.background="rgba(255, 255, 255, 0.04)",a.currentTarget.style.borderColor="rgba(255, 255, 255, 0.06)"},children:[o(De,{className:"w-3.5 h-3.5"}),"Reset to Defaults"]})]})]})]}),r&&s("div",{className:"fixed bottom-0 left-0 right-0 z-[9998] flex items-center justify-center pointer-events-none",style:{height:`${L}px`,background:"linear-gradient(to top, #1a1a1a 0%, #1a1a1a 80%, transparent 100%)"},children:[s("div",{className:"w-full max-w-2xl mx-4 px-4 py-3 rounded-2xl bg-[#2f2f2f] border border-[#424242] flex items-center gap-3",children:[o("div",{className:"w-8 h-8 rounded-full bg-[#424242] flex items-center justify-center",children:o("svg",{"aria-hidden":"true",className:"w-4 h-4 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:o("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),o("div",{className:"flex-1 text-gray-400 text-sm",children:"Ask anything..."}),o("div",{className:"w-8 h-8 rounded-full bg-[#424242] flex items-center justify-center",children:o("svg",{"aria-hidden":"true",className:"w-4 h-4 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:o("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4m-4-8a3 3 0 01-3-3V5a3 3 0 116 0v6a3 3 0 01-3 3z"})})})]}),s("div",{className:"absolute bottom-1 text-[10px] text-gray-600 font-mono",children:["Mock SafeArea: bottom=",L,"px"]})]})]})}import{useCallback as Fe}from"react";import D,{createContext as Le,useCallback as Q,useContext as Pe,useEffect as He,useState as _,useSyncExternalStore as je}from"react";async function X(){let{detectPlatform:e}=await import("../platform-4QZXTYT5.js");if(e()==="openai"){let{OpenAIWidgetClient:i}=await import("../openai-client-UL6T463M.js");return new i}else{let{MCPAppsWidgetClient:i}=await import("../mcp-apps-client-BU7EN3Z2.js");return new i}}var Z=Le(null);function ee({children:e,loading:t=null,onError:i}){let[m,u]=_(null),[c,g]=_(null),[f,p]=_(!0);return He(()=>{let n=!0;async function d(){try{let r=await X();await r.connect(),n&&(u(r),p(!1))}catch(r){n&&(console.log("error",r),g(r instanceof Error?r:new Error(String(r))),p(!1))}}return d(),()=>{n=!1}},[]),c&&i?D.createElement(D.Fragment,null,i(c)):f||!m?D.createElement(D.Fragment,null,t):D.createElement(Z.Provider,{value:m},e)}function l(e){let t=Pe(Z);if(!t)throw new Error("useWidgetClient must be used within a WidgetProvider");let i=Q(c=>e==="toolOutput"?t.onToolResult(()=>c()):e==="theme"?t.onThemeChange(()=>c()):e==="displayMode"?t.onDisplayModeChange(()=>c()):e==="safeArea"?t.onSafeAreaChange(()=>c()):e==="maxHeight"?t.onMaxHeightChange(()=>c()):e==="toolResponseMetadata"?t.onToolResponseMetadataChange(()=>c()):e==="widgetState"?t.onWidgetStateChange(()=>c()):()=>{},[t,e]),m=Q(()=>e==="toolOutput"?t.getToolOutput():e==="theme"?t.getTheme():e==="displayMode"?t.getDisplayMode():e==="locale"?t.getLocale():e==="safeArea"?t.getSafeArea():e==="maxHeight"?t.getMaxHeight():e==="toolResponseMetadata"?t.getToolResponseMetadata():e==="widgetState"?t.getWidgetState():null,[t,e]),u=je(i,m,m);return e?u:t}function te(){let e=l();return Fe((t,i)=>e.callTool(t,i),[e])}function oe(){return l("displayMode")}import{useSyncExternalStore as Ke}from"react";function ne(){return Ke(()=>()=>{},()=>typeof window>"u"?!1:window.__isChatGptApp===!0,()=>!1)}function re(){return l("locale")}function ae(){return l("maxHeight")}import{useCallback as Be}from"react";function ie(){let e=l();return Be(t=>e.openExternal(t),[e])}import{useCallback as _e}from"react";function se(){let e=l();return _e(t=>e.requestDisplayMode(t),[e])}function le(){return l("safeArea")}import{useCallback as ze}from"react";function de(){let e=l();return ze(t=>e.sendFollowUp(t),[e])}function ue(){return l("theme")}function ce(){return l("toolOutput")}function pe(){return l("toolResponseMetadata")}import{useCallback as Ge,useEffect as $e,useState as Je}from"react";function me(e){let t=l("widgetState"),[i,m]=Je(()=>t??(typeof e=="function"?e():e??null));$e(()=>{m(t)},[t]);let u=Ge(c=>{m(g=>{let f=typeof c=="function"?c(g):c;return $()==="openai"&&f!=null&&window.openai?.setWidgetState(f),f})},[]);return[i,u]}import{jsx as k,jsxs as ge}from"react/jsx-runtime";var qe=()=>ge("div",{className:"flex flex-col items-center justify-center h-full min-h-[120px] gap-4",children:[ge("div",{className:"flex gap-2",children:[k("div",{className:"w-3 h-3 rounded-full bg-gradient-to-r from-blue-400 to-cyan-400 animate-bounce [animation-delay:-0.3s]"}),k("div",{className:"w-3 h-3 rounded-full bg-gradient-to-r from-cyan-400 to-teal-400 animate-bounce [animation-delay:-0.15s]"}),k("div",{className:"w-3 h-3 rounded-full bg-gradient-to-r from-teal-400 to-emerald-400 animate-bounce"})]}),k("p",{className:"text-sm font-medium text-transparent bg-clip-text bg-gradient-to-r from-slate-400 via-slate-200 to-slate-400 bg-[length:200%_100%] animate-[shimmer_1.5s_ease-in-out_infinite]",children:"Loading widget..."}),k("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:k("div",{className:"w-16 h-16 rounded-full border-2 border-blue-400/20 animate-ping"})}),k("style",{children:`
|
|
63
|
+
@keyframes shimmer {
|
|
64
|
+
0% { background-position: 200% 0; }
|
|
65
|
+
100% { background-position: -200% 0; }
|
|
66
|
+
}
|
|
67
|
+
`})]});export{Y as DevModeProvider,Me as InitializeNextJsInChatGpt,qe as LoadingWidget,ee as WidgetProvider,U as getMockState,R as initializeMockOpenAI,O as updateMockDisplayMode,v as updateMockGlobal,A as updateMockTheme,W as updateMockToolOutput,te as useCallTool,oe as useDisplayMode,ne as useIsChatGptApp,re as useLocale,ae as useMaxHeight,ie as useOpenExternal,se as useRequestDisplayMode,le as useSafeArea,de as useSendFollowUp,ue as useTheme,ce as useToolOutput,pe as useToolResponseMetadata,l as useWidgetClient,me as useWidgetState};
|
|
68
|
+
//# sourceMappingURL=react.js.map
|