fix(types): restore npm run check
pi-coding-agent 0.84 no longer exports AuthStorage, so the named import failed to compile even though the call site already guarded for its absence. Read it off the module namespace instead, keeping the auth-file fallback when the export is missing. Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
This commit is contained in:
co-authored by
Simon Shi
parent
70fba627e6
commit
e98526a8cd
+13
-2
@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import type { OAuthCredentials, OAuthLoginCallbacks } from "@earendil-works/pi-ai";
|
||||
import { AuthStorage } from "@earendil-works/pi-coding-agent";
|
||||
import * as PiCodingAgent from "@earendil-works/pi-coding-agent";
|
||||
import { getMachineId, getQoderMode, getQoderRefreshURL, getQoderUserEmailFallback, isQoderCNMode } from "./cosy.js";
|
||||
import { interactiveLogin } from "./login.js";
|
||||
import { updateQoderModelsCache } from "./models.js";
|
||||
@@ -17,6 +17,17 @@ export interface QoderCredentials extends OAuthCredentials {
|
||||
|
||||
const AUTH_FILE = join(homedir(), ".pi", "agent", "auth.json");
|
||||
|
||||
/**
|
||||
* `AuthStorage` is not part of every pi-coding-agent release's public exports,
|
||||
* so it is read off the module namespace instead of imported by name: a missing
|
||||
* export must degrade to the auth-file fallback below, not break the build.
|
||||
*/
|
||||
const AuthStorage = (
|
||||
PiCodingAgent as unknown as {
|
||||
AuthStorage?: { create?: () => { set: (providerID: string, credentials: unknown) => void } };
|
||||
}
|
||||
).AuthStorage;
|
||||
|
||||
/** Return the PAT exposed through the environment for a provider mode. */
|
||||
export function getQoderPatForMode(mode: string): string {
|
||||
if (isQoderCNMode(mode)) {
|
||||
@@ -55,7 +66,7 @@ export async function autoLoginQoderFromEnvironment(providerID: string, mode: st
|
||||
// account's credentials.
|
||||
const credentials = await credentialsFromPat(pat, mode);
|
||||
|
||||
if (typeof AuthStorage !== "undefined" && typeof AuthStorage?.create === "function") {
|
||||
if (typeof AuthStorage?.create === "function") {
|
||||
try {
|
||||
const authStorage = AuthStorage.create();
|
||||
authStorage.set(providerID, { type: "oauth", ...credentials });
|
||||
|
||||
Reference in New Issue
Block a user