librebot-tools 0.0.0-stage → 0.4.4
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/LICENSE +21 -0
- package/README.md +270 -2
- package/bin/librebot.js +262 -0
- package/package.json +34 -4
- package/schema/v1/bot-yaml-schema.json +193 -0
- package/schema/v1/skills-sources-schema.json +31 -0
- package/src/errors.js +28 -0
- package/src/icon.js +130 -0
- package/src/index.d.ts +275 -0
- package/src/index.js +50 -0
- package/src/parse.js +702 -0
- package/src/scaffold.js +279 -0
- package/src/schema.js +14 -0
- package/src/skills-import.js +50 -0
- package/src/skills-lock.js +697 -0
- package/src/util.js +27 -0
- package/src/validate.js +851 -0
- package/test/assets.test.mjs +82 -0
- package/test/export.test.mjs +155 -0
- package/test/gitlab-preview.test.mjs +23 -0
- package/test/gitlab-triggers.test.mjs +53 -0
- package/test/icon.test.mjs +137 -0
- package/test/lock.test.mjs +92 -0
- package/test/malformed.test.mjs +79 -0
- package/test/readme.test.mjs +109 -0
- package/test/semantics.test.mjs +186 -0
- package/test/standard-skills.test.mjs +41 -0
- package/test/vendor.test.mjs +135 -0
- package/test/whatsapp-actions.test.mjs +31 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://librebot.dev/schema/bot-source/v1/bot-yaml-schema.json",
|
|
4
|
+
"title": "Librebot bot.yaml (source format v1)",
|
|
5
|
+
"description": "Consolidated bot definition. instructions.md carries the main prompt; knowledge/ and skills/ are file trees; knowledgeSources holds structured external references. Builtin tools are always on and must not be declared; local-execution MCP servers are unsupported.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"required": ["formatVersion", "name", "description", "modelRoles"],
|
|
9
|
+
"properties": {
|
|
10
|
+
"formatVersion": { "const": 1 },
|
|
11
|
+
"name": { "type": "string", "minLength": 1, "maxLength": 100 },
|
|
12
|
+
"description": { "type": "string", "minLength": 1, "maxLength": 1000 },
|
|
13
|
+
"icon": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"minLength": 1,
|
|
16
|
+
"maxLength": 512,
|
|
17
|
+
"pattern": "^(\\./)?[^.\\\\/:\\s][^\\\\:\\s]*\\.([sS][vV][gG]|[pP][nN][gG]|[wW][eE][bB][pP])$",
|
|
18
|
+
"description": "Repository-relative path to an SVG, PNG, or WebP bot icon. For PNG and WebP, use a square image, ideally 512 × 512 pixels; transparent backgrounds are supported. For SVG, use a square viewBox. Icons are displayed at small sizes, so prefer simple artwork with adequate padding and avoid fine details or text."
|
|
19
|
+
},
|
|
20
|
+
"modelRoles": {
|
|
21
|
+
"type": "array",
|
|
22
|
+
"minItems": 1,
|
|
23
|
+
"maxItems": 4,
|
|
24
|
+
"items": {
|
|
25
|
+
"type": "object",
|
|
26
|
+
"additionalProperties": false,
|
|
27
|
+
"required": ["role", "label"],
|
|
28
|
+
"properties": {
|
|
29
|
+
"role": { "enum": ["default", "smol", "slow", "plan"] },
|
|
30
|
+
"label": { "type": "string", "minLength": 1, "maxLength": 100 },
|
|
31
|
+
"requirements": {
|
|
32
|
+
"type": "object",
|
|
33
|
+
"additionalProperties": false,
|
|
34
|
+
"properties": {
|
|
35
|
+
"tools": { "type": "boolean" },
|
|
36
|
+
"vision": { "type": "boolean" },
|
|
37
|
+
"reasoning": { "type": "boolean" },
|
|
38
|
+
"minContextWindow": { "type": "number", "exclusiveMinimum": 0 }
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"workspace": {
|
|
45
|
+
"type": "array",
|
|
46
|
+
"maxItems": 10,
|
|
47
|
+
"items": {
|
|
48
|
+
"type": "object",
|
|
49
|
+
"additionalProperties": false,
|
|
50
|
+
"required": ["key", "path"],
|
|
51
|
+
"properties": {
|
|
52
|
+
"key": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$" },
|
|
53
|
+
"label": { "type": "string", "minLength": 1, "maxLength": 100 },
|
|
54
|
+
"path": { "type": "string", "pattern": "^\\./([^/.][^/]*)(/[^/.][^/]*)*$|^\\./$" }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"triggers": {
|
|
59
|
+
"type": "array",
|
|
60
|
+
"maxItems": 20,
|
|
61
|
+
"items": {
|
|
62
|
+
"type": "object",
|
|
63
|
+
"additionalProperties": false,
|
|
64
|
+
"required": ["key", "label", "kind", "eventTypes", "deciderInstructions"],
|
|
65
|
+
"properties": {
|
|
66
|
+
"key": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$" },
|
|
67
|
+
"label": { "type": "string", "minLength": 1, "maxLength": 100 },
|
|
68
|
+
"description": { "type": "string", "maxLength": 2000 },
|
|
69
|
+
"kind": { "enum": ["gitrepo", "whatsapp"] },
|
|
70
|
+
"eventTypes": {
|
|
71
|
+
"type": "array",
|
|
72
|
+
"minItems": 1,
|
|
73
|
+
"maxItems": 20,
|
|
74
|
+
"uniqueItems": true,
|
|
75
|
+
"items": { "enum": ["issue.opened", "issue.updated", "issue.closed", "issue.reopened", "issue.comment.created", "issue.comment.updated", "change_request.opened", "change_request.updated", "change_request.closed", "change_request.reopened", "change_request.merged", "change_request.commits_updated", "change_request.checks_updated", "change_request.comment.created", "change_request.comment.updated", "change_request.approval_changed", "repository.pushed", "message.created", "reaction.changed"] }
|
|
76
|
+
},
|
|
77
|
+
"inputs": {
|
|
78
|
+
"type": "array",
|
|
79
|
+
"maxItems": 50,
|
|
80
|
+
"items": {
|
|
81
|
+
"type": "object",
|
|
82
|
+
"additionalProperties": false,
|
|
83
|
+
"required": ["key", "type"],
|
|
84
|
+
"properties": {
|
|
85
|
+
"key": { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$" },
|
|
86
|
+
"label": { "type": "string", "maxLength": 100 },
|
|
87
|
+
"type": { "enum": ["string", "number", "boolean", "select"] },
|
|
88
|
+
"required": { "type": "boolean" },
|
|
89
|
+
"options": {
|
|
90
|
+
"type": "array",
|
|
91
|
+
"minItems": 1,
|
|
92
|
+
"maxItems": 50,
|
|
93
|
+
"items": { "type": "string", "minLength": 1, "maxLength": 200 }
|
|
94
|
+
},
|
|
95
|
+
"help": { "type": "string", "maxLength": 500 }
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"deciderRole": { "enum": ["default", "smol", "slow", "plan"] },
|
|
100
|
+
"deciderInstructions": { "type": "string", "minLength": 1, "maxLength": 20000 },
|
|
101
|
+
"enabledByDefault": { "type": "boolean" }
|
|
102
|
+
},
|
|
103
|
+
"allOf": [{
|
|
104
|
+
"if": { "properties": { "kind": { "const": "whatsapp" } } },
|
|
105
|
+
"then": { "properties": { "eventTypes": { "items": { "enum": ["message.created", "reaction.changed"] } } } },
|
|
106
|
+
"else": { "properties": { "eventTypes": { "items": { "enum": ["issue.opened", "issue.updated", "issue.closed", "issue.reopened", "issue.comment.created", "issue.comment.updated", "change_request.opened", "change_request.updated", "change_request.closed", "change_request.reopened", "change_request.merged", "change_request.commits_updated", "change_request.checks_updated", "change_request.comment.created", "change_request.comment.updated", "change_request.approval_changed", "repository.pushed"] } } } }
|
|
107
|
+
}]
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
"actions": {
|
|
111
|
+
"type": "array",
|
|
112
|
+
"maxItems": 20,
|
|
113
|
+
"items": {
|
|
114
|
+
"type": "object",
|
|
115
|
+
"additionalProperties": false,
|
|
116
|
+
"required": ["key", "kind", "capabilities"],
|
|
117
|
+
"properties": {
|
|
118
|
+
"key": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$" },
|
|
119
|
+
"kind": { "enum": ["gitrepo", "whatsapp"] },
|
|
120
|
+
"label": { "type": "string", "minLength": 1, "maxLength": 100 },
|
|
121
|
+
"capabilities": {
|
|
122
|
+
"type": "array", "minItems": 1, "maxItems": 13, "uniqueItems": true,
|
|
123
|
+
"items": { "enum": ["read_issue", "push_branch", "propose_change", "comment_issue", "search_issues", "read_change_request", "read_repository", "update_issue_labels", "react_issue", "update_issue_body", "update_issue_title", "publish_attachments", "merge_change_request", "read_messages", "send_text", "set_reaction", "remove_reaction"] }
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
"allOf": [{
|
|
127
|
+
"if": { "properties": { "kind": { "const": "whatsapp" } } },
|
|
128
|
+
"then": { "properties": { "capabilities": { "maxItems": 4, "items": { "enum": ["read_messages", "send_text", "set_reaction", "remove_reaction"] } } } },
|
|
129
|
+
"else": { "properties": { "capabilities": { "items": { "enum": ["read_issue", "push_branch", "propose_change", "comment_issue", "search_issues", "read_change_request", "read_repository", "update_issue_labels", "react_issue", "update_issue_body", "update_issue_title", "publish_attachments", "merge_change_request"] } } } }
|
|
130
|
+
}]
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
"connectors": {
|
|
134
|
+
"type": "array",
|
|
135
|
+
"maxItems": 50,
|
|
136
|
+
"items": {
|
|
137
|
+
"type": "object",
|
|
138
|
+
"additionalProperties": false,
|
|
139
|
+
"required": ["label", "tools"],
|
|
140
|
+
"properties": {
|
|
141
|
+
"label": { "type": "string", "minLength": 1, "maxLength": 200 },
|
|
142
|
+
"description": { "type": "string", "maxLength": 1000 },
|
|
143
|
+
"required": { "type": "boolean" },
|
|
144
|
+
"tools": {
|
|
145
|
+
"type": "array",
|
|
146
|
+
"minItems": 1,
|
|
147
|
+
"maxItems": 100,
|
|
148
|
+
"items": { "type": "string", "minLength": 1, "maxLength": 200 }
|
|
149
|
+
},
|
|
150
|
+
"resources": {
|
|
151
|
+
"type": "array",
|
|
152
|
+
"items": {
|
|
153
|
+
"type": "object",
|
|
154
|
+
"additionalProperties": false,
|
|
155
|
+
"required": ["key", "label", "tools"],
|
|
156
|
+
"properties": {
|
|
157
|
+
"key": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$" },
|
|
158
|
+
"label": { "type": "string", "minLength": 1, "maxLength": 200 },
|
|
159
|
+
"tools": {
|
|
160
|
+
"type": "array",
|
|
161
|
+
"minItems": 1,
|
|
162
|
+
"items": { "type": "string", "minLength": 1, "maxLength": 200 }
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
"endpoint": {
|
|
168
|
+
"type": "string",
|
|
169
|
+
"format": "uri",
|
|
170
|
+
"pattern": "^https://",
|
|
171
|
+
"description": "Remote MCP server identity. The runtime binds only this endpoint; local execution is unsupported."
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
"knowledgeSources": {
|
|
177
|
+
"type": "array",
|
|
178
|
+
"maxItems": 100,
|
|
179
|
+
"items": {
|
|
180
|
+
"type": "object",
|
|
181
|
+
"additionalProperties": false,
|
|
182
|
+
"required": ["id", "name", "kind", "url"],
|
|
183
|
+
"properties": {
|
|
184
|
+
"id": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$" },
|
|
185
|
+
"name": { "type": "string", "minLength": 1, "maxLength": 200 },
|
|
186
|
+
"kind": { "enum": ["resource", "repo"] },
|
|
187
|
+
"url": { "type": "string", "format": "uri", "maxLength": 500 },
|
|
188
|
+
"ref": { "type": "string", "maxLength": 256 }
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"title": "Librebot skill sources v1",
|
|
4
|
+
"description": "External skills installed locally and committed with skills/sources.lock and skills/.vendor/.",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"required": ["version", "sources"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"version": { "const": 1 },
|
|
10
|
+
"sources": {
|
|
11
|
+
"type": "array",
|
|
12
|
+
"maxItems": 50,
|
|
13
|
+
"items": {
|
|
14
|
+
"oneOf": [
|
|
15
|
+
{ "type": "string", "minLength": 1, "maxLength": 2000, "description": "A source locator accepted by npx skills." },
|
|
16
|
+
{
|
|
17
|
+
"type": "object",
|
|
18
|
+
"additionalProperties": false,
|
|
19
|
+
"required": ["name", "source"],
|
|
20
|
+
"properties": {
|
|
21
|
+
"name": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$" },
|
|
22
|
+
"source": { "type": "string", "minLength": 1, "maxLength": 2000, "description": "A standard skills source locator; credentials must not be embedded." },
|
|
23
|
+
"ref": { "type": "string", "minLength": 1, "maxLength": 256, "description": "Optional explicit GitHub repository ref; other sources encode ref selection in their source locator." },
|
|
24
|
+
"skills": { "type": "array", "maxItems": 50, "items": { "type": "string", "minLength": 1, "maxLength": 100, "pattern": "^[^-\\s].*$" } }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
package/src/errors.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Aggregated source-validation errors. Every failure carries the file,
|
|
2
|
+
// field, and cause so CLI, server, and UI surfaces can render it identically.
|
|
3
|
+
|
|
4
|
+
export class BotSourceError extends Error {
|
|
5
|
+
/** @type {Array<{ file: string; field: string; message: string }>} */
|
|
6
|
+
errors;
|
|
7
|
+
/** @type {Array<{ file: string; field: string; message: string }>} */
|
|
8
|
+
warnings;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {Array<{ file: string; field: string; message: string }>} errors
|
|
12
|
+
* @param {Array<{ file: string; field: string; message: string }>} [warnings]
|
|
13
|
+
*/
|
|
14
|
+
constructor(errors, warnings = []) {
|
|
15
|
+
super(
|
|
16
|
+
"invalid bot source: " +
|
|
17
|
+
errors.map((e) => `${e.file}:${e.field}: ${e.message}`).join("; "),
|
|
18
|
+
);
|
|
19
|
+
this.name = "BotSourceError";
|
|
20
|
+
this.errors = errors;
|
|
21
|
+
this.warnings = warnings;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** @param {unknown} value */
|
|
26
|
+
export function isRecord(value) {
|
|
27
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
28
|
+
}
|
package/src/icon.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { SaxesParser } from "saxes";
|
|
2
|
+
import { imageSize } from "image-size";
|
|
3
|
+
import { sha256Hex } from "./util.js";
|
|
4
|
+
|
|
5
|
+
export const DEFAULT_ICON = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="6" width="16" height="14" rx="4"/><path d="M12 3v3M8 16h8"/><circle cx="8.5" cy="11" r=".75" fill="currentColor"/><circle cx="15.5" cy="11" r=".75" fill="currentColor"/></svg>';
|
|
6
|
+
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
7
|
+
const elements = new Set("svg g defs path rect circle ellipse line polyline polygon linearGradient radialGradient stop clipPath mask pattern use symbol title desc".split(" "));
|
|
8
|
+
const attributes = new Set("id version viewBox width height x y x1 y1 x2 y2 cx cy r rx ry d points fill fill-opacity fill-rule stroke stroke-width stroke-opacity stroke-linecap stroke-linejoin stroke-miterlimit stroke-dasharray stroke-dashoffset opacity transform gradientTransform gradientUnits spreadMethod offset stop-color stop-opacity clip-path clip-rule mask maskUnits maskContentUnits patternUnits patternContentUnits patternTransform preserveAspectRatio vector-effect color href".split(" "));
|
|
9
|
+
attributes.add("style");
|
|
10
|
+
const styleProperties = new Set("fill fill-opacity fill-rule stroke stroke-width stroke-opacity stroke-linecap stroke-linejoin stroke-miterlimit stroke-dasharray stroke-dashoffset opacity stop-color stop-opacity clip-path clip-rule mask vector-effect color".split(" "));
|
|
11
|
+
|
|
12
|
+
export function iconPath(value) {
|
|
13
|
+
if (typeof value !== "string" || !value || value.length > 512 || /[:\\\s\u0000-\u001f\u007f]/.test(value) || value.startsWith("/")) throw new Error("icon must be a repository-relative SVG, PNG, or WebP path (max 512 characters)");
|
|
14
|
+
const path = value.startsWith("./") ? value.slice(2) : value;
|
|
15
|
+
if (path.split("/").some((part) => !part || part === "." || part === ".." || part.startsWith(".")) || !/\.(svg|png|webp)$/i.test(path)) throw new Error("icon must be a repository-relative SVG, PNG, or WebP path without traversal");
|
|
16
|
+
return path;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function square(width, height) {
|
|
20
|
+
if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || width !== height || width > 4096) throw new Error("icon dimensions must be positive, square, and at most 4096 pixels");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function svgDimensions(bytes) {
|
|
24
|
+
const text = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
25
|
+
const parser = new SaxesParser({ xmlns: true });
|
|
26
|
+
let root = false;
|
|
27
|
+
let dimensions;
|
|
28
|
+
parser.on("doctype", () => { throw new Error("SVG DOCTYPE and entities are forbidden"); });
|
|
29
|
+
parser.on("processinginstruction", () => { throw new Error("SVG processing instructions are forbidden"); });
|
|
30
|
+
parser.on("error", (error) => { throw error; });
|
|
31
|
+
parser.on("opentag", (node) => {
|
|
32
|
+
if (node.uri !== SVG_NS || !elements.has(node.local)) throw new Error(`unsafe SVG element: ${node.name}`);
|
|
33
|
+
if (!root) {
|
|
34
|
+
root = true;
|
|
35
|
+
if (node.local !== "svg") throw new Error("icon must have an SVG root");
|
|
36
|
+
const values = node.attributes.viewBox?.value.trim().split(/[\s,]+/).map(Number);
|
|
37
|
+
if (!values || values.length !== 4 || !values.every(Number.isFinite)) throw new Error("SVG icon requires a square viewBox");
|
|
38
|
+
square(values[2], values[3]);
|
|
39
|
+
const width = node.attributes.width?.value;
|
|
40
|
+
const height = node.attributes.height?.value;
|
|
41
|
+
if (width !== undefined || height !== undefined) {
|
|
42
|
+
if (!(width === "100%" && height === "100%")) {
|
|
43
|
+
if (!width || !height || !/^\d+(?:\.\d+)?(?:px)?$/.test(width) || !/^\d+(?:\.\d+)?(?:px)?$/.test(height)) throw new Error("SVG viewport must have matching numeric dimensions or 100% dimensions");
|
|
44
|
+
square(Number(width.replace(/px$/, "")), Number(height.replace(/px$/, "")));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
dimensions = { width: values[2], height: values[3] };
|
|
48
|
+
}
|
|
49
|
+
for (const attr of Object.values(node.attributes)) {
|
|
50
|
+
if (attr.uri === "http://www.w3.org/2000/xmlns/") {
|
|
51
|
+
if (attr.value !== SVG_NS && attr.value !== "http://www.w3.org/1999/xlink") throw new Error("unsupported SVG namespace");
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if ((attr.uri && !(attr.uri === "http://www.w3.org/1999/xlink" && attr.local === "href")) || !attributes.has(attr.local)) throw new Error(`unsafe SVG attribute: ${attr.name}`);
|
|
55
|
+
const value = attr.value;
|
|
56
|
+
if (attr.local === "style") {
|
|
57
|
+
for (const declaration of value.split(";")) {
|
|
58
|
+
if (!declaration.trim()) continue;
|
|
59
|
+
const colon = declaration.indexOf(":");
|
|
60
|
+
const property = declaration.slice(0, colon).trim().toLowerCase();
|
|
61
|
+
if (colon < 0 || !styleProperties.has(property) || !declaration.slice(colon + 1).trim() || /[{}!]/.test(declaration)) throw new Error("unsafe SVG style declaration");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (attr.local === "href" && !/^#[A-Za-z_][\w:.-]*$/.test(value)) throw new Error("SVG references must be local fragments");
|
|
65
|
+
// Reject CSS escapes/comments and anything except literal local paint references.
|
|
66
|
+
if (/[\\@]|\/\*|[\u0000-\u001f]/.test(value)) throw new Error("unsafe SVG attribute value");
|
|
67
|
+
const withoutUrls = value.replace(/url\(\s*(['"]?)#[A-Za-z_][\w:.-]*\1\s*\)/gi, "");
|
|
68
|
+
if (/url\s*\(|(?:https?|data|javascript|file):|\/\//i.test(withoutUrls)) throw new Error("external SVG references are forbidden");
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
parser.write(text).close();
|
|
72
|
+
if (!dimensions) throw new Error("icon must contain SVG artwork");
|
|
73
|
+
return dimensions;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Check complete container framing, not just image-size's header dimensions.
|
|
77
|
+
function validateRasterContainer(bytes, ext) {
|
|
78
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
79
|
+
const tag = (offset) => String.fromCharCode(...bytes.subarray(offset, offset + 4));
|
|
80
|
+
if (ext === "png") {
|
|
81
|
+
let offset = 8;
|
|
82
|
+
let header = false;
|
|
83
|
+
let data = false;
|
|
84
|
+
let ended = false;
|
|
85
|
+
while (offset + 12 <= bytes.length) {
|
|
86
|
+
const length = view.getUint32(offset);
|
|
87
|
+
const type = tag(offset + 4);
|
|
88
|
+
if (length > bytes.length - offset - 12) throw new Error("truncated PNG icon");
|
|
89
|
+
if (!header && (type !== "IHDR" || length !== 13)) throw new Error("PNG icon requires IHDR");
|
|
90
|
+
header = true;
|
|
91
|
+
if (type === "IDAT" && length > 0) data = true;
|
|
92
|
+
offset += length + 12;
|
|
93
|
+
if (type === "IEND") {
|
|
94
|
+
if (length !== 0 || offset !== bytes.length) throw new Error("invalid PNG end chunk");
|
|
95
|
+
ended = true;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (!header || !data || !ended) throw new Error("incomplete PNG icon");
|
|
100
|
+
} else {
|
|
101
|
+
if (bytes.length < 20 || tag(0) !== "RIFF" || tag(8) !== "WEBP" || view.getUint32(4, true) + 8 !== bytes.length) throw new Error("invalid WebP container length");
|
|
102
|
+
let offset = 12;
|
|
103
|
+
let image = false;
|
|
104
|
+
while (offset + 8 <= bytes.length) {
|
|
105
|
+
const length = view.getUint32(offset + 4, true);
|
|
106
|
+
if (length > bytes.length - offset - 8) throw new Error("truncated WebP icon");
|
|
107
|
+
const type = tag(offset);
|
|
108
|
+
if ((type === "VP8 " || type === "VP8L" || type === "ANMF") && length > 0) image = true;
|
|
109
|
+
offset += 8 + length + (length % 2);
|
|
110
|
+
}
|
|
111
|
+
if (!image || offset !== bytes.length) throw new Error("incomplete WebP icon");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function validateIcon(path, bytes) {
|
|
116
|
+
path = iconPath(path);
|
|
117
|
+
if (!(bytes instanceof Uint8Array) || !bytes.length) throw new Error("icon asset bytes are missing");
|
|
118
|
+
if (bytes.length > 256 * 1024) throw new Error("icon exceeds the 256 KiB limit");
|
|
119
|
+
const ext = path.slice(path.lastIndexOf(".") + 1).toLowerCase();
|
|
120
|
+
let dimensions;
|
|
121
|
+
if (ext === "svg") dimensions = svgDimensions(bytes);
|
|
122
|
+
else {
|
|
123
|
+
dimensions = imageSize(bytes);
|
|
124
|
+
if (dimensions.type !== ext) throw new Error("icon format does not match its file extension");
|
|
125
|
+
validateRasterContainer(bytes, ext);
|
|
126
|
+
square(dimensions.width, dimensions.height);
|
|
127
|
+
if (dimensions.images?.some((image) => image.width !== dimensions.width || image.height !== dimensions.height)) throw new Error("icon frames must have matching square dimensions");
|
|
128
|
+
}
|
|
129
|
+
return { path, bytes, mime: ext === "svg" ? "image/svg+xml" : `image/${ext}`, sha256: sha256Hex(bytes), size: bytes.length, width: dimensions.width, height: dimensions.height };
|
|
130
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
export type RepoCapability = "read_issue" | "push_branch" | "propose_change" | "comment_issue" | "search_issues" | "read_change_request" | "read_repository" | "update_issue_labels" | "react_issue" | "update_issue_body" | "update_issue_title" | "publish_attachments" | "merge_change_request";
|
|
2
|
+
export type WhatsAppCapability = "read_messages" | "send_text" | "set_reaction" | "remove_reaction";
|
|
3
|
+
export const FORMAT_VERSION: 1;
|
|
4
|
+
export const MODEL_ROLES: string[];
|
|
5
|
+
export const REPO_CAPABILITIES: RepoCapability[];
|
|
6
|
+
export const GITREPO_TRIGGER_EVENT_TYPES: string[];
|
|
7
|
+
// Type definitions for librebot-tools (hand-written; no build step).
|
|
8
|
+
|
|
9
|
+
export interface SourceIssue {
|
|
10
|
+
file: string;
|
|
11
|
+
field: string;
|
|
12
|
+
message: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ModelRequirements {
|
|
16
|
+
tools?: boolean;
|
|
17
|
+
vision?: boolean;
|
|
18
|
+
reasoning?: boolean;
|
|
19
|
+
minContextWindow?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface BotModelRole {
|
|
23
|
+
role: "default" | "smol" | "slow" | "plan";
|
|
24
|
+
label: string;
|
|
25
|
+
requirements: ModelRequirements;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface BotKnowledge {
|
|
29
|
+
id: string;
|
|
30
|
+
name: string;
|
|
31
|
+
kind: "file" | "resource" | "repo";
|
|
32
|
+
content?: string;
|
|
33
|
+
url?: string;
|
|
34
|
+
ref?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface BotSkill {
|
|
37
|
+
id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
description: string;
|
|
40
|
+
content: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface BotConnector {
|
|
44
|
+
/** Deterministic parser-internal ID; not serialized or a platform UUID. */
|
|
45
|
+
id: string;
|
|
46
|
+
label: string;
|
|
47
|
+
description: string;
|
|
48
|
+
required: boolean;
|
|
49
|
+
tools: string[];
|
|
50
|
+
resources: Array<{ key: string; label: string; tools: string[] }>;
|
|
51
|
+
/** Remote MCP server identity (https URL). Local execution is unsupported. */
|
|
52
|
+
endpoint?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface BotDraft {
|
|
56
|
+
name: string;
|
|
57
|
+
description: string;
|
|
58
|
+
botPrompt: string;
|
|
59
|
+
/** User-facing documentation from root README.md, separate from the prompt and knowledge. */
|
|
60
|
+
readme: string;
|
|
61
|
+
modelRoles: BotModelRole[];
|
|
62
|
+
knowledge: BotKnowledge[];
|
|
63
|
+
skills: BotSkill[];
|
|
64
|
+
connectors: BotConnector[];
|
|
65
|
+
triggers: Array<{ key: string; label: string; kind: "gitrepo" | "whatsapp"; eventTypes: string[]; description?: string; inputs?: Array<{ key: string; label?: string; type: "string" | "number" | "boolean" | "select"; required?: boolean; options?: string[]; help?: string }>; deciderRole?: "default" | "smol" | "slow" | "plan"; deciderInstructions: string; enabledByDefault?: boolean }>;
|
|
66
|
+
workspace: Array<{ key: string; label?: string; path: string }>;
|
|
67
|
+
actions: Array<{ key: string; kind: "gitrepo"; label?: string; capabilities: RepoCapability[] } | { key: string; kind: "whatsapp"; label?: string; capabilities: WhatsAppCapability[] }>;
|
|
68
|
+
icon?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface KnowledgeAsset {
|
|
72
|
+
knowledgeId: string;
|
|
73
|
+
path: string;
|
|
74
|
+
bytes: Uint8Array;
|
|
75
|
+
sha256: string;
|
|
76
|
+
size: number;
|
|
77
|
+
mime: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface SkillFile {
|
|
81
|
+
skillId: string;
|
|
82
|
+
path: string;
|
|
83
|
+
bytes: Uint8Array;
|
|
84
|
+
sha256: string;
|
|
85
|
+
size: number;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface SourceInventory {
|
|
89
|
+
botYaml: string;
|
|
90
|
+
instructions: string;
|
|
91
|
+
knowledgeFiles: string[];
|
|
92
|
+
skillDirs: string[];
|
|
93
|
+
lockPresent: boolean;
|
|
94
|
+
sourcesPresent: boolean;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface SkillLockEntry {
|
|
98
|
+
name: string;
|
|
99
|
+
repo: string;
|
|
100
|
+
resolvedSha?: string;
|
|
101
|
+
contentSha256?: string;
|
|
102
|
+
tarballSha256?: string;
|
|
103
|
+
skills: string[];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface SkillLock {
|
|
107
|
+
version: 1;
|
|
108
|
+
sourcesHash: string;
|
|
109
|
+
resolved: SkillLockEntry[];
|
|
110
|
+
vendorDirs: string[];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface IconAsset {
|
|
114
|
+
path: string;
|
|
115
|
+
bytes: Uint8Array;
|
|
116
|
+
mime: string;
|
|
117
|
+
sha256: string;
|
|
118
|
+
size: number;
|
|
119
|
+
width: number;
|
|
120
|
+
height: number;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface ParsedBotSource {
|
|
124
|
+
formatVersion: 1;
|
|
125
|
+
draft: BotDraft;
|
|
126
|
+
assets: KnowledgeAsset[];
|
|
127
|
+
icon?: IconAsset;
|
|
128
|
+
skillFiles: SkillFile[];
|
|
129
|
+
warnings: SourceIssue[];
|
|
130
|
+
source: SourceInventory;
|
|
131
|
+
lock: SkillLock | null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface ValidationSuccess extends ParsedBotSource {
|
|
135
|
+
ok: true;
|
|
136
|
+
errors: SourceIssue[];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface ValidationFailure {
|
|
140
|
+
ok: false;
|
|
141
|
+
errors: SourceIssue[];
|
|
142
|
+
warnings: SourceIssue[];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export type ValidationResult = ValidationSuccess | ValidationFailure;
|
|
146
|
+
|
|
147
|
+
export class BotSourceError extends Error {
|
|
148
|
+
errors: SourceIssue[];
|
|
149
|
+
warnings: SourceIssue[];
|
|
150
|
+
constructor(errors: SourceIssue[], warnings?: SourceIssue[]);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function parseBotFiles(
|
|
154
|
+
files: Record<string, Uint8Array | string>,
|
|
155
|
+
): Promise<ParsedBotSource>;
|
|
156
|
+
export function parseBotSource(dir: string): Promise<ParsedBotSource>;
|
|
157
|
+
export function validateFiles(
|
|
158
|
+
files: Record<string, Uint8Array | string>,
|
|
159
|
+
): Promise<ValidationResult>;
|
|
160
|
+
export function validateSource(dir: string): Promise<ValidationResult>;
|
|
161
|
+
export function readDirFiles(dir: string): Promise<Record<string, Uint8Array>>;
|
|
162
|
+
export function normalizeFileMap(
|
|
163
|
+
files: Record<string, Uint8Array | string>,
|
|
164
|
+
): Map<string, Uint8Array>;
|
|
165
|
+
export function knowledgeIdFor(rel: string): string;
|
|
166
|
+
export function parseSkillFrontmatter(text: string): {
|
|
167
|
+
name?: string;
|
|
168
|
+
description?: string;
|
|
169
|
+
body: string;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export interface SkillRepo {
|
|
173
|
+
owner: string;
|
|
174
|
+
repo: string;
|
|
175
|
+
url: string;
|
|
176
|
+
source?: string;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export const LOCK_VERSION: 1;
|
|
180
|
+
export const SOURCES_VERSION: 1;
|
|
181
|
+
export const MAX_TARBALL_BYTES: number;
|
|
182
|
+
export const MAX_DECOMPRESSED_BYTES: number;
|
|
183
|
+
|
|
184
|
+
export function parseRepo(source: unknown): SkillRepo | null;
|
|
185
|
+
export function parseSourcesText(text: string): unknown;
|
|
186
|
+
export function serializeLock(lock: SkillLock): string;
|
|
187
|
+
export function sourcesHash(
|
|
188
|
+
sources: Array<{ name: string; repo: SkillRepo; ref?: string; skills: string[] }>,
|
|
189
|
+
): string;
|
|
190
|
+
export function resolveSkillsLock(options: {
|
|
191
|
+
sources: {
|
|
192
|
+
sources: Array<{
|
|
193
|
+
name: string;
|
|
194
|
+
repo: SkillRepo;
|
|
195
|
+
ref?: string;
|
|
196
|
+
skills: string[];
|
|
197
|
+
}>;
|
|
198
|
+
};
|
|
199
|
+
existingLock?: SkillLock;
|
|
200
|
+
update?: boolean;
|
|
201
|
+
network?: boolean;
|
|
202
|
+
vendor?: boolean;
|
|
203
|
+
fetchImpl?: typeof fetch;
|
|
204
|
+
sourceBaseDir?: string;
|
|
205
|
+
currentFiles?: Record<string, Uint8Array>;
|
|
206
|
+
}): Promise<{
|
|
207
|
+
lock: SkillLock;
|
|
208
|
+
vendorFiles: Record<string, Uint8Array>;
|
|
209
|
+
errors: SourceIssue[];
|
|
210
|
+
warnings: SourceIssue[];
|
|
211
|
+
}>;
|
|
212
|
+
export function readTarEntries(buffer: Uint8Array): Array<{
|
|
213
|
+
name: string;
|
|
214
|
+
bytes: Uint8Array;
|
|
215
|
+
skipped: boolean;
|
|
216
|
+
}>;
|
|
217
|
+
export function fetchLockedSkills(
|
|
218
|
+
lock: SkillLock,
|
|
219
|
+
options?: { fetchImpl?: typeof fetch },
|
|
220
|
+
): Promise<{ vendorFiles: Record<string, Uint8Array>; errors: SourceIssue[] }>;
|
|
221
|
+
|
|
222
|
+
export function scaffoldBotFiles(input: {
|
|
223
|
+
name: string;
|
|
224
|
+
description?: string;
|
|
225
|
+
}): Record<string, string>;
|
|
226
|
+
export function exportBotFiles(
|
|
227
|
+
draft: BotDraft,
|
|
228
|
+
options?: {
|
|
229
|
+
icon?: { bytes: Uint8Array };
|
|
230
|
+
assets?: KnowledgeAsset[];
|
|
231
|
+
skillFiles?: SkillFile[];
|
|
232
|
+
sourcesText?: string;
|
|
233
|
+
lockText?: string;
|
|
234
|
+
},
|
|
235
|
+
): Record<string, string | Uint8Array>;
|
|
236
|
+
export function scaffoldBot(
|
|
237
|
+
dir: string,
|
|
238
|
+
input: { name: string; description?: string },
|
|
239
|
+
options?: { force?: boolean },
|
|
240
|
+
): Promise<string[]>;
|
|
241
|
+
export function writeFiles(
|
|
242
|
+
dir: string,
|
|
243
|
+
files: Record<string, string | Uint8Array>,
|
|
244
|
+
): Promise<string[]>;
|
|
245
|
+
export function exportKnowledgeFilename(item: {
|
|
246
|
+
id: string;
|
|
247
|
+
name?: string;
|
|
248
|
+
}): string;
|
|
249
|
+
export function sanitizePathSegment(segment: unknown, what: string): string;
|
|
250
|
+
export function sanitizeAssetRel(rel: unknown): string;
|
|
251
|
+
export function withSkillFrontmatter(skill: {
|
|
252
|
+
id: string;
|
|
253
|
+
name?: string;
|
|
254
|
+
description?: string;
|
|
255
|
+
content?: string;
|
|
256
|
+
}): string;
|
|
257
|
+
|
|
258
|
+
export const SCHEMA_VERSIONS: string[];
|
|
259
|
+
export function loadSchema(version?: string): Promise<Record<string, unknown>>;
|
|
260
|
+
|
|
261
|
+
export function toBytes(value: Uint8Array | string): Uint8Array;
|
|
262
|
+
export function sha256Hex(bytes: Uint8Array | string): string;
|
|
263
|
+
export function canonicalJson(value: unknown): string;
|
|
264
|
+
|
|
265
|
+
export function validateKnowledgeSources(
|
|
266
|
+
input: unknown,
|
|
267
|
+
sink: { errors: SourceIssue[]; warnings: SourceIssue[] },
|
|
268
|
+
file: string,
|
|
269
|
+
): BotKnowledge[];
|
|
270
|
+
export function validateRequirements(
|
|
271
|
+
input: unknown,
|
|
272
|
+
field: string,
|
|
273
|
+
sink: { errors: SourceIssue[]; warnings: SourceIssue[] },
|
|
274
|
+
file: string,
|
|
275
|
+
): ModelRequirements | undefined;
|