| 1 | import libs from './lib'; |
| 2 | import getContext from './scripts/st-context'; |
| 3 | import { power_user, getThemeObject } from './scripts/power-user'; |
| 4 | import { QuickReplyApi } from './scripts/extensions/quick-reply/api/QuickReplyApi'; |
| 5 | import { oai_settings } from './scripts/openai'; |
| 6 | import { textgenerationwebui_settings } from './scripts/textgen-settings'; |
| 7 | import { FileAttachment } from './scripts/chats'; |
| 8 | import { ReasoningMessageExtra } from './scripts/reasoning'; |
| 9 | import { IGNORE_SYMBOL, OVERSWIPE_BEHAVIOR } from './scripts/constants'; |
| 10 | import { ToolInvocation } from './scripts/tool-calling'; |
| 11 | import { getWorldInfoSettings } from './scripts/world-info'; |
| 12 | |
| 13 | declare global { |
| 14 | // Custom types |
| 15 | type InstructSettings = typeof power_user.instruct; |
| 16 | type ContextSettings = typeof power_user.context; |
| 17 | type ReasoningSettings = typeof power_user.reasoning; |
| 18 | type ChatCompletionSettings = typeof oai_settings; |
| 19 | type TextCompletionSettings = typeof textgenerationwebui_settings; |
| 20 | type WorldInfoSettings = ReturnType<typeof getWorldInfoSettings>; |
| 21 | type MessageTimestamp = string | number | Date; |
| 22 | type Character = import('./scripts/char-data').v1CharData; |
| 23 | type ChatMessageExtra = BaseMessageExtra & Partial<ReasoningMessageExtra> & Record<string, any>; |
| 24 | type Theme = ReturnType<typeof getThemeObject>; |
| 25 | |
| 26 | interface Group { |
| 27 | id: string; |
| 28 | name: string; |
| 29 | members: string[]; |
| 30 | disabled_members: string[]; |
| 31 | chat_id: string; |
| 32 | chats: string[]; |
| 33 | generation_mode?: number; |
| 34 | generation_mode_join_prefix?: string; |
| 35 | generation_mode_join_suffix?: string; |
| 36 | activation_strategy?: number; |
| 37 | auto_mode_delay?: number; |
| 38 | allow_self_responses?: boolean; |
| 39 | avatar_url?: string; |
| 40 | hideMutedSprites?: boolean; |
| 41 | fav?: boolean; |
| 42 | date_last_chat?: MessageTimestamp; |
| 43 | } |
| 44 | |
| 45 | interface ChatFile extends Array<ChatMessage> { |
| 46 | [index: number]: ChatMessage; |
| 47 | 0?: ChatHeader; |
| 48 | } |
| 49 | |
| 50 | interface ChatHeader { |
| 51 | chat_metadata: ChatMetadata; |
| 52 | /** @deprecated For backward compatibility ONLY */ |
| 53 | user_name: 'unused'; |
| 54 | /** @deprecated For backward compatibility ONLY */ |
| 55 | character_name: 'unused'; |
| 56 | } |
| 57 | |
| 58 | interface ChatMetadata { |
| 59 | tainted?: boolean; |
| 60 | integrity?: string; |
| 61 | scenario?: string; |
| 62 | persona?: string; |
| 63 | [key: string]: any; |
| 64 | } |
| 65 | |
| 66 | interface ChatMessage { |
| 67 | name?: string; |
| 68 | mes?: string; |
| 69 | title?: string; |
| 70 | gen_started?: MessageTimestamp; |
| 71 | gen_finished?: MessageTimestamp; |
| 72 | send_date?: MessageTimestamp; |
| 73 | is_user?: boolean; |
| 74 | is_system?: boolean; |
| 75 | force_avatar?: string; |
| 76 | original_avatar?: string; |
| 77 | swipes?: string[]; |
| 78 | swipe_info?: SwipeInfo[]; |
| 79 | swipe_id?: number; |
| 80 | extra?: ChatMessageExtra; |
| 81 | }; |
| 82 | |
| 83 | interface SwipeInfo { |
| 84 | send_date?: MessageTimestamp; |
| 85 | gen_started?: MessageTimestamp; |
| 86 | gen_finished?: MessageTimestamp; |
| 87 | extra?: ChatMessageExtra; |
| 88 | } |
| 89 | |
| 90 | interface BaseMessageExtra { |
| 91 | api?: string; |
| 92 | model?: string; |
| 93 | type?: string; |
| 94 | gen_id?: number; |
| 95 | bias?: string; |
| 96 | uses_system_ui?: boolean; |
| 97 | memory?: string; |
| 98 | display_text?: string; |
| 99 | reasoning_display_text?: string; |
| 100 | tool_invocations?: ToolInvocation[]; |
| 101 | title?: string; |
| 102 | isSmallSys?: boolean; |
| 103 | token_count?: number; |
| 104 | /** When false, the message cannot be swiped. */ |
| 105 | swipeable?: boolean; |
| 106 | overswipe_behavior?: OVERSWIPE_BEHAVIOR; |
| 107 | files?: FileAttachment[]; |
| 108 | inline_image?: boolean; |
| 109 | media_display?: string; |
| 110 | media_index?: number; |
| 111 | media?: MediaAttachment[], |
| 112 | /** @deprecated Use `files` instead */ |
| 113 | file?: FileAttachment; |
| 114 | /** @deprecated Use `media` instead */ |
| 115 | image?: string; |
| 116 | /** @deprecated Use `media` instead */ |
| 117 | video?: string; |
| 118 | /** @deprecated Use `media` with `media_display = 'gallery'` instead */ |
| 119 | image_swipes?: string[]; |
| 120 | /** @deprecated Use `MediaAttachment.append_title` instead */ |
| 121 | append_title?: boolean; |
| 122 | /** @deprecated Use `MediaAttachment.generation_type` instead */ |
| 123 | generationType?: number; |
| 124 | /** @deprecated Use `MediaAttachment.negative` instead */ |
| 125 | negative?: string; |
| 126 | /** Will exclude this message from prompt processing */ |
| 127 | [IGNORE_SYMBOL]?: boolean; |
| 128 | } |
| 129 | |
| 130 | type MediaAttachment = MediaAttachmentProps & ImageGenerationAttachmentProps & ImageCaptionAttachmentProps; |
| 131 | |
| 132 | interface MediaAttachmentProps { |
| 133 | url: string; |
| 134 | title?: string; |
| 135 | type: string; |
| 136 | source?: string; |
| 137 | } |
| 138 | |
| 139 | interface ImageGenerationAttachmentProps { |
| 140 | generation_type?: number; |
| 141 | negative?: string; |
| 142 | width?: number; |
| 143 | height?: number; |
| 144 | } |
| 145 | |
| 146 | interface ImageCaptionAttachmentProps { |
| 147 | /** Append title to the message text in case of non-inline captions. */ |
| 148 | append_title?: boolean; |
| 149 | /** Marker for captioned images to prevent auto-caption from firing again. */ |
| 150 | captioned?: boolean; |
| 151 | } |
| 152 | |
| 153 | /** Media playback state */ |
| 154 | interface MediaState { |
| 155 | /** Current playback time */ |
| 156 | currentTime: number; |
| 157 | /** Whether the media is paused */ |
| 158 | paused: boolean; |
| 159 | } |
| 160 | |
| 161 | interface ChatCompletionMessage { |
| 162 | name?: string; |
| 163 | role: string; |
| 164 | content: string; |
| 165 | } |
| 166 | |
| 167 | // Global namespace modules |
| 168 | interface Window { |
| 169 | ai: any; |
| 170 | } |
| 171 | |
| 172 | var pdfjsLib; |
| 173 | var ePub; |
| 174 | var quickReplyApi: QuickReplyApi; |
| 175 | |
| 176 | var SillyTavern: { |
| 177 | getContext(): typeof getContext; |
| 178 | llm: any; |
| 179 | libs: typeof libs; |
| 180 | }; |
| 181 | |
| 182 | // Jquery plugins |
| 183 | interface JQuery { |
| 184 | nanogallery2(options?: any): JQuery; |
| 185 | nanogallery2(method: string, options?: any): JQuery; |
| 186 | pagination(method: 'getCurrentPageNum'): number; |
| 187 | pagination(method: string, options?: any): JQuery; |
| 188 | pagination(options?: any): JQuery; |
| 189 | izoomify(options?: any): JQuery; |
| 190 | } |
| 191 | |
| 192 | // NPM package doesn't have the 'queue' property in the type definition |
| 193 | interface JQueryTransitOptions { |
| 194 | queue?: boolean; |
| 195 | } |
| 196 | |
| 197 | namespace Select2 { |
| 198 | interface Options<Result = DataFormat | GroupedDataFormat, RemoteResult = any> { |
| 199 | /** |
| 200 | * Extends Select2 v4 plugin by adding an option to set a placeholder for the 'search' input field |
| 201 | * [Custom Field] |
| 202 | * @default '' |
| 203 | */ |
| 204 | searchInputPlaceholder?: string; |
| 205 | |
| 206 | /** |
| 207 | * Extends select2 plugin by adding a custom css class for the 'search' input field |
| 208 | * [Custom Field] |
| 209 | * @default '' |
| 210 | */ |
| 211 | searchInputCssClass?: string; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Translates a text to a target language using a translation provider. |
| 217 | * @param text Text to translate |
| 218 | * @param lang Target language |
| 219 | * @param provider Translation provider |
| 220 | */ |
| 221 | function translate(text: string, lang: string, provider?: string | null): Promise<string>; |
| 222 | |
| 223 | interface ConvertVideoArgs { |
| 224 | buffer: Uint8Array; |
| 225 | name: string; |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Converts a video file to an animated WebP format using FFmpeg. |
| 230 | * @param args - The arguments for the conversion function. |
| 231 | */ |
| 232 | function convertVideoToAnimatedWebp(args: ConvertVideoArgs): Promise<Uint8Array>; |
| 233 | |
| 234 | type ColorPickerEvent = Omit<JQuery.ChangeEvent<HTMLElement>, "detail"> & { |
| 235 | detail: { |
| 236 | rgba: string; |
| 237 | } |
| 238 | }; |
| 239 | |
| 240 | type SwipeEvent = JQuery.TriggeredEvent<any, any, HTMLElement, HTMLElement>; |
| 241 | } |
| 242 | |
| 243 | //Overrides for public/scripts/chats.js |
| 244 | declare module 'dompurify' { |
| 245 | interface Config { |
| 246 | MESSAGE_SANITIZE?: boolean; |
| 247 | MESSAGE_ALLOW_SYSTEM_UI?: boolean; |
| 248 | } |
| 249 | } |