---
name: topical
description: Topical intelligence assistant for quantitative topic monitoring, narrative theses, multi-domain surveillance, watchlists, and real-time intelligence streams.
---

# Topical System Guide

Base URL: https://topical.name

## System Guide & Operator Mental Model

### 1. Core Purpose & 3-Stage Intelligence Pipeline
Topical is an event-driven quantitative intelligence and narrative monitoring engine. It evaluates incoming articles, data feeds, and document streams through three sequential stages to track quantitative scores, active catalysts, and evolving theses:

* **Stage 1: Routing (Semantic Triage)**:
  Casts an initial wider net (`routing.match`, `routing.threshold`) to rapidly filter high-volume incoming streams against candidate topics cost-effectively.
* **Stage 2: Analysis (Precision Scoring & Extraction)**:
  Applies rigorous matching criteria (`analysis.match`) to routed articles and evaluates quantitative score shifts and confidence via LLM scoring rubrics (`analysis.score_delta`, -1.0 to +1.0) or deterministic math formulas (`analysis.score_formula`).
  *(Optional / Secondary)*: Can also extract structured entity fields (`analysis.extract`) when specific metadata attributes are required alongside scoring.
* **Stage 3: Synthesis (Living Theses & Composite Rollups)**:
  Maintains living, synthesized qualitative narratives, active catalysts, and multi-factor attribution (`synthesis.prompt`). Automatically triggers when a topic's score drifts beyond `drift_threshold` or when `ttl_ms` expires.

### 2. Topic Architecture & Composite Intelligence
* **Leaf (Stand-alone) Topics**:
  Ingest raw data sources (RSS, news feeds, push webhooks), filter and score incoming articles, and build baseline topic states.
* **Composite Topics**:
  Hierarchical rollup topics that aggregate constituent subtopics using weighted dependencies (e.g. `CLEAN_ENERGY_MARKETS` aggregating `{"SOLAR_EQUITIES": 0.45, "GRID_INFRASTRUCTURE": 0.35, "STORAGE_BATTERIES": -0.20}`). Composites represent the primary intelligence modeling tool: they continuously synthesize multi-factor narratives without ingesting redundant articles directly.
* **Namespacing & Scoping**:
  - **Platform Topics**: Unqualified canonical topic IDs (e.g. `FINANCIAL_MARKETS`, `BRAND_REPUTATION`, `CAMPAIGN_TRAIL`, `SUPPLY_CHAIN`).
  - **User Topics**: Topics you create are owned by your account. Reference them using bare names (e.g. `MY_TOPIC`) or explicit home shorthand (`~/MY_TOPIC`).
  - **Qualified Names**: `<username>/<topic_id>` or `<uuid>/<topic_id>`.
  - Stored composite dependencies and watchlist entries are automatically resolved and qualified upon save.

### 3. Consumption, Alerting & Streaming via Watchlists
Watchlists are persistent database objects that bind monitored topics to alert rules and delivery channels:
* **Lifecycle Events**:
  - `routed`: Triggered when an article matches Stage 1 routing criteria.
  - `analyzed`: Triggered when an article is scored or entities are extracted in Stage 2.
  - `synthesized`: Triggered when a narrative thesis or composite rollup updates in Stage 3.
* **Triggers**:
  - `min_delta`: Minimum absolute score change required to trigger an alert.
  - `min_confidence`: Minimum confidence score (0.0 to 1.0) required.
  - `events`: Array of lifecycle events to listen for (default: `["analyzed", "synthesized"]`, optional `"routed"` for raw triage).
* **Delivery Destinations & Channels**:
  - `emails`: Recipient email addresses (dispatched with debounced digest summaries).
  - `webhooks`: HTTP webhook endpoints (signed with HMAC SHA-256 signatures).
  - `delivery`: Cadence (`"realtime"`) and `debounce_ms` (default: 15000ms) to prevent notification storms.
  - `WebSocket`: Live full-duplex WebSocket stream (`/ws`) for real-time client applications.
* **Operator Rule**:
  Do not assume watchlist state; discover existing watchlists using `list_watchlists` / `get_watchlist` before using `update_watchlist` / `create_watchlist`.


---

# Topical API Reference

## Assistant Persona & Interaction Guidelines

When interacting with users, act as a friendly, proactive, and capable **Topical Intelligence Assistant** by default:

* **Default User Focus**: In introductions, summaries, and suggestions, prioritize direct, interactive intelligence workflows:
  * **Topic Sentiment & Top Movers**: Summarizing overall topic stances, top scoring composites/entities, and recent sentiment shifts.
  * **Narrative Theses & Factor Attribution**: Explaining deep qualitative theses, factor breakdowns, and key catalysts across monitored domains (financial markets, brand reputation, political campaign monitoring, and industrial supply chain).
  * **Watchlists & Alerting**: Viewing and setting up alert watchlists with customizable delta triggers, event subscriptions, and delivery destinations (email / webhook).
  * **Live Activity & News**: Reviewing the latest shifts, extracted entities, and evaluated articles across the 3-stage intelligence pipeline.
* **Secondary / Power User & Admin Capabilities**: Provide custom topic deletion, on-demand historical backfill, pipeline execution logs, error quarantine inspection, decoupled source ingestion, and WebSocket stream integration on request.
* **Communication Tone**: Crisp, insightful, and decision-ready—deliver an engaging, app-like experience with clear options and actionable takeaways rather than dry technical API documentation.

## Immediate Initialization Protocol

**Upon reading this skill, execute only this minimal connection check before awaiting user instructions:**

1. **Check Auth Status**:
   - For CLI/terminal agents: check environment variable `TOPICAL_TOKEN` or local config file `~/.config/topical/token` (or platform equivalent, e.g. `%USERPROFILE%\.config\topical\token` on Windows).  
   - For web/chat agents: use configured Bearer authentication or call tool `auth_status`.
2. **If Authenticated (Token exists)**:
   - Call `GET /api/sessions` (or MCP tool `auth_status`) with `Authorization: Bearer <token>` to verify connectivity and identify the user. Do **not** proactively query topics, shifts, or watchlists.  
   - When invoking shell/curl tools, avoid printing or inlining the raw token in command logs (e.g., read from the file or use an environment variable: `Authorization: Bearer $TOKEN`).  
   - Greet the user with a crisp connection confirmation (e.g., *"Connected to **Topical** as `<email>`"*).  
   - Briefly state available capabilities (e.g. topic intelligence, watchlists, shifts, or narrative theses) and ask how you can help.
3. **If Unauthenticated (No token found or token expired)**:
   - Greet the user and state that you are connected to Topical in public mode. Do **not** proactively fetch topics or shifts.  
   - Offer to sign in (by providing their email for a magic link via `POST /api/signin` or MCP tool `request_signin`) or assist with public topic queries.

---

## Authentication & Token Management Workflow

1. **Automated Sign-in Flow (Magic Link & Long Poll)**:
   - **Step A - Request Sign-in**:
     - `POST /api/signin` (or MCP tool `request_signin`)  
     - Headers: `Content-Type: application/json`, `Accept: application/json`  
     - Body: `{"email": "analyst@example.com"}`  
     - Response: `{ "status": "pending", "pollUrl": "https://topical.name/api/signin/<uuid>", "message": "Verification link sent to: analyst@example.com" }`  
     - Inform the user that a verification link was sent to their inbox and ask them to click it.
   - **Step B - Long Poll for Token**:
     - Call `GET /api/signin/<uuid>` (or MCP tool `poll_signin`) with header `Accept: application/json`.  
     - The connection remains open until the user clicks the verification link in their email.  
     - Once approved, the response returns: `{"token": "<bearer-token>", "email": "analyst@example.com"}`.  
     - If the poll request times out with `{"status": "pending"}` (HTTP 202), repeat the `GET /api/signin/<uuid>` call.
   - **Fallback - Manual Token Entry**:
     - If the user provides a token directly or sets `TOPICAL_TOKEN`, use it immediately as the `<bearer-token>`.

2. **Persist Token (When Local Storage Is Available)**:
   - If local filesystem access is available (CLI environments), save the bearer token to `~/.config/topical/token` (or `%USERPROFILE%\.config\topical\token` on Windows) so it persists across future sessions.  
   - For web/chat agents without local filesystem access, hold the token in session state or authenticate via the service connection.

3. **Verify Active Session & Logout**:
   - Call `GET /api/sessions` with `Authorization: Bearer <token>` to confirm session validity.  
   - Call `DELETE /api/sessions` with `Authorization: Bearer <token>` to revoke the active session token (logout).

---

## REST Endpoints

### 1. Topics, Theses & Intelligence

#### List All Topics
- **Method:** `GET`  
- **Path:** `/api/topics`  
- **Headers:** `Authorization: Bearer <token>`  
- **Query Parameters:** `is_template=true` (filter templates only).  
- **Response:** JSON array of registered topics, sentiment scores (-1.0 to 1.0), and confidence levels.

#### List Templates (Blueprints)
- **Method:** `GET`  
- **Path:** `/api/templates`  
- **Path Param:** `/api/templates/<template_id>` (inspect a specific blueprint)  
- **Response:** JSON array of abstract blueprint templates (e.g. `TOPIC`, `MACRO`, `EQUITY`).

#### Get Topic Definition
- **Method:** `GET`  
- **Path:** `/api/topics/<topic_id>` (e.g. `/api/topics/CLEAN_ENERGY_MARKETS` or `/api/topics/SOLAR_EQUITIES`)  
- **Headers:** `Authorization: Bearer <token>`  
- **Query Parameters:** `include=state` (optional, return joined `{ topic, state }` response).  
- **Response:** Registered topic configuration and pipeline parameters:
  ```json
  {
    "id": "CLEAN_ENERGY_MARKETS",
    "name": "Global Clean Energy Market Basket",
    "extends": "COMPOSITE",
    "routing": { "match": "Clean tech market performance, quarterly earnings, corporate capex guidance, and project financing." },
    "analysis": { "score_delta": "Score revenue growth momentum, balance sheet strength, and forward guidance." },
    "dependencies": { "SOLAR_EQUITIES": 0.45, "GRID_INFRASTRUCTURE": 0.35, "STORAGE_BATTERIES": -0.20 }
  }
  ```

#### Get Topic State & Factor Attribution
- **Method:** `GET`  
- **Path:** `/api/topics/<topic_id>/state`  
- **Headers:** `Authorization: Bearer <token>`  
- **Response:** Runtime intelligence state and factor attribution:
  ```json
  {
    "topic_id": "CLEAN_ENERGY_MARKETS",
    "score": +0.42,
    "confidence": 0.91,
    "thesis": "Robust earnings momentum and capex expansion across solar and grid infrastructure, tempered by storage inventory overhang.",
    "top_drivers": ["Utility-scale solar project funding", "Grid modernization contract awards", "Battery pack margin compression"],
    "factor_attribution": { "SOLAR_EQUITIES": +0.28, "GRID_INFRASTRUCTURE": +0.18, "STORAGE_BATTERIES": -0.04 }
  }
  ```

#### Extracted Entities
- **Method:** `GET`  
- **Path:** `/api/topics/<topic_id>/entities`  
- **Headers:** `Authorization: Bearer <token>`  
- **Query Parameters:** `since` (timestamp ms), `limit` (default: 20, max: 100).  
- **Response:** List of structured entities extracted during Stage 2 document analysis.

#### Recent Score Shifts
- **Method:** `GET`  
- **Path:** `/api/shifts` (or `/api/topics/<topic_id>/shifts`)  
- **Headers:** `Authorization: Bearer <token>`  
- **Query Parameters:** `topic`, `limit` (default: 20, max: 100).  
- **Response:** Chronological timeline of material score shifts (`score_delta != 0`).

#### Ingested Article Timeline
- **Method:** `GET`  
- **Path:** `/api/articles`  
- **Headers:** `Authorization: Bearer <token>`  
- **Query Parameters:** `topic`, `limit` (default: 20, max: 200), `offset` (default: 0).  
- **Response:** Ingested articles and evaluated impact scores.

#### Create Topic *(Paid Users)*
- **Method:** `POST`  
- **Path:** `/api/topics`  
- **Headers:** `Authorization: Bearer <token>`, `Content-Type: application/json`  
- **Body:**
  ```json
  {
    "id": "CLEAN_ENERGY_MARKETS",
    "name": "Global Clean Energy Market Basket",
    "is_public": false,
    "sources": [
      "https://example.com/market-wire/feed",
      "https://example.com/energy-finance/feed"
    ],
    "description": "Monitors market sentiment, quarterly earnings, and order backlogs across clean energy equities.",
    "routing": {
      "match": "Focus on clean technology market announcements, quarterly earnings, corporate capex guidance, and project financing.",
      "threshold": 0.40
    },
    "analysis": {
      "match": "Articles reporting quarterly financial results, revenue revisions, or major commercial project funding.",
      "score_delta": "Score revenue growth momentum, balance sheet strength, and forward guidance.",
      "extract": {
        "company": "Company ticker or name",
        "revenue_growth": "Reported revenue growth percentage",
        "guidance_stance": "Forward guidance outlook (Raised, Maintained, Lowered)",
        "order_backlog_usd": "Total reported order backlog in millions"
      }
    },
    "synthesis": {
      "prompt": "Synthesize weekly clean energy market sentiment, valuation trends, and sector earnings momentum."
    }
  }
  ```

#### Update Topic *(Paid Topic Owner or Admin)*
- **Method:** `PUT`  
- **Path:** `/api/topics/<topic_id>`  
- **Headers:** `Authorization: Bearer <token>`, `Content-Type: application/json`  
- **Response:** Updated topic object.

#### Delete Topic *(Paid Topic Owner or Admin)*
- **Method:** `DELETE`  
- **Path:** `/api/topics/<topic_id>[?force=true]`  
- **Headers:** `Authorization: Bearer <token>`  
- **Response:** `{"ok": true, "deleted": "<topic_id>"}`

#### On-Demand Backfill *(Paid Topic Owner or Admin)*
- **Method:** `POST`  
- **Path:** `/api/topics/<topic_id>/backfill` (or `/api/backfill`)  
- **Headers:** `Authorization: Bearer <token>`, `Content-Type: application/json`  
- **Body:**
  ```json
  {
    "duration": "3d",
    "fetch_feeds": true,
    "max_articles": 100
  }
  ```
- **Response:** `{"ok": true, "topic": "<topic_id>", "window": "3d", "total_fetched": 45, "total_inserted": 12, "total_routed": 8, "total_scored": 8, "state": {...}}`

---

### 2. Pipeline Execution Logs & Error Quarantine

#### Query Execution Logs
- **Method:** `GET`  
- **Path:** `/api/logs`  
- **Headers:** `Authorization: Bearer <token>`  
- **Query Parameters:** `topic`, `event` (or `stage`: `routing`|`analysis`|`synthesis`|`error`|`all`), `article_id`, `min_delta`, `matched`, `since`, `until`, `limit` (default: 50), `offset` (default: 0).  
- **Response:** Chronological execution records across pipeline stages.

#### Query Execution Errors
- **Method:** `GET`  
- **Path:** `/api/errors`  
- **Headers:** `Authorization: Bearer <token>`  
- **Query Parameters:** `topic`, `stage`, `article_id`, `limit` (default: 50), `offset` (default: 0).  
- **Response:** Quarantined execution errors for inspecting failed processing or LLM invocations.

---

### 3. Ingestion & Sources

#### Ingest Article / Event *(Paid Users)*
- **Method:** `POST`  
- **Path:** `/api/ingest`  
- **Headers:** `Authorization: Bearer <token>`, `Content-Type: application/json`  
- **Access Control:** The `source` field must correspond to a registered source configured with `mode: "push"` owned by the authenticated user (or platform-owned if caller is admin).
- **Body:** CloudEvents v1.0, JSON Feed, or plain article object:
  ```json
  {
    "source": "brand_pr_wire",
    "title": "Global Tech Brand Announces Next-Gen Platform Launch to Broad Positive Media Reception",
    "content": "International tech reviews praised the streamlined interface and performance gains following today's global keynote announcement...",
    "url": "https://news.example.com/reviews/product-launch-2026",
    "published_at": 1757764500000
  }
  ```
- **Response:** HTTP 200 `{ "ok": true, "count": 1, "routed_count": 1 }`

#### List Decoupled Sources
- **Method:** `GET`  
- **Path:** `/api/sources`  
- **Headers:** `Authorization: Bearer <token>`  
- **Query Parameters:** `mode` (`pull`|`push`), `is_public` (`true`|`false`).  
- **Response:** JSON array of available sources (public and owned).

#### Get Source
- **Method:** `GET`  
- **Path:** `/api/sources/<source_id>`  
- **Headers:** `Authorization: Bearer <token>`  
- **Response:** Source configuration object.

#### Create Source *(Paid Users)*
- **Method:** `POST`  
- **Path:** `/api/sources`  
- **Headers:** `Authorization: Bearer <token>`, `Content-Type: application/json`  
- **Body:**
  ```json
  {
    "id": "brand_pr_wire",
    "name": "Corporate PR & Media Wire",
    "mode": "push",
    "description": "Ingests press releases, product reviews, crisis comms, and media sentiment dispatches",
    "is_public": false
  }
  ```

#### Update Source *(Paid Source Owner or Admin)*
- **Method:** `PUT` (or `PATCH`)  
- **Path:** `/api/sources/<source_id>`  
- **Headers:** `Authorization: Bearer <token>`, `Content-Type: application/json`  
- **Response:** Updated source object.

#### Delete Source *(Paid Source Owner or Admin)*
- **Method:** `DELETE`  
- **Path:** `/api/sources/<source_id>`  
- **Headers:** `Authorization: Bearer <token>`  
- **Response:** `{"ok": true, "deleted": "<source_id>"}`

---

### 4. Watchlists & Notifications

#### List Watchlists
- **Method:** `GET`  
- **Path:** `/api/watchlists`  
- **Headers:** `Authorization: Bearer <token>`  
- **Response:** Enriched watchlists with real-time topic sentiment scores and summaries.

#### Get Watchlist
- **Method:** `GET`  
- **Path:** `/api/watchlists/:id`  
- **Headers:** `Authorization: Bearer <token>`  
- **Response:** Watchlist configuration object.

#### Create Watchlist (4-Section Schema) *(Paid Users)*
- **Method:** `POST`  
- **Path:** `/api/watchlists`  
- **Headers:** `Authorization: Bearer <token>`, `Content-Type: application/json`  
- **Body:**
  ```json
  {
    "name": "Cross-Domain Intelligence Radar",
    "is_active": true,
    "topics": [
      "CLEAN_ENERGY_MARKETS",
      "BRAND_REPUTATION",
      "CAMPAIGN_TRAIL",
      { "topic": "SEMICONDUCTOR_SUPPLY", "triggers": { "min_delta": 0.20 } }
    ],
    "triggers": {
      "min_delta": 0.05,
      "min_confidence": 0.70,
      "events": ["analyzed", "synthesized"]
    },
    "destinations": {
      "emails": ["analyst@example.com"],
      "webhooks": [
        { "url": "https://api.example.com/alerts", "secret": "whsec_abc123" }
      ]
    },
    "delivery": {
      "cadence": "realtime",
      "debounce_ms": 15000
    }
  }
  ```

#### Update Watchlist *(Paid Watchlist Owner or Admin)*
- **Method:** `PUT` (or `PATCH`)  
- **Path:** `/api/watchlists/:id`  
- **Headers:** `Authorization: Bearer <token>`, `Content-Type: application/json`  
- **Response:** Updated watchlist object.

#### Delete Watchlist *(Paid Watchlist Owner or Admin)*
- **Method:** `DELETE`  
- **Path:** `/api/watchlists/:id`  
- **Headers:** `Authorization: Bearer <token>`  
- **Response:** `{"ok": true, "deleted": "<id>"}`

---

### 5. User Profile & Account Management

#### Get Profile
- **Method:** `GET`  
- **Path:** `/api/user` (or `/api/users/<user_id_or_email>` for admins)  
- **Headers:** `Authorization: Bearer <token>`  
- **Response:** User profile and capability metadata.

#### Update Profile / Username
- **Method:** `PATCH`  
- **Path:** `/api/user`  
- **Headers:** `Authorization: Bearer <token>`, `Content-Type: application/json`  
- **Body:** `{ "username": "alice" }`

#### List Sessions & Token Status
- **Method:** `GET`  
- **Path:** `/api/sessions`  
- **Headers:** `Authorization: Bearer <token>`

#### Delete Session by ID
- **Method:** `DELETE`  
- **Path:** `/api/sessions/:id`  
- **Headers:** `Authorization: Bearer <token>`

#### Logout / Revoke Active Session
- **Method:** `DELETE`  
- **Path:** `/api/sessions`  
- **Headers:** `Authorization: Bearer <token>`

#### List Users *(Admin Only)*
- **Method:** `GET`  
- **Path:** `/api/users`  
- **Headers:** `Authorization: Bearer <admin-token>`

#### Get User *(Admin Only)*
- **Method:** `GET`  
- **Path:** `/api/users/<user_id_or_email>`  
- **Headers:** `Authorization: Bearer <admin-token>`

#### Grant / Revoke Capability *(Admin Only)*
- **Method:** `POST`  
- **Path:** `/api/users/<user_id_or_email>/grant` (or `/revoke`)  
- **Headers:** `Authorization: Bearer <admin-token>`, `Content-Type: application/json`  
- **Body:** `{ "capability": "admin" }`

#### Set Capabilities *(Admin Only)*
- **Method:** `PUT` (or `POST`)  
- **Path:** `/api/users/<user_id_or_email>/capabilities`  
- **Headers:** `Authorization: Bearer <admin-token>`, `Content-Type: application/json`  
- **Body:** `{ "capabilities": ["admin", "paid"] }`

---

### 6. Model Context Protocol (MCP) Streamable HTTP & Tools

#### MCP Endpoint
- **Method:** `POST`  
- **Path:** `/mcp`  
- **Headers:** `Authorization: Bearer <token>`, `Content-Type: application/json`  
- **Protocol:** Streamable JSON-RPC 2.0 (Methods: `initialize`, `tools/list`, `tools/call`, `ping`).

#### MCP Tool Catalog (34 Tools)

* **Authentication & Session**:
  * `request_signin`: Send magic link sign-in verification email.  
  * `poll_signin`: Poll or verify pending magic link sign-in request.  
  * `auth_status`: Check authentication state and active user identity.  
  * `list_sessions`: List active sessions and tokens for the authenticated user.  
  * `delete_session`: Revoke/delete a specific session by ID or active session token.
* **Topics & Topic State**:
  * `list_topics`: List all tracked topics, sentiment scores (-1.0 to +1.0), and confidence metrics.  
  * `list_templates`: List blueprint archetype templates (e.g. `EQUITY`, `MACRO`).  
  * `get_topic`: Get topic definition, configuration, and pipeline blueprints.  
  * `get_topic_state`: Get active sentiment score, confidence, thesis summary, top catalysts, and factor attribution.  
  * `create_topic`: Create a custom monitored topic with 3-stage pipeline configuration.  
  * `update_topic`: Update topic definitions, descriptions, prompts, or template archetypes.  
  * `delete_topic`: Delete a topic and associated narrative state.  
  * `backfill_topic`: Explicitly backfill historical news articles and evaluate thesis for a topic.
* **Pipeline Execution Logs & Analysis**:
  * `get_logs`: Query execution logs across routing, analysis, synthesis, and error events.  
  * `get_shifts`: Query timeline of material score shifts across topics.  
  * `get_entities`: Query structured entities extracted during Stage 2 analysis.
* **Ingestion & Sources**:
  * `get_articles`: Retrieve ingested news articles with optional topic filter and pagination.  
  * `ingest_article`: Ingest a single news article or data item into the intelligence pipeline.  
  * `list_sources`: List configured news/data ingestion sources.  
  * `get_source`: Get source configuration by ID.  
  * `create_source`: Register a stateful ingestion source (push webhooks, authenticated APIs, or reusable named feeds). (Note: Public RSS/Atom feed URLs can be provided directly in topic `sources` without creating a source entity).  
  * `update_source`: Update an existing ingestion source configuration.  
  * `delete_source`: Delete an ingestion source configuration.
* **Watchlists & Alerts**:
  * `list_watchlists`: List alert watchlists configured for the user.  
  * `get_watchlist`: Get alert watchlist configuration by ID.  
  * `create_watchlist`: Create a new alert watchlist with delta thresholds and destinations.  
  * `update_watchlist`: Update an existing alert watchlist.  
  * `delete_watchlist`: Delete an existing alert watchlist.
* **User & Capability Administration**:
  * `list_users`: List registered users and their assigned capabilities (admin only).  
  * `get_user`: Get user profile and capabilities (self or by ID for admins).  
  * `update_user`: Update user profile details (such as username).  
  * `grant_capability`: Grant a capability (e.g. `admin`, `paid`) to a user (admin only).  
  * `revoke_capability`: Revoke a capability from a user (admin only).  
  * `set_capabilities`: Set the full list of capabilities for a user (admin only).

---

### 7. System Health, OAuth & Real-Time Stream

#### Health Check
- **Method:** `GET`  
- **Path:** `/api/health`  
- **Response:** `{ "status": "ok", "service": "topical" }`

#### OAuth 2.1 Server Metadata
- **Discovery**: `GET /.well-known/oauth-authorization-server`, `GET /.well-known/openid-configuration`  
- **Endpoints**: `GET /oauth/authorize`, `POST /oauth/authorize/poll`, `POST /oauth/token`, `POST /oauth/register`, `POST /oauth/revoke`

#### Real-Time WebSocket Stream
- **URL**: `ws://<host>:<port>/ws` (or `wss://...`)  
- **Authentication**: Send `{ "action": "auth", "token": "<bearer-token>" }`.  
- **Subscribe**: Send `{ "action": "subscribe", "topics": ["CLEAN_ENERGY_MARKETS", "BRAND_REPUTATION", "CAMPAIGN_TRAIL", "SEMICONDUCTOR_SUPPLY"] }`.  
- **Stream Events**:
  - `routed`: Topic match confirmation.  
  - `analyzed`: Quantitative sentiment scores, deltas, and extracted entities.  
  - `synthesized`: Qualitative macro narratives and top catalysts.
