@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/bin.cjs
CHANGED
|
@@ -2377,7 +2377,7 @@ if (typeof global.crypto === "undefined") {
|
|
|
2377
2377
|
var outgoingEnded = Symbol("outgoingEnded");
|
|
2378
2378
|
|
|
2379
2379
|
// __mcpc__cli_latest/node_modules/@jsr/std__cli/parse_args.js
|
|
2380
|
-
var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value
|
|
2380
|
+
var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.*))?$/s;
|
|
2381
2381
|
var LETTER_REGEXP = /[A-Za-z]/;
|
|
2382
2382
|
var NUMBER_REGEXP = /-?\d+(\.\d*)?(e-?\d+)?$/;
|
|
2383
2383
|
var HYPHEN_REGEXP = /^(-|--)[^-]/;
|
|
@@ -2388,12 +2388,19 @@ var NON_WHITESPACE_REGEXP = /\S/;
|
|
|
2388
2388
|
function isNumber(string3) {
|
|
2389
2389
|
return NON_WHITESPACE_REGEXP.test(string3) && Number.isFinite(Number(string3));
|
|
2390
2390
|
}
|
|
2391
|
+
function isConstructorOrProto(obj, key) {
|
|
2392
|
+
return key === "constructor" && typeof obj[key] === "function" || key === "__proto__";
|
|
2393
|
+
}
|
|
2391
2394
|
function setNested(object5, keys, value, collect = false) {
|
|
2392
2395
|
keys = [
|
|
2393
2396
|
...keys
|
|
2394
2397
|
];
|
|
2395
2398
|
const key = keys.pop();
|
|
2396
|
-
|
|
2399
|
+
for (const k of keys) {
|
|
2400
|
+
if (isConstructorOrProto(object5, k)) return;
|
|
2401
|
+
object5 = object5[k] ??= {};
|
|
2402
|
+
}
|
|
2403
|
+
if (isConstructorOrProto(object5, key)) return;
|
|
2397
2404
|
if (collect) {
|
|
2398
2405
|
const v = object5[key];
|
|
2399
2406
|
if (Array.isArray(v)) {
|
|
@@ -2524,7 +2531,7 @@ function parseArgs(args, options) {
|
|
|
2524
2531
|
let key = groups.key;
|
|
2525
2532
|
let value = groups.value;
|
|
2526
2533
|
if (doubleDash2) {
|
|
2527
|
-
if (value) {
|
|
2534
|
+
if (value != null) {
|
|
2528
2535
|
if (booleanSet.has(key)) value = parseBooleanString(value);
|
|
2529
2536
|
setArgument(key, value, arg, true);
|
|
2530
2537
|
continue;
|
|
@@ -2562,6 +2569,10 @@ function parseArgs(args, options) {
|
|
|
2562
2569
|
setArgument(letter, next, arg, true);
|
|
2563
2570
|
continue;
|
|
2564
2571
|
}
|
|
2572
|
+
if (next === "=") {
|
|
2573
|
+
setArgument(letter, "", arg, true);
|
|
2574
|
+
continue argsLoop;
|
|
2575
|
+
}
|
|
2565
2576
|
if (LETTER_REGEXP.test(letter)) {
|
|
2566
2577
|
const groups2 = VALUE_REGEXP.exec(next)?.groups;
|
|
2567
2578
|
if (groups2) {
|
|
@@ -3056,7 +3067,7 @@ Usage:
|
|
|
3056
3067
|
- ${toolName}({ skill: "skill-name" }) - Load main SKILL.md content
|
|
3057
3068
|
- ${toolName}({ skill: "skill-name", ref: "path/to/file" }) - Load reference file
|
|
3058
3069
|
|
|
3059
|
-
Note: For scripts
|
|
3070
|
+
Note: For scripts/, use the bash tool with the script path to execute.`;
|
|
3060
3071
|
}
|
|
3061
3072
|
function createSkillsPlugin(options) {
|
|
3062
3073
|
const { paths } = options;
|
|
@@ -3164,11 +3175,15 @@ Available skills: ${available.join(", ")}` : "\n\nNo skills available.";
|
|
|
3164
3175
|
try {
|
|
3165
3176
|
const content = await (0, import_promises2.readFile)((0, import_node_path4.join)(meta.basePath, "SKILL.md"), "utf-8");
|
|
3166
3177
|
const body = extractBody(content);
|
|
3178
|
+
const skillPathInfo = `
|
|
3179
|
+
---
|
|
3180
|
+
Skill path: ${meta.basePath}
|
|
3181
|
+
`;
|
|
3167
3182
|
return {
|
|
3168
3183
|
content: [
|
|
3169
3184
|
{
|
|
3170
3185
|
type: "text",
|
|
3171
|
-
text: body
|
|
3186
|
+
text: body + skillPathInfo
|
|
3172
3187
|
}
|
|
3173
3188
|
]
|
|
3174
3189
|
};
|
|
@@ -4039,12 +4054,29 @@ function writeFoldedLines(count) {
|
|
|
4039
4054
|
if (count > 1) return "\n".repeat(count - 1);
|
|
4040
4055
|
return "";
|
|
4041
4056
|
}
|
|
4057
|
+
var Scanner = class {
|
|
4058
|
+
source;
|
|
4059
|
+
#length;
|
|
4060
|
+
position = 0;
|
|
4061
|
+
constructor(source) {
|
|
4062
|
+
source += "\0";
|
|
4063
|
+
this.source = source;
|
|
4064
|
+
this.#length = source.length;
|
|
4065
|
+
}
|
|
4066
|
+
peek(offset = 0) {
|
|
4067
|
+
return this.source.charCodeAt(this.position + offset);
|
|
4068
|
+
}
|
|
4069
|
+
next() {
|
|
4070
|
+
this.position += 1;
|
|
4071
|
+
}
|
|
4072
|
+
eof() {
|
|
4073
|
+
return this.position >= this.#length - 1;
|
|
4074
|
+
}
|
|
4075
|
+
};
|
|
4042
4076
|
var LoaderState = class {
|
|
4043
|
-
|
|
4044
|
-
length;
|
|
4077
|
+
#scanner;
|
|
4045
4078
|
lineIndent = 0;
|
|
4046
4079
|
lineStart = 0;
|
|
4047
|
-
position = 0;
|
|
4048
4080
|
line = 0;
|
|
4049
4081
|
onWarning;
|
|
4050
4082
|
allowDuplicateKeys;
|
|
@@ -4054,44 +4086,40 @@ var LoaderState = class {
|
|
|
4054
4086
|
tagMap = /* @__PURE__ */ new Map();
|
|
4055
4087
|
anchorMap = /* @__PURE__ */ new Map();
|
|
4056
4088
|
constructor(input, { schema = DEFAULT_SCHEMA, onWarning, allowDuplicateKeys = false }) {
|
|
4057
|
-
this
|
|
4089
|
+
this.#scanner = new Scanner(input);
|
|
4058
4090
|
this.onWarning = onWarning;
|
|
4059
4091
|
this.allowDuplicateKeys = allowDuplicateKeys;
|
|
4060
4092
|
this.implicitTypes = schema.implicitTypes;
|
|
4061
4093
|
this.typeMap = schema.typeMap;
|
|
4062
|
-
this.length = input.length;
|
|
4063
4094
|
this.readIndent();
|
|
4064
4095
|
}
|
|
4065
4096
|
skipWhitespaces() {
|
|
4066
|
-
let ch = this.peek();
|
|
4097
|
+
let ch = this.#scanner.peek();
|
|
4067
4098
|
while (isWhiteSpace(ch)) {
|
|
4068
|
-
|
|
4099
|
+
this.#scanner.next();
|
|
4100
|
+
ch = this.#scanner.peek();
|
|
4069
4101
|
}
|
|
4070
4102
|
}
|
|
4071
4103
|
skipComment() {
|
|
4072
|
-
let ch = this.peek();
|
|
4104
|
+
let ch = this.#scanner.peek();
|
|
4073
4105
|
if (ch !== SHARP) return;
|
|
4074
|
-
|
|
4106
|
+
this.#scanner.next();
|
|
4107
|
+
ch = this.#scanner.peek();
|
|
4075
4108
|
while (ch !== 0 && !isEOL(ch)) {
|
|
4076
|
-
|
|
4109
|
+
this.#scanner.next();
|
|
4110
|
+
ch = this.#scanner.peek();
|
|
4077
4111
|
}
|
|
4078
4112
|
}
|
|
4079
4113
|
readIndent() {
|
|
4080
|
-
let
|
|
4081
|
-
while (
|
|
4114
|
+
let ch = this.#scanner.peek();
|
|
4115
|
+
while (ch === SPACE) {
|
|
4082
4116
|
this.lineIndent += 1;
|
|
4083
|
-
|
|
4117
|
+
this.#scanner.next();
|
|
4118
|
+
ch = this.#scanner.peek();
|
|
4084
4119
|
}
|
|
4085
4120
|
}
|
|
4086
|
-
peek(offset = 0) {
|
|
4087
|
-
return this.input.charCodeAt(this.position + offset);
|
|
4088
|
-
}
|
|
4089
|
-
next() {
|
|
4090
|
-
this.position += 1;
|
|
4091
|
-
return this.peek();
|
|
4092
|
-
}
|
|
4093
4121
|
#createError(message) {
|
|
4094
|
-
const mark = markToString(this.
|
|
4122
|
+
const mark = markToString(this.#scanner.source, this.#scanner.position, this.line, this.#scanner.position - this.lineStart);
|
|
4095
4123
|
return new SyntaxError(`${message} ${mark}`);
|
|
4096
4124
|
}
|
|
4097
4125
|
dispatchWarning(message) {
|
|
@@ -4136,7 +4164,7 @@ var LoaderState = class {
|
|
|
4136
4164
|
}
|
|
4137
4165
|
captureSegment(start, end, checkJson) {
|
|
4138
4166
|
if (start < end) {
|
|
4139
|
-
const result = this.
|
|
4167
|
+
const result = this.#scanner.source.slice(start, end);
|
|
4140
4168
|
if (checkJson) {
|
|
4141
4169
|
for (let position = 0; position < result.length; position++) {
|
|
4142
4170
|
const character = result.charCodeAt(position);
|
|
@@ -4154,21 +4182,21 @@ var LoaderState = class {
|
|
|
4154
4182
|
let detected = false;
|
|
4155
4183
|
const result = [];
|
|
4156
4184
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
4157
|
-
let ch = this.peek();
|
|
4185
|
+
let ch = this.#scanner.peek();
|
|
4158
4186
|
while (ch !== 0) {
|
|
4159
4187
|
if (ch !== MINUS) {
|
|
4160
4188
|
break;
|
|
4161
4189
|
}
|
|
4162
|
-
const following = this.peek(1);
|
|
4190
|
+
const following = this.#scanner.peek(1);
|
|
4163
4191
|
if (!isWhiteSpaceOrEOL(following)) {
|
|
4164
4192
|
break;
|
|
4165
4193
|
}
|
|
4166
4194
|
detected = true;
|
|
4167
|
-
this.
|
|
4195
|
+
this.#scanner.next();
|
|
4168
4196
|
if (this.skipSeparationSpace(true, -1)) {
|
|
4169
4197
|
if (this.lineIndent <= nodeIndent) {
|
|
4170
4198
|
result.push(null);
|
|
4171
|
-
ch = this.peek();
|
|
4199
|
+
ch = this.#scanner.peek();
|
|
4172
4200
|
continue;
|
|
4173
4201
|
}
|
|
4174
4202
|
}
|
|
@@ -4181,7 +4209,7 @@ var LoaderState = class {
|
|
|
4181
4209
|
});
|
|
4182
4210
|
if (newState) result.push(newState.result);
|
|
4183
4211
|
this.skipSeparationSpace(true, -1);
|
|
4184
|
-
ch = this.peek();
|
|
4212
|
+
ch = this.#scanner.peek();
|
|
4185
4213
|
if ((this.line === line || this.lineIndent > nodeIndent) && ch !== 0) {
|
|
4186
4214
|
throw this.#createError("Cannot read block sequence: bad indentation of a sequence entry");
|
|
4187
4215
|
} else if (this.lineIndent < nodeIndent) {
|
|
@@ -4237,7 +4265,7 @@ var LoaderState = class {
|
|
|
4237
4265
|
} else {
|
|
4238
4266
|
if (!this.allowDuplicateKeys && !overridableKeys.has(keyNode) && Object.hasOwn(result, keyNode)) {
|
|
4239
4267
|
this.line = startLine || this.line;
|
|
4240
|
-
this.position = startPos || this.position;
|
|
4268
|
+
this.#scanner.position = startPos || this.#scanner.position;
|
|
4241
4269
|
throw this.#createError("Cannot store mapping pair: duplicated key");
|
|
4242
4270
|
}
|
|
4243
4271
|
Object.defineProperty(result, keyNode, {
|
|
@@ -4251,37 +4279,37 @@ var LoaderState = class {
|
|
|
4251
4279
|
return result;
|
|
4252
4280
|
}
|
|
4253
4281
|
readLineBreak() {
|
|
4254
|
-
const ch = this.peek();
|
|
4282
|
+
const ch = this.#scanner.peek();
|
|
4255
4283
|
if (ch === LINE_FEED) {
|
|
4256
|
-
this.
|
|
4284
|
+
this.#scanner.next();
|
|
4257
4285
|
} else if (ch === CARRIAGE_RETURN) {
|
|
4258
|
-
this.
|
|
4259
|
-
if (this.peek() === LINE_FEED) {
|
|
4260
|
-
this.
|
|
4286
|
+
this.#scanner.next();
|
|
4287
|
+
if (this.#scanner.peek() === LINE_FEED) {
|
|
4288
|
+
this.#scanner.next();
|
|
4261
4289
|
}
|
|
4262
4290
|
} else {
|
|
4263
4291
|
throw this.#createError("Cannot read line: line break not found");
|
|
4264
4292
|
}
|
|
4265
4293
|
this.line += 1;
|
|
4266
|
-
this.lineStart = this.position;
|
|
4294
|
+
this.lineStart = this.#scanner.position;
|
|
4267
4295
|
}
|
|
4268
4296
|
skipSeparationSpace(allowComments, checkIndent) {
|
|
4269
4297
|
let lineBreaks = 0;
|
|
4270
|
-
let ch = this.peek();
|
|
4298
|
+
let ch = this.#scanner.peek();
|
|
4271
4299
|
while (ch !== 0) {
|
|
4272
4300
|
this.skipWhitespaces();
|
|
4273
|
-
ch = this.peek();
|
|
4301
|
+
ch = this.#scanner.peek();
|
|
4274
4302
|
if (allowComments) {
|
|
4275
4303
|
this.skipComment();
|
|
4276
|
-
ch = this.peek();
|
|
4304
|
+
ch = this.#scanner.peek();
|
|
4277
4305
|
}
|
|
4278
4306
|
if (isEOL(ch)) {
|
|
4279
4307
|
this.readLineBreak();
|
|
4280
|
-
ch = this.peek();
|
|
4308
|
+
ch = this.#scanner.peek();
|
|
4281
4309
|
lineBreaks++;
|
|
4282
4310
|
this.lineIndent = 0;
|
|
4283
4311
|
this.readIndent();
|
|
4284
|
-
ch = this.peek();
|
|
4312
|
+
ch = this.#scanner.peek();
|
|
4285
4313
|
} else {
|
|
4286
4314
|
break;
|
|
4287
4315
|
}
|
|
@@ -4292,9 +4320,9 @@ var LoaderState = class {
|
|
|
4292
4320
|
return lineBreaks;
|
|
4293
4321
|
}
|
|
4294
4322
|
testDocumentSeparator() {
|
|
4295
|
-
let ch = this.peek();
|
|
4296
|
-
if ((ch === MINUS || ch === DOT) && ch === this.peek(1) && ch === this.peek(2)) {
|
|
4297
|
-
ch = this.peek(3);
|
|
4323
|
+
let ch = this.#scanner.peek();
|
|
4324
|
+
if ((ch === MINUS || ch === DOT) && ch === this.#scanner.peek(1) && ch === this.#scanner.peek(2)) {
|
|
4325
|
+
ch = this.#scanner.peek(3);
|
|
4298
4326
|
if (ch === 0 || isWhiteSpaceOrEOL(ch)) {
|
|
4299
4327
|
return true;
|
|
4300
4328
|
}
|
|
@@ -4302,34 +4330,34 @@ var LoaderState = class {
|
|
|
4302
4330
|
return false;
|
|
4303
4331
|
}
|
|
4304
4332
|
readPlainScalar(tag, anchor, nodeIndent, withinFlowCollection) {
|
|
4305
|
-
let ch = this.peek();
|
|
4333
|
+
let ch = this.#scanner.peek();
|
|
4306
4334
|
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) {
|
|
4307
4335
|
return;
|
|
4308
4336
|
}
|
|
4309
4337
|
let following;
|
|
4310
4338
|
if (ch === QUESTION || ch === MINUS) {
|
|
4311
|
-
following = this.peek(1);
|
|
4339
|
+
following = this.#scanner.peek(1);
|
|
4312
4340
|
if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
|
|
4313
4341
|
return;
|
|
4314
4342
|
}
|
|
4315
4343
|
}
|
|
4316
4344
|
let result = "";
|
|
4317
|
-
let captureEnd = this.position;
|
|
4318
|
-
let captureStart = this.position;
|
|
4345
|
+
let captureEnd = this.#scanner.position;
|
|
4346
|
+
let captureStart = this.#scanner.position;
|
|
4319
4347
|
let hasPendingContent = false;
|
|
4320
4348
|
let line = 0;
|
|
4321
4349
|
while (ch !== 0) {
|
|
4322
4350
|
if (ch === COLON) {
|
|
4323
|
-
following = this.peek(1);
|
|
4351
|
+
following = this.#scanner.peek(1);
|
|
4324
4352
|
if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
|
|
4325
4353
|
break;
|
|
4326
4354
|
}
|
|
4327
4355
|
} else if (ch === SHARP) {
|
|
4328
|
-
const preceding = this.peek(-1);
|
|
4356
|
+
const preceding = this.#scanner.peek(-1);
|
|
4329
4357
|
if (isWhiteSpaceOrEOL(preceding)) {
|
|
4330
4358
|
break;
|
|
4331
4359
|
}
|
|
4332
|
-
} else if (this.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
|
|
4360
|
+
} else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
|
|
4333
4361
|
break;
|
|
4334
4362
|
} else if (isEOL(ch)) {
|
|
4335
4363
|
line = this.line;
|
|
@@ -4338,10 +4366,10 @@ var LoaderState = class {
|
|
|
4338
4366
|
this.skipSeparationSpace(false, -1);
|
|
4339
4367
|
if (this.lineIndent >= nodeIndent) {
|
|
4340
4368
|
hasPendingContent = true;
|
|
4341
|
-
ch = this.peek();
|
|
4369
|
+
ch = this.#scanner.peek();
|
|
4342
4370
|
continue;
|
|
4343
4371
|
} else {
|
|
4344
|
-
this.position = captureEnd;
|
|
4372
|
+
this.#scanner.position = captureEnd;
|
|
4345
4373
|
this.line = line;
|
|
4346
4374
|
this.lineStart = lineStart;
|
|
4347
4375
|
this.lineIndent = lineIndent;
|
|
@@ -4352,13 +4380,14 @@ var LoaderState = class {
|
|
|
4352
4380
|
const segment2 = this.captureSegment(captureStart, captureEnd, false);
|
|
4353
4381
|
if (segment2) result += segment2;
|
|
4354
4382
|
result += writeFoldedLines(this.line - line);
|
|
4355
|
-
captureStart = captureEnd = this.position;
|
|
4383
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
4356
4384
|
hasPendingContent = false;
|
|
4357
4385
|
}
|
|
4358
4386
|
if (!isWhiteSpace(ch)) {
|
|
4359
|
-
captureEnd = this.position + 1;
|
|
4387
|
+
captureEnd = this.#scanner.position + 1;
|
|
4360
4388
|
}
|
|
4361
|
-
|
|
4389
|
+
this.#scanner.next();
|
|
4390
|
+
ch = this.#scanner.peek();
|
|
4362
4391
|
}
|
|
4363
4392
|
const segment = this.captureSegment(captureStart, captureEnd, false);
|
|
4364
4393
|
if (segment) result += segment;
|
|
@@ -4371,22 +4400,23 @@ var LoaderState = class {
|
|
|
4371
4400
|
};
|
|
4372
4401
|
}
|
|
4373
4402
|
readSingleQuotedScalar(tag, anchor, nodeIndent) {
|
|
4374
|
-
let ch = this.peek();
|
|
4403
|
+
let ch = this.#scanner.peek();
|
|
4375
4404
|
if (ch !== SINGLE_QUOTE) return;
|
|
4376
4405
|
let result = "";
|
|
4377
|
-
this.
|
|
4378
|
-
let captureStart = this.position;
|
|
4379
|
-
let captureEnd = this.position;
|
|
4380
|
-
ch = this.peek();
|
|
4406
|
+
this.#scanner.next();
|
|
4407
|
+
let captureStart = this.#scanner.position;
|
|
4408
|
+
let captureEnd = this.#scanner.position;
|
|
4409
|
+
ch = this.#scanner.peek();
|
|
4381
4410
|
while (ch !== 0) {
|
|
4382
4411
|
if (ch === SINGLE_QUOTE) {
|
|
4383
|
-
const segment = this.captureSegment(captureStart, this.position, true);
|
|
4412
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, true);
|
|
4384
4413
|
if (segment) result += segment;
|
|
4385
|
-
|
|
4414
|
+
this.#scanner.next();
|
|
4415
|
+
ch = this.#scanner.peek();
|
|
4386
4416
|
if (ch === SINGLE_QUOTE) {
|
|
4387
|
-
captureStart = this.position;
|
|
4388
|
-
this.
|
|
4389
|
-
captureEnd = this.position;
|
|
4417
|
+
captureStart = this.#scanner.position;
|
|
4418
|
+
this.#scanner.next();
|
|
4419
|
+
captureEnd = this.#scanner.position;
|
|
4390
4420
|
} else {
|
|
4391
4421
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
4392
4422
|
return {
|
|
@@ -4400,31 +4430,31 @@ var LoaderState = class {
|
|
|
4400
4430
|
const segment = this.captureSegment(captureStart, captureEnd, true);
|
|
4401
4431
|
if (segment) result += segment;
|
|
4402
4432
|
result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
|
|
4403
|
-
captureStart = captureEnd = this.position;
|
|
4404
|
-
} else if (this.position === this.lineStart && this.testDocumentSeparator()) {
|
|
4433
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
4434
|
+
} else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
|
|
4405
4435
|
throw this.#createError("Unexpected end of the document within a single quoted scalar");
|
|
4406
4436
|
} else {
|
|
4407
|
-
this.
|
|
4408
|
-
captureEnd = this.position;
|
|
4437
|
+
this.#scanner.next();
|
|
4438
|
+
captureEnd = this.#scanner.position;
|
|
4409
4439
|
}
|
|
4410
|
-
ch = this.peek();
|
|
4440
|
+
ch = this.#scanner.peek();
|
|
4411
4441
|
}
|
|
4412
4442
|
throw this.#createError("Unexpected end of the stream within a single quoted scalar");
|
|
4413
4443
|
}
|
|
4414
4444
|
readDoubleQuotedScalar(tag, anchor, nodeIndent) {
|
|
4415
|
-
let ch = this.peek();
|
|
4445
|
+
let ch = this.#scanner.peek();
|
|
4416
4446
|
if (ch !== DOUBLE_QUOTE) return;
|
|
4417
4447
|
let result = "";
|
|
4418
|
-
this.
|
|
4419
|
-
let captureEnd = this.position;
|
|
4420
|
-
let captureStart = this.position;
|
|
4448
|
+
this.#scanner.next();
|
|
4449
|
+
let captureEnd = this.#scanner.position;
|
|
4450
|
+
let captureStart = this.#scanner.position;
|
|
4421
4451
|
let tmp;
|
|
4422
|
-
ch = this.peek();
|
|
4452
|
+
ch = this.#scanner.peek();
|
|
4423
4453
|
while (ch !== 0) {
|
|
4424
4454
|
if (ch === DOUBLE_QUOTE) {
|
|
4425
|
-
const segment = this.captureSegment(captureStart, this.position, true);
|
|
4455
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, true);
|
|
4426
4456
|
if (segment) result += segment;
|
|
4427
|
-
this.
|
|
4457
|
+
this.#scanner.next();
|
|
4428
4458
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
4429
4459
|
return {
|
|
4430
4460
|
tag,
|
|
@@ -4434,19 +4464,21 @@ var LoaderState = class {
|
|
|
4434
4464
|
};
|
|
4435
4465
|
}
|
|
4436
4466
|
if (ch === BACKSLASH) {
|
|
4437
|
-
const segment = this.captureSegment(captureStart, this.position, true);
|
|
4467
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, true);
|
|
4438
4468
|
if (segment) result += segment;
|
|
4439
|
-
|
|
4469
|
+
this.#scanner.next();
|
|
4470
|
+
ch = this.#scanner.peek();
|
|
4440
4471
|
if (isEOL(ch)) {
|
|
4441
4472
|
this.skipSeparationSpace(false, nodeIndent);
|
|
4442
4473
|
} else if (ch < 256 && SIMPLE_ESCAPE_SEQUENCES.has(ch)) {
|
|
4443
4474
|
result += SIMPLE_ESCAPE_SEQUENCES.get(ch);
|
|
4444
|
-
this.
|
|
4475
|
+
this.#scanner.next();
|
|
4445
4476
|
} else if ((tmp = ESCAPED_HEX_LENGTHS.get(ch) ?? 0) > 0) {
|
|
4446
4477
|
let hexLength = tmp;
|
|
4447
4478
|
let hexResult = 0;
|
|
4448
4479
|
for (; hexLength > 0; hexLength--) {
|
|
4449
|
-
|
|
4480
|
+
this.#scanner.next();
|
|
4481
|
+
ch = this.#scanner.peek();
|
|
4450
4482
|
if ((tmp = hexCharCodeToNumber(ch)) >= 0) {
|
|
4451
4483
|
hexResult = (hexResult << 4) + tmp;
|
|
4452
4484
|
} else {
|
|
@@ -4454,28 +4486,28 @@ var LoaderState = class {
|
|
|
4454
4486
|
}
|
|
4455
4487
|
}
|
|
4456
4488
|
result += codepointToChar(hexResult);
|
|
4457
|
-
this.
|
|
4489
|
+
this.#scanner.next();
|
|
4458
4490
|
} else {
|
|
4459
4491
|
throw this.#createError("Cannot read double quoted scalar: unknown escape sequence");
|
|
4460
4492
|
}
|
|
4461
|
-
captureStart = captureEnd = this.position;
|
|
4493
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
4462
4494
|
} else if (isEOL(ch)) {
|
|
4463
4495
|
const segment = this.captureSegment(captureStart, captureEnd, true);
|
|
4464
4496
|
if (segment) result += segment;
|
|
4465
4497
|
result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
|
|
4466
|
-
captureStart = captureEnd = this.position;
|
|
4467
|
-
} else if (this.position === this.lineStart && this.testDocumentSeparator()) {
|
|
4498
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
4499
|
+
} else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
|
|
4468
4500
|
throw this.#createError("Unexpected end of the document within a double quoted scalar");
|
|
4469
4501
|
} else {
|
|
4470
|
-
this.
|
|
4471
|
-
captureEnd = this.position;
|
|
4502
|
+
this.#scanner.next();
|
|
4503
|
+
captureEnd = this.#scanner.position;
|
|
4472
4504
|
}
|
|
4473
|
-
ch = this.peek();
|
|
4505
|
+
ch = this.#scanner.peek();
|
|
4474
4506
|
}
|
|
4475
4507
|
throw this.#createError("Unexpected end of the stream within a double quoted scalar");
|
|
4476
4508
|
}
|
|
4477
4509
|
readFlowCollection(tag, anchor, nodeIndent) {
|
|
4478
|
-
let ch = this.peek();
|
|
4510
|
+
let ch = this.#scanner.peek();
|
|
4479
4511
|
let terminator;
|
|
4480
4512
|
let isMapping = true;
|
|
4481
4513
|
let result = {};
|
|
@@ -4489,7 +4521,8 @@ var LoaderState = class {
|
|
|
4489
4521
|
return;
|
|
4490
4522
|
}
|
|
4491
4523
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
4492
|
-
|
|
4524
|
+
this.#scanner.next();
|
|
4525
|
+
ch = this.#scanner.peek();
|
|
4493
4526
|
let readNext = true;
|
|
4494
4527
|
let valueNode = null;
|
|
4495
4528
|
let keyNode = null;
|
|
@@ -4501,9 +4534,9 @@ var LoaderState = class {
|
|
|
4501
4534
|
const overridableKeys = /* @__PURE__ */ new Set();
|
|
4502
4535
|
while (ch !== 0) {
|
|
4503
4536
|
this.skipSeparationSpace(true, nodeIndent);
|
|
4504
|
-
ch = this.peek();
|
|
4537
|
+
ch = this.#scanner.peek();
|
|
4505
4538
|
if (ch === terminator) {
|
|
4506
|
-
this.
|
|
4539
|
+
this.#scanner.next();
|
|
4507
4540
|
const kind = isMapping ? "mapping" : "sequence";
|
|
4508
4541
|
return {
|
|
4509
4542
|
tag,
|
|
@@ -4518,10 +4551,10 @@ var LoaderState = class {
|
|
|
4518
4551
|
keyTag = keyNode = valueNode = null;
|
|
4519
4552
|
isPair = isExplicitPair = false;
|
|
4520
4553
|
if (ch === QUESTION) {
|
|
4521
|
-
following = this.peek(1);
|
|
4554
|
+
following = this.#scanner.peek(1);
|
|
4522
4555
|
if (isWhiteSpaceOrEOL(following)) {
|
|
4523
4556
|
isPair = isExplicitPair = true;
|
|
4524
|
-
this.
|
|
4557
|
+
this.#scanner.next();
|
|
4525
4558
|
this.skipSeparationSpace(true, nodeIndent);
|
|
4526
4559
|
}
|
|
4527
4560
|
}
|
|
@@ -4537,10 +4570,11 @@ var LoaderState = class {
|
|
|
4537
4570
|
keyNode = newState.result;
|
|
4538
4571
|
}
|
|
4539
4572
|
this.skipSeparationSpace(true, nodeIndent);
|
|
4540
|
-
ch = this.peek();
|
|
4573
|
+
ch = this.#scanner.peek();
|
|
4541
4574
|
if ((isExplicitPair || this.line === line) && ch === COLON) {
|
|
4542
4575
|
isPair = true;
|
|
4543
|
-
|
|
4576
|
+
this.#scanner.next();
|
|
4577
|
+
ch = this.#scanner.peek();
|
|
4544
4578
|
this.skipSeparationSpace(true, nodeIndent);
|
|
4545
4579
|
const newState2 = this.composeNode({
|
|
4546
4580
|
parentIndent: nodeIndent,
|
|
@@ -4558,10 +4592,11 @@ var LoaderState = class {
|
|
|
4558
4592
|
result.push(keyNode);
|
|
4559
4593
|
}
|
|
4560
4594
|
this.skipSeparationSpace(true, nodeIndent);
|
|
4561
|
-
ch = this.peek();
|
|
4595
|
+
ch = this.#scanner.peek();
|
|
4562
4596
|
if (ch === COMMA) {
|
|
4563
4597
|
readNext = true;
|
|
4564
|
-
|
|
4598
|
+
this.#scanner.next();
|
|
4599
|
+
ch = this.#scanner.peek();
|
|
4565
4600
|
} else {
|
|
4566
4601
|
readNext = false;
|
|
4567
4602
|
}
|
|
@@ -4577,7 +4612,7 @@ var LoaderState = class {
|
|
|
4577
4612
|
let textIndent = nodeIndent;
|
|
4578
4613
|
let emptyLines = 0;
|
|
4579
4614
|
let atMoreIndented = false;
|
|
4580
|
-
let ch = this.peek();
|
|
4615
|
+
let ch = this.#scanner.peek();
|
|
4581
4616
|
let folding = false;
|
|
4582
4617
|
if (ch === VERTICAL_LINE) {
|
|
4583
4618
|
folding = false;
|
|
@@ -4589,7 +4624,8 @@ var LoaderState = class {
|
|
|
4589
4624
|
let result = "";
|
|
4590
4625
|
let tmp = 0;
|
|
4591
4626
|
while (ch !== 0) {
|
|
4592
|
-
|
|
4627
|
+
this.#scanner.next();
|
|
4628
|
+
ch = this.#scanner.peek();
|
|
4593
4629
|
if (ch === PLUS || ch === MINUS) {
|
|
4594
4630
|
if (CHOMPING_CLIP === chomping) {
|
|
4595
4631
|
chomping = ch === PLUS ? CHOMPING_KEEP : CHOMPING_STRIP;
|
|
@@ -4612,15 +4648,16 @@ var LoaderState = class {
|
|
|
4612
4648
|
if (isWhiteSpace(ch)) {
|
|
4613
4649
|
this.skipWhitespaces();
|
|
4614
4650
|
this.skipComment();
|
|
4615
|
-
ch = this.peek();
|
|
4651
|
+
ch = this.#scanner.peek();
|
|
4616
4652
|
}
|
|
4617
4653
|
while (ch !== 0) {
|
|
4618
4654
|
this.readLineBreak();
|
|
4619
4655
|
this.lineIndent = 0;
|
|
4620
|
-
ch = this.peek();
|
|
4656
|
+
ch = this.#scanner.peek();
|
|
4621
4657
|
while ((!detectedIndent || this.lineIndent < textIndent) && ch === SPACE) {
|
|
4622
4658
|
this.lineIndent++;
|
|
4623
|
-
|
|
4659
|
+
this.#scanner.next();
|
|
4660
|
+
ch = this.#scanner.peek();
|
|
4624
4661
|
}
|
|
4625
4662
|
if (!detectedIndent && this.lineIndent > textIndent) {
|
|
4626
4663
|
textIndent = this.lineIndent;
|
|
@@ -4659,11 +4696,12 @@ var LoaderState = class {
|
|
|
4659
4696
|
didReadContent = true;
|
|
4660
4697
|
detectedIndent = true;
|
|
4661
4698
|
emptyLines = 0;
|
|
4662
|
-
const captureStart = this.position;
|
|
4699
|
+
const captureStart = this.#scanner.position;
|
|
4663
4700
|
while (!isEOL(ch) && ch !== 0) {
|
|
4664
|
-
|
|
4701
|
+
this.#scanner.next();
|
|
4702
|
+
ch = this.#scanner.peek();
|
|
4665
4703
|
}
|
|
4666
|
-
const segment = this.captureSegment(captureStart, this.position, false);
|
|
4704
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, false);
|
|
4667
4705
|
if (segment) result += segment;
|
|
4668
4706
|
}
|
|
4669
4707
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
@@ -4686,11 +4724,11 @@ var LoaderState = class {
|
|
|
4686
4724
|
let atExplicitKey = false;
|
|
4687
4725
|
let detected = false;
|
|
4688
4726
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
4689
|
-
let ch = this.peek();
|
|
4727
|
+
let ch = this.#scanner.peek();
|
|
4690
4728
|
while (ch !== 0) {
|
|
4691
|
-
const following = this.peek(1);
|
|
4729
|
+
const following = this.#scanner.peek(1);
|
|
4692
4730
|
line = this.line;
|
|
4693
|
-
pos = this.position;
|
|
4731
|
+
pos = this.#scanner.position;
|
|
4694
4732
|
if ((ch === QUESTION || ch === COLON) && isWhiteSpaceOrEOL(following)) {
|
|
4695
4733
|
if (ch === QUESTION) {
|
|
4696
4734
|
if (atExplicitKey) {
|
|
@@ -4708,7 +4746,7 @@ var LoaderState = class {
|
|
|
4708
4746
|
} else {
|
|
4709
4747
|
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");
|
|
4710
4748
|
}
|
|
4711
|
-
this.
|
|
4749
|
+
this.#scanner.next();
|
|
4712
4750
|
ch = following;
|
|
4713
4751
|
} else {
|
|
4714
4752
|
const newState = this.composeNode({
|
|
@@ -4719,11 +4757,12 @@ var LoaderState = class {
|
|
|
4719
4757
|
});
|
|
4720
4758
|
if (!newState) break;
|
|
4721
4759
|
if (this.line === line) {
|
|
4722
|
-
ch = this.peek();
|
|
4760
|
+
ch = this.#scanner.peek();
|
|
4723
4761
|
this.skipWhitespaces();
|
|
4724
|
-
ch = this.peek();
|
|
4762
|
+
ch = this.#scanner.peek();
|
|
4725
4763
|
if (ch === COLON) {
|
|
4726
|
-
|
|
4764
|
+
this.#scanner.next();
|
|
4765
|
+
ch = this.#scanner.peek();
|
|
4727
4766
|
if (!isWhiteSpaceOrEOL(ch)) {
|
|
4728
4767
|
throw this.#createError("Cannot read block: a whitespace character is expected after the key-value separator within a block mapping");
|
|
4729
4768
|
}
|
|
@@ -4780,7 +4819,7 @@ var LoaderState = class {
|
|
|
4780
4819
|
keyTag = keyNode = valueNode = null;
|
|
4781
4820
|
}
|
|
4782
4821
|
this.skipSeparationSpace(true, -1);
|
|
4783
|
-
ch = this.peek();
|
|
4822
|
+
ch = this.#scanner.peek();
|
|
4784
4823
|
}
|
|
4785
4824
|
if (this.lineIndent > nodeIndent && ch !== 0) {
|
|
4786
4825
|
throw this.#createError("Cannot read block: bad indentation of a mapping entry");
|
|
@@ -4803,30 +4842,35 @@ var LoaderState = class {
|
|
|
4803
4842
|
let isNamed = false;
|
|
4804
4843
|
let tagHandle = "";
|
|
4805
4844
|
let tagName;
|
|
4806
|
-
let ch = this.peek();
|
|
4845
|
+
let ch = this.#scanner.peek();
|
|
4807
4846
|
if (ch !== EXCLAMATION) return;
|
|
4808
4847
|
if (tag !== null) {
|
|
4809
4848
|
throw this.#createError("Cannot read tag property: duplication of a tag property");
|
|
4810
4849
|
}
|
|
4811
|
-
|
|
4850
|
+
this.#scanner.next();
|
|
4851
|
+
ch = this.#scanner.peek();
|
|
4812
4852
|
if (ch === SMALLER_THAN) {
|
|
4813
4853
|
isVerbatim = true;
|
|
4814
|
-
|
|
4854
|
+
this.#scanner.next();
|
|
4855
|
+
ch = this.#scanner.peek();
|
|
4815
4856
|
} else if (ch === EXCLAMATION) {
|
|
4816
4857
|
isNamed = true;
|
|
4817
4858
|
tagHandle = "!!";
|
|
4818
|
-
|
|
4859
|
+
this.#scanner.next();
|
|
4860
|
+
ch = this.#scanner.peek();
|
|
4819
4861
|
} else {
|
|
4820
4862
|
tagHandle = "!";
|
|
4821
4863
|
}
|
|
4822
|
-
let position = this.position;
|
|
4864
|
+
let position = this.#scanner.position;
|
|
4823
4865
|
if (isVerbatim) {
|
|
4824
4866
|
do {
|
|
4825
|
-
|
|
4867
|
+
this.#scanner.next();
|
|
4868
|
+
ch = this.#scanner.peek();
|
|
4826
4869
|
} while (ch !== 0 && ch !== GREATER_THAN);
|
|
4827
|
-
if (this.
|
|
4828
|
-
tagName = this.
|
|
4829
|
-
|
|
4870
|
+
if (!this.#scanner.eof()) {
|
|
4871
|
+
tagName = this.#scanner.source.slice(position, this.#scanner.position);
|
|
4872
|
+
this.#scanner.next();
|
|
4873
|
+
ch = this.#scanner.peek();
|
|
4830
4874
|
} else {
|
|
4831
4875
|
throw this.#createError("Cannot read tag property: unexpected end of stream");
|
|
4832
4876
|
}
|
|
@@ -4834,19 +4878,20 @@ var LoaderState = class {
|
|
|
4834
4878
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
|
|
4835
4879
|
if (ch === EXCLAMATION) {
|
|
4836
4880
|
if (!isNamed) {
|
|
4837
|
-
tagHandle = this.
|
|
4881
|
+
tagHandle = this.#scanner.source.slice(position - 1, this.#scanner.position + 1);
|
|
4838
4882
|
if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
|
4839
4883
|
throw this.#createError("Cannot read tag property: named tag handle contains invalid characters");
|
|
4840
4884
|
}
|
|
4841
4885
|
isNamed = true;
|
|
4842
|
-
position = this.position + 1;
|
|
4886
|
+
position = this.#scanner.position + 1;
|
|
4843
4887
|
} else {
|
|
4844
4888
|
throw this.#createError("Cannot read tag property: tag suffix cannot contain an exclamation mark");
|
|
4845
4889
|
}
|
|
4846
4890
|
}
|
|
4847
|
-
|
|
4891
|
+
this.#scanner.next();
|
|
4892
|
+
ch = this.#scanner.peek();
|
|
4848
4893
|
}
|
|
4849
|
-
tagName = this.
|
|
4894
|
+
tagName = this.#scanner.source.slice(position, this.#scanner.position);
|
|
4850
4895
|
if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
|
4851
4896
|
throw this.#createError("Cannot read tag property: tag suffix cannot contain flow indicator characters");
|
|
4852
4897
|
}
|
|
@@ -4866,32 +4911,36 @@ var LoaderState = class {
|
|
|
4866
4911
|
throw this.#createError(`Cannot read tag property: undeclared tag handle "${tagHandle}"`);
|
|
4867
4912
|
}
|
|
4868
4913
|
readAnchorProperty(anchor) {
|
|
4869
|
-
let ch = this.peek();
|
|
4914
|
+
let ch = this.#scanner.peek();
|
|
4870
4915
|
if (ch !== AMPERSAND) return;
|
|
4871
4916
|
if (anchor !== null) {
|
|
4872
4917
|
throw this.#createError("Cannot read anchor property: duplicate anchor property");
|
|
4873
4918
|
}
|
|
4874
|
-
|
|
4875
|
-
|
|
4919
|
+
this.#scanner.next();
|
|
4920
|
+
ch = this.#scanner.peek();
|
|
4921
|
+
const position = this.#scanner.position;
|
|
4876
4922
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
|
|
4877
|
-
|
|
4923
|
+
this.#scanner.next();
|
|
4924
|
+
ch = this.#scanner.peek();
|
|
4878
4925
|
}
|
|
4879
|
-
if (this.position === position) {
|
|
4926
|
+
if (this.#scanner.position === position) {
|
|
4880
4927
|
throw this.#createError("Cannot read anchor property: name of an anchor node must contain at least one character");
|
|
4881
4928
|
}
|
|
4882
|
-
return this.
|
|
4929
|
+
return this.#scanner.source.slice(position, this.#scanner.position);
|
|
4883
4930
|
}
|
|
4884
4931
|
readAlias() {
|
|
4885
|
-
if (this.peek() !== ASTERISK) return;
|
|
4886
|
-
|
|
4887
|
-
|
|
4932
|
+
if (this.#scanner.peek() !== ASTERISK) return;
|
|
4933
|
+
this.#scanner.next();
|
|
4934
|
+
let ch = this.#scanner.peek();
|
|
4935
|
+
const position = this.#scanner.position;
|
|
4888
4936
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
|
|
4889
|
-
|
|
4937
|
+
this.#scanner.next();
|
|
4938
|
+
ch = this.#scanner.peek();
|
|
4890
4939
|
}
|
|
4891
|
-
if (this.position === position) {
|
|
4940
|
+
if (this.#scanner.position === position) {
|
|
4892
4941
|
throw this.#createError("Cannot read alias: alias name must contain at least one character");
|
|
4893
4942
|
}
|
|
4894
|
-
const alias = this.
|
|
4943
|
+
const alias = this.#scanner.source.slice(position, this.#scanner.position);
|
|
4895
4944
|
if (!this.anchorMap.has(alias)) {
|
|
4896
4945
|
throw this.#createError(`Cannot read alias: unidentified alias "${alias}"`);
|
|
4897
4946
|
}
|
|
@@ -4974,7 +5023,7 @@ var LoaderState = class {
|
|
|
4974
5023
|
const cond = CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext;
|
|
4975
5024
|
const flowIndent = cond ? parentIndent : parentIndent + 1;
|
|
4976
5025
|
if (allowBlockCollections) {
|
|
4977
|
-
const blockIndent = this.position - this.lineStart;
|
|
5026
|
+
const blockIndent = this.#scanner.position - this.lineStart;
|
|
4978
5027
|
const blockSequenceState = this.readBlockSequence(tag, anchor, blockIndent);
|
|
4979
5028
|
if (blockSequenceState) return this.resolveTag(blockSequenceState);
|
|
4980
5029
|
const blockMappingState = this.readBlockMapping(tag, anchor, blockIndent, flowIndent);
|
|
@@ -5008,7 +5057,7 @@ var LoaderState = class {
|
|
|
5008
5057
|
return this.resolveTag(plainScalarState);
|
|
5009
5058
|
}
|
|
5010
5059
|
} else if (indentStatus === 0 && CONTEXT_BLOCK_OUT === nodeContext && allowBlockCollections) {
|
|
5011
|
-
const blockIndent = this.position - this.lineStart;
|
|
5060
|
+
const blockIndent = this.#scanner.position - this.lineStart;
|
|
5012
5061
|
const newState2 = this.readBlockSequence(tag, anchor, blockIndent);
|
|
5013
5062
|
if (newState2) return this.resolveTag(newState2);
|
|
5014
5063
|
}
|
|
@@ -5023,20 +5072,22 @@ var LoaderState = class {
|
|
|
5023
5072
|
readDirectives() {
|
|
5024
5073
|
let hasDirectives = false;
|
|
5025
5074
|
let version = null;
|
|
5026
|
-
let ch = this.peek();
|
|
5075
|
+
let ch = this.#scanner.peek();
|
|
5027
5076
|
while (ch !== 0) {
|
|
5028
5077
|
this.skipSeparationSpace(true, -1);
|
|
5029
|
-
ch = this.peek();
|
|
5078
|
+
ch = this.#scanner.peek();
|
|
5030
5079
|
if (this.lineIndent > 0 || ch !== PERCENT) {
|
|
5031
5080
|
break;
|
|
5032
5081
|
}
|
|
5033
5082
|
hasDirectives = true;
|
|
5034
|
-
|
|
5035
|
-
|
|
5083
|
+
this.#scanner.next();
|
|
5084
|
+
ch = this.#scanner.peek();
|
|
5085
|
+
let position = this.#scanner.position;
|
|
5036
5086
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
|
|
5037
|
-
|
|
5087
|
+
this.#scanner.next();
|
|
5088
|
+
ch = this.#scanner.peek();
|
|
5038
5089
|
}
|
|
5039
|
-
const directiveName = this.
|
|
5090
|
+
const directiveName = this.#scanner.source.slice(position, this.#scanner.position);
|
|
5040
5091
|
const directiveArgs = [];
|
|
5041
5092
|
if (directiveName.length < 1) {
|
|
5042
5093
|
throw this.#createError("Cannot read document: directive name length must be greater than zero");
|
|
@@ -5044,13 +5095,14 @@ var LoaderState = class {
|
|
|
5044
5095
|
while (ch !== 0) {
|
|
5045
5096
|
this.skipWhitespaces();
|
|
5046
5097
|
this.skipComment();
|
|
5047
|
-
ch = this.peek();
|
|
5098
|
+
ch = this.#scanner.peek();
|
|
5048
5099
|
if (isEOL(ch)) break;
|
|
5049
|
-
position = this.position;
|
|
5100
|
+
position = this.#scanner.position;
|
|
5050
5101
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
|
|
5051
|
-
|
|
5102
|
+
this.#scanner.next();
|
|
5103
|
+
ch = this.#scanner.peek();
|
|
5052
5104
|
}
|
|
5053
|
-
directiveArgs.push(this.
|
|
5105
|
+
directiveArgs.push(this.#scanner.source.slice(position, this.#scanner.position));
|
|
5054
5106
|
}
|
|
5055
5107
|
if (ch !== 0) this.readLineBreak();
|
|
5056
5108
|
switch (directiveName) {
|
|
@@ -5067,20 +5119,20 @@ var LoaderState = class {
|
|
|
5067
5119
|
this.dispatchWarning(`unknown document directive "${directiveName}"`);
|
|
5068
5120
|
break;
|
|
5069
5121
|
}
|
|
5070
|
-
ch = this.peek();
|
|
5122
|
+
ch = this.#scanner.peek();
|
|
5071
5123
|
}
|
|
5072
5124
|
return hasDirectives;
|
|
5073
5125
|
}
|
|
5074
5126
|
readDocument() {
|
|
5075
|
-
const documentStart = this.position;
|
|
5127
|
+
const documentStart = this.#scanner.position;
|
|
5076
5128
|
this.checkLineBreaks = false;
|
|
5077
5129
|
this.tagMap = /* @__PURE__ */ new Map();
|
|
5078
5130
|
this.anchorMap = /* @__PURE__ */ new Map();
|
|
5079
5131
|
const hasDirectives = this.readDirectives();
|
|
5080
5132
|
this.skipSeparationSpace(true, -1);
|
|
5081
5133
|
let result = null;
|
|
5082
|
-
if (this.lineIndent === 0 && this.peek() === MINUS && this.peek(1) === MINUS && this.peek(2) === MINUS) {
|
|
5083
|
-
this.position += 3;
|
|
5134
|
+
if (this.lineIndent === 0 && this.#scanner.peek() === MINUS && this.#scanner.peek(1) === MINUS && this.#scanner.peek(2) === MINUS) {
|
|
5135
|
+
this.#scanner.position += 3;
|
|
5084
5136
|
this.skipSeparationSpace(true, -1);
|
|
5085
5137
|
} else if (hasDirectives) {
|
|
5086
5138
|
throw this.#createError("Cannot read document: directives end mark is expected");
|
|
@@ -5093,21 +5145,21 @@ var LoaderState = class {
|
|
|
5093
5145
|
});
|
|
5094
5146
|
if (newState) result = newState.result;
|
|
5095
5147
|
this.skipSeparationSpace(true, -1);
|
|
5096
|
-
if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.
|
|
5148
|
+
if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.#scanner.source.slice(documentStart, this.#scanner.position))) {
|
|
5097
5149
|
this.dispatchWarning("non-ASCII line breaks are interpreted as content");
|
|
5098
5150
|
}
|
|
5099
|
-
if (this.position === this.lineStart && this.testDocumentSeparator()) {
|
|
5100
|
-
if (this.peek() === DOT) {
|
|
5101
|
-
this.position += 3;
|
|
5151
|
+
if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
|
|
5152
|
+
if (this.#scanner.peek() === DOT) {
|
|
5153
|
+
this.#scanner.position += 3;
|
|
5102
5154
|
this.skipSeparationSpace(true, -1);
|
|
5103
5155
|
}
|
|
5104
|
-
} else if (this.
|
|
5156
|
+
} else if (!this.#scanner.eof()) {
|
|
5105
5157
|
throw this.#createError("Cannot read document: end of the stream or a document separator is expected");
|
|
5106
5158
|
}
|
|
5107
5159
|
return result;
|
|
5108
5160
|
}
|
|
5109
5161
|
*readDocuments() {
|
|
5110
|
-
while (this.
|
|
5162
|
+
while (!this.#scanner.eof()) {
|
|
5111
5163
|
yield this.readDocument();
|
|
5112
5164
|
}
|
|
5113
5165
|
}
|
|
@@ -5120,7 +5172,6 @@ function sanitizeInput(input) {
|
|
|
5120
5172
|
if (!isEOL(input.charCodeAt(input.length - 1))) input += "\n";
|
|
5121
5173
|
if (input.charCodeAt(0) === 65279) input = input.slice(1);
|
|
5122
5174
|
}
|
|
5123
|
-
input += "\0";
|
|
5124
5175
|
return input;
|
|
5125
5176
|
}
|
|
5126
5177
|
function parse(content, options = {}) {
|
|
@@ -5280,7 +5331,7 @@ function getDefaultAgents() {
|
|
|
5280
5331
|
}
|
|
5281
5332
|
|
|
5282
5333
|
// __mcpc__cli_latest/node_modules/@mcpc/cli/src/config/loader.js
|
|
5283
|
-
var CLI_VERSION = "0.1.
|
|
5334
|
+
var CLI_VERSION = "0.1.51";
|
|
5284
5335
|
function extractServerName(command, commandArgs) {
|
|
5285
5336
|
for (const arg of commandArgs) {
|
|
5286
5337
|
if (!arg.startsWith("-")) {
|
|
@@ -6889,6 +6940,147 @@ var ExperimentalServerTasks = class {
|
|
|
6889
6940
|
requestStream(request, resultSchema, options) {
|
|
6890
6941
|
return this._server.requestStream(request, resultSchema, options);
|
|
6891
6942
|
}
|
|
6943
|
+
/**
|
|
6944
|
+
* Sends a sampling request and returns an AsyncGenerator that yields response messages.
|
|
6945
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
6946
|
+
*
|
|
6947
|
+
* For task-augmented requests, yields 'taskCreated' and 'taskStatus' messages
|
|
6948
|
+
* before the final result.
|
|
6949
|
+
*
|
|
6950
|
+
* @example
|
|
6951
|
+
* ```typescript
|
|
6952
|
+
* const stream = server.experimental.tasks.createMessageStream({
|
|
6953
|
+
* messages: [{ role: 'user', content: { type: 'text', text: 'Hello' } }],
|
|
6954
|
+
* maxTokens: 100
|
|
6955
|
+
* }, {
|
|
6956
|
+
* onprogress: (progress) => {
|
|
6957
|
+
* // Handle streaming tokens via progress notifications
|
|
6958
|
+
* console.log('Progress:', progress.message);
|
|
6959
|
+
* }
|
|
6960
|
+
* });
|
|
6961
|
+
*
|
|
6962
|
+
* for await (const message of stream) {
|
|
6963
|
+
* switch (message.type) {
|
|
6964
|
+
* case 'taskCreated':
|
|
6965
|
+
* console.log('Task created:', message.task.taskId);
|
|
6966
|
+
* break;
|
|
6967
|
+
* case 'taskStatus':
|
|
6968
|
+
* console.log('Task status:', message.task.status);
|
|
6969
|
+
* break;
|
|
6970
|
+
* case 'result':
|
|
6971
|
+
* console.log('Final result:', message.result);
|
|
6972
|
+
* break;
|
|
6973
|
+
* case 'error':
|
|
6974
|
+
* console.error('Error:', message.error);
|
|
6975
|
+
* break;
|
|
6976
|
+
* }
|
|
6977
|
+
* }
|
|
6978
|
+
* ```
|
|
6979
|
+
*
|
|
6980
|
+
* @param params - The sampling request parameters
|
|
6981
|
+
* @param options - Optional request options (timeout, signal, task creation params, onprogress, etc.)
|
|
6982
|
+
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
6983
|
+
*
|
|
6984
|
+
* @experimental
|
|
6985
|
+
*/
|
|
6986
|
+
createMessageStream(params, options) {
|
|
6987
|
+
const clientCapabilities = this._server.getClientCapabilities();
|
|
6988
|
+
if ((params.tools || params.toolChoice) && !clientCapabilities?.sampling?.tools) {
|
|
6989
|
+
throw new Error("Client does not support sampling tools capability.");
|
|
6990
|
+
}
|
|
6991
|
+
if (params.messages.length > 0) {
|
|
6992
|
+
const lastMessage = params.messages[params.messages.length - 1];
|
|
6993
|
+
const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];
|
|
6994
|
+
const hasToolResults = lastContent.some((c) => c.type === "tool_result");
|
|
6995
|
+
const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : void 0;
|
|
6996
|
+
const previousContent = previousMessage ? Array.isArray(previousMessage.content) ? previousMessage.content : [previousMessage.content] : [];
|
|
6997
|
+
const hasPreviousToolUse = previousContent.some((c) => c.type === "tool_use");
|
|
6998
|
+
if (hasToolResults) {
|
|
6999
|
+
if (lastContent.some((c) => c.type !== "tool_result")) {
|
|
7000
|
+
throw new Error("The last message must contain only tool_result content if any is present");
|
|
7001
|
+
}
|
|
7002
|
+
if (!hasPreviousToolUse) {
|
|
7003
|
+
throw new Error("tool_result blocks are not matching any tool_use from the previous message");
|
|
7004
|
+
}
|
|
7005
|
+
}
|
|
7006
|
+
if (hasPreviousToolUse) {
|
|
7007
|
+
const toolUseIds = new Set(previousContent.filter((c) => c.type === "tool_use").map((c) => c.id));
|
|
7008
|
+
const toolResultIds = new Set(lastContent.filter((c) => c.type === "tool_result").map((c) => c.toolUseId));
|
|
7009
|
+
if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((id) => toolResultIds.has(id))) {
|
|
7010
|
+
throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match");
|
|
7011
|
+
}
|
|
7012
|
+
}
|
|
7013
|
+
}
|
|
7014
|
+
return this.requestStream({
|
|
7015
|
+
method: "sampling/createMessage",
|
|
7016
|
+
params
|
|
7017
|
+
}, CreateMessageResultSchema, options);
|
|
7018
|
+
}
|
|
7019
|
+
/**
|
|
7020
|
+
* Sends an elicitation request and returns an AsyncGenerator that yields response messages.
|
|
7021
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
7022
|
+
*
|
|
7023
|
+
* For task-augmented requests (especially URL-based elicitation), yields 'taskCreated'
|
|
7024
|
+
* and 'taskStatus' messages before the final result.
|
|
7025
|
+
*
|
|
7026
|
+
* @example
|
|
7027
|
+
* ```typescript
|
|
7028
|
+
* const stream = server.experimental.tasks.elicitInputStream({
|
|
7029
|
+
* mode: 'url',
|
|
7030
|
+
* message: 'Please authenticate',
|
|
7031
|
+
* elicitationId: 'auth-123',
|
|
7032
|
+
* url: 'https://example.com/auth'
|
|
7033
|
+
* }, {
|
|
7034
|
+
* task: { ttl: 300000 } // Task-augmented for long-running auth flow
|
|
7035
|
+
* });
|
|
7036
|
+
*
|
|
7037
|
+
* for await (const message of stream) {
|
|
7038
|
+
* switch (message.type) {
|
|
7039
|
+
* case 'taskCreated':
|
|
7040
|
+
* console.log('Task created:', message.task.taskId);
|
|
7041
|
+
* break;
|
|
7042
|
+
* case 'taskStatus':
|
|
7043
|
+
* console.log('Task status:', message.task.status);
|
|
7044
|
+
* break;
|
|
7045
|
+
* case 'result':
|
|
7046
|
+
* console.log('User action:', message.result.action);
|
|
7047
|
+
* break;
|
|
7048
|
+
* case 'error':
|
|
7049
|
+
* console.error('Error:', message.error);
|
|
7050
|
+
* break;
|
|
7051
|
+
* }
|
|
7052
|
+
* }
|
|
7053
|
+
* ```
|
|
7054
|
+
*
|
|
7055
|
+
* @param params - The elicitation request parameters
|
|
7056
|
+
* @param options - Optional request options (timeout, signal, task creation params, etc.)
|
|
7057
|
+
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
7058
|
+
*
|
|
7059
|
+
* @experimental
|
|
7060
|
+
*/
|
|
7061
|
+
elicitInputStream(params, options) {
|
|
7062
|
+
const clientCapabilities = this._server.getClientCapabilities();
|
|
7063
|
+
const mode = params.mode ?? "form";
|
|
7064
|
+
switch (mode) {
|
|
7065
|
+
case "url": {
|
|
7066
|
+
if (!clientCapabilities?.elicitation?.url) {
|
|
7067
|
+
throw new Error("Client does not support url elicitation.");
|
|
7068
|
+
}
|
|
7069
|
+
break;
|
|
7070
|
+
}
|
|
7071
|
+
case "form": {
|
|
7072
|
+
if (!clientCapabilities?.elicitation?.form) {
|
|
7073
|
+
throw new Error("Client does not support form elicitation.");
|
|
7074
|
+
}
|
|
7075
|
+
break;
|
|
7076
|
+
}
|
|
7077
|
+
}
|
|
7078
|
+
const normalizedParams = mode === "form" && params.mode === void 0 ? { ...params, mode: "form" } : params;
|
|
7079
|
+
return this.requestStream({
|
|
7080
|
+
method: "elicitation/create",
|
|
7081
|
+
params: normalizedParams
|
|
7082
|
+
}, ElicitResultSchema, options);
|
|
7083
|
+
}
|
|
6892
7084
|
/**
|
|
6893
7085
|
* Gets the current status of a task.
|
|
6894
7086
|
*
|
|
@@ -9077,22 +9269,45 @@ async function auth(provider, options) {
|
|
|
9077
9269
|
}
|
|
9078
9270
|
}
|
|
9079
9271
|
async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
|
|
9272
|
+
const cachedState = await provider.discoveryState?.();
|
|
9080
9273
|
let resourceMetadata;
|
|
9081
9274
|
let authorizationServerUrl;
|
|
9082
|
-
|
|
9083
|
-
|
|
9084
|
-
|
|
9085
|
-
|
|
9275
|
+
let metadata;
|
|
9276
|
+
let effectiveResourceMetadataUrl = resourceMetadataUrl;
|
|
9277
|
+
if (!effectiveResourceMetadataUrl && cachedState?.resourceMetadataUrl) {
|
|
9278
|
+
effectiveResourceMetadataUrl = new URL(cachedState.resourceMetadataUrl);
|
|
9279
|
+
}
|
|
9280
|
+
if (cachedState?.authorizationServerUrl) {
|
|
9281
|
+
authorizationServerUrl = cachedState.authorizationServerUrl;
|
|
9282
|
+
resourceMetadata = cachedState.resourceMetadata;
|
|
9283
|
+
metadata = cachedState.authorizationServerMetadata ?? await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn });
|
|
9284
|
+
if (!resourceMetadata) {
|
|
9285
|
+
try {
|
|
9286
|
+
resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl }, fetchFn);
|
|
9287
|
+
} catch {
|
|
9288
|
+
}
|
|
9086
9289
|
}
|
|
9087
|
-
|
|
9088
|
-
|
|
9089
|
-
|
|
9090
|
-
|
|
9290
|
+
if (metadata !== cachedState.authorizationServerMetadata || resourceMetadata !== cachedState.resourceMetadata) {
|
|
9291
|
+
await provider.saveDiscoveryState?.({
|
|
9292
|
+
authorizationServerUrl: String(authorizationServerUrl),
|
|
9293
|
+
resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
|
|
9294
|
+
resourceMetadata,
|
|
9295
|
+
authorizationServerMetadata: metadata
|
|
9296
|
+
});
|
|
9297
|
+
}
|
|
9298
|
+
} else {
|
|
9299
|
+
const serverInfo = await discoverOAuthServerInfo(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl, fetchFn });
|
|
9300
|
+
authorizationServerUrl = serverInfo.authorizationServerUrl;
|
|
9301
|
+
metadata = serverInfo.authorizationServerMetadata;
|
|
9302
|
+
resourceMetadata = serverInfo.resourceMetadata;
|
|
9303
|
+
await provider.saveDiscoveryState?.({
|
|
9304
|
+
authorizationServerUrl: String(authorizationServerUrl),
|
|
9305
|
+
resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
|
|
9306
|
+
resourceMetadata,
|
|
9307
|
+
authorizationServerMetadata: metadata
|
|
9308
|
+
});
|
|
9091
9309
|
}
|
|
9092
9310
|
const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
|
|
9093
|
-
const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, {
|
|
9094
|
-
fetchFn
|
|
9095
|
-
});
|
|
9096
9311
|
let clientInformation = await Promise.resolve(provider.clientInformation());
|
|
9097
9312
|
if (!clientInformation) {
|
|
9098
9313
|
if (authorizationCode !== void 0) {
|
|
@@ -9347,6 +9562,26 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
|
|
|
9347
9562
|
}
|
|
9348
9563
|
return void 0;
|
|
9349
9564
|
}
|
|
9565
|
+
async function discoverOAuthServerInfo(serverUrl, opts) {
|
|
9566
|
+
let resourceMetadata;
|
|
9567
|
+
let authorizationServerUrl;
|
|
9568
|
+
try {
|
|
9569
|
+
resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: opts?.resourceMetadataUrl }, opts?.fetchFn);
|
|
9570
|
+
if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
|
|
9571
|
+
authorizationServerUrl = resourceMetadata.authorization_servers[0];
|
|
9572
|
+
}
|
|
9573
|
+
} catch {
|
|
9574
|
+
}
|
|
9575
|
+
if (!authorizationServerUrl) {
|
|
9576
|
+
authorizationServerUrl = String(new URL("/", serverUrl));
|
|
9577
|
+
}
|
|
9578
|
+
const authorizationServerMetadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn: opts?.fetchFn });
|
|
9579
|
+
return {
|
|
9580
|
+
authorizationServerUrl,
|
|
9581
|
+
authorizationServerMetadata,
|
|
9582
|
+
resourceMetadata
|
|
9583
|
+
};
|
|
9584
|
+
}
|
|
9350
9585
|
async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
|
|
9351
9586
|
let authorizationUrl;
|
|
9352
9587
|
if (metadata) {
|
|
@@ -10211,18 +10446,6 @@ var cleanToolSchema = (schema) => {
|
|
|
10211
10446
|
var import_node_process7 = require("node:process");
|
|
10212
10447
|
var import_node_process8 = __toESM(require("node:process"), 1);
|
|
10213
10448
|
var import_node_crypto = require("node:crypto");
|
|
10214
|
-
var mcpClientPool = /* @__PURE__ */ new Map();
|
|
10215
|
-
var mcpClientConnecting = /* @__PURE__ */ new Map();
|
|
10216
|
-
var shortHash = (s) => (0, import_node_crypto.createHash)("sha256").update(s).digest("hex").slice(0, 8);
|
|
10217
|
-
function defSignature(def) {
|
|
10218
|
-
const defCopy = {
|
|
10219
|
-
...def
|
|
10220
|
-
};
|
|
10221
|
-
if (defCopy.transportType === "memory" || defCopy.transport) {
|
|
10222
|
-
return `memory:${Date.now()}:${Math.random()}`;
|
|
10223
|
-
}
|
|
10224
|
-
return JSON.stringify(defCopy);
|
|
10225
|
-
}
|
|
10226
10449
|
function createTransport(def) {
|
|
10227
10450
|
const defAny = def;
|
|
10228
10451
|
const explicitType = defAny.transportType || defAny.type;
|
|
@@ -10270,90 +10493,43 @@ function createTransport(def) {
|
|
|
10270
10493
|
}
|
|
10271
10494
|
throw new Error(`Unsupported transport configuration: ${JSON.stringify(def)}`);
|
|
10272
10495
|
}
|
|
10273
|
-
|
|
10274
|
-
const
|
|
10275
|
-
|
|
10276
|
-
|
|
10277
|
-
|
|
10278
|
-
|
|
10279
|
-
const existingConnecting = mcpClientConnecting.get(defKey);
|
|
10280
|
-
if (existingConnecting) {
|
|
10281
|
-
const client = await existingConnecting;
|
|
10282
|
-
const entry = mcpClientPool.get(defKey);
|
|
10283
|
-
if (entry) entry.refCount += 1;
|
|
10284
|
-
return client;
|
|
10285
|
-
}
|
|
10286
|
-
const transport = createTransport(def);
|
|
10287
|
-
const connecting = (async () => {
|
|
10288
|
-
const client = new Client({
|
|
10289
|
-
name: `mcp_${shortHash(defSignature(def))}`,
|
|
10290
|
-
version: "1.0.0"
|
|
10291
|
-
});
|
|
10292
|
-
await client.connect(transport, {
|
|
10293
|
-
timeout: 6e4 * 10
|
|
10294
|
-
});
|
|
10295
|
-
return client;
|
|
10296
|
-
})();
|
|
10297
|
-
mcpClientConnecting.set(defKey, connecting);
|
|
10298
|
-
try {
|
|
10299
|
-
const client = await connecting;
|
|
10300
|
-
mcpClientPool.set(defKey, {
|
|
10301
|
-
client,
|
|
10302
|
-
refCount: 1
|
|
10303
|
-
});
|
|
10304
|
-
return client;
|
|
10305
|
-
} finally {
|
|
10306
|
-
mcpClientConnecting.delete(defKey);
|
|
10496
|
+
function defSignature(def) {
|
|
10497
|
+
const defCopy = {
|
|
10498
|
+
...def
|
|
10499
|
+
};
|
|
10500
|
+
if (defCopy.transportType === "memory" || defCopy.transport) {
|
|
10501
|
+
return `memory:${Date.now()}:${Math.random()}`;
|
|
10307
10502
|
}
|
|
10503
|
+
return JSON.stringify(defCopy);
|
|
10308
10504
|
}
|
|
10309
|
-
|
|
10310
|
-
|
|
10311
|
-
|
|
10312
|
-
|
|
10313
|
-
|
|
10314
|
-
|
|
10315
|
-
|
|
10316
|
-
|
|
10317
|
-
|
|
10318
|
-
|
|
10319
|
-
|
|
10320
|
-
}
|
|
10505
|
+
var shortHash = (s) => (0, import_node_crypto.createHash)("sha256").update(s).digest("hex").slice(0, 8);
|
|
10506
|
+
async function createMcpClient(def) {
|
|
10507
|
+
const transport = createTransport(def);
|
|
10508
|
+
const client = new Client({
|
|
10509
|
+
name: `mcp_${shortHash(defSignature(def))}`,
|
|
10510
|
+
version: "1.0.0"
|
|
10511
|
+
});
|
|
10512
|
+
await client.connect(transport, {
|
|
10513
|
+
timeout: 6e4 * 10
|
|
10514
|
+
});
|
|
10515
|
+
return client;
|
|
10321
10516
|
}
|
|
10322
|
-
var cleanupAllPooledClients = async () => {
|
|
10323
|
-
const entries = Array.from(mcpClientPool.entries());
|
|
10324
|
-
mcpClientPool.clear();
|
|
10325
|
-
await Promise.all(entries.map(async ([, { client }]) => {
|
|
10326
|
-
try {
|
|
10327
|
-
await client.close();
|
|
10328
|
-
} catch (err) {
|
|
10329
|
-
console.error("Error closing MCP client:", err);
|
|
10330
|
-
}
|
|
10331
|
-
}));
|
|
10332
|
-
};
|
|
10333
|
-
import_node_process8.default.once?.("exit", () => {
|
|
10334
|
-
cleanupAllPooledClients();
|
|
10335
|
-
});
|
|
10336
|
-
import_node_process8.default.once?.("SIGINT", () => {
|
|
10337
|
-
cleanupAllPooledClients().finally(() => import_node_process8.default.exit(0));
|
|
10338
|
-
});
|
|
10339
10517
|
async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
10340
10518
|
const allTools = {};
|
|
10341
10519
|
const allClients = {};
|
|
10342
|
-
const
|
|
10520
|
+
const clientsToClose = [];
|
|
10343
10521
|
for (const [name, definition] of Object.entries(mcpConfig.mcpServers)) {
|
|
10344
10522
|
const def = definition;
|
|
10345
10523
|
if (def.disabled) continue;
|
|
10346
|
-
const defKey = shortHash(defSignature(def));
|
|
10347
|
-
const serverId = name;
|
|
10348
10524
|
try {
|
|
10349
|
-
const client = await
|
|
10350
|
-
|
|
10351
|
-
allClients[
|
|
10525
|
+
const client = await createMcpClient(def);
|
|
10526
|
+
clientsToClose.push(client);
|
|
10527
|
+
allClients[name] = client;
|
|
10352
10528
|
const { tools } = await client.listTools();
|
|
10353
10529
|
tools.forEach((tool2) => {
|
|
10354
10530
|
const toolNameWithScope = `${name}.${tool2.name}`;
|
|
10355
10531
|
const internalToolName = tool2.name;
|
|
10356
|
-
const rawToolId = `${
|
|
10532
|
+
const rawToolId = `${name}_${internalToolName}`;
|
|
10357
10533
|
const toolId = sanitizePropertyKey(rawToolId);
|
|
10358
10534
|
if (filterIn && !filterIn({
|
|
10359
10535
|
action: internalToolName,
|
|
@@ -10365,7 +10541,7 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
|
10365
10541
|
})) {
|
|
10366
10542
|
return;
|
|
10367
10543
|
}
|
|
10368
|
-
const execute = (args) => allClients[
|
|
10544
|
+
const execute = (args) => allClients[name].callTool({
|
|
10369
10545
|
name: internalToolName,
|
|
10370
10546
|
arguments: args
|
|
10371
10547
|
}, void 0, {
|
|
@@ -10382,10 +10558,12 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
|
10382
10558
|
}
|
|
10383
10559
|
}
|
|
10384
10560
|
const cleanupClients = async () => {
|
|
10385
|
-
await Promise.all(
|
|
10386
|
-
|
|
10387
|
-
|
|
10388
|
-
|
|
10561
|
+
await Promise.all(clientsToClose.map((client) => {
|
|
10562
|
+
try {
|
|
10563
|
+
return client.close();
|
|
10564
|
+
} catch {
|
|
10565
|
+
}
|
|
10566
|
+
}));
|
|
10389
10567
|
};
|
|
10390
10568
|
return {
|
|
10391
10569
|
tools: allTools,
|