| 57 | selectedFunctions: string[]; |
| 58 | } |
| 59 | export function parseActionFilteringOutput( |
| 60 | output: string, |
| 61 | possibleOutputs: string[], |
| 62 | ): ActionFilteringOutput { |
| 63 | // Split out into thoughts and selected functions |
| 64 | if (!output.includes("Selected functions:")) { |
| 65 | return { thoughts: "", selectedFunctions: [] }; |
| 66 | } |
| 67 | const thoughts = output.split("Selected functions:")[0].split("Thoughts:")[1]; |
| 68 | return { |
| 69 | thoughts: thoughts ? thoughts.trim() : "", |
| 70 | selectedFunctions: output |
| 71 | .split("Selected functions:")[1] |
| 72 | .trim() |
| 73 | .split("\n") |
| 74 | .filter((s) => s.trim() !== "") |
| 75 | .map((s) => { |
| 76 | const match = s.match(/^(\d. |- )?([\w_]+).*\s?.*$/); |
| 77 | if (!match) return ""; |
| 78 | return match[2]; |
| 79 | }) |
| 80 | .filter(Boolean) |
| 81 | .filter((s) => possibleOutputs.includes(s)), |
| 82 | }; |
| 83 | } |