|
1 | 1 | import type { Streamer } from '@workflow/world'; |
2 | 2 | import { type APIConfig, getHttpConfig, type HttpConfig } from './utils.js'; |
3 | 3 |
|
4 | | -function getStreamUrl(name: string, httpConfig: HttpConfig) { |
5 | | - return new URL(`${httpConfig.baseUrl}/v1/stream/${encodeURIComponent(name)}`); |
| 4 | +function getStreamUrl(runId: string, name: string, httpConfig: HttpConfig) { |
| 5 | + return new URL( |
| 6 | + `${httpConfig.baseUrl}/v1/run/${runId}/stream/${encodeURIComponent(name)}` |
| 7 | + ); |
6 | 8 | } |
7 | 9 |
|
8 | 10 | export function createStreamer(config?: APIConfig): Streamer { |
9 | 11 | return { |
10 | 12 | async writeToStream( |
11 | | - _runId: string, |
| 13 | + runId: string, |
12 | 14 | name: string, |
13 | 15 | chunk: string | Uint8Array |
14 | 16 | ) { |
15 | 17 | const httpConfig = await getHttpConfig(config); |
16 | | - await fetch(getStreamUrl(name, httpConfig), { |
| 18 | + await fetch(getStreamUrl(runId, name, httpConfig), { |
17 | 19 | method: 'PUT', |
18 | 20 | body: chunk, |
19 | 21 | headers: httpConfig.headers, |
20 | 22 | duplex: 'half', |
21 | 23 | }); |
22 | 24 | }, |
23 | 25 |
|
24 | | - async closeStream(_runId: string, name: string) { |
| 26 | + async closeStream(runId: string, name: string) { |
25 | 27 | const httpConfig = await getHttpConfig(config); |
26 | 28 | httpConfig.headers.set('X-Stream-Done', 'true'); |
27 | | - await fetch(getStreamUrl(name, httpConfig), { |
| 29 | + await fetch(getStreamUrl(runId, name, httpConfig), { |
28 | 30 | method: 'PUT', |
29 | 31 | headers: httpConfig.headers, |
30 | 32 | }); |
31 | 33 | }, |
32 | 34 |
|
33 | | - async readFromStream(_runId: string, name: string, startIndex?: number) { |
| 35 | + async readFromStream(runId: string, name: string, startIndex?: number) { |
34 | 36 | const httpConfig = await getHttpConfig(config); |
35 | | - const url = getStreamUrl(name, httpConfig); |
| 37 | + const url = getStreamUrl(runId, name, httpConfig); |
36 | 38 | if (typeof startIndex === 'number') { |
37 | 39 | url.searchParams.set('startIndex', String(startIndex)); |
38 | 40 | } |
|
0 commit comments