@mcpc-tech/cli 0.1.50 → 0.1.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.cjs +632 -289
- package/app.mjs +632 -289
- package/bin/mcpc.cjs +630 -305
- package/bin/mcpc.mjs +628 -303
- package/bin.cjs +630 -305
- package/bin.mjs +628 -303
- package/index.cjs +652 -309
- package/index.mjs +650 -307
- package/package.json +1 -1
- package/server.cjs +652 -309
- package/server.mjs +650 -307
package/server.cjs
CHANGED
|
@@ -501,7 +501,7 @@ var require_cross_spawn = __commonJS({
|
|
|
501
501
|
var cp = require("child_process");
|
|
502
502
|
var parse2 = require_parse();
|
|
503
503
|
var enoent = require_enoent();
|
|
504
|
-
function
|
|
504
|
+
function spawn3(command, args, options) {
|
|
505
505
|
const parsed = parse2(command, args, options);
|
|
506
506
|
const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
|
|
507
507
|
enoent.hookChildProcess(spawned, parsed);
|
|
@@ -513,8 +513,8 @@ var require_cross_spawn = __commonJS({
|
|
|
513
513
|
result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
|
|
514
514
|
return result;
|
|
515
515
|
}
|
|
516
|
-
module2.exports =
|
|
517
|
-
module2.exports.spawn =
|
|
516
|
+
module2.exports = spawn3;
|
|
517
|
+
module2.exports.spawn = spawn3;
|
|
518
518
|
module2.exports.sync = spawnSync;
|
|
519
519
|
module2.exports._parse = parse2;
|
|
520
520
|
module2.exports._enoent = enoent;
|
|
@@ -3025,6 +3025,7 @@ data:
|
|
|
3025
3025
|
async handleGetRequest(req) {
|
|
3026
3026
|
const acceptHeader = req.headers.get("accept");
|
|
3027
3027
|
if (!acceptHeader?.includes("text/event-stream")) {
|
|
3028
|
+
this.onerror?.(new Error("Not Acceptable: Client must accept text/event-stream"));
|
|
3028
3029
|
return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept text/event-stream");
|
|
3029
3030
|
}
|
|
3030
3031
|
const sessionError = this.validateSession(req);
|
|
@@ -3042,6 +3043,7 @@ data:
|
|
|
3042
3043
|
}
|
|
3043
3044
|
}
|
|
3044
3045
|
if (this._streamMapping.get(this._standaloneSseStreamId) !== void 0) {
|
|
3046
|
+
this.onerror?.(new Error("Conflict: Only one SSE stream is allowed per session"));
|
|
3045
3047
|
return this.createJsonErrorResponse(409, -32e3, "Conflict: Only one SSE stream is allowed per session");
|
|
3046
3048
|
}
|
|
3047
3049
|
const encoder2 = new TextEncoder();
|
|
@@ -3081,6 +3083,7 @@ data:
|
|
|
3081
3083
|
*/
|
|
3082
3084
|
async replayEvents(lastEventId) {
|
|
3083
3085
|
if (!this._eventStore) {
|
|
3086
|
+
this.onerror?.(new Error("Event store not configured"));
|
|
3084
3087
|
return this.createJsonErrorResponse(400, -32e3, "Event store not configured");
|
|
3085
3088
|
}
|
|
3086
3089
|
try {
|
|
@@ -3088,9 +3091,11 @@ data:
|
|
|
3088
3091
|
if (this._eventStore.getStreamIdForEventId) {
|
|
3089
3092
|
streamId = await this._eventStore.getStreamIdForEventId(lastEventId);
|
|
3090
3093
|
if (!streamId) {
|
|
3094
|
+
this.onerror?.(new Error("Invalid event ID format"));
|
|
3091
3095
|
return this.createJsonErrorResponse(400, -32e3, "Invalid event ID format");
|
|
3092
3096
|
}
|
|
3093
3097
|
if (this._streamMapping.get(streamId) !== void 0) {
|
|
3098
|
+
this.onerror?.(new Error("Conflict: Stream already has an active connection"));
|
|
3094
3099
|
return this.createJsonErrorResponse(409, -32e3, "Conflict: Stream already has an active connection");
|
|
3095
3100
|
}
|
|
3096
3101
|
}
|
|
@@ -3156,7 +3161,8 @@ data:
|
|
|
3156
3161
|
`;
|
|
3157
3162
|
controller.enqueue(encoder2.encode(eventData));
|
|
3158
3163
|
return true;
|
|
3159
|
-
} catch {
|
|
3164
|
+
} catch (error) {
|
|
3165
|
+
this.onerror?.(error);
|
|
3160
3166
|
return false;
|
|
3161
3167
|
}
|
|
3162
3168
|
}
|
|
@@ -3164,6 +3170,7 @@ data:
|
|
|
3164
3170
|
* Handles unsupported requests (PUT, PATCH, etc.)
|
|
3165
3171
|
*/
|
|
3166
3172
|
handleUnsupportedRequest() {
|
|
3173
|
+
this.onerror?.(new Error("Method not allowed."));
|
|
3167
3174
|
return new Response(JSON.stringify({
|
|
3168
3175
|
jsonrpc: "2.0",
|
|
3169
3176
|
error: {
|
|
@@ -3186,14 +3193,17 @@ data:
|
|
|
3186
3193
|
try {
|
|
3187
3194
|
const acceptHeader = req.headers.get("accept");
|
|
3188
3195
|
if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
|
|
3196
|
+
this.onerror?.(new Error("Not Acceptable: Client must accept both application/json and text/event-stream"));
|
|
3189
3197
|
return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept both application/json and text/event-stream");
|
|
3190
3198
|
}
|
|
3191
3199
|
const ct = req.headers.get("content-type");
|
|
3192
3200
|
if (!ct || !ct.includes("application/json")) {
|
|
3201
|
+
this.onerror?.(new Error("Unsupported Media Type: Content-Type must be application/json"));
|
|
3193
3202
|
return this.createJsonErrorResponse(415, -32e3, "Unsupported Media Type: Content-Type must be application/json");
|
|
3194
3203
|
}
|
|
3195
3204
|
const requestInfo = {
|
|
3196
|
-
headers: Object.fromEntries(req.headers.entries())
|
|
3205
|
+
headers: Object.fromEntries(req.headers.entries()),
|
|
3206
|
+
url: new URL(req.url)
|
|
3197
3207
|
};
|
|
3198
3208
|
let rawMessage;
|
|
3199
3209
|
if (options?.parsedBody !== void 0) {
|
|
@@ -3202,6 +3212,7 @@ data:
|
|
|
3202
3212
|
try {
|
|
3203
3213
|
rawMessage = await req.json();
|
|
3204
3214
|
} catch {
|
|
3215
|
+
this.onerror?.(new Error("Parse error: Invalid JSON"));
|
|
3205
3216
|
return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON");
|
|
3206
3217
|
}
|
|
3207
3218
|
}
|
|
@@ -3213,14 +3224,17 @@ data:
|
|
|
3213
3224
|
messages = [JSONRPCMessageSchema.parse(rawMessage)];
|
|
3214
3225
|
}
|
|
3215
3226
|
} catch {
|
|
3227
|
+
this.onerror?.(new Error("Parse error: Invalid JSON-RPC message"));
|
|
3216
3228
|
return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON-RPC message");
|
|
3217
3229
|
}
|
|
3218
3230
|
const isInitializationRequest = messages.some(isInitializeRequest);
|
|
3219
3231
|
if (isInitializationRequest) {
|
|
3220
3232
|
if (this._initialized && this.sessionId !== void 0) {
|
|
3233
|
+
this.onerror?.(new Error("Invalid Request: Server already initialized"));
|
|
3221
3234
|
return this.createJsonErrorResponse(400, -32600, "Invalid Request: Server already initialized");
|
|
3222
3235
|
}
|
|
3223
3236
|
if (messages.length > 1) {
|
|
3237
|
+
this.onerror?.(new Error("Invalid Request: Only one initialization request is allowed"));
|
|
3224
3238
|
return this.createJsonErrorResponse(400, -32600, "Invalid Request: Only one initialization request is allowed");
|
|
3225
3239
|
}
|
|
3226
3240
|
this.sessionId = this.sessionIdGenerator?.();
|
|
@@ -3346,13 +3360,16 @@ data:
|
|
|
3346
3360
|
return void 0;
|
|
3347
3361
|
}
|
|
3348
3362
|
if (!this._initialized) {
|
|
3363
|
+
this.onerror?.(new Error("Bad Request: Server not initialized"));
|
|
3349
3364
|
return this.createJsonErrorResponse(400, -32e3, "Bad Request: Server not initialized");
|
|
3350
3365
|
}
|
|
3351
3366
|
const sessionId = req.headers.get("mcp-session-id");
|
|
3352
3367
|
if (!sessionId) {
|
|
3368
|
+
this.onerror?.(new Error("Bad Request: Mcp-Session-Id header is required"));
|
|
3353
3369
|
return this.createJsonErrorResponse(400, -32e3, "Bad Request: Mcp-Session-Id header is required");
|
|
3354
3370
|
}
|
|
3355
3371
|
if (sessionId !== this.sessionId) {
|
|
3372
|
+
this.onerror?.(new Error("Session not found"));
|
|
3356
3373
|
return this.createJsonErrorResponse(404, -32001, "Session not found");
|
|
3357
3374
|
}
|
|
3358
3375
|
return void 0;
|
|
@@ -3373,6 +3390,7 @@ data:
|
|
|
3373
3390
|
validateProtocolVersion(req) {
|
|
3374
3391
|
const protocolVersion = req.headers.get("mcp-protocol-version");
|
|
3375
3392
|
if (protocolVersion !== null && !SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) {
|
|
3393
|
+
this.onerror?.(new Error(`Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`));
|
|
3376
3394
|
return this.createJsonErrorResponse(400, -32e3, `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`);
|
|
3377
3395
|
}
|
|
3378
3396
|
return void 0;
|
|
@@ -3579,7 +3597,7 @@ var StreamableHTTPServerTransport = class {
|
|
|
3579
3597
|
};
|
|
3580
3598
|
|
|
3581
3599
|
// __mcpc__cli_latest/node_modules/@jsr/std__cli/parse_args.js
|
|
3582
|
-
var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value
|
|
3600
|
+
var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.*))?$/s;
|
|
3583
3601
|
var LETTER_REGEXP = /[A-Za-z]/;
|
|
3584
3602
|
var NUMBER_REGEXP = /-?\d+(\.\d*)?(e-?\d+)?$/;
|
|
3585
3603
|
var HYPHEN_REGEXP = /^(-|--)[^-]/;
|
|
@@ -3590,12 +3608,19 @@ var NON_WHITESPACE_REGEXP = /\S/;
|
|
|
3590
3608
|
function isNumber(string3) {
|
|
3591
3609
|
return NON_WHITESPACE_REGEXP.test(string3) && Number.isFinite(Number(string3));
|
|
3592
3610
|
}
|
|
3611
|
+
function isConstructorOrProto(obj, key) {
|
|
3612
|
+
return key === "constructor" && typeof obj[key] === "function" || key === "__proto__";
|
|
3613
|
+
}
|
|
3593
3614
|
function setNested(object5, keys, value, collect = false) {
|
|
3594
3615
|
keys = [
|
|
3595
3616
|
...keys
|
|
3596
3617
|
];
|
|
3597
3618
|
const key = keys.pop();
|
|
3598
|
-
|
|
3619
|
+
for (const k of keys) {
|
|
3620
|
+
if (isConstructorOrProto(object5, k)) return;
|
|
3621
|
+
object5 = object5[k] ??= {};
|
|
3622
|
+
}
|
|
3623
|
+
if (isConstructorOrProto(object5, key)) return;
|
|
3599
3624
|
if (collect) {
|
|
3600
3625
|
const v = object5[key];
|
|
3601
3626
|
if (Array.isArray(v)) {
|
|
@@ -3726,7 +3751,7 @@ function parseArgs(args, options) {
|
|
|
3726
3751
|
let key = groups.key;
|
|
3727
3752
|
let value = groups.value;
|
|
3728
3753
|
if (doubleDash2) {
|
|
3729
|
-
if (value) {
|
|
3754
|
+
if (value != null) {
|
|
3730
3755
|
if (booleanSet.has(key)) value = parseBooleanString(value);
|
|
3731
3756
|
setArgument(key, value, arg, true);
|
|
3732
3757
|
continue;
|
|
@@ -3764,6 +3789,10 @@ function parseArgs(args, options) {
|
|
|
3764
3789
|
setArgument(letter, next, arg, true);
|
|
3765
3790
|
continue;
|
|
3766
3791
|
}
|
|
3792
|
+
if (next === "=") {
|
|
3793
|
+
setArgument(letter, "", arg, true);
|
|
3794
|
+
continue argsLoop;
|
|
3795
|
+
}
|
|
3767
3796
|
if (LETTER_REGEXP.test(letter)) {
|
|
3768
3797
|
const groups2 = VALUE_REGEXP.exec(next)?.groups;
|
|
3769
3798
|
if (groups2) {
|
|
@@ -3840,7 +3869,7 @@ function parseArgs(args, options) {
|
|
|
3840
3869
|
var import_promises4 = require("node:fs/promises");
|
|
3841
3870
|
var import_node_os3 = require("node:os");
|
|
3842
3871
|
var import_node_path6 = require("node:path");
|
|
3843
|
-
var
|
|
3872
|
+
var import_node_process4 = __toESM(require("node:process"), 1);
|
|
3844
3873
|
|
|
3845
3874
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/plugins/large-result.js
|
|
3846
3875
|
var import_promises = require("node:fs/promises");
|
|
@@ -4258,7 +4287,7 @@ Usage:
|
|
|
4258
4287
|
- ${toolName}({ skill: "skill-name" }) - Load main SKILL.md content
|
|
4259
4288
|
- ${toolName}({ skill: "skill-name", ref: "path/to/file" }) - Load reference file
|
|
4260
4289
|
|
|
4261
|
-
Note: For scripts
|
|
4290
|
+
Note: For scripts/, use the bash tool with the script path to execute.`;
|
|
4262
4291
|
}
|
|
4263
4292
|
function createSkillsPlugin(options) {
|
|
4264
4293
|
const { paths } = options;
|
|
@@ -4366,11 +4395,15 @@ Available skills: ${available.join(", ")}` : "\n\nNo skills available.";
|
|
|
4366
4395
|
try {
|
|
4367
4396
|
const content = await (0, import_promises2.readFile)((0, import_node_path4.join)(meta.basePath, "SKILL.md"), "utf-8");
|
|
4368
4397
|
const body = extractBody(content);
|
|
4398
|
+
const skillPathInfo = `
|
|
4399
|
+
---
|
|
4400
|
+
Skill path: ${meta.basePath}
|
|
4401
|
+
`;
|
|
4369
4402
|
return {
|
|
4370
4403
|
content: [
|
|
4371
4404
|
{
|
|
4372
4405
|
type: "text",
|
|
4373
|
-
text: body
|
|
4406
|
+
text: body + skillPathInfo
|
|
4374
4407
|
}
|
|
4375
4408
|
]
|
|
4376
4409
|
};
|
|
@@ -4397,6 +4430,152 @@ Available skills: ${available.join(", ")}` : "\n\nNo skills available.";
|
|
|
4397
4430
|
};
|
|
4398
4431
|
}
|
|
4399
4432
|
|
|
4433
|
+
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/plugins/bash.js
|
|
4434
|
+
var import_node_child_process = require("node:child_process");
|
|
4435
|
+
var import_node_process = __toESM(require("node:process"), 1);
|
|
4436
|
+
var DEFAULT_MAX_BYTES = 1e5;
|
|
4437
|
+
var DEFAULT_MAX_LINES = 2e3;
|
|
4438
|
+
var DEFAULT_TIMEOUT_MS = 6e4;
|
|
4439
|
+
function truncateOutput(stdout, stderr, maxBytes = DEFAULT_MAX_BYTES, maxLines = DEFAULT_MAX_LINES) {
|
|
4440
|
+
const fullOutput = (stderr ? `STDERR:
|
|
4441
|
+
${stderr}
|
|
4442
|
+
|
|
4443
|
+
STDOUT:
|
|
4444
|
+
` : "") + stdout;
|
|
4445
|
+
const lines = fullOutput.split("\n");
|
|
4446
|
+
if (lines.length > maxLines) {
|
|
4447
|
+
const truncatedLines = lines.slice(-maxLines);
|
|
4448
|
+
return {
|
|
4449
|
+
output: `[OUTPUT TRUNCATED] Showing last ${maxLines} lines of ${lines.length} total
|
|
4450
|
+
|
|
4451
|
+
` + truncatedLines.join("\n"),
|
|
4452
|
+
truncated: true
|
|
4453
|
+
};
|
|
4454
|
+
}
|
|
4455
|
+
if (fullOutput.length > maxBytes) {
|
|
4456
|
+
const truncatedBytes = fullOutput.slice(-maxBytes);
|
|
4457
|
+
return {
|
|
4458
|
+
output: `[OUTPUT TRUNCATED] Showing last ${maxBytes} bytes of ${fullOutput.length} total
|
|
4459
|
+
|
|
4460
|
+
` + truncatedBytes,
|
|
4461
|
+
truncated: true
|
|
4462
|
+
};
|
|
4463
|
+
}
|
|
4464
|
+
return {
|
|
4465
|
+
output: fullOutput,
|
|
4466
|
+
truncated: false
|
|
4467
|
+
};
|
|
4468
|
+
}
|
|
4469
|
+
function executeBash(command, cwd2, timeoutMs) {
|
|
4470
|
+
return new Promise((resolve5) => {
|
|
4471
|
+
const stdout = [];
|
|
4472
|
+
const stderr = [];
|
|
4473
|
+
const proc = (0, import_node_child_process.spawn)("bash", [
|
|
4474
|
+
"-c",
|
|
4475
|
+
command
|
|
4476
|
+
], {
|
|
4477
|
+
cwd: cwd2,
|
|
4478
|
+
stdio: [
|
|
4479
|
+
"ignore",
|
|
4480
|
+
"pipe",
|
|
4481
|
+
"pipe"
|
|
4482
|
+
]
|
|
4483
|
+
});
|
|
4484
|
+
proc.stdout?.on("data", (data) => {
|
|
4485
|
+
stdout.push(data.toString());
|
|
4486
|
+
});
|
|
4487
|
+
proc.stderr?.on("data", (data) => {
|
|
4488
|
+
stderr.push(data.toString());
|
|
4489
|
+
});
|
|
4490
|
+
proc.on("close", (code) => {
|
|
4491
|
+
resolve5({
|
|
4492
|
+
stdout: stdout.join(""),
|
|
4493
|
+
stderr: stderr.join(""),
|
|
4494
|
+
exitCode: code
|
|
4495
|
+
});
|
|
4496
|
+
});
|
|
4497
|
+
proc.on("error", (err) => {
|
|
4498
|
+
resolve5({
|
|
4499
|
+
stdout: "",
|
|
4500
|
+
stderr: err.message,
|
|
4501
|
+
exitCode: null
|
|
4502
|
+
});
|
|
4503
|
+
});
|
|
4504
|
+
setTimeout(() => {
|
|
4505
|
+
proc.kill("SIGTERM");
|
|
4506
|
+
resolve5({
|
|
4507
|
+
stdout: stdout.join(""),
|
|
4508
|
+
stderr: stderr.join("") + "\n\n[TIMEOUT] Command execution timed out",
|
|
4509
|
+
exitCode: null
|
|
4510
|
+
});
|
|
4511
|
+
}, timeoutMs);
|
|
4512
|
+
});
|
|
4513
|
+
}
|
|
4514
|
+
function createBashPlugin(options = {}) {
|
|
4515
|
+
const { maxBytes, maxLines, timeoutMs } = {
|
|
4516
|
+
maxBytes: DEFAULT_MAX_BYTES,
|
|
4517
|
+
maxLines: DEFAULT_MAX_LINES,
|
|
4518
|
+
timeoutMs: DEFAULT_TIMEOUT_MS,
|
|
4519
|
+
...options
|
|
4520
|
+
};
|
|
4521
|
+
let serverRef = null;
|
|
4522
|
+
return {
|
|
4523
|
+
name: "plugin-bash",
|
|
4524
|
+
version: "1.0.0",
|
|
4525
|
+
// Store server reference for tool registration
|
|
4526
|
+
configureServer: (server) => {
|
|
4527
|
+
serverRef = server;
|
|
4528
|
+
},
|
|
4529
|
+
// Register bash tool with agent name prefix
|
|
4530
|
+
composeStart: (context2) => {
|
|
4531
|
+
if (!serverRef) return;
|
|
4532
|
+
const agentName = context2.serverName;
|
|
4533
|
+
const toolName = `${agentName}__bash`;
|
|
4534
|
+
serverRef.tool(toolName, "Execute a bash command and return its output.\n\nUse this for:\n- Running shell commands\n- Executing scripts\n- System operations\n\nNote: Output is truncated if too large.", {
|
|
4535
|
+
type: "object",
|
|
4536
|
+
properties: {
|
|
4537
|
+
command: {
|
|
4538
|
+
type: "string",
|
|
4539
|
+
description: "The bash command to execute"
|
|
4540
|
+
},
|
|
4541
|
+
cwd: {
|
|
4542
|
+
type: "string",
|
|
4543
|
+
description: "Optional: Working directory for the command (defaults to current directory)"
|
|
4544
|
+
}
|
|
4545
|
+
},
|
|
4546
|
+
required: [
|
|
4547
|
+
"command"
|
|
4548
|
+
]
|
|
4549
|
+
}, async (args) => {
|
|
4550
|
+
const cwd2 = args.cwd || import_node_process.default.cwd();
|
|
4551
|
+
const result = await executeBash(args.command, cwd2, timeoutMs);
|
|
4552
|
+
const { output, truncated } = truncateOutput(result.stdout, result.stderr, maxBytes, maxLines);
|
|
4553
|
+
let finalOutput = output;
|
|
4554
|
+
if (result.exitCode !== null && result.exitCode !== 0) {
|
|
4555
|
+
finalOutput = `[EXIT CODE: ${result.exitCode}]
|
|
4556
|
+
` + finalOutput;
|
|
4557
|
+
}
|
|
4558
|
+
if (truncated) {
|
|
4559
|
+
finalOutput += `
|
|
4560
|
+
|
|
4561
|
+
[Note: Output was truncated]`;
|
|
4562
|
+
}
|
|
4563
|
+
return {
|
|
4564
|
+
content: [
|
|
4565
|
+
{
|
|
4566
|
+
type: "text",
|
|
4567
|
+
text: finalOutput
|
|
4568
|
+
}
|
|
4569
|
+
],
|
|
4570
|
+
isError: result.exitCode !== null && result.exitCode !== 0
|
|
4571
|
+
};
|
|
4572
|
+
}, {
|
|
4573
|
+
internal: true
|
|
4574
|
+
});
|
|
4575
|
+
}
|
|
4576
|
+
};
|
|
4577
|
+
}
|
|
4578
|
+
|
|
4400
4579
|
// __mcpc__cli_latest/node_modules/@mcpc/cli/src/defaults.js
|
|
4401
4580
|
var import_plugin_code_execution = require("@mcpc-tech/plugin-code-execution");
|
|
4402
4581
|
|
|
@@ -5241,12 +5420,29 @@ function writeFoldedLines(count) {
|
|
|
5241
5420
|
if (count > 1) return "\n".repeat(count - 1);
|
|
5242
5421
|
return "";
|
|
5243
5422
|
}
|
|
5423
|
+
var Scanner = class {
|
|
5424
|
+
source;
|
|
5425
|
+
#length;
|
|
5426
|
+
position = 0;
|
|
5427
|
+
constructor(source) {
|
|
5428
|
+
source += "\0";
|
|
5429
|
+
this.source = source;
|
|
5430
|
+
this.#length = source.length;
|
|
5431
|
+
}
|
|
5432
|
+
peek(offset = 0) {
|
|
5433
|
+
return this.source.charCodeAt(this.position + offset);
|
|
5434
|
+
}
|
|
5435
|
+
next() {
|
|
5436
|
+
this.position += 1;
|
|
5437
|
+
}
|
|
5438
|
+
eof() {
|
|
5439
|
+
return this.position >= this.#length - 1;
|
|
5440
|
+
}
|
|
5441
|
+
};
|
|
5244
5442
|
var LoaderState = class {
|
|
5245
|
-
|
|
5246
|
-
length;
|
|
5443
|
+
#scanner;
|
|
5247
5444
|
lineIndent = 0;
|
|
5248
5445
|
lineStart = 0;
|
|
5249
|
-
position = 0;
|
|
5250
5446
|
line = 0;
|
|
5251
5447
|
onWarning;
|
|
5252
5448
|
allowDuplicateKeys;
|
|
@@ -5256,44 +5452,40 @@ var LoaderState = class {
|
|
|
5256
5452
|
tagMap = /* @__PURE__ */ new Map();
|
|
5257
5453
|
anchorMap = /* @__PURE__ */ new Map();
|
|
5258
5454
|
constructor(input, { schema = DEFAULT_SCHEMA, onWarning, allowDuplicateKeys = false }) {
|
|
5259
|
-
this
|
|
5455
|
+
this.#scanner = new Scanner(input);
|
|
5260
5456
|
this.onWarning = onWarning;
|
|
5261
5457
|
this.allowDuplicateKeys = allowDuplicateKeys;
|
|
5262
5458
|
this.implicitTypes = schema.implicitTypes;
|
|
5263
5459
|
this.typeMap = schema.typeMap;
|
|
5264
|
-
this.length = input.length;
|
|
5265
5460
|
this.readIndent();
|
|
5266
5461
|
}
|
|
5267
5462
|
skipWhitespaces() {
|
|
5268
|
-
let ch = this.peek();
|
|
5463
|
+
let ch = this.#scanner.peek();
|
|
5269
5464
|
while (isWhiteSpace(ch)) {
|
|
5270
|
-
|
|
5465
|
+
this.#scanner.next();
|
|
5466
|
+
ch = this.#scanner.peek();
|
|
5271
5467
|
}
|
|
5272
5468
|
}
|
|
5273
5469
|
skipComment() {
|
|
5274
|
-
let ch = this.peek();
|
|
5470
|
+
let ch = this.#scanner.peek();
|
|
5275
5471
|
if (ch !== SHARP) return;
|
|
5276
|
-
|
|
5472
|
+
this.#scanner.next();
|
|
5473
|
+
ch = this.#scanner.peek();
|
|
5277
5474
|
while (ch !== 0 && !isEOL(ch)) {
|
|
5278
|
-
|
|
5475
|
+
this.#scanner.next();
|
|
5476
|
+
ch = this.#scanner.peek();
|
|
5279
5477
|
}
|
|
5280
5478
|
}
|
|
5281
5479
|
readIndent() {
|
|
5282
|
-
let
|
|
5283
|
-
while (
|
|
5480
|
+
let ch = this.#scanner.peek();
|
|
5481
|
+
while (ch === SPACE) {
|
|
5284
5482
|
this.lineIndent += 1;
|
|
5285
|
-
|
|
5483
|
+
this.#scanner.next();
|
|
5484
|
+
ch = this.#scanner.peek();
|
|
5286
5485
|
}
|
|
5287
5486
|
}
|
|
5288
|
-
peek(offset = 0) {
|
|
5289
|
-
return this.input.charCodeAt(this.position + offset);
|
|
5290
|
-
}
|
|
5291
|
-
next() {
|
|
5292
|
-
this.position += 1;
|
|
5293
|
-
return this.peek();
|
|
5294
|
-
}
|
|
5295
5487
|
#createError(message) {
|
|
5296
|
-
const mark = markToString(this.
|
|
5488
|
+
const mark = markToString(this.#scanner.source, this.#scanner.position, this.line, this.#scanner.position - this.lineStart);
|
|
5297
5489
|
return new SyntaxError(`${message} ${mark}`);
|
|
5298
5490
|
}
|
|
5299
5491
|
dispatchWarning(message) {
|
|
@@ -5338,7 +5530,7 @@ var LoaderState = class {
|
|
|
5338
5530
|
}
|
|
5339
5531
|
captureSegment(start, end, checkJson) {
|
|
5340
5532
|
if (start < end) {
|
|
5341
|
-
const result = this.
|
|
5533
|
+
const result = this.#scanner.source.slice(start, end);
|
|
5342
5534
|
if (checkJson) {
|
|
5343
5535
|
for (let position = 0; position < result.length; position++) {
|
|
5344
5536
|
const character = result.charCodeAt(position);
|
|
@@ -5356,21 +5548,21 @@ var LoaderState = class {
|
|
|
5356
5548
|
let detected = false;
|
|
5357
5549
|
const result = [];
|
|
5358
5550
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
5359
|
-
let ch = this.peek();
|
|
5551
|
+
let ch = this.#scanner.peek();
|
|
5360
5552
|
while (ch !== 0) {
|
|
5361
5553
|
if (ch !== MINUS) {
|
|
5362
5554
|
break;
|
|
5363
5555
|
}
|
|
5364
|
-
const following = this.peek(1);
|
|
5556
|
+
const following = this.#scanner.peek(1);
|
|
5365
5557
|
if (!isWhiteSpaceOrEOL(following)) {
|
|
5366
5558
|
break;
|
|
5367
5559
|
}
|
|
5368
5560
|
detected = true;
|
|
5369
|
-
this.
|
|
5561
|
+
this.#scanner.next();
|
|
5370
5562
|
if (this.skipSeparationSpace(true, -1)) {
|
|
5371
5563
|
if (this.lineIndent <= nodeIndent) {
|
|
5372
5564
|
result.push(null);
|
|
5373
|
-
ch = this.peek();
|
|
5565
|
+
ch = this.#scanner.peek();
|
|
5374
5566
|
continue;
|
|
5375
5567
|
}
|
|
5376
5568
|
}
|
|
@@ -5383,7 +5575,7 @@ var LoaderState = class {
|
|
|
5383
5575
|
});
|
|
5384
5576
|
if (newState) result.push(newState.result);
|
|
5385
5577
|
this.skipSeparationSpace(true, -1);
|
|
5386
|
-
ch = this.peek();
|
|
5578
|
+
ch = this.#scanner.peek();
|
|
5387
5579
|
if ((this.line === line || this.lineIndent > nodeIndent) && ch !== 0) {
|
|
5388
5580
|
throw this.#createError("Cannot read block sequence: bad indentation of a sequence entry");
|
|
5389
5581
|
} else if (this.lineIndent < nodeIndent) {
|
|
@@ -5439,7 +5631,7 @@ var LoaderState = class {
|
|
|
5439
5631
|
} else {
|
|
5440
5632
|
if (!this.allowDuplicateKeys && !overridableKeys.has(keyNode) && Object.hasOwn(result, keyNode)) {
|
|
5441
5633
|
this.line = startLine || this.line;
|
|
5442
|
-
this.position = startPos || this.position;
|
|
5634
|
+
this.#scanner.position = startPos || this.#scanner.position;
|
|
5443
5635
|
throw this.#createError("Cannot store mapping pair: duplicated key");
|
|
5444
5636
|
}
|
|
5445
5637
|
Object.defineProperty(result, keyNode, {
|
|
@@ -5453,37 +5645,37 @@ var LoaderState = class {
|
|
|
5453
5645
|
return result;
|
|
5454
5646
|
}
|
|
5455
5647
|
readLineBreak() {
|
|
5456
|
-
const ch = this.peek();
|
|
5648
|
+
const ch = this.#scanner.peek();
|
|
5457
5649
|
if (ch === LINE_FEED) {
|
|
5458
|
-
this.
|
|
5650
|
+
this.#scanner.next();
|
|
5459
5651
|
} else if (ch === CARRIAGE_RETURN) {
|
|
5460
|
-
this.
|
|
5461
|
-
if (this.peek() === LINE_FEED) {
|
|
5462
|
-
this.
|
|
5652
|
+
this.#scanner.next();
|
|
5653
|
+
if (this.#scanner.peek() === LINE_FEED) {
|
|
5654
|
+
this.#scanner.next();
|
|
5463
5655
|
}
|
|
5464
5656
|
} else {
|
|
5465
5657
|
throw this.#createError("Cannot read line: line break not found");
|
|
5466
5658
|
}
|
|
5467
5659
|
this.line += 1;
|
|
5468
|
-
this.lineStart = this.position;
|
|
5660
|
+
this.lineStart = this.#scanner.position;
|
|
5469
5661
|
}
|
|
5470
5662
|
skipSeparationSpace(allowComments, checkIndent) {
|
|
5471
5663
|
let lineBreaks = 0;
|
|
5472
|
-
let ch = this.peek();
|
|
5664
|
+
let ch = this.#scanner.peek();
|
|
5473
5665
|
while (ch !== 0) {
|
|
5474
5666
|
this.skipWhitespaces();
|
|
5475
|
-
ch = this.peek();
|
|
5667
|
+
ch = this.#scanner.peek();
|
|
5476
5668
|
if (allowComments) {
|
|
5477
5669
|
this.skipComment();
|
|
5478
|
-
ch = this.peek();
|
|
5670
|
+
ch = this.#scanner.peek();
|
|
5479
5671
|
}
|
|
5480
5672
|
if (isEOL(ch)) {
|
|
5481
5673
|
this.readLineBreak();
|
|
5482
|
-
ch = this.peek();
|
|
5674
|
+
ch = this.#scanner.peek();
|
|
5483
5675
|
lineBreaks++;
|
|
5484
5676
|
this.lineIndent = 0;
|
|
5485
5677
|
this.readIndent();
|
|
5486
|
-
ch = this.peek();
|
|
5678
|
+
ch = this.#scanner.peek();
|
|
5487
5679
|
} else {
|
|
5488
5680
|
break;
|
|
5489
5681
|
}
|
|
@@ -5494,9 +5686,9 @@ var LoaderState = class {
|
|
|
5494
5686
|
return lineBreaks;
|
|
5495
5687
|
}
|
|
5496
5688
|
testDocumentSeparator() {
|
|
5497
|
-
let ch = this.peek();
|
|
5498
|
-
if ((ch === MINUS || ch === DOT) && ch === this.peek(1) && ch === this.peek(2)) {
|
|
5499
|
-
ch = this.peek(3);
|
|
5689
|
+
let ch = this.#scanner.peek();
|
|
5690
|
+
if ((ch === MINUS || ch === DOT) && ch === this.#scanner.peek(1) && ch === this.#scanner.peek(2)) {
|
|
5691
|
+
ch = this.#scanner.peek(3);
|
|
5500
5692
|
if (ch === 0 || isWhiteSpaceOrEOL(ch)) {
|
|
5501
5693
|
return true;
|
|
5502
5694
|
}
|
|
@@ -5504,34 +5696,34 @@ var LoaderState = class {
|
|
|
5504
5696
|
return false;
|
|
5505
5697
|
}
|
|
5506
5698
|
readPlainScalar(tag, anchor, nodeIndent, withinFlowCollection) {
|
|
5507
|
-
let ch = this.peek();
|
|
5699
|
+
let ch = this.#scanner.peek();
|
|
5508
5700
|
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) {
|
|
5509
5701
|
return;
|
|
5510
5702
|
}
|
|
5511
5703
|
let following;
|
|
5512
5704
|
if (ch === QUESTION || ch === MINUS) {
|
|
5513
|
-
following = this.peek(1);
|
|
5705
|
+
following = this.#scanner.peek(1);
|
|
5514
5706
|
if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
|
|
5515
5707
|
return;
|
|
5516
5708
|
}
|
|
5517
5709
|
}
|
|
5518
5710
|
let result = "";
|
|
5519
|
-
let captureEnd = this.position;
|
|
5520
|
-
let captureStart = this.position;
|
|
5711
|
+
let captureEnd = this.#scanner.position;
|
|
5712
|
+
let captureStart = this.#scanner.position;
|
|
5521
5713
|
let hasPendingContent = false;
|
|
5522
5714
|
let line = 0;
|
|
5523
5715
|
while (ch !== 0) {
|
|
5524
5716
|
if (ch === COLON) {
|
|
5525
|
-
following = this.peek(1);
|
|
5717
|
+
following = this.#scanner.peek(1);
|
|
5526
5718
|
if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
|
|
5527
5719
|
break;
|
|
5528
5720
|
}
|
|
5529
5721
|
} else if (ch === SHARP) {
|
|
5530
|
-
const preceding = this.peek(-1);
|
|
5722
|
+
const preceding = this.#scanner.peek(-1);
|
|
5531
5723
|
if (isWhiteSpaceOrEOL(preceding)) {
|
|
5532
5724
|
break;
|
|
5533
5725
|
}
|
|
5534
|
-
} else if (this.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
|
|
5726
|
+
} else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
|
|
5535
5727
|
break;
|
|
5536
5728
|
} else if (isEOL(ch)) {
|
|
5537
5729
|
line = this.line;
|
|
@@ -5540,10 +5732,10 @@ var LoaderState = class {
|
|
|
5540
5732
|
this.skipSeparationSpace(false, -1);
|
|
5541
5733
|
if (this.lineIndent >= nodeIndent) {
|
|
5542
5734
|
hasPendingContent = true;
|
|
5543
|
-
ch = this.peek();
|
|
5735
|
+
ch = this.#scanner.peek();
|
|
5544
5736
|
continue;
|
|
5545
5737
|
} else {
|
|
5546
|
-
this.position = captureEnd;
|
|
5738
|
+
this.#scanner.position = captureEnd;
|
|
5547
5739
|
this.line = line;
|
|
5548
5740
|
this.lineStart = lineStart;
|
|
5549
5741
|
this.lineIndent = lineIndent;
|
|
@@ -5554,13 +5746,14 @@ var LoaderState = class {
|
|
|
5554
5746
|
const segment2 = this.captureSegment(captureStart, captureEnd, false);
|
|
5555
5747
|
if (segment2) result += segment2;
|
|
5556
5748
|
result += writeFoldedLines(this.line - line);
|
|
5557
|
-
captureStart = captureEnd = this.position;
|
|
5749
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
5558
5750
|
hasPendingContent = false;
|
|
5559
5751
|
}
|
|
5560
5752
|
if (!isWhiteSpace(ch)) {
|
|
5561
|
-
captureEnd = this.position + 1;
|
|
5753
|
+
captureEnd = this.#scanner.position + 1;
|
|
5562
5754
|
}
|
|
5563
|
-
|
|
5755
|
+
this.#scanner.next();
|
|
5756
|
+
ch = this.#scanner.peek();
|
|
5564
5757
|
}
|
|
5565
5758
|
const segment = this.captureSegment(captureStart, captureEnd, false);
|
|
5566
5759
|
if (segment) result += segment;
|
|
@@ -5573,22 +5766,23 @@ var LoaderState = class {
|
|
|
5573
5766
|
};
|
|
5574
5767
|
}
|
|
5575
5768
|
readSingleQuotedScalar(tag, anchor, nodeIndent) {
|
|
5576
|
-
let ch = this.peek();
|
|
5769
|
+
let ch = this.#scanner.peek();
|
|
5577
5770
|
if (ch !== SINGLE_QUOTE) return;
|
|
5578
5771
|
let result = "";
|
|
5579
|
-
this.
|
|
5580
|
-
let captureStart = this.position;
|
|
5581
|
-
let captureEnd = this.position;
|
|
5582
|
-
ch = this.peek();
|
|
5772
|
+
this.#scanner.next();
|
|
5773
|
+
let captureStart = this.#scanner.position;
|
|
5774
|
+
let captureEnd = this.#scanner.position;
|
|
5775
|
+
ch = this.#scanner.peek();
|
|
5583
5776
|
while (ch !== 0) {
|
|
5584
5777
|
if (ch === SINGLE_QUOTE) {
|
|
5585
|
-
const segment = this.captureSegment(captureStart, this.position, true);
|
|
5778
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, true);
|
|
5586
5779
|
if (segment) result += segment;
|
|
5587
|
-
|
|
5780
|
+
this.#scanner.next();
|
|
5781
|
+
ch = this.#scanner.peek();
|
|
5588
5782
|
if (ch === SINGLE_QUOTE) {
|
|
5589
|
-
captureStart = this.position;
|
|
5590
|
-
this.
|
|
5591
|
-
captureEnd = this.position;
|
|
5783
|
+
captureStart = this.#scanner.position;
|
|
5784
|
+
this.#scanner.next();
|
|
5785
|
+
captureEnd = this.#scanner.position;
|
|
5592
5786
|
} else {
|
|
5593
5787
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
5594
5788
|
return {
|
|
@@ -5602,31 +5796,31 @@ var LoaderState = class {
|
|
|
5602
5796
|
const segment = this.captureSegment(captureStart, captureEnd, true);
|
|
5603
5797
|
if (segment) result += segment;
|
|
5604
5798
|
result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
|
|
5605
|
-
captureStart = captureEnd = this.position;
|
|
5606
|
-
} else if (this.position === this.lineStart && this.testDocumentSeparator()) {
|
|
5799
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
5800
|
+
} else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
|
|
5607
5801
|
throw this.#createError("Unexpected end of the document within a single quoted scalar");
|
|
5608
5802
|
} else {
|
|
5609
|
-
this.
|
|
5610
|
-
captureEnd = this.position;
|
|
5803
|
+
this.#scanner.next();
|
|
5804
|
+
captureEnd = this.#scanner.position;
|
|
5611
5805
|
}
|
|
5612
|
-
ch = this.peek();
|
|
5806
|
+
ch = this.#scanner.peek();
|
|
5613
5807
|
}
|
|
5614
5808
|
throw this.#createError("Unexpected end of the stream within a single quoted scalar");
|
|
5615
5809
|
}
|
|
5616
5810
|
readDoubleQuotedScalar(tag, anchor, nodeIndent) {
|
|
5617
|
-
let ch = this.peek();
|
|
5811
|
+
let ch = this.#scanner.peek();
|
|
5618
5812
|
if (ch !== DOUBLE_QUOTE) return;
|
|
5619
5813
|
let result = "";
|
|
5620
|
-
this.
|
|
5621
|
-
let captureEnd = this.position;
|
|
5622
|
-
let captureStart = this.position;
|
|
5814
|
+
this.#scanner.next();
|
|
5815
|
+
let captureEnd = this.#scanner.position;
|
|
5816
|
+
let captureStart = this.#scanner.position;
|
|
5623
5817
|
let tmp;
|
|
5624
|
-
ch = this.peek();
|
|
5818
|
+
ch = this.#scanner.peek();
|
|
5625
5819
|
while (ch !== 0) {
|
|
5626
5820
|
if (ch === DOUBLE_QUOTE) {
|
|
5627
|
-
const segment = this.captureSegment(captureStart, this.position, true);
|
|
5821
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, true);
|
|
5628
5822
|
if (segment) result += segment;
|
|
5629
|
-
this.
|
|
5823
|
+
this.#scanner.next();
|
|
5630
5824
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
5631
5825
|
return {
|
|
5632
5826
|
tag,
|
|
@@ -5636,19 +5830,21 @@ var LoaderState = class {
|
|
|
5636
5830
|
};
|
|
5637
5831
|
}
|
|
5638
5832
|
if (ch === BACKSLASH) {
|
|
5639
|
-
const segment = this.captureSegment(captureStart, this.position, true);
|
|
5833
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, true);
|
|
5640
5834
|
if (segment) result += segment;
|
|
5641
|
-
|
|
5835
|
+
this.#scanner.next();
|
|
5836
|
+
ch = this.#scanner.peek();
|
|
5642
5837
|
if (isEOL(ch)) {
|
|
5643
5838
|
this.skipSeparationSpace(false, nodeIndent);
|
|
5644
5839
|
} else if (ch < 256 && SIMPLE_ESCAPE_SEQUENCES.has(ch)) {
|
|
5645
5840
|
result += SIMPLE_ESCAPE_SEQUENCES.get(ch);
|
|
5646
|
-
this.
|
|
5841
|
+
this.#scanner.next();
|
|
5647
5842
|
} else if ((tmp = ESCAPED_HEX_LENGTHS.get(ch) ?? 0) > 0) {
|
|
5648
5843
|
let hexLength = tmp;
|
|
5649
5844
|
let hexResult = 0;
|
|
5650
5845
|
for (; hexLength > 0; hexLength--) {
|
|
5651
|
-
|
|
5846
|
+
this.#scanner.next();
|
|
5847
|
+
ch = this.#scanner.peek();
|
|
5652
5848
|
if ((tmp = hexCharCodeToNumber(ch)) >= 0) {
|
|
5653
5849
|
hexResult = (hexResult << 4) + tmp;
|
|
5654
5850
|
} else {
|
|
@@ -5656,28 +5852,28 @@ var LoaderState = class {
|
|
|
5656
5852
|
}
|
|
5657
5853
|
}
|
|
5658
5854
|
result += codepointToChar(hexResult);
|
|
5659
|
-
this.
|
|
5855
|
+
this.#scanner.next();
|
|
5660
5856
|
} else {
|
|
5661
5857
|
throw this.#createError("Cannot read double quoted scalar: unknown escape sequence");
|
|
5662
5858
|
}
|
|
5663
|
-
captureStart = captureEnd = this.position;
|
|
5859
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
5664
5860
|
} else if (isEOL(ch)) {
|
|
5665
5861
|
const segment = this.captureSegment(captureStart, captureEnd, true);
|
|
5666
5862
|
if (segment) result += segment;
|
|
5667
5863
|
result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
|
|
5668
|
-
captureStart = captureEnd = this.position;
|
|
5669
|
-
} else if (this.position === this.lineStart && this.testDocumentSeparator()) {
|
|
5864
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
5865
|
+
} else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
|
|
5670
5866
|
throw this.#createError("Unexpected end of the document within a double quoted scalar");
|
|
5671
5867
|
} else {
|
|
5672
|
-
this.
|
|
5673
|
-
captureEnd = this.position;
|
|
5868
|
+
this.#scanner.next();
|
|
5869
|
+
captureEnd = this.#scanner.position;
|
|
5674
5870
|
}
|
|
5675
|
-
ch = this.peek();
|
|
5871
|
+
ch = this.#scanner.peek();
|
|
5676
5872
|
}
|
|
5677
5873
|
throw this.#createError("Unexpected end of the stream within a double quoted scalar");
|
|
5678
5874
|
}
|
|
5679
5875
|
readFlowCollection(tag, anchor, nodeIndent) {
|
|
5680
|
-
let ch = this.peek();
|
|
5876
|
+
let ch = this.#scanner.peek();
|
|
5681
5877
|
let terminator;
|
|
5682
5878
|
let isMapping = true;
|
|
5683
5879
|
let result = {};
|
|
@@ -5691,7 +5887,8 @@ var LoaderState = class {
|
|
|
5691
5887
|
return;
|
|
5692
5888
|
}
|
|
5693
5889
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
5694
|
-
|
|
5890
|
+
this.#scanner.next();
|
|
5891
|
+
ch = this.#scanner.peek();
|
|
5695
5892
|
let readNext = true;
|
|
5696
5893
|
let valueNode = null;
|
|
5697
5894
|
let keyNode = null;
|
|
@@ -5703,9 +5900,9 @@ var LoaderState = class {
|
|
|
5703
5900
|
const overridableKeys = /* @__PURE__ */ new Set();
|
|
5704
5901
|
while (ch !== 0) {
|
|
5705
5902
|
this.skipSeparationSpace(true, nodeIndent);
|
|
5706
|
-
ch = this.peek();
|
|
5903
|
+
ch = this.#scanner.peek();
|
|
5707
5904
|
if (ch === terminator) {
|
|
5708
|
-
this.
|
|
5905
|
+
this.#scanner.next();
|
|
5709
5906
|
const kind = isMapping ? "mapping" : "sequence";
|
|
5710
5907
|
return {
|
|
5711
5908
|
tag,
|
|
@@ -5720,10 +5917,10 @@ var LoaderState = class {
|
|
|
5720
5917
|
keyTag = keyNode = valueNode = null;
|
|
5721
5918
|
isPair = isExplicitPair = false;
|
|
5722
5919
|
if (ch === QUESTION) {
|
|
5723
|
-
following = this.peek(1);
|
|
5920
|
+
following = this.#scanner.peek(1);
|
|
5724
5921
|
if (isWhiteSpaceOrEOL(following)) {
|
|
5725
5922
|
isPair = isExplicitPair = true;
|
|
5726
|
-
this.
|
|
5923
|
+
this.#scanner.next();
|
|
5727
5924
|
this.skipSeparationSpace(true, nodeIndent);
|
|
5728
5925
|
}
|
|
5729
5926
|
}
|
|
@@ -5739,10 +5936,11 @@ var LoaderState = class {
|
|
|
5739
5936
|
keyNode = newState.result;
|
|
5740
5937
|
}
|
|
5741
5938
|
this.skipSeparationSpace(true, nodeIndent);
|
|
5742
|
-
ch = this.peek();
|
|
5939
|
+
ch = this.#scanner.peek();
|
|
5743
5940
|
if ((isExplicitPair || this.line === line) && ch === COLON) {
|
|
5744
5941
|
isPair = true;
|
|
5745
|
-
|
|
5942
|
+
this.#scanner.next();
|
|
5943
|
+
ch = this.#scanner.peek();
|
|
5746
5944
|
this.skipSeparationSpace(true, nodeIndent);
|
|
5747
5945
|
const newState2 = this.composeNode({
|
|
5748
5946
|
parentIndent: nodeIndent,
|
|
@@ -5760,10 +5958,11 @@ var LoaderState = class {
|
|
|
5760
5958
|
result.push(keyNode);
|
|
5761
5959
|
}
|
|
5762
5960
|
this.skipSeparationSpace(true, nodeIndent);
|
|
5763
|
-
ch = this.peek();
|
|
5961
|
+
ch = this.#scanner.peek();
|
|
5764
5962
|
if (ch === COMMA) {
|
|
5765
5963
|
readNext = true;
|
|
5766
|
-
|
|
5964
|
+
this.#scanner.next();
|
|
5965
|
+
ch = this.#scanner.peek();
|
|
5767
5966
|
} else {
|
|
5768
5967
|
readNext = false;
|
|
5769
5968
|
}
|
|
@@ -5779,7 +5978,7 @@ var LoaderState = class {
|
|
|
5779
5978
|
let textIndent = nodeIndent;
|
|
5780
5979
|
let emptyLines = 0;
|
|
5781
5980
|
let atMoreIndented = false;
|
|
5782
|
-
let ch = this.peek();
|
|
5981
|
+
let ch = this.#scanner.peek();
|
|
5783
5982
|
let folding = false;
|
|
5784
5983
|
if (ch === VERTICAL_LINE) {
|
|
5785
5984
|
folding = false;
|
|
@@ -5791,7 +5990,8 @@ var LoaderState = class {
|
|
|
5791
5990
|
let result = "";
|
|
5792
5991
|
let tmp = 0;
|
|
5793
5992
|
while (ch !== 0) {
|
|
5794
|
-
|
|
5993
|
+
this.#scanner.next();
|
|
5994
|
+
ch = this.#scanner.peek();
|
|
5795
5995
|
if (ch === PLUS || ch === MINUS) {
|
|
5796
5996
|
if (CHOMPING_CLIP === chomping) {
|
|
5797
5997
|
chomping = ch === PLUS ? CHOMPING_KEEP : CHOMPING_STRIP;
|
|
@@ -5814,15 +6014,16 @@ var LoaderState = class {
|
|
|
5814
6014
|
if (isWhiteSpace(ch)) {
|
|
5815
6015
|
this.skipWhitespaces();
|
|
5816
6016
|
this.skipComment();
|
|
5817
|
-
ch = this.peek();
|
|
6017
|
+
ch = this.#scanner.peek();
|
|
5818
6018
|
}
|
|
5819
6019
|
while (ch !== 0) {
|
|
5820
6020
|
this.readLineBreak();
|
|
5821
6021
|
this.lineIndent = 0;
|
|
5822
|
-
ch = this.peek();
|
|
6022
|
+
ch = this.#scanner.peek();
|
|
5823
6023
|
while ((!detectedIndent || this.lineIndent < textIndent) && ch === SPACE) {
|
|
5824
6024
|
this.lineIndent++;
|
|
5825
|
-
|
|
6025
|
+
this.#scanner.next();
|
|
6026
|
+
ch = this.#scanner.peek();
|
|
5826
6027
|
}
|
|
5827
6028
|
if (!detectedIndent && this.lineIndent > textIndent) {
|
|
5828
6029
|
textIndent = this.lineIndent;
|
|
@@ -5861,11 +6062,12 @@ var LoaderState = class {
|
|
|
5861
6062
|
didReadContent = true;
|
|
5862
6063
|
detectedIndent = true;
|
|
5863
6064
|
emptyLines = 0;
|
|
5864
|
-
const captureStart = this.position;
|
|
6065
|
+
const captureStart = this.#scanner.position;
|
|
5865
6066
|
while (!isEOL(ch) && ch !== 0) {
|
|
5866
|
-
|
|
6067
|
+
this.#scanner.next();
|
|
6068
|
+
ch = this.#scanner.peek();
|
|
5867
6069
|
}
|
|
5868
|
-
const segment = this.captureSegment(captureStart, this.position, false);
|
|
6070
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, false);
|
|
5869
6071
|
if (segment) result += segment;
|
|
5870
6072
|
}
|
|
5871
6073
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
@@ -5888,11 +6090,11 @@ var LoaderState = class {
|
|
|
5888
6090
|
let atExplicitKey = false;
|
|
5889
6091
|
let detected = false;
|
|
5890
6092
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
5891
|
-
let ch = this.peek();
|
|
6093
|
+
let ch = this.#scanner.peek();
|
|
5892
6094
|
while (ch !== 0) {
|
|
5893
|
-
const following = this.peek(1);
|
|
6095
|
+
const following = this.#scanner.peek(1);
|
|
5894
6096
|
line = this.line;
|
|
5895
|
-
pos = this.position;
|
|
6097
|
+
pos = this.#scanner.position;
|
|
5896
6098
|
if ((ch === QUESTION || ch === COLON) && isWhiteSpaceOrEOL(following)) {
|
|
5897
6099
|
if (ch === QUESTION) {
|
|
5898
6100
|
if (atExplicitKey) {
|
|
@@ -5910,7 +6112,7 @@ var LoaderState = class {
|
|
|
5910
6112
|
} else {
|
|
5911
6113
|
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");
|
|
5912
6114
|
}
|
|
5913
|
-
this.
|
|
6115
|
+
this.#scanner.next();
|
|
5914
6116
|
ch = following;
|
|
5915
6117
|
} else {
|
|
5916
6118
|
const newState = this.composeNode({
|
|
@@ -5921,11 +6123,12 @@ var LoaderState = class {
|
|
|
5921
6123
|
});
|
|
5922
6124
|
if (!newState) break;
|
|
5923
6125
|
if (this.line === line) {
|
|
5924
|
-
ch = this.peek();
|
|
6126
|
+
ch = this.#scanner.peek();
|
|
5925
6127
|
this.skipWhitespaces();
|
|
5926
|
-
ch = this.peek();
|
|
6128
|
+
ch = this.#scanner.peek();
|
|
5927
6129
|
if (ch === COLON) {
|
|
5928
|
-
|
|
6130
|
+
this.#scanner.next();
|
|
6131
|
+
ch = this.#scanner.peek();
|
|
5929
6132
|
if (!isWhiteSpaceOrEOL(ch)) {
|
|
5930
6133
|
throw this.#createError("Cannot read block: a whitespace character is expected after the key-value separator within a block mapping");
|
|
5931
6134
|
}
|
|
@@ -5982,7 +6185,7 @@ var LoaderState = class {
|
|
|
5982
6185
|
keyTag = keyNode = valueNode = null;
|
|
5983
6186
|
}
|
|
5984
6187
|
this.skipSeparationSpace(true, -1);
|
|
5985
|
-
ch = this.peek();
|
|
6188
|
+
ch = this.#scanner.peek();
|
|
5986
6189
|
}
|
|
5987
6190
|
if (this.lineIndent > nodeIndent && ch !== 0) {
|
|
5988
6191
|
throw this.#createError("Cannot read block: bad indentation of a mapping entry");
|
|
@@ -6005,30 +6208,35 @@ var LoaderState = class {
|
|
|
6005
6208
|
let isNamed = false;
|
|
6006
6209
|
let tagHandle = "";
|
|
6007
6210
|
let tagName;
|
|
6008
|
-
let ch = this.peek();
|
|
6211
|
+
let ch = this.#scanner.peek();
|
|
6009
6212
|
if (ch !== EXCLAMATION) return;
|
|
6010
6213
|
if (tag !== null) {
|
|
6011
6214
|
throw this.#createError("Cannot read tag property: duplication of a tag property");
|
|
6012
6215
|
}
|
|
6013
|
-
|
|
6216
|
+
this.#scanner.next();
|
|
6217
|
+
ch = this.#scanner.peek();
|
|
6014
6218
|
if (ch === SMALLER_THAN) {
|
|
6015
6219
|
isVerbatim = true;
|
|
6016
|
-
|
|
6220
|
+
this.#scanner.next();
|
|
6221
|
+
ch = this.#scanner.peek();
|
|
6017
6222
|
} else if (ch === EXCLAMATION) {
|
|
6018
6223
|
isNamed = true;
|
|
6019
6224
|
tagHandle = "!!";
|
|
6020
|
-
|
|
6225
|
+
this.#scanner.next();
|
|
6226
|
+
ch = this.#scanner.peek();
|
|
6021
6227
|
} else {
|
|
6022
6228
|
tagHandle = "!";
|
|
6023
6229
|
}
|
|
6024
|
-
let position = this.position;
|
|
6230
|
+
let position = this.#scanner.position;
|
|
6025
6231
|
if (isVerbatim) {
|
|
6026
6232
|
do {
|
|
6027
|
-
|
|
6233
|
+
this.#scanner.next();
|
|
6234
|
+
ch = this.#scanner.peek();
|
|
6028
6235
|
} while (ch !== 0 && ch !== GREATER_THAN);
|
|
6029
|
-
if (this.
|
|
6030
|
-
tagName = this.
|
|
6031
|
-
|
|
6236
|
+
if (!this.#scanner.eof()) {
|
|
6237
|
+
tagName = this.#scanner.source.slice(position, this.#scanner.position);
|
|
6238
|
+
this.#scanner.next();
|
|
6239
|
+
ch = this.#scanner.peek();
|
|
6032
6240
|
} else {
|
|
6033
6241
|
throw this.#createError("Cannot read tag property: unexpected end of stream");
|
|
6034
6242
|
}
|
|
@@ -6036,19 +6244,20 @@ var LoaderState = class {
|
|
|
6036
6244
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
|
|
6037
6245
|
if (ch === EXCLAMATION) {
|
|
6038
6246
|
if (!isNamed) {
|
|
6039
|
-
tagHandle = this.
|
|
6247
|
+
tagHandle = this.#scanner.source.slice(position - 1, this.#scanner.position + 1);
|
|
6040
6248
|
if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
|
6041
6249
|
throw this.#createError("Cannot read tag property: named tag handle contains invalid characters");
|
|
6042
6250
|
}
|
|
6043
6251
|
isNamed = true;
|
|
6044
|
-
position = this.position + 1;
|
|
6252
|
+
position = this.#scanner.position + 1;
|
|
6045
6253
|
} else {
|
|
6046
6254
|
throw this.#createError("Cannot read tag property: tag suffix cannot contain an exclamation mark");
|
|
6047
6255
|
}
|
|
6048
6256
|
}
|
|
6049
|
-
|
|
6257
|
+
this.#scanner.next();
|
|
6258
|
+
ch = this.#scanner.peek();
|
|
6050
6259
|
}
|
|
6051
|
-
tagName = this.
|
|
6260
|
+
tagName = this.#scanner.source.slice(position, this.#scanner.position);
|
|
6052
6261
|
if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
|
6053
6262
|
throw this.#createError("Cannot read tag property: tag suffix cannot contain flow indicator characters");
|
|
6054
6263
|
}
|
|
@@ -6068,32 +6277,36 @@ var LoaderState = class {
|
|
|
6068
6277
|
throw this.#createError(`Cannot read tag property: undeclared tag handle "${tagHandle}"`);
|
|
6069
6278
|
}
|
|
6070
6279
|
readAnchorProperty(anchor) {
|
|
6071
|
-
let ch = this.peek();
|
|
6280
|
+
let ch = this.#scanner.peek();
|
|
6072
6281
|
if (ch !== AMPERSAND) return;
|
|
6073
6282
|
if (anchor !== null) {
|
|
6074
6283
|
throw this.#createError("Cannot read anchor property: duplicate anchor property");
|
|
6075
6284
|
}
|
|
6076
|
-
|
|
6077
|
-
|
|
6285
|
+
this.#scanner.next();
|
|
6286
|
+
ch = this.#scanner.peek();
|
|
6287
|
+
const position = this.#scanner.position;
|
|
6078
6288
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
|
|
6079
|
-
|
|
6289
|
+
this.#scanner.next();
|
|
6290
|
+
ch = this.#scanner.peek();
|
|
6080
6291
|
}
|
|
6081
|
-
if (this.position === position) {
|
|
6292
|
+
if (this.#scanner.position === position) {
|
|
6082
6293
|
throw this.#createError("Cannot read anchor property: name of an anchor node must contain at least one character");
|
|
6083
6294
|
}
|
|
6084
|
-
return this.
|
|
6295
|
+
return this.#scanner.source.slice(position, this.#scanner.position);
|
|
6085
6296
|
}
|
|
6086
6297
|
readAlias() {
|
|
6087
|
-
if (this.peek() !== ASTERISK) return;
|
|
6088
|
-
|
|
6089
|
-
|
|
6298
|
+
if (this.#scanner.peek() !== ASTERISK) return;
|
|
6299
|
+
this.#scanner.next();
|
|
6300
|
+
let ch = this.#scanner.peek();
|
|
6301
|
+
const position = this.#scanner.position;
|
|
6090
6302
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
|
|
6091
|
-
|
|
6303
|
+
this.#scanner.next();
|
|
6304
|
+
ch = this.#scanner.peek();
|
|
6092
6305
|
}
|
|
6093
|
-
if (this.position === position) {
|
|
6306
|
+
if (this.#scanner.position === position) {
|
|
6094
6307
|
throw this.#createError("Cannot read alias: alias name must contain at least one character");
|
|
6095
6308
|
}
|
|
6096
|
-
const alias = this.
|
|
6309
|
+
const alias = this.#scanner.source.slice(position, this.#scanner.position);
|
|
6097
6310
|
if (!this.anchorMap.has(alias)) {
|
|
6098
6311
|
throw this.#createError(`Cannot read alias: unidentified alias "${alias}"`);
|
|
6099
6312
|
}
|
|
@@ -6176,7 +6389,7 @@ var LoaderState = class {
|
|
|
6176
6389
|
const cond = CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext;
|
|
6177
6390
|
const flowIndent = cond ? parentIndent : parentIndent + 1;
|
|
6178
6391
|
if (allowBlockCollections) {
|
|
6179
|
-
const blockIndent = this.position - this.lineStart;
|
|
6392
|
+
const blockIndent = this.#scanner.position - this.lineStart;
|
|
6180
6393
|
const blockSequenceState = this.readBlockSequence(tag, anchor, blockIndent);
|
|
6181
6394
|
if (blockSequenceState) return this.resolveTag(blockSequenceState);
|
|
6182
6395
|
const blockMappingState = this.readBlockMapping(tag, anchor, blockIndent, flowIndent);
|
|
@@ -6210,7 +6423,7 @@ var LoaderState = class {
|
|
|
6210
6423
|
return this.resolveTag(plainScalarState);
|
|
6211
6424
|
}
|
|
6212
6425
|
} else if (indentStatus === 0 && CONTEXT_BLOCK_OUT === nodeContext && allowBlockCollections) {
|
|
6213
|
-
const blockIndent = this.position - this.lineStart;
|
|
6426
|
+
const blockIndent = this.#scanner.position - this.lineStart;
|
|
6214
6427
|
const newState2 = this.readBlockSequence(tag, anchor, blockIndent);
|
|
6215
6428
|
if (newState2) return this.resolveTag(newState2);
|
|
6216
6429
|
}
|
|
@@ -6225,20 +6438,22 @@ var LoaderState = class {
|
|
|
6225
6438
|
readDirectives() {
|
|
6226
6439
|
let hasDirectives = false;
|
|
6227
6440
|
let version = null;
|
|
6228
|
-
let ch = this.peek();
|
|
6441
|
+
let ch = this.#scanner.peek();
|
|
6229
6442
|
while (ch !== 0) {
|
|
6230
6443
|
this.skipSeparationSpace(true, -1);
|
|
6231
|
-
ch = this.peek();
|
|
6444
|
+
ch = this.#scanner.peek();
|
|
6232
6445
|
if (this.lineIndent > 0 || ch !== PERCENT) {
|
|
6233
6446
|
break;
|
|
6234
6447
|
}
|
|
6235
6448
|
hasDirectives = true;
|
|
6236
|
-
|
|
6237
|
-
|
|
6449
|
+
this.#scanner.next();
|
|
6450
|
+
ch = this.#scanner.peek();
|
|
6451
|
+
let position = this.#scanner.position;
|
|
6238
6452
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
|
|
6239
|
-
|
|
6453
|
+
this.#scanner.next();
|
|
6454
|
+
ch = this.#scanner.peek();
|
|
6240
6455
|
}
|
|
6241
|
-
const directiveName = this.
|
|
6456
|
+
const directiveName = this.#scanner.source.slice(position, this.#scanner.position);
|
|
6242
6457
|
const directiveArgs = [];
|
|
6243
6458
|
if (directiveName.length < 1) {
|
|
6244
6459
|
throw this.#createError("Cannot read document: directive name length must be greater than zero");
|
|
@@ -6246,13 +6461,14 @@ var LoaderState = class {
|
|
|
6246
6461
|
while (ch !== 0) {
|
|
6247
6462
|
this.skipWhitespaces();
|
|
6248
6463
|
this.skipComment();
|
|
6249
|
-
ch = this.peek();
|
|
6464
|
+
ch = this.#scanner.peek();
|
|
6250
6465
|
if (isEOL(ch)) break;
|
|
6251
|
-
position = this.position;
|
|
6466
|
+
position = this.#scanner.position;
|
|
6252
6467
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
|
|
6253
|
-
|
|
6468
|
+
this.#scanner.next();
|
|
6469
|
+
ch = this.#scanner.peek();
|
|
6254
6470
|
}
|
|
6255
|
-
directiveArgs.push(this.
|
|
6471
|
+
directiveArgs.push(this.#scanner.source.slice(position, this.#scanner.position));
|
|
6256
6472
|
}
|
|
6257
6473
|
if (ch !== 0) this.readLineBreak();
|
|
6258
6474
|
switch (directiveName) {
|
|
@@ -6269,20 +6485,20 @@ var LoaderState = class {
|
|
|
6269
6485
|
this.dispatchWarning(`unknown document directive "${directiveName}"`);
|
|
6270
6486
|
break;
|
|
6271
6487
|
}
|
|
6272
|
-
ch = this.peek();
|
|
6488
|
+
ch = this.#scanner.peek();
|
|
6273
6489
|
}
|
|
6274
6490
|
return hasDirectives;
|
|
6275
6491
|
}
|
|
6276
6492
|
readDocument() {
|
|
6277
|
-
const documentStart = this.position;
|
|
6493
|
+
const documentStart = this.#scanner.position;
|
|
6278
6494
|
this.checkLineBreaks = false;
|
|
6279
6495
|
this.tagMap = /* @__PURE__ */ new Map();
|
|
6280
6496
|
this.anchorMap = /* @__PURE__ */ new Map();
|
|
6281
6497
|
const hasDirectives = this.readDirectives();
|
|
6282
6498
|
this.skipSeparationSpace(true, -1);
|
|
6283
6499
|
let result = null;
|
|
6284
|
-
if (this.lineIndent === 0 && this.peek() === MINUS && this.peek(1) === MINUS && this.peek(2) === MINUS) {
|
|
6285
|
-
this.position += 3;
|
|
6500
|
+
if (this.lineIndent === 0 && this.#scanner.peek() === MINUS && this.#scanner.peek(1) === MINUS && this.#scanner.peek(2) === MINUS) {
|
|
6501
|
+
this.#scanner.position += 3;
|
|
6286
6502
|
this.skipSeparationSpace(true, -1);
|
|
6287
6503
|
} else if (hasDirectives) {
|
|
6288
6504
|
throw this.#createError("Cannot read document: directives end mark is expected");
|
|
@@ -6295,21 +6511,21 @@ var LoaderState = class {
|
|
|
6295
6511
|
});
|
|
6296
6512
|
if (newState) result = newState.result;
|
|
6297
6513
|
this.skipSeparationSpace(true, -1);
|
|
6298
|
-
if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.
|
|
6514
|
+
if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.#scanner.source.slice(documentStart, this.#scanner.position))) {
|
|
6299
6515
|
this.dispatchWarning("non-ASCII line breaks are interpreted as content");
|
|
6300
6516
|
}
|
|
6301
|
-
if (this.position === this.lineStart && this.testDocumentSeparator()) {
|
|
6302
|
-
if (this.peek() === DOT) {
|
|
6303
|
-
this.position += 3;
|
|
6517
|
+
if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
|
|
6518
|
+
if (this.#scanner.peek() === DOT) {
|
|
6519
|
+
this.#scanner.position += 3;
|
|
6304
6520
|
this.skipSeparationSpace(true, -1);
|
|
6305
6521
|
}
|
|
6306
|
-
} else if (this.
|
|
6522
|
+
} else if (!this.#scanner.eof()) {
|
|
6307
6523
|
throw this.#createError("Cannot read document: end of the stream or a document separator is expected");
|
|
6308
6524
|
}
|
|
6309
6525
|
return result;
|
|
6310
6526
|
}
|
|
6311
6527
|
*readDocuments() {
|
|
6312
|
-
while (this.
|
|
6528
|
+
while (!this.#scanner.eof()) {
|
|
6313
6529
|
yield this.readDocument();
|
|
6314
6530
|
}
|
|
6315
6531
|
}
|
|
@@ -6322,7 +6538,6 @@ function sanitizeInput(input) {
|
|
|
6322
6538
|
if (!isEOL(input.charCodeAt(input.length - 1))) input += "\n";
|
|
6323
6539
|
if (input.charCodeAt(0) === 65279) input = input.slice(1);
|
|
6324
6540
|
}
|
|
6325
|
-
input += "\0";
|
|
6326
6541
|
return input;
|
|
6327
6542
|
}
|
|
6328
6543
|
function parse(content, options = {}) {
|
|
@@ -6340,10 +6555,10 @@ function parse(content, options = {}) {
|
|
|
6340
6555
|
}
|
|
6341
6556
|
|
|
6342
6557
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__plugin-markdown-loader/src/markdown-loader.js
|
|
6343
|
-
var
|
|
6558
|
+
var import_node_process2 = __toESM(require("node:process"), 1);
|
|
6344
6559
|
function replaceEnvVars(str2) {
|
|
6345
6560
|
return str2.replace(/\$([A-Za-z_][A-Za-z0-9_]*)(?!\s*\()/g, (match, varName) => {
|
|
6346
|
-
const value =
|
|
6561
|
+
const value = import_node_process2.default.env[varName];
|
|
6347
6562
|
if (value !== void 0) {
|
|
6348
6563
|
return value;
|
|
6349
6564
|
}
|
|
@@ -6442,18 +6657,19 @@ var defaultPlugin = markdownLoaderPlugin();
|
|
|
6442
6657
|
|
|
6443
6658
|
// __mcpc__cli_latest/node_modules/@mcpc/cli/src/defaults.js
|
|
6444
6659
|
var import_node_path5 = require("node:path");
|
|
6445
|
-
var
|
|
6660
|
+
var import_node_process3 = __toESM(require("node:process"), 1);
|
|
6446
6661
|
var DEFAULT_SKILLS_PATHS = [
|
|
6447
6662
|
".agent/skills"
|
|
6448
6663
|
];
|
|
6449
6664
|
var DEFAULT_CODE_EXECUTION_TIMEOUT = 3e5;
|
|
6450
6665
|
function getGlobalPlugins(skillsPaths) {
|
|
6451
|
-
const resolvedPaths = skillsPaths.map((p2) => (0, import_node_path5.resolve)(
|
|
6666
|
+
const resolvedPaths = skillsPaths.map((p2) => (0, import_node_path5.resolve)(import_node_process3.default.cwd(), p2));
|
|
6452
6667
|
return [
|
|
6453
6668
|
markdownLoaderPlugin(),
|
|
6454
6669
|
createSkillsPlugin({
|
|
6455
6670
|
paths: resolvedPaths
|
|
6456
|
-
})
|
|
6671
|
+
}),
|
|
6672
|
+
createBashPlugin()
|
|
6457
6673
|
];
|
|
6458
6674
|
}
|
|
6459
6675
|
function getAgentPlugins() {
|
|
@@ -6482,7 +6698,7 @@ function getDefaultAgents() {
|
|
|
6482
6698
|
}
|
|
6483
6699
|
|
|
6484
6700
|
// __mcpc__cli_latest/node_modules/@mcpc/cli/src/config/loader.js
|
|
6485
|
-
var CLI_VERSION = "0.1.
|
|
6701
|
+
var CLI_VERSION = "0.1.52";
|
|
6486
6702
|
function extractServerName(command, commandArgs) {
|
|
6487
6703
|
for (const arg of commandArgs) {
|
|
6488
6704
|
if (!arg.startsWith("-")) {
|
|
@@ -6542,7 +6758,7 @@ async function saveUserConfig(config, newAgentName) {
|
|
|
6542
6758
|
async function createWrapConfig(args) {
|
|
6543
6759
|
if (!args.mcpServers || args.mcpServers.length === 0) {
|
|
6544
6760
|
console.error("Error: --wrap/--add requires at least one MCP server\nExample: mcpc --wrap --mcp-stdio 'npx -y @wonderwhy-er/desktop-commander'\nMultiple: mcpc --add --mcp-stdio 'npx -y server1' --mcp-http 'https://api.example.com'");
|
|
6545
|
-
|
|
6761
|
+
import_node_process4.default.exit(1);
|
|
6546
6762
|
}
|
|
6547
6763
|
const mcpServers = {};
|
|
6548
6764
|
const serverNames = [];
|
|
@@ -6665,7 +6881,7 @@ function parseMcpServer(cmdString, transportType) {
|
|
|
6665
6881
|
};
|
|
6666
6882
|
}
|
|
6667
6883
|
function parseCLIArgs() {
|
|
6668
|
-
const args = parseArgs(
|
|
6884
|
+
const args = parseArgs(import_node_process4.default.argv.slice(2), {
|
|
6669
6885
|
boolean: [
|
|
6670
6886
|
"help",
|
|
6671
6887
|
"version",
|
|
@@ -6754,15 +6970,15 @@ async function loadConfig() {
|
|
|
6754
6970
|
const args = parseCLIArgs();
|
|
6755
6971
|
if (args.version) {
|
|
6756
6972
|
printVersion();
|
|
6757
|
-
|
|
6973
|
+
import_node_process4.default.exit(0);
|
|
6758
6974
|
}
|
|
6759
6975
|
if (args.help) {
|
|
6760
6976
|
printHelp();
|
|
6761
|
-
|
|
6977
|
+
import_node_process4.default.exit(0);
|
|
6762
6978
|
}
|
|
6763
6979
|
if (args.cwd) {
|
|
6764
|
-
const targetCwd = (0, import_node_path6.resolve)(
|
|
6765
|
-
|
|
6980
|
+
const targetCwd = (0, import_node_path6.resolve)(import_node_process4.default.cwd(), args.cwd);
|
|
6981
|
+
import_node_process4.default.chdir(targetCwd);
|
|
6766
6982
|
console.error(`Changed working directory to: ${targetCwd}`);
|
|
6767
6983
|
}
|
|
6768
6984
|
const mergeSkills = (config) => {
|
|
@@ -6774,7 +6990,7 @@ async function loadConfig() {
|
|
|
6774
6990
|
...args,
|
|
6775
6991
|
saveConfig: true
|
|
6776
6992
|
});
|
|
6777
|
-
|
|
6993
|
+
import_node_process4.default.exit(0);
|
|
6778
6994
|
}
|
|
6779
6995
|
if (args.wrap) {
|
|
6780
6996
|
return mergeSkills(await createWrapConfig({
|
|
@@ -6791,16 +7007,16 @@ async function loadConfig() {
|
|
|
6791
7007
|
throw error;
|
|
6792
7008
|
}
|
|
6793
7009
|
}
|
|
6794
|
-
if (
|
|
7010
|
+
if (import_node_process4.default.env.MCPC_CONFIG) {
|
|
6795
7011
|
try {
|
|
6796
|
-
const parsed = JSON.parse(
|
|
7012
|
+
const parsed = JSON.parse(import_node_process4.default.env.MCPC_CONFIG);
|
|
6797
7013
|
return mergeSkills(applyModeOverride(normalizeConfig(parsed), args.mode));
|
|
6798
7014
|
} catch (error) {
|
|
6799
7015
|
console.error("Failed to parse MCPC_CONFIG environment variable:", error);
|
|
6800
7016
|
throw error;
|
|
6801
7017
|
}
|
|
6802
7018
|
}
|
|
6803
|
-
const configUrl = args.configUrl ||
|
|
7019
|
+
const configUrl = args.configUrl || import_node_process4.default.env.MCPC_CONFIG_URL;
|
|
6804
7020
|
if (configUrl) {
|
|
6805
7021
|
try {
|
|
6806
7022
|
const headers = {
|
|
@@ -6821,7 +7037,7 @@ async function loadConfig() {
|
|
|
6821
7037
|
throw error;
|
|
6822
7038
|
}
|
|
6823
7039
|
}
|
|
6824
|
-
const configFile = args.configFile ||
|
|
7040
|
+
const configFile = args.configFile || import_node_process4.default.env.MCPC_CONFIG_FILE;
|
|
6825
7041
|
if (configFile) {
|
|
6826
7042
|
try {
|
|
6827
7043
|
const config = await loadConfigFromFile(configFile);
|
|
@@ -6846,7 +7062,7 @@ async function loadConfig() {
|
|
|
6846
7062
|
throw error;
|
|
6847
7063
|
}
|
|
6848
7064
|
}
|
|
6849
|
-
const defaultJsonConfigPath = (0, import_node_path6.resolve)(
|
|
7065
|
+
const defaultJsonConfigPath = (0, import_node_path6.resolve)(import_node_process4.default.cwd(), "mcpc.config.json");
|
|
6850
7066
|
try {
|
|
6851
7067
|
const config = await loadConfigFromFile(defaultJsonConfigPath);
|
|
6852
7068
|
return mergeSkills(applyModeOverride(config, args.mode));
|
|
@@ -6861,7 +7077,7 @@ async function loadConfig() {
|
|
|
6861
7077
|
}
|
|
6862
7078
|
function replaceEnvVars2(str2) {
|
|
6863
7079
|
return str2.replace(/\$([A-Z_][A-Z0-9_]*)/g, (_match, varName) => {
|
|
6864
|
-
return
|
|
7080
|
+
return import_node_process4.default.env[varName] || "";
|
|
6865
7081
|
});
|
|
6866
7082
|
}
|
|
6867
7083
|
function isMarkdownFile2(path) {
|
|
@@ -8152,6 +8368,147 @@ var ExperimentalServerTasks = class {
|
|
|
8152
8368
|
requestStream(request, resultSchema, options) {
|
|
8153
8369
|
return this._server.requestStream(request, resultSchema, options);
|
|
8154
8370
|
}
|
|
8371
|
+
/**
|
|
8372
|
+
* Sends a sampling request and returns an AsyncGenerator that yields response messages.
|
|
8373
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
8374
|
+
*
|
|
8375
|
+
* For task-augmented requests, yields 'taskCreated' and 'taskStatus' messages
|
|
8376
|
+
* before the final result.
|
|
8377
|
+
*
|
|
8378
|
+
* @example
|
|
8379
|
+
* ```typescript
|
|
8380
|
+
* const stream = server.experimental.tasks.createMessageStream({
|
|
8381
|
+
* messages: [{ role: 'user', content: { type: 'text', text: 'Hello' } }],
|
|
8382
|
+
* maxTokens: 100
|
|
8383
|
+
* }, {
|
|
8384
|
+
* onprogress: (progress) => {
|
|
8385
|
+
* // Handle streaming tokens via progress notifications
|
|
8386
|
+
* console.log('Progress:', progress.message);
|
|
8387
|
+
* }
|
|
8388
|
+
* });
|
|
8389
|
+
*
|
|
8390
|
+
* for await (const message of stream) {
|
|
8391
|
+
* switch (message.type) {
|
|
8392
|
+
* case 'taskCreated':
|
|
8393
|
+
* console.log('Task created:', message.task.taskId);
|
|
8394
|
+
* break;
|
|
8395
|
+
* case 'taskStatus':
|
|
8396
|
+
* console.log('Task status:', message.task.status);
|
|
8397
|
+
* break;
|
|
8398
|
+
* case 'result':
|
|
8399
|
+
* console.log('Final result:', message.result);
|
|
8400
|
+
* break;
|
|
8401
|
+
* case 'error':
|
|
8402
|
+
* console.error('Error:', message.error);
|
|
8403
|
+
* break;
|
|
8404
|
+
* }
|
|
8405
|
+
* }
|
|
8406
|
+
* ```
|
|
8407
|
+
*
|
|
8408
|
+
* @param params - The sampling request parameters
|
|
8409
|
+
* @param options - Optional request options (timeout, signal, task creation params, onprogress, etc.)
|
|
8410
|
+
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
8411
|
+
*
|
|
8412
|
+
* @experimental
|
|
8413
|
+
*/
|
|
8414
|
+
createMessageStream(params, options) {
|
|
8415
|
+
const clientCapabilities = this._server.getClientCapabilities();
|
|
8416
|
+
if ((params.tools || params.toolChoice) && !clientCapabilities?.sampling?.tools) {
|
|
8417
|
+
throw new Error("Client does not support sampling tools capability.");
|
|
8418
|
+
}
|
|
8419
|
+
if (params.messages.length > 0) {
|
|
8420
|
+
const lastMessage = params.messages[params.messages.length - 1];
|
|
8421
|
+
const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];
|
|
8422
|
+
const hasToolResults = lastContent.some((c) => c.type === "tool_result");
|
|
8423
|
+
const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : void 0;
|
|
8424
|
+
const previousContent = previousMessage ? Array.isArray(previousMessage.content) ? previousMessage.content : [previousMessage.content] : [];
|
|
8425
|
+
const hasPreviousToolUse = previousContent.some((c) => c.type === "tool_use");
|
|
8426
|
+
if (hasToolResults) {
|
|
8427
|
+
if (lastContent.some((c) => c.type !== "tool_result")) {
|
|
8428
|
+
throw new Error("The last message must contain only tool_result content if any is present");
|
|
8429
|
+
}
|
|
8430
|
+
if (!hasPreviousToolUse) {
|
|
8431
|
+
throw new Error("tool_result blocks are not matching any tool_use from the previous message");
|
|
8432
|
+
}
|
|
8433
|
+
}
|
|
8434
|
+
if (hasPreviousToolUse) {
|
|
8435
|
+
const toolUseIds = new Set(previousContent.filter((c) => c.type === "tool_use").map((c) => c.id));
|
|
8436
|
+
const toolResultIds = new Set(lastContent.filter((c) => c.type === "tool_result").map((c) => c.toolUseId));
|
|
8437
|
+
if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((id) => toolResultIds.has(id))) {
|
|
8438
|
+
throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match");
|
|
8439
|
+
}
|
|
8440
|
+
}
|
|
8441
|
+
}
|
|
8442
|
+
return this.requestStream({
|
|
8443
|
+
method: "sampling/createMessage",
|
|
8444
|
+
params
|
|
8445
|
+
}, CreateMessageResultSchema, options);
|
|
8446
|
+
}
|
|
8447
|
+
/**
|
|
8448
|
+
* Sends an elicitation request and returns an AsyncGenerator that yields response messages.
|
|
8449
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
8450
|
+
*
|
|
8451
|
+
* For task-augmented requests (especially URL-based elicitation), yields 'taskCreated'
|
|
8452
|
+
* and 'taskStatus' messages before the final result.
|
|
8453
|
+
*
|
|
8454
|
+
* @example
|
|
8455
|
+
* ```typescript
|
|
8456
|
+
* const stream = server.experimental.tasks.elicitInputStream({
|
|
8457
|
+
* mode: 'url',
|
|
8458
|
+
* message: 'Please authenticate',
|
|
8459
|
+
* elicitationId: 'auth-123',
|
|
8460
|
+
* url: 'https://example.com/auth'
|
|
8461
|
+
* }, {
|
|
8462
|
+
* task: { ttl: 300000 } // Task-augmented for long-running auth flow
|
|
8463
|
+
* });
|
|
8464
|
+
*
|
|
8465
|
+
* for await (const message of stream) {
|
|
8466
|
+
* switch (message.type) {
|
|
8467
|
+
* case 'taskCreated':
|
|
8468
|
+
* console.log('Task created:', message.task.taskId);
|
|
8469
|
+
* break;
|
|
8470
|
+
* case 'taskStatus':
|
|
8471
|
+
* console.log('Task status:', message.task.status);
|
|
8472
|
+
* break;
|
|
8473
|
+
* case 'result':
|
|
8474
|
+
* console.log('User action:', message.result.action);
|
|
8475
|
+
* break;
|
|
8476
|
+
* case 'error':
|
|
8477
|
+
* console.error('Error:', message.error);
|
|
8478
|
+
* break;
|
|
8479
|
+
* }
|
|
8480
|
+
* }
|
|
8481
|
+
* ```
|
|
8482
|
+
*
|
|
8483
|
+
* @param params - The elicitation request parameters
|
|
8484
|
+
* @param options - Optional request options (timeout, signal, task creation params, etc.)
|
|
8485
|
+
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
8486
|
+
*
|
|
8487
|
+
* @experimental
|
|
8488
|
+
*/
|
|
8489
|
+
elicitInputStream(params, options) {
|
|
8490
|
+
const clientCapabilities = this._server.getClientCapabilities();
|
|
8491
|
+
const mode = params.mode ?? "form";
|
|
8492
|
+
switch (mode) {
|
|
8493
|
+
case "url": {
|
|
8494
|
+
if (!clientCapabilities?.elicitation?.url) {
|
|
8495
|
+
throw new Error("Client does not support url elicitation.");
|
|
8496
|
+
}
|
|
8497
|
+
break;
|
|
8498
|
+
}
|
|
8499
|
+
case "form": {
|
|
8500
|
+
if (!clientCapabilities?.elicitation?.form) {
|
|
8501
|
+
throw new Error("Client does not support form elicitation.");
|
|
8502
|
+
}
|
|
8503
|
+
break;
|
|
8504
|
+
}
|
|
8505
|
+
}
|
|
8506
|
+
const normalizedParams = mode === "form" && params.mode === void 0 ? { ...params, mode: "form" } : params;
|
|
8507
|
+
return this.requestStream({
|
|
8508
|
+
method: "elicitation/create",
|
|
8509
|
+
params: normalizedParams
|
|
8510
|
+
}, ElicitResultSchema, options);
|
|
8511
|
+
}
|
|
8155
8512
|
/**
|
|
8156
8513
|
* Gets the current status of a task.
|
|
8157
8514
|
*
|
|
@@ -9351,7 +9708,7 @@ var Client = class extends Protocol {
|
|
|
9351
9708
|
|
|
9352
9709
|
// __mcpc__cli_latest/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js
|
|
9353
9710
|
var import_cross_spawn = __toESM(require_cross_spawn(), 1);
|
|
9354
|
-
var
|
|
9711
|
+
var import_node_process5 = __toESM(require("node:process"), 1);
|
|
9355
9712
|
var import_node_stream = require("node:stream");
|
|
9356
9713
|
|
|
9357
9714
|
// __mcpc__cli_latest/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
|
|
@@ -9383,7 +9740,7 @@ function serializeMessage(message) {
|
|
|
9383
9740
|
}
|
|
9384
9741
|
|
|
9385
9742
|
// __mcpc__cli_latest/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js
|
|
9386
|
-
var DEFAULT_INHERITED_ENV_VARS =
|
|
9743
|
+
var DEFAULT_INHERITED_ENV_VARS = import_node_process5.default.platform === "win32" ? [
|
|
9387
9744
|
"APPDATA",
|
|
9388
9745
|
"HOMEDRIVE",
|
|
9389
9746
|
"HOMEPATH",
|
|
@@ -9403,7 +9760,7 @@ var DEFAULT_INHERITED_ENV_VARS = import_node_process4.default.platform === "win3
|
|
|
9403
9760
|
function getDefaultEnvironment() {
|
|
9404
9761
|
const env = {};
|
|
9405
9762
|
for (const key of DEFAULT_INHERITED_ENV_VARS) {
|
|
9406
|
-
const value =
|
|
9763
|
+
const value = import_node_process5.default.env[key];
|
|
9407
9764
|
if (value === void 0) {
|
|
9408
9765
|
continue;
|
|
9409
9766
|
}
|
|
@@ -9439,7 +9796,7 @@ var StdioClientTransport = class {
|
|
|
9439
9796
|
},
|
|
9440
9797
|
stdio: ["pipe", "pipe", this._serverParams.stderr ?? "inherit"],
|
|
9441
9798
|
shell: false,
|
|
9442
|
-
windowsHide:
|
|
9799
|
+
windowsHide: import_node_process5.default.platform === "win32" && isElectron(),
|
|
9443
9800
|
cwd: this._serverParams.cwd
|
|
9444
9801
|
});
|
|
9445
9802
|
this._process.on("error", (error) => {
|
|
@@ -9547,7 +9904,7 @@ var StdioClientTransport = class {
|
|
|
9547
9904
|
}
|
|
9548
9905
|
};
|
|
9549
9906
|
function isElectron() {
|
|
9550
|
-
return "type" in
|
|
9907
|
+
return "type" in import_node_process5.default;
|
|
9551
9908
|
}
|
|
9552
9909
|
|
|
9553
9910
|
// __mcpc__cli_latest/node_modules/eventsource-parser/dist/index.js
|
|
@@ -10370,22 +10727,45 @@ async function auth(provider, options) {
|
|
|
10370
10727
|
}
|
|
10371
10728
|
}
|
|
10372
10729
|
async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
|
|
10730
|
+
const cachedState = await provider.discoveryState?.();
|
|
10373
10731
|
let resourceMetadata;
|
|
10374
10732
|
let authorizationServerUrl;
|
|
10375
|
-
|
|
10376
|
-
|
|
10377
|
-
|
|
10378
|
-
|
|
10733
|
+
let metadata;
|
|
10734
|
+
let effectiveResourceMetadataUrl = resourceMetadataUrl;
|
|
10735
|
+
if (!effectiveResourceMetadataUrl && cachedState?.resourceMetadataUrl) {
|
|
10736
|
+
effectiveResourceMetadataUrl = new URL(cachedState.resourceMetadataUrl);
|
|
10737
|
+
}
|
|
10738
|
+
if (cachedState?.authorizationServerUrl) {
|
|
10739
|
+
authorizationServerUrl = cachedState.authorizationServerUrl;
|
|
10740
|
+
resourceMetadata = cachedState.resourceMetadata;
|
|
10741
|
+
metadata = cachedState.authorizationServerMetadata ?? await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn });
|
|
10742
|
+
if (!resourceMetadata) {
|
|
10743
|
+
try {
|
|
10744
|
+
resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl }, fetchFn);
|
|
10745
|
+
} catch {
|
|
10746
|
+
}
|
|
10379
10747
|
}
|
|
10380
|
-
|
|
10381
|
-
|
|
10382
|
-
|
|
10383
|
-
|
|
10748
|
+
if (metadata !== cachedState.authorizationServerMetadata || resourceMetadata !== cachedState.resourceMetadata) {
|
|
10749
|
+
await provider.saveDiscoveryState?.({
|
|
10750
|
+
authorizationServerUrl: String(authorizationServerUrl),
|
|
10751
|
+
resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
|
|
10752
|
+
resourceMetadata,
|
|
10753
|
+
authorizationServerMetadata: metadata
|
|
10754
|
+
});
|
|
10755
|
+
}
|
|
10756
|
+
} else {
|
|
10757
|
+
const serverInfo = await discoverOAuthServerInfo(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl, fetchFn });
|
|
10758
|
+
authorizationServerUrl = serverInfo.authorizationServerUrl;
|
|
10759
|
+
metadata = serverInfo.authorizationServerMetadata;
|
|
10760
|
+
resourceMetadata = serverInfo.resourceMetadata;
|
|
10761
|
+
await provider.saveDiscoveryState?.({
|
|
10762
|
+
authorizationServerUrl: String(authorizationServerUrl),
|
|
10763
|
+
resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
|
|
10764
|
+
resourceMetadata,
|
|
10765
|
+
authorizationServerMetadata: metadata
|
|
10766
|
+
});
|
|
10384
10767
|
}
|
|
10385
10768
|
const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
|
|
10386
|
-
const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, {
|
|
10387
|
-
fetchFn
|
|
10388
|
-
});
|
|
10389
10769
|
let clientInformation = await Promise.resolve(provider.clientInformation());
|
|
10390
10770
|
if (!clientInformation) {
|
|
10391
10771
|
if (authorizationCode !== void 0) {
|
|
@@ -10640,6 +11020,26 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
|
|
|
10640
11020
|
}
|
|
10641
11021
|
return void 0;
|
|
10642
11022
|
}
|
|
11023
|
+
async function discoverOAuthServerInfo(serverUrl, opts) {
|
|
11024
|
+
let resourceMetadata;
|
|
11025
|
+
let authorizationServerUrl;
|
|
11026
|
+
try {
|
|
11027
|
+
resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: opts?.resourceMetadataUrl }, opts?.fetchFn);
|
|
11028
|
+
if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
|
|
11029
|
+
authorizationServerUrl = resourceMetadata.authorization_servers[0];
|
|
11030
|
+
}
|
|
11031
|
+
} catch {
|
|
11032
|
+
}
|
|
11033
|
+
if (!authorizationServerUrl) {
|
|
11034
|
+
authorizationServerUrl = String(new URL("/", serverUrl));
|
|
11035
|
+
}
|
|
11036
|
+
const authorizationServerMetadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn: opts?.fetchFn });
|
|
11037
|
+
return {
|
|
11038
|
+
authorizationServerUrl,
|
|
11039
|
+
authorizationServerMetadata,
|
|
11040
|
+
resourceMetadata
|
|
11041
|
+
};
|
|
11042
|
+
}
|
|
10643
11043
|
async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
|
|
10644
11044
|
let authorizationUrl;
|
|
10645
11045
|
if (metadata) {
|
|
@@ -11428,8 +11828,8 @@ var InMemoryTransport = class _InMemoryTransport {
|
|
|
11428
11828
|
};
|
|
11429
11829
|
|
|
11430
11830
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/utils/common/config.js
|
|
11431
|
-
var
|
|
11432
|
-
var GEMINI_PREFERRED_FORMAT =
|
|
11831
|
+
var import_node_process6 = __toESM(require("node:process"), 1);
|
|
11832
|
+
var GEMINI_PREFERRED_FORMAT = import_node_process6.default.env.GEMINI_PREFERRED_FORMAT === "0" ? false : true;
|
|
11433
11833
|
|
|
11434
11834
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/utils/common/json.js
|
|
11435
11835
|
var import_jsonrepair2 = require("jsonrepair");
|
|
@@ -11501,21 +11901,9 @@ var cleanToolSchema = (schema) => {
|
|
|
11501
11901
|
};
|
|
11502
11902
|
|
|
11503
11903
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/utils/common/mcp.js
|
|
11504
|
-
var
|
|
11505
|
-
var
|
|
11904
|
+
var import_node_process7 = require("node:process");
|
|
11905
|
+
var import_node_process8 = __toESM(require("node:process"), 1);
|
|
11506
11906
|
var import_node_crypto = require("node:crypto");
|
|
11507
|
-
var mcpClientPool = /* @__PURE__ */ new Map();
|
|
11508
|
-
var mcpClientConnecting = /* @__PURE__ */ new Map();
|
|
11509
|
-
var shortHash = (s) => (0, import_node_crypto.createHash)("sha256").update(s).digest("hex").slice(0, 8);
|
|
11510
|
-
function defSignature(def) {
|
|
11511
|
-
const defCopy = {
|
|
11512
|
-
...def
|
|
11513
|
-
};
|
|
11514
|
-
if (defCopy.transportType === "memory" || defCopy.transport) {
|
|
11515
|
-
return `memory:${Date.now()}:${Math.random()}`;
|
|
11516
|
-
}
|
|
11517
|
-
return JSON.stringify(defCopy);
|
|
11518
|
-
}
|
|
11519
11907
|
function createTransport(def) {
|
|
11520
11908
|
const defAny = def;
|
|
11521
11909
|
const explicitType = defAny.transportType || defAny.type;
|
|
@@ -11555,98 +11943,51 @@ function createTransport(def) {
|
|
|
11555
11943
|
command: defAny.command,
|
|
11556
11944
|
args: defAny.args,
|
|
11557
11945
|
env: {
|
|
11558
|
-
...
|
|
11946
|
+
...import_node_process8.default.env,
|
|
11559
11947
|
...defAny.env ?? {}
|
|
11560
11948
|
},
|
|
11561
|
-
cwd: (0,
|
|
11949
|
+
cwd: (0, import_node_process7.cwd)()
|
|
11562
11950
|
});
|
|
11563
11951
|
}
|
|
11564
11952
|
throw new Error(`Unsupported transport configuration: ${JSON.stringify(def)}`);
|
|
11565
11953
|
}
|
|
11566
|
-
|
|
11567
|
-
const
|
|
11568
|
-
|
|
11569
|
-
|
|
11570
|
-
|
|
11571
|
-
|
|
11572
|
-
const existingConnecting = mcpClientConnecting.get(defKey);
|
|
11573
|
-
if (existingConnecting) {
|
|
11574
|
-
const client = await existingConnecting;
|
|
11575
|
-
const entry = mcpClientPool.get(defKey);
|
|
11576
|
-
if (entry) entry.refCount += 1;
|
|
11577
|
-
return client;
|
|
11578
|
-
}
|
|
11579
|
-
const transport = createTransport(def);
|
|
11580
|
-
const connecting = (async () => {
|
|
11581
|
-
const client = new Client({
|
|
11582
|
-
name: `mcp_${shortHash(defSignature(def))}`,
|
|
11583
|
-
version: "1.0.0"
|
|
11584
|
-
});
|
|
11585
|
-
await client.connect(transport, {
|
|
11586
|
-
timeout: 6e4 * 10
|
|
11587
|
-
});
|
|
11588
|
-
return client;
|
|
11589
|
-
})();
|
|
11590
|
-
mcpClientConnecting.set(defKey, connecting);
|
|
11591
|
-
try {
|
|
11592
|
-
const client = await connecting;
|
|
11593
|
-
mcpClientPool.set(defKey, {
|
|
11594
|
-
client,
|
|
11595
|
-
refCount: 1
|
|
11596
|
-
});
|
|
11597
|
-
return client;
|
|
11598
|
-
} finally {
|
|
11599
|
-
mcpClientConnecting.delete(defKey);
|
|
11954
|
+
function defSignature(def) {
|
|
11955
|
+
const defCopy = {
|
|
11956
|
+
...def
|
|
11957
|
+
};
|
|
11958
|
+
if (defCopy.transportType === "memory" || defCopy.transport) {
|
|
11959
|
+
return `memory:${Date.now()}:${Math.random()}`;
|
|
11600
11960
|
}
|
|
11961
|
+
return JSON.stringify(defCopy);
|
|
11601
11962
|
}
|
|
11602
|
-
|
|
11603
|
-
|
|
11604
|
-
|
|
11605
|
-
|
|
11606
|
-
|
|
11607
|
-
|
|
11608
|
-
|
|
11609
|
-
|
|
11610
|
-
|
|
11611
|
-
|
|
11612
|
-
|
|
11613
|
-
}
|
|
11963
|
+
var shortHash = (s) => (0, import_node_crypto.createHash)("sha256").update(s).digest("hex").slice(0, 8);
|
|
11964
|
+
async function createMcpClient(def) {
|
|
11965
|
+
const transport = createTransport(def);
|
|
11966
|
+
const client = new Client({
|
|
11967
|
+
name: `mcp_${shortHash(defSignature(def))}`,
|
|
11968
|
+
version: "1.0.0"
|
|
11969
|
+
});
|
|
11970
|
+
await client.connect(transport, {
|
|
11971
|
+
timeout: 6e4 * 10
|
|
11972
|
+
});
|
|
11973
|
+
return client;
|
|
11614
11974
|
}
|
|
11615
|
-
var cleanupAllPooledClients = async () => {
|
|
11616
|
-
const entries = Array.from(mcpClientPool.entries());
|
|
11617
|
-
mcpClientPool.clear();
|
|
11618
|
-
await Promise.all(entries.map(async ([, { client }]) => {
|
|
11619
|
-
try {
|
|
11620
|
-
await client.close();
|
|
11621
|
-
} catch (err) {
|
|
11622
|
-
console.error("Error closing MCP client:", err);
|
|
11623
|
-
}
|
|
11624
|
-
}));
|
|
11625
|
-
};
|
|
11626
|
-
import_node_process7.default.once?.("exit", () => {
|
|
11627
|
-
cleanupAllPooledClients();
|
|
11628
|
-
});
|
|
11629
|
-
import_node_process7.default.once?.("SIGINT", () => {
|
|
11630
|
-
cleanupAllPooledClients().finally(() => import_node_process7.default.exit(0));
|
|
11631
|
-
});
|
|
11632
11975
|
async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
11633
11976
|
const allTools = {};
|
|
11634
11977
|
const allClients = {};
|
|
11635
|
-
const
|
|
11978
|
+
const clientsToClose = [];
|
|
11636
11979
|
for (const [name, definition] of Object.entries(mcpConfig.mcpServers)) {
|
|
11637
11980
|
const def = definition;
|
|
11638
11981
|
if (def.disabled) continue;
|
|
11639
|
-
const defKey = shortHash(defSignature(def));
|
|
11640
|
-
const serverId = name;
|
|
11641
11982
|
try {
|
|
11642
|
-
const client = await
|
|
11643
|
-
|
|
11644
|
-
allClients[
|
|
11983
|
+
const client = await createMcpClient(def);
|
|
11984
|
+
clientsToClose.push(client);
|
|
11985
|
+
allClients[name] = client;
|
|
11645
11986
|
const { tools } = await client.listTools();
|
|
11646
11987
|
tools.forEach((tool2) => {
|
|
11647
11988
|
const toolNameWithScope = `${name}.${tool2.name}`;
|
|
11648
11989
|
const internalToolName = tool2.name;
|
|
11649
|
-
const rawToolId = `${
|
|
11990
|
+
const rawToolId = `${name}_${internalToolName}`;
|
|
11650
11991
|
const toolId = sanitizePropertyKey(rawToolId);
|
|
11651
11992
|
if (filterIn && !filterIn({
|
|
11652
11993
|
action: internalToolName,
|
|
@@ -11658,7 +11999,7 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
|
11658
11999
|
})) {
|
|
11659
12000
|
return;
|
|
11660
12001
|
}
|
|
11661
|
-
const execute = (args) => allClients[
|
|
12002
|
+
const execute = (args) => allClients[name].callTool({
|
|
11662
12003
|
name: internalToolName,
|
|
11663
12004
|
arguments: args
|
|
11664
12005
|
}, void 0, {
|
|
@@ -11675,10 +12016,12 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
|
11675
12016
|
}
|
|
11676
12017
|
}
|
|
11677
12018
|
const cleanupClients = async () => {
|
|
11678
|
-
await Promise.all(
|
|
11679
|
-
|
|
11680
|
-
|
|
11681
|
-
|
|
12019
|
+
await Promise.all(clientsToClose.map((client) => {
|
|
12020
|
+
try {
|
|
12021
|
+
return client.close();
|
|
12022
|
+
} catch {
|
|
12023
|
+
}
|
|
12024
|
+
}));
|
|
11682
12025
|
};
|
|
11683
12026
|
return {
|
|
11684
12027
|
tools: allTools,
|
|
@@ -12250,7 +12593,7 @@ function endSpan(span, error) {
|
|
|
12250
12593
|
}
|
|
12251
12594
|
|
|
12252
12595
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/executors/agentic/agentic-executor.js
|
|
12253
|
-
var
|
|
12596
|
+
var import_node_process9 = __toESM(require("node:process"), 1);
|
|
12254
12597
|
var AgenticExecutor = class {
|
|
12255
12598
|
name;
|
|
12256
12599
|
allToolNames;
|
|
@@ -12270,13 +12613,13 @@ var AgenticExecutor = class {
|
|
|
12270
12613
|
this.logger = createLogger(`mcpc.agentic.${name}`, server);
|
|
12271
12614
|
this.toolSchemaMap = new Map(toolNameToDetailList);
|
|
12272
12615
|
try {
|
|
12273
|
-
this.tracingEnabled =
|
|
12616
|
+
this.tracingEnabled = import_node_process9.default.env.MCPC_TRACING_ENABLED === "true";
|
|
12274
12617
|
if (this.tracingEnabled) {
|
|
12275
12618
|
initializeTracing({
|
|
12276
12619
|
enabled: true,
|
|
12277
12620
|
serviceName: `mcpc-agentic-${name}`,
|
|
12278
|
-
exportTo:
|
|
12279
|
-
otlpEndpoint:
|
|
12621
|
+
exportTo: import_node_process9.default.env.MCPC_TRACING_EXPORT ?? "otlp",
|
|
12622
|
+
otlpEndpoint: import_node_process9.default.env.MCPC_TRACING_OTLP_ENDPOINT ?? "http://localhost:4318/v1/traces"
|
|
12280
12623
|
});
|
|
12281
12624
|
}
|
|
12282
12625
|
} catch {
|
|
@@ -14991,12 +15334,12 @@ var ComposableMCPServer = class extends Server {
|
|
|
14991
15334
|
};
|
|
14992
15335
|
|
|
14993
15336
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/utils/common/env.js
|
|
14994
|
-
var
|
|
14995
|
-
var isSCF = () => Boolean(
|
|
15337
|
+
var import_node_process10 = __toESM(require("node:process"), 1);
|
|
15338
|
+
var isSCF = () => Boolean(import_node_process10.default.env.SCF_RUNTIME || import_node_process10.default.env.PROD_SCF);
|
|
14996
15339
|
if (isSCF()) {
|
|
14997
15340
|
console.log({
|
|
14998
15341
|
isSCF: isSCF(),
|
|
14999
|
-
SCF_RUNTIME:
|
|
15342
|
+
SCF_RUNTIME: import_node_process10.default.env.SCF_RUNTIME
|
|
15000
15343
|
});
|
|
15001
15344
|
}
|
|
15002
15345
|
|
|
@@ -15078,8 +15421,8 @@ var createApp = (config) => {
|
|
|
15078
15421
|
};
|
|
15079
15422
|
|
|
15080
15423
|
// __mcpc__cli_latest/node_modules/@mcpc/cli/src/server.ts
|
|
15081
|
-
var
|
|
15082
|
-
var port = Number(
|
|
15424
|
+
var import_node_process11 = __toESM(require("node:process"), 1);
|
|
15425
|
+
var port = Number(import_node_process11.default.env.PORT || "3002");
|
|
15083
15426
|
var hostname = "0.0.0.0";
|
|
15084
15427
|
async function main() {
|
|
15085
15428
|
const config = await loadConfig();
|