Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

1.0 KB
Raw Blame
const TOOL_CALL_ERROR_PREFIX = /^Error:\s*(?:\[[^\]]*\]\s*)*tool call failed:\s*/i;

export function hasToolCallErrorPrefix(text: string): boolean {
  return TOOL_CALL_ERROR_PREFIX.test(text);
}

/** Whether a tool output string is one the tool output renderers present as a failure. */
export function isToolErrorOutput(text: string): boolean {
  return hasToolCallErrorPrefix(text) || text.startsWith('Error processing tool');
}

const VALIDATION_FEEDBACK = /^Error:[\s\S]*\n Please fix your mistakes\.$/i;

/**
 * Whether a completed tool call failed. Agents SDK releases serialize tool failures
 * into these host-authored prefixes, and schema-validation feedback into a plain
 * `Error:` block, without carrying `ToolMessage.status` on the wire.
 */
export function isFailedToolOutput(text: string): boolean {
  return (
    hasToolCallErrorPrefix(text) ||
    /^Error processing tool(?::|$)/i.test(text) ||
    VALIDATION_FEEDBACK.test(text)
  );
}

export function stripToolCallErrorPrefix(text: string): string {
  return text.replace(TOOL_CALL_ERROR_PREFIX, '');
}