-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.d.ts
329 lines (274 loc) · 11.5 KB
/
types.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
export type AvailablePages = '/imageGenerationPage' | '/textGenerationPage' | '/audioGenerationPage';
export type ExtensionData = {
title: string;
description: string;
url: string;
stars?: number;
};
export type MainIpcTypes = {
handle(channel: string, listener: (event: any, ...args: any[]) => any): void;
on(channel: string, listener: (event: any, ...args: any[]) => void): void;
send: (channel: string, ...args: any[]) => void;
};
/** These methods will be called in the main process */
export type CardMainMethods = {
/** Return commands based on installed directory to be executed with terminal */
getRunCommands: (dir: string) => Promise<string | string[]>;
/** Read saved argument from file and return data with the array of type ChosenArgument */
readArgs?: (dir: string) => Promise<ChosenArgument[]>;
/** Get user configured arguments and save it to desire file */
saveArgs?: (cardDir: string, args: ChosenArgument[]) => Promise<void>;
/**
* Access to the main process IPC methods.
* Use this to send/receive data or messages between the main process and the renderer process.
*/
mainIpc?: (ipc: MainIpcTypes) => void;
};
export type InstallationMethod = {chosen: 'install' | 'locate'; targetDirectory?: string};
export type UserInputFieldType = 'checkbox' | 'text-input' | 'select' | 'directory' | 'file';
export type UserInputField = {id: string; label: string; type: UserInputFieldType; selectOptions?: string[]};
export type UserInputResult = {id: string; result: string | boolean};
export type RendererIpcTypes = {
invoke(channel: string, ...args: any[]): Promise<any>;
on(channel: string, listener: any): () => void;
send(channel: string, ...args: any[]): void;
};
export type InstallationStepper = {
/** Initialize the installation process by setting up the required steps.
* @param stepTitles An array of step titles representing the installation workflow.
*/
initialSteps: (stepTitles: string[]) => void;
/** Advance to the next step in the installation process. */
nextStep: () => void;
/** Normally the first step (Contain locating or start installation)
* @return A promise resolving to the user's choice of installation method.
*/
starterStep: () => Promise<InstallationMethod>;
/** Clone a Git repository to a user-selected directory.
* @param repositoryUrl The URL of the Git repository to clone.
* @returns A promise resolving to the path of the cloned repository.
*/
cloneRepository: (url: string) => Promise<string>;
/** Execute a terminal script file.
* @param workingDirectory The directory in which to execute the script.
* @param scriptFileName The name of the script file to execute.
* @returns A promise that resolves when execution is complete and the user proceeds.
*/
runTerminalScript: (workingDirectory: string, scriptFileName: string) => Promise<void>;
/** Execute one or more terminal commands.
* @param commands A single command or an array of commands to execute.
* @param workingDirectory Optional directory in which to execute the commands.
* @returns A promise that resolves when execution is complete and the user proceeds.
*/
executeTerminalCommands: (commands: string | string[], workingDirectory?: string) => Promise<void>;
/** Download a file from a given URL.
* @param fileUrl The URL of the file to download.
* @returns A promise resolving to the path of the downloaded file.
*/
downloadFileFromUrl: (fileUrl: string) => Promise<string>;
/**
* Displays a progress bar UI element.
* @param title The title of the progress bar.
* @param isIndeterminate Whether the progress is indeterminate (true) or determinate (false).
* @param percentage The completion percentage (0-100) for determinate progress. Ignored if isIndeterminate is true.
* @param description Optional array of label-value pairs to provide additional information about the progress.
*/
progressBar: (
isIndeterminate: boolean,
title?: string,
percentage?: number,
description?: {
label: string;
value: string;
}[],
) => void;
/** Call this when installation is done to set the card installed
* @param dir The directory to save
*/
setInstalled: (dir: string) => void;
/** Collect user input for various configuration options.
* @param inputFields An array of input fields to present to the user.
* @returns A promise resolving to an array of user input results.
*/
collectUserInput: (inputFields: UserInputField[]) => Promise<UserInputResult[]>;
/** Display the final step of the installation process with a result message.
* @param resultType The type of result: 'success' or 'error'.
* @param resultTitle A title summarizing the result.
* @param resultDescription An optional detailed description of the result.
*/
showFinalStep: (resultType: 'success' | 'error', resultTitle: string, resultDescription?: string) => void;
/**
* Provides access to the renderer process IPC methods.
* Use this to send/receive data or messages between the renderer process and the main process.
*/
ipc: RendererIpcTypes;
/** Use these operations after the `setInstalled` function */
postInstall: {
/**
* Installs a list of extensions for the user
* @param extensionURLs An array of Git repository URLs to clone
* @param extensionsDir The target directory where the extensions will be cloned
* @returns A Promise that resolves when all extensions are installed
*/
installExtensions: (extensionURLs: string[], extensionsDir: string) => Promise<void>;
/**
* Configures the WebUI with the provided settings
* @param configs An object containing configuration options
*/
config: (configs: {
/** If true, automatically updates all extensions when launching WebUI */
autoUpdateExtensions?: boolean;
/** If true, automatically updates the WebUI itself */
autoUpdateCard?: boolean;
/** Pre-defined arguments to pass to the WebUI */
customArguments?: {
/** Name of the preset configuration */
presetName: string;
/** Array of custom arguments */
customArguments: {
/** Name of the argument like --use-cpu */
name: string;
/** Value of the argument
* - Set empty string '', if it's Boolean or CheckBox
*/
value: string;
}[];
};
/** Custom commands to execute instead of the actual command to launch WebUI */
customCommands?: string[];
/** Defines the behavior of the browser and terminal when launching */
launchBehavior?: {
/** Specifies how to open the browser */
browser: 'appBrowser' | 'defaultBrowser' | 'doNothing';
/** Specifies how to handle the terminal */
terminal: 'runScript' | 'empty';
};
/** Actions to perform before launching WebUI */
preLaunch?: {
/** Commands to execute before launch */
preCommands: string[];
/** Paths to open before launch */
openPath: {path: string; type: 'folder' | 'file'}[];
};
}) => void;
};
/** Utility functions that don't involve UI interaction */
utils: {
/** Decompress a file.
* @param compressedFilePath The path to the compressed file.
* @returns A promise resolving to the path of the decompressed data.
*/
decompressFile: (compressedFilePath: string) => Promise<string>;
/** Validate if a local directory matches a given Git repository URL.
* @param localDirectory The local directory to validate.
* @param repositoryUrl The Git repository URL to compare against.
* @returns A promise resolving to true if the directory matches the repository, false otherwise.
*/
validateGitRepository: (localDirectory: string, repositoryUrl: string) => Promise<boolean>;
/** Check for the existence of specified files or folders in a directory.
* @param directory The directory to search in.
* @param itemNames An array of file or folder names to check for.
* @returns A promise resolving to true if all items exist, false otherwise.
*/
verifyFilesExist: (directory: string, itemNames: string[]) => Promise<boolean>;
/** Open a file or folder using the system's default manner.
* @param path Absolute path to open
*/
openFileOrFolder: (itemPath: string) => void;
};
};
/** These methods will be called in the renderer process */
export type CardRendererMethods = {
/** This method will be called with terminal output line parameter
* @return URL of running AI to be showing in browser of the user and
* @return undefined if URL is not in that line */
catchAddress?: (line: string) => string | undefined;
/** Fetching and return array of available extensions in type of `ExtensionData` */
fetchExtensionList?: () => Promise<ExtensionData[]>;
/** Parse the given argument to string */
parseArgsToString?: (args: ChosenArgument[]) => string;
/** Parse given string to the arguments */
parseStringToArgs?: (args: string) => ChosenArgument[];
manager?: {
startInstall: (stepper: InstallationStepper) => void;
updater: {
updateType: 'git' | 'stepper';
startUpdate?: (stepper: InstallationStepper, dir: string) => void;
updateAvailable?: () => boolean;
};
};
};
export type CardData = {
/** ID will be used to managing state of card */
id: string;
/** Card background
*
* **Acceptable sources: **
* - github.com
* - api.github.com
* - *.githubusercontent.com
* - image.civitai.com
*/
bgUrl: string;
/** Url to repository (Using this url recognize, clone and update card) */
repoUrl: string;
/** The title of card */
title: string;
/** Description about what card does */
description: string;
/** The directory of extension (In relative path like '/extensions')
* - Leave undefined if WebUI have no extension ability
*/
extensionsDir?: string;
/** Type of AI (Using type for things like discord activity status) */
type?: 'image' | 'audio' | 'text' | 'unknown';
/** List of all available arguments
* - Leave undefined if WebUI have no arguments to config
*/
arguments?: ArgumentsData;
/** These methods will be called in the renderer process
* @description This methods will be used when user interaction (Like recognizing URL to show in browser)
*/
methods: CardRendererMethods;
};
export type PagesData = {
/** Router path (For placing the card in relative page) */
routePath: AvailablePages;
/** Cards data */
cards: CardData[];
};
export type CardModules = PagesData[];
export type ChosenArgument = {name: string; value: string};
export type ArgumentType = 'Directory' | 'File' | 'Input' | 'DropDown' | 'CheckBox';
export type ArgumentItem = {
name: string;
description?: string;
type: ArgumentType;
defaultValue?: any;
values?: string[];
};
export type ArgumentSection = {
section: string;
items: ArgumentItem[];
};
export type DataSection = {
category: string;
condition?: string;
sections: ArgumentSection[];
};
export type DataItem = {
category: string;
condition?: string;
items: ArgumentItem[];
};
export type ArgumentsData = (DataItem | DataSection)[];
export type ArgType = {name: string; value: string};
export type Category = 'env' | 'envVar' | 'cl' | undefined;
export type MainModules = {
/** The ID of the card that using these methods */
id: string;
/** These methods will be called in the main process
* @description This methods will be used when user interaction (Like run, config, etc.)
*/
methods: CardMainMethods;
};