11import { Checkbox , Dropdown , Pane } from "vscrui"
22import type { DropdownOption } from "vscrui"
3- import { VSCodeLink , VSCodeRadio , VSCodeRadioGroup , VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
3+ import {
4+ VSCodeButton ,
5+ VSCodeLink ,
6+ VSCodeRadio ,
7+ VSCodeRadioGroup ,
8+ VSCodeTextField ,
9+ } from "@vscode/webview-ui-toolkit/react"
410import { Fragment , memo , useCallback , useEffect , useMemo , useState } from "react"
511import { useEvent , useInterval } from "react-use"
612import {
@@ -39,6 +45,8 @@ import OpenRouterModelPicker, {
3945import OpenAiModelPicker from "./OpenAiModelPicker"
4046import GlamaModelPicker from "./GlamaModelPicker"
4147
48+ const PEARAI_DEFAULT_URL = "https://stingray-app-gb2an.ondigitalocean.app/pearai-server-api2/integrations/cline"
49+
4250interface ApiOptionsProps {
4351 apiErrorMessage ?: string
4452 modelIdErrorMessage ?: string
@@ -52,6 +60,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
5260 const [ anthropicBaseUrlSelected , setAnthropicBaseUrlSelected ] = useState ( ! ! apiConfiguration ?. anthropicBaseUrl )
5361 const [ azureApiVersionSelected , setAzureApiVersionSelected ] = useState ( ! ! apiConfiguration ?. azureApiVersion )
5462 const [ openRouterBaseUrlSelected , setOpenRouterBaseUrlSelected ] = useState ( ! ! apiConfiguration ?. openRouterBaseUrl )
63+ const [ pearaiBaseUrlSelected , setPearaiBaseUrlSelected ] = useState ( ! ! apiConfiguration ?. pearaiBaseUrl )
5564 const [ isDescriptionExpanded , setIsDescriptionExpanded ] = useState ( false )
5665
5766 const { selectedProvider, selectedModelId, selectedModelInfo } = useMemo ( ( ) => {
@@ -134,6 +143,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
134143 } }
135144 style = { { minWidth : 130 , position : "relative" , zIndex : OPENROUTER_MODEL_PICKER_Z_INDEX + 1 } }
136145 options = { [
146+ { value : "pearai" , label : "PearAI" } ,
137147 { value : "openrouter" , label : "OpenRouter" } ,
138148 { value : "anthropic" , label : "Anthropic" } ,
139149 { value : "gemini" , label : "Google Gemini" } ,
@@ -151,6 +161,47 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
151161 />
152162 </ div >
153163
164+ { selectedProvider === "pearai" && (
165+ < div >
166+ < VSCodeTextField
167+ value = { apiConfiguration ?. pearaiApiKey || "" }
168+ style = { { width : "100%" } }
169+ type = "password"
170+ onInput = { handleInputChange ( "pearaiApiKey" ) }
171+ placeholder = "Enter API Key..." >
172+ < span style = { { fontWeight : 500 } } > PearAI API Key</ span >
173+ </ VSCodeTextField >
174+ < VSCodeTextField
175+ value = { apiConfiguration ?. pearaiBaseUrl || PEARAI_DEFAULT_URL }
176+ style = { { width : "100%" } }
177+ type = "url"
178+ onInput = { handleInputChange ( "pearaiBaseUrl" ) }
179+ placeholder = { PEARAI_DEFAULT_URL } >
180+ < span style = { { fontWeight : 500 } } > Base URL</ span >
181+ </ VSCodeTextField >
182+ { apiConfiguration ?. pearaiBaseUrl && apiConfiguration . pearaiBaseUrl !== PEARAI_DEFAULT_URL && (
183+ < VSCodeButton
184+ onClick = { ( ) => {
185+ handleInputChange ( "pearaiBaseUrl" ) ( {
186+ target : {
187+ value : PEARAI_DEFAULT_URL ,
188+ } ,
189+ } )
190+ } } >
191+ Reset to default URL
192+ </ VSCodeButton >
193+ ) }
194+ < p
195+ style = { {
196+ fontSize : "12px" ,
197+ marginTop : "5px" ,
198+ color : "var(--vscode-descriptionForeground)" ,
199+ } } >
200+ This key is stored locally and only used to make API requests from this extension.
201+ </ p >
202+ </ div >
203+ ) }
204+
154205 { selectedProvider === "anthropic" && (
155206 < div >
156207 < VSCodeTextField
@@ -1302,7 +1353,8 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
13021353 selectedProvider !== "openrouter" &&
13031354 selectedProvider !== "openai" &&
13041355 selectedProvider !== "ollama" &&
1305- selectedProvider !== "lmstudio" && (
1356+ selectedProvider !== "lmstudio" &&
1357+ selectedProvider !== "pearai" && (
13061358 < >
13071359 < div className = "dropdown-container" >
13081360 < label htmlFor = "model-id" >
@@ -1552,6 +1604,12 @@ export function normalizeApiConfiguration(apiConfiguration?: ApiConfiguration) {
15521604 supportsImages : false , // VSCode LM API currently doesn't support images
15531605 } ,
15541606 }
1607+ case "pearai" :
1608+ return {
1609+ selectedProvider : provider ,
1610+ selectedModelId : apiConfiguration ?. pearaiModelId || "" ,
1611+ selectedModelInfo : apiConfiguration ?. pearaiModelInfo || openAiModelInfoSaneDefaults ,
1612+ }
15551613 default :
15561614 return getProviderData ( anthropicModels , anthropicDefaultModelId )
15571615 }
0 commit comments