|
|
@@ -47,7 +47,7 @@ import { Package } from "../../shared/package"
|
|
|
import { findLast } from "../../shared/array"
|
|
|
import { supportPrompt } from "../../shared/support-prompt"
|
|
|
import { GlobalFileNames } from "../../shared/globalFileNames"
|
|
|
-import { ExtensionMessage, MarketplaceInstalledMetadata } from "../../shared/ExtensionMessage"
|
|
|
+import type { ExtensionMessage, ExtensionState, MarketplaceInstalledMetadata } from "../../shared/ExtensionMessage"
|
|
|
import { Mode, defaultModeSlug, getModeBySlug } from "../../shared/modes"
|
|
|
import { experimentDefault } from "../../shared/experiments"
|
|
|
import { formatLanguage } from "../../shared/language"
|
|
|
@@ -184,6 +184,7 @@ export class ClineProvider
|
|
|
const onTaskInteractive = (taskId: string) => this.emit(RooCodeEventName.TaskInteractive, taskId)
|
|
|
const onTaskResumable = (taskId: string) => this.emit(RooCodeEventName.TaskResumable, taskId)
|
|
|
const onTaskIdle = (taskId: string) => this.emit(RooCodeEventName.TaskIdle, taskId)
|
|
|
+ const onTaskUserMessage = (taskId: string) => this.emit(RooCodeEventName.TaskUserMessage, taskId)
|
|
|
|
|
|
// Attach the listeners.
|
|
|
instance.on(RooCodeEventName.TaskStarted, onTaskStarted)
|
|
|
@@ -195,6 +196,7 @@ export class ClineProvider
|
|
|
instance.on(RooCodeEventName.TaskInteractive, onTaskInteractive)
|
|
|
instance.on(RooCodeEventName.TaskResumable, onTaskResumable)
|
|
|
instance.on(RooCodeEventName.TaskIdle, onTaskIdle)
|
|
|
+ instance.on(RooCodeEventName.TaskUserMessage, onTaskUserMessage)
|
|
|
|
|
|
// Store the cleanup functions for later removal.
|
|
|
this.taskEventListeners.set(instance, [
|
|
|
@@ -207,6 +209,7 @@ export class ClineProvider
|
|
|
() => instance.off(RooCodeEventName.TaskInteractive, onTaskInteractive),
|
|
|
() => instance.off(RooCodeEventName.TaskResumable, onTaskResumable),
|
|
|
() => instance.off(RooCodeEventName.TaskIdle, onTaskIdle),
|
|
|
+ () => instance.off(RooCodeEventName.TaskUserMessage, onTaskUserMessage),
|
|
|
])
|
|
|
}
|
|
|
|
|
|
@@ -1210,14 +1213,16 @@ export class ClineProvider
|
|
|
// OpenRouter
|
|
|
|
|
|
async handleOpenRouterCallback(code: string) {
|
|
|
- let { apiConfiguration, currentApiConfigName } = await this.getState()
|
|
|
+ let { apiConfiguration, currentApiConfigName = "default" } = await this.getState()
|
|
|
|
|
|
let apiKey: string
|
|
|
+
|
|
|
try {
|
|
|
const baseUrl = apiConfiguration.openRouterBaseUrl || "https://openrouter.ai/api/v1"
|
|
|
- // Extract the base domain for the auth endpoint
|
|
|
+ // Extract the base domain for the auth endpoint.
|
|
|
const baseUrlDomain = baseUrl.match(/^(https?:\/\/[^\/]+)/)?.[1] || "https://openrouter.ai"
|
|
|
const response = await axios.post(`${baseUrlDomain}/api/v1/auth/keys`, { code })
|
|
|
+
|
|
|
if (response.data && response.data.key) {
|
|
|
apiKey = response.data.key
|
|
|
} else {
|
|
|
@@ -1227,6 +1232,7 @@ export class ClineProvider
|
|
|
this.log(
|
|
|
`Error exchanging code for API key: ${JSON.stringify(error, Object.getOwnPropertyNames(error), 2)}`,
|
|
|
)
|
|
|
+
|
|
|
throw error
|
|
|
}
|
|
|
|
|
|
@@ -1244,8 +1250,10 @@ export class ClineProvider
|
|
|
|
|
|
async handleGlamaCallback(code: string) {
|
|
|
let apiKey: string
|
|
|
+
|
|
|
try {
|
|
|
const response = await axios.post("https://glama.ai/api/gateway/v1/auth/exchange-code", { code })
|
|
|
+
|
|
|
if (response.data && response.data.apiKey) {
|
|
|
apiKey = response.data.apiKey
|
|
|
} else {
|
|
|
@@ -1255,10 +1263,11 @@ export class ClineProvider
|
|
|
this.log(
|
|
|
`Error exchanging code for API key: ${JSON.stringify(error, Object.getOwnPropertyNames(error), 2)}`,
|
|
|
)
|
|
|
+
|
|
|
throw error
|
|
|
}
|
|
|
|
|
|
- const { apiConfiguration, currentApiConfigName } = await this.getState()
|
|
|
+ const { apiConfiguration, currentApiConfigName = "default" } = await this.getState()
|
|
|
|
|
|
const newConfiguration: ProviderSettings = {
|
|
|
...apiConfiguration,
|
|
|
@@ -1273,7 +1282,7 @@ export class ClineProvider
|
|
|
// Requesty
|
|
|
|
|
|
async handleRequestyCallback(code: string) {
|
|
|
- let { apiConfiguration, currentApiConfigName } = await this.getState()
|
|
|
+ let { apiConfiguration, currentApiConfigName = "default" } = await this.getState()
|
|
|
|
|
|
const newConfiguration: ProviderSettings = {
|
|
|
...apiConfiguration,
|
|
|
@@ -1531,7 +1540,7 @@ export class ClineProvider
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async getStateToPostToWebview() {
|
|
|
+ async getStateToPostToWebview(): Promise<ExtensionState> {
|
|
|
const {
|
|
|
apiConfiguration,
|
|
|
lastShownAnnouncementId,
|
|
|
@@ -1621,6 +1630,7 @@ export class ClineProvider
|
|
|
remoteControlEnabled,
|
|
|
openRouterImageApiKey,
|
|
|
openRouterImageGenerationSelectedModel,
|
|
|
+ openRouterUseMiddleOutTransform,
|
|
|
} = await this.getState()
|
|
|
|
|
|
const telemetryKey = process.env.POSTHOG_API_KEY
|
|
|
@@ -1658,6 +1668,7 @@ export class ClineProvider
|
|
|
: undefined,
|
|
|
clineMessages: this.getCurrentTask()?.clineMessages || [],
|
|
|
currentTaskTodos: this.getCurrentTask()?.todoList || [],
|
|
|
+ messageQueue: this.getCurrentTask()?.messageQueueService?.messages,
|
|
|
taskHistory: (taskHistory || [])
|
|
|
.filter((item: HistoryItem) => item.ts && item.task)
|
|
|
.sort((a: HistoryItem, b: HistoryItem) => b.ts - a.ts),
|
|
|
@@ -1754,6 +1765,7 @@ export class ClineProvider
|
|
|
remoteControlEnabled,
|
|
|
openRouterImageApiKey,
|
|
|
openRouterImageGenerationSelectedModel,
|
|
|
+ openRouterUseMiddleOutTransform,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1763,7 +1775,17 @@ export class ClineProvider
|
|
|
* https://www.eliostruyf.com/devhack-code-extension-storage-options/
|
|
|
*/
|
|
|
|
|
|
- async getState() {
|
|
|
+ async getState(): Promise<
|
|
|
+ Omit<
|
|
|
+ ExtensionState,
|
|
|
+ | "clineMessages"
|
|
|
+ | "renderContext"
|
|
|
+ | "hasOpenedModeSelector"
|
|
|
+ | "version"
|
|
|
+ | "shouldShowAnnouncement"
|
|
|
+ | "hasSystemPromptOverride"
|
|
|
+ >
|
|
|
+ > {
|
|
|
const stateValues = this.contextProxy.getValues()
|
|
|
const customModes = await this.customModesManager.getCustomModes()
|
|
|
|
|
|
@@ -1831,7 +1853,7 @@ export class ClineProvider
|
|
|
)
|
|
|
}
|
|
|
|
|
|
- // Return the same structure as before
|
|
|
+ // Return the same structure as before.
|
|
|
return {
|
|
|
apiConfiguration: providerSettings,
|
|
|
lastShownAnnouncementId: stateValues.lastShownAnnouncementId,
|
|
|
@@ -1855,7 +1877,7 @@ export class ClineProvider
|
|
|
allowedMaxCost: stateValues.allowedMaxCost,
|
|
|
autoCondenseContext: stateValues.autoCondenseContext ?? true,
|
|
|
autoCondenseContextPercent: stateValues.autoCondenseContextPercent ?? 100,
|
|
|
- taskHistory: stateValues.taskHistory,
|
|
|
+ taskHistory: stateValues.taskHistory ?? [],
|
|
|
allowedCommands: stateValues.allowedCommands,
|
|
|
deniedCommands: stateValues.deniedCommands,
|
|
|
soundEnabled: stateValues.soundEnabled ?? false,
|
|
|
@@ -1902,7 +1924,7 @@ export class ClineProvider
|
|
|
customModes,
|
|
|
maxOpenTabsContext: stateValues.maxOpenTabsContext ?? 20,
|
|
|
maxWorkspaceFiles: stateValues.maxWorkspaceFiles ?? 200,
|
|
|
- openRouterUseMiddleOutTransform: stateValues.openRouterUseMiddleOutTransform ?? true,
|
|
|
+ openRouterUseMiddleOutTransform: stateValues.openRouterUseMiddleOutTransform,
|
|
|
browserToolEnabled: stateValues.browserToolEnabled ?? true,
|
|
|
telemetrySetting: stateValues.telemetrySetting || "unset",
|
|
|
showRooIgnoredFiles: stateValues.showRooIgnoredFiles ?? false,
|
|
|
@@ -1916,7 +1938,6 @@ export class ClineProvider
|
|
|
sharingEnabled,
|
|
|
organizationAllowList,
|
|
|
organizationSettingsVersion,
|
|
|
- // Explicitly add condensing settings
|
|
|
condensingApiConfigId: stateValues.condensingApiConfigId,
|
|
|
customCondensingPrompt: stateValues.customCondensingPrompt,
|
|
|
codebaseIndexModels: stateValues.codebaseIndexModels ?? EMBEDDING_MODEL_PROFILES,
|
|
|
@@ -1936,12 +1957,9 @@ export class ClineProvider
|
|
|
codebaseIndexSearchMinScore: stateValues.codebaseIndexConfig?.codebaseIndexSearchMinScore,
|
|
|
},
|
|
|
profileThresholds: stateValues.profileThresholds ?? {},
|
|
|
- // Add diagnostic message settings
|
|
|
includeDiagnosticMessages: stateValues.includeDiagnosticMessages ?? true,
|
|
|
maxDiagnosticMessages: stateValues.maxDiagnosticMessages ?? 50,
|
|
|
- // Add includeTaskHistoryInEnhance setting
|
|
|
includeTaskHistoryInEnhance: stateValues.includeTaskHistoryInEnhance ?? true,
|
|
|
- // Add remoteControlEnabled setting - get from cloud settings
|
|
|
remoteControlEnabled: (() => {
|
|
|
try {
|
|
|
const cloudSettings = CloudService.instance.getUserSettings()
|
|
|
@@ -1953,7 +1971,6 @@ export class ClineProvider
|
|
|
return false
|
|
|
}
|
|
|
})(),
|
|
|
- // Add image generation settings
|
|
|
openRouterImageApiKey: stateValues.openRouterImageApiKey,
|
|
|
openRouterImageGenerationSelectedModel: stateValues.openRouterImageGenerationSelectedModel,
|
|
|
}
|
|
|
@@ -2390,12 +2407,12 @@ export class ClineProvider
|
|
|
// Provider Profiles
|
|
|
|
|
|
public async getProviderProfiles(): Promise<{ name: string; provider?: string }[]> {
|
|
|
- const { listApiConfigMeta } = await this.getState()
|
|
|
+ const { listApiConfigMeta = [] } = await this.getState()
|
|
|
return listApiConfigMeta.map((profile) => ({ name: profile.name, provider: profile.apiProvider }))
|
|
|
}
|
|
|
|
|
|
public async getProviderProfile(): Promise<string> {
|
|
|
- const { currentApiConfigName } = await this.getState()
|
|
|
+ const { currentApiConfigName = "default" } = await this.getState()
|
|
|
return currentApiConfigName
|
|
|
}
|
|
|
|
|
|
@@ -2446,7 +2463,7 @@ export class ClineProvider
|
|
|
}
|
|
|
|
|
|
private async getTaskProperties(): Promise<DynamicAppProperties & TaskProperties> {
|
|
|
- const { language, mode, apiConfiguration } = await this.getState()
|
|
|
+ const { language = "en", mode, apiConfiguration } = await this.getState()
|
|
|
|
|
|
const task = this.getCurrentTask()
|
|
|
const todoList = task?.todoList
|