@aliou/pi-synthetic 0.4.2 → 0.4.3

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @aliou/pi-synthetic
2
2
 
3
+ ## 0.4.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 7dc1d80: Defer subscription check to session_start for non-blocking extension init.
8
+
3
9
  ## 0.4.2
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aliou/pi-synthetic",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/aliou/pi-synthetic"
@@ -14,6 +14,9 @@
14
14
  ],
15
15
  "video": "https://assets.aliou.me/pi-extensions/demos/pi-synthetic.mp4"
16
16
  },
17
+ "peerDependencies": {
18
+ "@mariozechner/pi-coding-agent": ">=0.51.0"
19
+ },
17
20
  "devDependencies": {
18
21
  "@biomejs/biome": "^2.3.13",
19
22
  "@changesets/cli": "^2.27.11",
@@ -1,9 +1,9 @@
1
1
  import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2
2
  import type { Component } from "@mariozechner/pi-tui";
3
- import { QuotasDisplayComponent } from "../components/quotas-display.js";
4
- import { QuotasErrorComponent } from "../components/quotas-error.js";
5
- import { QuotasLoadingComponent } from "../components/quotas-loading.js";
6
- import type { QuotasResponse } from "../types/quotas.js";
3
+ import { QuotasDisplayComponent } from "../components/quotas-display";
4
+ import { QuotasErrorComponent } from "../components/quotas-error";
5
+ import { QuotasLoadingComponent } from "../components/quotas-loading";
6
+ import type { QuotasResponse } from "../types/quotas";
7
7
 
8
8
  export function registerQuotasCommand(pi: ExtensionAPI): void {
9
9
  pi.registerCommand("synthetic:quotas", {
@@ -19,7 +19,7 @@ export function registerQuotasCommand(pi: ExtensionAPI): void {
19
19
  return;
20
20
  }
21
21
 
22
- await ctx.ui.custom<void>((tui, theme, _kb, done) => {
22
+ const result = await ctx.ui.custom<void>((tui, theme, _kb, done) => {
23
23
  let currentComponent: Component = new QuotasLoadingComponent(theme);
24
24
 
25
25
  fetchQuotas()
@@ -50,6 +50,16 @@ export function registerQuotasCommand(pi: ExtensionAPI): void {
50
50
  },
51
51
  };
52
52
  });
53
+
54
+ // RPC fallback: custom() returned undefined
55
+ if (result === undefined) {
56
+ const quotas = await fetchQuotas();
57
+ if (!quotas) {
58
+ ctx.ui.notify("Failed to fetch quotas", "error");
59
+ return;
60
+ }
61
+ ctx.ui.notify(formatQuotasPlain(quotas), "info");
62
+ }
53
63
  },
54
64
  });
55
65
  }
@@ -1,7 +1,7 @@
1
1
  import type { Theme } from "@mariozechner/pi-coding-agent";
2
2
  import { DynamicBorder } from "@mariozechner/pi-coding-agent";
3
3
  import { type Component, Container, Text } from "@mariozechner/pi-tui";
4
- import type { QuotasResponse } from "../types/quotas.js";
4
+ import type { QuotasResponse } from "../types/quotas";
5
5
 
6
6
  export class QuotasDisplayComponent implements Component {
7
7
  private container: Container;
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2
- import { registerQuotasCommand } from "./commands/quotas.js";
3
- import { registerSyntheticProvider } from "./providers/index.js";
4
- import { registerSyntheticWebSearchTool } from "./tools/search.js";
2
+ import { registerQuotasCommand } from "./commands/quotas";
3
+ import { registerSyntheticProvider } from "./providers/index";
4
+ import { registerSyntheticWebSearchTool } from "./tools/search";
5
5
 
6
6
  export default async function (pi: ExtensionAPI) {
7
7
  registerSyntheticProvider(pi);
@@ -9,6 +9,6 @@ export default async function (pi: ExtensionAPI) {
9
9
  // Only register quotas command and web search tool if API key is available
10
10
  if (process.env.SYNTHETIC_API_KEY) {
11
11
  registerQuotasCommand(pi);
12
- await registerSyntheticWebSearchTool(pi);
12
+ registerSyntheticWebSearchTool(pi);
13
13
  }
14
14
  }
@@ -1,5 +1,5 @@
1
1
  import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2
- import { SYNTHETIC_MODELS } from "./models.js";
2
+ import { SYNTHETIC_MODELS } from "./models";
3
3
 
4
4
  export function registerSyntheticProvider(pi: ExtensionAPI): void {
5
5
  pi.registerProvider("synthetic", {
@@ -73,27 +73,30 @@ async function checkSubscriptionAccess(
73
73
  }
74
74
 
75
75
  // Tool Registration
76
- export async function registerSyntheticWebSearchTool(pi: ExtensionAPI) {
77
- // Check for API key
76
+ export function registerSyntheticWebSearchTool(pi: ExtensionAPI) {
78
77
  const apiKey = process.env.SYNTHETIC_API_KEY;
79
78
  if (!apiKey) {
80
79
  return;
81
80
  }
82
81
 
83
- // Only register if user has subscription access (search is subscription-only)
84
- const access = await checkSubscriptionAccess(apiKey);
85
- if (!access.ok) {
86
- pi.on("session_start", async (_event, ctx) => {
82
+ // Check subscription on session start, only register tool if access is granted
83
+ pi.on("session_start", async (_event, ctx) => {
84
+ const access = await checkSubscriptionAccess(apiKey);
85
+ if (!access.ok) {
87
86
  if (ctx.hasUI) {
88
87
  ctx.ui.notify(
89
88
  `Synthetic web search disabled: ${access.reason}`,
90
89
  "warning",
91
90
  );
92
91
  }
93
- });
94
- return;
95
- }
92
+ return;
93
+ }
96
94
 
95
+ registerTool(pi, apiKey);
96
+ });
97
+ }
98
+
99
+ function registerTool(pi: ExtensionAPI, apiKey: string) {
97
100
  pi.registerTool<typeof SearchParams, WebSearchDetails>({
98
101
  name: "synthetic_web_search",
99
102
  label: "Synthetic: Web Search",
@@ -105,21 +108,13 @@ export async function registerSyntheticWebSearchTool(pi: ExtensionAPI) {
105
108
  _toolCallId: string,
106
109
  params: SearchParamsType,
107
110
  signal: AbortSignal | undefined,
108
- onUpdate: (result: AgentToolResult<WebSearchDetails>) => void,
111
+ onUpdate:
112
+ | ((result: AgentToolResult<WebSearchDetails>) => void)
113
+ | undefined,
109
114
  _ctx: ExtensionContext,
110
115
  ): Promise<AgentToolResult<WebSearchDetails>> {
111
- // Check for API key
112
- const apiKey = process.env.SYNTHETIC_API_KEY;
113
- if (!apiKey) {
114
- const error = "SYNTHETIC_API_KEY environment variable is required";
115
- return {
116
- content: [{ type: "text", text: `Error: ${error}` }],
117
- details: { error, isError: true },
118
- };
119
- }
120
-
121
116
  // Send progress update
122
- onUpdate({
117
+ onUpdate?.({
123
118
  content: [{ type: "text", text: "Searching..." }],
124
119
  details: { query: params.query },
125
120
  });