(part: unknown)
| 189 | } |
| 190 | |
| 191 | function parseToolResult(part: unknown): ParsedToolResult | null { |
| 192 | if (!isObject(part)) { |
| 193 | return null; |
| 194 | } |
| 195 | const record = part as Record<string, unknown>; |
| 196 | const callId = getString(record.callID) |
| 197 | || getString(record.callId) |
| 198 | || getString(record.tool_call_id) |
| 199 | || getString(record.toolCallId) |
| 200 | || getString(record.id); |
| 201 | if (!callId) { |
| 202 | return null; |
| 203 | } |
| 204 | if (getString(record.type) === 'tool' && isObject(record.state)) { |
| 205 | const state = record.state as Record<string, unknown>; |
| 206 | const status = getString(state.status); |
| 207 | if (status === 'completed') { |
| 208 | const output = { |
| 209 | content: state.output ?? state.title, |
| 210 | metadata: state.metadata, |
| 211 | title: state.title, |
| 212 | attachments: state.attachments |
| 213 | }; |
| 214 | return { callId, output }; |
| 215 | } |
| 216 | if (status === 'error') { |
| 217 | const output = { |
| 218 | content: state.error, |
| 219 | isError: true |
| 220 | }; |
| 221 | return { callId, output }; |
| 222 | } |
| 223 | return null; |
| 224 | } |
| 225 | const output = { |
| 226 | content: record.content, |
| 227 | metadata: record.metadata, |
| 228 | isError: record.is_error |
| 229 | }; |
| 230 | return { callId, output }; |
| 231 | } |
| 232 | |
| 233 | function normalizeDecision(response: string | null, approved: boolean): PermissionDecision { |
| 234 | if (response === 'always' || response === 'approved_for_session') { |
no test coverage detected