* fix(openai): harden Chat-to-Responses compatibility Add a shared Responses-to-Chat stream state machine and use it from the OpenAI relay path. Preserve assistant text alongside tool calls, bind tool argument deltas by output_index, map incomplete finish reasons, support reasoning/custom tool events, and buffer upstream SSE for non-stream Chat clients. Add deterministic service tests and relay SSE tests for the conversion path. Related to #5745. * refactor: rename openaicompat to relayconvert for improved clarity * feat(gemini): support responses request conversion * feat: add responses to chat conversion support * fix: harden responses chat conversion edge cases
34 lines
656 B
Go
34 lines
656 B
Go
package relayconvert
|
|
|
|
import (
|
|
"regexp"
|
|
"sync"
|
|
)
|
|
|
|
var compiledRegexCache sync.Map // map[string]*regexp.Regexp
|
|
|
|
func matchAnyRegex(patterns []string, s string) bool {
|
|
if len(patterns) == 0 || s == "" {
|
|
return false
|
|
}
|
|
for _, pattern := range patterns {
|
|
if pattern == "" {
|
|
continue
|
|
}
|
|
re, ok := compiledRegexCache.Load(pattern)
|
|
if !ok {
|
|
compiled, err := regexp.Compile(pattern)
|
|
if err != nil {
|
|
// Treat invalid patterns as non-matching to avoid breaking runtime traffic.
|
|
continue
|
|
}
|
|
re = compiled
|
|
compiledRegexCache.Store(pattern, re)
|
|
}
|
|
if re.(*regexp.Regexp).MatchString(s) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|