ogi-addon 1.9.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/{Configuration-CdRZbO6z.d.mts → Configuration-DdkCGFMU.d.cts} +2 -2
- package/build/{Configuration-WeOm-F0_.d.cts → Configuration-fDtr2bmH.d.mts} +2 -2
- package/build/{ConfigurationBuilder-BbZDA_xx.d.mts → ConfigurationBuilder-C83EP5v2.d.cts} +81 -21
- package/build/{ConfigurationBuilder-BSuJ4rSI.cjs → ConfigurationBuilder-CFXi6UwU.cjs} +112 -14
- package/build/ConfigurationBuilder-CFXi6UwU.cjs.map +1 -0
- package/build/{ConfigurationBuilder-CfHLKMTO.d.cts → ConfigurationBuilder-lzKf9gHw.d.mts} +81 -21
- package/build/{EventResponse-CQhmdz3C.d.mts → EventResponse-D0TZjAVC.d.mts} +88 -31
- package/build/{EventResponse-D1c-Df5W.d.cts → EventResponse-DgSuJPu8.d.cts} +88 -31
- package/build/EventResponse.cjs +5 -4
- package/build/EventResponse.cjs.map +1 -1
- package/build/EventResponse.d.cts +1 -1
- package/build/EventResponse.d.mts +1 -1
- package/build/EventResponse.mjs +5 -4
- package/build/EventResponse.mjs.map +1 -1
- package/build/{SearchEngine-CRQWXfo6.d.mts → SearchEngine-Cn_-M-at.d.cts} +5 -2
- package/build/{SearchEngine-DBSUNM4A.d.cts → SearchEngine-lZioNunY.d.mts} +5 -2
- package/build/SearchEngine.d.cts +1 -1
- package/build/SearchEngine.d.mts +1 -1
- package/build/config/Configuration.cjs +6 -3
- package/build/config/Configuration.cjs.map +1 -1
- package/build/config/Configuration.d.cts +3 -3
- package/build/config/Configuration.d.mts +3 -3
- package/build/config/Configuration.mjs +5 -4
- package/build/config/Configuration.mjs.map +1 -1
- package/build/config/ConfigurationBuilder.cjs +3 -1
- package/build/config/ConfigurationBuilder.d.cts +2 -2
- package/build/config/ConfigurationBuilder.d.mts +2 -2
- package/build/config/ConfigurationBuilder.mjs +100 -14
- package/build/config/ConfigurationBuilder.mjs.map +1 -1
- package/build/main.cjs +116 -14
- package/build/main.cjs.map +1 -1
- package/build/main.d.cts +5 -5
- package/build/main.d.mts +5 -5
- package/build/main.mjs +115 -14
- package/build/main.mjs.map +1 -1
- package/package.json +1 -1
- package/src/EventResponse.ts +14 -13
- package/src/SearchEngine.ts +5 -1
- package/src/config/Configuration.ts +13 -3
- package/src/config/ConfigurationBuilder.ts +157 -41
- package/src/main.ts +194 -36
- package/build/ConfigurationBuilder-BSuJ4rSI.cjs.map +0 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
const require_ConfigurationBuilder = require('../ConfigurationBuilder-
|
|
1
|
+
const require_ConfigurationBuilder = require('../ConfigurationBuilder-CFXi6UwU.cjs');
|
|
2
2
|
|
|
3
|
+
exports.ActionOption = require_ConfigurationBuilder.ActionOption;
|
|
3
4
|
exports.BooleanOption = require_ConfigurationBuilder.BooleanOption;
|
|
4
5
|
exports.ConfigurationBuilder = require_ConfigurationBuilder.ConfigurationBuilder;
|
|
5
6
|
exports.ConfigurationOption = require_ConfigurationBuilder.ConfigurationOption;
|
|
6
7
|
exports.NumberOption = require_ConfigurationBuilder.NumberOption;
|
|
7
8
|
exports.StringOption = require_ConfigurationBuilder.StringOption;
|
|
9
|
+
exports.isActionOption = require_ConfigurationBuilder.isActionOption;
|
|
8
10
|
exports.isBooleanOption = require_ConfigurationBuilder.isBooleanOption;
|
|
9
11
|
exports.isNumberOption = require_ConfigurationBuilder.isNumberOption;
|
|
10
12
|
exports.isStringOption = require_ConfigurationBuilder.isStringOption;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { BooleanOption, ConfigurationBuilder, ConfigurationFile, ConfigurationOption, ConfigurationOptionType, NumberOption, StringOption, isBooleanOption, isNumberOption, isStringOption };
|
|
1
|
+
import { a as ConfigurationOption, c as StringOption, d as isNumberOption, f as isStringOption, i as ConfigurationFile, l as isActionOption, n as BooleanOption, o as ConfigurationOptionType, r as ConfigurationBuilder, s as NumberOption, t as ActionOption, u as isBooleanOption } from "../ConfigurationBuilder-C83EP5v2.cjs";
|
|
2
|
+
export { ActionOption, BooleanOption, ConfigurationBuilder, ConfigurationFile, ConfigurationOption, ConfigurationOptionType, NumberOption, StringOption, isActionOption, isBooleanOption, isNumberOption, isStringOption };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { BooleanOption, ConfigurationBuilder, ConfigurationFile, ConfigurationOption, ConfigurationOptionType, NumberOption, StringOption, isBooleanOption, isNumberOption, isStringOption };
|
|
1
|
+
import { a as ConfigurationOption, c as StringOption, d as isNumberOption, f as isStringOption, i as ConfigurationFile, l as isActionOption, n as BooleanOption, o as ConfigurationOptionType, r as ConfigurationBuilder, s as NumberOption, t as ActionOption, u as isBooleanOption } from "../ConfigurationBuilder-lzKf9gHw.mjs";
|
|
2
|
+
export { ActionOption, BooleanOption, ConfigurationBuilder, ConfigurationFile, ConfigurationOption, ConfigurationOptionType, NumberOption, StringOption, isActionOption, isBooleanOption, isNumberOption, isStringOption };
|
|
@@ -15,37 +15,58 @@ function isNumberOption(option) {
|
|
|
15
15
|
function isBooleanOption(option) {
|
|
16
16
|
return option.type === "boolean";
|
|
17
17
|
}
|
|
18
|
+
function isActionOption(option) {
|
|
19
|
+
return option.type === "action";
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A builder for creating configuration screens. The generic type T accumulates
|
|
23
|
+
* the types of all options added to the builder, enabling type-safe access to
|
|
24
|
+
* the configuration values.
|
|
25
|
+
*
|
|
26
|
+
* @template T - The accumulated type of all configuration options
|
|
27
|
+
*/
|
|
18
28
|
var ConfigurationBuilder = class {
|
|
19
29
|
options = [];
|
|
20
30
|
/**
|
|
21
31
|
* Add a number option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.
|
|
22
|
-
* @param option { (option: NumberOption) => NumberOption }
|
|
23
|
-
* @returns
|
|
32
|
+
* @param option { (option: NumberOption) => NumberOption<K> }
|
|
33
|
+
* @returns A new ConfigurationBuilder with the number option's type added
|
|
24
34
|
*/
|
|
25
35
|
addNumberOption(option) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this.options.push(newOption);
|
|
36
|
+
const configuredOption = option(new NumberOption());
|
|
37
|
+
this.options.push(configuredOption);
|
|
29
38
|
return this;
|
|
30
39
|
}
|
|
31
40
|
/**
|
|
32
41
|
* Add a string option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.
|
|
33
|
-
* @param option { (option: StringOption) => StringOption }
|
|
42
|
+
* @param option { (option: StringOption) => StringOption<K> }
|
|
43
|
+
* @returns A new ConfigurationBuilder with the string option's type added
|
|
34
44
|
*/
|
|
35
45
|
addStringOption(option) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.options.push(newOption);
|
|
46
|
+
const configuredOption = option(new StringOption());
|
|
47
|
+
this.options.push(configuredOption);
|
|
39
48
|
return this;
|
|
40
49
|
}
|
|
41
50
|
/**
|
|
42
51
|
* Add a boolean option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.
|
|
43
|
-
* @param option { (option: BooleanOption) => BooleanOption }
|
|
52
|
+
* @param option { (option: BooleanOption) => BooleanOption<K> }
|
|
53
|
+
* @returns A new ConfigurationBuilder with the boolean option's type added
|
|
44
54
|
*/
|
|
45
55
|
addBooleanOption(option) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
this
|
|
56
|
+
const configuredOption = option(new BooleanOption());
|
|
57
|
+
this.options.push(configuredOption);
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Add an action option to the configuration builder and return the builder for chaining.
|
|
62
|
+
* Action options contribute a boolean to the return type (true if clicked, false if not).
|
|
63
|
+
* You must provide a name, display name, and description for the option.
|
|
64
|
+
* @param option { (option: ActionOption) => ActionOption<K> }
|
|
65
|
+
* @returns A new ConfigurationBuilder with the action option's type added as boolean
|
|
66
|
+
*/
|
|
67
|
+
addActionOption(option) {
|
|
68
|
+
const configuredOption = option(new ActionOption());
|
|
69
|
+
this.options.push(configuredOption);
|
|
49
70
|
return this;
|
|
50
71
|
}
|
|
51
72
|
build(includeFunctions) {
|
|
@@ -109,6 +130,14 @@ var StringOption = class extends ConfigurationOption {
|
|
|
109
130
|
inputType = "text";
|
|
110
131
|
type = "string";
|
|
111
132
|
/**
|
|
133
|
+
* Set the name of the option. **REQUIRED**
|
|
134
|
+
* @param name {string} The name of the option. This is used to reference the option in the configuration file.
|
|
135
|
+
*/
|
|
136
|
+
setName(name) {
|
|
137
|
+
this.name = name;
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
112
141
|
* Set the allowed values for the string. If the array is empty, any value is allowed. When provided, the client will act like this option is a dropdown.
|
|
113
142
|
* @param allowedValues {string[]} An array of allowed values for the string. If the array is empty, any value is allowed.
|
|
114
143
|
*/
|
|
@@ -162,6 +191,14 @@ var NumberOption = class extends ConfigurationOption {
|
|
|
162
191
|
type = "number";
|
|
163
192
|
inputType = "number";
|
|
164
193
|
/**
|
|
194
|
+
* Set the name of the option. **REQUIRED**
|
|
195
|
+
* @param name {string} The name of the option. This is used to reference the option in the configuration file.
|
|
196
|
+
*/
|
|
197
|
+
setName(name) {
|
|
198
|
+
this.name = name;
|
|
199
|
+
return this;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
165
202
|
* Set the minimum value for the number. If the user provides a number that is less than this value, the validation will fail.
|
|
166
203
|
* @param min {number} The minimum value for the number.
|
|
167
204
|
*/
|
|
@@ -203,6 +240,14 @@ var BooleanOption = class extends ConfigurationOption {
|
|
|
203
240
|
type = "boolean";
|
|
204
241
|
defaultValue = false;
|
|
205
242
|
/**
|
|
243
|
+
* Set the name of the option. **REQUIRED**
|
|
244
|
+
* @param name {string} The name of the option. This is used to reference the option in the configuration file.
|
|
245
|
+
*/
|
|
246
|
+
setName(name) {
|
|
247
|
+
this.name = name;
|
|
248
|
+
return this;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
206
251
|
* Set the default value for the boolean. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
|
|
207
252
|
* @param defaultValue {boolean} The default value for the boolean.
|
|
208
253
|
*/
|
|
@@ -215,7 +260,48 @@ var BooleanOption = class extends ConfigurationOption {
|
|
|
215
260
|
return [true, ""];
|
|
216
261
|
}
|
|
217
262
|
};
|
|
263
|
+
var ActionOption = class extends ConfigurationOption {
|
|
264
|
+
type = "action";
|
|
265
|
+
manifest = {};
|
|
266
|
+
buttonText = "Run";
|
|
267
|
+
taskName = "";
|
|
268
|
+
/**
|
|
269
|
+
* Set the name of the option. **REQUIRED**
|
|
270
|
+
* @param name {string} The name of the option. This is used to reference the option in the configuration file.
|
|
271
|
+
*/
|
|
272
|
+
setName(name) {
|
|
273
|
+
this.name = name;
|
|
274
|
+
return this;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Set the task name that will be used to identify which task handler to run. This should match the name used in `addon.onTask()`.
|
|
278
|
+
* @param taskName {string} The task name to identify the handler.
|
|
279
|
+
*/
|
|
280
|
+
setTaskName(taskName) {
|
|
281
|
+
this.taskName = taskName;
|
|
282
|
+
return this;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Set the manifest object that will be passed to the task-run handler. The task name should be set via setTaskName() rather than in the manifest.
|
|
286
|
+
* @param manifest {Record<string, unknown>} The manifest object to pass to the task handler.
|
|
287
|
+
*/
|
|
288
|
+
setManifest(manifest) {
|
|
289
|
+
this.manifest = manifest;
|
|
290
|
+
return this;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Set the text displayed on the action button.
|
|
294
|
+
* @param text {string} The button text.
|
|
295
|
+
*/
|
|
296
|
+
setButtonText(text) {
|
|
297
|
+
this.buttonText = text;
|
|
298
|
+
return this;
|
|
299
|
+
}
|
|
300
|
+
validate(_input) {
|
|
301
|
+
return [true, ""];
|
|
302
|
+
}
|
|
303
|
+
};
|
|
218
304
|
|
|
219
305
|
//#endregion
|
|
220
|
-
export { BooleanOption, ConfigurationBuilder, ConfigurationOption, NumberOption, StringOption, isBooleanOption, isNumberOption, isStringOption };
|
|
306
|
+
export { ActionOption, BooleanOption, ConfigurationBuilder, ConfigurationOption, NumberOption, StringOption, isActionOption, isBooleanOption, isNumberOption, isStringOption };
|
|
221
307
|
//# sourceMappingURL=ConfigurationBuilder.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigurationBuilder.mjs","names":[],"sources":["../../src/config/ConfigurationBuilder.ts"],"sourcesContent":["import z, { ZodError } from 'zod';\n\nexport interface ConfigurationFile {\n [key: string]: ConfigurationOption;\n}\n\nconst configValidation = z.object({\n name: z.string().min(1),\n displayName: z.string().min(1),\n description: z.string().min(1),\n});\n\nexport function isStringOption(\n option: ConfigurationOption\n): option is StringOption {\n return option.type === 'string';\n}\n\nexport function isNumberOption(\n option: ConfigurationOption\n): option is NumberOption {\n return option.type === 'number';\n}\n\nexport function isBooleanOption(\n option: ConfigurationOption\n): option is BooleanOption {\n return option.type === 'boolean';\n}\n\nexport class ConfigurationBuilder {\n private options: ConfigurationOption[] = [];\n\n /**\n * Add a number option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.\n * @param option { (option: NumberOption) => NumberOption }\n * @returns\n */\n public addNumberOption(\n option: (option: NumberOption) => NumberOption\n ): ConfigurationBuilder {\n let newOption = new NumberOption();\n newOption = option(newOption);\n this.options.push(newOption);\n return this;\n }\n\n /**\n * Add a string option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.\n * @param option { (option: StringOption) => StringOption }\n */\n public addStringOption(option: (option: StringOption) => StringOption) {\n let newOption = new StringOption();\n newOption = option(newOption);\n this.options.push(newOption);\n return this;\n }\n\n /**\n * Add a boolean option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.\n * @param option { (option: BooleanOption) => BooleanOption }\n */\n public addBooleanOption(option: (option: BooleanOption) => BooleanOption) {\n let newOption = new BooleanOption();\n newOption = option(newOption);\n this.options.push(newOption);\n return this;\n }\n\n public build(includeFunctions: boolean): ConfigurationFile {\n let config: ConfigurationFile = {};\n this.options.forEach((option) => {\n // remove all functions from the option object\n if (!includeFunctions) {\n option = JSON.parse(JSON.stringify(option));\n const optionData = configValidation.safeParse(option);\n if (!optionData.success) {\n throw new ZodError(optionData.error.errors);\n }\n\n config[option.name] = option;\n } else {\n config[option.name] = option;\n }\n });\n return config;\n }\n}\n\nexport type ConfigurationOptionType = 'string' | 'number' | 'boolean' | 'unset';\nexport class ConfigurationOption {\n public name: string = '';\n public defaultValue: unknown = '';\n public displayName: string = '';\n public description: string = '';\n public type: ConfigurationOptionType = 'unset';\n\n /**\n * Set the name of the option. **REQUIRED**\n * @param name {string} The name of the option. This is used to reference the option in the configuration file.\n */\n setName(name: string) {\n this.name = name;\n return this;\n }\n\n /**\n * Set the display name of the option. This is used to show the user a human readable version of what the option is. **REQUIRED**\n * @param displayName {string} The display name of the option.\n * @returns\n */\n setDisplayName(displayName: string) {\n this.displayName = displayName;\n return this;\n }\n\n /**\n * Set the description of the option. This is to show the user a brief description of what this option does. **REQUIRED**\n * @param description {string} The description of the option.\n * @returns\n */\n setDescription(description: string) {\n this.description = description;\n return this;\n }\n\n /**\n * Validation code for the option. This is called when the user provides input to the option. If the validation fails, the user will be prompted to provide input again.\n * @param input {unknown} The input to validate\n */\n validate(input: unknown): [boolean, string] {\n throw new Error('Validation code not implemented. Value: ' + input);\n }\n}\n\nexport class StringOption extends ConfigurationOption {\n public allowedValues: string[] = [];\n public minTextLength: number = 0;\n public maxTextLength: number = Number.MAX_SAFE_INTEGER;\n public defaultValue: string = '';\n public inputType: 'text' | 'file' | 'password' | 'folder' = 'text';\n public type: ConfigurationOptionType = 'string';\n\n /**\n * Set the allowed values for the string. If the array is empty, any value is allowed. When provided, the client will act like this option is a dropdown.\n * @param allowedValues {string[]} An array of allowed values for the string. If the array is empty, any value is allowed.\n */\n setAllowedValues(allowedValues: string[]): this {\n this.allowedValues = allowedValues;\n return this;\n }\n\n /**\n * Set the default value for the string. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\n * @param defaultValue {string} The default value for the string.\n */\n setDefaultValue(defaultValue: string): this {\n this.defaultValue = defaultValue;\n return this;\n }\n\n /**\n * Set the minimum text length for the string. If the user provides a string that is less than this value, the validation will fail.\n * @param minTextLength {number} The minimum text length for the string.\n */\n setMinTextLength(minTextLength: number): this {\n this.minTextLength = minTextLength;\n return this;\n }\n\n /**\n * Set the maximum text length for the string. If the user provides a string that is greater than this value, the validation will fail.\n * @param maxTextLength {number} The maximum text length for the string.\n */\n setMaxTextLength(maxTextLength: number): this {\n this.maxTextLength = maxTextLength;\n return this;\n }\n\n /**\n * Set the input type for the string. This will change how the client renders the input.\n * @param inputType {'text' | 'file' | 'password' | 'folder'} The input type for the string.\n */\n setInputType(inputType: 'text' | 'file' | 'password' | 'folder'): this {\n this.inputType = inputType;\n return this;\n }\n\n override validate(input: unknown): [boolean, string] {\n if (typeof input !== 'string') {\n return [false, 'Input is not a string'];\n }\n if (this.allowedValues.length === 0 && input.length !== 0)\n return [true, ''];\n if (\n input.length < this.minTextLength ||\n input.length > this.maxTextLength\n ) {\n return [\n false,\n 'Input is not within the text length ' +\n this.minTextLength +\n ' and ' +\n this.maxTextLength +\n ' characters (currently ' +\n input.length +\n ' characters)',\n ];\n }\n\n return [\n this.allowedValues.includes(input),\n 'Input is not an allowed value',\n ];\n }\n}\n\nexport class NumberOption extends ConfigurationOption {\n public min: number = 0;\n public max: number = Number.MAX_SAFE_INTEGER;\n public defaultValue: number = 0;\n public type: ConfigurationOptionType = 'number';\n public inputType: 'range' | 'number' = 'number';\n\n /**\n * Set the minimum value for the number. If the user provides a number that is less than this value, the validation will fail.\n * @param min {number} The minimum value for the number.\n */\n setMin(min: number): this {\n this.min = min;\n return this;\n }\n\n /**\n * Set the input type for the number. This will change how the client renders the input.\n * @param type {'range' | 'number'} The input type for the number.\n */\n setInputType(type: 'range' | 'number'): this {\n this.inputType = type;\n return this;\n }\n\n /**\n * Set the maximum value for the number. If the user provides a number that is greater than this value, the validation will fail.\n * @param max {number} The maximum value for the number.\n */\n setMax(max: number): this {\n this.max = max;\n return this;\n }\n\n /**\n * Set the default value for the number. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\n * @param defaultValue {number} The default value for the number.\n */\n setDefaultValue(defaultValue: number): this {\n this.defaultValue = defaultValue;\n return this;\n }\n\n override validate(input: unknown): [boolean, string] {\n if (isNaN(Number(input))) {\n return [false, 'Input is not a number'];\n }\n if (Number(input) < this.min || Number(input) > this.max) {\n return [\n false,\n 'Input is not within the range of ' + this.min + ' and ' + this.max,\n ];\n }\n return [true, ''];\n }\n}\n\nexport class BooleanOption extends ConfigurationOption {\n public type: ConfigurationOptionType = 'boolean';\n public defaultValue: boolean = false;\n\n /**\n * Set the default value for the boolean. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\n * @param defaultValue {boolean} The default value for the boolean.\n */\n setDefaultValue(defaultValue: boolean): this {\n this.defaultValue = defaultValue;\n return this;\n }\n\n override validate(input: unknown): [boolean, string] {\n if (typeof input !== 'boolean') {\n return [false, 'Input is not a boolean'];\n }\n return [true, ''];\n }\n}\n"],"mappings":";;;AAMA,MAAM,mBAAmB,EAAE,OAAO;CAChC,MAAM,EAAE,QAAQ,CAAC,IAAI,EAAE;CACvB,aAAa,EAAE,QAAQ,CAAC,IAAI,EAAE;CAC9B,aAAa,EAAE,QAAQ,CAAC,IAAI,EAAE;CAC/B,CAAC;AAEF,SAAgB,eACd,QACwB;AACxB,QAAO,OAAO,SAAS;;AAGzB,SAAgB,eACd,QACwB;AACxB,QAAO,OAAO,SAAS;;AAGzB,SAAgB,gBACd,QACyB;AACzB,QAAO,OAAO,SAAS;;AAGzB,IAAa,uBAAb,MAAkC;CAChC,AAAQ,UAAiC,EAAE;;;;;;CAO3C,AAAO,gBACL,QACsB;EACtB,IAAI,YAA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CAAC,MAAM,GAAG;;;AAIrB,IAAa,gBAAb,cAAmC,oBAAoB;CACrD,AAAO,OAAgC;CACvC,AAAO,eAAwB;;;;;CAM/B,gBAAgB,cAA6B;AAC3C,OAAK,eAAe;AACpB,SAAO;;CAGT,AAAS,SAAS,OAAmC;AACnD,MAAI,OAAO,UAAU,UACnB,QAAO,CAAC,OAAO,yBAAyB;AAE1C,SAAO,CAAC,MAAM,GAAG"}
|
|
1
|
+
{"version":3,"file":"ConfigurationBuilder.mjs","names":[],"sources":["../../src/config/ConfigurationBuilder.ts"],"sourcesContent":["import z, { ZodError } from 'zod';\n\nexport interface ConfigurationFile {\n [key: string]: ConfigurationOption<string>;\n}\n\nconst configValidation = z.object({\n name: z.string().min(1),\n displayName: z.string().min(1),\n description: z.string().min(1),\n});\n\nexport function isStringOption<N extends string = string>(\n option: ConfigurationOption<N>\n): option is StringOption<N> {\n return option.type === 'string';\n}\n\nexport function isNumberOption<N extends string = string>(\n option: ConfigurationOption<N>\n): option is NumberOption<N> {\n return option.type === 'number';\n}\n\nexport function isBooleanOption<N extends string = string>(\n option: ConfigurationOption<N>\n): option is BooleanOption<N> {\n return option.type === 'boolean';\n}\n\nexport function isActionOption<N extends string = string>(\n option: ConfigurationOption<N>\n): option is ActionOption<N> {\n return option.type === 'action';\n}\n\n/**\n * A builder for creating configuration screens. The generic type T accumulates\n * the types of all options added to the builder, enabling type-safe access to\n * the configuration values.\n * \n * @template T - The accumulated type of all configuration options\n */\nexport class ConfigurationBuilder<\n T extends Record<string, string | number | boolean> = {}\n> {\n private options: ConfigurationOption<string>[] = [];\n\n /**\n * Add a number option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.\n * @param option { (option: NumberOption) => NumberOption<K> }\n * @returns A new ConfigurationBuilder with the number option's type added\n */\n public addNumberOption<K extends string>(\n option: (option: NumberOption) => NumberOption<K>\n ): ConfigurationBuilder<T & { [P in K]: number }> {\n let newOption = new NumberOption();\n const configuredOption = option(newOption);\n this.options.push(configuredOption);\n return this as unknown as ConfigurationBuilder<T & { [P in K]: number }>;\n }\n\n /**\n * Add a string option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.\n * @param option { (option: StringOption) => StringOption<K> }\n * @returns A new ConfigurationBuilder with the string option's type added\n */\n public addStringOption<K extends string>(\n option: (option: StringOption) => StringOption<K>\n ): ConfigurationBuilder<T & { [P in K]: string }> {\n let newOption = new StringOption();\n const configuredOption = option(newOption);\n this.options.push(configuredOption);\n return this as unknown as ConfigurationBuilder<T & { [P in K]: string }>;\n }\n\n /**\n * Add a boolean option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.\n * @param option { (option: BooleanOption) => BooleanOption<K> }\n * @returns A new ConfigurationBuilder with the boolean option's type added\n */\n public addBooleanOption<K extends string>(\n option: (option: BooleanOption) => BooleanOption<K>\n ): ConfigurationBuilder<T & { [P in K]: boolean }> {\n let newOption = new BooleanOption();\n const configuredOption = option(newOption);\n this.options.push(configuredOption);\n return this as unknown as ConfigurationBuilder<T & { [P in K]: boolean }>;\n }\n\n /**\n * Add an action option to the configuration builder and return the builder for chaining. \n * Action options contribute a boolean to the return type (true if clicked, false if not).\n * You must provide a name, display name, and description for the option.\n * @param option { (option: ActionOption) => ActionOption<K> }\n * @returns A new ConfigurationBuilder with the action option's type added as boolean\n */\n public addActionOption<K extends string>(\n option: (option: ActionOption) => ActionOption<K>\n ): ConfigurationBuilder<T & { [P in K]: boolean }> {\n let newOption = new ActionOption();\n const configuredOption = option(newOption);\n this.options.push(configuredOption);\n return this as unknown as ConfigurationBuilder<T & { [P in K]: boolean }>;\n }\n\n public build(includeFunctions: boolean): ConfigurationFile {\n let config: ConfigurationFile = {};\n this.options.forEach((option) => {\n // remove all functions from the option object\n if (!includeFunctions) {\n option = JSON.parse(JSON.stringify(option));\n const optionData = configValidation.safeParse(option);\n if (!optionData.success) {\n throw new ZodError(optionData.error.errors);\n }\n\n config[option.name] = option;\n } else {\n config[option.name] = option;\n }\n });\n return config;\n }\n}\n\nexport type ConfigurationOptionType =\n | 'string'\n | 'number'\n | 'boolean'\n | 'action'\n | 'unset';\nexport class ConfigurationOption<N extends string = string> {\n public name: N = '' as N;\n public defaultValue: unknown = '';\n public displayName: string = '';\n public description: string = '';\n public type: ConfigurationOptionType = 'unset';\n\n /**\n * Set the name of the option. **REQUIRED**\n * @param name {string} The name of the option. This is used to reference the option in the configuration file.\n */\n setName<K extends string>(name: K): ConfigurationOption<K> {\n this.name = name as unknown as N;\n return this as unknown as ConfigurationOption<K>;\n }\n\n /**\n * Set the display name of the option. This is used to show the user a human readable version of what the option is. **REQUIRED**\n * @param displayName {string} The display name of the option.\n * @returns\n */\n setDisplayName(displayName: string): this {\n this.displayName = displayName;\n return this;\n }\n\n /**\n * Set the description of the option. This is to show the user a brief description of what this option does. **REQUIRED**\n * @param description {string} The description of the option.\n * @returns\n */\n setDescription(description: string): this {\n this.description = description;\n return this;\n }\n\n /**\n * Validation code for the option. This is called when the user provides input to the option. If the validation fails, the user will be prompted to provide input again.\n * @param input {unknown} The input to validate\n */\n validate(input: unknown): [boolean, string] {\n throw new Error('Validation code not implemented. Value: ' + input);\n }\n}\n\nexport class StringOption<N extends string = string> extends ConfigurationOption<N> {\n public allowedValues: string[] = [];\n public minTextLength: number = 0;\n public maxTextLength: number = Number.MAX_SAFE_INTEGER;\n public defaultValue: string = '';\n public inputType: 'text' | 'file' | 'password' | 'folder' = 'text';\n public type: ConfigurationOptionType = 'string';\n\n /**\n * Set the name of the option. **REQUIRED**\n * @param name {string} The name of the option. This is used to reference the option in the configuration file.\n */\n override setName<K extends string>(name: K): StringOption<K> {\n this.name = name as unknown as N;\n return this as unknown as StringOption<K>;\n }\n\n /**\n * Set the allowed values for the string. If the array is empty, any value is allowed. When provided, the client will act like this option is a dropdown.\n * @param allowedValues {string[]} An array of allowed values for the string. If the array is empty, any value is allowed.\n */\n setAllowedValues(allowedValues: string[]): this {\n this.allowedValues = allowedValues;\n return this;\n }\n\n /**\n * Set the default value for the string. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\n * @param defaultValue {string} The default value for the string.\n */\n setDefaultValue(defaultValue: string): this {\n this.defaultValue = defaultValue;\n return this;\n }\n\n /**\n * Set the minimum text length for the string. If the user provides a string that is less than this value, the validation will fail.\n * @param minTextLength {number} The minimum text length for the string.\n */\n setMinTextLength(minTextLength: number): this {\n this.minTextLength = minTextLength;\n return this;\n }\n\n /**\n * Set the maximum text length for the string. If the user provides a string that is greater than this value, the validation will fail.\n * @param maxTextLength {number} The maximum text length for the string.\n */\n setMaxTextLength(maxTextLength: number): this {\n this.maxTextLength = maxTextLength;\n return this;\n }\n\n /**\n * Set the input type for the string. This will change how the client renders the input.\n * @param inputType {'text' | 'file' | 'password' | 'folder'} The input type for the string.\n */\n setInputType(inputType: 'text' | 'file' | 'password' | 'folder'): this {\n this.inputType = inputType;\n return this;\n }\n\n override validate(input: unknown): [boolean, string] {\n if (typeof input !== 'string') {\n return [false, 'Input is not a string'];\n }\n if (this.allowedValues.length === 0 && input.length !== 0)\n return [true, ''];\n if (\n input.length < this.minTextLength ||\n input.length > this.maxTextLength\n ) {\n return [\n false,\n 'Input is not within the text length ' +\n this.minTextLength +\n ' and ' +\n this.maxTextLength +\n ' characters (currently ' +\n input.length +\n ' characters)',\n ];\n }\n\n return [\n this.allowedValues.includes(input),\n 'Input is not an allowed value',\n ];\n }\n}\n\nexport class NumberOption<N extends string = string> extends ConfigurationOption<N> {\n public min: number = 0;\n public max: number = Number.MAX_SAFE_INTEGER;\n public defaultValue: number = 0;\n public type: ConfigurationOptionType = 'number';\n public inputType: 'range' | 'number' = 'number';\n\n /**\n * Set the name of the option. **REQUIRED**\n * @param name {string} The name of the option. This is used to reference the option in the configuration file.\n */\n override setName<K extends string>(name: K): NumberOption<K> {\n this.name = name as unknown as N;\n return this as unknown as NumberOption<K>;\n }\n\n /**\n * Set the minimum value for the number. If the user provides a number that is less than this value, the validation will fail.\n * @param min {number} The minimum value for the number.\n */\n setMin(min: number): this {\n this.min = min;\n return this;\n }\n\n /**\n * Set the input type for the number. This will change how the client renders the input.\n * @param type {'range' | 'number'} The input type for the number.\n */\n setInputType(type: 'range' | 'number'): this {\n this.inputType = type;\n return this;\n }\n\n /**\n * Set the maximum value for the number. If the user provides a number that is greater than this value, the validation will fail.\n * @param max {number} The maximum value for the number.\n */\n setMax(max: number): this {\n this.max = max;\n return this;\n }\n\n /**\n * Set the default value for the number. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\n * @param defaultValue {number} The default value for the number.\n */\n setDefaultValue(defaultValue: number): this {\n this.defaultValue = defaultValue;\n return this;\n }\n\n override validate(input: unknown): [boolean, string] {\n if (isNaN(Number(input))) {\n return [false, 'Input is not a number'];\n }\n if (Number(input) < this.min || Number(input) > this.max) {\n return [\n false,\n 'Input is not within the range of ' + this.min + ' and ' + this.max,\n ];\n }\n return [true, ''];\n }\n}\n\nexport class BooleanOption<N extends string = string> extends ConfigurationOption<N> {\n public type: ConfigurationOptionType = 'boolean';\n public defaultValue: boolean = false;\n\n /**\n * Set the name of the option. **REQUIRED**\n * @param name {string} The name of the option. This is used to reference the option in the configuration file.\n */\n override setName<K extends string>(name: K): BooleanOption<K> {\n this.name = name as unknown as N;\n return this as unknown as BooleanOption<K>;\n }\n\n /**\n * Set the default value for the boolean. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\n * @param defaultValue {boolean} The default value for the boolean.\n */\n setDefaultValue(defaultValue: boolean): this {\n this.defaultValue = defaultValue;\n return this;\n }\n\n override validate(input: unknown): [boolean, string] {\n if (typeof input !== 'boolean') {\n return [false, 'Input is not a boolean'];\n }\n return [true, ''];\n }\n}\n\nexport class ActionOption<N extends string = string> extends ConfigurationOption<N> {\n public type: ConfigurationOptionType = 'action';\n public manifest: Record<string, unknown> = {};\n public buttonText: string = 'Run';\n public taskName: string = '';\n\n /**\n * Set the name of the option. **REQUIRED**\n * @param name {string} The name of the option. This is used to reference the option in the configuration file.\n */\n override setName<K extends string>(name: K): ActionOption<K> {\n this.name = name as unknown as N;\n return this as unknown as ActionOption<K>;\n }\n\n /**\n * Set the task name that will be used to identify which task handler to run. This should match the name used in `addon.onTask()`.\n * @param taskName {string} The task name to identify the handler.\n */\n setTaskName(taskName: string): this {\n this.taskName = taskName;\n return this;\n }\n\n /**\n * Set the manifest object that will be passed to the task-run handler. The task name should be set via setTaskName() rather than in the manifest.\n * @param manifest {Record<string, unknown>} The manifest object to pass to the task handler.\n */\n setManifest(manifest: Record<string, unknown>): this {\n this.manifest = manifest;\n return this;\n }\n\n /**\n * Set the text displayed on the action button.\n * @param text {string} The button text.\n */\n setButtonText(text: string): this {\n this.buttonText = text;\n return this;\n }\n\n override validate(_input: unknown): [boolean, string] {\n return [true, ''];\n }\n}\n"],"mappings":";;;AAMA,MAAM,mBAAmB,EAAE,OAAO;CAChC,MAAM,EAAE,QAAQ,CAAC,IAAI,EAAE;CACvB,aAAa,EAAE,QAAQ,CAAC,IAAI,EAAE;CAC9B,aAAa,EAAE,QAAQ,CAAC,IAAI,EAAE;CAC/B,CAAC;AAEF,SAAgB,eACd,QAC2B;AAC3B,QAAO,OAAO,SAAS;;AAGzB,SAAgB,eACd,QAC2B;AAC3B,QAAO,OAAO,SAAS;;AAGzB,SAAgB,gBACd,QAC4B;AAC5B,QAAO,OAAO,SAAS;;AAGzB,SAAgB,eACd,QAC2B;AAC3B,QAAO,OAAO,SAAS;;;;;;;;;AAUzB,IAAa,uBAAb,MAEE;CACA,AAAQ,UAAyC,EAAE;;;;;;CAOnD,AAAO,gBACL,QACgD;EAEhD,MAAM,mBAAmB,OADT,IAAI,cAAc,CACQ;AAC1C,OAAK,QAAQ,KAAK,iBAAiB;AACnC,SAAO;;;;;;;CAQT,AAAO,gBACL,QACgD;EAEhD,MAAM,mBAAmB,OADT,IAAI,cAAc,CACQ;AAC1C,OAAK,QAAQ,KAAK,iBAAiB;AACnC,SAAO;;;;;;;CAQT,AAAO,iBACL,QACiD;EAEjD,MAAM,mBAAmB,OADT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,gBAAb,cAA8D,oBAAuB;CACnF,AAAO,OAAgC;CACvC,AAAO,eAAwB;;;;;CAM/B,AAAS,QAA0B,MAA2B;AAC5D,OAAK,OAAO;AACZ,SAAO;;;;;;CAOT,gBAAgB,cAA6B;AAC3C,OAAK,eAAe;AACpB,SAAO;;CAGT,AAAS,SAAS,OAAmC;AACnD,MAAI,OAAO,UAAU,UACnB,QAAO,CAAC,OAAO,yBAAyB;AAE1C,SAAO,CAAC,MAAM,GAAG;;;AAIrB,IAAa,eAAb,cAA6D,oBAAuB;CAClF,AAAO,OAAgC;CACvC,AAAO,WAAoC,EAAE;CAC7C,AAAO,aAAqB;CAC5B,AAAO,WAAmB;;;;;CAM1B,AAAS,QAA0B,MAA0B;AAC3D,OAAK,OAAO;AACZ,SAAO;;;;;;CAOT,YAAY,UAAwB;AAClC,OAAK,WAAW;AAChB,SAAO;;;;;;CAOT,YAAY,UAAyC;AACnD,OAAK,WAAW;AAChB,SAAO;;;;;;CAOT,cAAc,MAAoB;AAChC,OAAK,aAAa;AAClB,SAAO;;CAGT,AAAS,SAAS,QAAoC;AACpD,SAAO,CAAC,MAAM,GAAG"}
|
package/build/main.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
-
const require_ConfigurationBuilder = require('./ConfigurationBuilder-
|
|
2
|
+
const require_ConfigurationBuilder = require('./ConfigurationBuilder-CFXi6UwU.cjs');
|
|
3
3
|
const require_EventResponse = require('./EventResponse.cjs');
|
|
4
4
|
const require_config_Configuration = require('./config/Configuration.cjs');
|
|
5
5
|
let ws = require("ws");
|
|
@@ -14,7 +14,7 @@ let node_fs = require("node:fs");
|
|
|
14
14
|
node_fs = require_ConfigurationBuilder.__toESM(node_fs);
|
|
15
15
|
|
|
16
16
|
//#region package.json
|
|
17
|
-
var version = "
|
|
17
|
+
var version = "2.0.0";
|
|
18
18
|
|
|
19
19
|
//#endregion
|
|
20
20
|
//#region src/main.ts
|
|
@@ -42,6 +42,7 @@ var OGIAddon = class {
|
|
|
42
42
|
config = new require_config_Configuration.Configuration({});
|
|
43
43
|
eventsAvailable = [];
|
|
44
44
|
registeredConnectEvent = false;
|
|
45
|
+
taskHandlers = /* @__PURE__ */ new Map();
|
|
45
46
|
constructor(addonInfo) {
|
|
46
47
|
this.addonInfo = addonInfo;
|
|
47
48
|
this.addonWSListener = new OGIAddonWSListener(this, this.eventEmitter);
|
|
@@ -115,6 +116,40 @@ var OGIAddon = class {
|
|
|
115
116
|
return task;
|
|
116
117
|
}
|
|
117
118
|
/**
|
|
119
|
+
* Register a task handler for a specific task name. The task name should match the taskName field in SearchResult or ActionOption.
|
|
120
|
+
* @param taskName {string} The name of the task (should match taskName in SearchResult or ActionOption.setTaskName()).
|
|
121
|
+
* @param handler {(task: Task, data: { manifest: Record<string, unknown>; downloadPath: string; name: string }) => Promise<void> | void} The handler function.
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* addon.onTask('clearCache', async (task) => {
|
|
125
|
+
* task.log('Clearing cache...');
|
|
126
|
+
* task.setProgress(50);
|
|
127
|
+
* await clearCacheFiles();
|
|
128
|
+
* task.setProgress(100);
|
|
129
|
+
* task.complete();
|
|
130
|
+
* });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
onTask(taskName, handler) {
|
|
134
|
+
this.taskHandlers.set(taskName, handler);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Check if a task handler is registered for the given task name.
|
|
138
|
+
* @param taskName {string} The task name to check.
|
|
139
|
+
* @returns {boolean} True if a handler is registered.
|
|
140
|
+
*/
|
|
141
|
+
hasTaskHandler(taskName) {
|
|
142
|
+
return this.taskHandlers.has(taskName);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get a task handler for the given task name.
|
|
146
|
+
* @param taskName {string} The task name.
|
|
147
|
+
* @returns The handler function or undefined if not found.
|
|
148
|
+
*/
|
|
149
|
+
getTaskHandler(taskName) {
|
|
150
|
+
return this.taskHandlers.get(taskName);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
118
153
|
* Extract a file using 7-Zip on Windows, unzip on Linux/Mac.
|
|
119
154
|
* @param path {string}
|
|
120
155
|
* @param outputPath {string}
|
|
@@ -237,6 +272,57 @@ var CustomTask = class {
|
|
|
237
272
|
}
|
|
238
273
|
};
|
|
239
274
|
/**
|
|
275
|
+
* A cleaner API wrapper around EventResponse for task handlers.
|
|
276
|
+
* Provides chainable methods for logging, progress updates, and completion.
|
|
277
|
+
*/
|
|
278
|
+
var Task = class {
|
|
279
|
+
event;
|
|
280
|
+
constructor(event) {
|
|
281
|
+
this.event = event;
|
|
282
|
+
this.event.defer();
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Log a message to the task. Returns this for chaining.
|
|
286
|
+
* @param message {string} The message to log.
|
|
287
|
+
*/
|
|
288
|
+
log(message) {
|
|
289
|
+
this.event.log(message);
|
|
290
|
+
return this;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Set the progress of the task (0-100). Returns this for chaining.
|
|
294
|
+
* @param progress {number} The progress value (0-100).
|
|
295
|
+
*/
|
|
296
|
+
setProgress(progress) {
|
|
297
|
+
this.event.progress = progress;
|
|
298
|
+
return this;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Complete the task successfully.
|
|
302
|
+
*/
|
|
303
|
+
complete() {
|
|
304
|
+
this.event.complete();
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Fail the task with an error message.
|
|
308
|
+
* @param message {string} The error message.
|
|
309
|
+
*/
|
|
310
|
+
fail(message) {
|
|
311
|
+
this.event.fail(message);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Ask the user for input using a ConfigurationBuilder screen.
|
|
315
|
+
* The return type is inferred from the ConfigurationBuilder's accumulated option types.
|
|
316
|
+
* @param name {string} The name/title of the input prompt.
|
|
317
|
+
* @param description {string} The description of what input is needed.
|
|
318
|
+
* @param screen {ConfigurationBuilder<U>} The configuration builder for the input form.
|
|
319
|
+
* @returns {Promise<U>} The user's input with types matching the configuration options.
|
|
320
|
+
*/
|
|
321
|
+
async askForInput(name, description, screen) {
|
|
322
|
+
return this.event.askForInput(name, description, screen);
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
240
326
|
* A search tool wrapper over Fuse.js for the OGI Addon. This tool is used to search for items in the library.
|
|
241
327
|
* @example
|
|
242
328
|
* ```typescript
|
|
@@ -337,7 +423,7 @@ var OGIAddonWSListener = class {
|
|
|
337
423
|
async userInputAsked(configBuilt, name, description, socket) {
|
|
338
424
|
const config = configBuilt.build(false);
|
|
339
425
|
const id = Math.random().toString(36).substring(7);
|
|
340
|
-
if (!socket)
|
|
426
|
+
if (!socket) throw new Error("Socket is not connected");
|
|
341
427
|
socket.send(JSON.stringify({
|
|
342
428
|
event: "input-asked",
|
|
343
429
|
args: {
|
|
@@ -431,19 +517,34 @@ var OGIAddonWSListener = class {
|
|
|
431
517
|
break;
|
|
432
518
|
case "task-run": {
|
|
433
519
|
let taskRunEvent = new require_EventResponse((screen, name, description) => this.userInputAsked(screen, name, description, this.socket));
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
520
|
+
const taskName = message.args.taskName && typeof message.args.taskName === "string" ? message.args.taskName : message.args.manifest && typeof message.args.manifest === "object" ? message.args.manifest.__taskName : void 0;
|
|
521
|
+
if (taskName && typeof taskName === "string" && this.addon.hasTaskHandler(taskName)) {
|
|
522
|
+
const handler = this.addon.getTaskHandler(taskName);
|
|
523
|
+
const task = new Task(taskRunEvent);
|
|
524
|
+
try {
|
|
525
|
+
const interval = setInterval(() => {
|
|
526
|
+
if (taskRunEvent.resolved) {
|
|
527
|
+
clearInterval(interval);
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
this.send("defer-update", {
|
|
531
|
+
logs: taskRunEvent.logs,
|
|
532
|
+
deferID: message.args.deferID,
|
|
533
|
+
progress: taskRunEvent.progress,
|
|
534
|
+
failed: taskRunEvent.failed
|
|
535
|
+
});
|
|
536
|
+
}, 100);
|
|
537
|
+
const result$1 = handler(task, {
|
|
538
|
+
manifest: message.args.manifest || {},
|
|
539
|
+
downloadPath: message.args.downloadPath || "",
|
|
540
|
+
name: message.args.name || ""
|
|
541
|
+
});
|
|
542
|
+
if (result$1 instanceof Promise) await result$1;
|
|
437
543
|
clearInterval(interval);
|
|
438
|
-
|
|
544
|
+
} catch (error) {
|
|
545
|
+
taskRunEvent.fail(error instanceof Error ? error.message : String(error));
|
|
439
546
|
}
|
|
440
|
-
|
|
441
|
-
logs: taskRunEvent.logs,
|
|
442
|
-
deferID: message.args.deferID,
|
|
443
|
-
progress: taskRunEvent.progress,
|
|
444
|
-
failed: taskRunEvent.failed
|
|
445
|
-
});
|
|
446
|
-
}, 100);
|
|
547
|
+
} else taskRunEvent.fail(taskName ? `No task handler registered for task name: ${taskName}` : "No task name provided");
|
|
447
548
|
const taskRunResult = await this.waitForEventToRespond(taskRunEvent);
|
|
448
549
|
this.respondToMessage(message.id, taskRunResult.data, taskRunEvent);
|
|
449
550
|
break;
|
|
@@ -516,6 +617,7 @@ exports.ConfigurationBuilder = require_ConfigurationBuilder.ConfigurationBuilder
|
|
|
516
617
|
exports.CustomTask = CustomTask;
|
|
517
618
|
exports.EventResponse = require_EventResponse;
|
|
518
619
|
exports.SearchTool = SearchTool;
|
|
620
|
+
exports.Task = Task;
|
|
519
621
|
exports.VERSION = VERSION;
|
|
520
622
|
exports.ZodLibraryInfo = ZodLibraryInfo;
|
|
521
623
|
exports.default = OGIAddon;
|