mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 12:12:54 +00:00
Extract shared normalization/coercion helpers into private @openclaw/normalization-core workspace package while preserving existing plugin SDK helper subpaths.\n\nAlso keeps direct normalization-core imports internal, wires UI/build/loader resolution, and replaces the slow PR network CodeQL lane with a fast added-line boundary scan while retaining full CodeQL for scheduled/manual runs.\n\nVerification: local moved tests, plugin SDK boundary tests, extension loader tests, agents-support shard, UI build/test, build artifacts, lint, workflow guards, autoreview, and GitHub CI passed on PR head 963d893715.
42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
|
|
import { formatErrorMessage } from "../../infra/errors.js";
|
|
|
|
export type ProviderRequestErrorCode = "provider_conversation_state_error";
|
|
|
|
export type ProviderRequestErrorClassification = {
|
|
code: ProviderRequestErrorCode;
|
|
userMessage: string;
|
|
technicalMessage: string;
|
|
};
|
|
|
|
export const PROVIDER_CONVERSATION_STATE_ERROR_USER_MESSAGE =
|
|
"⚠️ The model provider rejected the conversation state. Please try again, or use /new to start a fresh session.";
|
|
|
|
export function classifyProviderRequestError(
|
|
err: unknown,
|
|
): ProviderRequestErrorClassification | undefined {
|
|
const technicalMessage = formatErrorMessage(err);
|
|
if (isProviderConversationStateErrorMessage(technicalMessage)) {
|
|
return {
|
|
code: "provider_conversation_state_error",
|
|
userMessage: PROVIDER_CONVERSATION_STATE_ERROR_USER_MESSAGE,
|
|
technicalMessage,
|
|
};
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
export function isProviderConversationStateErrorMessage(message: string): boolean {
|
|
const lower = normalizeLowercaseStringOrEmpty(message);
|
|
return (
|
|
(lower.includes("custom tool call output is missing") && lower.includes("call id")) ||
|
|
(lower.includes("toolresult") &&
|
|
lower.includes("tooluse") &&
|
|
lower.includes("exceeds the number") &&
|
|
lower.includes("previous turn")) ||
|
|
lower.includes("function call turn comes immediately after") ||
|
|
lower.includes("incorrect role information") ||
|
|
lower.includes("roles must alternate")
|
|
);
|
|
}
|