Skip to content

Commit

Permalink
feat: ✨ add list command for GenAIScript scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Nov 21, 2024
1 parent 1b69c46 commit b792d4d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
6 changes: 6 additions & 0 deletions packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
"fullName": "GenAIScript",
"isSticky": false,
"commands": [
{
"name": "list",
"description": "Lists all available GenAIScript scripts.",
"isSticky": false,
"sampleRequest": "/list"
},
{
"name": "run",
"description": "Runs a GenAIScript script. The query should start with the script filename without the extension.",
Expand Down
23 changes: 16 additions & 7 deletions packages/vscode/src/chatparticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ export async function activateChatParticipant(state: ExtensionState) {

const { project } = state
const { templates } = project
const mdTemplateList = () =>
md(
state.project.templates
.filter((s) => !s.system && !s.unlisted)
.map((s) => `- \`${s.id}\`: ${s.title}`)
.join("\n")
)
if (command === "list") {
md("Use `@genaiscript /run ...` with one of these scripts:")
mdTemplateList()
return
}

let template: PromptScript
if (command === "run") {
const scriptid = prompt.split(" ")[0]
Expand All @@ -64,7 +77,7 @@ export async function activateChatParticipant(state: ExtensionState) {
if (!template) {
if (state.project.templates.length === 0) {
md(
`$(error) Oops, I could not find any genaiscript. Try **GenAIScript: Create new script...** to create one.`
`$(error) Oops, I could not find any genaiscript. Try **GenAIScript: Create new script...** to create one or checkout [samples](https://microsoft.github.io/genaiscript/reference/vscode/github-copilot-chat/).`
)
} else {
if (scriptid === "")
Expand All @@ -73,12 +86,8 @@ export async function activateChatParticipant(state: ExtensionState) {
md(
`$(error) Oops, I could not find any genaiscript matching \`${scriptid}\`.`
)
md(`Try one of the following:
${state.project.templates
.filter((s) => !s.system && !s.unlisted)
.map((s) => `- \`${s.id}\`: ${s.title}`)
.join("\n")}
`)
md(`Try one of the following:\n`)
mdTemplateList()
}
return
}
Expand Down

0 comments on commit b792d4d

Please sign in to comment.