@chosengeneration/light-code 0.68.0 → 0.70.0

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/dist/server.js CHANGED
@@ -15481,7 +15481,7 @@ var require_events = __commonJS({
15481
15481
  var { webidl } = require_webidl();
15482
15482
  var { kEnumerableProperty } = require_util();
15483
15483
  var { MessagePort } = __require("worker_threads");
15484
- var MessageEvent = class _MessageEvent extends Event {
15484
+ var MessageEvent2 = class _MessageEvent extends Event {
15485
15485
  #eventInit;
15486
15486
  constructor(type, eventInitDict = {}) {
15487
15487
  webidl.argumentLengthCheck(arguments, 1, { header: "MessageEvent constructor" });
@@ -15549,7 +15549,7 @@ var require_events = __commonJS({
15549
15549
  return this.#eventInit.reason;
15550
15550
  }
15551
15551
  };
15552
- var ErrorEvent = class _ErrorEvent extends Event {
15552
+ var ErrorEvent2 = class _ErrorEvent extends Event {
15553
15553
  #eventInit;
15554
15554
  constructor(type, eventInitDict) {
15555
15555
  webidl.argumentLengthCheck(arguments, 1, { header: "ErrorEvent constructor" });
@@ -15579,7 +15579,7 @@ var require_events = __commonJS({
15579
15579
  return this.#eventInit.error;
15580
15580
  }
15581
15581
  };
15582
- Object.defineProperties(MessageEvent.prototype, {
15582
+ Object.defineProperties(MessageEvent2.prototype, {
15583
15583
  [Symbol.toStringTag]: {
15584
15584
  value: "MessageEvent",
15585
15585
  configurable: true
@@ -15600,7 +15600,7 @@ var require_events = __commonJS({
15600
15600
  code: kEnumerableProperty,
15601
15601
  wasClean: kEnumerableProperty
15602
15602
  });
15603
- Object.defineProperties(ErrorEvent.prototype, {
15603
+ Object.defineProperties(ErrorEvent2.prototype, {
15604
15604
  [Symbol.toStringTag]: {
15605
15605
  value: "ErrorEvent",
15606
15606
  configurable: true
@@ -15710,9 +15710,9 @@ var require_events = __commonJS({
15710
15710
  }
15711
15711
  ]);
15712
15712
  module.exports = {
15713
- MessageEvent,
15713
+ MessageEvent: MessageEvent2,
15714
15714
  CloseEvent,
15715
- ErrorEvent
15715
+ ErrorEvent: ErrorEvent2
15716
15716
  };
15717
15717
  }
15718
15718
  });
@@ -15723,7 +15723,7 @@ var require_util7 = __commonJS({
15723
15723
  "use strict";
15724
15724
  var { kReadyState, kController, kResponse, kBinaryType, kWebSocketURL } = require_symbols5();
15725
15725
  var { states, opcodes } = require_constants5();
15726
- var { MessageEvent, ErrorEvent } = require_events();
15726
+ var { MessageEvent: MessageEvent2, ErrorEvent: ErrorEvent2 } = require_events();
15727
15727
  function isEstablished(ws) {
15728
15728
  return ws[kReadyState] === states.OPEN;
15729
15729
  }
@@ -15756,7 +15756,7 @@ var require_util7 = __commonJS({
15756
15756
  dataForEvent = new Uint8Array(data).buffer;
15757
15757
  }
15758
15758
  }
15759
- fireEvent("message", ws, MessageEvent, {
15759
+ fireEvent("message", ws, MessageEvent2, {
15760
15760
  origin: ws[kWebSocketURL].origin,
15761
15761
  data: dataForEvent
15762
15762
  });
@@ -15789,7 +15789,7 @@ var require_util7 = __commonJS({
15789
15789
  response.socket.destroy();
15790
15790
  }
15791
15791
  if (reason) {
15792
- fireEvent("error", ws, ErrorEvent, {
15792
+ fireEvent("error", ws, ErrorEvent2, {
15793
15793
  error: new Error(reason)
15794
15794
  });
15795
15795
  }
@@ -39293,6 +39293,19 @@ var stdioServerSchema = external_exports.object({
39293
39293
  });
39294
39294
  var httpServerSchema = external_exports.object({
39295
39295
  url: external_exports.string().min(1).url(),
39296
+ /**
39297
+ * Which HTTP transport this server speaks.
39298
+ *
39299
+ * **It was not here, and zod strips what it does not declare** — so a config pasted from
39300
+ * another client saying `"type": "sse"` parsed happily, lost that word, and was then driven
39301
+ * with Streamable HTTP. §11 requires a pasted config to work unchanged, and this is the one
39302
+ * field that decides whether it works at all. Reported from real use as a remote server that
39303
+ * another client talks to and this one gets 401 from.
39304
+ *
39305
+ * Absent means "work it out" — see `buildTransport`. `http` is accepted as a spelling of
39306
+ * `streamable-http` because both appear in the wild.
39307
+ */
39308
+ type: external_exports.enum(["sse", "streamable-http", "http"]).optional(),
39296
39309
  headers: external_exports.record(external_exports.string(), external_exports.string()).optional(),
39297
39310
  disabled: external_exports.boolean().optional(),
39298
39311
  disabledTools: external_exports.array(external_exports.string()).optional(),
@@ -54071,21 +54084,477 @@ var StdioClientTransport = class {
54071
54084
  }
54072
54085
  };
54073
54086
 
54074
- // ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1_ed45788dfbfe808cc09dd7daea6bd385/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/mediaType.js
54075
- var import_content_type = __toESM(require_content_type(), 1);
54076
- function mediaTypeEssence(header) {
54077
- if (!header) {
54078
- return void 0;
54087
+ // ../../node_modules/.pnpm/eventsource-parser@3.1.0/node_modules/eventsource-parser/dist/index.js
54088
+ var ParseError = class extends Error {
54089
+ constructor(message3, options) {
54090
+ super(message3), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
54079
54091
  }
54080
- try {
54081
- return import_content_type.default.parse(header).type;
54082
- } catch {
54083
- const essence = (header.split(";", 1)[0] ?? "").trim().toLowerCase();
54084
- if (essence === "" || header.slice(essence.length).includes(",")) {
54085
- return void 0;
54092
+ };
54093
+ var LF = 10;
54094
+ var CR = 13;
54095
+ var SPACE = 32;
54096
+ function noop(_arg) {
54097
+ }
54098
+ function createParser(config2) {
54099
+ if (typeof config2 == "function")
54100
+ throw new TypeError(
54101
+ "`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
54102
+ );
54103
+ const { onEvent = noop, onError = noop, onRetry = noop, onComment, maxBufferSize } = config2, pendingFragments = [];
54104
+ let pendingFragmentsLength = 0, isFirstChunk = true, id, data = "", dataLines = 0, eventType, terminated = false;
54105
+ function feed(chunk) {
54106
+ if (terminated)
54107
+ throw new Error(
54108
+ "Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
54109
+ );
54110
+ if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
54111
+ const trailing2 = processLines(chunk);
54112
+ trailing2 !== "" && (pendingFragments.push(trailing2), pendingFragmentsLength = trailing2.length), checkBufferSize();
54113
+ return;
54086
54114
  }
54087
- return essence;
54115
+ if (chunk.indexOf(`
54116
+ `) === -1 && chunk.indexOf("\r") === -1) {
54117
+ pendingFragments.push(chunk), pendingFragmentsLength += chunk.length, checkBufferSize();
54118
+ return;
54119
+ }
54120
+ pendingFragments.push(chunk);
54121
+ const input = pendingFragments.join("");
54122
+ pendingFragments.length = 0, pendingFragmentsLength = 0;
54123
+ const trailing = processLines(input);
54124
+ trailing !== "" && (pendingFragments.push(trailing), pendingFragmentsLength = trailing.length), checkBufferSize();
54125
+ }
54126
+ function checkBufferSize() {
54127
+ maxBufferSize !== void 0 && (pendingFragmentsLength + data.length <= maxBufferSize || (terminated = true, pendingFragments.length = 0, pendingFragmentsLength = 0, id = void 0, data = "", dataLines = 0, eventType = void 0, onError(
54128
+ new ParseError(`Buffered data exceeded max buffer size of ${maxBufferSize} characters`, {
54129
+ type: "max-buffer-size-exceeded"
54130
+ })
54131
+ )));
54132
+ }
54133
+ function processLines(chunk) {
54134
+ let searchIndex = 0;
54135
+ if (chunk.indexOf("\r") === -1) {
54136
+ let lfIndex = chunk.indexOf(`
54137
+ `, searchIndex);
54138
+ for (; lfIndex !== -1; ) {
54139
+ if (searchIndex === lfIndex) {
54140
+ dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
54141
+ `, searchIndex);
54142
+ continue;
54143
+ }
54144
+ const firstCharCode = chunk.charCodeAt(searchIndex);
54145
+ if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
54146
+ const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
54147
+ if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
54148
+ onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
54149
+ `, searchIndex);
54150
+ continue;
54151
+ }
54152
+ data = dataLines === 0 ? value : `${data}
54153
+ ${value}`, dataLines++;
54154
+ } else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
54155
+ chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
54156
+ lfIndex
54157
+ ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
54158
+ searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
54159
+ `, searchIndex);
54160
+ }
54161
+ return chunk.slice(searchIndex);
54162
+ }
54163
+ for (; searchIndex < chunk.length; ) {
54164
+ const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
54165
+ `, searchIndex);
54166
+ let lineEnd = -1;
54167
+ if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
54168
+ break;
54169
+ parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
54170
+ }
54171
+ return chunk.slice(searchIndex);
54172
+ }
54173
+ function parseLine(chunk, start, end) {
54174
+ if (start === end) {
54175
+ dispatchEvent();
54176
+ return;
54177
+ }
54178
+ const firstCharCode = chunk.charCodeAt(start);
54179
+ if (isDataPrefix(chunk, start, firstCharCode)) {
54180
+ const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
54181
+ data = dataLines === 0 ? value2 : `${data}
54182
+ ${value2}`, dataLines++;
54183
+ return;
54184
+ }
54185
+ if (isEventPrefix(chunk, start, firstCharCode)) {
54186
+ eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
54187
+ return;
54188
+ }
54189
+ if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
54190
+ const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
54191
+ id = value2.includes("\0") ? void 0 : value2;
54192
+ return;
54193
+ }
54194
+ if (firstCharCode === 58) {
54195
+ if (onComment) {
54196
+ const line2 = chunk.slice(start, end);
54197
+ onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
54198
+ }
54199
+ return;
54200
+ }
54201
+ const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
54202
+ if (fieldSeparatorIndex === -1) {
54203
+ processField(line, "", line);
54204
+ return;
54205
+ }
54206
+ const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
54207
+ processField(field, value, line);
54088
54208
  }
54209
+ function processField(field, value, line) {
54210
+ switch (field) {
54211
+ case "event":
54212
+ eventType = value || void 0;
54213
+ break;
54214
+ case "data":
54215
+ data = dataLines === 0 ? value : `${data}
54216
+ ${value}`, dataLines++;
54217
+ break;
54218
+ case "id":
54219
+ id = value.includes("\0") ? void 0 : value;
54220
+ break;
54221
+ case "retry":
54222
+ /^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(
54223
+ new ParseError(`Invalid \`retry\` value: "${value}"`, {
54224
+ type: "invalid-retry",
54225
+ value,
54226
+ line
54227
+ })
54228
+ );
54229
+ break;
54230
+ default:
54231
+ onError(
54232
+ new ParseError(
54233
+ `Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`,
54234
+ { type: "unknown-field", field, value, line }
54235
+ )
54236
+ );
54237
+ break;
54238
+ }
54239
+ }
54240
+ function dispatchEvent() {
54241
+ dataLines > 0 && onEvent({
54242
+ id,
54243
+ event: eventType,
54244
+ data
54245
+ }), id = void 0, data = "", dataLines = 0, eventType = void 0;
54246
+ }
54247
+ function reset(options = {}) {
54248
+ if (options.consume && pendingFragments.length > 0) {
54249
+ const incompleteLine = pendingFragments.join("");
54250
+ parseLine(incompleteLine, 0, incompleteLine.length);
54251
+ }
54252
+ isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0, pendingFragmentsLength = 0, terminated = false;
54253
+ }
54254
+ return { feed, reset };
54255
+ }
54256
+ function isDataPrefix(chunk, i, firstCharCode) {
54257
+ return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
54258
+ }
54259
+ function isEventPrefix(chunk, i, firstCharCode) {
54260
+ return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
54261
+ }
54262
+
54263
+ // ../../node_modules/.pnpm/eventsource@3.0.7/node_modules/eventsource/dist/index.js
54264
+ var ErrorEvent = class extends Event {
54265
+ /**
54266
+ * Constructs a new `ErrorEvent` instance. This is typically not called directly,
54267
+ * but rather emitted by the `EventSource` object when an error occurs.
54268
+ *
54269
+ * @param type - The type of the event (should be "error")
54270
+ * @param errorEventInitDict - Optional properties to include in the error event
54271
+ */
54272
+ constructor(type, errorEventInitDict) {
54273
+ var _a3, _b;
54274
+ super(type), this.code = (_a3 = errorEventInitDict == null ? void 0 : errorEventInitDict.code) != null ? _a3 : void 0, this.message = (_b = errorEventInitDict == null ? void 0 : errorEventInitDict.message) != null ? _b : void 0;
54275
+ }
54276
+ /**
54277
+ * Node.js "hides" the `message` and `code` properties of the `ErrorEvent` instance,
54278
+ * when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging,
54279
+ * we explicitly include the properties in the `inspect` method.
54280
+ *
54281
+ * This is automatically called by Node.js when you `console.log` an instance of this class.
54282
+ *
54283
+ * @param _depth - The current depth
54284
+ * @param options - The options passed to `util.inspect`
54285
+ * @param inspect - The inspect function to use (prevents having to import it from `util`)
54286
+ * @returns A string representation of the error
54287
+ */
54288
+ [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")](_depth, options, inspect) {
54289
+ return inspect(inspectableError(this), options);
54290
+ }
54291
+ /**
54292
+ * Deno "hides" the `message` and `code` properties of the `ErrorEvent` instance,
54293
+ * when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging,
54294
+ * we explicitly include the properties in the `inspect` method.
54295
+ *
54296
+ * This is automatically called by Deno when you `console.log` an instance of this class.
54297
+ *
54298
+ * @param inspect - The inspect function to use (prevents having to import it from `util`)
54299
+ * @param options - The options passed to `Deno.inspect`
54300
+ * @returns A string representation of the error
54301
+ */
54302
+ [/* @__PURE__ */ Symbol.for("Deno.customInspect")](inspect, options) {
54303
+ return inspect(inspectableError(this), options);
54304
+ }
54305
+ };
54306
+ function syntaxError(message3) {
54307
+ const DomException = globalThis.DOMException;
54308
+ return typeof DomException == "function" ? new DomException(message3, "SyntaxError") : new SyntaxError(message3);
54309
+ }
54310
+ function flattenError2(err) {
54311
+ return err instanceof Error ? "errors" in err && Array.isArray(err.errors) ? err.errors.map(flattenError2).join(", ") : "cause" in err && err.cause instanceof Error ? `${err}: ${flattenError2(err.cause)}` : err.message : `${err}`;
54312
+ }
54313
+ function inspectableError(err) {
54314
+ return {
54315
+ type: err.type,
54316
+ message: err.message,
54317
+ code: err.code,
54318
+ defaultPrevented: err.defaultPrevented,
54319
+ cancelable: err.cancelable,
54320
+ timeStamp: err.timeStamp
54321
+ };
54322
+ }
54323
+ var __typeError = (msg) => {
54324
+ throw TypeError(msg);
54325
+ };
54326
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
54327
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
54328
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
54329
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
54330
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
54331
+ var _readyState;
54332
+ var _url2;
54333
+ var _redirectUrl;
54334
+ var _withCredentials;
54335
+ var _fetch;
54336
+ var _reconnectInterval;
54337
+ var _reconnectTimer;
54338
+ var _lastEventId;
54339
+ var _controller;
54340
+ var _parser;
54341
+ var _onError;
54342
+ var _onMessage;
54343
+ var _onOpen;
54344
+ var _EventSource_instances;
54345
+ var connect_fn;
54346
+ var _onFetchResponse;
54347
+ var _onFetchError;
54348
+ var getRequestOptions_fn;
54349
+ var _onEvent;
54350
+ var _onRetryChange;
54351
+ var failConnection_fn;
54352
+ var scheduleReconnect_fn;
54353
+ var _reconnect;
54354
+ var EventSource = class extends EventTarget {
54355
+ constructor(url2, eventSourceInitDict) {
54356
+ var _a3, _b;
54357
+ super(), __privateAdd(this, _EventSource_instances), this.CONNECTING = 0, this.OPEN = 1, this.CLOSED = 2, __privateAdd(this, _readyState), __privateAdd(this, _url2), __privateAdd(this, _redirectUrl), __privateAdd(this, _withCredentials), __privateAdd(this, _fetch), __privateAdd(this, _reconnectInterval), __privateAdd(this, _reconnectTimer), __privateAdd(this, _lastEventId, null), __privateAdd(this, _controller), __privateAdd(this, _parser), __privateAdd(this, _onError, null), __privateAdd(this, _onMessage, null), __privateAdd(this, _onOpen, null), __privateAdd(this, _onFetchResponse, async (response) => {
54358
+ var _a22;
54359
+ __privateGet(this, _parser).reset();
54360
+ const { body, redirected, status, headers } = response;
54361
+ if (status === 204) {
54362
+ __privateMethod(this, _EventSource_instances, failConnection_fn).call(this, "Server sent HTTP 204, not reconnecting", 204), this.close();
54363
+ return;
54364
+ }
54365
+ if (redirected ? __privateSet(this, _redirectUrl, new URL(response.url)) : __privateSet(this, _redirectUrl, void 0), status !== 200) {
54366
+ __privateMethod(this, _EventSource_instances, failConnection_fn).call(this, `Non-200 status code (${status})`, status);
54367
+ return;
54368
+ }
54369
+ if (!(headers.get("content-type") || "").startsWith("text/event-stream")) {
54370
+ __privateMethod(this, _EventSource_instances, failConnection_fn).call(this, 'Invalid content type, expected "text/event-stream"', status);
54371
+ return;
54372
+ }
54373
+ if (__privateGet(this, _readyState) === this.CLOSED)
54374
+ return;
54375
+ __privateSet(this, _readyState, this.OPEN);
54376
+ const openEvent = new Event("open");
54377
+ if ((_a22 = __privateGet(this, _onOpen)) == null || _a22.call(this, openEvent), this.dispatchEvent(openEvent), typeof body != "object" || !body || !("getReader" in body)) {
54378
+ __privateMethod(this, _EventSource_instances, failConnection_fn).call(this, "Invalid response body, expected a web ReadableStream", status), this.close();
54379
+ return;
54380
+ }
54381
+ const decoder = new TextDecoder(), reader = body.getReader();
54382
+ let open = true;
54383
+ do {
54384
+ const { done, value } = await reader.read();
54385
+ value && __privateGet(this, _parser).feed(decoder.decode(value, { stream: !done })), done && (open = false, __privateGet(this, _parser).reset(), __privateMethod(this, _EventSource_instances, scheduleReconnect_fn).call(this));
54386
+ } while (open);
54387
+ }), __privateAdd(this, _onFetchError, (err) => {
54388
+ __privateSet(this, _controller, void 0), !(err.name === "AbortError" || err.type === "aborted") && __privateMethod(this, _EventSource_instances, scheduleReconnect_fn).call(this, flattenError2(err));
54389
+ }), __privateAdd(this, _onEvent, (event) => {
54390
+ typeof event.id == "string" && __privateSet(this, _lastEventId, event.id);
54391
+ const messageEvent = new MessageEvent(event.event || "message", {
54392
+ data: event.data,
54393
+ origin: __privateGet(this, _redirectUrl) ? __privateGet(this, _redirectUrl).origin : __privateGet(this, _url2).origin,
54394
+ lastEventId: event.id || ""
54395
+ });
54396
+ __privateGet(this, _onMessage) && (!event.event || event.event === "message") && __privateGet(this, _onMessage).call(this, messageEvent), this.dispatchEvent(messageEvent);
54397
+ }), __privateAdd(this, _onRetryChange, (value) => {
54398
+ __privateSet(this, _reconnectInterval, value);
54399
+ }), __privateAdd(this, _reconnect, () => {
54400
+ __privateSet(this, _reconnectTimer, void 0), __privateGet(this, _readyState) === this.CONNECTING && __privateMethod(this, _EventSource_instances, connect_fn).call(this);
54401
+ });
54402
+ try {
54403
+ if (url2 instanceof URL)
54404
+ __privateSet(this, _url2, url2);
54405
+ else if (typeof url2 == "string")
54406
+ __privateSet(this, _url2, new URL(url2, getBaseURL()));
54407
+ else
54408
+ throw new Error("Invalid URL");
54409
+ } catch {
54410
+ throw syntaxError("An invalid or illegal string was specified");
54411
+ }
54412
+ __privateSet(this, _parser, createParser({
54413
+ onEvent: __privateGet(this, _onEvent),
54414
+ onRetry: __privateGet(this, _onRetryChange)
54415
+ })), __privateSet(this, _readyState, this.CONNECTING), __privateSet(this, _reconnectInterval, 3e3), __privateSet(this, _fetch, (_a3 = eventSourceInitDict == null ? void 0 : eventSourceInitDict.fetch) != null ? _a3 : globalThis.fetch), __privateSet(this, _withCredentials, (_b = eventSourceInitDict == null ? void 0 : eventSourceInitDict.withCredentials) != null ? _b : false), __privateMethod(this, _EventSource_instances, connect_fn).call(this);
54416
+ }
54417
+ /**
54418
+ * Returns the state of this EventSource object's connection. It can have the values described below.
54419
+ *
54420
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/readyState)
54421
+ *
54422
+ * Note: typed as `number` instead of `0 | 1 | 2` for compatibility with the `EventSource` interface,
54423
+ * defined in the TypeScript `dom` library.
54424
+ *
54425
+ * @public
54426
+ */
54427
+ get readyState() {
54428
+ return __privateGet(this, _readyState);
54429
+ }
54430
+ /**
54431
+ * Returns the URL providing the event stream.
54432
+ *
54433
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/url)
54434
+ *
54435
+ * @public
54436
+ */
54437
+ get url() {
54438
+ return __privateGet(this, _url2).href;
54439
+ }
54440
+ /**
54441
+ * Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise.
54442
+ *
54443
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/withCredentials)
54444
+ */
54445
+ get withCredentials() {
54446
+ return __privateGet(this, _withCredentials);
54447
+ }
54448
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/error_event) */
54449
+ get onerror() {
54450
+ return __privateGet(this, _onError);
54451
+ }
54452
+ set onerror(value) {
54453
+ __privateSet(this, _onError, value);
54454
+ }
54455
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/message_event) */
54456
+ get onmessage() {
54457
+ return __privateGet(this, _onMessage);
54458
+ }
54459
+ set onmessage(value) {
54460
+ __privateSet(this, _onMessage, value);
54461
+ }
54462
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/open_event) */
54463
+ get onopen() {
54464
+ return __privateGet(this, _onOpen);
54465
+ }
54466
+ set onopen(value) {
54467
+ __privateSet(this, _onOpen, value);
54468
+ }
54469
+ addEventListener(type, listener, options) {
54470
+ const listen = listener;
54471
+ super.addEventListener(type, listen, options);
54472
+ }
54473
+ removeEventListener(type, listener, options) {
54474
+ const listen = listener;
54475
+ super.removeEventListener(type, listen, options);
54476
+ }
54477
+ /**
54478
+ * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
54479
+ *
54480
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/close)
54481
+ *
54482
+ * @public
54483
+ */
54484
+ close() {
54485
+ __privateGet(this, _reconnectTimer) && clearTimeout(__privateGet(this, _reconnectTimer)), __privateGet(this, _readyState) !== this.CLOSED && (__privateGet(this, _controller) && __privateGet(this, _controller).abort(), __privateSet(this, _readyState, this.CLOSED), __privateSet(this, _controller, void 0));
54486
+ }
54487
+ };
54488
+ _readyState = /* @__PURE__ */ new WeakMap(), _url2 = /* @__PURE__ */ new WeakMap(), _redirectUrl = /* @__PURE__ */ new WeakMap(), _withCredentials = /* @__PURE__ */ new WeakMap(), _fetch = /* @__PURE__ */ new WeakMap(), _reconnectInterval = /* @__PURE__ */ new WeakMap(), _reconnectTimer = /* @__PURE__ */ new WeakMap(), _lastEventId = /* @__PURE__ */ new WeakMap(), _controller = /* @__PURE__ */ new WeakMap(), _parser = /* @__PURE__ */ new WeakMap(), _onError = /* @__PURE__ */ new WeakMap(), _onMessage = /* @__PURE__ */ new WeakMap(), _onOpen = /* @__PURE__ */ new WeakMap(), _EventSource_instances = /* @__PURE__ */ new WeakSet(), /**
54489
+ * Connect to the given URL and start receiving events
54490
+ *
54491
+ * @internal
54492
+ */
54493
+ connect_fn = function() {
54494
+ __privateSet(this, _readyState, this.CONNECTING), __privateSet(this, _controller, new AbortController()), __privateGet(this, _fetch)(__privateGet(this, _url2), __privateMethod(this, _EventSource_instances, getRequestOptions_fn).call(this)).then(__privateGet(this, _onFetchResponse)).catch(__privateGet(this, _onFetchError));
54495
+ }, _onFetchResponse = /* @__PURE__ */ new WeakMap(), _onFetchError = /* @__PURE__ */ new WeakMap(), /**
54496
+ * Get request options for the `fetch()` request
54497
+ *
54498
+ * @returns The request options
54499
+ * @internal
54500
+ */
54501
+ getRequestOptions_fn = function() {
54502
+ var _a3;
54503
+ const init = {
54504
+ // [spec] Let `corsAttributeState` be `Anonymous`…
54505
+ // [spec] …will have their mode set to "cors"…
54506
+ mode: "cors",
54507
+ redirect: "follow",
54508
+ headers: { Accept: "text/event-stream", ...__privateGet(this, _lastEventId) ? { "Last-Event-ID": __privateGet(this, _lastEventId) } : void 0 },
54509
+ cache: "no-store",
54510
+ signal: (_a3 = __privateGet(this, _controller)) == null ? void 0 : _a3.signal
54511
+ };
54512
+ return "window" in globalThis && (init.credentials = this.withCredentials ? "include" : "same-origin"), init;
54513
+ }, _onEvent = /* @__PURE__ */ new WeakMap(), _onRetryChange = /* @__PURE__ */ new WeakMap(), /**
54514
+ * Handles the process referred to in the EventSource specification as "failing a connection".
54515
+ *
54516
+ * @param error - The error causing the connection to fail
54517
+ * @param code - The HTTP status code, if available
54518
+ * @internal
54519
+ */
54520
+ failConnection_fn = function(message3, code) {
54521
+ var _a3;
54522
+ __privateGet(this, _readyState) !== this.CLOSED && __privateSet(this, _readyState, this.CLOSED);
54523
+ const errorEvent = new ErrorEvent("error", { code, message: message3 });
54524
+ (_a3 = __privateGet(this, _onError)) == null || _a3.call(this, errorEvent), this.dispatchEvent(errorEvent);
54525
+ }, /**
54526
+ * Schedules a reconnection attempt against the EventSource endpoint.
54527
+ *
54528
+ * @param message - The error causing the connection to fail
54529
+ * @param code - The HTTP status code, if available
54530
+ * @internal
54531
+ */
54532
+ scheduleReconnect_fn = function(message3, code) {
54533
+ var _a3;
54534
+ if (__privateGet(this, _readyState) === this.CLOSED)
54535
+ return;
54536
+ __privateSet(this, _readyState, this.CONNECTING);
54537
+ const errorEvent = new ErrorEvent("error", { code, message: message3 });
54538
+ (_a3 = __privateGet(this, _onError)) == null || _a3.call(this, errorEvent), this.dispatchEvent(errorEvent), __privateSet(this, _reconnectTimer, setTimeout(__privateGet(this, _reconnect), __privateGet(this, _reconnectInterval)));
54539
+ }, _reconnect = /* @__PURE__ */ new WeakMap(), /**
54540
+ * ReadyState representing an EventSource currently trying to connect
54541
+ *
54542
+ * @public
54543
+ */
54544
+ EventSource.CONNECTING = 0, /**
54545
+ * ReadyState representing an EventSource connection that is open (eg connected)
54546
+ *
54547
+ * @public
54548
+ */
54549
+ EventSource.OPEN = 1, /**
54550
+ * ReadyState representing an EventSource connection that is closed (eg disconnected)
54551
+ *
54552
+ * @public
54553
+ */
54554
+ EventSource.CLOSED = 2;
54555
+ function getBaseURL() {
54556
+ const doc = "document" in globalThis ? globalThis.document : void 0;
54557
+ return doc && typeof doc == "object" && "baseURI" in doc && typeof doc.baseURI == "string" ? doc.baseURI : void 0;
54089
54558
  }
54090
54559
 
54091
54560
  // ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1_ed45788dfbfe808cc09dd7daea6bd385/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/transport.js
@@ -54958,180 +55427,212 @@ async function registerClient(authorizationServerUrl, { metadata, clientMetadata
54958
55427
  return OAuthClientInformationFullSchema.parse(await response.json());
54959
55428
  }
54960
55429
 
54961
- // ../../node_modules/.pnpm/eventsource-parser@3.1.0/node_modules/eventsource-parser/dist/index.js
54962
- var ParseError = class extends Error {
54963
- constructor(message3, options) {
54964
- super(message3), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
55430
+ // ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1_ed45788dfbfe808cc09dd7daea6bd385/node_modules/@modelcontextprotocol/sdk/dist/esm/client/sse.js
55431
+ var SseError = class extends Error {
55432
+ constructor(code, message3, event) {
55433
+ super(`SSE error: ${message3}`);
55434
+ this.code = code;
55435
+ this.event = event;
54965
55436
  }
54966
55437
  };
54967
- var LF = 10;
54968
- var CR = 13;
54969
- var SPACE = 32;
54970
- function noop(_arg) {
54971
- }
54972
- function createParser(config2) {
54973
- if (typeof config2 == "function")
54974
- throw new TypeError(
54975
- "`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
54976
- );
54977
- const { onEvent = noop, onError = noop, onRetry = noop, onComment, maxBufferSize } = config2, pendingFragments = [];
54978
- let pendingFragmentsLength = 0, isFirstChunk = true, id, data = "", dataLines = 0, eventType, terminated = false;
54979
- function feed(chunk) {
54980
- if (terminated)
54981
- throw new Error(
54982
- "Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
54983
- );
54984
- if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
54985
- const trailing2 = processLines(chunk);
54986
- trailing2 !== "" && (pendingFragments.push(trailing2), pendingFragmentsLength = trailing2.length), checkBufferSize();
54987
- return;
55438
+ var SSEClientTransport = class {
55439
+ constructor(url2, opts) {
55440
+ this._url = url2;
55441
+ this._resourceMetadataUrl = void 0;
55442
+ this._scope = void 0;
55443
+ this._eventSourceInit = opts?.eventSourceInit;
55444
+ this._requestInit = opts?.requestInit;
55445
+ this._authProvider = opts?.authProvider;
55446
+ this._fetch = opts?.fetch;
55447
+ this._fetchWithInit = createFetchWithInit(opts?.fetch, opts?.requestInit);
55448
+ }
55449
+ async _authThenStart() {
55450
+ if (!this._authProvider) {
55451
+ throw new UnauthorizedError("No auth provider");
54988
55452
  }
54989
- if (chunk.indexOf(`
54990
- `) === -1 && chunk.indexOf("\r") === -1) {
54991
- pendingFragments.push(chunk), pendingFragmentsLength += chunk.length, checkBufferSize();
54992
- return;
55453
+ let result;
55454
+ try {
55455
+ result = await auth(this._authProvider, {
55456
+ serverUrl: this._url,
55457
+ resourceMetadataUrl: this._resourceMetadataUrl,
55458
+ scope: this._scope,
55459
+ fetchFn: this._fetchWithInit
55460
+ });
55461
+ } catch (error51) {
55462
+ this.onerror?.(error51);
55463
+ throw error51;
54993
55464
  }
54994
- pendingFragments.push(chunk);
54995
- const input = pendingFragments.join("");
54996
- pendingFragments.length = 0, pendingFragmentsLength = 0;
54997
- const trailing = processLines(input);
54998
- trailing !== "" && (pendingFragments.push(trailing), pendingFragmentsLength = trailing.length), checkBufferSize();
54999
- }
55000
- function checkBufferSize() {
55001
- maxBufferSize !== void 0 && (pendingFragmentsLength + data.length <= maxBufferSize || (terminated = true, pendingFragments.length = 0, pendingFragmentsLength = 0, id = void 0, data = "", dataLines = 0, eventType = void 0, onError(
55002
- new ParseError(`Buffered data exceeded max buffer size of ${maxBufferSize} characters`, {
55003
- type: "max-buffer-size-exceeded"
55004
- })
55005
- )));
55465
+ if (result !== "AUTHORIZED") {
55466
+ throw new UnauthorizedError();
55467
+ }
55468
+ return await this._startOrAuth();
55006
55469
  }
55007
- function processLines(chunk) {
55008
- let searchIndex = 0;
55009
- if (chunk.indexOf("\r") === -1) {
55010
- let lfIndex = chunk.indexOf(`
55011
- `, searchIndex);
55012
- for (; lfIndex !== -1; ) {
55013
- if (searchIndex === lfIndex) {
55014
- dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
55015
- `, searchIndex);
55016
- continue;
55017
- }
55018
- const firstCharCode = chunk.charCodeAt(searchIndex);
55019
- if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
55020
- const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
55021
- if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
55022
- onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
55023
- `, searchIndex);
55024
- continue;
55025
- }
55026
- data = dataLines === 0 ? value : `${data}
55027
- ${value}`, dataLines++;
55028
- } else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
55029
- chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
55030
- lfIndex
55031
- ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
55032
- searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
55033
- `, searchIndex);
55470
+ async _commonHeaders() {
55471
+ const headers = {};
55472
+ if (this._authProvider) {
55473
+ const tokens = await this._authProvider.tokens();
55474
+ if (tokens) {
55475
+ headers["Authorization"] = `Bearer ${tokens.access_token}`;
55034
55476
  }
55035
- return chunk.slice(searchIndex);
55036
55477
  }
55037
- for (; searchIndex < chunk.length; ) {
55038
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
55039
- `, searchIndex);
55040
- let lineEnd = -1;
55041
- if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
55042
- break;
55043
- parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
55478
+ if (this._protocolVersion) {
55479
+ headers["mcp-protocol-version"] = this._protocolVersion;
55044
55480
  }
55045
- return chunk.slice(searchIndex);
55481
+ const extraHeaders = normalizeHeaders(this._requestInit?.headers);
55482
+ return new Headers({
55483
+ ...headers,
55484
+ ...extraHeaders
55485
+ });
55046
55486
  }
55047
- function parseLine(chunk, start, end) {
55048
- if (start === end) {
55049
- dispatchEvent();
55050
- return;
55487
+ _startOrAuth() {
55488
+ const fetchImpl = this?._eventSourceInit?.fetch ?? this._fetch ?? fetch;
55489
+ return new Promise((resolve, reject2) => {
55490
+ this._eventSource = new EventSource(this._url.href, {
55491
+ ...this._eventSourceInit,
55492
+ fetch: async (url2, init) => {
55493
+ const headers = await this._commonHeaders();
55494
+ headers.set("Accept", "text/event-stream");
55495
+ const response = await fetchImpl(url2, {
55496
+ ...init,
55497
+ headers
55498
+ });
55499
+ if (response.status === 401 && response.headers.has("www-authenticate")) {
55500
+ const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
55501
+ this._resourceMetadataUrl = resourceMetadataUrl;
55502
+ this._scope = scope;
55503
+ }
55504
+ return response;
55505
+ }
55506
+ });
55507
+ this._abortController = new AbortController();
55508
+ this._eventSource.onerror = (event) => {
55509
+ if (event.code === 401 && this._authProvider) {
55510
+ this._authThenStart().then(resolve, reject2);
55511
+ return;
55512
+ }
55513
+ const error51 = new SseError(event.code, event.message, event);
55514
+ reject2(error51);
55515
+ this.onerror?.(error51);
55516
+ };
55517
+ this._eventSource.onopen = () => {
55518
+ };
55519
+ this._eventSource.addEventListener("endpoint", (event) => {
55520
+ const messageEvent = event;
55521
+ try {
55522
+ this._endpoint = new URL(messageEvent.data, this._url);
55523
+ if (this._endpoint.origin !== this._url.origin) {
55524
+ throw new Error(`Endpoint origin does not match connection origin: ${this._endpoint.origin}`);
55525
+ }
55526
+ } catch (error51) {
55527
+ reject2(error51);
55528
+ this.onerror?.(error51);
55529
+ void this.close();
55530
+ return;
55531
+ }
55532
+ resolve();
55533
+ });
55534
+ this._eventSource.onmessage = (event) => {
55535
+ const messageEvent = event;
55536
+ let message3;
55537
+ try {
55538
+ message3 = JSONRPCMessageSchema.parse(JSON.parse(messageEvent.data));
55539
+ } catch (error51) {
55540
+ this.onerror?.(error51);
55541
+ return;
55542
+ }
55543
+ this.onmessage?.(message3);
55544
+ };
55545
+ });
55546
+ }
55547
+ async start() {
55548
+ if (this._eventSource) {
55549
+ throw new Error("SSEClientTransport already started! If using Client class, note that connect() calls start() automatically.");
55051
55550
  }
55052
- const firstCharCode = chunk.charCodeAt(start);
55053
- if (isDataPrefix(chunk, start, firstCharCode)) {
55054
- const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
55055
- data = dataLines === 0 ? value2 : `${data}
55056
- ${value2}`, dataLines++;
55057
- return;
55551
+ return await this._startOrAuth();
55552
+ }
55553
+ /**
55554
+ * Call this method after the user has finished authorizing via their user agent and is redirected back to the MCP client application. This will exchange the authorization code for an access token, enabling the next connection attempt to successfully auth.
55555
+ */
55556
+ async finishAuth(authorizationCode) {
55557
+ if (!this._authProvider) {
55558
+ throw new UnauthorizedError("No auth provider");
55058
55559
  }
55059
- if (isEventPrefix(chunk, start, firstCharCode)) {
55060
- eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
55061
- return;
55560
+ const result = await auth(this._authProvider, {
55561
+ serverUrl: this._url,
55562
+ authorizationCode,
55563
+ resourceMetadataUrl: this._resourceMetadataUrl,
55564
+ scope: this._scope,
55565
+ fetchFn: this._fetchWithInit
55566
+ });
55567
+ if (result !== "AUTHORIZED") {
55568
+ throw new UnauthorizedError("Failed to authorize");
55062
55569
  }
55063
- if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
55064
- const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
55065
- id = value2.includes("\0") ? void 0 : value2;
55066
- return;
55570
+ }
55571
+ async close() {
55572
+ this._abortController?.abort();
55573
+ this._eventSource?.close();
55574
+ this.onclose?.();
55575
+ }
55576
+ async send(message3) {
55577
+ if (!this._endpoint) {
55578
+ throw new Error("Not connected");
55067
55579
  }
55068
- if (firstCharCode === 58) {
55069
- if (onComment) {
55070
- const line2 = chunk.slice(start, end);
55071
- onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
55580
+ try {
55581
+ const headers = await this._commonHeaders();
55582
+ headers.set("content-type", "application/json");
55583
+ const init = {
55584
+ ...this._requestInit,
55585
+ method: "POST",
55586
+ headers,
55587
+ body: JSON.stringify(message3),
55588
+ signal: this._abortController?.signal
55589
+ };
55590
+ const response = await (this._fetch ?? fetch)(this._endpoint, init);
55591
+ if (!response.ok) {
55592
+ const text = await response.text().catch(() => null);
55593
+ if (response.status === 401 && this._authProvider) {
55594
+ const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
55595
+ this._resourceMetadataUrl = resourceMetadataUrl;
55596
+ this._scope = scope;
55597
+ const result = await auth(this._authProvider, {
55598
+ serverUrl: this._url,
55599
+ resourceMetadataUrl: this._resourceMetadataUrl,
55600
+ scope: this._scope,
55601
+ fetchFn: this._fetchWithInit
55602
+ });
55603
+ if (result !== "AUTHORIZED") {
55604
+ throw new UnauthorizedError();
55605
+ }
55606
+ return this.send(message3);
55607
+ }
55608
+ throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`);
55072
55609
  }
55073
- return;
55074
- }
55075
- const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
55076
- if (fieldSeparatorIndex === -1) {
55077
- processField(line, "", line);
55078
- return;
55610
+ await response.body?.cancel();
55611
+ } catch (error51) {
55612
+ this.onerror?.(error51);
55613
+ throw error51;
55079
55614
  }
55080
- const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
55081
- processField(field, value, line);
55082
55615
  }
55083
- function processField(field, value, line) {
55084
- switch (field) {
55085
- case "event":
55086
- eventType = value || void 0;
55087
- break;
55088
- case "data":
55089
- data = dataLines === 0 ? value : `${data}
55090
- ${value}`, dataLines++;
55091
- break;
55092
- case "id":
55093
- id = value.includes("\0") ? void 0 : value;
55094
- break;
55095
- case "retry":
55096
- /^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(
55097
- new ParseError(`Invalid \`retry\` value: "${value}"`, {
55098
- type: "invalid-retry",
55099
- value,
55100
- line
55101
- })
55102
- );
55103
- break;
55104
- default:
55105
- onError(
55106
- new ParseError(
55107
- `Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`,
55108
- { type: "unknown-field", field, value, line }
55109
- )
55110
- );
55111
- break;
55112
- }
55616
+ setProtocolVersion(version2) {
55617
+ this._protocolVersion = version2;
55113
55618
  }
55114
- function dispatchEvent() {
55115
- dataLines > 0 && onEvent({
55116
- id,
55117
- event: eventType,
55118
- data
55119
- }), id = void 0, data = "", dataLines = 0, eventType = void 0;
55619
+ };
55620
+
55621
+ // ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1_ed45788dfbfe808cc09dd7daea6bd385/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/mediaType.js
55622
+ var import_content_type = __toESM(require_content_type(), 1);
55623
+ function mediaTypeEssence(header) {
55624
+ if (!header) {
55625
+ return void 0;
55120
55626
  }
55121
- function reset(options = {}) {
55122
- if (options.consume && pendingFragments.length > 0) {
55123
- const incompleteLine = pendingFragments.join("");
55124
- parseLine(incompleteLine, 0, incompleteLine.length);
55627
+ try {
55628
+ return import_content_type.default.parse(header).type;
55629
+ } catch {
55630
+ const essence = (header.split(";", 1)[0] ?? "").trim().toLowerCase();
55631
+ if (essence === "" || header.slice(essence.length).includes(",")) {
55632
+ return void 0;
55125
55633
  }
55126
- isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0, pendingFragmentsLength = 0, terminated = false;
55634
+ return essence;
55127
55635
  }
55128
- return { feed, reset };
55129
- }
55130
- function isDataPrefix(chunk, i, firstCharCode) {
55131
- return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
55132
- }
55133
- function isEventPrefix(chunk, i, firstCharCode) {
55134
- return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
55135
55636
  }
55136
55637
 
55137
55638
  // ../../node_modules/.pnpm/eventsource-parser@3.1.0/node_modules/eventsource-parser/dist/stream.js
@@ -55595,10 +56096,15 @@ async function buildTransport(config2, secrets) {
55595
56096
  });
55596
56097
  }
55597
56098
  const headers = await interpolateSecrets(config2.headers, secrets);
55598
- const httpTransport = new StreamableHTTPClientTransport(new URL(config2.url), {
55599
- ...Object.keys(headers).length > 0 ? { requestInit: { headers } } : {}
55600
- });
55601
- return httpTransport;
56099
+ return httpTransport(config2.url, headers, httpKindOf(config2));
56100
+ }
56101
+ function httpKindOf(config2) {
56102
+ return config2.type === "sse" ? "sse" : "streamable-http";
56103
+ }
56104
+ function httpTransport(url2, headers, kind) {
56105
+ const options = Object.keys(headers).length > 0 ? { requestInit: { headers } } : {};
56106
+ const transport = kind === "sse" ? new SSEClientTransport(new URL(url2), options) : new StreamableHTTPClientTransport(new URL(url2), options);
56107
+ return transport;
55602
56108
  }
55603
56109
  var McpConnection = class {
55604
56110
  serverName;
@@ -55627,10 +56133,30 @@ var McpConnection = class {
55627
56133
  if (transport instanceof StdioClientTransport) {
55628
56134
  this.attachStderr(transport);
55629
56135
  }
55630
- await client.connect(transport);
56136
+ try {
56137
+ await client.connect(transport);
56138
+ } catch (error51) {
56139
+ const fallback = await this.fallbackTransport(error51);
56140
+ if (fallback === void 0)
56141
+ throw error51;
56142
+ await client.connect(fallback);
56143
+ this.client = client;
56144
+ this.transport = fallback;
56145
+ this.onLog(`Connected over SSE; Streamable HTTP was refused (${describeError(error51)})`);
56146
+ return;
56147
+ }
55631
56148
  this.client = client;
55632
56149
  this.transport = transport;
55633
56150
  }
56151
+ /** The other HTTP protocol, when this server never said which it speaks. */
56152
+ async fallbackTransport(error51) {
56153
+ const config2 = this.config;
56154
+ if (isStdioServer(config2) || config2.type !== void 0)
56155
+ return void 0;
56156
+ this.onLog(`Streamable HTTP failed (${describeError(error51)}) \u2014 retrying as SSE`);
56157
+ const headers = await interpolateSecrets(config2.headers, this.secrets);
56158
+ return httpTransport(config2.url, headers, "sse");
56159
+ }
55634
56160
  attachStderr(transport) {
55635
56161
  const stream = transport.stderr;
55636
56162
  if (stream === null)
@@ -55687,6 +56213,9 @@ function renderToolResult(result) {
55687
56213
  });
55688
56214
  return parts.join("\n");
55689
56215
  }
56216
+ function describeError(error51) {
56217
+ return error51 instanceof Error ? error51.message : String(error51);
56218
+ }
55690
56219
 
55691
56220
  // ../../packages/core/dist/mcp/registry.js
55692
56221
  function adaptTool(serverName, toolName, description, inputSchema, call) {
@@ -61366,7 +61895,7 @@ function stripEmpty(source) {
61366
61895
  var SCHEDULE_TICK_MS = 15e3;
61367
61896
  var STUCK_RUN_MS = 30 * 6e4;
61368
61897
  function wireChatBridge(services) {
61369
- const { transport, secrets, ui, workspaceRoot, storageDir, ripgrepPath } = services;
61898
+ const { transport, secrets, ui, workspaceRoot, storageDir } = services;
61370
61899
  const logger = new Logger({ level: "debug", sink: services.logSink });
61371
61900
  const configManager = new ConfigManager(services.configStore, services.workspaceRoot);
61372
61901
  const httpClient = services.httpClient ?? new FetchHttpClient();
@@ -62697,9 +63226,17 @@ ${preview.text}` } : {}
62697
63226
  // that stops to wait for one would never finish.
62698
63227
  ...schedule === void 0 ? { requestForm } : {},
62699
63228
  signal: activeAbortController.signal,
62700
- // Supplied by the host, not imported by core: the binary is platform-specific and
62701
- // lives in the VSIX, so resolving it is a host concern (§4).
62702
- ...ripgrepPath !== void 0 ? { ripgrepPath } : {}
63229
+ /*
63230
+ * Supplied by the host, not imported by core: the binary is platform-specific and
63231
+ * lives in the VSIX, so resolving it is a host concern (§4).
63232
+ *
63233
+ * Asked per turn rather than captured once, because a VS Code extension update
63234
+ * deletes the folder the previous answer pointed into. See `HostServices`.
63235
+ */
63236
+ ...(() => {
63237
+ const resolved = services.ripgrepPath();
63238
+ return resolved !== void 0 ? { ripgrepPath: resolved } : {};
63239
+ })()
62703
63240
  };
62704
63241
  consultationContext = () => toolContext;
62705
63242
  pythonNestedContext = toolContext;
@@ -64562,6 +65099,7 @@ ${direction}` : attachMentions(text, mentions);
64562
65099
  });
64563
65100
  }
64564
65101
  async function ignoredFilesPredicate() {
65102
+ const ripgrepPath = services.ripgrepPath();
64565
65103
  if (workspaceRoot === void 0 || ripgrepPath === void 0)
64566
65104
  return void 0;
64567
65105
  try {
@@ -68100,6 +68638,17 @@ ${output}${note}`,
68100
68638
 
68101
68639
  // ../../packages/core/dist/tools/listFiles.js
68102
68640
  import { execFile as execFile7 } from "node:child_process";
68641
+
68642
+ // ../../packages/core/dist/tools/ripgrepError.js
68643
+ function describeRipgrepFailure(error51, what) {
68644
+ const code = error51?.code;
68645
+ if (code === "ENOENT") {
68646
+ return `${what} is unavailable: the ripgrep binary it runs could not be found. This usually means Light Code was updated while this window was open, which replaces the folder the binary was in. Reloading the window (Developer: Reload Window) restores it. If it persists, the binary may have been removed by antivirus software.`;
68647
+ }
68648
+ return `${what} failed: ${error51 instanceof Error ? error51.message : String(error51)}`;
68649
+ }
68650
+
68651
+ // ../../packages/core/dist/tools/listFiles.js
68103
68652
  var paramsSchema16 = external_exports.object({
68104
68653
  path: external_exports.string().min(1).default(".").describe("Directory to list, relative to the workspace root."),
68105
68654
  recursive: external_exports.boolean().optional().describe("List the full subtree instead of just this directory."),
@@ -68161,7 +68710,7 @@ var listFilesTool = {
68161
68710
  content: params.includeIgnored === true ? "(no files found)" : "(no files found \u2014 .gitignore-excluded files are skipped; retry with includeIgnored: true)"
68162
68711
  };
68163
68712
  } catch (error51) {
68164
- return { content: `Could not list files: ${error51 instanceof Error ? error51.message : String(error51)}`, isError: true };
68713
+ return { content: describeRipgrepFailure(error51, "Listing files recursively"), isError: true };
68165
68714
  }
68166
68715
  }
68167
68716
  const entries = await context.fs.readdir(resolved.realPath);
@@ -68369,7 +68918,7 @@ var searchFilesTool = {
68369
68918
  content: params.includeIgnored === true ? "(no matches)" : "(no matches \u2014 .gitignore-excluded files were not searched; retry with includeIgnored: true)"
68370
68919
  };
68371
68920
  } catch (error51) {
68372
- return { content: `Search failed: ${error51 instanceof Error ? error51.message : String(error51)}`, isError: true };
68921
+ return { content: describeRipgrepFailure(error51, "Search"), isError: true };
68373
68922
  }
68374
68923
  }
68375
68924
  };
@@ -69188,7 +69737,11 @@ function securityHeaders() {
69188
69737
  * `'none'` unless somebody named an origin. A list here is a deliberate act by an operator
69189
69738
  * who wants this page inside another — a lab, a dashboard — and it names exactly which.
69190
69739
  */
69191
- frameAncestors.length === 0 ? "frame-ancestors 'none'" : `frame-ancestors ${frameAncestors.join(" ")}`,
69740
+ /*
69741
+ * `'self'` always, plus whatever was declared. Same-origin framing is what a proxy serving
69742
+ * this page under somebody's own host looks like, and refusing it protected nothing.
69743
+ */
69744
+ `frame-ancestors 'self'${frameAncestors.length === 0 ? "" : ` ${frameAncestors.join(" ")}`}`,
69192
69745
  "base-uri 'none'",
69193
69746
  "form-action 'none'"
69194
69747
  ].join("; "),