handleWorkflowProcessing loads, validates, and runs the workflow, then prints, copies, or writes the result.
(currentFlags *Flags, registry *core.PluginRegistry, messageTools string)
| 216 | // handleWorkflowProcessing loads, validates, and runs the workflow, then prints, |
| 217 | // copies, or writes the result. |
| 218 | func handleWorkflowProcessing(currentFlags *Flags, registry *core.PluginRegistry, messageTools string) (err error) { |
| 219 | wf, err := LoadWorkflow(currentFlags.Workflow) |
| 220 | if err != nil { |
| 221 | return |
| 222 | } |
| 223 | |
| 224 | if err = wf.Validate(registry.Db.Patterns); err != nil { |
| 225 | return fmt.Errorf("workflow %s is invalid: %w", currentFlags.Workflow, err) |
| 226 | } |
| 227 | |
| 228 | if messageTools != "" { |
| 229 | currentFlags.AppendMessage(messageTools) |
| 230 | } |
| 231 | |
| 232 | var chatOptions *domain.ChatOptions |
| 233 | if chatOptions, err = currentFlags.BuildChatOptions(); err != nil { |
| 234 | return |
| 235 | } |
| 236 | |
| 237 | var result string |
| 238 | if result, err = runWorkflow(registry, wf, currentFlags.Message, currentFlags, chatOptions); err != nil { |
| 239 | return |
| 240 | } |
| 241 | |
| 242 | // Print the result unless streaming already printed it. Remove terminal |
| 243 | // control sequences from the displayed copy only. |
| 244 | if !currentFlags.Stream || chatOptions.SuppressThink { |
| 245 | fmt.Println(domain.SanitizeTerminalOutput(result)) |
| 246 | } |
| 247 | |
| 248 | if currentFlags.Copy { |
| 249 | if err = CopyToClipboard(result); err != nil { |
| 250 | return |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | if currentFlags.Output != "" { |
| 255 | err = CreateOutputFile(result, currentFlags.Output) |
| 256 | } |
| 257 | return |
| 258 | } |
| 259 | |
| 260 | // resolveStepInputWithOverride returns the input for one step. A step.Input that |
| 261 | // is not blank after TrimSpace replaces carriedInput. Otherwise carriedInput stays. |