linkque-cli-v2 1.6.11-alpha.0 → 1.6.12

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.
Files changed (17) hide show
  1. package/linkquejs.js +145 -118
  2. package/package.json +1 -1
  3. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-NE7CUP5E.js → chunk-3J4AB676.js} +1 -1
  4. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-H7TMASQH.js → chunk-DPHKD4SK.js} +633 -558
  5. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-FA5CNADA.js → chunk-EHNI5TX3.js} +25 -1
  6. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-DNTEEBEH.js → chunk-SICWMO5Y.js} +1 -0
  7. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-bsd-JGCLGHFY.js → getMachineId-bsd-NYGVHXGN.js} +1 -1
  8. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-darwin-COHLFNXH.js → getMachineId-darwin-OPTJOAYC.js} +1 -1
  9. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-linux-XV3Z5FQG.js → getMachineId-linux-5SQRYTUJ.js} +1 -1
  10. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-unsupported-FCRKLIZL.js → getMachineId-unsupported-OJE7WPEH.js} +1 -1
  11. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-win-A4WRNVV6.js → getMachineId-win-SLTTCNXU.js} +1 -1
  12. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{mistral-conversations-ZYAKAOUL.js → mistral-conversations-XUDTCRDY.js} +1 -1
  13. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{otel-BHGIWGIT.js → otel-3OUODIOB.js} +1 -1
  14. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +25 -18
  15. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +3 -3
  16. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +3 -3
  17. package/worker.js +740 -666
@@ -283,8 +283,9 @@ import {
283
283
  esm_exports,
284
284
  init_esm,
285
285
  isSpanContextValid,
286
+ isValidTraceId,
286
287
  trace
287
- } from "./chunk-DNTEEBEH.js";
288
+ } from "./chunk-SICWMO5Y.js";
288
289
  import {
289
290
  __commonJS,
290
291
  __esm,
@@ -8665,6 +8666,110 @@ var require_dist = __commonJS({
8665
8666
  }
8666
8667
  });
8667
8668
 
8669
+ // ../../node_modules/content-type/index.js
8670
+ var require_content_type = __commonJS({
8671
+ "../../node_modules/content-type/index.js"(exports) {
8672
+ "use strict";
8673
+ var PARAM_REGEXP = /; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g;
8674
+ var TEXT_REGEXP = /^[\u000b\u0020-\u007e\u0080-\u00ff]+$/;
8675
+ var TOKEN_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
8676
+ var QESC_REGEXP = /\\([\u000b\u0020-\u00ff])/g;
8677
+ var QUOTE_REGEXP = /([\\"])/g;
8678
+ var TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
8679
+ exports.format = format;
8680
+ exports.parse = parse2;
8681
+ function format(obj) {
8682
+ if (!obj || typeof obj !== "object") {
8683
+ throw new TypeError("argument obj is required");
8684
+ }
8685
+ var parameters = obj.parameters;
8686
+ var type = obj.type;
8687
+ if (!type || !TYPE_REGEXP.test(type)) {
8688
+ throw new TypeError("invalid type");
8689
+ }
8690
+ var string2 = type;
8691
+ if (parameters && typeof parameters === "object") {
8692
+ var param;
8693
+ var params = Object.keys(parameters).sort();
8694
+ for (var i = 0; i < params.length; i++) {
8695
+ param = params[i];
8696
+ if (!TOKEN_REGEXP.test(param)) {
8697
+ throw new TypeError("invalid parameter name");
8698
+ }
8699
+ string2 += "; " + param + "=" + qstring(parameters[param]);
8700
+ }
8701
+ }
8702
+ return string2;
8703
+ }
8704
+ function parse2(string2) {
8705
+ if (!string2) {
8706
+ throw new TypeError("argument string is required");
8707
+ }
8708
+ var header = typeof string2 === "object" ? getcontenttype(string2) : string2;
8709
+ if (typeof header !== "string") {
8710
+ throw new TypeError("argument string is required to be a string");
8711
+ }
8712
+ var index = header.indexOf(";");
8713
+ var type = index !== -1 ? header.slice(0, index).trim() : header.trim();
8714
+ if (!TYPE_REGEXP.test(type)) {
8715
+ throw new TypeError("invalid media type");
8716
+ }
8717
+ var obj = new ContentType(type.toLowerCase());
8718
+ if (index !== -1) {
8719
+ var key;
8720
+ var match;
8721
+ var value;
8722
+ PARAM_REGEXP.lastIndex = index;
8723
+ while (match = PARAM_REGEXP.exec(header)) {
8724
+ if (match.index !== index) {
8725
+ throw new TypeError("invalid parameter format");
8726
+ }
8727
+ index += match[0].length;
8728
+ key = match[1].toLowerCase();
8729
+ value = match[2];
8730
+ if (value.charCodeAt(0) === 34) {
8731
+ value = value.slice(1, -1);
8732
+ if (value.indexOf("\\") !== -1) {
8733
+ value = value.replace(QESC_REGEXP, "$1");
8734
+ }
8735
+ }
8736
+ obj.parameters[key] = value;
8737
+ }
8738
+ if (index !== header.length) {
8739
+ throw new TypeError("invalid parameter format");
8740
+ }
8741
+ }
8742
+ return obj;
8743
+ }
8744
+ function getcontenttype(obj) {
8745
+ var header;
8746
+ if (typeof obj.getHeader === "function") {
8747
+ header = obj.getHeader("content-type");
8748
+ } else if (typeof obj.headers === "object") {
8749
+ header = obj.headers && obj.headers["content-type"];
8750
+ }
8751
+ if (typeof header !== "string") {
8752
+ throw new TypeError("content-type header is missing from object");
8753
+ }
8754
+ return header;
8755
+ }
8756
+ function qstring(val) {
8757
+ var str = String(val);
8758
+ if (TOKEN_REGEXP.test(str)) {
8759
+ return str;
8760
+ }
8761
+ if (str.length > 0 && !TEXT_REGEXP.test(str)) {
8762
+ throw new TypeError("invalid parameter value");
8763
+ }
8764
+ return '"' + str.replace(QUOTE_REGEXP, "\\$1") + '"';
8765
+ }
8766
+ function ContentType(type) {
8767
+ this.parameters = /* @__PURE__ */ Object.create(null);
8768
+ this.type = type;
8769
+ }
8770
+ }
8771
+ });
8772
+
8668
8773
  // ../../node_modules/@opentelemetry/core/build/src/trace/suppress-tracing.js
8669
8774
  var require_suppress_tracing = __commonJS({
8670
8775
  "../../node_modules/@opentelemetry/core/build/src/trace/suppress-tracing.js"(exports) {
@@ -12449,19 +12554,19 @@ var require_getMachineId = __commonJS({
12449
12554
  if (!getMachineIdImpl) {
12450
12555
  switch (process2.platform) {
12451
12556
  case "darwin":
12452
- getMachineIdImpl = (await import("./getMachineId-darwin-COHLFNXH.js")).getMachineId;
12557
+ getMachineIdImpl = (await import("./getMachineId-darwin-OPTJOAYC.js")).getMachineId;
12453
12558
  break;
12454
12559
  case "linux":
12455
- getMachineIdImpl = (await import("./getMachineId-linux-XV3Z5FQG.js")).getMachineId;
12560
+ getMachineIdImpl = (await import("./getMachineId-linux-5SQRYTUJ.js")).getMachineId;
12456
12561
  break;
12457
12562
  case "freebsd":
12458
- getMachineIdImpl = (await import("./getMachineId-bsd-JGCLGHFY.js")).getMachineId;
12563
+ getMachineIdImpl = (await import("./getMachineId-bsd-NYGVHXGN.js")).getMachineId;
12459
12564
  break;
12460
12565
  case "win32":
12461
- getMachineIdImpl = (await import("./getMachineId-win-A4WRNVV6.js")).getMachineId;
12566
+ getMachineIdImpl = (await import("./getMachineId-win-SLTTCNXU.js")).getMachineId;
12462
12567
  break;
12463
12568
  default:
12464
- getMachineIdImpl = (await import("./getMachineId-unsupported-FCRKLIZL.js")).getMachineId;
12569
+ getMachineIdImpl = (await import("./getMachineId-unsupported-OJE7WPEH.js")).getMachineId;
12465
12570
  break;
12466
12571
  }
12467
12572
  }
@@ -13853,7 +13958,7 @@ var require_RandomIdGenerator = __commonJS({
13853
13958
  exports.RandomIdGenerator = void 0;
13854
13959
  var SPAN_ID_BYTES = 8;
13855
13960
  var TRACE_ID_BYTES = 16;
13856
- var RandomIdGenerator = class {
13961
+ var RandomIdGenerator2 = class {
13857
13962
  /**
13858
13963
  * Returns a random 16-byte trace ID formatted/encoded as a 32 lowercase hex
13859
13964
  * characters corresponding to 128 bits.
@@ -13865,7 +13970,7 @@ var require_RandomIdGenerator = __commonJS({
13865
13970
  */
13866
13971
  generateSpanId = getIdGenerator(SPAN_ID_BYTES);
13867
13972
  };
13868
- exports.RandomIdGenerator = RandomIdGenerator;
13973
+ exports.RandomIdGenerator = RandomIdGenerator2;
13869
13974
  var SHARED_BUFFER = Buffer.allocUnsafe(TRACE_ID_BYTES);
13870
13975
  function getIdGenerator(bytes2) {
13871
13976
  return function generateId() {
@@ -24167,11 +24272,11 @@ function validateClientAction(body, path2, issues) {
24167
24272
  issues.push(issue2(`${path2}.context`, "INVALID_CLIENT_ACTION_CONTEXT", "ui.surface.open requires context.surfaceId"));
24168
24273
  return;
24169
24274
  }
24170
- if (body.name === "ui.page.open") {
24275
+ if (body.name === "ui.page.open" || body.name === "ui.miniprogram.embed") {
24171
24276
  if (!isPlainRecord(body.context) || Object.keys(body.context).length !== 1 || typeof body.context.url !== "string" && !isStrictBinding(body.context.url))
24172
- issues.push(issue2(`${path2}.context`, "INVALID_CLIENT_ACTION_CONTEXT", "ui.page.open requires one literal or bound URL"));
24277
+ issues.push(issue2(`${path2}.context`, "INVALID_CLIENT_ACTION_CONTEXT", `${body.name} requires one literal or bound URL`));
24173
24278
  else if (typeof body.context.url === "string" && !isSafePageUrl(body.context.url))
24174
- issues.push(issue2(`${path2}.context.url`, "INVALID_PAGE_URL", "ui.page.open URL must use https or the approved Alipay scheme"));
24279
+ issues.push(issue2(`${path2}.context.url`, "INVALID_PAGE_URL", `${body.name} URL must use https or the approved Alipay scheme`));
24175
24280
  return;
24176
24281
  }
24177
24282
  issues.push(issue2(`${path2}.name`, "UNSUPPORTED_CLIENT_ACTION", `unsupported client action ${String(body.name)}`));
@@ -35460,6 +35565,7 @@ var InitializedNotificationSchema = NotificationSchema.extend({
35460
35565
  method: literal("notifications/initialized"),
35461
35566
  params: NotificationsParamsSchema.optional()
35462
35567
  });
35568
+ var isInitializedNotification = (value) => InitializedNotificationSchema.safeParse(value).success;
35463
35569
  var PingRequestSchema = RequestSchema.extend({
35464
35570
  method: literal("ping"),
35465
35571
  params: BaseRequestParamsSchema.optional()
@@ -38590,477 +38696,21 @@ async function safeText(resp) {
38590
38696
  }
38591
38697
  }
38592
38698
 
38593
- // ../../node_modules/eventsource-parser/dist/index.js
38594
- var ParseError = class extends Error {
38595
- constructor(message, options) {
38596
- super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
38597
- }
38598
- };
38599
- var LF = 10;
38600
- var CR = 13;
38601
- var SPACE = 32;
38602
- function noop(_arg) {
38603
- }
38604
- function createParser(config) {
38605
- if (typeof config == "function")
38606
- throw new TypeError(
38607
- "`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
38608
- );
38609
- const { onEvent = noop, onError = noop, onRetry = noop, onComment, maxBufferSize } = config, pendingFragments = [];
38610
- let pendingFragmentsLength = 0, isFirstChunk = true, id, data = "", dataLines = 0, eventType, terminated = false;
38611
- function feed(chunk) {
38612
- if (terminated)
38613
- throw new Error(
38614
- "Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
38615
- );
38616
- if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
38617
- const trailing2 = processLines(chunk);
38618
- trailing2 !== "" && (pendingFragments.push(trailing2), pendingFragmentsLength = trailing2.length), checkBufferSize();
38619
- return;
38620
- }
38621
- if (chunk.indexOf(`
38622
- `) === -1 && chunk.indexOf("\r") === -1) {
38623
- pendingFragments.push(chunk), pendingFragmentsLength += chunk.length, checkBufferSize();
38624
- return;
38625
- }
38626
- pendingFragments.push(chunk);
38627
- const input = pendingFragments.join("");
38628
- pendingFragments.length = 0, pendingFragmentsLength = 0;
38629
- const trailing = processLines(input);
38630
- trailing !== "" && (pendingFragments.push(trailing), pendingFragmentsLength = trailing.length), checkBufferSize();
38631
- }
38632
- function checkBufferSize() {
38633
- maxBufferSize !== void 0 && (pendingFragmentsLength + data.length <= maxBufferSize || (terminated = true, pendingFragments.length = 0, pendingFragmentsLength = 0, id = void 0, data = "", dataLines = 0, eventType = void 0, onError(
38634
- new ParseError(`Buffered data exceeded max buffer size of ${maxBufferSize} characters`, {
38635
- type: "max-buffer-size-exceeded"
38636
- })
38637
- )));
38638
- }
38639
- function processLines(chunk) {
38640
- let searchIndex = 0;
38641
- if (chunk.indexOf("\r") === -1) {
38642
- let lfIndex = chunk.indexOf(`
38643
- `, searchIndex);
38644
- for (; lfIndex !== -1; ) {
38645
- if (searchIndex === lfIndex) {
38646
- dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
38647
- `, searchIndex);
38648
- continue;
38649
- }
38650
- const firstCharCode = chunk.charCodeAt(searchIndex);
38651
- if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
38652
- const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
38653
- if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
38654
- onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
38655
- `, searchIndex);
38656
- continue;
38657
- }
38658
- data = dataLines === 0 ? value : `${data}
38659
- ${value}`, dataLines++;
38660
- } else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
38661
- chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
38662
- lfIndex
38663
- ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
38664
- searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
38665
- `, searchIndex);
38666
- }
38667
- return chunk.slice(searchIndex);
38668
- }
38669
- for (; searchIndex < chunk.length; ) {
38670
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
38671
- `, searchIndex);
38672
- let lineEnd = -1;
38673
- 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)
38674
- break;
38675
- parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
38676
- }
38677
- return chunk.slice(searchIndex);
38678
- }
38679
- function parseLine(chunk, start, end) {
38680
- if (start === end) {
38681
- dispatchEvent();
38682
- return;
38683
- }
38684
- const firstCharCode = chunk.charCodeAt(start);
38685
- if (isDataPrefix(chunk, start, firstCharCode)) {
38686
- const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
38687
- data = dataLines === 0 ? value2 : `${data}
38688
- ${value2}`, dataLines++;
38689
- return;
38690
- }
38691
- if (isEventPrefix(chunk, start, firstCharCode)) {
38692
- eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
38693
- return;
38694
- }
38695
- if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
38696
- const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
38697
- id = value2.includes("\0") ? void 0 : value2;
38698
- return;
38699
- }
38700
- if (firstCharCode === 58) {
38701
- if (onComment) {
38702
- const line2 = chunk.slice(start, end);
38703
- onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
38704
- }
38705
- return;
38706
- }
38707
- const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
38708
- if (fieldSeparatorIndex === -1) {
38709
- processField(line, "", line);
38710
- return;
38711
- }
38712
- const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
38713
- processField(field, value, line);
38714
- }
38715
- function processField(field, value, line) {
38716
- switch (field) {
38717
- case "event":
38718
- eventType = value || void 0;
38719
- break;
38720
- case "data":
38721
- data = dataLines === 0 ? value : `${data}
38722
- ${value}`, dataLines++;
38723
- break;
38724
- case "id":
38725
- id = value.includes("\0") ? void 0 : value;
38726
- break;
38727
- case "retry":
38728
- /^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(
38729
- new ParseError(`Invalid \`retry\` value: "${value}"`, {
38730
- type: "invalid-retry",
38731
- value,
38732
- line
38733
- })
38734
- );
38735
- break;
38736
- default:
38737
- onError(
38738
- new ParseError(
38739
- `Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`,
38740
- { type: "unknown-field", field, value, line }
38741
- )
38742
- );
38743
- break;
38744
- }
38745
- }
38746
- function dispatchEvent() {
38747
- dataLines > 0 && onEvent({
38748
- id,
38749
- event: eventType,
38750
- data
38751
- }), id = void 0, data = "", dataLines = 0, eventType = void 0;
38752
- }
38753
- function reset(options = {}) {
38754
- if (options.consume && pendingFragments.length > 0) {
38755
- const incompleteLine = pendingFragments.join("");
38756
- parseLine(incompleteLine, 0, incompleteLine.length);
38757
- }
38758
- isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0, pendingFragmentsLength = 0, terminated = false;
38759
- }
38760
- return { feed, reset };
38761
- }
38762
- function isDataPrefix(chunk, i, firstCharCode) {
38763
- return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
38764
- }
38765
- function isEventPrefix(chunk, i, firstCharCode) {
38766
- 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;
38767
- }
38768
-
38769
- // ../../node_modules/eventsource/dist/index.js
38770
- var ErrorEvent = class extends Event {
38771
- /**
38772
- * Constructs a new `ErrorEvent` instance. This is typically not called directly,
38773
- * but rather emitted by the `EventSource` object when an error occurs.
38774
- *
38775
- * @param type - The type of the event (should be "error")
38776
- * @param errorEventInitDict - Optional properties to include in the error event
38777
- */
38778
- constructor(type, errorEventInitDict) {
38779
- var _a2, _b2;
38780
- super(type), this.code = (_a2 = errorEventInitDict == null ? void 0 : errorEventInitDict.code) != null ? _a2 : void 0, this.message = (_b2 = errorEventInitDict == null ? void 0 : errorEventInitDict.message) != null ? _b2 : void 0;
38781
- }
38782
- /**
38783
- * Node.js "hides" the `message` and `code` properties of the `ErrorEvent` instance,
38784
- * when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging,
38785
- * we explicitly include the properties in the `inspect` method.
38786
- *
38787
- * This is automatically called by Node.js when you `console.log` an instance of this class.
38788
- *
38789
- * @param _depth - The current depth
38790
- * @param options - The options passed to `util.inspect`
38791
- * @param inspect - The inspect function to use (prevents having to import it from `util`)
38792
- * @returns A string representation of the error
38793
- */
38794
- [Symbol.for("nodejs.util.inspect.custom")](_depth, options, inspect) {
38795
- return inspect(inspectableError(this), options);
38796
- }
38797
- /**
38798
- * Deno "hides" the `message` and `code` properties of the `ErrorEvent` instance,
38799
- * when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging,
38800
- * we explicitly include the properties in the `inspect` method.
38801
- *
38802
- * This is automatically called by Deno when you `console.log` an instance of this class.
38803
- *
38804
- * @param inspect - The inspect function to use (prevents having to import it from `util`)
38805
- * @param options - The options passed to `Deno.inspect`
38806
- * @returns A string representation of the error
38807
- */
38808
- [Symbol.for("Deno.customInspect")](inspect, options) {
38809
- return inspect(inspectableError(this), options);
38699
+ // ../../node_modules/@modelcontextprotocol/sdk/dist/esm/shared/mediaType.js
38700
+ var import_content_type = __toESM(require_content_type(), 1);
38701
+ function mediaTypeEssence(header) {
38702
+ if (!header) {
38703
+ return void 0;
38810
38704
  }
38811
- };
38812
- function syntaxError(message) {
38813
- const DomException = globalThis.DOMException;
38814
- return typeof DomException == "function" ? new DomException(message, "SyntaxError") : new SyntaxError(message);
38815
- }
38816
- function flattenError(err2) {
38817
- return err2 instanceof Error ? "errors" in err2 && Array.isArray(err2.errors) ? err2.errors.map(flattenError).join(", ") : "cause" in err2 && err2.cause instanceof Error ? `${err2}: ${flattenError(err2.cause)}` : err2.message : `${err2}`;
38818
- }
38819
- function inspectableError(err2) {
38820
- return {
38821
- type: err2.type,
38822
- message: err2.message,
38823
- code: err2.code,
38824
- defaultPrevented: err2.defaultPrevented,
38825
- cancelable: err2.cancelable,
38826
- timeStamp: err2.timeStamp
38827
- };
38828
- }
38829
- var __typeError = (msg) => {
38830
- throw TypeError(msg);
38831
- };
38832
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
38833
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
38834
- 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);
38835
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
38836
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
38837
- var _readyState;
38838
- var _url;
38839
- var _redirectUrl;
38840
- var _withCredentials;
38841
- var _fetch;
38842
- var _reconnectInterval;
38843
- var _reconnectTimer;
38844
- var _lastEventId;
38845
- var _controller;
38846
- var _parser;
38847
- var _onError;
38848
- var _onMessage;
38849
- var _onOpen;
38850
- var _EventSource_instances;
38851
- var connect_fn;
38852
- var _onFetchResponse;
38853
- var _onFetchError;
38854
- var getRequestOptions_fn;
38855
- var _onEvent;
38856
- var _onRetryChange;
38857
- var failConnection_fn;
38858
- var scheduleReconnect_fn;
38859
- var _reconnect;
38860
- var EventSource = class extends EventTarget {
38861
- constructor(url2, eventSourceInitDict) {
38862
- var _a2, _b2;
38863
- super(), __privateAdd(this, _EventSource_instances), this.CONNECTING = 0, this.OPEN = 1, this.CLOSED = 2, __privateAdd(this, _readyState), __privateAdd(this, _url), __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) => {
38864
- var _a22;
38865
- __privateGet(this, _parser).reset();
38866
- const { body, redirected, status, headers } = response;
38867
- if (status === 204) {
38868
- __privateMethod(this, _EventSource_instances, failConnection_fn).call(this, "Server sent HTTP 204, not reconnecting", 204), this.close();
38869
- return;
38870
- }
38871
- if (redirected ? __privateSet(this, _redirectUrl, new URL(response.url)) : __privateSet(this, _redirectUrl, void 0), status !== 200) {
38872
- __privateMethod(this, _EventSource_instances, failConnection_fn).call(this, `Non-200 status code (${status})`, status);
38873
- return;
38874
- }
38875
- if (!(headers.get("content-type") || "").startsWith("text/event-stream")) {
38876
- __privateMethod(this, _EventSource_instances, failConnection_fn).call(this, 'Invalid content type, expected "text/event-stream"', status);
38877
- return;
38878
- }
38879
- if (__privateGet(this, _readyState) === this.CLOSED)
38880
- return;
38881
- __privateSet(this, _readyState, this.OPEN);
38882
- const openEvent = new Event("open");
38883
- if ((_a22 = __privateGet(this, _onOpen)) == null || _a22.call(this, openEvent), this.dispatchEvent(openEvent), typeof body != "object" || !body || !("getReader" in body)) {
38884
- __privateMethod(this, _EventSource_instances, failConnection_fn).call(this, "Invalid response body, expected a web ReadableStream", status), this.close();
38885
- return;
38886
- }
38887
- const decoder = new TextDecoder(), reader = body.getReader();
38888
- let open = true;
38889
- do {
38890
- const { done, value } = await reader.read();
38891
- 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));
38892
- } while (open);
38893
- }), __privateAdd(this, _onFetchError, (err2) => {
38894
- __privateSet(this, _controller, void 0), !(err2.name === "AbortError" || err2.type === "aborted") && __privateMethod(this, _EventSource_instances, scheduleReconnect_fn).call(this, flattenError(err2));
38895
- }), __privateAdd(this, _onEvent, (event) => {
38896
- typeof event.id == "string" && __privateSet(this, _lastEventId, event.id);
38897
- const messageEvent = new MessageEvent(event.event || "message", {
38898
- data: event.data,
38899
- origin: __privateGet(this, _redirectUrl) ? __privateGet(this, _redirectUrl).origin : __privateGet(this, _url).origin,
38900
- lastEventId: event.id || ""
38901
- });
38902
- __privateGet(this, _onMessage) && (!event.event || event.event === "message") && __privateGet(this, _onMessage).call(this, messageEvent), this.dispatchEvent(messageEvent);
38903
- }), __privateAdd(this, _onRetryChange, (value) => {
38904
- __privateSet(this, _reconnectInterval, value);
38905
- }), __privateAdd(this, _reconnect, () => {
38906
- __privateSet(this, _reconnectTimer, void 0), __privateGet(this, _readyState) === this.CONNECTING && __privateMethod(this, _EventSource_instances, connect_fn).call(this);
38907
- });
38908
- try {
38909
- if (url2 instanceof URL)
38910
- __privateSet(this, _url, url2);
38911
- else if (typeof url2 == "string")
38912
- __privateSet(this, _url, new URL(url2, getBaseURL()));
38913
- else
38914
- throw new Error("Invalid URL");
38915
- } catch {
38916
- throw syntaxError("An invalid or illegal string was specified");
38705
+ try {
38706
+ return import_content_type.default.parse(header).type;
38707
+ } catch {
38708
+ const essence = (header.split(";", 1)[0] ?? "").trim().toLowerCase();
38709
+ if (essence === "" || header.slice(essence.length).includes(",")) {
38710
+ return void 0;
38917
38711
  }
38918
- __privateSet(this, _parser, createParser({
38919
- onEvent: __privateGet(this, _onEvent),
38920
- onRetry: __privateGet(this, _onRetryChange)
38921
- })), __privateSet(this, _readyState, this.CONNECTING), __privateSet(this, _reconnectInterval, 3e3), __privateSet(this, _fetch, (_a2 = eventSourceInitDict == null ? void 0 : eventSourceInitDict.fetch) != null ? _a2 : globalThis.fetch), __privateSet(this, _withCredentials, (_b2 = eventSourceInitDict == null ? void 0 : eventSourceInitDict.withCredentials) != null ? _b2 : false), __privateMethod(this, _EventSource_instances, connect_fn).call(this);
38712
+ return essence;
38922
38713
  }
38923
- /**
38924
- * Returns the state of this EventSource object's connection. It can have the values described below.
38925
- *
38926
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/readyState)
38927
- *
38928
- * Note: typed as `number` instead of `0 | 1 | 2` for compatibility with the `EventSource` interface,
38929
- * defined in the TypeScript `dom` library.
38930
- *
38931
- * @public
38932
- */
38933
- get readyState() {
38934
- return __privateGet(this, _readyState);
38935
- }
38936
- /**
38937
- * Returns the URL providing the event stream.
38938
- *
38939
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/url)
38940
- *
38941
- * @public
38942
- */
38943
- get url() {
38944
- return __privateGet(this, _url).href;
38945
- }
38946
- /**
38947
- * Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise.
38948
- *
38949
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/withCredentials)
38950
- */
38951
- get withCredentials() {
38952
- return __privateGet(this, _withCredentials);
38953
- }
38954
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/error_event) */
38955
- get onerror() {
38956
- return __privateGet(this, _onError);
38957
- }
38958
- set onerror(value) {
38959
- __privateSet(this, _onError, value);
38960
- }
38961
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/message_event) */
38962
- get onmessage() {
38963
- return __privateGet(this, _onMessage);
38964
- }
38965
- set onmessage(value) {
38966
- __privateSet(this, _onMessage, value);
38967
- }
38968
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/open_event) */
38969
- get onopen() {
38970
- return __privateGet(this, _onOpen);
38971
- }
38972
- set onopen(value) {
38973
- __privateSet(this, _onOpen, value);
38974
- }
38975
- addEventListener(type, listener, options) {
38976
- const listen = listener;
38977
- super.addEventListener(type, listen, options);
38978
- }
38979
- removeEventListener(type, listener, options) {
38980
- const listen = listener;
38981
- super.removeEventListener(type, listen, options);
38982
- }
38983
- /**
38984
- * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
38985
- *
38986
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/close)
38987
- *
38988
- * @public
38989
- */
38990
- close() {
38991
- __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));
38992
- }
38993
- };
38994
- _readyState = /* @__PURE__ */ new WeakMap(), _url = /* @__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(), /**
38995
- * Connect to the given URL and start receiving events
38996
- *
38997
- * @internal
38998
- */
38999
- connect_fn = function() {
39000
- __privateSet(this, _readyState, this.CONNECTING), __privateSet(this, _controller, new AbortController()), __privateGet(this, _fetch)(__privateGet(this, _url), __privateMethod(this, _EventSource_instances, getRequestOptions_fn).call(this)).then(__privateGet(this, _onFetchResponse)).catch(__privateGet(this, _onFetchError));
39001
- }, _onFetchResponse = /* @__PURE__ */ new WeakMap(), _onFetchError = /* @__PURE__ */ new WeakMap(), /**
39002
- * Get request options for the `fetch()` request
39003
- *
39004
- * @returns The request options
39005
- * @internal
39006
- */
39007
- getRequestOptions_fn = function() {
39008
- var _a2;
39009
- const init = {
39010
- // [spec] Let `corsAttributeState` be `Anonymous`…
39011
- // [spec] …will have their mode set to "cors"…
39012
- mode: "cors",
39013
- redirect: "follow",
39014
- headers: { Accept: "text/event-stream", ...__privateGet(this, _lastEventId) ? { "Last-Event-ID": __privateGet(this, _lastEventId) } : void 0 },
39015
- cache: "no-store",
39016
- signal: (_a2 = __privateGet(this, _controller)) == null ? void 0 : _a2.signal
39017
- };
39018
- return "window" in globalThis && (init.credentials = this.withCredentials ? "include" : "same-origin"), init;
39019
- }, _onEvent = /* @__PURE__ */ new WeakMap(), _onRetryChange = /* @__PURE__ */ new WeakMap(), /**
39020
- * Handles the process referred to in the EventSource specification as "failing a connection".
39021
- *
39022
- * @param error - The error causing the connection to fail
39023
- * @param code - The HTTP status code, if available
39024
- * @internal
39025
- */
39026
- failConnection_fn = function(message, code) {
39027
- var _a2;
39028
- __privateGet(this, _readyState) !== this.CLOSED && __privateSet(this, _readyState, this.CLOSED);
39029
- const errorEvent = new ErrorEvent("error", { code, message });
39030
- (_a2 = __privateGet(this, _onError)) == null || _a2.call(this, errorEvent), this.dispatchEvent(errorEvent);
39031
- }, /**
39032
- * Schedules a reconnection attempt against the EventSource endpoint.
39033
- *
39034
- * @param message - The error causing the connection to fail
39035
- * @param code - The HTTP status code, if available
39036
- * @internal
39037
- */
39038
- scheduleReconnect_fn = function(message, code) {
39039
- var _a2;
39040
- if (__privateGet(this, _readyState) === this.CLOSED)
39041
- return;
39042
- __privateSet(this, _readyState, this.CONNECTING);
39043
- const errorEvent = new ErrorEvent("error", { code, message });
39044
- (_a2 = __privateGet(this, _onError)) == null || _a2.call(this, errorEvent), this.dispatchEvent(errorEvent), __privateSet(this, _reconnectTimer, setTimeout(__privateGet(this, _reconnect), __privateGet(this, _reconnectInterval)));
39045
- }, _reconnect = /* @__PURE__ */ new WeakMap(), /**
39046
- * ReadyState representing an EventSource currently trying to connect
39047
- *
39048
- * @public
39049
- */
39050
- EventSource.CONNECTING = 0, /**
39051
- * ReadyState representing an EventSource connection that is open (eg connected)
39052
- *
39053
- * @public
39054
- */
39055
- EventSource.OPEN = 1, /**
39056
- * ReadyState representing an EventSource connection that is closed (eg disconnected)
39057
- *
39058
- * @public
39059
- */
39060
- EventSource.CLOSED = 2;
39061
- function getBaseURL() {
39062
- const doc = "document" in globalThis ? globalThis.document : void 0;
39063
- return doc && typeof doc == "object" && "baseURI" in doc && typeof doc.baseURI == "string" ? doc.baseURI : void 0;
39064
38714
  }
39065
38715
 
39066
38716
  // ../../node_modules/@modelcontextprotocol/sdk/dist/esm/shared/transport.js
@@ -39933,24 +39583,232 @@ async function registerClient(authorizationServerUrl, { metadata, clientMetadata
39933
39583
  return OAuthClientInformationFullSchema.parse(await response.json());
39934
39584
  }
39935
39585
 
39936
- // ../../node_modules/@modelcontextprotocol/sdk/dist/esm/client/sse.js
39937
- var SseError = class extends Error {
39938
- constructor(code, message, event) {
39939
- super(`SSE error: ${message}`);
39586
+ // ../../node_modules/eventsource-parser/dist/index.js
39587
+ var ParseError = class extends Error {
39588
+ constructor(message, options) {
39589
+ super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
39590
+ }
39591
+ };
39592
+ var LF = 10;
39593
+ var CR = 13;
39594
+ var SPACE = 32;
39595
+ function noop(_arg) {
39596
+ }
39597
+ function createParser(config) {
39598
+ if (typeof config == "function")
39599
+ throw new TypeError(
39600
+ "`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
39601
+ );
39602
+ const { onEvent = noop, onError = noop, onRetry = noop, onComment, maxBufferSize } = config, pendingFragments = [];
39603
+ let pendingFragmentsLength = 0, isFirstChunk = true, id, data = "", dataLines = 0, eventType, terminated = false;
39604
+ function feed(chunk) {
39605
+ if (terminated)
39606
+ throw new Error(
39607
+ "Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
39608
+ );
39609
+ if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
39610
+ const trailing2 = processLines(chunk);
39611
+ trailing2 !== "" && (pendingFragments.push(trailing2), pendingFragmentsLength = trailing2.length), checkBufferSize();
39612
+ return;
39613
+ }
39614
+ if (chunk.indexOf(`
39615
+ `) === -1 && chunk.indexOf("\r") === -1) {
39616
+ pendingFragments.push(chunk), pendingFragmentsLength += chunk.length, checkBufferSize();
39617
+ return;
39618
+ }
39619
+ pendingFragments.push(chunk);
39620
+ const input = pendingFragments.join("");
39621
+ pendingFragments.length = 0, pendingFragmentsLength = 0;
39622
+ const trailing = processLines(input);
39623
+ trailing !== "" && (pendingFragments.push(trailing), pendingFragmentsLength = trailing.length), checkBufferSize();
39624
+ }
39625
+ function checkBufferSize() {
39626
+ maxBufferSize !== void 0 && (pendingFragmentsLength + data.length <= maxBufferSize || (terminated = true, pendingFragments.length = 0, pendingFragmentsLength = 0, id = void 0, data = "", dataLines = 0, eventType = void 0, onError(
39627
+ new ParseError(`Buffered data exceeded max buffer size of ${maxBufferSize} characters`, {
39628
+ type: "max-buffer-size-exceeded"
39629
+ })
39630
+ )));
39631
+ }
39632
+ function processLines(chunk) {
39633
+ let searchIndex = 0;
39634
+ if (chunk.indexOf("\r") === -1) {
39635
+ let lfIndex = chunk.indexOf(`
39636
+ `, searchIndex);
39637
+ for (; lfIndex !== -1; ) {
39638
+ if (searchIndex === lfIndex) {
39639
+ dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
39640
+ `, searchIndex);
39641
+ continue;
39642
+ }
39643
+ const firstCharCode = chunk.charCodeAt(searchIndex);
39644
+ if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
39645
+ const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
39646
+ if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
39647
+ onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
39648
+ `, searchIndex);
39649
+ continue;
39650
+ }
39651
+ data = dataLines === 0 ? value : `${data}
39652
+ ${value}`, dataLines++;
39653
+ } else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
39654
+ chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
39655
+ lfIndex
39656
+ ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
39657
+ searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
39658
+ `, searchIndex);
39659
+ }
39660
+ return chunk.slice(searchIndex);
39661
+ }
39662
+ for (; searchIndex < chunk.length; ) {
39663
+ const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
39664
+ `, searchIndex);
39665
+ let lineEnd = -1;
39666
+ 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)
39667
+ break;
39668
+ parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
39669
+ }
39670
+ return chunk.slice(searchIndex);
39671
+ }
39672
+ function parseLine(chunk, start, end) {
39673
+ if (start === end) {
39674
+ dispatchEvent();
39675
+ return;
39676
+ }
39677
+ const firstCharCode = chunk.charCodeAt(start);
39678
+ if (isDataPrefix(chunk, start, firstCharCode)) {
39679
+ const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
39680
+ data = dataLines === 0 ? value2 : `${data}
39681
+ ${value2}`, dataLines++;
39682
+ return;
39683
+ }
39684
+ if (isEventPrefix(chunk, start, firstCharCode)) {
39685
+ eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
39686
+ return;
39687
+ }
39688
+ if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
39689
+ const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
39690
+ id = value2.includes("\0") ? void 0 : value2;
39691
+ return;
39692
+ }
39693
+ if (firstCharCode === 58) {
39694
+ if (onComment) {
39695
+ const line2 = chunk.slice(start, end);
39696
+ onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
39697
+ }
39698
+ return;
39699
+ }
39700
+ const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
39701
+ if (fieldSeparatorIndex === -1) {
39702
+ processField(line, "", line);
39703
+ return;
39704
+ }
39705
+ const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
39706
+ processField(field, value, line);
39707
+ }
39708
+ function processField(field, value, line) {
39709
+ switch (field) {
39710
+ case "event":
39711
+ eventType = value || void 0;
39712
+ break;
39713
+ case "data":
39714
+ data = dataLines === 0 ? value : `${data}
39715
+ ${value}`, dataLines++;
39716
+ break;
39717
+ case "id":
39718
+ id = value.includes("\0") ? void 0 : value;
39719
+ break;
39720
+ case "retry":
39721
+ /^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(
39722
+ new ParseError(`Invalid \`retry\` value: "${value}"`, {
39723
+ type: "invalid-retry",
39724
+ value,
39725
+ line
39726
+ })
39727
+ );
39728
+ break;
39729
+ default:
39730
+ onError(
39731
+ new ParseError(
39732
+ `Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`,
39733
+ { type: "unknown-field", field, value, line }
39734
+ )
39735
+ );
39736
+ break;
39737
+ }
39738
+ }
39739
+ function dispatchEvent() {
39740
+ dataLines > 0 && onEvent({
39741
+ id,
39742
+ event: eventType,
39743
+ data
39744
+ }), id = void 0, data = "", dataLines = 0, eventType = void 0;
39745
+ }
39746
+ function reset(options = {}) {
39747
+ if (options.consume && pendingFragments.length > 0) {
39748
+ const incompleteLine = pendingFragments.join("");
39749
+ parseLine(incompleteLine, 0, incompleteLine.length);
39750
+ }
39751
+ isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0, pendingFragmentsLength = 0, terminated = false;
39752
+ }
39753
+ return { feed, reset };
39754
+ }
39755
+ function isDataPrefix(chunk, i, firstCharCode) {
39756
+ return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
39757
+ }
39758
+ function isEventPrefix(chunk, i, firstCharCode) {
39759
+ 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;
39760
+ }
39761
+
39762
+ // ../../node_modules/eventsource-parser/dist/stream.js
39763
+ var EventSourceParserStream = class extends TransformStream {
39764
+ constructor({ onError, onRetry, onComment, maxBufferSize } = {}) {
39765
+ let parser;
39766
+ super({
39767
+ start(controller) {
39768
+ parser = createParser({
39769
+ onEvent: (event) => {
39770
+ controller.enqueue(event);
39771
+ },
39772
+ onError(error) {
39773
+ typeof onError == "function" && onError(error), (onError === "terminate" || error.type === "max-buffer-size-exceeded") && controller.error(error);
39774
+ },
39775
+ onRetry,
39776
+ onComment,
39777
+ maxBufferSize
39778
+ });
39779
+ },
39780
+ transform(chunk) {
39781
+ parser.feed(chunk);
39782
+ }
39783
+ });
39784
+ }
39785
+ };
39786
+
39787
+ // ../../node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js
39788
+ var DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS = {
39789
+ initialReconnectionDelay: 1e3,
39790
+ maxReconnectionDelay: 3e4,
39791
+ reconnectionDelayGrowFactor: 1.5,
39792
+ maxRetries: 2
39793
+ };
39794
+ var StreamableHTTPError = class extends Error {
39795
+ constructor(code, message) {
39796
+ super(`Streamable HTTP error: ${message}`);
39940
39797
  this.code = code;
39941
- this.event = event;
39942
39798
  }
39943
39799
  };
39944
- var SSEClientTransport = class {
39800
+ var StreamableHTTPClientTransport = class {
39945
39801
  constructor(url2, opts) {
39802
+ this._hasCompletedAuthFlow = false;
39946
39803
  this._url = url2;
39947
39804
  this._resourceMetadataUrl = void 0;
39948
39805
  this._scope = void 0;
39949
- this._eventSourceInit = opts?.eventSourceInit;
39950
39806
  this._requestInit = opts?.requestInit;
39951
39807
  this._authProvider = opts?.authProvider;
39952
39808
  this._fetch = opts?.fetch;
39953
39809
  this._fetchWithInit = createFetchWithInit(opts?.fetch, opts?.requestInit);
39810
+ this._sessionId = opts?.sessionId;
39811
+ this._reconnectionOptions = opts?.reconnectionOptions ?? DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS;
39954
39812
  }
39955
39813
  async _authThenStart() {
39956
39814
  if (!this._authProvider) {
@@ -39971,7 +39829,7 @@ var SSEClientTransport = class {
39971
39829
  if (result !== "AUTHORIZED") {
39972
39830
  throw new UnauthorizedError();
39973
39831
  }
39974
- return await this._startOrAuth();
39832
+ return await this._startOrAuthSse({ resumptionToken: void 0 });
39975
39833
  }
39976
39834
  async _commonHeaders() {
39977
39835
  const headers = {};
@@ -39981,6 +39839,9 @@ var SSEClientTransport = class {
39981
39839
  headers["Authorization"] = `Bearer ${tokens.access_token}`;
39982
39840
  }
39983
39841
  }
39842
+ if (this._sessionId) {
39843
+ headers["mcp-session-id"] = this._sessionId;
39844
+ }
39984
39845
  if (this._protocolVersion) {
39985
39846
  headers["mcp-protocol-version"] = this._protocolVersion;
39986
39847
  }
@@ -39990,71 +39851,146 @@ var SSEClientTransport = class {
39990
39851
  ...extraHeaders
39991
39852
  });
39992
39853
  }
39993
- _startOrAuth() {
39994
- const fetchImpl = this?._eventSourceInit?.fetch ?? this._fetch ?? fetch;
39995
- return new Promise((resolve, reject) => {
39996
- this._eventSource = new EventSource(this._url.href, {
39997
- ...this._eventSourceInit,
39998
- fetch: async (url2, init) => {
39999
- const headers = await this._commonHeaders();
40000
- headers.set("Accept", "text/event-stream");
40001
- const response = await fetchImpl(url2, {
40002
- ...init,
40003
- headers
40004
- });
40005
- if (response.status === 401 && response.headers.has("www-authenticate")) {
40006
- const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
40007
- this._resourceMetadataUrl = resourceMetadataUrl;
40008
- this._scope = scope;
40009
- }
40010
- return response;
40011
- }
39854
+ async _startOrAuthSse(options) {
39855
+ const { resumptionToken } = options;
39856
+ try {
39857
+ const headers = await this._commonHeaders();
39858
+ headers.set("Accept", "text/event-stream");
39859
+ if (resumptionToken) {
39860
+ headers.set("last-event-id", resumptionToken);
39861
+ }
39862
+ const response = await (this._fetch ?? fetch)(this._url, {
39863
+ method: "GET",
39864
+ headers,
39865
+ signal: this._abortController?.signal
40012
39866
  });
40013
- this._abortController = new AbortController();
40014
- this._eventSource.onerror = (event) => {
40015
- if (event.code === 401 && this._authProvider) {
40016
- this._authThenStart().then(resolve, reject);
40017
- return;
39867
+ if (!response.ok) {
39868
+ await response.body?.cancel();
39869
+ if (response.status === 401 && this._authProvider) {
39870
+ return await this._authThenStart();
40018
39871
  }
40019
- const error = new SseError(event.code, event.message, event);
40020
- reject(error);
40021
- this.onerror?.(error);
40022
- };
40023
- this._eventSource.onopen = () => {
40024
- };
40025
- this._eventSource.addEventListener("endpoint", (event) => {
40026
- const messageEvent = event;
40027
- try {
40028
- this._endpoint = new URL(messageEvent.data, this._url);
40029
- if (this._endpoint.origin !== this._url.origin) {
40030
- throw new Error(`Endpoint origin does not match connection origin: ${this._endpoint.origin}`);
40031
- }
40032
- } catch (error) {
40033
- reject(error);
40034
- this.onerror?.(error);
40035
- void this.close();
39872
+ if (response.status === 405) {
40036
39873
  return;
40037
39874
  }
40038
- resolve();
39875
+ throw new StreamableHTTPError(response.status, `Failed to open SSE stream: ${response.statusText}`);
39876
+ }
39877
+ this._handleSseStream(response.body, options, true);
39878
+ } catch (error) {
39879
+ this.onerror?.(error);
39880
+ throw error;
39881
+ }
39882
+ }
39883
+ /**
39884
+ * Calculates the next reconnection delay using backoff algorithm
39885
+ *
39886
+ * @param attempt Current reconnection attempt count for the specific stream
39887
+ * @returns Time to wait in milliseconds before next reconnection attempt
39888
+ */
39889
+ _getNextReconnectionDelay(attempt) {
39890
+ if (this._serverRetryMs !== void 0) {
39891
+ return this._serverRetryMs;
39892
+ }
39893
+ const initialDelay = this._reconnectionOptions.initialReconnectionDelay;
39894
+ const growFactor = this._reconnectionOptions.reconnectionDelayGrowFactor;
39895
+ const maxDelay = this._reconnectionOptions.maxReconnectionDelay;
39896
+ return Math.min(initialDelay * Math.pow(growFactor, attempt), maxDelay);
39897
+ }
39898
+ /**
39899
+ * Schedule a reconnection attempt using server-provided retry interval or backoff
39900
+ *
39901
+ * @param lastEventId The ID of the last received event for resumability
39902
+ * @param attemptCount Current reconnection attempt count for this specific stream
39903
+ */
39904
+ _scheduleReconnection(options, attemptCount = 0) {
39905
+ const maxRetries = this._reconnectionOptions.maxRetries;
39906
+ if (attemptCount >= maxRetries) {
39907
+ this.onerror?.(new Error(`Maximum reconnection attempts (${maxRetries}) exceeded.`));
39908
+ return;
39909
+ }
39910
+ const delay2 = this._getNextReconnectionDelay(attemptCount);
39911
+ this._reconnectionTimeout = setTimeout(() => {
39912
+ this._startOrAuthSse(options).catch((error) => {
39913
+ this.onerror?.(new Error(`Failed to reconnect SSE stream: ${error instanceof Error ? error.message : String(error)}`));
39914
+ this._scheduleReconnection(options, attemptCount + 1);
40039
39915
  });
40040
- this._eventSource.onmessage = (event) => {
40041
- const messageEvent = event;
40042
- let message;
40043
- try {
40044
- message = JSONRPCMessageSchema.parse(JSON.parse(messageEvent.data));
40045
- } catch (error) {
40046
- this.onerror?.(error);
40047
- return;
39916
+ }, delay2);
39917
+ }
39918
+ _handleSseStream(stream, options, isReconnectable) {
39919
+ if (!stream) {
39920
+ return;
39921
+ }
39922
+ const { onresumptiontoken, replayMessageId } = options;
39923
+ let lastEventId;
39924
+ let hasPrimingEvent = false;
39925
+ let receivedResponse = false;
39926
+ const processStream = async () => {
39927
+ try {
39928
+ const reader = stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream({
39929
+ onRetry: (retryMs) => {
39930
+ this._serverRetryMs = retryMs;
39931
+ }
39932
+ })).getReader();
39933
+ while (true) {
39934
+ const { value: event, done } = await reader.read();
39935
+ if (done) {
39936
+ break;
39937
+ }
39938
+ if (event.id) {
39939
+ lastEventId = event.id;
39940
+ hasPrimingEvent = true;
39941
+ onresumptiontoken?.(event.id);
39942
+ }
39943
+ if (!event.data) {
39944
+ continue;
39945
+ }
39946
+ if (!event.event || event.event === "message") {
39947
+ try {
39948
+ const message = JSONRPCMessageSchema.parse(JSON.parse(event.data));
39949
+ if (isJSONRPCResultResponse(message)) {
39950
+ receivedResponse = true;
39951
+ if (replayMessageId !== void 0) {
39952
+ message.id = replayMessageId;
39953
+ }
39954
+ }
39955
+ this.onmessage?.(message);
39956
+ } catch (error) {
39957
+ this.onerror?.(error);
39958
+ }
39959
+ }
40048
39960
  }
40049
- this.onmessage?.(message);
40050
- };
40051
- });
39961
+ const canResume = isReconnectable || hasPrimingEvent;
39962
+ const needsReconnect = canResume && !receivedResponse;
39963
+ if (needsReconnect && this._abortController && !this._abortController.signal.aborted) {
39964
+ this._scheduleReconnection({
39965
+ resumptionToken: lastEventId,
39966
+ onresumptiontoken,
39967
+ replayMessageId
39968
+ }, 0);
39969
+ }
39970
+ } catch (error) {
39971
+ this.onerror?.(new Error(`SSE stream disconnected: ${error}`));
39972
+ const canResume = isReconnectable || hasPrimingEvent;
39973
+ const needsReconnect = canResume && !receivedResponse;
39974
+ if (needsReconnect && this._abortController && !this._abortController.signal.aborted) {
39975
+ try {
39976
+ this._scheduleReconnection({
39977
+ resumptionToken: lastEventId,
39978
+ onresumptiontoken,
39979
+ replayMessageId
39980
+ }, 0);
39981
+ } catch (error2) {
39982
+ this.onerror?.(new Error(`Failed to reconnect: ${error2 instanceof Error ? error2.message : String(error2)}`));
39983
+ }
39984
+ }
39985
+ }
39986
+ };
39987
+ processStream();
40052
39988
  }
40053
39989
  async start() {
40054
- if (this._eventSource) {
40055
- throw new Error("SSEClientTransport already started! If using Client class, note that connect() calls start() automatically.");
39990
+ if (this._abortController) {
39991
+ throw new Error("StreamableHTTPClientTransport already started! If using Client class, note that connect() calls start() automatically.");
40056
39992
  }
40057
- return await this._startOrAuth();
39993
+ this._abortController = new AbortController();
40058
39994
  }
40059
39995
  /**
40060
39996
  * 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.
@@ -40075,17 +40011,23 @@ var SSEClientTransport = class {
40075
40011
  }
40076
40012
  }
40077
40013
  async close() {
40014
+ if (this._reconnectionTimeout) {
40015
+ clearTimeout(this._reconnectionTimeout);
40016
+ this._reconnectionTimeout = void 0;
40017
+ }
40078
40018
  this._abortController?.abort();
40079
- this._eventSource?.close();
40080
40019
  this.onclose?.();
40081
40020
  }
40082
- async send(message) {
40083
- if (!this._endpoint) {
40084
- throw new Error("Not connected");
40085
- }
40021
+ async send(message, options) {
40086
40022
  try {
40023
+ const { resumptionToken, onresumptiontoken } = options || {};
40024
+ if (resumptionToken) {
40025
+ this._startOrAuthSse({ resumptionToken, replayMessageId: isJSONRPCRequest(message) ? message.id : void 0 }).catch((err2) => this.onerror?.(err2));
40026
+ return;
40027
+ }
40087
40028
  const headers = await this._commonHeaders();
40088
40029
  headers.set("content-type", "application/json");
40030
+ headers.set("accept", "application/json, text/event-stream");
40089
40031
  const init = {
40090
40032
  ...this._requestInit,
40091
40033
  method: "POST",
@@ -40093,10 +40035,17 @@ var SSEClientTransport = class {
40093
40035
  body: JSON.stringify(message),
40094
40036
  signal: this._abortController?.signal
40095
40037
  };
40096
- const response = await (this._fetch ?? fetch)(this._endpoint, init);
40038
+ const response = await (this._fetch ?? fetch)(this._url, init);
40039
+ const sessionId = response.headers.get("mcp-session-id");
40040
+ if (sessionId) {
40041
+ this._sessionId = sessionId;
40042
+ }
40097
40043
  if (!response.ok) {
40098
40044
  const text = await response.text().catch(() => null);
40099
40045
  if (response.status === 401 && this._authProvider) {
40046
+ if (this._hasCompletedAuthFlow) {
40047
+ throw new StreamableHTTPError(401, "Server returned 401 after successful authentication");
40048
+ }
40100
40049
  const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
40101
40050
  this._resourceMetadataUrl = resourceMetadataUrl;
40102
40051
  this._scope = scope;
@@ -40109,11 +40058,103 @@ var SSEClientTransport = class {
40109
40058
  if (result !== "AUTHORIZED") {
40110
40059
  throw new UnauthorizedError();
40111
40060
  }
40061
+ this._hasCompletedAuthFlow = true;
40112
40062
  return this.send(message);
40113
40063
  }
40114
- throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`);
40064
+ if (response.status === 403 && this._authProvider) {
40065
+ const { resourceMetadataUrl, scope, error } = extractWWWAuthenticateParams(response);
40066
+ if (error === "insufficient_scope") {
40067
+ const wwwAuthHeader = response.headers.get("WWW-Authenticate");
40068
+ if (this._lastUpscopingHeader === wwwAuthHeader) {
40069
+ throw new StreamableHTTPError(403, "Server returned 403 after trying upscoping");
40070
+ }
40071
+ if (scope) {
40072
+ this._scope = scope;
40073
+ }
40074
+ if (resourceMetadataUrl) {
40075
+ this._resourceMetadataUrl = resourceMetadataUrl;
40076
+ }
40077
+ this._lastUpscopingHeader = wwwAuthHeader ?? void 0;
40078
+ const result = await auth(this._authProvider, {
40079
+ serverUrl: this._url,
40080
+ resourceMetadataUrl: this._resourceMetadataUrl,
40081
+ scope: this._scope,
40082
+ fetchFn: this._fetch
40083
+ });
40084
+ if (result !== "AUTHORIZED") {
40085
+ throw new UnauthorizedError();
40086
+ }
40087
+ return this.send(message);
40088
+ }
40089
+ }
40090
+ throw new StreamableHTTPError(response.status, `Error POSTing to endpoint: ${text}`);
40115
40091
  }
40092
+ this._hasCompletedAuthFlow = false;
40093
+ this._lastUpscopingHeader = void 0;
40094
+ if (response.status === 202) {
40095
+ await response.body?.cancel();
40096
+ if (isInitializedNotification(message)) {
40097
+ this._startOrAuthSse({ resumptionToken: void 0 }).catch((err2) => this.onerror?.(err2));
40098
+ }
40099
+ return;
40100
+ }
40101
+ const messages = Array.isArray(message) ? message : [message];
40102
+ const hasRequests = messages.filter((msg) => "method" in msg && "id" in msg && msg.id !== void 0).length > 0;
40103
+ const contentType2 = response.headers.get("content-type");
40104
+ const responseMediaType = mediaTypeEssence(contentType2);
40105
+ if (hasRequests) {
40106
+ if (responseMediaType === "text/event-stream") {
40107
+ this._handleSseStream(response.body, { onresumptiontoken }, false);
40108
+ } else if (responseMediaType === "application/json") {
40109
+ const data = await response.json();
40110
+ const responseMessages = Array.isArray(data) ? data.map((msg) => JSONRPCMessageSchema.parse(msg)) : [JSONRPCMessageSchema.parse(data)];
40111
+ for (const msg of responseMessages) {
40112
+ this.onmessage?.(msg);
40113
+ }
40114
+ } else {
40115
+ await response.body?.cancel();
40116
+ throw new StreamableHTTPError(-1, `Unexpected content type: ${contentType2}`);
40117
+ }
40118
+ } else {
40119
+ await response.body?.cancel();
40120
+ }
40121
+ } catch (error) {
40122
+ this.onerror?.(error);
40123
+ throw error;
40124
+ }
40125
+ }
40126
+ get sessionId() {
40127
+ return this._sessionId;
40128
+ }
40129
+ /**
40130
+ * Terminates the current session by sending a DELETE request to the server.
40131
+ *
40132
+ * Clients that no longer need a particular session
40133
+ * (e.g., because the user is leaving the client application) SHOULD send an
40134
+ * HTTP DELETE to the MCP endpoint with the Mcp-Session-Id header to explicitly
40135
+ * terminate the session.
40136
+ *
40137
+ * The server MAY respond with HTTP 405 Method Not Allowed, indicating that
40138
+ * the server does not allow clients to terminate sessions.
40139
+ */
40140
+ async terminateSession() {
40141
+ if (!this._sessionId) {
40142
+ return;
40143
+ }
40144
+ try {
40145
+ const headers = await this._commonHeaders();
40146
+ const init = {
40147
+ ...this._requestInit,
40148
+ method: "DELETE",
40149
+ headers,
40150
+ signal: this._abortController?.signal
40151
+ };
40152
+ const response = await (this._fetch ?? fetch)(this._url, init);
40116
40153
  await response.body?.cancel();
40154
+ if (!response.ok && response.status !== 405) {
40155
+ throw new StreamableHTTPError(response.status, `Failed to terminate session: ${response.statusText}`);
40156
+ }
40157
+ this._sessionId = void 0;
40117
40158
  } catch (error) {
40118
40159
  this.onerror?.(error);
40119
40160
  throw error;
@@ -40122,6 +40163,22 @@ var SSEClientTransport = class {
40122
40163
  setProtocolVersion(version) {
40123
40164
  this._protocolVersion = version;
40124
40165
  }
40166
+ get protocolVersion() {
40167
+ return this._protocolVersion;
40168
+ }
40169
+ /**
40170
+ * Resume an SSE stream from a previous event ID.
40171
+ * Opens a GET SSE connection with Last-Event-ID header to replay missed events.
40172
+ *
40173
+ * @param lastEventId The event ID to resume from
40174
+ * @param options Optional callback to receive new resumption tokens
40175
+ */
40176
+ async resumeStream(lastEventId, options) {
40177
+ await this._startOrAuthSse({
40178
+ resumptionToken: lastEventId,
40179
+ onresumptiontoken: options?.onresumptiontoken
40180
+ });
40181
+ }
40125
40182
  };
40126
40183
 
40127
40184
  // ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/mcpInvocationError.js
@@ -40240,7 +40297,7 @@ function createSigningFetch(signer, baseFetch = globalThis.fetch, onTraceId, deb
40240
40297
  };
40241
40298
  }
40242
40299
 
40243
- // ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/sseTransportFactory.js
40300
+ // ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/streamableHttpTransportFactory.js
40244
40301
  function withTimeout(fetch2, timeoutMs) {
40245
40302
  return async (url2, init) => {
40246
40303
  if (init?.signal) {
@@ -40254,14 +40311,12 @@ function withTimeout(fetch2, timeoutMs) {
40254
40311
  }
40255
40312
  };
40256
40313
  }
40257
- function createSseTransport(config, signer, onTraceId, debugLog, getCallHeaders, invocationContext) {
40314
+ function createStreamableHttpTransport(config, signer, onTraceId, debugLog, getCallHeaders, invocationContext) {
40258
40315
  const url2 = new URL(config.sseEndpoint, config.remoteBaseUrl);
40259
40316
  const timeoutMs = config.requestTimeoutMs ?? 18e4;
40260
40317
  const signingFetch = withTimeout(createSigningFetch(signer, void 0, onTraceId, debugLog, getCallHeaders, invocationContext), timeoutMs);
40261
- return new SSEClientTransport(url2, {
40262
- // SSE 建连(EventSource)的 GET fetch:SDK 先包默认头再调这里。
40263
- eventSourceInit: { fetch: signingFetch },
40264
- // MCP 发消息用的 POST fetch。
40318
+ return new StreamableHTTPClientTransport(url2, {
40319
+ // SDK 的所有 HTTP 请求统一经签名器,保留会话与协议协商请求头。
40265
40320
  fetch: signingFetch
40266
40321
  });
40267
40322
  }
@@ -40515,7 +40570,7 @@ var RemoteGatewayMcpServerProvider = class {
40515
40570
  const verifier = this.doCreateTokenVerifier(config);
40516
40571
  const callHeaders = new AsyncLocalStorage2();
40517
40572
  const { client } = await connectMcpClientWithRetry(config, {
40518
- createTransport: () => createSseTransport(config, this.doCreateSigner(config, this.getAuthorizationHeader), this.onTraceId, this.debugLog, () => callHeaders.getStore(), this.invocationContext),
40573
+ createTransport: () => createStreamableHttpTransport(config, this.doCreateSigner(config, this.getAuthorizationHeader), this.onTraceId, this.debugLog, () => callHeaders.getStore(), this.invocationContext),
40519
40574
  createClient: () => this.doCrateClient(),
40520
40575
  runConnect: (operation, attempt) => this.invocationContext.run(timeoutMs, connectSignal, operation, {
40521
40576
  observation,
@@ -42609,6 +42664,24 @@ function sanitizeAttributeValue(value) {
42609
42664
  }
42610
42665
 
42611
42666
  // ../linkque-agent-runtime/dist/esm/impl/telemetry/otelRuntimeTelemetry.js
42667
+ var InitialRootTraceIdGenerator = class {
42668
+ initialRootTraceId;
42669
+ fallback = new import_sdk_trace_base.RandomIdGenerator();
42670
+ constructor(initialRootTraceId) {
42671
+ this.initialRootTraceId = initialRootTraceId;
42672
+ }
42673
+ generateTraceId() {
42674
+ if (this.initialRootTraceId) {
42675
+ const traceId = this.initialRootTraceId;
42676
+ this.initialRootTraceId = void 0;
42677
+ return traceId;
42678
+ }
42679
+ return this.fallback.generateTraceId();
42680
+ }
42681
+ generateSpanId() {
42682
+ return this.fallback.generateSpanId();
42683
+ }
42684
+ };
42612
42685
  var OtelRuntimeTelemetry = class {
42613
42686
  options;
42614
42687
  queue;
@@ -42628,9 +42701,10 @@ var OtelRuntimeTelemetry = class {
42628
42701
  this.options = options;
42629
42702
  this.queue = new IdentityQueue(options);
42630
42703
  const ratio = options.sampleRatio ?? 1;
42704
+ const initialRootTraceId = options.initialRootTraceId?.toLowerCase();
42631
42705
  this.maxActive = options.maxActiveOperations ?? 4096;
42632
42706
  this.maxAge = options.operationMaxAgeMs ?? 24 * 60 * 60 * 1e3;
42633
- if (!options.serviceName || !options.serviceVersion || !options.environment || !Number.isFinite(ratio) || ratio < 0 || ratio > 1 || !Number.isSafeInteger(this.maxActive) || this.maxActive < 1 || !Number.isSafeInteger(this.maxAge) || this.maxAge < 1)
42707
+ if (!options.serviceName || !options.serviceVersion || !options.environment || !Number.isFinite(ratio) || ratio < 0 || ratio > 1 || !Number.isSafeInteger(this.maxActive) || this.maxActive < 1 || !Number.isSafeInteger(this.maxAge) || this.maxAge < 1 || initialRootTraceId !== void 0 && !isValidTraceId(initialRootTraceId))
42634
42708
  throw new Error("\u975E\u6CD5\u9065\u6D4B\u5B9E\u4F8B\u914D\u7F6E");
42635
42709
  const resource = (0, import_resources.resourceFromAttributes)({
42636
42710
  [ETelemetryAttribute.SERVICE_NAME]: options.serviceName,
@@ -42641,6 +42715,7 @@ var OtelRuntimeTelemetry = class {
42641
42715
  });
42642
42716
  this.tracerProvider = new import_sdk_trace_base.BasicTracerProvider({
42643
42717
  resource,
42718
+ idGenerator: new InitialRootTraceIdGenerator(initialRootTraceId),
42644
42719
  sampler: new import_sdk_trace_base.ParentBasedSampler({
42645
42720
  root: new import_sdk_trace_base.TraceIdRatioBasedSampler(ratio)
42646
42721
  }),