Skip to content

Commit

Permalink
Remove 'genaiscript.prompt.unbuiltin' command and add 'cmds' to setti…
Browse files Browse the repository at this point in the history
…ngs.json (#710)

* Remove 'genaiscript.prompt.unbuiltin' command and add 'cmds' to settings.json

* samples download menu

* Comment out activateSamplesCommands in extension.ts
  • Loading branch information
pelikhan authored Sep 14, 2024
1 parent 9a67509 commit 0719cd7
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 25 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"arrayify",
"Automatable",
"bitindex",
"cmds",
"Codespaces",
"demux",
"devcontainers",
Expand Down
18 changes: 5 additions & 13 deletions packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,6 @@
"command": "genaiscript.newfile.script",
"when": "false"
},
{
"command": "genaiscript.prompt.unbuiltin",
"when": "false"
},
{
"command": "genaiscript.prompt.navigate",
"when": "false"
Expand Down Expand Up @@ -235,10 +231,6 @@
{
"command": "genaiscript.prompt.fork",
"when": "view == genaiscript.prompts && viewItem =~ /^prompt/"
},
{
"command": "genaiscript.prompt.unbuiltin",
"when": "view == genaiscript.prompts && viewItem =~ /^prompt.builtin/"
}
],
"explorer/context": [
Expand Down Expand Up @@ -330,11 +322,6 @@
"category": "GenAIScript",
"icon": "$(repo-forked)"
},
{
"command": "genaiscript.prompt.unbuiltin",
"title": "Move builtin to project",
"category": "GenAIScript"
},
{
"command": "genaiscript.request.open",
"title": "Open request or response",
Expand Down Expand Up @@ -369,6 +356,11 @@
"command": "genaiscript.connection.configure",
"title": "Configure connection...",
"category": "GenAIScript"
},
{
"command": "genaiscript.samples.download",
"title": "Download sample...",
"category": "GenAIScript"
}
]
},
Expand Down
1 change: 0 additions & 1 deletion packages/vscode/src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as vscode from "vscode"
import { TOOL_NAME } from "../../core/src/constants"
import { errorMessage } from "../../core/src/error"
import { ExtensionState } from "./state"

export function registerCommand(
id: string,
Expand Down
7 changes: 4 additions & 3 deletions packages/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ExtensionState } from "./state"
import { activateStatusBar } from "./statusbar"
import { activateFragmentCommands } from "./fragmentcommands"
import { activateMarkdownTextDocumentContentProvider } from "./markdowndocumentprovider"
import { activatePrompTreeDataProvider } from "./prompttree"
import { activatePromptTreeDataProvider } from "./prompttree"
import { activatePromptCommands, commandButtons } from "./promptcommands"
import { activateLLMRequestTreeDataProvider } from "./llmrequesttree"
import { activateAIRequestTreeDataProvider } from "./airequesttree"
Expand All @@ -22,15 +22,16 @@ import MarkdownItGitHubAlerts from "markdown-it-github-alerts"
import { activateConnectionInfoTree } from "./connectioninfotree"
import { updateConnectionConfiguration } from "../../core/src/connection"
import { APIType } from "../../core/src/host"
import { openUrlInTab } from "./browser"
import { activeTaskProvider } from "./taskprovider"
import { activateSamplesCommands } from "./samplescommands"

export async function activate(context: ExtensionContext) {
const state = new ExtensionState(context)
activatePromptCommands(state)
activateFragmentCommands(state)
// activateSamplesCommands(state)
activateMarkdownTextDocumentContentProvider(state)
activatePrompTreeDataProvider(state)
activatePromptTreeDataProvider(state)
activateConnectionInfoTree(state)
activateAIRequestTreeDataProvider(state)
activateLLMRequestTreeDataProvider(state)
Expand Down
7 changes: 0 additions & 7 deletions packages/vscode/src/promptcommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ export function activatePromptCommands(state: ExtensionState) {
)
}
),
registerCommand(
"genaiscript.prompt.unbuiltin",
async (template: PromptScript) => {
if (!template) return
await showPrompt(await copyPrompt(template, { fork: false }))
}
),
registerCommand(
"genaiscript.prompt.navigate",
async (prompt: PromptScript) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode/src/prompttree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ ${description}
}
}

export function activatePrompTreeDataProvider(state: ExtensionState) {
export function activatePromptTreeDataProvider(state: ExtensionState) {
const { context } = state
const { subscriptions } = context
const treeDataProvider = new PromptTreeDataProvider(state)
Expand Down
52 changes: 52 additions & 0 deletions packages/vscode/src/samplescommands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as vscode from "vscode"
import { ExtensionState } from "./state"
import { registerCommand } from "./commands"
import { Utils } from "vscode-uri"
import { GENAI_SRC } from "../../core/src/constants"
import { parsePromptScriptMeta } from "../../core/src/template"
import { writeFile } from "./fs"

export function activateSamplesCommands(state: ExtensionState) {
const { context, host } = state

registerCommand("genaiscript.samples.download", async () => {
const dir = Utils.joinPath(context.extensionUri, GENAI_SRC)
const files = await vscode.workspace.fs.readDirectory(
Utils.joinPath(context.extensionUri, GENAI_SRC)
)
const utf8 = host.createUTF8Decoder()
const samples = (
await Promise.all(
files
.map((f) => f[0])
.filter((f) => f.endsWith(".genai.mts"))
.map(async (filename) => ({
filename,
jsSource: utf8.decode(
await vscode.workspace.fs.readFile(
Utils.joinPath(dir, filename)
)
),
}))
)
).map((s) => ({ ...s, meta: parsePromptScriptMeta(s.jsSource) }))

const res = await vscode.window.showQuickPick<
vscode.QuickPickItem & { filename: string; jsSource: string }
>(
samples.map((s) => ({
label: s.meta.title,
detail: s.meta.description,
...s,
})),
{ title: "Pick a sample to download" }
)
if (res === undefined) return

const { jsSource, filename } = res
await writeFile(host.toUri(GENAI_SRC), filename, jsSource, {
open: true,
})
await state.parseWorkspace()
})
}

0 comments on commit 0719cd7

Please sign in to comment.