import { z } from "zod";

const agentEnvSchema = z.object({
  AGENT_MODEL_API: z.literal("openai-completions"),
  AGENT_MODEL_API_KEY: z.string().min(1),
  AGENT_MODEL_BASE_URL: z.url(),
  AGENT_MODEL_CONTEXT_WINDOW: z.coerce.number().int().positive(),
  AGENT_MODEL_MAX_TOKENS: z.coerce.number().int().positive(),
  AGENT_MODEL_NAME: z.string().min(1),
  AGENT_MODEL_PROVIDER: z.string().min(1),
  CONVEX_URL: z.url(),
  DAEMON_ID: z.string().min(1),
  FLUE_DB_TOKEN: z.string().min(1),
  GITEA_TOKEN: z.string().min(1).optional(),
  GITEA_URL: z.url().default("https://git.openputer.com"),
});

export type AgentEnv = z.infer<typeof agentEnvSchema>;

export const parseAgentEnv = (
  runtimeEnv: Record<string, string | undefined>
): AgentEnv => agentEnvSchema.parse(runtimeEnv);
