Skip to content

Commit

Permalink
feat: enhance markdown command handling in chatparticipant ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Nov 21, 2024
1 parent 56f0c2a commit fba3e98
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions packages/vscode/src/chatparticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ export async function activateChatParticipant(state: ExtensionState) {
await state.parseWorkspace()
if (token.isCancellationRequested) return

const md = (t: string) => {
response.markdown(new vscode.MarkdownString(t + "\n", true))
const md = (t: string, ...enabledCommands: string[]) => {
const ms = new vscode.MarkdownString(t + "\n", true)
if (enabledCommands.length)
ms.isTrusted = {
enabledCommands,
}
response.markdown(ms)
}

const { project } = state
Expand All @@ -62,7 +67,8 @@ export async function activateChatParticipant(state: ExtensionState) {
)
const mdEmpty = () =>
md(
`$(error) Oops, I could not find any genaiscript. Try **GenAIScript: Create new script...** to create one.\n`
`\n$(error) Oops, I could not find any genaiscript. [Create a new script](command:genaiscript.prompt.create)).\n`,
"genaiscript.prompt.create"
)
const mdTemplateList = () => {
templates
Expand All @@ -78,15 +84,12 @@ export async function activateChatParticipant(state: ExtensionState) {
}
if (command === "list") {
if (templates.length) {
md(
"Use `@genaiscript /run ...` with one of these scripts:\n"
)
md("Use `@genaiscript /run <scriptid> ...` with:\n")
mdTemplateList()
mdHelp()
} else {
mdEmpty()
mdHelp()
}
mdHelp()
return
}

Expand All @@ -96,21 +99,19 @@ export async function activateChatParticipant(state: ExtensionState) {
prompt = prompt.slice(scriptid.length).trim()
template = templates.find((t) => t.id === scriptid)
if (!template) {
if (scriptid === "")
md(`$(error) Please specify a genaiscript to run.\n`)
else
md(
`$(error) Oops, I could not find any genaiscript matching \`${scriptid}\`.\n`
)
if (templates.length === 0) {
mdEmpty()
} else {
if (scriptid === "")
md(
`$(error) Please specify a genaiscript to run.\n`
)
else
md(
`$(error) Oops, I could not find any genaiscript matching \`${scriptid}\`.\n`
)
md(`Try one of the following:\n`)
mdTemplateList()
mdHelp()
}
mdHelp()
return
}
} else {
Expand All @@ -127,6 +128,7 @@ export async function activateChatParticipant(state: ExtensionState) {
template = picked?.template
if (!template) {
md(`\n\n$(error) Cancelled, no script selected.`)
mdHelp()
return
}
}
Expand Down Expand Up @@ -157,14 +159,10 @@ export async function activateChatParticipant(state: ExtensionState) {
const { text = "", status, statusText } = res || {}
if (status !== "success") md("$(error) " + statusText)
if (text) md("\n\n" + convertAnnotationsToItems(text))
const buttons = new vscode.MarkdownString(
md(
`\n\n[output](command:genaiscript.request.open?${encodeURIComponent(JSON.stringify([CACHE_AIREQUEST_TEXT_PREFIX + res.requestSha + ".md"]))}) | [trace](command:genaiscript.request.open?${encodeURIComponent(JSON.stringify([CACHE_AIREQUEST_TRACE_PREFIX + res.requestSha + ".md"]))})`,
true
"genaiscript.request.open"
)
buttons.isTrusted = {
enabledCommands: ["genaiscript.request.open"],
}
response.markdown(buttons)
}
)
participant.iconPath = new vscode.ThemeIcon(ICON_LOGO_NAME)
Expand Down

0 comments on commit fba3e98

Please sign in to comment.