@@ -70,13 +70,13 @@ function hasTypeProperty(item: unknown): item is {
7070 ) ;
7171}
7272
73- export interface GetResponseOptions < TOOLS extends readonly Tool [ ] > {
73+ export interface GetResponseOptions < TTools extends readonly Tool [ ] > {
7474 // Request can have async functions that will be resolved before sending to API
75- request : CallModelInput < TOOLS > ;
75+ request : CallModelInput < TTools > ;
7676 client : OpenRouterCore ;
7777 options ?: RequestOptions ;
78- tools ?: TOOLS ;
79- stopWhen ?: StopWhen < TOOLS > ;
78+ tools ?: TTools ;
79+ stopWhen ?: StopWhen < TTools > ;
8080}
8181
8282/**
@@ -96,13 +96,13 @@ export interface GetResponseOptions<TOOLS extends readonly Tool[]> {
9696 * All consumption patterns can be used concurrently thanks to the underlying
9797 * ReusableReadableStream implementation.
9898 *
99- * @template TOOLS - The tools array type to enable typed tool calls and results
99+ * @template TTools - The tools array type to enable typed tool calls and results
100100 */
101- export class ModelResult < TOOLS extends readonly Tool [ ] > {
101+ export class ModelResult < TTools extends readonly Tool [ ] > {
102102 private reusableStream : ReusableReadableStream < models . OpenResponsesStreamEvent > | null = null ;
103103 private streamPromise : Promise < EventStream < models . OpenResponsesStreamEvent > > | null = null ;
104104 private textPromise : Promise < string > | null = null ;
105- private options : GetResponseOptions < TOOLS > ;
105+ private options : GetResponseOptions < TTools > ;
106106 private initPromise : Promise < void > | null = null ;
107107 private toolExecutionPromise : Promise < void > | null = null ;
108108 private finalResponse : models . OpenResponsesNonStreamingResponse | null = null ;
@@ -116,7 +116,7 @@ export class ModelResult<TOOLS extends readonly Tool[]> {
116116 // Track resolved request after async function resolution
117117 private resolvedRequest : models . OpenResponsesRequest | null = null ;
118118
119- constructor ( options : GetResponseOptions < TOOLS > ) {
119+ constructor ( options : GetResponseOptions < TTools > ) {
120120 this . options = options ;
121121 }
122122
@@ -482,8 +482,8 @@ export class ModelResult<TOOLS extends readonly Tool[]> {
482482 * Multiple consumers can iterate over this stream concurrently.
483483 * Includes preliminary tool result events after tool execution.
484484 */
485- getFullResponsesStream ( ) : AsyncIterableIterator < ResponseStreamEvent < InferToolEventsUnion < TOOLS > > > {
486- return async function * ( this : ModelResult < TOOLS > ) {
485+ getFullResponsesStream ( ) : AsyncIterableIterator < ResponseStreamEvent < InferToolEventsUnion < TTools {
486+ return async function * ( this : ModelResult < TTools > ) {
487487 await this . initStream ( ) ;
488488 if ( ! this . reusableStream ) {
489489 throw new Error ( 'Stream not initialized' ) ;
@@ -505,7 +505,7 @@ export class ModelResult<TOOLS extends readonly Tool[]> {
505505 yield {
506506 type : 'tool.preliminary_result' as const ,
507507 toolCallId,
508- result : result as InferToolEventsUnion < TOOLS > ,
508+ result : result as InferToolEventsUnion < TTools > ,
509509 timestamp : Date . now ( ) ,
510510 } ;
511511 }
@@ -518,7 +518,7 @@ export class ModelResult<TOOLS extends readonly Tool[]> {
518518 * This filters the full event stream to only yield text content.
519519 */
520520 getTextStream ( ) : AsyncIterableIterator < string > {
521- return async function * ( this : ModelResult < TOOLS > ) {
521+ return async function * ( this : ModelResult < TTools > ) {
522522 await this . initStream ( ) ;
523523 if ( ! this . reusableStream ) {
524524 throw new Error ( 'Stream not initialized' ) ;
@@ -537,7 +537,7 @@ export class ModelResult<TOOLS extends readonly Tool[]> {
537537 getNewMessagesStream ( ) : AsyncIterableIterator <
538538 models . ResponsesOutputMessage | models . OpenResponsesFunctionCallOutput
539539 > {
540- return async function * ( this : ModelResult < TOOLS > ) {
540+ return async function * ( this : ModelResult < TTools > ) {
541541 await this . initStream ( ) ;
542542 if ( ! this . reusableStream ) {
543543 throw new Error ( 'Stream not initialized' ) ;
@@ -575,7 +575,7 @@ export class ModelResult<TOOLS extends readonly Tool[]> {
575575 * This filters the full event stream to only yield reasoning content.
576576 */
577577 getReasoningStream ( ) : AsyncIterableIterator < string > {
578- return async function * ( this : ModelResult < TOOLS > ) {
578+ return async function * ( this : ModelResult < TTools > ) {
579579 await this . initStream ( ) ;
580580 if ( ! this . reusableStream ) {
581581 throw new Error ( 'Stream not initialized' ) ;
@@ -591,8 +591,8 @@ export class ModelResult<TOOLS extends readonly Tool[]> {
591591 * - Tool call argument deltas as { type: "delta", content: string }
592592 * - Preliminary results as { type: "preliminary_result", toolCallId, result }
593593 */
594- getToolStream ( ) : AsyncIterableIterator < ToolStreamEvent < InferToolEventsUnion < TOOLS > > > {
595- return async function * ( this : ModelResult < TOOLS > ) {
594+ getToolStream ( ) : AsyncIterableIterator < ToolStreamEvent < InferToolEventsUnion < TTools >>> {
595+ return async function * ( this : ModelResult < TTools > ) {
596596 await this . initStream ( ) ;
597597 if ( ! this . reusableStream ) {
598598 throw new Error ( 'Stream not initialized' ) ;
@@ -615,7 +615,7 @@ export class ModelResult<TOOLS extends readonly Tool[]> {
615615 yield {
616616 type : 'preliminary_result' as const ,
617617 toolCallId,
618- result : result as InferToolEventsUnion < TOOLS > ,
618+ result : result as InferToolEventsUnion < TTools > ,
619619 } ;
620620 }
621621 }
@@ -628,28 +628,28 @@ export class ModelResult<TOOLS extends readonly Tool[]> {
628628 * and this will return the tool calls from the initial response.
629629 * Returns structured tool calls with parsed arguments.
630630 */
631- async getToolCalls ( ) : Promise < ParsedToolCall < TOOLS [ number ] > [ ] > {
631+ async getToolCalls ( ) : Promise < ParsedToolCall < TTools [ number ] > [ ] > {
632632 await this . initStream ( ) ;
633633 if ( ! this . reusableStream ) {
634634 throw new Error ( 'Stream not initialized' ) ;
635635 }
636636
637637 const completedResponse = await consumeStreamForCompletion ( this . reusableStream ) ;
638- return extractToolCallsFromResponse ( completedResponse ) as ParsedToolCall < TOOLS [ number ] > [ ] ;
638+ return extractToolCallsFromResponse ( completedResponse ) as ParsedToolCall < TTools [ number ] > [ ] ;
639639 }
640640
641641 /**
642642 * Stream structured tool call objects as they're completed.
643643 * Each iteration yields a complete tool call with parsed arguments.
644644 */
645- getToolCallsStream ( ) : AsyncIterableIterator < ParsedToolCall < TOOLS [ number ] > > {
646- return async function * ( this : ModelResult < TOOLS > ) {
645+ getToolCallsStream ( ) : AsyncIterableIterator < ParsedToolCall < TTools [ number ] >> {
646+ return async function * ( this : ModelResult < TTools > ) {
647647 await this . initStream ( ) ;
648648 if ( ! this . reusableStream ) {
649649 throw new Error ( 'Stream not initialized' ) ;
650650 }
651651
652- yield * buildToolCallStream ( this . reusableStream ) as AsyncIterableIterator < ParsedToolCall < TOOLS [ number ] > > ;
652+ yield * buildToolCallStream ( this . reusableStream ) as AsyncIterableIterator < ParsedToolCall < TTools [ number ] > > ;
653653 } . call ( this ) ;
654654 }
655655
0 commit comments