11import { useEffect , useState } from "react" ;
22import { useRepoStore } from "../store/useRepoStore" ;
33import { usePipelineStore } from "../store/usePipelineStore" ;
4+ import { useWizardStore } from "../store/useWizardStore" ;
45import { api } from "../lib/api" ;
56
67type ChatMessage = {
@@ -30,8 +31,17 @@ export default function ConfigurePage() {
3031 editedYaml,
3132 setEditedYaml,
3233 getEffectiveYaml,
34+ hydrateFromWizard,
3335 } = usePipelineStore ( ) ;
3436
37+ const {
38+ repoInfo,
39+ pipelineInfo,
40+ setRepoInfo,
41+ setPipelineInfo,
42+ setLastToolCalled,
43+ } = useWizardStore ( ) ;
44+
3545 const yaml = getEffectiveYaml ( ) ;
3646 const busy = status === "loading" ;
3747
@@ -57,6 +67,13 @@ export default function ConfigurePage() {
5767 alert ( "Pick a repo + branch on the Connect page first." ) ;
5868 return ;
5969 }
70+ console . log ( "[ConfigurePage] Generate clicked with inputs:" , {
71+ repo,
72+ branch,
73+ template,
74+ stages,
75+ options,
76+ } ) ;
6077 await regenerate ( { repo, branch } ) ;
6178 } ;
6279
@@ -92,40 +109,92 @@ export default function ConfigurePage() {
92109 setChatInput ( "" ) ;
93110 setChatLoading ( true ) ;
94111
95- try {
96- const res = await api . askYamlWizard ( {
97- repoUrl : repo , // backend expects "repoUrl"
98- provider : "aws" , // or whatever provider you use
99- branch : branch , // backend expects "branch"
100- message : trimmed , // optional, for your agent logic
101- yaml, // optional, current YAML for context
102- } ) ;
103-
104- const text =
105- ( res as any ) ?. reply ??
106- ( res as any ) ?. message ??
107- ( res as any ) ?. content ??
108- JSON . stringify ( res , null , 2 ) ;
109-
110- const assistantMessage : ChatMessage = {
111- role : "assistant" ,
112- content : text ,
113- } ;
114-
115- setChatMessages ( ( prev ) => [ ...prev , assistantMessage ] ) ;
116- } catch ( e : any ) {
117- console . error ( "[ConfigurePage] AI wizard error:" , e ) ;
118- const assistantMessage : ChatMessage = {
119- role : "assistant" ,
120- content :
121- "Sorry, I ran into an issue talking to the AI backend.\n\n" +
122- `Error: ${ e ?. message ?? "Unknown error" } ` ,
123- } ;
124- setChatMessages ( ( prev ) => [ ...prev , assistantMessage ] ) ;
125- } finally {
126- setChatLoading ( false ) ;
127- }
128- } ;
112+ try {
113+ const res = await api . askYamlWizard ( {
114+ repoUrl : repo , // backend expects "repoUrl"
115+ provider : "aws" , // or whatever provider you use
116+ branch : branch , // backend expects "branch"
117+ message : trimmed , // optional, for your agent logic
118+ yaml, // optional, current YAML for context
119+ } ) ;
120+
121+ // ---- Update wizard context memory ----
122+ if ( ( res as any ) ?. tool_called ) {
123+ setLastToolCalled ( ( res as any ) . tool_called ) ;
124+ }
125+
126+ // If repo info is available from selection or tool output, store it
127+ if ( repo ) {
128+ setRepoInfo ( {
129+ fullName : repo ,
130+ } ) ;
131+ }
132+
133+ // If a pipeline was generated, hydrate pipeline store + wizard context
134+ if ( ( res as any ) ?. tool_called === "pipeline_generator" ) {
135+ const generatedYaml =
136+ ( res as any ) ?. generated_yaml ??
137+ ( res as any ) ?. tool_output ?. data ?. generated_yaml ;
138+
139+ const pipelineName =
140+ ( res as any ) ?. pipeline_metadata ?. data ?. pipeline_name ??
141+ ( res as any ) ?. pipeline_metadata ?. pipeline_name ;
142+
143+ if ( generatedYaml ) {
144+ hydrateFromWizard ( {
145+ repo,
146+ generatedYaml,
147+ pipelineName,
148+ } ) ;
149+ }
150+
151+ setPipelineInfo ( {
152+ pipelineName,
153+ branch,
154+ provider : "aws" ,
155+ stages,
156+ } ) ;
157+ }
158+
159+ let text : string ;
160+
161+ if ( ( res as any ) ?. reply ) {
162+ text = ( res as any ) . reply ;
163+ } else if ( ( res as any ) ?. message ) {
164+ text = ( res as any ) . message ;
165+ } else if (
166+ ( res as any ) ?. tool_called === "repo_reader" &&
167+ Array . isArray ( ( res as any ) ?. tool_output ?. data ?. data ?. repositories )
168+ ) {
169+ const count =
170+ ( res as any ) . tool_output . data . data . repositories . length ;
171+ text = `I found ${ count } repositories. You can select one from the list to continue.` ;
172+ } else if ( repoInfo ?. fullName ) {
173+ text = `I’m looking at ${ repoInfo . fullName } . What would you like to change about the pipeline?` ;
174+ } else {
175+ text =
176+ "I couldn’t map that request to an action yet. You can ask me to modify the pipeline, deploy settings, or AWS role." ;
177+ }
178+
179+ const assistantMessage : ChatMessage = {
180+ role : "assistant" ,
181+ content : text ,
182+ } ;
183+
184+ setChatMessages ( ( prev ) => [ ...prev , assistantMessage ] ) ;
185+ } catch ( e : any ) {
186+ console . error ( "[ConfigurePage] AI wizard error:" , e ) ;
187+ const assistantMessage : ChatMessage = {
188+ role : "assistant" ,
189+ content :
190+ "Sorry, I ran into an issue talking to the AI backend.\n\n" +
191+ `Error: ${ e ?. message ?? "Unknown error" } ` ,
192+ } ;
193+ setChatMessages ( ( prev ) => [ ...prev , assistantMessage ] ) ;
194+ } finally {
195+ setChatLoading ( false ) ;
196+ }
197+ } ;
129198
130199 const handleChatKeyDown : React . KeyboardEventHandler < HTMLTextAreaElement > = (
131200 e
0 commit comments