MCPcopy
hub / github.com/thesysdev/openui / toolWorkflowSection

Function toolWorkflowSection

packages/lang-core/src/parser/prompt.ts:384–414  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

382}
383
384function toolWorkflowSection(): string {
385 return `## Data Workflow
386
387When tools are available, follow this workflow:
3881. FIRST: Call the most relevant tool to inspect the real data shape before generating code
3892. Use Query() for READ operations (data that should stay live) — NEVER hardcode tool results as literal arrays or objects
3903. Use Mutation() for WRITE operations (create, update, delete) — triggered by button clicks via Action([@Run(mutationRef)])
3914. Use the real data from step 1 as condensed Query defaults (3-5 rows) so the UI renders immediately
3925. Use @-prefixed builtins (@Count, @Filter, @Sort, @Sum) on Query results for KPIs and aggregations — the runtime evaluates these live on every refresh
3936. Hardcoded arrays are ONLY for static display data (labels, options) where no tool exists
394
395WRONG — you called a tool and got data back, but you inlined the results:
396\`\`\`
397openCount = 2
398item1 = SomeComp("first item title")
399item2 = SomeComp("second item title")
400list = Stack([item1, item2])
401chart = SomeChart(["A", "B"], [12, 8])
402\`\`\`
403This is static — it shows stale data and won't update. Creating item1, item2, item3... manually is ALWAYS wrong when a tool exists.
404
405RIGHT — use Query() for live data, Mutation() for writes, @builtins to derive values:
406\`\`\`
407data = Query("tool_name", {}, {rows: []})
408openCount = @Count(@Filter(data.rows, "field", "==", "value"))
409list = @Each(data.rows, "item", SomeComp(item.title, item.field))
410createResult = Mutation("create_tool", {title: $title})
411submitBtn = Button("Create", Action([@Run(createResult), @Run(data), @Reset($title)]))
412\`\`\`
413Everything derives from the Query — when data refreshes, the entire dashboard updates automatically.`;
414}
415
416function importantRules(
417 rootName: string,

Callers 1

generatePromptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected