librebot-tools 0.0.0-stage → 0.4.5
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 +277 -2
- package/bin/librebot.js +262 -0
- package/package.json +38 -4
- package/schema/v1/bot-yaml-schema.json +193 -0
- package/schema/v1/skills-sources-schema.json +31 -0
- package/src/contract.d.ts +25 -0
- package/src/contract.js +23 -0
- package/src/errors.js +28 -0
- package/src/icon.js +130 -0
- package/src/index.d.ts +271 -0
- package/src/index.js +57 -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 +835 -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
package/src/util.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Shared byte/string helpers (leaf module: no imports from parse/skills-lock).
|
|
2
|
+
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
|
|
5
|
+
/** @param {Uint8Array|string} value */
|
|
6
|
+
export function toBytes(value) {
|
|
7
|
+
if (typeof value === "string") return new TextEncoder().encode(value);
|
|
8
|
+
if (value instanceof Uint8Array) return value;
|
|
9
|
+
throw new Error("file map values must be strings or Uint8Arrays");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** @param {Uint8Array|string} bytes */
|
|
13
|
+
export function sha256Hex(bytes) {
|
|
14
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Deterministic JSON with sorted object keys (lock hashing, pinning). */
|
|
18
|
+
export function canonicalJson(value) {
|
|
19
|
+
if (Array.isArray(value)) {
|
|
20
|
+
return `[${value.map(canonicalJson).join(",")}]`;
|
|
21
|
+
}
|
|
22
|
+
if (typeof value === "object" && value !== null) {
|
|
23
|
+
const keys = Object.keys(value).sort();
|
|
24
|
+
return `{${keys.map((k) => JSON.stringify(k) + ":" + canonicalJson(value[k])).join(",")}}`;
|
|
25
|
+
}
|
|
26
|
+
return JSON.stringify(value);
|
|
27
|
+
}
|