feat: 添加对 langfuse 监控的支持 (#242)

* docs: 更新类型检查的 CLAUDE.md

* feat: 添加模型 1M 上下文切换

* chore: remove prefetchOfficialMcpUrls call on startup

* docs: 添加 git commit 规范

* feat: 第一次接入 langfuse

* fix: 修复 generation 的计时的错误

* feat: 添加多 agent 的监控

* feat: 添加 /poor 省流模式,toggle 关闭 extract_memories 和 prompt_suggestion

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: 修复 lock 文件

* chore: 更新类型依赖

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-04-11 22:07:38 +08:00
committed by GitHub
parent 6a9da9d546
commit 2fea429dc6
23 changed files with 1242 additions and 6 deletions

View File

@@ -50,6 +50,7 @@ import {
} from '../../tools/ToolSearchTool/prompt.js'
import { getAllBaseTools } from '../../tools.js'
import type { HookProgress } from '../../types/hooks.js'
import { recordToolObservation } from '../langfuse/index.js'
import type {
AssistantMessage,
AttachmentMessage,
@@ -1300,6 +1301,16 @@ async function checkPermissionsAndCallTool(
: String(result.data ?? '')
endToolSpan(toolResultStr)
// Record tool observation in Langfuse (no-op if not configured)
recordToolObservation(toolUseContext.langfuseTrace ?? null, {
toolName: tool.name,
toolUseId: toolUseID,
input: processedInput,
output: toolResultStr,
startTime: new Date(startTime),
isError: false,
})
// Map the tool result to API format once and cache it. This block is reused
// by addToolResult (skipping the remap) and measured here for analytics.
const mappedToolResultBlock = tool.mapToolResultToToolResultBlockParam(
@@ -1609,6 +1620,16 @@ async function checkPermissionsAndCallTool(
})
endToolSpan()
// Record error observation in Langfuse (no-op if not configured)
recordToolObservation(toolUseContext.langfuseTrace ?? null, {
toolName: tool?.name ?? 'unknown',
toolUseId: toolUseID,
input: processedInput ?? input,
output: errorMessage(error),
startTime: new Date(startTime),
isError: true,
})
// Handle MCP auth errors by updating the client status to 'needs-auth'
// This updates the /mcp display to show the server needs re-authorization
if (error instanceof McpAuthError) {