Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

1.3 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0

export type PromptQueueUserStopItem = {
  dispatched: boolean;
};

export type UserPromptQueueStopPlan = {
  cancelActiveItem: boolean;
  retainedItemIndexes: number[];
  pause: boolean;
};

export type PromptQueueTargetCancelMode = "none" | "activeRun" | "permanent";

export function userStopTargetCancelMode(
  plan: UserPromptQueueStopPlan,
): PromptQueueTargetCancelMode {
  if (!plan.cancelActiveItem) {
    return "none";
  }
  return plan.pause ? "activeRun" : "permanent";
}

export function planUserPromptQueueStop(
  items: readonly PromptQueueUserStopItem[],
  runIndex: number,
): UserPromptQueueStopPlan {
  if (runIndex < 0) {
    return {
      cancelActiveItem: false,
      retainedItemIndexes: items.map((_, index) => index),
      pause: items.length > 0,
    };
  }
  const activeIndex = runIndex;
  const activeItem = items[activeIndex];
  const dropActive = Boolean(activeItem?.dispatched);
  const retainedItemIndexes = items.flatMap((_, index) =>
    dropActive && index === activeIndex ? [] : [index],
  );
  return {
    cancelActiveItem: dropActive,
    retainedItemIndexes,
    pause: retainedItemIndexes.some((index) => !items[index]?.dispatched),
  };
}