@@ -48,6 +48,7 @@ import type {
4848 FlowGraph ,
4949 ForkBranch ,
5050 ForkNode ,
51+ JsonSchema ,
5152 LifetimePolicy ,
5253 ListenConfig ,
5354 ListenEvent ,
@@ -138,7 +139,20 @@ export function parseWorkflowFile(
138139 }
139140
140141 // Old format: flat steps with hoisted sub-graph entries.
141- return parseOldFormat ( doEntries , document , ctx ) ;
142+ const oldResult = parseOldFormat ( doEntries , document , ctx ) ;
143+ // Parse top-level schema for the single workflow in old format.
144+ const topLevelSchema = parseWorkflowSchema ( raw ) ;
145+ if ( topLevelSchema !== undefined ) {
146+ const wfId = oldResult . workflowFile . order [ 0 ] ! ;
147+ const wf = oldResult . workflowFile . workflows [ wfId ] ;
148+ if ( wf ) {
149+ oldResult . workflowFile . workflows [ wfId ] = {
150+ ...wf ,
151+ inputSchema : topLevelSchema ,
152+ } ;
153+ }
154+ }
155+ return oldResult ;
142156}
143157
144158// ---------------------------------------------------------------------------
@@ -167,6 +181,9 @@ function parseNewFormat(
167181 const root = parseGraph ( steps , new Map ( ) , new Set ( ) , ctx ) ;
168182 const id = crypto . randomUUID ( ) ;
169183 const workflow : NamedWorkflow = { id, name, root } ;
184+ // Parse optional input schema: schema: { format: json, document: { ... } }
185+ const inputSchema = parseWorkflowSchema ( def ) ;
186+ if ( inputSchema !== undefined ) workflow . inputSchema = inputSchema ;
170187 workflows [ id ] = workflow ;
171188 order . push ( id ) ;
172189 }
@@ -798,6 +815,22 @@ function parseTryNode(
798815 return node ;
799816}
800817
818+ // ---------------------------------------------------------------------------
819+ // Input schema parsing
820+ //
821+ // Reads `schema: { format: json, document: { ... } }` from a workflow entry
822+ // (new format) or the top-level document (old format). Returns undefined if
823+ // the key is absent or malformed, preserving the existing workflow unchanged.
824+ // ---------------------------------------------------------------------------
825+
826+ function parseWorkflowSchema ( def : RawEntry ) : JsonSchema | undefined {
827+ const schemaRaw = def [ 'schema' ] ;
828+ if ( ! schemaRaw || typeof schemaRaw !== 'object' ) return undefined ;
829+ const doc = ( schemaRaw as Record < string , unknown > ) [ 'document' ] ;
830+ if ( ! doc || typeof doc !== 'object' ) return undefined ;
831+ return doc as JsonSchema ;
832+ }
833+
801834// ---------------------------------------------------------------------------
802835// LoopNode
803836// ---------------------------------------------------------------------------
0 commit comments