@creature-ai/sdk 0.1.1 → 0.1.2

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.
@@ -1,8 +1,9 @@
1
1
  import { ChannelStatus, AppSession } from '../core/index.js';
2
2
  export { ChannelClient, ChannelClientConfig, ChatGPTHostClient, McpHostClient, createChannel, createHost, detectEnvironment } from '../core/index.js';
3
- import { T as ToolResult, W as WidgetState, E as Environment, H as HostClient, a as AppSessionState } from '../types-DcoqlK46.js';
4
- export { b as AppSessionListener, A as AppSessionOptions, d as HostClientConfig, f as HostClientEvents, e as HostClientState, c as HostContext, L as LogLevel, S as StructuredWidgetState } from '../types-DcoqlK46.js';
3
+ import { T as ToolResult, W as WidgetState, E as Environment, D as DisplayMode, H as HostClient, a as AppSessionState } from '../types-JBEuUzEi.js';
4
+ export { b as AppSessionListener, A as AppSessionOptions, d as HostClientConfig, f as HostClientEvents, e as HostClientState, c as HostContext, L as LogLevel, S as StructuredWidgetState } from '../types-JBEuUzEi.js';
5
5
  import * as react from 'react';
6
+ import * as react_jsx_runtime from 'react/jsx-runtime';
6
7
  export { applyDocumentTheme, applyHostFonts, applyHostStyleVariables, getDocumentTheme } from '@modelcontextprotocol/ext-apps';
7
8
 
8
9
  interface UseHostConfig {
@@ -56,6 +57,11 @@ interface UseHostReturn {
56
57
  environment: Environment;
57
58
  widgetState: WidgetState | null;
58
59
  setWidgetState: (state: WidgetState | null) => void;
60
+ requestDisplayMode: (params: {
61
+ mode: DisplayMode;
62
+ }) => Promise<{
63
+ mode: DisplayMode;
64
+ }>;
59
65
  /**
60
66
  * Logger for sending messages to the host's DevConsole.
61
67
  *
@@ -149,4 +155,27 @@ interface UseAppSessionReturn<TInternal extends Record<string, unknown> = Record
149
155
  }
150
156
  declare function useAppSession<TInternal extends Record<string, unknown> = Record<string, unknown>, TBackend extends Record<string, unknown> = Record<string, unknown>, TUi extends WidgetState | null = WidgetState | null>(config?: UseAppSessionConfig<TInternal, TBackend, TUi>): UseAppSessionReturn<TInternal, TBackend, TUi>;
151
157
 
152
- export { AppSession, AppSessionState, ChannelStatus, Environment, HostClient, type Logger, ToolResult, type UseAppSessionConfig, type UseAppSessionReturn, type UseChannelConfig, type UseChannelReturn, type UseHostConfig, type UseHostReturn, type UseToolResultReturn, WidgetState, WidgetStateContext, useAppSession, useChannel, useHost, useToolResult, useWidgetState };
158
+ /**
159
+ * CreatureIcon Component
160
+ *
161
+ * The Creature mascot icon with theme-aware colors.
162
+ * Uses the main creature shape with optional eyes, adapting colors for dark/light mode.
163
+ * Supports optional eye blinking animation at random intervals.
164
+ */
165
+ interface CreatureIconProps {
166
+ /** Whether the app is in dark mode */
167
+ isDarkMode: boolean;
168
+ /** Whether to show the eyes (default: true) */
169
+ showEyes?: boolean;
170
+ /** Whether to enable eye blinking animation (default: false) */
171
+ enableBlink?: boolean;
172
+ /** Width of the icon in pixels */
173
+ width?: number;
174
+ /** Height of the icon in pixels */
175
+ height?: number;
176
+ /** Optional className for additional styling */
177
+ className?: string;
178
+ }
179
+ declare function CreatureIcon({ isDarkMode, showEyes, enableBlink, width, height, className, }: CreatureIconProps): react_jsx_runtime.JSX.Element;
180
+
181
+ export { AppSession, AppSessionState, ChannelStatus, CreatureIcon, type CreatureIconProps, DisplayMode, Environment, HostClient, type Logger, ToolResult, type UseAppSessionConfig, type UseAppSessionReturn, type UseChannelConfig, type UseChannelReturn, type UseHostConfig, type UseHostReturn, type UseToolResultReturn, WidgetState, WidgetStateContext, useAppSession, useChannel, useHost, useToolResult, useWidgetState };
@@ -9530,6 +9530,13 @@ var McpHostClient = class extends Subscribable {
9530
9530
  widgetState: state
9531
9531
  });
9532
9532
  }
9533
+ async requestDisplayMode(params) {
9534
+ if (!this.app) {
9535
+ return { mode: params.mode };
9536
+ }
9537
+ const result = await this.app.requestDisplayMode({ mode: params.mode });
9538
+ return { mode: result.mode };
9539
+ }
9533
9540
  /**
9534
9541
  * Send a log message to the host's DevConsole.
9535
9542
  *
@@ -9667,6 +9674,14 @@ var ChatGPTHostClient = class extends Subscribable {
9667
9674
  const consoleMethod = level === "error" ? "error" : level === "warning" ? "warn" : "log";
9668
9675
  console[consoleMethod](`[${this.config.name}]`, message, data ?? "");
9669
9676
  }
9677
+ async requestDisplayMode(params) {
9678
+ const openai = window.openai;
9679
+ if (openai?.requestDisplayMode) {
9680
+ const result = await openai.requestDisplayMode({ mode: params.mode });
9681
+ return { mode: result.mode };
9682
+ }
9683
+ return { mode: params.mode };
9684
+ }
9670
9685
  };
9671
9686
 
9672
9687
  // src/core/utils.ts
@@ -9943,7 +9958,8 @@ function useHost(config) {
9943
9958
  () => ({
9944
9959
  callTool: client.callTool.bind(client),
9945
9960
  sendNotification: client.sendNotification.bind(client),
9946
- setWidgetState: client.setWidgetState.bind(client)
9961
+ setWidgetState: client.setWidgetState.bind(client),
9962
+ requestDisplayMode: client.requestDisplayMode.bind(client)
9947
9963
  }),
9948
9964
  [client]
9949
9965
  );
@@ -10001,6 +10017,7 @@ function useHost(config) {
10001
10017
  callTool: boundMethods.callTool,
10002
10018
  sendNotification: boundMethods.sendNotification,
10003
10019
  setWidgetState: boundMethods.setWidgetState,
10020
+ requestDisplayMode: boundMethods.requestDisplayMode,
10004
10021
  log
10005
10022
  };
10006
10023
  }
@@ -10161,9 +10178,105 @@ function useAppSession(config = {}) {
10161
10178
  updateUi
10162
10179
  };
10163
10180
  }
10181
+
10182
+ // src/react/CreatureIcon.tsx
10183
+ import { useState as useState3, useEffect as useEffect5, useRef as useRef4 } from "react";
10184
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10185
+ function CreatureIcon({
10186
+ isDarkMode,
10187
+ showEyes = true,
10188
+ enableBlink = false,
10189
+ width = 26,
10190
+ height = 26,
10191
+ className = ""
10192
+ }) {
10193
+ const fillColor = isDarkMode ? "#F8F7F6" : "#0D0D0C";
10194
+ const [isBlinking, setIsBlinking] = useState3(false);
10195
+ const timeoutRef = useRef4(null);
10196
+ useEffect5(() => {
10197
+ if (!enableBlink || !showEyes) {
10198
+ return;
10199
+ }
10200
+ const scheduleNextBlink = () => {
10201
+ const nextBlinkDelay = Math.random() * 4e3 + 2e3;
10202
+ timeoutRef.current = setTimeout(() => {
10203
+ setIsBlinking(true);
10204
+ setTimeout(() => {
10205
+ setIsBlinking(false);
10206
+ scheduleNextBlink();
10207
+ }, 150);
10208
+ }, nextBlinkDelay);
10209
+ };
10210
+ scheduleNextBlink();
10211
+ return () => {
10212
+ if (timeoutRef.current) {
10213
+ clearTimeout(timeoutRef.current);
10214
+ }
10215
+ };
10216
+ }, [enableBlink, showEyes]);
10217
+ return /* @__PURE__ */ jsxs(
10218
+ "svg",
10219
+ {
10220
+ width,
10221
+ height,
10222
+ viewBox: "0 0 110 111",
10223
+ fill: "none",
10224
+ xmlns: "http://www.w3.org/2000/svg",
10225
+ className,
10226
+ children: [
10227
+ /* @__PURE__ */ jsx(
10228
+ "path",
10229
+ {
10230
+ fillRule: "evenodd",
10231
+ clipRule: "evenodd",
10232
+ d: "M76.7407 18.0698L69.6709 0L47.7099 28.6693L11.7829 31.4596L8.12513 55.4302L15.3684 62.8469L21.6574 63.9457L0 88.9139C11.8118 94.2343 23.6381 99.5546 35.4499 104.861L54.2013 93.3813L62.7746 105.265L71.5215 110.889L87.5115 105.439L85.0537 85.1115L100.971 91.1693L109.053 74.5286L106.812 62.0084L94.7692 52.4953L101.608 26.3995L98.0532 1.81982L78.3892 18.2808L76.7407 18.0698ZM76.5816 94.1909L71.2034 65.0011L95.6366 73.5166L101.318 63.1072L80.9622 47.0159C84.5477 35.4354 88.191 23.826 91.5452 12.1877L77.1744 24.5698L69.6709 23.4566L68.3264 8.84802L49.9797 32.7897L15.5563 35.4643L13.113 51.4544L36.621 53.2616L7.08419 87.338L24.6212 95.2318L48.1147 77.5069L64.2348 99.8582L76.6105 94.1764L76.5816 94.1909Z",
10233
+ fill: fillColor
10234
+ }
10235
+ ),
10236
+ showEyes && /* @__PURE__ */ jsxs(Fragment, { children: [
10237
+ /* @__PURE__ */ jsx(
10238
+ "g",
10239
+ {
10240
+ style: {
10241
+ transformOrigin: "64px 33.65px",
10242
+ transform: isBlinking ? "scaleY(0.1)" : "scaleY(1)",
10243
+ transition: "transform 0.1s ease-out"
10244
+ },
10245
+ children: /* @__PURE__ */ jsx(
10246
+ "path",
10247
+ {
10248
+ d: "M65.6051 34.48C66.4951 32.97 66.6051 31.3799 65.8451 30.9299C65.0851 30.4899 63.7451 31.3499 62.8551 32.8699C61.9651 34.3799 61.8551 35.97 62.6151 36.42C63.3751 36.86 64.7151 36 65.6051 34.48Z",
10249
+ fill: fillColor
10250
+ }
10251
+ )
10252
+ }
10253
+ ),
10254
+ /* @__PURE__ */ jsx(
10255
+ "g",
10256
+ {
10257
+ style: {
10258
+ transformOrigin: "70px 36.265px",
10259
+ transform: isBlinking ? "scaleY(0.1)" : "scaleY(1)",
10260
+ transition: "transform 0.1s ease-out"
10261
+ },
10262
+ children: /* @__PURE__ */ jsx(
10263
+ "path",
10264
+ {
10265
+ d: "M71.7651 37.0999C72.6951 35.1499 72.6551 33.1899 71.6751 32.73C70.6951 32.27 69.1551 33.4799 68.2351 35.4299C67.3051 37.3799 67.3451 39.3399 68.3251 39.7999C69.3051 40.2599 70.8451 39.0499 71.7651 37.0999Z",
10266
+ fill: fillColor
10267
+ }
10268
+ )
10269
+ }
10270
+ )
10271
+ ] })
10272
+ ]
10273
+ }
10274
+ );
10275
+ }
10164
10276
  export {
10165
10277
  AppSession,
10166
10278
  ChatGPTHostClient,
10279
+ CreatureIcon,
10167
10280
  McpHostClient,
10168
10281
  WidgetStateContext,
10169
10282
  YU as applyDocumentTheme,