* Refactor services architecture with provider pattern and factory classes - Extract telemetry, error handling, and feature flags into separate service modules - Implement provider pattern with factory classes for better abstraction - Move PostHog-specific implementations to dedicated provider classes - Add interfaces for telemetry, error, and feature flags providers - Update imports across codebase to use new service structure - Add unit tests for telemetry service * Refactor service providers and centralize distinct ID management - Move provider interfaces to dedicated providers/ subdirectories - Extract distinct ID management to shared logging/distinctId module - Simplify PostHogClientProvider by removing distinct ID parameter - Update service factories to use centralized distinct ID - Reorganize test files to __tests__/ directories - Remove redundant distinct ID handling across services * merge main * clean up * add grok coder free model to cline provider (#5808) * add free grok-coder-free model to cline provider * add changeset * fix typo * v3.26.6 Release Notes (#5788) * changeset version bump * Updating CHANGELOG.md format * Update CHANGELOG.md for version 3.26.6 with user-friendly descriptions --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: pashpashpash <nik@cline.bot> * Remove top padding from ActionButtons component (#5806) Eliminate unnecessary top padding in the chat view. * removing middle out from params to or / cline providers (#5811) * Dify.ai integration (#5761) * add focus chain settings to statemanager initialize function (#5798) * add custom gpt-5 system prompt (#5757) * gpt-5 system prompt * add changeset * Focus chain telemetry tweaks (#5810) Co-authored-by: Kevin Bond <kevin@Kevins-MacBook-Pro.local> * Remove eslint-rules test patterns from Mocha spec configuration (#5812) Update the "spec" array in .mocharc.json to exclude "eslint-rules/__tests__/**/*.test.ts", as that directory has been removed. * Increase horizontal margin in AutoApproveBar component (#5813) Update the mx-[5px] to mx-[15px] in the div's className to adjust horizontal spacing for improved layout alignment. * fix: remove hardcoded Ollama host from options (#5816) * fix: remove hardcoded Ollama host from options Updates the Ollama handler to remove the hardcoded "http://localhost:11434" as the `ollamaBaseUrl` fallback option for the host to allow the Ollama SDK to handle the default endpoint configured on users' machine. Reason: Ollama allows cross-origin requests from 127.0.0.1 and 0.0.0.0 by default. However, when we use localhost, the browser would resolve it through DNS, which can result in different IP addresses. Docs: https://github.com/ollama/ollama/blob/main/docs/faq.md#how-can-i-expose-ollama-on-my-network * add changeset * deep-planning prompt PowerShell (#5699) * Windows/Powershell specific deep planning prompt changes * Prompt adjustments --------- Co-authored-by: Kevin Bond <kevin@Kevins-MacBook-Pro.local> * Changes to condenseToolResponse & summarizeTask prompting (#5817) * Condense & deep planning prompt adjustments * Removed ps prompting ready for PR * rebase * Fixed typo on one word --------- Co-authored-by: Kevin Bond <kevin@Kevins-MacBook-Pro.local> * rename CacheService to StateManager (#5681) * rename CacheService to StateManager * fix types * infer state key types from existing interfaces (#5815) * fix: AutoApproveModal positioning and scrolling behavior (#5819) * fix: AutoApproveModal positioning and scrolling behavior - Add dynamic positioning calculation to prevent modal overflow - Implement proper flex layout with scrollable content container - Ensure minimum usable height and top margin constraints - Fix modal positioning when button is near viewport edges * Add changeset * clean up * template-based system prompt (#5731) * Refactor system prompt architecture with new template-based system - Move existing system prompt files to legacy directory - Implement new modular system with PromptBuilder, PromptRegistry, and TemplateEngine - Add component-based prompt structure with reusable parts (capabilities, rules, tool_use, etc.) - Create variant-specific templates for generic and next-gen models - Add comprehensive test suite with snapshots for different model configurations - Introduce template engine with placeholder support for dynamic prompt generation * Refactor system prompt architecture with modular tool definitions - Extract tool specifications into dedicated modules under tools/ - Add ClineToolSet class for managing tool variants by model family - Restructure prompt components with centralized index exports - Update prompt builder and registry to support new tool architecture - Reorganize shared utilities and type definitions - Update all test snapshots to reflect new prompt structure * Update snapshots * reorg * Update template format * clean up * typos * focus chain section * fix task progress in attempt_completion * Implement tool retrieval with fallback options in PromptBuilder - Added `getToolByNameWithFallback` and `getToolsForVariantWithFallback` methods to `ClineToolSet` for improved tool resolution. - Updated `getToolsPrompts` in `PromptBuilder` to utilize these new methods, allowing for better handling of tool requests with fallback to generic tools. - Enhanced sorting and filtering of tools based on context requirements and requested order. * update fild structure * clean up * fix static test string * Update snapshot names * Update unit test * Remove unused placeholders and update docs * Update README on how to add new tool * Remove task_progress reference from attempt_completion tool description when focus chain is disabled * Upgrade posthog-node to v5.8.0 and add exception filtering - Update posthog-node from v4.8.1 to v5.8.0 - Add EventMessage import for type safety - Implement posthogEventFilter to only capture exceptions from Cline extension - Filter exceptions by checking for "cline" in error messages or "saoudrizwan" in stack frames * Use env var keys - Add PostHogClientConfig to ErrorProviderFactory with proper validation - Update PostHogErrorProvider to use dedicated client instead of shared one - Add API key validation in PostHogFeatureFlagsProvider before client creation - Enhance error handling with fallback to NoOpErrorProvider instead of throwing - Standardize configuration passing across telemetry, error, and feature flag services * Upadte filter * update filter * update imports * use secret * disable enableExceptionAutocapture * removes vscode.env.machineId * initializeDistinctId * use get trap as workaround * on exit --------- Co-authored-by: pashpashpash <nik@cline.bot> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Toshii <94262432+0xToshii@users.noreply.github.com> Co-authored-by: Yunus Emre AYHAN <ayhanyunusemre@gmail.com> Co-authored-by: celestial-vault <58194240+celestial-vault@users.noreply.github.com> Co-authored-by: canvrno <46584286+canvrno@users.noreply.github.com> Co-authored-by: Kevin Bond <kevin@Kevins-MacBook-Pro.local>
250 lines
11 KiB
TypeScript
250 lines
11 KiB
TypeScript
import { McpMarketplaceCatalog } from "@shared/mcp"
|
|
import { Empty, EmptyRequest } from "@shared/proto/cline/common"
|
|
import { OpenRouterCompatibleModelInfo } from "@shared/proto/cline/models"
|
|
import { featureFlagsService } from "@/services/feature-flags"
|
|
import { telemetryService } from "@/services/telemetry"
|
|
import type { Controller } from "../index"
|
|
import { sendMcpMarketplaceCatalogEvent } from "../mcp/subscribeToMcpMarketplaceCatalog"
|
|
import { refreshBasetenModels } from "../models/refreshBasetenModels"
|
|
import { refreshGroqModels } from "../models/refreshGroqModels"
|
|
import { refreshOpenRouterModels } from "../models/refreshOpenRouterModels"
|
|
import { refreshVercelAiGatewayModels } from "../models/refreshVercelAiGatewayModels"
|
|
import { sendOpenRouterModelsEvent } from "../models/subscribeToOpenRouterModels"
|
|
|
|
/**
|
|
* Initialize webview when it launches
|
|
* @param controller The controller instance
|
|
* @param request The empty request
|
|
* @returns Empty response
|
|
*/
|
|
export async function initializeWebview(controller: Controller, _request: EmptyRequest): Promise<Empty> {
|
|
try {
|
|
// Post last cached models in case the call to endpoint fails
|
|
controller.readOpenRouterModels().then((openRouterModels) => {
|
|
if (openRouterModels) {
|
|
sendOpenRouterModelsEvent(OpenRouterCompatibleModelInfo.create({ models: openRouterModels }))
|
|
}
|
|
})
|
|
|
|
// Refresh OpenRouter models from API
|
|
refreshOpenRouterModels(controller, EmptyRequest.create()).then(async (response) => {
|
|
if (response && response.models) {
|
|
// Update model info in state (this needs to be done here since we don't want to update state while settings is open, and we may refresh models there)
|
|
const apiConfiguration = controller.stateManager.getApiConfiguration()
|
|
const planActSeparateModelsSetting = controller.stateManager.getGlobalStateKey("planActSeparateModelsSetting")
|
|
const currentMode = await controller.getCurrentMode()
|
|
|
|
if (planActSeparateModelsSetting) {
|
|
// Separate models: update only current mode
|
|
const modelIdField = currentMode === "plan" ? "planModeOpenRouterModelId" : "actModeOpenRouterModelId"
|
|
const modelInfoField = currentMode === "plan" ? "planModeOpenRouterModelInfo" : "actModeOpenRouterModelInfo"
|
|
const modelId = apiConfiguration[modelIdField]
|
|
|
|
if (modelId && response.models[modelId]) {
|
|
const updatedConfig = {
|
|
...apiConfiguration,
|
|
[modelInfoField]: response.models[modelId],
|
|
}
|
|
controller.stateManager.setApiConfiguration(updatedConfig)
|
|
await controller.postStateToWebview()
|
|
}
|
|
} else {
|
|
// Shared models: update both plan and act modes
|
|
const planModelId = apiConfiguration.planModeOpenRouterModelId
|
|
const actModelId = apiConfiguration.actModeOpenRouterModelId
|
|
const updatedConfig = { ...apiConfiguration }
|
|
|
|
// Update plan mode model info if we have a model ID
|
|
if (planModelId && response.models[planModelId]) {
|
|
updatedConfig.planModeOpenRouterModelInfo = response.models[planModelId]
|
|
}
|
|
|
|
// Update act mode model info if we have a model ID
|
|
if (actModelId && response.models[actModelId]) {
|
|
updatedConfig.actModeOpenRouterModelInfo = response.models[actModelId]
|
|
}
|
|
|
|
// Post state update if we updated any model info
|
|
if ((planModelId && response.models[planModelId]) || (actModelId && response.models[actModelId])) {
|
|
controller.stateManager.setApiConfiguration(updatedConfig)
|
|
await controller.postStateToWebview()
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
refreshGroqModels(controller, EmptyRequest.create()).then(async (response) => {
|
|
if (response && response.models) {
|
|
// Update model info in state for Groq (this needs to be done here since we don't want to update state while settings is open, and we may refresh models there)
|
|
const apiConfiguration = controller.stateManager.getApiConfiguration()
|
|
const planActSeparateModelsSetting = controller.stateManager.getGlobalStateKey("planActSeparateModelsSetting")
|
|
const currentMode = await controller.getCurrentMode()
|
|
|
|
if (planActSeparateModelsSetting) {
|
|
// Separate models: update only current mode
|
|
const modelIdField = currentMode === "plan" ? "planModeGroqModelId" : "actModeGroqModelId"
|
|
const modelInfoField = currentMode === "plan" ? "planModeGroqModelInfo" : "actModeGroqModelInfo"
|
|
const modelId = apiConfiguration[modelIdField]
|
|
|
|
if (modelId && response.models[modelId]) {
|
|
const updatedConfig = {
|
|
...apiConfiguration,
|
|
[modelInfoField]: response.models[modelId],
|
|
}
|
|
controller.stateManager.setApiConfiguration(updatedConfig)
|
|
await controller.postStateToWebview()
|
|
}
|
|
} else {
|
|
// Shared models: update both plan and act modes
|
|
const planModelId = apiConfiguration.planModeGroqModelId
|
|
const actModelId = apiConfiguration.actModeGroqModelId
|
|
const updatedConfig = { ...apiConfiguration }
|
|
|
|
// Update plan mode model info if we have a model ID
|
|
if (planModelId && response.models[planModelId]) {
|
|
updatedConfig.planModeGroqModelInfo = response.models[planModelId]
|
|
}
|
|
|
|
// Update act mode model info if we have a model ID
|
|
if (actModelId && response.models[actModelId]) {
|
|
updatedConfig.actModeGroqModelInfo = response.models[actModelId]
|
|
}
|
|
|
|
// Post state update if we updated any model info
|
|
if ((planModelId && response.models[planModelId]) || (actModelId && response.models[actModelId])) {
|
|
controller.stateManager.setApiConfiguration(updatedConfig)
|
|
await controller.postStateToWebview()
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
refreshBasetenModels(controller, EmptyRequest.create()).then(async (response) => {
|
|
if (response && response.models) {
|
|
// Update model info in state for Baseten (this needs to be done here since we don't want to update state while settings is open, and we may refresh models there)
|
|
const apiConfiguration = controller.stateManager.getApiConfiguration()
|
|
const planActSeparateModelsSetting = controller.stateManager.getGlobalStateKey("planActSeparateModelsSetting")
|
|
|
|
const currentMode = await controller.getCurrentMode()
|
|
|
|
if (planActSeparateModelsSetting) {
|
|
// Separate models: update only current mode
|
|
const modelIdField = currentMode === "plan" ? "planModeBasetenModelId" : "actModeBasetenModelId"
|
|
const modelInfoField = currentMode === "plan" ? "planModeBasetenModelInfo" : "actModeBasetenModelInfo"
|
|
const modelId = apiConfiguration[modelIdField]
|
|
|
|
if (modelId && response.models[modelId]) {
|
|
controller.stateManager.setGlobalState(modelInfoField, response.models[modelId])
|
|
await controller.postStateToWebview()
|
|
}
|
|
} else {
|
|
// Shared models: update both plan and act modes
|
|
const planModelId = apiConfiguration.planModeBasetenModelId
|
|
const actModelId = apiConfiguration.actModeBasetenModelId
|
|
|
|
// Update plan mode model info if we have a model ID
|
|
if (planModelId && response.models[planModelId]) {
|
|
controller.stateManager.setGlobalState("planModeBasetenModelInfo", response.models[planModelId])
|
|
}
|
|
|
|
// Update act mode model info if we have a model ID
|
|
if (actModelId && response.models[actModelId]) {
|
|
controller.stateManager.setGlobalState("actModeBasetenModelInfo", response.models[actModelId])
|
|
}
|
|
|
|
// Post state update if we updated any model info
|
|
if ((planModelId && response.models[planModelId]) || (actModelId && response.models[actModelId])) {
|
|
await controller.postStateToWebview()
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
// Refresh Vercel AI Gateway models from API
|
|
refreshVercelAiGatewayModels(controller, EmptyRequest.create()).then(async (response) => {
|
|
if (response && response.models) {
|
|
// Update model info in state for Vercel AI Gateway (this needs to be done here since we don't want to update state while settings is open, and we may refresh models there)
|
|
const apiConfiguration = controller.stateManager.getApiConfiguration()
|
|
const planActSeparateModelsSetting = controller.stateManager.getGlobalStateKey("planActSeparateModelsSetting")
|
|
const currentMode = await controller.getCurrentMode()
|
|
|
|
if (planActSeparateModelsSetting) {
|
|
// Separate models: update only current mode
|
|
const modelIdField =
|
|
currentMode === "plan" ? "planModeVercelAiGatewayModelId" : "actModeVercelAiGatewayModelId"
|
|
const modelInfoField =
|
|
currentMode === "plan" ? "planModeVercelAiGatewayModelInfo" : "actModeVercelAiGatewayModelInfo"
|
|
const modelId = apiConfiguration[modelIdField]
|
|
|
|
if (modelId && response.models[modelId]) {
|
|
const updatedConfig = {
|
|
...apiConfiguration,
|
|
[modelInfoField]: response.models[modelId],
|
|
}
|
|
controller.stateManager.setApiConfiguration(updatedConfig)
|
|
await controller.postStateToWebview()
|
|
}
|
|
} else {
|
|
// Shared models: update both plan and act modes
|
|
const planModelId = apiConfiguration.planModeVercelAiGatewayModelId
|
|
const actModelId = apiConfiguration.actModeVercelAiGatewayModelId
|
|
const updatedConfig = { ...apiConfiguration }
|
|
|
|
// Update plan mode model info if we have a model ID
|
|
if (planModelId && response.models[planModelId]) {
|
|
updatedConfig.planModeVercelAiGatewayModelInfo = response.models[planModelId]
|
|
}
|
|
|
|
// Update act mode model info if we have a model ID
|
|
if (actModelId && response.models[actModelId]) {
|
|
updatedConfig.actModeVercelAiGatewayModelInfo = response.models[actModelId]
|
|
}
|
|
|
|
// Post state update if we updated any model info
|
|
if ((planModelId && response.models[planModelId]) || (actModelId && response.models[actModelId])) {
|
|
controller.stateManager.setApiConfiguration(updatedConfig)
|
|
await controller.postStateToWebview()
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
// GUI relies on model info to be up-to-date to provide the most accurate pricing, so we need to fetch the latest details on launch.
|
|
// We do this for all users since many users switch between api providers and if they were to switch back to openrouter it would be showing outdated model info if we hadn't retrieved the latest at this point
|
|
// (see normalizeApiConfiguration > openrouter)
|
|
// Prefetch marketplace and OpenRouter models
|
|
|
|
// Send stored MCP marketplace catalog if available
|
|
const mcpMarketplaceCatalog = controller.stateManager.getGlobalStateKey("mcpMarketplaceCatalog")
|
|
|
|
if (mcpMarketplaceCatalog) {
|
|
sendMcpMarketplaceCatalogEvent(mcpMarketplaceCatalog as McpMarketplaceCatalog)
|
|
}
|
|
|
|
// Silently refresh MCP marketplace catalog
|
|
controller.silentlyRefreshMcpMarketplace()
|
|
|
|
// Initialize telemetry service with user's current setting
|
|
controller.getStateToPostToWebview().then((state) => {
|
|
const { telemetrySetting } = state
|
|
const isOptedIn = telemetrySetting !== "disabled"
|
|
telemetryService.updateTelemetryState(isOptedIn)
|
|
})
|
|
|
|
// Refresh focus chain remote flag on webview init
|
|
featureFlagsService
|
|
.getFocusChainEnabled()
|
|
.then(async (enabled: boolean) => {
|
|
controller.stateManager.setGlobalState("focusChainFeatureFlagEnabled", enabled)
|
|
await controller.postStateToWebview()
|
|
})
|
|
.catch((err: any) => console.error("Failed to refresh focus chain remote flag on webview init", err))
|
|
|
|
return Empty.create({})
|
|
} catch (error) {
|
|
console.error("Failed to initialize webview:", error)
|
|
// Return empty response even on error to not break the frontend
|
|
return Empty.create({})
|
|
}
|
|
}
|