@pancake-apps/web 0.0.1
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/index.cjs +929 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +479 -0
- package/dist/index.d.ts +479 -0
- package/dist/index.js +919 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.cjs +1067 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +536 -0
- package/dist/react/index.d.ts +536 -0
- package/dist/react/index.js +1053 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +83 -0
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import React__default, { ReactNode, ComponentType } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Host context provided by MCP or OpenAI hosts
|
|
6
|
+
*/
|
|
7
|
+
interface HostContext {
|
|
8
|
+
/** Current theme */
|
|
9
|
+
theme: 'light' | 'dark';
|
|
10
|
+
/** Current display mode */
|
|
11
|
+
displayMode: 'inline' | 'fullscreen' | 'pip';
|
|
12
|
+
/** Available display modes */
|
|
13
|
+
availableDisplayModes: string[];
|
|
14
|
+
/** Viewport dimensions */
|
|
15
|
+
viewport: {
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
};
|
|
19
|
+
/** User's locale (e.g., 'en-US') */
|
|
20
|
+
locale: string;
|
|
21
|
+
/** User's timezone */
|
|
22
|
+
timeZone: string;
|
|
23
|
+
/** Platform type */
|
|
24
|
+
platform: 'desktop' | 'mobile' | 'web';
|
|
25
|
+
/** Current view identifier (if applicable) */
|
|
26
|
+
view?: string;
|
|
27
|
+
/** Safe area insets for mobile */
|
|
28
|
+
safeAreaInsets?: {
|
|
29
|
+
top: number;
|
|
30
|
+
right: number;
|
|
31
|
+
bottom: number;
|
|
32
|
+
left: number;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* View parameters passed to the UI
|
|
37
|
+
*/
|
|
38
|
+
interface ViewParams<TInputs = unknown, TData = unknown> {
|
|
39
|
+
/** Input parameters passed to the view */
|
|
40
|
+
inputs: TInputs;
|
|
41
|
+
/** Data returned by the view handler */
|
|
42
|
+
data: TData;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Protocol types
|
|
46
|
+
*/
|
|
47
|
+
type Protocol = 'mcp' | 'openai' | 'mock';
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Protocol adapter interface.
|
|
51
|
+
* Abstracts communication with the host (MCP or OpenAI).
|
|
52
|
+
*/
|
|
53
|
+
interface ProtocolAdapter {
|
|
54
|
+
/** Protocol name */
|
|
55
|
+
readonly protocol: 'mcp' | 'openai' | 'mock';
|
|
56
|
+
/** Whether the adapter is connected */
|
|
57
|
+
isConnected(): boolean;
|
|
58
|
+
/** Connect to the host */
|
|
59
|
+
connect(): Promise<void>;
|
|
60
|
+
/** Disconnect from the host */
|
|
61
|
+
disconnect(): Promise<void>;
|
|
62
|
+
/** Get the current host context */
|
|
63
|
+
getHostContext(): HostContext;
|
|
64
|
+
/** Subscribe to host context changes */
|
|
65
|
+
onHostContextChange(handler: (ctx: HostContext) => void): () => void;
|
|
66
|
+
/** Get the current view parameters (inputs + data) */
|
|
67
|
+
getViewParams(): ViewParams;
|
|
68
|
+
/** Get the current tool input (what the model sent) */
|
|
69
|
+
getToolInput(): Record<string, unknown> | undefined;
|
|
70
|
+
/** Get the current tool output (what the handler returned) */
|
|
71
|
+
getToolOutput(): Record<string, unknown> | undefined;
|
|
72
|
+
/** Subscribe to tool input changes */
|
|
73
|
+
onToolInput(handler: (input: unknown) => void): () => void;
|
|
74
|
+
/** Subscribe to tool output changes */
|
|
75
|
+
onToolOutput(handler: (output: unknown) => void): () => void;
|
|
76
|
+
/** Call a tool on the server */
|
|
77
|
+
callTool(name: string, args: Record<string, unknown>): Promise<unknown>;
|
|
78
|
+
/** Send a message to the model */
|
|
79
|
+
sendMessage(content: {
|
|
80
|
+
type: string;
|
|
81
|
+
text: string;
|
|
82
|
+
}): Promise<void>;
|
|
83
|
+
/** Open a link in the host */
|
|
84
|
+
openLink(url: string): Promise<void>;
|
|
85
|
+
/** Request a display mode change */
|
|
86
|
+
requestDisplayMode(mode: 'inline' | 'fullscreen' | 'pip'): Promise<{
|
|
87
|
+
mode: string;
|
|
88
|
+
}>;
|
|
89
|
+
/** Request to close the UI */
|
|
90
|
+
requestClose(): void;
|
|
91
|
+
/** Get the current view state */
|
|
92
|
+
getState<T>(): T | null;
|
|
93
|
+
/** Set the view state */
|
|
94
|
+
setState<T>(state: T): void;
|
|
95
|
+
/** Subscribe to tool cancellation */
|
|
96
|
+
onToolCancelled(handler: (reason?: string) => void): () => void;
|
|
97
|
+
/** Subscribe to teardown */
|
|
98
|
+
onTeardown(handler: (reason?: string) => void): () => void;
|
|
99
|
+
/** Log a message */
|
|
100
|
+
log(level: 'debug' | 'info' | 'warn' | 'error', data: unknown): void;
|
|
101
|
+
/** Notify the host of a size change */
|
|
102
|
+
sendSizeChanged(params: {
|
|
103
|
+
width: number;
|
|
104
|
+
height: number;
|
|
105
|
+
}): Promise<void>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Options for creating a Pancake client
|
|
110
|
+
*/
|
|
111
|
+
interface PancakeClientOptions {
|
|
112
|
+
/** Force a specific protocol adapter */
|
|
113
|
+
forceAdapter?: Protocol;
|
|
114
|
+
/** Enable auto-resize (default: true) */
|
|
115
|
+
autoResize?: boolean;
|
|
116
|
+
/** Initial tool input (for mock adapter) */
|
|
117
|
+
toolInput?: Record<string, unknown>;
|
|
118
|
+
/** Initial tool output (for mock adapter) */
|
|
119
|
+
toolOutput?: Record<string, unknown>;
|
|
120
|
+
/** Initial host context (for mock adapter) */
|
|
121
|
+
hostContext?: Partial<HostContext>;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Pancake client that wraps a protocol adapter.
|
|
125
|
+
*/
|
|
126
|
+
declare class PancakeClient {
|
|
127
|
+
private adapter;
|
|
128
|
+
private constructor();
|
|
129
|
+
/**
|
|
130
|
+
* Create and connect a Pancake client.
|
|
131
|
+
*/
|
|
132
|
+
static create(options?: PancakeClientOptions): Promise<PancakeClient>;
|
|
133
|
+
/**
|
|
134
|
+
* Create a Pancake client with a pre-configured adapter.
|
|
135
|
+
*/
|
|
136
|
+
static fromAdapter(adapter: ProtocolAdapter): PancakeClient;
|
|
137
|
+
/**
|
|
138
|
+
* Get the underlying protocol adapter.
|
|
139
|
+
*/
|
|
140
|
+
getAdapter(): ProtocolAdapter;
|
|
141
|
+
/**
|
|
142
|
+
* Get the current protocol.
|
|
143
|
+
*/
|
|
144
|
+
get protocol(): Protocol;
|
|
145
|
+
/**
|
|
146
|
+
* Check if the client is connected.
|
|
147
|
+
*/
|
|
148
|
+
isConnected(): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Get the current host context.
|
|
151
|
+
*/
|
|
152
|
+
getHostContext(): HostContext;
|
|
153
|
+
/**
|
|
154
|
+
* Subscribe to host context changes.
|
|
155
|
+
*/
|
|
156
|
+
onHostContextChange(handler: (ctx: HostContext) => void): () => void;
|
|
157
|
+
/**
|
|
158
|
+
* Get the current view parameters.
|
|
159
|
+
*/
|
|
160
|
+
getViewParams(): ViewParams;
|
|
161
|
+
/**
|
|
162
|
+
* Get the current tool input.
|
|
163
|
+
*/
|
|
164
|
+
getToolInput(): Record<string, unknown> | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* Get the current tool output.
|
|
167
|
+
*/
|
|
168
|
+
getToolOutput(): Record<string, unknown> | undefined;
|
|
169
|
+
/**
|
|
170
|
+
* Subscribe to tool input changes.
|
|
171
|
+
*/
|
|
172
|
+
onToolInput(handler: (input: unknown) => void): () => void;
|
|
173
|
+
/**
|
|
174
|
+
* Subscribe to tool output changes.
|
|
175
|
+
*/
|
|
176
|
+
onToolOutput(handler: (output: unknown) => void): () => void;
|
|
177
|
+
/**
|
|
178
|
+
* Call a tool on the server.
|
|
179
|
+
*/
|
|
180
|
+
callTool<T = unknown>(name: string, args?: Record<string, unknown>): Promise<T>;
|
|
181
|
+
/**
|
|
182
|
+
* Navigate to a view (calls view:name tool).
|
|
183
|
+
*/
|
|
184
|
+
navigateToView(viewName: string, params?: Record<string, unknown>): Promise<void>;
|
|
185
|
+
/**
|
|
186
|
+
* Dispatch an action (calls action:name tool).
|
|
187
|
+
*/
|
|
188
|
+
dispatch<T = unknown>(actionName: string, params?: Record<string, unknown>): Promise<T>;
|
|
189
|
+
/**
|
|
190
|
+
* Get data from a data fetcher (calls data:name tool).
|
|
191
|
+
*/
|
|
192
|
+
getData<T = unknown>(dataName: string, params?: Record<string, unknown>): Promise<T>;
|
|
193
|
+
/**
|
|
194
|
+
* Send a message to the model.
|
|
195
|
+
*/
|
|
196
|
+
say(message: string): Promise<void>;
|
|
197
|
+
/**
|
|
198
|
+
* Open a link in the host.
|
|
199
|
+
*/
|
|
200
|
+
openLink(url: string): Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* Request a display mode change.
|
|
203
|
+
*/
|
|
204
|
+
requestDisplayMode(mode: 'inline' | 'fullscreen' | 'pip'): Promise<{
|
|
205
|
+
mode: string;
|
|
206
|
+
}>;
|
|
207
|
+
/**
|
|
208
|
+
* Request to close the UI.
|
|
209
|
+
*/
|
|
210
|
+
requestClose(): void;
|
|
211
|
+
/**
|
|
212
|
+
* Get the current view state.
|
|
213
|
+
*/
|
|
214
|
+
getState<T>(): T | null;
|
|
215
|
+
/**
|
|
216
|
+
* Set the view state.
|
|
217
|
+
*/
|
|
218
|
+
setState<T>(state: T): void;
|
|
219
|
+
/**
|
|
220
|
+
* Subscribe to tool cancellation.
|
|
221
|
+
*/
|
|
222
|
+
onToolCancelled(handler: (reason?: string) => void): () => void;
|
|
223
|
+
/**
|
|
224
|
+
* Subscribe to teardown.
|
|
225
|
+
*/
|
|
226
|
+
onTeardown(handler: (reason?: string) => void): () => void;
|
|
227
|
+
/**
|
|
228
|
+
* Log a message.
|
|
229
|
+
*/
|
|
230
|
+
log(level: 'debug' | 'info' | 'warn' | 'error', data: unknown): void;
|
|
231
|
+
/**
|
|
232
|
+
* Notify the host of a size change.
|
|
233
|
+
*/
|
|
234
|
+
sendSizeChanged(params: {
|
|
235
|
+
width: number;
|
|
236
|
+
height: number;
|
|
237
|
+
}): Promise<void>;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Props for the PancakeProvider
|
|
242
|
+
*/
|
|
243
|
+
interface PancakeProviderProps {
|
|
244
|
+
children: ReactNode;
|
|
245
|
+
/** Pre-created client (optional) */
|
|
246
|
+
client?: PancakeClient;
|
|
247
|
+
/** Force a specific protocol adapter */
|
|
248
|
+
forceAdapter?: Protocol;
|
|
249
|
+
/** Enable auto-resize (default: true) */
|
|
250
|
+
autoResize?: boolean;
|
|
251
|
+
/** Initial host context (for testing) */
|
|
252
|
+
hostContext?: Partial<HostContext>;
|
|
253
|
+
/** Loading fallback UI */
|
|
254
|
+
fallback?: ReactNode;
|
|
255
|
+
/** Error fallback component */
|
|
256
|
+
errorFallback?: ComponentType<{
|
|
257
|
+
error: Error;
|
|
258
|
+
reset: () => void;
|
|
259
|
+
}>;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Provider component that initializes and provides the Pancake client.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```tsx
|
|
266
|
+
* import { PancakeProvider } from '@pancake-apps/web/react';
|
|
267
|
+
*
|
|
268
|
+
* function App() {
|
|
269
|
+
* return (
|
|
270
|
+
* <PancakeProvider>
|
|
271
|
+
* <MyView />
|
|
272
|
+
* </PancakeProvider>
|
|
273
|
+
* );
|
|
274
|
+
* }
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
declare function PancakeProvider({ children, client: providedClient, forceAdapter, autoResize, hostContext, fallback, errorFallback: ErrorFallback, }: PancakeProviderProps): React__default.ReactElement;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Context value for the Pancake provider
|
|
281
|
+
*/
|
|
282
|
+
interface PancakeContextValue {
|
|
283
|
+
client: PancakeClient | null;
|
|
284
|
+
isConnecting: boolean;
|
|
285
|
+
error: Error | null;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* React context for Pancake client
|
|
289
|
+
*/
|
|
290
|
+
declare const PancakeContext: React.Context<PancakeContextValue | null>;
|
|
291
|
+
/**
|
|
292
|
+
* Get the Pancake context (internal use)
|
|
293
|
+
*/
|
|
294
|
+
declare function usePancakeContext(): PancakeContextValue;
|
|
295
|
+
/**
|
|
296
|
+
* Get the Pancake client (throws if not connected)
|
|
297
|
+
*/
|
|
298
|
+
declare function usePancakeClient(): PancakeClient;
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Hook for managing view state.
|
|
302
|
+
*
|
|
303
|
+
* State is persisted in ChatGPT, volatile in MCP.
|
|
304
|
+
* Uses React-style updater function pattern.
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```tsx
|
|
308
|
+
* function Counter() {
|
|
309
|
+
* const [count, setCount] = useViewState(0);
|
|
310
|
+
*
|
|
311
|
+
* return (
|
|
312
|
+
* <div>
|
|
313
|
+
* <p>Count: {count}</p>
|
|
314
|
+
* <button onClick={() => setCount(c => c + 1)}>+</button>
|
|
315
|
+
* </div>
|
|
316
|
+
* );
|
|
317
|
+
* }
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
declare function useViewState<T>(defaultValue: T): [T, (newState: T | ((prev: T) => T)) => void];
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Hook for accessing the full host context.
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* ```tsx
|
|
327
|
+
* function MyComponent() {
|
|
328
|
+
* const host = useHost();
|
|
329
|
+
*
|
|
330
|
+
* return (
|
|
331
|
+
* <div>
|
|
332
|
+
* <p>Theme: {host.theme}</p>
|
|
333
|
+
* <p>Platform: {host.platform}</p>
|
|
334
|
+
* <p>Locale: {host.locale}</p>
|
|
335
|
+
* </div>
|
|
336
|
+
* );
|
|
337
|
+
* }
|
|
338
|
+
* ```
|
|
339
|
+
*/
|
|
340
|
+
declare function useHost(): HostContext;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Hook for accessing the current theme.
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```tsx
|
|
347
|
+
* function MyComponent() {
|
|
348
|
+
* const theme = useTheme();
|
|
349
|
+
*
|
|
350
|
+
* return (
|
|
351
|
+
* <div data-theme={theme}>
|
|
352
|
+
* <p>Current theme: {theme}</p>
|
|
353
|
+
* </div>
|
|
354
|
+
* );
|
|
355
|
+
* }
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
declare function useTheme(): 'light' | 'dark';
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Return type for useDisplayMode hook
|
|
362
|
+
*/
|
|
363
|
+
interface DisplayModeHook {
|
|
364
|
+
/** Current display mode */
|
|
365
|
+
mode: 'inline' | 'fullscreen' | 'pip';
|
|
366
|
+
/** Available display modes */
|
|
367
|
+
availableModes: string[];
|
|
368
|
+
/** Request a display mode change */
|
|
369
|
+
requestMode: (mode: 'inline' | 'fullscreen' | 'pip') => Promise<void>;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Hook for managing display mode.
|
|
373
|
+
*
|
|
374
|
+
* @example
|
|
375
|
+
* ```tsx
|
|
376
|
+
* function MyComponent() {
|
|
377
|
+
* const { mode, availableModes, requestMode } = useDisplayMode();
|
|
378
|
+
*
|
|
379
|
+
* return (
|
|
380
|
+
* <div>
|
|
381
|
+
* <p>Current mode: {mode}</p>
|
|
382
|
+
* {availableModes.includes('fullscreen') && (
|
|
383
|
+
* <button onClick={() => requestMode('fullscreen')}>
|
|
384
|
+
* Go Fullscreen
|
|
385
|
+
* </button>
|
|
386
|
+
* )}
|
|
387
|
+
* </div>
|
|
388
|
+
* );
|
|
389
|
+
* }
|
|
390
|
+
* ```
|
|
391
|
+
*/
|
|
392
|
+
declare function useDisplayMode(): DisplayModeHook;
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Return type for useNavigation hook
|
|
396
|
+
*/
|
|
397
|
+
interface NavigationHook {
|
|
398
|
+
/** Navigate to a view (triggers view:name tool call) */
|
|
399
|
+
navigate: (viewName: string, params?: Record<string, unknown>) => Promise<void>;
|
|
400
|
+
/** Send a message to the model */
|
|
401
|
+
say: (message: string) => Promise<void>;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Hook for navigation and communication with the model.
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* ```tsx
|
|
408
|
+
* function MyComponent() {
|
|
409
|
+
* const { navigate, say } = useNavigation();
|
|
410
|
+
*
|
|
411
|
+
* return (
|
|
412
|
+
* <div>
|
|
413
|
+
* <button onClick={() => navigate('dashboard', { userId: '123' })}>
|
|
414
|
+
* Go to Dashboard
|
|
415
|
+
* </button>
|
|
416
|
+
* <button onClick={() => say('Show me more details')}>
|
|
417
|
+
* Ask for More
|
|
418
|
+
* </button>
|
|
419
|
+
* </div>
|
|
420
|
+
* );
|
|
421
|
+
* }
|
|
422
|
+
* ```
|
|
423
|
+
*/
|
|
424
|
+
declare function useNavigation(): NavigationHook;
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Hook for accessing the current action input.
|
|
428
|
+
*
|
|
429
|
+
* This is useful for action UIs that need to display
|
|
430
|
+
* or process the input sent by the model.
|
|
431
|
+
*
|
|
432
|
+
* @example
|
|
433
|
+
* ```tsx
|
|
434
|
+
* function ActionConfirmation() {
|
|
435
|
+
* const input = useActionInput<{ itemId: string; action: string }>();
|
|
436
|
+
*
|
|
437
|
+
* if (!input) return <div>No input</div>;
|
|
438
|
+
*
|
|
439
|
+
* return (
|
|
440
|
+
* <div>
|
|
441
|
+
* <p>Action: {input.action}</p>
|
|
442
|
+
* <p>Item: {input.itemId}</p>
|
|
443
|
+
* </div>
|
|
444
|
+
* );
|
|
445
|
+
* }
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
declare function useActionInput<T = Record<string, unknown>>(): T | undefined;
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Hook for accessing view parameters (inputs + data).
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* ```tsx
|
|
455
|
+
* function MyView() {
|
|
456
|
+
* const { inputs, data } = useViewParams<
|
|
457
|
+
* { userId: string },
|
|
458
|
+
* { user: { name: string; email: string } }
|
|
459
|
+
* >();
|
|
460
|
+
*
|
|
461
|
+
* return (
|
|
462
|
+
* <div>
|
|
463
|
+
* <p>User ID: {inputs.userId}</p>
|
|
464
|
+
* <p>Name: {data.user.name}</p>
|
|
465
|
+
* <p>Email: {data.user.email}</p>
|
|
466
|
+
* </div>
|
|
467
|
+
* );
|
|
468
|
+
* }
|
|
469
|
+
* ```
|
|
470
|
+
*/
|
|
471
|
+
declare function useViewParams<TInputs = unknown, TData = unknown>(): ViewParams<TInputs, TData>;
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Return type for useAction hook
|
|
475
|
+
*/
|
|
476
|
+
interface ActionHook {
|
|
477
|
+
/** Dispatch an action (calls action:name tool) */
|
|
478
|
+
dispatch: <T = unknown>(actionName: string, params?: Record<string, unknown>) => Promise<T>;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Hook for dispatching actions (write operations).
|
|
482
|
+
*
|
|
483
|
+
* @example
|
|
484
|
+
* ```tsx
|
|
485
|
+
* function MyComponent() {
|
|
486
|
+
* const { dispatch } = useAction();
|
|
487
|
+
*
|
|
488
|
+
* const handleSubmit = async () => {
|
|
489
|
+
* const result = await dispatch<{ success: boolean }>('createUser', {
|
|
490
|
+
* name: 'John',
|
|
491
|
+
* email: 'john@example.com',
|
|
492
|
+
* });
|
|
493
|
+
* console.log('Created:', result.success);
|
|
494
|
+
* };
|
|
495
|
+
*
|
|
496
|
+
* return <button onClick={handleSubmit}>Create User</button>;
|
|
497
|
+
* }
|
|
498
|
+
* ```
|
|
499
|
+
*/
|
|
500
|
+
declare function useAction(): ActionHook;
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Return type for useData hook
|
|
504
|
+
*/
|
|
505
|
+
interface DataHook {
|
|
506
|
+
/** Fetch data from a data endpoint (calls data:name tool) */
|
|
507
|
+
getData: <T = unknown>(dataName: string, params?: Record<string, unknown>) => Promise<T>;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Hook for fetching data (read operations).
|
|
511
|
+
*
|
|
512
|
+
* @example
|
|
513
|
+
* ```tsx
|
|
514
|
+
* function UserList() {
|
|
515
|
+
* const { getData } = useData();
|
|
516
|
+
* const [users, setUsers] = useState<User[]>([]);
|
|
517
|
+
*
|
|
518
|
+
* const loadUsers = async () => {
|
|
519
|
+
* const data = await getData<User[]>('listUsers', { limit: 10 });
|
|
520
|
+
* setUsers(data);
|
|
521
|
+
* };
|
|
522
|
+
*
|
|
523
|
+
* return (
|
|
524
|
+
* <div>
|
|
525
|
+
* <button onClick={loadUsers}>Load Users</button>
|
|
526
|
+
* <ul>
|
|
527
|
+
* {users.map(u => <li key={u.id}>{u.name}</li>)}
|
|
528
|
+
* </ul>
|
|
529
|
+
* </div>
|
|
530
|
+
* );
|
|
531
|
+
* }
|
|
532
|
+
* ```
|
|
533
|
+
*/
|
|
534
|
+
declare function useData(): DataHook;
|
|
535
|
+
|
|
536
|
+
export { type ActionHook, type DataHook, type DisplayModeHook, type HostContext, type NavigationHook, PancakeContext, type PancakeContextValue, PancakeProvider, type PancakeProviderProps, type Protocol, type ViewParams, useAction, useActionInput, useData, useDisplayMode, useHost, useNavigation, usePancakeClient, usePancakeContext, useTheme, useViewParams, useViewState };
|