Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ Domains chain together: competitive research feeds marketing and business strate

## Recent Changes

- anthropic-proxy-endpoint: Native Anthropic Messages API proxy — `POST /ai/anthropic/v1/messages` pass-through to Cloudflare AI Gateway (`apps/api/src/routes/ai-proxy-anthropic.ts`); receives native Anthropic format, forwards unchanged to AI Gateway's `/anthropic/v1/messages` path (no format translation); auth via `x-api-key` header (workspace callback token — matches Claude Code's auth format); forwards `anthropic-version` and `anthropic-beta` headers; SSE streaming pass-through; model validation (claude-* only); `POST /ai/anthropic/v1/messages/count_tokens` token counting endpoint; shared helpers extracted to `apps/api/src/services/ai-proxy-shared.ts` (`extractCallbackToken`, `verifyAIProxyAuth`, `buildAIGatewayMetadata`, `buildAnthropicGatewayUrl`, `resolveAnthropicApiKey`, `AIProxyAuthError`); existing `ai-proxy.ts` refactored to use shared helpers; per-user RPM rate limiting and daily token budget shared with OpenAI proxy; Anthropic-format error responses (`{ type: "error", error: { type, message } }`); `cf-aig-metadata` header injected for cost attribution; configurable via AI_PROXY_ENABLED (kill switch), AI_PROXY_RATE_LIMIT_RPM (default: 30), AI_PROXY_RATE_LIMIT_WINDOW_SECONDS (default: 60), AI_PROXY_DAILY_INPUT_TOKEN_LIMIT (default: 500000), AI_PROXY_DAILY_OUTPUT_TOKEN_LIMIT (default: 200000), AI_GATEWAY_ID
- cost-monitoring-dashboard: Admin cost monitoring dashboard — `GET /api/admin/costs` route (`apps/api/src/routes/admin-costs.ts`) aggregates LLM costs from Cloudflare AI Gateway logs API (paginated, per-model/per-day/per-user breakdown, trial cost tracking, cached/error request counts) and compute costs from `getAllUsersNodeUsageSummary` node usage service into a unified `CostSummaryResponse`; monthly projection via daily average extrapolation; `AdminCosts.tsx` page with KPI cards (LLM cost, monthly projection, compute estimate, combined), daily cost trend AreaChart, cost by model horizontal BarChart + table, cost by user table; period selector (current-month, 30d, 90d); admin tab at `/admin/costs`; configurable via COST_MONITORING_ENABLED (default: true, set to 'false' to disable), COMPUTE_VCPU_HOUR_COST_USD (default: 0.003), AI_USAGE_PAGE_SIZE (default: 50), AI_USAGE_MAX_PAGES (default: 20, hard cap: 20)
- sam-observability-context-tools: SAM observability and codebase context tools — 5 new tools in `apps/api/src/durable-objects/sam-session/tools/` enable SAM to search task messages and browse project codebases: `list_sessions` (browse project chat sessions with status/taskId filters via `projectDataService.listSessions`), `get_session_messages` (retrieve grouped messages from a session via `projectDataService.getMessages` + `groupTokensIntoMessages`), `search_task_messages` (full-text search across task messages via `projectDataService.searchMessages` with FTS5/LIKE fallback, taskId→sessionId resolution), `search_code` (GitHub Code Search API with `repo:owner/name` qualifier, path/extension filters, text_matches snippets), `get_file_content` (GitHub Contents API for file content or directory listing with base64 decode); shared `helpers.ts` extracts `resolveProjectWithOwnership()`, `parseRepository()`, `getUserGitHubToken()` from `get-ci-status.ts`; SAM_SYSTEM_PROMPT updated with "Task Message Search (Observability)" and "Codebase Context" tool sections; configurable via SAM_SESSION_MESSAGES_LIMIT (default: 50), SAM_SESSION_MESSAGES_MAX_LIMIT (default: 200), SAM_SESSION_LIST_LIMIT (default: 20), SAM_SESSION_LIST_MAX_LIMIT (default: 100), SAM_TASK_MESSAGE_SEARCH_LIMIT (default: 10), SAM_TASK_MESSAGE_SEARCH_MAX_LIMIT (default: 50), SAM_CODE_SEARCH_LIMIT (default: 10), SAM_CODE_SEARCH_MAX_LIMIT (default: 30), SAM_FILE_CONTENT_MAX_BYTES (default: 1048576)
- sam-agent-phase-a-tools: SAM Phase A orchestration tools — 4 new tools in `apps/api/src/durable-objects/sam-session/tools/` transform SAM from read-only to functional orchestrator: `dispatch_task` (provisions workspace, runs agent, resolves config via explicit→profile→project→platform chain, reuses `startTaskRunnerDO`, `generateBranchName`, `generateTaskTitle`, `resolveAgentProfile`, `resolveCredentialSource`, `projectDataService.createSession/persistMessage`), `get_task_details` (full task details with output/PR/error via D1 tasks+projects join), `create_mission` (D1 insert + ProjectOrchestrator DO registration, per-project limit enforcement), `get_mission` (mission status with task summary counts and individual task list via projects join for ownership); all tools registered in `tools/index.ts` SAM_TOOLS array and toolHandlers map; SAM_SYSTEM_PROMPT updated with Observation and Action tool categories; `dispatch_task` accepts optional `missionId` for mission-task association; configurable via SAM_DISPATCH_MAX_DESCRIPTION_LENGTH (default: 32000)
Expand Down
4 changes: 3 additions & 1 deletion apps/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { agentProfileRoutes } from './routes/agent-profiles';
import { agentSettingsRoutes } from './routes/agent-settings';
import { agentsCatalogRoutes } from './routes/agents-catalog';
import { aiProxyRoutes } from './routes/ai-proxy';
import { aiProxyAnthropicRoutes } from './routes/ai-proxy-anthropic';
import { analyticsIngestRoutes } from './routes/analytics-ingest';
import { authRoutes } from './routes/auth';
import { bootstrapRoutes } from './routes/bootstrap';
Expand Down Expand Up @@ -320,7 +321,7 @@ app.use('*', cors({
return null;
},
credentials: true,
allowHeaders: ['Content-Type', 'Authorization'],
allowHeaders: ['Content-Type', 'Authorization', 'x-api-key', 'anthropic-version', 'anthropic-beta'],
allowMethods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
}));

Expand Down Expand Up @@ -429,6 +430,7 @@ app.route('/api', trialRoutes);
app.route('/api/trial', trialOnboardingRoutes);
app.route('/api/gcp', gcpRoutes);
app.route('/ai/v1', aiProxyRoutes);
app.route('/ai/anthropic/v1', aiProxyAnthropicRoutes);
app.route('/auth/google', googleAuthRoutes);
// MCP endpoint CORS override — MCP uses Bearer token auth (not cookies/sessions),
// so it needs credentials: false + origin: '*' to allow VM agent requests from any origin.
Expand Down
Loading
Loading