( message: ToolMessage, )
| 124 | } |
| 125 | |
| 126 | function convertToolResultMessage( |
| 127 | message: ToolMessage, |
| 128 | ): ModelMessageWithAuxiliaryData[] { |
| 129 | if (message.content.length === 0) { |
| 130 | return [ |
| 131 | cloneDeep<ToolModelMessage>({ |
| 132 | ...message, |
| 133 | role: 'tool', |
| 134 | content: [ |
| 135 | { |
| 136 | ...message, |
| 137 | output: { type: 'json', value: '' }, |
| 138 | type: 'tool-result', |
| 139 | }, |
| 140 | ], |
| 141 | }), |
| 142 | ] |
| 143 | } |
| 144 | return message.content.map((c) => { |
| 145 | if (c.type === 'json') { |
| 146 | return cloneDeep<ToolModelMessage>({ |
| 147 | ...message, |
| 148 | role: 'tool', |
| 149 | content: [{ ...message, output: c, type: 'tool-result' }], |
| 150 | }) |
| 151 | } |
| 152 | if (c.type === 'media') { |
| 153 | return cloneDeep<UserMessage>({ |
| 154 | ...message, |
| 155 | role: 'user', |
| 156 | content: [{ type: 'file', data: c.data, mediaType: c.mediaType }], |
| 157 | }) |
| 158 | } |
| 159 | c satisfies never |
| 160 | throw new Error( |
| 161 | `Invalid tool output type: ${(c as { type: unknown }).type}`, |
| 162 | ) |
| 163 | }) |
| 164 | } |
| 165 | |
| 166 | function convertToolMessage(message: Message): ModelMessageWithAuxiliaryData[] { |
| 167 | if (message.role === 'system') { |
no outgoing calls
no test coverage detected