mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 14:25:51 +00:00
feat: 大规模清理 claude 的类型问题及依赖
This commit is contained in:
@@ -656,20 +656,22 @@ export function logAPISuccessAndDuration({
|
||||
let connectorCount = 0
|
||||
|
||||
for (const msg of newMessages) {
|
||||
for (const block of msg.message.content) {
|
||||
const contentArr = Array.isArray(msg.message.content) ? msg.message.content : []
|
||||
for (const block of contentArr) {
|
||||
if (typeof block === 'string') continue
|
||||
if (block.type === 'text') {
|
||||
textLen += block.text.length
|
||||
textLen += (block as { type: 'text'; text: string }).text.length
|
||||
} else if (feature('CONNECTOR_TEXT') && isConnectorTextBlock(block)) {
|
||||
connectorCount++
|
||||
} else if (block.type === 'thinking') {
|
||||
thinkingLen += block.thinking.length
|
||||
thinkingLen += (block as { type: 'thinking'; thinking: string }).thinking.length
|
||||
} else if (
|
||||
block.type === 'tool_use' ||
|
||||
block.type === 'server_tool_use' ||
|
||||
block.type === 'mcp_tool_use'
|
||||
(block.type as string) === 'mcp_tool_use'
|
||||
) {
|
||||
const inputLen = jsonStringify(block.input).length
|
||||
const sanitizedName = sanitizeToolNameForAnalytics(block.name)
|
||||
const inputLen = jsonStringify((block as { input: unknown }).input).length
|
||||
const sanitizedName = sanitizeToolNameForAnalytics((block as { name: string }).name)
|
||||
toolLengths[sanitizedName] =
|
||||
(toolLengths[sanitizedName] ?? 0) + inputLen
|
||||
hasToolUse = true
|
||||
@@ -692,7 +694,7 @@ export function logAPISuccessAndDuration({
|
||||
preNormalizedModel,
|
||||
messageCount,
|
||||
messageTokens,
|
||||
usage,
|
||||
usage: usage as unknown as Usage,
|
||||
durationMs,
|
||||
durationMsIncludingRetries,
|
||||
attempt,
|
||||
@@ -735,29 +737,35 @@ export function logAPISuccessAndDuration({
|
||||
// Model output - visible to all users
|
||||
modelOutput =
|
||||
newMessages
|
||||
.flatMap(m =>
|
||||
m.message.content
|
||||
.filter(c => c.type === 'text')
|
||||
.map(c => (c as { type: 'text'; text: string }).text),
|
||||
)
|
||||
.flatMap(m => {
|
||||
const content = m.message.content
|
||||
if (!Array.isArray(content)) return []
|
||||
return content
|
||||
.filter(c => typeof c !== 'string' && c.type === 'text')
|
||||
.map(c => (c as { type: 'text'; text: string }).text)
|
||||
})
|
||||
.join('\n') || undefined
|
||||
|
||||
// Thinking output - Ant-only (build-time gated)
|
||||
if (process.env.USER_TYPE === 'ant') {
|
||||
thinkingOutput =
|
||||
newMessages
|
||||
.flatMap(m =>
|
||||
m.message.content
|
||||
.filter(c => c.type === 'thinking')
|
||||
.map(c => (c as { type: 'thinking'; thinking: string }).thinking),
|
||||
)
|
||||
.flatMap(m => {
|
||||
const content = m.message.content
|
||||
if (!Array.isArray(content)) return []
|
||||
return content
|
||||
.filter(c => typeof c !== 'string' && c.type === 'thinking')
|
||||
.map(c => (c as { type: 'thinking'; thinking: string }).thinking)
|
||||
})
|
||||
.join('\n') || undefined
|
||||
}
|
||||
|
||||
// Check if any tool_use blocks were in the output
|
||||
hasToolCall = newMessages.some(m =>
|
||||
m.message.content.some(c => c.type === 'tool_use'),
|
||||
)
|
||||
hasToolCall = newMessages.some(m => {
|
||||
const content = m.message.content
|
||||
if (!Array.isArray(content)) return false
|
||||
return content.some(c => typeof c !== 'string' && c.type === 'tool_use')
|
||||
})
|
||||
}
|
||||
|
||||
// Pass the span to correctly match responses to requests when beta tracing is enabled
|
||||
|
||||
Reference in New Issue
Block a user