conversationalist 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +150 -90
- package/dist/adapters/anthropic/index.d.ts +11 -6
- package/dist/adapters/anthropic/index.d.ts.map +1 -1
- package/dist/adapters/anthropic/index.js +16 -3
- package/dist/adapters/anthropic/index.js.map +5 -4
- package/dist/adapters/gemini/index.d.ts +2 -2
- package/dist/adapters/gemini/index.d.ts.map +1 -1
- package/dist/adapters/gemini/index.js +52 -9
- package/dist/adapters/gemini/index.js.map +5 -4
- package/dist/adapters/openai/index.d.ts +32 -5
- package/dist/adapters/openai/index.d.ts.map +1 -1
- package/dist/adapters/openai/index.js +30 -8
- package/dist/adapters/openai/index.js.map +5 -4
- package/dist/context.d.ts.map +1 -1
- package/dist/conversation/append.d.ts +4 -4
- package/dist/conversation/append.d.ts.map +1 -1
- package/dist/conversation/create.d.ts +2 -3
- package/dist/conversation/create.d.ts.map +1 -1
- package/dist/conversation/index.d.ts +2 -2
- package/dist/conversation/index.d.ts.map +1 -1
- package/dist/conversation/modify.d.ts.map +1 -1
- package/dist/conversation/query.d.ts +9 -5
- package/dist/conversation/query.d.ts.map +1 -1
- package/dist/conversation/serialization.d.ts +6 -28
- package/dist/conversation/serialization.d.ts.map +1 -1
- package/dist/conversation/system-messages.d.ts +3 -3
- package/dist/conversation/system-messages.d.ts.map +1 -1
- package/dist/conversation/transform.d.ts.map +1 -1
- package/dist/conversation.d.ts +74 -18
- package/dist/conversation.d.ts.map +1 -1
- package/dist/export/index.d.ts +7 -0
- package/dist/export/index.d.ts.map +1 -0
- package/dist/export/index.js +3762 -0
- package/dist/export/index.js.map +62 -0
- package/dist/history.d.ts +102 -24
- package/dist/history.d.ts.map +1 -1
- package/dist/index.d.ts +7 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +392 -4075
- package/dist/index.js.map +15 -60
- package/dist/markdown/index.d.ts +15 -0
- package/dist/markdown/index.d.ts.map +1 -0
- package/dist/markdown/index.js +4969 -0
- package/dist/markdown/index.js.map +69 -0
- package/dist/message.d.ts +1 -1
- package/dist/message.d.ts.map +1 -1
- package/dist/multi-modal.d.ts +3 -0
- package/dist/multi-modal.d.ts.map +1 -1
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +59 -0
- package/dist/plugins/index.js.map +10 -0
- package/dist/plugins/pii-redaction.d.ts +10 -1
- package/dist/plugins/pii-redaction.d.ts.map +1 -1
- package/dist/redaction/index.d.ts +2 -0
- package/dist/redaction/index.d.ts.map +1 -0
- package/dist/redaction/index.js +59 -0
- package/dist/redaction/index.js.map +10 -0
- package/dist/schemas/index.d.ts +2 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +114 -0
- package/dist/schemas/index.js.map +10 -0
- package/dist/schemas.d.ts +324 -15
- package/dist/schemas.d.ts.map +1 -1
- package/dist/sort/index.d.ts +2 -0
- package/dist/sort/index.d.ts.map +1 -0
- package/dist/sort/index.js +32 -0
- package/dist/sort/index.js.map +10 -0
- package/dist/streaming.d.ts +3 -3
- package/dist/streaming.d.ts.map +1 -1
- package/dist/types.d.ts +72 -50
- package/dist/types.d.ts.map +1 -1
- package/dist/utilities/index.d.ts +1 -3
- package/dist/utilities/index.d.ts.map +1 -1
- package/dist/utilities/line-endings.d.ts +5 -0
- package/dist/utilities/line-endings.d.ts.map +1 -0
- package/dist/utilities/markdown.d.ts +1 -1
- package/dist/utilities/markdown.d.ts.map +1 -1
- package/dist/utilities/message-store.d.ts +6 -0
- package/dist/utilities/message-store.d.ts.map +1 -0
- package/dist/utilities/message.d.ts +9 -3
- package/dist/utilities/message.d.ts.map +1 -1
- package/dist/utilities/tool-calls.d.ts +4 -4
- package/dist/utilities/tool-calls.d.ts.map +1 -1
- package/dist/utilities/tool-results.d.ts +10 -0
- package/dist/utilities/tool-results.d.ts.map +1 -0
- package/dist/utilities/transient.d.ts +2 -2
- package/dist/utilities/transient.d.ts.map +1 -1
- package/dist/utilities.d.ts +3 -5
- package/dist/utilities.d.ts.map +1 -1
- package/dist/versioning/index.d.ts +3 -0
- package/dist/versioning/index.d.ts.map +1 -0
- package/dist/versioning/index.js +58 -0
- package/dist/versioning/index.js.map +11 -0
- package/dist/with-conversation.d.ts +8 -8
- package/dist/with-conversation.d.ts.map +1 -1
- package/package.json +26 -1
|
@@ -0,0 +1,4969 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
19
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
20
|
+
|
|
21
|
+
// node_modules/kind-of/index.js
|
|
22
|
+
var require_kind_of = __commonJS((exports, module) => {
|
|
23
|
+
var toString = Object.prototype.toString;
|
|
24
|
+
module.exports = function kindOf(val) {
|
|
25
|
+
if (val === undefined)
|
|
26
|
+
return "undefined";
|
|
27
|
+
if (val === null)
|
|
28
|
+
return "null";
|
|
29
|
+
var type = typeof val;
|
|
30
|
+
if (type === "boolean")
|
|
31
|
+
return "boolean";
|
|
32
|
+
if (type === "string")
|
|
33
|
+
return "string";
|
|
34
|
+
if (type === "number")
|
|
35
|
+
return "number";
|
|
36
|
+
if (type === "symbol")
|
|
37
|
+
return "symbol";
|
|
38
|
+
if (type === "function") {
|
|
39
|
+
return isGeneratorFn(val) ? "generatorfunction" : "function";
|
|
40
|
+
}
|
|
41
|
+
if (isArray(val))
|
|
42
|
+
return "array";
|
|
43
|
+
if (isBuffer(val))
|
|
44
|
+
return "buffer";
|
|
45
|
+
if (isArguments(val))
|
|
46
|
+
return "arguments";
|
|
47
|
+
if (isDate(val))
|
|
48
|
+
return "date";
|
|
49
|
+
if (isError(val))
|
|
50
|
+
return "error";
|
|
51
|
+
if (isRegexp(val))
|
|
52
|
+
return "regexp";
|
|
53
|
+
switch (ctorName(val)) {
|
|
54
|
+
case "Symbol":
|
|
55
|
+
return "symbol";
|
|
56
|
+
case "Promise":
|
|
57
|
+
return "promise";
|
|
58
|
+
case "WeakMap":
|
|
59
|
+
return "weakmap";
|
|
60
|
+
case "WeakSet":
|
|
61
|
+
return "weakset";
|
|
62
|
+
case "Map":
|
|
63
|
+
return "map";
|
|
64
|
+
case "Set":
|
|
65
|
+
return "set";
|
|
66
|
+
case "Int8Array":
|
|
67
|
+
return "int8array";
|
|
68
|
+
case "Uint8Array":
|
|
69
|
+
return "uint8array";
|
|
70
|
+
case "Uint8ClampedArray":
|
|
71
|
+
return "uint8clampedarray";
|
|
72
|
+
case "Int16Array":
|
|
73
|
+
return "int16array";
|
|
74
|
+
case "Uint16Array":
|
|
75
|
+
return "uint16array";
|
|
76
|
+
case "Int32Array":
|
|
77
|
+
return "int32array";
|
|
78
|
+
case "Uint32Array":
|
|
79
|
+
return "uint32array";
|
|
80
|
+
case "Float32Array":
|
|
81
|
+
return "float32array";
|
|
82
|
+
case "Float64Array":
|
|
83
|
+
return "float64array";
|
|
84
|
+
}
|
|
85
|
+
if (isGeneratorObj(val)) {
|
|
86
|
+
return "generator";
|
|
87
|
+
}
|
|
88
|
+
type = toString.call(val);
|
|
89
|
+
switch (type) {
|
|
90
|
+
case "[object Object]":
|
|
91
|
+
return "object";
|
|
92
|
+
case "[object Map Iterator]":
|
|
93
|
+
return "mapiterator";
|
|
94
|
+
case "[object Set Iterator]":
|
|
95
|
+
return "setiterator";
|
|
96
|
+
case "[object String Iterator]":
|
|
97
|
+
return "stringiterator";
|
|
98
|
+
case "[object Array Iterator]":
|
|
99
|
+
return "arrayiterator";
|
|
100
|
+
}
|
|
101
|
+
return type.slice(8, -1).toLowerCase().replace(/\s/g, "");
|
|
102
|
+
};
|
|
103
|
+
function ctorName(val) {
|
|
104
|
+
return typeof val.constructor === "function" ? val.constructor.name : null;
|
|
105
|
+
}
|
|
106
|
+
function isArray(val) {
|
|
107
|
+
if (Array.isArray)
|
|
108
|
+
return Array.isArray(val);
|
|
109
|
+
return val instanceof Array;
|
|
110
|
+
}
|
|
111
|
+
function isError(val) {
|
|
112
|
+
return val instanceof Error || typeof val.message === "string" && val.constructor && typeof val.constructor.stackTraceLimit === "number";
|
|
113
|
+
}
|
|
114
|
+
function isDate(val) {
|
|
115
|
+
if (val instanceof Date)
|
|
116
|
+
return true;
|
|
117
|
+
return typeof val.toDateString === "function" && typeof val.getDate === "function" && typeof val.setDate === "function";
|
|
118
|
+
}
|
|
119
|
+
function isRegexp(val) {
|
|
120
|
+
if (val instanceof RegExp)
|
|
121
|
+
return true;
|
|
122
|
+
return typeof val.flags === "string" && typeof val.ignoreCase === "boolean" && typeof val.multiline === "boolean" && typeof val.global === "boolean";
|
|
123
|
+
}
|
|
124
|
+
function isGeneratorFn(name, val) {
|
|
125
|
+
return ctorName(name) === "GeneratorFunction";
|
|
126
|
+
}
|
|
127
|
+
function isGeneratorObj(val) {
|
|
128
|
+
return typeof val.throw === "function" && typeof val.return === "function" && typeof val.next === "function";
|
|
129
|
+
}
|
|
130
|
+
function isArguments(val) {
|
|
131
|
+
try {
|
|
132
|
+
if (typeof val.length === "number" && typeof val.callee === "function") {
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
} catch (err) {
|
|
136
|
+
if (err.message.indexOf("callee") !== -1) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
function isBuffer(val) {
|
|
143
|
+
if (val.constructor && typeof val.constructor.isBuffer === "function") {
|
|
144
|
+
return val.constructor.isBuffer(val);
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// node_modules/is-extendable/index.js
|
|
151
|
+
var require_is_extendable = __commonJS((exports, module) => {
|
|
152
|
+
/*!
|
|
153
|
+
* is-extendable <https://github.com/jonschlinkert/is-extendable>
|
|
154
|
+
*
|
|
155
|
+
* Copyright (c) 2015, Jon Schlinkert.
|
|
156
|
+
* Licensed under the MIT License.
|
|
157
|
+
*/
|
|
158
|
+
module.exports = function isExtendable(val) {
|
|
159
|
+
return typeof val !== "undefined" && val !== null && (typeof val === "object" || typeof val === "function");
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// node_modules/extend-shallow/index.js
|
|
164
|
+
var require_extend_shallow = __commonJS((exports, module) => {
|
|
165
|
+
var isObject = require_is_extendable();
|
|
166
|
+
module.exports = function extend(o) {
|
|
167
|
+
if (!isObject(o)) {
|
|
168
|
+
o = {};
|
|
169
|
+
}
|
|
170
|
+
var len = arguments.length;
|
|
171
|
+
for (var i = 1;i < len; i++) {
|
|
172
|
+
var obj = arguments[i];
|
|
173
|
+
if (isObject(obj)) {
|
|
174
|
+
assign(o, obj);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return o;
|
|
178
|
+
};
|
|
179
|
+
function assign(a, b) {
|
|
180
|
+
for (var key in b) {
|
|
181
|
+
if (hasOwn(b, key)) {
|
|
182
|
+
a[key] = b[key];
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function hasOwn(obj, key) {
|
|
187
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// node_modules/section-matter/index.js
|
|
192
|
+
var require_section_matter = __commonJS((exports, module) => {
|
|
193
|
+
var typeOf = require_kind_of();
|
|
194
|
+
var extend = require_extend_shallow();
|
|
195
|
+
module.exports = function(input, options2) {
|
|
196
|
+
if (typeof options2 === "function") {
|
|
197
|
+
options2 = { parse: options2 };
|
|
198
|
+
}
|
|
199
|
+
var file = toObject(input);
|
|
200
|
+
var defaults = { section_delimiter: "---", parse: identity };
|
|
201
|
+
var opts = extend({}, defaults, options2);
|
|
202
|
+
var delim = opts.section_delimiter;
|
|
203
|
+
var lines = file.content.split(/\r?\n/);
|
|
204
|
+
var sections = null;
|
|
205
|
+
var section = createSection();
|
|
206
|
+
var content = [];
|
|
207
|
+
var stack = [];
|
|
208
|
+
function initSections(val) {
|
|
209
|
+
file.content = val;
|
|
210
|
+
sections = [];
|
|
211
|
+
content = [];
|
|
212
|
+
}
|
|
213
|
+
function closeSection(val) {
|
|
214
|
+
if (stack.length) {
|
|
215
|
+
section.key = getKey(stack[0], delim);
|
|
216
|
+
section.content = val;
|
|
217
|
+
opts.parse(section, sections);
|
|
218
|
+
sections.push(section);
|
|
219
|
+
section = createSection();
|
|
220
|
+
content = [];
|
|
221
|
+
stack = [];
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
for (var i = 0;i < lines.length; i++) {
|
|
225
|
+
var line = lines[i];
|
|
226
|
+
var len = stack.length;
|
|
227
|
+
var ln = line.trim();
|
|
228
|
+
if (isDelimiter(ln, delim)) {
|
|
229
|
+
if (ln.length === 3 && i !== 0) {
|
|
230
|
+
if (len === 0 || len === 2) {
|
|
231
|
+
content.push(line);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
stack.push(ln);
|
|
235
|
+
section.data = content.join(`
|
|
236
|
+
`);
|
|
237
|
+
content = [];
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (sections === null) {
|
|
241
|
+
initSections(content.join(`
|
|
242
|
+
`));
|
|
243
|
+
}
|
|
244
|
+
if (len === 2) {
|
|
245
|
+
closeSection(content.join(`
|
|
246
|
+
`));
|
|
247
|
+
}
|
|
248
|
+
stack.push(ln);
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
content.push(line);
|
|
252
|
+
}
|
|
253
|
+
if (sections === null) {
|
|
254
|
+
initSections(content.join(`
|
|
255
|
+
`));
|
|
256
|
+
} else {
|
|
257
|
+
closeSection(content.join(`
|
|
258
|
+
`));
|
|
259
|
+
}
|
|
260
|
+
file.sections = sections;
|
|
261
|
+
return file;
|
|
262
|
+
};
|
|
263
|
+
function isDelimiter(line, delim) {
|
|
264
|
+
if (line.slice(0, delim.length) !== delim) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
if (line.charAt(delim.length + 1) === delim.slice(-1)) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
function toObject(input) {
|
|
273
|
+
if (typeOf(input) !== "object") {
|
|
274
|
+
input = { content: input };
|
|
275
|
+
}
|
|
276
|
+
if (typeof input.content !== "string" && !isBuffer(input.content)) {
|
|
277
|
+
throw new TypeError("expected a buffer or string");
|
|
278
|
+
}
|
|
279
|
+
input.content = input.content.toString();
|
|
280
|
+
input.sections = [];
|
|
281
|
+
return input;
|
|
282
|
+
}
|
|
283
|
+
function getKey(val, delim) {
|
|
284
|
+
return val ? val.slice(delim.length).trim() : "";
|
|
285
|
+
}
|
|
286
|
+
function createSection() {
|
|
287
|
+
return { key: "", data: "", content: "" };
|
|
288
|
+
}
|
|
289
|
+
function identity(val) {
|
|
290
|
+
return val;
|
|
291
|
+
}
|
|
292
|
+
function isBuffer(val) {
|
|
293
|
+
if (val && val.constructor && typeof val.constructor.isBuffer === "function") {
|
|
294
|
+
return val.constructor.isBuffer(val);
|
|
295
|
+
}
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/common.js
|
|
301
|
+
var require_common = __commonJS((exports, module) => {
|
|
302
|
+
function isNothing(subject) {
|
|
303
|
+
return typeof subject === "undefined" || subject === null;
|
|
304
|
+
}
|
|
305
|
+
function isObject(subject) {
|
|
306
|
+
return typeof subject === "object" && subject !== null;
|
|
307
|
+
}
|
|
308
|
+
function toArray(sequence) {
|
|
309
|
+
if (Array.isArray(sequence))
|
|
310
|
+
return sequence;
|
|
311
|
+
else if (isNothing(sequence))
|
|
312
|
+
return [];
|
|
313
|
+
return [sequence];
|
|
314
|
+
}
|
|
315
|
+
function extend(target, source) {
|
|
316
|
+
var index, length, key, sourceKeys;
|
|
317
|
+
if (source) {
|
|
318
|
+
sourceKeys = Object.keys(source);
|
|
319
|
+
for (index = 0, length = sourceKeys.length;index < length; index += 1) {
|
|
320
|
+
key = sourceKeys[index];
|
|
321
|
+
target[key] = source[key];
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return target;
|
|
325
|
+
}
|
|
326
|
+
function repeat(string, count) {
|
|
327
|
+
var result = "", cycle;
|
|
328
|
+
for (cycle = 0;cycle < count; cycle += 1) {
|
|
329
|
+
result += string;
|
|
330
|
+
}
|
|
331
|
+
return result;
|
|
332
|
+
}
|
|
333
|
+
function isNegativeZero(number) {
|
|
334
|
+
return number === 0 && Number.NEGATIVE_INFINITY === 1 / number;
|
|
335
|
+
}
|
|
336
|
+
exports.isNothing = isNothing;
|
|
337
|
+
exports.isObject = isObject;
|
|
338
|
+
exports.toArray = toArray;
|
|
339
|
+
exports.repeat = repeat;
|
|
340
|
+
exports.isNegativeZero = isNegativeZero;
|
|
341
|
+
exports.extend = extend;
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/exception.js
|
|
345
|
+
var require_exception = __commonJS((exports, module) => {
|
|
346
|
+
function YAMLException(reason, mark) {
|
|
347
|
+
Error.call(this);
|
|
348
|
+
this.name = "YAMLException";
|
|
349
|
+
this.reason = reason;
|
|
350
|
+
this.mark = mark;
|
|
351
|
+
this.message = (this.reason || "(unknown reason)") + (this.mark ? " " + this.mark.toString() : "");
|
|
352
|
+
if (Error.captureStackTrace) {
|
|
353
|
+
Error.captureStackTrace(this, this.constructor);
|
|
354
|
+
} else {
|
|
355
|
+
this.stack = new Error().stack || "";
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
YAMLException.prototype = Object.create(Error.prototype);
|
|
359
|
+
YAMLException.prototype.constructor = YAMLException;
|
|
360
|
+
YAMLException.prototype.toString = function toString(compact) {
|
|
361
|
+
var result = this.name + ": ";
|
|
362
|
+
result += this.reason || "(unknown reason)";
|
|
363
|
+
if (!compact && this.mark) {
|
|
364
|
+
result += " " + this.mark.toString();
|
|
365
|
+
}
|
|
366
|
+
return result;
|
|
367
|
+
};
|
|
368
|
+
module.exports = YAMLException;
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/mark.js
|
|
372
|
+
var require_mark = __commonJS((exports, module) => {
|
|
373
|
+
var common = require_common();
|
|
374
|
+
function Mark(name, buffer, position, line, column) {
|
|
375
|
+
this.name = name;
|
|
376
|
+
this.buffer = buffer;
|
|
377
|
+
this.position = position;
|
|
378
|
+
this.line = line;
|
|
379
|
+
this.column = column;
|
|
380
|
+
}
|
|
381
|
+
Mark.prototype.getSnippet = function getSnippet(indent, maxLength) {
|
|
382
|
+
var head, start, tail, end, snippet;
|
|
383
|
+
if (!this.buffer)
|
|
384
|
+
return null;
|
|
385
|
+
indent = indent || 4;
|
|
386
|
+
maxLength = maxLength || 75;
|
|
387
|
+
head = "";
|
|
388
|
+
start = this.position;
|
|
389
|
+
while (start > 0 && `\x00\r
|
|
390
|
+
\u2028\u2029`.indexOf(this.buffer.charAt(start - 1)) === -1) {
|
|
391
|
+
start -= 1;
|
|
392
|
+
if (this.position - start > maxLength / 2 - 1) {
|
|
393
|
+
head = " ... ";
|
|
394
|
+
start += 5;
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
tail = "";
|
|
399
|
+
end = this.position;
|
|
400
|
+
while (end < this.buffer.length && `\x00\r
|
|
401
|
+
\u2028\u2029`.indexOf(this.buffer.charAt(end)) === -1) {
|
|
402
|
+
end += 1;
|
|
403
|
+
if (end - this.position > maxLength / 2 - 1) {
|
|
404
|
+
tail = " ... ";
|
|
405
|
+
end -= 5;
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
snippet = this.buffer.slice(start, end);
|
|
410
|
+
return common.repeat(" ", indent) + head + snippet + tail + `
|
|
411
|
+
` + common.repeat(" ", indent + this.position - start + head.length) + "^";
|
|
412
|
+
};
|
|
413
|
+
Mark.prototype.toString = function toString(compact) {
|
|
414
|
+
var snippet, where = "";
|
|
415
|
+
if (this.name) {
|
|
416
|
+
where += 'in "' + this.name + '" ';
|
|
417
|
+
}
|
|
418
|
+
where += "at line " + (this.line + 1) + ", column " + (this.column + 1);
|
|
419
|
+
if (!compact) {
|
|
420
|
+
snippet = this.getSnippet();
|
|
421
|
+
if (snippet) {
|
|
422
|
+
where += `:
|
|
423
|
+
` + snippet;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return where;
|
|
427
|
+
};
|
|
428
|
+
module.exports = Mark;
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type.js
|
|
432
|
+
var require_type = __commonJS((exports, module) => {
|
|
433
|
+
var YAMLException = require_exception();
|
|
434
|
+
var TYPE_CONSTRUCTOR_OPTIONS = [
|
|
435
|
+
"kind",
|
|
436
|
+
"resolve",
|
|
437
|
+
"construct",
|
|
438
|
+
"instanceOf",
|
|
439
|
+
"predicate",
|
|
440
|
+
"represent",
|
|
441
|
+
"defaultStyle",
|
|
442
|
+
"styleAliases"
|
|
443
|
+
];
|
|
444
|
+
var YAML_NODE_KINDS = [
|
|
445
|
+
"scalar",
|
|
446
|
+
"sequence",
|
|
447
|
+
"mapping"
|
|
448
|
+
];
|
|
449
|
+
function compileStyleAliases(map) {
|
|
450
|
+
var result = {};
|
|
451
|
+
if (map !== null) {
|
|
452
|
+
Object.keys(map).forEach(function(style) {
|
|
453
|
+
map[style].forEach(function(alias) {
|
|
454
|
+
result[String(alias)] = style;
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
return result;
|
|
459
|
+
}
|
|
460
|
+
function Type(tag, options2) {
|
|
461
|
+
options2 = options2 || {};
|
|
462
|
+
Object.keys(options2).forEach(function(name) {
|
|
463
|
+
if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
|
|
464
|
+
throw new YAMLException('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
this.tag = tag;
|
|
468
|
+
this.kind = options2["kind"] || null;
|
|
469
|
+
this.resolve = options2["resolve"] || function() {
|
|
470
|
+
return true;
|
|
471
|
+
};
|
|
472
|
+
this.construct = options2["construct"] || function(data) {
|
|
473
|
+
return data;
|
|
474
|
+
};
|
|
475
|
+
this.instanceOf = options2["instanceOf"] || null;
|
|
476
|
+
this.predicate = options2["predicate"] || null;
|
|
477
|
+
this.represent = options2["represent"] || null;
|
|
478
|
+
this.defaultStyle = options2["defaultStyle"] || null;
|
|
479
|
+
this.styleAliases = compileStyleAliases(options2["styleAliases"] || null);
|
|
480
|
+
if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
|
|
481
|
+
throw new YAMLException('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
module.exports = Type;
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/schema.js
|
|
488
|
+
var require_schema = __commonJS((exports, module) => {
|
|
489
|
+
var common = require_common();
|
|
490
|
+
var YAMLException = require_exception();
|
|
491
|
+
var Type = require_type();
|
|
492
|
+
function compileList(schema, name, result) {
|
|
493
|
+
var exclude = [];
|
|
494
|
+
schema.include.forEach(function(includedSchema) {
|
|
495
|
+
result = compileList(includedSchema, name, result);
|
|
496
|
+
});
|
|
497
|
+
schema[name].forEach(function(currentType) {
|
|
498
|
+
result.forEach(function(previousType, previousIndex) {
|
|
499
|
+
if (previousType.tag === currentType.tag && previousType.kind === currentType.kind) {
|
|
500
|
+
exclude.push(previousIndex);
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
result.push(currentType);
|
|
504
|
+
});
|
|
505
|
+
return result.filter(function(type, index) {
|
|
506
|
+
return exclude.indexOf(index) === -1;
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
function compileMap() {
|
|
510
|
+
var result = {
|
|
511
|
+
scalar: {},
|
|
512
|
+
sequence: {},
|
|
513
|
+
mapping: {},
|
|
514
|
+
fallback: {}
|
|
515
|
+
}, index, length;
|
|
516
|
+
function collectType(type) {
|
|
517
|
+
result[type.kind][type.tag] = result["fallback"][type.tag] = type;
|
|
518
|
+
}
|
|
519
|
+
for (index = 0, length = arguments.length;index < length; index += 1) {
|
|
520
|
+
arguments[index].forEach(collectType);
|
|
521
|
+
}
|
|
522
|
+
return result;
|
|
523
|
+
}
|
|
524
|
+
function Schema(definition) {
|
|
525
|
+
this.include = definition.include || [];
|
|
526
|
+
this.implicit = definition.implicit || [];
|
|
527
|
+
this.explicit = definition.explicit || [];
|
|
528
|
+
this.implicit.forEach(function(type) {
|
|
529
|
+
if (type.loadKind && type.loadKind !== "scalar") {
|
|
530
|
+
throw new YAMLException("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
this.compiledImplicit = compileList(this, "implicit", []);
|
|
534
|
+
this.compiledExplicit = compileList(this, "explicit", []);
|
|
535
|
+
this.compiledTypeMap = compileMap(this.compiledImplicit, this.compiledExplicit);
|
|
536
|
+
}
|
|
537
|
+
Schema.DEFAULT = null;
|
|
538
|
+
Schema.create = function createSchema() {
|
|
539
|
+
var schemas, types;
|
|
540
|
+
switch (arguments.length) {
|
|
541
|
+
case 1:
|
|
542
|
+
schemas = Schema.DEFAULT;
|
|
543
|
+
types = arguments[0];
|
|
544
|
+
break;
|
|
545
|
+
case 2:
|
|
546
|
+
schemas = arguments[0];
|
|
547
|
+
types = arguments[1];
|
|
548
|
+
break;
|
|
549
|
+
default:
|
|
550
|
+
throw new YAMLException("Wrong number of arguments for Schema.create function");
|
|
551
|
+
}
|
|
552
|
+
schemas = common.toArray(schemas);
|
|
553
|
+
types = common.toArray(types);
|
|
554
|
+
if (!schemas.every(function(schema) {
|
|
555
|
+
return schema instanceof Schema;
|
|
556
|
+
})) {
|
|
557
|
+
throw new YAMLException("Specified list of super schemas (or a single Schema object) contains a non-Schema object.");
|
|
558
|
+
}
|
|
559
|
+
if (!types.every(function(type) {
|
|
560
|
+
return type instanceof Type;
|
|
561
|
+
})) {
|
|
562
|
+
throw new YAMLException("Specified list of YAML types (or a single Type object) contains a non-Type object.");
|
|
563
|
+
}
|
|
564
|
+
return new Schema({
|
|
565
|
+
include: schemas,
|
|
566
|
+
explicit: types
|
|
567
|
+
});
|
|
568
|
+
};
|
|
569
|
+
module.exports = Schema;
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/str.js
|
|
573
|
+
var require_str = __commonJS((exports, module) => {
|
|
574
|
+
var Type = require_type();
|
|
575
|
+
module.exports = new Type("tag:yaml.org,2002:str", {
|
|
576
|
+
kind: "scalar",
|
|
577
|
+
construct: function(data) {
|
|
578
|
+
return data !== null ? data : "";
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/seq.js
|
|
584
|
+
var require_seq = __commonJS((exports, module) => {
|
|
585
|
+
var Type = require_type();
|
|
586
|
+
module.exports = new Type("tag:yaml.org,2002:seq", {
|
|
587
|
+
kind: "sequence",
|
|
588
|
+
construct: function(data) {
|
|
589
|
+
return data !== null ? data : [];
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/map.js
|
|
595
|
+
var require_map = __commonJS((exports, module) => {
|
|
596
|
+
var Type = require_type();
|
|
597
|
+
module.exports = new Type("tag:yaml.org,2002:map", {
|
|
598
|
+
kind: "mapping",
|
|
599
|
+
construct: function(data) {
|
|
600
|
+
return data !== null ? data : {};
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/schema/failsafe.js
|
|
606
|
+
var require_failsafe = __commonJS((exports, module) => {
|
|
607
|
+
var Schema = require_schema();
|
|
608
|
+
module.exports = new Schema({
|
|
609
|
+
explicit: [
|
|
610
|
+
require_str(),
|
|
611
|
+
require_seq(),
|
|
612
|
+
require_map()
|
|
613
|
+
]
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/null.js
|
|
618
|
+
var require_null = __commonJS((exports, module) => {
|
|
619
|
+
var Type = require_type();
|
|
620
|
+
function resolveYamlNull(data) {
|
|
621
|
+
if (data === null)
|
|
622
|
+
return true;
|
|
623
|
+
var max = data.length;
|
|
624
|
+
return max === 1 && data === "~" || max === 4 && (data === "null" || data === "Null" || data === "NULL");
|
|
625
|
+
}
|
|
626
|
+
function constructYamlNull() {
|
|
627
|
+
return null;
|
|
628
|
+
}
|
|
629
|
+
function isNull(object) {
|
|
630
|
+
return object === null;
|
|
631
|
+
}
|
|
632
|
+
module.exports = new Type("tag:yaml.org,2002:null", {
|
|
633
|
+
kind: "scalar",
|
|
634
|
+
resolve: resolveYamlNull,
|
|
635
|
+
construct: constructYamlNull,
|
|
636
|
+
predicate: isNull,
|
|
637
|
+
represent: {
|
|
638
|
+
canonical: function() {
|
|
639
|
+
return "~";
|
|
640
|
+
},
|
|
641
|
+
lowercase: function() {
|
|
642
|
+
return "null";
|
|
643
|
+
},
|
|
644
|
+
uppercase: function() {
|
|
645
|
+
return "NULL";
|
|
646
|
+
},
|
|
647
|
+
camelcase: function() {
|
|
648
|
+
return "Null";
|
|
649
|
+
}
|
|
650
|
+
},
|
|
651
|
+
defaultStyle: "lowercase"
|
|
652
|
+
});
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/bool.js
|
|
656
|
+
var require_bool = __commonJS((exports, module) => {
|
|
657
|
+
var Type = require_type();
|
|
658
|
+
function resolveYamlBoolean(data) {
|
|
659
|
+
if (data === null)
|
|
660
|
+
return false;
|
|
661
|
+
var max = data.length;
|
|
662
|
+
return max === 4 && (data === "true" || data === "True" || data === "TRUE") || max === 5 && (data === "false" || data === "False" || data === "FALSE");
|
|
663
|
+
}
|
|
664
|
+
function constructYamlBoolean(data) {
|
|
665
|
+
return data === "true" || data === "True" || data === "TRUE";
|
|
666
|
+
}
|
|
667
|
+
function isBoolean(object) {
|
|
668
|
+
return Object.prototype.toString.call(object) === "[object Boolean]";
|
|
669
|
+
}
|
|
670
|
+
module.exports = new Type("tag:yaml.org,2002:bool", {
|
|
671
|
+
kind: "scalar",
|
|
672
|
+
resolve: resolveYamlBoolean,
|
|
673
|
+
construct: constructYamlBoolean,
|
|
674
|
+
predicate: isBoolean,
|
|
675
|
+
represent: {
|
|
676
|
+
lowercase: function(object) {
|
|
677
|
+
return object ? "true" : "false";
|
|
678
|
+
},
|
|
679
|
+
uppercase: function(object) {
|
|
680
|
+
return object ? "TRUE" : "FALSE";
|
|
681
|
+
},
|
|
682
|
+
camelcase: function(object) {
|
|
683
|
+
return object ? "True" : "False";
|
|
684
|
+
}
|
|
685
|
+
},
|
|
686
|
+
defaultStyle: "lowercase"
|
|
687
|
+
});
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/int.js
|
|
691
|
+
var require_int = __commonJS((exports, module) => {
|
|
692
|
+
var common = require_common();
|
|
693
|
+
var Type = require_type();
|
|
694
|
+
function isHexCode(c) {
|
|
695
|
+
return 48 <= c && c <= 57 || 65 <= c && c <= 70 || 97 <= c && c <= 102;
|
|
696
|
+
}
|
|
697
|
+
function isOctCode(c) {
|
|
698
|
+
return 48 <= c && c <= 55;
|
|
699
|
+
}
|
|
700
|
+
function isDecCode(c) {
|
|
701
|
+
return 48 <= c && c <= 57;
|
|
702
|
+
}
|
|
703
|
+
function resolveYamlInteger(data) {
|
|
704
|
+
if (data === null)
|
|
705
|
+
return false;
|
|
706
|
+
var max = data.length, index = 0, hasDigits = false, ch;
|
|
707
|
+
if (!max)
|
|
708
|
+
return false;
|
|
709
|
+
ch = data[index];
|
|
710
|
+
if (ch === "-" || ch === "+") {
|
|
711
|
+
ch = data[++index];
|
|
712
|
+
}
|
|
713
|
+
if (ch === "0") {
|
|
714
|
+
if (index + 1 === max)
|
|
715
|
+
return true;
|
|
716
|
+
ch = data[++index];
|
|
717
|
+
if (ch === "b") {
|
|
718
|
+
index++;
|
|
719
|
+
for (;index < max; index++) {
|
|
720
|
+
ch = data[index];
|
|
721
|
+
if (ch === "_")
|
|
722
|
+
continue;
|
|
723
|
+
if (ch !== "0" && ch !== "1")
|
|
724
|
+
return false;
|
|
725
|
+
hasDigits = true;
|
|
726
|
+
}
|
|
727
|
+
return hasDigits && ch !== "_";
|
|
728
|
+
}
|
|
729
|
+
if (ch === "x") {
|
|
730
|
+
index++;
|
|
731
|
+
for (;index < max; index++) {
|
|
732
|
+
ch = data[index];
|
|
733
|
+
if (ch === "_")
|
|
734
|
+
continue;
|
|
735
|
+
if (!isHexCode(data.charCodeAt(index)))
|
|
736
|
+
return false;
|
|
737
|
+
hasDigits = true;
|
|
738
|
+
}
|
|
739
|
+
return hasDigits && ch !== "_";
|
|
740
|
+
}
|
|
741
|
+
for (;index < max; index++) {
|
|
742
|
+
ch = data[index];
|
|
743
|
+
if (ch === "_")
|
|
744
|
+
continue;
|
|
745
|
+
if (!isOctCode(data.charCodeAt(index)))
|
|
746
|
+
return false;
|
|
747
|
+
hasDigits = true;
|
|
748
|
+
}
|
|
749
|
+
return hasDigits && ch !== "_";
|
|
750
|
+
}
|
|
751
|
+
if (ch === "_")
|
|
752
|
+
return false;
|
|
753
|
+
for (;index < max; index++) {
|
|
754
|
+
ch = data[index];
|
|
755
|
+
if (ch === "_")
|
|
756
|
+
continue;
|
|
757
|
+
if (ch === ":")
|
|
758
|
+
break;
|
|
759
|
+
if (!isDecCode(data.charCodeAt(index))) {
|
|
760
|
+
return false;
|
|
761
|
+
}
|
|
762
|
+
hasDigits = true;
|
|
763
|
+
}
|
|
764
|
+
if (!hasDigits || ch === "_")
|
|
765
|
+
return false;
|
|
766
|
+
if (ch !== ":")
|
|
767
|
+
return true;
|
|
768
|
+
return /^(:[0-5]?[0-9])+$/.test(data.slice(index));
|
|
769
|
+
}
|
|
770
|
+
function constructYamlInteger(data) {
|
|
771
|
+
var value = data, sign = 1, ch, base, digits = [];
|
|
772
|
+
if (value.indexOf("_") !== -1) {
|
|
773
|
+
value = value.replace(/_/g, "");
|
|
774
|
+
}
|
|
775
|
+
ch = value[0];
|
|
776
|
+
if (ch === "-" || ch === "+") {
|
|
777
|
+
if (ch === "-")
|
|
778
|
+
sign = -1;
|
|
779
|
+
value = value.slice(1);
|
|
780
|
+
ch = value[0];
|
|
781
|
+
}
|
|
782
|
+
if (value === "0")
|
|
783
|
+
return 0;
|
|
784
|
+
if (ch === "0") {
|
|
785
|
+
if (value[1] === "b")
|
|
786
|
+
return sign * parseInt(value.slice(2), 2);
|
|
787
|
+
if (value[1] === "x")
|
|
788
|
+
return sign * parseInt(value, 16);
|
|
789
|
+
return sign * parseInt(value, 8);
|
|
790
|
+
}
|
|
791
|
+
if (value.indexOf(":") !== -1) {
|
|
792
|
+
value.split(":").forEach(function(v) {
|
|
793
|
+
digits.unshift(parseInt(v, 10));
|
|
794
|
+
});
|
|
795
|
+
value = 0;
|
|
796
|
+
base = 1;
|
|
797
|
+
digits.forEach(function(d) {
|
|
798
|
+
value += d * base;
|
|
799
|
+
base *= 60;
|
|
800
|
+
});
|
|
801
|
+
return sign * value;
|
|
802
|
+
}
|
|
803
|
+
return sign * parseInt(value, 10);
|
|
804
|
+
}
|
|
805
|
+
function isInteger(object) {
|
|
806
|
+
return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 === 0 && !common.isNegativeZero(object));
|
|
807
|
+
}
|
|
808
|
+
module.exports = new Type("tag:yaml.org,2002:int", {
|
|
809
|
+
kind: "scalar",
|
|
810
|
+
resolve: resolveYamlInteger,
|
|
811
|
+
construct: constructYamlInteger,
|
|
812
|
+
predicate: isInteger,
|
|
813
|
+
represent: {
|
|
814
|
+
binary: function(obj) {
|
|
815
|
+
return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1);
|
|
816
|
+
},
|
|
817
|
+
octal: function(obj) {
|
|
818
|
+
return obj >= 0 ? "0" + obj.toString(8) : "-0" + obj.toString(8).slice(1);
|
|
819
|
+
},
|
|
820
|
+
decimal: function(obj) {
|
|
821
|
+
return obj.toString(10);
|
|
822
|
+
},
|
|
823
|
+
hexadecimal: function(obj) {
|
|
824
|
+
return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1);
|
|
825
|
+
}
|
|
826
|
+
},
|
|
827
|
+
defaultStyle: "decimal",
|
|
828
|
+
styleAliases: {
|
|
829
|
+
binary: [2, "bin"],
|
|
830
|
+
octal: [8, "oct"],
|
|
831
|
+
decimal: [10, "dec"],
|
|
832
|
+
hexadecimal: [16, "hex"]
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
});
|
|
836
|
+
|
|
837
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/float.js
|
|
838
|
+
var require_float = __commonJS((exports, module) => {
|
|
839
|
+
var common = require_common();
|
|
840
|
+
var Type = require_type();
|
|
841
|
+
var YAML_FLOAT_PATTERN = new RegExp("^(?:[-+]?(?:0|[1-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?" + "|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?" + "|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*" + "|[-+]?\\.(?:inf|Inf|INF)" + "|\\.(?:nan|NaN|NAN))$");
|
|
842
|
+
function resolveYamlFloat(data) {
|
|
843
|
+
if (data === null)
|
|
844
|
+
return false;
|
|
845
|
+
if (!YAML_FLOAT_PATTERN.test(data) || data[data.length - 1] === "_") {
|
|
846
|
+
return false;
|
|
847
|
+
}
|
|
848
|
+
return true;
|
|
849
|
+
}
|
|
850
|
+
function constructYamlFloat(data) {
|
|
851
|
+
var value, sign, base, digits;
|
|
852
|
+
value = data.replace(/_/g, "").toLowerCase();
|
|
853
|
+
sign = value[0] === "-" ? -1 : 1;
|
|
854
|
+
digits = [];
|
|
855
|
+
if ("+-".indexOf(value[0]) >= 0) {
|
|
856
|
+
value = value.slice(1);
|
|
857
|
+
}
|
|
858
|
+
if (value === ".inf") {
|
|
859
|
+
return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
860
|
+
} else if (value === ".nan") {
|
|
861
|
+
return NaN;
|
|
862
|
+
} else if (value.indexOf(":") >= 0) {
|
|
863
|
+
value.split(":").forEach(function(v) {
|
|
864
|
+
digits.unshift(parseFloat(v, 10));
|
|
865
|
+
});
|
|
866
|
+
value = 0;
|
|
867
|
+
base = 1;
|
|
868
|
+
digits.forEach(function(d) {
|
|
869
|
+
value += d * base;
|
|
870
|
+
base *= 60;
|
|
871
|
+
});
|
|
872
|
+
return sign * value;
|
|
873
|
+
}
|
|
874
|
+
return sign * parseFloat(value, 10);
|
|
875
|
+
}
|
|
876
|
+
var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
|
|
877
|
+
function representYamlFloat(object, style) {
|
|
878
|
+
var res;
|
|
879
|
+
if (isNaN(object)) {
|
|
880
|
+
switch (style) {
|
|
881
|
+
case "lowercase":
|
|
882
|
+
return ".nan";
|
|
883
|
+
case "uppercase":
|
|
884
|
+
return ".NAN";
|
|
885
|
+
case "camelcase":
|
|
886
|
+
return ".NaN";
|
|
887
|
+
}
|
|
888
|
+
} else if (Number.POSITIVE_INFINITY === object) {
|
|
889
|
+
switch (style) {
|
|
890
|
+
case "lowercase":
|
|
891
|
+
return ".inf";
|
|
892
|
+
case "uppercase":
|
|
893
|
+
return ".INF";
|
|
894
|
+
case "camelcase":
|
|
895
|
+
return ".Inf";
|
|
896
|
+
}
|
|
897
|
+
} else if (Number.NEGATIVE_INFINITY === object) {
|
|
898
|
+
switch (style) {
|
|
899
|
+
case "lowercase":
|
|
900
|
+
return "-.inf";
|
|
901
|
+
case "uppercase":
|
|
902
|
+
return "-.INF";
|
|
903
|
+
case "camelcase":
|
|
904
|
+
return "-.Inf";
|
|
905
|
+
}
|
|
906
|
+
} else if (common.isNegativeZero(object)) {
|
|
907
|
+
return "-0.0";
|
|
908
|
+
}
|
|
909
|
+
res = object.toString(10);
|
|
910
|
+
return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace("e", ".e") : res;
|
|
911
|
+
}
|
|
912
|
+
function isFloat(object) {
|
|
913
|
+
return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || common.isNegativeZero(object));
|
|
914
|
+
}
|
|
915
|
+
module.exports = new Type("tag:yaml.org,2002:float", {
|
|
916
|
+
kind: "scalar",
|
|
917
|
+
resolve: resolveYamlFloat,
|
|
918
|
+
construct: constructYamlFloat,
|
|
919
|
+
predicate: isFloat,
|
|
920
|
+
represent: representYamlFloat,
|
|
921
|
+
defaultStyle: "lowercase"
|
|
922
|
+
});
|
|
923
|
+
});
|
|
924
|
+
|
|
925
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/schema/json.js
|
|
926
|
+
var require_json = __commonJS((exports, module) => {
|
|
927
|
+
var Schema = require_schema();
|
|
928
|
+
module.exports = new Schema({
|
|
929
|
+
include: [
|
|
930
|
+
require_failsafe()
|
|
931
|
+
],
|
|
932
|
+
implicit: [
|
|
933
|
+
require_null(),
|
|
934
|
+
require_bool(),
|
|
935
|
+
require_int(),
|
|
936
|
+
require_float()
|
|
937
|
+
]
|
|
938
|
+
});
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/schema/core.js
|
|
942
|
+
var require_core = __commonJS((exports, module) => {
|
|
943
|
+
var Schema = require_schema();
|
|
944
|
+
module.exports = new Schema({
|
|
945
|
+
include: [
|
|
946
|
+
require_json()
|
|
947
|
+
]
|
|
948
|
+
});
|
|
949
|
+
});
|
|
950
|
+
|
|
951
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/timestamp.js
|
|
952
|
+
var require_timestamp = __commonJS((exports, module) => {
|
|
953
|
+
var Type = require_type();
|
|
954
|
+
var YAML_DATE_REGEXP = new RegExp("^([0-9][0-9][0-9][0-9])" + "-([0-9][0-9])" + "-([0-9][0-9])$");
|
|
955
|
+
var YAML_TIMESTAMP_REGEXP = new RegExp("^([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]))?))?$");
|
|
956
|
+
function resolveYamlTimestamp(data) {
|
|
957
|
+
if (data === null)
|
|
958
|
+
return false;
|
|
959
|
+
if (YAML_DATE_REGEXP.exec(data) !== null)
|
|
960
|
+
return true;
|
|
961
|
+
if (YAML_TIMESTAMP_REGEXP.exec(data) !== null)
|
|
962
|
+
return true;
|
|
963
|
+
return false;
|
|
964
|
+
}
|
|
965
|
+
function constructYamlTimestamp(data) {
|
|
966
|
+
var match, year, month, day, hour, minute, second, fraction = 0, delta = null, tz_hour, tz_minute, date;
|
|
967
|
+
match = YAML_DATE_REGEXP.exec(data);
|
|
968
|
+
if (match === null)
|
|
969
|
+
match = YAML_TIMESTAMP_REGEXP.exec(data);
|
|
970
|
+
if (match === null)
|
|
971
|
+
throw new Error("Date resolve error");
|
|
972
|
+
year = +match[1];
|
|
973
|
+
month = +match[2] - 1;
|
|
974
|
+
day = +match[3];
|
|
975
|
+
if (!match[4]) {
|
|
976
|
+
return new Date(Date.UTC(year, month, day));
|
|
977
|
+
}
|
|
978
|
+
hour = +match[4];
|
|
979
|
+
minute = +match[5];
|
|
980
|
+
second = +match[6];
|
|
981
|
+
if (match[7]) {
|
|
982
|
+
fraction = match[7].slice(0, 3);
|
|
983
|
+
while (fraction.length < 3) {
|
|
984
|
+
fraction += "0";
|
|
985
|
+
}
|
|
986
|
+
fraction = +fraction;
|
|
987
|
+
}
|
|
988
|
+
if (match[9]) {
|
|
989
|
+
tz_hour = +match[10];
|
|
990
|
+
tz_minute = +(match[11] || 0);
|
|
991
|
+
delta = (tz_hour * 60 + tz_minute) * 60000;
|
|
992
|
+
if (match[9] === "-")
|
|
993
|
+
delta = -delta;
|
|
994
|
+
}
|
|
995
|
+
date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
|
|
996
|
+
if (delta)
|
|
997
|
+
date.setTime(date.getTime() - delta);
|
|
998
|
+
return date;
|
|
999
|
+
}
|
|
1000
|
+
function representYamlTimestamp(object) {
|
|
1001
|
+
return object.toISOString();
|
|
1002
|
+
}
|
|
1003
|
+
module.exports = new Type("tag:yaml.org,2002:timestamp", {
|
|
1004
|
+
kind: "scalar",
|
|
1005
|
+
resolve: resolveYamlTimestamp,
|
|
1006
|
+
construct: constructYamlTimestamp,
|
|
1007
|
+
instanceOf: Date,
|
|
1008
|
+
represent: representYamlTimestamp
|
|
1009
|
+
});
|
|
1010
|
+
});
|
|
1011
|
+
|
|
1012
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/merge.js
|
|
1013
|
+
var require_merge = __commonJS((exports, module) => {
|
|
1014
|
+
var Type = require_type();
|
|
1015
|
+
function resolveYamlMerge(data) {
|
|
1016
|
+
return data === "<<" || data === null;
|
|
1017
|
+
}
|
|
1018
|
+
module.exports = new Type("tag:yaml.org,2002:merge", {
|
|
1019
|
+
kind: "scalar",
|
|
1020
|
+
resolve: resolveYamlMerge
|
|
1021
|
+
});
|
|
1022
|
+
});
|
|
1023
|
+
|
|
1024
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/binary.js
|
|
1025
|
+
var require_binary = __commonJS((exports, module) => {
|
|
1026
|
+
var NodeBuffer;
|
|
1027
|
+
try {
|
|
1028
|
+
_require = __require;
|
|
1029
|
+
NodeBuffer = _require("buffer").Buffer;
|
|
1030
|
+
} catch (__) {}
|
|
1031
|
+
var _require;
|
|
1032
|
+
var Type = require_type();
|
|
1033
|
+
var BASE64_MAP = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
|
|
1034
|
+
\r`;
|
|
1035
|
+
function resolveYamlBinary(data) {
|
|
1036
|
+
if (data === null)
|
|
1037
|
+
return false;
|
|
1038
|
+
var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP;
|
|
1039
|
+
for (idx = 0;idx < max; idx++) {
|
|
1040
|
+
code = map.indexOf(data.charAt(idx));
|
|
1041
|
+
if (code > 64)
|
|
1042
|
+
continue;
|
|
1043
|
+
if (code < 0)
|
|
1044
|
+
return false;
|
|
1045
|
+
bitlen += 6;
|
|
1046
|
+
}
|
|
1047
|
+
return bitlen % 8 === 0;
|
|
1048
|
+
}
|
|
1049
|
+
function constructYamlBinary(data) {
|
|
1050
|
+
var idx, tailbits, input = data.replace(/[\r\n=]/g, ""), max = input.length, map = BASE64_MAP, bits = 0, result = [];
|
|
1051
|
+
for (idx = 0;idx < max; idx++) {
|
|
1052
|
+
if (idx % 4 === 0 && idx) {
|
|
1053
|
+
result.push(bits >> 16 & 255);
|
|
1054
|
+
result.push(bits >> 8 & 255);
|
|
1055
|
+
result.push(bits & 255);
|
|
1056
|
+
}
|
|
1057
|
+
bits = bits << 6 | map.indexOf(input.charAt(idx));
|
|
1058
|
+
}
|
|
1059
|
+
tailbits = max % 4 * 6;
|
|
1060
|
+
if (tailbits === 0) {
|
|
1061
|
+
result.push(bits >> 16 & 255);
|
|
1062
|
+
result.push(bits >> 8 & 255);
|
|
1063
|
+
result.push(bits & 255);
|
|
1064
|
+
} else if (tailbits === 18) {
|
|
1065
|
+
result.push(bits >> 10 & 255);
|
|
1066
|
+
result.push(bits >> 2 & 255);
|
|
1067
|
+
} else if (tailbits === 12) {
|
|
1068
|
+
result.push(bits >> 4 & 255);
|
|
1069
|
+
}
|
|
1070
|
+
if (NodeBuffer) {
|
|
1071
|
+
return NodeBuffer.from ? NodeBuffer.from(result) : new NodeBuffer(result);
|
|
1072
|
+
}
|
|
1073
|
+
return result;
|
|
1074
|
+
}
|
|
1075
|
+
function representYamlBinary(object) {
|
|
1076
|
+
var result = "", bits = 0, idx, tail, max = object.length, map = BASE64_MAP;
|
|
1077
|
+
for (idx = 0;idx < max; idx++) {
|
|
1078
|
+
if (idx % 3 === 0 && idx) {
|
|
1079
|
+
result += map[bits >> 18 & 63];
|
|
1080
|
+
result += map[bits >> 12 & 63];
|
|
1081
|
+
result += map[bits >> 6 & 63];
|
|
1082
|
+
result += map[bits & 63];
|
|
1083
|
+
}
|
|
1084
|
+
bits = (bits << 8) + object[idx];
|
|
1085
|
+
}
|
|
1086
|
+
tail = max % 3;
|
|
1087
|
+
if (tail === 0) {
|
|
1088
|
+
result += map[bits >> 18 & 63];
|
|
1089
|
+
result += map[bits >> 12 & 63];
|
|
1090
|
+
result += map[bits >> 6 & 63];
|
|
1091
|
+
result += map[bits & 63];
|
|
1092
|
+
} else if (tail === 2) {
|
|
1093
|
+
result += map[bits >> 10 & 63];
|
|
1094
|
+
result += map[bits >> 4 & 63];
|
|
1095
|
+
result += map[bits << 2 & 63];
|
|
1096
|
+
result += map[64];
|
|
1097
|
+
} else if (tail === 1) {
|
|
1098
|
+
result += map[bits >> 2 & 63];
|
|
1099
|
+
result += map[bits << 4 & 63];
|
|
1100
|
+
result += map[64];
|
|
1101
|
+
result += map[64];
|
|
1102
|
+
}
|
|
1103
|
+
return result;
|
|
1104
|
+
}
|
|
1105
|
+
function isBinary(object) {
|
|
1106
|
+
return NodeBuffer && NodeBuffer.isBuffer(object);
|
|
1107
|
+
}
|
|
1108
|
+
module.exports = new Type("tag:yaml.org,2002:binary", {
|
|
1109
|
+
kind: "scalar",
|
|
1110
|
+
resolve: resolveYamlBinary,
|
|
1111
|
+
construct: constructYamlBinary,
|
|
1112
|
+
predicate: isBinary,
|
|
1113
|
+
represent: representYamlBinary
|
|
1114
|
+
});
|
|
1115
|
+
});
|
|
1116
|
+
|
|
1117
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/omap.js
|
|
1118
|
+
var require_omap = __commonJS((exports, module) => {
|
|
1119
|
+
var Type = require_type();
|
|
1120
|
+
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1121
|
+
var _toString = Object.prototype.toString;
|
|
1122
|
+
function resolveYamlOmap(data) {
|
|
1123
|
+
if (data === null)
|
|
1124
|
+
return true;
|
|
1125
|
+
var objectKeys = [], index, length, pair, pairKey, pairHasKey, object = data;
|
|
1126
|
+
for (index = 0, length = object.length;index < length; index += 1) {
|
|
1127
|
+
pair = object[index];
|
|
1128
|
+
pairHasKey = false;
|
|
1129
|
+
if (_toString.call(pair) !== "[object Object]")
|
|
1130
|
+
return false;
|
|
1131
|
+
for (pairKey in pair) {
|
|
1132
|
+
if (_hasOwnProperty.call(pair, pairKey)) {
|
|
1133
|
+
if (!pairHasKey)
|
|
1134
|
+
pairHasKey = true;
|
|
1135
|
+
else
|
|
1136
|
+
return false;
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
if (!pairHasKey)
|
|
1140
|
+
return false;
|
|
1141
|
+
if (objectKeys.indexOf(pairKey) === -1)
|
|
1142
|
+
objectKeys.push(pairKey);
|
|
1143
|
+
else
|
|
1144
|
+
return false;
|
|
1145
|
+
}
|
|
1146
|
+
return true;
|
|
1147
|
+
}
|
|
1148
|
+
function constructYamlOmap(data) {
|
|
1149
|
+
return data !== null ? data : [];
|
|
1150
|
+
}
|
|
1151
|
+
module.exports = new Type("tag:yaml.org,2002:omap", {
|
|
1152
|
+
kind: "sequence",
|
|
1153
|
+
resolve: resolveYamlOmap,
|
|
1154
|
+
construct: constructYamlOmap
|
|
1155
|
+
});
|
|
1156
|
+
});
|
|
1157
|
+
|
|
1158
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/pairs.js
|
|
1159
|
+
var require_pairs = __commonJS((exports, module) => {
|
|
1160
|
+
var Type = require_type();
|
|
1161
|
+
var _toString = Object.prototype.toString;
|
|
1162
|
+
function resolveYamlPairs(data) {
|
|
1163
|
+
if (data === null)
|
|
1164
|
+
return true;
|
|
1165
|
+
var index, length, pair, keys, result, object = data;
|
|
1166
|
+
result = new Array(object.length);
|
|
1167
|
+
for (index = 0, length = object.length;index < length; index += 1) {
|
|
1168
|
+
pair = object[index];
|
|
1169
|
+
if (_toString.call(pair) !== "[object Object]")
|
|
1170
|
+
return false;
|
|
1171
|
+
keys = Object.keys(pair);
|
|
1172
|
+
if (keys.length !== 1)
|
|
1173
|
+
return false;
|
|
1174
|
+
result[index] = [keys[0], pair[keys[0]]];
|
|
1175
|
+
}
|
|
1176
|
+
return true;
|
|
1177
|
+
}
|
|
1178
|
+
function constructYamlPairs(data) {
|
|
1179
|
+
if (data === null)
|
|
1180
|
+
return [];
|
|
1181
|
+
var index, length, pair, keys, result, object = data;
|
|
1182
|
+
result = new Array(object.length);
|
|
1183
|
+
for (index = 0, length = object.length;index < length; index += 1) {
|
|
1184
|
+
pair = object[index];
|
|
1185
|
+
keys = Object.keys(pair);
|
|
1186
|
+
result[index] = [keys[0], pair[keys[0]]];
|
|
1187
|
+
}
|
|
1188
|
+
return result;
|
|
1189
|
+
}
|
|
1190
|
+
module.exports = new Type("tag:yaml.org,2002:pairs", {
|
|
1191
|
+
kind: "sequence",
|
|
1192
|
+
resolve: resolveYamlPairs,
|
|
1193
|
+
construct: constructYamlPairs
|
|
1194
|
+
});
|
|
1195
|
+
});
|
|
1196
|
+
|
|
1197
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/set.js
|
|
1198
|
+
var require_set = __commonJS((exports, module) => {
|
|
1199
|
+
var Type = require_type();
|
|
1200
|
+
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1201
|
+
function resolveYamlSet(data) {
|
|
1202
|
+
if (data === null)
|
|
1203
|
+
return true;
|
|
1204
|
+
var key, object = data;
|
|
1205
|
+
for (key in object) {
|
|
1206
|
+
if (_hasOwnProperty.call(object, key)) {
|
|
1207
|
+
if (object[key] !== null)
|
|
1208
|
+
return false;
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
return true;
|
|
1212
|
+
}
|
|
1213
|
+
function constructYamlSet(data) {
|
|
1214
|
+
return data !== null ? data : {};
|
|
1215
|
+
}
|
|
1216
|
+
module.exports = new Type("tag:yaml.org,2002:set", {
|
|
1217
|
+
kind: "mapping",
|
|
1218
|
+
resolve: resolveYamlSet,
|
|
1219
|
+
construct: constructYamlSet
|
|
1220
|
+
});
|
|
1221
|
+
});
|
|
1222
|
+
|
|
1223
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/schema/default_safe.js
|
|
1224
|
+
var require_default_safe = __commonJS((exports, module) => {
|
|
1225
|
+
var Schema = require_schema();
|
|
1226
|
+
module.exports = new Schema({
|
|
1227
|
+
include: [
|
|
1228
|
+
require_core()
|
|
1229
|
+
],
|
|
1230
|
+
implicit: [
|
|
1231
|
+
require_timestamp(),
|
|
1232
|
+
require_merge()
|
|
1233
|
+
],
|
|
1234
|
+
explicit: [
|
|
1235
|
+
require_binary(),
|
|
1236
|
+
require_omap(),
|
|
1237
|
+
require_pairs(),
|
|
1238
|
+
require_set()
|
|
1239
|
+
]
|
|
1240
|
+
});
|
|
1241
|
+
});
|
|
1242
|
+
|
|
1243
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/js/undefined.js
|
|
1244
|
+
var require_undefined = __commonJS((exports, module) => {
|
|
1245
|
+
var Type = require_type();
|
|
1246
|
+
function resolveJavascriptUndefined() {
|
|
1247
|
+
return true;
|
|
1248
|
+
}
|
|
1249
|
+
function constructJavascriptUndefined() {
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
function representJavascriptUndefined() {
|
|
1253
|
+
return "";
|
|
1254
|
+
}
|
|
1255
|
+
function isUndefined(object) {
|
|
1256
|
+
return typeof object === "undefined";
|
|
1257
|
+
}
|
|
1258
|
+
module.exports = new Type("tag:yaml.org,2002:js/undefined", {
|
|
1259
|
+
kind: "scalar",
|
|
1260
|
+
resolve: resolveJavascriptUndefined,
|
|
1261
|
+
construct: constructJavascriptUndefined,
|
|
1262
|
+
predicate: isUndefined,
|
|
1263
|
+
represent: representJavascriptUndefined
|
|
1264
|
+
});
|
|
1265
|
+
});
|
|
1266
|
+
|
|
1267
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/js/regexp.js
|
|
1268
|
+
var require_regexp = __commonJS((exports, module) => {
|
|
1269
|
+
var Type = require_type();
|
|
1270
|
+
function resolveJavascriptRegExp(data) {
|
|
1271
|
+
if (data === null)
|
|
1272
|
+
return false;
|
|
1273
|
+
if (data.length === 0)
|
|
1274
|
+
return false;
|
|
1275
|
+
var regexp = data, tail = /\/([gim]*)$/.exec(data), modifiers = "";
|
|
1276
|
+
if (regexp[0] === "/") {
|
|
1277
|
+
if (tail)
|
|
1278
|
+
modifiers = tail[1];
|
|
1279
|
+
if (modifiers.length > 3)
|
|
1280
|
+
return false;
|
|
1281
|
+
if (regexp[regexp.length - modifiers.length - 1] !== "/")
|
|
1282
|
+
return false;
|
|
1283
|
+
}
|
|
1284
|
+
return true;
|
|
1285
|
+
}
|
|
1286
|
+
function constructJavascriptRegExp(data) {
|
|
1287
|
+
var regexp = data, tail = /\/([gim]*)$/.exec(data), modifiers = "";
|
|
1288
|
+
if (regexp[0] === "/") {
|
|
1289
|
+
if (tail)
|
|
1290
|
+
modifiers = tail[1];
|
|
1291
|
+
regexp = regexp.slice(1, regexp.length - modifiers.length - 1);
|
|
1292
|
+
}
|
|
1293
|
+
return new RegExp(regexp, modifiers);
|
|
1294
|
+
}
|
|
1295
|
+
function representJavascriptRegExp(object) {
|
|
1296
|
+
var result = "/" + object.source + "/";
|
|
1297
|
+
if (object.global)
|
|
1298
|
+
result += "g";
|
|
1299
|
+
if (object.multiline)
|
|
1300
|
+
result += "m";
|
|
1301
|
+
if (object.ignoreCase)
|
|
1302
|
+
result += "i";
|
|
1303
|
+
return result;
|
|
1304
|
+
}
|
|
1305
|
+
function isRegExp(object) {
|
|
1306
|
+
return Object.prototype.toString.call(object) === "[object RegExp]";
|
|
1307
|
+
}
|
|
1308
|
+
module.exports = new Type("tag:yaml.org,2002:js/regexp", {
|
|
1309
|
+
kind: "scalar",
|
|
1310
|
+
resolve: resolveJavascriptRegExp,
|
|
1311
|
+
construct: constructJavascriptRegExp,
|
|
1312
|
+
predicate: isRegExp,
|
|
1313
|
+
represent: representJavascriptRegExp
|
|
1314
|
+
});
|
|
1315
|
+
});
|
|
1316
|
+
|
|
1317
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/js/function.js
|
|
1318
|
+
var require_function = __commonJS((exports, module) => {
|
|
1319
|
+
var esprima;
|
|
1320
|
+
try {
|
|
1321
|
+
_require = __require;
|
|
1322
|
+
esprima = _require("esprima");
|
|
1323
|
+
} catch (_) {
|
|
1324
|
+
if (typeof window !== "undefined")
|
|
1325
|
+
esprima = window.esprima;
|
|
1326
|
+
}
|
|
1327
|
+
var _require;
|
|
1328
|
+
var Type = require_type();
|
|
1329
|
+
function resolveJavascriptFunction(data) {
|
|
1330
|
+
if (data === null)
|
|
1331
|
+
return false;
|
|
1332
|
+
try {
|
|
1333
|
+
var source = "(" + data + ")", ast = esprima.parse(source, { range: true });
|
|
1334
|
+
if (ast.type !== "Program" || ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement" || ast.body[0].expression.type !== "ArrowFunctionExpression" && ast.body[0].expression.type !== "FunctionExpression") {
|
|
1335
|
+
return false;
|
|
1336
|
+
}
|
|
1337
|
+
return true;
|
|
1338
|
+
} catch (err) {
|
|
1339
|
+
return false;
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
function constructJavascriptFunction(data) {
|
|
1343
|
+
var source = "(" + data + ")", ast = esprima.parse(source, { range: true }), params = [], body;
|
|
1344
|
+
if (ast.type !== "Program" || ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement" || ast.body[0].expression.type !== "ArrowFunctionExpression" && ast.body[0].expression.type !== "FunctionExpression") {
|
|
1345
|
+
throw new Error("Failed to resolve function");
|
|
1346
|
+
}
|
|
1347
|
+
ast.body[0].expression.params.forEach(function(param) {
|
|
1348
|
+
params.push(param.name);
|
|
1349
|
+
});
|
|
1350
|
+
body = ast.body[0].expression.body.range;
|
|
1351
|
+
if (ast.body[0].expression.body.type === "BlockStatement") {
|
|
1352
|
+
return new Function(params, source.slice(body[0] + 1, body[1] - 1));
|
|
1353
|
+
}
|
|
1354
|
+
return new Function(params, "return " + source.slice(body[0], body[1]));
|
|
1355
|
+
}
|
|
1356
|
+
function representJavascriptFunction(object) {
|
|
1357
|
+
return object.toString();
|
|
1358
|
+
}
|
|
1359
|
+
function isFunction(object) {
|
|
1360
|
+
return Object.prototype.toString.call(object) === "[object Function]";
|
|
1361
|
+
}
|
|
1362
|
+
module.exports = new Type("tag:yaml.org,2002:js/function", {
|
|
1363
|
+
kind: "scalar",
|
|
1364
|
+
resolve: resolveJavascriptFunction,
|
|
1365
|
+
construct: constructJavascriptFunction,
|
|
1366
|
+
predicate: isFunction,
|
|
1367
|
+
represent: representJavascriptFunction
|
|
1368
|
+
});
|
|
1369
|
+
});
|
|
1370
|
+
|
|
1371
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/schema/default_full.js
|
|
1372
|
+
var require_default_full = __commonJS((exports, module) => {
|
|
1373
|
+
var Schema = require_schema();
|
|
1374
|
+
module.exports = Schema.DEFAULT = new Schema({
|
|
1375
|
+
include: [
|
|
1376
|
+
require_default_safe()
|
|
1377
|
+
],
|
|
1378
|
+
explicit: [
|
|
1379
|
+
require_undefined(),
|
|
1380
|
+
require_regexp(),
|
|
1381
|
+
require_function()
|
|
1382
|
+
]
|
|
1383
|
+
});
|
|
1384
|
+
});
|
|
1385
|
+
|
|
1386
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/loader.js
|
|
1387
|
+
var require_loader = __commonJS((exports, module) => {
|
|
1388
|
+
var common = require_common();
|
|
1389
|
+
var YAMLException = require_exception();
|
|
1390
|
+
var Mark = require_mark();
|
|
1391
|
+
var DEFAULT_SAFE_SCHEMA = require_default_safe();
|
|
1392
|
+
var DEFAULT_FULL_SCHEMA = require_default_full();
|
|
1393
|
+
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1394
|
+
var CONTEXT_FLOW_IN = 1;
|
|
1395
|
+
var CONTEXT_FLOW_OUT = 2;
|
|
1396
|
+
var CONTEXT_BLOCK_IN = 3;
|
|
1397
|
+
var CONTEXT_BLOCK_OUT = 4;
|
|
1398
|
+
var CHOMPING_CLIP = 1;
|
|
1399
|
+
var CHOMPING_STRIP = 2;
|
|
1400
|
+
var CHOMPING_KEEP = 3;
|
|
1401
|
+
var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
|
|
1402
|
+
var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
|
|
1403
|
+
var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
|
|
1404
|
+
var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
|
|
1405
|
+
var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
|
|
1406
|
+
function _class(obj) {
|
|
1407
|
+
return Object.prototype.toString.call(obj);
|
|
1408
|
+
}
|
|
1409
|
+
function is_EOL(c) {
|
|
1410
|
+
return c === 10 || c === 13;
|
|
1411
|
+
}
|
|
1412
|
+
function is_WHITE_SPACE(c) {
|
|
1413
|
+
return c === 9 || c === 32;
|
|
1414
|
+
}
|
|
1415
|
+
function is_WS_OR_EOL(c) {
|
|
1416
|
+
return c === 9 || c === 32 || c === 10 || c === 13;
|
|
1417
|
+
}
|
|
1418
|
+
function is_FLOW_INDICATOR(c) {
|
|
1419
|
+
return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
|
|
1420
|
+
}
|
|
1421
|
+
function fromHexCode(c) {
|
|
1422
|
+
var lc;
|
|
1423
|
+
if (48 <= c && c <= 57) {
|
|
1424
|
+
return c - 48;
|
|
1425
|
+
}
|
|
1426
|
+
lc = c | 32;
|
|
1427
|
+
if (97 <= lc && lc <= 102) {
|
|
1428
|
+
return lc - 97 + 10;
|
|
1429
|
+
}
|
|
1430
|
+
return -1;
|
|
1431
|
+
}
|
|
1432
|
+
function escapedHexLen(c) {
|
|
1433
|
+
if (c === 120) {
|
|
1434
|
+
return 2;
|
|
1435
|
+
}
|
|
1436
|
+
if (c === 117) {
|
|
1437
|
+
return 4;
|
|
1438
|
+
}
|
|
1439
|
+
if (c === 85) {
|
|
1440
|
+
return 8;
|
|
1441
|
+
}
|
|
1442
|
+
return 0;
|
|
1443
|
+
}
|
|
1444
|
+
function fromDecimalCode(c) {
|
|
1445
|
+
if (48 <= c && c <= 57) {
|
|
1446
|
+
return c - 48;
|
|
1447
|
+
}
|
|
1448
|
+
return -1;
|
|
1449
|
+
}
|
|
1450
|
+
function simpleEscapeSequence(c) {
|
|
1451
|
+
return c === 48 ? "\x00" : c === 97 ? "\x07" : c === 98 ? "\b" : c === 116 ? "\t" : c === 9 ? "\t" : c === 110 ? `
|
|
1452
|
+
` : c === 118 ? "\v" : c === 102 ? "\f" : c === 114 ? "\r" : c === 101 ? "\x1B" : c === 32 ? " " : c === 34 ? '"' : c === 47 ? "/" : c === 92 ? "\\" : c === 78 ? "
" : c === 95 ? " " : c === 76 ? "\u2028" : c === 80 ? "\u2029" : "";
|
|
1453
|
+
}
|
|
1454
|
+
function charFromCodepoint(c) {
|
|
1455
|
+
if (c <= 65535) {
|
|
1456
|
+
return String.fromCharCode(c);
|
|
1457
|
+
}
|
|
1458
|
+
return String.fromCharCode((c - 65536 >> 10) + 55296, (c - 65536 & 1023) + 56320);
|
|
1459
|
+
}
|
|
1460
|
+
function setProperty(object, key, value) {
|
|
1461
|
+
if (key === "__proto__") {
|
|
1462
|
+
Object.defineProperty(object, key, {
|
|
1463
|
+
configurable: true,
|
|
1464
|
+
enumerable: true,
|
|
1465
|
+
writable: true,
|
|
1466
|
+
value
|
|
1467
|
+
});
|
|
1468
|
+
} else {
|
|
1469
|
+
object[key] = value;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
var simpleEscapeCheck = new Array(256);
|
|
1473
|
+
var simpleEscapeMap = new Array(256);
|
|
1474
|
+
for (i = 0;i < 256; i++) {
|
|
1475
|
+
simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
|
|
1476
|
+
simpleEscapeMap[i] = simpleEscapeSequence(i);
|
|
1477
|
+
}
|
|
1478
|
+
var i;
|
|
1479
|
+
function State(input, options2) {
|
|
1480
|
+
this.input = input;
|
|
1481
|
+
this.filename = options2["filename"] || null;
|
|
1482
|
+
this.schema = options2["schema"] || DEFAULT_FULL_SCHEMA;
|
|
1483
|
+
this.onWarning = options2["onWarning"] || null;
|
|
1484
|
+
this.legacy = options2["legacy"] || false;
|
|
1485
|
+
this.json = options2["json"] || false;
|
|
1486
|
+
this.listener = options2["listener"] || null;
|
|
1487
|
+
this.implicitTypes = this.schema.compiledImplicit;
|
|
1488
|
+
this.typeMap = this.schema.compiledTypeMap;
|
|
1489
|
+
this.length = input.length;
|
|
1490
|
+
this.position = 0;
|
|
1491
|
+
this.line = 0;
|
|
1492
|
+
this.lineStart = 0;
|
|
1493
|
+
this.lineIndent = 0;
|
|
1494
|
+
this.documents = [];
|
|
1495
|
+
}
|
|
1496
|
+
function generateError(state, message) {
|
|
1497
|
+
return new YAMLException(message, new Mark(state.filename, state.input, state.position, state.line, state.position - state.lineStart));
|
|
1498
|
+
}
|
|
1499
|
+
function throwError(state, message) {
|
|
1500
|
+
throw generateError(state, message);
|
|
1501
|
+
}
|
|
1502
|
+
function throwWarning(state, message) {
|
|
1503
|
+
if (state.onWarning) {
|
|
1504
|
+
state.onWarning.call(null, generateError(state, message));
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
var directiveHandlers = {
|
|
1508
|
+
YAML: function handleYamlDirective(state, name, args) {
|
|
1509
|
+
var match, major, minor;
|
|
1510
|
+
if (state.version !== null) {
|
|
1511
|
+
throwError(state, "duplication of %YAML directive");
|
|
1512
|
+
}
|
|
1513
|
+
if (args.length !== 1) {
|
|
1514
|
+
throwError(state, "YAML directive accepts exactly one argument");
|
|
1515
|
+
}
|
|
1516
|
+
match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
|
|
1517
|
+
if (match === null) {
|
|
1518
|
+
throwError(state, "ill-formed argument of the YAML directive");
|
|
1519
|
+
}
|
|
1520
|
+
major = parseInt(match[1], 10);
|
|
1521
|
+
minor = parseInt(match[2], 10);
|
|
1522
|
+
if (major !== 1) {
|
|
1523
|
+
throwError(state, "unacceptable YAML version of the document");
|
|
1524
|
+
}
|
|
1525
|
+
state.version = args[0];
|
|
1526
|
+
state.checkLineBreaks = minor < 2;
|
|
1527
|
+
if (minor !== 1 && minor !== 2) {
|
|
1528
|
+
throwWarning(state, "unsupported YAML version of the document");
|
|
1529
|
+
}
|
|
1530
|
+
},
|
|
1531
|
+
TAG: function handleTagDirective(state, name, args) {
|
|
1532
|
+
var handle, prefix;
|
|
1533
|
+
if (args.length !== 2) {
|
|
1534
|
+
throwError(state, "TAG directive accepts exactly two arguments");
|
|
1535
|
+
}
|
|
1536
|
+
handle = args[0];
|
|
1537
|
+
prefix = args[1];
|
|
1538
|
+
if (!PATTERN_TAG_HANDLE.test(handle)) {
|
|
1539
|
+
throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
|
|
1540
|
+
}
|
|
1541
|
+
if (_hasOwnProperty.call(state.tagMap, handle)) {
|
|
1542
|
+
throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
|
|
1543
|
+
}
|
|
1544
|
+
if (!PATTERN_TAG_URI.test(prefix)) {
|
|
1545
|
+
throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
|
|
1546
|
+
}
|
|
1547
|
+
state.tagMap[handle] = prefix;
|
|
1548
|
+
}
|
|
1549
|
+
};
|
|
1550
|
+
function captureSegment(state, start, end, checkJson) {
|
|
1551
|
+
var _position, _length, _character, _result;
|
|
1552
|
+
if (start < end) {
|
|
1553
|
+
_result = state.input.slice(start, end);
|
|
1554
|
+
if (checkJson) {
|
|
1555
|
+
for (_position = 0, _length = _result.length;_position < _length; _position += 1) {
|
|
1556
|
+
_character = _result.charCodeAt(_position);
|
|
1557
|
+
if (!(_character === 9 || 32 <= _character && _character <= 1114111)) {
|
|
1558
|
+
throwError(state, "expected valid JSON character");
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
} else if (PATTERN_NON_PRINTABLE.test(_result)) {
|
|
1562
|
+
throwError(state, "the stream contains non-printable characters");
|
|
1563
|
+
}
|
|
1564
|
+
state.result += _result;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
function mergeMappings(state, destination, source, overridableKeys) {
|
|
1568
|
+
var sourceKeys, key, index, quantity;
|
|
1569
|
+
if (!common.isObject(source)) {
|
|
1570
|
+
throwError(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
1571
|
+
}
|
|
1572
|
+
sourceKeys = Object.keys(source);
|
|
1573
|
+
for (index = 0, quantity = sourceKeys.length;index < quantity; index += 1) {
|
|
1574
|
+
key = sourceKeys[index];
|
|
1575
|
+
if (!_hasOwnProperty.call(destination, key)) {
|
|
1576
|
+
setProperty(destination, key, source[key]);
|
|
1577
|
+
overridableKeys[key] = true;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startPos) {
|
|
1582
|
+
var index, quantity;
|
|
1583
|
+
if (Array.isArray(keyNode)) {
|
|
1584
|
+
keyNode = Array.prototype.slice.call(keyNode);
|
|
1585
|
+
for (index = 0, quantity = keyNode.length;index < quantity; index += 1) {
|
|
1586
|
+
if (Array.isArray(keyNode[index])) {
|
|
1587
|
+
throwError(state, "nested arrays are not supported inside keys");
|
|
1588
|
+
}
|
|
1589
|
+
if (typeof keyNode === "object" && _class(keyNode[index]) === "[object Object]") {
|
|
1590
|
+
keyNode[index] = "[object Object]";
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
if (typeof keyNode === "object" && _class(keyNode) === "[object Object]") {
|
|
1595
|
+
keyNode = "[object Object]";
|
|
1596
|
+
}
|
|
1597
|
+
keyNode = String(keyNode);
|
|
1598
|
+
if (_result === null) {
|
|
1599
|
+
_result = {};
|
|
1600
|
+
}
|
|
1601
|
+
if (keyTag === "tag:yaml.org,2002:merge") {
|
|
1602
|
+
if (Array.isArray(valueNode)) {
|
|
1603
|
+
for (index = 0, quantity = valueNode.length;index < quantity; index += 1) {
|
|
1604
|
+
mergeMappings(state, _result, valueNode[index], overridableKeys);
|
|
1605
|
+
}
|
|
1606
|
+
} else {
|
|
1607
|
+
mergeMappings(state, _result, valueNode, overridableKeys);
|
|
1608
|
+
}
|
|
1609
|
+
} else {
|
|
1610
|
+
if (!state.json && !_hasOwnProperty.call(overridableKeys, keyNode) && _hasOwnProperty.call(_result, keyNode)) {
|
|
1611
|
+
state.line = startLine || state.line;
|
|
1612
|
+
state.position = startPos || state.position;
|
|
1613
|
+
throwError(state, "duplicated mapping key");
|
|
1614
|
+
}
|
|
1615
|
+
setProperty(_result, keyNode, valueNode);
|
|
1616
|
+
delete overridableKeys[keyNode];
|
|
1617
|
+
}
|
|
1618
|
+
return _result;
|
|
1619
|
+
}
|
|
1620
|
+
function readLineBreak(state) {
|
|
1621
|
+
var ch;
|
|
1622
|
+
ch = state.input.charCodeAt(state.position);
|
|
1623
|
+
if (ch === 10) {
|
|
1624
|
+
state.position++;
|
|
1625
|
+
} else if (ch === 13) {
|
|
1626
|
+
state.position++;
|
|
1627
|
+
if (state.input.charCodeAt(state.position) === 10) {
|
|
1628
|
+
state.position++;
|
|
1629
|
+
}
|
|
1630
|
+
} else {
|
|
1631
|
+
throwError(state, "a line break is expected");
|
|
1632
|
+
}
|
|
1633
|
+
state.line += 1;
|
|
1634
|
+
state.lineStart = state.position;
|
|
1635
|
+
}
|
|
1636
|
+
function skipSeparationSpace(state, allowComments, checkIndent) {
|
|
1637
|
+
var lineBreaks = 0, ch = state.input.charCodeAt(state.position);
|
|
1638
|
+
while (ch !== 0) {
|
|
1639
|
+
while (is_WHITE_SPACE(ch)) {
|
|
1640
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1641
|
+
}
|
|
1642
|
+
if (allowComments && ch === 35) {
|
|
1643
|
+
do {
|
|
1644
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1645
|
+
} while (ch !== 10 && ch !== 13 && ch !== 0);
|
|
1646
|
+
}
|
|
1647
|
+
if (is_EOL(ch)) {
|
|
1648
|
+
readLineBreak(state);
|
|
1649
|
+
ch = state.input.charCodeAt(state.position);
|
|
1650
|
+
lineBreaks++;
|
|
1651
|
+
state.lineIndent = 0;
|
|
1652
|
+
while (ch === 32) {
|
|
1653
|
+
state.lineIndent++;
|
|
1654
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1655
|
+
}
|
|
1656
|
+
} else {
|
|
1657
|
+
break;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
|
|
1661
|
+
throwWarning(state, "deficient indentation");
|
|
1662
|
+
}
|
|
1663
|
+
return lineBreaks;
|
|
1664
|
+
}
|
|
1665
|
+
function testDocumentSeparator(state) {
|
|
1666
|
+
var _position = state.position, ch;
|
|
1667
|
+
ch = state.input.charCodeAt(_position);
|
|
1668
|
+
if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(_position + 1) && ch === state.input.charCodeAt(_position + 2)) {
|
|
1669
|
+
_position += 3;
|
|
1670
|
+
ch = state.input.charCodeAt(_position);
|
|
1671
|
+
if (ch === 0 || is_WS_OR_EOL(ch)) {
|
|
1672
|
+
return true;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
return false;
|
|
1676
|
+
}
|
|
1677
|
+
function writeFoldedLines(state, count) {
|
|
1678
|
+
if (count === 1) {
|
|
1679
|
+
state.result += " ";
|
|
1680
|
+
} else if (count > 1) {
|
|
1681
|
+
state.result += common.repeat(`
|
|
1682
|
+
`, count - 1);
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
function readPlainScalar(state, nodeIndent, withinFlowCollection) {
|
|
1686
|
+
var preceding, following, captureStart, captureEnd, hasPendingContent, _line, _lineStart, _lineIndent, _kind = state.kind, _result = state.result, ch;
|
|
1687
|
+
ch = state.input.charCodeAt(state.position);
|
|
1688
|
+
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) {
|
|
1689
|
+
return false;
|
|
1690
|
+
}
|
|
1691
|
+
if (ch === 63 || ch === 45) {
|
|
1692
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1693
|
+
if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
|
1694
|
+
return false;
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
state.kind = "scalar";
|
|
1698
|
+
state.result = "";
|
|
1699
|
+
captureStart = captureEnd = state.position;
|
|
1700
|
+
hasPendingContent = false;
|
|
1701
|
+
while (ch !== 0) {
|
|
1702
|
+
if (ch === 58) {
|
|
1703
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1704
|
+
if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
|
1705
|
+
break;
|
|
1706
|
+
}
|
|
1707
|
+
} else if (ch === 35) {
|
|
1708
|
+
preceding = state.input.charCodeAt(state.position - 1);
|
|
1709
|
+
if (is_WS_OR_EOL(preceding)) {
|
|
1710
|
+
break;
|
|
1711
|
+
}
|
|
1712
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state) || withinFlowCollection && is_FLOW_INDICATOR(ch)) {
|
|
1713
|
+
break;
|
|
1714
|
+
} else if (is_EOL(ch)) {
|
|
1715
|
+
_line = state.line;
|
|
1716
|
+
_lineStart = state.lineStart;
|
|
1717
|
+
_lineIndent = state.lineIndent;
|
|
1718
|
+
skipSeparationSpace(state, false, -1);
|
|
1719
|
+
if (state.lineIndent >= nodeIndent) {
|
|
1720
|
+
hasPendingContent = true;
|
|
1721
|
+
ch = state.input.charCodeAt(state.position);
|
|
1722
|
+
continue;
|
|
1723
|
+
} else {
|
|
1724
|
+
state.position = captureEnd;
|
|
1725
|
+
state.line = _line;
|
|
1726
|
+
state.lineStart = _lineStart;
|
|
1727
|
+
state.lineIndent = _lineIndent;
|
|
1728
|
+
break;
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
if (hasPendingContent) {
|
|
1732
|
+
captureSegment(state, captureStart, captureEnd, false);
|
|
1733
|
+
writeFoldedLines(state, state.line - _line);
|
|
1734
|
+
captureStart = captureEnd = state.position;
|
|
1735
|
+
hasPendingContent = false;
|
|
1736
|
+
}
|
|
1737
|
+
if (!is_WHITE_SPACE(ch)) {
|
|
1738
|
+
captureEnd = state.position + 1;
|
|
1739
|
+
}
|
|
1740
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1741
|
+
}
|
|
1742
|
+
captureSegment(state, captureStart, captureEnd, false);
|
|
1743
|
+
if (state.result) {
|
|
1744
|
+
return true;
|
|
1745
|
+
}
|
|
1746
|
+
state.kind = _kind;
|
|
1747
|
+
state.result = _result;
|
|
1748
|
+
return false;
|
|
1749
|
+
}
|
|
1750
|
+
function readSingleQuotedScalar(state, nodeIndent) {
|
|
1751
|
+
var ch, captureStart, captureEnd;
|
|
1752
|
+
ch = state.input.charCodeAt(state.position);
|
|
1753
|
+
if (ch !== 39) {
|
|
1754
|
+
return false;
|
|
1755
|
+
}
|
|
1756
|
+
state.kind = "scalar";
|
|
1757
|
+
state.result = "";
|
|
1758
|
+
state.position++;
|
|
1759
|
+
captureStart = captureEnd = state.position;
|
|
1760
|
+
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
1761
|
+
if (ch === 39) {
|
|
1762
|
+
captureSegment(state, captureStart, state.position, true);
|
|
1763
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1764
|
+
if (ch === 39) {
|
|
1765
|
+
captureStart = state.position;
|
|
1766
|
+
state.position++;
|
|
1767
|
+
captureEnd = state.position;
|
|
1768
|
+
} else {
|
|
1769
|
+
return true;
|
|
1770
|
+
}
|
|
1771
|
+
} else if (is_EOL(ch)) {
|
|
1772
|
+
captureSegment(state, captureStart, captureEnd, true);
|
|
1773
|
+
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
1774
|
+
captureStart = captureEnd = state.position;
|
|
1775
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1776
|
+
throwError(state, "unexpected end of the document within a single quoted scalar");
|
|
1777
|
+
} else {
|
|
1778
|
+
state.position++;
|
|
1779
|
+
captureEnd = state.position;
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
throwError(state, "unexpected end of the stream within a single quoted scalar");
|
|
1783
|
+
}
|
|
1784
|
+
function readDoubleQuotedScalar(state, nodeIndent) {
|
|
1785
|
+
var captureStart, captureEnd, hexLength, hexResult, tmp, ch;
|
|
1786
|
+
ch = state.input.charCodeAt(state.position);
|
|
1787
|
+
if (ch !== 34) {
|
|
1788
|
+
return false;
|
|
1789
|
+
}
|
|
1790
|
+
state.kind = "scalar";
|
|
1791
|
+
state.result = "";
|
|
1792
|
+
state.position++;
|
|
1793
|
+
captureStart = captureEnd = state.position;
|
|
1794
|
+
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
1795
|
+
if (ch === 34) {
|
|
1796
|
+
captureSegment(state, captureStart, state.position, true);
|
|
1797
|
+
state.position++;
|
|
1798
|
+
return true;
|
|
1799
|
+
} else if (ch === 92) {
|
|
1800
|
+
captureSegment(state, captureStart, state.position, true);
|
|
1801
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1802
|
+
if (is_EOL(ch)) {
|
|
1803
|
+
skipSeparationSpace(state, false, nodeIndent);
|
|
1804
|
+
} else if (ch < 256 && simpleEscapeCheck[ch]) {
|
|
1805
|
+
state.result += simpleEscapeMap[ch];
|
|
1806
|
+
state.position++;
|
|
1807
|
+
} else if ((tmp = escapedHexLen(ch)) > 0) {
|
|
1808
|
+
hexLength = tmp;
|
|
1809
|
+
hexResult = 0;
|
|
1810
|
+
for (;hexLength > 0; hexLength--) {
|
|
1811
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1812
|
+
if ((tmp = fromHexCode(ch)) >= 0) {
|
|
1813
|
+
hexResult = (hexResult << 4) + tmp;
|
|
1814
|
+
} else {
|
|
1815
|
+
throwError(state, "expected hexadecimal character");
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
state.result += charFromCodepoint(hexResult);
|
|
1819
|
+
state.position++;
|
|
1820
|
+
} else {
|
|
1821
|
+
throwError(state, "unknown escape sequence");
|
|
1822
|
+
}
|
|
1823
|
+
captureStart = captureEnd = state.position;
|
|
1824
|
+
} else if (is_EOL(ch)) {
|
|
1825
|
+
captureSegment(state, captureStart, captureEnd, true);
|
|
1826
|
+
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
1827
|
+
captureStart = captureEnd = state.position;
|
|
1828
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1829
|
+
throwError(state, "unexpected end of the document within a double quoted scalar");
|
|
1830
|
+
} else {
|
|
1831
|
+
state.position++;
|
|
1832
|
+
captureEnd = state.position;
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
throwError(state, "unexpected end of the stream within a double quoted scalar");
|
|
1836
|
+
}
|
|
1837
|
+
function readFlowCollection(state, nodeIndent) {
|
|
1838
|
+
var readNext = true, _line, _tag = state.tag, _result, _anchor = state.anchor, following, terminator, isPair, isExplicitPair, isMapping, overridableKeys = {}, keyNode, keyTag, valueNode, ch;
|
|
1839
|
+
ch = state.input.charCodeAt(state.position);
|
|
1840
|
+
if (ch === 91) {
|
|
1841
|
+
terminator = 93;
|
|
1842
|
+
isMapping = false;
|
|
1843
|
+
_result = [];
|
|
1844
|
+
} else if (ch === 123) {
|
|
1845
|
+
terminator = 125;
|
|
1846
|
+
isMapping = true;
|
|
1847
|
+
_result = {};
|
|
1848
|
+
} else {
|
|
1849
|
+
return false;
|
|
1850
|
+
}
|
|
1851
|
+
if (state.anchor !== null) {
|
|
1852
|
+
state.anchorMap[state.anchor] = _result;
|
|
1853
|
+
}
|
|
1854
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1855
|
+
while (ch !== 0) {
|
|
1856
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1857
|
+
ch = state.input.charCodeAt(state.position);
|
|
1858
|
+
if (ch === terminator) {
|
|
1859
|
+
state.position++;
|
|
1860
|
+
state.tag = _tag;
|
|
1861
|
+
state.anchor = _anchor;
|
|
1862
|
+
state.kind = isMapping ? "mapping" : "sequence";
|
|
1863
|
+
state.result = _result;
|
|
1864
|
+
return true;
|
|
1865
|
+
} else if (!readNext) {
|
|
1866
|
+
throwError(state, "missed comma between flow collection entries");
|
|
1867
|
+
}
|
|
1868
|
+
keyTag = keyNode = valueNode = null;
|
|
1869
|
+
isPair = isExplicitPair = false;
|
|
1870
|
+
if (ch === 63) {
|
|
1871
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1872
|
+
if (is_WS_OR_EOL(following)) {
|
|
1873
|
+
isPair = isExplicitPair = true;
|
|
1874
|
+
state.position++;
|
|
1875
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
_line = state.line;
|
|
1879
|
+
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
1880
|
+
keyTag = state.tag;
|
|
1881
|
+
keyNode = state.result;
|
|
1882
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1883
|
+
ch = state.input.charCodeAt(state.position);
|
|
1884
|
+
if ((isExplicitPair || state.line === _line) && ch === 58) {
|
|
1885
|
+
isPair = true;
|
|
1886
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1887
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1888
|
+
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
1889
|
+
valueNode = state.result;
|
|
1890
|
+
}
|
|
1891
|
+
if (isMapping) {
|
|
1892
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
|
|
1893
|
+
} else if (isPair) {
|
|
1894
|
+
_result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode));
|
|
1895
|
+
} else {
|
|
1896
|
+
_result.push(keyNode);
|
|
1897
|
+
}
|
|
1898
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1899
|
+
ch = state.input.charCodeAt(state.position);
|
|
1900
|
+
if (ch === 44) {
|
|
1901
|
+
readNext = true;
|
|
1902
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1903
|
+
} else {
|
|
1904
|
+
readNext = false;
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
throwError(state, "unexpected end of the stream within a flow collection");
|
|
1908
|
+
}
|
|
1909
|
+
function readBlockScalar(state, nodeIndent) {
|
|
1910
|
+
var captureStart, folding, chomping = CHOMPING_CLIP, didReadContent = false, detectedIndent = false, textIndent = nodeIndent, emptyLines = 0, atMoreIndented = false, tmp, ch;
|
|
1911
|
+
ch = state.input.charCodeAt(state.position);
|
|
1912
|
+
if (ch === 124) {
|
|
1913
|
+
folding = false;
|
|
1914
|
+
} else if (ch === 62) {
|
|
1915
|
+
folding = true;
|
|
1916
|
+
} else {
|
|
1917
|
+
return false;
|
|
1918
|
+
}
|
|
1919
|
+
state.kind = "scalar";
|
|
1920
|
+
state.result = "";
|
|
1921
|
+
while (ch !== 0) {
|
|
1922
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1923
|
+
if (ch === 43 || ch === 45) {
|
|
1924
|
+
if (CHOMPING_CLIP === chomping) {
|
|
1925
|
+
chomping = ch === 43 ? CHOMPING_KEEP : CHOMPING_STRIP;
|
|
1926
|
+
} else {
|
|
1927
|
+
throwError(state, "repeat of a chomping mode identifier");
|
|
1928
|
+
}
|
|
1929
|
+
} else if ((tmp = fromDecimalCode(ch)) >= 0) {
|
|
1930
|
+
if (tmp === 0) {
|
|
1931
|
+
throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
|
|
1932
|
+
} else if (!detectedIndent) {
|
|
1933
|
+
textIndent = nodeIndent + tmp - 1;
|
|
1934
|
+
detectedIndent = true;
|
|
1935
|
+
} else {
|
|
1936
|
+
throwError(state, "repeat of an indentation width identifier");
|
|
1937
|
+
}
|
|
1938
|
+
} else {
|
|
1939
|
+
break;
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
if (is_WHITE_SPACE(ch)) {
|
|
1943
|
+
do {
|
|
1944
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1945
|
+
} while (is_WHITE_SPACE(ch));
|
|
1946
|
+
if (ch === 35) {
|
|
1947
|
+
do {
|
|
1948
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1949
|
+
} while (!is_EOL(ch) && ch !== 0);
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
while (ch !== 0) {
|
|
1953
|
+
readLineBreak(state);
|
|
1954
|
+
state.lineIndent = 0;
|
|
1955
|
+
ch = state.input.charCodeAt(state.position);
|
|
1956
|
+
while ((!detectedIndent || state.lineIndent < textIndent) && ch === 32) {
|
|
1957
|
+
state.lineIndent++;
|
|
1958
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1959
|
+
}
|
|
1960
|
+
if (!detectedIndent && state.lineIndent > textIndent) {
|
|
1961
|
+
textIndent = state.lineIndent;
|
|
1962
|
+
}
|
|
1963
|
+
if (is_EOL(ch)) {
|
|
1964
|
+
emptyLines++;
|
|
1965
|
+
continue;
|
|
1966
|
+
}
|
|
1967
|
+
if (state.lineIndent < textIndent) {
|
|
1968
|
+
if (chomping === CHOMPING_KEEP) {
|
|
1969
|
+
state.result += common.repeat(`
|
|
1970
|
+
`, didReadContent ? 1 + emptyLines : emptyLines);
|
|
1971
|
+
} else if (chomping === CHOMPING_CLIP) {
|
|
1972
|
+
if (didReadContent) {
|
|
1973
|
+
state.result += `
|
|
1974
|
+
`;
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
break;
|
|
1978
|
+
}
|
|
1979
|
+
if (folding) {
|
|
1980
|
+
if (is_WHITE_SPACE(ch)) {
|
|
1981
|
+
atMoreIndented = true;
|
|
1982
|
+
state.result += common.repeat(`
|
|
1983
|
+
`, didReadContent ? 1 + emptyLines : emptyLines);
|
|
1984
|
+
} else if (atMoreIndented) {
|
|
1985
|
+
atMoreIndented = false;
|
|
1986
|
+
state.result += common.repeat(`
|
|
1987
|
+
`, emptyLines + 1);
|
|
1988
|
+
} else if (emptyLines === 0) {
|
|
1989
|
+
if (didReadContent) {
|
|
1990
|
+
state.result += " ";
|
|
1991
|
+
}
|
|
1992
|
+
} else {
|
|
1993
|
+
state.result += common.repeat(`
|
|
1994
|
+
`, emptyLines);
|
|
1995
|
+
}
|
|
1996
|
+
} else {
|
|
1997
|
+
state.result += common.repeat(`
|
|
1998
|
+
`, didReadContent ? 1 + emptyLines : emptyLines);
|
|
1999
|
+
}
|
|
2000
|
+
didReadContent = true;
|
|
2001
|
+
detectedIndent = true;
|
|
2002
|
+
emptyLines = 0;
|
|
2003
|
+
captureStart = state.position;
|
|
2004
|
+
while (!is_EOL(ch) && ch !== 0) {
|
|
2005
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2006
|
+
}
|
|
2007
|
+
captureSegment(state, captureStart, state.position, false);
|
|
2008
|
+
}
|
|
2009
|
+
return true;
|
|
2010
|
+
}
|
|
2011
|
+
function readBlockSequence(state, nodeIndent) {
|
|
2012
|
+
var _line, _tag = state.tag, _anchor = state.anchor, _result = [], following, detected = false, ch;
|
|
2013
|
+
if (state.anchor !== null) {
|
|
2014
|
+
state.anchorMap[state.anchor] = _result;
|
|
2015
|
+
}
|
|
2016
|
+
ch = state.input.charCodeAt(state.position);
|
|
2017
|
+
while (ch !== 0) {
|
|
2018
|
+
if (ch !== 45) {
|
|
2019
|
+
break;
|
|
2020
|
+
}
|
|
2021
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
2022
|
+
if (!is_WS_OR_EOL(following)) {
|
|
2023
|
+
break;
|
|
2024
|
+
}
|
|
2025
|
+
detected = true;
|
|
2026
|
+
state.position++;
|
|
2027
|
+
if (skipSeparationSpace(state, true, -1)) {
|
|
2028
|
+
if (state.lineIndent <= nodeIndent) {
|
|
2029
|
+
_result.push(null);
|
|
2030
|
+
ch = state.input.charCodeAt(state.position);
|
|
2031
|
+
continue;
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
_line = state.line;
|
|
2035
|
+
composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
|
|
2036
|
+
_result.push(state.result);
|
|
2037
|
+
skipSeparationSpace(state, true, -1);
|
|
2038
|
+
ch = state.input.charCodeAt(state.position);
|
|
2039
|
+
if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
|
|
2040
|
+
throwError(state, "bad indentation of a sequence entry");
|
|
2041
|
+
} else if (state.lineIndent < nodeIndent) {
|
|
2042
|
+
break;
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
if (detected) {
|
|
2046
|
+
state.tag = _tag;
|
|
2047
|
+
state.anchor = _anchor;
|
|
2048
|
+
state.kind = "sequence";
|
|
2049
|
+
state.result = _result;
|
|
2050
|
+
return true;
|
|
2051
|
+
}
|
|
2052
|
+
return false;
|
|
2053
|
+
}
|
|
2054
|
+
function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
2055
|
+
var following, allowCompact, _line, _pos, _tag = state.tag, _anchor = state.anchor, _result = {}, overridableKeys = {}, keyTag = null, keyNode = null, valueNode = null, atExplicitKey = false, detected = false, ch;
|
|
2056
|
+
if (state.anchor !== null) {
|
|
2057
|
+
state.anchorMap[state.anchor] = _result;
|
|
2058
|
+
}
|
|
2059
|
+
ch = state.input.charCodeAt(state.position);
|
|
2060
|
+
while (ch !== 0) {
|
|
2061
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
2062
|
+
_line = state.line;
|
|
2063
|
+
_pos = state.position;
|
|
2064
|
+
if ((ch === 63 || ch === 58) && is_WS_OR_EOL(following)) {
|
|
2065
|
+
if (ch === 63) {
|
|
2066
|
+
if (atExplicitKey) {
|
|
2067
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
|
|
2068
|
+
keyTag = keyNode = valueNode = null;
|
|
2069
|
+
}
|
|
2070
|
+
detected = true;
|
|
2071
|
+
atExplicitKey = true;
|
|
2072
|
+
allowCompact = true;
|
|
2073
|
+
} else if (atExplicitKey) {
|
|
2074
|
+
atExplicitKey = false;
|
|
2075
|
+
allowCompact = true;
|
|
2076
|
+
} else {
|
|
2077
|
+
throwError(state, "incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line");
|
|
2078
|
+
}
|
|
2079
|
+
state.position += 1;
|
|
2080
|
+
ch = following;
|
|
2081
|
+
} else if (composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
|
|
2082
|
+
if (state.line === _line) {
|
|
2083
|
+
ch = state.input.charCodeAt(state.position);
|
|
2084
|
+
while (is_WHITE_SPACE(ch)) {
|
|
2085
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2086
|
+
}
|
|
2087
|
+
if (ch === 58) {
|
|
2088
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2089
|
+
if (!is_WS_OR_EOL(ch)) {
|
|
2090
|
+
throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
|
|
2091
|
+
}
|
|
2092
|
+
if (atExplicitKey) {
|
|
2093
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
|
|
2094
|
+
keyTag = keyNode = valueNode = null;
|
|
2095
|
+
}
|
|
2096
|
+
detected = true;
|
|
2097
|
+
atExplicitKey = false;
|
|
2098
|
+
allowCompact = false;
|
|
2099
|
+
keyTag = state.tag;
|
|
2100
|
+
keyNode = state.result;
|
|
2101
|
+
} else if (detected) {
|
|
2102
|
+
throwError(state, "can not read an implicit mapping pair; a colon is missed");
|
|
2103
|
+
} else {
|
|
2104
|
+
state.tag = _tag;
|
|
2105
|
+
state.anchor = _anchor;
|
|
2106
|
+
return true;
|
|
2107
|
+
}
|
|
2108
|
+
} else if (detected) {
|
|
2109
|
+
throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
|
|
2110
|
+
} else {
|
|
2111
|
+
state.tag = _tag;
|
|
2112
|
+
state.anchor = _anchor;
|
|
2113
|
+
return true;
|
|
2114
|
+
}
|
|
2115
|
+
} else {
|
|
2116
|
+
break;
|
|
2117
|
+
}
|
|
2118
|
+
if (state.line === _line || state.lineIndent > nodeIndent) {
|
|
2119
|
+
if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
|
|
2120
|
+
if (atExplicitKey) {
|
|
2121
|
+
keyNode = state.result;
|
|
2122
|
+
} else {
|
|
2123
|
+
valueNode = state.result;
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
if (!atExplicitKey) {
|
|
2127
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _pos);
|
|
2128
|
+
keyTag = keyNode = valueNode = null;
|
|
2129
|
+
}
|
|
2130
|
+
skipSeparationSpace(state, true, -1);
|
|
2131
|
+
ch = state.input.charCodeAt(state.position);
|
|
2132
|
+
}
|
|
2133
|
+
if (state.lineIndent > nodeIndent && ch !== 0) {
|
|
2134
|
+
throwError(state, "bad indentation of a mapping entry");
|
|
2135
|
+
} else if (state.lineIndent < nodeIndent) {
|
|
2136
|
+
break;
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
if (atExplicitKey) {
|
|
2140
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
|
|
2141
|
+
}
|
|
2142
|
+
if (detected) {
|
|
2143
|
+
state.tag = _tag;
|
|
2144
|
+
state.anchor = _anchor;
|
|
2145
|
+
state.kind = "mapping";
|
|
2146
|
+
state.result = _result;
|
|
2147
|
+
}
|
|
2148
|
+
return detected;
|
|
2149
|
+
}
|
|
2150
|
+
function readTagProperty(state) {
|
|
2151
|
+
var _position, isVerbatim = false, isNamed = false, tagHandle, tagName, ch;
|
|
2152
|
+
ch = state.input.charCodeAt(state.position);
|
|
2153
|
+
if (ch !== 33)
|
|
2154
|
+
return false;
|
|
2155
|
+
if (state.tag !== null) {
|
|
2156
|
+
throwError(state, "duplication of a tag property");
|
|
2157
|
+
}
|
|
2158
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2159
|
+
if (ch === 60) {
|
|
2160
|
+
isVerbatim = true;
|
|
2161
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2162
|
+
} else if (ch === 33) {
|
|
2163
|
+
isNamed = true;
|
|
2164
|
+
tagHandle = "!!";
|
|
2165
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2166
|
+
} else {
|
|
2167
|
+
tagHandle = "!";
|
|
2168
|
+
}
|
|
2169
|
+
_position = state.position;
|
|
2170
|
+
if (isVerbatim) {
|
|
2171
|
+
do {
|
|
2172
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2173
|
+
} while (ch !== 0 && ch !== 62);
|
|
2174
|
+
if (state.position < state.length) {
|
|
2175
|
+
tagName = state.input.slice(_position, state.position);
|
|
2176
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2177
|
+
} else {
|
|
2178
|
+
throwError(state, "unexpected end of the stream within a verbatim tag");
|
|
2179
|
+
}
|
|
2180
|
+
} else {
|
|
2181
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
2182
|
+
if (ch === 33) {
|
|
2183
|
+
if (!isNamed) {
|
|
2184
|
+
tagHandle = state.input.slice(_position - 1, state.position + 1);
|
|
2185
|
+
if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
|
2186
|
+
throwError(state, "named tag handle cannot contain such characters");
|
|
2187
|
+
}
|
|
2188
|
+
isNamed = true;
|
|
2189
|
+
_position = state.position + 1;
|
|
2190
|
+
} else {
|
|
2191
|
+
throwError(state, "tag suffix cannot contain exclamation marks");
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2195
|
+
}
|
|
2196
|
+
tagName = state.input.slice(_position, state.position);
|
|
2197
|
+
if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
|
2198
|
+
throwError(state, "tag suffix cannot contain flow indicator characters");
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
if (tagName && !PATTERN_TAG_URI.test(tagName)) {
|
|
2202
|
+
throwError(state, "tag name cannot contain such characters: " + tagName);
|
|
2203
|
+
}
|
|
2204
|
+
if (isVerbatim) {
|
|
2205
|
+
state.tag = tagName;
|
|
2206
|
+
} else if (_hasOwnProperty.call(state.tagMap, tagHandle)) {
|
|
2207
|
+
state.tag = state.tagMap[tagHandle] + tagName;
|
|
2208
|
+
} else if (tagHandle === "!") {
|
|
2209
|
+
state.tag = "!" + tagName;
|
|
2210
|
+
} else if (tagHandle === "!!") {
|
|
2211
|
+
state.tag = "tag:yaml.org,2002:" + tagName;
|
|
2212
|
+
} else {
|
|
2213
|
+
throwError(state, 'undeclared tag handle "' + tagHandle + '"');
|
|
2214
|
+
}
|
|
2215
|
+
return true;
|
|
2216
|
+
}
|
|
2217
|
+
function readAnchorProperty(state) {
|
|
2218
|
+
var _position, ch;
|
|
2219
|
+
ch = state.input.charCodeAt(state.position);
|
|
2220
|
+
if (ch !== 38)
|
|
2221
|
+
return false;
|
|
2222
|
+
if (state.anchor !== null) {
|
|
2223
|
+
throwError(state, "duplication of an anchor property");
|
|
2224
|
+
}
|
|
2225
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2226
|
+
_position = state.position;
|
|
2227
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
|
2228
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2229
|
+
}
|
|
2230
|
+
if (state.position === _position) {
|
|
2231
|
+
throwError(state, "name of an anchor node must contain at least one character");
|
|
2232
|
+
}
|
|
2233
|
+
state.anchor = state.input.slice(_position, state.position);
|
|
2234
|
+
return true;
|
|
2235
|
+
}
|
|
2236
|
+
function readAlias(state) {
|
|
2237
|
+
var _position, alias, ch;
|
|
2238
|
+
ch = state.input.charCodeAt(state.position);
|
|
2239
|
+
if (ch !== 42)
|
|
2240
|
+
return false;
|
|
2241
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2242
|
+
_position = state.position;
|
|
2243
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
|
2244
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2245
|
+
}
|
|
2246
|
+
if (state.position === _position) {
|
|
2247
|
+
throwError(state, "name of an alias node must contain at least one character");
|
|
2248
|
+
}
|
|
2249
|
+
alias = state.input.slice(_position, state.position);
|
|
2250
|
+
if (!_hasOwnProperty.call(state.anchorMap, alias)) {
|
|
2251
|
+
throwError(state, 'unidentified alias "' + alias + '"');
|
|
2252
|
+
}
|
|
2253
|
+
state.result = state.anchorMap[alias];
|
|
2254
|
+
skipSeparationSpace(state, true, -1);
|
|
2255
|
+
return true;
|
|
2256
|
+
}
|
|
2257
|
+
function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
|
|
2258
|
+
var allowBlockStyles, allowBlockScalars, allowBlockCollections, indentStatus = 1, atNewLine = false, hasContent = false, typeIndex, typeQuantity, type, flowIndent, blockIndent;
|
|
2259
|
+
if (state.listener !== null) {
|
|
2260
|
+
state.listener("open", state);
|
|
2261
|
+
}
|
|
2262
|
+
state.tag = null;
|
|
2263
|
+
state.anchor = null;
|
|
2264
|
+
state.kind = null;
|
|
2265
|
+
state.result = null;
|
|
2266
|
+
allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext;
|
|
2267
|
+
if (allowToSeek) {
|
|
2268
|
+
if (skipSeparationSpace(state, true, -1)) {
|
|
2269
|
+
atNewLine = true;
|
|
2270
|
+
if (state.lineIndent > parentIndent) {
|
|
2271
|
+
indentStatus = 1;
|
|
2272
|
+
} else if (state.lineIndent === parentIndent) {
|
|
2273
|
+
indentStatus = 0;
|
|
2274
|
+
} else if (state.lineIndent < parentIndent) {
|
|
2275
|
+
indentStatus = -1;
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
if (indentStatus === 1) {
|
|
2280
|
+
while (readTagProperty(state) || readAnchorProperty(state)) {
|
|
2281
|
+
if (skipSeparationSpace(state, true, -1)) {
|
|
2282
|
+
atNewLine = true;
|
|
2283
|
+
allowBlockCollections = allowBlockStyles;
|
|
2284
|
+
if (state.lineIndent > parentIndent) {
|
|
2285
|
+
indentStatus = 1;
|
|
2286
|
+
} else if (state.lineIndent === parentIndent) {
|
|
2287
|
+
indentStatus = 0;
|
|
2288
|
+
} else if (state.lineIndent < parentIndent) {
|
|
2289
|
+
indentStatus = -1;
|
|
2290
|
+
}
|
|
2291
|
+
} else {
|
|
2292
|
+
allowBlockCollections = false;
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
if (allowBlockCollections) {
|
|
2297
|
+
allowBlockCollections = atNewLine || allowCompact;
|
|
2298
|
+
}
|
|
2299
|
+
if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
|
|
2300
|
+
if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
|
|
2301
|
+
flowIndent = parentIndent;
|
|
2302
|
+
} else {
|
|
2303
|
+
flowIndent = parentIndent + 1;
|
|
2304
|
+
}
|
|
2305
|
+
blockIndent = state.position - state.lineStart;
|
|
2306
|
+
if (indentStatus === 1) {
|
|
2307
|
+
if (allowBlockCollections && (readBlockSequence(state, blockIndent) || readBlockMapping(state, blockIndent, flowIndent)) || readFlowCollection(state, flowIndent)) {
|
|
2308
|
+
hasContent = true;
|
|
2309
|
+
} else {
|
|
2310
|
+
if (allowBlockScalars && readBlockScalar(state, flowIndent) || readSingleQuotedScalar(state, flowIndent) || readDoubleQuotedScalar(state, flowIndent)) {
|
|
2311
|
+
hasContent = true;
|
|
2312
|
+
} else if (readAlias(state)) {
|
|
2313
|
+
hasContent = true;
|
|
2314
|
+
if (state.tag !== null || state.anchor !== null) {
|
|
2315
|
+
throwError(state, "alias node should not have any properties");
|
|
2316
|
+
}
|
|
2317
|
+
} else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
|
|
2318
|
+
hasContent = true;
|
|
2319
|
+
if (state.tag === null) {
|
|
2320
|
+
state.tag = "?";
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
if (state.anchor !== null) {
|
|
2324
|
+
state.anchorMap[state.anchor] = state.result;
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
} else if (indentStatus === 0) {
|
|
2328
|
+
hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
if (state.tag !== null && state.tag !== "!") {
|
|
2332
|
+
if (state.tag === "?") {
|
|
2333
|
+
if (state.result !== null && state.kind !== "scalar") {
|
|
2334
|
+
throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
|
|
2335
|
+
}
|
|
2336
|
+
for (typeIndex = 0, typeQuantity = state.implicitTypes.length;typeIndex < typeQuantity; typeIndex += 1) {
|
|
2337
|
+
type = state.implicitTypes[typeIndex];
|
|
2338
|
+
if (type.resolve(state.result)) {
|
|
2339
|
+
state.result = type.construct(state.result);
|
|
2340
|
+
state.tag = type.tag;
|
|
2341
|
+
if (state.anchor !== null) {
|
|
2342
|
+
state.anchorMap[state.anchor] = state.result;
|
|
2343
|
+
}
|
|
2344
|
+
break;
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
} else if (_hasOwnProperty.call(state.typeMap[state.kind || "fallback"], state.tag)) {
|
|
2348
|
+
type = state.typeMap[state.kind || "fallback"][state.tag];
|
|
2349
|
+
if (state.result !== null && type.kind !== state.kind) {
|
|
2350
|
+
throwError(state, "unacceptable node kind for !<" + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
|
|
2351
|
+
}
|
|
2352
|
+
if (!type.resolve(state.result)) {
|
|
2353
|
+
throwError(state, "cannot resolve a node with !<" + state.tag + "> explicit tag");
|
|
2354
|
+
} else {
|
|
2355
|
+
state.result = type.construct(state.result);
|
|
2356
|
+
if (state.anchor !== null) {
|
|
2357
|
+
state.anchorMap[state.anchor] = state.result;
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
} else {
|
|
2361
|
+
throwError(state, "unknown tag !<" + state.tag + ">");
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
if (state.listener !== null) {
|
|
2365
|
+
state.listener("close", state);
|
|
2366
|
+
}
|
|
2367
|
+
return state.tag !== null || state.anchor !== null || hasContent;
|
|
2368
|
+
}
|
|
2369
|
+
function readDocument(state) {
|
|
2370
|
+
var documentStart = state.position, _position, directiveName, directiveArgs, hasDirectives = false, ch;
|
|
2371
|
+
state.version = null;
|
|
2372
|
+
state.checkLineBreaks = state.legacy;
|
|
2373
|
+
state.tagMap = {};
|
|
2374
|
+
state.anchorMap = {};
|
|
2375
|
+
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
2376
|
+
skipSeparationSpace(state, true, -1);
|
|
2377
|
+
ch = state.input.charCodeAt(state.position);
|
|
2378
|
+
if (state.lineIndent > 0 || ch !== 37) {
|
|
2379
|
+
break;
|
|
2380
|
+
}
|
|
2381
|
+
hasDirectives = true;
|
|
2382
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2383
|
+
_position = state.position;
|
|
2384
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
2385
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2386
|
+
}
|
|
2387
|
+
directiveName = state.input.slice(_position, state.position);
|
|
2388
|
+
directiveArgs = [];
|
|
2389
|
+
if (directiveName.length < 1) {
|
|
2390
|
+
throwError(state, "directive name must not be less than one character in length");
|
|
2391
|
+
}
|
|
2392
|
+
while (ch !== 0) {
|
|
2393
|
+
while (is_WHITE_SPACE(ch)) {
|
|
2394
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2395
|
+
}
|
|
2396
|
+
if (ch === 35) {
|
|
2397
|
+
do {
|
|
2398
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2399
|
+
} while (ch !== 0 && !is_EOL(ch));
|
|
2400
|
+
break;
|
|
2401
|
+
}
|
|
2402
|
+
if (is_EOL(ch))
|
|
2403
|
+
break;
|
|
2404
|
+
_position = state.position;
|
|
2405
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
2406
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2407
|
+
}
|
|
2408
|
+
directiveArgs.push(state.input.slice(_position, state.position));
|
|
2409
|
+
}
|
|
2410
|
+
if (ch !== 0)
|
|
2411
|
+
readLineBreak(state);
|
|
2412
|
+
if (_hasOwnProperty.call(directiveHandlers, directiveName)) {
|
|
2413
|
+
directiveHandlers[directiveName](state, directiveName, directiveArgs);
|
|
2414
|
+
} else {
|
|
2415
|
+
throwWarning(state, 'unknown document directive "' + directiveName + '"');
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
skipSeparationSpace(state, true, -1);
|
|
2419
|
+
if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45) {
|
|
2420
|
+
state.position += 3;
|
|
2421
|
+
skipSeparationSpace(state, true, -1);
|
|
2422
|
+
} else if (hasDirectives) {
|
|
2423
|
+
throwError(state, "directives end mark is expected");
|
|
2424
|
+
}
|
|
2425
|
+
composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
|
|
2426
|
+
skipSeparationSpace(state, true, -1);
|
|
2427
|
+
if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
|
|
2428
|
+
throwWarning(state, "non-ASCII line breaks are interpreted as content");
|
|
2429
|
+
}
|
|
2430
|
+
state.documents.push(state.result);
|
|
2431
|
+
if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
2432
|
+
if (state.input.charCodeAt(state.position) === 46) {
|
|
2433
|
+
state.position += 3;
|
|
2434
|
+
skipSeparationSpace(state, true, -1);
|
|
2435
|
+
}
|
|
2436
|
+
return;
|
|
2437
|
+
}
|
|
2438
|
+
if (state.position < state.length - 1) {
|
|
2439
|
+
throwError(state, "end of the stream or a document separator is expected");
|
|
2440
|
+
} else {
|
|
2441
|
+
return;
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
function loadDocuments(input, options2) {
|
|
2445
|
+
input = String(input);
|
|
2446
|
+
options2 = options2 || {};
|
|
2447
|
+
if (input.length !== 0) {
|
|
2448
|
+
if (input.charCodeAt(input.length - 1) !== 10 && input.charCodeAt(input.length - 1) !== 13) {
|
|
2449
|
+
input += `
|
|
2450
|
+
`;
|
|
2451
|
+
}
|
|
2452
|
+
if (input.charCodeAt(0) === 65279) {
|
|
2453
|
+
input = input.slice(1);
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
var state = new State(input, options2);
|
|
2457
|
+
var nullpos = input.indexOf("\x00");
|
|
2458
|
+
if (nullpos !== -1) {
|
|
2459
|
+
state.position = nullpos;
|
|
2460
|
+
throwError(state, "null byte is not allowed in input");
|
|
2461
|
+
}
|
|
2462
|
+
state.input += "\x00";
|
|
2463
|
+
while (state.input.charCodeAt(state.position) === 32) {
|
|
2464
|
+
state.lineIndent += 1;
|
|
2465
|
+
state.position += 1;
|
|
2466
|
+
}
|
|
2467
|
+
while (state.position < state.length - 1) {
|
|
2468
|
+
readDocument(state);
|
|
2469
|
+
}
|
|
2470
|
+
return state.documents;
|
|
2471
|
+
}
|
|
2472
|
+
function loadAll(input, iterator, options2) {
|
|
2473
|
+
if (iterator !== null && typeof iterator === "object" && typeof options2 === "undefined") {
|
|
2474
|
+
options2 = iterator;
|
|
2475
|
+
iterator = null;
|
|
2476
|
+
}
|
|
2477
|
+
var documents = loadDocuments(input, options2);
|
|
2478
|
+
if (typeof iterator !== "function") {
|
|
2479
|
+
return documents;
|
|
2480
|
+
}
|
|
2481
|
+
for (var index = 0, length = documents.length;index < length; index += 1) {
|
|
2482
|
+
iterator(documents[index]);
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
function load(input, options2) {
|
|
2486
|
+
var documents = loadDocuments(input, options2);
|
|
2487
|
+
if (documents.length === 0) {
|
|
2488
|
+
return;
|
|
2489
|
+
} else if (documents.length === 1) {
|
|
2490
|
+
return documents[0];
|
|
2491
|
+
}
|
|
2492
|
+
throw new YAMLException("expected a single document in the stream, but found more");
|
|
2493
|
+
}
|
|
2494
|
+
function safeLoadAll(input, iterator, options2) {
|
|
2495
|
+
if (typeof iterator === "object" && iterator !== null && typeof options2 === "undefined") {
|
|
2496
|
+
options2 = iterator;
|
|
2497
|
+
iterator = null;
|
|
2498
|
+
}
|
|
2499
|
+
return loadAll(input, iterator, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options2));
|
|
2500
|
+
}
|
|
2501
|
+
function safeLoad(input, options2) {
|
|
2502
|
+
return load(input, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options2));
|
|
2503
|
+
}
|
|
2504
|
+
exports.loadAll = loadAll;
|
|
2505
|
+
exports.load = load;
|
|
2506
|
+
exports.safeLoadAll = safeLoadAll;
|
|
2507
|
+
exports.safeLoad = safeLoad;
|
|
2508
|
+
});
|
|
2509
|
+
|
|
2510
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/dumper.js
|
|
2511
|
+
var require_dumper = __commonJS((exports, module) => {
|
|
2512
|
+
var common = require_common();
|
|
2513
|
+
var YAMLException = require_exception();
|
|
2514
|
+
var DEFAULT_FULL_SCHEMA = require_default_full();
|
|
2515
|
+
var DEFAULT_SAFE_SCHEMA = require_default_safe();
|
|
2516
|
+
var _toString = Object.prototype.toString;
|
|
2517
|
+
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
2518
|
+
var CHAR_TAB = 9;
|
|
2519
|
+
var CHAR_LINE_FEED = 10;
|
|
2520
|
+
var CHAR_CARRIAGE_RETURN = 13;
|
|
2521
|
+
var CHAR_SPACE = 32;
|
|
2522
|
+
var CHAR_EXCLAMATION = 33;
|
|
2523
|
+
var CHAR_DOUBLE_QUOTE = 34;
|
|
2524
|
+
var CHAR_SHARP = 35;
|
|
2525
|
+
var CHAR_PERCENT = 37;
|
|
2526
|
+
var CHAR_AMPERSAND = 38;
|
|
2527
|
+
var CHAR_SINGLE_QUOTE = 39;
|
|
2528
|
+
var CHAR_ASTERISK = 42;
|
|
2529
|
+
var CHAR_COMMA = 44;
|
|
2530
|
+
var CHAR_MINUS = 45;
|
|
2531
|
+
var CHAR_COLON = 58;
|
|
2532
|
+
var CHAR_EQUALS = 61;
|
|
2533
|
+
var CHAR_GREATER_THAN = 62;
|
|
2534
|
+
var CHAR_QUESTION = 63;
|
|
2535
|
+
var CHAR_COMMERCIAL_AT = 64;
|
|
2536
|
+
var CHAR_LEFT_SQUARE_BRACKET = 91;
|
|
2537
|
+
var CHAR_RIGHT_SQUARE_BRACKET = 93;
|
|
2538
|
+
var CHAR_GRAVE_ACCENT = 96;
|
|
2539
|
+
var CHAR_LEFT_CURLY_BRACKET = 123;
|
|
2540
|
+
var CHAR_VERTICAL_LINE = 124;
|
|
2541
|
+
var CHAR_RIGHT_CURLY_BRACKET = 125;
|
|
2542
|
+
var ESCAPE_SEQUENCES = {};
|
|
2543
|
+
ESCAPE_SEQUENCES[0] = "\\0";
|
|
2544
|
+
ESCAPE_SEQUENCES[7] = "\\a";
|
|
2545
|
+
ESCAPE_SEQUENCES[8] = "\\b";
|
|
2546
|
+
ESCAPE_SEQUENCES[9] = "\\t";
|
|
2547
|
+
ESCAPE_SEQUENCES[10] = "\\n";
|
|
2548
|
+
ESCAPE_SEQUENCES[11] = "\\v";
|
|
2549
|
+
ESCAPE_SEQUENCES[12] = "\\f";
|
|
2550
|
+
ESCAPE_SEQUENCES[13] = "\\r";
|
|
2551
|
+
ESCAPE_SEQUENCES[27] = "\\e";
|
|
2552
|
+
ESCAPE_SEQUENCES[34] = "\\\"";
|
|
2553
|
+
ESCAPE_SEQUENCES[92] = "\\\\";
|
|
2554
|
+
ESCAPE_SEQUENCES[133] = "\\N";
|
|
2555
|
+
ESCAPE_SEQUENCES[160] = "\\_";
|
|
2556
|
+
ESCAPE_SEQUENCES[8232] = "\\L";
|
|
2557
|
+
ESCAPE_SEQUENCES[8233] = "\\P";
|
|
2558
|
+
var DEPRECATED_BOOLEANS_SYNTAX = [
|
|
2559
|
+
"y",
|
|
2560
|
+
"Y",
|
|
2561
|
+
"yes",
|
|
2562
|
+
"Yes",
|
|
2563
|
+
"YES",
|
|
2564
|
+
"on",
|
|
2565
|
+
"On",
|
|
2566
|
+
"ON",
|
|
2567
|
+
"n",
|
|
2568
|
+
"N",
|
|
2569
|
+
"no",
|
|
2570
|
+
"No",
|
|
2571
|
+
"NO",
|
|
2572
|
+
"off",
|
|
2573
|
+
"Off",
|
|
2574
|
+
"OFF"
|
|
2575
|
+
];
|
|
2576
|
+
function compileStyleMap(schema, map) {
|
|
2577
|
+
var result, keys, index, length, tag, style, type;
|
|
2578
|
+
if (map === null)
|
|
2579
|
+
return {};
|
|
2580
|
+
result = {};
|
|
2581
|
+
keys = Object.keys(map);
|
|
2582
|
+
for (index = 0, length = keys.length;index < length; index += 1) {
|
|
2583
|
+
tag = keys[index];
|
|
2584
|
+
style = String(map[tag]);
|
|
2585
|
+
if (tag.slice(0, 2) === "!!") {
|
|
2586
|
+
tag = "tag:yaml.org,2002:" + tag.slice(2);
|
|
2587
|
+
}
|
|
2588
|
+
type = schema.compiledTypeMap["fallback"][tag];
|
|
2589
|
+
if (type && _hasOwnProperty.call(type.styleAliases, style)) {
|
|
2590
|
+
style = type.styleAliases[style];
|
|
2591
|
+
}
|
|
2592
|
+
result[tag] = style;
|
|
2593
|
+
}
|
|
2594
|
+
return result;
|
|
2595
|
+
}
|
|
2596
|
+
function encodeHex(character) {
|
|
2597
|
+
var string, handle, length;
|
|
2598
|
+
string = character.toString(16).toUpperCase();
|
|
2599
|
+
if (character <= 255) {
|
|
2600
|
+
handle = "x";
|
|
2601
|
+
length = 2;
|
|
2602
|
+
} else if (character <= 65535) {
|
|
2603
|
+
handle = "u";
|
|
2604
|
+
length = 4;
|
|
2605
|
+
} else if (character <= 4294967295) {
|
|
2606
|
+
handle = "U";
|
|
2607
|
+
length = 8;
|
|
2608
|
+
} else {
|
|
2609
|
+
throw new YAMLException("code point within a string may not be greater than 0xFFFFFFFF");
|
|
2610
|
+
}
|
|
2611
|
+
return "\\" + handle + common.repeat("0", length - string.length) + string;
|
|
2612
|
+
}
|
|
2613
|
+
function State(options2) {
|
|
2614
|
+
this.schema = options2["schema"] || DEFAULT_FULL_SCHEMA;
|
|
2615
|
+
this.indent = Math.max(1, options2["indent"] || 2);
|
|
2616
|
+
this.noArrayIndent = options2["noArrayIndent"] || false;
|
|
2617
|
+
this.skipInvalid = options2["skipInvalid"] || false;
|
|
2618
|
+
this.flowLevel = common.isNothing(options2["flowLevel"]) ? -1 : options2["flowLevel"];
|
|
2619
|
+
this.styleMap = compileStyleMap(this.schema, options2["styles"] || null);
|
|
2620
|
+
this.sortKeys = options2["sortKeys"] || false;
|
|
2621
|
+
this.lineWidth = options2["lineWidth"] || 80;
|
|
2622
|
+
this.noRefs = options2["noRefs"] || false;
|
|
2623
|
+
this.noCompatMode = options2["noCompatMode"] || false;
|
|
2624
|
+
this.condenseFlow = options2["condenseFlow"] || false;
|
|
2625
|
+
this.implicitTypes = this.schema.compiledImplicit;
|
|
2626
|
+
this.explicitTypes = this.schema.compiledExplicit;
|
|
2627
|
+
this.tag = null;
|
|
2628
|
+
this.result = "";
|
|
2629
|
+
this.duplicates = [];
|
|
2630
|
+
this.usedDuplicates = null;
|
|
2631
|
+
}
|
|
2632
|
+
function indentString(string, spaces) {
|
|
2633
|
+
var ind = common.repeat(" ", spaces), position = 0, next = -1, result = "", line, length = string.length;
|
|
2634
|
+
while (position < length) {
|
|
2635
|
+
next = string.indexOf(`
|
|
2636
|
+
`, position);
|
|
2637
|
+
if (next === -1) {
|
|
2638
|
+
line = string.slice(position);
|
|
2639
|
+
position = length;
|
|
2640
|
+
} else {
|
|
2641
|
+
line = string.slice(position, next + 1);
|
|
2642
|
+
position = next + 1;
|
|
2643
|
+
}
|
|
2644
|
+
if (line.length && line !== `
|
|
2645
|
+
`)
|
|
2646
|
+
result += ind;
|
|
2647
|
+
result += line;
|
|
2648
|
+
}
|
|
2649
|
+
return result;
|
|
2650
|
+
}
|
|
2651
|
+
function generateNextLine(state, level) {
|
|
2652
|
+
return `
|
|
2653
|
+
` + common.repeat(" ", state.indent * level);
|
|
2654
|
+
}
|
|
2655
|
+
function testImplicitResolving(state, str2) {
|
|
2656
|
+
var index, length, type;
|
|
2657
|
+
for (index = 0, length = state.implicitTypes.length;index < length; index += 1) {
|
|
2658
|
+
type = state.implicitTypes[index];
|
|
2659
|
+
if (type.resolve(str2)) {
|
|
2660
|
+
return true;
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
return false;
|
|
2664
|
+
}
|
|
2665
|
+
function isWhitespace(c) {
|
|
2666
|
+
return c === CHAR_SPACE || c === CHAR_TAB;
|
|
2667
|
+
}
|
|
2668
|
+
function isPrintable(c) {
|
|
2669
|
+
return 32 <= c && c <= 126 || 161 <= c && c <= 55295 && c !== 8232 && c !== 8233 || 57344 <= c && c <= 65533 && c !== 65279 || 65536 <= c && c <= 1114111;
|
|
2670
|
+
}
|
|
2671
|
+
function isNsChar(c) {
|
|
2672
|
+
return isPrintable(c) && !isWhitespace(c) && c !== 65279 && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED;
|
|
2673
|
+
}
|
|
2674
|
+
function isPlainSafe(c, prev) {
|
|
2675
|
+
return isPrintable(c) && c !== 65279 && 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_COLON && (c !== CHAR_SHARP || prev && isNsChar(prev));
|
|
2676
|
+
}
|
|
2677
|
+
function isPlainSafeFirst(c) {
|
|
2678
|
+
return isPrintable(c) && c !== 65279 && !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;
|
|
2679
|
+
}
|
|
2680
|
+
function needIndentIndicator(string) {
|
|
2681
|
+
var leadingSpaceRe = /^\n* /;
|
|
2682
|
+
return leadingSpaceRe.test(string);
|
|
2683
|
+
}
|
|
2684
|
+
var STYLE_PLAIN = 1;
|
|
2685
|
+
var STYLE_SINGLE = 2;
|
|
2686
|
+
var STYLE_LITERAL = 3;
|
|
2687
|
+
var STYLE_FOLDED = 4;
|
|
2688
|
+
var STYLE_DOUBLE = 5;
|
|
2689
|
+
function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType) {
|
|
2690
|
+
var i;
|
|
2691
|
+
var char, prev_char;
|
|
2692
|
+
var hasLineBreak = false;
|
|
2693
|
+
var hasFoldableLine = false;
|
|
2694
|
+
var shouldTrackWidth = lineWidth !== -1;
|
|
2695
|
+
var previousLineBreak = -1;
|
|
2696
|
+
var plain = isPlainSafeFirst(string.charCodeAt(0)) && !isWhitespace(string.charCodeAt(string.length - 1));
|
|
2697
|
+
if (singleLineOnly) {
|
|
2698
|
+
for (i = 0;i < string.length; i++) {
|
|
2699
|
+
char = string.charCodeAt(i);
|
|
2700
|
+
if (!isPrintable(char)) {
|
|
2701
|
+
return STYLE_DOUBLE;
|
|
2702
|
+
}
|
|
2703
|
+
prev_char = i > 0 ? string.charCodeAt(i - 1) : null;
|
|
2704
|
+
plain = plain && isPlainSafe(char, prev_char);
|
|
2705
|
+
}
|
|
2706
|
+
} else {
|
|
2707
|
+
for (i = 0;i < string.length; i++) {
|
|
2708
|
+
char = string.charCodeAt(i);
|
|
2709
|
+
if (char === CHAR_LINE_FEED) {
|
|
2710
|
+
hasLineBreak = true;
|
|
2711
|
+
if (shouldTrackWidth) {
|
|
2712
|
+
hasFoldableLine = hasFoldableLine || i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
|
|
2713
|
+
previousLineBreak = i;
|
|
2714
|
+
}
|
|
2715
|
+
} else if (!isPrintable(char)) {
|
|
2716
|
+
return STYLE_DOUBLE;
|
|
2717
|
+
}
|
|
2718
|
+
prev_char = i > 0 ? string.charCodeAt(i - 1) : null;
|
|
2719
|
+
plain = plain && isPlainSafe(char, prev_char);
|
|
2720
|
+
}
|
|
2721
|
+
hasFoldableLine = hasFoldableLine || shouldTrackWidth && (i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ");
|
|
2722
|
+
}
|
|
2723
|
+
if (!hasLineBreak && !hasFoldableLine) {
|
|
2724
|
+
return plain && !testAmbiguousType(string) ? STYLE_PLAIN : STYLE_SINGLE;
|
|
2725
|
+
}
|
|
2726
|
+
if (indentPerLevel > 9 && needIndentIndicator(string)) {
|
|
2727
|
+
return STYLE_DOUBLE;
|
|
2728
|
+
}
|
|
2729
|
+
return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
|
|
2730
|
+
}
|
|
2731
|
+
function writeScalar(state, string, level, iskey) {
|
|
2732
|
+
state.dump = function() {
|
|
2733
|
+
if (string.length === 0) {
|
|
2734
|
+
return "''";
|
|
2735
|
+
}
|
|
2736
|
+
if (!state.noCompatMode && DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1) {
|
|
2737
|
+
return "'" + string + "'";
|
|
2738
|
+
}
|
|
2739
|
+
var indent = state.indent * Math.max(1, level);
|
|
2740
|
+
var lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
|
|
2741
|
+
var singleLineOnly = iskey || state.flowLevel > -1 && level >= state.flowLevel;
|
|
2742
|
+
function testAmbiguity(string2) {
|
|
2743
|
+
return testImplicitResolving(state, string2);
|
|
2744
|
+
}
|
|
2745
|
+
switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, testAmbiguity)) {
|
|
2746
|
+
case STYLE_PLAIN:
|
|
2747
|
+
return string;
|
|
2748
|
+
case STYLE_SINGLE:
|
|
2749
|
+
return "'" + string.replace(/'/g, "''") + "'";
|
|
2750
|
+
case STYLE_LITERAL:
|
|
2751
|
+
return "|" + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
|
|
2752
|
+
case STYLE_FOLDED:
|
|
2753
|
+
return ">" + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
|
|
2754
|
+
case STYLE_DOUBLE:
|
|
2755
|
+
return '"' + escapeString(string, lineWidth) + '"';
|
|
2756
|
+
default:
|
|
2757
|
+
throw new YAMLException("impossible error: invalid scalar style");
|
|
2758
|
+
}
|
|
2759
|
+
}();
|
|
2760
|
+
}
|
|
2761
|
+
function blockHeader(string, indentPerLevel) {
|
|
2762
|
+
var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
|
|
2763
|
+
var clip = string[string.length - 1] === `
|
|
2764
|
+
`;
|
|
2765
|
+
var keep = clip && (string[string.length - 2] === `
|
|
2766
|
+
` || string === `
|
|
2767
|
+
`);
|
|
2768
|
+
var chomp = keep ? "+" : clip ? "" : "-";
|
|
2769
|
+
return indentIndicator + chomp + `
|
|
2770
|
+
`;
|
|
2771
|
+
}
|
|
2772
|
+
function dropEndingNewline(string) {
|
|
2773
|
+
return string[string.length - 1] === `
|
|
2774
|
+
` ? string.slice(0, -1) : string;
|
|
2775
|
+
}
|
|
2776
|
+
function foldString(string, width) {
|
|
2777
|
+
var lineRe = /(\n+)([^\n]*)/g;
|
|
2778
|
+
var result = function() {
|
|
2779
|
+
var nextLF = string.indexOf(`
|
|
2780
|
+
`);
|
|
2781
|
+
nextLF = nextLF !== -1 ? nextLF : string.length;
|
|
2782
|
+
lineRe.lastIndex = nextLF;
|
|
2783
|
+
return foldLine(string.slice(0, nextLF), width);
|
|
2784
|
+
}();
|
|
2785
|
+
var prevMoreIndented = string[0] === `
|
|
2786
|
+
` || string[0] === " ";
|
|
2787
|
+
var moreIndented;
|
|
2788
|
+
var match;
|
|
2789
|
+
while (match = lineRe.exec(string)) {
|
|
2790
|
+
var prefix = match[1], line = match[2];
|
|
2791
|
+
moreIndented = line[0] === " ";
|
|
2792
|
+
result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? `
|
|
2793
|
+
` : "") + foldLine(line, width);
|
|
2794
|
+
prevMoreIndented = moreIndented;
|
|
2795
|
+
}
|
|
2796
|
+
return result;
|
|
2797
|
+
}
|
|
2798
|
+
function foldLine(line, width) {
|
|
2799
|
+
if (line === "" || line[0] === " ")
|
|
2800
|
+
return line;
|
|
2801
|
+
var breakRe = / [^ ]/g;
|
|
2802
|
+
var match;
|
|
2803
|
+
var start = 0, end, curr = 0, next = 0;
|
|
2804
|
+
var result = "";
|
|
2805
|
+
while (match = breakRe.exec(line)) {
|
|
2806
|
+
next = match.index;
|
|
2807
|
+
if (next - start > width) {
|
|
2808
|
+
end = curr > start ? curr : next;
|
|
2809
|
+
result += `
|
|
2810
|
+
` + line.slice(start, end);
|
|
2811
|
+
start = end + 1;
|
|
2812
|
+
}
|
|
2813
|
+
curr = next;
|
|
2814
|
+
}
|
|
2815
|
+
result += `
|
|
2816
|
+
`;
|
|
2817
|
+
if (line.length - start > width && curr > start) {
|
|
2818
|
+
result += line.slice(start, curr) + `
|
|
2819
|
+
` + line.slice(curr + 1);
|
|
2820
|
+
} else {
|
|
2821
|
+
result += line.slice(start);
|
|
2822
|
+
}
|
|
2823
|
+
return result.slice(1);
|
|
2824
|
+
}
|
|
2825
|
+
function escapeString(string) {
|
|
2826
|
+
var result = "";
|
|
2827
|
+
var char, nextChar;
|
|
2828
|
+
var escapeSeq;
|
|
2829
|
+
for (var i = 0;i < string.length; i++) {
|
|
2830
|
+
char = string.charCodeAt(i);
|
|
2831
|
+
if (char >= 55296 && char <= 56319) {
|
|
2832
|
+
nextChar = string.charCodeAt(i + 1);
|
|
2833
|
+
if (nextChar >= 56320 && nextChar <= 57343) {
|
|
2834
|
+
result += encodeHex((char - 55296) * 1024 + nextChar - 56320 + 65536);
|
|
2835
|
+
i++;
|
|
2836
|
+
continue;
|
|
2837
|
+
}
|
|
2838
|
+
}
|
|
2839
|
+
escapeSeq = ESCAPE_SEQUENCES[char];
|
|
2840
|
+
result += !escapeSeq && isPrintable(char) ? string[i] : escapeSeq || encodeHex(char);
|
|
2841
|
+
}
|
|
2842
|
+
return result;
|
|
2843
|
+
}
|
|
2844
|
+
function writeFlowSequence(state, level, object) {
|
|
2845
|
+
var _result = "", _tag = state.tag, index, length;
|
|
2846
|
+
for (index = 0, length = object.length;index < length; index += 1) {
|
|
2847
|
+
if (writeNode(state, level, object[index], false, false)) {
|
|
2848
|
+
if (index !== 0)
|
|
2849
|
+
_result += "," + (!state.condenseFlow ? " " : "");
|
|
2850
|
+
_result += state.dump;
|
|
2851
|
+
}
|
|
2852
|
+
}
|
|
2853
|
+
state.tag = _tag;
|
|
2854
|
+
state.dump = "[" + _result + "]";
|
|
2855
|
+
}
|
|
2856
|
+
function writeBlockSequence(state, level, object, compact) {
|
|
2857
|
+
var _result = "", _tag = state.tag, index, length;
|
|
2858
|
+
for (index = 0, length = object.length;index < length; index += 1) {
|
|
2859
|
+
if (writeNode(state, level + 1, object[index], true, true)) {
|
|
2860
|
+
if (!compact || index !== 0) {
|
|
2861
|
+
_result += generateNextLine(state, level);
|
|
2862
|
+
}
|
|
2863
|
+
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2864
|
+
_result += "-";
|
|
2865
|
+
} else {
|
|
2866
|
+
_result += "- ";
|
|
2867
|
+
}
|
|
2868
|
+
_result += state.dump;
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
state.tag = _tag;
|
|
2872
|
+
state.dump = _result || "[]";
|
|
2873
|
+
}
|
|
2874
|
+
function writeFlowMapping(state, level, object) {
|
|
2875
|
+
var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, pairBuffer;
|
|
2876
|
+
for (index = 0, length = objectKeyList.length;index < length; index += 1) {
|
|
2877
|
+
pairBuffer = "";
|
|
2878
|
+
if (index !== 0)
|
|
2879
|
+
pairBuffer += ", ";
|
|
2880
|
+
if (state.condenseFlow)
|
|
2881
|
+
pairBuffer += '"';
|
|
2882
|
+
objectKey = objectKeyList[index];
|
|
2883
|
+
objectValue = object[objectKey];
|
|
2884
|
+
if (!writeNode(state, level, objectKey, false, false)) {
|
|
2885
|
+
continue;
|
|
2886
|
+
}
|
|
2887
|
+
if (state.dump.length > 1024)
|
|
2888
|
+
pairBuffer += "? ";
|
|
2889
|
+
pairBuffer += state.dump + (state.condenseFlow ? '"' : "") + ":" + (state.condenseFlow ? "" : " ");
|
|
2890
|
+
if (!writeNode(state, level, objectValue, false, false)) {
|
|
2891
|
+
continue;
|
|
2892
|
+
}
|
|
2893
|
+
pairBuffer += state.dump;
|
|
2894
|
+
_result += pairBuffer;
|
|
2895
|
+
}
|
|
2896
|
+
state.tag = _tag;
|
|
2897
|
+
state.dump = "{" + _result + "}";
|
|
2898
|
+
}
|
|
2899
|
+
function writeBlockMapping(state, level, object, compact) {
|
|
2900
|
+
var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, explicitPair, pairBuffer;
|
|
2901
|
+
if (state.sortKeys === true) {
|
|
2902
|
+
objectKeyList.sort();
|
|
2903
|
+
} else if (typeof state.sortKeys === "function") {
|
|
2904
|
+
objectKeyList.sort(state.sortKeys);
|
|
2905
|
+
} else if (state.sortKeys) {
|
|
2906
|
+
throw new YAMLException("sortKeys must be a boolean or a function");
|
|
2907
|
+
}
|
|
2908
|
+
for (index = 0, length = objectKeyList.length;index < length; index += 1) {
|
|
2909
|
+
pairBuffer = "";
|
|
2910
|
+
if (!compact || index !== 0) {
|
|
2911
|
+
pairBuffer += generateNextLine(state, level);
|
|
2912
|
+
}
|
|
2913
|
+
objectKey = objectKeyList[index];
|
|
2914
|
+
objectValue = object[objectKey];
|
|
2915
|
+
if (!writeNode(state, level + 1, objectKey, true, true, true)) {
|
|
2916
|
+
continue;
|
|
2917
|
+
}
|
|
2918
|
+
explicitPair = state.tag !== null && state.tag !== "?" || state.dump && state.dump.length > 1024;
|
|
2919
|
+
if (explicitPair) {
|
|
2920
|
+
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2921
|
+
pairBuffer += "?";
|
|
2922
|
+
} else {
|
|
2923
|
+
pairBuffer += "? ";
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
pairBuffer += state.dump;
|
|
2927
|
+
if (explicitPair) {
|
|
2928
|
+
pairBuffer += generateNextLine(state, level);
|
|
2929
|
+
}
|
|
2930
|
+
if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
|
|
2931
|
+
continue;
|
|
2932
|
+
}
|
|
2933
|
+
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2934
|
+
pairBuffer += ":";
|
|
2935
|
+
} else {
|
|
2936
|
+
pairBuffer += ": ";
|
|
2937
|
+
}
|
|
2938
|
+
pairBuffer += state.dump;
|
|
2939
|
+
_result += pairBuffer;
|
|
2940
|
+
}
|
|
2941
|
+
state.tag = _tag;
|
|
2942
|
+
state.dump = _result || "{}";
|
|
2943
|
+
}
|
|
2944
|
+
function detectType(state, object, explicit) {
|
|
2945
|
+
var _result, typeList, index, length, type, style;
|
|
2946
|
+
typeList = explicit ? state.explicitTypes : state.implicitTypes;
|
|
2947
|
+
for (index = 0, length = typeList.length;index < length; index += 1) {
|
|
2948
|
+
type = typeList[index];
|
|
2949
|
+
if ((type.instanceOf || type.predicate) && (!type.instanceOf || typeof object === "object" && object instanceof type.instanceOf) && (!type.predicate || type.predicate(object))) {
|
|
2950
|
+
state.tag = explicit ? type.tag : "?";
|
|
2951
|
+
if (type.represent) {
|
|
2952
|
+
style = state.styleMap[type.tag] || type.defaultStyle;
|
|
2953
|
+
if (_toString.call(type.represent) === "[object Function]") {
|
|
2954
|
+
_result = type.represent(object, style);
|
|
2955
|
+
} else if (_hasOwnProperty.call(type.represent, style)) {
|
|
2956
|
+
_result = type.represent[style](object, style);
|
|
2957
|
+
} else {
|
|
2958
|
+
throw new YAMLException("!<" + type.tag + '> tag resolver accepts not "' + style + '" style');
|
|
2959
|
+
}
|
|
2960
|
+
state.dump = _result;
|
|
2961
|
+
}
|
|
2962
|
+
return true;
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
return false;
|
|
2966
|
+
}
|
|
2967
|
+
function writeNode(state, level, object, block, compact, iskey) {
|
|
2968
|
+
state.tag = null;
|
|
2969
|
+
state.dump = object;
|
|
2970
|
+
if (!detectType(state, object, false)) {
|
|
2971
|
+
detectType(state, object, true);
|
|
2972
|
+
}
|
|
2973
|
+
var type = _toString.call(state.dump);
|
|
2974
|
+
if (block) {
|
|
2975
|
+
block = state.flowLevel < 0 || state.flowLevel > level;
|
|
2976
|
+
}
|
|
2977
|
+
var objectOrArray = type === "[object Object]" || type === "[object Array]", duplicateIndex, duplicate;
|
|
2978
|
+
if (objectOrArray) {
|
|
2979
|
+
duplicateIndex = state.duplicates.indexOf(object);
|
|
2980
|
+
duplicate = duplicateIndex !== -1;
|
|
2981
|
+
}
|
|
2982
|
+
if (state.tag !== null && state.tag !== "?" || duplicate || state.indent !== 2 && level > 0) {
|
|
2983
|
+
compact = false;
|
|
2984
|
+
}
|
|
2985
|
+
if (duplicate && state.usedDuplicates[duplicateIndex]) {
|
|
2986
|
+
state.dump = "*ref_" + duplicateIndex;
|
|
2987
|
+
} else {
|
|
2988
|
+
if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
|
|
2989
|
+
state.usedDuplicates[duplicateIndex] = true;
|
|
2990
|
+
}
|
|
2991
|
+
if (type === "[object Object]") {
|
|
2992
|
+
if (block && Object.keys(state.dump).length !== 0) {
|
|
2993
|
+
writeBlockMapping(state, level, state.dump, compact);
|
|
2994
|
+
if (duplicate) {
|
|
2995
|
+
state.dump = "&ref_" + duplicateIndex + state.dump;
|
|
2996
|
+
}
|
|
2997
|
+
} else {
|
|
2998
|
+
writeFlowMapping(state, level, state.dump);
|
|
2999
|
+
if (duplicate) {
|
|
3000
|
+
state.dump = "&ref_" + duplicateIndex + " " + state.dump;
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
} else if (type === "[object Array]") {
|
|
3004
|
+
var arrayLevel = state.noArrayIndent && level > 0 ? level - 1 : level;
|
|
3005
|
+
if (block && state.dump.length !== 0) {
|
|
3006
|
+
writeBlockSequence(state, arrayLevel, state.dump, compact);
|
|
3007
|
+
if (duplicate) {
|
|
3008
|
+
state.dump = "&ref_" + duplicateIndex + state.dump;
|
|
3009
|
+
}
|
|
3010
|
+
} else {
|
|
3011
|
+
writeFlowSequence(state, arrayLevel, state.dump);
|
|
3012
|
+
if (duplicate) {
|
|
3013
|
+
state.dump = "&ref_" + duplicateIndex + " " + state.dump;
|
|
3014
|
+
}
|
|
3015
|
+
}
|
|
3016
|
+
} else if (type === "[object String]") {
|
|
3017
|
+
if (state.tag !== "?") {
|
|
3018
|
+
writeScalar(state, state.dump, level, iskey);
|
|
3019
|
+
}
|
|
3020
|
+
} else {
|
|
3021
|
+
if (state.skipInvalid)
|
|
3022
|
+
return false;
|
|
3023
|
+
throw new YAMLException("unacceptable kind of an object to dump " + type);
|
|
3024
|
+
}
|
|
3025
|
+
if (state.tag !== null && state.tag !== "?") {
|
|
3026
|
+
state.dump = "!<" + state.tag + "> " + state.dump;
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
return true;
|
|
3030
|
+
}
|
|
3031
|
+
function getDuplicateReferences(object, state) {
|
|
3032
|
+
var objects = [], duplicatesIndexes = [], index, length;
|
|
3033
|
+
inspectNode(object, objects, duplicatesIndexes);
|
|
3034
|
+
for (index = 0, length = duplicatesIndexes.length;index < length; index += 1) {
|
|
3035
|
+
state.duplicates.push(objects[duplicatesIndexes[index]]);
|
|
3036
|
+
}
|
|
3037
|
+
state.usedDuplicates = new Array(length);
|
|
3038
|
+
}
|
|
3039
|
+
function inspectNode(object, objects, duplicatesIndexes) {
|
|
3040
|
+
var objectKeyList, index, length;
|
|
3041
|
+
if (object !== null && typeof object === "object") {
|
|
3042
|
+
index = objects.indexOf(object);
|
|
3043
|
+
if (index !== -1) {
|
|
3044
|
+
if (duplicatesIndexes.indexOf(index) === -1) {
|
|
3045
|
+
duplicatesIndexes.push(index);
|
|
3046
|
+
}
|
|
3047
|
+
} else {
|
|
3048
|
+
objects.push(object);
|
|
3049
|
+
if (Array.isArray(object)) {
|
|
3050
|
+
for (index = 0, length = object.length;index < length; index += 1) {
|
|
3051
|
+
inspectNode(object[index], objects, duplicatesIndexes);
|
|
3052
|
+
}
|
|
3053
|
+
} else {
|
|
3054
|
+
objectKeyList = Object.keys(object);
|
|
3055
|
+
for (index = 0, length = objectKeyList.length;index < length; index += 1) {
|
|
3056
|
+
inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
|
|
3057
|
+
}
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
}
|
|
3061
|
+
}
|
|
3062
|
+
function dump(input, options2) {
|
|
3063
|
+
options2 = options2 || {};
|
|
3064
|
+
var state = new State(options2);
|
|
3065
|
+
if (!state.noRefs)
|
|
3066
|
+
getDuplicateReferences(input, state);
|
|
3067
|
+
if (writeNode(state, 0, input, true, true))
|
|
3068
|
+
return state.dump + `
|
|
3069
|
+
`;
|
|
3070
|
+
return "";
|
|
3071
|
+
}
|
|
3072
|
+
function safeDump(input, options2) {
|
|
3073
|
+
return dump(input, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options2));
|
|
3074
|
+
}
|
|
3075
|
+
exports.dump = dump;
|
|
3076
|
+
exports.safeDump = safeDump;
|
|
3077
|
+
});
|
|
3078
|
+
|
|
3079
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml.js
|
|
3080
|
+
var require_js_yaml = __commonJS((exports, module) => {
|
|
3081
|
+
var loader = require_loader();
|
|
3082
|
+
var dumper = require_dumper();
|
|
3083
|
+
function deprecated(name) {
|
|
3084
|
+
return function() {
|
|
3085
|
+
throw new Error("Function " + name + " is deprecated and cannot be used.");
|
|
3086
|
+
};
|
|
3087
|
+
}
|
|
3088
|
+
exports.Type = require_type();
|
|
3089
|
+
exports.Schema = require_schema();
|
|
3090
|
+
exports.FAILSAFE_SCHEMA = require_failsafe();
|
|
3091
|
+
exports.JSON_SCHEMA = require_json();
|
|
3092
|
+
exports.CORE_SCHEMA = require_core();
|
|
3093
|
+
exports.DEFAULT_SAFE_SCHEMA = require_default_safe();
|
|
3094
|
+
exports.DEFAULT_FULL_SCHEMA = require_default_full();
|
|
3095
|
+
exports.load = loader.load;
|
|
3096
|
+
exports.loadAll = loader.loadAll;
|
|
3097
|
+
exports.safeLoad = loader.safeLoad;
|
|
3098
|
+
exports.safeLoadAll = loader.safeLoadAll;
|
|
3099
|
+
exports.dump = dumper.dump;
|
|
3100
|
+
exports.safeDump = dumper.safeDump;
|
|
3101
|
+
exports.YAMLException = require_exception();
|
|
3102
|
+
exports.MINIMAL_SCHEMA = require_failsafe();
|
|
3103
|
+
exports.SAFE_SCHEMA = require_default_safe();
|
|
3104
|
+
exports.DEFAULT_SCHEMA = require_default_full();
|
|
3105
|
+
exports.scan = deprecated("scan");
|
|
3106
|
+
exports.parse = deprecated("parse");
|
|
3107
|
+
exports.compose = deprecated("compose");
|
|
3108
|
+
exports.addConstructor = deprecated("addConstructor");
|
|
3109
|
+
});
|
|
3110
|
+
|
|
3111
|
+
// node_modules/gray-matter/node_modules/js-yaml/index.js
|
|
3112
|
+
var require_js_yaml2 = __commonJS((exports, module) => {
|
|
3113
|
+
var yaml = require_js_yaml();
|
|
3114
|
+
module.exports = yaml;
|
|
3115
|
+
});
|
|
3116
|
+
|
|
3117
|
+
// node_modules/gray-matter/lib/engines.js
|
|
3118
|
+
var require_engines = __commonJS((exports, module) => {
|
|
3119
|
+
var yaml = require_js_yaml2();
|
|
3120
|
+
var engines = exports = module.exports;
|
|
3121
|
+
engines.yaml = {
|
|
3122
|
+
parse: yaml.safeLoad.bind(yaml),
|
|
3123
|
+
stringify: yaml.safeDump.bind(yaml)
|
|
3124
|
+
};
|
|
3125
|
+
engines.json = {
|
|
3126
|
+
parse: JSON.parse.bind(JSON),
|
|
3127
|
+
stringify: function(obj, options2) {
|
|
3128
|
+
const opts = Object.assign({ replacer: null, space: 2 }, options2);
|
|
3129
|
+
return JSON.stringify(obj, opts.replacer, opts.space);
|
|
3130
|
+
}
|
|
3131
|
+
};
|
|
3132
|
+
engines.javascript = {
|
|
3133
|
+
parse: function parse(str, options, wrap) {
|
|
3134
|
+
try {
|
|
3135
|
+
if (wrap !== false) {
|
|
3136
|
+
str = `(function() {
|
|
3137
|
+
return ` + str.trim() + `;
|
|
3138
|
+
}());`;
|
|
3139
|
+
}
|
|
3140
|
+
return eval(str) || {};
|
|
3141
|
+
} catch (err) {
|
|
3142
|
+
if (wrap !== false && /(unexpected|identifier)/i.test(err.message)) {
|
|
3143
|
+
return parse(str, options, false);
|
|
3144
|
+
}
|
|
3145
|
+
throw new SyntaxError(err);
|
|
3146
|
+
}
|
|
3147
|
+
},
|
|
3148
|
+
stringify: function() {
|
|
3149
|
+
throw new Error("stringifying JavaScript is not supported");
|
|
3150
|
+
}
|
|
3151
|
+
};
|
|
3152
|
+
});
|
|
3153
|
+
|
|
3154
|
+
// node_modules/strip-bom-string/index.js
|
|
3155
|
+
var require_strip_bom_string = __commonJS((exports, module) => {
|
|
3156
|
+
/*!
|
|
3157
|
+
* strip-bom-string <https://github.com/jonschlinkert/strip-bom-string>
|
|
3158
|
+
*
|
|
3159
|
+
* Copyright (c) 2015, 2017, Jon Schlinkert.
|
|
3160
|
+
* Released under the MIT License.
|
|
3161
|
+
*/
|
|
3162
|
+
module.exports = function(str2) {
|
|
3163
|
+
if (typeof str2 === "string" && str2.charAt(0) === "\uFEFF") {
|
|
3164
|
+
return str2.slice(1);
|
|
3165
|
+
}
|
|
3166
|
+
return str2;
|
|
3167
|
+
};
|
|
3168
|
+
});
|
|
3169
|
+
|
|
3170
|
+
// node_modules/gray-matter/lib/utils.js
|
|
3171
|
+
var require_utils = __commonJS((exports) => {
|
|
3172
|
+
var stripBom = require_strip_bom_string();
|
|
3173
|
+
var typeOf = require_kind_of();
|
|
3174
|
+
exports.define = function(obj, key, val) {
|
|
3175
|
+
Reflect.defineProperty(obj, key, {
|
|
3176
|
+
enumerable: false,
|
|
3177
|
+
configurable: true,
|
|
3178
|
+
writable: true,
|
|
3179
|
+
value: val
|
|
3180
|
+
});
|
|
3181
|
+
};
|
|
3182
|
+
exports.isBuffer = function(val) {
|
|
3183
|
+
return typeOf(val) === "buffer";
|
|
3184
|
+
};
|
|
3185
|
+
exports.isObject = function(val) {
|
|
3186
|
+
return typeOf(val) === "object";
|
|
3187
|
+
};
|
|
3188
|
+
exports.toBuffer = function(input) {
|
|
3189
|
+
return typeof input === "string" ? Buffer.from(input) : input;
|
|
3190
|
+
};
|
|
3191
|
+
exports.toString = function(input) {
|
|
3192
|
+
if (exports.isBuffer(input))
|
|
3193
|
+
return stripBom(String(input));
|
|
3194
|
+
if (typeof input !== "string") {
|
|
3195
|
+
throw new TypeError("expected input to be a string or buffer");
|
|
3196
|
+
}
|
|
3197
|
+
return stripBom(input);
|
|
3198
|
+
};
|
|
3199
|
+
exports.arrayify = function(val) {
|
|
3200
|
+
return val ? Array.isArray(val) ? val : [val] : [];
|
|
3201
|
+
};
|
|
3202
|
+
exports.startsWith = function(str2, substr, len) {
|
|
3203
|
+
if (typeof len !== "number")
|
|
3204
|
+
len = substr.length;
|
|
3205
|
+
return str2.slice(0, len) === substr;
|
|
3206
|
+
};
|
|
3207
|
+
});
|
|
3208
|
+
|
|
3209
|
+
// node_modules/gray-matter/lib/defaults.js
|
|
3210
|
+
var require_defaults = __commonJS((exports, module) => {
|
|
3211
|
+
var engines = require_engines();
|
|
3212
|
+
var utils = require_utils();
|
|
3213
|
+
module.exports = function(options2) {
|
|
3214
|
+
const opts = Object.assign({}, options2);
|
|
3215
|
+
opts.delimiters = utils.arrayify(opts.delims || opts.delimiters || "---");
|
|
3216
|
+
if (opts.delimiters.length === 1) {
|
|
3217
|
+
opts.delimiters.push(opts.delimiters[0]);
|
|
3218
|
+
}
|
|
3219
|
+
opts.language = (opts.language || opts.lang || "yaml").toLowerCase();
|
|
3220
|
+
opts.engines = Object.assign({}, engines, opts.parsers, opts.engines);
|
|
3221
|
+
return opts;
|
|
3222
|
+
};
|
|
3223
|
+
});
|
|
3224
|
+
|
|
3225
|
+
// node_modules/gray-matter/lib/engine.js
|
|
3226
|
+
var require_engine = __commonJS((exports, module) => {
|
|
3227
|
+
module.exports = function(name, options2) {
|
|
3228
|
+
let engine = options2.engines[name] || options2.engines[aliase(name)];
|
|
3229
|
+
if (typeof engine === "undefined") {
|
|
3230
|
+
throw new Error('gray-matter engine "' + name + '" is not registered');
|
|
3231
|
+
}
|
|
3232
|
+
if (typeof engine === "function") {
|
|
3233
|
+
engine = { parse: engine };
|
|
3234
|
+
}
|
|
3235
|
+
return engine;
|
|
3236
|
+
};
|
|
3237
|
+
function aliase(name) {
|
|
3238
|
+
switch (name.toLowerCase()) {
|
|
3239
|
+
case "js":
|
|
3240
|
+
case "javascript":
|
|
3241
|
+
return "javascript";
|
|
3242
|
+
case "coffee":
|
|
3243
|
+
case "coffeescript":
|
|
3244
|
+
case "cson":
|
|
3245
|
+
return "coffee";
|
|
3246
|
+
case "yaml":
|
|
3247
|
+
case "yml":
|
|
3248
|
+
return "yaml";
|
|
3249
|
+
default: {
|
|
3250
|
+
return name;
|
|
3251
|
+
}
|
|
3252
|
+
}
|
|
3253
|
+
}
|
|
3254
|
+
});
|
|
3255
|
+
|
|
3256
|
+
// node_modules/gray-matter/lib/stringify.js
|
|
3257
|
+
var require_stringify = __commonJS((exports, module) => {
|
|
3258
|
+
var typeOf = require_kind_of();
|
|
3259
|
+
var getEngine = require_engine();
|
|
3260
|
+
var defaults = require_defaults();
|
|
3261
|
+
module.exports = function(file, data, options2) {
|
|
3262
|
+
if (data == null && options2 == null) {
|
|
3263
|
+
switch (typeOf(file)) {
|
|
3264
|
+
case "object":
|
|
3265
|
+
data = file.data;
|
|
3266
|
+
options2 = {};
|
|
3267
|
+
break;
|
|
3268
|
+
case "string":
|
|
3269
|
+
return file;
|
|
3270
|
+
default: {
|
|
3271
|
+
throw new TypeError("expected file to be a string or object");
|
|
3272
|
+
}
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
3275
|
+
const str2 = file.content;
|
|
3276
|
+
const opts = defaults(options2);
|
|
3277
|
+
if (data == null) {
|
|
3278
|
+
if (!opts.data)
|
|
3279
|
+
return file;
|
|
3280
|
+
data = opts.data;
|
|
3281
|
+
}
|
|
3282
|
+
const language = file.language || opts.language;
|
|
3283
|
+
const engine = getEngine(language, opts);
|
|
3284
|
+
if (typeof engine.stringify !== "function") {
|
|
3285
|
+
throw new TypeError('expected "' + language + '.stringify" to be a function');
|
|
3286
|
+
}
|
|
3287
|
+
data = Object.assign({}, file.data, data);
|
|
3288
|
+
const open = opts.delimiters[0];
|
|
3289
|
+
const close = opts.delimiters[1];
|
|
3290
|
+
const matter = engine.stringify(data, options2).trim();
|
|
3291
|
+
let buf = "";
|
|
3292
|
+
if (matter !== "{}") {
|
|
3293
|
+
buf = newline(open) + newline(matter) + newline(close);
|
|
3294
|
+
}
|
|
3295
|
+
if (typeof file.excerpt === "string" && file.excerpt !== "") {
|
|
3296
|
+
if (str2.indexOf(file.excerpt.trim()) === -1) {
|
|
3297
|
+
buf += newline(file.excerpt) + newline(close);
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
return buf + newline(str2);
|
|
3301
|
+
};
|
|
3302
|
+
function newline(str2) {
|
|
3303
|
+
return str2.slice(-1) !== `
|
|
3304
|
+
` ? str2 + `
|
|
3305
|
+
` : str2;
|
|
3306
|
+
}
|
|
3307
|
+
});
|
|
3308
|
+
|
|
3309
|
+
// node_modules/gray-matter/lib/excerpt.js
|
|
3310
|
+
var require_excerpt = __commonJS((exports, module) => {
|
|
3311
|
+
var defaults = require_defaults();
|
|
3312
|
+
module.exports = function(file, options2) {
|
|
3313
|
+
const opts = defaults(options2);
|
|
3314
|
+
if (file.data == null) {
|
|
3315
|
+
file.data = {};
|
|
3316
|
+
}
|
|
3317
|
+
if (typeof opts.excerpt === "function") {
|
|
3318
|
+
return opts.excerpt(file, opts);
|
|
3319
|
+
}
|
|
3320
|
+
const sep = file.data.excerpt_separator || opts.excerpt_separator;
|
|
3321
|
+
if (sep == null && (opts.excerpt === false || opts.excerpt == null)) {
|
|
3322
|
+
return file;
|
|
3323
|
+
}
|
|
3324
|
+
const delimiter = typeof opts.excerpt === "string" ? opts.excerpt : sep || opts.delimiters[0];
|
|
3325
|
+
const idx = file.content.indexOf(delimiter);
|
|
3326
|
+
if (idx !== -1) {
|
|
3327
|
+
file.excerpt = file.content.slice(0, idx);
|
|
3328
|
+
}
|
|
3329
|
+
return file;
|
|
3330
|
+
};
|
|
3331
|
+
});
|
|
3332
|
+
|
|
3333
|
+
// node_modules/gray-matter/lib/to-file.js
|
|
3334
|
+
var require_to_file = __commonJS((exports, module) => {
|
|
3335
|
+
var typeOf = require_kind_of();
|
|
3336
|
+
var stringify = require_stringify();
|
|
3337
|
+
var utils = require_utils();
|
|
3338
|
+
module.exports = function(file) {
|
|
3339
|
+
if (typeOf(file) !== "object") {
|
|
3340
|
+
file = { content: file };
|
|
3341
|
+
}
|
|
3342
|
+
if (typeOf(file.data) !== "object") {
|
|
3343
|
+
file.data = {};
|
|
3344
|
+
}
|
|
3345
|
+
if (file.contents && file.content == null) {
|
|
3346
|
+
file.content = file.contents;
|
|
3347
|
+
}
|
|
3348
|
+
utils.define(file, "orig", utils.toBuffer(file.content));
|
|
3349
|
+
utils.define(file, "language", file.language || "");
|
|
3350
|
+
utils.define(file, "matter", file.matter || "");
|
|
3351
|
+
utils.define(file, "stringify", function(data, options2) {
|
|
3352
|
+
if (options2 && options2.language) {
|
|
3353
|
+
file.language = options2.language;
|
|
3354
|
+
}
|
|
3355
|
+
return stringify(file, data, options2);
|
|
3356
|
+
});
|
|
3357
|
+
file.content = utils.toString(file.content);
|
|
3358
|
+
file.isEmpty = false;
|
|
3359
|
+
file.excerpt = "";
|
|
3360
|
+
return file;
|
|
3361
|
+
};
|
|
3362
|
+
});
|
|
3363
|
+
|
|
3364
|
+
// node_modules/gray-matter/lib/parse.js
|
|
3365
|
+
var require_parse = __commonJS((exports, module) => {
|
|
3366
|
+
var getEngine = require_engine();
|
|
3367
|
+
var defaults = require_defaults();
|
|
3368
|
+
module.exports = function(language, str2, options2) {
|
|
3369
|
+
const opts = defaults(options2);
|
|
3370
|
+
const engine = getEngine(language, opts);
|
|
3371
|
+
if (typeof engine.parse !== "function") {
|
|
3372
|
+
throw new TypeError('expected "' + language + '.parse" to be a function');
|
|
3373
|
+
}
|
|
3374
|
+
return engine.parse(str2, opts);
|
|
3375
|
+
};
|
|
3376
|
+
});
|
|
3377
|
+
|
|
3378
|
+
// node_modules/gray-matter/index.js
|
|
3379
|
+
var require_gray_matter = __commonJS((exports, module) => {
|
|
3380
|
+
var fs = __require("fs");
|
|
3381
|
+
var sections = require_section_matter();
|
|
3382
|
+
var defaults = require_defaults();
|
|
3383
|
+
var stringify = require_stringify();
|
|
3384
|
+
var excerpt = require_excerpt();
|
|
3385
|
+
var engines = require_engines();
|
|
3386
|
+
var toFile = require_to_file();
|
|
3387
|
+
var parse2 = require_parse();
|
|
3388
|
+
var utils = require_utils();
|
|
3389
|
+
function matter(input, options2) {
|
|
3390
|
+
if (input === "") {
|
|
3391
|
+
return { data: {}, content: input, excerpt: "", orig: input };
|
|
3392
|
+
}
|
|
3393
|
+
let file = toFile(input);
|
|
3394
|
+
const cached = matter.cache[file.content];
|
|
3395
|
+
if (!options2) {
|
|
3396
|
+
if (cached) {
|
|
3397
|
+
file = Object.assign({}, cached);
|
|
3398
|
+
file.orig = cached.orig;
|
|
3399
|
+
return file;
|
|
3400
|
+
}
|
|
3401
|
+
matter.cache[file.content] = file;
|
|
3402
|
+
}
|
|
3403
|
+
return parseMatter(file, options2);
|
|
3404
|
+
}
|
|
3405
|
+
function parseMatter(file, options2) {
|
|
3406
|
+
const opts = defaults(options2);
|
|
3407
|
+
const open = opts.delimiters[0];
|
|
3408
|
+
const close = `
|
|
3409
|
+
` + opts.delimiters[1];
|
|
3410
|
+
let str2 = file.content;
|
|
3411
|
+
if (opts.language) {
|
|
3412
|
+
file.language = opts.language;
|
|
3413
|
+
}
|
|
3414
|
+
const openLen = open.length;
|
|
3415
|
+
if (!utils.startsWith(str2, open, openLen)) {
|
|
3416
|
+
excerpt(file, opts);
|
|
3417
|
+
return file;
|
|
3418
|
+
}
|
|
3419
|
+
if (str2.charAt(openLen) === open.slice(-1)) {
|
|
3420
|
+
return file;
|
|
3421
|
+
}
|
|
3422
|
+
str2 = str2.slice(openLen);
|
|
3423
|
+
const len = str2.length;
|
|
3424
|
+
const language = matter.language(str2, opts);
|
|
3425
|
+
if (language.name) {
|
|
3426
|
+
file.language = language.name;
|
|
3427
|
+
str2 = str2.slice(language.raw.length);
|
|
3428
|
+
}
|
|
3429
|
+
let closeIndex = str2.indexOf(close);
|
|
3430
|
+
if (closeIndex === -1) {
|
|
3431
|
+
closeIndex = len;
|
|
3432
|
+
}
|
|
3433
|
+
file.matter = str2.slice(0, closeIndex);
|
|
3434
|
+
const block = file.matter.replace(/^\s*#[^\n]+/gm, "").trim();
|
|
3435
|
+
if (block === "") {
|
|
3436
|
+
file.isEmpty = true;
|
|
3437
|
+
file.empty = file.content;
|
|
3438
|
+
file.data = {};
|
|
3439
|
+
} else {
|
|
3440
|
+
file.data = parse2(file.language, file.matter, opts);
|
|
3441
|
+
}
|
|
3442
|
+
if (closeIndex === len) {
|
|
3443
|
+
file.content = "";
|
|
3444
|
+
} else {
|
|
3445
|
+
file.content = str2.slice(closeIndex + close.length);
|
|
3446
|
+
if (file.content[0] === "\r") {
|
|
3447
|
+
file.content = file.content.slice(1);
|
|
3448
|
+
}
|
|
3449
|
+
if (file.content[0] === `
|
|
3450
|
+
`) {
|
|
3451
|
+
file.content = file.content.slice(1);
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
excerpt(file, opts);
|
|
3455
|
+
if (opts.sections === true || typeof opts.section === "function") {
|
|
3456
|
+
sections(file, opts.section);
|
|
3457
|
+
}
|
|
3458
|
+
return file;
|
|
3459
|
+
}
|
|
3460
|
+
matter.engines = engines;
|
|
3461
|
+
matter.stringify = function(file, data, options2) {
|
|
3462
|
+
if (typeof file === "string")
|
|
3463
|
+
file = matter(file, options2);
|
|
3464
|
+
return stringify(file, data, options2);
|
|
3465
|
+
};
|
|
3466
|
+
matter.read = function(filepath, options2) {
|
|
3467
|
+
const str2 = fs.readFileSync(filepath, "utf8");
|
|
3468
|
+
const file = matter(str2, options2);
|
|
3469
|
+
file.path = filepath;
|
|
3470
|
+
return file;
|
|
3471
|
+
};
|
|
3472
|
+
matter.test = function(str2, options2) {
|
|
3473
|
+
return utils.startsWith(str2, defaults(options2).delimiters[0]);
|
|
3474
|
+
};
|
|
3475
|
+
matter.language = function(str2, options2) {
|
|
3476
|
+
const opts = defaults(options2);
|
|
3477
|
+
const open = opts.delimiters[0];
|
|
3478
|
+
if (matter.test(str2)) {
|
|
3479
|
+
str2 = str2.slice(open.length);
|
|
3480
|
+
}
|
|
3481
|
+
const language = str2.slice(0, str2.search(/\r?\n/));
|
|
3482
|
+
return {
|
|
3483
|
+
raw: language,
|
|
3484
|
+
name: language ? language.trim() : ""
|
|
3485
|
+
};
|
|
3486
|
+
};
|
|
3487
|
+
matter.cache = {};
|
|
3488
|
+
matter.clearCache = function() {
|
|
3489
|
+
matter.cache = {};
|
|
3490
|
+
};
|
|
3491
|
+
module.exports = matter;
|
|
3492
|
+
});
|
|
3493
|
+
|
|
3494
|
+
// src/utilities/content.ts
|
|
3495
|
+
function normalizeContent(content) {
|
|
3496
|
+
if (content === undefined)
|
|
3497
|
+
return;
|
|
3498
|
+
if (typeof content === "string")
|
|
3499
|
+
return content;
|
|
3500
|
+
return Array.isArray(content) ? content : [content];
|
|
3501
|
+
}
|
|
3502
|
+
// src/multi-modal.ts
|
|
3503
|
+
function copyMultiModalContent(item) {
|
|
3504
|
+
if (item.type === "text") {
|
|
3505
|
+
const result2 = { type: "text" };
|
|
3506
|
+
if (item.text !== undefined)
|
|
3507
|
+
result2.text = item.text;
|
|
3508
|
+
return result2;
|
|
3509
|
+
}
|
|
3510
|
+
const result = { type: "image" };
|
|
3511
|
+
if (item.url !== undefined)
|
|
3512
|
+
result.url = item.url;
|
|
3513
|
+
if (item.mimeType !== undefined)
|
|
3514
|
+
result.mimeType = item.mimeType;
|
|
3515
|
+
if (item.text !== undefined)
|
|
3516
|
+
result.text = item.text;
|
|
3517
|
+
return result;
|
|
3518
|
+
}
|
|
3519
|
+
function copyContent(content) {
|
|
3520
|
+
if (typeof content === "string") {
|
|
3521
|
+
return content;
|
|
3522
|
+
}
|
|
3523
|
+
return content.map(copyMultiModalContent);
|
|
3524
|
+
}
|
|
3525
|
+
|
|
3526
|
+
// src/utilities/type-helpers.ts
|
|
3527
|
+
function toReadonly(value) {
|
|
3528
|
+
return value;
|
|
3529
|
+
}
|
|
3530
|
+
|
|
3531
|
+
// src/utilities/message.ts
|
|
3532
|
+
function createMessage(props) {
|
|
3533
|
+
const content = typeof props.content === "string" ? props.content : toReadonly(props.content.map((part) => part));
|
|
3534
|
+
const message = {
|
|
3535
|
+
id: props.id,
|
|
3536
|
+
role: props.role,
|
|
3537
|
+
content,
|
|
3538
|
+
position: props.position,
|
|
3539
|
+
createdAt: props.createdAt,
|
|
3540
|
+
metadata: toReadonly({ ...props.metadata }),
|
|
3541
|
+
hidden: props.hidden,
|
|
3542
|
+
toolCall: props.toolCall ? toReadonly({ ...props.toolCall }) : undefined,
|
|
3543
|
+
toolResult: props.toolResult ? toReadonly({ ...props.toolResult }) : undefined,
|
|
3544
|
+
tokenUsage: props.tokenUsage ? toReadonly({ ...props.tokenUsage }) : undefined
|
|
3545
|
+
};
|
|
3546
|
+
if (isAssistantMessage(props)) {
|
|
3547
|
+
return toReadonly({
|
|
3548
|
+
...message,
|
|
3549
|
+
role: "assistant",
|
|
3550
|
+
goalCompleted: props.goalCompleted
|
|
3551
|
+
});
|
|
3552
|
+
}
|
|
3553
|
+
return toReadonly(message);
|
|
3554
|
+
}
|
|
3555
|
+
function messageParts(message) {
|
|
3556
|
+
if (typeof message.content === "string") {
|
|
3557
|
+
return message.content ? [{ type: "text", text: message.content }] : [];
|
|
3558
|
+
}
|
|
3559
|
+
return message.content;
|
|
3560
|
+
}
|
|
3561
|
+
function messageText(message, joiner = `
|
|
3562
|
+
|
|
3563
|
+
`) {
|
|
3564
|
+
if (typeof message.content === "string")
|
|
3565
|
+
return message.content;
|
|
3566
|
+
return messageParts(message).filter((p) => p.type === "text").map((p) => p.type === "text" ? p.text : "").join(joiner);
|
|
3567
|
+
}
|
|
3568
|
+
function messageHasImages(message) {
|
|
3569
|
+
return messageParts(message).some((p) => p.type === "image");
|
|
3570
|
+
}
|
|
3571
|
+
function isAssistantMessage(message) {
|
|
3572
|
+
return message.role === "assistant";
|
|
3573
|
+
}
|
|
3574
|
+
// src/utilities/message-store.ts
|
|
3575
|
+
function getOrderedMessages(conversation) {
|
|
3576
|
+
const ordered = [];
|
|
3577
|
+
for (const id of conversation.ids) {
|
|
3578
|
+
const message = conversation.messages[id];
|
|
3579
|
+
if (message) {
|
|
3580
|
+
ordered.push(message);
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
return ordered;
|
|
3584
|
+
}
|
|
3585
|
+
function toIdRecord(items) {
|
|
3586
|
+
const record = {};
|
|
3587
|
+
for (const item of items) {
|
|
3588
|
+
record[item.id] = item;
|
|
3589
|
+
}
|
|
3590
|
+
return record;
|
|
3591
|
+
}
|
|
3592
|
+
|
|
3593
|
+
// src/utilities/transient.ts
|
|
3594
|
+
function isTransientKey(key) {
|
|
3595
|
+
return key.startsWith("_");
|
|
3596
|
+
}
|
|
3597
|
+
function stripTransientFromRecord(metadata) {
|
|
3598
|
+
const result = {};
|
|
3599
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
3600
|
+
if (!isTransientKey(key)) {
|
|
3601
|
+
result[key] = value;
|
|
3602
|
+
}
|
|
3603
|
+
}
|
|
3604
|
+
return result;
|
|
3605
|
+
}
|
|
3606
|
+
// src/environment.ts
|
|
3607
|
+
function simpleTokenEstimator(message) {
|
|
3608
|
+
const text = messageText(message);
|
|
3609
|
+
return Math.ceil(text.length / 4);
|
|
3610
|
+
}
|
|
3611
|
+
var defaultConversationEnvironment = {
|
|
3612
|
+
now: () => new Date().toISOString(),
|
|
3613
|
+
randomId: () => crypto.randomUUID(),
|
|
3614
|
+
estimateTokens: simpleTokenEstimator,
|
|
3615
|
+
plugins: []
|
|
3616
|
+
};
|
|
3617
|
+
function resolveConversationEnvironment(environment) {
|
|
3618
|
+
return {
|
|
3619
|
+
now: environment?.now ?? defaultConversationEnvironment.now,
|
|
3620
|
+
randomId: environment?.randomId ?? defaultConversationEnvironment.randomId,
|
|
3621
|
+
estimateTokens: environment?.estimateTokens ?? defaultConversationEnvironment.estimateTokens,
|
|
3622
|
+
plugins: [...environment?.plugins ?? defaultConversationEnvironment.plugins]
|
|
3623
|
+
};
|
|
3624
|
+
}
|
|
3625
|
+
function isConversationEnvironmentParameter(value) {
|
|
3626
|
+
if (!value || typeof value !== "object" || value === null)
|
|
3627
|
+
return false;
|
|
3628
|
+
if ("role" in value)
|
|
3629
|
+
return false;
|
|
3630
|
+
const candidate = value;
|
|
3631
|
+
return typeof candidate["now"] === "function" || typeof candidate["randomId"] === "function" || typeof candidate["estimateTokens"] === "function" || Array.isArray(candidate["plugins"]) && candidate["plugins"].length > 0;
|
|
3632
|
+
}
|
|
3633
|
+
|
|
3634
|
+
// src/context.ts
|
|
3635
|
+
var cloneMessageWithPosition = (message, position, content) => {
|
|
3636
|
+
const baseMessage = {
|
|
3637
|
+
id: message.id,
|
|
3638
|
+
role: message.role,
|
|
3639
|
+
content,
|
|
3640
|
+
position,
|
|
3641
|
+
createdAt: message.createdAt,
|
|
3642
|
+
metadata: { ...message.metadata },
|
|
3643
|
+
hidden: message.hidden,
|
|
3644
|
+
toolCall: message.toolCall ? { ...message.toolCall } : undefined,
|
|
3645
|
+
toolResult: message.toolResult ? { ...message.toolResult } : undefined,
|
|
3646
|
+
tokenUsage: message.tokenUsage ? { ...message.tokenUsage } : undefined
|
|
3647
|
+
};
|
|
3648
|
+
if (isAssistantMessage(message)) {
|
|
3649
|
+
const assistantMessage = {
|
|
3650
|
+
...baseMessage,
|
|
3651
|
+
role: "assistant",
|
|
3652
|
+
goalCompleted: message.goalCompleted
|
|
3653
|
+
};
|
|
3654
|
+
return createMessage(assistantMessage);
|
|
3655
|
+
}
|
|
3656
|
+
return createMessage(baseMessage);
|
|
3657
|
+
};
|
|
3658
|
+
function estimateConversationTokens(conversation, estimateTokens, environment) {
|
|
3659
|
+
let estimator = estimateTokens;
|
|
3660
|
+
let env = environment;
|
|
3661
|
+
if (!environment && estimateTokens && isConversationEnvironmentParameter(estimateTokens)) {
|
|
3662
|
+
env = estimateTokens;
|
|
3663
|
+
estimator = undefined;
|
|
3664
|
+
}
|
|
3665
|
+
const resolvedEnvironment = resolveConversationEnvironment(env);
|
|
3666
|
+
const finalEstimator = typeof estimator === "function" ? estimator : resolvedEnvironment.estimateTokens;
|
|
3667
|
+
return getOrderedMessages(conversation).reduce((total, message) => total + finalEstimator(message), 0);
|
|
3668
|
+
}
|
|
3669
|
+
function truncateToTokenLimit(conversation, maxTokens, optionsOrEstimator, environment) {
|
|
3670
|
+
let options2 = {};
|
|
3671
|
+
let env = environment;
|
|
3672
|
+
if (typeof optionsOrEstimator === "function") {
|
|
3673
|
+
options2 = { estimateTokens: optionsOrEstimator };
|
|
3674
|
+
} else if (optionsOrEstimator) {
|
|
3675
|
+
if (!environment && isConversationEnvironmentParameter(optionsOrEstimator)) {
|
|
3676
|
+
const candidate = optionsOrEstimator;
|
|
3677
|
+
const hasEnvFields = !!(candidate["now"] || candidate["randomId"] || Array.isArray(candidate["plugins"]) && candidate["plugins"].length > 0);
|
|
3678
|
+
if (hasEnvFields) {
|
|
3679
|
+
env = optionsOrEstimator;
|
|
3680
|
+
} else {
|
|
3681
|
+
options2 = optionsOrEstimator;
|
|
3682
|
+
}
|
|
3683
|
+
} else {
|
|
3684
|
+
options2 = optionsOrEstimator;
|
|
3685
|
+
}
|
|
3686
|
+
}
|
|
3687
|
+
const resolvedEnvironment = resolveConversationEnvironment(env);
|
|
3688
|
+
const estimator = options2.estimateTokens ?? resolvedEnvironment.estimateTokens;
|
|
3689
|
+
const preserveSystem = options2.preserveSystemMessages ?? true;
|
|
3690
|
+
const preserveLastN = options2.preserveLastN ?? 0;
|
|
3691
|
+
const currentTokens = estimateConversationTokens(conversation, estimator, resolvedEnvironment);
|
|
3692
|
+
if (currentTokens <= maxTokens) {
|
|
3693
|
+
return conversation;
|
|
3694
|
+
}
|
|
3695
|
+
const now = resolvedEnvironment.now();
|
|
3696
|
+
const orderedMessages = getOrderedMessages(conversation);
|
|
3697
|
+
const systemMessages = preserveSystem ? orderedMessages.filter((m) => m.role === "system") : [];
|
|
3698
|
+
const nonSystemMessages = orderedMessages.filter((m) => m.role !== "system");
|
|
3699
|
+
const protectedMessages = preserveLastN > 0 ? nonSystemMessages.slice(-preserveLastN) : [];
|
|
3700
|
+
const removableMessages = preserveLastN > 0 ? nonSystemMessages.slice(0, -preserveLastN) : nonSystemMessages;
|
|
3701
|
+
const systemTokens = systemMessages.reduce((sum, m) => sum + estimator(m), 0);
|
|
3702
|
+
const protectedTokens = protectedMessages.reduce((sum, m) => sum + estimator(m), 0);
|
|
3703
|
+
const availableTokens = maxTokens - systemTokens - protectedTokens;
|
|
3704
|
+
if (availableTokens <= 0) {
|
|
3705
|
+
const allMessages2 = [...systemMessages, ...protectedMessages];
|
|
3706
|
+
const renumbered2 = allMessages2.map((message, index) => cloneMessageWithPosition(message, index, copyContent(message.content)));
|
|
3707
|
+
return toReadonly({
|
|
3708
|
+
...conversation,
|
|
3709
|
+
ids: renumbered2.map((message) => message.id),
|
|
3710
|
+
messages: toIdRecord(renumbered2),
|
|
3711
|
+
updatedAt: now
|
|
3712
|
+
});
|
|
3713
|
+
}
|
|
3714
|
+
const keptRemovable = [];
|
|
3715
|
+
let usedTokens = 0;
|
|
3716
|
+
for (let i = removableMessages.length - 1;i >= 0; i--) {
|
|
3717
|
+
const message = removableMessages[i];
|
|
3718
|
+
const messageTokens = estimator(message);
|
|
3719
|
+
if (usedTokens + messageTokens <= availableTokens) {
|
|
3720
|
+
keptRemovable.unshift(message);
|
|
3721
|
+
usedTokens += messageTokens;
|
|
3722
|
+
} else {
|
|
3723
|
+
break;
|
|
3724
|
+
}
|
|
3725
|
+
}
|
|
3726
|
+
const allMessages = [...systemMessages, ...keptRemovable, ...protectedMessages];
|
|
3727
|
+
allMessages.sort((a, b) => a.position - b.position);
|
|
3728
|
+
const renumbered = allMessages.map((message, index) => cloneMessageWithPosition(message, index, copyContent(message.content)));
|
|
3729
|
+
return toReadonly({
|
|
3730
|
+
...conversation,
|
|
3731
|
+
ids: renumbered.map((message) => message.id),
|
|
3732
|
+
messages: toIdRecord(renumbered),
|
|
3733
|
+
updatedAt: now
|
|
3734
|
+
});
|
|
3735
|
+
}
|
|
3736
|
+
function getRecentMessages(conversation, count, options2) {
|
|
3737
|
+
const includeHidden = options2?.includeHidden ?? false;
|
|
3738
|
+
const includeSystem = options2?.includeSystem ?? false;
|
|
3739
|
+
const filtered = getOrderedMessages(conversation).filter((m) => {
|
|
3740
|
+
if (!includeHidden && m.hidden)
|
|
3741
|
+
return false;
|
|
3742
|
+
if (!includeSystem && m.role === "system")
|
|
3743
|
+
return false;
|
|
3744
|
+
return true;
|
|
3745
|
+
});
|
|
3746
|
+
return filtered.slice(-count);
|
|
3747
|
+
}
|
|
3748
|
+
function truncateFromPosition(conversation, position, options2, environment) {
|
|
3749
|
+
const preserveSystem = options2?.preserveSystemMessages ?? true;
|
|
3750
|
+
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
3751
|
+
const now = resolvedEnvironment.now();
|
|
3752
|
+
const ordered = getOrderedMessages(conversation);
|
|
3753
|
+
const systemMessages = preserveSystem ? ordered.filter((m) => m.role === "system" && m.position < position) : [];
|
|
3754
|
+
const keptMessages = ordered.filter((m) => m.position >= position);
|
|
3755
|
+
const allMessages = [...systemMessages, ...keptMessages];
|
|
3756
|
+
const renumbered = allMessages.map((message, index) => cloneMessageWithPosition(message, index, copyContent(message.content)));
|
|
3757
|
+
return toReadonly({
|
|
3758
|
+
...conversation,
|
|
3759
|
+
ids: renumbered.map((message) => message.id),
|
|
3760
|
+
messages: toIdRecord(renumbered),
|
|
3761
|
+
updatedAt: now
|
|
3762
|
+
});
|
|
3763
|
+
}
|
|
3764
|
+
|
|
3765
|
+
// src/errors.ts
|
|
3766
|
+
class ConversationalistError extends Error {
|
|
3767
|
+
code;
|
|
3768
|
+
context;
|
|
3769
|
+
cause;
|
|
3770
|
+
constructor(code, message, options2) {
|
|
3771
|
+
super(message);
|
|
3772
|
+
this.name = "ConversationalistError";
|
|
3773
|
+
this.code = code;
|
|
3774
|
+
this.context = options2?.context;
|
|
3775
|
+
this.cause = options2?.cause;
|
|
3776
|
+
if (Error.captureStackTrace) {
|
|
3777
|
+
Error.captureStackTrace(this, ConversationalistError);
|
|
3778
|
+
}
|
|
3779
|
+
}
|
|
3780
|
+
toDetailedString() {
|
|
3781
|
+
const parts = [`[${this.code}] ${this.message}`];
|
|
3782
|
+
if (this.context && Object.keys(this.context).length > 0) {
|
|
3783
|
+
parts.push(`Context: ${JSON.stringify(this.context, null, 2)}`);
|
|
3784
|
+
}
|
|
3785
|
+
if (this.cause) {
|
|
3786
|
+
parts.push(`Caused by: ${this.cause.message}`);
|
|
3787
|
+
}
|
|
3788
|
+
return parts.join(`
|
|
3789
|
+
`);
|
|
3790
|
+
}
|
|
3791
|
+
}
|
|
3792
|
+
function createInvalidPositionError(expected, actual) {
|
|
3793
|
+
return new ConversationalistError("error:invalid-position", `invalid position: expected ${expected}, got ${actual}`, { context: { expected, actual } });
|
|
3794
|
+
}
|
|
3795
|
+
function createInvalidToolReferenceError(callId) {
|
|
3796
|
+
return new ConversationalistError("error:invalid-tool-reference", `tool result references non-existent tool-use: ${callId}`, { context: { callId } });
|
|
3797
|
+
}
|
|
3798
|
+
function createSerializationError(message, cause) {
|
|
3799
|
+
return new ConversationalistError("error:serialization", message, { cause });
|
|
3800
|
+
}
|
|
3801
|
+
|
|
3802
|
+
// src/types.ts
|
|
3803
|
+
var CURRENT_SCHEMA_VERSION = 3;
|
|
3804
|
+
|
|
3805
|
+
// src/conversation.ts
|
|
3806
|
+
var buildToolUseIndex = (messages) => messages.reduce((index, message) => {
|
|
3807
|
+
if (message.role === "tool-use" && message.toolCall) {
|
|
3808
|
+
index.set(message.toolCall.id, { name: message.toolCall.name });
|
|
3809
|
+
}
|
|
3810
|
+
return index;
|
|
3811
|
+
}, new Map);
|
|
3812
|
+
var registerToolUse = (index, toolCall) => {
|
|
3813
|
+
const next = new Map(index);
|
|
3814
|
+
next.set(toolCall.id, { name: toolCall.name });
|
|
3815
|
+
return next;
|
|
3816
|
+
};
|
|
3817
|
+
var assertToolReference = (index, callId) => {
|
|
3818
|
+
if (!index.has(callId)) {
|
|
3819
|
+
throw createInvalidToolReferenceError(callId);
|
|
3820
|
+
}
|
|
3821
|
+
};
|
|
3822
|
+
function partitionAppendArgs(args) {
|
|
3823
|
+
if (args.length === 0) {
|
|
3824
|
+
return { inputs: [] };
|
|
3825
|
+
}
|
|
3826
|
+
const last = args[args.length - 1];
|
|
3827
|
+
if (isConversationEnvironmentParameter(last)) {
|
|
3828
|
+
return {
|
|
3829
|
+
inputs: args.slice(0, -1),
|
|
3830
|
+
environment: last
|
|
3831
|
+
};
|
|
3832
|
+
}
|
|
3833
|
+
return { inputs: args };
|
|
3834
|
+
}
|
|
3835
|
+
function createConversation(options2, environment) {
|
|
3836
|
+
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
3837
|
+
const now = resolvedEnvironment.now();
|
|
3838
|
+
const conv = {
|
|
3839
|
+
schemaVersion: CURRENT_SCHEMA_VERSION,
|
|
3840
|
+
id: options2?.id ?? resolvedEnvironment.randomId(),
|
|
3841
|
+
title: options2?.title,
|
|
3842
|
+
status: options2?.status ?? "active",
|
|
3843
|
+
metadata: { ...options2?.metadata ?? {} },
|
|
3844
|
+
ids: [],
|
|
3845
|
+
messages: {},
|
|
3846
|
+
createdAt: now,
|
|
3847
|
+
updatedAt: now
|
|
3848
|
+
};
|
|
3849
|
+
return toReadonly(conv);
|
|
3850
|
+
}
|
|
3851
|
+
function appendMessages(conversation, ...args) {
|
|
3852
|
+
const { inputs, environment } = partitionAppendArgs(args);
|
|
3853
|
+
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
3854
|
+
const now = resolvedEnvironment.now();
|
|
3855
|
+
const startPosition = conversation.ids.length;
|
|
3856
|
+
const initialToolUses = buildToolUseIndex(getOrderedMessages(conversation));
|
|
3857
|
+
const { messages } = inputs.reduce((state, input, index) => {
|
|
3858
|
+
const processedInput = resolvedEnvironment.plugins.reduce((acc, plugin) => plugin(acc), input);
|
|
3859
|
+
if (processedInput.role === "tool-result" && processedInput.toolResult) {
|
|
3860
|
+
assertToolReference(state.toolUses, processedInput.toolResult.callId);
|
|
3861
|
+
}
|
|
3862
|
+
const normalizedContent = normalizeContent(processedInput.content);
|
|
3863
|
+
const baseMessage = {
|
|
3864
|
+
id: resolvedEnvironment.randomId(),
|
|
3865
|
+
role: processedInput.role,
|
|
3866
|
+
content: normalizedContent,
|
|
3867
|
+
position: startPosition + index,
|
|
3868
|
+
createdAt: now,
|
|
3869
|
+
metadata: { ...processedInput.metadata ?? {} },
|
|
3870
|
+
hidden: processedInput.hidden ?? false,
|
|
3871
|
+
toolCall: processedInput.toolCall,
|
|
3872
|
+
toolResult: processedInput.toolResult,
|
|
3873
|
+
tokenUsage: processedInput.tokenUsage
|
|
3874
|
+
};
|
|
3875
|
+
let message;
|
|
3876
|
+
if (processedInput.role === "assistant") {
|
|
3877
|
+
const assistantMessage = {
|
|
3878
|
+
...baseMessage,
|
|
3879
|
+
role: "assistant",
|
|
3880
|
+
goalCompleted: processedInput.goalCompleted
|
|
3881
|
+
};
|
|
3882
|
+
message = createMessage(assistantMessage);
|
|
3883
|
+
} else {
|
|
3884
|
+
message = createMessage(baseMessage);
|
|
3885
|
+
}
|
|
3886
|
+
const toolUses = processedInput.role === "tool-use" && processedInput.toolCall ? registerToolUse(state.toolUses, processedInput.toolCall) : state.toolUses;
|
|
3887
|
+
return {
|
|
3888
|
+
toolUses,
|
|
3889
|
+
messages: [...state.messages, message]
|
|
3890
|
+
};
|
|
3891
|
+
}, { toolUses: initialToolUses, messages: [] });
|
|
3892
|
+
const messageIds = messages.map((message) => message.id);
|
|
3893
|
+
const next = {
|
|
3894
|
+
...conversation,
|
|
3895
|
+
ids: [...conversation.ids, ...messageIds],
|
|
3896
|
+
messages: { ...conversation.messages, ...toIdRecord(messages) },
|
|
3897
|
+
updatedAt: now
|
|
3898
|
+
};
|
|
3899
|
+
return toReadonly(next);
|
|
3900
|
+
}
|
|
3901
|
+
function appendUserMessage(conversation, content, metadata, environment) {
|
|
3902
|
+
return environment ? appendMessages(conversation, { role: "user", content, metadata }, environment) : appendMessages(conversation, { role: "user", content, metadata });
|
|
3903
|
+
}
|
|
3904
|
+
function appendAssistantMessage(conversation, content, metadata, environment) {
|
|
3905
|
+
return environment ? appendMessages(conversation, { role: "assistant", content, metadata }, environment) : appendMessages(conversation, { role: "assistant", content, metadata });
|
|
3906
|
+
}
|
|
3907
|
+
function appendSystemMessage(conversation, content, metadata, environment) {
|
|
3908
|
+
return environment ? appendMessages(conversation, { role: "system", content, metadata }, environment) : appendMessages(conversation, { role: "system", content, metadata });
|
|
3909
|
+
}
|
|
3910
|
+
function getMessages(conversation, options2) {
|
|
3911
|
+
const includeHidden = options2?.includeHidden ?? false;
|
|
3912
|
+
const ordered = getOrderedMessages(conversation);
|
|
3913
|
+
return includeHidden ? ordered : ordered.filter((m) => !m.hidden);
|
|
3914
|
+
}
|
|
3915
|
+
function getMessageAtPosition(conversation, position) {
|
|
3916
|
+
const id = conversation.ids[position];
|
|
3917
|
+
return id ? conversation.messages[id] : undefined;
|
|
3918
|
+
}
|
|
3919
|
+
function getMessageIds(conversation) {
|
|
3920
|
+
return [...conversation.ids];
|
|
3921
|
+
}
|
|
3922
|
+
function getMessageById(conversation, id) {
|
|
3923
|
+
return conversation.messages[id];
|
|
3924
|
+
}
|
|
3925
|
+
function searchConversationMessages(conversation, predicate) {
|
|
3926
|
+
return getOrderedMessages(conversation).filter(predicate);
|
|
3927
|
+
}
|
|
3928
|
+
function getStatistics(conversation) {
|
|
3929
|
+
const ordered = getOrderedMessages(conversation);
|
|
3930
|
+
const stats = ordered.reduce((acc, message) => {
|
|
3931
|
+
const byRole = {
|
|
3932
|
+
...acc.byRole,
|
|
3933
|
+
[message.role]: (acc.byRole[message.role] ?? 0) + 1
|
|
3934
|
+
};
|
|
3935
|
+
return {
|
|
3936
|
+
byRole,
|
|
3937
|
+
hidden: acc.hidden + (message.hidden ? 1 : 0),
|
|
3938
|
+
withImages: acc.withImages + (messageHasImages(message) ? 1 : 0)
|
|
3939
|
+
};
|
|
3940
|
+
}, { byRole: {}, hidden: 0, withImages: 0 });
|
|
3941
|
+
return { total: ordered.length, ...stats };
|
|
3942
|
+
}
|
|
3943
|
+
function hasSystemMessage(conversation) {
|
|
3944
|
+
return getOrderedMessages(conversation).some((m) => m.role === "system");
|
|
3945
|
+
}
|
|
3946
|
+
function getFirstSystemMessage(conversation) {
|
|
3947
|
+
return getOrderedMessages(conversation).find((m) => m.role === "system");
|
|
3948
|
+
}
|
|
3949
|
+
function getSystemMessages(conversation) {
|
|
3950
|
+
return getOrderedMessages(conversation).filter((m) => m.role === "system");
|
|
3951
|
+
}
|
|
3952
|
+
function prependSystemMessage(conversation, content, metadata, environment) {
|
|
3953
|
+
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
3954
|
+
const now = resolvedEnvironment.now();
|
|
3955
|
+
const newMessage = createMessage({
|
|
3956
|
+
id: resolvedEnvironment.randomId(),
|
|
3957
|
+
role: "system",
|
|
3958
|
+
content,
|
|
3959
|
+
position: 0,
|
|
3960
|
+
createdAt: now,
|
|
3961
|
+
metadata: { ...metadata ?? {} },
|
|
3962
|
+
hidden: false,
|
|
3963
|
+
toolCall: undefined,
|
|
3964
|
+
toolResult: undefined,
|
|
3965
|
+
tokenUsage: undefined
|
|
3966
|
+
});
|
|
3967
|
+
const ordered = getOrderedMessages(conversation);
|
|
3968
|
+
const renumberedMessages = ordered.map((message) => createMessage({
|
|
3969
|
+
id: message.id,
|
|
3970
|
+
role: message.role,
|
|
3971
|
+
content: copyContent(message.content),
|
|
3972
|
+
position: message.position + 1,
|
|
3973
|
+
createdAt: message.createdAt,
|
|
3974
|
+
metadata: { ...message.metadata },
|
|
3975
|
+
hidden: message.hidden,
|
|
3976
|
+
toolCall: message.toolCall,
|
|
3977
|
+
toolResult: message.toolResult,
|
|
3978
|
+
tokenUsage: message.tokenUsage
|
|
3979
|
+
}));
|
|
3980
|
+
return toReadonly({
|
|
3981
|
+
...conversation,
|
|
3982
|
+
ids: [newMessage.id, ...ordered.map((message) => message.id)],
|
|
3983
|
+
messages: toIdRecord([newMessage, ...renumberedMessages]),
|
|
3984
|
+
updatedAt: now
|
|
3985
|
+
});
|
|
3986
|
+
}
|
|
3987
|
+
function replaceSystemMessage(conversation, content, metadata, environment) {
|
|
3988
|
+
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
3989
|
+
const now = resolvedEnvironment.now();
|
|
3990
|
+
const ordered = getOrderedMessages(conversation);
|
|
3991
|
+
const firstSystemIndex = ordered.findIndex((m) => m.role === "system");
|
|
3992
|
+
if (firstSystemIndex === -1) {
|
|
3993
|
+
return prependSystemMessage(conversation, content, metadata, resolvedEnvironment);
|
|
3994
|
+
}
|
|
3995
|
+
const original = ordered[firstSystemIndex];
|
|
3996
|
+
const replaced = createMessage({
|
|
3997
|
+
id: original.id,
|
|
3998
|
+
role: "system",
|
|
3999
|
+
content,
|
|
4000
|
+
position: original.position,
|
|
4001
|
+
createdAt: original.createdAt,
|
|
4002
|
+
metadata: { ...metadata ?? original.metadata },
|
|
4003
|
+
hidden: original.hidden,
|
|
4004
|
+
toolCall: undefined,
|
|
4005
|
+
toolResult: undefined,
|
|
4006
|
+
tokenUsage: undefined
|
|
4007
|
+
});
|
|
4008
|
+
const next = {
|
|
4009
|
+
...conversation,
|
|
4010
|
+
ids: [...conversation.ids],
|
|
4011
|
+
messages: { ...conversation.messages, [replaced.id]: replaced },
|
|
4012
|
+
updatedAt: now
|
|
4013
|
+
};
|
|
4014
|
+
return toReadonly(next);
|
|
4015
|
+
}
|
|
4016
|
+
function collapseSystemMessages(conversation, environment) {
|
|
4017
|
+
const ordered = getOrderedMessages(conversation);
|
|
4018
|
+
const systemMessages = ordered.filter((m) => m.role === "system");
|
|
4019
|
+
if (systemMessages.length <= 1) {
|
|
4020
|
+
return conversation;
|
|
4021
|
+
}
|
|
4022
|
+
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
4023
|
+
const now = resolvedEnvironment.now();
|
|
4024
|
+
const { parts } = systemMessages.reduce((state, message) => {
|
|
4025
|
+
const contentStr = typeof message.content === "string" ? message.content : message.content.map((part) => part.type === "text" ? part.text : "").join("");
|
|
4026
|
+
if (!contentStr || state.seen.has(contentStr)) {
|
|
4027
|
+
return state;
|
|
4028
|
+
}
|
|
4029
|
+
const seen = new Set(state.seen);
|
|
4030
|
+
seen.add(contentStr);
|
|
4031
|
+
return { seen, parts: [...state.parts, contentStr] };
|
|
4032
|
+
}, { seen: new Set, parts: [] });
|
|
4033
|
+
const collapsedContent = parts.join(`
|
|
4034
|
+
`);
|
|
4035
|
+
const firstSystemMsg = systemMessages[0];
|
|
4036
|
+
const collapsed = createMessage({
|
|
4037
|
+
id: firstSystemMsg.id,
|
|
4038
|
+
role: "system",
|
|
4039
|
+
content: collapsedContent,
|
|
4040
|
+
position: firstSystemMsg.position,
|
|
4041
|
+
createdAt: firstSystemMsg.createdAt,
|
|
4042
|
+
metadata: { ...firstSystemMsg.metadata },
|
|
4043
|
+
hidden: firstSystemMsg.hidden,
|
|
4044
|
+
toolCall: undefined,
|
|
4045
|
+
toolResult: undefined,
|
|
4046
|
+
tokenUsage: undefined
|
|
4047
|
+
});
|
|
4048
|
+
const systemIdsToRemove = systemMessages.slice(1).reduce((ids, message) => {
|
|
4049
|
+
const nextIds = new Set(ids);
|
|
4050
|
+
nextIds.add(message.id);
|
|
4051
|
+
return nextIds;
|
|
4052
|
+
}, new Set);
|
|
4053
|
+
const messages = ordered.filter((m) => !systemIdsToRemove.has(m.id)).map((m) => m.id === firstSystemMsg.id ? collapsed : m);
|
|
4054
|
+
const renumbered = messages.map((message, index) => {
|
|
4055
|
+
if (message.position === index)
|
|
4056
|
+
return message;
|
|
4057
|
+
return createMessage({
|
|
4058
|
+
id: message.id,
|
|
4059
|
+
role: message.role,
|
|
4060
|
+
content: copyContent(message.content),
|
|
4061
|
+
position: index,
|
|
4062
|
+
createdAt: message.createdAt,
|
|
4063
|
+
metadata: { ...message.metadata },
|
|
4064
|
+
hidden: message.hidden,
|
|
4065
|
+
toolCall: message.toolCall,
|
|
4066
|
+
toolResult: message.toolResult,
|
|
4067
|
+
tokenUsage: message.tokenUsage
|
|
4068
|
+
});
|
|
4069
|
+
});
|
|
4070
|
+
const next = {
|
|
4071
|
+
...conversation,
|
|
4072
|
+
ids: renumbered.map((message) => message.id),
|
|
4073
|
+
messages: toIdRecord(renumbered),
|
|
4074
|
+
updatedAt: now
|
|
4075
|
+
};
|
|
4076
|
+
return toReadonly(next);
|
|
4077
|
+
}
|
|
4078
|
+
function redactMessageAtPosition(conversation, position, placeholder = "[REDACTED]", environment) {
|
|
4079
|
+
if (position < 0 || position >= conversation.ids.length) {
|
|
4080
|
+
throw createInvalidPositionError(conversation.ids.length - 1, position);
|
|
4081
|
+
}
|
|
4082
|
+
const id = conversation.ids[position];
|
|
4083
|
+
const original = id ? conversation.messages[id] : undefined;
|
|
4084
|
+
if (!original) {
|
|
4085
|
+
throw createInvalidPositionError(conversation.ids.length - 1, position);
|
|
4086
|
+
}
|
|
4087
|
+
const redacted = createMessage({
|
|
4088
|
+
id: original.id,
|
|
4089
|
+
role: original.role,
|
|
4090
|
+
content: placeholder,
|
|
4091
|
+
position: original.position,
|
|
4092
|
+
createdAt: original.createdAt,
|
|
4093
|
+
metadata: { ...original.metadata },
|
|
4094
|
+
hidden: original.hidden,
|
|
4095
|
+
toolCall: undefined,
|
|
4096
|
+
toolResult: undefined,
|
|
4097
|
+
tokenUsage: undefined
|
|
4098
|
+
});
|
|
4099
|
+
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
4100
|
+
const now = resolvedEnvironment.now();
|
|
4101
|
+
const next = {
|
|
4102
|
+
...conversation,
|
|
4103
|
+
ids: [...conversation.ids],
|
|
4104
|
+
messages: { ...conversation.messages, [redacted.id]: redacted },
|
|
4105
|
+
updatedAt: now
|
|
4106
|
+
};
|
|
4107
|
+
return toReadonly(next);
|
|
4108
|
+
}
|
|
4109
|
+
function migrateConversation(json) {
|
|
4110
|
+
if (typeof json !== "object" || json === null || Array.isArray(json)) {
|
|
4111
|
+
return {
|
|
4112
|
+
schemaVersion: CURRENT_SCHEMA_VERSION,
|
|
4113
|
+
id: "",
|
|
4114
|
+
status: "active",
|
|
4115
|
+
metadata: {},
|
|
4116
|
+
ids: [],
|
|
4117
|
+
messages: {},
|
|
4118
|
+
createdAt: new Date().toISOString(),
|
|
4119
|
+
updatedAt: new Date().toISOString()
|
|
4120
|
+
};
|
|
4121
|
+
}
|
|
4122
|
+
const data = json;
|
|
4123
|
+
const rawMessages = data.messages;
|
|
4124
|
+
let messages = {};
|
|
4125
|
+
let ids = [];
|
|
4126
|
+
const rawIds = data.ids;
|
|
4127
|
+
const isStringArray = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
4128
|
+
if (Array.isArray(rawMessages)) {
|
|
4129
|
+
const rawMessageArray = rawMessages;
|
|
4130
|
+
ids = rawMessageArray.map((message) => message.id);
|
|
4131
|
+
messages = Object.fromEntries(rawMessageArray.map((message) => [message.id, message]));
|
|
4132
|
+
} else if (rawMessages && typeof rawMessages === "object") {
|
|
4133
|
+
messages = { ...rawMessages };
|
|
4134
|
+
if (isStringArray(rawIds) && rawIds.length > 0) {
|
|
4135
|
+
ids = [...rawIds];
|
|
4136
|
+
} else {
|
|
4137
|
+
ids = Object.values(messages).sort((a, b) => a.position - b.position).map((message) => message.id);
|
|
4138
|
+
}
|
|
4139
|
+
}
|
|
4140
|
+
if (ids.length > 0) {
|
|
4141
|
+
ids = ids.filter((id) => (id in messages));
|
|
4142
|
+
const missing = Object.keys(messages).filter((id) => !ids.includes(id));
|
|
4143
|
+
if (missing.length > 0) {
|
|
4144
|
+
const sortedMissing = missing.sort((a, b) => (messages[a]?.position ?? 0) - (messages[b]?.position ?? 0));
|
|
4145
|
+
ids = [...ids, ...sortedMissing];
|
|
4146
|
+
}
|
|
4147
|
+
}
|
|
4148
|
+
if (!("schemaVersion" in json)) {
|
|
4149
|
+
return {
|
|
4150
|
+
...data,
|
|
4151
|
+
schemaVersion: CURRENT_SCHEMA_VERSION,
|
|
4152
|
+
ids,
|
|
4153
|
+
messages
|
|
4154
|
+
};
|
|
4155
|
+
}
|
|
4156
|
+
return { ...data, ids, messages };
|
|
4157
|
+
}
|
|
4158
|
+
function deserializeConversation(json) {
|
|
4159
|
+
const migrated = migrateConversation(json);
|
|
4160
|
+
try {
|
|
4161
|
+
const orderedMessages = migrated.ids.map((id, index) => {
|
|
4162
|
+
const message = migrated.messages[id];
|
|
4163
|
+
if (!message) {
|
|
4164
|
+
throw createSerializationError(`missing message for id ${id}`);
|
|
4165
|
+
}
|
|
4166
|
+
if (message.position !== index) {
|
|
4167
|
+
throw createInvalidPositionError(index, message.position);
|
|
4168
|
+
}
|
|
4169
|
+
return message;
|
|
4170
|
+
});
|
|
4171
|
+
orderedMessages.reduce((state, message) => {
|
|
4172
|
+
if (message.role === "tool-use" && message.toolCall) {
|
|
4173
|
+
return {
|
|
4174
|
+
toolUses: registerToolUse(state.toolUses, message.toolCall)
|
|
4175
|
+
};
|
|
4176
|
+
}
|
|
4177
|
+
if (message.role === "tool-result" && message.toolResult) {
|
|
4178
|
+
assertToolReference(state.toolUses, message.toolResult.callId);
|
|
4179
|
+
}
|
|
4180
|
+
return state;
|
|
4181
|
+
}, { toolUses: new Map });
|
|
4182
|
+
const messageInstances = orderedMessages.map((m) => createMessage(m));
|
|
4183
|
+
const conv = {
|
|
4184
|
+
schemaVersion: migrated.schemaVersion,
|
|
4185
|
+
id: migrated.id,
|
|
4186
|
+
title: migrated.title,
|
|
4187
|
+
status: migrated.status,
|
|
4188
|
+
metadata: { ...migrated.metadata },
|
|
4189
|
+
ids: orderedMessages.map((message) => message.id),
|
|
4190
|
+
messages: toIdRecord(messageInstances),
|
|
4191
|
+
createdAt: migrated.createdAt,
|
|
4192
|
+
updatedAt: migrated.updatedAt
|
|
4193
|
+
};
|
|
4194
|
+
return toReadonly(conv);
|
|
4195
|
+
} catch (error) {
|
|
4196
|
+
throw createSerializationError(`failed to deserialize conversation: ${error instanceof Error ? error.message : String(error)}`, error);
|
|
4197
|
+
}
|
|
4198
|
+
}
|
|
4199
|
+
function toChatMessages(conversation) {
|
|
4200
|
+
const roleMap = {
|
|
4201
|
+
user: "user",
|
|
4202
|
+
assistant: "assistant",
|
|
4203
|
+
system: "system",
|
|
4204
|
+
developer: "system",
|
|
4205
|
+
"tool-use": "assistant",
|
|
4206
|
+
"tool-result": "user",
|
|
4207
|
+
snapshot: "system"
|
|
4208
|
+
};
|
|
4209
|
+
const result = [];
|
|
4210
|
+
for (const message of getOrderedMessages(conversation)) {
|
|
4211
|
+
if (message.hidden)
|
|
4212
|
+
continue;
|
|
4213
|
+
const externalRole = roleMap[message.role];
|
|
4214
|
+
result.push({
|
|
4215
|
+
role: externalRole,
|
|
4216
|
+
content: message.content
|
|
4217
|
+
});
|
|
4218
|
+
}
|
|
4219
|
+
return result;
|
|
4220
|
+
}
|
|
4221
|
+
|
|
4222
|
+
// src/streaming.ts
|
|
4223
|
+
var STREAMING_KEY = "__streaming";
|
|
4224
|
+
var cloneMessage = (original, overrides = {}) => {
|
|
4225
|
+
const baseMessage = {
|
|
4226
|
+
id: original.id,
|
|
4227
|
+
role: original.role,
|
|
4228
|
+
content: overrides.content ?? (typeof original.content === "string" ? original.content : [...original.content]),
|
|
4229
|
+
position: overrides.position ?? original.position,
|
|
4230
|
+
createdAt: original.createdAt,
|
|
4231
|
+
metadata: overrides.metadata ?? { ...original.metadata },
|
|
4232
|
+
hidden: original.hidden,
|
|
4233
|
+
toolCall: original.toolCall ? { ...original.toolCall } : undefined,
|
|
4234
|
+
toolResult: original.toolResult ? { ...original.toolResult } : undefined,
|
|
4235
|
+
tokenUsage: overrides.tokenUsage
|
|
4236
|
+
};
|
|
4237
|
+
if (isAssistantMessage(original)) {
|
|
4238
|
+
const assistantMessage = {
|
|
4239
|
+
...baseMessage,
|
|
4240
|
+
role: "assistant",
|
|
4241
|
+
goalCompleted: original.goalCompleted
|
|
4242
|
+
};
|
|
4243
|
+
return createMessage(assistantMessage);
|
|
4244
|
+
}
|
|
4245
|
+
return createMessage(baseMessage);
|
|
4246
|
+
};
|
|
4247
|
+
function isStreamingMessage(message) {
|
|
4248
|
+
return message.metadata[STREAMING_KEY] === true;
|
|
4249
|
+
}
|
|
4250
|
+
function getStreamingMessage(conversation) {
|
|
4251
|
+
return getOrderedMessages(conversation).find(isStreamingMessage);
|
|
4252
|
+
}
|
|
4253
|
+
function appendStreamingMessage(conversation, role, metadata, environment) {
|
|
4254
|
+
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
4255
|
+
const now = resolvedEnvironment.now();
|
|
4256
|
+
const messageId = resolvedEnvironment.randomId();
|
|
4257
|
+
const newMessage = createMessage({
|
|
4258
|
+
id: messageId,
|
|
4259
|
+
role,
|
|
4260
|
+
content: "",
|
|
4261
|
+
position: conversation.ids.length,
|
|
4262
|
+
createdAt: now,
|
|
4263
|
+
metadata: { ...metadata ?? {}, [STREAMING_KEY]: true },
|
|
4264
|
+
hidden: false,
|
|
4265
|
+
toolCall: undefined,
|
|
4266
|
+
toolResult: undefined,
|
|
4267
|
+
tokenUsage: undefined
|
|
4268
|
+
});
|
|
4269
|
+
const updatedConversation = toReadonly({
|
|
4270
|
+
...conversation,
|
|
4271
|
+
ids: [...conversation.ids, messageId],
|
|
4272
|
+
messages: { ...conversation.messages, [messageId]: newMessage },
|
|
4273
|
+
updatedAt: now
|
|
4274
|
+
});
|
|
4275
|
+
return { conversation: updatedConversation, messageId };
|
|
4276
|
+
}
|
|
4277
|
+
function updateStreamingMessage(conversation, messageId, content, environment) {
|
|
4278
|
+
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
4279
|
+
const now = resolvedEnvironment.now();
|
|
4280
|
+
const original = conversation.messages[messageId];
|
|
4281
|
+
if (!original) {
|
|
4282
|
+
return conversation;
|
|
4283
|
+
}
|
|
4284
|
+
const overrides = {
|
|
4285
|
+
content: typeof content === "string" ? content : [...content]
|
|
4286
|
+
};
|
|
4287
|
+
if (original.tokenUsage) {
|
|
4288
|
+
overrides.tokenUsage = { ...original.tokenUsage };
|
|
4289
|
+
}
|
|
4290
|
+
const updated = cloneMessage(original, overrides);
|
|
4291
|
+
return toReadonly({
|
|
4292
|
+
...conversation,
|
|
4293
|
+
ids: [...conversation.ids],
|
|
4294
|
+
messages: { ...conversation.messages, [updated.id]: updated },
|
|
4295
|
+
updatedAt: now
|
|
4296
|
+
});
|
|
4297
|
+
}
|
|
4298
|
+
function finalizeStreamingMessage(conversation, messageId, options2, environment) {
|
|
4299
|
+
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
4300
|
+
const now = resolvedEnvironment.now();
|
|
4301
|
+
const original = conversation.messages[messageId];
|
|
4302
|
+
if (!original) {
|
|
4303
|
+
return conversation;
|
|
4304
|
+
}
|
|
4305
|
+
const { [STREAMING_KEY]: _, ...restMetadata } = original.metadata;
|
|
4306
|
+
const finalMetadata = {
|
|
4307
|
+
...restMetadata,
|
|
4308
|
+
...options2?.metadata ?? {}
|
|
4309
|
+
};
|
|
4310
|
+
const finalizeOverrides = {
|
|
4311
|
+
metadata: finalMetadata
|
|
4312
|
+
};
|
|
4313
|
+
if (options2?.tokenUsage) {
|
|
4314
|
+
finalizeOverrides.tokenUsage = { ...options2.tokenUsage };
|
|
4315
|
+
}
|
|
4316
|
+
const updated = cloneMessage(original, finalizeOverrides);
|
|
4317
|
+
return toReadonly({
|
|
4318
|
+
...conversation,
|
|
4319
|
+
ids: [...conversation.ids],
|
|
4320
|
+
messages: { ...conversation.messages, [updated.id]: updated },
|
|
4321
|
+
updatedAt: now
|
|
4322
|
+
});
|
|
4323
|
+
}
|
|
4324
|
+
function cancelStreamingMessage(conversation, messageId, environment) {
|
|
4325
|
+
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
4326
|
+
const now = resolvedEnvironment.now();
|
|
4327
|
+
if (!conversation.messages[messageId]) {
|
|
4328
|
+
return conversation;
|
|
4329
|
+
}
|
|
4330
|
+
const messages = getOrderedMessages(conversation).filter((m) => m.id !== messageId).map((message, index) => message.position === index ? message : (() => {
|
|
4331
|
+
const overrides = {
|
|
4332
|
+
position: index
|
|
4333
|
+
};
|
|
4334
|
+
if (message.tokenUsage) {
|
|
4335
|
+
overrides.tokenUsage = { ...message.tokenUsage };
|
|
4336
|
+
}
|
|
4337
|
+
return cloneMessage(message, overrides);
|
|
4338
|
+
})());
|
|
4339
|
+
return toReadonly({
|
|
4340
|
+
...conversation,
|
|
4341
|
+
ids: messages.map((message) => message.id),
|
|
4342
|
+
messages: toIdRecord(messages),
|
|
4343
|
+
updatedAt: now
|
|
4344
|
+
});
|
|
4345
|
+
}
|
|
4346
|
+
|
|
4347
|
+
// src/history.ts
|
|
4348
|
+
class ConversationHistoryEvent extends CustomEvent {
|
|
4349
|
+
constructor(type, detail) {
|
|
4350
|
+
super(type, { detail });
|
|
4351
|
+
}
|
|
4352
|
+
}
|
|
4353
|
+
|
|
4354
|
+
class ConversationHistory extends EventTarget {
|
|
4355
|
+
currentNode;
|
|
4356
|
+
environment;
|
|
4357
|
+
constructor(initial = createConversation(), environment) {
|
|
4358
|
+
super();
|
|
4359
|
+
this.environment = resolveConversationEnvironment(environment);
|
|
4360
|
+
this.currentNode = {
|
|
4361
|
+
conversation: initial,
|
|
4362
|
+
parent: null,
|
|
4363
|
+
children: []
|
|
4364
|
+
};
|
|
4365
|
+
}
|
|
4366
|
+
notifyChange(type) {
|
|
4367
|
+
const detail = {
|
|
4368
|
+
type,
|
|
4369
|
+
conversation: this.current
|
|
4370
|
+
};
|
|
4371
|
+
this.dispatchEvent(new ConversationHistoryEvent("change", detail));
|
|
4372
|
+
this.dispatchEvent(new ConversationHistoryEvent(type, detail));
|
|
4373
|
+
}
|
|
4374
|
+
addEventListener(type, callback, options2) {
|
|
4375
|
+
if (!callback)
|
|
4376
|
+
return;
|
|
4377
|
+
super.addEventListener(type, callback, options2);
|
|
4378
|
+
const unsubscribe = () => this.removeEventListener(type, callback, options2);
|
|
4379
|
+
return unsubscribe;
|
|
4380
|
+
}
|
|
4381
|
+
subscribe(run) {
|
|
4382
|
+
run(this.current);
|
|
4383
|
+
const handler = (event) => {
|
|
4384
|
+
if (event instanceof ConversationHistoryEvent) {
|
|
4385
|
+
run(event.detail.conversation);
|
|
4386
|
+
}
|
|
4387
|
+
};
|
|
4388
|
+
const unsubscribe = this.addEventListener("change", handler);
|
|
4389
|
+
return unsubscribe || (() => {});
|
|
4390
|
+
}
|
|
4391
|
+
getSnapshot() {
|
|
4392
|
+
return this.current;
|
|
4393
|
+
}
|
|
4394
|
+
get current() {
|
|
4395
|
+
return this.currentNode.conversation;
|
|
4396
|
+
}
|
|
4397
|
+
get ids() {
|
|
4398
|
+
return getMessageIds(this.current);
|
|
4399
|
+
}
|
|
4400
|
+
get canUndo() {
|
|
4401
|
+
return this.currentNode.parent !== null;
|
|
4402
|
+
}
|
|
4403
|
+
get canRedo() {
|
|
4404
|
+
return this.currentNode.children.length > 0;
|
|
4405
|
+
}
|
|
4406
|
+
get env() {
|
|
4407
|
+
return this.environment;
|
|
4408
|
+
}
|
|
4409
|
+
get branchCount() {
|
|
4410
|
+
return this.currentNode.parent ? this.currentNode.parent.children.length : 1;
|
|
4411
|
+
}
|
|
4412
|
+
get branchIndex() {
|
|
4413
|
+
if (!this.currentNode.parent)
|
|
4414
|
+
return 0;
|
|
4415
|
+
return this.currentNode.parent.children.indexOf(this.currentNode);
|
|
4416
|
+
}
|
|
4417
|
+
get redoCount() {
|
|
4418
|
+
return this.currentNode.children.length;
|
|
4419
|
+
}
|
|
4420
|
+
push(next) {
|
|
4421
|
+
const newNode = {
|
|
4422
|
+
conversation: next,
|
|
4423
|
+
parent: this.currentNode,
|
|
4424
|
+
children: []
|
|
4425
|
+
};
|
|
4426
|
+
this.currentNode.children.push(newNode);
|
|
4427
|
+
this.currentNode = newNode;
|
|
4428
|
+
this.notifyChange("push");
|
|
4429
|
+
}
|
|
4430
|
+
undo() {
|
|
4431
|
+
if (this.currentNode.parent) {
|
|
4432
|
+
this.currentNode = this.currentNode.parent;
|
|
4433
|
+
this.notifyChange("undo");
|
|
4434
|
+
return this.current;
|
|
4435
|
+
}
|
|
4436
|
+
return;
|
|
4437
|
+
}
|
|
4438
|
+
redo(childIndex = 0) {
|
|
4439
|
+
const next = this.currentNode.children[childIndex];
|
|
4440
|
+
if (next) {
|
|
4441
|
+
this.currentNode = next;
|
|
4442
|
+
this.notifyChange("redo");
|
|
4443
|
+
return this.current;
|
|
4444
|
+
}
|
|
4445
|
+
return;
|
|
4446
|
+
}
|
|
4447
|
+
switchToBranch(index) {
|
|
4448
|
+
if (this.currentNode.parent) {
|
|
4449
|
+
const target = this.currentNode.parent.children[index];
|
|
4450
|
+
if (target) {
|
|
4451
|
+
this.currentNode = target;
|
|
4452
|
+
this.notifyChange("switch");
|
|
4453
|
+
return this.current;
|
|
4454
|
+
}
|
|
4455
|
+
}
|
|
4456
|
+
return;
|
|
4457
|
+
}
|
|
4458
|
+
getPath() {
|
|
4459
|
+
const path = [];
|
|
4460
|
+
let curr = this.currentNode;
|
|
4461
|
+
while (curr) {
|
|
4462
|
+
path.unshift(curr.conversation);
|
|
4463
|
+
curr = curr.parent;
|
|
4464
|
+
}
|
|
4465
|
+
return path;
|
|
4466
|
+
}
|
|
4467
|
+
getMessages(options2) {
|
|
4468
|
+
return getMessages(this.current, options2);
|
|
4469
|
+
}
|
|
4470
|
+
getMessageAtPosition(position) {
|
|
4471
|
+
return getMessageAtPosition(this.current, position);
|
|
4472
|
+
}
|
|
4473
|
+
getMessageIds() {
|
|
4474
|
+
return getMessageIds(this.current);
|
|
4475
|
+
}
|
|
4476
|
+
getMessageById(id) {
|
|
4477
|
+
return getMessageById(this.current, id);
|
|
4478
|
+
}
|
|
4479
|
+
get(id) {
|
|
4480
|
+
return getMessageById(this.current, id);
|
|
4481
|
+
}
|
|
4482
|
+
searchMessages(predicate) {
|
|
4483
|
+
return searchConversationMessages(this.current, predicate);
|
|
4484
|
+
}
|
|
4485
|
+
getStatistics() {
|
|
4486
|
+
return getStatistics(this.current);
|
|
4487
|
+
}
|
|
4488
|
+
hasSystemMessage() {
|
|
4489
|
+
return hasSystemMessage(this.current);
|
|
4490
|
+
}
|
|
4491
|
+
getFirstSystemMessage() {
|
|
4492
|
+
return getFirstSystemMessage(this.current);
|
|
4493
|
+
}
|
|
4494
|
+
getSystemMessages() {
|
|
4495
|
+
return getSystemMessages(this.current);
|
|
4496
|
+
}
|
|
4497
|
+
toChatMessages() {
|
|
4498
|
+
return toChatMessages(this.current);
|
|
4499
|
+
}
|
|
4500
|
+
estimateTokens(estimator) {
|
|
4501
|
+
return estimateConversationTokens(this.current, estimator, this.env);
|
|
4502
|
+
}
|
|
4503
|
+
getRecentMessages(count, options2) {
|
|
4504
|
+
return getRecentMessages(this.current, count, options2);
|
|
4505
|
+
}
|
|
4506
|
+
getStreamingMessage() {
|
|
4507
|
+
return getStreamingMessage(this.current);
|
|
4508
|
+
}
|
|
4509
|
+
appendMessages(...inputs) {
|
|
4510
|
+
this.push(appendMessages(this.current, ...inputs, this.env));
|
|
4511
|
+
}
|
|
4512
|
+
appendUserMessage(content, metadata) {
|
|
4513
|
+
this.push(appendUserMessage(this.current, content, metadata, this.env));
|
|
4514
|
+
}
|
|
4515
|
+
appendAssistantMessage(content, metadata) {
|
|
4516
|
+
this.push(appendAssistantMessage(this.current, content, metadata, this.env));
|
|
4517
|
+
}
|
|
4518
|
+
appendSystemMessage(content, metadata) {
|
|
4519
|
+
this.push(appendSystemMessage(this.current, content, metadata, this.env));
|
|
4520
|
+
}
|
|
4521
|
+
prependSystemMessage(content, metadata) {
|
|
4522
|
+
this.push(prependSystemMessage(this.current, content, metadata, this.env));
|
|
4523
|
+
}
|
|
4524
|
+
replaceSystemMessage(content, metadata) {
|
|
4525
|
+
this.push(replaceSystemMessage(this.current, content, metadata, this.env));
|
|
4526
|
+
}
|
|
4527
|
+
collapseSystemMessages() {
|
|
4528
|
+
this.push(collapseSystemMessages(this.current, this.env));
|
|
4529
|
+
}
|
|
4530
|
+
redactMessageAtPosition(position, placeholder) {
|
|
4531
|
+
this.push(redactMessageAtPosition(this.current, position, placeholder, this.env));
|
|
4532
|
+
}
|
|
4533
|
+
truncateFromPosition(position, options2) {
|
|
4534
|
+
this.push(truncateFromPosition(this.current, position, options2, this.env));
|
|
4535
|
+
}
|
|
4536
|
+
truncateToTokenLimit(maxTokens, options2) {
|
|
4537
|
+
this.push(truncateToTokenLimit(this.current, maxTokens, options2, this.env));
|
|
4538
|
+
}
|
|
4539
|
+
appendStreamingMessage(role, metadata) {
|
|
4540
|
+
const { conversation, messageId } = appendStreamingMessage(this.current, role, metadata, this.env);
|
|
4541
|
+
this.push(conversation);
|
|
4542
|
+
return messageId;
|
|
4543
|
+
}
|
|
4544
|
+
updateStreamingMessage(messageId, content) {
|
|
4545
|
+
this.push(updateStreamingMessage(this.current, messageId, content, this.env));
|
|
4546
|
+
}
|
|
4547
|
+
finalizeStreamingMessage(messageId, options2) {
|
|
4548
|
+
this.push(finalizeStreamingMessage(this.current, messageId, options2, this.env));
|
|
4549
|
+
}
|
|
4550
|
+
cancelStreamingMessage(messageId) {
|
|
4551
|
+
this.push(cancelStreamingMessage(this.current, messageId, this.env));
|
|
4552
|
+
}
|
|
4553
|
+
snapshot() {
|
|
4554
|
+
const getPath = (node) => {
|
|
4555
|
+
const path = [];
|
|
4556
|
+
let curr = node;
|
|
4557
|
+
while (curr.parent) {
|
|
4558
|
+
path.unshift(curr.parent.children.indexOf(curr));
|
|
4559
|
+
curr = curr.parent;
|
|
4560
|
+
}
|
|
4561
|
+
return path;
|
|
4562
|
+
};
|
|
4563
|
+
const serializeNode = (node) => ({
|
|
4564
|
+
conversation: node.conversation,
|
|
4565
|
+
children: node.children.map(serializeNode)
|
|
4566
|
+
});
|
|
4567
|
+
let root = this.currentNode;
|
|
4568
|
+
while (root.parent) {
|
|
4569
|
+
root = root.parent;
|
|
4570
|
+
}
|
|
4571
|
+
return {
|
|
4572
|
+
root: serializeNode(root),
|
|
4573
|
+
currentPath: getPath(this.currentNode)
|
|
4574
|
+
};
|
|
4575
|
+
}
|
|
4576
|
+
static from(json, environment) {
|
|
4577
|
+
const rootConv = deserializeConversation(json.root.conversation);
|
|
4578
|
+
const history = new ConversationHistory(rootConv, environment);
|
|
4579
|
+
const buildTree = (nodeJSON, parentNode) => {
|
|
4580
|
+
const nodeConv = deserializeConversation(nodeJSON.conversation);
|
|
4581
|
+
const node = {
|
|
4582
|
+
conversation: nodeConv,
|
|
4583
|
+
parent: parentNode,
|
|
4584
|
+
children: []
|
|
4585
|
+
};
|
|
4586
|
+
node.children = nodeJSON.children.map((child) => buildTree(child, node));
|
|
4587
|
+
return node;
|
|
4588
|
+
};
|
|
4589
|
+
const h = history;
|
|
4590
|
+
const rootNode = h.currentNode;
|
|
4591
|
+
rootNode.children = json.root.children.map((child) => buildTree(child, rootNode));
|
|
4592
|
+
let current = rootNode;
|
|
4593
|
+
for (const index of json.currentPath) {
|
|
4594
|
+
const target = current.children[index];
|
|
4595
|
+
if (target) {
|
|
4596
|
+
current = target;
|
|
4597
|
+
}
|
|
4598
|
+
}
|
|
4599
|
+
h.currentNode = current;
|
|
4600
|
+
return history;
|
|
4601
|
+
}
|
|
4602
|
+
bind(fn) {
|
|
4603
|
+
return (...args) => {
|
|
4604
|
+
const boundFn = fn;
|
|
4605
|
+
const result = boundFn(this.current, ...args, this.env);
|
|
4606
|
+
if (isConversation(result)) {
|
|
4607
|
+
this.push(result);
|
|
4608
|
+
}
|
|
4609
|
+
return result;
|
|
4610
|
+
};
|
|
4611
|
+
}
|
|
4612
|
+
[Symbol.dispose]() {
|
|
4613
|
+
let root = this.currentNode;
|
|
4614
|
+
while (root?.parent) {
|
|
4615
|
+
root = root.parent;
|
|
4616
|
+
}
|
|
4617
|
+
const clearNode = (node) => {
|
|
4618
|
+
for (const child of node.children) {
|
|
4619
|
+
clearNode(child);
|
|
4620
|
+
}
|
|
4621
|
+
node.children = [];
|
|
4622
|
+
const n = node;
|
|
4623
|
+
n.parent = null;
|
|
4624
|
+
n.conversation = null;
|
|
4625
|
+
};
|
|
4626
|
+
if (root)
|
|
4627
|
+
clearNode(root);
|
|
4628
|
+
}
|
|
4629
|
+
}
|
|
4630
|
+
function isConversation(value) {
|
|
4631
|
+
return value !== null && typeof value === "object" && typeof value.schemaVersion === "number" && typeof value.id === "string" && typeof value.status === "string" && value.metadata !== null && typeof value.metadata === "object" && Array.isArray(value.ids) && typeof value.messages === "object" && value.messages !== null && !Array.isArray(value.messages) && typeof value.createdAt === "string" && typeof value.updatedAt === "string";
|
|
4632
|
+
}
|
|
4633
|
+
|
|
4634
|
+
// src/utilities/markdown.ts
|
|
4635
|
+
var import_gray_matter = __toESM(require_gray_matter(), 1);
|
|
4636
|
+
|
|
4637
|
+
// src/utilities/tool-results.ts
|
|
4638
|
+
function copyToolResult(toolResult) {
|
|
4639
|
+
return { ...toolResult };
|
|
4640
|
+
}
|
|
4641
|
+
function redactToolResult(toolResult, placeholder) {
|
|
4642
|
+
const result = { ...toolResult, content: placeholder };
|
|
4643
|
+
if (result.result !== undefined) {
|
|
4644
|
+
result.result = placeholder;
|
|
4645
|
+
}
|
|
4646
|
+
if (result.error !== undefined) {
|
|
4647
|
+
result.error = placeholder;
|
|
4648
|
+
}
|
|
4649
|
+
return result;
|
|
4650
|
+
}
|
|
4651
|
+
|
|
4652
|
+
// src/utilities/markdown.ts
|
|
4653
|
+
var ROLE_LABELS = {
|
|
4654
|
+
user: "User",
|
|
4655
|
+
assistant: "Assistant",
|
|
4656
|
+
system: "System",
|
|
4657
|
+
developer: "Developer",
|
|
4658
|
+
"tool-use": "Tool Use",
|
|
4659
|
+
"tool-result": "Tool Result",
|
|
4660
|
+
snapshot: "Snapshot"
|
|
4661
|
+
};
|
|
4662
|
+
var ROLE_DISPLAY_NAMES = ROLE_LABELS;
|
|
4663
|
+
var LABEL_TO_ROLE = {
|
|
4664
|
+
User: "user",
|
|
4665
|
+
Assistant: "assistant",
|
|
4666
|
+
System: "system",
|
|
4667
|
+
Developer: "developer",
|
|
4668
|
+
"Tool Use": "tool-use",
|
|
4669
|
+
"Tool Result": "tool-result",
|
|
4670
|
+
Snapshot: "snapshot"
|
|
4671
|
+
};
|
|
4672
|
+
var DISPLAY_NAME_TO_ROLE = LABEL_TO_ROLE;
|
|
4673
|
+
function getRoleLabel(role) {
|
|
4674
|
+
return ROLE_LABELS[role];
|
|
4675
|
+
}
|
|
4676
|
+
function getRoleFromLabel(label) {
|
|
4677
|
+
return LABEL_TO_ROLE[label];
|
|
4678
|
+
}
|
|
4679
|
+
var DEFAULT_REDACTED_PLACEHOLDER = "[REDACTED]";
|
|
4680
|
+
function resolveMarkdownOptions(options2 = {}) {
|
|
4681
|
+
return {
|
|
4682
|
+
includeMetadata: options2.includeMetadata ?? false,
|
|
4683
|
+
stripTransient: options2.stripTransient ?? false,
|
|
4684
|
+
includeHidden: options2.includeHidden ?? true,
|
|
4685
|
+
redactHiddenContent: options2.redactHiddenContent ?? false,
|
|
4686
|
+
redactToolArguments: options2.redactToolArguments ?? false,
|
|
4687
|
+
redactToolResults: options2.redactToolResults ?? false,
|
|
4688
|
+
redactedPlaceholder: options2.redactedPlaceholder ?? DEFAULT_REDACTED_PLACEHOLDER
|
|
4689
|
+
};
|
|
4690
|
+
}
|
|
4691
|
+
function sanitizeMessage(message, options2) {
|
|
4692
|
+
const metadata = options2.stripTransient ? stripTransientFromRecord({ ...message.metadata }) : { ...message.metadata };
|
|
4693
|
+
const content = options2.redactHiddenContent && message.hidden ? options2.redactedPlaceholder : copyContent(message.content);
|
|
4694
|
+
const toolCall = message.toolCall ? {
|
|
4695
|
+
...message.toolCall,
|
|
4696
|
+
arguments: options2.redactToolArguments ? options2.redactedPlaceholder : message.toolCall.arguments
|
|
4697
|
+
} : undefined;
|
|
4698
|
+
const toolResult = message.toolResult ? options2.redactToolResults ? redactToolResult(message.toolResult, options2.redactedPlaceholder) : copyToolResult(message.toolResult) : undefined;
|
|
4699
|
+
const baseMessage = {
|
|
4700
|
+
id: message.id,
|
|
4701
|
+
role: message.role,
|
|
4702
|
+
content,
|
|
4703
|
+
position: message.position,
|
|
4704
|
+
createdAt: message.createdAt,
|
|
4705
|
+
metadata: toReadonly(metadata),
|
|
4706
|
+
hidden: message.hidden,
|
|
4707
|
+
toolCall: toolCall ? toReadonly(toolCall) : undefined,
|
|
4708
|
+
toolResult: toolResult ? toReadonly(toolResult) : undefined,
|
|
4709
|
+
tokenUsage: message.tokenUsage ? toReadonly({ ...message.tokenUsage }) : undefined
|
|
4710
|
+
};
|
|
4711
|
+
if (isAssistantMessage(message)) {
|
|
4712
|
+
const assistantMessage = {
|
|
4713
|
+
...baseMessage,
|
|
4714
|
+
role: "assistant",
|
|
4715
|
+
goalCompleted: message.goalCompleted
|
|
4716
|
+
};
|
|
4717
|
+
return assistantMessage;
|
|
4718
|
+
}
|
|
4719
|
+
return baseMessage;
|
|
4720
|
+
}
|
|
4721
|
+
function prepareConversationForMarkdown(conversation, options2) {
|
|
4722
|
+
const metadata = options2.stripTransient ? stripTransientFromRecord({ ...conversation.metadata }) : { ...conversation.metadata };
|
|
4723
|
+
const messages = getOrderedMessages(conversation).filter((message) => options2.includeHidden || !message.hidden).map((message) => sanitizeMessage(message, options2));
|
|
4724
|
+
return {
|
|
4725
|
+
schemaVersion: conversation.schemaVersion,
|
|
4726
|
+
id: conversation.id,
|
|
4727
|
+
title: conversation.title,
|
|
4728
|
+
status: conversation.status,
|
|
4729
|
+
metadata: toReadonly(metadata),
|
|
4730
|
+
ids: toReadonly(messages.map((message) => message.id)),
|
|
4731
|
+
messages: toReadonly(toIdRecord(messages)),
|
|
4732
|
+
createdAt: conversation.createdAt,
|
|
4733
|
+
updatedAt: conversation.updatedAt
|
|
4734
|
+
};
|
|
4735
|
+
}
|
|
4736
|
+
function formatMessageContent(message) {
|
|
4737
|
+
if (typeof message.content === "string")
|
|
4738
|
+
return message.content;
|
|
4739
|
+
const parts = messageParts(message);
|
|
4740
|
+
const lines = [];
|
|
4741
|
+
for (const part of parts) {
|
|
4742
|
+
if (part.type === "text" && part.text) {
|
|
4743
|
+
lines.push(part.text);
|
|
4744
|
+
} else if (part.type === "image") {
|
|
4745
|
+
const imageUrl = part.url;
|
|
4746
|
+
const altText = part.text ?? "image";
|
|
4747
|
+
lines.push(``);
|
|
4748
|
+
}
|
|
4749
|
+
}
|
|
4750
|
+
return lines.join(`
|
|
4751
|
+
|
|
4752
|
+
`);
|
|
4753
|
+
}
|
|
4754
|
+
function toMarkdown(conversation, options2 = {}) {
|
|
4755
|
+
const resolved = resolveMarkdownOptions(options2);
|
|
4756
|
+
const prepared = prepareConversationForMarkdown(conversation, resolved);
|
|
4757
|
+
if (resolved.includeMetadata) {
|
|
4758
|
+
return toMarkdownWithMetadata(prepared, resolved);
|
|
4759
|
+
}
|
|
4760
|
+
return toMarkdownSimple(prepared);
|
|
4761
|
+
}
|
|
4762
|
+
function toMarkdownSimple(conversation) {
|
|
4763
|
+
const sections = [];
|
|
4764
|
+
for (const message of getOrderedMessages(conversation)) {
|
|
4765
|
+
const roleName = ROLE_DISPLAY_NAMES[message.role];
|
|
4766
|
+
const header = `### ${roleName}`;
|
|
4767
|
+
const content = formatMessageContent(message);
|
|
4768
|
+
sections.push(`${header}
|
|
4769
|
+
|
|
4770
|
+
${content}`);
|
|
4771
|
+
}
|
|
4772
|
+
return sections.join(`
|
|
4773
|
+
|
|
4774
|
+
`);
|
|
4775
|
+
}
|
|
4776
|
+
function toMarkdownWithMetadata(conversation, _options) {
|
|
4777
|
+
const messagesMetadata = {};
|
|
4778
|
+
for (const message of getOrderedMessages(conversation)) {
|
|
4779
|
+
const messageMeta = {
|
|
4780
|
+
position: message.position,
|
|
4781
|
+
createdAt: message.createdAt,
|
|
4782
|
+
metadata: { ...message.metadata },
|
|
4783
|
+
hidden: message.hidden
|
|
4784
|
+
};
|
|
4785
|
+
if (Array.isArray(message.content)) {
|
|
4786
|
+
messageMeta.content = copyContent(message.content);
|
|
4787
|
+
}
|
|
4788
|
+
if (message.toolCall) {
|
|
4789
|
+
messageMeta.toolCall = { ...message.toolCall };
|
|
4790
|
+
}
|
|
4791
|
+
if (message.toolResult) {
|
|
4792
|
+
messageMeta.toolResult = { ...message.toolResult };
|
|
4793
|
+
}
|
|
4794
|
+
if (message.tokenUsage) {
|
|
4795
|
+
messageMeta.tokenUsage = { ...message.tokenUsage };
|
|
4796
|
+
}
|
|
4797
|
+
if (isAssistantMessage(message) && message.goalCompleted !== undefined) {
|
|
4798
|
+
messageMeta.goalCompleted = message.goalCompleted;
|
|
4799
|
+
}
|
|
4800
|
+
messagesMetadata[message.id] = messageMeta;
|
|
4801
|
+
}
|
|
4802
|
+
const frontmatterData = {
|
|
4803
|
+
schemaVersion: conversation.schemaVersion,
|
|
4804
|
+
id: conversation.id,
|
|
4805
|
+
status: conversation.status,
|
|
4806
|
+
metadata: { ...conversation.metadata },
|
|
4807
|
+
createdAt: conversation.createdAt,
|
|
4808
|
+
updatedAt: conversation.updatedAt,
|
|
4809
|
+
messages: messagesMetadata
|
|
4810
|
+
};
|
|
4811
|
+
if (conversation.title !== undefined) {
|
|
4812
|
+
frontmatterData.title = conversation.title;
|
|
4813
|
+
}
|
|
4814
|
+
const messageSections = [];
|
|
4815
|
+
for (const message of getOrderedMessages(conversation)) {
|
|
4816
|
+
const roleName = ROLE_DISPLAY_NAMES[message.role];
|
|
4817
|
+
const header = `### ${roleName} (${message.id})`;
|
|
4818
|
+
const content = formatMessageContent(message);
|
|
4819
|
+
messageSections.push(`${header}
|
|
4820
|
+
|
|
4821
|
+
${content}`);
|
|
4822
|
+
}
|
|
4823
|
+
const body = messageSections.join(`
|
|
4824
|
+
|
|
4825
|
+
`);
|
|
4826
|
+
return import_gray_matter.default.stringify(body, frontmatterData);
|
|
4827
|
+
}
|
|
4828
|
+
|
|
4829
|
+
class MarkdownParseError extends Error {
|
|
4830
|
+
constructor(message) {
|
|
4831
|
+
super(message);
|
|
4832
|
+
this.name = "MarkdownParseError";
|
|
4833
|
+
}
|
|
4834
|
+
}
|
|
4835
|
+
function generateId() {
|
|
4836
|
+
return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
4837
|
+
}
|
|
4838
|
+
function fromMarkdown(markdown) {
|
|
4839
|
+
const trimmed = markdown.trim();
|
|
4840
|
+
const hasFrontmatter = trimmed.startsWith("---");
|
|
4841
|
+
if (hasFrontmatter) {
|
|
4842
|
+
return parseMarkdownWithMetadata(trimmed);
|
|
4843
|
+
}
|
|
4844
|
+
return parseMarkdownSimple(trimmed);
|
|
4845
|
+
}
|
|
4846
|
+
function parseMarkdownWithMetadata(trimmed) {
|
|
4847
|
+
let parsed;
|
|
4848
|
+
try {
|
|
4849
|
+
parsed = import_gray_matter.default(trimmed);
|
|
4850
|
+
} catch {
|
|
4851
|
+
throw new MarkdownParseError("Invalid frontmatter: failed to parse YAML");
|
|
4852
|
+
}
|
|
4853
|
+
const frontmatter = parsed.data;
|
|
4854
|
+
const body = parsed.content.trim();
|
|
4855
|
+
if (!frontmatter.id) {
|
|
4856
|
+
throw new MarkdownParseError('Invalid frontmatter: missing required field "id"');
|
|
4857
|
+
}
|
|
4858
|
+
const messages = [];
|
|
4859
|
+
const messagePattern = /^### ([\w\s]+) \(([^)]+)\)\n\n([\s\S]*?)(?=\n\n### |\n*$)/gm;
|
|
4860
|
+
let match;
|
|
4861
|
+
while ((match = messagePattern.exec(body)) !== null) {
|
|
4862
|
+
const [, roleDisplay, messageId, contentBody] = match;
|
|
4863
|
+
const role = DISPLAY_NAME_TO_ROLE[roleDisplay];
|
|
4864
|
+
if (!role) {
|
|
4865
|
+
throw new MarkdownParseError(`Unknown role: ${roleDisplay}`);
|
|
4866
|
+
}
|
|
4867
|
+
const messageMeta = frontmatter.messages?.[messageId];
|
|
4868
|
+
if (!messageMeta) {
|
|
4869
|
+
throw new MarkdownParseError(`Missing metadata for message: ${messageId}`);
|
|
4870
|
+
}
|
|
4871
|
+
let content;
|
|
4872
|
+
if (messageMeta.content) {
|
|
4873
|
+
content = toReadonly([...messageMeta.content]);
|
|
4874
|
+
} else {
|
|
4875
|
+
content = contentBody?.trim() ?? "";
|
|
4876
|
+
}
|
|
4877
|
+
const baseMessage = {
|
|
4878
|
+
id: messageId,
|
|
4879
|
+
role,
|
|
4880
|
+
content,
|
|
4881
|
+
position: messageMeta.position,
|
|
4882
|
+
createdAt: messageMeta.createdAt,
|
|
4883
|
+
metadata: toReadonly({ ...messageMeta.metadata }),
|
|
4884
|
+
hidden: messageMeta.hidden,
|
|
4885
|
+
toolCall: messageMeta.toolCall ? toReadonly({ ...messageMeta.toolCall }) : undefined,
|
|
4886
|
+
toolResult: messageMeta.toolResult ? toReadonly({ ...messageMeta.toolResult }) : undefined,
|
|
4887
|
+
tokenUsage: messageMeta.tokenUsage ? toReadonly({ ...messageMeta.tokenUsage }) : undefined
|
|
4888
|
+
};
|
|
4889
|
+
let message = baseMessage;
|
|
4890
|
+
if (role === "assistant") {
|
|
4891
|
+
message = {
|
|
4892
|
+
...baseMessage,
|
|
4893
|
+
role: "assistant",
|
|
4894
|
+
goalCompleted: messageMeta.goalCompleted
|
|
4895
|
+
};
|
|
4896
|
+
}
|
|
4897
|
+
messages.push(toReadonly(message));
|
|
4898
|
+
}
|
|
4899
|
+
const conversation = {
|
|
4900
|
+
schemaVersion: frontmatter.schemaVersion ?? CURRENT_SCHEMA_VERSION,
|
|
4901
|
+
id: frontmatter.id,
|
|
4902
|
+
title: frontmatter.title,
|
|
4903
|
+
status: frontmatter.status ?? "active",
|
|
4904
|
+
metadata: toReadonly({ ...frontmatter.metadata }),
|
|
4905
|
+
ids: toReadonly(messages.map((message) => message.id)),
|
|
4906
|
+
messages: toReadonly(toIdRecord(messages)),
|
|
4907
|
+
createdAt: frontmatter.createdAt,
|
|
4908
|
+
updatedAt: frontmatter.updatedAt
|
|
4909
|
+
};
|
|
4910
|
+
return toReadonly(conversation);
|
|
4911
|
+
}
|
|
4912
|
+
function parseMarkdownSimple(body) {
|
|
4913
|
+
const now = new Date().toISOString();
|
|
4914
|
+
const messages = [];
|
|
4915
|
+
const messagePattern = /^### ([^\n]+)\n\n([\s\S]*?)(?=\n\n### |\n*$)/gm;
|
|
4916
|
+
let match;
|
|
4917
|
+
let position = 0;
|
|
4918
|
+
while ((match = messagePattern.exec(body)) !== null) {
|
|
4919
|
+
const [, roleDisplay, contentBody] = match;
|
|
4920
|
+
const role = DISPLAY_NAME_TO_ROLE[roleDisplay];
|
|
4921
|
+
if (!role) {
|
|
4922
|
+
throw new MarkdownParseError(`Unknown role: ${roleDisplay}`);
|
|
4923
|
+
}
|
|
4924
|
+
const message = {
|
|
4925
|
+
id: generateId(),
|
|
4926
|
+
role,
|
|
4927
|
+
content: contentBody?.trim() ?? "",
|
|
4928
|
+
position,
|
|
4929
|
+
createdAt: now,
|
|
4930
|
+
metadata: toReadonly({}),
|
|
4931
|
+
hidden: false
|
|
4932
|
+
};
|
|
4933
|
+
messages.push(toReadonly(message));
|
|
4934
|
+
position++;
|
|
4935
|
+
}
|
|
4936
|
+
const conversation = {
|
|
4937
|
+
schemaVersion: CURRENT_SCHEMA_VERSION,
|
|
4938
|
+
id: generateId(),
|
|
4939
|
+
status: "active",
|
|
4940
|
+
metadata: toReadonly({}),
|
|
4941
|
+
ids: toReadonly(messages.map((message) => message.id)),
|
|
4942
|
+
messages: toReadonly(toIdRecord(messages)),
|
|
4943
|
+
createdAt: now,
|
|
4944
|
+
updatedAt: now
|
|
4945
|
+
};
|
|
4946
|
+
return toReadonly(conversation);
|
|
4947
|
+
}
|
|
4948
|
+
|
|
4949
|
+
// src/markdown/index.ts
|
|
4950
|
+
function historyToMarkdown(history, options2) {
|
|
4951
|
+
return toMarkdown(history.current, options2);
|
|
4952
|
+
}
|
|
4953
|
+
function historyFromMarkdown(markdown, environment) {
|
|
4954
|
+
const conversation = fromMarkdown(markdown);
|
|
4955
|
+
return new ConversationHistory(conversation, environment);
|
|
4956
|
+
}
|
|
4957
|
+
export {
|
|
4958
|
+
toMarkdown,
|
|
4959
|
+
historyToMarkdown,
|
|
4960
|
+
historyFromMarkdown,
|
|
4961
|
+
getRoleLabel,
|
|
4962
|
+
getRoleFromLabel,
|
|
4963
|
+
fromMarkdown,
|
|
4964
|
+
ROLE_LABELS,
|
|
4965
|
+
MarkdownParseError,
|
|
4966
|
+
LABEL_TO_ROLE
|
|
4967
|
+
};
|
|
4968
|
+
|
|
4969
|
+
//# debugId=12525694512E3BEC64756E2164756E21
|