mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 14:28:27 +00:00
chore: migrate to oxlint and oxfmt
Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
@@ -124,11 +124,7 @@ export function buildBootstrapContextFiles(
|
||||
});
|
||||
continue;
|
||||
}
|
||||
const trimmed = trimBootstrapContent(
|
||||
file.content ?? "",
|
||||
file.name,
|
||||
maxChars,
|
||||
);
|
||||
const trimmed = trimBootstrapContent(file.content ?? "", file.name, maxChars);
|
||||
if (!trimmed.content) continue;
|
||||
if (trimmed.truncated) {
|
||||
opts?.warn?.(
|
||||
@@ -143,13 +139,9 @@ export function buildBootstrapContextFiles(
|
||||
return result;
|
||||
}
|
||||
|
||||
export function sanitizeGoogleTurnOrdering(
|
||||
messages: AgentMessage[],
|
||||
): AgentMessage[] {
|
||||
export function sanitizeGoogleTurnOrdering(messages: AgentMessage[]): AgentMessage[] {
|
||||
const GOOGLE_TURN_ORDER_BOOTSTRAP_TEXT = "(session bootstrap)";
|
||||
const first = messages[0] as
|
||||
| { role?: unknown; content?: unknown }
|
||||
| undefined;
|
||||
const first = messages[0] as { role?: unknown; content?: unknown } | undefined;
|
||||
const role = first?.role;
|
||||
const content = first?.content;
|
||||
if (
|
||||
|
||||
@@ -40,9 +40,7 @@ export function formatAssistantErrorText(
|
||||
|
||||
const unknownTool =
|
||||
raw.match(/unknown tool[:\s]+["']?([a-z0-9_-]+)["']?/i) ??
|
||||
raw.match(
|
||||
/tool\s+["']?([a-z0-9_-]+)["']?\s+(?:not found|is not available)/i,
|
||||
);
|
||||
raw.match(/tool\s+["']?([a-z0-9_-]+)["']?\s+(?:not found|is not available)/i);
|
||||
if (unknownTool?.[1]) {
|
||||
const rewritten = formatSandboxToolPolicyBlockedMessage({
|
||||
cfg: opts?.cfg,
|
||||
@@ -66,9 +64,7 @@ export function formatAssistantErrorText(
|
||||
);
|
||||
}
|
||||
|
||||
const invalidRequest = raw.match(
|
||||
/"type":"invalid_request_error".*?"message":"([^"]+)"/,
|
||||
);
|
||||
const invalidRequest = raw.match(/"type":"invalid_request_error".*?"message":"([^"]+)"/);
|
||||
if (invalidRequest?.[1]) {
|
||||
return `LLM request rejected: ${invalidRequest[1]}`;
|
||||
}
|
||||
@@ -80,9 +76,7 @@ export function formatAssistantErrorText(
|
||||
return raw.length > 600 ? `${raw.slice(0, 600)}…` : raw;
|
||||
}
|
||||
|
||||
export function isRateLimitAssistantError(
|
||||
msg: AssistantMessage | undefined,
|
||||
): boolean {
|
||||
export function isRateLimitAssistantError(msg: AssistantMessage | undefined): boolean {
|
||||
if (!msg || msg.stopReason !== "error") return false;
|
||||
return isRateLimitErrorMessage(msg.errorMessage ?? "");
|
||||
}
|
||||
@@ -98,16 +92,8 @@ const ERROR_PATTERNS = {
|
||||
"resource_exhausted",
|
||||
"usage limit",
|
||||
],
|
||||
overloaded: [
|
||||
/overloaded_error|"type"\s*:\s*"overloaded_error"/i,
|
||||
"overloaded",
|
||||
],
|
||||
timeout: [
|
||||
"timeout",
|
||||
"timed out",
|
||||
"deadline exceeded",
|
||||
"context deadline exceeded",
|
||||
],
|
||||
overloaded: [/overloaded_error|"type"\s*:\s*"overloaded_error"/i, "overloaded"],
|
||||
timeout: ["timeout", "timed out", "deadline exceeded", "context deadline exceeded"],
|
||||
billing: [
|
||||
/\b402\b/,
|
||||
"payment required",
|
||||
@@ -140,10 +126,7 @@ const ERROR_PATTERNS = {
|
||||
],
|
||||
} as const;
|
||||
|
||||
function matchesErrorPatterns(
|
||||
raw: string,
|
||||
patterns: readonly ErrorPattern[],
|
||||
): boolean {
|
||||
function matchesErrorPatterns(raw: string, patterns: readonly ErrorPattern[]): boolean {
|
||||
if (!raw) return false;
|
||||
const value = raw.toLowerCase();
|
||||
return patterns.some((pattern) =>
|
||||
@@ -172,9 +155,7 @@ export function isBillingErrorMessage(raw: string): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
export function isBillingAssistantError(
|
||||
msg: AssistantMessage | undefined,
|
||||
): boolean {
|
||||
export function isBillingAssistantError(msg: AssistantMessage | undefined): boolean {
|
||||
if (!msg || msg.stopReason !== "error") return false;
|
||||
return isBillingErrorMessage(msg.errorMessage ?? "");
|
||||
}
|
||||
@@ -191,9 +172,7 @@ export function isCloudCodeAssistFormatError(raw: string): boolean {
|
||||
return matchesErrorPatterns(raw, ERROR_PATTERNS.format);
|
||||
}
|
||||
|
||||
export function isAuthAssistantError(
|
||||
msg: AssistantMessage | undefined,
|
||||
): boolean {
|
||||
export function isAuthAssistantError(msg: AssistantMessage | undefined): boolean {
|
||||
if (!msg || msg.stopReason !== "error") return false;
|
||||
return isAuthErrorMessage(msg.errorMessage ?? "");
|
||||
}
|
||||
@@ -212,9 +191,7 @@ export function isFailoverErrorMessage(raw: string): boolean {
|
||||
return classifyFailoverReason(raw) !== null;
|
||||
}
|
||||
|
||||
export function isFailoverAssistantError(
|
||||
msg: AssistantMessage | undefined,
|
||||
): boolean {
|
||||
export function isFailoverAssistantError(msg: AssistantMessage | undefined): boolean {
|
||||
if (!msg || msg.stopReason !== "error") return false;
|
||||
return isFailoverErrorMessage(msg.errorMessage ?? "");
|
||||
}
|
||||
|
||||
@@ -4,9 +4,7 @@ import { sanitizeGoogleTurnOrdering } from "./bootstrap.js";
|
||||
|
||||
export function isGoogleModelApi(api?: string | null): boolean {
|
||||
return (
|
||||
api === "google-gemini-cli" ||
|
||||
api === "google-generative-ai" ||
|
||||
api === "google-antigravity"
|
||||
api === "google-gemini-cli" || api === "google-generative-ai" || api === "google-antigravity"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -28,9 +26,7 @@ type GeminiToolCallBlock = {
|
||||
input?: unknown;
|
||||
};
|
||||
|
||||
export function downgradeGeminiHistory(
|
||||
messages: AgentMessage[],
|
||||
): AgentMessage[] {
|
||||
export function downgradeGeminiHistory(messages: AgentMessage[]): AgentMessage[] {
|
||||
const downgradedIds = new Set<string>();
|
||||
const out: AgentMessage[] = [];
|
||||
|
||||
@@ -63,11 +59,7 @@ export function downgradeGeminiHistory(
|
||||
if (!block || typeof block !== "object") return block;
|
||||
const blockRecord = block as GeminiToolCallBlock;
|
||||
const type = blockRecord.type;
|
||||
if (
|
||||
type === "toolCall" ||
|
||||
type === "functionCall" ||
|
||||
type === "toolUse"
|
||||
) {
|
||||
if (type === "toolCall" || type === "functionCall" || type === "toolUse") {
|
||||
const hasSignature = Boolean(blockRecord.thought_signature);
|
||||
if (!hasSignature) {
|
||||
const id =
|
||||
@@ -83,15 +75,12 @@ export function downgradeGeminiHistory(
|
||||
? blockRecord.toolName
|
||||
: undefined;
|
||||
const args =
|
||||
blockRecord.arguments !== undefined
|
||||
? blockRecord.arguments
|
||||
: blockRecord.input;
|
||||
blockRecord.arguments !== undefined ? blockRecord.arguments : blockRecord.input;
|
||||
|
||||
if (id) downgradedIds.add(id);
|
||||
hasDowngraded = true;
|
||||
|
||||
const argsText =
|
||||
typeof args === "string" ? args : JSON.stringify(args, null, 2);
|
||||
const argsText = typeof args === "string" ? args : JSON.stringify(args, null, 2);
|
||||
|
||||
return {
|
||||
type: "text",
|
||||
@@ -104,11 +93,7 @@ export function downgradeGeminiHistory(
|
||||
return block;
|
||||
});
|
||||
|
||||
out.push(
|
||||
hasDowngraded
|
||||
? ({ ...assistantMsg, content: newContent } as AgentMessage)
|
||||
: msg,
|
||||
);
|
||||
out.push(hasDowngraded ? ({ ...assistantMsg, content: newContent } as AgentMessage) : msg);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import type {
|
||||
AgentMessage,
|
||||
AgentToolResult,
|
||||
} from "@mariozechner/pi-agent-core";
|
||||
import type { AgentMessage, AgentToolResult } from "@mariozechner/pi-agent-core";
|
||||
|
||||
import { sanitizeToolCallIdsForCloudCodeAssist } from "../tool-call-id.js";
|
||||
import { sanitizeContentBlocksImages } from "../tool-images.js";
|
||||
@@ -93,11 +90,7 @@ export async function sanitizeSessionMessagesImages(
|
||||
const block = filteredContent[i];
|
||||
if (!block || typeof block !== "object") continue;
|
||||
const type = (block as { type?: unknown }).type;
|
||||
if (
|
||||
type === "functionCall" ||
|
||||
type === "toolUse" ||
|
||||
type === "toolCall"
|
||||
) {
|
||||
if (type === "functionCall" || type === "toolUse" || type === "toolCall") {
|
||||
lastToolIndex = i;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -21,27 +21,16 @@ export function isMessagingToolDuplicateNormalized(
|
||||
normalizedSentTexts: string[],
|
||||
): boolean {
|
||||
if (normalizedSentTexts.length === 0) return false;
|
||||
if (!normalized || normalized.length < MIN_DUPLICATE_TEXT_LENGTH)
|
||||
return false;
|
||||
if (!normalized || normalized.length < MIN_DUPLICATE_TEXT_LENGTH) return false;
|
||||
return normalizedSentTexts.some((normalizedSent) => {
|
||||
if (!normalizedSent || normalizedSent.length < MIN_DUPLICATE_TEXT_LENGTH)
|
||||
return false;
|
||||
return (
|
||||
normalized.includes(normalizedSent) || normalizedSent.includes(normalized)
|
||||
);
|
||||
if (!normalizedSent || normalizedSent.length < MIN_DUPLICATE_TEXT_LENGTH) return false;
|
||||
return normalized.includes(normalizedSent) || normalizedSent.includes(normalized);
|
||||
});
|
||||
}
|
||||
|
||||
export function isMessagingToolDuplicate(
|
||||
text: string,
|
||||
sentTexts: string[],
|
||||
): boolean {
|
||||
export function isMessagingToolDuplicate(text: string, sentTexts: string[]): boolean {
|
||||
if (sentTexts.length === 0) return false;
|
||||
const normalized = normalizeTextForComparison(text);
|
||||
if (!normalized || normalized.length < MIN_DUPLICATE_TEXT_LENGTH)
|
||||
return false;
|
||||
return isMessagingToolDuplicateNormalized(
|
||||
normalized,
|
||||
sentTexts.map(normalizeTextForComparison),
|
||||
);
|
||||
if (!normalized || normalized.length < MIN_DUPLICATE_TEXT_LENGTH) return false;
|
||||
return isMessagingToolDuplicateNormalized(normalized, sentTexts.map(normalizeTextForComparison));
|
||||
}
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
import {
|
||||
normalizeThinkLevel,
|
||||
type ThinkLevel,
|
||||
} from "../../auto-reply/thinking.js";
|
||||
import { normalizeThinkLevel, type ThinkLevel } from "../../auto-reply/thinking.js";
|
||||
|
||||
function extractSupportedValues(raw: string): string[] {
|
||||
const match =
|
||||
raw.match(/supported values are:\s*([^\n.]+)/i) ??
|
||||
raw.match(/supported values:\s*([^\n.]+)/i);
|
||||
raw.match(/supported values are:\s*([^\n.]+)/i) ?? raw.match(/supported values:\s*([^\n.]+)/i);
|
||||
if (!match?.[1]) return [];
|
||||
const fragment = match[1];
|
||||
const quoted = Array.from(fragment.matchAll(/['"]([^'"]+)['"]/g)).map(
|
||||
(entry) => entry[1]?.trim(),
|
||||
const quoted = Array.from(fragment.matchAll(/['"]([^'"]+)['"]/g)).map((entry) =>
|
||||
entry[1]?.trim(),
|
||||
);
|
||||
if (quoted.length > 0) {
|
||||
return quoted.filter((entry): entry is string => Boolean(entry));
|
||||
|
||||
@@ -30,10 +30,7 @@ export function validateGeminiTurns(messages: AgentMessage[]): AgentMessage[] {
|
||||
const currentMsg = msg as Extract<AgentMessage, { role: "assistant" }>;
|
||||
|
||||
if (lastMsg && typeof lastMsg === "object") {
|
||||
const lastAsst = lastMsg as Extract<
|
||||
AgentMessage,
|
||||
{ role: "assistant" }
|
||||
>;
|
||||
const lastAsst = lastMsg as Extract<AgentMessage, { role: "assistant" }>;
|
||||
const mergedContent = [
|
||||
...(Array.isArray(lastAsst.content) ? lastAsst.content : []),
|
||||
...(Array.isArray(currentMsg.content) ? currentMsg.content : []),
|
||||
@@ -82,9 +79,7 @@ export function mergeConsecutiveUserTurns(
|
||||
* Anthropic requires strict alternating user→assistant pattern.
|
||||
* Merges consecutive user messages together.
|
||||
*/
|
||||
export function validateAnthropicTurns(
|
||||
messages: AgentMessage[],
|
||||
): AgentMessage[] {
|
||||
export function validateAnthropicTurns(messages: AgentMessage[]): AgentMessage[] {
|
||||
if (!Array.isArray(messages) || messages.length === 0) {
|
||||
return messages;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
export type EmbeddedContextFile = { path: string; content: string };
|
||||
|
||||
export type FailoverReason =
|
||||
| "auth"
|
||||
| "format"
|
||||
| "rate_limit"
|
||||
| "billing"
|
||||
| "timeout"
|
||||
| "unknown";
|
||||
export type FailoverReason = "auth" | "format" | "rate_limit" | "billing" | "timeout" | "unknown";
|
||||
|
||||
Reference in New Issue
Block a user