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.6 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

import * as events from "../../src/features/auth/session-events.ts";
import { createDeepLinkIntentGate } from "../../src/features/deep-links/deep-link-intent.ts";
import { parseUnslothDeepLink } from "../../src/features/deep-links/parse-deep-link.ts";
import type * as Drafts from "../../src/features/model-picker/model-config/model-config-draft.ts";
import { modelConfigDraftKey } from "../../src/features/model-picker/model-config/model-config-draft.ts";
import * as inboxModule from "../../src/features/model-picker/sharing/inbox.ts";
import type * as Receiver from "../../src/features/model-picker/sharing/receive-link.ts";
import { loadWithStubs } from "./module-stubs.ts";
import * as links from "./sharing-links.ts";

export const settle = () =>
  new Promise<void>((resolve) => setImmediate(resolve));

export function receiverHarness({
  desktop = false,
  signedIn = () => true,
  loadParser = () => links,
  errors = [],
  notices = [],
  cleared = [],
  drafts = { markModelConfigDraftEdited: () => undefined, modelConfigDraftKey },
}: {
  desktop?: boolean;
  signedIn?: () => boolean;
  loadParser?: () => typeof links | Promise<typeof links>;
  errors?: string[];
  notices?: { message: string; description?: string }[];
  cleared?: string[];
  drafts?: Pick<
    typeof Drafts,
    "markModelConfigDraftEdited" | "modelConfigDraftKey"
  >;
} = {}) {
  const inbox = inboxModule.createRunConfigInbox();
  let nextId = 0;
  const receiver = loadWithStubs<typeof Receiver>(
    new URL(
      "../../src/features/model-picker/sharing/receive-link.ts",
      import.meta.url,
    ),
    {
      "@/lib/api-base": { isTauri: desktop },
      "@/lib/toast": {
        toast: {
          error: (message: string) => errors.push(message),
          info: (message: string, options?: { description?: string }) =>
            notices.push({ message, description: options?.description }),
        },
      },
      "@/features/auth": { ...events, hasAuthToken: signedIn },
      "@/features/deep-links": {
        createDeepLinkIntentGate,
        parseUnslothDeepLink,
      },
      "../model-config/model-config-draft": drafts,
      "../model-config/model-config-handoff": {
        clearModelConfigHandoff: (id: string) => cleared.push(id),
        createModelConfigHandoffRequestId: () => `request-${++nextId}`,
      },
      "./inbox": { ...inboxModule, runConfigInbox: inbox },
      get "./links"() {
        return loadParser();
      },
    },
  );
  return { receiver, inbox, errors, notices, cleared };
}