sunpeak 0.16.27 → 0.16.28
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/bin/commands/build.mjs +0 -1
- package/dist/chatgpt/globals.css +10 -9
- package/dist/chatgpt/index.cjs +55 -24
- package/dist/chatgpt/index.cjs.map +1 -1
- package/dist/chatgpt/index.js +31 -25
- package/dist/chatgpt/index.js.map +1 -1
- package/dist/chunk-9hOWP6kD.cjs +64 -0
- package/dist/chunk-D6g4UhsZ.js +35 -0
- package/dist/claude/index.cjs +4 -4
- package/dist/claude/index.js +3 -5
- package/dist/discovery-BxKCIgG5.cjs +332 -0
- package/dist/discovery-BxKCIgG5.cjs.map +1 -0
- package/dist/discovery-Du4LHrih.js +261 -0
- package/dist/discovery-Du4LHrih.js.map +1 -0
- package/dist/host/chatgpt/index.cjs +171 -65
- package/dist/host/chatgpt/index.cjs.map +1 -1
- package/dist/host/chatgpt/index.js +170 -70
- package/dist/host/chatgpt/index.js.map +1 -1
- package/dist/host/index.cjs +47 -19
- package/dist/host/index.cjs.map +1 -1
- package/dist/host/index.js +47 -24
- package/dist/host/index.js.map +1 -1
- package/dist/index.cjs +3103 -3725
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3026 -3746
- package/dist/index.js.map +1 -1
- package/dist/lib/discovery-cli.cjs +117 -131
- package/dist/lib/discovery-cli.cjs.map +1 -1
- package/dist/lib/discovery-cli.js +107 -111
- package/dist/lib/discovery-cli.js.map +1 -1
- package/dist/mcp/index.cjs +9818 -10283
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.js +9799 -10282
- package/dist/mcp/index.js.map +1 -1
- package/dist/protocol-DJmRaBzO.js +11080 -0
- package/dist/{protocol-DkDHRwOW.cjs.map → protocol-DJmRaBzO.js.map} +1 -1
- package/dist/protocol-jbxhzcnS.cjs +11493 -0
- package/dist/protocol-jbxhzcnS.cjs.map +1 -0
- package/dist/simulator/index.cjs +79 -36
- package/dist/simulator/index.cjs.map +1 -1
- package/dist/simulator/index.js +43 -37
- package/dist/simulator/index.js.map +1 -1
- package/dist/simulator-BYIH-xqQ.cjs +3701 -0
- package/dist/{simulator-Gc6n_fT4.cjs.map → simulator-BYIH-xqQ.cjs.map} +1 -1
- package/dist/simulator-CmgNnWBO.js +3575 -0
- package/dist/simulator-CmgNnWBO.js.map +1 -0
- package/dist/simulator-url-BDGD4vZD.cjs +69 -0
- package/dist/simulator-url-BDGD4vZD.cjs.map +1 -0
- package/dist/simulator-url-Bkxj43yT.js +64 -0
- package/dist/simulator-url-Bkxj43yT.js.map +1 -0
- package/dist/style.css +10 -9
- package/dist/use-app-D2h-aiyr.cjs +940 -0
- package/dist/use-app-D2h-aiyr.cjs.map +1 -0
- package/dist/use-app-X7JbGskk.js +598 -0
- package/dist/use-app-X7JbGskk.js.map +1 -0
- package/package.json +8 -8
- package/template/node_modules/.bin/vite +2 -2
- package/template/node_modules/.bin/vitest +2 -2
- package/template/package.json +5 -5
- package/dist/claude/index.cjs.map +0 -1
- package/dist/claude/index.js.map +0 -1
- package/dist/discovery-BVqD-JsT.js +0 -224
- package/dist/discovery-BVqD-JsT.js.map +0 -1
- package/dist/discovery-D1gpaVz4.cjs +0 -223
- package/dist/discovery-D1gpaVz4.cjs.map +0 -1
- package/dist/index-BEWVLFfB.cjs +0 -28
- package/dist/index-BEWVLFfB.cjs.map +0 -1
- package/dist/index-C6XYFOmh.js +0 -29
- package/dist/index-C6XYFOmh.js.map +0 -1
- package/dist/index-D0FsXP3Y.cjs +0 -40
- package/dist/index-D0FsXP3Y.cjs.map +0 -1
- package/dist/index-Rg7SWjvl.js +0 -41
- package/dist/index-Rg7SWjvl.js.map +0 -1
- package/dist/protocol-DkDHRwOW.cjs +0 -12221
- package/dist/protocol-uge7qFev.js +0 -12223
- package/dist/protocol-uge7qFev.js.map +0 -1
- package/dist/simulator-B-CrMHVs.js +0 -3534
- package/dist/simulator-B-CrMHVs.js.map +0 -1
- package/dist/simulator-Gc6n_fT4.cjs +0 -3549
- package/dist/simulator-url-DcSYRl-P.cjs +0 -53
- package/dist/simulator-url-DcSYRl-P.cjs.map +0 -1
- package/dist/simulator-url-j_XV3EoP.js +0 -54
- package/dist/simulator-url-j_XV3EoP.js.map +0 -1
- package/dist/use-app-C9gpzIQO.js +0 -349
- package/dist/use-app-C9gpzIQO.js.map +0 -1
- package/dist/use-app-D09O2swh.cjs +0 -348
- package/dist/use-app-D09O2swh.cjs.map +0 -1
|
@@ -1,3549 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
-
const React = require("react");
|
|
4
|
-
const protocol = require("./protocol-DkDHRwOW.cjs");
|
|
5
|
-
function _interopNamespaceDefault(e) {
|
|
6
|
-
const n2 = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
7
|
-
if (e) {
|
|
8
|
-
for (const k in e) {
|
|
9
|
-
if (k !== "default") {
|
|
10
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
-
Object.defineProperty(n2, k, d.get ? d : {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: () => e[k]
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
n2.default = e;
|
|
19
|
-
return Object.freeze(n2);
|
|
20
|
-
}
|
|
21
|
-
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
22
|
-
const DEFAULT_STYLE_VARIABLES = {
|
|
23
|
-
// Background colors
|
|
24
|
-
"--color-background-primary": "light-dark(#ffffff, #1a1a1a)",
|
|
25
|
-
"--color-background-secondary": "light-dark(#f5f5f5, #2d2d2d)",
|
|
26
|
-
"--color-background-tertiary": "light-dark(#e5e5e5, #404040)",
|
|
27
|
-
"--color-background-inverse": "light-dark(#1a1a1a, #ffffff)",
|
|
28
|
-
"--color-background-ghost": "light-dark(rgba(255,255,255,0), rgba(26,26,26,0))",
|
|
29
|
-
"--color-background-info": "light-dark(#eff6ff, #1e3a5f)",
|
|
30
|
-
"--color-background-danger": "light-dark(#fef2f2, #7f1d1d)",
|
|
31
|
-
"--color-background-success": "light-dark(#f0fdf4, #14532d)",
|
|
32
|
-
"--color-background-warning": "light-dark(#fefce8, #713f12)",
|
|
33
|
-
"--color-background-disabled": "light-dark(rgba(255,255,255,0.5), rgba(26,26,26,0.5))",
|
|
34
|
-
// Text colors
|
|
35
|
-
"--color-text-primary": "light-dark(#1f2937, #f3f4f6)",
|
|
36
|
-
"--color-text-secondary": "light-dark(#6b7280, #9ca3af)",
|
|
37
|
-
"--color-text-tertiary": "light-dark(#9ca3af, #6b7280)",
|
|
38
|
-
"--color-text-inverse": "light-dark(#f3f4f6, #1f2937)",
|
|
39
|
-
"--color-text-ghost": "light-dark(rgba(107,114,128,0.5), rgba(156,163,175,0.5))",
|
|
40
|
-
"--color-text-info": "light-dark(#1d4ed8, #60a5fa)",
|
|
41
|
-
"--color-text-danger": "light-dark(#b91c1c, #f87171)",
|
|
42
|
-
"--color-text-success": "light-dark(#15803d, #4ade80)",
|
|
43
|
-
"--color-text-warning": "light-dark(#a16207, #fbbf24)",
|
|
44
|
-
"--color-text-disabled": "light-dark(rgba(31,41,55,0.5), rgba(243,244,246,0.5))",
|
|
45
|
-
// Border colors
|
|
46
|
-
"--color-border-primary": "light-dark(#e5e7eb, #404040)",
|
|
47
|
-
"--color-border-secondary": "light-dark(#d1d5db, #525252)",
|
|
48
|
-
"--color-border-tertiary": "light-dark(#f3f4f6, #374151)",
|
|
49
|
-
"--color-border-inverse": "light-dark(rgba(255,255,255,0.3), rgba(0,0,0,0.3))",
|
|
50
|
-
"--color-border-ghost": "light-dark(rgba(229,231,235,0), rgba(64,64,64,0))",
|
|
51
|
-
"--color-border-info": "light-dark(#93c5fd, #1e40af)",
|
|
52
|
-
"--color-border-danger": "light-dark(#fca5a5, #991b1b)",
|
|
53
|
-
"--color-border-success": "light-dark(#86efac, #166534)",
|
|
54
|
-
"--color-border-warning": "light-dark(#fde047, #854d0e)",
|
|
55
|
-
"--color-border-disabled": "light-dark(rgba(229,231,235,0.5), rgba(64,64,64,0.5))",
|
|
56
|
-
// Ring colors (focus)
|
|
57
|
-
"--color-ring-primary": "light-dark(#3b82f6, #60a5fa)",
|
|
58
|
-
"--color-ring-secondary": "light-dark(#6b7280, #9ca3af)",
|
|
59
|
-
"--color-ring-inverse": "light-dark(#ffffff, #1f2937)",
|
|
60
|
-
"--color-ring-info": "light-dark(#2563eb, #3b82f6)",
|
|
61
|
-
"--color-ring-danger": "light-dark(#dc2626, #ef4444)",
|
|
62
|
-
"--color-ring-success": "light-dark(#16a34a, #22c55e)",
|
|
63
|
-
"--color-ring-warning": "light-dark(#ca8a04, #eab308)",
|
|
64
|
-
// Typography — Family
|
|
65
|
-
"--font-sans": "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
66
|
-
"--font-mono": "ui-monospace, 'SF Mono', Monaco, 'Cascadia Code', monospace",
|
|
67
|
-
// Typography — Weight
|
|
68
|
-
"--font-weight-normal": "400",
|
|
69
|
-
"--font-weight-medium": "500",
|
|
70
|
-
"--font-weight-semibold": "600",
|
|
71
|
-
"--font-weight-bold": "700",
|
|
72
|
-
// Typography — Text Size
|
|
73
|
-
"--font-text-xs-size": "0.75rem",
|
|
74
|
-
"--font-text-sm-size": "0.875rem",
|
|
75
|
-
"--font-text-md-size": "1rem",
|
|
76
|
-
"--font-text-lg-size": "1.125rem",
|
|
77
|
-
// Typography — Heading Size
|
|
78
|
-
"--font-heading-xs-size": "0.75rem",
|
|
79
|
-
"--font-heading-sm-size": "0.875rem",
|
|
80
|
-
"--font-heading-md-size": "1rem",
|
|
81
|
-
"--font-heading-lg-size": "1.25rem",
|
|
82
|
-
"--font-heading-xl-size": "1.5rem",
|
|
83
|
-
"--font-heading-2xl-size": "1.875rem",
|
|
84
|
-
"--font-heading-3xl-size": "2.25rem",
|
|
85
|
-
// Typography — Text Line Height
|
|
86
|
-
"--font-text-xs-line-height": "1.4",
|
|
87
|
-
"--font-text-sm-line-height": "1.4",
|
|
88
|
-
"--font-text-md-line-height": "1.5",
|
|
89
|
-
"--font-text-lg-line-height": "1.5",
|
|
90
|
-
// Typography — Heading Line Height
|
|
91
|
-
"--font-heading-xs-line-height": "1.4",
|
|
92
|
-
"--font-heading-sm-line-height": "1.4",
|
|
93
|
-
"--font-heading-md-line-height": "1.4",
|
|
94
|
-
"--font-heading-lg-line-height": "1.3",
|
|
95
|
-
"--font-heading-xl-line-height": "1.25",
|
|
96
|
-
"--font-heading-2xl-line-height": "1.2",
|
|
97
|
-
"--font-heading-3xl-line-height": "1.1",
|
|
98
|
-
// Border radius
|
|
99
|
-
"--border-radius-xs": "2px",
|
|
100
|
-
"--border-radius-sm": "4px",
|
|
101
|
-
"--border-radius-md": "6px",
|
|
102
|
-
"--border-radius-lg": "8px",
|
|
103
|
-
"--border-radius-xl": "12px",
|
|
104
|
-
"--border-radius-full": "9999px",
|
|
105
|
-
// Border width
|
|
106
|
-
"--border-width-regular": "1px",
|
|
107
|
-
// Shadows
|
|
108
|
-
"--shadow-hairline": "0 1px 2px 0 rgba(0, 0, 0, 0.05)",
|
|
109
|
-
"--shadow-sm": "0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1)",
|
|
110
|
-
"--shadow-md": "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)",
|
|
111
|
-
"--shadow-lg": "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)"
|
|
112
|
-
};
|
|
113
|
-
const registry = /* @__PURE__ */ new Map();
|
|
114
|
-
function registerHostShell(shell) {
|
|
115
|
-
registry.set(shell.id, shell);
|
|
116
|
-
}
|
|
117
|
-
function getHostShell(id) {
|
|
118
|
-
return registry.get(id);
|
|
119
|
-
}
|
|
120
|
-
function getRegisteredHosts() {
|
|
121
|
-
return Array.from(registry.values());
|
|
122
|
-
}
|
|
123
|
-
const SCREEN_WIDTHS = {
|
|
124
|
-
"mobile-s": 375,
|
|
125
|
-
"mobile-l": 425,
|
|
126
|
-
tablet: 768,
|
|
127
|
-
full: 1024
|
|
128
|
-
};
|
|
129
|
-
function CloseIcon$1({ className }) {
|
|
130
|
-
return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "1em", height: "1em", viewBox: "0 0 24 24", fill: "currentColor", className, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
131
|
-
"path",
|
|
132
|
-
{
|
|
133
|
-
fillRule: "evenodd",
|
|
134
|
-
clipRule: "evenodd",
|
|
135
|
-
d: "M5.83071 5.83077C6.33839 5.32309 7.16151 5.32309 7.66919 5.83077L12 10.1615L16.3307 5.83077C16.8384 5.32309 17.6615 5.32309 18.1692 5.83077C18.6769 6.33845 18.6769 7.16157 18.1692 7.66925L13.8384 12L18.1692 16.3308C18.6769 16.8385 18.6769 17.6616 18.1692 18.1693C17.6615 18.6769 16.8384 18.6769 16.3307 18.1693L12 13.8385L7.66919 18.1693C7.16151 18.6769 6.33839 18.6769 5.83071 18.1693C5.32303 17.6616 5.32303 16.8385 5.83071 16.3308L10.1615 12L5.83071 7.66925C5.32303 7.16157 5.32303 6.33845 5.83071 5.83077Z"
|
|
136
|
-
}
|
|
137
|
-
) });
|
|
138
|
-
}
|
|
139
|
-
function Conversation({
|
|
140
|
-
children,
|
|
141
|
-
screenWidth,
|
|
142
|
-
displayMode,
|
|
143
|
-
platform,
|
|
144
|
-
onRequestDisplayMode,
|
|
145
|
-
appName = "Sunpeak",
|
|
146
|
-
appIcon,
|
|
147
|
-
userMessage = "What have you got for me today?",
|
|
148
|
-
headerAction,
|
|
149
|
-
onContentWidthChange
|
|
150
|
-
}) {
|
|
151
|
-
const isDesktop = platform === "desktop";
|
|
152
|
-
const containerWidth = screenWidth === "full" ? "100%" : `${SCREEN_WIDTHS[screenWidth]}px`;
|
|
153
|
-
const isFullscreen = displayMode === "fullscreen";
|
|
154
|
-
const isPip = displayMode === "pip";
|
|
155
|
-
const contentRef = React.useRef(null);
|
|
156
|
-
const onContentWidthChangeRef = React.useRef(onContentWidthChange);
|
|
157
|
-
React.useEffect(() => {
|
|
158
|
-
onContentWidthChangeRef.current = onContentWidthChange;
|
|
159
|
-
});
|
|
160
|
-
const setContentRef = React.useCallback((node) => {
|
|
161
|
-
contentRef.current = node;
|
|
162
|
-
}, []);
|
|
163
|
-
React.useEffect(() => {
|
|
164
|
-
const el = contentRef.current;
|
|
165
|
-
if (!el) return;
|
|
166
|
-
const observer = new ResizeObserver((entries) => {
|
|
167
|
-
for (const entry of entries) {
|
|
168
|
-
const width = Math.round(entry.contentBoxSize[0]?.inlineSize ?? entry.contentRect.width);
|
|
169
|
-
if (width > 0) {
|
|
170
|
-
onContentWidthChangeRef.current?.(width);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
observer.observe(el);
|
|
175
|
-
return () => observer.disconnect();
|
|
176
|
-
}, []);
|
|
177
|
-
const handleClose = () => onRequestDisplayMode?.("inline");
|
|
178
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
179
|
-
"div",
|
|
180
|
-
{
|
|
181
|
-
className: "flex flex-col w-full h-full flex-1 items-center relative",
|
|
182
|
-
style: {
|
|
183
|
-
transform: "translate(0)",
|
|
184
|
-
backgroundColor: "var(--sim-bg-conversation, var(--color-background-primary))",
|
|
185
|
-
color: "var(--color-text-primary)"
|
|
186
|
-
},
|
|
187
|
-
children: [
|
|
188
|
-
isFullscreen && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
189
|
-
"div",
|
|
190
|
-
{
|
|
191
|
-
className: "fixed start-0 end-0 top-0 bottom-0 z-[51] mx-auto flex flex-col pointer-events-none",
|
|
192
|
-
style: { maxWidth: containerWidth },
|
|
193
|
-
children: [
|
|
194
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
195
|
-
"div",
|
|
196
|
-
{
|
|
197
|
-
className: "z-10 grid h-[3.25rem] grid-cols-[1fr_auto_1fr] border-b px-2 pointer-events-auto",
|
|
198
|
-
style: {
|
|
199
|
-
borderColor: "var(--color-border-primary)",
|
|
200
|
-
backgroundColor: "var(--sim-bg-conversation, var(--color-background-primary))"
|
|
201
|
-
},
|
|
202
|
-
children: [
|
|
203
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-start gap-3", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
204
|
-
"button",
|
|
205
|
-
{
|
|
206
|
-
onClick: handleClose,
|
|
207
|
-
"aria-label": "Close",
|
|
208
|
-
className: "h-7 w-7 flex items-center justify-center rounded-md transition-colors hover:opacity-70",
|
|
209
|
-
type: "button",
|
|
210
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon$1, {})
|
|
211
|
-
}
|
|
212
|
-
) }),
|
|
213
|
-
isDesktop && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center text-base", children: appName }),
|
|
214
|
-
isDesktop && /* @__PURE__ */ jsxRuntime.jsx("div", {})
|
|
215
|
-
]
|
|
216
|
-
}
|
|
217
|
-
),
|
|
218
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1" }),
|
|
219
|
-
/* @__PURE__ */ jsxRuntime.jsxs("footer", { className: "relative", children: [
|
|
220
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
221
|
-
"div",
|
|
222
|
-
{
|
|
223
|
-
className: "absolute inset-x-0 bottom-0 h-full -z-10",
|
|
224
|
-
style: {
|
|
225
|
-
maskImage: "linear-gradient(to bottom, transparent 0%, black 50%)",
|
|
226
|
-
WebkitMaskImage: "linear-gradient(to bottom, transparent 0%, black 50%)",
|
|
227
|
-
backdropFilter: "blur(16px)",
|
|
228
|
-
WebkitBackdropFilter: "blur(16px)"
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
),
|
|
232
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-w-[40rem] min-[1440px]:max-w-[48rem] mx-auto px-4 pt-4 pb-4 pointer-events-auto", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
233
|
-
"input",
|
|
234
|
-
{
|
|
235
|
-
type: "text",
|
|
236
|
-
name: "userInput",
|
|
237
|
-
disabled: true,
|
|
238
|
-
placeholder: "Message sunpeak.ai",
|
|
239
|
-
className: "w-full rounded-3xl px-5 py-3 pr-12 shadow-sm",
|
|
240
|
-
style: {
|
|
241
|
-
backgroundColor: "var(--sim-bg-reply-input, var(--color-background-secondary))",
|
|
242
|
-
color: "var(--color-text-primary)",
|
|
243
|
-
border: "1px solid var(--color-border-tertiary)"
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
) }) })
|
|
247
|
-
] })
|
|
248
|
-
]
|
|
249
|
-
}
|
|
250
|
-
),
|
|
251
|
-
!isFullscreen && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
252
|
-
"header",
|
|
253
|
-
{
|
|
254
|
-
className: "h-12 flex items-center gap-3 px-4 text-lg sticky top-0 z-40 w-full",
|
|
255
|
-
style: {
|
|
256
|
-
maxWidth: containerWidth,
|
|
257
|
-
backgroundColor: "var(--sim-bg-conversation, var(--color-background-primary))"
|
|
258
|
-
},
|
|
259
|
-
children: [
|
|
260
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "sunpeak.ai" }),
|
|
261
|
-
headerAction
|
|
262
|
-
]
|
|
263
|
-
}
|
|
264
|
-
),
|
|
265
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
266
|
-
"div",
|
|
267
|
-
{
|
|
268
|
-
className: "flex flex-col flex-1 w-full transition-all duration-200 overflow-hidden",
|
|
269
|
-
style: { maxWidth: containerWidth },
|
|
270
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("main", { className: "flex-1 overflow-y-auto overflow-x-hidden flex flex-col", children: [
|
|
271
|
-
!isFullscreen && /* @__PURE__ */ jsxRuntime.jsxs("article", { className: "w-full focus:outline-none", dir: "auto", "data-turn": "user", children: [
|
|
272
|
-
/* @__PURE__ */ jsxRuntime.jsx("h5", { className: "sr-only", children: "You said:" }),
|
|
273
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-base my-auto mx-auto md:pt-8 px-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-w-[40rem] min-[1440px]:max-w-[48rem] mx-auto flex-1 relative flex w-full min-w-0 flex-col", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex max-w-full flex-col grow", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
274
|
-
"div",
|
|
275
|
-
{
|
|
276
|
-
"data-message-author-role": "user",
|
|
277
|
-
className: "min-h-8 relative flex w-full flex-col items-end gap-2 text-start break-words whitespace-normal",
|
|
278
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-col gap-1 empty:hidden items-end", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
279
|
-
"div",
|
|
280
|
-
{
|
|
281
|
-
className: "relative rounded-[18px] px-4 py-3 max-w-[70%]",
|
|
282
|
-
style: {
|
|
283
|
-
backgroundColor: "var(--sim-bg-user-bubble, var(--color-background-tertiary))"
|
|
284
|
-
},
|
|
285
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "whitespace-pre-wrap", children: userMessage })
|
|
286
|
-
}
|
|
287
|
-
) })
|
|
288
|
-
}
|
|
289
|
-
) }) }) })
|
|
290
|
-
] }),
|
|
291
|
-
/* @__PURE__ */ jsxRuntime.jsxs("article", { className: "w-full focus:outline-none flex-1", dir: "auto", "data-turn": "assistant", children: [
|
|
292
|
-
/* @__PURE__ */ jsxRuntime.jsxs("h6", { className: "sr-only", children: [
|
|
293
|
-
appName,
|
|
294
|
-
" said:"
|
|
295
|
-
] }),
|
|
296
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-base my-auto mx-auto pb-10 px-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-w-[40rem] min-[1440px]:max-w-[48rem] mx-auto flex-1 relative flex w-full min-w-0 flex-col", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex max-w-full flex-col grow", children: [
|
|
297
|
-
!isFullscreen && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 my-3", children: [
|
|
298
|
-
appIcon ? appIcon.startsWith("data:") || appIcon.startsWith("http") ? /* @__PURE__ */ jsxRuntime.jsx("img", { src: appIcon, alt: "", className: "size-6 rounded-full object-cover" }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-6 flex items-center justify-center text-base", children: appIcon }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
299
|
-
"div",
|
|
300
|
-
{
|
|
301
|
-
className: "size-6 rounded-full flex items-center justify-center font-medium text-xs text-white",
|
|
302
|
-
style: { backgroundColor: "#10a37f" },
|
|
303
|
-
children: "AI"
|
|
304
|
-
}
|
|
305
|
-
),
|
|
306
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-semibold text-sm", children: appName })
|
|
307
|
-
] }),
|
|
308
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
309
|
-
"div",
|
|
310
|
-
{
|
|
311
|
-
"data-message-author-role": "assistant",
|
|
312
|
-
className: "min-h-8 relative flex w-full flex-col items-start gap-2 text-start break-words whitespace-normal",
|
|
313
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-col gap-1 empty:hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
314
|
-
"div",
|
|
315
|
-
{
|
|
316
|
-
ref: setContentRef,
|
|
317
|
-
className: isPip ? "no-scrollbar @w-xl/main:top-4 fixed start-4 end-4 top-12 z-50 mx-auto max-w-[40rem] lg:max-w-[48rem] sm:start-0 sm:end-0 sm:top-[3.25rem] sm:w-full overflow-visible" : isFullscreen ? "no-scrollbar fixed inset-x-0 top-[3.25rem] bottom-0 z-50 mx-auto" : "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",
|
|
318
|
-
style: {
|
|
319
|
-
...isPip ? { maxHeight: "480px" } : {},
|
|
320
|
-
...isFullscreen ? { maxWidth: containerWidth } : {}
|
|
321
|
-
},
|
|
322
|
-
children: [
|
|
323
|
-
isPip && /* @__PURE__ */ jsxRuntime.jsx(
|
|
324
|
-
"button",
|
|
325
|
-
{
|
|
326
|
-
onClick: handleClose,
|
|
327
|
-
className: "absolute -start-2 -top-1.5 z-10 rounded-full bg-[#3a3a3a] p-1.5 text-white shadow-[0px_0px_0px_1px_#fff3,0px_4px_12px_rgba(0,0,0,0.12)] hover:bg-[#6a6a6a]",
|
|
328
|
-
"aria-label": "Close picture-in-picture",
|
|
329
|
-
type: "button",
|
|
330
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon$1, { className: "h-4 w-4" })
|
|
331
|
-
},
|
|
332
|
-
"pip-close"
|
|
333
|
-
),
|
|
334
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
335
|
-
"div",
|
|
336
|
-
{
|
|
337
|
-
className: isPip ? "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" : "relative overflow-hidden h-full",
|
|
338
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
339
|
-
"div",
|
|
340
|
-
{
|
|
341
|
-
className: "h-full w-full max-w-full",
|
|
342
|
-
style: {
|
|
343
|
-
...isPip ? {
|
|
344
|
-
overflow: "auto",
|
|
345
|
-
backgroundColor: "var(--color-background-primary)"
|
|
346
|
-
} : isFullscreen ? {
|
|
347
|
-
overflow: "auto",
|
|
348
|
-
backgroundColor: "var(--color-background-primary)"
|
|
349
|
-
} : { backgroundColor: "transparent" }
|
|
350
|
-
},
|
|
351
|
-
children
|
|
352
|
-
}
|
|
353
|
-
)
|
|
354
|
-
},
|
|
355
|
-
"content"
|
|
356
|
-
)
|
|
357
|
-
]
|
|
358
|
-
}
|
|
359
|
-
) })
|
|
360
|
-
}
|
|
361
|
-
)
|
|
362
|
-
] }) }) })
|
|
363
|
-
] }),
|
|
364
|
-
!isFullscreen && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sticky bottom-0 z-10 pointer-events-none", children: [
|
|
365
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
366
|
-
"div",
|
|
367
|
-
{
|
|
368
|
-
className: "absolute inset-x-0 bottom-0 h-full -z-10",
|
|
369
|
-
style: {
|
|
370
|
-
maskImage: "linear-gradient(to bottom, transparent 0%, black 50%)",
|
|
371
|
-
WebkitMaskImage: "linear-gradient(to bottom, transparent 0%, black 50%)",
|
|
372
|
-
backdropFilter: "blur(16px)",
|
|
373
|
-
WebkitBackdropFilter: "blur(16px)"
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
),
|
|
377
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-w-[40rem] min-[1440px]:max-w-[48rem] mx-auto px-4 pt-4 pb-4 pointer-events-auto", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
378
|
-
"input",
|
|
379
|
-
{
|
|
380
|
-
type: "text",
|
|
381
|
-
name: "userInput",
|
|
382
|
-
disabled: true,
|
|
383
|
-
placeholder: "Message sunpeak.ai",
|
|
384
|
-
className: "w-full rounded-3xl px-5 py-3 pr-12 shadow-sm",
|
|
385
|
-
style: {
|
|
386
|
-
backgroundColor: "var(--sim-bg-reply-input, var(--color-background-secondary))",
|
|
387
|
-
color: "var(--color-text-primary)",
|
|
388
|
-
border: "1px solid var(--color-border-tertiary)"
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
) }) })
|
|
392
|
-
] })
|
|
393
|
-
] })
|
|
394
|
-
}
|
|
395
|
-
)
|
|
396
|
-
]
|
|
397
|
-
}
|
|
398
|
-
);
|
|
399
|
-
}
|
|
400
|
-
const CHATGPT_HOST_INFO = {
|
|
401
|
-
name: "chatgpt",
|
|
402
|
-
version: "0.0.1"
|
|
403
|
-
};
|
|
404
|
-
const CHATGPT_HOST_CAPABILITIES = {
|
|
405
|
-
openLinks: {},
|
|
406
|
-
serverTools: {},
|
|
407
|
-
serverResources: {},
|
|
408
|
-
logging: {},
|
|
409
|
-
updateModelContext: {},
|
|
410
|
-
message: {},
|
|
411
|
-
sandbox: {
|
|
412
|
-
permissions: {
|
|
413
|
-
microphone: {}
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
};
|
|
417
|
-
function applyChatGPTTheme(theme) {
|
|
418
|
-
document.documentElement.setAttribute("data-theme", theme);
|
|
419
|
-
document.documentElement.style.colorScheme = theme;
|
|
420
|
-
}
|
|
421
|
-
const CHATGPT_STYLE_VARIABLES = {
|
|
422
|
-
...DEFAULT_STYLE_VARIABLES
|
|
423
|
-
};
|
|
424
|
-
registerHostShell({
|
|
425
|
-
id: "chatgpt",
|
|
426
|
-
label: "ChatGPT",
|
|
427
|
-
Conversation,
|
|
428
|
-
applyTheme: applyChatGPTTheme,
|
|
429
|
-
hostInfo: CHATGPT_HOST_INFO,
|
|
430
|
-
hostCapabilities: CHATGPT_HOST_CAPABILITIES,
|
|
431
|
-
userAgent: "chatgpt",
|
|
432
|
-
styleVariables: CHATGPT_STYLE_VARIABLES,
|
|
433
|
-
pageStyles: {
|
|
434
|
-
"--sim-bg-sidebar": "light-dark(#ffffff, #212121)",
|
|
435
|
-
"--sim-bg-conversation": "light-dark(#ffffff, #212121)",
|
|
436
|
-
"--sim-bg-user-bubble": "light-dark(rgba(233,233,233,0.5), rgba(50,50,50,0.85))",
|
|
437
|
-
"--sim-bg-reply-input": "light-dark(#ffffff, #212121)"
|
|
438
|
-
}
|
|
439
|
-
});
|
|
440
|
-
function CloseIcon() {
|
|
441
|
-
return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
442
|
-
"path",
|
|
443
|
-
{
|
|
444
|
-
d: "M12 4L4 12M4 4L12 12",
|
|
445
|
-
stroke: "currentColor",
|
|
446
|
-
strokeWidth: "1.5",
|
|
447
|
-
strokeLinecap: "round"
|
|
448
|
-
}
|
|
449
|
-
) });
|
|
450
|
-
}
|
|
451
|
-
function BackIcon() {
|
|
452
|
-
return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
453
|
-
"path",
|
|
454
|
-
{
|
|
455
|
-
d: "M10 3L5 8L10 13",
|
|
456
|
-
stroke: "currentColor",
|
|
457
|
-
strokeWidth: "1.5",
|
|
458
|
-
strokeLinecap: "round",
|
|
459
|
-
strokeLinejoin: "round"
|
|
460
|
-
}
|
|
461
|
-
) });
|
|
462
|
-
}
|
|
463
|
-
function ClaudeConversation({
|
|
464
|
-
children,
|
|
465
|
-
screenWidth,
|
|
466
|
-
displayMode,
|
|
467
|
-
platform,
|
|
468
|
-
onRequestDisplayMode,
|
|
469
|
-
appName = "Sunpeak",
|
|
470
|
-
appIcon,
|
|
471
|
-
userMessage = "What have you got for me today?",
|
|
472
|
-
headerAction,
|
|
473
|
-
onContentWidthChange
|
|
474
|
-
}) {
|
|
475
|
-
const isDesktop = platform === "desktop";
|
|
476
|
-
const containerWidth = screenWidth === "full" ? "100%" : `${SCREEN_WIDTHS[screenWidth]}px`;
|
|
477
|
-
const isFullscreen = displayMode === "fullscreen";
|
|
478
|
-
const isPip = displayMode === "pip";
|
|
479
|
-
const contentRef = React.useRef(null);
|
|
480
|
-
const onContentWidthChangeRef = React.useRef(onContentWidthChange);
|
|
481
|
-
React.useEffect(() => {
|
|
482
|
-
onContentWidthChangeRef.current = onContentWidthChange;
|
|
483
|
-
});
|
|
484
|
-
const setContentRef = React.useCallback((node) => {
|
|
485
|
-
contentRef.current = node;
|
|
486
|
-
}, []);
|
|
487
|
-
React.useEffect(() => {
|
|
488
|
-
const el = contentRef.current;
|
|
489
|
-
if (!el) return;
|
|
490
|
-
const observer = new ResizeObserver((entries) => {
|
|
491
|
-
for (const entry of entries) {
|
|
492
|
-
const width = Math.round(entry.contentBoxSize[0]?.inlineSize ?? entry.contentRect.width);
|
|
493
|
-
if (width > 0) {
|
|
494
|
-
onContentWidthChangeRef.current?.(width);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
});
|
|
498
|
-
observer.observe(el);
|
|
499
|
-
return () => observer.disconnect();
|
|
500
|
-
}, []);
|
|
501
|
-
const handleClose = () => onRequestDisplayMode?.("inline");
|
|
502
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
503
|
-
"div",
|
|
504
|
-
{
|
|
505
|
-
className: "flex flex-col w-full h-full flex-1 items-center relative",
|
|
506
|
-
style: {
|
|
507
|
-
transform: "translate(0)",
|
|
508
|
-
backgroundColor: "var(--sim-bg-conversation, var(--color-background-primary))",
|
|
509
|
-
color: "var(--color-text-primary)"
|
|
510
|
-
},
|
|
511
|
-
children: [
|
|
512
|
-
isFullscreen && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
513
|
-
"div",
|
|
514
|
-
{
|
|
515
|
-
className: "fixed start-0 end-0 top-0 bottom-0 z-[51] mx-auto flex flex-col pointer-events-none",
|
|
516
|
-
style: { maxWidth: containerWidth },
|
|
517
|
-
children: [
|
|
518
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
519
|
-
"div",
|
|
520
|
-
{
|
|
521
|
-
className: "z-10 flex items-center h-12 border-b px-3 pointer-events-auto",
|
|
522
|
-
style: {
|
|
523
|
-
borderColor: "var(--color-border-primary)",
|
|
524
|
-
backgroundColor: "var(--sim-bg-conversation, var(--color-background-primary))"
|
|
525
|
-
},
|
|
526
|
-
children: [
|
|
527
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
528
|
-
"button",
|
|
529
|
-
{
|
|
530
|
-
onClick: handleClose,
|
|
531
|
-
"aria-label": "Back",
|
|
532
|
-
className: "h-8 w-8 flex items-center justify-center rounded-lg transition-colors hover:opacity-70",
|
|
533
|
-
type: "button",
|
|
534
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(BackIcon, {})
|
|
535
|
-
}
|
|
536
|
-
),
|
|
537
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 text-center text-sm font-medium", children: appName }),
|
|
538
|
-
isDesktop && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-8" })
|
|
539
|
-
]
|
|
540
|
-
}
|
|
541
|
-
),
|
|
542
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1" }),
|
|
543
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
544
|
-
"footer",
|
|
545
|
-
{
|
|
546
|
-
className: "pointer-events-auto p-3",
|
|
547
|
-
style: {
|
|
548
|
-
backgroundColor: "var(--sim-bg-conversation, var(--color-background-primary))"
|
|
549
|
-
},
|
|
550
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-w-[48rem] mx-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
551
|
-
"input",
|
|
552
|
-
{
|
|
553
|
-
type: "text",
|
|
554
|
-
name: "userInput",
|
|
555
|
-
disabled: true,
|
|
556
|
-
placeholder: "Reply to sunpeak...",
|
|
557
|
-
className: "w-full rounded-xl px-4 py-2.5 text-sm",
|
|
558
|
-
style: {
|
|
559
|
-
backgroundColor: "var(--sim-bg-reply-input, var(--color-background-secondary))",
|
|
560
|
-
border: "1px solid var(--color-border-primary)",
|
|
561
|
-
color: "var(--color-text-primary)"
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
) })
|
|
565
|
-
}
|
|
566
|
-
)
|
|
567
|
-
]
|
|
568
|
-
}
|
|
569
|
-
),
|
|
570
|
-
!isFullscreen && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
571
|
-
"header",
|
|
572
|
-
{
|
|
573
|
-
className: "h-12 flex items-center gap-3 px-4 text-sm font-medium sticky top-0 z-40 w-full",
|
|
574
|
-
style: {
|
|
575
|
-
maxWidth: containerWidth,
|
|
576
|
-
backgroundColor: "var(--sim-bg-conversation, var(--color-background-primary))"
|
|
577
|
-
},
|
|
578
|
-
children: [
|
|
579
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "sunpeak.ai" }),
|
|
580
|
-
headerAction
|
|
581
|
-
]
|
|
582
|
-
}
|
|
583
|
-
),
|
|
584
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
585
|
-
"div",
|
|
586
|
-
{
|
|
587
|
-
className: "flex flex-col flex-1 w-full transition-all duration-200 overflow-hidden",
|
|
588
|
-
style: { maxWidth: containerWidth },
|
|
589
|
-
children: [
|
|
590
|
-
/* @__PURE__ */ jsxRuntime.jsxs("main", { className: "flex-1 overflow-y-auto overflow-x-hidden", children: [
|
|
591
|
-
!isFullscreen && /* @__PURE__ */ jsxRuntime.jsx("article", { className: "w-full", dir: "auto", "data-turn": "user", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-w-[48rem] mx-auto flex justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
592
|
-
"div",
|
|
593
|
-
{
|
|
594
|
-
className: "inline-block rounded-2xl px-4 py-2.5 text-sm max-w-[85%]",
|
|
595
|
-
style: {
|
|
596
|
-
backgroundColor: "var(--sim-bg-user-bubble, var(--color-background-tertiary))"
|
|
597
|
-
},
|
|
598
|
-
children: userMessage
|
|
599
|
-
}
|
|
600
|
-
) }) }) }),
|
|
601
|
-
/* @__PURE__ */ jsxRuntime.jsxs("article", { className: "w-full", dir: "auto", "data-turn": "assistant", children: [
|
|
602
|
-
/* @__PURE__ */ jsxRuntime.jsxs("h6", { className: "sr-only", children: [
|
|
603
|
-
appName,
|
|
604
|
-
" said:"
|
|
605
|
-
] }),
|
|
606
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-4 py-2", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "max-w-[48rem] mx-auto", children: [
|
|
607
|
-
!isFullscreen && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 mb-3", children: [
|
|
608
|
-
appIcon ? appIcon.startsWith("data:") || appIcon.startsWith("http") ? /* @__PURE__ */ jsxRuntime.jsx("img", { src: appIcon, alt: "", className: "size-6 rounded-full object-cover" }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-6 flex items-center justify-center text-base", children: appIcon }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
609
|
-
"div",
|
|
610
|
-
{
|
|
611
|
-
className: "size-6 rounded-full flex items-center justify-center text-xs font-medium text-white",
|
|
612
|
-
style: { backgroundColor: "#c55a30" },
|
|
613
|
-
children: "C"
|
|
614
|
-
}
|
|
615
|
-
),
|
|
616
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium", children: appName })
|
|
617
|
-
] }),
|
|
618
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
619
|
-
"div",
|
|
620
|
-
{
|
|
621
|
-
ref: setContentRef,
|
|
622
|
-
className: isPip ? "fixed start-4 end-4 top-12 z-50 mx-auto max-w-[40rem] lg:max-w-[48rem] sm:start-0 sm:end-0 sm:top-[3rem] sm:w-full overflow-visible" : isFullscreen ? "fixed inset-x-0 top-[3rem] bottom-0 z-50 mx-auto" : "relative mb-2 w-full overflow-visible",
|
|
623
|
-
style: {
|
|
624
|
-
...isPip ? { maxHeight: "480px" } : {},
|
|
625
|
-
...isFullscreen ? { maxWidth: containerWidth } : {}
|
|
626
|
-
},
|
|
627
|
-
children: [
|
|
628
|
-
isPip && /* @__PURE__ */ jsxRuntime.jsx(
|
|
629
|
-
"button",
|
|
630
|
-
{
|
|
631
|
-
onClick: handleClose,
|
|
632
|
-
className: "absolute -start-2 -top-1.5 z-10 rounded-full p-1.5 text-white shadow-md",
|
|
633
|
-
style: { backgroundColor: "#4a4a4a" },
|
|
634
|
-
"aria-label": "Close picture-in-picture",
|
|
635
|
-
type: "button",
|
|
636
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, {})
|
|
637
|
-
},
|
|
638
|
-
"pip-close"
|
|
639
|
-
),
|
|
640
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
641
|
-
"div",
|
|
642
|
-
{
|
|
643
|
-
className: isPip ? "relative overflow-hidden h-full rounded-2xl shadow-lg" : "relative overflow-hidden h-full",
|
|
644
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
645
|
-
"div",
|
|
646
|
-
{
|
|
647
|
-
className: "h-full w-full max-w-full",
|
|
648
|
-
style: {
|
|
649
|
-
...isPip ? {
|
|
650
|
-
overflow: "auto",
|
|
651
|
-
backgroundColor: "var(--color-background-secondary)"
|
|
652
|
-
} : isFullscreen ? {
|
|
653
|
-
overflow: "auto",
|
|
654
|
-
backgroundColor: "var(--color-background-primary)"
|
|
655
|
-
} : { backgroundColor: "transparent" }
|
|
656
|
-
},
|
|
657
|
-
children
|
|
658
|
-
}
|
|
659
|
-
)
|
|
660
|
-
},
|
|
661
|
-
"content"
|
|
662
|
-
)
|
|
663
|
-
]
|
|
664
|
-
}
|
|
665
|
-
)
|
|
666
|
-
] }) })
|
|
667
|
-
] })
|
|
668
|
-
] }),
|
|
669
|
-
!isFullscreen && /* @__PURE__ */ jsxRuntime.jsx(
|
|
670
|
-
"footer",
|
|
671
|
-
{
|
|
672
|
-
style: {
|
|
673
|
-
backgroundColor: "var(--sim-bg-conversation, var(--color-background-primary))"
|
|
674
|
-
},
|
|
675
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-w-[48rem] mx-auto px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
676
|
-
"input",
|
|
677
|
-
{
|
|
678
|
-
type: "text",
|
|
679
|
-
name: "userInput",
|
|
680
|
-
disabled: true,
|
|
681
|
-
placeholder: "Reply to sunpeak...",
|
|
682
|
-
className: "w-full rounded-xl px-4 py-2.5 text-sm",
|
|
683
|
-
style: {
|
|
684
|
-
backgroundColor: "var(--sim-bg-reply-input, var(--color-background-secondary))",
|
|
685
|
-
border: "1px solid var(--color-border-primary)"
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
) }) })
|
|
689
|
-
}
|
|
690
|
-
)
|
|
691
|
-
]
|
|
692
|
-
}
|
|
693
|
-
)
|
|
694
|
-
]
|
|
695
|
-
}
|
|
696
|
-
);
|
|
697
|
-
}
|
|
698
|
-
const CLAUDE_HOST_INFO = {
|
|
699
|
-
name: "Claude",
|
|
700
|
-
version: "1.0.0"
|
|
701
|
-
};
|
|
702
|
-
const CLAUDE_HOST_CAPABILITIES = {
|
|
703
|
-
openLinks: {},
|
|
704
|
-
serverTools: {},
|
|
705
|
-
serverResources: {},
|
|
706
|
-
downloadFile: {},
|
|
707
|
-
logging: {},
|
|
708
|
-
updateModelContext: { text: {} },
|
|
709
|
-
message: { text: {} },
|
|
710
|
-
sandbox: {}
|
|
711
|
-
};
|
|
712
|
-
function applyClaudeTheme(theme) {
|
|
713
|
-
document.documentElement.setAttribute("data-theme", theme);
|
|
714
|
-
document.documentElement.style.colorScheme = theme;
|
|
715
|
-
}
|
|
716
|
-
const CLAUDE_STYLE_VARIABLES = {
|
|
717
|
-
...DEFAULT_STYLE_VARIABLES,
|
|
718
|
-
// Background colors — warm beige/cream palette
|
|
719
|
-
"--color-background-primary": "light-dark(#faf9f5, #262624)",
|
|
720
|
-
"--color-background-secondary": "light-dark(#ffffff, #3a3935)",
|
|
721
|
-
"--color-background-tertiary": "light-dark(#e8e4dc, #4a4843)",
|
|
722
|
-
"--color-background-inverse": "light-dark(#2b2a27, #f3f0e8)",
|
|
723
|
-
// Text colors
|
|
724
|
-
"--color-text-primary": "light-dark(#2d2b27, #e8e4dc)",
|
|
725
|
-
"--color-text-secondary": "light-dark(#6b6560, #9b9690)",
|
|
726
|
-
"--color-text-tertiary": "light-dark(#9b9690, #6b6560)",
|
|
727
|
-
"--color-text-inverse": "light-dark(#e8e4dc, #2d2b27)",
|
|
728
|
-
// Border colors
|
|
729
|
-
"--color-border-primary": "light-dark(#e0ddd5, #4a4843)",
|
|
730
|
-
"--color-border-secondary": "light-dark(#d5d1c8, #5a5753)",
|
|
731
|
-
"--color-border-tertiary": "light-dark(#f0ede5, #3a3935)"
|
|
732
|
-
};
|
|
733
|
-
registerHostShell({
|
|
734
|
-
id: "claude",
|
|
735
|
-
label: "Claude",
|
|
736
|
-
Conversation: ClaudeConversation,
|
|
737
|
-
applyTheme: applyClaudeTheme,
|
|
738
|
-
hostInfo: CLAUDE_HOST_INFO,
|
|
739
|
-
hostCapabilities: CLAUDE_HOST_CAPABILITIES,
|
|
740
|
-
userAgent: "claude",
|
|
741
|
-
styleVariables: CLAUDE_STYLE_VARIABLES,
|
|
742
|
-
pageStyles: {
|
|
743
|
-
"--sim-bg-sidebar": "light-dark(#f9f8f3, #252523)",
|
|
744
|
-
"--sim-bg-conversation": "light-dark(#faf9f5, #262624)",
|
|
745
|
-
"--sim-bg-user-bubble": "light-dark(#f1eee6, #141413)",
|
|
746
|
-
"--sim-bg-reply-input": "light-dark(#ffffff, #30302e)"
|
|
747
|
-
}
|
|
748
|
-
});
|
|
749
|
-
var G = "2026-01-26", _ = "ui/notifications/tool-input-partial";
|
|
750
|
-
var m = protocol.union([protocol.literal("light"), protocol.literal("dark")]).describe("Color theme preference for the host environment."), D = protocol.union([protocol.literal("inline"), protocol.literal("fullscreen"), protocol.literal("pip")]).describe("Display mode for UI presentation."), OQ = protocol.union([protocol.literal("--color-background-primary"), protocol.literal("--color-background-secondary"), protocol.literal("--color-background-tertiary"), protocol.literal("--color-background-inverse"), protocol.literal("--color-background-ghost"), protocol.literal("--color-background-info"), protocol.literal("--color-background-danger"), protocol.literal("--color-background-success"), protocol.literal("--color-background-warning"), protocol.literal("--color-background-disabled"), protocol.literal("--color-text-primary"), protocol.literal("--color-text-secondary"), protocol.literal("--color-text-tertiary"), protocol.literal("--color-text-inverse"), protocol.literal("--color-text-ghost"), protocol.literal("--color-text-info"), protocol.literal("--color-text-danger"), protocol.literal("--color-text-success"), protocol.literal("--color-text-warning"), protocol.literal("--color-text-disabled"), protocol.literal("--color-border-primary"), protocol.literal("--color-border-secondary"), protocol.literal("--color-border-tertiary"), protocol.literal("--color-border-inverse"), protocol.literal("--color-border-ghost"), protocol.literal("--color-border-info"), protocol.literal("--color-border-danger"), protocol.literal("--color-border-success"), protocol.literal("--color-border-warning"), protocol.literal("--color-border-disabled"), protocol.literal("--color-ring-primary"), protocol.literal("--color-ring-secondary"), protocol.literal("--color-ring-inverse"), protocol.literal("--color-ring-info"), protocol.literal("--color-ring-danger"), protocol.literal("--color-ring-success"), protocol.literal("--color-ring-warning"), protocol.literal("--font-sans"), protocol.literal("--font-mono"), protocol.literal("--font-weight-normal"), protocol.literal("--font-weight-medium"), protocol.literal("--font-weight-semibold"), protocol.literal("--font-weight-bold"), protocol.literal("--font-text-xs-size"), protocol.literal("--font-text-sm-size"), protocol.literal("--font-text-md-size"), protocol.literal("--font-text-lg-size"), protocol.literal("--font-heading-xs-size"), protocol.literal("--font-heading-sm-size"), protocol.literal("--font-heading-md-size"), protocol.literal("--font-heading-lg-size"), protocol.literal("--font-heading-xl-size"), protocol.literal("--font-heading-2xl-size"), protocol.literal("--font-heading-3xl-size"), protocol.literal("--font-text-xs-line-height"), protocol.literal("--font-text-sm-line-height"), protocol.literal("--font-text-md-line-height"), protocol.literal("--font-text-lg-line-height"), protocol.literal("--font-heading-xs-line-height"), protocol.literal("--font-heading-sm-line-height"), protocol.literal("--font-heading-md-line-height"), protocol.literal("--font-heading-lg-line-height"), protocol.literal("--font-heading-xl-line-height"), protocol.literal("--font-heading-2xl-line-height"), protocol.literal("--font-heading-3xl-line-height"), protocol.literal("--border-radius-xs"), protocol.literal("--border-radius-sm"), protocol.literal("--border-radius-md"), protocol.literal("--border-radius-lg"), protocol.literal("--border-radius-xl"), protocol.literal("--border-radius-full"), protocol.literal("--border-width-regular"), protocol.literal("--shadow-hairline"), protocol.literal("--shadow-sm"), protocol.literal("--shadow-md"), protocol.literal("--shadow-lg")]).describe("CSS variable keys available to MCP apps for theming."), VQ = protocol.record(OQ.describe(`Style variables for theming MCP apps.
|
|
751
|
-
|
|
752
|
-
Individual style keys are optional - hosts may provide any subset of these values.
|
|
753
|
-
Values are strings containing CSS values (colors, sizes, font stacks, etc.).
|
|
754
|
-
|
|
755
|
-
Note: This type uses \`Record<K, string | undefined>\` rather than \`Partial<Record<K, string>>\`
|
|
756
|
-
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`), protocol.union([protocol.string(), protocol._undefined()]).describe(`Style variables for theming MCP apps.
|
|
757
|
-
|
|
758
|
-
Individual style keys are optional - hosts may provide any subset of these values.
|
|
759
|
-
Values are strings containing CSS values (colors, sizes, font stacks, etc.).
|
|
760
|
-
|
|
761
|
-
Note: This type uses \`Record<K, string | undefined>\` rather than \`Partial<Record<K, string>>\`
|
|
762
|
-
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`)).describe(`Style variables for theming MCP apps.
|
|
763
|
-
|
|
764
|
-
Individual style keys are optional - hosts may provide any subset of these values.
|
|
765
|
-
Values are strings containing CSS values (colors, sizes, font stacks, etc.).
|
|
766
|
-
|
|
767
|
-
Note: This type uses \`Record<K, string | undefined>\` rather than \`Partial<Record<K, string>>\`
|
|
768
|
-
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`), V = protocol.object({ method: protocol.literal("ui/open-link"), params: protocol.object({ url: protocol.string().describe("URL to open in the host's browser") }) });
|
|
769
|
-
protocol.object({ isError: protocol.boolean().optional().describe("True if the host failed to open the URL (e.g., due to security policy).") }).passthrough();
|
|
770
|
-
protocol.object({ isError: protocol.boolean().optional().describe("True if the download failed (e.g., user cancelled or host denied).") }).passthrough();
|
|
771
|
-
protocol.object({ isError: protocol.boolean().optional().describe("True if the host rejected or failed to deliver the message.") }).passthrough();
|
|
772
|
-
var F = protocol.object({ method: protocol.literal("ui/notifications/sandbox-proxy-ready"), params: protocol.object({}) }), j = protocol.object({ connectDomains: protocol.array(protocol.string()).optional().describe(`Origins for network requests (fetch/XHR/WebSocket).
|
|
773
|
-
|
|
774
|
-
- Maps to CSP \`connect-src\` directive
|
|
775
|
-
- Empty or omitted → no network connections (secure default)`), resourceDomains: protocol.array(protocol.string()).optional().describe("Origins for static resources (images, scripts, stylesheets, fonts, media).\n\n- Maps to CSP `img-src`, `script-src`, `style-src`, `font-src`, `media-src` directives\n- Wildcard subdomains supported: `https://*.example.com`\n- Empty or omitted → no network resources (secure default)"), frameDomains: protocol.array(protocol.string()).optional().describe("Origins for nested iframes.\n\n- Maps to CSP `frame-src` directive\n- Empty or omitted → no nested iframes allowed (`frame-src 'none'`)"), baseUriDomains: protocol.array(protocol.string()).optional().describe("Allowed base URIs for the document.\n\n- Maps to CSP `base-uri` directive\n- Empty or omitted → only same origin allowed (`base-uri 'self'`)") }), E = protocol.object({ camera: protocol.object({}).optional().describe("Request camera access.\n\nMaps to Permission Policy `camera` feature."), microphone: protocol.object({}).optional().describe("Request microphone access.\n\nMaps to Permission Policy `microphone` feature."), geolocation: protocol.object({}).optional().describe("Request geolocation access.\n\nMaps to Permission Policy `geolocation` feature."), clipboardWrite: protocol.object({}).optional().describe("Request clipboard write access.\n\nMaps to Permission Policy `clipboard-write` feature.") }), P = protocol.object({ method: protocol.literal("ui/notifications/size-changed"), params: protocol.object({ width: protocol.number().optional().describe("New width in pixels."), height: protocol.number().optional().describe("New height in pixels.") }) });
|
|
776
|
-
protocol.object({ method: protocol.literal("ui/notifications/tool-input"), params: protocol.object({ arguments: protocol.record(protocol.string(), protocol.unknown().describe("Complete tool call arguments as key-value pairs.")).optional().describe("Complete tool call arguments as key-value pairs.") }) });
|
|
777
|
-
protocol.object({ method: protocol.literal("ui/notifications/tool-input-partial"), params: protocol.object({ arguments: protocol.record(protocol.string(), protocol.unknown().describe("Partial tool call arguments (incomplete, may change).")).optional().describe("Partial tool call arguments (incomplete, may change).") }) });
|
|
778
|
-
protocol.object({ method: protocol.literal("ui/notifications/tool-cancelled"), params: protocol.object({ reason: protocol.string().optional().describe('Optional reason for the cancellation (e.g., "user action", "timeout").') }) });
|
|
779
|
-
var p = protocol.object({ fonts: protocol.string().optional() }), c = protocol.object({ variables: VQ.optional().describe("CSS variables for theming the app."), css: p.optional().describe("CSS blocks that apps can inject.") });
|
|
780
|
-
protocol.object({ method: protocol.literal("ui/resource-teardown"), params: protocol.object({}) });
|
|
781
|
-
var R = protocol.record(protocol.string(), protocol.unknown()), O = protocol.object({ text: protocol.object({}).optional().describe("Host supports text content blocks."), image: protocol.object({}).optional().describe("Host supports image content blocks."), audio: protocol.object({}).optional().describe("Host supports audio content blocks."), resource: protocol.object({}).optional().describe("Host supports resource content blocks."), resourceLink: protocol.object({}).optional().describe("Host supports resource link content blocks."), structuredContent: protocol.object({}).optional().describe("Host supports structured content.") }), n = protocol.object({ experimental: protocol.object({}).optional().describe("Experimental features (structure TBD)."), openLinks: protocol.object({}).optional().describe("Host supports opening external URLs."), downloadFile: protocol.object({}).optional().describe("Host supports file downloads via ui/download-file."), serverTools: protocol.object({ listChanged: protocol.boolean().optional().describe("Host supports tools/list_changed notifications.") }).optional().describe("Host can proxy tool calls to the MCP server."), serverResources: protocol.object({ listChanged: protocol.boolean().optional().describe("Host supports resources/list_changed notifications.") }).optional().describe("Host can proxy resource reads to the MCP server."), logging: protocol.object({}).optional().describe("Host accepts log messages."), sandbox: protocol.object({ permissions: E.optional().describe("Permissions granted by the host (camera, microphone, geolocation)."), csp: j.optional().describe("CSP domains approved by the host.") }).optional().describe("Sandbox configuration applied by the host."), updateModelContext: O.optional().describe("Host accepts context updates (ui/update-model-context) to be included in the model's context for future turns."), message: O.optional().describe("Host supports receiving content messages (ui/message) from the view.") }), i = protocol.object({ experimental: protocol.object({}).optional().describe("Experimental features (structure TBD)."), tools: protocol.object({ listChanged: protocol.boolean().optional().describe("App supports tools/list_changed notifications.") }).optional().describe("App exposes MCP-style tools that the host can call."), availableDisplayModes: protocol.array(D).optional().describe("Display modes the app supports.") }), M = protocol.object({ method: protocol.literal("ui/notifications/initialized"), params: protocol.object({}).optional() });
|
|
782
|
-
protocol.object({ csp: j.optional().describe("Content Security Policy configuration for UI resources."), permissions: E.optional().describe("Sandbox permissions requested by the UI resource."), domain: protocol.string().optional().describe(`Dedicated origin for view sandbox.
|
|
783
|
-
|
|
784
|
-
Useful when views need stable, dedicated origins for OAuth callbacks, CORS policies, or API key allowlists.
|
|
785
|
-
|
|
786
|
-
**Host-dependent:** The format and validation rules for this field are determined by each host. Servers MUST consult host-specific documentation for the expected domain format. Common patterns include:
|
|
787
|
-
- Hash-based subdomains (e.g., \`{hash}.claudemcpcontent.com\`)
|
|
788
|
-
- URL-derived subdomains (e.g., \`www-example-com.oaiusercontent.com\`)
|
|
789
|
-
|
|
790
|
-
If omitted, host uses default sandbox origin (typically per-conversation).`), prefersBorder: protocol.boolean().optional().describe(`Visual boundary preference - true if view prefers a visible border.
|
|
791
|
-
|
|
792
|
-
Boolean requesting whether a visible border and background is provided by the host. Specifying an explicit value for this is recommended because hosts' defaults may vary.
|
|
793
|
-
|
|
794
|
-
- \`true\`: request visible border + background
|
|
795
|
-
- \`false\`: request no visible border + background
|
|
796
|
-
- omitted: host decides border`) });
|
|
797
|
-
var W = protocol.object({ method: protocol.literal("ui/request-display-mode"), params: protocol.object({ mode: D.describe("The display mode being requested.") }) });
|
|
798
|
-
protocol.object({ mode: D.describe("The display mode that was actually set. May differ from requested if not supported.") }).passthrough();
|
|
799
|
-
var l = protocol.union([protocol.literal("model"), protocol.literal("app")]).describe("Tool visibility scope - who can access the tool.");
|
|
800
|
-
protocol.object({ resourceUri: protocol.string().optional(), visibility: protocol.array(l).optional().describe(`Who can access this tool. Default: ["model", "app"]
|
|
801
|
-
- "model": Tool visible to and callable by the agent
|
|
802
|
-
- "app": Tool callable by the app from this server only`) });
|
|
803
|
-
protocol.object({ mimeTypes: protocol.array(protocol.string()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.') });
|
|
804
|
-
var S = protocol.object({ method: protocol.literal("ui/download-file"), params: protocol.object({ contents: protocol.array(protocol.union([protocol.EmbeddedResourceSchema, protocol.ResourceLinkSchema])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.") }) }), C = protocol.object({ method: protocol.literal("ui/message"), params: protocol.object({ role: protocol.literal("user").describe('Message role, currently only "user" is supported.'), content: protocol.array(protocol.ContentBlockSchema).describe("Message content blocks (text, image, etc.).") }) });
|
|
805
|
-
protocol.object({ method: protocol.literal("ui/notifications/sandbox-resource-ready"), params: protocol.object({ html: protocol.string().describe("HTML content to load into the inner iframe."), sandbox: protocol.string().optional().describe("Optional override for the inner iframe's sandbox attribute."), csp: j.optional().describe("CSP configuration from resource metadata."), permissions: E.optional().describe("Sandbox permissions from resource metadata.") }) });
|
|
806
|
-
protocol.object({ method: protocol.literal("ui/notifications/tool-result"), params: protocol.CallToolResultSchema.describe("Standard MCP tool execution result.") });
|
|
807
|
-
var q = protocol.object({ toolInfo: protocol.object({ id: protocol.RequestIdSchema.optional().describe("JSON-RPC id of the tools/call request."), tool: protocol.ToolSchema.describe("Tool definition including name, inputSchema, etc.") }).optional().describe("Metadata of the tool call that instantiated this App."), theme: m.optional().describe("Current color theme preference."), styles: c.optional().describe("Style configuration for theming the app."), displayMode: D.optional().describe("How the UI is currently displayed."), availableDisplayModes: protocol.array(D).optional().describe("Display modes the host supports."), containerDimensions: protocol.union([protocol.object({ height: protocol.number().describe("Fixed container height in pixels.") }), protocol.object({ maxHeight: protocol.union([protocol.number(), protocol._undefined()]).optional().describe("Maximum container height in pixels.") })]).and(protocol.union([protocol.object({ width: protocol.number().describe("Fixed container width in pixels.") }), protocol.object({ maxWidth: protocol.union([protocol.number(), protocol._undefined()]).optional().describe("Maximum container width in pixels.") })])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
|
|
808
|
-
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`), locale: protocol.string().optional().describe("User's language and region preference in BCP 47 format."), timeZone: protocol.string().optional().describe("User's timezone in IANA format."), userAgent: protocol.string().optional().describe("Host application identifier."), platform: protocol.union([protocol.literal("web"), protocol.literal("desktop"), protocol.literal("mobile")]).optional().describe("Platform type for responsive design decisions."), deviceCapabilities: protocol.object({ touch: protocol.boolean().optional().describe("Whether the device supports touch input."), hover: protocol.boolean().optional().describe("Whether the device supports hover interactions.") }).optional().describe("Device input capabilities."), safeAreaInsets: protocol.object({ top: protocol.number().describe("Top safe area inset in pixels."), right: protocol.number().describe("Right safe area inset in pixels."), bottom: protocol.number().describe("Bottom safe area inset in pixels."), left: protocol.number().describe("Left safe area inset in pixels.") }).optional().describe("Mobile safe area boundaries in pixels.") }).passthrough();
|
|
809
|
-
protocol.object({ method: protocol.literal("ui/notifications/host-context-changed"), params: q.describe("Partial context update containing only changed fields.") });
|
|
810
|
-
var y = protocol.object({ method: protocol.literal("ui/update-model-context"), params: protocol.object({ content: protocol.array(protocol.ContentBlockSchema).optional().describe("Context content blocks (text, image, etc.)."), structuredContent: protocol.record(protocol.string(), protocol.unknown().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.") }) }), f = protocol.object({ method: protocol.literal("ui/initialize"), params: protocol.object({ appInfo: protocol.ImplementationSchema.describe("App identification (name and version)."), appCapabilities: i.describe("Features and capabilities this app provides."), protocolVersion: protocol.string().describe("Protocol version this app supports.") }) });
|
|
811
|
-
protocol.object({ protocolVersion: protocol.string().describe('Negotiated protocol version string (e.g., "2025-11-21").'), hostInfo: protocol.ImplementationSchema.describe("Host application identification and version."), hostCapabilities: n.describe("Features and capabilities provided by the host."), hostContext: q.describe("Rich context about the host environment.") }).passthrough();
|
|
812
|
-
class N {
|
|
813
|
-
eventTarget;
|
|
814
|
-
eventSource;
|
|
815
|
-
messageListener;
|
|
816
|
-
constructor(X = window.parent, Y) {
|
|
817
|
-
this.eventTarget = X;
|
|
818
|
-
this.eventSource = Y;
|
|
819
|
-
this.messageListener = (Z) => {
|
|
820
|
-
if (Y && Z.source !== this.eventSource) {
|
|
821
|
-
console.debug("Ignoring message from unknown source", Z);
|
|
822
|
-
return;
|
|
823
|
-
}
|
|
824
|
-
let $ = protocol.JSONRPCMessageSchema.safeParse(Z.data);
|
|
825
|
-
if ($.success) console.debug("Parsed message", $.data), this.onmessage?.($.data);
|
|
826
|
-
else if (Z.data?.jsonrpc !== "2.0") console.debug("Ignoring non-JSON-RPC message", $.error.message, Z);
|
|
827
|
-
else console.error("Failed to parse message", $.error.message, Z), this.onerror?.(Error("Invalid JSON-RPC message received: " + $.error.message));
|
|
828
|
-
};
|
|
829
|
-
}
|
|
830
|
-
async start() {
|
|
831
|
-
window.addEventListener("message", this.messageListener);
|
|
832
|
-
}
|
|
833
|
-
async send(X, Y) {
|
|
834
|
-
if (X.method !== _) console.debug("Sending message", X);
|
|
835
|
-
this.eventTarget.postMessage(X, "*");
|
|
836
|
-
}
|
|
837
|
-
async close() {
|
|
838
|
-
window.removeEventListener("message", this.messageListener), this.onclose?.();
|
|
839
|
-
}
|
|
840
|
-
onclose;
|
|
841
|
-
onerror;
|
|
842
|
-
onmessage;
|
|
843
|
-
sessionId;
|
|
844
|
-
setProtocolVersion;
|
|
845
|
-
}
|
|
846
|
-
var rQ = [G];
|
|
847
|
-
class oQ extends protocol.Protocol {
|
|
848
|
-
_client;
|
|
849
|
-
_hostInfo;
|
|
850
|
-
_capabilities;
|
|
851
|
-
_appCapabilities;
|
|
852
|
-
_hostContext = {};
|
|
853
|
-
_appInfo;
|
|
854
|
-
constructor(X, Y, Z, $) {
|
|
855
|
-
super($);
|
|
856
|
-
this._client = X;
|
|
857
|
-
this._hostInfo = Y;
|
|
858
|
-
this._capabilities = Z;
|
|
859
|
-
this._hostContext = $?.hostContext || {}, this.setRequestHandler(f, (K) => this._oninitialize(K)), this.setRequestHandler(protocol.PingRequestSchema, (K, J) => {
|
|
860
|
-
return this.onping?.(K.params, J), {};
|
|
861
|
-
}), this.setRequestHandler(W, (K) => {
|
|
862
|
-
return { mode: this._hostContext.displayMode ?? "inline" };
|
|
863
|
-
});
|
|
864
|
-
}
|
|
865
|
-
getAppCapabilities() {
|
|
866
|
-
return this._appCapabilities;
|
|
867
|
-
}
|
|
868
|
-
getAppVersion() {
|
|
869
|
-
return this._appInfo;
|
|
870
|
-
}
|
|
871
|
-
onping;
|
|
872
|
-
set onsizechange(X) {
|
|
873
|
-
this.setNotificationHandler(P, (Y) => X(Y.params));
|
|
874
|
-
}
|
|
875
|
-
set onsandboxready(X) {
|
|
876
|
-
this.setNotificationHandler(F, (Y) => X(Y.params));
|
|
877
|
-
}
|
|
878
|
-
set oninitialized(X) {
|
|
879
|
-
this.setNotificationHandler(M, (Y) => X(Y.params));
|
|
880
|
-
}
|
|
881
|
-
set onmessage(X) {
|
|
882
|
-
this.setRequestHandler(C, async (Y, Z) => {
|
|
883
|
-
return X(Y.params, Z);
|
|
884
|
-
});
|
|
885
|
-
}
|
|
886
|
-
set onopenlink(X) {
|
|
887
|
-
this.setRequestHandler(V, async (Y, Z) => {
|
|
888
|
-
return X(Y.params, Z);
|
|
889
|
-
});
|
|
890
|
-
}
|
|
891
|
-
set ondownloadfile(X) {
|
|
892
|
-
this.setRequestHandler(S, async (Y, Z) => {
|
|
893
|
-
return X(Y.params, Z);
|
|
894
|
-
});
|
|
895
|
-
}
|
|
896
|
-
set onrequestdisplaymode(X) {
|
|
897
|
-
this.setRequestHandler(W, async (Y, Z) => {
|
|
898
|
-
return X(Y.params, Z);
|
|
899
|
-
});
|
|
900
|
-
}
|
|
901
|
-
set onloggingmessage(X) {
|
|
902
|
-
this.setNotificationHandler(protocol.LoggingMessageNotificationSchema, async (Y) => {
|
|
903
|
-
X(Y.params);
|
|
904
|
-
});
|
|
905
|
-
}
|
|
906
|
-
set onupdatemodelcontext(X) {
|
|
907
|
-
this.setRequestHandler(y, async (Y, Z) => {
|
|
908
|
-
return X(Y.params, Z);
|
|
909
|
-
});
|
|
910
|
-
}
|
|
911
|
-
set oncalltool(X) {
|
|
912
|
-
this.setRequestHandler(protocol.CallToolRequestSchema, async (Y, Z) => {
|
|
913
|
-
return X(Y.params, Z);
|
|
914
|
-
});
|
|
915
|
-
}
|
|
916
|
-
sendToolListChanged(X = {}) {
|
|
917
|
-
return this.notification({ method: "notifications/tools/list_changed", params: X });
|
|
918
|
-
}
|
|
919
|
-
set onlistresources(X) {
|
|
920
|
-
this.setRequestHandler(protocol.ListResourcesRequestSchema, async (Y, Z) => {
|
|
921
|
-
return X(Y.params, Z);
|
|
922
|
-
});
|
|
923
|
-
}
|
|
924
|
-
set onlistresourcetemplates(X) {
|
|
925
|
-
this.setRequestHandler(protocol.ListResourceTemplatesRequestSchema, async (Y, Z) => {
|
|
926
|
-
return X(Y.params, Z);
|
|
927
|
-
});
|
|
928
|
-
}
|
|
929
|
-
set onreadresource(X) {
|
|
930
|
-
this.setRequestHandler(protocol.ReadResourceRequestSchema, async (Y, Z) => {
|
|
931
|
-
return X(Y.params, Z);
|
|
932
|
-
});
|
|
933
|
-
}
|
|
934
|
-
sendResourceListChanged(X = {}) {
|
|
935
|
-
return this.notification({ method: "notifications/resources/list_changed", params: X });
|
|
936
|
-
}
|
|
937
|
-
set onlistprompts(X) {
|
|
938
|
-
this.setRequestHandler(protocol.ListPromptsRequestSchema, async (Y, Z) => {
|
|
939
|
-
return X(Y.params, Z);
|
|
940
|
-
});
|
|
941
|
-
}
|
|
942
|
-
sendPromptListChanged(X = {}) {
|
|
943
|
-
return this.notification({ method: "notifications/prompts/list_changed", params: X });
|
|
944
|
-
}
|
|
945
|
-
assertCapabilityForMethod(X) {
|
|
946
|
-
}
|
|
947
|
-
assertRequestHandlerCapability(X) {
|
|
948
|
-
}
|
|
949
|
-
assertNotificationCapability(X) {
|
|
950
|
-
}
|
|
951
|
-
assertTaskCapability(X) {
|
|
952
|
-
throw Error("Tasks are not supported in MCP Apps");
|
|
953
|
-
}
|
|
954
|
-
assertTaskHandlerCapability(X) {
|
|
955
|
-
throw Error("Task handlers are not supported in MCP Apps");
|
|
956
|
-
}
|
|
957
|
-
getCapabilities() {
|
|
958
|
-
return this._capabilities;
|
|
959
|
-
}
|
|
960
|
-
async _oninitialize(X) {
|
|
961
|
-
let Y = X.params.protocolVersion;
|
|
962
|
-
return this._appCapabilities = X.params.appCapabilities, this._appInfo = X.params.appInfo, { protocolVersion: rQ.includes(Y) ? Y : G, hostCapabilities: this.getCapabilities(), hostInfo: this._hostInfo, hostContext: this._hostContext };
|
|
963
|
-
}
|
|
964
|
-
setHostContext(X) {
|
|
965
|
-
let Y = {}, Z = false;
|
|
966
|
-
for (let $ of Object.keys(X)) {
|
|
967
|
-
let K = this._hostContext[$], J = X[$];
|
|
968
|
-
if (aQ(K, J)) continue;
|
|
969
|
-
Y[$] = J, Z = true;
|
|
970
|
-
}
|
|
971
|
-
if (Z) this._hostContext = X, this.sendHostContextChange(Y);
|
|
972
|
-
}
|
|
973
|
-
sendHostContextChange(X) {
|
|
974
|
-
return this.notification({ method: "ui/notifications/host-context-changed", params: X });
|
|
975
|
-
}
|
|
976
|
-
sendToolInput(X) {
|
|
977
|
-
return this.notification({ method: "ui/notifications/tool-input", params: X });
|
|
978
|
-
}
|
|
979
|
-
sendToolInputPartial(X) {
|
|
980
|
-
return this.notification({ method: "ui/notifications/tool-input-partial", params: X });
|
|
981
|
-
}
|
|
982
|
-
sendToolResult(X) {
|
|
983
|
-
return this.notification({ method: "ui/notifications/tool-result", params: X });
|
|
984
|
-
}
|
|
985
|
-
sendToolCancelled(X) {
|
|
986
|
-
return this.notification({ method: "ui/notifications/tool-cancelled", params: X });
|
|
987
|
-
}
|
|
988
|
-
sendSandboxResourceReady(X) {
|
|
989
|
-
return this.notification({ method: "ui/notifications/sandbox-resource-ready", params: X });
|
|
990
|
-
}
|
|
991
|
-
teardownResource(X, Y) {
|
|
992
|
-
return this.request({ method: "ui/resource-teardown", params: X }, R, Y);
|
|
993
|
-
}
|
|
994
|
-
sendResourceTeardown = this.teardownResource;
|
|
995
|
-
async connect(X) {
|
|
996
|
-
if (this.transport) throw Error("AppBridge is already connected. Call close() before connecting again.");
|
|
997
|
-
if (this._client) {
|
|
998
|
-
let Y = this._client.getServerCapabilities();
|
|
999
|
-
if (!Y) throw Error("Client server capabilities not available");
|
|
1000
|
-
if (Y.tools) {
|
|
1001
|
-
if (this.oncalltool = async (Z, $) => {
|
|
1002
|
-
return this._client.request({ method: "tools/call", params: Z }, protocol.CallToolResultSchema, { signal: $.signal });
|
|
1003
|
-
}, Y.tools.listChanged) this._client.setNotificationHandler(protocol.ToolListChangedNotificationSchema, (Z) => this.sendToolListChanged(Z.params));
|
|
1004
|
-
}
|
|
1005
|
-
if (Y.resources) {
|
|
1006
|
-
if (this.onlistresources = async (Z, $) => {
|
|
1007
|
-
return this._client.request({ method: "resources/list", params: Z }, protocol.ListResourcesResultSchema, { signal: $.signal });
|
|
1008
|
-
}, this.onlistresourcetemplates = async (Z, $) => {
|
|
1009
|
-
return this._client.request({ method: "resources/templates/list", params: Z }, protocol.ListResourceTemplatesResultSchema, { signal: $.signal });
|
|
1010
|
-
}, this.onreadresource = async (Z, $) => {
|
|
1011
|
-
return this._client.request({ method: "resources/read", params: Z }, protocol.ReadResourceResultSchema, { signal: $.signal });
|
|
1012
|
-
}, Y.resources.listChanged) this._client.setNotificationHandler(protocol.ResourceListChangedNotificationSchema, (Z) => this.sendResourceListChanged(Z.params));
|
|
1013
|
-
}
|
|
1014
|
-
if (Y.prompts) {
|
|
1015
|
-
if (this.onlistprompts = async (Z, $) => {
|
|
1016
|
-
return this._client.request({ method: "prompts/list", params: Z }, protocol.ListPromptsResultSchema, { signal: $.signal });
|
|
1017
|
-
}, Y.prompts.listChanged) this._client.setNotificationHandler(protocol.PromptListChangedNotificationSchema, (Z) => this.sendPromptListChanged(Z.params));
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
return super.connect(X);
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
function aQ(X, Y) {
|
|
1024
|
-
return JSON.stringify(X) === JSON.stringify(Y);
|
|
1025
|
-
}
|
|
1026
|
-
const DEFAULT_HOST_INFO = { name: "SunpeakSimulator", version: "1.0.0" };
|
|
1027
|
-
const DEFAULT_HOST_CAPABILITIES = {
|
|
1028
|
-
openLinks: {},
|
|
1029
|
-
serverTools: {},
|
|
1030
|
-
serverResources: {},
|
|
1031
|
-
downloadFile: {},
|
|
1032
|
-
logging: {},
|
|
1033
|
-
updateModelContext: { text: {} },
|
|
1034
|
-
message: { text: {} },
|
|
1035
|
-
sandbox: {}
|
|
1036
|
-
};
|
|
1037
|
-
class McpAppHost {
|
|
1038
|
-
bridge;
|
|
1039
|
-
options;
|
|
1040
|
-
_initialized = false;
|
|
1041
|
-
_contentWindow = null;
|
|
1042
|
-
_fenceId = 0;
|
|
1043
|
-
_fenceCleanup = null;
|
|
1044
|
-
_prevDisplayMode;
|
|
1045
|
-
_pendingToolInput = null;
|
|
1046
|
-
_pendingToolResult = null;
|
|
1047
|
-
constructor(options = {}) {
|
|
1048
|
-
this.options = options;
|
|
1049
|
-
this._prevDisplayMode = options.hostContext?.displayMode;
|
|
1050
|
-
const hostInfo = options.hostInfo ?? DEFAULT_HOST_INFO;
|
|
1051
|
-
const hostCapabilities = options.hostCapabilities ?? DEFAULT_HOST_CAPABILITIES;
|
|
1052
|
-
this.bridge = new oQ(null, hostInfo, hostCapabilities, {
|
|
1053
|
-
hostContext: options.hostContext
|
|
1054
|
-
});
|
|
1055
|
-
this.bridge.oninitialized = () => {
|
|
1056
|
-
this._initialized = true;
|
|
1057
|
-
if (this._pendingToolInput) {
|
|
1058
|
-
this.bridge.sendToolInput(this._pendingToolInput);
|
|
1059
|
-
this._pendingToolInput = null;
|
|
1060
|
-
}
|
|
1061
|
-
if (this._pendingToolResult) {
|
|
1062
|
-
this.bridge.sendToolResult(this._pendingToolResult);
|
|
1063
|
-
this._pendingToolResult = null;
|
|
1064
|
-
}
|
|
1065
|
-
};
|
|
1066
|
-
this.bridge.onopenlink = async ({ url }) => {
|
|
1067
|
-
console.log("[MCP App] openLink:", url);
|
|
1068
|
-
if (this.options.onOpenLink) {
|
|
1069
|
-
this.options.onOpenLink(url);
|
|
1070
|
-
} else {
|
|
1071
|
-
try {
|
|
1072
|
-
const parsed = new URL(url);
|
|
1073
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
1074
|
-
console.warn("[MCP App] openLink blocked non-http(s) URL:", url);
|
|
1075
|
-
return {};
|
|
1076
|
-
}
|
|
1077
|
-
} catch {
|
|
1078
|
-
console.warn("[MCP App] openLink blocked invalid URL:", url);
|
|
1079
|
-
return {};
|
|
1080
|
-
}
|
|
1081
|
-
window.open(url, "_blank");
|
|
1082
|
-
}
|
|
1083
|
-
return {};
|
|
1084
|
-
};
|
|
1085
|
-
this.bridge.onmessage = async ({ role, content }) => {
|
|
1086
|
-
if (this.options.onMessage) {
|
|
1087
|
-
this.options.onMessage(role, content);
|
|
1088
|
-
} else {
|
|
1089
|
-
console.log("[MCP App] sendMessage:", { role, content });
|
|
1090
|
-
}
|
|
1091
|
-
return {};
|
|
1092
|
-
};
|
|
1093
|
-
this.bridge.onrequestdisplaymode = async ({ mode }) => {
|
|
1094
|
-
this.options.onDisplayModeChange?.(mode);
|
|
1095
|
-
return { mode };
|
|
1096
|
-
};
|
|
1097
|
-
this.bridge.onupdatemodelcontext = async ({ content, structuredContent }) => {
|
|
1098
|
-
this.options.onUpdateModelContext?.(content ?? [], structuredContent);
|
|
1099
|
-
return {};
|
|
1100
|
-
};
|
|
1101
|
-
this.bridge.onsizechange = (params) => {
|
|
1102
|
-
this.options.onSizeChanged?.(params);
|
|
1103
|
-
};
|
|
1104
|
-
this.bridge.onloggingmessage = (params) => {
|
|
1105
|
-
if (this.options.onLog) {
|
|
1106
|
-
this.options.onLog(params);
|
|
1107
|
-
} else {
|
|
1108
|
-
const level = params.level ?? "info";
|
|
1109
|
-
const prefix = `[MCP App${params.logger ? ` ${params.logger}` : ""}]`;
|
|
1110
|
-
if (level === "error" || level === "critical" || level === "alert" || level === "emergency") {
|
|
1111
|
-
console.error(prefix, params.data);
|
|
1112
|
-
} else if (level === "warning") {
|
|
1113
|
-
console.warn(prefix, params.data);
|
|
1114
|
-
} else if (level === "debug") {
|
|
1115
|
-
console.debug(prefix, params.data);
|
|
1116
|
-
} else {
|
|
1117
|
-
console.log(prefix, params.data);
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
};
|
|
1121
|
-
this.bridge.oncalltool = async (params) => {
|
|
1122
|
-
if (this.options.onCallTool) {
|
|
1123
|
-
return this.options.onCallTool(params);
|
|
1124
|
-
}
|
|
1125
|
-
console.log("[MCP App] callServerTool:", params.name, params.arguments);
|
|
1126
|
-
return {
|
|
1127
|
-
content: [
|
|
1128
|
-
{
|
|
1129
|
-
type: "text",
|
|
1130
|
-
text: `[Simulator] Tool "${params.name}" called (no handler configured)`
|
|
1131
|
-
}
|
|
1132
|
-
]
|
|
1133
|
-
};
|
|
1134
|
-
};
|
|
1135
|
-
this.bridge.ondownloadfile = async ({ contents }) => {
|
|
1136
|
-
if (this.options.onDownloadFile) {
|
|
1137
|
-
this.options.onDownloadFile(contents);
|
|
1138
|
-
} else {
|
|
1139
|
-
console.log("[MCP App] downloadFile:", contents.length, "item(s)");
|
|
1140
|
-
}
|
|
1141
|
-
return {};
|
|
1142
|
-
};
|
|
1143
|
-
this.bridge.onsandboxready = () => {
|
|
1144
|
-
this.options.onSandboxReady?.();
|
|
1145
|
-
};
|
|
1146
|
-
}
|
|
1147
|
-
/**
|
|
1148
|
-
* Connect to an iframe's contentWindow.
|
|
1149
|
-
*/
|
|
1150
|
-
async connectToIframe(contentWindow) {
|
|
1151
|
-
this._contentWindow = contentWindow;
|
|
1152
|
-
const transport = new N(contentWindow, contentWindow);
|
|
1153
|
-
await this.bridge.connect(transport);
|
|
1154
|
-
}
|
|
1155
|
-
/**
|
|
1156
|
-
* Wait for the iframe to process all pending messages and commit its DOM.
|
|
1157
|
-
*
|
|
1158
|
-
* Uses a postMessage fence: since messages to the same target are delivered
|
|
1159
|
-
* in FIFO order, a fence message sent after setHostContext is guaranteed to
|
|
1160
|
-
* be processed after the host context change. The iframe's fence responder
|
|
1161
|
-
* waits for requestAnimationFrame before acking, ensuring the DOM has been
|
|
1162
|
-
* committed for the re-render triggered by the context change.
|
|
1163
|
-
*
|
|
1164
|
-
* Returns immediately if the iframe is not connected.
|
|
1165
|
-
*/
|
|
1166
|
-
waitForPaint() {
|
|
1167
|
-
const win = this._contentWindow;
|
|
1168
|
-
if (!win) return Promise.resolve();
|
|
1169
|
-
this._fenceCleanup?.();
|
|
1170
|
-
const id = ++this._fenceId;
|
|
1171
|
-
return new Promise((resolve) => {
|
|
1172
|
-
const handler = (event) => {
|
|
1173
|
-
if (event.source !== win) return;
|
|
1174
|
-
if (event.data?.method === "sunpeak/fence-ack" && event.data.params?.fenceId === id) {
|
|
1175
|
-
cleanup();
|
|
1176
|
-
resolve();
|
|
1177
|
-
}
|
|
1178
|
-
};
|
|
1179
|
-
const cleanup = () => {
|
|
1180
|
-
window.removeEventListener("message", handler);
|
|
1181
|
-
if (this._fenceCleanup === cleanup) {
|
|
1182
|
-
this._fenceCleanup = null;
|
|
1183
|
-
}
|
|
1184
|
-
};
|
|
1185
|
-
this._fenceCleanup = cleanup;
|
|
1186
|
-
window.addEventListener("message", handler);
|
|
1187
|
-
try {
|
|
1188
|
-
win.postMessage({ jsonrpc: "2.0", method: "sunpeak/fence", params: { fenceId: id } }, "*");
|
|
1189
|
-
} catch {
|
|
1190
|
-
cleanup();
|
|
1191
|
-
resolve();
|
|
1192
|
-
}
|
|
1193
|
-
});
|
|
1194
|
-
}
|
|
1195
|
-
/**
|
|
1196
|
-
* Update the host context and notify the connected app.
|
|
1197
|
-
* Automatically detects display mode changes and waits for the iframe
|
|
1198
|
-
* to commit its DOM before firing onDisplayModeReady.
|
|
1199
|
-
*/
|
|
1200
|
-
setHostContext(context) {
|
|
1201
|
-
this.bridge.setHostContext(context);
|
|
1202
|
-
const currentMode = context.displayMode;
|
|
1203
|
-
if (currentMode && currentMode !== this._prevDisplayMode) {
|
|
1204
|
-
this._prevDisplayMode = currentMode;
|
|
1205
|
-
const mode = currentMode;
|
|
1206
|
-
this.waitForPaint().then(() => {
|
|
1207
|
-
this.options.onDisplayModeReady?.(mode);
|
|
1208
|
-
});
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
/**
|
|
1212
|
-
* Send tool input to the app.
|
|
1213
|
-
* If the app hasn't initialized yet, the input is queued.
|
|
1214
|
-
*/
|
|
1215
|
-
sendToolInput(args) {
|
|
1216
|
-
const params = { arguments: args };
|
|
1217
|
-
if (this._initialized) {
|
|
1218
|
-
this.bridge.sendToolInput(params);
|
|
1219
|
-
} else {
|
|
1220
|
-
this._pendingToolInput = params;
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
/**
|
|
1224
|
-
* Send tool result to the app.
|
|
1225
|
-
* If the app hasn't initialized yet, the result is queued.
|
|
1226
|
-
*/
|
|
1227
|
-
sendToolResult(result) {
|
|
1228
|
-
if (this._initialized) {
|
|
1229
|
-
this.bridge.sendToolResult(result);
|
|
1230
|
-
} else {
|
|
1231
|
-
this._pendingToolResult = result;
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
/**
|
|
1235
|
-
* Send partial/streaming tool input to the app.
|
|
1236
|
-
* Useful for simulating streaming tool arguments.
|
|
1237
|
-
*/
|
|
1238
|
-
sendToolInputPartial(args) {
|
|
1239
|
-
const params = { arguments: args };
|
|
1240
|
-
if (this._initialized) {
|
|
1241
|
-
this.bridge.sendToolInputPartial(params);
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
/**
|
|
1245
|
-
* Send tool cancellation notification to the app.
|
|
1246
|
-
* Simulates user or host cancelling a tool execution.
|
|
1247
|
-
*/
|
|
1248
|
-
sendToolCancelled(reason) {
|
|
1249
|
-
const params = reason ? { reason } : {};
|
|
1250
|
-
if (this._initialized) {
|
|
1251
|
-
this.bridge.sendToolCancelled(params);
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
/**
|
|
1255
|
-
* Send HTML resource to the sandbox proxy for secure loading.
|
|
1256
|
-
* Used in the double-iframe architecture after the proxy signals readiness.
|
|
1257
|
-
*/
|
|
1258
|
-
sendSandboxResourceReady(params) {
|
|
1259
|
-
this.bridge.sendSandboxResourceReady(params);
|
|
1260
|
-
}
|
|
1261
|
-
/**
|
|
1262
|
-
* Send a custom message to the connected iframe (for sandbox proxy commands).
|
|
1263
|
-
*/
|
|
1264
|
-
sendRawMessage(data) {
|
|
1265
|
-
const win = this._contentWindow;
|
|
1266
|
-
if (!win) return;
|
|
1267
|
-
try {
|
|
1268
|
-
win.postMessage(data, "*");
|
|
1269
|
-
} catch {
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
/**
|
|
1273
|
-
* Close the connection.
|
|
1274
|
-
*/
|
|
1275
|
-
async close() {
|
|
1276
|
-
this._fenceCleanup?.();
|
|
1277
|
-
this._fenceCleanup = null;
|
|
1278
|
-
try {
|
|
1279
|
-
if (this._initialized) {
|
|
1280
|
-
await this.bridge.teardownResource({});
|
|
1281
|
-
}
|
|
1282
|
-
} catch {
|
|
1283
|
-
}
|
|
1284
|
-
await this.bridge.close();
|
|
1285
|
-
this._initialized = false;
|
|
1286
|
-
}
|
|
1287
|
-
/**
|
|
1288
|
-
* Debug: Inject state directly into the app's useAppState hook.
|
|
1289
|
-
* This bypasses the normal MCP Apps protocol and is intended for
|
|
1290
|
-
* simulator testing/debugging only.
|
|
1291
|
-
*/
|
|
1292
|
-
injectState(state) {
|
|
1293
|
-
const win = this._contentWindow;
|
|
1294
|
-
if (!win) return;
|
|
1295
|
-
try {
|
|
1296
|
-
win.postMessage({ jsonrpc: "2.0", method: "sunpeak/injectState", params: { state } }, "*");
|
|
1297
|
-
} catch {
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
/**
|
|
1301
|
-
* Update mutable options (callbacks) after construction.
|
|
1302
|
-
* Allows the simulator to swap handlers (e.g. onCallTool) without
|
|
1303
|
-
* recreating the host and tearing down the iframe connection.
|
|
1304
|
-
*/
|
|
1305
|
-
updateOptions(partial) {
|
|
1306
|
-
Object.assign(this.options, partial);
|
|
1307
|
-
}
|
|
1308
|
-
get initialized() {
|
|
1309
|
-
return this._initialized;
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
const MOCK_OPENAI_RUNTIME_SCRIPT = [
|
|
1313
|
-
"window.openai={",
|
|
1314
|
-
'uploadFile:function(f){console.log("[Simulator] uploadFile:",f.name);',
|
|
1315
|
-
'return Promise.resolve({fileId:"sim_file_"+Date.now()})},',
|
|
1316
|
-
'getFileDownloadUrl:function(p){console.log("[Simulator] getFileDownloadUrl:",p.fileId);',
|
|
1317
|
-
'return Promise.resolve({downloadUrl:"https://simulator.local/files/"+p.fileId})},',
|
|
1318
|
-
'requestModal:function(p){console.log("[Simulator] requestModal:",JSON.stringify(p));',
|
|
1319
|
-
"return Promise.resolve()},",
|
|
1320
|
-
'requestCheckout:function(s){console.log("[Simulator] requestCheckout:",JSON.stringify(s));',
|
|
1321
|
-
'return Promise.resolve({id:"sim_order_"+Date.now(),checkout_session_id:s.id||"sim_session",status:"completed"})},',
|
|
1322
|
-
'requestClose:function(){console.log("[Simulator] requestClose")},',
|
|
1323
|
-
'requestDisplayMode:function(p){console.log("[Simulator] requestDisplayMode:",p.mode);',
|
|
1324
|
-
"return Promise.resolve()},",
|
|
1325
|
-
'sendFollowUpMessage:function(p){console.log("[Simulator] sendFollowUpMessage:",p.prompt)},',
|
|
1326
|
-
'openExternal:function(p){console.log("[Simulator] openExternal:",p.href);window.open(p.href,"_blank")}',
|
|
1327
|
-
"};"
|
|
1328
|
-
].join("");
|
|
1329
|
-
function generateSandboxProxyHtml(platformScript) {
|
|
1330
|
-
const escapedPlatformScript = platformScript ? JSON.stringify(platformScript) : "null";
|
|
1331
|
-
const colorScheme = "dark";
|
|
1332
|
-
return `<!DOCTYPE html>
|
|
1333
|
-
<html style="color-scheme:${colorScheme}">
|
|
1334
|
-
<head>
|
|
1335
|
-
<meta name="color-scheme" content="${colorScheme}" />
|
|
1336
|
-
<style>
|
|
1337
|
-
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; }
|
|
1338
|
-
iframe { border: none; width: 100%; height: 100%; display: block; }
|
|
1339
|
-
</style>
|
|
1340
|
-
</head>
|
|
1341
|
-
<body>
|
|
1342
|
-
<script>
|
|
1343
|
-
(function() {
|
|
1344
|
-
var innerFrame = null;
|
|
1345
|
-
var innerWindow = null;
|
|
1346
|
-
var platformScript = ${escapedPlatformScript};
|
|
1347
|
-
|
|
1348
|
-
// Relay messages between parent (host) and inner iframe (app)
|
|
1349
|
-
window.addEventListener('message', function(event) {
|
|
1350
|
-
var data = event.data;
|
|
1351
|
-
if (!data || typeof data !== 'object') return;
|
|
1352
|
-
|
|
1353
|
-
if (event.source === window.parent) {
|
|
1354
|
-
// ── Messages from the host ──
|
|
1355
|
-
|
|
1356
|
-
// sandbox-resource-ready: load HTML into inner iframe (scriptSrc/prod mode)
|
|
1357
|
-
if (data.method === 'ui/notifications/sandbox-resource-ready' && data.params) {
|
|
1358
|
-
createInnerFrame(data.params);
|
|
1359
|
-
return;
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1362
|
-
// sunpeak/sandbox-load-src: load URL into inner iframe (src/dev mode)
|
|
1363
|
-
if (data.method === 'sunpeak/sandbox-load-src' && data.params) {
|
|
1364
|
-
createInnerFrameWithSrc(data.params);
|
|
1365
|
-
return;
|
|
1366
|
-
}
|
|
1367
|
-
|
|
1368
|
-
// Handle paint fence. Forward to the inner iframe and wait for its ack.
|
|
1369
|
-
// If the inner iframe has a fence responder (same-origin, script injected),
|
|
1370
|
-
// the ack is deterministic. Otherwise fall back to a 150ms timeout.
|
|
1371
|
-
if (data.method === 'sunpeak/fence' && data.params) {
|
|
1372
|
-
var fenceId = data.params.fenceId;
|
|
1373
|
-
var acked = false;
|
|
1374
|
-
var onAck = function(e) {
|
|
1375
|
-
if (e.source !== innerWindow) return;
|
|
1376
|
-
if (e.data && e.data.method === 'sunpeak/fence-ack' &&
|
|
1377
|
-
e.data.params && e.data.params.fenceId === fenceId) {
|
|
1378
|
-
acked = true;
|
|
1379
|
-
window.removeEventListener('message', onAck);
|
|
1380
|
-
window.parent.postMessage(e.data, '*');
|
|
1381
|
-
}
|
|
1382
|
-
};
|
|
1383
|
-
window.addEventListener('message', onAck);
|
|
1384
|
-
if (innerWindow) {
|
|
1385
|
-
try { innerWindow.postMessage(data, '*'); } catch(e) {}
|
|
1386
|
-
}
|
|
1387
|
-
setTimeout(function() {
|
|
1388
|
-
if (!acked) {
|
|
1389
|
-
window.removeEventListener('message', onAck);
|
|
1390
|
-
window.parent.postMessage({
|
|
1391
|
-
jsonrpc: '2.0',
|
|
1392
|
-
method: 'sunpeak/fence-ack',
|
|
1393
|
-
params: { fenceId: fenceId }
|
|
1394
|
-
}, '*');
|
|
1395
|
-
}
|
|
1396
|
-
}, 150);
|
|
1397
|
-
return;
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
// Forward all other messages to the inner iframe
|
|
1401
|
-
if (innerWindow) {
|
|
1402
|
-
try { innerWindow.postMessage(data, '*'); } catch(e) { /* detached */ }
|
|
1403
|
-
}
|
|
1404
|
-
} else if (innerWindow && event.source === innerWindow) {
|
|
1405
|
-
// ── Messages from the app → forward to host ──
|
|
1406
|
-
try { window.parent.postMessage(data, '*'); } catch(e) { /* detached */ }
|
|
1407
|
-
}
|
|
1408
|
-
});
|
|
1409
|
-
|
|
1410
|
-
function createInnerFrame(params) {
|
|
1411
|
-
if (innerFrame) innerFrame.remove();
|
|
1412
|
-
|
|
1413
|
-
innerFrame = document.createElement('iframe');
|
|
1414
|
-
innerFrame.sandbox = params.sandbox ||
|
|
1415
|
-
'allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox';
|
|
1416
|
-
if (params.allow) innerFrame.allow = params.allow;
|
|
1417
|
-
document.body.appendChild(innerFrame);
|
|
1418
|
-
innerWindow = innerFrame.contentWindow;
|
|
1419
|
-
|
|
1420
|
-
// Write HTML content into the inner iframe
|
|
1421
|
-
var doc = innerFrame.contentDocument;
|
|
1422
|
-
if (doc && params.html) {
|
|
1423
|
-
doc.open();
|
|
1424
|
-
doc.write(params.html);
|
|
1425
|
-
doc.close();
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
function createInnerFrameWithSrc(params) {
|
|
1430
|
-
if (innerFrame) innerFrame.remove();
|
|
1431
|
-
|
|
1432
|
-
innerFrame = document.createElement('iframe');
|
|
1433
|
-
innerFrame.sandbox =
|
|
1434
|
-
'allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox';
|
|
1435
|
-
if (params.allow) innerFrame.allow = params.allow;
|
|
1436
|
-
innerFrame.src = params.src;
|
|
1437
|
-
innerFrame.style.height = '100%';
|
|
1438
|
-
|
|
1439
|
-
// Set color-scheme on the inner iframe to match the host theme.
|
|
1440
|
-
// This ensures prefers-color-scheme resolves correctly inside.
|
|
1441
|
-
if (params.theme) {
|
|
1442
|
-
innerFrame.style.colorScheme = params.theme;
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1445
|
-
// After load, inject helpers into the inner iframe
|
|
1446
|
-
innerFrame.addEventListener('load', function() {
|
|
1447
|
-
innerWindow = innerFrame.contentWindow;
|
|
1448
|
-
|
|
1449
|
-
// Inject platform runtime (e.g., mock window.openai for ChatGPT)
|
|
1450
|
-
if (platformScript && innerWindow) {
|
|
1451
|
-
try {
|
|
1452
|
-
var pScript = innerFrame.contentDocument.createElement('script');
|
|
1453
|
-
pScript.textContent = platformScript;
|
|
1454
|
-
innerFrame.contentDocument.head.appendChild(pScript);
|
|
1455
|
-
} catch(e) { /* cross-origin */ }
|
|
1456
|
-
}
|
|
1457
|
-
|
|
1458
|
-
// Inject paint fence responder
|
|
1459
|
-
try {
|
|
1460
|
-
var fenceScript = innerFrame.contentDocument.createElement('script');
|
|
1461
|
-
fenceScript.setAttribute('data-sunpeak-fence', '');
|
|
1462
|
-
fenceScript.textContent = PAINT_FENCE_SCRIPT;
|
|
1463
|
-
innerFrame.contentDocument.head.appendChild(fenceScript);
|
|
1464
|
-
} catch(e) { /* cross-origin */ }
|
|
1465
|
-
|
|
1466
|
-
// Inject background rule
|
|
1467
|
-
if (params.theme) {
|
|
1468
|
-
try {
|
|
1469
|
-
innerFrame.contentDocument.documentElement.style.colorScheme = params.theme;
|
|
1470
|
-
var bgStyle = innerFrame.contentDocument.createElement('style');
|
|
1471
|
-
bgStyle.setAttribute('data-sunpeak-bg', '');
|
|
1472
|
-
bgStyle.textContent = 'html { background-color: var(--color-background-primary, Canvas); }';
|
|
1473
|
-
innerFrame.contentDocument.head.appendChild(bgStyle);
|
|
1474
|
-
} catch(e) { /* cross-origin */ }
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
// Inject style variables for immediate rendering
|
|
1478
|
-
if (params.styleVars) {
|
|
1479
|
-
try {
|
|
1480
|
-
var root = innerFrame.contentDocument.documentElement;
|
|
1481
|
-
for (var key in params.styleVars) {
|
|
1482
|
-
if (params.styleVars[key]) root.style.setProperty(key, params.styleVars[key]);
|
|
1483
|
-
}
|
|
1484
|
-
} catch(e) { /* cross-origin */ }
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1487
|
-
// Signal that load is complete — fade in
|
|
1488
|
-
innerFrame.style.opacity = '1';
|
|
1489
|
-
innerFrame.style.transition = 'opacity 100ms';
|
|
1490
|
-
});
|
|
1491
|
-
|
|
1492
|
-
// Start hidden for smooth fade-in
|
|
1493
|
-
innerFrame.style.opacity = '0';
|
|
1494
|
-
document.body.appendChild(innerFrame);
|
|
1495
|
-
innerWindow = innerFrame.contentWindow;
|
|
1496
|
-
}
|
|
1497
|
-
|
|
1498
|
-
// Paint fence responder — same as in iframe-resource.ts
|
|
1499
|
-
var PAINT_FENCE_SCRIPT = 'window.addEventListener("message",function(e){' +
|
|
1500
|
-
'if(e.data&&e.data.method==="sunpeak/fence"){' +
|
|
1501
|
-
'var fid=e.data.params&&e.data.params.fenceId;' +
|
|
1502
|
-
'requestAnimationFrame(function(){' +
|
|
1503
|
-
'e.source.postMessage({jsonrpc:"2.0",method:"sunpeak/fence-ack",params:{fenceId:fid}},"*");' +
|
|
1504
|
-
'});}});';
|
|
1505
|
-
|
|
1506
|
-
// Signal to the host that the proxy is ready.
|
|
1507
|
-
// Use setTimeout to ensure the host's PostMessageTransport listener
|
|
1508
|
-
// is set up before we send the ready notification. The srcdoc is parsed
|
|
1509
|
-
// synchronously by the browser, which can race with React's ref callback.
|
|
1510
|
-
setTimeout(function() {
|
|
1511
|
-
window.parent.postMessage({
|
|
1512
|
-
jsonrpc: '2.0',
|
|
1513
|
-
method: 'ui/notifications/sandbox-proxy-ready',
|
|
1514
|
-
params: {}
|
|
1515
|
-
}, '*');
|
|
1516
|
-
}, 0);
|
|
1517
|
-
})();
|
|
1518
|
-
<\/script>
|
|
1519
|
-
</body>
|
|
1520
|
-
</html>`;
|
|
1521
|
-
}
|
|
1522
|
-
const ALLOWED_SCRIPT_ORIGINS = [
|
|
1523
|
-
"https://sunpeak-prod-app-storage.s3.us-east-2.amazonaws.com",
|
|
1524
|
-
"http://localhost",
|
|
1525
|
-
"https://localhost",
|
|
1526
|
-
"http://127.0.0.1",
|
|
1527
|
-
"https://127.0.0.1"
|
|
1528
|
-
];
|
|
1529
|
-
function escapeHtml(str) {
|
|
1530
|
-
return str.replace(/[&<>"']/g, (c2) => {
|
|
1531
|
-
const entities = {
|
|
1532
|
-
"&": "&",
|
|
1533
|
-
"<": "<",
|
|
1534
|
-
">": ">",
|
|
1535
|
-
'"': """,
|
|
1536
|
-
"'": "'"
|
|
1537
|
-
};
|
|
1538
|
-
return entities[c2] ?? c2;
|
|
1539
|
-
});
|
|
1540
|
-
}
|
|
1541
|
-
function isAllowedUrl(src) {
|
|
1542
|
-
if (!src) return false;
|
|
1543
|
-
if (src.startsWith("/") && !src.startsWith("//")) return true;
|
|
1544
|
-
if (!src.includes("://")) return false;
|
|
1545
|
-
try {
|
|
1546
|
-
const url = new URL(src);
|
|
1547
|
-
if (url.origin === window.location.origin) return true;
|
|
1548
|
-
if (url.hostname === "localhost" || url.hostname === "127.0.0.1") return true;
|
|
1549
|
-
return ALLOWED_SCRIPT_ORIGINS.some((allowed) => {
|
|
1550
|
-
try {
|
|
1551
|
-
return url.origin === new URL(allowed).origin;
|
|
1552
|
-
} catch {
|
|
1553
|
-
return false;
|
|
1554
|
-
}
|
|
1555
|
-
});
|
|
1556
|
-
} catch {
|
|
1557
|
-
return false;
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
|
-
function extractResourceCSP(resource) {
|
|
1561
|
-
const meta = resource._meta;
|
|
1562
|
-
const ui = meta?.ui;
|
|
1563
|
-
return ui?.csp;
|
|
1564
|
-
}
|
|
1565
|
-
function isValidCspSource(source) {
|
|
1566
|
-
if (!source || /[\s;,']/.test(source) || source === "*") return false;
|
|
1567
|
-
try {
|
|
1568
|
-
const url = new URL(source);
|
|
1569
|
-
return url.protocol === "http:" || url.protocol === "https:" || url.protocol === "ws:" || url.protocol === "wss:";
|
|
1570
|
-
} catch {
|
|
1571
|
-
return false;
|
|
1572
|
-
}
|
|
1573
|
-
}
|
|
1574
|
-
function generateCSP(csp, scriptSrc) {
|
|
1575
|
-
let scriptOrigin = "";
|
|
1576
|
-
try {
|
|
1577
|
-
scriptOrigin = new URL(scriptSrc, window.location.origin).origin;
|
|
1578
|
-
} catch {
|
|
1579
|
-
}
|
|
1580
|
-
const frameSources = /* @__PURE__ */ new Set();
|
|
1581
|
-
if (csp?.frameDomains) {
|
|
1582
|
-
for (const domain of csp.frameDomains) {
|
|
1583
|
-
if (isValidCspSource(domain)) {
|
|
1584
|
-
frameSources.add(domain);
|
|
1585
|
-
} else {
|
|
1586
|
-
console.warn("[IframeResource] Ignoring invalid CSP frame domain:", domain);
|
|
1587
|
-
}
|
|
1588
|
-
}
|
|
1589
|
-
}
|
|
1590
|
-
const frameSrc = frameSources.size > 0 ? `frame-src ${Array.from(frameSources).join(" ")}` : "frame-src 'none'";
|
|
1591
|
-
const baseSources = /* @__PURE__ */ new Set(["'self'"]);
|
|
1592
|
-
if (csp?.baseUriDomains) {
|
|
1593
|
-
for (const domain of csp.baseUriDomains) {
|
|
1594
|
-
if (isValidCspSource(domain)) {
|
|
1595
|
-
baseSources.add(domain);
|
|
1596
|
-
} else {
|
|
1597
|
-
console.warn("[IframeResource] Ignoring invalid CSP base-uri domain:", domain);
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
const directives = [
|
|
1602
|
-
"default-src 'none'",
|
|
1603
|
-
`script-src 'self' 'unsafe-inline' 'unsafe-eval' blob: ${scriptOrigin}`.trim(),
|
|
1604
|
-
`style-src 'self' 'unsafe-inline' ${scriptOrigin}`.trim(),
|
|
1605
|
-
frameSrc,
|
|
1606
|
-
"object-src 'none'",
|
|
1607
|
-
"form-action 'none'",
|
|
1608
|
-
`base-uri ${Array.from(baseSources).join(" ")}`
|
|
1609
|
-
];
|
|
1610
|
-
const connectSources = /* @__PURE__ */ new Set(["'self'"]);
|
|
1611
|
-
if (scriptOrigin) connectSources.add(scriptOrigin);
|
|
1612
|
-
if (csp?.connectDomains) {
|
|
1613
|
-
for (const domain of csp.connectDomains) {
|
|
1614
|
-
if (isValidCspSource(domain)) {
|
|
1615
|
-
connectSources.add(domain);
|
|
1616
|
-
} else {
|
|
1617
|
-
console.warn("[IframeResource] Ignoring invalid CSP connect domain:", domain);
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
}
|
|
1621
|
-
directives.push(`connect-src ${Array.from(connectSources).join(" ")}`);
|
|
1622
|
-
const resourceSources = /* @__PURE__ */ new Set(["'self'", "data:", "blob:"]);
|
|
1623
|
-
if (scriptOrigin) resourceSources.add(scriptOrigin);
|
|
1624
|
-
if (csp?.resourceDomains) {
|
|
1625
|
-
for (const domain of csp.resourceDomains) {
|
|
1626
|
-
if (isValidCspSource(domain)) {
|
|
1627
|
-
resourceSources.add(domain);
|
|
1628
|
-
} else {
|
|
1629
|
-
console.warn("[IframeResource] Ignoring invalid CSP resource domain:", domain);
|
|
1630
|
-
}
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
const resourceList = Array.from(resourceSources).join(" ");
|
|
1634
|
-
directives.push(`img-src ${resourceList}`);
|
|
1635
|
-
directives.push(`font-src ${resourceList}`);
|
|
1636
|
-
directives.push(`media-src ${resourceList}`);
|
|
1637
|
-
return directives.join("; ");
|
|
1638
|
-
}
|
|
1639
|
-
const PAINT_FENCE_SCRIPT = `window.addEventListener("message",function(e){
|
|
1640
|
-
if(e.data&&e.data.method==="sunpeak/fence"){
|
|
1641
|
-
var fid=e.data.params&&e.data.params.fenceId;
|
|
1642
|
-
requestAnimationFrame(function(){
|
|
1643
|
-
e.source.postMessage({jsonrpc:"2.0",method:"sunpeak/fence-ack",params:{fenceId:fid}},"*");
|
|
1644
|
-
});}});`;
|
|
1645
|
-
function generateScriptHtml(scriptSrc, theme, cspPolicy, platformScript) {
|
|
1646
|
-
const safeScriptSrc = escapeHtml(scriptSrc);
|
|
1647
|
-
const safeCsp = escapeHtml(cspPolicy);
|
|
1648
|
-
const safeTheme = escapeHtml(theme);
|
|
1649
|
-
const platformTag = platformScript ? `
|
|
1650
|
-
<script>${platformScript}<\/script>` : "";
|
|
1651
|
-
return `<!DOCTYPE html>
|
|
1652
|
-
<html lang="en" data-theme="${safeTheme}" style="color-scheme:${safeTheme};background:Canvas">
|
|
1653
|
-
<head>
|
|
1654
|
-
<meta charset="UTF-8" />
|
|
1655
|
-
<meta name="color-scheme" content="${safeTheme}" />
|
|
1656
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
1657
|
-
<meta http-equiv="Content-Security-Policy" content="${safeCsp}" />
|
|
1658
|
-
<title>Resource</title>
|
|
1659
|
-
<style>
|
|
1660
|
-
html {
|
|
1661
|
-
/* Use the MCP App background variable once JS sets it, otherwise
|
|
1662
|
-
Canvas (the system color that auto-adapts to color-scheme). */
|
|
1663
|
-
background-color: var(--color-background-primary, Canvas);
|
|
1664
|
-
}
|
|
1665
|
-
body, #root {
|
|
1666
|
-
margin: 0;
|
|
1667
|
-
padding: 0;
|
|
1668
|
-
width: 100%;
|
|
1669
|
-
background: transparent;
|
|
1670
|
-
}
|
|
1671
|
-
</style>
|
|
1672
|
-
<script>${PAINT_FENCE_SCRIPT}<\/script>${platformTag}
|
|
1673
|
-
</head>
|
|
1674
|
-
<body>
|
|
1675
|
-
<div id="root"></div>
|
|
1676
|
-
<script src="${safeScriptSrc}"><\/script>
|
|
1677
|
-
</body>
|
|
1678
|
-
</html>`;
|
|
1679
|
-
}
|
|
1680
|
-
function buildIframeAllow(permissions) {
|
|
1681
|
-
const parts = [
|
|
1682
|
-
"local-network-access *"
|
|
1683
|
-
// Always needed for local dev server access
|
|
1684
|
-
];
|
|
1685
|
-
const permMap = [
|
|
1686
|
-
["camera", "camera"],
|
|
1687
|
-
["microphone", "microphone"],
|
|
1688
|
-
["geolocation", "geolocation"],
|
|
1689
|
-
["clipboardWrite", "clipboard-write"]
|
|
1690
|
-
];
|
|
1691
|
-
for (const [key, directive] of permMap) {
|
|
1692
|
-
if (permissions?.[key]) {
|
|
1693
|
-
parts.push(directive);
|
|
1694
|
-
}
|
|
1695
|
-
}
|
|
1696
|
-
return parts.join("; ");
|
|
1697
|
-
}
|
|
1698
|
-
function IframeResource({
|
|
1699
|
-
src,
|
|
1700
|
-
scriptSrc,
|
|
1701
|
-
hostContext,
|
|
1702
|
-
toolInput,
|
|
1703
|
-
toolInputPartial,
|
|
1704
|
-
toolResult,
|
|
1705
|
-
hostOptions,
|
|
1706
|
-
csp,
|
|
1707
|
-
permissions,
|
|
1708
|
-
prefersBorder,
|
|
1709
|
-
className,
|
|
1710
|
-
style,
|
|
1711
|
-
onDisplayModeReady,
|
|
1712
|
-
debugInjectState,
|
|
1713
|
-
injectOpenAIRuntime,
|
|
1714
|
-
sandboxUrl
|
|
1715
|
-
}) {
|
|
1716
|
-
const iframeRef = React.useRef(null);
|
|
1717
|
-
const hostRef = React.useRef(null);
|
|
1718
|
-
const resourceUrl = src ?? scriptSrc;
|
|
1719
|
-
const srcRef = React.useRef(src);
|
|
1720
|
-
srcRef.current = src;
|
|
1721
|
-
const scriptSrcRef = React.useRef(scriptSrc);
|
|
1722
|
-
scriptSrcRef.current = scriptSrc;
|
|
1723
|
-
const cspRef = React.useRef(csp);
|
|
1724
|
-
cspRef.current = csp;
|
|
1725
|
-
const hostContextRef = React.useRef(hostContext);
|
|
1726
|
-
hostContextRef.current = hostContext;
|
|
1727
|
-
const injectOpenAIRuntimeRef = React.useRef(injectOpenAIRuntime);
|
|
1728
|
-
injectOpenAIRuntimeRef.current = injectOpenAIRuntime;
|
|
1729
|
-
const permissionsRef = React.useRef(permissions);
|
|
1730
|
-
permissionsRef.current = permissions;
|
|
1731
|
-
const hasReceivedSizeRef = React.useRef(false);
|
|
1732
|
-
const displayModeRef = React.useRef(hostContext?.displayMode);
|
|
1733
|
-
displayModeRef.current = hostContext?.displayMode;
|
|
1734
|
-
const lastContentHeightRef = React.useRef(null);
|
|
1735
|
-
const host = React.useMemo(
|
|
1736
|
-
() => new McpAppHost({
|
|
1737
|
-
hostContext,
|
|
1738
|
-
...hostOptions,
|
|
1739
|
-
onSizeChanged: (params) => {
|
|
1740
|
-
hostOptions?.onSizeChanged?.(params);
|
|
1741
|
-
if (params.height != null) {
|
|
1742
|
-
lastContentHeightRef.current = params.height;
|
|
1743
|
-
}
|
|
1744
|
-
if (displayModeRef.current === "fullscreen") return;
|
|
1745
|
-
const iframe = iframeRef.current;
|
|
1746
|
-
if (!iframe) return;
|
|
1747
|
-
const style2 = getComputedStyle(iframe);
|
|
1748
|
-
const isBorderBox = style2.boxSizing === "border-box";
|
|
1749
|
-
const from = {};
|
|
1750
|
-
const to = {};
|
|
1751
|
-
if (params.width != null) {
|
|
1752
|
-
let w = params.width;
|
|
1753
|
-
if (isBorderBox) {
|
|
1754
|
-
w += parseFloat(style2.borderLeftWidth) + parseFloat(style2.borderRightWidth);
|
|
1755
|
-
}
|
|
1756
|
-
from.minWidth = `${iframe.offsetWidth}px`;
|
|
1757
|
-
iframe.style.minWidth = `min(${w}px, 100%)`;
|
|
1758
|
-
to.minWidth = `min(${w}px, 100%)`;
|
|
1759
|
-
}
|
|
1760
|
-
if (params.height != null) {
|
|
1761
|
-
hasReceivedSizeRef.current = true;
|
|
1762
|
-
let h = params.height;
|
|
1763
|
-
if (isBorderBox) {
|
|
1764
|
-
h += parseFloat(style2.borderTopWidth) + parseFloat(style2.borderBottomWidth);
|
|
1765
|
-
}
|
|
1766
|
-
from.height = `${iframe.offsetHeight}px`;
|
|
1767
|
-
iframe.style.height = `${h}px`;
|
|
1768
|
-
to.height = `${h}px`;
|
|
1769
|
-
}
|
|
1770
|
-
if (Object.keys(from).length > 0) {
|
|
1771
|
-
iframe.animate([from, to], { duration: 300, easing: "ease-out" });
|
|
1772
|
-
}
|
|
1773
|
-
},
|
|
1774
|
-
onDisplayModeReady: (mode) => onDisplayModeReady?.(mode),
|
|
1775
|
-
onSandboxReady: () => {
|
|
1776
|
-
const currentSrc = srcRef.current;
|
|
1777
|
-
const currentScriptSrc = scriptSrcRef.current;
|
|
1778
|
-
const currentHost = hostRef.current;
|
|
1779
|
-
if (!currentHost) return;
|
|
1780
|
-
if (currentScriptSrc) {
|
|
1781
|
-
const absoluteScriptSrc = currentScriptSrc.startsWith("/") ? `${window.location.origin}${currentScriptSrc}` : currentScriptSrc;
|
|
1782
|
-
const cspPolicy = generateCSP(cspRef.current, absoluteScriptSrc);
|
|
1783
|
-
const theme = hostContextRef.current?.theme ?? "dark";
|
|
1784
|
-
const platformScriptStr = injectOpenAIRuntimeRef.current ? MOCK_OPENAI_RUNTIME_SCRIPT : void 0;
|
|
1785
|
-
const appHtml = generateScriptHtml(
|
|
1786
|
-
absoluteScriptSrc,
|
|
1787
|
-
theme,
|
|
1788
|
-
cspPolicy,
|
|
1789
|
-
platformScriptStr
|
|
1790
|
-
);
|
|
1791
|
-
currentHost.sendSandboxResourceReady({
|
|
1792
|
-
html: appHtml,
|
|
1793
|
-
sandbox: "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox"
|
|
1794
|
-
});
|
|
1795
|
-
if (iframeRef.current) {
|
|
1796
|
-
iframeRef.current.style.opacity = "1";
|
|
1797
|
-
iframeRef.current.style.transition = "opacity 100ms";
|
|
1798
|
-
}
|
|
1799
|
-
} else if (currentSrc) {
|
|
1800
|
-
const absoluteSrc = currentSrc.startsWith("/") ? `${window.location.origin}${currentSrc}` : currentSrc;
|
|
1801
|
-
const allowAttr = buildIframeAllow(permissionsRef.current);
|
|
1802
|
-
currentHost.sendRawMessage({
|
|
1803
|
-
jsonrpc: "2.0",
|
|
1804
|
-
method: "sunpeak/sandbox-load-src",
|
|
1805
|
-
params: {
|
|
1806
|
-
src: absoluteSrc,
|
|
1807
|
-
allow: allowAttr,
|
|
1808
|
-
theme: hostContextRef.current?.theme,
|
|
1809
|
-
styleVars: hostContextRef.current?.styles?.variables
|
|
1810
|
-
}
|
|
1811
|
-
});
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
}),
|
|
1815
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1816
|
-
[]
|
|
1817
|
-
// Stable - create once
|
|
1818
|
-
);
|
|
1819
|
-
hostRef.current = host;
|
|
1820
|
-
const setIframeRef = React.useCallback(
|
|
1821
|
-
(node) => {
|
|
1822
|
-
iframeRef.current = node;
|
|
1823
|
-
if (node?.contentWindow) {
|
|
1824
|
-
host.connectToIframe(node.contentWindow);
|
|
1825
|
-
}
|
|
1826
|
-
},
|
|
1827
|
-
[host]
|
|
1828
|
-
);
|
|
1829
|
-
const handleLoad = React.useCallback(() => {
|
|
1830
|
-
if (iframeRef.current) {
|
|
1831
|
-
iframeRef.current.style.opacity = "1";
|
|
1832
|
-
iframeRef.current.style.transition = "opacity 100ms";
|
|
1833
|
-
}
|
|
1834
|
-
}, []);
|
|
1835
|
-
React.useEffect(() => {
|
|
1836
|
-
if (hostOptions) {
|
|
1837
|
-
host.updateOptions(hostOptions);
|
|
1838
|
-
}
|
|
1839
|
-
}, [host, hostOptions]);
|
|
1840
|
-
React.useEffect(() => {
|
|
1841
|
-
if (hostContext) {
|
|
1842
|
-
host.setHostContext(hostContext);
|
|
1843
|
-
}
|
|
1844
|
-
if (iframeRef.current) {
|
|
1845
|
-
if (hostContext?.displayMode === "fullscreen") {
|
|
1846
|
-
iframeRef.current.style.height = "100%";
|
|
1847
|
-
} else if (lastContentHeightRef.current != null) {
|
|
1848
|
-
iframeRef.current.style.height = `${lastContentHeightRef.current}px`;
|
|
1849
|
-
}
|
|
1850
|
-
}
|
|
1851
|
-
}, [host, hostContext]);
|
|
1852
|
-
React.useEffect(() => {
|
|
1853
|
-
if (toolInput) {
|
|
1854
|
-
host.sendToolInput(toolInput);
|
|
1855
|
-
}
|
|
1856
|
-
}, [host, toolInput]);
|
|
1857
|
-
React.useEffect(() => {
|
|
1858
|
-
if (toolInputPartial) {
|
|
1859
|
-
host.sendToolInputPartial(toolInputPartial);
|
|
1860
|
-
}
|
|
1861
|
-
}, [host, toolInputPartial]);
|
|
1862
|
-
React.useEffect(() => {
|
|
1863
|
-
if (toolResult) {
|
|
1864
|
-
host.sendToolResult(toolResult);
|
|
1865
|
-
}
|
|
1866
|
-
}, [host, toolResult]);
|
|
1867
|
-
React.useEffect(() => {
|
|
1868
|
-
if (debugInjectState != null) {
|
|
1869
|
-
host.injectState(debugInjectState);
|
|
1870
|
-
}
|
|
1871
|
-
}, [host, debugInjectState]);
|
|
1872
|
-
React.useEffect(() => {
|
|
1873
|
-
return () => {
|
|
1874
|
-
hostRef.current?.close();
|
|
1875
|
-
};
|
|
1876
|
-
}, []);
|
|
1877
|
-
const isValidUrl = React.useMemo(() => resourceUrl && isAllowedUrl(resourceUrl), [resourceUrl]);
|
|
1878
|
-
const allowAttribute = React.useMemo(() => buildIframeAllow(permissions), [permissions]);
|
|
1879
|
-
const borderStyle = prefersBorder ? { border: "1px solid var(--color-border-primary, #e5e7eb)" } : { border: "none" };
|
|
1880
|
-
const sandboxSrc = React.useMemo(() => {
|
|
1881
|
-
if (!sandboxUrl) return void 0;
|
|
1882
|
-
const url = new URL("/proxy", sandboxUrl);
|
|
1883
|
-
if (injectOpenAIRuntime) url.searchParams.set("platform", "chatgpt");
|
|
1884
|
-
return url.toString();
|
|
1885
|
-
}, [sandboxUrl, injectOpenAIRuntime]);
|
|
1886
|
-
const proxyHtml = React.useMemo(() => {
|
|
1887
|
-
if (sandboxSrc) return void 0;
|
|
1888
|
-
const platformScript = injectOpenAIRuntime ? MOCK_OPENAI_RUNTIME_SCRIPT : void 0;
|
|
1889
|
-
return generateSandboxProxyHtml(platformScript);
|
|
1890
|
-
}, [sandboxSrc, injectOpenAIRuntime]);
|
|
1891
|
-
const iframeStyle = {
|
|
1892
|
-
...borderStyle,
|
|
1893
|
-
background: "transparent",
|
|
1894
|
-
colorScheme: hostContext?.theme === "light" ? "light dark" : "dark light",
|
|
1895
|
-
// Start hidden; handleLoad fades in via direct DOM update
|
|
1896
|
-
opacity: 0,
|
|
1897
|
-
width: "100%",
|
|
1898
|
-
// In fullscreen, fill the container immediately. In other modes, use
|
|
1899
|
-
// minHeight to prevent collapse while waiting for the app to report size.
|
|
1900
|
-
...hostContext?.displayMode === "fullscreen" ? { height: "100%" } : { minHeight: "200px" },
|
|
1901
|
-
...style
|
|
1902
|
-
};
|
|
1903
|
-
const dims = hostContext?.containerDimensions;
|
|
1904
|
-
const isFullscreenMode = hostContext?.displayMode === "fullscreen";
|
|
1905
|
-
const wrapperStyle = {};
|
|
1906
|
-
if (dims && !isFullscreenMode) {
|
|
1907
|
-
const h = "height" in dims ? dims.height : void 0;
|
|
1908
|
-
const mh = "maxHeight" in dims ? dims.maxHeight : void 0;
|
|
1909
|
-
const w = "width" in dims ? dims.width : void 0;
|
|
1910
|
-
const mw = "maxWidth" in dims ? dims.maxWidth : void 0;
|
|
1911
|
-
if (h != null) {
|
|
1912
|
-
wrapperStyle.height = h;
|
|
1913
|
-
wrapperStyle.overflow = "hidden";
|
|
1914
|
-
}
|
|
1915
|
-
if (mh != null) {
|
|
1916
|
-
wrapperStyle.maxHeight = mh;
|
|
1917
|
-
wrapperStyle.overflow = "hidden";
|
|
1918
|
-
}
|
|
1919
|
-
if (w != null) wrapperStyle.width = w;
|
|
1920
|
-
if (mw != null) wrapperStyle.maxWidth = mw;
|
|
1921
|
-
}
|
|
1922
|
-
if (src && !isValidUrl) {
|
|
1923
|
-
console.error("[IframeResource] URL not allowed:", src);
|
|
1924
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { color: "red", padding: 20 }, children: [
|
|
1925
|
-
"Error: URL not allowed: ",
|
|
1926
|
-
src
|
|
1927
|
-
] });
|
|
1928
|
-
}
|
|
1929
|
-
if (scriptSrc && !isValidUrl) {
|
|
1930
|
-
console.error("[IframeResource] Script source not allowed:", scriptSrc);
|
|
1931
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "red", padding: 20 }, children: "Error: Script source not allowed." });
|
|
1932
|
-
}
|
|
1933
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", { className, style: wrapperStyle, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1934
|
-
"iframe",
|
|
1935
|
-
{
|
|
1936
|
-
ref: setIframeRef,
|
|
1937
|
-
onLoad: handleLoad,
|
|
1938
|
-
style: iframeStyle,
|
|
1939
|
-
title: "Resource Preview",
|
|
1940
|
-
sandbox: "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox",
|
|
1941
|
-
allow: allowAttribute,
|
|
1942
|
-
src: sandboxSrc ?? void 0,
|
|
1943
|
-
srcDoc: sandboxSrc ? void 0 : proxyHtml
|
|
1944
|
-
}
|
|
1945
|
-
) });
|
|
1946
|
-
}
|
|
1947
|
-
const DEFAULT_THEME = "dark";
|
|
1948
|
-
const DEFAULT_DISPLAY_MODE = "inline";
|
|
1949
|
-
const DEFAULT_PLATFORM = "desktop";
|
|
1950
|
-
function parseUrlParams() {
|
|
1951
|
-
if (typeof window === "undefined") return {};
|
|
1952
|
-
const params = new URLSearchParams(window.location.search);
|
|
1953
|
-
const simulation = params.get("simulation") ?? void 0;
|
|
1954
|
-
const theme = params.get("theme");
|
|
1955
|
-
const displayMode = params.get("displayMode");
|
|
1956
|
-
const locale = params.get("locale");
|
|
1957
|
-
const maxHeightParam = params.get("maxHeight");
|
|
1958
|
-
const containerMaxHeight = maxHeightParam ? Number(maxHeightParam) : void 0;
|
|
1959
|
-
const maxWidthParam = params.get("maxWidth");
|
|
1960
|
-
const containerMaxWidth = maxWidthParam ? Number(maxWidthParam) : void 0;
|
|
1961
|
-
const host = params.get("host") ?? void 0;
|
|
1962
|
-
const prodToolsParam = params.get("prodTools");
|
|
1963
|
-
const prodTools = prodToolsParam === "true" ? true : prodToolsParam === "false" ? false : void 0;
|
|
1964
|
-
const prodResourcesParam = params.get("prodResources");
|
|
1965
|
-
const prodResources = prodResourcesParam === "true" ? true : prodResourcesParam === "false" ? false : void 0;
|
|
1966
|
-
const deviceType = params.get("deviceType");
|
|
1967
|
-
let platform;
|
|
1968
|
-
if (deviceType === "mobile" || deviceType === "tablet") {
|
|
1969
|
-
platform = "mobile";
|
|
1970
|
-
} else if (deviceType === "desktop") {
|
|
1971
|
-
platform = "desktop";
|
|
1972
|
-
}
|
|
1973
|
-
const hoverParam = params.get("hover");
|
|
1974
|
-
const touchParam = params.get("touch");
|
|
1975
|
-
const hasCapParams = hoverParam || touchParam;
|
|
1976
|
-
const deviceCapabilities = hasCapParams ? {
|
|
1977
|
-
hover: hoverParam === "false" ? false : true,
|
|
1978
|
-
touch: touchParam === "true" ? true : false
|
|
1979
|
-
} : void 0;
|
|
1980
|
-
const safeAreaTop = params.get("safeAreaTop");
|
|
1981
|
-
const safeAreaBottom = params.get("safeAreaBottom");
|
|
1982
|
-
const safeAreaLeft = params.get("safeAreaLeft");
|
|
1983
|
-
const safeAreaRight = params.get("safeAreaRight");
|
|
1984
|
-
const hasSafeAreaParams = safeAreaTop || safeAreaBottom || safeAreaLeft || safeAreaRight;
|
|
1985
|
-
const safeAreaInsets = hasSafeAreaParams ? {
|
|
1986
|
-
top: safeAreaTop ? Number(safeAreaTop) : 0,
|
|
1987
|
-
bottom: safeAreaBottom ? Number(safeAreaBottom) : 0,
|
|
1988
|
-
left: safeAreaLeft ? Number(safeAreaLeft) : 0,
|
|
1989
|
-
right: safeAreaRight ? Number(safeAreaRight) : 0
|
|
1990
|
-
} : void 0;
|
|
1991
|
-
return {
|
|
1992
|
-
simulation,
|
|
1993
|
-
theme: theme ?? void 0,
|
|
1994
|
-
displayMode: displayMode ?? void 0,
|
|
1995
|
-
locale: locale ?? void 0,
|
|
1996
|
-
containerMaxHeight,
|
|
1997
|
-
containerMaxWidth,
|
|
1998
|
-
platform,
|
|
1999
|
-
deviceCapabilities,
|
|
2000
|
-
safeAreaInsets,
|
|
2001
|
-
host: host ?? void 0,
|
|
2002
|
-
prodTools,
|
|
2003
|
-
prodResources
|
|
2004
|
-
};
|
|
2005
|
-
}
|
|
2006
|
-
function useSimulatorState({
|
|
2007
|
-
simulations,
|
|
2008
|
-
defaultHost = "chatgpt"
|
|
2009
|
-
}) {
|
|
2010
|
-
const simulationNames = Object.keys(simulations).filter((name) => simulations[name].resource).sort((a, b) => {
|
|
2011
|
-
const simA = simulations[a];
|
|
2012
|
-
const simB = simulations[b];
|
|
2013
|
-
const resourceLabelA = simA.resource.title || simA.resource.name;
|
|
2014
|
-
const resourceLabelB = simB.resource.title || simB.resource.name;
|
|
2015
|
-
const labelA = `${resourceLabelA}: ${simA.tool.title || simA.tool.name}`;
|
|
2016
|
-
const labelB = `${resourceLabelB}: ${simB.tool.title || simB.tool.name}`;
|
|
2017
|
-
return labelA.localeCompare(labelB);
|
|
2018
|
-
});
|
|
2019
|
-
const urlParams = React.useMemo(() => parseUrlParams(), []);
|
|
2020
|
-
const [screenWidth, setScreenWidth] = React.useState("full");
|
|
2021
|
-
const isMobileWidth = (width) => width === "mobile-s" || width === "mobile-l";
|
|
2022
|
-
const [activeHost, setActiveHost] = React.useState(urlParams.host ?? defaultHost);
|
|
2023
|
-
const initialSimulationName = React.useMemo(() => {
|
|
2024
|
-
const defaultName = simulationNames[0] ?? "";
|
|
2025
|
-
if (!urlParams.simulation) return defaultName;
|
|
2026
|
-
return urlParams.simulation in simulations ? urlParams.simulation : defaultName;
|
|
2027
|
-
}, [urlParams.simulation, simulations, simulationNames]);
|
|
2028
|
-
const [selectedSimulationName, setSelectedSimulationName] = React.useState(initialSimulationName);
|
|
2029
|
-
const selectedSim = simulations[selectedSimulationName];
|
|
2030
|
-
const [theme, setTheme] = React.useState(urlParams.theme ?? DEFAULT_THEME);
|
|
2031
|
-
const [displayMode, _setDisplayMode] = React.useState(
|
|
2032
|
-
urlParams.displayMode ?? DEFAULT_DISPLAY_MODE
|
|
2033
|
-
);
|
|
2034
|
-
const [locale, setLocale] = React.useState(urlParams.locale ?? "en-US");
|
|
2035
|
-
const [containerHeight, setContainerHeight] = React.useState(void 0);
|
|
2036
|
-
const [containerWidth, setContainerWidth] = React.useState(void 0);
|
|
2037
|
-
const [containerMaxHeight, setContainerMaxHeight] = React.useState(
|
|
2038
|
-
urlParams.containerMaxHeight
|
|
2039
|
-
);
|
|
2040
|
-
const [containerMaxWidth, setContainerMaxWidth] = React.useState(
|
|
2041
|
-
urlParams.containerMaxWidth
|
|
2042
|
-
);
|
|
2043
|
-
const [platform, setPlatform] = React.useState(urlParams.platform ?? DEFAULT_PLATFORM);
|
|
2044
|
-
const [hover, setHover] = React.useState(urlParams.deviceCapabilities?.hover ?? true);
|
|
2045
|
-
const [touch, setTouch] = React.useState(urlParams.deviceCapabilities?.touch ?? false);
|
|
2046
|
-
const [safeAreaInsets, setSafeAreaInsets] = React.useState(
|
|
2047
|
-
urlParams.safeAreaInsets ?? { top: 0, bottom: 0, left: 0, right: 0 }
|
|
2048
|
-
);
|
|
2049
|
-
const [timeZone, setTimeZone] = React.useState(() => Intl.DateTimeFormat().resolvedOptions().timeZone);
|
|
2050
|
-
const [measuredContentWidth, setMeasuredContentWidth] = React.useState(void 0);
|
|
2051
|
-
const handleContentWidthChange = React.useCallback((width) => {
|
|
2052
|
-
setMeasuredContentWidth(width);
|
|
2053
|
-
}, []);
|
|
2054
|
-
const setDisplayMode = (mode) => {
|
|
2055
|
-
if (isMobileWidth(screenWidth) && mode === "pip") {
|
|
2056
|
-
_setDisplayMode("fullscreen");
|
|
2057
|
-
} else {
|
|
2058
|
-
_setDisplayMode(mode);
|
|
2059
|
-
}
|
|
2060
|
-
};
|
|
2061
|
-
const handleDisplayModeReady = React.useCallback((_mode) => {
|
|
2062
|
-
}, []);
|
|
2063
|
-
const containerDimensions = React.useMemo(() => {
|
|
2064
|
-
if (containerHeight != null || containerWidth != null || containerMaxHeight != null || containerMaxWidth != null) {
|
|
2065
|
-
return {
|
|
2066
|
-
...containerHeight != null ? { height: containerHeight } : {},
|
|
2067
|
-
...containerWidth != null ? { width: containerWidth } : {},
|
|
2068
|
-
...containerMaxHeight != null ? { maxHeight: containerMaxHeight } : {},
|
|
2069
|
-
...containerMaxWidth != null ? { maxWidth: containerMaxWidth } : {}
|
|
2070
|
-
};
|
|
2071
|
-
}
|
|
2072
|
-
if (displayMode === "fullscreen") {
|
|
2073
|
-
const h = typeof window !== "undefined" ? window.innerHeight - 52 : 800;
|
|
2074
|
-
const w = measuredContentWidth ?? (typeof window !== "undefined" ? window.innerWidth : 1280);
|
|
2075
|
-
return { height: h, width: w };
|
|
2076
|
-
}
|
|
2077
|
-
if (displayMode === "pip") {
|
|
2078
|
-
return {
|
|
2079
|
-
height: 480,
|
|
2080
|
-
...measuredContentWidth != null ? { maxWidth: measuredContentWidth } : {}
|
|
2081
|
-
};
|
|
2082
|
-
}
|
|
2083
|
-
if (measuredContentWidth != null) {
|
|
2084
|
-
return { maxWidth: measuredContentWidth };
|
|
2085
|
-
}
|
|
2086
|
-
return void 0;
|
|
2087
|
-
}, [
|
|
2088
|
-
containerHeight,
|
|
2089
|
-
containerWidth,
|
|
2090
|
-
containerMaxHeight,
|
|
2091
|
-
containerMaxWidth,
|
|
2092
|
-
measuredContentWidth,
|
|
2093
|
-
displayMode
|
|
2094
|
-
]);
|
|
2095
|
-
const hostContext = React.useMemo(
|
|
2096
|
-
() => ({
|
|
2097
|
-
theme,
|
|
2098
|
-
displayMode,
|
|
2099
|
-
availableDisplayModes: ["inline", "pip", "fullscreen"],
|
|
2100
|
-
locale,
|
|
2101
|
-
timeZone,
|
|
2102
|
-
platform,
|
|
2103
|
-
deviceCapabilities: { hover, touch },
|
|
2104
|
-
safeAreaInsets,
|
|
2105
|
-
...containerDimensions ? { containerDimensions } : {}
|
|
2106
|
-
}),
|
|
2107
|
-
[
|
|
2108
|
-
theme,
|
|
2109
|
-
displayMode,
|
|
2110
|
-
locale,
|
|
2111
|
-
timeZone,
|
|
2112
|
-
platform,
|
|
2113
|
-
hover,
|
|
2114
|
-
touch,
|
|
2115
|
-
safeAreaInsets,
|
|
2116
|
-
containerDimensions
|
|
2117
|
-
]
|
|
2118
|
-
);
|
|
2119
|
-
const [toolInput, setToolInput] = React.useState(
|
|
2120
|
-
() => selectedSim?.toolInput ?? {}
|
|
2121
|
-
);
|
|
2122
|
-
const [toolResult, setToolResult] = React.useState(
|
|
2123
|
-
() => selectedSim?.toolResult
|
|
2124
|
-
);
|
|
2125
|
-
const [toolInputJson, setToolInputJson] = React.useState(() => JSON.stringify(toolInput, null, 2));
|
|
2126
|
-
const [toolResultJson, setToolResultJson] = React.useState(
|
|
2127
|
-
() => JSON.stringify(toolResult ?? null, null, 2)
|
|
2128
|
-
);
|
|
2129
|
-
const [modelContextJson, setModelContextJson] = React.useState("null");
|
|
2130
|
-
const [modelContext, setModelContext] = React.useState(null);
|
|
2131
|
-
const [editingField, setEditingField] = React.useState(null);
|
|
2132
|
-
const [toolInputError, setToolInputError] = React.useState("");
|
|
2133
|
-
const [toolResultError, setToolResultError] = React.useState("");
|
|
2134
|
-
const [modelContextError, setModelContextError] = React.useState("");
|
|
2135
|
-
React.useEffect(() => {
|
|
2136
|
-
const newInput = selectedSim?.toolInput ?? {};
|
|
2137
|
-
const newResult = selectedSim?.toolResult ?? void 0;
|
|
2138
|
-
setToolInput(newInput);
|
|
2139
|
-
setToolResult(newResult);
|
|
2140
|
-
if (editingField !== "toolInput") {
|
|
2141
|
-
setToolInputJson(JSON.stringify(newInput, null, 2));
|
|
2142
|
-
setToolInputError("");
|
|
2143
|
-
}
|
|
2144
|
-
if (editingField !== "toolResult") {
|
|
2145
|
-
setToolResultJson(JSON.stringify(newResult ?? null, null, 2));
|
|
2146
|
-
setToolResultError("");
|
|
2147
|
-
}
|
|
2148
|
-
if (editingField !== "modelContext") {
|
|
2149
|
-
setModelContextJson("null");
|
|
2150
|
-
setModelContext(null);
|
|
2151
|
-
setModelContextError("");
|
|
2152
|
-
}
|
|
2153
|
-
}, [selectedSimulationName, selectedSim]);
|
|
2154
|
-
React.useEffect(() => {
|
|
2155
|
-
if (isMobileWidth(screenWidth) && displayMode === "pip") {
|
|
2156
|
-
_setDisplayMode("fullscreen");
|
|
2157
|
-
}
|
|
2158
|
-
}, [screenWidth, displayMode]);
|
|
2159
|
-
const handleDisplayModeChange = (mode) => {
|
|
2160
|
-
setDisplayMode(mode);
|
|
2161
|
-
};
|
|
2162
|
-
const handleUpdateModelContext = (content, structuredContent) => {
|
|
2163
|
-
setModelContextJson(JSON.stringify(structuredContent ?? content, null, 2));
|
|
2164
|
-
};
|
|
2165
|
-
const validateJSON = (json, setJson, setError) => {
|
|
2166
|
-
setJson(json);
|
|
2167
|
-
try {
|
|
2168
|
-
if (json.trim() !== "") JSON.parse(json);
|
|
2169
|
-
setError("");
|
|
2170
|
-
} catch (e) {
|
|
2171
|
-
setError(e instanceof Error ? e.message : "Invalid JSON");
|
|
2172
|
-
}
|
|
2173
|
-
};
|
|
2174
|
-
const commitJSON = (json, setError, updateFn) => {
|
|
2175
|
-
try {
|
|
2176
|
-
const parsed = json.trim() === "" ? null : JSON.parse(json);
|
|
2177
|
-
setError("");
|
|
2178
|
-
updateFn(parsed);
|
|
2179
|
-
} catch (e) {
|
|
2180
|
-
setError(e instanceof Error ? e.message : "Invalid JSON");
|
|
2181
|
-
} finally {
|
|
2182
|
-
setEditingField(null);
|
|
2183
|
-
}
|
|
2184
|
-
};
|
|
2185
|
-
const effectiveToolResult = React.useMemo(() => {
|
|
2186
|
-
if (!toolResult && !modelContext) return void 0;
|
|
2187
|
-
if (!modelContext) return toolResult;
|
|
2188
|
-
const baseResult = toolResult ?? { content: [] };
|
|
2189
|
-
const baseStructured = baseResult.structuredContent ?? {};
|
|
2190
|
-
return {
|
|
2191
|
-
...baseResult,
|
|
2192
|
-
structuredContent: { ...baseStructured, ...modelContext }
|
|
2193
|
-
};
|
|
2194
|
-
}, [toolResult, modelContext]);
|
|
2195
|
-
const resourceUrl = selectedSim?.resourceUrl;
|
|
2196
|
-
const resourceScript = selectedSim?.resourceScript;
|
|
2197
|
-
const csp = selectedSim?.resource ? extractResourceCSP(selectedSim.resource) : void 0;
|
|
2198
|
-
const resourceMeta = selectedSim?.resource?._meta?.ui;
|
|
2199
|
-
const permissions = resourceMeta?.permissions;
|
|
2200
|
-
const prefersBorder = resourceMeta?.prefersBorder ?? false;
|
|
2201
|
-
return {
|
|
2202
|
-
simulationNames,
|
|
2203
|
-
selectedSimulationName,
|
|
2204
|
-
setSelectedSimulationName,
|
|
2205
|
-
selectedSim,
|
|
2206
|
-
activeHost,
|
|
2207
|
-
setActiveHost,
|
|
2208
|
-
screenWidth,
|
|
2209
|
-
setScreenWidth,
|
|
2210
|
-
theme,
|
|
2211
|
-
setTheme,
|
|
2212
|
-
displayMode,
|
|
2213
|
-
setDisplayMode,
|
|
2214
|
-
locale,
|
|
2215
|
-
setLocale,
|
|
2216
|
-
containerHeight,
|
|
2217
|
-
setContainerHeight,
|
|
2218
|
-
containerWidth,
|
|
2219
|
-
setContainerWidth,
|
|
2220
|
-
containerMaxHeight,
|
|
2221
|
-
setContainerMaxHeight,
|
|
2222
|
-
containerMaxWidth,
|
|
2223
|
-
setContainerMaxWidth,
|
|
2224
|
-
platform,
|
|
2225
|
-
setPlatform,
|
|
2226
|
-
hover,
|
|
2227
|
-
setHover,
|
|
2228
|
-
touch,
|
|
2229
|
-
setTouch,
|
|
2230
|
-
safeAreaInsets,
|
|
2231
|
-
setSafeAreaInsets,
|
|
2232
|
-
timeZone,
|
|
2233
|
-
setTimeZone,
|
|
2234
|
-
hostContext,
|
|
2235
|
-
handleDisplayModeReady,
|
|
2236
|
-
toolInput,
|
|
2237
|
-
setToolInput,
|
|
2238
|
-
toolResult,
|
|
2239
|
-
setToolResult,
|
|
2240
|
-
effectiveToolResult,
|
|
2241
|
-
modelContext,
|
|
2242
|
-
setModelContext,
|
|
2243
|
-
toolInputJson,
|
|
2244
|
-
setToolInputJson,
|
|
2245
|
-
toolInputError,
|
|
2246
|
-
setToolInputError,
|
|
2247
|
-
toolResultJson,
|
|
2248
|
-
setToolResultJson,
|
|
2249
|
-
toolResultError,
|
|
2250
|
-
setToolResultError,
|
|
2251
|
-
modelContextJson,
|
|
2252
|
-
setModelContextJson,
|
|
2253
|
-
modelContextError,
|
|
2254
|
-
setModelContextError,
|
|
2255
|
-
editingField,
|
|
2256
|
-
setEditingField,
|
|
2257
|
-
validateJSON,
|
|
2258
|
-
commitJSON,
|
|
2259
|
-
measuredContentWidth,
|
|
2260
|
-
handleContentWidthChange,
|
|
2261
|
-
handleDisplayModeChange,
|
|
2262
|
-
handleUpdateModelContext,
|
|
2263
|
-
resourceUrl,
|
|
2264
|
-
resourceScript,
|
|
2265
|
-
csp,
|
|
2266
|
-
permissions,
|
|
2267
|
-
prefersBorder,
|
|
2268
|
-
urlProdTools: urlParams.prodTools,
|
|
2269
|
-
urlProdResources: urlParams.prodResources
|
|
2270
|
-
};
|
|
2271
|
-
}
|
|
2272
|
-
const ThemeProviderContext = React__namespace.createContext(void 0);
|
|
2273
|
-
function defaultApplyTheme(theme) {
|
|
2274
|
-
if (typeof document !== "undefined") {
|
|
2275
|
-
document.documentElement.setAttribute("data-theme", theme);
|
|
2276
|
-
}
|
|
2277
|
-
}
|
|
2278
|
-
function ThemeProvider({
|
|
2279
|
-
children,
|
|
2280
|
-
defaultTheme = "light",
|
|
2281
|
-
theme: controlledTheme,
|
|
2282
|
-
applyTheme,
|
|
2283
|
-
...props
|
|
2284
|
-
}) {
|
|
2285
|
-
const [internalTheme] = React__namespace.useState(defaultTheme);
|
|
2286
|
-
const theme = controlledTheme ?? internalTheme;
|
|
2287
|
-
const applier = applyTheme ?? defaultApplyTheme;
|
|
2288
|
-
React__namespace.useLayoutEffect(() => {
|
|
2289
|
-
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
2290
|
-
try {
|
|
2291
|
-
applier(theme);
|
|
2292
|
-
} catch (error) {
|
|
2293
|
-
console.warn("Failed to apply document theme:", error);
|
|
2294
|
-
}
|
|
2295
|
-
}
|
|
2296
|
-
}, [theme, applier]);
|
|
2297
|
-
const value = {
|
|
2298
|
-
theme
|
|
2299
|
-
};
|
|
2300
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ThemeProviderContext.Provider, { ...props, value, children });
|
|
2301
|
-
}
|
|
2302
|
-
const useThemeContext = () => {
|
|
2303
|
-
const context = React__namespace.useContext(ThemeProviderContext);
|
|
2304
|
-
if (context === void 0) throw new Error("useThemeContext must be used within a ThemeProvider");
|
|
2305
|
-
return context;
|
|
2306
|
-
};
|
|
2307
|
-
const DEFAULT_SIDEBAR_WIDTH = 224;
|
|
2308
|
-
function ChevronRightIcon() {
|
|
2309
|
-
return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "1em", height: "1em", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2310
|
-
"path",
|
|
2311
|
-
{
|
|
2312
|
-
fillRule: "evenodd",
|
|
2313
|
-
d: "M8.293 4.293a1 1 0 0 1 1.414 0l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L14.586 12 8.293 5.707a1 1 0 0 1 0-1.414Z",
|
|
2314
|
-
clipRule: "evenodd"
|
|
2315
|
-
}
|
|
2316
|
-
) });
|
|
2317
|
-
}
|
|
2318
|
-
function SimpleSidebar({ children, controls, headerRight }) {
|
|
2319
|
-
const [isDrawerOpen, setIsDrawerOpen] = React__namespace.useState(false);
|
|
2320
|
-
const [sidebarWidth, setSidebarWidth] = React__namespace.useState(DEFAULT_SIDEBAR_WIDTH);
|
|
2321
|
-
const [isResizing, setIsResizing] = React__namespace.useState(false);
|
|
2322
|
-
const handleMouseDown = React__namespace.useCallback((e) => {
|
|
2323
|
-
e.preventDefault();
|
|
2324
|
-
setIsResizing(true);
|
|
2325
|
-
}, []);
|
|
2326
|
-
React__namespace.useEffect(() => {
|
|
2327
|
-
if (!isResizing) return;
|
|
2328
|
-
const handleMouseMove = (e) => {
|
|
2329
|
-
const maxWidth = Math.floor(window.innerWidth / 3);
|
|
2330
|
-
const newWidth = Math.min(maxWidth, Math.max(DEFAULT_SIDEBAR_WIDTH, e.clientX));
|
|
2331
|
-
setSidebarWidth(newWidth);
|
|
2332
|
-
};
|
|
2333
|
-
const handleMouseUp = () => {
|
|
2334
|
-
setIsResizing(false);
|
|
2335
|
-
};
|
|
2336
|
-
document.addEventListener("mousemove", handleMouseMove);
|
|
2337
|
-
document.addEventListener("mouseup", handleMouseUp);
|
|
2338
|
-
return () => {
|
|
2339
|
-
document.removeEventListener("mousemove", handleMouseMove);
|
|
2340
|
-
document.removeEventListener("mouseup", handleMouseUp);
|
|
2341
|
-
};
|
|
2342
|
-
}, [isResizing]);
|
|
2343
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sunpeak-simulator-root flex h-screen w-full overflow-hidden relative", children: [
|
|
2344
|
-
isResizing && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "fixed inset-0 z-50 cursor-col-resize" }),
|
|
2345
|
-
isDrawerOpen && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2346
|
-
"div",
|
|
2347
|
-
{
|
|
2348
|
-
className: "md:hidden fixed inset-0 bg-black/50 z-40 pointer-events-auto",
|
|
2349
|
-
onClick: (e) => {
|
|
2350
|
-
if (e.target === e.currentTarget) {
|
|
2351
|
-
setIsDrawerOpen(false);
|
|
2352
|
-
}
|
|
2353
|
-
}
|
|
2354
|
-
}
|
|
2355
|
-
),
|
|
2356
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2357
|
-
"aside",
|
|
2358
|
-
{
|
|
2359
|
-
className: `
|
|
2360
|
-
relative flex flex-col bg-sidebar
|
|
2361
|
-
md:z-auto
|
|
2362
|
-
max-md:fixed max-md:inset-y-0 max-md:left-0 max-md:z-[100]
|
|
2363
|
-
max-md:transition-transform max-md:duration-300 max-md:!w-2/3
|
|
2364
|
-
${isDrawerOpen ? "max-md:translate-x-0" : "max-md:-translate-x-full"}
|
|
2365
|
-
`,
|
|
2366
|
-
style: {
|
|
2367
|
-
width: sidebarWidth,
|
|
2368
|
-
borderRight: "1px solid var(--color-border-primary)"
|
|
2369
|
-
},
|
|
2370
|
-
children: [
|
|
2371
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 overflow-y-auto min-h-0 px-3 pb-3 pt-0", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
2372
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between sticky top-0 bg-sidebar z-10 py-2", children: [
|
|
2373
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2374
|
-
"h2",
|
|
2375
|
-
{
|
|
2376
|
-
className: "text-xs font-semibold",
|
|
2377
|
-
style: { color: "var(--color-text-primary)" },
|
|
2378
|
-
children: "Controls"
|
|
2379
|
-
}
|
|
2380
|
-
),
|
|
2381
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
2382
|
-
headerRight,
|
|
2383
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2384
|
-
"button",
|
|
2385
|
-
{
|
|
2386
|
-
onClick: () => setIsDrawerOpen(false),
|
|
2387
|
-
className: "md:hidden p-1 transition-colors",
|
|
2388
|
-
style: { color: "var(--color-text-secondary)" },
|
|
2389
|
-
type: "button",
|
|
2390
|
-
"aria-label": "Close sidebar",
|
|
2391
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2392
|
-
"svg",
|
|
2393
|
-
{
|
|
2394
|
-
width: "16",
|
|
2395
|
-
height: "16",
|
|
2396
|
-
viewBox: "0 0 16 16",
|
|
2397
|
-
fill: "none",
|
|
2398
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2399
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2400
|
-
"path",
|
|
2401
|
-
{
|
|
2402
|
-
d: "M12 4L4 12M4 4L12 12",
|
|
2403
|
-
stroke: "currentColor",
|
|
2404
|
-
strokeWidth: "2",
|
|
2405
|
-
strokeLinecap: "round"
|
|
2406
|
-
}
|
|
2407
|
-
)
|
|
2408
|
-
}
|
|
2409
|
-
)
|
|
2410
|
-
}
|
|
2411
|
-
)
|
|
2412
|
-
] })
|
|
2413
|
-
] }),
|
|
2414
|
-
controls
|
|
2415
|
-
] }) }) }),
|
|
2416
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2417
|
-
"div",
|
|
2418
|
-
{
|
|
2419
|
-
onMouseDown: handleMouseDown,
|
|
2420
|
-
className: "hidden md:block absolute top-0 right-0 w-1 h-full cursor-col-resize hover:bg-black/10 dark:hover:bg-white/10 active:bg-black/20 dark:active:bg-white/20 transition-colors"
|
|
2421
|
-
}
|
|
2422
|
-
)
|
|
2423
|
-
]
|
|
2424
|
-
}
|
|
2425
|
-
),
|
|
2426
|
-
/* @__PURE__ */ jsxRuntime.jsxs("main", { className: "flex-1 overflow-auto relative", children: [
|
|
2427
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2428
|
-
"button",
|
|
2429
|
-
{
|
|
2430
|
-
onClick: () => setIsDrawerOpen(true),
|
|
2431
|
-
className: "md:hidden fixed top-18 left-0 z-30 bg-sidebar rounded-r-md p-2 shadow-lg hover:bg-black/5 dark:hover:bg-white/10 transition-colors",
|
|
2432
|
-
style: {
|
|
2433
|
-
borderRight: "1px solid var(--color-border-primary)",
|
|
2434
|
-
borderTop: "1px solid var(--color-border-primary)",
|
|
2435
|
-
borderBottom: "1px solid var(--color-border-primary)"
|
|
2436
|
-
},
|
|
2437
|
-
type: "button",
|
|
2438
|
-
"aria-label": "Open sidebar",
|
|
2439
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ChevronRightIcon, {})
|
|
2440
|
-
}
|
|
2441
|
-
),
|
|
2442
|
-
children
|
|
2443
|
-
] })
|
|
2444
|
-
] });
|
|
2445
|
-
}
|
|
2446
|
-
const DOCS_BASE_URL = "https://sunpeak.ai/docs";
|
|
2447
|
-
function HelpIcon({ tooltip, docsPath }) {
|
|
2448
|
-
const [pos, setPos] = React__namespace.useState(null);
|
|
2449
|
-
const ref = React__namespace.useRef(null);
|
|
2450
|
-
const showTooltip = () => {
|
|
2451
|
-
const rect = ref.current?.getBoundingClientRect();
|
|
2452
|
-
if (rect) {
|
|
2453
|
-
setPos({ top: rect.top + rect.height / 2, left: rect.right + 6 });
|
|
2454
|
-
}
|
|
2455
|
-
};
|
|
2456
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2457
|
-
"a",
|
|
2458
|
-
{
|
|
2459
|
-
ref,
|
|
2460
|
-
href: `${DOCS_BASE_URL}/${docsPath}`,
|
|
2461
|
-
target: "_blank",
|
|
2462
|
-
rel: "noopener noreferrer",
|
|
2463
|
-
className: "inline-flex items-center justify-center no-underline flex-shrink-0 transition-colors",
|
|
2464
|
-
style: {
|
|
2465
|
-
color: "var(--color-text-tertiary, var(--color-text-secondary))"
|
|
2466
|
-
},
|
|
2467
|
-
onClick: (e) => e.stopPropagation(),
|
|
2468
|
-
onMouseEnter: showTooltip,
|
|
2469
|
-
onMouseLeave: () => setPos(null),
|
|
2470
|
-
children: [
|
|
2471
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2472
|
-
"svg",
|
|
2473
|
-
{
|
|
2474
|
-
width: "12",
|
|
2475
|
-
height: "12",
|
|
2476
|
-
viewBox: "0 0 12 12",
|
|
2477
|
-
fill: "none",
|
|
2478
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2479
|
-
children: [
|
|
2480
|
-
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "6", cy: "6", r: "5.25", stroke: "currentColor", strokeWidth: "1" }),
|
|
2481
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2482
|
-
"text",
|
|
2483
|
-
{
|
|
2484
|
-
x: "6.25",
|
|
2485
|
-
y: "8.5",
|
|
2486
|
-
textAnchor: "middle",
|
|
2487
|
-
fill: "currentColor",
|
|
2488
|
-
fontSize: "7.5",
|
|
2489
|
-
fontWeight: "600",
|
|
2490
|
-
fontFamily: "system-ui, sans-serif",
|
|
2491
|
-
children: "?"
|
|
2492
|
-
}
|
|
2493
|
-
)
|
|
2494
|
-
]
|
|
2495
|
-
}
|
|
2496
|
-
),
|
|
2497
|
-
pos && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2498
|
-
"span",
|
|
2499
|
-
{
|
|
2500
|
-
className: "pointer-events-none fixed whitespace-nowrap rounded px-2 py-1 text-[11px] font-normal leading-tight z-[200]",
|
|
2501
|
-
style: {
|
|
2502
|
-
top: pos.top,
|
|
2503
|
-
left: pos.left,
|
|
2504
|
-
transform: "translateY(-50%)",
|
|
2505
|
-
backgroundColor: "var(--color-text-primary)",
|
|
2506
|
-
color: "var(--color-background-primary)"
|
|
2507
|
-
},
|
|
2508
|
-
children: tooltip
|
|
2509
|
-
}
|
|
2510
|
-
)
|
|
2511
|
-
]
|
|
2512
|
-
}
|
|
2513
|
-
);
|
|
2514
|
-
}
|
|
2515
|
-
function SidebarControl({ label, children, tooltip, docsPath }) {
|
|
2516
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1", children: [
|
|
2517
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2518
|
-
"span",
|
|
2519
|
-
{
|
|
2520
|
-
className: "text-[10px] font-medium leading-tight inline-flex items-center gap-1",
|
|
2521
|
-
style: { color: "var(--color-text-secondary)" },
|
|
2522
|
-
children: [
|
|
2523
|
-
label,
|
|
2524
|
-
tooltip && docsPath && /* @__PURE__ */ jsxRuntime.jsx(HelpIcon, { tooltip, docsPath })
|
|
2525
|
-
]
|
|
2526
|
-
}
|
|
2527
|
-
),
|
|
2528
|
-
children
|
|
2529
|
-
] });
|
|
2530
|
-
}
|
|
2531
|
-
function SidebarCollapsibleControl({
|
|
2532
|
-
label,
|
|
2533
|
-
children,
|
|
2534
|
-
defaultCollapsed = true,
|
|
2535
|
-
tooltip,
|
|
2536
|
-
docsPath
|
|
2537
|
-
}) {
|
|
2538
|
-
const [isCollapsed, setIsCollapsed] = React__namespace.useState(defaultCollapsed);
|
|
2539
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1", children: [
|
|
2540
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2541
|
-
"button",
|
|
2542
|
-
{
|
|
2543
|
-
onClick: () => setIsCollapsed(!isCollapsed),
|
|
2544
|
-
className: "w-full flex items-center justify-between text-[10px] font-medium leading-tight transition-colors py-1 cursor-pointer",
|
|
2545
|
-
style: { color: "var(--color-text-secondary)" },
|
|
2546
|
-
type: "button",
|
|
2547
|
-
children: [
|
|
2548
|
-
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "inline-flex items-center gap-1", children: [
|
|
2549
|
-
label,
|
|
2550
|
-
tooltip && docsPath && /* @__PURE__ */ jsxRuntime.jsx(HelpIcon, { tooltip, docsPath })
|
|
2551
|
-
] }),
|
|
2552
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[8px]", children: isCollapsed ? "▶" : "▼" })
|
|
2553
|
-
]
|
|
2554
|
-
}
|
|
2555
|
-
),
|
|
2556
|
-
!isCollapsed && children
|
|
2557
|
-
] });
|
|
2558
|
-
}
|
|
2559
|
-
const formElementStyle = {
|
|
2560
|
-
color: "var(--color-text-primary)",
|
|
2561
|
-
backgroundColor: "var(--color-background-primary)",
|
|
2562
|
-
cursor: "pointer"
|
|
2563
|
-
};
|
|
2564
|
-
function SidebarSelect({ value, onChange, options, placeholder }) {
|
|
2565
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2566
|
-
"select",
|
|
2567
|
-
{
|
|
2568
|
-
value,
|
|
2569
|
-
onChange: (e) => onChange(e.target.value),
|
|
2570
|
-
className: "w-full h-7 text-xs rounded-full px-2 outline-none appearance-none bg-no-repeat bg-[length:12px] bg-[right_6px_center]",
|
|
2571
|
-
style: {
|
|
2572
|
-
...formElementStyle,
|
|
2573
|
-
backgroundImage: `url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%236b7280'%3e%3cpath d='M4.22 6.22a.75.75 0 0 1 1.06 0L8 8.94l2.72-2.72a.75.75 0 1 1 1.06 1.06l-3.25 3.25a.75.75 0 0 1-1.06 0L4.22 7.28a.75.75 0 0 1 0-1.06Z'/%3e%3c/svg%3e")`,
|
|
2574
|
-
paddingRight: "1.5rem"
|
|
2575
|
-
},
|
|
2576
|
-
children: [
|
|
2577
|
-
placeholder && /* @__PURE__ */ jsxRuntime.jsx("option", { value: "", disabled: true, children: placeholder }),
|
|
2578
|
-
options.map((option) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: option.value, children: option.label }, option.value))
|
|
2579
|
-
]
|
|
2580
|
-
}
|
|
2581
|
-
);
|
|
2582
|
-
}
|
|
2583
|
-
function SidebarInput({
|
|
2584
|
-
value,
|
|
2585
|
-
onChange,
|
|
2586
|
-
applyOnBlur = false,
|
|
2587
|
-
placeholder,
|
|
2588
|
-
type = "text",
|
|
2589
|
-
disabled = false
|
|
2590
|
-
}) {
|
|
2591
|
-
const [draft, setDraft] = React.useState(value);
|
|
2592
|
-
const [isEditing, setIsEditing] = React.useState(false);
|
|
2593
|
-
const [prevValue, setPrevValue] = React.useState(value);
|
|
2594
|
-
if (!isEditing && value !== prevValue) {
|
|
2595
|
-
setPrevValue(value);
|
|
2596
|
-
setDraft(value);
|
|
2597
|
-
}
|
|
2598
|
-
if (applyOnBlur) {
|
|
2599
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2600
|
-
"input",
|
|
2601
|
-
{
|
|
2602
|
-
type,
|
|
2603
|
-
value: draft,
|
|
2604
|
-
onChange: (e) => setDraft(e.target.value),
|
|
2605
|
-
onFocus: () => setIsEditing(true),
|
|
2606
|
-
onBlur: () => {
|
|
2607
|
-
setIsEditing(false);
|
|
2608
|
-
onChange(draft);
|
|
2609
|
-
},
|
|
2610
|
-
placeholder,
|
|
2611
|
-
disabled,
|
|
2612
|
-
className: "w-full h-7 text-xs rounded-md px-2 outline-none disabled:opacity-50 disabled:cursor-not-allowed",
|
|
2613
|
-
style: { ...formElementStyle, cursor: disabled ? void 0 : "text" }
|
|
2614
|
-
}
|
|
2615
|
-
);
|
|
2616
|
-
}
|
|
2617
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2618
|
-
"input",
|
|
2619
|
-
{
|
|
2620
|
-
type,
|
|
2621
|
-
value,
|
|
2622
|
-
onChange: (e) => onChange(e.target.value),
|
|
2623
|
-
placeholder,
|
|
2624
|
-
disabled,
|
|
2625
|
-
className: "w-full h-7 text-xs rounded-md px-2 outline-none disabled:opacity-50 disabled:cursor-not-allowed",
|
|
2626
|
-
style: { ...formElementStyle, cursor: disabled ? void 0 : "text" }
|
|
2627
|
-
}
|
|
2628
|
-
);
|
|
2629
|
-
}
|
|
2630
|
-
function SidebarCheckbox({
|
|
2631
|
-
checked,
|
|
2632
|
-
onChange,
|
|
2633
|
-
label,
|
|
2634
|
-
tooltip,
|
|
2635
|
-
docsPath
|
|
2636
|
-
}) {
|
|
2637
|
-
const id = React__namespace.useId();
|
|
2638
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
2639
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2640
|
-
"input",
|
|
2641
|
-
{
|
|
2642
|
-
id,
|
|
2643
|
-
type: "checkbox",
|
|
2644
|
-
checked,
|
|
2645
|
-
onChange: (e) => onChange(e.target.checked),
|
|
2646
|
-
className: "outline-none cursor-pointer"
|
|
2647
|
-
}
|
|
2648
|
-
),
|
|
2649
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2650
|
-
"label",
|
|
2651
|
-
{
|
|
2652
|
-
htmlFor: id,
|
|
2653
|
-
className: "text-[11px] select-none cursor-pointer leading-tight inline-flex items-center gap-1",
|
|
2654
|
-
style: { color: "var(--color-text-primary)" },
|
|
2655
|
-
children: [
|
|
2656
|
-
label,
|
|
2657
|
-
tooltip && docsPath && /* @__PURE__ */ jsxRuntime.jsx(HelpIcon, { tooltip, docsPath })
|
|
2658
|
-
]
|
|
2659
|
-
}
|
|
2660
|
-
)
|
|
2661
|
-
] });
|
|
2662
|
-
}
|
|
2663
|
-
function SidebarTextarea({
|
|
2664
|
-
value,
|
|
2665
|
-
onChange,
|
|
2666
|
-
onFocus,
|
|
2667
|
-
onBlur,
|
|
2668
|
-
placeholder,
|
|
2669
|
-
maxRows = 8,
|
|
2670
|
-
error
|
|
2671
|
-
}) {
|
|
2672
|
-
const contentRows = value?.split("\n").length ?? 1;
|
|
2673
|
-
const rows = Math.min(contentRows, maxRows);
|
|
2674
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-0.5", children: [
|
|
2675
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2676
|
-
"textarea",
|
|
2677
|
-
{
|
|
2678
|
-
value,
|
|
2679
|
-
onChange: (e) => onChange(e.target.value),
|
|
2680
|
-
onFocus,
|
|
2681
|
-
onBlur,
|
|
2682
|
-
placeholder,
|
|
2683
|
-
rows,
|
|
2684
|
-
className: "w-full text-[10px] font-mono rounded-md px-2 py-1.5 outline-none resize-y",
|
|
2685
|
-
style: {
|
|
2686
|
-
...formElementStyle,
|
|
2687
|
-
cursor: "text",
|
|
2688
|
-
whiteSpace: "pre",
|
|
2689
|
-
overflowX: "auto",
|
|
2690
|
-
overflowWrap: "normal",
|
|
2691
|
-
...error ? { boxShadow: "inset 0 0 0 1px var(--color-text-danger, #dc2626)" } : {}
|
|
2692
|
-
},
|
|
2693
|
-
"aria-invalid": !!error
|
|
2694
|
-
}
|
|
2695
|
-
),
|
|
2696
|
-
error && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[9px]", style: { color: "var(--color-text-danger, #dc2626)" }, children: error })
|
|
2697
|
-
] });
|
|
2698
|
-
}
|
|
2699
|
-
function SidebarToggle({ value, onChange, options }) {
|
|
2700
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2701
|
-
"div",
|
|
2702
|
-
{
|
|
2703
|
-
className: "inline-flex w-full rounded-full p-[3px] gap-0.5",
|
|
2704
|
-
style: { backgroundColor: "var(--color-background-tertiary)" },
|
|
2705
|
-
role: "group",
|
|
2706
|
-
"aria-label": "Toggle options",
|
|
2707
|
-
children: options.map((option) => {
|
|
2708
|
-
const isSelected = value === option.value;
|
|
2709
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2710
|
-
"button",
|
|
2711
|
-
{
|
|
2712
|
-
onClick: () => onChange(option.value),
|
|
2713
|
-
"aria-pressed": isSelected,
|
|
2714
|
-
className: "flex-1 text-[10px] font-medium h-[22px] px-2 rounded-full outline-none transition-all duration-150 cursor-pointer",
|
|
2715
|
-
style: {
|
|
2716
|
-
backgroundColor: isSelected ? "var(--color-background-primary)" : "transparent",
|
|
2717
|
-
color: isSelected ? "var(--color-text-primary)" : "var(--color-text-secondary)",
|
|
2718
|
-
boxShadow: isSelected ? "0 1px 2px 0 rgba(0,0,0,0.06)" : "none"
|
|
2719
|
-
},
|
|
2720
|
-
type: "button",
|
|
2721
|
-
children: option.label
|
|
2722
|
-
},
|
|
2723
|
-
option.value
|
|
2724
|
-
);
|
|
2725
|
-
})
|
|
2726
|
-
}
|
|
2727
|
-
);
|
|
2728
|
-
}
|
|
2729
|
-
function resolveServerToolResult(mock, args) {
|
|
2730
|
-
if (!Array.isArray(mock)) return mock;
|
|
2731
|
-
for (const entry of mock) {
|
|
2732
|
-
const matches = Object.entries(entry.when).every(
|
|
2733
|
-
([key, value]) => args != null && args[key] === value
|
|
2734
|
-
);
|
|
2735
|
-
if (matches) return entry.result;
|
|
2736
|
-
}
|
|
2737
|
-
return void 0;
|
|
2738
|
-
}
|
|
2739
|
-
function Simulator({
|
|
2740
|
-
children,
|
|
2741
|
-
simulations = {},
|
|
2742
|
-
appName = "Sunpeak",
|
|
2743
|
-
appIcon,
|
|
2744
|
-
defaultHost = "chatgpt",
|
|
2745
|
-
onCallTool,
|
|
2746
|
-
defaultProdTools = false,
|
|
2747
|
-
defaultProdResources = false,
|
|
2748
|
-
hideSimulatorModes = false,
|
|
2749
|
-
sandboxUrl
|
|
2750
|
-
}) {
|
|
2751
|
-
const state = useSimulatorState({ simulations, defaultHost });
|
|
2752
|
-
const [prodTools, setProdTools] = React__namespace.useState(state.urlProdTools ?? defaultProdTools);
|
|
2753
|
-
const [prodResources, setProdResources] = React__namespace.useState(
|
|
2754
|
-
state.urlProdResources ?? defaultProdResources
|
|
2755
|
-
);
|
|
2756
|
-
const [isRunning, setIsRunning] = React__namespace.useState(false);
|
|
2757
|
-
const [hasRun, setHasRun] = React__namespace.useState(false);
|
|
2758
|
-
const [showCheck, setShowCheck] = React__namespace.useState(false);
|
|
2759
|
-
const checkTimerRef = React__namespace.useRef(void 0);
|
|
2760
|
-
React__namespace.useEffect(() => {
|
|
2761
|
-
if (prodTools) {
|
|
2762
|
-
setHasRun(false);
|
|
2763
|
-
} else {
|
|
2764
|
-
const simResult = state.selectedSim?.toolResult ?? void 0;
|
|
2765
|
-
state.setToolResult(simResult);
|
|
2766
|
-
}
|
|
2767
|
-
}, [prodTools, state.selectedSimulationName]);
|
|
2768
|
-
React__namespace.useEffect(() => () => clearTimeout(checkTimerRef.current), []);
|
|
2769
|
-
const toolOptions = React__namespace.useMemo(() => {
|
|
2770
|
-
if (!prodTools) return [];
|
|
2771
|
-
const seen = /* @__PURE__ */ new Map();
|
|
2772
|
-
for (const simName of state.simulationNames) {
|
|
2773
|
-
const sim = simulations[simName];
|
|
2774
|
-
const toolName = sim.tool.name;
|
|
2775
|
-
if (!seen.has(toolName)) {
|
|
2776
|
-
seen.set(toolName, simName);
|
|
2777
|
-
}
|
|
2778
|
-
}
|
|
2779
|
-
return Array.from(seen.entries()).map(([toolName, simName]) => ({
|
|
2780
|
-
value: simName,
|
|
2781
|
-
label: simulations[simName].tool.title || toolName
|
|
2782
|
-
}));
|
|
2783
|
-
}, [prodTools, state.simulationNames, simulations]);
|
|
2784
|
-
const handleRun = React__namespace.useCallback(async () => {
|
|
2785
|
-
if (!onCallTool || !state.selectedSim) return;
|
|
2786
|
-
const toolName = state.selectedSim.tool.name;
|
|
2787
|
-
setIsRunning(true);
|
|
2788
|
-
try {
|
|
2789
|
-
const result = await onCallTool({ name: toolName, arguments: state.toolInput });
|
|
2790
|
-
state.setToolResult(result);
|
|
2791
|
-
state.setToolResultJson(JSON.stringify(result, null, 2));
|
|
2792
|
-
state.setToolResultError("");
|
|
2793
|
-
setHasRun(true);
|
|
2794
|
-
setShowCheck(true);
|
|
2795
|
-
clearTimeout(checkTimerRef.current);
|
|
2796
|
-
checkTimerRef.current = setTimeout(() => setShowCheck(false), 2e3);
|
|
2797
|
-
} catch (err) {
|
|
2798
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
2799
|
-
state.setToolResult({
|
|
2800
|
-
content: [{ type: "text", text: `Error: ${message}` }],
|
|
2801
|
-
isError: true
|
|
2802
|
-
});
|
|
2803
|
-
state.setToolResultJson(
|
|
2804
|
-
JSON.stringify(
|
|
2805
|
-
{ content: [{ type: "text", text: `Error: ${message}` }], isError: true },
|
|
2806
|
-
null,
|
|
2807
|
-
2
|
|
2808
|
-
)
|
|
2809
|
-
);
|
|
2810
|
-
} finally {
|
|
2811
|
-
setIsRunning(false);
|
|
2812
|
-
}
|
|
2813
|
-
}, [onCallTool, state]);
|
|
2814
|
-
const activeShell = getHostShell(state.activeHost);
|
|
2815
|
-
const registeredHosts = getRegisteredHosts();
|
|
2816
|
-
const ShellConversation = activeShell?.Conversation;
|
|
2817
|
-
const hostContext = React__namespace.useMemo(() => {
|
|
2818
|
-
const styleVars = activeShell?.styleVariables;
|
|
2819
|
-
const userAgent = activeShell?.userAgent;
|
|
2820
|
-
const ctx = { ...state.hostContext };
|
|
2821
|
-
if (styleVars) {
|
|
2822
|
-
ctx.styles = { variables: styleVars };
|
|
2823
|
-
}
|
|
2824
|
-
if (userAgent) {
|
|
2825
|
-
ctx.userAgent = userAgent;
|
|
2826
|
-
}
|
|
2827
|
-
return ctx;
|
|
2828
|
-
}, [state.hostContext, activeShell]);
|
|
2829
|
-
React__namespace.useEffect(() => {
|
|
2830
|
-
const vars = activeShell?.styleVariables;
|
|
2831
|
-
if (!vars) return;
|
|
2832
|
-
const root = document.documentElement;
|
|
2833
|
-
for (const [key, value] of Object.entries(vars)) {
|
|
2834
|
-
if (value) root.style.setProperty(key, value);
|
|
2835
|
-
}
|
|
2836
|
-
}, [activeShell]);
|
|
2837
|
-
const prevPageStyleKeysRef = React__namespace.useRef([]);
|
|
2838
|
-
React__namespace.useEffect(() => {
|
|
2839
|
-
const root = document.documentElement;
|
|
2840
|
-
for (const key of prevPageStyleKeysRef.current) {
|
|
2841
|
-
root.style.removeProperty(key);
|
|
2842
|
-
}
|
|
2843
|
-
const pageStyles = activeShell?.pageStyles;
|
|
2844
|
-
if (pageStyles) {
|
|
2845
|
-
const keys = [];
|
|
2846
|
-
for (const [key, value] of Object.entries(pageStyles)) {
|
|
2847
|
-
root.style.setProperty(key, value);
|
|
2848
|
-
keys.push(key);
|
|
2849
|
-
}
|
|
2850
|
-
prevPageStyleKeysRef.current = keys;
|
|
2851
|
-
} else {
|
|
2852
|
-
prevPageStyleKeysRef.current = [];
|
|
2853
|
-
}
|
|
2854
|
-
}, [activeShell]);
|
|
2855
|
-
const handleCallTool = React__namespace.useCallback(
|
|
2856
|
-
(params) => {
|
|
2857
|
-
if (onCallTool) {
|
|
2858
|
-
return onCallTool(params);
|
|
2859
|
-
}
|
|
2860
|
-
const mock = state.selectedSim?.serverTools?.[params.name];
|
|
2861
|
-
if (mock) {
|
|
2862
|
-
const result = resolveServerToolResult(mock, params.arguments);
|
|
2863
|
-
if (result) return result;
|
|
2864
|
-
}
|
|
2865
|
-
return {
|
|
2866
|
-
content: [
|
|
2867
|
-
{
|
|
2868
|
-
type: "text",
|
|
2869
|
-
text: `[Simulator] Tool "${params.name}" called — no serverTools mock found in simulation "${state.selectedSimulationName}".`
|
|
2870
|
-
}
|
|
2871
|
-
]
|
|
2872
|
-
};
|
|
2873
|
-
},
|
|
2874
|
-
[onCallTool, state.selectedSim, state.selectedSimulationName]
|
|
2875
|
-
);
|
|
2876
|
-
const prodToolsUserMessage = prodTools && state.selectedSim ? `Call my ${state.selectedSim.tool.title || state.selectedSim.tool.name} tool` : void 0;
|
|
2877
|
-
const prodResourcesPath = React__namespace.useMemo(() => {
|
|
2878
|
-
if (!prodResources || !state.selectedSim?.resource) return void 0;
|
|
2879
|
-
const name = state.selectedSim.resource.name;
|
|
2880
|
-
return `/dist/${name}/${name}.html`;
|
|
2881
|
-
}, [prodResources, state.selectedSim?.resource]);
|
|
2882
|
-
const [prodResourcesReady, setProdResourcesReady] = React__namespace.useState(false);
|
|
2883
|
-
const [prodResourcesGeneration, setProdResourcesGeneration] = React__namespace.useState(0);
|
|
2884
|
-
const prodResourcesWasReady = React__namespace.useRef(false);
|
|
2885
|
-
React__namespace.useEffect(() => {
|
|
2886
|
-
if (!prodResourcesPath) {
|
|
2887
|
-
setProdResourcesReady(false);
|
|
2888
|
-
prodResourcesWasReady.current = false;
|
|
2889
|
-
return;
|
|
2890
|
-
}
|
|
2891
|
-
let cancelled = false;
|
|
2892
|
-
let timer;
|
|
2893
|
-
const check = async () => {
|
|
2894
|
-
let ok = false;
|
|
2895
|
-
try {
|
|
2896
|
-
const res = await fetch(prodResourcesPath, { method: "HEAD" });
|
|
2897
|
-
ok = res.ok;
|
|
2898
|
-
} catch {
|
|
2899
|
-
}
|
|
2900
|
-
if (cancelled) return;
|
|
2901
|
-
if (ok) {
|
|
2902
|
-
if (!prodResourcesWasReady.current) {
|
|
2903
|
-
setProdResourcesGeneration((g) => g + 1);
|
|
2904
|
-
}
|
|
2905
|
-
prodResourcesWasReady.current = true;
|
|
2906
|
-
setProdResourcesReady(true);
|
|
2907
|
-
} else {
|
|
2908
|
-
prodResourcesWasReady.current = false;
|
|
2909
|
-
setProdResourcesReady(false);
|
|
2910
|
-
}
|
|
2911
|
-
timer = setTimeout(check, 1e3);
|
|
2912
|
-
};
|
|
2913
|
-
check();
|
|
2914
|
-
return () => {
|
|
2915
|
-
cancelled = true;
|
|
2916
|
-
clearTimeout(timer);
|
|
2917
|
-
};
|
|
2918
|
-
}, [prodResourcesPath]);
|
|
2919
|
-
const effectiveResourceUrl = (prodResourcesPath && prodResourcesReady ? prodResourcesPath : void 0) ?? state.resourceUrl;
|
|
2920
|
-
const prodResourcesLoading = !!prodResourcesPath && !prodResourcesReady;
|
|
2921
|
-
const showEmptyState = prodTools && !hasRun;
|
|
2922
|
-
let content;
|
|
2923
|
-
const iframeBg = "var(--sim-bg-conversation, var(--color-background-primary, transparent))";
|
|
2924
|
-
if (showEmptyState) {
|
|
2925
|
-
content = /* @__PURE__ */ jsxRuntime.jsx(
|
|
2926
|
-
"div",
|
|
2927
|
-
{
|
|
2928
|
-
className: "h-full w-full flex items-center justify-center",
|
|
2929
|
-
style: { background: iframeBg },
|
|
2930
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-sm", style: { color: "var(--color-text-secondary)" }, children: [
|
|
2931
|
-
"Press ",
|
|
2932
|
-
/* @__PURE__ */ jsxRuntime.jsx("strong", { children: "Run" }),
|
|
2933
|
-
" to call the tool"
|
|
2934
|
-
] })
|
|
2935
|
-
}
|
|
2936
|
-
);
|
|
2937
|
-
} else if (prodResourcesLoading) {
|
|
2938
|
-
content = /* @__PURE__ */ jsxRuntime.jsx(
|
|
2939
|
-
"div",
|
|
2940
|
-
{
|
|
2941
|
-
className: "h-full w-full flex items-center justify-center",
|
|
2942
|
-
style: { background: iframeBg },
|
|
2943
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm", style: { color: "var(--color-text-secondary)" }, children: "Building…" })
|
|
2944
|
-
}
|
|
2945
|
-
);
|
|
2946
|
-
} else if (effectiveResourceUrl) {
|
|
2947
|
-
content = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-full w-full", style: { background: iframeBg }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2948
|
-
IframeResource,
|
|
2949
|
-
{
|
|
2950
|
-
src: effectiveResourceUrl,
|
|
2951
|
-
hostContext,
|
|
2952
|
-
toolInput: state.toolInput,
|
|
2953
|
-
toolResult: state.effectiveToolResult,
|
|
2954
|
-
hostOptions: {
|
|
2955
|
-
hostInfo: activeShell?.hostInfo,
|
|
2956
|
-
hostCapabilities: activeShell?.hostCapabilities,
|
|
2957
|
-
onDisplayModeChange: state.handleDisplayModeChange,
|
|
2958
|
-
onUpdateModelContext: state.handleUpdateModelContext,
|
|
2959
|
-
onCallTool: handleCallTool
|
|
2960
|
-
},
|
|
2961
|
-
permissions: state.permissions,
|
|
2962
|
-
prefersBorder: state.prefersBorder,
|
|
2963
|
-
onDisplayModeReady: state.handleDisplayModeReady,
|
|
2964
|
-
debugInjectState: state.modelContext,
|
|
2965
|
-
injectOpenAIRuntime: state.activeHost === "chatgpt",
|
|
2966
|
-
sandboxUrl,
|
|
2967
|
-
className: "h-full w-full"
|
|
2968
|
-
},
|
|
2969
|
-
`${state.activeHost}-${state.selectedSimulationName}-${prodResources}-${prodResourcesGeneration}`
|
|
2970
|
-
) });
|
|
2971
|
-
} else if (!prodResources && state.resourceScript) {
|
|
2972
|
-
content = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-full w-full", style: { background: iframeBg }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2973
|
-
IframeResource,
|
|
2974
|
-
{
|
|
2975
|
-
scriptSrc: state.resourceScript,
|
|
2976
|
-
hostContext,
|
|
2977
|
-
toolInput: state.toolInput,
|
|
2978
|
-
toolResult: state.effectiveToolResult,
|
|
2979
|
-
csp: state.csp,
|
|
2980
|
-
hostOptions: {
|
|
2981
|
-
hostInfo: activeShell?.hostInfo,
|
|
2982
|
-
hostCapabilities: activeShell?.hostCapabilities,
|
|
2983
|
-
onDisplayModeChange: state.handleDisplayModeChange,
|
|
2984
|
-
onUpdateModelContext: state.handleUpdateModelContext,
|
|
2985
|
-
onCallTool: handleCallTool
|
|
2986
|
-
},
|
|
2987
|
-
permissions: state.permissions,
|
|
2988
|
-
prefersBorder: state.prefersBorder,
|
|
2989
|
-
onDisplayModeReady: state.handleDisplayModeReady,
|
|
2990
|
-
debugInjectState: state.modelContext,
|
|
2991
|
-
injectOpenAIRuntime: state.activeHost === "chatgpt",
|
|
2992
|
-
sandboxUrl,
|
|
2993
|
-
className: "h-full w-full"
|
|
2994
|
-
},
|
|
2995
|
-
`${state.activeHost}-${state.selectedSimulationName}`
|
|
2996
|
-
) });
|
|
2997
|
-
} else {
|
|
2998
|
-
content = children;
|
|
2999
|
-
}
|
|
3000
|
-
const applyTheme = activeShell?.applyTheme;
|
|
3001
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ThemeProvider, { theme: state.theme, applyTheme, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3002
|
-
SimpleSidebar,
|
|
3003
|
-
{
|
|
3004
|
-
controls: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1", children: [
|
|
3005
|
-
!hideSimulatorModes && onCallTool && /* @__PURE__ */ jsxRuntime.jsx(
|
|
3006
|
-
SidebarCheckbox,
|
|
3007
|
-
{
|
|
3008
|
-
checked: prodTools,
|
|
3009
|
-
onChange: setProdTools,
|
|
3010
|
-
label: "Prod Tools",
|
|
3011
|
-
tooltip: "Use real tool handlers instead of simulations",
|
|
3012
|
-
docsPath: "api-reference/cli/dev#prod-tools-and-prod-resources-flags"
|
|
3013
|
-
}
|
|
3014
|
-
),
|
|
3015
|
-
!hideSimulatorModes && /* @__PURE__ */ jsxRuntime.jsx(
|
|
3016
|
-
SidebarCheckbox,
|
|
3017
|
-
{
|
|
3018
|
-
checked: prodResources,
|
|
3019
|
-
onChange: setProdResources,
|
|
3020
|
-
label: "Prod Resources",
|
|
3021
|
-
tooltip: "Load resources from dist/ builds instead of HMR",
|
|
3022
|
-
docsPath: "api-reference/cli/dev#prod-tools-and-prod-resources-flags"
|
|
3023
|
-
}
|
|
3024
|
-
),
|
|
3025
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-2", children: [
|
|
3026
|
-
registeredHosts.length > 1 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
3027
|
-
SidebarControl,
|
|
3028
|
-
{
|
|
3029
|
-
label: "Host",
|
|
3030
|
-
tooltip: "Host runtime to simulate",
|
|
3031
|
-
docsPath: "api-reference/functions/host-detection",
|
|
3032
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3033
|
-
SidebarSelect,
|
|
3034
|
-
{
|
|
3035
|
-
value: state.activeHost,
|
|
3036
|
-
onChange: (value) => state.setActiveHost(value),
|
|
3037
|
-
options: registeredHosts.map((h) => ({
|
|
3038
|
-
value: h.id,
|
|
3039
|
-
label: h.label
|
|
3040
|
-
}))
|
|
3041
|
-
}
|
|
3042
|
-
)
|
|
3043
|
-
}
|
|
3044
|
-
),
|
|
3045
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3046
|
-
SidebarControl,
|
|
3047
|
-
{
|
|
3048
|
-
label: "Width",
|
|
3049
|
-
tooltip: "Chat width",
|
|
3050
|
-
docsPath: "api-reference/simulations/simulator",
|
|
3051
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3052
|
-
SidebarSelect,
|
|
3053
|
-
{
|
|
3054
|
-
value: state.screenWidth,
|
|
3055
|
-
onChange: (value) => state.setScreenWidth(value),
|
|
3056
|
-
options: [
|
|
3057
|
-
{ value: "mobile-s", label: "Mobile S (375px)" },
|
|
3058
|
-
{ value: "mobile-l", label: "Mobile L (425px)" },
|
|
3059
|
-
{ value: "tablet", label: "Tablet (768px)" },
|
|
3060
|
-
{ value: "full", label: "100% (Full)" }
|
|
3061
|
-
]
|
|
3062
|
-
}
|
|
3063
|
-
)
|
|
3064
|
-
}
|
|
3065
|
-
)
|
|
3066
|
-
] }),
|
|
3067
|
-
prodTools && toolOptions.length > 1 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
3068
|
-
SidebarControl,
|
|
3069
|
-
{
|
|
3070
|
-
label: "Tool",
|
|
3071
|
-
tooltip: "Tool to call with prod handler",
|
|
3072
|
-
docsPath: "api-reference/cli/dev",
|
|
3073
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3074
|
-
SidebarSelect,
|
|
3075
|
-
{
|
|
3076
|
-
value: state.selectedSimulationName,
|
|
3077
|
-
onChange: (value) => state.setSelectedSimulationName(value),
|
|
3078
|
-
options: toolOptions
|
|
3079
|
-
}
|
|
3080
|
-
)
|
|
3081
|
-
}
|
|
3082
|
-
),
|
|
3083
|
-
!prodTools && state.simulationNames.length > 1 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
3084
|
-
SidebarControl,
|
|
3085
|
-
{
|
|
3086
|
-
label: "Simulation",
|
|
3087
|
-
tooltip: "Test fixture to render",
|
|
3088
|
-
docsPath: "api-reference/simulations/simulation",
|
|
3089
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3090
|
-
SidebarSelect,
|
|
3091
|
-
{
|
|
3092
|
-
value: state.selectedSimulationName,
|
|
3093
|
-
onChange: (value) => state.setSelectedSimulationName(value),
|
|
3094
|
-
options: state.simulationNames.map((name) => {
|
|
3095
|
-
const sim = simulations[name];
|
|
3096
|
-
const resourceTitle = sim.resource ? sim.resource.title || sim.resource.name : void 0;
|
|
3097
|
-
const toolTitle = sim.tool.title || sim.tool.name;
|
|
3098
|
-
return {
|
|
3099
|
-
value: name,
|
|
3100
|
-
label: resourceTitle ? `${resourceTitle}: ${toolTitle}` : toolTitle
|
|
3101
|
-
};
|
|
3102
|
-
})
|
|
3103
|
-
}
|
|
3104
|
-
)
|
|
3105
|
-
}
|
|
3106
|
-
),
|
|
3107
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3108
|
-
SidebarCollapsibleControl,
|
|
3109
|
-
{
|
|
3110
|
-
label: "Host Context",
|
|
3111
|
-
defaultCollapsed: false,
|
|
3112
|
-
tooltip: "Host-provided environment",
|
|
3113
|
-
docsPath: "api-reference/hooks/use-host-context",
|
|
3114
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1", children: [
|
|
3115
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[2fr_1fr] gap-2", children: [
|
|
3116
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3117
|
-
SidebarControl,
|
|
3118
|
-
{
|
|
3119
|
-
label: "Theme",
|
|
3120
|
-
tooltip: "Host color theme",
|
|
3121
|
-
docsPath: "api-reference/hooks/use-theme",
|
|
3122
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3123
|
-
SidebarToggle,
|
|
3124
|
-
{
|
|
3125
|
-
value: state.theme,
|
|
3126
|
-
onChange: (value) => state.setTheme(value),
|
|
3127
|
-
options: [
|
|
3128
|
-
{ value: "light", label: "Light" },
|
|
3129
|
-
{ value: "dark", label: "Dark" }
|
|
3130
|
-
]
|
|
3131
|
-
}
|
|
3132
|
-
)
|
|
3133
|
-
}
|
|
3134
|
-
),
|
|
3135
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3136
|
-
SidebarControl,
|
|
3137
|
-
{
|
|
3138
|
-
label: "Locale",
|
|
3139
|
-
tooltip: "BCP 47 language tag",
|
|
3140
|
-
docsPath: "api-reference/hooks/use-locale",
|
|
3141
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3142
|
-
SidebarInput,
|
|
3143
|
-
{
|
|
3144
|
-
applyOnBlur: true,
|
|
3145
|
-
value: state.locale,
|
|
3146
|
-
onChange: (value) => state.setLocale(value),
|
|
3147
|
-
placeholder: "en-US"
|
|
3148
|
-
}
|
|
3149
|
-
)
|
|
3150
|
-
}
|
|
3151
|
-
)
|
|
3152
|
-
] }),
|
|
3153
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3154
|
-
SidebarControl,
|
|
3155
|
-
{
|
|
3156
|
-
label: "Display Mode",
|
|
3157
|
-
tooltip: "Host resource rendering paradigm",
|
|
3158
|
-
docsPath: "api-reference/hooks/use-display-mode",
|
|
3159
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3160
|
-
SidebarToggle,
|
|
3161
|
-
{
|
|
3162
|
-
value: state.displayMode,
|
|
3163
|
-
onChange: (value) => state.setDisplayMode(value),
|
|
3164
|
-
options: [
|
|
3165
|
-
{ value: "inline", label: "Inline" },
|
|
3166
|
-
{ value: "pip", label: "PiP" },
|
|
3167
|
-
{ value: "fullscreen", label: "Full" }
|
|
3168
|
-
]
|
|
3169
|
-
}
|
|
3170
|
-
)
|
|
3171
|
-
}
|
|
3172
|
-
),
|
|
3173
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-7 gap-2", children: [
|
|
3174
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-3", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3175
|
-
SidebarControl,
|
|
3176
|
-
{
|
|
3177
|
-
label: "Platform",
|
|
3178
|
-
tooltip: "End user device platform",
|
|
3179
|
-
docsPath: "api-reference/hooks/use-platform",
|
|
3180
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3181
|
-
SidebarSelect,
|
|
3182
|
-
{
|
|
3183
|
-
value: state.platform,
|
|
3184
|
-
onChange: (value) => {
|
|
3185
|
-
const p2 = value;
|
|
3186
|
-
state.setPlatform(p2);
|
|
3187
|
-
if (p2 === "mobile") {
|
|
3188
|
-
state.setHover(false);
|
|
3189
|
-
state.setTouch(true);
|
|
3190
|
-
} else if (p2 === "desktop") {
|
|
3191
|
-
state.setHover(true);
|
|
3192
|
-
state.setTouch(false);
|
|
3193
|
-
} else {
|
|
3194
|
-
state.setHover(true);
|
|
3195
|
-
state.setTouch(false);
|
|
3196
|
-
}
|
|
3197
|
-
},
|
|
3198
|
-
options: [
|
|
3199
|
-
{ value: "mobile", label: "Mobile" },
|
|
3200
|
-
{ value: "desktop", label: "Desktop" },
|
|
3201
|
-
{ value: "web", label: "Web" }
|
|
3202
|
-
]
|
|
3203
|
-
}
|
|
3204
|
-
)
|
|
3205
|
-
}
|
|
3206
|
-
) }),
|
|
3207
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-4", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3208
|
-
SidebarControl,
|
|
3209
|
-
{
|
|
3210
|
-
label: "Capabilities",
|
|
3211
|
-
tooltip: "End user device capabilities",
|
|
3212
|
-
docsPath: "api-reference/hooks/use-device-capabilities",
|
|
3213
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
|
|
3214
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3215
|
-
SidebarCheckbox,
|
|
3216
|
-
{
|
|
3217
|
-
checked: state.hover,
|
|
3218
|
-
onChange: state.setHover,
|
|
3219
|
-
label: "Hover"
|
|
3220
|
-
}
|
|
3221
|
-
),
|
|
3222
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3223
|
-
SidebarCheckbox,
|
|
3224
|
-
{
|
|
3225
|
-
checked: state.touch,
|
|
3226
|
-
onChange: state.setTouch,
|
|
3227
|
-
label: "Touch"
|
|
3228
|
-
}
|
|
3229
|
-
)
|
|
3230
|
-
] })
|
|
3231
|
-
}
|
|
3232
|
-
) })
|
|
3233
|
-
] }),
|
|
3234
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3235
|
-
SidebarControl,
|
|
3236
|
-
{
|
|
3237
|
-
label: "Time Zone",
|
|
3238
|
-
tooltip: "End user IANA time zone",
|
|
3239
|
-
docsPath: "api-reference/hooks/use-time-zone",
|
|
3240
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3241
|
-
SidebarInput,
|
|
3242
|
-
{
|
|
3243
|
-
applyOnBlur: true,
|
|
3244
|
-
value: state.timeZone,
|
|
3245
|
-
onChange: (value) => state.setTimeZone(value),
|
|
3246
|
-
placeholder: "e.g. America/New_York"
|
|
3247
|
-
}
|
|
3248
|
-
)
|
|
3249
|
-
}
|
|
3250
|
-
),
|
|
3251
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3252
|
-
SidebarControl,
|
|
3253
|
-
{
|
|
3254
|
-
label: "Container Dimensions",
|
|
3255
|
-
tooltip: "Host-enforced size constraints (px)",
|
|
3256
|
-
docsPath: "api-reference/hooks/use-viewport",
|
|
3257
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-4 gap-1", children: [
|
|
3258
|
-
/* @__PURE__ */ jsxRuntime.jsx(SidebarControl, { label: "Height", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3259
|
-
SidebarInput,
|
|
3260
|
-
{
|
|
3261
|
-
type: "number",
|
|
3262
|
-
applyOnBlur: true,
|
|
3263
|
-
placeholder: "-",
|
|
3264
|
-
value: state.containerHeight != null ? String(state.containerHeight) : "",
|
|
3265
|
-
onChange: (value) => state.setContainerHeight(value ? Number(value) : void 0)
|
|
3266
|
-
}
|
|
3267
|
-
) }),
|
|
3268
|
-
/* @__PURE__ */ jsxRuntime.jsx(SidebarControl, { label: "Width", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3269
|
-
SidebarInput,
|
|
3270
|
-
{
|
|
3271
|
-
type: "number",
|
|
3272
|
-
applyOnBlur: true,
|
|
3273
|
-
placeholder: "-",
|
|
3274
|
-
value: state.containerWidth != null ? String(state.containerWidth) : "",
|
|
3275
|
-
onChange: (value) => state.setContainerWidth(value ? Number(value) : void 0)
|
|
3276
|
-
}
|
|
3277
|
-
) }),
|
|
3278
|
-
/* @__PURE__ */ jsxRuntime.jsx(SidebarControl, { label: "Max H", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3279
|
-
SidebarInput,
|
|
3280
|
-
{
|
|
3281
|
-
type: "number",
|
|
3282
|
-
applyOnBlur: true,
|
|
3283
|
-
placeholder: "-",
|
|
3284
|
-
value: state.containerMaxHeight != null ? String(state.containerMaxHeight) : "",
|
|
3285
|
-
onChange: (value) => state.setContainerMaxHeight(value ? Number(value) : void 0)
|
|
3286
|
-
}
|
|
3287
|
-
) }),
|
|
3288
|
-
/* @__PURE__ */ jsxRuntime.jsx(SidebarControl, { label: "Max W", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3289
|
-
SidebarInput,
|
|
3290
|
-
{
|
|
3291
|
-
type: "number",
|
|
3292
|
-
applyOnBlur: true,
|
|
3293
|
-
placeholder: state.measuredContentWidth != null ? String(state.measuredContentWidth) : "-",
|
|
3294
|
-
value: state.containerMaxWidth != null ? String(state.containerMaxWidth) : "",
|
|
3295
|
-
onChange: (value) => state.setContainerMaxWidth(value ? Number(value) : void 0)
|
|
3296
|
-
}
|
|
3297
|
-
) })
|
|
3298
|
-
] })
|
|
3299
|
-
}
|
|
3300
|
-
),
|
|
3301
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3302
|
-
SidebarControl,
|
|
3303
|
-
{
|
|
3304
|
-
label: "Safe Area Insets",
|
|
3305
|
-
tooltip: "Device safe area padding (px)",
|
|
3306
|
-
docsPath: "api-reference/hooks/use-safe-area",
|
|
3307
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-4 gap-1", children: [
|
|
3308
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-0.5", children: [
|
|
3309
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3310
|
-
"span",
|
|
3311
|
-
{
|
|
3312
|
-
className: "text-[10px]",
|
|
3313
|
-
style: { color: "var(--color-text-secondary)" },
|
|
3314
|
-
children: "↑"
|
|
3315
|
-
}
|
|
3316
|
-
),
|
|
3317
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3318
|
-
SidebarInput,
|
|
3319
|
-
{
|
|
3320
|
-
type: "number",
|
|
3321
|
-
applyOnBlur: true,
|
|
3322
|
-
placeholder: "-",
|
|
3323
|
-
value: state.safeAreaInsets.top ? String(state.safeAreaInsets.top) : "",
|
|
3324
|
-
onChange: (value) => state.setSafeAreaInsets((prev) => ({ ...prev, top: Number(value) || 0 }))
|
|
3325
|
-
}
|
|
3326
|
-
)
|
|
3327
|
-
] }),
|
|
3328
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-0.5", children: [
|
|
3329
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3330
|
-
"span",
|
|
3331
|
-
{
|
|
3332
|
-
className: "text-[10px]",
|
|
3333
|
-
style: { color: "var(--color-text-secondary)" },
|
|
3334
|
-
children: "↓"
|
|
3335
|
-
}
|
|
3336
|
-
),
|
|
3337
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3338
|
-
SidebarInput,
|
|
3339
|
-
{
|
|
3340
|
-
type: "number",
|
|
3341
|
-
applyOnBlur: true,
|
|
3342
|
-
placeholder: "-",
|
|
3343
|
-
value: state.safeAreaInsets.bottom ? String(state.safeAreaInsets.bottom) : "",
|
|
3344
|
-
onChange: (value) => state.setSafeAreaInsets((prev) => ({
|
|
3345
|
-
...prev,
|
|
3346
|
-
bottom: Number(value) || 0
|
|
3347
|
-
}))
|
|
3348
|
-
}
|
|
3349
|
-
)
|
|
3350
|
-
] }),
|
|
3351
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-0.5", children: [
|
|
3352
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3353
|
-
"span",
|
|
3354
|
-
{
|
|
3355
|
-
className: "text-[10px]",
|
|
3356
|
-
style: { color: "var(--color-text-secondary)" },
|
|
3357
|
-
children: "←"
|
|
3358
|
-
}
|
|
3359
|
-
),
|
|
3360
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3361
|
-
SidebarInput,
|
|
3362
|
-
{
|
|
3363
|
-
type: "number",
|
|
3364
|
-
applyOnBlur: true,
|
|
3365
|
-
placeholder: "-",
|
|
3366
|
-
value: state.safeAreaInsets.left ? String(state.safeAreaInsets.left) : "",
|
|
3367
|
-
onChange: (value) => state.setSafeAreaInsets((prev) => ({ ...prev, left: Number(value) || 0 }))
|
|
3368
|
-
}
|
|
3369
|
-
)
|
|
3370
|
-
] }),
|
|
3371
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-0.5", children: [
|
|
3372
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3373
|
-
"span",
|
|
3374
|
-
{
|
|
3375
|
-
className: "text-[10px]",
|
|
3376
|
-
style: { color: "var(--color-text-secondary)" },
|
|
3377
|
-
children: "→"
|
|
3378
|
-
}
|
|
3379
|
-
),
|
|
3380
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3381
|
-
SidebarInput,
|
|
3382
|
-
{
|
|
3383
|
-
type: "number",
|
|
3384
|
-
applyOnBlur: true,
|
|
3385
|
-
placeholder: "-",
|
|
3386
|
-
value: state.safeAreaInsets.right ? String(state.safeAreaInsets.right) : "",
|
|
3387
|
-
onChange: (value) => state.setSafeAreaInsets((prev) => ({
|
|
3388
|
-
...prev,
|
|
3389
|
-
right: Number(value) || 0
|
|
3390
|
-
}))
|
|
3391
|
-
}
|
|
3392
|
-
)
|
|
3393
|
-
] })
|
|
3394
|
-
] })
|
|
3395
|
-
}
|
|
3396
|
-
)
|
|
3397
|
-
] })
|
|
3398
|
-
}
|
|
3399
|
-
),
|
|
3400
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3401
|
-
SidebarCollapsibleControl,
|
|
3402
|
-
{
|
|
3403
|
-
label: "App Context",
|
|
3404
|
-
defaultCollapsed: true,
|
|
3405
|
-
tooltip: "App-provided context shared with the model",
|
|
3406
|
-
docsPath: "api-reference/hooks/use-app-state",
|
|
3407
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3408
|
-
SidebarTextarea,
|
|
3409
|
-
{
|
|
3410
|
-
value: state.modelContextJson,
|
|
3411
|
-
onChange: (json) => state.validateJSON(json, state.setModelContextJson, state.setModelContextError),
|
|
3412
|
-
onFocus: () => state.setEditingField("modelContext"),
|
|
3413
|
-
onBlur: () => state.commitJSON(state.modelContextJson, state.setModelContextError, (parsed) => {
|
|
3414
|
-
state.setModelContext(parsed);
|
|
3415
|
-
}),
|
|
3416
|
-
error: state.modelContextError,
|
|
3417
|
-
maxRows: 8
|
|
3418
|
-
}
|
|
3419
|
-
)
|
|
3420
|
-
}
|
|
3421
|
-
),
|
|
3422
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3423
|
-
SidebarCollapsibleControl,
|
|
3424
|
-
{
|
|
3425
|
-
label: "Tool Input (JSON)",
|
|
3426
|
-
defaultCollapsed: !prodTools,
|
|
3427
|
-
tooltip: "Arguments passed to the tool",
|
|
3428
|
-
docsPath: "api-reference/hooks/use-tool-data",
|
|
3429
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3430
|
-
SidebarTextarea,
|
|
3431
|
-
{
|
|
3432
|
-
value: state.toolInputJson,
|
|
3433
|
-
onChange: (json) => state.validateJSON(json, state.setToolInputJson, state.setToolInputError),
|
|
3434
|
-
onFocus: () => state.setEditingField("toolInput"),
|
|
3435
|
-
onBlur: () => state.commitJSON(
|
|
3436
|
-
state.toolInputJson,
|
|
3437
|
-
state.setToolInputError,
|
|
3438
|
-
(parsed) => state.setToolInput(parsed ?? {})
|
|
3439
|
-
),
|
|
3440
|
-
error: state.toolInputError,
|
|
3441
|
-
maxRows: 8
|
|
3442
|
-
}
|
|
3443
|
-
)
|
|
3444
|
-
},
|
|
3445
|
-
`tool-input-${prodTools}`
|
|
3446
|
-
),
|
|
3447
|
-
!prodTools && /* @__PURE__ */ jsxRuntime.jsx(
|
|
3448
|
-
SidebarCollapsibleControl,
|
|
3449
|
-
{
|
|
3450
|
-
label: "Tool Result (JSON)",
|
|
3451
|
-
defaultCollapsed: false,
|
|
3452
|
-
tooltip: "Structured content returned by the tool",
|
|
3453
|
-
docsPath: "api-reference/hooks/use-tool-data",
|
|
3454
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3455
|
-
SidebarTextarea,
|
|
3456
|
-
{
|
|
3457
|
-
value: state.toolResultJson,
|
|
3458
|
-
onChange: (json) => state.validateJSON(json, state.setToolResultJson, state.setToolResultError),
|
|
3459
|
-
onFocus: () => state.setEditingField("toolResult"),
|
|
3460
|
-
onBlur: () => state.commitJSON(state.toolResultJson, state.setToolResultError, (parsed) => {
|
|
3461
|
-
if (parsed === null) {
|
|
3462
|
-
state.setToolResult(void 0);
|
|
3463
|
-
} else {
|
|
3464
|
-
const result = parsed;
|
|
3465
|
-
if ("content" in result || "structuredContent" in result) {
|
|
3466
|
-
state.setToolResult(
|
|
3467
|
-
result
|
|
3468
|
-
);
|
|
3469
|
-
} else {
|
|
3470
|
-
state.setToolResult({ content: [], structuredContent: result });
|
|
3471
|
-
}
|
|
3472
|
-
}
|
|
3473
|
-
}),
|
|
3474
|
-
error: state.toolResultError,
|
|
3475
|
-
maxRows: 8
|
|
3476
|
-
}
|
|
3477
|
-
)
|
|
3478
|
-
}
|
|
3479
|
-
)
|
|
3480
|
-
] }),
|
|
3481
|
-
children: ShellConversation ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3482
|
-
ShellConversation,
|
|
3483
|
-
{
|
|
3484
|
-
screenWidth: state.screenWidth,
|
|
3485
|
-
displayMode: state.displayMode,
|
|
3486
|
-
platform: state.platform,
|
|
3487
|
-
onRequestDisplayMode: state.handleDisplayModeChange,
|
|
3488
|
-
appName,
|
|
3489
|
-
appIcon,
|
|
3490
|
-
userMessage: prodToolsUserMessage ?? state.selectedSim?.userMessage,
|
|
3491
|
-
onContentWidthChange: state.handleContentWidthChange,
|
|
3492
|
-
headerAction: prodTools && onCallTool ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3493
|
-
"button",
|
|
3494
|
-
{
|
|
3495
|
-
type: "button",
|
|
3496
|
-
onClick: handleRun,
|
|
3497
|
-
disabled: isRunning,
|
|
3498
|
-
className: "rounded-full px-3 py-1 text-sm font-medium transition-opacity disabled:opacity-40 flex items-center gap-1.5 cursor-pointer",
|
|
3499
|
-
style: {
|
|
3500
|
-
backgroundColor: "var(--color-text-primary)",
|
|
3501
|
-
color: "var(--color-background-primary)"
|
|
3502
|
-
},
|
|
3503
|
-
children: [
|
|
3504
|
-
showCheck ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3505
|
-
"svg",
|
|
3506
|
-
{
|
|
3507
|
-
width: "12",
|
|
3508
|
-
height: "12",
|
|
3509
|
-
viewBox: "0 0 12 12",
|
|
3510
|
-
fill: "none",
|
|
3511
|
-
stroke: "currentColor",
|
|
3512
|
-
strokeWidth: "2",
|
|
3513
|
-
strokeLinecap: "round",
|
|
3514
|
-
strokeLinejoin: "round",
|
|
3515
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M2 6L5 9L10 3" })
|
|
3516
|
-
}
|
|
3517
|
-
) : /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "10", height: "12", viewBox: "0 0 10 12", fill: "currentColor", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M0 0L10 6L0 12V0Z" }) }),
|
|
3518
|
-
"Run"
|
|
3519
|
-
]
|
|
3520
|
-
}
|
|
3521
|
-
) : void 0,
|
|
3522
|
-
children: content
|
|
3523
|
-
}
|
|
3524
|
-
) : content
|
|
3525
|
-
}
|
|
3526
|
-
) });
|
|
3527
|
-
}
|
|
3528
|
-
exports.DEFAULT_STYLE_VARIABLES = DEFAULT_STYLE_VARIABLES;
|
|
3529
|
-
exports.IframeResource = IframeResource;
|
|
3530
|
-
exports.McpAppHost = McpAppHost;
|
|
3531
|
-
exports.SCREEN_WIDTHS = SCREEN_WIDTHS;
|
|
3532
|
-
exports.SidebarCheckbox = SidebarCheckbox;
|
|
3533
|
-
exports.SidebarCollapsibleControl = SidebarCollapsibleControl;
|
|
3534
|
-
exports.SidebarControl = SidebarControl;
|
|
3535
|
-
exports.SidebarInput = SidebarInput;
|
|
3536
|
-
exports.SidebarSelect = SidebarSelect;
|
|
3537
|
-
exports.SidebarTextarea = SidebarTextarea;
|
|
3538
|
-
exports.SidebarToggle = SidebarToggle;
|
|
3539
|
-
exports.SimpleSidebar = SimpleSidebar;
|
|
3540
|
-
exports.Simulator = Simulator;
|
|
3541
|
-
exports.ThemeProvider = ThemeProvider;
|
|
3542
|
-
exports.extractResourceCSP = extractResourceCSP;
|
|
3543
|
-
exports.getHostShell = getHostShell;
|
|
3544
|
-
exports.getRegisteredHosts = getRegisteredHosts;
|
|
3545
|
-
exports.registerHostShell = registerHostShell;
|
|
3546
|
-
exports.resolveServerToolResult = resolveServerToolResult;
|
|
3547
|
-
exports.useSimulatorState = useSimulatorState;
|
|
3548
|
-
exports.useThemeContext = useThemeContext;
|
|
3549
|
-
//# sourceMappingURL=simulator-Gc6n_fT4.cjs.map
|