@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/app.mjs CHANGED
@@ -3496,6 +3496,147 @@ var ExperimentalServerTasks = class {
3496
3496
  requestStream(request, resultSchema, options) {
3497
3497
  return this._server.requestStream(request, resultSchema, options);
3498
3498
  }
3499
+ /**
3500
+ * Sends a sampling request and returns an AsyncGenerator that yields response messages.
3501
+ * The generator is guaranteed to end with either a 'result' or 'error' message.
3502
+ *
3503
+ * For task-augmented requests, yields 'taskCreated' and 'taskStatus' messages
3504
+ * before the final result.
3505
+ *
3506
+ * @example
3507
+ * ```typescript
3508
+ * const stream = server.experimental.tasks.createMessageStream({
3509
+ * messages: [{ role: 'user', content: { type: 'text', text: 'Hello' } }],
3510
+ * maxTokens: 100
3511
+ * }, {
3512
+ * onprogress: (progress) => {
3513
+ * // Handle streaming tokens via progress notifications
3514
+ * console.log('Progress:', progress.message);
3515
+ * }
3516
+ * });
3517
+ *
3518
+ * for await (const message of stream) {
3519
+ * switch (message.type) {
3520
+ * case 'taskCreated':
3521
+ * console.log('Task created:', message.task.taskId);
3522
+ * break;
3523
+ * case 'taskStatus':
3524
+ * console.log('Task status:', message.task.status);
3525
+ * break;
3526
+ * case 'result':
3527
+ * console.log('Final result:', message.result);
3528
+ * break;
3529
+ * case 'error':
3530
+ * console.error('Error:', message.error);
3531
+ * break;
3532
+ * }
3533
+ * }
3534
+ * ```
3535
+ *
3536
+ * @param params - The sampling request parameters
3537
+ * @param options - Optional request options (timeout, signal, task creation params, onprogress, etc.)
3538
+ * @returns AsyncGenerator that yields ResponseMessage objects
3539
+ *
3540
+ * @experimental
3541
+ */
3542
+ createMessageStream(params, options) {
3543
+ const clientCapabilities = this._server.getClientCapabilities();
3544
+ if ((params.tools || params.toolChoice) && !clientCapabilities?.sampling?.tools) {
3545
+ throw new Error("Client does not support sampling tools capability.");
3546
+ }
3547
+ if (params.messages.length > 0) {
3548
+ const lastMessage = params.messages[params.messages.length - 1];
3549
+ const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];
3550
+ const hasToolResults = lastContent.some((c) => c.type === "tool_result");
3551
+ const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : void 0;
3552
+ const previousContent = previousMessage ? Array.isArray(previousMessage.content) ? previousMessage.content : [previousMessage.content] : [];
3553
+ const hasPreviousToolUse = previousContent.some((c) => c.type === "tool_use");
3554
+ if (hasToolResults) {
3555
+ if (lastContent.some((c) => c.type !== "tool_result")) {
3556
+ throw new Error("The last message must contain only tool_result content if any is present");
3557
+ }
3558
+ if (!hasPreviousToolUse) {
3559
+ throw new Error("tool_result blocks are not matching any tool_use from the previous message");
3560
+ }
3561
+ }
3562
+ if (hasPreviousToolUse) {
3563
+ const toolUseIds = new Set(previousContent.filter((c) => c.type === "tool_use").map((c) => c.id));
3564
+ const toolResultIds = new Set(lastContent.filter((c) => c.type === "tool_result").map((c) => c.toolUseId));
3565
+ if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((id) => toolResultIds.has(id))) {
3566
+ throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match");
3567
+ }
3568
+ }
3569
+ }
3570
+ return this.requestStream({
3571
+ method: "sampling/createMessage",
3572
+ params
3573
+ }, CreateMessageResultSchema, options);
3574
+ }
3575
+ /**
3576
+ * Sends an elicitation request and returns an AsyncGenerator that yields response messages.
3577
+ * The generator is guaranteed to end with either a 'result' or 'error' message.
3578
+ *
3579
+ * For task-augmented requests (especially URL-based elicitation), yields 'taskCreated'
3580
+ * and 'taskStatus' messages before the final result.
3581
+ *
3582
+ * @example
3583
+ * ```typescript
3584
+ * const stream = server.experimental.tasks.elicitInputStream({
3585
+ * mode: 'url',
3586
+ * message: 'Please authenticate',
3587
+ * elicitationId: 'auth-123',
3588
+ * url: 'https://example.com/auth'
3589
+ * }, {
3590
+ * task: { ttl: 300000 } // Task-augmented for long-running auth flow
3591
+ * });
3592
+ *
3593
+ * for await (const message of stream) {
3594
+ * switch (message.type) {
3595
+ * case 'taskCreated':
3596
+ * console.log('Task created:', message.task.taskId);
3597
+ * break;
3598
+ * case 'taskStatus':
3599
+ * console.log('Task status:', message.task.status);
3600
+ * break;
3601
+ * case 'result':
3602
+ * console.log('User action:', message.result.action);
3603
+ * break;
3604
+ * case 'error':
3605
+ * console.error('Error:', message.error);
3606
+ * break;
3607
+ * }
3608
+ * }
3609
+ * ```
3610
+ *
3611
+ * @param params - The elicitation request parameters
3612
+ * @param options - Optional request options (timeout, signal, task creation params, etc.)
3613
+ * @returns AsyncGenerator that yields ResponseMessage objects
3614
+ *
3615
+ * @experimental
3616
+ */
3617
+ elicitInputStream(params, options) {
3618
+ const clientCapabilities = this._server.getClientCapabilities();
3619
+ const mode = params.mode ?? "form";
3620
+ switch (mode) {
3621
+ case "url": {
3622
+ if (!clientCapabilities?.elicitation?.url) {
3623
+ throw new Error("Client does not support url elicitation.");
3624
+ }
3625
+ break;
3626
+ }
3627
+ case "form": {
3628
+ if (!clientCapabilities?.elicitation?.form) {
3629
+ throw new Error("Client does not support form elicitation.");
3630
+ }
3631
+ break;
3632
+ }
3633
+ }
3634
+ const normalizedParams = mode === "form" && params.mode === void 0 ? { ...params, mode: "form" } : params;
3635
+ return this.requestStream({
3636
+ method: "elicitation/create",
3637
+ params: normalizedParams
3638
+ }, ElicitResultSchema, options);
3639
+ }
3499
3640
  /**
3500
3641
  * Gets the current status of a task.
3501
3642
  *
@@ -5714,22 +5855,45 @@ async function auth(provider, options) {
5714
5855
  }
5715
5856
  }
5716
5857
  async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
5858
+ const cachedState = await provider.discoveryState?.();
5717
5859
  let resourceMetadata;
5718
5860
  let authorizationServerUrl;
5719
- try {
5720
- resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl }, fetchFn);
5721
- if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
5722
- authorizationServerUrl = resourceMetadata.authorization_servers[0];
5861
+ let metadata;
5862
+ let effectiveResourceMetadataUrl = resourceMetadataUrl;
5863
+ if (!effectiveResourceMetadataUrl && cachedState?.resourceMetadataUrl) {
5864
+ effectiveResourceMetadataUrl = new URL(cachedState.resourceMetadataUrl);
5865
+ }
5866
+ if (cachedState?.authorizationServerUrl) {
5867
+ authorizationServerUrl = cachedState.authorizationServerUrl;
5868
+ resourceMetadata = cachedState.resourceMetadata;
5869
+ metadata = cachedState.authorizationServerMetadata ?? await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn });
5870
+ if (!resourceMetadata) {
5871
+ try {
5872
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl }, fetchFn);
5873
+ } catch {
5874
+ }
5723
5875
  }
5724
- } catch {
5725
- }
5726
- if (!authorizationServerUrl) {
5727
- authorizationServerUrl = new URL("/", serverUrl);
5876
+ if (metadata !== cachedState.authorizationServerMetadata || resourceMetadata !== cachedState.resourceMetadata) {
5877
+ await provider.saveDiscoveryState?.({
5878
+ authorizationServerUrl: String(authorizationServerUrl),
5879
+ resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
5880
+ resourceMetadata,
5881
+ authorizationServerMetadata: metadata
5882
+ });
5883
+ }
5884
+ } else {
5885
+ const serverInfo = await discoverOAuthServerInfo(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl, fetchFn });
5886
+ authorizationServerUrl = serverInfo.authorizationServerUrl;
5887
+ metadata = serverInfo.authorizationServerMetadata;
5888
+ resourceMetadata = serverInfo.resourceMetadata;
5889
+ await provider.saveDiscoveryState?.({
5890
+ authorizationServerUrl: String(authorizationServerUrl),
5891
+ resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
5892
+ resourceMetadata,
5893
+ authorizationServerMetadata: metadata
5894
+ });
5728
5895
  }
5729
5896
  const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
5730
- const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, {
5731
- fetchFn
5732
- });
5733
5897
  let clientInformation = await Promise.resolve(provider.clientInformation());
5734
5898
  if (!clientInformation) {
5735
5899
  if (authorizationCode !== void 0) {
@@ -5984,6 +6148,26 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
5984
6148
  }
5985
6149
  return void 0;
5986
6150
  }
6151
+ async function discoverOAuthServerInfo(serverUrl, opts) {
6152
+ let resourceMetadata;
6153
+ let authorizationServerUrl;
6154
+ try {
6155
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: opts?.resourceMetadataUrl }, opts?.fetchFn);
6156
+ if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
6157
+ authorizationServerUrl = resourceMetadata.authorization_servers[0];
6158
+ }
6159
+ } catch {
6160
+ }
6161
+ if (!authorizationServerUrl) {
6162
+ authorizationServerUrl = String(new URL("/", serverUrl));
6163
+ }
6164
+ const authorizationServerMetadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn: opts?.fetchFn });
6165
+ return {
6166
+ authorizationServerUrl,
6167
+ authorizationServerMetadata,
6168
+ resourceMetadata
6169
+ };
6170
+ }
5987
6171
  async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
5988
6172
  let authorizationUrl;
5989
6173
  if (metadata) {
@@ -6848,18 +7032,6 @@ var cleanToolSchema = (schema) => {
6848
7032
  import { cwd } from "node:process";
6849
7033
  import process4 from "node:process";
6850
7034
  import { createHash } from "node:crypto";
6851
- var mcpClientPool = /* @__PURE__ */ new Map();
6852
- var mcpClientConnecting = /* @__PURE__ */ new Map();
6853
- var shortHash = (s) => createHash("sha256").update(s).digest("hex").slice(0, 8);
6854
- function defSignature(def) {
6855
- const defCopy = {
6856
- ...def
6857
- };
6858
- if (defCopy.transportType === "memory" || defCopy.transport) {
6859
- return `memory:${Date.now()}:${Math.random()}`;
6860
- }
6861
- return JSON.stringify(defCopy);
6862
- }
6863
7035
  function createTransport(def) {
6864
7036
  const defAny = def;
6865
7037
  const explicitType = defAny.transportType || defAny.type;
@@ -6907,90 +7079,43 @@ function createTransport(def) {
6907
7079
  }
6908
7080
  throw new Error(`Unsupported transport configuration: ${JSON.stringify(def)}`);
6909
7081
  }
6910
- async function getOrCreateMcpClient(defKey, def) {
6911
- const pooled = mcpClientPool.get(defKey);
6912
- if (pooled) {
6913
- pooled.refCount += 1;
6914
- return pooled.client;
6915
- }
6916
- const existingConnecting = mcpClientConnecting.get(defKey);
6917
- if (existingConnecting) {
6918
- const client = await existingConnecting;
6919
- const entry = mcpClientPool.get(defKey);
6920
- if (entry) entry.refCount += 1;
6921
- return client;
6922
- }
6923
- const transport = createTransport(def);
6924
- const connecting = (async () => {
6925
- const client = new Client({
6926
- name: `mcp_${shortHash(defSignature(def))}`,
6927
- version: "1.0.0"
6928
- });
6929
- await client.connect(transport, {
6930
- timeout: 6e4 * 10
6931
- });
6932
- return client;
6933
- })();
6934
- mcpClientConnecting.set(defKey, connecting);
6935
- try {
6936
- const client = await connecting;
6937
- mcpClientPool.set(defKey, {
6938
- client,
6939
- refCount: 1
6940
- });
6941
- return client;
6942
- } finally {
6943
- mcpClientConnecting.delete(defKey);
7082
+ function defSignature(def) {
7083
+ const defCopy = {
7084
+ ...def
7085
+ };
7086
+ if (defCopy.transportType === "memory" || defCopy.transport) {
7087
+ return `memory:${Date.now()}:${Math.random()}`;
6944
7088
  }
7089
+ return JSON.stringify(defCopy);
6945
7090
  }
6946
- async function releaseMcpClient(defKey) {
6947
- const entry = mcpClientPool.get(defKey);
6948
- if (!entry) return;
6949
- entry.refCount -= 1;
6950
- if (entry.refCount <= 0) {
6951
- mcpClientPool.delete(defKey);
6952
- try {
6953
- await entry.client.close();
6954
- } catch (err) {
6955
- console.error("Error closing MCP client:", err);
6956
- }
6957
- }
7091
+ var shortHash = (s) => createHash("sha256").update(s).digest("hex").slice(0, 8);
7092
+ async function createMcpClient(def) {
7093
+ const transport = createTransport(def);
7094
+ const client = new Client({
7095
+ name: `mcp_${shortHash(defSignature(def))}`,
7096
+ version: "1.0.0"
7097
+ });
7098
+ await client.connect(transport, {
7099
+ timeout: 6e4 * 10
7100
+ });
7101
+ return client;
6958
7102
  }
6959
- var cleanupAllPooledClients = async () => {
6960
- const entries = Array.from(mcpClientPool.entries());
6961
- mcpClientPool.clear();
6962
- await Promise.all(entries.map(async ([, { client }]) => {
6963
- try {
6964
- await client.close();
6965
- } catch (err) {
6966
- console.error("Error closing MCP client:", err);
6967
- }
6968
- }));
6969
- };
6970
- process4.once?.("exit", () => {
6971
- cleanupAllPooledClients();
6972
- });
6973
- process4.once?.("SIGINT", () => {
6974
- cleanupAllPooledClients().finally(() => process4.exit(0));
6975
- });
6976
7103
  async function composeMcpDepTools(mcpConfig, filterIn) {
6977
7104
  const allTools = {};
6978
7105
  const allClients = {};
6979
- const acquiredKeys = [];
7106
+ const clientsToClose = [];
6980
7107
  for (const [name, definition] of Object.entries(mcpConfig.mcpServers)) {
6981
7108
  const def = definition;
6982
7109
  if (def.disabled) continue;
6983
- const defKey = shortHash(defSignature(def));
6984
- const serverId = name;
6985
7110
  try {
6986
- const client = await getOrCreateMcpClient(defKey, def);
6987
- acquiredKeys.push(defKey);
6988
- allClients[serverId] = client;
7111
+ const client = await createMcpClient(def);
7112
+ clientsToClose.push(client);
7113
+ allClients[name] = client;
6989
7114
  const { tools } = await client.listTools();
6990
7115
  tools.forEach((tool2) => {
6991
7116
  const toolNameWithScope = `${name}.${tool2.name}`;
6992
7117
  const internalToolName = tool2.name;
6993
- const rawToolId = `${serverId}_${internalToolName}`;
7118
+ const rawToolId = `${name}_${internalToolName}`;
6994
7119
  const toolId = sanitizePropertyKey(rawToolId);
6995
7120
  if (filterIn && !filterIn({
6996
7121
  action: internalToolName,
@@ -7002,7 +7127,7 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
7002
7127
  })) {
7003
7128
  return;
7004
7129
  }
7005
- const execute = (args) => allClients[serverId].callTool({
7130
+ const execute = (args) => allClients[name].callTool({
7006
7131
  name: internalToolName,
7007
7132
  arguments: args
7008
7133
  }, void 0, {
@@ -7019,10 +7144,12 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
7019
7144
  }
7020
7145
  }
7021
7146
  const cleanupClients = async () => {
7022
- await Promise.all(acquiredKeys.map((k) => releaseMcpClient(k)));
7023
- acquiredKeys.length = 0;
7024
- Object.keys(allTools).forEach((key) => delete allTools[key]);
7025
- Object.keys(allClients).forEach((key) => delete allClients[key]);
7147
+ await Promise.all(clientsToClose.map((client) => {
7148
+ try {
7149
+ return client.close();
7150
+ } catch {
7151
+ }
7152
+ }));
7026
7153
  };
7027
7154
  return {
7028
7155
  tools: allTools,
@@ -10778,7 +10905,7 @@ Usage:
10778
10905
  - ${toolName}({ skill: "skill-name" }) - Load main SKILL.md content
10779
10906
  - ${toolName}({ skill: "skill-name", ref: "path/to/file" }) - Load reference file
10780
10907
 
10781
- Note: For scripts/ and assets/, use appropriate tools directly.`;
10908
+ Note: For scripts/, use the bash tool with the script path to execute.`;
10782
10909
  }
10783
10910
  function createSkillsPlugin(options) {
10784
10911
  const { paths } = options;
@@ -10886,11 +11013,15 @@ Available skills: ${available.join(", ")}` : "\n\nNo skills available.";
10886
11013
  try {
10887
11014
  const content = await readFile(join2(meta.basePath, "SKILL.md"), "utf-8");
10888
11015
  const body = extractBody(content);
11016
+ const skillPathInfo = `
11017
+ ---
11018
+ Skill path: ${meta.basePath}
11019
+ `;
10889
11020
  return {
10890
11021
  content: [
10891
11022
  {
10892
11023
  type: "text",
10893
- text: body
11024
+ text: body + skillPathInfo
10894
11025
  }
10895
11026
  ]
10896
11027
  };
@@ -11761,12 +11892,29 @@ function writeFoldedLines(count) {
11761
11892
  if (count > 1) return "\n".repeat(count - 1);
11762
11893
  return "";
11763
11894
  }
11895
+ var Scanner = class {
11896
+ source;
11897
+ #length;
11898
+ position = 0;
11899
+ constructor(source) {
11900
+ source += "\0";
11901
+ this.source = source;
11902
+ this.#length = source.length;
11903
+ }
11904
+ peek(offset = 0) {
11905
+ return this.source.charCodeAt(this.position + offset);
11906
+ }
11907
+ next() {
11908
+ this.position += 1;
11909
+ }
11910
+ eof() {
11911
+ return this.position >= this.#length - 1;
11912
+ }
11913
+ };
11764
11914
  var LoaderState = class {
11765
- input;
11766
- length;
11915
+ #scanner;
11767
11916
  lineIndent = 0;
11768
11917
  lineStart = 0;
11769
- position = 0;
11770
11918
  line = 0;
11771
11919
  onWarning;
11772
11920
  allowDuplicateKeys;
@@ -11776,44 +11924,40 @@ var LoaderState = class {
11776
11924
  tagMap = /* @__PURE__ */ new Map();
11777
11925
  anchorMap = /* @__PURE__ */ new Map();
11778
11926
  constructor(input, { schema = DEFAULT_SCHEMA, onWarning, allowDuplicateKeys = false }) {
11779
- this.input = input;
11927
+ this.#scanner = new Scanner(input);
11780
11928
  this.onWarning = onWarning;
11781
11929
  this.allowDuplicateKeys = allowDuplicateKeys;
11782
11930
  this.implicitTypes = schema.implicitTypes;
11783
11931
  this.typeMap = schema.typeMap;
11784
- this.length = input.length;
11785
11932
  this.readIndent();
11786
11933
  }
11787
11934
  skipWhitespaces() {
11788
- let ch = this.peek();
11935
+ let ch = this.#scanner.peek();
11789
11936
  while (isWhiteSpace(ch)) {
11790
- ch = this.next();
11937
+ this.#scanner.next();
11938
+ ch = this.#scanner.peek();
11791
11939
  }
11792
11940
  }
11793
11941
  skipComment() {
11794
- let ch = this.peek();
11942
+ let ch = this.#scanner.peek();
11795
11943
  if (ch !== SHARP) return;
11796
- ch = this.next();
11944
+ this.#scanner.next();
11945
+ ch = this.#scanner.peek();
11797
11946
  while (ch !== 0 && !isEOL(ch)) {
11798
- ch = this.next();
11947
+ this.#scanner.next();
11948
+ ch = this.#scanner.peek();
11799
11949
  }
11800
11950
  }
11801
11951
  readIndent() {
11802
- let char = this.peek();
11803
- while (char === SPACE) {
11952
+ let ch = this.#scanner.peek();
11953
+ while (ch === SPACE) {
11804
11954
  this.lineIndent += 1;
11805
- char = this.next();
11955
+ this.#scanner.next();
11956
+ ch = this.#scanner.peek();
11806
11957
  }
11807
11958
  }
11808
- peek(offset = 0) {
11809
- return this.input.charCodeAt(this.position + offset);
11810
- }
11811
- next() {
11812
- this.position += 1;
11813
- return this.peek();
11814
- }
11815
11959
  #createError(message) {
11816
- const mark = markToString(this.input, this.position, this.line, this.position - this.lineStart);
11960
+ const mark = markToString(this.#scanner.source, this.#scanner.position, this.line, this.#scanner.position - this.lineStart);
11817
11961
  return new SyntaxError(`${message} ${mark}`);
11818
11962
  }
11819
11963
  dispatchWarning(message) {
@@ -11858,7 +12002,7 @@ var LoaderState = class {
11858
12002
  }
11859
12003
  captureSegment(start, end, checkJson) {
11860
12004
  if (start < end) {
11861
- const result = this.input.slice(start, end);
12005
+ const result = this.#scanner.source.slice(start, end);
11862
12006
  if (checkJson) {
11863
12007
  for (let position = 0; position < result.length; position++) {
11864
12008
  const character = result.charCodeAt(position);
@@ -11876,21 +12020,21 @@ var LoaderState = class {
11876
12020
  let detected = false;
11877
12021
  const result = [];
11878
12022
  if (anchor !== null) this.anchorMap.set(anchor, result);
11879
- let ch = this.peek();
12023
+ let ch = this.#scanner.peek();
11880
12024
  while (ch !== 0) {
11881
12025
  if (ch !== MINUS) {
11882
12026
  break;
11883
12027
  }
11884
- const following = this.peek(1);
12028
+ const following = this.#scanner.peek(1);
11885
12029
  if (!isWhiteSpaceOrEOL(following)) {
11886
12030
  break;
11887
12031
  }
11888
12032
  detected = true;
11889
- this.position++;
12033
+ this.#scanner.next();
11890
12034
  if (this.skipSeparationSpace(true, -1)) {
11891
12035
  if (this.lineIndent <= nodeIndent) {
11892
12036
  result.push(null);
11893
- ch = this.peek();
12037
+ ch = this.#scanner.peek();
11894
12038
  continue;
11895
12039
  }
11896
12040
  }
@@ -11903,7 +12047,7 @@ var LoaderState = class {
11903
12047
  });
11904
12048
  if (newState) result.push(newState.result);
11905
12049
  this.skipSeparationSpace(true, -1);
11906
- ch = this.peek();
12050
+ ch = this.#scanner.peek();
11907
12051
  if ((this.line === line || this.lineIndent > nodeIndent) && ch !== 0) {
11908
12052
  throw this.#createError("Cannot read block sequence: bad indentation of a sequence entry");
11909
12053
  } else if (this.lineIndent < nodeIndent) {
@@ -11959,7 +12103,7 @@ var LoaderState = class {
11959
12103
  } else {
11960
12104
  if (!this.allowDuplicateKeys && !overridableKeys.has(keyNode) && Object.hasOwn(result, keyNode)) {
11961
12105
  this.line = startLine || this.line;
11962
- this.position = startPos || this.position;
12106
+ this.#scanner.position = startPos || this.#scanner.position;
11963
12107
  throw this.#createError("Cannot store mapping pair: duplicated key");
11964
12108
  }
11965
12109
  Object.defineProperty(result, keyNode, {
@@ -11973,37 +12117,37 @@ var LoaderState = class {
11973
12117
  return result;
11974
12118
  }
11975
12119
  readLineBreak() {
11976
- const ch = this.peek();
12120
+ const ch = this.#scanner.peek();
11977
12121
  if (ch === LINE_FEED) {
11978
- this.position++;
12122
+ this.#scanner.next();
11979
12123
  } else if (ch === CARRIAGE_RETURN) {
11980
- this.position++;
11981
- if (this.peek() === LINE_FEED) {
11982
- this.position++;
12124
+ this.#scanner.next();
12125
+ if (this.#scanner.peek() === LINE_FEED) {
12126
+ this.#scanner.next();
11983
12127
  }
11984
12128
  } else {
11985
12129
  throw this.#createError("Cannot read line: line break not found");
11986
12130
  }
11987
12131
  this.line += 1;
11988
- this.lineStart = this.position;
12132
+ this.lineStart = this.#scanner.position;
11989
12133
  }
11990
12134
  skipSeparationSpace(allowComments, checkIndent) {
11991
12135
  let lineBreaks = 0;
11992
- let ch = this.peek();
12136
+ let ch = this.#scanner.peek();
11993
12137
  while (ch !== 0) {
11994
12138
  this.skipWhitespaces();
11995
- ch = this.peek();
12139
+ ch = this.#scanner.peek();
11996
12140
  if (allowComments) {
11997
12141
  this.skipComment();
11998
- ch = this.peek();
12142
+ ch = this.#scanner.peek();
11999
12143
  }
12000
12144
  if (isEOL(ch)) {
12001
12145
  this.readLineBreak();
12002
- ch = this.peek();
12146
+ ch = this.#scanner.peek();
12003
12147
  lineBreaks++;
12004
12148
  this.lineIndent = 0;
12005
12149
  this.readIndent();
12006
- ch = this.peek();
12150
+ ch = this.#scanner.peek();
12007
12151
  } else {
12008
12152
  break;
12009
12153
  }
@@ -12014,9 +12158,9 @@ var LoaderState = class {
12014
12158
  return lineBreaks;
12015
12159
  }
12016
12160
  testDocumentSeparator() {
12017
- let ch = this.peek();
12018
- if ((ch === MINUS || ch === DOT) && ch === this.peek(1) && ch === this.peek(2)) {
12019
- ch = this.peek(3);
12161
+ let ch = this.#scanner.peek();
12162
+ if ((ch === MINUS || ch === DOT) && ch === this.#scanner.peek(1) && ch === this.#scanner.peek(2)) {
12163
+ ch = this.#scanner.peek(3);
12020
12164
  if (ch === 0 || isWhiteSpaceOrEOL(ch)) {
12021
12165
  return true;
12022
12166
  }
@@ -12024,34 +12168,34 @@ var LoaderState = class {
12024
12168
  return false;
12025
12169
  }
12026
12170
  readPlainScalar(tag, anchor, nodeIndent, withinFlowCollection) {
12027
- let ch = this.peek();
12171
+ let ch = this.#scanner.peek();
12028
12172
  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) {
12029
12173
  return;
12030
12174
  }
12031
12175
  let following;
12032
12176
  if (ch === QUESTION || ch === MINUS) {
12033
- following = this.peek(1);
12177
+ following = this.#scanner.peek(1);
12034
12178
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
12035
12179
  return;
12036
12180
  }
12037
12181
  }
12038
12182
  let result = "";
12039
- let captureEnd = this.position;
12040
- let captureStart = this.position;
12183
+ let captureEnd = this.#scanner.position;
12184
+ let captureStart = this.#scanner.position;
12041
12185
  let hasPendingContent = false;
12042
12186
  let line = 0;
12043
12187
  while (ch !== 0) {
12044
12188
  if (ch === COLON) {
12045
- following = this.peek(1);
12189
+ following = this.#scanner.peek(1);
12046
12190
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
12047
12191
  break;
12048
12192
  }
12049
12193
  } else if (ch === SHARP) {
12050
- const preceding = this.peek(-1);
12194
+ const preceding = this.#scanner.peek(-1);
12051
12195
  if (isWhiteSpaceOrEOL(preceding)) {
12052
12196
  break;
12053
12197
  }
12054
- } else if (this.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
12198
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
12055
12199
  break;
12056
12200
  } else if (isEOL(ch)) {
12057
12201
  line = this.line;
@@ -12060,10 +12204,10 @@ var LoaderState = class {
12060
12204
  this.skipSeparationSpace(false, -1);
12061
12205
  if (this.lineIndent >= nodeIndent) {
12062
12206
  hasPendingContent = true;
12063
- ch = this.peek();
12207
+ ch = this.#scanner.peek();
12064
12208
  continue;
12065
12209
  } else {
12066
- this.position = captureEnd;
12210
+ this.#scanner.position = captureEnd;
12067
12211
  this.line = line;
12068
12212
  this.lineStart = lineStart;
12069
12213
  this.lineIndent = lineIndent;
@@ -12074,13 +12218,14 @@ var LoaderState = class {
12074
12218
  const segment2 = this.captureSegment(captureStart, captureEnd, false);
12075
12219
  if (segment2) result += segment2;
12076
12220
  result += writeFoldedLines(this.line - line);
12077
- captureStart = captureEnd = this.position;
12221
+ captureStart = captureEnd = this.#scanner.position;
12078
12222
  hasPendingContent = false;
12079
12223
  }
12080
12224
  if (!isWhiteSpace(ch)) {
12081
- captureEnd = this.position + 1;
12225
+ captureEnd = this.#scanner.position + 1;
12082
12226
  }
12083
- ch = this.next();
12227
+ this.#scanner.next();
12228
+ ch = this.#scanner.peek();
12084
12229
  }
12085
12230
  const segment = this.captureSegment(captureStart, captureEnd, false);
12086
12231
  if (segment) result += segment;
@@ -12093,22 +12238,23 @@ var LoaderState = class {
12093
12238
  };
12094
12239
  }
12095
12240
  readSingleQuotedScalar(tag, anchor, nodeIndent) {
12096
- let ch = this.peek();
12241
+ let ch = this.#scanner.peek();
12097
12242
  if (ch !== SINGLE_QUOTE) return;
12098
12243
  let result = "";
12099
- this.position++;
12100
- let captureStart = this.position;
12101
- let captureEnd = this.position;
12102
- ch = this.peek();
12244
+ this.#scanner.next();
12245
+ let captureStart = this.#scanner.position;
12246
+ let captureEnd = this.#scanner.position;
12247
+ ch = this.#scanner.peek();
12103
12248
  while (ch !== 0) {
12104
12249
  if (ch === SINGLE_QUOTE) {
12105
- const segment = this.captureSegment(captureStart, this.position, true);
12250
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
12106
12251
  if (segment) result += segment;
12107
- ch = this.next();
12252
+ this.#scanner.next();
12253
+ ch = this.#scanner.peek();
12108
12254
  if (ch === SINGLE_QUOTE) {
12109
- captureStart = this.position;
12110
- this.position++;
12111
- captureEnd = this.position;
12255
+ captureStart = this.#scanner.position;
12256
+ this.#scanner.next();
12257
+ captureEnd = this.#scanner.position;
12112
12258
  } else {
12113
12259
  if (anchor !== null) this.anchorMap.set(anchor, result);
12114
12260
  return {
@@ -12122,31 +12268,31 @@ var LoaderState = class {
12122
12268
  const segment = this.captureSegment(captureStart, captureEnd, true);
12123
12269
  if (segment) result += segment;
12124
12270
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
12125
- captureStart = captureEnd = this.position;
12126
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
12271
+ captureStart = captureEnd = this.#scanner.position;
12272
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
12127
12273
  throw this.#createError("Unexpected end of the document within a single quoted scalar");
12128
12274
  } else {
12129
- this.position++;
12130
- captureEnd = this.position;
12275
+ this.#scanner.next();
12276
+ captureEnd = this.#scanner.position;
12131
12277
  }
12132
- ch = this.peek();
12278
+ ch = this.#scanner.peek();
12133
12279
  }
12134
12280
  throw this.#createError("Unexpected end of the stream within a single quoted scalar");
12135
12281
  }
12136
12282
  readDoubleQuotedScalar(tag, anchor, nodeIndent) {
12137
- let ch = this.peek();
12283
+ let ch = this.#scanner.peek();
12138
12284
  if (ch !== DOUBLE_QUOTE) return;
12139
12285
  let result = "";
12140
- this.position++;
12141
- let captureEnd = this.position;
12142
- let captureStart = this.position;
12286
+ this.#scanner.next();
12287
+ let captureEnd = this.#scanner.position;
12288
+ let captureStart = this.#scanner.position;
12143
12289
  let tmp;
12144
- ch = this.peek();
12290
+ ch = this.#scanner.peek();
12145
12291
  while (ch !== 0) {
12146
12292
  if (ch === DOUBLE_QUOTE) {
12147
- const segment = this.captureSegment(captureStart, this.position, true);
12293
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
12148
12294
  if (segment) result += segment;
12149
- this.position++;
12295
+ this.#scanner.next();
12150
12296
  if (anchor !== null) this.anchorMap.set(anchor, result);
12151
12297
  return {
12152
12298
  tag,
@@ -12156,19 +12302,21 @@ var LoaderState = class {
12156
12302
  };
12157
12303
  }
12158
12304
  if (ch === BACKSLASH) {
12159
- const segment = this.captureSegment(captureStart, this.position, true);
12305
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
12160
12306
  if (segment) result += segment;
12161
- ch = this.next();
12307
+ this.#scanner.next();
12308
+ ch = this.#scanner.peek();
12162
12309
  if (isEOL(ch)) {
12163
12310
  this.skipSeparationSpace(false, nodeIndent);
12164
12311
  } else if (ch < 256 && SIMPLE_ESCAPE_SEQUENCES.has(ch)) {
12165
12312
  result += SIMPLE_ESCAPE_SEQUENCES.get(ch);
12166
- this.position++;
12313
+ this.#scanner.next();
12167
12314
  } else if ((tmp = ESCAPED_HEX_LENGTHS.get(ch) ?? 0) > 0) {
12168
12315
  let hexLength = tmp;
12169
12316
  let hexResult = 0;
12170
12317
  for (; hexLength > 0; hexLength--) {
12171
- ch = this.next();
12318
+ this.#scanner.next();
12319
+ ch = this.#scanner.peek();
12172
12320
  if ((tmp = hexCharCodeToNumber(ch)) >= 0) {
12173
12321
  hexResult = (hexResult << 4) + tmp;
12174
12322
  } else {
@@ -12176,28 +12324,28 @@ var LoaderState = class {
12176
12324
  }
12177
12325
  }
12178
12326
  result += codepointToChar(hexResult);
12179
- this.position++;
12327
+ this.#scanner.next();
12180
12328
  } else {
12181
12329
  throw this.#createError("Cannot read double quoted scalar: unknown escape sequence");
12182
12330
  }
12183
- captureStart = captureEnd = this.position;
12331
+ captureStart = captureEnd = this.#scanner.position;
12184
12332
  } else if (isEOL(ch)) {
12185
12333
  const segment = this.captureSegment(captureStart, captureEnd, true);
12186
12334
  if (segment) result += segment;
12187
12335
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
12188
- captureStart = captureEnd = this.position;
12189
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
12336
+ captureStart = captureEnd = this.#scanner.position;
12337
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
12190
12338
  throw this.#createError("Unexpected end of the document within a double quoted scalar");
12191
12339
  } else {
12192
- this.position++;
12193
- captureEnd = this.position;
12340
+ this.#scanner.next();
12341
+ captureEnd = this.#scanner.position;
12194
12342
  }
12195
- ch = this.peek();
12343
+ ch = this.#scanner.peek();
12196
12344
  }
12197
12345
  throw this.#createError("Unexpected end of the stream within a double quoted scalar");
12198
12346
  }
12199
12347
  readFlowCollection(tag, anchor, nodeIndent) {
12200
- let ch = this.peek();
12348
+ let ch = this.#scanner.peek();
12201
12349
  let terminator;
12202
12350
  let isMapping = true;
12203
12351
  let result = {};
@@ -12211,7 +12359,8 @@ var LoaderState = class {
12211
12359
  return;
12212
12360
  }
12213
12361
  if (anchor !== null) this.anchorMap.set(anchor, result);
12214
- ch = this.next();
12362
+ this.#scanner.next();
12363
+ ch = this.#scanner.peek();
12215
12364
  let readNext = true;
12216
12365
  let valueNode = null;
12217
12366
  let keyNode = null;
@@ -12223,9 +12372,9 @@ var LoaderState = class {
12223
12372
  const overridableKeys = /* @__PURE__ */ new Set();
12224
12373
  while (ch !== 0) {
12225
12374
  this.skipSeparationSpace(true, nodeIndent);
12226
- ch = this.peek();
12375
+ ch = this.#scanner.peek();
12227
12376
  if (ch === terminator) {
12228
- this.position++;
12377
+ this.#scanner.next();
12229
12378
  const kind = isMapping ? "mapping" : "sequence";
12230
12379
  return {
12231
12380
  tag,
@@ -12240,10 +12389,10 @@ var LoaderState = class {
12240
12389
  keyTag = keyNode = valueNode = null;
12241
12390
  isPair = isExplicitPair = false;
12242
12391
  if (ch === QUESTION) {
12243
- following = this.peek(1);
12392
+ following = this.#scanner.peek(1);
12244
12393
  if (isWhiteSpaceOrEOL(following)) {
12245
12394
  isPair = isExplicitPair = true;
12246
- this.position++;
12395
+ this.#scanner.next();
12247
12396
  this.skipSeparationSpace(true, nodeIndent);
12248
12397
  }
12249
12398
  }
@@ -12259,10 +12408,11 @@ var LoaderState = class {
12259
12408
  keyNode = newState.result;
12260
12409
  }
12261
12410
  this.skipSeparationSpace(true, nodeIndent);
12262
- ch = this.peek();
12411
+ ch = this.#scanner.peek();
12263
12412
  if ((isExplicitPair || this.line === line) && ch === COLON) {
12264
12413
  isPair = true;
12265
- ch = this.next();
12414
+ this.#scanner.next();
12415
+ ch = this.#scanner.peek();
12266
12416
  this.skipSeparationSpace(true, nodeIndent);
12267
12417
  const newState2 = this.composeNode({
12268
12418
  parentIndent: nodeIndent,
@@ -12280,10 +12430,11 @@ var LoaderState = class {
12280
12430
  result.push(keyNode);
12281
12431
  }
12282
12432
  this.skipSeparationSpace(true, nodeIndent);
12283
- ch = this.peek();
12433
+ ch = this.#scanner.peek();
12284
12434
  if (ch === COMMA) {
12285
12435
  readNext = true;
12286
- ch = this.next();
12436
+ this.#scanner.next();
12437
+ ch = this.#scanner.peek();
12287
12438
  } else {
12288
12439
  readNext = false;
12289
12440
  }
@@ -12299,7 +12450,7 @@ var LoaderState = class {
12299
12450
  let textIndent = nodeIndent;
12300
12451
  let emptyLines = 0;
12301
12452
  let atMoreIndented = false;
12302
- let ch = this.peek();
12453
+ let ch = this.#scanner.peek();
12303
12454
  let folding = false;
12304
12455
  if (ch === VERTICAL_LINE) {
12305
12456
  folding = false;
@@ -12311,7 +12462,8 @@ var LoaderState = class {
12311
12462
  let result = "";
12312
12463
  let tmp = 0;
12313
12464
  while (ch !== 0) {
12314
- ch = this.next();
12465
+ this.#scanner.next();
12466
+ ch = this.#scanner.peek();
12315
12467
  if (ch === PLUS || ch === MINUS) {
12316
12468
  if (CHOMPING_CLIP === chomping) {
12317
12469
  chomping = ch === PLUS ? CHOMPING_KEEP : CHOMPING_STRIP;
@@ -12334,15 +12486,16 @@ var LoaderState = class {
12334
12486
  if (isWhiteSpace(ch)) {
12335
12487
  this.skipWhitespaces();
12336
12488
  this.skipComment();
12337
- ch = this.peek();
12489
+ ch = this.#scanner.peek();
12338
12490
  }
12339
12491
  while (ch !== 0) {
12340
12492
  this.readLineBreak();
12341
12493
  this.lineIndent = 0;
12342
- ch = this.peek();
12494
+ ch = this.#scanner.peek();
12343
12495
  while ((!detectedIndent || this.lineIndent < textIndent) && ch === SPACE) {
12344
12496
  this.lineIndent++;
12345
- ch = this.next();
12497
+ this.#scanner.next();
12498
+ ch = this.#scanner.peek();
12346
12499
  }
12347
12500
  if (!detectedIndent && this.lineIndent > textIndent) {
12348
12501
  textIndent = this.lineIndent;
@@ -12381,11 +12534,12 @@ var LoaderState = class {
12381
12534
  didReadContent = true;
12382
12535
  detectedIndent = true;
12383
12536
  emptyLines = 0;
12384
- const captureStart = this.position;
12537
+ const captureStart = this.#scanner.position;
12385
12538
  while (!isEOL(ch) && ch !== 0) {
12386
- ch = this.next();
12539
+ this.#scanner.next();
12540
+ ch = this.#scanner.peek();
12387
12541
  }
12388
- const segment = this.captureSegment(captureStart, this.position, false);
12542
+ const segment = this.captureSegment(captureStart, this.#scanner.position, false);
12389
12543
  if (segment) result += segment;
12390
12544
  }
12391
12545
  if (anchor !== null) this.anchorMap.set(anchor, result);
@@ -12408,11 +12562,11 @@ var LoaderState = class {
12408
12562
  let atExplicitKey = false;
12409
12563
  let detected = false;
12410
12564
  if (anchor !== null) this.anchorMap.set(anchor, result);
12411
- let ch = this.peek();
12565
+ let ch = this.#scanner.peek();
12412
12566
  while (ch !== 0) {
12413
- const following = this.peek(1);
12567
+ const following = this.#scanner.peek(1);
12414
12568
  line = this.line;
12415
- pos = this.position;
12569
+ pos = this.#scanner.position;
12416
12570
  if ((ch === QUESTION || ch === COLON) && isWhiteSpaceOrEOL(following)) {
12417
12571
  if (ch === QUESTION) {
12418
12572
  if (atExplicitKey) {
@@ -12430,7 +12584,7 @@ var LoaderState = class {
12430
12584
  } else {
12431
12585
  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");
12432
12586
  }
12433
- this.position += 1;
12587
+ this.#scanner.next();
12434
12588
  ch = following;
12435
12589
  } else {
12436
12590
  const newState = this.composeNode({
@@ -12441,11 +12595,12 @@ var LoaderState = class {
12441
12595
  });
12442
12596
  if (!newState) break;
12443
12597
  if (this.line === line) {
12444
- ch = this.peek();
12598
+ ch = this.#scanner.peek();
12445
12599
  this.skipWhitespaces();
12446
- ch = this.peek();
12600
+ ch = this.#scanner.peek();
12447
12601
  if (ch === COLON) {
12448
- ch = this.next();
12602
+ this.#scanner.next();
12603
+ ch = this.#scanner.peek();
12449
12604
  if (!isWhiteSpaceOrEOL(ch)) {
12450
12605
  throw this.#createError("Cannot read block: a whitespace character is expected after the key-value separator within a block mapping");
12451
12606
  }
@@ -12502,7 +12657,7 @@ var LoaderState = class {
12502
12657
  keyTag = keyNode = valueNode = null;
12503
12658
  }
12504
12659
  this.skipSeparationSpace(true, -1);
12505
- ch = this.peek();
12660
+ ch = this.#scanner.peek();
12506
12661
  }
12507
12662
  if (this.lineIndent > nodeIndent && ch !== 0) {
12508
12663
  throw this.#createError("Cannot read block: bad indentation of a mapping entry");
@@ -12525,30 +12680,35 @@ var LoaderState = class {
12525
12680
  let isNamed = false;
12526
12681
  let tagHandle = "";
12527
12682
  let tagName;
12528
- let ch = this.peek();
12683
+ let ch = this.#scanner.peek();
12529
12684
  if (ch !== EXCLAMATION) return;
12530
12685
  if (tag !== null) {
12531
12686
  throw this.#createError("Cannot read tag property: duplication of a tag property");
12532
12687
  }
12533
- ch = this.next();
12688
+ this.#scanner.next();
12689
+ ch = this.#scanner.peek();
12534
12690
  if (ch === SMALLER_THAN) {
12535
12691
  isVerbatim = true;
12536
- ch = this.next();
12692
+ this.#scanner.next();
12693
+ ch = this.#scanner.peek();
12537
12694
  } else if (ch === EXCLAMATION) {
12538
12695
  isNamed = true;
12539
12696
  tagHandle = "!!";
12540
- ch = this.next();
12697
+ this.#scanner.next();
12698
+ ch = this.#scanner.peek();
12541
12699
  } else {
12542
12700
  tagHandle = "!";
12543
12701
  }
12544
- let position = this.position;
12702
+ let position = this.#scanner.position;
12545
12703
  if (isVerbatim) {
12546
12704
  do {
12547
- ch = this.next();
12705
+ this.#scanner.next();
12706
+ ch = this.#scanner.peek();
12548
12707
  } while (ch !== 0 && ch !== GREATER_THAN);
12549
- if (this.position < this.length) {
12550
- tagName = this.input.slice(position, this.position);
12551
- ch = this.next();
12708
+ if (!this.#scanner.eof()) {
12709
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
12710
+ this.#scanner.next();
12711
+ ch = this.#scanner.peek();
12552
12712
  } else {
12553
12713
  throw this.#createError("Cannot read tag property: unexpected end of stream");
12554
12714
  }
@@ -12556,19 +12716,20 @@ var LoaderState = class {
12556
12716
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
12557
12717
  if (ch === EXCLAMATION) {
12558
12718
  if (!isNamed) {
12559
- tagHandle = this.input.slice(position - 1, this.position + 1);
12719
+ tagHandle = this.#scanner.source.slice(position - 1, this.#scanner.position + 1);
12560
12720
  if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
12561
12721
  throw this.#createError("Cannot read tag property: named tag handle contains invalid characters");
12562
12722
  }
12563
12723
  isNamed = true;
12564
- position = this.position + 1;
12724
+ position = this.#scanner.position + 1;
12565
12725
  } else {
12566
12726
  throw this.#createError("Cannot read tag property: tag suffix cannot contain an exclamation mark");
12567
12727
  }
12568
12728
  }
12569
- ch = this.next();
12729
+ this.#scanner.next();
12730
+ ch = this.#scanner.peek();
12570
12731
  }
12571
- tagName = this.input.slice(position, this.position);
12732
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
12572
12733
  if (PATTERN_FLOW_INDICATORS.test(tagName)) {
12573
12734
  throw this.#createError("Cannot read tag property: tag suffix cannot contain flow indicator characters");
12574
12735
  }
@@ -12588,32 +12749,36 @@ var LoaderState = class {
12588
12749
  throw this.#createError(`Cannot read tag property: undeclared tag handle "${tagHandle}"`);
12589
12750
  }
12590
12751
  readAnchorProperty(anchor) {
12591
- let ch = this.peek();
12752
+ let ch = this.#scanner.peek();
12592
12753
  if (ch !== AMPERSAND) return;
12593
12754
  if (anchor !== null) {
12594
12755
  throw this.#createError("Cannot read anchor property: duplicate anchor property");
12595
12756
  }
12596
- ch = this.next();
12597
- const position = this.position;
12757
+ this.#scanner.next();
12758
+ ch = this.#scanner.peek();
12759
+ const position = this.#scanner.position;
12598
12760
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
12599
- ch = this.next();
12761
+ this.#scanner.next();
12762
+ ch = this.#scanner.peek();
12600
12763
  }
12601
- if (this.position === position) {
12764
+ if (this.#scanner.position === position) {
12602
12765
  throw this.#createError("Cannot read anchor property: name of an anchor node must contain at least one character");
12603
12766
  }
12604
- return this.input.slice(position, this.position);
12767
+ return this.#scanner.source.slice(position, this.#scanner.position);
12605
12768
  }
12606
12769
  readAlias() {
12607
- if (this.peek() !== ASTERISK) return;
12608
- let ch = this.next();
12609
- const position = this.position;
12770
+ if (this.#scanner.peek() !== ASTERISK) return;
12771
+ this.#scanner.next();
12772
+ let ch = this.#scanner.peek();
12773
+ const position = this.#scanner.position;
12610
12774
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
12611
- ch = this.next();
12775
+ this.#scanner.next();
12776
+ ch = this.#scanner.peek();
12612
12777
  }
12613
- if (this.position === position) {
12778
+ if (this.#scanner.position === position) {
12614
12779
  throw this.#createError("Cannot read alias: alias name must contain at least one character");
12615
12780
  }
12616
- const alias = this.input.slice(position, this.position);
12781
+ const alias = this.#scanner.source.slice(position, this.#scanner.position);
12617
12782
  if (!this.anchorMap.has(alias)) {
12618
12783
  throw this.#createError(`Cannot read alias: unidentified alias "${alias}"`);
12619
12784
  }
@@ -12696,7 +12861,7 @@ var LoaderState = class {
12696
12861
  const cond = CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext;
12697
12862
  const flowIndent = cond ? parentIndent : parentIndent + 1;
12698
12863
  if (allowBlockCollections) {
12699
- const blockIndent = this.position - this.lineStart;
12864
+ const blockIndent = this.#scanner.position - this.lineStart;
12700
12865
  const blockSequenceState = this.readBlockSequence(tag, anchor, blockIndent);
12701
12866
  if (blockSequenceState) return this.resolveTag(blockSequenceState);
12702
12867
  const blockMappingState = this.readBlockMapping(tag, anchor, blockIndent, flowIndent);
@@ -12730,7 +12895,7 @@ var LoaderState = class {
12730
12895
  return this.resolveTag(plainScalarState);
12731
12896
  }
12732
12897
  } else if (indentStatus === 0 && CONTEXT_BLOCK_OUT === nodeContext && allowBlockCollections) {
12733
- const blockIndent = this.position - this.lineStart;
12898
+ const blockIndent = this.#scanner.position - this.lineStart;
12734
12899
  const newState2 = this.readBlockSequence(tag, anchor, blockIndent);
12735
12900
  if (newState2) return this.resolveTag(newState2);
12736
12901
  }
@@ -12745,20 +12910,22 @@ var LoaderState = class {
12745
12910
  readDirectives() {
12746
12911
  let hasDirectives = false;
12747
12912
  let version = null;
12748
- let ch = this.peek();
12913
+ let ch = this.#scanner.peek();
12749
12914
  while (ch !== 0) {
12750
12915
  this.skipSeparationSpace(true, -1);
12751
- ch = this.peek();
12916
+ ch = this.#scanner.peek();
12752
12917
  if (this.lineIndent > 0 || ch !== PERCENT) {
12753
12918
  break;
12754
12919
  }
12755
12920
  hasDirectives = true;
12756
- ch = this.next();
12757
- let position = this.position;
12921
+ this.#scanner.next();
12922
+ ch = this.#scanner.peek();
12923
+ let position = this.#scanner.position;
12758
12924
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
12759
- ch = this.next();
12925
+ this.#scanner.next();
12926
+ ch = this.#scanner.peek();
12760
12927
  }
12761
- const directiveName = this.input.slice(position, this.position);
12928
+ const directiveName = this.#scanner.source.slice(position, this.#scanner.position);
12762
12929
  const directiveArgs = [];
12763
12930
  if (directiveName.length < 1) {
12764
12931
  throw this.#createError("Cannot read document: directive name length must be greater than zero");
@@ -12766,13 +12933,14 @@ var LoaderState = class {
12766
12933
  while (ch !== 0) {
12767
12934
  this.skipWhitespaces();
12768
12935
  this.skipComment();
12769
- ch = this.peek();
12936
+ ch = this.#scanner.peek();
12770
12937
  if (isEOL(ch)) break;
12771
- position = this.position;
12938
+ position = this.#scanner.position;
12772
12939
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
12773
- ch = this.next();
12940
+ this.#scanner.next();
12941
+ ch = this.#scanner.peek();
12774
12942
  }
12775
- directiveArgs.push(this.input.slice(position, this.position));
12943
+ directiveArgs.push(this.#scanner.source.slice(position, this.#scanner.position));
12776
12944
  }
12777
12945
  if (ch !== 0) this.readLineBreak();
12778
12946
  switch (directiveName) {
@@ -12789,20 +12957,20 @@ var LoaderState = class {
12789
12957
  this.dispatchWarning(`unknown document directive "${directiveName}"`);
12790
12958
  break;
12791
12959
  }
12792
- ch = this.peek();
12960
+ ch = this.#scanner.peek();
12793
12961
  }
12794
12962
  return hasDirectives;
12795
12963
  }
12796
12964
  readDocument() {
12797
- const documentStart = this.position;
12965
+ const documentStart = this.#scanner.position;
12798
12966
  this.checkLineBreaks = false;
12799
12967
  this.tagMap = /* @__PURE__ */ new Map();
12800
12968
  this.anchorMap = /* @__PURE__ */ new Map();
12801
12969
  const hasDirectives = this.readDirectives();
12802
12970
  this.skipSeparationSpace(true, -1);
12803
12971
  let result = null;
12804
- if (this.lineIndent === 0 && this.peek() === MINUS && this.peek(1) === MINUS && this.peek(2) === MINUS) {
12805
- this.position += 3;
12972
+ if (this.lineIndent === 0 && this.#scanner.peek() === MINUS && this.#scanner.peek(1) === MINUS && this.#scanner.peek(2) === MINUS) {
12973
+ this.#scanner.position += 3;
12806
12974
  this.skipSeparationSpace(true, -1);
12807
12975
  } else if (hasDirectives) {
12808
12976
  throw this.#createError("Cannot read document: directives end mark is expected");
@@ -12815,21 +12983,21 @@ var LoaderState = class {
12815
12983
  });
12816
12984
  if (newState) result = newState.result;
12817
12985
  this.skipSeparationSpace(true, -1);
12818
- if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.input.slice(documentStart, this.position))) {
12986
+ if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.#scanner.source.slice(documentStart, this.#scanner.position))) {
12819
12987
  this.dispatchWarning("non-ASCII line breaks are interpreted as content");
12820
12988
  }
12821
- if (this.position === this.lineStart && this.testDocumentSeparator()) {
12822
- if (this.peek() === DOT) {
12823
- this.position += 3;
12989
+ if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
12990
+ if (this.#scanner.peek() === DOT) {
12991
+ this.#scanner.position += 3;
12824
12992
  this.skipSeparationSpace(true, -1);
12825
12993
  }
12826
- } else if (this.position < this.length - 1) {
12994
+ } else if (!this.#scanner.eof()) {
12827
12995
  throw this.#createError("Cannot read document: end of the stream or a document separator is expected");
12828
12996
  }
12829
12997
  return result;
12830
12998
  }
12831
12999
  *readDocuments() {
12832
- while (this.position < this.length - 1) {
13000
+ while (!this.#scanner.eof()) {
12833
13001
  yield this.readDocument();
12834
13002
  }
12835
13003
  }
@@ -12842,7 +13010,6 @@ function sanitizeInput(input) {
12842
13010
  if (!isEOL(input.charCodeAt(input.length - 1))) input += "\n";
12843
13011
  if (input.charCodeAt(0) === 65279) input = input.slice(1);
12844
13012
  }
12845
- input += "\0";
12846
13013
  return input;
12847
13014
  }
12848
13015
  function parse(content, options = {}) {
@@ -13728,6 +13895,7 @@ data:
13728
13895
  async handleGetRequest(req) {
13729
13896
  const acceptHeader = req.headers.get("accept");
13730
13897
  if (!acceptHeader?.includes("text/event-stream")) {
13898
+ this.onerror?.(new Error("Not Acceptable: Client must accept text/event-stream"));
13731
13899
  return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept text/event-stream");
13732
13900
  }
13733
13901
  const sessionError = this.validateSession(req);
@@ -13745,6 +13913,7 @@ data:
13745
13913
  }
13746
13914
  }
13747
13915
  if (this._streamMapping.get(this._standaloneSseStreamId) !== void 0) {
13916
+ this.onerror?.(new Error("Conflict: Only one SSE stream is allowed per session"));
13748
13917
  return this.createJsonErrorResponse(409, -32e3, "Conflict: Only one SSE stream is allowed per session");
13749
13918
  }
13750
13919
  const encoder2 = new TextEncoder();
@@ -13784,6 +13953,7 @@ data:
13784
13953
  */
13785
13954
  async replayEvents(lastEventId) {
13786
13955
  if (!this._eventStore) {
13956
+ this.onerror?.(new Error("Event store not configured"));
13787
13957
  return this.createJsonErrorResponse(400, -32e3, "Event store not configured");
13788
13958
  }
13789
13959
  try {
@@ -13791,9 +13961,11 @@ data:
13791
13961
  if (this._eventStore.getStreamIdForEventId) {
13792
13962
  streamId = await this._eventStore.getStreamIdForEventId(lastEventId);
13793
13963
  if (!streamId) {
13964
+ this.onerror?.(new Error("Invalid event ID format"));
13794
13965
  return this.createJsonErrorResponse(400, -32e3, "Invalid event ID format");
13795
13966
  }
13796
13967
  if (this._streamMapping.get(streamId) !== void 0) {
13968
+ this.onerror?.(new Error("Conflict: Stream already has an active connection"));
13797
13969
  return this.createJsonErrorResponse(409, -32e3, "Conflict: Stream already has an active connection");
13798
13970
  }
13799
13971
  }
@@ -13859,7 +14031,8 @@ data:
13859
14031
  `;
13860
14032
  controller.enqueue(encoder2.encode(eventData));
13861
14033
  return true;
13862
- } catch {
14034
+ } catch (error) {
14035
+ this.onerror?.(error);
13863
14036
  return false;
13864
14037
  }
13865
14038
  }
@@ -13867,6 +14040,7 @@ data:
13867
14040
  * Handles unsupported requests (PUT, PATCH, etc.)
13868
14041
  */
13869
14042
  handleUnsupportedRequest() {
14043
+ this.onerror?.(new Error("Method not allowed."));
13870
14044
  return new Response(JSON.stringify({
13871
14045
  jsonrpc: "2.0",
13872
14046
  error: {
@@ -13889,14 +14063,17 @@ data:
13889
14063
  try {
13890
14064
  const acceptHeader = req.headers.get("accept");
13891
14065
  if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
14066
+ this.onerror?.(new Error("Not Acceptable: Client must accept both application/json and text/event-stream"));
13892
14067
  return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept both application/json and text/event-stream");
13893
14068
  }
13894
14069
  const ct = req.headers.get("content-type");
13895
14070
  if (!ct || !ct.includes("application/json")) {
14071
+ this.onerror?.(new Error("Unsupported Media Type: Content-Type must be application/json"));
13896
14072
  return this.createJsonErrorResponse(415, -32e3, "Unsupported Media Type: Content-Type must be application/json");
13897
14073
  }
13898
14074
  const requestInfo = {
13899
- headers: Object.fromEntries(req.headers.entries())
14075
+ headers: Object.fromEntries(req.headers.entries()),
14076
+ url: new URL(req.url)
13900
14077
  };
13901
14078
  let rawMessage;
13902
14079
  if (options?.parsedBody !== void 0) {
@@ -13905,6 +14082,7 @@ data:
13905
14082
  try {
13906
14083
  rawMessage = await req.json();
13907
14084
  } catch {
14085
+ this.onerror?.(new Error("Parse error: Invalid JSON"));
13908
14086
  return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON");
13909
14087
  }
13910
14088
  }
@@ -13916,14 +14094,17 @@ data:
13916
14094
  messages = [JSONRPCMessageSchema.parse(rawMessage)];
13917
14095
  }
13918
14096
  } catch {
14097
+ this.onerror?.(new Error("Parse error: Invalid JSON-RPC message"));
13919
14098
  return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON-RPC message");
13920
14099
  }
13921
14100
  const isInitializationRequest = messages.some(isInitializeRequest);
13922
14101
  if (isInitializationRequest) {
13923
14102
  if (this._initialized && this.sessionId !== void 0) {
14103
+ this.onerror?.(new Error("Invalid Request: Server already initialized"));
13924
14104
  return this.createJsonErrorResponse(400, -32600, "Invalid Request: Server already initialized");
13925
14105
  }
13926
14106
  if (messages.length > 1) {
14107
+ this.onerror?.(new Error("Invalid Request: Only one initialization request is allowed"));
13927
14108
  return this.createJsonErrorResponse(400, -32600, "Invalid Request: Only one initialization request is allowed");
13928
14109
  }
13929
14110
  this.sessionId = this.sessionIdGenerator?.();
@@ -14049,13 +14230,16 @@ data:
14049
14230
  return void 0;
14050
14231
  }
14051
14232
  if (!this._initialized) {
14233
+ this.onerror?.(new Error("Bad Request: Server not initialized"));
14052
14234
  return this.createJsonErrorResponse(400, -32e3, "Bad Request: Server not initialized");
14053
14235
  }
14054
14236
  const sessionId = req.headers.get("mcp-session-id");
14055
14237
  if (!sessionId) {
14238
+ this.onerror?.(new Error("Bad Request: Mcp-Session-Id header is required"));
14056
14239
  return this.createJsonErrorResponse(400, -32e3, "Bad Request: Mcp-Session-Id header is required");
14057
14240
  }
14058
14241
  if (sessionId !== this.sessionId) {
14242
+ this.onerror?.(new Error("Session not found"));
14059
14243
  return this.createJsonErrorResponse(404, -32001, "Session not found");
14060
14244
  }
14061
14245
  return void 0;
@@ -14076,6 +14260,7 @@ data:
14076
14260
  validateProtocolVersion(req) {
14077
14261
  const protocolVersion = req.headers.get("mcp-protocol-version");
14078
14262
  if (protocolVersion !== null && !SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) {
14263
+ this.onerror?.(new Error(`Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`));
14079
14264
  return this.createJsonErrorResponse(400, -32e3, `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`);
14080
14265
  }
14081
14266
  return void 0;
@@ -14282,7 +14467,7 @@ var StreamableHTTPServerTransport = class {
14282
14467
  };
14283
14468
 
14284
14469
  // __mcpc__cli_latest/node_modules/@jsr/std__cli/parse_args.js
14285
- var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.+?))?$/s;
14470
+ var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.*))?$/s;
14286
14471
  var LETTER_REGEXP = /[A-Za-z]/;
14287
14472
  var NUMBER_REGEXP = /-?\d+(\.\d*)?(e-?\d+)?$/;
14288
14473
  var HYPHEN_REGEXP = /^(-|--)[^-]/;
@@ -14293,12 +14478,19 @@ var NON_WHITESPACE_REGEXP = /\S/;
14293
14478
  function isNumber(string3) {
14294
14479
  return NON_WHITESPACE_REGEXP.test(string3) && Number.isFinite(Number(string3));
14295
14480
  }
14481
+ function isConstructorOrProto(obj, key) {
14482
+ return key === "constructor" && typeof obj[key] === "function" || key === "__proto__";
14483
+ }
14296
14484
  function setNested(object5, keys, value, collect = false) {
14297
14485
  keys = [
14298
14486
  ...keys
14299
14487
  ];
14300
14488
  const key = keys.pop();
14301
- keys.forEach((key2) => object5 = object5[key2] ??= {});
14489
+ for (const k of keys) {
14490
+ if (isConstructorOrProto(object5, k)) return;
14491
+ object5 = object5[k] ??= {};
14492
+ }
14493
+ if (isConstructorOrProto(object5, key)) return;
14302
14494
  if (collect) {
14303
14495
  const v = object5[key];
14304
14496
  if (Array.isArray(v)) {
@@ -14429,7 +14621,7 @@ function parseArgs(args, options) {
14429
14621
  let key = groups.key;
14430
14622
  let value = groups.value;
14431
14623
  if (doubleDash2) {
14432
- if (value) {
14624
+ if (value != null) {
14433
14625
  if (booleanSet.has(key)) value = parseBooleanString(value);
14434
14626
  setArgument(key, value, arg, true);
14435
14627
  continue;
@@ -14467,6 +14659,10 @@ function parseArgs(args, options) {
14467
14659
  setArgument(letter, next, arg, true);
14468
14660
  continue;
14469
14661
  }
14662
+ if (next === "=") {
14663
+ setArgument(letter, "", arg, true);
14664
+ continue argsLoop;
14665
+ }
14470
14666
  if (LETTER_REGEXP.test(letter)) {
14471
14667
  const groups2 = VALUE_REGEXP.exec(next)?.groups;
14472
14668
  if (groups2) {
@@ -14544,7 +14740,7 @@ import { mkdir, readFile as readFile3, writeFile as writeFile2 } from "node:fs/p
14544
14740
  import { homedir } from "node:os";
14545
14741
  import { dirname, join as join3, resolve as resolve4 } from "node:path";
14546
14742
  import process9 from "node:process";
14547
- var CLI_VERSION = "0.1.44";
14743
+ var CLI_VERSION = "0.1.51";
14548
14744
  function extractServerName(command, commandArgs) {
14549
14745
  for (const arg of commandArgs) {
14550
14746
  if (!arg.startsWith("-")) {