@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/bin/mcpc.mjs
CHANGED
|
@@ -2386,7 +2386,7 @@ if (typeof global.crypto === "undefined") {
|
|
|
2386
2386
|
var outgoingEnded = Symbol("outgoingEnded");
|
|
2387
2387
|
|
|
2388
2388
|
// __mcpc__cli_latest/node_modules/@jsr/std__cli/parse_args.js
|
|
2389
|
-
var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value
|
|
2389
|
+
var FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.*))?$/s;
|
|
2390
2390
|
var LETTER_REGEXP = /[A-Za-z]/;
|
|
2391
2391
|
var NUMBER_REGEXP = /-?\d+(\.\d*)?(e-?\d+)?$/;
|
|
2392
2392
|
var HYPHEN_REGEXP = /^(-|--)[^-]/;
|
|
@@ -2397,12 +2397,19 @@ var NON_WHITESPACE_REGEXP = /\S/;
|
|
|
2397
2397
|
function isNumber(string3) {
|
|
2398
2398
|
return NON_WHITESPACE_REGEXP.test(string3) && Number.isFinite(Number(string3));
|
|
2399
2399
|
}
|
|
2400
|
+
function isConstructorOrProto(obj, key) {
|
|
2401
|
+
return key === "constructor" && typeof obj[key] === "function" || key === "__proto__";
|
|
2402
|
+
}
|
|
2400
2403
|
function setNested(object5, keys, value, collect = false) {
|
|
2401
2404
|
keys = [
|
|
2402
2405
|
...keys
|
|
2403
2406
|
];
|
|
2404
2407
|
const key = keys.pop();
|
|
2405
|
-
|
|
2408
|
+
for (const k of keys) {
|
|
2409
|
+
if (isConstructorOrProto(object5, k)) return;
|
|
2410
|
+
object5 = object5[k] ??= {};
|
|
2411
|
+
}
|
|
2412
|
+
if (isConstructorOrProto(object5, key)) return;
|
|
2406
2413
|
if (collect) {
|
|
2407
2414
|
const v = object5[key];
|
|
2408
2415
|
if (Array.isArray(v)) {
|
|
@@ -2533,7 +2540,7 @@ function parseArgs(args, options) {
|
|
|
2533
2540
|
let key = groups.key;
|
|
2534
2541
|
let value = groups.value;
|
|
2535
2542
|
if (doubleDash2) {
|
|
2536
|
-
if (value) {
|
|
2543
|
+
if (value != null) {
|
|
2537
2544
|
if (booleanSet.has(key)) value = parseBooleanString(value);
|
|
2538
2545
|
setArgument(key, value, arg, true);
|
|
2539
2546
|
continue;
|
|
@@ -2571,6 +2578,10 @@ function parseArgs(args, options) {
|
|
|
2571
2578
|
setArgument(letter, next, arg, true);
|
|
2572
2579
|
continue;
|
|
2573
2580
|
}
|
|
2581
|
+
if (next === "=") {
|
|
2582
|
+
setArgument(letter, "", arg, true);
|
|
2583
|
+
continue argsLoop;
|
|
2584
|
+
}
|
|
2574
2585
|
if (LETTER_REGEXP.test(letter)) {
|
|
2575
2586
|
const groups2 = VALUE_REGEXP.exec(next)?.groups;
|
|
2576
2587
|
if (groups2) {
|
|
@@ -3065,7 +3076,7 @@ Usage:
|
|
|
3065
3076
|
- ${toolName}({ skill: "skill-name" }) - Load main SKILL.md content
|
|
3066
3077
|
- ${toolName}({ skill: "skill-name", ref: "path/to/file" }) - Load reference file
|
|
3067
3078
|
|
|
3068
|
-
Note: For scripts
|
|
3079
|
+
Note: For scripts/, use the bash tool with the script path to execute.`;
|
|
3069
3080
|
}
|
|
3070
3081
|
function createSkillsPlugin(options) {
|
|
3071
3082
|
const { paths } = options;
|
|
@@ -3173,11 +3184,15 @@ Available skills: ${available.join(", ")}` : "\n\nNo skills available.";
|
|
|
3173
3184
|
try {
|
|
3174
3185
|
const content = await readFile(join2(meta.basePath, "SKILL.md"), "utf-8");
|
|
3175
3186
|
const body = extractBody(content);
|
|
3187
|
+
const skillPathInfo = `
|
|
3188
|
+
---
|
|
3189
|
+
Skill path: ${meta.basePath}
|
|
3190
|
+
`;
|
|
3176
3191
|
return {
|
|
3177
3192
|
content: [
|
|
3178
3193
|
{
|
|
3179
3194
|
type: "text",
|
|
3180
|
-
text: body
|
|
3195
|
+
text: body + skillPathInfo
|
|
3181
3196
|
}
|
|
3182
3197
|
]
|
|
3183
3198
|
};
|
|
@@ -4048,12 +4063,29 @@ function writeFoldedLines(count) {
|
|
|
4048
4063
|
if (count > 1) return "\n".repeat(count - 1);
|
|
4049
4064
|
return "";
|
|
4050
4065
|
}
|
|
4066
|
+
var Scanner = class {
|
|
4067
|
+
source;
|
|
4068
|
+
#length;
|
|
4069
|
+
position = 0;
|
|
4070
|
+
constructor(source) {
|
|
4071
|
+
source += "\0";
|
|
4072
|
+
this.source = source;
|
|
4073
|
+
this.#length = source.length;
|
|
4074
|
+
}
|
|
4075
|
+
peek(offset = 0) {
|
|
4076
|
+
return this.source.charCodeAt(this.position + offset);
|
|
4077
|
+
}
|
|
4078
|
+
next() {
|
|
4079
|
+
this.position += 1;
|
|
4080
|
+
}
|
|
4081
|
+
eof() {
|
|
4082
|
+
return this.position >= this.#length - 1;
|
|
4083
|
+
}
|
|
4084
|
+
};
|
|
4051
4085
|
var LoaderState = class {
|
|
4052
|
-
|
|
4053
|
-
length;
|
|
4086
|
+
#scanner;
|
|
4054
4087
|
lineIndent = 0;
|
|
4055
4088
|
lineStart = 0;
|
|
4056
|
-
position = 0;
|
|
4057
4089
|
line = 0;
|
|
4058
4090
|
onWarning;
|
|
4059
4091
|
allowDuplicateKeys;
|
|
@@ -4063,44 +4095,40 @@ var LoaderState = class {
|
|
|
4063
4095
|
tagMap = /* @__PURE__ */ new Map();
|
|
4064
4096
|
anchorMap = /* @__PURE__ */ new Map();
|
|
4065
4097
|
constructor(input, { schema = DEFAULT_SCHEMA, onWarning, allowDuplicateKeys = false }) {
|
|
4066
|
-
this
|
|
4098
|
+
this.#scanner = new Scanner(input);
|
|
4067
4099
|
this.onWarning = onWarning;
|
|
4068
4100
|
this.allowDuplicateKeys = allowDuplicateKeys;
|
|
4069
4101
|
this.implicitTypes = schema.implicitTypes;
|
|
4070
4102
|
this.typeMap = schema.typeMap;
|
|
4071
|
-
this.length = input.length;
|
|
4072
4103
|
this.readIndent();
|
|
4073
4104
|
}
|
|
4074
4105
|
skipWhitespaces() {
|
|
4075
|
-
let ch = this.peek();
|
|
4106
|
+
let ch = this.#scanner.peek();
|
|
4076
4107
|
while (isWhiteSpace(ch)) {
|
|
4077
|
-
|
|
4108
|
+
this.#scanner.next();
|
|
4109
|
+
ch = this.#scanner.peek();
|
|
4078
4110
|
}
|
|
4079
4111
|
}
|
|
4080
4112
|
skipComment() {
|
|
4081
|
-
let ch = this.peek();
|
|
4113
|
+
let ch = this.#scanner.peek();
|
|
4082
4114
|
if (ch !== SHARP) return;
|
|
4083
|
-
|
|
4115
|
+
this.#scanner.next();
|
|
4116
|
+
ch = this.#scanner.peek();
|
|
4084
4117
|
while (ch !== 0 && !isEOL(ch)) {
|
|
4085
|
-
|
|
4118
|
+
this.#scanner.next();
|
|
4119
|
+
ch = this.#scanner.peek();
|
|
4086
4120
|
}
|
|
4087
4121
|
}
|
|
4088
4122
|
readIndent() {
|
|
4089
|
-
let
|
|
4090
|
-
while (
|
|
4123
|
+
let ch = this.#scanner.peek();
|
|
4124
|
+
while (ch === SPACE) {
|
|
4091
4125
|
this.lineIndent += 1;
|
|
4092
|
-
|
|
4126
|
+
this.#scanner.next();
|
|
4127
|
+
ch = this.#scanner.peek();
|
|
4093
4128
|
}
|
|
4094
4129
|
}
|
|
4095
|
-
peek(offset = 0) {
|
|
4096
|
-
return this.input.charCodeAt(this.position + offset);
|
|
4097
|
-
}
|
|
4098
|
-
next() {
|
|
4099
|
-
this.position += 1;
|
|
4100
|
-
return this.peek();
|
|
4101
|
-
}
|
|
4102
4130
|
#createError(message) {
|
|
4103
|
-
const mark = markToString(this.
|
|
4131
|
+
const mark = markToString(this.#scanner.source, this.#scanner.position, this.line, this.#scanner.position - this.lineStart);
|
|
4104
4132
|
return new SyntaxError(`${message} ${mark}`);
|
|
4105
4133
|
}
|
|
4106
4134
|
dispatchWarning(message) {
|
|
@@ -4145,7 +4173,7 @@ var LoaderState = class {
|
|
|
4145
4173
|
}
|
|
4146
4174
|
captureSegment(start, end, checkJson) {
|
|
4147
4175
|
if (start < end) {
|
|
4148
|
-
const result = this.
|
|
4176
|
+
const result = this.#scanner.source.slice(start, end);
|
|
4149
4177
|
if (checkJson) {
|
|
4150
4178
|
for (let position = 0; position < result.length; position++) {
|
|
4151
4179
|
const character = result.charCodeAt(position);
|
|
@@ -4163,21 +4191,21 @@ var LoaderState = class {
|
|
|
4163
4191
|
let detected = false;
|
|
4164
4192
|
const result = [];
|
|
4165
4193
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
4166
|
-
let ch = this.peek();
|
|
4194
|
+
let ch = this.#scanner.peek();
|
|
4167
4195
|
while (ch !== 0) {
|
|
4168
4196
|
if (ch !== MINUS) {
|
|
4169
4197
|
break;
|
|
4170
4198
|
}
|
|
4171
|
-
const following = this.peek(1);
|
|
4199
|
+
const following = this.#scanner.peek(1);
|
|
4172
4200
|
if (!isWhiteSpaceOrEOL(following)) {
|
|
4173
4201
|
break;
|
|
4174
4202
|
}
|
|
4175
4203
|
detected = true;
|
|
4176
|
-
this.
|
|
4204
|
+
this.#scanner.next();
|
|
4177
4205
|
if (this.skipSeparationSpace(true, -1)) {
|
|
4178
4206
|
if (this.lineIndent <= nodeIndent) {
|
|
4179
4207
|
result.push(null);
|
|
4180
|
-
ch = this.peek();
|
|
4208
|
+
ch = this.#scanner.peek();
|
|
4181
4209
|
continue;
|
|
4182
4210
|
}
|
|
4183
4211
|
}
|
|
@@ -4190,7 +4218,7 @@ var LoaderState = class {
|
|
|
4190
4218
|
});
|
|
4191
4219
|
if (newState) result.push(newState.result);
|
|
4192
4220
|
this.skipSeparationSpace(true, -1);
|
|
4193
|
-
ch = this.peek();
|
|
4221
|
+
ch = this.#scanner.peek();
|
|
4194
4222
|
if ((this.line === line || this.lineIndent > nodeIndent) && ch !== 0) {
|
|
4195
4223
|
throw this.#createError("Cannot read block sequence: bad indentation of a sequence entry");
|
|
4196
4224
|
} else if (this.lineIndent < nodeIndent) {
|
|
@@ -4246,7 +4274,7 @@ var LoaderState = class {
|
|
|
4246
4274
|
} else {
|
|
4247
4275
|
if (!this.allowDuplicateKeys && !overridableKeys.has(keyNode) && Object.hasOwn(result, keyNode)) {
|
|
4248
4276
|
this.line = startLine || this.line;
|
|
4249
|
-
this.position = startPos || this.position;
|
|
4277
|
+
this.#scanner.position = startPos || this.#scanner.position;
|
|
4250
4278
|
throw this.#createError("Cannot store mapping pair: duplicated key");
|
|
4251
4279
|
}
|
|
4252
4280
|
Object.defineProperty(result, keyNode, {
|
|
@@ -4260,37 +4288,37 @@ var LoaderState = class {
|
|
|
4260
4288
|
return result;
|
|
4261
4289
|
}
|
|
4262
4290
|
readLineBreak() {
|
|
4263
|
-
const ch = this.peek();
|
|
4291
|
+
const ch = this.#scanner.peek();
|
|
4264
4292
|
if (ch === LINE_FEED) {
|
|
4265
|
-
this.
|
|
4293
|
+
this.#scanner.next();
|
|
4266
4294
|
} else if (ch === CARRIAGE_RETURN) {
|
|
4267
|
-
this.
|
|
4268
|
-
if (this.peek() === LINE_FEED) {
|
|
4269
|
-
this.
|
|
4295
|
+
this.#scanner.next();
|
|
4296
|
+
if (this.#scanner.peek() === LINE_FEED) {
|
|
4297
|
+
this.#scanner.next();
|
|
4270
4298
|
}
|
|
4271
4299
|
} else {
|
|
4272
4300
|
throw this.#createError("Cannot read line: line break not found");
|
|
4273
4301
|
}
|
|
4274
4302
|
this.line += 1;
|
|
4275
|
-
this.lineStart = this.position;
|
|
4303
|
+
this.lineStart = this.#scanner.position;
|
|
4276
4304
|
}
|
|
4277
4305
|
skipSeparationSpace(allowComments, checkIndent) {
|
|
4278
4306
|
let lineBreaks = 0;
|
|
4279
|
-
let ch = this.peek();
|
|
4307
|
+
let ch = this.#scanner.peek();
|
|
4280
4308
|
while (ch !== 0) {
|
|
4281
4309
|
this.skipWhitespaces();
|
|
4282
|
-
ch = this.peek();
|
|
4310
|
+
ch = this.#scanner.peek();
|
|
4283
4311
|
if (allowComments) {
|
|
4284
4312
|
this.skipComment();
|
|
4285
|
-
ch = this.peek();
|
|
4313
|
+
ch = this.#scanner.peek();
|
|
4286
4314
|
}
|
|
4287
4315
|
if (isEOL(ch)) {
|
|
4288
4316
|
this.readLineBreak();
|
|
4289
|
-
ch = this.peek();
|
|
4317
|
+
ch = this.#scanner.peek();
|
|
4290
4318
|
lineBreaks++;
|
|
4291
4319
|
this.lineIndent = 0;
|
|
4292
4320
|
this.readIndent();
|
|
4293
|
-
ch = this.peek();
|
|
4321
|
+
ch = this.#scanner.peek();
|
|
4294
4322
|
} else {
|
|
4295
4323
|
break;
|
|
4296
4324
|
}
|
|
@@ -4301,9 +4329,9 @@ var LoaderState = class {
|
|
|
4301
4329
|
return lineBreaks;
|
|
4302
4330
|
}
|
|
4303
4331
|
testDocumentSeparator() {
|
|
4304
|
-
let ch = this.peek();
|
|
4305
|
-
if ((ch === MINUS || ch === DOT) && ch === this.peek(1) && ch === this.peek(2)) {
|
|
4306
|
-
ch = this.peek(3);
|
|
4332
|
+
let ch = this.#scanner.peek();
|
|
4333
|
+
if ((ch === MINUS || ch === DOT) && ch === this.#scanner.peek(1) && ch === this.#scanner.peek(2)) {
|
|
4334
|
+
ch = this.#scanner.peek(3);
|
|
4307
4335
|
if (ch === 0 || isWhiteSpaceOrEOL(ch)) {
|
|
4308
4336
|
return true;
|
|
4309
4337
|
}
|
|
@@ -4311,34 +4339,34 @@ var LoaderState = class {
|
|
|
4311
4339
|
return false;
|
|
4312
4340
|
}
|
|
4313
4341
|
readPlainScalar(tag, anchor, nodeIndent, withinFlowCollection) {
|
|
4314
|
-
let ch = this.peek();
|
|
4342
|
+
let ch = this.#scanner.peek();
|
|
4315
4343
|
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) {
|
|
4316
4344
|
return;
|
|
4317
4345
|
}
|
|
4318
4346
|
let following;
|
|
4319
4347
|
if (ch === QUESTION || ch === MINUS) {
|
|
4320
|
-
following = this.peek(1);
|
|
4348
|
+
following = this.#scanner.peek(1);
|
|
4321
4349
|
if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
|
|
4322
4350
|
return;
|
|
4323
4351
|
}
|
|
4324
4352
|
}
|
|
4325
4353
|
let result = "";
|
|
4326
|
-
let captureEnd = this.position;
|
|
4327
|
-
let captureStart = this.position;
|
|
4354
|
+
let captureEnd = this.#scanner.position;
|
|
4355
|
+
let captureStart = this.#scanner.position;
|
|
4328
4356
|
let hasPendingContent = false;
|
|
4329
4357
|
let line = 0;
|
|
4330
4358
|
while (ch !== 0) {
|
|
4331
4359
|
if (ch === COLON) {
|
|
4332
|
-
following = this.peek(1);
|
|
4360
|
+
following = this.#scanner.peek(1);
|
|
4333
4361
|
if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
|
|
4334
4362
|
break;
|
|
4335
4363
|
}
|
|
4336
4364
|
} else if (ch === SHARP) {
|
|
4337
|
-
const preceding = this.peek(-1);
|
|
4365
|
+
const preceding = this.#scanner.peek(-1);
|
|
4338
4366
|
if (isWhiteSpaceOrEOL(preceding)) {
|
|
4339
4367
|
break;
|
|
4340
4368
|
}
|
|
4341
|
-
} else if (this.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
|
|
4369
|
+
} else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
|
|
4342
4370
|
break;
|
|
4343
4371
|
} else if (isEOL(ch)) {
|
|
4344
4372
|
line = this.line;
|
|
@@ -4347,10 +4375,10 @@ var LoaderState = class {
|
|
|
4347
4375
|
this.skipSeparationSpace(false, -1);
|
|
4348
4376
|
if (this.lineIndent >= nodeIndent) {
|
|
4349
4377
|
hasPendingContent = true;
|
|
4350
|
-
ch = this.peek();
|
|
4378
|
+
ch = this.#scanner.peek();
|
|
4351
4379
|
continue;
|
|
4352
4380
|
} else {
|
|
4353
|
-
this.position = captureEnd;
|
|
4381
|
+
this.#scanner.position = captureEnd;
|
|
4354
4382
|
this.line = line;
|
|
4355
4383
|
this.lineStart = lineStart;
|
|
4356
4384
|
this.lineIndent = lineIndent;
|
|
@@ -4361,13 +4389,14 @@ var LoaderState = class {
|
|
|
4361
4389
|
const segment2 = this.captureSegment(captureStart, captureEnd, false);
|
|
4362
4390
|
if (segment2) result += segment2;
|
|
4363
4391
|
result += writeFoldedLines(this.line - line);
|
|
4364
|
-
captureStart = captureEnd = this.position;
|
|
4392
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
4365
4393
|
hasPendingContent = false;
|
|
4366
4394
|
}
|
|
4367
4395
|
if (!isWhiteSpace(ch)) {
|
|
4368
|
-
captureEnd = this.position + 1;
|
|
4396
|
+
captureEnd = this.#scanner.position + 1;
|
|
4369
4397
|
}
|
|
4370
|
-
|
|
4398
|
+
this.#scanner.next();
|
|
4399
|
+
ch = this.#scanner.peek();
|
|
4371
4400
|
}
|
|
4372
4401
|
const segment = this.captureSegment(captureStart, captureEnd, false);
|
|
4373
4402
|
if (segment) result += segment;
|
|
@@ -4380,22 +4409,23 @@ var LoaderState = class {
|
|
|
4380
4409
|
};
|
|
4381
4410
|
}
|
|
4382
4411
|
readSingleQuotedScalar(tag, anchor, nodeIndent) {
|
|
4383
|
-
let ch = this.peek();
|
|
4412
|
+
let ch = this.#scanner.peek();
|
|
4384
4413
|
if (ch !== SINGLE_QUOTE) return;
|
|
4385
4414
|
let result = "";
|
|
4386
|
-
this.
|
|
4387
|
-
let captureStart = this.position;
|
|
4388
|
-
let captureEnd = this.position;
|
|
4389
|
-
ch = this.peek();
|
|
4415
|
+
this.#scanner.next();
|
|
4416
|
+
let captureStart = this.#scanner.position;
|
|
4417
|
+
let captureEnd = this.#scanner.position;
|
|
4418
|
+
ch = this.#scanner.peek();
|
|
4390
4419
|
while (ch !== 0) {
|
|
4391
4420
|
if (ch === SINGLE_QUOTE) {
|
|
4392
|
-
const segment = this.captureSegment(captureStart, this.position, true);
|
|
4421
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, true);
|
|
4393
4422
|
if (segment) result += segment;
|
|
4394
|
-
|
|
4423
|
+
this.#scanner.next();
|
|
4424
|
+
ch = this.#scanner.peek();
|
|
4395
4425
|
if (ch === SINGLE_QUOTE) {
|
|
4396
|
-
captureStart = this.position;
|
|
4397
|
-
this.
|
|
4398
|
-
captureEnd = this.position;
|
|
4426
|
+
captureStart = this.#scanner.position;
|
|
4427
|
+
this.#scanner.next();
|
|
4428
|
+
captureEnd = this.#scanner.position;
|
|
4399
4429
|
} else {
|
|
4400
4430
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
4401
4431
|
return {
|
|
@@ -4409,31 +4439,31 @@ var LoaderState = class {
|
|
|
4409
4439
|
const segment = this.captureSegment(captureStart, captureEnd, true);
|
|
4410
4440
|
if (segment) result += segment;
|
|
4411
4441
|
result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
|
|
4412
|
-
captureStart = captureEnd = this.position;
|
|
4413
|
-
} else if (this.position === this.lineStart && this.testDocumentSeparator()) {
|
|
4442
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
4443
|
+
} else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
|
|
4414
4444
|
throw this.#createError("Unexpected end of the document within a single quoted scalar");
|
|
4415
4445
|
} else {
|
|
4416
|
-
this.
|
|
4417
|
-
captureEnd = this.position;
|
|
4446
|
+
this.#scanner.next();
|
|
4447
|
+
captureEnd = this.#scanner.position;
|
|
4418
4448
|
}
|
|
4419
|
-
ch = this.peek();
|
|
4449
|
+
ch = this.#scanner.peek();
|
|
4420
4450
|
}
|
|
4421
4451
|
throw this.#createError("Unexpected end of the stream within a single quoted scalar");
|
|
4422
4452
|
}
|
|
4423
4453
|
readDoubleQuotedScalar(tag, anchor, nodeIndent) {
|
|
4424
|
-
let ch = this.peek();
|
|
4454
|
+
let ch = this.#scanner.peek();
|
|
4425
4455
|
if (ch !== DOUBLE_QUOTE) return;
|
|
4426
4456
|
let result = "";
|
|
4427
|
-
this.
|
|
4428
|
-
let captureEnd = this.position;
|
|
4429
|
-
let captureStart = this.position;
|
|
4457
|
+
this.#scanner.next();
|
|
4458
|
+
let captureEnd = this.#scanner.position;
|
|
4459
|
+
let captureStart = this.#scanner.position;
|
|
4430
4460
|
let tmp;
|
|
4431
|
-
ch = this.peek();
|
|
4461
|
+
ch = this.#scanner.peek();
|
|
4432
4462
|
while (ch !== 0) {
|
|
4433
4463
|
if (ch === DOUBLE_QUOTE) {
|
|
4434
|
-
const segment = this.captureSegment(captureStart, this.position, true);
|
|
4464
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, true);
|
|
4435
4465
|
if (segment) result += segment;
|
|
4436
|
-
this.
|
|
4466
|
+
this.#scanner.next();
|
|
4437
4467
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
4438
4468
|
return {
|
|
4439
4469
|
tag,
|
|
@@ -4443,19 +4473,21 @@ var LoaderState = class {
|
|
|
4443
4473
|
};
|
|
4444
4474
|
}
|
|
4445
4475
|
if (ch === BACKSLASH) {
|
|
4446
|
-
const segment = this.captureSegment(captureStart, this.position, true);
|
|
4476
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, true);
|
|
4447
4477
|
if (segment) result += segment;
|
|
4448
|
-
|
|
4478
|
+
this.#scanner.next();
|
|
4479
|
+
ch = this.#scanner.peek();
|
|
4449
4480
|
if (isEOL(ch)) {
|
|
4450
4481
|
this.skipSeparationSpace(false, nodeIndent);
|
|
4451
4482
|
} else if (ch < 256 && SIMPLE_ESCAPE_SEQUENCES.has(ch)) {
|
|
4452
4483
|
result += SIMPLE_ESCAPE_SEQUENCES.get(ch);
|
|
4453
|
-
this.
|
|
4484
|
+
this.#scanner.next();
|
|
4454
4485
|
} else if ((tmp = ESCAPED_HEX_LENGTHS.get(ch) ?? 0) > 0) {
|
|
4455
4486
|
let hexLength = tmp;
|
|
4456
4487
|
let hexResult = 0;
|
|
4457
4488
|
for (; hexLength > 0; hexLength--) {
|
|
4458
|
-
|
|
4489
|
+
this.#scanner.next();
|
|
4490
|
+
ch = this.#scanner.peek();
|
|
4459
4491
|
if ((tmp = hexCharCodeToNumber(ch)) >= 0) {
|
|
4460
4492
|
hexResult = (hexResult << 4) + tmp;
|
|
4461
4493
|
} else {
|
|
@@ -4463,28 +4495,28 @@ var LoaderState = class {
|
|
|
4463
4495
|
}
|
|
4464
4496
|
}
|
|
4465
4497
|
result += codepointToChar(hexResult);
|
|
4466
|
-
this.
|
|
4498
|
+
this.#scanner.next();
|
|
4467
4499
|
} else {
|
|
4468
4500
|
throw this.#createError("Cannot read double quoted scalar: unknown escape sequence");
|
|
4469
4501
|
}
|
|
4470
|
-
captureStart = captureEnd = this.position;
|
|
4502
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
4471
4503
|
} else if (isEOL(ch)) {
|
|
4472
4504
|
const segment = this.captureSegment(captureStart, captureEnd, true);
|
|
4473
4505
|
if (segment) result += segment;
|
|
4474
4506
|
result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
|
|
4475
|
-
captureStart = captureEnd = this.position;
|
|
4476
|
-
} else if (this.position === this.lineStart && this.testDocumentSeparator()) {
|
|
4507
|
+
captureStart = captureEnd = this.#scanner.position;
|
|
4508
|
+
} else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
|
|
4477
4509
|
throw this.#createError("Unexpected end of the document within a double quoted scalar");
|
|
4478
4510
|
} else {
|
|
4479
|
-
this.
|
|
4480
|
-
captureEnd = this.position;
|
|
4511
|
+
this.#scanner.next();
|
|
4512
|
+
captureEnd = this.#scanner.position;
|
|
4481
4513
|
}
|
|
4482
|
-
ch = this.peek();
|
|
4514
|
+
ch = this.#scanner.peek();
|
|
4483
4515
|
}
|
|
4484
4516
|
throw this.#createError("Unexpected end of the stream within a double quoted scalar");
|
|
4485
4517
|
}
|
|
4486
4518
|
readFlowCollection(tag, anchor, nodeIndent) {
|
|
4487
|
-
let ch = this.peek();
|
|
4519
|
+
let ch = this.#scanner.peek();
|
|
4488
4520
|
let terminator;
|
|
4489
4521
|
let isMapping = true;
|
|
4490
4522
|
let result = {};
|
|
@@ -4498,7 +4530,8 @@ var LoaderState = class {
|
|
|
4498
4530
|
return;
|
|
4499
4531
|
}
|
|
4500
4532
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
4501
|
-
|
|
4533
|
+
this.#scanner.next();
|
|
4534
|
+
ch = this.#scanner.peek();
|
|
4502
4535
|
let readNext = true;
|
|
4503
4536
|
let valueNode = null;
|
|
4504
4537
|
let keyNode = null;
|
|
@@ -4510,9 +4543,9 @@ var LoaderState = class {
|
|
|
4510
4543
|
const overridableKeys = /* @__PURE__ */ new Set();
|
|
4511
4544
|
while (ch !== 0) {
|
|
4512
4545
|
this.skipSeparationSpace(true, nodeIndent);
|
|
4513
|
-
ch = this.peek();
|
|
4546
|
+
ch = this.#scanner.peek();
|
|
4514
4547
|
if (ch === terminator) {
|
|
4515
|
-
this.
|
|
4548
|
+
this.#scanner.next();
|
|
4516
4549
|
const kind = isMapping ? "mapping" : "sequence";
|
|
4517
4550
|
return {
|
|
4518
4551
|
tag,
|
|
@@ -4527,10 +4560,10 @@ var LoaderState = class {
|
|
|
4527
4560
|
keyTag = keyNode = valueNode = null;
|
|
4528
4561
|
isPair = isExplicitPair = false;
|
|
4529
4562
|
if (ch === QUESTION) {
|
|
4530
|
-
following = this.peek(1);
|
|
4563
|
+
following = this.#scanner.peek(1);
|
|
4531
4564
|
if (isWhiteSpaceOrEOL(following)) {
|
|
4532
4565
|
isPair = isExplicitPair = true;
|
|
4533
|
-
this.
|
|
4566
|
+
this.#scanner.next();
|
|
4534
4567
|
this.skipSeparationSpace(true, nodeIndent);
|
|
4535
4568
|
}
|
|
4536
4569
|
}
|
|
@@ -4546,10 +4579,11 @@ var LoaderState = class {
|
|
|
4546
4579
|
keyNode = newState.result;
|
|
4547
4580
|
}
|
|
4548
4581
|
this.skipSeparationSpace(true, nodeIndent);
|
|
4549
|
-
ch = this.peek();
|
|
4582
|
+
ch = this.#scanner.peek();
|
|
4550
4583
|
if ((isExplicitPair || this.line === line) && ch === COLON) {
|
|
4551
4584
|
isPair = true;
|
|
4552
|
-
|
|
4585
|
+
this.#scanner.next();
|
|
4586
|
+
ch = this.#scanner.peek();
|
|
4553
4587
|
this.skipSeparationSpace(true, nodeIndent);
|
|
4554
4588
|
const newState2 = this.composeNode({
|
|
4555
4589
|
parentIndent: nodeIndent,
|
|
@@ -4567,10 +4601,11 @@ var LoaderState = class {
|
|
|
4567
4601
|
result.push(keyNode);
|
|
4568
4602
|
}
|
|
4569
4603
|
this.skipSeparationSpace(true, nodeIndent);
|
|
4570
|
-
ch = this.peek();
|
|
4604
|
+
ch = this.#scanner.peek();
|
|
4571
4605
|
if (ch === COMMA) {
|
|
4572
4606
|
readNext = true;
|
|
4573
|
-
|
|
4607
|
+
this.#scanner.next();
|
|
4608
|
+
ch = this.#scanner.peek();
|
|
4574
4609
|
} else {
|
|
4575
4610
|
readNext = false;
|
|
4576
4611
|
}
|
|
@@ -4586,7 +4621,7 @@ var LoaderState = class {
|
|
|
4586
4621
|
let textIndent = nodeIndent;
|
|
4587
4622
|
let emptyLines = 0;
|
|
4588
4623
|
let atMoreIndented = false;
|
|
4589
|
-
let ch = this.peek();
|
|
4624
|
+
let ch = this.#scanner.peek();
|
|
4590
4625
|
let folding = false;
|
|
4591
4626
|
if (ch === VERTICAL_LINE) {
|
|
4592
4627
|
folding = false;
|
|
@@ -4598,7 +4633,8 @@ var LoaderState = class {
|
|
|
4598
4633
|
let result = "";
|
|
4599
4634
|
let tmp = 0;
|
|
4600
4635
|
while (ch !== 0) {
|
|
4601
|
-
|
|
4636
|
+
this.#scanner.next();
|
|
4637
|
+
ch = this.#scanner.peek();
|
|
4602
4638
|
if (ch === PLUS || ch === MINUS) {
|
|
4603
4639
|
if (CHOMPING_CLIP === chomping) {
|
|
4604
4640
|
chomping = ch === PLUS ? CHOMPING_KEEP : CHOMPING_STRIP;
|
|
@@ -4621,15 +4657,16 @@ var LoaderState = class {
|
|
|
4621
4657
|
if (isWhiteSpace(ch)) {
|
|
4622
4658
|
this.skipWhitespaces();
|
|
4623
4659
|
this.skipComment();
|
|
4624
|
-
ch = this.peek();
|
|
4660
|
+
ch = this.#scanner.peek();
|
|
4625
4661
|
}
|
|
4626
4662
|
while (ch !== 0) {
|
|
4627
4663
|
this.readLineBreak();
|
|
4628
4664
|
this.lineIndent = 0;
|
|
4629
|
-
ch = this.peek();
|
|
4665
|
+
ch = this.#scanner.peek();
|
|
4630
4666
|
while ((!detectedIndent || this.lineIndent < textIndent) && ch === SPACE) {
|
|
4631
4667
|
this.lineIndent++;
|
|
4632
|
-
|
|
4668
|
+
this.#scanner.next();
|
|
4669
|
+
ch = this.#scanner.peek();
|
|
4633
4670
|
}
|
|
4634
4671
|
if (!detectedIndent && this.lineIndent > textIndent) {
|
|
4635
4672
|
textIndent = this.lineIndent;
|
|
@@ -4668,11 +4705,12 @@ var LoaderState = class {
|
|
|
4668
4705
|
didReadContent = true;
|
|
4669
4706
|
detectedIndent = true;
|
|
4670
4707
|
emptyLines = 0;
|
|
4671
|
-
const captureStart = this.position;
|
|
4708
|
+
const captureStart = this.#scanner.position;
|
|
4672
4709
|
while (!isEOL(ch) && ch !== 0) {
|
|
4673
|
-
|
|
4710
|
+
this.#scanner.next();
|
|
4711
|
+
ch = this.#scanner.peek();
|
|
4674
4712
|
}
|
|
4675
|
-
const segment = this.captureSegment(captureStart, this.position, false);
|
|
4713
|
+
const segment = this.captureSegment(captureStart, this.#scanner.position, false);
|
|
4676
4714
|
if (segment) result += segment;
|
|
4677
4715
|
}
|
|
4678
4716
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
@@ -4695,11 +4733,11 @@ var LoaderState = class {
|
|
|
4695
4733
|
let atExplicitKey = false;
|
|
4696
4734
|
let detected = false;
|
|
4697
4735
|
if (anchor !== null) this.anchorMap.set(anchor, result);
|
|
4698
|
-
let ch = this.peek();
|
|
4736
|
+
let ch = this.#scanner.peek();
|
|
4699
4737
|
while (ch !== 0) {
|
|
4700
|
-
const following = this.peek(1);
|
|
4738
|
+
const following = this.#scanner.peek(1);
|
|
4701
4739
|
line = this.line;
|
|
4702
|
-
pos = this.position;
|
|
4740
|
+
pos = this.#scanner.position;
|
|
4703
4741
|
if ((ch === QUESTION || ch === COLON) && isWhiteSpaceOrEOL(following)) {
|
|
4704
4742
|
if (ch === QUESTION) {
|
|
4705
4743
|
if (atExplicitKey) {
|
|
@@ -4717,7 +4755,7 @@ var LoaderState = class {
|
|
|
4717
4755
|
} else {
|
|
4718
4756
|
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");
|
|
4719
4757
|
}
|
|
4720
|
-
this.
|
|
4758
|
+
this.#scanner.next();
|
|
4721
4759
|
ch = following;
|
|
4722
4760
|
} else {
|
|
4723
4761
|
const newState = this.composeNode({
|
|
@@ -4728,11 +4766,12 @@ var LoaderState = class {
|
|
|
4728
4766
|
});
|
|
4729
4767
|
if (!newState) break;
|
|
4730
4768
|
if (this.line === line) {
|
|
4731
|
-
ch = this.peek();
|
|
4769
|
+
ch = this.#scanner.peek();
|
|
4732
4770
|
this.skipWhitespaces();
|
|
4733
|
-
ch = this.peek();
|
|
4771
|
+
ch = this.#scanner.peek();
|
|
4734
4772
|
if (ch === COLON) {
|
|
4735
|
-
|
|
4773
|
+
this.#scanner.next();
|
|
4774
|
+
ch = this.#scanner.peek();
|
|
4736
4775
|
if (!isWhiteSpaceOrEOL(ch)) {
|
|
4737
4776
|
throw this.#createError("Cannot read block: a whitespace character is expected after the key-value separator within a block mapping");
|
|
4738
4777
|
}
|
|
@@ -4789,7 +4828,7 @@ var LoaderState = class {
|
|
|
4789
4828
|
keyTag = keyNode = valueNode = null;
|
|
4790
4829
|
}
|
|
4791
4830
|
this.skipSeparationSpace(true, -1);
|
|
4792
|
-
ch = this.peek();
|
|
4831
|
+
ch = this.#scanner.peek();
|
|
4793
4832
|
}
|
|
4794
4833
|
if (this.lineIndent > nodeIndent && ch !== 0) {
|
|
4795
4834
|
throw this.#createError("Cannot read block: bad indentation of a mapping entry");
|
|
@@ -4812,30 +4851,35 @@ var LoaderState = class {
|
|
|
4812
4851
|
let isNamed = false;
|
|
4813
4852
|
let tagHandle = "";
|
|
4814
4853
|
let tagName;
|
|
4815
|
-
let ch = this.peek();
|
|
4854
|
+
let ch = this.#scanner.peek();
|
|
4816
4855
|
if (ch !== EXCLAMATION) return;
|
|
4817
4856
|
if (tag !== null) {
|
|
4818
4857
|
throw this.#createError("Cannot read tag property: duplication of a tag property");
|
|
4819
4858
|
}
|
|
4820
|
-
|
|
4859
|
+
this.#scanner.next();
|
|
4860
|
+
ch = this.#scanner.peek();
|
|
4821
4861
|
if (ch === SMALLER_THAN) {
|
|
4822
4862
|
isVerbatim = true;
|
|
4823
|
-
|
|
4863
|
+
this.#scanner.next();
|
|
4864
|
+
ch = this.#scanner.peek();
|
|
4824
4865
|
} else if (ch === EXCLAMATION) {
|
|
4825
4866
|
isNamed = true;
|
|
4826
4867
|
tagHandle = "!!";
|
|
4827
|
-
|
|
4868
|
+
this.#scanner.next();
|
|
4869
|
+
ch = this.#scanner.peek();
|
|
4828
4870
|
} else {
|
|
4829
4871
|
tagHandle = "!";
|
|
4830
4872
|
}
|
|
4831
|
-
let position = this.position;
|
|
4873
|
+
let position = this.#scanner.position;
|
|
4832
4874
|
if (isVerbatim) {
|
|
4833
4875
|
do {
|
|
4834
|
-
|
|
4876
|
+
this.#scanner.next();
|
|
4877
|
+
ch = this.#scanner.peek();
|
|
4835
4878
|
} while (ch !== 0 && ch !== GREATER_THAN);
|
|
4836
|
-
if (this.
|
|
4837
|
-
tagName = this.
|
|
4838
|
-
|
|
4879
|
+
if (!this.#scanner.eof()) {
|
|
4880
|
+
tagName = this.#scanner.source.slice(position, this.#scanner.position);
|
|
4881
|
+
this.#scanner.next();
|
|
4882
|
+
ch = this.#scanner.peek();
|
|
4839
4883
|
} else {
|
|
4840
4884
|
throw this.#createError("Cannot read tag property: unexpected end of stream");
|
|
4841
4885
|
}
|
|
@@ -4843,19 +4887,20 @@ var LoaderState = class {
|
|
|
4843
4887
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
|
|
4844
4888
|
if (ch === EXCLAMATION) {
|
|
4845
4889
|
if (!isNamed) {
|
|
4846
|
-
tagHandle = this.
|
|
4890
|
+
tagHandle = this.#scanner.source.slice(position - 1, this.#scanner.position + 1);
|
|
4847
4891
|
if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
|
4848
4892
|
throw this.#createError("Cannot read tag property: named tag handle contains invalid characters");
|
|
4849
4893
|
}
|
|
4850
4894
|
isNamed = true;
|
|
4851
|
-
position = this.position + 1;
|
|
4895
|
+
position = this.#scanner.position + 1;
|
|
4852
4896
|
} else {
|
|
4853
4897
|
throw this.#createError("Cannot read tag property: tag suffix cannot contain an exclamation mark");
|
|
4854
4898
|
}
|
|
4855
4899
|
}
|
|
4856
|
-
|
|
4900
|
+
this.#scanner.next();
|
|
4901
|
+
ch = this.#scanner.peek();
|
|
4857
4902
|
}
|
|
4858
|
-
tagName = this.
|
|
4903
|
+
tagName = this.#scanner.source.slice(position, this.#scanner.position);
|
|
4859
4904
|
if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
|
4860
4905
|
throw this.#createError("Cannot read tag property: tag suffix cannot contain flow indicator characters");
|
|
4861
4906
|
}
|
|
@@ -4875,32 +4920,36 @@ var LoaderState = class {
|
|
|
4875
4920
|
throw this.#createError(`Cannot read tag property: undeclared tag handle "${tagHandle}"`);
|
|
4876
4921
|
}
|
|
4877
4922
|
readAnchorProperty(anchor) {
|
|
4878
|
-
let ch = this.peek();
|
|
4923
|
+
let ch = this.#scanner.peek();
|
|
4879
4924
|
if (ch !== AMPERSAND) return;
|
|
4880
4925
|
if (anchor !== null) {
|
|
4881
4926
|
throw this.#createError("Cannot read anchor property: duplicate anchor property");
|
|
4882
4927
|
}
|
|
4883
|
-
|
|
4884
|
-
|
|
4928
|
+
this.#scanner.next();
|
|
4929
|
+
ch = this.#scanner.peek();
|
|
4930
|
+
const position = this.#scanner.position;
|
|
4885
4931
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
|
|
4886
|
-
|
|
4932
|
+
this.#scanner.next();
|
|
4933
|
+
ch = this.#scanner.peek();
|
|
4887
4934
|
}
|
|
4888
|
-
if (this.position === position) {
|
|
4935
|
+
if (this.#scanner.position === position) {
|
|
4889
4936
|
throw this.#createError("Cannot read anchor property: name of an anchor node must contain at least one character");
|
|
4890
4937
|
}
|
|
4891
|
-
return this.
|
|
4938
|
+
return this.#scanner.source.slice(position, this.#scanner.position);
|
|
4892
4939
|
}
|
|
4893
4940
|
readAlias() {
|
|
4894
|
-
if (this.peek() !== ASTERISK) return;
|
|
4895
|
-
|
|
4896
|
-
|
|
4941
|
+
if (this.#scanner.peek() !== ASTERISK) return;
|
|
4942
|
+
this.#scanner.next();
|
|
4943
|
+
let ch = this.#scanner.peek();
|
|
4944
|
+
const position = this.#scanner.position;
|
|
4897
4945
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
|
|
4898
|
-
|
|
4946
|
+
this.#scanner.next();
|
|
4947
|
+
ch = this.#scanner.peek();
|
|
4899
4948
|
}
|
|
4900
|
-
if (this.position === position) {
|
|
4949
|
+
if (this.#scanner.position === position) {
|
|
4901
4950
|
throw this.#createError("Cannot read alias: alias name must contain at least one character");
|
|
4902
4951
|
}
|
|
4903
|
-
const alias = this.
|
|
4952
|
+
const alias = this.#scanner.source.slice(position, this.#scanner.position);
|
|
4904
4953
|
if (!this.anchorMap.has(alias)) {
|
|
4905
4954
|
throw this.#createError(`Cannot read alias: unidentified alias "${alias}"`);
|
|
4906
4955
|
}
|
|
@@ -4983,7 +5032,7 @@ var LoaderState = class {
|
|
|
4983
5032
|
const cond = CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext;
|
|
4984
5033
|
const flowIndent = cond ? parentIndent : parentIndent + 1;
|
|
4985
5034
|
if (allowBlockCollections) {
|
|
4986
|
-
const blockIndent = this.position - this.lineStart;
|
|
5035
|
+
const blockIndent = this.#scanner.position - this.lineStart;
|
|
4987
5036
|
const blockSequenceState = this.readBlockSequence(tag, anchor, blockIndent);
|
|
4988
5037
|
if (blockSequenceState) return this.resolveTag(blockSequenceState);
|
|
4989
5038
|
const blockMappingState = this.readBlockMapping(tag, anchor, blockIndent, flowIndent);
|
|
@@ -5017,7 +5066,7 @@ var LoaderState = class {
|
|
|
5017
5066
|
return this.resolveTag(plainScalarState);
|
|
5018
5067
|
}
|
|
5019
5068
|
} else if (indentStatus === 0 && CONTEXT_BLOCK_OUT === nodeContext && allowBlockCollections) {
|
|
5020
|
-
const blockIndent = this.position - this.lineStart;
|
|
5069
|
+
const blockIndent = this.#scanner.position - this.lineStart;
|
|
5021
5070
|
const newState2 = this.readBlockSequence(tag, anchor, blockIndent);
|
|
5022
5071
|
if (newState2) return this.resolveTag(newState2);
|
|
5023
5072
|
}
|
|
@@ -5032,20 +5081,22 @@ var LoaderState = class {
|
|
|
5032
5081
|
readDirectives() {
|
|
5033
5082
|
let hasDirectives = false;
|
|
5034
5083
|
let version = null;
|
|
5035
|
-
let ch = this.peek();
|
|
5084
|
+
let ch = this.#scanner.peek();
|
|
5036
5085
|
while (ch !== 0) {
|
|
5037
5086
|
this.skipSeparationSpace(true, -1);
|
|
5038
|
-
ch = this.peek();
|
|
5087
|
+
ch = this.#scanner.peek();
|
|
5039
5088
|
if (this.lineIndent > 0 || ch !== PERCENT) {
|
|
5040
5089
|
break;
|
|
5041
5090
|
}
|
|
5042
5091
|
hasDirectives = true;
|
|
5043
|
-
|
|
5044
|
-
|
|
5092
|
+
this.#scanner.next();
|
|
5093
|
+
ch = this.#scanner.peek();
|
|
5094
|
+
let position = this.#scanner.position;
|
|
5045
5095
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
|
|
5046
|
-
|
|
5096
|
+
this.#scanner.next();
|
|
5097
|
+
ch = this.#scanner.peek();
|
|
5047
5098
|
}
|
|
5048
|
-
const directiveName = this.
|
|
5099
|
+
const directiveName = this.#scanner.source.slice(position, this.#scanner.position);
|
|
5049
5100
|
const directiveArgs = [];
|
|
5050
5101
|
if (directiveName.length < 1) {
|
|
5051
5102
|
throw this.#createError("Cannot read document: directive name length must be greater than zero");
|
|
@@ -5053,13 +5104,14 @@ var LoaderState = class {
|
|
|
5053
5104
|
while (ch !== 0) {
|
|
5054
5105
|
this.skipWhitespaces();
|
|
5055
5106
|
this.skipComment();
|
|
5056
|
-
ch = this.peek();
|
|
5107
|
+
ch = this.#scanner.peek();
|
|
5057
5108
|
if (isEOL(ch)) break;
|
|
5058
|
-
position = this.position;
|
|
5109
|
+
position = this.#scanner.position;
|
|
5059
5110
|
while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
|
|
5060
|
-
|
|
5111
|
+
this.#scanner.next();
|
|
5112
|
+
ch = this.#scanner.peek();
|
|
5061
5113
|
}
|
|
5062
|
-
directiveArgs.push(this.
|
|
5114
|
+
directiveArgs.push(this.#scanner.source.slice(position, this.#scanner.position));
|
|
5063
5115
|
}
|
|
5064
5116
|
if (ch !== 0) this.readLineBreak();
|
|
5065
5117
|
switch (directiveName) {
|
|
@@ -5076,20 +5128,20 @@ var LoaderState = class {
|
|
|
5076
5128
|
this.dispatchWarning(`unknown document directive "${directiveName}"`);
|
|
5077
5129
|
break;
|
|
5078
5130
|
}
|
|
5079
|
-
ch = this.peek();
|
|
5131
|
+
ch = this.#scanner.peek();
|
|
5080
5132
|
}
|
|
5081
5133
|
return hasDirectives;
|
|
5082
5134
|
}
|
|
5083
5135
|
readDocument() {
|
|
5084
|
-
const documentStart = this.position;
|
|
5136
|
+
const documentStart = this.#scanner.position;
|
|
5085
5137
|
this.checkLineBreaks = false;
|
|
5086
5138
|
this.tagMap = /* @__PURE__ */ new Map();
|
|
5087
5139
|
this.anchorMap = /* @__PURE__ */ new Map();
|
|
5088
5140
|
const hasDirectives = this.readDirectives();
|
|
5089
5141
|
this.skipSeparationSpace(true, -1);
|
|
5090
5142
|
let result = null;
|
|
5091
|
-
if (this.lineIndent === 0 && this.peek() === MINUS && this.peek(1) === MINUS && this.peek(2) === MINUS) {
|
|
5092
|
-
this.position += 3;
|
|
5143
|
+
if (this.lineIndent === 0 && this.#scanner.peek() === MINUS && this.#scanner.peek(1) === MINUS && this.#scanner.peek(2) === MINUS) {
|
|
5144
|
+
this.#scanner.position += 3;
|
|
5093
5145
|
this.skipSeparationSpace(true, -1);
|
|
5094
5146
|
} else if (hasDirectives) {
|
|
5095
5147
|
throw this.#createError("Cannot read document: directives end mark is expected");
|
|
@@ -5102,21 +5154,21 @@ var LoaderState = class {
|
|
|
5102
5154
|
});
|
|
5103
5155
|
if (newState) result = newState.result;
|
|
5104
5156
|
this.skipSeparationSpace(true, -1);
|
|
5105
|
-
if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.
|
|
5157
|
+
if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.#scanner.source.slice(documentStart, this.#scanner.position))) {
|
|
5106
5158
|
this.dispatchWarning("non-ASCII line breaks are interpreted as content");
|
|
5107
5159
|
}
|
|
5108
|
-
if (this.position === this.lineStart && this.testDocumentSeparator()) {
|
|
5109
|
-
if (this.peek() === DOT) {
|
|
5110
|
-
this.position += 3;
|
|
5160
|
+
if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
|
|
5161
|
+
if (this.#scanner.peek() === DOT) {
|
|
5162
|
+
this.#scanner.position += 3;
|
|
5111
5163
|
this.skipSeparationSpace(true, -1);
|
|
5112
5164
|
}
|
|
5113
|
-
} else if (this.
|
|
5165
|
+
} else if (!this.#scanner.eof()) {
|
|
5114
5166
|
throw this.#createError("Cannot read document: end of the stream or a document separator is expected");
|
|
5115
5167
|
}
|
|
5116
5168
|
return result;
|
|
5117
5169
|
}
|
|
5118
5170
|
*readDocuments() {
|
|
5119
|
-
while (this.
|
|
5171
|
+
while (!this.#scanner.eof()) {
|
|
5120
5172
|
yield this.readDocument();
|
|
5121
5173
|
}
|
|
5122
5174
|
}
|
|
@@ -5129,7 +5181,6 @@ function sanitizeInput(input) {
|
|
|
5129
5181
|
if (!isEOL(input.charCodeAt(input.length - 1))) input += "\n";
|
|
5130
5182
|
if (input.charCodeAt(0) === 65279) input = input.slice(1);
|
|
5131
5183
|
}
|
|
5132
|
-
input += "\0";
|
|
5133
5184
|
return input;
|
|
5134
5185
|
}
|
|
5135
5186
|
function parse(content, options = {}) {
|
|
@@ -5289,7 +5340,7 @@ function getDefaultAgents() {
|
|
|
5289
5340
|
}
|
|
5290
5341
|
|
|
5291
5342
|
// __mcpc__cli_latest/node_modules/@mcpc/cli/src/config/loader.js
|
|
5292
|
-
var CLI_VERSION = "0.1.
|
|
5343
|
+
var CLI_VERSION = "0.1.51";
|
|
5293
5344
|
function extractServerName(command, commandArgs) {
|
|
5294
5345
|
for (const arg of commandArgs) {
|
|
5295
5346
|
if (!arg.startsWith("-")) {
|
|
@@ -6898,6 +6949,147 @@ var ExperimentalServerTasks = class {
|
|
|
6898
6949
|
requestStream(request, resultSchema, options) {
|
|
6899
6950
|
return this._server.requestStream(request, resultSchema, options);
|
|
6900
6951
|
}
|
|
6952
|
+
/**
|
|
6953
|
+
* Sends a sampling request and returns an AsyncGenerator that yields response messages.
|
|
6954
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
6955
|
+
*
|
|
6956
|
+
* For task-augmented requests, yields 'taskCreated' and 'taskStatus' messages
|
|
6957
|
+
* before the final result.
|
|
6958
|
+
*
|
|
6959
|
+
* @example
|
|
6960
|
+
* ```typescript
|
|
6961
|
+
* const stream = server.experimental.tasks.createMessageStream({
|
|
6962
|
+
* messages: [{ role: 'user', content: { type: 'text', text: 'Hello' } }],
|
|
6963
|
+
* maxTokens: 100
|
|
6964
|
+
* }, {
|
|
6965
|
+
* onprogress: (progress) => {
|
|
6966
|
+
* // Handle streaming tokens via progress notifications
|
|
6967
|
+
* console.log('Progress:', progress.message);
|
|
6968
|
+
* }
|
|
6969
|
+
* });
|
|
6970
|
+
*
|
|
6971
|
+
* for await (const message of stream) {
|
|
6972
|
+
* switch (message.type) {
|
|
6973
|
+
* case 'taskCreated':
|
|
6974
|
+
* console.log('Task created:', message.task.taskId);
|
|
6975
|
+
* break;
|
|
6976
|
+
* case 'taskStatus':
|
|
6977
|
+
* console.log('Task status:', message.task.status);
|
|
6978
|
+
* break;
|
|
6979
|
+
* case 'result':
|
|
6980
|
+
* console.log('Final result:', message.result);
|
|
6981
|
+
* break;
|
|
6982
|
+
* case 'error':
|
|
6983
|
+
* console.error('Error:', message.error);
|
|
6984
|
+
* break;
|
|
6985
|
+
* }
|
|
6986
|
+
* }
|
|
6987
|
+
* ```
|
|
6988
|
+
*
|
|
6989
|
+
* @param params - The sampling request parameters
|
|
6990
|
+
* @param options - Optional request options (timeout, signal, task creation params, onprogress, etc.)
|
|
6991
|
+
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
6992
|
+
*
|
|
6993
|
+
* @experimental
|
|
6994
|
+
*/
|
|
6995
|
+
createMessageStream(params, options) {
|
|
6996
|
+
const clientCapabilities = this._server.getClientCapabilities();
|
|
6997
|
+
if ((params.tools || params.toolChoice) && !clientCapabilities?.sampling?.tools) {
|
|
6998
|
+
throw new Error("Client does not support sampling tools capability.");
|
|
6999
|
+
}
|
|
7000
|
+
if (params.messages.length > 0) {
|
|
7001
|
+
const lastMessage = params.messages[params.messages.length - 1];
|
|
7002
|
+
const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];
|
|
7003
|
+
const hasToolResults = lastContent.some((c) => c.type === "tool_result");
|
|
7004
|
+
const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : void 0;
|
|
7005
|
+
const previousContent = previousMessage ? Array.isArray(previousMessage.content) ? previousMessage.content : [previousMessage.content] : [];
|
|
7006
|
+
const hasPreviousToolUse = previousContent.some((c) => c.type === "tool_use");
|
|
7007
|
+
if (hasToolResults) {
|
|
7008
|
+
if (lastContent.some((c) => c.type !== "tool_result")) {
|
|
7009
|
+
throw new Error("The last message must contain only tool_result content if any is present");
|
|
7010
|
+
}
|
|
7011
|
+
if (!hasPreviousToolUse) {
|
|
7012
|
+
throw new Error("tool_result blocks are not matching any tool_use from the previous message");
|
|
7013
|
+
}
|
|
7014
|
+
}
|
|
7015
|
+
if (hasPreviousToolUse) {
|
|
7016
|
+
const toolUseIds = new Set(previousContent.filter((c) => c.type === "tool_use").map((c) => c.id));
|
|
7017
|
+
const toolResultIds = new Set(lastContent.filter((c) => c.type === "tool_result").map((c) => c.toolUseId));
|
|
7018
|
+
if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((id) => toolResultIds.has(id))) {
|
|
7019
|
+
throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match");
|
|
7020
|
+
}
|
|
7021
|
+
}
|
|
7022
|
+
}
|
|
7023
|
+
return this.requestStream({
|
|
7024
|
+
method: "sampling/createMessage",
|
|
7025
|
+
params
|
|
7026
|
+
}, CreateMessageResultSchema, options);
|
|
7027
|
+
}
|
|
7028
|
+
/**
|
|
7029
|
+
* Sends an elicitation request and returns an AsyncGenerator that yields response messages.
|
|
7030
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
7031
|
+
*
|
|
7032
|
+
* For task-augmented requests (especially URL-based elicitation), yields 'taskCreated'
|
|
7033
|
+
* and 'taskStatus' messages before the final result.
|
|
7034
|
+
*
|
|
7035
|
+
* @example
|
|
7036
|
+
* ```typescript
|
|
7037
|
+
* const stream = server.experimental.tasks.elicitInputStream({
|
|
7038
|
+
* mode: 'url',
|
|
7039
|
+
* message: 'Please authenticate',
|
|
7040
|
+
* elicitationId: 'auth-123',
|
|
7041
|
+
* url: 'https://example.com/auth'
|
|
7042
|
+
* }, {
|
|
7043
|
+
* task: { ttl: 300000 } // Task-augmented for long-running auth flow
|
|
7044
|
+
* });
|
|
7045
|
+
*
|
|
7046
|
+
* for await (const message of stream) {
|
|
7047
|
+
* switch (message.type) {
|
|
7048
|
+
* case 'taskCreated':
|
|
7049
|
+
* console.log('Task created:', message.task.taskId);
|
|
7050
|
+
* break;
|
|
7051
|
+
* case 'taskStatus':
|
|
7052
|
+
* console.log('Task status:', message.task.status);
|
|
7053
|
+
* break;
|
|
7054
|
+
* case 'result':
|
|
7055
|
+
* console.log('User action:', message.result.action);
|
|
7056
|
+
* break;
|
|
7057
|
+
* case 'error':
|
|
7058
|
+
* console.error('Error:', message.error);
|
|
7059
|
+
* break;
|
|
7060
|
+
* }
|
|
7061
|
+
* }
|
|
7062
|
+
* ```
|
|
7063
|
+
*
|
|
7064
|
+
* @param params - The elicitation request parameters
|
|
7065
|
+
* @param options - Optional request options (timeout, signal, task creation params, etc.)
|
|
7066
|
+
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
7067
|
+
*
|
|
7068
|
+
* @experimental
|
|
7069
|
+
*/
|
|
7070
|
+
elicitInputStream(params, options) {
|
|
7071
|
+
const clientCapabilities = this._server.getClientCapabilities();
|
|
7072
|
+
const mode = params.mode ?? "form";
|
|
7073
|
+
switch (mode) {
|
|
7074
|
+
case "url": {
|
|
7075
|
+
if (!clientCapabilities?.elicitation?.url) {
|
|
7076
|
+
throw new Error("Client does not support url elicitation.");
|
|
7077
|
+
}
|
|
7078
|
+
break;
|
|
7079
|
+
}
|
|
7080
|
+
case "form": {
|
|
7081
|
+
if (!clientCapabilities?.elicitation?.form) {
|
|
7082
|
+
throw new Error("Client does not support form elicitation.");
|
|
7083
|
+
}
|
|
7084
|
+
break;
|
|
7085
|
+
}
|
|
7086
|
+
}
|
|
7087
|
+
const normalizedParams = mode === "form" && params.mode === void 0 ? { ...params, mode: "form" } : params;
|
|
7088
|
+
return this.requestStream({
|
|
7089
|
+
method: "elicitation/create",
|
|
7090
|
+
params: normalizedParams
|
|
7091
|
+
}, ElicitResultSchema, options);
|
|
7092
|
+
}
|
|
6901
7093
|
/**
|
|
6902
7094
|
* Gets the current status of a task.
|
|
6903
7095
|
*
|
|
@@ -9086,22 +9278,45 @@ async function auth(provider, options) {
|
|
|
9086
9278
|
}
|
|
9087
9279
|
}
|
|
9088
9280
|
async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
|
|
9281
|
+
const cachedState = await provider.discoveryState?.();
|
|
9089
9282
|
let resourceMetadata;
|
|
9090
9283
|
let authorizationServerUrl;
|
|
9091
|
-
|
|
9092
|
-
|
|
9093
|
-
|
|
9094
|
-
|
|
9284
|
+
let metadata;
|
|
9285
|
+
let effectiveResourceMetadataUrl = resourceMetadataUrl;
|
|
9286
|
+
if (!effectiveResourceMetadataUrl && cachedState?.resourceMetadataUrl) {
|
|
9287
|
+
effectiveResourceMetadataUrl = new URL(cachedState.resourceMetadataUrl);
|
|
9288
|
+
}
|
|
9289
|
+
if (cachedState?.authorizationServerUrl) {
|
|
9290
|
+
authorizationServerUrl = cachedState.authorizationServerUrl;
|
|
9291
|
+
resourceMetadata = cachedState.resourceMetadata;
|
|
9292
|
+
metadata = cachedState.authorizationServerMetadata ?? await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn });
|
|
9293
|
+
if (!resourceMetadata) {
|
|
9294
|
+
try {
|
|
9295
|
+
resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl }, fetchFn);
|
|
9296
|
+
} catch {
|
|
9297
|
+
}
|
|
9095
9298
|
}
|
|
9096
|
-
|
|
9097
|
-
|
|
9098
|
-
|
|
9099
|
-
|
|
9299
|
+
if (metadata !== cachedState.authorizationServerMetadata || resourceMetadata !== cachedState.resourceMetadata) {
|
|
9300
|
+
await provider.saveDiscoveryState?.({
|
|
9301
|
+
authorizationServerUrl: String(authorizationServerUrl),
|
|
9302
|
+
resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
|
|
9303
|
+
resourceMetadata,
|
|
9304
|
+
authorizationServerMetadata: metadata
|
|
9305
|
+
});
|
|
9306
|
+
}
|
|
9307
|
+
} else {
|
|
9308
|
+
const serverInfo = await discoverOAuthServerInfo(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl, fetchFn });
|
|
9309
|
+
authorizationServerUrl = serverInfo.authorizationServerUrl;
|
|
9310
|
+
metadata = serverInfo.authorizationServerMetadata;
|
|
9311
|
+
resourceMetadata = serverInfo.resourceMetadata;
|
|
9312
|
+
await provider.saveDiscoveryState?.({
|
|
9313
|
+
authorizationServerUrl: String(authorizationServerUrl),
|
|
9314
|
+
resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
|
|
9315
|
+
resourceMetadata,
|
|
9316
|
+
authorizationServerMetadata: metadata
|
|
9317
|
+
});
|
|
9100
9318
|
}
|
|
9101
9319
|
const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
|
|
9102
|
-
const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, {
|
|
9103
|
-
fetchFn
|
|
9104
|
-
});
|
|
9105
9320
|
let clientInformation = await Promise.resolve(provider.clientInformation());
|
|
9106
9321
|
if (!clientInformation) {
|
|
9107
9322
|
if (authorizationCode !== void 0) {
|
|
@@ -9356,6 +9571,26 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
|
|
|
9356
9571
|
}
|
|
9357
9572
|
return void 0;
|
|
9358
9573
|
}
|
|
9574
|
+
async function discoverOAuthServerInfo(serverUrl, opts) {
|
|
9575
|
+
let resourceMetadata;
|
|
9576
|
+
let authorizationServerUrl;
|
|
9577
|
+
try {
|
|
9578
|
+
resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: opts?.resourceMetadataUrl }, opts?.fetchFn);
|
|
9579
|
+
if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
|
|
9580
|
+
authorizationServerUrl = resourceMetadata.authorization_servers[0];
|
|
9581
|
+
}
|
|
9582
|
+
} catch {
|
|
9583
|
+
}
|
|
9584
|
+
if (!authorizationServerUrl) {
|
|
9585
|
+
authorizationServerUrl = String(new URL("/", serverUrl));
|
|
9586
|
+
}
|
|
9587
|
+
const authorizationServerMetadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn: opts?.fetchFn });
|
|
9588
|
+
return {
|
|
9589
|
+
authorizationServerUrl,
|
|
9590
|
+
authorizationServerMetadata,
|
|
9591
|
+
resourceMetadata
|
|
9592
|
+
};
|
|
9593
|
+
}
|
|
9359
9594
|
async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
|
|
9360
9595
|
let authorizationUrl;
|
|
9361
9596
|
if (metadata) {
|
|
@@ -10220,18 +10455,6 @@ var cleanToolSchema = (schema) => {
|
|
|
10220
10455
|
import { cwd } from "node:process";
|
|
10221
10456
|
import process8 from "node:process";
|
|
10222
10457
|
import { createHash } from "node:crypto";
|
|
10223
|
-
var mcpClientPool = /* @__PURE__ */ new Map();
|
|
10224
|
-
var mcpClientConnecting = /* @__PURE__ */ new Map();
|
|
10225
|
-
var shortHash = (s) => createHash("sha256").update(s).digest("hex").slice(0, 8);
|
|
10226
|
-
function defSignature(def) {
|
|
10227
|
-
const defCopy = {
|
|
10228
|
-
...def
|
|
10229
|
-
};
|
|
10230
|
-
if (defCopy.transportType === "memory" || defCopy.transport) {
|
|
10231
|
-
return `memory:${Date.now()}:${Math.random()}`;
|
|
10232
|
-
}
|
|
10233
|
-
return JSON.stringify(defCopy);
|
|
10234
|
-
}
|
|
10235
10458
|
function createTransport(def) {
|
|
10236
10459
|
const defAny = def;
|
|
10237
10460
|
const explicitType = defAny.transportType || defAny.type;
|
|
@@ -10279,90 +10502,43 @@ function createTransport(def) {
|
|
|
10279
10502
|
}
|
|
10280
10503
|
throw new Error(`Unsupported transport configuration: ${JSON.stringify(def)}`);
|
|
10281
10504
|
}
|
|
10282
|
-
|
|
10283
|
-
const
|
|
10284
|
-
|
|
10285
|
-
|
|
10286
|
-
|
|
10287
|
-
|
|
10288
|
-
const existingConnecting = mcpClientConnecting.get(defKey);
|
|
10289
|
-
if (existingConnecting) {
|
|
10290
|
-
const client = await existingConnecting;
|
|
10291
|
-
const entry = mcpClientPool.get(defKey);
|
|
10292
|
-
if (entry) entry.refCount += 1;
|
|
10293
|
-
return client;
|
|
10294
|
-
}
|
|
10295
|
-
const transport = createTransport(def);
|
|
10296
|
-
const connecting = (async () => {
|
|
10297
|
-
const client = new Client({
|
|
10298
|
-
name: `mcp_${shortHash(defSignature(def))}`,
|
|
10299
|
-
version: "1.0.0"
|
|
10300
|
-
});
|
|
10301
|
-
await client.connect(transport, {
|
|
10302
|
-
timeout: 6e4 * 10
|
|
10303
|
-
});
|
|
10304
|
-
return client;
|
|
10305
|
-
})();
|
|
10306
|
-
mcpClientConnecting.set(defKey, connecting);
|
|
10307
|
-
try {
|
|
10308
|
-
const client = await connecting;
|
|
10309
|
-
mcpClientPool.set(defKey, {
|
|
10310
|
-
client,
|
|
10311
|
-
refCount: 1
|
|
10312
|
-
});
|
|
10313
|
-
return client;
|
|
10314
|
-
} finally {
|
|
10315
|
-
mcpClientConnecting.delete(defKey);
|
|
10505
|
+
function defSignature(def) {
|
|
10506
|
+
const defCopy = {
|
|
10507
|
+
...def
|
|
10508
|
+
};
|
|
10509
|
+
if (defCopy.transportType === "memory" || defCopy.transport) {
|
|
10510
|
+
return `memory:${Date.now()}:${Math.random()}`;
|
|
10316
10511
|
}
|
|
10512
|
+
return JSON.stringify(defCopy);
|
|
10317
10513
|
}
|
|
10318
|
-
|
|
10319
|
-
|
|
10320
|
-
|
|
10321
|
-
|
|
10322
|
-
|
|
10323
|
-
|
|
10324
|
-
|
|
10325
|
-
|
|
10326
|
-
|
|
10327
|
-
|
|
10328
|
-
|
|
10329
|
-
}
|
|
10514
|
+
var shortHash = (s) => createHash("sha256").update(s).digest("hex").slice(0, 8);
|
|
10515
|
+
async function createMcpClient(def) {
|
|
10516
|
+
const transport = createTransport(def);
|
|
10517
|
+
const client = new Client({
|
|
10518
|
+
name: `mcp_${shortHash(defSignature(def))}`,
|
|
10519
|
+
version: "1.0.0"
|
|
10520
|
+
});
|
|
10521
|
+
await client.connect(transport, {
|
|
10522
|
+
timeout: 6e4 * 10
|
|
10523
|
+
});
|
|
10524
|
+
return client;
|
|
10330
10525
|
}
|
|
10331
|
-
var cleanupAllPooledClients = async () => {
|
|
10332
|
-
const entries = Array.from(mcpClientPool.entries());
|
|
10333
|
-
mcpClientPool.clear();
|
|
10334
|
-
await Promise.all(entries.map(async ([, { client }]) => {
|
|
10335
|
-
try {
|
|
10336
|
-
await client.close();
|
|
10337
|
-
} catch (err) {
|
|
10338
|
-
console.error("Error closing MCP client:", err);
|
|
10339
|
-
}
|
|
10340
|
-
}));
|
|
10341
|
-
};
|
|
10342
|
-
process8.once?.("exit", () => {
|
|
10343
|
-
cleanupAllPooledClients();
|
|
10344
|
-
});
|
|
10345
|
-
process8.once?.("SIGINT", () => {
|
|
10346
|
-
cleanupAllPooledClients().finally(() => process8.exit(0));
|
|
10347
|
-
});
|
|
10348
10526
|
async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
10349
10527
|
const allTools = {};
|
|
10350
10528
|
const allClients = {};
|
|
10351
|
-
const
|
|
10529
|
+
const clientsToClose = [];
|
|
10352
10530
|
for (const [name, definition] of Object.entries(mcpConfig.mcpServers)) {
|
|
10353
10531
|
const def = definition;
|
|
10354
10532
|
if (def.disabled) continue;
|
|
10355
|
-
const defKey = shortHash(defSignature(def));
|
|
10356
|
-
const serverId = name;
|
|
10357
10533
|
try {
|
|
10358
|
-
const client = await
|
|
10359
|
-
|
|
10360
|
-
allClients[
|
|
10534
|
+
const client = await createMcpClient(def);
|
|
10535
|
+
clientsToClose.push(client);
|
|
10536
|
+
allClients[name] = client;
|
|
10361
10537
|
const { tools } = await client.listTools();
|
|
10362
10538
|
tools.forEach((tool2) => {
|
|
10363
10539
|
const toolNameWithScope = `${name}.${tool2.name}`;
|
|
10364
10540
|
const internalToolName = tool2.name;
|
|
10365
|
-
const rawToolId = `${
|
|
10541
|
+
const rawToolId = `${name}_${internalToolName}`;
|
|
10366
10542
|
const toolId = sanitizePropertyKey(rawToolId);
|
|
10367
10543
|
if (filterIn && !filterIn({
|
|
10368
10544
|
action: internalToolName,
|
|
@@ -10374,7 +10550,7 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
|
10374
10550
|
})) {
|
|
10375
10551
|
return;
|
|
10376
10552
|
}
|
|
10377
|
-
const execute = (args) => allClients[
|
|
10553
|
+
const execute = (args) => allClients[name].callTool({
|
|
10378
10554
|
name: internalToolName,
|
|
10379
10555
|
arguments: args
|
|
10380
10556
|
}, void 0, {
|
|
@@ -10391,10 +10567,12 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
|
10391
10567
|
}
|
|
10392
10568
|
}
|
|
10393
10569
|
const cleanupClients = async () => {
|
|
10394
|
-
await Promise.all(
|
|
10395
|
-
|
|
10396
|
-
|
|
10397
|
-
|
|
10570
|
+
await Promise.all(clientsToClose.map((client) => {
|
|
10571
|
+
try {
|
|
10572
|
+
return client.close();
|
|
10573
|
+
} catch {
|
|
10574
|
+
}
|
|
10575
|
+
}));
|
|
10398
10576
|
};
|
|
10399
10577
|
return {
|
|
10400
10578
|
tools: allTools,
|