Closed general

Public POST /api/parts-search: forward parts search to Component Ocean (adom-parts-search goes wiki-only)

Ray · ·closed by Colby Knox

What we need

adom-parts-search (app, CLI and skill) should call only wiki.adom.inc. Every distributor search goes user or AI → wiki → Component Ocean → Mouser / DigiKey / JLCPCB. CO is the only caller of the distributor APIs, and it owns caching, freshness, budgets, rate limits and outage fallbacks.

CO's side is live (component-ocean eceb2aa): POST /api/parts-search. The wiki needs a public route that forwards to it, the way the request box forwards to /api/part-request.

The wiki route

POST https://wiki.adom.inc/api/parts-search

Request body (JSON), forwarded to CO unchanged:

field type
q string, 2 to 80 chars a part number or keywords
limit 3, 5 or 10 per vendor, default 5
in_stock_only bool optional
jlcpcb_basic bool optional, JLCPCB Basic parts only
vendors array of mouser, digikey, jlcpcb optional, default all three

Forward to POST https://component-ocean-jk89eeqplwfl.adom.cloud/api/parts-search with the same headers the request box sends to /api/part-request:

  • X-Adom-Request-Key
  • X-Adom-User: the signed-in user; email:<hex> for a signed-out visitor who left an email; or anon with X-Adom-Anon-Ip for an anonymous visitor
  • X-Adom-Client: the caller's User-Agent, so the demand log can tell the app, the CLI and the wiki apart

Same rules as the request box: the same auth and the same anonymous handling. A rate cap should be a little looser than the request box's, since a search is cheaper than a build, but keep anonymous callers per IP.

Response: CO's JSON, passed through:

{
  "query": "LM358DR",
  "mouser":  {"ok": true, "count": 5, "components": [{"mpn": "...", "mouser_pn": "...", "stock": 0, "price_tiers": [], "image_url": "...", "product_url": "...", "...": "..."}],
              "fetched_at": "2026-11-04T17:20:00Z", "age_s": 0, "from_cache": false, "elapsed_ms": 900},
  "digikey": {"...": "same shape"},
  "jlcpcb":  {"...": "same shape"},
  "live_calls": 3,
  "exact": {"mpn": "LM358DR", "manufacturer": "Texas Instruments", "stock": 55449, "lcsc": "C5423"},
  "hits": 9,
  "demand": {"recorded": true, "miss": false, "page_url": "https://wiki.adom.inc/adom/lm358dr"}
}

components is each vendor service's own answer, the same shape adom-parts-search shows today, so its grid, photos and price breaks stay as they are. A vendor that fails comes back ok: false with error. If CO has an older answer, it serves that with from_cache: true and the error text instead.

What CO does behind it

  • Each vendor answer is cached for 6 h (Mouser, DigiKey) or 24 h (JLCPCB). A search makes at most one live call per vendor, and only when the cache is stale or missing. A repeat inside the window makes none: measured live, LM358DR took 3 calls in 1.3 s, then 0 calls in 0.1 s.
  • Live calls spend the distributor budget as the user; anonymous calls count against an app class.
  • Every query is logged. An exact part a distributor sells but the wiki has no page for counts toward the inferred build queue, the same as a search miss today. A part number no vendor sells is logged as a miss. GET /api/parts-search/demand?days=7 (CO, request key) lists the top queries, misses and live calls.

Two smaller gaps for the CLI and AIs

  1. POST /api/part-search-miss refuses anything but the wiki's own search page (PART_SEARCH_MISS_CROSS_SITE). Once /api/parts-search forwards, CO logs those misses itself, so this matters only for a wiki-page-only lookup. A token-authenticated path would still help.
  2. GET /api/pages/<ref>/stock serves its cache only, and that cache is empty on most pages, since it fills only when a person opens the stock widget. For a page, the parts-search answer above is the better stock source.

adom-parts-search will use /api/parts-search behind a flag until this ships, and nothing merges before it's live.

3 Replies

Colby Knox marked this in progress ·
Colby Knox ·

The wiki route is on staging (c5783be8), not on prod yet. POST /api/parts-search forwards to your route with the request key, X-Adom-User, X-Adom-Anon-Ip for anonymous callers and X-Adom-Client, and returns your JSON unchanged. Real LM358DR searches through staging came back signed in and signed out.

What differs from your spec:

  • Signed-out callers are always anon with their IP. I left out email:<hex>: a caller could send a new address each time and get past the anonymous budget. A body email is ignored.
  • Browsers on other sites get 403 PARTS_SEARCH_CROSS_SITE. The CLI and an app's server send neither header and pass. If any adom-parts-search page calls the wiki straight from the browser, tell me, because that call would be refused.
  • Limits: 60/min signed in; signed out 20/min and 200/hour per IP. The request box is 30 and 12. These count per server process, so the real ceiling is somewhat higher.
  • Timeout: the wiki waits 20 s for you.

I also added the token path from your first smaller gap: POST /api/part-search-miss now takes a token. I left page stock as it is, per your second one.

Two things in your answers for you to check:

  1. limit looks ignored on cached answers. "limit": 3 came back with Mouser count: 5 and DigiKey count: 8. The wiki does send limit.
  2. demand.page_url was missing on the signed-out search and present on the signed-in one, for the same part seconds apart.
Ray ·

Thanks for testing it. Both fixed in component-ocean 70efba3 (live):

  1. limit on cached answers. count is the vendor's total matches for the query, not the size of the answer, so limit 3 can still show Mouser 5 and DigiKey 8. components never went over the limit. To make that clear, each vendor answer now also carries returned: the components in this answer, never more than limit. A test checks count, returned and components for a limit-3 search, both live and from cache. LM358DR with limit 3 now reads Mouser 5/3/3, DigiKey 8/3/3, JLCPCB 3/3/3 (count/returned/components).
  2. demand.page_url missing when signed out. That was a real bug: the page lookup ran only for signed-in searches. It now runs for every caller. A signed-out and a signed-in LM358DR search both return https://wiki.adom.inc/adom/lm358dr. As before, only a signed-in (or email) searcher counts toward the build queue; an IP doesn't.

Noted on the differences: signed-out callers are always anon plus IP, cross-site browsers get 403, the limits are 60/min signed in and 20/min, 200/h per IP signed out, and the wiki waits 20 s. The app's page already calls its own local server, which calls the wiki, so the cross-site rule won't bite. Thanks for the token path on /api/part-search-miss too.

What's the staging host? I'll test adom-parts-search against your route there behind its flag, and nothing merges before it's on prod.

Colby Knox ·

It's live on prod (c5783be8), so you can skip staging and test adom-parts-search against POST https://wiki.adom.inc/api/parts-search. The full wiki test suite passed on this commit.

I checked your fix through the prod route: LM358DR with limit 3 reads Mouser 5/3/3, DigiKey 8/3/3, JLCPCB 3/3/3, and a signed-out search now has demand.page_url. My limit note was a misread of count, not a bug on your side.

Closing this. Reopen it if anything looks wrong when you test.

Colby Knox closed this ·

Log in to reply.