(
invoker: DefaultToolInvoker,
toolName: string,
args: Record<string, unknown>,
opts: {
runtime: 'cli' | 'daemon' | 'mcp';
socketPath?: string;
workspaceRoot?: string;
cliExposedWorkflowIds?: string[];
},
)
| 120 | } |
| 121 | |
| 122 | function invokeAndFinalize( |
| 123 | invoker: DefaultToolInvoker, |
| 124 | toolName: string, |
| 125 | args: Record<string, unknown>, |
| 126 | opts: { |
| 127 | runtime: 'cli' | 'daemon' | 'mcp'; |
| 128 | socketPath?: string; |
| 129 | workspaceRoot?: string; |
| 130 | cliExposedWorkflowIds?: string[]; |
| 131 | }, |
| 132 | ): Promise<ToolResponse & { structuredOutput?: StructuredToolOutput }> { |
| 133 | const session = createRenderSession('text'); |
| 134 | const promise = invoker.invoke(toolName, args, { ...opts, renderSession: session }); |
| 135 | return promise.then(() => { |
| 136 | const text = session.finalize(); |
| 137 | const response: ToolResponse = { |
| 138 | content: text ? [{ type: 'text', text }] : [], |
| 139 | isError: session.isError() || undefined, |
| 140 | nextSteps: undefined, |
| 141 | structuredOutput: session.getStructuredOutput?.(), |
| 142 | }; |
| 143 | return response; |
| 144 | }); |
| 145 | } |
| 146 | |
| 147 | function emitHandler(text: string): ToolDefinition['handler'] { |
| 148 | return vi.fn(async (_params, ctx) => { |
no test coverage detected