@supyagent/sdk 0.1.39 → 0.2.1

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/react.cjs CHANGED
@@ -37,6 +37,7 @@ __export(react_exports, {
37
37
  CalendlyFormatter: () => CalendlyFormatter,
38
38
  CollapsibleResult: () => CollapsibleResult,
39
39
  ComputeFormatter: () => ComputeFormatter,
40
+ ConnectCallback: () => ConnectCallback,
40
41
  ContextIndicator: () => ContextIndicator,
41
42
  DiscordFormatter: () => DiscordFormatter,
42
43
  DocsFormatter: () => DocsFormatter,
@@ -85,7 +86,8 @@ __export(react_exports, {
85
86
  normalizeMicrosoftDrive: () => normalizeMicrosoftDrive,
86
87
  normalizeMicrosoftMail: () => normalizeMicrosoftMail,
87
88
  resolveToolName: () => resolveToolName,
88
- unwrapSupyagentResult: () => unwrapSupyagentResult
89
+ unwrapSupyagentResult: () => unwrapSupyagentResult,
90
+ useSupyagentConnect: () => useSupyagentConnect
89
91
  });
90
92
  module.exports = __toCommonJS(react_exports);
91
93
 
@@ -3798,6 +3800,125 @@ function SupyagentToolCall({ part }) {
3798
3800
  }
3799
3801
  );
3800
3802
  }
3803
+
3804
+ // src/react.tsx
3805
+ var import_react6 = require("react");
3806
+
3807
+ // src/connect/popup.ts
3808
+ function openConnectPopup(options) {
3809
+ const { connectUrl, width = 500, height = 700, onSuccess, onError } = options;
3810
+ return new Promise((resolve, reject) => {
3811
+ const left = Math.round(window.screenX + (window.outerWidth - width) / 2);
3812
+ const top = Math.round(window.screenY + (window.outerHeight - height) / 2);
3813
+ const features = `width=${width},height=${height},left=${left},top=${top},popup=1`;
3814
+ const popup = window.open(connectUrl, "supyagent_connect", features);
3815
+ if (!popup) {
3816
+ const err = new Error(
3817
+ "Popup was blocked by the browser. Please allow popups for this site."
3818
+ );
3819
+ onError?.(err);
3820
+ reject(err);
3821
+ return;
3822
+ }
3823
+ const popupRef = popup;
3824
+ let settled = false;
3825
+ function cleanup() {
3826
+ window.removeEventListener("message", onMessage);
3827
+ clearInterval(pollTimer);
3828
+ }
3829
+ function onMessage(event) {
3830
+ const data = event.data;
3831
+ if (!data || data.type !== "supyagent:connect") return;
3832
+ settled = true;
3833
+ cleanup();
3834
+ try {
3835
+ popupRef.close();
3836
+ } catch {
3837
+ }
3838
+ if (data.status === "success" && data.provider && data.accountId) {
3839
+ const result = {
3840
+ status: "success",
3841
+ provider: data.provider,
3842
+ accountId: data.accountId
3843
+ };
3844
+ onSuccess?.(result);
3845
+ resolve(result);
3846
+ } else {
3847
+ const err = new Error(data.error || "OAuth connect failed");
3848
+ onError?.(err);
3849
+ reject(err);
3850
+ }
3851
+ }
3852
+ window.addEventListener("message", onMessage);
3853
+ const pollTimer = setInterval(() => {
3854
+ if (!settled && popupRef.closed) {
3855
+ settled = true;
3856
+ cleanup();
3857
+ const err = new Error("Popup was closed before completing the OAuth flow");
3858
+ onError?.(err);
3859
+ reject(err);
3860
+ }
3861
+ }, 500);
3862
+ });
3863
+ }
3864
+
3865
+ // src/connect/callback.ts
3866
+ function handleConnectCallback(options) {
3867
+ const { targetOrigin = "*", autoClose = true } = options ?? {};
3868
+ const params = new URLSearchParams(window.location.search);
3869
+ const status = params.get("status");
3870
+ const provider = params.get("provider");
3871
+ const accountId = params.get("account_id");
3872
+ const error = params.get("error");
3873
+ const message = {
3874
+ type: "supyagent:connect",
3875
+ status: status === "success" ? "success" : "error",
3876
+ ...provider ? { provider } : {},
3877
+ ...accountId ? { accountId } : {},
3878
+ ...error ? { error } : {}
3879
+ };
3880
+ if (window.opener) {
3881
+ window.opener.postMessage(message, targetOrigin);
3882
+ }
3883
+ if (autoClose) {
3884
+ window.close();
3885
+ }
3886
+ }
3887
+
3888
+ // src/react.tsx
3889
+ var import_jsx_runtime39 = require("react/jsx-runtime");
3890
+ function useSupyagentConnect() {
3891
+ const [isConnecting, setIsConnecting] = (0, import_react6.useState)(false);
3892
+ const [error, setError] = (0, import_react6.useState)(null);
3893
+ const [result, setResult] = (0, import_react6.useState)(null);
3894
+ const connect = (0, import_react6.useCallback)(async (options) => {
3895
+ setIsConnecting(true);
3896
+ setError(null);
3897
+ setResult(null);
3898
+ try {
3899
+ const res = await openConnectPopup(options);
3900
+ setResult(res);
3901
+ return res;
3902
+ } catch (err) {
3903
+ const e = err instanceof Error ? err : new Error(String(err));
3904
+ setError(e);
3905
+ throw e;
3906
+ } finally {
3907
+ setIsConnecting(false);
3908
+ }
3909
+ }, []);
3910
+ return { connect, isConnecting, error, result };
3911
+ }
3912
+ function ConnectCallback({
3913
+ children,
3914
+ targetOrigin,
3915
+ autoClose = true
3916
+ }) {
3917
+ (0, import_react6.useEffect)(() => {
3918
+ handleConnectCallback({ targetOrigin, autoClose });
3919
+ }, [targetOrigin, autoClose]);
3920
+ return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_jsx_runtime39.Fragment, { children: children ?? null });
3921
+ }
3801
3922
  // Annotate the CommonJS export names for ESM import in node:
3802
3923
  0 && (module.exports = {
3803
3924
  BrevoFormatter,
@@ -3806,6 +3927,7 @@ function SupyagentToolCall({ part }) {
3806
3927
  CalendlyFormatter,
3807
3928
  CollapsibleResult,
3808
3929
  ComputeFormatter,
3930
+ ConnectCallback,
3809
3931
  ContextIndicator,
3810
3932
  DiscordFormatter,
3811
3933
  DocsFormatter,
@@ -3854,6 +3976,7 @@ function SupyagentToolCall({ part }) {
3854
3976
  normalizeMicrosoftDrive,
3855
3977
  normalizeMicrosoftMail,
3856
3978
  resolveToolName,
3857
- unwrapSupyagentResult
3979
+ unwrapSupyagentResult,
3980
+ useSupyagentConnect
3858
3981
  });
3859
3982
  //# sourceMappingURL=react.cjs.map