From e98526a8cd3f2b75ab7743c3184911244e0059b9 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 31 Aug 2026 15:57:26 +0000 Subject: [PATCH] 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 --- src/oauth.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/oauth.ts b/src/oauth.ts index 675081c..71432fb 100644 --- a/src/oauth.ts +++ b/src/oauth.ts @@ -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 });