@mcpc-tech/cli 0.1.50 → 0.1.51

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.
Files changed (11) hide show
  1. package/app.cjs +463 -267
  2. package/app.mjs +463 -267
  3. package/bin/mcpc.cjs +443 -265
  4. package/bin/mcpc.mjs +443 -265
  5. package/bin.cjs +443 -265
  6. package/bin.mjs +443 -265
  7. package/index.cjs +463 -267
  8. package/index.mjs +463 -267
  9. package/package.json +1 -1
  10. package/server.cjs +463 -267
  11. package/server.mjs +463 -267
package/server.mjs CHANGED
@@ -3033,6 +3033,7 @@ data:
3033
3033
  async handleGetRequest(req) {
3034
3034
  const acceptHeader = req.headers.get("accept");
3035
3035
  if (!acceptHeader?.includes("text/event-stream")) {
3036
+ this.onerror?.(new Error("Not Acceptable: Client must accept text/event-stream"));
3036
3037
  return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept text/event-stream");
3037
3038
  }
3038
3039
  const sessionError = this.validateSession(req);
@@ -3050,6 +3051,7 @@ data:
3050
3051
  }
3051
3052
  }
3052
3053
  if (this._streamMapping.get(this._standaloneSseStreamId) !== void 0) {
3054
+ this.onerror?.(new Error("Conflict: Only one SSE stream is allowed per session"));
3053
3055
  return this.createJsonErrorResponse(409, -32e3, "Conflict: Only one SSE stream is allowed per session");
3054
3056
  }
3055
3057
  const encoder2 = new TextEncoder();
@@ -3089,6 +3091,7 @@ data:
3089
3091
  */
3090
3092
  async replayEvents(lastEventId) {
3091
3093
  if (!this._eventStore) {
3094
+ this.onerror?.(new Error("Event store not configured"));
3092
3095
  return this.createJsonErrorResponse(400, -32e3, "Event store not configured");
3093
3096
  }
3094
3097
  try {
@@ -3096,9 +3099,11 @@ data:
3096
3099
  if (this._eventStore.getStreamIdForEventId) {
3097
3100
  streamId = await this._eventStore.getStreamIdForEventId(lastEventId);
3098
3101
  if (!streamId) {
3102
+ this.onerror?.(new Error("Invalid event ID format"));
3099
3103
  return this.createJsonErrorResponse(400, -32e3, "Invalid event ID format");
3100
3104
  }
3101
3105
  if (this._streamMapping.get(streamId) !== void 0) {
3106
+ this.onerror?.(new Error("Conflict: Stream already has an active connection"));
3102
3107
  return this.createJsonErrorResponse(409, -32e3, "Conflict: Stream already has an active connection");
3103
3108
  }
3104
3109
  }
@@ -3164,7 +3169,8 @@ data:
3164
3169
  `;
3165
3170
  controller.enqueue(encoder2.encode(eventData));
3166
3171
  return true;
3167
- } catch {
3172
+ } catch (error) {
3173
+ this.onerror?.(error);
3168
3174
  return false;
3169
3175
  }
3170
3176
  }
@@ -3172,6 +3178,7 @@ data:
3172
3178
  * Handles unsupported requests (PUT, PATCH, etc.)
3173
3179
  */
3174
3180
  handleUnsupportedRequest() {
3181
+ this.onerror?.(new Error("Method not allowed."));
3175
3182
  return new Response(JSON.stringify({
3176
3183
  jsonrpc: "2.0",
3177
3184
  error: {
@@ -3194,14 +3201,17 @@ data:
3194
3201
  try {
3195
3202
  const acceptHeader = req.headers.get("accept");
3196
3203
  if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
3204
+ this.onerror?.(new Error("Not Acceptable: Client must accept both application/json and text/event-stream"));
3197
3205
  return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept both application/json and text/event-stream");
3198
3206
  }
3199
3207
  const ct = req.headers.get("content-type");
3200
3208
  if (!ct || !ct.includes("application/json")) {
3209
+ this.onerror?.(new Error("Unsupported Media Type: Content-Type must be application/json"));
3201
3210
  return this.createJsonErrorResponse(415, -32e3, "Unsupported Media Type: Content-Type must be application/json");
3202
3211
  }
3203
3212
  const requestInfo = {
3204
- headers: Object.fromEntries(req.headers.entries())
3213
+ headers: Object.fromEntries(req.headers.entries()),
3214
+ url: new URL(req.url)
3205
3215
  };
3206
3216
  let rawMessage;
3207
3217
  if (options?.parsedBody !== void 0) {
@@ -3210,6 +3220,7 @@ data:
3210
3220
  try {
3211
3221
  rawMessage = await req.json();
3212
3222
  } catch {
3223
+ this.onerror?.(new Error("Parse error: Invalid JSON"));
3213
3224
  return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON");
3214
3225
  }
3215
3226
  }
@@ -3221,14 +3232,17 @@ data:
3221
3232
  messages = [JSONRPCMessageSchema.parse(rawMessage)];
3222
3233
  }
3223
3234
  } catch {
3235
+ this.onerror?.(new Error("Parse error: Invalid JSON-RPC message"));
3224
3236
  return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON-RPC message");
3225
3237
  }
3226
3238
  const isInitializationRequest = messages.some(isInitializeRequest);
3227
3239
  if (isInitializationRequest) {
3228
3240
  if (this._initialized && this.sessionId !== void 0) {
3241
+ this.onerror?.(new Error("Invalid Request: Server already initialized"));
3229
3242
  return this.createJsonErrorResponse(400, -32600, "Invalid Request: Server already initialized");
3230
3243
  }
3231
3244
  if (messages.length > 1) {
3245
+ this.onerror?.(new Error("Invalid Request: Only one initialization request is allowed"));
3232
3246
  return this.createJsonErrorResponse(400, -32600, "Invalid Request: Only one initialization request is allowed");
3233
3247
  }
3234
3248
  this.sessionId = this.sessionIdGenerator?.();
@@ -3354,13 +3368,16 @@ data:
3354
3368
  return void 0;
3355
3369
  }
3356
3370
  if (!this._initialized) {
3371
+ this.onerror?.(new Error("Bad Request: Server not initialized"));
3357
3372
  return this.createJsonErrorResponse(400, -32e3, "Bad Request: Server not initialized");
3358
3373
  }
3359
3374
  const sessionId = req.headers.get("mcp-session-id");
3360
3375
  if (!sessionId) {
3376
+ this.onerror?.(new Error("Bad Request: Mcp-Session-Id header is required"));
3361
3377
  return this.createJsonErrorResponse(400, -32e3, "Bad Request: Mcp-Session-Id header is required");
3362
3378
  }
3363
3379
  if (sessionId !== this.sessionId) {
3380
+ this.onerror?.(new Error("Session not found"));
3364
3381
  return this.createJsonErrorResponse(404, -32001, "Session not found");
3365
3382
  }
3366
3383
  return void 0;
@@ -3381,6 +3398,7 @@ data:
3381
3398
  validateProtocolVersion(req) {
3382
3399
  const protocolVersion = req.headers.get("mcp-protocol-version");
3383
3400
  if (protocolVersion !== null && !SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) {
3401
+ this.onerror?.(new Error(`Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`));
3384
3402
  return this.createJsonErrorResponse(400, -32e3, `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`);
3385
3403
  }
3386
3404
  return void 0;
@@ -3587,7 +3605,7 @@ var StreamableHTTPServerTransport = class {
3587
3605
  };
3588
3606
 
3589
3607
  // __mcpc__cli_latest/node_modules/@jsr/std__cli/parse_args.js
3590
- var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.+?))?$/s;
3608
+ var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.*))?$/s;
3591
3609
  var LETTER_REGEXP = /[A-Za-z]/;
3592
3610
  var NUMBER_REGEXP = /-?\d+(\.\d*)?(e-?\d+)?$/;
3593
3611
  var HYPHEN_REGEXP = /^(-|--)[^-]/;
@@ -3598,12 +3616,19 @@ var NON_WHITESPACE_REGEXP = /\S/;
3598
3616
  function isNumber(string3) {
3599
3617
  return NON_WHITESPACE_REGEXP.test(string3) && Number.isFinite(Number(string3));
3600
3618
  }
3619
+ function isConstructorOrProto(obj, key) {
3620
+ return key === "constructor" && typeof obj[key] === "function" || key === "__proto__";
3621
+ }
3601
3622
  function setNested(object5, keys, value, collect = false) {
3602
3623
  keys = [
3603
3624
  ...keys
3604
3625
  ];
3605
3626
  const key = keys.pop();
3606
- keys.forEach((key2) => object5 = object5[key2] ??= {});
3627
+ for (const k of keys) {
3628
+ if (isConstructorOrProto(object5, k)) return;
3629
+ object5 = object5[k] ??= {};
3630
+ }
3631
+ if (isConstructorOrProto(object5, key)) return;
3607
3632
  if (collect) {
3608
3633
  const v = object5[key];
3609
3634
  if (Array.isArray(v)) {
@@ -3734,7 +3759,7 @@ function parseArgs(args, options) {
3734
3759
  let key = groups.key;
3735
3760
  let value = groups.value;
3736
3761
  if (doubleDash2) {
3737
- if (value) {
3762
+ if (value != null) {
3738
3763
  if (booleanSet.has(key)) value = parseBooleanString(value);
3739
3764
  setArgument(key, value, arg, true);
3740
3765
  continue;
@@ -3772,6 +3797,10 @@ function parseArgs(args, options) {
3772
3797
  setArgument(letter, next, arg, true);
3773
3798
  continue;
3774
3799
  }
3800
+ if (next === "=") {
3801
+ setArgument(letter, "", arg, true);
3802
+ continue argsLoop;
3803
+ }
3775
3804
  if (LETTER_REGEXP.test(letter)) {
3776
3805
  const groups2 = VALUE_REGEXP.exec(next)?.groups;
3777
3806
  if (groups2) {
@@ -4266,7 +4295,7 @@ Usage:
4266
4295
  - ${toolName}({ skill: "skill-name" }) - Load main SKILL.md content
4267
4296
  - ${toolName}({ skill: "skill-name", ref: "path/to/file" }) - Load reference file
4268
4297
 
4269
- Note: For scripts/ and assets/, use appropriate tools directly.`;
4298
+ Note: For scripts/, use the bash tool with the script path to execute.`;
4270
4299
  }
4271
4300
  function createSkillsPlugin(options) {
4272
4301
  const { paths } = options;
@@ -4374,11 +4403,15 @@ Available skills: ${available.join(", ")}` : "\n\nNo skills available.";
4374
4403
  try {
4375
4404
  const content = await readFile(join2(meta.basePath, "SKILL.md"), "utf-8");
4376
4405
  const body = extractBody(content);
4406
+ const skillPathInfo = `
4407
+ ---
4408
+ Skill path: ${meta.basePath}
4409
+ `;
4377
4410
  return {
4378
4411
  content: [
4379
4412
  {
4380
4413
  type: "text",
4381
- text: body
4414
+ text: body + skillPathInfo
4382
4415
  }
4383
4416
  ]
4384
4417
  };
@@ -5249,12 +5282,29 @@ function writeFoldedLines(count) {
5249
5282
  if (count > 1) return "\n".repeat(count - 1);
5250
5283
  return "";
5251
5284
  }
5285
+ var Scanner = class {
5286
+ source;
5287
+ #length;
5288
+ position = 0;
5289
+ constructor(source) {
5290
+ source += "\0";
5291
+ this.source = source;
5292
+ this.#length = source.length;
5293
+ }
5294
+ peek(offset = 0) {
5295
+ return this.source.charCodeAt(this.position + offset);
5296
+ }
5297
+ next() {
5298
+ this.position += 1;
5299
+ }
5300
+ eof() {
5301
+ return this.position >= this.#length - 1;
5302
+ }
5303
+ };
5252
5304
  var LoaderState = class {
5253
- input;
5254
- length;
5305
+ #scanner;
5255
5306
  lineIndent = 0;
5256
5307
  lineStart = 0;
5257
- position = 0;
5258
5308
  line = 0;
5259
5309
  onWarning;
5260
5310
  allowDuplicateKeys;
@@ -5264,44 +5314,40 @@ var LoaderState = class {
5264
5314
  tagMap = /* @__PURE__ */ new Map();
5265
5315
  anchorMap = /* @__PURE__ */ new Map();
5266
5316
  constructor(input, { schema = DEFAULT_SCHEMA, onWarning, allowDuplicateKeys = false }) {
5267
- this.input = input;
5317
+ this.#scanner = new Scanner(input);
5268
5318
  this.onWarning = onWarning;
5269
5319
  this.allowDuplicateKeys = allowDuplicateKeys;
5270
5320
  this.implicitTypes = schema.implicitTypes;
5271
5321
  this.typeMap = schema.typeMap;
5272
- this.length = input.length;
5273
5322
  this.readIndent();
5274
5323
  }
5275
5324
  skipWhitespaces() {
5276
- let ch = this.peek();
5325
+ let ch = this.#scanner.peek();
5277
5326
  while (isWhiteSpace(ch)) {
5278
- ch = this.next();
5327
+ this.#scanner.next();
5328
+ ch = this.#scanner.peek();
5279
5329
  }
5280
5330
  }
5281
5331
  skipComment() {
5282
- let ch = this.peek();
5332
+ let ch = this.#scanner.peek();
5283
5333
  if (ch !== SHARP) return;
5284
- ch = this.next();
5334
+ this.#scanner.next();
5335
+ ch = this.#scanner.peek();
5285
5336
  while (ch !== 0 && !isEOL(ch)) {
5286
- ch = this.next();
5337
+ this.#scanner.next();
5338
+ ch = this.#scanner.peek();
5287
5339
  }
5288
5340
  }
5289
5341
  readIndent() {
5290
- let char = this.peek();
5291
- while (char === SPACE) {
5342
+ let ch = this.#scanner.peek();
5343
+ while (ch === SPACE) {
5292
5344
  this.lineIndent += 1;
5293
- char = this.next();
5345
+ this.#scanner.next();
5346
+ ch = this.#scanner.peek();
5294
5347
  }
5295
5348
  }
5296
- peek(offset = 0) {
5297
- return this.input.charCodeAt(this.position + offset);
5298
- }
5299
- next() {
5300
- this.position += 1;
5301
- return this.peek();
5302
- }
5303
5349
  #createError(message) {
5304
- const mark = markToString(this.input, this.position, this.line, this.position - this.lineStart);
5350
+ const mark = markToString(this.#scanner.source, this.#scanner.position, this.line, this.#scanner.position - this.lineStart);
5305
5351
  return new SyntaxError(`${message} ${mark}`);
5306
5352
  }
5307
5353
  dispatchWarning(message) {
@@ -5346,7 +5392,7 @@ var LoaderState = class {
5346
5392
  }
5347
5393
  captureSegment(start, end, checkJson) {
5348
5394
  if (start < end) {
5349
- const result = this.input.slice(start, end);
5395
+ const result = this.#scanner.source.slice(start, end);
5350
5396
  if (checkJson) {
5351
5397
  for (let position = 0; position < result.length; position++) {
5352
5398
  const character = result.charCodeAt(position);
@@ -5364,21 +5410,21 @@ var LoaderState = class {
5364
5410
  let detected = false;
5365
5411
  const result = [];
5366
5412
  if (anchor !== null) this.anchorMap.set(anchor, result);
5367
- let ch = this.peek();
5413
+ let ch = this.#scanner.peek();
5368
5414
  while (ch !== 0) {
5369
5415
  if (ch !== MINUS) {
5370
5416
  break;
5371
5417
  }
5372
- const following = this.peek(1);
5418
+ const following = this.#scanner.peek(1);
5373
5419
  if (!isWhiteSpaceOrEOL(following)) {
5374
5420
  break;
5375
5421
  }
5376
5422
  detected = true;
5377
- this.position++;
5423
+ this.#scanner.next();
5378
5424
  if (this.skipSeparationSpace(true, -1)) {
5379
5425
  if (this.lineIndent <= nodeIndent) {
5380
5426
  result.push(null);
5381
- ch = this.peek();
5427
+ ch = this.#scanner.peek();
5382
5428
  continue;
5383
5429
  }
5384
5430
  }
@@ -5391,7 +5437,7 @@ var LoaderState = class {
5391
5437
  });
5392
5438
  if (newState) result.push(newState.result);
5393
5439
  this.skipSeparationSpace(true, -1);
5394
- ch = this.peek();
5440
+ ch = this.#scanner.peek();
5395
5441
  if ((this.line === line || this.lineIndent > nodeIndent) && ch !== 0) {
5396
5442
  throw this.#createError("Cannot read block sequence: bad indentation of a sequence entry");
5397
5443
  } else if (this.lineIndent < nodeIndent) {
@@ -5447,7 +5493,7 @@ var LoaderState = class {
5447
5493
  } else {
5448
5494
  if (!this.allowDuplicateKeys && !overridableKeys.has(keyNode) && Object.hasOwn(result, keyNode)) {
5449
5495
  this.line = startLine || this.line;
5450
- this.position = startPos || this.position;
5496
+ this.#scanner.position = startPos || this.#scanner.position;
5451
5497
  throw this.#createError("Cannot store mapping pair: duplicated key");
5452
5498
  }
5453
5499
  Object.defineProperty(result, keyNode, {
@@ -5461,37 +5507,37 @@ var LoaderState = class {
5461
5507
  return result;
5462
5508
  }
5463
5509
  readLineBreak() {
5464
- const ch = this.peek();
5510
+ const ch = this.#scanner.peek();
5465
5511
  if (ch === LINE_FEED) {
5466
- this.position++;
5512
+ this.#scanner.next();
5467
5513
  } else if (ch === CARRIAGE_RETURN) {
5468
- this.position++;
5469
- if (this.peek() === LINE_FEED) {
5470
- this.position++;
5514
+ this.#scanner.next();
5515
+ if (this.#scanner.peek() === LINE_FEED) {
5516
+ this.#scanner.next();
5471
5517
  }
5472
5518
  } else {
5473
5519
  throw this.#createError("Cannot read line: line break not found");
5474
5520
  }
5475
5521
  this.line += 1;
5476
- this.lineStart = this.position;
5522
+ this.lineStart = this.#scanner.position;
5477
5523
  }
5478
5524
  skipSeparationSpace(allowComments, checkIndent) {
5479
5525
  let lineBreaks = 0;
5480
- let ch = this.peek();
5526
+ let ch = this.#scanner.peek();
5481
5527
  while (ch !== 0) {
5482
5528
  this.skipWhitespaces();
5483
- ch = this.peek();
5529
+ ch = this.#scanner.peek();
5484
5530
  if (allowComments) {
5485
5531
  this.skipComment();
5486
- ch = this.peek();
5532
+ ch = this.#scanner.peek();
5487
5533
  }
5488
5534
  if (isEOL(ch)) {
5489
5535
  this.readLineBreak();
5490
- ch = this.peek();
5536
+ ch = this.#scanner.peek();
5491
5537
  lineBreaks++;
5492
5538
  this.lineIndent = 0;
5493
5539
  this.readIndent();
5494
- ch = this.peek();
5540
+ ch = this.#scanner.peek();
5495
5541
  } else {
5496
5542
  break;
5497
5543
  }
@@ -5502,9 +5548,9 @@ var LoaderState = class {
5502
5548
  return lineBreaks;
5503
5549
  }
5504
5550
  testDocumentSeparator() {
5505
- let ch = this.peek();
5506
- if ((ch === MINUS || ch === DOT) && ch === this.peek(1) && ch === this.peek(2)) {
5507
- ch = this.peek(3);
5551
+ let ch = this.#scanner.peek();
5552
+ if ((ch === MINUS || ch === DOT) && ch === this.#scanner.peek(1) && ch === this.#scanner.peek(2)) {
5553
+ ch = this.#scanner.peek(3);
5508
5554
  if (ch === 0 || isWhiteSpaceOrEOL(ch)) {
5509
5555
  return true;
5510
5556
  }
@@ -5512,34 +5558,34 @@ var LoaderState = class {
5512
5558
  return false;
5513
5559
  }
5514
5560
  readPlainScalar(tag, anchor, nodeIndent, withinFlowCollection) {
5515
- let ch = this.peek();
5561
+ let ch = this.#scanner.peek();
5516
5562
  if (isWhiteSpaceOrEOL(ch) || isFlowIndicator(ch) || ch === SHARP || ch === AMPERSAND || ch === ASTERISK || ch === EXCLAMATION || ch === VERTICAL_LINE || ch === GREATER_THAN || ch === SINGLE_QUOTE || ch === DOUBLE_QUOTE || ch === PERCENT || ch === COMMERCIAL_AT || ch === GRAVE_ACCENT) {
5517
5563
  return;
5518
5564
  }
5519
5565
  let following;
5520
5566
  if (ch === QUESTION || ch === MINUS) {
5521
- following = this.peek(1);
5567
+ following = this.#scanner.peek(1);
5522
5568
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
5523
5569
  return;
5524
5570
  }
5525
5571
  }
5526
5572
  let result = "";
5527
- let captureEnd = this.position;
5528
- let captureStart = this.position;
5573
+ let captureEnd = this.#scanner.position;
5574
+ let captureStart = this.#scanner.position;
5529
5575
  let hasPendingContent = false;
5530
5576
  let line = 0;
5531
5577
  while (ch !== 0) {
5532
5578
  if (ch === COLON) {
5533
- following = this.peek(1);
5579
+ following = this.#scanner.peek(1);
5534
5580
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
5535
5581
  break;
5536
5582
  }
5537
5583
  } else if (ch === SHARP) {
5538
- const preceding = this.peek(-1);
5584
+ const preceding = this.#scanner.peek(-1);
5539
5585
  if (isWhiteSpaceOrEOL(preceding)) {
5540
5586
  break;
5541
5587
  }
5542
- } else if (this.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
5588
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
5543
5589
  break;
5544
5590
  } else if (isEOL(ch)) {
5545
5591
  line = this.line;
@@ -5548,10 +5594,10 @@ var LoaderState = class {
5548
5594
  this.skipSeparationSpace(false, -1);
5549
5595
  if (this.lineIndent >= nodeIndent) {
5550
5596
  hasPendingContent = true;
5551
- ch = this.peek();
5597
+ ch = this.#scanner.peek();
5552
5598
  continue;
5553
5599
  } else {
5554
- this.position = captureEnd;
5600
+ this.#scanner.position = captureEnd;
5555
5601
  this.line = line;
5556
5602
  this.lineStart = lineStart;
5557
5603
  this.lineIndent = lineIndent;
@@ -5562,13 +5608,14 @@ var LoaderState = class {
5562
5608
  const segment2 = this.captureSegment(captureStart, captureEnd, false);
5563
5609
  if (segment2) result += segment2;
5564
5610
  result += writeFoldedLines(this.line - line);
5565
- captureStart = captureEnd = this.position;
5611
+ captureStart = captureEnd = this.#scanner.position;
5566
5612
  hasPendingContent = false;
5567
5613
  }
5568
5614
  if (!isWhiteSpace(ch)) {
5569
- captureEnd = this.position + 1;
5615
+ captureEnd = this.#scanner.position + 1;
5570
5616
  }
5571
- ch = this.next();
5617
+ this.#scanner.next();
5618
+ ch = this.#scanner.peek();
5572
5619
  }
5573
5620
  const segment = this.captureSegment(captureStart, captureEnd, false);
5574
5621
  if (segment) result += segment;
@@ -5581,22 +5628,23 @@ var LoaderState = class {
5581
5628
  };
5582
5629
  }
5583
5630
  readSingleQuotedScalar(tag, anchor, nodeIndent) {
5584
- let ch = this.peek();
5631
+ let ch = this.#scanner.peek();
5585
5632
  if (ch !== SINGLE_QUOTE) return;
5586
5633
  let result = "";
5587
- this.position++;
5588
- let captureStart = this.position;
5589
- let captureEnd = this.position;
5590
- ch = this.peek();
5634
+ this.#scanner.next();
5635
+ let captureStart = this.#scanner.position;
5636
+ let captureEnd = this.#scanner.position;
5637
+ ch = this.#scanner.peek();
5591
5638
  while (ch !== 0) {
5592
5639
  if (ch === SINGLE_QUOTE) {
5593
- const segment = this.captureSegment(captureStart, this.position, true);
5640
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
5594
5641
  if (segment) result += segment;
5595
- ch = this.next();
5642
+ this.#scanner.next();
5643
+ ch = this.#scanner.peek();
5596
5644
  if (ch === SINGLE_QUOTE) {
5597
- captureStart = this.position;
5598
- this.position++;
5599
- captureEnd = this.position;
5645
+ captureStart = this.#scanner.position;
5646
+ this.#scanner.next();
5647
+ captureEnd = this.#scanner.position;
5600
5648
  } else {
5601
5649
  if (anchor !== null) this.anchorMap.set(anchor, result);
5602
5650
  return {
@@ -5610,31 +5658,31 @@ var LoaderState = class {
5610
5658
  const segment = this.captureSegment(captureStart, captureEnd, true);
5611
5659
  if (segment) result += segment;
5612
5660
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
5613
- captureStart = captureEnd = this.position;
5614
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
5661
+ captureStart = captureEnd = this.#scanner.position;
5662
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
5615
5663
  throw this.#createError("Unexpected end of the document within a single quoted scalar");
5616
5664
  } else {
5617
- this.position++;
5618
- captureEnd = this.position;
5665
+ this.#scanner.next();
5666
+ captureEnd = this.#scanner.position;
5619
5667
  }
5620
- ch = this.peek();
5668
+ ch = this.#scanner.peek();
5621
5669
  }
5622
5670
  throw this.#createError("Unexpected end of the stream within a single quoted scalar");
5623
5671
  }
5624
5672
  readDoubleQuotedScalar(tag, anchor, nodeIndent) {
5625
- let ch = this.peek();
5673
+ let ch = this.#scanner.peek();
5626
5674
  if (ch !== DOUBLE_QUOTE) return;
5627
5675
  let result = "";
5628
- this.position++;
5629
- let captureEnd = this.position;
5630
- let captureStart = this.position;
5676
+ this.#scanner.next();
5677
+ let captureEnd = this.#scanner.position;
5678
+ let captureStart = this.#scanner.position;
5631
5679
  let tmp;
5632
- ch = this.peek();
5680
+ ch = this.#scanner.peek();
5633
5681
  while (ch !== 0) {
5634
5682
  if (ch === DOUBLE_QUOTE) {
5635
- const segment = this.captureSegment(captureStart, this.position, true);
5683
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
5636
5684
  if (segment) result += segment;
5637
- this.position++;
5685
+ this.#scanner.next();
5638
5686
  if (anchor !== null) this.anchorMap.set(anchor, result);
5639
5687
  return {
5640
5688
  tag,
@@ -5644,19 +5692,21 @@ var LoaderState = class {
5644
5692
  };
5645
5693
  }
5646
5694
  if (ch === BACKSLASH) {
5647
- const segment = this.captureSegment(captureStart, this.position, true);
5695
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
5648
5696
  if (segment) result += segment;
5649
- ch = this.next();
5697
+ this.#scanner.next();
5698
+ ch = this.#scanner.peek();
5650
5699
  if (isEOL(ch)) {
5651
5700
  this.skipSeparationSpace(false, nodeIndent);
5652
5701
  } else if (ch < 256 && SIMPLE_ESCAPE_SEQUENCES.has(ch)) {
5653
5702
  result += SIMPLE_ESCAPE_SEQUENCES.get(ch);
5654
- this.position++;
5703
+ this.#scanner.next();
5655
5704
  } else if ((tmp = ESCAPED_HEX_LENGTHS.get(ch) ?? 0) > 0) {
5656
5705
  let hexLength = tmp;
5657
5706
  let hexResult = 0;
5658
5707
  for (; hexLength > 0; hexLength--) {
5659
- ch = this.next();
5708
+ this.#scanner.next();
5709
+ ch = this.#scanner.peek();
5660
5710
  if ((tmp = hexCharCodeToNumber(ch)) >= 0) {
5661
5711
  hexResult = (hexResult << 4) + tmp;
5662
5712
  } else {
@@ -5664,28 +5714,28 @@ var LoaderState = class {
5664
5714
  }
5665
5715
  }
5666
5716
  result += codepointToChar(hexResult);
5667
- this.position++;
5717
+ this.#scanner.next();
5668
5718
  } else {
5669
5719
  throw this.#createError("Cannot read double quoted scalar: unknown escape sequence");
5670
5720
  }
5671
- captureStart = captureEnd = this.position;
5721
+ captureStart = captureEnd = this.#scanner.position;
5672
5722
  } else if (isEOL(ch)) {
5673
5723
  const segment = this.captureSegment(captureStart, captureEnd, true);
5674
5724
  if (segment) result += segment;
5675
5725
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
5676
- captureStart = captureEnd = this.position;
5677
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
5726
+ captureStart = captureEnd = this.#scanner.position;
5727
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
5678
5728
  throw this.#createError("Unexpected end of the document within a double quoted scalar");
5679
5729
  } else {
5680
- this.position++;
5681
- captureEnd = this.position;
5730
+ this.#scanner.next();
5731
+ captureEnd = this.#scanner.position;
5682
5732
  }
5683
- ch = this.peek();
5733
+ ch = this.#scanner.peek();
5684
5734
  }
5685
5735
  throw this.#createError("Unexpected end of the stream within a double quoted scalar");
5686
5736
  }
5687
5737
  readFlowCollection(tag, anchor, nodeIndent) {
5688
- let ch = this.peek();
5738
+ let ch = this.#scanner.peek();
5689
5739
  let terminator;
5690
5740
  let isMapping = true;
5691
5741
  let result = {};
@@ -5699,7 +5749,8 @@ var LoaderState = class {
5699
5749
  return;
5700
5750
  }
5701
5751
  if (anchor !== null) this.anchorMap.set(anchor, result);
5702
- ch = this.next();
5752
+ this.#scanner.next();
5753
+ ch = this.#scanner.peek();
5703
5754
  let readNext = true;
5704
5755
  let valueNode = null;
5705
5756
  let keyNode = null;
@@ -5711,9 +5762,9 @@ var LoaderState = class {
5711
5762
  const overridableKeys = /* @__PURE__ */ new Set();
5712
5763
  while (ch !== 0) {
5713
5764
  this.skipSeparationSpace(true, nodeIndent);
5714
- ch = this.peek();
5765
+ ch = this.#scanner.peek();
5715
5766
  if (ch === terminator) {
5716
- this.position++;
5767
+ this.#scanner.next();
5717
5768
  const kind = isMapping ? "mapping" : "sequence";
5718
5769
  return {
5719
5770
  tag,
@@ -5728,10 +5779,10 @@ var LoaderState = class {
5728
5779
  keyTag = keyNode = valueNode = null;
5729
5780
  isPair = isExplicitPair = false;
5730
5781
  if (ch === QUESTION) {
5731
- following = this.peek(1);
5782
+ following = this.#scanner.peek(1);
5732
5783
  if (isWhiteSpaceOrEOL(following)) {
5733
5784
  isPair = isExplicitPair = true;
5734
- this.position++;
5785
+ this.#scanner.next();
5735
5786
  this.skipSeparationSpace(true, nodeIndent);
5736
5787
  }
5737
5788
  }
@@ -5747,10 +5798,11 @@ var LoaderState = class {
5747
5798
  keyNode = newState.result;
5748
5799
  }
5749
5800
  this.skipSeparationSpace(true, nodeIndent);
5750
- ch = this.peek();
5801
+ ch = this.#scanner.peek();
5751
5802
  if ((isExplicitPair || this.line === line) && ch === COLON) {
5752
5803
  isPair = true;
5753
- ch = this.next();
5804
+ this.#scanner.next();
5805
+ ch = this.#scanner.peek();
5754
5806
  this.skipSeparationSpace(true, nodeIndent);
5755
5807
  const newState2 = this.composeNode({
5756
5808
  parentIndent: nodeIndent,
@@ -5768,10 +5820,11 @@ var LoaderState = class {
5768
5820
  result.push(keyNode);
5769
5821
  }
5770
5822
  this.skipSeparationSpace(true, nodeIndent);
5771
- ch = this.peek();
5823
+ ch = this.#scanner.peek();
5772
5824
  if (ch === COMMA) {
5773
5825
  readNext = true;
5774
- ch = this.next();
5826
+ this.#scanner.next();
5827
+ ch = this.#scanner.peek();
5775
5828
  } else {
5776
5829
  readNext = false;
5777
5830
  }
@@ -5787,7 +5840,7 @@ var LoaderState = class {
5787
5840
  let textIndent = nodeIndent;
5788
5841
  let emptyLines = 0;
5789
5842
  let atMoreIndented = false;
5790
- let ch = this.peek();
5843
+ let ch = this.#scanner.peek();
5791
5844
  let folding = false;
5792
5845
  if (ch === VERTICAL_LINE) {
5793
5846
  folding = false;
@@ -5799,7 +5852,8 @@ var LoaderState = class {
5799
5852
  let result = "";
5800
5853
  let tmp = 0;
5801
5854
  while (ch !== 0) {
5802
- ch = this.next();
5855
+ this.#scanner.next();
5856
+ ch = this.#scanner.peek();
5803
5857
  if (ch === PLUS || ch === MINUS) {
5804
5858
  if (CHOMPING_CLIP === chomping) {
5805
5859
  chomping = ch === PLUS ? CHOMPING_KEEP : CHOMPING_STRIP;
@@ -5822,15 +5876,16 @@ var LoaderState = class {
5822
5876
  if (isWhiteSpace(ch)) {
5823
5877
  this.skipWhitespaces();
5824
5878
  this.skipComment();
5825
- ch = this.peek();
5879
+ ch = this.#scanner.peek();
5826
5880
  }
5827
5881
  while (ch !== 0) {
5828
5882
  this.readLineBreak();
5829
5883
  this.lineIndent = 0;
5830
- ch = this.peek();
5884
+ ch = this.#scanner.peek();
5831
5885
  while ((!detectedIndent || this.lineIndent < textIndent) && ch === SPACE) {
5832
5886
  this.lineIndent++;
5833
- ch = this.next();
5887
+ this.#scanner.next();
5888
+ ch = this.#scanner.peek();
5834
5889
  }
5835
5890
  if (!detectedIndent && this.lineIndent > textIndent) {
5836
5891
  textIndent = this.lineIndent;
@@ -5869,11 +5924,12 @@ var LoaderState = class {
5869
5924
  didReadContent = true;
5870
5925
  detectedIndent = true;
5871
5926
  emptyLines = 0;
5872
- const captureStart = this.position;
5927
+ const captureStart = this.#scanner.position;
5873
5928
  while (!isEOL(ch) && ch !== 0) {
5874
- ch = this.next();
5929
+ this.#scanner.next();
5930
+ ch = this.#scanner.peek();
5875
5931
  }
5876
- const segment = this.captureSegment(captureStart, this.position, false);
5932
+ const segment = this.captureSegment(captureStart, this.#scanner.position, false);
5877
5933
  if (segment) result += segment;
5878
5934
  }
5879
5935
  if (anchor !== null) this.anchorMap.set(anchor, result);
@@ -5896,11 +5952,11 @@ var LoaderState = class {
5896
5952
  let atExplicitKey = false;
5897
5953
  let detected = false;
5898
5954
  if (anchor !== null) this.anchorMap.set(anchor, result);
5899
- let ch = this.peek();
5955
+ let ch = this.#scanner.peek();
5900
5956
  while (ch !== 0) {
5901
- const following = this.peek(1);
5957
+ const following = this.#scanner.peek(1);
5902
5958
  line = this.line;
5903
- pos = this.position;
5959
+ pos = this.#scanner.position;
5904
5960
  if ((ch === QUESTION || ch === COLON) && isWhiteSpaceOrEOL(following)) {
5905
5961
  if (ch === QUESTION) {
5906
5962
  if (atExplicitKey) {
@@ -5918,7 +5974,7 @@ var LoaderState = class {
5918
5974
  } else {
5919
5975
  throw this.#createError("Cannot read block as explicit mapping pair is incomplete: a key node is missed or followed by a non-tabulated empty line");
5920
5976
  }
5921
- this.position += 1;
5977
+ this.#scanner.next();
5922
5978
  ch = following;
5923
5979
  } else {
5924
5980
  const newState = this.composeNode({
@@ -5929,11 +5985,12 @@ var LoaderState = class {
5929
5985
  });
5930
5986
  if (!newState) break;
5931
5987
  if (this.line === line) {
5932
- ch = this.peek();
5988
+ ch = this.#scanner.peek();
5933
5989
  this.skipWhitespaces();
5934
- ch = this.peek();
5990
+ ch = this.#scanner.peek();
5935
5991
  if (ch === COLON) {
5936
- ch = this.next();
5992
+ this.#scanner.next();
5993
+ ch = this.#scanner.peek();
5937
5994
  if (!isWhiteSpaceOrEOL(ch)) {
5938
5995
  throw this.#createError("Cannot read block: a whitespace character is expected after the key-value separator within a block mapping");
5939
5996
  }
@@ -5990,7 +6047,7 @@ var LoaderState = class {
5990
6047
  keyTag = keyNode = valueNode = null;
5991
6048
  }
5992
6049
  this.skipSeparationSpace(true, -1);
5993
- ch = this.peek();
6050
+ ch = this.#scanner.peek();
5994
6051
  }
5995
6052
  if (this.lineIndent > nodeIndent && ch !== 0) {
5996
6053
  throw this.#createError("Cannot read block: bad indentation of a mapping entry");
@@ -6013,30 +6070,35 @@ var LoaderState = class {
6013
6070
  let isNamed = false;
6014
6071
  let tagHandle = "";
6015
6072
  let tagName;
6016
- let ch = this.peek();
6073
+ let ch = this.#scanner.peek();
6017
6074
  if (ch !== EXCLAMATION) return;
6018
6075
  if (tag !== null) {
6019
6076
  throw this.#createError("Cannot read tag property: duplication of a tag property");
6020
6077
  }
6021
- ch = this.next();
6078
+ this.#scanner.next();
6079
+ ch = this.#scanner.peek();
6022
6080
  if (ch === SMALLER_THAN) {
6023
6081
  isVerbatim = true;
6024
- ch = this.next();
6082
+ this.#scanner.next();
6083
+ ch = this.#scanner.peek();
6025
6084
  } else if (ch === EXCLAMATION) {
6026
6085
  isNamed = true;
6027
6086
  tagHandle = "!!";
6028
- ch = this.next();
6087
+ this.#scanner.next();
6088
+ ch = this.#scanner.peek();
6029
6089
  } else {
6030
6090
  tagHandle = "!";
6031
6091
  }
6032
- let position = this.position;
6092
+ let position = this.#scanner.position;
6033
6093
  if (isVerbatim) {
6034
6094
  do {
6035
- ch = this.next();
6095
+ this.#scanner.next();
6096
+ ch = this.#scanner.peek();
6036
6097
  } while (ch !== 0 && ch !== GREATER_THAN);
6037
- if (this.position < this.length) {
6038
- tagName = this.input.slice(position, this.position);
6039
- ch = this.next();
6098
+ if (!this.#scanner.eof()) {
6099
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
6100
+ this.#scanner.next();
6101
+ ch = this.#scanner.peek();
6040
6102
  } else {
6041
6103
  throw this.#createError("Cannot read tag property: unexpected end of stream");
6042
6104
  }
@@ -6044,19 +6106,20 @@ var LoaderState = class {
6044
6106
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
6045
6107
  if (ch === EXCLAMATION) {
6046
6108
  if (!isNamed) {
6047
- tagHandle = this.input.slice(position - 1, this.position + 1);
6109
+ tagHandle = this.#scanner.source.slice(position - 1, this.#scanner.position + 1);
6048
6110
  if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
6049
6111
  throw this.#createError("Cannot read tag property: named tag handle contains invalid characters");
6050
6112
  }
6051
6113
  isNamed = true;
6052
- position = this.position + 1;
6114
+ position = this.#scanner.position + 1;
6053
6115
  } else {
6054
6116
  throw this.#createError("Cannot read tag property: tag suffix cannot contain an exclamation mark");
6055
6117
  }
6056
6118
  }
6057
- ch = this.next();
6119
+ this.#scanner.next();
6120
+ ch = this.#scanner.peek();
6058
6121
  }
6059
- tagName = this.input.slice(position, this.position);
6122
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
6060
6123
  if (PATTERN_FLOW_INDICATORS.test(tagName)) {
6061
6124
  throw this.#createError("Cannot read tag property: tag suffix cannot contain flow indicator characters");
6062
6125
  }
@@ -6076,32 +6139,36 @@ var LoaderState = class {
6076
6139
  throw this.#createError(`Cannot read tag property: undeclared tag handle "${tagHandle}"`);
6077
6140
  }
6078
6141
  readAnchorProperty(anchor) {
6079
- let ch = this.peek();
6142
+ let ch = this.#scanner.peek();
6080
6143
  if (ch !== AMPERSAND) return;
6081
6144
  if (anchor !== null) {
6082
6145
  throw this.#createError("Cannot read anchor property: duplicate anchor property");
6083
6146
  }
6084
- ch = this.next();
6085
- const position = this.position;
6147
+ this.#scanner.next();
6148
+ ch = this.#scanner.peek();
6149
+ const position = this.#scanner.position;
6086
6150
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
6087
- ch = this.next();
6151
+ this.#scanner.next();
6152
+ ch = this.#scanner.peek();
6088
6153
  }
6089
- if (this.position === position) {
6154
+ if (this.#scanner.position === position) {
6090
6155
  throw this.#createError("Cannot read anchor property: name of an anchor node must contain at least one character");
6091
6156
  }
6092
- return this.input.slice(position, this.position);
6157
+ return this.#scanner.source.slice(position, this.#scanner.position);
6093
6158
  }
6094
6159
  readAlias() {
6095
- if (this.peek() !== ASTERISK) return;
6096
- let ch = this.next();
6097
- const position = this.position;
6160
+ if (this.#scanner.peek() !== ASTERISK) return;
6161
+ this.#scanner.next();
6162
+ let ch = this.#scanner.peek();
6163
+ const position = this.#scanner.position;
6098
6164
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
6099
- ch = this.next();
6165
+ this.#scanner.next();
6166
+ ch = this.#scanner.peek();
6100
6167
  }
6101
- if (this.position === position) {
6168
+ if (this.#scanner.position === position) {
6102
6169
  throw this.#createError("Cannot read alias: alias name must contain at least one character");
6103
6170
  }
6104
- const alias = this.input.slice(position, this.position);
6171
+ const alias = this.#scanner.source.slice(position, this.#scanner.position);
6105
6172
  if (!this.anchorMap.has(alias)) {
6106
6173
  throw this.#createError(`Cannot read alias: unidentified alias "${alias}"`);
6107
6174
  }
@@ -6184,7 +6251,7 @@ var LoaderState = class {
6184
6251
  const cond = CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext;
6185
6252
  const flowIndent = cond ? parentIndent : parentIndent + 1;
6186
6253
  if (allowBlockCollections) {
6187
- const blockIndent = this.position - this.lineStart;
6254
+ const blockIndent = this.#scanner.position - this.lineStart;
6188
6255
  const blockSequenceState = this.readBlockSequence(tag, anchor, blockIndent);
6189
6256
  if (blockSequenceState) return this.resolveTag(blockSequenceState);
6190
6257
  const blockMappingState = this.readBlockMapping(tag, anchor, blockIndent, flowIndent);
@@ -6218,7 +6285,7 @@ var LoaderState = class {
6218
6285
  return this.resolveTag(plainScalarState);
6219
6286
  }
6220
6287
  } else if (indentStatus === 0 && CONTEXT_BLOCK_OUT === nodeContext && allowBlockCollections) {
6221
- const blockIndent = this.position - this.lineStart;
6288
+ const blockIndent = this.#scanner.position - this.lineStart;
6222
6289
  const newState2 = this.readBlockSequence(tag, anchor, blockIndent);
6223
6290
  if (newState2) return this.resolveTag(newState2);
6224
6291
  }
@@ -6233,20 +6300,22 @@ var LoaderState = class {
6233
6300
  readDirectives() {
6234
6301
  let hasDirectives = false;
6235
6302
  let version = null;
6236
- let ch = this.peek();
6303
+ let ch = this.#scanner.peek();
6237
6304
  while (ch !== 0) {
6238
6305
  this.skipSeparationSpace(true, -1);
6239
- ch = this.peek();
6306
+ ch = this.#scanner.peek();
6240
6307
  if (this.lineIndent > 0 || ch !== PERCENT) {
6241
6308
  break;
6242
6309
  }
6243
6310
  hasDirectives = true;
6244
- ch = this.next();
6245
- let position = this.position;
6311
+ this.#scanner.next();
6312
+ ch = this.#scanner.peek();
6313
+ let position = this.#scanner.position;
6246
6314
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
6247
- ch = this.next();
6315
+ this.#scanner.next();
6316
+ ch = this.#scanner.peek();
6248
6317
  }
6249
- const directiveName = this.input.slice(position, this.position);
6318
+ const directiveName = this.#scanner.source.slice(position, this.#scanner.position);
6250
6319
  const directiveArgs = [];
6251
6320
  if (directiveName.length < 1) {
6252
6321
  throw this.#createError("Cannot read document: directive name length must be greater than zero");
@@ -6254,13 +6323,14 @@ var LoaderState = class {
6254
6323
  while (ch !== 0) {
6255
6324
  this.skipWhitespaces();
6256
6325
  this.skipComment();
6257
- ch = this.peek();
6326
+ ch = this.#scanner.peek();
6258
6327
  if (isEOL(ch)) break;
6259
- position = this.position;
6328
+ position = this.#scanner.position;
6260
6329
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
6261
- ch = this.next();
6330
+ this.#scanner.next();
6331
+ ch = this.#scanner.peek();
6262
6332
  }
6263
- directiveArgs.push(this.input.slice(position, this.position));
6333
+ directiveArgs.push(this.#scanner.source.slice(position, this.#scanner.position));
6264
6334
  }
6265
6335
  if (ch !== 0) this.readLineBreak();
6266
6336
  switch (directiveName) {
@@ -6277,20 +6347,20 @@ var LoaderState = class {
6277
6347
  this.dispatchWarning(`unknown document directive "${directiveName}"`);
6278
6348
  break;
6279
6349
  }
6280
- ch = this.peek();
6350
+ ch = this.#scanner.peek();
6281
6351
  }
6282
6352
  return hasDirectives;
6283
6353
  }
6284
6354
  readDocument() {
6285
- const documentStart = this.position;
6355
+ const documentStart = this.#scanner.position;
6286
6356
  this.checkLineBreaks = false;
6287
6357
  this.tagMap = /* @__PURE__ */ new Map();
6288
6358
  this.anchorMap = /* @__PURE__ */ new Map();
6289
6359
  const hasDirectives = this.readDirectives();
6290
6360
  this.skipSeparationSpace(true, -1);
6291
6361
  let result = null;
6292
- if (this.lineIndent === 0 && this.peek() === MINUS && this.peek(1) === MINUS && this.peek(2) === MINUS) {
6293
- this.position += 3;
6362
+ if (this.lineIndent === 0 && this.#scanner.peek() === MINUS && this.#scanner.peek(1) === MINUS && this.#scanner.peek(2) === MINUS) {
6363
+ this.#scanner.position += 3;
6294
6364
  this.skipSeparationSpace(true, -1);
6295
6365
  } else if (hasDirectives) {
6296
6366
  throw this.#createError("Cannot read document: directives end mark is expected");
@@ -6303,21 +6373,21 @@ var LoaderState = class {
6303
6373
  });
6304
6374
  if (newState) result = newState.result;
6305
6375
  this.skipSeparationSpace(true, -1);
6306
- if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.input.slice(documentStart, this.position))) {
6376
+ if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.#scanner.source.slice(documentStart, this.#scanner.position))) {
6307
6377
  this.dispatchWarning("non-ASCII line breaks are interpreted as content");
6308
6378
  }
6309
- if (this.position === this.lineStart && this.testDocumentSeparator()) {
6310
- if (this.peek() === DOT) {
6311
- this.position += 3;
6379
+ if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
6380
+ if (this.#scanner.peek() === DOT) {
6381
+ this.#scanner.position += 3;
6312
6382
  this.skipSeparationSpace(true, -1);
6313
6383
  }
6314
- } else if (this.position < this.length - 1) {
6384
+ } else if (!this.#scanner.eof()) {
6315
6385
  throw this.#createError("Cannot read document: end of the stream or a document separator is expected");
6316
6386
  }
6317
6387
  return result;
6318
6388
  }
6319
6389
  *readDocuments() {
6320
- while (this.position < this.length - 1) {
6390
+ while (!this.#scanner.eof()) {
6321
6391
  yield this.readDocument();
6322
6392
  }
6323
6393
  }
@@ -6330,7 +6400,6 @@ function sanitizeInput(input) {
6330
6400
  if (!isEOL(input.charCodeAt(input.length - 1))) input += "\n";
6331
6401
  if (input.charCodeAt(0) === 65279) input = input.slice(1);
6332
6402
  }
6333
- input += "\0";
6334
6403
  return input;
6335
6404
  }
6336
6405
  function parse(content, options = {}) {
@@ -6490,7 +6559,7 @@ function getDefaultAgents() {
6490
6559
  }
6491
6560
 
6492
6561
  // __mcpc__cli_latest/node_modules/@mcpc/cli/src/config/loader.js
6493
- var CLI_VERSION = "0.1.44";
6562
+ var CLI_VERSION = "0.1.51";
6494
6563
  function extractServerName(command, commandArgs) {
6495
6564
  for (const arg of commandArgs) {
6496
6565
  if (!arg.startsWith("-")) {
@@ -8160,6 +8229,147 @@ var ExperimentalServerTasks = class {
8160
8229
  requestStream(request, resultSchema, options) {
8161
8230
  return this._server.requestStream(request, resultSchema, options);
8162
8231
  }
8232
+ /**
8233
+ * Sends a sampling request and returns an AsyncGenerator that yields response messages.
8234
+ * The generator is guaranteed to end with either a 'result' or 'error' message.
8235
+ *
8236
+ * For task-augmented requests, yields 'taskCreated' and 'taskStatus' messages
8237
+ * before the final result.
8238
+ *
8239
+ * @example
8240
+ * ```typescript
8241
+ * const stream = server.experimental.tasks.createMessageStream({
8242
+ * messages: [{ role: 'user', content: { type: 'text', text: 'Hello' } }],
8243
+ * maxTokens: 100
8244
+ * }, {
8245
+ * onprogress: (progress) => {
8246
+ * // Handle streaming tokens via progress notifications
8247
+ * console.log('Progress:', progress.message);
8248
+ * }
8249
+ * });
8250
+ *
8251
+ * for await (const message of stream) {
8252
+ * switch (message.type) {
8253
+ * case 'taskCreated':
8254
+ * console.log('Task created:', message.task.taskId);
8255
+ * break;
8256
+ * case 'taskStatus':
8257
+ * console.log('Task status:', message.task.status);
8258
+ * break;
8259
+ * case 'result':
8260
+ * console.log('Final result:', message.result);
8261
+ * break;
8262
+ * case 'error':
8263
+ * console.error('Error:', message.error);
8264
+ * break;
8265
+ * }
8266
+ * }
8267
+ * ```
8268
+ *
8269
+ * @param params - The sampling request parameters
8270
+ * @param options - Optional request options (timeout, signal, task creation params, onprogress, etc.)
8271
+ * @returns AsyncGenerator that yields ResponseMessage objects
8272
+ *
8273
+ * @experimental
8274
+ */
8275
+ createMessageStream(params, options) {
8276
+ const clientCapabilities = this._server.getClientCapabilities();
8277
+ if ((params.tools || params.toolChoice) && !clientCapabilities?.sampling?.tools) {
8278
+ throw new Error("Client does not support sampling tools capability.");
8279
+ }
8280
+ if (params.messages.length > 0) {
8281
+ const lastMessage = params.messages[params.messages.length - 1];
8282
+ const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];
8283
+ const hasToolResults = lastContent.some((c) => c.type === "tool_result");
8284
+ const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : void 0;
8285
+ const previousContent = previousMessage ? Array.isArray(previousMessage.content) ? previousMessage.content : [previousMessage.content] : [];
8286
+ const hasPreviousToolUse = previousContent.some((c) => c.type === "tool_use");
8287
+ if (hasToolResults) {
8288
+ if (lastContent.some((c) => c.type !== "tool_result")) {
8289
+ throw new Error("The last message must contain only tool_result content if any is present");
8290
+ }
8291
+ if (!hasPreviousToolUse) {
8292
+ throw new Error("tool_result blocks are not matching any tool_use from the previous message");
8293
+ }
8294
+ }
8295
+ if (hasPreviousToolUse) {
8296
+ const toolUseIds = new Set(previousContent.filter((c) => c.type === "tool_use").map((c) => c.id));
8297
+ const toolResultIds = new Set(lastContent.filter((c) => c.type === "tool_result").map((c) => c.toolUseId));
8298
+ if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((id) => toolResultIds.has(id))) {
8299
+ throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match");
8300
+ }
8301
+ }
8302
+ }
8303
+ return this.requestStream({
8304
+ method: "sampling/createMessage",
8305
+ params
8306
+ }, CreateMessageResultSchema, options);
8307
+ }
8308
+ /**
8309
+ * Sends an elicitation request and returns an AsyncGenerator that yields response messages.
8310
+ * The generator is guaranteed to end with either a 'result' or 'error' message.
8311
+ *
8312
+ * For task-augmented requests (especially URL-based elicitation), yields 'taskCreated'
8313
+ * and 'taskStatus' messages before the final result.
8314
+ *
8315
+ * @example
8316
+ * ```typescript
8317
+ * const stream = server.experimental.tasks.elicitInputStream({
8318
+ * mode: 'url',
8319
+ * message: 'Please authenticate',
8320
+ * elicitationId: 'auth-123',
8321
+ * url: 'https://example.com/auth'
8322
+ * }, {
8323
+ * task: { ttl: 300000 } // Task-augmented for long-running auth flow
8324
+ * });
8325
+ *
8326
+ * for await (const message of stream) {
8327
+ * switch (message.type) {
8328
+ * case 'taskCreated':
8329
+ * console.log('Task created:', message.task.taskId);
8330
+ * break;
8331
+ * case 'taskStatus':
8332
+ * console.log('Task status:', message.task.status);
8333
+ * break;
8334
+ * case 'result':
8335
+ * console.log('User action:', message.result.action);
8336
+ * break;
8337
+ * case 'error':
8338
+ * console.error('Error:', message.error);
8339
+ * break;
8340
+ * }
8341
+ * }
8342
+ * ```
8343
+ *
8344
+ * @param params - The elicitation request parameters
8345
+ * @param options - Optional request options (timeout, signal, task creation params, etc.)
8346
+ * @returns AsyncGenerator that yields ResponseMessage objects
8347
+ *
8348
+ * @experimental
8349
+ */
8350
+ elicitInputStream(params, options) {
8351
+ const clientCapabilities = this._server.getClientCapabilities();
8352
+ const mode = params.mode ?? "form";
8353
+ switch (mode) {
8354
+ case "url": {
8355
+ if (!clientCapabilities?.elicitation?.url) {
8356
+ throw new Error("Client does not support url elicitation.");
8357
+ }
8358
+ break;
8359
+ }
8360
+ case "form": {
8361
+ if (!clientCapabilities?.elicitation?.form) {
8362
+ throw new Error("Client does not support form elicitation.");
8363
+ }
8364
+ break;
8365
+ }
8366
+ }
8367
+ const normalizedParams = mode === "form" && params.mode === void 0 ? { ...params, mode: "form" } : params;
8368
+ return this.requestStream({
8369
+ method: "elicitation/create",
8370
+ params: normalizedParams
8371
+ }, ElicitResultSchema, options);
8372
+ }
8163
8373
  /**
8164
8374
  * Gets the current status of a task.
8165
8375
  *
@@ -10378,22 +10588,45 @@ async function auth(provider, options) {
10378
10588
  }
10379
10589
  }
10380
10590
  async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
10591
+ const cachedState = await provider.discoveryState?.();
10381
10592
  let resourceMetadata;
10382
10593
  let authorizationServerUrl;
10383
- try {
10384
- resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl }, fetchFn);
10385
- if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
10386
- authorizationServerUrl = resourceMetadata.authorization_servers[0];
10594
+ let metadata;
10595
+ let effectiveResourceMetadataUrl = resourceMetadataUrl;
10596
+ if (!effectiveResourceMetadataUrl && cachedState?.resourceMetadataUrl) {
10597
+ effectiveResourceMetadataUrl = new URL(cachedState.resourceMetadataUrl);
10598
+ }
10599
+ if (cachedState?.authorizationServerUrl) {
10600
+ authorizationServerUrl = cachedState.authorizationServerUrl;
10601
+ resourceMetadata = cachedState.resourceMetadata;
10602
+ metadata = cachedState.authorizationServerMetadata ?? await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn });
10603
+ if (!resourceMetadata) {
10604
+ try {
10605
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl }, fetchFn);
10606
+ } catch {
10607
+ }
10387
10608
  }
10388
- } catch {
10389
- }
10390
- if (!authorizationServerUrl) {
10391
- authorizationServerUrl = new URL("/", serverUrl);
10609
+ if (metadata !== cachedState.authorizationServerMetadata || resourceMetadata !== cachedState.resourceMetadata) {
10610
+ await provider.saveDiscoveryState?.({
10611
+ authorizationServerUrl: String(authorizationServerUrl),
10612
+ resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
10613
+ resourceMetadata,
10614
+ authorizationServerMetadata: metadata
10615
+ });
10616
+ }
10617
+ } else {
10618
+ const serverInfo = await discoverOAuthServerInfo(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl, fetchFn });
10619
+ authorizationServerUrl = serverInfo.authorizationServerUrl;
10620
+ metadata = serverInfo.authorizationServerMetadata;
10621
+ resourceMetadata = serverInfo.resourceMetadata;
10622
+ await provider.saveDiscoveryState?.({
10623
+ authorizationServerUrl: String(authorizationServerUrl),
10624
+ resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
10625
+ resourceMetadata,
10626
+ authorizationServerMetadata: metadata
10627
+ });
10392
10628
  }
10393
10629
  const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
10394
- const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, {
10395
- fetchFn
10396
- });
10397
10630
  let clientInformation = await Promise.resolve(provider.clientInformation());
10398
10631
  if (!clientInformation) {
10399
10632
  if (authorizationCode !== void 0) {
@@ -10648,6 +10881,26 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
10648
10881
  }
10649
10882
  return void 0;
10650
10883
  }
10884
+ async function discoverOAuthServerInfo(serverUrl, opts) {
10885
+ let resourceMetadata;
10886
+ let authorizationServerUrl;
10887
+ try {
10888
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: opts?.resourceMetadataUrl }, opts?.fetchFn);
10889
+ if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
10890
+ authorizationServerUrl = resourceMetadata.authorization_servers[0];
10891
+ }
10892
+ } catch {
10893
+ }
10894
+ if (!authorizationServerUrl) {
10895
+ authorizationServerUrl = String(new URL("/", serverUrl));
10896
+ }
10897
+ const authorizationServerMetadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn: opts?.fetchFn });
10898
+ return {
10899
+ authorizationServerUrl,
10900
+ authorizationServerMetadata,
10901
+ resourceMetadata
10902
+ };
10903
+ }
10651
10904
  async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
10652
10905
  let authorizationUrl;
10653
10906
  if (metadata) {
@@ -11512,18 +11765,6 @@ var cleanToolSchema = (schema) => {
11512
11765
  import { cwd } from "node:process";
11513
11766
  import process7 from "node:process";
11514
11767
  import { createHash } from "node:crypto";
11515
- var mcpClientPool = /* @__PURE__ */ new Map();
11516
- var mcpClientConnecting = /* @__PURE__ */ new Map();
11517
- var shortHash = (s) => createHash("sha256").update(s).digest("hex").slice(0, 8);
11518
- function defSignature(def) {
11519
- const defCopy = {
11520
- ...def
11521
- };
11522
- if (defCopy.transportType === "memory" || defCopy.transport) {
11523
- return `memory:${Date.now()}:${Math.random()}`;
11524
- }
11525
- return JSON.stringify(defCopy);
11526
- }
11527
11768
  function createTransport(def) {
11528
11769
  const defAny = def;
11529
11770
  const explicitType = defAny.transportType || defAny.type;
@@ -11571,90 +11812,43 @@ function createTransport(def) {
11571
11812
  }
11572
11813
  throw new Error(`Unsupported transport configuration: ${JSON.stringify(def)}`);
11573
11814
  }
11574
- async function getOrCreateMcpClient(defKey, def) {
11575
- const pooled = mcpClientPool.get(defKey);
11576
- if (pooled) {
11577
- pooled.refCount += 1;
11578
- return pooled.client;
11579
- }
11580
- const existingConnecting = mcpClientConnecting.get(defKey);
11581
- if (existingConnecting) {
11582
- const client = await existingConnecting;
11583
- const entry = mcpClientPool.get(defKey);
11584
- if (entry) entry.refCount += 1;
11585
- return client;
11586
- }
11587
- const transport = createTransport(def);
11588
- const connecting = (async () => {
11589
- const client = new Client({
11590
- name: `mcp_${shortHash(defSignature(def))}`,
11591
- version: "1.0.0"
11592
- });
11593
- await client.connect(transport, {
11594
- timeout: 6e4 * 10
11595
- });
11596
- return client;
11597
- })();
11598
- mcpClientConnecting.set(defKey, connecting);
11599
- try {
11600
- const client = await connecting;
11601
- mcpClientPool.set(defKey, {
11602
- client,
11603
- refCount: 1
11604
- });
11605
- return client;
11606
- } finally {
11607
- mcpClientConnecting.delete(defKey);
11815
+ function defSignature(def) {
11816
+ const defCopy = {
11817
+ ...def
11818
+ };
11819
+ if (defCopy.transportType === "memory" || defCopy.transport) {
11820
+ return `memory:${Date.now()}:${Math.random()}`;
11608
11821
  }
11822
+ return JSON.stringify(defCopy);
11609
11823
  }
11610
- async function releaseMcpClient(defKey) {
11611
- const entry = mcpClientPool.get(defKey);
11612
- if (!entry) return;
11613
- entry.refCount -= 1;
11614
- if (entry.refCount <= 0) {
11615
- mcpClientPool.delete(defKey);
11616
- try {
11617
- await entry.client.close();
11618
- } catch (err) {
11619
- console.error("Error closing MCP client:", err);
11620
- }
11621
- }
11824
+ var shortHash = (s) => createHash("sha256").update(s).digest("hex").slice(0, 8);
11825
+ async function createMcpClient(def) {
11826
+ const transport = createTransport(def);
11827
+ const client = new Client({
11828
+ name: `mcp_${shortHash(defSignature(def))}`,
11829
+ version: "1.0.0"
11830
+ });
11831
+ await client.connect(transport, {
11832
+ timeout: 6e4 * 10
11833
+ });
11834
+ return client;
11622
11835
  }
11623
- var cleanupAllPooledClients = async () => {
11624
- const entries = Array.from(mcpClientPool.entries());
11625
- mcpClientPool.clear();
11626
- await Promise.all(entries.map(async ([, { client }]) => {
11627
- try {
11628
- await client.close();
11629
- } catch (err) {
11630
- console.error("Error closing MCP client:", err);
11631
- }
11632
- }));
11633
- };
11634
- process7.once?.("exit", () => {
11635
- cleanupAllPooledClients();
11636
- });
11637
- process7.once?.("SIGINT", () => {
11638
- cleanupAllPooledClients().finally(() => process7.exit(0));
11639
- });
11640
11836
  async function composeMcpDepTools(mcpConfig, filterIn) {
11641
11837
  const allTools = {};
11642
11838
  const allClients = {};
11643
- const acquiredKeys = [];
11839
+ const clientsToClose = [];
11644
11840
  for (const [name, definition] of Object.entries(mcpConfig.mcpServers)) {
11645
11841
  const def = definition;
11646
11842
  if (def.disabled) continue;
11647
- const defKey = shortHash(defSignature(def));
11648
- const serverId = name;
11649
11843
  try {
11650
- const client = await getOrCreateMcpClient(defKey, def);
11651
- acquiredKeys.push(defKey);
11652
- allClients[serverId] = client;
11844
+ const client = await createMcpClient(def);
11845
+ clientsToClose.push(client);
11846
+ allClients[name] = client;
11653
11847
  const { tools } = await client.listTools();
11654
11848
  tools.forEach((tool2) => {
11655
11849
  const toolNameWithScope = `${name}.${tool2.name}`;
11656
11850
  const internalToolName = tool2.name;
11657
- const rawToolId = `${serverId}_${internalToolName}`;
11851
+ const rawToolId = `${name}_${internalToolName}`;
11658
11852
  const toolId = sanitizePropertyKey(rawToolId);
11659
11853
  if (filterIn && !filterIn({
11660
11854
  action: internalToolName,
@@ -11666,7 +11860,7 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
11666
11860
  })) {
11667
11861
  return;
11668
11862
  }
11669
- const execute = (args) => allClients[serverId].callTool({
11863
+ const execute = (args) => allClients[name].callTool({
11670
11864
  name: internalToolName,
11671
11865
  arguments: args
11672
11866
  }, void 0, {
@@ -11683,10 +11877,12 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
11683
11877
  }
11684
11878
  }
11685
11879
  const cleanupClients = async () => {
11686
- await Promise.all(acquiredKeys.map((k) => releaseMcpClient(k)));
11687
- acquiredKeys.length = 0;
11688
- Object.keys(allTools).forEach((key) => delete allTools[key]);
11689
- Object.keys(allClients).forEach((key) => delete allClients[key]);
11880
+ await Promise.all(clientsToClose.map((client) => {
11881
+ try {
11882
+ return client.close();
11883
+ } catch {
11884
+ }
11885
+ }));
11690
11886
  };
11691
11887
  return {
11692
11888
  tools: allTools,