Skip to content

Commit

Permalink
Support single-file prompts (#20)
Browse files Browse the repository at this point in the history
* Support single-file prompts

* `prompt-file` -> `prompts-file`

* Add arg dump
  • Loading branch information
ColinMcNeil authored Sep 9, 2024
1 parent bc41cb1 commit 76acc60
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 271 deletions.

This file was deleted.

3 changes: 3 additions & 0 deletions src/extension/ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,11 @@ export function App() {
]);

runOutput.updateOutput({ method: 'message', params: { debug: 'Running prompts...' } })

const args = getRunArgs(selectedPrompt!, selectedProject!, "", client.host.platform)

runOutput.updateOutput({ method: 'message', params: { debug: `Running prompt image with args ${args}` } })

client.docker.cli.exec("run", args, {
stream: {
splitOutputLines: true,
Expand Down
4 changes: 2 additions & 2 deletions src/extension/ui/src/args.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export const getRunArgs = (promptRef: string, projectDir: string, username: string, platform: string, render = false) => {
const isLocal = promptRef.startsWith('local://');
const isMarkdown = promptRef.toLowerCase().endsWith('.md');
let promptArgs: string[] = ["--prompts", promptRef];
let mountArgs: string[] = [];

if (isLocal) {
const localPromptPath = promptRef.replace('local://', '');
const pathSeparator = platform === 'win32' ? '\\' : '/';
promptRef = localPromptPath.split(pathSeparator).pop() || 'unknown-local-prompt';
promptArgs = ["--prompts-dir", `/app/${promptRef}`];
promptArgs = [isMarkdown ? "--prompts-file" : "--prompts-dir", `/app/${promptRef}`];
mountArgs = ["--mount", `type=bind,source=${localPromptPath},target=/app/${promptRef}`];
}

Expand Down
8 changes: 5 additions & 3 deletions src/extension/ui/src/components/Projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ const Projects: React.FC<ProjectsProps> = ({ projects, selectedProject, setProje
<Stack direction='row' spacing={1} sx={{ mt: 1 }} alignItems={'center'} justifyContent={'space-between'}>
<Button sx={{ padding: 1 }} onClick={() => {
client.desktopUI.dialog.showOpenDialog({
properties: ['openDirectory', 'multiSelections']
title: 'Import projects',
properties: ['openDirectory', 'multiSelections'],
}).then((result) => {
if (result.canceled) {
return;
}
const newProjects = result.filePaths;
setProjects([...projects, ...newProjects]);
setSelectedProject(newProjects[0]);
});
}}>
Import projects
Import project(s)
</Button>
</Stack>
<List>
Expand All @@ -57,7 +59,7 @@ const Projects: React.FC<ProjectsProps> = ({ projects, selectedProject, setProje
</ListItem>
))}
</List>
</Paper>
</Paper >
);
};

Expand Down
7 changes: 5 additions & 2 deletions src/extension/ui/src/components/Prompts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ const Prompts: React.FC<PromptsProps> = ({ prompts, selectedPrompt, promptInput,
)}
<Button onClick={() => {
client.desktopUI.dialog.showOpenDialog({
properties: ['openDirectory', 'multiSelections']
title: 'Select prompt',
properties: ['openDirectory', 'openFile', 'multiSelections'],
filters: [{ name: 'Markdown', extensions: ['.md'] }],
}).then((result) => {
if (result.canceled) {
return;
}
track('DockerPromptsAddLocalPrompt');
setPrompts([...prompts, ...result.filePaths.map(p => `local://${p}`)]);
setSelectedPrompt(`local://${result.filePaths[0]}`);
});
}}>Add local prompt</Button>
}}>Add local prompt(s)</Button>
</Stack>
<List>
{prompts.map((prompt) => (
Expand Down
Loading

0 comments on commit 76acc60

Please sign in to comment.