@pancake-apps/web 0.0.0-snapshot-20260125200133

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,395 @@
1
+ import { d as ContentBlock, j as TeardownHandler, H as HostPlatform, l as UnifiedAdaptor, T as Theme, D as DisplayMode, S as SafeAreaInsets, P as Platform, a as DeviceType, C as ContainerSize, I as InputCapabilities, c as CallToolResult, f as ResourceReadResult, L as LogLevel } from './adaptor-interface-BYbH9PpT.js';
2
+ import { N as ToolInputParams, Q as ToolInputPartialParams, K as ToolCancelledParams, H as HostContext, g as HostCapabilities, h as HostInfo } from './types-B_O3kZYh.js';
3
+
4
+ /**
5
+ * View Class
6
+ *
7
+ * A unified, platform-agnostic API for building Pancake apps.
8
+ * Works seamlessly with both MCP Apps and ChatGPT Apps.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { View } from '@pancake-apps/web';
13
+ *
14
+ * const view = new View({
15
+ * appInfo: { name: "MyApp", version: "1.0.0" },
16
+ * });
17
+ *
18
+ * view.ontoolinput = (params) => {
19
+ * console.log("Tool input:", params.arguments);
20
+ * };
21
+ *
22
+ * await view.connect();
23
+ *
24
+ * // Actions
25
+ * await view.callTool("my-tool", { arg: "value" });
26
+ * view.sendMessage("Hello!");
27
+ * ```
28
+ */
29
+
30
+ /**
31
+ * App information for initialization
32
+ */
33
+ interface ViewAppInfo {
34
+ name: string;
35
+ version: string;
36
+ }
37
+ /**
38
+ * Options for creating a View
39
+ */
40
+ interface ViewOptions {
41
+ /**
42
+ * Application information (used for MCP initialization)
43
+ */
44
+ appInfo?: ViewAppInfo;
45
+ /**
46
+ * Force a specific platform instead of auto-detecting
47
+ */
48
+ platform?: HostPlatform;
49
+ /**
50
+ * Custom capabilities to send during MCP initialization
51
+ */
52
+ capabilities?: Record<string, unknown>;
53
+ }
54
+ /**
55
+ * Tool result notification params
56
+ */
57
+ interface ToolResultParams {
58
+ content: ContentBlock[];
59
+ structuredContent?: unknown;
60
+ isError?: boolean;
61
+ _meta?: Record<string, unknown>;
62
+ }
63
+ declare class View {
64
+ private adaptor;
65
+ private options;
66
+ private _isConnected;
67
+ private cleanupFns;
68
+ private _hostContext;
69
+ private _hostCapabilities;
70
+ private _hostInfo;
71
+ /**
72
+ * Called when tool input is received (complete input)
73
+ */
74
+ ontoolinput?: (params: ToolInputParams) => void;
75
+ /**
76
+ * Called during streaming when partial tool input is received (MCP only)
77
+ */
78
+ ontoolinputpartial?: (params: ToolInputPartialParams) => void;
79
+ /**
80
+ * Called when tool result is received
81
+ */
82
+ ontoolresult?: (params: ToolResultParams) => void;
83
+ /**
84
+ * Called when tool execution is cancelled
85
+ */
86
+ ontoolcancelled?: (params: ToolCancelledParams) => void;
87
+ /**
88
+ * Called when host context changes (theme, display mode, etc.)
89
+ */
90
+ onhostcontextchanged?: (context: HostContext) => void;
91
+ /**
92
+ * Called when the host requests teardown
93
+ */
94
+ onteardown?: TeardownHandler;
95
+ /**
96
+ * Called when an error occurs
97
+ */
98
+ onerror?: (error: Error) => void;
99
+ /**
100
+ * Called when the connection is closed
101
+ */
102
+ onclose?: () => void;
103
+ constructor(options?: ViewOptions);
104
+ /**
105
+ * Get the current host context (MCP-specific)
106
+ */
107
+ getHostContext(): HostContext | undefined;
108
+ /**
109
+ * Get host capabilities (MCP-specific)
110
+ */
111
+ getHostCapabilities(): HostCapabilities | undefined;
112
+ /**
113
+ * Get host info (MCP-specific)
114
+ */
115
+ getHostInfo(): HostInfo | undefined;
116
+ /**
117
+ * Check if the view is connected
118
+ */
119
+ isConnected(): boolean;
120
+ /**
121
+ * Get the current platform
122
+ */
123
+ getPlatform(): HostPlatform;
124
+ /**
125
+ * Get the underlying adaptor for advanced use cases
126
+ */
127
+ getAdaptor(): UnifiedAdaptor;
128
+ /**
129
+ * Get the current theme
130
+ */
131
+ getTheme(): Theme;
132
+ /**
133
+ * Get the current locale
134
+ */
135
+ getLocale(): string;
136
+ /**
137
+ * Get the current display mode
138
+ */
139
+ getDisplayMode(): DisplayMode;
140
+ /**
141
+ * Get the max height constraint
142
+ */
143
+ getMaxHeight(): number;
144
+ /**
145
+ * Get safe area insets
146
+ */
147
+ getSafeArea(): SafeAreaInsets;
148
+ /**
149
+ * Get the normalized platform
150
+ */
151
+ getNormalizedPlatform(): Platform;
152
+ /**
153
+ * Get the device type
154
+ */
155
+ getDeviceType(): DeviceType;
156
+ /**
157
+ * Get container size
158
+ */
159
+ getContainerSize(): ContainerSize;
160
+ /**
161
+ * Get input capabilities
162
+ */
163
+ getInputCapabilities(): InputCapabilities;
164
+ /**
165
+ * Get the current tool input
166
+ */
167
+ getToolInput<T>(): T | undefined;
168
+ /**
169
+ * Get partial tool input during streaming (MCP only)
170
+ */
171
+ getToolInputPartial<T>(): Partial<T> | undefined;
172
+ /**
173
+ * Get the current tool output
174
+ */
175
+ getToolOutput<T>(): T | undefined;
176
+ /**
177
+ * Connect to the host platform.
178
+ * For MCP, this performs the initialization handshake.
179
+ * For Apps SDK, this is a no-op (already connected).
180
+ */
181
+ connect(): Promise<void>;
182
+ private connectMcp;
183
+ private connectAppsSdk;
184
+ /**
185
+ * Close the view and cleanup resources
186
+ */
187
+ close(): void;
188
+ /**
189
+ * Call a server tool
190
+ */
191
+ callTool<TInput = Record<string, unknown>, TOutput = unknown>(name: string, args?: TInput): Promise<CallToolResult<TOutput>>;
192
+ /**
193
+ * Send a message to the chat
194
+ */
195
+ sendMessage(content: string | ContentBlock[]): Promise<void>;
196
+ /**
197
+ * Open a link in the browser
198
+ */
199
+ openLink(url: string): Promise<void>;
200
+ /**
201
+ * Request a display mode change
202
+ */
203
+ requestDisplayMode(mode: DisplayMode): Promise<DisplayMode>;
204
+ /**
205
+ * Update the model context (MCP only)
206
+ */
207
+ updateModelContext(content?: ContentBlock[], structured?: Record<string, unknown>): Promise<void>;
208
+ /**
209
+ * Read a resource (MCP only)
210
+ */
211
+ readResource(uri: string): Promise<ResourceReadResult>;
212
+ /**
213
+ * Notify the host of size changes
214
+ */
215
+ notifySizeChanged(width: number, height: number): void;
216
+ /**
217
+ * Setup automatic size reporting
218
+ */
219
+ setupAutoSizeReporting(element?: HTMLElement): () => void;
220
+ /**
221
+ * Log a message to the host
222
+ */
223
+ log(level: LogLevel, data: unknown, logger?: string): void;
224
+ /**
225
+ * Ping the host (MCP only)
226
+ */
227
+ ping(): Promise<void>;
228
+ private ensureConnected;
229
+ }
230
+ /**
231
+ * Create and optionally connect a View
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * const view = await createView({
236
+ * appInfo: { name: "MyApp", version: "1.0.0" },
237
+ * autoConnect: true,
238
+ * });
239
+ * ```
240
+ */
241
+ declare function createView(options?: ViewOptions & {
242
+ autoConnect?: boolean;
243
+ }): Promise<View>;
244
+
245
+ /**
246
+ * useView Hook
247
+ *
248
+ * React hook for creating and managing a View instance.
249
+ *
250
+ * @example
251
+ * ```tsx
252
+ * const { view, isConnected, error } = useView({
253
+ * appInfo: { name: "MyApp", version: "1.0.0" },
254
+ * onViewCreated: (view) => {
255
+ * view.ontoolinput = handleToolInput;
256
+ * },
257
+ * });
258
+ * ```
259
+ */
260
+
261
+ interface UseViewOptions extends ViewOptions {
262
+ /**
263
+ * Whether to auto-connect on mount (default: true)
264
+ */
265
+ autoConnect?: boolean;
266
+ /**
267
+ * Callback when the view is created (before connecting)
268
+ * Use this to set up event handlers
269
+ */
270
+ onViewCreated?: (view: View) => void;
271
+ /**
272
+ * Callback when successfully connected
273
+ */
274
+ onConnected?: (view: View) => void;
275
+ /**
276
+ * Callback when connection fails
277
+ */
278
+ onError?: (error: Error) => void;
279
+ /**
280
+ * Callback when the view is closed
281
+ */
282
+ onClose?: () => void;
283
+ }
284
+ interface UseViewResult {
285
+ /**
286
+ * The View instance
287
+ */
288
+ view: View | null;
289
+ /**
290
+ * Whether the view is connected
291
+ */
292
+ isConnected: boolean;
293
+ /**
294
+ * Whether the view is currently connecting
295
+ */
296
+ isConnecting: boolean;
297
+ /**
298
+ * Any error that occurred during connection
299
+ */
300
+ error: Error | null;
301
+ /**
302
+ * Manually connect the view
303
+ */
304
+ connect: () => Promise<void>;
305
+ /**
306
+ * Manually disconnect/close the view
307
+ */
308
+ disconnect: () => void;
309
+ }
310
+ /**
311
+ * Create and manage a View instance
312
+ */
313
+ declare function useView(options?: UseViewOptions): UseViewResult;
314
+
315
+ /**
316
+ * useHostStyles Hook
317
+ *
318
+ * React hook for applying host-provided styles to the document.
319
+ *
320
+ * @example
321
+ * ```tsx
322
+ * const { view, isConnected } = useView({ ... });
323
+ *
324
+ * // Apply host styles when connected
325
+ * useHostStyles(view?.getHostContext());
326
+ * ```
327
+ */
328
+
329
+ interface UseHostStylesOptions {
330
+ /**
331
+ * Whether to apply theme (default: true)
332
+ */
333
+ applyTheme?: boolean;
334
+ /**
335
+ * Whether to apply CSS variables (default: true)
336
+ */
337
+ applyVariables?: boolean;
338
+ /**
339
+ * Whether to apply fonts (default: true)
340
+ */
341
+ applyFonts?: boolean;
342
+ /**
343
+ * Whether to apply safe area insets (default: true)
344
+ */
345
+ applySafeArea?: boolean;
346
+ /**
347
+ * Whether to clear styles on unmount (default: true)
348
+ */
349
+ clearOnUnmount?: boolean;
350
+ }
351
+ /**
352
+ * Apply host-provided styles to the document
353
+ */
354
+ declare function useHostStyles(context: HostContext | undefined, options?: UseHostStylesOptions): void;
355
+ /**
356
+ * Apply only the theme from host context
357
+ */
358
+ declare function useHostTheme(context: HostContext | undefined): void;
359
+ /**
360
+ * Apply only CSS variables from host context
361
+ */
362
+ declare function useHostVariables(context: HostContext | undefined): void;
363
+ /**
364
+ * Apply only fonts from host context
365
+ */
366
+ declare function useHostFontsHook(context: HostContext | undefined): void;
367
+
368
+ /**
369
+ * useDocumentTheme Hook
370
+ *
371
+ * React hook for reactive document theme detection.
372
+ *
373
+ * @example
374
+ * ```tsx
375
+ * const theme = useDocumentTheme();
376
+ * console.log(theme); // 'light' or 'dark'
377
+ * ```
378
+ */
379
+
380
+ /**
381
+ * Get the current document theme reactively
382
+ * Updates when the theme changes (via class, data-theme, or system preference)
383
+ */
384
+ declare function useDocumentTheme(): Theme;
385
+ /**
386
+ * Alternative hook using useState/useEffect pattern
387
+ * @deprecated Use useDocumentTheme() instead
388
+ */
389
+ declare function useDocumentThemeState(): Theme;
390
+ /**
391
+ * Get the system color scheme preference (ignores document classes)
392
+ */
393
+ declare function useSystemColorScheme(): Theme;
394
+
395
+ export { type ToolResultParams as T, type UseHostStylesOptions as U, View as V, type UseViewOptions as a, type UseViewResult as b, type ViewAppInfo as c, type ViewOptions as d, createView as e, useDocumentThemeState as f, useHostFontsHook as g, useHostStyles as h, useHostTheme as i, useHostVariables as j, useSystemColorScheme as k, useView as l, useDocumentTheme as u };