@mindstudio-ai/interface 0.1.7 → 0.1.9
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/index.d.ts +142 -8
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -607,6 +607,13 @@ interface AppUser {
|
|
|
607
607
|
roles: string[];
|
|
608
608
|
/** Masked API key (e.g. "sk_...a1b2"), or null if no key exists. */
|
|
609
609
|
apiKey: string | null;
|
|
610
|
+
/**
|
|
611
|
+
* How this user authenticated. `'remy'` means the identity was delegated
|
|
612
|
+
* to the platform via "Sign in with Remy" (roles + verification are
|
|
613
|
+
* platform-managed for these users). `null`/absent means an app-verified
|
|
614
|
+
* user (email-code, sms-code, or api-key).
|
|
615
|
+
*/
|
|
616
|
+
provider?: 'remy' | null;
|
|
610
617
|
/** ISO 8601 timestamp of when the user was created. */
|
|
611
618
|
createdAt: string;
|
|
612
619
|
}
|
|
@@ -747,6 +754,49 @@ interface Country {
|
|
|
747
754
|
* ```
|
|
748
755
|
*/
|
|
749
756
|
|
|
757
|
+
/**
|
|
758
|
+
* The high-level authentication state, from {@link Auth.authStatus}.
|
|
759
|
+
*
|
|
760
|
+
* - `'authenticating'` — a "Sign in with Remy" handshake is completing right
|
|
761
|
+
* now: a cold-load redirect return (top-level or dashboard launch) is being
|
|
762
|
+
* redeemed, or an embedded popup exchange is in flight. Render a
|
|
763
|
+
* "Completing sign-in…" state, not the logged-out UI.
|
|
764
|
+
* - `'authenticated'` — a user is signed in ({@link Auth.currentUser} is set).
|
|
765
|
+
* - `'unauthenticated'` — no session and nothing in progress.
|
|
766
|
+
*/
|
|
767
|
+
type AuthStatus = 'authenticating' | 'authenticated' | 'unauthenticated';
|
|
768
|
+
/**
|
|
769
|
+
* Options for {@link Auth.signInWithRemy}.
|
|
770
|
+
*/
|
|
771
|
+
interface SignInWithRemyOptions {
|
|
772
|
+
/**
|
|
773
|
+
* The same-origin URL the platform should return the browser to after
|
|
774
|
+
* resolving access. Must be an origin the app actually serves on (the
|
|
775
|
+
* backend validates it against the app's allow-list).
|
|
776
|
+
*
|
|
777
|
+
* @default `window.location.href` — the user lands back where they started.
|
|
778
|
+
*/
|
|
779
|
+
redirectUri?: string;
|
|
780
|
+
/**
|
|
781
|
+
* CSRF token round-tripped through the redirect. Provide your own to
|
|
782
|
+
* correlate the return with app state; otherwise an opaque random value
|
|
783
|
+
* is generated. Validated on return by {@link Auth.handleRemyRedirect}
|
|
784
|
+
* (top-level flow) or by the opener (embedded/popup flow).
|
|
785
|
+
*/
|
|
786
|
+
state?: string;
|
|
787
|
+
/**
|
|
788
|
+
* How to run the handshake.
|
|
789
|
+
*
|
|
790
|
+
* - `'auto'` (default) — full-page redirect when the app is top-level; a
|
|
791
|
+
* popup when it's embedded in a cross-origin iframe (the authorize page
|
|
792
|
+
* can't be framed, so a redirect there would fail).
|
|
793
|
+
* - `'popup'` — always use a popup.
|
|
794
|
+
* - `'redirect'` — always use a full-page redirect.
|
|
795
|
+
*
|
|
796
|
+
* @default 'auto'
|
|
797
|
+
*/
|
|
798
|
+
mode?: 'auto' | 'popup' | 'redirect';
|
|
799
|
+
}
|
|
750
800
|
/**
|
|
751
801
|
* The auth namespace — authentication flows, state, and helpers.
|
|
752
802
|
*
|
|
@@ -769,6 +819,21 @@ interface Auth {
|
|
|
769
819
|
getCurrentUser(): AppUser | null;
|
|
770
820
|
/** Whether the current session is authenticated. */
|
|
771
821
|
isAuthenticated(): boolean;
|
|
822
|
+
/**
|
|
823
|
+
* The high-level auth state — `'authenticating'`, `'authenticated'`, or
|
|
824
|
+
* `'unauthenticated'`. Synchronous and safe to read in render.
|
|
825
|
+
*
|
|
826
|
+
* The key case is `'authenticating'`: it's `true` from **page load** through
|
|
827
|
+
* settle whenever a "Sign in with Remy" handshake is completing (a cold-load
|
|
828
|
+
* redirect return being redeemed, or an embedded popup exchange in flight).
|
|
829
|
+
* Read this to show a "Completing sign-in…" state instead of the logged-out
|
|
830
|
+
* UI — the `?code` URL param can't be used for that (it's stripped at the
|
|
831
|
+
* start of the exchange), and the immediate `null` from
|
|
832
|
+
* {@link onAuthStateChanged} during this window is expected.
|
|
833
|
+
*
|
|
834
|
+
* `onAuthStateChanged` fires on every transition, so re-read this there.
|
|
835
|
+
*/
|
|
836
|
+
readonly authStatus: AuthStatus;
|
|
772
837
|
/**
|
|
773
838
|
* The stable per-browser, per-app visitor identifier, or `null` if
|
|
774
839
|
* unavailable (e.g. cached bootstrap from before this field existed).
|
|
@@ -799,6 +864,67 @@ interface Auth {
|
|
|
799
864
|
* and returns the authenticated user.
|
|
800
865
|
*/
|
|
801
866
|
verifySmsCode(verificationId: string, code: string): Promise<AppUser>;
|
|
867
|
+
/**
|
|
868
|
+
* Start the "Sign in with Remy" flow. The platform — not the app — decides
|
|
869
|
+
* who the person is and whether they're allowed (think "Sign in with
|
|
870
|
+
* Google"). Auto-detects the context:
|
|
871
|
+
*
|
|
872
|
+
* - **Top-level** (production, standalone tab): redirects the browser to the
|
|
873
|
+
* platform and bounces back to `redirectUri` with a one-time code that
|
|
874
|
+
* {@link handleRemyRedirect} redeems on return. **The page navigates away**,
|
|
875
|
+
* so the returned promise never settles.
|
|
876
|
+
* - **Embedded** (cross-origin iframe, e.g. the dev IDE preview): opens a
|
|
877
|
+
* top-level popup for the handshake (the authorize page can't be framed).
|
|
878
|
+
* The returned promise resolves with the user on success, `null` if the
|
|
879
|
+
* user closes the popup, or rejects (`popup_blocked` / `invalid_state` /
|
|
880
|
+
* `signin_timeout` / exchange error). `onAuthStateChanged` also fires on
|
|
881
|
+
* success.
|
|
882
|
+
*
|
|
883
|
+
* Must be called from a user gesture (e.g. a click) so the popup isn't
|
|
884
|
+
* blocked. Override the auto-detection with `options.mode`.
|
|
885
|
+
*
|
|
886
|
+
* @example
|
|
887
|
+
* ```ts
|
|
888
|
+
* // "Continue with {Org}" button — works top-level or embedded:
|
|
889
|
+
* <button onClick={() => auth.signInWithRemy()}>Continue with Acme</button>
|
|
890
|
+
*
|
|
891
|
+
* // Await the result in an embedded app:
|
|
892
|
+
* const user = await auth.signInWithRemy();
|
|
893
|
+
* if (user) navigate('/dashboard');
|
|
894
|
+
* ```
|
|
895
|
+
*/
|
|
896
|
+
signInWithRemy(options?: SignInWithRemyOptions): Promise<AppUser | null>;
|
|
897
|
+
/**
|
|
898
|
+
* Complete a "Sign in with Remy" redirect. Call once on app load — it's a
|
|
899
|
+
* no-op (resolves `null`) when there's no code to redeem, so it's safe to
|
|
900
|
+
* run on every mount.
|
|
901
|
+
*
|
|
902
|
+
* Handles both entry points:
|
|
903
|
+
* - **SP-initiated** (returned from {@link signInWithRemy}) — validates the
|
|
904
|
+
* round-tripped CSRF `state` against the value stashed at start.
|
|
905
|
+
* - **IdP-initiated** (opened from the Remy dashboard) — a `?code=` lands on
|
|
906
|
+
* first paint with no `state`; the single-use, app-bound code is the
|
|
907
|
+
* control, so it's redeemed directly.
|
|
908
|
+
*
|
|
909
|
+
* Inside the embedded/popup document it's also a safe no-op: the popup boots
|
|
910
|
+
* the same bundle, but the code is relayed to the opener exactly once
|
|
911
|
+
* (idempotent — the import-time fast path already forwarded it), and this
|
|
912
|
+
* call resolves `null` without redeeming. So the documented "call on load"
|
|
913
|
+
* guidance holds everywhere — no need to special-case the popup.
|
|
914
|
+
*
|
|
915
|
+
* On success, updates the session in-place (fires `onAuthStateChanged`),
|
|
916
|
+
* strips `code`/`state` from the URL, and returns the authenticated user.
|
|
917
|
+
*
|
|
918
|
+
* @returns The authenticated user, or `null` if there was no code to redeem.
|
|
919
|
+
* @throws `invalid_state` if a returned `state` doesn't match the stashed one.
|
|
920
|
+
*
|
|
921
|
+
* @example
|
|
922
|
+
* ```ts
|
|
923
|
+
* useEffect(() => { auth.handleRemyRedirect(); }, []);
|
|
924
|
+
* useEffect(() => auth.onAuthStateChanged(setUser), []);
|
|
925
|
+
* ```
|
|
926
|
+
*/
|
|
927
|
+
handleRemyRedirect(): Promise<AppUser | null>;
|
|
802
928
|
/** Request an email change. Sends a code to the new email. */
|
|
803
929
|
requestEmailChange(newEmail: string): Promise<void>;
|
|
804
930
|
/** Confirm an email change with the verification code. */
|
|
@@ -828,19 +954,27 @@ interface Auth {
|
|
|
828
954
|
*/
|
|
829
955
|
revokeApiKey(): Promise<void>;
|
|
830
956
|
/**
|
|
831
|
-
* Subscribe to auth state changes. Fires immediately with the
|
|
832
|
-
*
|
|
833
|
-
*
|
|
957
|
+
* Subscribe to auth state changes. Fires immediately with the current user,
|
|
958
|
+
* then again on every transition — verify / confirm / logout, **and** each
|
|
959
|
+
* `authStatus` change (a "Sign in with Remy" handshake starting or settling).
|
|
960
|
+
*
|
|
961
|
+
* During `'authenticating'` the callback may fire with `null` (no session
|
|
962
|
+
* yet) — that's expected; read {@link authStatus} to tell it apart from a
|
|
963
|
+
* logged-out visit rather than rendering the login UI.
|
|
834
964
|
*
|
|
835
965
|
* @returns An unsubscribe function.
|
|
836
966
|
*
|
|
837
967
|
* @example
|
|
838
968
|
* ```ts
|
|
839
|
-
* // React hook
|
|
969
|
+
* // React hook — track both the user and the status.
|
|
840
970
|
* function useAuth() {
|
|
841
|
-
* const [user, setUser] = useState
|
|
842
|
-
*
|
|
843
|
-
*
|
|
971
|
+
* const [user, setUser] = useState(auth.currentUser);
|
|
972
|
+
* const [status, setStatus] = useState(auth.authStatus);
|
|
973
|
+
* useEffect(() => auth.onAuthStateChanged(() => {
|
|
974
|
+
* setUser(auth.currentUser);
|
|
975
|
+
* setStatus(auth.authStatus);
|
|
976
|
+
* }), []);
|
|
977
|
+
* return { user, status };
|
|
844
978
|
* }
|
|
845
979
|
* ```
|
|
846
980
|
*/
|
|
@@ -1008,4 +1142,4 @@ type Breadcrumb = {
|
|
|
1008
1142
|
timestamp: number;
|
|
1009
1143
|
};
|
|
1010
1144
|
|
|
1011
|
-
export { type AbortablePromise, type AgentChatClient, type AgentChatEvent, type AnalyticsClient, type AppUser, type Auth, type BootstrapConfig, type Breadcrumb, type Country, type CustomEventProps, type InvokeOptions, type Message, MindStudioInterfaceError, type SendMessageCallbacks, type SendMessageOptions, type SendMessageResult, type Thread, type ThreadListPage, type ThreadSummary, type UploadFileOptions, analytics, auth, createAgentChatClient, createClient, platform };
|
|
1145
|
+
export { type AbortablePromise, type AgentChatClient, type AgentChatEvent, type AnalyticsClient, type AppUser, type Auth, type AuthStatus, type BootstrapConfig, type Breadcrumb, type Country, type CustomEventProps, type InvokeOptions, type Message, MindStudioInterfaceError, type SendMessageCallbacks, type SendMessageOptions, type SendMessageResult, type SignInWithRemyOptions, type Thread, type ThreadListPage, type ThreadSummary, type UploadFileOptions, analytics, auth, createAgentChatClient, createClient, platform };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var l=class extends Error{code;status;constructor(t,n,
|
|
2
|
-
`)[1]??"";return`${e}|${n.trim()}`}function
|
|
3
|
-
`);m=
|
|
4
|
-
`);E=A.pop()??"";for(let R of A){if(!R.startsWith("data: "))continue;let f=R.slice(6);try{let I=JSON.parse(f);I.type==="done"&&(T={stopReason:I.stopReason,usage:I.usage}),Xe(I,r)}catch{}}}if(!T)throw new l("Stream ended without a done event","stream_incomplete");return T})();return c.abort=()=>o.abort(),c}}}var We={async uploadFile(e,t){let n=s(),{onProgress:a,signal:o}=t??{};o?.throwIfAborted();let i=await fetch("/_/generate-upload-request",{method:"POST",headers:{Authorization:`Bearer ${n.token}`,"Content-Type":"application/json"},body:JSON.stringify({filename:e.name,contentType:e.type||"application/octet-stream"}),signal:o});if(!i.ok)throw new l(`Upload presign failed: ${i.status} ${i.statusText}`,"upload_error",i.status);let{uploadUrl:c,uploadFields:d,publicUrl:g}=await i.json(),u=new FormData;for(let[v,E]of Object.entries(d))u.append(v,E);if(u.append("file",e),a)return await Qe(c,u,a,o),g;let m=await fetch(c,{method:"POST",body:u,signal:o});if(!m.ok)throw new l(`File upload failed: ${m.status} ${m.statusText}`,"upload_error",m.status);return g}};function Qe(e,t,n,a){return new Promise((o,r)=>{let i=new XMLHttpRequest;if(i.upload.addEventListener("progress",c=>{c.lengthComputable&&n(c.loaded/c.total)}),i.addEventListener("load",()=>{i.status>=200&&i.status<300?(n(1),o()):r(new l(`File upload failed: ${i.status} ${i.statusText}`,"upload_error",i.status))}),i.addEventListener("error",()=>{r(new l("File upload failed: network error","upload_error"))}),i.addEventListener("abort",()=>{r(new DOMException("Upload aborted","AbortError"))}),a){if(a.aborted){r(new DOMException("Upload aborted","AbortError"));return}a.addEventListener("abort",()=>i.abort(),{once:!0})}i.open("POST",e),i.send(t)})}var D=[{code:"AF",dialCode:"+93",name:"Afghanistan",flag:"\u{1F1E6}\u{1F1EB}"},{code:"AL",dialCode:"+355",name:"Albania",flag:"\u{1F1E6}\u{1F1F1}"},{code:"DZ",dialCode:"+213",name:"Algeria",flag:"\u{1F1E9}\u{1F1FF}"},{code:"AD",dialCode:"+376",name:"Andorra",flag:"\u{1F1E6}\u{1F1E9}"},{code:"AO",dialCode:"+244",name:"Angola",flag:"\u{1F1E6}\u{1F1F4}"},{code:"AG",dialCode:"+1",name:"Antigua and Barbuda",flag:"\u{1F1E6}\u{1F1EC}"},{code:"AR",dialCode:"+54",name:"Argentina",flag:"\u{1F1E6}\u{1F1F7}"},{code:"AM",dialCode:"+374",name:"Armenia",flag:"\u{1F1E6}\u{1F1F2}"},{code:"AU",dialCode:"+61",name:"Australia",flag:"\u{1F1E6}\u{1F1FA}"},{code:"AT",dialCode:"+43",name:"Austria",flag:"\u{1F1E6}\u{1F1F9}"},{code:"AZ",dialCode:"+994",name:"Azerbaijan",flag:"\u{1F1E6}\u{1F1FF}"},{code:"BS",dialCode:"+1",name:"Bahamas",flag:"\u{1F1E7}\u{1F1F8}"},{code:"BH",dialCode:"+973",name:"Bahrain",flag:"\u{1F1E7}\u{1F1ED}"},{code:"BD",dialCode:"+880",name:"Bangladesh",flag:"\u{1F1E7}\u{1F1E9}"},{code:"BB",dialCode:"+1",name:"Barbados",flag:"\u{1F1E7}\u{1F1E7}"},{code:"BY",dialCode:"+375",name:"Belarus",flag:"\u{1F1E7}\u{1F1FE}"},{code:"BE",dialCode:"+32",name:"Belgium",flag:"\u{1F1E7}\u{1F1EA}"},{code:"BZ",dialCode:"+501",name:"Belize",flag:"\u{1F1E7}\u{1F1FF}"},{code:"BJ",dialCode:"+229",name:"Benin",flag:"\u{1F1E7}\u{1F1EF}"},{code:"BT",dialCode:"+975",name:"Bhutan",flag:"\u{1F1E7}\u{1F1F9}"},{code:"BO",dialCode:"+591",name:"Bolivia",flag:"\u{1F1E7}\u{1F1F4}"},{code:"BA",dialCode:"+387",name:"Bosnia and Herzegovina",flag:"\u{1F1E7}\u{1F1E6}"},{code:"BW",dialCode:"+267",name:"Botswana",flag:"\u{1F1E7}\u{1F1FC}"},{code:"BR",dialCode:"+55",name:"Brazil",flag:"\u{1F1E7}\u{1F1F7}"},{code:"BN",dialCode:"+673",name:"Brunei",flag:"\u{1F1E7}\u{1F1F3}"},{code:"BG",dialCode:"+359",name:"Bulgaria",flag:"\u{1F1E7}\u{1F1EC}"},{code:"BF",dialCode:"+226",name:"Burkina Faso",flag:"\u{1F1E7}\u{1F1EB}"},{code:"BI",dialCode:"+257",name:"Burundi",flag:"\u{1F1E7}\u{1F1EE}"},{code:"CV",dialCode:"+238",name:"Cabo Verde",flag:"\u{1F1E8}\u{1F1FB}"},{code:"KH",dialCode:"+855",name:"Cambodia",flag:"\u{1F1F0}\u{1F1ED}"},{code:"CM",dialCode:"+237",name:"Cameroon",flag:"\u{1F1E8}\u{1F1F2}"},{code:"CA",dialCode:"+1",name:"Canada",flag:"\u{1F1E8}\u{1F1E6}"},{code:"CF",dialCode:"+236",name:"Central African Republic",flag:"\u{1F1E8}\u{1F1EB}"},{code:"TD",dialCode:"+235",name:"Chad",flag:"\u{1F1F9}\u{1F1E9}"},{code:"CL",dialCode:"+56",name:"Chile",flag:"\u{1F1E8}\u{1F1F1}"},{code:"CN",dialCode:"+86",name:"China",flag:"\u{1F1E8}\u{1F1F3}"},{code:"CO",dialCode:"+57",name:"Colombia",flag:"\u{1F1E8}\u{1F1F4}"},{code:"KM",dialCode:"+269",name:"Comoros",flag:"\u{1F1F0}\u{1F1F2}"},{code:"CG",dialCode:"+242",name:"Congo",flag:"\u{1F1E8}\u{1F1EC}"},{code:"CD",dialCode:"+243",name:"Congo (DRC)",flag:"\u{1F1E8}\u{1F1E9}"},{code:"CR",dialCode:"+506",name:"Costa Rica",flag:"\u{1F1E8}\u{1F1F7}"},{code:"HR",dialCode:"+385",name:"Croatia",flag:"\u{1F1ED}\u{1F1F7}"},{code:"CU",dialCode:"+53",name:"Cuba",flag:"\u{1F1E8}\u{1F1FA}"},{code:"CY",dialCode:"+357",name:"Cyprus",flag:"\u{1F1E8}\u{1F1FE}"},{code:"CZ",dialCode:"+420",name:"Czechia",flag:"\u{1F1E8}\u{1F1FF}"},{code:"CI",dialCode:"+225",name:"Cote d'Ivoire",flag:"\u{1F1E8}\u{1F1EE}"},{code:"DK",dialCode:"+45",name:"Denmark",flag:"\u{1F1E9}\u{1F1F0}"},{code:"DJ",dialCode:"+253",name:"Djibouti",flag:"\u{1F1E9}\u{1F1EF}"},{code:"DM",dialCode:"+1",name:"Dominica",flag:"\u{1F1E9}\u{1F1F2}"},{code:"DO",dialCode:"+1",name:"Dominican Republic",flag:"\u{1F1E9}\u{1F1F4}"},{code:"EC",dialCode:"+593",name:"Ecuador",flag:"\u{1F1EA}\u{1F1E8}"},{code:"EG",dialCode:"+20",name:"Egypt",flag:"\u{1F1EA}\u{1F1EC}"},{code:"SV",dialCode:"+503",name:"El Salvador",flag:"\u{1F1F8}\u{1F1FB}"},{code:"GQ",dialCode:"+240",name:"Equatorial Guinea",flag:"\u{1F1EC}\u{1F1F6}"},{code:"ER",dialCode:"+291",name:"Eritrea",flag:"\u{1F1EA}\u{1F1F7}"},{code:"EE",dialCode:"+372",name:"Estonia",flag:"\u{1F1EA}\u{1F1EA}"},{code:"SZ",dialCode:"+268",name:"Eswatini",flag:"\u{1F1F8}\u{1F1FF}"},{code:"ET",dialCode:"+251",name:"Ethiopia",flag:"\u{1F1EA}\u{1F1F9}"},{code:"FJ",dialCode:"+679",name:"Fiji",flag:"\u{1F1EB}\u{1F1EF}"},{code:"FI",dialCode:"+358",name:"Finland",flag:"\u{1F1EB}\u{1F1EE}"},{code:"FR",dialCode:"+33",name:"France",flag:"\u{1F1EB}\u{1F1F7}"},{code:"GA",dialCode:"+241",name:"Gabon",flag:"\u{1F1EC}\u{1F1E6}"},{code:"GM",dialCode:"+220",name:"Gambia",flag:"\u{1F1EC}\u{1F1F2}"},{code:"GE",dialCode:"+995",name:"Georgia",flag:"\u{1F1EC}\u{1F1EA}"},{code:"DE",dialCode:"+49",name:"Germany",flag:"\u{1F1E9}\u{1F1EA}"},{code:"GH",dialCode:"+233",name:"Ghana",flag:"\u{1F1EC}\u{1F1ED}"},{code:"GR",dialCode:"+30",name:"Greece",flag:"\u{1F1EC}\u{1F1F7}"},{code:"GD",dialCode:"+1",name:"Grenada",flag:"\u{1F1EC}\u{1F1E9}"},{code:"GT",dialCode:"+502",name:"Guatemala",flag:"\u{1F1EC}\u{1F1F9}"},{code:"GN",dialCode:"+224",name:"Guinea",flag:"\u{1F1EC}\u{1F1F3}"},{code:"GW",dialCode:"+245",name:"Guinea-Bissau",flag:"\u{1F1EC}\u{1F1FC}"},{code:"GY",dialCode:"+592",name:"Guyana",flag:"\u{1F1EC}\u{1F1FE}"},{code:"HT",dialCode:"+509",name:"Haiti",flag:"\u{1F1ED}\u{1F1F9}"},{code:"HN",dialCode:"+504",name:"Honduras",flag:"\u{1F1ED}\u{1F1F3}"},{code:"HK",dialCode:"+852",name:"Hong Kong",flag:"\u{1F1ED}\u{1F1F0}"},{code:"HU",dialCode:"+36",name:"Hungary",flag:"\u{1F1ED}\u{1F1FA}"},{code:"IS",dialCode:"+354",name:"Iceland",flag:"\u{1F1EE}\u{1F1F8}"},{code:"IN",dialCode:"+91",name:"India",flag:"\u{1F1EE}\u{1F1F3}"},{code:"ID",dialCode:"+62",name:"Indonesia",flag:"\u{1F1EE}\u{1F1E9}"},{code:"IR",dialCode:"+98",name:"Iran",flag:"\u{1F1EE}\u{1F1F7}"},{code:"IQ",dialCode:"+964",name:"Iraq",flag:"\u{1F1EE}\u{1F1F6}"},{code:"IE",dialCode:"+353",name:"Ireland",flag:"\u{1F1EE}\u{1F1EA}"},{code:"IL",dialCode:"+972",name:"Israel",flag:"\u{1F1EE}\u{1F1F1}"},{code:"IT",dialCode:"+39",name:"Italy",flag:"\u{1F1EE}\u{1F1F9}"},{code:"JM",dialCode:"+1",name:"Jamaica",flag:"\u{1F1EF}\u{1F1F2}"},{code:"JP",dialCode:"+81",name:"Japan",flag:"\u{1F1EF}\u{1F1F5}"},{code:"JO",dialCode:"+962",name:"Jordan",flag:"\u{1F1EF}\u{1F1F4}"},{code:"KZ",dialCode:"+7",name:"Kazakhstan",flag:"\u{1F1F0}\u{1F1FF}"},{code:"KE",dialCode:"+254",name:"Kenya",flag:"\u{1F1F0}\u{1F1EA}"},{code:"KI",dialCode:"+686",name:"Kiribati",flag:"\u{1F1F0}\u{1F1EE}"},{code:"KW",dialCode:"+965",name:"Kuwait",flag:"\u{1F1F0}\u{1F1FC}"},{code:"KG",dialCode:"+996",name:"Kyrgyzstan",flag:"\u{1F1F0}\u{1F1EC}"},{code:"LA",dialCode:"+856",name:"Laos",flag:"\u{1F1F1}\u{1F1E6}"},{code:"LV",dialCode:"+371",name:"Latvia",flag:"\u{1F1F1}\u{1F1FB}"},{code:"LB",dialCode:"+961",name:"Lebanon",flag:"\u{1F1F1}\u{1F1E7}"},{code:"LS",dialCode:"+266",name:"Lesotho",flag:"\u{1F1F1}\u{1F1F8}"},{code:"LR",dialCode:"+231",name:"Liberia",flag:"\u{1F1F1}\u{1F1F7}"},{code:"LY",dialCode:"+218",name:"Libya",flag:"\u{1F1F1}\u{1F1FE}"},{code:"LI",dialCode:"+423",name:"Liechtenstein",flag:"\u{1F1F1}\u{1F1EE}"},{code:"LT",dialCode:"+370",name:"Lithuania",flag:"\u{1F1F1}\u{1F1F9}"},{code:"LU",dialCode:"+352",name:"Luxembourg",flag:"\u{1F1F1}\u{1F1FA}"},{code:"MO",dialCode:"+853",name:"Macao",flag:"\u{1F1F2}\u{1F1F4}"},{code:"MG",dialCode:"+261",name:"Madagascar",flag:"\u{1F1F2}\u{1F1EC}"},{code:"MW",dialCode:"+265",name:"Malawi",flag:"\u{1F1F2}\u{1F1FC}"},{code:"MY",dialCode:"+60",name:"Malaysia",flag:"\u{1F1F2}\u{1F1FE}"},{code:"MV",dialCode:"+960",name:"Maldives",flag:"\u{1F1F2}\u{1F1FB}"},{code:"ML",dialCode:"+223",name:"Mali",flag:"\u{1F1F2}\u{1F1F1}"},{code:"MT",dialCode:"+356",name:"Malta",flag:"\u{1F1F2}\u{1F1F9}"},{code:"MH",dialCode:"+692",name:"Marshall Islands",flag:"\u{1F1F2}\u{1F1ED}"},{code:"MR",dialCode:"+222",name:"Mauritania",flag:"\u{1F1F2}\u{1F1F7}"},{code:"MU",dialCode:"+230",name:"Mauritius",flag:"\u{1F1F2}\u{1F1FA}"},{code:"MX",dialCode:"+52",name:"Mexico",flag:"\u{1F1F2}\u{1F1FD}"},{code:"FM",dialCode:"+691",name:"Micronesia",flag:"\u{1F1EB}\u{1F1F2}"},{code:"MD",dialCode:"+373",name:"Moldova",flag:"\u{1F1F2}\u{1F1E9}"},{code:"MC",dialCode:"+377",name:"Monaco",flag:"\u{1F1F2}\u{1F1E8}"},{code:"MN",dialCode:"+976",name:"Mongolia",flag:"\u{1F1F2}\u{1F1F3}"},{code:"ME",dialCode:"+382",name:"Montenegro",flag:"\u{1F1F2}\u{1F1EA}"},{code:"MA",dialCode:"+212",name:"Morocco",flag:"\u{1F1F2}\u{1F1E6}"},{code:"MZ",dialCode:"+258",name:"Mozambique",flag:"\u{1F1F2}\u{1F1FF}"},{code:"MM",dialCode:"+95",name:"Myanmar",flag:"\u{1F1F2}\u{1F1F2}"},{code:"NA",dialCode:"+264",name:"Namibia",flag:"\u{1F1F3}\u{1F1E6}"},{code:"NR",dialCode:"+674",name:"Nauru",flag:"\u{1F1F3}\u{1F1F7}"},{code:"NP",dialCode:"+977",name:"Nepal",flag:"\u{1F1F3}\u{1F1F5}"},{code:"NL",dialCode:"+31",name:"Netherlands",flag:"\u{1F1F3}\u{1F1F1}"},{code:"NZ",dialCode:"+64",name:"New Zealand",flag:"\u{1F1F3}\u{1F1FF}"},{code:"NI",dialCode:"+505",name:"Nicaragua",flag:"\u{1F1F3}\u{1F1EE}"},{code:"NE",dialCode:"+227",name:"Niger",flag:"\u{1F1F3}\u{1F1EA}"},{code:"NG",dialCode:"+234",name:"Nigeria",flag:"\u{1F1F3}\u{1F1EC}"},{code:"KP",dialCode:"+850",name:"North Korea",flag:"\u{1F1F0}\u{1F1F5}"},{code:"MK",dialCode:"+389",name:"North Macedonia",flag:"\u{1F1F2}\u{1F1F0}"},{code:"NO",dialCode:"+47",name:"Norway",flag:"\u{1F1F3}\u{1F1F4}"},{code:"OM",dialCode:"+968",name:"Oman",flag:"\u{1F1F4}\u{1F1F2}"},{code:"PK",dialCode:"+92",name:"Pakistan",flag:"\u{1F1F5}\u{1F1F0}"},{code:"PW",dialCode:"+680",name:"Palau",flag:"\u{1F1F5}\u{1F1FC}"},{code:"PS",dialCode:"+970",name:"Palestine",flag:"\u{1F1F5}\u{1F1F8}"},{code:"PA",dialCode:"+507",name:"Panama",flag:"\u{1F1F5}\u{1F1E6}"},{code:"PG",dialCode:"+675",name:"Papua New Guinea",flag:"\u{1F1F5}\u{1F1EC}"},{code:"PY",dialCode:"+595",name:"Paraguay",flag:"\u{1F1F5}\u{1F1FE}"},{code:"PE",dialCode:"+51",name:"Peru",flag:"\u{1F1F5}\u{1F1EA}"},{code:"PH",dialCode:"+63",name:"Philippines",flag:"\u{1F1F5}\u{1F1ED}"},{code:"PL",dialCode:"+48",name:"Poland",flag:"\u{1F1F5}\u{1F1F1}"},{code:"PT",dialCode:"+351",name:"Portugal",flag:"\u{1F1F5}\u{1F1F9}"},{code:"PR",dialCode:"+1",name:"Puerto Rico",flag:"\u{1F1F5}\u{1F1F7}"},{code:"QA",dialCode:"+974",name:"Qatar",flag:"\u{1F1F6}\u{1F1E6}"},{code:"RO",dialCode:"+40",name:"Romania",flag:"\u{1F1F7}\u{1F1F4}"},{code:"RU",dialCode:"+7",name:"Russia",flag:"\u{1F1F7}\u{1F1FA}"},{code:"RW",dialCode:"+250",name:"Rwanda",flag:"\u{1F1F7}\u{1F1FC}"},{code:"KN",dialCode:"+1",name:"Saint Kitts and Nevis",flag:"\u{1F1F0}\u{1F1F3}"},{code:"LC",dialCode:"+1",name:"Saint Lucia",flag:"\u{1F1F1}\u{1F1E8}"},{code:"VC",dialCode:"+1",name:"Saint Vincent and the Grenadines",flag:"\u{1F1FB}\u{1F1E8}"},{code:"WS",dialCode:"+685",name:"Samoa",flag:"\u{1F1FC}\u{1F1F8}"},{code:"SM",dialCode:"+378",name:"San Marino",flag:"\u{1F1F8}\u{1F1F2}"},{code:"ST",dialCode:"+239",name:"Sao Tome and Principe",flag:"\u{1F1F8}\u{1F1F9}"},{code:"SA",dialCode:"+966",name:"Saudi Arabia",flag:"\u{1F1F8}\u{1F1E6}"},{code:"SN",dialCode:"+221",name:"Senegal",flag:"\u{1F1F8}\u{1F1F3}"},{code:"RS",dialCode:"+381",name:"Serbia",flag:"\u{1F1F7}\u{1F1F8}"},{code:"SC",dialCode:"+248",name:"Seychelles",flag:"\u{1F1F8}\u{1F1E8}"},{code:"SL",dialCode:"+232",name:"Sierra Leone",flag:"\u{1F1F8}\u{1F1F1}"},{code:"SG",dialCode:"+65",name:"Singapore",flag:"\u{1F1F8}\u{1F1EC}"},{code:"SK",dialCode:"+421",name:"Slovakia",flag:"\u{1F1F8}\u{1F1F0}"},{code:"SI",dialCode:"+386",name:"Slovenia",flag:"\u{1F1F8}\u{1F1EE}"},{code:"SB",dialCode:"+677",name:"Solomon Islands",flag:"\u{1F1F8}\u{1F1E7}"},{code:"SO",dialCode:"+252",name:"Somalia",flag:"\u{1F1F8}\u{1F1F4}"},{code:"ZA",dialCode:"+27",name:"South Africa",flag:"\u{1F1FF}\u{1F1E6}"},{code:"KR",dialCode:"+82",name:"South Korea",flag:"\u{1F1F0}\u{1F1F7}"},{code:"SS",dialCode:"+211",name:"South Sudan",flag:"\u{1F1F8}\u{1F1F8}"},{code:"ES",dialCode:"+34",name:"Spain",flag:"\u{1F1EA}\u{1F1F8}"},{code:"LK",dialCode:"+94",name:"Sri Lanka",flag:"\u{1F1F1}\u{1F1F0}"},{code:"SD",dialCode:"+249",name:"Sudan",flag:"\u{1F1F8}\u{1F1E9}"},{code:"SR",dialCode:"+597",name:"Suriname",flag:"\u{1F1F8}\u{1F1F7}"},{code:"SE",dialCode:"+46",name:"Sweden",flag:"\u{1F1F8}\u{1F1EA}"},{code:"CH",dialCode:"+41",name:"Switzerland",flag:"\u{1F1E8}\u{1F1ED}"},{code:"SY",dialCode:"+963",name:"Syria",flag:"\u{1F1F8}\u{1F1FE}"},{code:"TW",dialCode:"+886",name:"Taiwan",flag:"\u{1F1F9}\u{1F1FC}"},{code:"TJ",dialCode:"+992",name:"Tajikistan",flag:"\u{1F1F9}\u{1F1EF}"},{code:"TZ",dialCode:"+255",name:"Tanzania",flag:"\u{1F1F9}\u{1F1FF}"},{code:"TH",dialCode:"+66",name:"Thailand",flag:"\u{1F1F9}\u{1F1ED}"},{code:"TL",dialCode:"+670",name:"Timor-Leste",flag:"\u{1F1F9}\u{1F1F1}"},{code:"TG",dialCode:"+228",name:"Togo",flag:"\u{1F1F9}\u{1F1EC}"},{code:"TO",dialCode:"+676",name:"Tonga",flag:"\u{1F1F9}\u{1F1F4}"},{code:"TT",dialCode:"+1",name:"Trinidad and Tobago",flag:"\u{1F1F9}\u{1F1F9}"},{code:"TN",dialCode:"+216",name:"Tunisia",flag:"\u{1F1F9}\u{1F1F3}"},{code:"TR",dialCode:"+90",name:"Turkey",flag:"\u{1F1F9}\u{1F1F7}"},{code:"TM",dialCode:"+993",name:"Turkmenistan",flag:"\u{1F1F9}\u{1F1F2}"},{code:"TV",dialCode:"+688",name:"Tuvalu",flag:"\u{1F1F9}\u{1F1FB}"},{code:"UG",dialCode:"+256",name:"Uganda",flag:"\u{1F1FA}\u{1F1EC}"},{code:"UA",dialCode:"+380",name:"Ukraine",flag:"\u{1F1FA}\u{1F1E6}"},{code:"AE",dialCode:"+971",name:"United Arab Emirates",flag:"\u{1F1E6}\u{1F1EA}"},{code:"GB",dialCode:"+44",name:"United Kingdom",flag:"\u{1F1EC}\u{1F1E7}"},{code:"US",dialCode:"+1",name:"United States",flag:"\u{1F1FA}\u{1F1F8}"},{code:"UY",dialCode:"+598",name:"Uruguay",flag:"\u{1F1FA}\u{1F1FE}"},{code:"UZ",dialCode:"+998",name:"Uzbekistan",flag:"\u{1F1FA}\u{1F1FF}"},{code:"VU",dialCode:"+678",name:"Vanuatu",flag:"\u{1F1FB}\u{1F1FA}"},{code:"VA",dialCode:"+39",name:"Vatican City",flag:"\u{1F1FB}\u{1F1E6}"},{code:"VE",dialCode:"+58",name:"Venezuela",flag:"\u{1F1FB}\u{1F1EA}"},{code:"VN",dialCode:"+84",name:"Vietnam",flag:"\u{1F1FB}\u{1F1F3}"},{code:"YE",dialCode:"+967",name:"Yemen",flag:"\u{1F1FE}\u{1F1EA}"},{code:"ZM",dialCode:"+260",name:"Zambia",flag:"\u{1F1FF}\u{1F1F2}"},{code:"ZW",dialCode:"+263",name:"Zimbabwe",flag:"\u{1F1FF}\u{1F1FC}"}],et=new Map(D.map(e=>[e.code,e])),tt={"America/New_York":"US","America/Chicago":"US","America/Denver":"US","America/Los_Angeles":"US","America/Anchorage":"US","Pacific/Honolulu":"US","America/Phoenix":"US","America/Indiana/Indianapolis":"US","America/Toronto":"CA","America/Vancouver":"CA","America/Edmonton":"CA","America/Winnipeg":"CA","America/Halifax":"CA","America/St_Johns":"CA","Europe/London":"GB","Europe/Dublin":"IE","Europe/Paris":"FR","Europe/Berlin":"DE","Europe/Madrid":"ES","Europe/Rome":"IT","Europe/Amsterdam":"NL","Europe/Brussels":"BE","Europe/Zurich":"CH","Europe/Vienna":"AT","Europe/Stockholm":"SE","Europe/Oslo":"NO","Europe/Copenhagen":"DK","Europe/Helsinki":"FI","Europe/Warsaw":"PL","Europe/Prague":"CZ","Europe/Bucharest":"RO","Europe/Budapest":"HU","Europe/Athens":"GR","Europe/Istanbul":"TR","Europe/Moscow":"RU","Europe/Kiev":"UA","Europe/Lisbon":"PT","Europe/Belgrade":"RS","Europe/Zagreb":"HR","Europe/Bratislava":"SK","Europe/Ljubljana":"SI","Europe/Tallinn":"EE","Europe/Riga":"LV","Europe/Vilnius":"LT","Asia/Tokyo":"JP","Asia/Seoul":"KR","Asia/Shanghai":"CN","Asia/Hong_Kong":"HK","Asia/Taipei":"TW","Asia/Singapore":"SG","Asia/Kolkata":"IN","Asia/Karachi":"PK","Asia/Dhaka":"BD","Asia/Bangkok":"TH","Asia/Jakarta":"ID","Asia/Manila":"PH","Asia/Kuala_Lumpur":"MY","Asia/Ho_Chi_Minh":"VN","Asia/Riyadh":"SA","Asia/Dubai":"AE","Asia/Tehran":"IR","Asia/Baghdad":"IQ","Asia/Beirut":"LB","Asia/Jerusalem":"IL","Asia/Amman":"JO","Asia/Almaty":"KZ","Asia/Tashkent":"UZ","Asia/Colombo":"LK","Asia/Kathmandu":"NP","Asia/Yangon":"MM","Australia/Sydney":"AU","Australia/Melbourne":"AU","Australia/Brisbane":"AU","Australia/Perth":"AU","Australia/Adelaide":"AU","Pacific/Auckland":"NZ","Pacific/Fiji":"FJ","Africa/Cairo":"EG","Africa/Lagos":"NG","Africa/Nairobi":"KE","Africa/Johannesburg":"ZA","Africa/Casablanca":"MA","Africa/Accra":"GH","Africa/Addis_Ababa":"ET","Africa/Dar_es_Salaam":"TZ","Africa/Kampala":"UG","America/Mexico_City":"MX","America/Bogota":"CO","America/Lima":"PE","America/Santiago":"CL","America/Buenos_Aires":"AR","America/Sao_Paulo":"BR","America/Caracas":"VE","America/Guatemala":"GT","America/Havana":"CU","America/Panama":"PA","America/Jamaica":"JM"};function he(){try{let e=Intl.DateTimeFormat().resolvedOptions().timeZone;return tt[e]??"US"}catch{return"US"}}function Ce(e){if(!e.startsWith("+"))return e;let t=e.slice(1);if(t.startsWith("1")&&t.length===11){let n=t.slice(1,4),a=t.slice(4,7),o=t.slice(7);return`+1 (${n}) ${a}-${o}`}for(let n=4;n>=1;n--){let a="+"+t.slice(0,n),o=D.find(r=>r.dialCode===a);if(o){let r=t.slice(n);return`${o.dialCode} ${r}`}}return e}function ye(e,t){let n=e.replace(/\D/g,""),a=et.get(t);if(!a)return"+"+n;let o=a.dialCode.slice(1);return n.startsWith(o)?"+"+n:a.dialCode+n}function Ae(e){return/^\+[1-9]\d{6,14}$/.test(e)}function Ee(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}async function y(e,t,n){let o={Authorization:`Bearer ${s().token}`};n!==void 0&&(o["Content-Type"]="application/json");let r=await fetch(e,{method:t,headers:o,...n!==void 0&&{body:JSON.stringify(n)}});if(!r.ok){let i=`Auth request failed: ${r.status} ${r.statusText}`,c="auth_error";try{let d=await r.json();d.error&&(i=d.error),d.code&&(c=d.code)}catch{}throw new l(i,c,r.status)}return await r.json()}var G=new Set;function P(e){me({token:e.token,user:e.user,methods:e.methods,visitorId:e.visitorId}),G.forEach(t=>t(e.user))}function H(e){if(!e.user)throw new l("Verification succeeded but no user was returned","auth_error");return e.user}function Te(e){let t=s();t.user&&(Object.assign(t.user,e),G.forEach(n=>n(t.user)))}var ot={get currentUser(){return s().user},getCurrentUser(){return s().user},isAuthenticated(){return s().user!==null},get currentVisitorId(){return s().visitorId??null},getCurrentVisitorId(){return s().visitorId??null},sendEmailCode(e){return y("/_/auth/email/send","POST",{email:e})},async verifyEmailCode(e,t){let n=await y("/_/auth/email/verify","POST",{verificationId:e,code:t});return P(n),H(n)},sendSmsCode(e){return y("/_/auth/sms/send","POST",{phone:e})},async verifySmsCode(e,t){let n=await y("/_/auth/sms/verify","POST",{verificationId:e,code:t});return P(n),H(n)},async requestEmailChange(e){await y("/_/auth/email/change","POST",{newEmail:e})},async confirmEmailChange(e,t){let n=await y("/_/auth/email/change/confirm","POST",{newEmail:e,code:t});return P(n),H(n)},async requestPhoneChange(e){await y("/_/auth/phone/change","POST",{newPhone:e})},async confirmPhoneChange(e,t){let n=await y("/_/auth/phone/change/confirm","POST",{newPhone:e,code:t});return P(n),H(n)},async logout(){let e=await y("/_/auth/logout","POST",{});P(e)},async createApiKey(){let e=await y("/_/auth/api-key/create","POST",{});return Te({apiKey:e.apiKey}),{key:e.key}},async revokeApiKey(){await y("/_/auth/api-key/revoke","POST",{}),Te({apiKey:null})},onAuthStateChanged(e){return G.add(e),e(s().user),()=>{G.delete(e)}},phone:{countries:D,detectCountry:he,format:Ce,toE164:ye,isValid:Ae},email:{isValid:Ee}};typeof window<"u"&&globalThis.__MINDSTUDIO__&&setTimeout(()=>{try{s()}catch{}},0);export{l as MindStudioInterfaceError,De as analytics,ot as auth,Ye as createAgentChatClient,ze as createClient,We as platform};
|
|
1
|
+
var l=class extends Error{code;status;constructor(t,n,o){super(t),this.name="MindStudioInterfaceError",this.code=n,this.status=o}};var Ie="/_/telemetry/";var O=[];function v(e){O.push(e),O.length>20&&O.shift()}function j(){return O.slice()}function te(e){return e.includes(Ie)}function Be(e){return typeof e=="string"?e:e instanceof URL?e.href:e.url||String(e)}var D="",F=new Set;function ne(e){return F.add(e),()=>{F.delete(e)}}function x(e){e!==D&&(v({type:"navigation",from:D,to:e,timestamp:Date.now()}),D=e,F.forEach(t=>{try{t(e)}catch{}}))}function Le(){let e=window;if(e.__ms_history_patched)return;e.__ms_history_patched=!0,D=location.href;let t=history.pushState.bind(history);history.pushState=function(o,a,r){t(o,a,r);try{x(location.href)}catch{}};let n=history.replaceState.bind(history);history.replaceState=function(o,a,r){n(o,a,r);try{x(location.href)}catch{}},window.addEventListener("popstate",()=>{try{x(location.href)}catch{}}),window.addEventListener("hashchange",()=>{try{x(location.href)}catch{}})}function xe(e){if(!window.fetch||window.fetch.__ms_patched)return;let n=window.fetch.bind(window),o=function(a,r){let i=Be(a);if(te(i))return n(a,r);let c=(r?.method||(typeof a!="string"&&!(a instanceof URL)?a.method:"")||"GET").toUpperCase(),s=Date.now();return n(a,r).then(g=>{let u={type:"fetch",method:c,url:i,status:g.status,ok:g.ok,duration:Date.now()-s,timestamp:s};if(!g.ok&&e)try{g.clone().text().then(m=>{u.body=m.slice(0,1024),v(u)}).catch(()=>v(u))}catch{v(u)}else v(u);return g},g=>{throw v({type:"fetch",method:c,url:i,ok:!1,duration:Date.now()-s,timestamp:s,error:g instanceof Error?g.message:String(g??"fetch failed")}),g})};o.__ms_patched=!0,window.fetch=o}function Oe(){if(XMLHttpRequest.prototype.open.__ms_patched)return;let t=XMLHttpRequest.prototype.open,n=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(o,a,...r){return this.__ms_method=(o||"GET").toUpperCase(),this.__ms_url=String(a),t.apply(this,[o,a,...r])},XMLHttpRequest.prototype.send=function(o){let a=this.__ms_method||"GET",r=this.__ms_url||"";if(te(r))return n.apply(this,[o]);let i=Date.now();return this.addEventListener("loadend",function(){v({type:"xhr",method:a,url:r,status:this.status,ok:this.status>=200&&this.status<300,duration:Date.now()-i,timestamp:i})},{once:!0}),n.apply(this,[o])},XMLHttpRequest.prototype.open.__ms_patched=!0}var ee=!1;function ae(e){if(!ee){ee=!0;try{Le()}catch{}try{xe(e.captureResponseBodies)}catch{}try{Oe()}catch{}}}var se="/_/telemetry/events",De=1e3,Ne=100,He=6e4,S=[],V=null,J=0,de=!1;function le(e){de||S.length>=Ne||(S.push(e),Ge())}function Ge(){V||S.length===0||(V=setTimeout(()=>{V=null,$e()},De))}function ce(){let e=S;return S=[],e}async function $e(){if(S.length===0)return;if(Date.now()<J){S=[];return}let e;try{e=d()}catch{S=[];return}let t=ce();try{let n=await fetch(se,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.token}`},body:JSON.stringify({events:t})});if(n.status===429){let o=n.headers.get("Retry-After"),a=o?parseInt(o,10):NaN,r=Number.isFinite(a)&&a>0?a*1e3:He;J=Date.now()+r}}catch{}}function oe(){if(S.length===0)return;if(Date.now()<J){S=[];return}let e;try{e=d()}catch{S=[];return}let t=ce();try{fetch(se,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.token}`},body:JSON.stringify({events:t}),keepalive:!0})}catch{}}function Ke(e){if(!e)return;let t={};for(let[n,o]of Object.entries(e))(typeof o=="string"||typeof o=="number"||typeof o=="boolean")&&(t[n]=o);return Object.keys(t).length>0?t:void 0}function re(e){try{let t=d();le({type:"pageview",releaseId:t.releaseId,url:e,referrer:document.referrer,userAgent:navigator.userAgent,language:navigator.language,screen:{w:window.innerWidth,h:window.innerHeight},timestamp:Date.now()})}catch{}}function Fe(e,t){try{let n=d();le({type:"event",releaseId:n.releaseId,name:e,url:location.href,timestamp:Date.now(),props:Ke(t)})}catch{}}var je="/_/telemetry/presence",Ve=1e4,qe=3e4,k=null,_=null,H=1e3,b=!1;function q(){let e=H;H=Math.min(H*2,Ve);let t=Math.random()*250;return e+t}function N(e){_&&clearTimeout(_),_=setTimeout(()=>{_=null,b&&ue()},e)}function Je(){if(b=!1,_&&(clearTimeout(_),_=null),k){try{k.abort()}catch{}k=null}}async function ue(){if(!b)return;let e;try{e=d()}catch{b=!1;return}k=new AbortController;let t=k.signal;try{let n=await fetch(je,{method:"GET",headers:{Authorization:`Bearer ${e.token}`,Accept:"text/event-stream"},signal:t});if(n.status===503){let a=n.headers.get("Retry-After"),r=a?parseInt(a,10):NaN,i=Number.isFinite(r)&&r>0?r*1e3:qe;N(i);return}if(n.status===401){b=!1;return}if(!n.ok||!n.body){N(q());return}H=1e3;let o=n.body.getReader();for(;b;){let{done:a}=await o.read();if(a)break}b&&N(q())}catch(n){let o=n?.name;b&&o!=="AbortError"&&N(q())}}var We={track:Fe},ie=!1;function Ye(){if(ie||typeof window>"u")return;let e;try{e=d()}catch{return}if(e.telemetry?.analytics===!1)return;ie=!0;let t=()=>{de=!0,oe(),Je()};window.addEventListener("pagehide",t),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&oe()}),ne(n=>{re(n)}),re(location.href),b=!0,ue()}function ge(){try{Ye()}catch{}}var pe="/_/telemetry/errors",Ze=1e3,ze=50,Xe=6e4,fe=!1,A=[],W=null,Y=0,he=!1;function Qe(e,t){let n=t.split(`
|
|
2
|
+
`)[1]??"";return`${e}|${n.trim()}`}function Ce(e){if(he)return;let t=Qe(e.message,e.stack);for(let n of A)if(n._fp===t){n.count=(n.count??1)+1;return}A.length>=ze||(e._fp=t,A.push(e),et())}function et(){W||A.length===0||(W=setTimeout(()=>{W=null,tt()},Ze))}function ye(){let e=A;return A=[],e.map(({_fp:t,...n})=>n)}async function tt(){if(A.length===0)return;if(Date.now()<Y){A=[];return}let e=(()=>{try{return d()}catch{return null}})();if(!e){A=[];return}let t=ye();try{let n=await fetch(pe,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.token}`},body:JSON.stringify({events:t})});if(n.status===429){let o=n.headers.get("Retry-After"),a=o?parseInt(o,10):NaN,r=Number.isFinite(a)&&a>0?a*1e3:Xe;Y=Date.now()+r}}catch{}}function me(){if(A.length===0)return;if(Date.now()<Y){A=[];return}let e=null;try{e=d()}catch{A=[];return}let t=ye();try{fetch(pe,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.token}`},body:JSON.stringify({events:t}),keepalive:!0})}catch{}}function nt(e){try{let t=d();Ce({releaseId:t.releaseId,url:location.href,userAgent:navigator.userAgent,timestamp:Date.now(),type:"error",message:e.message||"Unknown error",stack:e.error?.stack??"",source:e.filename||void 0,line:typeof e.lineno=="number"?e.lineno:void 0,column:typeof e.colno=="number"?e.colno:void 0,breadcrumbs:j()})}catch{}}function at(e){try{let t=d(),n=e.reason,o,a="";n&&typeof n=="object"?(o=n.message||String(n),a=n.stack??""):o=String(n??"Unhandled rejection"),Ce({releaseId:t.releaseId,url:location.href,userAgent:navigator.userAgent,timestamp:Date.now(),type:"unhandledrejection",message:o,stack:a,breadcrumbs:j()})}catch{}}function ot(){if(fe||typeof window>"u")return;let e;try{e=d()}catch{return}if(e.telemetry?.errors===!1)return;fe=!0,ae({captureResponseBodies:!!e.telemetryCaptureResponseBodies}),window.addEventListener("error",nt),window.addEventListener("unhandledrejection",at);let t=()=>{he=!0,me()};window.addEventListener("pagehide",t),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&me()})}function Ae(){try{ot()}catch{}}var G;function d(){if(G)return G;let e=globalThis.__MINDSTUDIO__;if(!e)throw new l("@mindstudio-ai/interface requires the MindStudio platform context. This page must be loaded inside MindStudio (window.__MINDSTUDIO__ is missing).","not_initialized");if(!e.token||!e.releaseId||!e.methods){let t=["token","releaseId","methods"].filter(n=>!e[n]).join(", ");throw new l(`MindStudio platform context is incomplete. Missing: ${t}`,"invalid_config")}return G=e,Ae(),ge(),G}function we(e){let t=d();e.token!==void 0&&(t.token=e.token),e.user!==void 0&&(t.user=e.user),e.methods!==void 0&&(t.methods=e.methods),e.visitorId!==void 0&&(t.visitorId=e.visitorId)}function rt(){return new Proxy({},{get(e,t){return async(n,o)=>{let a=d(),r=a.methods[t];if(!r)throw new l(`Method "${t}" not found. Available methods: ${Object.keys(a.methods).join(", ")||"(none)"}`,"method_not_found");let i=`/_/methods/${r}/invoke`,c=o?.stream===!0,s=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a.token}`},body:JSON.stringify({input:n??{},...c&&{stream:!0}})});if(!s.ok){let p=`Method "${t}" failed: ${s.status} ${s.statusText}`,h="method_error";try{let f=await s.json();f.error&&(p=f.error),f.code&&(h=f.code)}catch{}throw new l(p,h,s.status)}if(!c)return(await s.json()).output;let g=s.body.getReader(),u=new TextDecoder,m="",E,w;for(;;){let{done:p,value:h}=await g.read();if(p)break;m+=u.decode(h,{stream:!0});let f=m.split(`
|
|
3
|
+
`);m=f.pop()??"";for(let T of f){if(!T.startsWith("data: "))continue;let B=T.slice(6);try{let C=JSON.parse(B);C.type==="token"&&o?.onToken&&C.text?o.onToken(C.text):C.type==="data"&&o?.onStreamData?o.onStreamData(C.data):C.type==="error"&&C.error?(w=C.error,o?.onStreamError&&o.onStreamError(C.error)):C.type==="done"&&(E=C.output)}catch{}}}if(E===void 0&&w!==void 0)throw new l(w,"method_error");if(E===void 0)throw new l("Stream ended without a done event","stream_incomplete");return E}}})}var Se="/_/agent";async function U(e,t,n){let a={Authorization:`Bearer ${d().token}`};n!==void 0&&(a["Content-Type"]="application/json");let r=await fetch(`${Se}${e}`,{method:t,headers:a,...n!==void 0&&{body:JSON.stringify(n)}});if(!r.ok){let i=`Agent chat request failed: ${r.status} ${r.statusText}`,c="agent_chat_error";try{let s=await r.json();s.error&&(i=s.error),s.code&&(c=s.code)}catch{}throw new l(i,c,r.status)}return await r.json()}function it(e,t){switch(t.onEvent?.(e),e.type){case"text":t.onText?.(e.text);break;case"thinking":t.onThinking?.(e.text);break;case"thinking_complete":t.onThinkingComplete?.(e.thinking,e.signature);break;case"tool_call_start":t.onToolCallStart?.(e.id,e.name);break;case"tool_call_result":t.onToolCallResult?.(e.id,e.output);break;case"error":t.onError?.(e.error);break}}function st(){return{createThread(){return U("/threads","POST")},listThreads(e){let t=e?`?cursor=${encodeURIComponent(e)}`:"";return U(`/threads${t}`,"GET")},getThread(e){return U(`/threads/${e}`,"GET")},async updateThread(e,t){await U(`/threads/${e}`,"PATCH",{title:t})},async deleteThread(e){await U(`/threads/${e}`,"DELETE")},sendMessage(e,t,n,o){let a=new AbortController,r=n??{};r.signal&&(r.signal.aborted?a.abort():r.signal.addEventListener("abort",()=>a.abort(),{once:!0}));let c=(async()=>{let s=d(),g=`${Se}/threads/${e}/messages`,u=await fetch(g,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s.token}`},body:JSON.stringify({content:t,...o?.attachments?.length&&{attachments:o.attachments}}),signal:a.signal});if(!u.ok){let h=`Send message failed: ${u.status} ${u.statusText}`,f="agent_chat_error";try{let T=await u.json();T.error&&(h=T.error),T.code&&(f=T.code)}catch{}throw new l(h,f,u.status)}let m=u.body.getReader(),E=new TextDecoder,w="",p;for(;;){let{done:h,value:f}=await m.read();if(h)break;w+=E.decode(f,{stream:!0});let T=w.split(`
|
|
4
|
+
`);w=T.pop()??"";for(let B of T){if(!B.startsWith("data: "))continue;let C=B.slice(6);try{let L=JSON.parse(C);L.type==="done"&&(p={stopReason:L.stopReason,usage:L.usage}),it(L,r)}catch{}}}if(!p)throw new l("Stream ended without a done event","stream_incomplete");return p})();return c.abort=()=>a.abort(),c}}}var dt={async uploadFile(e,t){let n=d(),{onProgress:o,signal:a}=t??{};a?.throwIfAborted();let i=await fetch("/_/generate-upload-request",{method:"POST",headers:{Authorization:`Bearer ${n.token}`,"Content-Type":"application/json"},body:JSON.stringify({filename:e.name,contentType:e.type||"application/octet-stream"}),signal:a});if(!i.ok)throw new l(`Upload presign failed: ${i.status} ${i.statusText}`,"upload_error",i.status);let{uploadUrl:c,uploadFields:s,publicUrl:g}=await i.json(),u=new FormData;for(let[E,w]of Object.entries(s))u.append(E,w);if(u.append("file",e),o)return await lt(c,u,o,a),g;let m=await fetch(c,{method:"POST",body:u,signal:a});if(!m.ok)throw new l(`File upload failed: ${m.status} ${m.statusText}`,"upload_error",m.status);return g}};function lt(e,t,n,o){return new Promise((a,r)=>{let i=new XMLHttpRequest;if(i.upload.addEventListener("progress",c=>{c.lengthComputable&&n(c.loaded/c.total)}),i.addEventListener("load",()=>{i.status>=200&&i.status<300?(n(1),a()):r(new l(`File upload failed: ${i.status} ${i.statusText}`,"upload_error",i.status))}),i.addEventListener("error",()=>{r(new l("File upload failed: network error","upload_error"))}),i.addEventListener("abort",()=>{r(new DOMException("Upload aborted","AbortError"))}),o){if(o.aborted){r(new DOMException("Upload aborted","AbortError"));return}o.addEventListener("abort",()=>i.abort(),{once:!0})}i.open("POST",e),i.send(t)})}var $=[{code:"AF",dialCode:"+93",name:"Afghanistan",flag:"\u{1F1E6}\u{1F1EB}"},{code:"AL",dialCode:"+355",name:"Albania",flag:"\u{1F1E6}\u{1F1F1}"},{code:"DZ",dialCode:"+213",name:"Algeria",flag:"\u{1F1E9}\u{1F1FF}"},{code:"AD",dialCode:"+376",name:"Andorra",flag:"\u{1F1E6}\u{1F1E9}"},{code:"AO",dialCode:"+244",name:"Angola",flag:"\u{1F1E6}\u{1F1F4}"},{code:"AG",dialCode:"+1",name:"Antigua and Barbuda",flag:"\u{1F1E6}\u{1F1EC}"},{code:"AR",dialCode:"+54",name:"Argentina",flag:"\u{1F1E6}\u{1F1F7}"},{code:"AM",dialCode:"+374",name:"Armenia",flag:"\u{1F1E6}\u{1F1F2}"},{code:"AU",dialCode:"+61",name:"Australia",flag:"\u{1F1E6}\u{1F1FA}"},{code:"AT",dialCode:"+43",name:"Austria",flag:"\u{1F1E6}\u{1F1F9}"},{code:"AZ",dialCode:"+994",name:"Azerbaijan",flag:"\u{1F1E6}\u{1F1FF}"},{code:"BS",dialCode:"+1",name:"Bahamas",flag:"\u{1F1E7}\u{1F1F8}"},{code:"BH",dialCode:"+973",name:"Bahrain",flag:"\u{1F1E7}\u{1F1ED}"},{code:"BD",dialCode:"+880",name:"Bangladesh",flag:"\u{1F1E7}\u{1F1E9}"},{code:"BB",dialCode:"+1",name:"Barbados",flag:"\u{1F1E7}\u{1F1E7}"},{code:"BY",dialCode:"+375",name:"Belarus",flag:"\u{1F1E7}\u{1F1FE}"},{code:"BE",dialCode:"+32",name:"Belgium",flag:"\u{1F1E7}\u{1F1EA}"},{code:"BZ",dialCode:"+501",name:"Belize",flag:"\u{1F1E7}\u{1F1FF}"},{code:"BJ",dialCode:"+229",name:"Benin",flag:"\u{1F1E7}\u{1F1EF}"},{code:"BT",dialCode:"+975",name:"Bhutan",flag:"\u{1F1E7}\u{1F1F9}"},{code:"BO",dialCode:"+591",name:"Bolivia",flag:"\u{1F1E7}\u{1F1F4}"},{code:"BA",dialCode:"+387",name:"Bosnia and Herzegovina",flag:"\u{1F1E7}\u{1F1E6}"},{code:"BW",dialCode:"+267",name:"Botswana",flag:"\u{1F1E7}\u{1F1FC}"},{code:"BR",dialCode:"+55",name:"Brazil",flag:"\u{1F1E7}\u{1F1F7}"},{code:"BN",dialCode:"+673",name:"Brunei",flag:"\u{1F1E7}\u{1F1F3}"},{code:"BG",dialCode:"+359",name:"Bulgaria",flag:"\u{1F1E7}\u{1F1EC}"},{code:"BF",dialCode:"+226",name:"Burkina Faso",flag:"\u{1F1E7}\u{1F1EB}"},{code:"BI",dialCode:"+257",name:"Burundi",flag:"\u{1F1E7}\u{1F1EE}"},{code:"CV",dialCode:"+238",name:"Cabo Verde",flag:"\u{1F1E8}\u{1F1FB}"},{code:"KH",dialCode:"+855",name:"Cambodia",flag:"\u{1F1F0}\u{1F1ED}"},{code:"CM",dialCode:"+237",name:"Cameroon",flag:"\u{1F1E8}\u{1F1F2}"},{code:"CA",dialCode:"+1",name:"Canada",flag:"\u{1F1E8}\u{1F1E6}"},{code:"CF",dialCode:"+236",name:"Central African Republic",flag:"\u{1F1E8}\u{1F1EB}"},{code:"TD",dialCode:"+235",name:"Chad",flag:"\u{1F1F9}\u{1F1E9}"},{code:"CL",dialCode:"+56",name:"Chile",flag:"\u{1F1E8}\u{1F1F1}"},{code:"CN",dialCode:"+86",name:"China",flag:"\u{1F1E8}\u{1F1F3}"},{code:"CO",dialCode:"+57",name:"Colombia",flag:"\u{1F1E8}\u{1F1F4}"},{code:"KM",dialCode:"+269",name:"Comoros",flag:"\u{1F1F0}\u{1F1F2}"},{code:"CG",dialCode:"+242",name:"Congo",flag:"\u{1F1E8}\u{1F1EC}"},{code:"CD",dialCode:"+243",name:"Congo (DRC)",flag:"\u{1F1E8}\u{1F1E9}"},{code:"CR",dialCode:"+506",name:"Costa Rica",flag:"\u{1F1E8}\u{1F1F7}"},{code:"HR",dialCode:"+385",name:"Croatia",flag:"\u{1F1ED}\u{1F1F7}"},{code:"CU",dialCode:"+53",name:"Cuba",flag:"\u{1F1E8}\u{1F1FA}"},{code:"CY",dialCode:"+357",name:"Cyprus",flag:"\u{1F1E8}\u{1F1FE}"},{code:"CZ",dialCode:"+420",name:"Czechia",flag:"\u{1F1E8}\u{1F1FF}"},{code:"CI",dialCode:"+225",name:"Cote d'Ivoire",flag:"\u{1F1E8}\u{1F1EE}"},{code:"DK",dialCode:"+45",name:"Denmark",flag:"\u{1F1E9}\u{1F1F0}"},{code:"DJ",dialCode:"+253",name:"Djibouti",flag:"\u{1F1E9}\u{1F1EF}"},{code:"DM",dialCode:"+1",name:"Dominica",flag:"\u{1F1E9}\u{1F1F2}"},{code:"DO",dialCode:"+1",name:"Dominican Republic",flag:"\u{1F1E9}\u{1F1F4}"},{code:"EC",dialCode:"+593",name:"Ecuador",flag:"\u{1F1EA}\u{1F1E8}"},{code:"EG",dialCode:"+20",name:"Egypt",flag:"\u{1F1EA}\u{1F1EC}"},{code:"SV",dialCode:"+503",name:"El Salvador",flag:"\u{1F1F8}\u{1F1FB}"},{code:"GQ",dialCode:"+240",name:"Equatorial Guinea",flag:"\u{1F1EC}\u{1F1F6}"},{code:"ER",dialCode:"+291",name:"Eritrea",flag:"\u{1F1EA}\u{1F1F7}"},{code:"EE",dialCode:"+372",name:"Estonia",flag:"\u{1F1EA}\u{1F1EA}"},{code:"SZ",dialCode:"+268",name:"Eswatini",flag:"\u{1F1F8}\u{1F1FF}"},{code:"ET",dialCode:"+251",name:"Ethiopia",flag:"\u{1F1EA}\u{1F1F9}"},{code:"FJ",dialCode:"+679",name:"Fiji",flag:"\u{1F1EB}\u{1F1EF}"},{code:"FI",dialCode:"+358",name:"Finland",flag:"\u{1F1EB}\u{1F1EE}"},{code:"FR",dialCode:"+33",name:"France",flag:"\u{1F1EB}\u{1F1F7}"},{code:"GA",dialCode:"+241",name:"Gabon",flag:"\u{1F1EC}\u{1F1E6}"},{code:"GM",dialCode:"+220",name:"Gambia",flag:"\u{1F1EC}\u{1F1F2}"},{code:"GE",dialCode:"+995",name:"Georgia",flag:"\u{1F1EC}\u{1F1EA}"},{code:"DE",dialCode:"+49",name:"Germany",flag:"\u{1F1E9}\u{1F1EA}"},{code:"GH",dialCode:"+233",name:"Ghana",flag:"\u{1F1EC}\u{1F1ED}"},{code:"GR",dialCode:"+30",name:"Greece",flag:"\u{1F1EC}\u{1F1F7}"},{code:"GD",dialCode:"+1",name:"Grenada",flag:"\u{1F1EC}\u{1F1E9}"},{code:"GT",dialCode:"+502",name:"Guatemala",flag:"\u{1F1EC}\u{1F1F9}"},{code:"GN",dialCode:"+224",name:"Guinea",flag:"\u{1F1EC}\u{1F1F3}"},{code:"GW",dialCode:"+245",name:"Guinea-Bissau",flag:"\u{1F1EC}\u{1F1FC}"},{code:"GY",dialCode:"+592",name:"Guyana",flag:"\u{1F1EC}\u{1F1FE}"},{code:"HT",dialCode:"+509",name:"Haiti",flag:"\u{1F1ED}\u{1F1F9}"},{code:"HN",dialCode:"+504",name:"Honduras",flag:"\u{1F1ED}\u{1F1F3}"},{code:"HK",dialCode:"+852",name:"Hong Kong",flag:"\u{1F1ED}\u{1F1F0}"},{code:"HU",dialCode:"+36",name:"Hungary",flag:"\u{1F1ED}\u{1F1FA}"},{code:"IS",dialCode:"+354",name:"Iceland",flag:"\u{1F1EE}\u{1F1F8}"},{code:"IN",dialCode:"+91",name:"India",flag:"\u{1F1EE}\u{1F1F3}"},{code:"ID",dialCode:"+62",name:"Indonesia",flag:"\u{1F1EE}\u{1F1E9}"},{code:"IR",dialCode:"+98",name:"Iran",flag:"\u{1F1EE}\u{1F1F7}"},{code:"IQ",dialCode:"+964",name:"Iraq",flag:"\u{1F1EE}\u{1F1F6}"},{code:"IE",dialCode:"+353",name:"Ireland",flag:"\u{1F1EE}\u{1F1EA}"},{code:"IL",dialCode:"+972",name:"Israel",flag:"\u{1F1EE}\u{1F1F1}"},{code:"IT",dialCode:"+39",name:"Italy",flag:"\u{1F1EE}\u{1F1F9}"},{code:"JM",dialCode:"+1",name:"Jamaica",flag:"\u{1F1EF}\u{1F1F2}"},{code:"JP",dialCode:"+81",name:"Japan",flag:"\u{1F1EF}\u{1F1F5}"},{code:"JO",dialCode:"+962",name:"Jordan",flag:"\u{1F1EF}\u{1F1F4}"},{code:"KZ",dialCode:"+7",name:"Kazakhstan",flag:"\u{1F1F0}\u{1F1FF}"},{code:"KE",dialCode:"+254",name:"Kenya",flag:"\u{1F1F0}\u{1F1EA}"},{code:"KI",dialCode:"+686",name:"Kiribati",flag:"\u{1F1F0}\u{1F1EE}"},{code:"KW",dialCode:"+965",name:"Kuwait",flag:"\u{1F1F0}\u{1F1FC}"},{code:"KG",dialCode:"+996",name:"Kyrgyzstan",flag:"\u{1F1F0}\u{1F1EC}"},{code:"LA",dialCode:"+856",name:"Laos",flag:"\u{1F1F1}\u{1F1E6}"},{code:"LV",dialCode:"+371",name:"Latvia",flag:"\u{1F1F1}\u{1F1FB}"},{code:"LB",dialCode:"+961",name:"Lebanon",flag:"\u{1F1F1}\u{1F1E7}"},{code:"LS",dialCode:"+266",name:"Lesotho",flag:"\u{1F1F1}\u{1F1F8}"},{code:"LR",dialCode:"+231",name:"Liberia",flag:"\u{1F1F1}\u{1F1F7}"},{code:"LY",dialCode:"+218",name:"Libya",flag:"\u{1F1F1}\u{1F1FE}"},{code:"LI",dialCode:"+423",name:"Liechtenstein",flag:"\u{1F1F1}\u{1F1EE}"},{code:"LT",dialCode:"+370",name:"Lithuania",flag:"\u{1F1F1}\u{1F1F9}"},{code:"LU",dialCode:"+352",name:"Luxembourg",flag:"\u{1F1F1}\u{1F1FA}"},{code:"MO",dialCode:"+853",name:"Macao",flag:"\u{1F1F2}\u{1F1F4}"},{code:"MG",dialCode:"+261",name:"Madagascar",flag:"\u{1F1F2}\u{1F1EC}"},{code:"MW",dialCode:"+265",name:"Malawi",flag:"\u{1F1F2}\u{1F1FC}"},{code:"MY",dialCode:"+60",name:"Malaysia",flag:"\u{1F1F2}\u{1F1FE}"},{code:"MV",dialCode:"+960",name:"Maldives",flag:"\u{1F1F2}\u{1F1FB}"},{code:"ML",dialCode:"+223",name:"Mali",flag:"\u{1F1F2}\u{1F1F1}"},{code:"MT",dialCode:"+356",name:"Malta",flag:"\u{1F1F2}\u{1F1F9}"},{code:"MH",dialCode:"+692",name:"Marshall Islands",flag:"\u{1F1F2}\u{1F1ED}"},{code:"MR",dialCode:"+222",name:"Mauritania",flag:"\u{1F1F2}\u{1F1F7}"},{code:"MU",dialCode:"+230",name:"Mauritius",flag:"\u{1F1F2}\u{1F1FA}"},{code:"MX",dialCode:"+52",name:"Mexico",flag:"\u{1F1F2}\u{1F1FD}"},{code:"FM",dialCode:"+691",name:"Micronesia",flag:"\u{1F1EB}\u{1F1F2}"},{code:"MD",dialCode:"+373",name:"Moldova",flag:"\u{1F1F2}\u{1F1E9}"},{code:"MC",dialCode:"+377",name:"Monaco",flag:"\u{1F1F2}\u{1F1E8}"},{code:"MN",dialCode:"+976",name:"Mongolia",flag:"\u{1F1F2}\u{1F1F3}"},{code:"ME",dialCode:"+382",name:"Montenegro",flag:"\u{1F1F2}\u{1F1EA}"},{code:"MA",dialCode:"+212",name:"Morocco",flag:"\u{1F1F2}\u{1F1E6}"},{code:"MZ",dialCode:"+258",name:"Mozambique",flag:"\u{1F1F2}\u{1F1FF}"},{code:"MM",dialCode:"+95",name:"Myanmar",flag:"\u{1F1F2}\u{1F1F2}"},{code:"NA",dialCode:"+264",name:"Namibia",flag:"\u{1F1F3}\u{1F1E6}"},{code:"NR",dialCode:"+674",name:"Nauru",flag:"\u{1F1F3}\u{1F1F7}"},{code:"NP",dialCode:"+977",name:"Nepal",flag:"\u{1F1F3}\u{1F1F5}"},{code:"NL",dialCode:"+31",name:"Netherlands",flag:"\u{1F1F3}\u{1F1F1}"},{code:"NZ",dialCode:"+64",name:"New Zealand",flag:"\u{1F1F3}\u{1F1FF}"},{code:"NI",dialCode:"+505",name:"Nicaragua",flag:"\u{1F1F3}\u{1F1EE}"},{code:"NE",dialCode:"+227",name:"Niger",flag:"\u{1F1F3}\u{1F1EA}"},{code:"NG",dialCode:"+234",name:"Nigeria",flag:"\u{1F1F3}\u{1F1EC}"},{code:"KP",dialCode:"+850",name:"North Korea",flag:"\u{1F1F0}\u{1F1F5}"},{code:"MK",dialCode:"+389",name:"North Macedonia",flag:"\u{1F1F2}\u{1F1F0}"},{code:"NO",dialCode:"+47",name:"Norway",flag:"\u{1F1F3}\u{1F1F4}"},{code:"OM",dialCode:"+968",name:"Oman",flag:"\u{1F1F4}\u{1F1F2}"},{code:"PK",dialCode:"+92",name:"Pakistan",flag:"\u{1F1F5}\u{1F1F0}"},{code:"PW",dialCode:"+680",name:"Palau",flag:"\u{1F1F5}\u{1F1FC}"},{code:"PS",dialCode:"+970",name:"Palestine",flag:"\u{1F1F5}\u{1F1F8}"},{code:"PA",dialCode:"+507",name:"Panama",flag:"\u{1F1F5}\u{1F1E6}"},{code:"PG",dialCode:"+675",name:"Papua New Guinea",flag:"\u{1F1F5}\u{1F1EC}"},{code:"PY",dialCode:"+595",name:"Paraguay",flag:"\u{1F1F5}\u{1F1FE}"},{code:"PE",dialCode:"+51",name:"Peru",flag:"\u{1F1F5}\u{1F1EA}"},{code:"PH",dialCode:"+63",name:"Philippines",flag:"\u{1F1F5}\u{1F1ED}"},{code:"PL",dialCode:"+48",name:"Poland",flag:"\u{1F1F5}\u{1F1F1}"},{code:"PT",dialCode:"+351",name:"Portugal",flag:"\u{1F1F5}\u{1F1F9}"},{code:"PR",dialCode:"+1",name:"Puerto Rico",flag:"\u{1F1F5}\u{1F1F7}"},{code:"QA",dialCode:"+974",name:"Qatar",flag:"\u{1F1F6}\u{1F1E6}"},{code:"RO",dialCode:"+40",name:"Romania",flag:"\u{1F1F7}\u{1F1F4}"},{code:"RU",dialCode:"+7",name:"Russia",flag:"\u{1F1F7}\u{1F1FA}"},{code:"RW",dialCode:"+250",name:"Rwanda",flag:"\u{1F1F7}\u{1F1FC}"},{code:"KN",dialCode:"+1",name:"Saint Kitts and Nevis",flag:"\u{1F1F0}\u{1F1F3}"},{code:"LC",dialCode:"+1",name:"Saint Lucia",flag:"\u{1F1F1}\u{1F1E8}"},{code:"VC",dialCode:"+1",name:"Saint Vincent and the Grenadines",flag:"\u{1F1FB}\u{1F1E8}"},{code:"WS",dialCode:"+685",name:"Samoa",flag:"\u{1F1FC}\u{1F1F8}"},{code:"SM",dialCode:"+378",name:"San Marino",flag:"\u{1F1F8}\u{1F1F2}"},{code:"ST",dialCode:"+239",name:"Sao Tome and Principe",flag:"\u{1F1F8}\u{1F1F9}"},{code:"SA",dialCode:"+966",name:"Saudi Arabia",flag:"\u{1F1F8}\u{1F1E6}"},{code:"SN",dialCode:"+221",name:"Senegal",flag:"\u{1F1F8}\u{1F1F3}"},{code:"RS",dialCode:"+381",name:"Serbia",flag:"\u{1F1F7}\u{1F1F8}"},{code:"SC",dialCode:"+248",name:"Seychelles",flag:"\u{1F1F8}\u{1F1E8}"},{code:"SL",dialCode:"+232",name:"Sierra Leone",flag:"\u{1F1F8}\u{1F1F1}"},{code:"SG",dialCode:"+65",name:"Singapore",flag:"\u{1F1F8}\u{1F1EC}"},{code:"SK",dialCode:"+421",name:"Slovakia",flag:"\u{1F1F8}\u{1F1F0}"},{code:"SI",dialCode:"+386",name:"Slovenia",flag:"\u{1F1F8}\u{1F1EE}"},{code:"SB",dialCode:"+677",name:"Solomon Islands",flag:"\u{1F1F8}\u{1F1E7}"},{code:"SO",dialCode:"+252",name:"Somalia",flag:"\u{1F1F8}\u{1F1F4}"},{code:"ZA",dialCode:"+27",name:"South Africa",flag:"\u{1F1FF}\u{1F1E6}"},{code:"KR",dialCode:"+82",name:"South Korea",flag:"\u{1F1F0}\u{1F1F7}"},{code:"SS",dialCode:"+211",name:"South Sudan",flag:"\u{1F1F8}\u{1F1F8}"},{code:"ES",dialCode:"+34",name:"Spain",flag:"\u{1F1EA}\u{1F1F8}"},{code:"LK",dialCode:"+94",name:"Sri Lanka",flag:"\u{1F1F1}\u{1F1F0}"},{code:"SD",dialCode:"+249",name:"Sudan",flag:"\u{1F1F8}\u{1F1E9}"},{code:"SR",dialCode:"+597",name:"Suriname",flag:"\u{1F1F8}\u{1F1F7}"},{code:"SE",dialCode:"+46",name:"Sweden",flag:"\u{1F1F8}\u{1F1EA}"},{code:"CH",dialCode:"+41",name:"Switzerland",flag:"\u{1F1E8}\u{1F1ED}"},{code:"SY",dialCode:"+963",name:"Syria",flag:"\u{1F1F8}\u{1F1FE}"},{code:"TW",dialCode:"+886",name:"Taiwan",flag:"\u{1F1F9}\u{1F1FC}"},{code:"TJ",dialCode:"+992",name:"Tajikistan",flag:"\u{1F1F9}\u{1F1EF}"},{code:"TZ",dialCode:"+255",name:"Tanzania",flag:"\u{1F1F9}\u{1F1FF}"},{code:"TH",dialCode:"+66",name:"Thailand",flag:"\u{1F1F9}\u{1F1ED}"},{code:"TL",dialCode:"+670",name:"Timor-Leste",flag:"\u{1F1F9}\u{1F1F1}"},{code:"TG",dialCode:"+228",name:"Togo",flag:"\u{1F1F9}\u{1F1EC}"},{code:"TO",dialCode:"+676",name:"Tonga",flag:"\u{1F1F9}\u{1F1F4}"},{code:"TT",dialCode:"+1",name:"Trinidad and Tobago",flag:"\u{1F1F9}\u{1F1F9}"},{code:"TN",dialCode:"+216",name:"Tunisia",flag:"\u{1F1F9}\u{1F1F3}"},{code:"TR",dialCode:"+90",name:"Turkey",flag:"\u{1F1F9}\u{1F1F7}"},{code:"TM",dialCode:"+993",name:"Turkmenistan",flag:"\u{1F1F9}\u{1F1F2}"},{code:"TV",dialCode:"+688",name:"Tuvalu",flag:"\u{1F1F9}\u{1F1FB}"},{code:"UG",dialCode:"+256",name:"Uganda",flag:"\u{1F1FA}\u{1F1EC}"},{code:"UA",dialCode:"+380",name:"Ukraine",flag:"\u{1F1FA}\u{1F1E6}"},{code:"AE",dialCode:"+971",name:"United Arab Emirates",flag:"\u{1F1E6}\u{1F1EA}"},{code:"GB",dialCode:"+44",name:"United Kingdom",flag:"\u{1F1EC}\u{1F1E7}"},{code:"US",dialCode:"+1",name:"United States",flag:"\u{1F1FA}\u{1F1F8}"},{code:"UY",dialCode:"+598",name:"Uruguay",flag:"\u{1F1FA}\u{1F1FE}"},{code:"UZ",dialCode:"+998",name:"Uzbekistan",flag:"\u{1F1FA}\u{1F1FF}"},{code:"VU",dialCode:"+678",name:"Vanuatu",flag:"\u{1F1FB}\u{1F1FA}"},{code:"VA",dialCode:"+39",name:"Vatican City",flag:"\u{1F1FB}\u{1F1E6}"},{code:"VE",dialCode:"+58",name:"Venezuela",flag:"\u{1F1FB}\u{1F1EA}"},{code:"VN",dialCode:"+84",name:"Vietnam",flag:"\u{1F1FB}\u{1F1F3}"},{code:"YE",dialCode:"+967",name:"Yemen",flag:"\u{1F1FE}\u{1F1EA}"},{code:"ZM",dialCode:"+260",name:"Zambia",flag:"\u{1F1FF}\u{1F1F2}"},{code:"ZW",dialCode:"+263",name:"Zimbabwe",flag:"\u{1F1FF}\u{1F1FC}"}],ct=new Map($.map(e=>[e.code,e])),ut={"America/New_York":"US","America/Chicago":"US","America/Denver":"US","America/Los_Angeles":"US","America/Anchorage":"US","Pacific/Honolulu":"US","America/Phoenix":"US","America/Indiana/Indianapolis":"US","America/Toronto":"CA","America/Vancouver":"CA","America/Edmonton":"CA","America/Winnipeg":"CA","America/Halifax":"CA","America/St_Johns":"CA","Europe/London":"GB","Europe/Dublin":"IE","Europe/Paris":"FR","Europe/Berlin":"DE","Europe/Madrid":"ES","Europe/Rome":"IT","Europe/Amsterdam":"NL","Europe/Brussels":"BE","Europe/Zurich":"CH","Europe/Vienna":"AT","Europe/Stockholm":"SE","Europe/Oslo":"NO","Europe/Copenhagen":"DK","Europe/Helsinki":"FI","Europe/Warsaw":"PL","Europe/Prague":"CZ","Europe/Bucharest":"RO","Europe/Budapest":"HU","Europe/Athens":"GR","Europe/Istanbul":"TR","Europe/Moscow":"RU","Europe/Kiev":"UA","Europe/Lisbon":"PT","Europe/Belgrade":"RS","Europe/Zagreb":"HR","Europe/Bratislava":"SK","Europe/Ljubljana":"SI","Europe/Tallinn":"EE","Europe/Riga":"LV","Europe/Vilnius":"LT","Asia/Tokyo":"JP","Asia/Seoul":"KR","Asia/Shanghai":"CN","Asia/Hong_Kong":"HK","Asia/Taipei":"TW","Asia/Singapore":"SG","Asia/Kolkata":"IN","Asia/Karachi":"PK","Asia/Dhaka":"BD","Asia/Bangkok":"TH","Asia/Jakarta":"ID","Asia/Manila":"PH","Asia/Kuala_Lumpur":"MY","Asia/Ho_Chi_Minh":"VN","Asia/Riyadh":"SA","Asia/Dubai":"AE","Asia/Tehran":"IR","Asia/Baghdad":"IQ","Asia/Beirut":"LB","Asia/Jerusalem":"IL","Asia/Amman":"JO","Asia/Almaty":"KZ","Asia/Tashkent":"UZ","Asia/Colombo":"LK","Asia/Kathmandu":"NP","Asia/Yangon":"MM","Australia/Sydney":"AU","Australia/Melbourne":"AU","Australia/Brisbane":"AU","Australia/Perth":"AU","Australia/Adelaide":"AU","Pacific/Auckland":"NZ","Pacific/Fiji":"FJ","Africa/Cairo":"EG","Africa/Lagos":"NG","Africa/Nairobi":"KE","Africa/Johannesburg":"ZA","Africa/Casablanca":"MA","Africa/Accra":"GH","Africa/Addis_Ababa":"ET","Africa/Dar_es_Salaam":"TZ","Africa/Kampala":"UG","America/Mexico_City":"MX","America/Bogota":"CO","America/Lima":"PE","America/Santiago":"CL","America/Buenos_Aires":"AR","America/Sao_Paulo":"BR","America/Caracas":"VE","America/Guatemala":"GT","America/Havana":"CU","America/Panama":"PA","America/Jamaica":"JM"};function Ee(){try{let e=Intl.DateTimeFormat().resolvedOptions().timeZone;return ut[e]??"US"}catch{return"US"}}function Te(e){if(!e.startsWith("+"))return e;let t=e.slice(1);if(t.startsWith("1")&&t.length===11){let n=t.slice(1,4),o=t.slice(4,7),a=t.slice(7);return`+1 (${n}) ${o}-${a}`}for(let n=4;n>=1;n--){let o="+"+t.slice(0,n),a=$.find(r=>r.dialCode===o);if(a){let r=t.slice(n);return`${a.dialCode} ${r}`}}return e}function be(e,t){let n=e.replace(/\D/g,""),o=ct.get(t);if(!o)return"+"+n;let a=o.dialCode.slice(1);return n.startsWith(a)?"+"+n:o.dialCode+n}function ve(e){return/^\+[1-9]\d{6,14}$/.test(e)}function _e(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}async function y(e,t,n){let a={Authorization:`Bearer ${d().token}`};n!==void 0&&(a["Content-Type"]="application/json");let r=await fetch(e,{method:t,headers:a,...n!==void 0&&{body:JSON.stringify(n)}});if(!r.ok){let i=`Auth request failed: ${r.status} ${r.statusText}`,c="auth_error";try{let s=await r.json();s.error&&(i=s.error),s.code&&(c=s.code)}catch{}throw new l(i,c,r.status)}return await r.json()}var Z="__ms_remy_state",K="ms_popup",Me="ms:remy:callback",Pe=!1,R=mt();function mt(){if(typeof window>"u")return!1;try{let e=new URL(window.location.href).searchParams;return e.has("code")&&e.get(K)!=="1"}catch{return!1}}function pt(){let e=globalThis.crypto;if(e&&typeof e.randomUUID=="function")return e.randomUUID();let t=new Uint8Array(16);return e?.getRandomValues?.(t),Array.from(t,n=>n.toString(16).padStart(2,"0")).join("")}function ht(e){e.searchParams.delete("code"),e.searchParams.delete("state");try{window.history.replaceState(window.history.state,"",e.toString())}catch{}}var I=new Set;function P(e){we({token:e.token,user:e.user,methods:e.methods,visitorId:e.visitorId}),I.forEach(t=>t(e.user))}function M(e){if(!e.user)throw new l("Verification succeeded but no user was returned","auth_error");return e.user}function Re(e){let t=d();t.user&&(Object.assign(t.user,e),I.forEach(n=>n(t.user)))}function z(){try{return d().user}catch{return null}}function ke(){let e=z();I.forEach(t=>t(e))}function Ue(){R||(R=!0,ke())}function X(){R&&(R=!1,ke())}function Ct(){try{return window.top!==window.self}catch{return!0}}var yt=520,At=600;function wt(e,t){let n=window.screenX,o=window.screenY,a=window.outerWidth||window.innerWidth||window.screen.width,r=window.outerHeight||window.innerHeight||window.screen.height,i=Math.min(e,a),c=Math.min(t,r),s=Math.max(0,Math.round(n+(a-i)/2)),g=Math.max(0,Math.round(o+(r-c)/2));return`popup=yes,width=${Math.round(i)},height=${Math.round(c)},left=${s},top=${g}`}function St(e,t){let n=new URL(e,window.location.href);n.searchParams.set(K,"1");let o=`/_/auth/remy/start?${new URLSearchParams({redirect_uri:n.toString(),state:t}).toString()}`,a=window.open(o,"ms-remy-signin",wt(yt,At));return a?(Ue(),new Promise((r,i)=>{let c=window.location.origin,s=!1,g=!1,u=p=>{if(!s){s=!0,window.removeEventListener("message",m),clearInterval(E),clearTimeout(w),X();try{a.closed||a.close()}catch{}p()}},m=p=>{if(s||g||p.origin!==c||p.source!==a)return;let h=p.data;if(!(!h||h.type!==Me||h.state!==t)){if(g=!0,!h.code){u(()=>i(new l("Sign-in returned no code.","auth_error")));return}y("/_/auth/remy/exchange","POST",{code:h.code}).then(f=>{R=!1,P(f),u(()=>r(M(f)))}).catch(f=>u(()=>i(f)))}};window.addEventListener("message",m);let E=setInterval(()=>{a.closed&&!g&&u(()=>r(null))},400),w=setTimeout(()=>u(()=>i(new l("Sign-in timed out.","signin_timeout"))),300*1e3)})):Promise.reject(new l("The sign-in popup was blocked. Allow popups for this site and try again.","popup_blocked"))}function Q(){if(typeof window>"u")return!1;let e;try{e=new URL(window.location.href).searchParams}catch{return!1}if(e.get(K)!=="1")return!1;let t=e.get("code");if(!t)return!1;if(Pe)return!0;let n=window.opener;if(!n||n===window)return!1;try{n.postMessage({type:Me,code:t,state:e.get("state")??void 0},window.location.origin)}catch{return!1}Pe=!0;try{setTimeout(()=>window.close(),0)}catch{}return!0}var Et={get currentUser(){return d().user},getCurrentUser(){return d().user},isAuthenticated(){return d().user!==null},get authStatus(){return R?"authenticating":z()?"authenticated":"unauthenticated"},get currentVisitorId(){return d().visitorId??null},getCurrentVisitorId(){return d().visitorId??null},sendEmailCode(e){return y("/_/auth/email/send","POST",{email:e})},async verifyEmailCode(e,t){let n=await y("/_/auth/email/verify","POST",{verificationId:e,code:t});return P(n),M(n)},sendSmsCode(e){return y("/_/auth/sms/send","POST",{phone:e})},async verifySmsCode(e,t){let n=await y("/_/auth/sms/verify","POST",{verificationId:e,code:t});return P(n),M(n)},signInWithRemy(e){let t=e?.mode??"auto",n=t==="popup"||t==="auto"&&Ct(),o=e?.redirectUri??window.location.href,a=e?.state??pt();if(n)return St(o,a);try{sessionStorage.setItem(Z,a)}catch{}let r=new URLSearchParams({redirect_uri:o,state:a});return window.location.assign(`/_/auth/remy/start?${r.toString()}`),new Promise(()=>{})},async handleRemyRedirect(){if(typeof window>"u")return null;let e=new URL(window.location.href),t=e.searchParams.get("code");if(!t)return null;if(e.searchParams.get(K)==="1")return Q(),null;let n=e.searchParams.get("state");ht(e);let o=null;try{o=sessionStorage.getItem(Z),sessionStorage.removeItem(Z)}catch{}if(Ue(),n!==null&&n!==o)throw X(),new l("Sign-in state mismatch \u2014 possible CSRF or a stale redirect. Please try again.","invalid_state");try{let a=await y("/_/auth/remy/exchange","POST",{code:t});return R=!1,P(a),M(a)}catch(a){throw X(),a}},async requestEmailChange(e){await y("/_/auth/email/change","POST",{newEmail:e})},async confirmEmailChange(e,t){let n=await y("/_/auth/email/change/confirm","POST",{newEmail:e,code:t});return P(n),M(n)},async requestPhoneChange(e){await y("/_/auth/phone/change","POST",{newPhone:e})},async confirmPhoneChange(e,t){let n=await y("/_/auth/phone/change/confirm","POST",{newPhone:e,code:t});return P(n),M(n)},async logout(){let e=await y("/_/auth/logout","POST",{});P(e)},async createApiKey(){let e=await y("/_/auth/api-key/create","POST",{});return Re({apiKey:e.apiKey}),{key:e.key}},async revokeApiKey(){await y("/_/auth/api-key/revoke","POST",{}),Re({apiKey:null})},onAuthStateChanged(e){return I.add(e),e(z()),()=>{I.delete(e)}},phone:{countries:$,detectCountry:Ee,format:Te,toE164:be,isValid:ve},email:{isValid:_e}};typeof window<"u"&&!Q()&&globalThis.__MINDSTUDIO__&&setTimeout(()=>{try{d()}catch{}},0);export{l as MindStudioInterfaceError,We as analytics,Et as auth,st as createAgentChatClient,rt as createClient,dt as platform};
|
|
5
5
|
//# sourceMappingURL=index.js.map
|