@docyrus/ui-pro-ai-assistant 0.2.6 → 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/index.js +60 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2557,48 +2557,77 @@ function toAgentTriggerData(id, data) {
|
|
|
2557
2557
|
}
|
|
2558
2558
|
function useAgentsData(agentIds) {
|
|
2559
2559
|
const apiClient = useApiClient();
|
|
2560
|
+
const apiClientRef = useRef(apiClient);
|
|
2561
|
+
apiClientRef.current = apiClient;
|
|
2560
2562
|
const [agents, setAgents] = useState([]);
|
|
2561
2563
|
const [isLoading, setIsLoading] = useState(false);
|
|
2562
2564
|
const [error, setError] = useState(null);
|
|
2565
|
+
const [retryCount, setRetryCount] = useState(0);
|
|
2563
2566
|
const idsKey = agentIds.join(",");
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
const
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2567
|
+
useEffect(() => {
|
|
2568
|
+
let cancelled = false;
|
|
2569
|
+
const run = async () => {
|
|
2570
|
+
const ids = idsKey.split(",").filter(Boolean);
|
|
2571
|
+
if (ids.length === 0) {
|
|
2572
|
+
setAgents([]);
|
|
2573
|
+
return;
|
|
2574
|
+
}
|
|
2575
|
+
setIsLoading(true);
|
|
2576
|
+
setError(null);
|
|
2577
|
+
try {
|
|
2578
|
+
const BATCH_SIZE = 3;
|
|
2579
|
+
const BATCH_DELAY = 200;
|
|
2580
|
+
const resolved = [];
|
|
2581
|
+
const client = apiClientRef.current;
|
|
2582
|
+
for (let start = 0; start < ids.length; start += BATCH_SIZE) {
|
|
2583
|
+
if (cancelled) return;
|
|
2584
|
+
if (start > 0) {
|
|
2585
|
+
await new Promise((resolve) => {
|
|
2586
|
+
const timer = setTimeout(resolve, BATCH_DELAY);
|
|
2587
|
+
if (cancelled) clearTimeout(timer);
|
|
2588
|
+
});
|
|
2589
|
+
}
|
|
2590
|
+
const batch = ids.slice(start, start + BATCH_SIZE);
|
|
2591
|
+
const results = await Promise.allSettled(
|
|
2592
|
+
batch.map((id) => client.get(`/ai/agent-deployments/base/${id}`))
|
|
2593
|
+
);
|
|
2594
|
+
for (let i = 0; i < batch.length; i++) {
|
|
2595
|
+
const result = results[i];
|
|
2596
|
+
if (result.status === "fulfilled" && result.value.success && result.value.data) {
|
|
2597
|
+
resolved.push(
|
|
2598
|
+
toAgentTriggerData(batch[i], result.value.data)
|
|
2599
|
+
);
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
if (!cancelled) {
|
|
2604
|
+
setAgents(resolved);
|
|
2605
|
+
}
|
|
2606
|
+
} catch (err) {
|
|
2607
|
+
if (!cancelled) {
|
|
2608
|
+
setError(
|
|
2609
|
+
err instanceof Error ? err : new Error("Failed to fetch agents")
|
|
2582
2610
|
);
|
|
2583
2611
|
}
|
|
2612
|
+
} finally {
|
|
2613
|
+
if (!cancelled) {
|
|
2614
|
+
setIsLoading(false);
|
|
2615
|
+
}
|
|
2584
2616
|
}
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
}, [
|
|
2594
|
-
useEffect(() => {
|
|
2595
|
-
void fetchAgents();
|
|
2596
|
-
}, [fetchAgents]);
|
|
2617
|
+
};
|
|
2618
|
+
void run();
|
|
2619
|
+
return () => {
|
|
2620
|
+
cancelled = true;
|
|
2621
|
+
};
|
|
2622
|
+
}, [idsKey, retryCount]);
|
|
2623
|
+
const retry = useCallback(() => {
|
|
2624
|
+
setRetryCount((c) => c + 1);
|
|
2625
|
+
}, []);
|
|
2597
2626
|
return {
|
|
2598
2627
|
agents,
|
|
2599
2628
|
isLoading,
|
|
2600
2629
|
error,
|
|
2601
|
-
retry
|
|
2630
|
+
retry
|
|
2602
2631
|
};
|
|
2603
2632
|
}
|
|
2604
2633
|
function useAssistantApi({
|