@@ -7,6 +7,8 @@ import { MetadataStream } from "./metadataStream.js";
77import { ApiClient } from "../apiClient/index.js" ;
88import { FlushedRunMetadata , RunMetadataChangeOperation } from "../schemas/common.js" ;
99import { applyMetadataOperations } from "./operations.js" ;
10+ import { SSEStreamSubscriptionFactory } from "../apiClient/runStream.js" ;
11+ import { AsyncIterableStream } from "../apiClient/stream.js" ;
1012
1113const MAXIMUM_ACTIVE_STREAMS = 5 ;
1214const MAXIMUM_TOTAL_STREAMS = 10 ;
@@ -197,6 +199,25 @@ export class StandardMetadataManager implements RunMetadataManager {
197199 return this . doStream ( key , value , "self" , this , signal ) ;
198200 }
199201
202+ public async fetchStream < T > ( key : string , signal ?: AbortSignal ) : Promise < AsyncIterableStream < T > > {
203+ if ( ! this . runId ) {
204+ throw new Error ( "Run ID is required to fetch metadata streams." ) ;
205+ }
206+
207+ const baseUrl = this . getKey ( "$$streamsBaseUrl" ) ;
208+
209+ const $baseUrl = typeof baseUrl === "string" ? baseUrl : this . streamsBaseUrl ;
210+
211+ const streamFactory = new SSEStreamSubscriptionFactory ( $baseUrl , {
212+ headers : this . apiClient . getHeaders ( ) ,
213+ signal,
214+ } ) ;
215+
216+ const subscription = streamFactory . createSubscription ( this . store ?? { } , this . runId , key ) ;
217+
218+ return ( await subscription . subscribe ( ) ) as AsyncIterableStream < T > ;
219+ }
220+
200221 private async doStream < T > (
201222 key : string ,
202223 value : AsyncIterable < T > | ReadableStream < T > ,
0 commit comments