Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Members can read a private repository's pull request forks | 1 | import type { AgentModel } from "@g1t/contracts"; |
| 2 | ||
| 3 | /** A model as configured: what people see, and what is sent to the provider. */ | |
| 4 | export type ConfiguredModel = AgentModel & { model: string }; | |
| 5 | ||
| 6 | /** The settings that decide where model requests go. */ | |
| 7 | export type ModelRouting = { | |
| 8 | ANTHROPIC_API_KEY?: string; | |
| 9 | /** A Cloudflare AI Gateway id; empty sends requests to the provider directly. */ | |
| 10 | AI_GATEWAY_ID: string; | |
| 11 | CLOUDFLARE_ACCOUNT_ID: string; | |
| 12 | /** Needed only if the gateway requires authentication. */ | |
| 13 | AI_GATEWAY_TOKEN?: string; | |
| 14 | }; | |
| 15 | ||
| 16 | /** Where the sandbox sends model requests, and what it sends with them. */ | |
| 17 | export function modelEnv(env: ModelRouting, model: ConfiguredModel): Record<string, string> { | |
| 18 | const vars: Record<string, string> = { | |
| 19 | ANTHROPIC_API_KEY: env.ANTHROPIC_API_KEY!, | |
| 20 | ANTHROPIC_MODEL: model.model, | |
| 21 | // Recorded at the top of the session, so anyone can see what ran. | |
| 22 | AGENT_MODEL_NAME: `${model.modelName} (${model.label})`, | |
| 23 | }; | |
| 24 | if (env.AI_GATEWAY_ID) { | |
| 25 | vars.ANTHROPIC_BASE_URL = `https://gateway.ai.cloudflare.com/v1/${env.CLOUDFLARE_ACCOUNT_ID}/${env.AI_GATEWAY_ID}/anthropic`; | |
| 26 | if (env.AI_GATEWAY_TOKEN) { | |
| 27 | vars.AI_GATEWAY_TOKEN = env.AI_GATEWAY_TOKEN; | |
| 28 | vars.ANTHROPIC_CUSTOM_HEADERS = `cf-aig-authorization: Bearer ${env.AI_GATEWAY_TOKEN}`; | |
| 29 | } | |
| 30 | } | |
| 31 | return vars; | |
| 32 | } |