@@ -72,30 +72,65 @@ export async function elicitGameCreationPreferences(
7272 }
7373 }
7474
75- const schema = schemas [ gameType as keyof typeof schemas ]
76- if ( ! schema ) {
75+ const baseSchema = schemas [ gameType as keyof typeof schemas ]
76+ if ( ! baseSchema ) {
7777 throw new Error ( `No elicitation schema defined for game type: ${ gameType } ` )
7878 }
7979
80+ // Filter out properties that are already provided
81+ const filteredSchema : any = { ...baseSchema }
82+ const filteredProperties : Record < string , any > = { ...baseSchema . properties }
83+ const filteredRequired = [ ...( baseSchema . required || [ ] ) ]
84+
85+ // Remove properties that already have values
86+ if ( existingArgs ) {
87+ Object . keys ( existingArgs ) . forEach ( key => {
88+ if ( existingArgs [ key ] !== undefined && existingArgs [ key ] !== null && existingArgs [ key ] !== '' ) {
89+ delete filteredProperties [ key ]
90+ // Remove from required array if present
91+ const requiredIndex = filteredRequired . indexOf ( key )
92+ if ( requiredIndex > - 1 ) {
93+ filteredRequired . splice ( requiredIndex , 1 )
94+ }
95+ }
96+ } )
97+ }
98+
99+ filteredSchema . properties = filteredProperties
100+ filteredSchema . required = filteredRequired
101+
102+ // If no properties remain to be elicited, skip elicitation
103+ if ( Object . keys ( filteredProperties ) . length === 0 ) {
104+ return {
105+ action : "accept" ,
106+ content : existingArgs || { }
107+ }
108+ }
109+
80110 const message = `Let's set up your ${ gameType . replace ( '-' , ' ' ) } game! 🎮\n\nI'll need a few preferences to customize your experience:`
81111
82112 try {
83113 const result = await server . elicitInput ( {
84114 message,
85- requestedSchema : schema
115+ requestedSchema : filteredSchema
86116 } )
87117
118+ // Merge the elicitation result with existing arguments
119+ if ( result . action === 'accept' && result . content ) {
120+ result . content = { ...existingArgs , ...result . content }
121+ }
122+
88123 return result
89124 } catch ( error ) {
90125 console . error ( 'Elicitation failed:' , error )
91126 // Return default preferences if elicitation fails
92127 return {
93128 action : "accept" ,
94129 content : {
95- difficulty : existingArgs ?. aiDifficulty || DEFAULT_AI_DIFFICULTY ,
130+ difficulty : existingArgs ?. difficulty || DEFAULT_AI_DIFFICULTY ,
96131 playerName : existingArgs ?. playerName || DEFAULT_PLAYER_NAME ,
97- ...( gameType === 'rock-paper-scissors' && { maxRounds : 3 } ) ,
98- ...( gameType === 'tic-tac-toe' && { playerSymbol : "X" } )
132+ ...( gameType === 'rock-paper-scissors' && { maxRounds : existingArgs ?. maxRounds || 3 } ) ,
133+ ...( gameType === 'tic-tac-toe' && { playerSymbol : existingArgs ?. playerSymbol || "X" } )
99134 }
100135 }
101136 }
@@ -160,10 +195,10 @@ export async function elicitGameCompletionFeedback(
160195 gameType : string
161196 gameId : string
162197 result : 'win' | 'loss' | 'draw'
163- aiDifficulty : string
198+ difficulty : string
164199 }
165200) : Promise < ElicitationResult > {
166- const { gameType, result, aiDifficulty } = context
201+ const { gameType, result, difficulty } = context
167202
168203 const resultMessages = {
169204 win : "🎉 Congratulations! You won!" ,
@@ -179,7 +214,7 @@ export async function elicitGameCompletionFeedback(
179214 enum : [ "too_easy" , "just_right" , "too_hard" ] ,
180215 enumNames : [ "Too Easy" , "Just Right" , "Too Hard" ] ,
181216 title : "How was the difficulty?" ,
182- description : `The AI was set to ${ aiDifficulty } difficulty`
217+ description : `The AI was set to ${ difficulty } difficulty`
183218 } ,
184219 playAgain : {
185220 type : "boolean" ,
0 commit comments