mirror of
https://github.com/cline/cline.git
synced 2025-06-03 03:59:07 +00:00
67 lines
2.0 KiB
TypeScript
67 lines
2.0 KiB
TypeScript
import * as vscode from "vscode"
|
|
import { Controller } from "@core/controller"
|
|
import { ClineAPI } from "./cline"
|
|
import { getGlobalState } from "@core/storage/state"
|
|
|
|
export function createClineAPI(outputChannel: vscode.OutputChannel, sidebarController: Controller): ClineAPI {
|
|
const api: ClineAPI = {
|
|
setCustomInstructions: async (value: string) => {
|
|
await sidebarController.updateCustomInstructions(value)
|
|
outputChannel.appendLine("Custom instructions set")
|
|
},
|
|
|
|
getCustomInstructions: async () => {
|
|
return (await getGlobalState(sidebarController.context, "customInstructions")) as string | undefined
|
|
},
|
|
|
|
startNewTask: async (task?: string, images?: string[]) => {
|
|
outputChannel.appendLine("Starting new task")
|
|
await sidebarController.clearTask()
|
|
await sidebarController.postStateToWebview()
|
|
await sidebarController.postMessageToWebview({
|
|
type: "action",
|
|
action: "chatButtonClicked",
|
|
})
|
|
await sidebarController.postMessageToWebview({
|
|
type: "invoke",
|
|
invoke: "sendMessage",
|
|
text: task,
|
|
images: images,
|
|
})
|
|
outputChannel.appendLine(
|
|
`Task started with message: ${task ? `"${task}"` : "undefined"} and ${images?.length || 0} image(s)`,
|
|
)
|
|
},
|
|
|
|
sendMessage: async (message?: string, images?: string[]) => {
|
|
outputChannel.appendLine(
|
|
`Sending message: ${message ? `"${message}"` : "undefined"} with ${images?.length || 0} image(s)`,
|
|
)
|
|
await sidebarController.postMessageToWebview({
|
|
type: "invoke",
|
|
invoke: "sendMessage",
|
|
text: message,
|
|
images: images,
|
|
})
|
|
},
|
|
|
|
pressPrimaryButton: async () => {
|
|
outputChannel.appendLine("Pressing primary button")
|
|
await sidebarController.postMessageToWebview({
|
|
type: "invoke",
|
|
invoke: "primaryButtonClick",
|
|
})
|
|
},
|
|
|
|
pressSecondaryButton: async () => {
|
|
outputChannel.appendLine("Pressing secondary button")
|
|
await sidebarController.postMessageToWebview({
|
|
type: "invoke",
|
|
invoke: "secondaryButtonClick",
|
|
})
|
|
},
|
|
}
|
|
|
|
return api
|
|
}
|