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

Function decodeAndExecute

packages/llm/src/tool-runtime.ts:37–61  ·  view source on GitHub ↗
(tool: AnyTool, call: ToolCallPart)

Source from the content-addressed store, hash-verified

35}
36
37const decodeAndExecute = (tool: AnyTool, call: ToolCallPart): Effect.Effect<ToolSettlement, ToolFailure> =>
38 tool._decode(call.input).pipe(
39 Effect.mapError((error) => new ToolFailure({ message: `Invalid tool input: ${error.message}` })),
40 Effect.flatMap((decoded) =>
41 tool.execute!(decoded, { id: call.id, name: call.name }).pipe(
42 Effect.flatMap((value) =>
43 tool._encode(value).pipe(
44 Effect.mapError(
45 (error) =>
46 new ToolFailure({
47 message: `Tool returned an invalid value for its success schema: ${error.message}`,
48 }),
49 ),
50 ),
51 ),
52 Effect.map((encoded) => {
53 if (tool._legacyResult && ToolResultValue.is(encoded))
54 return { result: encoded, output: ToolOutput.fromResultValue(encoded) }
55 const output = tool._project(decoded, call.id, encoded)
56 const result = ToolOutput.toResultValue(output)
57 return result.type === "error" ? { result } : { result, output }
58 }),
59 ),
60 ),
61 )
62
63const result = (call: ToolCallPart, value: ToolResultValueType | ToolSettlement, error?: unknown): DispatchResult => {
64 const settlement = ToolResultValue.is(value) ? { result: value } : value

Callers 1

dispatchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected