@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/dist/index.js
ADDED
|
@@ -0,0 +1,685 @@
|
|
|
1
|
+
import { updateModelContext, setupAutoSizeReporting, sendFollowUpMessage, say, requestDisplayMode, readResource, ping, openExternal, onTeardown, notifySizeChanged, navigateToView, logWarning, logInfo, logError, logDebug, log, isSupported, data, callTool, action } from './chunk-7HJ5PKKT.js';
|
|
2
|
+
export { action, callTool, data, isSupported, log, logDebug, logError, logInfo, logWarning, navigateToView, notifySizeChanged, onTeardown, openExternal, ping, readResource, requestDisplayMode, say, sendFollowUpMessage, setupAutoSizeReporting, updateModelContext } from './chunk-7HJ5PKKT.js';
|
|
3
|
+
import { useView, useSystemColorScheme, useHostVariables, useHostTheme, useHostStyles, useHostFontsHook, useDocumentThemeState, useDocumentTheme, observeDocumentTheme, getSafeAreaInsets, getDocumentTheme, getComputedStyleVariables, createView, clearHostStyles, applySafeAreaInsets, applyHostStyleVariables, applyHostFonts, applyHostContext, applyDocumentTheme, View } from './chunk-TLBYYZHP.js';
|
|
4
|
+
export { View, applyDocumentTheme, applyHostContext, applyHostFonts, applyHostStyleVariables, applySafeAreaInsets, clearHostStyles, createView, getComputedStyleVariables, getDocumentTheme, getSafeAreaInsets, observeDocumentTheme, useDocumentTheme, useDocumentThemeState, useHostFontsHook, useHostStyles, useHostTheme, useHostVariables, useSystemColorScheme, useView } from './chunk-TLBYYZHP.js';
|
|
5
|
+
import { resetAdaptor, isMcpAppsAvailable, isAppsSdkAvailable, getPlatform, getAdaptor, SSR_DEFAULTS } from './chunk-ZYBPDIEG.js';
|
|
6
|
+
export { getAdaptor, getPlatform, isAppsSdkAvailable, isMcpAppsAvailable, resetAdaptor } from './chunk-ZYBPDIEG.js';
|
|
7
|
+
import { apps_sdk_exports } from './chunk-5NYJ2IVD.js';
|
|
8
|
+
export { apps_sdk_exports as appsSdk } from './chunk-5NYJ2IVD.js';
|
|
9
|
+
import { mcp_apps_exports } from './chunk-YGGRUIUG.js';
|
|
10
|
+
export { mcp_apps_exports as mcpApps } from './chunk-YGGRUIUG.js';
|
|
11
|
+
import { __export } from './chunk-PZ5AY32C.js';
|
|
12
|
+
import { useSyncExternalStore, useState, useCallback, useRef, useEffect, useMemo, createContext, useContext } from 'react';
|
|
13
|
+
import { jsx } from 'react/jsx-runtime';
|
|
14
|
+
|
|
15
|
+
// src/unified/index.ts
|
|
16
|
+
var unified_exports = {};
|
|
17
|
+
__export(unified_exports, {
|
|
18
|
+
DEBUG: () => DEBUG,
|
|
19
|
+
IS_STORYBOOK: () => IS_STORYBOOK,
|
|
20
|
+
IS_TEST: () => IS_TEST,
|
|
21
|
+
PancakeProvider: () => PancakeProvider,
|
|
22
|
+
View: () => View,
|
|
23
|
+
action: () => action,
|
|
24
|
+
applyDocumentTheme: () => applyDocumentTheme,
|
|
25
|
+
applyHostContext: () => applyHostContext,
|
|
26
|
+
applyHostFonts: () => applyHostFonts,
|
|
27
|
+
applyHostStyleVariables: () => applyHostStyleVariables,
|
|
28
|
+
applySafeAreaInsets: () => applySafeAreaInsets,
|
|
29
|
+
callTool: () => callTool,
|
|
30
|
+
clearHostStyles: () => clearHostStyles,
|
|
31
|
+
createView: () => createView,
|
|
32
|
+
data: () => data,
|
|
33
|
+
debugAssert: () => debugAssert,
|
|
34
|
+
debugLog: () => debugLog,
|
|
35
|
+
debugTime: () => debugTime,
|
|
36
|
+
debugTimeAsync: () => debugTimeAsync,
|
|
37
|
+
debugWarn: () => debugWarn,
|
|
38
|
+
getAdaptor: () => getAdaptor,
|
|
39
|
+
getComputedStyleVariables: () => getComputedStyleVariables,
|
|
40
|
+
getDocumentTheme: () => getDocumentTheme,
|
|
41
|
+
getPlatform: () => getPlatform,
|
|
42
|
+
getSafeAreaInsets: () => getSafeAreaInsets,
|
|
43
|
+
isAppsSdkAvailable: () => isAppsSdkAvailable,
|
|
44
|
+
isMcpAppsAvailable: () => isMcpAppsAvailable,
|
|
45
|
+
isSupported: () => isSupported,
|
|
46
|
+
log: () => log,
|
|
47
|
+
logDebug: () => logDebug,
|
|
48
|
+
logError: () => logError,
|
|
49
|
+
logInfo: () => logInfo,
|
|
50
|
+
logWarning: () => logWarning,
|
|
51
|
+
navigateToView: () => navigateToView,
|
|
52
|
+
notifySizeChanged: () => notifySizeChanged,
|
|
53
|
+
observeDocumentTheme: () => observeDocumentTheme,
|
|
54
|
+
onTeardown: () => onTeardown,
|
|
55
|
+
openExternal: () => openExternal,
|
|
56
|
+
ping: () => ping,
|
|
57
|
+
readResource: () => readResource,
|
|
58
|
+
requestDisplayMode: () => requestDisplayMode,
|
|
59
|
+
resetAdaptor: () => resetAdaptor,
|
|
60
|
+
say: () => say,
|
|
61
|
+
sendFollowUpMessage: () => sendFollowUpMessage,
|
|
62
|
+
setupAutoSizeReporting: () => setupAutoSizeReporting,
|
|
63
|
+
updateModelContext: () => updateModelContext,
|
|
64
|
+
useAction: () => useAction,
|
|
65
|
+
useCallTool: () => useCallTool,
|
|
66
|
+
useContainerSize: () => useContainerSize,
|
|
67
|
+
useData: () => useData,
|
|
68
|
+
useDeviceType: () => useDeviceType,
|
|
69
|
+
useDisplayMode: () => useDisplayMode,
|
|
70
|
+
useDisplayModeControl: () => useDisplayModeControl,
|
|
71
|
+
useDocumentTheme: () => useDocumentTheme,
|
|
72
|
+
useDocumentThemeState: () => useDocumentThemeState,
|
|
73
|
+
useHostEnvironment: () => useHostEnvironment,
|
|
74
|
+
useHostFontsHook: () => useHostFontsHook,
|
|
75
|
+
useHostStyles: () => useHostStyles,
|
|
76
|
+
useHostTheme: () => useHostTheme,
|
|
77
|
+
useHostVariables: () => useHostVariables,
|
|
78
|
+
useInputCapabilities: () => useInputCapabilities,
|
|
79
|
+
useIsDarkMode: () => useIsDarkMode,
|
|
80
|
+
useIsFullscreen: () => useIsFullscreen,
|
|
81
|
+
useIsMobile: () => useIsMobile,
|
|
82
|
+
useLocale: () => useLocale,
|
|
83
|
+
useMaxHeight: () => useMaxHeight,
|
|
84
|
+
usePancakeContext: () => usePancakeContext,
|
|
85
|
+
usePlatform: () => usePlatform,
|
|
86
|
+
useSafeArea: () => useSafeArea,
|
|
87
|
+
useSystemColorScheme: () => useSystemColorScheme,
|
|
88
|
+
useTheme: () => useTheme,
|
|
89
|
+
useToolInput: () => useToolInput,
|
|
90
|
+
useToolOutput: () => useToolOutput,
|
|
91
|
+
useToolResponseMetadata: () => useToolResponseMetadata,
|
|
92
|
+
useView: () => useView,
|
|
93
|
+
useViewData: () => useViewData,
|
|
94
|
+
useViewParams: () => useViewParams,
|
|
95
|
+
useViewState: () => useViewState
|
|
96
|
+
});
|
|
97
|
+
function useToolInput() {
|
|
98
|
+
const adaptor = getAdaptor();
|
|
99
|
+
const store = adaptor.getExternalStore("toolInput");
|
|
100
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot);
|
|
101
|
+
}
|
|
102
|
+
function useToolInputPartial() {
|
|
103
|
+
const adaptor = getAdaptor();
|
|
104
|
+
const store = adaptor.getExternalStore("toolInputPartial");
|
|
105
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot);
|
|
106
|
+
}
|
|
107
|
+
function useToolOutput() {
|
|
108
|
+
const adaptor = getAdaptor();
|
|
109
|
+
const store = adaptor.getExternalStore("toolOutput");
|
|
110
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot);
|
|
111
|
+
}
|
|
112
|
+
function useToolResponseMetadata() {
|
|
113
|
+
const adaptor = getAdaptor();
|
|
114
|
+
const store = adaptor.getExternalStore("toolResponseMetadata");
|
|
115
|
+
return useSyncExternalStore(
|
|
116
|
+
store.subscribe,
|
|
117
|
+
store.getSnapshot,
|
|
118
|
+
store.getServerSnapshot
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/unified/hooks/semantic/use-view-data.ts
|
|
123
|
+
function useViewData() {
|
|
124
|
+
const input = useToolInput();
|
|
125
|
+
const output = useToolOutput();
|
|
126
|
+
const metadata = useToolResponseMetadata();
|
|
127
|
+
const inputPartial = useToolInputPartial();
|
|
128
|
+
let status;
|
|
129
|
+
let error;
|
|
130
|
+
if (!input && !inputPartial) {
|
|
131
|
+
status = "idle";
|
|
132
|
+
} else if (inputPartial && !input) {
|
|
133
|
+
status = "streaming";
|
|
134
|
+
} else if (input && !output) {
|
|
135
|
+
status = "pending";
|
|
136
|
+
} else if (output) {
|
|
137
|
+
status = "ready";
|
|
138
|
+
} else {
|
|
139
|
+
status = "idle";
|
|
140
|
+
}
|
|
141
|
+
if (metadata && metadata.isError) {
|
|
142
|
+
status = "error";
|
|
143
|
+
error = new Error(
|
|
144
|
+
metadata.errorMessage ?? "Unknown error"
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
status,
|
|
149
|
+
isIdle: status === "idle",
|
|
150
|
+
isPending: status === "pending",
|
|
151
|
+
isStreaming: status === "streaming",
|
|
152
|
+
isReady: status === "ready",
|
|
153
|
+
isError: status === "error",
|
|
154
|
+
input,
|
|
155
|
+
inputPartial,
|
|
156
|
+
output,
|
|
157
|
+
metadata,
|
|
158
|
+
error
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function useAction(toolName) {
|
|
162
|
+
const [status, setStatus] = useState("idle");
|
|
163
|
+
const [error, setError] = useState(void 0);
|
|
164
|
+
const executeAsync = useCallback(
|
|
165
|
+
async (input) => {
|
|
166
|
+
setStatus("pending");
|
|
167
|
+
setError(void 0);
|
|
168
|
+
try {
|
|
169
|
+
await action(toolName, input);
|
|
170
|
+
setStatus("success");
|
|
171
|
+
} catch (err) {
|
|
172
|
+
const errorObj = err instanceof Error ? err : new Error(String(err));
|
|
173
|
+
setError(errorObj);
|
|
174
|
+
setStatus("error");
|
|
175
|
+
throw errorObj;
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
[toolName]
|
|
179
|
+
);
|
|
180
|
+
const execute = useCallback(
|
|
181
|
+
(input, callbacks) => {
|
|
182
|
+
executeAsync(input).then(() => {
|
|
183
|
+
callbacks?.onSuccess?.();
|
|
184
|
+
callbacks?.onSettled?.();
|
|
185
|
+
}).catch((err) => {
|
|
186
|
+
callbacks?.onError?.(err);
|
|
187
|
+
callbacks?.onSettled?.();
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
[executeAsync]
|
|
191
|
+
);
|
|
192
|
+
const reset = useCallback(() => {
|
|
193
|
+
setStatus("idle");
|
|
194
|
+
setError(void 0);
|
|
195
|
+
}, []);
|
|
196
|
+
return {
|
|
197
|
+
status,
|
|
198
|
+
isIdle: status === "idle",
|
|
199
|
+
isPending: status === "pending",
|
|
200
|
+
isSuccess: status === "success",
|
|
201
|
+
isError: status === "error",
|
|
202
|
+
error,
|
|
203
|
+
execute,
|
|
204
|
+
executeAsync,
|
|
205
|
+
reset
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
var cache = /* @__PURE__ */ new Map();
|
|
209
|
+
function getCacheKey(toolName, input) {
|
|
210
|
+
return `${toolName}:${JSON.stringify(input ?? null)}`;
|
|
211
|
+
}
|
|
212
|
+
var DEFAULT_OPTIONS = {
|
|
213
|
+
staleTime: 0,
|
|
214
|
+
cacheTime: 5 * 60 * 1e3,
|
|
215
|
+
// 5 minutes
|
|
216
|
+
refetchOnWindowFocus: false
|
|
217
|
+
};
|
|
218
|
+
function useData(toolName, defaultInput, options) {
|
|
219
|
+
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
220
|
+
const [status, setStatus] = useState("idle");
|
|
221
|
+
const [fetchedData, setFetchedData] = useState(opts.initialData);
|
|
222
|
+
const [error, setError] = useState(void 0);
|
|
223
|
+
const [isFetching, setIsFetching] = useState(false);
|
|
224
|
+
const [isStale, setIsStale] = useState(false);
|
|
225
|
+
const lastInputRef = useRef(defaultInput);
|
|
226
|
+
const refetchIntervalRef = useRef(null);
|
|
227
|
+
const checkStale = useCallback(
|
|
228
|
+
(cacheKey) => {
|
|
229
|
+
const entry = cache.get(cacheKey);
|
|
230
|
+
if (!entry) return true;
|
|
231
|
+
const age = Date.now() - entry.timestamp;
|
|
232
|
+
return age > opts.staleTime;
|
|
233
|
+
},
|
|
234
|
+
[opts.staleTime]
|
|
235
|
+
);
|
|
236
|
+
const cleanupCache = useCallback(() => {
|
|
237
|
+
const now = Date.now();
|
|
238
|
+
for (const [key, entry] of cache.entries()) {
|
|
239
|
+
if (now - entry.timestamp > opts.cacheTime) {
|
|
240
|
+
cache.delete(key);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}, [opts.cacheTime]);
|
|
244
|
+
const fetchAsync = useCallback(
|
|
245
|
+
async (input) => {
|
|
246
|
+
const actualInput = input ?? lastInputRef.current;
|
|
247
|
+
lastInputRef.current = actualInput;
|
|
248
|
+
const cacheKey = getCacheKey(toolName, actualInput);
|
|
249
|
+
const cachedEntry = cache.get(cacheKey);
|
|
250
|
+
const isCacheStale = checkStale(cacheKey);
|
|
251
|
+
if (cachedEntry && !isCacheStale) {
|
|
252
|
+
setFetchedData(cachedEntry.data);
|
|
253
|
+
setStatus("success");
|
|
254
|
+
setIsStale(false);
|
|
255
|
+
return cachedEntry.data;
|
|
256
|
+
}
|
|
257
|
+
if (cachedEntry && isCacheStale) {
|
|
258
|
+
setFetchedData(cachedEntry.data);
|
|
259
|
+
setStatus("stale");
|
|
260
|
+
setIsStale(true);
|
|
261
|
+
} else {
|
|
262
|
+
setStatus("pending");
|
|
263
|
+
}
|
|
264
|
+
setIsFetching(true);
|
|
265
|
+
setError(void 0);
|
|
266
|
+
try {
|
|
267
|
+
const result = await data(toolName, actualInput);
|
|
268
|
+
cache.set(cacheKey, {
|
|
269
|
+
data: result,
|
|
270
|
+
timestamp: Date.now(),
|
|
271
|
+
input: actualInput
|
|
272
|
+
});
|
|
273
|
+
setFetchedData(result);
|
|
274
|
+
setStatus("success");
|
|
275
|
+
setIsStale(false);
|
|
276
|
+
opts.onSuccess?.(result);
|
|
277
|
+
cleanupCache();
|
|
278
|
+
return result;
|
|
279
|
+
} catch (err) {
|
|
280
|
+
const errorObj = err instanceof Error ? err : new Error(String(err));
|
|
281
|
+
setError(errorObj);
|
|
282
|
+
setStatus("error");
|
|
283
|
+
opts.onError?.(errorObj);
|
|
284
|
+
throw errorObj;
|
|
285
|
+
} finally {
|
|
286
|
+
setIsFetching(false);
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
[toolName, checkStale, cleanupCache, opts]
|
|
290
|
+
);
|
|
291
|
+
const fetch = useCallback(
|
|
292
|
+
(input) => {
|
|
293
|
+
fetchAsync(input).catch(() => {
|
|
294
|
+
});
|
|
295
|
+
},
|
|
296
|
+
[fetchAsync]
|
|
297
|
+
);
|
|
298
|
+
const refetch = useCallback(() => {
|
|
299
|
+
fetch(lastInputRef.current);
|
|
300
|
+
}, [fetch]);
|
|
301
|
+
const invalidate = useCallback(() => {
|
|
302
|
+
const cacheKey = getCacheKey(toolName, lastInputRef.current);
|
|
303
|
+
cache.delete(cacheKey);
|
|
304
|
+
setIsStale(true);
|
|
305
|
+
setStatus((prev) => prev === "success" ? "stale" : prev);
|
|
306
|
+
}, [toolName]);
|
|
307
|
+
useEffect(() => {
|
|
308
|
+
if (!opts.refetchOnWindowFocus) return;
|
|
309
|
+
const handleFocus = () => {
|
|
310
|
+
if (fetchedData !== void 0) {
|
|
311
|
+
refetch();
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
window.addEventListener("focus", handleFocus);
|
|
315
|
+
return () => window.removeEventListener("focus", handleFocus);
|
|
316
|
+
}, [opts.refetchOnWindowFocus, fetchedData, refetch]);
|
|
317
|
+
useEffect(() => {
|
|
318
|
+
if (!opts.refetchInterval) return;
|
|
319
|
+
refetchIntervalRef.current = setInterval(() => {
|
|
320
|
+
if (fetchedData !== void 0) {
|
|
321
|
+
refetch();
|
|
322
|
+
}
|
|
323
|
+
}, opts.refetchInterval);
|
|
324
|
+
return () => {
|
|
325
|
+
if (refetchIntervalRef.current) {
|
|
326
|
+
clearInterval(refetchIntervalRef.current);
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
}, [opts.refetchInterval, fetchedData, refetch]);
|
|
330
|
+
return {
|
|
331
|
+
status,
|
|
332
|
+
isIdle: status === "idle",
|
|
333
|
+
isPending: status === "pending",
|
|
334
|
+
isSuccess: status === "success",
|
|
335
|
+
isError: status === "error",
|
|
336
|
+
isStale: status === "stale" || isStale,
|
|
337
|
+
isFetching,
|
|
338
|
+
data: fetchedData,
|
|
339
|
+
error,
|
|
340
|
+
fetch,
|
|
341
|
+
fetchAsync,
|
|
342
|
+
refetch,
|
|
343
|
+
invalidate
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
function useTheme() {
|
|
347
|
+
const adaptor = getAdaptor();
|
|
348
|
+
const store = adaptor.getExternalStore("theme");
|
|
349
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot) ?? SSR_DEFAULTS.theme;
|
|
350
|
+
}
|
|
351
|
+
function useLocale() {
|
|
352
|
+
const adaptor = getAdaptor();
|
|
353
|
+
const store = adaptor.getExternalStore("locale");
|
|
354
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot) ?? "en-US";
|
|
355
|
+
}
|
|
356
|
+
function useDeviceType() {
|
|
357
|
+
const adaptor = getAdaptor();
|
|
358
|
+
const store = adaptor.getExternalStore("deviceType");
|
|
359
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot) ?? SSR_DEFAULTS.deviceType;
|
|
360
|
+
}
|
|
361
|
+
function usePlatform() {
|
|
362
|
+
const adaptor = getAdaptor();
|
|
363
|
+
const store = adaptor.getExternalStore("platform");
|
|
364
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot) ?? SSR_DEFAULTS.platform;
|
|
365
|
+
}
|
|
366
|
+
function useSafeArea() {
|
|
367
|
+
const adaptor = getAdaptor();
|
|
368
|
+
const store = adaptor.getExternalStore("safeArea");
|
|
369
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot) ?? SSR_DEFAULTS.safeArea;
|
|
370
|
+
}
|
|
371
|
+
function useMaxHeight() {
|
|
372
|
+
const adaptor = getAdaptor();
|
|
373
|
+
const store = adaptor.getExternalStore("maxHeight");
|
|
374
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot) ?? SSR_DEFAULTS.maxHeight;
|
|
375
|
+
}
|
|
376
|
+
function useDisplayMode() {
|
|
377
|
+
const adaptor = getAdaptor();
|
|
378
|
+
const store = adaptor.getExternalStore("displayMode");
|
|
379
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot) ?? SSR_DEFAULTS.displayMode;
|
|
380
|
+
}
|
|
381
|
+
function useContainerSize() {
|
|
382
|
+
const adaptor = getAdaptor();
|
|
383
|
+
const store = adaptor.getExternalStore("containerSize");
|
|
384
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot) ?? SSR_DEFAULTS.containerSize;
|
|
385
|
+
}
|
|
386
|
+
function useInputCapabilities() {
|
|
387
|
+
const adaptor = getAdaptor();
|
|
388
|
+
const store = adaptor.getExternalStore("inputCapabilities");
|
|
389
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot) ?? SSR_DEFAULTS.inputCapabilities;
|
|
390
|
+
}
|
|
391
|
+
function useCallTool(toolName) {
|
|
392
|
+
const [status, setStatus] = useState("idle");
|
|
393
|
+
const [data2, setData] = useState(void 0);
|
|
394
|
+
const [error, setError] = useState(void 0);
|
|
395
|
+
const callToolAsync = useCallback(
|
|
396
|
+
async (args) => {
|
|
397
|
+
const adaptor = getAdaptor();
|
|
398
|
+
setStatus("pending");
|
|
399
|
+
setError(void 0);
|
|
400
|
+
try {
|
|
401
|
+
const result = await adaptor.callTool(toolName, args);
|
|
402
|
+
setData(result);
|
|
403
|
+
setStatus("success");
|
|
404
|
+
return result;
|
|
405
|
+
} catch (err) {
|
|
406
|
+
const errorObj = err instanceof Error ? err : new Error(String(err));
|
|
407
|
+
setError(errorObj);
|
|
408
|
+
setStatus("error");
|
|
409
|
+
throw errorObj;
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
[toolName]
|
|
413
|
+
);
|
|
414
|
+
const callTool2 = useCallback(
|
|
415
|
+
(args, callbacks) => {
|
|
416
|
+
callToolAsync(args).then((result) => {
|
|
417
|
+
callbacks?.onSuccess?.(result);
|
|
418
|
+
callbacks?.onSettled?.();
|
|
419
|
+
}).catch((err) => {
|
|
420
|
+
callbacks?.onError?.(err);
|
|
421
|
+
callbacks?.onSettled?.();
|
|
422
|
+
});
|
|
423
|
+
},
|
|
424
|
+
[callToolAsync]
|
|
425
|
+
);
|
|
426
|
+
const reset = useCallback(() => {
|
|
427
|
+
setStatus("idle");
|
|
428
|
+
setData(void 0);
|
|
429
|
+
setError(void 0);
|
|
430
|
+
}, []);
|
|
431
|
+
return {
|
|
432
|
+
status,
|
|
433
|
+
isIdle: status === "idle",
|
|
434
|
+
isPending: status === "pending",
|
|
435
|
+
isSuccess: status === "success",
|
|
436
|
+
isError: status === "error",
|
|
437
|
+
data: data2,
|
|
438
|
+
error,
|
|
439
|
+
callTool: callTool2,
|
|
440
|
+
callToolAsync,
|
|
441
|
+
reset
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// src/unified/hooks/rich/use-view-params.ts
|
|
446
|
+
function useViewParams() {
|
|
447
|
+
const input = useToolInput();
|
|
448
|
+
const output = useToolOutput();
|
|
449
|
+
const metadata = useToolResponseMetadata();
|
|
450
|
+
let status;
|
|
451
|
+
if (!input) {
|
|
452
|
+
status = "idle";
|
|
453
|
+
} else if (!output) {
|
|
454
|
+
status = "pending";
|
|
455
|
+
} else {
|
|
456
|
+
status = "success";
|
|
457
|
+
}
|
|
458
|
+
return {
|
|
459
|
+
status,
|
|
460
|
+
isIdle: status === "idle",
|
|
461
|
+
isPending: status === "pending",
|
|
462
|
+
isSuccess: status === "success",
|
|
463
|
+
input,
|
|
464
|
+
output,
|
|
465
|
+
metadata
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
function useViewState(initialState) {
|
|
469
|
+
const adaptor = getAdaptor();
|
|
470
|
+
const store = adaptor.getExternalStore("viewState");
|
|
471
|
+
const initialRef = useRef(initialState);
|
|
472
|
+
const persistedState = useSyncExternalStore(
|
|
473
|
+
store.subscribe,
|
|
474
|
+
store.getSnapshot,
|
|
475
|
+
store.getServerSnapshot
|
|
476
|
+
);
|
|
477
|
+
const state = persistedState ?? initialState;
|
|
478
|
+
const setState = useCallback((newState) => {
|
|
479
|
+
const current = adaptor.getViewState() ?? initialRef.current;
|
|
480
|
+
const nextState = typeof newState === "function" ? newState(current) : newState;
|
|
481
|
+
adaptor.setViewState(nextState);
|
|
482
|
+
}, [adaptor]);
|
|
483
|
+
const resetState = useCallback(() => {
|
|
484
|
+
adaptor.setViewState(initialRef.current);
|
|
485
|
+
}, [adaptor]);
|
|
486
|
+
const isDirty = persistedState !== void 0 && JSON.stringify(persistedState) !== JSON.stringify(initialRef.current);
|
|
487
|
+
return useMemo(() => {
|
|
488
|
+
const result = [state, setState];
|
|
489
|
+
result.state = state;
|
|
490
|
+
result.setState = setState;
|
|
491
|
+
result.resetState = resetState;
|
|
492
|
+
result.isDirty = isDirty;
|
|
493
|
+
return result;
|
|
494
|
+
}, [state, setState, resetState, isDirty]);
|
|
495
|
+
}
|
|
496
|
+
function useHostEnvironment() {
|
|
497
|
+
const theme = useTheme();
|
|
498
|
+
const locale = useLocale();
|
|
499
|
+
const deviceType = useDeviceType();
|
|
500
|
+
const platform = usePlatform();
|
|
501
|
+
const safeArea = useSafeArea();
|
|
502
|
+
const displayMode = useDisplayMode();
|
|
503
|
+
const containerSize = useContainerSize();
|
|
504
|
+
const inputCapabilities = useInputCapabilities();
|
|
505
|
+
return useMemo(
|
|
506
|
+
() => ({
|
|
507
|
+
theme,
|
|
508
|
+
locale,
|
|
509
|
+
deviceType,
|
|
510
|
+
platform,
|
|
511
|
+
safeArea,
|
|
512
|
+
displayMode,
|
|
513
|
+
containerSize,
|
|
514
|
+
inputCapabilities
|
|
515
|
+
}),
|
|
516
|
+
[theme, locale, deviceType, platform, safeArea, displayMode, containerSize, inputCapabilities]
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
function useDisplayModeControl() {
|
|
520
|
+
const displayMode = useDisplayMode();
|
|
521
|
+
const adaptor = getAdaptor();
|
|
522
|
+
const requestDisplayMode2 = useCallback(
|
|
523
|
+
async (mode) => {
|
|
524
|
+
await adaptor.requestDisplayMode(mode);
|
|
525
|
+
},
|
|
526
|
+
[adaptor]
|
|
527
|
+
);
|
|
528
|
+
const requestFullscreen = useCallback(async () => {
|
|
529
|
+
await requestDisplayMode2("fullscreen");
|
|
530
|
+
}, [requestDisplayMode2]);
|
|
531
|
+
const requestInline = useCallback(async () => {
|
|
532
|
+
await requestDisplayMode2("inline");
|
|
533
|
+
}, [requestDisplayMode2]);
|
|
534
|
+
const requestPip = useCallback(async () => {
|
|
535
|
+
await requestDisplayMode2("pip");
|
|
536
|
+
}, [requestDisplayMode2]);
|
|
537
|
+
return useMemo(
|
|
538
|
+
() => ({
|
|
539
|
+
displayMode,
|
|
540
|
+
requestFullscreen,
|
|
541
|
+
requestInline,
|
|
542
|
+
requestPip,
|
|
543
|
+
requestDisplayMode: requestDisplayMode2,
|
|
544
|
+
isFullscreen: displayMode === "fullscreen",
|
|
545
|
+
isInline: displayMode === "inline",
|
|
546
|
+
isPip: displayMode === "pip"
|
|
547
|
+
}),
|
|
548
|
+
[displayMode, requestFullscreen, requestInline, requestPip, requestDisplayMode2]
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
// src/unified/hooks/convenience/use-is-mobile.ts
|
|
553
|
+
function useIsMobile() {
|
|
554
|
+
const deviceType = useDeviceType();
|
|
555
|
+
return deviceType === "mobile" || deviceType === "tablet";
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// src/unified/hooks/convenience/use-is-fullscreen.ts
|
|
559
|
+
function useIsFullscreen() {
|
|
560
|
+
const displayMode = useDisplayMode();
|
|
561
|
+
return displayMode === "fullscreen";
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// src/unified/hooks/convenience/use-is-dark-mode.ts
|
|
565
|
+
function useIsDarkMode() {
|
|
566
|
+
const theme = useTheme();
|
|
567
|
+
return theme === "dark";
|
|
568
|
+
}
|
|
569
|
+
var PancakeContext = createContext(null);
|
|
570
|
+
function PancakeProvider({
|
|
571
|
+
children,
|
|
572
|
+
onError,
|
|
573
|
+
debug = false,
|
|
574
|
+
fallback = null,
|
|
575
|
+
immediate = false
|
|
576
|
+
}) {
|
|
577
|
+
const [isReady, setIsReady] = useState(false);
|
|
578
|
+
const [error, setError] = useState(void 0);
|
|
579
|
+
const isMcp = isMcpAppsAvailable();
|
|
580
|
+
const platform = isMcp ? "mcp-apps" : "apps-sdk";
|
|
581
|
+
useEffect(() => {
|
|
582
|
+
const adaptor = getAdaptor();
|
|
583
|
+
if (debug) {
|
|
584
|
+
console.log("[Pancake] Initializing on platform:", platform);
|
|
585
|
+
}
|
|
586
|
+
adaptor.ensureReady().then(() => {
|
|
587
|
+
if (debug) {
|
|
588
|
+
console.log("[Pancake] Initialization complete");
|
|
589
|
+
}
|
|
590
|
+
setIsReady(true);
|
|
591
|
+
}).catch((err) => {
|
|
592
|
+
if (debug) {
|
|
593
|
+
console.error("[Pancake] Initialization failed:", err);
|
|
594
|
+
}
|
|
595
|
+
setError(err);
|
|
596
|
+
onError?.(err);
|
|
597
|
+
});
|
|
598
|
+
}, [debug, onError, platform]);
|
|
599
|
+
const contextValue = {
|
|
600
|
+
isReady,
|
|
601
|
+
error,
|
|
602
|
+
platform
|
|
603
|
+
};
|
|
604
|
+
const shouldRender = isReady || immediate || !isMcp && !error;
|
|
605
|
+
return /* @__PURE__ */ jsx(PancakeContext.Provider, { value: contextValue, children: shouldRender ? children : fallback });
|
|
606
|
+
}
|
|
607
|
+
function usePancakeContext() {
|
|
608
|
+
const context = useContext(PancakeContext);
|
|
609
|
+
if (!context) {
|
|
610
|
+
throw new Error("usePancakeContext must be used within a PancakeProvider");
|
|
611
|
+
}
|
|
612
|
+
return context;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// src/unified/debug.ts
|
|
616
|
+
var DEBUG = typeof process !== "undefined" && process.env?.NODE_ENV === "development";
|
|
617
|
+
var IS_TEST = typeof process !== "undefined" && process.env?.NODE_ENV === "test";
|
|
618
|
+
var IS_STORYBOOK = typeof window !== "undefined" && Boolean(window.__STORYBOOK_CLIENT_API__);
|
|
619
|
+
function debugLog(message, data2) {
|
|
620
|
+
if (DEBUG) {
|
|
621
|
+
if (data2 !== void 0) {
|
|
622
|
+
console.log(`[Pancake Debug] ${message}`, data2);
|
|
623
|
+
} else {
|
|
624
|
+
console.log(`[Pancake Debug] ${message}`);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
function debugWarn(message, data2) {
|
|
629
|
+
if (DEBUG) {
|
|
630
|
+
if (data2 !== void 0) {
|
|
631
|
+
console.warn(`[Pancake Debug] ${message}`, data2);
|
|
632
|
+
} else {
|
|
633
|
+
console.warn(`[Pancake Debug] ${message}`);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
function debugAssert(condition, message) {
|
|
638
|
+
if (DEBUG && !condition) {
|
|
639
|
+
console.error(`[Pancake Assert] ${message}`);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
function debugTime(label, fn) {
|
|
643
|
+
if (DEBUG) {
|
|
644
|
+
console.time(`[Pancake] ${label}`);
|
|
645
|
+
const result = fn();
|
|
646
|
+
console.timeEnd(`[Pancake] ${label}`);
|
|
647
|
+
return result;
|
|
648
|
+
}
|
|
649
|
+
return fn();
|
|
650
|
+
}
|
|
651
|
+
async function debugTimeAsync(label, fn) {
|
|
652
|
+
if (DEBUG) {
|
|
653
|
+
console.time(`[Pancake] ${label}`);
|
|
654
|
+
const result = await fn();
|
|
655
|
+
console.timeEnd(`[Pancake] ${label}`);
|
|
656
|
+
return result;
|
|
657
|
+
}
|
|
658
|
+
return fn();
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// src/index.ts
|
|
662
|
+
function initPancake() {
|
|
663
|
+
const pancake = {
|
|
664
|
+
platform: getPlatform(),
|
|
665
|
+
adaptor: getAdaptor(),
|
|
666
|
+
appsSdk: apps_sdk_exports,
|
|
667
|
+
mcpApps: mcp_apps_exports,
|
|
668
|
+
unified: unified_exports
|
|
669
|
+
};
|
|
670
|
+
if (typeof window !== "undefined") {
|
|
671
|
+
window.pancake = pancake;
|
|
672
|
+
}
|
|
673
|
+
return pancake;
|
|
674
|
+
}
|
|
675
|
+
if (typeof window !== "undefined") {
|
|
676
|
+
setTimeout(() => {
|
|
677
|
+
if (!window.pancake) {
|
|
678
|
+
initPancake();
|
|
679
|
+
}
|
|
680
|
+
}, 0);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
export { DEBUG, IS_STORYBOOK, IS_TEST, PancakeProvider, debugAssert, debugLog, debugTime, debugTimeAsync, debugWarn, initPancake, useAction, useCallTool, useContainerSize, useData, useDeviceType, useDisplayMode, useDisplayModeControl, useHostEnvironment, useInputCapabilities, useIsDarkMode, useIsFullscreen, useIsMobile, useLocale, useMaxHeight, usePancakeContext, usePlatform, useSafeArea, useTheme, useToolInput, useToolOutput, useToolResponseMetadata, useViewData, useViewParams, useViewState };
|
|
684
|
+
//# sourceMappingURL=index.js.map
|
|
685
|
+
//# sourceMappingURL=index.js.map
|