11<template >
2- <div class =" api-key-form" >
3- <BaseInput
4- type =" password"
5- placeholder =" sk-proj-..."
6- v-model =" openaiApiKey"
7- >
2+ <div class =" api-key-form" :class =" { 'dropdown-based': dropdownBased }" >
3+ <div class =" input-container" v-if =" dropdownBased" >
4+ <label for =" select-provider" >Provider</label >
5+ <Select for =" select-provider" v-model =" selectedProvider" :options =" dropdownOptions" optionLabel =" label"
6+ placeholder =" Select a provider" />
7+ </div >
8+ <BaseInput v-if =" !dropdownBased || selectedProvider.value === 'openai'" type =" password" placeholder =" sk-proj-..."
9+ v-model =" openaiApiKey" >
810 <template #label >
911 {{ providerConfigs["openai"].displayName }}
12+ {{ dropdownBased ? "API Key" : '' }}
1013 </template >
1114 <template #helper >
1215 Get your <ExternalLink href =" https://platform.openai.com/account/api-keys" >API Key here.</ExternalLink >
1316 </template >
1417 </BaseInput >
15- <BaseInput
16- type =" password"
17- placeholder =" sk-ant-..."
18- v-model =" anthropicApiKey"
19- >
18+ <BaseInput v-if =" !dropdownBased || selectedProvider.value === 'anthropic'" type =" password" placeholder =" sk-ant-..."
19+ v-model =" anthropicApiKey" >
2020 <template #label >
2121 {{ providerConfigs["anthropic"].displayName }}
22+ {{ dropdownBased ? "API Key" : '' }}
2223 </template >
2324 <template #helper >
2425 Get your <ExternalLink href =" https://console.anthropic.com/settings/keys" >API Key here.</ExternalLink >
2526 </template >
2627 </BaseInput >
27- <BaseInput
28- type =" password"
29- placeholder =" AIzaSy..."
30- v-model =" googleApiKey"
31- >
28+ <BaseInput v-if =" !dropdownBased || selectedProvider.value === 'google'" type =" password" placeholder =" AIzaSy..."
29+ v-model =" googleApiKey" >
3230 <template #label >
3331 {{ providerConfigs["google"].displayName }}
32+ {{ dropdownBased ? "API Key" : '' }}
3433 </template >
3534 <template #helper >
3635 Get your <ExternalLink href =" https://aistudio.google.com/app/apikey" >API Key here.</ExternalLink >
3736 </template >
3837 </BaseInput >
38+ <template v-if =" selectedProvider .value === ' openaiCompat' " >
39+ <BaseInput v-model =" openaiCompatApiKey" >
40+ <template #label >OpenAI Compatible API Key</template >
41+ </BaseInput >
42+ <BaseInput v-model =" openaiCompatBaseUrl" >
43+ <template #label >Base URL</template >
44+ </BaseInput >
45+ <BaseInput v-model =" openaiCompatHeaders" type =" textarea" >
46+ <template #label >Custom Headers</template >
47+ </BaseInput >
48+ </template >
49+ <template v-if =" selectedProvider .value === ' ollama' " >
50+ <BaseInput v-model =" ollamaBaseUrl" >
51+ <template #label >Ollama Base URL</template >
52+ </BaseInput >
53+ <BaseInput v-model =" ollamaHeaders" type =" textarea" >
54+ <template #label >Custom Headers</template >
55+ </BaseInput >
56+ </template >
3957 </div >
4058</template >
4159
4260<script lang="ts">
43- import { mapState , mapActions } from " pinia" ;
61+ import { mapActions } from " pinia" ;
4462import { useConfigurationStore } from " @/stores/configuration" ;
45- import { providerConfigs } from " @/config" ;
63+ import { AvailableProviders , providerConfigs } from " @/config" ;
4664import BaseInput from " ./common/BaseInput.vue" ;
4765import ExternalLink from " ./common/ExternalLink.vue" ;
66+ import Select from ' primevue/select' ;
4867
4968export default {
5069 name: " ApiKeyForm" ,
5170
5271 components: {
5372 BaseInput ,
5473 ExternalLink ,
74+ Select ,
5575 },
5676
57- emits: [" change" ],
77+ emits: [" change" , " changeProvider" ],
78+
79+ props: {
80+ dropdownBased: Boolean ,
81+ },
5882
5983 data() {
84+ const config = useConfigurationStore ();
85+
6086 return {
61- openaiApiKey: " " ,
62- anthropicApiKey: " " ,
63- googleApiKey: " " ,
87+ selectedProvider: {
88+ label: " " as typeof providerConfigs [AvailableProviders ][' displayName' ],
89+ value: " " as AvailableProviders ,
90+ },
91+ openaiApiKey: config [' providers.openai.apiKey' ],
92+ anthropicApiKey: config [' providers.anthropic.apiKey' ],
93+ googleApiKey: config [' providers.google.apiKey' ],
94+ ollamaBaseUrl: config .providers_ollama_baseUrl ,
95+ ollamaHeaders: config .providers_ollama_headers ,
96+ openaiCompatBaseUrl: config .providers_openaiCompat_baseUrl ,
97+ openaiCompatApiKey: config .providers_openaiCompat_apiKey ,
98+ openaiCompatHeaders: config .providers_openaiCompat_headers ,
6499 };
65100 },
66101
67102 computed: {
68- ... mapState (useConfigurationStore , [
69- " providers.openai.apiKey" ,
70- " providers.anthropic.apiKey" ,
71- " providers.google.apiKey" ,
72- ]),
73103 providerConfigs() {
74104 return providerConfigs ;
75105 },
106+ dropdownOptions() {
107+ return Object .keys (providerConfigs ).map ((provider ) => ({
108+ label: this .providerConfigs [provider ].displayName ,
109+ value: provider ,
110+ }));
111+ },
76112 },
77113
78114 watch: {
@@ -88,16 +124,46 @@ export default {
88124 this .configure (" providers.google.apiKey" , this .googleApiKey );
89125 this .$emit (" change" );
90126 },
127+ ollamaBaseUrl() {
128+ this .configure (" providers_ollama_baseUrl" , this .ollamaBaseUrl );
129+ this .$emit (" change" );
130+ },
131+ ollamaHeaders() {
132+ this .configure (" providers_ollama_headers" , this .ollamaHeaders );
133+ this .$emit (" change" );
134+ },
135+ openaiCompatBaseUrl() {
136+ this .configure (" providers_openaiCompat_baseUrl" , this .openaiCompatBaseUrl );
137+ this .$emit (" change" );
138+ },
139+ openaiCompatApiKey() {
140+ this .configure (" providers_openaiCompat_apiKey" , this .openaiCompatApiKey );
141+ this .$emit (" change" );
142+ },
143+ openaiCompatHeaders() {
144+ this .configure (" providers_openaiCompat_headers" , this .openaiCompatHeaders );
145+ this .$emit (" change" );
146+ },
147+ selectedProvider() {
148+ this .$emit (" changeProvider" , this .selectedProvider .value );
149+ },
91150 },
92151
93152 methods: {
94153 ... mapActions (useConfigurationStore , [" configure" ]),
95154 },
96-
97- mounted() {
98- this .openaiApiKey = this [" providers.openai.apiKey" ];
99- this .anthropicApiKey = this [" providers.anthropic.apiKey" ];
100- this .googleApiKey = this [" providers.google.apiKey" ];
101- },
102155};
103156 </script >
157+
158+ <style scoped>
159+ .input-container {
160+ display : flex ;
161+ flex-direction : column ;
162+ gap : 0.5rem ;
163+ justify-content : flex-start ;
164+
165+ label {
166+ align-self : flex-start ;
167+ }
168+ }
169+ </style >
0 commit comments