diff --git a/Main.sublime-commands b/Main.sublime-commands index 4893c76..a94fb4f 100644 --- a/Main.sublime-commands +++ b/Main.sublime-commands @@ -121,4 +121,8 @@ "default": "/* User extra CSS rules: Chat Panel */\n/* CSS rules: https://www.sublimetext.com/docs/minihtml.html#css */\n", }, }, + { + "caption": "Copilot: Send Any Request", + "command": "copilot_send_any_request" + } ] diff --git a/plugin/__init__.py b/plugin/__init__.py index 69df9f8..2e6badb 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -29,6 +29,7 @@ CopilotPrepareAndEditSettingsCommand, CopilotPreviousCompletionCommand, CopilotRejectCompletionCommand, + CopilotSendAnyRequestCommand, CopilotSignInCommand, CopilotSignInWithGithubTokenCommand, CopilotSignOutCommand, @@ -73,6 +74,7 @@ "CopilotConversationCopyCodeCommand", "CopilotConversationInsertCodeShimCommand", "CopilotConversationInsertCodeCommand", + "CopilotSendAnyRequestCommand", # ST: helper commands "CopilotPrepareAndEditSettingsCommand", # ST: event listeners diff --git a/plugin/commands.py b/plugin/commands.py index b2a7764..477f2eb 100644 --- a/plugin/commands.py +++ b/plugin/commands.py @@ -816,3 +816,42 @@ def _on_result_sign_out(self, payload: CopilotPayloadSignOut) -> None: message_dialog("Sign out OK. Bye!") GithubInfo.clear_avatar() + + +class CopilotSendAnyRequestCommand(CopilotTextCommand): + @_provide_plugin_session() + def run(self, plugin: CopilotPlugin, session: Session, _: sublime.Edit, request_type: str, payload: str) -> None: + try: + decode_payload = sublime.decode_value(payload) + except ValueError as e: + message_dialog(f"Failed to parse payload: {e}", is_error_=True) + decode_payload = {} + session.send_request(Request(request_type, decode_payload), self._on_results_any_request) + + def _on_results_any_request(self, payload: Any) -> None: + print(payload) + + def input(self, args: dict[str, Any]) -> sublime_plugin.CommandInputHandler | None: + return CopilotSendAnyRequestCommandTextInputHandler() + + +class CopilotSendAnyRequestCommandTextInputHandler(sublime_plugin.TextInputHandler): + def placeholder(self) -> str: + return "Enter type of request. Example: conversation/turn" + + def name(self) -> str: + return "request_type" + + def next_input(self, args: dict[str, Any]) -> sublime_plugin.CommandInputHandler | None: + return CopilotSendAnyRequestPayloadInputHandler(args) + + +class CopilotSendAnyRequestPayloadInputHandler(sublime_plugin.TextInputHandler): + def __init__(self, args: dict[str, Any]) -> None: + self.args = args + + def placeholder(self) -> str: + return 'Enter payload JSON. Example: {"conversationId": "12345"}' + + def name(self) -> str: + return "payload" diff --git a/plugin/types.py b/plugin/types.py index 566c744..56ad8b3 100644 --- a/plugin/types.py +++ b/plugin/types.py @@ -117,7 +117,13 @@ class CopilotPayloadSignInWithGithubToken(TypedDict, total=True): class CopilotPayloadSignInConfirm(TypedDict, total=True): - status: Literal["AlreadySignedIn", "MaybeOk", "NotAuthorized", "NotSignedIn", "OK"] + status: Literal[ + "AlreadySignedIn", + "MaybeOk", + "NotAuthorized", + "NotSignedIn", + "OK", + ] user: str @@ -239,7 +245,13 @@ class CopilotPayloadConversationContext(TypedDict, total=True): """E.g., `"e3b0d5e3-0c3b-4292-a5ea-15d6003e7c45"`.""" turnId: str """E.g., `"09ac7601-6c28-4617-b3e4-13f5ff8502b7"`.""" - skillId: Literal["current-editor", "project-labels", "recent-files"] # not the complet list yet + skillId: Literal[ + "current-editor", + "project-labels", + "recent-files", + "references", + "problems-in-active-document", + ] # not the complet list yet class CopilotUserDefinedPromptTemplates(TypedDict, total=True):