Repository Public License
1// FlowEngine — built-in example workflows and the module's convenience entry points.2import Foundation3import NavigatorCore45/// A workflow shipped with the app as a starting point.6public struct FlowExample: Sendable, Hashable, Identifiable {7 public var id: String8 public var title: String9 public var summary: String10 public var source: String11}1213/// Entry points of the Flow module.14public enum FlowEngine {15 /// Compiles a stored workflow.16 public static func compile(_ workflow: Workflow, registry: FlowActionRegistry = .standard) -> FlowCompilation {17 FlowCompiler.compile(workflow.source, registry: registry)18 }1920 /// A new stored workflow from source text; its name is the one declared in the `flow` header.21 public static func makeWorkflow(source: String, registry: FlowActionRegistry = .standard) -> Workflow {22 let name = FlowCompiler.compile(source, registry: registry).program.name23 return Workflow(name: name.isEmpty ? "Untitled workflow" : name, source: source, languageVersion: FlowLanguage.currentVersion)24 }2526 /// The examples are Swift string constants rather than bundle resources: the package manifest declares no27 /// resources for this target, and constants are checked by the same tests either way.28 public static let examples: [FlowExample] = [29 FlowExample(id: "research-brief", title: "Research brief",30 summary: "Reads a Wikipedia article and up to five linked pages, then writes a cited summary to Downloads.",31 source: """32 # Reads an encyclopedia article and a few of the pages it links to,33 # then writes a summary with citations.34 flow "Research brief" version 13536 param topic: text3738 allow domains "wikipedia.org", "arxiv.org"39 limit steps 40, duration 300s, timeout 30s4041 space "Research" {42 open "https://en.wikipedia.org/wiki/{topic}" as wiki43 extract article from wiki as overview44 collect overview into sources45 # Only links that stay on the allowed domains are followed.46 for link in allowed(overview.links) limit 5 parallel 3 {47 open link as page48 extract article from page as item49 collect item into sources50 close page51 }52 if count(sources) > 0 {53 summarize sources with citations as report54 export report as markdown to downloads55 }56 }5758 """),59 FlowExample(id: "reading-list", title: "Reading list to notes",60 summary: "Opens a fixed list of pages and saves a short note for each.",61 source: """62 flow "Reading list to notes" version 16364 allow domains "swift.org", "developer.apple.com"65 limit steps 30, duration 240s6667 let pages = allowed(["https://www.swift.org/blog/", "https://developer.apple.com/news/"])68 for address in pages limit 5 {69 open address as page70 extract article from page as article71 summarize article length short as digest72 save note digest title article.title73 close page74 }7576 """),77 FlowExample(id: "compare-two-pages", title: "Compare two pages",78 summary: "Opens two pages side by side and asks the AI provider what differs.",79 source: """80 flow "Compare two pages" version 18182 param first: url83 param second: url84 param question: text = "What are the main differences between these two texts?"8586 allow domains "wikipedia.org", "britannica.com"87 limit steps 12, duration 180s8889 parallel limit 2 {90 open first as left91 open second as right92 }93 extract article from left as a94 extract article from right as b95 ask question about [a, b] as answer96 save note answer title "Comparison: {a.title} / {b.title}"9798 """),99 FlowExample(id: "daily-download", title: "Download a daily file",100 summary: "Downloads one file after asking for confirmation, then notifies.",101 source: """102 flow "Download a daily file" version 1103104 param day: text105106 allow domains "data.gov"107 limit steps 5, duration 120s, timeout 60s108109 # The download step always asks for confirmation before it runs.110 download "https://catalog.data.gov/reports/{day}.csv" as file111 notify "Downloaded {file.name}"112113 """),114 ]115}116