fix: route PAT login through pi LoginDialog callbacks
The custom ctx.ui.custom login menu stole focus from pi's built-in LoginDialog, so onPrompt never received keystrokes and PAT login silently failed with 'No API key found'. Drive login via the provided onPrompt/onAuth/onProgress callbacks instead, and drop login-ui.ts and the now-unused pi-tui dependency. Also clears remaining lint warnings by removing any-casts in models/oauth/stream/transform.
This commit is contained in:
+28
-26
@@ -1,39 +1,41 @@
|
||||
import type { Api, Model, OAuthCredentials } from "@earendil-works/pi-ai";
|
||||
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
||||
import { setExtensionContext } from "./login-ui.js";
|
||||
import type { ExtensionAPI, ProviderConfig } from "@earendil-works/pi-coding-agent";
|
||||
import { getCachedModels, staticModels } from "./models.js";
|
||||
import { loginQoder, refreshQoderToken } from "./oauth.js";
|
||||
import { streamQoder } from "./stream.js";
|
||||
import { fetchQoderUsage } from "./usage.js";
|
||||
|
||||
// pi supports a `fetchUsage` hook on the oauth config at runtime, but it is not
|
||||
// part of the published ProviderConfig type. Declare the extension locally.
|
||||
type OAuthConfigWithUsage = NonNullable<ProviderConfig["oauth"]> & {
|
||||
fetchUsage: typeof fetchQoderUsage;
|
||||
};
|
||||
|
||||
export default function (pi: ExtensionAPI) {
|
||||
// Capture ctx for custom TUI login components
|
||||
pi.on("session_start", async (_event, ctx) => {
|
||||
setExtensionContext(ctx);
|
||||
});
|
||||
const oauth: OAuthConfigWithUsage = {
|
||||
name: "Qoder (Browser OAuth / PAT)",
|
||||
login: loginQoder,
|
||||
refreshToken: refreshQoderToken,
|
||||
getApiKey: (cred: OAuthCredentials) => cred.access,
|
||||
modifyModels: (models: Model<Api>[], _cred: OAuthCredentials) => {
|
||||
const cached = getCachedModels();
|
||||
const nonQoder = models.filter((m: Model<Api>) => m.provider !== "qoder");
|
||||
const modelsToUse = cached.length > 0 ? cached : staticModels;
|
||||
const modifiedQoder = modelsToUse.map((m) => ({
|
||||
...m,
|
||||
baseUrl: "https://api3.qoder.sh/",
|
||||
})) as Model<Api>[];
|
||||
|
||||
return [...nonQoder, ...modifiedQoder];
|
||||
},
|
||||
fetchUsage: fetchQoderUsage,
|
||||
};
|
||||
|
||||
pi.registerProvider("qoder", {
|
||||
baseUrl: "https://api3.qoder.sh/",
|
||||
api: "qoder-api" as any,
|
||||
models: getCachedModels(),
|
||||
oauth: {
|
||||
name: "Qoder (Browser OAuth / PAT)",
|
||||
login: loginQoder,
|
||||
refreshToken: refreshQoderToken,
|
||||
getApiKey: (cred: OAuthCredentials) => cred.access,
|
||||
modifyModels: (models: Model<Api>[], cred: OAuthCredentials) => {
|
||||
const cached = getCachedModels();
|
||||
const nonQoder = models.filter((m: Model<Api>) => m.provider !== "qoder");
|
||||
const modelsToUse = cached.length > 0 ? cached : staticModels;
|
||||
const modifiedQoder = modelsToUse.map((m: Model<Api>) => ({
|
||||
...m,
|
||||
baseUrl: "https://api3.qoder.sh/",
|
||||
}));
|
||||
|
||||
return [...nonQoder, ...modifiedQoder];
|
||||
},
|
||||
fetchUsage: fetchQoderUsage,
|
||||
} as any,
|
||||
api: "qoder-api" as Api,
|
||||
models: getCachedModels() as unknown as ProviderConfig["models"],
|
||||
oauth: oauth as ProviderConfig["oauth"],
|
||||
streamSimple: streamQoder,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user