#!/usr/bin/env python3
"""Observable data loader: all workstreams."""
import json
import os
import urllib.request
import urllib.error

API_BASE = os.environ.get("API_BASE", "http://127.0.0.1:8000").rstrip("/")
_HEADERS = {"X-StateHub-Component": "state-hub.dashboard.workstreams-list"}

try:
    req = urllib.request.Request(f"{API_BASE}/workplans", headers=_HEADERS)
    with urllib.request.urlopen(req, timeout=10) as resp:
        data = json.loads(resp.read())
    print(json.dumps(data))
except urllib.error.URLError as e:
    print(json.dumps({"error": str(e), "workstreams": []}))
