From 00161935780ce10566ad66636c00cf9efc1eabfe Mon Sep 17 00:00:00 2001 From: nang-dev Date: Thu, 6 Mar 2025 15:03:41 -0500 Subject: [PATCH 1/3] At least the connection is working --- src/core/webview/ClineProvider.ts | 2 +- src/shared/api.ts | 87 ++++++++++++++----------------- 2 files changed, 41 insertions(+), 48 deletions(-) diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 6164595e689..3d5ea79762c 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -423,7 +423,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { `style-src ${webview.cspSource} 'unsafe-inline' https://* http://${localServerUrl} http://0.0.0.0:${localPort}`, `img-src ${webview.cspSource} data:`, `script-src 'unsafe-eval' https://* http://${localServerUrl} http://0.0.0.0:${localPort} 'nonce-${nonce}'`, - `connect-src https://* ws://${localServerUrl} ws://0.0.0.0:${localPort} http://${localServerUrl} http://0.0.0.0:${localPort}`, + `connect-src https://* ws://${localServerUrl} ws://0.0.0.0:${localPort} http://${localServerUrl} http://0.0.0.0:${localPort} http://localhost:8000 http://0.0.0.0:8000`, ] return /*html*/ ` diff --git a/src/shared/api.ts b/src/shared/api.ts index c01179ace74..8e482cbeb5b 100644 --- a/src/shared/api.ts +++ b/src/shared/api.ts @@ -792,14 +792,27 @@ export const unboundDefaultModelInfo: ModelInfo = { } // CHANGE AS NEEDED FOR TESTING // PROD: -export const PEARAI_URL = "https://stingray-app-gb2an.ondigitalocean.app/pearai-server-api2/integrations/cline" +// export const PEARAI_URL = "https://stingray-app-gb2an.ondigitalocean.app/pearai-server-api2/integrations/cline" // DEV: -// export const PEARAI_URL = "http://localhost:8000/integrations/cline" +export const PEARAI_URL = "http://localhost:8000/integrations/cline" // PearAI export type PearAiModelId = keyof typeof pearAiModels export const pearAiDefaultModelId: PearAiModelId = "pearai-model" -export const pearAiModels = { +export const pearAiDefaultModelInfo: ModelInfo = { + maxTokens: 8192, + contextWindow: 64000, + supportsImages: false, + supportsPromptCache: true, + inputPrice: 0.014, + outputPrice: 0.28, + cacheWritesPrice: 0.27, + cacheReadsPrice: 0.07, + description: + "DeepSeek-V3 achieves a significant breakthrough in inference speed over previous models. It tops the leaderboard among open-source models and rivals the most advanced closed-source models globally.", +} + +export let pearAiModels = { "pearai-model": { maxTokens: 8192, contextWindow: 64000, @@ -812,48 +825,28 @@ export const pearAiModels = { description: "DeepSeek-V3 achieves a significant breakthrough in inference speed over previous models. It tops the leaderboard among open-source models and rivals the most advanced closed-source models globally.", }, - "claude-3-5-sonnet-20241022": { - maxTokens: 8192, - contextWindow: 200000, - supportsImages: true, - supportsComputerUse: true, - supportsPromptCache: true, - inputPrice: 3.0, - outputPrice: 15.0, - cacheWritesPrice: 3.75, - cacheReadsPrice: 0.3, - }, - "claude-3-5-haiku-20241022": { - maxTokens: 8192, - contextWindow: 200000, - supportsImages: false, - supportsPromptCache: true, - inputPrice: 1.0, - outputPrice: 5.0, - cacheWritesPrice: 1.25, - cacheReadsPrice: 0.1, - }, - "deepseek-chat": { - maxTokens: 8192, - contextWindow: 64000, - supportsImages: false, - supportsPromptCache: true, - inputPrice: 0.014, - outputPrice: 0.28, - cacheWritesPrice: 0.27, - cacheReadsPrice: 0.07, - description: - "DeepSeek-V3 achieves a significant breakthrough in inference speed over previous models. It tops the leaderboard among open-source models and rivals the most advanced closed-source models globally.", - }, - "deepseek-reasoner": { - maxTokens: 8192, - contextWindow: 64000, - supportsImages: false, - supportsPromptCache: true, - inputPrice: 0.55, - outputPrice: 2.19, - cacheWritesPrice: 0.55, - cacheReadsPrice: 0.14, - description: "DeepSeek-R1 achieves performance comparable to OpenAI-o1 across math, code, and reasoning tasks.", - }, } as const satisfies Record + +// Initialize models with a Promise +export let modelsInitialized: Promise> + +modelsInitialized = (async () => { + try { + const res = await fetch(`${PEARAI_URL}/getPearAIAgentModels`) + if (!res.ok) throw new Error("Failed to fetch models") + const config = await res.json() + + if (config.models && Object.keys(config.models).length > 0) { + console.log("Models successfully loaded from server") + console.dir(config.models) + pearAiModels = config.models + return config.models + } else { + console.log("Using default models (no models returned from server)") + return { [pearAiDefaultModelId]: pearAiDefaultModelInfo } + } + } catch (error) { + console.error("Error fetching PearAI models:", error) + return { [pearAiDefaultModelId]: pearAiDefaultModelInfo } + } +})() From deedf9ee8704ff0c6e81555f7cd5e872ff8e8fdd Mon Sep 17 00:00:00 2001 From: nang-dev Date: Thu, 6 Mar 2025 15:13:46 -0500 Subject: [PATCH 2/3] Added working --- src/shared/api.ts | 30 +------ .../src/components/settings/ApiOptions.tsx | 78 +++++++++++++++---- 2 files changed, 64 insertions(+), 44 deletions(-) diff --git a/src/shared/api.ts b/src/shared/api.ts index 8e482cbeb5b..0b6433a03fa 100644 --- a/src/shared/api.ts +++ b/src/shared/api.ts @@ -792,9 +792,9 @@ export const unboundDefaultModelInfo: ModelInfo = { } // CHANGE AS NEEDED FOR TESTING // PROD: -// export const PEARAI_URL = "https://stingray-app-gb2an.ondigitalocean.app/pearai-server-api2/integrations/cline" +export const PEARAI_URL = "https://stingray-app-gb2an.ondigitalocean.app/pearai-server-api2/integrations/cline" // DEV: -export const PEARAI_URL = "http://localhost:8000/integrations/cline" +// export const PEARAI_URL = "http://localhost:8000/integrations/cline" // PearAI export type PearAiModelId = keyof typeof pearAiModels @@ -812,7 +812,7 @@ export const pearAiDefaultModelInfo: ModelInfo = { "DeepSeek-V3 achieves a significant breakthrough in inference speed over previous models. It tops the leaderboard among open-source models and rivals the most advanced closed-source models globally.", } -export let pearAiModels = { +export const pearAiModels = { "pearai-model": { maxTokens: 8192, contextWindow: 64000, @@ -826,27 +826,3 @@ export let pearAiModels = { "DeepSeek-V3 achieves a significant breakthrough in inference speed over previous models. It tops the leaderboard among open-source models and rivals the most advanced closed-source models globally.", }, } as const satisfies Record - -// Initialize models with a Promise -export let modelsInitialized: Promise> - -modelsInitialized = (async () => { - try { - const res = await fetch(`${PEARAI_URL}/getPearAIAgentModels`) - if (!res.ok) throw new Error("Failed to fetch models") - const config = await res.json() - - if (config.models && Object.keys(config.models).length > 0) { - console.log("Models successfully loaded from server") - console.dir(config.models) - pearAiModels = config.models - return config.models - } else { - console.log("Using default models (no models returned from server)") - return { [pearAiDefaultModelId]: pearAiDefaultModelInfo } - } - } catch (error) { - console.error("Error fetching PearAI models:", error) - return { [pearAiDefaultModelId]: pearAiDefaultModelInfo } - } -})() diff --git a/webview-ui/src/components/settings/ApiOptions.tsx b/webview-ui/src/components/settings/ApiOptions.tsx index ca5c7f95299..dd644bdf871 100644 --- a/webview-ui/src/components/settings/ApiOptions.tsx +++ b/webview-ui/src/components/settings/ApiOptions.tsx @@ -1,4 +1,4 @@ -import { Fragment, memo, useCallback, useEffect, useMemo, useState } from "react" +import { Fragment, memo, useCallback, useEffect, useMemo, useState, useRef } from "react" import { useEvent, useDebounce, useInterval } from "react-use" import { Checkbox, Dropdown, Pane, type DropdownOption } from "vscrui" import { @@ -40,6 +40,8 @@ import { requestyDefaultModelInfo, pearAiModels, pearAiDefaultModelId, + pearAiDefaultModelInfo, + PEARAI_URL, } from "../../../../src/shared/api" import { ExtensionMessage } from "../../../../src/shared/ExtensionMessage" @@ -52,17 +54,6 @@ import { validateApiConfiguration, validateModelId } from "@/utils/validate" import { ApiErrorMessage } from "./ApiErrorMessage" import { ThinkingBudget } from "./ThinkingBudget" -const modelsByProvider: Record> = { - anthropic: anthropicModels, - bedrock: bedrockModels, - vertex: vertexModels, - gemini: geminiModels, - "openai-native": openAiNativeModels, - deepseek: deepSeekModels, - mistral: mistralModels, - pearai: pearAiModels, -} - interface ApiOptionsProps { uriScheme: string | undefined apiConfiguration: ApiConfiguration @@ -101,6 +92,9 @@ const ApiOptions = ({ }) const [openAiModels, setOpenAiModels] = useState | null>(null) + const [pearAiModels, setPearAiModels] = useState>({ + [pearAiDefaultModelId]: pearAiDefaultModelInfo, + }) const [anthropicBaseUrlSelected, setAnthropicBaseUrlSelected] = useState(!!apiConfiguration?.anthropicBaseUrl) const [azureApiVersionSelected, setAzureApiVersionSelected] = useState(!!apiConfiguration?.azureApiVersion) @@ -123,10 +117,16 @@ const ApiOptions = ({ [setApiConfigurationField], ) - const { selectedProvider, selectedModelId, selectedModelInfo } = useMemo( - () => normalizeApiConfiguration(apiConfiguration), - [apiConfiguration], - ) + const { selectedProvider, selectedModelId, selectedModelInfo } = useMemo(() => { + const result = normalizeApiConfiguration(apiConfiguration) + if (result.selectedProvider === "pearai") { + return { + ...result, + selectedModelInfo: pearAiModels[result.selectedModelId] || pearAiModels[pearAiDefaultModelId], + } + } + return result + }, [apiConfiguration, pearAiModels]) // Debounced refresh model updates, only executed 250ms after the user // stops typing. @@ -167,6 +167,28 @@ const ApiOptions = ({ ], ) + // Fetch PearAI models when provider is selected + useEffect(() => { + if (selectedProvider === "pearai") { + const fetchPearAiModels = async () => { + try { + const res = await fetch(`${PEARAI_URL}/getPearAIAgentModels`) + if (!res.ok) throw new Error("Failed to fetch models") + const config = await res.json() + + if (config.models && Object.keys(config.models).length > 0) { + console.log("Models successfully loaded from server") + setPearAiModels(config.models) + } + } catch (error) { + console.error("Error fetching PearAI models:", error) + } + } + + fetchPearAiModels() + } + }, [selectedProvider, setPearAiModels]) + useEffect(() => { const apiValidationResult = validateApiConfiguration(apiConfiguration) || @@ -227,6 +249,28 @@ const ApiOptions = ({ useEvent("message", onMessage) + const modelsByProvider = useMemo( + () => ({ + anthropic: anthropicModels, + bedrock: bedrockModels, + vertex: vertexModels, + gemini: geminiModels, + "openai-native": openAiNativeModels, + deepseek: deepSeekModels, + mistral: mistralModels, + pearai: pearAiModels, + glama: glamaModels, + openrouter: openRouterModels, + unbound: unboundModels, + requesty: requestyModels, + openai: openAiModels || {}, + ollama: {}, + lmstudio: {}, + "vscode-lm": {}, + }), + [pearAiModels, glamaModels, openRouterModels, unboundModels, requestyModels, openAiModels], + ) + const selectedProviderModelOptions: DropdownOption[] = useMemo( () => modelsByProvider[selectedProvider] @@ -238,7 +282,7 @@ const ApiOptions = ({ })), ] : [], - [selectedProvider], + [selectedProvider, modelsByProvider], ) return ( From 92e3de44728f161b8d662e7413d608c317a3a96a Mon Sep 17 00:00:00 2001 From: nang-dev Date: Thu, 6 Mar 2025 16:07:29 -0500 Subject: [PATCH 3/3] Added connection allow --- src/core/webview/ClineProvider.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 3d5ea79762c..4f97d3771ad 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -423,7 +423,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { `style-src ${webview.cspSource} 'unsafe-inline' https://* http://${localServerUrl} http://0.0.0.0:${localPort}`, `img-src ${webview.cspSource} data:`, `script-src 'unsafe-eval' https://* http://${localServerUrl} http://0.0.0.0:${localPort} 'nonce-${nonce}'`, - `connect-src https://* ws://${localServerUrl} ws://0.0.0.0:${localPort} http://${localServerUrl} http://0.0.0.0:${localPort} http://localhost:8000 http://0.0.0.0:8000`, + `connect-src https://* ws://${localServerUrl} ws://0.0.0.0:${localPort} http://${localServerUrl} http://0.0.0.0:${localPort} http://localhost:8000 http://0.0.0.0:8000 https://stingray-app-gb2an.ondigitalocean.app`, ] return /*html*/ ` @@ -507,7 +507,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { - + Roo Code