sunpeak 0.1.0

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.
@@ -0,0 +1,571 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ButtonHTMLAttributes, HTMLAttributes, ReactNode, SetStateAction } from 'react';
3
+
4
+ interface ButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick'> {
5
+ /**
6
+ * Whether to use primary styling (accent color) or secondary (outlined)
7
+ * @default false
8
+ */
9
+ isPrimary?: boolean;
10
+ /**
11
+ * Click handler (required)
12
+ */
13
+ onClick: () => void;
14
+ /**
15
+ * Button label
16
+ */
17
+ children: React.ReactNode;
18
+ }
19
+ /**
20
+ * Button - A button component that follows platform design guidelines.
21
+ * Requires an action handler. Use isPrimary to toggle between primary and secondary styles.
22
+ *
23
+ * Design specs:
24
+ * - Primary (isPrimary=true): Accent color background, white text
25
+ * - Secondary (isPrimary=false): Transparent background with border
26
+ * - Both: 14px medium font, rounded corners, hover/active states
27
+ */
28
+ declare const Button: ({ isPrimary, onClick, children, className, type, ...props }: ButtonProps) => react_jsx_runtime.JSX.Element;
29
+
30
+ interface GenAIProps extends HTMLAttributes<HTMLDivElement> {
31
+ /**
32
+ * Maximum width in pixels
33
+ * @default 800
34
+ */
35
+ maxWidth?: number;
36
+ }
37
+ interface GenAIRenderProps {
38
+ /**
39
+ * Maximum height from platform (in pixels)
40
+ */
41
+ maxHeight: number | null;
42
+ /**
43
+ * Color scheme from platform
44
+ */
45
+ colorScheme: 'light' | 'dark' | null;
46
+ }
47
+ /**
48
+ * GenAI - Create platform-aware genAI Apps with automatic theming and constraints.
49
+ *
50
+ * @example
51
+ * ```tsx
52
+ * export const MyApp = GenAI(() => (
53
+ * <div>My content</div>
54
+ * ));
55
+ * ```
56
+ */
57
+ declare function GenAI(renderFn: (props: GenAIRenderProps) => ReactNode): {
58
+ (props?: GenAIProps): react_jsx_runtime.JSX.Element;
59
+ displayName: string;
60
+ };
61
+
62
+ interface CardProps extends Omit<GenAIProps, 'children'>, HTMLAttributes<HTMLDivElement> {
63
+ /**
64
+ * Card content
65
+ */
66
+ children?: ReactNode;
67
+ /**
68
+ * Image to display at the top of the card
69
+ */
70
+ image: string;
71
+ /**
72
+ * Alt text for the image
73
+ */
74
+ imageAlt: string;
75
+ /**
76
+ * Maximum width for the image in pixels
77
+ */
78
+ imageMaxWidth: number;
79
+ /**
80
+ * Maximum height for the image in pixels
81
+ */
82
+ imageMaxHeight: number;
83
+ /**
84
+ * Optional header text (title)
85
+ */
86
+ header?: ReactNode;
87
+ /**
88
+ * Optional metadata text (e.g., rating, category)
89
+ */
90
+ metadata?: ReactNode;
91
+ /**
92
+ * First action button (0-1)
93
+ */
94
+ button1?: ButtonProps;
95
+ /**
96
+ * Second action button (0-1)
97
+ */
98
+ button2?: ButtonProps;
99
+ /**
100
+ * Card variant
101
+ */
102
+ variant?: 'default' | 'bordered' | 'elevated';
103
+ }
104
+ /**
105
+ * Card - A responsive card component that adapts to display mode.
106
+ *
107
+ * In inline mode:
108
+ * - Width: 220px (fixed for carousel consistency)
109
+ * - Compact layout optimized for horizontal scrolling
110
+ * - Clickable to request fullscreen mode
111
+ *
112
+ * In fullscreen mode:
113
+ * - Full width layout
114
+ * - Expanded content display
115
+ * - More breathing room for content
116
+ *
117
+ * Design specs:
118
+ * - Image: aspect-square with 24px border radius
119
+ * - Typography: 16px medium for header, 12px for metadata, 14px for description
120
+ * - Spacing: 12px between sections
121
+ * - Max 2 actions in footer (design guideline)
122
+ */
123
+ declare const Card: ({ children, image, imageAlt, imageMaxWidth, imageMaxHeight, header, metadata, button1, button2, variant, maxWidth, className, onClick, id, ...props }: CardProps) => react_jsx_runtime.JSX.Element;
124
+
125
+ interface CarouselProps extends Omit<GenAIProps, 'children'>, HTMLAttributes<HTMLDivElement> {
126
+ /**
127
+ * Carousel items (typically Card components)
128
+ */
129
+ children: ReactNode;
130
+ /**
131
+ * Gap between items in pixels
132
+ * @default 16
133
+ */
134
+ gap?: number;
135
+ /**
136
+ * Show navigation arrows
137
+ * @default true
138
+ */
139
+ showArrows?: boolean;
140
+ /**
141
+ * Show edge gradients to indicate more content
142
+ * @default true
143
+ */
144
+ showEdgeGradients?: boolean;
145
+ }
146
+ /**
147
+ * Carousel - A carousel component for displaying multiple cards side-by-side.
148
+ * Follows OpenAI ChatGPT Apps SDK design guidelines.
149
+ *
150
+ * Design specs:
151
+ * - 3-8 items recommended (design guideline)
152
+ * - 16px gap between items
153
+ * - 32px circular navigation buttons with shadow
154
+ * - Edge gradients with fade effect
155
+ * - Padding: 20px vertical
156
+ * - Draggable with mouse for smooth scrolling
157
+ */
158
+ declare const Carousel: ({ children, gap, maxWidth, showArrows, showEdgeGradients, className, ...props }: CarouselProps) => react_jsx_runtime.JSX.Element;
159
+
160
+ type UnknownObject$1 = Record<string, unknown>;
161
+ type Theme$1 = 'light' | 'dark';
162
+ type SafeAreaInsets$1 = {
163
+ top: number;
164
+ bottom: number;
165
+ left: number;
166
+ right: number;
167
+ };
168
+ type SafeArea$1 = {
169
+ insets: SafeAreaInsets$1;
170
+ };
171
+ type DeviceType$1 = 'mobile' | 'tablet' | 'desktop' | 'unknown';
172
+ type UserAgent$1 = {
173
+ device: {
174
+ type: DeviceType$1;
175
+ };
176
+ capabilities: {
177
+ hover: boolean;
178
+ touch: boolean;
179
+ };
180
+ };
181
+ /** Display mode */
182
+ type DisplayMode$1 = 'pip' | 'inline' | 'fullscreen';
183
+ type RequestDisplayMode$1 = (args: {
184
+ mode: DisplayMode$1;
185
+ }) => Promise<{
186
+ /**
187
+ * The granted display mode. The host may reject the request.
188
+ * For mobile, PiP is always coerced to fullscreen.
189
+ */
190
+ mode: DisplayMode$1;
191
+ }>;
192
+ type CallToolResponse$1 = {
193
+ result: string;
194
+ };
195
+ /** Calling APIs */
196
+ type CallTool$1 = (name: string, args: Record<string, unknown>) => Promise<CallToolResponse$1>;
197
+ type ChatGPTGlobals<ToolInput = UnknownObject$1, ToolOutput = UnknownObject$1, ToolResponseMetadata = UnknownObject$1, WidgetState = UnknownObject$1> = {
198
+ colorScheme: Theme$1;
199
+ userAgent: UserAgent$1;
200
+ locale: string;
201
+ maxHeight: number;
202
+ displayMode: DisplayMode$1;
203
+ safeArea: SafeArea$1;
204
+ toolInput: ToolInput;
205
+ toolOutput: ToolOutput | null;
206
+ toolResponseMetadata: ToolResponseMetadata | null;
207
+ widgetState: WidgetState | null;
208
+ setWidgetState: (state: WidgetState) => Promise<void>;
209
+ };
210
+ type API = {
211
+ callTool: CallTool$1;
212
+ sendFollowUpMessage: (args: {
213
+ prompt: string;
214
+ }) => Promise<void>;
215
+ openExternal(payload: {
216
+ href: string;
217
+ }): void;
218
+ requestDisplayMode: RequestDisplayMode$1;
219
+ };
220
+ /** Extra events */
221
+ declare const SET_GLOBALS_EVENT_TYPE = "chatgpt:set_globals";
222
+ declare class SetGlobalsEvent extends CustomEvent<{
223
+ globals: Partial<ChatGPTGlobals>;
224
+ }> {
225
+ readonly type = "chatgpt:set_globals";
226
+ }
227
+ /**
228
+ * Global openai object injected by the web sandbox for communicating with ChatGPT host page.
229
+ */
230
+ declare global {
231
+ interface Window {
232
+ openai?: API & ChatGPTGlobals;
233
+ }
234
+ interface WindowEventMap {
235
+ [SET_GLOBALS_EVENT_TYPE]: SetGlobalsEvent;
236
+ }
237
+ }
238
+
239
+ /**
240
+ * Platform-agnostic types for genAI App SDKs
241
+ *
242
+ * These types define a common interface that can be implemented
243
+ * by different platforms (ChatGPT, Gemini, Claude, etc.)
244
+ */
245
+ type UnknownObject = Record<string, unknown>;
246
+ type Theme = 'light' | 'dark';
247
+ type SafeAreaInsets = {
248
+ top: number;
249
+ bottom: number;
250
+ left: number;
251
+ right: number;
252
+ };
253
+ type SafeArea = {
254
+ insets: SafeAreaInsets;
255
+ };
256
+ type DeviceType = 'mobile' | 'tablet' | 'desktop' | 'unknown';
257
+ type UserAgent = {
258
+ device: {
259
+ type: DeviceType;
260
+ };
261
+ capabilities: {
262
+ hover: boolean;
263
+ touch: boolean;
264
+ };
265
+ };
266
+ /** Display mode for the app */
267
+ type DisplayMode = 'pip' | 'inline' | 'fullscreen';
268
+ type RequestDisplayMode = (args: {
269
+ mode: DisplayMode;
270
+ }) => Promise<{
271
+ mode: DisplayMode;
272
+ }>;
273
+ type CallToolResponse = {
274
+ result: string;
275
+ };
276
+ type CallTool = (name: string, args: Record<string, unknown>) => Promise<CallToolResponse>;
277
+ /**
278
+ * Platform-agnostic global state interface
279
+ *
280
+ * All genAI platforms should implement this interface to work with Sunpeak components.
281
+ */
282
+ type PlatformGlobals<ToolInput = UnknownObject, ToolOutput = UnknownObject, ToolResponseMetadata = UnknownObject, WidgetState = UnknownObject> = {
283
+ colorScheme: Theme;
284
+ userAgent: UserAgent;
285
+ locale: string;
286
+ maxHeight: number;
287
+ displayMode: DisplayMode;
288
+ safeArea: SafeArea;
289
+ toolInput: ToolInput;
290
+ toolOutput: ToolOutput | null;
291
+ toolResponseMetadata: ToolResponseMetadata | null;
292
+ widgetState: WidgetState | null;
293
+ setWidgetState: (state: WidgetState) => Promise<void>;
294
+ };
295
+ /**
296
+ * Platform API methods
297
+ */
298
+ type PlatformAPI = {
299
+ callTool: CallTool;
300
+ sendFollowUpMessage: (args: {
301
+ prompt: string;
302
+ }) => Promise<void>;
303
+ openExternal(payload: {
304
+ href: string;
305
+ }): void;
306
+ requestDisplayMode: RequestDisplayMode;
307
+ };
308
+ /**
309
+ * Platform adapter interface
310
+ *
311
+ * Implement this interface to add support for a new genAI platform.
312
+ */
313
+ interface PlatformAdapter {
314
+ /**
315
+ * Platform identifier (e.g., 'chatgpt', 'gemini', 'claude')
316
+ */
317
+ readonly name: string;
318
+ /**
319
+ * Check if this platform is available in the current environment
320
+ */
321
+ isAvailable(): boolean;
322
+ /**
323
+ * Get a specific global value
324
+ */
325
+ getGlobal<K extends keyof PlatformGlobals>(key: K): PlatformGlobals[K] | null;
326
+ /**
327
+ * Get all platform globals
328
+ */
329
+ getGlobals(): (PlatformAPI & PlatformGlobals) | null;
330
+ /**
331
+ * Subscribe to changes in platform globals
332
+ * Returns an unsubscribe function
333
+ */
334
+ subscribe(callback: () => void): () => void;
335
+ }
336
+ /**
337
+ * Platform registry to track supported platforms
338
+ */
339
+ type PlatformType = 'chatgpt' | 'gemini' | 'claude' | 'custom';
340
+
341
+ interface ChatGPTSimulatorProps {
342
+ /**
343
+ * The component to render in the ChatGPT message
344
+ * Can be a function that receives the selected App UI
345
+ */
346
+ children: ReactNode | ((uiSimulation: string) => ReactNode);
347
+ /**
348
+ * Initial display mode
349
+ */
350
+ displayMode?: DisplayMode$1;
351
+ /**
352
+ * Initial color scheme
353
+ */
354
+ colorScheme?: Theme$1;
355
+ /**
356
+ * Initial tool input
357
+ */
358
+ toolInput?: Record<string, unknown>;
359
+ /**
360
+ * Initial tool output
361
+ */
362
+ toolOutput?: Record<string, unknown> | null;
363
+ /**
364
+ * Initial widget state
365
+ */
366
+ widgetState?: Record<string, unknown> | null;
367
+ /**
368
+ * User message to display above the component
369
+ */
370
+ userMessage?: string;
371
+ /**
372
+ * Show simulator controls
373
+ */
374
+ showControls?: boolean;
375
+ /**
376
+ * App UIs for the App UI selector
377
+ */
378
+ uiSimulations?: string[];
379
+ /**
380
+ * Initial App UI
381
+ */
382
+ initialUISimulation?: string;
383
+ }
384
+ /**
385
+ * ChatGPT Simulator Component
386
+ *
387
+ * Emulates the ChatGPT environment for testing components locally.
388
+ * Provides window.openai API and renders components in a ChatGPT-like UI.
389
+ */
390
+ declare function ChatGPTSimulator({ children, displayMode: initialDisplayMode, colorScheme: initialColorScheme, toolInput, toolOutput, widgetState: initialWidgetState, userMessage, showControls, uiSimulations, initialUISimulation, }: ChatGPTSimulatorProps): react_jsx_runtime.JSX.Element;
391
+
392
+ interface PlatformProviderProps {
393
+ /**
394
+ * The platform adapter to use. If not provided, will auto-detect.
395
+ */
396
+ adapter?: PlatformAdapter;
397
+ /**
398
+ * Platform name to use (e.g., 'chatgpt', 'gemini'). If not provided, will auto-detect.
399
+ */
400
+ platform?: string;
401
+ children: ReactNode;
402
+ }
403
+ /**
404
+ * Platform Provider
405
+ *
406
+ * Wrap your app with this provider to specify which genAI platform to use.
407
+ * If no platform is specified, it will auto-detect the available platform.
408
+ *
409
+ * @example
410
+ * ```tsx
411
+ * import { PlatformProvider } from 'sunpeak';
412
+ *
413
+ * // Auto-detect platform
414
+ * <PlatformProvider>
415
+ * <App />
416
+ * </PlatformProvider>
417
+ *
418
+ * // Explicitly use ChatGPT
419
+ * <PlatformProvider platform="chatgpt">
420
+ * <App />
421
+ * </PlatformProvider>
422
+ * ```
423
+ */
424
+ declare function PlatformProvider({ adapter, platform, children }: PlatformProviderProps): react_jsx_runtime.JSX.Element;
425
+ /**
426
+ * Hook to access the current platform adapter
427
+ *
428
+ * Returns null if no platform is available or detected.
429
+ */
430
+ declare function usePlatform(): PlatformAdapter | null;
431
+
432
+ declare class ChatGPTPlatformAdapter implements PlatformAdapter {
433
+ readonly name = "chatgpt";
434
+ isAvailable(): boolean;
435
+ getGlobal<K extends keyof PlatformGlobals>(key: K): PlatformGlobals[K] | null;
436
+ getGlobals(): ({
437
+ callTool: CallTool$1;
438
+ sendFollowUpMessage: (args: {
439
+ prompt: string;
440
+ }) => Promise<void>;
441
+ openExternal(payload: {
442
+ href: string;
443
+ }): void;
444
+ requestDisplayMode: RequestDisplayMode$1;
445
+ } & ChatGPTGlobals<UnknownObject$1, UnknownObject$1, UnknownObject$1, UnknownObject$1>) | null;
446
+ subscribe(callback: () => void): () => void;
447
+ }
448
+ /**
449
+ * Singleton instance of the ChatGPT platform adapter
450
+ */
451
+ declare const chatgptPlatform: ChatGPTPlatformAdapter;
452
+
453
+ /**
454
+ * Platform Registry
455
+ *
456
+ * Manages multiple platform adapters and auto-detects the active platform.
457
+ */
458
+
459
+ interface PlatformRegistry {
460
+ /**
461
+ * Register a platform adapter
462
+ */
463
+ register(adapter: PlatformAdapter): void;
464
+ /**
465
+ * Get a specific platform adapter by name
466
+ */
467
+ get(name: string): PlatformAdapter | null;
468
+ /**
469
+ * Auto-detect and return the active platform
470
+ * Returns the first available platform in the registry
471
+ */
472
+ detect(): PlatformAdapter | null;
473
+ /**
474
+ * Get all registered platforms
475
+ */
476
+ getAll(): PlatformAdapter[];
477
+ }
478
+ /**
479
+ * Create a new platform registry
480
+ */
481
+ declare function createPlatformRegistry(): PlatformRegistry;
482
+
483
+ /**
484
+ * Hook to access platform global state in a platform-agnostic way.
485
+ * Works with any genAI platform (ChatGPT, Gemini, Claude, etc.)
486
+ *
487
+ * Uses React's useSyncExternalStore to efficiently subscribe to changes.
488
+ *
489
+ * @param key - The key of the global state to access
490
+ * @returns The value of the global state, or null if not available
491
+ *
492
+ * @example
493
+ * ```tsx
494
+ * function MyWidget() {
495
+ * const colorScheme = usePlatformGlobal('colorScheme');
496
+ * const displayMode = usePlatformGlobal('displayMode');
497
+ *
498
+ * return <div className={colorScheme === 'dark' ? 'dark' : 'light'}>...</div>;
499
+ * }
500
+ * ```
501
+ */
502
+ declare function usePlatformGlobal<K extends keyof PlatformGlobals>(key: K): PlatformGlobals[K] | null;
503
+
504
+ /**
505
+ * Hook to get the current display mode from the active genAI platform.
506
+ * Display modes include: 'inline', 'fullscreen', and 'pip' (picture-in-picture).
507
+ *
508
+ * Works with any supported genAI platform (ChatGPT, Gemini, Claude, etc.)
509
+ *
510
+ * @returns The current display mode, or null if not in a supported environment
511
+ */
512
+ declare const useDisplayMode: () => DisplayMode$1 | null;
513
+
514
+ /**
515
+ * Hook to get the maximum height constraint from the active genAI platform.
516
+ * Useful for ensuring your widget doesn't exceed the available space.
517
+ *
518
+ * Works with any supported genAI platform (ChatGPT, Gemini, Claude, etc.)
519
+ *
520
+ * @returns The maximum height in pixels, or null if not available
521
+ */
522
+ declare const useMaxHeight: () => number | null;
523
+
524
+ /**
525
+ * Hook to request a specific display mode from the platform
526
+ *
527
+ * @example
528
+ * ```tsx
529
+ * const requestDisplayMode = useRequestDisplayMode();
530
+ *
531
+ * const handleClick = async () => {
532
+ * await requestDisplayMode({ mode: 'fullscreen' });
533
+ * };
534
+ * ```
535
+ */
536
+ declare function useRequestDisplayMode(): RequestDisplayMode$1;
537
+
538
+ /**
539
+ * Hook to get the current color scheme from the active genAI platform.
540
+ * Color scheme can be 'light' or 'dark'.
541
+ *
542
+ * Works with any supported genAI platform (ChatGPT, Gemini, Claude, etc.)
543
+ *
544
+ * @returns The current color scheme, or null if not in a supported environment
545
+ */
546
+ declare const useColorScheme: () => Theme$1 | null;
547
+
548
+ /**
549
+ * Hook to get widget props (tool output) from the active genAI platform.
550
+ * This contains the data returned by your server's tool.
551
+ *
552
+ * Works with any supported genAI platform (ChatGPT, Gemini, Claude, etc.)
553
+ *
554
+ * @param defaultState - Default state to use if no props are available
555
+ * @returns The widget props from the tool output
556
+ */
557
+ declare function useWidgetProps<T extends Record<string, unknown>>(defaultState?: T | (() => T)): T;
558
+
559
+ /**
560
+ * Hook to manage widget state that persists in the active genAI platform.
561
+ * Similar to useState, but syncs with the platform host page.
562
+ *
563
+ * Works with any supported genAI platform (ChatGPT, Gemini, Claude, etc.)
564
+ *
565
+ * @param defaultState - Default state value or function to generate it
566
+ * @returns A tuple of [state, setState] similar to useState
567
+ */
568
+ declare function useWidgetState<T extends UnknownObject$1>(defaultState: T | (() => T)): readonly [T, (state: SetStateAction<T>) => void];
569
+ declare function useWidgetState<T extends UnknownObject$1>(defaultState?: T | (() => T | null) | null): readonly [T | null, (state: SetStateAction<T | null>) => void];
570
+
571
+ export { Button, type ButtonProps, type CallTool$1 as CallTool, type CallToolResponse$1 as CallToolResponse, Card, type CardProps, Carousel, type CarouselProps, type ChatGPTGlobals, ChatGPTSimulator, type ChatGPTSimulatorProps, type DeviceType$1 as DeviceType, type DisplayMode$1 as DisplayMode, GenAI, type GenAIProps, type GenAIRenderProps, type PlatformAPI, type PlatformAdapter, type PlatformGlobals, PlatformProvider, type PlatformProviderProps, type PlatformRegistry, type PlatformType, type RequestDisplayMode$1 as RequestDisplayMode, type SafeArea$1 as SafeArea, type SafeAreaInsets$1 as SafeAreaInsets, type Theme$1 as Theme, type UnknownObject$1 as UnknownObject, type UserAgent$1 as UserAgent, chatgptPlatform, createPlatformRegistry, useColorScheme, useDisplayMode, useMaxHeight, usePlatform, usePlatformGlobal, useRequestDisplayMode, useWidgetProps, useWidgetState };