Changesets · Branches · Tags · Compare
| Changeset | 24ab09d466aebb813791730c68e755b4ee58331f20fb7b3c761c6058968af020 |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-06-27 17:26 -07:00 |
| Committer | Dallin Romney <dallinromney@gmail.com> · 2025-06-27 17:26 -07:00 |
| Parents | 409299863087 |
2 files changed
added gui/src/components/mainInput/TipTapEditor/utils/renderMcpPrompt.ts +32 −0
| @@ -0,0 +1,32 @@ | ||
| 1 | +import { SlashCommandDescWithSource } from "core"; | |
| 2 | +import { IIdeMessenger } from "../../../../context/IdeMessenger"; | |
| 3 | + | |
| 4 | +export async function renderMcpPrompt( | |
| 5 | + command: SlashCommandDescWithSource, | |
| 6 | + ideMessenger: IIdeMessenger, | |
| 7 | + userInput?: string, | |
| 8 | +) { | |
| 9 | + // TODO add support for mcp prompt args using command.mcpArgs | |
| 10 | + const args: { [key: string]: string } = {}; | |
| 11 | + if (command.mcpArgs) { | |
| 12 | + command.mcpArgs.forEach((arg, i) => { | |
| 13 | + args[arg.name] = ""; | |
| 14 | + }); | |
| 15 | + } | |
| 16 | + const response = await ideMessenger.request("mcp/getPrompt", { | |
| 17 | + serverName: command.mcpServerName!, | |
| 18 | + promptName: command.name, | |
| 19 | + args: args, | |
| 20 | + }); | |
| 21 | + if (response.status === "success") { | |
| 22 | + let renderedPrompt = response.content.prompt; | |
| 23 | + if (userInput) { | |
| 24 | + renderedPrompt += `\n\n${userInput}`; | |
| 25 | + } | |
| 26 | + return renderedPrompt; | |
| 27 | + } else { | |
| 28 | + throw new Error( | |
| 29 | + `Failed to get MCP prompt for slash command ${command.name}`, | |
| 30 | + ); | |
| 31 | + } | |
| 32 | +} |
modified gui/src/components/mainInput/TipTapEditor/utils/renderSlashCommand.ts +16 −26
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | import { MessagePart, RangeInFile, SlashCommandDescWithSource } from "core"; |
| 2 | 2 | import { stripImages } from "core/util/messageContent"; |
| 3 | 3 | import { IIdeMessenger } from "../../../../context/IdeMessenger"; |
| 4 | +import { renderMcpPrompt } from "./mcpPromptArgs"; | |
| 4 | 5 | import { getRenderedV1Prompt } from "./renderPromptv1"; |
| 5 | 6 | import { getPromptV2ContextRequests } from "./renderPromptv2"; |
| 6 | 7 | import { GetContextRequest } from "./types"; |
| @@ -63,32 +64,20 @@ | ||
| 63 | 64 | }); |
| 64 | 65 | break; |
| 65 | 66 | case "mcp-prompt": |
| 66 | - // TODO add support for mcp prompt args using command.mcpArgs | |
| 67 | - const args: { [key: string]: string } = {}; | |
| 68 | - if (command.mcpArgs) { | |
| 69 | - command.mcpArgs.forEach((arg, i) => { | |
| 70 | - args[arg.name] = ""; | |
| 71 | - }); | |
| 72 | - } | |
| 73 | - const response = await ideMessenger.request("mcp/getPrompt", { | |
| 74 | - serverName: command.mcpServerName!, | |
| 75 | - promptName: command.name, | |
| 76 | - args: args, | |
| 67 | + const renderedMcpPrompt = await renderMcpPrompt( | |
| 68 | + command, | |
| 69 | + ideMessenger, | |
| 70 | + userInput, | |
| 71 | + ); | |
| 72 | + slashedParts.push({ | |
| 73 | + type: "text", | |
| 74 | + text: renderedMcpPrompt, | |
| 77 | 75 | }); |
| 78 | - if (response.status === "success") { | |
| 79 | - slashedParts.push({ | |
| 80 | - type: "text", | |
| 81 | - text: `${response.content.prompt}${userInput ? "\n\n" + userInput : ""}`, | |
| 82 | - }); | |
| 83 | - } else { | |
| 84 | - throw new Error( | |
| 85 | - `Failed to get MCP prompt for slash command ${command.name}`, | |
| 86 | - ); | |
| 87 | - } | |
| 88 | 76 | break; |
| 89 | 77 | case "prompt-file-v1": |
| 90 | 78 | case "prompt-file-v2": |
| 91 | 79 | case "yaml-prompt-block": |
| 80 | + case "invokable-rule": | |
| 92 | 81 | if (!command.prompt) { |
| 93 | 82 | console.warn(`Invalid/empty prompt from slash command ${command.name}`); |
| 94 | 83 | break; |
| @@ -110,13 +99,13 @@ | ||
| 110 | 99 | command, |
| 111 | 100 | ); |
| 112 | 101 | contextRequests.push(...promptFileCtxRequests); |
| 113 | - renderedPrompt = [command.prompt, userInput].join("\n\n"); | |
| 102 | + renderedPrompt = [command.prompt, userInput].join("\n\n").trim(); | |
| 114 | 103 | } |
| 115 | 104 | |
| 116 | 105 | if (renderedPrompt) { |
| 117 | 106 | slashedParts.push({ |
| 118 | 107 | type: "text", |
| 119 | - text: renderedPrompt.trim(), // Includes user input | |
| 108 | + text: renderedPrompt, // Includes user input | |
| 120 | 109 | }); |
| 121 | 110 | } else { |
| 122 | 111 | console.warn( |
| @@ -126,14 +115,15 @@ | ||
| 126 | 115 | |
| 127 | 116 | break; |
| 128 | 117 | case "built-in": |
| 129 | - case "invokable-rule": | |
| 130 | 118 | case "json-custom-command": |
| 131 | 119 | if (!command.prompt) { |
| 132 | 120 | console.warn(`Slash command ${command.name} is missing prompt`); |
| 133 | 121 | break; |
| 134 | 122 | } |
| 135 | - const rendered = | |
| 136 | - `${command.prompt}${userInput ? "\n\n" + userInput : ""}`.trim(); | |
| 123 | + let rendered = command.prompt; | |
| 124 | + if (userInput) { | |
| 125 | + rendered += `\n\n${userInput}`; | |
| 126 | + } | |
| 137 | 127 | if (rendered) { |
| 138 | 128 | slashedParts.push({ |
| 139 | 129 | type: "text", |