sunpeak 0.9.3 → 0.9.8
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 +2 -2
- package/dist/chatgpt/conversation.d.ts +5 -2
- package/dist/chatgpt/iframe-resource.d.ts +69 -0
- package/dist/chatgpt/index.cjs +2 -1
- package/dist/chatgpt/index.cjs.map +1 -1
- package/dist/chatgpt/index.d.ts +1 -0
- package/dist/chatgpt/index.js +2 -1
- package/dist/chatgpt/simple-sidebar.d.ts +2 -2
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -2
- package/dist/{simulator-url-CG8lAAC3.cjs → simulator-url-BpCa95pE.cjs} +876 -251
- package/dist/simulator-url-BpCa95pE.cjs.map +1 -0
- package/dist/{simulator-url-CexnaL-e.js → simulator-url-q5tHLc4-.js} +876 -251
- package/dist/simulator-url-q5tHLc4-.js.map +1 -0
- package/dist/style.css +12 -0
- package/dist/types/simulation.d.ts +4 -1
- package/package.json +1 -1
- package/template/README.md +2 -2
- package/template/dist/albums.js +7 -7
- package/template/dist/albums.json +1 -1
- package/template/dist/carousel.js +6 -6
- package/template/dist/carousel.json +1 -1
- package/template/dist/map.js +17 -17
- package/template/dist/map.json +1 -1
- package/template/dist/review.js +7 -7
- package/template/dist/review.json +1 -1
- package/template/node_modules/.vite/deps/_metadata.json +19 -19
- package/template/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -1
- package/template/src/components/album/album-carousel.tsx +28 -3
- package/template/src/components/carousel/carousel.tsx +28 -3
- package/dist/simulator-url-CG8lAAC3.cjs.map +0 -1
- package/dist/simulator-url-CexnaL-e.js.map +0 -1
|
@@ -4,7 +4,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4
4
|
var _a, _b;
|
|
5
5
|
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import * as React from "react";
|
|
7
|
-
import React__default, { useSyncExternalStore, useState, useEffect, useCallback, useLayoutEffect,
|
|
7
|
+
import React__default, { useSyncExternalStore, useState, useRef, useEffect, useCallback, useLayoutEffect, useId as useId$1, Children, isValidElement, cloneElement, createContext, useReducer, useMemo, use } from "react";
|
|
8
8
|
import * as ReactDOM from "react-dom";
|
|
9
9
|
import ReactDOM__default from "react-dom";
|
|
10
10
|
const SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
|
|
@@ -39,19 +39,38 @@ class OpenAiProvider {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
getAPI() {
|
|
42
|
-
var _a2, _b2, _c, _d, _e, _f, _g;
|
|
43
42
|
if (typeof window === "undefined" || !window.openai) {
|
|
44
43
|
return null;
|
|
45
44
|
}
|
|
46
|
-
const api = window.openai;
|
|
47
45
|
return {
|
|
48
|
-
callTool: (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
callTool: (...args) => {
|
|
47
|
+
var _a2, _b2;
|
|
48
|
+
return (_b2 = (_a2 = window.openai) == null ? void 0 : _a2.callTool) == null ? void 0 : _b2.call(_a2, ...args);
|
|
49
|
+
},
|
|
50
|
+
sendFollowUpMessage: (...args) => {
|
|
51
|
+
var _a2, _b2;
|
|
52
|
+
return (_b2 = (_a2 = window.openai) == null ? void 0 : _a2.sendFollowUpMessage) == null ? void 0 : _b2.call(_a2, ...args);
|
|
53
|
+
},
|
|
54
|
+
openExternal: (...args) => {
|
|
55
|
+
var _a2, _b2;
|
|
56
|
+
return (_b2 = (_a2 = window.openai) == null ? void 0 : _a2.openExternal) == null ? void 0 : _b2.call(_a2, ...args);
|
|
57
|
+
},
|
|
58
|
+
requestDisplayMode: (...args) => {
|
|
59
|
+
var _a2, _b2;
|
|
60
|
+
return (_b2 = (_a2 = window.openai) == null ? void 0 : _a2.requestDisplayMode) == null ? void 0 : _b2.call(_a2, ...args);
|
|
61
|
+
},
|
|
62
|
+
requestModal: (...args) => {
|
|
63
|
+
var _a2, _b2;
|
|
64
|
+
return (_b2 = (_a2 = window.openai) == null ? void 0 : _a2.requestModal) == null ? void 0 : _b2.call(_a2, ...args);
|
|
65
|
+
},
|
|
66
|
+
notifyIntrinsicHeight: (...args) => {
|
|
67
|
+
var _a2, _b2;
|
|
68
|
+
return (_b2 = (_a2 = window.openai) == null ? void 0 : _a2.notifyIntrinsicHeight) == null ? void 0 : _b2.call(_a2, ...args);
|
|
69
|
+
},
|
|
70
|
+
setWidgetState: (...args) => {
|
|
71
|
+
var _a2, _b2;
|
|
72
|
+
return (_b2 = (_a2 = window.openai) == null ? void 0 : _a2.setWidgetState) == null ? void 0 : _b2.call(_a2, ...args);
|
|
73
|
+
}
|
|
55
74
|
};
|
|
56
75
|
}
|
|
57
76
|
}
|
|
@@ -154,8 +173,17 @@ function useWidgetState(defaultState) {
|
|
|
154
173
|
}
|
|
155
174
|
return typeof defaultState === "function" ? defaultState() : defaultState ?? null;
|
|
156
175
|
});
|
|
176
|
+
const hasSentInitialState = useRef(false);
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
if (!hasSentInitialState.current && widgetStateFromProvider == null && widgetState != null && (api == null ? void 0 : api.setWidgetState)) {
|
|
179
|
+
hasSentInitialState.current = true;
|
|
180
|
+
api.setWidgetState(widgetState);
|
|
181
|
+
}
|
|
182
|
+
}, [api, widgetState, widgetStateFromProvider]);
|
|
157
183
|
useEffect(() => {
|
|
158
|
-
|
|
184
|
+
if (widgetStateFromProvider != null) {
|
|
185
|
+
_setWidgetState(widgetStateFromProvider);
|
|
186
|
+
}
|
|
159
187
|
}, [widgetStateFromProvider]);
|
|
160
188
|
const setWidgetState = useCallback(
|
|
161
189
|
(state) => {
|
|
@@ -7502,9 +7530,11 @@ function SidebarTextarea({
|
|
|
7502
7530
|
onFocus,
|
|
7503
7531
|
onBlur,
|
|
7504
7532
|
placeholder,
|
|
7505
|
-
|
|
7533
|
+
maxRows = 8,
|
|
7506
7534
|
error
|
|
7507
7535
|
}) {
|
|
7536
|
+
const contentRows = (value == null ? void 0 : value.split("\n").length) ?? 1;
|
|
7537
|
+
const rows = Math.min(contentRows, maxRows);
|
|
7508
7538
|
return /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
|
|
7509
7539
|
/* @__PURE__ */ jsx(
|
|
7510
7540
|
Textarea,
|
|
@@ -7516,7 +7546,8 @@ function SidebarTextarea({
|
|
|
7516
7546
|
placeholder,
|
|
7517
7547
|
rows,
|
|
7518
7548
|
size: "2xs",
|
|
7519
|
-
className: "text-[10px] font-mono",
|
|
7549
|
+
className: "text-[10px] font-mono resize-y",
|
|
7550
|
+
style: { whiteSpace: "pre", overflowX: "auto", overflowWrap: "normal" },
|
|
7520
7551
|
invalid: !!error
|
|
7521
7552
|
}
|
|
7522
7553
|
),
|
|
@@ -7542,8 +7573,591 @@ const SCREEN_WIDTHS = {
|
|
|
7542
7573
|
tablet: 768,
|
|
7543
7574
|
full: 1024
|
|
7544
7575
|
};
|
|
7576
|
+
const ALLOWED_SCRIPT_ORIGINS = [
|
|
7577
|
+
"https://sandbox.sunpeakai.com",
|
|
7578
|
+
"http://localhost",
|
|
7579
|
+
"https://localhost",
|
|
7580
|
+
"http://127.0.0.1",
|
|
7581
|
+
"https://127.0.0.1"
|
|
7582
|
+
];
|
|
7583
|
+
const ALLOWED_PARENT_ORIGINS = [
|
|
7584
|
+
"https://app.sunpeak.ai",
|
|
7585
|
+
"http://localhost",
|
|
7586
|
+
"https://localhost",
|
|
7587
|
+
"http://127.0.0.1",
|
|
7588
|
+
"https://127.0.0.1"
|
|
7589
|
+
];
|
|
7590
|
+
function escapeHtml(str) {
|
|
7591
|
+
return str.replace(/[&<>"']/g, (c) => {
|
|
7592
|
+
const entities = {
|
|
7593
|
+
"&": "&",
|
|
7594
|
+
"<": "<",
|
|
7595
|
+
">": ">",
|
|
7596
|
+
'"': """,
|
|
7597
|
+
"'": "'"
|
|
7598
|
+
};
|
|
7599
|
+
return entities[c] ?? c;
|
|
7600
|
+
});
|
|
7601
|
+
}
|
|
7602
|
+
function isAllowedScriptSrc(src) {
|
|
7603
|
+
if (!src) {
|
|
7604
|
+
return false;
|
|
7605
|
+
}
|
|
7606
|
+
if (src.startsWith("/") && !src.startsWith("//")) {
|
|
7607
|
+
return true;
|
|
7608
|
+
}
|
|
7609
|
+
if (!src.includes("://")) {
|
|
7610
|
+
return false;
|
|
7611
|
+
}
|
|
7612
|
+
try {
|
|
7613
|
+
const url = new URL(src);
|
|
7614
|
+
if (url.origin === window.location.origin) {
|
|
7615
|
+
return true;
|
|
7616
|
+
}
|
|
7617
|
+
if (url.hostname === "localhost" || url.hostname === "127.0.0.1") {
|
|
7618
|
+
return true;
|
|
7619
|
+
}
|
|
7620
|
+
return ALLOWED_SCRIPT_ORIGINS.some((allowed) => {
|
|
7621
|
+
try {
|
|
7622
|
+
const allowedUrl = new URL(allowed);
|
|
7623
|
+
return url.origin === allowedUrl.origin;
|
|
7624
|
+
} catch {
|
|
7625
|
+
return false;
|
|
7626
|
+
}
|
|
7627
|
+
});
|
|
7628
|
+
} catch {
|
|
7629
|
+
return false;
|
|
7630
|
+
}
|
|
7631
|
+
}
|
|
7632
|
+
function generateCSP(csp, scriptSrc) {
|
|
7633
|
+
let scriptOrigin = "";
|
|
7634
|
+
try {
|
|
7635
|
+
const scriptUrl = new URL(scriptSrc, window.location.origin);
|
|
7636
|
+
scriptOrigin = scriptUrl.origin;
|
|
7637
|
+
} catch {
|
|
7638
|
+
}
|
|
7639
|
+
const directives = [
|
|
7640
|
+
"default-src 'self'",
|
|
7641
|
+
// Allow inline scripts for the bridge, blob: for dynamic content, and the script origin
|
|
7642
|
+
`script-src 'self' 'unsafe-inline' blob: ${scriptOrigin}`.trim(),
|
|
7643
|
+
// Allow inline styles and data: URIs for images embedded in CSS
|
|
7644
|
+
`style-src 'self' 'unsafe-inline' ${scriptOrigin}`.trim(),
|
|
7645
|
+
// Disallow iframes within the iframe (no nesting)
|
|
7646
|
+
"frame-src 'none'",
|
|
7647
|
+
// Disallow form submissions
|
|
7648
|
+
"form-action 'none'",
|
|
7649
|
+
// Disallow changing the base URL
|
|
7650
|
+
"base-uri 'self'"
|
|
7651
|
+
];
|
|
7652
|
+
const connectSources = /* @__PURE__ */ new Set(["'self'"]);
|
|
7653
|
+
if (scriptOrigin) {
|
|
7654
|
+
connectSources.add(scriptOrigin);
|
|
7655
|
+
}
|
|
7656
|
+
if (csp == null ? void 0 : csp.connect_domains) {
|
|
7657
|
+
for (const domain of csp.connect_domains) {
|
|
7658
|
+
connectSources.add(domain);
|
|
7659
|
+
}
|
|
7660
|
+
}
|
|
7661
|
+
directives.push(`connect-src ${Array.from(connectSources).join(" ")}`);
|
|
7662
|
+
const resourceSources = /* @__PURE__ */ new Set(["'self'", "data:", "blob:"]);
|
|
7663
|
+
if (scriptOrigin) {
|
|
7664
|
+
resourceSources.add(scriptOrigin);
|
|
7665
|
+
}
|
|
7666
|
+
if (csp == null ? void 0 : csp.resource_domains) {
|
|
7667
|
+
for (const domain of csp.resource_domains) {
|
|
7668
|
+
resourceSources.add(domain);
|
|
7669
|
+
}
|
|
7670
|
+
}
|
|
7671
|
+
const resourceList = Array.from(resourceSources).join(" ");
|
|
7672
|
+
directives.push(`img-src ${resourceList}`);
|
|
7673
|
+
directives.push(`font-src ${resourceList}`);
|
|
7674
|
+
directives.push(`media-src ${resourceList}`);
|
|
7675
|
+
return directives.join("; ");
|
|
7676
|
+
}
|
|
7677
|
+
function generateBridgeScript(allowedParentOrigins) {
|
|
7678
|
+
const originsJson = JSON.stringify(allowedParentOrigins);
|
|
7679
|
+
return `
|
|
7680
|
+
<script>
|
|
7681
|
+
(function() {
|
|
7682
|
+
// Allowed origins that can send messages to this iframe
|
|
7683
|
+
var allowedOrigins = ${originsJson};
|
|
7684
|
+
|
|
7685
|
+
// MessagePort for secure communication with parent (set during handshake)
|
|
7686
|
+
var messagePort = null;
|
|
7687
|
+
|
|
7688
|
+
// Queue messages until port is ready
|
|
7689
|
+
var messageQueue = [];
|
|
7690
|
+
|
|
7691
|
+
// Check if an origin is allowed (handles localhost with any port)
|
|
7692
|
+
function isAllowedOrigin(origin) {
|
|
7693
|
+
// Note: We no longer accept 'null' origin - MessageChannel provides security
|
|
7694
|
+
for (var i = 0; i < allowedOrigins.length; i++) {
|
|
7695
|
+
if (origin === allowedOrigins[i]) return true;
|
|
7696
|
+
// Handle localhost/127.0.0.1 with any port
|
|
7697
|
+
if (allowedOrigins[i].indexOf('localhost') !== -1 || allowedOrigins[i].indexOf('127.0.0.1') !== -1) {
|
|
7698
|
+
try {
|
|
7699
|
+
var allowed = new URL(allowedOrigins[i]);
|
|
7700
|
+
var test = new URL(origin);
|
|
7701
|
+
if (test.hostname === allowed.hostname && test.protocol === allowed.protocol) return true;
|
|
7702
|
+
} catch (e) {}
|
|
7703
|
+
}
|
|
7704
|
+
}
|
|
7705
|
+
return false;
|
|
7706
|
+
}
|
|
7707
|
+
|
|
7708
|
+
// Send message via MessagePort (queues if port not ready)
|
|
7709
|
+
function sendToParent(message) {
|
|
7710
|
+
if (messagePort) {
|
|
7711
|
+
messagePort.postMessage(message);
|
|
7712
|
+
} else {
|
|
7713
|
+
messageQueue.push(message);
|
|
7714
|
+
}
|
|
7715
|
+
}
|
|
7716
|
+
|
|
7717
|
+
// Flush queued messages once port is ready
|
|
7718
|
+
function flushMessageQueue() {
|
|
7719
|
+
while (messageQueue.length > 0) {
|
|
7720
|
+
var msg = messageQueue.shift();
|
|
7721
|
+
messagePort.postMessage(msg);
|
|
7722
|
+
}
|
|
7723
|
+
}
|
|
7724
|
+
|
|
7725
|
+
// Set up window.openai with placeholder values (updated via MessageChannel)
|
|
7726
|
+
window.openai = {
|
|
7727
|
+
theme: 'dark',
|
|
7728
|
+
locale: 'en-US',
|
|
7729
|
+
displayMode: 'inline',
|
|
7730
|
+
maxHeight: undefined,
|
|
7731
|
+
userAgent: { device: { type: 'desktop' }, capabilities: { hover: true, touch: false } },
|
|
7732
|
+
safeArea: { insets: { top: 0, bottom: 0, left: 0, right: 0 } },
|
|
7733
|
+
view: null,
|
|
7734
|
+
toolInput: {},
|
|
7735
|
+
toolOutput: null,
|
|
7736
|
+
toolResponseMetadata: null,
|
|
7737
|
+
widgetState: null,
|
|
7738
|
+
|
|
7739
|
+
// API methods that send messages to parent via MessagePort
|
|
7740
|
+
callTool: function(name, args) {
|
|
7741
|
+
sendToParent({ type: 'openai:callTool', payload: { name, args } });
|
|
7742
|
+
},
|
|
7743
|
+
sendFollowUpMessage: function(params) {
|
|
7744
|
+
sendToParent({ type: 'openai:sendFollowUpMessage', payload: params });
|
|
7745
|
+
},
|
|
7746
|
+
openExternal: function(params) {
|
|
7747
|
+
sendToParent({ type: 'openai:openExternal', payload: params });
|
|
7748
|
+
},
|
|
7749
|
+
requestDisplayMode: function(params) {
|
|
7750
|
+
sendToParent({ type: 'openai:requestDisplayMode', payload: params });
|
|
7751
|
+
},
|
|
7752
|
+
requestModal: function(params) {
|
|
7753
|
+
sendToParent({ type: 'openai:requestModal', payload: params });
|
|
7754
|
+
},
|
|
7755
|
+
notifyIntrinsicHeight: function(height) {
|
|
7756
|
+
// Height updates use postMessage directly to avoid delays during handshake.
|
|
7757
|
+
// This is safe because height values are validated on the parent side.
|
|
7758
|
+
window.parent.postMessage({ type: 'openai:notifyIntrinsicHeight', payload: { height } }, '*');
|
|
7759
|
+
},
|
|
7760
|
+
setWidgetState: function(state) {
|
|
7761
|
+
sendToParent({ type: 'openai:setWidgetState', payload: state });
|
|
7762
|
+
},
|
|
7763
|
+
};
|
|
7764
|
+
|
|
7765
|
+
// Handle incoming messages on the MessagePort
|
|
7766
|
+
function handlePortMessage(event) {
|
|
7767
|
+
var data = event.data;
|
|
7768
|
+
if (!data || typeof data !== 'object') return;
|
|
7769
|
+
|
|
7770
|
+
if (data.type === 'openai:init' || data.type === 'openai:update') {
|
|
7771
|
+
var payload = data.payload || {};
|
|
7772
|
+
|
|
7773
|
+
// Update window.openai with new values
|
|
7774
|
+
if (payload.theme !== undefined) {
|
|
7775
|
+
window.openai.theme = payload.theme;
|
|
7776
|
+
// Also set data-theme attribute for CSS theming
|
|
7777
|
+
document.documentElement.dataset.theme = payload.theme;
|
|
7778
|
+
}
|
|
7779
|
+
if (payload.displayMode !== undefined) window.openai.displayMode = payload.displayMode;
|
|
7780
|
+
if (payload.locale !== undefined) window.openai.locale = payload.locale;
|
|
7781
|
+
if (payload.maxHeight !== undefined) window.openai.maxHeight = payload.maxHeight;
|
|
7782
|
+
if (payload.userAgent !== undefined) window.openai.userAgent = payload.userAgent;
|
|
7783
|
+
if (payload.safeArea !== undefined) window.openai.safeArea = payload.safeArea;
|
|
7784
|
+
if (payload.view !== undefined) window.openai.view = payload.view;
|
|
7785
|
+
if (payload.toolInput !== undefined) window.openai.toolInput = payload.toolInput;
|
|
7786
|
+
if (payload.toolOutput !== undefined) window.openai.toolOutput = payload.toolOutput;
|
|
7787
|
+
if (payload.toolResponseMetadata !== undefined) window.openai.toolResponseMetadata = payload.toolResponseMetadata;
|
|
7788
|
+
if (payload.widgetState !== undefined) window.openai.widgetState = payload.widgetState;
|
|
7789
|
+
|
|
7790
|
+
// Dispatch custom event so widgets can react to changes
|
|
7791
|
+
// Must match SET_GLOBALS_EVENT_TYPE ('openai:set_globals') in providers/openai/types.ts
|
|
7792
|
+
window.dispatchEvent(new CustomEvent('openai:set_globals', { detail: { globals: payload } }));
|
|
7793
|
+
}
|
|
7794
|
+
}
|
|
7795
|
+
|
|
7796
|
+
// Listen for handshake message from parent (transfers MessagePort)
|
|
7797
|
+
window.addEventListener('message', function(event) {
|
|
7798
|
+
// Strict source validation: only accept messages from parent window
|
|
7799
|
+
if (event.source !== window.parent) {
|
|
7800
|
+
console.warn('[IframeBridge] Rejected message from non-parent source');
|
|
7801
|
+
return;
|
|
7802
|
+
}
|
|
7803
|
+
|
|
7804
|
+
// Validate message origin (allows localhost with any port)
|
|
7805
|
+
if (!isAllowedOrigin(event.origin)) {
|
|
7806
|
+
console.warn('[IframeBridge] Rejected message from untrusted origin:', event.origin);
|
|
7807
|
+
return;
|
|
7808
|
+
}
|
|
7809
|
+
|
|
7810
|
+
// Handle handshake with MessagePort transfer
|
|
7811
|
+
if (event.data && event.data.type === 'openai:handshake' && event.ports && event.ports.length > 0) {
|
|
7812
|
+
messagePort = event.ports[0];
|
|
7813
|
+
messagePort.onmessage = handlePortMessage;
|
|
7814
|
+
messagePort.start();
|
|
7815
|
+
|
|
7816
|
+
// Flush any queued messages
|
|
7817
|
+
flushMessageQueue();
|
|
7818
|
+
|
|
7819
|
+
// Confirm handshake complete
|
|
7820
|
+
sendToParent({ type: 'openai:handshake_complete' });
|
|
7821
|
+
}
|
|
7822
|
+
});
|
|
7823
|
+
|
|
7824
|
+
// Signal to parent that we're ready for handshake
|
|
7825
|
+
window.parent.postMessage({ type: 'openai:ready' }, '*');
|
|
7826
|
+
|
|
7827
|
+
// Auto-measure and report content height immediately
|
|
7828
|
+
var lastHeight = 0;
|
|
7829
|
+
var pendingFrame = null;
|
|
7830
|
+
function reportHeight() {
|
|
7831
|
+
var height = document.documentElement.scrollHeight || document.body.scrollHeight;
|
|
7832
|
+
if (height > 0 && height !== lastHeight) {
|
|
7833
|
+
lastHeight = height;
|
|
7834
|
+
window.openai.notifyIntrinsicHeight(height);
|
|
7835
|
+
}
|
|
7836
|
+
}
|
|
7837
|
+
|
|
7838
|
+
// Schedule height report on next animation frame (batches rapid changes)
|
|
7839
|
+
function scheduleHeightReport() {
|
|
7840
|
+
if (pendingFrame) return;
|
|
7841
|
+
pendingFrame = requestAnimationFrame(function() {
|
|
7842
|
+
pendingFrame = null;
|
|
7843
|
+
reportHeight();
|
|
7844
|
+
});
|
|
7845
|
+
}
|
|
7846
|
+
|
|
7847
|
+
// Report height immediately when ready
|
|
7848
|
+
if (document.readyState === 'complete') {
|
|
7849
|
+
reportHeight();
|
|
7850
|
+
} else {
|
|
7851
|
+
window.addEventListener('load', reportHeight);
|
|
7852
|
+
}
|
|
7853
|
+
|
|
7854
|
+
// Use ResizeObserver to track size changes
|
|
7855
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
7856
|
+
var resizeObserver = new ResizeObserver(function() {
|
|
7857
|
+
scheduleHeightReport();
|
|
7858
|
+
});
|
|
7859
|
+
function observeElements() {
|
|
7860
|
+
if (document.body) resizeObserver.observe(document.body);
|
|
7861
|
+
if (document.documentElement) resizeObserver.observe(document.documentElement);
|
|
7862
|
+
// Also observe the root element if it exists
|
|
7863
|
+
var root = document.getElementById('root');
|
|
7864
|
+
if (root) resizeObserver.observe(root);
|
|
7865
|
+
}
|
|
7866
|
+
if (document.body) {
|
|
7867
|
+
observeElements();
|
|
7868
|
+
} else {
|
|
7869
|
+
document.addEventListener('DOMContentLoaded', observeElements);
|
|
7870
|
+
}
|
|
7871
|
+
}
|
|
7872
|
+
|
|
7873
|
+
// Use MutationObserver to detect DOM changes that may affect height
|
|
7874
|
+
if (typeof MutationObserver !== 'undefined') {
|
|
7875
|
+
var mutationObserver = new MutationObserver(function() {
|
|
7876
|
+
scheduleHeightReport();
|
|
7877
|
+
});
|
|
7878
|
+
function observeMutations() {
|
|
7879
|
+
mutationObserver.observe(document.body, {
|
|
7880
|
+
childList: true,
|
|
7881
|
+
subtree: true,
|
|
7882
|
+
attributes: true,
|
|
7883
|
+
characterData: true
|
|
7884
|
+
});
|
|
7885
|
+
}
|
|
7886
|
+
if (document.body) {
|
|
7887
|
+
observeMutations();
|
|
7888
|
+
} else {
|
|
7889
|
+
document.addEventListener('DOMContentLoaded', observeMutations);
|
|
7890
|
+
}
|
|
7891
|
+
}
|
|
7892
|
+
})();
|
|
7893
|
+
<\/script>
|
|
7894
|
+
`;
|
|
7895
|
+
}
|
|
7896
|
+
function generateScriptHtml(scriptSrc, theme, cspPolicy) {
|
|
7897
|
+
const safeScriptSrc = escapeHtml(scriptSrc);
|
|
7898
|
+
const safeCsp = escapeHtml(cspPolicy);
|
|
7899
|
+
return `<!DOCTYPE html>
|
|
7900
|
+
<html lang="en" data-theme="${theme}">
|
|
7901
|
+
<head>
|
|
7902
|
+
<meta charset="UTF-8" />
|
|
7903
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7904
|
+
<meta http-equiv="Content-Security-Policy" content="${safeCsp}" />
|
|
7905
|
+
<title>Resource</title>
|
|
7906
|
+
<style>
|
|
7907
|
+
html, body, #root {
|
|
7908
|
+
margin: 0;
|
|
7909
|
+
padding: 0;
|
|
7910
|
+
height: 100%;
|
|
7911
|
+
width: 100%;
|
|
7912
|
+
}
|
|
7913
|
+
body {
|
|
7914
|
+
background: transparent;
|
|
7915
|
+
}
|
|
7916
|
+
</style>
|
|
7917
|
+
</head>
|
|
7918
|
+
<body>
|
|
7919
|
+
<div id="root"></div>
|
|
7920
|
+
<script src="${safeScriptSrc}"><\/script>
|
|
7921
|
+
</body>
|
|
7922
|
+
</html>`;
|
|
7923
|
+
}
|
|
7924
|
+
function injectBridgeScript(htmlContent, bridgeScript) {
|
|
7925
|
+
const headMatch = htmlContent.match(/<head[^>]*>/i);
|
|
7926
|
+
if (headMatch) {
|
|
7927
|
+
const insertPos = headMatch.index + headMatch[0].length;
|
|
7928
|
+
return htmlContent.slice(0, insertPos) + bridgeScript + htmlContent.slice(insertPos);
|
|
7929
|
+
}
|
|
7930
|
+
const doctypeMatch = htmlContent.match(/<!DOCTYPE[^>]*>/i);
|
|
7931
|
+
if (doctypeMatch) {
|
|
7932
|
+
const insertPos = doctypeMatch.index + doctypeMatch[0].length;
|
|
7933
|
+
return htmlContent.slice(0, insertPos) + bridgeScript + htmlContent.slice(insertPos);
|
|
7934
|
+
}
|
|
7935
|
+
return bridgeScript + htmlContent;
|
|
7936
|
+
}
|
|
7937
|
+
function IframeResource({ scriptSrc, className, style, csp }) {
|
|
7938
|
+
const iframeRef = useRef(null);
|
|
7939
|
+
const messageChannelRef = useRef(null);
|
|
7940
|
+
const messagePortRef = useRef(null);
|
|
7941
|
+
const [isHeightReady, setIsHeightReady] = React.useState(false);
|
|
7942
|
+
React.useEffect(() => {
|
|
7943
|
+
setIsHeightReady(false);
|
|
7944
|
+
const timeout = setTimeout(() => {
|
|
7945
|
+
setIsHeightReady(true);
|
|
7946
|
+
}, 500);
|
|
7947
|
+
return () => clearTimeout(timeout);
|
|
7948
|
+
}, [scriptSrc]);
|
|
7949
|
+
const theme = useTheme();
|
|
7950
|
+
const displayMode = useDisplayMode();
|
|
7951
|
+
const locale = useLocale();
|
|
7952
|
+
const maxHeight = useMaxHeight();
|
|
7953
|
+
const userAgent = useUserAgent();
|
|
7954
|
+
const safeArea = useSafeArea();
|
|
7955
|
+
const view = useView();
|
|
7956
|
+
const toolInput = useToolInput();
|
|
7957
|
+
const toolOutput = useWidgetProps();
|
|
7958
|
+
const toolResponseMetadata = useToolResponseMetadata();
|
|
7959
|
+
const [widgetState] = useWidgetState();
|
|
7960
|
+
const currentState = React.useMemo(
|
|
7961
|
+
() => ({
|
|
7962
|
+
theme,
|
|
7963
|
+
displayMode,
|
|
7964
|
+
locale,
|
|
7965
|
+
maxHeight,
|
|
7966
|
+
userAgent,
|
|
7967
|
+
safeArea,
|
|
7968
|
+
view,
|
|
7969
|
+
toolInput,
|
|
7970
|
+
toolOutput,
|
|
7971
|
+
toolResponseMetadata,
|
|
7972
|
+
widgetState
|
|
7973
|
+
}),
|
|
7974
|
+
[
|
|
7975
|
+
theme,
|
|
7976
|
+
displayMode,
|
|
7977
|
+
locale,
|
|
7978
|
+
maxHeight,
|
|
7979
|
+
userAgent,
|
|
7980
|
+
safeArea,
|
|
7981
|
+
view,
|
|
7982
|
+
toolInput,
|
|
7983
|
+
toolOutput,
|
|
7984
|
+
toolResponseMetadata,
|
|
7985
|
+
widgetState
|
|
7986
|
+
]
|
|
7987
|
+
);
|
|
7988
|
+
const sendUpdate = useCallback(
|
|
7989
|
+
(type) => {
|
|
7990
|
+
const port = messagePortRef.current;
|
|
7991
|
+
if (port) {
|
|
7992
|
+
const message = {
|
|
7993
|
+
type,
|
|
7994
|
+
payload: currentState
|
|
7995
|
+
};
|
|
7996
|
+
port.postMessage(message);
|
|
7997
|
+
}
|
|
7998
|
+
},
|
|
7999
|
+
[currentState]
|
|
8000
|
+
);
|
|
8001
|
+
const sendUpdateRef = useRef(sendUpdate);
|
|
8002
|
+
useEffect(() => {
|
|
8003
|
+
sendUpdateRef.current = sendUpdate;
|
|
8004
|
+
}, [sendUpdate]);
|
|
8005
|
+
const handlePortMessage = useCallback(
|
|
8006
|
+
(event) => {
|
|
8007
|
+
var _a2, _b2;
|
|
8008
|
+
if (!event.data || typeof event.data !== "object" || typeof event.data.type !== "string") {
|
|
8009
|
+
return;
|
|
8010
|
+
}
|
|
8011
|
+
const { type } = event.data;
|
|
8012
|
+
switch (type) {
|
|
8013
|
+
case "openai:handshake_complete":
|
|
8014
|
+
sendUpdateRef.current("openai:init");
|
|
8015
|
+
break;
|
|
8016
|
+
case "openai:requestDisplayMode": {
|
|
8017
|
+
const payload = event.data.payload;
|
|
8018
|
+
if (!payload || typeof payload !== "object" || !("mode" in payload) || typeof payload.mode !== "string") {
|
|
8019
|
+
console.warn("[IframeResource] Invalid requestDisplayMode payload");
|
|
8020
|
+
return;
|
|
8021
|
+
}
|
|
8022
|
+
const validModes = ["inline", "pip", "fullscreen"];
|
|
8023
|
+
const mode = payload.mode;
|
|
8024
|
+
if (!validModes.includes(mode)) {
|
|
8025
|
+
console.warn("[IframeResource] Invalid display mode:", mode);
|
|
8026
|
+
return;
|
|
8027
|
+
}
|
|
8028
|
+
if (typeof window !== "undefined" && ((_a2 = window.openai) == null ? void 0 : _a2.requestDisplayMode)) {
|
|
8029
|
+
window.openai.requestDisplayMode({ mode });
|
|
8030
|
+
}
|
|
8031
|
+
break;
|
|
8032
|
+
}
|
|
8033
|
+
case "openai:setWidgetState": {
|
|
8034
|
+
const payload = event.data.payload;
|
|
8035
|
+
if (payload !== null && (typeof payload !== "object" || Array.isArray(payload))) {
|
|
8036
|
+
console.warn("[IframeResource] Invalid widgetState payload");
|
|
8037
|
+
return;
|
|
8038
|
+
}
|
|
8039
|
+
if (typeof window !== "undefined" && ((_b2 = window.openai) == null ? void 0 : _b2.setWidgetState)) {
|
|
8040
|
+
window.openai.setWidgetState(payload);
|
|
8041
|
+
}
|
|
8042
|
+
break;
|
|
8043
|
+
}
|
|
8044
|
+
case "openai:notifyIntrinsicHeight": {
|
|
8045
|
+
const payload = event.data.payload;
|
|
8046
|
+
if (!payload || typeof payload !== "object" || !("height" in payload) || typeof payload.height !== "number") {
|
|
8047
|
+
console.warn("[IframeResource] Invalid notifyIntrinsicHeight payload");
|
|
8048
|
+
return;
|
|
8049
|
+
}
|
|
8050
|
+
const height = payload.height;
|
|
8051
|
+
if (height <= 0 || height > 1e5) {
|
|
8052
|
+
console.warn("[IframeResource] Height out of range:", height);
|
|
8053
|
+
return;
|
|
8054
|
+
}
|
|
8055
|
+
if (iframeRef.current) {
|
|
8056
|
+
iframeRef.current.style.height = `${height}px`;
|
|
8057
|
+
}
|
|
8058
|
+
break;
|
|
8059
|
+
}
|
|
8060
|
+
case "openai:callTool":
|
|
8061
|
+
case "openai:sendFollowUpMessage":
|
|
8062
|
+
case "openai:openExternal":
|
|
8063
|
+
case "openai:requestModal":
|
|
8064
|
+
console.log(`[IframeResource] Received ${type}:`, event.data.payload);
|
|
8065
|
+
break;
|
|
8066
|
+
}
|
|
8067
|
+
},
|
|
8068
|
+
[]
|
|
8069
|
+
// No dependencies - uses refs for changing values
|
|
8070
|
+
);
|
|
8071
|
+
useEffect(() => {
|
|
8072
|
+
const handleMessage = (event) => {
|
|
8073
|
+
if (iframeRef.current && event.source !== iframeRef.current.contentWindow) {
|
|
8074
|
+
return;
|
|
8075
|
+
}
|
|
8076
|
+
if (!event.data || typeof event.data !== "object" || typeof event.data.type !== "string") {
|
|
8077
|
+
return;
|
|
8078
|
+
}
|
|
8079
|
+
if (event.data.type === "openai:ready") {
|
|
8080
|
+
const channel = new MessageChannel();
|
|
8081
|
+
messageChannelRef.current = channel;
|
|
8082
|
+
messagePortRef.current = channel.port1;
|
|
8083
|
+
channel.port1.onmessage = handlePortMessage;
|
|
8084
|
+
channel.port1.start();
|
|
8085
|
+
const iframe = iframeRef.current;
|
|
8086
|
+
if (iframe == null ? void 0 : iframe.contentWindow) {
|
|
8087
|
+
iframe.contentWindow.postMessage({ type: "openai:handshake" }, "*", [channel.port2]);
|
|
8088
|
+
}
|
|
8089
|
+
}
|
|
8090
|
+
if (event.data.type === "openai:notifyIntrinsicHeight") {
|
|
8091
|
+
const payload = event.data.payload;
|
|
8092
|
+
if (!payload || typeof payload !== "object" || !("height" in payload) || typeof payload.height !== "number") {
|
|
8093
|
+
return;
|
|
8094
|
+
}
|
|
8095
|
+
const height = payload.height;
|
|
8096
|
+
if (height <= 0 || height > 1e5) {
|
|
8097
|
+
return;
|
|
8098
|
+
}
|
|
8099
|
+
if (iframeRef.current) {
|
|
8100
|
+
iframeRef.current.style.height = `${height}px`;
|
|
8101
|
+
setIsHeightReady(true);
|
|
8102
|
+
}
|
|
8103
|
+
}
|
|
8104
|
+
};
|
|
8105
|
+
window.addEventListener("message", handleMessage);
|
|
8106
|
+
return () => {
|
|
8107
|
+
window.removeEventListener("message", handleMessage);
|
|
8108
|
+
if (messagePortRef.current) {
|
|
8109
|
+
messagePortRef.current.close();
|
|
8110
|
+
}
|
|
8111
|
+
};
|
|
8112
|
+
}, [handlePortMessage]);
|
|
8113
|
+
useEffect(() => {
|
|
8114
|
+
sendUpdate("openai:update");
|
|
8115
|
+
}, [sendUpdate]);
|
|
8116
|
+
const isValidScriptSrc = useMemo(() => isAllowedScriptSrc(scriptSrc), [scriptSrc]);
|
|
8117
|
+
const blobUrl = useMemo(() => {
|
|
8118
|
+
if (!isValidScriptSrc) {
|
|
8119
|
+
console.error("[IframeResource] Script source not allowed:", scriptSrc);
|
|
8120
|
+
const errorHtml = `<!DOCTYPE html><html><body><h1>Error</h1><p>Script source not allowed.</p></body></html>`;
|
|
8121
|
+
const blob2 = new Blob([errorHtml], { type: "text/html" });
|
|
8122
|
+
return URL.createObjectURL(blob2);
|
|
8123
|
+
}
|
|
8124
|
+
const absoluteScriptSrc = scriptSrc.startsWith("/") ? `${window.location.origin}${scriptSrc}` : scriptSrc;
|
|
8125
|
+
const cspPolicy = generateCSP(csp, absoluteScriptSrc);
|
|
8126
|
+
const bridgeScript = generateBridgeScript(ALLOWED_PARENT_ORIGINS);
|
|
8127
|
+
const html = injectBridgeScript(
|
|
8128
|
+
generateScriptHtml(absoluteScriptSrc, theme ?? "dark", cspPolicy),
|
|
8129
|
+
bridgeScript
|
|
8130
|
+
);
|
|
8131
|
+
const blob = new Blob([html], { type: "text/html" });
|
|
8132
|
+
return URL.createObjectURL(blob);
|
|
8133
|
+
}, [scriptSrc, theme, isValidScriptSrc, csp]);
|
|
8134
|
+
useEffect(() => {
|
|
8135
|
+
return () => URL.revokeObjectURL(blobUrl);
|
|
8136
|
+
}, [blobUrl]);
|
|
8137
|
+
return /* @__PURE__ */ jsx(
|
|
8138
|
+
"iframe",
|
|
8139
|
+
{
|
|
8140
|
+
ref: iframeRef,
|
|
8141
|
+
src: blobUrl,
|
|
8142
|
+
className,
|
|
8143
|
+
style: {
|
|
8144
|
+
border: "none",
|
|
8145
|
+
width: "100%",
|
|
8146
|
+
height: "100%",
|
|
8147
|
+
// Hide until first height update to prevent flash of incorrect size
|
|
8148
|
+
opacity: isHeightReady ? 1 : 0,
|
|
8149
|
+
transition: "opacity 0.1s ease-in",
|
|
8150
|
+
...style
|
|
8151
|
+
},
|
|
8152
|
+
title: "Resource Preview",
|
|
8153
|
+
sandbox: "allow-scripts",
|
|
8154
|
+
allow: "accelerometer 'none'; autoplay 'none'; camera 'none'; display-capture 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; midi 'none'; payment 'none'; publickey-credentials-get 'none'; usb 'none'; xr-spatial-tracking 'none'"
|
|
8155
|
+
}
|
|
8156
|
+
);
|
|
8157
|
+
}
|
|
7545
8158
|
function Conversation({
|
|
7546
8159
|
children,
|
|
8160
|
+
iframeScriptSrc,
|
|
7547
8161
|
screenWidth,
|
|
7548
8162
|
appName = "Sunpeak",
|
|
7549
8163
|
appIcon,
|
|
@@ -7555,6 +8169,8 @@ function Conversation({
|
|
|
7555
8169
|
const userAgent = useUserAgent();
|
|
7556
8170
|
const isDesktop = (userAgent == null ? void 0 : userAgent.device.type) === "desktop";
|
|
7557
8171
|
const containerWidth = screenWidth === "full" ? "100%" : `${SCREEN_WIDTHS[screenWidth]}px`;
|
|
8172
|
+
const widgetCSP = resourceMeta == null ? void 0 : resourceMeta["openai/widgetCSP"];
|
|
8173
|
+
const content = iframeScriptSrc ? /* @__PURE__ */ jsx(IframeResource, { scriptSrc: iframeScriptSrc, className: "h-full w-full", csp: widgetCSP }) : children;
|
|
7558
8174
|
if (displayMode === "fullscreen") {
|
|
7559
8175
|
const handleClose = () => {
|
|
7560
8176
|
if (api == null ? void 0 : api.requestDisplayMode) {
|
|
@@ -7604,7 +8220,7 @@ function Conversation({
|
|
|
7604
8220
|
}
|
|
7605
8221
|
) })
|
|
7606
8222
|
] }),
|
|
7607
|
-
/* @__PURE__ */ jsx("div", { className: "relative overflow-hidden flex-1 min-h-0", children: /* @__PURE__ */ jsx("div", { className: "h-full w-full max-w-full overflow-auto", children }) }),
|
|
8223
|
+
/* @__PURE__ */ jsx("div", { className: "relative overflow-hidden flex-1 min-h-0", children: /* @__PURE__ */ jsx("div", { className: "h-full w-full max-w-full overflow-auto", children: content }) }),
|
|
7608
8224
|
/* @__PURE__ */ jsx("footer", { className: "bg-surface", children: /* @__PURE__ */ jsx("div", { className: "max-w-[48rem] mx-auto px-4 py-4", children: /* @__PURE__ */ jsx("div", { className: "relative", children: /* @__PURE__ */ jsx(
|
|
7609
8225
|
"input",
|
|
7610
8226
|
{
|
|
@@ -7694,10 +8310,10 @@ function Conversation({
|
|
|
7694
8310
|
children: /* @__PURE__ */ jsx(CloseBold, { className: "h-4 w-4" })
|
|
7695
8311
|
}
|
|
7696
8312
|
),
|
|
7697
|
-
/* @__PURE__ */ jsx("div", { className: "relative overflow-hidden h-full rounded-2xl sm:rounded-3xl shadow-[0px_0px_0px_1px_#fff3,0px_6px_20px_rgba(0,0,0,0.1)] md:-mx-4", children: /* @__PURE__ */ jsx("div", { className: "h-full w-full max-w-full overflow-auto bg-white dark:bg-[#212121]", children }) })
|
|
8313
|
+
/* @__PURE__ */ jsx("div", { className: "relative overflow-hidden h-full rounded-2xl sm:rounded-3xl shadow-[0px_0px_0px_1px_#fff3,0px_6px_20px_rgba(0,0,0,0.1)] md:-mx-4", children: /* @__PURE__ */ jsx("div", { className: "h-full w-full max-w-full overflow-auto bg-white dark:bg-[#212121]", children: content }) })
|
|
7698
8314
|
]
|
|
7699
8315
|
}
|
|
7700
|
-
) : /* @__PURE__ */ jsx("div", { className: "no-scrollbar relative mb-2 @w-sm/main:w-full mx-0 max-sm:-mx-[1rem] max-sm:w-[100cqw] max-sm:overflow-hidden overflow-visible", children: /* @__PURE__ */ jsx("div", { className: "relative overflow-hidden h-full", children }) }) })
|
|
8316
|
+
) : /* @__PURE__ */ jsx("div", { className: "no-scrollbar relative mb-2 @w-sm/main:w-full mx-0 max-sm:-mx-[1rem] max-sm:w-[100cqw] max-sm:overflow-hidden overflow-visible", children: /* @__PURE__ */ jsx("div", { className: "relative overflow-hidden h-full", children: content }) }) })
|
|
7701
8317
|
}
|
|
7702
8318
|
)
|
|
7703
8319
|
] }) }) })
|
|
@@ -7773,8 +8389,8 @@ class MockOpenAI {
|
|
|
7773
8389
|
console.log("Mock notifyIntrinsicHeight:", height);
|
|
7774
8390
|
}
|
|
7775
8391
|
async setWidgetState(state) {
|
|
7776
|
-
this.widgetState = state;
|
|
7777
|
-
this.emitUpdate({ widgetState:
|
|
8392
|
+
this.widgetState = { ...this.widgetState, ...state };
|
|
8393
|
+
this.emitUpdate({ widgetState: this.widgetState });
|
|
7778
8394
|
}
|
|
7779
8395
|
setTheme(theme) {
|
|
7780
8396
|
this.theme = theme;
|
|
@@ -7985,11 +8601,17 @@ function ChatGPTSimulator({
|
|
|
7985
8601
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- only initialize once
|
|
7986
8602
|
[]
|
|
7987
8603
|
);
|
|
8604
|
+
if (typeof window !== "undefined") {
|
|
8605
|
+
window.openai = mock;
|
|
8606
|
+
resetProviderCache();
|
|
8607
|
+
}
|
|
7988
8608
|
useEffect(() => {
|
|
7989
8609
|
var _a2, _b2;
|
|
7990
8610
|
if (selectedSim) {
|
|
7991
8611
|
mock.toolInput = ((_a2 = selectedSim.callToolRequestParams) == null ? void 0 : _a2.arguments) ?? {};
|
|
7992
|
-
|
|
8612
|
+
if (selectedSim.widgetState !== void 0) {
|
|
8613
|
+
mock.setWidgetStateExternal(selectedSim.widgetState);
|
|
8614
|
+
}
|
|
7993
8615
|
mock.toolOutput = ((_b2 = selectedSim.callToolResult) == null ? void 0 : _b2.structuredContent) ?? null;
|
|
7994
8616
|
}
|
|
7995
8617
|
}, [selectedSimulationName, selectedSim, mock]);
|
|
@@ -8001,7 +8623,7 @@ function ChatGPTSimulator({
|
|
|
8001
8623
|
const safeArea = useSafeArea();
|
|
8002
8624
|
const view = useView();
|
|
8003
8625
|
const toolInput = useToolInput();
|
|
8004
|
-
const
|
|
8626
|
+
const widgetState = useWidgetGlobal("widgetState");
|
|
8005
8627
|
const toolResponseMetadata = useToolResponseMetadata();
|
|
8006
8628
|
const toolOutput = useWidgetProps();
|
|
8007
8629
|
const [toolInputJson, setToolInputJson] = useState(
|
|
@@ -8025,12 +8647,6 @@ function ChatGPTSimulator({
|
|
|
8025
8647
|
const [toolResponseMetadataError, setToolResponseMetadataError] = useState("");
|
|
8026
8648
|
const [widgetStateError, setWidgetStateError] = useState("");
|
|
8027
8649
|
const [viewParamsError, setViewParamsError] = useState("");
|
|
8028
|
-
useLayoutEffect(() => {
|
|
8029
|
-
if (mock && typeof window !== "undefined") {
|
|
8030
|
-
window.openai = mock;
|
|
8031
|
-
resetProviderCache();
|
|
8032
|
-
}
|
|
8033
|
-
}, [mock]);
|
|
8034
8650
|
useEffect(() => {
|
|
8035
8651
|
if (mock) {
|
|
8036
8652
|
mock.emitUpdate({
|
|
@@ -8113,16 +8729,21 @@ function ChatGPTSimulator({
|
|
|
8113
8729
|
}
|
|
8114
8730
|
};
|
|
8115
8731
|
const SelectedComponent = selectedSim == null ? void 0 : selectedSim.resourceComponent;
|
|
8732
|
+
const iframeScriptSrc = !SelectedComponent ? selectedSim == null ? void 0 : selectedSim.resourceScript : void 0;
|
|
8116
8733
|
const content = SelectedComponent ? /* @__PURE__ */ jsx(SelectedComponent, {}) : children;
|
|
8117
8734
|
return /* @__PURE__ */ jsx(ThemeProvider, { theme, children: /* @__PURE__ */ jsx(
|
|
8118
8735
|
SimpleSidebar,
|
|
8119
8736
|
{
|
|
8120
8737
|
controls: /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
8121
|
-
simulationNames.length >
|
|
8738
|
+
simulationNames.length > 1 && /* @__PURE__ */ jsx(SidebarControl, { label: "Simulation", children: /* @__PURE__ */ jsx(
|
|
8122
8739
|
SidebarSelect,
|
|
8123
8740
|
{
|
|
8124
8741
|
value: selectedSimulationName,
|
|
8125
|
-
onChange: (value) =>
|
|
8742
|
+
onChange: (value) => {
|
|
8743
|
+
const newSim = simulations[value];
|
|
8744
|
+
mock.setWidgetStateExternal((newSim == null ? void 0 : newSim.widgetState) ?? null);
|
|
8745
|
+
setSelectedSimulationName(value);
|
|
8746
|
+
},
|
|
8126
8747
|
options: simulationNames.map((name) => {
|
|
8127
8748
|
const sim = simulations[name];
|
|
8128
8749
|
const resourceTitle = sim.resource.title || sim.resource.name;
|
|
@@ -8147,237 +8768,254 @@ function ChatGPTSimulator({
|
|
|
8147
8768
|
]
|
|
8148
8769
|
}
|
|
8149
8770
|
) }),
|
|
8150
|
-
/* @__PURE__ */ jsx(
|
|
8151
|
-
|
|
8152
|
-
|
|
8153
|
-
value: theme,
|
|
8154
|
-
onChange: (value) => mock.setTheme(value),
|
|
8155
|
-
options: [
|
|
8156
|
-
{ value: "light", label: "Light" },
|
|
8157
|
-
{ value: "dark", label: "Dark" }
|
|
8158
|
-
]
|
|
8159
|
-
}
|
|
8160
|
-
) }),
|
|
8161
|
-
/* @__PURE__ */ jsx(SidebarControl, { label: "Display Mode", children: /* @__PURE__ */ jsx(
|
|
8162
|
-
SidebarToggle,
|
|
8163
|
-
{
|
|
8164
|
-
value: displayMode,
|
|
8165
|
-
onChange: (value) => {
|
|
8166
|
-
const newMode = value;
|
|
8167
|
-
if (isMobileWidth(screenWidth) && newMode === "pip") {
|
|
8168
|
-
mock.setDisplayMode("fullscreen");
|
|
8169
|
-
} else {
|
|
8170
|
-
mock.setDisplayMode(newMode);
|
|
8171
|
-
}
|
|
8172
|
-
},
|
|
8173
|
-
options: [
|
|
8174
|
-
{ value: "inline", label: "Inline" },
|
|
8175
|
-
{ value: "pip", label: "PiP" },
|
|
8176
|
-
{ value: "fullscreen", label: "Full" }
|
|
8177
|
-
]
|
|
8178
|
-
}
|
|
8179
|
-
) }),
|
|
8180
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-2", children: [
|
|
8181
|
-
/* @__PURE__ */ jsx(SidebarControl, { label: "Locale", children: /* @__PURE__ */ jsx(
|
|
8182
|
-
SidebarInput,
|
|
8771
|
+
/* @__PURE__ */ jsx(SidebarCollapsibleControl, { label: "Runtime Globals", defaultCollapsed: false, children: /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
8772
|
+
/* @__PURE__ */ jsx(SidebarControl, { label: "Theme", children: /* @__PURE__ */ jsx(
|
|
8773
|
+
SidebarToggle,
|
|
8183
8774
|
{
|
|
8184
|
-
value:
|
|
8185
|
-
onChange: (value) => mock.
|
|
8186
|
-
|
|
8775
|
+
value: theme,
|
|
8776
|
+
onChange: (value) => mock.setTheme(value),
|
|
8777
|
+
options: [
|
|
8778
|
+
{ value: "light", label: "Light" },
|
|
8779
|
+
{ value: "dark", label: "Dark" }
|
|
8780
|
+
]
|
|
8187
8781
|
}
|
|
8188
8782
|
) }),
|
|
8189
|
-
/* @__PURE__ */ jsx(SidebarControl, { label: "
|
|
8190
|
-
|
|
8783
|
+
/* @__PURE__ */ jsx(SidebarControl, { label: "Display Mode", children: /* @__PURE__ */ jsx(
|
|
8784
|
+
SidebarToggle,
|
|
8191
8785
|
{
|
|
8192
|
-
|
|
8193
|
-
value: displayMode === "pip" && maxHeight !== void 0 ? String(maxHeight) : "",
|
|
8786
|
+
value: displayMode,
|
|
8194
8787
|
onChange: (value) => {
|
|
8195
|
-
|
|
8196
|
-
|
|
8788
|
+
const newMode = value;
|
|
8789
|
+
if (isMobileWidth(screenWidth) && newMode === "pip") {
|
|
8790
|
+
mock.setDisplayMode("fullscreen");
|
|
8791
|
+
} else {
|
|
8792
|
+
mock.setDisplayMode(newMode);
|
|
8197
8793
|
}
|
|
8198
8794
|
},
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
|
|
8202
|
-
|
|
8203
|
-
|
|
8204
|
-
/* @__PURE__ */ jsx(SidebarControl, { label: "User Agent - Device", children: /* @__PURE__ */ jsx(
|
|
8205
|
-
SidebarSelect,
|
|
8206
|
-
{
|
|
8207
|
-
value: (userAgent == null ? void 0 : userAgent.device.type) ?? "desktop",
|
|
8208
|
-
onChange: (value) => {
|
|
8209
|
-
const deviceType = value;
|
|
8210
|
-
let capabilities;
|
|
8211
|
-
switch (deviceType) {
|
|
8212
|
-
case "mobile":
|
|
8213
|
-
capabilities = { hover: false, touch: true };
|
|
8214
|
-
break;
|
|
8215
|
-
case "tablet":
|
|
8216
|
-
capabilities = { hover: false, touch: true };
|
|
8217
|
-
break;
|
|
8218
|
-
case "desktop":
|
|
8219
|
-
capabilities = { hover: true, touch: false };
|
|
8220
|
-
break;
|
|
8221
|
-
case "unknown":
|
|
8222
|
-
default:
|
|
8223
|
-
capabilities = { hover: true, touch: false };
|
|
8224
|
-
break;
|
|
8225
|
-
}
|
|
8226
|
-
mock.setUserAgent({
|
|
8227
|
-
...userAgent,
|
|
8228
|
-
device: { type: deviceType },
|
|
8229
|
-
capabilities
|
|
8230
|
-
});
|
|
8231
|
-
},
|
|
8232
|
-
options: [
|
|
8233
|
-
{ value: "mobile", label: "Mobile" },
|
|
8234
|
-
{ value: "tablet", label: "Tablet" },
|
|
8235
|
-
{ value: "desktop", label: "Desktop" },
|
|
8236
|
-
{ value: "unknown", label: "Unknown" }
|
|
8237
|
-
]
|
|
8238
|
-
}
|
|
8239
|
-
) }),
|
|
8240
|
-
/* @__PURE__ */ jsx("div", { className: "pl-4", children: /* @__PURE__ */ jsx(SidebarControl, { label: "Capabilities", children: /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
8241
|
-
/* @__PURE__ */ jsx(
|
|
8242
|
-
SidebarCheckbox,
|
|
8243
|
-
{
|
|
8244
|
-
checked: (userAgent == null ? void 0 : userAgent.capabilities.hover) ?? true,
|
|
8245
|
-
onChange: (checked) => mock.setUserAgent({
|
|
8246
|
-
...userAgent,
|
|
8247
|
-
device: (userAgent == null ? void 0 : userAgent.device) ?? { type: "desktop" },
|
|
8248
|
-
capabilities: {
|
|
8249
|
-
hover: checked,
|
|
8250
|
-
touch: (userAgent == null ? void 0 : userAgent.capabilities.touch) ?? false
|
|
8251
|
-
}
|
|
8252
|
-
}),
|
|
8253
|
-
label: "Hover"
|
|
8795
|
+
options: [
|
|
8796
|
+
{ value: "inline", label: "Inline" },
|
|
8797
|
+
{ value: "pip", label: "PiP" },
|
|
8798
|
+
{ value: "fullscreen", label: "Full" }
|
|
8799
|
+
]
|
|
8254
8800
|
}
|
|
8255
|
-
),
|
|
8256
|
-
/* @__PURE__ */
|
|
8257
|
-
|
|
8258
|
-
{
|
|
8259
|
-
checked: (userAgent == null ? void 0 : userAgent.capabilities.touch) ?? false,
|
|
8260
|
-
onChange: (checked) => mock.setUserAgent({
|
|
8261
|
-
...userAgent,
|
|
8262
|
-
device: (userAgent == null ? void 0 : userAgent.device) ?? { type: "desktop" },
|
|
8263
|
-
capabilities: {
|
|
8264
|
-
hover: (userAgent == null ? void 0 : userAgent.capabilities.hover) ?? true,
|
|
8265
|
-
touch: checked
|
|
8266
|
-
}
|
|
8267
|
-
}),
|
|
8268
|
-
label: "Touch"
|
|
8269
|
-
}
|
|
8270
|
-
)
|
|
8271
|
-
] }) }) }),
|
|
8272
|
-
/* @__PURE__ */ jsx(SidebarControl, { label: "Safe Area Insets", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-1", children: [
|
|
8273
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
|
|
8274
|
-
/* @__PURE__ */ jsx("label", { className: "text-[9px] text-secondary", children: "Top" }),
|
|
8275
|
-
/* @__PURE__ */ jsx(
|
|
8801
|
+
) }),
|
|
8802
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-2", children: [
|
|
8803
|
+
/* @__PURE__ */ jsx(SidebarControl, { label: "Locale", children: /* @__PURE__ */ jsx(
|
|
8276
8804
|
SidebarInput,
|
|
8277
8805
|
{
|
|
8278
|
-
|
|
8279
|
-
|
|
8280
|
-
|
|
8281
|
-
insets: {
|
|
8282
|
-
...safeArea == null ? void 0 : safeArea.insets,
|
|
8283
|
-
top: Number(value),
|
|
8284
|
-
bottom: (safeArea == null ? void 0 : safeArea.insets.bottom) ?? 0,
|
|
8285
|
-
left: (safeArea == null ? void 0 : safeArea.insets.left) ?? 0,
|
|
8286
|
-
right: (safeArea == null ? void 0 : safeArea.insets.right) ?? 0
|
|
8287
|
-
}
|
|
8288
|
-
})
|
|
8806
|
+
value: locale,
|
|
8807
|
+
onChange: (value) => mock.setLocale(value),
|
|
8808
|
+
placeholder: "e.g. en-US"
|
|
8289
8809
|
}
|
|
8290
|
-
)
|
|
8291
|
-
|
|
8292
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
|
|
8293
|
-
/* @__PURE__ */ jsx("label", { className: "text-[9px] text-secondary", children: "Bottom" }),
|
|
8294
|
-
/* @__PURE__ */ jsx(
|
|
8810
|
+
) }),
|
|
8811
|
+
/* @__PURE__ */ jsx(SidebarControl, { label: "Max Height (PiP)", children: /* @__PURE__ */ jsx(
|
|
8295
8812
|
SidebarInput,
|
|
8296
8813
|
{
|
|
8297
8814
|
type: "number",
|
|
8298
|
-
value:
|
|
8299
|
-
onChange: (value) =>
|
|
8300
|
-
|
|
8301
|
-
|
|
8302
|
-
top: (safeArea == null ? void 0 : safeArea.insets.top) ?? 0,
|
|
8303
|
-
bottom: Number(value),
|
|
8304
|
-
left: (safeArea == null ? void 0 : safeArea.insets.left) ?? 0,
|
|
8305
|
-
right: (safeArea == null ? void 0 : safeArea.insets.right) ?? 0
|
|
8815
|
+
value: displayMode === "pip" && maxHeight !== void 0 ? String(maxHeight) : "",
|
|
8816
|
+
onChange: (value) => {
|
|
8817
|
+
if (displayMode === "pip") {
|
|
8818
|
+
mock.setMaxHeight(value ? Number(value) : 480);
|
|
8306
8819
|
}
|
|
8307
|
-
}
|
|
8820
|
+
},
|
|
8821
|
+
placeholder: displayMode === "pip" ? "480" : "-",
|
|
8822
|
+
disabled: displayMode !== "pip"
|
|
8308
8823
|
}
|
|
8309
|
-
)
|
|
8824
|
+
) })
|
|
8310
8825
|
] }),
|
|
8311
|
-
/* @__PURE__ */
|
|
8312
|
-
|
|
8826
|
+
/* @__PURE__ */ jsx(SidebarControl, { label: "User Agent - Device", children: /* @__PURE__ */ jsx(
|
|
8827
|
+
SidebarSelect,
|
|
8828
|
+
{
|
|
8829
|
+
value: (userAgent == null ? void 0 : userAgent.device.type) ?? "desktop",
|
|
8830
|
+
onChange: (value) => {
|
|
8831
|
+
const deviceType = value;
|
|
8832
|
+
let capabilities;
|
|
8833
|
+
switch (deviceType) {
|
|
8834
|
+
case "mobile":
|
|
8835
|
+
capabilities = { hover: false, touch: true };
|
|
8836
|
+
break;
|
|
8837
|
+
case "tablet":
|
|
8838
|
+
capabilities = { hover: false, touch: true };
|
|
8839
|
+
break;
|
|
8840
|
+
case "desktop":
|
|
8841
|
+
capabilities = { hover: true, touch: false };
|
|
8842
|
+
break;
|
|
8843
|
+
case "unknown":
|
|
8844
|
+
default:
|
|
8845
|
+
capabilities = { hover: true, touch: false };
|
|
8846
|
+
break;
|
|
8847
|
+
}
|
|
8848
|
+
mock.setUserAgent({
|
|
8849
|
+
...userAgent,
|
|
8850
|
+
device: { type: deviceType },
|
|
8851
|
+
capabilities
|
|
8852
|
+
});
|
|
8853
|
+
},
|
|
8854
|
+
options: [
|
|
8855
|
+
{ value: "mobile", label: "Mobile" },
|
|
8856
|
+
{ value: "tablet", label: "Tablet" },
|
|
8857
|
+
{ value: "desktop", label: "Desktop" },
|
|
8858
|
+
{ value: "unknown", label: "Unknown" }
|
|
8859
|
+
]
|
|
8860
|
+
}
|
|
8861
|
+
) }),
|
|
8862
|
+
/* @__PURE__ */ jsx("div", { className: "pl-4", children: /* @__PURE__ */ jsx(SidebarControl, { label: "Capabilities", children: /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
8313
8863
|
/* @__PURE__ */ jsx(
|
|
8314
|
-
|
|
8864
|
+
SidebarCheckbox,
|
|
8315
8865
|
{
|
|
8316
|
-
|
|
8317
|
-
|
|
8318
|
-
|
|
8319
|
-
|
|
8320
|
-
|
|
8321
|
-
|
|
8322
|
-
|
|
8323
|
-
left: Number(value),
|
|
8324
|
-
right: (safeArea == null ? void 0 : safeArea.insets.right) ?? 0
|
|
8866
|
+
checked: (userAgent == null ? void 0 : userAgent.capabilities.hover) ?? true,
|
|
8867
|
+
onChange: (checked) => mock.setUserAgent({
|
|
8868
|
+
...userAgent,
|
|
8869
|
+
device: (userAgent == null ? void 0 : userAgent.device) ?? { type: "desktop" },
|
|
8870
|
+
capabilities: {
|
|
8871
|
+
hover: checked,
|
|
8872
|
+
touch: (userAgent == null ? void 0 : userAgent.capabilities.touch) ?? false
|
|
8325
8873
|
}
|
|
8326
|
-
})
|
|
8874
|
+
}),
|
|
8875
|
+
label: "Hover"
|
|
8327
8876
|
}
|
|
8328
|
-
)
|
|
8329
|
-
] }),
|
|
8330
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
|
|
8331
|
-
/* @__PURE__ */ jsx("label", { className: "text-[9px] text-secondary", children: "Right" }),
|
|
8877
|
+
),
|
|
8332
8878
|
/* @__PURE__ */ jsx(
|
|
8333
|
-
|
|
8879
|
+
SidebarCheckbox,
|
|
8334
8880
|
{
|
|
8335
|
-
|
|
8336
|
-
|
|
8337
|
-
|
|
8338
|
-
|
|
8339
|
-
|
|
8340
|
-
|
|
8341
|
-
|
|
8342
|
-
left: (safeArea == null ? void 0 : safeArea.insets.left) ?? 0,
|
|
8343
|
-
right: Number(value)
|
|
8881
|
+
checked: (userAgent == null ? void 0 : userAgent.capabilities.touch) ?? false,
|
|
8882
|
+
onChange: (checked) => mock.setUserAgent({
|
|
8883
|
+
...userAgent,
|
|
8884
|
+
device: (userAgent == null ? void 0 : userAgent.device) ?? { type: "desktop" },
|
|
8885
|
+
capabilities: {
|
|
8886
|
+
hover: (userAgent == null ? void 0 : userAgent.capabilities.hover) ?? true,
|
|
8887
|
+
touch: checked
|
|
8344
8888
|
}
|
|
8345
|
-
})
|
|
8889
|
+
}),
|
|
8890
|
+
label: "Touch"
|
|
8346
8891
|
}
|
|
8347
8892
|
)
|
|
8348
|
-
] })
|
|
8893
|
+
] }) }) }),
|
|
8894
|
+
/* @__PURE__ */ jsx(SidebarControl, { label: "Safe Area Insets", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-4 gap-1", children: [
|
|
8895
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-0.5", children: [
|
|
8896
|
+
/* @__PURE__ */ jsx("span", { className: "text-[10px] text-secondary", children: "↑" }),
|
|
8897
|
+
/* @__PURE__ */ jsx(
|
|
8898
|
+
SidebarInput,
|
|
8899
|
+
{
|
|
8900
|
+
type: "number",
|
|
8901
|
+
value: String((safeArea == null ? void 0 : safeArea.insets.top) ?? 0),
|
|
8902
|
+
onChange: (value) => mock.setSafeArea({
|
|
8903
|
+
insets: {
|
|
8904
|
+
...safeArea == null ? void 0 : safeArea.insets,
|
|
8905
|
+
top: Number(value),
|
|
8906
|
+
bottom: (safeArea == null ? void 0 : safeArea.insets.bottom) ?? 0,
|
|
8907
|
+
left: (safeArea == null ? void 0 : safeArea.insets.left) ?? 0,
|
|
8908
|
+
right: (safeArea == null ? void 0 : safeArea.insets.right) ?? 0
|
|
8909
|
+
}
|
|
8910
|
+
})
|
|
8911
|
+
}
|
|
8912
|
+
)
|
|
8913
|
+
] }),
|
|
8914
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-0.5", children: [
|
|
8915
|
+
/* @__PURE__ */ jsx("span", { className: "text-[10px] text-secondary", children: "↓" }),
|
|
8916
|
+
/* @__PURE__ */ jsx(
|
|
8917
|
+
SidebarInput,
|
|
8918
|
+
{
|
|
8919
|
+
type: "number",
|
|
8920
|
+
value: String((safeArea == null ? void 0 : safeArea.insets.bottom) ?? 0),
|
|
8921
|
+
onChange: (value) => mock.setSafeArea({
|
|
8922
|
+
insets: {
|
|
8923
|
+
...safeArea == null ? void 0 : safeArea.insets,
|
|
8924
|
+
top: (safeArea == null ? void 0 : safeArea.insets.top) ?? 0,
|
|
8925
|
+
bottom: Number(value),
|
|
8926
|
+
left: (safeArea == null ? void 0 : safeArea.insets.left) ?? 0,
|
|
8927
|
+
right: (safeArea == null ? void 0 : safeArea.insets.right) ?? 0
|
|
8928
|
+
}
|
|
8929
|
+
})
|
|
8930
|
+
}
|
|
8931
|
+
)
|
|
8932
|
+
] }),
|
|
8933
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-0.5", children: [
|
|
8934
|
+
/* @__PURE__ */ jsx("span", { className: "text-[10px] text-secondary", children: "←" }),
|
|
8935
|
+
/* @__PURE__ */ jsx(
|
|
8936
|
+
SidebarInput,
|
|
8937
|
+
{
|
|
8938
|
+
type: "number",
|
|
8939
|
+
value: String((safeArea == null ? void 0 : safeArea.insets.left) ?? 0),
|
|
8940
|
+
onChange: (value) => mock.setSafeArea({
|
|
8941
|
+
insets: {
|
|
8942
|
+
...safeArea == null ? void 0 : safeArea.insets,
|
|
8943
|
+
top: (safeArea == null ? void 0 : safeArea.insets.top) ?? 0,
|
|
8944
|
+
bottom: (safeArea == null ? void 0 : safeArea.insets.bottom) ?? 0,
|
|
8945
|
+
left: Number(value),
|
|
8946
|
+
right: (safeArea == null ? void 0 : safeArea.insets.right) ?? 0
|
|
8947
|
+
}
|
|
8948
|
+
})
|
|
8949
|
+
}
|
|
8950
|
+
)
|
|
8951
|
+
] }),
|
|
8952
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-0.5", children: [
|
|
8953
|
+
/* @__PURE__ */ jsx("span", { className: "text-[10px] text-secondary", children: "→" }),
|
|
8954
|
+
/* @__PURE__ */ jsx(
|
|
8955
|
+
SidebarInput,
|
|
8956
|
+
{
|
|
8957
|
+
type: "number",
|
|
8958
|
+
value: String((safeArea == null ? void 0 : safeArea.insets.right) ?? 0),
|
|
8959
|
+
onChange: (value) => mock.setSafeArea({
|
|
8960
|
+
insets: {
|
|
8961
|
+
...safeArea == null ? void 0 : safeArea.insets,
|
|
8962
|
+
top: (safeArea == null ? void 0 : safeArea.insets.top) ?? 0,
|
|
8963
|
+
bottom: (safeArea == null ? void 0 : safeArea.insets.bottom) ?? 0,
|
|
8964
|
+
left: (safeArea == null ? void 0 : safeArea.insets.left) ?? 0,
|
|
8965
|
+
right: Number(value)
|
|
8966
|
+
}
|
|
8967
|
+
})
|
|
8968
|
+
}
|
|
8969
|
+
)
|
|
8970
|
+
] })
|
|
8971
|
+
] }) }),
|
|
8972
|
+
/* @__PURE__ */ jsx(SidebarControl, { label: "View Mode", children: /* @__PURE__ */ jsx(
|
|
8973
|
+
SidebarSelect,
|
|
8974
|
+
{
|
|
8975
|
+
value: (view == null ? void 0 : view.mode) ?? "default",
|
|
8976
|
+
onChange: (value) => mock.setView(
|
|
8977
|
+
value === "default" ? null : {
|
|
8978
|
+
mode: value,
|
|
8979
|
+
params: view == null ? void 0 : view.params
|
|
8980
|
+
}
|
|
8981
|
+
),
|
|
8982
|
+
options: [
|
|
8983
|
+
{ value: "default", label: "Default (null)" },
|
|
8984
|
+
{ value: "modal", label: "Modal" }
|
|
8985
|
+
]
|
|
8986
|
+
}
|
|
8987
|
+
) }),
|
|
8988
|
+
view && view.mode !== "default" && /* @__PURE__ */ jsx(SidebarControl, { label: "View Params (JSON)", children: /* @__PURE__ */ jsx(
|
|
8989
|
+
SidebarTextarea,
|
|
8990
|
+
{
|
|
8991
|
+
value: viewParamsJson,
|
|
8992
|
+
onChange: (json) => validateJSON(json, setViewParamsJson, setViewParamsError),
|
|
8993
|
+
onFocus: () => setEditingField("viewParams"),
|
|
8994
|
+
onBlur: () => commitJSON(viewParamsJson, setViewParamsError, (parsed) => {
|
|
8995
|
+
if (view) {
|
|
8996
|
+
mock.setView({ ...view, params: parsed ?? void 0 });
|
|
8997
|
+
}
|
|
8998
|
+
}),
|
|
8999
|
+
error: viewParamsError,
|
|
9000
|
+
maxRows: 2
|
|
9001
|
+
}
|
|
9002
|
+
) }),
|
|
9003
|
+
/* @__PURE__ */ jsx(SidebarCollapsibleControl, { label: "Widget State (JSON)", defaultCollapsed: false, children: /* @__PURE__ */ jsx(
|
|
9004
|
+
SidebarTextarea,
|
|
9005
|
+
{
|
|
9006
|
+
value: widgetStateJson,
|
|
9007
|
+
onChange: (json) => validateJSON(json, setWidgetStateJson, setWidgetStateError),
|
|
9008
|
+
onFocus: () => setEditingField("widgetState"),
|
|
9009
|
+
onBlur: () => commitJSON(
|
|
9010
|
+
widgetStateJson,
|
|
9011
|
+
setWidgetStateError,
|
|
9012
|
+
(parsed) => mock.setWidgetStateExternal(parsed)
|
|
9013
|
+
),
|
|
9014
|
+
error: widgetStateError,
|
|
9015
|
+
maxRows: 8
|
|
9016
|
+
}
|
|
9017
|
+
) })
|
|
8349
9018
|
] }) }),
|
|
8350
|
-
/* @__PURE__ */ jsx(SidebarControl, { label: "View Mode", children: /* @__PURE__ */ jsx(
|
|
8351
|
-
SidebarSelect,
|
|
8352
|
-
{
|
|
8353
|
-
value: (view == null ? void 0 : view.mode) ?? "default",
|
|
8354
|
-
onChange: (value) => mock.setView(
|
|
8355
|
-
value === "default" ? null : {
|
|
8356
|
-
mode: value,
|
|
8357
|
-
params: view == null ? void 0 : view.params
|
|
8358
|
-
}
|
|
8359
|
-
),
|
|
8360
|
-
options: [
|
|
8361
|
-
{ value: "default", label: "Default (null)" },
|
|
8362
|
-
{ value: "modal", label: "Modal" }
|
|
8363
|
-
]
|
|
8364
|
-
}
|
|
8365
|
-
) }),
|
|
8366
|
-
view && view.mode !== "default" && /* @__PURE__ */ jsx(SidebarControl, { label: "View Params (JSON)", children: /* @__PURE__ */ jsx(
|
|
8367
|
-
SidebarTextarea,
|
|
8368
|
-
{
|
|
8369
|
-
value: viewParamsJson,
|
|
8370
|
-
onChange: (json) => validateJSON(json, setViewParamsJson, setViewParamsError),
|
|
8371
|
-
onFocus: () => setEditingField("viewParams"),
|
|
8372
|
-
onBlur: () => commitJSON(viewParamsJson, setViewParamsError, (parsed) => {
|
|
8373
|
-
if (view) {
|
|
8374
|
-
mock.setView({ ...view, params: parsed ?? void 0 });
|
|
8375
|
-
}
|
|
8376
|
-
}),
|
|
8377
|
-
error: viewParamsError,
|
|
8378
|
-
rows: 2
|
|
8379
|
-
}
|
|
8380
|
-
) }),
|
|
8381
9019
|
/* @__PURE__ */ jsx(SidebarCollapsibleControl, { label: "Tool Input (JSON)", children: /* @__PURE__ */ jsx(
|
|
8382
9020
|
SidebarTextarea,
|
|
8383
9021
|
{
|
|
@@ -8390,7 +9028,7 @@ function ChatGPTSimulator({
|
|
|
8390
9028
|
(parsed) => mock.setToolInput(parsed ?? {})
|
|
8391
9029
|
),
|
|
8392
9030
|
error: toolInputError,
|
|
8393
|
-
|
|
9031
|
+
maxRows: 8
|
|
8394
9032
|
}
|
|
8395
9033
|
) }),
|
|
8396
9034
|
/* @__PURE__ */ jsx(SidebarCollapsibleControl, { label: "Tool Output (JSON)", children: /* @__PURE__ */ jsx(
|
|
@@ -8405,7 +9043,7 @@ function ChatGPTSimulator({
|
|
|
8405
9043
|
(parsed) => mock.setToolOutput(parsed)
|
|
8406
9044
|
),
|
|
8407
9045
|
error: toolOutputError,
|
|
8408
|
-
|
|
9046
|
+
maxRows: 8
|
|
8409
9047
|
}
|
|
8410
9048
|
) }),
|
|
8411
9049
|
/* @__PURE__ */ jsx(SidebarCollapsibleControl, { label: "Tool Response Metadata (JSON)", children: /* @__PURE__ */ jsx(
|
|
@@ -8420,22 +9058,7 @@ function ChatGPTSimulator({
|
|
|
8420
9058
|
(parsed) => mock.setToolResponseMetadata(parsed)
|
|
8421
9059
|
),
|
|
8422
9060
|
error: toolResponseMetadataError,
|
|
8423
|
-
|
|
8424
|
-
}
|
|
8425
|
-
) }),
|
|
8426
|
-
/* @__PURE__ */ jsx(SidebarCollapsibleControl, { label: "Widget State (JSON)", children: /* @__PURE__ */ jsx(
|
|
8427
|
-
SidebarTextarea,
|
|
8428
|
-
{
|
|
8429
|
-
value: widgetStateJson,
|
|
8430
|
-
onChange: (json) => validateJSON(json, setWidgetStateJson, setWidgetStateError),
|
|
8431
|
-
onFocus: () => setEditingField("widgetState"),
|
|
8432
|
-
onBlur: () => commitJSON(
|
|
8433
|
-
widgetStateJson,
|
|
8434
|
-
setWidgetStateError,
|
|
8435
|
-
(parsed) => mock.setWidgetStateExternal(parsed)
|
|
8436
|
-
),
|
|
8437
|
-
error: widgetStateError,
|
|
8438
|
-
rows: 8
|
|
9061
|
+
maxRows: 8
|
|
8439
9062
|
}
|
|
8440
9063
|
) })
|
|
8441
9064
|
] }),
|
|
@@ -8447,6 +9070,7 @@ function ChatGPTSimulator({
|
|
|
8447
9070
|
appIcon,
|
|
8448
9071
|
userMessage,
|
|
8449
9072
|
resourceMeta: selectedSim == null ? void 0 : selectedSim.resource._meta,
|
|
9073
|
+
iframeScriptSrc,
|
|
8450
9074
|
children: content
|
|
8451
9075
|
},
|
|
8452
9076
|
selectedSimulationName
|
|
@@ -8500,6 +9124,7 @@ function createSimulatorUrl(params, basePath = "/") {
|
|
|
8500
9124
|
}
|
|
8501
9125
|
export {
|
|
8502
9126
|
ChatGPTSimulator as C,
|
|
9127
|
+
IframeResource as I,
|
|
8503
9128
|
SCREEN_WIDTHS as S,
|
|
8504
9129
|
ThemeProvider as T,
|
|
8505
9130
|
clsx as a,
|
|
@@ -8526,4 +9151,4 @@ export {
|
|
|
8526
9151
|
getAPI as v,
|
|
8527
9152
|
resetProviderCache as w
|
|
8528
9153
|
};
|
|
8529
|
-
//# sourceMappingURL=simulator-url-
|
|
9154
|
+
//# sourceMappingURL=simulator-url-q5tHLc4-.js.map
|