@mcpc-tech/cli 0.1.50 → 0.1.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.cjs +463 -267
- package/app.mjs +463 -267
- package/bin/mcpc.cjs +443 -265
- package/bin/mcpc.mjs +443 -265
- package/bin.cjs +443 -265
- package/bin.mjs +443 -265
- package/index.cjs +463 -267
- package/index.mjs +463 -267
- package/package.json +1 -1
- package/server.cjs +463 -267
- package/server.mjs +463 -267
package/server.cjs
CHANGED
|
@@ -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) {
|
|
@@ -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
|
};
|
|
@@ -5241,12 +5274,29 @@ function writeFoldedLines(count) {
|
|
|
5241
5274
|
if (count > 1) return "\n".repeat(count - 1);
|
|
5242
5275
|
return "";
|
|
5243
5276
|
}
|
|
5277
|
+
var Scanner = class {
|
|
5278
|
+
source;
|
|
5279
|
+
#length;
|
|
5280
|
+
position = 0;
|
|
5281
|
+
constructor(source) {
|
|
5282
|
+
source += "\0";
|
|
5283
|
+
this.source = source;
|
|
5284
|
+
this.#length = source.length;
|
|
5285
|
+
}
|
|
5286
|
+
peek(offset = 0) {
|
|
5287
|
+
return this.source.charCodeAt(this.position + offset);
|
|
5288
|
+
}
|
|
5289
|
+
next() {
|
|
5290
|
+
this.position += 1;
|
|
5291
|
+
}
|
|
5292
|
+
eof() {
|
|
5293
|
+
return this.position >= this.#length - 1;
|
|
5294
|
+
}
|
|
5295
|
+
};
|
|
5244
5296
|
var LoaderState = class {
|
|
5245
|
-
|
|
5246
|
-
length;
|
|
5297
|
+
#scanner;
|
|
5247
5298
|
lineIndent = 0;
|
|
5248
5299
|
lineStart = 0;
|
|
5249
|
-
position = 0;
|
|
5250
5300
|
line = 0;
|
|
5251
5301
|
onWarning;
|
|
5252
5302
|
allowDuplicateKeys;
|
|
@@ -5256,44 +5306,40 @@ var LoaderState = class {
|
|
|
5256
5306
|
tagMap = /* @__PURE__ */ new Map();
|
|
5257
5307
|
anchorMap = /* @__PURE__ */ new Map();
|
|
5258
5308
|
constructor(input, { schema = DEFAULT_SCHEMA, onWarning, allowDuplicateKeys = false }) {
|
|
5259
|
-
this
|
|
5309
|
+
this.#scanner = new Scanner(input);
|
|
5260
5310
|
this.onWarning = onWarning;
|
|
5261
5311
|
this.allowDuplicateKeys = allowDuplicateKeys;
|
|
5262
5312
|
this.implicitTypes = schema.implicitTypes;
|
|
5263
5313
|
this.typeMap = schema.typeMap;
|
|
5264
|
-
this.length = input.length;
|
|
5265
5314
|
this.readIndent();
|
|
5266
5315
|
}
|
|
5267
5316
|
skipWhitespaces() {
|
|
5268
|
-
let ch = this.peek();
|
|
5317
|
+
let ch = this.#scanner.peek();
|
|
5269
5318
|
while (isWhiteSpace(ch)) {
|
|
5270
|
-
|
|
5319
|
+
this.#scanner.next();
|
|
5320
|
+
ch = this.#scanner.peek();
|
|
5271
5321
|
}
|
|
5272
5322
|
}
|
|
5273
5323
|
skipComment() {
|
|
5274
|
-
let ch = this.peek();
|
|
5324
|
+
let ch = this.#scanner.peek();
|
|
5275
5325
|
if (ch !== SHARP) return;
|
|
5276
|
-
|
|
5326
|
+
this.#scanner.next();
|
|
5327
|
+
ch = this.#scanner.peek();
|
|
5277
5328
|
while (ch !== 0 && !isEOL(ch)) {
|
|
5278
|
-
|
|
5329
|
+
this.#scanner.next();
|
|
5330
|
+
ch = this.#scanner.peek();
|
|
5279
5331
|
}
|
|
5280
5332
|
}
|
|
5281
5333
|
readIndent() {
|
|
5282
|
-
let
|
|
5283
|
-
while (
|
|
5334
|
+
let ch = this.#scanner.peek();
|
|
5335
|
+
while (ch === SPACE) {
|
|
5284
5336
|
this.lineIndent += 1;
|
|
5285
|
-
|
|
5337
|
+
this.#scanner.next();
|
|
5338
|
+
ch = this.#scanner.peek();
|
|
5286
5339
|
}
|
|
5287
5340
|
}
|
|
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
5341
|
#createError(message) {
|
|
5296
|
-
const mark = markToString(this.
|
|
5342
|
+
const mark = markToString(this.#scanner.source, this.#scanner.position, this.line, this.#scanner.position - this.lineStart);
|
|
5297
5343
|
return new SyntaxError(`${message} ${mark}`);
|
|
5298
5344
|
}
|
|
5299
5345
|
dispatchWarning(message) {
|
|
@@ -5338,7 +5384,7 @@ var LoaderState = class {
|
|
|
5338
5384
|
}
|
|
5339
5385
|
captureSegment(start, end, checkJson) {
|
|
5340
5386
|
if (start < end) {
|
|
5341
|
-
const result = this.
|
|
5387
|
+
const result = this.#scanner.source.slice(start, end);
|
|
5342
5388
|
if (checkJson) {
|
|
5343
5389
|
for (let position = 0; position < result.length; position++) {
|
|
5344
5390
|
const character = result.charCodeAt(position);
|
|
@@ -5356,21 +5402,21 @@ var LoaderState = class {
|
|
|
5356
5402
|
let detected = false;
|
|
5357
5403
|
const result = [];
|
|
5358
5404
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
5359
|
-
let ch = this.peek();
|
|
5405
|
+
let ch = this.#scanner.peek();
|
|
5360
5406
|
while (ch !== 0) {
|
|
5361
5407
|
if (ch !== MINUS) {
|
|
5362
5408
|
break;
|
|
5363
5409
|
}
|
|
5364
|
-
const following = this.peek(1);
|
|
5410
|
+
const following = this.#scanner.peek(1);
|
|
5365
5411
|
if (!isWhiteSpaceOrEOL(following)) {
|
|
5366
5412
|
break;
|
|
5367
5413
|
}
|
|
5368
5414
|
detected = true;
|
|
5369
|
-
this.
|
|
5415
|
+
this.#scanner.next();
|
|
5370
5416
|
if (this.skipSeparationSpace(true, -1)) {
|
|
5371
5417
|
if (this.lineIndent <= nodeIndent) {
|
|
5372
5418
|
result.push(null);
|
|
5373
|
-
ch = this.peek();
|
|
5419
|
+
ch = this.#scanner.peek();
|
|
5374
5420
|
continue;
|
|
5375
5421
|
}
|
|
5376
5422
|
}
|
|
@@ -5383,7 +5429,7 @@ var LoaderState = class {
|
|
|
5383
5429
|
});
|
|
5384
5430
|
if (newState) result.push(newState.result);
|
|
5385
5431
|
this.skipSeparationSpace(true, -1);
|
|
5386
|
-
ch = this.peek();
|
|
5432
|
+
ch = this.#scanner.peek();
|
|
5387
5433
|
if ((this.line === line || this.lineIndent > nodeIndent) && ch !== 0) {
|
|
5388
5434
|
throw this.#createError("Cannot read block sequence: bad indentation of a sequence entry");
|
|
5389
5435
|
} else if (this.lineIndent < nodeIndent) {
|
|
@@ -5439,7 +5485,7 @@ var LoaderState = class {
|
|
|
5439
5485
|
} else {
|
|
5440
5486
|
if (!this.allowDuplicateKeys && !overridableKeys.has(keyNode) && Object.hasOwn(result, keyNode)) {
|
|
5441
5487
|
this.line = startLine || this.line;
|
|
5442
|
-
this.position = startPos || this.position;
|
|
5488
|
+
this.#scanner.position = startPos || this.#scanner.position;
|
|
5443
5489
|
throw this.#createError("Cannot store mapping pair: duplicated key");
|
|
5444
5490
|
}
|
|
5445
5491
|
Object.defineProperty(result, keyNode, {
|
|
@@ -5453,37 +5499,37 @@ var LoaderState = class {
|
|
|
5453
5499
|
return result;
|
|
5454
5500
|
}
|
|
5455
5501
|
readLineBreak() {
|
|
5456
|
-
const ch = this.peek();
|
|
5502
|
+
const ch = this.#scanner.peek();
|
|
5457
5503
|
if (ch === LINE_FEED) {
|
|
5458
|
-
this.
|
|
5504
|
+
this.#scanner.next();
|
|
5459
5505
|
} else if (ch === CARRIAGE_RETURN) {
|
|
5460
|
-
this.
|
|
5461
|
-
if (this.peek() === LINE_FEED) {
|
|
5462
|
-
this.
|
|
5506
|
+
this.#scanner.next();
|
|
5507
|
+
if (this.#scanner.peek() === LINE_FEED) {
|
|
5508
|
+
this.#scanner.next();
|
|
5463
5509
|
}
|
|
5464
5510
|
} else {
|
|
5465
5511
|
throw this.#createError("Cannot read line: line break not found");
|
|
5466
5512
|
}
|
|
5467
5513
|
this.line += 1;
|
|
5468
|
-
this.lineStart = this.position;
|
|
5514
|
+
this.lineStart = this.#scanner.position;
|
|
5469
5515
|
}
|
|
5470
5516
|
skipSeparationSpace(allowComments, checkIndent) {
|
|
5471
5517
|
let lineBreaks = 0;
|
|
5472
|
-
let ch = this.peek();
|
|
5518
|
+
let ch = this.#scanner.peek();
|
|
5473
5519
|
while (ch !== 0) {
|
|
5474
5520
|
this.skipWhitespaces();
|
|
5475
|
-
ch = this.peek();
|
|
5521
|
+
ch = this.#scanner.peek();
|
|
5476
5522
|
if (allowComments) {
|
|
5477
5523
|
this.skipComment();
|
|
5478
|
-
ch = this.peek();
|
|
5524
|
+
ch = this.#scanner.peek();
|
|
5479
5525
|
}
|
|
5480
5526
|
if (isEOL(ch)) {
|
|
5481
5527
|
this.readLineBreak();
|
|
5482
|
-
ch = this.peek();
|
|
5528
|
+
ch = this.#scanner.peek();
|
|
5483
5529
|
lineBreaks++;
|
|
5484
5530
|
this.lineIndent = 0;
|
|
5485
5531
|
this.readIndent();
|
|
5486
|
-
ch = this.peek();
|
|
5532
|
+
ch = this.#scanner.peek();
|
|
5487
5533
|
} else {
|
|
5488
5534
|
break;
|
|
5489
5535
|
}
|
|
@@ -5494,9 +5540,9 @@ var LoaderState = class {
|
|
|
5494
5540
|
return lineBreaks;
|
|
5495
5541
|
}
|
|
5496
5542
|
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);
|
|
5543
|
+
let ch = this.#scanner.peek();
|
|
5544
|
+
if ((ch === MINUS || ch === DOT) && ch === this.#scanner.peek(1) && ch === this.#scanner.peek(2)) {
|
|
5545
|
+
ch = this.#scanner.peek(3);
|
|
5500
5546
|
if (ch === 0 || isWhiteSpaceOrEOL(ch)) {
|
|
5501
5547
|
return true;
|
|
5502
5548
|
}
|
|
@@ -5504,34 +5550,34 @@ var LoaderState = class {
|
|
|
5504
5550
|
return false;
|
|
5505
5551
|
}
|
|
5506
5552
|
readPlainScalar(tag, anchor, nodeIndent, withinFlowCollection) {
|
|
5507
|
-
let ch = this.peek();
|
|
5553
|
+
let ch = this.#scanner.peek();
|
|
5508
5554
|
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
5555
|
return;
|
|
5510
5556
|
}
|
|
5511
5557
|
let following;
|
|
5512
5558
|
if (ch === QUESTION || ch === MINUS) {
|
|
5513
|
-
following = this.peek(1);
|
|
5559
|
+
following = this.#scanner.peek(1);
|
|
5514
5560
|
if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
|
|
5515
5561
|
return;
|
|
5516
5562
|
}
|
|
5517
5563
|
}
|
|
5518
5564
|
let result = "";
|
|
5519
|
-
let captureEnd = this.position;
|
|
5520
|
-
let captureStart = this.position;
|
|
5565
|
+
let captureEnd = this.#scanner.position;
|
|
5566
|
+
let captureStart = this.#scanner.position;
|
|
5521
5567
|
let hasPendingContent = false;
|
|
5522
5568
|
let line = 0;
|
|
5523
5569
|
while (ch !== 0) {
|
|
5524
5570
|
if (ch === COLON) {
|
|
5525
|
-
following = this.peek(1);
|
|
5571
|
+
following = this.#scanner.peek(1);
|
|
5526
5572
|
if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
|
|
5527
5573
|
break;
|
|
5528
5574
|
}
|
|
5529
5575
|
} else if (ch === SHARP) {
|
|
5530
|
-
const preceding = this.peek(-1);
|
|
5576
|
+
const preceding = this.#scanner.peek(-1);
|
|
5531
5577
|
if (isWhiteSpaceOrEOL(preceding)) {
|
|
5532
5578
|
break;
|
|
5533
5579
|
}
|
|
5534
|
-
} else if (this.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
|
|
5580
|
+
} else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
|
|
5535
5581
|
break;
|
|
5536
5582
|
} else if (isEOL(ch)) {
|
|
5537
5583
|
line = this.line;
|
|
@@ -5540,10 +5586,10 @@ var LoaderState = class {
|
|
|
5540
5586
|
this.skipSeparationSpace(false, -1);
|
|
5541
5587
|
if (this.lineIndent >= nodeIndent) {
|
|
5542
5588
|
hasPendingContent = true;
|
|
5543
|
-
ch = this.peek();
|
|
5589
|
+
ch = this.#scanner.peek();
|
|
5544
5590
|
continue;
|
|
5545
5591
|
} else {
|
|
5546
|
-
this.position = captureEnd;
|
|
5592
|
+
this.#scanner.position = captureEnd;
|
|
5547
5593
|
this.line = line;
|
|
5548
5594
|
this.lineStart = lineStart;
|
|
5549
5595
|
this.lineIndent = lineIndent;
|
|
@@ -5554,13 +5600,14 @@ var LoaderState = class {
|
|
|
5554
5600
|
const segment2 = this.captureSegment(captureStart, captureEnd, false);
|
|
5555
5601
|
if (segment2) result += segment2;
|
|
5556
5602
|
result += writeFoldedLines(this.line - line);
|
|
5557
|
-
captureStart = captureEnd = this.position;
|
|
5603
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
5558
5604
|
hasPendingContent = false;
|
|
5559
5605
|
}
|
|
5560
5606
|
if (!isWhiteSpace(ch)) {
|
|
5561
|
-
captureEnd = this.position + 1;
|
|
5607
|
+
captureEnd = this.#scanner.position + 1;
|
|
5562
5608
|
}
|
|
5563
|
-
|
|
5609
|
+
this.#scanner.next();
|
|
5610
|
+
ch = this.#scanner.peek();
|
|
5564
5611
|
}
|
|
5565
5612
|
const segment = this.captureSegment(captureStart, captureEnd, false);
|
|
5566
5613
|
if (segment) result += segment;
|
|
@@ -5573,22 +5620,23 @@ var LoaderState = class {
|
|
|
5573
5620
|
};
|
|
5574
5621
|
}
|
|
5575
5622
|
readSingleQuotedScalar(tag, anchor, nodeIndent) {
|
|
5576
|
-
let ch = this.peek();
|
|
5623
|
+
let ch = this.#scanner.peek();
|
|
5577
5624
|
if (ch !== SINGLE_QUOTE) return;
|
|
5578
5625
|
let result = "";
|
|
5579
|
-
this.
|
|
5580
|
-
let captureStart = this.position;
|
|
5581
|
-
let captureEnd = this.position;
|
|
5582
|
-
ch = this.peek();
|
|
5626
|
+
this.#scanner.next();
|
|
5627
|
+
let captureStart = this.#scanner.position;
|
|
5628
|
+
let captureEnd = this.#scanner.position;
|
|
5629
|
+
ch = this.#scanner.peek();
|
|
5583
5630
|
while (ch !== 0) {
|
|
5584
5631
|
if (ch === SINGLE_QUOTE) {
|
|
5585
|
-
const segment = this.captureSegment(captureStart, this.position, true);
|
|
5632
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, true);
|
|
5586
5633
|
if (segment) result += segment;
|
|
5587
|
-
|
|
5634
|
+
this.#scanner.next();
|
|
5635
|
+
ch = this.#scanner.peek();
|
|
5588
5636
|
if (ch === SINGLE_QUOTE) {
|
|
5589
|
-
captureStart = this.position;
|
|
5590
|
-
this.
|
|
5591
|
-
captureEnd = this.position;
|
|
5637
|
+
captureStart = this.#scanner.position;
|
|
5638
|
+
this.#scanner.next();
|
|
5639
|
+
captureEnd = this.#scanner.position;
|
|
5592
5640
|
} else {
|
|
5593
5641
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
5594
5642
|
return {
|
|
@@ -5602,31 +5650,31 @@ var LoaderState = class {
|
|
|
5602
5650
|
const segment = this.captureSegment(captureStart, captureEnd, true);
|
|
5603
5651
|
if (segment) result += segment;
|
|
5604
5652
|
result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
|
|
5605
|
-
captureStart = captureEnd = this.position;
|
|
5606
|
-
} else if (this.position === this.lineStart && this.testDocumentSeparator()) {
|
|
5653
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
5654
|
+
} else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
|
|
5607
5655
|
throw this.#createError("Unexpected end of the document within a single quoted scalar");
|
|
5608
5656
|
} else {
|
|
5609
|
-
this.
|
|
5610
|
-
captureEnd = this.position;
|
|
5657
|
+
this.#scanner.next();
|
|
5658
|
+
captureEnd = this.#scanner.position;
|
|
5611
5659
|
}
|
|
5612
|
-
ch = this.peek();
|
|
5660
|
+
ch = this.#scanner.peek();
|
|
5613
5661
|
}
|
|
5614
5662
|
throw this.#createError("Unexpected end of the stream within a single quoted scalar");
|
|
5615
5663
|
}
|
|
5616
5664
|
readDoubleQuotedScalar(tag, anchor, nodeIndent) {
|
|
5617
|
-
let ch = this.peek();
|
|
5665
|
+
let ch = this.#scanner.peek();
|
|
5618
5666
|
if (ch !== DOUBLE_QUOTE) return;
|
|
5619
5667
|
let result = "";
|
|
5620
|
-
this.
|
|
5621
|
-
let captureEnd = this.position;
|
|
5622
|
-
let captureStart = this.position;
|
|
5668
|
+
this.#scanner.next();
|
|
5669
|
+
let captureEnd = this.#scanner.position;
|
|
5670
|
+
let captureStart = this.#scanner.position;
|
|
5623
5671
|
let tmp;
|
|
5624
|
-
ch = this.peek();
|
|
5672
|
+
ch = this.#scanner.peek();
|
|
5625
5673
|
while (ch !== 0) {
|
|
5626
5674
|
if (ch === DOUBLE_QUOTE) {
|
|
5627
|
-
const segment = this.captureSegment(captureStart, this.position, true);
|
|
5675
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, true);
|
|
5628
5676
|
if (segment) result += segment;
|
|
5629
|
-
this.
|
|
5677
|
+
this.#scanner.next();
|
|
5630
5678
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
5631
5679
|
return {
|
|
5632
5680
|
tag,
|
|
@@ -5636,19 +5684,21 @@ var LoaderState = class {
|
|
|
5636
5684
|
};
|
|
5637
5685
|
}
|
|
5638
5686
|
if (ch === BACKSLASH) {
|
|
5639
|
-
const segment = this.captureSegment(captureStart, this.position, true);
|
|
5687
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, true);
|
|
5640
5688
|
if (segment) result += segment;
|
|
5641
|
-
|
|
5689
|
+
this.#scanner.next();
|
|
5690
|
+
ch = this.#scanner.peek();
|
|
5642
5691
|
if (isEOL(ch)) {
|
|
5643
5692
|
this.skipSeparationSpace(false, nodeIndent);
|
|
5644
5693
|
} else if (ch < 256 && SIMPLE_ESCAPE_SEQUENCES.has(ch)) {
|
|
5645
5694
|
result += SIMPLE_ESCAPE_SEQUENCES.get(ch);
|
|
5646
|
-
this.
|
|
5695
|
+
this.#scanner.next();
|
|
5647
5696
|
} else if ((tmp = ESCAPED_HEX_LENGTHS.get(ch) ?? 0) > 0) {
|
|
5648
5697
|
let hexLength = tmp;
|
|
5649
5698
|
let hexResult = 0;
|
|
5650
5699
|
for (; hexLength > 0; hexLength--) {
|
|
5651
|
-
|
|
5700
|
+
this.#scanner.next();
|
|
5701
|
+
ch = this.#scanner.peek();
|
|
5652
5702
|
if ((tmp = hexCharCodeToNumber(ch)) >= 0) {
|
|
5653
5703
|
hexResult = (hexResult << 4) + tmp;
|
|
5654
5704
|
} else {
|
|
@@ -5656,28 +5706,28 @@ var LoaderState = class {
|
|
|
5656
5706
|
}
|
|
5657
5707
|
}
|
|
5658
5708
|
result += codepointToChar(hexResult);
|
|
5659
|
-
this.
|
|
5709
|
+
this.#scanner.next();
|
|
5660
5710
|
} else {
|
|
5661
5711
|
throw this.#createError("Cannot read double quoted scalar: unknown escape sequence");
|
|
5662
5712
|
}
|
|
5663
|
-
captureStart = captureEnd = this.position;
|
|
5713
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
5664
5714
|
} else if (isEOL(ch)) {
|
|
5665
5715
|
const segment = this.captureSegment(captureStart, captureEnd, true);
|
|
5666
5716
|
if (segment) result += segment;
|
|
5667
5717
|
result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
|
|
5668
|
-
captureStart = captureEnd = this.position;
|
|
5669
|
-
} else if (this.position === this.lineStart && this.testDocumentSeparator()) {
|
|
5718
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
5719
|
+
} else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
|
|
5670
5720
|
throw this.#createError("Unexpected end of the document within a double quoted scalar");
|
|
5671
5721
|
} else {
|
|
5672
|
-
this.
|
|
5673
|
-
captureEnd = this.position;
|
|
5722
|
+
this.#scanner.next();
|
|
5723
|
+
captureEnd = this.#scanner.position;
|
|
5674
5724
|
}
|
|
5675
|
-
ch = this.peek();
|
|
5725
|
+
ch = this.#scanner.peek();
|
|
5676
5726
|
}
|
|
5677
5727
|
throw this.#createError("Unexpected end of the stream within a double quoted scalar");
|
|
5678
5728
|
}
|
|
5679
5729
|
readFlowCollection(tag, anchor, nodeIndent) {
|
|
5680
|
-
let ch = this.peek();
|
|
5730
|
+
let ch = this.#scanner.peek();
|
|
5681
5731
|
let terminator;
|
|
5682
5732
|
let isMapping = true;
|
|
5683
5733
|
let result = {};
|
|
@@ -5691,7 +5741,8 @@ var LoaderState = class {
|
|
|
5691
5741
|
return;
|
|
5692
5742
|
}
|
|
5693
5743
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
5694
|
-
|
|
5744
|
+
this.#scanner.next();
|
|
5745
|
+
ch = this.#scanner.peek();
|
|
5695
5746
|
let readNext = true;
|
|
5696
5747
|
let valueNode = null;
|
|
5697
5748
|
let keyNode = null;
|
|
@@ -5703,9 +5754,9 @@ var LoaderState = class {
|
|
|
5703
5754
|
const overridableKeys = /* @__PURE__ */ new Set();
|
|
5704
5755
|
while (ch !== 0) {
|
|
5705
5756
|
this.skipSeparationSpace(true, nodeIndent);
|
|
5706
|
-
ch = this.peek();
|
|
5757
|
+
ch = this.#scanner.peek();
|
|
5707
5758
|
if (ch === terminator) {
|
|
5708
|
-
this.
|
|
5759
|
+
this.#scanner.next();
|
|
5709
5760
|
const kind = isMapping ? "mapping" : "sequence";
|
|
5710
5761
|
return {
|
|
5711
5762
|
tag,
|
|
@@ -5720,10 +5771,10 @@ var LoaderState = class {
|
|
|
5720
5771
|
keyTag = keyNode = valueNode = null;
|
|
5721
5772
|
isPair = isExplicitPair = false;
|
|
5722
5773
|
if (ch === QUESTION) {
|
|
5723
|
-
following = this.peek(1);
|
|
5774
|
+
following = this.#scanner.peek(1);
|
|
5724
5775
|
if (isWhiteSpaceOrEOL(following)) {
|
|
5725
5776
|
isPair = isExplicitPair = true;
|
|
5726
|
-
this.
|
|
5777
|
+
this.#scanner.next();
|
|
5727
5778
|
this.skipSeparationSpace(true, nodeIndent);
|
|
5728
5779
|
}
|
|
5729
5780
|
}
|
|
@@ -5739,10 +5790,11 @@ var LoaderState = class {
|
|
|
5739
5790
|
keyNode = newState.result;
|
|
5740
5791
|
}
|
|
5741
5792
|
this.skipSeparationSpace(true, nodeIndent);
|
|
5742
|
-
ch = this.peek();
|
|
5793
|
+
ch = this.#scanner.peek();
|
|
5743
5794
|
if ((isExplicitPair || this.line === line) && ch === COLON) {
|
|
5744
5795
|
isPair = true;
|
|
5745
|
-
|
|
5796
|
+
this.#scanner.next();
|
|
5797
|
+
ch = this.#scanner.peek();
|
|
5746
5798
|
this.skipSeparationSpace(true, nodeIndent);
|
|
5747
5799
|
const newState2 = this.composeNode({
|
|
5748
5800
|
parentIndent: nodeIndent,
|
|
@@ -5760,10 +5812,11 @@ var LoaderState = class {
|
|
|
5760
5812
|
result.push(keyNode);
|
|
5761
5813
|
}
|
|
5762
5814
|
this.skipSeparationSpace(true, nodeIndent);
|
|
5763
|
-
ch = this.peek();
|
|
5815
|
+
ch = this.#scanner.peek();
|
|
5764
5816
|
if (ch === COMMA) {
|
|
5765
5817
|
readNext = true;
|
|
5766
|
-
|
|
5818
|
+
this.#scanner.next();
|
|
5819
|
+
ch = this.#scanner.peek();
|
|
5767
5820
|
} else {
|
|
5768
5821
|
readNext = false;
|
|
5769
5822
|
}
|
|
@@ -5779,7 +5832,7 @@ var LoaderState = class {
|
|
|
5779
5832
|
let textIndent = nodeIndent;
|
|
5780
5833
|
let emptyLines = 0;
|
|
5781
5834
|
let atMoreIndented = false;
|
|
5782
|
-
let ch = this.peek();
|
|
5835
|
+
let ch = this.#scanner.peek();
|
|
5783
5836
|
let folding = false;
|
|
5784
5837
|
if (ch === VERTICAL_LINE) {
|
|
5785
5838
|
folding = false;
|
|
@@ -5791,7 +5844,8 @@ var LoaderState = class {
|
|
|
5791
5844
|
let result = "";
|
|
5792
5845
|
let tmp = 0;
|
|
5793
5846
|
while (ch !== 0) {
|
|
5794
|
-
|
|
5847
|
+
this.#scanner.next();
|
|
5848
|
+
ch = this.#scanner.peek();
|
|
5795
5849
|
if (ch === PLUS || ch === MINUS) {
|
|
5796
5850
|
if (CHOMPING_CLIP === chomping) {
|
|
5797
5851
|
chomping = ch === PLUS ? CHOMPING_KEEP : CHOMPING_STRIP;
|
|
@@ -5814,15 +5868,16 @@ var LoaderState = class {
|
|
|
5814
5868
|
if (isWhiteSpace(ch)) {
|
|
5815
5869
|
this.skipWhitespaces();
|
|
5816
5870
|
this.skipComment();
|
|
5817
|
-
ch = this.peek();
|
|
5871
|
+
ch = this.#scanner.peek();
|
|
5818
5872
|
}
|
|
5819
5873
|
while (ch !== 0) {
|
|
5820
5874
|
this.readLineBreak();
|
|
5821
5875
|
this.lineIndent = 0;
|
|
5822
|
-
ch = this.peek();
|
|
5876
|
+
ch = this.#scanner.peek();
|
|
5823
5877
|
while ((!detectedIndent || this.lineIndent < textIndent) && ch === SPACE) {
|
|
5824
5878
|
this.lineIndent++;
|
|
5825
|
-
|
|
5879
|
+
this.#scanner.next();
|
|
5880
|
+
ch = this.#scanner.peek();
|
|
5826
5881
|
}
|
|
5827
5882
|
if (!detectedIndent && this.lineIndent > textIndent) {
|
|
5828
5883
|
textIndent = this.lineIndent;
|
|
@@ -5861,11 +5916,12 @@ var LoaderState = class {
|
|
|
5861
5916
|
didReadContent = true;
|
|
5862
5917
|
detectedIndent = true;
|
|
5863
5918
|
emptyLines = 0;
|
|
5864
|
-
const captureStart = this.position;
|
|
5919
|
+
const captureStart = this.#scanner.position;
|
|
5865
5920
|
while (!isEOL(ch) && ch !== 0) {
|
|
5866
|
-
|
|
5921
|
+
this.#scanner.next();
|
|
5922
|
+
ch = this.#scanner.peek();
|
|
5867
5923
|
}
|
|
5868
|
-
const segment = this.captureSegment(captureStart, this.position, false);
|
|
5924
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, false);
|
|
5869
5925
|
if (segment) result += segment;
|
|
5870
5926
|
}
|
|
5871
5927
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
@@ -5888,11 +5944,11 @@ var LoaderState = class {
|
|
|
5888
5944
|
let atExplicitKey = false;
|
|
5889
5945
|
let detected = false;
|
|
5890
5946
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
5891
|
-
let ch = this.peek();
|
|
5947
|
+
let ch = this.#scanner.peek();
|
|
5892
5948
|
while (ch !== 0) {
|
|
5893
|
-
const following = this.peek(1);
|
|
5949
|
+
const following = this.#scanner.peek(1);
|
|
5894
5950
|
line = this.line;
|
|
5895
|
-
pos = this.position;
|
|
5951
|
+
pos = this.#scanner.position;
|
|
5896
5952
|
if ((ch === QUESTION || ch === COLON) && isWhiteSpaceOrEOL(following)) {
|
|
5897
5953
|
if (ch === QUESTION) {
|
|
5898
5954
|
if (atExplicitKey) {
|
|
@@ -5910,7 +5966,7 @@ var LoaderState = class {
|
|
|
5910
5966
|
} else {
|
|
5911
5967
|
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
5968
|
}
|
|
5913
|
-
this.
|
|
5969
|
+
this.#scanner.next();
|
|
5914
5970
|
ch = following;
|
|
5915
5971
|
} else {
|
|
5916
5972
|
const newState = this.composeNode({
|
|
@@ -5921,11 +5977,12 @@ var LoaderState = class {
|
|
|
5921
5977
|
});
|
|
5922
5978
|
if (!newState) break;
|
|
5923
5979
|
if (this.line === line) {
|
|
5924
|
-
ch = this.peek();
|
|
5980
|
+
ch = this.#scanner.peek();
|
|
5925
5981
|
this.skipWhitespaces();
|
|
5926
|
-
ch = this.peek();
|
|
5982
|
+
ch = this.#scanner.peek();
|
|
5927
5983
|
if (ch === COLON) {
|
|
5928
|
-
|
|
5984
|
+
this.#scanner.next();
|
|
5985
|
+
ch = this.#scanner.peek();
|
|
5929
5986
|
if (!isWhiteSpaceOrEOL(ch)) {
|
|
5930
5987
|
throw this.#createError("Cannot read block: a whitespace character is expected after the key-value separator within a block mapping");
|
|
5931
5988
|
}
|
|
@@ -5982,7 +6039,7 @@ var LoaderState = class {
|
|
|
5982
6039
|
keyTag = keyNode = valueNode = null;
|
|
5983
6040
|
}
|
|
5984
6041
|
this.skipSeparationSpace(true, -1);
|
|
5985
|
-
ch = this.peek();
|
|
6042
|
+
ch = this.#scanner.peek();
|
|
5986
6043
|
}
|
|
5987
6044
|
if (this.lineIndent > nodeIndent && ch !== 0) {
|
|
5988
6045
|
throw this.#createError("Cannot read block: bad indentation of a mapping entry");
|
|
@@ -6005,30 +6062,35 @@ var LoaderState = class {
|
|
|
6005
6062
|
let isNamed = false;
|
|
6006
6063
|
let tagHandle = "";
|
|
6007
6064
|
let tagName;
|
|
6008
|
-
let ch = this.peek();
|
|
6065
|
+
let ch = this.#scanner.peek();
|
|
6009
6066
|
if (ch !== EXCLAMATION) return;
|
|
6010
6067
|
if (tag !== null) {
|
|
6011
6068
|
throw this.#createError("Cannot read tag property: duplication of a tag property");
|
|
6012
6069
|
}
|
|
6013
|
-
|
|
6070
|
+
this.#scanner.next();
|
|
6071
|
+
ch = this.#scanner.peek();
|
|
6014
6072
|
if (ch === SMALLER_THAN) {
|
|
6015
6073
|
isVerbatim = true;
|
|
6016
|
-
|
|
6074
|
+
this.#scanner.next();
|
|
6075
|
+
ch = this.#scanner.peek();
|
|
6017
6076
|
} else if (ch === EXCLAMATION) {
|
|
6018
6077
|
isNamed = true;
|
|
6019
6078
|
tagHandle = "!!";
|
|
6020
|
-
|
|
6079
|
+
this.#scanner.next();
|
|
6080
|
+
ch = this.#scanner.peek();
|
|
6021
6081
|
} else {
|
|
6022
6082
|
tagHandle = "!";
|
|
6023
6083
|
}
|
|
6024
|
-
let position = this.position;
|
|
6084
|
+
let position = this.#scanner.position;
|
|
6025
6085
|
if (isVerbatim) {
|
|
6026
6086
|
do {
|
|
6027
|
-
|
|
6087
|
+
this.#scanner.next();
|
|
6088
|
+
ch = this.#scanner.peek();
|
|
6028
6089
|
} while (ch !== 0 && ch !== GREATER_THAN);
|
|
6029
|
-
if (this.
|
|
6030
|
-
tagName = this.
|
|
6031
|
-
|
|
6090
|
+
if (!this.#scanner.eof()) {
|
|
6091
|
+
tagName = this.#scanner.source.slice(position, this.#scanner.position);
|
|
6092
|
+
this.#scanner.next();
|
|
6093
|
+
ch = this.#scanner.peek();
|
|
6032
6094
|
} else {
|
|
6033
6095
|
throw this.#createError("Cannot read tag property: unexpected end of stream");
|
|
6034
6096
|
}
|
|
@@ -6036,19 +6098,20 @@ var LoaderState = class {
|
|
|
6036
6098
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
|
|
6037
6099
|
if (ch === EXCLAMATION) {
|
|
6038
6100
|
if (!isNamed) {
|
|
6039
|
-
tagHandle = this.
|
|
6101
|
+
tagHandle = this.#scanner.source.slice(position - 1, this.#scanner.position + 1);
|
|
6040
6102
|
if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
|
6041
6103
|
throw this.#createError("Cannot read tag property: named tag handle contains invalid characters");
|
|
6042
6104
|
}
|
|
6043
6105
|
isNamed = true;
|
|
6044
|
-
position = this.position + 1;
|
|
6106
|
+
position = this.#scanner.position + 1;
|
|
6045
6107
|
} else {
|
|
6046
6108
|
throw this.#createError("Cannot read tag property: tag suffix cannot contain an exclamation mark");
|
|
6047
6109
|
}
|
|
6048
6110
|
}
|
|
6049
|
-
|
|
6111
|
+
this.#scanner.next();
|
|
6112
|
+
ch = this.#scanner.peek();
|
|
6050
6113
|
}
|
|
6051
|
-
tagName = this.
|
|
6114
|
+
tagName = this.#scanner.source.slice(position, this.#scanner.position);
|
|
6052
6115
|
if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
|
6053
6116
|
throw this.#createError("Cannot read tag property: tag suffix cannot contain flow indicator characters");
|
|
6054
6117
|
}
|
|
@@ -6068,32 +6131,36 @@ var LoaderState = class {
|
|
|
6068
6131
|
throw this.#createError(`Cannot read tag property: undeclared tag handle "${tagHandle}"`);
|
|
6069
6132
|
}
|
|
6070
6133
|
readAnchorProperty(anchor) {
|
|
6071
|
-
let ch = this.peek();
|
|
6134
|
+
let ch = this.#scanner.peek();
|
|
6072
6135
|
if (ch !== AMPERSAND) return;
|
|
6073
6136
|
if (anchor !== null) {
|
|
6074
6137
|
throw this.#createError("Cannot read anchor property: duplicate anchor property");
|
|
6075
6138
|
}
|
|
6076
|
-
|
|
6077
|
-
|
|
6139
|
+
this.#scanner.next();
|
|
6140
|
+
ch = this.#scanner.peek();
|
|
6141
|
+
const position = this.#scanner.position;
|
|
6078
6142
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
|
|
6079
|
-
|
|
6143
|
+
this.#scanner.next();
|
|
6144
|
+
ch = this.#scanner.peek();
|
|
6080
6145
|
}
|
|
6081
|
-
if (this.position === position) {
|
|
6146
|
+
if (this.#scanner.position === position) {
|
|
6082
6147
|
throw this.#createError("Cannot read anchor property: name of an anchor node must contain at least one character");
|
|
6083
6148
|
}
|
|
6084
|
-
return this.
|
|
6149
|
+
return this.#scanner.source.slice(position, this.#scanner.position);
|
|
6085
6150
|
}
|
|
6086
6151
|
readAlias() {
|
|
6087
|
-
if (this.peek() !== ASTERISK) return;
|
|
6088
|
-
|
|
6089
|
-
|
|
6152
|
+
if (this.#scanner.peek() !== ASTERISK) return;
|
|
6153
|
+
this.#scanner.next();
|
|
6154
|
+
let ch = this.#scanner.peek();
|
|
6155
|
+
const position = this.#scanner.position;
|
|
6090
6156
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
|
|
6091
|
-
|
|
6157
|
+
this.#scanner.next();
|
|
6158
|
+
ch = this.#scanner.peek();
|
|
6092
6159
|
}
|
|
6093
|
-
if (this.position === position) {
|
|
6160
|
+
if (this.#scanner.position === position) {
|
|
6094
6161
|
throw this.#createError("Cannot read alias: alias name must contain at least one character");
|
|
6095
6162
|
}
|
|
6096
|
-
const alias = this.
|
|
6163
|
+
const alias = this.#scanner.source.slice(position, this.#scanner.position);
|
|
6097
6164
|
if (!this.anchorMap.has(alias)) {
|
|
6098
6165
|
throw this.#createError(`Cannot read alias: unidentified alias "${alias}"`);
|
|
6099
6166
|
}
|
|
@@ -6176,7 +6243,7 @@ var LoaderState = class {
|
|
|
6176
6243
|
const cond = CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext;
|
|
6177
6244
|
const flowIndent = cond ? parentIndent : parentIndent + 1;
|
|
6178
6245
|
if (allowBlockCollections) {
|
|
6179
|
-
const blockIndent = this.position - this.lineStart;
|
|
6246
|
+
const blockIndent = this.#scanner.position - this.lineStart;
|
|
6180
6247
|
const blockSequenceState = this.readBlockSequence(tag, anchor, blockIndent);
|
|
6181
6248
|
if (blockSequenceState) return this.resolveTag(blockSequenceState);
|
|
6182
6249
|
const blockMappingState = this.readBlockMapping(tag, anchor, blockIndent, flowIndent);
|
|
@@ -6210,7 +6277,7 @@ var LoaderState = class {
|
|
|
6210
6277
|
return this.resolveTag(plainScalarState);
|
|
6211
6278
|
}
|
|
6212
6279
|
} else if (indentStatus === 0 && CONTEXT_BLOCK_OUT === nodeContext && allowBlockCollections) {
|
|
6213
|
-
const blockIndent = this.position - this.lineStart;
|
|
6280
|
+
const blockIndent = this.#scanner.position - this.lineStart;
|
|
6214
6281
|
const newState2 = this.readBlockSequence(tag, anchor, blockIndent);
|
|
6215
6282
|
if (newState2) return this.resolveTag(newState2);
|
|
6216
6283
|
}
|
|
@@ -6225,20 +6292,22 @@ var LoaderState = class {
|
|
|
6225
6292
|
readDirectives() {
|
|
6226
6293
|
let hasDirectives = false;
|
|
6227
6294
|
let version = null;
|
|
6228
|
-
let ch = this.peek();
|
|
6295
|
+
let ch = this.#scanner.peek();
|
|
6229
6296
|
while (ch !== 0) {
|
|
6230
6297
|
this.skipSeparationSpace(true, -1);
|
|
6231
|
-
ch = this.peek();
|
|
6298
|
+
ch = this.#scanner.peek();
|
|
6232
6299
|
if (this.lineIndent > 0 || ch !== PERCENT) {
|
|
6233
6300
|
break;
|
|
6234
6301
|
}
|
|
6235
6302
|
hasDirectives = true;
|
|
6236
|
-
|
|
6237
|
-
|
|
6303
|
+
this.#scanner.next();
|
|
6304
|
+
ch = this.#scanner.peek();
|
|
6305
|
+
let position = this.#scanner.position;
|
|
6238
6306
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
|
|
6239
|
-
|
|
6307
|
+
this.#scanner.next();
|
|
6308
|
+
ch = this.#scanner.peek();
|
|
6240
6309
|
}
|
|
6241
|
-
const directiveName = this.
|
|
6310
|
+
const directiveName = this.#scanner.source.slice(position, this.#scanner.position);
|
|
6242
6311
|
const directiveArgs = [];
|
|
6243
6312
|
if (directiveName.length < 1) {
|
|
6244
6313
|
throw this.#createError("Cannot read document: directive name length must be greater than zero");
|
|
@@ -6246,13 +6315,14 @@ var LoaderState = class {
|
|
|
6246
6315
|
while (ch !== 0) {
|
|
6247
6316
|
this.skipWhitespaces();
|
|
6248
6317
|
this.skipComment();
|
|
6249
|
-
ch = this.peek();
|
|
6318
|
+
ch = this.#scanner.peek();
|
|
6250
6319
|
if (isEOL(ch)) break;
|
|
6251
|
-
position = this.position;
|
|
6320
|
+
position = this.#scanner.position;
|
|
6252
6321
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
|
|
6253
|
-
|
|
6322
|
+
this.#scanner.next();
|
|
6323
|
+
ch = this.#scanner.peek();
|
|
6254
6324
|
}
|
|
6255
|
-
directiveArgs.push(this.
|
|
6325
|
+
directiveArgs.push(this.#scanner.source.slice(position, this.#scanner.position));
|
|
6256
6326
|
}
|
|
6257
6327
|
if (ch !== 0) this.readLineBreak();
|
|
6258
6328
|
switch (directiveName) {
|
|
@@ -6269,20 +6339,20 @@ var LoaderState = class {
|
|
|
6269
6339
|
this.dispatchWarning(`unknown document directive "${directiveName}"`);
|
|
6270
6340
|
break;
|
|
6271
6341
|
}
|
|
6272
|
-
ch = this.peek();
|
|
6342
|
+
ch = this.#scanner.peek();
|
|
6273
6343
|
}
|
|
6274
6344
|
return hasDirectives;
|
|
6275
6345
|
}
|
|
6276
6346
|
readDocument() {
|
|
6277
|
-
const documentStart = this.position;
|
|
6347
|
+
const documentStart = this.#scanner.position;
|
|
6278
6348
|
this.checkLineBreaks = false;
|
|
6279
6349
|
this.tagMap = /* @__PURE__ */ new Map();
|
|
6280
6350
|
this.anchorMap = /* @__PURE__ */ new Map();
|
|
6281
6351
|
const hasDirectives = this.readDirectives();
|
|
6282
6352
|
this.skipSeparationSpace(true, -1);
|
|
6283
6353
|
let result = null;
|
|
6284
|
-
if (this.lineIndent === 0 && this.peek() === MINUS && this.peek(1) === MINUS && this.peek(2) === MINUS) {
|
|
6285
|
-
this.position += 3;
|
|
6354
|
+
if (this.lineIndent === 0 && this.#scanner.peek() === MINUS && this.#scanner.peek(1) === MINUS && this.#scanner.peek(2) === MINUS) {
|
|
6355
|
+
this.#scanner.position += 3;
|
|
6286
6356
|
this.skipSeparationSpace(true, -1);
|
|
6287
6357
|
} else if (hasDirectives) {
|
|
6288
6358
|
throw this.#createError("Cannot read document: directives end mark is expected");
|
|
@@ -6295,21 +6365,21 @@ var LoaderState = class {
|
|
|
6295
6365
|
});
|
|
6296
6366
|
if (newState) result = newState.result;
|
|
6297
6367
|
this.skipSeparationSpace(true, -1);
|
|
6298
|
-
if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.
|
|
6368
|
+
if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.#scanner.source.slice(documentStart, this.#scanner.position))) {
|
|
6299
6369
|
this.dispatchWarning("non-ASCII line breaks are interpreted as content");
|
|
6300
6370
|
}
|
|
6301
|
-
if (this.position === this.lineStart && this.testDocumentSeparator()) {
|
|
6302
|
-
if (this.peek() === DOT) {
|
|
6303
|
-
this.position += 3;
|
|
6371
|
+
if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
|
|
6372
|
+
if (this.#scanner.peek() === DOT) {
|
|
6373
|
+
this.#scanner.position += 3;
|
|
6304
6374
|
this.skipSeparationSpace(true, -1);
|
|
6305
6375
|
}
|
|
6306
|
-
} else if (this.
|
|
6376
|
+
} else if (!this.#scanner.eof()) {
|
|
6307
6377
|
throw this.#createError("Cannot read document: end of the stream or a document separator is expected");
|
|
6308
6378
|
}
|
|
6309
6379
|
return result;
|
|
6310
6380
|
}
|
|
6311
6381
|
*readDocuments() {
|
|
6312
|
-
while (this.
|
|
6382
|
+
while (!this.#scanner.eof()) {
|
|
6313
6383
|
yield this.readDocument();
|
|
6314
6384
|
}
|
|
6315
6385
|
}
|
|
@@ -6322,7 +6392,6 @@ function sanitizeInput(input) {
|
|
|
6322
6392
|
if (!isEOL(input.charCodeAt(input.length - 1))) input += "\n";
|
|
6323
6393
|
if (input.charCodeAt(0) === 65279) input = input.slice(1);
|
|
6324
6394
|
}
|
|
6325
|
-
input += "\0";
|
|
6326
6395
|
return input;
|
|
6327
6396
|
}
|
|
6328
6397
|
function parse(content, options = {}) {
|
|
@@ -6482,7 +6551,7 @@ function getDefaultAgents() {
|
|
|
6482
6551
|
}
|
|
6483
6552
|
|
|
6484
6553
|
// __mcpc__cli_latest/node_modules/@mcpc/cli/src/config/loader.js
|
|
6485
|
-
var CLI_VERSION = "0.1.
|
|
6554
|
+
var CLI_VERSION = "0.1.51";
|
|
6486
6555
|
function extractServerName(command, commandArgs) {
|
|
6487
6556
|
for (const arg of commandArgs) {
|
|
6488
6557
|
if (!arg.startsWith("-")) {
|
|
@@ -8152,6 +8221,147 @@ var ExperimentalServerTasks = class {
|
|
|
8152
8221
|
requestStream(request, resultSchema, options) {
|
|
8153
8222
|
return this._server.requestStream(request, resultSchema, options);
|
|
8154
8223
|
}
|
|
8224
|
+
/**
|
|
8225
|
+
* Sends a sampling request and returns an AsyncGenerator that yields response messages.
|
|
8226
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
8227
|
+
*
|
|
8228
|
+
* For task-augmented requests, yields 'taskCreated' and 'taskStatus' messages
|
|
8229
|
+
* before the final result.
|
|
8230
|
+
*
|
|
8231
|
+
* @example
|
|
8232
|
+
* ```typescript
|
|
8233
|
+
* const stream = server.experimental.tasks.createMessageStream({
|
|
8234
|
+
* messages: [{ role: 'user', content: { type: 'text', text: 'Hello' } }],
|
|
8235
|
+
* maxTokens: 100
|
|
8236
|
+
* }, {
|
|
8237
|
+
* onprogress: (progress) => {
|
|
8238
|
+
* // Handle streaming tokens via progress notifications
|
|
8239
|
+
* console.log('Progress:', progress.message);
|
|
8240
|
+
* }
|
|
8241
|
+
* });
|
|
8242
|
+
*
|
|
8243
|
+
* for await (const message of stream) {
|
|
8244
|
+
* switch (message.type) {
|
|
8245
|
+
* case 'taskCreated':
|
|
8246
|
+
* console.log('Task created:', message.task.taskId);
|
|
8247
|
+
* break;
|
|
8248
|
+
* case 'taskStatus':
|
|
8249
|
+
* console.log('Task status:', message.task.status);
|
|
8250
|
+
* break;
|
|
8251
|
+
* case 'result':
|
|
8252
|
+
* console.log('Final result:', message.result);
|
|
8253
|
+
* break;
|
|
8254
|
+
* case 'error':
|
|
8255
|
+
* console.error('Error:', message.error);
|
|
8256
|
+
* break;
|
|
8257
|
+
* }
|
|
8258
|
+
* }
|
|
8259
|
+
* ```
|
|
8260
|
+
*
|
|
8261
|
+
* @param params - The sampling request parameters
|
|
8262
|
+
* @param options - Optional request options (timeout, signal, task creation params, onprogress, etc.)
|
|
8263
|
+
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
8264
|
+
*
|
|
8265
|
+
* @experimental
|
|
8266
|
+
*/
|
|
8267
|
+
createMessageStream(params, options) {
|
|
8268
|
+
const clientCapabilities = this._server.getClientCapabilities();
|
|
8269
|
+
if ((params.tools || params.toolChoice) && !clientCapabilities?.sampling?.tools) {
|
|
8270
|
+
throw new Error("Client does not support sampling tools capability.");
|
|
8271
|
+
}
|
|
8272
|
+
if (params.messages.length > 0) {
|
|
8273
|
+
const lastMessage = params.messages[params.messages.length - 1];
|
|
8274
|
+
const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];
|
|
8275
|
+
const hasToolResults = lastContent.some((c) => c.type === "tool_result");
|
|
8276
|
+
const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : void 0;
|
|
8277
|
+
const previousContent = previousMessage ? Array.isArray(previousMessage.content) ? previousMessage.content : [previousMessage.content] : [];
|
|
8278
|
+
const hasPreviousToolUse = previousContent.some((c) => c.type === "tool_use");
|
|
8279
|
+
if (hasToolResults) {
|
|
8280
|
+
if (lastContent.some((c) => c.type !== "tool_result")) {
|
|
8281
|
+
throw new Error("The last message must contain only tool_result content if any is present");
|
|
8282
|
+
}
|
|
8283
|
+
if (!hasPreviousToolUse) {
|
|
8284
|
+
throw new Error("tool_result blocks are not matching any tool_use from the previous message");
|
|
8285
|
+
}
|
|
8286
|
+
}
|
|
8287
|
+
if (hasPreviousToolUse) {
|
|
8288
|
+
const toolUseIds = new Set(previousContent.filter((c) => c.type === "tool_use").map((c) => c.id));
|
|
8289
|
+
const toolResultIds = new Set(lastContent.filter((c) => c.type === "tool_result").map((c) => c.toolUseId));
|
|
8290
|
+
if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((id) => toolResultIds.has(id))) {
|
|
8291
|
+
throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match");
|
|
8292
|
+
}
|
|
8293
|
+
}
|
|
8294
|
+
}
|
|
8295
|
+
return this.requestStream({
|
|
8296
|
+
method: "sampling/createMessage",
|
|
8297
|
+
params
|
|
8298
|
+
}, CreateMessageResultSchema, options);
|
|
8299
|
+
}
|
|
8300
|
+
/**
|
|
8301
|
+
* Sends an elicitation request and returns an AsyncGenerator that yields response messages.
|
|
8302
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
8303
|
+
*
|
|
8304
|
+
* For task-augmented requests (especially URL-based elicitation), yields 'taskCreated'
|
|
8305
|
+
* and 'taskStatus' messages before the final result.
|
|
8306
|
+
*
|
|
8307
|
+
* @example
|
|
8308
|
+
* ```typescript
|
|
8309
|
+
* const stream = server.experimental.tasks.elicitInputStream({
|
|
8310
|
+
* mode: 'url',
|
|
8311
|
+
* message: 'Please authenticate',
|
|
8312
|
+
* elicitationId: 'auth-123',
|
|
8313
|
+
* url: 'https://example.com/auth'
|
|
8314
|
+
* }, {
|
|
8315
|
+
* task: { ttl: 300000 } // Task-augmented for long-running auth flow
|
|
8316
|
+
* });
|
|
8317
|
+
*
|
|
8318
|
+
* for await (const message of stream) {
|
|
8319
|
+
* switch (message.type) {
|
|
8320
|
+
* case 'taskCreated':
|
|
8321
|
+
* console.log('Task created:', message.task.taskId);
|
|
8322
|
+
* break;
|
|
8323
|
+
* case 'taskStatus':
|
|
8324
|
+
* console.log('Task status:', message.task.status);
|
|
8325
|
+
* break;
|
|
8326
|
+
* case 'result':
|
|
8327
|
+
* console.log('User action:', message.result.action);
|
|
8328
|
+
* break;
|
|
8329
|
+
* case 'error':
|
|
8330
|
+
* console.error('Error:', message.error);
|
|
8331
|
+
* break;
|
|
8332
|
+
* }
|
|
8333
|
+
* }
|
|
8334
|
+
* ```
|
|
8335
|
+
*
|
|
8336
|
+
* @param params - The elicitation request parameters
|
|
8337
|
+
* @param options - Optional request options (timeout, signal, task creation params, etc.)
|
|
8338
|
+
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
8339
|
+
*
|
|
8340
|
+
* @experimental
|
|
8341
|
+
*/
|
|
8342
|
+
elicitInputStream(params, options) {
|
|
8343
|
+
const clientCapabilities = this._server.getClientCapabilities();
|
|
8344
|
+
const mode = params.mode ?? "form";
|
|
8345
|
+
switch (mode) {
|
|
8346
|
+
case "url": {
|
|
8347
|
+
if (!clientCapabilities?.elicitation?.url) {
|
|
8348
|
+
throw new Error("Client does not support url elicitation.");
|
|
8349
|
+
}
|
|
8350
|
+
break;
|
|
8351
|
+
}
|
|
8352
|
+
case "form": {
|
|
8353
|
+
if (!clientCapabilities?.elicitation?.form) {
|
|
8354
|
+
throw new Error("Client does not support form elicitation.");
|
|
8355
|
+
}
|
|
8356
|
+
break;
|
|
8357
|
+
}
|
|
8358
|
+
}
|
|
8359
|
+
const normalizedParams = mode === "form" && params.mode === void 0 ? { ...params, mode: "form" } : params;
|
|
8360
|
+
return this.requestStream({
|
|
8361
|
+
method: "elicitation/create",
|
|
8362
|
+
params: normalizedParams
|
|
8363
|
+
}, ElicitResultSchema, options);
|
|
8364
|
+
}
|
|
8155
8365
|
/**
|
|
8156
8366
|
* Gets the current status of a task.
|
|
8157
8367
|
*
|
|
@@ -10370,22 +10580,45 @@ async function auth(provider, options) {
|
|
|
10370
10580
|
}
|
|
10371
10581
|
}
|
|
10372
10582
|
async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
|
|
10583
|
+
const cachedState = await provider.discoveryState?.();
|
|
10373
10584
|
let resourceMetadata;
|
|
10374
10585
|
let authorizationServerUrl;
|
|
10375
|
-
|
|
10376
|
-
|
|
10377
|
-
|
|
10378
|
-
|
|
10586
|
+
let metadata;
|
|
10587
|
+
let effectiveResourceMetadataUrl = resourceMetadataUrl;
|
|
10588
|
+
if (!effectiveResourceMetadataUrl && cachedState?.resourceMetadataUrl) {
|
|
10589
|
+
effectiveResourceMetadataUrl = new URL(cachedState.resourceMetadataUrl);
|
|
10590
|
+
}
|
|
10591
|
+
if (cachedState?.authorizationServerUrl) {
|
|
10592
|
+
authorizationServerUrl = cachedState.authorizationServerUrl;
|
|
10593
|
+
resourceMetadata = cachedState.resourceMetadata;
|
|
10594
|
+
metadata = cachedState.authorizationServerMetadata ?? await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn });
|
|
10595
|
+
if (!resourceMetadata) {
|
|
10596
|
+
try {
|
|
10597
|
+
resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl }, fetchFn);
|
|
10598
|
+
} catch {
|
|
10599
|
+
}
|
|
10379
10600
|
}
|
|
10380
|
-
|
|
10381
|
-
|
|
10382
|
-
|
|
10383
|
-
|
|
10601
|
+
if (metadata !== cachedState.authorizationServerMetadata || resourceMetadata !== cachedState.resourceMetadata) {
|
|
10602
|
+
await provider.saveDiscoveryState?.({
|
|
10603
|
+
authorizationServerUrl: String(authorizationServerUrl),
|
|
10604
|
+
resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
|
|
10605
|
+
resourceMetadata,
|
|
10606
|
+
authorizationServerMetadata: metadata
|
|
10607
|
+
});
|
|
10608
|
+
}
|
|
10609
|
+
} else {
|
|
10610
|
+
const serverInfo = await discoverOAuthServerInfo(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl, fetchFn });
|
|
10611
|
+
authorizationServerUrl = serverInfo.authorizationServerUrl;
|
|
10612
|
+
metadata = serverInfo.authorizationServerMetadata;
|
|
10613
|
+
resourceMetadata = serverInfo.resourceMetadata;
|
|
10614
|
+
await provider.saveDiscoveryState?.({
|
|
10615
|
+
authorizationServerUrl: String(authorizationServerUrl),
|
|
10616
|
+
resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
|
|
10617
|
+
resourceMetadata,
|
|
10618
|
+
authorizationServerMetadata: metadata
|
|
10619
|
+
});
|
|
10384
10620
|
}
|
|
10385
10621
|
const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
|
|
10386
|
-
const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, {
|
|
10387
|
-
fetchFn
|
|
10388
|
-
});
|
|
10389
10622
|
let clientInformation = await Promise.resolve(provider.clientInformation());
|
|
10390
10623
|
if (!clientInformation) {
|
|
10391
10624
|
if (authorizationCode !== void 0) {
|
|
@@ -10640,6 +10873,26 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
|
|
|
10640
10873
|
}
|
|
10641
10874
|
return void 0;
|
|
10642
10875
|
}
|
|
10876
|
+
async function discoverOAuthServerInfo(serverUrl, opts) {
|
|
10877
|
+
let resourceMetadata;
|
|
10878
|
+
let authorizationServerUrl;
|
|
10879
|
+
try {
|
|
10880
|
+
resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: opts?.resourceMetadataUrl }, opts?.fetchFn);
|
|
10881
|
+
if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
|
|
10882
|
+
authorizationServerUrl = resourceMetadata.authorization_servers[0];
|
|
10883
|
+
}
|
|
10884
|
+
} catch {
|
|
10885
|
+
}
|
|
10886
|
+
if (!authorizationServerUrl) {
|
|
10887
|
+
authorizationServerUrl = String(new URL("/", serverUrl));
|
|
10888
|
+
}
|
|
10889
|
+
const authorizationServerMetadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn: opts?.fetchFn });
|
|
10890
|
+
return {
|
|
10891
|
+
authorizationServerUrl,
|
|
10892
|
+
authorizationServerMetadata,
|
|
10893
|
+
resourceMetadata
|
|
10894
|
+
};
|
|
10895
|
+
}
|
|
10643
10896
|
async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
|
|
10644
10897
|
let authorizationUrl;
|
|
10645
10898
|
if (metadata) {
|
|
@@ -11504,18 +11757,6 @@ var cleanToolSchema = (schema) => {
|
|
|
11504
11757
|
var import_node_process6 = require("node:process");
|
|
11505
11758
|
var import_node_process7 = __toESM(require("node:process"), 1);
|
|
11506
11759
|
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
11760
|
function createTransport(def) {
|
|
11520
11761
|
const defAny = def;
|
|
11521
11762
|
const explicitType = defAny.transportType || defAny.type;
|
|
@@ -11563,90 +11804,43 @@ function createTransport(def) {
|
|
|
11563
11804
|
}
|
|
11564
11805
|
throw new Error(`Unsupported transport configuration: ${JSON.stringify(def)}`);
|
|
11565
11806
|
}
|
|
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);
|
|
11807
|
+
function defSignature(def) {
|
|
11808
|
+
const defCopy = {
|
|
11809
|
+
...def
|
|
11810
|
+
};
|
|
11811
|
+
if (defCopy.transportType === "memory" || defCopy.transport) {
|
|
11812
|
+
return `memory:${Date.now()}:${Math.random()}`;
|
|
11600
11813
|
}
|
|
11814
|
+
return JSON.stringify(defCopy);
|
|
11601
11815
|
}
|
|
11602
|
-
|
|
11603
|
-
|
|
11604
|
-
|
|
11605
|
-
|
|
11606
|
-
|
|
11607
|
-
|
|
11608
|
-
|
|
11609
|
-
|
|
11610
|
-
|
|
11611
|
-
|
|
11612
|
-
|
|
11613
|
-
}
|
|
11816
|
+
var shortHash = (s) => (0, import_node_crypto.createHash)("sha256").update(s).digest("hex").slice(0, 8);
|
|
11817
|
+
async function createMcpClient(def) {
|
|
11818
|
+
const transport = createTransport(def);
|
|
11819
|
+
const client = new Client({
|
|
11820
|
+
name: `mcp_${shortHash(defSignature(def))}`,
|
|
11821
|
+
version: "1.0.0"
|
|
11822
|
+
});
|
|
11823
|
+
await client.connect(transport, {
|
|
11824
|
+
timeout: 6e4 * 10
|
|
11825
|
+
});
|
|
11826
|
+
return client;
|
|
11614
11827
|
}
|
|
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
11828
|
async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
11633
11829
|
const allTools = {};
|
|
11634
11830
|
const allClients = {};
|
|
11635
|
-
const
|
|
11831
|
+
const clientsToClose = [];
|
|
11636
11832
|
for (const [name, definition] of Object.entries(mcpConfig.mcpServers)) {
|
|
11637
11833
|
const def = definition;
|
|
11638
11834
|
if (def.disabled) continue;
|
|
11639
|
-
const defKey = shortHash(defSignature(def));
|
|
11640
|
-
const serverId = name;
|
|
11641
11835
|
try {
|
|
11642
|
-
const client = await
|
|
11643
|
-
|
|
11644
|
-
allClients[
|
|
11836
|
+
const client = await createMcpClient(def);
|
|
11837
|
+
clientsToClose.push(client);
|
|
11838
|
+
allClients[name] = client;
|
|
11645
11839
|
const { tools } = await client.listTools();
|
|
11646
11840
|
tools.forEach((tool2) => {
|
|
11647
11841
|
const toolNameWithScope = `${name}.${tool2.name}`;
|
|
11648
11842
|
const internalToolName = tool2.name;
|
|
11649
|
-
const rawToolId = `${
|
|
11843
|
+
const rawToolId = `${name}_${internalToolName}`;
|
|
11650
11844
|
const toolId = sanitizePropertyKey(rawToolId);
|
|
11651
11845
|
if (filterIn && !filterIn({
|
|
11652
11846
|
action: internalToolName,
|
|
@@ -11658,7 +11852,7 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
|
11658
11852
|
})) {
|
|
11659
11853
|
return;
|
|
11660
11854
|
}
|
|
11661
|
-
const execute = (args) => allClients[
|
|
11855
|
+
const execute = (args) => allClients[name].callTool({
|
|
11662
11856
|
name: internalToolName,
|
|
11663
11857
|
arguments: args
|
|
11664
11858
|
}, void 0, {
|
|
@@ -11675,10 +11869,12 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
|
11675
11869
|
}
|
|
11676
11870
|
}
|
|
11677
11871
|
const cleanupClients = async () => {
|
|
11678
|
-
await Promise.all(
|
|
11679
|
-
|
|
11680
|
-
|
|
11681
|
-
|
|
11872
|
+
await Promise.all(clientsToClose.map((client) => {
|
|
11873
|
+
try {
|
|
11874
|
+
return client.close();
|
|
11875
|
+
} catch {
|
|
11876
|
+
}
|
|
11877
|
+
}));
|
|
11682
11878
|
};
|
|
11683
11879
|
return {
|
|
11684
11880
|
tools: allTools,
|