mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-29 11:02:12 +03:00
chore: migrate to oxlint and oxfmt
Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
import { intro, note, outro, spinner } from "@clack/prompts";
|
||||
|
||||
import {
|
||||
ensureAuthProfileStore,
|
||||
upsertAuthProfile,
|
||||
} from "../agents/auth-profiles.js";
|
||||
import { ensureAuthProfileStore, upsertAuthProfile } from "../agents/auth-profiles.js";
|
||||
import { updateConfig } from "../commands/models/shared.js";
|
||||
import { applyAuthProfileConfig } from "../commands/onboard-auth.js";
|
||||
import { CONFIG_PATH_CLAWDBOT } from "../config/config.js";
|
||||
@@ -41,9 +38,7 @@ function parseJsonResponse<T>(value: unknown): T {
|
||||
return value as T;
|
||||
}
|
||||
|
||||
async function requestDeviceCode(params: {
|
||||
scope: string;
|
||||
}): Promise<DeviceCodeResponse> {
|
||||
async function requestDeviceCode(params: { scope: string }): Promise<DeviceCodeResponse> {
|
||||
const body = new URLSearchParams({
|
||||
client_id: CLIENT_ID,
|
||||
scope: params.scope,
|
||||
@@ -148,9 +143,7 @@ export async function githubCopilotLoginCommand(
|
||||
spin.stop("Device code ready");
|
||||
|
||||
note(
|
||||
[`Visit: ${device.verification_uri}`, `Code: ${device.user_code}`].join(
|
||||
"\n",
|
||||
),
|
||||
[`Visit: ${device.verification_uri}`, `Code: ${device.user_code}`].join("\n"),
|
||||
stylePromptTitle("Authorize"),
|
||||
);
|
||||
|
||||
|
||||
@@ -20,9 +20,7 @@ export function getDefaultCopilotModelIds(): string[] {
|
||||
return [...DEFAULT_MODEL_IDS];
|
||||
}
|
||||
|
||||
export function buildCopilotModelDefinition(
|
||||
modelId: string,
|
||||
): ModelDefinitionConfig {
|
||||
export function buildCopilotModelDefinition(modelId: string): ModelDefinitionConfig {
|
||||
const id = modelId.trim();
|
||||
if (!id) throw new Error("Model id required");
|
||||
return {
|
||||
|
||||
@@ -15,16 +15,14 @@ vi.mock("../config/paths.js", () => ({
|
||||
|
||||
describe("github-copilot token", () => {
|
||||
it("derives baseUrl from token", async () => {
|
||||
const { deriveCopilotApiBaseUrlFromToken } = await import(
|
||||
"./github-copilot-token.js"
|
||||
);
|
||||
const { deriveCopilotApiBaseUrlFromToken } = await import("./github-copilot-token.js");
|
||||
|
||||
expect(
|
||||
deriveCopilotApiBaseUrlFromToken("token;proxy-ep=proxy.example.com;"),
|
||||
).toBe("https://api.example.com");
|
||||
expect(
|
||||
deriveCopilotApiBaseUrlFromToken("token;proxy-ep=https://proxy.foo.bar;"),
|
||||
).toBe("https://api.foo.bar");
|
||||
expect(deriveCopilotApiBaseUrlFromToken("token;proxy-ep=proxy.example.com;")).toBe(
|
||||
"https://api.example.com",
|
||||
);
|
||||
expect(deriveCopilotApiBaseUrlFromToken("token;proxy-ep=https://proxy.foo.bar;")).toBe(
|
||||
"https://api.foo.bar",
|
||||
);
|
||||
});
|
||||
|
||||
it("uses cache when token is still valid", async () => {
|
||||
@@ -35,9 +33,7 @@ describe("github-copilot token", () => {
|
||||
updatedAt: now,
|
||||
});
|
||||
|
||||
const { resolveCopilotApiToken } = await import(
|
||||
"./github-copilot-token.js"
|
||||
);
|
||||
const { resolveCopilotApiToken } = await import("./github-copilot-token.js");
|
||||
|
||||
const fetchImpl = vi.fn();
|
||||
const res = await resolveCopilotApiToken({
|
||||
@@ -63,9 +59,7 @@ describe("github-copilot token", () => {
|
||||
}),
|
||||
});
|
||||
|
||||
const { resolveCopilotApiToken } = await import(
|
||||
"./github-copilot-token.js"
|
||||
);
|
||||
const { resolveCopilotApiToken } = await import("./github-copilot-token.js");
|
||||
|
||||
const res = await resolveCopilotApiToken({
|
||||
githubToken: "gh",
|
||||
|
||||
@@ -14,11 +14,7 @@ export type CachedCopilotToken = {
|
||||
};
|
||||
|
||||
function resolveCopilotTokenCachePath(env: NodeJS.ProcessEnv = process.env) {
|
||||
return path.join(
|
||||
resolveStateDir(env),
|
||||
"credentials",
|
||||
"github-copilot.token.json",
|
||||
);
|
||||
return path.join(resolveStateDir(env), "credentials", "github-copilot.token.json");
|
||||
}
|
||||
|
||||
function isTokenUsable(cache: CachedCopilotToken, now = Date.now()): boolean {
|
||||
@@ -57,8 +53,7 @@ function parseCopilotTokenResponse(value: unknown): {
|
||||
return { token, expiresAt: expiresAtMs };
|
||||
}
|
||||
|
||||
export const DEFAULT_COPILOT_API_BASE_URL =
|
||||
"https://api.individual.githubcopilot.com";
|
||||
export const DEFAULT_COPILOT_API_BASE_URL = "https://api.individual.githubcopilot.com";
|
||||
|
||||
export function deriveCopilotApiBaseUrlFromToken(token: string): string | null {
|
||||
const trimmed = token.trim();
|
||||
@@ -91,19 +86,13 @@ export async function resolveCopilotApiToken(params: {
|
||||
const env = params.env ?? process.env;
|
||||
const cachePath = resolveCopilotTokenCachePath(env);
|
||||
const cached = loadJsonFile(cachePath) as CachedCopilotToken | undefined;
|
||||
if (
|
||||
cached &&
|
||||
typeof cached.token === "string" &&
|
||||
typeof cached.expiresAt === "number"
|
||||
) {
|
||||
if (cached && typeof cached.token === "string" && typeof cached.expiresAt === "number") {
|
||||
if (isTokenUsable(cached)) {
|
||||
return {
|
||||
token: cached.token,
|
||||
expiresAt: cached.expiresAt,
|
||||
source: `cache:${cachePath}`,
|
||||
baseUrl:
|
||||
deriveCopilotApiBaseUrlFromToken(cached.token) ??
|
||||
DEFAULT_COPILOT_API_BASE_URL,
|
||||
baseUrl: deriveCopilotApiBaseUrlFromToken(cached.token) ?? DEFAULT_COPILOT_API_BASE_URL,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -133,8 +122,6 @@ export async function resolveCopilotApiToken(params: {
|
||||
token: payload.token,
|
||||
expiresAt: payload.expiresAt,
|
||||
source: `fetched:${COPILOT_TOKEN_URL}`,
|
||||
baseUrl:
|
||||
deriveCopilotApiBaseUrlFromToken(payload.token) ??
|
||||
DEFAULT_COPILOT_API_BASE_URL,
|
||||
baseUrl: deriveCopilotApiBaseUrlFromToken(payload.token) ?? DEFAULT_COPILOT_API_BASE_URL,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -108,8 +108,7 @@ describe("google-shared convertTools", () => {
|
||||
expect(contents[1].role).toBe("model");
|
||||
expect(contents[2].role).toBe("model");
|
||||
const toolCallPart = contents[2].parts?.find(
|
||||
(part) =>
|
||||
typeof part === "object" && part !== null && "functionCall" in part,
|
||||
(part) => typeof part === "object" && part !== null && "functionCall" in part,
|
||||
);
|
||||
const toolCall = asRecord(toolCallPart);
|
||||
expect(toolCall.functionCall).toBeTruthy();
|
||||
@@ -167,12 +166,10 @@ describe("google-shared convertTools", () => {
|
||||
const contents = convertMessages(model, context);
|
||||
const parts = contents.flatMap((content) => content.parts ?? []);
|
||||
const toolCallPart = parts.find(
|
||||
(part) =>
|
||||
typeof part === "object" && part !== null && "functionCall" in part,
|
||||
(part) => typeof part === "object" && part !== null && "functionCall" in part,
|
||||
);
|
||||
const toolResponsePart = parts.find(
|
||||
(part) =>
|
||||
typeof part === "object" && part !== null && "functionResponse" in part,
|
||||
(part) => typeof part === "object" && part !== null && "functionResponse" in part,
|
||||
);
|
||||
|
||||
const toolCall = asRecord(toolCallPart);
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
convertMessages,
|
||||
convertTools,
|
||||
} from "@mariozechner/pi-ai/dist/providers/google-shared.js";
|
||||
import { convertMessages, convertTools } from "@mariozechner/pi-ai/dist/providers/google-shared.js";
|
||||
import type { Context, Model, Tool } from "@mariozechner/pi-ai/dist/types.js";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
@@ -56,9 +53,7 @@ describe("google-shared convertTools", () => {
|
||||
] as unknown as Tool[];
|
||||
|
||||
const converted = convertTools(tools);
|
||||
const params = asRecord(
|
||||
converted?.[0]?.functionDeclarations?.[0]?.parameters,
|
||||
);
|
||||
const params = asRecord(converted?.[0]?.functionDeclarations?.[0]?.parameters);
|
||||
|
||||
expect(params.type).toBeUndefined();
|
||||
expect(params.properties).toBeDefined();
|
||||
@@ -98,9 +93,7 @@ describe("google-shared convertTools", () => {
|
||||
] as unknown as Tool[];
|
||||
|
||||
const converted = convertTools(tools);
|
||||
const params = asRecord(
|
||||
converted?.[0]?.functionDeclarations?.[0]?.parameters,
|
||||
);
|
||||
const params = asRecord(converted?.[0]?.functionDeclarations?.[0]?.parameters);
|
||||
const properties = asRecord(params.properties);
|
||||
const mode = asRecord(properties.mode);
|
||||
const options = asRecord(properties.options);
|
||||
@@ -141,9 +134,7 @@ describe("google-shared convertTools", () => {
|
||||
] as unknown as Tool[];
|
||||
|
||||
const converted = convertTools(tools);
|
||||
const params = asRecord(
|
||||
converted?.[0]?.functionDeclarations?.[0]?.parameters,
|
||||
);
|
||||
const params = asRecord(converted?.[0]?.functionDeclarations?.[0]?.parameters);
|
||||
const config = asRecord(asRecord(params.properties).config);
|
||||
const configProps = asRecord(config.properties);
|
||||
const retries = asRecord(configProps.retries);
|
||||
@@ -423,8 +414,7 @@ describe("google-shared convertMessages", () => {
|
||||
expect(contents[2].role).toBe("user");
|
||||
expect(contents[3].role).toBe("user");
|
||||
const toolResponsePart = contents[2].parts?.find(
|
||||
(part) =>
|
||||
typeof part === "object" && part !== null && "functionResponse" in part,
|
||||
(part) => typeof part === "object" && part !== null && "functionResponse" in part,
|
||||
);
|
||||
const toolResponse = asRecord(toolResponsePart);
|
||||
expect(toolResponse.functionResponse).toBeTruthy();
|
||||
|
||||
Reference in New Issue
Block a user