feat: expose prompt helper to workspace panels

This commit is contained in:
Federico Jaramillo Martinez
2026-06-24 23:59:39 +02:00
parent f6fbf6b851
commit 9980027cee
6 changed files with 45 additions and 4 deletions
+1
View File
@@ -1250,6 +1250,7 @@ export class PiWebApp extends LitElement {
workspace,
state: this.state,
files: this.createWorkspaceFiles(workspace, machineId),
prompt: this.createPromptEditor(),
terminal: {
open: (options) => { void this.openRuntimeTerminal(machineId, workspace, options); },
runCommand: (input) => terminalCommandRuns.runCommand({ ...input, workspace }),
+33 -1
View File
@@ -89,6 +89,37 @@ describe("PluginRegistry", () => {
expect(registry.getWorkspacePanels()[0]?.icon).toBeDefined();
});
it("exposes the prompt helper to workspace panel callbacks", () => {
const registry = new PluginRegistry();
registry.register({
id: "example",
plugin: {
apiVersion: 1,
name: "Example",
activate: () => ({
contributions: {
workspacePanels: [
{
id: "workspace.prompt",
title: "Prompt",
render: (context) => {
context.prompt.insertText("@docs/example.md");
return html`<p>Prompt</p>`;
},
},
],
},
}),
},
});
const insertText = vi.fn();
const context = createWorkspacePanelContext("local", { insertText, getText: vi.fn(() => ""), getSelection: vi.fn(() => null) });
registry.getWorkspacePanels()[0]?.render(context);
expect(insertText).toHaveBeenCalledWith("@docs/example.md");
});
it("rejects duplicate ids within the same namespace", () => {
const registry = new PluginRegistry();
@@ -561,13 +592,14 @@ function createWorkspaceLabelContext(machineId: string, workspace = testWorkspac
};
}
function createWorkspacePanelContext(machineId: string): WorkspacePanelContext {
function createWorkspacePanelContext(machineId: string, prompt: WorkspacePanelContext["prompt"] = { insertText: vi.fn(), getText: vi.fn(() => ""), getSelection: vi.fn(() => null) }): WorkspacePanelContext {
const workspace = testWorkspace();
return {
machine: { id: machineId, name: machineId, kind: machineId === "local" ? "local" : "remote" },
workspace,
state: { ...initialAppState(), selectedMachine: testMachine(machineId) },
files: { readFile: vi.fn(), writeFile: vi.fn(), deleteFile: vi.fn(), moveFile: vi.fn() },
prompt,
terminal: { open: vi.fn(), runCommand: vi.fn() },
host: { requestRender: vi.fn() },
fileTree: [],
+1
View File
@@ -138,6 +138,7 @@ export interface QualifiedPluginAction extends AppAction {
}
export interface WorkspacePanelContext extends WorkspaceContext {
prompt: PluginPromptEditor;
terminal: WorkspacePanelTerminal;
/**
* @deprecated Runtime-only compatibility alias for pre-v2 plugins. Use `terminal.open()` instead.
+1
View File
@@ -168,6 +168,7 @@ export interface WorkspacePanelTerminal {
}
export interface WorkspacePanelContext extends WorkspaceContext {
prompt: PluginPromptEditor;
terminal: WorkspacePanelTerminal;
}