@superatomai/application-react 0.0.1 → 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.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
- import React, { Component as Component$1, ReactNode } from 'react';
2
+ import * as React from 'react';
3
+ import React__default, { Component as Component$1, ReactNode } from 'react';
3
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
5
 
5
6
  declare const ExpressionSchema$1: z.ZodObject<{
@@ -244,6 +245,36 @@ declare const UserPromptRequestMessageSchema: z.ZodObject<{
244
245
  }, z.core.$strip>;
245
246
  }, z.core.$strip>;
246
247
  type UserPromptRequestMessage = z.infer<typeof UserPromptRequestMessageSchema>;
248
+ /**
249
+ * User prompt abort request payload schema
250
+ * Synced with sdk-nodejs: UserPromptAbortRequestPayloadSchema
251
+ */
252
+ declare const UserPromptAbortRequestPayloadSchema: z.ZodObject<{
253
+ uiBlockId: z.ZodString;
254
+ threadId: z.ZodOptional<z.ZodString>;
255
+ }, z.core.$strip>;
256
+ type UserPromptAbortRequestPayload = z.infer<typeof UserPromptAbortRequestPayloadSchema>;
257
+ /**
258
+ * User prompt abort request message schema
259
+ * Synced with sdk-nodejs: UserPromptAbortRequestMessageSchema
260
+ */
261
+ declare const UserPromptAbortRequestMessageSchema: z.ZodObject<{
262
+ id: z.ZodString;
263
+ type: z.ZodLiteral<"USER_PROMPT_ABORT_REQ">;
264
+ from: z.ZodObject<{
265
+ id: z.ZodOptional<z.ZodString>;
266
+ type: z.ZodOptional<z.ZodString>;
267
+ }, z.core.$strip>;
268
+ to: z.ZodOptional<z.ZodObject<{
269
+ id: z.ZodOptional<z.ZodString>;
270
+ type: z.ZodOptional<z.ZodString>;
271
+ }, z.core.$strip>>;
272
+ payload: z.ZodObject<{
273
+ uiBlockId: z.ZodString;
274
+ threadId: z.ZodOptional<z.ZodString>;
275
+ }, z.core.$strip>;
276
+ }, z.core.$strip>;
277
+ type UserPromptAbortRequestMessage = z.infer<typeof UserPromptAbortRequestMessageSchema>;
247
278
  /**
248
279
  * Component schema (from backend)
249
280
  * Synced with sdk-nodejs: ComponentSchema
@@ -1026,8 +1057,17 @@ declare const ClientConfigSchema: z.ZodObject<{
1026
1057
  maxReconnectDelay: z.ZodDefault<z.ZodNumber>;
1027
1058
  defaultTimeout: z.ZodDefault<z.ZodNumber>;
1028
1059
  debug: z.ZodDefault<z.ZodBoolean>;
1060
+ token: z.ZodOptional<z.ZodString>;
1029
1061
  }, z.core.$strip>;
1030
- 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
+ };
1031
1071
  type ResolvedClientConfig = z.output<typeof ClientConfigSchema>;
1032
1072
 
1033
1073
  /**
@@ -1048,6 +1088,20 @@ type ResolvedClientConfig = z.output<typeof ClientConfigSchema>;
1048
1088
  * @returns Server response message
1049
1089
  */
1050
1090
  declare function sendUserPromptRequest(client: SuperatomClient, prompt: string, threadId: string, uiBlockId: string, userId?: string, responseMode?: 'component' | 'text', onStream?: (chunk: string) => void, timeout?: number): Promise<Message>;
1091
+ /**
1092
+ * Abort an in-flight user prompt request.
1093
+ *
1094
+ * Fire-and-forget: sends a USER_PROMPT_ABORT_REQ identifying the question by its
1095
+ * uiBlockId. The backend cancels the matching in-flight request (LLM stream,
1096
+ * source agents, any running script) and acks with USER_PROMPT_ABORTED. There's
1097
+ * no response to await — the caller has already marked the message "stopped" on
1098
+ * its side; this just stops the server-side work.
1099
+ *
1100
+ * @param client - SuperatomClient instance
1101
+ * @param uiBlockId - The uiBlockId of the question to cancel
1102
+ * @param threadId - The thread the question belongs to (optional context)
1103
+ */
1104
+ declare function abortUserPromptRequest(client: SuperatomClient, uiBlockId: string, threadId?: string): void;
1051
1105
  /**
1052
1106
  * Send a user prompt suggestions request
1053
1107
  * @param client - SuperatomClient instance
@@ -1740,6 +1794,99 @@ declare function queryMenus(client: SuperatomClient, options?: QueryMenusOptions
1740
1794
  message?: string;
1741
1795
  }>;
1742
1796
 
1797
+ /**
1798
+ * User Conversations Service
1799
+ * Thread list + thread history via the `user-conversations` data collection
1800
+ * (same calls as Runtime-react's services/wsMessages/userConversations.ts)
1801
+ */
1802
+
1803
+ /**
1804
+ * A single conversation thread summary, as returned by getUserThreads.
1805
+ * `title` is the opening question of the thread (its earliest prompt).
1806
+ */
1807
+ interface ThreadSummary {
1808
+ threadId: string;
1809
+ title: string;
1810
+ messageCount: number;
1811
+ createdAt: string;
1812
+ updatedAt: string;
1813
+ archived: boolean;
1814
+ config?: {
1815
+ dashboardId?: string;
1816
+ } | null;
1817
+ }
1818
+ /**
1819
+ * One persisted Q&A row inside a thread (the user_conversations table shape).
1820
+ * The full assistant response lives inside `response`.
1821
+ */
1822
+ interface ThreadConversationRow {
1823
+ id: number;
1824
+ userId: string;
1825
+ threadid: string | null;
1826
+ userprompt: string;
1827
+ status?: 'success' | 'error' | 'aborted';
1828
+ response: {
1829
+ id?: string;
1830
+ component?: any;
1831
+ analysis?: string | null;
1832
+ user_prompt?: string;
1833
+ error?: unknown;
1834
+ [key: string]: any;
1835
+ };
1836
+ createdAt: string;
1837
+ updatedAt: string;
1838
+ }
1839
+ /**
1840
+ * List the user's conversation threads, most-recently-active first.
1841
+ * `total` is the user's full thread count (independent of the page window).
1842
+ */
1843
+ declare function getUserThreads(client: SuperatomClient, userId: string, limit?: number, offset?: number, timeout?: number): Promise<{
1844
+ success: boolean;
1845
+ threads: ThreadSummary[];
1846
+ total: number;
1847
+ error?: string;
1848
+ }>;
1849
+ /**
1850
+ * Delete a whole thread (all its conversations).
1851
+ */
1852
+ declare function deleteThread(client: SuperatomClient, userId: string, threadId: string, clearCache?: boolean, timeout?: number): Promise<{
1853
+ success: boolean;
1854
+ error?: string;
1855
+ message?: string;
1856
+ deletedCount?: number;
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
+ }>;
1871
+ /**
1872
+ * Rename a thread's title.
1873
+ */
1874
+ declare function updateThreadTitle(client: SuperatomClient, userId: string, threadId: string, title: string, timeout?: number): Promise<{
1875
+ success: boolean;
1876
+ error?: string;
1877
+ title?: string;
1878
+ }>;
1879
+ /**
1880
+ * Fetch a page of conversations within a thread, newest-first (offset 0 = the
1881
+ * most recent `limit` messages). `total` is the thread's full message count.
1882
+ */
1883
+ declare function getThreadConversations(client: SuperatomClient, userId: string, threadId: string, limit?: number, offset?: number, timeout?: number): Promise<{
1884
+ success: boolean;
1885
+ rows: ThreadConversationRow[];
1886
+ total: number;
1887
+ error?: string;
1888
+ }>;
1889
+
1743
1890
  /**
1744
1891
  * Services Index
1745
1892
  * Re-exports all service functions for easy importing
@@ -1761,12 +1908,17 @@ type index_QueryReportsOptions = QueryReportsOptions;
1761
1908
  type index_QueryUIsOptions = QueryUIsOptions;
1762
1909
  type index_QueryUsersOptions = QueryUsersOptions;
1763
1910
  type index_Report = Report;
1911
+ type index_ThreadConversationRow = ThreadConversationRow;
1912
+ type index_ThreadSummary = ThreadSummary;
1764
1913
  type index_UI = UI;
1765
1914
  type index_UpdateBookmarkOptions = UpdateBookmarkOptions;
1766
1915
  type index_User = User;
1916
+ declare const index_abortUserPromptRequest: typeof abortUserPromptRequest;
1767
1917
  declare const index_createBookmark: typeof createBookmark;
1768
1918
  declare const index_deleteArtifact: typeof deleteArtifact;
1769
1919
  declare const index_deleteBookmark: typeof deleteBookmark;
1920
+ declare const index_deleteThread: typeof deleteThread;
1921
+ declare const index_deleteUserConversation: typeof deleteUserConversation;
1770
1922
  declare const index_getActions: typeof getActions;
1771
1923
  declare const index_getAllArtifacts: typeof getAllArtifacts;
1772
1924
  declare const index_getAllBookmarks: typeof getAllBookmarks;
@@ -1782,7 +1934,9 @@ declare const index_getMenu: typeof getMenu;
1782
1934
  declare const index_getMenusHierarchy: typeof getMenusHierarchy;
1783
1935
  declare const index_getReport: typeof getReport;
1784
1936
  declare const index_getRootMenus: typeof getRootMenus;
1937
+ declare const index_getThreadConversations: typeof getThreadConversations;
1785
1938
  declare const index_getUI: typeof getUI;
1939
+ declare const index_getUserThreads: typeof getUserThreads;
1786
1940
  declare const index_injectBundleStyles: typeof injectBundleStyles;
1787
1941
  declare const index_queryArtifacts: typeof queryArtifacts;
1788
1942
  declare const index_queryBookmarks: typeof queryBookmarks;
@@ -1797,8 +1951,9 @@ declare const index_sendComponents: typeof sendComponents;
1797
1951
  declare const index_sendUserPromptRequest: typeof sendUserPromptRequest;
1798
1952
  declare const index_sendUserPromptSuggestionsRequest: typeof sendUserPromptSuggestionsRequest;
1799
1953
  declare const index_updateBookmark: typeof updateBookmark;
1954
+ declare const index_updateThreadTitle: typeof updateThreadTitle;
1800
1955
  declare namespace index {
1801
- 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_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_createBookmark as createBookmark, index_deleteArtifact as deleteArtifact, index_deleteBookmark as deleteBookmark, 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_getUI as getUI, 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 };
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 };
1802
1957
  }
1803
1958
 
1804
1959
  type MessageHandler = (message: Message) => void;
@@ -1823,6 +1978,8 @@ declare class SuperatomClient {
1823
1978
  private config;
1824
1979
  private connectPromise;
1825
1980
  private connectResolve;
1981
+ private getAccessToken;
1982
+ private fetchingToken;
1826
1983
  private heartbeatInterval;
1827
1984
  private pongDeadline;
1828
1985
  private readonly HEARTBEAT_INTERVAL_MS;
@@ -1839,6 +1996,12 @@ declare class SuperatomClient {
1839
1996
  * Get WebSocket URL with query parameters
1840
1997
  */
1841
1998
  private getWebSocketUrl;
1999
+ /**
2000
+ * Swap the session token used on the next (re)connect.
2001
+ * Deliberately does NOT re-dial a live socket: the relay only checks the
2002
+ * token at handshake, so an open connection stays valid.
2003
+ */
2004
+ setToken(token: string): void;
1842
2005
  /**
1843
2006
  * Calculate reconnection delay with exponential backoff
1844
2007
  */
@@ -1885,6 +2048,14 @@ declare class SuperatomClient {
1885
2048
  * window 'online' / 'visibilitychange' handlers.
1886
2049
  */
1887
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;
1888
2059
  /**
1889
2060
  * Attach window-level listeners that catch network changes faster than
1890
2061
  * the socket's own onclose. The browser's onclose for a half-open TCP can
@@ -1908,6 +2079,16 @@ declare class SuperatomClient {
1908
2079
  * The Promise never rejects - failures are logged silently and auto-reconnect is triggered
1909
2080
  */
1910
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;
1911
2092
  /**
1912
2093
  * Disconnect from WebSocket server
1913
2094
  */
@@ -1994,6 +2175,11 @@ declare class SuperatomClient {
1994
2175
  * @param onStream - Optional callback for streaming text chunks (only for text mode)
1995
2176
  */
1996
2177
  sendUserPromptRequest(prompt: string, threadId: string, uiBlockId: string, userId?: string, responseMode?: 'component' | 'text', onStream?: (chunk: string) => void, timeout?: number): Promise<Message>;
2178
+ /**
2179
+ * Abort an in-flight user prompt request (frontend "Stop" button).
2180
+ * Fire-and-forget — cancels the backend work for the given uiBlockId.
2181
+ */
2182
+ abortUserPromptRequest(uiBlockId: string, threadId?: string): void;
1997
2183
  /**
1998
2184
  * Send a user prompt suggestions request
1999
2185
  * Delegates to user prompt service
@@ -2007,6 +2193,8 @@ declare class SuperatomClient {
2007
2193
  requestBundle(options?: {
2008
2194
  timeout?: number;
2009
2195
  onProgress?: (progress: number) => void;
2196
+ devbundlereq?: boolean;
2197
+ /** @deprecated Use `devbundlereq` */
2010
2198
  devbundle?: boolean;
2011
2199
  }): Promise<string>;
2012
2200
  /**
@@ -2330,6 +2518,116 @@ declare class SuperatomClient {
2330
2518
  private log;
2331
2519
  }
2332
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
+
2333
2631
  /**
2334
2632
  * Component mount function type
2335
2633
  */
@@ -3423,13 +3721,13 @@ interface ExtendedDSLRendererProps extends DSLRendererProps {
3423
3721
  onNavigate?: NavigationHandler;
3424
3722
  handlers?: Record<string, Function>;
3425
3723
  }
3426
- declare const DSLRenderer: React.FC<ExtendedDSLRendererProps>;
3724
+ declare const DSLRenderer: React__default.FC<ExtendedDSLRendererProps>;
3427
3725
 
3428
3726
  interface ComponentDefinition {
3429
3727
  id: string;
3430
3728
  name: string;
3431
3729
  head: string;
3432
- COMP: React.ComponentType<any>;
3730
+ COMP: React__default.ComponentType<any>;
3433
3731
  dependencies?: string[];
3434
3732
  version?: string;
3435
3733
  }
@@ -3449,10 +3747,10 @@ declare const useDynamicComponent: (componentType: string) => {
3449
3747
  isLoaded: boolean;
3450
3748
  error: string | null;
3451
3749
  };
3452
- declare const DynamicComponent: React.FC<{
3750
+ declare const DynamicComponent: React__default.FC<{
3453
3751
  type: string;
3454
3752
  props?: any;
3455
- children?: React.ReactNode;
3753
+ children?: React__default.ReactNode;
3456
3754
  }>;
3457
3755
 
3458
3756
  interface DSLErrorBoundaryProps {
@@ -3460,7 +3758,7 @@ interface DSLErrorBoundaryProps {
3460
3758
  fallback?: ReactNode;
3461
3759
  elementType?: string;
3462
3760
  elementKey?: string | number;
3463
- onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
3761
+ onError?: (error: Error, errorInfo: React__default.ErrorInfo) => void;
3464
3762
  skipBoundary?: boolean;
3465
3763
  }
3466
3764
  interface DSLErrorBoundaryState {
@@ -3471,12 +3769,19 @@ interface DSLErrorBoundaryState {
3471
3769
  declare class DSLErrorBoundary extends Component$1<DSLErrorBoundaryProps, DSLErrorBoundaryState> {
3472
3770
  constructor(props: DSLErrorBoundaryProps);
3473
3771
  static getDerivedStateFromError(error: Error): DSLErrorBoundaryState;
3474
- componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void;
3475
- render(): string | number | boolean | Iterable<React.ReactNode> | react_jsx_runtime.JSX.Element | null | undefined;
3772
+ componentDidCatch(error: Error, errorInfo: React__default.ErrorInfo): void;
3773
+ render(): string | number | boolean | Iterable<React__default.ReactNode> | react_jsx_runtime.JSX.Element | null | undefined;
3476
3774
  }
3477
3775
  declare const withConditionalErrorBoundary: (component: ReactNode, elementType: string, elementKey?: string | number, forceWrap?: boolean) => ReactNode;
3478
3776
 
3777
+ /**
3778
+ * Register every component exposed on window.SUPERATOM.COMPONENTS into COMP_REGISTRY.
3779
+ * Safe to call repeatedly — each call reflects the currently loaded bundle.
3780
+ */
3479
3781
  declare function registerBundleComponents(): number;
3782
+ /**
3783
+ * Remove all bundle components added by registerBundleComponents from COMP_REGISTRY.
3784
+ */
3480
3785
  declare function resetRegistration(): void;
3481
3786
 
3482
3787
  interface ChatMessage {
@@ -3491,12 +3796,32 @@ interface ChatMessage {
3491
3796
  isLoading?: boolean;
3492
3797
  isStreaming?: boolean;
3493
3798
  isTextOnlyResponse?: boolean;
3799
+ aborted?: boolean;
3800
+ fromHistory?: boolean;
3494
3801
  }
3495
3802
 
3496
3803
  interface UseSuperAtomOptions {
3804
+ /** A Superatom session token, passed directly (our own apps). Use `getToken` for SDK sign-in instead. */
3497
3805
  token?: string;
3498
3806
  userId?: string;
3499
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;
3500
3825
  debug?: boolean;
3501
3826
  streaming?: boolean;
3502
3827
  }
@@ -3507,8 +3832,43 @@ interface UseSuperAtomReturn {
3507
3832
  setInput: (value: string) => void;
3508
3833
  sendMessage: () => void;
3509
3834
  isSending: boolean;
3835
+ /** Stop the in-flight response (keeps any partial answer, labels it "Stopped") */
3836
+ abortRequest: () => void;
3837
+ /** The user's conversation threads, most recent first */
3838
+ threads: ThreadSummary[];
3839
+ /** Thread the chat is currently in */
3840
+ activeThreadId: string;
3841
+ /** Open a saved thread and load its messages */
3842
+ openThread: (threadId: string) => void;
3843
+ /** Start a fresh chat (new thread) */
3844
+ newChat: () => void;
3845
+ /** A saved thread's messages are loading */
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;
3852
+ /** Re-fetch the thread list */
3853
+ refreshThreads: () => void;
3854
+ /** Delete a thread and all its messages; if it's the open one, starts a new chat */
3855
+ deleteThread: (threadId: string) => Promise<{
3856
+ success: boolean;
3857
+ error?: string;
3858
+ }>;
3859
+ /** Rename a thread */
3860
+ renameThread: (threadId: string, title: string) => Promise<{
3861
+ success: boolean;
3862
+ error?: string;
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;
3510
3870
  }
3511
- 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;
3512
3872
 
3513
3873
  interface ChatInputProps {
3514
3874
  input: string;
@@ -3518,22 +3878,40 @@ interface ChatInputProps {
3518
3878
  placeholder?: string;
3519
3879
  primaryColor?: string;
3520
3880
  className?: string;
3881
+ /** A response is in flight — swaps Send for Stop and enables Esc-to-stop */
3882
+ isResponding?: boolean;
3883
+ onStop?: () => void;
3521
3884
  }
3522
- declare function ChatInput({ input, setInput, onSend, disabled, placeholder, primaryColor, className, }: ChatInputProps): react_jsx_runtime.JSX.Element;
3885
+ declare function ChatInput({ input, setInput, onSend, disabled, placeholder, primaryColor, className, isResponding, onStop, }: ChatInputProps): react_jsx_runtime.JSX.Element;
3523
3886
 
3524
3887
  interface MessageListProps {
3525
3888
  messages: ChatMessage[];
3526
3889
  bundleReady: boolean;
3527
3890
  connectingText?: string;
3528
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;
3529
3899
  className?: string;
3900
+ /** A response is in flight — shows a Stop button on the latest assistant message */
3901
+ isResponding?: boolean;
3902
+ onStop?: () => void;
3903
+ /** A saved thread is being opened — shows a loading state instead of the empty text */
3904
+ isLoadingThread?: boolean;
3905
+ loadingThreadText?: string;
3530
3906
  }
3531
- declare function MessageList({ messages, bundleReady, connectingText, emptyText, className, }: 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;
3532
3908
 
3533
3909
  interface MessageBubbleProps {
3534
3910
  message: ChatMessage;
3911
+ /** When set, this message's response is in flight and a Stop button is shown */
3912
+ onStop?: () => void;
3535
3913
  }
3536
- declare function MessageBubble({ message }: MessageBubbleProps): react_jsx_runtime.JSX.Element;
3914
+ declare function MessageBubble({ message, onStop }: MessageBubbleProps): react_jsx_runtime.JSX.Element;
3537
3915
 
3538
3916
  interface MenuV1Item {
3539
3917
  id: string;
@@ -3561,29 +3939,73 @@ interface MenuV1Root {
3561
3939
  }
3562
3940
 
3563
3941
  interface SidebarProps {
3564
- children?: React.ReactNode;
3942
+ children?: React__default.ReactNode;
3565
3943
  className?: string;
3566
3944
  onItemClick?: (item: MenuV1Item) => void;
3945
+ /** Shows the "New chat" button when provided (pass `newChat` from useSuperAtom) */
3946
+ onNewChat?: () => void;
3947
+ /** Conversation threads for the "Chats" section (pass `threads` from useSuperAtom) */
3948
+ threads?: ThreadSummary[];
3949
+ /** Highlighted thread (pass `activeThreadId` from useSuperAtom) */
3950
+ activeThreadId?: string;
3951
+ /** Open a thread (pass `openThread` from useSuperAtom) */
3952
+ onSelectThread?: (threadId: string) => void;
3953
+ /** Enables "Delete chat" in each thread's menu (pass `deleteThread` from useSuperAtom) */
3954
+ onDeleteThread?: (threadId: string) => Promise<{
3955
+ success: boolean;
3956
+ error?: string;
3957
+ }>;
3958
+ /** Enables "Rename" in each thread's menu (pass `renameThread` from useSuperAtom) */
3959
+ onRenameThread?: (threadId: string, title: string) => Promise<{
3960
+ success: boolean;
3961
+ error?: string;
3962
+ }>;
3963
+ primaryColor?: string;
3964
+ }
3965
+ declare function Sidebar({ children, className, onItemClick, onNewChat, threads, activeThreadId, onSelectThread, onDeleteThread, onRenameThread, primaryColor, }: SidebarProps): react_jsx_runtime.JSX.Element;
3966
+
3967
+ interface NewChatHeroProps {
3968
+ /** The chat input to center, e.g. <ChatInput ... /> */
3969
+ children: React__default.ReactNode;
3970
+ title?: string;
3971
+ subtitle?: string;
3972
+ className?: string;
3973
+ }
3974
+ /**
3975
+ * Centered "new chat" empty state (like most chat apps): a greeting with the
3976
+ * chat box in the middle of the screen. Same as Runtime-react's NewChatHero.
3977
+ * Render it instead of <MessageList /> + bottom <ChatInput /> while the chat is empty.
3978
+ */
3979
+ declare function NewChatHero({ children, title, subtitle, className, }: NewChatHeroProps): react_jsx_runtime.JSX.Element;
3980
+
3981
+ interface ConfirmDeleteModalProps {
3982
+ isOpen: boolean;
3983
+ onClose: () => void;
3984
+ onConfirm: () => void;
3985
+ isDeleting: boolean;
3986
+ title?: string;
3987
+ message?: string;
3567
3988
  }
3568
- declare function Sidebar({ children, className, onItemClick }: SidebarProps): react_jsx_runtime.JSX.Element;
3989
+ /** Same as Runtime-react's components/chat/ConfirmDeleteModal */
3990
+ declare function ConfirmDeleteModal({ isOpen, onClose, onConfirm, isDeleting, title, message, }: ConfirmDeleteModalProps): React.ReactPortal | null;
3569
3991
 
3570
3992
  interface MenuV1RendererProps {
3571
3993
  items: MenuV1Item[];
3572
3994
  onItemClick: (item: MenuV1Item) => void;
3573
3995
  isCollapsed: boolean;
3574
3996
  }
3575
- declare const MenuV1Renderer: React.FC<MenuV1RendererProps>;
3997
+ declare const MenuV1Renderer: React__default.FC<MenuV1RendererProps>;
3576
3998
 
3577
3999
  interface MenuV1RendererCollapsedProps {
3578
4000
  items: MenuV1Item[];
3579
4001
  onItemClick: (item: MenuV1Item) => void;
3580
4002
  }
3581
- declare const MenuV1RendererCollapsed: React.FC<MenuV1RendererCollapsedProps>;
4003
+ declare const MenuV1RendererCollapsed: React__default.FC<MenuV1RendererCollapsedProps>;
3582
4004
 
3583
4005
  /**
3584
4006
  * @superatomai/application-sdk
3585
4007
  * SuperAtom Application SDK - WebSocket client, DSL renderer, and pre-built chat UI
3586
4008
  */
3587
- declare const SDK_VERSION = "0.0.1";
4009
+ declare const SDK_VERSION = "0.0.3";
3588
4010
 
3589
- 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, 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, type QuerySpec, QuerySpecSchema, type ResolvedClientConfig, SDK_VERSION, Sidebar, type SidebarProps, type SuperAtomGlobal, SuperatomClient, type UIComponent, UIComponentSchema, type UIElement, UIElementSchema, type UILogEntry, UILogEntrySchema, type UILogsMessage, UILogsMessageSchema, type UILogsPayload, UILogsPayloadSchema, type UseSuperAtomOptions, type UseSuperAtomReturn, 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 };