@smthrs/flow 1.0.0-rc.3 → 1.0.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/Graph.ts CHANGED
@@ -1813,6 +1813,10 @@ export const inspect = (flow: Flow.Any): Inspection => {
1813
1813
  const prompt = "prompt" in flow && typeof flow.prompt === "function"
1814
1814
  ? Function.prototype.toString.call(flow.prompt)
1815
1815
  : undefined
1816
+ // The prompt source belongs to the declaration, so it rides on every
1817
+ // inspection, whether or not the graph could be built.
1818
+ const withPrompt = (inspection: Omit<Inspection, "prompt">): Inspection =>
1819
+ prompt === undefined ? inspection : { ...inspection, prompt }
1816
1820
  try {
1817
1821
  const graph = build(flow, Planned.make("input"))
1818
1822
  const nodes = graph.nodes.map((node) => ({
@@ -1834,15 +1838,14 @@ export const inspect = (flow: Flow.Any): Inspection => {
1834
1838
  ? [{ id: node.id, label: node.ast.flow }]
1835
1839
  : []
1836
1840
  )
1837
- return {
1841
+ return withPrompt({
1838
1842
  nodes,
1839
1843
  edges: graph.edges,
1840
1844
  steps,
1841
- diagnostics: graph.diagnostics.map(({ code, message }) => ({ code, message })),
1842
- ...(prompt === undefined ? {} : { prompt })
1843
- }
1845
+ diagnostics: graph.diagnostics.map(({ code, message }) => ({ code, message }))
1846
+ })
1844
1847
  } catch (error) {
1845
- return {
1848
+ return withPrompt({
1846
1849
  // The declaration itself is a known boundary even when its internals
1847
1850
  // require real input. Do not publish a fictitious empty execution.
1848
1851
  nodes: [{ id: "root", kind: "FlowCall", label: flow._tag, dependencies: [] }],
@@ -1853,8 +1856,7 @@ export const inspect = (flow: Flow.Any): Inspection => {
1853
1856
  ? error.code === "planned_value_computed" ? "declaration_requires_input" : error.code
1854
1857
  : "declaration_inspection_failed",
1855
1858
  message: error instanceof Error ? error.message : String(error)
1856
- }],
1857
- ...(prompt === undefined ? {} : { prompt })
1858
- }
1859
+ }]
1860
+ })
1859
1861
  }
1860
1862
  }