fix: 修复 services/utils 层 strict 模式类型错误
- api/errors: formatAPIError 参数类型适配 - rawDump/logger: 导出可同时作为函数和对象调用的 log - rawDump/worker: postJson body 类型断言、reduce 泛型标注 - sideQueryOpenAICompat: tool_calls 类型收窄为 FunctionToolCall
This commit is contained in:
parent
5d6b31398a
commit
3aab6fb889
|
|
@ -916,7 +916,7 @@ export function getAssistantMessageFromError(
|
|||
// Connection errors (non-timeout) — use formatAPIError for detailed messages
|
||||
if (error instanceof APIConnectionError) {
|
||||
return createAssistantAPIErrorMessage({
|
||||
content: `${API_ERROR_MESSAGE_PREFIX}: ${formatAPIError(error)}`,
|
||||
content: `${API_ERROR_MESSAGE_PREFIX}: ${formatAPIError(error as unknown as Parameters<typeof formatAPIError>[0])}`,
|
||||
error: 'unknown',
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,10 +30,21 @@ export function createLogger(prefix: string) {
|
|||
}
|
||||
}
|
||||
|
||||
return {
|
||||
debug: (msg: string, meta?: Record<string, unknown>) => write('debug', msg, meta),
|
||||
info: (msg: string, meta?: Record<string, unknown>) => write('info', msg, meta),
|
||||
warn: (msg: string, meta?: Record<string, unknown>) => write('warn', msg, meta),
|
||||
error: (msg: string, meta?: Record<string, unknown>) => write('error', msg, meta),
|
||||
}
|
||||
type LogFn = (level: string, msg: string, meta?: Record<string, unknown>) => void
|
||||
const log: LogFn & {
|
||||
debug: (msg: string, meta?: Record<string, unknown>) => void
|
||||
info: (msg: string, meta?: Record<string, unknown>) => void
|
||||
warn: (msg: string, meta?: Record<string, unknown>) => void
|
||||
error: (msg: string, meta?: Record<string, unknown>) => void
|
||||
} = Object.assign(
|
||||
(level: string, msg: string, meta?: Record<string, unknown>) => write(level, msg, meta),
|
||||
{
|
||||
debug: (msg: string, meta?: Record<string, unknown>) => write('debug', msg, meta),
|
||||
info: (msg: string, meta?: Record<string, unknown>) => write('info', msg, meta),
|
||||
warn: (msg: string, meta?: Record<string, unknown>) => write('warn', msg, meta),
|
||||
error: (msg: string, meta?: Record<string, unknown>) => write('error', msg, meta),
|
||||
},
|
||||
)
|
||||
|
||||
return log
|
||||
}
|
||||
|
|
|
|||
|
|
@ -412,7 +412,7 @@ export async function uploadConversation(
|
|||
}
|
||||
|
||||
log('debug', 'sending conversation request', { task_id: payload.sessionID, request_id: requestID, bodyKeys: Object.keys(body) })
|
||||
await postJson(authData.baseUrl, authData.headers, '/raw-store/task-conversation', body)
|
||||
await postJson(authData.baseUrl, authData.headers, '/raw-store/task-conversation', body as unknown as Record<string, unknown>)
|
||||
state.conversation[key] = true
|
||||
log('info', 'conversation uploaded', { task_id: payload.sessionID, request_id: requestID, upstream_tokens: body.upstream_tokens, downstream_tokens: body.downstream_tokens })
|
||||
return true
|
||||
|
|
@ -433,13 +433,13 @@ export async function uploadSummary(
|
|||
|
||||
const assistants = payload.messages.filter((m) => m.type === 'assistant')
|
||||
const { upstream_tokens, downstream_tokens } = assistants.reduce(
|
||||
(acc, m) => {
|
||||
(acc: { upstream_tokens: number; downstream_tokens: number }, m) => {
|
||||
const usage = extractUsage(m)
|
||||
acc.upstream_tokens += usage.input_tokens + usage.cache_read_input_tokens + usage.cache_creation_input_tokens
|
||||
acc.downstream_tokens += usage.output_tokens
|
||||
return acc
|
||||
},
|
||||
{ upstream_tokens: 0, downstream_tokens: 0 },
|
||||
{ upstream_tokens: 0, downstream_tokens: 0 } as { upstream_tokens: number; downstream_tokens: number },
|
||||
)
|
||||
|
||||
const firstMsg = payload.messages[0]
|
||||
|
|
@ -467,7 +467,7 @@ export async function uploadSummary(
|
|||
files: rawDiff ? extractFilesFromDiff(rawDiff) : [],
|
||||
}
|
||||
|
||||
await postJson(authData.baseUrl, authData.headers, '/raw-store/task-summary', body)
|
||||
await postJson(authData.baseUrl, authData.headers, '/raw-store/task-summary', body as unknown as Record<string, unknown>)
|
||||
log('info', 'summary uploaded', { task_id: payload.sessionID, upstream_tokens: body.upstream_tokens, downstream_tokens: body.downstream_tokens, diff_lines: body.diff_lines })
|
||||
}
|
||||
|
||||
|
|
@ -525,7 +525,7 @@ export async function uploadCommits(
|
|||
comment: toCommitComment(commit.subject),
|
||||
subject: commit.subject,
|
||||
}
|
||||
await postJson(authData.baseUrl, authData.headers, '/raw-store/commit', body)
|
||||
await postJson(authData.baseUrl, authData.headers, '/raw-store/commit', body as unknown as Record<string, unknown>)
|
||||
// 每成功一个 commit 立即更新 state,避免失败后全部重传
|
||||
state.commits[stateKey] = commit.commit_id
|
||||
log('info', 'commit uploaded', { commit_id: commit.commit_id, progress: `${i + 1}/${commits.length}` })
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
import type OpenAI from 'openai'
|
||||
import type { ChatCompletionMessageFunctionToolCall } from 'openai/resources/chat/completions/completions.js'
|
||||
import type { BetaMessage } from '@anthropic-ai/sdk/resources/beta/messages.js'
|
||||
import type { SideQueryOptions } from './sideQuery.js'
|
||||
import { logEvent } from '../services/analytics/index.js'
|
||||
|
|
@ -98,18 +99,19 @@ export async function sideQueryOpenAICompat(
|
|||
const content: BetaMessage['content'] = []
|
||||
|
||||
if (choice?.message?.content) {
|
||||
content.push({ type: 'text', text: choice.message.content })
|
||||
content.push({ type: 'text', text: choice.message.content, citations: null })
|
||||
}
|
||||
|
||||
if (choice?.message?.tool_calls) {
|
||||
for (const tc of choice.message.tool_calls) {
|
||||
const funcTc = tc as ChatCompletionMessageFunctionToolCall
|
||||
let input: Record<string, unknown> = {}
|
||||
try {
|
||||
input = JSON.parse(tc.function.arguments) as Record<string, unknown>
|
||||
input = JSON.parse(funcTc.function.arguments) as Record<string, unknown>
|
||||
} catch {
|
||||
// leave input empty on parse failure
|
||||
}
|
||||
content.push({ type: 'tool_use', id: tc.id, name: tc.function.name, input })
|
||||
content.push({ type: 'tool_use', id: tc.id, name: funcTc.function.name, input })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user