(response: ToolResponse, runtime: RuntimeKind)
| 18 | } |
| 19 | |
| 20 | export function processToolResponse(response: ToolResponse, runtime: RuntimeKind): ToolResponse { |
| 21 | const { nextSteps, ...rest } = response; |
| 22 | |
| 23 | if (!nextSteps || nextSteps.length === 0) { |
| 24 | return { ...rest }; |
| 25 | } |
| 26 | |
| 27 | const nextStepsSection = renderNextStepsSection(nextSteps, runtime); |
| 28 | const processedContent = [...response.content]; |
| 29 | let textItemIndex = -1; |
| 30 | |
| 31 | for (let index = processedContent.length - 1; index >= 0; index -= 1) { |
| 32 | if (processedContent[index]?.type === 'text') { |
| 33 | textItemIndex = index; |
| 34 | break; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | if (textItemIndex >= 0) { |
| 39 | const textItem = processedContent[textItemIndex]; |
| 40 | if (textItem?.type === 'text') { |
| 41 | processedContent[textItemIndex] = { |
| 42 | ...textItem, |
| 43 | text: textItem.text + '\n\n' + nextStepsSection, |
| 44 | }; |
| 45 | } |
| 46 | } else { |
| 47 | processedContent.push({ type: 'text', text: nextStepsSection.trim() }); |
| 48 | } |
| 49 | |
| 50 | return { ...rest, content: processedContent }; |
| 51 | } |
no test coverage detected