@nylorun/core 0.26.0-beta → 0.28.0-beta
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/CHANGELOG.md +54 -0
- package/README.md +6 -0
- package/dist/compatibility.d.ts +11 -2
- package/dist/compatibility.js +10 -0
- package/dist/contracts.d.ts +362 -0
- package/dist/contracts.js +131 -5
- package/dist/define.d.ts +2 -1
- package/dist/define.js +2 -1
- package/dist/definition/cron.d.ts +15 -0
- package/dist/definition/cron.js +155 -0
- package/dist/definition/sections.d.ts +11 -0
- package/dist/definition/sections.js +29 -20
- package/dist/folder/compile.d.ts +87 -0
- package/dist/folder/compile.js +1280 -0
- package/dist/folder/context.d.ts +97 -0
- package/dist/folder/context.js +79 -0
- package/dist/folder/decompile.d.ts +18 -0
- package/dist/folder/decompile.js +660 -0
- package/dist/folder/fix.d.ts +22 -0
- package/dist/folder/fix.js +191 -0
- package/dist/folder/flow.d.ts +42 -0
- package/dist/folder/flow.js +215 -0
- package/dist/folder/frontmatter.d.ts +21 -0
- package/dist/folder/frontmatter.js +91 -0
- package/dist/folder/index.d.ts +12 -0
- package/dist/folder/index.js +12 -0
- package/dist/folder/json-schema.d.ts +15 -0
- package/dist/folder/json-schema.js +212 -0
- package/dist/folder/json.d.ts +28 -0
- package/dist/folder/json.js +183 -0
- package/dist/folder/nested.d.ts +24 -0
- package/dist/folder/nested.js +378 -0
- package/dist/folder/plugins.d.ts +23 -0
- package/dist/folder/plugins.js +155 -0
- package/dist/folder/schemas.d.ts +8 -0
- package/dist/folder/schemas.js +238 -0
- package/dist/folder/suggest.d.ts +13 -0
- package/dist/folder/suggest.js +63 -0
- package/dist/schemas/agent-folder/agent-md.schema.json +143 -0
- package/dist/schemas/agent-folder/flow.schema.json +466 -0
- package/dist/schemas/agent-folder/mcp.schema.json +59 -0
- package/dist/schemas/agent-folder/runtime.schema.json +447 -0
- package/dist/schemas/agent-folder/tool.schema.json +77 -0
- package/dist/schemas/agent-folder/trigger-md.schema.json +65 -0
- package/dist/utils/runtime-limits.d.ts +8 -0
- package/dist/utils/runtime-limits.js +19 -0
- package/package.json +14 -3
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The JSON Schemas of an agent folder (`inputSchema`, `outputSchema` and the schema files they
|
|
3
|
+
* name), checked as JSON Schema 2020-12 before the folder compiles. Two passes:
|
|
4
|
+
*
|
|
5
|
+
* 1. A check of the keywords' shapes, with the pointer of each problem in the schema, so the
|
|
6
|
+
* compiler names its file, line and column: a `type` that is no JSON Schema type, `properties`
|
|
7
|
+
* that is not a map, `required` that is not a list of names, and so on, in every subschema.
|
|
8
|
+
* 2. The engine's own reading (`z.fromJSONSchema`, as `schemaFromJSON` reads a tool's schemas in
|
|
9
|
+
* each turn), when the first pass finds no error: a schema the engine cannot use would fail
|
|
10
|
+
* every turn, so it fails the check instead.
|
|
11
|
+
*
|
|
12
|
+
* Keywords JSON Schema allows and the engine cannot use (`if`, `not`, `dependentRequired`,
|
|
13
|
+
* `unevaluatedProperties`, a `$ref` outside `$defs`) are errors with their own reasons. An
|
|
14
|
+
* unknown keyword is an annotation in JSON Schema, so it is only a warning, and only when it is
|
|
15
|
+
* close to a keyword (`proprties`).
|
|
16
|
+
*/
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
import { suggestion } from "./suggest.js";
|
|
19
|
+
/** JSON Schema's seven types. */
|
|
20
|
+
export const JSON_SCHEMA_TYPES = ["null", "boolean", "object", "array", "number", "string", "integer"];
|
|
21
|
+
const TYPES_TEXT = "null, boolean, object, array, number, string and integer";
|
|
22
|
+
/** Keywords whose value is one schema. */
|
|
23
|
+
const ONE_SCHEMA = ["additionalProperties", "items", "contains", "propertyNames", "not", "if", "then", "else", "unevaluatedProperties", "unevaluatedItems", "contentSchema", "additionalItems"];
|
|
24
|
+
/** Keywords whose value maps names to schemas. */
|
|
25
|
+
const SCHEMA_MAPS = ["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"];
|
|
26
|
+
/** Keywords whose value is a non-empty list of schemas. */
|
|
27
|
+
const SCHEMA_LISTS = ["allOf", "anyOf", "oneOf", "prefixItems"];
|
|
28
|
+
const COUNTS = ["minLength", "maxLength", "minItems", "maxItems", "minProperties", "maxProperties", "minContains", "maxContains"];
|
|
29
|
+
const NUMBERS = ["minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum", "multipleOf"];
|
|
30
|
+
const STRINGS = ["title", "description", "format", "pattern", "$comment", "$id", "$schema", "$anchor", "$dynamicAnchor", "$ref", "$dynamicRef", "contentEncoding", "contentMediaType"];
|
|
31
|
+
const BOOLEANS = ["uniqueItems", "readOnly", "writeOnly", "deprecated"];
|
|
32
|
+
const OTHERS = ["type", "required", "enum", "const", "default", "examples", "dependentRequired", "$vocabulary"];
|
|
33
|
+
const KEYWORDS = [...ONE_SCHEMA, ...SCHEMA_MAPS, ...SCHEMA_LISTS, ...COUNTS, ...NUMBERS, ...STRINGS, ...BOOLEANS, ...OTHERS];
|
|
34
|
+
/** Why the engine cannot use a keyword JSON Schema allows. */
|
|
35
|
+
const UNSUPPORTED = {
|
|
36
|
+
if: "conditional schemas (if, then, else) are not supported: write the cases as anyOf",
|
|
37
|
+
then: "conditional schemas (if, then, else) are not supported: write the cases as anyOf",
|
|
38
|
+
else: "conditional schemas (if, then, else) are not supported: write the cases as anyOf",
|
|
39
|
+
dependentSchemas: "dependentSchemas is not supported",
|
|
40
|
+
dependentRequired: "dependentRequired is not supported",
|
|
41
|
+
unevaluatedProperties: "unevaluatedProperties is not supported: use additionalProperties",
|
|
42
|
+
unevaluatedItems: "unevaluatedItems is not supported: use items",
|
|
43
|
+
};
|
|
44
|
+
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
45
|
+
const show = (value) => JSON.stringify(value) ?? String(value);
|
|
46
|
+
/** Every problem in `schema`, a JSON Schema at the root of a field or file. */
|
|
47
|
+
export function jsonSchemaIssues(schema) {
|
|
48
|
+
const issues = [];
|
|
49
|
+
const error = (path, message, key = false) => issues.push({ severity: "error", path, message, ...(key ? { key } : {}) });
|
|
50
|
+
const warn = (path, message, key = false) => issues.push({ severity: "warning", path, message, ...(key ? { key } : {}) });
|
|
51
|
+
const defs = isObject(schema) && isObject(schema.$defs) ? schema.$defs : {};
|
|
52
|
+
const visit = (node, path) => {
|
|
53
|
+
if (typeof node === "boolean")
|
|
54
|
+
return;
|
|
55
|
+
if (!isObject(node)) {
|
|
56
|
+
error(path, `A schema is an object (or true or false), not ${show(node)}`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
for (const [keyword, value] of Object.entries(node)) {
|
|
60
|
+
const at = [...path, keyword];
|
|
61
|
+
if (keyword in UNSUPPORTED) {
|
|
62
|
+
error(at, `${keyword} is JSON Schema, but the engine cannot use it: ${UNSUPPORTED[keyword]}`, true);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (keyword === "type") {
|
|
66
|
+
typeIssues(value, at);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (keyword === "not") {
|
|
70
|
+
if (!isObject(value) || Object.keys(value).length > 0)
|
|
71
|
+
error(at, "not is JSON Schema, but the engine cannot use it, except as { \"not\": {} } for a value that never matches", true);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (ONE_SCHEMA.includes(keyword)) {
|
|
75
|
+
if (keyword === "items" && Array.isArray(value)) {
|
|
76
|
+
warn(at, "items is one schema in JSON Schema 2020-12; a list of schemas is draft-07's tuple form. Fix: rename it prefixItems", true);
|
|
77
|
+
value.forEach((item, index) => visit(item, [...at, index]));
|
|
78
|
+
}
|
|
79
|
+
else
|
|
80
|
+
visit(value, at);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (SCHEMA_MAPS.includes(keyword)) {
|
|
84
|
+
if (!isObject(value)) {
|
|
85
|
+
error(at, `${keyword} is a map of ${keyword === "properties" ? "property names" : keyword === "patternProperties" ? "patterns" : "names"} to schemas, not ${show(value)}`);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
for (const [name, child] of Object.entries(value)) {
|
|
89
|
+
if (keyword === "patternProperties" && !isPattern(name))
|
|
90
|
+
error([...at, name], `${show(name)} is not a regular expression`, true);
|
|
91
|
+
visit(child, [...at, name]);
|
|
92
|
+
}
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (SCHEMA_LISTS.includes(keyword)) {
|
|
96
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
97
|
+
error(at, `${keyword} is a list of one or more schemas, not ${show(value)}`);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
value.forEach((item, index) => visit(item, [...at, index]));
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (COUNTS.includes(keyword)) {
|
|
104
|
+
if (!Number.isInteger(value) || value < 0)
|
|
105
|
+
error(at, `${keyword} is a whole number, 0 or more, not ${show(value)}`);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (NUMBERS.includes(keyword)) {
|
|
109
|
+
if (typeof value !== "number")
|
|
110
|
+
error(at, `${keyword} is a number, not ${show(value)}`);
|
|
111
|
+
else if (keyword === "multipleOf" && value <= 0)
|
|
112
|
+
error(at, `multipleOf is a number above 0, not ${show(value)}`);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (STRINGS.includes(keyword)) {
|
|
116
|
+
if (typeof value !== "string")
|
|
117
|
+
error(at, `${keyword} is a string, not ${show(value)}`);
|
|
118
|
+
else if (keyword === "pattern" && !isPattern(value))
|
|
119
|
+
error(at, `pattern ${show(value)} is not a regular expression`);
|
|
120
|
+
else if (keyword === "$ref")
|
|
121
|
+
refIssue(value, at);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (BOOLEANS.includes(keyword)) {
|
|
125
|
+
if (typeof value !== "boolean")
|
|
126
|
+
error(at, `${keyword} is true or false, not ${show(value)}`);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (keyword === "required") {
|
|
130
|
+
if (!Array.isArray(value)) {
|
|
131
|
+
error(at, `required is a list of property names, such as ["id"], not ${show(value)}`);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const seen = new Set();
|
|
135
|
+
value.forEach((name, index) => {
|
|
136
|
+
if (typeof name !== "string")
|
|
137
|
+
error([...at, index], `required lists property names, which are strings, not ${show(name)}`);
|
|
138
|
+
else if (seen.has(name))
|
|
139
|
+
error([...at, index], `required lists ${show(name)} twice`);
|
|
140
|
+
else
|
|
141
|
+
seen.add(name);
|
|
142
|
+
});
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (keyword === "enum" || keyword === "examples") {
|
|
146
|
+
if (!Array.isArray(value))
|
|
147
|
+
error(at, `${keyword} is a list of values, not ${show(value)}`);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (keyword === "dependentRequired" || keyword === "$vocabulary" || keyword === "const" || keyword === "default")
|
|
151
|
+
continue;
|
|
152
|
+
const close = suggestion(keyword, KEYWORDS);
|
|
153
|
+
if (close)
|
|
154
|
+
issues.push({ severity: "warning", path: at, message: `Unknown keyword '${keyword}'. Did you mean '${close}'? JSON Schema ignores a keyword it does not know`, key: true, known: KEYWORDS });
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const typeIssues = (value, at) => {
|
|
158
|
+
const one = (name, path) => {
|
|
159
|
+
if (typeof name === "string" && JSON_SCHEMA_TYPES.includes(name))
|
|
160
|
+
return;
|
|
161
|
+
const close = typeof name === "string" ? suggestion(name, JSON_SCHEMA_TYPES) : undefined;
|
|
162
|
+
error(path, `type ${show(name)} is not a JSON Schema type.${close ? ` Did you mean '${close}'?` : ""} The types are ${TYPES_TEXT}`);
|
|
163
|
+
};
|
|
164
|
+
if (!Array.isArray(value))
|
|
165
|
+
return one(value, at);
|
|
166
|
+
if (value.length === 0)
|
|
167
|
+
return error(at, `type is a type or a list of one or more types: ${TYPES_TEXT}`);
|
|
168
|
+
const seen = new Set();
|
|
169
|
+
value.forEach((name, index) => {
|
|
170
|
+
if (seen.has(name))
|
|
171
|
+
error([...at, index], `type lists ${show(name)} twice`);
|
|
172
|
+
seen.add(name);
|
|
173
|
+
one(name, [...at, index]);
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
const refIssue = (ref, at) => {
|
|
177
|
+
if (ref === "#")
|
|
178
|
+
return;
|
|
179
|
+
const local = /^#\/\$defs\/([^/]+)$/.exec(ref);
|
|
180
|
+
if (local) {
|
|
181
|
+
const name = local[1].replace(/~1/g, "/").replace(/~0/g, "~");
|
|
182
|
+
if (!(name in defs)) {
|
|
183
|
+
const close = suggestion(name, Object.keys(defs));
|
|
184
|
+
error(at, `$ref ${show(ref)} names no schema in this schema's $defs.${close ? ` Did you mean '#/$defs/${close}'?` : ""}`);
|
|
185
|
+
}
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
error(at, ref.startsWith("#")
|
|
189
|
+
? `$ref ${show(ref)}: the engine resolves a $ref to the schema itself (#) or to one of its $defs (#/$defs/<name>) only`
|
|
190
|
+
: `$ref ${show(ref)} names another document: the engine resolves a $ref inside this schema only (#/$defs/<name>)`);
|
|
191
|
+
};
|
|
192
|
+
visit(schema, []);
|
|
193
|
+
if (issues.some((issue) => issue.severity === "error"))
|
|
194
|
+
return issues;
|
|
195
|
+
try {
|
|
196
|
+
z.fromJSONSchema(schema);
|
|
197
|
+
}
|
|
198
|
+
catch (cause) {
|
|
199
|
+
error([], `The engine cannot use this schema: ${cause instanceof Error ? cause.message.split("\n")[0] : String(cause)}`);
|
|
200
|
+
}
|
|
201
|
+
return issues;
|
|
202
|
+
}
|
|
203
|
+
/** Whether `pattern` is an ECMA-262 regular expression, the dialect JSON Schema names. */
|
|
204
|
+
function isPattern(pattern) {
|
|
205
|
+
try {
|
|
206
|
+
new RegExp(pattern);
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strict JSON (RFC 8259) with positions, for an agent folder's JSON files: no comments, no
|
|
3
|
+
* trailing commas, and a key twice in one object is an error. Each value and object key is
|
|
4
|
+
* found by its JSON pointer, so a diagnostic names the line and column of what it is about.
|
|
5
|
+
*/
|
|
6
|
+
/** A 1-based line and column. */
|
|
7
|
+
export interface Position {
|
|
8
|
+
readonly line: number;
|
|
9
|
+
readonly column: number;
|
|
10
|
+
}
|
|
11
|
+
/** Where a parsed value starts, and for an object member where its key starts. */
|
|
12
|
+
export interface Located {
|
|
13
|
+
readonly value: Position;
|
|
14
|
+
readonly key?: Position;
|
|
15
|
+
}
|
|
16
|
+
export type ParsedJson = {
|
|
17
|
+
readonly ok: true;
|
|
18
|
+
readonly value: unknown;
|
|
19
|
+
readonly positions: ReadonlyMap<string, Located>;
|
|
20
|
+
} | {
|
|
21
|
+
readonly ok: false;
|
|
22
|
+
readonly message: string;
|
|
23
|
+
readonly at: Position;
|
|
24
|
+
};
|
|
25
|
+
/** The pointer of `path` (RFC 6901): `""` for the whole document. */
|
|
26
|
+
export declare function pointerOf(path: readonly PropertyKey[]): string;
|
|
27
|
+
/** Parses `text` as strict JSON, keeping the position of every value and key. */
|
|
28
|
+
export declare function parseJson(text: string): ParsedJson;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strict JSON (RFC 8259) with positions, for an agent folder's JSON files: no comments, no
|
|
3
|
+
* trailing commas, and a key twice in one object is an error. Each value and object key is
|
|
4
|
+
* found by its JSON pointer, so a diagnostic names the line and column of what it is about.
|
|
5
|
+
*/
|
|
6
|
+
/** The pointer of `path` (RFC 6901): `""` for the whole document. */
|
|
7
|
+
export function pointerOf(path) {
|
|
8
|
+
return path.map((part) => `/${String(part).replace(/~/g, "~0").replace(/\//g, "~1")}`).join("");
|
|
9
|
+
}
|
|
10
|
+
class JsonError extends Error {
|
|
11
|
+
at;
|
|
12
|
+
constructor(message, at) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.at = at;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Parses `text` as strict JSON, keeping the position of every value and key. */
|
|
18
|
+
export function parseJson(text) {
|
|
19
|
+
const positions = new Map();
|
|
20
|
+
let index = 0;
|
|
21
|
+
let line = 1;
|
|
22
|
+
let lineStart = 0;
|
|
23
|
+
const here = () => ({ line, column: index - lineStart + 1 });
|
|
24
|
+
const fail = (message, at = here()) => {
|
|
25
|
+
throw new JsonError(message, at);
|
|
26
|
+
};
|
|
27
|
+
const space = () => {
|
|
28
|
+
for (;;) {
|
|
29
|
+
const char = text[index];
|
|
30
|
+
if (char === "\n") {
|
|
31
|
+
index++;
|
|
32
|
+
line++;
|
|
33
|
+
lineStart = index;
|
|
34
|
+
}
|
|
35
|
+
else if (char === " " || char === "\t" || char === "\r")
|
|
36
|
+
index++;
|
|
37
|
+
else if (char === "/" && (text[index + 1] === "/" || text[index + 1] === "*"))
|
|
38
|
+
fail("Comments are not JSON: explain a value in its description field, or in README.md");
|
|
39
|
+
else
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const literal = (word, value) => {
|
|
44
|
+
if (text.startsWith(word, index)) {
|
|
45
|
+
index += word.length;
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
return fail(`Unexpected ${describe(text[index])}`);
|
|
49
|
+
};
|
|
50
|
+
const string = () => {
|
|
51
|
+
let out = "";
|
|
52
|
+
index++; // the opening quote
|
|
53
|
+
for (;;) {
|
|
54
|
+
const char = text[index];
|
|
55
|
+
if (char === undefined)
|
|
56
|
+
fail("A string is not closed");
|
|
57
|
+
if (char === '"') {
|
|
58
|
+
index++;
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
if (char === "\n" || char < " ")
|
|
62
|
+
fail("A string holds a control character; write it as an escape such as \\n");
|
|
63
|
+
if (char !== "\\") {
|
|
64
|
+
out += char;
|
|
65
|
+
index++;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const escape = text[index + 1];
|
|
69
|
+
const simple = { '"': '"', "\\": "\\", "/": "/", b: "\b", f: "\f", n: "\n", r: "\r", t: "\t" };
|
|
70
|
+
if (escape !== undefined && escape in simple) {
|
|
71
|
+
out += simple[escape];
|
|
72
|
+
index += 2;
|
|
73
|
+
}
|
|
74
|
+
else if (escape === "u" && /^[0-9a-fA-F]{4}$/.test(text.slice(index + 2, index + 6))) {
|
|
75
|
+
out += String.fromCharCode(Number.parseInt(text.slice(index + 2, index + 6), 16));
|
|
76
|
+
index += 6;
|
|
77
|
+
}
|
|
78
|
+
else
|
|
79
|
+
fail(`Unknown escape \\${escape ?? ""}`);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const number = () => {
|
|
83
|
+
const match = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/.exec(text.slice(index));
|
|
84
|
+
if (!match)
|
|
85
|
+
return fail(`Unexpected ${describe(text[index])}`);
|
|
86
|
+
index += match[0].length;
|
|
87
|
+
return Number(match[0]);
|
|
88
|
+
};
|
|
89
|
+
const value = (path, key) => {
|
|
90
|
+
space();
|
|
91
|
+
const start = here();
|
|
92
|
+
positions.set(pointerOf(path), key ? { value: start, key } : { value: start });
|
|
93
|
+
const char = text[index];
|
|
94
|
+
if (char === "{") {
|
|
95
|
+
index++;
|
|
96
|
+
const object = {};
|
|
97
|
+
space();
|
|
98
|
+
if (text[index] === "}") {
|
|
99
|
+
index++;
|
|
100
|
+
return object;
|
|
101
|
+
}
|
|
102
|
+
for (;;) {
|
|
103
|
+
space();
|
|
104
|
+
if (text[index] !== '"')
|
|
105
|
+
fail(text[index] === "}" ? "A trailing comma is not JSON" : "An object's key is a string in double quotes");
|
|
106
|
+
const keyAt = here();
|
|
107
|
+
const name = string();
|
|
108
|
+
if (Object.hasOwn(object, name))
|
|
109
|
+
fail(`The key "${name}" appears twice in one object`, keyAt);
|
|
110
|
+
space();
|
|
111
|
+
if (text[index] !== ":")
|
|
112
|
+
fail(`Expected : after the key "${name}"`);
|
|
113
|
+
index++;
|
|
114
|
+
object[name] = value([...path, name], keyAt);
|
|
115
|
+
space();
|
|
116
|
+
if (text[index] === ",") {
|
|
117
|
+
index++;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (text[index] === "}") {
|
|
121
|
+
index++;
|
|
122
|
+
return object;
|
|
123
|
+
}
|
|
124
|
+
fail(`Expected , or } after the value of "${name}"`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (char === "[") {
|
|
128
|
+
index++;
|
|
129
|
+
const array = [];
|
|
130
|
+
space();
|
|
131
|
+
if (text[index] === "]") {
|
|
132
|
+
index++;
|
|
133
|
+
return array;
|
|
134
|
+
}
|
|
135
|
+
for (;;) {
|
|
136
|
+
array.push(value([...path, array.length]));
|
|
137
|
+
space();
|
|
138
|
+
if (text[index] === ",") {
|
|
139
|
+
index++;
|
|
140
|
+
space();
|
|
141
|
+
if (text[index] === "]")
|
|
142
|
+
fail("A trailing comma is not JSON");
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (text[index] === "]") {
|
|
146
|
+
index++;
|
|
147
|
+
return array;
|
|
148
|
+
}
|
|
149
|
+
fail("Expected , or ] in an array");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (char === '"')
|
|
153
|
+
return string();
|
|
154
|
+
if (char === "t")
|
|
155
|
+
return literal("true", true);
|
|
156
|
+
if (char === "f")
|
|
157
|
+
return literal("false", false);
|
|
158
|
+
if (char === "n")
|
|
159
|
+
return literal("null", null);
|
|
160
|
+
if (char === "-" || (char !== undefined && char >= "0" && char <= "9"))
|
|
161
|
+
return number();
|
|
162
|
+
return fail(char === undefined ? "The file ends before a value" : `Unexpected ${describe(char)}`);
|
|
163
|
+
};
|
|
164
|
+
try {
|
|
165
|
+
const parsed = value([]);
|
|
166
|
+
space();
|
|
167
|
+
if (index < text.length)
|
|
168
|
+
fail(`Unexpected ${describe(text[index])} after the value`);
|
|
169
|
+
return { ok: true, value: parsed, positions };
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
if (error instanceof JsonError)
|
|
173
|
+
return { ok: false, message: error.message, at: error.at };
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function describe(char) {
|
|
178
|
+
if (char === undefined)
|
|
179
|
+
return "end of file";
|
|
180
|
+
if (char === "'")
|
|
181
|
+
return "' (JSON strings use double quotes)";
|
|
182
|
+
return JSON.stringify(char);
|
|
183
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AgentFolderEntry } from "./compile.js";
|
|
2
|
+
import { type FolderContext, type FolderScope } from "./context.js";
|
|
3
|
+
export type { FolderScope } from "./context.js";
|
|
4
|
+
/** The files of every folder under `agents/` and `plugins/` the compiler reads. */
|
|
5
|
+
export declare function nestedTextPaths(entries: readonly AgentFolderEntry[], folderTextPaths: (entries: readonly AgentFolderEntry[]) => string[]): string[];
|
|
6
|
+
/** `/x` from a folder inside another: the uploaded folder's file, or why not. */
|
|
7
|
+
export declare function scopedSchema(scope: FolderScope, value: string, fail: (code: string, message: string) => void): Record<string, unknown> | undefined;
|
|
8
|
+
/** The hooks `compileAgentFolder` calls for one folder: plugins, subagents and flows. */
|
|
9
|
+
export declare function folderParts(ctx: FolderContext): {
|
|
10
|
+
/** Adds the plugins' MCP servers, before `AGENT.md` says how the agent uses them. */
|
|
11
|
+
mergeServers(servers: Record<string, Record<string, unknown>>): void;
|
|
12
|
+
/**
|
|
13
|
+
* `credential` in `AGENT.md`'s block for a plugin's server, which cannot know the agent's slot
|
|
14
|
+
* names. True when the server is a plugin's, so the block may name it.
|
|
15
|
+
*/
|
|
16
|
+
serverCredential(servers: Record<string, Record<string, unknown>>, key: string, settings: Record<string, unknown>, at: readonly PropertyKey[]): boolean;
|
|
17
|
+
/** Adds the plugins' skills, before `AGENT.md` says which secrets each gets. */
|
|
18
|
+
mergeSkills(skills: Record<string, Record<string, unknown>>): void;
|
|
19
|
+
/**
|
|
20
|
+
* Subagents, or the flow: called once the folder's own parts are compiled. False when a part
|
|
21
|
+
* it needs did not compile and its errors are reported elsewhere (a stage of the flow root).
|
|
22
|
+
*/
|
|
23
|
+
compose(): boolean;
|
|
24
|
+
};
|