refactor(semantle): swap word2sim backend for ConceptNet

ConceptNet provides a free public /relatedness endpoint (returns cosine-like
[-1, 1]) and /c/en/{term} for vocabulary check. No random-word endpoint, so
we ship a curated local target pool in wordlist.js (~250 words) and verify
each pick via the concept endpoint with a fallback to an unverified pick.

Each guess now makes two parallel ConceptNet calls (concept + relatedness)
instead of a single word2sim call. Slightly higher latency but zero hosting
cost and no dependency on the self-hosted word2sim instance.

- api-client.js rewritten; UpstreamError replaces Word2SimError (aliased
  for backwards compat with older imports).
- wordlist.js added (curated target pool + pickFromPool).
- handlers.js: drops RANDOM_FILTERS (no filtering needed; pool is curated).
- index.js: drops WORD2SIM_API_URL env var; ConceptNet base hardcoded.
- wrangler.toml + .dev.vars.example: drop WORD2SIM_API_URL.
- api-client tests rewritten for ConceptNet shape; total tests 336 → 341.
This commit is contained in:
2026-04-22 23:07:54 +07:00
parent 51d36272c7
commit fca6d733c9
8 changed files with 337 additions and 164 deletions
-4
View File
@@ -2,7 +2,3 @@
# Copy to .dev.vars (gitignored) and fill in real values.
TELEGRAM_BOT_TOKEN=
TELEGRAM_WEBHOOK_SECRET=
# Optional: override the word2sim base URL for local/self-hosted instances
# (semantle module). Default is https://word2sim.sg.miti99.com.
# WORD2SIM_API_URL=http://localhost:8000