Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AIScientists Dev WorldSeed usePolling

From Leeroopedia
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>;
}

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment