@hermes-hq/hodios-schema 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.
@@ -0,0 +1,47 @@
1
+ import ajv2020 from 'ajv/dist/2020.js';
2
+ import { entrySchema, evalsSchema, vocabSchema } from './schemas.js';
3
+ // ajv ships CommonJS; its default export is reachable as `.default` in every module system.
4
+ const Ajv2020 = ajv2020.default;
5
+ const ajv = new Ajv2020({ allErrors: true, strict: true, strictRequired: false, allowUnionTypes: true });
6
+ function toIssues(errors) {
7
+ if (!errors)
8
+ return [];
9
+ const seen = new Set();
10
+ const issues = [];
11
+ for (const e of errors) {
12
+ // if/then/else wrappers repeat the real error; keep the specific one only.
13
+ if (e.keyword === 'if')
14
+ continue;
15
+ let message = e.message ?? 'is invalid';
16
+ if (e.keyword === 'additionalProperties') {
17
+ message = `unknown field "${String(e.params['additionalProperty'])}"`;
18
+ }
19
+ else if (e.keyword === 'enum') {
20
+ message = `must be one of: ${e.params['allowedValues'].join(', ')}`;
21
+ }
22
+ else if (e.keyword === 'not') {
23
+ message = 'contains a field that is not allowed for this kind or status';
24
+ }
25
+ const key = `${e.instancePath}|${message}`;
26
+ if (seen.has(key))
27
+ continue;
28
+ seen.add(key);
29
+ issues.push({ path: e.instancePath, message });
30
+ }
31
+ return issues;
32
+ }
33
+ function makeValidator(validate) {
34
+ return (data) => {
35
+ const valid = validate(data);
36
+ return valid
37
+ ? { valid: true, value: data, issues: [] }
38
+ : { valid: false, issues: toIssues(validate.errors) };
39
+ };
40
+ }
41
+ /** Validates entry frontmatter against entry.schema.json. */
42
+ export const validateEntry = makeValidator(ajv.compile(entrySchema));
43
+ /** Validates the contents of an evals.yaml against evals.schema.json. */
44
+ export const validateEvals = makeValidator(ajv.compile(evalsSchema));
45
+ /** Validates a vocab/<facet>.yml against vocab.schema.json. */
46
+ export const validateVocab = makeValidator(ajv.compile(vocabSchema));
47
+ //# sourceMappingURL=validate.js.map
@@ -0,0 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,IAAI,OAAO,EAAE,CAAC;QAC3C,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,SAAS;QAC5B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACd,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,YAAY,EAAE,OAAO,EAAE,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,aAAa,CAAI,QAA0B;IAClD,OAAO,CAAC,IAAa,EAAmB,EAAE;QACxC,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC7B,OAAO,KAAK;YACV,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAS,EAAE,MAAM,EAAE,EAAE,EAAE;YAC/C,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;IAC1D,CAAC,CAAC;AACJ,CAAC;AAED,6DAA6D;AAC7D,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAmB,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;AAEvF,yEAAyE;AACzE,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAY,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;AAEhF,+DAA+D;AAC/D,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAY,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@hermes-hq/hodios-schema",
3
+ "version": "0.1.0",
4
+ "description": "JSON Schemas, TypeScript types and a validator for Hodios library entries.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./entry.schema.json": "./schemas/entry.schema.json",
15
+ "./evals.schema.json": "./schemas/evals.schema.json",
16
+ "./vocab.schema.json": "./schemas/vocab.schema.json"
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "schemas"
21
+ ],
22
+ "scripts": {
23
+ "prepack": "node -e \"require('node:fs').cpSync('../../schema','schemas',{recursive:true})\""
24
+ },
25
+ "dependencies": {
26
+ "ajv": "^8.20.0"
27
+ },
28
+ "engines": {
29
+ "node": ">=22.13"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/hermes-hq/hodios.git",
34
+ "directory": "packages/schema"
35
+ },
36
+ "homepage": "https://hermes-ide.com/prompts",
37
+ "bugs": "https://github.com/hermes-hq/hodios/issues",
38
+ "keywords": [
39
+ "hodios",
40
+ "prompts",
41
+ "json-schema",
42
+ "agent-skills"
43
+ ],
44
+ "publishConfig": {
45
+ "access": "public",
46
+ "provenance": true
47
+ }
48
+ }