open-webui/src/lib/stores/index.ts

288 lines
6.7 KiB
TypeScript
Raw Normal View History

2024-02-24 01:12:19 +00:00
import { APP_NAME } from '$lib/constants';
2024-04-21 10:41:18 +00:00
import { type Writable, writable } from 'svelte/store';
2024-12-31 10:26:30 +00:00
import type { ModelConfig } from '$lib/apis';
import type { Banner } from '$lib/types';
2024-06-04 06:39:52 +00:00
import type { Socket } from 'socket.io-client';
2023-11-19 00:47:12 +00:00
2024-12-30 10:20:09 +00:00
import emojiShortCodes from '$lib/emoji-shortcodes.json';
2023-11-20 01:47:07 +00:00
// Backend
2024-02-24 01:12:19 +00:00
export const WEBUI_NAME = writable(APP_NAME);
export const config: Writable<Config | undefined> = writable(undefined);
export const user: Writable<SessionUser | undefined> = writable(undefined);
2023-11-20 01:47:07 +00:00
2025-01-14 03:18:32 +00:00
// Electron App
export const isApp = writable(false);
2025-01-18 01:05:52 +00:00
export const appInfo = writable(null);
2025-01-22 17:42:40 +00:00
export const appData = writable(null);
2025-01-14 03:18:32 +00:00
2023-11-20 01:47:07 +00:00
// Frontend
export const MODEL_DOWNLOAD_POOL = writable({});
2024-01-03 04:41:37 +00:00
2024-05-14 22:26:53 +00:00
export const mobile = writable(false);
2024-06-04 06:39:52 +00:00
export const socket: Writable<null | Socket> = writable(null);
2024-12-27 07:29:33 +00:00
export const activeUserIds: Writable<null | string[]> = writable(null);
2024-06-04 18:13:43 +00:00
export const USAGE_POOL: Writable<null | string[]> = writable(null);
2024-06-04 06:39:52 +00:00
export const theme = writable('system');
2024-09-26 01:21:37 +00:00
2024-12-31 10:26:30 +00:00
export const shortCodesToEmojis = writable(
Object.entries(emojiShortCodes).reduce((acc, [key, value]) => {
if (typeof value === 'string') {
acc[value] = key;
} else {
for (const v of value) {
acc[v] = key;
}
2024-12-30 10:20:09 +00:00
}
2024-12-31 10:26:30 +00:00
return acc;
}, {})
);
2024-12-30 10:20:09 +00:00
2025-02-10 07:42:27 +00:00
export const TTSWorker = writable(null);
2023-11-20 01:47:07 +00:00
export const chatId = writable('');
2024-09-26 01:21:37 +00:00
export const chatTitle = writable('');
2024-01-03 04:41:37 +00:00
2024-12-22 11:10:10 +00:00
export const channels = writable([]);
2025-03-26 07:43:51 +00:00
export const chats = writable(null);
2024-07-02 06:08:01 +00:00
export const pinnedChats = writable([]);
2024-01-18 10:55:25 +00:00
export const tags = writable([]);
2025-08-09 21:03:02 +00:00
export const folders = writable([]);
2024-01-08 07:43:32 +00:00
export const selectedFolder = writable(null);
2024-06-11 03:39:55 +00:00
export const models: Writable<Model[]> = writable([]);
2024-06-20 08:44:52 +00:00
export const prompts: Writable<null | Prompt[]> = writable(null);
export const knowledge: Writable<null | Document[]> = writable(null);
export const tools = writable(null);
export const functions = writable(null);
2025-03-27 09:27:56 +00:00
export const toolServers = writable([]);
export const banners: Writable<Banner[]> = writable([]);
export const settings: Writable<Settings> = writable({});
2024-04-30 23:34:29 +00:00
export const showSidebar = writable(false);
2025-05-18 21:39:33 +00:00
export const showSearch = writable(false);
2023-11-20 01:47:07 +00:00
export const showSettings = writable(false);
2025-07-18 08:47:22 +00:00
export const showShortcuts = writable(false);
2024-05-15 08:22:15 +00:00
export const showArchivedChats = writable(false);
2024-02-23 08:47:54 +00:00
export const showChangelog = writable(false);
2024-09-17 20:05:19 +00:00
export const showControls = writable(false);
export const showOverview = writable(false);
export const showArtifacts = writable(false);
2024-06-07 05:30:19 +00:00
export const showCallOverlay = writable(false);
2024-04-21 10:41:18 +00:00
2025-05-16 17:47:43 +00:00
export const artifactCode = writable(null);
export const temporaryChatEnabled = writable(false);
2024-08-04 15:31:41 +00:00
export const scrollPaginationEnabled = writable(false);
2024-08-04 15:11:41 +00:00
export const currentChatPage = writable(1);
2024-04-21 10:41:18 +00:00
export const isLastActiveTab = writable(true);
2025-01-04 10:05:42 +00:00
export const playingNotificationSound = writable(false);
export type Model = OpenAIModel | OllamaModel;
2024-04-21 10:41:18 +00:00
type BaseModel = {
2024-04-21 10:41:18 +00:00
id: string;
name: string;
2024-05-25 01:26:36 +00:00
info?: ModelConfig;
2024-10-22 10:16:48 +00:00
owned_by: 'ollama' | 'openai' | 'arena';
};
2024-04-21 10:41:18 +00:00
export interface OpenAIModel extends BaseModel {
2024-08-20 00:44:09 +00:00
owned_by: 'openai';
external: boolean;
source?: string;
}
export interface OllamaModel extends BaseModel {
2024-08-20 00:44:09 +00:00
owned_by: 'ollama';
2024-04-21 10:41:18 +00:00
details: OllamaModelDetails;
size: number;
description: string;
model: string;
modified_at: string;
digest: string;
2024-08-20 00:44:09 +00:00
ollama?: {
name?: string;
model?: string;
modified_at: string;
size?: number;
digest?: string;
details?: {
parent_model?: string;
format?: string;
family?: string;
families?: string[];
parameter_size?: string;
quantization_level?: string;
};
urls?: number[];
};
}
2024-04-21 10:41:18 +00:00
type OllamaModelDetails = {
parent_model: string;
format: string;
family: string;
families: string[] | null;
parameter_size: string;
quantization_level: string;
};
type Settings = {
2025-06-18 06:01:21 +00:00
pinnedModels?: never[];
toolServers?: never[];
detectArtifacts?: boolean;
showUpdateToast?: boolean;
showChangelog?: boolean;
showEmojiInCall?: boolean;
voiceInterruption?: boolean;
collapseCodeBlocks?: boolean;
expandDetails?: boolean;
notificationSound?: boolean;
notificationSoundAlways?: boolean;
stylizedPdfExport?: boolean;
notifications?: any;
imageCompression?: boolean;
imageCompressionSize?: any;
widescreenMode?: null;
largeTextAsFile?: boolean;
promptAutocomplete?: boolean;
hapticFeedback?: boolean;
responseAutoCopy?: any;
richTextInput?: boolean;
params?: any;
userLocation?: any;
webSearch?: any;
2025-06-18 06:01:21 +00:00
memory?: boolean;
autoTags?: boolean;
autoFollowUps?: boolean;
splitLargeChunks?(body: any, splitLargeChunks: any): unknown;
backgroundImageUrl?: null;
landingPageMode?: string;
iframeSandboxAllowForms?: boolean;
iframeSandboxAllowSameOrigin?: boolean;
scrollOnBranchChange?: boolean;
directConnections?: null;
chatBubble?: boolean;
copyFormatted?: boolean;
models?: string[];
conversationMode?: boolean;
speechAutoSend?: boolean;
responseAutoPlayback?: boolean;
audio?: AudioSettings;
showUsername?: boolean;
notificationEnabled?: boolean;
2025-06-06 11:38:35 +00:00
highContrastMode?: boolean;
title?: TitleSettings;
splitLargeDeltas?: boolean;
2025-06-18 06:01:21 +00:00
chatDirection?: 'LTR' | 'RTL' | 'auto';
2025-03-04 04:53:14 +00:00
ctrlEnterToSend?: boolean;
system?: string;
seed?: number;
temperature?: string;
repeat_penalty?: string;
top_k?: string;
top_p?: string;
num_ctx?: string;
2024-06-14 05:31:26 +00:00
num_batch?: string;
num_keep?: string;
options?: ModelOptions;
};
type ModelOptions = {
stop?: boolean;
};
type AudioSettings = {
stt: any;
tts: any;
STTEngine?: string;
TTSEngine?: string;
speaker?: string;
2024-05-07 00:28:34 +00:00
model?: string;
nonLocalVoices?: boolean;
};
type TitleSettings = {
auto?: boolean;
model?: string;
modelExternal?: string;
prompt?: string;
};
type Prompt = {
command: string;
user_id: string;
title: string;
content: string;
timestamp: number;
};
2024-06-11 03:39:55 +00:00
type Document = {
collection_name: string;
filename: string;
name: string;
title: string;
};
type Config = {
license_metadata: any;
status: boolean;
name: string;
version: string;
default_locale: string;
default_models: string;
default_prompt_suggestions: PromptSuggestion[];
2024-05-26 20:02:40 +00:00
features: {
2024-05-26 16:10:25 +00:00
auth: boolean;
auth_trusted_header: boolean;
2024-11-19 20:17:23 +00:00
enable_api_key: boolean;
2024-05-27 19:48:08 +00:00
enable_signup: boolean;
enable_login_form: boolean;
2024-05-27 19:48:08 +00:00
enable_web_search?: boolean;
2024-12-19 02:04:56 +00:00
enable_google_drive_integration: boolean;
2025-02-24 14:14:10 +00:00
enable_onedrive_integration: boolean;
2024-05-26 16:10:25 +00:00
enable_image_generation: boolean;
enable_admin_export: boolean;
enable_admin_chat_access: boolean;
2024-05-26 16:10:25 +00:00
enable_community_sharing: boolean;
enable_autocomplete_generation: boolean;
enable_direct_connections: boolean;
enable_version_update_check: boolean;
};
oauth: {
providers: {
[key: string]: string;
};
};
2025-05-14 17:39:17 +00:00
ui?: {
pending_user_overlay_title?: string;
pending_user_overlay_description?: string;
};
};
type PromptSuggestion = {
content: string;
title: [string, string];
};
type SessionUser = {
permissions: any;
id: string;
email: string;
name: string;
role: string;
profile_image_url: string;
2024-04-21 10:41:18 +00:00
};