@databricks/appkit 0.69.1 → 0.69.3
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/dist/appkit/package.js +1 -1
- package/dist/core/agent/plugins-map.js +5 -1
- package/dist/core/agent/plugins-map.js.map +1 -1
- package/dist/plugins/agents/agents.d.ts.map +1 -1
- package/dist/plugins/agents/agents.js +8 -4
- package/dist/plugins/agents/agents.js.map +1 -1
- package/dist/plugins/agents/tool-dispatch.js +35 -14
- package/dist/plugins/agents/tool-dispatch.js.map +1 -1
- package/dist/plugins/server/index.js +2 -2
- package/dist/plugins/server/index.js.map +1 -1
- package/dist/plugins/server/remote-tunnel/remote-tunnel-manager.js +3 -3
- package/dist/plugins/server/remote-tunnel/remote-tunnel-manager.js.map +1 -1
- package/dist/plugins/server/static-server.js +3 -3
- package/dist/plugins/server/static-server.js.map +1 -1
- package/dist/plugins/server/utils.js +3 -3
- package/dist/plugins/server/utils.js.map +1 -1
- package/dist/plugins/server/vite-dev-server.js +4 -4
- package/dist/plugins/server/vite-dev-server.js.map +1 -1
- package/dist/shared/src/schemas/manifest.d.ts +33 -33
- package/dist/stream/defaults.js +1 -1
- package/dist/stream/defaults.js.map +1 -1
- package/dist/stream/stream-manager.d.ts.map +1 -1
- package/dist/stream/stream-manager.js +6 -3
- package/dist/stream/stream-manager.js.map +1 -1
- package/dist/stream/types.js.map +1 -1
- package/dist/type-generator/database/generate.js +3 -3
- package/dist/type-generator/database/generate.js.map +1 -1
- package/dist/type-generator/migration.js +2 -2
- package/dist/type-generator/migration.js.map +1 -1
- package/dist/type-generator/serving/server-file-extractor.js +3 -3
- package/dist/type-generator/serving/server-file-extractor.js.map +1 -1
- package/package.json +1 -1
- package/sbom.cdx.json +1 -1
|
@@ -12,12 +12,12 @@ declare const resourceFieldEntrySchema: z.ZodObject<{
|
|
|
12
12
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
13
13
|
type: z.ZodLiteral<"kind">;
|
|
14
14
|
resourceKind: z.ZodEnum<{
|
|
15
|
+
volume: "volume";
|
|
15
16
|
warehouse: "warehouse";
|
|
16
17
|
genie_space: "genie_space";
|
|
17
18
|
postgres_project: "postgres_project";
|
|
18
19
|
postgres_branch: "postgres_branch";
|
|
19
20
|
postgres_database: "postgres_database";
|
|
20
|
-
volume: "volume";
|
|
21
21
|
}>;
|
|
22
22
|
select: z.ZodOptional<z.ZodString>;
|
|
23
23
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -58,12 +58,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
58
58
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
59
59
|
type: z.ZodLiteral<"kind">;
|
|
60
60
|
resourceKind: z.ZodEnum<{
|
|
61
|
+
volume: "volume";
|
|
61
62
|
warehouse: "warehouse";
|
|
62
63
|
genie_space: "genie_space";
|
|
63
64
|
postgres_project: "postgres_project";
|
|
64
65
|
postgres_branch: "postgres_branch";
|
|
65
66
|
postgres_database: "postgres_database";
|
|
66
|
-
volume: "volume";
|
|
67
67
|
}>;
|
|
68
68
|
select: z.ZodOptional<z.ZodString>;
|
|
69
69
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -99,12 +99,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
99
99
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
100
100
|
type: z.ZodLiteral<"kind">;
|
|
101
101
|
resourceKind: z.ZodEnum<{
|
|
102
|
+
volume: "volume";
|
|
102
103
|
warehouse: "warehouse";
|
|
103
104
|
genie_space: "genie_space";
|
|
104
105
|
postgres_project: "postgres_project";
|
|
105
106
|
postgres_branch: "postgres_branch";
|
|
106
107
|
postgres_database: "postgres_database";
|
|
107
|
-
volume: "volume";
|
|
108
108
|
}>;
|
|
109
109
|
select: z.ZodOptional<z.ZodString>;
|
|
110
110
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -139,12 +139,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
139
139
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
140
140
|
type: z.ZodLiteral<"kind">;
|
|
141
141
|
resourceKind: z.ZodEnum<{
|
|
142
|
+
volume: "volume";
|
|
142
143
|
warehouse: "warehouse";
|
|
143
144
|
genie_space: "genie_space";
|
|
144
145
|
postgres_project: "postgres_project";
|
|
145
146
|
postgres_branch: "postgres_branch";
|
|
146
147
|
postgres_database: "postgres_database";
|
|
147
|
-
volume: "volume";
|
|
148
148
|
}>;
|
|
149
149
|
select: z.ZodOptional<z.ZodString>;
|
|
150
150
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -162,9 +162,9 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
162
162
|
type: z.ZodLiteral<"sql_warehouse">;
|
|
163
163
|
}, z.core.$strict>, z.ZodObject<{
|
|
164
164
|
permission: z.ZodEnum<{
|
|
165
|
+
CAN_QUERY: "CAN_QUERY";
|
|
165
166
|
CAN_VIEW: "CAN_VIEW";
|
|
166
167
|
CAN_MANAGE: "CAN_MANAGE";
|
|
167
|
-
CAN_QUERY: "CAN_QUERY";
|
|
168
168
|
}>;
|
|
169
169
|
alias: z.ZodString;
|
|
170
170
|
resourceKey: z.ZodString;
|
|
@@ -180,12 +180,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
180
180
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
181
181
|
type: z.ZodLiteral<"kind">;
|
|
182
182
|
resourceKind: z.ZodEnum<{
|
|
183
|
+
volume: "volume";
|
|
183
184
|
warehouse: "warehouse";
|
|
184
185
|
genie_space: "genie_space";
|
|
185
186
|
postgres_project: "postgres_project";
|
|
186
187
|
postgres_branch: "postgres_branch";
|
|
187
188
|
postgres_database: "postgres_database";
|
|
188
|
-
volume: "volume";
|
|
189
189
|
}>;
|
|
190
190
|
select: z.ZodOptional<z.ZodString>;
|
|
191
191
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -220,12 +220,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
220
220
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
221
221
|
type: z.ZodLiteral<"kind">;
|
|
222
222
|
resourceKind: z.ZodEnum<{
|
|
223
|
+
volume: "volume";
|
|
223
224
|
warehouse: "warehouse";
|
|
224
225
|
genie_space: "genie_space";
|
|
225
226
|
postgres_project: "postgres_project";
|
|
226
227
|
postgres_branch: "postgres_branch";
|
|
227
228
|
postgres_database: "postgres_database";
|
|
228
|
-
volume: "volume";
|
|
229
229
|
}>;
|
|
230
230
|
select: z.ZodOptional<z.ZodString>;
|
|
231
231
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -259,12 +259,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
259
259
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
260
260
|
type: z.ZodLiteral<"kind">;
|
|
261
261
|
resourceKind: z.ZodEnum<{
|
|
262
|
+
volume: "volume";
|
|
262
263
|
warehouse: "warehouse";
|
|
263
264
|
genie_space: "genie_space";
|
|
264
265
|
postgres_project: "postgres_project";
|
|
265
266
|
postgres_branch: "postgres_branch";
|
|
266
267
|
postgres_database: "postgres_database";
|
|
267
|
-
volume: "volume";
|
|
268
268
|
}>;
|
|
269
269
|
select: z.ZodOptional<z.ZodString>;
|
|
270
270
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -298,12 +298,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
298
298
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
299
299
|
type: z.ZodLiteral<"kind">;
|
|
300
300
|
resourceKind: z.ZodEnum<{
|
|
301
|
+
volume: "volume";
|
|
301
302
|
warehouse: "warehouse";
|
|
302
303
|
genie_space: "genie_space";
|
|
303
304
|
postgres_project: "postgres_project";
|
|
304
305
|
postgres_branch: "postgres_branch";
|
|
305
306
|
postgres_database: "postgres_database";
|
|
306
|
-
volume: "volume";
|
|
307
307
|
}>;
|
|
308
308
|
select: z.ZodOptional<z.ZodString>;
|
|
309
309
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -337,12 +337,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
337
337
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
338
338
|
type: z.ZodLiteral<"kind">;
|
|
339
339
|
resourceKind: z.ZodEnum<{
|
|
340
|
+
volume: "volume";
|
|
340
341
|
warehouse: "warehouse";
|
|
341
342
|
genie_space: "genie_space";
|
|
342
343
|
postgres_project: "postgres_project";
|
|
343
344
|
postgres_branch: "postgres_branch";
|
|
344
345
|
postgres_database: "postgres_database";
|
|
345
|
-
volume: "volume";
|
|
346
346
|
}>;
|
|
347
347
|
select: z.ZodOptional<z.ZodString>;
|
|
348
348
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -376,12 +376,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
376
376
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
377
377
|
type: z.ZodLiteral<"kind">;
|
|
378
378
|
resourceKind: z.ZodEnum<{
|
|
379
|
+
volume: "volume";
|
|
379
380
|
warehouse: "warehouse";
|
|
380
381
|
genie_space: "genie_space";
|
|
381
382
|
postgres_project: "postgres_project";
|
|
382
383
|
postgres_branch: "postgres_branch";
|
|
383
384
|
postgres_database: "postgres_database";
|
|
384
|
-
volume: "volume";
|
|
385
385
|
}>;
|
|
386
386
|
select: z.ZodOptional<z.ZodString>;
|
|
387
387
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -415,12 +415,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
415
415
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
416
416
|
type: z.ZodLiteral<"kind">;
|
|
417
417
|
resourceKind: z.ZodEnum<{
|
|
418
|
+
volume: "volume";
|
|
418
419
|
warehouse: "warehouse";
|
|
419
420
|
genie_space: "genie_space";
|
|
420
421
|
postgres_project: "postgres_project";
|
|
421
422
|
postgres_branch: "postgres_branch";
|
|
422
423
|
postgres_database: "postgres_database";
|
|
423
|
-
volume: "volume";
|
|
424
424
|
}>;
|
|
425
425
|
select: z.ZodOptional<z.ZodString>;
|
|
426
426
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -438,10 +438,10 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
438
438
|
type: z.ZodLiteral<"postgres">;
|
|
439
439
|
}, z.core.$strict>, z.ZodObject<{
|
|
440
440
|
permission: z.ZodEnum<{
|
|
441
|
+
CAN_EDIT: "CAN_EDIT";
|
|
441
442
|
CAN_VIEW: "CAN_VIEW";
|
|
442
443
|
CAN_MANAGE: "CAN_MANAGE";
|
|
443
444
|
CAN_RUN: "CAN_RUN";
|
|
444
|
-
CAN_EDIT: "CAN_EDIT";
|
|
445
445
|
}>;
|
|
446
446
|
alias: z.ZodString;
|
|
447
447
|
resourceKey: z.ZodString;
|
|
@@ -457,12 +457,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
457
457
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
458
458
|
type: z.ZodLiteral<"kind">;
|
|
459
459
|
resourceKind: z.ZodEnum<{
|
|
460
|
+
volume: "volume";
|
|
460
461
|
warehouse: "warehouse";
|
|
461
462
|
genie_space: "genie_space";
|
|
462
463
|
postgres_project: "postgres_project";
|
|
463
464
|
postgres_branch: "postgres_branch";
|
|
464
465
|
postgres_database: "postgres_database";
|
|
465
|
-
volume: "volume";
|
|
466
466
|
}>;
|
|
467
467
|
select: z.ZodOptional<z.ZodString>;
|
|
468
468
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -480,8 +480,8 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
480
480
|
type: z.ZodLiteral<"genie_space">;
|
|
481
481
|
}, z.core.$strict>, z.ZodObject<{
|
|
482
482
|
permission: z.ZodEnum<{
|
|
483
|
-
CAN_MANAGE: "CAN_MANAGE";
|
|
484
483
|
CAN_EDIT: "CAN_EDIT";
|
|
484
|
+
CAN_MANAGE: "CAN_MANAGE";
|
|
485
485
|
CAN_READ: "CAN_READ";
|
|
486
486
|
}>;
|
|
487
487
|
alias: z.ZodString;
|
|
@@ -498,12 +498,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
498
498
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
499
499
|
type: z.ZodLiteral<"kind">;
|
|
500
500
|
resourceKind: z.ZodEnum<{
|
|
501
|
+
volume: "volume";
|
|
501
502
|
warehouse: "warehouse";
|
|
502
503
|
genie_space: "genie_space";
|
|
503
504
|
postgres_project: "postgres_project";
|
|
504
505
|
postgres_branch: "postgres_branch";
|
|
505
506
|
postgres_database: "postgres_database";
|
|
506
|
-
volume: "volume";
|
|
507
507
|
}>;
|
|
508
508
|
select: z.ZodOptional<z.ZodString>;
|
|
509
509
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -537,12 +537,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
537
537
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
538
538
|
type: z.ZodLiteral<"kind">;
|
|
539
539
|
resourceKind: z.ZodEnum<{
|
|
540
|
+
volume: "volume";
|
|
540
541
|
warehouse: "warehouse";
|
|
541
542
|
genie_space: "genie_space";
|
|
542
543
|
postgres_project: "postgres_project";
|
|
543
544
|
postgres_branch: "postgres_branch";
|
|
544
545
|
postgres_database: "postgres_database";
|
|
545
|
-
volume: "volume";
|
|
546
546
|
}>;
|
|
547
547
|
select: z.ZodOptional<z.ZodString>;
|
|
548
548
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -579,12 +579,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
579
579
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
580
580
|
type: z.ZodLiteral<"kind">;
|
|
581
581
|
resourceKind: z.ZodEnum<{
|
|
582
|
+
volume: "volume";
|
|
582
583
|
warehouse: "warehouse";
|
|
583
584
|
genie_space: "genie_space";
|
|
584
585
|
postgres_project: "postgres_project";
|
|
585
586
|
postgres_branch: "postgres_branch";
|
|
586
587
|
postgres_database: "postgres_database";
|
|
587
|
-
volume: "volume";
|
|
588
588
|
}>;
|
|
589
589
|
select: z.ZodOptional<z.ZodString>;
|
|
590
590
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -620,12 +620,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
620
620
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
621
621
|
type: z.ZodLiteral<"kind">;
|
|
622
622
|
resourceKind: z.ZodEnum<{
|
|
623
|
+
volume: "volume";
|
|
623
624
|
warehouse: "warehouse";
|
|
624
625
|
genie_space: "genie_space";
|
|
625
626
|
postgres_project: "postgres_project";
|
|
626
627
|
postgres_branch: "postgres_branch";
|
|
627
628
|
postgres_database: "postgres_database";
|
|
628
|
-
volume: "volume";
|
|
629
629
|
}>;
|
|
630
630
|
select: z.ZodOptional<z.ZodString>;
|
|
631
631
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -660,12 +660,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
660
660
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
661
661
|
type: z.ZodLiteral<"kind">;
|
|
662
662
|
resourceKind: z.ZodEnum<{
|
|
663
|
+
volume: "volume";
|
|
663
664
|
warehouse: "warehouse";
|
|
664
665
|
genie_space: "genie_space";
|
|
665
666
|
postgres_project: "postgres_project";
|
|
666
667
|
postgres_branch: "postgres_branch";
|
|
667
668
|
postgres_database: "postgres_database";
|
|
668
|
-
volume: "volume";
|
|
669
669
|
}>;
|
|
670
670
|
select: z.ZodOptional<z.ZodString>;
|
|
671
671
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -683,9 +683,9 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
683
683
|
type: z.ZodLiteral<"sql_warehouse">;
|
|
684
684
|
}, z.core.$strict>, z.ZodObject<{
|
|
685
685
|
permission: z.ZodEnum<{
|
|
686
|
+
CAN_QUERY: "CAN_QUERY";
|
|
686
687
|
CAN_VIEW: "CAN_VIEW";
|
|
687
688
|
CAN_MANAGE: "CAN_MANAGE";
|
|
688
|
-
CAN_QUERY: "CAN_QUERY";
|
|
689
689
|
}>;
|
|
690
690
|
alias: z.ZodString;
|
|
691
691
|
resourceKey: z.ZodString;
|
|
@@ -701,12 +701,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
701
701
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
702
702
|
type: z.ZodLiteral<"kind">;
|
|
703
703
|
resourceKind: z.ZodEnum<{
|
|
704
|
+
volume: "volume";
|
|
704
705
|
warehouse: "warehouse";
|
|
705
706
|
genie_space: "genie_space";
|
|
706
707
|
postgres_project: "postgres_project";
|
|
707
708
|
postgres_branch: "postgres_branch";
|
|
708
709
|
postgres_database: "postgres_database";
|
|
709
|
-
volume: "volume";
|
|
710
710
|
}>;
|
|
711
711
|
select: z.ZodOptional<z.ZodString>;
|
|
712
712
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -741,12 +741,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
741
741
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
742
742
|
type: z.ZodLiteral<"kind">;
|
|
743
743
|
resourceKind: z.ZodEnum<{
|
|
744
|
+
volume: "volume";
|
|
744
745
|
warehouse: "warehouse";
|
|
745
746
|
genie_space: "genie_space";
|
|
746
747
|
postgres_project: "postgres_project";
|
|
747
748
|
postgres_branch: "postgres_branch";
|
|
748
749
|
postgres_database: "postgres_database";
|
|
749
|
-
volume: "volume";
|
|
750
750
|
}>;
|
|
751
751
|
select: z.ZodOptional<z.ZodString>;
|
|
752
752
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -780,12 +780,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
780
780
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
781
781
|
type: z.ZodLiteral<"kind">;
|
|
782
782
|
resourceKind: z.ZodEnum<{
|
|
783
|
+
volume: "volume";
|
|
783
784
|
warehouse: "warehouse";
|
|
784
785
|
genie_space: "genie_space";
|
|
785
786
|
postgres_project: "postgres_project";
|
|
786
787
|
postgres_branch: "postgres_branch";
|
|
787
788
|
postgres_database: "postgres_database";
|
|
788
|
-
volume: "volume";
|
|
789
789
|
}>;
|
|
790
790
|
select: z.ZodOptional<z.ZodString>;
|
|
791
791
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -819,12 +819,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
819
819
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
820
820
|
type: z.ZodLiteral<"kind">;
|
|
821
821
|
resourceKind: z.ZodEnum<{
|
|
822
|
+
volume: "volume";
|
|
822
823
|
warehouse: "warehouse";
|
|
823
824
|
genie_space: "genie_space";
|
|
824
825
|
postgres_project: "postgres_project";
|
|
825
826
|
postgres_branch: "postgres_branch";
|
|
826
827
|
postgres_database: "postgres_database";
|
|
827
|
-
volume: "volume";
|
|
828
828
|
}>;
|
|
829
829
|
select: z.ZodOptional<z.ZodString>;
|
|
830
830
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -858,12 +858,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
858
858
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
859
859
|
type: z.ZodLiteral<"kind">;
|
|
860
860
|
resourceKind: z.ZodEnum<{
|
|
861
|
+
volume: "volume";
|
|
861
862
|
warehouse: "warehouse";
|
|
862
863
|
genie_space: "genie_space";
|
|
863
864
|
postgres_project: "postgres_project";
|
|
864
865
|
postgres_branch: "postgres_branch";
|
|
865
866
|
postgres_database: "postgres_database";
|
|
866
|
-
volume: "volume";
|
|
867
867
|
}>;
|
|
868
868
|
select: z.ZodOptional<z.ZodString>;
|
|
869
869
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -897,12 +897,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
897
897
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
898
898
|
type: z.ZodLiteral<"kind">;
|
|
899
899
|
resourceKind: z.ZodEnum<{
|
|
900
|
+
volume: "volume";
|
|
900
901
|
warehouse: "warehouse";
|
|
901
902
|
genie_space: "genie_space";
|
|
902
903
|
postgres_project: "postgres_project";
|
|
903
904
|
postgres_branch: "postgres_branch";
|
|
904
905
|
postgres_database: "postgres_database";
|
|
905
|
-
volume: "volume";
|
|
906
906
|
}>;
|
|
907
907
|
select: z.ZodOptional<z.ZodString>;
|
|
908
908
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -936,12 +936,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
936
936
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
937
937
|
type: z.ZodLiteral<"kind">;
|
|
938
938
|
resourceKind: z.ZodEnum<{
|
|
939
|
+
volume: "volume";
|
|
939
940
|
warehouse: "warehouse";
|
|
940
941
|
genie_space: "genie_space";
|
|
941
942
|
postgres_project: "postgres_project";
|
|
942
943
|
postgres_branch: "postgres_branch";
|
|
943
944
|
postgres_database: "postgres_database";
|
|
944
|
-
volume: "volume";
|
|
945
945
|
}>;
|
|
946
946
|
select: z.ZodOptional<z.ZodString>;
|
|
947
947
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -959,10 +959,10 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
959
959
|
type: z.ZodLiteral<"postgres">;
|
|
960
960
|
}, z.core.$strict>, z.ZodObject<{
|
|
961
961
|
permission: z.ZodEnum<{
|
|
962
|
+
CAN_EDIT: "CAN_EDIT";
|
|
962
963
|
CAN_VIEW: "CAN_VIEW";
|
|
963
964
|
CAN_MANAGE: "CAN_MANAGE";
|
|
964
965
|
CAN_RUN: "CAN_RUN";
|
|
965
|
-
CAN_EDIT: "CAN_EDIT";
|
|
966
966
|
}>;
|
|
967
967
|
alias: z.ZodString;
|
|
968
968
|
resourceKey: z.ZodString;
|
|
@@ -978,12 +978,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
978
978
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
979
979
|
type: z.ZodLiteral<"kind">;
|
|
980
980
|
resourceKind: z.ZodEnum<{
|
|
981
|
+
volume: "volume";
|
|
981
982
|
warehouse: "warehouse";
|
|
982
983
|
genie_space: "genie_space";
|
|
983
984
|
postgres_project: "postgres_project";
|
|
984
985
|
postgres_branch: "postgres_branch";
|
|
985
986
|
postgres_database: "postgres_database";
|
|
986
|
-
volume: "volume";
|
|
987
987
|
}>;
|
|
988
988
|
select: z.ZodOptional<z.ZodString>;
|
|
989
989
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -1001,8 +1001,8 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
1001
1001
|
type: z.ZodLiteral<"genie_space">;
|
|
1002
1002
|
}, z.core.$strict>, z.ZodObject<{
|
|
1003
1003
|
permission: z.ZodEnum<{
|
|
1004
|
-
CAN_MANAGE: "CAN_MANAGE";
|
|
1005
1004
|
CAN_EDIT: "CAN_EDIT";
|
|
1005
|
+
CAN_MANAGE: "CAN_MANAGE";
|
|
1006
1006
|
CAN_READ: "CAN_READ";
|
|
1007
1007
|
}>;
|
|
1008
1008
|
alias: z.ZodString;
|
|
@@ -1019,12 +1019,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
1019
1019
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
1020
1020
|
type: z.ZodLiteral<"kind">;
|
|
1021
1021
|
resourceKind: z.ZodEnum<{
|
|
1022
|
+
volume: "volume";
|
|
1022
1023
|
warehouse: "warehouse";
|
|
1023
1024
|
genie_space: "genie_space";
|
|
1024
1025
|
postgres_project: "postgres_project";
|
|
1025
1026
|
postgres_branch: "postgres_branch";
|
|
1026
1027
|
postgres_database: "postgres_database";
|
|
1027
|
-
volume: "volume";
|
|
1028
1028
|
}>;
|
|
1029
1029
|
select: z.ZodOptional<z.ZodString>;
|
|
1030
1030
|
display: z.ZodOptional<z.ZodString>;
|
|
@@ -1058,12 +1058,12 @@ declare const pluginManifestSchema: z.ZodObject<{
|
|
|
1058
1058
|
discovery: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
1059
1059
|
type: z.ZodLiteral<"kind">;
|
|
1060
1060
|
resourceKind: z.ZodEnum<{
|
|
1061
|
+
volume: "volume";
|
|
1061
1062
|
warehouse: "warehouse";
|
|
1062
1063
|
genie_space: "genie_space";
|
|
1063
1064
|
postgres_project: "postgres_project";
|
|
1064
1065
|
postgres_branch: "postgres_branch";
|
|
1065
1066
|
postgres_database: "postgres_database";
|
|
1066
|
-
volume: "volume";
|
|
1067
1067
|
}>;
|
|
1068
1068
|
select: z.ZodOptional<z.ZodString>;
|
|
1069
1069
|
display: z.ZodOptional<z.ZodString>;
|
package/dist/stream/defaults.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.js","names":[],"sources":["../../src/stream/defaults.ts"],"sourcesContent":["export const streamDefaults = {\n bufferSize: 100,\n //
|
|
1
|
+
{"version":3,"file":"defaults.js","names":[],"sources":["../../src/stream/defaults.ts"],"sourcesContent":["export const streamDefaults = {\n bufferSize: 100,\n // Bounds the JSON_ARRAY path only: ARROW_STREAM bytes stream back on the\n // query response body (`_handleArrowStreamQuery`), never over SSE.\n // Keep in sync with `connectSSE`'s `maxBufferSize` default.\n maxEventSize: 5 * 1024 * 1024,\n bufferTTL: 10 * 60 * 1000, // 10 minutes\n heartbeatInterval: 10 * 1000, // 10 seconds\n maxActiveStreams: 1000, // 1000 streams\n disconnectGraceMs: 15_000, // 15 seconds\n} as const;\n"],"mappings":";AAAA,MAAa,iBAAiB;CAC5B,YAAY;CAIZ,cAAc,IAAI,OAAO;CACzB,WAAW,MAAU;CACrB,mBAAmB,KAAK;CACxB,kBAAkB;CAClB,mBAAmB;CACpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-manager.d.ts","names":[],"sources":["../../src/stream/stream-manager.ts"],"mappings":";;;;;cAmBa,aAAA;EAAA,QACH,gBAAA;EAAA,QACA,cAAA;EAAA,QACA,SAAA;EAAA,QACA,YAAA;EAAA,QACA,SAAA;EAAA,QACA,iBAAA;cAEI,OAAA,GAAU,YAAA;EAahB,MAAA,CACJ,GAAA,EAAK,YAAA,EACL,OAAA,GAAU,MAAA,EAAQ,WAAA,KAAgB,cAAA,sBAClC,OAAA,GAAU,YAAA,EACV,QAAA,YACC,OAAA;EAsCH,QAAA,CAAA;EAaA,cAAA,CAAA;EAAA,QAKc,uBAAA;EAAA,QA+EA,gBAAA;EAAA,
|
|
1
|
+
{"version":3,"file":"stream-manager.d.ts","names":[],"sources":["../../src/stream/stream-manager.ts"],"mappings":";;;;;cAmBa,aAAA;EAAA,QACH,gBAAA;EAAA,QACA,cAAA;EAAA,QACA,SAAA;EAAA,QACA,YAAA;EAAA,QACA,SAAA;EAAA,QACA,iBAAA;cAEI,OAAA,GAAU,YAAA;EAahB,MAAA,CACJ,GAAA,EAAK,YAAA,EACL,OAAA,GAAU,MAAA,EAAQ,WAAA,KAAgB,cAAA,sBAClC,OAAA,GAAU,YAAA,EACV,QAAA,YACC,OAAA;EAsCH,QAAA,CAAA;EAaA,cAAA,CAAA;EAAA,QAKc,uBAAA;EAAA,QA+EA,gBAAA;EAAA,QAmFA,6BAAA;EAAA,QA0GN,eAAA;EAAA,QA6BA,yBAAA;EAAA,QAaA,wBAAA;EAAA,QAwBA,eAAA;EAAA,QAYA,gBAAA;EAAA,QAUA,mBAAA;EAAA,QAuBA,wBAAA;EAAA,QA8BA,gBAAA;AAAA"}
|
|
@@ -100,6 +100,7 @@ var StreamManager = class {
|
|
|
100
100
|
if (res.writableEnded || res.destroyed) return;
|
|
101
101
|
const abortController = new AbortController();
|
|
102
102
|
const eventBuffer = new EventRingBuffer(options?.bufferSize ?? streamDefaults.bufferSize);
|
|
103
|
+
const maxEventSize = options?.maxEventSize ?? this.maxEventSize;
|
|
103
104
|
const combinedSignal = this._combineSignals(abortController.signal, options?.userSignal);
|
|
104
105
|
const heartbeat = this.sseWriter.startHeartbeat(res, combinedSignal);
|
|
105
106
|
const traceContext = context.active();
|
|
@@ -116,7 +117,8 @@ var StreamManager = class {
|
|
|
116
117
|
isCompleted: false,
|
|
117
118
|
lastAccess: Date.now(),
|
|
118
119
|
abortController,
|
|
119
|
-
traceContext
|
|
120
|
+
traceContext,
|
|
121
|
+
maxEventSize
|
|
120
122
|
};
|
|
121
123
|
this.streamRegistry.add(streamEntry);
|
|
122
124
|
const streamOperation = {
|
|
@@ -143,8 +145,9 @@ var StreamManager = class {
|
|
|
143
145
|
if (streamEntry.abortController.signal.aborted) break;
|
|
144
146
|
const eventId = randomUUID();
|
|
145
147
|
const eventData = JSON.stringify(event);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
+
const { maxEventSize } = streamEntry;
|
|
149
|
+
if (Buffer.byteLength(eventData, "utf8") > maxEventSize) {
|
|
150
|
+
const errorMsg = `Event exceeds max size of ${maxEventSize} bytes`;
|
|
148
151
|
const errorCode = SSEErrorCode.INVALID_REQUEST;
|
|
149
152
|
this._broadcastErrorToClients(streamEntry, eventId, errorMsg, errorCode);
|
|
150
153
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-manager.js","names":[],"sources":["../../src/stream/stream-manager.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\n\nimport { context } from \"@opentelemetry/api\";\nimport type { IAppResponse, StreamConfig } from \"shared\";\n\nimport { AppKitError } from \"../errors/base\";\nimport { ExecutionError } from \"../errors/execution\";\nimport { createLogger } from \"../logging/logger\";\nimport { EventRingBuffer } from \"./buffers\";\nimport { streamDefaults } from \"./defaults\";\nimport { SSEWriter } from \"./sse-writer\";\nimport { StreamRegistry } from \"./stream-registry\";\nimport { clearGraceTimer, clearRemovalTimer } from \"./timers\";\nimport { SSEErrorCode, type StreamEntry, type StreamOperation } from \"./types\";\nimport { StreamValidator } from \"./validator\";\n\nconst logger = createLogger(\"stream\");\n\n// main entry point for Server-Sent events streaming\nexport class StreamManager {\n private activeOperations: Set<StreamOperation>;\n private streamRegistry: StreamRegistry;\n private sseWriter: SSEWriter;\n private maxEventSize: number;\n private bufferTTL: number;\n private disconnectGraceMs: number;\n\n constructor(options?: StreamConfig) {\n this.streamRegistry = new StreamRegistry(\n options?.maxActiveStreams ?? streamDefaults.maxActiveStreams,\n );\n this.sseWriter = new SSEWriter();\n this.maxEventSize = options?.maxEventSize ?? streamDefaults.maxEventSize;\n this.bufferTTL = options?.bufferTTL ?? streamDefaults.bufferTTL;\n this.disconnectGraceMs =\n options?.disconnectGraceMs ?? streamDefaults.disconnectGraceMs;\n this.activeOperations = new Set();\n }\n\n // main streaming method - handles new connection and reconnection\n async stream(\n res: IAppResponse,\n handler: (signal: AbortSignal) => AsyncGenerator<any, void, unknown>,\n options?: StreamConfig,\n ownerKey?: string,\n ): Promise<void> {\n const { streamId } = options || {};\n\n // check if response is already closed\n if (res.writableEnded || res.destroyed) {\n return;\n }\n\n // setup SSE headers\n this.sseWriter.setupHeaders(res);\n\n // handle reconnection\n if (streamId && StreamValidator.validateStreamId(streamId)) {\n const existingStream = this.streamRegistry.get(streamId);\n if (existingStream) {\n // Enforce per-user binding: the stream's owner key must match the\n // requesting caller's owner key. This prevents cross-user stream\n // takeover via guessed/leaked stream IDs (the SSE registry was\n // previously a global lookup with no authorization step).\n if (existingStream.ownerKey !== ownerKey) {\n this.sseWriter.writeError(\n res,\n randomUUID(),\n \"Stream not found or access denied\",\n SSEErrorCode.STREAM_FORBIDDEN,\n );\n res.end();\n return;\n }\n return this._attachToExistingStream(res, existingStream, options);\n }\n }\n\n // if stream does not exist, create a new one\n return this._createNewStream(res, handler, options, ownerKey);\n }\n\n // abort all active operations\n abortAll(): void {\n // pending disconnect-grace timers are cleared by streamRegistry.clear() below\n this.activeOperations.forEach((operation) => {\n if (operation.heartbeat) clearInterval(operation.heartbeat);\n operation.controller.abort(\n new DOMException(\"Server shutdown\", \"AbortError\"),\n );\n });\n this.activeOperations.clear();\n this.streamRegistry.clear();\n }\n\n // get the number of active operations\n getActiveCount(): number {\n return this.activeOperations.size;\n }\n\n // attach to existing stream\n private async _attachToExistingStream(\n res: IAppResponse,\n streamEntry: StreamEntry,\n options?: StreamConfig,\n ): Promise<void> {\n // handle reconnection - replay missed events\n const lastEventId = res.req?.headers[\"last-event-id\"];\n\n if (StreamValidator.validateEventId(lastEventId)) {\n // cast to string after validation\n const validEventId = lastEventId as string;\n if (streamEntry.eventBuffer.has(validEventId)) {\n const missedEvents =\n streamEntry.eventBuffer.getEventsSince(validEventId);\n // broadcast missed events to client\n for (const event of missedEvents) {\n if (options?.userSignal?.aborted) break;\n this.sseWriter.writeBufferedEvent(res, event);\n }\n } else {\n // buffer overflow - send warning\n this.sseWriter.writeBufferOverflowWarning(res, validEventId);\n }\n }\n\n // a reconnecting client cancels the pending disconnect-grace abort\n clearGraceTimer(streamEntry);\n\n // a reconnect cancels any pending registry removal so the entry isn't\n // pulled out from under the newly attached client\n clearRemovalTimer(streamEntry);\n\n // add client to stream entry\n streamEntry.clients.add(res);\n streamEntry.lastAccess = Date.now();\n\n // start heartbeat\n const combinedSignal = this._combineSignals(\n streamEntry.abortController.signal,\n options?.userSignal,\n );\n const heartbeat = this.sseWriter.startHeartbeat(res, combinedSignal);\n\n // track operation\n const streamOperation: StreamOperation = {\n controller: streamEntry.abortController,\n type: \"stream\",\n heartbeat,\n };\n this.activeOperations.add(streamOperation);\n\n // handle client disconnect\n res.on(\"close\", () => {\n clearInterval(heartbeat);\n streamEntry.clients.delete(res);\n this.activeOperations.delete(streamOperation);\n\n // grace-abort instead of aborting now, so a reconnect can resume\n if (streamEntry.clients.size === 0 && !streamEntry.isCompleted) {\n this._scheduleGraceAbort(streamEntry);\n }\n\n // cleanup if stream is completed and no clients are connected\n this._scheduleRemovalAfterTTL(streamEntry);\n });\n\n // if stream is completed, close connection\n if (streamEntry.isCompleted) {\n res.end();\n // cleanup operation\n this.activeOperations.delete(streamOperation);\n clearInterval(heartbeat);\n // we deliberately ended this client, so drop it from the entry and\n // schedule removal now instead of relying on the transport's `close`\n // event (the close handler's later delete is a safe no-op)\n streamEntry.clients.delete(res);\n this._scheduleRemovalAfterTTL(streamEntry);\n }\n }\n private async _createNewStream(\n res: IAppResponse,\n handler: (signal: AbortSignal) => AsyncGenerator<any, void, unknown>,\n options?: StreamConfig,\n ownerKey?: string,\n ): Promise<void> {\n const streamId = options?.streamId ?? randomUUID();\n\n // abort stream if response is closed\n if (res.writableEnded || res.destroyed) {\n return;\n }\n\n const abortController = new AbortController();\n\n // create event buffer\n const eventBuffer = new EventRingBuffer(\n options?.bufferSize ?? streamDefaults.bufferSize,\n );\n\n // setup signals and heartbeat\n const combinedSignal = this._combineSignals(\n abortController.signal,\n options?.userSignal,\n );\n const heartbeat = this.sseWriter.startHeartbeat(res, combinedSignal);\n\n // capture the current trace context at stream creation time\n const traceContext = context.active();\n\n // abort stream if response is closed\n if (res.writableEnded || res.destroyed) {\n clearInterval(heartbeat);\n return;\n }\n\n // create stream entry\n const streamEntry: StreamEntry = {\n streamId,\n ownerKey,\n generator: handler(combinedSignal),\n eventBuffer,\n clients: new Set([res]),\n isCompleted: false,\n lastAccess: Date.now(),\n abortController,\n traceContext,\n };\n this.streamRegistry.add(streamEntry);\n\n // track operation\n const streamOperation: StreamOperation = {\n controller: abortController,\n type: \"stream\",\n heartbeat,\n };\n this.activeOperations.add(streamOperation);\n\n res.on(\"close\", () => {\n clearInterval(heartbeat);\n this.activeOperations.delete(streamOperation);\n streamEntry.clients.delete(res);\n\n // grace-abort instead of aborting now, so a reconnect can resume\n if (streamEntry.clients.size === 0 && !streamEntry.isCompleted) {\n this._scheduleGraceAbort(streamEntry);\n }\n\n // if the stream already finished (completed or errored), schedule\n // registry removal once the buffer TTL elapses so completed streams\n // don't accumulate in the registry forever\n this._scheduleRemovalAfterTTL(streamEntry);\n });\n\n await this._processGeneratorInBackground(streamEntry);\n\n // cleanup\n clearInterval(heartbeat);\n this.activeOperations.delete(streamOperation);\n }\n\n private async _processGeneratorInBackground(\n streamEntry: StreamEntry,\n ): Promise<void> {\n // run the entire generator processing within the captured trace context\n return context.with(streamEntry.traceContext, async () => {\n try {\n // retrieve all events from generator\n for await (const event of streamEntry.generator) {\n if (streamEntry.abortController.signal.aborted) break;\n const eventId = randomUUID();\n const eventData = JSON.stringify(event);\n\n // validate event size\n if (eventData.length > this.maxEventSize) {\n const errorMsg = `Event exceeds max size of ${this.maxEventSize} bytes`;\n const errorCode = SSEErrorCode.INVALID_REQUEST;\n // broadcast error to all connected clients\n this._broadcastErrorToClients(\n streamEntry,\n eventId,\n errorMsg,\n errorCode,\n );\n continue;\n }\n\n // buffer event for reconnection\n streamEntry.eventBuffer.add({\n id: eventId,\n type: event.type,\n data: eventData,\n timestamp: Date.now(),\n });\n\n // broadcast to all connected clients\n this._broadcastEventsToClients(streamEntry, eventId, event);\n streamEntry.lastAccess = Date.now();\n }\n\n this._finalizeStream(streamEntry);\n } catch (error) {\n // Two distinct messages: a *raw* one for server-side logs (full\n // detail, statement fragments, correlation IDs) and a *client*\n // one for the SSE payload (sanitized, stable, safe to render in\n // a UI). Mixing them leaks upstream wording to anyone connected\n // to the stream — see CWE-209.\n const rawMsg =\n error instanceof Error ? error.message : \"Internal server error\";\n const clientMsg =\n error instanceof AppKitError\n ? error.clientMessage\n : \"Internal server error\";\n // Upstream structured code (e.g. RESULT_TOO_LARGE_FOR_JSON_FALLBACK,\n // NOT_IMPLEMENTED). UI should branch on this, not on `error`.\n const upstreamCode =\n error instanceof ExecutionError ? error.errorCode : undefined;\n const errorEventId = randomUUID();\n const errorCode = this._categorizeError(error);\n\n // client cancellation is a normal control-flow signal, not a failure\n if (errorCode === SSEErrorCode.STREAM_ABORTED) {\n logger.info(\"Stream aborted by client (code=%s)\", errorCode);\n this._finalizeStream(streamEntry);\n return;\n }\n\n logger.error(\n \"Stream execution failed: %s (code=%s upstreamCode=%s)\",\n rawMsg,\n errorCode,\n upstreamCode ?? \"n/a\",\n );\n\n const payload: Record<string, unknown> = {\n error: clientMsg,\n code: errorCode,\n };\n if (upstreamCode) payload.errorCode = upstreamCode;\n\n // buffer error event\n streamEntry.eventBuffer.add({\n id: errorEventId,\n type: \"error\",\n data: JSON.stringify(payload),\n timestamp: Date.now(),\n });\n\n // send error event to all connected clients\n this._broadcastErrorToClients(\n streamEntry,\n errorEventId,\n clientMsg,\n errorCode,\n true,\n upstreamCode,\n );\n // the broadcast above already ended the connected clients; finalize\n // still detaches them so removal is scheduled without waiting on a\n // transport `close` event\n this._finalizeStream(streamEntry);\n }\n });\n }\n\n private _combineSignals(\n internalSignal?: AbortSignal,\n userSignal?: AbortSignal,\n ): AbortSignal {\n if (!userSignal) return internalSignal || new AbortController().signal;\n\n const signals = [internalSignal, userSignal].filter(\n Boolean,\n ) as AbortSignal[];\n const controller = new AbortController();\n\n signals.forEach((signal) => {\n if (signal?.aborted) {\n controller.abort(signal.reason);\n return;\n }\n\n signal?.addEventListener(\n \"abort\",\n () => {\n controller.abort(signal.reason);\n },\n { once: true },\n );\n });\n return controller.signal;\n }\n\n // broadcast events to all connected clients\n private _broadcastEventsToClients(\n streamEntry: StreamEntry,\n eventId: string,\n event: any,\n ): void {\n for (const client of streamEntry.clients) {\n if (!client.writableEnded) {\n this.sseWriter.writeEvent(client, eventId, event);\n }\n }\n }\n\n // broadcast error to all connected clients\n private _broadcastErrorToClients(\n streamEntry: StreamEntry,\n eventId: string,\n errorMessage: string,\n errorCode: SSEErrorCode,\n closeClients: boolean = false,\n upstreamCode?: string,\n ): void {\n for (const client of streamEntry.clients) {\n if (!client.writableEnded) {\n this.sseWriter.writeError(\n client,\n eventId,\n errorMessage,\n errorCode,\n upstreamCode,\n );\n if (closeClients) {\n client.end();\n }\n }\n }\n }\n\n private _finalizeStream(streamEntry: StreamEntry): void {\n streamEntry.isCompleted = true;\n clearGraceTimer(streamEntry);\n this._closeAllClients(streamEntry);\n this._scheduleRemovalAfterTTL(streamEntry);\n }\n\n // close all connected clients and remove them from the stream entry.\n // We are deliberately terminating these connections, so cleanup must not\n // depend on the transport emitting a `close` event for each client (it may\n // never fire). The close handlers' later `clients.delete(...)` calls remain\n // safe no-ops.\n private _closeAllClients(streamEntry: StreamEntry): void {\n for (const client of streamEntry.clients) {\n if (!client.writableEnded) {\n client.end();\n }\n }\n streamEntry.clients.clear();\n }\n\n // abort the generator after the grace window unless a client reconnects first\n private _scheduleGraceAbort(streamEntry: StreamEntry): void {\n // clear any existing timer to avoid stacking\n clearGraceTimer(streamEntry);\n\n const timer = setTimeout(() => {\n streamEntry.disconnectGraceTimer = undefined;\n if (streamEntry.clients.size === 0 && !streamEntry.isCompleted) {\n streamEntry.abortController.abort(\n new DOMException(\"Client disconnected (grace expired)\", \"AbortError\"),\n );\n }\n }, this.disconnectGraceMs);\n\n // never keep the process alive solely for a grace timer\n timer.unref?.();\n streamEntry.disconnectGraceTimer = timer;\n }\n\n // schedule registry removal once a finished (completed or errored) stream\n // has no connected clients. The event buffer stays available for\n // reconnect replay for `bufferTTL` after the last client disconnects;\n // after that the stream entry is removed from the registry so it can be\n // garbage collected.\n private _scheduleRemovalAfterTTL(streamEntry: StreamEntry): void {\n if (!streamEntry.isCompleted || streamEntry.clients.size > 0) {\n return;\n }\n\n // at most one removal timer per stream: rescheduling replaces any\n // pending timer instead of stacking a new one (each pending timer pins\n // the entry's buffer/generator/trace context for the full TTL)\n clearRemovalTimer(streamEntry);\n\n // mark the moment the stream became idle so a reconnect during the TTL\n // window (which refreshes lastAccess) makes the pending timer a no-op\n streamEntry.lastAccess = Date.now();\n\n streamEntry.removalTimer = setTimeout(() => {\n streamEntry.removalTimer = undefined;\n // safety net: no-op if a client reconnected during the TTL window;\n // a fresh removal is scheduled when that client disconnects\n if (\n streamEntry.clients.size === 0 &&\n Date.now() - streamEntry.lastAccess >= this.bufferTTL\n ) {\n this.streamRegistry.remove(streamEntry.streamId);\n }\n }, this.bufferTTL);\n\n // don't keep the process alive just to clean up finished streams\n streamEntry.removalTimer.unref?.();\n }\n\n private _categorizeError(error: unknown): SSEErrorCode {\n if (error instanceof Error) {\n const message = error.message.toLowerCase();\n if (message.includes(\"timeout\") || message.includes(\"timed out\")) {\n return SSEErrorCode.TIMEOUT;\n }\n\n if (message.includes(\"unavailable\") || message.includes(\"econnrefused\")) {\n return SSEErrorCode.TEMPORARY_UNAVAILABLE;\n }\n\n if (error.name === \"AbortError\") {\n return SSEErrorCode.STREAM_ABORTED;\n }\n\n // Defense-in-depth: upstream layers (SQL client, cache) may wrap an\n // AbortError into ExecutionError, losing `name` but keeping the message.\n if (\n message.includes(\"operation was aborted\") ||\n message.includes(\"the request was aborted\") ||\n message.includes(\"statement was canceled\")\n ) {\n return SSEErrorCode.STREAM_ABORTED;\n }\n\n // Detect upstream API errors (e.g., from Databricks SDK ApiError)\n if (\n \"statusCode\" in error &&\n typeof (error as any).statusCode === \"number\"\n ) {\n return SSEErrorCode.UPSTREAM_ERROR;\n }\n }\n\n return SSEErrorCode.INTERNAL_ERROR;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,MAAM,SAAS,aAAa,SAAS;AAGrC,IAAa,gBAAb,MAA2B;CACzB,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;C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B,IACzC,QAAQ,SAAS,0BAA0B,IAC3C,QAAQ,SAAS,yBAAyB,CAE1C,QAAO,aAAa;AAItB,OACE,gBAAgB,SAChB,OAAQ,MAAc,eAAe,SAErC,QAAO,aAAa;;AAIxB,SAAO,aAAa"}
|
|
1
|
+
{"version":3,"file":"stream-manager.js","names":[],"sources":["../../src/stream/stream-manager.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\n\nimport { context } from \"@opentelemetry/api\";\nimport type { IAppResponse, StreamConfig } from \"shared\";\n\nimport { AppKitError } from \"../errors/base\";\nimport { ExecutionError } from \"../errors/execution\";\nimport { createLogger } from \"../logging/logger\";\nimport { EventRingBuffer } from \"./buffers\";\nimport { streamDefaults } from \"./defaults\";\nimport { SSEWriter } from \"./sse-writer\";\nimport { StreamRegistry } from \"./stream-registry\";\nimport { clearGraceTimer, clearRemovalTimer } from \"./timers\";\nimport { SSEErrorCode, type StreamEntry, type StreamOperation } from \"./types\";\nimport { StreamValidator } from \"./validator\";\n\nconst logger = createLogger(\"stream\");\n\n// main entry point for Server-Sent events streaming\nexport class StreamManager {\n private activeOperations: Set<StreamOperation>;\n private streamRegistry: StreamRegistry;\n private sseWriter: SSEWriter;\n private maxEventSize: number;\n private bufferTTL: number;\n private disconnectGraceMs: number;\n\n constructor(options?: StreamConfig) {\n this.streamRegistry = new StreamRegistry(\n options?.maxActiveStreams ?? streamDefaults.maxActiveStreams,\n );\n this.sseWriter = new SSEWriter();\n this.maxEventSize = options?.maxEventSize ?? streamDefaults.maxEventSize;\n this.bufferTTL = options?.bufferTTL ?? streamDefaults.bufferTTL;\n this.disconnectGraceMs =\n options?.disconnectGraceMs ?? streamDefaults.disconnectGraceMs;\n this.activeOperations = new Set();\n }\n\n // main streaming method - handles new connection and reconnection\n async stream(\n res: IAppResponse,\n handler: (signal: AbortSignal) => AsyncGenerator<any, void, unknown>,\n options?: StreamConfig,\n ownerKey?: string,\n ): Promise<void> {\n const { streamId } = options || {};\n\n // check if response is already closed\n if (res.writableEnded || res.destroyed) {\n return;\n }\n\n // setup SSE headers\n this.sseWriter.setupHeaders(res);\n\n // handle reconnection\n if (streamId && StreamValidator.validateStreamId(streamId)) {\n const existingStream = this.streamRegistry.get(streamId);\n if (existingStream) {\n // Enforce per-user binding: the stream's owner key must match the\n // requesting caller's owner key. This prevents cross-user stream\n // takeover via guessed/leaked stream IDs (the SSE registry was\n // previously a global lookup with no authorization step).\n if (existingStream.ownerKey !== ownerKey) {\n this.sseWriter.writeError(\n res,\n randomUUID(),\n \"Stream not found or access denied\",\n SSEErrorCode.STREAM_FORBIDDEN,\n );\n res.end();\n return;\n }\n return this._attachToExistingStream(res, existingStream, options);\n }\n }\n\n // if stream does not exist, create a new one\n return this._createNewStream(res, handler, options, ownerKey);\n }\n\n // abort all active operations\n abortAll(): void {\n // pending disconnect-grace timers are cleared by streamRegistry.clear() below\n this.activeOperations.forEach((operation) => {\n if (operation.heartbeat) clearInterval(operation.heartbeat);\n operation.controller.abort(\n new DOMException(\"Server shutdown\", \"AbortError\"),\n );\n });\n this.activeOperations.clear();\n this.streamRegistry.clear();\n }\n\n // get the number of active operations\n getActiveCount(): number {\n return this.activeOperations.size;\n }\n\n // attach to existing stream\n private async _attachToExistingStream(\n res: IAppResponse,\n streamEntry: StreamEntry,\n options?: StreamConfig,\n ): Promise<void> {\n // handle reconnection - replay missed events\n const lastEventId = res.req?.headers[\"last-event-id\"];\n\n if (StreamValidator.validateEventId(lastEventId)) {\n // cast to string after validation\n const validEventId = lastEventId as string;\n if (streamEntry.eventBuffer.has(validEventId)) {\n const missedEvents =\n streamEntry.eventBuffer.getEventsSince(validEventId);\n // broadcast missed events to client\n for (const event of missedEvents) {\n if (options?.userSignal?.aborted) break;\n this.sseWriter.writeBufferedEvent(res, event);\n }\n } else {\n // buffer overflow - send warning\n this.sseWriter.writeBufferOverflowWarning(res, validEventId);\n }\n }\n\n // a reconnecting client cancels the pending disconnect-grace abort\n clearGraceTimer(streamEntry);\n\n // a reconnect cancels any pending registry removal so the entry isn't\n // pulled out from under the newly attached client\n clearRemovalTimer(streamEntry);\n\n // add client to stream entry\n streamEntry.clients.add(res);\n streamEntry.lastAccess = Date.now();\n\n // start heartbeat\n const combinedSignal = this._combineSignals(\n streamEntry.abortController.signal,\n options?.userSignal,\n );\n const heartbeat = this.sseWriter.startHeartbeat(res, combinedSignal);\n\n // track operation\n const streamOperation: StreamOperation = {\n controller: streamEntry.abortController,\n type: \"stream\",\n heartbeat,\n };\n this.activeOperations.add(streamOperation);\n\n // handle client disconnect\n res.on(\"close\", () => {\n clearInterval(heartbeat);\n streamEntry.clients.delete(res);\n this.activeOperations.delete(streamOperation);\n\n // grace-abort instead of aborting now, so a reconnect can resume\n if (streamEntry.clients.size === 0 && !streamEntry.isCompleted) {\n this._scheduleGraceAbort(streamEntry);\n }\n\n // cleanup if stream is completed and no clients are connected\n this._scheduleRemovalAfterTTL(streamEntry);\n });\n\n // if stream is completed, close connection\n if (streamEntry.isCompleted) {\n res.end();\n // cleanup operation\n this.activeOperations.delete(streamOperation);\n clearInterval(heartbeat);\n // we deliberately ended this client, so drop it from the entry and\n // schedule removal now instead of relying on the transport's `close`\n // event (the close handler's later delete is a safe no-op)\n streamEntry.clients.delete(res);\n this._scheduleRemovalAfterTTL(streamEntry);\n }\n }\n private async _createNewStream(\n res: IAppResponse,\n handler: (signal: AbortSignal) => AsyncGenerator<any, void, unknown>,\n options?: StreamConfig,\n ownerKey?: string,\n ): Promise<void> {\n const streamId = options?.streamId ?? randomUUID();\n\n // abort stream if response is closed\n if (res.writableEnded || res.destroyed) {\n return;\n }\n\n const abortController = new AbortController();\n\n // create event buffer\n const eventBuffer = new EventRingBuffer(\n options?.bufferSize ?? streamDefaults.bufferSize,\n );\n const maxEventSize = options?.maxEventSize ?? this.maxEventSize;\n\n // setup signals and heartbeat\n const combinedSignal = this._combineSignals(\n abortController.signal,\n options?.userSignal,\n );\n const heartbeat = this.sseWriter.startHeartbeat(res, combinedSignal);\n\n // capture the current trace context at stream creation time\n const traceContext = context.active();\n\n // abort stream if response is closed\n if (res.writableEnded || res.destroyed) {\n clearInterval(heartbeat);\n return;\n }\n\n // create stream entry\n const streamEntry: StreamEntry = {\n streamId,\n ownerKey,\n generator: handler(combinedSignal),\n eventBuffer,\n clients: new Set([res]),\n isCompleted: false,\n lastAccess: Date.now(),\n abortController,\n traceContext,\n maxEventSize,\n };\n this.streamRegistry.add(streamEntry);\n\n // track operation\n const streamOperation: StreamOperation = {\n controller: abortController,\n type: \"stream\",\n heartbeat,\n };\n this.activeOperations.add(streamOperation);\n\n res.on(\"close\", () => {\n clearInterval(heartbeat);\n this.activeOperations.delete(streamOperation);\n streamEntry.clients.delete(res);\n\n // grace-abort instead of aborting now, so a reconnect can resume\n if (streamEntry.clients.size === 0 && !streamEntry.isCompleted) {\n this._scheduleGraceAbort(streamEntry);\n }\n\n // if the stream already finished (completed or errored), schedule\n // registry removal once the buffer TTL elapses so completed streams\n // don't accumulate in the registry forever\n this._scheduleRemovalAfterTTL(streamEntry);\n });\n\n await this._processGeneratorInBackground(streamEntry);\n\n // cleanup\n clearInterval(heartbeat);\n this.activeOperations.delete(streamOperation);\n }\n\n private async _processGeneratorInBackground(\n streamEntry: StreamEntry,\n ): Promise<void> {\n // run the entire generator processing within the captured trace context\n return context.with(streamEntry.traceContext, async () => {\n try {\n // retrieve all events from generator\n for await (const event of streamEntry.generator) {\n if (streamEntry.abortController.signal.aborted) break;\n const eventId = randomUUID();\n const eventData = JSON.stringify(event);\n const { maxEventSize } = streamEntry;\n\n // UTF-8 bytes, not `String.length`: non-ASCII payloads used to slip\n // past a limit they exceeded on the wire.\n if (Buffer.byteLength(eventData, \"utf8\") > maxEventSize) {\n const errorMsg = `Event exceeds max size of ${maxEventSize} bytes`;\n const errorCode = SSEErrorCode.INVALID_REQUEST;\n // broadcast error to all connected clients\n this._broadcastErrorToClients(\n streamEntry,\n eventId,\n errorMsg,\n errorCode,\n );\n continue;\n }\n\n // buffer event for reconnection\n streamEntry.eventBuffer.add({\n id: eventId,\n type: event.type,\n data: eventData,\n timestamp: Date.now(),\n });\n\n // broadcast to all connected clients\n this._broadcastEventsToClients(streamEntry, eventId, event);\n streamEntry.lastAccess = Date.now();\n }\n\n this._finalizeStream(streamEntry);\n } catch (error) {\n // Two distinct messages: a *raw* one for server-side logs (full\n // detail, statement fragments, correlation IDs) and a *client*\n // one for the SSE payload (sanitized, stable, safe to render in\n // a UI). Mixing them leaks upstream wording to anyone connected\n // to the stream — see CWE-209.\n const rawMsg =\n error instanceof Error ? error.message : \"Internal server error\";\n const clientMsg =\n error instanceof AppKitError\n ? error.clientMessage\n : \"Internal server error\";\n // Upstream structured code (e.g. RESULT_TOO_LARGE_FOR_JSON_FALLBACK,\n // NOT_IMPLEMENTED). UI should branch on this, not on `error`.\n const upstreamCode =\n error instanceof ExecutionError ? error.errorCode : undefined;\n const errorEventId = randomUUID();\n const errorCode = this._categorizeError(error);\n\n // client cancellation is a normal control-flow signal, not a failure\n if (errorCode === SSEErrorCode.STREAM_ABORTED) {\n logger.info(\"Stream aborted by client (code=%s)\", errorCode);\n this._finalizeStream(streamEntry);\n return;\n }\n\n logger.error(\n \"Stream execution failed: %s (code=%s upstreamCode=%s)\",\n rawMsg,\n errorCode,\n upstreamCode ?? \"n/a\",\n );\n\n const payload: Record<string, unknown> = {\n error: clientMsg,\n code: errorCode,\n };\n if (upstreamCode) payload.errorCode = upstreamCode;\n\n // buffer error event\n streamEntry.eventBuffer.add({\n id: errorEventId,\n type: \"error\",\n data: JSON.stringify(payload),\n timestamp: Date.now(),\n });\n\n // send error event to all connected clients\n this._broadcastErrorToClients(\n streamEntry,\n errorEventId,\n clientMsg,\n errorCode,\n true,\n upstreamCode,\n );\n // the broadcast above already ended the connected clients; finalize\n // still detaches them so removal is scheduled without waiting on a\n // transport `close` event\n this._finalizeStream(streamEntry);\n }\n });\n }\n\n private _combineSignals(\n internalSignal?: AbortSignal,\n userSignal?: AbortSignal,\n ): AbortSignal {\n if (!userSignal) return internalSignal || new AbortController().signal;\n\n const signals = [internalSignal, userSignal].filter(\n Boolean,\n ) as AbortSignal[];\n const controller = new AbortController();\n\n signals.forEach((signal) => {\n if (signal?.aborted) {\n controller.abort(signal.reason);\n return;\n }\n\n signal?.addEventListener(\n \"abort\",\n () => {\n controller.abort(signal.reason);\n },\n { once: true },\n );\n });\n return controller.signal;\n }\n\n // broadcast events to all connected clients\n private _broadcastEventsToClients(\n streamEntry: StreamEntry,\n eventId: string,\n event: any,\n ): void {\n for (const client of streamEntry.clients) {\n if (!client.writableEnded) {\n this.sseWriter.writeEvent(client, eventId, event);\n }\n }\n }\n\n // broadcast error to all connected clients\n private _broadcastErrorToClients(\n streamEntry: StreamEntry,\n eventId: string,\n errorMessage: string,\n errorCode: SSEErrorCode,\n closeClients: boolean = false,\n upstreamCode?: string,\n ): void {\n for (const client of streamEntry.clients) {\n if (!client.writableEnded) {\n this.sseWriter.writeError(\n client,\n eventId,\n errorMessage,\n errorCode,\n upstreamCode,\n );\n if (closeClients) {\n client.end();\n }\n }\n }\n }\n\n private _finalizeStream(streamEntry: StreamEntry): void {\n streamEntry.isCompleted = true;\n clearGraceTimer(streamEntry);\n this._closeAllClients(streamEntry);\n this._scheduleRemovalAfterTTL(streamEntry);\n }\n\n // close all connected clients and remove them from the stream entry.\n // We are deliberately terminating these connections, so cleanup must not\n // depend on the transport emitting a `close` event for each client (it may\n // never fire). The close handlers' later `clients.delete(...)` calls remain\n // safe no-ops.\n private _closeAllClients(streamEntry: StreamEntry): void {\n for (const client of streamEntry.clients) {\n if (!client.writableEnded) {\n client.end();\n }\n }\n streamEntry.clients.clear();\n }\n\n // abort the generator after the grace window unless a client reconnects first\n private _scheduleGraceAbort(streamEntry: StreamEntry): void {\n // clear any existing timer to avoid stacking\n clearGraceTimer(streamEntry);\n\n const timer = setTimeout(() => {\n streamEntry.disconnectGraceTimer = undefined;\n if (streamEntry.clients.size === 0 && !streamEntry.isCompleted) {\n streamEntry.abortController.abort(\n new DOMException(\"Client disconnected (grace expired)\", \"AbortError\"),\n );\n }\n }, this.disconnectGraceMs);\n\n // never keep the process alive solely for a grace timer\n timer.unref?.();\n streamEntry.disconnectGraceTimer = timer;\n }\n\n // schedule registry removal once a finished (completed or errored) stream\n // has no connected clients. The event buffer stays available for\n // reconnect replay for `bufferTTL` after the last client disconnects;\n // after that the stream entry is removed from the registry so it can be\n // garbage collected.\n private _scheduleRemovalAfterTTL(streamEntry: StreamEntry): void {\n if (!streamEntry.isCompleted || streamEntry.clients.size > 0) {\n return;\n }\n\n // at most one removal timer per stream: rescheduling replaces any\n // pending timer instead of stacking a new one (each pending timer pins\n // the entry's buffer/generator/trace context for the full TTL)\n clearRemovalTimer(streamEntry);\n\n // mark the moment the stream became idle so a reconnect during the TTL\n // window (which refreshes lastAccess) makes the pending timer a no-op\n streamEntry.lastAccess = Date.now();\n\n streamEntry.removalTimer = setTimeout(() => {\n streamEntry.removalTimer = undefined;\n // safety net: no-op if a client reconnected during the TTL window;\n // a fresh removal is scheduled when that client disconnects\n if (\n streamEntry.clients.size === 0 &&\n Date.now() - streamEntry.lastAccess >= this.bufferTTL\n ) {\n this.streamRegistry.remove(streamEntry.streamId);\n }\n }, this.bufferTTL);\n\n // don't keep the process alive just to clean up finished streams\n streamEntry.removalTimer.unref?.();\n }\n\n private _categorizeError(error: unknown): SSEErrorCode {\n if (error instanceof Error) {\n const message = error.message.toLowerCase();\n if (message.includes(\"timeout\") || message.includes(\"timed out\")) {\n return SSEErrorCode.TIMEOUT;\n }\n\n if (message.includes(\"unavailable\") || message.includes(\"econnrefused\")) {\n return SSEErrorCode.TEMPORARY_UNAVAILABLE;\n }\n\n if (error.name === \"AbortError\") {\n return SSEErrorCode.STREAM_ABORTED;\n }\n\n // Defense-in-depth: upstream layers (SQL client, cache) may wrap an\n // AbortError into ExecutionError, losing `name` but keeping the message.\n if (\n message.includes(\"operation was aborted\") ||\n message.includes(\"the request was aborted\") ||\n message.includes(\"statement was canceled\")\n ) {\n return SSEErrorCode.STREAM_ABORTED;\n }\n\n // Detect upstream API errors (e.g., from Databricks SDK ApiError)\n if (\n \"statusCode\" in error &&\n typeof (error as any).statusCode === \"number\"\n ) {\n return SSEErrorCode.UPSTREAM_ERROR;\n }\n }\n\n return SSEErrorCode.INTERNAL_ERROR;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,MAAM,SAAS,aAAa,SAAS;AAGrC,IAAa,gBAAb,MAA2B;CACzB,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,YAAY,SAAwB;AAClC,OAAK,iBAAiB,IAAI,eACxB,SAAS,oBAAoB,eAAe,iBAC7C;AACD,OAAK,YAAY,IAAI,WAAW;AAChC,OAAK,eAAe,SAAS,gBAAgB,eAAe;AAC5D,OAAK,YAAY,SAAS,aAAa,eAAe;AACtD,OAAK,oBACH,SAAS,qBAAqB,eAAe;AAC/C,OAAK,mCAAmB,IAAI,KAAK;;CAInC,MAAM,OACJ,KACA,SACA,SACA,UACe;EACf,MAAM,EAAE,aAAa,WAAW,EAAE;AAGlC,MAAI,IAAI,iBAAiB,IAAI,UAC3B;AAIF,OAAK,UAAU,aAAa,IAAI;AAGhC,MAAI,YAAY,gBAAgB,iBAAiB,SAAS,EAAE;GAC1D,MAAM,iBAAiB,KAAK,eAAe,IAAI,SAAS;AACxD,OAAI,gBAAgB;AAKlB,QAAI,eAAe,aAAa,UAAU;AACxC,UAAK,UAAU,WACb,KACA,YAAY,EACZ,qCACA,aAAa,iBACd;AACD,SAAI,KAAK;AACT;;AAEF,WAAO,KAAK,wBAAwB,KAAK,gBAAgB,QAAQ;;;AAKrE,SAAO,KAAK,iBAAiB,KAAK,SAAS,SAAS,SAAS;;CAI/D,WAAiB;AAEf,OAAK,iBAAiB,SAAS,cAAc;AAC3C,OAAI,UAAU,UAAW,eAAc,UAAU,UAAU;AAC3D,aAAU,WAAW,MACnB,IAAI,aAAa,mBAAmB,aAAa,CAClD;IACD;AACF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,MAAK,eAAe,OAAO,YAAY,SAAS;KAEjD,KAAK,UAAU;AAGlB,cAAY,aAAa,SAAS;;CAGpC,AAAQ,iBAAiB,OAA8B;AACrD,MAAI,iBAAiB,OAAO;GAC1B,MAAM,UAAU,MAAM,QAAQ,aAAa;AAC3C,OAAI,QAAQ,SAAS,UAAU,IAAI,QAAQ,SAAS,YAAY,CAC9D,QAAO,aAAa;AAGtB,OAAI,QAAQ,SAAS,cAAc,IAAI,QAAQ,SAAS,eAAe,CACrE,QAAO,aAAa;AAGtB,OAAI,MAAM,SAAS,aACjB,QAAO,aAAa;AAKtB,OACE,QAAQ,SAAS,wBAAwB,IACzC,QAAQ,SAAS,0BAA0B,IAC3C,QAAQ,SAAS,yBAAyB,CAE1C,QAAO,aAAa;AAItB,OACE,gBAAgB,SAChB,OAAQ,MAAc,eAAe,SAErC,QAAO,aAAa;;AAIxB,SAAO,aAAa"}
|
package/dist/stream/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../src/stream/types.ts"],"sourcesContent":["import type { Context } from \"@opentelemetry/api\";\nimport type { IAppResponse } from \"shared\";\n\nimport type { EventRingBuffer } from \"./buffers\";\n\nexport const SSEWarningCode = {\n BUFFER_OVERFLOW_RESTART: \"BUFFER_OVERFLOW_RESTART\",\n} as const satisfies Record<string, string>;\n\nexport type SSEWarningCode =\n (typeof SSEWarningCode)[keyof typeof SSEWarningCode];\n\nexport const SSEErrorCode = {\n TEMPORARY_UNAVAILABLE: \"TEMPORARY_UNAVAILABLE\",\n TIMEOUT: \"TIMEOUT\",\n INTERNAL_ERROR: \"INTERNAL_ERROR\",\n INVALID_REQUEST: \"INVALID_REQUEST\",\n STREAM_ABORTED: \"STREAM_ABORTED\",\n STREAM_EVICTED: \"STREAM_EVICTED\",\n STREAM_FORBIDDEN: \"STREAM_FORBIDDEN\",\n UPSTREAM_ERROR: \"UPSTREAM_ERROR\",\n} as const satisfies Record<string, string>;\n\nexport type SSEErrorCode = (typeof SSEErrorCode)[keyof typeof SSEErrorCode];\n\nexport interface SSEError {\n error: string;\n code: SSEErrorCode;\n /**\n * Upstream-domain structured code (e.g. `RESULT_TOO_LARGE_FOR_JSON_FALLBACK`,\n * `NOT_IMPLEMENTED`). UI code should branch on this instead of parsing\n * the human-readable `error` string.\n */\n errorCode?: string;\n}\n\nexport interface BufferedEvent {\n id: string;\n type: string;\n data: string;\n timestamp: number;\n}\n\nexport interface StreamEntry {\n streamId: string;\n /**\n * Identifier of the principal that created the stream (e.g. end-user ID\n * or service principal user ID). When set, only requests sharing the\n * same owner key may reconnect to the stream.\n */\n ownerKey?: string;\n generator: AsyncGenerator<any, void, unknown>;\n eventBuffer: EventRingBuffer;\n clients: Set<IAppResponse>;\n isCompleted: boolean;\n lastAccess: number;\n abortController: AbortController;\n traceContext: Context;\n // pending grace-window abort, set while the last client is disconnected\n disconnectGraceTimer?: NodeJS.Timeout;\n /**\n * Pending registry-removal timer. At most one removal timer exists per\n * stream; scheduling a new one clears any previous timer first.\n */\n removalTimer?: NodeJS.Timeout;\n}\n\nexport interface StreamOperation {\n controller: AbortController;\n type: \"query\" | \"stream\";\n heartbeat?: NodeJS.Timeout;\n}\n"],"mappings":";AAKA,MAAa,iBAAiB,EAC5B,yBAAyB,2BAC1B;AAKD,MAAa,eAAe;CAC1B,uBAAuB;CACvB,SAAS;CACT,gBAAgB;CAChB,iBAAiB;CACjB,gBAAgB;CAChB,gBAAgB;CAChB,kBAAkB;CAClB,gBAAgB;CACjB"}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/stream/types.ts"],"sourcesContent":["import type { Context } from \"@opentelemetry/api\";\nimport type { IAppResponse } from \"shared\";\n\nimport type { EventRingBuffer } from \"./buffers\";\n\nexport const SSEWarningCode = {\n BUFFER_OVERFLOW_RESTART: \"BUFFER_OVERFLOW_RESTART\",\n} as const satisfies Record<string, string>;\n\nexport type SSEWarningCode =\n (typeof SSEWarningCode)[keyof typeof SSEWarningCode];\n\nexport const SSEErrorCode = {\n TEMPORARY_UNAVAILABLE: \"TEMPORARY_UNAVAILABLE\",\n TIMEOUT: \"TIMEOUT\",\n INTERNAL_ERROR: \"INTERNAL_ERROR\",\n INVALID_REQUEST: \"INVALID_REQUEST\",\n STREAM_ABORTED: \"STREAM_ABORTED\",\n STREAM_EVICTED: \"STREAM_EVICTED\",\n STREAM_FORBIDDEN: \"STREAM_FORBIDDEN\",\n UPSTREAM_ERROR: \"UPSTREAM_ERROR\",\n} as const satisfies Record<string, string>;\n\nexport type SSEErrorCode = (typeof SSEErrorCode)[keyof typeof SSEErrorCode];\n\nexport interface SSEError {\n error: string;\n code: SSEErrorCode;\n /**\n * Upstream-domain structured code (e.g. `RESULT_TOO_LARGE_FOR_JSON_FALLBACK`,\n * `NOT_IMPLEMENTED`). UI code should branch on this instead of parsing\n * the human-readable `error` string.\n */\n errorCode?: string;\n}\n\nexport interface BufferedEvent {\n id: string;\n type: string;\n data: string;\n timestamp: number;\n}\n\nexport interface StreamEntry {\n streamId: string;\n /**\n * Identifier of the principal that created the stream (e.g. end-user ID\n * or service principal user ID). When set, only requests sharing the\n * same owner key may reconnect to the stream.\n */\n ownerKey?: string;\n generator: AsyncGenerator<any, void, unknown>;\n eventBuffer: EventRingBuffer;\n clients: Set<IAppResponse>;\n isCompleted: boolean;\n lastAccess: number;\n abortController: AbortController;\n traceContext: Context;\n /**\n * UTF-8 bytes. Lives on the entry, not on `StreamManager`: one manager is\n * shared by every stream a plugin opens, so reading it off the instance made\n * per-call overrides silently ineffective.\n */\n maxEventSize: number;\n // pending grace-window abort, set while the last client is disconnected\n disconnectGraceTimer?: NodeJS.Timeout;\n /**\n * Pending registry-removal timer. At most one removal timer exists per\n * stream; scheduling a new one clears any previous timer first.\n */\n removalTimer?: NodeJS.Timeout;\n}\n\nexport interface StreamOperation {\n controller: AbortController;\n type: \"query\" | \"stream\";\n heartbeat?: NodeJS.Timeout;\n}\n"],"mappings":";AAKA,MAAa,iBAAiB,EAC5B,yBAAyB,2BAC1B;AAKD,MAAa,eAAe;CAC1B,uBAAuB;CACvB,SAAS;CACT,gBAAgB;CAChB,iBAAiB;CACjB,gBAAgB;CAChB,gBAAgB;CAChB,kBAAkB;CAClB,gBAAgB;CACjB"}
|