@@ -19,7 +19,8 @@ export interface RunOptions {
19
19
threadId ?: string ;
20
20
rawResponse ?: boolean ;
21
21
runTools ?: boolean ;
22
- name ?: string ; // Pipe name for SDK
22
+ name ?: string ; // Pipe name for SDK,
23
+ apiKey ?: string ; // pipe level key for SDK
23
24
}
24
25
25
26
export interface RunOptionsStream extends RunOptions {
@@ -83,12 +84,16 @@ export class Pipe {
83
84
private maxCalls : number ;
84
85
private hasTools : boolean ;
85
86
private prod : boolean ;
87
+ private baseUrl : string ;
86
88
87
89
constructor ( options : PipeOptions ) {
88
90
this . prod = options . prod ?? isProd ( ) ;
89
- const baseUrl = getApiUrl ( this . prod ) ;
91
+ this . baseUrl = getApiUrl ( this . prod ) ;
90
92
91
- this . request = new Request ( { apiKey : options . apiKey , baseUrl} ) ;
93
+ this . request = new Request ( {
94
+ apiKey : options . apiKey ,
95
+ baseUrl : this . baseUrl ,
96
+ } ) ;
92
97
this . pipe = options ;
93
98
94
99
delete this . pipe . prod ;
@@ -163,7 +168,6 @@ export class Pipe {
163
168
private async handleStreamResponse (
164
169
options : RunOptionsStream ,
165
170
response : RunResponseStream ,
166
- pipeName : string ,
167
171
) : Promise < RunResponseStream > {
168
172
const endpoint = '/v1/pipes/run' ;
169
173
const stream = this . isStreamRequested ( options ) ;
@@ -218,7 +222,6 @@ export class Pipe {
218
222
messages,
219
223
threadId : currentResponse . threadId ,
220
224
} ,
221
- pipeName
222
225
) ;
223
226
224
227
callCount ++ ;
@@ -247,7 +250,21 @@ export class Pipe {
247
250
const modelProvider = getProvider ( providerString ) ;
248
251
const isAnthropic = modelProvider === ANTHROPIC ;
249
252
const hasTools = this . pipe . tools . length > 0 ;
250
- const pipeName = options . name || this . pipe . name ;
253
+
254
+ // For SDK
255
+ // Run the given pipe name
256
+ if ( options . name ) {
257
+ this . pipe = { ...this . pipe , name : options . name } ;
258
+ }
259
+
260
+ // For SDK
261
+ // Run the pipe against the given Pipe API key
262
+ if ( options . apiKey ) {
263
+ this . request = new Request ( {
264
+ apiKey : options . apiKey ,
265
+ baseUrl : this . baseUrl ,
266
+ } ) ;
267
+ }
251
268
252
269
let stream = this . isStreamRequested ( options ) ;
253
270
@@ -264,7 +281,7 @@ export class Pipe {
264
281
265
282
let response = await this . createRequest <
266
283
RunResponse | RunResponseStream
267
- > ( endpoint , body , pipeName ) ;
284
+ > ( endpoint , body ) ;
268
285
if ( Object . entries ( response ) . length === 0 ) {
269
286
return { } as RunResponse | RunResponseStream ;
270
287
}
@@ -281,7 +298,6 @@ export class Pipe {
281
298
return await this . handleStreamResponse (
282
299
options as RunOptionsStream ,
283
300
response as RunResponseStream ,
284
- pipeName
285
301
) ;
286
302
}
287
303
@@ -324,7 +340,7 @@ export class Pipe {
324
340
messages,
325
341
stream : false ,
326
342
threadId : currentResponse . threadId ,
327
- } , pipeName ) ;
343
+ } ) ;
328
344
329
345
callCount ++ ;
330
346
@@ -343,17 +359,13 @@ export class Pipe {
343
359
return currentResponse ;
344
360
}
345
361
346
- private async createRequest < T > (
347
- endpoint : string ,
348
- body : any ,
349
- pipeName ?: string ,
350
- ) : Promise < T > {
362
+ private async createRequest < T > ( endpoint : string , body : any ) : Promise < T > {
351
363
const isProdEnv = this . prod ;
352
364
const prodOptions = {
353
365
endpoint,
354
366
body : {
355
367
...body ,
356
- name : pipeName || this . pipe . name ,
368
+ name : this . pipe . name ,
357
369
} ,
358
370
} ;
359
371
0 commit comments