@electric-ax/agents-server 0.4.11 → 0.4.13

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.
@@ -225,7 +225,7 @@ export class StreamClient {
225
225
 
226
226
  async create(
227
227
  path: string,
228
- opts: { contentType: string; body?: Uint8Array | string }
228
+ opts: { contentType: string; body?: Uint8Array | string; closed?: boolean }
229
229
  ): Promise<void> {
230
230
  return await withSpan(`stream.create`, async (span) => {
231
231
  span.setAttributes({
@@ -237,6 +237,7 @@ export class StreamClient {
237
237
  headers: this.streamHeaders(),
238
238
  contentType: opts.contentType,
239
239
  body: opts.body,
240
+ closed: opts.closed,
240
241
  })
241
242
  })
242
243
  }
@@ -368,38 +369,18 @@ export class StreamClient {
368
369
  offset: fromOffset ?? `-1`,
369
370
  live: false,
370
371
  })
371
- const messages: Array<StreamMessage> = []
372
-
373
- return await new Promise<StreamReadResult>((resolve, reject) => {
374
- let settled = false
375
- let unsub = () => {}
376
-
377
- const finish = (r: StreamReadResult) => {
378
- if (settled) return
379
- settled = true
380
- unsub()
381
- resolve(r)
382
- }
383
-
384
- unsub = response.subscribeBytes((chunk) => {
385
- messages.push({
386
- data: chunk.data,
387
- offset: chunk.offset,
388
- })
389
- if (chunk.upToDate || chunk.streamClosed) {
390
- finish({ messages })
391
- }
392
- })
393
-
394
- response.closed
395
- .then(() => finish({ messages }))
396
- .catch((err) => {
397
- if (settled) return
398
- settled = true
399
- unsub()
400
- reject(err)
401
- })
402
- })
372
+ const body = await response.body()
373
+ return {
374
+ messages:
375
+ body.length === 0
376
+ ? []
377
+ : [
378
+ {
379
+ data: body,
380
+ offset: response.offset,
381
+ },
382
+ ],
383
+ }
403
384
  })
404
385
  }
405
386