mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-07 10:07:07 +00:00
* feat(relaykit): preserve hosted tools across conversions - add protocol-neutral hosted-tool DTOs, conversion metadata, and loss policies - bridge citations, grounding metadata, and hosted-tool stream lifecycles - document the public conversion behavior and channel policy controls * refactor(relaykit): normalize reasoning and thinking intent - centralize provider-neutral reasoning intent, effort, and budget mappings - parse model suffixes at the host entry boundary while preserving provider-owned tails - keep adaptive Claude thinking and explicit zero-token compatibility consistent * fix(billing): preserve authoritative usage across relay hops - carry native BillingUsage sidecars through direct and streamed protocol bridges - merge partial and terminal usage monotonically with safe fallback settlement - retain cache metadata, penultimate usage, and per-call Gemini tool surcharges * feat(relay): bridge Responses with Claude and Gemini protocols - add direct request, response, and stream converters across supported relay formats - expose Claude count_tokens and Chat-to-Responses compatibility endpoints - carry conversion diagnostics through the host while retaining the curated public goldens * fix(relay): wire relaykit conversions into host channels - connect handlers, adaptors, and channel settings to the standalone conversion layer - keep model mapping, pricing identity, retries, and provider-specific suffix behavior aligned - ignore local audit artifacts and retain focused public regression coverage
76 lines
2.4 KiB
Go
76 lines
2.4 KiB
Go
package types
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
type ConversionDiagnosticSeverity string
|
|
|
|
const (
|
|
ConversionDiagnosticWarning ConversionDiagnosticSeverity = "warning"
|
|
ConversionDiagnosticError ConversionDiagnosticSeverity = "error"
|
|
)
|
|
|
|
type ConversionDiagnostic struct {
|
|
Code string `json:"code"`
|
|
Path string `json:"path,omitempty"`
|
|
Message string `json:"message"`
|
|
Severity ConversionDiagnosticSeverity `json:"severity"`
|
|
From RelayFormat `json:"from"`
|
|
To RelayFormat `json:"to"`
|
|
}
|
|
|
|
type ConversionLossPolicy string
|
|
|
|
const (
|
|
// ConversionLossPolicySafe rejects request-phase conversions that would
|
|
// change tool execution semantics, while returning non-fatal loss as
|
|
// diagnostics. It is opt-in; the default is ConversionLossPolicyAllow.
|
|
ConversionLossPolicySafe ConversionLossPolicy = "safe"
|
|
// ConversionLossPolicyStrict rejects every lossy conversion, including
|
|
// presentation-only metadata loss.
|
|
ConversionLossPolicyStrict ConversionLossPolicy = "strict"
|
|
// ConversionLossPolicyAllow is the default. It permits lossy conversion
|
|
// and reports every loss through the conversion result.
|
|
ConversionLossPolicyAllow ConversionLossPolicy = "allow"
|
|
)
|
|
|
|
type ConversionLossError struct {
|
|
Diagnostics []ConversionDiagnostic
|
|
}
|
|
|
|
func (e *ConversionLossError) Error() string {
|
|
if e == nil || len(e.Diagnostics) == 0 {
|
|
return "conversion would lose protocol semantics"
|
|
}
|
|
messages := make([]string, 0, len(e.Diagnostics))
|
|
for _, diagnostic := range e.Diagnostics {
|
|
message := diagnostic.Message
|
|
if message == "" {
|
|
message = diagnostic.Code
|
|
}
|
|
if diagnostic.Path != "" {
|
|
message = fmt.Sprintf("%s: %s", diagnostic.Path, message)
|
|
}
|
|
messages = append(messages, message)
|
|
}
|
|
return "conversion would lose protocol semantics: " + strings.Join(messages, "; ")
|
|
}
|
|
|
|
func RejectConversionLoss(policy ConversionLossPolicy, diagnostics []ConversionDiagnostic) error {
|
|
if policy == ConversionLossPolicyAllow || len(diagnostics) == 0 {
|
|
return nil
|
|
}
|
|
rejected := make([]ConversionDiagnostic, 0, len(diagnostics))
|
|
for _, diagnostic := range diagnostics {
|
|
if policy == ConversionLossPolicyStrict || diagnostic.Severity == ConversionDiagnosticError {
|
|
rejected = append(rejected, diagnostic)
|
|
}
|
|
}
|
|
if len(rejected) == 0 {
|
|
return nil
|
|
}
|
|
return &ConversionLossError{Diagnostics: rejected}
|
|
}
|