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:23blocks OS Ai maestro Use Hosts Hook

From Leeroopedia
Knowledge Sources
Domains UI, Networking
Last Updated 2026-10-26 18:00 GMT

Overview

Concrete tool for fetching and managing configured hosts with exponential-backoff retry, periodic refresh, and stale-data refetch on tab focus, provided by AI Maestro's `hooks/useHosts.ts`.

Description

The useHosts hook fetches the mesh host list from `/api/hosts` with a 10-second timeout (increased from 5s for mobile networks). On failure it retries with exponential backoff (1s, 2s, 4s, 8s, max 15s). It refreshes every 30 seconds and refetches on `visibilitychange` if data is stale (>30s), so switching tabs always shows fresh host status.

Usage

Call `useHosts()` at the top level. Read `hosts`, `loading`, `error`. The hook manages its own polling and retry lifecycle.

Code Reference

Source Location

  • Repository: ai-maestro
  • File: hooks/useHosts.ts
  • Lines: L1-L110

Signature

export function useHosts(): {
  hosts: Host[]
  loading: boolean
  error: Error | null
}

Import

import { useHosts } from '@/hooks/useHosts'

I/O Contract

Name Type Description
hosts Host[] All configured hosts
loading boolean True during fetch
error null Error on failure

Usage Examples

import { useHosts } from '@/hooks/useHosts'

function HostList() {
  const { hosts, loading } = useHosts()
  if (loading) return <p>Loading…</p>
  return hosts.map(h => <div key={h.id}>{h.name}</div>)
}

Related Pages

Implements Principle

Requires Environment

Page Connections

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