@creature-ai/sdk 0.1.18 → 0.1.19

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.
@@ -464,6 +464,9 @@ declare function detectEnvironment(): Environment;
464
464
  * 2. Detect theme (light or dark)
465
465
  * 3. Inject defaults immediately on document.documentElement
466
466
  * 4. When host connects, host variables override these defaults
467
+ *
468
+ * IMPORTANT: MCP Apps defaults match Creature's actual values exactly.
469
+ * The observer only runs for ChatGPT (MCP Apps hosts handle theme changes themselves).
467
470
  */
468
471
 
469
472
  /**
@@ -474,20 +477,23 @@ type Theme = "light" | "dark";
474
477
  * Options for initializing styles.
475
478
  */
476
479
  interface InitStylesOptions {
477
- /** Whether to set up a MutationObserver for dynamic theme changes. Default: true */
480
+ /** Whether to set up a MutationObserver for dynamic theme changes. Default: true for ChatGPT only */
478
481
  observeThemeChanges?: boolean;
479
482
  }
480
- /**
481
- * MCP Apps / Creature default values - LIGHT mode.
482
- * Host will override these with actual values via hostContext.styles.variables.
483
- */
484
- declare const MCP_APPS_LIGHT_DEFAULTS: Record<string, string>;
485
483
  /**
486
484
  * MCP Apps / Creature default values - DARK mode.
485
+ * These values are extracted directly from Creature's globals.css.
486
+ * They MUST match exactly what Creature sends via hostContext.styles.variables.
487
487
  */
488
488
  declare const MCP_APPS_DARK_DEFAULTS: Record<string, string>;
489
489
  /**
490
- * Shared MCP Apps typography and layout tokens (same for light/dark).
490
+ * MCP Apps / Creature default values - LIGHT mode.
491
+ * These values are extracted directly from Creature's globals.css.
492
+ */
493
+ declare const MCP_APPS_LIGHT_DEFAULTS: Record<string, string>;
494
+ /**
495
+ * Shared MCP Apps / Creature typography and layout tokens (same for light/dark).
496
+ * These values are extracted directly from Creature's globals.css.
491
497
  */
492
498
  declare const MCP_APPS_SHARED_DEFAULTS: Record<string, string>;
493
499
  /**
@@ -506,6 +512,7 @@ declare const CHATGPT_SHARED_DEFAULTS: Record<string, string>;
506
512
  /**
507
513
  * Get MCP Apps default styles for the specified theme.
508
514
  * Returns CSS variable names with their default values.
515
+ * These values match exactly what Creature sends via hostContext.styles.variables.
509
516
  *
510
517
  * @param theme - The theme to get defaults for
511
518
  * @returns Record of CSS variable names to their values
@@ -542,6 +549,12 @@ declare const applyStyles: ({ styles }: {
542
549
  * Initialize default styles based on detected environment and theme.
543
550
  * This should be called early in your app entry point to prevent FOUC.
544
551
  *
552
+ * For MCP Apps (Creature): Applies defaults once. The host handles theme changes
553
+ * and sends new styles via hostContext, which override these defaults.
554
+ *
555
+ * For ChatGPT: Applies defaults and sets up an observer to handle theme changes,
556
+ * since ChatGPT may change theme before sending new hostContext.
557
+ *
545
558
  * @param environment - The detected environment (from detectEnvironment)
546
559
  * @param options - Configuration options
547
560
  */
@@ -9796,124 +9796,146 @@ function detectEnvironment() {
9796
9796
  }
9797
9797
 
9798
9798
  // src/core/styles.ts
9799
- var MCP_APPS_LIGHT_DEFAULTS = {
9800
- "--color-background-primary": "#ffffff",
9801
- "--color-background-secondary": "#f8f9fa",
9802
- "--color-background-tertiary": "#f1f3f5",
9803
- "--color-background-inverse": "#1a1a1a",
9804
- "--color-background-ghost": "rgba(0, 0, 0, 0.04)",
9805
- "--color-background-info": "#e7f5ff",
9806
- "--color-background-danger": "#fff5f5",
9807
- "--color-background-success": "#ebfbee",
9808
- "--color-background-warning": "#fff9db",
9809
- "--color-background-disabled": "#e9ecef",
9810
- "--color-text-primary": "#212529",
9811
- "--color-text-secondary": "#495057",
9812
- "--color-text-tertiary": "#868e96",
9813
- "--color-text-inverse": "#ffffff",
9814
- "--color-text-ghost": "rgba(0, 0, 0, 0.4)",
9815
- "--color-text-info": "#1971c2",
9816
- "--color-text-danger": "#c92a2a",
9817
- "--color-text-success": "#2f9e44",
9818
- "--color-text-warning": "#e67700",
9819
- "--color-text-disabled": "#adb5bd",
9820
- "--color-border-primary": "#dee2e6",
9821
- "--color-border-secondary": "#e9ecef",
9822
- "--color-border-tertiary": "#f1f3f5",
9823
- "--color-border-inverse": "#343a40",
9824
- "--color-border-ghost": "rgba(0, 0, 0, 0.08)",
9825
- "--color-border-info": "#74c0fc",
9826
- "--color-border-danger": "#ffa8a8",
9827
- "--color-border-success": "#8ce99a",
9828
- "--color-border-warning": "#ffe066",
9829
- "--color-border-disabled": "#ced4da",
9830
- "--color-ring-primary": "#228be6",
9831
- "--color-ring-secondary": "#495057",
9832
- "--color-ring-inverse": "#ffffff",
9833
- "--color-ring-info": "#228be6",
9834
- "--color-ring-danger": "#fa5252",
9835
- "--color-ring-success": "#40c057",
9836
- "--color-ring-warning": "#fab005"
9837
- };
9838
9799
  var MCP_APPS_DARK_DEFAULTS = {
9839
- "--color-background-primary": "#1a1a1a",
9840
- "--color-background-secondary": "#252525",
9841
- "--color-background-tertiary": "#2f2f2f",
9842
- "--color-background-inverse": "#ffffff",
9843
- "--color-background-ghost": "rgba(255, 255, 255, 0.04)",
9844
- "--color-background-info": "#1a3a4a",
9845
- "--color-background-danger": "#4a1a1a",
9846
- "--color-background-success": "#1a3a1a",
9847
- "--color-background-warning": "#4a3a1a",
9848
- "--color-background-disabled": "#2a2a2a",
9849
- "--color-text-primary": "#e9ecef",
9850
- "--color-text-secondary": "#adb5bd",
9851
- "--color-text-tertiary": "#868e96",
9852
- "--color-text-inverse": "#1a1a1a",
9853
- "--color-text-ghost": "rgba(255, 255, 255, 0.4)",
9854
- "--color-text-info": "#74c0fc",
9855
- "--color-text-danger": "#ffa8a8",
9856
- "--color-text-success": "#8ce99a",
9857
- "--color-text-warning": "#ffe066",
9858
- "--color-text-disabled": "#495057",
9859
- "--color-border-primary": "#343a40",
9860
- "--color-border-secondary": "#2f2f2f",
9861
- "--color-border-tertiary": "#252525",
9862
- "--color-border-inverse": "#dee2e6",
9863
- "--color-border-ghost": "rgba(255, 255, 255, 0.08)",
9864
- "--color-border-info": "#1971c2",
9865
- "--color-border-danger": "#c92a2a",
9866
- "--color-border-success": "#2f9e44",
9867
- "--color-border-warning": "#e67700",
9868
- "--color-border-disabled": "#3a3a3a",
9869
- "--color-ring-primary": "#4dabf7",
9870
- "--color-ring-secondary": "#adb5bd",
9871
- "--color-ring-inverse": "#1a1a1a",
9872
- "--color-ring-info": "#4dabf7",
9873
- "--color-ring-danger": "#ff8787",
9874
- "--color-ring-success": "#69db7c",
9875
- "--color-ring-warning": "#ffd43b"
9800
+ // Background colors
9801
+ "--color-background-primary": "#0D0D0B",
9802
+ "--color-background-secondary": "#1A1917",
9803
+ "--color-background-tertiary": "#141311",
9804
+ "--color-background-inverse": "#efefef",
9805
+ "--color-background-ghost": "transparent",
9806
+ "--color-background-info": "#1e3a5f",
9807
+ "--color-background-danger": "#5f1e1e",
9808
+ "--color-background-success": "#1e5f2e",
9809
+ "--color-background-warning": "#5f4a1e",
9810
+ "--color-background-disabled": "#1A1917",
9811
+ // Text colors
9812
+ "--color-text-primary": "#efefef",
9813
+ "--color-text-secondary": "#888888",
9814
+ "--color-text-tertiary": "#4A4846",
9815
+ "--color-text-inverse": "#0D0D0B",
9816
+ "--color-text-ghost": "#3A3836",
9817
+ "--color-text-info": "#58a6ff",
9818
+ "--color-text-danger": "#F85149",
9819
+ "--color-text-success": "#3fb950",
9820
+ "--color-text-warning": "#d29922",
9821
+ "--color-text-disabled": "#4A4846",
9822
+ // Border colors
9823
+ "--color-border-primary": "#4A4846",
9824
+ "--color-border-secondary": "#242222",
9825
+ "--color-border-tertiary": "#1A1917",
9826
+ "--color-border-inverse": "#ABABAB",
9827
+ "--color-border-ghost": "transparent",
9828
+ "--color-border-info": "#58a6ff",
9829
+ "--color-border-danger": "#F85149",
9830
+ "--color-border-success": "#3fb950",
9831
+ "--color-border-warning": "#d29922",
9832
+ "--color-border-disabled": "#242222",
9833
+ // Ring/focus colors
9834
+ "--color-ring-primary": "#cdcdcd",
9835
+ "--color-ring-secondary": "#666666",
9836
+ "--color-ring-inverse": "#0D0D0B",
9837
+ "--color-ring-info": "#58a6ff",
9838
+ "--color-ring-danger": "#F85149",
9839
+ "--color-ring-success": "#3fb950",
9840
+ "--color-ring-warning": "#d29922",
9841
+ // Shadows (dark mode)
9842
+ "--shadow-hairline": "0 0 0 1px rgba(0, 0, 0, 0.1)",
9843
+ "--shadow-sm": "0 1px 2px 0 rgba(0, 0, 0, 0.3)",
9844
+ "--shadow-md": "0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.3)",
9845
+ "--shadow-lg": "0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -4px rgba(0, 0, 0, 0.3)"
9846
+ };
9847
+ var MCP_APPS_LIGHT_DEFAULTS = {
9848
+ // Background colors
9849
+ "--color-background-primary": "#f2f2f2",
9850
+ "--color-background-secondary": "#e8e8e8",
9851
+ "--color-background-tertiary": "#eaeaea",
9852
+ "--color-background-inverse": "#1F1E1D",
9853
+ "--color-background-ghost": "transparent",
9854
+ "--color-background-info": "#dbeafe",
9855
+ "--color-background-danger": "#fee2e2",
9856
+ "--color-background-success": "#dcfce7",
9857
+ "--color-background-warning": "#fef3c7",
9858
+ "--color-background-disabled": "#e8e8e8",
9859
+ // Text colors
9860
+ "--color-text-primary": "#1F1E1D",
9861
+ "--color-text-secondary": "#6B6A68",
9862
+ "--color-text-tertiary": "#9A9998",
9863
+ "--color-text-inverse": "#F8F7F6",
9864
+ "--color-text-ghost": "#B8B7B5",
9865
+ "--color-text-info": "#0366d6",
9866
+ "--color-text-danger": "#DC2626",
9867
+ "--color-text-success": "#22863a",
9868
+ "--color-text-warning": "#b08800",
9869
+ "--color-text-disabled": "#9A9998",
9870
+ // Border colors
9871
+ "--color-border-primary": "#b8b8b8",
9872
+ "--color-border-secondary": "#d8d8d8",
9873
+ "--color-border-tertiary": "#e8e8e8",
9874
+ "--color-border-inverse": "#1F1E1D",
9875
+ "--color-border-ghost": "transparent",
9876
+ "--color-border-info": "#0366d6",
9877
+ "--color-border-danger": "#DC2626",
9878
+ "--color-border-success": "#22863a",
9879
+ "--color-border-warning": "#b08800",
9880
+ "--color-border-disabled": "#d8d8d8",
9881
+ // Ring/focus colors
9882
+ "--color-ring-primary": "#666666",
9883
+ "--color-ring-secondary": "#AAAAAA",
9884
+ "--color-ring-inverse": "#F8F7F6",
9885
+ "--color-ring-info": "#0366d6",
9886
+ "--color-ring-danger": "#DC2626",
9887
+ "--color-ring-success": "#22863a",
9888
+ "--color-ring-warning": "#b08800",
9889
+ // Shadows (light mode)
9890
+ "--shadow-hairline": "0 0 0 1px rgba(0, 0, 0, 0.05)",
9891
+ "--shadow-sm": "0 1px 2px 0 rgba(0, 0, 0, 0.1)",
9892
+ "--shadow-md": "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)",
9893
+ "--shadow-lg": "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)"
9876
9894
  };
9877
9895
  var MCP_APPS_SHARED_DEFAULTS = {
9878
- "--font-sans": '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
9879
- "--font-mono": 'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace',
9896
+ // Typography - font families
9897
+ "--font-sans": '"Sora", system-ui, sans-serif',
9898
+ "--font-mono": '"SF Mono", Monaco, Consolas, "Liberation Mono", monospace',
9899
+ // Typography - font weights
9880
9900
  "--font-weight-normal": "400",
9881
9901
  "--font-weight-medium": "500",
9882
9902
  "--font-weight-semibold": "600",
9883
9903
  "--font-weight-bold": "700",
9884
- "--font-text-xs-size": "0.75rem",
9904
+ // Typography - text sizes
9905
+ "--font-text-xs-size": "0.6875rem",
9906
+ "--font-text-sm-size": "0.75rem",
9907
+ "--font-text-md-size": "0.875rem",
9908
+ "--font-text-lg-size": "1rem",
9909
+ // Typography - text line heights
9885
9910
  "--font-text-xs-line-height": "1rem",
9886
- "--font-text-sm-size": "0.875rem",
9887
9911
  "--font-text-sm-line-height": "1.25rem",
9888
- "--font-text-md-size": "1rem",
9889
9912
  "--font-text-md-line-height": "1.5rem",
9890
- "--font-text-lg-size": "1.125rem",
9891
9913
  "--font-text-lg-line-height": "1.75rem",
9914
+ // Typography - heading sizes
9892
9915
  "--font-heading-xs-size": "0.875rem",
9893
- "--font-heading-xs-line-height": "1.25rem",
9894
9916
  "--font-heading-sm-size": "1rem",
9895
- "--font-heading-sm-line-height": "1.5rem",
9896
9917
  "--font-heading-md-size": "1.125rem",
9897
- "--font-heading-md-line-height": "1.75rem",
9898
9918
  "--font-heading-lg-size": "1.25rem",
9899
- "--font-heading-lg-line-height": "1.75rem",
9900
9919
  "--font-heading-xl-size": "1.5rem",
9901
- "--font-heading-xl-line-height": "2rem",
9902
9920
  "--font-heading-2xl-size": "1.875rem",
9903
- "--font-heading-2xl-line-height": "2.25rem",
9904
9921
  "--font-heading-3xl-size": "2.25rem",
9905
- "--font-heading-3xl-line-height": "2.5rem",
9906
- "--border-radius-xs": "2px",
9907
- "--border-radius-sm": "4px",
9908
- "--border-radius-md": "6px",
9909
- "--border-radius-lg": "8px",
9910
- "--border-radius-xl": "12px",
9922
+ // Typography - heading line heights
9923
+ "--font-heading-xs-line-height": "1.25rem",
9924
+ "--font-heading-sm-line-height": "1.5rem",
9925
+ "--font-heading-md-line-height": "1.75rem",
9926
+ "--font-heading-lg-line-height": "2rem",
9927
+ "--font-heading-xl-line-height": "2.25rem",
9928
+ "--font-heading-2xl-line-height": "2.5rem",
9929
+ "--font-heading-3xl-line-height": "2.75rem",
9930
+ // Border radius
9931
+ "--border-radius-xs": "0.125rem",
9932
+ "--border-radius-sm": "0.25rem",
9933
+ "--border-radius-md": "0.375rem",
9934
+ "--border-radius-lg": "0.5rem",
9935
+ "--border-radius-xl": "0.75rem",
9911
9936
  "--border-radius-full": "9999px",
9912
- "--border-width-regular": "1px",
9913
- "--shadow-hairline": "0 0 0 1px rgba(0, 0, 0, 0.05)",
9914
- "--shadow-sm": "0 1px 2px rgba(0, 0, 0, 0.05)",
9915
- "--shadow-md": "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)",
9916
- "--shadow-lg": "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)"
9937
+ // Border width
9938
+ "--border-width-regular": "1px"
9917
9939
  };
9918
9940
  var CHATGPT_LIGHT_DEFAULTS = {
9919
9941
  "--color-background-primary": "#ffffff",
@@ -10044,20 +10066,23 @@ var getChatGptDefaultStyles = ({ theme }) => {
10044
10066
  };
10045
10067
  var detectTheme = () => {
10046
10068
  if (typeof document === "undefined") {
10047
- return "light";
10069
+ return "dark";
10048
10070
  }
10049
10071
  const root = document.documentElement;
10050
10072
  const dataTheme = root.getAttribute("data-theme");
10051
10073
  if (dataTheme === "dark" || dataTheme === "light") {
10052
10074
  return dataTheme;
10053
10075
  }
10076
+ if (root.classList.contains("light")) {
10077
+ return "light";
10078
+ }
10054
10079
  if (root.classList.contains("dark")) {
10055
10080
  return "dark";
10056
10081
  }
10057
10082
  if (typeof window !== "undefined" && window.matchMedia?.("(prefers-color-scheme: dark)").matches) {
10058
10083
  return "dark";
10059
10084
  }
10060
- return "light";
10085
+ return "dark";
10061
10086
  };
10062
10087
  var applyStyles = ({ styles }) => {
10063
10088
  if (typeof document === "undefined") {
@@ -10075,12 +10100,12 @@ var initStyles = ({
10075
10100
  if (typeof document === "undefined") {
10076
10101
  return;
10077
10102
  }
10078
- const { observeThemeChanges = true } = options;
10079
10103
  const theme = detectTheme();
10080
10104
  const defaults = environment === "chatgpt" ? getChatGptDefaultStyles({ theme }) : getMcpAppDefaultStyles({ theme });
10081
10105
  applyStyles({ styles: defaults });
10082
10106
  document.documentElement.setAttribute("data-env", environment);
10083
- if (observeThemeChanges) {
10107
+ const shouldObserve = options.observeThemeChanges ?? environment === "chatgpt";
10108
+ if (shouldObserve && environment === "chatgpt") {
10084
10109
  setupThemeObserver({ environment });
10085
10110
  }
10086
10111
  };
@@ -10088,13 +10113,15 @@ var setupThemeObserver = ({ environment }) => {
10088
10113
  if (typeof document === "undefined" || typeof MutationObserver === "undefined") {
10089
10114
  return;
10090
10115
  }
10116
+ if (environment !== "chatgpt") {
10117
+ return;
10118
+ }
10091
10119
  const root = document.documentElement;
10092
10120
  const observer = new MutationObserver((mutations) => {
10093
10121
  for (const mutation of mutations) {
10094
10122
  if (mutation.type === "attributes" && (mutation.attributeName === "data-theme" || mutation.attributeName === "class")) {
10095
10123
  const newTheme = detectTheme();
10096
- const currentEnv = root.getAttribute("data-env") || environment;
10097
- const defaults = currentEnv === "chatgpt" ? getChatGptDefaultStyles({ theme: newTheme }) : getMcpAppDefaultStyles({ theme: newTheme });
10124
+ const defaults = getChatGptDefaultStyles({ theme: newTheme });
10098
10125
  applyStyles({ styles: defaults });
10099
10126
  }
10100
10127
  }