File size: 4,603 Bytes
311fa35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import type {
  ImageProviderKey,
  LLMAuthType,
  LLMProviderKey,
  MusicProviderKey,
  SearchProviderKey,
  TTSProviderKey,
  VideoProviderKey,
} from "../schema/providers.js";

interface EnvRequirement {
  key: string;
  provider: string;
  signupUrl: string;
  required: boolean;
}

export function validateEnv(opts: {
  provider: LLMProviderKey;
  ttsProvider: TTSProviderKey;
  imageProvider: ImageProviderKey;
  videoProvider?: VideoProviderKey;
  musicProvider?: MusicProviderKey;
  searchProvider?: SearchProviderKey;
  llmAuthType?: LLMAuthType;
  noAiAssets?: boolean;
}): void {
  // The effective auth mode comes from the flag or the env var.
  const llmAuthType =
    opts.llmAuthType ??
    (["none", "bearer", "custom-header"].includes(process.env["OPENREELS_LLM_AUTH"] ?? "")
      ? (process.env["OPENREELS_LLM_AUTH"] as LLMAuthType)
      : "auto");

  const requirements: EnvRequirement[] = [
    {
      key: "ANTHROPIC_API_KEY",
      provider: "Anthropic (LLM)",
      signupUrl: "https://console.anthropic.com/",
      required: opts.provider === "anthropic",
    },
    {
      key: "OPENAI_API_KEY",
      provider: "OpenAI (LLM/Image)",
      signupUrl: "https://platform.openai.com/api-keys",
      required:
        opts.provider === "openai" ||
        (opts.imageProvider === "openai" && !opts.noAiAssets) ||
        opts.ttsProvider === "openai-tts",
    },
    {
      key: "GOOGLE_API_KEY",
      provider: "Google Gemini (LLM/Image/Video/TTS)",
      signupUrl: "https://aistudio.google.com/apikey",
      required:
        opts.provider === "gemini" ||
        (opts.imageProvider === "gemini" && !opts.noAiAssets) ||
        (opts.videoProvider === "gemini" && !opts.noAiAssets) ||
        opts.ttsProvider === "gemini-tts" ||
        opts.musicProvider === "lyria",
    },
    {
      key: "ELEVENLABS_API_KEY",
      provider: "ElevenLabs (TTS)",
      signupUrl: "https://elevenlabs.io/",
      required: opts.ttsProvider === "elevenlabs",
    },
    {
      key: "INWORLD_TTS_API_KEY",
      provider: "Inworld (TTS)",
      signupUrl: "https://inworld.ai/",
      required: opts.ttsProvider === "inworld",
    },
    {
      key: "OPENROUTER_API_KEY",
      provider: "OpenRouter (LLM)",
      signupUrl: "https://openrouter.ai/",
      required: opts.provider === "openrouter",
    },
    {
      key: "TAVILY_API_KEY",
      provider: "Tavily (Web Search)",
      signupUrl: "https://tavily.com/",
      required: opts.searchProvider === "tavily",
    },
    {
      key: "OPENREELS_LLM_API_KEY",
      provider: "OpenAI-compatible endpoint (auth)",
      signupUrl: "your endpoint's dashboard",
      required:
        opts.provider === "openai-compatible" &&
        (llmAuthType === "bearer" || llmAuthType === "custom-header"),
    },
  ];

  const missing = requirements.filter((r) => r.required && !process.env[r.key]);

  // Stock keys are optional — the pipeline degrades gracefully (black frames) — but
  // warn upfront so users aren't surprised by missing visuals on stock_image/stock_video scenes.
  const hasStockKey = process.env["PEXELS_API_KEY"] || process.env["PIXABAY_API_KEY"];
  if (!hasStockKey) {
    console.warn(
      "\nWarning: No stock media API key found (PEXELS_API_KEY or PIXABAY_API_KEY).\n" +
        (opts.noAiAssets
          ? "Stock scenes will render as procedural text cards.\n"
          : "Scenes using stock_image or stock_video will render as blank frames.\n") +
        "Get a free key: https://www.pexels.com/api/ or https://pixabay.com/api/docs/\n",
    );
  }

  // Warn when openrouter/openai-compatible without explicit search provider and no Tavily key
  const needsSearchWarning =
    (opts.provider === "openrouter" || opts.provider === "openai-compatible") &&
    !opts.searchProvider &&
    !process.env["TAVILY_API_KEY"];
  if (needsSearchWarning) {
    console.warn(
      "\nWarning: TAVILY_API_KEY not set. Web search will be disabled for this provider.\n" +
        "Research agent will use parametric knowledge only.\n" +
        "Get a key: https://tavily.com/ or use --search-provider none to suppress this warning.\n",
    );
  }

  if (missing.length === 0) return;

  console.error("\nMissing required API keys:\n");
  console.error("  Key                     Status    Get it at");
  console.error("  " + "-".repeat(70));
  for (const r of missing) {
    const key = r.key.padEnd(24);
    console.error(`  ${key}MISSING   ${r.signupUrl}`);
  }
  console.error(
    "\nSet these in your .env file (or pass with `docker run --env-file .env` when using Docker).\n",
  );
  process.exit(1);
}