Skip to content

Commit

Permalink
fix: resolve the merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ali00209 committed Nov 12, 2024
1 parent 7b0f67b commit 45df6d6
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions app/lib/stores/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import { PreviewsStore } from './previews';
import { TerminalStore } from './terminal';
import JSZip from 'jszip';
import { saveAs } from 'file-saver';
import { Octokit } from "@octokit/rest";
import { Octokit, type RestEndpointMethodTypes } from "@octokit/rest";
import * as nodePath from 'node:path';
import type { WebContainerProcess } from '@webcontainer/api';

export interface ArtifactState {
id: string;
Expand Down Expand Up @@ -39,6 +41,7 @@ export class WorkbenchStore {
unsavedFiles: WritableAtom<Set<string>> = import.meta.hot?.data.unsavedFiles ?? atom(new Set<string>());
modifiedFiles = new Set<string>();
artifactIdList: string[] = [];
#boltTerminal: { terminal: ITerminal; process: WebContainerProcess } | undefined;

constructor() {
if (import.meta.hot) {
Expand Down Expand Up @@ -76,6 +79,9 @@ export class WorkbenchStore {
get showTerminal() {
return this.#terminalStore.showTerminal;
}
get boltTerminal() {
return this.#terminalStore.boltTerminal;
}

toggleTerminal(value?: boolean) {
this.#terminalStore.toggleTerminal(value);
Expand All @@ -84,6 +90,10 @@ export class WorkbenchStore {
attachTerminal(terminal: ITerminal) {
this.#terminalStore.attachTerminal(terminal);
}
attachBoltTerminal(terminal: ITerminal) {

this.#terminalStore.attachBoltTerminal(terminal);
}

onTerminalResize(cols: number, rows: number) {
this.#terminalStore.onTerminalResize(cols, rows);
Expand Down Expand Up @@ -232,7 +242,7 @@ export class WorkbenchStore {
id,
title,
closed: false,
runner: new ActionRunner(webcontainer),
runner: new ActionRunner(webcontainer, () => this.boltTerminal),
});
}

Expand All @@ -258,16 +268,37 @@ export class WorkbenchStore {
artifact.runner.addAction(data);
}

async runAction(data: ActionCallbackData) {
async runAction(data: ActionCallbackData, isStreaming: boolean = false) {
const { messageId } = data;

const artifact = this.#getArtifact(messageId);

if (!artifact) {
unreachable('Artifact not found');
}
if (data.action.type === 'file') {
let wc = await webcontainer
const fullPath = nodePath.join(wc.workdir, data.action.filePath);
if (this.selectedFile.value !== fullPath) {
this.setSelectedFile(fullPath);
}
if (this.currentView.value !== 'code') {
this.currentView.set('code');
}
const doc = this.#editorStore.documents.get()[fullPath];
if (!doc) {
await artifact.runner.runAction(data, isStreaming);
}

this.#editorStore.updateFile(fullPath, data.action.content);

artifact.runner.runAction(data);
if (!isStreaming) {
this.resetCurrentDocument();
await artifact.runner.runAction(data);
}
} else {
artifact.runner.runAction(data);
}
}

#getArtifact(id: string) {
Expand Down

0 comments on commit 45df6d6

Please sign in to comment.