@useatlas/react 0.0.1 → 0.0.2
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/LICENSE +21 -0
- package/README.md +79 -2
- package/dist/{chunk-5SEVKHS5.cjs → chunk-35SCTKSW.js} +100 -7
- package/dist/chunk-35SCTKSW.js.map +1 -0
- package/dist/{chunk-UIRB6L36.cjs → chunk-DZFSZSQB.cjs} +46 -54
- package/dist/chunk-DZFSZSQB.cjs.map +1 -0
- package/dist/{chunk-2WFDP7G5.js → chunk-FMSGREKS.js} +46 -54
- package/dist/chunk-FMSGREKS.js.map +1 -0
- package/dist/{chunk-44HBZYKP.js → chunk-IDXGFWFS.cjs} +109 -3
- package/dist/chunk-IDXGFWFS.cjs.map +1 -0
- package/dist/global.d.ts +36 -0
- package/dist/hooks.cjs +10 -10
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +2 -2
- package/dist/hooks.d.ts +2 -2
- package/dist/hooks.js +3 -3
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +385 -265
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +224 -4
- package/dist/index.d.ts +224 -4
- package/dist/index.js +328 -208
- package/dist/index.js.map +1 -1
- package/dist/lib/widget-types.d.ts +232 -0
- package/dist/{result-chart-YLCKBNV4.cjs → result-chart-ANZOT6FL.cjs} +24 -34
- package/dist/result-chart-ANZOT6FL.cjs.map +1 -0
- package/dist/{result-chart-NFAJ4IQ5.js → result-chart-C3EJTN5G.js} +22 -32
- package/dist/result-chart-C3EJTN5G.js.map +1 -0
- package/dist/widget.css +2 -2
- package/dist/widget.js +215 -246
- package/package.json +26 -16
- package/src/components/__tests__/data-table.test.tsx +125 -0
- package/src/components/actions/action-approval-card.tsx +26 -19
- package/src/components/actions/action-status-badge.tsx +3 -3
- package/src/components/atlas-chat.tsx +97 -37
- package/src/components/chart/result-chart.tsx +13 -37
- package/src/components/chat/api-key-bar.tsx +4 -4
- package/src/components/chat/data-table.tsx +42 -3
- package/src/components/chat/error-banner.tsx +108 -5
- package/src/components/chat/follow-up-chips.tsx +1 -1
- package/src/components/chat/managed-auth-card.tsx +6 -6
- package/src/components/conversations/conversation-item.tsx +19 -14
- package/src/components/conversations/conversation-list.tsx +3 -3
- package/src/components/conversations/conversation-sidebar.tsx +15 -4
- package/src/components/conversations/delete-confirmation.tsx +2 -2
- package/src/components/error-boundary.tsx +66 -0
- package/src/components/schema-explorer/schema-explorer.tsx +4 -0
- package/src/env.d.ts +9 -7
- package/src/global.d.ts +36 -0
- package/src/hooks/__tests__/use-atlas-conversations.test.tsx +4 -6
- package/src/hooks/use-atlas-chat.ts +1 -1
- package/src/hooks/use-atlas-conversations.ts +2 -2
- package/src/hooks/use-conversations.ts +60 -68
- package/src/index.ts +8 -0
- package/src/lib/action-types.ts +2 -2
- package/src/lib/helpers.ts +16 -16
- package/src/lib/types.ts +3 -2
- package/src/lib/widget-types.ts +232 -0
- package/src/test-setup.ts +2 -2
- package/dist/chunk-2WFDP7G5.js.map +0 -1
- package/dist/chunk-44HBZYKP.js.map +0 -1
- package/dist/chunk-5SEVKHS5.cjs.map +0 -1
- package/dist/chunk-UIRB6L36.cjs.map +0 -1
- package/dist/result-chart-NFAJ4IQ5.js.map +0 -1
- package/dist/result-chart-YLCKBNV4.cjs.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -36,6 +36,10 @@ interface AtlasChatProps {
|
|
|
36
36
|
authClient?: AtlasAuthClient;
|
|
37
37
|
/** Custom renderers for tool results. Keys are tool names (e.g. "executeSQL", "explore", "executePython"). */
|
|
38
38
|
toolRenderers?: ToolRenderers;
|
|
39
|
+
/** Custom chat API endpoint path. Defaults to "/api/v1/chat". */
|
|
40
|
+
chatEndpoint?: string;
|
|
41
|
+
/** Custom conversations API endpoint path. Defaults to "/api/v1/conversations". */
|
|
42
|
+
conversationsEndpoint?: string;
|
|
39
43
|
}
|
|
40
44
|
/**
|
|
41
45
|
* Standalone Atlas chat component.
|
|
@@ -50,20 +54,236 @@ interface UseConversationsOptions {
|
|
|
50
54
|
enabled: boolean;
|
|
51
55
|
getHeaders: () => Record<string, string>;
|
|
52
56
|
getCredentials: () => RequestCredentials;
|
|
57
|
+
/** Custom conversations API endpoint path. Defaults to "/api/v1/conversations". */
|
|
58
|
+
conversationsEndpoint?: string;
|
|
53
59
|
}
|
|
54
60
|
interface UseConversationsReturn {
|
|
55
61
|
conversations: Conversation[];
|
|
56
62
|
total: number;
|
|
57
63
|
loading: boolean;
|
|
58
64
|
available: boolean;
|
|
65
|
+
fetchError: string | null;
|
|
59
66
|
selectedId: string | null;
|
|
60
67
|
setSelectedId: (id: string | null) => void;
|
|
61
68
|
fetchList: () => Promise<void>;
|
|
62
|
-
loadConversation: (id: string) => Promise<UIMessage[]
|
|
63
|
-
deleteConversation: (id: string) => Promise<
|
|
64
|
-
starConversation: (id: string, starred: boolean) => Promise<
|
|
69
|
+
loadConversation: (id: string) => Promise<UIMessage[]>;
|
|
70
|
+
deleteConversation: (id: string) => Promise<void>;
|
|
71
|
+
starConversation: (id: string, starred: boolean) => Promise<void>;
|
|
65
72
|
refresh: () => Promise<void>;
|
|
66
73
|
}
|
|
67
74
|
declare function useConversations(opts: UseConversationsOptions): UseConversationsReturn;
|
|
68
75
|
|
|
69
|
-
|
|
76
|
+
/**
|
|
77
|
+
* TypeScript type definitions for the Atlas widget script-tag API.
|
|
78
|
+
*
|
|
79
|
+
* When embedded via `<script src="https://api.example.com/widget.js">`,
|
|
80
|
+
* the loader exposes `window.Atlas` with a programmatic API for controlling
|
|
81
|
+
* the chat widget.
|
|
82
|
+
*
|
|
83
|
+
* **Usage for embedders:**
|
|
84
|
+
*
|
|
85
|
+
* Add a triple-slash reference at the top of your script to get full
|
|
86
|
+
* autocomplete and type-checking:
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* /// <reference types="@useatlas/react/widget" />
|
|
90
|
+
*
|
|
91
|
+
* Atlas.open();
|
|
92
|
+
* Atlas.ask("How many users signed up today?");
|
|
93
|
+
* Atlas.on("queryComplete", (detail) => {
|
|
94
|
+
* console.log("Query returned", detail.rowCount, "rows");
|
|
95
|
+
* });
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @module
|
|
99
|
+
*/
|
|
100
|
+
/**
|
|
101
|
+
* Map of event names to their detail payloads.
|
|
102
|
+
*
|
|
103
|
+
* Used by {@link AtlasWidget.on} to provide type-safe event handling.
|
|
104
|
+
*/
|
|
105
|
+
interface AtlasWidgetEventMap {
|
|
106
|
+
/** Fired when the widget panel opens. */
|
|
107
|
+
open: Record<string, never>;
|
|
108
|
+
/** Fired when the widget panel closes. */
|
|
109
|
+
close: Record<string, never>;
|
|
110
|
+
/** Fired when a SQL query completes inside the widget. */
|
|
111
|
+
queryComplete: {
|
|
112
|
+
sql?: string;
|
|
113
|
+
rowCount?: number;
|
|
114
|
+
};
|
|
115
|
+
/** Fired when the widget encounters an error. */
|
|
116
|
+
error: {
|
|
117
|
+
code?: string;
|
|
118
|
+
message?: string;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Configuration options read from `data-*` attributes on the `<script>` tag.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```html
|
|
126
|
+
* <script src="https://api.example.com/widget.js"
|
|
127
|
+
* data-api-url="https://api.example.com"
|
|
128
|
+
* data-api-key="sk-..."
|
|
129
|
+
* data-theme="dark"
|
|
130
|
+
* data-position="bottom-left"
|
|
131
|
+
* data-on-open="onAtlasOpen"
|
|
132
|
+
* data-on-error="onAtlasError">
|
|
133
|
+
* </script>
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
interface AtlasWidgetConfig {
|
|
137
|
+
/**
|
|
138
|
+
* Base URL of the Atlas API (required).
|
|
139
|
+
*
|
|
140
|
+
* Must use `http:` or `https:` protocol.
|
|
141
|
+
*/
|
|
142
|
+
apiUrl: string;
|
|
143
|
+
/**
|
|
144
|
+
* API key for authentication (optional).
|
|
145
|
+
*
|
|
146
|
+
* Passed to the widget iframe as an auth token.
|
|
147
|
+
*/
|
|
148
|
+
apiKey?: string;
|
|
149
|
+
/**
|
|
150
|
+
* Widget color theme (optional, default `"light"`).
|
|
151
|
+
*/
|
|
152
|
+
theme?: "light" | "dark";
|
|
153
|
+
/**
|
|
154
|
+
* Position of the floating chat bubble (optional, default `"bottom-right"`).
|
|
155
|
+
*/
|
|
156
|
+
position?: "bottom-right" | "bottom-left";
|
|
157
|
+
/**
|
|
158
|
+
* Name of a global function called when the widget opens (optional).
|
|
159
|
+
*
|
|
160
|
+
* The function must exist on `window` at the time the event fires.
|
|
161
|
+
*/
|
|
162
|
+
onOpen?: string;
|
|
163
|
+
/**
|
|
164
|
+
* Name of a global function called when the widget closes (optional).
|
|
165
|
+
*/
|
|
166
|
+
onClose?: string;
|
|
167
|
+
/**
|
|
168
|
+
* Name of a global function called when a query completes (optional).
|
|
169
|
+
*/
|
|
170
|
+
onQueryComplete?: string;
|
|
171
|
+
/**
|
|
172
|
+
* Name of a global function called when the widget encounters an error (optional).
|
|
173
|
+
*/
|
|
174
|
+
onError?: string;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Programmatic API exposed on `window.Atlas` after the widget script loads.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* /// <reference types="@useatlas/react/widget" />
|
|
182
|
+
*
|
|
183
|
+
* // Open the widget
|
|
184
|
+
* Atlas.open();
|
|
185
|
+
*
|
|
186
|
+
* // Send a question programmatically
|
|
187
|
+
* Atlas.ask("What are the top 10 customers by revenue?");
|
|
188
|
+
*
|
|
189
|
+
* // Listen for events
|
|
190
|
+
* Atlas.on("queryComplete", (detail) => {
|
|
191
|
+
* console.log(`Query returned ${detail.rowCount} rows`);
|
|
192
|
+
* });
|
|
193
|
+
*
|
|
194
|
+
* // Change theme at runtime
|
|
195
|
+
* Atlas.setTheme("dark");
|
|
196
|
+
*
|
|
197
|
+
* // Clean up when done
|
|
198
|
+
* Atlas.destroy();
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
interface AtlasWidget {
|
|
202
|
+
/**
|
|
203
|
+
* Opens the widget panel.
|
|
204
|
+
*
|
|
205
|
+
* No-op if the widget has been destroyed.
|
|
206
|
+
*/
|
|
207
|
+
open(): void;
|
|
208
|
+
/**
|
|
209
|
+
* Closes the widget panel.
|
|
210
|
+
*
|
|
211
|
+
* No-op if the widget has been destroyed.
|
|
212
|
+
*/
|
|
213
|
+
close(): void;
|
|
214
|
+
/**
|
|
215
|
+
* Toggles the widget panel open or closed.
|
|
216
|
+
*
|
|
217
|
+
* No-op if the widget has been destroyed.
|
|
218
|
+
*/
|
|
219
|
+
toggle(): void;
|
|
220
|
+
/**
|
|
221
|
+
* Opens the widget and sends a question to the Atlas agent.
|
|
222
|
+
*
|
|
223
|
+
* @param question - The natural-language question to ask.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```ts
|
|
227
|
+
* Atlas.ask("How many users signed up this week?");
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
ask(question: string): void;
|
|
231
|
+
/**
|
|
232
|
+
* Removes the widget from the DOM, cleans up all event listeners,
|
|
233
|
+
* and deletes `window.Atlas`.
|
|
234
|
+
*
|
|
235
|
+
* After calling `destroy()`, all other methods become no-ops.
|
|
236
|
+
*/
|
|
237
|
+
destroy(): void;
|
|
238
|
+
/**
|
|
239
|
+
* Binds a type-safe event listener.
|
|
240
|
+
*
|
|
241
|
+
* Supported events: `"open"`, `"close"`, `"queryComplete"`, `"error"`.
|
|
242
|
+
*
|
|
243
|
+
* @param event - The event name.
|
|
244
|
+
* @param handler - Callback receiving the event detail payload.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```ts
|
|
248
|
+
* Atlas.on("error", (detail) => {
|
|
249
|
+
* console.error(`Atlas error [${detail.code}]: ${detail.message}`);
|
|
250
|
+
* });
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
on<K extends keyof AtlasWidgetEventMap>(event: K, handler: (detail: AtlasWidgetEventMap[K]) => void): void;
|
|
254
|
+
/**
|
|
255
|
+
* Sends an authentication token to the widget iframe.
|
|
256
|
+
*
|
|
257
|
+
* Use this when the auth token is obtained after the script tag loads
|
|
258
|
+
* (e.g., after a user logs in).
|
|
259
|
+
*
|
|
260
|
+
* @param token - The authentication token string.
|
|
261
|
+
*/
|
|
262
|
+
setAuthToken(token: string): void;
|
|
263
|
+
/**
|
|
264
|
+
* Sets the widget color theme at runtime.
|
|
265
|
+
*
|
|
266
|
+
* @param theme - `"light"` or `"dark"`.
|
|
267
|
+
*/
|
|
268
|
+
setTheme(theme: "light" | "dark"): void;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Pre-load command queue entry.
|
|
272
|
+
*
|
|
273
|
+
* Before the widget script loads, `window.Atlas` can be set to an array
|
|
274
|
+
* of queued commands that are replayed once the widget initializes:
|
|
275
|
+
*
|
|
276
|
+
* ```ts
|
|
277
|
+
* window.Atlas = window.Atlas || [];
|
|
278
|
+
* Atlas.push(["open"]);
|
|
279
|
+
* Atlas.push(["ask", "How many users signed up today?"]);
|
|
280
|
+
* ```
|
|
281
|
+
*
|
|
282
|
+
* Each entry is a tuple of `[methodName, ...args]`.
|
|
283
|
+
*/
|
|
284
|
+
type AtlasWidgetCommand = [
|
|
285
|
+
keyof AtlasWidget,
|
|
286
|
+
...unknown[]
|
|
287
|
+
];
|
|
288
|
+
|
|
289
|
+
export { AtlasAuthClient, AtlasChat, type AtlasChatProps, type AtlasWidget, type AtlasWidgetCommand, type AtlasWidgetConfig, type AtlasWidgetEventMap, THEME_STORAGE_KEY, ThemeMode, ToolRenderers, type UseConversationsOptions, type UseConversationsReturn, buildThemeInitScript, useConversations };
|
package/dist/index.d.ts
CHANGED
|
@@ -36,6 +36,10 @@ interface AtlasChatProps {
|
|
|
36
36
|
authClient?: AtlasAuthClient;
|
|
37
37
|
/** Custom renderers for tool results. Keys are tool names (e.g. "executeSQL", "explore", "executePython"). */
|
|
38
38
|
toolRenderers?: ToolRenderers;
|
|
39
|
+
/** Custom chat API endpoint path. Defaults to "/api/v1/chat". */
|
|
40
|
+
chatEndpoint?: string;
|
|
41
|
+
/** Custom conversations API endpoint path. Defaults to "/api/v1/conversations". */
|
|
42
|
+
conversationsEndpoint?: string;
|
|
39
43
|
}
|
|
40
44
|
/**
|
|
41
45
|
* Standalone Atlas chat component.
|
|
@@ -50,20 +54,236 @@ interface UseConversationsOptions {
|
|
|
50
54
|
enabled: boolean;
|
|
51
55
|
getHeaders: () => Record<string, string>;
|
|
52
56
|
getCredentials: () => RequestCredentials;
|
|
57
|
+
/** Custom conversations API endpoint path. Defaults to "/api/v1/conversations". */
|
|
58
|
+
conversationsEndpoint?: string;
|
|
53
59
|
}
|
|
54
60
|
interface UseConversationsReturn {
|
|
55
61
|
conversations: Conversation[];
|
|
56
62
|
total: number;
|
|
57
63
|
loading: boolean;
|
|
58
64
|
available: boolean;
|
|
65
|
+
fetchError: string | null;
|
|
59
66
|
selectedId: string | null;
|
|
60
67
|
setSelectedId: (id: string | null) => void;
|
|
61
68
|
fetchList: () => Promise<void>;
|
|
62
|
-
loadConversation: (id: string) => Promise<UIMessage[]
|
|
63
|
-
deleteConversation: (id: string) => Promise<
|
|
64
|
-
starConversation: (id: string, starred: boolean) => Promise<
|
|
69
|
+
loadConversation: (id: string) => Promise<UIMessage[]>;
|
|
70
|
+
deleteConversation: (id: string) => Promise<void>;
|
|
71
|
+
starConversation: (id: string, starred: boolean) => Promise<void>;
|
|
65
72
|
refresh: () => Promise<void>;
|
|
66
73
|
}
|
|
67
74
|
declare function useConversations(opts: UseConversationsOptions): UseConversationsReturn;
|
|
68
75
|
|
|
69
|
-
|
|
76
|
+
/**
|
|
77
|
+
* TypeScript type definitions for the Atlas widget script-tag API.
|
|
78
|
+
*
|
|
79
|
+
* When embedded via `<script src="https://api.example.com/widget.js">`,
|
|
80
|
+
* the loader exposes `window.Atlas` with a programmatic API for controlling
|
|
81
|
+
* the chat widget.
|
|
82
|
+
*
|
|
83
|
+
* **Usage for embedders:**
|
|
84
|
+
*
|
|
85
|
+
* Add a triple-slash reference at the top of your script to get full
|
|
86
|
+
* autocomplete and type-checking:
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* /// <reference types="@useatlas/react/widget" />
|
|
90
|
+
*
|
|
91
|
+
* Atlas.open();
|
|
92
|
+
* Atlas.ask("How many users signed up today?");
|
|
93
|
+
* Atlas.on("queryComplete", (detail) => {
|
|
94
|
+
* console.log("Query returned", detail.rowCount, "rows");
|
|
95
|
+
* });
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @module
|
|
99
|
+
*/
|
|
100
|
+
/**
|
|
101
|
+
* Map of event names to their detail payloads.
|
|
102
|
+
*
|
|
103
|
+
* Used by {@link AtlasWidget.on} to provide type-safe event handling.
|
|
104
|
+
*/
|
|
105
|
+
interface AtlasWidgetEventMap {
|
|
106
|
+
/** Fired when the widget panel opens. */
|
|
107
|
+
open: Record<string, never>;
|
|
108
|
+
/** Fired when the widget panel closes. */
|
|
109
|
+
close: Record<string, never>;
|
|
110
|
+
/** Fired when a SQL query completes inside the widget. */
|
|
111
|
+
queryComplete: {
|
|
112
|
+
sql?: string;
|
|
113
|
+
rowCount?: number;
|
|
114
|
+
};
|
|
115
|
+
/** Fired when the widget encounters an error. */
|
|
116
|
+
error: {
|
|
117
|
+
code?: string;
|
|
118
|
+
message?: string;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Configuration options read from `data-*` attributes on the `<script>` tag.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```html
|
|
126
|
+
* <script src="https://api.example.com/widget.js"
|
|
127
|
+
* data-api-url="https://api.example.com"
|
|
128
|
+
* data-api-key="sk-..."
|
|
129
|
+
* data-theme="dark"
|
|
130
|
+
* data-position="bottom-left"
|
|
131
|
+
* data-on-open="onAtlasOpen"
|
|
132
|
+
* data-on-error="onAtlasError">
|
|
133
|
+
* </script>
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
interface AtlasWidgetConfig {
|
|
137
|
+
/**
|
|
138
|
+
* Base URL of the Atlas API (required).
|
|
139
|
+
*
|
|
140
|
+
* Must use `http:` or `https:` protocol.
|
|
141
|
+
*/
|
|
142
|
+
apiUrl: string;
|
|
143
|
+
/**
|
|
144
|
+
* API key for authentication (optional).
|
|
145
|
+
*
|
|
146
|
+
* Passed to the widget iframe as an auth token.
|
|
147
|
+
*/
|
|
148
|
+
apiKey?: string;
|
|
149
|
+
/**
|
|
150
|
+
* Widget color theme (optional, default `"light"`).
|
|
151
|
+
*/
|
|
152
|
+
theme?: "light" | "dark";
|
|
153
|
+
/**
|
|
154
|
+
* Position of the floating chat bubble (optional, default `"bottom-right"`).
|
|
155
|
+
*/
|
|
156
|
+
position?: "bottom-right" | "bottom-left";
|
|
157
|
+
/**
|
|
158
|
+
* Name of a global function called when the widget opens (optional).
|
|
159
|
+
*
|
|
160
|
+
* The function must exist on `window` at the time the event fires.
|
|
161
|
+
*/
|
|
162
|
+
onOpen?: string;
|
|
163
|
+
/**
|
|
164
|
+
* Name of a global function called when the widget closes (optional).
|
|
165
|
+
*/
|
|
166
|
+
onClose?: string;
|
|
167
|
+
/**
|
|
168
|
+
* Name of a global function called when a query completes (optional).
|
|
169
|
+
*/
|
|
170
|
+
onQueryComplete?: string;
|
|
171
|
+
/**
|
|
172
|
+
* Name of a global function called when the widget encounters an error (optional).
|
|
173
|
+
*/
|
|
174
|
+
onError?: string;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Programmatic API exposed on `window.Atlas` after the widget script loads.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* /// <reference types="@useatlas/react/widget" />
|
|
182
|
+
*
|
|
183
|
+
* // Open the widget
|
|
184
|
+
* Atlas.open();
|
|
185
|
+
*
|
|
186
|
+
* // Send a question programmatically
|
|
187
|
+
* Atlas.ask("What are the top 10 customers by revenue?");
|
|
188
|
+
*
|
|
189
|
+
* // Listen for events
|
|
190
|
+
* Atlas.on("queryComplete", (detail) => {
|
|
191
|
+
* console.log(`Query returned ${detail.rowCount} rows`);
|
|
192
|
+
* });
|
|
193
|
+
*
|
|
194
|
+
* // Change theme at runtime
|
|
195
|
+
* Atlas.setTheme("dark");
|
|
196
|
+
*
|
|
197
|
+
* // Clean up when done
|
|
198
|
+
* Atlas.destroy();
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
interface AtlasWidget {
|
|
202
|
+
/**
|
|
203
|
+
* Opens the widget panel.
|
|
204
|
+
*
|
|
205
|
+
* No-op if the widget has been destroyed.
|
|
206
|
+
*/
|
|
207
|
+
open(): void;
|
|
208
|
+
/**
|
|
209
|
+
* Closes the widget panel.
|
|
210
|
+
*
|
|
211
|
+
* No-op if the widget has been destroyed.
|
|
212
|
+
*/
|
|
213
|
+
close(): void;
|
|
214
|
+
/**
|
|
215
|
+
* Toggles the widget panel open or closed.
|
|
216
|
+
*
|
|
217
|
+
* No-op if the widget has been destroyed.
|
|
218
|
+
*/
|
|
219
|
+
toggle(): void;
|
|
220
|
+
/**
|
|
221
|
+
* Opens the widget and sends a question to the Atlas agent.
|
|
222
|
+
*
|
|
223
|
+
* @param question - The natural-language question to ask.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```ts
|
|
227
|
+
* Atlas.ask("How many users signed up this week?");
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
ask(question: string): void;
|
|
231
|
+
/**
|
|
232
|
+
* Removes the widget from the DOM, cleans up all event listeners,
|
|
233
|
+
* and deletes `window.Atlas`.
|
|
234
|
+
*
|
|
235
|
+
* After calling `destroy()`, all other methods become no-ops.
|
|
236
|
+
*/
|
|
237
|
+
destroy(): void;
|
|
238
|
+
/**
|
|
239
|
+
* Binds a type-safe event listener.
|
|
240
|
+
*
|
|
241
|
+
* Supported events: `"open"`, `"close"`, `"queryComplete"`, `"error"`.
|
|
242
|
+
*
|
|
243
|
+
* @param event - The event name.
|
|
244
|
+
* @param handler - Callback receiving the event detail payload.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```ts
|
|
248
|
+
* Atlas.on("error", (detail) => {
|
|
249
|
+
* console.error(`Atlas error [${detail.code}]: ${detail.message}`);
|
|
250
|
+
* });
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
on<K extends keyof AtlasWidgetEventMap>(event: K, handler: (detail: AtlasWidgetEventMap[K]) => void): void;
|
|
254
|
+
/**
|
|
255
|
+
* Sends an authentication token to the widget iframe.
|
|
256
|
+
*
|
|
257
|
+
* Use this when the auth token is obtained after the script tag loads
|
|
258
|
+
* (e.g., after a user logs in).
|
|
259
|
+
*
|
|
260
|
+
* @param token - The authentication token string.
|
|
261
|
+
*/
|
|
262
|
+
setAuthToken(token: string): void;
|
|
263
|
+
/**
|
|
264
|
+
* Sets the widget color theme at runtime.
|
|
265
|
+
*
|
|
266
|
+
* @param theme - `"light"` or `"dark"`.
|
|
267
|
+
*/
|
|
268
|
+
setTheme(theme: "light" | "dark"): void;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Pre-load command queue entry.
|
|
272
|
+
*
|
|
273
|
+
* Before the widget script loads, `window.Atlas` can be set to an array
|
|
274
|
+
* of queued commands that are replayed once the widget initializes:
|
|
275
|
+
*
|
|
276
|
+
* ```ts
|
|
277
|
+
* window.Atlas = window.Atlas || [];
|
|
278
|
+
* Atlas.push(["open"]);
|
|
279
|
+
* Atlas.push(["ask", "How many users signed up today?"]);
|
|
280
|
+
* ```
|
|
281
|
+
*
|
|
282
|
+
* Each entry is a tuple of `[methodName, ...args]`.
|
|
283
|
+
*/
|
|
284
|
+
type AtlasWidgetCommand = [
|
|
285
|
+
keyof AtlasWidget,
|
|
286
|
+
...unknown[]
|
|
287
|
+
];
|
|
288
|
+
|
|
289
|
+
export { AtlasAuthClient, AtlasChat, type AtlasChatProps, type AtlasWidget, type AtlasWidgetCommand, type AtlasWidgetConfig, type AtlasWidgetEventMap, THEME_STORAGE_KEY, ThemeMode, ToolRenderers, type UseConversationsOptions, type UseConversationsReturn, buildThemeInitScript, useConversations };
|