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.

2.7 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 interface StubThread {
  id: string;
  archived?: boolean;
  pairId?: string;
  title?: string;
  updatedAt?: number;
}

interface Recorder {
  notifications: number;
  patched: string[];
  events: string[];
  threads: StubThread[];
  failOn: Set<string>;
  slowOn: Set<string>;
}

export const recorder: Recorder = {
  notifications: 0,
  patched: [],
  events: [],
  threads: [],
  failOn: new Set(),
  slowOn: new Set(),
};

export function resetRecorder(
  threads: StubThread[],
  failOn: string[] = [],
  slowOn: string[] = [],
) {
  recorder.notifications = 0;
  recorder.patched = [];
  recorder.events = [];
  recorder.threads = threads;
  recorder.failOn = new Set(failOn);
  recorder.slowOn = new Set(slowOn);
}

export const CHAT_HISTORY_UPDATED_EVENT = "unsloth:chat-history-updated";

export function notifyChatHistoryUpdated(): void {
  recorder.notifications += 1;
  recorder.events.push("notify");
}

export async function listStoredChatThreads(): Promise<StubThread[]> {
  return recorder.threads;
}

export async function updateStoredChatThread(
  threadId: string,
  _patch: unknown,
  options: { notify?: boolean } = {},
): Promise<StubThread> {
  if (recorder.slowOn.has(threadId)) {
    await new Promise((resolve) => setTimeout(resolve, 0));
  }
  if (recorder.failOn.has(threadId)) {
    recorder.events.push(`fail:${threadId}`);
    throw new Error(`PATCH failed for ${threadId}`);
  }
  recorder.patched.push(threadId);
  recorder.events.push(`patch:${threadId}`);
  if (options.notify !== false) notifyChatHistoryUpdated();
  return { id: threadId, archived: true };
}

export async function listStoredChatThreadsWithMessages(): Promise<StubThread[]> {
  return [];
}
export async function deleteStoredChatThreads(): Promise<void> {}
export function isExpectedBackgroundChatStorageError(): boolean {
  return false;
}
export function clearComposerDraft(): void {}
export function closeComposerDraft(): void {}
export function reopenComposerDraft(): void {}
export async function offerToDeleteKeptSandboxes(): Promise<void> {}
export async function stopChatThread(): Promise<void> {}
export function markChatThreadsDeleted(): void {}
export function notifyChatThreadsDeleted(): void {}
export function removeChatThreadTombstones(): void {}
export function requestPromptQueueStop(): void {}
export async function repairLegacyChatTitles(): Promise<void> {}

const inertStore = {
  getState: () => ({
    setActiveThreadId: () => {},
    cancelIfRunning: () => {},
  }),
};
export const useChatRuntimeStore = inertStore;
export const useChatArtifactsStore = inertStore;