Commit e7c818c
committed
feat(doctor): probe embedding endpoint with clear diagnostics (fixes #29)
The most common embedding-config mistakes (wrong URL shape, missing env
var, provider that doesn't implement embeddings) produced silent 401/404
failures at runtime with no hint about what was wrong. The dashboard
exposes a 'test connection' button backed by a Rust `reqwest` call, but
doctor didn't have anything equivalent and was the natural place to
surface these errors during setup.
Adds `probeEmbeddingEndpoint` in
`src/features/magic-context/memory/embedding-probe.ts` — a small Node/Bun
fetch-based probe that sends `{model, input}` to `${endpoint}/embeddings`
with a 10s timeout and classifies the outcome:
- `ok` — 2xx with `data[].embedding` array (reports dimensions)
- `auth_failed` — 401/403 with body preview
- `endpoint_unsupported` — 404/405, OR 2xx without embeddings payload
(catches routers that accept the URL but don't speak the spec)
- `http_error` — other non-2xx
- `timeout` — AbortSignal.timeout triggered
- `network_error` — fetch threw (DNS, connection refused, etc.)
- `invalid_scheme` — endpoint missing http(s):// before any request
Doctor gains a `checkEmbeddingConfig` step (run as 7b, between user-
memories and plugin-cache checks). It uses the same
`substituteConfigVariables` path the runtime uses, so the probe sees the
real resolved api_key/endpoint — not the literal `{env:...}` template.
If a `{env:VAR}` token survived substitution the doctor warns that the
env var is not set in the current shell.
For each probe outcome doctor emits a specific recommendation. The
`endpoint_unsupported` case lists known non-embedding providers (OpenRouter,
Anthropic) since those are the two most likely configurations from user
reports, and gives concrete working alternatives (OpenAI, Voyage, Together,
LM Studio, local).
Issue #29's exact config
(`endpoint: https://openrouter.ai/api/v1/chat/completions`,
`api_key: "{env:OPENROUTER_API_KEY}"`) produces three distinct failure
modes that are each handled:
1. `{env:` residue warning if OPENROUTER_API_KEY is not exported
2. 404/405 from `/chat/completions/embeddings` (wrong URL shape)
3. OpenRouter would still return an unsupported response even if the
URL were right — covered by `endpoint_unsupported`
Tests: 17 unit tests in `embedding-probe.test.ts` covering every outcome
kind, custom timeouts, AbortError and TimeoutError branches, trailing-
slash trimming, Bearer-auth header presence/absence/whitespace, and
preview truncation. 679 total tests pass.
CONFIGURATION.md: embedding example updated to show the
`{env:OPENAI_API_KEY}` pattern and calls out that doctor validates the
endpoint.
Closes #291 parent 1582549 commit e7c818c
4 files changed
Lines changed: 695 additions & 1 deletion
File tree
- packages/plugin/src
- cli
- features/magic-context/memory
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
333 | 333 | | |
334 | 334 | | |
335 | 335 | | |
336 | | - | |
| 336 | + | |
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
340 | 340 | | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
341 | 345 | | |
342 | 346 | | |
343 | 347 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
7 | 12 | | |
8 | 13 | | |
9 | 14 | | |
| |||
200 | 205 | | |
201 | 206 | | |
202 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
203 | 382 | | |
204 | 383 | | |
205 | 384 | | |
| |||
437 | 616 | | |
438 | 617 | | |
439 | 618 | | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
440 | 625 | | |
441 | 626 | | |
442 | 627 | | |
| |||
0 commit comments