Skip to content

Commit ddfa940

Browse files
chore(pi-web-search): update Pi package scope (#12)
1 parent af179e6 commit ddfa940

7 files changed

Lines changed: 45 additions & 1110 deletions

File tree

packages/pi-web-search/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 0.5.0
4+
5+
### Minor Changes
6+
7+
- Update Pi peer dependencies and extension imports to the official
8+
`@earendil-works/*` package scope for Pi 0.74.
9+
- Treat `typebox` as a Pi-provided peer dependency for extension schemas.
10+
311
## 0.4.1
412

513
### Patch Changes

packages/pi-web-search/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Pi Web Search
22

3-
A [Pi](https://github.com/badlogic/pi-coding-agent) extension that gives the agent two tools for working with the open web:
3+
A [Pi](https://github.com/earendil-works/pi) extension that gives the agent two tools for working with the open web:
44

55
1. **`web_search`** for querying multiple search providers with automatic fallback.
66
2. **`web_fetch`** for reading pages as clean markdown.

packages/pi-web-search/extensions/web-search.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2-
import { StringEnum, Type } from "@mariozechner/pi-ai";
1+
import { StringEnum } from "@earendil-works/pi-ai";
2+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
3+
import { Type } from "typebox";
34

45
import { loadConfig, normalizeDomains, resolveSearchProviders } from "../src/config.js";
56
import {
@@ -50,15 +51,15 @@ export default function (pi: ExtensionAPI) {
5051
parameters: Type.Object({
5152
query: Type.String({ description: "Search query" }),
5253
depth: Type.Optional(
53-
StringEnum(["basic", "thorough"], {
54+
StringEnum(["basic", "thorough"] as const, {
5455
default: "basic",
5556
description:
5657
"basic (default): fast search that returns snippets. " +
5758
"thorough: content-enriched search that may include one inline content excerpt.",
5859
}),
5960
),
6061
freshness: Type.Optional(
61-
StringEnum(["day", "week", "month", "year"], {
62+
StringEnum(["day", "week", "month", "year"] as const, {
6263
description: "Optional recency filter for time-sensitive searches.",
6364
}),
6465
),
@@ -79,19 +80,22 @@ export default function (pi: ExtensionAPI) {
7980
),
8081
}),
8182
async execute(_toolCallId, params, signal, onUpdate) {
83+
const abortSignal = signal ?? new AbortController().signal;
84+
8285
if (!providers.hasAnySearchProvider) {
8386
throw new Error(
8487
"No search provider configured. Set one of BRAVE_API_KEY, TAVILY_API_KEY, or EXA_API_KEY to enable web_search.",
8588
);
8689
}
8790

8891
const depth = params.depth ?? "basic";
92+
const freshness = params.freshness;
8993
const maxResults = params.max_results ?? 5;
9094
const domains = normalizeDomains(params.domains);
9195
const resolution = resolveSearchProviders(
9296
{
9397
depth,
94-
freshness: params.freshness,
98+
freshness,
9599
domains,
96100
},
97101
providers.search,
@@ -107,7 +111,7 @@ export default function (pi: ExtensionAPI) {
107111
let lastError: Error | undefined;
108112

109113
for (const provider of resolution.providers) {
110-
if (signal.aborted) throw new Error("Search aborted.");
114+
if (abortSignal.aborted) throw new Error("Search aborted.");
111115

112116
onUpdate?.({
113117
content: [
@@ -124,9 +128,9 @@ export default function (pi: ExtensionAPI) {
124128
query: params.query,
125129
maxResults,
126130
includeContent: resolution.servedDepth === "thorough",
127-
freshness: params.freshness,
131+
freshness,
128132
domains,
129-
signal,
133+
signal: abortSignal,
130134
});
131135

132136
const notes = [...resolution.notes, ...(response.notes ?? [])];
@@ -140,7 +144,7 @@ export default function (pi: ExtensionAPI) {
140144
provider: provider.name,
141145
requestedDepth: depth,
142146
servedDepth: resolution.servedDepth,
143-
freshness: params.freshness,
147+
freshness,
144148
domains,
145149
appliedFilters: response.appliedFilters,
146150
notes,
@@ -153,14 +157,14 @@ export default function (pi: ExtensionAPI) {
153157
servedDepth: resolution.servedDepth,
154158
degraded: resolution.servedDepth !== depth,
155159
warnings: config.warnings,
156-
freshness: params.freshness ?? null,
160+
freshness: freshness ?? null,
157161
domains: domains ?? [],
158162
appliedFilters: response.appliedFilters ?? null,
159163
resultCount: response.results.length,
160164
},
161165
};
162166
} catch (error) {
163-
if (signal.aborted) throw error;
167+
if (abortSignal.aborted) throw error;
164168

165169
lastError = error instanceof Error ? error : new Error(String(error));
166170
if (!isTransientProviderError(lastError)) {
@@ -199,6 +203,7 @@ export default function (pi: ExtensionAPI) {
199203
),
200204
}),
201205
async execute(_toolCallId, params, signal) {
206+
const abortSignal = signal ?? new AbortController().signal;
202207
const url = validateFetchUrl(params.url);
203208
const offset = params.offset ?? 0;
204209
const maxChars = params.max_chars ?? FETCH_DEFAULT_MAX_CHARS;
@@ -214,11 +219,11 @@ export default function (pi: ExtensionAPI) {
214219
}
215220

216221
try {
217-
content = await provider.fetch(url, signal);
222+
content = await provider.fetch(url, abortSignal);
218223
providerName = provider.name;
219224
pageCache.set(url, content, provider.name);
220225
} catch (error) {
221-
if (signal.aborted) throw error;
226+
if (abortSignal.aborted) throw error;
222227

223228
const providerError = error instanceof Error ? error : new Error(String(error));
224229
if (!isTransientProviderError(providerError)) {

packages/pi-web-search/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@counterposition/pi-web-search",
3-
"version": "0.4.1",
3+
"version": "0.5.0",
44
"description": "Multi-provider web search and markdown page fetch for Pi",
55
"keywords": [
66
"brave-search",
@@ -48,15 +48,19 @@
4848
"pack:check": "pnpm pack --pack-destination ../../.pack"
4949
},
5050
"devDependencies": {
51+
"@earendil-works/pi-ai": "^0.74.0",
52+
"@earendil-works/pi-coding-agent": "^0.74.0",
5153
"@types/node": "^25.5.0",
5254
"oxfmt": "^0.42.0",
5355
"oxlint": "^1.57.0",
56+
"typebox": "^1.1.38",
5457
"typescript": "^6.0.2",
5558
"vitest": "^4.1.2"
5659
},
5760
"peerDependencies": {
58-
"@mariozechner/pi-ai": "*",
59-
"@mariozechner/pi-coding-agent": "*"
61+
"@earendil-works/pi-ai": "*",
62+
"@earendil-works/pi-coding-agent": "*",
63+
"typebox": "*"
6064
},
6165
"engines": {
6266
"node": ">=24"

packages/pi-web-search/src/pi-ambient.d.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

packages/pi-web-search/tests/extension.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const state = vi.hoisted(() => ({
2626
resolveSearchProviders: vi.fn(),
2727
}));
2828

29-
vi.mock("@mariozechner/pi-ai", () => ({
29+
vi.mock("@earendil-works/pi-ai", () => ({
3030
Type: {
3131
Object: (value: unknown) => value,
3232
String: (value?: unknown) => value ?? {},

0 commit comments

Comments
 (0)