@@ -11,7 +11,7 @@ import type {
1111 ChatCompletionTool ,
1212 ChatCompletionToolMessageParam ,
1313} from '../../resources/chat/completions' ;
14- import type { BetaRunnableTool } from './BetaRunnableTool' ;
14+ import type { BetaRunnableChatCompletionFunctionTool } from './BetaRunnableTool' ;
1515
1616/**
1717 * Just Promise.withResolvers(), which is not available in all environments.
@@ -255,7 +255,10 @@ export class BetaToolRunner<Stream extends boolean>
255255 }
256256 const toolsResponse = generateToolResponse (
257257 lastMessage ,
258- this . #state. params . tools . filter ( ( tool ) : tool is BetaRunnableTool < any > => 'run' in tool ) ,
258+ this . #state. params . tools . filter (
259+ ( tool ) : tool is BetaRunnableChatCompletionFunctionTool < any > =>
260+ 'run' in tool && tool . type === 'function' ,
261+ ) ,
259262 ) ;
260263 this . #toolResponse = toolsResponse ;
261264 return toolsResponse ;
@@ -358,7 +361,7 @@ export class BetaToolRunner<Stream extends boolean>
358361
359362async function generateToolResponse (
360363 lastMessage : ChatCompletionMessage ,
361- tools : BetaRunnableTool < any > [ ] ,
364+ tools : BetaRunnableChatCompletionFunctionTool < any > [ ] ,
362365) : Promise < null | ChatCompletionToolMessageParam [ ] > {
363366 // Only process if the last message is from the assistant and has tool use blocks
364367 if (
@@ -383,7 +386,7 @@ async function generateToolResponse(
383386
384387 const tool = tools . find (
385388 ( t ) => t . type === 'function' && toolUse . function . name === t . function . name ,
386- ) as BetaRunnableTool ;
389+ ) as BetaRunnableChatCompletionFunctionTool ;
387390
388391 if ( ! tool || ! ( 'run' in tool ) ) {
389392 return {
@@ -435,7 +438,7 @@ type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
435438 */
436439export type BetaToolRunnerParams = Simplify <
437440 Omit < ChatCompletionCreateParams , 'tools' > & {
438- tools : ( ChatCompletionTool | BetaRunnableTool < any > ) [ ] ;
441+ tools : ( ChatCompletionTool | BetaRunnableChatCompletionFunctionTool < any > ) [ ] ;
439442 /**
440443 * Maximum number of iterations (API requests) to make in the tool execution loop.
441444 * Each iteration consists of: assistant response → tool execution → tool results.
0 commit comments