@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/index.mjs CHANGED
@@ -3030,6 +3030,7 @@ data:
3030
3030
  async handleGetRequest(req) {
3031
3031
  const acceptHeader = req.headers.get("accept");
3032
3032
  if (!acceptHeader?.includes("text/event-stream")) {
3033
+ this.onerror?.(new Error("Not Acceptable: Client must accept text/event-stream"));
3033
3034
  return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept text/event-stream");
3034
3035
  }
3035
3036
  const sessionError = this.validateSession(req);
@@ -3047,6 +3048,7 @@ data:
3047
3048
  }
3048
3049
  }
3049
3050
  if (this._streamMapping.get(this._standaloneSseStreamId) !== void 0) {
3051
+ this.onerror?.(new Error("Conflict: Only one SSE stream is allowed per session"));
3050
3052
  return this.createJsonErrorResponse(409, -32e3, "Conflict: Only one SSE stream is allowed per session");
3051
3053
  }
3052
3054
  const encoder2 = new TextEncoder();
@@ -3086,6 +3088,7 @@ data:
3086
3088
  */
3087
3089
  async replayEvents(lastEventId) {
3088
3090
  if (!this._eventStore) {
3091
+ this.onerror?.(new Error("Event store not configured"));
3089
3092
  return this.createJsonErrorResponse(400, -32e3, "Event store not configured");
3090
3093
  }
3091
3094
  try {
@@ -3093,9 +3096,11 @@ data:
3093
3096
  if (this._eventStore.getStreamIdForEventId) {
3094
3097
  streamId = await this._eventStore.getStreamIdForEventId(lastEventId);
3095
3098
  if (!streamId) {
3099
+ this.onerror?.(new Error("Invalid event ID format"));
3096
3100
  return this.createJsonErrorResponse(400, -32e3, "Invalid event ID format");
3097
3101
  }
3098
3102
  if (this._streamMapping.get(streamId) !== void 0) {
3103
+ this.onerror?.(new Error("Conflict: Stream already has an active connection"));
3099
3104
  return this.createJsonErrorResponse(409, -32e3, "Conflict: Stream already has an active connection");
3100
3105
  }
3101
3106
  }
@@ -3161,7 +3166,8 @@ data:
3161
3166
  `;
3162
3167
  controller.enqueue(encoder2.encode(eventData));
3163
3168
  return true;
3164
- } catch {
3169
+ } catch (error) {
3170
+ this.onerror?.(error);
3165
3171
  return false;
3166
3172
  }
3167
3173
  }
@@ -3169,6 +3175,7 @@ data:
3169
3175
  * Handles unsupported requests (PUT, PATCH, etc.)
3170
3176
  */
3171
3177
  handleUnsupportedRequest() {
3178
+ this.onerror?.(new Error("Method not allowed."));
3172
3179
  return new Response(JSON.stringify({
3173
3180
  jsonrpc: "2.0",
3174
3181
  error: {
@@ -3191,14 +3198,17 @@ data:
3191
3198
  try {
3192
3199
  const acceptHeader = req.headers.get("accept");
3193
3200
  if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
3201
+ this.onerror?.(new Error("Not Acceptable: Client must accept both application/json and text/event-stream"));
3194
3202
  return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept both application/json and text/event-stream");
3195
3203
  }
3196
3204
  const ct = req.headers.get("content-type");
3197
3205
  if (!ct || !ct.includes("application/json")) {
3206
+ this.onerror?.(new Error("Unsupported Media Type: Content-Type must be application/json"));
3198
3207
  return this.createJsonErrorResponse(415, -32e3, "Unsupported Media Type: Content-Type must be application/json");
3199
3208
  }
3200
3209
  const requestInfo = {
3201
- headers: Object.fromEntries(req.headers.entries())
3210
+ headers: Object.fromEntries(req.headers.entries()),
3211
+ url: new URL(req.url)
3202
3212
  };
3203
3213
  let rawMessage;
3204
3214
  if (options?.parsedBody !== void 0) {
@@ -3207,6 +3217,7 @@ data:
3207
3217
  try {
3208
3218
  rawMessage = await req.json();
3209
3219
  } catch {
3220
+ this.onerror?.(new Error("Parse error: Invalid JSON"));
3210
3221
  return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON");
3211
3222
  }
3212
3223
  }
@@ -3218,14 +3229,17 @@ data:
3218
3229
  messages = [JSONRPCMessageSchema.parse(rawMessage)];
3219
3230
  }
3220
3231
  } catch {
3232
+ this.onerror?.(new Error("Parse error: Invalid JSON-RPC message"));
3221
3233
  return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON-RPC message");
3222
3234
  }
3223
3235
  const isInitializationRequest = messages.some(isInitializeRequest);
3224
3236
  if (isInitializationRequest) {
3225
3237
  if (this._initialized && this.sessionId !== void 0) {
3238
+ this.onerror?.(new Error("Invalid Request: Server already initialized"));
3226
3239
  return this.createJsonErrorResponse(400, -32600, "Invalid Request: Server already initialized");
3227
3240
  }
3228
3241
  if (messages.length > 1) {
3242
+ this.onerror?.(new Error("Invalid Request: Only one initialization request is allowed"));
3229
3243
  return this.createJsonErrorResponse(400, -32600, "Invalid Request: Only one initialization request is allowed");
3230
3244
  }
3231
3245
  this.sessionId = this.sessionIdGenerator?.();
@@ -3351,13 +3365,16 @@ data:
3351
3365
  return void 0;
3352
3366
  }
3353
3367
  if (!this._initialized) {
3368
+ this.onerror?.(new Error("Bad Request: Server not initialized"));
3354
3369
  return this.createJsonErrorResponse(400, -32e3, "Bad Request: Server not initialized");
3355
3370
  }
3356
3371
  const sessionId = req.headers.get("mcp-session-id");
3357
3372
  if (!sessionId) {
3373
+ this.onerror?.(new Error("Bad Request: Mcp-Session-Id header is required"));
3358
3374
  return this.createJsonErrorResponse(400, -32e3, "Bad Request: Mcp-Session-Id header is required");
3359
3375
  }
3360
3376
  if (sessionId !== this.sessionId) {
3377
+ this.onerror?.(new Error("Session not found"));
3361
3378
  return this.createJsonErrorResponse(404, -32001, "Session not found");
3362
3379
  }
3363
3380
  return void 0;
@@ -3378,6 +3395,7 @@ data:
3378
3395
  validateProtocolVersion(req) {
3379
3396
  const protocolVersion = req.headers.get("mcp-protocol-version");
3380
3397
  if (protocolVersion !== null && !SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) {
3398
+ this.onerror?.(new Error(`Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`));
3381
3399
  return this.createJsonErrorResponse(400, -32e3, `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`);
3382
3400
  }
3383
3401
  return void 0;
@@ -3584,7 +3602,7 @@ var StreamableHTTPServerTransport = class {
3584
3602
  };
3585
3603
 
3586
3604
  // __mcpc__cli_latest/node_modules/@jsr/std__cli/parse_args.js
3587
- var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.+?))?$/s;
3605
+ var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.*))?$/s;
3588
3606
  var LETTER_REGEXP = /[A-Za-z]/;
3589
3607
  var NUMBER_REGEXP = /-?\d+(\.\d*)?(e-?\d+)?$/;
3590
3608
  var HYPHEN_REGEXP = /^(-|--)[^-]/;
@@ -3595,12 +3613,19 @@ var NON_WHITESPACE_REGEXP = /\S/;
3595
3613
  function isNumber(string3) {
3596
3614
  return NON_WHITESPACE_REGEXP.test(string3) && Number.isFinite(Number(string3));
3597
3615
  }
3616
+ function isConstructorOrProto(obj, key) {
3617
+ return key === "constructor" && typeof obj[key] === "function" || key === "__proto__";
3618
+ }
3598
3619
  function setNested(object5, keys, value, collect = false) {
3599
3620
  keys = [
3600
3621
  ...keys
3601
3622
  ];
3602
3623
  const key = keys.pop();
3603
- keys.forEach((key2) => object5 = object5[key2] ??= {});
3624
+ for (const k of keys) {
3625
+ if (isConstructorOrProto(object5, k)) return;
3626
+ object5 = object5[k] ??= {};
3627
+ }
3628
+ if (isConstructorOrProto(object5, key)) return;
3604
3629
  if (collect) {
3605
3630
  const v = object5[key];
3606
3631
  if (Array.isArray(v)) {
@@ -3731,7 +3756,7 @@ function parseArgs(args, options) {
3731
3756
  let key = groups.key;
3732
3757
  let value = groups.value;
3733
3758
  if (doubleDash2) {
3734
- if (value) {
3759
+ if (value != null) {
3735
3760
  if (booleanSet.has(key)) value = parseBooleanString(value);
3736
3761
  setArgument(key, value, arg, true);
3737
3762
  continue;
@@ -3769,6 +3794,10 @@ function parseArgs(args, options) {
3769
3794
  setArgument(letter, next, arg, true);
3770
3795
  continue;
3771
3796
  }
3797
+ if (next === "=") {
3798
+ setArgument(letter, "", arg, true);
3799
+ continue argsLoop;
3800
+ }
3772
3801
  if (LETTER_REGEXP.test(letter)) {
3773
3802
  const groups2 = VALUE_REGEXP.exec(next)?.groups;
3774
3803
  if (groups2) {
@@ -4263,7 +4292,7 @@ Usage:
4263
4292
  - ${toolName}({ skill: "skill-name" }) - Load main SKILL.md content
4264
4293
  - ${toolName}({ skill: "skill-name", ref: "path/to/file" }) - Load reference file
4265
4294
 
4266
- Note: For scripts/ and assets/, use appropriate tools directly.`;
4295
+ Note: For scripts/, use the bash tool with the script path to execute.`;
4267
4296
  }
4268
4297
  function createSkillsPlugin(options) {
4269
4298
  const { paths } = options;
@@ -4371,11 +4400,15 @@ Available skills: ${available.join(", ")}` : "\n\nNo skills available.";
4371
4400
  try {
4372
4401
  const content = await readFile(join2(meta.basePath, "SKILL.md"), "utf-8");
4373
4402
  const body = extractBody(content);
4403
+ const skillPathInfo = `
4404
+ ---
4405
+ Skill path: ${meta.basePath}
4406
+ `;
4374
4407
  return {
4375
4408
  content: [
4376
4409
  {
4377
4410
  type: "text",
4378
- text: body
4411
+ text: body + skillPathInfo
4379
4412
  }
4380
4413
  ]
4381
4414
  };
@@ -5246,12 +5279,29 @@ function writeFoldedLines(count) {
5246
5279
  if (count > 1) return "\n".repeat(count - 1);
5247
5280
  return "";
5248
5281
  }
5282
+ var Scanner = class {
5283
+ source;
5284
+ #length;
5285
+ position = 0;
5286
+ constructor(source) {
5287
+ source += "\0";
5288
+ this.source = source;
5289
+ this.#length = source.length;
5290
+ }
5291
+ peek(offset = 0) {
5292
+ return this.source.charCodeAt(this.position + offset);
5293
+ }
5294
+ next() {
5295
+ this.position += 1;
5296
+ }
5297
+ eof() {
5298
+ return this.position >= this.#length - 1;
5299
+ }
5300
+ };
5249
5301
  var LoaderState = class {
5250
- input;
5251
- length;
5302
+ #scanner;
5252
5303
  lineIndent = 0;
5253
5304
  lineStart = 0;
5254
- position = 0;
5255
5305
  line = 0;
5256
5306
  onWarning;
5257
5307
  allowDuplicateKeys;
@@ -5261,44 +5311,40 @@ var LoaderState = class {
5261
5311
  tagMap = /* @__PURE__ */ new Map();
5262
5312
  anchorMap = /* @__PURE__ */ new Map();
5263
5313
  constructor(input, { schema = DEFAULT_SCHEMA, onWarning, allowDuplicateKeys = false }) {
5264
- this.input = input;
5314
+ this.#scanner = new Scanner(input);
5265
5315
  this.onWarning = onWarning;
5266
5316
  this.allowDuplicateKeys = allowDuplicateKeys;
5267
5317
  this.implicitTypes = schema.implicitTypes;
5268
5318
  this.typeMap = schema.typeMap;
5269
- this.length = input.length;
5270
5319
  this.readIndent();
5271
5320
  }
5272
5321
  skipWhitespaces() {
5273
- let ch = this.peek();
5322
+ let ch = this.#scanner.peek();
5274
5323
  while (isWhiteSpace(ch)) {
5275
- ch = this.next();
5324
+ this.#scanner.next();
5325
+ ch = this.#scanner.peek();
5276
5326
  }
5277
5327
  }
5278
5328
  skipComment() {
5279
- let ch = this.peek();
5329
+ let ch = this.#scanner.peek();
5280
5330
  if (ch !== SHARP) return;
5281
- ch = this.next();
5331
+ this.#scanner.next();
5332
+ ch = this.#scanner.peek();
5282
5333
  while (ch !== 0 && !isEOL(ch)) {
5283
- ch = this.next();
5334
+ this.#scanner.next();
5335
+ ch = this.#scanner.peek();
5284
5336
  }
5285
5337
  }
5286
5338
  readIndent() {
5287
- let char = this.peek();
5288
- while (char === SPACE) {
5339
+ let ch = this.#scanner.peek();
5340
+ while (ch === SPACE) {
5289
5341
  this.lineIndent += 1;
5290
- char = this.next();
5342
+ this.#scanner.next();
5343
+ ch = this.#scanner.peek();
5291
5344
  }
5292
5345
  }
5293
- peek(offset = 0) {
5294
- return this.input.charCodeAt(this.position + offset);
5295
- }
5296
- next() {
5297
- this.position += 1;
5298
- return this.peek();
5299
- }
5300
5346
  #createError(message) {
5301
- const mark = markToString(this.input, this.position, this.line, this.position - this.lineStart);
5347
+ const mark = markToString(this.#scanner.source, this.#scanner.position, this.line, this.#scanner.position - this.lineStart);
5302
5348
  return new SyntaxError(`${message} ${mark}`);
5303
5349
  }
5304
5350
  dispatchWarning(message) {
@@ -5343,7 +5389,7 @@ var LoaderState = class {
5343
5389
  }
5344
5390
  captureSegment(start, end, checkJson) {
5345
5391
  if (start < end) {
5346
- const result = this.input.slice(start, end);
5392
+ const result = this.#scanner.source.slice(start, end);
5347
5393
  if (checkJson) {
5348
5394
  for (let position = 0; position < result.length; position++) {
5349
5395
  const character = result.charCodeAt(position);
@@ -5361,21 +5407,21 @@ var LoaderState = class {
5361
5407
  let detected = false;
5362
5408
  const result = [];
5363
5409
  if (anchor !== null) this.anchorMap.set(anchor, result);
5364
- let ch = this.peek();
5410
+ let ch = this.#scanner.peek();
5365
5411
  while (ch !== 0) {
5366
5412
  if (ch !== MINUS) {
5367
5413
  break;
5368
5414
  }
5369
- const following = this.peek(1);
5415
+ const following = this.#scanner.peek(1);
5370
5416
  if (!isWhiteSpaceOrEOL(following)) {
5371
5417
  break;
5372
5418
  }
5373
5419
  detected = true;
5374
- this.position++;
5420
+ this.#scanner.next();
5375
5421
  if (this.skipSeparationSpace(true, -1)) {
5376
5422
  if (this.lineIndent <= nodeIndent) {
5377
5423
  result.push(null);
5378
- ch = this.peek();
5424
+ ch = this.#scanner.peek();
5379
5425
  continue;
5380
5426
  }
5381
5427
  }
@@ -5388,7 +5434,7 @@ var LoaderState = class {
5388
5434
  });
5389
5435
  if (newState) result.push(newState.result);
5390
5436
  this.skipSeparationSpace(true, -1);
5391
- ch = this.peek();
5437
+ ch = this.#scanner.peek();
5392
5438
  if ((this.line === line || this.lineIndent > nodeIndent) && ch !== 0) {
5393
5439
  throw this.#createError("Cannot read block sequence: bad indentation of a sequence entry");
5394
5440
  } else if (this.lineIndent < nodeIndent) {
@@ -5444,7 +5490,7 @@ var LoaderState = class {
5444
5490
  } else {
5445
5491
  if (!this.allowDuplicateKeys && !overridableKeys.has(keyNode) && Object.hasOwn(result, keyNode)) {
5446
5492
  this.line = startLine || this.line;
5447
- this.position = startPos || this.position;
5493
+ this.#scanner.position = startPos || this.#scanner.position;
5448
5494
  throw this.#createError("Cannot store mapping pair: duplicated key");
5449
5495
  }
5450
5496
  Object.defineProperty(result, keyNode, {
@@ -5458,37 +5504,37 @@ var LoaderState = class {
5458
5504
  return result;
5459
5505
  }
5460
5506
  readLineBreak() {
5461
- const ch = this.peek();
5507
+ const ch = this.#scanner.peek();
5462
5508
  if (ch === LINE_FEED) {
5463
- this.position++;
5509
+ this.#scanner.next();
5464
5510
  } else if (ch === CARRIAGE_RETURN) {
5465
- this.position++;
5466
- if (this.peek() === LINE_FEED) {
5467
- this.position++;
5511
+ this.#scanner.next();
5512
+ if (this.#scanner.peek() === LINE_FEED) {
5513
+ this.#scanner.next();
5468
5514
  }
5469
5515
  } else {
5470
5516
  throw this.#createError("Cannot read line: line break not found");
5471
5517
  }
5472
5518
  this.line += 1;
5473
- this.lineStart = this.position;
5519
+ this.lineStart = this.#scanner.position;
5474
5520
  }
5475
5521
  skipSeparationSpace(allowComments, checkIndent) {
5476
5522
  let lineBreaks = 0;
5477
- let ch = this.peek();
5523
+ let ch = this.#scanner.peek();
5478
5524
  while (ch !== 0) {
5479
5525
  this.skipWhitespaces();
5480
- ch = this.peek();
5526
+ ch = this.#scanner.peek();
5481
5527
  if (allowComments) {
5482
5528
  this.skipComment();
5483
- ch = this.peek();
5529
+ ch = this.#scanner.peek();
5484
5530
  }
5485
5531
  if (isEOL(ch)) {
5486
5532
  this.readLineBreak();
5487
- ch = this.peek();
5533
+ ch = this.#scanner.peek();
5488
5534
  lineBreaks++;
5489
5535
  this.lineIndent = 0;
5490
5536
  this.readIndent();
5491
- ch = this.peek();
5537
+ ch = this.#scanner.peek();
5492
5538
  } else {
5493
5539
  break;
5494
5540
  }
@@ -5499,9 +5545,9 @@ var LoaderState = class {
5499
5545
  return lineBreaks;
5500
5546
  }
5501
5547
  testDocumentSeparator() {
5502
- let ch = this.peek();
5503
- if ((ch === MINUS || ch === DOT) && ch === this.peek(1) && ch === this.peek(2)) {
5504
- ch = this.peek(3);
5548
+ let ch = this.#scanner.peek();
5549
+ if ((ch === MINUS || ch === DOT) && ch === this.#scanner.peek(1) && ch === this.#scanner.peek(2)) {
5550
+ ch = this.#scanner.peek(3);
5505
5551
  if (ch === 0 || isWhiteSpaceOrEOL(ch)) {
5506
5552
  return true;
5507
5553
  }
@@ -5509,34 +5555,34 @@ var LoaderState = class {
5509
5555
  return false;
5510
5556
  }
5511
5557
  readPlainScalar(tag, anchor, nodeIndent, withinFlowCollection) {
5512
- let ch = this.peek();
5558
+ let ch = this.#scanner.peek();
5513
5559
  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) {
5514
5560
  return;
5515
5561
  }
5516
5562
  let following;
5517
5563
  if (ch === QUESTION || ch === MINUS) {
5518
- following = this.peek(1);
5564
+ following = this.#scanner.peek(1);
5519
5565
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
5520
5566
  return;
5521
5567
  }
5522
5568
  }
5523
5569
  let result = "";
5524
- let captureEnd = this.position;
5525
- let captureStart = this.position;
5570
+ let captureEnd = this.#scanner.position;
5571
+ let captureStart = this.#scanner.position;
5526
5572
  let hasPendingContent = false;
5527
5573
  let line = 0;
5528
5574
  while (ch !== 0) {
5529
5575
  if (ch === COLON) {
5530
- following = this.peek(1);
5576
+ following = this.#scanner.peek(1);
5531
5577
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
5532
5578
  break;
5533
5579
  }
5534
5580
  } else if (ch === SHARP) {
5535
- const preceding = this.peek(-1);
5581
+ const preceding = this.#scanner.peek(-1);
5536
5582
  if (isWhiteSpaceOrEOL(preceding)) {
5537
5583
  break;
5538
5584
  }
5539
- } else if (this.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
5585
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
5540
5586
  break;
5541
5587
  } else if (isEOL(ch)) {
5542
5588
  line = this.line;
@@ -5545,10 +5591,10 @@ var LoaderState = class {
5545
5591
  this.skipSeparationSpace(false, -1);
5546
5592
  if (this.lineIndent >= nodeIndent) {
5547
5593
  hasPendingContent = true;
5548
- ch = this.peek();
5594
+ ch = this.#scanner.peek();
5549
5595
  continue;
5550
5596
  } else {
5551
- this.position = captureEnd;
5597
+ this.#scanner.position = captureEnd;
5552
5598
  this.line = line;
5553
5599
  this.lineStart = lineStart;
5554
5600
  this.lineIndent = lineIndent;
@@ -5559,13 +5605,14 @@ var LoaderState = class {
5559
5605
  const segment2 = this.captureSegment(captureStart, captureEnd, false);
5560
5606
  if (segment2) result += segment2;
5561
5607
  result += writeFoldedLines(this.line - line);
5562
- captureStart = captureEnd = this.position;
5608
+ captureStart = captureEnd = this.#scanner.position;
5563
5609
  hasPendingContent = false;
5564
5610
  }
5565
5611
  if (!isWhiteSpace(ch)) {
5566
- captureEnd = this.position + 1;
5612
+ captureEnd = this.#scanner.position + 1;
5567
5613
  }
5568
- ch = this.next();
5614
+ this.#scanner.next();
5615
+ ch = this.#scanner.peek();
5569
5616
  }
5570
5617
  const segment = this.captureSegment(captureStart, captureEnd, false);
5571
5618
  if (segment) result += segment;
@@ -5578,22 +5625,23 @@ var LoaderState = class {
5578
5625
  };
5579
5626
  }
5580
5627
  readSingleQuotedScalar(tag, anchor, nodeIndent) {
5581
- let ch = this.peek();
5628
+ let ch = this.#scanner.peek();
5582
5629
  if (ch !== SINGLE_QUOTE) return;
5583
5630
  let result = "";
5584
- this.position++;
5585
- let captureStart = this.position;
5586
- let captureEnd = this.position;
5587
- ch = this.peek();
5631
+ this.#scanner.next();
5632
+ let captureStart = this.#scanner.position;
5633
+ let captureEnd = this.#scanner.position;
5634
+ ch = this.#scanner.peek();
5588
5635
  while (ch !== 0) {
5589
5636
  if (ch === SINGLE_QUOTE) {
5590
- const segment = this.captureSegment(captureStart, this.position, true);
5637
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
5591
5638
  if (segment) result += segment;
5592
- ch = this.next();
5639
+ this.#scanner.next();
5640
+ ch = this.#scanner.peek();
5593
5641
  if (ch === SINGLE_QUOTE) {
5594
- captureStart = this.position;
5595
- this.position++;
5596
- captureEnd = this.position;
5642
+ captureStart = this.#scanner.position;
5643
+ this.#scanner.next();
5644
+ captureEnd = this.#scanner.position;
5597
5645
  } else {
5598
5646
  if (anchor !== null) this.anchorMap.set(anchor, result);
5599
5647
  return {
@@ -5607,31 +5655,31 @@ var LoaderState = class {
5607
5655
  const segment = this.captureSegment(captureStart, captureEnd, true);
5608
5656
  if (segment) result += segment;
5609
5657
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
5610
- captureStart = captureEnd = this.position;
5611
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
5658
+ captureStart = captureEnd = this.#scanner.position;
5659
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
5612
5660
  throw this.#createError("Unexpected end of the document within a single quoted scalar");
5613
5661
  } else {
5614
- this.position++;
5615
- captureEnd = this.position;
5662
+ this.#scanner.next();
5663
+ captureEnd = this.#scanner.position;
5616
5664
  }
5617
- ch = this.peek();
5665
+ ch = this.#scanner.peek();
5618
5666
  }
5619
5667
  throw this.#createError("Unexpected end of the stream within a single quoted scalar");
5620
5668
  }
5621
5669
  readDoubleQuotedScalar(tag, anchor, nodeIndent) {
5622
- let ch = this.peek();
5670
+ let ch = this.#scanner.peek();
5623
5671
  if (ch !== DOUBLE_QUOTE) return;
5624
5672
  let result = "";
5625
- this.position++;
5626
- let captureEnd = this.position;
5627
- let captureStart = this.position;
5673
+ this.#scanner.next();
5674
+ let captureEnd = this.#scanner.position;
5675
+ let captureStart = this.#scanner.position;
5628
5676
  let tmp;
5629
- ch = this.peek();
5677
+ ch = this.#scanner.peek();
5630
5678
  while (ch !== 0) {
5631
5679
  if (ch === DOUBLE_QUOTE) {
5632
- const segment = this.captureSegment(captureStart, this.position, true);
5680
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
5633
5681
  if (segment) result += segment;
5634
- this.position++;
5682
+ this.#scanner.next();
5635
5683
  if (anchor !== null) this.anchorMap.set(anchor, result);
5636
5684
  return {
5637
5685
  tag,
@@ -5641,19 +5689,21 @@ var LoaderState = class {
5641
5689
  };
5642
5690
  }
5643
5691
  if (ch === BACKSLASH) {
5644
- const segment = this.captureSegment(captureStart, this.position, true);
5692
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
5645
5693
  if (segment) result += segment;
5646
- ch = this.next();
5694
+ this.#scanner.next();
5695
+ ch = this.#scanner.peek();
5647
5696
  if (isEOL(ch)) {
5648
5697
  this.skipSeparationSpace(false, nodeIndent);
5649
5698
  } else if (ch < 256 && SIMPLE_ESCAPE_SEQUENCES.has(ch)) {
5650
5699
  result += SIMPLE_ESCAPE_SEQUENCES.get(ch);
5651
- this.position++;
5700
+ this.#scanner.next();
5652
5701
  } else if ((tmp = ESCAPED_HEX_LENGTHS.get(ch) ?? 0) > 0) {
5653
5702
  let hexLength = tmp;
5654
5703
  let hexResult = 0;
5655
5704
  for (; hexLength > 0; hexLength--) {
5656
- ch = this.next();
5705
+ this.#scanner.next();
5706
+ ch = this.#scanner.peek();
5657
5707
  if ((tmp = hexCharCodeToNumber(ch)) >= 0) {
5658
5708
  hexResult = (hexResult << 4) + tmp;
5659
5709
  } else {
@@ -5661,28 +5711,28 @@ var LoaderState = class {
5661
5711
  }
5662
5712
  }
5663
5713
  result += codepointToChar(hexResult);
5664
- this.position++;
5714
+ this.#scanner.next();
5665
5715
  } else {
5666
5716
  throw this.#createError("Cannot read double quoted scalar: unknown escape sequence");
5667
5717
  }
5668
- captureStart = captureEnd = this.position;
5718
+ captureStart = captureEnd = this.#scanner.position;
5669
5719
  } else if (isEOL(ch)) {
5670
5720
  const segment = this.captureSegment(captureStart, captureEnd, true);
5671
5721
  if (segment) result += segment;
5672
5722
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
5673
- captureStart = captureEnd = this.position;
5674
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
5723
+ captureStart = captureEnd = this.#scanner.position;
5724
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
5675
5725
  throw this.#createError("Unexpected end of the document within a double quoted scalar");
5676
5726
  } else {
5677
- this.position++;
5678
- captureEnd = this.position;
5727
+ this.#scanner.next();
5728
+ captureEnd = this.#scanner.position;
5679
5729
  }
5680
- ch = this.peek();
5730
+ ch = this.#scanner.peek();
5681
5731
  }
5682
5732
  throw this.#createError("Unexpected end of the stream within a double quoted scalar");
5683
5733
  }
5684
5734
  readFlowCollection(tag, anchor, nodeIndent) {
5685
- let ch = this.peek();
5735
+ let ch = this.#scanner.peek();
5686
5736
  let terminator;
5687
5737
  let isMapping = true;
5688
5738
  let result = {};
@@ -5696,7 +5746,8 @@ var LoaderState = class {
5696
5746
  return;
5697
5747
  }
5698
5748
  if (anchor !== null) this.anchorMap.set(anchor, result);
5699
- ch = this.next();
5749
+ this.#scanner.next();
5750
+ ch = this.#scanner.peek();
5700
5751
  let readNext = true;
5701
5752
  let valueNode = null;
5702
5753
  let keyNode = null;
@@ -5708,9 +5759,9 @@ var LoaderState = class {
5708
5759
  const overridableKeys = /* @__PURE__ */ new Set();
5709
5760
  while (ch !== 0) {
5710
5761
  this.skipSeparationSpace(true, nodeIndent);
5711
- ch = this.peek();
5762
+ ch = this.#scanner.peek();
5712
5763
  if (ch === terminator) {
5713
- this.position++;
5764
+ this.#scanner.next();
5714
5765
  const kind = isMapping ? "mapping" : "sequence";
5715
5766
  return {
5716
5767
  tag,
@@ -5725,10 +5776,10 @@ var LoaderState = class {
5725
5776
  keyTag = keyNode = valueNode = null;
5726
5777
  isPair = isExplicitPair = false;
5727
5778
  if (ch === QUESTION) {
5728
- following = this.peek(1);
5779
+ following = this.#scanner.peek(1);
5729
5780
  if (isWhiteSpaceOrEOL(following)) {
5730
5781
  isPair = isExplicitPair = true;
5731
- this.position++;
5782
+ this.#scanner.next();
5732
5783
  this.skipSeparationSpace(true, nodeIndent);
5733
5784
  }
5734
5785
  }
@@ -5744,10 +5795,11 @@ var LoaderState = class {
5744
5795
  keyNode = newState.result;
5745
5796
  }
5746
5797
  this.skipSeparationSpace(true, nodeIndent);
5747
- ch = this.peek();
5798
+ ch = this.#scanner.peek();
5748
5799
  if ((isExplicitPair || this.line === line) && ch === COLON) {
5749
5800
  isPair = true;
5750
- ch = this.next();
5801
+ this.#scanner.next();
5802
+ ch = this.#scanner.peek();
5751
5803
  this.skipSeparationSpace(true, nodeIndent);
5752
5804
  const newState2 = this.composeNode({
5753
5805
  parentIndent: nodeIndent,
@@ -5765,10 +5817,11 @@ var LoaderState = class {
5765
5817
  result.push(keyNode);
5766
5818
  }
5767
5819
  this.skipSeparationSpace(true, nodeIndent);
5768
- ch = this.peek();
5820
+ ch = this.#scanner.peek();
5769
5821
  if (ch === COMMA) {
5770
5822
  readNext = true;
5771
- ch = this.next();
5823
+ this.#scanner.next();
5824
+ ch = this.#scanner.peek();
5772
5825
  } else {
5773
5826
  readNext = false;
5774
5827
  }
@@ -5784,7 +5837,7 @@ var LoaderState = class {
5784
5837
  let textIndent = nodeIndent;
5785
5838
  let emptyLines = 0;
5786
5839
  let atMoreIndented = false;
5787
- let ch = this.peek();
5840
+ let ch = this.#scanner.peek();
5788
5841
  let folding = false;
5789
5842
  if (ch === VERTICAL_LINE) {
5790
5843
  folding = false;
@@ -5796,7 +5849,8 @@ var LoaderState = class {
5796
5849
  let result = "";
5797
5850
  let tmp = 0;
5798
5851
  while (ch !== 0) {
5799
- ch = this.next();
5852
+ this.#scanner.next();
5853
+ ch = this.#scanner.peek();
5800
5854
  if (ch === PLUS || ch === MINUS) {
5801
5855
  if (CHOMPING_CLIP === chomping) {
5802
5856
  chomping = ch === PLUS ? CHOMPING_KEEP : CHOMPING_STRIP;
@@ -5819,15 +5873,16 @@ var LoaderState = class {
5819
5873
  if (isWhiteSpace(ch)) {
5820
5874
  this.skipWhitespaces();
5821
5875
  this.skipComment();
5822
- ch = this.peek();
5876
+ ch = this.#scanner.peek();
5823
5877
  }
5824
5878
  while (ch !== 0) {
5825
5879
  this.readLineBreak();
5826
5880
  this.lineIndent = 0;
5827
- ch = this.peek();
5881
+ ch = this.#scanner.peek();
5828
5882
  while ((!detectedIndent || this.lineIndent < textIndent) && ch === SPACE) {
5829
5883
  this.lineIndent++;
5830
- ch = this.next();
5884
+ this.#scanner.next();
5885
+ ch = this.#scanner.peek();
5831
5886
  }
5832
5887
  if (!detectedIndent && this.lineIndent > textIndent) {
5833
5888
  textIndent = this.lineIndent;
@@ -5866,11 +5921,12 @@ var LoaderState = class {
5866
5921
  didReadContent = true;
5867
5922
  detectedIndent = true;
5868
5923
  emptyLines = 0;
5869
- const captureStart = this.position;
5924
+ const captureStart = this.#scanner.position;
5870
5925
  while (!isEOL(ch) && ch !== 0) {
5871
- ch = this.next();
5926
+ this.#scanner.next();
5927
+ ch = this.#scanner.peek();
5872
5928
  }
5873
- const segment = this.captureSegment(captureStart, this.position, false);
5929
+ const segment = this.captureSegment(captureStart, this.#scanner.position, false);
5874
5930
  if (segment) result += segment;
5875
5931
  }
5876
5932
  if (anchor !== null) this.anchorMap.set(anchor, result);
@@ -5893,11 +5949,11 @@ var LoaderState = class {
5893
5949
  let atExplicitKey = false;
5894
5950
  let detected = false;
5895
5951
  if (anchor !== null) this.anchorMap.set(anchor, result);
5896
- let ch = this.peek();
5952
+ let ch = this.#scanner.peek();
5897
5953
  while (ch !== 0) {
5898
- const following = this.peek(1);
5954
+ const following = this.#scanner.peek(1);
5899
5955
  line = this.line;
5900
- pos = this.position;
5956
+ pos = this.#scanner.position;
5901
5957
  if ((ch === QUESTION || ch === COLON) && isWhiteSpaceOrEOL(following)) {
5902
5958
  if (ch === QUESTION) {
5903
5959
  if (atExplicitKey) {
@@ -5915,7 +5971,7 @@ var LoaderState = class {
5915
5971
  } else {
5916
5972
  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");
5917
5973
  }
5918
- this.position += 1;
5974
+ this.#scanner.next();
5919
5975
  ch = following;
5920
5976
  } else {
5921
5977
  const newState = this.composeNode({
@@ -5926,11 +5982,12 @@ var LoaderState = class {
5926
5982
  });
5927
5983
  if (!newState) break;
5928
5984
  if (this.line === line) {
5929
- ch = this.peek();
5985
+ ch = this.#scanner.peek();
5930
5986
  this.skipWhitespaces();
5931
- ch = this.peek();
5987
+ ch = this.#scanner.peek();
5932
5988
  if (ch === COLON) {
5933
- ch = this.next();
5989
+ this.#scanner.next();
5990
+ ch = this.#scanner.peek();
5934
5991
  if (!isWhiteSpaceOrEOL(ch)) {
5935
5992
  throw this.#createError("Cannot read block: a whitespace character is expected after the key-value separator within a block mapping");
5936
5993
  }
@@ -5987,7 +6044,7 @@ var LoaderState = class {
5987
6044
  keyTag = keyNode = valueNode = null;
5988
6045
  }
5989
6046
  this.skipSeparationSpace(true, -1);
5990
- ch = this.peek();
6047
+ ch = this.#scanner.peek();
5991
6048
  }
5992
6049
  if (this.lineIndent > nodeIndent && ch !== 0) {
5993
6050
  throw this.#createError("Cannot read block: bad indentation of a mapping entry");
@@ -6010,30 +6067,35 @@ var LoaderState = class {
6010
6067
  let isNamed = false;
6011
6068
  let tagHandle = "";
6012
6069
  let tagName;
6013
- let ch = this.peek();
6070
+ let ch = this.#scanner.peek();
6014
6071
  if (ch !== EXCLAMATION) return;
6015
6072
  if (tag !== null) {
6016
6073
  throw this.#createError("Cannot read tag property: duplication of a tag property");
6017
6074
  }
6018
- ch = this.next();
6075
+ this.#scanner.next();
6076
+ ch = this.#scanner.peek();
6019
6077
  if (ch === SMALLER_THAN) {
6020
6078
  isVerbatim = true;
6021
- ch = this.next();
6079
+ this.#scanner.next();
6080
+ ch = this.#scanner.peek();
6022
6081
  } else if (ch === EXCLAMATION) {
6023
6082
  isNamed = true;
6024
6083
  tagHandle = "!!";
6025
- ch = this.next();
6084
+ this.#scanner.next();
6085
+ ch = this.#scanner.peek();
6026
6086
  } else {
6027
6087
  tagHandle = "!";
6028
6088
  }
6029
- let position = this.position;
6089
+ let position = this.#scanner.position;
6030
6090
  if (isVerbatim) {
6031
6091
  do {
6032
- ch = this.next();
6092
+ this.#scanner.next();
6093
+ ch = this.#scanner.peek();
6033
6094
  } while (ch !== 0 && ch !== GREATER_THAN);
6034
- if (this.position < this.length) {
6035
- tagName = this.input.slice(position, this.position);
6036
- ch = this.next();
6095
+ if (!this.#scanner.eof()) {
6096
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
6097
+ this.#scanner.next();
6098
+ ch = this.#scanner.peek();
6037
6099
  } else {
6038
6100
  throw this.#createError("Cannot read tag property: unexpected end of stream");
6039
6101
  }
@@ -6041,19 +6103,20 @@ var LoaderState = class {
6041
6103
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
6042
6104
  if (ch === EXCLAMATION) {
6043
6105
  if (!isNamed) {
6044
- tagHandle = this.input.slice(position - 1, this.position + 1);
6106
+ tagHandle = this.#scanner.source.slice(position - 1, this.#scanner.position + 1);
6045
6107
  if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
6046
6108
  throw this.#createError("Cannot read tag property: named tag handle contains invalid characters");
6047
6109
  }
6048
6110
  isNamed = true;
6049
- position = this.position + 1;
6111
+ position = this.#scanner.position + 1;
6050
6112
  } else {
6051
6113
  throw this.#createError("Cannot read tag property: tag suffix cannot contain an exclamation mark");
6052
6114
  }
6053
6115
  }
6054
- ch = this.next();
6116
+ this.#scanner.next();
6117
+ ch = this.#scanner.peek();
6055
6118
  }
6056
- tagName = this.input.slice(position, this.position);
6119
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
6057
6120
  if (PATTERN_FLOW_INDICATORS.test(tagName)) {
6058
6121
  throw this.#createError("Cannot read tag property: tag suffix cannot contain flow indicator characters");
6059
6122
  }
@@ -6073,32 +6136,36 @@ var LoaderState = class {
6073
6136
  throw this.#createError(`Cannot read tag property: undeclared tag handle "${tagHandle}"`);
6074
6137
  }
6075
6138
  readAnchorProperty(anchor) {
6076
- let ch = this.peek();
6139
+ let ch = this.#scanner.peek();
6077
6140
  if (ch !== AMPERSAND) return;
6078
6141
  if (anchor !== null) {
6079
6142
  throw this.#createError("Cannot read anchor property: duplicate anchor property");
6080
6143
  }
6081
- ch = this.next();
6082
- const position = this.position;
6144
+ this.#scanner.next();
6145
+ ch = this.#scanner.peek();
6146
+ const position = this.#scanner.position;
6083
6147
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
6084
- ch = this.next();
6148
+ this.#scanner.next();
6149
+ ch = this.#scanner.peek();
6085
6150
  }
6086
- if (this.position === position) {
6151
+ if (this.#scanner.position === position) {
6087
6152
  throw this.#createError("Cannot read anchor property: name of an anchor node must contain at least one character");
6088
6153
  }
6089
- return this.input.slice(position, this.position);
6154
+ return this.#scanner.source.slice(position, this.#scanner.position);
6090
6155
  }
6091
6156
  readAlias() {
6092
- if (this.peek() !== ASTERISK) return;
6093
- let ch = this.next();
6094
- const position = this.position;
6157
+ if (this.#scanner.peek() !== ASTERISK) return;
6158
+ this.#scanner.next();
6159
+ let ch = this.#scanner.peek();
6160
+ const position = this.#scanner.position;
6095
6161
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
6096
- ch = this.next();
6162
+ this.#scanner.next();
6163
+ ch = this.#scanner.peek();
6097
6164
  }
6098
- if (this.position === position) {
6165
+ if (this.#scanner.position === position) {
6099
6166
  throw this.#createError("Cannot read alias: alias name must contain at least one character");
6100
6167
  }
6101
- const alias = this.input.slice(position, this.position);
6168
+ const alias = this.#scanner.source.slice(position, this.#scanner.position);
6102
6169
  if (!this.anchorMap.has(alias)) {
6103
6170
  throw this.#createError(`Cannot read alias: unidentified alias "${alias}"`);
6104
6171
  }
@@ -6181,7 +6248,7 @@ var LoaderState = class {
6181
6248
  const cond = CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext;
6182
6249
  const flowIndent = cond ? parentIndent : parentIndent + 1;
6183
6250
  if (allowBlockCollections) {
6184
- const blockIndent = this.position - this.lineStart;
6251
+ const blockIndent = this.#scanner.position - this.lineStart;
6185
6252
  const blockSequenceState = this.readBlockSequence(tag, anchor, blockIndent);
6186
6253
  if (blockSequenceState) return this.resolveTag(blockSequenceState);
6187
6254
  const blockMappingState = this.readBlockMapping(tag, anchor, blockIndent, flowIndent);
@@ -6215,7 +6282,7 @@ var LoaderState = class {
6215
6282
  return this.resolveTag(plainScalarState);
6216
6283
  }
6217
6284
  } else if (indentStatus === 0 && CONTEXT_BLOCK_OUT === nodeContext && allowBlockCollections) {
6218
- const blockIndent = this.position - this.lineStart;
6285
+ const blockIndent = this.#scanner.position - this.lineStart;
6219
6286
  const newState2 = this.readBlockSequence(tag, anchor, blockIndent);
6220
6287
  if (newState2) return this.resolveTag(newState2);
6221
6288
  }
@@ -6230,20 +6297,22 @@ var LoaderState = class {
6230
6297
  readDirectives() {
6231
6298
  let hasDirectives = false;
6232
6299
  let version = null;
6233
- let ch = this.peek();
6300
+ let ch = this.#scanner.peek();
6234
6301
  while (ch !== 0) {
6235
6302
  this.skipSeparationSpace(true, -1);
6236
- ch = this.peek();
6303
+ ch = this.#scanner.peek();
6237
6304
  if (this.lineIndent > 0 || ch !== PERCENT) {
6238
6305
  break;
6239
6306
  }
6240
6307
  hasDirectives = true;
6241
- ch = this.next();
6242
- let position = this.position;
6308
+ this.#scanner.next();
6309
+ ch = this.#scanner.peek();
6310
+ let position = this.#scanner.position;
6243
6311
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
6244
- ch = this.next();
6312
+ this.#scanner.next();
6313
+ ch = this.#scanner.peek();
6245
6314
  }
6246
- const directiveName = this.input.slice(position, this.position);
6315
+ const directiveName = this.#scanner.source.slice(position, this.#scanner.position);
6247
6316
  const directiveArgs = [];
6248
6317
  if (directiveName.length < 1) {
6249
6318
  throw this.#createError("Cannot read document: directive name length must be greater than zero");
@@ -6251,13 +6320,14 @@ var LoaderState = class {
6251
6320
  while (ch !== 0) {
6252
6321
  this.skipWhitespaces();
6253
6322
  this.skipComment();
6254
- ch = this.peek();
6323
+ ch = this.#scanner.peek();
6255
6324
  if (isEOL(ch)) break;
6256
- position = this.position;
6325
+ position = this.#scanner.position;
6257
6326
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
6258
- ch = this.next();
6327
+ this.#scanner.next();
6328
+ ch = this.#scanner.peek();
6259
6329
  }
6260
- directiveArgs.push(this.input.slice(position, this.position));
6330
+ directiveArgs.push(this.#scanner.source.slice(position, this.#scanner.position));
6261
6331
  }
6262
6332
  if (ch !== 0) this.readLineBreak();
6263
6333
  switch (directiveName) {
@@ -6274,20 +6344,20 @@ var LoaderState = class {
6274
6344
  this.dispatchWarning(`unknown document directive "${directiveName}"`);
6275
6345
  break;
6276
6346
  }
6277
- ch = this.peek();
6347
+ ch = this.#scanner.peek();
6278
6348
  }
6279
6349
  return hasDirectives;
6280
6350
  }
6281
6351
  readDocument() {
6282
- const documentStart = this.position;
6352
+ const documentStart = this.#scanner.position;
6283
6353
  this.checkLineBreaks = false;
6284
6354
  this.tagMap = /* @__PURE__ */ new Map();
6285
6355
  this.anchorMap = /* @__PURE__ */ new Map();
6286
6356
  const hasDirectives = this.readDirectives();
6287
6357
  this.skipSeparationSpace(true, -1);
6288
6358
  let result = null;
6289
- if (this.lineIndent === 0 && this.peek() === MINUS && this.peek(1) === MINUS && this.peek(2) === MINUS) {
6290
- this.position += 3;
6359
+ if (this.lineIndent === 0 && this.#scanner.peek() === MINUS && this.#scanner.peek(1) === MINUS && this.#scanner.peek(2) === MINUS) {
6360
+ this.#scanner.position += 3;
6291
6361
  this.skipSeparationSpace(true, -1);
6292
6362
  } else if (hasDirectives) {
6293
6363
  throw this.#createError("Cannot read document: directives end mark is expected");
@@ -6300,21 +6370,21 @@ var LoaderState = class {
6300
6370
  });
6301
6371
  if (newState) result = newState.result;
6302
6372
  this.skipSeparationSpace(true, -1);
6303
- if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.input.slice(documentStart, this.position))) {
6373
+ if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.#scanner.source.slice(documentStart, this.#scanner.position))) {
6304
6374
  this.dispatchWarning("non-ASCII line breaks are interpreted as content");
6305
6375
  }
6306
- if (this.position === this.lineStart && this.testDocumentSeparator()) {
6307
- if (this.peek() === DOT) {
6308
- this.position += 3;
6376
+ if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
6377
+ if (this.#scanner.peek() === DOT) {
6378
+ this.#scanner.position += 3;
6309
6379
  this.skipSeparationSpace(true, -1);
6310
6380
  }
6311
- } else if (this.position < this.length - 1) {
6381
+ } else if (!this.#scanner.eof()) {
6312
6382
  throw this.#createError("Cannot read document: end of the stream or a document separator is expected");
6313
6383
  }
6314
6384
  return result;
6315
6385
  }
6316
6386
  *readDocuments() {
6317
- while (this.position < this.length - 1) {
6387
+ while (!this.#scanner.eof()) {
6318
6388
  yield this.readDocument();
6319
6389
  }
6320
6390
  }
@@ -6327,7 +6397,6 @@ function sanitizeInput(input) {
6327
6397
  if (!isEOL(input.charCodeAt(input.length - 1))) input += "\n";
6328
6398
  if (input.charCodeAt(0) === 65279) input = input.slice(1);
6329
6399
  }
6330
- input += "\0";
6331
6400
  return input;
6332
6401
  }
6333
6402
  function parse(content, options = {}) {
@@ -6487,7 +6556,7 @@ function getDefaultAgents() {
6487
6556
  }
6488
6557
 
6489
6558
  // __mcpc__cli_latest/node_modules/@mcpc/cli/src/config/loader.js
6490
- var CLI_VERSION = "0.1.44";
6559
+ var CLI_VERSION = "0.1.51";
6491
6560
  function extractServerName(command, commandArgs) {
6492
6561
  for (const arg of commandArgs) {
6493
6562
  if (!arg.startsWith("-")) {
@@ -8168,6 +8237,147 @@ var ExperimentalServerTasks = class {
8168
8237
  requestStream(request, resultSchema, options) {
8169
8238
  return this._server.requestStream(request, resultSchema, options);
8170
8239
  }
8240
+ /**
8241
+ * Sends a sampling request and returns an AsyncGenerator that yields response messages.
8242
+ * The generator is guaranteed to end with either a 'result' or 'error' message.
8243
+ *
8244
+ * For task-augmented requests, yields 'taskCreated' and 'taskStatus' messages
8245
+ * before the final result.
8246
+ *
8247
+ * @example
8248
+ * ```typescript
8249
+ * const stream = server.experimental.tasks.createMessageStream({
8250
+ * messages: [{ role: 'user', content: { type: 'text', text: 'Hello' } }],
8251
+ * maxTokens: 100
8252
+ * }, {
8253
+ * onprogress: (progress) => {
8254
+ * // Handle streaming tokens via progress notifications
8255
+ * console.log('Progress:', progress.message);
8256
+ * }
8257
+ * });
8258
+ *
8259
+ * for await (const message of stream) {
8260
+ * switch (message.type) {
8261
+ * case 'taskCreated':
8262
+ * console.log('Task created:', message.task.taskId);
8263
+ * break;
8264
+ * case 'taskStatus':
8265
+ * console.log('Task status:', message.task.status);
8266
+ * break;
8267
+ * case 'result':
8268
+ * console.log('Final result:', message.result);
8269
+ * break;
8270
+ * case 'error':
8271
+ * console.error('Error:', message.error);
8272
+ * break;
8273
+ * }
8274
+ * }
8275
+ * ```
8276
+ *
8277
+ * @param params - The sampling request parameters
8278
+ * @param options - Optional request options (timeout, signal, task creation params, onprogress, etc.)
8279
+ * @returns AsyncGenerator that yields ResponseMessage objects
8280
+ *
8281
+ * @experimental
8282
+ */
8283
+ createMessageStream(params, options) {
8284
+ const clientCapabilities = this._server.getClientCapabilities();
8285
+ if ((params.tools || params.toolChoice) && !clientCapabilities?.sampling?.tools) {
8286
+ throw new Error("Client does not support sampling tools capability.");
8287
+ }
8288
+ if (params.messages.length > 0) {
8289
+ const lastMessage = params.messages[params.messages.length - 1];
8290
+ const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];
8291
+ const hasToolResults = lastContent.some((c) => c.type === "tool_result");
8292
+ const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : void 0;
8293
+ const previousContent = previousMessage ? Array.isArray(previousMessage.content) ? previousMessage.content : [previousMessage.content] : [];
8294
+ const hasPreviousToolUse = previousContent.some((c) => c.type === "tool_use");
8295
+ if (hasToolResults) {
8296
+ if (lastContent.some((c) => c.type !== "tool_result")) {
8297
+ throw new Error("The last message must contain only tool_result content if any is present");
8298
+ }
8299
+ if (!hasPreviousToolUse) {
8300
+ throw new Error("tool_result blocks are not matching any tool_use from the previous message");
8301
+ }
8302
+ }
8303
+ if (hasPreviousToolUse) {
8304
+ const toolUseIds = new Set(previousContent.filter((c) => c.type === "tool_use").map((c) => c.id));
8305
+ const toolResultIds = new Set(lastContent.filter((c) => c.type === "tool_result").map((c) => c.toolUseId));
8306
+ if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((id) => toolResultIds.has(id))) {
8307
+ throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match");
8308
+ }
8309
+ }
8310
+ }
8311
+ return this.requestStream({
8312
+ method: "sampling/createMessage",
8313
+ params
8314
+ }, CreateMessageResultSchema, options);
8315
+ }
8316
+ /**
8317
+ * Sends an elicitation request and returns an AsyncGenerator that yields response messages.
8318
+ * The generator is guaranteed to end with either a 'result' or 'error' message.
8319
+ *
8320
+ * For task-augmented requests (especially URL-based elicitation), yields 'taskCreated'
8321
+ * and 'taskStatus' messages before the final result.
8322
+ *
8323
+ * @example
8324
+ * ```typescript
8325
+ * const stream = server.experimental.tasks.elicitInputStream({
8326
+ * mode: 'url',
8327
+ * message: 'Please authenticate',
8328
+ * elicitationId: 'auth-123',
8329
+ * url: 'https://example.com/auth'
8330
+ * }, {
8331
+ * task: { ttl: 300000 } // Task-augmented for long-running auth flow
8332
+ * });
8333
+ *
8334
+ * for await (const message of stream) {
8335
+ * switch (message.type) {
8336
+ * case 'taskCreated':
8337
+ * console.log('Task created:', message.task.taskId);
8338
+ * break;
8339
+ * case 'taskStatus':
8340
+ * console.log('Task status:', message.task.status);
8341
+ * break;
8342
+ * case 'result':
8343
+ * console.log('User action:', message.result.action);
8344
+ * break;
8345
+ * case 'error':
8346
+ * console.error('Error:', message.error);
8347
+ * break;
8348
+ * }
8349
+ * }
8350
+ * ```
8351
+ *
8352
+ * @param params - The elicitation request parameters
8353
+ * @param options - Optional request options (timeout, signal, task creation params, etc.)
8354
+ * @returns AsyncGenerator that yields ResponseMessage objects
8355
+ *
8356
+ * @experimental
8357
+ */
8358
+ elicitInputStream(params, options) {
8359
+ const clientCapabilities = this._server.getClientCapabilities();
8360
+ const mode = params.mode ?? "form";
8361
+ switch (mode) {
8362
+ case "url": {
8363
+ if (!clientCapabilities?.elicitation?.url) {
8364
+ throw new Error("Client does not support url elicitation.");
8365
+ }
8366
+ break;
8367
+ }
8368
+ case "form": {
8369
+ if (!clientCapabilities?.elicitation?.form) {
8370
+ throw new Error("Client does not support form elicitation.");
8371
+ }
8372
+ break;
8373
+ }
8374
+ }
8375
+ const normalizedParams = mode === "form" && params.mode === void 0 ? { ...params, mode: "form" } : params;
8376
+ return this.requestStream({
8377
+ method: "elicitation/create",
8378
+ params: normalizedParams
8379
+ }, ElicitResultSchema, options);
8380
+ }
8171
8381
  /**
8172
8382
  * Gets the current status of a task.
8173
8383
  *
@@ -10386,22 +10596,45 @@ async function auth(provider, options) {
10386
10596
  }
10387
10597
  }
10388
10598
  async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
10599
+ const cachedState = await provider.discoveryState?.();
10389
10600
  let resourceMetadata;
10390
10601
  let authorizationServerUrl;
10391
- try {
10392
- resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl }, fetchFn);
10393
- if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
10394
- authorizationServerUrl = resourceMetadata.authorization_servers[0];
10602
+ let metadata;
10603
+ let effectiveResourceMetadataUrl = resourceMetadataUrl;
10604
+ if (!effectiveResourceMetadataUrl && cachedState?.resourceMetadataUrl) {
10605
+ effectiveResourceMetadataUrl = new URL(cachedState.resourceMetadataUrl);
10606
+ }
10607
+ if (cachedState?.authorizationServerUrl) {
10608
+ authorizationServerUrl = cachedState.authorizationServerUrl;
10609
+ resourceMetadata = cachedState.resourceMetadata;
10610
+ metadata = cachedState.authorizationServerMetadata ?? await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn });
10611
+ if (!resourceMetadata) {
10612
+ try {
10613
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl }, fetchFn);
10614
+ } catch {
10615
+ }
10395
10616
  }
10396
- } catch {
10397
- }
10398
- if (!authorizationServerUrl) {
10399
- authorizationServerUrl = new URL("/", serverUrl);
10617
+ if (metadata !== cachedState.authorizationServerMetadata || resourceMetadata !== cachedState.resourceMetadata) {
10618
+ await provider.saveDiscoveryState?.({
10619
+ authorizationServerUrl: String(authorizationServerUrl),
10620
+ resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
10621
+ resourceMetadata,
10622
+ authorizationServerMetadata: metadata
10623
+ });
10624
+ }
10625
+ } else {
10626
+ const serverInfo = await discoverOAuthServerInfo(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl, fetchFn });
10627
+ authorizationServerUrl = serverInfo.authorizationServerUrl;
10628
+ metadata = serverInfo.authorizationServerMetadata;
10629
+ resourceMetadata = serverInfo.resourceMetadata;
10630
+ await provider.saveDiscoveryState?.({
10631
+ authorizationServerUrl: String(authorizationServerUrl),
10632
+ resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
10633
+ resourceMetadata,
10634
+ authorizationServerMetadata: metadata
10635
+ });
10400
10636
  }
10401
10637
  const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
10402
- const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, {
10403
- fetchFn
10404
- });
10405
10638
  let clientInformation = await Promise.resolve(provider.clientInformation());
10406
10639
  if (!clientInformation) {
10407
10640
  if (authorizationCode !== void 0) {
@@ -10656,6 +10889,26 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
10656
10889
  }
10657
10890
  return void 0;
10658
10891
  }
10892
+ async function discoverOAuthServerInfo(serverUrl, opts) {
10893
+ let resourceMetadata;
10894
+ let authorizationServerUrl;
10895
+ try {
10896
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: opts?.resourceMetadataUrl }, opts?.fetchFn);
10897
+ if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
10898
+ authorizationServerUrl = resourceMetadata.authorization_servers[0];
10899
+ }
10900
+ } catch {
10901
+ }
10902
+ if (!authorizationServerUrl) {
10903
+ authorizationServerUrl = String(new URL("/", serverUrl));
10904
+ }
10905
+ const authorizationServerMetadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn: opts?.fetchFn });
10906
+ return {
10907
+ authorizationServerUrl,
10908
+ authorizationServerMetadata,
10909
+ resourceMetadata
10910
+ };
10911
+ }
10659
10912
  async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
10660
10913
  let authorizationUrl;
10661
10914
  if (metadata) {
@@ -11520,18 +11773,6 @@ var cleanToolSchema = (schema) => {
11520
11773
  import { cwd } from "node:process";
11521
11774
  import process7 from "node:process";
11522
11775
  import { createHash } from "node:crypto";
11523
- var mcpClientPool = /* @__PURE__ */ new Map();
11524
- var mcpClientConnecting = /* @__PURE__ */ new Map();
11525
- var shortHash = (s) => createHash("sha256").update(s).digest("hex").slice(0, 8);
11526
- function defSignature(def) {
11527
- const defCopy = {
11528
- ...def
11529
- };
11530
- if (defCopy.transportType === "memory" || defCopy.transport) {
11531
- return `memory:${Date.now()}:${Math.random()}`;
11532
- }
11533
- return JSON.stringify(defCopy);
11534
- }
11535
11776
  function createTransport(def) {
11536
11777
  const defAny = def;
11537
11778
  const explicitType = defAny.transportType || defAny.type;
@@ -11579,90 +11820,43 @@ function createTransport(def) {
11579
11820
  }
11580
11821
  throw new Error(`Unsupported transport configuration: ${JSON.stringify(def)}`);
11581
11822
  }
11582
- async function getOrCreateMcpClient(defKey, def) {
11583
- const pooled = mcpClientPool.get(defKey);
11584
- if (pooled) {
11585
- pooled.refCount += 1;
11586
- return pooled.client;
11587
- }
11588
- const existingConnecting = mcpClientConnecting.get(defKey);
11589
- if (existingConnecting) {
11590
- const client = await existingConnecting;
11591
- const entry = mcpClientPool.get(defKey);
11592
- if (entry) entry.refCount += 1;
11593
- return client;
11594
- }
11595
- const transport = createTransport(def);
11596
- const connecting = (async () => {
11597
- const client = new Client({
11598
- name: `mcp_${shortHash(defSignature(def))}`,
11599
- version: "1.0.0"
11600
- });
11601
- await client.connect(transport, {
11602
- timeout: 6e4 * 10
11603
- });
11604
- return client;
11605
- })();
11606
- mcpClientConnecting.set(defKey, connecting);
11607
- try {
11608
- const client = await connecting;
11609
- mcpClientPool.set(defKey, {
11610
- client,
11611
- refCount: 1
11612
- });
11613
- return client;
11614
- } finally {
11615
- mcpClientConnecting.delete(defKey);
11823
+ function defSignature(def) {
11824
+ const defCopy = {
11825
+ ...def
11826
+ };
11827
+ if (defCopy.transportType === "memory" || defCopy.transport) {
11828
+ return `memory:${Date.now()}:${Math.random()}`;
11616
11829
  }
11830
+ return JSON.stringify(defCopy);
11617
11831
  }
11618
- async function releaseMcpClient(defKey) {
11619
- const entry = mcpClientPool.get(defKey);
11620
- if (!entry) return;
11621
- entry.refCount -= 1;
11622
- if (entry.refCount <= 0) {
11623
- mcpClientPool.delete(defKey);
11624
- try {
11625
- await entry.client.close();
11626
- } catch (err) {
11627
- console.error("Error closing MCP client:", err);
11628
- }
11629
- }
11832
+ var shortHash = (s) => createHash("sha256").update(s).digest("hex").slice(0, 8);
11833
+ async function createMcpClient(def) {
11834
+ const transport = createTransport(def);
11835
+ const client = new Client({
11836
+ name: `mcp_${shortHash(defSignature(def))}`,
11837
+ version: "1.0.0"
11838
+ });
11839
+ await client.connect(transport, {
11840
+ timeout: 6e4 * 10
11841
+ });
11842
+ return client;
11630
11843
  }
11631
- var cleanupAllPooledClients = async () => {
11632
- const entries = Array.from(mcpClientPool.entries());
11633
- mcpClientPool.clear();
11634
- await Promise.all(entries.map(async ([, { client }]) => {
11635
- try {
11636
- await client.close();
11637
- } catch (err) {
11638
- console.error("Error closing MCP client:", err);
11639
- }
11640
- }));
11641
- };
11642
- process7.once?.("exit", () => {
11643
- cleanupAllPooledClients();
11644
- });
11645
- process7.once?.("SIGINT", () => {
11646
- cleanupAllPooledClients().finally(() => process7.exit(0));
11647
- });
11648
11844
  async function composeMcpDepTools(mcpConfig, filterIn) {
11649
11845
  const allTools = {};
11650
11846
  const allClients = {};
11651
- const acquiredKeys = [];
11847
+ const clientsToClose = [];
11652
11848
  for (const [name, definition] of Object.entries(mcpConfig.mcpServers)) {
11653
11849
  const def = definition;
11654
11850
  if (def.disabled) continue;
11655
- const defKey = shortHash(defSignature(def));
11656
- const serverId = name;
11657
11851
  try {
11658
- const client = await getOrCreateMcpClient(defKey, def);
11659
- acquiredKeys.push(defKey);
11660
- allClients[serverId] = client;
11852
+ const client = await createMcpClient(def);
11853
+ clientsToClose.push(client);
11854
+ allClients[name] = client;
11661
11855
  const { tools } = await client.listTools();
11662
11856
  tools.forEach((tool2) => {
11663
11857
  const toolNameWithScope = `${name}.${tool2.name}`;
11664
11858
  const internalToolName = tool2.name;
11665
- const rawToolId = `${serverId}_${internalToolName}`;
11859
+ const rawToolId = `${name}_${internalToolName}`;
11666
11860
  const toolId = sanitizePropertyKey(rawToolId);
11667
11861
  if (filterIn && !filterIn({
11668
11862
  action: internalToolName,
@@ -11674,7 +11868,7 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
11674
11868
  })) {
11675
11869
  return;
11676
11870
  }
11677
- const execute = (args) => allClients[serverId].callTool({
11871
+ const execute = (args) => allClients[name].callTool({
11678
11872
  name: internalToolName,
11679
11873
  arguments: args
11680
11874
  }, void 0, {
@@ -11691,10 +11885,12 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
11691
11885
  }
11692
11886
  }
11693
11887
  const cleanupClients = async () => {
11694
- await Promise.all(acquiredKeys.map((k) => releaseMcpClient(k)));
11695
- acquiredKeys.length = 0;
11696
- Object.keys(allTools).forEach((key) => delete allTools[key]);
11697
- Object.keys(allClients).forEach((key) => delete allClients[key]);
11888
+ await Promise.all(clientsToClose.map((client) => {
11889
+ try {
11890
+ return client.close();
11891
+ } catch {
11892
+ }
11893
+ }));
11698
11894
  };
11699
11895
  return {
11700
11896
  tools: allTools,