@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/index.cjs
CHANGED
|
@@ -506,7 +506,7 @@ var require_cross_spawn = __commonJS({
|
|
|
506
506
|
var cp = require("child_process");
|
|
507
507
|
var parse2 = require_parse();
|
|
508
508
|
var enoent = require_enoent();
|
|
509
|
-
function
|
|
509
|
+
function spawn3(command, args, options) {
|
|
510
510
|
const parsed = parse2(command, args, options);
|
|
511
511
|
const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
|
|
512
512
|
enoent.hookChildProcess(spawned, parsed);
|
|
@@ -518,8 +518,8 @@ var require_cross_spawn = __commonJS({
|
|
|
518
518
|
result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
|
|
519
519
|
return result;
|
|
520
520
|
}
|
|
521
|
-
module2.exports =
|
|
522
|
-
module2.exports.spawn =
|
|
521
|
+
module2.exports = spawn3;
|
|
522
|
+
module2.exports.spawn = spawn3;
|
|
523
523
|
module2.exports.sync = spawnSync;
|
|
524
524
|
module2.exports._parse = parse2;
|
|
525
525
|
module2.exports._enoent = enoent;
|
|
@@ -3037,6 +3037,7 @@ data:
|
|
|
3037
3037
|
async handleGetRequest(req) {
|
|
3038
3038
|
const acceptHeader = req.headers.get("accept");
|
|
3039
3039
|
if (!acceptHeader?.includes("text/event-stream")) {
|
|
3040
|
+
this.onerror?.(new Error("Not Acceptable: Client must accept text/event-stream"));
|
|
3040
3041
|
return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept text/event-stream");
|
|
3041
3042
|
}
|
|
3042
3043
|
const sessionError = this.validateSession(req);
|
|
@@ -3054,6 +3055,7 @@ data:
|
|
|
3054
3055
|
}
|
|
3055
3056
|
}
|
|
3056
3057
|
if (this._streamMapping.get(this._standaloneSseStreamId) !== void 0) {
|
|
3058
|
+
this.onerror?.(new Error("Conflict: Only one SSE stream is allowed per session"));
|
|
3057
3059
|
return this.createJsonErrorResponse(409, -32e3, "Conflict: Only one SSE stream is allowed per session");
|
|
3058
3060
|
}
|
|
3059
3061
|
const encoder2 = new TextEncoder();
|
|
@@ -3093,6 +3095,7 @@ data:
|
|
|
3093
3095
|
*/
|
|
3094
3096
|
async replayEvents(lastEventId) {
|
|
3095
3097
|
if (!this._eventStore) {
|
|
3098
|
+
this.onerror?.(new Error("Event store not configured"));
|
|
3096
3099
|
return this.createJsonErrorResponse(400, -32e3, "Event store not configured");
|
|
3097
3100
|
}
|
|
3098
3101
|
try {
|
|
@@ -3100,9 +3103,11 @@ data:
|
|
|
3100
3103
|
if (this._eventStore.getStreamIdForEventId) {
|
|
3101
3104
|
streamId = await this._eventStore.getStreamIdForEventId(lastEventId);
|
|
3102
3105
|
if (!streamId) {
|
|
3106
|
+
this.onerror?.(new Error("Invalid event ID format"));
|
|
3103
3107
|
return this.createJsonErrorResponse(400, -32e3, "Invalid event ID format");
|
|
3104
3108
|
}
|
|
3105
3109
|
if (this._streamMapping.get(streamId) !== void 0) {
|
|
3110
|
+
this.onerror?.(new Error("Conflict: Stream already has an active connection"));
|
|
3106
3111
|
return this.createJsonErrorResponse(409, -32e3, "Conflict: Stream already has an active connection");
|
|
3107
3112
|
}
|
|
3108
3113
|
}
|
|
@@ -3168,7 +3173,8 @@ data:
|
|
|
3168
3173
|
`;
|
|
3169
3174
|
controller.enqueue(encoder2.encode(eventData));
|
|
3170
3175
|
return true;
|
|
3171
|
-
} catch {
|
|
3176
|
+
} catch (error) {
|
|
3177
|
+
this.onerror?.(error);
|
|
3172
3178
|
return false;
|
|
3173
3179
|
}
|
|
3174
3180
|
}
|
|
@@ -3176,6 +3182,7 @@ data:
|
|
|
3176
3182
|
* Handles unsupported requests (PUT, PATCH, etc.)
|
|
3177
3183
|
*/
|
|
3178
3184
|
handleUnsupportedRequest() {
|
|
3185
|
+
this.onerror?.(new Error("Method not allowed."));
|
|
3179
3186
|
return new Response(JSON.stringify({
|
|
3180
3187
|
jsonrpc: "2.0",
|
|
3181
3188
|
error: {
|
|
@@ -3198,14 +3205,17 @@ data:
|
|
|
3198
3205
|
try {
|
|
3199
3206
|
const acceptHeader = req.headers.get("accept");
|
|
3200
3207
|
if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
|
|
3208
|
+
this.onerror?.(new Error("Not Acceptable: Client must accept both application/json and text/event-stream"));
|
|
3201
3209
|
return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept both application/json and text/event-stream");
|
|
3202
3210
|
}
|
|
3203
3211
|
const ct = req.headers.get("content-type");
|
|
3204
3212
|
if (!ct || !ct.includes("application/json")) {
|
|
3213
|
+
this.onerror?.(new Error("Unsupported Media Type: Content-Type must be application/json"));
|
|
3205
3214
|
return this.createJsonErrorResponse(415, -32e3, "Unsupported Media Type: Content-Type must be application/json");
|
|
3206
3215
|
}
|
|
3207
3216
|
const requestInfo = {
|
|
3208
|
-
headers: Object.fromEntries(req.headers.entries())
|
|
3217
|
+
headers: Object.fromEntries(req.headers.entries()),
|
|
3218
|
+
url: new URL(req.url)
|
|
3209
3219
|
};
|
|
3210
3220
|
let rawMessage;
|
|
3211
3221
|
if (options?.parsedBody !== void 0) {
|
|
@@ -3214,6 +3224,7 @@ data:
|
|
|
3214
3224
|
try {
|
|
3215
3225
|
rawMessage = await req.json();
|
|
3216
3226
|
} catch {
|
|
3227
|
+
this.onerror?.(new Error("Parse error: Invalid JSON"));
|
|
3217
3228
|
return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON");
|
|
3218
3229
|
}
|
|
3219
3230
|
}
|
|
@@ -3225,14 +3236,17 @@ data:
|
|
|
3225
3236
|
messages = [JSONRPCMessageSchema.parse(rawMessage)];
|
|
3226
3237
|
}
|
|
3227
3238
|
} catch {
|
|
3239
|
+
this.onerror?.(new Error("Parse error: Invalid JSON-RPC message"));
|
|
3228
3240
|
return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON-RPC message");
|
|
3229
3241
|
}
|
|
3230
3242
|
const isInitializationRequest = messages.some(isInitializeRequest);
|
|
3231
3243
|
if (isInitializationRequest) {
|
|
3232
3244
|
if (this._initialized && this.sessionId !== void 0) {
|
|
3245
|
+
this.onerror?.(new Error("Invalid Request: Server already initialized"));
|
|
3233
3246
|
return this.createJsonErrorResponse(400, -32600, "Invalid Request: Server already initialized");
|
|
3234
3247
|
}
|
|
3235
3248
|
if (messages.length > 1) {
|
|
3249
|
+
this.onerror?.(new Error("Invalid Request: Only one initialization request is allowed"));
|
|
3236
3250
|
return this.createJsonErrorResponse(400, -32600, "Invalid Request: Only one initialization request is allowed");
|
|
3237
3251
|
}
|
|
3238
3252
|
this.sessionId = this.sessionIdGenerator?.();
|
|
@@ -3358,13 +3372,16 @@ data:
|
|
|
3358
3372
|
return void 0;
|
|
3359
3373
|
}
|
|
3360
3374
|
if (!this._initialized) {
|
|
3375
|
+
this.onerror?.(new Error("Bad Request: Server not initialized"));
|
|
3361
3376
|
return this.createJsonErrorResponse(400, -32e3, "Bad Request: Server not initialized");
|
|
3362
3377
|
}
|
|
3363
3378
|
const sessionId = req.headers.get("mcp-session-id");
|
|
3364
3379
|
if (!sessionId) {
|
|
3380
|
+
this.onerror?.(new Error("Bad Request: Mcp-Session-Id header is required"));
|
|
3365
3381
|
return this.createJsonErrorResponse(400, -32e3, "Bad Request: Mcp-Session-Id header is required");
|
|
3366
3382
|
}
|
|
3367
3383
|
if (sessionId !== this.sessionId) {
|
|
3384
|
+
this.onerror?.(new Error("Session not found"));
|
|
3368
3385
|
return this.createJsonErrorResponse(404, -32001, "Session not found");
|
|
3369
3386
|
}
|
|
3370
3387
|
return void 0;
|
|
@@ -3385,6 +3402,7 @@ data:
|
|
|
3385
3402
|
validateProtocolVersion(req) {
|
|
3386
3403
|
const protocolVersion = req.headers.get("mcp-protocol-version");
|
|
3387
3404
|
if (protocolVersion !== null && !SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) {
|
|
3405
|
+
this.onerror?.(new Error(`Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`));
|
|
3388
3406
|
return this.createJsonErrorResponse(400, -32e3, `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`);
|
|
3389
3407
|
}
|
|
3390
3408
|
return void 0;
|
|
@@ -3591,7 +3609,7 @@ var StreamableHTTPServerTransport = class {
|
|
|
3591
3609
|
};
|
|
3592
3610
|
|
|
3593
3611
|
// __mcpc__cli_latest/node_modules/@jsr/std__cli/parse_args.js
|
|
3594
|
-
var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value
|
|
3612
|
+
var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.*))?$/s;
|
|
3595
3613
|
var LETTER_REGEXP = /[A-Za-z]/;
|
|
3596
3614
|
var NUMBER_REGEXP = /-?\d+(\.\d*)?(e-?\d+)?$/;
|
|
3597
3615
|
var HYPHEN_REGEXP = /^(-|--)[^-]/;
|
|
@@ -3602,12 +3620,19 @@ var NON_WHITESPACE_REGEXP = /\S/;
|
|
|
3602
3620
|
function isNumber(string3) {
|
|
3603
3621
|
return NON_WHITESPACE_REGEXP.test(string3) && Number.isFinite(Number(string3));
|
|
3604
3622
|
}
|
|
3623
|
+
function isConstructorOrProto(obj, key) {
|
|
3624
|
+
return key === "constructor" && typeof obj[key] === "function" || key === "__proto__";
|
|
3625
|
+
}
|
|
3605
3626
|
function setNested(object5, keys, value, collect = false) {
|
|
3606
3627
|
keys = [
|
|
3607
3628
|
...keys
|
|
3608
3629
|
];
|
|
3609
3630
|
const key = keys.pop();
|
|
3610
|
-
|
|
3631
|
+
for (const k of keys) {
|
|
3632
|
+
if (isConstructorOrProto(object5, k)) return;
|
|
3633
|
+
object5 = object5[k] ??= {};
|
|
3634
|
+
}
|
|
3635
|
+
if (isConstructorOrProto(object5, key)) return;
|
|
3611
3636
|
if (collect) {
|
|
3612
3637
|
const v = object5[key];
|
|
3613
3638
|
if (Array.isArray(v)) {
|
|
@@ -3738,7 +3763,7 @@ function parseArgs(args, options) {
|
|
|
3738
3763
|
let key = groups.key;
|
|
3739
3764
|
let value = groups.value;
|
|
3740
3765
|
if (doubleDash2) {
|
|
3741
|
-
if (value) {
|
|
3766
|
+
if (value != null) {
|
|
3742
3767
|
if (booleanSet.has(key)) value = parseBooleanString(value);
|
|
3743
3768
|
setArgument(key, value, arg, true);
|
|
3744
3769
|
continue;
|
|
@@ -3776,6 +3801,10 @@ function parseArgs(args, options) {
|
|
|
3776
3801
|
setArgument(letter, next, arg, true);
|
|
3777
3802
|
continue;
|
|
3778
3803
|
}
|
|
3804
|
+
if (next === "=") {
|
|
3805
|
+
setArgument(letter, "", arg, true);
|
|
3806
|
+
continue argsLoop;
|
|
3807
|
+
}
|
|
3779
3808
|
if (LETTER_REGEXP.test(letter)) {
|
|
3780
3809
|
const groups2 = VALUE_REGEXP.exec(next)?.groups;
|
|
3781
3810
|
if (groups2) {
|
|
@@ -3852,7 +3881,7 @@ function parseArgs(args, options) {
|
|
|
3852
3881
|
var import_promises4 = require("node:fs/promises");
|
|
3853
3882
|
var import_node_os3 = require("node:os");
|
|
3854
3883
|
var import_node_path6 = require("node:path");
|
|
3855
|
-
var
|
|
3884
|
+
var import_node_process4 = __toESM(require("node:process"), 1);
|
|
3856
3885
|
|
|
3857
3886
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/plugins/large-result.js
|
|
3858
3887
|
var import_promises = require("node:fs/promises");
|
|
@@ -4270,7 +4299,7 @@ Usage:
|
|
|
4270
4299
|
- ${toolName}({ skill: "skill-name" }) - Load main SKILL.md content
|
|
4271
4300
|
- ${toolName}({ skill: "skill-name", ref: "path/to/file" }) - Load reference file
|
|
4272
4301
|
|
|
4273
|
-
Note: For scripts
|
|
4302
|
+
Note: For scripts/, use the bash tool with the script path to execute.`;
|
|
4274
4303
|
}
|
|
4275
4304
|
function createSkillsPlugin(options) {
|
|
4276
4305
|
const { paths } = options;
|
|
@@ -4378,11 +4407,15 @@ Available skills: ${available.join(", ")}` : "\n\nNo skills available.";
|
|
|
4378
4407
|
try {
|
|
4379
4408
|
const content = await (0, import_promises2.readFile)((0, import_node_path4.join)(meta.basePath, "SKILL.md"), "utf-8");
|
|
4380
4409
|
const body = extractBody(content);
|
|
4410
|
+
const skillPathInfo = `
|
|
4411
|
+
---
|
|
4412
|
+
Skill path: ${meta.basePath}
|
|
4413
|
+
`;
|
|
4381
4414
|
return {
|
|
4382
4415
|
content: [
|
|
4383
4416
|
{
|
|
4384
4417
|
type: "text",
|
|
4385
|
-
text: body
|
|
4418
|
+
text: body + skillPathInfo
|
|
4386
4419
|
}
|
|
4387
4420
|
]
|
|
4388
4421
|
};
|
|
@@ -4409,6 +4442,152 @@ Available skills: ${available.join(", ")}` : "\n\nNo skills available.";
|
|
|
4409
4442
|
};
|
|
4410
4443
|
}
|
|
4411
4444
|
|
|
4445
|
+
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/plugins/bash.js
|
|
4446
|
+
var import_node_child_process = require("node:child_process");
|
|
4447
|
+
var import_node_process = __toESM(require("node:process"), 1);
|
|
4448
|
+
var DEFAULT_MAX_BYTES = 1e5;
|
|
4449
|
+
var DEFAULT_MAX_LINES = 2e3;
|
|
4450
|
+
var DEFAULT_TIMEOUT_MS = 6e4;
|
|
4451
|
+
function truncateOutput(stdout, stderr, maxBytes = DEFAULT_MAX_BYTES, maxLines = DEFAULT_MAX_LINES) {
|
|
4452
|
+
const fullOutput = (stderr ? `STDERR:
|
|
4453
|
+
${stderr}
|
|
4454
|
+
|
|
4455
|
+
STDOUT:
|
|
4456
|
+
` : "") + stdout;
|
|
4457
|
+
const lines = fullOutput.split("\n");
|
|
4458
|
+
if (lines.length > maxLines) {
|
|
4459
|
+
const truncatedLines = lines.slice(-maxLines);
|
|
4460
|
+
return {
|
|
4461
|
+
output: `[OUTPUT TRUNCATED] Showing last ${maxLines} lines of ${lines.length} total
|
|
4462
|
+
|
|
4463
|
+
` + truncatedLines.join("\n"),
|
|
4464
|
+
truncated: true
|
|
4465
|
+
};
|
|
4466
|
+
}
|
|
4467
|
+
if (fullOutput.length > maxBytes) {
|
|
4468
|
+
const truncatedBytes = fullOutput.slice(-maxBytes);
|
|
4469
|
+
return {
|
|
4470
|
+
output: `[OUTPUT TRUNCATED] Showing last ${maxBytes} bytes of ${fullOutput.length} total
|
|
4471
|
+
|
|
4472
|
+
` + truncatedBytes,
|
|
4473
|
+
truncated: true
|
|
4474
|
+
};
|
|
4475
|
+
}
|
|
4476
|
+
return {
|
|
4477
|
+
output: fullOutput,
|
|
4478
|
+
truncated: false
|
|
4479
|
+
};
|
|
4480
|
+
}
|
|
4481
|
+
function executeBash(command, cwd2, timeoutMs) {
|
|
4482
|
+
return new Promise((resolve5) => {
|
|
4483
|
+
const stdout = [];
|
|
4484
|
+
const stderr = [];
|
|
4485
|
+
const proc = (0, import_node_child_process.spawn)("bash", [
|
|
4486
|
+
"-c",
|
|
4487
|
+
command
|
|
4488
|
+
], {
|
|
4489
|
+
cwd: cwd2,
|
|
4490
|
+
stdio: [
|
|
4491
|
+
"ignore",
|
|
4492
|
+
"pipe",
|
|
4493
|
+
"pipe"
|
|
4494
|
+
]
|
|
4495
|
+
});
|
|
4496
|
+
proc.stdout?.on("data", (data) => {
|
|
4497
|
+
stdout.push(data.toString());
|
|
4498
|
+
});
|
|
4499
|
+
proc.stderr?.on("data", (data) => {
|
|
4500
|
+
stderr.push(data.toString());
|
|
4501
|
+
});
|
|
4502
|
+
proc.on("close", (code) => {
|
|
4503
|
+
resolve5({
|
|
4504
|
+
stdout: stdout.join(""),
|
|
4505
|
+
stderr: stderr.join(""),
|
|
4506
|
+
exitCode: code
|
|
4507
|
+
});
|
|
4508
|
+
});
|
|
4509
|
+
proc.on("error", (err) => {
|
|
4510
|
+
resolve5({
|
|
4511
|
+
stdout: "",
|
|
4512
|
+
stderr: err.message,
|
|
4513
|
+
exitCode: null
|
|
4514
|
+
});
|
|
4515
|
+
});
|
|
4516
|
+
setTimeout(() => {
|
|
4517
|
+
proc.kill("SIGTERM");
|
|
4518
|
+
resolve5({
|
|
4519
|
+
stdout: stdout.join(""),
|
|
4520
|
+
stderr: stderr.join("") + "\n\n[TIMEOUT] Command execution timed out",
|
|
4521
|
+
exitCode: null
|
|
4522
|
+
});
|
|
4523
|
+
}, timeoutMs);
|
|
4524
|
+
});
|
|
4525
|
+
}
|
|
4526
|
+
function createBashPlugin(options = {}) {
|
|
4527
|
+
const { maxBytes, maxLines, timeoutMs } = {
|
|
4528
|
+
maxBytes: DEFAULT_MAX_BYTES,
|
|
4529
|
+
maxLines: DEFAULT_MAX_LINES,
|
|
4530
|
+
timeoutMs: DEFAULT_TIMEOUT_MS,
|
|
4531
|
+
...options
|
|
4532
|
+
};
|
|
4533
|
+
let serverRef = null;
|
|
4534
|
+
return {
|
|
4535
|
+
name: "plugin-bash",
|
|
4536
|
+
version: "1.0.0",
|
|
4537
|
+
// Store server reference for tool registration
|
|
4538
|
+
configureServer: (server) => {
|
|
4539
|
+
serverRef = server;
|
|
4540
|
+
},
|
|
4541
|
+
// Register bash tool with agent name prefix
|
|
4542
|
+
composeStart: (context2) => {
|
|
4543
|
+
if (!serverRef) return;
|
|
4544
|
+
const agentName = context2.serverName;
|
|
4545
|
+
const toolName = `${agentName}__bash`;
|
|
4546
|
+
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.", {
|
|
4547
|
+
type: "object",
|
|
4548
|
+
properties: {
|
|
4549
|
+
command: {
|
|
4550
|
+
type: "string",
|
|
4551
|
+
description: "The bash command to execute"
|
|
4552
|
+
},
|
|
4553
|
+
cwd: {
|
|
4554
|
+
type: "string",
|
|
4555
|
+
description: "Optional: Working directory for the command (defaults to current directory)"
|
|
4556
|
+
}
|
|
4557
|
+
},
|
|
4558
|
+
required: [
|
|
4559
|
+
"command"
|
|
4560
|
+
]
|
|
4561
|
+
}, async (args) => {
|
|
4562
|
+
const cwd2 = args.cwd || import_node_process.default.cwd();
|
|
4563
|
+
const result = await executeBash(args.command, cwd2, timeoutMs);
|
|
4564
|
+
const { output, truncated } = truncateOutput(result.stdout, result.stderr, maxBytes, maxLines);
|
|
4565
|
+
let finalOutput = output;
|
|
4566
|
+
if (result.exitCode !== null && result.exitCode !== 0) {
|
|
4567
|
+
finalOutput = `[EXIT CODE: ${result.exitCode}]
|
|
4568
|
+
` + finalOutput;
|
|
4569
|
+
}
|
|
4570
|
+
if (truncated) {
|
|
4571
|
+
finalOutput += `
|
|
4572
|
+
|
|
4573
|
+
[Note: Output was truncated]`;
|
|
4574
|
+
}
|
|
4575
|
+
return {
|
|
4576
|
+
content: [
|
|
4577
|
+
{
|
|
4578
|
+
type: "text",
|
|
4579
|
+
text: finalOutput
|
|
4580
|
+
}
|
|
4581
|
+
],
|
|
4582
|
+
isError: result.exitCode !== null && result.exitCode !== 0
|
|
4583
|
+
};
|
|
4584
|
+
}, {
|
|
4585
|
+
internal: true
|
|
4586
|
+
});
|
|
4587
|
+
}
|
|
4588
|
+
};
|
|
4589
|
+
}
|
|
4590
|
+
|
|
4412
4591
|
// __mcpc__cli_latest/node_modules/@mcpc/cli/src/defaults.js
|
|
4413
4592
|
var import_plugin_code_execution = require("@mcpc-tech/plugin-code-execution");
|
|
4414
4593
|
|
|
@@ -5253,12 +5432,29 @@ function writeFoldedLines(count) {
|
|
|
5253
5432
|
if (count > 1) return "\n".repeat(count - 1);
|
|
5254
5433
|
return "";
|
|
5255
5434
|
}
|
|
5435
|
+
var Scanner = class {
|
|
5436
|
+
source;
|
|
5437
|
+
#length;
|
|
5438
|
+
position = 0;
|
|
5439
|
+
constructor(source) {
|
|
5440
|
+
source += "\0";
|
|
5441
|
+
this.source = source;
|
|
5442
|
+
this.#length = source.length;
|
|
5443
|
+
}
|
|
5444
|
+
peek(offset = 0) {
|
|
5445
|
+
return this.source.charCodeAt(this.position + offset);
|
|
5446
|
+
}
|
|
5447
|
+
next() {
|
|
5448
|
+
this.position += 1;
|
|
5449
|
+
}
|
|
5450
|
+
eof() {
|
|
5451
|
+
return this.position >= this.#length - 1;
|
|
5452
|
+
}
|
|
5453
|
+
};
|
|
5256
5454
|
var LoaderState = class {
|
|
5257
|
-
|
|
5258
|
-
length;
|
|
5455
|
+
#scanner;
|
|
5259
5456
|
lineIndent = 0;
|
|
5260
5457
|
lineStart = 0;
|
|
5261
|
-
position = 0;
|
|
5262
5458
|
line = 0;
|
|
5263
5459
|
onWarning;
|
|
5264
5460
|
allowDuplicateKeys;
|
|
@@ -5268,44 +5464,40 @@ var LoaderState = class {
|
|
|
5268
5464
|
tagMap = /* @__PURE__ */ new Map();
|
|
5269
5465
|
anchorMap = /* @__PURE__ */ new Map();
|
|
5270
5466
|
constructor(input, { schema = DEFAULT_SCHEMA, onWarning, allowDuplicateKeys = false }) {
|
|
5271
|
-
this
|
|
5467
|
+
this.#scanner = new Scanner(input);
|
|
5272
5468
|
this.onWarning = onWarning;
|
|
5273
5469
|
this.allowDuplicateKeys = allowDuplicateKeys;
|
|
5274
5470
|
this.implicitTypes = schema.implicitTypes;
|
|
5275
5471
|
this.typeMap = schema.typeMap;
|
|
5276
|
-
this.length = input.length;
|
|
5277
5472
|
this.readIndent();
|
|
5278
5473
|
}
|
|
5279
5474
|
skipWhitespaces() {
|
|
5280
|
-
let ch = this.peek();
|
|
5475
|
+
let ch = this.#scanner.peek();
|
|
5281
5476
|
while (isWhiteSpace(ch)) {
|
|
5282
|
-
|
|
5477
|
+
this.#scanner.next();
|
|
5478
|
+
ch = this.#scanner.peek();
|
|
5283
5479
|
}
|
|
5284
5480
|
}
|
|
5285
5481
|
skipComment() {
|
|
5286
|
-
let ch = this.peek();
|
|
5482
|
+
let ch = this.#scanner.peek();
|
|
5287
5483
|
if (ch !== SHARP) return;
|
|
5288
|
-
|
|
5484
|
+
this.#scanner.next();
|
|
5485
|
+
ch = this.#scanner.peek();
|
|
5289
5486
|
while (ch !== 0 && !isEOL(ch)) {
|
|
5290
|
-
|
|
5487
|
+
this.#scanner.next();
|
|
5488
|
+
ch = this.#scanner.peek();
|
|
5291
5489
|
}
|
|
5292
5490
|
}
|
|
5293
5491
|
readIndent() {
|
|
5294
|
-
let
|
|
5295
|
-
while (
|
|
5492
|
+
let ch = this.#scanner.peek();
|
|
5493
|
+
while (ch === SPACE) {
|
|
5296
5494
|
this.lineIndent += 1;
|
|
5297
|
-
|
|
5495
|
+
this.#scanner.next();
|
|
5496
|
+
ch = this.#scanner.peek();
|
|
5298
5497
|
}
|
|
5299
5498
|
}
|
|
5300
|
-
peek(offset = 0) {
|
|
5301
|
-
return this.input.charCodeAt(this.position + offset);
|
|
5302
|
-
}
|
|
5303
|
-
next() {
|
|
5304
|
-
this.position += 1;
|
|
5305
|
-
return this.peek();
|
|
5306
|
-
}
|
|
5307
5499
|
#createError(message) {
|
|
5308
|
-
const mark = markToString(this.
|
|
5500
|
+
const mark = markToString(this.#scanner.source, this.#scanner.position, this.line, this.#scanner.position - this.lineStart);
|
|
5309
5501
|
return new SyntaxError(`${message} ${mark}`);
|
|
5310
5502
|
}
|
|
5311
5503
|
dispatchWarning(message) {
|
|
@@ -5350,7 +5542,7 @@ var LoaderState = class {
|
|
|
5350
5542
|
}
|
|
5351
5543
|
captureSegment(start, end, checkJson) {
|
|
5352
5544
|
if (start < end) {
|
|
5353
|
-
const result = this.
|
|
5545
|
+
const result = this.#scanner.source.slice(start, end);
|
|
5354
5546
|
if (checkJson) {
|
|
5355
5547
|
for (let position = 0; position < result.length; position++) {
|
|
5356
5548
|
const character = result.charCodeAt(position);
|
|
@@ -5368,21 +5560,21 @@ var LoaderState = class {
|
|
|
5368
5560
|
let detected = false;
|
|
5369
5561
|
const result = [];
|
|
5370
5562
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
5371
|
-
let ch = this.peek();
|
|
5563
|
+
let ch = this.#scanner.peek();
|
|
5372
5564
|
while (ch !== 0) {
|
|
5373
5565
|
if (ch !== MINUS) {
|
|
5374
5566
|
break;
|
|
5375
5567
|
}
|
|
5376
|
-
const following = this.peek(1);
|
|
5568
|
+
const following = this.#scanner.peek(1);
|
|
5377
5569
|
if (!isWhiteSpaceOrEOL(following)) {
|
|
5378
5570
|
break;
|
|
5379
5571
|
}
|
|
5380
5572
|
detected = true;
|
|
5381
|
-
this.
|
|
5573
|
+
this.#scanner.next();
|
|
5382
5574
|
if (this.skipSeparationSpace(true, -1)) {
|
|
5383
5575
|
if (this.lineIndent <= nodeIndent) {
|
|
5384
5576
|
result.push(null);
|
|
5385
|
-
ch = this.peek();
|
|
5577
|
+
ch = this.#scanner.peek();
|
|
5386
5578
|
continue;
|
|
5387
5579
|
}
|
|
5388
5580
|
}
|
|
@@ -5395,7 +5587,7 @@ var LoaderState = class {
|
|
|
5395
5587
|
});
|
|
5396
5588
|
if (newState) result.push(newState.result);
|
|
5397
5589
|
this.skipSeparationSpace(true, -1);
|
|
5398
|
-
ch = this.peek();
|
|
5590
|
+
ch = this.#scanner.peek();
|
|
5399
5591
|
if ((this.line === line || this.lineIndent > nodeIndent) && ch !== 0) {
|
|
5400
5592
|
throw this.#createError("Cannot read block sequence: bad indentation of a sequence entry");
|
|
5401
5593
|
} else if (this.lineIndent < nodeIndent) {
|
|
@@ -5451,7 +5643,7 @@ var LoaderState = class {
|
|
|
5451
5643
|
} else {
|
|
5452
5644
|
if (!this.allowDuplicateKeys && !overridableKeys.has(keyNode) && Object.hasOwn(result, keyNode)) {
|
|
5453
5645
|
this.line = startLine || this.line;
|
|
5454
|
-
this.position = startPos || this.position;
|
|
5646
|
+
this.#scanner.position = startPos || this.#scanner.position;
|
|
5455
5647
|
throw this.#createError("Cannot store mapping pair: duplicated key");
|
|
5456
5648
|
}
|
|
5457
5649
|
Object.defineProperty(result, keyNode, {
|
|
@@ -5465,37 +5657,37 @@ var LoaderState = class {
|
|
|
5465
5657
|
return result;
|
|
5466
5658
|
}
|
|
5467
5659
|
readLineBreak() {
|
|
5468
|
-
const ch = this.peek();
|
|
5660
|
+
const ch = this.#scanner.peek();
|
|
5469
5661
|
if (ch === LINE_FEED) {
|
|
5470
|
-
this.
|
|
5662
|
+
this.#scanner.next();
|
|
5471
5663
|
} else if (ch === CARRIAGE_RETURN) {
|
|
5472
|
-
this.
|
|
5473
|
-
if (this.peek() === LINE_FEED) {
|
|
5474
|
-
this.
|
|
5664
|
+
this.#scanner.next();
|
|
5665
|
+
if (this.#scanner.peek() === LINE_FEED) {
|
|
5666
|
+
this.#scanner.next();
|
|
5475
5667
|
}
|
|
5476
5668
|
} else {
|
|
5477
5669
|
throw this.#createError("Cannot read line: line break not found");
|
|
5478
5670
|
}
|
|
5479
5671
|
this.line += 1;
|
|
5480
|
-
this.lineStart = this.position;
|
|
5672
|
+
this.lineStart = this.#scanner.position;
|
|
5481
5673
|
}
|
|
5482
5674
|
skipSeparationSpace(allowComments, checkIndent) {
|
|
5483
5675
|
let lineBreaks = 0;
|
|
5484
|
-
let ch = this.peek();
|
|
5676
|
+
let ch = this.#scanner.peek();
|
|
5485
5677
|
while (ch !== 0) {
|
|
5486
5678
|
this.skipWhitespaces();
|
|
5487
|
-
ch = this.peek();
|
|
5679
|
+
ch = this.#scanner.peek();
|
|
5488
5680
|
if (allowComments) {
|
|
5489
5681
|
this.skipComment();
|
|
5490
|
-
ch = this.peek();
|
|
5682
|
+
ch = this.#scanner.peek();
|
|
5491
5683
|
}
|
|
5492
5684
|
if (isEOL(ch)) {
|
|
5493
5685
|
this.readLineBreak();
|
|
5494
|
-
ch = this.peek();
|
|
5686
|
+
ch = this.#scanner.peek();
|
|
5495
5687
|
lineBreaks++;
|
|
5496
5688
|
this.lineIndent = 0;
|
|
5497
5689
|
this.readIndent();
|
|
5498
|
-
ch = this.peek();
|
|
5690
|
+
ch = this.#scanner.peek();
|
|
5499
5691
|
} else {
|
|
5500
5692
|
break;
|
|
5501
5693
|
}
|
|
@@ -5506,9 +5698,9 @@ var LoaderState = class {
|
|
|
5506
5698
|
return lineBreaks;
|
|
5507
5699
|
}
|
|
5508
5700
|
testDocumentSeparator() {
|
|
5509
|
-
let ch = this.peek();
|
|
5510
|
-
if ((ch === MINUS || ch === DOT) && ch === this.peek(1) && ch === this.peek(2)) {
|
|
5511
|
-
ch = this.peek(3);
|
|
5701
|
+
let ch = this.#scanner.peek();
|
|
5702
|
+
if ((ch === MINUS || ch === DOT) && ch === this.#scanner.peek(1) && ch === this.#scanner.peek(2)) {
|
|
5703
|
+
ch = this.#scanner.peek(3);
|
|
5512
5704
|
if (ch === 0 || isWhiteSpaceOrEOL(ch)) {
|
|
5513
5705
|
return true;
|
|
5514
5706
|
}
|
|
@@ -5516,34 +5708,34 @@ var LoaderState = class {
|
|
|
5516
5708
|
return false;
|
|
5517
5709
|
}
|
|
5518
5710
|
readPlainScalar(tag, anchor, nodeIndent, withinFlowCollection) {
|
|
5519
|
-
let ch = this.peek();
|
|
5711
|
+
let ch = this.#scanner.peek();
|
|
5520
5712
|
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) {
|
|
5521
5713
|
return;
|
|
5522
5714
|
}
|
|
5523
5715
|
let following;
|
|
5524
5716
|
if (ch === QUESTION || ch === MINUS) {
|
|
5525
|
-
following = this.peek(1);
|
|
5717
|
+
following = this.#scanner.peek(1);
|
|
5526
5718
|
if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
|
|
5527
5719
|
return;
|
|
5528
5720
|
}
|
|
5529
5721
|
}
|
|
5530
5722
|
let result = "";
|
|
5531
|
-
let captureEnd = this.position;
|
|
5532
|
-
let captureStart = this.position;
|
|
5723
|
+
let captureEnd = this.#scanner.position;
|
|
5724
|
+
let captureStart = this.#scanner.position;
|
|
5533
5725
|
let hasPendingContent = false;
|
|
5534
5726
|
let line = 0;
|
|
5535
5727
|
while (ch !== 0) {
|
|
5536
5728
|
if (ch === COLON) {
|
|
5537
|
-
following = this.peek(1);
|
|
5729
|
+
following = this.#scanner.peek(1);
|
|
5538
5730
|
if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
|
|
5539
5731
|
break;
|
|
5540
5732
|
}
|
|
5541
5733
|
} else if (ch === SHARP) {
|
|
5542
|
-
const preceding = this.peek(-1);
|
|
5734
|
+
const preceding = this.#scanner.peek(-1);
|
|
5543
5735
|
if (isWhiteSpaceOrEOL(preceding)) {
|
|
5544
5736
|
break;
|
|
5545
5737
|
}
|
|
5546
|
-
} else if (this.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
|
|
5738
|
+
} else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
|
|
5547
5739
|
break;
|
|
5548
5740
|
} else if (isEOL(ch)) {
|
|
5549
5741
|
line = this.line;
|
|
@@ -5552,10 +5744,10 @@ var LoaderState = class {
|
|
|
5552
5744
|
this.skipSeparationSpace(false, -1);
|
|
5553
5745
|
if (this.lineIndent >= nodeIndent) {
|
|
5554
5746
|
hasPendingContent = true;
|
|
5555
|
-
ch = this.peek();
|
|
5747
|
+
ch = this.#scanner.peek();
|
|
5556
5748
|
continue;
|
|
5557
5749
|
} else {
|
|
5558
|
-
this.position = captureEnd;
|
|
5750
|
+
this.#scanner.position = captureEnd;
|
|
5559
5751
|
this.line = line;
|
|
5560
5752
|
this.lineStart = lineStart;
|
|
5561
5753
|
this.lineIndent = lineIndent;
|
|
@@ -5566,13 +5758,14 @@ var LoaderState = class {
|
|
|
5566
5758
|
const segment2 = this.captureSegment(captureStart, captureEnd, false);
|
|
5567
5759
|
if (segment2) result += segment2;
|
|
5568
5760
|
result += writeFoldedLines(this.line - line);
|
|
5569
|
-
captureStart = captureEnd = this.position;
|
|
5761
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
5570
5762
|
hasPendingContent = false;
|
|
5571
5763
|
}
|
|
5572
5764
|
if (!isWhiteSpace(ch)) {
|
|
5573
|
-
captureEnd = this.position + 1;
|
|
5765
|
+
captureEnd = this.#scanner.position + 1;
|
|
5574
5766
|
}
|
|
5575
|
-
|
|
5767
|
+
this.#scanner.next();
|
|
5768
|
+
ch = this.#scanner.peek();
|
|
5576
5769
|
}
|
|
5577
5770
|
const segment = this.captureSegment(captureStart, captureEnd, false);
|
|
5578
5771
|
if (segment) result += segment;
|
|
@@ -5585,22 +5778,23 @@ var LoaderState = class {
|
|
|
5585
5778
|
};
|
|
5586
5779
|
}
|
|
5587
5780
|
readSingleQuotedScalar(tag, anchor, nodeIndent) {
|
|
5588
|
-
let ch = this.peek();
|
|
5781
|
+
let ch = this.#scanner.peek();
|
|
5589
5782
|
if (ch !== SINGLE_QUOTE) return;
|
|
5590
5783
|
let result = "";
|
|
5591
|
-
this.
|
|
5592
|
-
let captureStart = this.position;
|
|
5593
|
-
let captureEnd = this.position;
|
|
5594
|
-
ch = this.peek();
|
|
5784
|
+
this.#scanner.next();
|
|
5785
|
+
let captureStart = this.#scanner.position;
|
|
5786
|
+
let captureEnd = this.#scanner.position;
|
|
5787
|
+
ch = this.#scanner.peek();
|
|
5595
5788
|
while (ch !== 0) {
|
|
5596
5789
|
if (ch === SINGLE_QUOTE) {
|
|
5597
|
-
const segment = this.captureSegment(captureStart, this.position, true);
|
|
5790
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, true);
|
|
5598
5791
|
if (segment) result += segment;
|
|
5599
|
-
|
|
5792
|
+
this.#scanner.next();
|
|
5793
|
+
ch = this.#scanner.peek();
|
|
5600
5794
|
if (ch === SINGLE_QUOTE) {
|
|
5601
|
-
captureStart = this.position;
|
|
5602
|
-
this.
|
|
5603
|
-
captureEnd = this.position;
|
|
5795
|
+
captureStart = this.#scanner.position;
|
|
5796
|
+
this.#scanner.next();
|
|
5797
|
+
captureEnd = this.#scanner.position;
|
|
5604
5798
|
} else {
|
|
5605
5799
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
5606
5800
|
return {
|
|
@@ -5614,31 +5808,31 @@ var LoaderState = class {
|
|
|
5614
5808
|
const segment = this.captureSegment(captureStart, captureEnd, true);
|
|
5615
5809
|
if (segment) result += segment;
|
|
5616
5810
|
result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
|
|
5617
|
-
captureStart = captureEnd = this.position;
|
|
5618
|
-
} else if (this.position === this.lineStart && this.testDocumentSeparator()) {
|
|
5811
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
5812
|
+
} else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
|
|
5619
5813
|
throw this.#createError("Unexpected end of the document within a single quoted scalar");
|
|
5620
5814
|
} else {
|
|
5621
|
-
this.
|
|
5622
|
-
captureEnd = this.position;
|
|
5815
|
+
this.#scanner.next();
|
|
5816
|
+
captureEnd = this.#scanner.position;
|
|
5623
5817
|
}
|
|
5624
|
-
ch = this.peek();
|
|
5818
|
+
ch = this.#scanner.peek();
|
|
5625
5819
|
}
|
|
5626
5820
|
throw this.#createError("Unexpected end of the stream within a single quoted scalar");
|
|
5627
5821
|
}
|
|
5628
5822
|
readDoubleQuotedScalar(tag, anchor, nodeIndent) {
|
|
5629
|
-
let ch = this.peek();
|
|
5823
|
+
let ch = this.#scanner.peek();
|
|
5630
5824
|
if (ch !== DOUBLE_QUOTE) return;
|
|
5631
5825
|
let result = "";
|
|
5632
|
-
this.
|
|
5633
|
-
let captureEnd = this.position;
|
|
5634
|
-
let captureStart = this.position;
|
|
5826
|
+
this.#scanner.next();
|
|
5827
|
+
let captureEnd = this.#scanner.position;
|
|
5828
|
+
let captureStart = this.#scanner.position;
|
|
5635
5829
|
let tmp;
|
|
5636
|
-
ch = this.peek();
|
|
5830
|
+
ch = this.#scanner.peek();
|
|
5637
5831
|
while (ch !== 0) {
|
|
5638
5832
|
if (ch === DOUBLE_QUOTE) {
|
|
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
|
-
this.
|
|
5835
|
+
this.#scanner.next();
|
|
5642
5836
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
5643
5837
|
return {
|
|
5644
5838
|
tag,
|
|
@@ -5648,19 +5842,21 @@ var LoaderState = class {
|
|
|
5648
5842
|
};
|
|
5649
5843
|
}
|
|
5650
5844
|
if (ch === BACKSLASH) {
|
|
5651
|
-
const segment = this.captureSegment(captureStart, this.position, true);
|
|
5845
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, true);
|
|
5652
5846
|
if (segment) result += segment;
|
|
5653
|
-
|
|
5847
|
+
this.#scanner.next();
|
|
5848
|
+
ch = this.#scanner.peek();
|
|
5654
5849
|
if (isEOL(ch)) {
|
|
5655
5850
|
this.skipSeparationSpace(false, nodeIndent);
|
|
5656
5851
|
} else if (ch < 256 && SIMPLE_ESCAPE_SEQUENCES.has(ch)) {
|
|
5657
5852
|
result += SIMPLE_ESCAPE_SEQUENCES.get(ch);
|
|
5658
|
-
this.
|
|
5853
|
+
this.#scanner.next();
|
|
5659
5854
|
} else if ((tmp = ESCAPED_HEX_LENGTHS.get(ch) ?? 0) > 0) {
|
|
5660
5855
|
let hexLength = tmp;
|
|
5661
5856
|
let hexResult = 0;
|
|
5662
5857
|
for (; hexLength > 0; hexLength--) {
|
|
5663
|
-
|
|
5858
|
+
this.#scanner.next();
|
|
5859
|
+
ch = this.#scanner.peek();
|
|
5664
5860
|
if ((tmp = hexCharCodeToNumber(ch)) >= 0) {
|
|
5665
5861
|
hexResult = (hexResult << 4) + tmp;
|
|
5666
5862
|
} else {
|
|
@@ -5668,28 +5864,28 @@ var LoaderState = class {
|
|
|
5668
5864
|
}
|
|
5669
5865
|
}
|
|
5670
5866
|
result += codepointToChar(hexResult);
|
|
5671
|
-
this.
|
|
5867
|
+
this.#scanner.next();
|
|
5672
5868
|
} else {
|
|
5673
5869
|
throw this.#createError("Cannot read double quoted scalar: unknown escape sequence");
|
|
5674
5870
|
}
|
|
5675
|
-
captureStart = captureEnd = this.position;
|
|
5871
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
5676
5872
|
} else if (isEOL(ch)) {
|
|
5677
5873
|
const segment = this.captureSegment(captureStart, captureEnd, true);
|
|
5678
5874
|
if (segment) result += segment;
|
|
5679
5875
|
result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
|
|
5680
|
-
captureStart = captureEnd = this.position;
|
|
5681
|
-
} else if (this.position === this.lineStart && this.testDocumentSeparator()) {
|
|
5876
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
5877
|
+
} else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
|
|
5682
5878
|
throw this.#createError("Unexpected end of the document within a double quoted scalar");
|
|
5683
5879
|
} else {
|
|
5684
|
-
this.
|
|
5685
|
-
captureEnd = this.position;
|
|
5880
|
+
this.#scanner.next();
|
|
5881
|
+
captureEnd = this.#scanner.position;
|
|
5686
5882
|
}
|
|
5687
|
-
ch = this.peek();
|
|
5883
|
+
ch = this.#scanner.peek();
|
|
5688
5884
|
}
|
|
5689
5885
|
throw this.#createError("Unexpected end of the stream within a double quoted scalar");
|
|
5690
5886
|
}
|
|
5691
5887
|
readFlowCollection(tag, anchor, nodeIndent) {
|
|
5692
|
-
let ch = this.peek();
|
|
5888
|
+
let ch = this.#scanner.peek();
|
|
5693
5889
|
let terminator;
|
|
5694
5890
|
let isMapping = true;
|
|
5695
5891
|
let result = {};
|
|
@@ -5703,7 +5899,8 @@ var LoaderState = class {
|
|
|
5703
5899
|
return;
|
|
5704
5900
|
}
|
|
5705
5901
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
5706
|
-
|
|
5902
|
+
this.#scanner.next();
|
|
5903
|
+
ch = this.#scanner.peek();
|
|
5707
5904
|
let readNext = true;
|
|
5708
5905
|
let valueNode = null;
|
|
5709
5906
|
let keyNode = null;
|
|
@@ -5715,9 +5912,9 @@ var LoaderState = class {
|
|
|
5715
5912
|
const overridableKeys = /* @__PURE__ */ new Set();
|
|
5716
5913
|
while (ch !== 0) {
|
|
5717
5914
|
this.skipSeparationSpace(true, nodeIndent);
|
|
5718
|
-
ch = this.peek();
|
|
5915
|
+
ch = this.#scanner.peek();
|
|
5719
5916
|
if (ch === terminator) {
|
|
5720
|
-
this.
|
|
5917
|
+
this.#scanner.next();
|
|
5721
5918
|
const kind = isMapping ? "mapping" : "sequence";
|
|
5722
5919
|
return {
|
|
5723
5920
|
tag,
|
|
@@ -5732,10 +5929,10 @@ var LoaderState = class {
|
|
|
5732
5929
|
keyTag = keyNode = valueNode = null;
|
|
5733
5930
|
isPair = isExplicitPair = false;
|
|
5734
5931
|
if (ch === QUESTION) {
|
|
5735
|
-
following = this.peek(1);
|
|
5932
|
+
following = this.#scanner.peek(1);
|
|
5736
5933
|
if (isWhiteSpaceOrEOL(following)) {
|
|
5737
5934
|
isPair = isExplicitPair = true;
|
|
5738
|
-
this.
|
|
5935
|
+
this.#scanner.next();
|
|
5739
5936
|
this.skipSeparationSpace(true, nodeIndent);
|
|
5740
5937
|
}
|
|
5741
5938
|
}
|
|
@@ -5751,10 +5948,11 @@ var LoaderState = class {
|
|
|
5751
5948
|
keyNode = newState.result;
|
|
5752
5949
|
}
|
|
5753
5950
|
this.skipSeparationSpace(true, nodeIndent);
|
|
5754
|
-
ch = this.peek();
|
|
5951
|
+
ch = this.#scanner.peek();
|
|
5755
5952
|
if ((isExplicitPair || this.line === line) && ch === COLON) {
|
|
5756
5953
|
isPair = true;
|
|
5757
|
-
|
|
5954
|
+
this.#scanner.next();
|
|
5955
|
+
ch = this.#scanner.peek();
|
|
5758
5956
|
this.skipSeparationSpace(true, nodeIndent);
|
|
5759
5957
|
const newState2 = this.composeNode({
|
|
5760
5958
|
parentIndent: nodeIndent,
|
|
@@ -5772,10 +5970,11 @@ var LoaderState = class {
|
|
|
5772
5970
|
result.push(keyNode);
|
|
5773
5971
|
}
|
|
5774
5972
|
this.skipSeparationSpace(true, nodeIndent);
|
|
5775
|
-
ch = this.peek();
|
|
5973
|
+
ch = this.#scanner.peek();
|
|
5776
5974
|
if (ch === COMMA) {
|
|
5777
5975
|
readNext = true;
|
|
5778
|
-
|
|
5976
|
+
this.#scanner.next();
|
|
5977
|
+
ch = this.#scanner.peek();
|
|
5779
5978
|
} else {
|
|
5780
5979
|
readNext = false;
|
|
5781
5980
|
}
|
|
@@ -5791,7 +5990,7 @@ var LoaderState = class {
|
|
|
5791
5990
|
let textIndent = nodeIndent;
|
|
5792
5991
|
let emptyLines = 0;
|
|
5793
5992
|
let atMoreIndented = false;
|
|
5794
|
-
let ch = this.peek();
|
|
5993
|
+
let ch = this.#scanner.peek();
|
|
5795
5994
|
let folding = false;
|
|
5796
5995
|
if (ch === VERTICAL_LINE) {
|
|
5797
5996
|
folding = false;
|
|
@@ -5803,7 +6002,8 @@ var LoaderState = class {
|
|
|
5803
6002
|
let result = "";
|
|
5804
6003
|
let tmp = 0;
|
|
5805
6004
|
while (ch !== 0) {
|
|
5806
|
-
|
|
6005
|
+
this.#scanner.next();
|
|
6006
|
+
ch = this.#scanner.peek();
|
|
5807
6007
|
if (ch === PLUS || ch === MINUS) {
|
|
5808
6008
|
if (CHOMPING_CLIP === chomping) {
|
|
5809
6009
|
chomping = ch === PLUS ? CHOMPING_KEEP : CHOMPING_STRIP;
|
|
@@ -5826,15 +6026,16 @@ var LoaderState = class {
|
|
|
5826
6026
|
if (isWhiteSpace(ch)) {
|
|
5827
6027
|
this.skipWhitespaces();
|
|
5828
6028
|
this.skipComment();
|
|
5829
|
-
ch = this.peek();
|
|
6029
|
+
ch = this.#scanner.peek();
|
|
5830
6030
|
}
|
|
5831
6031
|
while (ch !== 0) {
|
|
5832
6032
|
this.readLineBreak();
|
|
5833
6033
|
this.lineIndent = 0;
|
|
5834
|
-
ch = this.peek();
|
|
6034
|
+
ch = this.#scanner.peek();
|
|
5835
6035
|
while ((!detectedIndent || this.lineIndent < textIndent) && ch === SPACE) {
|
|
5836
6036
|
this.lineIndent++;
|
|
5837
|
-
|
|
6037
|
+
this.#scanner.next();
|
|
6038
|
+
ch = this.#scanner.peek();
|
|
5838
6039
|
}
|
|
5839
6040
|
if (!detectedIndent && this.lineIndent > textIndent) {
|
|
5840
6041
|
textIndent = this.lineIndent;
|
|
@@ -5873,11 +6074,12 @@ var LoaderState = class {
|
|
|
5873
6074
|
didReadContent = true;
|
|
5874
6075
|
detectedIndent = true;
|
|
5875
6076
|
emptyLines = 0;
|
|
5876
|
-
const captureStart = this.position;
|
|
6077
|
+
const captureStart = this.#scanner.position;
|
|
5877
6078
|
while (!isEOL(ch) && ch !== 0) {
|
|
5878
|
-
|
|
6079
|
+
this.#scanner.next();
|
|
6080
|
+
ch = this.#scanner.peek();
|
|
5879
6081
|
}
|
|
5880
|
-
const segment = this.captureSegment(captureStart, this.position, false);
|
|
6082
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, false);
|
|
5881
6083
|
if (segment) result += segment;
|
|
5882
6084
|
}
|
|
5883
6085
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
@@ -5900,11 +6102,11 @@ var LoaderState = class {
|
|
|
5900
6102
|
let atExplicitKey = false;
|
|
5901
6103
|
let detected = false;
|
|
5902
6104
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
5903
|
-
let ch = this.peek();
|
|
6105
|
+
let ch = this.#scanner.peek();
|
|
5904
6106
|
while (ch !== 0) {
|
|
5905
|
-
const following = this.peek(1);
|
|
6107
|
+
const following = this.#scanner.peek(1);
|
|
5906
6108
|
line = this.line;
|
|
5907
|
-
pos = this.position;
|
|
6109
|
+
pos = this.#scanner.position;
|
|
5908
6110
|
if ((ch === QUESTION || ch === COLON) && isWhiteSpaceOrEOL(following)) {
|
|
5909
6111
|
if (ch === QUESTION) {
|
|
5910
6112
|
if (atExplicitKey) {
|
|
@@ -5922,7 +6124,7 @@ var LoaderState = class {
|
|
|
5922
6124
|
} else {
|
|
5923
6125
|
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");
|
|
5924
6126
|
}
|
|
5925
|
-
this.
|
|
6127
|
+
this.#scanner.next();
|
|
5926
6128
|
ch = following;
|
|
5927
6129
|
} else {
|
|
5928
6130
|
const newState = this.composeNode({
|
|
@@ -5933,11 +6135,12 @@ var LoaderState = class {
|
|
|
5933
6135
|
});
|
|
5934
6136
|
if (!newState) break;
|
|
5935
6137
|
if (this.line === line) {
|
|
5936
|
-
ch = this.peek();
|
|
6138
|
+
ch = this.#scanner.peek();
|
|
5937
6139
|
this.skipWhitespaces();
|
|
5938
|
-
ch = this.peek();
|
|
6140
|
+
ch = this.#scanner.peek();
|
|
5939
6141
|
if (ch === COLON) {
|
|
5940
|
-
|
|
6142
|
+
this.#scanner.next();
|
|
6143
|
+
ch = this.#scanner.peek();
|
|
5941
6144
|
if (!isWhiteSpaceOrEOL(ch)) {
|
|
5942
6145
|
throw this.#createError("Cannot read block: a whitespace character is expected after the key-value separator within a block mapping");
|
|
5943
6146
|
}
|
|
@@ -5994,7 +6197,7 @@ var LoaderState = class {
|
|
|
5994
6197
|
keyTag = keyNode = valueNode = null;
|
|
5995
6198
|
}
|
|
5996
6199
|
this.skipSeparationSpace(true, -1);
|
|
5997
|
-
ch = this.peek();
|
|
6200
|
+
ch = this.#scanner.peek();
|
|
5998
6201
|
}
|
|
5999
6202
|
if (this.lineIndent > nodeIndent && ch !== 0) {
|
|
6000
6203
|
throw this.#createError("Cannot read block: bad indentation of a mapping entry");
|
|
@@ -6017,30 +6220,35 @@ var LoaderState = class {
|
|
|
6017
6220
|
let isNamed = false;
|
|
6018
6221
|
let tagHandle = "";
|
|
6019
6222
|
let tagName;
|
|
6020
|
-
let ch = this.peek();
|
|
6223
|
+
let ch = this.#scanner.peek();
|
|
6021
6224
|
if (ch !== EXCLAMATION) return;
|
|
6022
6225
|
if (tag !== null) {
|
|
6023
6226
|
throw this.#createError("Cannot read tag property: duplication of a tag property");
|
|
6024
6227
|
}
|
|
6025
|
-
|
|
6228
|
+
this.#scanner.next();
|
|
6229
|
+
ch = this.#scanner.peek();
|
|
6026
6230
|
if (ch === SMALLER_THAN) {
|
|
6027
6231
|
isVerbatim = true;
|
|
6028
|
-
|
|
6232
|
+
this.#scanner.next();
|
|
6233
|
+
ch = this.#scanner.peek();
|
|
6029
6234
|
} else if (ch === EXCLAMATION) {
|
|
6030
6235
|
isNamed = true;
|
|
6031
6236
|
tagHandle = "!!";
|
|
6032
|
-
|
|
6237
|
+
this.#scanner.next();
|
|
6238
|
+
ch = this.#scanner.peek();
|
|
6033
6239
|
} else {
|
|
6034
6240
|
tagHandle = "!";
|
|
6035
6241
|
}
|
|
6036
|
-
let position = this.position;
|
|
6242
|
+
let position = this.#scanner.position;
|
|
6037
6243
|
if (isVerbatim) {
|
|
6038
6244
|
do {
|
|
6039
|
-
|
|
6245
|
+
this.#scanner.next();
|
|
6246
|
+
ch = this.#scanner.peek();
|
|
6040
6247
|
} while (ch !== 0 && ch !== GREATER_THAN);
|
|
6041
|
-
if (this.
|
|
6042
|
-
tagName = this.
|
|
6043
|
-
|
|
6248
|
+
if (!this.#scanner.eof()) {
|
|
6249
|
+
tagName = this.#scanner.source.slice(position, this.#scanner.position);
|
|
6250
|
+
this.#scanner.next();
|
|
6251
|
+
ch = this.#scanner.peek();
|
|
6044
6252
|
} else {
|
|
6045
6253
|
throw this.#createError("Cannot read tag property: unexpected end of stream");
|
|
6046
6254
|
}
|
|
@@ -6048,19 +6256,20 @@ var LoaderState = class {
|
|
|
6048
6256
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
|
|
6049
6257
|
if (ch === EXCLAMATION) {
|
|
6050
6258
|
if (!isNamed) {
|
|
6051
|
-
tagHandle = this.
|
|
6259
|
+
tagHandle = this.#scanner.source.slice(position - 1, this.#scanner.position + 1);
|
|
6052
6260
|
if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
|
6053
6261
|
throw this.#createError("Cannot read tag property: named tag handle contains invalid characters");
|
|
6054
6262
|
}
|
|
6055
6263
|
isNamed = true;
|
|
6056
|
-
position = this.position + 1;
|
|
6264
|
+
position = this.#scanner.position + 1;
|
|
6057
6265
|
} else {
|
|
6058
6266
|
throw this.#createError("Cannot read tag property: tag suffix cannot contain an exclamation mark");
|
|
6059
6267
|
}
|
|
6060
6268
|
}
|
|
6061
|
-
|
|
6269
|
+
this.#scanner.next();
|
|
6270
|
+
ch = this.#scanner.peek();
|
|
6062
6271
|
}
|
|
6063
|
-
tagName = this.
|
|
6272
|
+
tagName = this.#scanner.source.slice(position, this.#scanner.position);
|
|
6064
6273
|
if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
|
6065
6274
|
throw this.#createError("Cannot read tag property: tag suffix cannot contain flow indicator characters");
|
|
6066
6275
|
}
|
|
@@ -6080,32 +6289,36 @@ var LoaderState = class {
|
|
|
6080
6289
|
throw this.#createError(`Cannot read tag property: undeclared tag handle "${tagHandle}"`);
|
|
6081
6290
|
}
|
|
6082
6291
|
readAnchorProperty(anchor) {
|
|
6083
|
-
let ch = this.peek();
|
|
6292
|
+
let ch = this.#scanner.peek();
|
|
6084
6293
|
if (ch !== AMPERSAND) return;
|
|
6085
6294
|
if (anchor !== null) {
|
|
6086
6295
|
throw this.#createError("Cannot read anchor property: duplicate anchor property");
|
|
6087
6296
|
}
|
|
6088
|
-
|
|
6089
|
-
|
|
6297
|
+
this.#scanner.next();
|
|
6298
|
+
ch = this.#scanner.peek();
|
|
6299
|
+
const position = this.#scanner.position;
|
|
6090
6300
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
|
|
6091
|
-
|
|
6301
|
+
this.#scanner.next();
|
|
6302
|
+
ch = this.#scanner.peek();
|
|
6092
6303
|
}
|
|
6093
|
-
if (this.position === position) {
|
|
6304
|
+
if (this.#scanner.position === position) {
|
|
6094
6305
|
throw this.#createError("Cannot read anchor property: name of an anchor node must contain at least one character");
|
|
6095
6306
|
}
|
|
6096
|
-
return this.
|
|
6307
|
+
return this.#scanner.source.slice(position, this.#scanner.position);
|
|
6097
6308
|
}
|
|
6098
6309
|
readAlias() {
|
|
6099
|
-
if (this.peek() !== ASTERISK) return;
|
|
6100
|
-
|
|
6101
|
-
|
|
6310
|
+
if (this.#scanner.peek() !== ASTERISK) return;
|
|
6311
|
+
this.#scanner.next();
|
|
6312
|
+
let ch = this.#scanner.peek();
|
|
6313
|
+
const position = this.#scanner.position;
|
|
6102
6314
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
|
|
6103
|
-
|
|
6315
|
+
this.#scanner.next();
|
|
6316
|
+
ch = this.#scanner.peek();
|
|
6104
6317
|
}
|
|
6105
|
-
if (this.position === position) {
|
|
6318
|
+
if (this.#scanner.position === position) {
|
|
6106
6319
|
throw this.#createError("Cannot read alias: alias name must contain at least one character");
|
|
6107
6320
|
}
|
|
6108
|
-
const alias = this.
|
|
6321
|
+
const alias = this.#scanner.source.slice(position, this.#scanner.position);
|
|
6109
6322
|
if (!this.anchorMap.has(alias)) {
|
|
6110
6323
|
throw this.#createError(`Cannot read alias: unidentified alias "${alias}"`);
|
|
6111
6324
|
}
|
|
@@ -6188,7 +6401,7 @@ var LoaderState = class {
|
|
|
6188
6401
|
const cond = CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext;
|
|
6189
6402
|
const flowIndent = cond ? parentIndent : parentIndent + 1;
|
|
6190
6403
|
if (allowBlockCollections) {
|
|
6191
|
-
const blockIndent = this.position - this.lineStart;
|
|
6404
|
+
const blockIndent = this.#scanner.position - this.lineStart;
|
|
6192
6405
|
const blockSequenceState = this.readBlockSequence(tag, anchor, blockIndent);
|
|
6193
6406
|
if (blockSequenceState) return this.resolveTag(blockSequenceState);
|
|
6194
6407
|
const blockMappingState = this.readBlockMapping(tag, anchor, blockIndent, flowIndent);
|
|
@@ -6222,7 +6435,7 @@ var LoaderState = class {
|
|
|
6222
6435
|
return this.resolveTag(plainScalarState);
|
|
6223
6436
|
}
|
|
6224
6437
|
} else if (indentStatus === 0 && CONTEXT_BLOCK_OUT === nodeContext && allowBlockCollections) {
|
|
6225
|
-
const blockIndent = this.position - this.lineStart;
|
|
6438
|
+
const blockIndent = this.#scanner.position - this.lineStart;
|
|
6226
6439
|
const newState2 = this.readBlockSequence(tag, anchor, blockIndent);
|
|
6227
6440
|
if (newState2) return this.resolveTag(newState2);
|
|
6228
6441
|
}
|
|
@@ -6237,20 +6450,22 @@ var LoaderState = class {
|
|
|
6237
6450
|
readDirectives() {
|
|
6238
6451
|
let hasDirectives = false;
|
|
6239
6452
|
let version = null;
|
|
6240
|
-
let ch = this.peek();
|
|
6453
|
+
let ch = this.#scanner.peek();
|
|
6241
6454
|
while (ch !== 0) {
|
|
6242
6455
|
this.skipSeparationSpace(true, -1);
|
|
6243
|
-
ch = this.peek();
|
|
6456
|
+
ch = this.#scanner.peek();
|
|
6244
6457
|
if (this.lineIndent > 0 || ch !== PERCENT) {
|
|
6245
6458
|
break;
|
|
6246
6459
|
}
|
|
6247
6460
|
hasDirectives = true;
|
|
6248
|
-
|
|
6249
|
-
|
|
6461
|
+
this.#scanner.next();
|
|
6462
|
+
ch = this.#scanner.peek();
|
|
6463
|
+
let position = this.#scanner.position;
|
|
6250
6464
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
|
|
6251
|
-
|
|
6465
|
+
this.#scanner.next();
|
|
6466
|
+
ch = this.#scanner.peek();
|
|
6252
6467
|
}
|
|
6253
|
-
const directiveName = this.
|
|
6468
|
+
const directiveName = this.#scanner.source.slice(position, this.#scanner.position);
|
|
6254
6469
|
const directiveArgs = [];
|
|
6255
6470
|
if (directiveName.length < 1) {
|
|
6256
6471
|
throw this.#createError("Cannot read document: directive name length must be greater than zero");
|
|
@@ -6258,13 +6473,14 @@ var LoaderState = class {
|
|
|
6258
6473
|
while (ch !== 0) {
|
|
6259
6474
|
this.skipWhitespaces();
|
|
6260
6475
|
this.skipComment();
|
|
6261
|
-
ch = this.peek();
|
|
6476
|
+
ch = this.#scanner.peek();
|
|
6262
6477
|
if (isEOL(ch)) break;
|
|
6263
|
-
position = this.position;
|
|
6478
|
+
position = this.#scanner.position;
|
|
6264
6479
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
|
|
6265
|
-
|
|
6480
|
+
this.#scanner.next();
|
|
6481
|
+
ch = this.#scanner.peek();
|
|
6266
6482
|
}
|
|
6267
|
-
directiveArgs.push(this.
|
|
6483
|
+
directiveArgs.push(this.#scanner.source.slice(position, this.#scanner.position));
|
|
6268
6484
|
}
|
|
6269
6485
|
if (ch !== 0) this.readLineBreak();
|
|
6270
6486
|
switch (directiveName) {
|
|
@@ -6281,20 +6497,20 @@ var LoaderState = class {
|
|
|
6281
6497
|
this.dispatchWarning(`unknown document directive "${directiveName}"`);
|
|
6282
6498
|
break;
|
|
6283
6499
|
}
|
|
6284
|
-
ch = this.peek();
|
|
6500
|
+
ch = this.#scanner.peek();
|
|
6285
6501
|
}
|
|
6286
6502
|
return hasDirectives;
|
|
6287
6503
|
}
|
|
6288
6504
|
readDocument() {
|
|
6289
|
-
const documentStart = this.position;
|
|
6505
|
+
const documentStart = this.#scanner.position;
|
|
6290
6506
|
this.checkLineBreaks = false;
|
|
6291
6507
|
this.tagMap = /* @__PURE__ */ new Map();
|
|
6292
6508
|
this.anchorMap = /* @__PURE__ */ new Map();
|
|
6293
6509
|
const hasDirectives = this.readDirectives();
|
|
6294
6510
|
this.skipSeparationSpace(true, -1);
|
|
6295
6511
|
let result = null;
|
|
6296
|
-
if (this.lineIndent === 0 && this.peek() === MINUS && this.peek(1) === MINUS && this.peek(2) === MINUS) {
|
|
6297
|
-
this.position += 3;
|
|
6512
|
+
if (this.lineIndent === 0 && this.#scanner.peek() === MINUS && this.#scanner.peek(1) === MINUS && this.#scanner.peek(2) === MINUS) {
|
|
6513
|
+
this.#scanner.position += 3;
|
|
6298
6514
|
this.skipSeparationSpace(true, -1);
|
|
6299
6515
|
} else if (hasDirectives) {
|
|
6300
6516
|
throw this.#createError("Cannot read document: directives end mark is expected");
|
|
@@ -6307,21 +6523,21 @@ var LoaderState = class {
|
|
|
6307
6523
|
});
|
|
6308
6524
|
if (newState) result = newState.result;
|
|
6309
6525
|
this.skipSeparationSpace(true, -1);
|
|
6310
|
-
if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.
|
|
6526
|
+
if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.#scanner.source.slice(documentStart, this.#scanner.position))) {
|
|
6311
6527
|
this.dispatchWarning("non-ASCII line breaks are interpreted as content");
|
|
6312
6528
|
}
|
|
6313
|
-
if (this.position === this.lineStart && this.testDocumentSeparator()) {
|
|
6314
|
-
if (this.peek() === DOT) {
|
|
6315
|
-
this.position += 3;
|
|
6529
|
+
if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
|
|
6530
|
+
if (this.#scanner.peek() === DOT) {
|
|
6531
|
+
this.#scanner.position += 3;
|
|
6316
6532
|
this.skipSeparationSpace(true, -1);
|
|
6317
6533
|
}
|
|
6318
|
-
} else if (this.
|
|
6534
|
+
} else if (!this.#scanner.eof()) {
|
|
6319
6535
|
throw this.#createError("Cannot read document: end of the stream or a document separator is expected");
|
|
6320
6536
|
}
|
|
6321
6537
|
return result;
|
|
6322
6538
|
}
|
|
6323
6539
|
*readDocuments() {
|
|
6324
|
-
while (this.
|
|
6540
|
+
while (!this.#scanner.eof()) {
|
|
6325
6541
|
yield this.readDocument();
|
|
6326
6542
|
}
|
|
6327
6543
|
}
|
|
@@ -6334,7 +6550,6 @@ function sanitizeInput(input) {
|
|
|
6334
6550
|
if (!isEOL(input.charCodeAt(input.length - 1))) input += "\n";
|
|
6335
6551
|
if (input.charCodeAt(0) === 65279) input = input.slice(1);
|
|
6336
6552
|
}
|
|
6337
|
-
input += "\0";
|
|
6338
6553
|
return input;
|
|
6339
6554
|
}
|
|
6340
6555
|
function parse(content, options = {}) {
|
|
@@ -6352,10 +6567,10 @@ function parse(content, options = {}) {
|
|
|
6352
6567
|
}
|
|
6353
6568
|
|
|
6354
6569
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__plugin-markdown-loader/src/markdown-loader.js
|
|
6355
|
-
var
|
|
6570
|
+
var import_node_process2 = __toESM(require("node:process"), 1);
|
|
6356
6571
|
function replaceEnvVars(str2) {
|
|
6357
6572
|
return str2.replace(/\$([A-Za-z_][A-Za-z0-9_]*)(?!\s*\()/g, (match, varName) => {
|
|
6358
|
-
const value =
|
|
6573
|
+
const value = import_node_process2.default.env[varName];
|
|
6359
6574
|
if (value !== void 0) {
|
|
6360
6575
|
return value;
|
|
6361
6576
|
}
|
|
@@ -6454,18 +6669,19 @@ var defaultPlugin = markdownLoaderPlugin();
|
|
|
6454
6669
|
|
|
6455
6670
|
// __mcpc__cli_latest/node_modules/@mcpc/cli/src/defaults.js
|
|
6456
6671
|
var import_node_path5 = require("node:path");
|
|
6457
|
-
var
|
|
6672
|
+
var import_node_process3 = __toESM(require("node:process"), 1);
|
|
6458
6673
|
var DEFAULT_SKILLS_PATHS = [
|
|
6459
6674
|
".agent/skills"
|
|
6460
6675
|
];
|
|
6461
6676
|
var DEFAULT_CODE_EXECUTION_TIMEOUT = 3e5;
|
|
6462
6677
|
function getGlobalPlugins(skillsPaths) {
|
|
6463
|
-
const resolvedPaths = skillsPaths.map((p2) => (0, import_node_path5.resolve)(
|
|
6678
|
+
const resolvedPaths = skillsPaths.map((p2) => (0, import_node_path5.resolve)(import_node_process3.default.cwd(), p2));
|
|
6464
6679
|
return [
|
|
6465
6680
|
markdownLoaderPlugin(),
|
|
6466
6681
|
createSkillsPlugin({
|
|
6467
6682
|
paths: resolvedPaths
|
|
6468
|
-
})
|
|
6683
|
+
}),
|
|
6684
|
+
createBashPlugin()
|
|
6469
6685
|
];
|
|
6470
6686
|
}
|
|
6471
6687
|
function getAgentPlugins() {
|
|
@@ -6494,7 +6710,7 @@ function getDefaultAgents() {
|
|
|
6494
6710
|
}
|
|
6495
6711
|
|
|
6496
6712
|
// __mcpc__cli_latest/node_modules/@mcpc/cli/src/config/loader.js
|
|
6497
|
-
var CLI_VERSION = "0.1.
|
|
6713
|
+
var CLI_VERSION = "0.1.52";
|
|
6498
6714
|
function extractServerName(command, commandArgs) {
|
|
6499
6715
|
for (const arg of commandArgs) {
|
|
6500
6716
|
if (!arg.startsWith("-")) {
|
|
@@ -6554,7 +6770,7 @@ async function saveUserConfig(config, newAgentName) {
|
|
|
6554
6770
|
async function createWrapConfig(args) {
|
|
6555
6771
|
if (!args.mcpServers || args.mcpServers.length === 0) {
|
|
6556
6772
|
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'");
|
|
6557
|
-
|
|
6773
|
+
import_node_process4.default.exit(1);
|
|
6558
6774
|
}
|
|
6559
6775
|
const mcpServers = {};
|
|
6560
6776
|
const serverNames = [];
|
|
@@ -6677,7 +6893,7 @@ function parseMcpServer(cmdString, transportType) {
|
|
|
6677
6893
|
};
|
|
6678
6894
|
}
|
|
6679
6895
|
function parseCLIArgs() {
|
|
6680
|
-
const args = parseArgs(
|
|
6896
|
+
const args = parseArgs(import_node_process4.default.argv.slice(2), {
|
|
6681
6897
|
boolean: [
|
|
6682
6898
|
"help",
|
|
6683
6899
|
"version",
|
|
@@ -6766,15 +6982,15 @@ async function loadConfig() {
|
|
|
6766
6982
|
const args = parseCLIArgs();
|
|
6767
6983
|
if (args.version) {
|
|
6768
6984
|
printVersion();
|
|
6769
|
-
|
|
6985
|
+
import_node_process4.default.exit(0);
|
|
6770
6986
|
}
|
|
6771
6987
|
if (args.help) {
|
|
6772
6988
|
printHelp();
|
|
6773
|
-
|
|
6989
|
+
import_node_process4.default.exit(0);
|
|
6774
6990
|
}
|
|
6775
6991
|
if (args.cwd) {
|
|
6776
|
-
const targetCwd = (0, import_node_path6.resolve)(
|
|
6777
|
-
|
|
6992
|
+
const targetCwd = (0, import_node_path6.resolve)(import_node_process4.default.cwd(), args.cwd);
|
|
6993
|
+
import_node_process4.default.chdir(targetCwd);
|
|
6778
6994
|
console.error(`Changed working directory to: ${targetCwd}`);
|
|
6779
6995
|
}
|
|
6780
6996
|
const mergeSkills = (config) => {
|
|
@@ -6786,7 +7002,7 @@ async function loadConfig() {
|
|
|
6786
7002
|
...args,
|
|
6787
7003
|
saveConfig: true
|
|
6788
7004
|
});
|
|
6789
|
-
|
|
7005
|
+
import_node_process4.default.exit(0);
|
|
6790
7006
|
}
|
|
6791
7007
|
if (args.wrap) {
|
|
6792
7008
|
return mergeSkills(await createWrapConfig({
|
|
@@ -6803,16 +7019,16 @@ async function loadConfig() {
|
|
|
6803
7019
|
throw error;
|
|
6804
7020
|
}
|
|
6805
7021
|
}
|
|
6806
|
-
if (
|
|
7022
|
+
if (import_node_process4.default.env.MCPC_CONFIG) {
|
|
6807
7023
|
try {
|
|
6808
|
-
const parsed = JSON.parse(
|
|
7024
|
+
const parsed = JSON.parse(import_node_process4.default.env.MCPC_CONFIG);
|
|
6809
7025
|
return mergeSkills(applyModeOverride(normalizeConfig(parsed), args.mode));
|
|
6810
7026
|
} catch (error) {
|
|
6811
7027
|
console.error("Failed to parse MCPC_CONFIG environment variable:", error);
|
|
6812
7028
|
throw error;
|
|
6813
7029
|
}
|
|
6814
7030
|
}
|
|
6815
|
-
const configUrl = args.configUrl ||
|
|
7031
|
+
const configUrl = args.configUrl || import_node_process4.default.env.MCPC_CONFIG_URL;
|
|
6816
7032
|
if (configUrl) {
|
|
6817
7033
|
try {
|
|
6818
7034
|
const headers = {
|
|
@@ -6833,7 +7049,7 @@ async function loadConfig() {
|
|
|
6833
7049
|
throw error;
|
|
6834
7050
|
}
|
|
6835
7051
|
}
|
|
6836
|
-
const configFile = args.configFile ||
|
|
7052
|
+
const configFile = args.configFile || import_node_process4.default.env.MCPC_CONFIG_FILE;
|
|
6837
7053
|
if (configFile) {
|
|
6838
7054
|
try {
|
|
6839
7055
|
const config = await loadConfigFromFile(configFile);
|
|
@@ -6858,7 +7074,7 @@ async function loadConfig() {
|
|
|
6858
7074
|
throw error;
|
|
6859
7075
|
}
|
|
6860
7076
|
}
|
|
6861
|
-
const defaultJsonConfigPath = (0, import_node_path6.resolve)(
|
|
7077
|
+
const defaultJsonConfigPath = (0, import_node_path6.resolve)(import_node_process4.default.cwd(), "mcpc.config.json");
|
|
6862
7078
|
try {
|
|
6863
7079
|
const config = await loadConfigFromFile(defaultJsonConfigPath);
|
|
6864
7080
|
return mergeSkills(applyModeOverride(config, args.mode));
|
|
@@ -6873,7 +7089,7 @@ async function loadConfig() {
|
|
|
6873
7089
|
}
|
|
6874
7090
|
function replaceEnvVars2(str2) {
|
|
6875
7091
|
return str2.replace(/\$([A-Z_][A-Z0-9_]*)/g, (_match, varName) => {
|
|
6876
|
-
return
|
|
7092
|
+
return import_node_process4.default.env[varName] || "";
|
|
6877
7093
|
});
|
|
6878
7094
|
}
|
|
6879
7095
|
function isMarkdownFile2(path) {
|
|
@@ -8175,6 +8391,147 @@ var ExperimentalServerTasks = class {
|
|
|
8175
8391
|
requestStream(request, resultSchema, options) {
|
|
8176
8392
|
return this._server.requestStream(request, resultSchema, options);
|
|
8177
8393
|
}
|
|
8394
|
+
/**
|
|
8395
|
+
* Sends a sampling request and returns an AsyncGenerator that yields response messages.
|
|
8396
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
8397
|
+
*
|
|
8398
|
+
* For task-augmented requests, yields 'taskCreated' and 'taskStatus' messages
|
|
8399
|
+
* before the final result.
|
|
8400
|
+
*
|
|
8401
|
+
* @example
|
|
8402
|
+
* ```typescript
|
|
8403
|
+
* const stream = server.experimental.tasks.createMessageStream({
|
|
8404
|
+
* messages: [{ role: 'user', content: { type: 'text', text: 'Hello' } }],
|
|
8405
|
+
* maxTokens: 100
|
|
8406
|
+
* }, {
|
|
8407
|
+
* onprogress: (progress) => {
|
|
8408
|
+
* // Handle streaming tokens via progress notifications
|
|
8409
|
+
* console.log('Progress:', progress.message);
|
|
8410
|
+
* }
|
|
8411
|
+
* });
|
|
8412
|
+
*
|
|
8413
|
+
* for await (const message of stream) {
|
|
8414
|
+
* switch (message.type) {
|
|
8415
|
+
* case 'taskCreated':
|
|
8416
|
+
* console.log('Task created:', message.task.taskId);
|
|
8417
|
+
* break;
|
|
8418
|
+
* case 'taskStatus':
|
|
8419
|
+
* console.log('Task status:', message.task.status);
|
|
8420
|
+
* break;
|
|
8421
|
+
* case 'result':
|
|
8422
|
+
* console.log('Final result:', message.result);
|
|
8423
|
+
* break;
|
|
8424
|
+
* case 'error':
|
|
8425
|
+
* console.error('Error:', message.error);
|
|
8426
|
+
* break;
|
|
8427
|
+
* }
|
|
8428
|
+
* }
|
|
8429
|
+
* ```
|
|
8430
|
+
*
|
|
8431
|
+
* @param params - The sampling request parameters
|
|
8432
|
+
* @param options - Optional request options (timeout, signal, task creation params, onprogress, etc.)
|
|
8433
|
+
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
8434
|
+
*
|
|
8435
|
+
* @experimental
|
|
8436
|
+
*/
|
|
8437
|
+
createMessageStream(params, options) {
|
|
8438
|
+
const clientCapabilities = this._server.getClientCapabilities();
|
|
8439
|
+
if ((params.tools || params.toolChoice) && !clientCapabilities?.sampling?.tools) {
|
|
8440
|
+
throw new Error("Client does not support sampling tools capability.");
|
|
8441
|
+
}
|
|
8442
|
+
if (params.messages.length > 0) {
|
|
8443
|
+
const lastMessage = params.messages[params.messages.length - 1];
|
|
8444
|
+
const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];
|
|
8445
|
+
const hasToolResults = lastContent.some((c) => c.type === "tool_result");
|
|
8446
|
+
const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : void 0;
|
|
8447
|
+
const previousContent = previousMessage ? Array.isArray(previousMessage.content) ? previousMessage.content : [previousMessage.content] : [];
|
|
8448
|
+
const hasPreviousToolUse = previousContent.some((c) => c.type === "tool_use");
|
|
8449
|
+
if (hasToolResults) {
|
|
8450
|
+
if (lastContent.some((c) => c.type !== "tool_result")) {
|
|
8451
|
+
throw new Error("The last message must contain only tool_result content if any is present");
|
|
8452
|
+
}
|
|
8453
|
+
if (!hasPreviousToolUse) {
|
|
8454
|
+
throw new Error("tool_result blocks are not matching any tool_use from the previous message");
|
|
8455
|
+
}
|
|
8456
|
+
}
|
|
8457
|
+
if (hasPreviousToolUse) {
|
|
8458
|
+
const toolUseIds = new Set(previousContent.filter((c) => c.type === "tool_use").map((c) => c.id));
|
|
8459
|
+
const toolResultIds = new Set(lastContent.filter((c) => c.type === "tool_result").map((c) => c.toolUseId));
|
|
8460
|
+
if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((id) => toolResultIds.has(id))) {
|
|
8461
|
+
throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match");
|
|
8462
|
+
}
|
|
8463
|
+
}
|
|
8464
|
+
}
|
|
8465
|
+
return this.requestStream({
|
|
8466
|
+
method: "sampling/createMessage",
|
|
8467
|
+
params
|
|
8468
|
+
}, CreateMessageResultSchema, options);
|
|
8469
|
+
}
|
|
8470
|
+
/**
|
|
8471
|
+
* Sends an elicitation request and returns an AsyncGenerator that yields response messages.
|
|
8472
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
8473
|
+
*
|
|
8474
|
+
* For task-augmented requests (especially URL-based elicitation), yields 'taskCreated'
|
|
8475
|
+
* and 'taskStatus' messages before the final result.
|
|
8476
|
+
*
|
|
8477
|
+
* @example
|
|
8478
|
+
* ```typescript
|
|
8479
|
+
* const stream = server.experimental.tasks.elicitInputStream({
|
|
8480
|
+
* mode: 'url',
|
|
8481
|
+
* message: 'Please authenticate',
|
|
8482
|
+
* elicitationId: 'auth-123',
|
|
8483
|
+
* url: 'https://example.com/auth'
|
|
8484
|
+
* }, {
|
|
8485
|
+
* task: { ttl: 300000 } // Task-augmented for long-running auth flow
|
|
8486
|
+
* });
|
|
8487
|
+
*
|
|
8488
|
+
* for await (const message of stream) {
|
|
8489
|
+
* switch (message.type) {
|
|
8490
|
+
* case 'taskCreated':
|
|
8491
|
+
* console.log('Task created:', message.task.taskId);
|
|
8492
|
+
* break;
|
|
8493
|
+
* case 'taskStatus':
|
|
8494
|
+
* console.log('Task status:', message.task.status);
|
|
8495
|
+
* break;
|
|
8496
|
+
* case 'result':
|
|
8497
|
+
* console.log('User action:', message.result.action);
|
|
8498
|
+
* break;
|
|
8499
|
+
* case 'error':
|
|
8500
|
+
* console.error('Error:', message.error);
|
|
8501
|
+
* break;
|
|
8502
|
+
* }
|
|
8503
|
+
* }
|
|
8504
|
+
* ```
|
|
8505
|
+
*
|
|
8506
|
+
* @param params - The elicitation request parameters
|
|
8507
|
+
* @param options - Optional request options (timeout, signal, task creation params, etc.)
|
|
8508
|
+
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
8509
|
+
*
|
|
8510
|
+
* @experimental
|
|
8511
|
+
*/
|
|
8512
|
+
elicitInputStream(params, options) {
|
|
8513
|
+
const clientCapabilities = this._server.getClientCapabilities();
|
|
8514
|
+
const mode = params.mode ?? "form";
|
|
8515
|
+
switch (mode) {
|
|
8516
|
+
case "url": {
|
|
8517
|
+
if (!clientCapabilities?.elicitation?.url) {
|
|
8518
|
+
throw new Error("Client does not support url elicitation.");
|
|
8519
|
+
}
|
|
8520
|
+
break;
|
|
8521
|
+
}
|
|
8522
|
+
case "form": {
|
|
8523
|
+
if (!clientCapabilities?.elicitation?.form) {
|
|
8524
|
+
throw new Error("Client does not support form elicitation.");
|
|
8525
|
+
}
|
|
8526
|
+
break;
|
|
8527
|
+
}
|
|
8528
|
+
}
|
|
8529
|
+
const normalizedParams = mode === "form" && params.mode === void 0 ? { ...params, mode: "form" } : params;
|
|
8530
|
+
return this.requestStream({
|
|
8531
|
+
method: "elicitation/create",
|
|
8532
|
+
params: normalizedParams
|
|
8533
|
+
}, ElicitResultSchema, options);
|
|
8534
|
+
}
|
|
8178
8535
|
/**
|
|
8179
8536
|
* Gets the current status of a task.
|
|
8180
8537
|
*
|
|
@@ -9374,7 +9731,7 @@ var Client = class extends Protocol {
|
|
|
9374
9731
|
|
|
9375
9732
|
// __mcpc__cli_latest/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js
|
|
9376
9733
|
var import_cross_spawn = __toESM(require_cross_spawn(), 1);
|
|
9377
|
-
var
|
|
9734
|
+
var import_node_process5 = __toESM(require("node:process"), 1);
|
|
9378
9735
|
var import_node_stream = require("node:stream");
|
|
9379
9736
|
|
|
9380
9737
|
// __mcpc__cli_latest/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
|
|
@@ -9406,7 +9763,7 @@ function serializeMessage(message) {
|
|
|
9406
9763
|
}
|
|
9407
9764
|
|
|
9408
9765
|
// __mcpc__cli_latest/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js
|
|
9409
|
-
var DEFAULT_INHERITED_ENV_VARS =
|
|
9766
|
+
var DEFAULT_INHERITED_ENV_VARS = import_node_process5.default.platform === "win32" ? [
|
|
9410
9767
|
"APPDATA",
|
|
9411
9768
|
"HOMEDRIVE",
|
|
9412
9769
|
"HOMEPATH",
|
|
@@ -9426,7 +9783,7 @@ var DEFAULT_INHERITED_ENV_VARS = import_node_process4.default.platform === "win3
|
|
|
9426
9783
|
function getDefaultEnvironment() {
|
|
9427
9784
|
const env = {};
|
|
9428
9785
|
for (const key of DEFAULT_INHERITED_ENV_VARS) {
|
|
9429
|
-
const value =
|
|
9786
|
+
const value = import_node_process5.default.env[key];
|
|
9430
9787
|
if (value === void 0) {
|
|
9431
9788
|
continue;
|
|
9432
9789
|
}
|
|
@@ -9462,7 +9819,7 @@ var StdioClientTransport = class {
|
|
|
9462
9819
|
},
|
|
9463
9820
|
stdio: ["pipe", "pipe", this._serverParams.stderr ?? "inherit"],
|
|
9464
9821
|
shell: false,
|
|
9465
|
-
windowsHide:
|
|
9822
|
+
windowsHide: import_node_process5.default.platform === "win32" && isElectron(),
|
|
9466
9823
|
cwd: this._serverParams.cwd
|
|
9467
9824
|
});
|
|
9468
9825
|
this._process.on("error", (error) => {
|
|
@@ -9570,7 +9927,7 @@ var StdioClientTransport = class {
|
|
|
9570
9927
|
}
|
|
9571
9928
|
};
|
|
9572
9929
|
function isElectron() {
|
|
9573
|
-
return "type" in
|
|
9930
|
+
return "type" in import_node_process5.default;
|
|
9574
9931
|
}
|
|
9575
9932
|
|
|
9576
9933
|
// __mcpc__cli_latest/node_modules/eventsource-parser/dist/index.js
|
|
@@ -10393,22 +10750,45 @@ async function auth(provider, options) {
|
|
|
10393
10750
|
}
|
|
10394
10751
|
}
|
|
10395
10752
|
async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
|
|
10753
|
+
const cachedState = await provider.discoveryState?.();
|
|
10396
10754
|
let resourceMetadata;
|
|
10397
10755
|
let authorizationServerUrl;
|
|
10398
|
-
|
|
10399
|
-
|
|
10400
|
-
|
|
10401
|
-
|
|
10756
|
+
let metadata;
|
|
10757
|
+
let effectiveResourceMetadataUrl = resourceMetadataUrl;
|
|
10758
|
+
if (!effectiveResourceMetadataUrl && cachedState?.resourceMetadataUrl) {
|
|
10759
|
+
effectiveResourceMetadataUrl = new URL(cachedState.resourceMetadataUrl);
|
|
10760
|
+
}
|
|
10761
|
+
if (cachedState?.authorizationServerUrl) {
|
|
10762
|
+
authorizationServerUrl = cachedState.authorizationServerUrl;
|
|
10763
|
+
resourceMetadata = cachedState.resourceMetadata;
|
|
10764
|
+
metadata = cachedState.authorizationServerMetadata ?? await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn });
|
|
10765
|
+
if (!resourceMetadata) {
|
|
10766
|
+
try {
|
|
10767
|
+
resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl }, fetchFn);
|
|
10768
|
+
} catch {
|
|
10769
|
+
}
|
|
10402
10770
|
}
|
|
10403
|
-
|
|
10404
|
-
|
|
10405
|
-
|
|
10406
|
-
|
|
10771
|
+
if (metadata !== cachedState.authorizationServerMetadata || resourceMetadata !== cachedState.resourceMetadata) {
|
|
10772
|
+
await provider.saveDiscoveryState?.({
|
|
10773
|
+
authorizationServerUrl: String(authorizationServerUrl),
|
|
10774
|
+
resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
|
|
10775
|
+
resourceMetadata,
|
|
10776
|
+
authorizationServerMetadata: metadata
|
|
10777
|
+
});
|
|
10778
|
+
}
|
|
10779
|
+
} else {
|
|
10780
|
+
const serverInfo = await discoverOAuthServerInfo(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl, fetchFn });
|
|
10781
|
+
authorizationServerUrl = serverInfo.authorizationServerUrl;
|
|
10782
|
+
metadata = serverInfo.authorizationServerMetadata;
|
|
10783
|
+
resourceMetadata = serverInfo.resourceMetadata;
|
|
10784
|
+
await provider.saveDiscoveryState?.({
|
|
10785
|
+
authorizationServerUrl: String(authorizationServerUrl),
|
|
10786
|
+
resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
|
|
10787
|
+
resourceMetadata,
|
|
10788
|
+
authorizationServerMetadata: metadata
|
|
10789
|
+
});
|
|
10407
10790
|
}
|
|
10408
10791
|
const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
|
|
10409
|
-
const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, {
|
|
10410
|
-
fetchFn
|
|
10411
|
-
});
|
|
10412
10792
|
let clientInformation = await Promise.resolve(provider.clientInformation());
|
|
10413
10793
|
if (!clientInformation) {
|
|
10414
10794
|
if (authorizationCode !== void 0) {
|
|
@@ -10663,6 +11043,26 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
|
|
|
10663
11043
|
}
|
|
10664
11044
|
return void 0;
|
|
10665
11045
|
}
|
|
11046
|
+
async function discoverOAuthServerInfo(serverUrl, opts) {
|
|
11047
|
+
let resourceMetadata;
|
|
11048
|
+
let authorizationServerUrl;
|
|
11049
|
+
try {
|
|
11050
|
+
resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: opts?.resourceMetadataUrl }, opts?.fetchFn);
|
|
11051
|
+
if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
|
|
11052
|
+
authorizationServerUrl = resourceMetadata.authorization_servers[0];
|
|
11053
|
+
}
|
|
11054
|
+
} catch {
|
|
11055
|
+
}
|
|
11056
|
+
if (!authorizationServerUrl) {
|
|
11057
|
+
authorizationServerUrl = String(new URL("/", serverUrl));
|
|
11058
|
+
}
|
|
11059
|
+
const authorizationServerMetadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn: opts?.fetchFn });
|
|
11060
|
+
return {
|
|
11061
|
+
authorizationServerUrl,
|
|
11062
|
+
authorizationServerMetadata,
|
|
11063
|
+
resourceMetadata
|
|
11064
|
+
};
|
|
11065
|
+
}
|
|
10666
11066
|
async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
|
|
10667
11067
|
let authorizationUrl;
|
|
10668
11068
|
if (metadata) {
|
|
@@ -11451,8 +11851,8 @@ var InMemoryTransport = class _InMemoryTransport {
|
|
|
11451
11851
|
};
|
|
11452
11852
|
|
|
11453
11853
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/utils/common/config.js
|
|
11454
|
-
var
|
|
11455
|
-
var GEMINI_PREFERRED_FORMAT =
|
|
11854
|
+
var import_node_process6 = __toESM(require("node:process"), 1);
|
|
11855
|
+
var GEMINI_PREFERRED_FORMAT = import_node_process6.default.env.GEMINI_PREFERRED_FORMAT === "0" ? false : true;
|
|
11456
11856
|
|
|
11457
11857
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/utils/common/json.js
|
|
11458
11858
|
var import_jsonrepair2 = require("jsonrepair");
|
|
@@ -11524,21 +11924,9 @@ var cleanToolSchema = (schema) => {
|
|
|
11524
11924
|
};
|
|
11525
11925
|
|
|
11526
11926
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/utils/common/mcp.js
|
|
11527
|
-
var
|
|
11528
|
-
var
|
|
11927
|
+
var import_node_process7 = require("node:process");
|
|
11928
|
+
var import_node_process8 = __toESM(require("node:process"), 1);
|
|
11529
11929
|
var import_node_crypto = require("node:crypto");
|
|
11530
|
-
var mcpClientPool = /* @__PURE__ */ new Map();
|
|
11531
|
-
var mcpClientConnecting = /* @__PURE__ */ new Map();
|
|
11532
|
-
var shortHash = (s) => (0, import_node_crypto.createHash)("sha256").update(s).digest("hex").slice(0, 8);
|
|
11533
|
-
function defSignature(def) {
|
|
11534
|
-
const defCopy = {
|
|
11535
|
-
...def
|
|
11536
|
-
};
|
|
11537
|
-
if (defCopy.transportType === "memory" || defCopy.transport) {
|
|
11538
|
-
return `memory:${Date.now()}:${Math.random()}`;
|
|
11539
|
-
}
|
|
11540
|
-
return JSON.stringify(defCopy);
|
|
11541
|
-
}
|
|
11542
11930
|
function createTransport(def) {
|
|
11543
11931
|
const defAny = def;
|
|
11544
11932
|
const explicitType = defAny.transportType || defAny.type;
|
|
@@ -11578,98 +11966,51 @@ function createTransport(def) {
|
|
|
11578
11966
|
command: defAny.command,
|
|
11579
11967
|
args: defAny.args,
|
|
11580
11968
|
env: {
|
|
11581
|
-
...
|
|
11969
|
+
...import_node_process8.default.env,
|
|
11582
11970
|
...defAny.env ?? {}
|
|
11583
11971
|
},
|
|
11584
|
-
cwd: (0,
|
|
11972
|
+
cwd: (0, import_node_process7.cwd)()
|
|
11585
11973
|
});
|
|
11586
11974
|
}
|
|
11587
11975
|
throw new Error(`Unsupported transport configuration: ${JSON.stringify(def)}`);
|
|
11588
11976
|
}
|
|
11589
|
-
|
|
11590
|
-
const
|
|
11591
|
-
|
|
11592
|
-
|
|
11593
|
-
|
|
11594
|
-
|
|
11595
|
-
const existingConnecting = mcpClientConnecting.get(defKey);
|
|
11596
|
-
if (existingConnecting) {
|
|
11597
|
-
const client = await existingConnecting;
|
|
11598
|
-
const entry = mcpClientPool.get(defKey);
|
|
11599
|
-
if (entry) entry.refCount += 1;
|
|
11600
|
-
return client;
|
|
11601
|
-
}
|
|
11602
|
-
const transport = createTransport(def);
|
|
11603
|
-
const connecting = (async () => {
|
|
11604
|
-
const client = new Client({
|
|
11605
|
-
name: `mcp_${shortHash(defSignature(def))}`,
|
|
11606
|
-
version: "1.0.0"
|
|
11607
|
-
});
|
|
11608
|
-
await client.connect(transport, {
|
|
11609
|
-
timeout: 6e4 * 10
|
|
11610
|
-
});
|
|
11611
|
-
return client;
|
|
11612
|
-
})();
|
|
11613
|
-
mcpClientConnecting.set(defKey, connecting);
|
|
11614
|
-
try {
|
|
11615
|
-
const client = await connecting;
|
|
11616
|
-
mcpClientPool.set(defKey, {
|
|
11617
|
-
client,
|
|
11618
|
-
refCount: 1
|
|
11619
|
-
});
|
|
11620
|
-
return client;
|
|
11621
|
-
} finally {
|
|
11622
|
-
mcpClientConnecting.delete(defKey);
|
|
11977
|
+
function defSignature(def) {
|
|
11978
|
+
const defCopy = {
|
|
11979
|
+
...def
|
|
11980
|
+
};
|
|
11981
|
+
if (defCopy.transportType === "memory" || defCopy.transport) {
|
|
11982
|
+
return `memory:${Date.now()}:${Math.random()}`;
|
|
11623
11983
|
}
|
|
11984
|
+
return JSON.stringify(defCopy);
|
|
11624
11985
|
}
|
|
11625
|
-
|
|
11626
|
-
|
|
11627
|
-
|
|
11628
|
-
|
|
11629
|
-
|
|
11630
|
-
|
|
11631
|
-
|
|
11632
|
-
|
|
11633
|
-
|
|
11634
|
-
|
|
11635
|
-
|
|
11636
|
-
}
|
|
11986
|
+
var shortHash = (s) => (0, import_node_crypto.createHash)("sha256").update(s).digest("hex").slice(0, 8);
|
|
11987
|
+
async function createMcpClient(def) {
|
|
11988
|
+
const transport = createTransport(def);
|
|
11989
|
+
const client = new Client({
|
|
11990
|
+
name: `mcp_${shortHash(defSignature(def))}`,
|
|
11991
|
+
version: "1.0.0"
|
|
11992
|
+
});
|
|
11993
|
+
await client.connect(transport, {
|
|
11994
|
+
timeout: 6e4 * 10
|
|
11995
|
+
});
|
|
11996
|
+
return client;
|
|
11637
11997
|
}
|
|
11638
|
-
var cleanupAllPooledClients = async () => {
|
|
11639
|
-
const entries = Array.from(mcpClientPool.entries());
|
|
11640
|
-
mcpClientPool.clear();
|
|
11641
|
-
await Promise.all(entries.map(async ([, { client }]) => {
|
|
11642
|
-
try {
|
|
11643
|
-
await client.close();
|
|
11644
|
-
} catch (err) {
|
|
11645
|
-
console.error("Error closing MCP client:", err);
|
|
11646
|
-
}
|
|
11647
|
-
}));
|
|
11648
|
-
};
|
|
11649
|
-
import_node_process7.default.once?.("exit", () => {
|
|
11650
|
-
cleanupAllPooledClients();
|
|
11651
|
-
});
|
|
11652
|
-
import_node_process7.default.once?.("SIGINT", () => {
|
|
11653
|
-
cleanupAllPooledClients().finally(() => import_node_process7.default.exit(0));
|
|
11654
|
-
});
|
|
11655
11998
|
async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
11656
11999
|
const allTools = {};
|
|
11657
12000
|
const allClients = {};
|
|
11658
|
-
const
|
|
12001
|
+
const clientsToClose = [];
|
|
11659
12002
|
for (const [name, definition] of Object.entries(mcpConfig.mcpServers)) {
|
|
11660
12003
|
const def = definition;
|
|
11661
12004
|
if (def.disabled) continue;
|
|
11662
|
-
const defKey = shortHash(defSignature(def));
|
|
11663
|
-
const serverId = name;
|
|
11664
12005
|
try {
|
|
11665
|
-
const client = await
|
|
11666
|
-
|
|
11667
|
-
allClients[
|
|
12006
|
+
const client = await createMcpClient(def);
|
|
12007
|
+
clientsToClose.push(client);
|
|
12008
|
+
allClients[name] = client;
|
|
11668
12009
|
const { tools } = await client.listTools();
|
|
11669
12010
|
tools.forEach((tool2) => {
|
|
11670
12011
|
const toolNameWithScope = `${name}.${tool2.name}`;
|
|
11671
12012
|
const internalToolName = tool2.name;
|
|
11672
|
-
const rawToolId = `${
|
|
12013
|
+
const rawToolId = `${name}_${internalToolName}`;
|
|
11673
12014
|
const toolId = sanitizePropertyKey(rawToolId);
|
|
11674
12015
|
if (filterIn && !filterIn({
|
|
11675
12016
|
action: internalToolName,
|
|
@@ -11681,7 +12022,7 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
|
11681
12022
|
})) {
|
|
11682
12023
|
return;
|
|
11683
12024
|
}
|
|
11684
|
-
const execute = (args) => allClients[
|
|
12025
|
+
const execute = (args) => allClients[name].callTool({
|
|
11685
12026
|
name: internalToolName,
|
|
11686
12027
|
arguments: args
|
|
11687
12028
|
}, void 0, {
|
|
@@ -11698,10 +12039,12 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
|
11698
12039
|
}
|
|
11699
12040
|
}
|
|
11700
12041
|
const cleanupClients = async () => {
|
|
11701
|
-
await Promise.all(
|
|
11702
|
-
|
|
11703
|
-
|
|
11704
|
-
|
|
12042
|
+
await Promise.all(clientsToClose.map((client) => {
|
|
12043
|
+
try {
|
|
12044
|
+
return client.close();
|
|
12045
|
+
} catch {
|
|
12046
|
+
}
|
|
12047
|
+
}));
|
|
11705
12048
|
};
|
|
11706
12049
|
return {
|
|
11707
12050
|
tools: allTools,
|
|
@@ -12273,7 +12616,7 @@ function endSpan(span, error) {
|
|
|
12273
12616
|
}
|
|
12274
12617
|
|
|
12275
12618
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/executors/agentic/agentic-executor.js
|
|
12276
|
-
var
|
|
12619
|
+
var import_node_process9 = __toESM(require("node:process"), 1);
|
|
12277
12620
|
var AgenticExecutor = class {
|
|
12278
12621
|
name;
|
|
12279
12622
|
allToolNames;
|
|
@@ -12293,13 +12636,13 @@ var AgenticExecutor = class {
|
|
|
12293
12636
|
this.logger = createLogger(`mcpc.agentic.${name}`, server);
|
|
12294
12637
|
this.toolSchemaMap = new Map(toolNameToDetailList);
|
|
12295
12638
|
try {
|
|
12296
|
-
this.tracingEnabled =
|
|
12639
|
+
this.tracingEnabled = import_node_process9.default.env.MCPC_TRACING_ENABLED === "true";
|
|
12297
12640
|
if (this.tracingEnabled) {
|
|
12298
12641
|
initializeTracing({
|
|
12299
12642
|
enabled: true,
|
|
12300
12643
|
serviceName: `mcpc-agentic-${name}`,
|
|
12301
|
-
exportTo:
|
|
12302
|
-
otlpEndpoint:
|
|
12644
|
+
exportTo: import_node_process9.default.env.MCPC_TRACING_EXPORT ?? "otlp",
|
|
12645
|
+
otlpEndpoint: import_node_process9.default.env.MCPC_TRACING_OTLP_ENDPOINT ?? "http://localhost:4318/v1/traces"
|
|
12303
12646
|
});
|
|
12304
12647
|
}
|
|
12305
12648
|
} catch {
|
|
@@ -15014,12 +15357,12 @@ var ComposableMCPServer = class extends Server {
|
|
|
15014
15357
|
};
|
|
15015
15358
|
|
|
15016
15359
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/utils/common/env.js
|
|
15017
|
-
var
|
|
15018
|
-
var isSCF = () => Boolean(
|
|
15360
|
+
var import_node_process10 = __toESM(require("node:process"), 1);
|
|
15361
|
+
var isSCF = () => Boolean(import_node_process10.default.env.SCF_RUNTIME || import_node_process10.default.env.PROD_SCF);
|
|
15019
15362
|
if (isSCF()) {
|
|
15020
15363
|
console.log({
|
|
15021
15364
|
isSCF: isSCF(),
|
|
15022
|
-
SCF_RUNTIME:
|
|
15365
|
+
SCF_RUNTIME: import_node_process10.default.env.SCF_RUNTIME
|
|
15023
15366
|
});
|
|
15024
15367
|
}
|
|
15025
15368
|
|
|
@@ -15102,8 +15445,8 @@ var createApp = (config) => {
|
|
|
15102
15445
|
|
|
15103
15446
|
// __mcpc__cli_latest/node_modules/@mcpc/cli/src/server.js
|
|
15104
15447
|
var import_zod_openapi4 = require("@hono/zod-openapi");
|
|
15105
|
-
var
|
|
15106
|
-
var port = Number(
|
|
15448
|
+
var import_node_process11 = __toESM(require("node:process"), 1);
|
|
15449
|
+
var port = Number(import_node_process11.default.env.PORT || "3002");
|
|
15107
15450
|
var hostname = "0.0.0.0";
|
|
15108
15451
|
async function main() {
|
|
15109
15452
|
const config = await loadConfig();
|