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

@@ -57,6 +57,12 @@ import { clearSessionHooks } from '../../utils/hooks/sessionHooks.js'
import { executeSubagentStartHooks } from '../../utils/hooks.js'
import { createUserMessage } from '../../utils/messages.js'
import { getAgentModel } from '../../utils/model/agent.js'
import { getAPIProvider } from '../../utils/model/providers.js'
import {
createSubagentTrace,
endTrace,
isLangfuseEnabled,
} from '../../services/langfuse/index.js'
import type { ModelAlias } from '../../utils/model/aliases.js'
import {
clearAgentTranscriptSubdir,
@@ -744,6 +750,25 @@ export async function* runAgent({
// Track the last recorded message UUID for parent chain continuity
let lastRecordedUuid: UUID | null = initialMessages.at(-1)?.uuid ?? null
// Create Langfuse sub-agent trace (no-op if not configured).
// Sub-agent trace shares the same sessionId as the parent, so Langfuse
// groups them under the same Session view.
const subTrace = isLangfuseEnabled()
? createSubagentTrace({
sessionId: getSessionId(),
agentType: agentDefinition.agentType,
agentId,
model: resolvedAgentModel,
provider: getAPIProvider(),
input: initialMessages,
})
: null
// Attach sub-agent trace to toolUseContext so query() reuses it
if (subTrace) {
agentToolUseContext.langfuseTrace = subTrace
}
try {
for await (const message of query({
messages: initialMessages,
@@ -814,6 +839,8 @@ export async function* runAgent({
agentDefinition.callback()
}
} finally {
// End Langfuse sub-agent trace (no-op if not configured)
endTrace(subTrace)
// Clean up agent-specific MCP servers (runs on normal completion, abort, or error)
await mcpCleanup()
// Clean up agent's session hooks