Skip to content

[T1] Core Lucid Agent — x402 paid API with TDD #1

@langoustine69

Description

@langoustine69

TaskMarket Bounty: $10 USDC

Summary

Build the production-ready Queryx Lucid Agent using the Lucid Agents SDK (TypeScript/Bun). This is the core of the product — a paid HTTP API accepting x402 USDC micropayments on Base Mainnet.

Required Endpoints

  • GET /v1/search — web search + AI synthesis ($0.001 USDC per call)
  • GET /v1/search/news — news-focused search ($0.001 USDC per call)
  • POST /v1/search/deep — multi-source deep research ($0.005 USDC per call)
  • GET /health — free

Response Schema (all paid endpoints)

{
  "query": "string",
  "answer": "string",
  "sources": [
    { "title": "string", "url": "string", "snippet": "string", "published": "ISO8601" }
  ],
  "confidence": 0.87,
  "freshness": { "fetchedAt": "ISO8601", "resultsAge": "4h" },
  "model": "queryx-fast-v1",
  "tokens": { "in": 312, "out": 187 }
}

Lucid Stack (mandatory)

  • @lucid-agents/core — agent runtime
  • @lucid-agents/http — transport
  • @lucid-agents/payments + paymentsFromEnv() — x402 paywall
  • @lucid-agents/hono v0.7.20+ — server adapter (Base x402 v2 support)
  • @lucid-agents/wallet, identity, a2a, ap2
  • Zod v4 (NOT v3 — z.toJSONSchema is required)

TDD Sequence (strict — tests written before implementation)

  1. Contract tests — all request/response schemas, error envelopes
  2. Logic tests — query normalization, source ranking, confidence scoring
  3. Integration tests — 402 without payment, 200 with valid payment
  4. Freshness/cache tests — TTL behaviour, staleness metadata, P95 budget

File Structure

src/
  index.ts           — export default { port, fetch: app.fetch }
  agent.ts           — agent + extension setup
  routes/
    search.ts        — GET /v1/search
    search-news.ts   — GET /v1/search/news
    search-deep.ts   — POST /v1/search/deep
  schemas/
    index.ts         — all Zod v4 schemas
  logic/
    search.ts        — query handling + source coordination
    synth.ts         — LLM synthesis interface
    cache.ts         — in-memory cache, 5min TTL
    rank.ts          — source ranking/dedup
tests/
  contract/          — schema + error envelope tests
  logic/             — pure transform tests
  integration/       — endpoint + paywall tests
  freshness/         — cache + staleness tests
package.json
.env.example
README.md
tsconfig.json

Required Env Vars

PAYMENTS_RECEIVABLE_ADDRESS=   # USDC receivable address on Base
FACILITATOR_URL=https://facilitator.daydreams.systems
NETWORK=base
BRAVE_API_KEY=                 # Brave Search API key
OPENAI_API_KEY=                # For GPT-4o-mini synthesis
PORT=3000
CACHE_TTL_SECONDS=300

Acceptance Criteria

  • All monetized endpoints return HTTP 402 without valid x402 payment
  • All monetized endpoints return valid JSON after payment
  • P95 response time on cached path < 200ms
  • All responses include freshness and confidence fields
  • 20+ tests passing (bun test clean)
  • Server uses export default { port, fetch: app.fetch } (no Bun.serve())
  • Zod v4 schemas export valid JSON Schema via toJSONSchema

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreCore implementationtaskmarketBounty on TaskMarket

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions