@@ -731,6 +731,22 @@ function extractFormValues(payload: unknown): Record<string, string> {
731731 return normalized ;
732732}
733733
734+ function pickFormValue (
735+ formValues : Record < string , string > ,
736+ key : string
737+ ) : { exists : boolean ; value : string } {
738+ if ( Object . prototype . hasOwnProperty . call ( formValues , key ) ) {
739+ return {
740+ exists : true ,
741+ value : formValues [ key ] ?? "" ,
742+ } ;
743+ }
744+ return {
745+ exists : false ,
746+ value : "" ,
747+ } ;
748+ }
749+
734750async function processLarkCardAction ( payload : unknown ) : Promise < void > {
735751 if ( ! payload || typeof payload !== "object" ) return ;
736752 const envelope = payload as LarkCardActionEnvelope ;
@@ -809,10 +825,15 @@ async function processLarkCardAction(payload: unknown): Promise<void> {
809825 }
810826
811827 if ( action === "set_channel_settings" ) {
828+ const formValues = extractFormValues ( payload ) ;
812829 const selected = pickActionSelectedOption ( payload ) ;
813830 const field = firstNonEmptyString (
814831 pickValueField ( value , "field" )
815832 ) ;
833+ const formModel = pickFormValue ( formValues , "model" ) ;
834+ const formWorkingDirectory = pickFormValue ( formValues , "workingDirectory" ) ;
835+ const formBaseBranch = pickFormValue ( formValues , "baseBranch" ) ;
836+ const formSystemMessage = pickFormValue ( formValues , "channelSystemMessage" ) ;
816837 const provider = firstNonEmptyString (
817838 pickValueField ( value , "provider" ) ,
818839 field === "provider" ? selected : ""
@@ -831,60 +852,74 @@ async function processLarkCardAction(payload: unknown): Promise<void> {
831852 setChannelAgentProvider ( channelId , provider ) ;
832853 }
833854
834- const model = firstNonEmptyString (
835- pickValueField ( value , "model" ) ,
836- field === "model" ? selected : ""
837- ) ;
855+ const model = formModel . exists
856+ ? formModel . value
857+ : firstNonEmptyString (
858+ pickValueField ( value , "model" ) ,
859+ field === "model" ? selected : ""
860+ ) ;
838861 setChannelModel ( channelId , model ) ;
839862
840- const workingDirectory = firstNonEmptyString (
841- pickValueField ( value , "working_directory" ) ,
842- pickValueField ( value , "workingDirectory" ) ,
843- field === "workingDirectory" ? selected : ""
844- ) ;
863+ const workingDirectory = formWorkingDirectory . exists
864+ ? formWorkingDirectory . value
865+ : firstNonEmptyString (
866+ pickValueField ( value , "working_directory" ) ,
867+ pickValueField ( value , "workingDirectory" ) ,
868+ field === "workingDirectory" ? selected : ""
869+ ) ;
845870 setChannelWorkingDirectory ( channelId , workingDirectory || null ) ;
846871
847- const baseBranch = firstNonEmptyString (
848- pickValueField ( value , "base_branch" ) ,
849- pickValueField ( value , "baseBranch" ) ,
850- field === "baseBranch" ? selected : ""
851- ) ;
872+ const baseBranch = formBaseBranch . exists
873+ ? formBaseBranch . value
874+ : firstNonEmptyString (
875+ pickValueField ( value , "base_branch" ) ,
876+ pickValueField ( value , "baseBranch" ) ,
877+ field === "baseBranch" ? selected : ""
878+ ) ;
852879 setChannelBaseBranch ( channelId , baseBranch || null ) ;
853880
854- const channelSystemMessage = firstNonEmptyString (
855- pickValueField ( value , "channel_system_message" ) ,
856- pickValueField ( value , "channelSystemMessage" ) ,
857- field === "channelSystemMessage" ? selected : ""
858- ) ;
881+ const channelSystemMessage = formSystemMessage . exists
882+ ? formSystemMessage . value
883+ : firstNonEmptyString (
884+ pickValueField ( value , "channel_system_message" ) ,
885+ pickValueField ( value , "channelSystemMessage" ) ,
886+ field === "channelSystemMessage" ? selected : ""
887+ ) ;
859888 setChannelSystemMessage ( channelId , channelSystemMessage || null ) ;
860889 }
861890
862891 if ( action === "set_github_info" ) {
863892 const formValues = extractFormValues ( payload ) ;
864893 const selected = pickActionSelectedOption ( payload ) ;
865894 const field = firstNonEmptyString ( pickValueField ( value , "field" ) ) ;
866- const token = firstNonEmptyString (
867- pickValueField ( value , "github_token" ) ,
868- pickValueField ( value , "githubToken" ) ,
869- formValues . githubToken ,
870- field === "githubToken" ? selected : ""
871- ) ;
872- const gitName = firstNonEmptyString (
873- pickValueField ( value , "git_name" ) ,
874- pickValueField ( value , "github_name" ) ,
875- pickValueField ( value , "gitName" ) ,
876- pickValueField ( value , "githubName" ) ,
877- formValues . githubName ,
878- field === "githubName" ? selected : ""
879- ) ;
880- const gitEmail = firstNonEmptyString (
881- pickValueField ( value , "git_email" ) ,
882- pickValueField ( value , "github_email" ) ,
883- pickValueField ( value , "gitEmail" ) ,
884- pickValueField ( value , "githubEmail" ) ,
885- formValues . githubEmail ,
886- field === "githubEmail" ? selected : ""
887- ) ;
895+ const formGithubToken = pickFormValue ( formValues , "githubToken" ) ;
896+ const formGithubName = pickFormValue ( formValues , "githubName" ) ;
897+ const formGithubEmail = pickFormValue ( formValues , "githubEmail" ) ;
898+ const token = formGithubToken . exists
899+ ? formGithubToken . value
900+ : firstNonEmptyString (
901+ pickValueField ( value , "github_token" ) ,
902+ pickValueField ( value , "githubToken" ) ,
903+ field === "githubToken" ? selected : ""
904+ ) ;
905+ const gitName = formGithubName . exists
906+ ? formGithubName . value
907+ : firstNonEmptyString (
908+ pickValueField ( value , "git_name" ) ,
909+ pickValueField ( value , "github_name" ) ,
910+ pickValueField ( value , "gitName" ) ,
911+ pickValueField ( value , "githubName" ) ,
912+ field === "githubName" ? selected : ""
913+ ) ;
914+ const gitEmail = formGithubEmail . exists
915+ ? formGithubEmail . value
916+ : firstNonEmptyString (
917+ pickValueField ( value , "git_email" ) ,
918+ pickValueField ( value , "github_email" ) ,
919+ pickValueField ( value , "gitEmail" ) ,
920+ pickValueField ( value , "githubEmail" ) ,
921+ field === "githubEmail" ? selected : ""
922+ ) ;
888923 setGitHubInfoForUser ( userId || "" , {
889924 token,
890925 gitName,
0 commit comments