diff --git a/.vscode/settings.json b/.vscode/settings.json index 476405440e..37b6a125ac 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,7 @@ "arrayify", "Automatable", "bitindex", + "cmds", "Codespaces", "demux", "devcontainers", diff --git a/packages/vscode/package.json b/packages/vscode/package.json index 68b0c25112..6f93d5769f 100644 --- a/packages/vscode/package.json +++ b/packages/vscode/package.json @@ -197,10 +197,6 @@ "command": "genaiscript.newfile.script", "when": "false" }, - { - "command": "genaiscript.prompt.unbuiltin", - "when": "false" - }, { "command": "genaiscript.prompt.navigate", "when": "false" @@ -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": [ @@ -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", @@ -369,6 +356,11 @@ "command": "genaiscript.connection.configure", "title": "Configure connection...", "category": "GenAIScript" + }, + { + "command": "genaiscript.samples.download", + "title": "Download sample...", + "category": "GenAIScript" } ] }, diff --git a/packages/vscode/src/commands.ts b/packages/vscode/src/commands.ts index 59376696ea..7a25a83cb3 100644 --- a/packages/vscode/src/commands.ts +++ b/packages/vscode/src/commands.ts @@ -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, diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index 85ba94cc02..fb892c90a0 100644 --- a/packages/vscode/src/extension.ts +++ b/packages/vscode/src/extension.ts @@ -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" @@ -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) diff --git a/packages/vscode/src/promptcommands.ts b/packages/vscode/src/promptcommands.ts index b2101194b7..cc741e9a71 100644 --- a/packages/vscode/src/promptcommands.ts +++ b/packages/vscode/src/promptcommands.ts @@ -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) => { diff --git a/packages/vscode/src/prompttree.ts b/packages/vscode/src/prompttree.ts index 0cba07de9f..1877b63d64 100644 --- a/packages/vscode/src/prompttree.ts +++ b/packages/vscode/src/prompttree.ts @@ -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) diff --git a/packages/vscode/src/samplescommands.ts b/packages/vscode/src/samplescommands.ts new file mode 100644 index 0000000000..0c5b347156 --- /dev/null +++ b/packages/vscode/src/samplescommands.ts @@ -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() + }) +}