@erdoai/ui 0.1.25 → 0.1.28
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/README.md +36 -19
- package/dist/index.cjs +8 -8
- package/dist/index.d.cts +19 -26
- package/dist/index.d.ts +19 -26
- package/dist/index.js +8 -8
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ npm install @erdoai/ui
|
|
|
11
11
|
### Peer Dependencies
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
npm install react react-dom
|
|
14
|
+
npm install react react-dom
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## Quick Start
|
|
@@ -22,22 +22,17 @@ npm install react react-dom @tanstack/react-query
|
|
|
22
22
|
|
|
23
23
|
```tsx
|
|
24
24
|
import { ErdoProvider } from '@erdoai/ui';
|
|
25
|
-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
26
|
-
|
|
27
|
-
const queryClient = new QueryClient();
|
|
28
25
|
|
|
29
26
|
function App() {
|
|
30
27
|
return (
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
</ErdoProvider>
|
|
40
|
-
</QueryClientProvider>
|
|
28
|
+
<ErdoProvider
|
|
29
|
+
config={{
|
|
30
|
+
baseUrl: 'https://api.erdo.ai',
|
|
31
|
+
token: 'scoped-token', // Short-lived token from createToken()
|
|
32
|
+
}}
|
|
33
|
+
>
|
|
34
|
+
<YourApp />
|
|
35
|
+
</ErdoProvider>
|
|
41
36
|
);
|
|
42
37
|
}
|
|
43
38
|
```
|
|
@@ -261,12 +256,14 @@ await sendMessage('Analyze our sales data');
|
|
|
261
256
|
|
|
262
257
|
### useDatasetContents
|
|
263
258
|
|
|
264
|
-
Fetch dataset contents:
|
|
259
|
+
Fetch dataset contents using plain React state (no React Query required):
|
|
265
260
|
|
|
266
261
|
```tsx
|
|
267
|
-
const { data, isLoading, error } = useDatasetContents('dataset-slug', 'invocation-id');
|
|
262
|
+
const { data, isLoading, error, refetch } = useDatasetContents('dataset-slug', 'invocation-id');
|
|
268
263
|
```
|
|
269
264
|
|
|
265
|
+
The hook uses the `DataFetcher` from the provider if available, otherwise falls back to the REST API.
|
|
266
|
+
|
|
270
267
|
### useMultipleDatasetContents
|
|
271
268
|
|
|
272
269
|
Fetch multiple datasets in parallel:
|
|
@@ -308,15 +305,35 @@ Scoped tokens are short-lived tokens created via `createToken()` for end users:
|
|
|
308
305
|
|
|
309
306
|
### Custom Data Fetcher
|
|
310
307
|
|
|
311
|
-
|
|
308
|
+
Provide a custom `DataFetcher` to:
|
|
309
|
+
|
|
310
|
+
- **Proxy requests** through your own backend (keeping API keys server-side)
|
|
311
|
+
- **Add custom authentication** headers or logic
|
|
312
|
+
- **Transform data** before it reaches components
|
|
313
|
+
- **Use your own API** instead of Erdo's REST endpoints
|
|
312
314
|
|
|
313
315
|
```tsx
|
|
314
|
-
|
|
316
|
+
import type { DataFetcher } from '@erdoai/ui';
|
|
317
|
+
|
|
318
|
+
const customFetcher: DataFetcher = {
|
|
319
|
+
// Required: fetch dataset contents for charts/tables
|
|
315
320
|
fetchDatasetContents: async (slug, invocationId) => {
|
|
316
|
-
// Fetch through your server which adds authentication
|
|
317
321
|
const response = await fetch(`/api/datasets/${slug}?invocationId=${invocationId}`);
|
|
318
322
|
return response.json();
|
|
319
323
|
},
|
|
324
|
+
|
|
325
|
+
// Optional: get dataset details for download buttons
|
|
326
|
+
getDatasetDetails: async (slug, threadId) => {
|
|
327
|
+
const response = await fetch(`/api/datasets/${slug}/details?threadId=${threadId}`);
|
|
328
|
+
if (!response.ok) return null;
|
|
329
|
+
return response.json(); // { id: string, name: string }
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
// Optional: download dataset as file
|
|
333
|
+
downloadDataset: async (datasetId) => {
|
|
334
|
+
const response = await fetch(`/api/datasets/${datasetId}/download`);
|
|
335
|
+
return response.blob();
|
|
336
|
+
},
|
|
320
337
|
};
|
|
321
338
|
|
|
322
339
|
<ErdoProvider
|