@distri/react 0.2.5 → 0.2.7
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/globals.css +2 -61
- package/dist/globals.d.cts +2 -0
- package/dist/globals.d.ts +2 -0
- package/dist/index.cjs +9 -30
- package/dist/index.css +2 -61
- package/dist/index.d.cts +738 -0
- package/dist/index.d.ts +738 -0
- package/dist/index.js +9 -29
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1336,19 +1336,6 @@ function useDistri() {
|
|
|
1336
1336
|
}
|
|
1337
1337
|
return context;
|
|
1338
1338
|
}
|
|
1339
|
-
function useDistriClient() {
|
|
1340
|
-
const { client, error, isLoading } = useDistri();
|
|
1341
|
-
if (isLoading) {
|
|
1342
|
-
throw new Error("Distri client is still loading");
|
|
1343
|
-
}
|
|
1344
|
-
if (error) {
|
|
1345
|
-
throw new Error(`Distri client initialization failed: ${error.message}`);
|
|
1346
|
-
}
|
|
1347
|
-
if (!client) {
|
|
1348
|
-
throw new Error("Distri client is not initialized");
|
|
1349
|
-
}
|
|
1350
|
-
return client;
|
|
1351
|
-
}
|
|
1352
1339
|
|
|
1353
1340
|
// src/useAgent.ts
|
|
1354
1341
|
function useAgent({
|
|
@@ -1571,13 +1558,6 @@ function useThreads() {
|
|
|
1571
1558
|
setLoading(false);
|
|
1572
1559
|
}
|
|
1573
1560
|
}, [clientLoading, clientError, client, fetchThreads]);
|
|
1574
|
-
useEffect6(() => {
|
|
1575
|
-
if (!client) return;
|
|
1576
|
-
const interval = setInterval(() => {
|
|
1577
|
-
fetchThreads();
|
|
1578
|
-
}, 3e4);
|
|
1579
|
-
return () => clearInterval(interval);
|
|
1580
|
-
}, [client, fetchThreads]);
|
|
1581
1561
|
return {
|
|
1582
1562
|
threads,
|
|
1583
1563
|
loading: loading || clientLoading,
|
|
@@ -5453,7 +5433,7 @@ import { useEffect as useEffect12, useMemo as useMemo5, useState as useState16 }
|
|
|
5453
5433
|
// src/hooks/useConfiguration.ts
|
|
5454
5434
|
import { useCallback as useCallback13, useEffect as useEffect11, useState as useState15 } from "react";
|
|
5455
5435
|
function useConfiguration() {
|
|
5456
|
-
const client =
|
|
5436
|
+
const { client, isLoading } = useDistri();
|
|
5457
5437
|
const [configuration, setConfiguration] = useState15(null);
|
|
5458
5438
|
const [meta, setMeta] = useState15(null);
|
|
5459
5439
|
const [loading, setLoading] = useState15(true);
|
|
@@ -5461,6 +5441,7 @@ function useConfiguration() {
|
|
|
5461
5441
|
const refresh = useCallback13(async () => {
|
|
5462
5442
|
setLoading(true);
|
|
5463
5443
|
try {
|
|
5444
|
+
if (isLoading || !client) return;
|
|
5464
5445
|
const response = await client.getConfiguration();
|
|
5465
5446
|
setConfiguration(response.configuration);
|
|
5466
5447
|
setMeta(response.meta);
|
|
@@ -5471,7 +5452,7 @@ function useConfiguration() {
|
|
|
5471
5452
|
} finally {
|
|
5472
5453
|
setLoading(false);
|
|
5473
5454
|
}
|
|
5474
|
-
}, [client]);
|
|
5455
|
+
}, [client, isLoading]);
|
|
5475
5456
|
const saveConfiguration = useCallback13(
|
|
5476
5457
|
async (config) => {
|
|
5477
5458
|
setLoading(true);
|
|
@@ -6169,11 +6150,11 @@ function convertA2APartToDistri(a2aPart) {
|
|
|
6169
6150
|
// src/hooks/useChatMessages.ts
|
|
6170
6151
|
function useChatMessages({
|
|
6171
6152
|
initialMessages = [],
|
|
6172
|
-
agent,
|
|
6173
6153
|
threadId,
|
|
6174
6154
|
onError
|
|
6175
6155
|
} = {}) {
|
|
6176
6156
|
const onErrorRef = useRef8(onError);
|
|
6157
|
+
const { client } = useDistri();
|
|
6177
6158
|
useEffect14(() => {
|
|
6178
6159
|
onErrorRef.current = onError;
|
|
6179
6160
|
}, [onError]);
|
|
@@ -6195,11 +6176,11 @@ function useChatMessages({
|
|
|
6195
6176
|
setMessages([]);
|
|
6196
6177
|
}, []);
|
|
6197
6178
|
const fetchMessages = useCallback14(async () => {
|
|
6198
|
-
if (!
|
|
6179
|
+
if (!client || !threadId) return;
|
|
6199
6180
|
try {
|
|
6200
6181
|
setIsLoading(true);
|
|
6201
6182
|
setError(null);
|
|
6202
|
-
const a2aMessages = await
|
|
6183
|
+
const a2aMessages = await client.getThreadMessages(threadId);
|
|
6203
6184
|
const distriMessages = a2aMessages.map(decodeA2AStreamEvent).filter(Boolean);
|
|
6204
6185
|
setMessages(distriMessages);
|
|
6205
6186
|
} catch (err) {
|
|
@@ -6209,12 +6190,12 @@ function useChatMessages({
|
|
|
6209
6190
|
} finally {
|
|
6210
6191
|
setIsLoading(false);
|
|
6211
6192
|
}
|
|
6212
|
-
}, [
|
|
6193
|
+
}, [client, threadId]);
|
|
6213
6194
|
useEffect14(() => {
|
|
6214
|
-
if (threadId &&
|
|
6195
|
+
if (threadId && client && !initialMessagesLength) {
|
|
6215
6196
|
fetchMessages();
|
|
6216
6197
|
}
|
|
6217
|
-
}, [
|
|
6198
|
+
}, [client, fetchMessages, initialMessagesLength, threadId]);
|
|
6218
6199
|
return {
|
|
6219
6200
|
messages,
|
|
6220
6201
|
addMessage,
|
|
@@ -6353,7 +6334,6 @@ export {
|
|
|
6353
6334
|
useChatStateStore,
|
|
6354
6335
|
useConfiguration,
|
|
6355
6336
|
useDistri,
|
|
6356
|
-
useDistriClient,
|
|
6357
6337
|
useSidebar,
|
|
6358
6338
|
useSpeechToText,
|
|
6359
6339
|
useTheme,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@distri/react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "React hooks and components for Distri Framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"react": ">=18.0.0",
|
|
68
68
|
"react-dom": ">=18.0.0",
|
|
69
|
-
"@distri/core": "0.2.
|
|
69
|
+
"@distri/core": "0.2.7"
|
|
70
70
|
},
|
|
71
71
|
"publishConfig": {
|
|
72
72
|
"access": "public"
|