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

245 lines
5.6 KiB
TypeScript
Raw Normal View History

2024-02-23 17:12:19 -08:00
import { APP_NAME } from '$lib/constants';
2024-04-21 11:41:18 +01:00
import { type Writable, writable } from 'svelte/store';
2024-12-31 02:26:30 -08:00
import type { ModelConfig } from '$lib/apis';
import type { Banner } from '$lib/types';
2024-06-03 23:39:52 -07:00
import type { Socket } from 'socket.io-client';
2023-11-18 16:47:12 -08:00
2024-12-30 02:20:09 -08:00
import emojiShortCodes from '$lib/emoji-shortcodes.json';
2023-11-19 17:47:07 -08:00
// Backend
2024-02-23 17:12:19 -08: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-19 17:47:07 -08:00
2025-01-13 19:18:32 -08:00
// Electron App
export const isApp = writable(false);
2025-01-17 17:05:52 -08:00
export const appInfo = writable(null);
2025-01-22 09:42:40 -08:00
export const appData = writable(null);
2025-01-13 19:18:32 -08:00
2023-11-19 17:47:07 -08:00
// Frontend
export const MODEL_DOWNLOAD_POOL = writable({});
2024-01-02 20:41:37 -08:00
2024-05-14 12:26:53 -10:00
export const mobile = writable(false);
2024-06-03 23:39:52 -07:00
export const socket: Writable<null | Socket> = writable(null);
2024-12-26 23:29:33 -08:00
export const activeUserIds: Writable<null | string[]> = writable(null);
2024-06-04 11:13:43 -07:00
export const USAGE_POOL: Writable<null | string[]> = writable(null);
2024-06-03 23:39:52 -07:00
export const theme = writable('system');
2024-09-26 03:21:37 +02:00
2024-12-31 02:26:30 -08: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 02:20:09 -08:00
}
2024-12-31 02:26:30 -08:00
return acc;
}, {})
);
2024-12-30 02:20:09 -08:00
2025-02-09 23:42:27 -08:00
export const TTSWorker = writable(null);
2023-11-19 17:47:07 -08:00
export const chatId = writable('');
2024-09-26 03:21:37 +02:00
export const chatTitle = writable('');
2024-01-02 20:41:37 -08:00
2024-12-22 04:10:10 -07:00
export const channels = writable([]);
2025-03-26 00:43:51 -07:00
export const chats = writable(null);
2024-07-01 23:08:01 -07:00
export const pinnedChats = writable([]);
2024-01-18 02:55:25 -08:00
export const tags = writable([]);
2024-01-07 23:43:32 -08:00
2024-06-10 20:39:55 -07:00
export const models: Writable<Model[]> = writable([]);
2025-06-09 00:33:41 +04:00
export const pinnedModels = writable([]);
2024-06-20 01:44:52 -07: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 02:27:56 -07:00
export const toolServers = writable([]);
export const banners: Writable<Banner[]> = writable([]);
export const settings: Writable<Settings> = writable({});
2024-04-30 16:34:29 -07:00
export const showSidebar = writable(false);
2025-05-19 01:39:33 +04:00
export const showSearch = writable(false);
2023-11-19 17:47:07 -08:00
export const showSettings = writable(false);
2024-05-14 22:22:15 -10:00
export const showArchivedChats = writable(false);
2024-02-23 00:47:54 -08:00
export const showChangelog = writable(false);
2024-09-17 22:05:19 +02:00
export const showControls = writable(false);
export const showOverview = writable(false);
export const showArtifacts = writable(false);
2024-06-06 22:30:19 -07:00
export const showCallOverlay = writable(false);
2024-04-21 11:41:18 +01:00
2025-05-16 21:47:43 +04:00
export const artifactCode = writable(null);
export const temporaryChatEnabled = writable(false);
2024-08-04 17:31:41 +02:00
export const scrollPaginationEnabled = writable(false);
2024-08-04 17:11:41 +02:00
export const currentChatPage = writable(1);
2024-04-21 11:41:18 +01:00
export const isLastActiveTab = writable(true);
2025-01-04 02:05:42 -08:00
export const playingNotificationSound = writable(false);
export type Model = OpenAIModel | OllamaModel;
2024-04-21 11:41:18 +01:00
type BaseModel = {
2024-04-21 11:41:18 +01:00
id: string;
name: string;
2024-05-24 18:26:36 -07:00
info?: ModelConfig;
2024-10-22 03:16:48 -07:00
owned_by: 'ollama' | 'openai' | 'arena';
};
2024-04-21 11:41:18 +01:00
export interface OpenAIModel extends BaseModel {
2024-08-20 08:44:09 +08:00
owned_by: 'openai';
external: boolean;
source?: string;
}
export interface OllamaModel extends BaseModel {
2024-08-20 08:44:09 +08:00
owned_by: 'ollama';
2024-04-21 11:41:18 +01:00
details: OllamaModelDetails;
size: number;
description: string;
model: string;
modified_at: string;
digest: string;
2024-08-20 08:44:09 +08: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 11:41:18 +01:00
type OllamaModelDetails = {
parent_model: string;
format: string;
family: string;
families: string[] | null;
parameter_size: string;
quantization_level: string;
};
type Settings = {
models?: string[];
conversationMode?: boolean;
speechAutoSend?: boolean;
responseAutoPlayback?: boolean;
audio?: AudioSettings;
showUsername?: boolean;
notificationEnabled?: boolean;
title?: TitleSettings;
splitLargeDeltas?: boolean;
2025-04-06 17:02:39 -07:00
chatDirection: 'LTR' | 'RTL' | 'auto';
2025-03-03 20:53:14 -08:00
ctrlEnterToSend?: boolean;
system?: string;
requestFormat?: string;
keepAlive?: string;
seed?: number;
temperature?: string;
repeat_penalty?: string;
top_k?: string;
top_p?: string;
num_ctx?: string;
2024-06-14 15:31:26 +10:00
num_batch?: string;
num_keep?: string;
options?: ModelOptions;
};
type ModelOptions = {
stop?: boolean;
};
type AudioSettings = {
STTEngine?: string;
TTSEngine?: string;
speaker?: string;
2024-05-07 08:28:34 +08: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-10 20:39:55 -07:00
type Document = {
collection_name: string;
filename: string;
name: string;
title: string;
};
type Config = {
status: boolean;
name: string;
version: string;
default_locale: string;
default_models: string;
default_prompt_suggestions: PromptSuggestion[];
2024-05-26 13:02:40 -07:00
features: {
2024-05-26 17:10:25 +01:00
auth: boolean;
auth_trusted_header: boolean;
2024-11-19 12:17:23 -08:00
enable_api_key: boolean;
2024-05-27 12:48:08 -07:00
enable_signup: boolean;
enable_login_form: boolean;
2024-05-27 12:48:08 -07:00
enable_web_search?: boolean;
2024-12-18 18:04:56 -08:00
enable_google_drive_integration: boolean;
2025-02-24 23:14:10 +09:00
enable_onedrive_integration: boolean;
2024-05-26 17:10:25 +01:00
enable_image_generation: boolean;
enable_admin_export: boolean;
enable_admin_chat_access: boolean;
2024-05-26 17:10:25 +01:00
enable_community_sharing: boolean;
enable_autocomplete_generation: boolean;
enable_direct_connections: boolean;
};
oauth: {
providers: {
[key: string]: string;
};
};
2025-05-14 21:39:17 +04:00
ui?: {
pending_user_overlay_title?: string;
pending_user_overlay_description?: string;
};
};
type PromptSuggestion = {
content: string;
title: [string, string];
};
type SessionUser = {
id: string;
email: string;
name: string;
role: string;
profile_image_url: string;
2024-04-21 11:41:18 +01:00
};