@creature-ai/sdk 0.1.4 → 0.1.6
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/core/index.d.ts +6 -0
- package/dist/core/index.js +16 -0
- package/dist/core/index.js.map +1 -1
- package/dist/react/index.d.ts +1 -10
- package/dist/react/index.js +24 -42
- package/dist/react/index.js.map +1 -1
- package/dist/server/index.d.ts +11 -0
- package/dist/server/index.js +5 -1
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
package/dist/react/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ToolResult, WidgetState, Environment, DisplayMode, WebSocketStatus } from '../core/index.js';
|
|
2
2
|
export { ChatGptAppHostClient, HostClient, HostClientConfig, HostClientEvents, HostClientState, HostContext, LogLevel, McpAppHostClient, StructuredWidgetState, WebSocketClient, WebSocketClientConfig, createHost, createWebSocket, detectEnvironment } from '../core/index.js';
|
|
3
|
-
import * as react from 'react';
|
|
4
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
4
|
export { applyDocumentTheme, applyHostFonts, applyHostStyleVariables, getDocumentTheme } from '@modelcontextprotocol/ext-apps';
|
|
6
5
|
|
|
@@ -155,14 +154,6 @@ declare function useHost(config: UseHostConfig): UseHostReturn;
|
|
|
155
154
|
*/
|
|
156
155
|
declare function useToolResult<T = Record<string, unknown>>(): UseToolResultReturn<T>;
|
|
157
156
|
|
|
158
|
-
type SetStateAction<T> = T | ((prev: T) => T);
|
|
159
|
-
interface WidgetStateContextValue {
|
|
160
|
-
widgetState: WidgetState | null;
|
|
161
|
-
setWidgetState: (state: WidgetState | null) => void;
|
|
162
|
-
}
|
|
163
|
-
declare const WidgetStateContext: react.Context<WidgetStateContextValue | null>;
|
|
164
|
-
declare function useWidgetState<T extends WidgetState>(initialState?: T | (() => T | null) | null): readonly [T | null, (state: SetStateAction<T | null>) => void];
|
|
165
|
-
|
|
166
157
|
declare function useWebSocket<TSend = unknown, TReceive = unknown>(url: string | undefined, config?: UseWebSocketConfig<TReceive>): UseWebSocketReturn<TSend>;
|
|
167
158
|
|
|
168
159
|
/**
|
|
@@ -174,4 +165,4 @@ declare function useWebSocket<TSend = unknown, TReceive = unknown>(url: string |
|
|
|
174
165
|
*/
|
|
175
166
|
declare function CreatureIcon({ isDarkMode, showEyes, enableBlink, width, height, className, }: CreatureIconProps): react_jsx_runtime.JSX.Element;
|
|
176
167
|
|
|
177
|
-
export { CreatureIcon, type CreatureIconProps, DisplayMode, Environment, type Logger, ToolResult, type UseHostConfig, type UseHostReturn, type UseToolResultReturn, type UseWebSocketConfig, type UseWebSocketReturn, WebSocketStatus, WidgetState,
|
|
168
|
+
export { CreatureIcon, type CreatureIconProps, DisplayMode, Environment, type Logger, ToolResult, type UseHostConfig, type UseHostReturn, type UseToolResultReturn, type UseWebSocketConfig, type UseWebSocketReturn, WebSocketStatus, WidgetState, useHost, useToolResult, useWebSocket };
|
package/dist/react/index.js
CHANGED
|
@@ -9562,6 +9562,7 @@ var McpAppHostClient = class extends Subscribable {
|
|
|
9562
9562
|
}
|
|
9563
9563
|
/**
|
|
9564
9564
|
* Apply theme, styles, and fonts from host context.
|
|
9565
|
+
* Also applies Creature-specific extension styles if present.
|
|
9565
9566
|
*/
|
|
9566
9567
|
applyHostContext(context) {
|
|
9567
9568
|
if (context.theme) {
|
|
@@ -9574,6 +9575,21 @@ var McpAppHostClient = class extends Subscribable {
|
|
|
9574
9575
|
if (context.styles?.css?.fonts) {
|
|
9575
9576
|
qU(context.styles.css.fonts);
|
|
9576
9577
|
}
|
|
9578
|
+
if (context.creatureStyles) {
|
|
9579
|
+
this.applyCreatureStyles(context.creatureStyles);
|
|
9580
|
+
}
|
|
9581
|
+
}
|
|
9582
|
+
/**
|
|
9583
|
+
* Apply Creature-specific CSS variables to the document root.
|
|
9584
|
+
* These are host extensions sent outside the spec-validated styles.variables path.
|
|
9585
|
+
*/
|
|
9586
|
+
applyCreatureStyles(styles) {
|
|
9587
|
+
const root = document.documentElement;
|
|
9588
|
+
for (const [key, value] of Object.entries(styles)) {
|
|
9589
|
+
if (value !== void 0) {
|
|
9590
|
+
root.style.setProperty(key, value);
|
|
9591
|
+
}
|
|
9592
|
+
}
|
|
9577
9593
|
}
|
|
9578
9594
|
/**
|
|
9579
9595
|
* Extract text content from SDK result content array.
|
|
@@ -10034,40 +10050,8 @@ function useToolResult() {
|
|
|
10034
10050
|
};
|
|
10035
10051
|
}
|
|
10036
10052
|
|
|
10037
|
-
// src/react/useWidgetState.ts
|
|
10038
|
-
import { useState as useState2, useCallback as useCallback2, useEffect as useEffect2, createContext, useContext } from "react";
|
|
10039
|
-
var WidgetStateContext = createContext(null);
|
|
10040
|
-
function useWidgetState(initialState) {
|
|
10041
|
-
const context = useContext(WidgetStateContext);
|
|
10042
|
-
const getInitialState = () => {
|
|
10043
|
-
if (context?.widgetState) {
|
|
10044
|
-
return context.widgetState;
|
|
10045
|
-
}
|
|
10046
|
-
if (typeof initialState === "function") {
|
|
10047
|
-
return initialState();
|
|
10048
|
-
}
|
|
10049
|
-
return initialState ?? null;
|
|
10050
|
-
};
|
|
10051
|
-
const [localState, setLocalState] = useState2(getInitialState);
|
|
10052
|
-
useEffect2(() => {
|
|
10053
|
-
if (context?.widgetState !== void 0) {
|
|
10054
|
-
setLocalState(context.widgetState);
|
|
10055
|
-
}
|
|
10056
|
-
}, [context?.widgetState]);
|
|
10057
|
-
const setState = useCallback2((action) => {
|
|
10058
|
-
setLocalState((prev) => {
|
|
10059
|
-
const newState = typeof action === "function" ? action(prev) : action;
|
|
10060
|
-
if (context?.setWidgetState) {
|
|
10061
|
-
context.setWidgetState(newState);
|
|
10062
|
-
}
|
|
10063
|
-
return newState;
|
|
10064
|
-
});
|
|
10065
|
-
}, [context]);
|
|
10066
|
-
return [localState, setState];
|
|
10067
|
-
}
|
|
10068
|
-
|
|
10069
10053
|
// src/react/useWebSocket.ts
|
|
10070
|
-
import { useEffect as
|
|
10054
|
+
import { useEffect as useEffect2, useRef as useRef2, useMemo as useMemo2, useCallback as useCallback2, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
10071
10055
|
function useWebSocket(url, config = {}) {
|
|
10072
10056
|
const { onMessage, enabled = true } = config;
|
|
10073
10057
|
const onMessageRef = useRef2(onMessage);
|
|
@@ -10075,15 +10059,15 @@ function useWebSocket(url, config = {}) {
|
|
|
10075
10059
|
const stateRef = useRef2({ status: "disconnected", error: void 0 });
|
|
10076
10060
|
const listenersRef = useRef2(/* @__PURE__ */ new Set());
|
|
10077
10061
|
const clientRef = useRef2(null);
|
|
10078
|
-
const subscribe =
|
|
10062
|
+
const subscribe = useCallback2((listener) => {
|
|
10079
10063
|
listenersRef.current.add(listener);
|
|
10080
10064
|
return () => {
|
|
10081
10065
|
listenersRef.current.delete(listener);
|
|
10082
10066
|
};
|
|
10083
10067
|
}, []);
|
|
10084
|
-
const getSnapshot =
|
|
10068
|
+
const getSnapshot = useCallback2(() => stateRef.current, []);
|
|
10085
10069
|
const state = useSyncExternalStore2(subscribe, getSnapshot, getSnapshot);
|
|
10086
|
-
|
|
10070
|
+
useEffect2(() => {
|
|
10087
10071
|
if (!url || !enabled) {
|
|
10088
10072
|
if (clientRef.current) {
|
|
10089
10073
|
clientRef.current.disconnect();
|
|
@@ -10120,7 +10104,7 @@ function useWebSocket(url, config = {}) {
|
|
|
10120
10104
|
}
|
|
10121
10105
|
|
|
10122
10106
|
// src/react/CreatureIcon.tsx
|
|
10123
|
-
import { useState as
|
|
10107
|
+
import { useState as useState2, useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
10124
10108
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10125
10109
|
function CreatureIcon({
|
|
10126
10110
|
isDarkMode,
|
|
@@ -10131,9 +10115,9 @@ function CreatureIcon({
|
|
|
10131
10115
|
className = ""
|
|
10132
10116
|
}) {
|
|
10133
10117
|
const fillColor = isDarkMode ? "#F8F7F6" : "#0D0D0C";
|
|
10134
|
-
const [isBlinking, setIsBlinking] =
|
|
10118
|
+
const [isBlinking, setIsBlinking] = useState2(false);
|
|
10135
10119
|
const timeoutRef = useRef3(null);
|
|
10136
|
-
|
|
10120
|
+
useEffect3(() => {
|
|
10137
10121
|
if (!enableBlink || !showEyes) {
|
|
10138
10122
|
return;
|
|
10139
10123
|
}
|
|
@@ -10217,7 +10201,6 @@ export {
|
|
|
10217
10201
|
ChatGptAppHostClient,
|
|
10218
10202
|
CreatureIcon,
|
|
10219
10203
|
McpAppHostClient,
|
|
10220
|
-
WidgetStateContext,
|
|
10221
10204
|
YU as applyDocumentTheme,
|
|
10222
10205
|
qU as applyHostFonts,
|
|
10223
10206
|
QU as applyHostStyleVariables,
|
|
@@ -10227,7 +10210,6 @@ export {
|
|
|
10227
10210
|
VU as getDocumentTheme,
|
|
10228
10211
|
useHost,
|
|
10229
10212
|
useToolResult,
|
|
10230
|
-
useWebSocket
|
|
10231
|
-
useWidgetState
|
|
10213
|
+
useWebSocket
|
|
10232
10214
|
};
|
|
10233
10215
|
//# sourceMappingURL=index.js.map
|