MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / executeTool

Function executeTool

packages/agent-core/test/tools/fixtures/execute-tool.ts:13–33  ·  view source on GitHub ↗
(
  tool: ExecutableTool<Input>,
  context: TestExecutableToolContext<Input>,
)

Source from the content-addressed store, hash-verified

11};
12
13export async function executeTool<Input>(
14 tool: ExecutableTool<Input>,
15 context: TestExecutableToolContext<Input>,
16): Promise<ExecutableToolResult> {
17 const { args, ...executionContext } = context;
18 let execution: ToolExecution;
19 try {
20 const resolved = tool.resolveExecution(args);
21 execution = isPromiseLike(resolved) ? await resolved : resolved;
22 } catch (error) {
23 const output =
24 error instanceof PathSecurityError
25 ? error.message
26 : `Tool "${tool.name}" failed to resolve execution: ${
27 error instanceof Error ? error.message : String(error)
28 }`;
29 return { isError: true, output };
30 }
31 if (execution.isError === true) return execution;
32 return execution.execute(executionContext);
33}
34
35function isPromiseLike(value: ToolExecution | Promise<ToolExecution>): value is Promise<ToolExecution> {
36 return typeof (value as Promise<ToolExecution>).then === 'function';

Callers 15

read.test.tsFile · 0.90
todo-list.test.tsFile · 0.90
web-search.test.tsFile · 0.90
executeFunction · 0.90
ask-user.test.tsFile · 0.90
captureSpawnEnvFunction · 0.90
bash-env.test.tsFile · 0.90
fetch-url.test.tsFile · 0.90
read-file.test.tsFile · 0.90

Calls 3

isPromiseLikeFunction · 0.85
executeMethod · 0.80
resolveExecutionMethod · 0.65

Tested by 8

executeFunction · 0.72
captureSpawnEnvFunction · 0.72
executeFunction · 0.72
captureCommandRewriteFunction · 0.72
executeFunction · 0.72
taskOutputFunction · 0.72
executeFunction · 0.72
runToolFunction · 0.72