feat(usage): attribute requests to agent sessions and projects - #14833
fouadSalkini wants to merge 6 commits into
Conversation
…-sessions-project-attribution # Conflicts: # config/quality/file-size-baseline.json
The release tip now owns 190_call_logs_content_provenance.sql, so this PR's 190/191 collided. Move to the tentative slots 197/198 (age-order scheme; diegosouzapw#14771 got 194, diegosouzapw#14801 got 196) pending maintainer confirmation, rename the matching test, and update the migration-count claims in README.md, AGENTS.md, llm.txt and its 66 i18n mirrors (regenerated with scripts/i18n/sync-llm-mirrors.mjs).
|
Updated to latest |
…-sessions-project-attribution # Conflicts: # config/quality/file-size-baseline.json
|
Merged the latest The migration-count docs failure is the inherited base-red #14866. |
…egosouzapw#14864 agent sessions Agent session and project attribution (diegosouzapw#14833), the /v1/me/sessions self-service endpoints (diegosouzapw#14840), and /v1/me/sessions/{id}/messages with opt-in turn capture (diegosouzapw#14864), including the chatCore wiring, as deployed. Migrations keep the deployed numbers 9191-9193, which production databases have already applied. chatCore.ts also carries the diegosouzapw#14314 and diegosouzapw#14862 wiring.
…zapw#14863 and diegosouzapw#14864 files Adds the deployed useApiKeyDetails.ts (diegosouzapw#14863), the agent-session-messages retention in cleanup.ts (diegosouzapw#14864), the agent session attribution in usageHistory.ts (diegosouzapw#14833/diegosouzapw#14864), and the Opus 5.5 case in the combo catalog test. The content is as deployed, reformatted by prettier only.
|
Re-homed to |
Summary
Attributes each proxied request to a coding-agent session and project for team usage reporting:
open-sse/handlers/chatCore/agentContext.ts: pure extraction of client, clientSessionId, projectName, projectRepo, projectPath, and gitBranch.x-omniroute-project/x-omniroute-project-repoheaders win; falls back to announced working directory inrole: "system"message (Claude Code 2.1.282mid-conversation-systembeta), top-levelsystem(older builds), or<environment_context><cwd>(Codex)./.claude/worktrees/,/.worktrees/) are stripped to resolve the true repository name.x-omniroute-session-id->x-claude-code-session-id->metadata.user_id.session_id->x-codex-session-id->x-opencode-session->metadata.session_id.noLogdrop prompt-derived fields (working directory, branch) while preserving explicit headers.src/lib/db/agentSessions.ts: upserts one aggregate row per(apiKeyId, clientSessionId)with input/output/cache/reasoning tokens, request/error counts, pricedcost_usd, and unpriced count. Without a client session id, requests from the same key and project within 30 minutes share a session.src/lib/usage/usageHistory.ts: prices the request viacalculateCostDetailedbefore the transaction, then records session usage and linksusage_history.agent_session_idwithin the existing transaction.190_agent_sessions.sqland191_usage_history_agent_session_id.sql.docs/guides/CLAUDE-CODE-CONFIGURATION.md: documents usage attribution and the dynamicclaude()shell wrapper usingANTHROPIC_CUSTOM_HEADERS.Verification
All passed clean.