@superatomai/application-react 0.0.3 → 0.0.4
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.cjs +83 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -2
- package/dist/index.d.ts +16 -2
- package/dist/index.js +83 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -68148,6 +68148,7 @@ var SuperAtomAuthError = class extends Error {
|
|
|
68148
68148
|
super(message);
|
|
68149
68149
|
this.name = "SuperAtomAuthError";
|
|
68150
68150
|
this.code = code4;
|
|
68151
|
+
this.reason = options.reason;
|
|
68151
68152
|
this.status = options.status;
|
|
68152
68153
|
this.fatal = options.fatal;
|
|
68153
68154
|
if (options.cause !== void 0) this.cause = options.cause;
|
|
@@ -68213,8 +68214,10 @@ var SdkSession = class {
|
|
|
68213
68214
|
}
|
|
68214
68215
|
renew() {
|
|
68215
68216
|
if (!this.inFlight) {
|
|
68217
|
+
this.opts.onSigningIn?.(true);
|
|
68216
68218
|
this.inFlight = this.exchange().finally(() => {
|
|
68217
68219
|
this.inFlight = null;
|
|
68220
|
+
this.opts.onSigningIn?.(false);
|
|
68218
68221
|
});
|
|
68219
68222
|
}
|
|
68220
68223
|
return this.inFlight;
|
|
@@ -68249,7 +68252,11 @@ var SdkSession = class {
|
|
|
68249
68252
|
const message = typeof body?.error === "string" ? body.error : `Sign-in failed (${res.status})`;
|
|
68250
68253
|
const fatal = res.status >= 400 && res.status < 500 && res.status !== 429;
|
|
68251
68254
|
throw this.fail(
|
|
68252
|
-
new SuperAtomAuthError(fatal ? "exchange_rejected" : "exchange_unavailable", message, {
|
|
68255
|
+
new SuperAtomAuthError(fatal ? "exchange_rejected" : "exchange_unavailable", message, {
|
|
68256
|
+
status: res.status,
|
|
68257
|
+
reason: typeof body?.code === "string" ? body.code : void 0,
|
|
68258
|
+
fatal
|
|
68259
|
+
})
|
|
68253
68260
|
);
|
|
68254
68261
|
}
|
|
68255
68262
|
if (typeof body?.token !== "string" || !body.user?.id) {
|
|
@@ -69448,6 +69455,8 @@ function resetRegistration() {
|
|
|
69448
69455
|
}
|
|
69449
69456
|
var current = null;
|
|
69450
69457
|
var retrying = null;
|
|
69458
|
+
var signingIn = false;
|
|
69459
|
+
var chatReady = false;
|
|
69451
69460
|
var listeners = /* @__PURE__ */ new Set();
|
|
69452
69461
|
function setAuthStatus(error51) {
|
|
69453
69462
|
if (current === error51) return;
|
|
@@ -69460,6 +69469,36 @@ function setRetryingStatus(error51) {
|
|
|
69460
69469
|
retrying = error51;
|
|
69461
69470
|
listeners.forEach((l) => l());
|
|
69462
69471
|
}
|
|
69472
|
+
function setSigningIn(value) {
|
|
69473
|
+
if (signingIn === value) return;
|
|
69474
|
+
signingIn = value;
|
|
69475
|
+
listeners.forEach((l) => l());
|
|
69476
|
+
}
|
|
69477
|
+
function useSigningIn() {
|
|
69478
|
+
return React6.useSyncExternalStore(
|
|
69479
|
+
(l) => {
|
|
69480
|
+
listeners.add(l);
|
|
69481
|
+
return () => listeners.delete(l);
|
|
69482
|
+
},
|
|
69483
|
+
() => signingIn,
|
|
69484
|
+
() => false
|
|
69485
|
+
);
|
|
69486
|
+
}
|
|
69487
|
+
function setChatReady(value) {
|
|
69488
|
+
if (chatReady === value) return;
|
|
69489
|
+
chatReady = value;
|
|
69490
|
+
listeners.forEach((l) => l());
|
|
69491
|
+
}
|
|
69492
|
+
function useStartingUp() {
|
|
69493
|
+
return React6.useSyncExternalStore(
|
|
69494
|
+
(l) => {
|
|
69495
|
+
listeners.add(l);
|
|
69496
|
+
return () => listeners.delete(l);
|
|
69497
|
+
},
|
|
69498
|
+
() => !chatReady,
|
|
69499
|
+
() => false
|
|
69500
|
+
);
|
|
69501
|
+
}
|
|
69463
69502
|
function useRetryingStatus() {
|
|
69464
69503
|
return React6.useSyncExternalStore(
|
|
69465
69504
|
(l) => {
|
|
@@ -69480,12 +69519,34 @@ function useAuthStatus() {
|
|
|
69480
69519
|
() => null
|
|
69481
69520
|
);
|
|
69482
69521
|
}
|
|
69522
|
+
var SETUP_REASONS = /* @__PURE__ */ new Set([
|
|
69523
|
+
"bad_request",
|
|
69524
|
+
"bad_project_id",
|
|
69525
|
+
"unknown_project",
|
|
69526
|
+
"bad_sub",
|
|
69527
|
+
"bad_email",
|
|
69528
|
+
"bad_roles",
|
|
69529
|
+
"bad_access",
|
|
69530
|
+
"bad_access_values",
|
|
69531
|
+
"bad_access_filters",
|
|
69532
|
+
"access_not_set_up",
|
|
69533
|
+
"lifetime_too_long",
|
|
69534
|
+
"issued_in_future",
|
|
69535
|
+
"email_linked_elsewhere"
|
|
69536
|
+
]);
|
|
69483
69537
|
function authStatusMessage(error51) {
|
|
69484
69538
|
switch (error51.code) {
|
|
69485
69539
|
case "get_token_failed":
|
|
69486
69540
|
return "Your session has ended. Please sign in again to continue.";
|
|
69487
69541
|
case "exchange_rejected":
|
|
69488
|
-
|
|
69542
|
+
if (error51.reason === "inactive") return "This account has been deactivated.";
|
|
69543
|
+
if (error51.reason === "sdk_not_enabled" || error51.status === 403) {
|
|
69544
|
+
return "This account cannot use the chat. Please contact your administrator.";
|
|
69545
|
+
}
|
|
69546
|
+
if (error51.reason && SETUP_REASONS.has(error51.reason)) {
|
|
69547
|
+
return `This app\u2019s Superatom sign-in is not set up correctly: ${error51.message}`;
|
|
69548
|
+
}
|
|
69549
|
+
return "Your session is no longer valid. Please sign in again to continue.";
|
|
69489
69550
|
default:
|
|
69490
69551
|
return "Could not connect to Superatom. Please try again in a moment.";
|
|
69491
69552
|
}
|
|
@@ -69685,6 +69746,7 @@ function useSuperAtom({
|
|
|
69685
69746
|
if (sdkSignIn && token) throw new Error("[SuperAtom] Pass either token or getToken, not both");
|
|
69686
69747
|
const [user, setUser] = React6.useState(null);
|
|
69687
69748
|
const [authError, setAuthError] = React6.useState(null);
|
|
69749
|
+
const [isSigningIn, setIsSigningIn] = React6.useState(false);
|
|
69688
69750
|
const [signInAttempt, setSignInAttempt] = React6.useState(0);
|
|
69689
69751
|
const directUserId = (() => {
|
|
69690
69752
|
if (sdkSignIn) return void 0;
|
|
@@ -69750,7 +69812,13 @@ function useSuperAtom({
|
|
|
69750
69812
|
},
|
|
69751
69813
|
// Superatom unreachable or down, after a couple of tries: say so in the
|
|
69752
69814
|
// chat instead of sitting on "Connecting…".
|
|
69753
|
-
onRetrying: (err) => setRetryingStatus(err)
|
|
69815
|
+
onRetrying: (err) => setRetryingStatus(err),
|
|
69816
|
+
// Lets the chat show "Signing in…" instead of an empty chat while a
|
|
69817
|
+
// sign-in — including one after reconnect() — is in flight.
|
|
69818
|
+
onSigningIn: (value) => {
|
|
69819
|
+
setSigningIn(value);
|
|
69820
|
+
setIsSigningIn(value);
|
|
69821
|
+
}
|
|
69754
69822
|
});
|
|
69755
69823
|
sessionRef.current = session;
|
|
69756
69824
|
for (let delay = 1e3; ; delay = Math.min(delay * 2, 3e4)) {
|
|
@@ -69877,6 +69945,7 @@ function useSuperAtom({
|
|
|
69877
69945
|
if (!cancelled) {
|
|
69878
69946
|
setupDoneRef.current = true;
|
|
69879
69947
|
setBundleReady(true);
|
|
69948
|
+
setChatReady(true);
|
|
69880
69949
|
}
|
|
69881
69950
|
} catch (err) {
|
|
69882
69951
|
console.error("[SuperAtom] Setup failed:", err);
|
|
@@ -69896,6 +69965,7 @@ function useSuperAtom({
|
|
|
69896
69965
|
setAuthStatus(null);
|
|
69897
69966
|
setupDoneRef.current = false;
|
|
69898
69967
|
setBundleReady(false);
|
|
69968
|
+
setChatReady(false);
|
|
69899
69969
|
};
|
|
69900
69970
|
}, [directUserId, sdkSignIn, projectId, apiUrl, wsUrl, debug, signInAttempt]);
|
|
69901
69971
|
const reconnect = React6.useCallback(() => {
|
|
@@ -70361,6 +70431,7 @@ function useSuperAtom({
|
|
|
70361
70431
|
isNewChat: bundleReady && !isLoadingThread && messages2.length === 0,
|
|
70362
70432
|
user,
|
|
70363
70433
|
authError,
|
|
70434
|
+
isSigningIn,
|
|
70364
70435
|
reconnect
|
|
70365
70436
|
};
|
|
70366
70437
|
}
|
|
@@ -70458,6 +70529,7 @@ function ChatInput({
|
|
|
70458
70529
|
onStop
|
|
70459
70530
|
}) {
|
|
70460
70531
|
const authError = useAuthStatus();
|
|
70532
|
+
const startingUp = useStartingUp();
|
|
70461
70533
|
const isLocked = disabled || !!authError;
|
|
70462
70534
|
const textareaRef = React6.useRef(null);
|
|
70463
70535
|
const historyRef = React6.useRef(null);
|
|
@@ -70520,6 +70592,7 @@ function ChatInput({
|
|
|
70520
70592
|
}, [input, isLocked, onSend, getOrCreateHistory]);
|
|
70521
70593
|
const themeColor = getThemeColor();
|
|
70522
70594
|
const effectivePlaceholder = authError ? authStatusMessage(authError) : placeholder;
|
|
70595
|
+
if (startingUp) return null;
|
|
70523
70596
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: `sa-ui shrink-0 bg-base-100 border-t border-base-300 px-4 py-2 ${className}`, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: `group ${isMultiline ? "rounded-3xl" : "rounded-full"} bg-base-200 transition-all duration-200 w-full max-w-2xl mx-auto`, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
70524
70597
|
"div",
|
|
70525
70598
|
{
|
|
@@ -70955,8 +71028,12 @@ function MessageList({
|
|
|
70955
71028
|
}, [messages2]);
|
|
70956
71029
|
const authError = useAuthStatus();
|
|
70957
71030
|
const retrying2 = useRetryingStatus();
|
|
71031
|
+
const signingIn2 = useSigningIn();
|
|
70958
71032
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `sa-ui flex-1 relative overflow-hidden ${className}`, children: [
|
|
70959
|
-
/* @__PURE__ */ jsxRuntime.jsx("main", { ref: containerRef, className: "h-full overflow-y-auto py-6", children:
|
|
71033
|
+
/* @__PURE__ */ jsxRuntime.jsx("main", { ref: containerRef, className: "h-full overflow-y-auto py-6", children: signingIn2 && !bundleReady ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "h-full flex flex-col items-center justify-center gap-3 text-base-content/50", children: [
|
|
71034
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "loading loading-spinner loading-lg" }),
|
|
71035
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm", children: "Signing in to Superatom\u2026" })
|
|
71036
|
+
] }) : authError ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "h-full flex flex-col items-center justify-center gap-3 px-6 text-center", children: [
|
|
70960
71037
|
/* @__PURE__ */ jsxRuntime.jsx(Icon, { icon: "mdi:lock-alert-outline", width: 28, height: 28, className: "text-base-content/40" }),
|
|
70961
71038
|
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-base-content/70 max-w-sm", children: authStatusMessage(authError) })
|
|
70962
71039
|
] }) : !bundleReady || isLoadingThread && messages2.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "h-full flex flex-col items-center justify-center gap-3 text-base-content/50", children: [
|
|
@@ -71407,6 +71484,7 @@ function Sidebar({
|
|
|
71407
71484
|
setThreadToDelete(null);
|
|
71408
71485
|
}
|
|
71409
71486
|
};
|
|
71487
|
+
const startingUp = useStartingUp();
|
|
71410
71488
|
const [collapsed, setCollapsed] = React6.useState(() => {
|
|
71411
71489
|
try {
|
|
71412
71490
|
return localStorage.getItem(SIDEBAR_COLLAPSED_KEY) === "true";
|
|
@@ -71491,6 +71569,7 @@ function Sidebar({
|
|
|
71491
71569
|
});
|
|
71492
71570
|
}
|
|
71493
71571
|
}
|
|
71572
|
+
if (startingUp) return null;
|
|
71494
71573
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
71495
71574
|
"aside",
|
|
71496
71575
|
{
|