( toolCallState: ToolCallState, extras: ClientToolExtras, )
| 29 | ) => Promise<ClientToolOutput>; |
| 30 | |
| 31 | export async function callClientTool( |
| 32 | toolCallState: ToolCallState, |
| 33 | extras: ClientToolExtras, |
| 34 | ): Promise<ClientToolResult> { |
| 35 | const { toolCall, parsedArgs } = toolCallState; |
| 36 | try { |
| 37 | let output: ClientToolOutput; |
| 38 | switch (toolCall.function.name) { |
| 39 | case BuiltInToolNames.EditExistingFile: |
| 40 | output = await editToolImpl(parsedArgs, toolCall.id, extras); |
| 41 | break; |
| 42 | case BuiltInToolNames.SingleFindAndReplace: |
| 43 | output = await singleFindAndReplaceImpl( |
| 44 | parsedArgs, |
| 45 | toolCall.id, |
| 46 | extras, |
| 47 | ); |
| 48 | break; |
| 49 | case BuiltInToolNames.MultiEdit: |
| 50 | output = await multiEditImpl(parsedArgs, toolCall.id, extras); |
| 51 | break; |
| 52 | default: |
| 53 | throw new Error(`Invalid client tool name ${toolCall.function.name}`); |
| 54 | } |
| 55 | return output; |
| 56 | } catch (e) { |
| 57 | return { |
| 58 | respondImmediately: true, |
| 59 | error: |
| 60 | e instanceof ContinueError |
| 61 | ? e |
| 62 | : e instanceof Error |
| 63 | ? new ContinueError(ContinueErrorReason.Unspecified, e.message) |
| 64 | : new ContinueError(ContinueErrorReason.Unknown, String(e)), |
| 65 | output: undefined, |
| 66 | }; |
| 67 | } |
| 68 | } |
no test coverage detected