sunpeak 0.2.4 → 0.2.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/README.md +10 -0
- package/dist/index.cjs +264 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +212 -12
- package/dist/index.d.ts +212 -12
- package/dist/index.js +246 -76
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.cjs +250 -0
- package/dist/mcp/index.cjs.map +1 -0
- package/dist/mcp/index.d.cts +12 -0
- package/dist/mcp/index.d.ts +12 -0
- package/dist/mcp/index.js +243 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/styles/globals.css +0 -1
- package/package.json +10 -2
- package/template/README.md +38 -2
- package/template/dev/main.tsx +51 -48
- package/template/mcp/server.ts +66 -0
- package/template/package.json +3 -0
- package/template/postcss.config.js +5 -0
- package/template/src/App.tsx +8 -4
- package/template/src/components/sunpeak-card.tsx +43 -12
- package/template/src/components/sunpeak-carousel.tsx +42 -8
- package/template/src/index.chatgpt.tsx +8 -0
- package/template/src/styles/globals.css +0 -1
- package/template/tsup.config.ts +29 -2
- package/template/vite.config.ts +2 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { SetStateAction } from 'react';
|
|
3
4
|
import { ClassValue } from 'clsx';
|
|
4
5
|
|
|
5
6
|
type Theme$1 = "light" | "dark";
|
|
@@ -41,6 +42,11 @@ type RequestDisplayMode = (args: {
|
|
|
41
42
|
}) => Promise<{
|
|
42
43
|
mode: DisplayMode;
|
|
43
44
|
}>;
|
|
45
|
+
type ViewMode = 'modal' | 'default';
|
|
46
|
+
type View = {
|
|
47
|
+
mode: ViewMode;
|
|
48
|
+
params?: UnknownObject;
|
|
49
|
+
};
|
|
44
50
|
type CallToolResponse = {
|
|
45
51
|
result: string;
|
|
46
52
|
};
|
|
@@ -52,12 +58,18 @@ type OpenAiGlobals<ToolInput = UnknownObject, ToolOutput = UnknownObject, ToolRe
|
|
|
52
58
|
maxHeight: number;
|
|
53
59
|
displayMode: DisplayMode;
|
|
54
60
|
safeArea: SafeArea;
|
|
61
|
+
view: View | null;
|
|
55
62
|
toolInput: ToolInput;
|
|
56
63
|
toolOutput: ToolOutput | null;
|
|
57
64
|
toolResponseMetadata: ToolResponseMetadata | null;
|
|
58
65
|
widgetState: WidgetState | null;
|
|
59
66
|
setWidgetState: (state: WidgetState) => Promise<void>;
|
|
60
67
|
};
|
|
68
|
+
type RequestModal = (args: {
|
|
69
|
+
mode: ViewMode;
|
|
70
|
+
params?: UnknownObject;
|
|
71
|
+
}) => Promise<void>;
|
|
72
|
+
type NotifyIntrinsicHeight = (height: number) => void;
|
|
61
73
|
type OpenAiAPI = {
|
|
62
74
|
callTool: CallTool;
|
|
63
75
|
sendFollowUpMessage: (args: {
|
|
@@ -67,6 +79,8 @@ type OpenAiAPI = {
|
|
|
67
79
|
href: string;
|
|
68
80
|
}): void;
|
|
69
81
|
requestDisplayMode: RequestDisplayMode;
|
|
82
|
+
requestModal: RequestModal;
|
|
83
|
+
notifyIntrinsicHeight: NotifyIntrinsicHeight;
|
|
70
84
|
};
|
|
71
85
|
declare const SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
|
|
72
86
|
declare class SetGlobalsEvent extends CustomEvent<{
|
|
@@ -83,6 +97,163 @@ declare global {
|
|
|
83
97
|
}
|
|
84
98
|
}
|
|
85
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Provider-agnostic types for widget runtime environments.
|
|
102
|
+
* These types abstract away the specific host (OpenAI/ChatGPT, etc.)
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Global state available from the widget runtime environment.
|
|
107
|
+
* This is a provider-agnostic alias for OpenAiGlobals.
|
|
108
|
+
*/
|
|
109
|
+
type WidgetGlobals<ToolInput = UnknownObject, ToolOutput = UnknownObject, ToolResponseMetadata = UnknownObject, WidgetState = UnknownObject> = {
|
|
110
|
+
theme: Theme;
|
|
111
|
+
userAgent: UserAgent;
|
|
112
|
+
locale: string;
|
|
113
|
+
maxHeight: number;
|
|
114
|
+
displayMode: DisplayMode;
|
|
115
|
+
safeArea: SafeArea;
|
|
116
|
+
view: View | null;
|
|
117
|
+
toolInput: ToolInput;
|
|
118
|
+
toolOutput: ToolOutput | null;
|
|
119
|
+
toolResponseMetadata: ToolResponseMetadata | null;
|
|
120
|
+
widgetState: WidgetState | null;
|
|
121
|
+
setWidgetState: (state: WidgetState) => Promise<void>;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* API methods available from the widget runtime environment.
|
|
125
|
+
* This is a provider-agnostic alias for OpenAiAPI.
|
|
126
|
+
*/
|
|
127
|
+
type WidgetAPI = {
|
|
128
|
+
callTool?: (name: string, args: Record<string, unknown>) => Promise<CallToolResponse>;
|
|
129
|
+
sendFollowUpMessage?: (args: {
|
|
130
|
+
prompt: string;
|
|
131
|
+
}) => Promise<void>;
|
|
132
|
+
openExternal?: (payload: {
|
|
133
|
+
href: string;
|
|
134
|
+
}) => void;
|
|
135
|
+
requestDisplayMode?: (args: {
|
|
136
|
+
mode: DisplayMode;
|
|
137
|
+
}) => Promise<{
|
|
138
|
+
mode: DisplayMode;
|
|
139
|
+
}>;
|
|
140
|
+
requestModal?: (args: {
|
|
141
|
+
mode: ViewMode;
|
|
142
|
+
params?: UnknownObject;
|
|
143
|
+
}) => Promise<void>;
|
|
144
|
+
notifyIntrinsicHeight?: (height: number) => void;
|
|
145
|
+
setWidgetState?: (state: UnknownObject) => Promise<void>;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Provider interface that abstracts the widget runtime environment.
|
|
149
|
+
* Each host (OpenAI, etc.) implements this interface.
|
|
150
|
+
*/
|
|
151
|
+
interface WidgetProvider {
|
|
152
|
+
/**
|
|
153
|
+
* Unique identifier for the provider.
|
|
154
|
+
*/
|
|
155
|
+
readonly id: string;
|
|
156
|
+
/**
|
|
157
|
+
* Get the current value of a global property.
|
|
158
|
+
*/
|
|
159
|
+
getGlobal<K extends keyof WidgetGlobals>(key: K): WidgetGlobals[K] | null;
|
|
160
|
+
/**
|
|
161
|
+
* Subscribe to changes for a specific global property.
|
|
162
|
+
* Returns an unsubscribe function.
|
|
163
|
+
*/
|
|
164
|
+
subscribe(key: keyof WidgetGlobals, onChange: () => void): () => void;
|
|
165
|
+
/**
|
|
166
|
+
* Get the API methods, or null if not available.
|
|
167
|
+
*/
|
|
168
|
+
getAPI(): WidgetAPI | null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* OpenAI/ChatGPT provider implementation.
|
|
173
|
+
* Bridges the OpenAI-specific window.openai API to the provider-agnostic interface.
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Check if the OpenAI provider is available.
|
|
178
|
+
*/
|
|
179
|
+
declare function isOpenAiAvailable(): boolean;
|
|
180
|
+
/**
|
|
181
|
+
* OpenAI provider implementation.
|
|
182
|
+
*/
|
|
183
|
+
declare class OpenAiProvider implements WidgetProvider {
|
|
184
|
+
readonly id = "openai";
|
|
185
|
+
getGlobal<K extends keyof WidgetGlobals>(key: K): WidgetGlobals[K] | null;
|
|
186
|
+
subscribe(key: keyof WidgetGlobals, onChange: () => void): () => void;
|
|
187
|
+
getAPI(): WidgetAPI | null;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Get the OpenAI provider instance (singleton).
|
|
191
|
+
*/
|
|
192
|
+
declare function getOpenAiProvider(): OpenAiProvider;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Provider detection and routing.
|
|
196
|
+
*
|
|
197
|
+
* This module automatically detects which widget runtime environment is available
|
|
198
|
+
* and provides the appropriate provider. The detection happens once on first access,
|
|
199
|
+
* and subsequent calls return the cached provider directly.
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Detect and return the appropriate provider for the current environment.
|
|
204
|
+
* This function caches the result, so detection only happens once.
|
|
205
|
+
*
|
|
206
|
+
* @returns The detected provider, or null if no provider is available.
|
|
207
|
+
*/
|
|
208
|
+
declare function getProvider(): WidgetProvider | null;
|
|
209
|
+
/**
|
|
210
|
+
* Check if any provider is available.
|
|
211
|
+
*/
|
|
212
|
+
declare function isProviderAvailable(): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Get a global value from the detected provider.
|
|
215
|
+
*
|
|
216
|
+
* @param key - The global property key to retrieve.
|
|
217
|
+
* @returns The value, or null if not available.
|
|
218
|
+
*/
|
|
219
|
+
declare function getGlobal<K extends keyof WidgetGlobals>(key: K): WidgetGlobals[K] | null;
|
|
220
|
+
/**
|
|
221
|
+
* Subscribe to changes for a global property.
|
|
222
|
+
*
|
|
223
|
+
* @param key - The global property key to subscribe to.
|
|
224
|
+
* @param onChange - Callback to invoke when the value changes.
|
|
225
|
+
* @returns An unsubscribe function.
|
|
226
|
+
*/
|
|
227
|
+
declare function subscribeToGlobal(key: keyof WidgetGlobals, onChange: () => void): () => void;
|
|
228
|
+
/**
|
|
229
|
+
* Get the API from the detected provider.
|
|
230
|
+
*
|
|
231
|
+
* @returns The API object, or null if not available.
|
|
232
|
+
*/
|
|
233
|
+
declare function getAPI(): WidgetAPI | null;
|
|
234
|
+
/**
|
|
235
|
+
* Reset the provider detection cache.
|
|
236
|
+
* Useful for testing or when the environment changes.
|
|
237
|
+
*/
|
|
238
|
+
declare function resetProviderCache(): void;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Hook to read and subscribe to a global property from the widget runtime.
|
|
242
|
+
* Automatically detects and uses the appropriate provider (OpenAI, etc.).
|
|
243
|
+
*
|
|
244
|
+
* @param key - The global property key to read.
|
|
245
|
+
* @returns The current value, or null if not available.
|
|
246
|
+
*/
|
|
247
|
+
declare function useWidgetGlobal<K extends keyof WidgetGlobals>(key: K): WidgetGlobals[K] | null;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Hook to get the widget runtime API.
|
|
251
|
+
* Automatically detects and uses the appropriate provider (OpenAI, etc.).
|
|
252
|
+
*
|
|
253
|
+
* @returns The API object, or null if not available.
|
|
254
|
+
*/
|
|
255
|
+
declare function useWidgetAPI(): WidgetAPI | null;
|
|
256
|
+
|
|
86
257
|
type ScreenWidth = 'mobile-s' | 'mobile-l' | 'tablet' | 'full';
|
|
87
258
|
type SimulatorConfig = {
|
|
88
259
|
theme: Theme;
|
|
@@ -93,26 +264,38 @@ declare const SCREEN_WIDTHS: Record<ScreenWidth, number>;
|
|
|
93
264
|
|
|
94
265
|
declare const useDisplayMode: () => DisplayMode | null;
|
|
95
266
|
|
|
267
|
+
declare const useLocale: () => string | null;
|
|
268
|
+
|
|
96
269
|
declare const useMaxHeight: () => number | null;
|
|
97
270
|
|
|
98
271
|
declare function useIsMobile(): boolean;
|
|
99
272
|
|
|
100
|
-
declare
|
|
273
|
+
declare const useSafeArea: () => SafeArea | null;
|
|
101
274
|
|
|
102
275
|
declare const useTheme: () => Theme | null;
|
|
103
276
|
|
|
104
|
-
declare function
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
277
|
+
declare function useToolInput<T extends UnknownObject = UnknownObject>(): T | null;
|
|
278
|
+
|
|
279
|
+
declare function useToolResponseMetadata<T extends UnknownObject = UnknownObject>(): T | null;
|
|
280
|
+
|
|
281
|
+
declare const useUserAgent: () => UserAgent | null;
|
|
282
|
+
|
|
283
|
+
declare function useView(): View | null;
|
|
284
|
+
|
|
285
|
+
declare function useWidgetProps<T extends Record<string, unknown>>(defaultState?: T | (() => T)): T;
|
|
286
|
+
|
|
287
|
+
declare function useWidgetState<T extends UnknownObject>(defaultState: T | (() => T)): readonly [T, (state: SetStateAction<T>) => void];
|
|
288
|
+
declare function useWidgetState<T extends UnknownObject>(defaultState?: T | (() => T | null) | null): readonly [T | null, (state: SetStateAction<T | null>) => void];
|
|
108
289
|
|
|
109
290
|
interface ChatGPTSimulatorProps {
|
|
110
291
|
children: React.ReactNode;
|
|
111
292
|
appName?: string;
|
|
112
293
|
appIcon?: string;
|
|
113
294
|
userMessage?: string;
|
|
295
|
+
toolOutput?: Record<string, unknown> | null;
|
|
296
|
+
widgetState?: Record<string, unknown> | null;
|
|
114
297
|
}
|
|
115
|
-
declare function ChatGPTSimulator({ children, appName, appIcon, userMessage }: ChatGPTSimulatorProps): react_jsx_runtime.JSX.Element;
|
|
298
|
+
declare function ChatGPTSimulator({ children, appName, appIcon, userMessage, toolOutput, widgetState, }: ChatGPTSimulatorProps): react_jsx_runtime.JSX.Element;
|
|
116
299
|
|
|
117
300
|
declare class MockOpenAI implements OpenAiAPI, OpenAiGlobals {
|
|
118
301
|
theme: Theme;
|
|
@@ -136,9 +319,10 @@ declare class MockOpenAI implements OpenAiAPI, OpenAiGlobals {
|
|
|
136
319
|
right: number;
|
|
137
320
|
};
|
|
138
321
|
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
322
|
+
view: View | null;
|
|
323
|
+
toolInput: Record<string, unknown>;
|
|
324
|
+
toolOutput: Record<string, unknown> | null;
|
|
325
|
+
toolResponseMetadata: Record<string, unknown> | null;
|
|
142
326
|
widgetState: Record<string, unknown> | null;
|
|
143
327
|
callTool(name: string, args: Record<string, unknown>): Promise<{
|
|
144
328
|
result: string;
|
|
@@ -154,13 +338,29 @@ declare class MockOpenAI implements OpenAiAPI, OpenAiGlobals {
|
|
|
154
338
|
}): Promise<{
|
|
155
339
|
mode: DisplayMode;
|
|
156
340
|
}>;
|
|
341
|
+
requestModal(args: {
|
|
342
|
+
mode: ViewMode;
|
|
343
|
+
params?: UnknownObject;
|
|
344
|
+
}): Promise<void>;
|
|
345
|
+
notifyIntrinsicHeight(height: number): void;
|
|
157
346
|
setWidgetState(state: Record<string, unknown>): Promise<void>;
|
|
158
347
|
setTheme(theme: Theme): void;
|
|
159
348
|
setDisplayMode(displayMode: DisplayMode): void;
|
|
160
|
-
|
|
349
|
+
setToolOutput(toolOutput: Record<string, unknown> | null): void;
|
|
350
|
+
setWidgetStateExternal(widgetState: Record<string, unknown> | null): void;
|
|
351
|
+
emitUpdate(globals: Partial<OpenAiGlobals>): void;
|
|
161
352
|
}
|
|
162
|
-
declare function initMockOpenAI(
|
|
353
|
+
declare function initMockOpenAI(initialData?: {
|
|
354
|
+
theme?: Theme;
|
|
355
|
+
displayMode?: DisplayMode;
|
|
356
|
+
toolOutput?: Record<string, unknown> | null;
|
|
357
|
+
widgetState?: Record<string, unknown> | null;
|
|
358
|
+
}): MockOpenAI;
|
|
163
359
|
|
|
164
360
|
declare function cn(...inputs: ClassValue[]): string;
|
|
165
361
|
|
|
166
|
-
|
|
362
|
+
declare const prefersReducedMotion: () => boolean;
|
|
363
|
+
declare const isPrimarilyTouchDevice: () => boolean;
|
|
364
|
+
declare const isHoverAvailable: () => boolean;
|
|
365
|
+
|
|
366
|
+
export { type CallTool, type CallToolResponse, ChatGPTSimulator, type DeviceType, type DisplayMode, type NotifyIntrinsicHeight, type OpenAiAPI, type OpenAiGlobals, type RequestDisplayMode, type RequestModal, SCREEN_WIDTHS, SET_GLOBALS_EVENT_TYPE, type SafeArea, type SafeAreaInsets, type ScreenWidth, SetGlobalsEvent, type SimulatorConfig, type Theme, ThemeProvider, type UnknownObject, type UserAgent, type View, type ViewMode, type WidgetAPI, type WidgetGlobals, type WidgetProvider, cn, getAPI, getGlobal, getOpenAiProvider, getProvider, initMockOpenAI, isHoverAvailable, isOpenAiAvailable, isPrimarilyTouchDevice, isProviderAvailable, prefersReducedMotion, resetProviderCache, subscribeToGlobal, useDisplayMode, useIsMobile, useLocale, useMaxHeight, useSafeArea, useTheme, useThemeContext, useToolInput, useToolResponseMetadata, useUserAgent, useView, useWidgetAPI, useWidgetGlobal, useWidgetProps, useWidgetState };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { SetStateAction } from 'react';
|
|
3
4
|
import { ClassValue } from 'clsx';
|
|
4
5
|
|
|
5
6
|
type Theme$1 = "light" | "dark";
|
|
@@ -41,6 +42,11 @@ type RequestDisplayMode = (args: {
|
|
|
41
42
|
}) => Promise<{
|
|
42
43
|
mode: DisplayMode;
|
|
43
44
|
}>;
|
|
45
|
+
type ViewMode = 'modal' | 'default';
|
|
46
|
+
type View = {
|
|
47
|
+
mode: ViewMode;
|
|
48
|
+
params?: UnknownObject;
|
|
49
|
+
};
|
|
44
50
|
type CallToolResponse = {
|
|
45
51
|
result: string;
|
|
46
52
|
};
|
|
@@ -52,12 +58,18 @@ type OpenAiGlobals<ToolInput = UnknownObject, ToolOutput = UnknownObject, ToolRe
|
|
|
52
58
|
maxHeight: number;
|
|
53
59
|
displayMode: DisplayMode;
|
|
54
60
|
safeArea: SafeArea;
|
|
61
|
+
view: View | null;
|
|
55
62
|
toolInput: ToolInput;
|
|
56
63
|
toolOutput: ToolOutput | null;
|
|
57
64
|
toolResponseMetadata: ToolResponseMetadata | null;
|
|
58
65
|
widgetState: WidgetState | null;
|
|
59
66
|
setWidgetState: (state: WidgetState) => Promise<void>;
|
|
60
67
|
};
|
|
68
|
+
type RequestModal = (args: {
|
|
69
|
+
mode: ViewMode;
|
|
70
|
+
params?: UnknownObject;
|
|
71
|
+
}) => Promise<void>;
|
|
72
|
+
type NotifyIntrinsicHeight = (height: number) => void;
|
|
61
73
|
type OpenAiAPI = {
|
|
62
74
|
callTool: CallTool;
|
|
63
75
|
sendFollowUpMessage: (args: {
|
|
@@ -67,6 +79,8 @@ type OpenAiAPI = {
|
|
|
67
79
|
href: string;
|
|
68
80
|
}): void;
|
|
69
81
|
requestDisplayMode: RequestDisplayMode;
|
|
82
|
+
requestModal: RequestModal;
|
|
83
|
+
notifyIntrinsicHeight: NotifyIntrinsicHeight;
|
|
70
84
|
};
|
|
71
85
|
declare const SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
|
|
72
86
|
declare class SetGlobalsEvent extends CustomEvent<{
|
|
@@ -83,6 +97,163 @@ declare global {
|
|
|
83
97
|
}
|
|
84
98
|
}
|
|
85
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Provider-agnostic types for widget runtime environments.
|
|
102
|
+
* These types abstract away the specific host (OpenAI/ChatGPT, etc.)
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Global state available from the widget runtime environment.
|
|
107
|
+
* This is a provider-agnostic alias for OpenAiGlobals.
|
|
108
|
+
*/
|
|
109
|
+
type WidgetGlobals<ToolInput = UnknownObject, ToolOutput = UnknownObject, ToolResponseMetadata = UnknownObject, WidgetState = UnknownObject> = {
|
|
110
|
+
theme: Theme;
|
|
111
|
+
userAgent: UserAgent;
|
|
112
|
+
locale: string;
|
|
113
|
+
maxHeight: number;
|
|
114
|
+
displayMode: DisplayMode;
|
|
115
|
+
safeArea: SafeArea;
|
|
116
|
+
view: View | null;
|
|
117
|
+
toolInput: ToolInput;
|
|
118
|
+
toolOutput: ToolOutput | null;
|
|
119
|
+
toolResponseMetadata: ToolResponseMetadata | null;
|
|
120
|
+
widgetState: WidgetState | null;
|
|
121
|
+
setWidgetState: (state: WidgetState) => Promise<void>;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* API methods available from the widget runtime environment.
|
|
125
|
+
* This is a provider-agnostic alias for OpenAiAPI.
|
|
126
|
+
*/
|
|
127
|
+
type WidgetAPI = {
|
|
128
|
+
callTool?: (name: string, args: Record<string, unknown>) => Promise<CallToolResponse>;
|
|
129
|
+
sendFollowUpMessage?: (args: {
|
|
130
|
+
prompt: string;
|
|
131
|
+
}) => Promise<void>;
|
|
132
|
+
openExternal?: (payload: {
|
|
133
|
+
href: string;
|
|
134
|
+
}) => void;
|
|
135
|
+
requestDisplayMode?: (args: {
|
|
136
|
+
mode: DisplayMode;
|
|
137
|
+
}) => Promise<{
|
|
138
|
+
mode: DisplayMode;
|
|
139
|
+
}>;
|
|
140
|
+
requestModal?: (args: {
|
|
141
|
+
mode: ViewMode;
|
|
142
|
+
params?: UnknownObject;
|
|
143
|
+
}) => Promise<void>;
|
|
144
|
+
notifyIntrinsicHeight?: (height: number) => void;
|
|
145
|
+
setWidgetState?: (state: UnknownObject) => Promise<void>;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Provider interface that abstracts the widget runtime environment.
|
|
149
|
+
* Each host (OpenAI, etc.) implements this interface.
|
|
150
|
+
*/
|
|
151
|
+
interface WidgetProvider {
|
|
152
|
+
/**
|
|
153
|
+
* Unique identifier for the provider.
|
|
154
|
+
*/
|
|
155
|
+
readonly id: string;
|
|
156
|
+
/**
|
|
157
|
+
* Get the current value of a global property.
|
|
158
|
+
*/
|
|
159
|
+
getGlobal<K extends keyof WidgetGlobals>(key: K): WidgetGlobals[K] | null;
|
|
160
|
+
/**
|
|
161
|
+
* Subscribe to changes for a specific global property.
|
|
162
|
+
* Returns an unsubscribe function.
|
|
163
|
+
*/
|
|
164
|
+
subscribe(key: keyof WidgetGlobals, onChange: () => void): () => void;
|
|
165
|
+
/**
|
|
166
|
+
* Get the API methods, or null if not available.
|
|
167
|
+
*/
|
|
168
|
+
getAPI(): WidgetAPI | null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* OpenAI/ChatGPT provider implementation.
|
|
173
|
+
* Bridges the OpenAI-specific window.openai API to the provider-agnostic interface.
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Check if the OpenAI provider is available.
|
|
178
|
+
*/
|
|
179
|
+
declare function isOpenAiAvailable(): boolean;
|
|
180
|
+
/**
|
|
181
|
+
* OpenAI provider implementation.
|
|
182
|
+
*/
|
|
183
|
+
declare class OpenAiProvider implements WidgetProvider {
|
|
184
|
+
readonly id = "openai";
|
|
185
|
+
getGlobal<K extends keyof WidgetGlobals>(key: K): WidgetGlobals[K] | null;
|
|
186
|
+
subscribe(key: keyof WidgetGlobals, onChange: () => void): () => void;
|
|
187
|
+
getAPI(): WidgetAPI | null;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Get the OpenAI provider instance (singleton).
|
|
191
|
+
*/
|
|
192
|
+
declare function getOpenAiProvider(): OpenAiProvider;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Provider detection and routing.
|
|
196
|
+
*
|
|
197
|
+
* This module automatically detects which widget runtime environment is available
|
|
198
|
+
* and provides the appropriate provider. The detection happens once on first access,
|
|
199
|
+
* and subsequent calls return the cached provider directly.
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Detect and return the appropriate provider for the current environment.
|
|
204
|
+
* This function caches the result, so detection only happens once.
|
|
205
|
+
*
|
|
206
|
+
* @returns The detected provider, or null if no provider is available.
|
|
207
|
+
*/
|
|
208
|
+
declare function getProvider(): WidgetProvider | null;
|
|
209
|
+
/**
|
|
210
|
+
* Check if any provider is available.
|
|
211
|
+
*/
|
|
212
|
+
declare function isProviderAvailable(): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Get a global value from the detected provider.
|
|
215
|
+
*
|
|
216
|
+
* @param key - The global property key to retrieve.
|
|
217
|
+
* @returns The value, or null if not available.
|
|
218
|
+
*/
|
|
219
|
+
declare function getGlobal<K extends keyof WidgetGlobals>(key: K): WidgetGlobals[K] | null;
|
|
220
|
+
/**
|
|
221
|
+
* Subscribe to changes for a global property.
|
|
222
|
+
*
|
|
223
|
+
* @param key - The global property key to subscribe to.
|
|
224
|
+
* @param onChange - Callback to invoke when the value changes.
|
|
225
|
+
* @returns An unsubscribe function.
|
|
226
|
+
*/
|
|
227
|
+
declare function subscribeToGlobal(key: keyof WidgetGlobals, onChange: () => void): () => void;
|
|
228
|
+
/**
|
|
229
|
+
* Get the API from the detected provider.
|
|
230
|
+
*
|
|
231
|
+
* @returns The API object, or null if not available.
|
|
232
|
+
*/
|
|
233
|
+
declare function getAPI(): WidgetAPI | null;
|
|
234
|
+
/**
|
|
235
|
+
* Reset the provider detection cache.
|
|
236
|
+
* Useful for testing or when the environment changes.
|
|
237
|
+
*/
|
|
238
|
+
declare function resetProviderCache(): void;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Hook to read and subscribe to a global property from the widget runtime.
|
|
242
|
+
* Automatically detects and uses the appropriate provider (OpenAI, etc.).
|
|
243
|
+
*
|
|
244
|
+
* @param key - The global property key to read.
|
|
245
|
+
* @returns The current value, or null if not available.
|
|
246
|
+
*/
|
|
247
|
+
declare function useWidgetGlobal<K extends keyof WidgetGlobals>(key: K): WidgetGlobals[K] | null;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Hook to get the widget runtime API.
|
|
251
|
+
* Automatically detects and uses the appropriate provider (OpenAI, etc.).
|
|
252
|
+
*
|
|
253
|
+
* @returns The API object, or null if not available.
|
|
254
|
+
*/
|
|
255
|
+
declare function useWidgetAPI(): WidgetAPI | null;
|
|
256
|
+
|
|
86
257
|
type ScreenWidth = 'mobile-s' | 'mobile-l' | 'tablet' | 'full';
|
|
87
258
|
type SimulatorConfig = {
|
|
88
259
|
theme: Theme;
|
|
@@ -93,26 +264,38 @@ declare const SCREEN_WIDTHS: Record<ScreenWidth, number>;
|
|
|
93
264
|
|
|
94
265
|
declare const useDisplayMode: () => DisplayMode | null;
|
|
95
266
|
|
|
267
|
+
declare const useLocale: () => string | null;
|
|
268
|
+
|
|
96
269
|
declare const useMaxHeight: () => number | null;
|
|
97
270
|
|
|
98
271
|
declare function useIsMobile(): boolean;
|
|
99
272
|
|
|
100
|
-
declare
|
|
273
|
+
declare const useSafeArea: () => SafeArea | null;
|
|
101
274
|
|
|
102
275
|
declare const useTheme: () => Theme | null;
|
|
103
276
|
|
|
104
|
-
declare function
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
277
|
+
declare function useToolInput<T extends UnknownObject = UnknownObject>(): T | null;
|
|
278
|
+
|
|
279
|
+
declare function useToolResponseMetadata<T extends UnknownObject = UnknownObject>(): T | null;
|
|
280
|
+
|
|
281
|
+
declare const useUserAgent: () => UserAgent | null;
|
|
282
|
+
|
|
283
|
+
declare function useView(): View | null;
|
|
284
|
+
|
|
285
|
+
declare function useWidgetProps<T extends Record<string, unknown>>(defaultState?: T | (() => T)): T;
|
|
286
|
+
|
|
287
|
+
declare function useWidgetState<T extends UnknownObject>(defaultState: T | (() => T)): readonly [T, (state: SetStateAction<T>) => void];
|
|
288
|
+
declare function useWidgetState<T extends UnknownObject>(defaultState?: T | (() => T | null) | null): readonly [T | null, (state: SetStateAction<T | null>) => void];
|
|
108
289
|
|
|
109
290
|
interface ChatGPTSimulatorProps {
|
|
110
291
|
children: React.ReactNode;
|
|
111
292
|
appName?: string;
|
|
112
293
|
appIcon?: string;
|
|
113
294
|
userMessage?: string;
|
|
295
|
+
toolOutput?: Record<string, unknown> | null;
|
|
296
|
+
widgetState?: Record<string, unknown> | null;
|
|
114
297
|
}
|
|
115
|
-
declare function ChatGPTSimulator({ children, appName, appIcon, userMessage }: ChatGPTSimulatorProps): react_jsx_runtime.JSX.Element;
|
|
298
|
+
declare function ChatGPTSimulator({ children, appName, appIcon, userMessage, toolOutput, widgetState, }: ChatGPTSimulatorProps): react_jsx_runtime.JSX.Element;
|
|
116
299
|
|
|
117
300
|
declare class MockOpenAI implements OpenAiAPI, OpenAiGlobals {
|
|
118
301
|
theme: Theme;
|
|
@@ -136,9 +319,10 @@ declare class MockOpenAI implements OpenAiAPI, OpenAiGlobals {
|
|
|
136
319
|
right: number;
|
|
137
320
|
};
|
|
138
321
|
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
322
|
+
view: View | null;
|
|
323
|
+
toolInput: Record<string, unknown>;
|
|
324
|
+
toolOutput: Record<string, unknown> | null;
|
|
325
|
+
toolResponseMetadata: Record<string, unknown> | null;
|
|
142
326
|
widgetState: Record<string, unknown> | null;
|
|
143
327
|
callTool(name: string, args: Record<string, unknown>): Promise<{
|
|
144
328
|
result: string;
|
|
@@ -154,13 +338,29 @@ declare class MockOpenAI implements OpenAiAPI, OpenAiGlobals {
|
|
|
154
338
|
}): Promise<{
|
|
155
339
|
mode: DisplayMode;
|
|
156
340
|
}>;
|
|
341
|
+
requestModal(args: {
|
|
342
|
+
mode: ViewMode;
|
|
343
|
+
params?: UnknownObject;
|
|
344
|
+
}): Promise<void>;
|
|
345
|
+
notifyIntrinsicHeight(height: number): void;
|
|
157
346
|
setWidgetState(state: Record<string, unknown>): Promise<void>;
|
|
158
347
|
setTheme(theme: Theme): void;
|
|
159
348
|
setDisplayMode(displayMode: DisplayMode): void;
|
|
160
|
-
|
|
349
|
+
setToolOutput(toolOutput: Record<string, unknown> | null): void;
|
|
350
|
+
setWidgetStateExternal(widgetState: Record<string, unknown> | null): void;
|
|
351
|
+
emitUpdate(globals: Partial<OpenAiGlobals>): void;
|
|
161
352
|
}
|
|
162
|
-
declare function initMockOpenAI(
|
|
353
|
+
declare function initMockOpenAI(initialData?: {
|
|
354
|
+
theme?: Theme;
|
|
355
|
+
displayMode?: DisplayMode;
|
|
356
|
+
toolOutput?: Record<string, unknown> | null;
|
|
357
|
+
widgetState?: Record<string, unknown> | null;
|
|
358
|
+
}): MockOpenAI;
|
|
163
359
|
|
|
164
360
|
declare function cn(...inputs: ClassValue[]): string;
|
|
165
361
|
|
|
166
|
-
|
|
362
|
+
declare const prefersReducedMotion: () => boolean;
|
|
363
|
+
declare const isPrimarilyTouchDevice: () => boolean;
|
|
364
|
+
declare const isHoverAvailable: () => boolean;
|
|
365
|
+
|
|
366
|
+
export { type CallTool, type CallToolResponse, ChatGPTSimulator, type DeviceType, type DisplayMode, type NotifyIntrinsicHeight, type OpenAiAPI, type OpenAiGlobals, type RequestDisplayMode, type RequestModal, SCREEN_WIDTHS, SET_GLOBALS_EVENT_TYPE, type SafeArea, type SafeAreaInsets, type ScreenWidth, SetGlobalsEvent, type SimulatorConfig, type Theme, ThemeProvider, type UnknownObject, type UserAgent, type View, type ViewMode, type WidgetAPI, type WidgetGlobals, type WidgetProvider, cn, getAPI, getGlobal, getOpenAiProvider, getProvider, initMockOpenAI, isHoverAvailable, isOpenAiAvailable, isPrimarilyTouchDevice, isProviderAvailable, prefersReducedMotion, resetProviderCache, subscribeToGlobal, useDisplayMode, useIsMobile, useLocale, useMaxHeight, useSafeArea, useTheme, useThemeContext, useToolInput, useToolResponseMetadata, useUserAgent, useView, useWidgetAPI, useWidgetGlobal, useWidgetProps, useWidgetState };
|