@bohvaa/pi-web-tools 0.0.0-stage → 1.0.0

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/index.ts ADDED
@@ -0,0 +1,59 @@
1
+ import { getAgentDir, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import Conf from "conf";
3
+ import { Type } from "typebox";
4
+
5
+ import { providers } from "./providers.ts";
6
+
7
+ const result = (data: unknown) => ({ content: [{ type: "text" as const, text: JSON.stringify(data) }], details: {} });
8
+
9
+ export default function (pi: ExtensionAPI) {
10
+ const config = new Conf<{ provider: string; apiKeys: Record<string, string> }>({
11
+ cwd: getAgentDir(),
12
+ configName: "web-tools",
13
+ configFileMode: 0o600,
14
+ });
15
+
16
+ const client = () => {
17
+ const provider = config.get("provider");
18
+ const apiKey = config.get("apiKeys")?.[provider];
19
+ if (!provider || !apiKey) throw new Error("Please run /web-tools to configure a provider and API key first.");
20
+
21
+ return providers[provider](apiKey);
22
+ };
23
+
24
+ pi.registerCommand("web-tools", {
25
+ description: "Select and configure the web API provider.",
26
+
27
+ async handler(_args, ctx) {
28
+ const provider = await ctx.ui.select("web API provider", Object.keys(providers));
29
+ if (provider === undefined) return;
30
+
31
+ const apiKey = await ctx.ui.input(`${provider} API key`);
32
+ if (apiKey === undefined) return;
33
+
34
+ config.set({ provider, apiKeys: { ...config.get("apiKeys"), [provider]: apiKey } });
35
+ },
36
+ });
37
+
38
+ pi.registerTool({
39
+ name: "web_search",
40
+ label: "web search",
41
+ description: "Search the web for information. Returns result titles, URLs, and content snippets.",
42
+ parameters: Type.Object({ query: Type.String({ description: "search query" }) }),
43
+
44
+ async execute(_id, { query }) {
45
+ return result(await client().search(query));
46
+ },
47
+ });
48
+
49
+ pi.registerTool({
50
+ name: "web_fetch",
51
+ label: "web fetch",
52
+ description: "Fetch the content of a web page. Returns the page URL and extracted Markdown content.",
53
+ parameters: Type.Object({ url: Type.String({ description: "web page URL to fetch" }) }),
54
+
55
+ async execute(_id, { url }) {
56
+ return result(await client().fetch(url));
57
+ },
58
+ });
59
+ }
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@bohvaa/pi-web-tools",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/bohvaa/pi-web-tools.git"
7
+ },
8
+ "keywords": [
9
+ "pi-package"
10
+ ],
11
+ "type": "module",
12
+ "files": [
13
+ "index.ts",
14
+ "providers.ts"
15
+ ],
16
+ "engines": {
17
+ "node": ">=22"
18
+ },
19
+ "scripts": {
20
+ "format": "prettier --write .",
21
+ "format:check": "prettier --check ."
22
+ },
23
+ "pi": {
24
+ "extensions": [
25
+ "./index.ts"
26
+ ]
27
+ },
28
+ "dependencies": {
29
+ "@tavily/core": "^1.0.0",
30
+ "conf": "^16.0.0"
31
+ },
32
+ "peerDependencies": {
33
+ "@earendil-works/pi-coding-agent": "*",
34
+ "typebox": "*"
35
+ },
36
+ "devDependencies": {
37
+ "@ianvs/prettier-plugin-sort-imports": "^4.7.1",
38
+ "prettier": "^3.9.10"
39
+ }
40
+ }
package/providers.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { tavily } from "@tavily/core";
2
+
3
+ export interface WebProvider {
4
+ search(query: string): Promise<unknown>;
5
+ fetch(url: string): Promise<unknown>;
6
+ }
7
+
8
+ export const providers: Record<string, (apiKey: string) => WebProvider> = {
9
+ tavily: (apiKey) => {
10
+ const client = tavily({ apiKey });
11
+
12
+ return { search: (query) => client.search(query), fetch: (url) => client.extract([url]) };
13
+ },
14
+ };
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.