@superatomai/application-react 0.0.2 → 0.0.3
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 +744 -197
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +194 -6
- package/dist/index.d.ts +194 -6
- package/dist/index.js +743 -199
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1059,7 +1059,15 @@ declare const ClientConfigSchema: z.ZodObject<{
|
|
|
1059
1059
|
debug: z.ZodDefault<z.ZodBoolean>;
|
|
1060
1060
|
token: z.ZodOptional<z.ZodString>;
|
|
1061
1061
|
}, z.core.$strip>;
|
|
1062
|
-
type ClientConfig = z.input<typeof ClientConfigSchema
|
|
1062
|
+
type ClientConfig = z.input<typeof ClientConfigSchema> & {
|
|
1063
|
+
/**
|
|
1064
|
+
* Called before every (re)connect for a valid session token, replacing
|
|
1065
|
+
* `token`. Used for SDK sign-in (see SdkSession in auth.ts). Rejecting with an
|
|
1066
|
+
* error whose `fatal` is true stops reconnecting; any other rejection is
|
|
1067
|
+
* retried with the normal back-off.
|
|
1068
|
+
*/
|
|
1069
|
+
getAccessToken?: () => Promise<string>;
|
|
1070
|
+
};
|
|
1063
1071
|
type ResolvedClientConfig = z.output<typeof ClientConfigSchema>;
|
|
1064
1072
|
|
|
1065
1073
|
/**
|
|
@@ -1847,6 +1855,19 @@ declare function deleteThread(client: SuperatomClient, userId: string, threadId:
|
|
|
1847
1855
|
message?: string;
|
|
1848
1856
|
deletedCount?: number;
|
|
1849
1857
|
}>;
|
|
1858
|
+
/**
|
|
1859
|
+
* Delete one saved question/answer, by the question that produced it.
|
|
1860
|
+
*
|
|
1861
|
+
* `clearCache` also drops what was cached for it (query results and embeddings),
|
|
1862
|
+
* so asking the same thing again is answered from the data, not from the old
|
|
1863
|
+
* result. Same call Runtime-react's trash button makes.
|
|
1864
|
+
*/
|
|
1865
|
+
declare function deleteUserConversation(client: SuperatomClient, userPrompt: string, userId?: string, clearCache?: boolean, timeout?: number): Promise<{
|
|
1866
|
+
success: boolean;
|
|
1867
|
+
error?: string;
|
|
1868
|
+
message?: string;
|
|
1869
|
+
queriesDeleted?: number;
|
|
1870
|
+
}>;
|
|
1850
1871
|
/**
|
|
1851
1872
|
* Rename a thread's title.
|
|
1852
1873
|
*/
|
|
@@ -1897,6 +1918,7 @@ declare const index_createBookmark: typeof createBookmark;
|
|
|
1897
1918
|
declare const index_deleteArtifact: typeof deleteArtifact;
|
|
1898
1919
|
declare const index_deleteBookmark: typeof deleteBookmark;
|
|
1899
1920
|
declare const index_deleteThread: typeof deleteThread;
|
|
1921
|
+
declare const index_deleteUserConversation: typeof deleteUserConversation;
|
|
1900
1922
|
declare const index_getActions: typeof getActions;
|
|
1901
1923
|
declare const index_getAllArtifacts: typeof getAllArtifacts;
|
|
1902
1924
|
declare const index_getAllBookmarks: typeof getAllBookmarks;
|
|
@@ -1931,7 +1953,7 @@ declare const index_sendUserPromptSuggestionsRequest: typeof sendUserPromptSugge
|
|
|
1931
1953
|
declare const index_updateBookmark: typeof updateBookmark;
|
|
1932
1954
|
declare const index_updateThreadTitle: typeof updateThreadTitle;
|
|
1933
1955
|
declare namespace index {
|
|
1934
|
-
export { type index_Artifact as Artifact, type Binding$1 as Binding, BindingSchema$1 as BindingSchema, type index_Bookmark as Bookmark, type index_CreateBookmarkOptions as CreateBookmarkOptions, type DSLRendererProps$3 as DSLRendererProps, DSLRendererPropsSchema$3 as DSLRendererPropsSchema, type index_Dashboard as Dashboard, type Expression$1 as Expression, ExpressionSchema$1 as ExpressionSchema, type ForDirective$1 as ForDirective, ForDirectiveSchema$1 as ForDirectiveSchema, type index_Menu as Menu, type index_Page as Page, index_PageSchema as PageSchema, type index_QueryArtifactsFilters as QueryArtifactsFilters, type index_QueryArtifactsOptions as QueryArtifactsOptions, type index_QueryBookmarksOptions as QueryBookmarksOptions, type index_QueryDashboardsOptions as QueryDashboardsOptions, type index_QueryMenusOptions as QueryMenusOptions, type index_QueryReportsOptions as QueryReportsOptions, type QuerySpec$1 as QuerySpec, QuerySpecSchema$1 as QuerySpecSchema, type index_QueryUIsOptions as QueryUIsOptions, type index_QueryUsersOptions as QueryUsersOptions, type index_Report as Report, type DSLRendererProps$2 as ReportDSLRendererProps, type index_ThreadConversationRow as ThreadConversationRow, type index_ThreadSummary as ThreadSummary, type index_UI as UI, type UIComponent$1 as UIComponent, UIComponentSchema$1 as UIComponentSchema, type DSLRendererProps$1 as UIDSLRendererProps, type UIElement$1 as UIElement, UIElementSchema$1 as UIElementSchema, type index_UpdateBookmarkOptions as UpdateBookmarkOptions, type index_User as User, index_abortUserPromptRequest as abortUserPromptRequest, index_createBookmark as createBookmark, index_deleteArtifact as deleteArtifact, index_deleteBookmark as deleteBookmark, index_deleteThread as deleteThread, index_getActions as getActions, index_getAllArtifacts as getAllArtifacts, index_getAllBookmarks as getAllBookmarks, index_getAllDashboards as getAllDashboards, index_getAllMenus as getAllMenus, index_getAllReports as getAllReports, index_getAllUIs as getAllUIs, index_getArtifact as getArtifact, index_getBookmark as getBookmark, index_getChildMenus as getChildMenus, index_getDashboard as getDashboard, index_getMenu as getMenu, index_getMenusHierarchy as getMenusHierarchy, index_getReport as getReport, index_getRootMenus as getRootMenus, index_getThreadConversations as getThreadConversations, index_getUI as getUI, index_getUserThreads as getUserThreads, index_injectBundleStyles as injectBundleStyles, index_queryArtifacts as queryArtifacts, index_queryBookmarks as queryBookmarks, index_queryDashboards as queryDashboards, index_queryMenus as queryMenus, index_queryReports as queryReports, index_queryUIs as queryUIs, index_queryUsers as queryUsers, index_requestBundle as requestBundle, index_requestData as requestData, index_sendComponents as sendComponents, index_sendUserPromptRequest as sendUserPromptRequest, index_sendUserPromptSuggestionsRequest as sendUserPromptSuggestionsRequest, index_updateBookmark as updateBookmark, index_updateThreadTitle as updateThreadTitle };
|
|
1956
|
+
export { type index_Artifact as Artifact, type Binding$1 as Binding, BindingSchema$1 as BindingSchema, type index_Bookmark as Bookmark, type index_CreateBookmarkOptions as CreateBookmarkOptions, type DSLRendererProps$3 as DSLRendererProps, DSLRendererPropsSchema$3 as DSLRendererPropsSchema, type index_Dashboard as Dashboard, type Expression$1 as Expression, ExpressionSchema$1 as ExpressionSchema, type ForDirective$1 as ForDirective, ForDirectiveSchema$1 as ForDirectiveSchema, type index_Menu as Menu, type index_Page as Page, index_PageSchema as PageSchema, type index_QueryArtifactsFilters as QueryArtifactsFilters, type index_QueryArtifactsOptions as QueryArtifactsOptions, type index_QueryBookmarksOptions as QueryBookmarksOptions, type index_QueryDashboardsOptions as QueryDashboardsOptions, type index_QueryMenusOptions as QueryMenusOptions, type index_QueryReportsOptions as QueryReportsOptions, type QuerySpec$1 as QuerySpec, QuerySpecSchema$1 as QuerySpecSchema, type index_QueryUIsOptions as QueryUIsOptions, type index_QueryUsersOptions as QueryUsersOptions, type index_Report as Report, type DSLRendererProps$2 as ReportDSLRendererProps, type index_ThreadConversationRow as ThreadConversationRow, type index_ThreadSummary as ThreadSummary, type index_UI as UI, type UIComponent$1 as UIComponent, UIComponentSchema$1 as UIComponentSchema, type DSLRendererProps$1 as UIDSLRendererProps, type UIElement$1 as UIElement, UIElementSchema$1 as UIElementSchema, type index_UpdateBookmarkOptions as UpdateBookmarkOptions, type index_User as User, index_abortUserPromptRequest as abortUserPromptRequest, index_createBookmark as createBookmark, index_deleteArtifact as deleteArtifact, index_deleteBookmark as deleteBookmark, index_deleteThread as deleteThread, index_deleteUserConversation as deleteUserConversation, index_getActions as getActions, index_getAllArtifacts as getAllArtifacts, index_getAllBookmarks as getAllBookmarks, index_getAllDashboards as getAllDashboards, index_getAllMenus as getAllMenus, index_getAllReports as getAllReports, index_getAllUIs as getAllUIs, index_getArtifact as getArtifact, index_getBookmark as getBookmark, index_getChildMenus as getChildMenus, index_getDashboard as getDashboard, index_getMenu as getMenu, index_getMenusHierarchy as getMenusHierarchy, index_getReport as getReport, index_getRootMenus as getRootMenus, index_getThreadConversations as getThreadConversations, index_getUI as getUI, index_getUserThreads as getUserThreads, index_injectBundleStyles as injectBundleStyles, index_queryArtifacts as queryArtifacts, index_queryBookmarks as queryBookmarks, index_queryDashboards as queryDashboards, index_queryMenus as queryMenus, index_queryReports as queryReports, index_queryUIs as queryUIs, index_queryUsers as queryUsers, index_requestBundle as requestBundle, index_requestData as requestData, index_sendComponents as sendComponents, index_sendUserPromptRequest as sendUserPromptRequest, index_sendUserPromptSuggestionsRequest as sendUserPromptSuggestionsRequest, index_updateBookmark as updateBookmark, index_updateThreadTitle as updateThreadTitle };
|
|
1935
1957
|
}
|
|
1936
1958
|
|
|
1937
1959
|
type MessageHandler = (message: Message) => void;
|
|
@@ -1956,6 +1978,8 @@ declare class SuperatomClient {
|
|
|
1956
1978
|
private config;
|
|
1957
1979
|
private connectPromise;
|
|
1958
1980
|
private connectResolve;
|
|
1981
|
+
private getAccessToken;
|
|
1982
|
+
private fetchingToken;
|
|
1959
1983
|
private heartbeatInterval;
|
|
1960
1984
|
private pongDeadline;
|
|
1961
1985
|
private readonly HEARTBEAT_INTERVAL_MS;
|
|
@@ -2024,6 +2048,14 @@ declare class SuperatomClient {
|
|
|
2024
2048
|
* window 'online' / 'visibilitychange' handlers.
|
|
2025
2049
|
*/
|
|
2026
2050
|
forceReconnect(): Promise<void>;
|
|
2051
|
+
/**
|
|
2052
|
+
* Drop the current socket without triggering its handlers: they are detached
|
|
2053
|
+
* first, so its eventual real close is a no-op (on Linux/Chrome that close
|
|
2054
|
+
* can arrive 30-60s later). Returns whether it was open.
|
|
2055
|
+
*/
|
|
2056
|
+
private discardSocket;
|
|
2057
|
+
/** A connection attempt is under way — fetching the session token, or the socket handshake. */
|
|
2058
|
+
private isConnecting;
|
|
2027
2059
|
/**
|
|
2028
2060
|
* Attach window-level listeners that catch network changes faster than
|
|
2029
2061
|
* the socket's own onclose. The browser's onclose for a half-open TCP can
|
|
@@ -2047,6 +2079,16 @@ declare class SuperatomClient {
|
|
|
2047
2079
|
* The Promise never rejects - failures are logged silently and auto-reconnect is triggered
|
|
2048
2080
|
*/
|
|
2049
2081
|
connect(): Promise<void>;
|
|
2082
|
+
/**
|
|
2083
|
+
* Get a valid session token, then open the socket. The relay checks the token
|
|
2084
|
+
* only at handshake, so every (re)connect must present one that is still valid.
|
|
2085
|
+
*
|
|
2086
|
+
* A fatal auth failure (see SuperAtomAuthError.fatal) stops reconnecting — the
|
|
2087
|
+
* session reports it to the host, and retrying would only repeat it. Anything
|
|
2088
|
+
* else goes through the normal back-off.
|
|
2089
|
+
*/
|
|
2090
|
+
private openWithFreshToken;
|
|
2091
|
+
private openSocket;
|
|
2050
2092
|
/**
|
|
2051
2093
|
* Disconnect from WebSocket server
|
|
2052
2094
|
*/
|
|
@@ -2476,6 +2518,116 @@ declare class SuperatomClient {
|
|
|
2476
2518
|
private log;
|
|
2477
2519
|
}
|
|
2478
2520
|
|
|
2521
|
+
/**
|
|
2522
|
+
* SDK sign-in with the customer's own login.
|
|
2523
|
+
*
|
|
2524
|
+
* The host app hands us `getToken()` — a function THEY write that asks their
|
|
2525
|
+
* backend for a short-lived JWT signed with their SDK secret. We exchange it at
|
|
2526
|
+
* sa-api (`POST /auth/sdk/exchange`) for OUR 15-minute access token, which the
|
|
2527
|
+
* WebSocket relay accepts at handshake.
|
|
2528
|
+
*
|
|
2529
|
+
* There is no refresh token in this mode: the customer's own session is the
|
|
2530
|
+
* long-lived one. To renew we simply call `getToken()` again and re-exchange —
|
|
2531
|
+
* before every (re)connect when ours is about to expire, and on a timer a
|
|
2532
|
+
* couple of minutes ahead, so a reconnect never has to wait for it.
|
|
2533
|
+
*
|
|
2534
|
+
* Failures are split in two:
|
|
2535
|
+
* - fatal (their token rejected, SDK not enabled, user deactivated, or
|
|
2536
|
+
* `getToken()` itself failing): reported once through `onAuthError`, and
|
|
2537
|
+
* every later call fails fast with the same error — no loop against their
|
|
2538
|
+
* backend or ours — until `reset()`.
|
|
2539
|
+
* - transient (network, sa-api 5xx / 429): thrown to the caller, whose normal
|
|
2540
|
+
* reconnect back-off retries.
|
|
2541
|
+
*/
|
|
2542
|
+
declare const DEFAULT_API_URL = "https://sa-api.superatom.ai";
|
|
2543
|
+
/** The signed-in user, as returned by the exchange. `id` is OUR user id. */
|
|
2544
|
+
interface SdkUser {
|
|
2545
|
+
id: string;
|
|
2546
|
+
email: string;
|
|
2547
|
+
name: string;
|
|
2548
|
+
/** The role this session acts with — always "member" for SDK sessions. */
|
|
2549
|
+
role: string;
|
|
2550
|
+
/** Their own role names, from the `roles` claim. */
|
|
2551
|
+
externalRoles: string[];
|
|
2552
|
+
}
|
|
2553
|
+
type SuperAtomAuthErrorCode =
|
|
2554
|
+
/** `getToken()` threw or returned no token. */
|
|
2555
|
+
'get_token_failed'
|
|
2556
|
+
/** sa-api refused the token (400 / 401 / 403). `status` and `message` say why. */
|
|
2557
|
+
| 'exchange_rejected'
|
|
2558
|
+
/** sa-api unavailable (5xx / 429). Retried. */
|
|
2559
|
+
| 'exchange_unavailable'
|
|
2560
|
+
/** Could not reach sa-api, or it timed out. Retried. */
|
|
2561
|
+
| 'network';
|
|
2562
|
+
declare class SuperAtomAuthError extends Error {
|
|
2563
|
+
readonly code: SuperAtomAuthErrorCode;
|
|
2564
|
+
/** HTTP status from sa-api, when there was a response. */
|
|
2565
|
+
readonly status?: number;
|
|
2566
|
+
/** True when retrying cannot help — see the module comment. */
|
|
2567
|
+
readonly fatal: boolean;
|
|
2568
|
+
constructor(code: SuperAtomAuthErrorCode, message: string, options: {
|
|
2569
|
+
status?: number;
|
|
2570
|
+
fatal: boolean;
|
|
2571
|
+
cause?: unknown;
|
|
2572
|
+
});
|
|
2573
|
+
}
|
|
2574
|
+
interface SdkSessionOptions {
|
|
2575
|
+
projectId: string;
|
|
2576
|
+
/** Returns the customer-signed JWT. Written by the host app. */
|
|
2577
|
+
getToken: () => Promise<string> | string;
|
|
2578
|
+
/** Called once for each fatal failure. */
|
|
2579
|
+
onAuthError?: (error: SuperAtomAuthError) => void;
|
|
2580
|
+
/** Called after each successful exchange. */
|
|
2581
|
+
onSession?: (user: SdkUser) => void;
|
|
2582
|
+
/**
|
|
2583
|
+
* Sign-in keeps failing for a retryable reason (Superatom unreachable or down),
|
|
2584
|
+
* after a couple of attempts. Called again on each further failure, and with
|
|
2585
|
+
* null once a sign-in succeeds.
|
|
2586
|
+
*/
|
|
2587
|
+
onRetrying?: (error: SuperAtomAuthError | null) => void;
|
|
2588
|
+
/** sa-api base URL. Default: prod. */
|
|
2589
|
+
apiUrl?: string;
|
|
2590
|
+
debug?: boolean;
|
|
2591
|
+
}
|
|
2592
|
+
declare class SdkSession {
|
|
2593
|
+
private readonly opts;
|
|
2594
|
+
private readonly apiUrl;
|
|
2595
|
+
private token;
|
|
2596
|
+
private expiresAt;
|
|
2597
|
+
private currentUser;
|
|
2598
|
+
/** The one renewal in flight — every caller shares it. */
|
|
2599
|
+
private inFlight;
|
|
2600
|
+
private fatalError;
|
|
2601
|
+
/** Retryable failures in a row; reset by a successful exchange. */
|
|
2602
|
+
private retries;
|
|
2603
|
+
private renewTimer;
|
|
2604
|
+
private stopped;
|
|
2605
|
+
constructor(opts: SdkSessionOptions);
|
|
2606
|
+
get user(): SdkUser | null;
|
|
2607
|
+
/** The fatal error that stopped the session, if any. */
|
|
2608
|
+
get error(): SuperAtomAuthError | null;
|
|
2609
|
+
/**
|
|
2610
|
+
* A token with at least a minute left — the cached one, or a fresh exchange.
|
|
2611
|
+
* Rejects with SuperAtomAuthError.
|
|
2612
|
+
*/
|
|
2613
|
+
getAccessToken(): Promise<string>;
|
|
2614
|
+
/** Clear a fatal error so the next getAccessToken() tries again (e.g. after the user signs in again). */
|
|
2615
|
+
reset(): void;
|
|
2616
|
+
/** Stop renewing — the host unmounted or disconnected. */
|
|
2617
|
+
stop(): void;
|
|
2618
|
+
private renew;
|
|
2619
|
+
private exchange;
|
|
2620
|
+
/** Record a failure: a fatal one stops the session and is reported once. */
|
|
2621
|
+
private fail;
|
|
2622
|
+
/**
|
|
2623
|
+
* Renew in the background ahead of expiry. Timers are paused while the machine
|
|
2624
|
+
* sleeps and fire on wake; a reconnect after wake also renews first if needed.
|
|
2625
|
+
*/
|
|
2626
|
+
private scheduleRenew;
|
|
2627
|
+
private clearRenewTimer;
|
|
2628
|
+
private log;
|
|
2629
|
+
}
|
|
2630
|
+
|
|
2479
2631
|
/**
|
|
2480
2632
|
* Component mount function type
|
|
2481
2633
|
*/
|
|
@@ -3649,9 +3801,27 @@ interface ChatMessage {
|
|
|
3649
3801
|
}
|
|
3650
3802
|
|
|
3651
3803
|
interface UseSuperAtomOptions {
|
|
3804
|
+
/** A Superatom session token, passed directly (our own apps). Use `getToken` for SDK sign-in instead. */
|
|
3652
3805
|
token?: string;
|
|
3653
3806
|
userId?: string;
|
|
3654
3807
|
projectId: string;
|
|
3808
|
+
/**
|
|
3809
|
+
* SDK sign-in with your own login: return a short-lived JWT for the signed-in
|
|
3810
|
+
* user, signed by YOUR backend with your Superatom SDK secret. Called at start
|
|
3811
|
+
* and again whenever the session needs renewing — e.g.
|
|
3812
|
+
* `() => fetch('/api/superatom-token').then(r => r.text())`.
|
|
3813
|
+
*/
|
|
3814
|
+
getToken?: () => Promise<string> | string;
|
|
3815
|
+
/**
|
|
3816
|
+
* Called when sign-in fails in a way retrying cannot fix: `getToken` threw, or
|
|
3817
|
+
* Superatom refused the token (invalid, SDK not enabled, user deactivated).
|
|
3818
|
+
* The SDK stops reconnecting; call `reconnect()` once the user can sign in again.
|
|
3819
|
+
*/
|
|
3820
|
+
onAuthError?: (error: SuperAtomAuthError) => void;
|
|
3821
|
+
/** sa-api URL. Default: prod. For testing against dev / local only. */
|
|
3822
|
+
apiUrl?: string;
|
|
3823
|
+
/** WebSocket URL. Default: prod. For testing against dev / local only. */
|
|
3824
|
+
wsUrl?: string;
|
|
3655
3825
|
debug?: boolean;
|
|
3656
3826
|
streaming?: boolean;
|
|
3657
3827
|
}
|
|
@@ -3674,6 +3844,11 @@ interface UseSuperAtomReturn {
|
|
|
3674
3844
|
newChat: () => void;
|
|
3675
3845
|
/** A saved thread's messages are loading */
|
|
3676
3846
|
isLoadingThread: boolean;
|
|
3847
|
+
/**
|
|
3848
|
+
* The chat is ready and empty — show a greeting (e.g. `<NewChatHero>`) instead
|
|
3849
|
+
* of the message list. Saves every app computing the same condition.
|
|
3850
|
+
*/
|
|
3851
|
+
isNewChat: boolean;
|
|
3677
3852
|
/** Re-fetch the thread list */
|
|
3678
3853
|
refreshThreads: () => void;
|
|
3679
3854
|
/** Delete a thread and all its messages; if it's the open one, starts a new chat */
|
|
@@ -3686,8 +3861,14 @@ interface UseSuperAtomReturn {
|
|
|
3686
3861
|
success: boolean;
|
|
3687
3862
|
error?: string;
|
|
3688
3863
|
}>;
|
|
3864
|
+
/** The signed-in user (SDK sign-in with `getToken` only; null until signed in). */
|
|
3865
|
+
user: SdkUser | null;
|
|
3866
|
+
/** The sign-in failure that stopped the SDK, if any (same as passed to `onAuthError`). */
|
|
3867
|
+
authError: SuperAtomAuthError | null;
|
|
3868
|
+
/** Try signing in and connecting again — e.g. after the user signed in again on your side. */
|
|
3869
|
+
reconnect: () => void;
|
|
3689
3870
|
}
|
|
3690
|
-
declare function useSuperAtom({ token, userId, projectId, debug, streaming }: UseSuperAtomOptions): UseSuperAtomReturn;
|
|
3871
|
+
declare function useSuperAtom({ token, userId, projectId, getToken, onAuthError, apiUrl, wsUrl, debug, streaming, }: UseSuperAtomOptions): UseSuperAtomReturn;
|
|
3691
3872
|
|
|
3692
3873
|
interface ChatInputProps {
|
|
3693
3874
|
input: string;
|
|
@@ -3708,6 +3889,13 @@ interface MessageListProps {
|
|
|
3708
3889
|
bundleReady: boolean;
|
|
3709
3890
|
connectingText?: string;
|
|
3710
3891
|
emptyText?: string;
|
|
3892
|
+
/**
|
|
3893
|
+
* Shown in place of `emptyText` while the chat is empty — e.g. a greeting, or
|
|
3894
|
+
* `<NewChatHero>` with the input inside it. With this, the whole chat is just
|
|
3895
|
+
* <MessageList /> + <ChatInput />; without it, render your own empty screen
|
|
3896
|
+
* using the hook's `isNewChat`.
|
|
3897
|
+
*/
|
|
3898
|
+
emptyState?: ReactNode;
|
|
3711
3899
|
className?: string;
|
|
3712
3900
|
/** A response is in flight — shows a Stop button on the latest assistant message */
|
|
3713
3901
|
isResponding?: boolean;
|
|
@@ -3716,7 +3904,7 @@ interface MessageListProps {
|
|
|
3716
3904
|
isLoadingThread?: boolean;
|
|
3717
3905
|
loadingThreadText?: string;
|
|
3718
3906
|
}
|
|
3719
|
-
declare function MessageList({ messages, bundleReady, connectingText, emptyText, className, isResponding, onStop, isLoadingThread, loadingThreadText, }: MessageListProps): react_jsx_runtime.JSX.Element;
|
|
3907
|
+
declare function MessageList({ messages, bundleReady, connectingText, emptyText, emptyState, className, isResponding, onStop, isLoadingThread, loadingThreadText, }: MessageListProps): react_jsx_runtime.JSX.Element;
|
|
3720
3908
|
|
|
3721
3909
|
interface MessageBubbleProps {
|
|
3722
3910
|
message: ChatMessage;
|
|
@@ -3818,6 +4006,6 @@ declare const MenuV1RendererCollapsed: React__default.FC<MenuV1RendererCollapsed
|
|
|
3818
4006
|
* @superatomai/application-sdk
|
|
3819
4007
|
* SuperAtom Application SDK - WebSocket client, DSL renderer, and pre-built chat UI
|
|
3820
4008
|
*/
|
|
3821
|
-
declare const SDK_VERSION = "0.0.
|
|
4009
|
+
declare const SDK_VERSION = "0.0.3";
|
|
3822
4010
|
|
|
3823
|
-
export { type ActionsRequestMessage, ActionsRequestMessageSchema, type ActionsRequestPayload, ActionsRequestPayloadSchema, type ActionsResponseMessage, ActionsResponseMessageSchema, type ActionsResponsePayload, ActionsResponsePayloadSchema, type Binding, BindingSchema, type BundleChunkMessage, BundleChunkMessageSchema, type BundleChunkPayload, BundleChunkPayloadSchema, type BundleErrorMessage, BundleErrorMessageSchema, type BundleErrorPayload, BundleErrorPayloadSchema, type BundleRequestMessage, BundleRequestMessageSchema, type BundleRequestPayload, BundleRequestPayloadSchema, COMP_REGISTRY, ChatInput, type ChatInputProps, type ChatMessage, type ClientConfig, ClientConfigSchema, type Component, type ComponentDefinition, type ComponentRegistryType, ComponentSchema, type ComponentsRegistry, type ComponentsSendMessage, ComponentsSendMessageSchema, type ComponentsSendPayload, ComponentsSendPayloadSchema, ConfirmDeleteModal, type ConfirmDeleteModalProps, DSLErrorBoundary, DSLRenderer, type DSLRendererProps, DSLRendererPropsSchema, type DataRequestMessage, DataRequestMessageSchema, type DataRequestPayload, DataRequestPayloadSchema, type DataResponseMessage, DataResponseMessageSchema, type DataResponsePayload, DataResponsePayloadSchema, DynamicComponent, type Expression, ExpressionSchema, type ForDirective, ForDirectiveSchema, type MenuData, MenuDataSchema, type MenuQueryFilters, MenuQueryFiltersSchema, type MenuV1Item, MenuV1Renderer, MenuV1RendererCollapsed, type MenuV1Root, type MenusRequestMessage, MenusRequestMessageSchema, type MenusRequestPayload, MenusRequestPayloadSchema, type MenusResponseMessage, MenusResponseMessageSchema, type MenusResponsePayload, MenusResponsePayloadSchema, type Message, MessageBubble, type MessageBubbleProps, MessageList, type MessageListProps, type MessageParticipant, MessageParticipantSchema, MessageSchema, type MountFunction, NewChatHero, type NewChatHeroProps, type QuerySpec, QuerySpecSchema, type ResolvedClientConfig, SDK_VERSION, Sidebar, type SidebarProps, type SuperAtomGlobal, SuperatomClient, type ThreadConversationRow, type ThreadSummary, type UIComponent, UIComponentSchema, type UIElement, UIElementSchema, type UILogEntry, UILogEntrySchema, type UILogsMessage, UILogsMessageSchema, type UILogsPayload, UILogsPayloadSchema, type UseSuperAtomOptions, type UseSuperAtomReturn, type UserPromptAbortRequestMessage, UserPromptAbortRequestMessageSchema, type UserPromptAbortRequestPayload, UserPromptAbortRequestPayloadSchema, type UserPromptRequestMessage, UserPromptRequestMessageSchema, type UserPromptRequestPayload, UserPromptRequestPayloadSchema, type UserPromptResponseMessage, UserPromptResponseMessageSchema, type UserPromptResponsePayload, UserPromptResponsePayloadSchema, type UserPromptSuggestionsRequestMessage, UserPromptSuggestionsRequestMessageSchema, type UserPromptSuggestionsRequestPayload, UserPromptSuggestionsRequestPayloadSchema, type UserPromptSuggestionsResponseMessage, UserPromptSuggestionsResponseMessageSchema, type UserPromptSuggestionsResponsePayload, UserPromptSuggestionsResponsePayloadSchema, getComponent, getComponentStates, getComponents, hasComponents, registerBundleComponents, resetAllFailedComponents, resetFailedComponent, resetRegistration, sanitizeDSL, index as services, setup, useDynamicComponent, useSuperAtom, validateDSL, validateUIComponent, validateUIElement, withConditionalErrorBoundary };
|
|
4011
|
+
export { type ActionsRequestMessage, ActionsRequestMessageSchema, type ActionsRequestPayload, ActionsRequestPayloadSchema, type ActionsResponseMessage, ActionsResponseMessageSchema, type ActionsResponsePayload, ActionsResponsePayloadSchema, type Binding, BindingSchema, type BundleChunkMessage, BundleChunkMessageSchema, type BundleChunkPayload, BundleChunkPayloadSchema, type BundleErrorMessage, BundleErrorMessageSchema, type BundleErrorPayload, BundleErrorPayloadSchema, type BundleRequestMessage, BundleRequestMessageSchema, type BundleRequestPayload, BundleRequestPayloadSchema, COMP_REGISTRY, ChatInput, type ChatInputProps, type ChatMessage, type ClientConfig, ClientConfigSchema, type Component, type ComponentDefinition, type ComponentRegistryType, ComponentSchema, type ComponentsRegistry, type ComponentsSendMessage, ComponentsSendMessageSchema, type ComponentsSendPayload, ComponentsSendPayloadSchema, ConfirmDeleteModal, type ConfirmDeleteModalProps, DEFAULT_API_URL, DSLErrorBoundary, DSLRenderer, type DSLRendererProps, DSLRendererPropsSchema, type DataRequestMessage, DataRequestMessageSchema, type DataRequestPayload, DataRequestPayloadSchema, type DataResponseMessage, DataResponseMessageSchema, type DataResponsePayload, DataResponsePayloadSchema, DynamicComponent, type Expression, ExpressionSchema, type ForDirective, ForDirectiveSchema, type MenuData, MenuDataSchema, type MenuQueryFilters, MenuQueryFiltersSchema, type MenuV1Item, MenuV1Renderer, MenuV1RendererCollapsed, type MenuV1Root, type MenusRequestMessage, MenusRequestMessageSchema, type MenusRequestPayload, MenusRequestPayloadSchema, type MenusResponseMessage, MenusResponseMessageSchema, type MenusResponsePayload, MenusResponsePayloadSchema, type Message, MessageBubble, type MessageBubbleProps, MessageList, type MessageListProps, type MessageParticipant, MessageParticipantSchema, MessageSchema, type MountFunction, NewChatHero, type NewChatHeroProps, type QuerySpec, QuerySpecSchema, type ResolvedClientConfig, SDK_VERSION, SdkSession, type SdkSessionOptions, type SdkUser, Sidebar, type SidebarProps, SuperAtomAuthError, type SuperAtomAuthErrorCode, type SuperAtomGlobal, SuperatomClient, type ThreadConversationRow, type ThreadSummary, type UIComponent, UIComponentSchema, type UIElement, UIElementSchema, type UILogEntry, UILogEntrySchema, type UILogsMessage, UILogsMessageSchema, type UILogsPayload, UILogsPayloadSchema, type UseSuperAtomOptions, type UseSuperAtomReturn, type UserPromptAbortRequestMessage, UserPromptAbortRequestMessageSchema, type UserPromptAbortRequestPayload, UserPromptAbortRequestPayloadSchema, type UserPromptRequestMessage, UserPromptRequestMessageSchema, type UserPromptRequestPayload, UserPromptRequestPayloadSchema, type UserPromptResponseMessage, UserPromptResponseMessageSchema, type UserPromptResponsePayload, UserPromptResponsePayloadSchema, type UserPromptSuggestionsRequestMessage, UserPromptSuggestionsRequestMessageSchema, type UserPromptSuggestionsRequestPayload, UserPromptSuggestionsRequestPayloadSchema, type UserPromptSuggestionsResponseMessage, UserPromptSuggestionsResponseMessageSchema, type UserPromptSuggestionsResponsePayload, UserPromptSuggestionsResponsePayloadSchema, getComponent, getComponentStates, getComponents, hasComponents, registerBundleComponents, resetAllFailedComponents, resetFailedComponent, resetRegistration, sanitizeDSL, index as services, setup, useDynamicComponent, useSuperAtom, validateDSL, validateUIComponent, validateUIElement, withConditionalErrorBoundary };
|
package/dist/index.d.ts
CHANGED
|
@@ -1059,7 +1059,15 @@ declare const ClientConfigSchema: z.ZodObject<{
|
|
|
1059
1059
|
debug: z.ZodDefault<z.ZodBoolean>;
|
|
1060
1060
|
token: z.ZodOptional<z.ZodString>;
|
|
1061
1061
|
}, z.core.$strip>;
|
|
1062
|
-
type ClientConfig = z.input<typeof ClientConfigSchema
|
|
1062
|
+
type ClientConfig = z.input<typeof ClientConfigSchema> & {
|
|
1063
|
+
/**
|
|
1064
|
+
* Called before every (re)connect for a valid session token, replacing
|
|
1065
|
+
* `token`. Used for SDK sign-in (see SdkSession in auth.ts). Rejecting with an
|
|
1066
|
+
* error whose `fatal` is true stops reconnecting; any other rejection is
|
|
1067
|
+
* retried with the normal back-off.
|
|
1068
|
+
*/
|
|
1069
|
+
getAccessToken?: () => Promise<string>;
|
|
1070
|
+
};
|
|
1063
1071
|
type ResolvedClientConfig = z.output<typeof ClientConfigSchema>;
|
|
1064
1072
|
|
|
1065
1073
|
/**
|
|
@@ -1847,6 +1855,19 @@ declare function deleteThread(client: SuperatomClient, userId: string, threadId:
|
|
|
1847
1855
|
message?: string;
|
|
1848
1856
|
deletedCount?: number;
|
|
1849
1857
|
}>;
|
|
1858
|
+
/**
|
|
1859
|
+
* Delete one saved question/answer, by the question that produced it.
|
|
1860
|
+
*
|
|
1861
|
+
* `clearCache` also drops what was cached for it (query results and embeddings),
|
|
1862
|
+
* so asking the same thing again is answered from the data, not from the old
|
|
1863
|
+
* result. Same call Runtime-react's trash button makes.
|
|
1864
|
+
*/
|
|
1865
|
+
declare function deleteUserConversation(client: SuperatomClient, userPrompt: string, userId?: string, clearCache?: boolean, timeout?: number): Promise<{
|
|
1866
|
+
success: boolean;
|
|
1867
|
+
error?: string;
|
|
1868
|
+
message?: string;
|
|
1869
|
+
queriesDeleted?: number;
|
|
1870
|
+
}>;
|
|
1850
1871
|
/**
|
|
1851
1872
|
* Rename a thread's title.
|
|
1852
1873
|
*/
|
|
@@ -1897,6 +1918,7 @@ declare const index_createBookmark: typeof createBookmark;
|
|
|
1897
1918
|
declare const index_deleteArtifact: typeof deleteArtifact;
|
|
1898
1919
|
declare const index_deleteBookmark: typeof deleteBookmark;
|
|
1899
1920
|
declare const index_deleteThread: typeof deleteThread;
|
|
1921
|
+
declare const index_deleteUserConversation: typeof deleteUserConversation;
|
|
1900
1922
|
declare const index_getActions: typeof getActions;
|
|
1901
1923
|
declare const index_getAllArtifacts: typeof getAllArtifacts;
|
|
1902
1924
|
declare const index_getAllBookmarks: typeof getAllBookmarks;
|
|
@@ -1931,7 +1953,7 @@ declare const index_sendUserPromptSuggestionsRequest: typeof sendUserPromptSugge
|
|
|
1931
1953
|
declare const index_updateBookmark: typeof updateBookmark;
|
|
1932
1954
|
declare const index_updateThreadTitle: typeof updateThreadTitle;
|
|
1933
1955
|
declare namespace index {
|
|
1934
|
-
export { type index_Artifact as Artifact, type Binding$1 as Binding, BindingSchema$1 as BindingSchema, type index_Bookmark as Bookmark, type index_CreateBookmarkOptions as CreateBookmarkOptions, type DSLRendererProps$3 as DSLRendererProps, DSLRendererPropsSchema$3 as DSLRendererPropsSchema, type index_Dashboard as Dashboard, type Expression$1 as Expression, ExpressionSchema$1 as ExpressionSchema, type ForDirective$1 as ForDirective, ForDirectiveSchema$1 as ForDirectiveSchema, type index_Menu as Menu, type index_Page as Page, index_PageSchema as PageSchema, type index_QueryArtifactsFilters as QueryArtifactsFilters, type index_QueryArtifactsOptions as QueryArtifactsOptions, type index_QueryBookmarksOptions as QueryBookmarksOptions, type index_QueryDashboardsOptions as QueryDashboardsOptions, type index_QueryMenusOptions as QueryMenusOptions, type index_QueryReportsOptions as QueryReportsOptions, type QuerySpec$1 as QuerySpec, QuerySpecSchema$1 as QuerySpecSchema, type index_QueryUIsOptions as QueryUIsOptions, type index_QueryUsersOptions as QueryUsersOptions, type index_Report as Report, type DSLRendererProps$2 as ReportDSLRendererProps, type index_ThreadConversationRow as ThreadConversationRow, type index_ThreadSummary as ThreadSummary, type index_UI as UI, type UIComponent$1 as UIComponent, UIComponentSchema$1 as UIComponentSchema, type DSLRendererProps$1 as UIDSLRendererProps, type UIElement$1 as UIElement, UIElementSchema$1 as UIElementSchema, type index_UpdateBookmarkOptions as UpdateBookmarkOptions, type index_User as User, index_abortUserPromptRequest as abortUserPromptRequest, index_createBookmark as createBookmark, index_deleteArtifact as deleteArtifact, index_deleteBookmark as deleteBookmark, index_deleteThread as deleteThread, index_getActions as getActions, index_getAllArtifacts as getAllArtifacts, index_getAllBookmarks as getAllBookmarks, index_getAllDashboards as getAllDashboards, index_getAllMenus as getAllMenus, index_getAllReports as getAllReports, index_getAllUIs as getAllUIs, index_getArtifact as getArtifact, index_getBookmark as getBookmark, index_getChildMenus as getChildMenus, index_getDashboard as getDashboard, index_getMenu as getMenu, index_getMenusHierarchy as getMenusHierarchy, index_getReport as getReport, index_getRootMenus as getRootMenus, index_getThreadConversations as getThreadConversations, index_getUI as getUI, index_getUserThreads as getUserThreads, index_injectBundleStyles as injectBundleStyles, index_queryArtifacts as queryArtifacts, index_queryBookmarks as queryBookmarks, index_queryDashboards as queryDashboards, index_queryMenus as queryMenus, index_queryReports as queryReports, index_queryUIs as queryUIs, index_queryUsers as queryUsers, index_requestBundle as requestBundle, index_requestData as requestData, index_sendComponents as sendComponents, index_sendUserPromptRequest as sendUserPromptRequest, index_sendUserPromptSuggestionsRequest as sendUserPromptSuggestionsRequest, index_updateBookmark as updateBookmark, index_updateThreadTitle as updateThreadTitle };
|
|
1956
|
+
export { type index_Artifact as Artifact, type Binding$1 as Binding, BindingSchema$1 as BindingSchema, type index_Bookmark as Bookmark, type index_CreateBookmarkOptions as CreateBookmarkOptions, type DSLRendererProps$3 as DSLRendererProps, DSLRendererPropsSchema$3 as DSLRendererPropsSchema, type index_Dashboard as Dashboard, type Expression$1 as Expression, ExpressionSchema$1 as ExpressionSchema, type ForDirective$1 as ForDirective, ForDirectiveSchema$1 as ForDirectiveSchema, type index_Menu as Menu, type index_Page as Page, index_PageSchema as PageSchema, type index_QueryArtifactsFilters as QueryArtifactsFilters, type index_QueryArtifactsOptions as QueryArtifactsOptions, type index_QueryBookmarksOptions as QueryBookmarksOptions, type index_QueryDashboardsOptions as QueryDashboardsOptions, type index_QueryMenusOptions as QueryMenusOptions, type index_QueryReportsOptions as QueryReportsOptions, type QuerySpec$1 as QuerySpec, QuerySpecSchema$1 as QuerySpecSchema, type index_QueryUIsOptions as QueryUIsOptions, type index_QueryUsersOptions as QueryUsersOptions, type index_Report as Report, type DSLRendererProps$2 as ReportDSLRendererProps, type index_ThreadConversationRow as ThreadConversationRow, type index_ThreadSummary as ThreadSummary, type index_UI as UI, type UIComponent$1 as UIComponent, UIComponentSchema$1 as UIComponentSchema, type DSLRendererProps$1 as UIDSLRendererProps, type UIElement$1 as UIElement, UIElementSchema$1 as UIElementSchema, type index_UpdateBookmarkOptions as UpdateBookmarkOptions, type index_User as User, index_abortUserPromptRequest as abortUserPromptRequest, index_createBookmark as createBookmark, index_deleteArtifact as deleteArtifact, index_deleteBookmark as deleteBookmark, index_deleteThread as deleteThread, index_deleteUserConversation as deleteUserConversation, index_getActions as getActions, index_getAllArtifacts as getAllArtifacts, index_getAllBookmarks as getAllBookmarks, index_getAllDashboards as getAllDashboards, index_getAllMenus as getAllMenus, index_getAllReports as getAllReports, index_getAllUIs as getAllUIs, index_getArtifact as getArtifact, index_getBookmark as getBookmark, index_getChildMenus as getChildMenus, index_getDashboard as getDashboard, index_getMenu as getMenu, index_getMenusHierarchy as getMenusHierarchy, index_getReport as getReport, index_getRootMenus as getRootMenus, index_getThreadConversations as getThreadConversations, index_getUI as getUI, index_getUserThreads as getUserThreads, index_injectBundleStyles as injectBundleStyles, index_queryArtifacts as queryArtifacts, index_queryBookmarks as queryBookmarks, index_queryDashboards as queryDashboards, index_queryMenus as queryMenus, index_queryReports as queryReports, index_queryUIs as queryUIs, index_queryUsers as queryUsers, index_requestBundle as requestBundle, index_requestData as requestData, index_sendComponents as sendComponents, index_sendUserPromptRequest as sendUserPromptRequest, index_sendUserPromptSuggestionsRequest as sendUserPromptSuggestionsRequest, index_updateBookmark as updateBookmark, index_updateThreadTitle as updateThreadTitle };
|
|
1935
1957
|
}
|
|
1936
1958
|
|
|
1937
1959
|
type MessageHandler = (message: Message) => void;
|
|
@@ -1956,6 +1978,8 @@ declare class SuperatomClient {
|
|
|
1956
1978
|
private config;
|
|
1957
1979
|
private connectPromise;
|
|
1958
1980
|
private connectResolve;
|
|
1981
|
+
private getAccessToken;
|
|
1982
|
+
private fetchingToken;
|
|
1959
1983
|
private heartbeatInterval;
|
|
1960
1984
|
private pongDeadline;
|
|
1961
1985
|
private readonly HEARTBEAT_INTERVAL_MS;
|
|
@@ -2024,6 +2048,14 @@ declare class SuperatomClient {
|
|
|
2024
2048
|
* window 'online' / 'visibilitychange' handlers.
|
|
2025
2049
|
*/
|
|
2026
2050
|
forceReconnect(): Promise<void>;
|
|
2051
|
+
/**
|
|
2052
|
+
* Drop the current socket without triggering its handlers: they are detached
|
|
2053
|
+
* first, so its eventual real close is a no-op (on Linux/Chrome that close
|
|
2054
|
+
* can arrive 30-60s later). Returns whether it was open.
|
|
2055
|
+
*/
|
|
2056
|
+
private discardSocket;
|
|
2057
|
+
/** A connection attempt is under way — fetching the session token, or the socket handshake. */
|
|
2058
|
+
private isConnecting;
|
|
2027
2059
|
/**
|
|
2028
2060
|
* Attach window-level listeners that catch network changes faster than
|
|
2029
2061
|
* the socket's own onclose. The browser's onclose for a half-open TCP can
|
|
@@ -2047,6 +2079,16 @@ declare class SuperatomClient {
|
|
|
2047
2079
|
* The Promise never rejects - failures are logged silently and auto-reconnect is triggered
|
|
2048
2080
|
*/
|
|
2049
2081
|
connect(): Promise<void>;
|
|
2082
|
+
/**
|
|
2083
|
+
* Get a valid session token, then open the socket. The relay checks the token
|
|
2084
|
+
* only at handshake, so every (re)connect must present one that is still valid.
|
|
2085
|
+
*
|
|
2086
|
+
* A fatal auth failure (see SuperAtomAuthError.fatal) stops reconnecting — the
|
|
2087
|
+
* session reports it to the host, and retrying would only repeat it. Anything
|
|
2088
|
+
* else goes through the normal back-off.
|
|
2089
|
+
*/
|
|
2090
|
+
private openWithFreshToken;
|
|
2091
|
+
private openSocket;
|
|
2050
2092
|
/**
|
|
2051
2093
|
* Disconnect from WebSocket server
|
|
2052
2094
|
*/
|
|
@@ -2476,6 +2518,116 @@ declare class SuperatomClient {
|
|
|
2476
2518
|
private log;
|
|
2477
2519
|
}
|
|
2478
2520
|
|
|
2521
|
+
/**
|
|
2522
|
+
* SDK sign-in with the customer's own login.
|
|
2523
|
+
*
|
|
2524
|
+
* The host app hands us `getToken()` — a function THEY write that asks their
|
|
2525
|
+
* backend for a short-lived JWT signed with their SDK secret. We exchange it at
|
|
2526
|
+
* sa-api (`POST /auth/sdk/exchange`) for OUR 15-minute access token, which the
|
|
2527
|
+
* WebSocket relay accepts at handshake.
|
|
2528
|
+
*
|
|
2529
|
+
* There is no refresh token in this mode: the customer's own session is the
|
|
2530
|
+
* long-lived one. To renew we simply call `getToken()` again and re-exchange —
|
|
2531
|
+
* before every (re)connect when ours is about to expire, and on a timer a
|
|
2532
|
+
* couple of minutes ahead, so a reconnect never has to wait for it.
|
|
2533
|
+
*
|
|
2534
|
+
* Failures are split in two:
|
|
2535
|
+
* - fatal (their token rejected, SDK not enabled, user deactivated, or
|
|
2536
|
+
* `getToken()` itself failing): reported once through `onAuthError`, and
|
|
2537
|
+
* every later call fails fast with the same error — no loop against their
|
|
2538
|
+
* backend or ours — until `reset()`.
|
|
2539
|
+
* - transient (network, sa-api 5xx / 429): thrown to the caller, whose normal
|
|
2540
|
+
* reconnect back-off retries.
|
|
2541
|
+
*/
|
|
2542
|
+
declare const DEFAULT_API_URL = "https://sa-api.superatom.ai";
|
|
2543
|
+
/** The signed-in user, as returned by the exchange. `id` is OUR user id. */
|
|
2544
|
+
interface SdkUser {
|
|
2545
|
+
id: string;
|
|
2546
|
+
email: string;
|
|
2547
|
+
name: string;
|
|
2548
|
+
/** The role this session acts with — always "member" for SDK sessions. */
|
|
2549
|
+
role: string;
|
|
2550
|
+
/** Their own role names, from the `roles` claim. */
|
|
2551
|
+
externalRoles: string[];
|
|
2552
|
+
}
|
|
2553
|
+
type SuperAtomAuthErrorCode =
|
|
2554
|
+
/** `getToken()` threw or returned no token. */
|
|
2555
|
+
'get_token_failed'
|
|
2556
|
+
/** sa-api refused the token (400 / 401 / 403). `status` and `message` say why. */
|
|
2557
|
+
| 'exchange_rejected'
|
|
2558
|
+
/** sa-api unavailable (5xx / 429). Retried. */
|
|
2559
|
+
| 'exchange_unavailable'
|
|
2560
|
+
/** Could not reach sa-api, or it timed out. Retried. */
|
|
2561
|
+
| 'network';
|
|
2562
|
+
declare class SuperAtomAuthError extends Error {
|
|
2563
|
+
readonly code: SuperAtomAuthErrorCode;
|
|
2564
|
+
/** HTTP status from sa-api, when there was a response. */
|
|
2565
|
+
readonly status?: number;
|
|
2566
|
+
/** True when retrying cannot help — see the module comment. */
|
|
2567
|
+
readonly fatal: boolean;
|
|
2568
|
+
constructor(code: SuperAtomAuthErrorCode, message: string, options: {
|
|
2569
|
+
status?: number;
|
|
2570
|
+
fatal: boolean;
|
|
2571
|
+
cause?: unknown;
|
|
2572
|
+
});
|
|
2573
|
+
}
|
|
2574
|
+
interface SdkSessionOptions {
|
|
2575
|
+
projectId: string;
|
|
2576
|
+
/** Returns the customer-signed JWT. Written by the host app. */
|
|
2577
|
+
getToken: () => Promise<string> | string;
|
|
2578
|
+
/** Called once for each fatal failure. */
|
|
2579
|
+
onAuthError?: (error: SuperAtomAuthError) => void;
|
|
2580
|
+
/** Called after each successful exchange. */
|
|
2581
|
+
onSession?: (user: SdkUser) => void;
|
|
2582
|
+
/**
|
|
2583
|
+
* Sign-in keeps failing for a retryable reason (Superatom unreachable or down),
|
|
2584
|
+
* after a couple of attempts. Called again on each further failure, and with
|
|
2585
|
+
* null once a sign-in succeeds.
|
|
2586
|
+
*/
|
|
2587
|
+
onRetrying?: (error: SuperAtomAuthError | null) => void;
|
|
2588
|
+
/** sa-api base URL. Default: prod. */
|
|
2589
|
+
apiUrl?: string;
|
|
2590
|
+
debug?: boolean;
|
|
2591
|
+
}
|
|
2592
|
+
declare class SdkSession {
|
|
2593
|
+
private readonly opts;
|
|
2594
|
+
private readonly apiUrl;
|
|
2595
|
+
private token;
|
|
2596
|
+
private expiresAt;
|
|
2597
|
+
private currentUser;
|
|
2598
|
+
/** The one renewal in flight — every caller shares it. */
|
|
2599
|
+
private inFlight;
|
|
2600
|
+
private fatalError;
|
|
2601
|
+
/** Retryable failures in a row; reset by a successful exchange. */
|
|
2602
|
+
private retries;
|
|
2603
|
+
private renewTimer;
|
|
2604
|
+
private stopped;
|
|
2605
|
+
constructor(opts: SdkSessionOptions);
|
|
2606
|
+
get user(): SdkUser | null;
|
|
2607
|
+
/** The fatal error that stopped the session, if any. */
|
|
2608
|
+
get error(): SuperAtomAuthError | null;
|
|
2609
|
+
/**
|
|
2610
|
+
* A token with at least a minute left — the cached one, or a fresh exchange.
|
|
2611
|
+
* Rejects with SuperAtomAuthError.
|
|
2612
|
+
*/
|
|
2613
|
+
getAccessToken(): Promise<string>;
|
|
2614
|
+
/** Clear a fatal error so the next getAccessToken() tries again (e.g. after the user signs in again). */
|
|
2615
|
+
reset(): void;
|
|
2616
|
+
/** Stop renewing — the host unmounted or disconnected. */
|
|
2617
|
+
stop(): void;
|
|
2618
|
+
private renew;
|
|
2619
|
+
private exchange;
|
|
2620
|
+
/** Record a failure: a fatal one stops the session and is reported once. */
|
|
2621
|
+
private fail;
|
|
2622
|
+
/**
|
|
2623
|
+
* Renew in the background ahead of expiry. Timers are paused while the machine
|
|
2624
|
+
* sleeps and fire on wake; a reconnect after wake also renews first if needed.
|
|
2625
|
+
*/
|
|
2626
|
+
private scheduleRenew;
|
|
2627
|
+
private clearRenewTimer;
|
|
2628
|
+
private log;
|
|
2629
|
+
}
|
|
2630
|
+
|
|
2479
2631
|
/**
|
|
2480
2632
|
* Component mount function type
|
|
2481
2633
|
*/
|
|
@@ -3649,9 +3801,27 @@ interface ChatMessage {
|
|
|
3649
3801
|
}
|
|
3650
3802
|
|
|
3651
3803
|
interface UseSuperAtomOptions {
|
|
3804
|
+
/** A Superatom session token, passed directly (our own apps). Use `getToken` for SDK sign-in instead. */
|
|
3652
3805
|
token?: string;
|
|
3653
3806
|
userId?: string;
|
|
3654
3807
|
projectId: string;
|
|
3808
|
+
/**
|
|
3809
|
+
* SDK sign-in with your own login: return a short-lived JWT for the signed-in
|
|
3810
|
+
* user, signed by YOUR backend with your Superatom SDK secret. Called at start
|
|
3811
|
+
* and again whenever the session needs renewing — e.g.
|
|
3812
|
+
* `() => fetch('/api/superatom-token').then(r => r.text())`.
|
|
3813
|
+
*/
|
|
3814
|
+
getToken?: () => Promise<string> | string;
|
|
3815
|
+
/**
|
|
3816
|
+
* Called when sign-in fails in a way retrying cannot fix: `getToken` threw, or
|
|
3817
|
+
* Superatom refused the token (invalid, SDK not enabled, user deactivated).
|
|
3818
|
+
* The SDK stops reconnecting; call `reconnect()` once the user can sign in again.
|
|
3819
|
+
*/
|
|
3820
|
+
onAuthError?: (error: SuperAtomAuthError) => void;
|
|
3821
|
+
/** sa-api URL. Default: prod. For testing against dev / local only. */
|
|
3822
|
+
apiUrl?: string;
|
|
3823
|
+
/** WebSocket URL. Default: prod. For testing against dev / local only. */
|
|
3824
|
+
wsUrl?: string;
|
|
3655
3825
|
debug?: boolean;
|
|
3656
3826
|
streaming?: boolean;
|
|
3657
3827
|
}
|
|
@@ -3674,6 +3844,11 @@ interface UseSuperAtomReturn {
|
|
|
3674
3844
|
newChat: () => void;
|
|
3675
3845
|
/** A saved thread's messages are loading */
|
|
3676
3846
|
isLoadingThread: boolean;
|
|
3847
|
+
/**
|
|
3848
|
+
* The chat is ready and empty — show a greeting (e.g. `<NewChatHero>`) instead
|
|
3849
|
+
* of the message list. Saves every app computing the same condition.
|
|
3850
|
+
*/
|
|
3851
|
+
isNewChat: boolean;
|
|
3677
3852
|
/** Re-fetch the thread list */
|
|
3678
3853
|
refreshThreads: () => void;
|
|
3679
3854
|
/** Delete a thread and all its messages; if it's the open one, starts a new chat */
|
|
@@ -3686,8 +3861,14 @@ interface UseSuperAtomReturn {
|
|
|
3686
3861
|
success: boolean;
|
|
3687
3862
|
error?: string;
|
|
3688
3863
|
}>;
|
|
3864
|
+
/** The signed-in user (SDK sign-in with `getToken` only; null until signed in). */
|
|
3865
|
+
user: SdkUser | null;
|
|
3866
|
+
/** The sign-in failure that stopped the SDK, if any (same as passed to `onAuthError`). */
|
|
3867
|
+
authError: SuperAtomAuthError | null;
|
|
3868
|
+
/** Try signing in and connecting again — e.g. after the user signed in again on your side. */
|
|
3869
|
+
reconnect: () => void;
|
|
3689
3870
|
}
|
|
3690
|
-
declare function useSuperAtom({ token, userId, projectId, debug, streaming }: UseSuperAtomOptions): UseSuperAtomReturn;
|
|
3871
|
+
declare function useSuperAtom({ token, userId, projectId, getToken, onAuthError, apiUrl, wsUrl, debug, streaming, }: UseSuperAtomOptions): UseSuperAtomReturn;
|
|
3691
3872
|
|
|
3692
3873
|
interface ChatInputProps {
|
|
3693
3874
|
input: string;
|
|
@@ -3708,6 +3889,13 @@ interface MessageListProps {
|
|
|
3708
3889
|
bundleReady: boolean;
|
|
3709
3890
|
connectingText?: string;
|
|
3710
3891
|
emptyText?: string;
|
|
3892
|
+
/**
|
|
3893
|
+
* Shown in place of `emptyText` while the chat is empty — e.g. a greeting, or
|
|
3894
|
+
* `<NewChatHero>` with the input inside it. With this, the whole chat is just
|
|
3895
|
+
* <MessageList /> + <ChatInput />; without it, render your own empty screen
|
|
3896
|
+
* using the hook's `isNewChat`.
|
|
3897
|
+
*/
|
|
3898
|
+
emptyState?: ReactNode;
|
|
3711
3899
|
className?: string;
|
|
3712
3900
|
/** A response is in flight — shows a Stop button on the latest assistant message */
|
|
3713
3901
|
isResponding?: boolean;
|
|
@@ -3716,7 +3904,7 @@ interface MessageListProps {
|
|
|
3716
3904
|
isLoadingThread?: boolean;
|
|
3717
3905
|
loadingThreadText?: string;
|
|
3718
3906
|
}
|
|
3719
|
-
declare function MessageList({ messages, bundleReady, connectingText, emptyText, className, isResponding, onStop, isLoadingThread, loadingThreadText, }: MessageListProps): react_jsx_runtime.JSX.Element;
|
|
3907
|
+
declare function MessageList({ messages, bundleReady, connectingText, emptyText, emptyState, className, isResponding, onStop, isLoadingThread, loadingThreadText, }: MessageListProps): react_jsx_runtime.JSX.Element;
|
|
3720
3908
|
|
|
3721
3909
|
interface MessageBubbleProps {
|
|
3722
3910
|
message: ChatMessage;
|
|
@@ -3818,6 +4006,6 @@ declare const MenuV1RendererCollapsed: React__default.FC<MenuV1RendererCollapsed
|
|
|
3818
4006
|
* @superatomai/application-sdk
|
|
3819
4007
|
* SuperAtom Application SDK - WebSocket client, DSL renderer, and pre-built chat UI
|
|
3820
4008
|
*/
|
|
3821
|
-
declare const SDK_VERSION = "0.0.
|
|
4009
|
+
declare const SDK_VERSION = "0.0.3";
|
|
3822
4010
|
|
|
3823
|
-
export { type ActionsRequestMessage, ActionsRequestMessageSchema, type ActionsRequestPayload, ActionsRequestPayloadSchema, type ActionsResponseMessage, ActionsResponseMessageSchema, type ActionsResponsePayload, ActionsResponsePayloadSchema, type Binding, BindingSchema, type BundleChunkMessage, BundleChunkMessageSchema, type BundleChunkPayload, BundleChunkPayloadSchema, type BundleErrorMessage, BundleErrorMessageSchema, type BundleErrorPayload, BundleErrorPayloadSchema, type BundleRequestMessage, BundleRequestMessageSchema, type BundleRequestPayload, BundleRequestPayloadSchema, COMP_REGISTRY, ChatInput, type ChatInputProps, type ChatMessage, type ClientConfig, ClientConfigSchema, type Component, type ComponentDefinition, type ComponentRegistryType, ComponentSchema, type ComponentsRegistry, type ComponentsSendMessage, ComponentsSendMessageSchema, type ComponentsSendPayload, ComponentsSendPayloadSchema, ConfirmDeleteModal, type ConfirmDeleteModalProps, DSLErrorBoundary, DSLRenderer, type DSLRendererProps, DSLRendererPropsSchema, type DataRequestMessage, DataRequestMessageSchema, type DataRequestPayload, DataRequestPayloadSchema, type DataResponseMessage, DataResponseMessageSchema, type DataResponsePayload, DataResponsePayloadSchema, DynamicComponent, type Expression, ExpressionSchema, type ForDirective, ForDirectiveSchema, type MenuData, MenuDataSchema, type MenuQueryFilters, MenuQueryFiltersSchema, type MenuV1Item, MenuV1Renderer, MenuV1RendererCollapsed, type MenuV1Root, type MenusRequestMessage, MenusRequestMessageSchema, type MenusRequestPayload, MenusRequestPayloadSchema, type MenusResponseMessage, MenusResponseMessageSchema, type MenusResponsePayload, MenusResponsePayloadSchema, type Message, MessageBubble, type MessageBubbleProps, MessageList, type MessageListProps, type MessageParticipant, MessageParticipantSchema, MessageSchema, type MountFunction, NewChatHero, type NewChatHeroProps, type QuerySpec, QuerySpecSchema, type ResolvedClientConfig, SDK_VERSION, Sidebar, type SidebarProps, type SuperAtomGlobal, SuperatomClient, type ThreadConversationRow, type ThreadSummary, type UIComponent, UIComponentSchema, type UIElement, UIElementSchema, type UILogEntry, UILogEntrySchema, type UILogsMessage, UILogsMessageSchema, type UILogsPayload, UILogsPayloadSchema, type UseSuperAtomOptions, type UseSuperAtomReturn, type UserPromptAbortRequestMessage, UserPromptAbortRequestMessageSchema, type UserPromptAbortRequestPayload, UserPromptAbortRequestPayloadSchema, type UserPromptRequestMessage, UserPromptRequestMessageSchema, type UserPromptRequestPayload, UserPromptRequestPayloadSchema, type UserPromptResponseMessage, UserPromptResponseMessageSchema, type UserPromptResponsePayload, UserPromptResponsePayloadSchema, type UserPromptSuggestionsRequestMessage, UserPromptSuggestionsRequestMessageSchema, type UserPromptSuggestionsRequestPayload, UserPromptSuggestionsRequestPayloadSchema, type UserPromptSuggestionsResponseMessage, UserPromptSuggestionsResponseMessageSchema, type UserPromptSuggestionsResponsePayload, UserPromptSuggestionsResponsePayloadSchema, getComponent, getComponentStates, getComponents, hasComponents, registerBundleComponents, resetAllFailedComponents, resetFailedComponent, resetRegistration, sanitizeDSL, index as services, setup, useDynamicComponent, useSuperAtom, validateDSL, validateUIComponent, validateUIElement, withConditionalErrorBoundary };
|
|
4011
|
+
export { type ActionsRequestMessage, ActionsRequestMessageSchema, type ActionsRequestPayload, ActionsRequestPayloadSchema, type ActionsResponseMessage, ActionsResponseMessageSchema, type ActionsResponsePayload, ActionsResponsePayloadSchema, type Binding, BindingSchema, type BundleChunkMessage, BundleChunkMessageSchema, type BundleChunkPayload, BundleChunkPayloadSchema, type BundleErrorMessage, BundleErrorMessageSchema, type BundleErrorPayload, BundleErrorPayloadSchema, type BundleRequestMessage, BundleRequestMessageSchema, type BundleRequestPayload, BundleRequestPayloadSchema, COMP_REGISTRY, ChatInput, type ChatInputProps, type ChatMessage, type ClientConfig, ClientConfigSchema, type Component, type ComponentDefinition, type ComponentRegistryType, ComponentSchema, type ComponentsRegistry, type ComponentsSendMessage, ComponentsSendMessageSchema, type ComponentsSendPayload, ComponentsSendPayloadSchema, ConfirmDeleteModal, type ConfirmDeleteModalProps, DEFAULT_API_URL, DSLErrorBoundary, DSLRenderer, type DSLRendererProps, DSLRendererPropsSchema, type DataRequestMessage, DataRequestMessageSchema, type DataRequestPayload, DataRequestPayloadSchema, type DataResponseMessage, DataResponseMessageSchema, type DataResponsePayload, DataResponsePayloadSchema, DynamicComponent, type Expression, ExpressionSchema, type ForDirective, ForDirectiveSchema, type MenuData, MenuDataSchema, type MenuQueryFilters, MenuQueryFiltersSchema, type MenuV1Item, MenuV1Renderer, MenuV1RendererCollapsed, type MenuV1Root, type MenusRequestMessage, MenusRequestMessageSchema, type MenusRequestPayload, MenusRequestPayloadSchema, type MenusResponseMessage, MenusResponseMessageSchema, type MenusResponsePayload, MenusResponsePayloadSchema, type Message, MessageBubble, type MessageBubbleProps, MessageList, type MessageListProps, type MessageParticipant, MessageParticipantSchema, MessageSchema, type MountFunction, NewChatHero, type NewChatHeroProps, type QuerySpec, QuerySpecSchema, type ResolvedClientConfig, SDK_VERSION, SdkSession, type SdkSessionOptions, type SdkUser, Sidebar, type SidebarProps, SuperAtomAuthError, type SuperAtomAuthErrorCode, type SuperAtomGlobal, SuperatomClient, type ThreadConversationRow, type ThreadSummary, type UIComponent, UIComponentSchema, type UIElement, UIElementSchema, type UILogEntry, UILogEntrySchema, type UILogsMessage, UILogsMessageSchema, type UILogsPayload, UILogsPayloadSchema, type UseSuperAtomOptions, type UseSuperAtomReturn, type UserPromptAbortRequestMessage, UserPromptAbortRequestMessageSchema, type UserPromptAbortRequestPayload, UserPromptAbortRequestPayloadSchema, type UserPromptRequestMessage, UserPromptRequestMessageSchema, type UserPromptRequestPayload, UserPromptRequestPayloadSchema, type UserPromptResponseMessage, UserPromptResponseMessageSchema, type UserPromptResponsePayload, UserPromptResponsePayloadSchema, type UserPromptSuggestionsRequestMessage, UserPromptSuggestionsRequestMessageSchema, type UserPromptSuggestionsRequestPayload, UserPromptSuggestionsRequestPayloadSchema, type UserPromptSuggestionsResponseMessage, UserPromptSuggestionsResponseMessageSchema, type UserPromptSuggestionsResponsePayload, UserPromptSuggestionsResponsePayloadSchema, getComponent, getComponentStates, getComponents, hasComponents, registerBundleComponents, resetAllFailedComponents, resetFailedComponent, resetRegistration, sanitizeDSL, index as services, setup, useDynamicComponent, useSuperAtom, validateDSL, validateUIComponent, validateUIElement, withConditionalErrorBoundary };
|