1ccacad63281094de8a3372d5a507d38f9969e5c
12
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
ece12b370d |
search: TinyFish is a built-in search API (Niapyaya on X)
Niapyaya asked on X for TinyFish (tinyfish.ai) among the search APIs. TinyFish has a plain Search API beside its browser agents, so it is added as vendor "tinyfish", following Yuanbao Search ( |
||
|
|
c8eb7b3877 |
search: a search API's keys are a list, each switched off, moved and removed on its own
Web search took one key per API in one field (辰林鸭~ on Discord: only one
Tavily key). Settings › Models › Web search now lists an API's keys under
it as a provider's accounts are: each masked on its own row with a tick
(off / on), Show, Copy and Remove; several pasted at once (commas,
semicolons, lines), the reply saying how many were new and how many it
had; the order changed by dragging or Alt+↑/↓. A resting key says why and
until when on its row ("asked last until 14:05: rate limited"), from the
gateway's rest (SearchKeyRest, SearchQuota.Ref); rotation on 401/403,
402/432/433 and 429 (#1477) is unchanged.
provider.SearchAPI keeps Key as the keys on, comma-joined, so the gateway
and an older magpie never ask one switched off; keyList is written only
while a key is off. A Key that differs from the list (an older magpie, a
sync) wins, its keys on in its order, the list's off keys after. The last
key on can't be switched off or removed. The GUI names a key by
SearchKeyRef (a hash): POST /api/settings/search-keys (add, ref+on,
ref+remove, arrange) and /api/settings/search-key with ref. Saving an API
with no key keeps its keys, off ones too. Backup and WebDAV sync carry
the off keys, or leave them out with the rest. `magpie search` says
"+N off". docs/subsystems/gateway-routing.md has "The keys as a list".
Run (mote, at this tree, base
|
||
|
|
30a0bfe889 |
gateway, provider, cli: search APIs marked mix are asked together, their pages merged (#2845)
A search asked the search APIs in order and gave the model the first one's pages. On #2845's 80-query benchmark no single API was best on both sets. The deduplicated union of two or three APIs' pages scored higher than the best single API and lost no query (60-query set: 108 to 114-117 of 120, sign test p <= 0.03). Off by default. When two or more search APIs are marked mix (SearchAPI.Mix), they are asked first, at once (askSearchAPIsTogether). Each uses its own keys and timeouts, as when it is asked alone (askSearchAPIKeys). Their pages go to the model in turn: each API's first page in the saved order, then each one's second. A page an earlier API already gave is left out by its address (pageKey). One that fails or finds nothing leaves the others' pages. When none finds anything, the APIs not mixed are asked in order. With fewer than two mixed APIs on and ready, a search runs in order as before. No text says which API found a page, so what a vendor sees reads as before. MixSearchAPIs marks the vendors named (two or more, set up, each once) and clears the rest; none clears all. SetSearchAPI keeps the mark, as it keeps off, since Settings sends an edit without it. Backup copies the whole entry, so the mark carries over. CLI: magpie search mix <api>,<api>, magpie search mix off, and magpie search lists a mixed one as mix. docs/subsystems/gateway-routing.md has a section on it. Ported from mdwsk88's 2966cce77 and reviewed line by line. What changed from it: - The cap follows the search's count (#5545, the commit before this): searchMixMost is 2 x the count a search asks for, at most 20 (searchHitsMost). The default stays 12 pages, as in the patch. TestSearchAPIsMixedCapped is a table over count settings and named counts. - The CLI keeps both search count and search mix. - No Settings toggle. The mode stays CLI-only, by the UI-restraint rule; the docs say so. Run (mote-run): - go test -count=1 -run "Search|Mix" ./internal/gateway/: ok; -race -run "TestSearchAPIsMixed|TestMixSearchAPIs": ok. - go test ./internal/provider/ ./internal/backup/: ok; ./internal/cli/ -run "TestSearchCLI|TestEveryRoute": ok. Broken by hand: with apiSearch's mixed branch turned off, TestSearchAPIsMixedAskedTogether fails (only the first API's pages) and TestSearchAPIsMixedCapped fails ("count set 0, named 0: 6 pages, want 12"). Restored, both pass. Not tried: a real search with two vendors' live keys. The tests use fake search APIs. Co-authored-by: mdwsk88 <11055210+mdwsk88@users.noreply.github.com> Reported-by: mdwsk88 (dawei on Discord) |
||
|
|
4e0e8e7933 |
gateway, settings, gui, cli: the results a search is answered with can be set, 1 to 20 (#5545)
Claude Code's WebSearch and Codex's web_search never name a count, so magpie answered every such search with searchHits, 6 pages (#5545, mdwsk88: more pages for research-heavy work, fewer to save context). settings.SearchCount holds the count. 0 means the default, 6 (SearchCountDefault), and the most is 20 (SearchCountMost), the most Brave and Tavily return. Save refuses a value out of range, so nothing is written. Settings.SearchPages reads it. The gateway's searchCount falls back to it when a search names no count. The web_search MCP tool still answers a named count with that count, and its schema's default says the count set. It reaches every search API (Brave, Tavily, Exa, You, the plugins' searchers), as a named count already did. - Settings › Models › Web search: "Results per search", segments 3, 6, 10, 15 and 20, plus a count set by hand in settings.json. POST /api/settings/search-count sets it alone. settingsapi.Apply keeps it as it keeps search-all, so a save of the Settings form doesn't put it back. - CLI: magpie search count says the count; magpie search count <n> sets it; magpie search count default puts 6 back. A bad value is refused and nothing is written. - docs/subsystems/gateway-routing.md says it. - New strings are in zh, zh-TW, ja and de. Run at this tree (mote-run, macOS): - go test -count=1: internal/settings, settingsapi, cli, gateway (TestSearchMCPCount, TestSearchCountReachesEveryAPI, TestSearchCountSetting), and gui (TestSettingsSearchCountSetOnItsOwn, and TestSettingsSaveKeepsWhatItDoesNotSend with SearchCount set): ok. internal/gateway whole: ok with -timeout 45m (847s). internal/gui whole: ok but TestMainWindowCorners/macOS_26_SDK (#3949, mote is on macOS 27). The first cli run was red on TestEveryRouteHasACommandOrIsNamed: the new route had no CLI entry. cliForRoute maps it to search count now. - Broken by hand: searchCount returning searchHits again makes TestSearchCountSetting fail ("set 11: a search naming no count asks for 6, want 11"). Restored, it passes. - GUI: node --test --test-concurrency=4 over routing-*, usage-*, ledger-*, panel-*, call-*, search-*, searcher-*, settings-*, i18n-* and gui-* (Chromium and WebKit; the files cover en, zh, zh-TW, ja and de), with #2398 and #5545 in one tree: 4961 of 5016 ok. The 55 reds are in 12 files. i18n-keys' "a plugin's words are its own" names other files' strings (#5327, #5426, #5482). The other 11 files were run alone at dc49feca9 (this tree without either change) and at this tree: 52 and 51 reds, the same tests. The one apart is usage-focus-steady, which flakes (#3501). Each is filed: #5392, #3414, #5048, #3799, #3415, #3954, #4627, #4628, #5223, #1529. routing-canceled-row.test.cjs: 10 of 10. With the .rt-req.gone rule taken out, its dot is the answered green rgb(24, 154, 88) and it fails. Restored, it passes. - Not tried: a real Claude Code WebSearch through this tree with a live search API key. The tests use fake search APIs. Co-authored-by: mdwsk88 <11055210+mdwsk88@users.noreply.github.com> Reported-by: mdwsk88 (dawei on Discord) |
||
|
|
90bf96a23d |
search: a plugin can give a web search API (its search hook)
treeman on Discord #help asked for web search to be pluggable so users can
add search vendors. A plugin's `search` hook, {search: {<id>: {name, keysURL?,
keyOptional?, url?, execute({query, count, key, url}, ctx)}}}, adds an API to
Settings > Models > Web search as `<plugin>:<id>`. It is added, keyed, ordered,
switched off and removed like Tavily or Brave. The built-in APIs stay built in.
How: host.js collects the hook's entries (id [a-z0-9-], an execute) into
Loaded.Searches and runs one with the `search` op (timeout from ctx, an error
with a numeric status comes back as a refusal). The host notes them in
plugin-searches.json (internal/plugin/search.go); provider.AllSearchVendors
adds the noted ones of plugins that are on to SearchVendors, so Ready, check,
the CLI and the GUI list see them. askSearchAPI hands a plugin vendor to
askPluginSearch below askSearchAPIKeys, so keys, rest on 401/402/403/429,
order, the masked query and the request-log row are the built-ins' own.
Run (mote, on this tree, whose base
|
||
|
|
0804f2d97d |
search: Tencent Cloud's Yuanbao Search (wsa) is a built-in search API (plugins#509)
chenjiangzi asked for Tencent Cloud's WSA SearchPro (元宝搜索). It is added
as vendor "wsa", following Doubao Search (
|
||
|
|
acbd6b11ab |
search: a search API's URL given with the path magpie adds is its base, never …/search/search (plugins#509)
chenjiangzi set Tavily's url to https://api.tavily.com/search, and magpie appended /search again. Each vendor now names the paths magpie puts after its base (SearchVendor.Paths). A url that already ends in one of them, with or without a trailing slash and in any case, is cut back to its base. This happens when it is saved (SetSearchAPI) and again when it is read (SearchAPI.Base), so an entry saved before this change works too, and so does Tavily's quota URL built on the same base. Every vendor is covered: tavily, brave, exa, firecrawl, you (both paths), deepseek, volcengine, searxng, and wsa in the next commit. A path of the user's own (/my-search) is left alone. The url= help and gateway-routing.md say so. Run on mote (mote-run), at the rebased head: - go test -run 'SearchAPI|WSASearch|Volcengine|Search' ./internal/gateway/ ./internal/gui/ ./internal/provider/ ./internal/cli/: ok - go vet -tags nogui for darwin, GOOS=linux and GOOS=windows on provider, gateway, cli (and gui on darwin): ok; gofmt -l clean - GUI (no GUI file changes; the picker reads SearchVendors): search-api.test.cjs in Chromium 4/4 ok. Its WebKit cases and searcher-pick timed out at browserType.launch (180s) on mote, where ~57 WebKit pw_run launches from several sessions hang. Not a result about this change; WebKit not run. Broken by hand: ownBase returning the URL unchanged made TestSearchAPIBaseURLWithItsPath red ("asked /relay/tavily/search/search, want /relay/tavily/search"). Not tried: a real Tavily request; the full go test ./... (to follow). |
||
|
|
dca3e2d716 |
search: Doubao Search (Volcengine) as a search API (CyberCaius on Discord)
CyberCaius asked on Discord #help (10-30) for Volcengine's Doubao search under Settings › Models › Search APIs, or a custom API address. Volcengine's Doubao Search Custom (豆包搜索 Custom版, once 联网搜索 / 融合信息搜索, docs.volcengine.com/docs/networked-search/networked-search, the same page as volcengine.com/docs/87772/2272953) can now be added with its API key: - provider.SearchVendors: volcengine, "Doubao Search (Volcengine)", at https://open.feedcoopapi.com, keys at console.volcengine.com/search-infinity/api-key, after DeepSeek. The GUI takes its vendors from SearchVendors, so it shows in the Search API picker with its Get a key link and base URL field; no GUI file changes. - askSearchAPI: POST /search_api/web_search, Bearer key (the default, as the docs and volcengine/mcp-server's askecho_search_infinity send it), body {Query, SearchType: "web", Count: searchHits, Filter: {NeedUrl: true}}. The query is cut to the 100 characters the docs allow. NeedUrl leaves out its 火山如意 cards, which have no URL to cite. - readVolcSearch reads Result.WebResults: Summary as the page's text (the docs recommend it for models; Content is the whole page, Snippet ~200 chars "only for list display"), Snippet when there is no Summary, PublishTime as the page's age, a 1970-01-01 time (its image example's stand-in) as none, and a result with no Url left out. - volcSearchError: its errors are in ResponseMetadata.Error, a code the docs list, and the docs don't say the HTTP status, so the code decides: 10401/10403/10409 rest the key as turned away (403), 10406/10408/ 10410/10412 (free searches spent with none paid, no plan, plan spent) as out of credit (402), 700429 as rate limited (429). Any other code is a plain error, a 200 carrying one included. The key is masked in the error as for every vendor. - A custom address: every search API already takes a base URL (#1580, the field under the key in Settings, url= in the CLI), so an endpoint that answers as Tavily, SearXNG, Brave, Exa, Firecrawl, You.com, DeepSeek or now Doubao Search does can be set there. There is no common format across the vendors (each has its own path, body and reply), so no separate "custom" vendor was added. - Siblings: CLI usage (main.go, search_cli.go's api list and empty-state hint), README.md, README.zh-CN.md, gateway-routing.md's path list and refusal paragraph. The test's reply is the docs' own web-search response example, byte for byte (testdata/volcengine_web_search.json); its error replies are the docs' error example with its "// 该字段为错误码" note taken out (not JSON). Not tried against the real API: no Volcengine search key in this run. Run (worktree on origin/main |
||
|
|
d432920f02 |
search: DeepSeek's Search API as a search API vendor (TJHHHH on Discord)
DeepSeek's own Search API (api-docs.deepseek.com/guides/search) can now be added as a search API, with a DeepSeek API key: - provider.SearchVendors: deepseek, at https://api.deepseek.com, keys at platform.deepseek.com/api_keys, offered after You.com. - askSearchAPI: POST /v1/tools/search, Bearer key (the default), body {query, count: searchHits}. The query is cut to the 128 characters the docs allow (a longer one is a 400); need_content stays false. - readSearchAPI reads its summary (the docs' text "for a model", ~600-800 chars) as the page's text, since content is empty without need_content; its snippet stands in when there is no summary, and its date (RFC 3339 or null) is the page's age. Other vendors' fields are read as before; summary and snippet are only fallbacks after content. - 402 (no balance) and 429 (5 QPS per account) already rest a key as out of credit and rate limited (searchRestFor); the test pins it for deepseek. - Siblings: CLI usage (main.go, search_cli.go's api list and empty-state hint), README.md, README.zh-CN.md, gateway-routing.md's path list. The GUI takes its vendors from SearchVendors (no vendor list in app.js or i18n), so no GUI file changes. Not tried against the real DeepSeek API (no key in this run); the fake is built from the docs' response shape, with null site_name/date and empty summary/content. Note DeepSeek bills direct API calls ($0.75 per 1,000 non-empty searches). Run (worktree on origin/main |
||
|
|
ec13d1162a |
search: the search APIs are dragged into the order they are asked in, and each switches off without losing its key (#2286, blackrion)
The search APIs were asked in the order they were added, and the only way to keep one out of the chain (to try another alone, or rest one whose credit is nearly spent) was to remove it and paste its key again later. - provider: SearchAPI.Off; SearchAPIs() leaves an API switched off out, so neither a model's search nor the web_search MCP asks it. SwitchSearchAPI keeps key, URL and place; SetSearchAPI keeps Off. ArrangeSearchAPIs puts them in the vendors' order, refuses an unknown or twice-named vendor, and keeps one not named after them. RestoreSearchAPIs now puts a backup's APIs in the backup's order (one only here after them), so a restored order and Off come back as they were; sync already mirrors the list. - GUI: each API's row and its keys' row are one unit, dragged off its buttons with dragRows (as routing's groups, #779) or moved with Alt+↑/↓, renumbered at once, focus kept, redrawn as saved if the order is refused. A lib-switch per row posts {vendor, on}; one off is dimmed and says Off; Search first with counts only APIs that are on. The row's buttons wrap instead of running past a 420px window. - CLI: magpie search off|on <api>, move <api> <n>; the list says off. - POST /api/settings/search-api takes {arrange} and {vendor, on}. - Docs: gateway-routing "The search APIs' order, and one switched off", gui-shell, README (en, zh-CN). Run: go test -tags nogui ./internal/provider ./internal/cli ./internal/gui ./internal/gateway (TestSearch*) ./internal/backup ./internal/davsync; GOOS=linux/windows go vet of the touched packages; gofmt -l clean. GUI: search-order.test.cjs 16/16 (chromium + webkit, en/zh/ja/de, 1100/420), and search-api, search-first, search-instead, search-keys, search-mcp, searcher-pick, i18n-keys, gui-ja, gui-de, gui-zh-tw 100/100. Broken by hand: SearchAPIs without the Off filter turns TestSearchAPIOrderAndOff and TestSearchCLIOffAndMove red; the GUI counting off APIs for Search first turns search-order red. Full suite: SUITE_LINE |
||
|
|
a5d72a095b |
gateway, gui, cli: a search API's keys take turns, a refused one rests, and each Tavily key shows what it has used (SlouchyQuill)
SlouchyQuill on Discord asked for a Tavily key pool after dsh-tavily-pool: several keys, each key's quota shown, keys rotated. Before this, the comma-separated keys (#1477) always started from the key that last answered, so one key took every search until it was refused, a refused key kept no rest of its own, and nothing showed what a key had left. What changed: - Turns (internal/gateway/search_keys.go). Searches take turns over the keys by default (round robin, a counter per vendor). pick=order (CLI) or In order (Settings) always starts from the first key; the pick is saved in SearchAPI.Pick. - Rests. A refused key rests: 401/403 for 10m ("turned away"), 402 for 1h ("out of credit"), 429 for its Retry-After held to 30s-10m (1m without one). 432/433 count as out of credit from Tavily only; from any other vendor they rest as a rate limit. A resting key is asked after the others, soonest back first, so failover is kept, and it wakes when it answers. Rests are keyed by a hash of the key. - Quota (internal/gateway/search_quota.go). Each Tavily key's quota is read from GET /usage with that key. The fixture is the documented reply from docs.tavily.com. The key's own limit is used when it has one; otherwise its plan's plan_limit/plan_usage, which the account's keys share. A failed read, or a reply missing those fields, says unknown and why, never 0. A read is kept 2m unless asked fresh. A key found used up with no pay-as-you-go credit rests 1h; a later read with credit wakes it. - Keys never appear in full. The vendor's error has the key masked (tvly-…abcd), and errors name "key N (tvly-…abcd)". - GUI. Settings › Models › Web search adds a "Keys of <API>" row under an API with several keys or with Tavily's: In turn / In order, each key masked with what it has used and why it is asked last, and Check again. There is an API for it (POST /api/settings/search-quota), and 13 strings in zh, zh-TW, ja and de. - CLI. `magpie search` lists the pick and each Tavily key's quota, read fresh; `magpie search add … pick=turns|order`. - Docs. gateway-routing.md has a new section "A search API's keys"; both READMEs have a line on web search. What was run: - go test -tags nogui ./internal/gateway ./internal/provider ./internal/cli ./internal/gui: ok. After the last rebase, provider and cli again, and gateway -race -run Search. - New tests: TestReadTavilyUsage, TestSearchKeysTakeTurnsRoundRobin, TestSearchKeyRefusedRests, TestSearchRestFor, TestSearchQuotas and TestSearchKeyNeverInFull. Each guarantee was broken by hand and its tests went red: - turns pinned to the first key: RoundRobin and RefusedRests; - rests ignored: TestSearchAPIKeysTakeTurns, RefusedRests and TestSearchQuotas; - key masking removed: NeverInFull; - a failed read reported as known: TestSearchQuotas. - gofmt -l; go vet -tags nogui for darwin, linux and windows on the four packages. - GUI: search-keys.test.cjs covers en, zh, zh-TW, ja and de × Chromium and WebKit × 1100 and 420px: 20/20. Without the new .search-keys .val wrap rule, de at 420px fails ("Erneut prüfen" went past the window's edge). - search-api, search-first, search-instead, search-mcp, searcher-pick, settings-search, provider-search, gui-de, gui-ja and i18n-keys: 56/56 in each engine. - Full suite in Chromium (concurrency 6, load ~40): 4498/4504. The files that failed (gateway-key-groups, rest-try-now, routing-wb-restricted, text-size, usage-sum-whole) were rerun alone. All pass except usage-sum-whole, which fails now and then on an origin/main worktree too under the same load (#1864, #2023; rest-try-now and routing-wb-restricted are #1905). None of them touch search. - Real Tavily API with two invalid keys: /search returns 401 {"detail":{"error":"Unauthorized: missing or invalid API key."}}, which counts as a refusal. Both keys rest 10m as turned away, the error names them only masked, and both quotas read "unknown · 401". Checked through a test and through the nogui CLI binary in a sandbox HOME. Not tried: a valid key's /usage against the real API. No Tavily key was at hand, so the quota parsing is checked against the documented bytes only. |
||
|
|
23e764d0e0 |
cli: magpie's commands move from the root into internal/cli; the root keeps only main.go
The root held 89 .go files (30 commands, 59 tests). They move as they are to internal/cli (package cli), with git mv so history follows them. The only code change is main() becoming cli.Main(version): the root's new main.go keeps `var version` in package main, so -ldflags "-X main.version=…" in the Makefile, the Dockerfile and magpie-releases, and every workflow, work unchanged. go-winres's rsrc_windows_*.syso still land next to package main in the root. Tests that read testdata by a root-relative path now go up one level (../plugin/testdata/fake, ../sessions/testdata). Five subsystem doc links point at internal/cli/. Run: - go build ./..., gofmt -l, go vet on darwin, linux and windows (nogui) - builds with tags production, dev, "production nogui"; windows -H windowsgui; linux CGO_ENABLED=0 - make release-cli TARGETS="darwin/arm64 linux/amd64 windows/amd64 android/arm64" VERSION=9.9.9-tidy: all four built, binary prints "magpie 9.9.9-tidy" - docker build --build-arg VERSION=7.7.7-tidy: container prints "magpie 7.7.7-tidy" - go test ./internal/cli (default and nogui): 152 tests, the same count as the root on main - go test ./...: all packages pass (agent, gateway, library, provider timed out at 10m under other sessions' load and passed rerun alone with -timeout 40m; none of them changed) - the built binary in a sandbox HOME: version, help, ls, providers, claude, and an unknown command's error |