Skip to content

Commit f530180

Browse files
TOOLS -> TTools
1 parent 7a42ef6 commit f530180

File tree

6 files changed

+51
-51
lines changed

6 files changed

+51
-51
lines changed

src/funcs/call-model.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ export type { CallModelInput } from '../lib/async-params.js';
119119
*
120120
* Default: `stepCountIs(5)` if not specified
121121
*/
122-
export function callModel<TOOLS extends readonly Tool[]>(
122+
export function callModel<TTools extends readonly Tool[]>(
123123
client: OpenRouterCore,
124-
request: CallModelInput<TOOLS>,
124+
request: CallModelInput<TTools>,
125125
options?: RequestOptions,
126-
): ModelResult<TOOLS> {
126+
): ModelResult<TTools> {
127127
const { tools, stopWhen, ...apiRequest } = request;
128128

129129
// Convert tools to API format - no cast needed now that convertToolsToAPIFormat accepts readonly
@@ -140,14 +140,14 @@ export function callModel<TOOLS extends readonly Tool[]>(
140140
finalRequest['tools'] = apiTools;
141141
}
142142

143-
return new ModelResult<TOOLS>({
143+
return new ModelResult<TTools>({
144144
client,
145145
request: finalRequest,
146146
options: options ?? {},
147-
// Preserve the exact TOOLS type instead of widening to Tool[]
148-
tools: tools as TOOLS | undefined,
147+
// Preserve the exact TTools type instead of widening to Tool[]
148+
tools: tools as TTools | undefined,
149149
...(stopWhen !== undefined && {
150150
stopWhen,
151151
}),
152-
} as GetResponseOptions<TOOLS>);
152+
} as GetResponseOptions<TTools>);
153153
}

src/lib/async-params.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ export type FieldOrAsyncFunction<T> = T | ((context: TurnContext) => T | Promise
3131
/**
3232
* Input type for callModel function
3333
* Each field can independently be a static value or a function that computes the value
34-
* Generic over TOOLS to enable proper type inference for stopWhen conditions
34+
* Generic over TTools to enable proper type inference for stopWhen conditions
3535
*/
36-
export type CallModelInput<TOOLS extends readonly Tool[] = readonly Tool[]> = {
36+
export type CallModelInput<TTools extends readonly Tool[] = readonly Tool[]> = {
3737
[K in keyof Omit<models.OpenResponsesRequest, 'stream' | 'tools'>]?: FieldOrAsyncFunction<
3838
models.OpenResponsesRequest[K]
3939
>;
4040
} & {
41-
tools?: TOOLS;
42-
stopWhen?: StopWhen<TOOLS>;
41+
tools?: TTools;
42+
stopWhen?: StopWhen<TTools>;
4343
};
4444

4545
/**

src/lib/model-result.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/lib/stop-conditions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ export function hasToolCall(toolName: string): StopCondition {
4646
* });
4747
* ```
4848
*/
49-
export async function isStopConditionMet<TOOLS extends readonly Tool[]>(options: {
50-
readonly stopConditions: ReadonlyArray<StopCondition<TOOLS>>;
51-
readonly steps: ReadonlyArray<StepResult<TOOLS>>;
49+
export async function isStopConditionMet<TTools extends readonly Tool[]>(options: {
50+
readonly stopConditions: ReadonlyArray<StopCondition<TTools>>;
51+
readonly steps: ReadonlyArray<StepResult<TTools>>;
5252
}): Promise<boolean> {
5353
const { stopConditions, steps } = options;
5454

5555
// Evaluate all conditions in parallel
5656
const results = await Promise.all(
57-
stopConditions.map((condition: StopCondition<TOOLS>) =>
57+
stopConditions.map((condition: StopCondition<TTools>) =>
5858
Promise.resolve(
5959
condition({
6060
steps,

src/lib/tool-types.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,11 @@ export interface Warning {
294294
* Result of a single step in the tool execution loop
295295
* Compatible with Vercel AI SDK pattern
296296
*/
297-
export interface StepResult<TOOLS extends readonly Tool[] = readonly Tool[]> {
297+
export interface StepResult<TTools extends readonly Tool[] = readonly Tool[]> {
298298
readonly stepType: 'initial' | 'continue';
299299
readonly text: string;
300-
readonly toolCalls: TypedToolCallUnion<TOOLS>[];
301-
readonly toolResults: ToolExecutionResultUnion<TOOLS>[];
300+
readonly toolCalls: TypedToolCallUnion<TTools>[];
301+
readonly toolResults: ToolExecutionResultUnion<TTools>[];
302302
readonly response: models.OpenResponsesNonStreamingResponse;
303303
readonly usage?: models.OpenResponsesUsage | undefined;
304304
readonly finishReason?: string | undefined;
@@ -311,24 +311,24 @@ export interface StepResult<TOOLS extends readonly Tool[] = readonly Tool[]> {
311311
* Returns true to STOP execution, false to CONTINUE
312312
* (Matches Vercel AI SDK semantics)
313313
*/
314-
export type StopCondition<TOOLS extends readonly Tool[] = readonly Tool[]> = (options: {
315-
readonly steps: ReadonlyArray<StepResult<TOOLS>>;
314+
export type StopCondition<TTools extends readonly Tool[] = readonly Tool[]> = (options: {
315+
readonly steps: ReadonlyArray<StepResult<TTools>>;
316316
}) => boolean | Promise<boolean>;
317317

318318
/**
319319
* Stop condition configuration
320320
* Can be a single condition or array of conditions
321321
*/
322-
export type StopWhen<TOOLS extends readonly Tool[] = readonly Tool[]> =
323-
| StopCondition<TOOLS>
324-
| ReadonlyArray<StopCondition<TOOLS>>;
322+
export type StopWhen<TTools extends readonly Tool[] = readonly Tool[]> =
323+
| StopCondition<TTools>
324+
| ReadonlyArray<StopCondition<TTools>>;
325325

326326
/**
327327
* Result of executeTools operation
328328
*/
329-
export interface ExecuteToolsResult<TOOLS extends readonly Tool[]> {
330-
finalResponse: ModelResult<TOOLS>;
331-
allResponses: ModelResult<TOOLS>[];
329+
export interface ExecuteToolsResult<TTools extends readonly Tool[]> {
330+
finalResponse: ModelResult<TTools>;
331+
allResponses: ModelResult<TTools>[];
332332
toolResults: Map<
333333
string,
334334
{

src/sdk/sdk.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ export class OpenRouter extends ClientSDK {
9696
}
9797

9898
// #region sdk-class-body
99-
callModel<TOOLS extends readonly Tool[]>(
100-
request: CallModelInput<TOOLS>,
99+
callModel<TTools extends readonly Tool[]>(
100+
request: CallModelInput<TTools>,
101101
options?: RequestOptions,
102-
): ModelResult<TOOLS> {
102+
): ModelResult<TTools> {
103103
return callModelFunc(this, request, options);
104104
}
105105
// #endregion sdk-class-body

0 commit comments

Comments
 (0)