Merge branch 'main' of github.com:getpaseo/paseo
This commit is contained in:
@@ -24,6 +24,7 @@ const KimiAuthSchema = z.object({
|
|||||||
interface KimiQuotaProviderOptions {
|
interface KimiQuotaProviderOptions {
|
||||||
logger: Logger;
|
logger: Logger;
|
||||||
fetch?: ProviderApiFetch;
|
fetch?: ProviderApiFetch;
|
||||||
|
homeDir?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class KimiQuotaProvider implements ProviderUsageFetcher {
|
export class KimiQuotaProvider implements ProviderUsageFetcher {
|
||||||
@@ -32,10 +33,12 @@ export class KimiQuotaProvider implements ProviderUsageFetcher {
|
|||||||
|
|
||||||
private readonly logger: Logger;
|
private readonly logger: Logger;
|
||||||
private readonly fetchApi: ProviderApiFetch;
|
private readonly fetchApi: ProviderApiFetch;
|
||||||
|
private readonly homeDir?: string;
|
||||||
|
|
||||||
constructor(options: KimiQuotaProviderOptions) {
|
constructor(options: KimiQuotaProviderOptions) {
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
this.fetchApi = options.fetch ?? fetch;
|
this.fetchApi = options.fetch ?? fetch;
|
||||||
|
this.homeDir = options.homeDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchUsage(): Promise<ProviderUsage> {
|
async fetchUsage(): Promise<ProviderUsage> {
|
||||||
@@ -88,13 +91,14 @@ export class KimiQuotaProvider implements ProviderUsageFetcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async readKimiToken(): Promise<string | null> {
|
private async readKimiToken(): Promise<string | null> {
|
||||||
|
const homeDir = this.homeDir ?? homedir();
|
||||||
const paths = [
|
const paths = [
|
||||||
join(
|
join(
|
||||||
process.env["KIMI_CODE_HOME"] || join(homedir(), ".kimi-code"),
|
process.env["KIMI_CODE_HOME"] || join(homeDir, ".kimi-code"),
|
||||||
"credentials",
|
"credentials",
|
||||||
"kimi-code.json",
|
"kimi-code.json",
|
||||||
),
|
),
|
||||||
join(homedir(), ".kimi", "credentials", "kimi-code.json"),
|
join(homeDir, ".kimi", "credentials", "kimi-code.json"),
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const path of paths) {
|
for (const path of paths) {
|
||||||
|
|||||||
@@ -335,7 +335,11 @@ describe("real provider usage fetchers", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function service(
|
function service(
|
||||||
options: { platform?: typeof process.platform; keychain?: () => Promise<unknown | null> } = {},
|
options: {
|
||||||
|
platform?: typeof process.platform;
|
||||||
|
keychain?: () => Promise<unknown | null>;
|
||||||
|
kimiHomeDir?: string;
|
||||||
|
} = {},
|
||||||
) {
|
) {
|
||||||
const logger = createLogger();
|
const logger = createLogger();
|
||||||
const fetchThroughTestDouble = ((url: RequestInfo | URL, init?: RequestInit) =>
|
const fetchThroughTestDouble = ((url: RequestInfo | URL, init?: RequestInit) =>
|
||||||
@@ -356,7 +360,11 @@ describe("real provider usage fetchers", () => {
|
|||||||
new CursorQuotaProvider({ logger, fetch: fetchThroughTestDouble }),
|
new CursorQuotaProvider({ logger, fetch: fetchThroughTestDouble }),
|
||||||
new ZaiQuotaProvider({ logger, fetch: fetchThroughTestDouble }),
|
new ZaiQuotaProvider({ logger, fetch: fetchThroughTestDouble }),
|
||||||
new GrokQuotaProvider({ logger, fetch: fetchThroughTestDouble }),
|
new GrokQuotaProvider({ logger, fetch: fetchThroughTestDouble }),
|
||||||
new KimiQuotaProvider({ logger, fetch: fetchThroughTestDouble }),
|
new KimiQuotaProvider({
|
||||||
|
logger,
|
||||||
|
fetch: fetchThroughTestDouble,
|
||||||
|
homeDir: options.kimiHomeDir,
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
cacheTtlMs: 0,
|
cacheTtlMs: 0,
|
||||||
});
|
});
|
||||||
@@ -712,11 +720,11 @@ describe("real provider usage fetchers", () => {
|
|||||||
|
|
||||||
it("fetches Kimi usage from the CLI credential home", async () => {
|
it("fetches Kimi usage from the CLI credential home", async () => {
|
||||||
writeKimiCredentials(join(homeDir, ".kimi-code"), "kimi_cli_token");
|
writeKimiCredentials(join(homeDir, ".kimi-code"), "kimi_cli_token");
|
||||||
fetchApi = vi.fn(async (url: RequestInfo | URL, init?: RequestInit) => {
|
let requestedUrl: string | null = null;
|
||||||
expect(url.toString()).toBe("https://api.kimi.com/coding/v1/usages");
|
let authorization: string | null = null;
|
||||||
expect((init?.headers as Record<string, string> | undefined)?.Authorization).toBe(
|
fetchApi = (async (url: RequestInfo | URL, init?: RequestInit) => {
|
||||||
"Bearer kimi_cli_token",
|
requestedUrl = url.toString();
|
||||||
);
|
authorization = (init?.headers as Record<string, string> | undefined)?.Authorization ?? null;
|
||||||
return jsonResponse({
|
return jsonResponse({
|
||||||
usage: {
|
usage: {
|
||||||
limit: "200",
|
limit: "200",
|
||||||
@@ -726,8 +734,10 @@ describe("real provider usage fetchers", () => {
|
|||||||
});
|
});
|
||||||
}) as unknown as typeof fetch;
|
}) as unknown as typeof fetch;
|
||||||
|
|
||||||
const kimi = findProvider(await service().listUsage(), "kimi");
|
const kimi = findProvider(await service({ kimiHomeDir: homeDir }).listUsage(), "kimi");
|
||||||
|
|
||||||
|
expect(requestedUrl).toBe("https://api.kimi.com/coding/v1/usages");
|
||||||
|
expect(authorization).toBe("Bearer kimi_cli_token");
|
||||||
expect(kimi).toMatchObject({
|
expect(kimi).toMatchObject({
|
||||||
status: "available",
|
status: "available",
|
||||||
windows: [
|
windows: [
|
||||||
|
|||||||
Reference in New Issue
Block a user