sunpeak 0.4.4 → 0.5.3
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/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 +69 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +69 -40
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.cjs +76 -112
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.d.ts +2 -1
- package/dist/mcp/index.js +76 -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 +6 -7
- package/template/dev/main.tsx +38 -3
- package/template/mcp/server.ts +9 -6
- package/template/nodemon.json +7 -0
- package/template/package.json +4 -2
- package/template/scripts/build-all.mjs +108 -0
- package/template/scripts/validate.mjs +16 -7
- package/template/src/components/index.ts +1 -1
- package/template/src/components/resources/AlbumsResource.tsx +13 -0
- package/template/src/components/{apps/PlacesApp.tsx → resources/CarouselResource.tsx} +11 -10
- package/template/src/components/{apps/App.tsx → resources/CounterResource.tsx} +5 -14
- package/template/src/components/resources/index.ts +3 -0
- package/template/src/index-resource.tsx +11 -0
- package/template/src/simulations/albums-simulation.ts +35 -9
- package/template/src/simulations/carousel-simulation.ts +35 -9
- package/template/src/simulations/counter-simulation.ts +41 -0
- package/template/src/simulations/index.ts +10 -10
- package/template/vite.config.build.ts +21 -15
- package/dist/chatgpt/mcp-provider.d.ts +0 -25
- package/dist/style.css +0 -4420
- package/template/src/components/apps/AlbumsApp.tsx +0 -13
- package/template/src/components/apps/active-app.ts +0 -11
- package/template/src/components/apps/index.ts +0 -3
- package/template/src/index.chatgpt.tsx +0 -9
- package/template/src/index.ts +0 -2
- package/template/src/simulations/app-configs.ts +0 -30
- package/template/src/simulations/app-simulation.ts +0 -15
- package/template/src/simulations/simulations.ts +0 -74
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,7 +3380,7 @@ const SCREEN_WIDTHS = {
|
|
|
3377
3380
|
function Conversation({
|
|
3378
3381
|
children,
|
|
3379
3382
|
screenWidth,
|
|
3380
|
-
appName = "
|
|
3383
|
+
appName = "Sunpeak App",
|
|
3381
3384
|
appIcon,
|
|
3382
3385
|
userMessage = "What have you got for me today?"
|
|
3383
3386
|
}) {
|
|
@@ -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(
|
|
@@ -3709,7 +3741,8 @@ function ChatGPTSimulator({
|
|
|
3709
3741
|
appIcon,
|
|
3710
3742
|
userMessage,
|
|
3711
3743
|
children: content
|
|
3712
|
-
}
|
|
3744
|
+
},
|
|
3745
|
+
selectedKey
|
|
3713
3746
|
)
|
|
3714
3747
|
}
|
|
3715
3748
|
) });
|
|
@@ -3717,17 +3750,13 @@ function ChatGPTSimulator({
|
|
|
3717
3750
|
export {
|
|
3718
3751
|
ChatGPTSimulator,
|
|
3719
3752
|
SCREEN_WIDTHS,
|
|
3720
|
-
SET_GLOBALS_EVENT_TYPE,
|
|
3721
|
-
SetGlobalsEvent,
|
|
3722
3753
|
ThemeProvider,
|
|
3723
3754
|
cn,
|
|
3724
3755
|
getAPI,
|
|
3725
3756
|
getGlobal,
|
|
3726
|
-
getOpenAiProvider,
|
|
3727
3757
|
getProvider,
|
|
3728
3758
|
initMockOpenAI,
|
|
3729
3759
|
isHoverAvailable,
|
|
3730
|
-
isOpenAiAvailable,
|
|
3731
3760
|
isPrimarilyTouchDevice,
|
|
3732
3761
|
isProviderAvailable,
|
|
3733
3762
|
prefersReducedMotion,
|