feat: publish sanitized custom.97 source

This commit is contained in:
cneicy committed 2026-10-27 20:43:39 +08:00
1 parent 8e6ed0317b
commit 86c0276156
1022 files changed
+69903 -19207

No files matched your search

+87
View File
@@ -5,6 +5,8 @@
package convmeta
import (
"strings"
"github.com/QuantumNous/new-api/relaykit/dto"
"github.com/QuantumNous/new-api/relaykit/types"
)
@@ -40,6 +42,15 @@ type Meta interface {
// nil receiver may return a temporary initialized state.
EnsureClaudeConvertInfo() *ClaudeConvertInfo
// ResponsesToolState returns the Responses tool encoding recorded by the
// latest request conversion, or nil when none was recorded. Response
// converters read it to restore Responses-only tool call shapes.
ResponsesToolState() *ResponsesToolState
// SetResponsesToolState replaces that record; nil clears it. Request
// conversion calls it on every attempt so retries never inherit a record
// from another channel.
SetResponsesToolState(state *ResponsesToolState)
// GetSendResponseCount / IncrSendResponseCount expose the shared
// downstream-chunk counter (the host may also increment it).
GetSendResponseCount() int
@@ -80,6 +91,60 @@ type ClaudeStreamToolCall struct {
Started bool
}
// ResponsesToolState records how Responses-only tool definitions were encoded
// for the upstream protocol, so the matching response can be restored.
type ResponsesToolState struct {
// CustomToolNames lists Responses custom (freeform) tools that were sent
// upstream as function tools taking one string "input" argument. Function
// calls with these names are custom tool calls.
CustomToolNames map[string]struct{}
// Namespaces maps an upstream function name to the Responses tool
// namespace it was flattened from; see NamespacedToolName.
Namespaces map[string]string
}
// CustomToolInputArgument is the single function argument that carries a
// Responses custom tool input through an upstream function call.
const CustomToolInputArgument = "input"
// DefaultResponsesToolNamespace is the namespace Codex declares its ordinary
// tools in. OpenAI returns calls to its tools by bare name without a
// namespace field, so its tools keep their names upstream.
const DefaultResponsesToolNamespace = "functions"
// NamespacedToolName is the upstream function name of a tool declared in a
// Responses tool namespace: "<namespace>__<name>", or the bare name for the
// default namespace.
func NamespacedToolName(namespace string, name string) string {
if namespace == "" || namespace == DefaultResponsesToolNamespace {
return name
}
return namespace + "__" + name
}
// IsCustomTool reports whether name was encoded from a Responses custom tool.
func (s *ResponsesToolState) IsCustomTool(name string) bool {
if s == nil {
return false
}
_, ok := s.CustomToolNames[name]
return ok
}
// ResponsesToolName restores the Responses namespace and tool name of an
// upstream function name. Names that were not flattened from a namespace
// return an empty namespace and the name unchanged.
func (s *ResponsesToolState) ResponsesToolName(upstreamName string) (string, string) {
if s == nil {
return "", upstreamName
}
namespace, ok := s.Namespaces[upstreamName]
if !ok {
return "", upstreamName
}
return namespace, strings.TrimPrefix(upstreamName, namespace+"__")
}
const (
LastMessageTypeNone = "none"
LastMessageTypeText = "text"
@@ -101,6 +166,7 @@ type Values struct {
EstimatePromptTokens int
ClaudeConvertInfo *ClaudeConvertInfo
ResponsesTools *ResponsesToolState
SendResponseCount int
ConversionChain []types.RelayFormat
@@ -182,6 +248,19 @@ func (v *Values) EnsureClaudeConvertInfo() *ClaudeConvertInfo {
return v.ClaudeConvertInfo
}
func (v *Values) ResponsesToolState() *ResponsesToolState {
if v == nil {
return nil
}
return v.ResponsesTools
}
func (v *Values) SetResponsesToolState(state *ResponsesToolState) {
if v != nil {
v.ResponsesTools = state
}
}
func (v *Values) GetSendResponseCount() int {
if v == nil {
return 0
@@ -240,6 +319,14 @@ func OptionsOf(m Meta) *Options {
return m.ConvOptions()
}
// ResponsesToolStateOf is a nil-safe reader for Meta.ResponsesToolState.
func ResponsesToolStateOf(m Meta) *ResponsesToolState {
if m == nil {
return nil
}
return m.ResponsesToolState()
}
// ReasoningStateOf is a nil-safe reader for Meta.ReasoningState.
func ReasoningStateOf(m Meta) *dto.ReasoningConversionState {
if m == nil {