@sjawhar/claude-envoy 5.10.0 → 5.10.2

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.
@@ -18143,13 +18143,1129 @@ var DELIMITERS = {
18143
18143
  pipe: "|"
18144
18144
  };
18145
18145
  var DEFAULT_DELIMITER = DELIMITERS.comma;
18146
+ function trimSpaces(value) {
18147
+ let start = 0;
18148
+ let end = value.length;
18149
+ while (start < end && value[start] === " ")
18150
+ start++;
18151
+ while (end > start && value[end - 1] === " ")
18152
+ end--;
18153
+ return start === 0 && end === value.length ? value : value.slice(start, end);
18154
+ }
18146
18155
  function escapeString(value) {
18147
18156
  return value.replace(/\\/g, `\\\\`).replace(/"/g, `\\"`).replace(/\n/g, `\\n`).replace(/\r/g, `\\r`).replace(/\t/g, `\\t`).replace(/[\u0000-\u001F]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
18148
18157
  }
18158
+ function unescapeString(value) {
18159
+ let unescaped = "";
18160
+ let i = 0;
18161
+ while (i < value.length) {
18162
+ if (value[i] === "\\") {
18163
+ if (i + 1 >= value.length)
18164
+ throw new SyntaxError("Invalid escape sequence: backslash at end of string");
18165
+ const next = value[i + 1];
18166
+ if (next === "n") {
18167
+ unescaped += `
18168
+ `;
18169
+ i += 2;
18170
+ continue;
18171
+ }
18172
+ if (next === "t") {
18173
+ unescaped += "\t";
18174
+ i += 2;
18175
+ continue;
18176
+ }
18177
+ if (next === "r") {
18178
+ unescaped += "\r";
18179
+ i += 2;
18180
+ continue;
18181
+ }
18182
+ if (next === "\\") {
18183
+ unescaped += "\\";
18184
+ i += 2;
18185
+ continue;
18186
+ }
18187
+ if (next === '"') {
18188
+ unescaped += '"';
18189
+ i += 2;
18190
+ continue;
18191
+ }
18192
+ if (next === "u") {
18193
+ if (i + 6 > value.length)
18194
+ throw new SyntaxError(`Invalid escape sequence: truncated \\u escape at "${value.slice(i, i + 6)}"`);
18195
+ const hex = value.slice(i + 2, i + 6);
18196
+ if (!/^[0-9a-f]{4}$/i.test(hex))
18197
+ throw new SyntaxError(`Invalid escape sequence: \\u must be followed by 4 hex digits, got "${hex}"`);
18198
+ const codeUnit = Number.parseInt(hex, 16);
18199
+ if (codeUnit >= 55296 && codeUnit <= 57343)
18200
+ throw new SyntaxError(`Invalid escape sequence: \\u${hex} is a lone surrogate. Supplementary code points MUST appear as literal UTF-8`);
18201
+ unescaped += String.fromCodePoint(codeUnit);
18202
+ i += 6;
18203
+ continue;
18204
+ }
18205
+ throw new SyntaxError(`Invalid escape sequence: \\${next}`);
18206
+ }
18207
+ unescaped += value[i];
18208
+ i++;
18209
+ }
18210
+ return unescaped;
18211
+ }
18212
+ function findClosingQuote(content, start) {
18213
+ let i = start + 1;
18214
+ while (i < content.length) {
18215
+ if (content[i] === "\\" && i + 1 < content.length) {
18216
+ i += 2;
18217
+ continue;
18218
+ }
18219
+ if (content[i] === '"')
18220
+ return i;
18221
+ i++;
18222
+ }
18223
+ return -1;
18224
+ }
18225
+ function findUnquotedChar(content, char, start = 0) {
18226
+ let inQuotes = false;
18227
+ let i = start;
18228
+ while (i < content.length) {
18229
+ if (content[i] === "\\" && i + 1 < content.length && inQuotes) {
18230
+ i += 2;
18231
+ continue;
18232
+ }
18233
+ if (content[i] === '"') {
18234
+ inQuotes = !inQuotes;
18235
+ i++;
18236
+ continue;
18237
+ }
18238
+ if (content[i] === char && !inQuotes)
18239
+ return i;
18240
+ i++;
18241
+ }
18242
+ return -1;
18243
+ }
18244
+ var ToonDecodeError = class extends SyntaxError {
18245
+ constructor(message, context) {
18246
+ const prefix = context?.line !== undefined ? `Line ${context.line}: ` : "";
18247
+ super(prefix + message, context?.cause !== undefined ? { cause: context.cause } : undefined);
18248
+ this.name = "ToonDecodeError";
18249
+ this.line = context?.line;
18250
+ this.source = context?.source;
18251
+ }
18252
+ };
18253
+ function withLine(line, fn) {
18254
+ try {
18255
+ return fn();
18256
+ } catch (error) {
18257
+ if (error instanceof ToonDecodeError)
18258
+ throw error;
18259
+ if (error instanceof Error)
18260
+ throw new ToonDecodeError(error.message, {
18261
+ line: line.lineNumber,
18262
+ source: line.raw,
18263
+ cause: error
18264
+ });
18265
+ throw error;
18266
+ }
18267
+ }
18268
+ var LEADING_WHITESPACE_PATTERN = /^[ \t]*/;
18269
+ function createScanState() {
18270
+ return {
18271
+ lineNumber: 0,
18272
+ blankLines: []
18273
+ };
18274
+ }
18275
+ function parseLineIncremental(raw, state, indentSize, strict) {
18276
+ state.lineNumber++;
18277
+ const lineNumber = state.lineNumber;
18278
+ if (lineNumber === 1 && raw[0] === "\uFEFF")
18279
+ raw = raw.slice(1);
18280
+ if (raw[raw.length - 1] === "\r")
18281
+ raw = raw.slice(0, -1);
18282
+ const leadingWhitespace = LEADING_WHITESPACE_PATTERN.exec(raw)[0];
18283
+ const firstTabIndex = leadingWhitespace.indexOf("\t");
18284
+ const indent = strict && firstTabIndex !== -1 ? firstTabIndex : leadingWhitespace.length;
18285
+ const tabIndent = strict || firstTabIndex === -1 ? 0 : leadingWhitespace.split("\t").length - 1;
18286
+ const content = trimTrailingSpaces(raw.slice(indent));
18287
+ if (firstTabIndex === -1 && content[0] === "#")
18288
+ return;
18289
+ const depth = computeDepthFromIndent(indent - tabIndent, indentSize) + tabIndent;
18290
+ if (!content) {
18291
+ state.blankLines.push({
18292
+ lineNumber,
18293
+ indent,
18294
+ depth
18295
+ });
18296
+ return;
18297
+ }
18298
+ if (strict) {
18299
+ if (firstTabIndex !== -1)
18300
+ throw new ToonDecodeError("Tabs are not allowed in indentation in strict mode", {
18301
+ line: lineNumber,
18302
+ source: raw
18303
+ });
18304
+ if (indent > 0 && indent % indentSize !== 0)
18305
+ throw new ToonDecodeError(`Indentation must be exact multiple of ${indentSize}, but found ${indent} spaces`, {
18306
+ line: lineNumber,
18307
+ source: raw
18308
+ });
18309
+ }
18310
+ return {
18311
+ raw,
18312
+ indent,
18313
+ content,
18314
+ depth,
18315
+ lineNumber
18316
+ };
18317
+ }
18318
+ function computeDepthFromIndent(indentSpaces, indentSize) {
18319
+ return Math.floor(indentSpaces / indentSize);
18320
+ }
18321
+ function trimTrailingSpaces(value) {
18322
+ let end = value.length;
18323
+ while (end > 0 && value[end - 1] === " ")
18324
+ end--;
18325
+ return end === value.length ? value : value.slice(0, end);
18326
+ }
18149
18327
  var FETCH_LINE = Symbol("fetch-line");
18328
+ function createLineReader(context) {
18329
+ return {
18330
+ buffer: [],
18331
+ done: false,
18332
+ lastLine: undefined,
18333
+ scanState: createScanState(),
18334
+ indentSize: context.indentSize,
18335
+ strict: context.strict
18336
+ };
18337
+ }
18338
+ function* fillBuffer(reader) {
18339
+ while (reader.buffer.length === 0 && !reader.done) {
18340
+ const raw = yield FETCH_LINE;
18341
+ if (raw === undefined) {
18342
+ reader.done = true;
18343
+ return;
18344
+ }
18345
+ const parsedLine = parseLineIncremental(raw, reader.scanState, reader.indentSize, reader.strict);
18346
+ if (parsedLine !== undefined)
18347
+ reader.buffer.push(parsedLine);
18348
+ }
18349
+ }
18350
+ function* peekLine(reader) {
18351
+ yield* fillBuffer(reader);
18352
+ return reader.buffer[0];
18353
+ }
18354
+ function* readLine(reader) {
18355
+ yield* fillBuffer(reader);
18356
+ const line = reader.buffer[0];
18357
+ if (line !== undefined) {
18358
+ reader.buffer.shift();
18359
+ reader.lastLine = line;
18360
+ }
18361
+ return line;
18362
+ }
18363
+ function* driveSync(rawSource, rule) {
18364
+ const iterator = rawSource[Symbol.iterator]();
18365
+ let step = rule.next();
18366
+ while (!step.done)
18367
+ if (step.value === FETCH_LINE) {
18368
+ const result = iterator.next();
18369
+ step = rule.next(result.done ? undefined : result.value);
18370
+ } else {
18371
+ yield step.value;
18372
+ step = rule.next();
18373
+ }
18374
+ }
18375
+ var NUMERIC_LITERAL_PATTERN = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:e[+-]?\d+)?$/i;
18150
18376
  function isBooleanOrNullLiteral(token) {
18151
18377
  return token === "true" || token === "false" || token === "null";
18152
18378
  }
18379
+ function isNumericLiteral(token) {
18380
+ if (!token)
18381
+ return false;
18382
+ if (!NUMERIC_LITERAL_PATTERN.test(token))
18383
+ return false;
18384
+ const numericValue = Number(token);
18385
+ return !Number.isNaN(numericValue) && Number.isFinite(numericValue);
18386
+ }
18387
+ function parseArrayHeaderLine(content, defaultDelimiter) {
18388
+ const trimmedToken = content.trimStart();
18389
+ let bracketStart = -1;
18390
+ if (trimmedToken.startsWith('"')) {
18391
+ const closingQuoteIndex = findClosingQuote(trimmedToken, 0);
18392
+ if (closingQuoteIndex === -1)
18393
+ return { kind: "notHeader" };
18394
+ if (!trimmedToken.slice(closingQuoteIndex + 1).startsWith("["))
18395
+ return { kind: "notHeader" };
18396
+ const keyEndIndex = content.length - trimmedToken.length + closingQuoteIndex + 1;
18397
+ bracketStart = content.indexOf("[", keyEndIndex);
18398
+ } else
18399
+ bracketStart = findUnquotedChar(content, "[");
18400
+ if (bracketStart === -1)
18401
+ return { kind: "notHeader" };
18402
+ const firstColonIndex = findUnquotedChar(content, ":");
18403
+ if (firstColonIndex !== -1 && firstColonIndex < bracketStart)
18404
+ return { kind: "notHeader" };
18405
+ const bracketEnd = findUnquotedChar(content, "]", bracketStart);
18406
+ if (bracketEnd === -1)
18407
+ return { kind: "notHeader" };
18408
+ let colonIndex = bracketEnd + 1;
18409
+ let braceEnd = colonIndex;
18410
+ const braceStart = findUnquotedChar(content, "{", bracketEnd);
18411
+ if (braceStart !== -1 && braceStart < findUnquotedChar(content, ":", bracketEnd)) {
18412
+ const gapBeforeBrace = content.slice(bracketEnd + 1, braceStart);
18413
+ if (gapBeforeBrace !== "") {
18414
+ const trimmedGap = gapBeforeBrace.trim();
18415
+ return {
18416
+ kind: "invalid",
18417
+ reason: trimmedGap === "" ? `Unexpected whitespace between bracket segment and field list` : `Unexpected content "${trimmedGap}" between bracket segment and field list`
18418
+ };
18419
+ }
18420
+ const foundBraceEnd = findMatchingBrace(content, braceStart);
18421
+ if (foundBraceEnd !== -1)
18422
+ braceEnd = foundBraceEnd + 1;
18423
+ }
18424
+ colonIndex = findUnquotedChar(content, ":", Math.max(bracketEnd, braceEnd));
18425
+ if (colonIndex === -1)
18426
+ return { kind: "notHeader" };
18427
+ const gapStart = Math.max(bracketEnd + 1, braceEnd);
18428
+ const gapBeforeColon = content.slice(gapStart, colonIndex);
18429
+ if (gapBeforeColon !== "") {
18430
+ const trimmedGap = gapBeforeColon.trim();
18431
+ return {
18432
+ kind: "invalid",
18433
+ reason: trimmedGap === "" ? `Unexpected whitespace between bracket segment and colon` : `Unexpected content "${trimmedGap}" between bracket segment and colon`
18434
+ };
18435
+ }
18436
+ let key;
18437
+ if (bracketStart > 0) {
18438
+ const rawKey = content.slice(0, bracketStart);
18439
+ if (rawKey !== rawKey.trimEnd())
18440
+ return {
18441
+ kind: "invalid",
18442
+ reason: "Unexpected whitespace between key and bracket segment"
18443
+ };
18444
+ key = rawKey.startsWith('"') ? parseStringLiteral(rawKey) : rawKey;
18445
+ }
18446
+ const afterColon = trimSpaces(content.slice(colonIndex + 1));
18447
+ const bracketContent = content.slice(bracketStart + 1, bracketEnd);
18448
+ let parsedBracket;
18449
+ try {
18450
+ parsedBracket = parseBracketSegment(bracketContent, defaultDelimiter);
18451
+ } catch (error) {
18452
+ return {
18453
+ kind: "invalid",
18454
+ reason: error.message
18455
+ };
18456
+ }
18457
+ const { length, delimiter, keyed } = parsedBracket;
18458
+ let fields;
18459
+ if (braceStart !== -1 && braceStart < colonIndex) {
18460
+ const foundBraceEnd = findMatchingBrace(content, braceStart);
18461
+ if (foundBraceEnd !== -1 && foundBraceEnd < colonIndex) {
18462
+ const fieldsContent = content.slice(braceStart + 1, foundBraceEnd);
18463
+ const mismatchedDelimiter = findUnquotedMismatchedDelimiter(fieldsContent, delimiter);
18464
+ if (mismatchedDelimiter !== undefined)
18465
+ return {
18466
+ kind: "invalid",
18467
+ reason: `Header delimiter mismatch: bracket declares "${formatDelimiter(delimiter)}" but field list contains unquoted "${formatDelimiter(mismatchedDelimiter)}"`
18468
+ };
18469
+ try {
18470
+ fields = parseFieldEntries(fieldsContent, delimiter);
18471
+ } catch (error) {
18472
+ return {
18473
+ kind: "invalid",
18474
+ reason: error.message
18475
+ };
18476
+ }
18477
+ }
18478
+ }
18479
+ const duplicateFieldName = fields ? findDuplicateFieldName(fields) : undefined;
18480
+ const duplicateReason = duplicateFieldName ? `Duplicate field name "${duplicateFieldName}" in field list` : undefined;
18481
+ if (keyed && !fields)
18482
+ return {
18483
+ kind: "invalid",
18484
+ reason: "Keyed header requires a field list"
18485
+ };
18486
+ if (fields && afterColon)
18487
+ return {
18488
+ kind: "invalid",
18489
+ reason: duplicateReason ?? "Unexpected content after fields-bearing header colon"
18490
+ };
18491
+ return {
18492
+ kind: "header",
18493
+ header: {
18494
+ key,
18495
+ length,
18496
+ delimiter,
18497
+ fields,
18498
+ keyed
18499
+ },
18500
+ inlineValues: afterColon || undefined,
18501
+ strictError: duplicateReason
18502
+ };
18503
+ }
18504
+ var BRACKET_LENGTH_PATTERN = /^(?:0|[1-9]\d*)$/;
18505
+ function parseBracketSegment(seg, defaultDelimiter) {
18506
+ let content = seg;
18507
+ let delimiter = defaultDelimiter;
18508
+ if (content.endsWith("\t")) {
18509
+ delimiter = DELIMITERS.tab;
18510
+ content = content.slice(0, -1);
18511
+ } else if (content.endsWith("|")) {
18512
+ delimiter = DELIMITERS.pipe;
18513
+ content = content.slice(0, -1);
18514
+ }
18515
+ let keyed = false;
18516
+ if (content.endsWith(":")) {
18517
+ keyed = true;
18518
+ content = content.slice(0, -1);
18519
+ }
18520
+ if (!BRACKET_LENGTH_PATTERN.test(content))
18521
+ throw new SyntaxError(`Invalid array length: "${seg}" (expected non-negative integer with no leading zeros)`);
18522
+ return {
18523
+ length: Number.parseInt(content, 10),
18524
+ delimiter,
18525
+ keyed
18526
+ };
18527
+ }
18528
+ function parseFieldEntries(fieldsContent, delimiter) {
18529
+ return splitFieldEntries(fieldsContent, delimiter).map((entry) => {
18530
+ const trimmedEntry = trimSpaces(entry);
18531
+ if (!trimmedEntry)
18532
+ throw new SyntaxError("Empty field name in field list");
18533
+ const groupStart = findUnquotedChar(trimmedEntry, "{");
18534
+ if (groupStart === -1)
18535
+ return { name: parseStringLiteral(trimmedEntry) };
18536
+ const namePart = trimSpaces(trimmedEntry.slice(0, groupStart));
18537
+ if (!namePart)
18538
+ throw new SyntaxError("Missing field name before nested field group");
18539
+ const groupEnd = findMatchingBrace(trimmedEntry, groupStart);
18540
+ if (groupEnd === -1)
18541
+ throw new SyntaxError("Unmatched brace in field list");
18542
+ if (groupEnd !== trimmedEntry.length - 1)
18543
+ throw new SyntaxError("Unexpected content after nested field group");
18544
+ const children = parseFieldEntries(trimmedEntry.slice(groupStart + 1, groupEnd), delimiter);
18545
+ return {
18546
+ name: parseStringLiteral(namePart),
18547
+ children
18548
+ };
18549
+ });
18550
+ }
18551
+ function splitFieldEntries(content, delimiter) {
18552
+ const entries = [];
18553
+ let entryBuffer = "";
18554
+ let inQuotes = false;
18555
+ let braceDepth = 0;
18556
+ let i = 0;
18557
+ while (i < content.length) {
18558
+ const char = content[i];
18559
+ if (char === "\\" && i + 1 < content.length && inQuotes) {
18560
+ entryBuffer += char + content[i + 1];
18561
+ i += 2;
18562
+ continue;
18563
+ }
18564
+ if (char === '"') {
18565
+ inQuotes = !inQuotes;
18566
+ entryBuffer += char;
18567
+ i++;
18568
+ continue;
18569
+ }
18570
+ if (!inQuotes) {
18571
+ if (char === "{")
18572
+ braceDepth++;
18573
+ else if (char === "}")
18574
+ braceDepth--;
18575
+ else if (char === delimiter && braceDepth === 0) {
18576
+ entries.push(entryBuffer);
18577
+ entryBuffer = "";
18578
+ i++;
18579
+ continue;
18580
+ }
18581
+ }
18582
+ entryBuffer += char;
18583
+ i++;
18584
+ }
18585
+ entries.push(entryBuffer);
18586
+ return entries;
18587
+ }
18588
+ function findMatchingBrace(content, braceStart) {
18589
+ let inQuotes = false;
18590
+ let braceDepth = 0;
18591
+ let i = braceStart;
18592
+ while (i < content.length) {
18593
+ const char = content[i];
18594
+ if (char === "\\" && i + 1 < content.length && inQuotes) {
18595
+ i += 2;
18596
+ continue;
18597
+ }
18598
+ if (char === '"') {
18599
+ inQuotes = !inQuotes;
18600
+ i++;
18601
+ continue;
18602
+ }
18603
+ if (!inQuotes) {
18604
+ if (char === "{")
18605
+ braceDepth++;
18606
+ else if (char === "}") {
18607
+ braceDepth--;
18608
+ if (braceDepth === 0)
18609
+ return i;
18610
+ }
18611
+ }
18612
+ i++;
18613
+ }
18614
+ return -1;
18615
+ }
18616
+ function findDuplicateFieldName(fields) {
18617
+ const seenNames = /* @__PURE__ */ new Set;
18618
+ for (const field of fields) {
18619
+ if (seenNames.has(field.name))
18620
+ return field.name;
18621
+ seenNames.add(field.name);
18622
+ if (field.children) {
18623
+ const nestedDuplicate = findDuplicateFieldName(field.children);
18624
+ if (nestedDuplicate !== undefined)
18625
+ return nestedDuplicate;
18626
+ }
18627
+ }
18628
+ }
18629
+ function countLeafFields(fields) {
18630
+ let leafCount = 0;
18631
+ for (const field of fields)
18632
+ leafCount += field.children ? countLeafFields(field.children) : 1;
18633
+ return leafCount;
18634
+ }
18635
+ var DELIMITER_CANDIDATES = [
18636
+ ",",
18637
+ "\t",
18638
+ "|"
18639
+ ];
18640
+ function findUnquotedMismatchedDelimiter(content, activeDelimiter) {
18641
+ for (const candidate of DELIMITER_CANDIDATES) {
18642
+ if (candidate === activeDelimiter)
18643
+ continue;
18644
+ if (findUnquotedChar(content, candidate) !== -1)
18645
+ return candidate;
18646
+ }
18647
+ }
18648
+ function formatDelimiter(delimiter) {
18649
+ if (delimiter === "\t")
18650
+ return "\\t";
18651
+ return delimiter;
18652
+ }
18653
+ function parseDelimitedValues(input, delimiter) {
18654
+ const values = [];
18655
+ let valueBuffer = "";
18656
+ let inQuotes = false;
18657
+ let i = 0;
18658
+ while (i < input.length) {
18659
+ const char = input[i];
18660
+ if (char === "\\" && i + 1 < input.length && inQuotes) {
18661
+ valueBuffer += char + input[i + 1];
18662
+ i += 2;
18663
+ continue;
18664
+ }
18665
+ if (char === '"') {
18666
+ inQuotes = !inQuotes;
18667
+ valueBuffer += char;
18668
+ i++;
18669
+ continue;
18670
+ }
18671
+ if (char === delimiter && !inQuotes) {
18672
+ values.push(trimSpaces(valueBuffer));
18673
+ valueBuffer = "";
18674
+ i++;
18675
+ continue;
18676
+ }
18677
+ valueBuffer += char;
18678
+ i++;
18679
+ }
18680
+ if (valueBuffer || values.length > 0)
18681
+ values.push(trimSpaces(valueBuffer));
18682
+ return values;
18683
+ }
18684
+ function mapRowValuesToPrimitives(values) {
18685
+ return values.map((v) => parsePrimitiveToken(v));
18686
+ }
18687
+ function parsePrimitiveToken(token) {
18688
+ const trimmedToken = trimSpaces(token);
18689
+ if (!trimmedToken)
18690
+ return "";
18691
+ if (trimmedToken.startsWith('"'))
18692
+ return parseStringLiteral(trimmedToken);
18693
+ if (isBooleanOrNullLiteral(trimmedToken)) {
18694
+ if (trimmedToken === "true")
18695
+ return true;
18696
+ if (trimmedToken === "false")
18697
+ return false;
18698
+ if (trimmedToken === "null")
18699
+ return null;
18700
+ }
18701
+ if (isNumericLiteral(trimmedToken)) {
18702
+ const parsedNumber = Number.parseFloat(trimmedToken);
18703
+ return Object.is(parsedNumber, -0) ? 0 : parsedNumber;
18704
+ }
18705
+ return trimmedToken;
18706
+ }
18707
+ function parseStringLiteral(token) {
18708
+ const trimmedToken = trimSpaces(token);
18709
+ if (trimmedToken.startsWith('"')) {
18710
+ const closingQuoteIndex = findClosingQuote(trimmedToken, 0);
18711
+ if (closingQuoteIndex === -1)
18712
+ throw new SyntaxError("Unterminated string: missing closing quote");
18713
+ if (closingQuoteIndex !== trimmedToken.length - 1)
18714
+ throw new SyntaxError("Unexpected characters after closing quote");
18715
+ return unescapeString(trimmedToken.slice(1, closingQuoteIndex));
18716
+ }
18717
+ return trimmedToken;
18718
+ }
18719
+ function parseUnquotedKey(content, start) {
18720
+ const colonIndex = findUnquotedChar(content, ":", start);
18721
+ if (colonIndex === -1)
18722
+ throw new SyntaxError("Missing colon after key");
18723
+ return {
18724
+ key: trimSpaces(content.slice(start, colonIndex)),
18725
+ end: colonIndex + 1
18726
+ };
18727
+ }
18728
+ function parseQuotedKey(content, start) {
18729
+ const closingQuoteIndex = findClosingQuote(content, start);
18730
+ if (closingQuoteIndex === -1)
18731
+ throw new SyntaxError("Unterminated quoted key");
18732
+ const key = unescapeString(content.slice(start + 1, closingQuoteIndex));
18733
+ let parsePosition = closingQuoteIndex + 1;
18734
+ if (parsePosition >= content.length || content[parsePosition] !== ":")
18735
+ throw new SyntaxError("Missing colon after key");
18736
+ parsePosition++;
18737
+ return {
18738
+ key,
18739
+ end: parsePosition
18740
+ };
18741
+ }
18742
+ function parseKeyToken(content, start) {
18743
+ return content[start] === '"' ? parseQuotedKey(content, start) : parseUnquotedKey(content, start);
18744
+ }
18745
+ function isArrayHeaderContent(content) {
18746
+ return content.trim().startsWith("[") && findUnquotedChar(content, ":") !== -1;
18747
+ }
18748
+ function isKeyValueContent(content) {
18749
+ return findUnquotedChar(content, ":") !== -1;
18750
+ }
18751
+ function assertExpectedCount(actual, expected, itemType, options, line) {
18752
+ if (options.strict && actual !== expected)
18753
+ throw new ToonDecodeError(`Expected ${expected} ${itemType}, but got ${actual}`, {
18754
+ line: line.lineNumber,
18755
+ source: line.raw
18756
+ });
18757
+ }
18758
+ function validateNoExtraListItems(nextLine, itemDepth, expectedCount) {
18759
+ if (nextLine?.depth === itemDepth && nextLine.content.startsWith("- "))
18760
+ throw new ToonDecodeError(`Expected ${expectedCount} list-form items, but found more`, {
18761
+ line: nextLine.lineNumber,
18762
+ source: nextLine.raw
18763
+ });
18764
+ }
18765
+ function validateNoExtraTabularRows(nextLine, rowDepth, header) {
18766
+ if (nextLine?.depth === rowDepth && !nextLine.content.startsWith("- ") && isDataRow(nextLine.content, header.delimiter))
18767
+ throw new ToonDecodeError(`Expected ${header.length} tabular rows, but found more`, {
18768
+ line: nextLine.lineNumber,
18769
+ source: nextLine.raw
18770
+ });
18771
+ }
18772
+ function validateNoBlankLinesInRange(startLine, endLine, blankLines, strict, context) {
18773
+ if (!strict)
18774
+ return;
18775
+ const firstBlank = blankLines.find((blank) => blank.lineNumber > startLine && blank.lineNumber < endLine);
18776
+ if (firstBlank)
18777
+ throw new ToonDecodeError(`Blank lines inside ${context} are not allowed in strict mode`, { line: firstBlank.lineNumber });
18778
+ }
18779
+ function isDataRow(content, delimiter) {
18780
+ const colonPos = findUnquotedChar(content, ":");
18781
+ const delimiterPos = findUnquotedChar(content, delimiter);
18782
+ if (colonPos === -1)
18783
+ return true;
18784
+ if (delimiterPos !== -1 && delimiterPos < colonPos)
18785
+ return true;
18786
+ return false;
18787
+ }
18788
+ function resolveContext(options) {
18789
+ return {
18790
+ indentSize: options?.indentSize ?? options?.indent ?? 2,
18791
+ strict: options?.strict ?? true
18792
+ };
18793
+ }
18794
+ function decodeStreamSync$1(source, options) {
18795
+ const resolvedOptions = resolveContext(options);
18796
+ return driveSync(source, decodeDocument(createLineReader(resolvedOptions), resolvedOptions));
18797
+ }
18798
+ function* decodeDocument(reader, options) {
18799
+ const first = yield* peekLine(reader);
18800
+ if (!first) {
18801
+ yield { type: "startObject" };
18802
+ yield { type: "endObject" };
18803
+ return;
18804
+ }
18805
+ if (trimSpaces(first.content) === "[]") {
18806
+ yield* readLine(reader);
18807
+ yield {
18808
+ type: "startArray",
18809
+ length: 0
18810
+ };
18811
+ yield { type: "endArray" };
18812
+ yield* assertFullyConsumed(reader, options.strict);
18813
+ return;
18814
+ }
18815
+ if (isArrayHeaderContent(first.content)) {
18816
+ const headerInfo = withLine(first, () => resolveArrayHeader(parseArrayHeaderLine(first.content, DEFAULT_DELIMITER), options.strict));
18817
+ if (headerInfo) {
18818
+ yield* readLine(reader);
18819
+ yield* decodeArrayFromHeader(headerInfo.header, headerInfo.inlineValues, reader, 0, options, first);
18820
+ yield* assertFullyConsumed(reader, options.strict);
18821
+ return;
18822
+ }
18823
+ }
18824
+ yield* readLine(reader);
18825
+ const following = yield* peekLine(reader);
18826
+ if (!(following !== undefined) && !isKeyValueLine(first)) {
18827
+ yield {
18828
+ type: "primitive",
18829
+ value: withLine(first, () => parsePrimitiveToken(first.content))
18830
+ };
18831
+ return;
18832
+ }
18833
+ if (!isKeyValueLine(first) && following?.depth === 0)
18834
+ throw new ToonDecodeError("Top-level document must start with a key-value or array-header line", {
18835
+ line: first.lineNumber,
18836
+ source: first.raw
18837
+ });
18838
+ const rootSeenKeys = options.strict ? /* @__PURE__ */ new Set : undefined;
18839
+ yield { type: "startObject" };
18840
+ yield* decodeKeyValue(first, reader, 0, options, rootSeenKeys);
18841
+ while (true) {
18842
+ const line = yield* peekLine(reader);
18843
+ if (!line)
18844
+ break;
18845
+ if (line.depth !== 0) {
18846
+ if (options.strict)
18847
+ throw overIndentedLineError(line, 0);
18848
+ assertNotScalarLine(line);
18849
+ yield* readLine(reader);
18850
+ continue;
18851
+ }
18852
+ yield* readLine(reader);
18853
+ yield* decodeKeyValue(line, reader, 0, options, rootSeenKeys);
18854
+ }
18855
+ yield { type: "endObject" };
18856
+ }
18857
+ function assertNoDepthJump(firstNestedLine, parentDepth, strict) {
18858
+ if (strict && firstNestedLine.depth > parentDepth + 1)
18859
+ throw new ToonDecodeError(`Indentation depth jump: expected depth ${parentDepth + 1}, but found ${firstNestedLine.depth}`, {
18860
+ line: firstNestedLine.lineNumber,
18861
+ source: firstNestedLine.raw
18862
+ });
18863
+ }
18864
+ function overIndentedLineError(line, expectedDepth) {
18865
+ return new ToonDecodeError(`Over-indented line: expected depth ${expectedDepth}, but found ${line.depth}`, {
18866
+ line: line.lineNumber,
18867
+ source: line.raw
18868
+ });
18869
+ }
18870
+ function assertNotScalarLine(line) {
18871
+ if (line.content.startsWith("- ") || line.content === "-" || findUnquotedChar(line.content, ":") !== -1)
18872
+ return;
18873
+ throw new ToonDecodeError("Unexpected bare token line outside root primitive position", {
18874
+ line: line.lineNumber,
18875
+ source: line.raw
18876
+ });
18877
+ }
18878
+ function keylessKeyedError(line) {
18879
+ return new ToonDecodeError("Keyless keyed header is only valid at the document root", {
18880
+ line: line.lineNumber,
18881
+ source: line.raw
18882
+ });
18883
+ }
18884
+ function keylessHeaderError(line) {
18885
+ return new ToonDecodeError("Keyless array header is only valid at the document root or as a list item", {
18886
+ line: line.lineNumber,
18887
+ source: line.raw
18888
+ });
18889
+ }
18890
+ function keylessFieldsHeaderError(line) {
18891
+ return new ToonDecodeError("Keyless header with a field list is only valid at the document root", {
18892
+ line: line.lineNumber,
18893
+ source: line.raw
18894
+ });
18895
+ }
18896
+ function* assertFullyConsumed(reader, strict) {
18897
+ if (!strict)
18898
+ return;
18899
+ const line = yield* peekLine(reader);
18900
+ if (line)
18901
+ throw new ToonDecodeError("Unexpected content after the document root", {
18902
+ line: line.lineNumber,
18903
+ source: line.raw
18904
+ });
18905
+ }
18906
+ function assertNoDuplicateKey(key, line, seenKeys) {
18907
+ if (!seenKeys)
18908
+ return;
18909
+ if (seenKeys.has(key))
18910
+ throw new ToonDecodeError(`Duplicate sibling key "${key}"`, {
18911
+ line: line.lineNumber,
18912
+ source: line.raw
18913
+ });
18914
+ seenKeys.add(key);
18915
+ }
18916
+ function* decodeKeyValue(line, reader, baseDepth, options, seenKeys) {
18917
+ const content = line.content;
18918
+ const arrayHeader = withLine(line, () => resolveArrayHeader(parseArrayHeaderLine(content, DEFAULT_DELIMITER), options.strict));
18919
+ if (arrayHeader && arrayHeader.header.key !== undefined) {
18920
+ assertNoDuplicateKey(arrayHeader.header.key, line, seenKeys);
18921
+ yield {
18922
+ type: "key",
18923
+ key: arrayHeader.header.key
18924
+ };
18925
+ yield* decodeArrayFromHeader(arrayHeader.header, arrayHeader.inlineValues, reader, baseDepth, options, line);
18926
+ return;
18927
+ }
18928
+ if (arrayHeader && arrayHeader.header.key === undefined && options.strict)
18929
+ throw arrayHeader.header.keyed ? keylessKeyedError(line) : keylessHeaderError(line);
18930
+ const { key, end } = withLine(line, () => parseKeyToken(content, 0));
18931
+ const rest = trimSpaces(content.slice(end));
18932
+ assertNoDuplicateKey(key, line, seenKeys);
18933
+ yield {
18934
+ type: "key",
18935
+ key
18936
+ };
18937
+ if (!rest) {
18938
+ const nextLine = yield* peekLine(reader);
18939
+ if (nextLine && nextLine.depth > baseDepth) {
18940
+ assertNoDepthJump(nextLine, baseDepth, options.strict);
18941
+ yield { type: "startObject" };
18942
+ yield* decodeObjectFields(reader, baseDepth + 1, options);
18943
+ yield { type: "endObject" };
18944
+ return;
18945
+ }
18946
+ yield { type: "startObject" };
18947
+ yield { type: "endObject" };
18948
+ return;
18949
+ }
18950
+ if (rest === "[]") {
18951
+ yield {
18952
+ type: "startArray",
18953
+ length: 0
18954
+ };
18955
+ yield { type: "endArray" };
18956
+ return;
18957
+ }
18958
+ yield {
18959
+ type: "primitive",
18960
+ value: withLine(line, () => parsePrimitiveToken(rest))
18961
+ };
18962
+ }
18963
+ function* decodeObjectFields(reader, baseDepth, options) {
18964
+ let computedDepth;
18965
+ const seenKeys = options.strict ? /* @__PURE__ */ new Set : undefined;
18966
+ while (true) {
18967
+ const line = yield* peekLine(reader);
18968
+ if (!line || line.depth < baseDepth)
18969
+ break;
18970
+ if (computedDepth === undefined && line.depth >= baseDepth)
18971
+ computedDepth = line.depth;
18972
+ if (line.depth === computedDepth) {
18973
+ yield* readLine(reader);
18974
+ yield* decodeKeyValue(line, reader, computedDepth, options, seenKeys);
18975
+ } else if (computedDepth !== undefined && line.depth > computedDepth) {
18976
+ if (options.strict)
18977
+ throw overIndentedLineError(line, computedDepth);
18978
+ assertNotScalarLine(line);
18979
+ yield* readLine(reader);
18980
+ } else
18981
+ break;
18982
+ }
18983
+ }
18984
+ function* decodeArrayFromHeader(header, inlineValues, reader, baseDepth, options, headerLine) {
18985
+ if (header.keyed) {
18986
+ yield* decodeKeyedObject(header, reader, baseDepth, options, headerLine);
18987
+ return;
18988
+ }
18989
+ yield {
18990
+ type: "startArray",
18991
+ length: header.length
18992
+ };
18993
+ if (inlineValues) {
18994
+ yield* decodeInlinePrimitiveArray(header, inlineValues, options, headerLine);
18995
+ yield { type: "endArray" };
18996
+ return;
18997
+ }
18998
+ if (header.fields && header.fields.length > 0) {
18999
+ yield* decodeTabularArray(header, reader, baseDepth, options, headerLine);
19000
+ yield { type: "endArray" };
19001
+ return;
19002
+ }
19003
+ yield* decodeListArray(header, reader, baseDepth, options, headerLine);
19004
+ yield { type: "endArray" };
19005
+ }
19006
+ function* decodeInlinePrimitiveArray(header, inlineValues, options, headerLine) {
19007
+ if (!trimSpaces(inlineValues)) {
19008
+ assertExpectedCount(0, header.length, "inline-form values", options, headerLine);
19009
+ return;
19010
+ }
19011
+ const values = withLine(headerLine, () => parseDelimitedValues(inlineValues, header.delimiter));
19012
+ const primitives = withLine(headerLine, () => mapRowValuesToPrimitives(values));
19013
+ assertExpectedCount(primitives.length, header.length, "inline-form values", options, headerLine);
19014
+ for (const primitive of primitives)
19015
+ yield {
19016
+ type: "primitive",
19017
+ value: primitive
19018
+ };
19019
+ }
19020
+ function* decodeKeyedObject(header, reader, baseDepth, options, headerLine) {
19021
+ const entryDepth = baseDepth + 1;
19022
+ const leafFieldCount = countLeafFields(header.fields);
19023
+ const seenEntryKeys = options.strict ? /* @__PURE__ */ new Set : undefined;
19024
+ let entryCount = 0;
19025
+ let startLine;
19026
+ let endLine;
19027
+ let lastEntryLine = headerLine;
19028
+ yield { type: "startObject" };
19029
+ while (true) {
19030
+ const line = yield* peekLine(reader);
19031
+ if (!line || line.depth <= baseDepth)
19032
+ break;
19033
+ if (line.depth > entryDepth) {
19034
+ if (options.strict)
19035
+ throw new ToonDecodeError("Unexpected indentation inside keyed tabular object", {
19036
+ line: line.lineNumber,
19037
+ source: line.raw
19038
+ });
19039
+ yield* readLine(reader);
19040
+ continue;
19041
+ }
19042
+ if (findUnquotedChar(line.content, ":") === -1) {
19043
+ if (options.strict)
19044
+ throw new ToonDecodeError("Expected entry row inside keyed tabular object", {
19045
+ line: line.lineNumber,
19046
+ source: line.raw
19047
+ });
19048
+ yield* readLine(reader);
19049
+ continue;
19050
+ }
19051
+ yield* readLine(reader);
19052
+ if (startLine === undefined)
19053
+ startLine = line.lineNumber;
19054
+ endLine = line.lineNumber;
19055
+ lastEntryLine = line;
19056
+ const { key, end } = withLine(line, () => parseKeyToken(line.content, 0));
19057
+ assertNoDuplicateKey(key, line, seenEntryKeys);
19058
+ yield {
19059
+ type: "key",
19060
+ key
19061
+ };
19062
+ const cellsContent = trimSpaces(line.content.slice(end));
19063
+ const values = cellsContent === "" ? [] : withLine(line, () => parseDelimitedValues(cellsContent, header.delimiter));
19064
+ assertExpectedCount(values.length, leafFieldCount, "keyed entry cells", options, line);
19065
+ const primitives = withLine(line, () => mapRowValuesToPrimitives(values));
19066
+ yield* yieldObjectFromFields(header.fields, primitives);
19067
+ entryCount++;
19068
+ }
19069
+ assertExpectedCount(entryCount, header.length, "keyed entries", options, lastEntryLine);
19070
+ if (options.strict && startLine !== undefined && endLine !== undefined)
19071
+ validateNoBlankLinesInRange(startLine, endLine, reader.scanState.blankLines, options.strict, "keyed tabular object");
19072
+ yield { type: "endObject" };
19073
+ }
19074
+ function* decodeTabularArray(header, reader, baseDepth, options, headerLine) {
19075
+ const rowDepth = baseDepth + 1;
19076
+ let rowCount = 0;
19077
+ let startLine;
19078
+ let endLine;
19079
+ let lastRowLine = headerLine;
19080
+ while (!options.strict || rowCount < header.length) {
19081
+ const line = yield* peekLine(reader);
19082
+ if (!line || line.depth < rowDepth)
19083
+ break;
19084
+ if (line.depth === rowDepth) {
19085
+ if (!isDataRow(line.content, header.delimiter))
19086
+ break;
19087
+ if (startLine === undefined)
19088
+ startLine = line.lineNumber;
19089
+ endLine = line.lineNumber;
19090
+ lastRowLine = line;
19091
+ yield* readLine(reader);
19092
+ const values = withLine(line, () => parseDelimitedValues(line.content, header.delimiter));
19093
+ assertExpectedCount(values.length, countLeafFields(header.fields), "tabular row values", options, line);
19094
+ const primitives = withLine(line, () => mapRowValuesToPrimitives(values));
19095
+ yield* yieldObjectFromFields(header.fields, primitives);
19096
+ rowCount++;
19097
+ } else
19098
+ break;
19099
+ }
19100
+ assertExpectedCount(rowCount, header.length, "tabular rows", options, lastRowLine);
19101
+ if (options.strict && startLine !== undefined && endLine !== undefined)
19102
+ validateNoBlankLinesInRange(startLine, endLine, reader.scanState.blankLines, options.strict, "tabular array");
19103
+ if (options.strict)
19104
+ validateNoExtraTabularRows(yield* peekLine(reader), rowDepth, header);
19105
+ }
19106
+ function* decodeListArray(header, reader, baseDepth, options, headerLine) {
19107
+ const itemDepth = baseDepth + 1;
19108
+ let itemCount = 0;
19109
+ let startLine;
19110
+ let endLine;
19111
+ let lastItemLine = headerLine;
19112
+ while (!options.strict || itemCount < header.length) {
19113
+ const line = yield* peekLine(reader);
19114
+ if (!line || line.depth < itemDepth)
19115
+ break;
19116
+ const isListItem = line.content.startsWith("- ") || line.content === "-";
19117
+ if (line.depth === itemDepth && isListItem) {
19118
+ if (startLine === undefined)
19119
+ startLine = line.lineNumber;
19120
+ endLine = line.lineNumber;
19121
+ lastItemLine = line;
19122
+ yield* decodeListItem(reader, itemDepth, options);
19123
+ const lastConsumedLine = reader.lastLine;
19124
+ if (lastConsumedLine) {
19125
+ endLine = lastConsumedLine.lineNumber;
19126
+ lastItemLine = lastConsumedLine;
19127
+ }
19128
+ itemCount++;
19129
+ } else
19130
+ break;
19131
+ }
19132
+ assertExpectedCount(itemCount, header.length, "list-form items", options, lastItemLine);
19133
+ if (options.strict && startLine !== undefined && endLine !== undefined)
19134
+ validateNoBlankLinesInRange(startLine, endLine, reader.scanState.blankLines, options.strict, "list-form array");
19135
+ if (options.strict)
19136
+ validateNoExtraListItems(yield* peekLine(reader), itemDepth, header.length);
19137
+ }
19138
+ function* decodeListItem(reader, baseDepth, options) {
19139
+ const line = yield* readLine(reader);
19140
+ if (!line)
19141
+ throw new ReferenceError("Expected list item");
19142
+ let afterHyphen;
19143
+ if (line.content === "-") {
19144
+ yield { type: "startObject" };
19145
+ yield { type: "endObject" };
19146
+ return;
19147
+ } else if (line.content.startsWith("- "))
19148
+ afterHyphen = line.content.slice(2);
19149
+ else
19150
+ throw new ToonDecodeError(`Expected list item to start with "- "`, {
19151
+ line: line.lineNumber,
19152
+ source: line.raw
19153
+ });
19154
+ if (!trimSpaces(afterHyphen)) {
19155
+ yield { type: "startObject" };
19156
+ yield { type: "endObject" };
19157
+ return;
19158
+ }
19159
+ if (trimSpaces(afterHyphen) === "[]") {
19160
+ yield {
19161
+ type: "startArray",
19162
+ length: 0
19163
+ };
19164
+ yield { type: "endArray" };
19165
+ return;
19166
+ }
19167
+ const itemLine = {
19168
+ ...line,
19169
+ content: afterHyphen
19170
+ };
19171
+ if (isArrayHeaderContent(afterHyphen)) {
19172
+ const arrayHeader = withLine(itemLine, () => resolveArrayHeader(parseArrayHeaderLine(afterHyphen, DEFAULT_DELIMITER), options.strict));
19173
+ if (arrayHeader)
19174
+ if (arrayHeader.header.keyed || arrayHeader.header.fields !== undefined) {
19175
+ if (options.strict)
19176
+ throw arrayHeader.header.keyed ? keylessKeyedError(itemLine) : keylessFieldsHeaderError(itemLine);
19177
+ } else {
19178
+ yield* decodeArrayFromHeader(arrayHeader.header, arrayHeader.inlineValues, reader, baseDepth, options, itemLine);
19179
+ return;
19180
+ }
19181
+ }
19182
+ const headerInfo = withLine(itemLine, () => resolveArrayHeader(parseArrayHeaderLine(afterHyphen, DEFAULT_DELIMITER), options.strict));
19183
+ if (headerInfo && headerInfo.header.key !== undefined && headerInfo.header.fields !== undefined) {
19184
+ const header = headerInfo.header;
19185
+ const seenKeys = options.strict ? /* @__PURE__ */ new Set([header.key]) : undefined;
19186
+ yield { type: "startObject" };
19187
+ yield {
19188
+ type: "key",
19189
+ key: header.key
19190
+ };
19191
+ yield* decodeArrayFromHeader(header, headerInfo.inlineValues, reader, baseDepth + 1, options, itemLine);
19192
+ yield* followSiblingFields(reader, baseDepth + 1, options, seenKeys);
19193
+ yield { type: "endObject" };
19194
+ return;
19195
+ }
19196
+ if (isKeyValueContent(afterHyphen)) {
19197
+ const seenKeys = options.strict ? /* @__PURE__ */ new Set : undefined;
19198
+ yield { type: "startObject" };
19199
+ yield* decodeKeyValue(itemLine, reader, baseDepth + 1, options, seenKeys);
19200
+ yield* followSiblingFields(reader, baseDepth + 1, options, seenKeys);
19201
+ yield { type: "endObject" };
19202
+ return;
19203
+ }
19204
+ yield {
19205
+ type: "primitive",
19206
+ value: withLine(itemLine, () => parsePrimitiveToken(afterHyphen))
19207
+ };
19208
+ }
19209
+ function* followSiblingFields(reader, followDepth, options, seenKeys) {
19210
+ while (true) {
19211
+ const nextLine = yield* peekLine(reader);
19212
+ if (!nextLine || nextLine.depth < followDepth)
19213
+ break;
19214
+ if (nextLine.depth === followDepth && !nextLine.content.startsWith("- ")) {
19215
+ yield* readLine(reader);
19216
+ yield* decodeKeyValue(nextLine, reader, followDepth, options, seenKeys);
19217
+ } else
19218
+ break;
19219
+ }
19220
+ }
19221
+ function isKeyValueLine(line) {
19222
+ const content = line.content;
19223
+ if (content.startsWith('"')) {
19224
+ const closingQuoteIndex = findClosingQuote(content, 0);
19225
+ if (closingQuoteIndex === -1)
19226
+ return false;
19227
+ return content.slice(closingQuoteIndex + 1).includes(":");
19228
+ } else
19229
+ return content.includes(":");
19230
+ }
19231
+ function resolveArrayHeader(result, strict) {
19232
+ if (result.kind === "notHeader")
19233
+ return;
19234
+ if (result.kind === "invalid") {
19235
+ if (strict)
19236
+ throw new SyntaxError(result.reason);
19237
+ return;
19238
+ }
19239
+ if (strict && result.strictError !== undefined)
19240
+ throw new SyntaxError(result.strictError);
19241
+ return {
19242
+ header: result.header,
19243
+ inlineValues: result.inlineValues
19244
+ };
19245
+ }
19246
+ function* yieldObjectFromFields(fields, primitives) {
19247
+ let cellIndex = 0;
19248
+ function* walkFieldGroup(nodes) {
19249
+ yield { type: "startObject" };
19250
+ for (const node of nodes) {
19251
+ if (!node.children && cellIndex >= primitives.length)
19252
+ continue;
19253
+ yield {
19254
+ type: "key",
19255
+ key: node.name
19256
+ };
19257
+ if (node.children)
19258
+ yield* walkFieldGroup(node.children);
19259
+ else
19260
+ yield {
19261
+ type: "primitive",
19262
+ value: primitives[cellIndex++]
19263
+ };
19264
+ }
19265
+ yield { type: "endObject" };
19266
+ }
19267
+ yield* walkFieldGroup(fields);
19268
+ }
18153
19269
  function setOwnProperty(target, key, value) {
18154
19270
  if (key === "__proto__") {
18155
19271
  Object.defineProperty(target, key, {
@@ -18162,6 +19278,116 @@ function setOwnProperty(target, key, value) {
18162
19278
  }
18163
19279
  target[key] = value;
18164
19280
  }
19281
+ function buildValueFromEvents(events) {
19282
+ const state = {
19283
+ stack: [],
19284
+ root: undefined
19285
+ };
19286
+ for (const event of events)
19287
+ applyEvent(state, event);
19288
+ return finalizeState(state);
19289
+ }
19290
+ function applyEvent(state, event) {
19291
+ const { stack } = state;
19292
+ switch (event.type) {
19293
+ case "startObject": {
19294
+ const obj = {};
19295
+ if (stack.length === 0)
19296
+ stack.push({
19297
+ type: "object",
19298
+ obj
19299
+ });
19300
+ else {
19301
+ const parent = stack[stack.length - 1];
19302
+ if (parent.type === "object") {
19303
+ if (parent.currentKey === undefined)
19304
+ throw new Error("Object startObject event without preceding key");
19305
+ setOwnProperty(parent.obj, parent.currentKey, obj);
19306
+ parent.currentKey = undefined;
19307
+ } else if (parent.type === "array")
19308
+ parent.arr.push(obj);
19309
+ stack.push({
19310
+ type: "object",
19311
+ obj
19312
+ });
19313
+ }
19314
+ break;
19315
+ }
19316
+ case "endObject": {
19317
+ if (stack.length === 0)
19318
+ throw new Error("Unexpected endObject event");
19319
+ const context = stack.pop();
19320
+ if (context.type !== "object")
19321
+ throw new Error("Mismatched endObject event");
19322
+ if (stack.length === 0)
19323
+ state.root = context.obj;
19324
+ break;
19325
+ }
19326
+ case "startArray": {
19327
+ const arr = [];
19328
+ if (stack.length === 0)
19329
+ stack.push({
19330
+ type: "array",
19331
+ arr
19332
+ });
19333
+ else {
19334
+ const parent = stack[stack.length - 1];
19335
+ if (parent.type === "object") {
19336
+ if (parent.currentKey === undefined)
19337
+ throw new Error("Array startArray event without preceding key");
19338
+ setOwnProperty(parent.obj, parent.currentKey, arr);
19339
+ parent.currentKey = undefined;
19340
+ } else if (parent.type === "array")
19341
+ parent.arr.push(arr);
19342
+ stack.push({
19343
+ type: "array",
19344
+ arr
19345
+ });
19346
+ }
19347
+ break;
19348
+ }
19349
+ case "endArray": {
19350
+ if (stack.length === 0)
19351
+ throw new Error("Unexpected endArray event");
19352
+ const context = stack.pop();
19353
+ if (context.type !== "array")
19354
+ throw new Error("Mismatched endArray event");
19355
+ if (stack.length === 0)
19356
+ state.root = context.arr;
19357
+ break;
19358
+ }
19359
+ case "key": {
19360
+ if (stack.length === 0)
19361
+ throw new Error("Key event outside of object context");
19362
+ const parent = stack[stack.length - 1];
19363
+ if (parent.type !== "object")
19364
+ throw new Error("Key event outside of object context");
19365
+ parent.currentKey = event.key;
19366
+ break;
19367
+ }
19368
+ case "primitive":
19369
+ if (stack.length === 0)
19370
+ state.root = event.value;
19371
+ else {
19372
+ const parent = stack[stack.length - 1];
19373
+ if (parent.type === "object") {
19374
+ if (parent.currentKey === undefined)
19375
+ throw new Error("Primitive event without preceding key in object");
19376
+ setOwnProperty(parent.obj, parent.currentKey, event.value);
19377
+ parent.currentKey = undefined;
19378
+ } else if (parent.type === "array")
19379
+ parent.arr.push(event.value);
19380
+ }
19381
+ break;
19382
+ }
19383
+ }
19384
+ function finalizeState(state) {
19385
+ if (state.stack.length !== 0)
19386
+ throw new Error("Incomplete event stream: unclosed objects or arrays");
19387
+ if (state.root === undefined)
19388
+ throw new Error("No root value built from events");
19389
+ return state.root;
19390
+ }
18165
19391
  var COMMENT_LINE_PATTERN = new RegExp(`(?:^\uFEFF?|\\n) *#`);
18166
19392
  var RawString = class {
18167
19393
  constructor(value) {
@@ -18643,11 +19869,18 @@ function encode3(input, options) {
18643
19869
  return Array.from(encodeLines(input, options)).join(`
18644
19870
  `);
18645
19871
  }
19872
+ function decode3(input, options) {
19873
+ return decodeFromLines(input.split(`
19874
+ `), options);
19875
+ }
18646
19876
  function encodeLines(input, options) {
18647
19877
  const normalizedValue = normalizeValue(input);
18648
19878
  const resolvedOptions = resolveOptions(options);
18649
19879
  return encodeJsonValue(resolvedOptions.replacer ? applyReplacer(normalizedValue, resolvedOptions.replacer) : normalizedValue, resolvedOptions, 0);
18650
19880
  }
19881
+ function decodeFromLines(lines, options) {
19882
+ return buildValueFromEvents(decodeStreamSync$1(lines, resolveDecodeOptions(options)));
19883
+ }
18651
19884
  function resolveOptions(options) {
18652
19885
  const delimiter = options?.delimiter ?? DEFAULT_DELIMITER;
18653
19886
  assertValidDelimiter(delimiter);
@@ -18657,6 +19890,12 @@ function resolveOptions(options) {
18657
19890
  replacer: options?.replacer
18658
19891
  };
18659
19892
  }
19893
+ function resolveDecodeOptions(options) {
19894
+ return {
19895
+ indentSize: options?.indentSize ?? options?.indent ?? 2,
19896
+ strict: options?.strict ?? true
19897
+ };
19898
+ }
18660
19899
 
18661
19900
  // ../envoy-client/src/ask-answer.ts
18662
19901
  var HEAD_LENGTH = 120;
@@ -27586,7 +28825,7 @@ function decodeBase64(encoded) {
27586
28825
 
27587
28826
  // ../../node_modules/.bun/jose@6.2.9/node_modules/jose/dist/webapi/util/base64url.js
27588
28827
  var invalid = "The input to be decoded is not correctly encoded.";
27589
- function decode3(input) {
28828
+ function decode4(input) {
27590
28829
  if (Uint8Array.fromBase64) {
27591
28830
  try {
27592
28831
  return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
@@ -27780,7 +29019,7 @@ async function prepareKey(entry, key, usage) {
27780
29019
  case JWK: {
27781
29020
  const key = tagged[1];
27782
29021
  if (key.k) {
27783
- return decode3(key.k);
29022
+ return decode4(key.k);
27784
29023
  }
27785
29024
  if (!Object.isFrozen(key)) {
27786
29025
  const { key_ops } = key;