mcp-use 1.1.6-canary.1 → 1.1.7-canary.0

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 CHANGED
@@ -587,7 +587,7 @@ server.listen(3000)
587
587
 
588
588
  This automatically creates:
589
589
 
590
- - **Tool**: `ui_kanban-board` - Accepts parameters and returns UIResource
590
+ - **Tool**: `kanban-board` - Accepts parameters and returns UIResource
591
591
  - **Resource**: `ui://widget/kanban-board` - Static access with defaults
592
592
 
593
593
  #### Three Resource Types
@@ -691,6 +691,170 @@ function useMcp(options) {
691
691
  }
692
692
  __name(useMcp, "useMcp");
693
693
 
694
+ // src/react/useWidget.ts
695
+ import { useCallback as useCallback2, useEffect as useEffect2, useMemo, useState as useState2, useSyncExternalStore } from "react";
696
+
697
+ // src/react/widget-types.ts
698
+ var SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
699
+
700
+ // src/react/useWidget.ts
701
+ function useOpenAiGlobal(key) {
702
+ return useSyncExternalStore(
703
+ (onChange) => {
704
+ const handleSetGlobal = /* @__PURE__ */ __name((event) => {
705
+ const customEvent = event;
706
+ const value = customEvent.detail.globals[key];
707
+ if (value === void 0) {
708
+ return;
709
+ }
710
+ onChange();
711
+ }, "handleSetGlobal");
712
+ if (typeof window !== "undefined") {
713
+ window.addEventListener(
714
+ SET_GLOBALS_EVENT_TYPE,
715
+ handleSetGlobal
716
+ );
717
+ }
718
+ return () => {
719
+ if (typeof window !== "undefined") {
720
+ window.removeEventListener(
721
+ SET_GLOBALS_EVENT_TYPE,
722
+ handleSetGlobal
723
+ );
724
+ }
725
+ };
726
+ },
727
+ () => typeof window !== "undefined" && window.openai ? window.openai[key] : void 0
728
+ );
729
+ }
730
+ __name(useOpenAiGlobal, "useOpenAiGlobal");
731
+ function useWidget(defaultProps) {
732
+ console.log(window?.location?.search, window.openai);
733
+ const isOpenAiAvailable = useMemo(() => typeof window !== "undefined" && !!window.openai, []);
734
+ const provider = useMemo(() => {
735
+ return isOpenAiAvailable ? "openai" : "mcp-ui";
736
+ }, [isOpenAiAvailable]);
737
+ const urlParams = useMemo(() => {
738
+ const urlParams2 = new URLSearchParams(window?.location?.search);
739
+ if (urlParams2.has("mcpUseParams")) {
740
+ return JSON.parse(urlParams2.get("mcpUseParams"));
741
+ }
742
+ return {
743
+ toolInput: {},
744
+ toolOutput: {},
745
+ toolId: ""
746
+ };
747
+ }, [window?.location?.search]);
748
+ console.log(urlParams);
749
+ const toolInput = provider === "openai" ? useOpenAiGlobal("toolInput") : urlParams.toolInput;
750
+ const toolOutput = provider === "openai" ? useOpenAiGlobal("toolOutput") : urlParams.toolOutput;
751
+ const toolResponseMetadata = useOpenAiGlobal("toolResponseMetadata");
752
+ const widgetState = useOpenAiGlobal("widgetState");
753
+ const theme = useOpenAiGlobal("theme");
754
+ const displayMode = useOpenAiGlobal("displayMode");
755
+ const safeArea = useOpenAiGlobal("safeArea");
756
+ const maxHeight = useOpenAiGlobal("maxHeight");
757
+ const userAgent = useOpenAiGlobal("userAgent");
758
+ const locale = useOpenAiGlobal("locale");
759
+ const [localWidgetState, setLocalWidgetState] = useState2(null);
760
+ useEffect2(() => {
761
+ if (widgetState !== void 0) {
762
+ setLocalWidgetState(widgetState);
763
+ }
764
+ }, [widgetState]);
765
+ const callTool = useCallback2(
766
+ async (name, args) => {
767
+ if (!window.openai?.callTool) {
768
+ throw new Error("window.openai.callTool is not available");
769
+ }
770
+ return window.openai.callTool(name, args);
771
+ },
772
+ []
773
+ );
774
+ const sendFollowUpMessage = useCallback2(async (prompt) => {
775
+ if (!window.openai?.sendFollowUpMessage) {
776
+ throw new Error("window.openai.sendFollowUpMessage is not available");
777
+ }
778
+ return window.openai.sendFollowUpMessage({ prompt });
779
+ }, []);
780
+ const openExternal = useCallback2((href) => {
781
+ if (!window.openai?.openExternal) {
782
+ throw new Error("window.openai.openExternal is not available");
783
+ }
784
+ window.openai.openExternal({ href });
785
+ }, []);
786
+ const requestDisplayMode = useCallback2(
787
+ async (mode) => {
788
+ if (!window.openai?.requestDisplayMode) {
789
+ throw new Error("window.openai.requestDisplayMode is not available");
790
+ }
791
+ return window.openai.requestDisplayMode({ mode });
792
+ },
793
+ []
794
+ );
795
+ const setState = useCallback2(
796
+ async (state) => {
797
+ const newState = typeof state === "function" ? state(localWidgetState) : state;
798
+ if (!window.openai?.setWidgetState) {
799
+ throw new Error("window.openai.setWidgetState is not available");
800
+ }
801
+ setLocalWidgetState(newState);
802
+ return window.openai.setWidgetState(newState);
803
+ },
804
+ [localWidgetState]
805
+ );
806
+ return {
807
+ // Props and state (with defaults)
808
+ props: toolInput || defaultProps || {},
809
+ output: toolOutput ?? null,
810
+ metadata: toolResponseMetadata ?? null,
811
+ state: localWidgetState,
812
+ setState,
813
+ // Layout and theme (with safe defaults)
814
+ theme: theme || "light",
815
+ displayMode: displayMode || "inline",
816
+ safeArea: safeArea || { insets: { top: 0, bottom: 0, left: 0, right: 0 } },
817
+ maxHeight: maxHeight || 600,
818
+ userAgent: userAgent || {
819
+ device: { type: "desktop" },
820
+ capabilities: { hover: true, touch: false }
821
+ },
822
+ locale: locale || "en",
823
+ // Actions
824
+ callTool,
825
+ sendFollowUpMessage,
826
+ openExternal,
827
+ requestDisplayMode,
828
+ // Availability
829
+ isAvailable: isOpenAiAvailable
830
+ };
831
+ }
832
+ __name(useWidget, "useWidget");
833
+ function useWidgetProps(defaultProps) {
834
+ const { props } = useWidget(defaultProps);
835
+ return props;
836
+ }
837
+ __name(useWidgetProps, "useWidgetProps");
838
+ function useWidgetTheme() {
839
+ const { theme } = useWidget();
840
+ return theme;
841
+ }
842
+ __name(useWidgetTheme, "useWidgetTheme");
843
+ function useWidgetState(defaultState) {
844
+ const { state, setState } = useWidget();
845
+ useEffect2(() => {
846
+ if (state === null && defaultState !== void 0 && window.openai?.setWidgetState) {
847
+ setState(defaultState);
848
+ }
849
+ }, []);
850
+ return [state, setState];
851
+ }
852
+ __name(useWidgetState, "useWidgetState");
853
+
694
854
  export {
695
- useMcp
855
+ useMcp,
856
+ useWidget,
857
+ useWidgetProps,
858
+ useWidgetTheme,
859
+ useWidgetState
696
860
  };
package/dist/index.cjs CHANGED
@@ -504,7 +504,11 @@ __export(index_exports, {
504
504
  setTelemetrySource: () => setTelemetrySource,
505
505
  streamEventsToAISDK: () => streamEventsToAISDK,
506
506
  streamEventsToAISDKWithTools: () => streamEventsToAISDKWithTools,
507
- useMcp: () => useMcp
507
+ useMcp: () => useMcp,
508
+ useWidget: () => useWidget,
509
+ useWidgetProps: () => useWidgetProps,
510
+ useWidgetState: () => useWidgetState,
511
+ useWidgetTheme: () => useWidgetTheme
508
512
  });
509
513
  module.exports = __toCommonJS(index_exports);
510
514
 
@@ -5402,6 +5406,166 @@ function useMcp(options) {
5402
5406
  }
5403
5407
  __name(useMcp, "useMcp");
5404
5408
 
5409
+ // src/react/useWidget.ts
5410
+ var import_react2 = require("react");
5411
+
5412
+ // src/react/widget-types.ts
5413
+ var SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
5414
+
5415
+ // src/react/useWidget.ts
5416
+ function useOpenAiGlobal(key) {
5417
+ return (0, import_react2.useSyncExternalStore)(
5418
+ (onChange) => {
5419
+ const handleSetGlobal = /* @__PURE__ */ __name((event) => {
5420
+ const customEvent = event;
5421
+ const value = customEvent.detail.globals[key];
5422
+ if (value === void 0) {
5423
+ return;
5424
+ }
5425
+ onChange();
5426
+ }, "handleSetGlobal");
5427
+ if (typeof window !== "undefined") {
5428
+ window.addEventListener(
5429
+ SET_GLOBALS_EVENT_TYPE,
5430
+ handleSetGlobal
5431
+ );
5432
+ }
5433
+ return () => {
5434
+ if (typeof window !== "undefined") {
5435
+ window.removeEventListener(
5436
+ SET_GLOBALS_EVENT_TYPE,
5437
+ handleSetGlobal
5438
+ );
5439
+ }
5440
+ };
5441
+ },
5442
+ () => typeof window !== "undefined" && window.openai ? window.openai[key] : void 0
5443
+ );
5444
+ }
5445
+ __name(useOpenAiGlobal, "useOpenAiGlobal");
5446
+ function useWidget(defaultProps) {
5447
+ console.log(window?.location?.search, window.openai);
5448
+ const isOpenAiAvailable = (0, import_react2.useMemo)(() => typeof window !== "undefined" && !!window.openai, []);
5449
+ const provider = (0, import_react2.useMemo)(() => {
5450
+ return isOpenAiAvailable ? "openai" : "mcp-ui";
5451
+ }, [isOpenAiAvailable]);
5452
+ const urlParams = (0, import_react2.useMemo)(() => {
5453
+ const urlParams2 = new URLSearchParams(window?.location?.search);
5454
+ if (urlParams2.has("mcpUseParams")) {
5455
+ return JSON.parse(urlParams2.get("mcpUseParams"));
5456
+ }
5457
+ return {
5458
+ toolInput: {},
5459
+ toolOutput: {},
5460
+ toolId: ""
5461
+ };
5462
+ }, [window?.location?.search]);
5463
+ console.log(urlParams);
5464
+ const toolInput = provider === "openai" ? useOpenAiGlobal("toolInput") : urlParams.toolInput;
5465
+ const toolOutput = provider === "openai" ? useOpenAiGlobal("toolOutput") : urlParams.toolOutput;
5466
+ const toolResponseMetadata = useOpenAiGlobal("toolResponseMetadata");
5467
+ const widgetState = useOpenAiGlobal("widgetState");
5468
+ const theme = useOpenAiGlobal("theme");
5469
+ const displayMode = useOpenAiGlobal("displayMode");
5470
+ const safeArea = useOpenAiGlobal("safeArea");
5471
+ const maxHeight = useOpenAiGlobal("maxHeight");
5472
+ const userAgent = useOpenAiGlobal("userAgent");
5473
+ const locale = useOpenAiGlobal("locale");
5474
+ const [localWidgetState, setLocalWidgetState] = (0, import_react2.useState)(null);
5475
+ (0, import_react2.useEffect)(() => {
5476
+ if (widgetState !== void 0) {
5477
+ setLocalWidgetState(widgetState);
5478
+ }
5479
+ }, [widgetState]);
5480
+ const callTool = (0, import_react2.useCallback)(
5481
+ async (name, args) => {
5482
+ if (!window.openai?.callTool) {
5483
+ throw new Error("window.openai.callTool is not available");
5484
+ }
5485
+ return window.openai.callTool(name, args);
5486
+ },
5487
+ []
5488
+ );
5489
+ const sendFollowUpMessage = (0, import_react2.useCallback)(async (prompt) => {
5490
+ if (!window.openai?.sendFollowUpMessage) {
5491
+ throw new Error("window.openai.sendFollowUpMessage is not available");
5492
+ }
5493
+ return window.openai.sendFollowUpMessage({ prompt });
5494
+ }, []);
5495
+ const openExternal = (0, import_react2.useCallback)((href) => {
5496
+ if (!window.openai?.openExternal) {
5497
+ throw new Error("window.openai.openExternal is not available");
5498
+ }
5499
+ window.openai.openExternal({ href });
5500
+ }, []);
5501
+ const requestDisplayMode = (0, import_react2.useCallback)(
5502
+ async (mode) => {
5503
+ if (!window.openai?.requestDisplayMode) {
5504
+ throw new Error("window.openai.requestDisplayMode is not available");
5505
+ }
5506
+ return window.openai.requestDisplayMode({ mode });
5507
+ },
5508
+ []
5509
+ );
5510
+ const setState = (0, import_react2.useCallback)(
5511
+ async (state) => {
5512
+ const newState = typeof state === "function" ? state(localWidgetState) : state;
5513
+ if (!window.openai?.setWidgetState) {
5514
+ throw new Error("window.openai.setWidgetState is not available");
5515
+ }
5516
+ setLocalWidgetState(newState);
5517
+ return window.openai.setWidgetState(newState);
5518
+ },
5519
+ [localWidgetState]
5520
+ );
5521
+ return {
5522
+ // Props and state (with defaults)
5523
+ props: toolInput || defaultProps || {},
5524
+ output: toolOutput ?? null,
5525
+ metadata: toolResponseMetadata ?? null,
5526
+ state: localWidgetState,
5527
+ setState,
5528
+ // Layout and theme (with safe defaults)
5529
+ theme: theme || "light",
5530
+ displayMode: displayMode || "inline",
5531
+ safeArea: safeArea || { insets: { top: 0, bottom: 0, left: 0, right: 0 } },
5532
+ maxHeight: maxHeight || 600,
5533
+ userAgent: userAgent || {
5534
+ device: { type: "desktop" },
5535
+ capabilities: { hover: true, touch: false }
5536
+ },
5537
+ locale: locale || "en",
5538
+ // Actions
5539
+ callTool,
5540
+ sendFollowUpMessage,
5541
+ openExternal,
5542
+ requestDisplayMode,
5543
+ // Availability
5544
+ isAvailable: isOpenAiAvailable
5545
+ };
5546
+ }
5547
+ __name(useWidget, "useWidget");
5548
+ function useWidgetProps(defaultProps) {
5549
+ const { props } = useWidget(defaultProps);
5550
+ return props;
5551
+ }
5552
+ __name(useWidgetProps, "useWidgetProps");
5553
+ function useWidgetTheme() {
5554
+ const { theme } = useWidget();
5555
+ return theme;
5556
+ }
5557
+ __name(useWidgetTheme, "useWidgetTheme");
5558
+ function useWidgetState(defaultState) {
5559
+ const { state, setState } = useWidget();
5560
+ (0, import_react2.useEffect)(() => {
5561
+ if (state === null && defaultState !== void 0 && window.openai?.setWidgetState) {
5562
+ setState(defaultState);
5563
+ }
5564
+ }, []);
5565
+ return [state, setState];
5566
+ }
5567
+ __name(useWidgetState, "useWidgetState");
5568
+
5405
5569
  // index.ts
5406
5570
  var import_messages3 = require("@langchain/core/messages");
5407
5571
  // Annotate the CommonJS export names for ESM import in node:
@@ -5441,5 +5605,9 @@ var import_messages3 = require("@langchain/core/messages");
5441
5605
  setTelemetrySource,
5442
5606
  streamEventsToAISDK,
5443
5607
  streamEventsToAISDKWithTools,
5444
- useMcp
5608
+ useMcp,
5609
+ useWidget,
5610
+ useWidgetProps,
5611
+ useWidgetState,
5612
+ useWidgetTheme
5445
5613
  });
package/dist/index.js CHANGED
@@ -23,8 +23,12 @@ import {
23
23
  streamEventsToAISDKWithTools
24
24
  } from "./chunk-4SWVHFJH.js";
25
25
  import {
26
- useMcp
27
- } from "./chunk-B5SNLEZM.js";
26
+ useMcp,
27
+ useWidget,
28
+ useWidgetProps,
29
+ useWidgetState,
30
+ useWidgetTheme
31
+ } from "./chunk-JV7HAYUT.js";
28
32
  import {
29
33
  BrowserOAuthClientProvider,
30
34
  onMcpAuthorization
@@ -640,5 +644,9 @@ export {
640
644
  setTelemetrySource,
641
645
  streamEventsToAISDK,
642
646
  streamEventsToAISDKWithTools,
643
- useMcp
647
+ useMcp,
648
+ useWidget,
649
+ useWidgetProps,
650
+ useWidgetState,
651
+ useWidgetTheme
644
652
  };
@@ -22,7 +22,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  var react_exports = {};
23
23
  __export(react_exports, {
24
24
  onMcpAuthorization: () => onMcpAuthorization,
25
- useMcp: () => useMcp
25
+ useMcp: () => useMcp,
26
+ useWidget: () => useWidget,
27
+ useWidgetProps: () => useWidgetProps,
28
+ useWidgetState: () => useWidgetState,
29
+ useWidgetTheme: () => useWidgetTheme
26
30
  });
27
31
  module.exports = __toCommonJS(react_exports);
28
32
 
@@ -996,8 +1000,172 @@ async function onMcpAuthorization() {
996
1000
  }
997
1001
  }
998
1002
  __name(onMcpAuthorization, "onMcpAuthorization");
1003
+
1004
+ // src/react/useWidget.ts
1005
+ var import_react2 = require("react");
1006
+
1007
+ // src/react/widget-types.ts
1008
+ var SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
1009
+
1010
+ // src/react/useWidget.ts
1011
+ function useOpenAiGlobal(key) {
1012
+ return (0, import_react2.useSyncExternalStore)(
1013
+ (onChange) => {
1014
+ const handleSetGlobal = /* @__PURE__ */ __name((event) => {
1015
+ const customEvent = event;
1016
+ const value = customEvent.detail.globals[key];
1017
+ if (value === void 0) {
1018
+ return;
1019
+ }
1020
+ onChange();
1021
+ }, "handleSetGlobal");
1022
+ if (typeof window !== "undefined") {
1023
+ window.addEventListener(
1024
+ SET_GLOBALS_EVENT_TYPE,
1025
+ handleSetGlobal
1026
+ );
1027
+ }
1028
+ return () => {
1029
+ if (typeof window !== "undefined") {
1030
+ window.removeEventListener(
1031
+ SET_GLOBALS_EVENT_TYPE,
1032
+ handleSetGlobal
1033
+ );
1034
+ }
1035
+ };
1036
+ },
1037
+ () => typeof window !== "undefined" && window.openai ? window.openai[key] : void 0
1038
+ );
1039
+ }
1040
+ __name(useOpenAiGlobal, "useOpenAiGlobal");
1041
+ function useWidget(defaultProps) {
1042
+ console.log(window?.location?.search, window.openai);
1043
+ const isOpenAiAvailable = (0, import_react2.useMemo)(() => typeof window !== "undefined" && !!window.openai, []);
1044
+ const provider = (0, import_react2.useMemo)(() => {
1045
+ return isOpenAiAvailable ? "openai" : "mcp-ui";
1046
+ }, [isOpenAiAvailable]);
1047
+ const urlParams = (0, import_react2.useMemo)(() => {
1048
+ const urlParams2 = new URLSearchParams(window?.location?.search);
1049
+ if (urlParams2.has("mcpUseParams")) {
1050
+ return JSON.parse(urlParams2.get("mcpUseParams"));
1051
+ }
1052
+ return {
1053
+ toolInput: {},
1054
+ toolOutput: {},
1055
+ toolId: ""
1056
+ };
1057
+ }, [window?.location?.search]);
1058
+ console.log(urlParams);
1059
+ const toolInput = provider === "openai" ? useOpenAiGlobal("toolInput") : urlParams.toolInput;
1060
+ const toolOutput = provider === "openai" ? useOpenAiGlobal("toolOutput") : urlParams.toolOutput;
1061
+ const toolResponseMetadata = useOpenAiGlobal("toolResponseMetadata");
1062
+ const widgetState = useOpenAiGlobal("widgetState");
1063
+ const theme = useOpenAiGlobal("theme");
1064
+ const displayMode = useOpenAiGlobal("displayMode");
1065
+ const safeArea = useOpenAiGlobal("safeArea");
1066
+ const maxHeight = useOpenAiGlobal("maxHeight");
1067
+ const userAgent = useOpenAiGlobal("userAgent");
1068
+ const locale = useOpenAiGlobal("locale");
1069
+ const [localWidgetState, setLocalWidgetState] = (0, import_react2.useState)(null);
1070
+ (0, import_react2.useEffect)(() => {
1071
+ if (widgetState !== void 0) {
1072
+ setLocalWidgetState(widgetState);
1073
+ }
1074
+ }, [widgetState]);
1075
+ const callTool = (0, import_react2.useCallback)(
1076
+ async (name, args) => {
1077
+ if (!window.openai?.callTool) {
1078
+ throw new Error("window.openai.callTool is not available");
1079
+ }
1080
+ return window.openai.callTool(name, args);
1081
+ },
1082
+ []
1083
+ );
1084
+ const sendFollowUpMessage = (0, import_react2.useCallback)(async (prompt) => {
1085
+ if (!window.openai?.sendFollowUpMessage) {
1086
+ throw new Error("window.openai.sendFollowUpMessage is not available");
1087
+ }
1088
+ return window.openai.sendFollowUpMessage({ prompt });
1089
+ }, []);
1090
+ const openExternal = (0, import_react2.useCallback)((href) => {
1091
+ if (!window.openai?.openExternal) {
1092
+ throw new Error("window.openai.openExternal is not available");
1093
+ }
1094
+ window.openai.openExternal({ href });
1095
+ }, []);
1096
+ const requestDisplayMode = (0, import_react2.useCallback)(
1097
+ async (mode) => {
1098
+ if (!window.openai?.requestDisplayMode) {
1099
+ throw new Error("window.openai.requestDisplayMode is not available");
1100
+ }
1101
+ return window.openai.requestDisplayMode({ mode });
1102
+ },
1103
+ []
1104
+ );
1105
+ const setState = (0, import_react2.useCallback)(
1106
+ async (state) => {
1107
+ const newState = typeof state === "function" ? state(localWidgetState) : state;
1108
+ if (!window.openai?.setWidgetState) {
1109
+ throw new Error("window.openai.setWidgetState is not available");
1110
+ }
1111
+ setLocalWidgetState(newState);
1112
+ return window.openai.setWidgetState(newState);
1113
+ },
1114
+ [localWidgetState]
1115
+ );
1116
+ return {
1117
+ // Props and state (with defaults)
1118
+ props: toolInput || defaultProps || {},
1119
+ output: toolOutput ?? null,
1120
+ metadata: toolResponseMetadata ?? null,
1121
+ state: localWidgetState,
1122
+ setState,
1123
+ // Layout and theme (with safe defaults)
1124
+ theme: theme || "light",
1125
+ displayMode: displayMode || "inline",
1126
+ safeArea: safeArea || { insets: { top: 0, bottom: 0, left: 0, right: 0 } },
1127
+ maxHeight: maxHeight || 600,
1128
+ userAgent: userAgent || {
1129
+ device: { type: "desktop" },
1130
+ capabilities: { hover: true, touch: false }
1131
+ },
1132
+ locale: locale || "en",
1133
+ // Actions
1134
+ callTool,
1135
+ sendFollowUpMessage,
1136
+ openExternal,
1137
+ requestDisplayMode,
1138
+ // Availability
1139
+ isAvailable: isOpenAiAvailable
1140
+ };
1141
+ }
1142
+ __name(useWidget, "useWidget");
1143
+ function useWidgetProps(defaultProps) {
1144
+ const { props } = useWidget(defaultProps);
1145
+ return props;
1146
+ }
1147
+ __name(useWidgetProps, "useWidgetProps");
1148
+ function useWidgetTheme() {
1149
+ const { theme } = useWidget();
1150
+ return theme;
1151
+ }
1152
+ __name(useWidgetTheme, "useWidgetTheme");
1153
+ function useWidgetState(defaultState) {
1154
+ const { state, setState } = useWidget();
1155
+ (0, import_react2.useEffect)(() => {
1156
+ if (state === null && defaultState !== void 0 && window.openai?.setWidgetState) {
1157
+ setState(defaultState);
1158
+ }
1159
+ }, []);
1160
+ return [state, setState];
1161
+ }
1162
+ __name(useWidgetState, "useWidgetState");
999
1163
  // Annotate the CommonJS export names for ESM import in node:
1000
1164
  0 && (module.exports = {
1001
1165
  onMcpAuthorization,
1002
- useMcp
1166
+ useMcp,
1167
+ useWidget,
1168
+ useWidgetProps,
1169
+ useWidgetState,
1170
+ useWidgetTheme
1003
1171
  });
@@ -6,4 +6,6 @@ export { useMcp } from './useMcp.js';
6
6
  export type { UseMcpOptions, UseMcpResult } from './types.js';
7
7
  export { onMcpAuthorization } from '../auth/callback.js';
8
8
  export type { Tool, Resource, ResourceTemplate, Prompt } from '@modelcontextprotocol/sdk/types.js';
9
+ export { useWidget, useWidgetProps, useWidgetTheme, useWidgetState } from './useWidget.js';
10
+ export type { UseWidgetResult, OpenAiGlobals, API, Theme, DisplayMode, DeviceType, SafeArea, SafeAreaInsets, UserAgent, CallToolResponse, UnknownObject, } from './widget-types.js';
9
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAG7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAGxD,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAG7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAGxD,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAA;AAGlG,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC1F,YAAY,EACV,eAAe,EACf,aAAa,EACb,GAAG,EACH,KAAK,EACL,WAAW,EACX,UAAU,EACV,QAAQ,EACR,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,aAAa,GACd,MAAM,mBAAmB,CAAA"}
@@ -1,11 +1,19 @@
1
1
  import {
2
- useMcp
3
- } from "../../chunk-B5SNLEZM.js";
2
+ useMcp,
3
+ useWidget,
4
+ useWidgetProps,
5
+ useWidgetState,
6
+ useWidgetTheme
7
+ } from "../../chunk-JV7HAYUT.js";
4
8
  import {
5
9
  onMcpAuthorization
6
10
  } from "../../chunk-62GFHYCL.js";
7
11
  import "../../chunk-SHUYVCID.js";
8
12
  export {
9
13
  onMcpAuthorization,
10
- useMcp
14
+ useMcp,
15
+ useWidget,
16
+ useWidgetProps,
17
+ useWidgetState,
18
+ useWidgetTheme
11
19
  };
@@ -0,0 +1,54 @@
1
+ /**
2
+ * React hook for OpenAI Apps SDK widget development
3
+ * Wraps window.openai API and adapts MCP UI props to toolInput
4
+ */
5
+ import type { Theme, UnknownObject, UseWidgetResult } from './widget-types.js';
6
+ /**
7
+ * React hook for building OpenAI Apps SDK widgets with MCP-use
8
+ *
9
+ * Provides type-safe access to the window.openai API and automatically
10
+ * maps MCP UI props to the Apps SDK toolInput format.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * const MyWidget: React.FC = () => {
15
+ * const { props, theme, callTool, sendFollowUpMessage } = useWidget<{
16
+ * city: string;
17
+ * temperature: number;
18
+ * }>();
19
+ *
20
+ * return (
21
+ * <div data-theme={theme}>
22
+ * <h1>{props.city}</h1>
23
+ * <p>{props.temperature}°C</p>
24
+ * </div>
25
+ * );
26
+ * };
27
+ * ```
28
+ */
29
+ export declare function useWidget<TProps extends UnknownObject = UnknownObject, TOutput extends UnknownObject = UnknownObject, TMetadata extends UnknownObject = UnknownObject, TState extends UnknownObject = UnknownObject>(defaultProps?: TProps): UseWidgetResult<TProps, TOutput, TMetadata, TState>;
30
+ /**
31
+ * Hook to get just the widget props (most common use case)
32
+ * @example
33
+ * ```tsx
34
+ * const props = useWidgetProps<{ city: string; temperature: number }>();
35
+ * ```
36
+ */
37
+ export declare function useWidgetProps<TProps extends UnknownObject = UnknownObject>(defaultProps?: TProps): TProps;
38
+ /**
39
+ * Hook to get theme value
40
+ * @example
41
+ * ```tsx
42
+ * const theme = useWidgetTheme();
43
+ * ```
44
+ */
45
+ export declare function useWidgetTheme(): Theme;
46
+ /**
47
+ * Hook to get and update widget state
48
+ * @example
49
+ * ```tsx
50
+ * const [favorites, setFavorites] = useWidgetState<string[]>([]);
51
+ * ```
52
+ */
53
+ export declare function useWidgetState<TState extends UnknownObject>(defaultState?: TState): readonly [TState | null, (state: TState | ((prev: TState | null) => TState)) => Promise<void>];
54
+ //# sourceMappingURL=useWidget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWidget.d.ts","sourceRoot":"","sources":["../../../src/react/useWidget.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAKV,KAAK,EACL,aAAa,EAEb,eAAe,EAChB,MAAM,mBAAmB,CAAA;AAyC1B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,SAAS,CACvB,MAAM,SAAS,aAAa,GAAG,aAAa,EAC5C,OAAO,SAAS,aAAa,GAAG,aAAa,EAC7C,SAAS,SAAS,aAAa,GAAG,aAAa,EAC/C,MAAM,SAAS,aAAa,GAAG,aAAa,EAC5C,YAAY,CAAC,EAAE,MAAM,GAAG,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAmI5E;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,SAAS,aAAa,GAAG,aAAa,EACzE,YAAY,CAAC,EAAE,MAAM,GACpB,MAAM,CAGR;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,IAAI,KAAK,CAGtC;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,SAAS,aAAa,EACzD,YAAY,CAAC,EAAE,MAAM,GACpB,SAAS,CAAC,MAAM,GAAG,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK,MAAM,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,CAWhG"}