@opentiny/next-sdk 0.3.1 → 0.3.3-alpha.1

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 (54) hide show
  1. package/WebMcp.ts +6 -0
  2. package/WebMcpClient.ts +16 -21
  3. package/agent/type.ts +93 -69
  4. package/core.ts +1 -0
  5. package/dist/SimulatorMask-BHVXyogh-BFEGpD5S.js +1048 -0
  6. package/dist/SimulatorMask-BHVXyogh-CCYbrb84.js +801 -0
  7. package/dist/WebMcp.d.ts +3 -0
  8. package/dist/WebMcpClient.d.ts +7 -13
  9. package/dist/agent/type.d.ts +10 -0
  10. package/dist/core.d.ts +1 -0
  11. package/dist/core.js +16 -15
  12. package/dist/index.d.ts +3 -2
  13. package/dist/index.es.dev.js +8384 -2700
  14. package/dist/index.es.js +21608 -16893
  15. package/dist/index.js +4033 -1850
  16. package/dist/index.umd.dev.js +9739 -3110
  17. package/dist/index.umd.js +500 -66
  18. package/dist/initialize-builtin-WebMCP-HgObT902.js +6279 -0
  19. package/dist/mcpsdk@1.25.3.dev.js +253 -94
  20. package/dist/mcpsdk@1.25.3.es.dev.js +253 -94
  21. package/dist/mcpsdk@1.25.3.es.js +5689 -5531
  22. package/dist/mcpsdk@1.25.3.js +32 -27
  23. package/dist/page-tools/a11y-tree.d.ts +103 -0
  24. package/dist/page-tools/bridge.d.ts +0 -6
  25. package/dist/page-tools/initialize-builtin-WebMCP.d.ts +1 -0
  26. package/dist/page-tools/page-agent-tool.d.ts +9 -0
  27. package/dist/page-tools/page-state-cache.d.ts +36 -0
  28. package/dist/skills/index.d.ts +7 -12
  29. package/dist/webagent.dev.js +3772 -1919
  30. package/dist/webagent.es.dev.js +3528 -1571
  31. package/dist/webagent.es.js +16380 -14585
  32. package/dist/webagent.js +74 -66
  33. package/dist/webmcp-full.dev.js +7670 -747
  34. package/dist/webmcp-full.es.dev.js +6482 -608
  35. package/dist/webmcp-full.es.js +12180 -7618
  36. package/dist/webmcp-full.js +631 -29
  37. package/dist/webmcp.dev.js +8047 -53
  38. package/dist/webmcp.es.dev.js +6977 -31
  39. package/dist/webmcp.es.js +6187 -860
  40. package/dist/webmcp.js +602 -1
  41. package/index.ts +2 -15
  42. package/package.json +11 -4
  43. package/page-tools/a11y-tree.ts +532 -0
  44. package/page-tools/bridge.ts +48 -14
  45. package/page-tools/initialize-builtin-WebMCP.ts +20 -0
  46. package/page-tools/page-agent-prompt.md +123 -0
  47. package/page-tools/page-agent-tool.ts +223 -0
  48. package/page-tools/page-state-cache.ts +78 -0
  49. package/remoter/createRemoter.ts +2 -1
  50. package/remoter/svgs/logo.svg +45 -0
  51. package/skills/index.ts +50 -31
  52. package/utils/builtinProxy.ts +42 -20
  53. package/vite-env.d.ts +5 -0
  54. package/dist/AgentModelProvider-BnMj6YSC.js +0 -4182
@@ -3084,6 +3084,9 @@ function requireUtils() {
3084
3084
  hasRequiredUtils = 1;
3085
3085
  const isUUID = RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu);
3086
3086
  const isIPv4 = RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u);
3087
+ const isHexPair = RegExp.prototype.test.bind(/^[\da-f]{2}$/iu);
3088
+ const isUnreserved = RegExp.prototype.test.bind(/^[\da-z\-._~]$/iu);
3089
+ const isPathCharacter = RegExp.prototype.test.bind(/^[\da-z\-._~!$&'()*+,;=:@/]$/iu);
3087
3090
  function stringArrayToHexStripped(input) {
3088
3091
  let acc = "";
3089
3092
  let code2 = 0;
@@ -3276,27 +3279,77 @@ function requireUtils() {
3276
3279
  }
3277
3280
  return output.join("");
3278
3281
  }
3279
- function normalizeComponentEncoding(component, esc2) {
3280
- const func = esc2 !== true ? escape : unescape;
3281
- if (component.scheme !== void 0) {
3282
- component.scheme = func(component.scheme);
3283
- }
3284
- if (component.userinfo !== void 0) {
3285
- component.userinfo = func(component.userinfo);
3286
- }
3287
- if (component.host !== void 0) {
3288
- component.host = func(component.host);
3282
+ const HOST_DELIMS = { "@": "%40", "/": "%2F", "?": "%3F", "#": "%23", ":": "%3A" };
3283
+ const HOST_DELIM_RE = /[@/?#:]/g;
3284
+ const HOST_DELIM_NO_COLON_RE = /[@/?#]/g;
3285
+ function reescapeHostDelimiters(host, isIP) {
3286
+ const re = isIP ? HOST_DELIM_NO_COLON_RE : HOST_DELIM_RE;
3287
+ re.lastIndex = 0;
3288
+ return host.replace(re, (ch) => HOST_DELIMS[ch]);
3289
+ }
3290
+ function normalizePercentEncoding(input, decodeUnreserved = false) {
3291
+ if (input.indexOf("%") === -1) {
3292
+ return input;
3289
3293
  }
3290
- if (component.path !== void 0) {
3291
- component.path = func(component.path);
3294
+ let output = "";
3295
+ for (let i = 0; i < input.length; i++) {
3296
+ if (input[i] === "%" && i + 2 < input.length) {
3297
+ const hex = input.slice(i + 1, i + 3);
3298
+ if (isHexPair(hex)) {
3299
+ const normalizedHex = hex.toUpperCase();
3300
+ const decoded = String.fromCharCode(parseInt(normalizedHex, 16));
3301
+ if (decodeUnreserved && isUnreserved(decoded)) {
3302
+ output += decoded;
3303
+ } else {
3304
+ output += "%" + normalizedHex;
3305
+ }
3306
+ i += 2;
3307
+ continue;
3308
+ }
3309
+ }
3310
+ output += input[i];
3292
3311
  }
3293
- if (component.query !== void 0) {
3294
- component.query = func(component.query);
3312
+ return output;
3313
+ }
3314
+ function normalizePathEncoding(input) {
3315
+ let output = "";
3316
+ for (let i = 0; i < input.length; i++) {
3317
+ if (input[i] === "%" && i + 2 < input.length) {
3318
+ const hex = input.slice(i + 1, i + 3);
3319
+ if (isHexPair(hex)) {
3320
+ const normalizedHex = hex.toUpperCase();
3321
+ const decoded = String.fromCharCode(parseInt(normalizedHex, 16));
3322
+ if (decoded !== "." && isUnreserved(decoded)) {
3323
+ output += decoded;
3324
+ } else {
3325
+ output += "%" + normalizedHex;
3326
+ }
3327
+ i += 2;
3328
+ continue;
3329
+ }
3330
+ }
3331
+ if (isPathCharacter(input[i])) {
3332
+ output += input[i];
3333
+ } else {
3334
+ output += escape(input[i]);
3335
+ }
3295
3336
  }
3296
- if (component.fragment !== void 0) {
3297
- component.fragment = func(component.fragment);
3337
+ return output;
3338
+ }
3339
+ function escapePreservingEscapes(input) {
3340
+ let output = "";
3341
+ for (let i = 0; i < input.length; i++) {
3342
+ if (input[i] === "%" && i + 2 < input.length) {
3343
+ const hex = input.slice(i + 1, i + 3);
3344
+ if (isHexPair(hex)) {
3345
+ output += "%" + hex.toUpperCase();
3346
+ i += 2;
3347
+ continue;
3348
+ }
3349
+ }
3350
+ output += escape(input[i]);
3298
3351
  }
3299
- return component;
3352
+ return output;
3300
3353
  }
3301
3354
  function recomposeAuthority(component) {
3302
3355
  const uriTokens = [];
@@ -3311,7 +3364,7 @@ function requireUtils() {
3311
3364
  if (ipV6res.isIPV6 === true) {
3312
3365
  host = `[${ipV6res.escapedHost}]`;
3313
3366
  } else {
3314
- host = component.host;
3367
+ host = reescapeHostDelimiters(host, false);
3315
3368
  }
3316
3369
  }
3317
3370
  uriTokens.push(host);
@@ -3325,7 +3378,10 @@ function requireUtils() {
3325
3378
  utils = {
3326
3379
  nonSimpleDomain,
3327
3380
  recomposeAuthority,
3328
- normalizeComponentEncoding,
3381
+ reescapeHostDelimiters,
3382
+ normalizePercentEncoding,
3383
+ normalizePathEncoding,
3384
+ escapePreservingEscapes,
3329
3385
  removeDotSegments,
3330
3386
  isIPv4,
3331
3387
  isUUID,
@@ -3548,12 +3604,12 @@ var hasRequiredFastUri;
3548
3604
  function requireFastUri() {
3549
3605
  if (hasRequiredFastUri) return fastUri.exports;
3550
3606
  hasRequiredFastUri = 1;
3551
- const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4, nonSimpleDomain } = requireUtils();
3607
+ const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding, escapePreservingEscapes, reescapeHostDelimiters, isIPv4, nonSimpleDomain } = requireUtils();
3552
3608
  const { SCHEMES, getSchemeHandler } = requireSchemes();
3553
3609
  function normalize(uri2, options) {
3554
3610
  if (typeof uri2 === "string") {
3555
3611
  uri2 = /** @type {T} */
3556
- serialize(parse2(uri2, options), options);
3612
+ normalizeString(uri2, options);
3557
3613
  } else if (typeof uri2 === "object") {
3558
3614
  uri2 = /** @type {T} */
3559
3615
  parse2(serialize(uri2, options), options);
@@ -3620,19 +3676,9 @@ function requireFastUri() {
3620
3676
  return target;
3621
3677
  }
3622
3678
  function equal2(uriA, uriB, options) {
3623
- if (typeof uriA === "string") {
3624
- uriA = unescape(uriA);
3625
- uriA = serialize(normalizeComponentEncoding(parse2(uriA, options), true), { ...options, skipEscape: true });
3626
- } else if (typeof uriA === "object") {
3627
- uriA = serialize(normalizeComponentEncoding(uriA, true), { ...options, skipEscape: true });
3628
- }
3629
- if (typeof uriB === "string") {
3630
- uriB = unescape(uriB);
3631
- uriB = serialize(normalizeComponentEncoding(parse2(uriB, options), true), { ...options, skipEscape: true });
3632
- } else if (typeof uriB === "object") {
3633
- uriB = serialize(normalizeComponentEncoding(uriB, true), { ...options, skipEscape: true });
3634
- }
3635
- return uriA.toLowerCase() === uriB.toLowerCase();
3679
+ const normalizedA = normalizeComparableURI(uriA, options);
3680
+ const normalizedB = normalizeComparableURI(uriB, options);
3681
+ return normalizedA !== void 0 && normalizedB !== void 0 && normalizedA.toLowerCase() === normalizedB.toLowerCase();
3636
3682
  }
3637
3683
  function serialize(cmpts, opts) {
3638
3684
  const component = {
@@ -3657,12 +3703,12 @@ function requireFastUri() {
3657
3703
  if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(component, options);
3658
3704
  if (component.path !== void 0) {
3659
3705
  if (!options.skipEscape) {
3660
- component.path = escape(component.path);
3706
+ component.path = escapePreservingEscapes(component.path);
3661
3707
  if (component.scheme !== void 0) {
3662
3708
  component.path = component.path.split("%3A").join(":");
3663
3709
  }
3664
3710
  } else {
3665
- component.path = unescape(component.path);
3711
+ component.path = normalizePercentEncoding(component.path);
3666
3712
  }
3667
3713
  }
3668
3714
  if (options.reference !== "suffix" && component.scheme) {
@@ -3697,7 +3743,16 @@ function requireFastUri() {
3697
3743
  return uriTokens.join("");
3698
3744
  }
3699
3745
  const URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u;
3700
- function parse2(uri2, opts) {
3746
+ function getParseError(parsed, matches) {
3747
+ if (matches[2] !== void 0 && parsed.path && parsed.path[0] !== "/") {
3748
+ return 'URI path must start with "/" when authority is present.';
3749
+ }
3750
+ if (typeof parsed.port === "number" && (parsed.port < 0 || parsed.port > 65535)) {
3751
+ return "URI port is malformed.";
3752
+ }
3753
+ return void 0;
3754
+ }
3755
+ function parseWithStatus(uri2, opts) {
3701
3756
  const options = Object.assign({}, opts);
3702
3757
  const parsed = {
3703
3758
  scheme: void 0,
@@ -3708,6 +3763,7 @@ function requireFastUri() {
3708
3763
  query: void 0,
3709
3764
  fragment: void 0
3710
3765
  };
3766
+ let malformedAuthorityOrPort = false;
3711
3767
  let isIP = false;
3712
3768
  if (options.reference === "suffix") {
3713
3769
  if (options.scheme) {
@@ -3728,6 +3784,11 @@ function requireFastUri() {
3728
3784
  if (isNaN(parsed.port)) {
3729
3785
  parsed.port = matches[5];
3730
3786
  }
3787
+ const parseError = getParseError(parsed, matches);
3788
+ if (parseError !== void 0) {
3789
+ parsed.error = parsed.error || parseError;
3790
+ malformedAuthorityOrPort = true;
3791
+ }
3731
3792
  if (parsed.host) {
3732
3793
  const ipv4result = isIPv4(parsed.host);
3733
3794
  if (ipv4result === false) {
@@ -3754,7 +3815,7 @@ function requireFastUri() {
3754
3815
  if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
3755
3816
  if (parsed.host && (options.domainHost || schemeHandler && schemeHandler.domainHost) && isIP === false && nonSimpleDomain(parsed.host)) {
3756
3817
  try {
3757
- parsed.host = URL.domainToASCII(parsed.host.toLowerCase());
3818
+ parsed.host = new URL("http://" + parsed.host).hostname;
3758
3819
  } catch (e) {
3759
3820
  parsed.error = parsed.error || "Host's domain name can not be converted to ASCII: " + e;
3760
3821
  }
@@ -3766,14 +3827,18 @@ function requireFastUri() {
3766
3827
  parsed.scheme = unescape(parsed.scheme);
3767
3828
  }
3768
3829
  if (parsed.host !== void 0) {
3769
- parsed.host = unescape(parsed.host);
3830
+ parsed.host = reescapeHostDelimiters(unescape(parsed.host), isIP);
3770
3831
  }
3771
3832
  }
3772
3833
  if (parsed.path) {
3773
- parsed.path = escape(unescape(parsed.path));
3834
+ parsed.path = normalizePathEncoding(parsed.path);
3774
3835
  }
3775
3836
  if (parsed.fragment) {
3776
- parsed.fragment = encodeURI(decodeURIComponent(parsed.fragment));
3837
+ try {
3838
+ parsed.fragment = encodeURI(decodeURIComponent(parsed.fragment));
3839
+ } catch {
3840
+ parsed.error = parsed.error || "URI malformed";
3841
+ }
3777
3842
  }
3778
3843
  }
3779
3844
  if (schemeHandler && schemeHandler.parse) {
@@ -3782,7 +3847,29 @@ function requireFastUri() {
3782
3847
  } else {
3783
3848
  parsed.error = parsed.error || "URI can not be parsed.";
3784
3849
  }
3785
- return parsed;
3850
+ return { parsed, malformedAuthorityOrPort };
3851
+ }
3852
+ function parse2(uri2, opts) {
3853
+ return parseWithStatus(uri2, opts).parsed;
3854
+ }
3855
+ function normalizeString(uri2, opts) {
3856
+ return normalizeStringWithStatus(uri2, opts).normalized;
3857
+ }
3858
+ function normalizeStringWithStatus(uri2, opts) {
3859
+ const { parsed, malformedAuthorityOrPort } = parseWithStatus(uri2, opts);
3860
+ return {
3861
+ normalized: malformedAuthorityOrPort ? uri2 : serialize(parsed, opts),
3862
+ malformedAuthorityOrPort
3863
+ };
3864
+ }
3865
+ function normalizeComparableURI(uri2, opts) {
3866
+ if (typeof uri2 === "string") {
3867
+ const { normalized, malformedAuthorityOrPort } = normalizeStringWithStatus(uri2, opts);
3868
+ return malformedAuthorityOrPort ? void 0 : normalized;
3869
+ }
3870
+ if (typeof uri2 === "object") {
3871
+ return serialize(uri2, opts);
3872
+ }
3786
3873
  }
3787
3874
  const fastUri$1 = {
3788
3875
  SCHEMES,
@@ -3921,7 +4008,7 @@ function requireCore$1() {
3921
4008
  constructor(opts = {}) {
3922
4009
  this.schemas = {};
3923
4010
  this.refs = {};
3924
- this.formats = {};
4011
+ this.formats = /* @__PURE__ */ Object.create(null);
3925
4012
  this._compilations = /* @__PURE__ */ new Set();
3926
4013
  this._loading = {};
3927
4014
  this._cache = /* @__PURE__ */ new Map();
@@ -20095,46 +20182,128 @@ class ParseError extends Error {
20095
20182
  super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
20096
20183
  }
20097
20184
  }
20185
+ const LF = 10, CR = 13, SPACE = 32;
20098
20186
  function noop(_arg) {
20099
20187
  }
20100
- function createParser(callbacks) {
20101
- if (typeof callbacks == "function")
20188
+ function createParser(config2) {
20189
+ if (typeof config2 == "function")
20102
20190
  throw new TypeError(
20103
- "`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
20191
+ "`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
20104
20192
  );
20105
- const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
20106
- let incompleteLine = "", isFirstChunk = true, id2, data = "", eventType = "";
20107
- function feed(newChunk) {
20108
- const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
20109
- for (const line of complete)
20110
- parseLine(line);
20111
- incompleteLine = incomplete, isFirstChunk = false;
20112
- }
20113
- function parseLine(line) {
20114
- if (line === "") {
20193
+ const { onEvent = noop, onError = noop, onRetry = noop, onComment, maxBufferSize } = config2, pendingFragments = [];
20194
+ let pendingFragmentsLength = 0, isFirstChunk = true, id2, data = "", dataLines = 0, eventType, terminated = false;
20195
+ function feed(chunk) {
20196
+ if (terminated)
20197
+ throw new Error(
20198
+ "Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
20199
+ );
20200
+ if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
20201
+ const trailing2 = processLines(chunk);
20202
+ trailing2 !== "" && (pendingFragments.push(trailing2), pendingFragmentsLength = trailing2.length), checkBufferSize();
20203
+ return;
20204
+ }
20205
+ if (chunk.indexOf(`
20206
+ `) === -1 && chunk.indexOf("\r") === -1) {
20207
+ pendingFragments.push(chunk), pendingFragmentsLength += chunk.length, checkBufferSize();
20208
+ return;
20209
+ }
20210
+ pendingFragments.push(chunk);
20211
+ const input = pendingFragments.join("");
20212
+ pendingFragments.length = 0, pendingFragmentsLength = 0;
20213
+ const trailing = processLines(input);
20214
+ trailing !== "" && (pendingFragments.push(trailing), pendingFragmentsLength = trailing.length), checkBufferSize();
20215
+ }
20216
+ function checkBufferSize() {
20217
+ maxBufferSize !== void 0 && (pendingFragmentsLength + data.length <= maxBufferSize || (terminated = true, pendingFragments.length = 0, pendingFragmentsLength = 0, id2 = void 0, data = "", dataLines = 0, eventType = void 0, onError(
20218
+ new ParseError(`Buffered data exceeded max buffer size of ${maxBufferSize} characters`, {
20219
+ type: "max-buffer-size-exceeded"
20220
+ })
20221
+ )));
20222
+ }
20223
+ function processLines(chunk) {
20224
+ let searchIndex = 0;
20225
+ if (chunk.indexOf("\r") === -1) {
20226
+ let lfIndex = chunk.indexOf(`
20227
+ `, searchIndex);
20228
+ for (; lfIndex !== -1; ) {
20229
+ if (searchIndex === lfIndex) {
20230
+ dataLines > 0 && onEvent({ id: id2, event: eventType, data }), id2 = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
20231
+ `, searchIndex);
20232
+ continue;
20233
+ }
20234
+ const firstCharCode = chunk.charCodeAt(searchIndex);
20235
+ if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
20236
+ const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
20237
+ if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
20238
+ onEvent({ id: id2, event: eventType, data: value }), id2 = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
20239
+ `, searchIndex);
20240
+ continue;
20241
+ }
20242
+ data = dataLines === 0 ? value : `${data}
20243
+ ${value}`, dataLines++;
20244
+ } else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
20245
+ chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
20246
+ lfIndex
20247
+ ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
20248
+ searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
20249
+ `, searchIndex);
20250
+ }
20251
+ return chunk.slice(searchIndex);
20252
+ }
20253
+ for (; searchIndex < chunk.length; ) {
20254
+ const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
20255
+ `, searchIndex);
20256
+ let lineEnd = -1;
20257
+ 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)
20258
+ break;
20259
+ parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
20260
+ }
20261
+ return chunk.slice(searchIndex);
20262
+ }
20263
+ function parseLine(chunk, start, end) {
20264
+ if (start === end) {
20115
20265
  dispatchEvent();
20116
20266
  return;
20117
20267
  }
20118
- if (line.startsWith(":")) {
20119
- onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
20268
+ const firstCharCode = chunk.charCodeAt(start);
20269
+ if (isDataPrefix(chunk, start, firstCharCode)) {
20270
+ const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
20271
+ data = dataLines === 0 ? value2 : `${data}
20272
+ ${value2}`, dataLines++;
20273
+ return;
20274
+ }
20275
+ if (isEventPrefix(chunk, start, firstCharCode)) {
20276
+ eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
20120
20277
  return;
20121
20278
  }
20122
- const fieldSeparatorIndex = line.indexOf(":");
20123
- if (fieldSeparatorIndex !== -1) {
20124
- const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
20125
- processField(field, value, line);
20279
+ if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
20280
+ const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
20281
+ id2 = value2.includes("\0") ? void 0 : value2;
20126
20282
  return;
20127
20283
  }
20128
- processField(line, "", line);
20284
+ if (firstCharCode === 58) {
20285
+ if (onComment) {
20286
+ const line2 = chunk.slice(start, end);
20287
+ onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
20288
+ }
20289
+ return;
20290
+ }
20291
+ const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
20292
+ if (fieldSeparatorIndex === -1) {
20293
+ processField(line, "", line);
20294
+ return;
20295
+ }
20296
+ const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
20297
+ processField(field, value, line);
20129
20298
  }
20130
20299
  function processField(field, value, line) {
20131
20300
  switch (field) {
20132
20301
  case "event":
20133
- eventType = value;
20302
+ eventType = value || void 0;
20134
20303
  break;
20135
20304
  case "data":
20136
- data = `${data}${value}
20137
- `;
20305
+ data = dataLines === 0 ? value : `${data}
20306
+ ${value}`, dataLines++;
20138
20307
  break;
20139
20308
  case "id":
20140
20309
  id2 = value.includes("\0") ? void 0 : value;
@@ -20159,37 +20328,26 @@ function createParser(callbacks) {
20159
20328
  }
20160
20329
  }
20161
20330
  function dispatchEvent() {
20162
- data.length > 0 && onEvent({
20331
+ dataLines > 0 && onEvent({
20163
20332
  id: id2,
20164
- event: eventType || void 0,
20165
- // If the data buffer's last character is a U+000A LINE FEED (LF) character,
20166
- // then remove the last character from the data buffer.
20167
- data: data.endsWith(`
20168
- `) ? data.slice(0, -1) : data
20169
- }), id2 = void 0, data = "", eventType = "";
20333
+ event: eventType,
20334
+ data
20335
+ }), id2 = void 0, data = "", dataLines = 0, eventType = void 0;
20170
20336
  }
20171
20337
  function reset(options = {}) {
20172
- incompleteLine && options.consume && parseLine(incompleteLine), isFirstChunk = true, id2 = void 0, data = "", eventType = "", incompleteLine = "";
20338
+ if (options.consume && pendingFragments.length > 0) {
20339
+ const incompleteLine = pendingFragments.join("");
20340
+ parseLine(incompleteLine, 0, incompleteLine.length);
20341
+ }
20342
+ isFirstChunk = true, id2 = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0, pendingFragmentsLength = 0, terminated = false;
20173
20343
  }
20174
20344
  return { feed, reset };
20175
20345
  }
20176
- function splitLines(chunk) {
20177
- const lines = [];
20178
- let incompleteLine = "", searchIndex = 0;
20179
- for (; searchIndex < chunk.length; ) {
20180
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
20181
- `, searchIndex);
20182
- let lineEnd = -1;
20183
- if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
20184
- incompleteLine = chunk.slice(searchIndex);
20185
- break;
20186
- } else {
20187
- const line = chunk.slice(searchIndex, lineEnd);
20188
- lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
20189
- ` && searchIndex++;
20190
- }
20191
- }
20192
- return [lines, incompleteLine];
20346
+ function isDataPrefix(chunk, i, firstCharCode) {
20347
+ return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
20348
+ }
20349
+ function isEventPrefix(chunk, i, firstCharCode) {
20350
+ 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;
20193
20351
  }
20194
20352
  class ErrorEvent extends Event {
20195
20353
  /**
@@ -20673,7 +20831,7 @@ class SSEClientTransport {
20673
20831
  }
20674
20832
  }
20675
20833
  class EventSourceParserStream extends TransformStream {
20676
- constructor({ onError, onRetry, onComment } = {}) {
20834
+ constructor({ onError, onRetry, onComment, maxBufferSize } = {}) {
20677
20835
  let parser;
20678
20836
  super({
20679
20837
  start(controller) {
@@ -20682,10 +20840,11 @@ class EventSourceParserStream extends TransformStream {
20682
20840
  controller.enqueue(event);
20683
20841
  },
20684
20842
  onError(error) {
20685
- onError === "terminate" ? controller.error(error) : typeof onError == "function" && onError(error);
20843
+ typeof onError == "function" && onError(error), (onError === "terminate" || error.type === "max-buffer-size-exceeded") && controller.error(error);
20686
20844
  },
20687
20845
  onRetry,
20688
- onComment
20846
+ onComment,
20847
+ maxBufferSize
20689
20848
  });
20690
20849
  },
20691
20850
  transform(chunk) {