@juicesharp/rpiv-web-tools 2.13.6 → 2.13.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/providers.md +4 -1
- package/docs/tools.md +14 -9
- package/package.json +2 -2
- package/web-tools.ts +50 -20
package/docs/providers.md
CHANGED
|
@@ -41,7 +41,10 @@ Four tiers, first match wins:
|
|
|
41
41
|
4. **`brave`**, the built-in default.
|
|
42
42
|
|
|
43
43
|
`/web-tools --show` prints the resolved name together with its source
|
|
44
|
-
(`env`, `config`, or `default`), so you can see which tier won.
|
|
44
|
+
(`env`, `config`, or `default`), so you can see which tier won. The model-facing
|
|
45
|
+
`web_search` schema uses the same resolution and labels this provider as the
|
|
46
|
+
default; it exposes only providers configured with a key or explicit base URL,
|
|
47
|
+
plus the active provider.
|
|
45
48
|
|
|
46
49
|
An unknown name at tier 1 or tier 2 throws:
|
|
47
50
|
|
package/docs/tools.md
CHANGED
|
@@ -14,9 +14,8 @@ search provider's API and returns titled results with URLs and snippets.
|
|
|
14
14
|
web_search({
|
|
15
15
|
query: string, // required — natural-language query
|
|
16
16
|
max_results?: number, // 1-10, default 5
|
|
17
|
-
provider?: //
|
|
18
|
-
| "
|
|
19
|
-
| "firecrawl" | "perplexity" | "searxng" | "ollama",
|
|
17
|
+
provider?: // configured providers only; see below
|
|
18
|
+
| "<configured-provider>",
|
|
20
19
|
})
|
|
21
20
|
```
|
|
22
21
|
|
|
@@ -53,12 +52,18 @@ When the provider returns zero results, the envelope collapses to
|
|
|
53
52
|
|
|
54
53
|
### Per-call `provider` override
|
|
55
54
|
|
|
56
|
-
The optional `provider` parameter routes a single call to a different
|
|
57
|
-
without mutating persisted config and without a session restart.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
The optional `provider` parameter routes a single call to a different configured
|
|
56
|
+
backend without mutating persisted config and without a session restart. At tool
|
|
57
|
+
registration, the schema exposes only providers with a resolved API key or
|
|
58
|
+
explicit base URL, plus the active provider. The provider description identifies
|
|
59
|
+
the default provider and its source (`env`, `config`, or `default`). Saving in
|
|
60
|
+
`/web-tools` re-registers the tool, so the list follows the new configuration
|
|
61
|
+
without a restart; environment-variable changes take effect on the next start.
|
|
62
|
+
|
|
63
|
+
The named provider must have its own credentials — the override does **not**
|
|
64
|
+
inherit the active provider's key, and an unconfigured target throws the usual
|
|
65
|
+
`… is not set` error rather than silently falling back, so the caller can detect
|
|
66
|
+
the misconfiguration.
|
|
62
67
|
|
|
63
68
|
An override also short-circuits the `WEB_SEARCH_PROVIDER` environment variable
|
|
64
69
|
entirely: that tier is neither read nor validated when an override is present,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-web-tools",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.8",
|
|
4
4
|
"description": "Pi extension. Web search and fetch for the model with pluggable providers (Brave, Tavily, Serper, Exa, You.com, Jina, Firecrawl, Perplexity, SearXNG, Ollama).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
]
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@juicesharp/rpiv-config": "^2.13.
|
|
68
|
+
"@juicesharp/rpiv-config": "^2.13.8"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"@earendil-works/pi-coding-agent": "*",
|
package/web-tools.ts
CHANGED
|
@@ -128,11 +128,42 @@ function resolveProviderBaseUrl(meta: ProviderMeta, config: WebToolsConfig): str
|
|
|
128
128
|
return meta.defaultBaseUrl ?? "";
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
// Known provider names — derived once from PROVIDERS so
|
|
132
|
-
//
|
|
133
|
-
// when a provider is added or removed.
|
|
131
|
+
// Known provider names — derived once from PROVIDERS so validation and error
|
|
132
|
+
// messages stay in sync when a provider is added or removed.
|
|
134
133
|
const KNOWN_PROVIDER_NAMES = PROVIDERS.map((p) => p.name) as readonly string[];
|
|
135
134
|
|
|
135
|
+
// "Configured" = usable without further setup: a hosted provider with a
|
|
136
|
+
// resolved API key, or a self-hosted one with an explicit base URL (env or
|
|
137
|
+
// config). The bare default URL doesn't count — it's just a hint that the user
|
|
138
|
+
// hasn't touched the setting yet. Shared by the /web-tools picker markers and
|
|
139
|
+
// the model-visible `web_search` provider enum.
|
|
140
|
+
function isProviderConfigured(meta: ProviderMeta, config: WebToolsConfig): boolean {
|
|
141
|
+
if (meta.baseUrlEnvVar) {
|
|
142
|
+
return Boolean(process.env[meta.baseUrlEnvVar]?.trim() || config.baseUrls?.[meta.name]?.trim());
|
|
143
|
+
}
|
|
144
|
+
return resolveProviderApiKey(meta.name, config) !== undefined;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function getVisibleProviderNames(config: WebToolsConfig): {
|
|
148
|
+
active: { name: string; source: "env" | "config" | "default" };
|
|
149
|
+
names: string[];
|
|
150
|
+
} {
|
|
151
|
+
const active = resolveActiveProviderName(config);
|
|
152
|
+
const configured = PROVIDERS.filter((meta) => isProviderConfigured(meta, config)).map((meta) => meta.name);
|
|
153
|
+
const names = configured.filter((name) => name !== active.name);
|
|
154
|
+
if (KNOWN_PROVIDER_NAMES.includes(active.name)) names.unshift(active.name);
|
|
155
|
+
if (names.length === 0) names.push(DEFAULT_PROVIDER_NAME);
|
|
156
|
+
return { active, names };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function providerSelectionDescription(names: readonly string[], active: { name: string; source: string }): string {
|
|
160
|
+
return (
|
|
161
|
+
"Search provider to use for this call only, overriding the active provider set via /web-tools. " +
|
|
162
|
+
`Configured providers: ${names.join(", ")}. Default provider: ${active.name} (source: ${active.source}). ` +
|
|
163
|
+
"Omit to use the configured active provider. The named provider must have its API key/URL configured or the call throws."
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
136
167
|
// Uniform "unknown provider" error for both the per-call override path and the
|
|
137
168
|
// WEB_SEARCH_PROVIDER env path so misconfiguration surfaces the same shape.
|
|
138
169
|
function assertKnownProvider(name: string): void {
|
|
@@ -307,7 +338,9 @@ function buildEmptyResultsEnvelope(query: string, providerName: string) {
|
|
|
307
338
|
// ---------------------------------------------------------------------------
|
|
308
339
|
|
|
309
340
|
export function registerWebSearchTool(pi: ExtensionAPI): void {
|
|
310
|
-
const
|
|
341
|
+
const config = loadConfig();
|
|
342
|
+
const guidance = validateGuidanceFields(config.guidance?.web_search);
|
|
343
|
+
const visibleProviders = getVisibleProviderNames(config);
|
|
311
344
|
|
|
312
345
|
pi.registerTool({
|
|
313
346
|
name: "web_search",
|
|
@@ -330,13 +363,8 @@ export function registerWebSearchTool(pi: ExtensionAPI): void {
|
|
|
330
363
|
),
|
|
331
364
|
provider: Type.Optional(
|
|
332
365
|
Type.Union(
|
|
333
|
-
|
|
334
|
-
{
|
|
335
|
-
description:
|
|
336
|
-
"Search provider to use for this call only, overriding the active provider set via /web-tools. " +
|
|
337
|
-
`Valid values: ${KNOWN_PROVIDER_NAMES.join(", ")}. ` +
|
|
338
|
-
"Omit to use the configured active provider. The named provider must have its API key/URL configured (via env var or /web-tools) or the call throws — there is no silent fallback.",
|
|
339
|
-
},
|
|
366
|
+
visibleProviders.names.map((name) => Type.Literal(name)),
|
|
367
|
+
{ description: providerSelectionDescription(visibleProviders.names, visibleProviders.active) },
|
|
340
368
|
),
|
|
341
369
|
),
|
|
342
370
|
}),
|
|
@@ -575,6 +603,14 @@ function formatShowConfigMessage(current: WebToolsConfig): string {
|
|
|
575
603
|
return lines.join("\n");
|
|
576
604
|
}
|
|
577
605
|
|
|
606
|
+
// The `web_search` provider enum is built from the config at registration, so a
|
|
607
|
+
// saved /web-tools change re-registers the tool: Pi replaces a re-registered
|
|
608
|
+
// tool's definition, and without the refresh the model would keep seeing the
|
|
609
|
+
// pre-change providers (and default) until the next restart (#204).
|
|
610
|
+
function refreshWebSearchSchema(pi: ExtensionAPI): void {
|
|
611
|
+
registerWebSearchTool(pi);
|
|
612
|
+
}
|
|
613
|
+
|
|
578
614
|
export function registerWebSearchConfigCommand(pi: ExtensionAPI): void {
|
|
579
615
|
pi.registerCommand(WEB_TOOLS_COMMAND_NAME, {
|
|
580
616
|
description: "Configure the search provider and API key used by web_search",
|
|
@@ -596,15 +632,7 @@ export function registerWebSearchConfigCommand(pi: ExtensionAPI): void {
|
|
|
596
632
|
...PROVIDERS.filter((p) => p.name === activeProvider),
|
|
597
633
|
...PROVIDERS.filter((p) => p.name !== activeProvider),
|
|
598
634
|
];
|
|
599
|
-
const hasKey = (p: ProviderMeta) =>
|
|
600
|
-
// Self-hosted providers are "configured" once they have a base URL
|
|
601
|
-
// (env or config). The bare default URL doesn't count — it's just a
|
|
602
|
-
// hint that the user hasn't touched the setting yet.
|
|
603
|
-
if (p.baseUrlEnvVar) {
|
|
604
|
-
return Boolean(process.env[p.baseUrlEnvVar]?.trim() || current.baseUrls?.[p.name]?.trim());
|
|
605
|
-
}
|
|
606
|
-
return resolveProviderApiKey(p.name, current) !== undefined;
|
|
607
|
-
};
|
|
635
|
+
const hasKey = (p: ProviderMeta) => isProviderConfigured(p, current);
|
|
608
636
|
const labelOf = (p: (typeof PROVIDERS)[number]) => {
|
|
609
637
|
const markers: string[] = [];
|
|
610
638
|
if (p.name === activeProvider) markers.push("✓");
|
|
@@ -657,6 +685,7 @@ export function registerWebSearchConfigCommand(pi: ExtensionAPI): void {
|
|
|
657
685
|
);
|
|
658
686
|
return;
|
|
659
687
|
}
|
|
688
|
+
refreshWebSearchSchema(pi);
|
|
660
689
|
ctx.ui.notify(
|
|
661
690
|
result.baseUrl
|
|
662
691
|
? `Saved ${selectedMeta.label} config (url: ${result.baseUrl}) to ${CONFIG_PATH}`
|
|
@@ -702,6 +731,7 @@ export function registerWebSearchConfigCommand(pi: ExtensionAPI): void {
|
|
|
702
731
|
);
|
|
703
732
|
return;
|
|
704
733
|
}
|
|
734
|
+
refreshWebSearchSchema(pi);
|
|
705
735
|
ctx.ui.notify(
|
|
706
736
|
trimmed
|
|
707
737
|
? `Saved ${selectedMeta.label} API key to ${CONFIG_PATH}`
|