refactor: replace any types with proper SDK types in event handlers
This commit is contained in:
16
index.ts
16
index.ts
@@ -1,4 +1,4 @@
|
|||||||
import { AuthStorage, type AuthCredential, type ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
import { AuthStorage, type AuthCredential, type ExtensionAPI, type ExtensionContext, type ExtensionCommandContext, type SessionStartEvent, type SessionShutdownEvent, type AgentEndEvent } from "@mariozechner/pi-coding-agent";
|
||||||
import { statusbarConfig } from "./config";
|
import { statusbarConfig } from "./config";
|
||||||
import { contextModule, costModule, directoryModule, modelModule, thinkingModule } from "./modules/basic";
|
import { contextModule, costModule, directoryModule, modelModule, thinkingModule } from "./modules/basic";
|
||||||
import { usageModule } from "./modules/usage";
|
import { usageModule } from "./modules/usage";
|
||||||
@@ -64,7 +64,7 @@ async function readPiCredential(authStorage: AuthStorage, provider: Provider): P
|
|||||||
async function forceRefreshPiCredential(authStorage: AuthStorage, provider: Provider): Promise<UsageCredential> {
|
async function forceRefreshPiCredential(authStorage: AuthStorage, provider: Provider): Promise<UsageCredential> {
|
||||||
authStorage.reload();
|
authStorage.reload();
|
||||||
const raw = authStorage.get(provider);
|
const raw = authStorage.get(provider);
|
||||||
const oauthProvider = authStorage.getOAuthProviders().find((candidate: any) => candidate.id === provider);
|
const oauthProvider = authStorage.getOAuthProviders().find(candidate => candidate.id === provider);
|
||||||
if (raw?.type !== "oauth" || !oauthProvider) throw new Error("login expired");
|
if (raw?.type !== "oauth" || !oauthProvider) throw new Error("login expired");
|
||||||
|
|
||||||
// Refresh Provider OAuth Token
|
// Refresh Provider OAuth Token
|
||||||
@@ -211,7 +211,7 @@ export default function piStatusbarExtension(pi: ExtensionAPI) {
|
|||||||
if (lastProvider === provider) rerender(ctx);
|
if (lastProvider === provider) rerender(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pi.on("session_start", async (_event: any, ctx: any) => {
|
pi.on("session_start", async (_event: SessionStartEvent, ctx: ExtensionContext) => {
|
||||||
updateThinkingLevel();
|
updateThinkingLevel();
|
||||||
installFooter(ctx);
|
installFooter(ctx);
|
||||||
await refresh(ctx, true);
|
await refresh(ctx, true);
|
||||||
@@ -220,7 +220,7 @@ export default function piStatusbarExtension(pi: ExtensionAPI) {
|
|||||||
timer = setInterval(() => void refresh(latestCtx ?? ctx), REFRESH_MS);
|
timer = setInterval(() => void refresh(latestCtx ?? ctx), REFRESH_MS);
|
||||||
});
|
});
|
||||||
|
|
||||||
pi.on("session_shutdown", async (_event: any, ctx: any) => {
|
pi.on("session_shutdown", async (_event: SessionShutdownEvent, ctx: ExtensionContext) => {
|
||||||
if (timer) clearInterval(timer);
|
if (timer) clearInterval(timer);
|
||||||
timer = undefined;
|
timer = undefined;
|
||||||
inFlight?.abort();
|
inFlight?.abort();
|
||||||
@@ -232,24 +232,24 @@ export default function piStatusbarExtension(pi: ExtensionAPI) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
pi.on("model_select", async (_event: any, ctx: any) => {
|
pi.on("model_select", async (_event, ctx) => {
|
||||||
updateThinkingLevel();
|
updateThinkingLevel();
|
||||||
await refresh(ctx, true);
|
await refresh(ctx, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
pi.on("thinking_level_select", async (event: any, ctx: any) => {
|
pi.on("thinking_level_select", async (event, ctx) => {
|
||||||
statusbarState.thinkingLevel = event.level;
|
statusbarState.thinkingLevel = event.level;
|
||||||
rerender(ctx);
|
rerender(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
pi.on("agent_end", async (_event: any, ctx: any) => {
|
pi.on("agent_end", async (_event: AgentEndEvent, ctx: ExtensionContext) => {
|
||||||
updateThinkingLevel();
|
updateThinkingLevel();
|
||||||
await refresh(ctx);
|
await refresh(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
pi.registerCommand("refresh-usage", {
|
pi.registerCommand("refresh-usage", {
|
||||||
description: "Refresh account usage for the active provider",
|
description: "Refresh account usage for the active provider",
|
||||||
handler: async (_args: any, ctx: any) => {
|
handler: async (_args: string, ctx: ExtensionCommandContext) => {
|
||||||
await refresh(ctx, true);
|
await refresh(ctx, true);
|
||||||
ctx.ui.notify(usageSummary(statusbarState.report, statusbarState.error), statusbarState.error ? "warning" : "info");
|
ctx.ui.notify(usageSummary(statusbarState.report, statusbarState.error), statusbarState.error ? "warning" : "info");
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user