/**
 * Signal composition helper for LLM adapter timeouts
 * Composes an execution-level abort signal with a per-call timeout
 */

/**
 * Compose an abort signal from a per-call timeout and an optional execution-level signal.
 * Returns a single signal that fires when either source aborts.
 *
 * @param timeoutMs - Per-call timeout in milliseconds
 * @param executionSignal - Optional execution-level abort signal (from coordinator)
 * @returns Composed AbortSignal via AbortSignal.any()
 */
export function composeSignal(timeoutMs: number, executionSignal?: AbortSignal): AbortSignal {
  const signals: AbortSignal[] = [AbortSignal.timeout(timeoutMs)]
  if (executionSignal) signals.push(executionSignal)
  return AbortSignal.any(signals)
}
