opencode-gitlab-dap 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,198 +17,2825 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
21
31
  var index_exports = {};
22
32
  __export(index_exports, {
23
- default: () => index_default,
24
- plugin: () => plugin
33
+ default: () => index_default
25
34
  });
26
35
  module.exports = __toCommonJS(index_exports);
27
-
28
- // src/select.ts
29
36
  var import_gitlab_ai_provider = require("gitlab-ai-provider");
30
- var discovery = null;
31
- function getDiscovery() {
32
- return discovery;
33
- }
34
- async function discover(opts) {
35
- if (!opts.token) return { status: "no_provider" };
36
- if (opts.fresh) {
37
- const c = new import_gitlab_ai_provider.GitLabModelCache(opts.directory, opts.instanceUrl);
38
- c.clear();
39
- }
40
- const headers = () => ({ Authorization: `Bearer ${opts.token}` });
41
- const detector = new import_gitlab_ai_provider.GitLabProjectDetector({
42
- instanceUrl: opts.instanceUrl,
43
- getHeaders: headers
37
+
38
+ // node_modules/js-yaml/dist/js-yaml.mjs
39
+ function isNothing(subject) {
40
+ return typeof subject === "undefined" || subject === null;
41
+ }
42
+ function isObject(subject) {
43
+ return typeof subject === "object" && subject !== null;
44
+ }
45
+ function toArray(sequence) {
46
+ if (Array.isArray(sequence)) return sequence;
47
+ else if (isNothing(sequence)) return [];
48
+ return [sequence];
49
+ }
50
+ function extend(target, source) {
51
+ var index, length, key, sourceKeys;
52
+ if (source) {
53
+ sourceKeys = Object.keys(source);
54
+ for (index = 0, length = sourceKeys.length; index < length; index += 1) {
55
+ key = sourceKeys[index];
56
+ target[key] = source[key];
57
+ }
58
+ }
59
+ return target;
60
+ }
61
+ function repeat(string, count) {
62
+ var result = "", cycle;
63
+ for (cycle = 0; cycle < count; cycle += 1) {
64
+ result += string;
65
+ }
66
+ return result;
67
+ }
68
+ function isNegativeZero(number) {
69
+ return number === 0 && Number.NEGATIVE_INFINITY === 1 / number;
70
+ }
71
+ var isNothing_1 = isNothing;
72
+ var isObject_1 = isObject;
73
+ var toArray_1 = toArray;
74
+ var repeat_1 = repeat;
75
+ var isNegativeZero_1 = isNegativeZero;
76
+ var extend_1 = extend;
77
+ var common = {
78
+ isNothing: isNothing_1,
79
+ isObject: isObject_1,
80
+ toArray: toArray_1,
81
+ repeat: repeat_1,
82
+ isNegativeZero: isNegativeZero_1,
83
+ extend: extend_1
84
+ };
85
+ function formatError(exception2, compact) {
86
+ var where = "", message = exception2.reason || "(unknown reason)";
87
+ if (!exception2.mark) return message;
88
+ if (exception2.mark.name) {
89
+ where += 'in "' + exception2.mark.name + '" ';
90
+ }
91
+ where += "(" + (exception2.mark.line + 1) + ":" + (exception2.mark.column + 1) + ")";
92
+ if (!compact && exception2.mark.snippet) {
93
+ where += "\n\n" + exception2.mark.snippet;
94
+ }
95
+ return message + " " + where;
96
+ }
97
+ function YAMLException$1(reason, mark) {
98
+ Error.call(this);
99
+ this.name = "YAMLException";
100
+ this.reason = reason;
101
+ this.mark = mark;
102
+ this.message = formatError(this, false);
103
+ if (Error.captureStackTrace) {
104
+ Error.captureStackTrace(this, this.constructor);
105
+ } else {
106
+ this.stack = new Error().stack || "";
107
+ }
108
+ }
109
+ YAMLException$1.prototype = Object.create(Error.prototype);
110
+ YAMLException$1.prototype.constructor = YAMLException$1;
111
+ YAMLException$1.prototype.toString = function toString(compact) {
112
+ return this.name + ": " + formatError(this, compact);
113
+ };
114
+ var exception = YAMLException$1;
115
+ function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
116
+ var head = "";
117
+ var tail = "";
118
+ var maxHalfLength = Math.floor(maxLineLength / 2) - 1;
119
+ if (position - lineStart > maxHalfLength) {
120
+ head = " ... ";
121
+ lineStart = position - maxHalfLength + head.length;
122
+ }
123
+ if (lineEnd - position > maxHalfLength) {
124
+ tail = " ...";
125
+ lineEnd = position + maxHalfLength - tail.length;
126
+ }
127
+ return {
128
+ str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "\u2192") + tail,
129
+ pos: position - lineStart + head.length
130
+ // relative position
131
+ };
132
+ }
133
+ function padStart(string, max) {
134
+ return common.repeat(" ", max - string.length) + string;
135
+ }
136
+ function makeSnippet(mark, options) {
137
+ options = Object.create(options || null);
138
+ if (!mark.buffer) return null;
139
+ if (!options.maxLength) options.maxLength = 79;
140
+ if (typeof options.indent !== "number") options.indent = 1;
141
+ if (typeof options.linesBefore !== "number") options.linesBefore = 3;
142
+ if (typeof options.linesAfter !== "number") options.linesAfter = 2;
143
+ var re = /\r?\n|\r|\0/g;
144
+ var lineStarts = [0];
145
+ var lineEnds = [];
146
+ var match;
147
+ var foundLineNo = -1;
148
+ while (match = re.exec(mark.buffer)) {
149
+ lineEnds.push(match.index);
150
+ lineStarts.push(match.index + match[0].length);
151
+ if (mark.position <= match.index && foundLineNo < 0) {
152
+ foundLineNo = lineStarts.length - 2;
153
+ }
154
+ }
155
+ if (foundLineNo < 0) foundLineNo = lineStarts.length - 1;
156
+ var result = "", i, line;
157
+ var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length;
158
+ var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3);
159
+ for (i = 1; i <= options.linesBefore; i++) {
160
+ if (foundLineNo - i < 0) break;
161
+ line = getLine(
162
+ mark.buffer,
163
+ lineStarts[foundLineNo - i],
164
+ lineEnds[foundLineNo - i],
165
+ mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]),
166
+ maxLineLength
167
+ );
168
+ result = common.repeat(" ", options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) + " | " + line.str + "\n" + result;
169
+ }
170
+ line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
171
+ result += common.repeat(" ", options.indent) + padStart((mark.line + 1).toString(), lineNoLength) + " | " + line.str + "\n";
172
+ result += common.repeat("-", options.indent + lineNoLength + 3 + line.pos) + "^\n";
173
+ for (i = 1; i <= options.linesAfter; i++) {
174
+ if (foundLineNo + i >= lineEnds.length) break;
175
+ line = getLine(
176
+ mark.buffer,
177
+ lineStarts[foundLineNo + i],
178
+ lineEnds[foundLineNo + i],
179
+ mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]),
180
+ maxLineLength
181
+ );
182
+ result += common.repeat(" ", options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) + " | " + line.str + "\n";
183
+ }
184
+ return result.replace(/\n$/, "");
185
+ }
186
+ var snippet = makeSnippet;
187
+ var TYPE_CONSTRUCTOR_OPTIONS = [
188
+ "kind",
189
+ "multi",
190
+ "resolve",
191
+ "construct",
192
+ "instanceOf",
193
+ "predicate",
194
+ "represent",
195
+ "representName",
196
+ "defaultStyle",
197
+ "styleAliases"
198
+ ];
199
+ var YAML_NODE_KINDS = [
200
+ "scalar",
201
+ "sequence",
202
+ "mapping"
203
+ ];
204
+ function compileStyleAliases(map2) {
205
+ var result = {};
206
+ if (map2 !== null) {
207
+ Object.keys(map2).forEach(function(style) {
208
+ map2[style].forEach(function(alias) {
209
+ result[String(alias)] = style;
210
+ });
211
+ });
212
+ }
213
+ return result;
214
+ }
215
+ function Type$1(tag, options) {
216
+ options = options || {};
217
+ Object.keys(options).forEach(function(name) {
218
+ if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
219
+ throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
220
+ }
44
221
  });
45
- const project = await detector.detectProject(opts.directory).catch(() => null);
46
- if (!project?.namespaceId)
47
- return { status: "no_provider", error: "Could not detect GitLab project" };
48
- const nsid = `gid://gitlab/Group/${project.namespaceId}`;
49
- const disc = new import_gitlab_ai_provider.GitLabModelDiscovery({
50
- instanceUrl: opts.instanceUrl,
51
- getHeaders: headers
222
+ this.options = options;
223
+ this.tag = tag;
224
+ this.kind = options["kind"] || null;
225
+ this.resolve = options["resolve"] || function() {
226
+ return true;
227
+ };
228
+ this.construct = options["construct"] || function(data) {
229
+ return data;
230
+ };
231
+ this.instanceOf = options["instanceOf"] || null;
232
+ this.predicate = options["predicate"] || null;
233
+ this.represent = options["represent"] || null;
234
+ this.representName = options["representName"] || null;
235
+ this.defaultStyle = options["defaultStyle"] || null;
236
+ this.multi = options["multi"] || false;
237
+ this.styleAliases = compileStyleAliases(options["styleAliases"] || null);
238
+ if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
239
+ throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
240
+ }
241
+ }
242
+ var type = Type$1;
243
+ function compileList(schema2, name) {
244
+ var result = [];
245
+ schema2[name].forEach(function(currentType) {
246
+ var newIndex = result.length;
247
+ result.forEach(function(previousType, previousIndex) {
248
+ if (previousType.tag === currentType.tag && previousType.kind === currentType.kind && previousType.multi === currentType.multi) {
249
+ newIndex = previousIndex;
250
+ }
251
+ });
252
+ result[newIndex] = currentType;
253
+ });
254
+ return result;
255
+ }
256
+ function compileMap() {
257
+ var result = {
258
+ scalar: {},
259
+ sequence: {},
260
+ mapping: {},
261
+ fallback: {},
262
+ multi: {
263
+ scalar: [],
264
+ sequence: [],
265
+ mapping: [],
266
+ fallback: []
267
+ }
268
+ }, index, length;
269
+ function collectType(type2) {
270
+ if (type2.multi) {
271
+ result.multi[type2.kind].push(type2);
272
+ result.multi["fallback"].push(type2);
273
+ } else {
274
+ result[type2.kind][type2.tag] = result["fallback"][type2.tag] = type2;
275
+ }
276
+ }
277
+ for (index = 0, length = arguments.length; index < length; index += 1) {
278
+ arguments[index].forEach(collectType);
279
+ }
280
+ return result;
281
+ }
282
+ function Schema$1(definition) {
283
+ return this.extend(definition);
284
+ }
285
+ Schema$1.prototype.extend = function extend2(definition) {
286
+ var implicit = [];
287
+ var explicit = [];
288
+ if (definition instanceof type) {
289
+ explicit.push(definition);
290
+ } else if (Array.isArray(definition)) {
291
+ explicit = explicit.concat(definition);
292
+ } else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) {
293
+ if (definition.implicit) implicit = implicit.concat(definition.implicit);
294
+ if (definition.explicit) explicit = explicit.concat(definition.explicit);
295
+ } else {
296
+ throw new exception("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");
297
+ }
298
+ implicit.forEach(function(type$1) {
299
+ if (!(type$1 instanceof type)) {
300
+ throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
301
+ }
302
+ if (type$1.loadKind && type$1.loadKind !== "scalar") {
303
+ throw new exception("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");
304
+ }
305
+ if (type$1.multi) {
306
+ throw new exception("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.");
307
+ }
52
308
  });
53
- const result = await disc.discover(nsid).catch(() => null);
54
- if (!result) return { status: "no_models" };
55
- discovery = result;
56
- const cache = new import_gitlab_ai_provider.GitLabModelCache(opts.directory, opts.instanceUrl);
57
- cache.saveDiscovery(result);
58
- if (result.pinnedModel) {
59
- cache.saveSelection(result.pinnedModel.ref, result.pinnedModel.name);
60
- return { status: "pinned", model: result.pinnedModel };
61
- }
62
- const cached = cache.load();
63
- if (cached?.selectedModelRef) {
64
- const match = result.selectableModels.find((m) => m.ref === cached.selectedModelRef);
65
- if (match) return { status: "cached", model: match };
66
- return {
67
- status: "cached",
68
- model: { name: cached.selectedModelRef, ref: cached.selectedModelRef }
69
- };
70
- }
71
- if (result.selectableModels.length > 0) {
72
- const models = result.selectableModels.map((m) => ({
73
- name: m.name,
74
- ref: m.ref,
75
- isDefault: result.defaultModel?.ref === m.ref
76
- }));
77
- return { status: "asked", models };
78
- }
79
- if (result.defaultModel) {
80
- cache.saveSelection(result.defaultModel.ref, result.defaultModel.name);
81
- return { status: "default", model: result.defaultModel };
82
- }
83
- return { status: "no_models" };
84
- }
85
- function saveSelection(opts) {
86
- const cache = new import_gitlab_ai_provider.GitLabModelCache(opts.directory, opts.instanceUrl);
87
- const model = discovery?.selectableModels.find((m) => m.ref === opts.ref);
88
- cache.saveSelection(opts.ref, model?.name ?? opts.ref);
89
- return { ref: opts.ref, name: model?.name ?? opts.ref };
90
- }
91
- function clearCache(opts) {
92
- const cache = new import_gitlab_ai_provider.GitLabModelCache(opts.directory, opts.instanceUrl);
93
- cache.clear();
94
- discovery = null;
309
+ explicit.forEach(function(type$1) {
310
+ if (!(type$1 instanceof type)) {
311
+ throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
312
+ }
313
+ });
314
+ var result = Object.create(Schema$1.prototype);
315
+ result.implicit = (this.implicit || []).concat(implicit);
316
+ result.explicit = (this.explicit || []).concat(explicit);
317
+ result.compiledImplicit = compileList(result, "implicit");
318
+ result.compiledExplicit = compileList(result, "explicit");
319
+ result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit);
320
+ return result;
321
+ };
322
+ var schema = Schema$1;
323
+ var str = new type("tag:yaml.org,2002:str", {
324
+ kind: "scalar",
325
+ construct: function(data) {
326
+ return data !== null ? data : "";
327
+ }
328
+ });
329
+ var seq = new type("tag:yaml.org,2002:seq", {
330
+ kind: "sequence",
331
+ construct: function(data) {
332
+ return data !== null ? data : [];
333
+ }
334
+ });
335
+ var map = new type("tag:yaml.org,2002:map", {
336
+ kind: "mapping",
337
+ construct: function(data) {
338
+ return data !== null ? data : {};
339
+ }
340
+ });
341
+ var failsafe = new schema({
342
+ explicit: [
343
+ str,
344
+ seq,
345
+ map
346
+ ]
347
+ });
348
+ function resolveYamlNull(data) {
349
+ if (data === null) return true;
350
+ var max = data.length;
351
+ return max === 1 && data === "~" || max === 4 && (data === "null" || data === "Null" || data === "NULL");
352
+ }
353
+ function constructYamlNull() {
354
+ return null;
355
+ }
356
+ function isNull(object) {
357
+ return object === null;
358
+ }
359
+ var _null = new type("tag:yaml.org,2002:null", {
360
+ kind: "scalar",
361
+ resolve: resolveYamlNull,
362
+ construct: constructYamlNull,
363
+ predicate: isNull,
364
+ represent: {
365
+ canonical: function() {
366
+ return "~";
367
+ },
368
+ lowercase: function() {
369
+ return "null";
370
+ },
371
+ uppercase: function() {
372
+ return "NULL";
373
+ },
374
+ camelcase: function() {
375
+ return "Null";
376
+ },
377
+ empty: function() {
378
+ return "";
379
+ }
380
+ },
381
+ defaultStyle: "lowercase"
382
+ });
383
+ function resolveYamlBoolean(data) {
384
+ if (data === null) return false;
385
+ var max = data.length;
386
+ return max === 4 && (data === "true" || data === "True" || data === "TRUE") || max === 5 && (data === "false" || data === "False" || data === "FALSE");
387
+ }
388
+ function constructYamlBoolean(data) {
389
+ return data === "true" || data === "True" || data === "TRUE";
390
+ }
391
+ function isBoolean(object) {
392
+ return Object.prototype.toString.call(object) === "[object Boolean]";
393
+ }
394
+ var bool = new type("tag:yaml.org,2002:bool", {
395
+ kind: "scalar",
396
+ resolve: resolveYamlBoolean,
397
+ construct: constructYamlBoolean,
398
+ predicate: isBoolean,
399
+ represent: {
400
+ lowercase: function(object) {
401
+ return object ? "true" : "false";
402
+ },
403
+ uppercase: function(object) {
404
+ return object ? "TRUE" : "FALSE";
405
+ },
406
+ camelcase: function(object) {
407
+ return object ? "True" : "False";
408
+ }
409
+ },
410
+ defaultStyle: "lowercase"
411
+ });
412
+ function isHexCode(c) {
413
+ return 48 <= c && c <= 57 || 65 <= c && c <= 70 || 97 <= c && c <= 102;
414
+ }
415
+ function isOctCode(c) {
416
+ return 48 <= c && c <= 55;
417
+ }
418
+ function isDecCode(c) {
419
+ return 48 <= c && c <= 57;
420
+ }
421
+ function resolveYamlInteger(data) {
422
+ if (data === null) return false;
423
+ var max = data.length, index = 0, hasDigits = false, ch;
424
+ if (!max) return false;
425
+ ch = data[index];
426
+ if (ch === "-" || ch === "+") {
427
+ ch = data[++index];
428
+ }
429
+ if (ch === "0") {
430
+ if (index + 1 === max) return true;
431
+ ch = data[++index];
432
+ if (ch === "b") {
433
+ index++;
434
+ for (; index < max; index++) {
435
+ ch = data[index];
436
+ if (ch === "_") continue;
437
+ if (ch !== "0" && ch !== "1") return false;
438
+ hasDigits = true;
439
+ }
440
+ return hasDigits && ch !== "_";
441
+ }
442
+ if (ch === "x") {
443
+ index++;
444
+ for (; index < max; index++) {
445
+ ch = data[index];
446
+ if (ch === "_") continue;
447
+ if (!isHexCode(data.charCodeAt(index))) return false;
448
+ hasDigits = true;
449
+ }
450
+ return hasDigits && ch !== "_";
451
+ }
452
+ if (ch === "o") {
453
+ index++;
454
+ for (; index < max; index++) {
455
+ ch = data[index];
456
+ if (ch === "_") continue;
457
+ if (!isOctCode(data.charCodeAt(index))) return false;
458
+ hasDigits = true;
459
+ }
460
+ return hasDigits && ch !== "_";
461
+ }
462
+ }
463
+ if (ch === "_") return false;
464
+ for (; index < max; index++) {
465
+ ch = data[index];
466
+ if (ch === "_") continue;
467
+ if (!isDecCode(data.charCodeAt(index))) {
468
+ return false;
469
+ }
470
+ hasDigits = true;
471
+ }
472
+ if (!hasDigits || ch === "_") return false;
473
+ return true;
474
+ }
475
+ function constructYamlInteger(data) {
476
+ var value = data, sign = 1, ch;
477
+ if (value.indexOf("_") !== -1) {
478
+ value = value.replace(/_/g, "");
479
+ }
480
+ ch = value[0];
481
+ if (ch === "-" || ch === "+") {
482
+ if (ch === "-") sign = -1;
483
+ value = value.slice(1);
484
+ ch = value[0];
485
+ }
486
+ if (value === "0") return 0;
487
+ if (ch === "0") {
488
+ if (value[1] === "b") return sign * parseInt(value.slice(2), 2);
489
+ if (value[1] === "x") return sign * parseInt(value.slice(2), 16);
490
+ if (value[1] === "o") return sign * parseInt(value.slice(2), 8);
491
+ }
492
+ return sign * parseInt(value, 10);
493
+ }
494
+ function isInteger(object) {
495
+ return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 === 0 && !common.isNegativeZero(object));
496
+ }
497
+ var int = new type("tag:yaml.org,2002:int", {
498
+ kind: "scalar",
499
+ resolve: resolveYamlInteger,
500
+ construct: constructYamlInteger,
501
+ predicate: isInteger,
502
+ represent: {
503
+ binary: function(obj) {
504
+ return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1);
505
+ },
506
+ octal: function(obj) {
507
+ return obj >= 0 ? "0o" + obj.toString(8) : "-0o" + obj.toString(8).slice(1);
508
+ },
509
+ decimal: function(obj) {
510
+ return obj.toString(10);
511
+ },
512
+ /* eslint-disable max-len */
513
+ hexadecimal: function(obj) {
514
+ return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1);
515
+ }
516
+ },
517
+ defaultStyle: "decimal",
518
+ styleAliases: {
519
+ binary: [2, "bin"],
520
+ octal: [8, "oct"],
521
+ decimal: [10, "dec"],
522
+ hexadecimal: [16, "hex"]
523
+ }
524
+ });
525
+ var YAML_FLOAT_PATTERN = new RegExp(
526
+ // 2.5e4, 2.5 and integers
527
+ "^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$"
528
+ );
529
+ function resolveYamlFloat(data) {
530
+ if (data === null) return false;
531
+ if (!YAML_FLOAT_PATTERN.test(data) || // Quick hack to not allow integers end with `_`
532
+ // Probably should update regexp & check speed
533
+ data[data.length - 1] === "_") {
534
+ return false;
535
+ }
536
+ return true;
537
+ }
538
+ function constructYamlFloat(data) {
539
+ var value, sign;
540
+ value = data.replace(/_/g, "").toLowerCase();
541
+ sign = value[0] === "-" ? -1 : 1;
542
+ if ("+-".indexOf(value[0]) >= 0) {
543
+ value = value.slice(1);
544
+ }
545
+ if (value === ".inf") {
546
+ return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
547
+ } else if (value === ".nan") {
548
+ return NaN;
549
+ }
550
+ return sign * parseFloat(value, 10);
551
+ }
552
+ var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
553
+ function representYamlFloat(object, style) {
554
+ var res;
555
+ if (isNaN(object)) {
556
+ switch (style) {
557
+ case "lowercase":
558
+ return ".nan";
559
+ case "uppercase":
560
+ return ".NAN";
561
+ case "camelcase":
562
+ return ".NaN";
563
+ }
564
+ } else if (Number.POSITIVE_INFINITY === object) {
565
+ switch (style) {
566
+ case "lowercase":
567
+ return ".inf";
568
+ case "uppercase":
569
+ return ".INF";
570
+ case "camelcase":
571
+ return ".Inf";
572
+ }
573
+ } else if (Number.NEGATIVE_INFINITY === object) {
574
+ switch (style) {
575
+ case "lowercase":
576
+ return "-.inf";
577
+ case "uppercase":
578
+ return "-.INF";
579
+ case "camelcase":
580
+ return "-.Inf";
581
+ }
582
+ } else if (common.isNegativeZero(object)) {
583
+ return "-0.0";
584
+ }
585
+ res = object.toString(10);
586
+ return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace("e", ".e") : res;
587
+ }
588
+ function isFloat(object) {
589
+ return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || common.isNegativeZero(object));
590
+ }
591
+ var float = new type("tag:yaml.org,2002:float", {
592
+ kind: "scalar",
593
+ resolve: resolveYamlFloat,
594
+ construct: constructYamlFloat,
595
+ predicate: isFloat,
596
+ represent: representYamlFloat,
597
+ defaultStyle: "lowercase"
598
+ });
599
+ var json = failsafe.extend({
600
+ implicit: [
601
+ _null,
602
+ bool,
603
+ int,
604
+ float
605
+ ]
606
+ });
607
+ var core = json;
608
+ var YAML_DATE_REGEXP = new RegExp(
609
+ "^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"
610
+ );
611
+ var YAML_TIMESTAMP_REGEXP = new RegExp(
612
+ "^([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]))?))?$"
613
+ );
614
+ function resolveYamlTimestamp(data) {
615
+ if (data === null) return false;
616
+ if (YAML_DATE_REGEXP.exec(data) !== null) return true;
617
+ if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
618
+ return false;
619
+ }
620
+ function constructYamlTimestamp(data) {
621
+ var match, year, month, day, hour, minute, second, fraction = 0, delta = null, tz_hour, tz_minute, date;
622
+ match = YAML_DATE_REGEXP.exec(data);
623
+ if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
624
+ if (match === null) throw new Error("Date resolve error");
625
+ year = +match[1];
626
+ month = +match[2] - 1;
627
+ day = +match[3];
628
+ if (!match[4]) {
629
+ return new Date(Date.UTC(year, month, day));
630
+ }
631
+ hour = +match[4];
632
+ minute = +match[5];
633
+ second = +match[6];
634
+ if (match[7]) {
635
+ fraction = match[7].slice(0, 3);
636
+ while (fraction.length < 3) {
637
+ fraction += "0";
638
+ }
639
+ fraction = +fraction;
640
+ }
641
+ if (match[9]) {
642
+ tz_hour = +match[10];
643
+ tz_minute = +(match[11] || 0);
644
+ delta = (tz_hour * 60 + tz_minute) * 6e4;
645
+ if (match[9] === "-") delta = -delta;
646
+ }
647
+ date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
648
+ if (delta) date.setTime(date.getTime() - delta);
649
+ return date;
650
+ }
651
+ function representYamlTimestamp(object) {
652
+ return object.toISOString();
653
+ }
654
+ var timestamp = new type("tag:yaml.org,2002:timestamp", {
655
+ kind: "scalar",
656
+ resolve: resolveYamlTimestamp,
657
+ construct: constructYamlTimestamp,
658
+ instanceOf: Date,
659
+ represent: representYamlTimestamp
660
+ });
661
+ function resolveYamlMerge(data) {
662
+ return data === "<<" || data === null;
663
+ }
664
+ var merge = new type("tag:yaml.org,2002:merge", {
665
+ kind: "scalar",
666
+ resolve: resolveYamlMerge
667
+ });
668
+ var BASE64_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";
669
+ function resolveYamlBinary(data) {
670
+ if (data === null) return false;
671
+ var code, idx, bitlen = 0, max = data.length, map2 = BASE64_MAP;
672
+ for (idx = 0; idx < max; idx++) {
673
+ code = map2.indexOf(data.charAt(idx));
674
+ if (code > 64) continue;
675
+ if (code < 0) return false;
676
+ bitlen += 6;
677
+ }
678
+ return bitlen % 8 === 0;
679
+ }
680
+ function constructYamlBinary(data) {
681
+ var idx, tailbits, input = data.replace(/[\r\n=]/g, ""), max = input.length, map2 = BASE64_MAP, bits = 0, result = [];
682
+ for (idx = 0; idx < max; idx++) {
683
+ if (idx % 4 === 0 && idx) {
684
+ result.push(bits >> 16 & 255);
685
+ result.push(bits >> 8 & 255);
686
+ result.push(bits & 255);
687
+ }
688
+ bits = bits << 6 | map2.indexOf(input.charAt(idx));
689
+ }
690
+ tailbits = max % 4 * 6;
691
+ if (tailbits === 0) {
692
+ result.push(bits >> 16 & 255);
693
+ result.push(bits >> 8 & 255);
694
+ result.push(bits & 255);
695
+ } else if (tailbits === 18) {
696
+ result.push(bits >> 10 & 255);
697
+ result.push(bits >> 2 & 255);
698
+ } else if (tailbits === 12) {
699
+ result.push(bits >> 4 & 255);
700
+ }
701
+ return new Uint8Array(result);
702
+ }
703
+ function representYamlBinary(object) {
704
+ var result = "", bits = 0, idx, tail, max = object.length, map2 = BASE64_MAP;
705
+ for (idx = 0; idx < max; idx++) {
706
+ if (idx % 3 === 0 && idx) {
707
+ result += map2[bits >> 18 & 63];
708
+ result += map2[bits >> 12 & 63];
709
+ result += map2[bits >> 6 & 63];
710
+ result += map2[bits & 63];
711
+ }
712
+ bits = (bits << 8) + object[idx];
713
+ }
714
+ tail = max % 3;
715
+ if (tail === 0) {
716
+ result += map2[bits >> 18 & 63];
717
+ result += map2[bits >> 12 & 63];
718
+ result += map2[bits >> 6 & 63];
719
+ result += map2[bits & 63];
720
+ } else if (tail === 2) {
721
+ result += map2[bits >> 10 & 63];
722
+ result += map2[bits >> 4 & 63];
723
+ result += map2[bits << 2 & 63];
724
+ result += map2[64];
725
+ } else if (tail === 1) {
726
+ result += map2[bits >> 2 & 63];
727
+ result += map2[bits << 4 & 63];
728
+ result += map2[64];
729
+ result += map2[64];
730
+ }
731
+ return result;
732
+ }
733
+ function isBinary(obj) {
734
+ return Object.prototype.toString.call(obj) === "[object Uint8Array]";
735
+ }
736
+ var binary = new type("tag:yaml.org,2002:binary", {
737
+ kind: "scalar",
738
+ resolve: resolveYamlBinary,
739
+ construct: constructYamlBinary,
740
+ predicate: isBinary,
741
+ represent: representYamlBinary
742
+ });
743
+ var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
744
+ var _toString$2 = Object.prototype.toString;
745
+ function resolveYamlOmap(data) {
746
+ if (data === null) return true;
747
+ var objectKeys = [], index, length, pair, pairKey, pairHasKey, object = data;
748
+ for (index = 0, length = object.length; index < length; index += 1) {
749
+ pair = object[index];
750
+ pairHasKey = false;
751
+ if (_toString$2.call(pair) !== "[object Object]") return false;
752
+ for (pairKey in pair) {
753
+ if (_hasOwnProperty$3.call(pair, pairKey)) {
754
+ if (!pairHasKey) pairHasKey = true;
755
+ else return false;
756
+ }
757
+ }
758
+ if (!pairHasKey) return false;
759
+ if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
760
+ else return false;
761
+ }
762
+ return true;
763
+ }
764
+ function constructYamlOmap(data) {
765
+ return data !== null ? data : [];
766
+ }
767
+ var omap = new type("tag:yaml.org,2002:omap", {
768
+ kind: "sequence",
769
+ resolve: resolveYamlOmap,
770
+ construct: constructYamlOmap
771
+ });
772
+ var _toString$1 = Object.prototype.toString;
773
+ function resolveYamlPairs(data) {
774
+ if (data === null) return true;
775
+ var index, length, pair, keys, result, object = data;
776
+ result = new Array(object.length);
777
+ for (index = 0, length = object.length; index < length; index += 1) {
778
+ pair = object[index];
779
+ if (_toString$1.call(pair) !== "[object Object]") return false;
780
+ keys = Object.keys(pair);
781
+ if (keys.length !== 1) return false;
782
+ result[index] = [keys[0], pair[keys[0]]];
783
+ }
784
+ return true;
785
+ }
786
+ function constructYamlPairs(data) {
787
+ if (data === null) return [];
788
+ var index, length, pair, keys, result, object = data;
789
+ result = new Array(object.length);
790
+ for (index = 0, length = object.length; index < length; index += 1) {
791
+ pair = object[index];
792
+ keys = Object.keys(pair);
793
+ result[index] = [keys[0], pair[keys[0]]];
794
+ }
795
+ return result;
796
+ }
797
+ var pairs = new type("tag:yaml.org,2002:pairs", {
798
+ kind: "sequence",
799
+ resolve: resolveYamlPairs,
800
+ construct: constructYamlPairs
801
+ });
802
+ var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
803
+ function resolveYamlSet(data) {
804
+ if (data === null) return true;
805
+ var key, object = data;
806
+ for (key in object) {
807
+ if (_hasOwnProperty$2.call(object, key)) {
808
+ if (object[key] !== null) return false;
809
+ }
810
+ }
811
+ return true;
812
+ }
813
+ function constructYamlSet(data) {
814
+ return data !== null ? data : {};
815
+ }
816
+ var set = new type("tag:yaml.org,2002:set", {
817
+ kind: "mapping",
818
+ resolve: resolveYamlSet,
819
+ construct: constructYamlSet
820
+ });
821
+ var _default = core.extend({
822
+ implicit: [
823
+ timestamp,
824
+ merge
825
+ ],
826
+ explicit: [
827
+ binary,
828
+ omap,
829
+ pairs,
830
+ set
831
+ ]
832
+ });
833
+ var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
834
+ var CONTEXT_FLOW_IN = 1;
835
+ var CONTEXT_FLOW_OUT = 2;
836
+ var CONTEXT_BLOCK_IN = 3;
837
+ var CONTEXT_BLOCK_OUT = 4;
838
+ var CHOMPING_CLIP = 1;
839
+ var CHOMPING_STRIP = 2;
840
+ var CHOMPING_KEEP = 3;
841
+ var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
842
+ var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
843
+ var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
844
+ var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
845
+ var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
846
+ function _class(obj) {
847
+ return Object.prototype.toString.call(obj);
848
+ }
849
+ function is_EOL(c) {
850
+ return c === 10 || c === 13;
851
+ }
852
+ function is_WHITE_SPACE(c) {
853
+ return c === 9 || c === 32;
854
+ }
855
+ function is_WS_OR_EOL(c) {
856
+ return c === 9 || c === 32 || c === 10 || c === 13;
857
+ }
858
+ function is_FLOW_INDICATOR(c) {
859
+ return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
860
+ }
861
+ function fromHexCode(c) {
862
+ var lc;
863
+ if (48 <= c && c <= 57) {
864
+ return c - 48;
865
+ }
866
+ lc = c | 32;
867
+ if (97 <= lc && lc <= 102) {
868
+ return lc - 97 + 10;
869
+ }
870
+ return -1;
871
+ }
872
+ function escapedHexLen(c) {
873
+ if (c === 120) {
874
+ return 2;
875
+ }
876
+ if (c === 117) {
877
+ return 4;
878
+ }
879
+ if (c === 85) {
880
+ return 8;
881
+ }
882
+ return 0;
883
+ }
884
+ function fromDecimalCode(c) {
885
+ if (48 <= c && c <= 57) {
886
+ return c - 48;
887
+ }
888
+ return -1;
889
+ }
890
+ function simpleEscapeSequence(c) {
891
+ 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" : "";
892
+ }
893
+ function charFromCodepoint(c) {
894
+ if (c <= 65535) {
895
+ return String.fromCharCode(c);
896
+ }
897
+ return String.fromCharCode(
898
+ (c - 65536 >> 10) + 55296,
899
+ (c - 65536 & 1023) + 56320
900
+ );
901
+ }
902
+ function setProperty(object, key, value) {
903
+ if (key === "__proto__") {
904
+ Object.defineProperty(object, key, {
905
+ configurable: true,
906
+ enumerable: true,
907
+ writable: true,
908
+ value
909
+ });
910
+ } else {
911
+ object[key] = value;
912
+ }
913
+ }
914
+ var simpleEscapeCheck = new Array(256);
915
+ var simpleEscapeMap = new Array(256);
916
+ for (i = 0; i < 256; i++) {
917
+ simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
918
+ simpleEscapeMap[i] = simpleEscapeSequence(i);
919
+ }
920
+ var i;
921
+ function State$1(input, options) {
922
+ this.input = input;
923
+ this.filename = options["filename"] || null;
924
+ this.schema = options["schema"] || _default;
925
+ this.onWarning = options["onWarning"] || null;
926
+ this.legacy = options["legacy"] || false;
927
+ this.json = options["json"] || false;
928
+ this.listener = options["listener"] || null;
929
+ this.implicitTypes = this.schema.compiledImplicit;
930
+ this.typeMap = this.schema.compiledTypeMap;
931
+ this.length = input.length;
932
+ this.position = 0;
933
+ this.line = 0;
934
+ this.lineStart = 0;
935
+ this.lineIndent = 0;
936
+ this.firstTabInLine = -1;
937
+ this.documents = [];
938
+ }
939
+ function generateError(state, message) {
940
+ var mark = {
941
+ name: state.filename,
942
+ buffer: state.input.slice(0, -1),
943
+ // omit trailing \0
944
+ position: state.position,
945
+ line: state.line,
946
+ column: state.position - state.lineStart
947
+ };
948
+ mark.snippet = snippet(mark);
949
+ return new exception(message, mark);
950
+ }
951
+ function throwError(state, message) {
952
+ throw generateError(state, message);
953
+ }
954
+ function throwWarning(state, message) {
955
+ if (state.onWarning) {
956
+ state.onWarning.call(null, generateError(state, message));
957
+ }
958
+ }
959
+ var directiveHandlers = {
960
+ YAML: function handleYamlDirective(state, name, args) {
961
+ var match, major, minor;
962
+ if (state.version !== null) {
963
+ throwError(state, "duplication of %YAML directive");
964
+ }
965
+ if (args.length !== 1) {
966
+ throwError(state, "YAML directive accepts exactly one argument");
967
+ }
968
+ match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
969
+ if (match === null) {
970
+ throwError(state, "ill-formed argument of the YAML directive");
971
+ }
972
+ major = parseInt(match[1], 10);
973
+ minor = parseInt(match[2], 10);
974
+ if (major !== 1) {
975
+ throwError(state, "unacceptable YAML version of the document");
976
+ }
977
+ state.version = args[0];
978
+ state.checkLineBreaks = minor < 2;
979
+ if (minor !== 1 && minor !== 2) {
980
+ throwWarning(state, "unsupported YAML version of the document");
981
+ }
982
+ },
983
+ TAG: function handleTagDirective(state, name, args) {
984
+ var handle, prefix;
985
+ if (args.length !== 2) {
986
+ throwError(state, "TAG directive accepts exactly two arguments");
987
+ }
988
+ handle = args[0];
989
+ prefix = args[1];
990
+ if (!PATTERN_TAG_HANDLE.test(handle)) {
991
+ throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
992
+ }
993
+ if (_hasOwnProperty$1.call(state.tagMap, handle)) {
994
+ throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
995
+ }
996
+ if (!PATTERN_TAG_URI.test(prefix)) {
997
+ throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
998
+ }
999
+ try {
1000
+ prefix = decodeURIComponent(prefix);
1001
+ } catch (err) {
1002
+ throwError(state, "tag prefix is malformed: " + prefix);
1003
+ }
1004
+ state.tagMap[handle] = prefix;
1005
+ }
1006
+ };
1007
+ function captureSegment(state, start, end, checkJson) {
1008
+ var _position, _length, _character, _result;
1009
+ if (start < end) {
1010
+ _result = state.input.slice(start, end);
1011
+ if (checkJson) {
1012
+ for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
1013
+ _character = _result.charCodeAt(_position);
1014
+ if (!(_character === 9 || 32 <= _character && _character <= 1114111)) {
1015
+ throwError(state, "expected valid JSON character");
1016
+ }
1017
+ }
1018
+ } else if (PATTERN_NON_PRINTABLE.test(_result)) {
1019
+ throwError(state, "the stream contains non-printable characters");
1020
+ }
1021
+ state.result += _result;
1022
+ }
1023
+ }
1024
+ function mergeMappings(state, destination, source, overridableKeys) {
1025
+ var sourceKeys, key, index, quantity;
1026
+ if (!common.isObject(source)) {
1027
+ throwError(state, "cannot merge mappings; the provided source object is unacceptable");
1028
+ }
1029
+ sourceKeys = Object.keys(source);
1030
+ for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
1031
+ key = sourceKeys[index];
1032
+ if (!_hasOwnProperty$1.call(destination, key)) {
1033
+ setProperty(destination, key, source[key]);
1034
+ overridableKeys[key] = true;
1035
+ }
1036
+ }
1037
+ }
1038
+ function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startLineStart, startPos) {
1039
+ var index, quantity;
1040
+ if (Array.isArray(keyNode)) {
1041
+ keyNode = Array.prototype.slice.call(keyNode);
1042
+ for (index = 0, quantity = keyNode.length; index < quantity; index += 1) {
1043
+ if (Array.isArray(keyNode[index])) {
1044
+ throwError(state, "nested arrays are not supported inside keys");
1045
+ }
1046
+ if (typeof keyNode === "object" && _class(keyNode[index]) === "[object Object]") {
1047
+ keyNode[index] = "[object Object]";
1048
+ }
1049
+ }
1050
+ }
1051
+ if (typeof keyNode === "object" && _class(keyNode) === "[object Object]") {
1052
+ keyNode = "[object Object]";
1053
+ }
1054
+ keyNode = String(keyNode);
1055
+ if (_result === null) {
1056
+ _result = {};
1057
+ }
1058
+ if (keyTag === "tag:yaml.org,2002:merge") {
1059
+ if (Array.isArray(valueNode)) {
1060
+ for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
1061
+ mergeMappings(state, _result, valueNode[index], overridableKeys);
1062
+ }
1063
+ } else {
1064
+ mergeMappings(state, _result, valueNode, overridableKeys);
1065
+ }
1066
+ } else {
1067
+ if (!state.json && !_hasOwnProperty$1.call(overridableKeys, keyNode) && _hasOwnProperty$1.call(_result, keyNode)) {
1068
+ state.line = startLine || state.line;
1069
+ state.lineStart = startLineStart || state.lineStart;
1070
+ state.position = startPos || state.position;
1071
+ throwError(state, "duplicated mapping key");
1072
+ }
1073
+ setProperty(_result, keyNode, valueNode);
1074
+ delete overridableKeys[keyNode];
1075
+ }
1076
+ return _result;
1077
+ }
1078
+ function readLineBreak(state) {
1079
+ var ch;
1080
+ ch = state.input.charCodeAt(state.position);
1081
+ if (ch === 10) {
1082
+ state.position++;
1083
+ } else if (ch === 13) {
1084
+ state.position++;
1085
+ if (state.input.charCodeAt(state.position) === 10) {
1086
+ state.position++;
1087
+ }
1088
+ } else {
1089
+ throwError(state, "a line break is expected");
1090
+ }
1091
+ state.line += 1;
1092
+ state.lineStart = state.position;
1093
+ state.firstTabInLine = -1;
1094
+ }
1095
+ function skipSeparationSpace(state, allowComments, checkIndent) {
1096
+ var lineBreaks = 0, ch = state.input.charCodeAt(state.position);
1097
+ while (ch !== 0) {
1098
+ while (is_WHITE_SPACE(ch)) {
1099
+ if (ch === 9 && state.firstTabInLine === -1) {
1100
+ state.firstTabInLine = state.position;
1101
+ }
1102
+ ch = state.input.charCodeAt(++state.position);
1103
+ }
1104
+ if (allowComments && ch === 35) {
1105
+ do {
1106
+ ch = state.input.charCodeAt(++state.position);
1107
+ } while (ch !== 10 && ch !== 13 && ch !== 0);
1108
+ }
1109
+ if (is_EOL(ch)) {
1110
+ readLineBreak(state);
1111
+ ch = state.input.charCodeAt(state.position);
1112
+ lineBreaks++;
1113
+ state.lineIndent = 0;
1114
+ while (ch === 32) {
1115
+ state.lineIndent++;
1116
+ ch = state.input.charCodeAt(++state.position);
1117
+ }
1118
+ } else {
1119
+ break;
1120
+ }
1121
+ }
1122
+ if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
1123
+ throwWarning(state, "deficient indentation");
1124
+ }
1125
+ return lineBreaks;
1126
+ }
1127
+ function testDocumentSeparator(state) {
1128
+ var _position = state.position, ch;
1129
+ ch = state.input.charCodeAt(_position);
1130
+ if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(_position + 1) && ch === state.input.charCodeAt(_position + 2)) {
1131
+ _position += 3;
1132
+ ch = state.input.charCodeAt(_position);
1133
+ if (ch === 0 || is_WS_OR_EOL(ch)) {
1134
+ return true;
1135
+ }
1136
+ }
1137
+ return false;
1138
+ }
1139
+ function writeFoldedLines(state, count) {
1140
+ if (count === 1) {
1141
+ state.result += " ";
1142
+ } else if (count > 1) {
1143
+ state.result += common.repeat("\n", count - 1);
1144
+ }
1145
+ }
1146
+ function readPlainScalar(state, nodeIndent, withinFlowCollection) {
1147
+ var preceding, following, captureStart, captureEnd, hasPendingContent, _line, _lineStart, _lineIndent, _kind = state.kind, _result = state.result, ch;
1148
+ ch = state.input.charCodeAt(state.position);
1149
+ 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) {
1150
+ return false;
1151
+ }
1152
+ if (ch === 63 || ch === 45) {
1153
+ following = state.input.charCodeAt(state.position + 1);
1154
+ if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
1155
+ return false;
1156
+ }
1157
+ }
1158
+ state.kind = "scalar";
1159
+ state.result = "";
1160
+ captureStart = captureEnd = state.position;
1161
+ hasPendingContent = false;
1162
+ while (ch !== 0) {
1163
+ if (ch === 58) {
1164
+ following = state.input.charCodeAt(state.position + 1);
1165
+ if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
1166
+ break;
1167
+ }
1168
+ } else if (ch === 35) {
1169
+ preceding = state.input.charCodeAt(state.position - 1);
1170
+ if (is_WS_OR_EOL(preceding)) {
1171
+ break;
1172
+ }
1173
+ } else if (state.position === state.lineStart && testDocumentSeparator(state) || withinFlowCollection && is_FLOW_INDICATOR(ch)) {
1174
+ break;
1175
+ } else if (is_EOL(ch)) {
1176
+ _line = state.line;
1177
+ _lineStart = state.lineStart;
1178
+ _lineIndent = state.lineIndent;
1179
+ skipSeparationSpace(state, false, -1);
1180
+ if (state.lineIndent >= nodeIndent) {
1181
+ hasPendingContent = true;
1182
+ ch = state.input.charCodeAt(state.position);
1183
+ continue;
1184
+ } else {
1185
+ state.position = captureEnd;
1186
+ state.line = _line;
1187
+ state.lineStart = _lineStart;
1188
+ state.lineIndent = _lineIndent;
1189
+ break;
1190
+ }
1191
+ }
1192
+ if (hasPendingContent) {
1193
+ captureSegment(state, captureStart, captureEnd, false);
1194
+ writeFoldedLines(state, state.line - _line);
1195
+ captureStart = captureEnd = state.position;
1196
+ hasPendingContent = false;
1197
+ }
1198
+ if (!is_WHITE_SPACE(ch)) {
1199
+ captureEnd = state.position + 1;
1200
+ }
1201
+ ch = state.input.charCodeAt(++state.position);
1202
+ }
1203
+ captureSegment(state, captureStart, captureEnd, false);
1204
+ if (state.result) {
1205
+ return true;
1206
+ }
1207
+ state.kind = _kind;
1208
+ state.result = _result;
1209
+ return false;
1210
+ }
1211
+ function readSingleQuotedScalar(state, nodeIndent) {
1212
+ var ch, captureStart, captureEnd;
1213
+ ch = state.input.charCodeAt(state.position);
1214
+ if (ch !== 39) {
1215
+ return false;
1216
+ }
1217
+ state.kind = "scalar";
1218
+ state.result = "";
1219
+ state.position++;
1220
+ captureStart = captureEnd = state.position;
1221
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
1222
+ if (ch === 39) {
1223
+ captureSegment(state, captureStart, state.position, true);
1224
+ ch = state.input.charCodeAt(++state.position);
1225
+ if (ch === 39) {
1226
+ captureStart = state.position;
1227
+ state.position++;
1228
+ captureEnd = state.position;
1229
+ } else {
1230
+ return true;
1231
+ }
1232
+ } else if (is_EOL(ch)) {
1233
+ captureSegment(state, captureStart, captureEnd, true);
1234
+ writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
1235
+ captureStart = captureEnd = state.position;
1236
+ } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
1237
+ throwError(state, "unexpected end of the document within a single quoted scalar");
1238
+ } else {
1239
+ state.position++;
1240
+ captureEnd = state.position;
1241
+ }
1242
+ }
1243
+ throwError(state, "unexpected end of the stream within a single quoted scalar");
1244
+ }
1245
+ function readDoubleQuotedScalar(state, nodeIndent) {
1246
+ var captureStart, captureEnd, hexLength, hexResult, tmp, ch;
1247
+ ch = state.input.charCodeAt(state.position);
1248
+ if (ch !== 34) {
1249
+ return false;
1250
+ }
1251
+ state.kind = "scalar";
1252
+ state.result = "";
1253
+ state.position++;
1254
+ captureStart = captureEnd = state.position;
1255
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
1256
+ if (ch === 34) {
1257
+ captureSegment(state, captureStart, state.position, true);
1258
+ state.position++;
1259
+ return true;
1260
+ } else if (ch === 92) {
1261
+ captureSegment(state, captureStart, state.position, true);
1262
+ ch = state.input.charCodeAt(++state.position);
1263
+ if (is_EOL(ch)) {
1264
+ skipSeparationSpace(state, false, nodeIndent);
1265
+ } else if (ch < 256 && simpleEscapeCheck[ch]) {
1266
+ state.result += simpleEscapeMap[ch];
1267
+ state.position++;
1268
+ } else if ((tmp = escapedHexLen(ch)) > 0) {
1269
+ hexLength = tmp;
1270
+ hexResult = 0;
1271
+ for (; hexLength > 0; hexLength--) {
1272
+ ch = state.input.charCodeAt(++state.position);
1273
+ if ((tmp = fromHexCode(ch)) >= 0) {
1274
+ hexResult = (hexResult << 4) + tmp;
1275
+ } else {
1276
+ throwError(state, "expected hexadecimal character");
1277
+ }
1278
+ }
1279
+ state.result += charFromCodepoint(hexResult);
1280
+ state.position++;
1281
+ } else {
1282
+ throwError(state, "unknown escape sequence");
1283
+ }
1284
+ captureStart = captureEnd = state.position;
1285
+ } else if (is_EOL(ch)) {
1286
+ captureSegment(state, captureStart, captureEnd, true);
1287
+ writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
1288
+ captureStart = captureEnd = state.position;
1289
+ } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
1290
+ throwError(state, "unexpected end of the document within a double quoted scalar");
1291
+ } else {
1292
+ state.position++;
1293
+ captureEnd = state.position;
1294
+ }
1295
+ }
1296
+ throwError(state, "unexpected end of the stream within a double quoted scalar");
1297
+ }
1298
+ function readFlowCollection(state, nodeIndent) {
1299
+ 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;
1300
+ ch = state.input.charCodeAt(state.position);
1301
+ if (ch === 91) {
1302
+ terminator = 93;
1303
+ isMapping = false;
1304
+ _result = [];
1305
+ } else if (ch === 123) {
1306
+ terminator = 125;
1307
+ isMapping = true;
1308
+ _result = {};
1309
+ } else {
1310
+ return false;
1311
+ }
1312
+ if (state.anchor !== null) {
1313
+ state.anchorMap[state.anchor] = _result;
1314
+ }
1315
+ ch = state.input.charCodeAt(++state.position);
1316
+ while (ch !== 0) {
1317
+ skipSeparationSpace(state, true, nodeIndent);
1318
+ ch = state.input.charCodeAt(state.position);
1319
+ if (ch === terminator) {
1320
+ state.position++;
1321
+ state.tag = _tag;
1322
+ state.anchor = _anchor;
1323
+ state.kind = isMapping ? "mapping" : "sequence";
1324
+ state.result = _result;
1325
+ return true;
1326
+ } else if (!readNext) {
1327
+ throwError(state, "missed comma between flow collection entries");
1328
+ } else if (ch === 44) {
1329
+ throwError(state, "expected the node content, but found ','");
1330
+ }
1331
+ keyTag = keyNode = valueNode = null;
1332
+ isPair = isExplicitPair = false;
1333
+ if (ch === 63) {
1334
+ following = state.input.charCodeAt(state.position + 1);
1335
+ if (is_WS_OR_EOL(following)) {
1336
+ isPair = isExplicitPair = true;
1337
+ state.position++;
1338
+ skipSeparationSpace(state, true, nodeIndent);
1339
+ }
1340
+ }
1341
+ _line = state.line;
1342
+ _lineStart = state.lineStart;
1343
+ _pos = state.position;
1344
+ composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
1345
+ keyTag = state.tag;
1346
+ keyNode = state.result;
1347
+ skipSeparationSpace(state, true, nodeIndent);
1348
+ ch = state.input.charCodeAt(state.position);
1349
+ if ((isExplicitPair || state.line === _line) && ch === 58) {
1350
+ isPair = true;
1351
+ ch = state.input.charCodeAt(++state.position);
1352
+ skipSeparationSpace(state, true, nodeIndent);
1353
+ composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
1354
+ valueNode = state.result;
1355
+ }
1356
+ if (isMapping) {
1357
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos);
1358
+ } else if (isPair) {
1359
+ _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos));
1360
+ } else {
1361
+ _result.push(keyNode);
1362
+ }
1363
+ skipSeparationSpace(state, true, nodeIndent);
1364
+ ch = state.input.charCodeAt(state.position);
1365
+ if (ch === 44) {
1366
+ readNext = true;
1367
+ ch = state.input.charCodeAt(++state.position);
1368
+ } else {
1369
+ readNext = false;
1370
+ }
1371
+ }
1372
+ throwError(state, "unexpected end of the stream within a flow collection");
1373
+ }
1374
+ function readBlockScalar(state, nodeIndent) {
1375
+ var captureStart, folding, chomping = CHOMPING_CLIP, didReadContent = false, detectedIndent = false, textIndent = nodeIndent, emptyLines = 0, atMoreIndented = false, tmp, ch;
1376
+ ch = state.input.charCodeAt(state.position);
1377
+ if (ch === 124) {
1378
+ folding = false;
1379
+ } else if (ch === 62) {
1380
+ folding = true;
1381
+ } else {
1382
+ return false;
1383
+ }
1384
+ state.kind = "scalar";
1385
+ state.result = "";
1386
+ while (ch !== 0) {
1387
+ ch = state.input.charCodeAt(++state.position);
1388
+ if (ch === 43 || ch === 45) {
1389
+ if (CHOMPING_CLIP === chomping) {
1390
+ chomping = ch === 43 ? CHOMPING_KEEP : CHOMPING_STRIP;
1391
+ } else {
1392
+ throwError(state, "repeat of a chomping mode identifier");
1393
+ }
1394
+ } else if ((tmp = fromDecimalCode(ch)) >= 0) {
1395
+ if (tmp === 0) {
1396
+ throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
1397
+ } else if (!detectedIndent) {
1398
+ textIndent = nodeIndent + tmp - 1;
1399
+ detectedIndent = true;
1400
+ } else {
1401
+ throwError(state, "repeat of an indentation width identifier");
1402
+ }
1403
+ } else {
1404
+ break;
1405
+ }
1406
+ }
1407
+ if (is_WHITE_SPACE(ch)) {
1408
+ do {
1409
+ ch = state.input.charCodeAt(++state.position);
1410
+ } while (is_WHITE_SPACE(ch));
1411
+ if (ch === 35) {
1412
+ do {
1413
+ ch = state.input.charCodeAt(++state.position);
1414
+ } while (!is_EOL(ch) && ch !== 0);
1415
+ }
1416
+ }
1417
+ while (ch !== 0) {
1418
+ readLineBreak(state);
1419
+ state.lineIndent = 0;
1420
+ ch = state.input.charCodeAt(state.position);
1421
+ while ((!detectedIndent || state.lineIndent < textIndent) && ch === 32) {
1422
+ state.lineIndent++;
1423
+ ch = state.input.charCodeAt(++state.position);
1424
+ }
1425
+ if (!detectedIndent && state.lineIndent > textIndent) {
1426
+ textIndent = state.lineIndent;
1427
+ }
1428
+ if (is_EOL(ch)) {
1429
+ emptyLines++;
1430
+ continue;
1431
+ }
1432
+ if (state.lineIndent < textIndent) {
1433
+ if (chomping === CHOMPING_KEEP) {
1434
+ state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
1435
+ } else if (chomping === CHOMPING_CLIP) {
1436
+ if (didReadContent) {
1437
+ state.result += "\n";
1438
+ }
1439
+ }
1440
+ break;
1441
+ }
1442
+ if (folding) {
1443
+ if (is_WHITE_SPACE(ch)) {
1444
+ atMoreIndented = true;
1445
+ state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
1446
+ } else if (atMoreIndented) {
1447
+ atMoreIndented = false;
1448
+ state.result += common.repeat("\n", emptyLines + 1);
1449
+ } else if (emptyLines === 0) {
1450
+ if (didReadContent) {
1451
+ state.result += " ";
1452
+ }
1453
+ } else {
1454
+ state.result += common.repeat("\n", emptyLines);
1455
+ }
1456
+ } else {
1457
+ state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
1458
+ }
1459
+ didReadContent = true;
1460
+ detectedIndent = true;
1461
+ emptyLines = 0;
1462
+ captureStart = state.position;
1463
+ while (!is_EOL(ch) && ch !== 0) {
1464
+ ch = state.input.charCodeAt(++state.position);
1465
+ }
1466
+ captureSegment(state, captureStart, state.position, false);
1467
+ }
1468
+ return true;
1469
+ }
1470
+ function readBlockSequence(state, nodeIndent) {
1471
+ var _line, _tag = state.tag, _anchor = state.anchor, _result = [], following, detected = false, ch;
1472
+ if (state.firstTabInLine !== -1) return false;
1473
+ if (state.anchor !== null) {
1474
+ state.anchorMap[state.anchor] = _result;
1475
+ }
1476
+ ch = state.input.charCodeAt(state.position);
1477
+ while (ch !== 0) {
1478
+ if (state.firstTabInLine !== -1) {
1479
+ state.position = state.firstTabInLine;
1480
+ throwError(state, "tab characters must not be used in indentation");
1481
+ }
1482
+ if (ch !== 45) {
1483
+ break;
1484
+ }
1485
+ following = state.input.charCodeAt(state.position + 1);
1486
+ if (!is_WS_OR_EOL(following)) {
1487
+ break;
1488
+ }
1489
+ detected = true;
1490
+ state.position++;
1491
+ if (skipSeparationSpace(state, true, -1)) {
1492
+ if (state.lineIndent <= nodeIndent) {
1493
+ _result.push(null);
1494
+ ch = state.input.charCodeAt(state.position);
1495
+ continue;
1496
+ }
1497
+ }
1498
+ _line = state.line;
1499
+ composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
1500
+ _result.push(state.result);
1501
+ skipSeparationSpace(state, true, -1);
1502
+ ch = state.input.charCodeAt(state.position);
1503
+ if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
1504
+ throwError(state, "bad indentation of a sequence entry");
1505
+ } else if (state.lineIndent < nodeIndent) {
1506
+ break;
1507
+ }
1508
+ }
1509
+ if (detected) {
1510
+ state.tag = _tag;
1511
+ state.anchor = _anchor;
1512
+ state.kind = "sequence";
1513
+ state.result = _result;
1514
+ return true;
1515
+ }
1516
+ return false;
95
1517
  }
96
-
97
- // src/routes.ts
98
- function auth(c) {
99
- return {
100
- token: c.req.header("x-plugin-auth-token") || "",
101
- instanceUrl: c.req.header("x-plugin-auth-instance") || process.env.GITLAB_INSTANCE_URL || "https://gitlab.com",
102
- directory: c.req.header("x-plugin-directory") || process.cwd()
103
- };
1518
+ function readBlockMapping(state, nodeIndent, flowIndent) {
1519
+ 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;
1520
+ if (state.firstTabInLine !== -1) return false;
1521
+ if (state.anchor !== null) {
1522
+ state.anchorMap[state.anchor] = _result;
1523
+ }
1524
+ ch = state.input.charCodeAt(state.position);
1525
+ while (ch !== 0) {
1526
+ if (!atExplicitKey && state.firstTabInLine !== -1) {
1527
+ state.position = state.firstTabInLine;
1528
+ throwError(state, "tab characters must not be used in indentation");
1529
+ }
1530
+ following = state.input.charCodeAt(state.position + 1);
1531
+ _line = state.line;
1532
+ if ((ch === 63 || ch === 58) && is_WS_OR_EOL(following)) {
1533
+ if (ch === 63) {
1534
+ if (atExplicitKey) {
1535
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
1536
+ keyTag = keyNode = valueNode = null;
1537
+ }
1538
+ detected = true;
1539
+ atExplicitKey = true;
1540
+ allowCompact = true;
1541
+ } else if (atExplicitKey) {
1542
+ atExplicitKey = false;
1543
+ allowCompact = true;
1544
+ } else {
1545
+ throwError(state, "incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line");
1546
+ }
1547
+ state.position += 1;
1548
+ ch = following;
1549
+ } else {
1550
+ _keyLine = state.line;
1551
+ _keyLineStart = state.lineStart;
1552
+ _keyPos = state.position;
1553
+ if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
1554
+ break;
1555
+ }
1556
+ if (state.line === _line) {
1557
+ ch = state.input.charCodeAt(state.position);
1558
+ while (is_WHITE_SPACE(ch)) {
1559
+ ch = state.input.charCodeAt(++state.position);
1560
+ }
1561
+ if (ch === 58) {
1562
+ ch = state.input.charCodeAt(++state.position);
1563
+ if (!is_WS_OR_EOL(ch)) {
1564
+ throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
1565
+ }
1566
+ if (atExplicitKey) {
1567
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
1568
+ keyTag = keyNode = valueNode = null;
1569
+ }
1570
+ detected = true;
1571
+ atExplicitKey = false;
1572
+ allowCompact = false;
1573
+ keyTag = state.tag;
1574
+ keyNode = state.result;
1575
+ } else if (detected) {
1576
+ throwError(state, "can not read an implicit mapping pair; a colon is missed");
1577
+ } else {
1578
+ state.tag = _tag;
1579
+ state.anchor = _anchor;
1580
+ return true;
1581
+ }
1582
+ } else if (detected) {
1583
+ throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
1584
+ } else {
1585
+ state.tag = _tag;
1586
+ state.anchor = _anchor;
1587
+ return true;
1588
+ }
1589
+ }
1590
+ if (state.line === _line || state.lineIndent > nodeIndent) {
1591
+ if (atExplicitKey) {
1592
+ _keyLine = state.line;
1593
+ _keyLineStart = state.lineStart;
1594
+ _keyPos = state.position;
1595
+ }
1596
+ if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
1597
+ if (atExplicitKey) {
1598
+ keyNode = state.result;
1599
+ } else {
1600
+ valueNode = state.result;
1601
+ }
1602
+ }
1603
+ if (!atExplicitKey) {
1604
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineStart, _keyPos);
1605
+ keyTag = keyNode = valueNode = null;
1606
+ }
1607
+ skipSeparationSpace(state, true, -1);
1608
+ ch = state.input.charCodeAt(state.position);
1609
+ }
1610
+ if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
1611
+ throwError(state, "bad indentation of a mapping entry");
1612
+ } else if (state.lineIndent < nodeIndent) {
1613
+ break;
1614
+ }
1615
+ }
1616
+ if (atExplicitKey) {
1617
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
1618
+ }
1619
+ if (detected) {
1620
+ state.tag = _tag;
1621
+ state.anchor = _anchor;
1622
+ state.kind = "mapping";
1623
+ state.result = _result;
1624
+ }
1625
+ return detected;
104
1626
  }
105
- function routes(ctx) {
106
- return (app) => {
107
- app.post("/discover", async (c) => {
108
- try {
109
- const hdr = auth(c);
110
- const body = await c.req.json().catch(() => ({}));
111
- const cred = hdr.token ? hdr : await ctx.creds();
112
- if (!cred?.token)
113
- return c.json({
114
- status: "no_provider",
115
- error: "No auth token found"
116
- });
117
- const result = await discover({
118
- token: cred.token,
119
- instanceUrl: cred.instanceUrl,
120
- directory: hdr.directory,
121
- fresh: body.fresh
122
- });
123
- if (result.status === "asked" && result.models) {
124
- const value = await ctx.askUser(result.models);
125
- if (value) {
126
- saveSelection({
127
- ref: value,
128
- directory: hdr.directory,
129
- instanceUrl: cred.instanceUrl
130
- });
131
- const match = result.models.find((m) => m.ref === value);
132
- return c.json({
133
- status: "selected",
134
- model: { name: match?.name ?? value, ref: value }
135
- });
1627
+ function readTagProperty(state) {
1628
+ var _position, isVerbatim = false, isNamed = false, tagHandle, tagName, ch;
1629
+ ch = state.input.charCodeAt(state.position);
1630
+ if (ch !== 33) return false;
1631
+ if (state.tag !== null) {
1632
+ throwError(state, "duplication of a tag property");
1633
+ }
1634
+ ch = state.input.charCodeAt(++state.position);
1635
+ if (ch === 60) {
1636
+ isVerbatim = true;
1637
+ ch = state.input.charCodeAt(++state.position);
1638
+ } else if (ch === 33) {
1639
+ isNamed = true;
1640
+ tagHandle = "!!";
1641
+ ch = state.input.charCodeAt(++state.position);
1642
+ } else {
1643
+ tagHandle = "!";
1644
+ }
1645
+ _position = state.position;
1646
+ if (isVerbatim) {
1647
+ do {
1648
+ ch = state.input.charCodeAt(++state.position);
1649
+ } while (ch !== 0 && ch !== 62);
1650
+ if (state.position < state.length) {
1651
+ tagName = state.input.slice(_position, state.position);
1652
+ ch = state.input.charCodeAt(++state.position);
1653
+ } else {
1654
+ throwError(state, "unexpected end of the stream within a verbatim tag");
1655
+ }
1656
+ } else {
1657
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
1658
+ if (ch === 33) {
1659
+ if (!isNamed) {
1660
+ tagHandle = state.input.slice(_position - 1, state.position + 1);
1661
+ if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
1662
+ throwError(state, "named tag handle cannot contain such characters");
136
1663
  }
137
- return c.json({ status: "dismissed" });
1664
+ isNamed = true;
1665
+ _position = state.position + 1;
1666
+ } else {
1667
+ throwError(state, "tag suffix cannot contain exclamation marks");
138
1668
  }
139
- return c.json(result);
140
- } catch (e) {
141
- return c.json({ status: "error", error: e?.message ?? String(e) });
142
1669
  }
1670
+ ch = state.input.charCodeAt(++state.position);
1671
+ }
1672
+ tagName = state.input.slice(_position, state.position);
1673
+ if (PATTERN_FLOW_INDICATORS.test(tagName)) {
1674
+ throwError(state, "tag suffix cannot contain flow indicator characters");
1675
+ }
1676
+ }
1677
+ if (tagName && !PATTERN_TAG_URI.test(tagName)) {
1678
+ throwError(state, "tag name cannot contain such characters: " + tagName);
1679
+ }
1680
+ try {
1681
+ tagName = decodeURIComponent(tagName);
1682
+ } catch (err) {
1683
+ throwError(state, "tag name is malformed: " + tagName);
1684
+ }
1685
+ if (isVerbatim) {
1686
+ state.tag = tagName;
1687
+ } else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) {
1688
+ state.tag = state.tagMap[tagHandle] + tagName;
1689
+ } else if (tagHandle === "!") {
1690
+ state.tag = "!" + tagName;
1691
+ } else if (tagHandle === "!!") {
1692
+ state.tag = "tag:yaml.org,2002:" + tagName;
1693
+ } else {
1694
+ throwError(state, 'undeclared tag handle "' + tagHandle + '"');
1695
+ }
1696
+ return true;
1697
+ }
1698
+ function readAnchorProperty(state) {
1699
+ var _position, ch;
1700
+ ch = state.input.charCodeAt(state.position);
1701
+ if (ch !== 38) return false;
1702
+ if (state.anchor !== null) {
1703
+ throwError(state, "duplication of an anchor property");
1704
+ }
1705
+ ch = state.input.charCodeAt(++state.position);
1706
+ _position = state.position;
1707
+ while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
1708
+ ch = state.input.charCodeAt(++state.position);
1709
+ }
1710
+ if (state.position === _position) {
1711
+ throwError(state, "name of an anchor node must contain at least one character");
1712
+ }
1713
+ state.anchor = state.input.slice(_position, state.position);
1714
+ return true;
1715
+ }
1716
+ function readAlias(state) {
1717
+ var _position, alias, ch;
1718
+ ch = state.input.charCodeAt(state.position);
1719
+ if (ch !== 42) return false;
1720
+ ch = state.input.charCodeAt(++state.position);
1721
+ _position = state.position;
1722
+ while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
1723
+ ch = state.input.charCodeAt(++state.position);
1724
+ }
1725
+ if (state.position === _position) {
1726
+ throwError(state, "name of an alias node must contain at least one character");
1727
+ }
1728
+ alias = state.input.slice(_position, state.position);
1729
+ if (!_hasOwnProperty$1.call(state.anchorMap, alias)) {
1730
+ throwError(state, 'unidentified alias "' + alias + '"');
1731
+ }
1732
+ state.result = state.anchorMap[alias];
1733
+ skipSeparationSpace(state, true, -1);
1734
+ return true;
1735
+ }
1736
+ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
1737
+ var allowBlockStyles, allowBlockScalars, allowBlockCollections, indentStatus = 1, atNewLine = false, hasContent = false, typeIndex, typeQuantity, typeList, type2, flowIndent, blockIndent;
1738
+ if (state.listener !== null) {
1739
+ state.listener("open", state);
1740
+ }
1741
+ state.tag = null;
1742
+ state.anchor = null;
1743
+ state.kind = null;
1744
+ state.result = null;
1745
+ allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext;
1746
+ if (allowToSeek) {
1747
+ if (skipSeparationSpace(state, true, -1)) {
1748
+ atNewLine = true;
1749
+ if (state.lineIndent > parentIndent) {
1750
+ indentStatus = 1;
1751
+ } else if (state.lineIndent === parentIndent) {
1752
+ indentStatus = 0;
1753
+ } else if (state.lineIndent < parentIndent) {
1754
+ indentStatus = -1;
1755
+ }
1756
+ }
1757
+ }
1758
+ if (indentStatus === 1) {
1759
+ while (readTagProperty(state) || readAnchorProperty(state)) {
1760
+ if (skipSeparationSpace(state, true, -1)) {
1761
+ atNewLine = true;
1762
+ allowBlockCollections = allowBlockStyles;
1763
+ if (state.lineIndent > parentIndent) {
1764
+ indentStatus = 1;
1765
+ } else if (state.lineIndent === parentIndent) {
1766
+ indentStatus = 0;
1767
+ } else if (state.lineIndent < parentIndent) {
1768
+ indentStatus = -1;
1769
+ }
1770
+ } else {
1771
+ allowBlockCollections = false;
1772
+ }
1773
+ }
1774
+ }
1775
+ if (allowBlockCollections) {
1776
+ allowBlockCollections = atNewLine || allowCompact;
1777
+ }
1778
+ if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
1779
+ if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
1780
+ flowIndent = parentIndent;
1781
+ } else {
1782
+ flowIndent = parentIndent + 1;
1783
+ }
1784
+ blockIndent = state.position - state.lineStart;
1785
+ if (indentStatus === 1) {
1786
+ if (allowBlockCollections && (readBlockSequence(state, blockIndent) || readBlockMapping(state, blockIndent, flowIndent)) || readFlowCollection(state, flowIndent)) {
1787
+ hasContent = true;
1788
+ } else {
1789
+ if (allowBlockScalars && readBlockScalar(state, flowIndent) || readSingleQuotedScalar(state, flowIndent) || readDoubleQuotedScalar(state, flowIndent)) {
1790
+ hasContent = true;
1791
+ } else if (readAlias(state)) {
1792
+ hasContent = true;
1793
+ if (state.tag !== null || state.anchor !== null) {
1794
+ throwError(state, "alias node should not have any properties");
1795
+ }
1796
+ } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
1797
+ hasContent = true;
1798
+ if (state.tag === null) {
1799
+ state.tag = "?";
1800
+ }
1801
+ }
1802
+ if (state.anchor !== null) {
1803
+ state.anchorMap[state.anchor] = state.result;
1804
+ }
1805
+ }
1806
+ } else if (indentStatus === 0) {
1807
+ hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
1808
+ }
1809
+ }
1810
+ if (state.tag === null) {
1811
+ if (state.anchor !== null) {
1812
+ state.anchorMap[state.anchor] = state.result;
1813
+ }
1814
+ } else if (state.tag === "?") {
1815
+ if (state.result !== null && state.kind !== "scalar") {
1816
+ throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
1817
+ }
1818
+ for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
1819
+ type2 = state.implicitTypes[typeIndex];
1820
+ if (type2.resolve(state.result)) {
1821
+ state.result = type2.construct(state.result);
1822
+ state.tag = type2.tag;
1823
+ if (state.anchor !== null) {
1824
+ state.anchorMap[state.anchor] = state.result;
1825
+ }
1826
+ break;
1827
+ }
1828
+ }
1829
+ } else if (state.tag !== "!") {
1830
+ if (_hasOwnProperty$1.call(state.typeMap[state.kind || "fallback"], state.tag)) {
1831
+ type2 = state.typeMap[state.kind || "fallback"][state.tag];
1832
+ } else {
1833
+ type2 = null;
1834
+ typeList = state.typeMap.multi[state.kind || "fallback"];
1835
+ for (typeIndex = 0, typeQuantity = typeList.length; typeIndex < typeQuantity; typeIndex += 1) {
1836
+ if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) {
1837
+ type2 = typeList[typeIndex];
1838
+ break;
1839
+ }
1840
+ }
1841
+ }
1842
+ if (!type2) {
1843
+ throwError(state, "unknown tag !<" + state.tag + ">");
1844
+ }
1845
+ if (state.result !== null && type2.kind !== state.kind) {
1846
+ throwError(state, "unacceptable node kind for !<" + state.tag + '> tag; it should be "' + type2.kind + '", not "' + state.kind + '"');
1847
+ }
1848
+ if (!type2.resolve(state.result, state.tag)) {
1849
+ throwError(state, "cannot resolve a node with !<" + state.tag + "> explicit tag");
1850
+ } else {
1851
+ state.result = type2.construct(state.result, state.tag);
1852
+ if (state.anchor !== null) {
1853
+ state.anchorMap[state.anchor] = state.result;
1854
+ }
1855
+ }
1856
+ }
1857
+ if (state.listener !== null) {
1858
+ state.listener("close", state);
1859
+ }
1860
+ return state.tag !== null || state.anchor !== null || hasContent;
1861
+ }
1862
+ function readDocument(state) {
1863
+ var documentStart = state.position, _position, directiveName, directiveArgs, hasDirectives = false, ch;
1864
+ state.version = null;
1865
+ state.checkLineBreaks = state.legacy;
1866
+ state.tagMap = /* @__PURE__ */ Object.create(null);
1867
+ state.anchorMap = /* @__PURE__ */ Object.create(null);
1868
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
1869
+ skipSeparationSpace(state, true, -1);
1870
+ ch = state.input.charCodeAt(state.position);
1871
+ if (state.lineIndent > 0 || ch !== 37) {
1872
+ break;
1873
+ }
1874
+ hasDirectives = true;
1875
+ ch = state.input.charCodeAt(++state.position);
1876
+ _position = state.position;
1877
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
1878
+ ch = state.input.charCodeAt(++state.position);
1879
+ }
1880
+ directiveName = state.input.slice(_position, state.position);
1881
+ directiveArgs = [];
1882
+ if (directiveName.length < 1) {
1883
+ throwError(state, "directive name must not be less than one character in length");
1884
+ }
1885
+ while (ch !== 0) {
1886
+ while (is_WHITE_SPACE(ch)) {
1887
+ ch = state.input.charCodeAt(++state.position);
1888
+ }
1889
+ if (ch === 35) {
1890
+ do {
1891
+ ch = state.input.charCodeAt(++state.position);
1892
+ } while (ch !== 0 && !is_EOL(ch));
1893
+ break;
1894
+ }
1895
+ if (is_EOL(ch)) break;
1896
+ _position = state.position;
1897
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
1898
+ ch = state.input.charCodeAt(++state.position);
1899
+ }
1900
+ directiveArgs.push(state.input.slice(_position, state.position));
1901
+ }
1902
+ if (ch !== 0) readLineBreak(state);
1903
+ if (_hasOwnProperty$1.call(directiveHandlers, directiveName)) {
1904
+ directiveHandlers[directiveName](state, directiveName, directiveArgs);
1905
+ } else {
1906
+ throwWarning(state, 'unknown document directive "' + directiveName + '"');
1907
+ }
1908
+ }
1909
+ skipSeparationSpace(state, true, -1);
1910
+ if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45) {
1911
+ state.position += 3;
1912
+ skipSeparationSpace(state, true, -1);
1913
+ } else if (hasDirectives) {
1914
+ throwError(state, "directives end mark is expected");
1915
+ }
1916
+ composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
1917
+ skipSeparationSpace(state, true, -1);
1918
+ if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
1919
+ throwWarning(state, "non-ASCII line breaks are interpreted as content");
1920
+ }
1921
+ state.documents.push(state.result);
1922
+ if (state.position === state.lineStart && testDocumentSeparator(state)) {
1923
+ if (state.input.charCodeAt(state.position) === 46) {
1924
+ state.position += 3;
1925
+ skipSeparationSpace(state, true, -1);
1926
+ }
1927
+ return;
1928
+ }
1929
+ if (state.position < state.length - 1) {
1930
+ throwError(state, "end of the stream or a document separator is expected");
1931
+ } else {
1932
+ return;
1933
+ }
1934
+ }
1935
+ function loadDocuments(input, options) {
1936
+ input = String(input);
1937
+ options = options || {};
1938
+ if (input.length !== 0) {
1939
+ if (input.charCodeAt(input.length - 1) !== 10 && input.charCodeAt(input.length - 1) !== 13) {
1940
+ input += "\n";
1941
+ }
1942
+ if (input.charCodeAt(0) === 65279) {
1943
+ input = input.slice(1);
1944
+ }
1945
+ }
1946
+ var state = new State$1(input, options);
1947
+ var nullpos = input.indexOf("\0");
1948
+ if (nullpos !== -1) {
1949
+ state.position = nullpos;
1950
+ throwError(state, "null byte is not allowed in input");
1951
+ }
1952
+ state.input += "\0";
1953
+ while (state.input.charCodeAt(state.position) === 32) {
1954
+ state.lineIndent += 1;
1955
+ state.position += 1;
1956
+ }
1957
+ while (state.position < state.length - 1) {
1958
+ readDocument(state);
1959
+ }
1960
+ return state.documents;
1961
+ }
1962
+ function loadAll$1(input, iterator, options) {
1963
+ if (iterator !== null && typeof iterator === "object" && typeof options === "undefined") {
1964
+ options = iterator;
1965
+ iterator = null;
1966
+ }
1967
+ var documents = loadDocuments(input, options);
1968
+ if (typeof iterator !== "function") {
1969
+ return documents;
1970
+ }
1971
+ for (var index = 0, length = documents.length; index < length; index += 1) {
1972
+ iterator(documents[index]);
1973
+ }
1974
+ }
1975
+ function load$1(input, options) {
1976
+ var documents = loadDocuments(input, options);
1977
+ if (documents.length === 0) {
1978
+ return void 0;
1979
+ } else if (documents.length === 1) {
1980
+ return documents[0];
1981
+ }
1982
+ throw new exception("expected a single document in the stream, but found more");
1983
+ }
1984
+ var loadAll_1 = loadAll$1;
1985
+ var load_1 = load$1;
1986
+ var loader = {
1987
+ loadAll: loadAll_1,
1988
+ load: load_1
1989
+ };
1990
+ var _toString = Object.prototype.toString;
1991
+ var _hasOwnProperty = Object.prototype.hasOwnProperty;
1992
+ var CHAR_BOM = 65279;
1993
+ var CHAR_TAB = 9;
1994
+ var CHAR_LINE_FEED = 10;
1995
+ var CHAR_CARRIAGE_RETURN = 13;
1996
+ var CHAR_SPACE = 32;
1997
+ var CHAR_EXCLAMATION = 33;
1998
+ var CHAR_DOUBLE_QUOTE = 34;
1999
+ var CHAR_SHARP = 35;
2000
+ var CHAR_PERCENT = 37;
2001
+ var CHAR_AMPERSAND = 38;
2002
+ var CHAR_SINGLE_QUOTE = 39;
2003
+ var CHAR_ASTERISK = 42;
2004
+ var CHAR_COMMA = 44;
2005
+ var CHAR_MINUS = 45;
2006
+ var CHAR_COLON = 58;
2007
+ var CHAR_EQUALS = 61;
2008
+ var CHAR_GREATER_THAN = 62;
2009
+ var CHAR_QUESTION = 63;
2010
+ var CHAR_COMMERCIAL_AT = 64;
2011
+ var CHAR_LEFT_SQUARE_BRACKET = 91;
2012
+ var CHAR_RIGHT_SQUARE_BRACKET = 93;
2013
+ var CHAR_GRAVE_ACCENT = 96;
2014
+ var CHAR_LEFT_CURLY_BRACKET = 123;
2015
+ var CHAR_VERTICAL_LINE = 124;
2016
+ var CHAR_RIGHT_CURLY_BRACKET = 125;
2017
+ var ESCAPE_SEQUENCES = {};
2018
+ ESCAPE_SEQUENCES[0] = "\\0";
2019
+ ESCAPE_SEQUENCES[7] = "\\a";
2020
+ ESCAPE_SEQUENCES[8] = "\\b";
2021
+ ESCAPE_SEQUENCES[9] = "\\t";
2022
+ ESCAPE_SEQUENCES[10] = "\\n";
2023
+ ESCAPE_SEQUENCES[11] = "\\v";
2024
+ ESCAPE_SEQUENCES[12] = "\\f";
2025
+ ESCAPE_SEQUENCES[13] = "\\r";
2026
+ ESCAPE_SEQUENCES[27] = "\\e";
2027
+ ESCAPE_SEQUENCES[34] = '\\"';
2028
+ ESCAPE_SEQUENCES[92] = "\\\\";
2029
+ ESCAPE_SEQUENCES[133] = "\\N";
2030
+ ESCAPE_SEQUENCES[160] = "\\_";
2031
+ ESCAPE_SEQUENCES[8232] = "\\L";
2032
+ ESCAPE_SEQUENCES[8233] = "\\P";
2033
+ var DEPRECATED_BOOLEANS_SYNTAX = [
2034
+ "y",
2035
+ "Y",
2036
+ "yes",
2037
+ "Yes",
2038
+ "YES",
2039
+ "on",
2040
+ "On",
2041
+ "ON",
2042
+ "n",
2043
+ "N",
2044
+ "no",
2045
+ "No",
2046
+ "NO",
2047
+ "off",
2048
+ "Off",
2049
+ "OFF"
2050
+ ];
2051
+ var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;
2052
+ function compileStyleMap(schema2, map2) {
2053
+ var result, keys, index, length, tag, style, type2;
2054
+ if (map2 === null) return {};
2055
+ result = {};
2056
+ keys = Object.keys(map2);
2057
+ for (index = 0, length = keys.length; index < length; index += 1) {
2058
+ tag = keys[index];
2059
+ style = String(map2[tag]);
2060
+ if (tag.slice(0, 2) === "!!") {
2061
+ tag = "tag:yaml.org,2002:" + tag.slice(2);
2062
+ }
2063
+ type2 = schema2.compiledTypeMap["fallback"][tag];
2064
+ if (type2 && _hasOwnProperty.call(type2.styleAliases, style)) {
2065
+ style = type2.styleAliases[style];
2066
+ }
2067
+ result[tag] = style;
2068
+ }
2069
+ return result;
2070
+ }
2071
+ function encodeHex(character) {
2072
+ var string, handle, length;
2073
+ string = character.toString(16).toUpperCase();
2074
+ if (character <= 255) {
2075
+ handle = "x";
2076
+ length = 2;
2077
+ } else if (character <= 65535) {
2078
+ handle = "u";
2079
+ length = 4;
2080
+ } else if (character <= 4294967295) {
2081
+ handle = "U";
2082
+ length = 8;
2083
+ } else {
2084
+ throw new exception("code point within a string may not be greater than 0xFFFFFFFF");
2085
+ }
2086
+ return "\\" + handle + common.repeat("0", length - string.length) + string;
2087
+ }
2088
+ var QUOTING_TYPE_SINGLE = 1;
2089
+ var QUOTING_TYPE_DOUBLE = 2;
2090
+ function State(options) {
2091
+ this.schema = options["schema"] || _default;
2092
+ this.indent = Math.max(1, options["indent"] || 2);
2093
+ this.noArrayIndent = options["noArrayIndent"] || false;
2094
+ this.skipInvalid = options["skipInvalid"] || false;
2095
+ this.flowLevel = common.isNothing(options["flowLevel"]) ? -1 : options["flowLevel"];
2096
+ this.styleMap = compileStyleMap(this.schema, options["styles"] || null);
2097
+ this.sortKeys = options["sortKeys"] || false;
2098
+ this.lineWidth = options["lineWidth"] || 80;
2099
+ this.noRefs = options["noRefs"] || false;
2100
+ this.noCompatMode = options["noCompatMode"] || false;
2101
+ this.condenseFlow = options["condenseFlow"] || false;
2102
+ this.quotingType = options["quotingType"] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE;
2103
+ this.forceQuotes = options["forceQuotes"] || false;
2104
+ this.replacer = typeof options["replacer"] === "function" ? options["replacer"] : null;
2105
+ this.implicitTypes = this.schema.compiledImplicit;
2106
+ this.explicitTypes = this.schema.compiledExplicit;
2107
+ this.tag = null;
2108
+ this.result = "";
2109
+ this.duplicates = [];
2110
+ this.usedDuplicates = null;
2111
+ }
2112
+ function indentString(string, spaces) {
2113
+ var ind = common.repeat(" ", spaces), position = 0, next = -1, result = "", line, length = string.length;
2114
+ while (position < length) {
2115
+ next = string.indexOf("\n", position);
2116
+ if (next === -1) {
2117
+ line = string.slice(position);
2118
+ position = length;
2119
+ } else {
2120
+ line = string.slice(position, next + 1);
2121
+ position = next + 1;
2122
+ }
2123
+ if (line.length && line !== "\n") result += ind;
2124
+ result += line;
2125
+ }
2126
+ return result;
2127
+ }
2128
+ function generateNextLine(state, level) {
2129
+ return "\n" + common.repeat(" ", state.indent * level);
2130
+ }
2131
+ function testImplicitResolving(state, str2) {
2132
+ var index, length, type2;
2133
+ for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
2134
+ type2 = state.implicitTypes[index];
2135
+ if (type2.resolve(str2)) {
2136
+ return true;
2137
+ }
2138
+ }
2139
+ return false;
2140
+ }
2141
+ function isWhitespace(c) {
2142
+ return c === CHAR_SPACE || c === CHAR_TAB;
2143
+ }
2144
+ function isPrintable(c) {
2145
+ return 32 <= c && c <= 126 || 161 <= c && c <= 55295 && c !== 8232 && c !== 8233 || 57344 <= c && c <= 65533 && c !== CHAR_BOM || 65536 <= c && c <= 1114111;
2146
+ }
2147
+ function isNsCharOrWhitespace(c) {
2148
+ return isPrintable(c) && c !== CHAR_BOM && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED;
2149
+ }
2150
+ function isPlainSafe(c, prev, inblock) {
2151
+ var cIsNsCharOrWhitespace = isNsCharOrWhitespace(c);
2152
+ var cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c);
2153
+ return (
2154
+ // ns-plain-safe
2155
+ (inblock ? (
2156
+ // c = flow-in
2157
+ cIsNsCharOrWhitespace
2158
+ ) : 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
2159
+ );
2160
+ }
2161
+ function isPlainSafeFirst(c) {
2162
+ 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;
2163
+ }
2164
+ function isPlainSafeLast(c) {
2165
+ return !isWhitespace(c) && c !== CHAR_COLON;
2166
+ }
2167
+ function codePointAt(string, pos) {
2168
+ var first = string.charCodeAt(pos), second;
2169
+ if (first >= 55296 && first <= 56319 && pos + 1 < string.length) {
2170
+ second = string.charCodeAt(pos + 1);
2171
+ if (second >= 56320 && second <= 57343) {
2172
+ return (first - 55296) * 1024 + second - 56320 + 65536;
2173
+ }
2174
+ }
2175
+ return first;
2176
+ }
2177
+ function needIndentIndicator(string) {
2178
+ var leadingSpaceRe = /^\n* /;
2179
+ return leadingSpaceRe.test(string);
2180
+ }
2181
+ var STYLE_PLAIN = 1;
2182
+ var STYLE_SINGLE = 2;
2183
+ var STYLE_LITERAL = 3;
2184
+ var STYLE_FOLDED = 4;
2185
+ var STYLE_DOUBLE = 5;
2186
+ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType, quotingType, forceQuotes, inblock) {
2187
+ var i;
2188
+ var char = 0;
2189
+ var prevChar = null;
2190
+ var hasLineBreak = false;
2191
+ var hasFoldableLine = false;
2192
+ var shouldTrackWidth = lineWidth !== -1;
2193
+ var previousLineBreak = -1;
2194
+ var plain = isPlainSafeFirst(codePointAt(string, 0)) && isPlainSafeLast(codePointAt(string, string.length - 1));
2195
+ if (singleLineOnly || forceQuotes) {
2196
+ for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
2197
+ char = codePointAt(string, i);
2198
+ if (!isPrintable(char)) {
2199
+ return STYLE_DOUBLE;
2200
+ }
2201
+ plain = plain && isPlainSafe(char, prevChar, inblock);
2202
+ prevChar = char;
2203
+ }
2204
+ } else {
2205
+ for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
2206
+ char = codePointAt(string, i);
2207
+ if (char === CHAR_LINE_FEED) {
2208
+ hasLineBreak = true;
2209
+ if (shouldTrackWidth) {
2210
+ hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented.
2211
+ i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
2212
+ previousLineBreak = i;
2213
+ }
2214
+ } else if (!isPrintable(char)) {
2215
+ return STYLE_DOUBLE;
2216
+ }
2217
+ plain = plain && isPlainSafe(char, prevChar, inblock);
2218
+ prevChar = char;
2219
+ }
2220
+ hasFoldableLine = hasFoldableLine || shouldTrackWidth && (i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ");
2221
+ }
2222
+ if (!hasLineBreak && !hasFoldableLine) {
2223
+ if (plain && !forceQuotes && !testAmbiguousType(string)) {
2224
+ return STYLE_PLAIN;
2225
+ }
2226
+ return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
2227
+ }
2228
+ if (indentPerLevel > 9 && needIndentIndicator(string)) {
2229
+ return STYLE_DOUBLE;
2230
+ }
2231
+ if (!forceQuotes) {
2232
+ return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
2233
+ }
2234
+ return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
2235
+ }
2236
+ function writeScalar(state, string, level, iskey, inblock) {
2237
+ state.dump = (function() {
2238
+ if (string.length === 0) {
2239
+ return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''";
2240
+ }
2241
+ if (!state.noCompatMode) {
2242
+ if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) {
2243
+ return state.quotingType === QUOTING_TYPE_DOUBLE ? '"' + string + '"' : "'" + string + "'";
2244
+ }
2245
+ }
2246
+ var indent = state.indent * Math.max(1, level);
2247
+ var lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
2248
+ var singleLineOnly = iskey || state.flowLevel > -1 && level >= state.flowLevel;
2249
+ function testAmbiguity(string2) {
2250
+ return testImplicitResolving(state, string2);
2251
+ }
2252
+ switch (chooseScalarStyle(
2253
+ string,
2254
+ singleLineOnly,
2255
+ state.indent,
2256
+ lineWidth,
2257
+ testAmbiguity,
2258
+ state.quotingType,
2259
+ state.forceQuotes && !iskey,
2260
+ inblock
2261
+ )) {
2262
+ case STYLE_PLAIN:
2263
+ return string;
2264
+ case STYLE_SINGLE:
2265
+ return "'" + string.replace(/'/g, "''") + "'";
2266
+ case STYLE_LITERAL:
2267
+ return "|" + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
2268
+ case STYLE_FOLDED:
2269
+ return ">" + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
2270
+ case STYLE_DOUBLE:
2271
+ return '"' + escapeString(string) + '"';
2272
+ default:
2273
+ throw new exception("impossible error: invalid scalar style");
2274
+ }
2275
+ })();
2276
+ }
2277
+ function blockHeader(string, indentPerLevel) {
2278
+ var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
2279
+ var clip = string[string.length - 1] === "\n";
2280
+ var keep = clip && (string[string.length - 2] === "\n" || string === "\n");
2281
+ var chomp = keep ? "+" : clip ? "" : "-";
2282
+ return indentIndicator + chomp + "\n";
2283
+ }
2284
+ function dropEndingNewline(string) {
2285
+ return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
2286
+ }
2287
+ function foldString(string, width) {
2288
+ var lineRe = /(\n+)([^\n]*)/g;
2289
+ var result = (function() {
2290
+ var nextLF = string.indexOf("\n");
2291
+ nextLF = nextLF !== -1 ? nextLF : string.length;
2292
+ lineRe.lastIndex = nextLF;
2293
+ return foldLine(string.slice(0, nextLF), width);
2294
+ })();
2295
+ var prevMoreIndented = string[0] === "\n" || string[0] === " ";
2296
+ var moreIndented;
2297
+ var match;
2298
+ while (match = lineRe.exec(string)) {
2299
+ var prefix = match[1], line = match[2];
2300
+ moreIndented = line[0] === " ";
2301
+ result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
2302
+ prevMoreIndented = moreIndented;
2303
+ }
2304
+ return result;
2305
+ }
2306
+ function foldLine(line, width) {
2307
+ if (line === "" || line[0] === " ") return line;
2308
+ var breakRe = / [^ ]/g;
2309
+ var match;
2310
+ var start = 0, end, curr = 0, next = 0;
2311
+ var result = "";
2312
+ while (match = breakRe.exec(line)) {
2313
+ next = match.index;
2314
+ if (next - start > width) {
2315
+ end = curr > start ? curr : next;
2316
+ result += "\n" + line.slice(start, end);
2317
+ start = end + 1;
2318
+ }
2319
+ curr = next;
2320
+ }
2321
+ result += "\n";
2322
+ if (line.length - start > width && curr > start) {
2323
+ result += line.slice(start, curr) + "\n" + line.slice(curr + 1);
2324
+ } else {
2325
+ result += line.slice(start);
2326
+ }
2327
+ return result.slice(1);
2328
+ }
2329
+ function escapeString(string) {
2330
+ var result = "";
2331
+ var char = 0;
2332
+ var escapeSeq;
2333
+ for (var i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
2334
+ char = codePointAt(string, i);
2335
+ escapeSeq = ESCAPE_SEQUENCES[char];
2336
+ if (!escapeSeq && isPrintable(char)) {
2337
+ result += string[i];
2338
+ if (char >= 65536) result += string[i + 1];
2339
+ } else {
2340
+ result += escapeSeq || encodeHex(char);
2341
+ }
2342
+ }
2343
+ return result;
2344
+ }
2345
+ function writeFlowSequence(state, level, object) {
2346
+ var _result = "", _tag = state.tag, index, length, value;
2347
+ for (index = 0, length = object.length; index < length; index += 1) {
2348
+ value = object[index];
2349
+ if (state.replacer) {
2350
+ value = state.replacer.call(object, String(index), value);
2351
+ }
2352
+ if (writeNode(state, level, value, false, false) || typeof value === "undefined" && writeNode(state, level, null, false, false)) {
2353
+ if (_result !== "") _result += "," + (!state.condenseFlow ? " " : "");
2354
+ _result += state.dump;
2355
+ }
2356
+ }
2357
+ state.tag = _tag;
2358
+ state.dump = "[" + _result + "]";
2359
+ }
2360
+ function writeBlockSequence(state, level, object, compact) {
2361
+ var _result = "", _tag = state.tag, index, length, value;
2362
+ for (index = 0, length = object.length; index < length; index += 1) {
2363
+ value = object[index];
2364
+ if (state.replacer) {
2365
+ value = state.replacer.call(object, String(index), value);
2366
+ }
2367
+ if (writeNode(state, level + 1, value, true, true, false, true) || typeof value === "undefined" && writeNode(state, level + 1, null, true, true, false, true)) {
2368
+ if (!compact || _result !== "") {
2369
+ _result += generateNextLine(state, level);
2370
+ }
2371
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
2372
+ _result += "-";
2373
+ } else {
2374
+ _result += "- ";
2375
+ }
2376
+ _result += state.dump;
2377
+ }
2378
+ }
2379
+ state.tag = _tag;
2380
+ state.dump = _result || "[]";
2381
+ }
2382
+ function writeFlowMapping(state, level, object) {
2383
+ var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, pairBuffer;
2384
+ for (index = 0, length = objectKeyList.length; index < length; index += 1) {
2385
+ pairBuffer = "";
2386
+ if (_result !== "") pairBuffer += ", ";
2387
+ if (state.condenseFlow) pairBuffer += '"';
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, objectKey, false, false)) {
2394
+ continue;
2395
+ }
2396
+ if (state.dump.length > 1024) pairBuffer += "? ";
2397
+ pairBuffer += state.dump + (state.condenseFlow ? '"' : "") + ":" + (state.condenseFlow ? "" : " ");
2398
+ if (!writeNode(state, level, objectValue, false, false)) {
2399
+ continue;
2400
+ }
2401
+ pairBuffer += state.dump;
2402
+ _result += pairBuffer;
2403
+ }
2404
+ state.tag = _tag;
2405
+ state.dump = "{" + _result + "}";
2406
+ }
2407
+ function writeBlockMapping(state, level, object, compact) {
2408
+ var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, explicitPair, pairBuffer;
2409
+ if (state.sortKeys === true) {
2410
+ objectKeyList.sort();
2411
+ } else if (typeof state.sortKeys === "function") {
2412
+ objectKeyList.sort(state.sortKeys);
2413
+ } else if (state.sortKeys) {
2414
+ throw new exception("sortKeys must be a boolean or a function");
2415
+ }
2416
+ for (index = 0, length = objectKeyList.length; index < length; index += 1) {
2417
+ pairBuffer = "";
2418
+ if (!compact || _result !== "") {
2419
+ pairBuffer += generateNextLine(state, level);
2420
+ }
2421
+ objectKey = objectKeyList[index];
2422
+ objectValue = object[objectKey];
2423
+ if (state.replacer) {
2424
+ objectValue = state.replacer.call(object, objectKey, objectValue);
2425
+ }
2426
+ if (!writeNode(state, level + 1, objectKey, true, true, true)) {
2427
+ continue;
2428
+ }
2429
+ explicitPair = state.tag !== null && state.tag !== "?" || state.dump && state.dump.length > 1024;
2430
+ if (explicitPair) {
2431
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
2432
+ pairBuffer += "?";
2433
+ } else {
2434
+ pairBuffer += "? ";
2435
+ }
2436
+ }
2437
+ pairBuffer += state.dump;
2438
+ if (explicitPair) {
2439
+ pairBuffer += generateNextLine(state, level);
2440
+ }
2441
+ if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
2442
+ continue;
2443
+ }
2444
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
2445
+ pairBuffer += ":";
2446
+ } else {
2447
+ pairBuffer += ": ";
2448
+ }
2449
+ pairBuffer += state.dump;
2450
+ _result += pairBuffer;
2451
+ }
2452
+ state.tag = _tag;
2453
+ state.dump = _result || "{}";
2454
+ }
2455
+ function detectType(state, object, explicit) {
2456
+ var _result, typeList, index, length, type2, style;
2457
+ typeList = explicit ? state.explicitTypes : state.implicitTypes;
2458
+ for (index = 0, length = typeList.length; index < length; index += 1) {
2459
+ type2 = typeList[index];
2460
+ if ((type2.instanceOf || type2.predicate) && (!type2.instanceOf || typeof object === "object" && object instanceof type2.instanceOf) && (!type2.predicate || type2.predicate(object))) {
2461
+ if (explicit) {
2462
+ if (type2.multi && type2.representName) {
2463
+ state.tag = type2.representName(object);
2464
+ } else {
2465
+ state.tag = type2.tag;
2466
+ }
2467
+ } else {
2468
+ state.tag = "?";
2469
+ }
2470
+ if (type2.represent) {
2471
+ style = state.styleMap[type2.tag] || type2.defaultStyle;
2472
+ if (_toString.call(type2.represent) === "[object Function]") {
2473
+ _result = type2.represent(object, style);
2474
+ } else if (_hasOwnProperty.call(type2.represent, style)) {
2475
+ _result = type2.represent[style](object, style);
2476
+ } else {
2477
+ throw new exception("!<" + type2.tag + '> tag resolver accepts not "' + style + '" style');
2478
+ }
2479
+ state.dump = _result;
2480
+ }
2481
+ return true;
2482
+ }
2483
+ }
2484
+ return false;
2485
+ }
2486
+ function writeNode(state, level, object, block, compact, iskey, isblockseq) {
2487
+ state.tag = null;
2488
+ state.dump = object;
2489
+ if (!detectType(state, object, false)) {
2490
+ detectType(state, object, true);
2491
+ }
2492
+ var type2 = _toString.call(state.dump);
2493
+ var inblock = block;
2494
+ var tagStr;
2495
+ if (block) {
2496
+ block = state.flowLevel < 0 || state.flowLevel > level;
2497
+ }
2498
+ var objectOrArray = type2 === "[object Object]" || type2 === "[object Array]", duplicateIndex, duplicate;
2499
+ if (objectOrArray) {
2500
+ duplicateIndex = state.duplicates.indexOf(object);
2501
+ duplicate = duplicateIndex !== -1;
2502
+ }
2503
+ if (state.tag !== null && state.tag !== "?" || duplicate || state.indent !== 2 && level > 0) {
2504
+ compact = false;
2505
+ }
2506
+ if (duplicate && state.usedDuplicates[duplicateIndex]) {
2507
+ state.dump = "*ref_" + duplicateIndex;
2508
+ } else {
2509
+ if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
2510
+ state.usedDuplicates[duplicateIndex] = true;
2511
+ }
2512
+ if (type2 === "[object Object]") {
2513
+ if (block && Object.keys(state.dump).length !== 0) {
2514
+ writeBlockMapping(state, level, state.dump, compact);
2515
+ if (duplicate) {
2516
+ state.dump = "&ref_" + duplicateIndex + state.dump;
2517
+ }
2518
+ } else {
2519
+ writeFlowMapping(state, level, state.dump);
2520
+ if (duplicate) {
2521
+ state.dump = "&ref_" + duplicateIndex + " " + state.dump;
2522
+ }
2523
+ }
2524
+ } else if (type2 === "[object Array]") {
2525
+ if (block && state.dump.length !== 0) {
2526
+ if (state.noArrayIndent && !isblockseq && level > 0) {
2527
+ writeBlockSequence(state, level - 1, state.dump, compact);
2528
+ } else {
2529
+ writeBlockSequence(state, level, state.dump, compact);
2530
+ }
2531
+ if (duplicate) {
2532
+ state.dump = "&ref_" + duplicateIndex + state.dump;
2533
+ }
2534
+ } else {
2535
+ writeFlowSequence(state, level, state.dump);
2536
+ if (duplicate) {
2537
+ state.dump = "&ref_" + duplicateIndex + " " + state.dump;
2538
+ }
2539
+ }
2540
+ } else if (type2 === "[object String]") {
2541
+ if (state.tag !== "?") {
2542
+ writeScalar(state, state.dump, level, iskey, inblock);
2543
+ }
2544
+ } else if (type2 === "[object Undefined]") {
2545
+ return false;
2546
+ } else {
2547
+ if (state.skipInvalid) return false;
2548
+ throw new exception("unacceptable kind of an object to dump " + type2);
2549
+ }
2550
+ if (state.tag !== null && state.tag !== "?") {
2551
+ tagStr = encodeURI(
2552
+ state.tag[0] === "!" ? state.tag.slice(1) : state.tag
2553
+ ).replace(/!/g, "%21");
2554
+ if (state.tag[0] === "!") {
2555
+ tagStr = "!" + tagStr;
2556
+ } else if (tagStr.slice(0, 18) === "tag:yaml.org,2002:") {
2557
+ tagStr = "!!" + tagStr.slice(18);
2558
+ } else {
2559
+ tagStr = "!<" + tagStr + ">";
2560
+ }
2561
+ state.dump = tagStr + " " + state.dump;
2562
+ }
2563
+ }
2564
+ return true;
2565
+ }
2566
+ function getDuplicateReferences(object, state) {
2567
+ var objects = [], duplicatesIndexes = [], index, length;
2568
+ inspectNode(object, objects, duplicatesIndexes);
2569
+ for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
2570
+ state.duplicates.push(objects[duplicatesIndexes[index]]);
2571
+ }
2572
+ state.usedDuplicates = new Array(length);
2573
+ }
2574
+ function inspectNode(object, objects, duplicatesIndexes) {
2575
+ var objectKeyList, index, length;
2576
+ if (object !== null && typeof object === "object") {
2577
+ index = objects.indexOf(object);
2578
+ if (index !== -1) {
2579
+ if (duplicatesIndexes.indexOf(index) === -1) {
2580
+ duplicatesIndexes.push(index);
2581
+ }
2582
+ } else {
2583
+ objects.push(object);
2584
+ if (Array.isArray(object)) {
2585
+ for (index = 0, length = object.length; index < length; index += 1) {
2586
+ inspectNode(object[index], objects, duplicatesIndexes);
2587
+ }
2588
+ } else {
2589
+ objectKeyList = Object.keys(object);
2590
+ for (index = 0, length = objectKeyList.length; index < length; index += 1) {
2591
+ inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
2592
+ }
2593
+ }
2594
+ }
2595
+ }
2596
+ }
2597
+ function dump$1(input, options) {
2598
+ options = options || {};
2599
+ var state = new State(options);
2600
+ if (!state.noRefs) getDuplicateReferences(input, state);
2601
+ var value = input;
2602
+ if (state.replacer) {
2603
+ value = state.replacer.call({ "": value }, "", value);
2604
+ }
2605
+ if (writeNode(state, 0, value, true, true)) return state.dump + "\n";
2606
+ return "";
2607
+ }
2608
+ var dump_1 = dump$1;
2609
+ var dumper = {
2610
+ dump: dump_1
2611
+ };
2612
+ function renamed(from, to) {
2613
+ return function() {
2614
+ throw new Error("Function yaml." + from + " is removed in js-yaml 4. Use yaml." + to + " instead, which is now safe by default.");
2615
+ };
2616
+ }
2617
+ var load = loader.load;
2618
+ var loadAll = loader.loadAll;
2619
+ var dump = dumper.dump;
2620
+ var safeLoad = renamed("safeLoad", "load");
2621
+ var safeLoadAll = renamed("safeLoadAll", "loadAll");
2622
+ var safeDump = renamed("safeDump", "dump");
2623
+
2624
+ // src/catalog.ts
2625
+ var FOUNDATIONAL_QUERY = `
2626
+ query AiFoundationalChatAgents($projectId: ProjectID!, $after: String) {
2627
+ aiFoundationalChatAgents(projectId: $projectId, first: 50, after: $after) {
2628
+ pageInfo { hasNextPage endCursor }
2629
+ nodes { id name description reference referenceWithVersion }
2630
+ }
2631
+ }`;
2632
+ var CUSTOM_AGENTS_QUERY = `
2633
+ query AiCatalogCustomAgents($projectId: ProjectID!, $after: String) {
2634
+ aiCatalogConfiguredItems(first: 50, projectId: $projectId, after: $after) {
2635
+ pageInfo { hasNextPage endCursor }
2636
+ nodes {
2637
+ enabled
2638
+ item {
2639
+ id
2640
+ name
2641
+ description
2642
+ foundational
2643
+ itemType
2644
+ latestVersion { id }
2645
+ }
2646
+ }
2647
+ }
2648
+ }`;
2649
+ var FLOW_CONFIG_QUERY = `
2650
+ query AiCatalogAgentFlowConfig($versionId: AiCatalogItemVersionID!) {
2651
+ aiCatalogAgentFlowConfig(agentVersionId: $versionId, flowConfigType: CHAT)
2652
+ }`;
2653
+ async function gql(instanceUrl, token, query, variables) {
2654
+ const res = await fetch(`${instanceUrl.replace(/\/$/, "")}/api/graphql`, {
2655
+ method: "POST",
2656
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` },
2657
+ body: JSON.stringify({ query, variables })
2658
+ });
2659
+ const json2 = await res.json();
2660
+ if (json2.errors?.length) throw new Error(json2.errors[0].message);
2661
+ return json2.data;
2662
+ }
2663
+ async function fetchFoundationalChatAgents(instanceUrl, token, projectId) {
2664
+ const agents = [];
2665
+ let after = null;
2666
+ for (; ; ) {
2667
+ const data = await gql(instanceUrl, token, FOUNDATIONAL_QUERY, {
2668
+ projectId,
2669
+ ...after ? { after } : {}
143
2670
  });
144
- app.post("/reply", async (c) => {
145
- const body = await c.req.json();
146
- const hdr = auth(c);
147
- const result = saveSelection({
148
- ref: body.ref,
149
- directory: hdr.directory,
150
- instanceUrl: hdr.instanceUrl
151
- });
152
- return c.json(result);
153
- });
154
- app.post("/clear", async (c) => {
155
- const hdr = auth(c);
156
- clearCache({ directory: hdr.directory, instanceUrl: hdr.instanceUrl });
157
- return c.json(true);
158
- });
159
- app.get("/models", async (c) => {
160
- const disc = getDiscovery();
161
- return c.json({
162
- models: disc?.selectableModels || [],
163
- pinned: disc?.pinnedModel || null,
164
- default: disc?.defaultModel || null,
165
- switching: disc?.modelSwitchingEnabled || false
2671
+ const page = data?.aiFoundationalChatAgents;
2672
+ if (!page) break;
2673
+ for (const node of page.nodes ?? []) {
2674
+ if (!node.reference) continue;
2675
+ agents.push({
2676
+ identifier: node.reference,
2677
+ name: node.name,
2678
+ description: node.description ?? "",
2679
+ workflowDefinition: node.referenceWithVersion || node.reference,
2680
+ foundational: true
166
2681
  });
2682
+ }
2683
+ if (!page.pageInfo?.hasNextPage) break;
2684
+ after = page.pageInfo.endCursor;
2685
+ }
2686
+ return agents;
2687
+ }
2688
+ async function fetchCustomAgents(instanceUrl, token, projectId) {
2689
+ const agents = [];
2690
+ const seen = /* @__PURE__ */ new Set();
2691
+ let after = null;
2692
+ for (; ; ) {
2693
+ const data = await gql(instanceUrl, token, CUSTOM_AGENTS_QUERY, {
2694
+ projectId,
2695
+ ...after ? { after } : {}
167
2696
  });
168
- };
2697
+ const page = data?.aiCatalogConfiguredItems;
2698
+ if (!page) break;
2699
+ for (const node of page.nodes ?? []) {
2700
+ if (!node.enabled) continue;
2701
+ const item = node.item;
2702
+ if (!item) continue;
2703
+ if (item.foundational || item.itemType !== "AGENT" || !item.latestVersion?.id) continue;
2704
+ if (seen.has(item.id)) continue;
2705
+ seen.add(item.id);
2706
+ try {
2707
+ const cfgData = await gql(instanceUrl, token, FLOW_CONFIG_QUERY, {
2708
+ versionId: item.latestVersion.id
2709
+ });
2710
+ const yamlStr = cfgData?.aiCatalogAgentFlowConfig;
2711
+ if (!yamlStr) continue;
2712
+ const parsed = load(yamlStr);
2713
+ agents.push({
2714
+ identifier: item.id,
2715
+ name: item.name,
2716
+ description: item.description ?? "",
2717
+ flowConfig: parsed,
2718
+ flowConfigSchemaVersion: parsed?.version ?? "v1",
2719
+ foundational: false,
2720
+ // extract numeric ID from GID e.g. "gid://gitlab/Ai::Catalog::ItemVersion/1015082" → 1015082
2721
+ catalogItemVersionId: parseInt(item.latestVersion.id.split("/").pop() ?? "", 10) || void 0
2722
+ });
2723
+ } catch {
2724
+ }
2725
+ }
2726
+ if (!page.pageInfo?.hasNextPage) break;
2727
+ after = page.pageInfo.endCursor;
2728
+ }
2729
+ return agents;
2730
+ }
2731
+ async function fetchCatalogAgents(instanceUrl, token, projectId) {
2732
+ try {
2733
+ const [foundational, custom] = await Promise.all([
2734
+ fetchFoundationalChatAgents(instanceUrl, token, projectId),
2735
+ fetchCustomAgents(instanceUrl, token, projectId)
2736
+ ]);
2737
+ return [...foundational, ...custom];
2738
+ } catch {
2739
+ return [];
2740
+ }
2741
+ }
2742
+
2743
+ // src/agents.ts
2744
+ function resolveModelId(entry) {
2745
+ const ref = entry.selectedModelRef ?? entry.discovery?.defaultModel?.ref;
2746
+ if (!ref) return "duo-workflow-default";
2747
+ return `duo-workflow-${ref.replace(/[/_]/g, "-")}`;
169
2748
  }
170
2749
 
171
2750
  // src/index.ts
172
- var plugin = async (input) => {
173
- const client = input.client;
174
- const serverFetch = client._client.getConfig().fetch ?? fetch;
175
- async function creds() {
176
- const auth2 = await input.getAuth("gitlab");
177
- if (!auth2) return null;
178
- const token = auth2.type === "oauth" ? auth2.access : auth2.type === "api" ? auth2.key : "";
179
- const instanceUrl = auth2.enterpriseUrl ?? process.env.GITLAB_INSTANCE_URL ?? "https://gitlab.com";
2751
+ var import_fs = require("fs");
2752
+ var import_path = require("path");
2753
+ var import_os = __toESM(require("os"), 1);
2754
+ var logFile = (0, import_path.join)(
2755
+ process.env.XDG_DATA_HOME ?? (0, import_path.join)(import_os.default.homedir(), ".local", "share"),
2756
+ "opencode",
2757
+ "log",
2758
+ "gitlab-dap.log"
2759
+ );
2760
+ function log(...args) {
2761
+ const line = `${(/* @__PURE__ */ new Date()).toISOString()} ${args.map(String).join(" ")}
2762
+ `;
2763
+ try {
2764
+ (0, import_fs.appendFileSync)(logFile, line);
2765
+ } catch {
2766
+ }
2767
+ }
2768
+ function readAuth() {
2769
+ try {
2770
+ const authPath = (0, import_path.join)(import_os.default.homedir(), ".local", "share", "opencode", "auth.json");
2771
+ const data = JSON.parse((0, import_fs.readFileSync)(authPath, "utf-8"));
2772
+ const gitlab = data?.gitlab;
2773
+ if (!gitlab) return null;
2774
+ const token = gitlab.type === "oauth" ? gitlab.access : gitlab.type === "api" ? gitlab.key : null;
2775
+ if (!token) return null;
2776
+ const instanceUrl = gitlab.enterpriseUrl ?? process.env.GITLAB_INSTANCE_URL ?? "https://gitlab.com";
180
2777
  return { token, instanceUrl };
2778
+ } catch {
2779
+ return null;
181
2780
  }
182
- async function askUser(models) {
183
- const res = await serverFetch(
184
- new Request("http://localhost:4096/plugin-select/ask", {
185
- method: "POST",
186
- headers: { "Content-Type": "application/json" },
187
- body: JSON.stringify({
188
- title: "Select GitLab DAP model",
189
- options: models.map((m) => ({
190
- label: m.name,
191
- value: m.ref,
192
- isDefault: m.isDefault
193
- }))
194
- })
195
- })
2781
+ }
2782
+ var memo = /* @__PURE__ */ new Map();
2783
+ var plugin = async (input) => {
2784
+ log("plugin init, directory:", input.directory);
2785
+ async function load2() {
2786
+ const auth = readAuth();
2787
+ log("readAuth result:", auth ? `instanceUrl=${auth.instanceUrl}` : "null");
2788
+ if (!auth) return null;
2789
+ const { token, instanceUrl } = auth;
2790
+ log("instanceUrl:", instanceUrl);
2791
+ const cache = new import_gitlab_ai_provider.GitLabModelCache(input.directory, instanceUrl);
2792
+ const entry = cache.load();
2793
+ log(
2794
+ "cache entry:",
2795
+ entry ? `discovery=${!!entry.discovery} projectId=${entry.project?.id}` : "null"
196
2796
  );
197
- const data = await res.json();
198
- return data?.value ?? null;
2797
+ if (!entry?.discovery) return null;
2798
+ const projectId = entry.project?.id;
2799
+ if (!projectId) return null;
2800
+ const key = `${input.directory}\0${instanceUrl}`;
2801
+ const cached = memo.get(key);
2802
+ const agents = cached ?? await fetchCatalogAgents(instanceUrl, token, `gid://gitlab/Project/${projectId}`);
2803
+ log("agents fetched:", agents.length);
2804
+ if (!cached) memo.set(key, agents);
2805
+ return { agents, entry };
199
2806
  }
200
2807
  return {
201
- route: {
202
- prefix: "gitlab",
203
- handler: routes({ creds, askUser })
2808
+ async config(cfg) {
2809
+ log("config hook called");
2810
+ const result = await load2();
2811
+ if (!result?.agents.length) return;
2812
+ const baseModelId = resolveModelId(result.entry);
2813
+ cfg.agent ??= {};
2814
+ for (const agent of result.agents) {
2815
+ cfg.agent[agent.name] = {
2816
+ name: agent.name,
2817
+ description: agent.foundational ? "[GitLab Foundational Agent]" : "[GitLab Custom Agent]",
2818
+ mode: "primary",
2819
+ model: `gitlab/${baseModelId}`,
2820
+ options: {
2821
+ workflowDefinition: agent.workflowDefinition,
2822
+ flowConfig: agent.flowConfig,
2823
+ flowConfigSchemaVersion: agent.flowConfigSchemaVersion,
2824
+ // numeric version ID passed as ai_catalog_item_version_id in createWorkflow
2825
+ // so GitLab UI links the session to the correct custom agent page
2826
+ aiCatalogItemVersionId: agent.catalogItemVersionId
2827
+ },
2828
+ permission: { "*": "allow" }
2829
+ };
2830
+ }
2831
+ log("config hook injected:", result.agents.map((a) => a.name).join(", "));
204
2832
  }
205
2833
  };
206
2834
  };
207
2835
  var index_default = plugin;
208
- // Annotate the CommonJS export names for ESM import in node:
209
- 0 && (module.exports = {
210
- plugin
211
- });
2836
+ /*! Bundled license information:
2837
+
2838
+ js-yaml/dist/js-yaml.mjs:
2839
+ (*! js-yaml 4.1.1 https://github.com/nodeca/js-yaml @license MIT *)
2840
+ */
212
2841
  //# sourceMappingURL=index.cjs.map