diff --git a/internal/adapter/openai/tool_sieve_core.go b/internal/adapter/openai/tool_sieve_core.go index 3d70551..1b3c975 100644 --- a/internal/adapter/openai/tool_sieve_core.go +++ b/internal/adapter/openai/tool_sieve_core.go @@ -282,32 +282,3 @@ func consumeToolCapture(state *toolStreamSieveState, toolNames []string) (prefix prefixPart, suffixPart = trimWrappingJSONFence(prefixPart, suffixPart) return prefixPart, parsed.Calls, suffixPart, true } - -func findQuotedFunctionCallKeyStart(s string) int { - lower := strings.ToLower(s) - const key = "\"functioncall\"" - for from := 0; from < len(lower); { - rel := strings.Index(lower[from:], key) - if rel < 0 { - return -1 - } - idx := from + rel - if !hasJSONObjectContextPrefix(lower[:idx]) { - from = idx + 1 - continue - } - j := idx + len(key) - for j < len(lower) && (lower[j] == ' ' || lower[j] == '\t' || lower[j] == '\r' || lower[j] == '\n') { - j++ - } - if j < len(lower) && lower[j] == ':' { - return idx - } - from = idx + 1 - } - return -1 -} - -func hasJSONObjectContextPrefix(prefix string) bool { - return strings.LastIndex(prefix, "{") >= 0 -} diff --git a/internal/adapter/openai/tool_sieve_functioncall.go b/internal/adapter/openai/tool_sieve_functioncall.go new file mode 100644 index 0000000..f3cacbe --- /dev/null +++ b/internal/adapter/openai/tool_sieve_functioncall.go @@ -0,0 +1,32 @@ +package openai + +import "strings" + +func findQuotedFunctionCallKeyStart(s string) int { + lower := strings.ToLower(s) + const key = "\"functioncall\"" + for from := 0; from < len(lower); { + rel := strings.Index(lower[from:], key) + if rel < 0 { + return -1 + } + idx := from + rel + if !hasJSONObjectContextPrefix(lower[:idx]) { + from = idx + 1 + continue + } + j := idx + len(key) + for j < len(lower) && (lower[j] == ' ' || lower[j] == '\t' || lower[j] == '\r' || lower[j] == '\n') { + j++ + } + if j < len(lower) && lower[j] == ':' { + return idx + } + from = idx + 1 + } + return -1 +} + +func hasJSONObjectContextPrefix(prefix string) bool { + return strings.LastIndex(prefix, "{") >= 0 +}