(logic: () => Promise<unknown>)
| 104 | * ToolResponse-shaped result for backward-compatible test assertions. |
| 105 | */ |
| 106 | export async function runLogic(logic: () => Promise<unknown>): Promise<RunLogicResult> { |
| 107 | const { result, run } = createMockToolHandlerContext(); |
| 108 | const response = await run(logic); |
| 109 | |
| 110 | if ( |
| 111 | response && |
| 112 | typeof response === 'object' && |
| 113 | 'content' in (response as Record<string, unknown>) |
| 114 | ) { |
| 115 | return response as RunLogicResult; |
| 116 | } |
| 117 | |
| 118 | const text = result.text(); |
| 119 | const textContent = text.length > 0 ? [{ type: 'text' as const, text }] : []; |
| 120 | const imageContent = result.attachments.map((attachment) => ({ |
| 121 | type: 'image' as const, |
| 122 | data: attachment.data, |
| 123 | mimeType: attachment.mimeType, |
| 124 | })); |
| 125 | |
| 126 | return { |
| 127 | content: [...textContent, ...imageContent], |
| 128 | isError: result.isError() ? true : undefined, |
| 129 | nextStepParams: result.nextStepParams, |
| 130 | attachments: result.attachments, |
| 131 | text, |
| 132 | }; |
| 133 | } |
| 134 | |
| 135 | export interface CallHandlerResult { |
| 136 | content: Array<{ type: 'text'; text: string }>; |
no test coverage detected