| 209 | } |
| 210 | |
| 211 | function getAutonomyTurnOutcome(params: { |
| 212 | terminal?: Terminal |
| 213 | thrownError?: unknown |
| 214 | }): AutonomyTurnOutcome { |
| 215 | if (params.thrownError !== undefined) { |
| 216 | return { type: 'failed', error: params.thrownError } |
| 217 | } |
| 218 | |
| 219 | const terminal = params.terminal |
| 220 | const reason = terminal?.reason |
| 221 | switch (reason) { |
| 222 | case 'completed': |
| 223 | return { type: 'completed' } |
| 224 | case undefined: |
| 225 | case 'aborted_streaming': |
| 226 | case 'aborted_tools': |
| 227 | return { type: 'cancelled' } |
| 228 | case 'model_error': |
| 229 | return { type: 'failed', error: terminal.error } |
| 230 | default: |
| 231 | return { |
| 232 | type: 'failed', |
| 233 | message: `query ended without successful completion: ${reason}`, |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | export type QueryParams = { |
| 239 | messages: Message[] |