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