@zhexin/pi-agy 0.0.3 → 0.0.4

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/README.md CHANGED
@@ -12,7 +12,7 @@ pi auth login agy
12
12
 
13
13
  ## Usage
14
14
 
15
- Run `/agy usage` to show remaining 5-hour and weekly quota, with reset times.
15
+ Install [`@zhexin/pi-usage`](../usage/README.md) and run `/usage agy` to show remaining 5-hour and weekly quota, with reset times.
16
16
 
17
17
  ## License
18
18
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zhexin/pi-agy",
3
3
  "description": "Antigravity OAuth provider for the Pi agent.",
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "keywords": [
package/src/index.ts CHANGED
@@ -6,42 +6,30 @@ import { oauth } from "./auth.ts";
6
6
  import { agyCredential, fetchModels } from "./ccpa.ts";
7
7
  import { usage } from "./usage.ts";
8
8
 
9
- const commands: Record<
10
- string,
11
- {
12
- description: string;
13
- handler: (args: string, ctx: ExtensionCommandContext) => Promise<void>;
14
- }
15
- > = {
16
- usage: { description: "Show remaining quota", handler: usage },
17
- };
18
-
19
9
  export default function (pi: ExtensionAPI): void {
20
- pi.registerCommand("agy", {
21
- description: "Antigravity commands",
22
- getArgumentCompletions: (prefix) => {
23
- const items = Object.entries(commands)
24
- .filter(([name]) => name.startsWith(prefix))
25
- .map(([name, command]) => ({
26
- value: name,
27
- label: name,
28
- description: command.description,
29
- }));
30
- return items.length ? items : null;
31
- },
32
- handler: async (input, ctx) => {
33
- const [name = "", ...args] = input.trim().split(/\s+/);
34
- const command = Object.hasOwn(commands, name) ? commands[name] : undefined;
35
- if (command) {
36
- await command.handler(args.join(" "), ctx);
37
- return;
38
- }
39
- const help = Object.entries(commands)
40
- .map(([name, command]) => `/agy ${name} — ${command.description}`)
41
- .join("\n");
42
- if (ctx.hasUI) ctx.ui.notify(help, "info");
43
- else console.log(help);
44
- },
10
+ pi.events.on("pi-usage:discover", (data) => {
11
+ const discovery = data as {
12
+ add: (provider: { id: string; label: string; authHint: string }) => void;
13
+ };
14
+ if (typeof discovery?.add !== "function") return;
15
+ discovery.add({
16
+ id: "agy",
17
+ label: "Antigravity",
18
+ authHint: "Run /login agy to authenticate.",
19
+ });
20
+ });
21
+
22
+ pi.events.on("pi-usage:request", async (data) => {
23
+ const request = data as { provider: string; ctx: ExtensionCommandContext } | undefined;
24
+ if (request?.provider !== "agy" || !request.ctx) return;
25
+ const { ctx } = request;
26
+ try {
27
+ await usage(ctx);
28
+ } catch (error) {
29
+ const message = `Antigravity quota query failed: ${error instanceof Error ? error.message : String(error)}`;
30
+ if (ctx.hasUI) ctx.ui.notify(message, "error");
31
+ else console.error(message);
32
+ }
45
33
  });
46
34
 
47
35
  pi.on("before_agent_start", async (event, ctx) => {
package/src/usage.ts CHANGED
@@ -28,7 +28,7 @@ function resetLabel(resetTime: string | undefined, now: number): string {
28
28
  return ` · resets in ${remaining}`;
29
29
  }
30
30
 
31
- export async function usage(_args: string, ctx: ExtensionCommandContext): Promise<void> {
31
+ export async function usage(ctx: ExtensionCommandContext): Promise<void> {
32
32
  const output = (text: string) => {
33
33
  if (ctx.hasUI) ctx.ui.notify(text);
34
34
  else console.log(text);