sunpeak 0.4.2 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/bin/sunpeak.js +1 -1
- package/dist/chatgpt/chatgpt-simulator-types.d.ts +1 -1
- package/dist/chatgpt/chatgpt-simulator.d.ts +4 -15
- package/dist/chatgpt/index.d.ts +1 -1
- package/dist/chatgpt/mock-openai.d.ts +4 -16
- package/dist/index.cjs +70 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +70 -42
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.cjs +45 -112
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.d.ts +2 -1
- package/dist/mcp/index.js +45 -112
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/server.d.ts +2 -4
- package/dist/mcp/types.d.ts +16 -62
- package/dist/providers/index.d.ts +1 -3
- package/dist/providers/openai/index.d.ts +7 -0
- package/dist/{chatgpt/openai-provider.d.ts → providers/openai/provider.d.ts} +1 -1
- package/dist/{chatgpt/openai-types.d.ts → providers/openai/types.d.ts} +3 -32
- package/dist/providers/types.d.ts +4 -5
- package/dist/runtime/index.d.ts +7 -0
- package/dist/runtime/provider-detection.d.ts +17 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/runtime.d.ts +34 -0
- package/dist/types/simulation.d.ts +47 -0
- package/package.json +2 -2
- package/template/README.md +1 -1
- package/template/dev/main.tsx +6 -2
- package/template/mcp/server.ts +8 -9
- package/template/package.json +1 -1
- package/template/scripts/build-all.mjs +43 -0
- package/template/scripts/validate.mjs +16 -7
- package/template/src/components/album/albums.tsx +7 -7
- package/template/src/components/card/card.tsx +4 -0
- package/template/src/components/index.ts +1 -1
- package/template/src/components/resources/AlbumsResource.tsx +13 -0
- package/template/src/{App.tsx → components/resources/CounterResource.tsx} +5 -14
- package/template/src/components/{simulations/carousel-simulation.tsx → resources/PlacesResource.tsx} +11 -17
- package/template/src/components/resources/index.ts +3 -0
- package/template/src/index-albums.tsx +9 -0
- package/template/src/index-carousel.tsx +9 -0
- package/template/src/index-counter.tsx +9 -0
- package/template/src/simulations/albums-simulation.ts +157 -0
- package/template/src/simulations/carousel-simulation.ts +94 -0
- package/template/src/simulations/counter-simulation.ts +43 -0
- package/template/src/simulations/index.ts +11 -0
- package/template/src/simulations/simulation-configs.ts +23 -0
- package/template/src/simulations/simulations.ts +36 -0
- package/template/src/simulations/types.ts +12 -0
- package/template/vite.config.build.ts +20 -14
- package/dist/chatgpt/mcp-provider.d.ts +0 -25
- package/template/data/albums.json +0 -112
- package/template/data/places.json +0 -49
- package/template/src/components/simulations/albums-simulation.tsx +0 -20
- package/template/src/components/simulations/app-simulation.tsx +0 -13
- package/template/src/components/simulations/index.tsx +0 -14
- package/template/src/index.chatgpt.tsx +0 -8
- package/template/src/index.ts +0 -3
package/dist/index.js
CHANGED
|
@@ -5,12 +5,6 @@ import * as React from "react";
|
|
|
5
5
|
import { useSyncExternalStore, useMemo, useState, useEffect, useCallback, useRef, useLayoutEffect } from "react";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
const SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
|
|
8
|
-
class SetGlobalsEvent extends CustomEvent {
|
|
9
|
-
constructor() {
|
|
10
|
-
super(...arguments);
|
|
11
|
-
__publicField(this, "type", SET_GLOBALS_EVENT_TYPE);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
8
|
function isOpenAiAvailable() {
|
|
15
9
|
return typeof window !== "undefined" && window.openai != null;
|
|
16
10
|
}
|
|
@@ -67,7 +61,7 @@ function getOpenAiProvider() {
|
|
|
67
61
|
}
|
|
68
62
|
let cachedProvider = null;
|
|
69
63
|
let detectionComplete = false;
|
|
70
|
-
function
|
|
64
|
+
function detectProvider() {
|
|
71
65
|
if (detectionComplete) {
|
|
72
66
|
return cachedProvider;
|
|
73
67
|
}
|
|
@@ -77,8 +71,18 @@ function getProvider() {
|
|
|
77
71
|
detectionComplete = true;
|
|
78
72
|
return cachedProvider;
|
|
79
73
|
}
|
|
74
|
+
function isProviderAvailable$1() {
|
|
75
|
+
return detectProvider() !== null;
|
|
76
|
+
}
|
|
77
|
+
function resetProviderCache$1() {
|
|
78
|
+
cachedProvider = null;
|
|
79
|
+
detectionComplete = false;
|
|
80
|
+
}
|
|
81
|
+
function getProvider() {
|
|
82
|
+
return detectProvider();
|
|
83
|
+
}
|
|
80
84
|
function isProviderAvailable() {
|
|
81
|
-
return
|
|
85
|
+
return isProviderAvailable$1();
|
|
82
86
|
}
|
|
83
87
|
function getGlobal(key) {
|
|
84
88
|
const provider = getProvider();
|
|
@@ -94,8 +98,7 @@ function getAPI() {
|
|
|
94
98
|
return (provider == null ? void 0 : provider.getAPI()) ?? null;
|
|
95
99
|
}
|
|
96
100
|
function resetProviderCache() {
|
|
97
|
-
|
|
98
|
-
detectionComplete = false;
|
|
101
|
+
resetProviderCache$1();
|
|
99
102
|
}
|
|
100
103
|
function useWidgetGlobal(key) {
|
|
101
104
|
return useSyncExternalStore(
|
|
@@ -3377,9 +3380,9 @@ const SCREEN_WIDTHS = {
|
|
|
3377
3380
|
function Conversation({
|
|
3378
3381
|
children,
|
|
3379
3382
|
screenWidth,
|
|
3380
|
-
appName = "
|
|
3383
|
+
appName = "Sunpeak App",
|
|
3381
3384
|
appIcon,
|
|
3382
|
-
userMessage = "
|
|
3385
|
+
userMessage = "What have you got for me today?"
|
|
3383
3386
|
}) {
|
|
3384
3387
|
const displayMode = useDisplayMode() ?? "inline";
|
|
3385
3388
|
const containerWidth = screenWidth === "full" ? "100%" : `${SCREEN_WIDTHS[screenWidth]}px`;
|
|
@@ -3387,7 +3390,7 @@ function Conversation({
|
|
|
3387
3390
|
return /* @__PURE__ */ jsx("div", { className: "flex flex-col bg-surface w-full flex-1", children: /* @__PURE__ */ jsx("div", { className: "flex-1 overflow-auto", children }) });
|
|
3388
3391
|
}
|
|
3389
3392
|
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col bg-surface w-full h-full flex-1", children: [
|
|
3390
|
-
/* @__PURE__ */ jsx("header", { className: "h-12 border-b border-subtle bg-surface flex items-center px-4 text-lg", children: /* @__PURE__ */ jsx("span", { className: "text-foreground", children: "
|
|
3393
|
+
/* @__PURE__ */ jsx("header", { className: "h-12 border-b border-subtle bg-surface flex items-center px-4 text-lg", children: /* @__PURE__ */ jsx("span", { className: "text-foreground", children: "SimGPT" }) }),
|
|
3391
3394
|
/* @__PURE__ */ jsxs(
|
|
3392
3395
|
"div",
|
|
3393
3396
|
{
|
|
@@ -3458,7 +3461,7 @@ function Conversation({
|
|
|
3458
3461
|
type: "text",
|
|
3459
3462
|
name: "userInput",
|
|
3460
3463
|
disabled: true,
|
|
3461
|
-
placeholder: "Message
|
|
3464
|
+
placeholder: "Message SimGPT",
|
|
3462
3465
|
className: "w-full bg-[var(--color-background-primary)] dark:bg-[#303030] text-secondary-foreground placeholder:text-muted-foreground rounded-3xl px-5 py-3 pr-12 shadow-md light:border border-[#0000000f]"
|
|
3463
3466
|
}
|
|
3464
3467
|
) }) }) })
|
|
@@ -3554,12 +3557,33 @@ function initMockOpenAI(initialData) {
|
|
|
3554
3557
|
if ((initialData == null ? void 0 : initialData.theme) !== void 0) {
|
|
3555
3558
|
mock.theme = initialData.theme;
|
|
3556
3559
|
}
|
|
3560
|
+
if ((initialData == null ? void 0 : initialData.userAgent) !== void 0) {
|
|
3561
|
+
mock.userAgent = initialData.userAgent;
|
|
3562
|
+
}
|
|
3563
|
+
if ((initialData == null ? void 0 : initialData.locale) !== void 0) {
|
|
3564
|
+
mock.locale = initialData.locale;
|
|
3565
|
+
}
|
|
3566
|
+
if ((initialData == null ? void 0 : initialData.maxHeight) !== void 0) {
|
|
3567
|
+
mock.maxHeight = initialData.maxHeight;
|
|
3568
|
+
}
|
|
3557
3569
|
if ((initialData == null ? void 0 : initialData.displayMode) !== void 0) {
|
|
3558
3570
|
mock.displayMode = initialData.displayMode;
|
|
3559
3571
|
}
|
|
3572
|
+
if ((initialData == null ? void 0 : initialData.safeArea) !== void 0) {
|
|
3573
|
+
mock.safeArea = initialData.safeArea;
|
|
3574
|
+
}
|
|
3575
|
+
if ((initialData == null ? void 0 : initialData.view) !== void 0) {
|
|
3576
|
+
mock.view = initialData.view;
|
|
3577
|
+
}
|
|
3578
|
+
if ((initialData == null ? void 0 : initialData.toolInput) !== void 0) {
|
|
3579
|
+
mock.toolInput = initialData.toolInput;
|
|
3580
|
+
}
|
|
3560
3581
|
if ((initialData == null ? void 0 : initialData.toolOutput) !== void 0) {
|
|
3561
3582
|
mock.toolOutput = initialData.toolOutput;
|
|
3562
3583
|
}
|
|
3584
|
+
if ((initialData == null ? void 0 : initialData.toolResponseMetadata) !== void 0) {
|
|
3585
|
+
mock.toolResponseMetadata = initialData.toolResponseMetadata;
|
|
3586
|
+
}
|
|
3563
3587
|
if ((initialData == null ? void 0 : initialData.widgetState) !== void 0) {
|
|
3564
3588
|
mock.widgetState = initialData.widgetState;
|
|
3565
3589
|
}
|
|
@@ -3608,38 +3632,42 @@ const DEFAULT_THEME = "dark";
|
|
|
3608
3632
|
const DEFAULT_DISPLAY_MODE = "inline";
|
|
3609
3633
|
function ChatGPTSimulator({
|
|
3610
3634
|
children,
|
|
3611
|
-
simulations = []
|
|
3635
|
+
simulations = [],
|
|
3636
|
+
appName = "Sunpeak App",
|
|
3637
|
+
appIcon
|
|
3612
3638
|
}) {
|
|
3613
3639
|
const [screenWidth, setScreenWidth] = React.useState("full");
|
|
3640
|
+
const getSimulationKey = (sim) => `${sim.resource.name}-${sim.tool.name}`;
|
|
3614
3641
|
const [selectedKey, setSelectedKey] = React.useState(
|
|
3615
|
-
simulations.length > 0 ? simulations[0]
|
|
3642
|
+
simulations.length > 0 ? getSimulationKey(simulations[0]) : ""
|
|
3616
3643
|
);
|
|
3617
|
-
const selectedSim = simulations.find((sim) => sim
|
|
3618
|
-
const appName = selectedSim == null ? void 0 : selectedSim.appName;
|
|
3619
|
-
const appIcon = selectedSim == null ? void 0 : selectedSim.appIcon;
|
|
3644
|
+
const selectedSim = simulations.find((sim) => getSimulationKey(sim) === selectedKey);
|
|
3620
3645
|
const userMessage = selectedSim == null ? void 0 : selectedSim.userMessage;
|
|
3621
|
-
const toolOutput = (selectedSim == null ? void 0 : selectedSim.toolOutput) ?? null;
|
|
3622
|
-
const widgetState = (selectedSim == null ? void 0 : selectedSim.widgetState) ?? null;
|
|
3623
3646
|
const mock = useMemo(
|
|
3624
|
-
() =>
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3647
|
+
() => {
|
|
3648
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3649
|
+
return initMockOpenAI({
|
|
3650
|
+
theme: ((_a = selectedSim == null ? void 0 : selectedSim.simulationGlobals) == null ? void 0 : _a.theme) ?? DEFAULT_THEME,
|
|
3651
|
+
userAgent: (_b = selectedSim == null ? void 0 : selectedSim.simulationGlobals) == null ? void 0 : _b.userAgent,
|
|
3652
|
+
locale: (_c = selectedSim == null ? void 0 : selectedSim.simulationGlobals) == null ? void 0 : _c.locale,
|
|
3653
|
+
maxHeight: (_d = selectedSim == null ? void 0 : selectedSim.simulationGlobals) == null ? void 0 : _d.maxHeight,
|
|
3654
|
+
displayMode: ((_e = selectedSim == null ? void 0 : selectedSim.simulationGlobals) == null ? void 0 : _e.displayMode) ?? DEFAULT_DISPLAY_MODE,
|
|
3655
|
+
safeArea: (_f = selectedSim == null ? void 0 : selectedSim.simulationGlobals) == null ? void 0 : _f.safeArea,
|
|
3656
|
+
view: (_g = selectedSim == null ? void 0 : selectedSim.simulationGlobals) == null ? void 0 : _g.view,
|
|
3657
|
+
toolInput: (_h = selectedSim == null ? void 0 : selectedSim.simulationGlobals) == null ? void 0 : _h.toolInput,
|
|
3658
|
+
widgetState: ((_i = selectedSim == null ? void 0 : selectedSim.simulationGlobals) == null ? void 0 : _i.widgetState) ?? null,
|
|
3659
|
+
toolOutput: ((_j = selectedSim == null ? void 0 : selectedSim.toolCall) == null ? void 0 : _j.structuredContent) ?? null
|
|
3660
|
+
});
|
|
3661
|
+
},
|
|
3662
|
+
[selectedSim]
|
|
3629
3663
|
);
|
|
3630
3664
|
const theme = useTheme() ?? DEFAULT_THEME;
|
|
3631
3665
|
const displayMode = useDisplayMode() ?? DEFAULT_DISPLAY_MODE;
|
|
3632
3666
|
useLayoutEffect(() => {
|
|
3633
3667
|
if (mock && typeof window !== "undefined") {
|
|
3634
3668
|
window.openai = mock;
|
|
3635
|
-
if (toolOutput !== void 0) {
|
|
3636
|
-
mock.setToolOutput(toolOutput);
|
|
3637
|
-
}
|
|
3638
|
-
if (widgetState !== void 0) {
|
|
3639
|
-
mock.setWidgetStateExternal(widgetState);
|
|
3640
|
-
}
|
|
3641
3669
|
}
|
|
3642
|
-
}, [mock
|
|
3670
|
+
}, [mock]);
|
|
3643
3671
|
useEffect(() => {
|
|
3644
3672
|
return () => {
|
|
3645
3673
|
if (typeof window !== "undefined") {
|
|
@@ -3647,7 +3675,7 @@ function ChatGPTSimulator({
|
|
|
3647
3675
|
}
|
|
3648
3676
|
};
|
|
3649
3677
|
}, []);
|
|
3650
|
-
const SelectedComponent = selectedSim == null ? void 0 : selectedSim.
|
|
3678
|
+
const SelectedComponent = selectedSim == null ? void 0 : selectedSim.resourceComponent;
|
|
3651
3679
|
const content = SelectedComponent ? /* @__PURE__ */ jsx(SelectedComponent, {}) : children;
|
|
3652
3680
|
return /* @__PURE__ */ jsx(ThemeProvider, { theme, children: /* @__PURE__ */ jsx(
|
|
3653
3681
|
SimpleSidebar,
|
|
@@ -3658,10 +3686,14 @@ function ChatGPTSimulator({
|
|
|
3658
3686
|
{
|
|
3659
3687
|
value: selectedKey,
|
|
3660
3688
|
onChange: (value) => setSelectedKey(value),
|
|
3661
|
-
options: simulations.map((sim) =>
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3689
|
+
options: simulations.map((sim) => {
|
|
3690
|
+
const resourceTitle = sim.resource.title || sim.resource.name;
|
|
3691
|
+
const toolTitle = sim.tool.title || sim.tool.name;
|
|
3692
|
+
return {
|
|
3693
|
+
value: getSimulationKey(sim),
|
|
3694
|
+
label: `${resourceTitle} ${toolTitle}`
|
|
3695
|
+
};
|
|
3696
|
+
})
|
|
3665
3697
|
}
|
|
3666
3698
|
) }),
|
|
3667
3699
|
/* @__PURE__ */ jsx(SidebarControl, { label: "Theme", children: /* @__PURE__ */ jsx(
|
|
@@ -3717,17 +3749,13 @@ function ChatGPTSimulator({
|
|
|
3717
3749
|
export {
|
|
3718
3750
|
ChatGPTSimulator,
|
|
3719
3751
|
SCREEN_WIDTHS,
|
|
3720
|
-
SET_GLOBALS_EVENT_TYPE,
|
|
3721
|
-
SetGlobalsEvent,
|
|
3722
3752
|
ThemeProvider,
|
|
3723
3753
|
cn,
|
|
3724
3754
|
getAPI,
|
|
3725
3755
|
getGlobal,
|
|
3726
|
-
getOpenAiProvider,
|
|
3727
3756
|
getProvider,
|
|
3728
3757
|
initMockOpenAI,
|
|
3729
3758
|
isHoverAvailable,
|
|
3730
|
-
isOpenAiAvailable,
|
|
3731
3759
|
isPrimarilyTouchDevice,
|
|
3732
3760
|
isProviderAvailable,
|
|
3733
3761
|
prefersReducedMotion,
|