@@ -1716,7 +1716,7 @@ func ParseHistoryToHistoricMessages(historyJson string) (history []sharedtypes.H
1716
1716
// - slashCmd: the slash command if found, otherwise an empty string
1717
1717
// - targetCmd: the target command if found, otherwise an empty string
1718
1718
// - hasCmd: boolean indicating if a slash command or target command was found
1719
- func ParseSlashCommand (userInput string ) (slashCmd , targetCmd string , hasCmd bool ) {
1719
+ func ParseSlashCommand (userInput string ) (slashCmd , targetCmd string , hasCmd bool , hasContext bool ) {
1720
1720
1721
1721
targetRe := regexp .MustCompile (`@[A-Za-z][\w]*` )
1722
1722
slashRe := regexp .MustCompile (`/[A-Za-z][\w]*` )
@@ -1740,9 +1740,12 @@ func ParseSlashCommand(userInput string) (slashCmd, targetCmd string, hasCmd boo
1740
1740
hasCmd = false
1741
1741
}
1742
1742
1743
- logging .Log .Debugf (& logging.ContextMap {}, "User Command: Slash: %s, Target: %s, Has Command: %t" , slash , target , hasCmd )
1743
+ remaining := strings .TrimSpace (strings .ReplaceAll (strings .ReplaceAll (userInput , "/" + slash , "" ), "@" + target , "" ))
1744
+ hasContext = remaining != ""
1744
1745
1745
- return slash , target , hasCmd
1746
+ logging .Log .Debugf (& logging.ContextMap {}, "User Command: Slash: %s, Target: %s, Has Command: %t, Has Context: %t, Remaining: %s" , slash , target , hasCmd , hasContext , remaining )
1747
+
1748
+ return slash , target , hasCmd , hasContext
1746
1749
}
1747
1750
1748
1751
// SynthesizeSlashCommand synthesize actions based on user instruction
@@ -1756,7 +1759,7 @@ func ParseSlashCommand(userInput string) (slashCmd, targetCmd string, hasCmd boo
1756
1759
//
1757
1760
// Returns:
1758
1761
// - result: the synthesized string
1759
- func SynthesizeSlashCommand (slashCmd , targetCmd string ) (result string ) {
1762
+ func SynthesizeSlashCommand (slashCmd , targetCmd , finalizeResult string ) (result string ) {
1760
1763
ctx := & logging.ContextMap {}
1761
1764
1762
1765
message , exists := config .GlobalConfig .WORKFLOW_CONFIG_VARIABLES ["APP_ACTION_TOOL_17_SUCCESS_MESSAGE" ]
@@ -1787,12 +1790,41 @@ func SynthesizeSlashCommand(slashCmd, targetCmd string) (result string) {
1787
1790
panic (errorMessage )
1788
1791
}
1789
1792
1790
- actions := []map [string ]string {
1791
- {
1792
- actionKey1 : targetCmd ,
1793
- actionKey2 : actionValue2 ,
1794
- "Argument" : slashCmd ,
1795
- },
1793
+ var actions []map [string ]string
1794
+
1795
+ if finalizeResult != "" {
1796
+ var parsedResult map [string ]interface {}
1797
+ err := json .Unmarshal ([]byte (finalizeResult ), & parsedResult )
1798
+ if err != nil {
1799
+ errorMessage := fmt .Sprintf ("failed to unmarshal finalizeResult: %v" , err )
1800
+ logging .Log .Error (ctx , errorMessage )
1801
+ panic (errorMessage )
1802
+ }
1803
+
1804
+ if parsedActions , ok := parsedResult ["Actions" ].([]interface {}); ok {
1805
+ for _ , action := range parsedActions {
1806
+ if actionMap , ok := action .(map [string ]interface {}); ok {
1807
+ updatedAction := map [string ]string {}
1808
+ for k , v := range actionMap {
1809
+ if strVal , ok := v .(string ); ok {
1810
+ updatedAction [k ] = strVal
1811
+ }
1812
+ }
1813
+ updatedAction [actionKey1 ] = targetCmd
1814
+ updatedAction [actionKey2 ] = actionValue2
1815
+ updatedAction ["Argument" ] = slashCmd
1816
+ actions = append (actions , updatedAction )
1817
+ }
1818
+ }
1819
+ }
1820
+ } else {
1821
+ actions = []map [string ]string {
1822
+ {
1823
+ actionKey1 : targetCmd ,
1824
+ actionKey2 : actionValue2 ,
1825
+ "Argument" : slashCmd ,
1826
+ },
1827
+ }
1796
1828
}
1797
1829
1798
1830
finalMessage := map [string ]interface {}{
@@ -1802,7 +1834,7 @@ func SynthesizeSlashCommand(slashCmd, targetCmd string) (result string) {
1802
1834
1803
1835
resultStream , err := json .Marshal (finalMessage )
1804
1836
if err != nil {
1805
- errorMessage := fmt .Sprintf ("failed to marshal final message for tool 17 : %v" , err )
1837
+ errorMessage := fmt .Sprintf ("failed to marshal final message: %v" , err )
1806
1838
logging .Log .Error (ctx , errorMessage )
1807
1839
panic (errorMessage )
1808
1840
}
0 commit comments