feat(search): add Jina.ai as web search provider#513
feat(search): add Jina.ai as web search provider#513leszek3737 wants to merge 5 commits intomoltis-org:mainfrom
Conversation
Add Jina.ai (s.jina.ai) as a third search provider alongside Brave and Perplexity. Uses the same shared api_key field — no extra config section needed. Supports JINA_API_KEY env var for key resolution.
Add tests for HTTP error paths, malformed JSON responses, env var resolution, cache key isolation, and api_key_candidates dispatch.
- Add country (gl) and search_lang (hl) query params for Jina provider - Update DuckDuckGo fallback error messages to mention JINA_API_KEY - Update doc comment on WebSearchTool to include Jina - Trim content field in parse_jina_results for consistency - Update configuration.md with Jina provider table and env vars - Update docker.md to mention Jina API key - Update config template api_key comment to include Jina - Add test for gl/hl param forwarding
Greptile SummaryThis PR adds Jina ( Key changes:
Issues found:
Confidence Score: 5/5Safe to merge; all remaining findings are P2 style or speculative correctness concerns. The implementation is well-structured and follows existing provider patterns closely. The crates/tools/src/web_search.rs — verify whether Important Files Changed
Sequence DiagramsequenceDiagram
participant LLM
participant WebSearchTool
participant Cache
participant JinaAPI as s.jina.ai
LLM->>WebSearchTool: execute({ query, count, country, search_lang })
WebSearchTool->>Cache: cache_get(provider:key_state:query:count)
alt Cache hit
Cache-->>WebSearchTool: cached result
else Cache miss
alt api_key present
WebSearchTool->>JinaAPI: GET /{encoded_query}?count=N&gl=..&hl=..
Note over WebSearchTool,JinaAPI: Authorization: Bearer {JINA_API_KEY}
alt HTTP 2xx
JinaAPI-->>WebSearchTool: { data: [ {title, url, content}, ... ] }
WebSearchTool->>WebSearchTool: parse_jina_results(body)
WebSearchTool-->>LLM: { provider:"jina", query, results }
else HTTP error
JinaAPI-->>WebSearchTool: error status + body
WebSearchTool-->>LLM: Err("Jina Search API returned {status}")
end
else api_key empty AND fallback_enabled
WebSearchTool->>WebSearchTool: search_duckduckgo(query, count)
WebSearchTool-->>LLM: DDG results
else api_key empty AND !fallback_enabled
WebSearchTool-->>LLM: { error: "not configured", hint: "Set JINA_API_KEY" }
end
WebSearchTool->>Cache: cache_set(key, result)
end
|
- Fix stale api_key doc comment in schema.rs to mention Jina - Add warn! log on Jina response deserialization failure - Add client-side .take(max_results) truncation in parse_jina_results since Jina SERP API does not document a count parameter - Add test for client-side truncation
Summary
jinaas a third web search provider alongsidebraveandperplexitys.jina.ai) acceptsgl(country) andhl(language) query params, mapped from the existingcountryandsearch_langtool parameters
JINA_API_KEYValidation
Completed
cargo test -p moltis-tools jina— 17 tests passcargo check -p moltis-tools— cleanbiome check --write— no JS changesconfiguration.md,docker.mdupdatedRemaining
just format(pinned nightly rustfmt)just lintjust test./scripts/local-validate.sh <PR_NUMBER>Manual QA
JINA_API_KEYand addprovider = "jina"to[tools.web.search]inmoltis.tomlcountry = "pl"/search_lang = "pl"in a search call — verifygl=pl&hl=plare forwardedJINA_API_KEYduckduckgo_fallback = trueand no key — verify DDG fallback works normally