Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: open in vscode #127

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"simple-git": "^3.22.0"
},
"devDependencies": {
"@podman-desktop/api": "0.0.202401191125-9c1aea6",
"@podman-desktop/api": "next",
"@types/js-yaml": "^4.0.9",
"@types/node": "^18",
"vitest": "^1.1.0"
Expand Down
12 changes: 10 additions & 2 deletions packages/backend/src/managers/applicationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ export class ApplicationManager {
private modelsManager: ModelsManager,
) {}

getRecipeLocalDirectory(recipe: Recipe): string {
return path.join(this.appUserDirectory, recipe.id);
}

async pullApplication(recipe: Recipe, model: ModelInfo) {
// Create a TaskUtils object to help us
const taskUtil = new RecipeStatusUtils(recipe.id, this.recipeStatusRegistry);

const localFolder = path.join(this.appUserDirectory, recipe.id);
const localFolder = this.getRecipeLocalDirectory(recipe);

// Adding checkout task
const checkoutTask: Task = {
Expand Down Expand Up @@ -209,7 +213,11 @@ export class ApplicationManager {
taskUtil.setTaskState(container.name, 'error');
});
}),
);
).then(() => {
taskUtil.setStatus('pulled');
}).catch(() => {
taskUtil.setStatus('error');
});
}

downloadModelMain(modelId: string, url: string, taskUtil: RecipeStatusUtils, destFileName?: string): Promise<string> {
Expand Down
11 changes: 11 additions & 0 deletions packages/backend/src/studio-api-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,15 @@ export class StudioApiImpl implements StudioAPI {
async getCatalog(): Promise<Catalog> {
return this.catalogManager.getCatalog();
}

async openVSCode(project: string): Promise<void> {
void podmanDesktopApi.env.openExternal(podmanDesktopApi.Uri.parse(project).with({scheme: 'vscode'}));
}

async getRecipeLocalDirectory(recipeId: string): Promise<string> {
const recipe = this.catalogManager.getRecipes().find((recipe) => recipe.id === recipeId);
if(recipe === undefined)
throw new Error(`Recipe with id ${recipeId} cannot be found.`);
return this.applicationManager.getRecipeLocalDirectory(recipe);
}
}
Binary file added packages/frontend/src/assets/vscode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions packages/frontend/src/lib/button/Button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export let padding: string = type !== 'tab' ? 'px-4 py-[5px]' : 'px-4 pb-1';
let iconType: string | undefined = undefined;

onMount(() => {
if (icon?.prefix === 'fas') {
if(typeof icon === 'string') {
iconType = 'string';
} else if (typeof icon === 'object' && !!icon && 'prefix' in icon && icon?.prefix === 'fas') {
iconType = 'fa';
} else {
iconType = 'unknown';
Expand Down Expand Up @@ -66,12 +68,14 @@ $: {
aria-label="{$$props['aria-label']}"
on:click
disabled="{disabled || inProgress}">
{#if icon}
{#if icon !== undefined}
<div class="flex flex-row p-0 m-0 bg-transparent justify-center items-center space-x-[4px]">
{#if inProgress}
<Spinner size="1em" />
{:else if iconType === 'fa'}
<Fa icon="{icon}" />
{:else if iconType === 'string'}
<img class="w-4 h-4 mr-1" alt="button-icon" src="{icon}"/>
{:else if iconType === 'unknown'}
<svelte:component this="{icon}" />
{/if}
Expand Down
18 changes: 16 additions & 2 deletions packages/frontend/src/pages/Recipe.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { getDisplayName } from '/@/utils/versionControlUtils';
import { getIcon } from '/@/utils/categoriesUtils';
import RecipeModels from './RecipeModels.svelte';
import { catalog } from '/@/stores/catalog';
import { recipes } from '/@/stores/recipe';
import { recipes } from '/@/stores/recipe';
import vscode from '../assets/vscode.png';

export let recipeId: string;

Expand All @@ -32,7 +33,12 @@ const onPullingRequest = async () => {
const onClickRepository = () => {
if (recipe) {
studioClient.openURL(recipe.repository);
}
}
}

const openInVSCode = async () => {
const directory = await studioClient.getRecipeLocalDirectory(recipeId);
void studioClient.openVSCode(directory);
}
</script>

Expand Down Expand Up @@ -60,6 +66,8 @@ const onClickRepository = () => {
</div>
</div>
</Card>

<span>status: {recipeStatus?.state}</span>
{#if recipeStatus !== undefined && recipeStatus.tasks.length > 0}
<Card classes="bg-charcoal-800 mt-4">
<div slot="content" class="text-base font-normal p-2">
Expand All @@ -73,6 +81,12 @@ const onClickRepository = () => {
class="w-full mt-4 p-2"
icon="{faRefresh}"
>Retry</Button>
{:else if recipeStatus.state === 'running' ||recipeStatus.state === 'pulled'}
<Button
on:click={() => openInVSCode()}
class="w-full mt-4 p-2"
icon="{vscode}"
>Open in vsCode</Button>
{/if}
</div>
</Card>
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/src/StudioAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ export abstract class StudioAPI {
abstract askPlayground(modelId: string, prompt: string): Promise<number>;
abstract getPlaygroundQueriesState(): Promise<QueryState[]>;
abstract getPlaygroundsState(): Promise<PlaygroundState[]>;
abstract openVSCode(project: string): Promise<void>;
abstract getRecipeLocalDirectory(recipeId: string): Promise<string>;
}
2 changes: 2 additions & 0 deletions types/additional.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
declare module 'tinro/dist/tinro_lib';

declare module "*.png"

Check failure on line 3 in types/additional.d.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / windows-2022

Strings must use singlequote

Check failure on line 3 in types/additional.d.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / ubuntu-22.04

Strings must use singlequote

Check failure on line 3 in types/additional.d.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / macos-12

Strings must use singlequote
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,10 @@
resolved "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz"
integrity sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==

"@podman-desktop/api@0.0.202401191125-9c1aea6":
version "0.0.202401191125-9c1aea6"
resolved "https://registry.yarnpkg.com/@podman-desktop/api/-/api-0.0.202401191125-9c1aea6.tgz#a6dd84efaa1769cc3eedde320c9d5524e2f920f1"
integrity sha512-4oMQmfCXpnQrnEihe1yn3mGZULle4a0MlXdyOZ4vlKx04e2rZK7jFI45EjU6L64pwN0bGHWLFRI12Ut2sAirHQ==
"@podman-desktop/api@next":
version "0.0.202401241015-649826f"
resolved "https://registry.yarnpkg.com/@podman-desktop/api/-/api-0.0.202401241015-649826f.tgz#2d0b2fcb9ebec8a02f293b62f4111761a624de46"
integrity sha512-IODttlkupNitoxE8FyHELcmIzInByalhz1jcB35kRC6UkPIXf9yNVrqPPXm+hTMNRMdRHTqE6a0KssiqoJ+lmA==

"@rollup/[email protected]":
version "4.9.1"
Expand Down
Loading