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
package/dist/index.js
CHANGED
|
@@ -1,3496 +1,3 @@
|
|
|
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
1
|
// src/multi-modal.ts
|
|
3495
2
|
function copyMultiModalContent(item) {
|
|
3496
3
|
if (item.type === "text") {
|
|
@@ -3514,19 +21,38 @@ function copyContent(content) {
|
|
|
3514
21
|
}
|
|
3515
22
|
return content.map(copyMultiModalContent);
|
|
3516
23
|
}
|
|
3517
|
-
// src/types.ts
|
|
3518
|
-
var CURRENT_SCHEMA_VERSION = 1;
|
|
3519
24
|
// src/schemas.ts
|
|
3520
25
|
import { z } from "zod";
|
|
26
|
+
function toMultiModalContent(value) {
|
|
27
|
+
const result = { type: value.type };
|
|
28
|
+
if (value.text !== undefined)
|
|
29
|
+
result.text = value.text;
|
|
30
|
+
if (value.url !== undefined)
|
|
31
|
+
result.url = value.url;
|
|
32
|
+
if (value.mimeType !== undefined)
|
|
33
|
+
result.mimeType = value.mimeType;
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
var jsonValueSchema = z.lazy(() => z.union([
|
|
37
|
+
z.string(),
|
|
38
|
+
z.number(),
|
|
39
|
+
z.boolean(),
|
|
40
|
+
z.null(),
|
|
41
|
+
z.array(jsonValueSchema),
|
|
42
|
+
z.record(z.string(), jsonValueSchema)
|
|
43
|
+
]));
|
|
3521
44
|
var multiModalContentSchema = z.discriminatedUnion("type", [
|
|
3522
|
-
z.object({
|
|
45
|
+
z.object({
|
|
46
|
+
type: z.literal("text"),
|
|
47
|
+
text: z.string()
|
|
48
|
+
}),
|
|
3523
49
|
z.object({
|
|
3524
50
|
type: z.literal("image"),
|
|
3525
51
|
url: z.string().url(),
|
|
3526
52
|
mimeType: z.string().optional(),
|
|
3527
53
|
text: z.string().optional()
|
|
3528
54
|
})
|
|
3529
|
-
]);
|
|
55
|
+
]).transform(toMultiModalContent);
|
|
3530
56
|
var messageRoleSchema = z.enum([
|
|
3531
57
|
"user",
|
|
3532
58
|
"assistant",
|
|
@@ -3539,12 +65,16 @@ var messageRoleSchema = z.enum([
|
|
|
3539
65
|
var toolCallSchema = z.object({
|
|
3540
66
|
id: z.string(),
|
|
3541
67
|
name: z.string(),
|
|
3542
|
-
arguments:
|
|
68
|
+
arguments: jsonValueSchema
|
|
3543
69
|
});
|
|
3544
70
|
var toolResultSchema = z.object({
|
|
3545
71
|
callId: z.string(),
|
|
3546
72
|
outcome: z.enum(["success", "error"]),
|
|
3547
|
-
content:
|
|
73
|
+
content: jsonValueSchema,
|
|
74
|
+
toolCallId: z.string().optional(),
|
|
75
|
+
toolName: z.string().optional(),
|
|
76
|
+
result: jsonValueSchema.optional(),
|
|
77
|
+
error: z.string().optional()
|
|
3548
78
|
});
|
|
3549
79
|
var tokenUsageSchema = z.object({
|
|
3550
80
|
prompt: z.number().int().min(0),
|
|
@@ -3554,7 +84,7 @@ var tokenUsageSchema = z.object({
|
|
|
3554
84
|
var messageInputSchema = z.object({
|
|
3555
85
|
role: messageRoleSchema,
|
|
3556
86
|
content: z.union([z.string(), z.array(multiModalContentSchema)]),
|
|
3557
|
-
metadata: z.record(z.string(),
|
|
87
|
+
metadata: z.record(z.string(), jsonValueSchema).optional(),
|
|
3558
88
|
hidden: z.boolean().optional(),
|
|
3559
89
|
toolCall: toolCallSchema.optional(),
|
|
3560
90
|
toolResult: toolResultSchema.optional(),
|
|
@@ -3567,13 +97,13 @@ var messageJSONSchema = z.object({
|
|
|
3567
97
|
content: z.union([z.string(), z.array(multiModalContentSchema)]),
|
|
3568
98
|
position: z.number().int().min(0),
|
|
3569
99
|
createdAt: z.string(),
|
|
3570
|
-
metadata: z.record(z.string(),
|
|
100
|
+
metadata: z.record(z.string(), jsonValueSchema),
|
|
3571
101
|
hidden: z.boolean(),
|
|
3572
102
|
toolCall: toolCallSchema.optional(),
|
|
3573
103
|
toolResult: toolResultSchema.optional(),
|
|
3574
104
|
tokenUsage: tokenUsageSchema.optional(),
|
|
3575
105
|
goalCompleted: z.boolean().optional()
|
|
3576
|
-
}).
|
|
106
|
+
}).loose();
|
|
3577
107
|
var conversationStatusSchema = z.enum([
|
|
3578
108
|
"active",
|
|
3579
109
|
"archived",
|
|
@@ -3584,9 +114,9 @@ var conversationShape = {
|
|
|
3584
114
|
id: z.string(),
|
|
3585
115
|
title: z.string().optional(),
|
|
3586
116
|
status: conversationStatusSchema,
|
|
3587
|
-
metadata: z.record(z.string(),
|
|
3588
|
-
|
|
3589
|
-
messages: z.
|
|
117
|
+
metadata: z.record(z.string(), jsonValueSchema),
|
|
118
|
+
ids: z.array(z.string()),
|
|
119
|
+
messages: z.record(z.string(), messageJSONSchema),
|
|
3590
120
|
createdAt: z.string(),
|
|
3591
121
|
updatedAt: z.string()
|
|
3592
122
|
};
|
|
@@ -3604,35 +134,6 @@ function normalizeContent(content) {
|
|
|
3604
134
|
return content;
|
|
3605
135
|
return Array.isArray(content) ? content : [content];
|
|
3606
136
|
}
|
|
3607
|
-
// src/utilities/deterministic.ts
|
|
3608
|
-
function sortObjectKeys(obj) {
|
|
3609
|
-
if (obj === null || typeof obj !== "object") {
|
|
3610
|
-
return obj;
|
|
3611
|
-
}
|
|
3612
|
-
if (Array.isArray(obj)) {
|
|
3613
|
-
return obj.map(sortObjectKeys);
|
|
3614
|
-
}
|
|
3615
|
-
const sorted = {};
|
|
3616
|
-
const keys = Object.keys(obj).sort();
|
|
3617
|
-
for (const key of keys) {
|
|
3618
|
-
sorted[key] = sortObjectKeys(obj[key]);
|
|
3619
|
-
}
|
|
3620
|
-
return sorted;
|
|
3621
|
-
}
|
|
3622
|
-
function sortMessagesByPosition(messages) {
|
|
3623
|
-
return [...messages].sort((a, b) => {
|
|
3624
|
-
if (a.position !== b.position) {
|
|
3625
|
-
return a.position - b.position;
|
|
3626
|
-
}
|
|
3627
|
-
if (a.createdAt !== b.createdAt) {
|
|
3628
|
-
return a.createdAt.localeCompare(b.createdAt);
|
|
3629
|
-
}
|
|
3630
|
-
return a.id.localeCompare(b.id);
|
|
3631
|
-
});
|
|
3632
|
-
}
|
|
3633
|
-
// src/utilities/markdown.ts
|
|
3634
|
-
var import_gray_matter = __toESM(require_gray_matter(), 1);
|
|
3635
|
-
|
|
3636
137
|
// src/utilities/type-helpers.ts
|
|
3637
138
|
function toReadonly(value) {
|
|
3638
139
|
return value;
|
|
@@ -3640,7 +141,7 @@ function toReadonly(value) {
|
|
|
3640
141
|
|
|
3641
142
|
// src/utilities/message.ts
|
|
3642
143
|
function createMessage(props) {
|
|
3643
|
-
const content =
|
|
144
|
+
const content = typeof props.content === "string" ? props.content : toReadonly(props.content.map((part) => part));
|
|
3644
145
|
const message = {
|
|
3645
146
|
id: props.id,
|
|
3646
147
|
role: props.role,
|
|
@@ -3651,9 +152,15 @@ function createMessage(props) {
|
|
|
3651
152
|
hidden: props.hidden,
|
|
3652
153
|
toolCall: props.toolCall ? toReadonly({ ...props.toolCall }) : undefined,
|
|
3653
154
|
toolResult: props.toolResult ? toReadonly({ ...props.toolResult }) : undefined,
|
|
3654
|
-
tokenUsage: props.tokenUsage ? toReadonly({ ...props.tokenUsage }) : undefined
|
|
3655
|
-
goalCompleted: props.goalCompleted
|
|
155
|
+
tokenUsage: props.tokenUsage ? toReadonly({ ...props.tokenUsage }) : undefined
|
|
3656
156
|
};
|
|
157
|
+
if (isAssistantMessage(props)) {
|
|
158
|
+
return toReadonly({
|
|
159
|
+
...message,
|
|
160
|
+
role: "assistant",
|
|
161
|
+
goalCompleted: props.goalCompleted
|
|
162
|
+
});
|
|
163
|
+
}
|
|
3657
164
|
return toReadonly(message);
|
|
3658
165
|
}
|
|
3659
166
|
function messageParts(message) {
|
|
@@ -3672,246 +179,21 @@ function messageText(message, joiner = `
|
|
|
3672
179
|
function messageHasImages(message) {
|
|
3673
180
|
return messageParts(message).some((p) => p.type === "image");
|
|
3674
181
|
}
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
var ROLE_LABELS = {
|
|
3678
|
-
user: "User",
|
|
3679
|
-
assistant: "Assistant",
|
|
3680
|
-
system: "System",
|
|
3681
|
-
developer: "Developer",
|
|
3682
|
-
"tool-use": "Tool Use",
|
|
3683
|
-
"tool-result": "Tool Result",
|
|
3684
|
-
snapshot: "Snapshot"
|
|
3685
|
-
};
|
|
3686
|
-
var ROLE_DISPLAY_NAMES = ROLE_LABELS;
|
|
3687
|
-
var LABEL_TO_ROLE = {
|
|
3688
|
-
User: "user",
|
|
3689
|
-
Assistant: "assistant",
|
|
3690
|
-
System: "system",
|
|
3691
|
-
Developer: "developer",
|
|
3692
|
-
"Tool Use": "tool-use",
|
|
3693
|
-
"Tool Result": "tool-result",
|
|
3694
|
-
Snapshot: "snapshot"
|
|
3695
|
-
};
|
|
3696
|
-
var DISPLAY_NAME_TO_ROLE = LABEL_TO_ROLE;
|
|
3697
|
-
function getRoleLabel(role) {
|
|
3698
|
-
return ROLE_LABELS[role];
|
|
3699
|
-
}
|
|
3700
|
-
function getRoleFromLabel(label) {
|
|
3701
|
-
return LABEL_TO_ROLE[label];
|
|
3702
|
-
}
|
|
3703
|
-
function formatMessageContent(message) {
|
|
3704
|
-
if (typeof message.content === "string")
|
|
3705
|
-
return message.content;
|
|
3706
|
-
const parts = messageParts(message);
|
|
3707
|
-
const lines = [];
|
|
3708
|
-
for (const part of parts) {
|
|
3709
|
-
if (part.type === "text" && part.text) {
|
|
3710
|
-
lines.push(part.text);
|
|
3711
|
-
} else if (part.type === "image") {
|
|
3712
|
-
const imageUrl = part.url;
|
|
3713
|
-
const altText = part.text ?? "image";
|
|
3714
|
-
lines.push(``);
|
|
3715
|
-
}
|
|
3716
|
-
}
|
|
3717
|
-
return lines.join(`
|
|
3718
|
-
|
|
3719
|
-
`);
|
|
3720
|
-
}
|
|
3721
|
-
function toMarkdown(conversation, options2 = {}) {
|
|
3722
|
-
const { includeMetadata = false } = options2;
|
|
3723
|
-
if (includeMetadata) {
|
|
3724
|
-
return toMarkdownWithMetadata(conversation);
|
|
3725
|
-
}
|
|
3726
|
-
return toMarkdownSimple(conversation);
|
|
3727
|
-
}
|
|
3728
|
-
function toMarkdownSimple(conversation) {
|
|
3729
|
-
const sections = [];
|
|
3730
|
-
for (const message of conversation.messages) {
|
|
3731
|
-
const roleName = ROLE_DISPLAY_NAMES[message.role];
|
|
3732
|
-
const header = `### ${roleName}`;
|
|
3733
|
-
const content = formatMessageContent(message);
|
|
3734
|
-
sections.push(`${header}
|
|
3735
|
-
|
|
3736
|
-
${content}`);
|
|
3737
|
-
}
|
|
3738
|
-
return sections.join(`
|
|
3739
|
-
|
|
3740
|
-
`);
|
|
3741
|
-
}
|
|
3742
|
-
function toMarkdownWithMetadata(conversation) {
|
|
3743
|
-
const messagesMetadata = {};
|
|
3744
|
-
for (const message of conversation.messages) {
|
|
3745
|
-
const messageMeta = {
|
|
3746
|
-
position: message.position,
|
|
3747
|
-
createdAt: message.createdAt,
|
|
3748
|
-
metadata: { ...message.metadata },
|
|
3749
|
-
hidden: message.hidden
|
|
3750
|
-
};
|
|
3751
|
-
if (Array.isArray(message.content)) {
|
|
3752
|
-
messageMeta.content = copyContent(message.content);
|
|
3753
|
-
}
|
|
3754
|
-
if (message.toolCall) {
|
|
3755
|
-
messageMeta.toolCall = { ...message.toolCall };
|
|
3756
|
-
}
|
|
3757
|
-
if (message.toolResult) {
|
|
3758
|
-
messageMeta.toolResult = { ...message.toolResult };
|
|
3759
|
-
}
|
|
3760
|
-
if (message.tokenUsage) {
|
|
3761
|
-
messageMeta.tokenUsage = { ...message.tokenUsage };
|
|
3762
|
-
}
|
|
3763
|
-
if (message.goalCompleted !== undefined) {
|
|
3764
|
-
messageMeta.goalCompleted = message.goalCompleted;
|
|
3765
|
-
}
|
|
3766
|
-
messagesMetadata[message.id] = messageMeta;
|
|
3767
|
-
}
|
|
3768
|
-
const frontmatterData = {
|
|
3769
|
-
id: conversation.id,
|
|
3770
|
-
status: conversation.status,
|
|
3771
|
-
metadata: { ...conversation.metadata },
|
|
3772
|
-
tags: [...conversation.tags],
|
|
3773
|
-
createdAt: conversation.createdAt,
|
|
3774
|
-
updatedAt: conversation.updatedAt,
|
|
3775
|
-
messages: messagesMetadata
|
|
3776
|
-
};
|
|
3777
|
-
if (conversation.title !== undefined) {
|
|
3778
|
-
frontmatterData.title = conversation.title;
|
|
3779
|
-
}
|
|
3780
|
-
const messageSections = [];
|
|
3781
|
-
for (const message of conversation.messages) {
|
|
3782
|
-
const roleName = ROLE_DISPLAY_NAMES[message.role];
|
|
3783
|
-
const header = `### ${roleName} (${message.id})`;
|
|
3784
|
-
const content = formatMessageContent(message);
|
|
3785
|
-
messageSections.push(`${header}
|
|
3786
|
-
|
|
3787
|
-
${content}`);
|
|
3788
|
-
}
|
|
3789
|
-
const body = messageSections.join(`
|
|
3790
|
-
|
|
3791
|
-
`);
|
|
3792
|
-
return import_gray_matter.default.stringify(body, frontmatterData);
|
|
3793
|
-
}
|
|
3794
|
-
|
|
3795
|
-
class MarkdownParseError extends Error {
|
|
3796
|
-
constructor(message) {
|
|
3797
|
-
super(message);
|
|
3798
|
-
this.name = "MarkdownParseError";
|
|
3799
|
-
}
|
|
3800
|
-
}
|
|
3801
|
-
function generateId() {
|
|
3802
|
-
return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
3803
|
-
}
|
|
3804
|
-
function fromMarkdown(markdown) {
|
|
3805
|
-
const trimmed = markdown.trim();
|
|
3806
|
-
const hasFrontmatter = trimmed.startsWith("---");
|
|
3807
|
-
if (hasFrontmatter) {
|
|
3808
|
-
return parseMarkdownWithMetadata(trimmed);
|
|
3809
|
-
}
|
|
3810
|
-
return parseMarkdownSimple(trimmed);
|
|
3811
|
-
}
|
|
3812
|
-
function parseMarkdownWithMetadata(trimmed) {
|
|
3813
|
-
let parsed;
|
|
3814
|
-
try {
|
|
3815
|
-
parsed = import_gray_matter.default(trimmed);
|
|
3816
|
-
} catch {
|
|
3817
|
-
throw new MarkdownParseError("Invalid frontmatter: failed to parse YAML");
|
|
3818
|
-
}
|
|
3819
|
-
const frontmatter = parsed.data;
|
|
3820
|
-
const body = parsed.content.trim();
|
|
3821
|
-
if (!frontmatter.id) {
|
|
3822
|
-
throw new MarkdownParseError('Invalid frontmatter: missing required field "id"');
|
|
3823
|
-
}
|
|
3824
|
-
const messages = [];
|
|
3825
|
-
const messagePattern = /^### ([\w\s]+) \(([^)]+)\)\n\n([\s\S]*?)(?=\n\n### |\n*$)/gm;
|
|
3826
|
-
let match;
|
|
3827
|
-
while ((match = messagePattern.exec(body)) !== null) {
|
|
3828
|
-
const [, roleDisplay, messageId, contentBody] = match;
|
|
3829
|
-
const role = DISPLAY_NAME_TO_ROLE[roleDisplay];
|
|
3830
|
-
if (!role) {
|
|
3831
|
-
throw new MarkdownParseError(`Unknown role: ${roleDisplay}`);
|
|
3832
|
-
}
|
|
3833
|
-
const messageMeta = frontmatter.messages?.[messageId];
|
|
3834
|
-
if (!messageMeta) {
|
|
3835
|
-
throw new MarkdownParseError(`Missing metadata for message: ${messageId}`);
|
|
3836
|
-
}
|
|
3837
|
-
let content;
|
|
3838
|
-
if (messageMeta.content) {
|
|
3839
|
-
content = toReadonly([...messageMeta.content]);
|
|
3840
|
-
} else {
|
|
3841
|
-
content = contentBody?.trim() ?? "";
|
|
3842
|
-
}
|
|
3843
|
-
const message = {
|
|
3844
|
-
id: messageId,
|
|
3845
|
-
role,
|
|
3846
|
-
content,
|
|
3847
|
-
position: messageMeta.position,
|
|
3848
|
-
createdAt: messageMeta.createdAt,
|
|
3849
|
-
metadata: toReadonly({ ...messageMeta.metadata }),
|
|
3850
|
-
hidden: messageMeta.hidden,
|
|
3851
|
-
toolCall: messageMeta.toolCall ? toReadonly({ ...messageMeta.toolCall }) : undefined,
|
|
3852
|
-
toolResult: messageMeta.toolResult ? toReadonly({ ...messageMeta.toolResult }) : undefined,
|
|
3853
|
-
tokenUsage: messageMeta.tokenUsage ? toReadonly({ ...messageMeta.tokenUsage }) : undefined,
|
|
3854
|
-
goalCompleted: messageMeta.goalCompleted
|
|
3855
|
-
};
|
|
3856
|
-
messages.push(toReadonly(message));
|
|
3857
|
-
}
|
|
3858
|
-
const conversation = {
|
|
3859
|
-
id: frontmatter.id,
|
|
3860
|
-
title: frontmatter.title,
|
|
3861
|
-
status: frontmatter.status ?? "active",
|
|
3862
|
-
metadata: toReadonly({ ...frontmatter.metadata }),
|
|
3863
|
-
tags: toReadonly([...frontmatter.tags ?? []]),
|
|
3864
|
-
messages: toReadonly(messages),
|
|
3865
|
-
createdAt: frontmatter.createdAt,
|
|
3866
|
-
updatedAt: frontmatter.updatedAt
|
|
3867
|
-
};
|
|
3868
|
-
return toReadonly(conversation);
|
|
3869
|
-
}
|
|
3870
|
-
function parseMarkdownSimple(body) {
|
|
3871
|
-
const now = new Date().toISOString();
|
|
3872
|
-
const messages = [];
|
|
3873
|
-
const messagePattern = /^### ([^\n]+)\n\n([\s\S]*?)(?=\n\n### |\n*$)/gm;
|
|
3874
|
-
let match;
|
|
3875
|
-
let position = 0;
|
|
3876
|
-
while ((match = messagePattern.exec(body)) !== null) {
|
|
3877
|
-
const [, roleDisplay, contentBody] = match;
|
|
3878
|
-
const role = DISPLAY_NAME_TO_ROLE[roleDisplay];
|
|
3879
|
-
if (!role) {
|
|
3880
|
-
throw new MarkdownParseError(`Unknown role: ${roleDisplay}`);
|
|
3881
|
-
}
|
|
3882
|
-
const message = {
|
|
3883
|
-
id: generateId(),
|
|
3884
|
-
role,
|
|
3885
|
-
content: contentBody?.trim() ?? "",
|
|
3886
|
-
position,
|
|
3887
|
-
createdAt: now,
|
|
3888
|
-
metadata: toReadonly({}),
|
|
3889
|
-
hidden: false
|
|
3890
|
-
};
|
|
3891
|
-
messages.push(toReadonly(message));
|
|
3892
|
-
position++;
|
|
3893
|
-
}
|
|
3894
|
-
const conversation = {
|
|
3895
|
-
id: generateId(),
|
|
3896
|
-
status: "active",
|
|
3897
|
-
metadata: toReadonly({}),
|
|
3898
|
-
tags: toReadonly([]),
|
|
3899
|
-
messages: toReadonly(messages),
|
|
3900
|
-
createdAt: now,
|
|
3901
|
-
updatedAt: now
|
|
3902
|
-
};
|
|
3903
|
-
return toReadonly(conversation);
|
|
182
|
+
function isAssistantMessage(message) {
|
|
183
|
+
return message.role === "assistant";
|
|
3904
184
|
}
|
|
3905
185
|
// src/utilities/tool-calls.ts
|
|
3906
186
|
function pairToolCallsWithResults(messages) {
|
|
187
|
+
const isMessageArray = (value) => Array.isArray(value);
|
|
188
|
+
const ordered = isMessageArray(messages) ? messages : Object.values(messages).sort((a, b) => a.position - b.position);
|
|
3907
189
|
const pairs = [];
|
|
3908
190
|
const resultsMap = new Map;
|
|
3909
|
-
for (const msg of
|
|
191
|
+
for (const msg of ordered) {
|
|
3910
192
|
if (msg.toolResult) {
|
|
3911
193
|
resultsMap.set(msg.toolResult.callId, msg.toolResult);
|
|
3912
194
|
}
|
|
3913
195
|
}
|
|
3914
|
-
for (const msg of
|
|
196
|
+
for (const msg of ordered) {
|
|
3915
197
|
if (msg.toolCall) {
|
|
3916
198
|
pairs.push({
|
|
3917
199
|
call: msg.toolCall,
|
|
@@ -3921,6 +203,25 @@ function pairToolCallsWithResults(messages) {
|
|
|
3921
203
|
}
|
|
3922
204
|
return pairs;
|
|
3923
205
|
}
|
|
206
|
+
// src/utilities/message-store.ts
|
|
207
|
+
function getOrderedMessages(conversation) {
|
|
208
|
+
const ordered = [];
|
|
209
|
+
for (const id of conversation.ids) {
|
|
210
|
+
const message = conversation.messages[id];
|
|
211
|
+
if (message) {
|
|
212
|
+
ordered.push(message);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return ordered;
|
|
216
|
+
}
|
|
217
|
+
function toIdRecord(items) {
|
|
218
|
+
const record = {};
|
|
219
|
+
for (const item of items) {
|
|
220
|
+
record[item.id] = item;
|
|
221
|
+
}
|
|
222
|
+
return record;
|
|
223
|
+
}
|
|
224
|
+
|
|
3924
225
|
// src/utilities/transient.ts
|
|
3925
226
|
function isTransientKey(key) {
|
|
3926
227
|
return key.startsWith("_");
|
|
@@ -3935,26 +236,37 @@ function stripTransientFromRecord(metadata) {
|
|
|
3935
236
|
return result;
|
|
3936
237
|
}
|
|
3937
238
|
function stripTransientMetadata(conversation) {
|
|
3938
|
-
const strippedMessages = conversation.
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
239
|
+
const strippedMessages = getOrderedMessages(conversation).map((message) => {
|
|
240
|
+
const baseMessage = {
|
|
241
|
+
id: message.id,
|
|
242
|
+
role: message.role,
|
|
243
|
+
content: message.content,
|
|
244
|
+
position: message.position,
|
|
245
|
+
createdAt: message.createdAt,
|
|
246
|
+
metadata: toReadonly(stripTransientFromRecord({ ...message.metadata })),
|
|
247
|
+
hidden: message.hidden,
|
|
248
|
+
toolCall: message.toolCall,
|
|
249
|
+
toolResult: message.toolResult,
|
|
250
|
+
tokenUsage: message.tokenUsage
|
|
251
|
+
};
|
|
252
|
+
if (isAssistantMessage(message)) {
|
|
253
|
+
const assistantMessage = {
|
|
254
|
+
...baseMessage,
|
|
255
|
+
role: "assistant",
|
|
256
|
+
goalCompleted: message.goalCompleted
|
|
257
|
+
};
|
|
258
|
+
return toReadonly(assistantMessage);
|
|
259
|
+
}
|
|
260
|
+
return toReadonly(baseMessage);
|
|
261
|
+
});
|
|
3951
262
|
return toReadonly({
|
|
263
|
+
schemaVersion: conversation.schemaVersion,
|
|
3952
264
|
id: conversation.id,
|
|
3953
265
|
title: conversation.title,
|
|
3954
266
|
status: conversation.status,
|
|
3955
267
|
metadata: toReadonly(stripTransientFromRecord({ ...conversation.metadata })),
|
|
3956
|
-
|
|
3957
|
-
messages: strippedMessages,
|
|
268
|
+
ids: strippedMessages.map((message) => message.id),
|
|
269
|
+
messages: toIdRecord(strippedMessages),
|
|
3958
270
|
createdAt: conversation.createdAt,
|
|
3959
271
|
updatedAt: conversation.updatedAt
|
|
3960
272
|
});
|
|
@@ -3995,12 +307,12 @@ class ConversationalistError extends Error {
|
|
|
3995
307
|
code;
|
|
3996
308
|
context;
|
|
3997
309
|
cause;
|
|
3998
|
-
constructor(code, message,
|
|
310
|
+
constructor(code, message, options) {
|
|
3999
311
|
super(message);
|
|
4000
312
|
this.name = "ConversationalistError";
|
|
4001
313
|
this.code = code;
|
|
4002
|
-
this.context =
|
|
4003
|
-
this.cause =
|
|
314
|
+
this.context = options?.context;
|
|
315
|
+
this.cause = options?.cause;
|
|
4004
316
|
if (Error.captureStackTrace) {
|
|
4005
317
|
Error.captureStackTrace(this, ConversationalistError);
|
|
4006
318
|
}
|
|
@@ -4044,6 +356,9 @@ function createValidationError(message, context, cause) {
|
|
|
4044
356
|
return new ConversationalistError("error:validation", message, { context, cause });
|
|
4045
357
|
}
|
|
4046
358
|
|
|
359
|
+
// src/types.ts
|
|
360
|
+
var CURRENT_SCHEMA_VERSION = 3;
|
|
361
|
+
|
|
4047
362
|
// src/conversation.ts
|
|
4048
363
|
var buildToolUseIndex = (messages) => messages.reduce((index, message) => {
|
|
4049
364
|
if (message.role === "tool-use" && message.toolCall) {
|
|
@@ -4074,16 +389,17 @@ function partitionAppendArgs(args) {
|
|
|
4074
389
|
}
|
|
4075
390
|
return { inputs: args };
|
|
4076
391
|
}
|
|
4077
|
-
function createConversation(
|
|
392
|
+
function createConversation(options, environment) {
|
|
4078
393
|
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
4079
394
|
const now = resolvedEnvironment.now();
|
|
4080
395
|
const conv = {
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
396
|
+
schemaVersion: CURRENT_SCHEMA_VERSION,
|
|
397
|
+
id: options?.id ?? resolvedEnvironment.randomId(),
|
|
398
|
+
title: options?.title,
|
|
399
|
+
status: options?.status ?? "active",
|
|
400
|
+
metadata: { ...options?.metadata ?? {} },
|
|
401
|
+
ids: [],
|
|
402
|
+
messages: {},
|
|
4087
403
|
createdAt: now,
|
|
4088
404
|
updatedAt: now
|
|
4089
405
|
};
|
|
@@ -4093,15 +409,15 @@ function appendMessages(conversation, ...args) {
|
|
|
4093
409
|
const { inputs, environment } = partitionAppendArgs(args);
|
|
4094
410
|
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
4095
411
|
const now = resolvedEnvironment.now();
|
|
4096
|
-
const startPosition = conversation.
|
|
4097
|
-
const initialToolUses = buildToolUseIndex(conversation
|
|
412
|
+
const startPosition = conversation.ids.length;
|
|
413
|
+
const initialToolUses = buildToolUseIndex(getOrderedMessages(conversation));
|
|
4098
414
|
const { messages } = inputs.reduce((state, input, index) => {
|
|
4099
415
|
const processedInput = resolvedEnvironment.plugins.reduce((acc, plugin) => plugin(acc), input);
|
|
4100
416
|
if (processedInput.role === "tool-result" && processedInput.toolResult) {
|
|
4101
417
|
assertToolReference(state.toolUses, processedInput.toolResult.callId);
|
|
4102
418
|
}
|
|
4103
419
|
const normalizedContent = normalizeContent(processedInput.content);
|
|
4104
|
-
const
|
|
420
|
+
const baseMessage = {
|
|
4105
421
|
id: resolvedEnvironment.randomId(),
|
|
4106
422
|
role: processedInput.role,
|
|
4107
423
|
content: normalizedContent,
|
|
@@ -4111,18 +427,30 @@ function appendMessages(conversation, ...args) {
|
|
|
4111
427
|
hidden: processedInput.hidden ?? false,
|
|
4112
428
|
toolCall: processedInput.toolCall,
|
|
4113
429
|
toolResult: processedInput.toolResult,
|
|
4114
|
-
tokenUsage: processedInput.tokenUsage
|
|
4115
|
-
|
|
4116
|
-
|
|
430
|
+
tokenUsage: processedInput.tokenUsage
|
|
431
|
+
};
|
|
432
|
+
let message;
|
|
433
|
+
if (processedInput.role === "assistant") {
|
|
434
|
+
const assistantMessage = {
|
|
435
|
+
...baseMessage,
|
|
436
|
+
role: "assistant",
|
|
437
|
+
goalCompleted: processedInput.goalCompleted
|
|
438
|
+
};
|
|
439
|
+
message = createMessage(assistantMessage);
|
|
440
|
+
} else {
|
|
441
|
+
message = createMessage(baseMessage);
|
|
442
|
+
}
|
|
4117
443
|
const toolUses = processedInput.role === "tool-use" && processedInput.toolCall ? registerToolUse(state.toolUses, processedInput.toolCall) : state.toolUses;
|
|
4118
444
|
return {
|
|
4119
445
|
toolUses,
|
|
4120
446
|
messages: [...state.messages, message]
|
|
4121
447
|
};
|
|
4122
448
|
}, { toolUses: initialToolUses, messages: [] });
|
|
449
|
+
const messageIds = messages.map((message) => message.id);
|
|
4123
450
|
const next = {
|
|
4124
451
|
...conversation,
|
|
4125
|
-
|
|
452
|
+
ids: [...conversation.ids, ...messageIds],
|
|
453
|
+
messages: { ...conversation.messages, ...toIdRecord(messages) },
|
|
4126
454
|
updatedAt: now
|
|
4127
455
|
};
|
|
4128
456
|
return toReadonly(next);
|
|
@@ -4136,21 +464,27 @@ function appendAssistantMessage(conversation, content, metadata, environment) {
|
|
|
4136
464
|
function appendSystemMessage(conversation, content, metadata, environment) {
|
|
4137
465
|
return environment ? appendMessages(conversation, { role: "system", content, metadata }, environment) : appendMessages(conversation, { role: "system", content, metadata });
|
|
4138
466
|
}
|
|
4139
|
-
function
|
|
4140
|
-
const includeHidden =
|
|
4141
|
-
|
|
467
|
+
function getMessages(conversation, options) {
|
|
468
|
+
const includeHidden = options?.includeHidden ?? false;
|
|
469
|
+
const ordered = getOrderedMessages(conversation);
|
|
470
|
+
return includeHidden ? ordered : ordered.filter((m) => !m.hidden);
|
|
4142
471
|
}
|
|
4143
472
|
function getMessageAtPosition(conversation, position) {
|
|
4144
|
-
|
|
473
|
+
const id = conversation.ids[position];
|
|
474
|
+
return id ? conversation.messages[id] : undefined;
|
|
4145
475
|
}
|
|
4146
|
-
function
|
|
4147
|
-
return conversation.
|
|
476
|
+
function getMessageIds(conversation) {
|
|
477
|
+
return [...conversation.ids];
|
|
478
|
+
}
|
|
479
|
+
function getMessageById(conversation, id) {
|
|
480
|
+
return conversation.messages[id];
|
|
4148
481
|
}
|
|
4149
482
|
function searchConversationMessages(conversation, predicate) {
|
|
4150
|
-
return conversation.
|
|
483
|
+
return getOrderedMessages(conversation).filter(predicate);
|
|
4151
484
|
}
|
|
4152
|
-
function
|
|
4153
|
-
const
|
|
485
|
+
function getStatistics(conversation) {
|
|
486
|
+
const ordered = getOrderedMessages(conversation);
|
|
487
|
+
const stats = ordered.reduce((acc, message) => {
|
|
4154
488
|
const byRole = {
|
|
4155
489
|
...acc.byRole,
|
|
4156
490
|
[message.role]: (acc.byRole[message.role] ?? 0) + 1
|
|
@@ -4161,16 +495,16 @@ function computeConversationStatistics(conversation) {
|
|
|
4161
495
|
withImages: acc.withImages + (messageHasImages(message) ? 1 : 0)
|
|
4162
496
|
};
|
|
4163
497
|
}, { byRole: {}, hidden: 0, withImages: 0 });
|
|
4164
|
-
return { total:
|
|
498
|
+
return { total: ordered.length, ...stats };
|
|
4165
499
|
}
|
|
4166
500
|
function hasSystemMessage(conversation) {
|
|
4167
|
-
return conversation.
|
|
501
|
+
return getOrderedMessages(conversation).some((m) => m.role === "system");
|
|
4168
502
|
}
|
|
4169
503
|
function getFirstSystemMessage(conversation) {
|
|
4170
|
-
return conversation.
|
|
504
|
+
return getOrderedMessages(conversation).find((m) => m.role === "system");
|
|
4171
505
|
}
|
|
4172
506
|
function getSystemMessages(conversation) {
|
|
4173
|
-
return conversation.
|
|
507
|
+
return getOrderedMessages(conversation).filter((m) => m.role === "system");
|
|
4174
508
|
}
|
|
4175
509
|
function prependSystemMessage(conversation, content, metadata, environment) {
|
|
4176
510
|
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
@@ -4187,7 +521,8 @@ function prependSystemMessage(conversation, content, metadata, environment) {
|
|
|
4187
521
|
toolResult: undefined,
|
|
4188
522
|
tokenUsage: undefined
|
|
4189
523
|
});
|
|
4190
|
-
const
|
|
524
|
+
const ordered = getOrderedMessages(conversation);
|
|
525
|
+
const renumberedMessages = ordered.map((message) => createMessage({
|
|
4191
526
|
id: message.id,
|
|
4192
527
|
role: message.role,
|
|
4193
528
|
content: copyContent(message.content),
|
|
@@ -4201,18 +536,20 @@ function prependSystemMessage(conversation, content, metadata, environment) {
|
|
|
4201
536
|
}));
|
|
4202
537
|
return toReadonly({
|
|
4203
538
|
...conversation,
|
|
4204
|
-
|
|
539
|
+
ids: [newMessage.id, ...ordered.map((message) => message.id)],
|
|
540
|
+
messages: toIdRecord([newMessage, ...renumberedMessages]),
|
|
4205
541
|
updatedAt: now
|
|
4206
542
|
});
|
|
4207
543
|
}
|
|
4208
544
|
function replaceSystemMessage(conversation, content, metadata, environment) {
|
|
4209
545
|
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
4210
546
|
const now = resolvedEnvironment.now();
|
|
4211
|
-
const
|
|
547
|
+
const ordered = getOrderedMessages(conversation);
|
|
548
|
+
const firstSystemIndex = ordered.findIndex((m) => m.role === "system");
|
|
4212
549
|
if (firstSystemIndex === -1) {
|
|
4213
550
|
return prependSystemMessage(conversation, content, metadata, resolvedEnvironment);
|
|
4214
551
|
}
|
|
4215
|
-
const original =
|
|
552
|
+
const original = ordered[firstSystemIndex];
|
|
4216
553
|
const replaced = createMessage({
|
|
4217
554
|
id: original.id,
|
|
4218
555
|
role: "system",
|
|
@@ -4225,12 +562,17 @@ function replaceSystemMessage(conversation, content, metadata, environment) {
|
|
|
4225
562
|
toolResult: undefined,
|
|
4226
563
|
tokenUsage: undefined
|
|
4227
564
|
});
|
|
4228
|
-
const
|
|
4229
|
-
|
|
565
|
+
const next = {
|
|
566
|
+
...conversation,
|
|
567
|
+
ids: [...conversation.ids],
|
|
568
|
+
messages: { ...conversation.messages, [replaced.id]: replaced },
|
|
569
|
+
updatedAt: now
|
|
570
|
+
};
|
|
4230
571
|
return toReadonly(next);
|
|
4231
572
|
}
|
|
4232
573
|
function collapseSystemMessages(conversation, environment) {
|
|
4233
|
-
const
|
|
574
|
+
const ordered = getOrderedMessages(conversation);
|
|
575
|
+
const systemMessages = ordered.filter((m) => m.role === "system");
|
|
4234
576
|
if (systemMessages.length <= 1) {
|
|
4235
577
|
return conversation;
|
|
4236
578
|
}
|
|
@@ -4265,7 +607,7 @@ function collapseSystemMessages(conversation, environment) {
|
|
|
4265
607
|
nextIds.add(message.id);
|
|
4266
608
|
return nextIds;
|
|
4267
609
|
}, new Set);
|
|
4268
|
-
const messages =
|
|
610
|
+
const messages = ordered.filter((m) => !systemIdsToRemove.has(m.id)).map((m) => m.id === firstSystemMsg.id ? collapsed : m);
|
|
4269
611
|
const renumbered = messages.map((message, index) => {
|
|
4270
612
|
if (message.position === index)
|
|
4271
613
|
return message;
|
|
@@ -4284,16 +626,21 @@ function collapseSystemMessages(conversation, environment) {
|
|
|
4284
626
|
});
|
|
4285
627
|
const next = {
|
|
4286
628
|
...conversation,
|
|
4287
|
-
|
|
629
|
+
ids: renumbered.map((message) => message.id),
|
|
630
|
+
messages: toIdRecord(renumbered),
|
|
4288
631
|
updatedAt: now
|
|
4289
632
|
};
|
|
4290
633
|
return toReadonly(next);
|
|
4291
634
|
}
|
|
4292
635
|
function redactMessageAtPosition(conversation, position, placeholder = "[REDACTED]", environment) {
|
|
4293
|
-
if (position < 0 || position >= conversation.
|
|
4294
|
-
throw createInvalidPositionError(conversation.
|
|
636
|
+
if (position < 0 || position >= conversation.ids.length) {
|
|
637
|
+
throw createInvalidPositionError(conversation.ids.length - 1, position);
|
|
638
|
+
}
|
|
639
|
+
const id = conversation.ids[position];
|
|
640
|
+
const original = id ? conversation.messages[id] : undefined;
|
|
641
|
+
if (!original) {
|
|
642
|
+
throw createInvalidPositionError(conversation.ids.length - 1, position);
|
|
4295
643
|
}
|
|
4296
|
-
const original = conversation.messages[position];
|
|
4297
644
|
const redacted = createMessage({
|
|
4298
645
|
id: original.id,
|
|
4299
646
|
role: original.role,
|
|
@@ -4308,95 +655,77 @@ function redactMessageAtPosition(conversation, position, placeholder = "[REDACTE
|
|
|
4308
655
|
});
|
|
4309
656
|
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
4310
657
|
const now = resolvedEnvironment.now();
|
|
4311
|
-
const
|
|
4312
|
-
|
|
658
|
+
const next = {
|
|
659
|
+
...conversation,
|
|
660
|
+
ids: [...conversation.ids],
|
|
661
|
+
messages: { ...conversation.messages, [redacted.id]: redacted },
|
|
662
|
+
updatedAt: now
|
|
663
|
+
};
|
|
4313
664
|
return toReadonly(next);
|
|
4314
665
|
}
|
|
4315
|
-
|
|
4316
|
-
function migrateConversationJSON(json) {
|
|
666
|
+
function migrateConversation(json) {
|
|
4317
667
|
if (typeof json !== "object" || json === null || Array.isArray(json)) {
|
|
4318
668
|
return {
|
|
4319
669
|
schemaVersion: CURRENT_SCHEMA_VERSION,
|
|
4320
670
|
id: "",
|
|
4321
671
|
status: "active",
|
|
4322
672
|
metadata: {},
|
|
4323
|
-
|
|
4324
|
-
messages:
|
|
673
|
+
ids: [],
|
|
674
|
+
messages: {},
|
|
4325
675
|
createdAt: new Date().toISOString(),
|
|
4326
676
|
updatedAt: new Date().toISOString()
|
|
4327
677
|
};
|
|
4328
678
|
}
|
|
4329
679
|
const data = json;
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
if (stripTransient) {
|
|
4347
|
-
metadata = stripTransientFromRecord(metadata);
|
|
680
|
+
const rawMessages = data.messages;
|
|
681
|
+
let messages = {};
|
|
682
|
+
let ids = [];
|
|
683
|
+
const rawIds = data.ids;
|
|
684
|
+
const isStringArray = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
685
|
+
if (Array.isArray(rawMessages)) {
|
|
686
|
+
const rawMessageArray = rawMessages;
|
|
687
|
+
ids = rawMessageArray.map((message) => message.id);
|
|
688
|
+
messages = Object.fromEntries(rawMessageArray.map((message) => [message.id, message]));
|
|
689
|
+
} else if (rawMessages && typeof rawMessages === "object") {
|
|
690
|
+
messages = { ...rawMessages };
|
|
691
|
+
if (isStringArray(rawIds) && rawIds.length > 0) {
|
|
692
|
+
ids = [...rawIds];
|
|
693
|
+
} else {
|
|
694
|
+
ids = Object.values(messages).sort((a, b) => a.position - b.position).map((message) => message.id);
|
|
695
|
+
}
|
|
4348
696
|
}
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
697
|
+
if (ids.length > 0) {
|
|
698
|
+
ids = ids.filter((id) => (id in messages));
|
|
699
|
+
const missing = Object.keys(messages).filter((id) => !ids.includes(id));
|
|
700
|
+
if (missing.length > 0) {
|
|
701
|
+
const sortedMissing = missing.sort((a, b) => (messages[a]?.position ?? 0) - (messages[b]?.position ?? 0));
|
|
702
|
+
ids = [...ids, ...sortedMissing];
|
|
4353
703
|
}
|
|
704
|
+
}
|
|
705
|
+
if (!("schemaVersion" in json)) {
|
|
4354
706
|
return {
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
createdAt: m.createdAt,
|
|
4360
|
-
metadata: msgMetadata,
|
|
4361
|
-
hidden: m.hidden,
|
|
4362
|
-
toolCall: m.toolCall ? {
|
|
4363
|
-
...m.toolCall,
|
|
4364
|
-
arguments: redactToolArguments ? REDACTED : m.toolCall.arguments
|
|
4365
|
-
} : undefined,
|
|
4366
|
-
toolResult: m.toolResult ? {
|
|
4367
|
-
...m.toolResult,
|
|
4368
|
-
content: redactToolResults ? REDACTED : m.toolResult.content
|
|
4369
|
-
} : undefined,
|
|
4370
|
-
tokenUsage: m.tokenUsage ? { ...m.tokenUsage } : undefined,
|
|
4371
|
-
goalCompleted: m.goalCompleted
|
|
707
|
+
...data,
|
|
708
|
+
schemaVersion: CURRENT_SCHEMA_VERSION,
|
|
709
|
+
ids,
|
|
710
|
+
messages
|
|
4372
711
|
};
|
|
4373
|
-
});
|
|
4374
|
-
if (deterministic) {
|
|
4375
|
-
messages = sortMessagesByPosition(messages);
|
|
4376
|
-
}
|
|
4377
|
-
let result = {
|
|
4378
|
-
schemaVersion: CURRENT_SCHEMA_VERSION,
|
|
4379
|
-
id: conversation.id,
|
|
4380
|
-
title: conversation.title,
|
|
4381
|
-
status: conversation.status,
|
|
4382
|
-
metadata,
|
|
4383
|
-
tags: [...conversation.tags],
|
|
4384
|
-
messages,
|
|
4385
|
-
createdAt: conversation.createdAt,
|
|
4386
|
-
updatedAt: conversation.updatedAt
|
|
4387
|
-
};
|
|
4388
|
-
if (deterministic) {
|
|
4389
|
-
result = sortObjectKeys(result);
|
|
4390
712
|
}
|
|
4391
|
-
return
|
|
713
|
+
return { ...data, ids, messages };
|
|
4392
714
|
}
|
|
4393
715
|
function deserializeConversation(json) {
|
|
4394
|
-
const migrated =
|
|
716
|
+
const migrated = migrateConversation(json);
|
|
4395
717
|
try {
|
|
4396
|
-
migrated.
|
|
718
|
+
const orderedMessages = migrated.ids.map((id, index) => {
|
|
719
|
+
const message = migrated.messages[id];
|
|
720
|
+
if (!message) {
|
|
721
|
+
throw createSerializationError(`missing message for id ${id}`);
|
|
722
|
+
}
|
|
4397
723
|
if (message.position !== index) {
|
|
4398
724
|
throw createInvalidPositionError(index, message.position);
|
|
4399
725
|
}
|
|
726
|
+
return message;
|
|
727
|
+
});
|
|
728
|
+
orderedMessages.reduce((state, message) => {
|
|
4400
729
|
if (message.role === "tool-use" && message.toolCall) {
|
|
4401
730
|
return {
|
|
4402
731
|
toolUses: registerToolUse(state.toolUses, message.toolCall)
|
|
@@ -4407,14 +736,15 @@ function deserializeConversation(json) {
|
|
|
4407
736
|
}
|
|
4408
737
|
return state;
|
|
4409
738
|
}, { toolUses: new Map });
|
|
4410
|
-
const
|
|
739
|
+
const messageInstances = orderedMessages.map((m) => createMessage(m));
|
|
4411
740
|
const conv = {
|
|
741
|
+
schemaVersion: migrated.schemaVersion,
|
|
4412
742
|
id: migrated.id,
|
|
4413
743
|
title: migrated.title,
|
|
4414
744
|
status: migrated.status,
|
|
4415
745
|
metadata: { ...migrated.metadata },
|
|
4416
|
-
|
|
4417
|
-
messages,
|
|
746
|
+
ids: orderedMessages.map((message) => message.id),
|
|
747
|
+
messages: toIdRecord(messageInstances),
|
|
4418
748
|
createdAt: migrated.createdAt,
|
|
4419
749
|
updatedAt: migrated.updatedAt
|
|
4420
750
|
};
|
|
@@ -4434,7 +764,7 @@ function toChatMessages(conversation) {
|
|
|
4434
764
|
snapshot: "system"
|
|
4435
765
|
};
|
|
4436
766
|
const result = [];
|
|
4437
|
-
for (const message of conversation
|
|
767
|
+
for (const message of getOrderedMessages(conversation)) {
|
|
4438
768
|
if (message.hidden)
|
|
4439
769
|
continue;
|
|
4440
770
|
const externalRole = roleMap[message.role];
|
|
@@ -4446,6 +776,29 @@ function toChatMessages(conversation) {
|
|
|
4446
776
|
return result;
|
|
4447
777
|
}
|
|
4448
778
|
// src/context.ts
|
|
779
|
+
var cloneMessageWithPosition = (message, position, content) => {
|
|
780
|
+
const baseMessage = {
|
|
781
|
+
id: message.id,
|
|
782
|
+
role: message.role,
|
|
783
|
+
content,
|
|
784
|
+
position,
|
|
785
|
+
createdAt: message.createdAt,
|
|
786
|
+
metadata: { ...message.metadata },
|
|
787
|
+
hidden: message.hidden,
|
|
788
|
+
toolCall: message.toolCall ? { ...message.toolCall } : undefined,
|
|
789
|
+
toolResult: message.toolResult ? { ...message.toolResult } : undefined,
|
|
790
|
+
tokenUsage: message.tokenUsage ? { ...message.tokenUsage } : undefined
|
|
791
|
+
};
|
|
792
|
+
if (isAssistantMessage(message)) {
|
|
793
|
+
const assistantMessage = {
|
|
794
|
+
...baseMessage,
|
|
795
|
+
role: "assistant",
|
|
796
|
+
goalCompleted: message.goalCompleted
|
|
797
|
+
};
|
|
798
|
+
return createMessage(assistantMessage);
|
|
799
|
+
}
|
|
800
|
+
return createMessage(baseMessage);
|
|
801
|
+
};
|
|
4449
802
|
function estimateConversationTokens(conversation, estimateTokens, environment) {
|
|
4450
803
|
let estimator = estimateTokens;
|
|
4451
804
|
let env = environment;
|
|
@@ -4455,13 +808,13 @@ function estimateConversationTokens(conversation, estimateTokens, environment) {
|
|
|
4455
808
|
}
|
|
4456
809
|
const resolvedEnvironment = resolveConversationEnvironment(env);
|
|
4457
810
|
const finalEstimator = typeof estimator === "function" ? estimator : resolvedEnvironment.estimateTokens;
|
|
4458
|
-
return conversation.
|
|
811
|
+
return getOrderedMessages(conversation).reduce((total, message) => total + finalEstimator(message), 0);
|
|
4459
812
|
}
|
|
4460
813
|
function truncateToTokenLimit(conversation, maxTokens, optionsOrEstimator, environment) {
|
|
4461
|
-
let
|
|
814
|
+
let options = {};
|
|
4462
815
|
let env = environment;
|
|
4463
816
|
if (typeof optionsOrEstimator === "function") {
|
|
4464
|
-
|
|
817
|
+
options = { estimateTokens: optionsOrEstimator };
|
|
4465
818
|
} else if (optionsOrEstimator) {
|
|
4466
819
|
if (!environment && isConversationEnvironmentParameter(optionsOrEstimator)) {
|
|
4467
820
|
const candidate = optionsOrEstimator;
|
|
@@ -4469,23 +822,24 @@ function truncateToTokenLimit(conversation, maxTokens, optionsOrEstimator, envir
|
|
|
4469
822
|
if (hasEnvFields) {
|
|
4470
823
|
env = optionsOrEstimator;
|
|
4471
824
|
} else {
|
|
4472
|
-
|
|
825
|
+
options = optionsOrEstimator;
|
|
4473
826
|
}
|
|
4474
827
|
} else {
|
|
4475
|
-
|
|
828
|
+
options = optionsOrEstimator;
|
|
4476
829
|
}
|
|
4477
830
|
}
|
|
4478
831
|
const resolvedEnvironment = resolveConversationEnvironment(env);
|
|
4479
|
-
const estimator =
|
|
4480
|
-
const preserveSystem =
|
|
4481
|
-
const preserveLastN =
|
|
832
|
+
const estimator = options.estimateTokens ?? resolvedEnvironment.estimateTokens;
|
|
833
|
+
const preserveSystem = options.preserveSystemMessages ?? true;
|
|
834
|
+
const preserveLastN = options.preserveLastN ?? 0;
|
|
4482
835
|
const currentTokens = estimateConversationTokens(conversation, estimator, resolvedEnvironment);
|
|
4483
836
|
if (currentTokens <= maxTokens) {
|
|
4484
837
|
return conversation;
|
|
4485
838
|
}
|
|
4486
839
|
const now = resolvedEnvironment.now();
|
|
4487
|
-
const
|
|
4488
|
-
const
|
|
840
|
+
const orderedMessages = getOrderedMessages(conversation);
|
|
841
|
+
const systemMessages = preserveSystem ? orderedMessages.filter((m) => m.role === "system") : [];
|
|
842
|
+
const nonSystemMessages = orderedMessages.filter((m) => m.role !== "system");
|
|
4489
843
|
const protectedMessages = preserveLastN > 0 ? nonSystemMessages.slice(-preserveLastN) : [];
|
|
4490
844
|
const removableMessages = preserveLastN > 0 ? nonSystemMessages.slice(0, -preserveLastN) : nonSystemMessages;
|
|
4491
845
|
const systemTokens = systemMessages.reduce((sum, m) => sum + estimator(m), 0);
|
|
@@ -4493,22 +847,11 @@ function truncateToTokenLimit(conversation, maxTokens, optionsOrEstimator, envir
|
|
|
4493
847
|
const availableTokens = maxTokens - systemTokens - protectedTokens;
|
|
4494
848
|
if (availableTokens <= 0) {
|
|
4495
849
|
const allMessages2 = [...systemMessages, ...protectedMessages];
|
|
4496
|
-
const renumbered2 = allMessages2.map((message, index) =>
|
|
4497
|
-
id: message.id,
|
|
4498
|
-
role: message.role,
|
|
4499
|
-
content: copyContent(message.content),
|
|
4500
|
-
position: index,
|
|
4501
|
-
createdAt: message.createdAt,
|
|
4502
|
-
metadata: { ...message.metadata },
|
|
4503
|
-
hidden: message.hidden,
|
|
4504
|
-
toolCall: message.toolCall ? { ...message.toolCall } : undefined,
|
|
4505
|
-
toolResult: message.toolResult ? { ...message.toolResult } : undefined,
|
|
4506
|
-
tokenUsage: message.tokenUsage ? { ...message.tokenUsage } : undefined,
|
|
4507
|
-
goalCompleted: message.goalCompleted
|
|
4508
|
-
}));
|
|
850
|
+
const renumbered2 = allMessages2.map((message, index) => cloneMessageWithPosition(message, index, copyContent(message.content)));
|
|
4509
851
|
return toReadonly({
|
|
4510
852
|
...conversation,
|
|
4511
|
-
|
|
853
|
+
ids: renumbered2.map((message) => message.id),
|
|
854
|
+
messages: toIdRecord(renumbered2),
|
|
4512
855
|
updatedAt: now
|
|
4513
856
|
});
|
|
4514
857
|
}
|
|
@@ -4526,29 +869,18 @@ function truncateToTokenLimit(conversation, maxTokens, optionsOrEstimator, envir
|
|
|
4526
869
|
}
|
|
4527
870
|
const allMessages = [...systemMessages, ...keptRemovable, ...protectedMessages];
|
|
4528
871
|
allMessages.sort((a, b) => a.position - b.position);
|
|
4529
|
-
const renumbered = allMessages.map((message, index) =>
|
|
4530
|
-
id: message.id,
|
|
4531
|
-
role: message.role,
|
|
4532
|
-
content: copyContent(message.content),
|
|
4533
|
-
position: index,
|
|
4534
|
-
createdAt: message.createdAt,
|
|
4535
|
-
metadata: { ...message.metadata },
|
|
4536
|
-
hidden: message.hidden,
|
|
4537
|
-
toolCall: message.toolCall ? { ...message.toolCall } : undefined,
|
|
4538
|
-
toolResult: message.toolResult ? { ...message.toolResult } : undefined,
|
|
4539
|
-
tokenUsage: message.tokenUsage ? { ...message.tokenUsage } : undefined,
|
|
4540
|
-
goalCompleted: message.goalCompleted
|
|
4541
|
-
}));
|
|
872
|
+
const renumbered = allMessages.map((message, index) => cloneMessageWithPosition(message, index, copyContent(message.content)));
|
|
4542
873
|
return toReadonly({
|
|
4543
874
|
...conversation,
|
|
4544
|
-
|
|
875
|
+
ids: renumbered.map((message) => message.id),
|
|
876
|
+
messages: toIdRecord(renumbered),
|
|
4545
877
|
updatedAt: now
|
|
4546
878
|
});
|
|
4547
879
|
}
|
|
4548
|
-
function getRecentMessages(conversation, count,
|
|
4549
|
-
const includeHidden =
|
|
4550
|
-
const includeSystem =
|
|
4551
|
-
const filtered = conversation.
|
|
880
|
+
function getRecentMessages(conversation, count, options) {
|
|
881
|
+
const includeHidden = options?.includeHidden ?? false;
|
|
882
|
+
const includeSystem = options?.includeSystem ?? false;
|
|
883
|
+
const filtered = getOrderedMessages(conversation).filter((m) => {
|
|
4552
884
|
if (!includeHidden && m.hidden)
|
|
4553
885
|
return false;
|
|
4554
886
|
if (!includeSystem && m.role === "system")
|
|
@@ -4557,40 +889,53 @@ function getRecentMessages(conversation, count, options2) {
|
|
|
4557
889
|
});
|
|
4558
890
|
return filtered.slice(-count);
|
|
4559
891
|
}
|
|
4560
|
-
function truncateFromPosition(conversation, position,
|
|
4561
|
-
const preserveSystem =
|
|
892
|
+
function truncateFromPosition(conversation, position, options, environment) {
|
|
893
|
+
const preserveSystem = options?.preserveSystemMessages ?? true;
|
|
4562
894
|
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
4563
895
|
const now = resolvedEnvironment.now();
|
|
4564
|
-
const
|
|
4565
|
-
const
|
|
896
|
+
const ordered = getOrderedMessages(conversation);
|
|
897
|
+
const systemMessages = preserveSystem ? ordered.filter((m) => m.role === "system" && m.position < position) : [];
|
|
898
|
+
const keptMessages = ordered.filter((m) => m.position >= position);
|
|
4566
899
|
const allMessages = [...systemMessages, ...keptMessages];
|
|
4567
|
-
const renumbered = allMessages.map((message, index) =>
|
|
4568
|
-
id: message.id,
|
|
4569
|
-
role: message.role,
|
|
4570
|
-
content: copyContent(message.content),
|
|
4571
|
-
position: index,
|
|
4572
|
-
createdAt: message.createdAt,
|
|
4573
|
-
metadata: { ...message.metadata },
|
|
4574
|
-
hidden: message.hidden,
|
|
4575
|
-
toolCall: message.toolCall ? { ...message.toolCall } : undefined,
|
|
4576
|
-
toolResult: message.toolResult ? { ...message.toolResult } : undefined,
|
|
4577
|
-
tokenUsage: message.tokenUsage ? { ...message.tokenUsage } : undefined,
|
|
4578
|
-
goalCompleted: message.goalCompleted
|
|
4579
|
-
}));
|
|
900
|
+
const renumbered = allMessages.map((message, index) => cloneMessageWithPosition(message, index, copyContent(message.content)));
|
|
4580
901
|
return toReadonly({
|
|
4581
902
|
...conversation,
|
|
4582
|
-
|
|
903
|
+
ids: renumbered.map((message) => message.id),
|
|
904
|
+
messages: toIdRecord(renumbered),
|
|
4583
905
|
updatedAt: now
|
|
4584
906
|
});
|
|
4585
907
|
}
|
|
4586
908
|
|
|
4587
909
|
// src/streaming.ts
|
|
4588
910
|
var STREAMING_KEY = "__streaming";
|
|
911
|
+
var cloneMessage = (original, overrides = {}) => {
|
|
912
|
+
const baseMessage = {
|
|
913
|
+
id: original.id,
|
|
914
|
+
role: original.role,
|
|
915
|
+
content: overrides.content ?? (typeof original.content === "string" ? original.content : [...original.content]),
|
|
916
|
+
position: overrides.position ?? original.position,
|
|
917
|
+
createdAt: original.createdAt,
|
|
918
|
+
metadata: overrides.metadata ?? { ...original.metadata },
|
|
919
|
+
hidden: original.hidden,
|
|
920
|
+
toolCall: original.toolCall ? { ...original.toolCall } : undefined,
|
|
921
|
+
toolResult: original.toolResult ? { ...original.toolResult } : undefined,
|
|
922
|
+
tokenUsage: overrides.tokenUsage
|
|
923
|
+
};
|
|
924
|
+
if (isAssistantMessage(original)) {
|
|
925
|
+
const assistantMessage = {
|
|
926
|
+
...baseMessage,
|
|
927
|
+
role: "assistant",
|
|
928
|
+
goalCompleted: original.goalCompleted
|
|
929
|
+
};
|
|
930
|
+
return createMessage(assistantMessage);
|
|
931
|
+
}
|
|
932
|
+
return createMessage(baseMessage);
|
|
933
|
+
};
|
|
4589
934
|
function isStreamingMessage(message) {
|
|
4590
935
|
return message.metadata[STREAMING_KEY] === true;
|
|
4591
936
|
}
|
|
4592
937
|
function getStreamingMessage(conversation) {
|
|
4593
|
-
return conversation.
|
|
938
|
+
return getOrderedMessages(conversation).find(isStreamingMessage);
|
|
4594
939
|
}
|
|
4595
940
|
function appendStreamingMessage(conversation, role, metadata, environment) {
|
|
4596
941
|
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
@@ -4600,7 +945,7 @@ function appendStreamingMessage(conversation, role, metadata, environment) {
|
|
|
4600
945
|
id: messageId,
|
|
4601
946
|
role,
|
|
4602
947
|
content: "",
|
|
4603
|
-
position: conversation.
|
|
948
|
+
position: conversation.ids.length,
|
|
4604
949
|
createdAt: now,
|
|
4605
950
|
metadata: { ...metadata ?? {}, [STREAMING_KEY]: true },
|
|
4606
951
|
hidden: false,
|
|
@@ -4610,7 +955,8 @@ function appendStreamingMessage(conversation, role, metadata, environment) {
|
|
|
4610
955
|
});
|
|
4611
956
|
const updatedConversation = toReadonly({
|
|
4612
957
|
...conversation,
|
|
4613
|
-
|
|
958
|
+
ids: [...conversation.ids, messageId],
|
|
959
|
+
messages: { ...conversation.messages, [messageId]: newMessage },
|
|
4614
960
|
updatedAt: now
|
|
4615
961
|
});
|
|
4616
962
|
return { conversation: updatedConversation, messageId };
|
|
@@ -4618,84 +964,69 @@ function appendStreamingMessage(conversation, role, metadata, environment) {
|
|
|
4618
964
|
function updateStreamingMessage(conversation, messageId, content, environment) {
|
|
4619
965
|
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
4620
966
|
const now = resolvedEnvironment.now();
|
|
4621
|
-
const
|
|
4622
|
-
if (
|
|
967
|
+
const original = conversation.messages[messageId];
|
|
968
|
+
if (!original) {
|
|
4623
969
|
return conversation;
|
|
4624
970
|
}
|
|
4625
|
-
const
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
metadata: { ...original.metadata },
|
|
4633
|
-
hidden: original.hidden,
|
|
4634
|
-
toolCall: original.toolCall ? { ...original.toolCall } : undefined,
|
|
4635
|
-
toolResult: original.toolResult ? { ...original.toolResult } : undefined,
|
|
4636
|
-
tokenUsage: original.tokenUsage ? { ...original.tokenUsage } : undefined,
|
|
4637
|
-
goalCompleted: original.goalCompleted
|
|
4638
|
-
});
|
|
4639
|
-
const messages = conversation.messages.map((m, i) => i === messageIndex ? updated : m);
|
|
971
|
+
const overrides = {
|
|
972
|
+
content: typeof content === "string" ? content : [...content]
|
|
973
|
+
};
|
|
974
|
+
if (original.tokenUsage) {
|
|
975
|
+
overrides.tokenUsage = { ...original.tokenUsage };
|
|
976
|
+
}
|
|
977
|
+
const updated = cloneMessage(original, overrides);
|
|
4640
978
|
return toReadonly({
|
|
4641
979
|
...conversation,
|
|
4642
|
-
|
|
980
|
+
ids: [...conversation.ids],
|
|
981
|
+
messages: { ...conversation.messages, [updated.id]: updated },
|
|
4643
982
|
updatedAt: now
|
|
4644
983
|
});
|
|
4645
984
|
}
|
|
4646
|
-
function finalizeStreamingMessage(conversation, messageId,
|
|
985
|
+
function finalizeStreamingMessage(conversation, messageId, options, environment) {
|
|
4647
986
|
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
4648
987
|
const now = resolvedEnvironment.now();
|
|
4649
|
-
const
|
|
4650
|
-
if (
|
|
988
|
+
const original = conversation.messages[messageId];
|
|
989
|
+
if (!original) {
|
|
4651
990
|
return conversation;
|
|
4652
991
|
}
|
|
4653
|
-
const original = conversation.messages[messageIndex];
|
|
4654
992
|
const { [STREAMING_KEY]: _, ...restMetadata } = original.metadata;
|
|
4655
|
-
const finalMetadata = {
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
tokenUsage: options2?.tokenUsage ? { ...options2.tokenUsage } : undefined,
|
|
4667
|
-
goalCompleted: original.goalCompleted
|
|
4668
|
-
});
|
|
4669
|
-
const messages = conversation.messages.map((m, i) => i === messageIndex ? updated : m);
|
|
993
|
+
const finalMetadata = {
|
|
994
|
+
...restMetadata,
|
|
995
|
+
...options?.metadata ?? {}
|
|
996
|
+
};
|
|
997
|
+
const finalizeOverrides = {
|
|
998
|
+
metadata: finalMetadata
|
|
999
|
+
};
|
|
1000
|
+
if (options?.tokenUsage) {
|
|
1001
|
+
finalizeOverrides.tokenUsage = { ...options.tokenUsage };
|
|
1002
|
+
}
|
|
1003
|
+
const updated = cloneMessage(original, finalizeOverrides);
|
|
4670
1004
|
return toReadonly({
|
|
4671
1005
|
...conversation,
|
|
4672
|
-
|
|
1006
|
+
ids: [...conversation.ids],
|
|
1007
|
+
messages: { ...conversation.messages, [updated.id]: updated },
|
|
4673
1008
|
updatedAt: now
|
|
4674
1009
|
});
|
|
4675
1010
|
}
|
|
4676
1011
|
function cancelStreamingMessage(conversation, messageId, environment) {
|
|
4677
1012
|
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
4678
1013
|
const now = resolvedEnvironment.now();
|
|
4679
|
-
|
|
4680
|
-
if (messageIndex === -1) {
|
|
1014
|
+
if (!conversation.messages[messageId]) {
|
|
4681
1015
|
return conversation;
|
|
4682
1016
|
}
|
|
4683
|
-
const messages = conversation.
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
toolResult: message.toolResult ? { ...message.toolResult } : undefined,
|
|
4693
|
-
tokenUsage: message.tokenUsage ? { ...message.tokenUsage } : undefined,
|
|
4694
|
-
goalCompleted: message.goalCompleted
|
|
4695
|
-
}));
|
|
1017
|
+
const messages = getOrderedMessages(conversation).filter((m) => m.id !== messageId).map((message, index) => message.position === index ? message : (() => {
|
|
1018
|
+
const overrides = {
|
|
1019
|
+
position: index
|
|
1020
|
+
};
|
|
1021
|
+
if (message.tokenUsage) {
|
|
1022
|
+
overrides.tokenUsage = { ...message.tokenUsage };
|
|
1023
|
+
}
|
|
1024
|
+
return cloneMessage(message, overrides);
|
|
1025
|
+
})());
|
|
4696
1026
|
return toReadonly({
|
|
4697
1027
|
...conversation,
|
|
4698
|
-
messages,
|
|
1028
|
+
ids: messages.map((message) => message.id),
|
|
1029
|
+
messages: toIdRecord(messages),
|
|
4699
1030
|
updatedAt: now
|
|
4700
1031
|
});
|
|
4701
1032
|
}
|
|
@@ -4748,20 +1079,20 @@ function createDraft(initial) {
|
|
|
4748
1079
|
current = updateStreamingMessage(current, messageId, content);
|
|
4749
1080
|
return draft;
|
|
4750
1081
|
},
|
|
4751
|
-
finalizeStreamingMessage: (messageId,
|
|
4752
|
-
current = finalizeStreamingMessage(current, messageId,
|
|
1082
|
+
finalizeStreamingMessage: (messageId, options) => {
|
|
1083
|
+
current = finalizeStreamingMessage(current, messageId, options);
|
|
4753
1084
|
return draft;
|
|
4754
1085
|
},
|
|
4755
1086
|
cancelStreamingMessage: (messageId) => {
|
|
4756
1087
|
current = cancelStreamingMessage(current, messageId);
|
|
4757
1088
|
return draft;
|
|
4758
1089
|
},
|
|
4759
|
-
truncateFromPosition: (position,
|
|
4760
|
-
current = truncateFromPosition(current, position,
|
|
1090
|
+
truncateFromPosition: (position, options) => {
|
|
1091
|
+
current = truncateFromPosition(current, position, options);
|
|
4761
1092
|
return draft;
|
|
4762
1093
|
},
|
|
4763
|
-
truncateToTokenLimit: (maxTokens,
|
|
4764
|
-
current = truncateToTokenLimit(current, maxTokens,
|
|
1094
|
+
truncateToTokenLimit: (maxTokens, options) => {
|
|
1095
|
+
current = truncateToTokenLimit(current, maxTokens, options);
|
|
4765
1096
|
return draft;
|
|
4766
1097
|
}
|
|
4767
1098
|
};
|
|
@@ -4805,11 +1136,11 @@ class ConversationHistory extends EventTarget {
|
|
|
4805
1136
|
this.dispatchEvent(new ConversationHistoryEvent("change", detail));
|
|
4806
1137
|
this.dispatchEvent(new ConversationHistoryEvent(type, detail));
|
|
4807
1138
|
}
|
|
4808
|
-
addEventListener(type, callback,
|
|
1139
|
+
addEventListener(type, callback, options) {
|
|
4809
1140
|
if (!callback)
|
|
4810
1141
|
return;
|
|
4811
|
-
super.addEventListener(type, callback,
|
|
4812
|
-
const unsubscribe = () => this.removeEventListener(type, callback,
|
|
1142
|
+
super.addEventListener(type, callback, options);
|
|
1143
|
+
const unsubscribe = () => this.removeEventListener(type, callback, options);
|
|
4813
1144
|
return unsubscribe;
|
|
4814
1145
|
}
|
|
4815
1146
|
subscribe(run) {
|
|
@@ -4828,6 +1159,9 @@ class ConversationHistory extends EventTarget {
|
|
|
4828
1159
|
get current() {
|
|
4829
1160
|
return this.currentNode.conversation;
|
|
4830
1161
|
}
|
|
1162
|
+
get ids() {
|
|
1163
|
+
return getMessageIds(this.current);
|
|
1164
|
+
}
|
|
4831
1165
|
get canUndo() {
|
|
4832
1166
|
return this.currentNode.parent !== null;
|
|
4833
1167
|
}
|
|
@@ -4895,20 +1229,26 @@ class ConversationHistory extends EventTarget {
|
|
|
4895
1229
|
}
|
|
4896
1230
|
return path;
|
|
4897
1231
|
}
|
|
4898
|
-
getMessages(
|
|
4899
|
-
return
|
|
1232
|
+
getMessages(options) {
|
|
1233
|
+
return getMessages(this.current, options);
|
|
4900
1234
|
}
|
|
4901
1235
|
getMessageAtPosition(position) {
|
|
4902
1236
|
return getMessageAtPosition(this.current, position);
|
|
4903
1237
|
}
|
|
4904
|
-
|
|
4905
|
-
return
|
|
1238
|
+
getMessageIds() {
|
|
1239
|
+
return getMessageIds(this.current);
|
|
1240
|
+
}
|
|
1241
|
+
getMessageById(id) {
|
|
1242
|
+
return getMessageById(this.current, id);
|
|
1243
|
+
}
|
|
1244
|
+
get(id) {
|
|
1245
|
+
return getMessageById(this.current, id);
|
|
4906
1246
|
}
|
|
4907
1247
|
searchMessages(predicate) {
|
|
4908
1248
|
return searchConversationMessages(this.current, predicate);
|
|
4909
1249
|
}
|
|
4910
1250
|
getStatistics() {
|
|
4911
|
-
return
|
|
1251
|
+
return getStatistics(this.current);
|
|
4912
1252
|
}
|
|
4913
1253
|
hasSystemMessage() {
|
|
4914
1254
|
return hasSystemMessage(this.current);
|
|
@@ -4919,20 +1259,14 @@ class ConversationHistory extends EventTarget {
|
|
|
4919
1259
|
getSystemMessages() {
|
|
4920
1260
|
return getSystemMessages(this.current);
|
|
4921
1261
|
}
|
|
4922
|
-
serialize() {
|
|
4923
|
-
return serializeConversation(this.current);
|
|
4924
|
-
}
|
|
4925
1262
|
toChatMessages() {
|
|
4926
1263
|
return toChatMessages(this.current);
|
|
4927
1264
|
}
|
|
4928
|
-
toMarkdown(options2) {
|
|
4929
|
-
return toMarkdown(this.current, options2);
|
|
4930
|
-
}
|
|
4931
1265
|
estimateTokens(estimator) {
|
|
4932
1266
|
return estimateConversationTokens(this.current, estimator, this.env);
|
|
4933
1267
|
}
|
|
4934
|
-
getRecentMessages(count,
|
|
4935
|
-
return getRecentMessages(this.current, count,
|
|
1268
|
+
getRecentMessages(count, options) {
|
|
1269
|
+
return getRecentMessages(this.current, count, options);
|
|
4936
1270
|
}
|
|
4937
1271
|
getStreamingMessage() {
|
|
4938
1272
|
return getStreamingMessage(this.current);
|
|
@@ -4961,11 +1295,11 @@ class ConversationHistory extends EventTarget {
|
|
|
4961
1295
|
redactMessageAtPosition(position, placeholder) {
|
|
4962
1296
|
this.push(redactMessageAtPosition(this.current, position, placeholder, this.env));
|
|
4963
1297
|
}
|
|
4964
|
-
truncateFromPosition(position,
|
|
4965
|
-
this.push(truncateFromPosition(this.current, position,
|
|
1298
|
+
truncateFromPosition(position, options) {
|
|
1299
|
+
this.push(truncateFromPosition(this.current, position, options, this.env));
|
|
4966
1300
|
}
|
|
4967
|
-
truncateToTokenLimit(maxTokens,
|
|
4968
|
-
this.push(truncateToTokenLimit(this.current, maxTokens,
|
|
1301
|
+
truncateToTokenLimit(maxTokens, options) {
|
|
1302
|
+
this.push(truncateToTokenLimit(this.current, maxTokens, options, this.env));
|
|
4969
1303
|
}
|
|
4970
1304
|
appendStreamingMessage(role, metadata) {
|
|
4971
1305
|
const { conversation, messageId } = appendStreamingMessage(this.current, role, metadata, this.env);
|
|
@@ -4975,13 +1309,13 @@ class ConversationHistory extends EventTarget {
|
|
|
4975
1309
|
updateStreamingMessage(messageId, content) {
|
|
4976
1310
|
this.push(updateStreamingMessage(this.current, messageId, content, this.env));
|
|
4977
1311
|
}
|
|
4978
|
-
finalizeStreamingMessage(messageId,
|
|
4979
|
-
this.push(finalizeStreamingMessage(this.current, messageId,
|
|
1312
|
+
finalizeStreamingMessage(messageId, options) {
|
|
1313
|
+
this.push(finalizeStreamingMessage(this.current, messageId, options, this.env));
|
|
4980
1314
|
}
|
|
4981
1315
|
cancelStreamingMessage(messageId) {
|
|
4982
1316
|
this.push(cancelStreamingMessage(this.current, messageId, this.env));
|
|
4983
1317
|
}
|
|
4984
|
-
|
|
1318
|
+
snapshot() {
|
|
4985
1319
|
const getPath = (node) => {
|
|
4986
1320
|
const path = [];
|
|
4987
1321
|
let curr = node;
|
|
@@ -4992,7 +1326,7 @@ class ConversationHistory extends EventTarget {
|
|
|
4992
1326
|
return path;
|
|
4993
1327
|
};
|
|
4994
1328
|
const serializeNode = (node) => ({
|
|
4995
|
-
conversation:
|
|
1329
|
+
conversation: node.conversation,
|
|
4996
1330
|
children: node.children.map(serializeNode)
|
|
4997
1331
|
});
|
|
4998
1332
|
let root = this.currentNode;
|
|
@@ -5030,12 +1364,15 @@ class ConversationHistory extends EventTarget {
|
|
|
5030
1364
|
h.currentNode = current;
|
|
5031
1365
|
return history;
|
|
5032
1366
|
}
|
|
5033
|
-
static fromMarkdown(markdown, environment) {
|
|
5034
|
-
const conversation = fromMarkdown(markdown);
|
|
5035
|
-
return new ConversationHistory(conversation, environment);
|
|
5036
|
-
}
|
|
5037
1367
|
bind(fn) {
|
|
5038
|
-
return
|
|
1368
|
+
return (...args) => {
|
|
1369
|
+
const boundFn = fn;
|
|
1370
|
+
const result = boundFn(this.current, ...args, this.env);
|
|
1371
|
+
if (isConversation(result)) {
|
|
1372
|
+
this.push(result);
|
|
1373
|
+
}
|
|
1374
|
+
return result;
|
|
1375
|
+
};
|
|
5039
1376
|
}
|
|
5040
1377
|
[Symbol.dispose]() {
|
|
5041
1378
|
let root = this.currentNode;
|
|
@@ -5055,18 +1392,8 @@ class ConversationHistory extends EventTarget {
|
|
|
5055
1392
|
clearNode(root);
|
|
5056
1393
|
}
|
|
5057
1394
|
}
|
|
5058
|
-
function bindToConversationHistory(history, fn) {
|
|
5059
|
-
return (...args) => {
|
|
5060
|
-
const boundFn = fn;
|
|
5061
|
-
const result = boundFn(history.current, ...args, history.env);
|
|
5062
|
-
if (isConversation(result)) {
|
|
5063
|
-
history.push(result);
|
|
5064
|
-
}
|
|
5065
|
-
return result;
|
|
5066
|
-
};
|
|
5067
|
-
}
|
|
5068
1395
|
function isConversation(value) {
|
|
5069
|
-
return value !== null && typeof value === "object" && typeof value.id === "string" && typeof value.status === "string" && value.metadata !== null && typeof value.metadata === "object" && Array.isArray(value.
|
|
1396
|
+
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";
|
|
5070
1397
|
}
|
|
5071
1398
|
export {
|
|
5072
1399
|
withEnvironment,
|
|
@@ -5078,14 +1405,10 @@ export {
|
|
|
5078
1405
|
toolCallSchema,
|
|
5079
1406
|
tokenUsageSchema,
|
|
5080
1407
|
toMultiModalArray,
|
|
5081
|
-
toMarkdown,
|
|
5082
1408
|
toChatMessages,
|
|
5083
1409
|
stripTransientMetadata,
|
|
5084
1410
|
stripTransientFromRecord,
|
|
5085
|
-
sortObjectKeys,
|
|
5086
|
-
sortMessagesByPosition,
|
|
5087
1411
|
simpleTokenEstimator,
|
|
5088
|
-
serializeConversation,
|
|
5089
1412
|
searchConversationMessages,
|
|
5090
1413
|
replaceSystemMessage,
|
|
5091
1414
|
redactMessageAtPosition,
|
|
@@ -5094,23 +1417,23 @@ export {
|
|
|
5094
1417
|
pairToolCallsWithResults,
|
|
5095
1418
|
normalizeContent,
|
|
5096
1419
|
multiModalContentSchema,
|
|
5097
|
-
migrateConversationJSON,
|
|
5098
1420
|
messageRoleSchema,
|
|
5099
1421
|
messageJSONSchema,
|
|
5100
1422
|
messageInputSchema,
|
|
1423
|
+
jsonValueSchema,
|
|
5101
1424
|
isTransientKey,
|
|
5102
1425
|
isStreamingMessage,
|
|
1426
|
+
isAssistantMessage,
|
|
5103
1427
|
hasSystemMessage,
|
|
5104
1428
|
getSystemMessages,
|
|
5105
1429
|
getStreamingMessage,
|
|
5106
|
-
|
|
5107
|
-
getRoleFromLabel,
|
|
1430
|
+
getStatistics,
|
|
5108
1431
|
getRecentMessages,
|
|
5109
|
-
|
|
1432
|
+
getMessages,
|
|
1433
|
+
getMessageIds,
|
|
1434
|
+
getMessageById,
|
|
5110
1435
|
getMessageAtPosition,
|
|
5111
1436
|
getFirstSystemMessage,
|
|
5112
|
-
getConversationMessages,
|
|
5113
|
-
fromMarkdown,
|
|
5114
1437
|
finalizeStreamingMessage,
|
|
5115
1438
|
estimateConversationTokens,
|
|
5116
1439
|
deserializeConversation,
|
|
@@ -5128,21 +1451,15 @@ export {
|
|
|
5128
1451
|
copyContent,
|
|
5129
1452
|
conversationShape,
|
|
5130
1453
|
conversationSchema,
|
|
5131
|
-
computeConversationStatistics,
|
|
5132
1454
|
collapseSystemMessages,
|
|
5133
1455
|
cancelStreamingMessage,
|
|
5134
|
-
bindToConversationHistory,
|
|
5135
1456
|
appendUserMessage,
|
|
5136
1457
|
appendSystemMessage,
|
|
5137
1458
|
appendStreamingMessage,
|
|
5138
1459
|
appendMessages,
|
|
5139
1460
|
appendAssistantMessage,
|
|
5140
|
-
ROLE_LABELS,
|
|
5141
|
-
MarkdownParseError,
|
|
5142
|
-
LABEL_TO_ROLE,
|
|
5143
1461
|
ConversationalistError,
|
|
5144
|
-
ConversationHistory
|
|
5145
|
-
CURRENT_SCHEMA_VERSION
|
|
1462
|
+
ConversationHistory
|
|
5146
1463
|
};
|
|
5147
1464
|
|
|
5148
|
-
//# debugId=
|
|
1465
|
+
//# debugId=77EDEC984ED3373C64756E2164756E21
|