refactor: type ModuleContext and index.ts functions with SDK types
This commit is contained in:
14
index.ts
14
index.ts
@@ -1,4 +1,4 @@
|
||||
import { AuthStorage, type AuthCredential, type ExtensionAPI, type ExtensionContext, type ExtensionCommandContext, type SessionStartEvent, type SessionShutdownEvent, type AgentEndEvent } from "@mariozechner/pi-coding-agent";
|
||||
import { AuthStorage, type AuthCredential, type ExtensionAPI, type ExtensionContext, type ExtensionCommandContext, type ReadonlyFooterDataProvider, type SessionStartEvent, type SessionShutdownEvent, type AgentEndEvent } from "@mariozechner/pi-coding-agent";
|
||||
import { statusbarConfig } from "./config";
|
||||
import { contextModule, costModule, directoryModule, modelModule, thinkingModule } from "./modules/basic";
|
||||
import { usageModule } from "./modules/usage";
|
||||
@@ -21,7 +21,7 @@ function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function activeProvider(ctx: any): Provider | undefined {
|
||||
function activeProvider(ctx: ExtensionContext): Provider | undefined {
|
||||
const provider = ctx.model?.provider as string | undefined;
|
||||
if (provider === "openai-codex" || provider === "zai" || provider === "anthropic") return provider;
|
||||
return undefined;
|
||||
@@ -91,7 +91,7 @@ function renderModule(moduleCtx: ModuleContext, spec: ModuleSpec): RenderedModul
|
||||
}
|
||||
}
|
||||
|
||||
function renderFooter(ctx: any, footerData: any, state: StatusbarState, width: number, theme?: any): string[] {
|
||||
function renderFooter(ctx: ExtensionContext, footerData: ReadonlyFooterDataProvider, state: StatusbarState, width: number, theme?: any): string[] {
|
||||
const moduleCtx: ModuleContext = { ctx, footerData, state, config: statusbarConfig };
|
||||
return statusbarConfig.rows.map(row => renderRow({
|
||||
left: (row.left ?? []).map(spec => renderModule(moduleCtx, spec)),
|
||||
@@ -110,7 +110,7 @@ export default function piStatusbarExtension(pi: ExtensionAPI) {
|
||||
let timer: ReturnType<typeof setInterval> | undefined;
|
||||
let inFlight: AbortController | undefined;
|
||||
let lastProvider: Provider | undefined;
|
||||
let latestCtx: any;
|
||||
let latestCtx: ExtensionContext | undefined;
|
||||
let requestRender: (() => void) | undefined;
|
||||
const statusbarState: StatusbarState = {};
|
||||
const authStorage = AuthStorage.create();
|
||||
@@ -124,7 +124,7 @@ export default function piStatusbarExtension(pi: ExtensionAPI) {
|
||||
}
|
||||
|
||||
let rerenderScheduled = false;
|
||||
function rerender(ctx: any) {
|
||||
function rerender(ctx: ExtensionContext) {
|
||||
latestCtx = ctx;
|
||||
if (rerenderScheduled) return;
|
||||
rerenderScheduled = true;
|
||||
@@ -138,7 +138,7 @@ export default function piStatusbarExtension(pi: ExtensionAPI) {
|
||||
});
|
||||
}
|
||||
|
||||
function installFooter(ctx: any) {
|
||||
function installFooter(ctx: ExtensionContext) {
|
||||
if (!ctx.hasUI) return;
|
||||
latestCtx = ctx;
|
||||
ctx.ui.setFooter((tui: any, theme: any, footerData: any) => {
|
||||
@@ -155,7 +155,7 @@ export default function piStatusbarExtension(pi: ExtensionAPI) {
|
||||
});
|
||||
}
|
||||
|
||||
async function refresh(ctx: any, force = false) {
|
||||
async function refresh(ctx: ExtensionContext, force = false) {
|
||||
latestCtx = ctx;
|
||||
const provider = activeProvider(ctx);
|
||||
lastProvider = provider;
|
||||
|
||||
5
types.ts
5
types.ts
@@ -1,3 +1,4 @@
|
||||
import type { ExtensionContext, ReadonlyFooterDataProvider } from "@mariozechner/pi-coding-agent";
|
||||
import type { UsageLimit, UsageReport } from "./usage";
|
||||
|
||||
export type ModuleName = "directory" | "context" | "model" | "thinking" | "cost" | "usage";
|
||||
@@ -40,8 +41,8 @@ export interface StatusbarState {
|
||||
}
|
||||
|
||||
export interface ModuleContext {
|
||||
ctx: any;
|
||||
footerData: any;
|
||||
ctx: ExtensionContext;
|
||||
footerData: ReadonlyFooterDataProvider;
|
||||
state: StatusbarState;
|
||||
config: StatusbarConfig;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user