@rollrook-ai/plugin-cli 0.0.0-stage → 0.1.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/bin/rollrook-plugin.js +2 -0
- package/dist/cli.d.ts +25 -0
- package/dist/cli.js +194 -0
- package/dist/cli.js.map +1 -0
- package/dist/errors.d.ts +10 -0
- package/dist/errors.js +12 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +3 -0
- package/dist/main.js.map +1 -0
- package/dist/manifest.d.ts +200 -0
- package/dist/manifest.js +723 -0
- package/dist/manifest.js.map +1 -0
- package/dist/packer.d.ts +44 -0
- package/dist/packer.js +78 -0
- package/dist/packer.js.map +1 -0
- package/dist/project.d.ts +59 -0
- package/dist/project.js +149 -0
- package/dist/project.js.map +1 -0
- package/dist/scaffold.d.ts +49 -0
- package/dist/scaffold.js +127 -0
- package/dist/scaffold.js.map +1 -0
- package/dist/vite.d.ts +40 -0
- package/dist/vite.js +124 -0
- package/dist/vite.js.map +1 -0
- package/package.json +49 -4
- package/src/cli.ts +206 -0
- package/src/errors.ts +11 -0
- package/src/index.ts +24 -0
- package/src/main.ts +3 -0
- package/src/manifest.ts +882 -0
- package/src/packer.ts +104 -0
- package/src/project.ts +168 -0
- package/src/scaffold.ts +156 -0
- package/src/vite.ts +136 -0
- package/template/README.md +12 -0
- package/template/_gitignore +4 -0
- package/template/icon.svg +14 -0
- package/template/index.html +33 -0
- package/template/package.json +22 -0
- package/template/rollrook-plugin.json +18 -0
- package/template/src/main.ts +78 -0
- package/template/src/style.css +35 -0
- package/template/src/vite-env.d.ts +1 -0
- package/template/tsconfig.json +18 -0
- package/template/vite.config.ts +10 -0
- package/README.md +0 -3
package/dist/manifest.js
ADDED
|
@@ -0,0 +1,723 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { extname, isAbsolute, join } from "node:path";
|
|
3
|
+
/** Checks `rollrook-plugin.json` against the rules RollRook installs by. */
|
|
4
|
+
export class ManifestValidator {
|
|
5
|
+
/** The manifest's file name, at the plugin's root. */
|
|
6
|
+
static MANIFEST_FILE = "rollrook-plugin.json";
|
|
7
|
+
/** Two or more dot-separated parts of lowercase letters, digits and dashes. */
|
|
8
|
+
static ID_PATTERN = /^[a-z0-9-]+(\.[a-z0-9-]+)+$/;
|
|
9
|
+
/** Semantic versioning 2.0.0. */
|
|
10
|
+
static SEMVER_PATTERN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
11
|
+
/** A host name for `net:<host>`, optionally with a leading `*.` for its subdomains. */
|
|
12
|
+
static HOST_PATTERN = /^(\*\.)?([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)*[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
|
|
13
|
+
/** The permissions a plugin may ask for, besides `net:<host>`. */
|
|
14
|
+
static LIST_KNOWN_PERMISSIONS = ["raven", "agents.read", "audio", "video"];
|
|
15
|
+
/** What every plugin has without asking; listing them is refused as unknown. */
|
|
16
|
+
static LIST_DEFAULT_PERMISSIONS = ["context", "storage", "files", "settings", "ui", "system", "plugin"];
|
|
17
|
+
/** A view's id: lowercase letters, digits and dashes. */
|
|
18
|
+
static VIEW_ID_PATTERN = /^[a-z0-9-]+$/;
|
|
19
|
+
/** The slots a view may show in. */
|
|
20
|
+
static LIST_SLOTS = ["dock", "sidebar", "footbar", "popover", "settings", "background"];
|
|
21
|
+
/** The fields each slot takes besides `id`, `slot` and `entry`. */
|
|
22
|
+
static map_slot_fields = {
|
|
23
|
+
dock: ["title", "icon"],
|
|
24
|
+
sidebar: ["title", "icon"],
|
|
25
|
+
footbar: ["width", "align", "order"],
|
|
26
|
+
popover: ["width", "height"],
|
|
27
|
+
settings: ["height"],
|
|
28
|
+
background: [],
|
|
29
|
+
};
|
|
30
|
+
/** A tool's name: snake_case words of lowercase letters and digits joined by single underscores, a letter first. */
|
|
31
|
+
static TOOL_NAME_PATTERN = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/;
|
|
32
|
+
/** The longest a tool's name may be; RollRook prefixes it with the plugin's name for the assistant. */
|
|
33
|
+
static TOOL_NAME_MAX_LENGTH = 32;
|
|
34
|
+
/** The most tools a plugin may give the assistant. */
|
|
35
|
+
static TOOL_LIMIT = 40;
|
|
36
|
+
/** The longest the calendar layer's title may be. */
|
|
37
|
+
static CALENDAR_TITLE_MAX_LENGTH = 40;
|
|
38
|
+
/** The fields `contributes` takes. */
|
|
39
|
+
static LIST_CONTRIBUTION_FIELDS = ["calendar", "raven"];
|
|
40
|
+
/** The fields a tool takes. */
|
|
41
|
+
static LIST_TOOL_FIELDS = ["name", "description", "input", "confirm"];
|
|
42
|
+
/** The extension of the assistant's skill file. */
|
|
43
|
+
static SKILL_EXTENSION = ".md";
|
|
44
|
+
/** The slots a plugin needs at least one view in: the others are opened from those. */
|
|
45
|
+
static LIST_STANDING_SLOTS = ["dock", "sidebar", "footbar"];
|
|
46
|
+
/** A settings view's height when the manifest gives none, in points. */
|
|
47
|
+
static SETTINGS_DEFAULT_HEIGHT = 320;
|
|
48
|
+
/** The widest a footbar view may be, in points. */
|
|
49
|
+
static FOOTBAR_MAX_WIDTH = 600;
|
|
50
|
+
/** The largest a popover may be either way, in points. */
|
|
51
|
+
static POPOVER_MAX_SIZE = 800;
|
|
52
|
+
/** The kinds of value a setting holds. */
|
|
53
|
+
static LIST_SETTING_TYPES = ["string", "number", "boolean", "enum", "json"];
|
|
54
|
+
/** The longest a setting's key may be. */
|
|
55
|
+
static SETTING_KEY_MAX_LENGTH = 200;
|
|
56
|
+
/** The id of the view the older form's `main` page becomes. */
|
|
57
|
+
static MAIN_VIEW_ID = "main";
|
|
58
|
+
/** The prefix of a network permission. */
|
|
59
|
+
static NET_PREFIX = "net:";
|
|
60
|
+
/** The permission to reach any site. */
|
|
61
|
+
static NET_ANY_PERMISSION = "net:*";
|
|
62
|
+
/** The bytes of a PNG up to the end of its size in the IHDR chunk. */
|
|
63
|
+
static PNG_HEADER_LENGTH = 24;
|
|
64
|
+
/** The icon formats RollRook shows. */
|
|
65
|
+
static LIST_ICON_EXTENSIONS = [".png", ".svg"];
|
|
66
|
+
/** The fields the manifest defines. */
|
|
67
|
+
static LIST_FIELDS = [
|
|
68
|
+
"id",
|
|
69
|
+
"name",
|
|
70
|
+
"version",
|
|
71
|
+
"description",
|
|
72
|
+
"publisher",
|
|
73
|
+
"main",
|
|
74
|
+
"icon",
|
|
75
|
+
"views",
|
|
76
|
+
"settings",
|
|
77
|
+
"permissions",
|
|
78
|
+
"contributes",
|
|
79
|
+
"minRollRook",
|
|
80
|
+
"repository",
|
|
81
|
+
];
|
|
82
|
+
/**
|
|
83
|
+
* Read and check the manifest in a folder.
|
|
84
|
+
*
|
|
85
|
+
* @param folder - the plugin's folder
|
|
86
|
+
* @returns the manifest and its problems
|
|
87
|
+
*/
|
|
88
|
+
static read(folder) {
|
|
89
|
+
const path = join(folder, ManifestValidator.MANIFEST_FILE);
|
|
90
|
+
if (!existsSync(path)) {
|
|
91
|
+
return ManifestValidator.failed(`no ${ManifestValidator.MANIFEST_FILE} in ${folder}`);
|
|
92
|
+
}
|
|
93
|
+
let raw;
|
|
94
|
+
try {
|
|
95
|
+
raw = JSON.parse(readFileSync(path, "utf8"));
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
if (err instanceof SyntaxError) {
|
|
99
|
+
return ManifestValidator.failed(`${ManifestValidator.MANIFEST_FILE} is not valid JSON: ${err.message}`);
|
|
100
|
+
}
|
|
101
|
+
throw err;
|
|
102
|
+
}
|
|
103
|
+
return ManifestValidator.check(raw, { folder });
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Check a parsed manifest.
|
|
107
|
+
*
|
|
108
|
+
* @param raw - the parsed JSON
|
|
109
|
+
* @param options - the folder to look for `main` and `icon` in
|
|
110
|
+
* @returns the manifest and its problems
|
|
111
|
+
*/
|
|
112
|
+
static check(raw, options = {}) {
|
|
113
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
114
|
+
return ManifestValidator.failed("the manifest must be a JSON object");
|
|
115
|
+
}
|
|
116
|
+
return new ManifestValidator({ ...raw }, options.folder).run();
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Whether a permission is one RollRook knows.
|
|
120
|
+
*
|
|
121
|
+
* @param permission - the permission as written in the manifest
|
|
122
|
+
* @returns true for `raven`, `agents.read`, `audio`, `video`, `net:*` and a well-formed `net:<host>` with a dot in its host
|
|
123
|
+
*/
|
|
124
|
+
static is_known_permission(permission) {
|
|
125
|
+
if (ManifestValidator.LIST_KNOWN_PERMISSIONS.includes(permission)
|
|
126
|
+
|| permission === ManifestValidator.NET_ANY_PERMISSION) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
if (!permission.startsWith(ManifestValidator.NET_PREFIX)) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
const host = permission.slice(ManifestValidator.NET_PREFIX.length);
|
|
133
|
+
const bare_host = host.startsWith("*.") ? host.slice(2) : host;
|
|
134
|
+
return ManifestValidator.HOST_PATTERN.test(host) && bare_host.includes(".");
|
|
135
|
+
}
|
|
136
|
+
static failed(message) {
|
|
137
|
+
return {
|
|
138
|
+
manifest: undefined,
|
|
139
|
+
list_problems: [{ field: "manifest", message, severity: "error" }],
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
record;
|
|
143
|
+
folder;
|
|
144
|
+
list_problems = [];
|
|
145
|
+
constructor(record, folder) {
|
|
146
|
+
this.record = record;
|
|
147
|
+
this.folder = folder;
|
|
148
|
+
}
|
|
149
|
+
run() {
|
|
150
|
+
const id = this.text_field("id", true);
|
|
151
|
+
if (id !== undefined && !ManifestValidator.ID_PATTERN.test(id)) {
|
|
152
|
+
this.error("id", "must be two or more dot-separated parts of lowercase letters, digits and dashes, the first the publisher's (e.g. octo.pomodoro)");
|
|
153
|
+
}
|
|
154
|
+
const name = this.text_field("name", true);
|
|
155
|
+
const version = this.text_field("version", true);
|
|
156
|
+
if (version !== undefined && !ManifestValidator.SEMVER_PATTERN.test(version)) {
|
|
157
|
+
this.error("version", `${version} is not a semantic version (e.g. 1.2.0)`);
|
|
158
|
+
}
|
|
159
|
+
const description = this.text_field("description", false);
|
|
160
|
+
const publisher = this.text_field("publisher", false);
|
|
161
|
+
const id_publisher = id?.split(".")[0];
|
|
162
|
+
if (publisher !== undefined && id_publisher !== undefined && id_publisher !== publisher) {
|
|
163
|
+
this.warning("publisher", `the id's first part (${id_publisher}) should be the publisher (${publisher})`);
|
|
164
|
+
}
|
|
165
|
+
const has_views = this.record["views"] !== undefined;
|
|
166
|
+
const main = this.text_field("main", !has_views);
|
|
167
|
+
if (main !== undefined && has_views) {
|
|
168
|
+
this.warning("main", "is ignored when views are given");
|
|
169
|
+
}
|
|
170
|
+
else if (main !== undefined) {
|
|
171
|
+
this.check_path("main", main);
|
|
172
|
+
}
|
|
173
|
+
const icon = this.text_field("icon", false);
|
|
174
|
+
if (icon !== undefined) {
|
|
175
|
+
if (!ManifestValidator.LIST_ICON_EXTENSIONS.includes(extname(icon).toLowerCase())) {
|
|
176
|
+
this.error("icon", "must be a PNG or an SVG");
|
|
177
|
+
}
|
|
178
|
+
else if (this.check_path("icon", icon)) {
|
|
179
|
+
this.check_png_square(icon);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const list_views = has_views ? this.check_views() : [];
|
|
183
|
+
if (!has_views && main !== undefined && name !== undefined) {
|
|
184
|
+
list_views.push({
|
|
185
|
+
id: ManifestValidator.MAIN_VIEW_ID,
|
|
186
|
+
slot: "dock",
|
|
187
|
+
entry: main,
|
|
188
|
+
title: name,
|
|
189
|
+
icon: undefined,
|
|
190
|
+
width: undefined,
|
|
191
|
+
height: undefined,
|
|
192
|
+
align: undefined,
|
|
193
|
+
order: undefined,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
const list_settings = this.check_settings();
|
|
197
|
+
const list_permissions = this.check_permissions();
|
|
198
|
+
const contributes = this.check_contributes(list_views);
|
|
199
|
+
const min_rollrook = this.text_field("minRollRook", false);
|
|
200
|
+
if (min_rollrook !== undefined && !ManifestValidator.SEMVER_PATTERN.test(min_rollrook)) {
|
|
201
|
+
this.error("minRollRook", `${min_rollrook} is not a semantic version`);
|
|
202
|
+
}
|
|
203
|
+
const repository = this.text_field("repository", false);
|
|
204
|
+
if (repository !== undefined && !repository.startsWith("https://")) {
|
|
205
|
+
this.warning("repository", "should be an https URL");
|
|
206
|
+
}
|
|
207
|
+
for (const key of Object.keys(this.record)) {
|
|
208
|
+
if (!ManifestValidator.LIST_FIELDS.includes(key)) {
|
|
209
|
+
this.warning(key, "is not a manifest field and is ignored");
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const has_error = this.list_problems.some((problem) => problem.severity === "error");
|
|
213
|
+
if (has_error
|
|
214
|
+
|| id === undefined
|
|
215
|
+
|| name === undefined
|
|
216
|
+
|| version === undefined
|
|
217
|
+
|| list_views.length === 0) {
|
|
218
|
+
return { manifest: undefined, list_problems: this.list_problems };
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
manifest: {
|
|
222
|
+
id,
|
|
223
|
+
name,
|
|
224
|
+
version,
|
|
225
|
+
description,
|
|
226
|
+
publisher,
|
|
227
|
+
main,
|
|
228
|
+
icon,
|
|
229
|
+
list_views,
|
|
230
|
+
list_settings,
|
|
231
|
+
list_permissions,
|
|
232
|
+
contributes,
|
|
233
|
+
min_rollrook,
|
|
234
|
+
repository,
|
|
235
|
+
},
|
|
236
|
+
list_problems: this.list_problems,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
error(field, message) {
|
|
240
|
+
this.list_problems.push({ field, message, severity: "error" });
|
|
241
|
+
}
|
|
242
|
+
warning(field, message) {
|
|
243
|
+
this.list_problems.push({ field, message, severity: "warning" });
|
|
244
|
+
}
|
|
245
|
+
text_field(key, is_required) {
|
|
246
|
+
const value = this.record[key];
|
|
247
|
+
if (value === undefined) {
|
|
248
|
+
if (is_required) {
|
|
249
|
+
this.error(key, "is required");
|
|
250
|
+
}
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
254
|
+
this.error(key, "must be a non-empty string");
|
|
255
|
+
return undefined;
|
|
256
|
+
}
|
|
257
|
+
return value;
|
|
258
|
+
}
|
|
259
|
+
check_path(field, path) {
|
|
260
|
+
if (isAbsolute(path) || path.split(/[\\/]/).includes("..")) {
|
|
261
|
+
this.error(field, "must be a path inside the plugin's folder");
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
if (this.folder === undefined) {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
const full_path = join(this.folder, path);
|
|
268
|
+
if (!existsSync(full_path) || !statSync(full_path).isFile()) {
|
|
269
|
+
this.error(field, `${path} does not exist in ${this.folder}`);
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
check_png_square(icon) {
|
|
275
|
+
if (this.folder === undefined || extname(icon).toLowerCase() !== ".png") {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const data = readFileSync(join(this.folder, icon));
|
|
279
|
+
if (data.length < ManifestValidator.PNG_HEADER_LENGTH || data.toString("ascii", 12, 16) !== "IHDR") {
|
|
280
|
+
this.error("icon", "is not a PNG file");
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const width = data.readUInt32BE(16);
|
|
284
|
+
const height = data.readUInt32BE(20);
|
|
285
|
+
if (width !== height) {
|
|
286
|
+
this.error("icon", `must be square, not ${width}×${height}`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
check_views() {
|
|
290
|
+
const raw = this.record["views"];
|
|
291
|
+
if (!Array.isArray(raw) || raw.length === 0) {
|
|
292
|
+
this.error("views", "must be a non-empty array of views");
|
|
293
|
+
return [];
|
|
294
|
+
}
|
|
295
|
+
const list_views = [];
|
|
296
|
+
const set_ids = new Set();
|
|
297
|
+
for (const [index, item] of raw.entries()) {
|
|
298
|
+
const view = this.check_view(item, index);
|
|
299
|
+
if (view === undefined) {
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
if (set_ids.has(view.id)) {
|
|
303
|
+
this.error(`views[${index}].id`, `two views are called ${view.id}`);
|
|
304
|
+
}
|
|
305
|
+
set_ids.add(view.id);
|
|
306
|
+
list_views.push(view);
|
|
307
|
+
}
|
|
308
|
+
if (list_views.length > 0 && !list_views.some((view) => ManifestValidator.LIST_STANDING_SLOTS.includes(view.slot))) {
|
|
309
|
+
this.error("views", "needs a dock, sidebar or footbar view; popover and settings views are opened from those");
|
|
310
|
+
}
|
|
311
|
+
const list_settings_views = list_views.filter((view) => view.slot === "settings");
|
|
312
|
+
if (list_settings_views.length > 1) {
|
|
313
|
+
this.error("views", "may have only one settings view");
|
|
314
|
+
}
|
|
315
|
+
const list_background_views = list_views.filter((view) => view.slot === "background");
|
|
316
|
+
if (list_background_views.length > 1) {
|
|
317
|
+
this.error("views", "may have only one background view");
|
|
318
|
+
}
|
|
319
|
+
return list_views;
|
|
320
|
+
}
|
|
321
|
+
check_view(item, index) {
|
|
322
|
+
const field = `views[${index}]`;
|
|
323
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
324
|
+
this.error(field, "must be an object");
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
327
|
+
const view = { ...item };
|
|
328
|
+
const id = view["id"];
|
|
329
|
+
if (typeof id !== "string" || !ManifestValidator.VIEW_ID_PATTERN.test(id)) {
|
|
330
|
+
this.error(`${field}.id`, "must be lowercase letters, digits and dashes");
|
|
331
|
+
}
|
|
332
|
+
const slot = ManifestValidator.LIST_SLOTS.find((candidate) => candidate === view["slot"]);
|
|
333
|
+
if (slot === undefined) {
|
|
334
|
+
this.error(`${field}.slot`, `must be one of ${ManifestValidator.LIST_SLOTS.join(", ")}`);
|
|
335
|
+
}
|
|
336
|
+
const entry = view["entry"];
|
|
337
|
+
if (typeof entry !== "string" || entry === "") {
|
|
338
|
+
this.error(`${field}.entry`, "must be the path of a page inside the plugin");
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
this.check_path(`${field}.entry`, entry);
|
|
342
|
+
}
|
|
343
|
+
if (typeof id !== "string" || slot === undefined || typeof entry !== "string") {
|
|
344
|
+
return undefined;
|
|
345
|
+
}
|
|
346
|
+
const list_allowed = ["id", "slot", "entry", ...ManifestValidator.map_slot_fields[slot]];
|
|
347
|
+
for (const key of Object.keys(view)) {
|
|
348
|
+
if (!list_allowed.includes(key)) {
|
|
349
|
+
this.warning(`${field}.${key}`, `is not a field of a ${slot} view and is ignored`);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
const title = view["title"];
|
|
353
|
+
if (title !== undefined && (typeof title !== "string" || title.trim() === "")) {
|
|
354
|
+
this.error(`${field}.title`, "must be a non-empty string");
|
|
355
|
+
}
|
|
356
|
+
const icon = view["icon"];
|
|
357
|
+
if (icon !== undefined) {
|
|
358
|
+
if (typeof icon !== "string" || !ManifestValidator.LIST_ICON_EXTENSIONS.includes(extname(icon).toLowerCase())) {
|
|
359
|
+
this.error(`${field}.icon`, "must be a PNG or an SVG");
|
|
360
|
+
}
|
|
361
|
+
else if (this.check_path(`${field}.icon`, icon)) {
|
|
362
|
+
this.check_png_square(icon);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
const width = view["width"];
|
|
366
|
+
const height = view["height"];
|
|
367
|
+
const align = view["align"];
|
|
368
|
+
const order = view["order"];
|
|
369
|
+
if (slot === "footbar") {
|
|
370
|
+
if (width !== undefined && width !== "fill" && !ManifestValidator.is_size(width, ManifestValidator.FOOTBAR_MAX_WIDTH)) {
|
|
371
|
+
this.error(`${field}.width`, `must be "fill" or a number of points from 1 to ${ManifestValidator.FOOTBAR_MAX_WIDTH}`);
|
|
372
|
+
}
|
|
373
|
+
if (align !== undefined && align !== "leading" && align !== "trailing") {
|
|
374
|
+
this.error(`${field}.align`, "must be leading or trailing");
|
|
375
|
+
}
|
|
376
|
+
if (order !== undefined && (typeof order !== "number" || !Number.isFinite(order))) {
|
|
377
|
+
this.error(`${field}.order`, "must be a number");
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (slot === "popover") {
|
|
381
|
+
if (!ManifestValidator.is_size(width, ManifestValidator.POPOVER_MAX_SIZE)) {
|
|
382
|
+
this.error(`${field}.width`, `a popover needs a width from 1 to ${ManifestValidator.POPOVER_MAX_SIZE} points`);
|
|
383
|
+
}
|
|
384
|
+
if (!ManifestValidator.is_size(height, ManifestValidator.POPOVER_MAX_SIZE)) {
|
|
385
|
+
this.error(`${field}.height`, `a popover needs a height from 1 to ${ManifestValidator.POPOVER_MAX_SIZE} points`);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (slot === "settings" && height !== undefined && !ManifestValidator.is_size(height, ManifestValidator.POPOVER_MAX_SIZE)) {
|
|
389
|
+
this.error(`${field}.height`, `must be a number of points from 1 to ${ManifestValidator.POPOVER_MAX_SIZE}`);
|
|
390
|
+
}
|
|
391
|
+
return {
|
|
392
|
+
id,
|
|
393
|
+
slot,
|
|
394
|
+
entry,
|
|
395
|
+
title: typeof title === "string" ? title : undefined,
|
|
396
|
+
icon: typeof icon === "string" ? icon : undefined,
|
|
397
|
+
width: width === "fill" || typeof width === "number" ? width : undefined,
|
|
398
|
+
height: typeof height === "number"
|
|
399
|
+
? height
|
|
400
|
+
: slot === "settings" ? ManifestValidator.SETTINGS_DEFAULT_HEIGHT : undefined,
|
|
401
|
+
align: align === "leading" || align === "trailing" ? align : undefined,
|
|
402
|
+
order: typeof order === "number" ? order : undefined,
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
check_settings() {
|
|
406
|
+
const raw = this.record["settings"];
|
|
407
|
+
if (raw === undefined) {
|
|
408
|
+
return [];
|
|
409
|
+
}
|
|
410
|
+
if (!Array.isArray(raw)) {
|
|
411
|
+
this.error("settings", "must be an array of settings");
|
|
412
|
+
return [];
|
|
413
|
+
}
|
|
414
|
+
const list_settings = [];
|
|
415
|
+
const set_keys = new Set();
|
|
416
|
+
for (const [index, item] of raw.entries()) {
|
|
417
|
+
const setting = this.check_setting(item, index);
|
|
418
|
+
if (setting === undefined) {
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
if (set_keys.has(setting.key)) {
|
|
422
|
+
this.error(`settings[${index}].key`, `two settings are called ${setting.key}`);
|
|
423
|
+
}
|
|
424
|
+
set_keys.add(setting.key);
|
|
425
|
+
list_settings.push(setting);
|
|
426
|
+
}
|
|
427
|
+
return list_settings;
|
|
428
|
+
}
|
|
429
|
+
check_setting(item, index) {
|
|
430
|
+
const field = `settings[${index}]`;
|
|
431
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
432
|
+
this.error(field, "must be an object");
|
|
433
|
+
return undefined;
|
|
434
|
+
}
|
|
435
|
+
const setting = { ...item };
|
|
436
|
+
const key = setting["key"];
|
|
437
|
+
if (typeof key !== "string" || key === "" || key.length > ManifestValidator.SETTING_KEY_MAX_LENGTH) {
|
|
438
|
+
this.error(`${field}.key`, `must be a string of 1 to ${ManifestValidator.SETTING_KEY_MAX_LENGTH} characters`);
|
|
439
|
+
}
|
|
440
|
+
const type = ManifestValidator.LIST_SETTING_TYPES.find((candidate) => candidate === setting["type"]);
|
|
441
|
+
if (type === undefined) {
|
|
442
|
+
this.error(`${field}.type`, `must be one of ${ManifestValidator.LIST_SETTING_TYPES.join(", ")}`);
|
|
443
|
+
}
|
|
444
|
+
const title = setting["title"];
|
|
445
|
+
if (typeof title !== "string" || title.trim() === "") {
|
|
446
|
+
this.error(`${field}.title`, "must be a non-empty string");
|
|
447
|
+
}
|
|
448
|
+
if (typeof key !== "string" || type === undefined || typeof title !== "string") {
|
|
449
|
+
return undefined;
|
|
450
|
+
}
|
|
451
|
+
const list_options = type === "enum" ? this.check_options(setting["options"], field) : [];
|
|
452
|
+
if (type !== "enum" && setting["options"] !== undefined) {
|
|
453
|
+
this.warning(`${field}.options`, "applies only to enum settings and is ignored");
|
|
454
|
+
}
|
|
455
|
+
const map_bounds = {};
|
|
456
|
+
for (const bound of ["min", "max", "step"]) {
|
|
457
|
+
const value = setting[bound];
|
|
458
|
+
if (value === undefined) {
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
if (type !== "number") {
|
|
462
|
+
this.warning(`${field}.${bound}`, "applies only to number settings and is ignored");
|
|
463
|
+
}
|
|
464
|
+
else if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
465
|
+
this.error(`${field}.${bound}`, "must be a number");
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
map_bounds[bound] = value;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
const min = map_bounds["min"];
|
|
472
|
+
const max = map_bounds["max"];
|
|
473
|
+
if (min !== undefined && max !== undefined && min > max) {
|
|
474
|
+
this.error(`${field}.min`, "is greater than max");
|
|
475
|
+
}
|
|
476
|
+
const default_value = setting["default"];
|
|
477
|
+
if (default_value !== undefined) {
|
|
478
|
+
this.check_default({
|
|
479
|
+
field: `${field}.default`,
|
|
480
|
+
type,
|
|
481
|
+
value: default_value,
|
|
482
|
+
list_options,
|
|
483
|
+
min,
|
|
484
|
+
max,
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
for (const name of Object.keys(setting)) {
|
|
488
|
+
if (!["key", "type", "title", "default", "options", "min", "max", "step"].includes(name)) {
|
|
489
|
+
this.warning(`${field}.${name}`, "is not a field of a setting and is ignored");
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return {
|
|
493
|
+
key,
|
|
494
|
+
type,
|
|
495
|
+
title,
|
|
496
|
+
default_value,
|
|
497
|
+
list_options,
|
|
498
|
+
min,
|
|
499
|
+
max,
|
|
500
|
+
step: map_bounds["step"],
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
check_options(raw, field) {
|
|
504
|
+
if (!Array.isArray(raw) || raw.length === 0) {
|
|
505
|
+
this.error(`${field}.options`, "an enum setting needs options: [{ value, title }]");
|
|
506
|
+
return [];
|
|
507
|
+
}
|
|
508
|
+
const list_options = [];
|
|
509
|
+
for (const option of raw) {
|
|
510
|
+
if (typeof option === "object"
|
|
511
|
+
&& option !== null
|
|
512
|
+
&& typeof option.value === "string"
|
|
513
|
+
&& typeof option.title === "string") {
|
|
514
|
+
list_options.push({ value: option.value, title: option.title });
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
this.error(`${field}.options`, "each option is { value, title }, both strings");
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return list_options;
|
|
521
|
+
}
|
|
522
|
+
check_default(check) {
|
|
523
|
+
const { field, type, value } = check;
|
|
524
|
+
const is_valid = type === "string" ? typeof value === "string"
|
|
525
|
+
: type === "number" ? typeof value === "number" && Number.isFinite(value)
|
|
526
|
+
: type === "boolean" ? typeof value === "boolean"
|
|
527
|
+
: type === "enum" ? check.list_options.some((option) => option.value === value)
|
|
528
|
+
: ManifestValidator.is_json(value);
|
|
529
|
+
if (!is_valid) {
|
|
530
|
+
this.error(field, type === "enum" ? "must be one of the options' values" : `must be a ${type} value`);
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
if (typeof value === "number"
|
|
534
|
+
&& ((check.min !== undefined && value < check.min) || (check.max !== undefined && value > check.max))) {
|
|
535
|
+
this.warning(field, "lies outside min and max; RollRook clamps it");
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
static is_size(value, maximum) {
|
|
539
|
+
return typeof value === "number" && value >= 1 && value <= maximum;
|
|
540
|
+
}
|
|
541
|
+
static is_json(value) {
|
|
542
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") {
|
|
543
|
+
return true;
|
|
544
|
+
}
|
|
545
|
+
if (typeof value === "number") {
|
|
546
|
+
return Number.isFinite(value);
|
|
547
|
+
}
|
|
548
|
+
if (Array.isArray(value)) {
|
|
549
|
+
return value.every((item) => ManifestValidator.is_json(item));
|
|
550
|
+
}
|
|
551
|
+
return typeof value === "object" && Object.values(value).every((item) => ManifestValidator.is_json(item));
|
|
552
|
+
}
|
|
553
|
+
check_contributes(list_views) {
|
|
554
|
+
const contributes = {
|
|
555
|
+
calendar_title: undefined,
|
|
556
|
+
list_tools: [],
|
|
557
|
+
skill: undefined,
|
|
558
|
+
};
|
|
559
|
+
const raw = this.record["contributes"];
|
|
560
|
+
if (raw === undefined) {
|
|
561
|
+
return contributes;
|
|
562
|
+
}
|
|
563
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
564
|
+
this.error("contributes", "must be an object");
|
|
565
|
+
return contributes;
|
|
566
|
+
}
|
|
567
|
+
const record = { ...raw };
|
|
568
|
+
for (const key of Object.keys(record)) {
|
|
569
|
+
if (!ManifestValidator.LIST_CONTRIBUTION_FIELDS.includes(key)) {
|
|
570
|
+
this.warning(`contributes.${key}`, "is not something a plugin contributes and is ignored");
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
const has_background = list_views.some((view) => view.slot === "background");
|
|
574
|
+
const calendar = record["calendar"];
|
|
575
|
+
if (calendar !== undefined) {
|
|
576
|
+
const title = typeof calendar === "object" && calendar !== null && !Array.isArray(calendar)
|
|
577
|
+
? Reflect.get(calendar, "title")
|
|
578
|
+
: undefined;
|
|
579
|
+
if (typeof title !== "string" || title.trim() === "" || title.length > ManifestValidator.CALENDAR_TITLE_MAX_LENGTH) {
|
|
580
|
+
this.error("contributes.calendar", `must be { title }, 1 to ${ManifestValidator.CALENDAR_TITLE_MAX_LENGTH} characters, the layer RollRook shows the plugin's items under`);
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
contributes.calendar_title = title;
|
|
584
|
+
if (!has_background) {
|
|
585
|
+
this.warning("contributes.calendar", "has no background view to follow calendar.move and keep the items published while no view shows");
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
const raven = record["raven"];
|
|
590
|
+
if (raven !== undefined) {
|
|
591
|
+
if (typeof raven !== "object" || raven === null || Array.isArray(raven)) {
|
|
592
|
+
this.error("contributes.raven", "must be { tools, skill? }");
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
const raven_record = { ...raven };
|
|
596
|
+
contributes.list_tools = this.check_tools(raven_record["tools"]);
|
|
597
|
+
contributes.skill = this.check_skill(raven_record["skill"]);
|
|
598
|
+
if (contributes.list_tools.length > 0 && !has_background) {
|
|
599
|
+
this.error("contributes.raven.tools", "are answered in a background view; add a view with \"slot\": \"background\"");
|
|
600
|
+
}
|
|
601
|
+
for (const key of Object.keys(raven_record)) {
|
|
602
|
+
if (key !== "tools" && key !== "skill") {
|
|
603
|
+
this.warning(`contributes.raven.${key}`, "is not a field of contributes.raven and is ignored");
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
return contributes;
|
|
609
|
+
}
|
|
610
|
+
check_tools(raw) {
|
|
611
|
+
const field = "contributes.raven.tools";
|
|
612
|
+
if (raw === undefined) {
|
|
613
|
+
return [];
|
|
614
|
+
}
|
|
615
|
+
if (!Array.isArray(raw)) {
|
|
616
|
+
this.error(field, "must be an array of tools");
|
|
617
|
+
return [];
|
|
618
|
+
}
|
|
619
|
+
if (raw.length > ManifestValidator.TOOL_LIMIT) {
|
|
620
|
+
this.error(field, `may hold at most ${ManifestValidator.TOOL_LIMIT} tools`);
|
|
621
|
+
}
|
|
622
|
+
const list_tools = [];
|
|
623
|
+
const set_names = new Set();
|
|
624
|
+
for (const [index, item] of raw.entries()) {
|
|
625
|
+
const tool_field = `${field}[${index}]`;
|
|
626
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
627
|
+
this.error(tool_field, "must be { name, description, input, confirm? }");
|
|
628
|
+
continue;
|
|
629
|
+
}
|
|
630
|
+
const tool = { ...item };
|
|
631
|
+
const name = tool["name"];
|
|
632
|
+
const description = tool["description"];
|
|
633
|
+
const input = tool["input"] ?? { type: "object" };
|
|
634
|
+
const confirm = tool["confirm"];
|
|
635
|
+
let is_valid = true;
|
|
636
|
+
if (typeof name !== "string"
|
|
637
|
+
|| !ManifestValidator.TOOL_NAME_PATTERN.test(name)
|
|
638
|
+
|| name.length > ManifestValidator.TOOL_NAME_MAX_LENGTH) {
|
|
639
|
+
this.error(`${tool_field}.name`, `must be snake_case (words of lowercase letters and digits joined by single underscores, a letter first), at most ${ManifestValidator.TOOL_NAME_MAX_LENGTH} characters`);
|
|
640
|
+
is_valid = false;
|
|
641
|
+
}
|
|
642
|
+
else if (set_names.has(name)) {
|
|
643
|
+
this.error(`${tool_field}.name`, `two tools are called ${name}`);
|
|
644
|
+
}
|
|
645
|
+
if (typeof description !== "string" || description.trim() === "") {
|
|
646
|
+
this.error(`${tool_field}.description`, "must say what the tool does and when to use it");
|
|
647
|
+
is_valid = false;
|
|
648
|
+
}
|
|
649
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
650
|
+
this.error(`${tool_field}.input`, "must be a JSON Schema object");
|
|
651
|
+
is_valid = false;
|
|
652
|
+
}
|
|
653
|
+
else if (Reflect.get(input, "type") !== "object") {
|
|
654
|
+
this.error(`${tool_field}.input`, "must be a JSON Schema of an object: { \"type\": \"object\", \"properties\": { ... } }");
|
|
655
|
+
is_valid = false;
|
|
656
|
+
}
|
|
657
|
+
else if (!ManifestValidator.is_json(input)) {
|
|
658
|
+
this.error(`${tool_field}.input`, "must be JSON");
|
|
659
|
+
is_valid = false;
|
|
660
|
+
}
|
|
661
|
+
if (confirm !== undefined && typeof confirm !== "boolean") {
|
|
662
|
+
this.error(`${tool_field}.confirm`, "must be true or false");
|
|
663
|
+
}
|
|
664
|
+
for (const key of Object.keys(tool)) {
|
|
665
|
+
if (!ManifestValidator.LIST_TOOL_FIELDS.includes(key)) {
|
|
666
|
+
this.warning(`${tool_field}.${key}`, "is not a field of a tool and is ignored");
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
if (!is_valid || typeof name !== "string" || typeof description !== "string" || typeof input !== "object" || input === null) {
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
672
|
+
set_names.add(name);
|
|
673
|
+
list_tools.push({
|
|
674
|
+
name,
|
|
675
|
+
description,
|
|
676
|
+
input: { ...input },
|
|
677
|
+
is_confirmed: confirm === true,
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
return list_tools;
|
|
681
|
+
}
|
|
682
|
+
check_skill(raw) {
|
|
683
|
+
const field = "contributes.raven.skill";
|
|
684
|
+
if (raw === undefined) {
|
|
685
|
+
return undefined;
|
|
686
|
+
}
|
|
687
|
+
if (typeof raw !== "string" || extname(raw).toLowerCase() !== ManifestValidator.SKILL_EXTENSION) {
|
|
688
|
+
this.error(field, "must be the path of a Markdown file inside the plugin");
|
|
689
|
+
return undefined;
|
|
690
|
+
}
|
|
691
|
+
return this.check_path(field, raw) ? raw : undefined;
|
|
692
|
+
}
|
|
693
|
+
check_permissions() {
|
|
694
|
+
const raw = this.record["permissions"];
|
|
695
|
+
if (raw === undefined) {
|
|
696
|
+
return [];
|
|
697
|
+
}
|
|
698
|
+
if (!Array.isArray(raw)) {
|
|
699
|
+
this.error("permissions", "must be an array of strings");
|
|
700
|
+
return [];
|
|
701
|
+
}
|
|
702
|
+
const list_permissions = [];
|
|
703
|
+
for (const permission of raw) {
|
|
704
|
+
if (typeof permission !== "string") {
|
|
705
|
+
this.error("permissions", "must be an array of strings");
|
|
706
|
+
}
|
|
707
|
+
else if (ManifestValidator.LIST_DEFAULT_PERMISSIONS.includes(permission)) {
|
|
708
|
+
this.error("permissions", `${permission} is granted to every plugin; remove it, RollRook refuses permissions it does not know`);
|
|
709
|
+
}
|
|
710
|
+
else if (!ManifestValidator.is_known_permission(permission)) {
|
|
711
|
+
this.error("permissions", `${permission} is not a known permission (raven, agents.read, audio, video, net:<host>, net:*)`);
|
|
712
|
+
}
|
|
713
|
+
else if (list_permissions.includes(permission)) {
|
|
714
|
+
this.warning("permissions", `${permission} is listed twice`);
|
|
715
|
+
}
|
|
716
|
+
else {
|
|
717
|
+
list_permissions.push(permission);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return list_permissions;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
//# sourceMappingURL=manifest.js.map
|