(message)
| 324 | } |
| 325 | |
| 326 | function normalizeObservation(message) { |
| 327 | const extra = message && message.extra ? message.extra : {}; |
| 328 | if (extra.observation && typeof extra.observation === 'object') { |
| 329 | return { |
| 330 | output: String(extra.observation.command_output || ''), |
| 331 | exitCode: typeof extra.observation.returncode === 'number' ? extra.observation.returncode : parseExitCode(extra.observation.command_output || ''), |
| 332 | command: String(extra.observation.command || ''), |
| 333 | success: extra.observation.success |
| 334 | }; |
| 335 | } |
| 336 | const text = contentToText(message.content); |
| 337 | if (!/^Observation:/i.test(text)) { |
| 338 | return null; |
| 339 | } |
| 340 | const outputMatch = text.match(/Command output:\n([\s\S]*)$/i); |
| 341 | const commandMatch = text.match(/Command:\s*([^\n]+)/i); |
| 342 | return { |
| 343 | output: outputMatch ? outputMatch[1].trim() : text, |
| 344 | exitCode: parseExitCode(text), |
| 345 | command: commandMatch ? commandMatch[1].trim() : '', |
| 346 | success: /Status:\s*ok/i.test(text) |
| 347 | }; |
| 348 | } |
| 349 | |
| 350 | function stripSessionMarkup(text) { |
| 351 | return String(text || '') |
no test coverage detected