import { StepResult } from './step-result'; import { ToolSet } from './tool-set'; export type StopCondition = (options: { steps: Array>; }) => PromiseLike | boolean; export function stepCountIs(stepCount: number): StopCondition { return ({ steps }) => steps.length === stepCount; } export function isLoopFinished(): StopCondition { return () => false; } export function hasToolCall(toolName: string): StopCondition { return ({ steps }) => steps[steps.length - 1]?.toolCalls?.some( toolCall => toolCall.toolName === toolName, ) ?? false; } export async function isStopConditionMet({ stopConditions, steps, }: { stopConditions: Array>; steps: Array>; }): Promise { return ( await Promise.all(stopConditions.map(condition => condition({ steps }))) ).some(result => result); }