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

const LLAMA_JOB_STARTED_STORAGE_KEY = "unsloth_llama_job_started_at";
const LLAMA_JOB_STARTED_EVENT = "unsloth:llama-job-started";

export function signalLlamaJobStarted(startedAt: string | null): void {
  try {
    localStorage.setItem(
      LLAMA_JOB_STARTED_STORAGE_KEY,
      `${startedAt ?? "unknown"}:${Date.now()}`,
    );
  } catch {
    // Storage can be unavailable in restricted browser contexts.
  }
  window.dispatchEvent(new Event(LLAMA_JOB_STARTED_EVENT));
}

export function signalRunningLlamaJob(job: {
  state: unknown;
  started_at: string | null;
}): boolean {
  if (job.state !== "running") {
    return false;
  }
  signalLlamaJobStarted(job.started_at);
  return true;
}

export function subscribeToLlamaJobStarted(listener: () => void): () => void {
  const onStorage = (event: StorageEvent) => {
    if (event.key === LLAMA_JOB_STARTED_STORAGE_KEY) {
      listener();
    }
  };
  window.addEventListener(LLAMA_JOB_STARTED_EVENT, listener);
  window.addEventListener("storage", onStorage);
  return () => {
    window.removeEventListener(LLAMA_JOB_STARTED_EVENT, listener);
    window.removeEventListener("storage", onStorage);
  };
}