( provider: ClineProvider, message: WebviewMessage, marketplaceManager?: MarketplaceManager, )
| 102 | } from "./worktree" |
| 103 | |
| 104 | export const webviewMessageHandler = async ( |
| 105 | provider: ClineProvider, |
| 106 | message: WebviewMessage, |
| 107 | marketplaceManager?: MarketplaceManager, |
| 108 | ) => { |
| 109 | // Utility functions provided for concise get/update of global state via contextProxy API. |
| 110 | const getGlobalState = <K extends keyof GlobalState>(key: K) => provider.contextProxy.getValue(key) |
| 111 | const updateGlobalState = async <K extends keyof GlobalState>(key: K, value: GlobalState[K]) => |
| 112 | await provider.contextProxy.setValue(key, value) |
| 113 | |
| 114 | const getCurrentCwd = () => { |
| 115 | return provider.getCurrentTask()?.cwd || provider.cwd |
| 116 | } |
| 117 | |
| 118 | const isCloudServiceAvailable = () => CloudService.hasInstance() |
| 119 | |
| 120 | const showCloudUnavailableMessage = () => { |
| 121 | vscode.window.showInformationMessage(getRouterUnavailableSignInMessage()) |
| 122 | } |
| 123 | |
| 124 | const resolveCompletionCheckpoint = (currentCline: { clineMessages: ClineMessage[] }) => { |
| 125 | return getCompletionCheckpoint(currentCline.clineMessages) |
| 126 | } |
| 127 | |
| 128 | const getCurrentMode = async (): Promise<string> => { |
| 129 | const currentTask = provider.getCurrentTask() |
| 130 | |
| 131 | if (currentTask) { |
| 132 | try { |
| 133 | return await currentTask.getTaskMode() |
| 134 | } catch (error) { |
| 135 | provider.log( |
| 136 | `Error resolving current task mode for command discovery: ${JSON.stringify(error, Object.getOwnPropertyNames(error), 2)}`, |
| 137 | ) |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | try { |
| 142 | const state = await provider.getState() |
| 143 | if (typeof state.mode === "string" && state.mode.length > 0) { |
| 144 | return state.mode |
| 145 | } |
| 146 | } catch (error) { |
| 147 | provider.log( |
| 148 | `Error resolving global mode for command discovery: ${JSON.stringify(error, Object.getOwnPropertyNames(error), 2)}`, |
| 149 | ) |
| 150 | } |
| 151 | |
| 152 | return defaultModeSlug |
| 153 | } |
| 154 | |
| 155 | const getDiscoveredCommands = async (): Promise<SlashCommand[]> => { |
| 156 | const { getCommands } = await import("../../services/command/commands") |
| 157 | const commands = await getCommands(getCurrentCwd()) |
| 158 | |
| 159 | const commandList: SlashCommand[] = commands.map((command) => ({ |
| 160 | name: command.name, |
| 161 | source: command.source, |
no test coverage detected