feat: parse llm response into vector of actions

dino and Gaauwe Rombouts created

Co-authored-by: Gaauwe Rombouts <mail@grombouts.nl>

Change summary

crates/magic_palette/src/magic_palette.rs | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)

Detailed changes

crates/magic_palette/src/magic_palette.rs 🔗

@@ -222,7 +222,26 @@ Format your response as a simple list of action names, one per line, with no add
                         buffer.push_str(&message);
                     }
 
-                    dbg!(buffer);
+                    dbg!(&buffer);
+
+                    // Split result by ';` and for each string, call `cx.build_action`.
+                    let _ = cx.update(move |_window, cx| {
+                        let mut actions: Vec<Box<dyn Action>> = vec![];
+
+                        for line in buffer.lines() {
+                            dbg!(line);
+
+                            let action = cx.build_action(line, None);
+                            match action {
+                                Ok(action) => actions.push(action),
+                                Err(err) => {
+                                    log::error!("Failed to build action: {}", err);
+                                }
+                            }
+                        }
+
+                        dbg!(&actions);
+                    });
                     //
                     Ok(())
                 });