@bagelink/sdk 1.15.168 → 1.15.170
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/index.cjs +9 -7
- package/dist/index.mjs +9 -7
- package/package.json +1 -1
- package/src/openAPITools/streamClient.ts +19 -9
package/dist/index.cjs
CHANGED
|
@@ -1342,6 +1342,9 @@ function createSSEStream(url, options = {}) {
|
|
|
1342
1342
|
const reader = response.body.getReader();
|
|
1343
1343
|
const decoder = new TextDecoder();
|
|
1344
1344
|
let buffer = "";
|
|
1345
|
+
let currentEvent = "message";
|
|
1346
|
+
let currentData = "";
|
|
1347
|
+
let currentId;
|
|
1345
1348
|
try {
|
|
1346
1349
|
while (true) {
|
|
1347
1350
|
const { done, value } = await reader.read();
|
|
@@ -1355,16 +1358,14 @@ function createSSEStream(url, options = {}) {
|
|
|
1355
1358
|
buffer += decoder.decode(value, { stream: true });
|
|
1356
1359
|
const lines = buffer.split("\n");
|
|
1357
1360
|
buffer = lines.pop() || "";
|
|
1358
|
-
let currentEvent = "message";
|
|
1359
|
-
let currentData = "";
|
|
1360
|
-
let currentId;
|
|
1361
1361
|
for (const line of lines) {
|
|
1362
1362
|
if (line.startsWith("id:")) {
|
|
1363
1363
|
currentId = line.slice(3).trim();
|
|
1364
1364
|
} else if (line.startsWith("event:")) {
|
|
1365
1365
|
currentEvent = line.slice(6).trim();
|
|
1366
1366
|
} else if (line.startsWith("data:")) {
|
|
1367
|
-
currentData =
|
|
1367
|
+
currentData = currentData ? `${currentData}
|
|
1368
|
+
${line.slice(5).trim()}` : line.slice(5).trim();
|
|
1368
1369
|
} else if (line === "" && currentData) {
|
|
1369
1370
|
if (currentId !== void 0) lastEventId = currentId;
|
|
1370
1371
|
try {
|
|
@@ -1439,6 +1440,8 @@ function createSSEStreamPost(url, body, options = {}) {
|
|
|
1439
1440
|
const reader = response.body.getReader();
|
|
1440
1441
|
const decoder = new TextDecoder();
|
|
1441
1442
|
let buffer = "";
|
|
1443
|
+
let currentEvent = "message";
|
|
1444
|
+
let currentData = "";
|
|
1442
1445
|
try {
|
|
1443
1446
|
while (true) {
|
|
1444
1447
|
const { done, value } = await reader.read();
|
|
@@ -1450,13 +1453,12 @@ function createSSEStreamPost(url, body, options = {}) {
|
|
|
1450
1453
|
buffer += decoder.decode(value, { stream: true });
|
|
1451
1454
|
const lines = buffer.split("\n");
|
|
1452
1455
|
buffer = lines.pop() || "";
|
|
1453
|
-
let currentEvent = "message";
|
|
1454
|
-
let currentData = "";
|
|
1455
1456
|
for (const line of lines) {
|
|
1456
1457
|
if (line.startsWith("event:")) {
|
|
1457
1458
|
currentEvent = line.slice(6).trim();
|
|
1458
1459
|
} else if (line.startsWith("data:")) {
|
|
1459
|
-
currentData =
|
|
1460
|
+
currentData = currentData ? `${currentData}
|
|
1461
|
+
${line.slice(5).trim()}` : line.slice(5).trim();
|
|
1460
1462
|
} else if (line === "" && currentData) {
|
|
1461
1463
|
try {
|
|
1462
1464
|
const parsed = JSON.parse(currentData);
|
package/dist/index.mjs
CHANGED
|
@@ -1336,6 +1336,9 @@ function createSSEStream(url, options = {}) {
|
|
|
1336
1336
|
const reader = response.body.getReader();
|
|
1337
1337
|
const decoder = new TextDecoder();
|
|
1338
1338
|
let buffer = "";
|
|
1339
|
+
let currentEvent = "message";
|
|
1340
|
+
let currentData = "";
|
|
1341
|
+
let currentId;
|
|
1339
1342
|
try {
|
|
1340
1343
|
while (true) {
|
|
1341
1344
|
const { done, value } = await reader.read();
|
|
@@ -1349,16 +1352,14 @@ function createSSEStream(url, options = {}) {
|
|
|
1349
1352
|
buffer += decoder.decode(value, { stream: true });
|
|
1350
1353
|
const lines = buffer.split("\n");
|
|
1351
1354
|
buffer = lines.pop() || "";
|
|
1352
|
-
let currentEvent = "message";
|
|
1353
|
-
let currentData = "";
|
|
1354
|
-
let currentId;
|
|
1355
1355
|
for (const line of lines) {
|
|
1356
1356
|
if (line.startsWith("id:")) {
|
|
1357
1357
|
currentId = line.slice(3).trim();
|
|
1358
1358
|
} else if (line.startsWith("event:")) {
|
|
1359
1359
|
currentEvent = line.slice(6).trim();
|
|
1360
1360
|
} else if (line.startsWith("data:")) {
|
|
1361
|
-
currentData =
|
|
1361
|
+
currentData = currentData ? `${currentData}
|
|
1362
|
+
${line.slice(5).trim()}` : line.slice(5).trim();
|
|
1362
1363
|
} else if (line === "" && currentData) {
|
|
1363
1364
|
if (currentId !== void 0) lastEventId = currentId;
|
|
1364
1365
|
try {
|
|
@@ -1433,6 +1434,8 @@ function createSSEStreamPost(url, body, options = {}) {
|
|
|
1433
1434
|
const reader = response.body.getReader();
|
|
1434
1435
|
const decoder = new TextDecoder();
|
|
1435
1436
|
let buffer = "";
|
|
1437
|
+
let currentEvent = "message";
|
|
1438
|
+
let currentData = "";
|
|
1436
1439
|
try {
|
|
1437
1440
|
while (true) {
|
|
1438
1441
|
const { done, value } = await reader.read();
|
|
@@ -1444,13 +1447,12 @@ function createSSEStreamPost(url, body, options = {}) {
|
|
|
1444
1447
|
buffer += decoder.decode(value, { stream: true });
|
|
1445
1448
|
const lines = buffer.split("\n");
|
|
1446
1449
|
buffer = lines.pop() || "";
|
|
1447
|
-
let currentEvent = "message";
|
|
1448
|
-
let currentData = "";
|
|
1449
1450
|
for (const line of lines) {
|
|
1450
1451
|
if (line.startsWith("event:")) {
|
|
1451
1452
|
currentEvent = line.slice(6).trim();
|
|
1452
1453
|
} else if (line.startsWith("data:")) {
|
|
1453
|
-
currentData =
|
|
1454
|
+
currentData = currentData ? `${currentData}
|
|
1455
|
+
${line.slice(5).trim()}` : line.slice(5).trim();
|
|
1454
1456
|
} else if (line === "" && currentData) {
|
|
1455
1457
|
try {
|
|
1456
1458
|
const parsed = JSON.parse(currentData);
|
package/package.json
CHANGED
|
@@ -105,6 +105,16 @@ export function createSSEStream<TEventMap extends StreamEventMap = StreamEventMa
|
|
|
105
105
|
const decoder = new TextDecoder()
|
|
106
106
|
let buffer = ''
|
|
107
107
|
|
|
108
|
+
// SSE parser state MUST live across read() chunks: a single event's
|
|
109
|
+
// `event:`/`data:` lines and its terminating blank line can be split over
|
|
110
|
+
// multiple network chunks (very common for large payloads such as big
|
|
111
|
+
// tool_result blobs). Re-initialising these per chunk would drop or
|
|
112
|
+
// mis-attribute those events, making large results appear to only "arrive"
|
|
113
|
+
// once the whole response flushes at the end.
|
|
114
|
+
let currentEvent = 'message'
|
|
115
|
+
let currentData = ''
|
|
116
|
+
let currentId: string | undefined
|
|
117
|
+
|
|
108
118
|
try {
|
|
109
119
|
while (true) {
|
|
110
120
|
const { done, value } = await reader.read()
|
|
@@ -122,17 +132,15 @@ export function createSSEStream<TEventMap extends StreamEventMap = StreamEventMa
|
|
|
122
132
|
const lines = buffer.split('\n')
|
|
123
133
|
buffer = lines.pop() || ''
|
|
124
134
|
|
|
125
|
-
let currentEvent = 'message'
|
|
126
|
-
let currentData = ''
|
|
127
|
-
let currentId: string | undefined
|
|
128
|
-
|
|
129
135
|
for (const line of lines) {
|
|
130
136
|
if (line.startsWith('id:')) {
|
|
131
137
|
currentId = line.slice(3).trim()
|
|
132
138
|
} else if (line.startsWith('event:')) {
|
|
133
139
|
currentEvent = line.slice(6).trim()
|
|
134
140
|
} else if (line.startsWith('data:')) {
|
|
135
|
-
|
|
141
|
+
// Accumulate multi-line data fields per the SSE spec instead of
|
|
142
|
+
// overwriting, so multi-line `data:` payloads survive intact.
|
|
143
|
+
currentData = currentData ? `${currentData}\n${line.slice(5).trim()}` : line.slice(5).trim()
|
|
136
144
|
} else if (line === '' && currentData) {
|
|
137
145
|
// Track last seen ID for reconnect
|
|
138
146
|
if (currentId !== undefined) lastEventId = currentId
|
|
@@ -235,6 +243,11 @@ export function createSSEStreamPost<TEventMap extends StreamEventMap = StreamEve
|
|
|
235
243
|
const decoder = new TextDecoder()
|
|
236
244
|
let buffer = ''
|
|
237
245
|
|
|
246
|
+
// Parser state must persist across chunks — a single SSE event (esp. a
|
|
247
|
+
// large tool_result) can be split over multiple network reads.
|
|
248
|
+
let currentEvent = 'message'
|
|
249
|
+
let currentData = ''
|
|
250
|
+
|
|
238
251
|
try {
|
|
239
252
|
while (true) {
|
|
240
253
|
const { done, value } = await reader.read()
|
|
@@ -252,14 +265,11 @@ export function createSSEStreamPost<TEventMap extends StreamEventMap = StreamEve
|
|
|
252
265
|
const lines = buffer.split('\n')
|
|
253
266
|
buffer = lines.pop() || '' // Keep incomplete line in buffer
|
|
254
267
|
|
|
255
|
-
let currentEvent = 'message'
|
|
256
|
-
let currentData = ''
|
|
257
|
-
|
|
258
268
|
for (const line of lines) {
|
|
259
269
|
if (line.startsWith('event:')) {
|
|
260
270
|
currentEvent = line.slice(6).trim()
|
|
261
271
|
} else if (line.startsWith('data:')) {
|
|
262
|
-
currentData = line.slice(5).trim()
|
|
272
|
+
currentData = currentData ? `${currentData}\n${line.slice(5).trim()}` : line.slice(5).trim()
|
|
263
273
|
} else if (line === '' && currentData) {
|
|
264
274
|
// Empty line indicates end of event - emit immediately
|
|
265
275
|
try {
|