Date: 2026-05-20
Task: agent-state-worker-proxy
Added proxy routes to the diamond-node Cloudflare Worker to enable access to the agent state API and WebSocket through yennefer.quest.
- Proxies GET requests to orchestrator at
YENNEFER_API_URL(default: http://localhost:8080) - Forwards
Authorizationheader withGATEWAY_SECRET - Returns JSON with proper CORS and cache headers
- Graceful error handling with 503 status when orchestrator unavailable
- Added route handler with 426 status for non-WebSocket upgrade requests
- Returns informative 501 response directing users to Cloudflare Tunnel endpoint
- Documents that WebSocket proxying through CF Workers requires special setup
- Provides fallback guidance to use REST API polling
Updated connectAgentWebSocket() function with environment-aware URL selection:
function connectAgentWebSocket() {
let wsUrl;
if (window.location.hostname.includes('yennefer.quest')) {
// Production: Use Cloudflare Tunnel endpoint directly
wsUrl = 'wss://api.yennefer.quest/ws/agent-state';
} else {
// Development: Connect to same origin
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
wsUrl = `${wsProtocol}//${window.location.host}/ws/agent-state`;
}
agentWS = new WebSocket(wsUrl);
}Production behavior: Dashboard on yennefer.quest connects directly to wss://api.yennefer.quest/ws/agent-state (Cloudflare Tunnel)
Development behavior: Dashboard connects to same-origin WebSocket endpoint
Added environment variables to Env interface:
YENNEFER_API_URL?: string— Orchestrator API URL (default: http://localhost:8080)GATEWAY_SECRET?: string— Auth secret for orchestrator requests
Cloudflare Workers support WebSocket upgrades, but proxying WebSocket connections through Workers to backend services requires special handling:
- Durable Objects: Full WebSocket proxying typically requires CF Durable Objects
- Cloudflare Tunnel (Recommended): For production, use Cloudflare Tunnel at
api.yennefer.questto expose the orchestrator directly - Fallback: REST API at
/api/agent/stateprovides polling alternative
- REST API: Fully functional proxy through Worker ✅
- WebSocket: Dashboard connects directly to tunnel endpoint in production ✅
- Development: WebSocket connects to local orchestrator ✅
cd ~/diamond-node
wrangler secret put GATEWAY_SECRET
wrangler secret put YENNEFER_API_URL # Optional, defaults to http://localhost:8080cd ~/diamond-node
npm run typecheck # ✅ Passes
npm run deploycloudflared tunnel create api-yennefer-quest
cloudflared tunnel route dns api-yennefer-quest api.yennefer.quest
cloudflared tunnel run --url http://localhost:8080 api-yennefer-quest# Development
curl http://localhost:8787/api/agent/state
# Production
curl https://yennefer.quest/api/agent/stateDevelopment:
const ws = new WebSocket('ws://localhost:8787/ws/agent-state');Production (via Cloudflare Tunnel):
const ws = new WebSocket('wss://api.yennefer.quest/ws/agent-state');- Agent state API accessible through Worker
- WebSocket connection strategy documented
- Dashboard updated to use correct WebSocket URL based on environment
- Error handling for unavailable services (503 status)
- CORS headers configured (
Access-Control-Allow-Origin: *) - TypeScript types pass validation
- Cache control headers for API responses (
no-cache)
- Deploy Worker:
cd ~/diamond-node && npm run deploy - Configure Cloudflare Tunnel: Set up
api.yennefer.quest→http://localhost:8080 - Test Endpoints: Verify REST API and WebSocket connections
- Monitor Logs: Check
wrangler tailfor proxy errors
src/index.ts— Added/api/agent/stateand/ws/agent-stateroutessrc/yennefer-dashboard.ts— Updated WebSocket connection logicsrc/types.ts— AddedYENNEFER_API_URLandGATEWAY_SECRETto Env interface
/home/diamondnode/YENNEFER_INTEGRATION_QUICKREF.md— Yennefer orchestrator integration/home/diamondnode/YENNEFER_PRODUCTION_STATUS.md— Production deployment status/home/diamondnode/diamond-node/CLAUDE.md— Diamond node architecture
Status: Complete
Verified: TypeScript passes, routes implemented, documentation updated