Merge pull request #84 from CJackHwang/codex/fix-code-conflicts-in-pr-#82

Resolve PR #82 merge conflicts and restore tool-call parsing (invoke/argument and XML arguments)
This commit is contained in:
CJACK.
2026-03-08 02:31:21 +08:00
committed by GitHub
2 changed files with 26 additions and 1 deletions

View File

@@ -15,6 +15,7 @@ var antmlArgumentPattern = regexp.MustCompile(`(?is)<(?:[a-z0-9_]+:)?argument\s+
var antmlParametersPattern = regexp.MustCompile(`(?is)<(?:[a-z0-9_]+:)?parameters\s*>\s*(\{.*?\})\s*</(?:[a-z0-9_]+:)?parameters>`)
var invokeCallPattern = regexp.MustCompile(`(?is)<invoke\s+name="([^"]+)"\s*>(.*?)</invoke>`)
var invokeParamPattern = regexp.MustCompile(`(?is)<parameter\s+name="([^"]+)"\s*>\s*(.*?)\s*</parameter>`)
var invokeArgumentPattern = regexp.MustCompile(`(?is)<argument(?:\s+name="([^"]+)")?\s*>\s*(.*?)\s*</argument>`)
func parseXMLToolCalls(text string) []ParsedToolCall {
matches := xmlToolCallPattern.FindAllString(text, -1)
@@ -111,6 +112,14 @@ func parseSingleXMLToolCall(block string) (ParsedToolCall, bool) {
}
}
}
if fallback := parseMarkupSingleToolCall("", inner); fallback.Name != "" {
if strings.TrimSpace(name) == "" {
name = fallback.Name
}
if len(params) == 0 && strings.EqualFold(strings.TrimSpace(fallback.Name), strings.TrimSpace(name)) {
params = fallback.Input
}
}
if strings.TrimSpace(name) == "" {
return ParsedToolCall{}, false
}
@@ -210,6 +219,23 @@ func parseInvokeFunctionCallStyle(text string) (ParsedToolCall, bool) {
input[k] = v
}
}
for _, am := range invokeArgumentPattern.FindAllStringSubmatch(m[2], -1) {
if len(am) < 3 {
continue
}
key := strings.TrimSpace(am[1])
raw := strings.TrimSpace(am[2])
if raw == "" {
continue
}
if key != "" {
input[key] = raw
continue
}
for k, v := range parseToolCallInput(raw) {
input[k] = v
}
}
return ParsedToolCall{Name: name, Input: input}, true
}

View File

@@ -271,7 +271,6 @@ func TestParseToolCallsSupportsMultipleAntmlFunctionCalls(t *testing.T) {
t.Fatalf("expected canonical names [bash read], got %#v", calls)
}
}
func TestParseToolCallsDoesNotAcceptMismatchedMarkupTags(t *testing.T) {
text := `<tool_call><name>read_file</function><arguments>{"path":"README.md"}</arguments></tool_call>`
calls := ParseToolCalls(text, []string{"read_file"})