summaryrefslogtreecommitdiff
path: root/continuedev/src/continuedev/plugins/steps/custom_command.py
blob: 4128415b2cc7755d0b86fc62d10db081d3a26274 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from ...core.main import Step
from ...core.sdk import ContinueSDK, Models
from ...libs.util.templating import render_templated_string
from ..steps.chat import SimpleChatStep


class CustomCommandStep(Step):
    name: str
    prompt: str
    user_input: str
    slash_command: str
    hide: bool = True

    async def describe(self, models: Models):
        return self.prompt

    async def run(self, sdk: ContinueSDK):
        task = render_templated_string(self.prompt)

        prompt_user_input = f"Task: {task}. Additional info: {self.user_input}"
        messages = await sdk.get_chat_context()
        # Find the last chat message with this slash command and replace it with the user input
        for i in range(len(messages) - 1, -1, -1):
            if messages[i].role == "user" and messages[i].content.startswith(
                self.slash_command
            ):
                messages[i] = messages[i].copy(update={"content": prompt_user_input})
                break
        await sdk.run_step(SimpleChatStep(messages=messages))