mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-11 14:41:21 +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
67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package claudemessages
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/QuantumNous/new-api/relaykit/dto"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestMessageStartZeroOutputSidecarRemainsRefreshable(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
info := &ClaudeResponseInfo{Usage: &dto.Usage{}}
|
|
ok := FormatClaudeResponseInfo(&dto.ClaudeResponse{
|
|
Type: "message_start",
|
|
Message: &dto.ClaudeMediaMessage{
|
|
Id: "msg_1",
|
|
Model: "claude-test",
|
|
Usage: &dto.ClaudeUsage{
|
|
InputTokens: 10,
|
|
OutputTokens: 0,
|
|
BillingUsage: dto.NewClaudeMessagesBillingUsage(&dto.ClaudeUsage{
|
|
InputTokens: 10,
|
|
OutputTokens: 0,
|
|
}),
|
|
},
|
|
},
|
|
}, nil, info)
|
|
require.True(t, ok)
|
|
|
|
ok = FormatClaudeResponseInfo(&dto.ClaudeResponse{
|
|
Type: "message_delta",
|
|
Usage: &dto.ClaudeUsage{
|
|
OutputTokens: 42,
|
|
},
|
|
}, nil, info)
|
|
require.True(t, ok)
|
|
require.NotNil(t, info.Usage.BillingUsage)
|
|
require.NotNil(t, info.Usage.BillingUsage.ClaudeUsage)
|
|
assert.Equal(t, 42, info.Usage.BillingUsage.ClaudeUsage.OutputTokens)
|
|
}
|
|
|
|
func TestTerminalSidecarRemainsAuthoritativeAgainstFinalize(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
info := &ClaudeResponseInfo{Usage: &dto.Usage{}}
|
|
ok := FormatClaudeResponseInfo(&dto.ClaudeResponse{
|
|
Type: "message_delta",
|
|
Usage: &dto.ClaudeUsage{
|
|
InputTokens: 10,
|
|
OutputTokens: 7,
|
|
BillingUsage: dto.NewClaudeMessagesBillingUsage(&dto.ClaudeUsage{
|
|
InputTokens: 10,
|
|
OutputTokens: 7,
|
|
}),
|
|
},
|
|
}, nil, info)
|
|
require.True(t, ok)
|
|
require.NotNil(t, info.Usage.BillingUsage)
|
|
require.NotNil(t, info.Usage.BillingUsage.ClaudeUsage)
|
|
|
|
info.Usage.CompletionTokens = 99
|
|
FinalizeClaudeStreamBillingUsage(info)
|
|
assert.Equal(t, 7, info.Usage.BillingUsage.ClaudeUsage.OutputTokens)
|
|
}
|