@rebon/cli-darwin-arm64 0.17.2 → 0.18.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 (82) hide show
  1. package/bin/compose-runtime/package.json +17 -0
  2. package/bin/compose-runtime/payload/compose/credentials-runtime.js +38 -0
  3. package/bin/compose-runtime/payload/compose/llm-runtime.js +330 -0
  4. package/bin/compose-runtime/payload/compose/loop-assembly.js +149 -0
  5. package/bin/compose-runtime/payload/compose/serve-dispatch.js +82 -0
  6. package/bin/compose-runtime/payload/compose/shims/dsh-anonymous-user-id.js +10 -0
  7. package/bin/compose-runtime/payload/compose/shims/dsh-credentials.js +13 -0
  8. package/bin/compose-runtime/payload/compose/shims/dsh-launch-environment.js +21 -0
  9. package/bin/compose-runtime/payload/compose/shims/dsh-llm.js +313 -0
  10. package/bin/compose-runtime/payload/compose/shims/dsh-settings.js +43 -0
  11. package/bin/compose-runtime/payload/compose/shims/dsh-tools.js +20 -0
  12. package/bin/compose-runtime/payload/compose/shims/dsh-web.js +10 -0
  13. package/bin/compose-runtime/payload/compose/shims/llm-adapter.js +32 -0
  14. package/bin/compose-runtime/payload/compose/shims/zod-lite.js +49 -0
  15. package/bin/compose-runtime/payload/compose/systemprompt-runtime.js +74 -0
  16. package/bin/compose-runtime/payload/compose/tools-runtime.js +228 -0
  17. package/bin/compose-runtime/payload/compose/web-runtime.js +204 -0
  18. package/bin/compose-runtime/payload/vendor/cordis/index.js +1530 -0
  19. package/bin/compose-runtime/payload/vendor/cosmokit/LICENSE +21 -0
  20. package/bin/compose-runtime/payload/vendor/cosmokit/index.mjs +357 -0
  21. package/bin/compose-runtime/payload/vendor/dsh/LICENSE-agent +21 -0
  22. package/bin/compose-runtime/payload/vendor/dsh/LICENSE-agent-loop +21 -0
  23. package/bin/compose-runtime/payload/vendor/dsh/LICENSE-llm-core +21 -0
  24. package/bin/compose-runtime/payload/vendor/dsh/LICENSE-llm-deepseek +21 -0
  25. package/bin/compose-runtime/payload/vendor/dsh/LICENSE-logger-console +21 -0
  26. package/bin/compose-runtime/payload/vendor/dsh/LICENSE-scope +21 -0
  27. package/bin/compose-runtime/payload/vendor/dsh/LICENSE-session +21 -0
  28. package/bin/compose-runtime/payload/vendor/dsh/LICENSE-system-prompt +21 -0
  29. package/bin/compose-runtime/payload/vendor/dsh/LICENSE-timeout +21 -0
  30. package/bin/compose-runtime/payload/vendor/dsh/LICENSE-timer +21 -0
  31. package/bin/compose-runtime/payload/vendor/dsh/LICENSE-tool-todo +21 -0
  32. package/bin/compose-runtime/payload/vendor/dsh/LICENSE-tool-web +21 -0
  33. package/bin/compose-runtime/payload/vendor/dsh/LICENSE-tools-schema +21 -0
  34. package/bin/compose-runtime/payload/vendor/dsh/LICENSE-web-search-exa +21 -0
  35. package/bin/compose-runtime/payload/vendor/dsh/agent-loop.js +1193 -0
  36. package/bin/compose-runtime/payload/vendor/dsh/agent.js +714 -0
  37. package/bin/compose-runtime/payload/vendor/dsh/llm-core.js +269 -0
  38. package/bin/compose-runtime/payload/vendor/dsh/llm-deepseek.js +672 -0
  39. package/bin/compose-runtime/payload/vendor/dsh/logger-console.js +83 -0
  40. package/bin/compose-runtime/payload/vendor/dsh/scope.js +287 -0
  41. package/bin/compose-runtime/payload/vendor/dsh/session.js +1668 -0
  42. package/bin/compose-runtime/payload/vendor/dsh/system-prompt.js +309 -0
  43. package/bin/compose-runtime/payload/vendor/dsh/timeout.js +100 -0
  44. package/bin/compose-runtime/payload/vendor/dsh/timer.js +128 -0
  45. package/bin/compose-runtime/payload/vendor/dsh/tool-todo.js +143 -0
  46. package/bin/compose-runtime/payload/vendor/dsh/tool-web.js +1527 -0
  47. package/bin/compose-runtime/payload/vendor/dsh/tools-schema.js +849 -0
  48. package/bin/compose-runtime/payload/vendor/dsh/web-search-exa.js +122 -0
  49. package/bin/compose-runtime/payload/vendor/eventsource-parser/LICENSE +21 -0
  50. package/bin/compose-runtime/payload/vendor/eventsource-parser/index.js +177 -0
  51. package/bin/compose-runtime/payload/vendor/eventsource-parser/stream.js +48 -0
  52. package/bin/compose-runtime/payload/vendor/schemastery/index.mjs +656 -0
  53. package/bin/compose-runtime/payload-manifests.json +48 -0
  54. package/bin/compose-runtime/src/bridge.mjs +142 -0
  55. package/bin/compose-runtime/src/credentials-runtime.mjs +50 -0
  56. package/bin/compose-runtime/src/eventsource-stream.mjs +48 -0
  57. package/bin/compose-runtime/src/index.mjs +7 -0
  58. package/bin/compose-runtime/src/llm-runtime.mjs +326 -0
  59. package/bin/compose-runtime/src/loader.mjs +78 -0
  60. package/bin/compose-runtime/src/loop-assembly.mjs +237 -0
  61. package/bin/compose-runtime/src/payload.mjs +49 -0
  62. package/bin/compose-runtime/src/plugin.mjs +59 -0
  63. package/bin/compose-runtime/src/realm.mjs +223 -0
  64. package/bin/compose-runtime/src/registry.mjs +191 -0
  65. package/bin/compose-runtime/src/resolve.mjs +115 -0
  66. package/bin/compose-runtime/src/systemprompt-runtime.mjs +67 -0
  67. package/bin/compose-runtime/src/tools-runtime.mjs +239 -0
  68. package/bin/compose-runtime/src/web-runtime.mjs +209 -0
  69. package/bin/plugin-host/package.json +11 -0
  70. package/bin/plugin-host/src/bridge.mjs +64 -0
  71. package/bin/plugin-host/src/cli.mjs +105 -0
  72. package/bin/plugin-host/src/framing.mjs +113 -0
  73. package/bin/plugin-host/src/host.mjs +624 -0
  74. package/bin/plugin-host/src/json.mjs +196 -0
  75. package/bin/plugin-host/src/lifecycle.mjs +114 -0
  76. package/bin/plugin-host/src/loader.mjs +142 -0
  77. package/bin/plugin-host/src/methods.mjs +256 -0
  78. package/bin/plugin-host/src/protocol.mjs +129 -0
  79. package/bin/plugin-host/src/sdk.mjs +7 -0
  80. package/bin/rebon +0 -0
  81. package/bin/rebon-boa-helper +0 -0
  82. package/package.json +4 -1
@@ -0,0 +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
+ };
@@ -0,0 +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.
@@ -0,0 +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
+
@@ -0,0 +1,48 @@
1
+ // Mini-streams-protocol build of `eventsource-parser/stream`.
2
+ //
3
+ // The published package's EventSourceParserStream extends the WHATWG
4
+ // TransformStream, which bare deno_core does not have. Kernel JS hosts use
5
+ // the Mini streams protocol instead (see js/web.js): a transform is any
6
+ // object with `transformIterable(source) -> asyncIterable`. Parsing itself
7
+ // is the vendored upstream `createParser` (js/vendor/eventsource-parser/
8
+ // index.js), so framing semantics — chunk reassembly, CRLF/BOM, comment
9
+ // skipping, multi-`data:` joining — are byte-identical to the real package.
10
+ // Error semantics mirror upstream: a parse error reaches `onError` when one
11
+ // is supplied, and only `onError: 'terminate'` or a max-buffer-size
12
+ // overflow aborts the stream.
13
+ import { createParser } from './index.js';
14
+
15
+ export { ParseError } from './index.js';
16
+
17
+ export class EventSourceParserStream {
18
+ constructor({ onError, onRetry, onComment, maxBufferSize } = {}) {
19
+ this._options = { onError, onRetry, onComment, maxBufferSize };
20
+ }
21
+
22
+ transformIterable(source) {
23
+ const { onError, onRetry, onComment, maxBufferSize } = this._options;
24
+ return (async function* () {
25
+ const queue = [];
26
+ let terminal;
27
+ const parser = createParser({
28
+ onEvent: (event) => {
29
+ queue.push(event);
30
+ },
31
+ onError(error) {
32
+ if (typeof onError === 'function') onError(error);
33
+ if (onError === 'terminate' || error.type === 'max-buffer-size-exceeded') {
34
+ terminal = error;
35
+ }
36
+ },
37
+ onRetry,
38
+ onComment,
39
+ maxBufferSize,
40
+ });
41
+ for await (const chunk of source) {
42
+ parser.feed(chunk);
43
+ while (queue.length > 0) yield queue.shift();
44
+ if (terminal !== undefined) throw terminal;
45
+ }
46
+ })();
47
+ }
48
+ }