@zhexin/pi-agy 0.0.1 → 0.0.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/README.md +4 -0
- package/package.json +1 -1
- package/src/api.ts +1 -9
- package/src/ccpa.ts +1 -1
- package/src/index.ts +39 -1
- package/src/usage.ts +62 -0
package/README.md
CHANGED
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -15,7 +15,6 @@ import {
|
|
|
15
15
|
type StreamOptions,
|
|
16
16
|
type TranscriptContext,
|
|
17
17
|
} from "@earendil-works/pi-ai";
|
|
18
|
-
import { clampMaxTokensToContext } from "@earendil-works/pi-ai/api/simple-options";
|
|
19
18
|
import { googleGenerativeAIApi } from "@earendil-works/pi-ai/compat";
|
|
20
19
|
|
|
21
20
|
import { endpointUrl, PROJECT_HEADER, USER_AGENT } from "./ccpa.ts";
|
|
@@ -212,14 +211,7 @@ function stream(
|
|
|
212
211
|
context,
|
|
213
212
|
{
|
|
214
213
|
...innerOptions,
|
|
215
|
-
maxTokens:
|
|
216
|
-
method === "streamSimple"
|
|
217
|
-
? clampMaxTokensToContext(
|
|
218
|
-
model,
|
|
219
|
-
context,
|
|
220
|
-
innerOptions.maxTokens ?? model.maxTokens,
|
|
221
|
-
)
|
|
222
|
-
: (innerOptions.maxTokens ?? model.maxTokens),
|
|
214
|
+
maxTokens: innerOptions.maxTokens ?? model.maxTokens,
|
|
223
215
|
...(backendId ? { thinking: { enabled: true } } : {}),
|
|
224
216
|
apiKey: adapter.key,
|
|
225
217
|
headers: Object.fromEntries(headers),
|
package/src/ccpa.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,11 +1,49 @@
|
|
|
1
1
|
import { createProvider } from "@earendil-works/pi-ai";
|
|
2
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
|
|
4
4
|
import { api } from "./api.ts";
|
|
5
5
|
import { oauth } from "./auth.ts";
|
|
6
6
|
import { agyCredential, fetchModels } from "./ccpa.ts";
|
|
7
|
+
import { usage } from "./usage.ts";
|
|
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
|
+
};
|
|
7
18
|
|
|
8
19
|
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
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
9
47
|
pi.on("before_agent_start", async (event, ctx) => {
|
|
10
48
|
if (ctx.model?.provider !== "agy") return;
|
|
11
49
|
return {
|
package/src/usage.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
import { PROJECT_HEADER, rpc } from "./ccpa.ts";
|
|
4
|
+
|
|
5
|
+
type QuotaSummary = {
|
|
6
|
+
groups: {
|
|
7
|
+
displayName: string;
|
|
8
|
+
buckets: {
|
|
9
|
+
bucketId: string;
|
|
10
|
+
displayName: string;
|
|
11
|
+
window: string;
|
|
12
|
+
remainingFraction: number;
|
|
13
|
+
resetTime: string;
|
|
14
|
+
}[];
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function resetLabel(resetTime: string | undefined, now: number): string {
|
|
19
|
+
const minutes = Math.ceil((Date.parse(resetTime ?? "") - now) / 60_000);
|
|
20
|
+
if (!Number.isFinite(minutes) || minutes <= 0) return "";
|
|
21
|
+
const hours = Math.floor(minutes / 60);
|
|
22
|
+
const days = Math.floor(hours / 24);
|
|
23
|
+
const remaining = days
|
|
24
|
+
? `${days}d ${hours % 24}h`
|
|
25
|
+
: hours
|
|
26
|
+
? `${hours}h ${minutes % 60}m`
|
|
27
|
+
: `${minutes}m`;
|
|
28
|
+
return ` · resets in ${remaining}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function usage(_args: string, ctx: ExtensionCommandContext): Promise<void> {
|
|
32
|
+
const output = (text: string) => {
|
|
33
|
+
if (ctx.hasUI) ctx.ui.notify(text);
|
|
34
|
+
else console.log(text);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const resolved = await ctx.modelRegistry.getProviderAuth("agy");
|
|
38
|
+
const auth = resolved?.auth;
|
|
39
|
+
const project = auth?.headers?.[PROJECT_HEADER];
|
|
40
|
+
if (!auth?.apiKey || !auth.baseUrl || !project) {
|
|
41
|
+
output("Run /login agy to authenticate.");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const summary = await rpc<QuotaSummary>(
|
|
45
|
+
auth.apiKey,
|
|
46
|
+
auth.baseUrl,
|
|
47
|
+
"retrieveUserQuotaSummary",
|
|
48
|
+
{ project },
|
|
49
|
+
ctx.signal ?? AbortSignal.timeout(30_000),
|
|
50
|
+
);
|
|
51
|
+
const now = Date.now();
|
|
52
|
+
const groups = summary.groups.flatMap((group) => {
|
|
53
|
+
const buckets = group.buckets.map((bucket) => {
|
|
54
|
+
const fraction = bucket.remainingFraction;
|
|
55
|
+
const left = `${String(Math.round(Math.max(0, Math.min(1, fraction)) * 100)).padStart(3)}% left`;
|
|
56
|
+
const label = bucket.window || bucket.displayName || bucket.bucketId || "Quota";
|
|
57
|
+
return ` ${label.padEnd(6)} ${left}${resetLabel(bucket.resetTime, now)}`;
|
|
58
|
+
});
|
|
59
|
+
return buckets.length ? [[group.displayName || "AGY", ...buckets].join("\n")] : [];
|
|
60
|
+
});
|
|
61
|
+
output(groups.join("\n\n") || "No quota information available.");
|
|
62
|
+
}
|