// src/server/config.ts
import { z } from "zod";
var backendSchema = z.enum(["auto", "vllm", "sglang", "ollama", "llamacpp"]).default("auto");
var envSchema = z.object({
  // New env var name, with fallback to old name for backward compatibility
  OPENFOX_LLM_URL: z.string().url().optional(),
  OPENFOX_VLLM_URL: z.string().url().optional(),
  OPENFOX_BACKEND: backendSchema,
  OPENFOX_MODEL_NAME: z.string().default("qwen3.5-122b-int4-autoround"),
  OPENFOX_MAX_CONTEXT: z.coerce.number().default(2e5),
  OPENFOX_PORT: z.coerce.number().default(10369),
  OPENFOX_HOST: z.string().optional(),
  OPENFOX_WORKDIR: z.string().optional(),
  OPENFOX_DB_PATH: z.string().default("./openfox.db"),
  OPENFOX_LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]).default("info"),
  OPENFOX_DISABLE_THINKING: z.coerce.boolean().default(false),
  OPENFOX_DEV: z.coerce.boolean().default(false)
});
function loadConfig() {
  const env = envSchema.parse(process.env);
  const llmUrl = env.OPENFOX_LLM_URL ?? env.OPENFOX_VLLM_URL ?? "http://localhost:8000/v1";
  const workdir = env.OPENFOX_WORKDIR ?? process.cwd();
  return {
    llm: {
      baseUrl: llmUrl,
      model: env.OPENFOX_MODEL_NAME,
      timeout: 3e5,
      // 5 minutes (deprecated, kept for backward compatibility)
      idleTimeout: 3e5,
      // 5 minutes of inactivity
      backend: env.OPENFOX_BACKEND,
      disableThinking: env.OPENFOX_DISABLE_THINKING
    },
    context: {
      maxTokens: env.OPENFOX_MAX_CONTEXT,
      compactionThreshold: 0.85,
      compactionTarget: 0.6
    },
    agent: {
      maxIterations: 10,
      maxConsecutiveFailures: 3,
      toolTimeout: 3e5
    },
    server: {
      port: env.OPENFOX_PORT,
      ...env.OPENFOX_HOST !== void 0 ? { host: env.OPENFOX_HOST } : {}
    },
    database: {
      path: env.OPENFOX_DB_PATH
    },
    mode: env.OPENFOX_DEV ? "development" : "production",
    workdir
  };
}

// src/server/runtime-config.ts
var runtimeConfig = null;
function setRuntimeConfig(config) {
  runtimeConfig = config;
}
function getRuntimeConfig() {
  return runtimeConfig ?? loadConfig();
}

export {
  loadConfig,
  setRuntimeConfig,
  getRuntimeConfig
};
//# sourceMappingURL=chunk-CGZHLM3K.js.map