@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.
- package/README.md +333 -0
- package/dist/adaptor-interface-BYbH9PpT.d.ts +370 -0
- package/dist/apps-sdk/index.d.ts +1 -0
- package/dist/apps-sdk/index.js +4 -0
- package/dist/apps-sdk/index.js.map +1 -0
- package/dist/chunk-5NYJ2IVD.js +406 -0
- package/dist/chunk-5NYJ2IVD.js.map +1 -0
- package/dist/chunk-7HJ5PKKT.js +146 -0
- package/dist/chunk-7HJ5PKKT.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +9 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-TLBYYZHP.js +715 -0
- package/dist/chunk-TLBYYZHP.js.map +1 -0
- package/dist/chunk-YGGRUIUG.js +977 -0
- package/dist/chunk-YGGRUIUG.js.map +1 -0
- package/dist/chunk-ZYBPDIEG.js +674 -0
- package/dist/chunk-ZYBPDIEG.js.map +1 -0
- package/dist/core/index.d.ts +169 -0
- package/dist/core/index.js +195 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index-BBfZZJWn.d.ts +671 -0
- package/dist/index-CpXDfXKD.d.ts +395 -0
- package/dist/index-DtukOUjY.d.ts +738 -0
- package/dist/index.d.ts +741 -0
- package/dist/index.js +685 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-apps/index.d.ts +2 -0
- package/dist/mcp-apps/index.js +4 -0
- package/dist/mcp-apps/index.js.map +1 -0
- package/dist/notify-size-changed-Ck2BGfUk.d.ts +270 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.js +7 -0
- package/dist/react/index.js.map +1 -0
- package/dist/types-B_O3kZYh.d.ts +253 -0
- package/package.json +90 -0
package/README.md
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
# @pancake-apps/web
|
|
2
|
+
|
|
3
|
+
Unified SDK for building views that work across AI host environments (ChatGPT Apps SDK and MCP Apps).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Multi-platform support**: Write once, run everywhere (ChatGPT Apps SDK or MCP Apps)
|
|
8
|
+
- **React 18 optimized**: Built with `useSyncExternalStore` for efficient state management
|
|
9
|
+
- **Type-safe**: Full TypeScript support with comprehensive type definitions
|
|
10
|
+
- **Modular**: Use the unified SDK or platform-specific SDKs based on your needs
|
|
11
|
+
- **Tree-shakeable**: ESM-only with proper exports for optimal bundle size
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @pancake-apps/web
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Package Structure
|
|
20
|
+
|
|
21
|
+
This package provides three subpath exports:
|
|
22
|
+
|
|
23
|
+
| Import Path | Description |
|
|
24
|
+
|-------------|-------------|
|
|
25
|
+
| `@pancake-apps/web` | Unified SDK - auto-detects platform |
|
|
26
|
+
| `@pancake-apps/web/apps-sdk` | ChatGPT Apps SDK (wraps `window.openai`) |
|
|
27
|
+
| `@pancake-apps/web/mcp-apps` | MCP Apps SDK (JSON-RPC over postMessage) |
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
### Unified SDK (Recommended)
|
|
32
|
+
|
|
33
|
+
The unified SDK automatically detects the platform and provides a consistent API:
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import {
|
|
37
|
+
useTheme,
|
|
38
|
+
useLocale,
|
|
39
|
+
useDisplayMode,
|
|
40
|
+
useHostEnvironment,
|
|
41
|
+
callTool,
|
|
42
|
+
sendFollowUpMessage,
|
|
43
|
+
} from '@pancake-apps/web';
|
|
44
|
+
|
|
45
|
+
function MyApp() {
|
|
46
|
+
const theme = useTheme(); // 'light' | 'dark'
|
|
47
|
+
const locale = useLocale(); // e.g., 'en-US'
|
|
48
|
+
const displayMode = useDisplayMode(); // 'inline' | 'pip' | 'fullscreen'
|
|
49
|
+
|
|
50
|
+
// Get all environment info at once
|
|
51
|
+
const env = useHostEnvironment();
|
|
52
|
+
|
|
53
|
+
const handleClick = async () => {
|
|
54
|
+
// Call a tool
|
|
55
|
+
const result = await callTool('my-tool', { param: 'value' });
|
|
56
|
+
|
|
57
|
+
// Send a message back to the conversation
|
|
58
|
+
await sendFollowUpMessage('Here is the result...');
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<div data-theme={theme}>
|
|
63
|
+
{/* Your app */}
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Platform-Specific SDKs
|
|
70
|
+
|
|
71
|
+
If you know your target platform, you can import directly:
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
// For ChatGPT Apps
|
|
75
|
+
import { useTheme, callTool } from '@pancake-apps/web/apps-sdk';
|
|
76
|
+
|
|
77
|
+
// For MCP Apps
|
|
78
|
+
import { useTheme, callTool } from '@pancake-apps/web/mcp-apps';
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Semantic API (Recommended)
|
|
82
|
+
|
|
83
|
+
The Semantic API provides the simplest, most intuitive way to build Pancake apps:
|
|
84
|
+
|
|
85
|
+
### useViewData Hook
|
|
86
|
+
|
|
87
|
+
Get all view data in one hook with loading states:
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
import { useViewData, say } from '@pancake-apps/web';
|
|
91
|
+
|
|
92
|
+
interface MyInput {
|
|
93
|
+
query: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
interface MyOutput {
|
|
97
|
+
results: string[];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function MyApp() {
|
|
101
|
+
const {
|
|
102
|
+
status, // 'idle' | 'streaming' | 'pending' | 'ready' | 'error'
|
|
103
|
+
isReady, // true when both input and output are available
|
|
104
|
+
isStreaming, // true when receiving streaming input (MCP only)
|
|
105
|
+
input, // Tool input parameters
|
|
106
|
+
inputPartial, // Partial input during streaming
|
|
107
|
+
output, // Tool output data
|
|
108
|
+
error, // Error if isError is true
|
|
109
|
+
} = useViewData<MyInput, MyOutput>();
|
|
110
|
+
|
|
111
|
+
if (!isReady) {
|
|
112
|
+
return <div>Loading...</div>;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<div>
|
|
117
|
+
<h1>Results for: {input?.query}</h1>
|
|
118
|
+
<ul>
|
|
119
|
+
{output?.results.map((r, i) => <li key={i}>{r}</li>)}
|
|
120
|
+
</ul>
|
|
121
|
+
<button onClick={() => say('Thanks for the results!')}>
|
|
122
|
+
Send Feedback
|
|
123
|
+
</button>
|
|
124
|
+
</div>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Semantic Actions
|
|
130
|
+
|
|
131
|
+
```tsx
|
|
132
|
+
import { say, navigateToView } from '@pancake-apps/web';
|
|
133
|
+
|
|
134
|
+
// Send a message to the conversation
|
|
135
|
+
say('Task completed successfully!');
|
|
136
|
+
|
|
137
|
+
// Navigate to another view/tool
|
|
138
|
+
await navigateToView('settings');
|
|
139
|
+
await navigateToView('user-profile', { userId: '123' });
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### PancakeProvider
|
|
143
|
+
|
|
144
|
+
Wrap your app with `PancakeProvider` for proper MCP initialization:
|
|
145
|
+
|
|
146
|
+
```tsx
|
|
147
|
+
import { PancakeProvider, usePancakeContext } from '@pancake-apps/web';
|
|
148
|
+
|
|
149
|
+
function App() {
|
|
150
|
+
return (
|
|
151
|
+
<PancakeProvider
|
|
152
|
+
onError={(e) => console.error('Init failed:', e)}
|
|
153
|
+
fallback={<LoadingSpinner />}
|
|
154
|
+
>
|
|
155
|
+
<MyPancakeApp />
|
|
156
|
+
</PancakeProvider>
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function MyPancakeApp() {
|
|
161
|
+
const { isReady, platform, error } = usePancakeContext();
|
|
162
|
+
|
|
163
|
+
if (error) return <ErrorDisplay error={error} />;
|
|
164
|
+
if (!isReady) return <Loading />;
|
|
165
|
+
|
|
166
|
+
return <Content platform={platform} />;
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**Provider Props:**
|
|
171
|
+
|
|
172
|
+
| Prop | Type | Description |
|
|
173
|
+
|------|------|-------------|
|
|
174
|
+
| `children` | `ReactNode` | App content |
|
|
175
|
+
| `onError` | `(error: Error) => void` | Error callback |
|
|
176
|
+
| `fallback` | `ReactNode` | Loading component (MCP only) |
|
|
177
|
+
| `immediate` | `boolean` | Render before init completes |
|
|
178
|
+
| `debug` | `boolean` | Enable debug logging |
|
|
179
|
+
|
|
180
|
+
## API Reference
|
|
181
|
+
|
|
182
|
+
### Hooks
|
|
183
|
+
|
|
184
|
+
#### Simple Hooks (State)
|
|
185
|
+
|
|
186
|
+
| Hook | Return Type | Description |
|
|
187
|
+
|------|-------------|-------------|
|
|
188
|
+
| `useTheme()` | `'light' \| 'dark'` | Current color theme |
|
|
189
|
+
| `useLocale()` | `string` | Locale string (e.g., `'en-US'`) |
|
|
190
|
+
| `useDisplayMode()` | `DisplayMode` | Current display mode |
|
|
191
|
+
| `usePlatform()` | `Platform` | Current platform identifier |
|
|
192
|
+
| `useDeviceType()` | `DeviceType` | Device type (mobile/tablet/desktop) |
|
|
193
|
+
| `useSafeArea()` | `SafeAreaInsets` | Safe area insets for notched devices |
|
|
194
|
+
| `useMaxHeight()` | `number` | Maximum height constraint |
|
|
195
|
+
| `useContainerSize()` | `ContainerSize` | Container dimensions |
|
|
196
|
+
| `useInputCapabilities()` | `InputCapabilities` | Input device capabilities |
|
|
197
|
+
| `useToolInput<T>()` | `T \| undefined` | Tool input parameters |
|
|
198
|
+
| `useToolOutput<T>()` | `T \| undefined` | Tool output data |
|
|
199
|
+
| `useToolResponseMetadata()` | `ToolResponseMetadata \| undefined` | Tool response metadata |
|
|
200
|
+
|
|
201
|
+
#### Rich Hooks (State + Actions)
|
|
202
|
+
|
|
203
|
+
| Hook | Description |
|
|
204
|
+
|------|-------------|
|
|
205
|
+
| `useCallTool(toolName, options?)` | Call tools with loading/error state management |
|
|
206
|
+
| `useViewParams<T>()` | Parse URL search parameters |
|
|
207
|
+
| `useViewState<T>(initial)` | Manage view state with reset and dirty tracking |
|
|
208
|
+
|
|
209
|
+
#### Convenience Hooks
|
|
210
|
+
|
|
211
|
+
| Hook | Description |
|
|
212
|
+
|------|-------------|
|
|
213
|
+
| `useHostEnvironment()` | Get all environment info in one object |
|
|
214
|
+
| `useDisplayModeControl()` | Control display mode with helper methods |
|
|
215
|
+
|
|
216
|
+
### Actions
|
|
217
|
+
|
|
218
|
+
| Function | Description |
|
|
219
|
+
|----------|-------------|
|
|
220
|
+
| `callTool(name, args)` | Call a tool |
|
|
221
|
+
| `sendFollowUpMessage(message)` | Send a message to the conversation |
|
|
222
|
+
| `openExternal(url)` | Open an external URL |
|
|
223
|
+
| `requestDisplayMode(mode)` | Request a display mode change |
|
|
224
|
+
| `isSupported(feature)` | Check if a feature is supported |
|
|
225
|
+
|
|
226
|
+
### Types
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
type Theme = 'light' | 'dark';
|
|
230
|
+
type DisplayMode = 'inline' | 'pip' | 'fullscreen';
|
|
231
|
+
type Platform = 'ios' | 'android' | 'macos' | 'windows' | 'web';
|
|
232
|
+
type DeviceType = 'mobile' | 'tablet' | 'desktop';
|
|
233
|
+
|
|
234
|
+
interface SafeAreaInsets {
|
|
235
|
+
top: number;
|
|
236
|
+
right: number;
|
|
237
|
+
bottom: number;
|
|
238
|
+
left: number;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
interface ContainerSize {
|
|
242
|
+
width: number;
|
|
243
|
+
height: number;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
interface InputCapabilities {
|
|
247
|
+
canHover: boolean;
|
|
248
|
+
hasCoarsePointer: boolean;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
interface CallToolResult<T = unknown> {
|
|
252
|
+
content: ContentBlock[];
|
|
253
|
+
structuredContent?: T;
|
|
254
|
+
isError?: boolean;
|
|
255
|
+
_meta?: Record<string, unknown>;
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Feature Detection
|
|
260
|
+
|
|
261
|
+
Check if specific features are supported on the current platform:
|
|
262
|
+
|
|
263
|
+
```tsx
|
|
264
|
+
import { isSupported } from '@pancake-apps/web';
|
|
265
|
+
|
|
266
|
+
if (isSupported('uploadFile')) {
|
|
267
|
+
// Apps SDK only feature
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (isSupported('readResource')) {
|
|
271
|
+
// MCP Apps only feature
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## Global Object
|
|
276
|
+
|
|
277
|
+
For imperative access outside React, use the actions directly:
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
import { callTool, sendFollowUpMessage, openExternal } from '@pancake-apps/web';
|
|
281
|
+
|
|
282
|
+
// Call a tool
|
|
283
|
+
const result = await callTool('my-tool', { param: 'value' });
|
|
284
|
+
|
|
285
|
+
// Send a message
|
|
286
|
+
sendFollowUpMessage('Here is the result...');
|
|
287
|
+
|
|
288
|
+
// Open external URL
|
|
289
|
+
openExternal('https://example.com');
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Platform Differences
|
|
293
|
+
|
|
294
|
+
| Feature | Apps SDK | MCP Apps |
|
|
295
|
+
|---------|----------|----------|
|
|
296
|
+
| `uploadFile` | ✅ | ❌ |
|
|
297
|
+
| `getFileDownloadUrl` | ✅ | ❌ |
|
|
298
|
+
| `requestModal` | ✅ | ❌ |
|
|
299
|
+
| `readResource` | ❌ | ✅ |
|
|
300
|
+
| `updateModelContext` | ❌ | ✅ |
|
|
301
|
+
| `logging` | ❌ | ✅ |
|
|
302
|
+
| `callTool` | ✅ | ✅ |
|
|
303
|
+
| `sendMessage` | ✅ | ✅ |
|
|
304
|
+
| `openLink` | ✅ | ✅ |
|
|
305
|
+
|
|
306
|
+
## Development
|
|
307
|
+
|
|
308
|
+
```bash
|
|
309
|
+
# Install dependencies
|
|
310
|
+
npm install
|
|
311
|
+
|
|
312
|
+
# Run development build with watch
|
|
313
|
+
npm run dev
|
|
314
|
+
|
|
315
|
+
# Run tests
|
|
316
|
+
npm test
|
|
317
|
+
|
|
318
|
+
# Run tests once
|
|
319
|
+
npm run test:run
|
|
320
|
+
|
|
321
|
+
# Type check
|
|
322
|
+
npm run typecheck
|
|
323
|
+
|
|
324
|
+
# Lint
|
|
325
|
+
npm run lint
|
|
326
|
+
|
|
327
|
+
# Build for production
|
|
328
|
+
npm run build
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
## License
|
|
332
|
+
|
|
333
|
+
MIT
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified Pancake SDK Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* These types normalize across both ChatGPT Apps SDK and MCP Apps platforms.
|
|
5
|
+
*/
|
|
6
|
+
type Theme = 'light' | 'dark';
|
|
7
|
+
type DisplayMode = 'inline' | 'pip' | 'fullscreen';
|
|
8
|
+
/**
|
|
9
|
+
* Normalized platform types
|
|
10
|
+
* - Apps SDK: No platform info, defaults to 'web'
|
|
11
|
+
* - MCP Apps: 'web' | 'desktop' | 'mobile' mapped to our types
|
|
12
|
+
*/
|
|
13
|
+
type Platform = 'ios' | 'android' | 'macos' | 'windows' | 'web';
|
|
14
|
+
type DeviceType = 'mobile' | 'tablet' | 'desktop';
|
|
15
|
+
interface SafeAreaInsets {
|
|
16
|
+
top: number;
|
|
17
|
+
right: number;
|
|
18
|
+
bottom: number;
|
|
19
|
+
left: number;
|
|
20
|
+
}
|
|
21
|
+
interface ContainerSize {
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
}
|
|
25
|
+
interface InputCapabilities {
|
|
26
|
+
canHover: boolean;
|
|
27
|
+
hasCoarsePointer: boolean;
|
|
28
|
+
}
|
|
29
|
+
interface ContentBlock {
|
|
30
|
+
type: string;
|
|
31
|
+
text?: string;
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
}
|
|
34
|
+
interface CallToolResult<TOutput = unknown> {
|
|
35
|
+
content: ContentBlock[];
|
|
36
|
+
structuredContent?: TOutput;
|
|
37
|
+
isError?: boolean;
|
|
38
|
+
_meta?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Status for view parameter loading
|
|
42
|
+
*/
|
|
43
|
+
type ViewParamsStatus = 'idle' | 'pending' | 'success';
|
|
44
|
+
interface UseViewParamsResult<TInput, TOutput, TMeta> {
|
|
45
|
+
status: ViewParamsStatus;
|
|
46
|
+
isIdle: boolean;
|
|
47
|
+
isPending: boolean;
|
|
48
|
+
isSuccess: boolean;
|
|
49
|
+
input: TInput | undefined;
|
|
50
|
+
output: TOutput | undefined;
|
|
51
|
+
metadata: TMeta | undefined;
|
|
52
|
+
}
|
|
53
|
+
type CallToolStatus = 'idle' | 'pending' | 'success' | 'error';
|
|
54
|
+
interface UseCallToolCallbacks<TOutput> {
|
|
55
|
+
onSuccess?: (data: CallToolResult<TOutput>) => void;
|
|
56
|
+
onError?: (error: Error) => void;
|
|
57
|
+
onSettled?: () => void;
|
|
58
|
+
}
|
|
59
|
+
interface UseCallToolResult<TInput, TOutput> {
|
|
60
|
+
status: CallToolStatus;
|
|
61
|
+
isIdle: boolean;
|
|
62
|
+
isPending: boolean;
|
|
63
|
+
isSuccess: boolean;
|
|
64
|
+
isError: boolean;
|
|
65
|
+
data: CallToolResult<TOutput> | undefined;
|
|
66
|
+
error: Error | undefined;
|
|
67
|
+
callTool: (args?: TInput, callbacks?: UseCallToolCallbacks<TOutput>) => void;
|
|
68
|
+
callToolAsync: (args?: TInput) => Promise<CallToolResult<TOutput>>;
|
|
69
|
+
reset: () => void;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Features that may or may not be supported depending on platform
|
|
73
|
+
*/
|
|
74
|
+
type Feature = 'uploadFile' | 'getFileDownloadUrl' | 'requestModal' | 'requestClose' | 'setOpenInAppUrl' | 'notifyIntrinsicHeight' | 'readResource' | 'updateModelContext' | 'timezone' | 'cssVariables' | 'toolInfo' | 'logging' | 'ping' | 'onTeardown' | 'callTool' | 'sendMessage' | 'openLink' | 'requestDisplayMode' | 'sizeReporting';
|
|
75
|
+
type LogLevel = 'debug' | 'info' | 'warning' | 'error';
|
|
76
|
+
interface ResourceContent {
|
|
77
|
+
uri: string;
|
|
78
|
+
mimeType: string;
|
|
79
|
+
text?: string;
|
|
80
|
+
blob?: string;
|
|
81
|
+
_meta?: Record<string, unknown>;
|
|
82
|
+
}
|
|
83
|
+
interface ResourceReadResult {
|
|
84
|
+
contents: ResourceContent[];
|
|
85
|
+
}
|
|
86
|
+
interface UpdateModelContextParams {
|
|
87
|
+
content?: ContentBlock[];
|
|
88
|
+
structuredContent?: Record<string, unknown>;
|
|
89
|
+
}
|
|
90
|
+
interface ResourceTeardownParams {
|
|
91
|
+
reason: string;
|
|
92
|
+
}
|
|
93
|
+
type TeardownHandler = (params: ResourceTeardownParams) => Promise<void> | void;
|
|
94
|
+
interface AdaptorStoreState {
|
|
95
|
+
theme: Theme;
|
|
96
|
+
locale: string;
|
|
97
|
+
displayMode: DisplayMode;
|
|
98
|
+
maxHeight: number;
|
|
99
|
+
safeArea: SafeAreaInsets;
|
|
100
|
+
containerSize: ContainerSize;
|
|
101
|
+
containerWidth: number;
|
|
102
|
+
containerHeight: number;
|
|
103
|
+
platform: Platform;
|
|
104
|
+
deviceType: DeviceType;
|
|
105
|
+
canHover: boolean;
|
|
106
|
+
hasCoarsePointer: boolean;
|
|
107
|
+
inputCapabilities: InputCapabilities;
|
|
108
|
+
toolInput: unknown;
|
|
109
|
+
toolInputPartial: unknown;
|
|
110
|
+
toolOutput: unknown;
|
|
111
|
+
toolResponseMetadata: unknown;
|
|
112
|
+
viewState: unknown;
|
|
113
|
+
}
|
|
114
|
+
interface ExternalStore<T> {
|
|
115
|
+
subscribe: (callback: () => void) => () => void;
|
|
116
|
+
getSnapshot: () => T;
|
|
117
|
+
getServerSnapshot: () => T | undefined;
|
|
118
|
+
}
|
|
119
|
+
interface ToolResponseMetadata {
|
|
120
|
+
toolName?: string;
|
|
121
|
+
timestamp?: number;
|
|
122
|
+
[key: string]: unknown;
|
|
123
|
+
}
|
|
124
|
+
type AdaptorStoreKey = keyof AdaptorStoreState;
|
|
125
|
+
/**
|
|
126
|
+
* Status for view data loading in the semantic API
|
|
127
|
+
*/
|
|
128
|
+
type ViewDataStatus = 'idle' | 'streaming' | 'pending' | 'ready' | 'error';
|
|
129
|
+
/**
|
|
130
|
+
* Result type for the useViewData semantic hook
|
|
131
|
+
*/
|
|
132
|
+
interface UseViewDataResult<TInput, TOutput, TMeta> {
|
|
133
|
+
/** Current status of the view data */
|
|
134
|
+
status: ViewDataStatus;
|
|
135
|
+
/** True when no input has been received yet */
|
|
136
|
+
isIdle: boolean;
|
|
137
|
+
/** True when input received but no output yet */
|
|
138
|
+
isPending: boolean;
|
|
139
|
+
/** True when receiving streaming input (MCP Apps only) */
|
|
140
|
+
isStreaming: boolean;
|
|
141
|
+
/** True when both input and output are available */
|
|
142
|
+
isReady: boolean;
|
|
143
|
+
/** True when an error occurred */
|
|
144
|
+
isError: boolean;
|
|
145
|
+
/** The complete tool input */
|
|
146
|
+
input: TInput | undefined;
|
|
147
|
+
/** Partial input during streaming (MCP Apps only) */
|
|
148
|
+
inputPartial: Partial<TInput> | undefined;
|
|
149
|
+
/** The tool output */
|
|
150
|
+
output: TOutput | undefined;
|
|
151
|
+
/** Tool response metadata */
|
|
152
|
+
metadata: TMeta | undefined;
|
|
153
|
+
/** Error if isError is true */
|
|
154
|
+
error: Error | undefined;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Status for action execution
|
|
158
|
+
*/
|
|
159
|
+
type ActionStatus = 'idle' | 'pending' | 'success' | 'error';
|
|
160
|
+
/**
|
|
161
|
+
* Status for data queries (extends ActionStatus with stale state)
|
|
162
|
+
*/
|
|
163
|
+
type DataStatus = 'idle' | 'pending' | 'success' | 'error' | 'stale';
|
|
164
|
+
/**
|
|
165
|
+
* Marker type for action tools (side-effect, fire-and-forget)
|
|
166
|
+
* Use for: save, delete, update, navigate, send, submit
|
|
167
|
+
*/
|
|
168
|
+
type ActionTool<TInput = void> = {
|
|
169
|
+
readonly _brand: 'ActionTool';
|
|
170
|
+
readonly _input: TInput;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Marker type for data tools (read-only queries)
|
|
174
|
+
* Use for: search, get, list, fetch
|
|
175
|
+
*/
|
|
176
|
+
type DataTool<TInput = void, TOutput = unknown> = {
|
|
177
|
+
readonly _brand: 'DataTool';
|
|
178
|
+
readonly _input: TInput;
|
|
179
|
+
readonly _output: TOutput;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Callbacks for useAction hook
|
|
183
|
+
*/
|
|
184
|
+
interface UseActionCallbacks {
|
|
185
|
+
onSuccess?: () => void;
|
|
186
|
+
onError?: (error: Error) => void;
|
|
187
|
+
onSettled?: () => void;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Result type for useAction hook
|
|
191
|
+
*/
|
|
192
|
+
interface UseActionResult<TInput> {
|
|
193
|
+
/** Current status of the action */
|
|
194
|
+
status: ActionStatus;
|
|
195
|
+
/** True when action has not been executed yet */
|
|
196
|
+
isIdle: boolean;
|
|
197
|
+
/** True when action is executing */
|
|
198
|
+
isPending: boolean;
|
|
199
|
+
/** True when action completed successfully */
|
|
200
|
+
isSuccess: boolean;
|
|
201
|
+
/** True when action failed */
|
|
202
|
+
isError: boolean;
|
|
203
|
+
/** Error if isError is true */
|
|
204
|
+
error: Error | undefined;
|
|
205
|
+
/** Execute the action (fire-and-forget with callbacks) */
|
|
206
|
+
execute: (input?: TInput, callbacks?: UseActionCallbacks) => void;
|
|
207
|
+
/** Execute the action (promise-based) */
|
|
208
|
+
executeAsync: (input?: TInput) => Promise<void>;
|
|
209
|
+
/** Reset state back to idle */
|
|
210
|
+
reset: () => void;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Options for useData hook
|
|
214
|
+
*/
|
|
215
|
+
interface UseDataOptions<TOutput> {
|
|
216
|
+
/** Initial data to use before first fetch */
|
|
217
|
+
initialData?: TOutput;
|
|
218
|
+
/** Time in ms before data is considered stale (default: 0 = immediately stale) */
|
|
219
|
+
staleTime?: number;
|
|
220
|
+
/** Time in ms to keep data in cache (default: 5 minutes) */
|
|
221
|
+
cacheTime?: number;
|
|
222
|
+
/** Refetch when window regains focus */
|
|
223
|
+
refetchOnWindowFocus?: boolean;
|
|
224
|
+
/** Refetch on interval (ms) */
|
|
225
|
+
refetchInterval?: number;
|
|
226
|
+
/** Callback on successful fetch */
|
|
227
|
+
onSuccess?: (data: TOutput) => void;
|
|
228
|
+
/** Callback on fetch error */
|
|
229
|
+
onError?: (error: Error) => void;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Result type for useData hook
|
|
233
|
+
*/
|
|
234
|
+
interface UseDataResult<TInput, TOutput> {
|
|
235
|
+
/** Current status of the data */
|
|
236
|
+
status: DataStatus;
|
|
237
|
+
/** True when no data has been fetched yet */
|
|
238
|
+
isIdle: boolean;
|
|
239
|
+
/** True when data is being fetched for the first time */
|
|
240
|
+
isPending: boolean;
|
|
241
|
+
/** True when data is available */
|
|
242
|
+
isSuccess: boolean;
|
|
243
|
+
/** True when fetch failed */
|
|
244
|
+
isError: boolean;
|
|
245
|
+
/** True when data exists but is stale */
|
|
246
|
+
isStale: boolean;
|
|
247
|
+
/** True when a fetch is in progress (including background refetch) */
|
|
248
|
+
isFetching: boolean;
|
|
249
|
+
/** The fetched data */
|
|
250
|
+
data: TOutput | undefined;
|
|
251
|
+
/** Error if isError is true */
|
|
252
|
+
error: Error | undefined;
|
|
253
|
+
/** Fetch data (fire-and-forget) */
|
|
254
|
+
fetch: (input?: TInput) => void;
|
|
255
|
+
/** Fetch data (promise-based) */
|
|
256
|
+
fetchAsync: (input?: TInput) => Promise<TOutput>;
|
|
257
|
+
/** Refetch using the last input */
|
|
258
|
+
refetch: () => void;
|
|
259
|
+
/** Invalidate the cache (marks data as stale) */
|
|
260
|
+
invalidate: () => void;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Platform Detection
|
|
265
|
+
*
|
|
266
|
+
* Detects which host environment is available.
|
|
267
|
+
*/
|
|
268
|
+
type HostPlatform = 'apps-sdk' | 'mcp-apps';
|
|
269
|
+
declare global {
|
|
270
|
+
interface Window {
|
|
271
|
+
__PANCAKE_FORCE_MCP__?: boolean;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Check if ChatGPT Apps SDK (window.openai) is available
|
|
276
|
+
*/
|
|
277
|
+
declare function isAppsSdkAvailable(): boolean;
|
|
278
|
+
/**
|
|
279
|
+
* Check if MCP Apps environment is likely available
|
|
280
|
+
*
|
|
281
|
+
* MCP Apps uses postMessage, so we check for iframe context
|
|
282
|
+
*/
|
|
283
|
+
declare function isMcpAppsAvailable(): boolean;
|
|
284
|
+
declare function getPlatform(): HostPlatform;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Unified Adaptor Interface
|
|
288
|
+
*
|
|
289
|
+
* Defines the contract that both platform adaptors must implement.
|
|
290
|
+
*/
|
|
291
|
+
|
|
292
|
+
interface UnifiedAdaptor {
|
|
293
|
+
/**
|
|
294
|
+
* Platform identifier
|
|
295
|
+
*/
|
|
296
|
+
readonly platform: 'apps-sdk' | 'mcp-apps';
|
|
297
|
+
/**
|
|
298
|
+
* Get an external store for a specific state key
|
|
299
|
+
* Used with useSyncExternalStore
|
|
300
|
+
*/
|
|
301
|
+
getExternalStore<K extends AdaptorStoreKey>(key: K): ExternalStore<AdaptorStoreState[K]>;
|
|
302
|
+
getTheme(): Theme;
|
|
303
|
+
getLocale(): string;
|
|
304
|
+
getDisplayMode(): DisplayMode;
|
|
305
|
+
getMaxHeight(): number;
|
|
306
|
+
getSafeArea(): SafeAreaInsets;
|
|
307
|
+
getPlatform(): Platform;
|
|
308
|
+
getDeviceType(): DeviceType;
|
|
309
|
+
getContainerSize(): {
|
|
310
|
+
width: number;
|
|
311
|
+
height: number;
|
|
312
|
+
};
|
|
313
|
+
getInputCapabilities(): {
|
|
314
|
+
canHover: boolean;
|
|
315
|
+
hasCoarsePointer: boolean;
|
|
316
|
+
};
|
|
317
|
+
getToolInput<T>(): T | undefined;
|
|
318
|
+
getToolOutput<T>(): T | undefined;
|
|
319
|
+
getToolResponseMetadata<T>(): T | undefined;
|
|
320
|
+
getViewState<T>(): T | undefined;
|
|
321
|
+
/**
|
|
322
|
+
* Get partial tool input during streaming (MCP-specific)
|
|
323
|
+
* Used by useViewData for streaming status detection
|
|
324
|
+
*/
|
|
325
|
+
getToolInputPartial<T>(): Partial<T> | undefined;
|
|
326
|
+
callTool<TInput, TOutput>(name: string, args?: TInput): Promise<CallToolResult<TOutput>>;
|
|
327
|
+
sendFollowUpMessage(message: string): void;
|
|
328
|
+
openExternal(url: string): void;
|
|
329
|
+
requestDisplayMode(mode: DisplayMode): void;
|
|
330
|
+
setViewState<T>(state: T): void;
|
|
331
|
+
isSupported(feature: Feature): boolean;
|
|
332
|
+
/**
|
|
333
|
+
* Read a resource by URI (MCP-specific, throws on Apps SDK)
|
|
334
|
+
*/
|
|
335
|
+
readResource(uri: string): Promise<ResourceReadResult>;
|
|
336
|
+
/**
|
|
337
|
+
* Update the model context (MCP-specific, no-op on Apps SDK)
|
|
338
|
+
*/
|
|
339
|
+
updateModelContext(params: UpdateModelContextParams): Promise<void>;
|
|
340
|
+
/**
|
|
341
|
+
* Log a message (MCP sends to host, Apps SDK uses console)
|
|
342
|
+
*/
|
|
343
|
+
log(level: LogLevel, data: unknown, logger?: string): void;
|
|
344
|
+
/**
|
|
345
|
+
* Ping the host (MCP-specific, no-op on Apps SDK)
|
|
346
|
+
*/
|
|
347
|
+
ping(): Promise<void>;
|
|
348
|
+
/**
|
|
349
|
+
* Register a teardown handler (MCP-specific, no-op on Apps SDK)
|
|
350
|
+
*/
|
|
351
|
+
onTeardown(handler: TeardownHandler): () => void;
|
|
352
|
+
/**
|
|
353
|
+
* Notify the host of size changes (MCP sends notification, Apps SDK uses notifyIntrinsicHeight)
|
|
354
|
+
*/
|
|
355
|
+
notifySizeChanged(width: number, height: number): void;
|
|
356
|
+
/**
|
|
357
|
+
* Setup automatic size reporting via ResizeObserver
|
|
358
|
+
*/
|
|
359
|
+
setupAutoSizeReporting(element: HTMLElement): () => void;
|
|
360
|
+
/**
|
|
361
|
+
* Initialize the adaptor (MCP Apps requires explicit init)
|
|
362
|
+
*/
|
|
363
|
+
initialize?(): Promise<void>;
|
|
364
|
+
/**
|
|
365
|
+
* Ensure initialized before operations
|
|
366
|
+
*/
|
|
367
|
+
ensureReady(): Promise<void>;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export { type ActionTool as A, type ContainerSize as C, type DisplayMode as D, type ExternalStore as E, type Feature as F, type HostPlatform as H, type InputCapabilities as I, type LogLevel as L, type Platform as P, type ResourceContent as R, type SafeAreaInsets as S, type Theme as T, type UpdateModelContextParams as U, type ViewDataStatus as V, type DeviceType as a, isMcpAppsAvailable as b, type CallToolResult as c, type ContentBlock as d, type ToolResponseMetadata as e, type ResourceReadResult as f, getPlatform as g, type ResourceTeardownParams as h, isAppsSdkAvailable as i, type TeardownHandler as j, type DataTool as k, type UnifiedAdaptor as l, type UseViewDataResult as m, type UseActionResult as n, type UseDataOptions as o, type UseDataResult as p, type UseCallToolResult as q, type UseCallToolCallbacks as r, type UseViewParamsResult as s, type ActionStatus as t, type AdaptorStoreKey as u, type AdaptorStoreState as v, type CallToolStatus as w, type DataStatus as x, type UseActionCallbacks as y, type ViewParamsStatus as z };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { A as AppsSdkBridge, j as AppsSdkStore, b as CallToolResult, C as ContentBlock, D as DisplayMode, M as ModalOptions, O as OpenAiGlobals, c as OpenAiMethods, d as OpenAiRuntime, g as SET_GLOBALS_EVENT_TYPE, S as SafeAreaInsets, f as SetGlobalsEvent, e as SetGlobalsEventDetail, T as Theme, y as callTool, l as createOpenAiGlobalHook, h as getBridge, E as getFileDownloadUrl, k as getStore, i as isAppsSdkAvailable, H as notifyIntrinsicHeight, J as openExternal, I as requestClose, F as requestDisplayMode, G as requestModal, z as sendFollowUpMessage, K as setOpenInAppUrl, B as uploadFile, o as useDisplayMode, n as useLocale, p as useMaxHeight, u as useOpenAiGlobal, q as useSafeArea, m as useTheme, t as useToolInput, v as useToolOutput, w as useToolResponseMetadata, s as useUserAgent, r as useView, x as useWidgetState } from '../index-BBfZZJWn.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { AppsSdkBridge, AppsSdkStore, SET_GLOBALS_EVENT_TYPE, callTool, createOpenAiGlobalHook, getBridge, getFileDownloadUrl, getStore, isAppsSdkAvailable, notifyIntrinsicHeight, openExternal, requestClose, requestDisplayMode, requestModal, sendFollowUpMessage, setOpenInAppUrl, uploadFile, useDisplayMode, useLocale, useMaxHeight, useOpenAiGlobal, useSafeArea, useTheme, useToolInput, useToolOutput, useToolResponseMetadata, useUserAgent, useView, useWidgetState } from '../chunk-5NYJ2IVD.js';
|
|
2
|
+
import '../chunk-PZ5AY32C.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
4
|
+
//# sourceMappingURL=index.js.map
|