Elffuss BraidHub

kikocis/continue public

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