opencode-gitlab-dap 1.5.1 → 1.6.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/README.md +40 -4
- package/dist/index.cjs +974 -2598
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +974 -2598
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/dist/index.js
CHANGED
|
@@ -2,2591 +2,8 @@
|
|
|
2
2
|
import { tool } from "@opencode-ai/plugin";
|
|
3
3
|
import { GitLabModelCache } from "gitlab-ai-provider";
|
|
4
4
|
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
return typeof subject === "undefined" || subject === null;
|
|
8
|
-
}
|
|
9
|
-
function isObject(subject) {
|
|
10
|
-
return typeof subject === "object" && subject !== null;
|
|
11
|
-
}
|
|
12
|
-
function toArray(sequence) {
|
|
13
|
-
if (Array.isArray(sequence)) return sequence;
|
|
14
|
-
else if (isNothing(sequence)) return [];
|
|
15
|
-
return [sequence];
|
|
16
|
-
}
|
|
17
|
-
function extend(target, source) {
|
|
18
|
-
var index, length, key, sourceKeys;
|
|
19
|
-
if (source) {
|
|
20
|
-
sourceKeys = Object.keys(source);
|
|
21
|
-
for (index = 0, length = sourceKeys.length; index < length; index += 1) {
|
|
22
|
-
key = sourceKeys[index];
|
|
23
|
-
target[key] = source[key];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return target;
|
|
27
|
-
}
|
|
28
|
-
function repeat(string, count) {
|
|
29
|
-
var result = "", cycle;
|
|
30
|
-
for (cycle = 0; cycle < count; cycle += 1) {
|
|
31
|
-
result += string;
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
function isNegativeZero(number) {
|
|
36
|
-
return number === 0 && Number.NEGATIVE_INFINITY === 1 / number;
|
|
37
|
-
}
|
|
38
|
-
var isNothing_1 = isNothing;
|
|
39
|
-
var isObject_1 = isObject;
|
|
40
|
-
var toArray_1 = toArray;
|
|
41
|
-
var repeat_1 = repeat;
|
|
42
|
-
var isNegativeZero_1 = isNegativeZero;
|
|
43
|
-
var extend_1 = extend;
|
|
44
|
-
var common = {
|
|
45
|
-
isNothing: isNothing_1,
|
|
46
|
-
isObject: isObject_1,
|
|
47
|
-
toArray: toArray_1,
|
|
48
|
-
repeat: repeat_1,
|
|
49
|
-
isNegativeZero: isNegativeZero_1,
|
|
50
|
-
extend: extend_1
|
|
51
|
-
};
|
|
52
|
-
function formatError(exception2, compact) {
|
|
53
|
-
var where = "", message = exception2.reason || "(unknown reason)";
|
|
54
|
-
if (!exception2.mark) return message;
|
|
55
|
-
if (exception2.mark.name) {
|
|
56
|
-
where += 'in "' + exception2.mark.name + '" ';
|
|
57
|
-
}
|
|
58
|
-
where += "(" + (exception2.mark.line + 1) + ":" + (exception2.mark.column + 1) + ")";
|
|
59
|
-
if (!compact && exception2.mark.snippet) {
|
|
60
|
-
where += "\n\n" + exception2.mark.snippet;
|
|
61
|
-
}
|
|
62
|
-
return message + " " + where;
|
|
63
|
-
}
|
|
64
|
-
function YAMLException$1(reason, mark) {
|
|
65
|
-
Error.call(this);
|
|
66
|
-
this.name = "YAMLException";
|
|
67
|
-
this.reason = reason;
|
|
68
|
-
this.mark = mark;
|
|
69
|
-
this.message = formatError(this, false);
|
|
70
|
-
if (Error.captureStackTrace) {
|
|
71
|
-
Error.captureStackTrace(this, this.constructor);
|
|
72
|
-
} else {
|
|
73
|
-
this.stack = new Error().stack || "";
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
YAMLException$1.prototype = Object.create(Error.prototype);
|
|
77
|
-
YAMLException$1.prototype.constructor = YAMLException$1;
|
|
78
|
-
YAMLException$1.prototype.toString = function toString(compact) {
|
|
79
|
-
return this.name + ": " + formatError(this, compact);
|
|
80
|
-
};
|
|
81
|
-
var exception = YAMLException$1;
|
|
82
|
-
function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
|
|
83
|
-
var head = "";
|
|
84
|
-
var tail = "";
|
|
85
|
-
var maxHalfLength = Math.floor(maxLineLength / 2) - 1;
|
|
86
|
-
if (position - lineStart > maxHalfLength) {
|
|
87
|
-
head = " ... ";
|
|
88
|
-
lineStart = position - maxHalfLength + head.length;
|
|
89
|
-
}
|
|
90
|
-
if (lineEnd - position > maxHalfLength) {
|
|
91
|
-
tail = " ...";
|
|
92
|
-
lineEnd = position + maxHalfLength - tail.length;
|
|
93
|
-
}
|
|
94
|
-
return {
|
|
95
|
-
str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "\u2192") + tail,
|
|
96
|
-
pos: position - lineStart + head.length
|
|
97
|
-
// relative position
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
function padStart(string, max) {
|
|
101
|
-
return common.repeat(" ", max - string.length) + string;
|
|
102
|
-
}
|
|
103
|
-
function makeSnippet(mark, options) {
|
|
104
|
-
options = Object.create(options || null);
|
|
105
|
-
if (!mark.buffer) return null;
|
|
106
|
-
if (!options.maxLength) options.maxLength = 79;
|
|
107
|
-
if (typeof options.indent !== "number") options.indent = 1;
|
|
108
|
-
if (typeof options.linesBefore !== "number") options.linesBefore = 3;
|
|
109
|
-
if (typeof options.linesAfter !== "number") options.linesAfter = 2;
|
|
110
|
-
var re = /\r?\n|\r|\0/g;
|
|
111
|
-
var lineStarts = [0];
|
|
112
|
-
var lineEnds = [];
|
|
113
|
-
var match;
|
|
114
|
-
var foundLineNo = -1;
|
|
115
|
-
while (match = re.exec(mark.buffer)) {
|
|
116
|
-
lineEnds.push(match.index);
|
|
117
|
-
lineStarts.push(match.index + match[0].length);
|
|
118
|
-
if (mark.position <= match.index && foundLineNo < 0) {
|
|
119
|
-
foundLineNo = lineStarts.length - 2;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (foundLineNo < 0) foundLineNo = lineStarts.length - 1;
|
|
123
|
-
var result = "", i, line;
|
|
124
|
-
var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length;
|
|
125
|
-
var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3);
|
|
126
|
-
for (i = 1; i <= options.linesBefore; i++) {
|
|
127
|
-
if (foundLineNo - i < 0) break;
|
|
128
|
-
line = getLine(
|
|
129
|
-
mark.buffer,
|
|
130
|
-
lineStarts[foundLineNo - i],
|
|
131
|
-
lineEnds[foundLineNo - i],
|
|
132
|
-
mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]),
|
|
133
|
-
maxLineLength
|
|
134
|
-
);
|
|
135
|
-
result = common.repeat(" ", options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) + " | " + line.str + "\n" + result;
|
|
136
|
-
}
|
|
137
|
-
line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
|
|
138
|
-
result += common.repeat(" ", options.indent) + padStart((mark.line + 1).toString(), lineNoLength) + " | " + line.str + "\n";
|
|
139
|
-
result += common.repeat("-", options.indent + lineNoLength + 3 + line.pos) + "^\n";
|
|
140
|
-
for (i = 1; i <= options.linesAfter; i++) {
|
|
141
|
-
if (foundLineNo + i >= lineEnds.length) break;
|
|
142
|
-
line = getLine(
|
|
143
|
-
mark.buffer,
|
|
144
|
-
lineStarts[foundLineNo + i],
|
|
145
|
-
lineEnds[foundLineNo + i],
|
|
146
|
-
mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]),
|
|
147
|
-
maxLineLength
|
|
148
|
-
);
|
|
149
|
-
result += common.repeat(" ", options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) + " | " + line.str + "\n";
|
|
150
|
-
}
|
|
151
|
-
return result.replace(/\n$/, "");
|
|
152
|
-
}
|
|
153
|
-
var snippet = makeSnippet;
|
|
154
|
-
var TYPE_CONSTRUCTOR_OPTIONS = [
|
|
155
|
-
"kind",
|
|
156
|
-
"multi",
|
|
157
|
-
"resolve",
|
|
158
|
-
"construct",
|
|
159
|
-
"instanceOf",
|
|
160
|
-
"predicate",
|
|
161
|
-
"represent",
|
|
162
|
-
"representName",
|
|
163
|
-
"defaultStyle",
|
|
164
|
-
"styleAliases"
|
|
165
|
-
];
|
|
166
|
-
var YAML_NODE_KINDS = [
|
|
167
|
-
"scalar",
|
|
168
|
-
"sequence",
|
|
169
|
-
"mapping"
|
|
170
|
-
];
|
|
171
|
-
function compileStyleAliases(map2) {
|
|
172
|
-
var result = {};
|
|
173
|
-
if (map2 !== null) {
|
|
174
|
-
Object.keys(map2).forEach(function(style) {
|
|
175
|
-
map2[style].forEach(function(alias) {
|
|
176
|
-
result[String(alias)] = style;
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
return result;
|
|
181
|
-
}
|
|
182
|
-
function Type$1(tag, options) {
|
|
183
|
-
options = options || {};
|
|
184
|
-
Object.keys(options).forEach(function(name) {
|
|
185
|
-
if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
|
|
186
|
-
throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
this.options = options;
|
|
190
|
-
this.tag = tag;
|
|
191
|
-
this.kind = options["kind"] || null;
|
|
192
|
-
this.resolve = options["resolve"] || function() {
|
|
193
|
-
return true;
|
|
194
|
-
};
|
|
195
|
-
this.construct = options["construct"] || function(data) {
|
|
196
|
-
return data;
|
|
197
|
-
};
|
|
198
|
-
this.instanceOf = options["instanceOf"] || null;
|
|
199
|
-
this.predicate = options["predicate"] || null;
|
|
200
|
-
this.represent = options["represent"] || null;
|
|
201
|
-
this.representName = options["representName"] || null;
|
|
202
|
-
this.defaultStyle = options["defaultStyle"] || null;
|
|
203
|
-
this.multi = options["multi"] || false;
|
|
204
|
-
this.styleAliases = compileStyleAliases(options["styleAliases"] || null);
|
|
205
|
-
if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
|
|
206
|
-
throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
var type = Type$1;
|
|
210
|
-
function compileList(schema2, name) {
|
|
211
|
-
var result = [];
|
|
212
|
-
schema2[name].forEach(function(currentType) {
|
|
213
|
-
var newIndex = result.length;
|
|
214
|
-
result.forEach(function(previousType, previousIndex) {
|
|
215
|
-
if (previousType.tag === currentType.tag && previousType.kind === currentType.kind && previousType.multi === currentType.multi) {
|
|
216
|
-
newIndex = previousIndex;
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
result[newIndex] = currentType;
|
|
220
|
-
});
|
|
221
|
-
return result;
|
|
222
|
-
}
|
|
223
|
-
function compileMap() {
|
|
224
|
-
var result = {
|
|
225
|
-
scalar: {},
|
|
226
|
-
sequence: {},
|
|
227
|
-
mapping: {},
|
|
228
|
-
fallback: {},
|
|
229
|
-
multi: {
|
|
230
|
-
scalar: [],
|
|
231
|
-
sequence: [],
|
|
232
|
-
mapping: [],
|
|
233
|
-
fallback: []
|
|
234
|
-
}
|
|
235
|
-
}, index, length;
|
|
236
|
-
function collectType(type2) {
|
|
237
|
-
if (type2.multi) {
|
|
238
|
-
result.multi[type2.kind].push(type2);
|
|
239
|
-
result.multi["fallback"].push(type2);
|
|
240
|
-
} else {
|
|
241
|
-
result[type2.kind][type2.tag] = result["fallback"][type2.tag] = type2;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
for (index = 0, length = arguments.length; index < length; index += 1) {
|
|
245
|
-
arguments[index].forEach(collectType);
|
|
246
|
-
}
|
|
247
|
-
return result;
|
|
248
|
-
}
|
|
249
|
-
function Schema$1(definition) {
|
|
250
|
-
return this.extend(definition);
|
|
251
|
-
}
|
|
252
|
-
Schema$1.prototype.extend = function extend2(definition) {
|
|
253
|
-
var implicit = [];
|
|
254
|
-
var explicit = [];
|
|
255
|
-
if (definition instanceof type) {
|
|
256
|
-
explicit.push(definition);
|
|
257
|
-
} else if (Array.isArray(definition)) {
|
|
258
|
-
explicit = explicit.concat(definition);
|
|
259
|
-
} else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) {
|
|
260
|
-
if (definition.implicit) implicit = implicit.concat(definition.implicit);
|
|
261
|
-
if (definition.explicit) explicit = explicit.concat(definition.explicit);
|
|
262
|
-
} else {
|
|
263
|
-
throw new exception("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");
|
|
264
|
-
}
|
|
265
|
-
implicit.forEach(function(type$1) {
|
|
266
|
-
if (!(type$1 instanceof type)) {
|
|
267
|
-
throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
|
|
268
|
-
}
|
|
269
|
-
if (type$1.loadKind && type$1.loadKind !== "scalar") {
|
|
270
|
-
throw new exception("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");
|
|
271
|
-
}
|
|
272
|
-
if (type$1.multi) {
|
|
273
|
-
throw new exception("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.");
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
explicit.forEach(function(type$1) {
|
|
277
|
-
if (!(type$1 instanceof type)) {
|
|
278
|
-
throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
var result = Object.create(Schema$1.prototype);
|
|
282
|
-
result.implicit = (this.implicit || []).concat(implicit);
|
|
283
|
-
result.explicit = (this.explicit || []).concat(explicit);
|
|
284
|
-
result.compiledImplicit = compileList(result, "implicit");
|
|
285
|
-
result.compiledExplicit = compileList(result, "explicit");
|
|
286
|
-
result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit);
|
|
287
|
-
return result;
|
|
288
|
-
};
|
|
289
|
-
var schema = Schema$1;
|
|
290
|
-
var str = new type("tag:yaml.org,2002:str", {
|
|
291
|
-
kind: "scalar",
|
|
292
|
-
construct: function(data) {
|
|
293
|
-
return data !== null ? data : "";
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
var seq = new type("tag:yaml.org,2002:seq", {
|
|
297
|
-
kind: "sequence",
|
|
298
|
-
construct: function(data) {
|
|
299
|
-
return data !== null ? data : [];
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
var map = new type("tag:yaml.org,2002:map", {
|
|
303
|
-
kind: "mapping",
|
|
304
|
-
construct: function(data) {
|
|
305
|
-
return data !== null ? data : {};
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
var failsafe = new schema({
|
|
309
|
-
explicit: [
|
|
310
|
-
str,
|
|
311
|
-
seq,
|
|
312
|
-
map
|
|
313
|
-
]
|
|
314
|
-
});
|
|
315
|
-
function resolveYamlNull(data) {
|
|
316
|
-
if (data === null) return true;
|
|
317
|
-
var max = data.length;
|
|
318
|
-
return max === 1 && data === "~" || max === 4 && (data === "null" || data === "Null" || data === "NULL");
|
|
319
|
-
}
|
|
320
|
-
function constructYamlNull() {
|
|
321
|
-
return null;
|
|
322
|
-
}
|
|
323
|
-
function isNull(object) {
|
|
324
|
-
return object === null;
|
|
325
|
-
}
|
|
326
|
-
var _null = new type("tag:yaml.org,2002:null", {
|
|
327
|
-
kind: "scalar",
|
|
328
|
-
resolve: resolveYamlNull,
|
|
329
|
-
construct: constructYamlNull,
|
|
330
|
-
predicate: isNull,
|
|
331
|
-
represent: {
|
|
332
|
-
canonical: function() {
|
|
333
|
-
return "~";
|
|
334
|
-
},
|
|
335
|
-
lowercase: function() {
|
|
336
|
-
return "null";
|
|
337
|
-
},
|
|
338
|
-
uppercase: function() {
|
|
339
|
-
return "NULL";
|
|
340
|
-
},
|
|
341
|
-
camelcase: function() {
|
|
342
|
-
return "Null";
|
|
343
|
-
},
|
|
344
|
-
empty: function() {
|
|
345
|
-
return "";
|
|
346
|
-
}
|
|
347
|
-
},
|
|
348
|
-
defaultStyle: "lowercase"
|
|
349
|
-
});
|
|
350
|
-
function resolveYamlBoolean(data) {
|
|
351
|
-
if (data === null) return false;
|
|
352
|
-
var max = data.length;
|
|
353
|
-
return max === 4 && (data === "true" || data === "True" || data === "TRUE") || max === 5 && (data === "false" || data === "False" || data === "FALSE");
|
|
354
|
-
}
|
|
355
|
-
function constructYamlBoolean(data) {
|
|
356
|
-
return data === "true" || data === "True" || data === "TRUE";
|
|
357
|
-
}
|
|
358
|
-
function isBoolean(object) {
|
|
359
|
-
return Object.prototype.toString.call(object) === "[object Boolean]";
|
|
360
|
-
}
|
|
361
|
-
var bool = new type("tag:yaml.org,2002:bool", {
|
|
362
|
-
kind: "scalar",
|
|
363
|
-
resolve: resolveYamlBoolean,
|
|
364
|
-
construct: constructYamlBoolean,
|
|
365
|
-
predicate: isBoolean,
|
|
366
|
-
represent: {
|
|
367
|
-
lowercase: function(object) {
|
|
368
|
-
return object ? "true" : "false";
|
|
369
|
-
},
|
|
370
|
-
uppercase: function(object) {
|
|
371
|
-
return object ? "TRUE" : "FALSE";
|
|
372
|
-
},
|
|
373
|
-
camelcase: function(object) {
|
|
374
|
-
return object ? "True" : "False";
|
|
375
|
-
}
|
|
376
|
-
},
|
|
377
|
-
defaultStyle: "lowercase"
|
|
378
|
-
});
|
|
379
|
-
function isHexCode(c) {
|
|
380
|
-
return 48 <= c && c <= 57 || 65 <= c && c <= 70 || 97 <= c && c <= 102;
|
|
381
|
-
}
|
|
382
|
-
function isOctCode(c) {
|
|
383
|
-
return 48 <= c && c <= 55;
|
|
384
|
-
}
|
|
385
|
-
function isDecCode(c) {
|
|
386
|
-
return 48 <= c && c <= 57;
|
|
387
|
-
}
|
|
388
|
-
function resolveYamlInteger(data) {
|
|
389
|
-
if (data === null) return false;
|
|
390
|
-
var max = data.length, index = 0, hasDigits = false, ch;
|
|
391
|
-
if (!max) return false;
|
|
392
|
-
ch = data[index];
|
|
393
|
-
if (ch === "-" || ch === "+") {
|
|
394
|
-
ch = data[++index];
|
|
395
|
-
}
|
|
396
|
-
if (ch === "0") {
|
|
397
|
-
if (index + 1 === max) return true;
|
|
398
|
-
ch = data[++index];
|
|
399
|
-
if (ch === "b") {
|
|
400
|
-
index++;
|
|
401
|
-
for (; index < max; index++) {
|
|
402
|
-
ch = data[index];
|
|
403
|
-
if (ch === "_") continue;
|
|
404
|
-
if (ch !== "0" && ch !== "1") return false;
|
|
405
|
-
hasDigits = true;
|
|
406
|
-
}
|
|
407
|
-
return hasDigits && ch !== "_";
|
|
408
|
-
}
|
|
409
|
-
if (ch === "x") {
|
|
410
|
-
index++;
|
|
411
|
-
for (; index < max; index++) {
|
|
412
|
-
ch = data[index];
|
|
413
|
-
if (ch === "_") continue;
|
|
414
|
-
if (!isHexCode(data.charCodeAt(index))) return false;
|
|
415
|
-
hasDigits = true;
|
|
416
|
-
}
|
|
417
|
-
return hasDigits && ch !== "_";
|
|
418
|
-
}
|
|
419
|
-
if (ch === "o") {
|
|
420
|
-
index++;
|
|
421
|
-
for (; index < max; index++) {
|
|
422
|
-
ch = data[index];
|
|
423
|
-
if (ch === "_") continue;
|
|
424
|
-
if (!isOctCode(data.charCodeAt(index))) return false;
|
|
425
|
-
hasDigits = true;
|
|
426
|
-
}
|
|
427
|
-
return hasDigits && ch !== "_";
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
if (ch === "_") return false;
|
|
431
|
-
for (; index < max; index++) {
|
|
432
|
-
ch = data[index];
|
|
433
|
-
if (ch === "_") continue;
|
|
434
|
-
if (!isDecCode(data.charCodeAt(index))) {
|
|
435
|
-
return false;
|
|
436
|
-
}
|
|
437
|
-
hasDigits = true;
|
|
438
|
-
}
|
|
439
|
-
if (!hasDigits || ch === "_") return false;
|
|
440
|
-
return true;
|
|
441
|
-
}
|
|
442
|
-
function constructYamlInteger(data) {
|
|
443
|
-
var value = data, sign = 1, ch;
|
|
444
|
-
if (value.indexOf("_") !== -1) {
|
|
445
|
-
value = value.replace(/_/g, "");
|
|
446
|
-
}
|
|
447
|
-
ch = value[0];
|
|
448
|
-
if (ch === "-" || ch === "+") {
|
|
449
|
-
if (ch === "-") sign = -1;
|
|
450
|
-
value = value.slice(1);
|
|
451
|
-
ch = value[0];
|
|
452
|
-
}
|
|
453
|
-
if (value === "0") return 0;
|
|
454
|
-
if (ch === "0") {
|
|
455
|
-
if (value[1] === "b") return sign * parseInt(value.slice(2), 2);
|
|
456
|
-
if (value[1] === "x") return sign * parseInt(value.slice(2), 16);
|
|
457
|
-
if (value[1] === "o") return sign * parseInt(value.slice(2), 8);
|
|
458
|
-
}
|
|
459
|
-
return sign * parseInt(value, 10);
|
|
460
|
-
}
|
|
461
|
-
function isInteger(object) {
|
|
462
|
-
return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 === 0 && !common.isNegativeZero(object));
|
|
463
|
-
}
|
|
464
|
-
var int = new type("tag:yaml.org,2002:int", {
|
|
465
|
-
kind: "scalar",
|
|
466
|
-
resolve: resolveYamlInteger,
|
|
467
|
-
construct: constructYamlInteger,
|
|
468
|
-
predicate: isInteger,
|
|
469
|
-
represent: {
|
|
470
|
-
binary: function(obj) {
|
|
471
|
-
return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1);
|
|
472
|
-
},
|
|
473
|
-
octal: function(obj) {
|
|
474
|
-
return obj >= 0 ? "0o" + obj.toString(8) : "-0o" + obj.toString(8).slice(1);
|
|
475
|
-
},
|
|
476
|
-
decimal: function(obj) {
|
|
477
|
-
return obj.toString(10);
|
|
478
|
-
},
|
|
479
|
-
/* eslint-disable max-len */
|
|
480
|
-
hexadecimal: function(obj) {
|
|
481
|
-
return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1);
|
|
482
|
-
}
|
|
483
|
-
},
|
|
484
|
-
defaultStyle: "decimal",
|
|
485
|
-
styleAliases: {
|
|
486
|
-
binary: [2, "bin"],
|
|
487
|
-
octal: [8, "oct"],
|
|
488
|
-
decimal: [10, "dec"],
|
|
489
|
-
hexadecimal: [16, "hex"]
|
|
490
|
-
}
|
|
491
|
-
});
|
|
492
|
-
var YAML_FLOAT_PATTERN = new RegExp(
|
|
493
|
-
// 2.5e4, 2.5 and integers
|
|
494
|
-
"^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$"
|
|
495
|
-
);
|
|
496
|
-
function resolveYamlFloat(data) {
|
|
497
|
-
if (data === null) return false;
|
|
498
|
-
if (!YAML_FLOAT_PATTERN.test(data) || // Quick hack to not allow integers end with `_`
|
|
499
|
-
// Probably should update regexp & check speed
|
|
500
|
-
data[data.length - 1] === "_") {
|
|
501
|
-
return false;
|
|
502
|
-
}
|
|
503
|
-
return true;
|
|
504
|
-
}
|
|
505
|
-
function constructYamlFloat(data) {
|
|
506
|
-
var value, sign;
|
|
507
|
-
value = data.replace(/_/g, "").toLowerCase();
|
|
508
|
-
sign = value[0] === "-" ? -1 : 1;
|
|
509
|
-
if ("+-".indexOf(value[0]) >= 0) {
|
|
510
|
-
value = value.slice(1);
|
|
511
|
-
}
|
|
512
|
-
if (value === ".inf") {
|
|
513
|
-
return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
514
|
-
} else if (value === ".nan") {
|
|
515
|
-
return NaN;
|
|
516
|
-
}
|
|
517
|
-
return sign * parseFloat(value, 10);
|
|
518
|
-
}
|
|
519
|
-
var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
|
|
520
|
-
function representYamlFloat(object, style) {
|
|
521
|
-
var res;
|
|
522
|
-
if (isNaN(object)) {
|
|
523
|
-
switch (style) {
|
|
524
|
-
case "lowercase":
|
|
525
|
-
return ".nan";
|
|
526
|
-
case "uppercase":
|
|
527
|
-
return ".NAN";
|
|
528
|
-
case "camelcase":
|
|
529
|
-
return ".NaN";
|
|
530
|
-
}
|
|
531
|
-
} else if (Number.POSITIVE_INFINITY === object) {
|
|
532
|
-
switch (style) {
|
|
533
|
-
case "lowercase":
|
|
534
|
-
return ".inf";
|
|
535
|
-
case "uppercase":
|
|
536
|
-
return ".INF";
|
|
537
|
-
case "camelcase":
|
|
538
|
-
return ".Inf";
|
|
539
|
-
}
|
|
540
|
-
} else if (Number.NEGATIVE_INFINITY === object) {
|
|
541
|
-
switch (style) {
|
|
542
|
-
case "lowercase":
|
|
543
|
-
return "-.inf";
|
|
544
|
-
case "uppercase":
|
|
545
|
-
return "-.INF";
|
|
546
|
-
case "camelcase":
|
|
547
|
-
return "-.Inf";
|
|
548
|
-
}
|
|
549
|
-
} else if (common.isNegativeZero(object)) {
|
|
550
|
-
return "-0.0";
|
|
551
|
-
}
|
|
552
|
-
res = object.toString(10);
|
|
553
|
-
return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace("e", ".e") : res;
|
|
554
|
-
}
|
|
555
|
-
function isFloat(object) {
|
|
556
|
-
return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || common.isNegativeZero(object));
|
|
557
|
-
}
|
|
558
|
-
var float = new type("tag:yaml.org,2002:float", {
|
|
559
|
-
kind: "scalar",
|
|
560
|
-
resolve: resolveYamlFloat,
|
|
561
|
-
construct: constructYamlFloat,
|
|
562
|
-
predicate: isFloat,
|
|
563
|
-
represent: representYamlFloat,
|
|
564
|
-
defaultStyle: "lowercase"
|
|
565
|
-
});
|
|
566
|
-
var json = failsafe.extend({
|
|
567
|
-
implicit: [
|
|
568
|
-
_null,
|
|
569
|
-
bool,
|
|
570
|
-
int,
|
|
571
|
-
float
|
|
572
|
-
]
|
|
573
|
-
});
|
|
574
|
-
var core = json;
|
|
575
|
-
var YAML_DATE_REGEXP = new RegExp(
|
|
576
|
-
"^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"
|
|
577
|
-
);
|
|
578
|
-
var YAML_TIMESTAMP_REGEXP = new RegExp(
|
|
579
|
-
"^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$"
|
|
580
|
-
);
|
|
581
|
-
function resolveYamlTimestamp(data) {
|
|
582
|
-
if (data === null) return false;
|
|
583
|
-
if (YAML_DATE_REGEXP.exec(data) !== null) return true;
|
|
584
|
-
if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
|
|
585
|
-
return false;
|
|
586
|
-
}
|
|
587
|
-
function constructYamlTimestamp(data) {
|
|
588
|
-
var match, year, month, day, hour, minute, second, fraction = 0, delta = null, tz_hour, tz_minute, date;
|
|
589
|
-
match = YAML_DATE_REGEXP.exec(data);
|
|
590
|
-
if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
|
|
591
|
-
if (match === null) throw new Error("Date resolve error");
|
|
592
|
-
year = +match[1];
|
|
593
|
-
month = +match[2] - 1;
|
|
594
|
-
day = +match[3];
|
|
595
|
-
if (!match[4]) {
|
|
596
|
-
return new Date(Date.UTC(year, month, day));
|
|
597
|
-
}
|
|
598
|
-
hour = +match[4];
|
|
599
|
-
minute = +match[5];
|
|
600
|
-
second = +match[6];
|
|
601
|
-
if (match[7]) {
|
|
602
|
-
fraction = match[7].slice(0, 3);
|
|
603
|
-
while (fraction.length < 3) {
|
|
604
|
-
fraction += "0";
|
|
605
|
-
}
|
|
606
|
-
fraction = +fraction;
|
|
607
|
-
}
|
|
608
|
-
if (match[9]) {
|
|
609
|
-
tz_hour = +match[10];
|
|
610
|
-
tz_minute = +(match[11] || 0);
|
|
611
|
-
delta = (tz_hour * 60 + tz_minute) * 6e4;
|
|
612
|
-
if (match[9] === "-") delta = -delta;
|
|
613
|
-
}
|
|
614
|
-
date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
|
|
615
|
-
if (delta) date.setTime(date.getTime() - delta);
|
|
616
|
-
return date;
|
|
617
|
-
}
|
|
618
|
-
function representYamlTimestamp(object) {
|
|
619
|
-
return object.toISOString();
|
|
620
|
-
}
|
|
621
|
-
var timestamp = new type("tag:yaml.org,2002:timestamp", {
|
|
622
|
-
kind: "scalar",
|
|
623
|
-
resolve: resolveYamlTimestamp,
|
|
624
|
-
construct: constructYamlTimestamp,
|
|
625
|
-
instanceOf: Date,
|
|
626
|
-
represent: representYamlTimestamp
|
|
627
|
-
});
|
|
628
|
-
function resolveYamlMerge(data) {
|
|
629
|
-
return data === "<<" || data === null;
|
|
630
|
-
}
|
|
631
|
-
var merge = new type("tag:yaml.org,2002:merge", {
|
|
632
|
-
kind: "scalar",
|
|
633
|
-
resolve: resolveYamlMerge
|
|
634
|
-
});
|
|
635
|
-
var BASE64_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";
|
|
636
|
-
function resolveYamlBinary(data) {
|
|
637
|
-
if (data === null) return false;
|
|
638
|
-
var code, idx, bitlen = 0, max = data.length, map2 = BASE64_MAP;
|
|
639
|
-
for (idx = 0; idx < max; idx++) {
|
|
640
|
-
code = map2.indexOf(data.charAt(idx));
|
|
641
|
-
if (code > 64) continue;
|
|
642
|
-
if (code < 0) return false;
|
|
643
|
-
bitlen += 6;
|
|
644
|
-
}
|
|
645
|
-
return bitlen % 8 === 0;
|
|
646
|
-
}
|
|
647
|
-
function constructYamlBinary(data) {
|
|
648
|
-
var idx, tailbits, input = data.replace(/[\r\n=]/g, ""), max = input.length, map2 = BASE64_MAP, bits = 0, result = [];
|
|
649
|
-
for (idx = 0; idx < max; idx++) {
|
|
650
|
-
if (idx % 4 === 0 && idx) {
|
|
651
|
-
result.push(bits >> 16 & 255);
|
|
652
|
-
result.push(bits >> 8 & 255);
|
|
653
|
-
result.push(bits & 255);
|
|
654
|
-
}
|
|
655
|
-
bits = bits << 6 | map2.indexOf(input.charAt(idx));
|
|
656
|
-
}
|
|
657
|
-
tailbits = max % 4 * 6;
|
|
658
|
-
if (tailbits === 0) {
|
|
659
|
-
result.push(bits >> 16 & 255);
|
|
660
|
-
result.push(bits >> 8 & 255);
|
|
661
|
-
result.push(bits & 255);
|
|
662
|
-
} else if (tailbits === 18) {
|
|
663
|
-
result.push(bits >> 10 & 255);
|
|
664
|
-
result.push(bits >> 2 & 255);
|
|
665
|
-
} else if (tailbits === 12) {
|
|
666
|
-
result.push(bits >> 4 & 255);
|
|
667
|
-
}
|
|
668
|
-
return new Uint8Array(result);
|
|
669
|
-
}
|
|
670
|
-
function representYamlBinary(object) {
|
|
671
|
-
var result = "", bits = 0, idx, tail, max = object.length, map2 = BASE64_MAP;
|
|
672
|
-
for (idx = 0; idx < max; idx++) {
|
|
673
|
-
if (idx % 3 === 0 && idx) {
|
|
674
|
-
result += map2[bits >> 18 & 63];
|
|
675
|
-
result += map2[bits >> 12 & 63];
|
|
676
|
-
result += map2[bits >> 6 & 63];
|
|
677
|
-
result += map2[bits & 63];
|
|
678
|
-
}
|
|
679
|
-
bits = (bits << 8) + object[idx];
|
|
680
|
-
}
|
|
681
|
-
tail = max % 3;
|
|
682
|
-
if (tail === 0) {
|
|
683
|
-
result += map2[bits >> 18 & 63];
|
|
684
|
-
result += map2[bits >> 12 & 63];
|
|
685
|
-
result += map2[bits >> 6 & 63];
|
|
686
|
-
result += map2[bits & 63];
|
|
687
|
-
} else if (tail === 2) {
|
|
688
|
-
result += map2[bits >> 10 & 63];
|
|
689
|
-
result += map2[bits >> 4 & 63];
|
|
690
|
-
result += map2[bits << 2 & 63];
|
|
691
|
-
result += map2[64];
|
|
692
|
-
} else if (tail === 1) {
|
|
693
|
-
result += map2[bits >> 2 & 63];
|
|
694
|
-
result += map2[bits << 4 & 63];
|
|
695
|
-
result += map2[64];
|
|
696
|
-
result += map2[64];
|
|
697
|
-
}
|
|
698
|
-
return result;
|
|
699
|
-
}
|
|
700
|
-
function isBinary(obj) {
|
|
701
|
-
return Object.prototype.toString.call(obj) === "[object Uint8Array]";
|
|
702
|
-
}
|
|
703
|
-
var binary = new type("tag:yaml.org,2002:binary", {
|
|
704
|
-
kind: "scalar",
|
|
705
|
-
resolve: resolveYamlBinary,
|
|
706
|
-
construct: constructYamlBinary,
|
|
707
|
-
predicate: isBinary,
|
|
708
|
-
represent: representYamlBinary
|
|
709
|
-
});
|
|
710
|
-
var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
|
|
711
|
-
var _toString$2 = Object.prototype.toString;
|
|
712
|
-
function resolveYamlOmap(data) {
|
|
713
|
-
if (data === null) return true;
|
|
714
|
-
var objectKeys = [], index, length, pair, pairKey, pairHasKey, object = data;
|
|
715
|
-
for (index = 0, length = object.length; index < length; index += 1) {
|
|
716
|
-
pair = object[index];
|
|
717
|
-
pairHasKey = false;
|
|
718
|
-
if (_toString$2.call(pair) !== "[object Object]") return false;
|
|
719
|
-
for (pairKey in pair) {
|
|
720
|
-
if (_hasOwnProperty$3.call(pair, pairKey)) {
|
|
721
|
-
if (!pairHasKey) pairHasKey = true;
|
|
722
|
-
else return false;
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
if (!pairHasKey) return false;
|
|
726
|
-
if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
|
|
727
|
-
else return false;
|
|
728
|
-
}
|
|
729
|
-
return true;
|
|
730
|
-
}
|
|
731
|
-
function constructYamlOmap(data) {
|
|
732
|
-
return data !== null ? data : [];
|
|
733
|
-
}
|
|
734
|
-
var omap = new type("tag:yaml.org,2002:omap", {
|
|
735
|
-
kind: "sequence",
|
|
736
|
-
resolve: resolveYamlOmap,
|
|
737
|
-
construct: constructYamlOmap
|
|
738
|
-
});
|
|
739
|
-
var _toString$1 = Object.prototype.toString;
|
|
740
|
-
function resolveYamlPairs(data) {
|
|
741
|
-
if (data === null) return true;
|
|
742
|
-
var index, length, pair, keys, result, object = data;
|
|
743
|
-
result = new Array(object.length);
|
|
744
|
-
for (index = 0, length = object.length; index < length; index += 1) {
|
|
745
|
-
pair = object[index];
|
|
746
|
-
if (_toString$1.call(pair) !== "[object Object]") return false;
|
|
747
|
-
keys = Object.keys(pair);
|
|
748
|
-
if (keys.length !== 1) return false;
|
|
749
|
-
result[index] = [keys[0], pair[keys[0]]];
|
|
750
|
-
}
|
|
751
|
-
return true;
|
|
752
|
-
}
|
|
753
|
-
function constructYamlPairs(data) {
|
|
754
|
-
if (data === null) return [];
|
|
755
|
-
var index, length, pair, keys, result, object = data;
|
|
756
|
-
result = new Array(object.length);
|
|
757
|
-
for (index = 0, length = object.length; index < length; index += 1) {
|
|
758
|
-
pair = object[index];
|
|
759
|
-
keys = Object.keys(pair);
|
|
760
|
-
result[index] = [keys[0], pair[keys[0]]];
|
|
761
|
-
}
|
|
762
|
-
return result;
|
|
763
|
-
}
|
|
764
|
-
var pairs = new type("tag:yaml.org,2002:pairs", {
|
|
765
|
-
kind: "sequence",
|
|
766
|
-
resolve: resolveYamlPairs,
|
|
767
|
-
construct: constructYamlPairs
|
|
768
|
-
});
|
|
769
|
-
var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
|
770
|
-
function resolveYamlSet(data) {
|
|
771
|
-
if (data === null) return true;
|
|
772
|
-
var key, object = data;
|
|
773
|
-
for (key in object) {
|
|
774
|
-
if (_hasOwnProperty$2.call(object, key)) {
|
|
775
|
-
if (object[key] !== null) return false;
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
return true;
|
|
779
|
-
}
|
|
780
|
-
function constructYamlSet(data) {
|
|
781
|
-
return data !== null ? data : {};
|
|
782
|
-
}
|
|
783
|
-
var set = new type("tag:yaml.org,2002:set", {
|
|
784
|
-
kind: "mapping",
|
|
785
|
-
resolve: resolveYamlSet,
|
|
786
|
-
construct: constructYamlSet
|
|
787
|
-
});
|
|
788
|
-
var _default = core.extend({
|
|
789
|
-
implicit: [
|
|
790
|
-
timestamp,
|
|
791
|
-
merge
|
|
792
|
-
],
|
|
793
|
-
explicit: [
|
|
794
|
-
binary,
|
|
795
|
-
omap,
|
|
796
|
-
pairs,
|
|
797
|
-
set
|
|
798
|
-
]
|
|
799
|
-
});
|
|
800
|
-
var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
801
|
-
var CONTEXT_FLOW_IN = 1;
|
|
802
|
-
var CONTEXT_FLOW_OUT = 2;
|
|
803
|
-
var CONTEXT_BLOCK_IN = 3;
|
|
804
|
-
var CONTEXT_BLOCK_OUT = 4;
|
|
805
|
-
var CHOMPING_CLIP = 1;
|
|
806
|
-
var CHOMPING_STRIP = 2;
|
|
807
|
-
var CHOMPING_KEEP = 3;
|
|
808
|
-
var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
|
|
809
|
-
var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
|
|
810
|
-
var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
|
|
811
|
-
var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
|
|
812
|
-
var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
|
|
813
|
-
function _class(obj) {
|
|
814
|
-
return Object.prototype.toString.call(obj);
|
|
815
|
-
}
|
|
816
|
-
function is_EOL(c) {
|
|
817
|
-
return c === 10 || c === 13;
|
|
818
|
-
}
|
|
819
|
-
function is_WHITE_SPACE(c) {
|
|
820
|
-
return c === 9 || c === 32;
|
|
821
|
-
}
|
|
822
|
-
function is_WS_OR_EOL(c) {
|
|
823
|
-
return c === 9 || c === 32 || c === 10 || c === 13;
|
|
824
|
-
}
|
|
825
|
-
function is_FLOW_INDICATOR(c) {
|
|
826
|
-
return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
|
|
827
|
-
}
|
|
828
|
-
function fromHexCode(c) {
|
|
829
|
-
var lc;
|
|
830
|
-
if (48 <= c && c <= 57) {
|
|
831
|
-
return c - 48;
|
|
832
|
-
}
|
|
833
|
-
lc = c | 32;
|
|
834
|
-
if (97 <= lc && lc <= 102) {
|
|
835
|
-
return lc - 97 + 10;
|
|
836
|
-
}
|
|
837
|
-
return -1;
|
|
838
|
-
}
|
|
839
|
-
function escapedHexLen(c) {
|
|
840
|
-
if (c === 120) {
|
|
841
|
-
return 2;
|
|
842
|
-
}
|
|
843
|
-
if (c === 117) {
|
|
844
|
-
return 4;
|
|
845
|
-
}
|
|
846
|
-
if (c === 85) {
|
|
847
|
-
return 8;
|
|
848
|
-
}
|
|
849
|
-
return 0;
|
|
850
|
-
}
|
|
851
|
-
function fromDecimalCode(c) {
|
|
852
|
-
if (48 <= c && c <= 57) {
|
|
853
|
-
return c - 48;
|
|
854
|
-
}
|
|
855
|
-
return -1;
|
|
856
|
-
}
|
|
857
|
-
function simpleEscapeSequence(c) {
|
|
858
|
-
return c === 48 ? "\0" : c === 97 ? "\x07" : c === 98 ? "\b" : c === 116 ? " " : c === 9 ? " " : c === 110 ? "\n" : c === 118 ? "\v" : c === 102 ? "\f" : c === 114 ? "\r" : c === 101 ? "\x1B" : c === 32 ? " " : c === 34 ? '"' : c === 47 ? "/" : c === 92 ? "\\" : c === 78 ? "\x85" : c === 95 ? "\xA0" : c === 76 ? "\u2028" : c === 80 ? "\u2029" : "";
|
|
859
|
-
}
|
|
860
|
-
function charFromCodepoint(c) {
|
|
861
|
-
if (c <= 65535) {
|
|
862
|
-
return String.fromCharCode(c);
|
|
863
|
-
}
|
|
864
|
-
return String.fromCharCode(
|
|
865
|
-
(c - 65536 >> 10) + 55296,
|
|
866
|
-
(c - 65536 & 1023) + 56320
|
|
867
|
-
);
|
|
868
|
-
}
|
|
869
|
-
function setProperty(object, key, value) {
|
|
870
|
-
if (key === "__proto__") {
|
|
871
|
-
Object.defineProperty(object, key, {
|
|
872
|
-
configurable: true,
|
|
873
|
-
enumerable: true,
|
|
874
|
-
writable: true,
|
|
875
|
-
value
|
|
876
|
-
});
|
|
877
|
-
} else {
|
|
878
|
-
object[key] = value;
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
var simpleEscapeCheck = new Array(256);
|
|
882
|
-
var simpleEscapeMap = new Array(256);
|
|
883
|
-
for (i = 0; i < 256; i++) {
|
|
884
|
-
simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
|
|
885
|
-
simpleEscapeMap[i] = simpleEscapeSequence(i);
|
|
886
|
-
}
|
|
887
|
-
var i;
|
|
888
|
-
function State$1(input, options) {
|
|
889
|
-
this.input = input;
|
|
890
|
-
this.filename = options["filename"] || null;
|
|
891
|
-
this.schema = options["schema"] || _default;
|
|
892
|
-
this.onWarning = options["onWarning"] || null;
|
|
893
|
-
this.legacy = options["legacy"] || false;
|
|
894
|
-
this.json = options["json"] || false;
|
|
895
|
-
this.listener = options["listener"] || null;
|
|
896
|
-
this.implicitTypes = this.schema.compiledImplicit;
|
|
897
|
-
this.typeMap = this.schema.compiledTypeMap;
|
|
898
|
-
this.length = input.length;
|
|
899
|
-
this.position = 0;
|
|
900
|
-
this.line = 0;
|
|
901
|
-
this.lineStart = 0;
|
|
902
|
-
this.lineIndent = 0;
|
|
903
|
-
this.firstTabInLine = -1;
|
|
904
|
-
this.documents = [];
|
|
905
|
-
}
|
|
906
|
-
function generateError(state, message) {
|
|
907
|
-
var mark = {
|
|
908
|
-
name: state.filename,
|
|
909
|
-
buffer: state.input.slice(0, -1),
|
|
910
|
-
// omit trailing \0
|
|
911
|
-
position: state.position,
|
|
912
|
-
line: state.line,
|
|
913
|
-
column: state.position - state.lineStart
|
|
914
|
-
};
|
|
915
|
-
mark.snippet = snippet(mark);
|
|
916
|
-
return new exception(message, mark);
|
|
917
|
-
}
|
|
918
|
-
function throwError(state, message) {
|
|
919
|
-
throw generateError(state, message);
|
|
920
|
-
}
|
|
921
|
-
function throwWarning(state, message) {
|
|
922
|
-
if (state.onWarning) {
|
|
923
|
-
state.onWarning.call(null, generateError(state, message));
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
var directiveHandlers = {
|
|
927
|
-
YAML: function handleYamlDirective(state, name, args) {
|
|
928
|
-
var match, major, minor;
|
|
929
|
-
if (state.version !== null) {
|
|
930
|
-
throwError(state, "duplication of %YAML directive");
|
|
931
|
-
}
|
|
932
|
-
if (args.length !== 1) {
|
|
933
|
-
throwError(state, "YAML directive accepts exactly one argument");
|
|
934
|
-
}
|
|
935
|
-
match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
|
|
936
|
-
if (match === null) {
|
|
937
|
-
throwError(state, "ill-formed argument of the YAML directive");
|
|
938
|
-
}
|
|
939
|
-
major = parseInt(match[1], 10);
|
|
940
|
-
minor = parseInt(match[2], 10);
|
|
941
|
-
if (major !== 1) {
|
|
942
|
-
throwError(state, "unacceptable YAML version of the document");
|
|
943
|
-
}
|
|
944
|
-
state.version = args[0];
|
|
945
|
-
state.checkLineBreaks = minor < 2;
|
|
946
|
-
if (minor !== 1 && minor !== 2) {
|
|
947
|
-
throwWarning(state, "unsupported YAML version of the document");
|
|
948
|
-
}
|
|
949
|
-
},
|
|
950
|
-
TAG: function handleTagDirective(state, name, args) {
|
|
951
|
-
var handle, prefix;
|
|
952
|
-
if (args.length !== 2) {
|
|
953
|
-
throwError(state, "TAG directive accepts exactly two arguments");
|
|
954
|
-
}
|
|
955
|
-
handle = args[0];
|
|
956
|
-
prefix = args[1];
|
|
957
|
-
if (!PATTERN_TAG_HANDLE.test(handle)) {
|
|
958
|
-
throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
|
|
959
|
-
}
|
|
960
|
-
if (_hasOwnProperty$1.call(state.tagMap, handle)) {
|
|
961
|
-
throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
|
|
962
|
-
}
|
|
963
|
-
if (!PATTERN_TAG_URI.test(prefix)) {
|
|
964
|
-
throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
|
|
965
|
-
}
|
|
966
|
-
try {
|
|
967
|
-
prefix = decodeURIComponent(prefix);
|
|
968
|
-
} catch (err) {
|
|
969
|
-
throwError(state, "tag prefix is malformed: " + prefix);
|
|
970
|
-
}
|
|
971
|
-
state.tagMap[handle] = prefix;
|
|
972
|
-
}
|
|
973
|
-
};
|
|
974
|
-
function captureSegment(state, start, end, checkJson) {
|
|
975
|
-
var _position, _length, _character, _result;
|
|
976
|
-
if (start < end) {
|
|
977
|
-
_result = state.input.slice(start, end);
|
|
978
|
-
if (checkJson) {
|
|
979
|
-
for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
|
|
980
|
-
_character = _result.charCodeAt(_position);
|
|
981
|
-
if (!(_character === 9 || 32 <= _character && _character <= 1114111)) {
|
|
982
|
-
throwError(state, "expected valid JSON character");
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
} else if (PATTERN_NON_PRINTABLE.test(_result)) {
|
|
986
|
-
throwError(state, "the stream contains non-printable characters");
|
|
987
|
-
}
|
|
988
|
-
state.result += _result;
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
function mergeMappings(state, destination, source, overridableKeys) {
|
|
992
|
-
var sourceKeys, key, index, quantity;
|
|
993
|
-
if (!common.isObject(source)) {
|
|
994
|
-
throwError(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
995
|
-
}
|
|
996
|
-
sourceKeys = Object.keys(source);
|
|
997
|
-
for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
|
|
998
|
-
key = sourceKeys[index];
|
|
999
|
-
if (!_hasOwnProperty$1.call(destination, key)) {
|
|
1000
|
-
setProperty(destination, key, source[key]);
|
|
1001
|
-
overridableKeys[key] = true;
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startLineStart, startPos) {
|
|
1006
|
-
var index, quantity;
|
|
1007
|
-
if (Array.isArray(keyNode)) {
|
|
1008
|
-
keyNode = Array.prototype.slice.call(keyNode);
|
|
1009
|
-
for (index = 0, quantity = keyNode.length; index < quantity; index += 1) {
|
|
1010
|
-
if (Array.isArray(keyNode[index])) {
|
|
1011
|
-
throwError(state, "nested arrays are not supported inside keys");
|
|
1012
|
-
}
|
|
1013
|
-
if (typeof keyNode === "object" && _class(keyNode[index]) === "[object Object]") {
|
|
1014
|
-
keyNode[index] = "[object Object]";
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
if (typeof keyNode === "object" && _class(keyNode) === "[object Object]") {
|
|
1019
|
-
keyNode = "[object Object]";
|
|
1020
|
-
}
|
|
1021
|
-
keyNode = String(keyNode);
|
|
1022
|
-
if (_result === null) {
|
|
1023
|
-
_result = {};
|
|
1024
|
-
}
|
|
1025
|
-
if (keyTag === "tag:yaml.org,2002:merge") {
|
|
1026
|
-
if (Array.isArray(valueNode)) {
|
|
1027
|
-
for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
|
|
1028
|
-
mergeMappings(state, _result, valueNode[index], overridableKeys);
|
|
1029
|
-
}
|
|
1030
|
-
} else {
|
|
1031
|
-
mergeMappings(state, _result, valueNode, overridableKeys);
|
|
1032
|
-
}
|
|
1033
|
-
} else {
|
|
1034
|
-
if (!state.json && !_hasOwnProperty$1.call(overridableKeys, keyNode) && _hasOwnProperty$1.call(_result, keyNode)) {
|
|
1035
|
-
state.line = startLine || state.line;
|
|
1036
|
-
state.lineStart = startLineStart || state.lineStart;
|
|
1037
|
-
state.position = startPos || state.position;
|
|
1038
|
-
throwError(state, "duplicated mapping key");
|
|
1039
|
-
}
|
|
1040
|
-
setProperty(_result, keyNode, valueNode);
|
|
1041
|
-
delete overridableKeys[keyNode];
|
|
1042
|
-
}
|
|
1043
|
-
return _result;
|
|
1044
|
-
}
|
|
1045
|
-
function readLineBreak(state) {
|
|
1046
|
-
var ch;
|
|
1047
|
-
ch = state.input.charCodeAt(state.position);
|
|
1048
|
-
if (ch === 10) {
|
|
1049
|
-
state.position++;
|
|
1050
|
-
} else if (ch === 13) {
|
|
1051
|
-
state.position++;
|
|
1052
|
-
if (state.input.charCodeAt(state.position) === 10) {
|
|
1053
|
-
state.position++;
|
|
1054
|
-
}
|
|
1055
|
-
} else {
|
|
1056
|
-
throwError(state, "a line break is expected");
|
|
1057
|
-
}
|
|
1058
|
-
state.line += 1;
|
|
1059
|
-
state.lineStart = state.position;
|
|
1060
|
-
state.firstTabInLine = -1;
|
|
1061
|
-
}
|
|
1062
|
-
function skipSeparationSpace(state, allowComments, checkIndent) {
|
|
1063
|
-
var lineBreaks = 0, ch = state.input.charCodeAt(state.position);
|
|
1064
|
-
while (ch !== 0) {
|
|
1065
|
-
while (is_WHITE_SPACE(ch)) {
|
|
1066
|
-
if (ch === 9 && state.firstTabInLine === -1) {
|
|
1067
|
-
state.firstTabInLine = state.position;
|
|
1068
|
-
}
|
|
1069
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1070
|
-
}
|
|
1071
|
-
if (allowComments && ch === 35) {
|
|
1072
|
-
do {
|
|
1073
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1074
|
-
} while (ch !== 10 && ch !== 13 && ch !== 0);
|
|
1075
|
-
}
|
|
1076
|
-
if (is_EOL(ch)) {
|
|
1077
|
-
readLineBreak(state);
|
|
1078
|
-
ch = state.input.charCodeAt(state.position);
|
|
1079
|
-
lineBreaks++;
|
|
1080
|
-
state.lineIndent = 0;
|
|
1081
|
-
while (ch === 32) {
|
|
1082
|
-
state.lineIndent++;
|
|
1083
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1084
|
-
}
|
|
1085
|
-
} else {
|
|
1086
|
-
break;
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
|
|
1090
|
-
throwWarning(state, "deficient indentation");
|
|
1091
|
-
}
|
|
1092
|
-
return lineBreaks;
|
|
1093
|
-
}
|
|
1094
|
-
function testDocumentSeparator(state) {
|
|
1095
|
-
var _position = state.position, ch;
|
|
1096
|
-
ch = state.input.charCodeAt(_position);
|
|
1097
|
-
if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(_position + 1) && ch === state.input.charCodeAt(_position + 2)) {
|
|
1098
|
-
_position += 3;
|
|
1099
|
-
ch = state.input.charCodeAt(_position);
|
|
1100
|
-
if (ch === 0 || is_WS_OR_EOL(ch)) {
|
|
1101
|
-
return true;
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
return false;
|
|
1105
|
-
}
|
|
1106
|
-
function writeFoldedLines(state, count) {
|
|
1107
|
-
if (count === 1) {
|
|
1108
|
-
state.result += " ";
|
|
1109
|
-
} else if (count > 1) {
|
|
1110
|
-
state.result += common.repeat("\n", count - 1);
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
function readPlainScalar(state, nodeIndent, withinFlowCollection) {
|
|
1114
|
-
var preceding, following, captureStart, captureEnd, hasPendingContent, _line, _lineStart, _lineIndent, _kind = state.kind, _result = state.result, ch;
|
|
1115
|
-
ch = state.input.charCodeAt(state.position);
|
|
1116
|
-
if (is_WS_OR_EOL(ch) || is_FLOW_INDICATOR(ch) || ch === 35 || ch === 38 || ch === 42 || ch === 33 || ch === 124 || ch === 62 || ch === 39 || ch === 34 || ch === 37 || ch === 64 || ch === 96) {
|
|
1117
|
-
return false;
|
|
1118
|
-
}
|
|
1119
|
-
if (ch === 63 || ch === 45) {
|
|
1120
|
-
following = state.input.charCodeAt(state.position + 1);
|
|
1121
|
-
if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
|
1122
|
-
return false;
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
state.kind = "scalar";
|
|
1126
|
-
state.result = "";
|
|
1127
|
-
captureStart = captureEnd = state.position;
|
|
1128
|
-
hasPendingContent = false;
|
|
1129
|
-
while (ch !== 0) {
|
|
1130
|
-
if (ch === 58) {
|
|
1131
|
-
following = state.input.charCodeAt(state.position + 1);
|
|
1132
|
-
if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
|
1133
|
-
break;
|
|
1134
|
-
}
|
|
1135
|
-
} else if (ch === 35) {
|
|
1136
|
-
preceding = state.input.charCodeAt(state.position - 1);
|
|
1137
|
-
if (is_WS_OR_EOL(preceding)) {
|
|
1138
|
-
break;
|
|
1139
|
-
}
|
|
1140
|
-
} else if (state.position === state.lineStart && testDocumentSeparator(state) || withinFlowCollection && is_FLOW_INDICATOR(ch)) {
|
|
1141
|
-
break;
|
|
1142
|
-
} else if (is_EOL(ch)) {
|
|
1143
|
-
_line = state.line;
|
|
1144
|
-
_lineStart = state.lineStart;
|
|
1145
|
-
_lineIndent = state.lineIndent;
|
|
1146
|
-
skipSeparationSpace(state, false, -1);
|
|
1147
|
-
if (state.lineIndent >= nodeIndent) {
|
|
1148
|
-
hasPendingContent = true;
|
|
1149
|
-
ch = state.input.charCodeAt(state.position);
|
|
1150
|
-
continue;
|
|
1151
|
-
} else {
|
|
1152
|
-
state.position = captureEnd;
|
|
1153
|
-
state.line = _line;
|
|
1154
|
-
state.lineStart = _lineStart;
|
|
1155
|
-
state.lineIndent = _lineIndent;
|
|
1156
|
-
break;
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
if (hasPendingContent) {
|
|
1160
|
-
captureSegment(state, captureStart, captureEnd, false);
|
|
1161
|
-
writeFoldedLines(state, state.line - _line);
|
|
1162
|
-
captureStart = captureEnd = state.position;
|
|
1163
|
-
hasPendingContent = false;
|
|
1164
|
-
}
|
|
1165
|
-
if (!is_WHITE_SPACE(ch)) {
|
|
1166
|
-
captureEnd = state.position + 1;
|
|
1167
|
-
}
|
|
1168
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1169
|
-
}
|
|
1170
|
-
captureSegment(state, captureStart, captureEnd, false);
|
|
1171
|
-
if (state.result) {
|
|
1172
|
-
return true;
|
|
1173
|
-
}
|
|
1174
|
-
state.kind = _kind;
|
|
1175
|
-
state.result = _result;
|
|
1176
|
-
return false;
|
|
1177
|
-
}
|
|
1178
|
-
function readSingleQuotedScalar(state, nodeIndent) {
|
|
1179
|
-
var ch, captureStart, captureEnd;
|
|
1180
|
-
ch = state.input.charCodeAt(state.position);
|
|
1181
|
-
if (ch !== 39) {
|
|
1182
|
-
return false;
|
|
1183
|
-
}
|
|
1184
|
-
state.kind = "scalar";
|
|
1185
|
-
state.result = "";
|
|
1186
|
-
state.position++;
|
|
1187
|
-
captureStart = captureEnd = state.position;
|
|
1188
|
-
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
1189
|
-
if (ch === 39) {
|
|
1190
|
-
captureSegment(state, captureStart, state.position, true);
|
|
1191
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1192
|
-
if (ch === 39) {
|
|
1193
|
-
captureStart = state.position;
|
|
1194
|
-
state.position++;
|
|
1195
|
-
captureEnd = state.position;
|
|
1196
|
-
} else {
|
|
1197
|
-
return true;
|
|
1198
|
-
}
|
|
1199
|
-
} else if (is_EOL(ch)) {
|
|
1200
|
-
captureSegment(state, captureStart, captureEnd, true);
|
|
1201
|
-
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
1202
|
-
captureStart = captureEnd = state.position;
|
|
1203
|
-
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1204
|
-
throwError(state, "unexpected end of the document within a single quoted scalar");
|
|
1205
|
-
} else {
|
|
1206
|
-
state.position++;
|
|
1207
|
-
captureEnd = state.position;
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
throwError(state, "unexpected end of the stream within a single quoted scalar");
|
|
1211
|
-
}
|
|
1212
|
-
function readDoubleQuotedScalar(state, nodeIndent) {
|
|
1213
|
-
var captureStart, captureEnd, hexLength, hexResult, tmp, ch;
|
|
1214
|
-
ch = state.input.charCodeAt(state.position);
|
|
1215
|
-
if (ch !== 34) {
|
|
1216
|
-
return false;
|
|
1217
|
-
}
|
|
1218
|
-
state.kind = "scalar";
|
|
1219
|
-
state.result = "";
|
|
1220
|
-
state.position++;
|
|
1221
|
-
captureStart = captureEnd = state.position;
|
|
1222
|
-
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
1223
|
-
if (ch === 34) {
|
|
1224
|
-
captureSegment(state, captureStart, state.position, true);
|
|
1225
|
-
state.position++;
|
|
1226
|
-
return true;
|
|
1227
|
-
} else if (ch === 92) {
|
|
1228
|
-
captureSegment(state, captureStart, state.position, true);
|
|
1229
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1230
|
-
if (is_EOL(ch)) {
|
|
1231
|
-
skipSeparationSpace(state, false, nodeIndent);
|
|
1232
|
-
} else if (ch < 256 && simpleEscapeCheck[ch]) {
|
|
1233
|
-
state.result += simpleEscapeMap[ch];
|
|
1234
|
-
state.position++;
|
|
1235
|
-
} else if ((tmp = escapedHexLen(ch)) > 0) {
|
|
1236
|
-
hexLength = tmp;
|
|
1237
|
-
hexResult = 0;
|
|
1238
|
-
for (; hexLength > 0; hexLength--) {
|
|
1239
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1240
|
-
if ((tmp = fromHexCode(ch)) >= 0) {
|
|
1241
|
-
hexResult = (hexResult << 4) + tmp;
|
|
1242
|
-
} else {
|
|
1243
|
-
throwError(state, "expected hexadecimal character");
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
state.result += charFromCodepoint(hexResult);
|
|
1247
|
-
state.position++;
|
|
1248
|
-
} else {
|
|
1249
|
-
throwError(state, "unknown escape sequence");
|
|
1250
|
-
}
|
|
1251
|
-
captureStart = captureEnd = state.position;
|
|
1252
|
-
} else if (is_EOL(ch)) {
|
|
1253
|
-
captureSegment(state, captureStart, captureEnd, true);
|
|
1254
|
-
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
1255
|
-
captureStart = captureEnd = state.position;
|
|
1256
|
-
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1257
|
-
throwError(state, "unexpected end of the document within a double quoted scalar");
|
|
1258
|
-
} else {
|
|
1259
|
-
state.position++;
|
|
1260
|
-
captureEnd = state.position;
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
throwError(state, "unexpected end of the stream within a double quoted scalar");
|
|
1264
|
-
}
|
|
1265
|
-
function readFlowCollection(state, nodeIndent) {
|
|
1266
|
-
var readNext = true, _line, _lineStart, _pos, _tag = state.tag, _result, _anchor = state.anchor, following, terminator, isPair, isExplicitPair, isMapping, overridableKeys = /* @__PURE__ */ Object.create(null), keyNode, keyTag, valueNode, ch;
|
|
1267
|
-
ch = state.input.charCodeAt(state.position);
|
|
1268
|
-
if (ch === 91) {
|
|
1269
|
-
terminator = 93;
|
|
1270
|
-
isMapping = false;
|
|
1271
|
-
_result = [];
|
|
1272
|
-
} else if (ch === 123) {
|
|
1273
|
-
terminator = 125;
|
|
1274
|
-
isMapping = true;
|
|
1275
|
-
_result = {};
|
|
1276
|
-
} else {
|
|
1277
|
-
return false;
|
|
1278
|
-
}
|
|
1279
|
-
if (state.anchor !== null) {
|
|
1280
|
-
state.anchorMap[state.anchor] = _result;
|
|
1281
|
-
}
|
|
1282
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1283
|
-
while (ch !== 0) {
|
|
1284
|
-
skipSeparationSpace(state, true, nodeIndent);
|
|
1285
|
-
ch = state.input.charCodeAt(state.position);
|
|
1286
|
-
if (ch === terminator) {
|
|
1287
|
-
state.position++;
|
|
1288
|
-
state.tag = _tag;
|
|
1289
|
-
state.anchor = _anchor;
|
|
1290
|
-
state.kind = isMapping ? "mapping" : "sequence";
|
|
1291
|
-
state.result = _result;
|
|
1292
|
-
return true;
|
|
1293
|
-
} else if (!readNext) {
|
|
1294
|
-
throwError(state, "missed comma between flow collection entries");
|
|
1295
|
-
} else if (ch === 44) {
|
|
1296
|
-
throwError(state, "expected the node content, but found ','");
|
|
1297
|
-
}
|
|
1298
|
-
keyTag = keyNode = valueNode = null;
|
|
1299
|
-
isPair = isExplicitPair = false;
|
|
1300
|
-
if (ch === 63) {
|
|
1301
|
-
following = state.input.charCodeAt(state.position + 1);
|
|
1302
|
-
if (is_WS_OR_EOL(following)) {
|
|
1303
|
-
isPair = isExplicitPair = true;
|
|
1304
|
-
state.position++;
|
|
1305
|
-
skipSeparationSpace(state, true, nodeIndent);
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
_line = state.line;
|
|
1309
|
-
_lineStart = state.lineStart;
|
|
1310
|
-
_pos = state.position;
|
|
1311
|
-
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
1312
|
-
keyTag = state.tag;
|
|
1313
|
-
keyNode = state.result;
|
|
1314
|
-
skipSeparationSpace(state, true, nodeIndent);
|
|
1315
|
-
ch = state.input.charCodeAt(state.position);
|
|
1316
|
-
if ((isExplicitPair || state.line === _line) && ch === 58) {
|
|
1317
|
-
isPair = true;
|
|
1318
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1319
|
-
skipSeparationSpace(state, true, nodeIndent);
|
|
1320
|
-
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
1321
|
-
valueNode = state.result;
|
|
1322
|
-
}
|
|
1323
|
-
if (isMapping) {
|
|
1324
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos);
|
|
1325
|
-
} else if (isPair) {
|
|
1326
|
-
_result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos));
|
|
1327
|
-
} else {
|
|
1328
|
-
_result.push(keyNode);
|
|
1329
|
-
}
|
|
1330
|
-
skipSeparationSpace(state, true, nodeIndent);
|
|
1331
|
-
ch = state.input.charCodeAt(state.position);
|
|
1332
|
-
if (ch === 44) {
|
|
1333
|
-
readNext = true;
|
|
1334
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1335
|
-
} else {
|
|
1336
|
-
readNext = false;
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
throwError(state, "unexpected end of the stream within a flow collection");
|
|
1340
|
-
}
|
|
1341
|
-
function readBlockScalar(state, nodeIndent) {
|
|
1342
|
-
var captureStart, folding, chomping = CHOMPING_CLIP, didReadContent = false, detectedIndent = false, textIndent = nodeIndent, emptyLines = 0, atMoreIndented = false, tmp, ch;
|
|
1343
|
-
ch = state.input.charCodeAt(state.position);
|
|
1344
|
-
if (ch === 124) {
|
|
1345
|
-
folding = false;
|
|
1346
|
-
} else if (ch === 62) {
|
|
1347
|
-
folding = true;
|
|
1348
|
-
} else {
|
|
1349
|
-
return false;
|
|
1350
|
-
}
|
|
1351
|
-
state.kind = "scalar";
|
|
1352
|
-
state.result = "";
|
|
1353
|
-
while (ch !== 0) {
|
|
1354
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1355
|
-
if (ch === 43 || ch === 45) {
|
|
1356
|
-
if (CHOMPING_CLIP === chomping) {
|
|
1357
|
-
chomping = ch === 43 ? CHOMPING_KEEP : CHOMPING_STRIP;
|
|
1358
|
-
} else {
|
|
1359
|
-
throwError(state, "repeat of a chomping mode identifier");
|
|
1360
|
-
}
|
|
1361
|
-
} else if ((tmp = fromDecimalCode(ch)) >= 0) {
|
|
1362
|
-
if (tmp === 0) {
|
|
1363
|
-
throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
|
|
1364
|
-
} else if (!detectedIndent) {
|
|
1365
|
-
textIndent = nodeIndent + tmp - 1;
|
|
1366
|
-
detectedIndent = true;
|
|
1367
|
-
} else {
|
|
1368
|
-
throwError(state, "repeat of an indentation width identifier");
|
|
1369
|
-
}
|
|
1370
|
-
} else {
|
|
1371
|
-
break;
|
|
1372
|
-
}
|
|
1373
|
-
}
|
|
1374
|
-
if (is_WHITE_SPACE(ch)) {
|
|
1375
|
-
do {
|
|
1376
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1377
|
-
} while (is_WHITE_SPACE(ch));
|
|
1378
|
-
if (ch === 35) {
|
|
1379
|
-
do {
|
|
1380
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1381
|
-
} while (!is_EOL(ch) && ch !== 0);
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
while (ch !== 0) {
|
|
1385
|
-
readLineBreak(state);
|
|
1386
|
-
state.lineIndent = 0;
|
|
1387
|
-
ch = state.input.charCodeAt(state.position);
|
|
1388
|
-
while ((!detectedIndent || state.lineIndent < textIndent) && ch === 32) {
|
|
1389
|
-
state.lineIndent++;
|
|
1390
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1391
|
-
}
|
|
1392
|
-
if (!detectedIndent && state.lineIndent > textIndent) {
|
|
1393
|
-
textIndent = state.lineIndent;
|
|
1394
|
-
}
|
|
1395
|
-
if (is_EOL(ch)) {
|
|
1396
|
-
emptyLines++;
|
|
1397
|
-
continue;
|
|
1398
|
-
}
|
|
1399
|
-
if (state.lineIndent < textIndent) {
|
|
1400
|
-
if (chomping === CHOMPING_KEEP) {
|
|
1401
|
-
state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
|
|
1402
|
-
} else if (chomping === CHOMPING_CLIP) {
|
|
1403
|
-
if (didReadContent) {
|
|
1404
|
-
state.result += "\n";
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
break;
|
|
1408
|
-
}
|
|
1409
|
-
if (folding) {
|
|
1410
|
-
if (is_WHITE_SPACE(ch)) {
|
|
1411
|
-
atMoreIndented = true;
|
|
1412
|
-
state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
|
|
1413
|
-
} else if (atMoreIndented) {
|
|
1414
|
-
atMoreIndented = false;
|
|
1415
|
-
state.result += common.repeat("\n", emptyLines + 1);
|
|
1416
|
-
} else if (emptyLines === 0) {
|
|
1417
|
-
if (didReadContent) {
|
|
1418
|
-
state.result += " ";
|
|
1419
|
-
}
|
|
1420
|
-
} else {
|
|
1421
|
-
state.result += common.repeat("\n", emptyLines);
|
|
1422
|
-
}
|
|
1423
|
-
} else {
|
|
1424
|
-
state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
|
|
1425
|
-
}
|
|
1426
|
-
didReadContent = true;
|
|
1427
|
-
detectedIndent = true;
|
|
1428
|
-
emptyLines = 0;
|
|
1429
|
-
captureStart = state.position;
|
|
1430
|
-
while (!is_EOL(ch) && ch !== 0) {
|
|
1431
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1432
|
-
}
|
|
1433
|
-
captureSegment(state, captureStart, state.position, false);
|
|
1434
|
-
}
|
|
1435
|
-
return true;
|
|
1436
|
-
}
|
|
1437
|
-
function readBlockSequence(state, nodeIndent) {
|
|
1438
|
-
var _line, _tag = state.tag, _anchor = state.anchor, _result = [], following, detected = false, ch;
|
|
1439
|
-
if (state.firstTabInLine !== -1) return false;
|
|
1440
|
-
if (state.anchor !== null) {
|
|
1441
|
-
state.anchorMap[state.anchor] = _result;
|
|
1442
|
-
}
|
|
1443
|
-
ch = state.input.charCodeAt(state.position);
|
|
1444
|
-
while (ch !== 0) {
|
|
1445
|
-
if (state.firstTabInLine !== -1) {
|
|
1446
|
-
state.position = state.firstTabInLine;
|
|
1447
|
-
throwError(state, "tab characters must not be used in indentation");
|
|
1448
|
-
}
|
|
1449
|
-
if (ch !== 45) {
|
|
1450
|
-
break;
|
|
1451
|
-
}
|
|
1452
|
-
following = state.input.charCodeAt(state.position + 1);
|
|
1453
|
-
if (!is_WS_OR_EOL(following)) {
|
|
1454
|
-
break;
|
|
1455
|
-
}
|
|
1456
|
-
detected = true;
|
|
1457
|
-
state.position++;
|
|
1458
|
-
if (skipSeparationSpace(state, true, -1)) {
|
|
1459
|
-
if (state.lineIndent <= nodeIndent) {
|
|
1460
|
-
_result.push(null);
|
|
1461
|
-
ch = state.input.charCodeAt(state.position);
|
|
1462
|
-
continue;
|
|
1463
|
-
}
|
|
1464
|
-
}
|
|
1465
|
-
_line = state.line;
|
|
1466
|
-
composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
|
|
1467
|
-
_result.push(state.result);
|
|
1468
|
-
skipSeparationSpace(state, true, -1);
|
|
1469
|
-
ch = state.input.charCodeAt(state.position);
|
|
1470
|
-
if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
|
|
1471
|
-
throwError(state, "bad indentation of a sequence entry");
|
|
1472
|
-
} else if (state.lineIndent < nodeIndent) {
|
|
1473
|
-
break;
|
|
1474
|
-
}
|
|
1475
|
-
}
|
|
1476
|
-
if (detected) {
|
|
1477
|
-
state.tag = _tag;
|
|
1478
|
-
state.anchor = _anchor;
|
|
1479
|
-
state.kind = "sequence";
|
|
1480
|
-
state.result = _result;
|
|
1481
|
-
return true;
|
|
1482
|
-
}
|
|
1483
|
-
return false;
|
|
1484
|
-
}
|
|
1485
|
-
function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
1486
|
-
var following, allowCompact, _line, _keyLine, _keyLineStart, _keyPos, _tag = state.tag, _anchor = state.anchor, _result = {}, overridableKeys = /* @__PURE__ */ Object.create(null), keyTag = null, keyNode = null, valueNode = null, atExplicitKey = false, detected = false, ch;
|
|
1487
|
-
if (state.firstTabInLine !== -1) return false;
|
|
1488
|
-
if (state.anchor !== null) {
|
|
1489
|
-
state.anchorMap[state.anchor] = _result;
|
|
1490
|
-
}
|
|
1491
|
-
ch = state.input.charCodeAt(state.position);
|
|
1492
|
-
while (ch !== 0) {
|
|
1493
|
-
if (!atExplicitKey && state.firstTabInLine !== -1) {
|
|
1494
|
-
state.position = state.firstTabInLine;
|
|
1495
|
-
throwError(state, "tab characters must not be used in indentation");
|
|
1496
|
-
}
|
|
1497
|
-
following = state.input.charCodeAt(state.position + 1);
|
|
1498
|
-
_line = state.line;
|
|
1499
|
-
if ((ch === 63 || ch === 58) && is_WS_OR_EOL(following)) {
|
|
1500
|
-
if (ch === 63) {
|
|
1501
|
-
if (atExplicitKey) {
|
|
1502
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
1503
|
-
keyTag = keyNode = valueNode = null;
|
|
1504
|
-
}
|
|
1505
|
-
detected = true;
|
|
1506
|
-
atExplicitKey = true;
|
|
1507
|
-
allowCompact = true;
|
|
1508
|
-
} else if (atExplicitKey) {
|
|
1509
|
-
atExplicitKey = false;
|
|
1510
|
-
allowCompact = true;
|
|
1511
|
-
} else {
|
|
1512
|
-
throwError(state, "incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line");
|
|
1513
|
-
}
|
|
1514
|
-
state.position += 1;
|
|
1515
|
-
ch = following;
|
|
1516
|
-
} else {
|
|
1517
|
-
_keyLine = state.line;
|
|
1518
|
-
_keyLineStart = state.lineStart;
|
|
1519
|
-
_keyPos = state.position;
|
|
1520
|
-
if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
|
|
1521
|
-
break;
|
|
1522
|
-
}
|
|
1523
|
-
if (state.line === _line) {
|
|
1524
|
-
ch = state.input.charCodeAt(state.position);
|
|
1525
|
-
while (is_WHITE_SPACE(ch)) {
|
|
1526
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1527
|
-
}
|
|
1528
|
-
if (ch === 58) {
|
|
1529
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1530
|
-
if (!is_WS_OR_EOL(ch)) {
|
|
1531
|
-
throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
|
|
1532
|
-
}
|
|
1533
|
-
if (atExplicitKey) {
|
|
1534
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
1535
|
-
keyTag = keyNode = valueNode = null;
|
|
1536
|
-
}
|
|
1537
|
-
detected = true;
|
|
1538
|
-
atExplicitKey = false;
|
|
1539
|
-
allowCompact = false;
|
|
1540
|
-
keyTag = state.tag;
|
|
1541
|
-
keyNode = state.result;
|
|
1542
|
-
} else if (detected) {
|
|
1543
|
-
throwError(state, "can not read an implicit mapping pair; a colon is missed");
|
|
1544
|
-
} else {
|
|
1545
|
-
state.tag = _tag;
|
|
1546
|
-
state.anchor = _anchor;
|
|
1547
|
-
return true;
|
|
1548
|
-
}
|
|
1549
|
-
} else if (detected) {
|
|
1550
|
-
throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
|
|
1551
|
-
} else {
|
|
1552
|
-
state.tag = _tag;
|
|
1553
|
-
state.anchor = _anchor;
|
|
1554
|
-
return true;
|
|
1555
|
-
}
|
|
1556
|
-
}
|
|
1557
|
-
if (state.line === _line || state.lineIndent > nodeIndent) {
|
|
1558
|
-
if (atExplicitKey) {
|
|
1559
|
-
_keyLine = state.line;
|
|
1560
|
-
_keyLineStart = state.lineStart;
|
|
1561
|
-
_keyPos = state.position;
|
|
1562
|
-
}
|
|
1563
|
-
if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
|
|
1564
|
-
if (atExplicitKey) {
|
|
1565
|
-
keyNode = state.result;
|
|
1566
|
-
} else {
|
|
1567
|
-
valueNode = state.result;
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1570
|
-
if (!atExplicitKey) {
|
|
1571
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineStart, _keyPos);
|
|
1572
|
-
keyTag = keyNode = valueNode = null;
|
|
1573
|
-
}
|
|
1574
|
-
skipSeparationSpace(state, true, -1);
|
|
1575
|
-
ch = state.input.charCodeAt(state.position);
|
|
1576
|
-
}
|
|
1577
|
-
if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
|
|
1578
|
-
throwError(state, "bad indentation of a mapping entry");
|
|
1579
|
-
} else if (state.lineIndent < nodeIndent) {
|
|
1580
|
-
break;
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
if (atExplicitKey) {
|
|
1584
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
1585
|
-
}
|
|
1586
|
-
if (detected) {
|
|
1587
|
-
state.tag = _tag;
|
|
1588
|
-
state.anchor = _anchor;
|
|
1589
|
-
state.kind = "mapping";
|
|
1590
|
-
state.result = _result;
|
|
1591
|
-
}
|
|
1592
|
-
return detected;
|
|
1593
|
-
}
|
|
1594
|
-
function readTagProperty(state) {
|
|
1595
|
-
var _position, isVerbatim = false, isNamed = false, tagHandle, tagName, ch;
|
|
1596
|
-
ch = state.input.charCodeAt(state.position);
|
|
1597
|
-
if (ch !== 33) return false;
|
|
1598
|
-
if (state.tag !== null) {
|
|
1599
|
-
throwError(state, "duplication of a tag property");
|
|
1600
|
-
}
|
|
1601
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1602
|
-
if (ch === 60) {
|
|
1603
|
-
isVerbatim = true;
|
|
1604
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1605
|
-
} else if (ch === 33) {
|
|
1606
|
-
isNamed = true;
|
|
1607
|
-
tagHandle = "!!";
|
|
1608
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1609
|
-
} else {
|
|
1610
|
-
tagHandle = "!";
|
|
1611
|
-
}
|
|
1612
|
-
_position = state.position;
|
|
1613
|
-
if (isVerbatim) {
|
|
1614
|
-
do {
|
|
1615
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1616
|
-
} while (ch !== 0 && ch !== 62);
|
|
1617
|
-
if (state.position < state.length) {
|
|
1618
|
-
tagName = state.input.slice(_position, state.position);
|
|
1619
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1620
|
-
} else {
|
|
1621
|
-
throwError(state, "unexpected end of the stream within a verbatim tag");
|
|
1622
|
-
}
|
|
1623
|
-
} else {
|
|
1624
|
-
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
1625
|
-
if (ch === 33) {
|
|
1626
|
-
if (!isNamed) {
|
|
1627
|
-
tagHandle = state.input.slice(_position - 1, state.position + 1);
|
|
1628
|
-
if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
|
1629
|
-
throwError(state, "named tag handle cannot contain such characters");
|
|
1630
|
-
}
|
|
1631
|
-
isNamed = true;
|
|
1632
|
-
_position = state.position + 1;
|
|
1633
|
-
} else {
|
|
1634
|
-
throwError(state, "tag suffix cannot contain exclamation marks");
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1638
|
-
}
|
|
1639
|
-
tagName = state.input.slice(_position, state.position);
|
|
1640
|
-
if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
|
1641
|
-
throwError(state, "tag suffix cannot contain flow indicator characters");
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
if (tagName && !PATTERN_TAG_URI.test(tagName)) {
|
|
1645
|
-
throwError(state, "tag name cannot contain such characters: " + tagName);
|
|
1646
|
-
}
|
|
1647
|
-
try {
|
|
1648
|
-
tagName = decodeURIComponent(tagName);
|
|
1649
|
-
} catch (err) {
|
|
1650
|
-
throwError(state, "tag name is malformed: " + tagName);
|
|
1651
|
-
}
|
|
1652
|
-
if (isVerbatim) {
|
|
1653
|
-
state.tag = tagName;
|
|
1654
|
-
} else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) {
|
|
1655
|
-
state.tag = state.tagMap[tagHandle] + tagName;
|
|
1656
|
-
} else if (tagHandle === "!") {
|
|
1657
|
-
state.tag = "!" + tagName;
|
|
1658
|
-
} else if (tagHandle === "!!") {
|
|
1659
|
-
state.tag = "tag:yaml.org,2002:" + tagName;
|
|
1660
|
-
} else {
|
|
1661
|
-
throwError(state, 'undeclared tag handle "' + tagHandle + '"');
|
|
1662
|
-
}
|
|
1663
|
-
return true;
|
|
1664
|
-
}
|
|
1665
|
-
function readAnchorProperty(state) {
|
|
1666
|
-
var _position, ch;
|
|
1667
|
-
ch = state.input.charCodeAt(state.position);
|
|
1668
|
-
if (ch !== 38) return false;
|
|
1669
|
-
if (state.anchor !== null) {
|
|
1670
|
-
throwError(state, "duplication of an anchor property");
|
|
1671
|
-
}
|
|
1672
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1673
|
-
_position = state.position;
|
|
1674
|
-
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
|
1675
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1676
|
-
}
|
|
1677
|
-
if (state.position === _position) {
|
|
1678
|
-
throwError(state, "name of an anchor node must contain at least one character");
|
|
1679
|
-
}
|
|
1680
|
-
state.anchor = state.input.slice(_position, state.position);
|
|
1681
|
-
return true;
|
|
1682
|
-
}
|
|
1683
|
-
function readAlias(state) {
|
|
1684
|
-
var _position, alias, ch;
|
|
1685
|
-
ch = state.input.charCodeAt(state.position);
|
|
1686
|
-
if (ch !== 42) return false;
|
|
1687
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1688
|
-
_position = state.position;
|
|
1689
|
-
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
|
1690
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1691
|
-
}
|
|
1692
|
-
if (state.position === _position) {
|
|
1693
|
-
throwError(state, "name of an alias node must contain at least one character");
|
|
1694
|
-
}
|
|
1695
|
-
alias = state.input.slice(_position, state.position);
|
|
1696
|
-
if (!_hasOwnProperty$1.call(state.anchorMap, alias)) {
|
|
1697
|
-
throwError(state, 'unidentified alias "' + alias + '"');
|
|
1698
|
-
}
|
|
1699
|
-
state.result = state.anchorMap[alias];
|
|
1700
|
-
skipSeparationSpace(state, true, -1);
|
|
1701
|
-
return true;
|
|
1702
|
-
}
|
|
1703
|
-
function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
|
|
1704
|
-
var allowBlockStyles, allowBlockScalars, allowBlockCollections, indentStatus = 1, atNewLine = false, hasContent = false, typeIndex, typeQuantity, typeList, type2, flowIndent, blockIndent;
|
|
1705
|
-
if (state.listener !== null) {
|
|
1706
|
-
state.listener("open", state);
|
|
1707
|
-
}
|
|
1708
|
-
state.tag = null;
|
|
1709
|
-
state.anchor = null;
|
|
1710
|
-
state.kind = null;
|
|
1711
|
-
state.result = null;
|
|
1712
|
-
allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext;
|
|
1713
|
-
if (allowToSeek) {
|
|
1714
|
-
if (skipSeparationSpace(state, true, -1)) {
|
|
1715
|
-
atNewLine = true;
|
|
1716
|
-
if (state.lineIndent > parentIndent) {
|
|
1717
|
-
indentStatus = 1;
|
|
1718
|
-
} else if (state.lineIndent === parentIndent) {
|
|
1719
|
-
indentStatus = 0;
|
|
1720
|
-
} else if (state.lineIndent < parentIndent) {
|
|
1721
|
-
indentStatus = -1;
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
|
-
}
|
|
1725
|
-
if (indentStatus === 1) {
|
|
1726
|
-
while (readTagProperty(state) || readAnchorProperty(state)) {
|
|
1727
|
-
if (skipSeparationSpace(state, true, -1)) {
|
|
1728
|
-
atNewLine = true;
|
|
1729
|
-
allowBlockCollections = allowBlockStyles;
|
|
1730
|
-
if (state.lineIndent > parentIndent) {
|
|
1731
|
-
indentStatus = 1;
|
|
1732
|
-
} else if (state.lineIndent === parentIndent) {
|
|
1733
|
-
indentStatus = 0;
|
|
1734
|
-
} else if (state.lineIndent < parentIndent) {
|
|
1735
|
-
indentStatus = -1;
|
|
1736
|
-
}
|
|
1737
|
-
} else {
|
|
1738
|
-
allowBlockCollections = false;
|
|
1739
|
-
}
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
|
-
if (allowBlockCollections) {
|
|
1743
|
-
allowBlockCollections = atNewLine || allowCompact;
|
|
1744
|
-
}
|
|
1745
|
-
if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
|
|
1746
|
-
if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
|
|
1747
|
-
flowIndent = parentIndent;
|
|
1748
|
-
} else {
|
|
1749
|
-
flowIndent = parentIndent + 1;
|
|
1750
|
-
}
|
|
1751
|
-
blockIndent = state.position - state.lineStart;
|
|
1752
|
-
if (indentStatus === 1) {
|
|
1753
|
-
if (allowBlockCollections && (readBlockSequence(state, blockIndent) || readBlockMapping(state, blockIndent, flowIndent)) || readFlowCollection(state, flowIndent)) {
|
|
1754
|
-
hasContent = true;
|
|
1755
|
-
} else {
|
|
1756
|
-
if (allowBlockScalars && readBlockScalar(state, flowIndent) || readSingleQuotedScalar(state, flowIndent) || readDoubleQuotedScalar(state, flowIndent)) {
|
|
1757
|
-
hasContent = true;
|
|
1758
|
-
} else if (readAlias(state)) {
|
|
1759
|
-
hasContent = true;
|
|
1760
|
-
if (state.tag !== null || state.anchor !== null) {
|
|
1761
|
-
throwError(state, "alias node should not have any properties");
|
|
1762
|
-
}
|
|
1763
|
-
} else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
|
|
1764
|
-
hasContent = true;
|
|
1765
|
-
if (state.tag === null) {
|
|
1766
|
-
state.tag = "?";
|
|
1767
|
-
}
|
|
1768
|
-
}
|
|
1769
|
-
if (state.anchor !== null) {
|
|
1770
|
-
state.anchorMap[state.anchor] = state.result;
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
} else if (indentStatus === 0) {
|
|
1774
|
-
hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
|
|
1775
|
-
}
|
|
1776
|
-
}
|
|
1777
|
-
if (state.tag === null) {
|
|
1778
|
-
if (state.anchor !== null) {
|
|
1779
|
-
state.anchorMap[state.anchor] = state.result;
|
|
1780
|
-
}
|
|
1781
|
-
} else if (state.tag === "?") {
|
|
1782
|
-
if (state.result !== null && state.kind !== "scalar") {
|
|
1783
|
-
throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
|
|
1784
|
-
}
|
|
1785
|
-
for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
|
|
1786
|
-
type2 = state.implicitTypes[typeIndex];
|
|
1787
|
-
if (type2.resolve(state.result)) {
|
|
1788
|
-
state.result = type2.construct(state.result);
|
|
1789
|
-
state.tag = type2.tag;
|
|
1790
|
-
if (state.anchor !== null) {
|
|
1791
|
-
state.anchorMap[state.anchor] = state.result;
|
|
1792
|
-
}
|
|
1793
|
-
break;
|
|
1794
|
-
}
|
|
1795
|
-
}
|
|
1796
|
-
} else if (state.tag !== "!") {
|
|
1797
|
-
if (_hasOwnProperty$1.call(state.typeMap[state.kind || "fallback"], state.tag)) {
|
|
1798
|
-
type2 = state.typeMap[state.kind || "fallback"][state.tag];
|
|
1799
|
-
} else {
|
|
1800
|
-
type2 = null;
|
|
1801
|
-
typeList = state.typeMap.multi[state.kind || "fallback"];
|
|
1802
|
-
for (typeIndex = 0, typeQuantity = typeList.length; typeIndex < typeQuantity; typeIndex += 1) {
|
|
1803
|
-
if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) {
|
|
1804
|
-
type2 = typeList[typeIndex];
|
|
1805
|
-
break;
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
}
|
|
1809
|
-
if (!type2) {
|
|
1810
|
-
throwError(state, "unknown tag !<" + state.tag + ">");
|
|
1811
|
-
}
|
|
1812
|
-
if (state.result !== null && type2.kind !== state.kind) {
|
|
1813
|
-
throwError(state, "unacceptable node kind for !<" + state.tag + '> tag; it should be "' + type2.kind + '", not "' + state.kind + '"');
|
|
1814
|
-
}
|
|
1815
|
-
if (!type2.resolve(state.result, state.tag)) {
|
|
1816
|
-
throwError(state, "cannot resolve a node with !<" + state.tag + "> explicit tag");
|
|
1817
|
-
} else {
|
|
1818
|
-
state.result = type2.construct(state.result, state.tag);
|
|
1819
|
-
if (state.anchor !== null) {
|
|
1820
|
-
state.anchorMap[state.anchor] = state.result;
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1823
|
-
}
|
|
1824
|
-
if (state.listener !== null) {
|
|
1825
|
-
state.listener("close", state);
|
|
1826
|
-
}
|
|
1827
|
-
return state.tag !== null || state.anchor !== null || hasContent;
|
|
1828
|
-
}
|
|
1829
|
-
function readDocument(state) {
|
|
1830
|
-
var documentStart = state.position, _position, directiveName, directiveArgs, hasDirectives = false, ch;
|
|
1831
|
-
state.version = null;
|
|
1832
|
-
state.checkLineBreaks = state.legacy;
|
|
1833
|
-
state.tagMap = /* @__PURE__ */ Object.create(null);
|
|
1834
|
-
state.anchorMap = /* @__PURE__ */ Object.create(null);
|
|
1835
|
-
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
1836
|
-
skipSeparationSpace(state, true, -1);
|
|
1837
|
-
ch = state.input.charCodeAt(state.position);
|
|
1838
|
-
if (state.lineIndent > 0 || ch !== 37) {
|
|
1839
|
-
break;
|
|
1840
|
-
}
|
|
1841
|
-
hasDirectives = true;
|
|
1842
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1843
|
-
_position = state.position;
|
|
1844
|
-
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
1845
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1846
|
-
}
|
|
1847
|
-
directiveName = state.input.slice(_position, state.position);
|
|
1848
|
-
directiveArgs = [];
|
|
1849
|
-
if (directiveName.length < 1) {
|
|
1850
|
-
throwError(state, "directive name must not be less than one character in length");
|
|
1851
|
-
}
|
|
1852
|
-
while (ch !== 0) {
|
|
1853
|
-
while (is_WHITE_SPACE(ch)) {
|
|
1854
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1855
|
-
}
|
|
1856
|
-
if (ch === 35) {
|
|
1857
|
-
do {
|
|
1858
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1859
|
-
} while (ch !== 0 && !is_EOL(ch));
|
|
1860
|
-
break;
|
|
1861
|
-
}
|
|
1862
|
-
if (is_EOL(ch)) break;
|
|
1863
|
-
_position = state.position;
|
|
1864
|
-
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
1865
|
-
ch = state.input.charCodeAt(++state.position);
|
|
1866
|
-
}
|
|
1867
|
-
directiveArgs.push(state.input.slice(_position, state.position));
|
|
1868
|
-
}
|
|
1869
|
-
if (ch !== 0) readLineBreak(state);
|
|
1870
|
-
if (_hasOwnProperty$1.call(directiveHandlers, directiveName)) {
|
|
1871
|
-
directiveHandlers[directiveName](state, directiveName, directiveArgs);
|
|
1872
|
-
} else {
|
|
1873
|
-
throwWarning(state, 'unknown document directive "' + directiveName + '"');
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
skipSeparationSpace(state, true, -1);
|
|
1877
|
-
if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45) {
|
|
1878
|
-
state.position += 3;
|
|
1879
|
-
skipSeparationSpace(state, true, -1);
|
|
1880
|
-
} else if (hasDirectives) {
|
|
1881
|
-
throwError(state, "directives end mark is expected");
|
|
1882
|
-
}
|
|
1883
|
-
composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
|
|
1884
|
-
skipSeparationSpace(state, true, -1);
|
|
1885
|
-
if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
|
|
1886
|
-
throwWarning(state, "non-ASCII line breaks are interpreted as content");
|
|
1887
|
-
}
|
|
1888
|
-
state.documents.push(state.result);
|
|
1889
|
-
if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1890
|
-
if (state.input.charCodeAt(state.position) === 46) {
|
|
1891
|
-
state.position += 3;
|
|
1892
|
-
skipSeparationSpace(state, true, -1);
|
|
1893
|
-
}
|
|
1894
|
-
return;
|
|
1895
|
-
}
|
|
1896
|
-
if (state.position < state.length - 1) {
|
|
1897
|
-
throwError(state, "end of the stream or a document separator is expected");
|
|
1898
|
-
} else {
|
|
1899
|
-
return;
|
|
1900
|
-
}
|
|
1901
|
-
}
|
|
1902
|
-
function loadDocuments(input, options) {
|
|
1903
|
-
input = String(input);
|
|
1904
|
-
options = options || {};
|
|
1905
|
-
if (input.length !== 0) {
|
|
1906
|
-
if (input.charCodeAt(input.length - 1) !== 10 && input.charCodeAt(input.length - 1) !== 13) {
|
|
1907
|
-
input += "\n";
|
|
1908
|
-
}
|
|
1909
|
-
if (input.charCodeAt(0) === 65279) {
|
|
1910
|
-
input = input.slice(1);
|
|
1911
|
-
}
|
|
1912
|
-
}
|
|
1913
|
-
var state = new State$1(input, options);
|
|
1914
|
-
var nullpos = input.indexOf("\0");
|
|
1915
|
-
if (nullpos !== -1) {
|
|
1916
|
-
state.position = nullpos;
|
|
1917
|
-
throwError(state, "null byte is not allowed in input");
|
|
1918
|
-
}
|
|
1919
|
-
state.input += "\0";
|
|
1920
|
-
while (state.input.charCodeAt(state.position) === 32) {
|
|
1921
|
-
state.lineIndent += 1;
|
|
1922
|
-
state.position += 1;
|
|
1923
|
-
}
|
|
1924
|
-
while (state.position < state.length - 1) {
|
|
1925
|
-
readDocument(state);
|
|
1926
|
-
}
|
|
1927
|
-
return state.documents;
|
|
1928
|
-
}
|
|
1929
|
-
function loadAll$1(input, iterator, options) {
|
|
1930
|
-
if (iterator !== null && typeof iterator === "object" && typeof options === "undefined") {
|
|
1931
|
-
options = iterator;
|
|
1932
|
-
iterator = null;
|
|
1933
|
-
}
|
|
1934
|
-
var documents = loadDocuments(input, options);
|
|
1935
|
-
if (typeof iterator !== "function") {
|
|
1936
|
-
return documents;
|
|
1937
|
-
}
|
|
1938
|
-
for (var index = 0, length = documents.length; index < length; index += 1) {
|
|
1939
|
-
iterator(documents[index]);
|
|
1940
|
-
}
|
|
1941
|
-
}
|
|
1942
|
-
function load$1(input, options) {
|
|
1943
|
-
var documents = loadDocuments(input, options);
|
|
1944
|
-
if (documents.length === 0) {
|
|
1945
|
-
return void 0;
|
|
1946
|
-
} else if (documents.length === 1) {
|
|
1947
|
-
return documents[0];
|
|
1948
|
-
}
|
|
1949
|
-
throw new exception("expected a single document in the stream, but found more");
|
|
1950
|
-
}
|
|
1951
|
-
var loadAll_1 = loadAll$1;
|
|
1952
|
-
var load_1 = load$1;
|
|
1953
|
-
var loader = {
|
|
1954
|
-
loadAll: loadAll_1,
|
|
1955
|
-
load: load_1
|
|
1956
|
-
};
|
|
1957
|
-
var _toString = Object.prototype.toString;
|
|
1958
|
-
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1959
|
-
var CHAR_BOM = 65279;
|
|
1960
|
-
var CHAR_TAB = 9;
|
|
1961
|
-
var CHAR_LINE_FEED = 10;
|
|
1962
|
-
var CHAR_CARRIAGE_RETURN = 13;
|
|
1963
|
-
var CHAR_SPACE = 32;
|
|
1964
|
-
var CHAR_EXCLAMATION = 33;
|
|
1965
|
-
var CHAR_DOUBLE_QUOTE = 34;
|
|
1966
|
-
var CHAR_SHARP = 35;
|
|
1967
|
-
var CHAR_PERCENT = 37;
|
|
1968
|
-
var CHAR_AMPERSAND = 38;
|
|
1969
|
-
var CHAR_SINGLE_QUOTE = 39;
|
|
1970
|
-
var CHAR_ASTERISK = 42;
|
|
1971
|
-
var CHAR_COMMA = 44;
|
|
1972
|
-
var CHAR_MINUS = 45;
|
|
1973
|
-
var CHAR_COLON = 58;
|
|
1974
|
-
var CHAR_EQUALS = 61;
|
|
1975
|
-
var CHAR_GREATER_THAN = 62;
|
|
1976
|
-
var CHAR_QUESTION = 63;
|
|
1977
|
-
var CHAR_COMMERCIAL_AT = 64;
|
|
1978
|
-
var CHAR_LEFT_SQUARE_BRACKET = 91;
|
|
1979
|
-
var CHAR_RIGHT_SQUARE_BRACKET = 93;
|
|
1980
|
-
var CHAR_GRAVE_ACCENT = 96;
|
|
1981
|
-
var CHAR_LEFT_CURLY_BRACKET = 123;
|
|
1982
|
-
var CHAR_VERTICAL_LINE = 124;
|
|
1983
|
-
var CHAR_RIGHT_CURLY_BRACKET = 125;
|
|
1984
|
-
var ESCAPE_SEQUENCES = {};
|
|
1985
|
-
ESCAPE_SEQUENCES[0] = "\\0";
|
|
1986
|
-
ESCAPE_SEQUENCES[7] = "\\a";
|
|
1987
|
-
ESCAPE_SEQUENCES[8] = "\\b";
|
|
1988
|
-
ESCAPE_SEQUENCES[9] = "\\t";
|
|
1989
|
-
ESCAPE_SEQUENCES[10] = "\\n";
|
|
1990
|
-
ESCAPE_SEQUENCES[11] = "\\v";
|
|
1991
|
-
ESCAPE_SEQUENCES[12] = "\\f";
|
|
1992
|
-
ESCAPE_SEQUENCES[13] = "\\r";
|
|
1993
|
-
ESCAPE_SEQUENCES[27] = "\\e";
|
|
1994
|
-
ESCAPE_SEQUENCES[34] = '\\"';
|
|
1995
|
-
ESCAPE_SEQUENCES[92] = "\\\\";
|
|
1996
|
-
ESCAPE_SEQUENCES[133] = "\\N";
|
|
1997
|
-
ESCAPE_SEQUENCES[160] = "\\_";
|
|
1998
|
-
ESCAPE_SEQUENCES[8232] = "\\L";
|
|
1999
|
-
ESCAPE_SEQUENCES[8233] = "\\P";
|
|
2000
|
-
var DEPRECATED_BOOLEANS_SYNTAX = [
|
|
2001
|
-
"y",
|
|
2002
|
-
"Y",
|
|
2003
|
-
"yes",
|
|
2004
|
-
"Yes",
|
|
2005
|
-
"YES",
|
|
2006
|
-
"on",
|
|
2007
|
-
"On",
|
|
2008
|
-
"ON",
|
|
2009
|
-
"n",
|
|
2010
|
-
"N",
|
|
2011
|
-
"no",
|
|
2012
|
-
"No",
|
|
2013
|
-
"NO",
|
|
2014
|
-
"off",
|
|
2015
|
-
"Off",
|
|
2016
|
-
"OFF"
|
|
2017
|
-
];
|
|
2018
|
-
var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;
|
|
2019
|
-
function compileStyleMap(schema2, map2) {
|
|
2020
|
-
var result, keys, index, length, tag, style, type2;
|
|
2021
|
-
if (map2 === null) return {};
|
|
2022
|
-
result = {};
|
|
2023
|
-
keys = Object.keys(map2);
|
|
2024
|
-
for (index = 0, length = keys.length; index < length; index += 1) {
|
|
2025
|
-
tag = keys[index];
|
|
2026
|
-
style = String(map2[tag]);
|
|
2027
|
-
if (tag.slice(0, 2) === "!!") {
|
|
2028
|
-
tag = "tag:yaml.org,2002:" + tag.slice(2);
|
|
2029
|
-
}
|
|
2030
|
-
type2 = schema2.compiledTypeMap["fallback"][tag];
|
|
2031
|
-
if (type2 && _hasOwnProperty.call(type2.styleAliases, style)) {
|
|
2032
|
-
style = type2.styleAliases[style];
|
|
2033
|
-
}
|
|
2034
|
-
result[tag] = style;
|
|
2035
|
-
}
|
|
2036
|
-
return result;
|
|
2037
|
-
}
|
|
2038
|
-
function encodeHex(character) {
|
|
2039
|
-
var string, handle, length;
|
|
2040
|
-
string = character.toString(16).toUpperCase();
|
|
2041
|
-
if (character <= 255) {
|
|
2042
|
-
handle = "x";
|
|
2043
|
-
length = 2;
|
|
2044
|
-
} else if (character <= 65535) {
|
|
2045
|
-
handle = "u";
|
|
2046
|
-
length = 4;
|
|
2047
|
-
} else if (character <= 4294967295) {
|
|
2048
|
-
handle = "U";
|
|
2049
|
-
length = 8;
|
|
2050
|
-
} else {
|
|
2051
|
-
throw new exception("code point within a string may not be greater than 0xFFFFFFFF");
|
|
2052
|
-
}
|
|
2053
|
-
return "\\" + handle + common.repeat("0", length - string.length) + string;
|
|
2054
|
-
}
|
|
2055
|
-
var QUOTING_TYPE_SINGLE = 1;
|
|
2056
|
-
var QUOTING_TYPE_DOUBLE = 2;
|
|
2057
|
-
function State(options) {
|
|
2058
|
-
this.schema = options["schema"] || _default;
|
|
2059
|
-
this.indent = Math.max(1, options["indent"] || 2);
|
|
2060
|
-
this.noArrayIndent = options["noArrayIndent"] || false;
|
|
2061
|
-
this.skipInvalid = options["skipInvalid"] || false;
|
|
2062
|
-
this.flowLevel = common.isNothing(options["flowLevel"]) ? -1 : options["flowLevel"];
|
|
2063
|
-
this.styleMap = compileStyleMap(this.schema, options["styles"] || null);
|
|
2064
|
-
this.sortKeys = options["sortKeys"] || false;
|
|
2065
|
-
this.lineWidth = options["lineWidth"] || 80;
|
|
2066
|
-
this.noRefs = options["noRefs"] || false;
|
|
2067
|
-
this.noCompatMode = options["noCompatMode"] || false;
|
|
2068
|
-
this.condenseFlow = options["condenseFlow"] || false;
|
|
2069
|
-
this.quotingType = options["quotingType"] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE;
|
|
2070
|
-
this.forceQuotes = options["forceQuotes"] || false;
|
|
2071
|
-
this.replacer = typeof options["replacer"] === "function" ? options["replacer"] : null;
|
|
2072
|
-
this.implicitTypes = this.schema.compiledImplicit;
|
|
2073
|
-
this.explicitTypes = this.schema.compiledExplicit;
|
|
2074
|
-
this.tag = null;
|
|
2075
|
-
this.result = "";
|
|
2076
|
-
this.duplicates = [];
|
|
2077
|
-
this.usedDuplicates = null;
|
|
2078
|
-
}
|
|
2079
|
-
function indentString(string, spaces) {
|
|
2080
|
-
var ind = common.repeat(" ", spaces), position = 0, next = -1, result = "", line, length = string.length;
|
|
2081
|
-
while (position < length) {
|
|
2082
|
-
next = string.indexOf("\n", position);
|
|
2083
|
-
if (next === -1) {
|
|
2084
|
-
line = string.slice(position);
|
|
2085
|
-
position = length;
|
|
2086
|
-
} else {
|
|
2087
|
-
line = string.slice(position, next + 1);
|
|
2088
|
-
position = next + 1;
|
|
2089
|
-
}
|
|
2090
|
-
if (line.length && line !== "\n") result += ind;
|
|
2091
|
-
result += line;
|
|
2092
|
-
}
|
|
2093
|
-
return result;
|
|
2094
|
-
}
|
|
2095
|
-
function generateNextLine(state, level) {
|
|
2096
|
-
return "\n" + common.repeat(" ", state.indent * level);
|
|
2097
|
-
}
|
|
2098
|
-
function testImplicitResolving(state, str2) {
|
|
2099
|
-
var index, length, type2;
|
|
2100
|
-
for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
|
|
2101
|
-
type2 = state.implicitTypes[index];
|
|
2102
|
-
if (type2.resolve(str2)) {
|
|
2103
|
-
return true;
|
|
2104
|
-
}
|
|
2105
|
-
}
|
|
2106
|
-
return false;
|
|
2107
|
-
}
|
|
2108
|
-
function isWhitespace(c) {
|
|
2109
|
-
return c === CHAR_SPACE || c === CHAR_TAB;
|
|
2110
|
-
}
|
|
2111
|
-
function isPrintable(c) {
|
|
2112
|
-
return 32 <= c && c <= 126 || 161 <= c && c <= 55295 && c !== 8232 && c !== 8233 || 57344 <= c && c <= 65533 && c !== CHAR_BOM || 65536 <= c && c <= 1114111;
|
|
2113
|
-
}
|
|
2114
|
-
function isNsCharOrWhitespace(c) {
|
|
2115
|
-
return isPrintable(c) && c !== CHAR_BOM && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED;
|
|
2116
|
-
}
|
|
2117
|
-
function isPlainSafe(c, prev, inblock) {
|
|
2118
|
-
var cIsNsCharOrWhitespace = isNsCharOrWhitespace(c);
|
|
2119
|
-
var cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c);
|
|
2120
|
-
return (
|
|
2121
|
-
// ns-plain-safe
|
|
2122
|
-
(inblock ? (
|
|
2123
|
-
// c = flow-in
|
|
2124
|
-
cIsNsCharOrWhitespace
|
|
2125
|
-
) : cIsNsCharOrWhitespace && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET) && c !== CHAR_SHARP && !(prev === CHAR_COLON && !cIsNsChar) || isNsCharOrWhitespace(prev) && !isWhitespace(prev) && c === CHAR_SHARP || prev === CHAR_COLON && cIsNsChar
|
|
2126
|
-
);
|
|
2127
|
-
}
|
|
2128
|
-
function isPlainSafeFirst(c) {
|
|
2129
|
-
return isPrintable(c) && c !== CHAR_BOM && !isWhitespace(c) && c !== CHAR_MINUS && c !== CHAR_QUESTION && c !== CHAR_COLON && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET && c !== CHAR_SHARP && c !== CHAR_AMPERSAND && c !== CHAR_ASTERISK && c !== CHAR_EXCLAMATION && c !== CHAR_VERTICAL_LINE && c !== CHAR_EQUALS && c !== CHAR_GREATER_THAN && c !== CHAR_SINGLE_QUOTE && c !== CHAR_DOUBLE_QUOTE && c !== CHAR_PERCENT && c !== CHAR_COMMERCIAL_AT && c !== CHAR_GRAVE_ACCENT;
|
|
2130
|
-
}
|
|
2131
|
-
function isPlainSafeLast(c) {
|
|
2132
|
-
return !isWhitespace(c) && c !== CHAR_COLON;
|
|
2133
|
-
}
|
|
2134
|
-
function codePointAt(string, pos) {
|
|
2135
|
-
var first = string.charCodeAt(pos), second;
|
|
2136
|
-
if (first >= 55296 && first <= 56319 && pos + 1 < string.length) {
|
|
2137
|
-
second = string.charCodeAt(pos + 1);
|
|
2138
|
-
if (second >= 56320 && second <= 57343) {
|
|
2139
|
-
return (first - 55296) * 1024 + second - 56320 + 65536;
|
|
2140
|
-
}
|
|
2141
|
-
}
|
|
2142
|
-
return first;
|
|
2143
|
-
}
|
|
2144
|
-
function needIndentIndicator(string) {
|
|
2145
|
-
var leadingSpaceRe = /^\n* /;
|
|
2146
|
-
return leadingSpaceRe.test(string);
|
|
2147
|
-
}
|
|
2148
|
-
var STYLE_PLAIN = 1;
|
|
2149
|
-
var STYLE_SINGLE = 2;
|
|
2150
|
-
var STYLE_LITERAL = 3;
|
|
2151
|
-
var STYLE_FOLDED = 4;
|
|
2152
|
-
var STYLE_DOUBLE = 5;
|
|
2153
|
-
function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType, quotingType, forceQuotes, inblock) {
|
|
2154
|
-
var i;
|
|
2155
|
-
var char = 0;
|
|
2156
|
-
var prevChar = null;
|
|
2157
|
-
var hasLineBreak = false;
|
|
2158
|
-
var hasFoldableLine = false;
|
|
2159
|
-
var shouldTrackWidth = lineWidth !== -1;
|
|
2160
|
-
var previousLineBreak = -1;
|
|
2161
|
-
var plain = isPlainSafeFirst(codePointAt(string, 0)) && isPlainSafeLast(codePointAt(string, string.length - 1));
|
|
2162
|
-
if (singleLineOnly || forceQuotes) {
|
|
2163
|
-
for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2164
|
-
char = codePointAt(string, i);
|
|
2165
|
-
if (!isPrintable(char)) {
|
|
2166
|
-
return STYLE_DOUBLE;
|
|
2167
|
-
}
|
|
2168
|
-
plain = plain && isPlainSafe(char, prevChar, inblock);
|
|
2169
|
-
prevChar = char;
|
|
2170
|
-
}
|
|
2171
|
-
} else {
|
|
2172
|
-
for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2173
|
-
char = codePointAt(string, i);
|
|
2174
|
-
if (char === CHAR_LINE_FEED) {
|
|
2175
|
-
hasLineBreak = true;
|
|
2176
|
-
if (shouldTrackWidth) {
|
|
2177
|
-
hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented.
|
|
2178
|
-
i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
|
|
2179
|
-
previousLineBreak = i;
|
|
2180
|
-
}
|
|
2181
|
-
} else if (!isPrintable(char)) {
|
|
2182
|
-
return STYLE_DOUBLE;
|
|
2183
|
-
}
|
|
2184
|
-
plain = plain && isPlainSafe(char, prevChar, inblock);
|
|
2185
|
-
prevChar = char;
|
|
2186
|
-
}
|
|
2187
|
-
hasFoldableLine = hasFoldableLine || shouldTrackWidth && (i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ");
|
|
2188
|
-
}
|
|
2189
|
-
if (!hasLineBreak && !hasFoldableLine) {
|
|
2190
|
-
if (plain && !forceQuotes && !testAmbiguousType(string)) {
|
|
2191
|
-
return STYLE_PLAIN;
|
|
2192
|
-
}
|
|
2193
|
-
return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
2194
|
-
}
|
|
2195
|
-
if (indentPerLevel > 9 && needIndentIndicator(string)) {
|
|
2196
|
-
return STYLE_DOUBLE;
|
|
2197
|
-
}
|
|
2198
|
-
if (!forceQuotes) {
|
|
2199
|
-
return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
|
|
2200
|
-
}
|
|
2201
|
-
return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
2202
|
-
}
|
|
2203
|
-
function writeScalar(state, string, level, iskey, inblock) {
|
|
2204
|
-
state.dump = (function() {
|
|
2205
|
-
if (string.length === 0) {
|
|
2206
|
-
return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''";
|
|
2207
|
-
}
|
|
2208
|
-
if (!state.noCompatMode) {
|
|
2209
|
-
if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) {
|
|
2210
|
-
return state.quotingType === QUOTING_TYPE_DOUBLE ? '"' + string + '"' : "'" + string + "'";
|
|
2211
|
-
}
|
|
2212
|
-
}
|
|
2213
|
-
var indent = state.indent * Math.max(1, level);
|
|
2214
|
-
var lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
|
|
2215
|
-
var singleLineOnly = iskey || state.flowLevel > -1 && level >= state.flowLevel;
|
|
2216
|
-
function testAmbiguity(string2) {
|
|
2217
|
-
return testImplicitResolving(state, string2);
|
|
2218
|
-
}
|
|
2219
|
-
switch (chooseScalarStyle(
|
|
2220
|
-
string,
|
|
2221
|
-
singleLineOnly,
|
|
2222
|
-
state.indent,
|
|
2223
|
-
lineWidth,
|
|
2224
|
-
testAmbiguity,
|
|
2225
|
-
state.quotingType,
|
|
2226
|
-
state.forceQuotes && !iskey,
|
|
2227
|
-
inblock
|
|
2228
|
-
)) {
|
|
2229
|
-
case STYLE_PLAIN:
|
|
2230
|
-
return string;
|
|
2231
|
-
case STYLE_SINGLE:
|
|
2232
|
-
return "'" + string.replace(/'/g, "''") + "'";
|
|
2233
|
-
case STYLE_LITERAL:
|
|
2234
|
-
return "|" + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
|
|
2235
|
-
case STYLE_FOLDED:
|
|
2236
|
-
return ">" + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
|
|
2237
|
-
case STYLE_DOUBLE:
|
|
2238
|
-
return '"' + escapeString(string) + '"';
|
|
2239
|
-
default:
|
|
2240
|
-
throw new exception("impossible error: invalid scalar style");
|
|
2241
|
-
}
|
|
2242
|
-
})();
|
|
2243
|
-
}
|
|
2244
|
-
function blockHeader(string, indentPerLevel) {
|
|
2245
|
-
var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
|
|
2246
|
-
var clip = string[string.length - 1] === "\n";
|
|
2247
|
-
var keep = clip && (string[string.length - 2] === "\n" || string === "\n");
|
|
2248
|
-
var chomp = keep ? "+" : clip ? "" : "-";
|
|
2249
|
-
return indentIndicator + chomp + "\n";
|
|
2250
|
-
}
|
|
2251
|
-
function dropEndingNewline(string) {
|
|
2252
|
-
return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
|
|
2253
|
-
}
|
|
2254
|
-
function foldString(string, width) {
|
|
2255
|
-
var lineRe = /(\n+)([^\n]*)/g;
|
|
2256
|
-
var result = (function() {
|
|
2257
|
-
var nextLF = string.indexOf("\n");
|
|
2258
|
-
nextLF = nextLF !== -1 ? nextLF : string.length;
|
|
2259
|
-
lineRe.lastIndex = nextLF;
|
|
2260
|
-
return foldLine(string.slice(0, nextLF), width);
|
|
2261
|
-
})();
|
|
2262
|
-
var prevMoreIndented = string[0] === "\n" || string[0] === " ";
|
|
2263
|
-
var moreIndented;
|
|
2264
|
-
var match;
|
|
2265
|
-
while (match = lineRe.exec(string)) {
|
|
2266
|
-
var prefix = match[1], line = match[2];
|
|
2267
|
-
moreIndented = line[0] === " ";
|
|
2268
|
-
result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
|
|
2269
|
-
prevMoreIndented = moreIndented;
|
|
2270
|
-
}
|
|
2271
|
-
return result;
|
|
2272
|
-
}
|
|
2273
|
-
function foldLine(line, width) {
|
|
2274
|
-
if (line === "" || line[0] === " ") return line;
|
|
2275
|
-
var breakRe = / [^ ]/g;
|
|
2276
|
-
var match;
|
|
2277
|
-
var start = 0, end, curr = 0, next = 0;
|
|
2278
|
-
var result = "";
|
|
2279
|
-
while (match = breakRe.exec(line)) {
|
|
2280
|
-
next = match.index;
|
|
2281
|
-
if (next - start > width) {
|
|
2282
|
-
end = curr > start ? curr : next;
|
|
2283
|
-
result += "\n" + line.slice(start, end);
|
|
2284
|
-
start = end + 1;
|
|
2285
|
-
}
|
|
2286
|
-
curr = next;
|
|
2287
|
-
}
|
|
2288
|
-
result += "\n";
|
|
2289
|
-
if (line.length - start > width && curr > start) {
|
|
2290
|
-
result += line.slice(start, curr) + "\n" + line.slice(curr + 1);
|
|
2291
|
-
} else {
|
|
2292
|
-
result += line.slice(start);
|
|
2293
|
-
}
|
|
2294
|
-
return result.slice(1);
|
|
2295
|
-
}
|
|
2296
|
-
function escapeString(string) {
|
|
2297
|
-
var result = "";
|
|
2298
|
-
var char = 0;
|
|
2299
|
-
var escapeSeq;
|
|
2300
|
-
for (var i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2301
|
-
char = codePointAt(string, i);
|
|
2302
|
-
escapeSeq = ESCAPE_SEQUENCES[char];
|
|
2303
|
-
if (!escapeSeq && isPrintable(char)) {
|
|
2304
|
-
result += string[i];
|
|
2305
|
-
if (char >= 65536) result += string[i + 1];
|
|
2306
|
-
} else {
|
|
2307
|
-
result += escapeSeq || encodeHex(char);
|
|
2308
|
-
}
|
|
2309
|
-
}
|
|
2310
|
-
return result;
|
|
2311
|
-
}
|
|
2312
|
-
function writeFlowSequence(state, level, object) {
|
|
2313
|
-
var _result = "", _tag = state.tag, index, length, value;
|
|
2314
|
-
for (index = 0, length = object.length; index < length; index += 1) {
|
|
2315
|
-
value = object[index];
|
|
2316
|
-
if (state.replacer) {
|
|
2317
|
-
value = state.replacer.call(object, String(index), value);
|
|
2318
|
-
}
|
|
2319
|
-
if (writeNode(state, level, value, false, false) || typeof value === "undefined" && writeNode(state, level, null, false, false)) {
|
|
2320
|
-
if (_result !== "") _result += "," + (!state.condenseFlow ? " " : "");
|
|
2321
|
-
_result += state.dump;
|
|
2322
|
-
}
|
|
2323
|
-
}
|
|
2324
|
-
state.tag = _tag;
|
|
2325
|
-
state.dump = "[" + _result + "]";
|
|
2326
|
-
}
|
|
2327
|
-
function writeBlockSequence(state, level, object, compact) {
|
|
2328
|
-
var _result = "", _tag = state.tag, index, length, value;
|
|
2329
|
-
for (index = 0, length = object.length; index < length; index += 1) {
|
|
2330
|
-
value = object[index];
|
|
2331
|
-
if (state.replacer) {
|
|
2332
|
-
value = state.replacer.call(object, String(index), value);
|
|
2333
|
-
}
|
|
2334
|
-
if (writeNode(state, level + 1, value, true, true, false, true) || typeof value === "undefined" && writeNode(state, level + 1, null, true, true, false, true)) {
|
|
2335
|
-
if (!compact || _result !== "") {
|
|
2336
|
-
_result += generateNextLine(state, level);
|
|
2337
|
-
}
|
|
2338
|
-
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2339
|
-
_result += "-";
|
|
2340
|
-
} else {
|
|
2341
|
-
_result += "- ";
|
|
2342
|
-
}
|
|
2343
|
-
_result += state.dump;
|
|
2344
|
-
}
|
|
2345
|
-
}
|
|
2346
|
-
state.tag = _tag;
|
|
2347
|
-
state.dump = _result || "[]";
|
|
2348
|
-
}
|
|
2349
|
-
function writeFlowMapping(state, level, object) {
|
|
2350
|
-
var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, pairBuffer;
|
|
2351
|
-
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
|
2352
|
-
pairBuffer = "";
|
|
2353
|
-
if (_result !== "") pairBuffer += ", ";
|
|
2354
|
-
if (state.condenseFlow) pairBuffer += '"';
|
|
2355
|
-
objectKey = objectKeyList[index];
|
|
2356
|
-
objectValue = object[objectKey];
|
|
2357
|
-
if (state.replacer) {
|
|
2358
|
-
objectValue = state.replacer.call(object, objectKey, objectValue);
|
|
2359
|
-
}
|
|
2360
|
-
if (!writeNode(state, level, objectKey, false, false)) {
|
|
2361
|
-
continue;
|
|
2362
|
-
}
|
|
2363
|
-
if (state.dump.length > 1024) pairBuffer += "? ";
|
|
2364
|
-
pairBuffer += state.dump + (state.condenseFlow ? '"' : "") + ":" + (state.condenseFlow ? "" : " ");
|
|
2365
|
-
if (!writeNode(state, level, objectValue, false, false)) {
|
|
2366
|
-
continue;
|
|
2367
|
-
}
|
|
2368
|
-
pairBuffer += state.dump;
|
|
2369
|
-
_result += pairBuffer;
|
|
2370
|
-
}
|
|
2371
|
-
state.tag = _tag;
|
|
2372
|
-
state.dump = "{" + _result + "}";
|
|
2373
|
-
}
|
|
2374
|
-
function writeBlockMapping(state, level, object, compact) {
|
|
2375
|
-
var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, explicitPair, pairBuffer;
|
|
2376
|
-
if (state.sortKeys === true) {
|
|
2377
|
-
objectKeyList.sort();
|
|
2378
|
-
} else if (typeof state.sortKeys === "function") {
|
|
2379
|
-
objectKeyList.sort(state.sortKeys);
|
|
2380
|
-
} else if (state.sortKeys) {
|
|
2381
|
-
throw new exception("sortKeys must be a boolean or a function");
|
|
2382
|
-
}
|
|
2383
|
-
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
|
2384
|
-
pairBuffer = "";
|
|
2385
|
-
if (!compact || _result !== "") {
|
|
2386
|
-
pairBuffer += generateNextLine(state, level);
|
|
2387
|
-
}
|
|
2388
|
-
objectKey = objectKeyList[index];
|
|
2389
|
-
objectValue = object[objectKey];
|
|
2390
|
-
if (state.replacer) {
|
|
2391
|
-
objectValue = state.replacer.call(object, objectKey, objectValue);
|
|
2392
|
-
}
|
|
2393
|
-
if (!writeNode(state, level + 1, objectKey, true, true, true)) {
|
|
2394
|
-
continue;
|
|
2395
|
-
}
|
|
2396
|
-
explicitPair = state.tag !== null && state.tag !== "?" || state.dump && state.dump.length > 1024;
|
|
2397
|
-
if (explicitPair) {
|
|
2398
|
-
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2399
|
-
pairBuffer += "?";
|
|
2400
|
-
} else {
|
|
2401
|
-
pairBuffer += "? ";
|
|
2402
|
-
}
|
|
2403
|
-
}
|
|
2404
|
-
pairBuffer += state.dump;
|
|
2405
|
-
if (explicitPair) {
|
|
2406
|
-
pairBuffer += generateNextLine(state, level);
|
|
2407
|
-
}
|
|
2408
|
-
if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
|
|
2409
|
-
continue;
|
|
2410
|
-
}
|
|
2411
|
-
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2412
|
-
pairBuffer += ":";
|
|
2413
|
-
} else {
|
|
2414
|
-
pairBuffer += ": ";
|
|
2415
|
-
}
|
|
2416
|
-
pairBuffer += state.dump;
|
|
2417
|
-
_result += pairBuffer;
|
|
2418
|
-
}
|
|
2419
|
-
state.tag = _tag;
|
|
2420
|
-
state.dump = _result || "{}";
|
|
2421
|
-
}
|
|
2422
|
-
function detectType(state, object, explicit) {
|
|
2423
|
-
var _result, typeList, index, length, type2, style;
|
|
2424
|
-
typeList = explicit ? state.explicitTypes : state.implicitTypes;
|
|
2425
|
-
for (index = 0, length = typeList.length; index < length; index += 1) {
|
|
2426
|
-
type2 = typeList[index];
|
|
2427
|
-
if ((type2.instanceOf || type2.predicate) && (!type2.instanceOf || typeof object === "object" && object instanceof type2.instanceOf) && (!type2.predicate || type2.predicate(object))) {
|
|
2428
|
-
if (explicit) {
|
|
2429
|
-
if (type2.multi && type2.representName) {
|
|
2430
|
-
state.tag = type2.representName(object);
|
|
2431
|
-
} else {
|
|
2432
|
-
state.tag = type2.tag;
|
|
2433
|
-
}
|
|
2434
|
-
} else {
|
|
2435
|
-
state.tag = "?";
|
|
2436
|
-
}
|
|
2437
|
-
if (type2.represent) {
|
|
2438
|
-
style = state.styleMap[type2.tag] || type2.defaultStyle;
|
|
2439
|
-
if (_toString.call(type2.represent) === "[object Function]") {
|
|
2440
|
-
_result = type2.represent(object, style);
|
|
2441
|
-
} else if (_hasOwnProperty.call(type2.represent, style)) {
|
|
2442
|
-
_result = type2.represent[style](object, style);
|
|
2443
|
-
} else {
|
|
2444
|
-
throw new exception("!<" + type2.tag + '> tag resolver accepts not "' + style + '" style');
|
|
2445
|
-
}
|
|
2446
|
-
state.dump = _result;
|
|
2447
|
-
}
|
|
2448
|
-
return true;
|
|
2449
|
-
}
|
|
2450
|
-
}
|
|
2451
|
-
return false;
|
|
2452
|
-
}
|
|
2453
|
-
function writeNode(state, level, object, block, compact, iskey, isblockseq) {
|
|
2454
|
-
state.tag = null;
|
|
2455
|
-
state.dump = object;
|
|
2456
|
-
if (!detectType(state, object, false)) {
|
|
2457
|
-
detectType(state, object, true);
|
|
2458
|
-
}
|
|
2459
|
-
var type2 = _toString.call(state.dump);
|
|
2460
|
-
var inblock = block;
|
|
2461
|
-
var tagStr;
|
|
2462
|
-
if (block) {
|
|
2463
|
-
block = state.flowLevel < 0 || state.flowLevel > level;
|
|
2464
|
-
}
|
|
2465
|
-
var objectOrArray = type2 === "[object Object]" || type2 === "[object Array]", duplicateIndex, duplicate;
|
|
2466
|
-
if (objectOrArray) {
|
|
2467
|
-
duplicateIndex = state.duplicates.indexOf(object);
|
|
2468
|
-
duplicate = duplicateIndex !== -1;
|
|
2469
|
-
}
|
|
2470
|
-
if (state.tag !== null && state.tag !== "?" || duplicate || state.indent !== 2 && level > 0) {
|
|
2471
|
-
compact = false;
|
|
2472
|
-
}
|
|
2473
|
-
if (duplicate && state.usedDuplicates[duplicateIndex]) {
|
|
2474
|
-
state.dump = "*ref_" + duplicateIndex;
|
|
2475
|
-
} else {
|
|
2476
|
-
if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
|
|
2477
|
-
state.usedDuplicates[duplicateIndex] = true;
|
|
2478
|
-
}
|
|
2479
|
-
if (type2 === "[object Object]") {
|
|
2480
|
-
if (block && Object.keys(state.dump).length !== 0) {
|
|
2481
|
-
writeBlockMapping(state, level, state.dump, compact);
|
|
2482
|
-
if (duplicate) {
|
|
2483
|
-
state.dump = "&ref_" + duplicateIndex + state.dump;
|
|
2484
|
-
}
|
|
2485
|
-
} else {
|
|
2486
|
-
writeFlowMapping(state, level, state.dump);
|
|
2487
|
-
if (duplicate) {
|
|
2488
|
-
state.dump = "&ref_" + duplicateIndex + " " + state.dump;
|
|
2489
|
-
}
|
|
2490
|
-
}
|
|
2491
|
-
} else if (type2 === "[object Array]") {
|
|
2492
|
-
if (block && state.dump.length !== 0) {
|
|
2493
|
-
if (state.noArrayIndent && !isblockseq && level > 0) {
|
|
2494
|
-
writeBlockSequence(state, level - 1, state.dump, compact);
|
|
2495
|
-
} else {
|
|
2496
|
-
writeBlockSequence(state, level, state.dump, compact);
|
|
2497
|
-
}
|
|
2498
|
-
if (duplicate) {
|
|
2499
|
-
state.dump = "&ref_" + duplicateIndex + state.dump;
|
|
2500
|
-
}
|
|
2501
|
-
} else {
|
|
2502
|
-
writeFlowSequence(state, level, state.dump);
|
|
2503
|
-
if (duplicate) {
|
|
2504
|
-
state.dump = "&ref_" + duplicateIndex + " " + state.dump;
|
|
2505
|
-
}
|
|
2506
|
-
}
|
|
2507
|
-
} else if (type2 === "[object String]") {
|
|
2508
|
-
if (state.tag !== "?") {
|
|
2509
|
-
writeScalar(state, state.dump, level, iskey, inblock);
|
|
2510
|
-
}
|
|
2511
|
-
} else if (type2 === "[object Undefined]") {
|
|
2512
|
-
return false;
|
|
2513
|
-
} else {
|
|
2514
|
-
if (state.skipInvalid) return false;
|
|
2515
|
-
throw new exception("unacceptable kind of an object to dump " + type2);
|
|
2516
|
-
}
|
|
2517
|
-
if (state.tag !== null && state.tag !== "?") {
|
|
2518
|
-
tagStr = encodeURI(
|
|
2519
|
-
state.tag[0] === "!" ? state.tag.slice(1) : state.tag
|
|
2520
|
-
).replace(/!/g, "%21");
|
|
2521
|
-
if (state.tag[0] === "!") {
|
|
2522
|
-
tagStr = "!" + tagStr;
|
|
2523
|
-
} else if (tagStr.slice(0, 18) === "tag:yaml.org,2002:") {
|
|
2524
|
-
tagStr = "!!" + tagStr.slice(18);
|
|
2525
|
-
} else {
|
|
2526
|
-
tagStr = "!<" + tagStr + ">";
|
|
2527
|
-
}
|
|
2528
|
-
state.dump = tagStr + " " + state.dump;
|
|
2529
|
-
}
|
|
2530
|
-
}
|
|
2531
|
-
return true;
|
|
2532
|
-
}
|
|
2533
|
-
function getDuplicateReferences(object, state) {
|
|
2534
|
-
var objects = [], duplicatesIndexes = [], index, length;
|
|
2535
|
-
inspectNode(object, objects, duplicatesIndexes);
|
|
2536
|
-
for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
|
|
2537
|
-
state.duplicates.push(objects[duplicatesIndexes[index]]);
|
|
2538
|
-
}
|
|
2539
|
-
state.usedDuplicates = new Array(length);
|
|
2540
|
-
}
|
|
2541
|
-
function inspectNode(object, objects, duplicatesIndexes) {
|
|
2542
|
-
var objectKeyList, index, length;
|
|
2543
|
-
if (object !== null && typeof object === "object") {
|
|
2544
|
-
index = objects.indexOf(object);
|
|
2545
|
-
if (index !== -1) {
|
|
2546
|
-
if (duplicatesIndexes.indexOf(index) === -1) {
|
|
2547
|
-
duplicatesIndexes.push(index);
|
|
2548
|
-
}
|
|
2549
|
-
} else {
|
|
2550
|
-
objects.push(object);
|
|
2551
|
-
if (Array.isArray(object)) {
|
|
2552
|
-
for (index = 0, length = object.length; index < length; index += 1) {
|
|
2553
|
-
inspectNode(object[index], objects, duplicatesIndexes);
|
|
2554
|
-
}
|
|
2555
|
-
} else {
|
|
2556
|
-
objectKeyList = Object.keys(object);
|
|
2557
|
-
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
|
2558
|
-
inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
|
|
2559
|
-
}
|
|
2560
|
-
}
|
|
2561
|
-
}
|
|
2562
|
-
}
|
|
2563
|
-
}
|
|
2564
|
-
function dump$1(input, options) {
|
|
2565
|
-
options = options || {};
|
|
2566
|
-
var state = new State(options);
|
|
2567
|
-
if (!state.noRefs) getDuplicateReferences(input, state);
|
|
2568
|
-
var value = input;
|
|
2569
|
-
if (state.replacer) {
|
|
2570
|
-
value = state.replacer.call({ "": value }, "", value);
|
|
2571
|
-
}
|
|
2572
|
-
if (writeNode(state, 0, value, true, true)) return state.dump + "\n";
|
|
2573
|
-
return "";
|
|
2574
|
-
}
|
|
2575
|
-
var dump_1 = dump$1;
|
|
2576
|
-
var dumper = {
|
|
2577
|
-
dump: dump_1
|
|
2578
|
-
};
|
|
2579
|
-
function renamed(from, to) {
|
|
2580
|
-
return function() {
|
|
2581
|
-
throw new Error("Function yaml." + from + " is removed in js-yaml 4. Use yaml." + to + " instead, which is now safe by default.");
|
|
2582
|
-
};
|
|
2583
|
-
}
|
|
2584
|
-
var load = loader.load;
|
|
2585
|
-
var loadAll = loader.loadAll;
|
|
2586
|
-
var dump = dumper.dump;
|
|
2587
|
-
var safeLoad = renamed("safeLoad", "load");
|
|
2588
|
-
var safeLoadAll = renamed("safeLoadAll", "loadAll");
|
|
2589
|
-
var safeDump = renamed("safeDump", "dump");
|
|
5
|
+
// src/catalog.ts
|
|
6
|
+
import { load as yamlLoad } from "js-yaml";
|
|
2590
7
|
|
|
2591
8
|
// src/generated/foundational-flows.ts
|
|
2592
9
|
var FOUNDATIONAL_FLOWS = {
|
|
@@ -3825,9 +1242,9 @@ async function gql(instanceUrl, token, query, variables) {
|
|
|
3825
1242
|
headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` },
|
|
3826
1243
|
body: JSON.stringify({ query, variables })
|
|
3827
1244
|
});
|
|
3828
|
-
const
|
|
3829
|
-
if (
|
|
3830
|
-
return
|
|
1245
|
+
const json = await res.json();
|
|
1246
|
+
if (json.errors?.length) throw new Error(json.errors[0].message);
|
|
1247
|
+
return json.data;
|
|
3831
1248
|
}
|
|
3832
1249
|
async function fetchFoundationalChatAgents(instanceUrl, token, projectId) {
|
|
3833
1250
|
const agents = [];
|
|
@@ -3881,7 +1298,7 @@ async function fetchCustomAgents(instanceUrl, token, projectId) {
|
|
|
3881
1298
|
versionId: item.latestVersion.id
|
|
3882
1299
|
});
|
|
3883
1300
|
const yamlStr = cfgData?.aiCatalogAgentFlowConfig;
|
|
3884
|
-
const parsed = yamlStr ?
|
|
1301
|
+
const parsed = yamlStr ? yamlLoad(yamlStr) : void 0;
|
|
3885
1302
|
agents.push({
|
|
3886
1303
|
identifier: item.id,
|
|
3887
1304
|
name: item.name,
|
|
@@ -4310,8 +1727,48 @@ query AiCatalogBuiltInTools {
|
|
|
4310
1727
|
nodes {
|
|
4311
1728
|
id
|
|
4312
1729
|
name
|
|
4313
|
-
title
|
|
1730
|
+
title
|
|
1731
|
+
description
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
}`;
|
|
1735
|
+
var CREATE_FLOW_MUTATION = `
|
|
1736
|
+
mutation AiCatalogFlowCreate($input: AiCatalogFlowCreateInput!) {
|
|
1737
|
+
aiCatalogFlowCreate(input: $input) {
|
|
1738
|
+
errors
|
|
1739
|
+
item {
|
|
1740
|
+
id
|
|
1741
|
+
name
|
|
1742
|
+
description
|
|
1743
|
+
itemType
|
|
1744
|
+
public
|
|
1745
|
+
project { id, nameWithNamespace, webUrl }
|
|
1746
|
+
latestVersion {
|
|
1747
|
+
id
|
|
1748
|
+
humanVersionName
|
|
1749
|
+
released
|
|
1750
|
+
... on AiCatalogFlowVersion { definition }
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
}`;
|
|
1755
|
+
var UPDATE_FLOW_MUTATION = `
|
|
1756
|
+
mutation AiCatalogFlowUpdate($input: AiCatalogFlowUpdateInput!) {
|
|
1757
|
+
aiCatalogFlowUpdate(input: $input) {
|
|
1758
|
+
errors
|
|
1759
|
+
item {
|
|
1760
|
+
id
|
|
1761
|
+
name
|
|
4314
1762
|
description
|
|
1763
|
+
itemType
|
|
1764
|
+
public
|
|
1765
|
+
project { id, nameWithNamespace, webUrl }
|
|
1766
|
+
latestVersion {
|
|
1767
|
+
id
|
|
1768
|
+
humanVersionName
|
|
1769
|
+
released
|
|
1770
|
+
... on AiCatalogFlowVersion { definition }
|
|
1771
|
+
}
|
|
4315
1772
|
}
|
|
4316
1773
|
}
|
|
4317
1774
|
}`;
|
|
@@ -4430,6 +1887,644 @@ async function listBuiltInTools(instanceUrl, token) {
|
|
|
4430
1887
|
const result = await gql(instanceUrl, token, LIST_BUILTIN_TOOLS_QUERY, {});
|
|
4431
1888
|
return result.aiCatalogBuiltInTools?.nodes ?? [];
|
|
4432
1889
|
}
|
|
1890
|
+
async function createFlow(instanceUrl, token, projectPath, params) {
|
|
1891
|
+
const projectGid = await resolveProjectGid(instanceUrl, token, projectPath);
|
|
1892
|
+
const input = {
|
|
1893
|
+
projectId: projectGid,
|
|
1894
|
+
name: params.name,
|
|
1895
|
+
description: params.description,
|
|
1896
|
+
public: params.public,
|
|
1897
|
+
definition: params.definition
|
|
1898
|
+
};
|
|
1899
|
+
if (params.release !== void 0) input.release = params.release;
|
|
1900
|
+
const result = await gql(instanceUrl, token, CREATE_FLOW_MUTATION, { input });
|
|
1901
|
+
if (result.aiCatalogFlowCreate.errors.length > 0) {
|
|
1902
|
+
throw new Error(`Failed to create flow: ${result.aiCatalogFlowCreate.errors.join(", ")}`);
|
|
1903
|
+
}
|
|
1904
|
+
return result.aiCatalogFlowCreate.item;
|
|
1905
|
+
}
|
|
1906
|
+
async function updateFlow(instanceUrl, token, itemId, params) {
|
|
1907
|
+
const gid = normalizeItemGid(itemId);
|
|
1908
|
+
const input = { id: gid };
|
|
1909
|
+
if (params.name !== void 0) input.name = params.name;
|
|
1910
|
+
if (params.description !== void 0) input.description = params.description;
|
|
1911
|
+
if (params.public !== void 0) input.public = params.public;
|
|
1912
|
+
if (params.definition !== void 0) input.definition = params.definition;
|
|
1913
|
+
if (params.release !== void 0) input.release = params.release;
|
|
1914
|
+
if (params.versionBump) input.versionBump = params.versionBump;
|
|
1915
|
+
const result = await gql(instanceUrl, token, UPDATE_FLOW_MUTATION, { input });
|
|
1916
|
+
if (result.aiCatalogFlowUpdate.errors.length > 0) {
|
|
1917
|
+
throw new Error(`Failed to update flow: ${result.aiCatalogFlowUpdate.errors.join(", ")}`);
|
|
1918
|
+
}
|
|
1919
|
+
return result.aiCatalogFlowUpdate.item;
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
// src/flow-validator.ts
|
|
1923
|
+
import Ajv from "ajv";
|
|
1924
|
+
import yaml from "js-yaml";
|
|
1925
|
+
|
|
1926
|
+
// vendor/schemas/flow_v2.json
|
|
1927
|
+
var flow_v2_default = {
|
|
1928
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
1929
|
+
title: "Flow Registry v1 Configuration Schema",
|
|
1930
|
+
description: "JSON Schema for validating Flow Registry v1 YAML configuration files",
|
|
1931
|
+
type: "object",
|
|
1932
|
+
required: [
|
|
1933
|
+
"version",
|
|
1934
|
+
"environment",
|
|
1935
|
+
"components",
|
|
1936
|
+
"routers",
|
|
1937
|
+
"flow",
|
|
1938
|
+
"yaml_definition"
|
|
1939
|
+
],
|
|
1940
|
+
additionalProperties: false,
|
|
1941
|
+
properties: {
|
|
1942
|
+
version: {
|
|
1943
|
+
type: "string",
|
|
1944
|
+
const: "v1",
|
|
1945
|
+
description: "Framework version - must be 'v1' for current stable version"
|
|
1946
|
+
},
|
|
1947
|
+
environment: {
|
|
1948
|
+
type: "string",
|
|
1949
|
+
enum: [
|
|
1950
|
+
"ambient"
|
|
1951
|
+
],
|
|
1952
|
+
description: "Flow environment declaring expected level of interaction between human and AI agent"
|
|
1953
|
+
},
|
|
1954
|
+
components: {
|
|
1955
|
+
type: "array",
|
|
1956
|
+
minItems: 1,
|
|
1957
|
+
description: "List of components that make up the flow",
|
|
1958
|
+
items: {
|
|
1959
|
+
oneOf: [
|
|
1960
|
+
{
|
|
1961
|
+
$ref: "#/definitions/AgentComponent"
|
|
1962
|
+
},
|
|
1963
|
+
{
|
|
1964
|
+
$ref: "#/definitions/DeterministicStepComponent"
|
|
1965
|
+
},
|
|
1966
|
+
{
|
|
1967
|
+
$ref: "#/definitions/OneOffComponent"
|
|
1968
|
+
}
|
|
1969
|
+
]
|
|
1970
|
+
}
|
|
1971
|
+
},
|
|
1972
|
+
routers: {
|
|
1973
|
+
type: "array",
|
|
1974
|
+
description: "Define how components connect to each other",
|
|
1975
|
+
items: {
|
|
1976
|
+
$ref: "#/definitions/Router"
|
|
1977
|
+
}
|
|
1978
|
+
},
|
|
1979
|
+
flow: {
|
|
1980
|
+
type: "object",
|
|
1981
|
+
description: "Specify the entry point component and other flow options",
|
|
1982
|
+
properties: {
|
|
1983
|
+
entry_point: {
|
|
1984
|
+
type: "string",
|
|
1985
|
+
description: "Name of first component to run. Examples: 'main_agent', 'initial_step'",
|
|
1986
|
+
pattern: "^[a-zA-Z0-9_]+$"
|
|
1987
|
+
},
|
|
1988
|
+
inputs: {
|
|
1989
|
+
type: "array",
|
|
1990
|
+
description: "Optional additional context schema definitions that can be passed to the flow (in addition to the 'goal')",
|
|
1991
|
+
items: {
|
|
1992
|
+
$ref: "#/definitions/FlowInputCategory"
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
},
|
|
1996
|
+
additionalProperties: false
|
|
1997
|
+
},
|
|
1998
|
+
prompts: {
|
|
1999
|
+
type: "array",
|
|
2000
|
+
description: "List of inline prompt templates for flow components to use",
|
|
2001
|
+
items: {
|
|
2002
|
+
$ref: "#/definitions/LocalPrompt"
|
|
2003
|
+
}
|
|
2004
|
+
},
|
|
2005
|
+
yaml_definition: {
|
|
2006
|
+
type: "string"
|
|
2007
|
+
}
|
|
2008
|
+
},
|
|
2009
|
+
definitions: {
|
|
2010
|
+
ComponentName: {
|
|
2011
|
+
type: "string",
|
|
2012
|
+
pattern: "^[a-zA-Z0-9_]+$",
|
|
2013
|
+
description: "Component name must use alphanumeric characters or underscore. Must not include characters such as : and . Examples: 'my_agent', 'step1', 'dataProcessor'"
|
|
2014
|
+
},
|
|
2015
|
+
AgentComponent: {
|
|
2016
|
+
type: "object",
|
|
2017
|
+
required: [
|
|
2018
|
+
"name",
|
|
2019
|
+
"type",
|
|
2020
|
+
"prompt_id"
|
|
2021
|
+
],
|
|
2022
|
+
additionalProperties: false,
|
|
2023
|
+
properties: {
|
|
2024
|
+
name: {
|
|
2025
|
+
$ref: "#/definitions/ComponentName"
|
|
2026
|
+
},
|
|
2027
|
+
type: {
|
|
2028
|
+
type: "string",
|
|
2029
|
+
const: "AgentComponent"
|
|
2030
|
+
},
|
|
2031
|
+
prompt_id: {
|
|
2032
|
+
type: "string",
|
|
2033
|
+
description: "ID of the prompt template from either the prompt registry or locally defined prompts"
|
|
2034
|
+
},
|
|
2035
|
+
prompt_version: {
|
|
2036
|
+
oneOf: [
|
|
2037
|
+
{
|
|
2038
|
+
type: "string",
|
|
2039
|
+
pattern: "^[~^]?\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$",
|
|
2040
|
+
description: "Semantic version constraint (e.g., '^1.0.0')"
|
|
2041
|
+
},
|
|
2042
|
+
{
|
|
2043
|
+
type: "null",
|
|
2044
|
+
description: "Use locally defined prompt from flow YAML"
|
|
2045
|
+
}
|
|
2046
|
+
]
|
|
2047
|
+
},
|
|
2048
|
+
inputs: {
|
|
2049
|
+
type: "array",
|
|
2050
|
+
description: "List of input data sources",
|
|
2051
|
+
default: [
|
|
2052
|
+
"context:goal"
|
|
2053
|
+
],
|
|
2054
|
+
items: {
|
|
2055
|
+
oneOf: [
|
|
2056
|
+
{
|
|
2057
|
+
type: "string",
|
|
2058
|
+
description: "Simple input reference"
|
|
2059
|
+
},
|
|
2060
|
+
{
|
|
2061
|
+
$ref: "#/definitions/InputMapping"
|
|
2062
|
+
}
|
|
2063
|
+
]
|
|
2064
|
+
}
|
|
2065
|
+
},
|
|
2066
|
+
toolset: {
|
|
2067
|
+
type: "array",
|
|
2068
|
+
description: "List of tools available to the agent. Can be tool names or objects with tool options. Examples: ['read_file', {'create_merge_request_note': {'force_internal': true}}]",
|
|
2069
|
+
items: {
|
|
2070
|
+
oneOf: [
|
|
2071
|
+
{
|
|
2072
|
+
type: "string",
|
|
2073
|
+
description: "Tool name from tools registry"
|
|
2074
|
+
},
|
|
2075
|
+
{
|
|
2076
|
+
type: "object",
|
|
2077
|
+
description: "Tool with options. Key is tool name, value is options object",
|
|
2078
|
+
minProperties: 1,
|
|
2079
|
+
maxProperties: 1,
|
|
2080
|
+
additionalProperties: {
|
|
2081
|
+
type: "object",
|
|
2082
|
+
description: "Tool-specific options as key-value pairs",
|
|
2083
|
+
additionalProperties: {
|
|
2084
|
+
oneOf: [
|
|
2085
|
+
{
|
|
2086
|
+
type: "string"
|
|
2087
|
+
},
|
|
2088
|
+
{
|
|
2089
|
+
type: "number"
|
|
2090
|
+
},
|
|
2091
|
+
{
|
|
2092
|
+
type: "boolean"
|
|
2093
|
+
},
|
|
2094
|
+
{
|
|
2095
|
+
type: "null"
|
|
2096
|
+
},
|
|
2097
|
+
{
|
|
2098
|
+
type: "array",
|
|
2099
|
+
items: {
|
|
2100
|
+
oneOf: [
|
|
2101
|
+
{
|
|
2102
|
+
type: "string"
|
|
2103
|
+
},
|
|
2104
|
+
{
|
|
2105
|
+
type: "number"
|
|
2106
|
+
},
|
|
2107
|
+
{
|
|
2108
|
+
type: "boolean"
|
|
2109
|
+
},
|
|
2110
|
+
{
|
|
2111
|
+
type: "null"
|
|
2112
|
+
}
|
|
2113
|
+
]
|
|
2114
|
+
}
|
|
2115
|
+
},
|
|
2116
|
+
{
|
|
2117
|
+
type: "object",
|
|
2118
|
+
additionalProperties: {
|
|
2119
|
+
oneOf: [
|
|
2120
|
+
{
|
|
2121
|
+
type: "string"
|
|
2122
|
+
},
|
|
2123
|
+
{
|
|
2124
|
+
type: "number"
|
|
2125
|
+
},
|
|
2126
|
+
{
|
|
2127
|
+
type: "boolean"
|
|
2128
|
+
},
|
|
2129
|
+
{
|
|
2130
|
+
type: "null"
|
|
2131
|
+
}
|
|
2132
|
+
]
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
]
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
]
|
|
2140
|
+
}
|
|
2141
|
+
},
|
|
2142
|
+
ui_log_events: {
|
|
2143
|
+
type: "array",
|
|
2144
|
+
description: "UI logging configuration",
|
|
2145
|
+
items: {
|
|
2146
|
+
type: "string",
|
|
2147
|
+
enum: [
|
|
2148
|
+
"on_agent_final_answer",
|
|
2149
|
+
"on_tool_execution_success",
|
|
2150
|
+
"on_tool_execution_failed"
|
|
2151
|
+
]
|
|
2152
|
+
}
|
|
2153
|
+
},
|
|
2154
|
+
ui_role_as: {
|
|
2155
|
+
type: "string",
|
|
2156
|
+
enum: [
|
|
2157
|
+
"agent",
|
|
2158
|
+
"tool"
|
|
2159
|
+
],
|
|
2160
|
+
description: "Display role in UI"
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
},
|
|
2164
|
+
DeterministicStepComponent: {
|
|
2165
|
+
type: "object",
|
|
2166
|
+
required: [
|
|
2167
|
+
"name",
|
|
2168
|
+
"type",
|
|
2169
|
+
"tool_name"
|
|
2170
|
+
],
|
|
2171
|
+
additionalProperties: false,
|
|
2172
|
+
properties: {
|
|
2173
|
+
name: {
|
|
2174
|
+
$ref: "#/definitions/ComponentName"
|
|
2175
|
+
},
|
|
2176
|
+
type: {
|
|
2177
|
+
type: "string",
|
|
2178
|
+
const: "DeterministicStepComponent"
|
|
2179
|
+
},
|
|
2180
|
+
tool_name: {
|
|
2181
|
+
type: "string",
|
|
2182
|
+
description: "Name of the single tool to execute"
|
|
2183
|
+
},
|
|
2184
|
+
toolset: {
|
|
2185
|
+
type: "array",
|
|
2186
|
+
description: "Toolset containing the tool to be executed",
|
|
2187
|
+
items: {
|
|
2188
|
+
type: "string"
|
|
2189
|
+
}
|
|
2190
|
+
},
|
|
2191
|
+
inputs: {
|
|
2192
|
+
type: "array",
|
|
2193
|
+
description: "List of input data sources to extract tool parameters",
|
|
2194
|
+
default: [],
|
|
2195
|
+
items: {
|
|
2196
|
+
oneOf: [
|
|
2197
|
+
{
|
|
2198
|
+
type: "string",
|
|
2199
|
+
description: "Simple input reference. Examples: 'context:goal'"
|
|
2200
|
+
},
|
|
2201
|
+
{
|
|
2202
|
+
$ref: "#/definitions/InputMapping"
|
|
2203
|
+
}
|
|
2204
|
+
]
|
|
2205
|
+
}
|
|
2206
|
+
},
|
|
2207
|
+
ui_log_events: {
|
|
2208
|
+
type: "array",
|
|
2209
|
+
description: "UI logging configuration for displaying tool execution",
|
|
2210
|
+
items: {
|
|
2211
|
+
type: "string",
|
|
2212
|
+
enum: [
|
|
2213
|
+
"on_tool_execution_success",
|
|
2214
|
+
"on_tool_execution_failed"
|
|
2215
|
+
]
|
|
2216
|
+
}
|
|
2217
|
+
},
|
|
2218
|
+
ui_role_as: {
|
|
2219
|
+
type: "string",
|
|
2220
|
+
enum: [
|
|
2221
|
+
"agent",
|
|
2222
|
+
"tool"
|
|
2223
|
+
],
|
|
2224
|
+
default: "tool",
|
|
2225
|
+
description: "Display role in UI"
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
},
|
|
2229
|
+
OneOffComponent: {
|
|
2230
|
+
type: "object",
|
|
2231
|
+
required: [
|
|
2232
|
+
"name",
|
|
2233
|
+
"type",
|
|
2234
|
+
"prompt_id",
|
|
2235
|
+
"toolset"
|
|
2236
|
+
],
|
|
2237
|
+
additionalProperties: false,
|
|
2238
|
+
properties: {
|
|
2239
|
+
name: {
|
|
2240
|
+
$ref: "#/definitions/ComponentName"
|
|
2241
|
+
},
|
|
2242
|
+
type: {
|
|
2243
|
+
type: "string",
|
|
2244
|
+
const: "OneOffComponent"
|
|
2245
|
+
},
|
|
2246
|
+
prompt_id: {
|
|
2247
|
+
type: "string",
|
|
2248
|
+
description: "ID of the prompt template from either the prompt registry or locally defined prompts"
|
|
2249
|
+
},
|
|
2250
|
+
prompt_version: {
|
|
2251
|
+
oneOf: [
|
|
2252
|
+
{
|
|
2253
|
+
type: "string",
|
|
2254
|
+
pattern: "^[~^]?\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$",
|
|
2255
|
+
description: "Semantic version constraint. Examples: '1.0.0' (exact), '^1.2.3' (compatible)"
|
|
2256
|
+
},
|
|
2257
|
+
{
|
|
2258
|
+
type: "null",
|
|
2259
|
+
description: "Use locally defined prompt from flow YAML"
|
|
2260
|
+
}
|
|
2261
|
+
]
|
|
2262
|
+
},
|
|
2263
|
+
toolset: {
|
|
2264
|
+
type: "array",
|
|
2265
|
+
minItems: 1,
|
|
2266
|
+
description: "List of tools available to the component. Examples: ['read_file', 'list_dir', 'edit_file']",
|
|
2267
|
+
items: {
|
|
2268
|
+
type: "string",
|
|
2269
|
+
description: "Tool name from tools registry"
|
|
2270
|
+
}
|
|
2271
|
+
},
|
|
2272
|
+
inputs: {
|
|
2273
|
+
type: "array",
|
|
2274
|
+
description: "List of input data sources",
|
|
2275
|
+
default: [
|
|
2276
|
+
"context:goal"
|
|
2277
|
+
],
|
|
2278
|
+
items: {
|
|
2279
|
+
oneOf: [
|
|
2280
|
+
{
|
|
2281
|
+
type: "string",
|
|
2282
|
+
description: "Simple input reference. Examples: 'context:goal'"
|
|
2283
|
+
},
|
|
2284
|
+
{
|
|
2285
|
+
$ref: "#/definitions/InputMapping"
|
|
2286
|
+
}
|
|
2287
|
+
]
|
|
2288
|
+
}
|
|
2289
|
+
},
|
|
2290
|
+
max_correction_attempts: {
|
|
2291
|
+
type: "integer",
|
|
2292
|
+
minimum: 0,
|
|
2293
|
+
default: 3,
|
|
2294
|
+
description: "Maximum number of retry attempts for failed tool executions"
|
|
2295
|
+
},
|
|
2296
|
+
ui_log_events: {
|
|
2297
|
+
type: "array",
|
|
2298
|
+
description: "UI logging configuration for displaying tool execution progress",
|
|
2299
|
+
items: {
|
|
2300
|
+
type: "string",
|
|
2301
|
+
enum: [
|
|
2302
|
+
"on_tool_call_input",
|
|
2303
|
+
"on_tool_execution_success",
|
|
2304
|
+
"on_tool_execution_failed"
|
|
2305
|
+
]
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
},
|
|
2310
|
+
InputMapping: {
|
|
2311
|
+
type: "object",
|
|
2312
|
+
required: [
|
|
2313
|
+
"from",
|
|
2314
|
+
"as"
|
|
2315
|
+
],
|
|
2316
|
+
additionalProperties: false,
|
|
2317
|
+
properties: {
|
|
2318
|
+
from: {
|
|
2319
|
+
type: "string",
|
|
2320
|
+
description: "Source of the input data. Examples: 'context:goal'"
|
|
2321
|
+
},
|
|
2322
|
+
as: {
|
|
2323
|
+
type: "string",
|
|
2324
|
+
description: "Variable name to use in prompt template. Examples: 'user_goal'"
|
|
2325
|
+
},
|
|
2326
|
+
literal: {
|
|
2327
|
+
type: "boolean",
|
|
2328
|
+
description: "Whether the 'from' value should be treated as a literal value"
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
},
|
|
2332
|
+
Router: {
|
|
2333
|
+
type: "object",
|
|
2334
|
+
required: [
|
|
2335
|
+
"from"
|
|
2336
|
+
],
|
|
2337
|
+
additionalProperties: false,
|
|
2338
|
+
properties: {
|
|
2339
|
+
from: {
|
|
2340
|
+
type: "string",
|
|
2341
|
+
description: "Source component name. Examples: 'main_agent', 'data_processor'"
|
|
2342
|
+
},
|
|
2343
|
+
to: {
|
|
2344
|
+
type: "string",
|
|
2345
|
+
description: "Target component name or 'end'. Examples: 'next_step', 'error_handler', 'end'"
|
|
2346
|
+
},
|
|
2347
|
+
condition: {
|
|
2348
|
+
$ref: "#/definitions/RouterCondition"
|
|
2349
|
+
}
|
|
2350
|
+
},
|
|
2351
|
+
oneOf: [
|
|
2352
|
+
{
|
|
2353
|
+
required: [
|
|
2354
|
+
"to"
|
|
2355
|
+
]
|
|
2356
|
+
},
|
|
2357
|
+
{
|
|
2358
|
+
required: [
|
|
2359
|
+
"condition"
|
|
2360
|
+
]
|
|
2361
|
+
}
|
|
2362
|
+
]
|
|
2363
|
+
},
|
|
2364
|
+
RouterCondition: {
|
|
2365
|
+
type: "object",
|
|
2366
|
+
required: [
|
|
2367
|
+
"input",
|
|
2368
|
+
"routes"
|
|
2369
|
+
],
|
|
2370
|
+
additionalProperties: false,
|
|
2371
|
+
properties: {
|
|
2372
|
+
input: {
|
|
2373
|
+
type: "string",
|
|
2374
|
+
description: "Input to evaluate for routing decision"
|
|
2375
|
+
},
|
|
2376
|
+
routes: {
|
|
2377
|
+
type: "object",
|
|
2378
|
+
description: "Mapping of condition values to target components",
|
|
2379
|
+
patternProperties: {
|
|
2380
|
+
".*": {
|
|
2381
|
+
type: "string",
|
|
2382
|
+
description: "Target component name or 'end'"
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
},
|
|
2388
|
+
LocalPrompt: {
|
|
2389
|
+
type: "object",
|
|
2390
|
+
required: [
|
|
2391
|
+
"prompt_id",
|
|
2392
|
+
"name",
|
|
2393
|
+
"prompt_template",
|
|
2394
|
+
"unit_primitives"
|
|
2395
|
+
],
|
|
2396
|
+
additionalProperties: false,
|
|
2397
|
+
properties: {
|
|
2398
|
+
prompt_id: {
|
|
2399
|
+
type: "string",
|
|
2400
|
+
description: "Unique identifier for the local prompt"
|
|
2401
|
+
},
|
|
2402
|
+
name: {
|
|
2403
|
+
type: "string",
|
|
2404
|
+
description: "name for the local prompt"
|
|
2405
|
+
},
|
|
2406
|
+
prompt_template: {
|
|
2407
|
+
$ref: "#/definitions/PromptTemplate"
|
|
2408
|
+
},
|
|
2409
|
+
params: {
|
|
2410
|
+
type: "object",
|
|
2411
|
+
properties: {
|
|
2412
|
+
timeout: {
|
|
2413
|
+
type: "integer",
|
|
2414
|
+
minimum: 1,
|
|
2415
|
+
description: "Timeout in seconds for prompt execution"
|
|
2416
|
+
},
|
|
2417
|
+
vertex_location: {
|
|
2418
|
+
type: "string",
|
|
2419
|
+
description: "Vertex AI location for the flow"
|
|
2420
|
+
}
|
|
2421
|
+
},
|
|
2422
|
+
additionalProperties: false
|
|
2423
|
+
},
|
|
2424
|
+
unit_primitives: {
|
|
2425
|
+
type: "array",
|
|
2426
|
+
description: "Unit primitives configuration",
|
|
2427
|
+
items: {
|
|
2428
|
+
type: "string"
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
},
|
|
2433
|
+
PromptTemplate: {
|
|
2434
|
+
type: "object",
|
|
2435
|
+
additionalProperties: false,
|
|
2436
|
+
properties: {
|
|
2437
|
+
system: {
|
|
2438
|
+
type: "string",
|
|
2439
|
+
description: "System message template"
|
|
2440
|
+
},
|
|
2441
|
+
user: {
|
|
2442
|
+
type: "string",
|
|
2443
|
+
description: "User message template"
|
|
2444
|
+
},
|
|
2445
|
+
placeholder: {
|
|
2446
|
+
type: "string",
|
|
2447
|
+
enum: [
|
|
2448
|
+
"history"
|
|
2449
|
+
],
|
|
2450
|
+
description: "Message placeholder for conversation history"
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
},
|
|
2454
|
+
FlowInputCategory: {
|
|
2455
|
+
type: "object",
|
|
2456
|
+
required: [
|
|
2457
|
+
"category",
|
|
2458
|
+
"input_schema"
|
|
2459
|
+
],
|
|
2460
|
+
additionalProperties: false,
|
|
2461
|
+
description: "Defines a category of additional context inputs that can be passed to the flow",
|
|
2462
|
+
properties: {
|
|
2463
|
+
category: {
|
|
2464
|
+
type: "string",
|
|
2465
|
+
description: "Category name for the additional context. Examples: 'merge_request_info', 'pipeline_info'"
|
|
2466
|
+
},
|
|
2467
|
+
input_schema: {
|
|
2468
|
+
type: "object",
|
|
2469
|
+
description: "Schema definition for the inputs in this category",
|
|
2470
|
+
patternProperties: {
|
|
2471
|
+
".*": {
|
|
2472
|
+
$ref: "#/definitions/FlowInputField"
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
},
|
|
2478
|
+
FlowInputField: {
|
|
2479
|
+
type: "object",
|
|
2480
|
+
required: [
|
|
2481
|
+
"type"
|
|
2482
|
+
],
|
|
2483
|
+
additionalProperties: false,
|
|
2484
|
+
description: "Schema definition for a single input field",
|
|
2485
|
+
properties: {
|
|
2486
|
+
type: {
|
|
2487
|
+
type: "string",
|
|
2488
|
+
description: "JSON Schema type for the field. Examples: 'string'"
|
|
2489
|
+
},
|
|
2490
|
+
format: {
|
|
2491
|
+
type: "string",
|
|
2492
|
+
description: "Optional JSON Schema format specifier. Examples: 'uri', 'email', 'date-time'"
|
|
2493
|
+
},
|
|
2494
|
+
description: {
|
|
2495
|
+
type: "string",
|
|
2496
|
+
description: "Optional description of the field's purpose"
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
};
|
|
2502
|
+
|
|
2503
|
+
// src/flow-validator.ts
|
|
2504
|
+
function validateFlowYaml(yamlString) {
|
|
2505
|
+
let parsed;
|
|
2506
|
+
try {
|
|
2507
|
+
parsed = yaml.load(yamlString);
|
|
2508
|
+
} catch (e) {
|
|
2509
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
2510
|
+
return { valid: false, errors: [`Invalid YAML syntax: ${msg}`] };
|
|
2511
|
+
}
|
|
2512
|
+
if (!parsed || typeof parsed !== "object") {
|
|
2513
|
+
return { valid: false, errors: ["YAML must be an object"] };
|
|
2514
|
+
}
|
|
2515
|
+
parsed.yaml_definition = yamlString;
|
|
2516
|
+
const ajv = new Ajv({ allErrors: true, strict: false });
|
|
2517
|
+
const validate = ajv.compile(flow_v2_default);
|
|
2518
|
+
const valid = validate(parsed);
|
|
2519
|
+
if (!valid && validate.errors) {
|
|
2520
|
+
const errors = validate.errors.map((e) => {
|
|
2521
|
+
const path = e.instancePath || "/";
|
|
2522
|
+
return `${path}: ${e.message}`;
|
|
2523
|
+
});
|
|
2524
|
+
return { valid: false, errors };
|
|
2525
|
+
}
|
|
2526
|
+
return { valid: true, errors: [] };
|
|
2527
|
+
}
|
|
4433
2528
|
|
|
4434
2529
|
// src/agents.ts
|
|
4435
2530
|
function resolveModelId(entry) {
|
|
@@ -4652,6 +2747,166 @@ Before calling gitlab_create_agent, you MUST:
|
|
|
4652
2747
|
3. Show the generated system prompt and ask for confirmation.
|
|
4653
2748
|
4. Only then call gitlab_create_agent. Use full tool GIDs like "gid://gitlab/Ai::Catalog::BuiltInTool/1".
|
|
4654
2749
|
5. Ask if the user wants to enable it on the current project.`;
|
|
2750
|
+
var FLOW_SCHEMA_REFERENCE = `## Flow YAML Schema Reference
|
|
2751
|
+
|
|
2752
|
+
### Top-level structure (all required unless noted):
|
|
2753
|
+
version: "v1" # Always "v1"
|
|
2754
|
+
environment: ambient # Always "ambient"
|
|
2755
|
+
components: [...] # Array of components (min 1)
|
|
2756
|
+
routers: [...] # Array of routers connecting components
|
|
2757
|
+
flow:
|
|
2758
|
+
entry_point: "component_name" # First component to run
|
|
2759
|
+
inputs: [...] # Optional: additional context inputs
|
|
2760
|
+
prompts: [...] # Optional: inline prompt definitions
|
|
2761
|
+
|
|
2762
|
+
### Component types:
|
|
2763
|
+
|
|
2764
|
+
1. DeterministicStepComponent \u2014 runs ONE tool, no LLM call:
|
|
2765
|
+
- name: "fetch_data" # alphanumeric + underscore only
|
|
2766
|
+
type: DeterministicStepComponent
|
|
2767
|
+
tool_name: "get_merge_request"
|
|
2768
|
+
inputs: # map tool parameters
|
|
2769
|
+
- { from: "context:goal", as: "merge_request_iid" }
|
|
2770
|
+
- { from: "context:project_id", as: "project_id" }
|
|
2771
|
+
|
|
2772
|
+
2. OneOffComponent \u2014 single LLM call + tool execution:
|
|
2773
|
+
- name: "process_data"
|
|
2774
|
+
type: OneOffComponent
|
|
2775
|
+
prompt_id: "my_prompt" # references inline prompt
|
|
2776
|
+
prompt_version: null # null = use inline prompt from prompts section
|
|
2777
|
+
toolset: ["read_file", "edit_file"]
|
|
2778
|
+
inputs:
|
|
2779
|
+
- { from: "context:fetch_data.tool_responses", as: "data" }
|
|
2780
|
+
max_correction_attempts: 3 # retries on tool failure (default 3)
|
|
2781
|
+
|
|
2782
|
+
3. AgentComponent \u2014 multi-turn LLM reasoning loop:
|
|
2783
|
+
- name: "analyze"
|
|
2784
|
+
type: AgentComponent
|
|
2785
|
+
prompt_id: "my_agent_prompt"
|
|
2786
|
+
prompt_version: null
|
|
2787
|
+
toolset: ["read_file", "grep"]
|
|
2788
|
+
inputs:
|
|
2789
|
+
- { from: "context:goal", as: "user_goal" }
|
|
2790
|
+
ui_log_events: ["on_agent_final_answer"]
|
|
2791
|
+
|
|
2792
|
+
### IOKey syntax (inputs/from values):
|
|
2793
|
+
"context:goal" # The flow goal (user input)
|
|
2794
|
+
"context:project_id" # Project ID (auto-injected)
|
|
2795
|
+
"context:<component_name>.tool_responses" # Tool output from a component
|
|
2796
|
+
"context:<component_name>.final_answer" # Agent's final text answer
|
|
2797
|
+
"context:<component_name>.execution_result" # OneOff execution result
|
|
2798
|
+
{ from: "context:x", as: "var_name" } # Rename for prompt template
|
|
2799
|
+
{ from: "true", as: "flag", literal: true } # Literal value
|
|
2800
|
+
|
|
2801
|
+
### Router patterns:
|
|
2802
|
+
Direct: { from: "step1", to: "step2" }
|
|
2803
|
+
To end: { from: "last_step", to: "end" }
|
|
2804
|
+
Conditional: { from: "step1", condition: { input: "context:step1.final_answer.decision", routes: { "yes": "step2", "no": "end" } } }
|
|
2805
|
+
|
|
2806
|
+
### Inline prompts (in prompts section):
|
|
2807
|
+
- prompt_id: "my_prompt"
|
|
2808
|
+
name: "My Prompt"
|
|
2809
|
+
unit_primitives: ["duo_agent_platform"] # Always this value
|
|
2810
|
+
prompt_template:
|
|
2811
|
+
system: "You are a helpful assistant. {{var_name}} is available."
|
|
2812
|
+
user: "Process: {{data}}"
|
|
2813
|
+
placeholder: "history" # Optional, for AgentComponent conversation history
|
|
2814
|
+
|
|
2815
|
+
### Tool names: use names from gitlab_list_builtin_tools (e.g., "read_file", "get_merge_request", "create_merge_request_note").`;
|
|
2816
|
+
var FLOW_EXAMPLE_LINEAR = `## Example: Simple linear flow (fetch MR \u2192 analyze \u2192 post comment)
|
|
2817
|
+
\`\`\`yaml
|
|
2818
|
+
version: "v1"
|
|
2819
|
+
environment: ambient
|
|
2820
|
+
components:
|
|
2821
|
+
- name: fetch_mr
|
|
2822
|
+
type: DeterministicStepComponent
|
|
2823
|
+
tool_name: build_review_merge_request_context
|
|
2824
|
+
inputs:
|
|
2825
|
+
- { from: "context:project_id", as: "project_id" }
|
|
2826
|
+
- { from: "context:goal", as: "merge_request_iid" }
|
|
2827
|
+
ui_log_events: ["on_tool_execution_success", "on_tool_execution_failed"]
|
|
2828
|
+
- name: analyze_and_comment
|
|
2829
|
+
type: OneOffComponent
|
|
2830
|
+
prompt_id: review_prompt
|
|
2831
|
+
prompt_version: null
|
|
2832
|
+
toolset: ["create_merge_request_note"]
|
|
2833
|
+
inputs:
|
|
2834
|
+
- { from: "context:fetch_mr.tool_responses", as: "mr_data" }
|
|
2835
|
+
- { from: "context:project_id", as: "project_id" }
|
|
2836
|
+
- { from: "context:goal", as: "merge_request_iid" }
|
|
2837
|
+
max_correction_attempts: 3
|
|
2838
|
+
ui_log_events: ["on_tool_execution_success"]
|
|
2839
|
+
routers:
|
|
2840
|
+
- { from: fetch_mr, to: analyze_and_comment }
|
|
2841
|
+
- { from: analyze_and_comment, to: end }
|
|
2842
|
+
flow:
|
|
2843
|
+
entry_point: fetch_mr
|
|
2844
|
+
prompts:
|
|
2845
|
+
- prompt_id: review_prompt
|
|
2846
|
+
name: MR Review Prompt
|
|
2847
|
+
unit_primitives: ["duo_agent_platform"]
|
|
2848
|
+
prompt_template:
|
|
2849
|
+
system: |
|
|
2850
|
+
You review merge requests. Analyze the MR data and post a concise review comment.
|
|
2851
|
+
Focus on code quality, potential bugs, and improvements.
|
|
2852
|
+
user: "Review MR !{{merge_request_iid}} in project {{project_id}}: {{mr_data}}"
|
|
2853
|
+
\`\`\``;
|
|
2854
|
+
var FLOW_EXAMPLE_CONDITIONAL = `## Example: Conditional flow (gather data \u2192 decide \u2192 branch)
|
|
2855
|
+
\`\`\`yaml
|
|
2856
|
+
version: "v1"
|
|
2857
|
+
environment: ambient
|
|
2858
|
+
components:
|
|
2859
|
+
- name: gather_context
|
|
2860
|
+
type: DeterministicStepComponent
|
|
2861
|
+
tool_name: get_vulnerability_details
|
|
2862
|
+
inputs:
|
|
2863
|
+
- { from: "context:goal", as: "vulnerability_id" }
|
|
2864
|
+
ui_log_events: ["on_tool_execution_success"]
|
|
2865
|
+
- name: evaluate
|
|
2866
|
+
type: AgentComponent
|
|
2867
|
+
prompt_id: eval_prompt
|
|
2868
|
+
prompt_version: null
|
|
2869
|
+
toolset: []
|
|
2870
|
+
inputs:
|
|
2871
|
+
- { from: "context:gather_context.tool_responses", as: "vuln_data" }
|
|
2872
|
+
ui_log_events: ["on_agent_final_answer"]
|
|
2873
|
+
- name: create_fix
|
|
2874
|
+
type: AgentComponent
|
|
2875
|
+
prompt_id: fix_prompt
|
|
2876
|
+
prompt_version: null
|
|
2877
|
+
toolset: ["read_file", "edit_file", "grep"]
|
|
2878
|
+
inputs:
|
|
2879
|
+
- { from: "context:gather_context.tool_responses", as: "vuln_data" }
|
|
2880
|
+
ui_log_events: ["on_agent_final_answer", "on_tool_execution_success"]
|
|
2881
|
+
routers:
|
|
2882
|
+
- { from: gather_context, to: evaluate }
|
|
2883
|
+
- from: evaluate
|
|
2884
|
+
condition:
|
|
2885
|
+
input: "context:evaluate.final_answer"
|
|
2886
|
+
routes:
|
|
2887
|
+
"fix_needed": create_fix
|
|
2888
|
+
"false_positive": end
|
|
2889
|
+
default_route: end
|
|
2890
|
+
- { from: create_fix, to: end }
|
|
2891
|
+
flow:
|
|
2892
|
+
entry_point: gather_context
|
|
2893
|
+
prompts:
|
|
2894
|
+
- prompt_id: eval_prompt
|
|
2895
|
+
name: Vulnerability Evaluator
|
|
2896
|
+
unit_primitives: ["duo_agent_platform"]
|
|
2897
|
+
prompt_template:
|
|
2898
|
+
system: |
|
|
2899
|
+
Evaluate if a vulnerability needs fixing. Respond with exactly "fix_needed" or "false_positive".
|
|
2900
|
+
user: "Evaluate: {{vuln_data}}"
|
|
2901
|
+
- prompt_id: fix_prompt
|
|
2902
|
+
name: Fix Generator
|
|
2903
|
+
unit_primitives: ["duo_agent_platform"]
|
|
2904
|
+
prompt_template:
|
|
2905
|
+
system: |
|
|
2906
|
+
You fix security vulnerabilities. Read the relevant code and apply the fix.
|
|
2907
|
+
user: "Fix this vulnerability: {{vuln_data}}"
|
|
2908
|
+
placeholder: history
|
|
2909
|
+
\`\`\``;
|
|
4655
2910
|
var plugin = async (input) => {
|
|
4656
2911
|
let authCache = null;
|
|
4657
2912
|
let projectPath;
|
|
@@ -4661,7 +2916,7 @@ var plugin = async (input) => {
|
|
|
4661
2916
|
let cachedAgents = [];
|
|
4662
2917
|
let cfgRef = null;
|
|
4663
2918
|
let baseModelIdRef;
|
|
4664
|
-
async function
|
|
2919
|
+
async function load() {
|
|
4665
2920
|
const auth = readAuth();
|
|
4666
2921
|
if (!auth) return null;
|
|
4667
2922
|
authCache = auth;
|
|
@@ -4683,7 +2938,7 @@ var plugin = async (input) => {
|
|
|
4683
2938
|
if (!authCache || !cfgRef) return;
|
|
4684
2939
|
const key = `${input.directory}\0${authCache.instanceUrl}`;
|
|
4685
2940
|
memo.delete(key);
|
|
4686
|
-
const result = await
|
|
2941
|
+
const result = await load();
|
|
4687
2942
|
if (!result) return;
|
|
4688
2943
|
const previousNames = /* @__PURE__ */ new Set([
|
|
4689
2944
|
...flowAgents.keys(),
|
|
@@ -4736,7 +2991,7 @@ var plugin = async (input) => {
|
|
|
4736
2991
|
}
|
|
4737
2992
|
return {
|
|
4738
2993
|
async config(cfg) {
|
|
4739
|
-
const result = await
|
|
2994
|
+
const result = await load();
|
|
4740
2995
|
if (!result?.agents.length) return;
|
|
4741
2996
|
cachedAgents = result.agents;
|
|
4742
2997
|
const baseModelId = resolveModelId(result.entry);
|
|
@@ -5127,6 +3382,132 @@ User goal: "${rawText2}"`;
|
|
|
5127
3382
|
return JSON.stringify(tools, null, 2);
|
|
5128
3383
|
}
|
|
5129
3384
|
}),
|
|
3385
|
+
gitlab_design_flow: tool({
|
|
3386
|
+
description: "Interactive flow design tool. Returns the flow YAML schema reference, examples, and instructions.\nUse this BEFORE gitlab_create_flow to design the flow definition interactively with the user.\nThe tool also validates generated YAML against the flow_v2 JSON schema.",
|
|
3387
|
+
args: {
|
|
3388
|
+
action: z.enum(["get_schema", "validate"]).describe(
|
|
3389
|
+
'"get_schema" returns the schema reference and examples. "validate" validates a YAML definition.'
|
|
3390
|
+
),
|
|
3391
|
+
definition: z.string().optional().describe("YAML definition to validate (required when action=validate)")
|
|
3392
|
+
},
|
|
3393
|
+
execute: async (args) => {
|
|
3394
|
+
if (args.action === "validate") {
|
|
3395
|
+
if (!args.definition) return "Error: definition is required for validate action.";
|
|
3396
|
+
const result = validateFlowYaml(args.definition);
|
|
3397
|
+
if (result.valid) return "VALID: Flow definition passes schema validation.";
|
|
3398
|
+
return `INVALID: ${result.errors.length} error(s):
|
|
3399
|
+
${result.errors.map((e, i) => ` ${i + 1}. ${e}`).join("\n")}`;
|
|
3400
|
+
}
|
|
3401
|
+
return [
|
|
3402
|
+
"Follow this multi-round workflow to design a flow:",
|
|
3403
|
+
"",
|
|
3404
|
+
"ROUND 1: Call gitlab_list_builtin_tools to discover available tool names for the flow.",
|
|
3405
|
+
" Then use the question tool to ask the user:",
|
|
3406
|
+
" - Flow name",
|
|
3407
|
+
" - Visibility: Public or Private",
|
|
3408
|
+
" - What the flow should do (step-by-step description)",
|
|
3409
|
+
" - What GitLab resource it operates on (MR, issue, pipeline, vulnerability, etc.)",
|
|
3410
|
+
"",
|
|
3411
|
+
"ROUND 2: Based on the user's answers, propose a component architecture in plain text:",
|
|
3412
|
+
" - List each step with its type (DeterministicStep, OneOff, or Agent)",
|
|
3413
|
+
" - Explain what each step does and what tools it uses",
|
|
3414
|
+
" - Show the routing (linear or conditional)",
|
|
3415
|
+
" Ask the user to confirm or adjust.",
|
|
3416
|
+
"",
|
|
3417
|
+
"ROUND 3: Generate the full YAML definition using the schema below.",
|
|
3418
|
+
" Call gitlab_design_flow with action='validate' to check it.",
|
|
3419
|
+
" Show the validated YAML to the user for final approval.",
|
|
3420
|
+
" Then call gitlab_create_flow with confirmed=true.",
|
|
3421
|
+
"",
|
|
3422
|
+
"=== FLOW YAML SCHEMA ===",
|
|
3423
|
+
FLOW_SCHEMA_REFERENCE,
|
|
3424
|
+
"",
|
|
3425
|
+
"=== EXAMPLE: Linear flow ===",
|
|
3426
|
+
FLOW_EXAMPLE_LINEAR,
|
|
3427
|
+
"",
|
|
3428
|
+
"=== EXAMPLE: Conditional flow ===",
|
|
3429
|
+
FLOW_EXAMPLE_CONDITIONAL
|
|
3430
|
+
].join("\n");
|
|
3431
|
+
}
|
|
3432
|
+
}),
|
|
3433
|
+
gitlab_create_flow: tool({
|
|
3434
|
+
description: "Create a custom flow in the GitLab AI Catalog.\nFirst call: set confirmed=false (or omit). Returns instructions to use gitlab_design_flow first.\nSecond call: after the user confirms, set confirmed=true to create the flow.\nAfter creation, use gitlab_enable_project_flow to enable it on a project.",
|
|
3435
|
+
args: {
|
|
3436
|
+
project_id: z.string().describe('Project path (e.g., "gitlab-org/gitlab")'),
|
|
3437
|
+
name: z.string().describe("Display name for the flow"),
|
|
3438
|
+
description: z.string().describe("Description of what the flow does"),
|
|
3439
|
+
public: z.boolean().describe("Whether publicly visible in the AI Catalog"),
|
|
3440
|
+
definition: z.string().describe("Flow YAML definition (validated via gitlab_design_flow)"),
|
|
3441
|
+
release: z.boolean().optional().describe("Whether to release the version immediately"),
|
|
3442
|
+
confirmed: z.boolean().optional().describe("Set true only after user has reviewed the YAML")
|
|
3443
|
+
},
|
|
3444
|
+
execute: async (args) => {
|
|
3445
|
+
if (!args.confirmed) {
|
|
3446
|
+
return [
|
|
3447
|
+
"STOP: Do not create the flow yet.",
|
|
3448
|
+
"",
|
|
3449
|
+
"Call gitlab_design_flow with action='get_schema' first to get the interactive workflow.",
|
|
3450
|
+
"Follow the multi-round design process, then call this tool with confirmed=true."
|
|
3451
|
+
].join("\n");
|
|
3452
|
+
}
|
|
3453
|
+
const validation = validateFlowYaml(args.definition);
|
|
3454
|
+
if (!validation.valid) {
|
|
3455
|
+
return `Flow YAML validation failed:
|
|
3456
|
+
${validation.errors.map((e, i) => ` ${i + 1}. ${e}`).join("\n")}
|
|
3457
|
+
|
|
3458
|
+
Fix the errors and try again.`;
|
|
3459
|
+
}
|
|
3460
|
+
const auth = authCache ?? readAuth();
|
|
3461
|
+
if (!auth) throw new Error("Not authenticated");
|
|
3462
|
+
const result = await createFlow(auth.instanceUrl, auth.token, args.project_id, {
|
|
3463
|
+
name: args.name,
|
|
3464
|
+
description: args.description,
|
|
3465
|
+
public: args.public,
|
|
3466
|
+
definition: args.definition,
|
|
3467
|
+
release: args.release
|
|
3468
|
+
});
|
|
3469
|
+
await refreshAgents();
|
|
3470
|
+
const json = JSON.stringify(result, null, 2);
|
|
3471
|
+
return `${json}
|
|
3472
|
+
|
|
3473
|
+
Flow created successfully. Ask the user if they want to enable it on the current project using gitlab_enable_project_flow.`;
|
|
3474
|
+
}
|
|
3475
|
+
}),
|
|
3476
|
+
gitlab_update_flow: tool({
|
|
3477
|
+
description: "Update an existing custom flow in the GitLab AI Catalog.\nOnly provided fields are updated; omitted fields remain unchanged.\nUse gitlab_design_flow with action='validate' to check YAML before updating.",
|
|
3478
|
+
args: {
|
|
3479
|
+
id: z.string().describe("Flow ID (numeric or full GID)"),
|
|
3480
|
+
name: z.string().optional().describe("New display name"),
|
|
3481
|
+
description: z.string().optional().describe("New description"),
|
|
3482
|
+
public: z.boolean().optional().describe("Whether publicly visible"),
|
|
3483
|
+
definition: z.string().optional().describe("New flow YAML definition"),
|
|
3484
|
+
release: z.boolean().optional().describe("Whether to release the latest version"),
|
|
3485
|
+
version_bump: z.enum(["MAJOR", "MINOR", "PATCH"]).optional().describe("Version bump type")
|
|
3486
|
+
},
|
|
3487
|
+
execute: async (args) => {
|
|
3488
|
+
if (args.definition) {
|
|
3489
|
+
const validation = validateFlowYaml(args.definition);
|
|
3490
|
+
if (!validation.valid) {
|
|
3491
|
+
return `Flow YAML validation failed:
|
|
3492
|
+
${validation.errors.map((e, i) => ` ${i + 1}. ${e}`).join("\n")}
|
|
3493
|
+
|
|
3494
|
+
Fix the errors and try again.`;
|
|
3495
|
+
}
|
|
3496
|
+
}
|
|
3497
|
+
const auth = authCache ?? readAuth();
|
|
3498
|
+
if (!auth) throw new Error("Not authenticated");
|
|
3499
|
+
const result = await updateFlow(auth.instanceUrl, auth.token, args.id, {
|
|
3500
|
+
name: args.name,
|
|
3501
|
+
description: args.description,
|
|
3502
|
+
public: args.public,
|
|
3503
|
+
definition: args.definition,
|
|
3504
|
+
release: args.release,
|
|
3505
|
+
versionBump: args.version_bump
|
|
3506
|
+
});
|
|
3507
|
+
await refreshAgents();
|
|
3508
|
+
return JSON.stringify(result, null, 2);
|
|
3509
|
+
}
|
|
3510
|
+
}),
|
|
5130
3511
|
...makeAgentFlowTools(
|
|
5131
3512
|
z,
|
|
5132
3513
|
() => authCache,
|
|
@@ -5143,9 +3524,4 @@ var index_default = plugin;
|
|
|
5143
3524
|
export {
|
|
5144
3525
|
index_default as default
|
|
5145
3526
|
};
|
|
5146
|
-
/*! Bundled license information:
|
|
5147
|
-
|
|
5148
|
-
js-yaml/dist/js-yaml.mjs:
|
|
5149
|
-
(*! js-yaml 4.1.1 https://github.com/nodeca/js-yaml @license MIT *)
|
|
5150
|
-
*/
|
|
5151
3527
|
//# sourceMappingURL=index.js.map
|