@kortyx/stream 0.3.1 → 0.4.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @chatbot-core/types
2
2
 
3
+ ## [0.4.1](https://github.com/kortyx-io/kortyx/compare/stream-v0.4.0...stream-v0.4.1) (2026-02-17)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **release:** publish packages with pnpm and public access ([357e268](https://github.com/kortyx-io/kortyx/commit/357e2680469e729ea58d103915989142f668a39a))
9
+ * **release:** publish packages with pnpm and public access ([5ef7498](https://github.com/kortyx-io/kortyx/commit/5ef7498330129f376ca7197b70cb7b6a38138e8a))
10
+
11
+ ## [0.4.0](https://github.com/kortyx-io/kortyx/compare/stream-v0.3.1...stream-v0.4.0) (2026-02-17)
12
+
13
+
14
+ ### Features
15
+
16
+ * **hooks:** consolidate reason+interrupt contracts ([4716a4d](https://github.com/kortyx-io/kortyx/commit/4716a4d4739b4a71b7c6e84717c830cd9ff625a6))
17
+
3
18
  ## [0.3.1](https://github.com/kortyx-io/kortyx/compare/stream-v0.3.0...stream-v0.3.1) (2026-02-17)
4
19
 
5
20
 
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -36,33 +36,60 @@ declare const StreamChunkSchema: z.ZodUnion<[z.ZodObject<{
36
36
  }>, z.ZodObject<{
37
37
  type: z.ZodLiteral<"text-start">;
38
38
  node: z.ZodOptional<z.ZodString>;
39
+ id: z.ZodOptional<z.ZodString>;
40
+ opId: z.ZodOptional<z.ZodString>;
41
+ segmentId: z.ZodOptional<z.ZodString>;
39
42
  }, "strip", z.ZodTypeAny, {
40
43
  type?: "text-start";
44
+ id?: string;
45
+ opId?: string;
41
46
  node?: string;
47
+ segmentId?: string;
42
48
  }, {
43
49
  type?: "text-start";
50
+ id?: string;
51
+ opId?: string;
44
52
  node?: string;
53
+ segmentId?: string;
45
54
  }>, z.ZodObject<{
46
55
  type: z.ZodLiteral<"text-delta">;
47
56
  delta: z.ZodString;
48
57
  node: z.ZodOptional<z.ZodString>;
58
+ id: z.ZodOptional<z.ZodString>;
59
+ opId: z.ZodOptional<z.ZodString>;
60
+ segmentId: z.ZodOptional<z.ZodString>;
49
61
  }, "strip", z.ZodTypeAny, {
50
62
  type?: "text-delta";
63
+ id?: string;
64
+ opId?: string;
51
65
  node?: string;
66
+ segmentId?: string;
52
67
  delta?: string;
53
68
  }, {
54
69
  type?: "text-delta";
70
+ id?: string;
71
+ opId?: string;
55
72
  node?: string;
73
+ segmentId?: string;
56
74
  delta?: string;
57
75
  }>, z.ZodObject<{
58
76
  type: z.ZodLiteral<"text-end">;
59
77
  node: z.ZodOptional<z.ZodString>;
78
+ id: z.ZodOptional<z.ZodString>;
79
+ opId: z.ZodOptional<z.ZodString>;
80
+ segmentId: z.ZodOptional<z.ZodString>;
60
81
  }, "strip", z.ZodTypeAny, {
61
82
  type?: "text-end";
83
+ id?: string;
84
+ opId?: string;
62
85
  node?: string;
86
+ segmentId?: string;
63
87
  }, {
64
88
  type?: "text-end";
89
+ id?: string;
90
+ opId?: string;
65
91
  node?: string;
92
+ segmentId?: string;
66
93
  }>, z.ZodObject<{
67
94
  type: z.ZodLiteral<"tool-result">;
68
95
  tool: z.ZodOptional<z.ZodString>;
@@ -84,25 +111,45 @@ declare const StreamChunkSchema: z.ZodUnion<[z.ZodObject<{
84
111
  resumeToken: z.ZodString;
85
112
  workflow: z.ZodOptional<z.ZodString>;
86
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>;
87
118
  input: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
88
119
  kind: z.ZodLiteral<"text">;
89
120
  multiple: z.ZodBoolean;
90
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>>;
91
126
  options: z.ZodOptional<z.ZodArray<z.ZodNever, "many">>;
92
127
  }, "strip", z.ZodTypeAny, {
93
128
  options?: never[];
129
+ id?: string;
130
+ schemaId?: string;
131
+ schemaVersion?: string;
94
132
  kind?: "text";
95
133
  multiple?: boolean;
96
134
  question?: string;
135
+ meta?: Record<string, unknown>;
97
136
  }, {
98
137
  options?: never[];
138
+ id?: string;
139
+ schemaId?: string;
140
+ schemaVersion?: string;
99
141
  kind?: "text";
100
142
  multiple?: boolean;
101
143
  question?: string;
144
+ meta?: Record<string, unknown>;
102
145
  }>, z.ZodObject<{
103
146
  kind: z.ZodEnum<["choice", "multi-choice"]>;
104
147
  multiple: z.ZodBoolean;
105
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>>;
106
153
  options: z.ZodArray<z.ZodObject<{
107
154
  id: z.ZodString;
108
155
  label: z.ZodString;
@@ -122,68 +169,106 @@ declare const StreamChunkSchema: z.ZodUnion<[z.ZodObject<{
122
169
  label?: string;
123
170
  description?: string;
124
171
  }[];
172
+ id?: string;
173
+ schemaId?: string;
174
+ schemaVersion?: string;
125
175
  kind?: "choice" | "multi-choice";
126
176
  multiple?: boolean;
127
177
  question?: string;
178
+ meta?: Record<string, unknown>;
128
179
  }, {
129
180
  options?: {
130
181
  id?: string;
131
182
  label?: string;
132
183
  description?: string;
133
184
  }[];
185
+ id?: string;
186
+ schemaId?: string;
187
+ schemaVersion?: string;
134
188
  kind?: "choice" | "multi-choice";
135
189
  multiple?: boolean;
136
190
  question?: string;
191
+ meta?: Record<string, unknown>;
137
192
  }>]>;
138
193
  meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
139
194
  }, "strip", z.ZodTypeAny, {
140
195
  type?: "interrupt";
196
+ id?: string;
197
+ schemaId?: string;
198
+ schemaVersion?: string;
199
+ opId?: string;
141
200
  node?: string;
142
201
  requestId?: string;
143
202
  resumeToken?: string;
144
203
  workflow?: string;
145
204
  input?: {
146
205
  options?: never[];
206
+ id?: string;
207
+ schemaId?: string;
208
+ schemaVersion?: string;
147
209
  kind?: "text";
148
210
  multiple?: boolean;
149
211
  question?: string;
212
+ meta?: Record<string, unknown>;
150
213
  } | {
151
214
  options?: {
152
215
  id?: string;
153
216
  label?: string;
154
217
  description?: string;
155
218
  }[];
219
+ id?: string;
220
+ schemaId?: string;
221
+ schemaVersion?: string;
156
222
  kind?: "choice" | "multi-choice";
157
223
  multiple?: boolean;
158
224
  question?: string;
225
+ meta?: Record<string, unknown>;
159
226
  };
160
227
  meta?: Record<string, unknown>;
161
228
  }, {
162
229
  type?: "interrupt";
230
+ id?: string;
231
+ schemaId?: string;
232
+ schemaVersion?: string;
233
+ opId?: string;
163
234
  node?: string;
164
235
  requestId?: string;
165
236
  resumeToken?: string;
166
237
  workflow?: string;
167
238
  input?: {
168
239
  options?: never[];
240
+ id?: string;
241
+ schemaId?: string;
242
+ schemaVersion?: string;
169
243
  kind?: "text";
170
244
  multiple?: boolean;
171
245
  question?: string;
246
+ meta?: Record<string, unknown>;
172
247
  } | {
173
248
  options?: {
174
249
  id?: string;
175
250
  label?: string;
176
251
  description?: string;
177
252
  }[];
253
+ id?: string;
254
+ schemaId?: string;
255
+ schemaVersion?: string;
178
256
  kind?: "choice" | "multi-choice";
179
257
  multiple?: boolean;
180
258
  question?: string;
259
+ meta?: Record<string, unknown>;
181
260
  };
182
261
  meta?: Record<string, unknown>;
183
- }>, z.ZodDiscriminatedUnion<"dataType", [z.ZodObject<{
262
+ }>, z.ZodUnion<[z.ZodObject<{
184
263
  type: z.ZodLiteral<"structured-data">;
185
- 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>;
186
269
  node: z.ZodOptional<z.ZodString>;
270
+ } & {
271
+ dataType: z.ZodLiteral<"jobs">;
187
272
  data: z.ZodObject<{
188
273
  jobs: z.ZodArray<z.ZodObject<{
189
274
  id: z.ZodString;
@@ -226,7 +311,12 @@ declare const StreamChunkSchema: z.ZodUnion<[z.ZodObject<{
226
311
  }>;
227
312
  }, "strip", z.ZodTypeAny, {
228
313
  type?: "structured-data";
314
+ id?: string;
229
315
  dataType?: "jobs";
316
+ mode?: "final" | "patch" | "snapshot";
317
+ schemaId?: string;
318
+ schemaVersion?: string;
319
+ opId?: string;
230
320
  node?: string;
231
321
  data?: {
232
322
  jobs?: {
@@ -240,7 +330,12 @@ declare const StreamChunkSchema: z.ZodUnion<[z.ZodObject<{
240
330
  };
241
331
  }, {
242
332
  type?: "structured-data";
333
+ id?: string;
243
334
  dataType?: "jobs";
335
+ mode?: "final" | "patch" | "snapshot";
336
+ schemaId?: string;
337
+ schemaVersion?: string;
338
+ opId?: string;
244
339
  node?: string;
245
340
  data?: {
246
341
  jobs?: {
@@ -252,6 +347,37 @@ declare const StreamChunkSchema: z.ZodUnion<[z.ZodObject<{
252
347
  }[];
253
348
  reasoning?: string;
254
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;
255
381
  }>]>, z.ZodObject<{
256
382
  type: z.ZodLiteral<"transition">;
257
383
  transitionTo: z.ZodString;
package/dist/browser.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { S as StreamChunk, b as StreamFromRouteArgs, r as readStream, s as streamFromRoute } from './browser-2jZhtGOe.js';
1
+ export { S as StreamChunk, b as StreamFromRouteArgs, r as readStream, s as streamFromRoute } from './browser-BIAzFI3U.js';
2
2
  import 'zod';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as StreamChunk } from './browser-2jZhtGOe.js';
2
- export { a as StreamChunkSchema, b as StreamFromRouteArgs, r as readStream, s as streamFromRoute } from './browser-2jZhtGOe.js';
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
3
  import 'zod';
4
4
 
5
5
  declare const STREAM_HEADERS: {
package/dist/index.js CHANGED
@@ -162,20 +162,26 @@ var JobsStructuredData = import_zod.z.object({
162
162
  });
163
163
 
164
164
  // src/types/structured-data/index.ts
165
- var StructuredDataChunkSchema = import_zod2.z.discriminatedUnion("dataType", [
166
- import_zod2.z.object({
167
- type: import_zod2.z.literal("structured-data"),
168
- dataType: import_zod2.z.literal("jobs"),
169
- node: import_zod2.z.string().optional(),
170
- data: JobsStructuredData
171
- })
172
- // Future additions:
173
- // z.object({
174
- // type: z.literal("structured-data"),
175
- // dataType: z.literal("profile"),
176
- // node: z.string().optional(),
177
- // data: ProfileStructuredData,
178
- // }),
165
+ var StructuredDataBase = import_zod2.z.object({
166
+ type: import_zod2.z.literal("structured-data"),
167
+ dataType: import_zod2.z.string().optional(),
168
+ mode: import_zod2.z.enum(["final", "patch", "snapshot"]).optional(),
169
+ schemaId: import_zod2.z.string().optional(),
170
+ schemaVersion: import_zod2.z.string().optional(),
171
+ id: import_zod2.z.string().optional(),
172
+ opId: import_zod2.z.string().optional(),
173
+ node: import_zod2.z.string().optional()
174
+ });
175
+ var JobsStructuredDataChunkSchema = StructuredDataBase.extend({
176
+ dataType: import_zod2.z.literal("jobs"),
177
+ data: JobsStructuredData
178
+ });
179
+ var GenericStructuredDataChunkSchema = StructuredDataBase.extend({
180
+ data: import_zod2.z.unknown()
181
+ });
182
+ var StructuredDataChunkSchema = import_zod2.z.union([
183
+ JobsStructuredDataChunkSchema,
184
+ GenericStructuredDataChunkSchema
179
185
  ]);
180
186
 
181
187
  // src/types/stream-chunk.ts
@@ -196,16 +202,25 @@ var StreamChunkSchema = import_zod3.z.union([
196
202
  }),
197
203
  import_zod3.z.object({
198
204
  type: import_zod3.z.literal("text-start"),
199
- node: import_zod3.z.string().optional()
205
+ node: import_zod3.z.string().optional(),
206
+ id: import_zod3.z.string().optional(),
207
+ opId: import_zod3.z.string().optional(),
208
+ segmentId: import_zod3.z.string().optional()
200
209
  }),
201
210
  import_zod3.z.object({
202
211
  type: import_zod3.z.literal("text-delta"),
203
212
  delta: import_zod3.z.string(),
204
- node: import_zod3.z.string().optional()
213
+ node: import_zod3.z.string().optional(),
214
+ id: import_zod3.z.string().optional(),
215
+ opId: import_zod3.z.string().optional(),
216
+ segmentId: import_zod3.z.string().optional()
205
217
  }),
206
218
  import_zod3.z.object({
207
219
  type: import_zod3.z.literal("text-end"),
208
- node: import_zod3.z.string().optional()
220
+ node: import_zod3.z.string().optional(),
221
+ id: import_zod3.z.string().optional(),
222
+ opId: import_zod3.z.string().optional(),
223
+ segmentId: import_zod3.z.string().optional()
209
224
  }),
210
225
  import_zod3.z.object({
211
226
  type: import_zod3.z.literal("tool-result"),
@@ -220,12 +235,20 @@ var StreamChunkSchema = import_zod3.z.union([
220
235
  resumeToken: import_zod3.z.string(),
221
236
  workflow: import_zod3.z.string().optional(),
222
237
  node: import_zod3.z.string().optional(),
238
+ id: import_zod3.z.string().optional(),
239
+ opId: import_zod3.z.string().optional(),
240
+ schemaId: import_zod3.z.string().optional(),
241
+ schemaVersion: import_zod3.z.string().optional(),
223
242
  input: import_zod3.z.discriminatedUnion("kind", [
224
243
  // Text input: question optional, no options
225
244
  import_zod3.z.object({
226
245
  kind: import_zod3.z.literal("text"),
227
246
  multiple: import_zod3.z.boolean(),
228
247
  question: import_zod3.z.string().optional(),
248
+ id: import_zod3.z.string().optional(),
249
+ schemaId: import_zod3.z.string().optional(),
250
+ schemaVersion: import_zod3.z.string().optional(),
251
+ meta: import_zod3.z.record(import_zod3.z.unknown()).optional(),
229
252
  options: import_zod3.z.array(import_zod3.z.never()).optional()
230
253
  }),
231
254
  // Choice/multi-choice: question + options required
@@ -233,6 +256,10 @@ var StreamChunkSchema = import_zod3.z.union([
233
256
  kind: import_zod3.z.enum(["choice", "multi-choice"]),
234
257
  multiple: import_zod3.z.boolean(),
235
258
  question: import_zod3.z.string(),
259
+ id: import_zod3.z.string().optional(),
260
+ schemaId: import_zod3.z.string().optional(),
261
+ schemaVersion: import_zod3.z.string().optional(),
262
+ meta: import_zod3.z.record(import_zod3.z.unknown()).optional(),
236
263
  options: import_zod3.z.array(
237
264
  import_zod3.z.object({
238
265
  id: import_zod3.z.string(),
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/client/read-stream.ts","../src/client/stream-from-route.ts","../src/server/create-stream-response.ts","../src/types/stream-chunk.ts","../src/types/structured-data/index.ts","../src/types/structured-data/jobs.ts"],"sourcesContent":["// release-test: 2026-01-22\n// packages/stream/src/index.ts\n\n// client\nexport * from \"./client/read-stream\";\nexport * from \"./client/stream-from-route\";\n\n// server\nexport * from \"./server/create-stream-response\";\nexport * 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","// packages/stream/src/server/create-stream-response.ts\nimport type { StreamChunk } from \"../types/stream-chunk\";\n\nexport const STREAM_HEADERS = {\n \"content-type\": \"text/event-stream\",\n \"cache-control\": \"no-cache\",\n connection: \"keep-alive\",\n \"x-accel-buffering\": \"no\",\n};\n\nclass JsonToSseTransformStream extends TransformStream<unknown, string> {\n constructor() {\n super({\n transform(part, controller) {\n controller.enqueue(`data: ${JSON.stringify(part)}\\n\\n`);\n },\n flush(controller) {\n controller.enqueue(\"data: [DONE]\\n\\n\");\n },\n });\n }\n}\n\n/**\n * Turns an AsyncIterable<StreamChunk> into a streamed HTTP Response.\n * Works in Node, Bun, Cloudflare, Edge, etc.\n */\nexport function createStreamResponse(\n stream: AsyncIterable<StreamChunk>,\n): Response {\n const readable = new ReadableStream<StreamChunk>({\n async start(controller) {\n try {\n for await (const chunk of stream) {\n controller.enqueue(chunk);\n }\n } catch (err: any) {\n controller.enqueue({\n type: \"error\",\n message: String(err?.message ?? err),\n } as StreamChunk);\n } finally {\n controller.close();\n }\n },\n });\n\n return new Response(\n readable\n .pipeThrough(new JsonToSseTransformStream())\n .pipeThrough(new TextEncoderStream()),\n { headers: STREAM_HEADERS },\n );\n}\n","import { z } from \"zod\";\nimport { StructuredDataChunkSchema } from \"./structured-data\";\n\nexport const StreamChunkSchema = z.union([\n z.object({\n type: z.literal(\"session\"),\n sessionId: z.string(),\n }),\n z.object({\n type: z.literal(\"status\"),\n message: z.string(),\n node: z.string().optional(),\n }),\n z.object({\n type: z.literal(\"message\"),\n content: z.string(),\n node: z.string().optional(),\n }),\n z.object({\n type: z.literal(\"text-start\"),\n node: z.string().optional(),\n }),\n z.object({\n type: z.literal(\"text-delta\"),\n delta: z.string(),\n node: z.string().optional(),\n }),\n z.object({\n type: z.literal(\"text-end\"),\n node: z.string().optional(),\n }),\n z.object({\n type: z.literal(\"tool-result\"),\n tool: z.string().optional(),\n node: z.string().optional(),\n content: z.unknown(),\n }),\n // Interrupt request chunk (used to render interactive options in UI)\n z.object({\n type: z.literal(\"interrupt\"),\n requestId: z.string(),\n resumeToken: z.string(),\n workflow: z.string().optional(),\n node: z.string().optional(),\n input: z.discriminatedUnion(\"kind\", [\n // Text input: question optional, no options\n z.object({\n kind: z.literal(\"text\"),\n multiple: z.boolean(),\n question: z.string().optional(),\n options: z.array(z.never()).optional(),\n }),\n // Choice/multi-choice: question + options required\n z.object({\n kind: z.enum([\"choice\", \"multi-choice\"]),\n multiple: z.boolean(),\n question: z.string(),\n options: z.array(\n z.object({\n id: z.string(),\n label: z.string(),\n description: z.string().optional(),\n }),\n ),\n }),\n ]),\n meta: z.record(z.unknown()).optional(),\n }),\n StructuredDataChunkSchema,\n z.object({\n type: z.literal(\"transition\"),\n transitionTo: z.string(),\n payload: z.any().optional(),\n }),\n z.object({ type: z.literal(\"done\"), data: z.any().optional() }),\n z.object({ type: z.literal(\"error\"), message: z.string() }),\n]);\n\nexport type StreamChunk = z.infer<typeof StreamChunkSchema>;\n","import { z } from \"zod\";\nimport { JobsStructuredData } from \"./jobs\";\n// import { ProfileStructuredData } from \"./profile\"; // future use\n\n/**\n * Define all known structured data chunk schemas.\n * Each one discriminates on `dataType` so we can infer its shape.\n */\nexport const StructuredDataChunkSchema = z.discriminatedUnion(\"dataType\", [\n z.object({\n type: z.literal(\"structured-data\"),\n dataType: z.literal(\"jobs\"),\n node: z.string().optional(),\n data: JobsStructuredData,\n }),\n\n // Future additions:\n // z.object({\n // type: z.literal(\"structured-data\"),\n // dataType: z.literal(\"profile\"),\n // node: z.string().optional(),\n // data: ProfileStructuredData,\n // }),\n]);\n\nexport type StructuredDataChunk = z.infer<typeof StructuredDataChunkSchema>;\n","import { z } from \"zod\";\n\nexport const JobsStructuredData = z.object({\n jobs: z.array(\n z.object({\n id: z.string(),\n title: z.string(),\n company: z.string(),\n location: z.string(),\n match: z.number(),\n }),\n ),\n reasoning: z.string().optional(),\n});\n\nexport type JobsStructuredData = z.infer<typeof JobsStructuredData>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;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;AA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AU,cAAE,OAAO,EAAE,SAAS;AAAA,IAC9B,MAAM,cAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,OAAO,cAAE,mBAAmB,QAAQ;AAAA;AAAA,MAElC,cAAE,OAAO;AAAA,QACP,MAAM,cAAE,QAAQ,MAAM;AAAA,QACtB,UAAU,cAAE,QAAQ;AAAA,QACpB,UAAU,cAAE,OAAO,EAAE,SAAS;AAAA,QAC9B,SAAS,cAAE,MAAM,cAAE,MAAM,CAAC,EAAE,SAAS;AAAA,MACvC,CAAC;AAAA;AAAA,MAED,cAAE,OAAO;AAAA,QACP,MAAM,cAAE,KAAK,CAAC,UAAU,cAAc,CAAC;AAAA,QACvC,UAAU,cAAE,QAAQ;AAAA,QACpB,UAAU,cAAE,OAAO;AAAA,QACnB,SAAS,cAAE;AAAA,UACT,cAAE,OAAO;AAAA,YACP,IAAI,cAAE,OAAO;AAAA,YACb,OAAO,cAAE,OAAO;AAAA,YAChB,aAAa,cAAE,OAAO,EAAE,SAAS;AAAA,UACnC,CAAC;AAAA,QACH;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAAA,IACD,MAAM,cAAE,OAAO,cAAE,QAAQ,CAAC,EAAE,SAAS;AAAA,EACvC,CAAC;AAAA,EACD;AAAA,EACA,cAAE,OAAO;AAAA,IACP,MAAM,cAAE,QAAQ,YAAY;AAAA,IAC5B,cAAc,cAAE,OAAO;AAAA,IACvB,SAAS,cAAE,IAAI,EAAE,SAAS;AAAA,EAC5B,CAAC;AAAA,EACD,cAAE,OAAO,EAAE,MAAM,cAAE,QAAQ,MAAM,GAAG,MAAM,cAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAAA,EAC9D,cAAE,OAAO,EAAE,MAAM,cAAE,QAAQ,OAAO,GAAG,SAAS,cAAE,OAAO,EAAE,CAAC;AAC5D,CAAC;","names":["import_zod","import_zod"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/client/read-stream.ts","../src/client/stream-from-route.ts","../src/server/create-stream-response.ts","../src/types/stream-chunk.ts","../src/types/structured-data/index.ts","../src/types/structured-data/jobs.ts"],"sourcesContent":["// release-test: 2026-01-22\n// packages/stream/src/index.ts\n\n// client\nexport * from \"./client/read-stream\";\nexport * from \"./client/stream-from-route\";\n\n// server\nexport * from \"./server/create-stream-response\";\nexport * 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","// packages/stream/src/server/create-stream-response.ts\nimport type { StreamChunk } from \"../types/stream-chunk\";\n\nexport const STREAM_HEADERS = {\n \"content-type\": \"text/event-stream\",\n \"cache-control\": \"no-cache\",\n connection: \"keep-alive\",\n \"x-accel-buffering\": \"no\",\n};\n\nclass JsonToSseTransformStream extends TransformStream<unknown, string> {\n constructor() {\n super({\n transform(part, controller) {\n controller.enqueue(`data: ${JSON.stringify(part)}\\n\\n`);\n },\n flush(controller) {\n controller.enqueue(\"data: [DONE]\\n\\n\");\n },\n });\n }\n}\n\n/**\n * Turns an AsyncIterable<StreamChunk> into a streamed HTTP Response.\n * Works in Node, Bun, Cloudflare, Edge, etc.\n */\nexport function createStreamResponse(\n stream: AsyncIterable<StreamChunk>,\n): Response {\n const readable = new ReadableStream<StreamChunk>({\n async start(controller) {\n try {\n for await (const chunk of stream) {\n controller.enqueue(chunk);\n }\n } catch (err: any) {\n controller.enqueue({\n type: \"error\",\n message: String(err?.message ?? err),\n } as StreamChunk);\n } finally {\n controller.close();\n }\n },\n });\n\n return new Response(\n readable\n .pipeThrough(new JsonToSseTransformStream())\n .pipeThrough(new TextEncoderStream()),\n { headers: STREAM_HEADERS },\n );\n}\n","import { z } from \"zod\";\nimport { StructuredDataChunkSchema } from \"./structured-data\";\n\nexport const StreamChunkSchema = z.union([\n z.object({\n type: z.literal(\"session\"),\n sessionId: z.string(),\n }),\n z.object({\n type: z.literal(\"status\"),\n message: z.string(),\n node: z.string().optional(),\n }),\n z.object({\n type: z.literal(\"message\"),\n content: z.string(),\n node: z.string().optional(),\n }),\n z.object({\n type: z.literal(\"text-start\"),\n node: z.string().optional(),\n id: z.string().optional(),\n opId: z.string().optional(),\n segmentId: z.string().optional(),\n }),\n z.object({\n type: z.literal(\"text-delta\"),\n delta: z.string(),\n node: z.string().optional(),\n id: z.string().optional(),\n opId: z.string().optional(),\n segmentId: z.string().optional(),\n }),\n z.object({\n type: z.literal(\"text-end\"),\n node: z.string().optional(),\n id: z.string().optional(),\n opId: z.string().optional(),\n segmentId: z.string().optional(),\n }),\n z.object({\n type: z.literal(\"tool-result\"),\n tool: z.string().optional(),\n node: z.string().optional(),\n content: z.unknown(),\n }),\n // Interrupt request chunk (used to render interactive options in UI)\n z.object({\n type: z.literal(\"interrupt\"),\n requestId: z.string(),\n resumeToken: z.string(),\n workflow: z.string().optional(),\n node: z.string().optional(),\n id: z.string().optional(),\n opId: z.string().optional(),\n schemaId: z.string().optional(),\n schemaVersion: z.string().optional(),\n input: z.discriminatedUnion(\"kind\", [\n // Text input: question optional, no options\n z.object({\n kind: z.literal(\"text\"),\n multiple: z.boolean(),\n question: z.string().optional(),\n id: z.string().optional(),\n schemaId: z.string().optional(),\n schemaVersion: z.string().optional(),\n meta: z.record(z.unknown()).optional(),\n options: z.array(z.never()).optional(),\n }),\n // Choice/multi-choice: question + options required\n z.object({\n kind: z.enum([\"choice\", \"multi-choice\"]),\n multiple: z.boolean(),\n question: z.string(),\n id: z.string().optional(),\n schemaId: z.string().optional(),\n schemaVersion: z.string().optional(),\n meta: z.record(z.unknown()).optional(),\n options: z.array(\n z.object({\n id: z.string(),\n label: z.string(),\n description: z.string().optional(),\n }),\n ),\n }),\n ]),\n meta: z.record(z.unknown()).optional(),\n }),\n StructuredDataChunkSchema,\n z.object({\n type: z.literal(\"transition\"),\n transitionTo: z.string(),\n payload: z.any().optional(),\n }),\n z.object({ type: z.literal(\"done\"), data: z.any().optional() }),\n z.object({ type: z.literal(\"error\"), message: z.string() }),\n]);\n\nexport type StreamChunk = z.infer<typeof StreamChunkSchema>;\n","import { z } from \"zod\";\nimport { JobsStructuredData } from \"./jobs\";\n\nconst StructuredDataBase = z.object({\n type: z.literal(\"structured-data\"),\n dataType: z.string().optional(),\n mode: z.enum([\"final\", \"patch\", \"snapshot\"]).optional(),\n schemaId: z.string().optional(),\n schemaVersion: z.string().optional(),\n id: z.string().optional(),\n opId: z.string().optional(),\n node: z.string().optional(),\n});\n\nconst JobsStructuredDataChunkSchema = StructuredDataBase.extend({\n dataType: z.literal(\"jobs\"),\n data: JobsStructuredData,\n});\n\nconst GenericStructuredDataChunkSchema = StructuredDataBase.extend({\n data: z.unknown(),\n});\n\nexport const StructuredDataChunkSchema = z.union([\n JobsStructuredDataChunkSchema,\n GenericStructuredDataChunkSchema,\n]);\n\nexport type StructuredDataChunk = z.infer<typeof StructuredDataChunkSchema>;\n","import { z } from \"zod\";\n\nexport const JobsStructuredData = z.object({\n jobs: z.array(\n z.object({\n id: z.string(),\n title: z.string(),\n company: z.string(),\n location: z.string(),\n match: z.number(),\n }),\n ),\n reasoning: z.string().optional(),\n});\n\nexport type JobsStructuredData = z.infer<typeof JobsStructuredData>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;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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AO,cAAE,QAAQ,CAAC,EAAE,SAAS;AAAA,EACvC,CAAC;AAAA,EACD;AAAA,EACA,cAAE,OAAO;AAAA,IACP,MAAM,cAAE,QAAQ,YAAY;AAAA,IAC5B,cAAc,cAAE,OAAO;AAAA,IACvB,SAAS,cAAE,IAAI,EAAE,SAAS;AAAA,EAC5B,CAAC;AAAA,EACD,cAAE,OAAO,EAAE,MAAM,cAAE,QAAQ,MAAM,GAAG,MAAM,cAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAAA,EAC9D,cAAE,OAAO,EAAE,MAAM,cAAE,QAAQ,OAAO,GAAG,SAAS,cAAE,OAAO,EAAE,CAAC;AAC5D,CAAC;","names":["import_zod","import_zod"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kortyx/stream",
3
- "version": "0.3.1",
3
+ "version": "0.4.1",
4
4
  "private": false,
5
5
  "description": "Streaming primitives for Kortyx.",
6
6
  "keywords": [
@@ -36,13 +36,6 @@
36
36
  "README.md",
37
37
  "CHANGELOG.md"
38
38
  ],
39
- "scripts": {
40
- "build": "tsup",
41
- "dev": "tsc --watch",
42
- "lint": "biome check src",
43
- "test": "pnpm -s type-check",
44
- "type-check": "tsc --noEmit"
45
- },
46
39
  "dependencies": {
47
40
  "zod": "^3.23.8"
48
41
  },
@@ -56,5 +49,15 @@
56
49
  "type": "git",
57
50
  "url": "https://github.com/kortyx-io/kortyx.git",
58
51
  "directory": "packages/stream"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "scripts": {
57
+ "build": "tsup",
58
+ "dev": "tsc --watch",
59
+ "lint": "biome check src",
60
+ "test": "pnpm -s type-check",
61
+ "type-check": "tsc --noEmit"
59
62
  }
60
- }
63
+ }