export interface PluginConfig {
  apiKey: string;
  endpoint: string;
  enabled: boolean;
  /** Opt-in: capture full message content in traces */
  captureContent: boolean;
  /** Maximum characters for tool output before truncation */
  maxOutputLength: number;
  /** Milliseconds between automatic flushes */
  flushInterval: number;
  /** Maximum traces per batch */
  maxBatchSize: number;
}

export function loadConfig(): PluginConfig {
  const apiKey = process.env["AGENTLENS_API_KEY"] ?? "";

  if (!apiKey) {
    console.warn(
      "[agentlens] AGENTLENS_API_KEY not set — plugin will be disabled",
    );
  }

  return {
    apiKey,
    endpoint:
      process.env["AGENTLENS_ENDPOINT"] ?? "https://agentlens.vectry.tech",
    enabled: (process.env["AGENTLENS_ENABLED"] ?? "true") === "true",
    captureContent:
      (process.env["AGENTLENS_CAPTURE_CONTENT"] ?? "false") === "true",
    maxOutputLength: parseInt(
      process.env["AGENTLENS_MAX_OUTPUT_LENGTH"] ?? "2000",
      10,
    ),
    flushInterval: parseInt(
      process.env["AGENTLENS_FLUSH_INTERVAL"] ?? "5000",
      10,
    ),
    maxBatchSize: parseInt(process.env["AGENTLENS_BATCH_SIZE"] ?? "10", 10),
  };
}
