Implementation:AIScientists Dev WorldSeed usePolling
| Knowledge Sources | |
|---|---|
| Domains | Frontend, Data_Loading |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Concrete React hook providing unified run data loading, live tick updates, and agent data polling, provided by the WorldSeed frontend.
Description
The usePolling hook returns `pollWorld` and `pollAgentData` functions. `pollWorld` polls `/health` for world status, loads run data (state, stream, meta) once per run via `loadRunData`, then refreshes live state via `refreshLiveState` which detects new ticks, computes numeric deltas for display, and resets on run rollback. `pollAgentData` fetches the selected agent's inbox and run list. The hook uses module-level state (`runLoaded`, `lastLiveTick`, `pollCounter`) to track loading progress across renders. It composes `useSSE` for live event streaming. `computeDeltas` tracks property changes per tick, pruning deltas older than 2 ticks.
Usage
Import this hook in the dashboard component and call `pollWorld`/`pollAgentData` on a polling interval. It orchestrates all data loading for the main dashboard view.
Code Reference
Source Location
- Repository: WorldSeed
- File: frontend/src/hooks/usePolling.ts
Signature
export function usePolling(): {
pollWorld: () => Promise<void>;
pollAgentData: () => Promise<void>;
};
Import
import { usePolling } from '@/hooks/usePolling';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (none) | — | — │ Reads from Zustand stores (worldStore, agentStore, etc.) |
Outputs
| Name | Type | Description |
|---|---|---|
| pollWorld | async () => void │ Polls health, loads run, refreshes live state | |
| pollAgentData | async () => void │ Fetches selected agent's inbox + runs |
Usage Examples
import { useEffect } from 'react';
import { usePolling } from '@/hooks/usePolling';
function Dashboard() {
const { pollWorld, pollAgentData } = usePolling();
useEffect(() => {
const worldTimer = setInterval(pollWorld, 1000);
const agentTimer = setInterval(pollAgentData, 2000);
return () => {
clearInterval(worldTimer);
clearInterval(agentTimer);
};
}, [pollWorld, pollAgentData]);
return <div>{/* dashboard */}</div>;
}