mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 22:35:51 +00:00
feat: 完成第二版类型清理
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { BetaToolUseBlock } from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs'
|
||||
import type { ToolResultBlockParam } from '@anthropic-ai/sdk/resources/messages/messages.mjs'
|
||||
import type { ContentBlockParam, ToolResultBlockParam } from '@anthropic-ai/sdk/resources/messages/messages.mjs'
|
||||
import type { Tools } from '../Tool.js'
|
||||
import type {
|
||||
GroupedToolUseMessage,
|
||||
@@ -34,10 +34,10 @@ function getToolsWithGrouping(tools: Tools): Set<string> {
|
||||
function getToolUseInfo(
|
||||
msg: MessageWithoutProgress,
|
||||
): { messageId: string; toolUseId: string; toolName: string } | null {
|
||||
if (msg.type === 'assistant' && msg.message.content[0]?.type === 'tool_use') {
|
||||
const content = msg.message.content[0]
|
||||
if (msg.type === 'assistant' && msg.message?.content && Array.isArray(msg.message.content) && (msg.message.content[0] as { type?: string })?.type === 'tool_use') {
|
||||
const content = msg.message.content[0] as unknown as { type: 'tool_use'; id: string; name: string; [key: string]: unknown }
|
||||
return {
|
||||
messageId: msg.message.id,
|
||||
messageId: msg.message.id as string,
|
||||
toolUseId: content.id,
|
||||
toolName: content.name,
|
||||
}
|
||||
@@ -59,7 +59,7 @@ export function applyGrouping(
|
||||
// In verbose mode, don't group - each message renders at its original position
|
||||
if (verbose) {
|
||||
return {
|
||||
messages: messages,
|
||||
messages: messages as RenderableMessage[],
|
||||
}
|
||||
}
|
||||
const toolsWithGrouping = getToolsWithGrouping(tools)
|
||||
@@ -104,13 +104,13 @@ export function applyGrouping(
|
||||
const resultsByToolUseId = new Map<string, NormalizedUserMessage>()
|
||||
|
||||
for (const msg of messages) {
|
||||
if (msg.type === 'user') {
|
||||
if (msg.type === 'user' && msg.message?.content && Array.isArray(msg.message.content)) {
|
||||
for (const content of msg.message.content) {
|
||||
if (
|
||||
content.type === 'tool_result' &&
|
||||
groupedToolUseIds.has(content.tool_use_id)
|
||||
(content as { type?: string }).type === 'tool_result' &&
|
||||
groupedToolUseIds.has((content as { tool_use_id: string }).tool_use_id)
|
||||
) {
|
||||
resultsByToolUseId.set(content.tool_use_id, msg)
|
||||
resultsByToolUseId.set((content as { tool_use_id: string }).tool_use_id, msg as NormalizedUserMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,8 +161,8 @@ export function applyGrouping(
|
||||
}
|
||||
|
||||
// Skip user messages whose tool_results are all grouped
|
||||
if (msg.type === 'user') {
|
||||
const toolResults = msg.message.content.filter(
|
||||
if (msg.type === 'user' && msg.message?.content && Array.isArray(msg.message.content)) {
|
||||
const toolResults = (msg.message.content as Array<ContentBlockParam>).filter(
|
||||
(c): c is ToolResultBlockParam => c.type === 'tool_result',
|
||||
)
|
||||
if (toolResults.length > 0) {
|
||||
@@ -175,7 +175,7 @@ export function applyGrouping(
|
||||
}
|
||||
}
|
||||
|
||||
result.push(msg)
|
||||
result.push(msg as RenderableMessage)
|
||||
}
|
||||
|
||||
return { messages: result }
|
||||
|
||||
Reference in New Issue
Block a user