AlexStocks commented on code in PR #1061:
URL: https://github.com/apache/dubbo-go-samples/pull/1061#discussion_r3032529969


##########
book-flight-ai-agent/go-server/actions/action.go:
##########
@@ -29,12 +30,23 @@ import (
 type Action mcp.RequestRPC
 
 func NewAction(text string) Action {
-       re := regexp.MustCompile("```json[^`]*```")
-       matches := re.FindAllString(text, -1)
        action := Action{}
-       if len(matches) > 0 {
-               match := matches[0][7 : len(matches[0])-3]
-               json.Unmarshal([]byte(match), &action)
+
+       // Try to extract from ```json ... ``` code fence
+       re := regexp.MustCompile("```json([^`]*)```")
+       matches := re.FindStringSubmatch(text)
+       if len(matches) > 1 {
+               jsonStr := strings.ReplaceAll(matches[1], `\n`, "\n")
+               if json.Unmarshal([]byte(jsonStr), &action) == nil {
+                       return action
+               }
+       }
+
+       // Fallback: find raw JSON object in text
+       re2 := regexp.MustCompile(`\{[^{}]*\}`)

Review Comment:
   [P1] 这个 fallback 正则只能匹配不含嵌套大括号的对象,但 Action 的正常返回本身就有 params 子对象。模型如果直接返回原始 
JSON,而不是 code fence,这里拿到的会只是 params 内层对象,最终 action.Method 为空,后面的 QueryTool 
会直接找不到工具。我本地最小复现的输出是 method 为空、params 为空。这里需要改成解析完整 JSON 对象,不能继续用这个正则截取。



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to