Skip to content

Latest commit

 

History

History
101 lines (74 loc) · 1.84 KB

File metadata and controls

101 lines (74 loc) · 1.84 KB

Consult API Worker

Cloudflare Worker backend for /api/consult.

What it does

  • Accepts public consult requests from the portfolio consult page.
  • Attempts Workers AI inference (@cf/meta/llama-3.1-8b-instruct).
  • Falls back to deterministic capability mapping if AI fails or times out.
  • Logs full request records to D1 (consult_logs).

Request / Response

POST /api/consult

Request JSON:

{
  "challenge": "Need help designing a multi-agent content pipeline...",
  "industry": "saas",
  "page": "/portfolio/consult/",
  "requestId": "uuid"
}

Success JSON:

{
  "ok": true,
  "mode": "ai",
  "analysisHtml": "<p>...</p>",
  "analysisText": "Plain text...",
  "requestId": "uuid",
  "durationMs": 482
}

Fallback JSON (mode: "fallback"):

{
  "ok": true,
  "mode": "fallback",
  "analysisHtml": "<p>...</p>",
  "analysisText": "Plain text...",
  "requestId": "uuid",
  "durationMs": 121,
  "note": "Workers AI is unavailable right now. Showing deterministic capability mapping."
}

Error JSON:

{
  "ok": false,
  "code": "BAD_INPUT",
  "message": "Challenge must be between 20 and 4000 characters.",
  "requestId": "uuid"
}

Setup

  1. Authenticate Wrangler:
npx wrangler whoami
  1. Create D1 database:
npx wrangler d1 create portfolio-consult-logs
  1. Copy returned database_id into workers/consult-api/wrangler.jsonc.

  2. Apply migrations:

npx wrangler d1 migrations apply portfolio-consult-logs --config workers/consult-api/wrangler.jsonc --remote
  1. Set secrets:
npx wrangler secret put LOG_HASH_SALT --config workers/consult-api/wrangler.jsonc
  1. Deploy:
npx wrangler deploy --config workers/consult-api/wrangler.jsonc
  1. Set frontend API base in deployment env:

PUBLIC_CONSULT_API_BASE=https://<your-worker-subdomain>.workers.dev