[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-81554":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":14,"stars7d":16,"stars30d":16,"stars90d":15,"forks30d":15,"starsTrendScore":16,"compositeScore":17,"rankGlobal":9,"rankLanguage":9,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":21,"hasPages":19,"topics":22,"createdAt":9,"pushedAt":9,"updatedAt":23,"readmeContent":24,"aiSummary":25,"trendingCount":15,"starSnapshotCount":15,"syncStatus":26,"lastSyncTime":27,"discoverSource":28},81554,"pi-native-search","smalibary\u002Fpi-native-search","smalibary","Pi extension that adds web_search and web_fetch tools using each provider's native search backend (ZAI, Anthropic, Google, OpenAI, xAI, Claude Code subscription), with DuckDuckGo fallback.",null,"TypeScript",28,4,25,1,0,3,45.9,"MIT License",false,"main",true,[],"2026-06-12 04:01:34","# pi-native-search\n\n[![npm version](https:\u002F\u002Fimg.shields.io\u002Fnpm\u002Fv\u002Fpi-native-search)](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fpi-native-search)\n[![license](https:\u002F\u002Fimg.shields.io\u002Fnpm\u002Fl\u002Fpi-native-search)](LICENSE)\n\nA [pi](https:\u002F\u002Fgithub.com\u002Fbadlogic\u002Fpi-mono) extension that adds `web_search` and `web_fetch` tools, routing each call through the **active provider's own native search backend** when available, and falling back to DuckDuckGo HTML scraping otherwise.\n\nThe headline feature: when you're using your **Claude Code subscription via [pi-claude-bridge](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fpi-claude-bridge)**, search and fetch are delegated to Claude Code's actual `WebSearch` and `WebFetch` tools — the same ones you get in Zed, Claude Desktop, or the Claude Code CLI. No separate API key required.\n\n## Why\n\nPi ships with provider plumbing but no built-in search. Most extensions either (a) hard-code DuckDuckGo, or (b) require you to wire up your own paid search API. This extension uses what each provider already gives you for free.\n\n| Provider | Native backend | Auth source |\n|---|---|---|\n| **claude-bridge** (Claude Code subscription) | Claude Code's `WebSearch` \u002F `WebFetch` (via `@anthropic-ai\u002Fclaude-agent-sdk`) | Your `claude` CLI login |\n| **zai** (GLM) | ZAI MCP `web_search_prime` (included in Coding Plans, *not* the separate paid Web Search API) | `ZAI_API_KEY` |\n| **anthropic** | `web_search_20250305` server tool | `ANTHROPIC_API_KEY` |\n| **google** (Gemini) | `google_search` grounding tool | `GEMINI_API_KEY` |\n| **openai** | Responses API `web_search` tool | `OPENAI_API_KEY` |\n| **xai** (Grok) | Responses API `web_search` tool | `XAI_API_KEY` |\n| All other providers | DuckDuckGo HTML fallback | none |\n\n`web_fetch` uses the same routing — currently only `claude-bridge` has a native backend; everything else uses a built-in HTTP fetcher.\n\n## Install\n\n```bash\npi install npm:pi-native-search\n```\n\nThe extension auto-detects your active provider via pi's `ctx.model.provider` and picks the right backend on every call.\n\n## Usage\n\nOnce installed, two tools become available to the model:\n\n- `web_search { query }` — searches the web and returns ranked results.\n- `web_fetch { url }` — fetches and returns a page's text content (truncated to 50 KB \u002F 2000 lines).\n\nThe model decides when to use them; you don't need to do anything else. To configure or inspect the extension, use the `\u002Fsearch` slash command:\n\n```\n\u002Fsearch           # open the settings panel (configured providers only)\n\u002Fsearch providers # show ALL providers and their capabilities\n\u002Fsearch config    # print current config (active provider, native vs. ddg, etc.)\n\u002Fsearch on        # enable both tools\n\u002Fsearch off       # disable the extension entirely\n```\n\nThe bottom status bar shows the active backend per call, e.g.:\n\n```\nsearch[search:native:cc-sdk,fetch:cc-sdk]    # claude-bridge route\nsearch[search:native:mcp,fetch]               # ZAI route\nsearch[search:ddg,fetch]                      # DDG fallback\n```\n\nConfiguration persists in `~\u002F.pi\u002Fagent\u002Fsearch-config.json`.\n\n## How it works\n\nThe dispatcher in `doSearch` (and the `web_fetch` handler) reads the active provider from the extension context and selects a backend:\n\n```ts\nasync function doSearch(query, provider, model, baseUrl, signal) {\n  const cap = PROVIDERS[provider];\n  if (cap?.nativeSearch && hasAuth) {\n    switch (provider) {\n      case \"zai\":           return zaiSearch(query, apiKey, signal);\n      case \"google\":        return googleSearch(query, model, apiKey, signal);\n      case \"openai\":        return openaiSearch(query, model, apiKey, signal);\n      case \"xai\":           return xaiSearch(query, model, apiKey, signal);\n      case \"anthropic\":     return anthropicSearch(query, model, apiKey, baseUrl, signal);\n      case \"claude-bridge\": return claudeBridgeSearch(query, signal);\n    }\n  }\n  return ddgSearch(query, signal); \u002F\u002F fallback\n}\n```\n\nIf the native call throws, the result is silently swapped for the DDG fallback with a `> Native failed (...)` prefix so you can see what went wrong without losing the search result.\n\n### claude-bridge specifics\n\nWhen the active provider is `claude-bridge`, the extension dynamically locates `@anthropic-ai\u002Fclaude-agent-sdk` (shipped inside `pi-claude-bridge`'s own `node_modules`) and spawns a one-shot `query()` with `allowedTools: [\"WebSearch\"]` (or `[\"WebFetch\"]`). The result text is captured and returned as the tool output. This means:\n\n- No extra dependency to install — reuses what `pi-claude-bridge` already brought in.\n- Auth comes from your `claude` CLI login, not an API key.\n- It uses your subscription, not API credits.\n\n## Adding a new provider\n\nThe extension is structured so that adding a backend is a self-contained change. To add provider `foo`:\n\n**1. Add an entry to the `PROVIDERS` map** at the top of `extensions\u002Findex.ts`:\n\n```ts\nfoo: {\n  name: \"Foo Provider\",\n  nativeSearch: true,\n  nativeFetch: false,\n  envKey: \"FOO_API_KEY\",\n},\n```\n\n**2. Implement the search function**:\n\n```ts\nasync function fooSearch(\n  query: string,\n  model: string,\n  apiKey: string,\n  signal?: AbortSignal,\n): Promise\u003Cstring> {\n  const res = await fetch(\"https:\u002F\u002Fapi.foo.com\u002Fsearch\", {\n    method: \"POST\",\n    signal,\n    headers: {\n      \"Content-Type\": \"application\u002Fjson\",\n      Authorization: `Bearer ${apiKey}`,\n    },\n    body: JSON.stringify({ query, model }),\n  });\n  if (!res.ok)\n    throw new Error(`Foo ${res.status}: ${(await res.text()).slice(0, 200)}`);\n  const data = (await res.json()) as any;\n  \u002F\u002F Format as numbered list with title, url, snippet\n  return data.results\n    .map(\n      (r: any, i: number) =>\n        `${i + 1}. **${r.title}**\\n   ${r.url}\\n   ${r.snippet}`,\n    )\n    .join(\"\\n\\n\");\n}\n```\n\n**3. Add a case to `doSearch`**:\n\n```ts\ncase \"foo\":\n  return { text: await fooSearch(query, model, apiKey, signal) };\n```\n\nThat's it. The settings UI, status line, and fallback handling all pick it up automatically from the `PROVIDERS` map.\n\nIf the provider doesn't use a standard `Bearer` API key (e.g. OAuth, MCP session, or an SDK that handles auth itself like `claude-bridge`), see `claudeBridgeSearch` for how to special-case the auth check in `hasCredentials` and the `hasAuth` gate in `doSearch`.\n\n## Development\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fsmalibary\u002Fpi-native-search.git\ncd pi-native-search\n# Edit extensions\u002Findex.ts, then test by symlinking into pi:\ncp extensions\u002Findex.ts ~\u002F.pi\u002Fagent\u002Fextensions\u002Fpi-native-search\u002Findex.ts\n# In pi: \u002Freload\n```\n\nThe extension is a single TypeScript file (`extensions\u002Findex.ts`) that pi loads via `tsx` at runtime — no build step required.\n\n## License\n\nMIT — see [LICENSE](LICENSE). PRs welcome, especially for new provider backends.\n\n## Acknowledgements\n\n- [pi](https:\u002F\u002Fgithub.com\u002Fbadlogic\u002Fpi-mono) by Mario Zechner — the host TUI agent\n- [pi-claude-bridge](https:\u002F\u002Fgithub.com\u002Felidickinson\u002Fpi-claude-bridge) by Eli Dickinson — provides the Claude Agent SDK that `claude-bridge` mode reuses\n","pi-native-search 是一个为 pi 框架扩展的工具，主要增加了 web_search 和 web_fetch 功能，通过使用各个提供商（如 Claude Code、ZAI、Anthropic 等）自带的搜索后端来执行网络查询和页面抓取任务，并在必要时回退到 DuckDuckGo 作为备用方案。该扩展利用了用户已有的服务订阅或 API 密钥，无需额外配置即可实现与各平台原生搜索能力的无缝集成。特别适合需要频繁进行网络信息检索及内容获取的应用场景，如开发辅助、研究分析等，能够显著提升工作效率并减少对外部服务的依赖。",2,"2026-06-11 04:05:28","CREATED_QUERY"]