feat: Integration Phase 2 — config, live WS, auth, agent hot-add (#7, #11, #12) #39

Merged
perplexity merged 1 commits from feat/integration-phase2 into fix/qa-sprint-v2 2026-03-18 21:53:46 -04:00
Owner

Integration Phase 2

This PR implements the three highest-leverage integration issues, forming the complete Phase 2 integration layer:

1. js/config.js — Connection Configuration (Issue #7)

  • URL param overrides: ?ws=, ?token=, ?mock=true
  • Env var support: VITE_WS_URL, VITE_WS_TOKEN, VITE_MOCK_MODE
  • Priority chain: URL params > env vars > defaults
  • Computed getters: Config.isLive, Config.wsUrlWithAuth

2. WS Authentication — Phase 1 Shared Secret (Issue #11)

  • Auth token appended as ?token= query param on WebSocket connect
  • Configurable via ?token= URL param or VITE_WS_TOKEN env var
  • Clean upgrade path to L402 in Phase 3 (just swap the auth logic in config.js)

3. js/websocket.js — Live WS Client (Issue #7)

  • Live/mock switching via Config.isLive
  • Reconnection with exponential backoff (2s → 30s cap)
  • Heartbeat with 30s ping / 5s timeout for zombie detection
  • sendMessage() API for UI → backend communication
  • agent_joined handler dispatches to addAgent() for hot-add

4. Dynamic Agent Hot-Add (Issue #12)

  • addAgent(def): spawns 3D avatar at runtime without page reload
  • autoPlace(): finds unoccupied position on circular rings (radius 8+, 30° increments)
  • removeAgent(id): clean GPU dispose + connection line rebuild
  • Connection distance threshold widened (8→14) to accommodate larger agent rings

How to Use

Mock mode (default): No changes needed, works as before.

Live mode:

# Via URL params
https://matrix.example.com/?ws=ws://tower:8080/ws/world-state&token=my-secret

# Via env vars
VITE_WS_URL=ws://tower:8080/ws/world-state VITE_WS_TOKEN=my-secret npx vite

Agent hot-add event: Backend sends:

{"type": "agent_joined", "id": "scout", "label": "SCOUT", "color": "00ffcc", "role": "scout"}

Build

  • Vite build passes (16 modules, 0 errors)
  • No breaking changes — mock mode behavior unchanged

Closes #7, #11, #12

## Integration Phase 2 This PR implements the three highest-leverage integration issues, forming the complete Phase 2 integration layer: ### 1. `js/config.js` — Connection Configuration (Issue #7) - **URL param overrides**: `?ws=`, `?token=`, `?mock=true` - **Env var support**: `VITE_WS_URL`, `VITE_WS_TOKEN`, `VITE_MOCK_MODE` - **Priority chain**: URL params > env vars > defaults - **Computed getters**: `Config.isLive`, `Config.wsUrlWithAuth` ### 2. WS Authentication — Phase 1 Shared Secret (Issue #11) - Auth token appended as `?token=` query param on WebSocket connect - Configurable via `?token=` URL param or `VITE_WS_TOKEN` env var - Clean upgrade path to L402 in Phase 3 (just swap the auth logic in config.js) ### 3. `js/websocket.js` — Live WS Client (Issue #7) - **Live/mock switching** via `Config.isLive` - **Reconnection** with exponential backoff (2s → 30s cap) - **Heartbeat** with 30s ping / 5s timeout for zombie detection - **`sendMessage()` API** for UI → backend communication - **`agent_joined` handler** dispatches to `addAgent()` for hot-add ### 4. Dynamic Agent Hot-Add (Issue #12) - `addAgent(def)`: spawns 3D avatar at runtime without page reload - `autoPlace()`: finds unoccupied position on circular rings (radius 8+, 30° increments) - `removeAgent(id)`: clean GPU dispose + connection line rebuild - Connection distance threshold widened (8→14) to accommodate larger agent rings ### How to Use **Mock mode (default)**: No changes needed, works as before. **Live mode**: ``` # Via URL params https://matrix.example.com/?ws=ws://tower:8080/ws/world-state&token=my-secret # Via env vars VITE_WS_URL=ws://tower:8080/ws/world-state VITE_WS_TOKEN=my-secret npx vite ``` **Agent hot-add event**: Backend sends: ```json {"type": "agent_joined", "id": "scout", "label": "SCOUT", "color": "00ffcc", "role": "scout"} ``` ### Build - ✅ Vite build passes (16 modules, 0 errors) - ✅ No breaking changes — mock mode behavior unchanged Closes #7, #11, #12
perplexity added 1 commit 2026-03-18 21:10:34 -04:00
- js/config.js: connection config with URL param + env var override
  - WS URL, auth token, mock mode toggle
  - Computed isLive and wsUrlWithAuth getters
  - Resolves #7 (config.js)
  - Resolves #11 (Phase 1 shared-secret auth via query param)

- js/websocket.js: refactored to use Config for live/mock switching
  - Live mode: real WS with reconnection + exponential backoff
  - Auth token appended as ?token= on WS connect
  - agent_joined handler dispatches to addAgent() for hot-add
  - sendMessage() public API for UI → backend communication

- js/agents.js: dynamic agent hot-add and removal
  - addAgent(def): spawns 3D avatar at runtime without reload
  - autoPlace(): finds unoccupied circular slot (radius 8+)
  - removeAgent(id): clean dispose + connection line rebuild
  - Connection distance threshold 8→14 for larger agent rings
  - Resolves #12 (dynamic agent hot-add)
perplexity merged commit 086eaf943c into fix/qa-sprint-v2 2026-03-18 21:53:46 -04:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: perplexity/the-matrix#39