@kortyx/stream 0.3.0 → 0.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 (34) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/{types/stream-chunk.d.ts → browser-BIAzFI3U.d.ts} +148 -6
  3. package/dist/browser.d.ts +2 -5
  4. package/dist/browser.js +100 -7
  5. package/dist/browser.js.map +1 -0
  6. package/dist/index.d.ts +17 -5
  7. package/dist/index.js +289 -18
  8. package/dist/index.js.map +1 -0
  9. package/package.json +6 -5
  10. package/dist/browser.d.ts.map +0 -1
  11. package/dist/client/read-stream.d.ts +0 -3
  12. package/dist/client/read-stream.d.ts.map +0 -1
  13. package/dist/client/read-stream.js +0 -32
  14. package/dist/client/stream-from-route.d.ts +0 -10
  15. package/dist/client/stream-from-route.d.ts.map +0 -1
  16. package/dist/client/stream-from-route.js +0 -49
  17. package/dist/index.d.ts.map +0 -1
  18. package/dist/server/create-stream-response.d.ts +0 -9
  19. package/dist/server/create-stream-response.d.ts.map +0 -1
  20. package/dist/server/create-stream-response.js +0 -45
  21. package/dist/server/json-to-sse.d.ts +0 -4
  22. package/dist/server/json-to-sse.d.ts.map +0 -1
  23. package/dist/server/json-to-sse.js +0 -16
  24. package/dist/types/stream-chunk.d.ts.map +0 -1
  25. package/dist/types/stream-chunk.js +0 -74
  26. package/dist/types/stream-result.d.ts +0 -465
  27. package/dist/types/stream-result.d.ts.map +0 -1
  28. package/dist/types/stream-result.js +0 -18
  29. package/dist/types/structured-data/index.d.ts +0 -76
  30. package/dist/types/structured-data/index.d.ts.map +0 -1
  31. package/dist/types/structured-data/index.js +0 -13
  32. package/dist/types/structured-data/jobs.d.ts +0 -43
  33. package/dist/types/structured-data/jobs.d.ts.map +0 -1
  34. package/dist/types/structured-data/jobs.js +0 -14
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @chatbot-core/types
2
2
 
3
+ ## [0.4.0](https://github.com/kortyx-io/kortyx/compare/stream-v0.3.1...stream-v0.4.0) (2026-02-17)
4
+
5
+
6
+ ### Features
7
+
8
+ * **hooks:** consolidate reason+interrupt contracts ([4716a4d](https://github.com/kortyx-io/kortyx/commit/4716a4d4739b4a71b7c6e84717c830cd9ff625a6))
9
+
10
+ ## [0.3.1](https://github.com/kortyx-io/kortyx/compare/stream-v0.3.0...stream-v0.3.1) (2026-02-17)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **build:** align package tsconfig with shared lib baseline ([48d2b57](https://github.com/kortyx-io/kortyx/commit/48d2b5765fefbb5fcbbe548e749e7b5f51b450b9))
16
+ * **build:** wire tsup for publishable packages ([e7b1b5c](https://github.com/kortyx-io/kortyx/commit/e7b1b5c28af55becffc137233dd92d8953d7cb8e))
17
+ * **dev:** restore tsc watch flow for local workspace ([4305823](https://github.com/kortyx-io/kortyx/commit/430582372cad466bf28af554042aa11bdb8bf027))
18
+
3
19
  ## [0.3.0](https://github.com/kortyx-io/kortyx/compare/stream-v0.2.3...stream-v0.3.0) (2026-02-17)
4
20
 
5
21
 
@@ -1,5 +1,6 @@
1
- import { z } from "zod";
2
- export declare const StreamChunkSchema: z.ZodUnion<[z.ZodObject<{
1
+ import { z } from 'zod';
2
+
3
+ declare const StreamChunkSchema: z.ZodUnion<[z.ZodObject<{
3
4
  type: z.ZodLiteral<"session">;
4
5
  sessionId: z.ZodString;
5
6
  }, "strip", z.ZodTypeAny, {
@@ -35,33 +36,60 @@ export declare const StreamChunkSchema: z.ZodUnion<[z.ZodObject<{
35
36
  }>, z.ZodObject<{
36
37
  type: z.ZodLiteral<"text-start">;
37
38
  node: z.ZodOptional<z.ZodString>;
39
+ id: z.ZodOptional<z.ZodString>;
40
+ opId: z.ZodOptional<z.ZodString>;
41
+ segmentId: z.ZodOptional<z.ZodString>;
38
42
  }, "strip", z.ZodTypeAny, {
39
43
  type?: "text-start";
44
+ id?: string;
45
+ opId?: string;
40
46
  node?: string;
47
+ segmentId?: string;
41
48
  }, {
42
49
  type?: "text-start";
50
+ id?: string;
51
+ opId?: string;
43
52
  node?: string;
53
+ segmentId?: string;
44
54
  }>, z.ZodObject<{
45
55
  type: z.ZodLiteral<"text-delta">;
46
56
  delta: z.ZodString;
47
57
  node: z.ZodOptional<z.ZodString>;
58
+ id: z.ZodOptional<z.ZodString>;
59
+ opId: z.ZodOptional<z.ZodString>;
60
+ segmentId: z.ZodOptional<z.ZodString>;
48
61
  }, "strip", z.ZodTypeAny, {
49
62
  type?: "text-delta";
63
+ id?: string;
64
+ opId?: string;
50
65
  node?: string;
66
+ segmentId?: string;
51
67
  delta?: string;
52
68
  }, {
53
69
  type?: "text-delta";
70
+ id?: string;
71
+ opId?: string;
54
72
  node?: string;
73
+ segmentId?: string;
55
74
  delta?: string;
56
75
  }>, z.ZodObject<{
57
76
  type: z.ZodLiteral<"text-end">;
58
77
  node: z.ZodOptional<z.ZodString>;
78
+ id: z.ZodOptional<z.ZodString>;
79
+ opId: z.ZodOptional<z.ZodString>;
80
+ segmentId: z.ZodOptional<z.ZodString>;
59
81
  }, "strip", z.ZodTypeAny, {
60
82
  type?: "text-end";
83
+ id?: string;
84
+ opId?: string;
61
85
  node?: string;
86
+ segmentId?: string;
62
87
  }, {
63
88
  type?: "text-end";
89
+ id?: string;
90
+ opId?: string;
64
91
  node?: string;
92
+ segmentId?: string;
65
93
  }>, z.ZodObject<{
66
94
  type: z.ZodLiteral<"tool-result">;
67
95
  tool: z.ZodOptional<z.ZodString>;
@@ -83,25 +111,45 @@ export declare const StreamChunkSchema: z.ZodUnion<[z.ZodObject<{
83
111
  resumeToken: z.ZodString;
84
112
  workflow: z.ZodOptional<z.ZodString>;
85
113
  node: z.ZodOptional<z.ZodString>;
114
+ id: z.ZodOptional<z.ZodString>;
115
+ opId: z.ZodOptional<z.ZodString>;
116
+ schemaId: z.ZodOptional<z.ZodString>;
117
+ schemaVersion: z.ZodOptional<z.ZodString>;
86
118
  input: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
87
119
  kind: z.ZodLiteral<"text">;
88
120
  multiple: z.ZodBoolean;
89
121
  question: z.ZodOptional<z.ZodString>;
122
+ id: z.ZodOptional<z.ZodString>;
123
+ schemaId: z.ZodOptional<z.ZodString>;
124
+ schemaVersion: z.ZodOptional<z.ZodString>;
125
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
90
126
  options: z.ZodOptional<z.ZodArray<z.ZodNever, "many">>;
91
127
  }, "strip", z.ZodTypeAny, {
92
128
  options?: never[];
129
+ id?: string;
130
+ schemaId?: string;
131
+ schemaVersion?: string;
93
132
  kind?: "text";
94
133
  multiple?: boolean;
95
134
  question?: string;
135
+ meta?: Record<string, unknown>;
96
136
  }, {
97
137
  options?: never[];
138
+ id?: string;
139
+ schemaId?: string;
140
+ schemaVersion?: string;
98
141
  kind?: "text";
99
142
  multiple?: boolean;
100
143
  question?: string;
144
+ meta?: Record<string, unknown>;
101
145
  }>, z.ZodObject<{
102
146
  kind: z.ZodEnum<["choice", "multi-choice"]>;
103
147
  multiple: z.ZodBoolean;
104
148
  question: z.ZodString;
149
+ id: z.ZodOptional<z.ZodString>;
150
+ schemaId: z.ZodOptional<z.ZodString>;
151
+ schemaVersion: z.ZodOptional<z.ZodString>;
152
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
105
153
  options: z.ZodArray<z.ZodObject<{
106
154
  id: z.ZodString;
107
155
  label: z.ZodString;
@@ -121,68 +169,106 @@ export declare const StreamChunkSchema: z.ZodUnion<[z.ZodObject<{
121
169
  label?: string;
122
170
  description?: string;
123
171
  }[];
172
+ id?: string;
173
+ schemaId?: string;
174
+ schemaVersion?: string;
124
175
  kind?: "choice" | "multi-choice";
125
176
  multiple?: boolean;
126
177
  question?: string;
178
+ meta?: Record<string, unknown>;
127
179
  }, {
128
180
  options?: {
129
181
  id?: string;
130
182
  label?: string;
131
183
  description?: string;
132
184
  }[];
185
+ id?: string;
186
+ schemaId?: string;
187
+ schemaVersion?: string;
133
188
  kind?: "choice" | "multi-choice";
134
189
  multiple?: boolean;
135
190
  question?: string;
191
+ meta?: Record<string, unknown>;
136
192
  }>]>;
137
193
  meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
138
194
  }, "strip", z.ZodTypeAny, {
139
195
  type?: "interrupt";
196
+ id?: string;
197
+ schemaId?: string;
198
+ schemaVersion?: string;
199
+ opId?: string;
140
200
  node?: string;
141
201
  requestId?: string;
142
202
  resumeToken?: string;
143
203
  workflow?: string;
144
204
  input?: {
145
205
  options?: never[];
206
+ id?: string;
207
+ schemaId?: string;
208
+ schemaVersion?: string;
146
209
  kind?: "text";
147
210
  multiple?: boolean;
148
211
  question?: string;
212
+ meta?: Record<string, unknown>;
149
213
  } | {
150
214
  options?: {
151
215
  id?: string;
152
216
  label?: string;
153
217
  description?: string;
154
218
  }[];
219
+ id?: string;
220
+ schemaId?: string;
221
+ schemaVersion?: string;
155
222
  kind?: "choice" | "multi-choice";
156
223
  multiple?: boolean;
157
224
  question?: string;
225
+ meta?: Record<string, unknown>;
158
226
  };
159
227
  meta?: Record<string, unknown>;
160
228
  }, {
161
229
  type?: "interrupt";
230
+ id?: string;
231
+ schemaId?: string;
232
+ schemaVersion?: string;
233
+ opId?: string;
162
234
  node?: string;
163
235
  requestId?: string;
164
236
  resumeToken?: string;
165
237
  workflow?: string;
166
238
  input?: {
167
239
  options?: never[];
240
+ id?: string;
241
+ schemaId?: string;
242
+ schemaVersion?: string;
168
243
  kind?: "text";
169
244
  multiple?: boolean;
170
245
  question?: string;
246
+ meta?: Record<string, unknown>;
171
247
  } | {
172
248
  options?: {
173
249
  id?: string;
174
250
  label?: string;
175
251
  description?: string;
176
252
  }[];
253
+ id?: string;
254
+ schemaId?: string;
255
+ schemaVersion?: string;
177
256
  kind?: "choice" | "multi-choice";
178
257
  multiple?: boolean;
179
258
  question?: string;
259
+ meta?: Record<string, unknown>;
180
260
  };
181
261
  meta?: Record<string, unknown>;
182
- }>, z.ZodDiscriminatedUnion<"dataType", [z.ZodObject<{
262
+ }>, z.ZodUnion<[z.ZodObject<{
183
263
  type: z.ZodLiteral<"structured-data">;
184
- dataType: z.ZodLiteral<"jobs">;
264
+ mode: z.ZodOptional<z.ZodEnum<["final", "patch", "snapshot"]>>;
265
+ schemaId: z.ZodOptional<z.ZodString>;
266
+ schemaVersion: z.ZodOptional<z.ZodString>;
267
+ id: z.ZodOptional<z.ZodString>;
268
+ opId: z.ZodOptional<z.ZodString>;
185
269
  node: z.ZodOptional<z.ZodString>;
270
+ } & {
271
+ dataType: z.ZodLiteral<"jobs">;
186
272
  data: z.ZodObject<{
187
273
  jobs: z.ZodArray<z.ZodObject<{
188
274
  id: z.ZodString;
@@ -225,7 +311,12 @@ export declare const StreamChunkSchema: z.ZodUnion<[z.ZodObject<{
225
311
  }>;
226
312
  }, "strip", z.ZodTypeAny, {
227
313
  type?: "structured-data";
314
+ id?: string;
228
315
  dataType?: "jobs";
316
+ mode?: "final" | "patch" | "snapshot";
317
+ schemaId?: string;
318
+ schemaVersion?: string;
319
+ opId?: string;
229
320
  node?: string;
230
321
  data?: {
231
322
  jobs?: {
@@ -239,7 +330,12 @@ export declare const StreamChunkSchema: z.ZodUnion<[z.ZodObject<{
239
330
  };
240
331
  }, {
241
332
  type?: "structured-data";
333
+ id?: string;
242
334
  dataType?: "jobs";
335
+ mode?: "final" | "patch" | "snapshot";
336
+ schemaId?: string;
337
+ schemaVersion?: string;
338
+ opId?: string;
243
339
  node?: string;
244
340
  data?: {
245
341
  jobs?: {
@@ -251,6 +347,37 @@ export declare const StreamChunkSchema: z.ZodUnion<[z.ZodObject<{
251
347
  }[];
252
348
  reasoning?: string;
253
349
  };
350
+ }>, z.ZodObject<{
351
+ type: z.ZodLiteral<"structured-data">;
352
+ dataType: z.ZodOptional<z.ZodString>;
353
+ mode: z.ZodOptional<z.ZodEnum<["final", "patch", "snapshot"]>>;
354
+ schemaId: z.ZodOptional<z.ZodString>;
355
+ schemaVersion: z.ZodOptional<z.ZodString>;
356
+ id: z.ZodOptional<z.ZodString>;
357
+ opId: z.ZodOptional<z.ZodString>;
358
+ node: z.ZodOptional<z.ZodString>;
359
+ } & {
360
+ data: z.ZodUnknown;
361
+ }, "strip", z.ZodTypeAny, {
362
+ type?: "structured-data";
363
+ id?: string;
364
+ dataType?: string;
365
+ mode?: "final" | "patch" | "snapshot";
366
+ schemaId?: string;
367
+ schemaVersion?: string;
368
+ opId?: string;
369
+ node?: string;
370
+ data?: unknown;
371
+ }, {
372
+ type?: "structured-data";
373
+ id?: string;
374
+ dataType?: string;
375
+ mode?: "final" | "patch" | "snapshot";
376
+ schemaId?: string;
377
+ schemaVersion?: string;
378
+ opId?: string;
379
+ node?: string;
380
+ data?: unknown;
254
381
  }>]>, z.ZodObject<{
255
382
  type: z.ZodLiteral<"transition">;
256
383
  transitionTo: z.ZodString;
@@ -282,5 +409,20 @@ export declare const StreamChunkSchema: z.ZodUnion<[z.ZodObject<{
282
409
  message?: string;
283
410
  type?: "error";
284
411
  }>]>;
285
- export type StreamChunk = z.infer<typeof StreamChunkSchema>;
286
- //# sourceMappingURL=stream-chunk.d.ts.map
412
+ type StreamChunk = z.infer<typeof StreamChunkSchema>;
413
+
414
+ /**
415
+ * Reads a server-sent event (SSE) Response body and yields StreamChunk objects.
416
+ */
417
+ declare function readStream(body: ReadableStream<Uint8Array> | null): AsyncGenerator<StreamChunk, void, void>;
418
+
419
+ interface StreamFromRouteArgs<TBody = unknown> {
420
+ endpoint: string;
421
+ body: TBody;
422
+ method?: string | undefined;
423
+ fetchImpl?: typeof fetch;
424
+ headers?: Record<string, string> | undefined;
425
+ }
426
+ declare function streamFromRoute<TBody = unknown>(args: StreamFromRouteArgs<TBody>): AsyncGenerator<StreamChunk, void, void>;
427
+
428
+ export { type StreamChunk as S, StreamChunkSchema as a, type StreamFromRouteArgs as b, readStream as r, streamFromRoute as s };
package/dist/browser.d.ts CHANGED
@@ -1,5 +1,2 @@
1
- export { readStream } from "./client/read-stream";
2
- export type { StreamFromRouteArgs } from "./client/stream-from-route";
3
- export { streamFromRoute } from "./client/stream-from-route";
4
- export type { StreamChunk } from "./types/stream-chunk";
5
- //# sourceMappingURL=browser.d.ts.map
1
+ export { S as StreamChunk, b as StreamFromRouteArgs, r as readStream, s as streamFromRoute } from './browser-BIAzFI3U.js';
2
+ import 'zod';
package/dist/browser.js CHANGED
@@ -1,7 +1,100 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.streamFromRoute = exports.readStream = void 0;
4
- var read_stream_1 = require("./client/read-stream");
5
- Object.defineProperty(exports, "readStream", { enumerable: true, get: function () { return read_stream_1.readStream; } });
6
- var stream_from_route_1 = require("./client/stream-from-route");
7
- Object.defineProperty(exports, "streamFromRoute", { enumerable: true, get: function () { return stream_from_route_1.streamFromRoute; } });
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/browser.ts
20
+ var browser_exports = {};
21
+ __export(browser_exports, {
22
+ readStream: () => readStream,
23
+ streamFromRoute: () => streamFromRoute
24
+ });
25
+ module.exports = __toCommonJS(browser_exports);
26
+
27
+ // src/client/read-stream.ts
28
+ async function* readStream(body) {
29
+ if (!body) return;
30
+ const reader = body.getReader();
31
+ const decoder = new TextDecoder("utf-8");
32
+ let buffer = "";
33
+ while (true) {
34
+ const { done, value } = await reader.read();
35
+ if (done) break;
36
+ buffer += decoder.decode(value, { stream: true });
37
+ const parts = buffer.split("\n\n");
38
+ buffer = parts.pop() ?? "";
39
+ for (const part of parts) {
40
+ if (!part.startsWith("data: ")) continue;
41
+ const payload = part.slice(6);
42
+ if (payload.trim() === "[DONE]") return;
43
+ try {
44
+ yield JSON.parse(payload);
45
+ } catch (err) {
46
+ console.warn("Invalid JSON in stream chunk:", payload);
47
+ console.error(err);
48
+ }
49
+ }
50
+ }
51
+ }
52
+
53
+ // src/client/stream-from-route.ts
54
+ var toErrorMessage = (error) => error instanceof Error ? error.message : String(error);
55
+ var readErrorMessage = async (response) => {
56
+ let message = `Request failed (${response.status})`;
57
+ try {
58
+ const payload = await response.json();
59
+ if (payload && typeof payload === "object" && "error" in payload && typeof payload.error === "string") {
60
+ message = payload.error;
61
+ }
62
+ } catch {
63
+ }
64
+ return message;
65
+ };
66
+ async function* streamFromRoute(args) {
67
+ const fetchFn = args.fetchImpl ?? globalThis.fetch;
68
+ if (!fetchFn) {
69
+ yield { type: "error", message: "No fetch implementation available." };
70
+ yield { type: "done" };
71
+ return;
72
+ }
73
+ let response;
74
+ try {
75
+ response = await fetchFn(args.endpoint, {
76
+ method: args.method ?? "POST",
77
+ headers: {
78
+ "content-type": "application/json",
79
+ ...args.headers ?? {}
80
+ },
81
+ body: JSON.stringify(args.body)
82
+ });
83
+ } catch (error) {
84
+ yield { type: "error", message: toErrorMessage(error) };
85
+ yield { type: "done" };
86
+ return;
87
+ }
88
+ if (!response.ok) {
89
+ yield { type: "error", message: await readErrorMessage(response) };
90
+ yield { type: "done" };
91
+ return;
92
+ }
93
+ yield* readStream(response.body);
94
+ }
95
+ // Annotate the CommonJS export names for ESM import in node:
96
+ 0 && (module.exports = {
97
+ readStream,
98
+ streamFromRoute
99
+ });
100
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/browser.ts","../src/client/read-stream.ts","../src/client/stream-from-route.ts"],"sourcesContent":["// Browser-safe exports for client bundles.\n// Keep this file free of Node-only imports (fs, path, etc).\n\nexport { readStream } from \"./client/read-stream\";\nexport type { StreamFromRouteArgs } from \"./client/stream-from-route\";\nexport { streamFromRoute } from \"./client/stream-from-route\";\nexport type { StreamChunk } from \"./types/stream-chunk\";\n","// packages/stream/src/client/read-stream.ts\nimport type { StreamChunk } from \"../types/stream-chunk\";\n\n/**\n * Reads a server-sent event (SSE) Response body and yields StreamChunk objects.\n */\nexport async function* readStream(\n body: ReadableStream<Uint8Array> | null,\n): AsyncGenerator<StreamChunk, void, void> {\n if (!body) return;\n\n const reader = body.getReader();\n const decoder = new TextDecoder(\"utf-8\");\n let buffer = \"\";\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const parts = buffer.split(\"\\n\\n\");\n buffer = parts.pop() ?? \"\";\n\n for (const part of parts) {\n if (!part.startsWith(\"data: \")) continue;\n const payload = part.slice(6);\n if (payload.trim() === \"[DONE]\") return;\n try {\n yield JSON.parse(payload) as StreamChunk;\n } catch (err: any) {\n console.warn(\"Invalid JSON in stream chunk:\", payload);\n console.error(err);\n }\n }\n }\n}\n","import type { StreamChunk } from \"../types/stream-chunk\";\nimport { readStream } from \"./read-stream\";\n\nexport interface StreamFromRouteArgs<TBody = unknown> {\n endpoint: string;\n body: TBody;\n method?: string | undefined;\n fetchImpl?: typeof fetch;\n headers?: Record<string, string> | undefined;\n}\n\nconst toErrorMessage = (error: unknown): string =>\n error instanceof Error ? error.message : String(error);\n\nconst readErrorMessage = async (response: Response): Promise<string> => {\n let message = `Request failed (${response.status})`;\n try {\n const payload = (await response.json()) as unknown;\n if (\n payload &&\n typeof payload === \"object\" &&\n \"error\" in payload &&\n typeof (payload as { error?: unknown }).error === \"string\"\n ) {\n message = (payload as { error: string }).error;\n }\n } catch {}\n return message;\n};\n\nexport async function* streamFromRoute<TBody = unknown>(\n args: StreamFromRouteArgs<TBody>,\n): AsyncGenerator<StreamChunk, void, void> {\n const fetchFn = args.fetchImpl ?? globalThis.fetch;\n if (!fetchFn) {\n yield { type: \"error\", message: \"No fetch implementation available.\" };\n yield { type: \"done\" };\n return;\n }\n\n let response: Response;\n try {\n response = await fetchFn(args.endpoint, {\n method: args.method ?? \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n ...(args.headers ?? {}),\n },\n body: JSON.stringify(args.body),\n });\n } catch (error) {\n yield { type: \"error\", message: toErrorMessage(error) };\n yield { type: \"done\" };\n return;\n }\n\n if (!response.ok) {\n yield { type: \"error\", message: await readErrorMessage(response) };\n yield { type: \"done\" };\n return;\n }\n\n yield* readStream(response.body);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,gBAAuB,WACrB,MACyC;AACzC,MAAI,CAAC,KAAM;AAEX,QAAM,SAAS,KAAK,UAAU;AAC9B,QAAM,UAAU,IAAI,YAAY,OAAO;AACvC,MAAI,SAAS;AAEb,SAAO,MAAM;AACX,UAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,QAAI,KAAM;AAEV,cAAU,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;AAChD,UAAM,QAAQ,OAAO,MAAM,MAAM;AACjC,aAAS,MAAM,IAAI,KAAK;AAExB,eAAW,QAAQ,OAAO;AACxB,UAAI,CAAC,KAAK,WAAW,QAAQ,EAAG;AAChC,YAAM,UAAU,KAAK,MAAM,CAAC;AAC5B,UAAI,QAAQ,KAAK,MAAM,SAAU;AACjC,UAAI;AACF,cAAM,KAAK,MAAM,OAAO;AAAA,MAC1B,SAAS,KAAU;AACjB,gBAAQ,KAAK,iCAAiC,OAAO;AACrD,gBAAQ,MAAM,GAAG;AAAA,MACnB;AAAA,IACF;AAAA,EACF;AACF;;;ACxBA,IAAM,iBAAiB,CAAC,UACtB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAEvD,IAAM,mBAAmB,OAAO,aAAwC;AACtE,MAAI,UAAU,mBAAmB,SAAS,MAAM;AAChD,MAAI;AACF,UAAM,UAAW,MAAM,SAAS,KAAK;AACrC,QACE,WACA,OAAO,YAAY,YACnB,WAAW,WACX,OAAQ,QAAgC,UAAU,UAClD;AACA,gBAAW,QAA8B;AAAA,IAC3C;AAAA,EACF,QAAQ;AAAA,EAAC;AACT,SAAO;AACT;AAEA,gBAAuB,gBACrB,MACyC;AACzC,QAAM,UAAU,KAAK,aAAa,WAAW;AAC7C,MAAI,CAAC,SAAS;AACZ,UAAM,EAAE,MAAM,SAAS,SAAS,qCAAqC;AACrE,UAAM,EAAE,MAAM,OAAO;AACrB;AAAA,EACF;AAEA,MAAI;AACJ,MAAI;AACF,eAAW,MAAM,QAAQ,KAAK,UAAU;AAAA,MACtC,QAAQ,KAAK,UAAU;AAAA,MACvB,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,GAAI,KAAK,WAAW,CAAC;AAAA,MACvB;AAAA,MACA,MAAM,KAAK,UAAU,KAAK,IAAI;AAAA,IAChC,CAAC;AAAA,EACH,SAAS,OAAO;AACd,UAAM,EAAE,MAAM,SAAS,SAAS,eAAe,KAAK,EAAE;AACtD,UAAM,EAAE,MAAM,OAAO;AACrB;AAAA,EACF;AAEA,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,EAAE,MAAM,SAAS,SAAS,MAAM,iBAAiB,QAAQ,EAAE;AACjE,UAAM,EAAE,MAAM,OAAO;AACrB;AAAA,EACF;AAEA,SAAO,WAAW,SAAS,IAAI;AACjC;","names":[]}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,17 @@
1
- export * from "./client/read-stream";
2
- export * from "./client/stream-from-route";
3
- export * from "./server/create-stream-response";
4
- export * from "./types/stream-chunk";
5
- //# sourceMappingURL=index.d.ts.map
1
+ import { S as StreamChunk } from './browser-BIAzFI3U.js';
2
+ export { a as StreamChunkSchema, b as StreamFromRouteArgs, r as readStream, s as streamFromRoute } from './browser-BIAzFI3U.js';
3
+ import 'zod';
4
+
5
+ declare const STREAM_HEADERS: {
6
+ "content-type": string;
7
+ "cache-control": string;
8
+ connection: string;
9
+ "x-accel-buffering": string;
10
+ };
11
+ /**
12
+ * Turns an AsyncIterable<StreamChunk> into a streamed HTTP Response.
13
+ * Works in Node, Bun, Cloudflare, Edge, etc.
14
+ */
15
+ declare function createStreamResponse(stream: AsyncIterable<StreamChunk>): Response;
16
+
17
+ export { STREAM_HEADERS, StreamChunk, createStreamResponse };