@rebon/cli-win32-x64 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +10 -0
  3. package/README.md +203 -144
  4. package/THIRD_PARTY_NOTICES.txt +1232 -1232
  5. package/bin/rebon.js +22 -22
  6. package/lib/windows-managed.js +390 -390
  7. package/package.json +9 -2
  8. package/payload/compose-runtime/package.json +17 -17
  9. package/payload/compose-runtime/payload/compose/shims/dsh-anonymous-user-id.js +10 -10
  10. package/payload/compose-runtime/payload/compose/shims/dsh-credentials.js +13 -13
  11. package/payload/compose-runtime/payload/compose/shims/dsh-launch-environment.js +21 -21
  12. package/payload/compose-runtime/payload/compose/shims/dsh-llm.js +313 -313
  13. package/payload/compose-runtime/payload/compose/shims/dsh-settings.js +43 -43
  14. package/payload/compose-runtime/payload/compose/shims/dsh-tools.js +20 -20
  15. package/payload/compose-runtime/payload/compose/shims/dsh-web.js +10 -10
  16. package/payload/compose-runtime/payload/compose/shims/llm-adapter.js +32 -32
  17. package/payload/compose-runtime/payload/compose/shims/zod-lite.js +49 -49
  18. package/payload/compose-runtime/payload/vendor/cordis/LICENSE +21 -21
  19. package/payload/compose-runtime/payload/vendor/cordis/index.js +1530 -1530
  20. package/payload/compose-runtime/payload/vendor/cosmokit/LICENSE +21 -21
  21. package/payload/compose-runtime/payload/vendor/cosmokit/index.mjs +357 -357
  22. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-agent +21 -21
  23. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-agent-loop +21 -21
  24. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-llm-core +21 -21
  25. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-llm-deepseek +21 -21
  26. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-logger-console +21 -21
  27. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-scope +21 -21
  28. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-session +21 -21
  29. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-system-prompt +21 -21
  30. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-timeout +21 -21
  31. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-timer +21 -21
  32. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-tool-todo +21 -21
  33. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-tool-web +21 -21
  34. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-tools-schema +21 -21
  35. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-turndown +21 -21
  36. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-turndown-plugin-gfm +21 -21
  37. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-web-search-exa +21 -21
  38. package/payload/compose-runtime/payload/vendor/dsh/agent-loop.js +1193 -1193
  39. package/payload/compose-runtime/payload/vendor/dsh/agent.js +714 -714
  40. package/payload/compose-runtime/payload/vendor/dsh/llm-core.js +269 -269
  41. package/payload/compose-runtime/payload/vendor/dsh/llm-deepseek.js +672 -672
  42. package/payload/compose-runtime/payload/vendor/dsh/logger-console.js +83 -83
  43. package/payload/compose-runtime/payload/vendor/dsh/scope.js +287 -287
  44. package/payload/compose-runtime/payload/vendor/dsh/session.js +1668 -1668
  45. package/payload/compose-runtime/payload/vendor/dsh/system-prompt.js +309 -309
  46. package/payload/compose-runtime/payload/vendor/dsh/timeout.js +100 -100
  47. package/payload/compose-runtime/payload/vendor/dsh/timer.js +128 -128
  48. package/payload/compose-runtime/payload/vendor/dsh/tool-todo.js +143 -143
  49. package/payload/compose-runtime/payload/vendor/dsh/tool-web.js +1527 -1527
  50. package/payload/compose-runtime/payload/vendor/dsh/tools-schema.js +849 -849
  51. package/payload/compose-runtime/payload/vendor/dsh/web-search-exa.js +122 -122
  52. package/payload/compose-runtime/payload/vendor/eventsource-parser/LICENSE +21 -21
  53. package/payload/compose-runtime/payload/vendor/eventsource-parser/index.js +177 -177
  54. package/payload/compose-runtime/payload/vendor/eventsource-parser/stream.js +48 -48
  55. package/payload/compose-runtime/payload/vendor/schemastery/LICENSE +21 -21
  56. package/payload/compose-runtime/payload/vendor/schemastery/index.mjs +656 -656
  57. package/payload/compose-runtime/payload-manifests.json +48 -48
  58. package/payload/compose-runtime/src/bridge.mjs +193 -195
  59. package/payload/compose-runtime/src/credentials-runtime.mjs +50 -50
  60. package/payload/compose-runtime/src/eventsource-stream.mjs +48 -48
  61. package/payload/compose-runtime/src/index.mjs +7 -7
  62. package/payload/compose-runtime/src/llm-runtime.mjs +326 -326
  63. package/payload/compose-runtime/src/loader.mjs +78 -78
  64. package/payload/compose-runtime/src/loop-assembly.mjs +237 -237
  65. package/payload/compose-runtime/src/payload.mjs +49 -49
  66. package/payload/compose-runtime/src/plugin.mjs +59 -59
  67. package/payload/compose-runtime/src/realm.mjs +223 -223
  68. package/payload/compose-runtime/src/registry.mjs +191 -191
  69. package/payload/compose-runtime/src/resolve.mjs +115 -115
  70. package/payload/compose-runtime/src/systemprompt-runtime.mjs +67 -67
  71. package/payload/compose-runtime/src/tools-runtime.mjs +239 -239
  72. package/payload/compose-runtime/src/web-runtime.mjs +209 -209
  73. package/payload/plugin-host/package.json +11 -11
  74. package/payload/plugin-host/src/bridge.mjs +64 -64
  75. package/payload/plugin-host/src/cli.mjs +147 -147
  76. package/payload/plugin-host/src/framing.mjs +113 -113
  77. package/payload/plugin-host/src/host.mjs +691 -691
  78. package/payload/plugin-host/src/json.mjs +208 -208
  79. package/payload/plugin-host/src/lifecycle.mjs +114 -114
  80. package/payload/plugin-host/src/loader.mjs +183 -183
  81. package/payload/plugin-host/src/methods.mjs +377 -377
  82. package/payload/plugin-host/src/ownership.mjs +57 -57
  83. package/payload/plugin-host/src/protocol.mjs +129 -129
  84. package/payload/plugin-host/src/sdk.mjs +7 -7
  85. package/payload/rebon-boa-helper.exe +0 -0
  86. package/payload/rebon-browser-mcp.exe +0 -0
  87. package/payload/rebon-computer-use.exe +0 -0
  88. package/payload/rebon-lsp-mcp.exe +0 -0
  89. package/payload/rebon.exe +2 -2
  90. package/payload/sandbox-win.exe +0 -0
  91. package/scripts/postinstall.js +112 -112
@@ -1,122 +1,122 @@
1
- // packages/web/web-search-exa/src/index.ts
2
- import { launchEnvironmentOf } from "@deepseek-ai/dsh-launch-environment";
3
- import z from "@deepseek-ai/schemastery";
4
-
5
- // packages/web/web-search-exa/src/provider.ts
6
- import { WebError } from "@deepseek-ai/dsh-web";
7
- var EXA_PROVIDER_ID = "exa";
8
- var EXA_DEFAULT_BASE_URL = "https://api.exa.ai";
9
- var EXA_DEFAULT_SEARCH_TYPE = "auto";
10
- var EXA_DEFAULT_HIGHLIGHTS_PER_RESULT = 1;
11
- var USER_AGENT = "deepseek-harness/0.0.1";
12
- function mapExaResult(result) {
13
- const snippet = result.highlights?.find((highlight) => highlight.trim().length > 0);
14
- if (snippet === void 0) return void 0;
15
- return {
16
- url: result.url,
17
- ...result.title != null && result.title.length > 0 ? { title: result.title } : {},
18
- snippet,
19
- ...result.publishedDate != null && result.publishedDate.length > 0 ? { publishedAt: result.publishedDate } : {}
20
- };
21
- }
22
- function mapExaResponse(response) {
23
- const sources = (response.results ?? []).map(mapExaResult).filter((source) => source !== void 0);
24
- return { sources, truncated: false };
25
- }
26
- var ExaSearchProvider = class {
27
- constructor(options) {
28
- this.options = options;
29
- }
30
- options;
31
- id = EXA_PROVIDER_ID;
32
- available() {
33
- return this.options.apiKey.length > 0 && isValidBaseUrl(this.options.baseURL) && isPositiveInteger(this.options.highlightsPerResult) && (this.options.numResults === void 0 || isPositiveInteger(this.options.numResults));
34
- }
35
- async search(request, signal) {
36
- const numResults = request.maxResults ?? this.options.numResults;
37
- let response;
38
- try {
39
- response = await fetch(`${this.options.baseURL}/search`, {
40
- method: "POST",
41
- redirect: "error",
42
- headers: {
43
- "authorization": `Bearer ${this.options.apiKey}`,
44
- "content-type": "application/json",
45
- "accept": "application/json",
46
- "user-agent": USER_AGENT
47
- },
48
- body: JSON.stringify({
49
- query: request.query,
50
- type: this.options.searchType,
51
- contents: { highlights: { highlightsPerUrl: this.options.highlightsPerResult } },
52
- ...numResults !== void 0 ? { numResults } : {}
53
- }),
54
- ...signal !== void 0 ? { signal } : {}
55
- });
56
- } catch (error) {
57
- if (isAbortError(error)) throw new WebError("Exa search aborted", "WEB_ABORTED", { cause: error });
58
- throw new WebError(`Exa search request failed: ${String(error)}`, "WEB_PROVIDER_ERROR", { cause: error });
59
- }
60
- if (!response.ok) {
61
- const status = response.status;
62
- let message = `Exa API error (HTTP ${status})`;
63
- try {
64
- const parsed = await response.json();
65
- const detail = parsed.error ?? parsed.message;
66
- if (detail !== void 0 && detail.length > 0) message = detail;
67
- } catch (error) {
68
- if (isAbortError(error)) throw new WebError("Exa search aborted", "WEB_ABORTED", { cause: error });
69
- }
70
- throw new WebError(message, "WEB_PROVIDER_ERROR");
71
- }
72
- try {
73
- const payload = await response.json();
74
- return mapExaResponse(payload);
75
- } catch (error) {
76
- if (isAbortError(error)) throw new WebError("Exa search aborted", "WEB_ABORTED", { cause: error });
77
- throw new WebError(`Exa returned an unprocessable response body: ${String(error)}`, "WEB_PROVIDER_ERROR", { cause: error });
78
- }
79
- }
80
- };
81
- function isValidBaseUrl(baseURL) {
82
- return URL.canParse(baseURL);
83
- }
84
- function isPositiveInteger(value) {
85
- return Number.isInteger(value) && value > 0;
86
- }
87
- function isAbortError(error) {
88
- return error instanceof DOMException && error.name === "AbortError";
89
- }
90
-
91
- // packages/web/web-search-exa/src/index.ts
92
- var name = "web-search-exa";
93
- var inject = ["web"];
94
- var Config = z.object({
95
- apiKey: z.string(),
96
- baseURL: z.string(),
97
- searchType: z.union(["auto", "keyword", "neural"]),
98
- numResults: z.number().step(1).min(1),
99
- highlightsPerResult: z.number().step(1).min(1)
100
- });
101
- function apply(ctx, config) {
102
- ctx.web.registerSearchProvider(new ExaSearchProvider({
103
- // Every environment layer may name this key: the product trusts the
104
- // project it is launched in, and the managed store is not involved here.
105
- apiKey: config.apiKey ?? launchEnvironmentOf(ctx).get("EXA_API_KEY")?.value ?? "",
106
- baseURL: config.baseURL ?? EXA_DEFAULT_BASE_URL,
107
- searchType: config.searchType ?? EXA_DEFAULT_SEARCH_TYPE,
108
- highlightsPerResult: config.highlightsPerResult ?? EXA_DEFAULT_HIGHLIGHTS_PER_RESULT,
109
- ...config.numResults !== void 0 ? { numResults: config.numResults } : {}
110
- }));
111
- }
112
- export {
113
- Config,
114
- EXA_DEFAULT_BASE_URL,
115
- EXA_DEFAULT_HIGHLIGHTS_PER_RESULT,
116
- EXA_DEFAULT_SEARCH_TYPE,
117
- EXA_PROVIDER_ID,
118
- ExaSearchProvider,
119
- apply,
120
- inject,
121
- name
122
- };
1
+ // packages/web/web-search-exa/src/index.ts
2
+ import { launchEnvironmentOf } from "@deepseek-ai/dsh-launch-environment";
3
+ import z from "@deepseek-ai/schemastery";
4
+
5
+ // packages/web/web-search-exa/src/provider.ts
6
+ import { WebError } from "@deepseek-ai/dsh-web";
7
+ var EXA_PROVIDER_ID = "exa";
8
+ var EXA_DEFAULT_BASE_URL = "https://api.exa.ai";
9
+ var EXA_DEFAULT_SEARCH_TYPE = "auto";
10
+ var EXA_DEFAULT_HIGHLIGHTS_PER_RESULT = 1;
11
+ var USER_AGENT = "deepseek-harness/0.0.1";
12
+ function mapExaResult(result) {
13
+ const snippet = result.highlights?.find((highlight) => highlight.trim().length > 0);
14
+ if (snippet === void 0) return void 0;
15
+ return {
16
+ url: result.url,
17
+ ...result.title != null && result.title.length > 0 ? { title: result.title } : {},
18
+ snippet,
19
+ ...result.publishedDate != null && result.publishedDate.length > 0 ? { publishedAt: result.publishedDate } : {}
20
+ };
21
+ }
22
+ function mapExaResponse(response) {
23
+ const sources = (response.results ?? []).map(mapExaResult).filter((source) => source !== void 0);
24
+ return { sources, truncated: false };
25
+ }
26
+ var ExaSearchProvider = class {
27
+ constructor(options) {
28
+ this.options = options;
29
+ }
30
+ options;
31
+ id = EXA_PROVIDER_ID;
32
+ available() {
33
+ return this.options.apiKey.length > 0 && isValidBaseUrl(this.options.baseURL) && isPositiveInteger(this.options.highlightsPerResult) && (this.options.numResults === void 0 || isPositiveInteger(this.options.numResults));
34
+ }
35
+ async search(request, signal) {
36
+ const numResults = request.maxResults ?? this.options.numResults;
37
+ let response;
38
+ try {
39
+ response = await fetch(`${this.options.baseURL}/search`, {
40
+ method: "POST",
41
+ redirect: "error",
42
+ headers: {
43
+ "authorization": `Bearer ${this.options.apiKey}`,
44
+ "content-type": "application/json",
45
+ "accept": "application/json",
46
+ "user-agent": USER_AGENT
47
+ },
48
+ body: JSON.stringify({
49
+ query: request.query,
50
+ type: this.options.searchType,
51
+ contents: { highlights: { highlightsPerUrl: this.options.highlightsPerResult } },
52
+ ...numResults !== void 0 ? { numResults } : {}
53
+ }),
54
+ ...signal !== void 0 ? { signal } : {}
55
+ });
56
+ } catch (error) {
57
+ if (isAbortError(error)) throw new WebError("Exa search aborted", "WEB_ABORTED", { cause: error });
58
+ throw new WebError(`Exa search request failed: ${String(error)}`, "WEB_PROVIDER_ERROR", { cause: error });
59
+ }
60
+ if (!response.ok) {
61
+ const status = response.status;
62
+ let message = `Exa API error (HTTP ${status})`;
63
+ try {
64
+ const parsed = await response.json();
65
+ const detail = parsed.error ?? parsed.message;
66
+ if (detail !== void 0 && detail.length > 0) message = detail;
67
+ } catch (error) {
68
+ if (isAbortError(error)) throw new WebError("Exa search aborted", "WEB_ABORTED", { cause: error });
69
+ }
70
+ throw new WebError(message, "WEB_PROVIDER_ERROR");
71
+ }
72
+ try {
73
+ const payload = await response.json();
74
+ return mapExaResponse(payload);
75
+ } catch (error) {
76
+ if (isAbortError(error)) throw new WebError("Exa search aborted", "WEB_ABORTED", { cause: error });
77
+ throw new WebError(`Exa returned an unprocessable response body: ${String(error)}`, "WEB_PROVIDER_ERROR", { cause: error });
78
+ }
79
+ }
80
+ };
81
+ function isValidBaseUrl(baseURL) {
82
+ return URL.canParse(baseURL);
83
+ }
84
+ function isPositiveInteger(value) {
85
+ return Number.isInteger(value) && value > 0;
86
+ }
87
+ function isAbortError(error) {
88
+ return error instanceof DOMException && error.name === "AbortError";
89
+ }
90
+
91
+ // packages/web/web-search-exa/src/index.ts
92
+ var name = "web-search-exa";
93
+ var inject = ["web"];
94
+ var Config = z.object({
95
+ apiKey: z.string(),
96
+ baseURL: z.string(),
97
+ searchType: z.union(["auto", "keyword", "neural"]),
98
+ numResults: z.number().step(1).min(1),
99
+ highlightsPerResult: z.number().step(1).min(1)
100
+ });
101
+ function apply(ctx, config) {
102
+ ctx.web.registerSearchProvider(new ExaSearchProvider({
103
+ // Every environment layer may name this key: the product trusts the
104
+ // project it is launched in, and the managed store is not involved here.
105
+ apiKey: config.apiKey ?? launchEnvironmentOf(ctx).get("EXA_API_KEY")?.value ?? "",
106
+ baseURL: config.baseURL ?? EXA_DEFAULT_BASE_URL,
107
+ searchType: config.searchType ?? EXA_DEFAULT_SEARCH_TYPE,
108
+ highlightsPerResult: config.highlightsPerResult ?? EXA_DEFAULT_HIGHLIGHTS_PER_RESULT,
109
+ ...config.numResults !== void 0 ? { numResults: config.numResults } : {}
110
+ }));
111
+ }
112
+ export {
113
+ Config,
114
+ EXA_DEFAULT_BASE_URL,
115
+ EXA_DEFAULT_HIGHLIGHTS_PER_RESULT,
116
+ EXA_DEFAULT_SEARCH_TYPE,
117
+ EXA_PROVIDER_ID,
118
+ ExaSearchProvider,
119
+ apply,
120
+ inject,
121
+ name
122
+ };
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Espen Hovlandsdal <espen@hovlandsdal.com>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Espen Hovlandsdal <espen@hovlandsdal.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,177 +1,177 @@
1
- class ParseError extends Error {
2
- constructor(message, options) {
3
- super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
4
- }
5
- }
6
- const LF = 10, CR = 13, SPACE = 32;
7
- function noop(_arg) {
8
- }
9
- function createParser(config) {
10
- if (typeof config == "function")
11
- throw new TypeError(
12
- "`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
13
- );
14
- const { onEvent = noop, onError = noop, onRetry = noop, onComment, maxBufferSize } = config, pendingFragments = [];
15
- let pendingFragmentsLength = 0, isFirstChunk = !0, id, data = "", dataLines = 0, eventType, terminated = !1;
16
- function feed(chunk) {
17
- if (terminated)
18
- throw new Error(
19
- "Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
20
- );
21
- if (isFirstChunk && (isFirstChunk = !1, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
22
- const trailing2 = processLines(chunk);
23
- trailing2 !== "" && (pendingFragments.push(trailing2), pendingFragmentsLength = trailing2.length), checkBufferSize();
24
- return;
25
- }
26
- if (chunk.indexOf(`
27
- `) === -1 && chunk.indexOf("\r") === -1) {
28
- pendingFragments.push(chunk), pendingFragmentsLength += chunk.length, checkBufferSize();
29
- return;
30
- }
31
- pendingFragments.push(chunk);
32
- const input = pendingFragments.join("");
33
- pendingFragments.length = 0, pendingFragmentsLength = 0;
34
- const trailing = processLines(input);
35
- trailing !== "" && (pendingFragments.push(trailing), pendingFragmentsLength = trailing.length), checkBufferSize();
36
- }
37
- function checkBufferSize() {
38
- maxBufferSize !== void 0 && (pendingFragmentsLength + data.length <= maxBufferSize || (terminated = !0, pendingFragments.length = 0, pendingFragmentsLength = 0, id = void 0, data = "", dataLines = 0, eventType = void 0, onError(
39
- new ParseError(`Buffered data exceeded max buffer size of ${maxBufferSize} characters`, {
40
- type: "max-buffer-size-exceeded"
41
- })
42
- )));
43
- }
44
- function processLines(chunk) {
45
- let searchIndex = 0;
46
- if (chunk.indexOf("\r") === -1) {
47
- let lfIndex = chunk.indexOf(`
48
- `, searchIndex);
49
- for (; lfIndex !== -1; ) {
50
- if (searchIndex === lfIndex) {
51
- dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
52
- `, searchIndex);
53
- continue;
54
- }
55
- const firstCharCode = chunk.charCodeAt(searchIndex);
56
- if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
57
- const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
58
- if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
59
- onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
60
- `, searchIndex);
61
- continue;
62
- }
63
- data = dataLines === 0 ? value : `${data}
64
- ${value}`, dataLines++;
65
- } else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
66
- chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
67
- lfIndex
68
- ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
69
- searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
70
- `, searchIndex);
71
- }
72
- return chunk.slice(searchIndex);
73
- }
74
- for (; searchIndex < chunk.length; ) {
75
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
76
- `, searchIndex);
77
- let lineEnd = -1;
78
- 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)
79
- break;
80
- parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
81
- }
82
- return chunk.slice(searchIndex);
83
- }
84
- function parseLine(chunk, start, end) {
85
- if (start === end) {
86
- dispatchEvent();
87
- return;
88
- }
89
- const firstCharCode = chunk.charCodeAt(start);
90
- if (isDataPrefix(chunk, start, firstCharCode)) {
91
- const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
92
- data = dataLines === 0 ? value2 : `${data}
93
- ${value2}`, dataLines++;
94
- return;
95
- }
96
- if (isEventPrefix(chunk, start, firstCharCode)) {
97
- eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
98
- return;
99
- }
100
- if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
101
- const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
102
- id = value2.includes("\0") ? void 0 : value2;
103
- return;
104
- }
105
- if (firstCharCode === 58) {
106
- if (onComment) {
107
- const line2 = chunk.slice(start, end);
108
- onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
109
- }
110
- return;
111
- }
112
- const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
113
- if (fieldSeparatorIndex === -1) {
114
- processField(line, "", line);
115
- return;
116
- }
117
- const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
118
- processField(field, value, line);
119
- }
120
- function processField(field, value, line) {
121
- switch (field) {
122
- case "event":
123
- eventType = value || void 0;
124
- break;
125
- case "data":
126
- data = dataLines === 0 ? value : `${data}
127
- ${value}`, dataLines++;
128
- break;
129
- case "id":
130
- id = value.includes("\0") ? void 0 : value;
131
- break;
132
- case "retry":
133
- /^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(
134
- new ParseError(`Invalid \`retry\` value: "${value}"`, {
135
- type: "invalid-retry",
136
- value,
137
- line
138
- })
139
- );
140
- break;
141
- default:
142
- onError(
143
- new ParseError(
144
- `Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`,
145
- { type: "unknown-field", field, value, line }
146
- )
147
- );
148
- break;
149
- }
150
- }
151
- function dispatchEvent() {
152
- dataLines > 0 && onEvent({
153
- id,
154
- event: eventType,
155
- data
156
- }), id = void 0, data = "", dataLines = 0, eventType = void 0;
157
- }
158
- function reset(options = {}) {
159
- if (options.consume && pendingFragments.length > 0) {
160
- const incompleteLine = pendingFragments.join("");
161
- parseLine(incompleteLine, 0, incompleteLine.length);
162
- }
163
- isFirstChunk = !0, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0, pendingFragmentsLength = 0, terminated = !1;
164
- }
165
- return { feed, reset };
166
- }
167
- function isDataPrefix(chunk, i, firstCharCode) {
168
- return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
169
- }
170
- function isEventPrefix(chunk, i, firstCharCode) {
171
- 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;
172
- }
173
- export {
174
- ParseError,
175
- createParser
176
- };
177
-
1
+ class ParseError extends Error {
2
+ constructor(message, options) {
3
+ super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
4
+ }
5
+ }
6
+ const LF = 10, CR = 13, SPACE = 32;
7
+ function noop(_arg) {
8
+ }
9
+ function createParser(config) {
10
+ if (typeof config == "function")
11
+ throw new TypeError(
12
+ "`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
13
+ );
14
+ const { onEvent = noop, onError = noop, onRetry = noop, onComment, maxBufferSize } = config, pendingFragments = [];
15
+ let pendingFragmentsLength = 0, isFirstChunk = !0, id, data = "", dataLines = 0, eventType, terminated = !1;
16
+ function feed(chunk) {
17
+ if (terminated)
18
+ throw new Error(
19
+ "Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
20
+ );
21
+ if (isFirstChunk && (isFirstChunk = !1, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
22
+ const trailing2 = processLines(chunk);
23
+ trailing2 !== "" && (pendingFragments.push(trailing2), pendingFragmentsLength = trailing2.length), checkBufferSize();
24
+ return;
25
+ }
26
+ if (chunk.indexOf(`
27
+ `) === -1 && chunk.indexOf("\r") === -1) {
28
+ pendingFragments.push(chunk), pendingFragmentsLength += chunk.length, checkBufferSize();
29
+ return;
30
+ }
31
+ pendingFragments.push(chunk);
32
+ const input = pendingFragments.join("");
33
+ pendingFragments.length = 0, pendingFragmentsLength = 0;
34
+ const trailing = processLines(input);
35
+ trailing !== "" && (pendingFragments.push(trailing), pendingFragmentsLength = trailing.length), checkBufferSize();
36
+ }
37
+ function checkBufferSize() {
38
+ maxBufferSize !== void 0 && (pendingFragmentsLength + data.length <= maxBufferSize || (terminated = !0, pendingFragments.length = 0, pendingFragmentsLength = 0, id = void 0, data = "", dataLines = 0, eventType = void 0, onError(
39
+ new ParseError(`Buffered data exceeded max buffer size of ${maxBufferSize} characters`, {
40
+ type: "max-buffer-size-exceeded"
41
+ })
42
+ )));
43
+ }
44
+ function processLines(chunk) {
45
+ let searchIndex = 0;
46
+ if (chunk.indexOf("\r") === -1) {
47
+ let lfIndex = chunk.indexOf(`
48
+ `, searchIndex);
49
+ for (; lfIndex !== -1; ) {
50
+ if (searchIndex === lfIndex) {
51
+ dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
52
+ `, searchIndex);
53
+ continue;
54
+ }
55
+ const firstCharCode = chunk.charCodeAt(searchIndex);
56
+ if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
57
+ const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
58
+ if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
59
+ onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
60
+ `, searchIndex);
61
+ continue;
62
+ }
63
+ data = dataLines === 0 ? value : `${data}
64
+ ${value}`, dataLines++;
65
+ } else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
66
+ chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
67
+ lfIndex
68
+ ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
69
+ searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
70
+ `, searchIndex);
71
+ }
72
+ return chunk.slice(searchIndex);
73
+ }
74
+ for (; searchIndex < chunk.length; ) {
75
+ const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
76
+ `, searchIndex);
77
+ let lineEnd = -1;
78
+ 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)
79
+ break;
80
+ parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
81
+ }
82
+ return chunk.slice(searchIndex);
83
+ }
84
+ function parseLine(chunk, start, end) {
85
+ if (start === end) {
86
+ dispatchEvent();
87
+ return;
88
+ }
89
+ const firstCharCode = chunk.charCodeAt(start);
90
+ if (isDataPrefix(chunk, start, firstCharCode)) {
91
+ const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
92
+ data = dataLines === 0 ? value2 : `${data}
93
+ ${value2}`, dataLines++;
94
+ return;
95
+ }
96
+ if (isEventPrefix(chunk, start, firstCharCode)) {
97
+ eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
98
+ return;
99
+ }
100
+ if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
101
+ const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
102
+ id = value2.includes("\0") ? void 0 : value2;
103
+ return;
104
+ }
105
+ if (firstCharCode === 58) {
106
+ if (onComment) {
107
+ const line2 = chunk.slice(start, end);
108
+ onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
109
+ }
110
+ return;
111
+ }
112
+ const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
113
+ if (fieldSeparatorIndex === -1) {
114
+ processField(line, "", line);
115
+ return;
116
+ }
117
+ const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
118
+ processField(field, value, line);
119
+ }
120
+ function processField(field, value, line) {
121
+ switch (field) {
122
+ case "event":
123
+ eventType = value || void 0;
124
+ break;
125
+ case "data":
126
+ data = dataLines === 0 ? value : `${data}
127
+ ${value}`, dataLines++;
128
+ break;
129
+ case "id":
130
+ id = value.includes("\0") ? void 0 : value;
131
+ break;
132
+ case "retry":
133
+ /^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(
134
+ new ParseError(`Invalid \`retry\` value: "${value}"`, {
135
+ type: "invalid-retry",
136
+ value,
137
+ line
138
+ })
139
+ );
140
+ break;
141
+ default:
142
+ onError(
143
+ new ParseError(
144
+ `Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`,
145
+ { type: "unknown-field", field, value, line }
146
+ )
147
+ );
148
+ break;
149
+ }
150
+ }
151
+ function dispatchEvent() {
152
+ dataLines > 0 && onEvent({
153
+ id,
154
+ event: eventType,
155
+ data
156
+ }), id = void 0, data = "", dataLines = 0, eventType = void 0;
157
+ }
158
+ function reset(options = {}) {
159
+ if (options.consume && pendingFragments.length > 0) {
160
+ const incompleteLine = pendingFragments.join("");
161
+ parseLine(incompleteLine, 0, incompleteLine.length);
162
+ }
163
+ isFirstChunk = !0, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0, pendingFragmentsLength = 0, terminated = !1;
164
+ }
165
+ return { feed, reset };
166
+ }
167
+ function isDataPrefix(chunk, i, firstCharCode) {
168
+ return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
169
+ }
170
+ function isEventPrefix(chunk, i, firstCharCode) {
171
+ 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;
172
+ }
173
+ export {
174
+ ParseError,
175
+ createParser
176
+ };
177
+