Elffuss BraidHub

kikocis/continue public

2ff6e1c400a1 · 1.0 KiBRawPermalink
1import { decodeSecretLocation, SecretType } from "@continuedev/config-yaml";
2import { BrowserSerializedContinueConfig } from "core";
3/**
4 * Helper function to determine if the config uses a free trial API key
5 * @param config The serialized config object
6 * @returns true if the config is using any free trial models
7 */
8export function usesFreeTrialApiKey(
9 config: BrowserSerializedContinueConfig | null,
10): boolean {
11 if (!config) {
12 return false;
13 }
14
15 // Check if the currently selected chat model uses free-trial provider
16 const modelsByRole = config.modelsByRole;
17 const allModels = [...Object.values(modelsByRole)].flat();
18
19 // Check if any of the chat models use free-trial provider
20 try {
21 const hasFreeTrial = allModels?.some(
22 (model) =>
23 model.apiKeyLocation &&
24 decodeSecretLocation(model.apiKeyLocation).secretType ===
25 SecretType.FreeTrial,
26 );
27
28 return hasFreeTrial;
29 } catch (e) {
30 console.error("Error checking for free trial API key:", e);
31 }
32
33 return false;
34}