@@ -16,6 +16,7 @@ import * as nodePath from 'node:path';
1616import { extractRelativePath } from '~/utils/diff' ;
1717import { description } from '~/lib/persistence' ;
1818import Cookies from 'js-cookie' ;
19+ import { createSampler } from '~/utils/sampler' ;
1920
2021export interface ArtifactState {
2122 id : string ;
@@ -262,9 +263,9 @@ export class WorkbenchStore {
262263 this . artifacts . setKey ( messageId , { ...artifact , ...state } ) ;
263264 }
264265 addAction ( data : ActionCallbackData ) {
265- this . _addAction ( data ) ;
266+ // this._addAction(data);
266267
267- // this.addToExecutionQueue(()=> this._addAction(data))
268+ this . addToExecutionQueue ( ( ) => this . _addAction ( data ) ) ;
268269 }
269270 async _addAction ( data : ActionCallbackData ) {
270271 const { messageId } = data ;
@@ -280,7 +281,7 @@ export class WorkbenchStore {
280281
281282 runAction ( data : ActionCallbackData , isStreaming : boolean = false ) {
282283 if ( isStreaming ) {
283- this . _runAction ( data , isStreaming ) ;
284+ this . actionStreamSampler ( data , isStreaming ) ;
284285 } else {
285286 this . addToExecutionQueue ( ( ) => this . _runAction ( data , isStreaming ) ) ;
286287 }
@@ -294,6 +295,12 @@ export class WorkbenchStore {
294295 unreachable ( 'Artifact not found' ) ;
295296 }
296297
298+ const action = artifact . runner . actions . get ( ) [ data . actionId ] ;
299+
300+ if ( ! action || action . executed ) {
301+ return ;
302+ }
303+
297304 if ( data . action . type === 'file' ) {
298305 const wc = await webcontainer ;
299306 const fullPath = nodePath . join ( wc . workdir , data . action . filePath ) ;
@@ -323,6 +330,10 @@ export class WorkbenchStore {
323330 }
324331 }
325332
333+ actionStreamSampler = createSampler ( async ( data : ActionCallbackData , isStreaming : boolean = false ) => {
334+ return await this . _runAction ( data , isStreaming ) ;
335+ } , 100 ) ; // TODO: remove this magic number to have it configurable
336+
326337 #getArtifact( id : string ) {
327338 const artifacts = this . artifacts . get ( ) ;
328339 return artifacts [ id ] ;
0 commit comments