@alexanderfortin/pi-tavily-tools 0.2.0 → 0.3.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,45 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.3.1] - 2026-04-06
9
+
10
+ ### Changed
11
+
12
+ - fixed wrong calculation for status, now also includes paygo data
13
+ - bump Pi deps to latest
14
+
15
+ ## [0.3.0] - 2026-04-05
16
+
17
+ ### Added
18
+
19
+ - add Tavily quota usage to footer
20
+ - CI workflow for Pi
21
+ - add CHANGELOG.md (this file)
22
+
23
+ ## [0.2.0] - 2026-04-05
24
+
25
+ ### Added
26
+
27
+ - `web_extract` tool for extracting raw content from URLs using Tavily
28
+
29
+ ## [0.1.2] - 2026-04-05
30
+
31
+ ### Changed
32
+
33
+ - Refactor: split web search execute function
34
+
35
+ ## [0.1.1] - 2026-04-05
36
+
37
+ ### Changed
38
+
39
+ - Bump version to v0.1.1 to test NPM publishing workflow
40
+
41
+ ## [0.1.0] - 2026-04-04
42
+
43
+ ### Added
44
+
45
+ - Initial release with `web_search` tool using Tavily
package/README.md CHANGED
@@ -39,6 +39,7 @@ You can get a free one at <https://tavily.com>
39
39
 
40
40
  ### Shared Features
41
41
 
42
+ - **Usage in Footer:** Show current percentage of Tavily quota used in the footer
42
43
  - **Proper Truncation:** Output truncated to 50KB / 2000 lines to avoid context overflow
43
44
  - **Custom TUI Rendering:** Beautiful display with expandable results
44
45
  - **Error Handling:** Graceful failures with helpful error messages
package/dist/index.d.ts CHANGED
@@ -9,6 +9,9 @@ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
9
9
  /**
10
10
  * Main extension entry point.
11
11
  *
12
+ * Requires TAVILY_API_KEY to be set — if missing, no hooks are registered
13
+ * and the extension is effectively a no-op.
14
+ *
12
15
  * Defers tool registration to `session_start` so Pi can start
13
16
  * even if the TAVILY_API_KEY is missing. The tool is registered only
14
17
  * once on the first agent run and persists across sessions.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAKlE;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,WAAW,EAAE,EAAE,YAAY,GAAG,IAAI,CAoB/C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAMlE;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,WAAW,EAAE,EAAE,YAAY,GAAG,IAAI,CAyB/C"}
package/dist/index.js CHANGED
@@ -8,33 +8,37 @@
8
8
  import { createTavilyClient } from "./tools/tavily/client.js";
9
9
  import { registerWebExtractTool } from "./tools/web-extract.js";
10
10
  import { registerWebSearchTool } from "./tools/web-search.js";
11
+ import { TavilyUsageCache } from "./usage/status.js";
11
12
  /**
12
13
  * Main extension entry point.
13
14
  *
15
+ * Requires TAVILY_API_KEY to be set — if missing, no hooks are registered
16
+ * and the extension is effectively a no-op.
17
+ *
14
18
  * Defers tool registration to `session_start` so Pi can start
15
19
  * even if the TAVILY_API_KEY is missing. The tool is registered only
16
20
  * once on the first agent run and persists across sessions.
17
21
  */
18
22
  export default function (pi) {
23
+ const apiKey = process.env.TAVILY_API_KEY?.trim();
24
+ if (!apiKey)
25
+ return;
19
26
  let registered = false;
20
- pi.on("session_start", (_event, ctx) => {
27
+ const usageCache = new TavilyUsageCache(apiKey);
28
+ pi.on("session_start", async (_event, ctx) => {
21
29
  if (registered)
22
30
  return;
23
31
  registered = true;
24
- try {
25
- const client = createTavilyClient();
26
- registerWebSearchTool(pi, client);
27
- registerWebExtractTool(pi, client);
28
- }
29
- catch (error) {
30
- if (error instanceof Error) {
31
- ctx.ui.notify(`[pi-tavily-tools] ${error.message}`, "error");
32
- }
33
- else {
34
- // Re-throw non-Error types (shouldn't happen, but be safe)
35
- throw error;
36
- }
37
- }
32
+ const client = createTavilyClient(apiKey);
33
+ registerWebSearchTool(pi, client);
34
+ registerWebExtractTool(pi, client);
35
+ await usageCache.updateStatus(ctx);
36
+ });
37
+ pi.on("turn_end", async (_event, ctx) => {
38
+ await usageCache.updateStatus(ctx);
39
+ });
40
+ pi.on("session_shutdown", (_event, ctx) => {
41
+ usageCache.clear(ctx);
38
42
  });
39
43
  }
40
44
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,WAAW,EAAgB;IACvC,IAAI,UAAU,GAAG,KAAK,CAAC;IAEvB,EAAE,CAAC,EAAE,CAAC,eAAe,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;QACrC,IAAI,UAAU;YAAE,OAAO;QACvB,UAAU,GAAG,IAAI,CAAC;QAElB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,kBAAkB,EAAE,CAAC;YACpC,qBAAqB,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;YAClC,sBAAsB,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAA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MAAM,EAAE,GAAG,EAAE,EAAE;QACtC,MAAM,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,EAAE,CAAC,kBAAkB,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;QACxC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Tavily Usage API Client
3
+ *
4
+ * Fetches usage data from the Tavily usage endpoint.
5
+ * @see https://docs.tavily.com/documentation/api-reference/endpoint/usage
6
+ */
7
+ export interface TavilyUsageKeySection {
8
+ usage: number;
9
+ limit: number;
10
+ search_usage: number;
11
+ extract_usage: number;
12
+ crawl_usage: number;
13
+ map_usage: number;
14
+ research_usage: number;
15
+ }
16
+ export interface TavilyUsageAccountSection {
17
+ current_plan?: string;
18
+ plan_usage: number;
19
+ plan_limit: number;
20
+ paygo_usage: number;
21
+ paygo_limit: number;
22
+ search_usage: number;
23
+ extract_usage: number;
24
+ crawl_usage: number;
25
+ map_usage: number;
26
+ research_usage: number;
27
+ }
28
+ export interface TavilyUsageResponse {
29
+ key: TavilyUsageKeySection;
30
+ account: TavilyUsageAccountSection;
31
+ }
32
+ export interface TavilyUsageData {
33
+ /** Total usage as percentage of combined plan + PAYGO limit (0–100+) */
34
+ percentage: number;
35
+ /** Plan credits used */
36
+ planUsage: number;
37
+ /** Plan credits available */
38
+ planLimit: number;
39
+ /** Pay-as-you-go credits used */
40
+ paygoUsage: number;
41
+ /** Pay-as-you-go credits available */
42
+ paygoLimit: number;
43
+ /** Per-API key usage */
44
+ keyUsage: number;
45
+ /** Per-API key limit */
46
+ keyLimit: number;
47
+ }
48
+ /**
49
+ * Fetch Tavily usage data from the API
50
+ * @throws {Error} If the API key is missing, the request fails, or the response is malformed
51
+ */
52
+ export declare function getTavilyUsage(apiKey: string): Promise<TavilyUsageData>;
53
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/usage/api.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,yBAAyB;IACxC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,qBAAqB,CAAC;IAC3B,OAAO,EAAE,yBAAyB,CAAC;CACpC;AAED,MAAM,WAAW,eAAe;IAC9B,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC;IACnB,wBAAwB;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,wBAAwB;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,wBAAwB;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAMD;;;GAGG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAwC7E"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Tavily Usage API Client
3
+ *
4
+ * Fetches usage data from the Tavily usage endpoint.
5
+ * @see https://docs.tavily.com/documentation/api-reference/endpoint/usage
6
+ */
7
+ const TAVILY_USAGE_API_URL = "https://api.tavily.com/usage";
8
+ // ============================================================================
9
+ // API Client
10
+ // ============================================================================
11
+ /**
12
+ * Fetch Tavily usage data from the API
13
+ * @throws {Error} If the API key is missing, the request fails, or the response is malformed
14
+ */
15
+ export async function getTavilyUsage(apiKey) {
16
+ if (!apiKey) {
17
+ throw new Error("TAVILY_API_KEY is not set. " + 'Please set it with: export TAVILY_API_KEY="your-api-key"');
18
+ }
19
+ const response = await fetch(TAVILY_USAGE_API_URL, {
20
+ headers: {
21
+ Authorization: `Bearer ${apiKey}`,
22
+ },
23
+ });
24
+ if (!response.ok) {
25
+ throw new Error(`Tavily usage API request failed with status ${response.status}`);
26
+ }
27
+ const data = (await response.json());
28
+ if (!data.account || typeof data.account.plan_usage !== "number") {
29
+ throw new Error("Unexpected Tavily usage API response: missing account usage data");
30
+ }
31
+ if (typeof data.account.plan_limit !== "number") {
32
+ throw new Error("Unexpected Tavily usage API response: missing account plan limit");
33
+ }
34
+ const totalUsage = data.account.plan_usage + (data.account.paygo_usage ?? 0);
35
+ const totalLimit = data.account.plan_limit + (data.account.paygo_limit ?? 0);
36
+ const percentage = (totalUsage / (totalLimit || 1)) * 100;
37
+ return {
38
+ percentage,
39
+ planUsage: data.account.plan_usage,
40
+ planLimit: data.account.plan_limit,
41
+ paygoUsage: data.account.paygo_usage ?? 0,
42
+ paygoLimit: data.account.paygo_limit ?? 0,
43
+ keyUsage: data.key?.usage ?? 0,
44
+ keyLimit: data.key?.limit ?? 0,
45
+ };
46
+ }
47
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/usage/api.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,M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AC;IAE1D,OAAO;QACL,UAAU;QACV,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU;QAClC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU;QAClC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,IAAI,CAAC;QACzC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,IAAI,CAAC;QACzC,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,IAAI,CAAC;QAC9B,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,IAAI,CAAC;KAC/B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Tavily Usage Footer Status
3
+ *
4
+ * Manages the Pi footer status display for Tavily API usage,
5
+ * with caching to avoid excessive API calls.
6
+ */
7
+ import type { ExtensionContext } from "@mariozechner/pi-coding-agent";
8
+ import { type TavilyUsageData } from "./api.js";
9
+ /** Fetch usage function signature (same as getTavilyUsage for testability) */
10
+ export type FetchUsageFn = (apiKey: string) => Promise<TavilyUsageData>;
11
+ /** Cache for Tavily usage data to avoid excessive API calls */
12
+ export declare class TavilyUsageCache {
13
+ private readonly apiKey;
14
+ private lastUsage;
15
+ private lastFetchTime;
16
+ private static readonly FETCH_COOLDOWN_MS;
17
+ constructor(apiKey: string);
18
+ /** Build and set footer status string from usage data */
19
+ private setStatusFromUsage;
20
+ /** Update footer status with Tavily usage information */
21
+ updateStatus(ctx: ExtensionContext, fetchUsage?: FetchUsageFn): Promise<void>;
22
+ /** Clear Tavily usage footer status */
23
+ clear(ctx: ExtensionContext): void;
24
+ }
25
+ //# sourceMappingURL=status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/usage/status.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhE,8EAA8E;AAC9E,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,eAAe,CAAC,CAAC;AAExE,+DAA+D;AAC/D,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,SAAS,CAAgC;IACjD,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAU;gBAEvC,MAAM,EAAE,MAAM;IAI1B,yDAAyD;IACzD,OAAO,CAAC,kBAAkB;IAS1B,yDAAyD;IACnD,YAAY,CAChB,GAAG,EAAE,gBAAgB,EACrB,UAAU,GAAE,YAA6B,GACxC,OAAO,CAAC,IAAI,CAAC;IAyBhB,uCAAuC;IACvC,KAAK,CAAC,GAAG,EAAE,gBAAgB,GAAG,IAAI;CAGnC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Tavily Usage Footer Status
3
+ *
4
+ * Manages the Pi footer status display for Tavily API usage,
5
+ * with caching to avoid excessive API calls.
6
+ */
7
+ import { Temporal } from "temporal-polyfill";
8
+ import { getTavilyUsage } from "./api.js";
9
+ /** Cache for Tavily usage data to avoid excessive API calls */
10
+ export class TavilyUsageCache {
11
+ apiKey;
12
+ lastUsage = null;
13
+ lastFetchTime = 0;
14
+ static FETCH_COOLDOWN_MS = 30_000;
15
+ constructor(apiKey) {
16
+ this.apiKey = apiKey;
17
+ }
18
+ /** Build and set footer status string from usage data */
19
+ setStatusFromUsage(ctx, usageData) {
20
+ const theme = ctx.ui.theme;
21
+ const displayPercentage = Math.round(usageData.percentage * 10) / 10;
22
+ let status = theme.fg("muted", "Tavily:") + theme.fg("accent", `${displayPercentage}%`);
23
+ ctx.ui.setStatus("tavily-usage", status);
24
+ }
25
+ /** Update footer status with Tavily usage information */
26
+ async updateStatus(ctx, fetchUsage = getTavilyUsage) {
27
+ try {
28
+ const now = Temporal.Now.instant().epochMilliseconds;
29
+ // Use cached data if still fresh
30
+ if (this.lastUsage &&
31
+ this.lastFetchTime &&
32
+ now - this.lastFetchTime < TavilyUsageCache.FETCH_COOLDOWN_MS) {
33
+ this.setStatusFromUsage(ctx, this.lastUsage);
34
+ return;
35
+ }
36
+ const usage = await fetchUsage(this.apiKey);
37
+ this.lastUsage = usage;
38
+ this.lastFetchTime = now;
39
+ this.setStatusFromUsage(ctx, usage);
40
+ }
41
+ catch (error) {
42
+ console.error(`Error updating Tavily usage: ${String(error)}`);
43
+ this.clear(ctx);
44
+ }
45
+ }
46
+ /** Clear Tavily usage footer status */
47
+ clear(ctx) {
48
+ ctx.ui.setStatus("tavily-usage", undefined);
49
+ }
50
+ }
51
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/usage/status.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAwB,MAAM,UAAU,CAAC;AAKhE,+DAA+D;AAC/D,MAAM,OAAO,gBAAgB;IACV,MAAM,CAAS;IACxB,SAAS,GAA2B,IAAI,CAAC;IACzC,aAAa,GAAG,CAAC,CAAC;IAClB,MAAM,CAAU,iBAAiB,GAAG,MAAM,CAAC;IAEnD,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,yDAAyD;IACjD,kBAAkB,CAAC,GAAqB,EAAE,SAA0B;QAC1E,MAAM,KAAK,GAAG,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC;QAC3B,MAAM,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,UAAU,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;QAErE,IAAI,MAAM,GAAG,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,GAAG,KAA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"0.3.1",
5
5
  "description": "Pi coding agent extension for web search and content extraction using Tavily",
6
6
  "keywords": [
7
7
  "pi-package",
@@ -33,6 +33,7 @@
33
33
  "dist",
34
34
  "package.json",
35
35
  "README.md",
36
+ "CHANGELOG.md",
36
37
  "LICENSE"
37
38
  ],
38
39
  "peerDependencies": {
@@ -60,21 +61,22 @@
60
61
  "release:dry-run": "bun run build && npm publish --dry-run"
61
62
  },
62
63
  "devDependencies": {
63
- "@mariozechner/pi-ai": "*",
64
- "@mariozechner/pi-coding-agent": "*",
65
- "@mariozechner/pi-tui": "*",
66
- "@sinclair/typebox": "*",
64
+ "@mariozechner/pi-ai": "^0.65.2",
65
+ "@mariozechner/pi-coding-agent": "^0.65.2",
66
+ "@mariozechner/pi-tui": "^0.65.2",
67
+ "@sinclair/typebox": "^0.34.49",
67
68
  "@types/bun": "^1.3.11",
68
69
  "@types/node": "^25.5.2",
69
- "@typescript-eslint/eslint-plugin": "^8.20.0",
70
- "@typescript-eslint/parser": "^8.20.0",
70
+ "@typescript-eslint/eslint-plugin": "^8.58.0",
71
+ "@typescript-eslint/parser": "^8.58.0",
71
72
  "eslint": "^10.2.0",
72
73
  "eslint-config-prettier": "^10.1.8",
73
- "prettier": "^3.4.2",
74
- "prettier-plugin-organize-imports": "^4.1.0",
75
- "typescript": "^6.0.0"
74
+ "prettier": "^3.8.1",
75
+ "prettier-plugin-organize-imports": "^4.3.0",
76
+ "typescript": "^6.0.2"
76
77
  },
77
78
  "dependencies": {
78
- "@tavily/core": "^0.7.2"
79
+ "@tavily/core": "^0.7.2",
80
+ "temporal-polyfill": "^0.3.2"
79
81
  }
80
82
  }