Skip to content

Commit f9be1b6

Browse files
Fix streamer URL
1 parent 69ae717 commit f9be1b6

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

packages/world-vercel/src/streamer.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
11
import type { Streamer } from '@workflow/world';
22
import { type APIConfig, getHttpConfig, type HttpConfig } from './utils.js';
33

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+
);
68
}
79

810
export function createStreamer(config?: APIConfig): Streamer {
911
return {
1012
async writeToStream(
11-
_runId: string,
13+
runId: string,
1214
name: string,
1315
chunk: string | Uint8Array
1416
) {
1517
const httpConfig = await getHttpConfig(config);
16-
await fetch(getStreamUrl(name, httpConfig), {
18+
await fetch(getStreamUrl(runId, name, httpConfig), {
1719
method: 'PUT',
1820
body: chunk,
1921
headers: httpConfig.headers,
2022
duplex: 'half',
2123
});
2224
},
2325

24-
async closeStream(_runId: string, name: string) {
26+
async closeStream(runId: string, name: string) {
2527
const httpConfig = await getHttpConfig(config);
2628
httpConfig.headers.set('X-Stream-Done', 'true');
27-
await fetch(getStreamUrl(name, httpConfig), {
29+
await fetch(getStreamUrl(runId, name, httpConfig), {
2830
method: 'PUT',
2931
headers: httpConfig.headers,
3032
});
3133
},
3234

33-
async readFromStream(_runId: string, name: string, startIndex?: number) {
35+
async readFromStream(runId: string, name: string, startIndex?: number) {
3436
const httpConfig = await getHttpConfig(config);
35-
const url = getStreamUrl(name, httpConfig);
37+
const url = getStreamUrl(runId, name, httpConfig);
3638
if (typeof startIndex === 'number') {
3739
url.searchParams.set('startIndex', String(startIndex));
3840
}

0 commit comments

Comments
 (0)