MCPcopy Create free account
hub / github.com/anomalyco/opencode / dispatch

Function dispatch

packages/llm/src/tool-runtime.ts:23–35  ·  view source on GitHub ↗
(tools: Tools, call: ToolCallPart)

Source from the content-addressed store, hash-verified

21
22/** Execute one canonical tool call without owning provider IO or continuation. */
23export const dispatch = (tools: Tools, call: ToolCallPart): Effect.Effect<DispatchResult> => {
24 const tool = tools[call.name]
25 if (!tool) return Effect.succeed(result(call, { type: "error", value: `Unknown tool: ${call.name}` }))
26 if (!tool.execute)
27 return Effect.succeed(result(call, { type: "error", value: `Tool has no execute handler: ${call.name}` }))
28
29 return decodeAndExecute(tool, call).pipe(
30 Effect.map((value) => result(call, value)),
31 Effect.catchTag("LLM.ToolFailure", (failure) =>
32 Effect.succeed(result(call, { type: "error", value: failure.message }, failure.error)),
33 ),
34 )
35}
36
37const decodeAndExecute = (tool: AnyTool, call: ToolCallPart): Effect.Effect<ToolSettlement, ToolFailure> =>
38 tool._decode(call.input).pipe(

Callers

nothing calls this directly

Calls 2

decodeAndExecuteFunction · 0.85
resultFunction · 0.70

Tested by

no test coverage detected