diff --git a/src/__tests__/oauth.test.ts b/src/__tests__/oauth.test.ts index b7643b3..8685bd5 100644 --- a/src/__tests__/oauth.test.ts +++ b/src/__tests__/oauth.test.ts @@ -2,9 +2,9 @@ import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { homedir } from "node:os"; import { join } from "node:path"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; -import { updateQoderModelsCache } from "../catalog.js"; import { autoLoginQoderFromEnvironment, getCachedCredentials, getQoderPatForMode } from "../auth/oauth.js"; import { credentialsFromPat } from "../auth/pat.js"; +import { updateQoderModelsCache } from "../catalog.js"; import { loadLiveFixture } from "./live-fixture.js"; const AUTH_FILE = join(homedir(), ".pi", "agent", "auth.json"); diff --git a/src/auth/login.ts b/src/auth/login.ts index 9ef066a..27e430a 100644 --- a/src/auth/login.ts +++ b/src/auth/login.ts @@ -43,10 +43,7 @@ function parseExpiresAt(s?: string, expiresInSeconds?: number): number { return Date.now() + 30 * 24 * 60 * 60 * 1000; // default 30 days } -export async function interactiveLogin( - callbacks: OAuthLoginCallbacks, - mode: QoderMode, -): Promise { +export async function interactiveLogin(callbacks: OAuthLoginCallbacks, mode: QoderMode): Promise { const region = getQoderRegionConfig(mode); // pi drives this via its built-in LoginDialog, which wires onPrompt/onAuth/ // onProgress to a focused input. We must use those callbacks directly rather diff --git a/src/auth/oauth.ts b/src/auth/oauth.ts index a423199..448722e 100644 --- a/src/auth/oauth.ts +++ b/src/auth/oauth.ts @@ -3,8 +3,8 @@ import { homedir } from "node:os"; import { dirname, join } from "node:path"; import type { OAuthCredentials, OAuthLoginCallbacks } from "@earendil-works/pi-ai"; import * as PiCodingAgent from "@earendil-works/pi-coding-agent"; -import { getMachineId } from "../cosy.js"; import { updateQoderModelsCache } from "../catalog.js"; +import { getMachineId } from "../cosy.js"; import { getQoderRefreshURL, getQoderRegionConfig, type QoderMode } from "../region.js"; import { interactiveLogin } from "./login.js"; import { credentialsFromPat, decodePatRefresh, fetchUserInfo, isPatRefresh } from "./pat.js"; diff --git a/src/auth/pat.ts b/src/auth/pat.ts index 8f62183..c764fff 100644 --- a/src/auth/pat.ts +++ b/src/auth/pat.ts @@ -1,11 +1,6 @@ import type { OAuthCredentials } from "@earendil-works/pi-ai"; import { getMachineId, QODER_CLIENT_TYPE, QODER_OPENAPI_COSY_VERSION } from "../cosy.js"; -import { - getQoderExchangeURL, - getQoderRegionConfig, - getQoderUserInfoURL, - type QoderMode, -} from "../region.js"; +import { getQoderExchangeURL, getQoderRegionConfig, getQoderUserInfoURL, type QoderMode } from "../region.js"; const UA = "pi-provider-qoder"; diff --git a/src/catalog.ts b/src/catalog.ts index 966d571..174c23f 100644 --- a/src/catalog.ts +++ b/src/catalog.ts @@ -3,12 +3,7 @@ import { homedir } from "node:os"; import { dirname, join } from "node:path"; import type { ThinkingLevel, ThinkingLevelMap } from "@earendil-works/pi-ai"; import { buildAuthHeaders } from "./cosy.js"; -import { - getQoderBaseUrl, - getQoderModelListURL, - getQoderRegionConfig, - type QoderMode, -} from "./region.js"; +import { getQoderBaseUrl, getQoderModelListURL, getQoderRegionConfig, type QoderMode } from "./region.js"; export const ZERO_COST = Object.freeze({ input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }); @@ -525,9 +520,7 @@ export function getCachedModelConfig(modelId: string, mode: QoderMode): QoderMod // Read old cache shapes without preserving their raw-key aliases. const legacyEntry = Object.values(data?.configs || {}).find( (entry) => - entry && - typeof entry === "object" && - toQoderModelId((entry as QoderModelEntry).display_name) === modelId, + entry && typeof entry === "object" && toQoderModelId((entry as QoderModelEntry).display_name) === modelId, ) as QoderModelEntry | undefined; if (legacyEntry) { return withMaxContextAsDefault(legacyEntry); diff --git a/src/index.ts b/src/index.ts index b792dd8..1dbe4a1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,15 @@ import type { Api, Model, OAuthCredentials } from "@earendil-works/pi-ai"; import type { ExtensionAPI, ProviderConfig } from "@earendil-works/pi-coding-agent"; -import { getCachedModels, isCacheStale, staticCnModels, staticModels, updateQoderModelsCache } from "./catalog.js"; -import { getQoderBaseUrl, getQoderRegionConfig, QODER_MODES, type QoderMode } from "./region.js"; import { autoLoginQoderFromEnvironment, getCachedCredentials, loginQoderForMode, refreshQoderTokenForMode, } from "./auth/oauth.js"; -import { streamQoder } from "./protocol/stream.js"; import { fetchQoderUsageForMode } from "./auth/usage.js"; +import { getCachedModels, isCacheStale, staticCnModels, staticModels, updateQoderModelsCache } from "./catalog.js"; +import { streamQoder } from "./protocol/stream.js"; +import { getQoderBaseUrl, getQoderRegionConfig, QODER_MODES, type QoderMode } from "./region.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. diff --git a/src/protocol/stream.ts b/src/protocol/stream.ts index bcc9997..2dfadc8 100644 --- a/src/protocol/stream.ts +++ b/src/protocol/stream.ts @@ -12,9 +12,9 @@ import { type ThinkingContent, type ToolCall, } from "@earendil-works/pi-ai"; -import { buildAuthHeaders, getMachineId } from "../cosy.js"; -import { getCachedModelConfig, MAX_OUTPUT_TOKENS } from "../catalog.js"; import { resolveQoderIdentity } from "../auth/oauth.js"; +import { getCachedModelConfig, MAX_OUTPUT_TOKENS } from "../catalog.js"; +import { buildAuthHeaders, getMachineId } from "../cosy.js"; import { getQoderChatURL, getQoderRegionConfig } from "../region.js"; import { qoderEncodeBody } from "./encoding.js"; import { stripThinkingTags, ThinkingTagParser } from "./thinking.js";