@@ -252,7 +252,8 @@ import {
252252 setActivePreviewTab ,
253253 useThreadPreviewState ,
254254} from "../previewStateStore" ;
255- import { BrowserSettingsReadError } from "../browser/openFileInPreview" ;
255+ import { BrowserSettingsReadError , openUrlInPreview } from "../browser/openFileInPreview" ;
256+ import { resolveDiscoveredServerUrl } from "../browser/browserTargetResolver" ;
256257import { previewRuntimeTabId } from "../browser/previewRuntimeTabId" ;
257258import { addBrowserSurface } from "./preview/addBrowserSurface" ;
258259import { closePreviewSession } from "./preview/closePreviewSession" ;
@@ -4892,12 +4893,32 @@ export default function ChatView(props: ChatViewProps) {
48924893 data : `${ script . command } \r` ,
48934894 } ,
48944895 } ) ;
4895- if ( writeResult . _tag === "Failure" && ! isAtomCommandInterrupted ( writeResult ) ) {
4896- const error = squashAtomCommandFailure ( writeResult ) ;
4897- setThreadError (
4898- activeThreadId ,
4899- error instanceof Error ? error . message : `Failed to run script "${ script . name } ".` ,
4900- ) ;
4896+ if ( writeResult . _tag === "Failure" ) {
4897+ if ( ! isAtomCommandInterrupted ( writeResult ) ) {
4898+ const error = squashAtomCommandFailure ( writeResult ) ;
4899+ setThreadError (
4900+ activeThreadId ,
4901+ error instanceof Error ? error . message : `Failed to run script "${ script . name } ".` ,
4902+ ) ;
4903+ }
4904+ return ;
4905+ }
4906+ if ( script . autoOpenPreview && script . previewUrl && isPreviewSupportedInRuntime ( ) ) {
4907+ const previewResult = await openUrlInPreview ( {
4908+ threadRef : activeThreadRef ,
4909+ url : resolveDiscoveredServerUrl ( activeThreadRef . environmentId , script . previewUrl ) ,
4910+ openPreview,
4911+ } ) ;
4912+ if ( previewResult . _tag === "Failure" && ! isAtomCommandInterrupted ( previewResult ) ) {
4913+ const error = squashAtomCommandFailure ( previewResult ) ;
4914+ toastManager . add (
4915+ stackedThreadToast ( {
4916+ type : "error" ,
4917+ title : "Could not open preview" ,
4918+ description : error instanceof Error ? error . message : "An unexpected error occurred." ,
4919+ } ) ,
4920+ ) ;
4921+ }
49014922 }
49024923 } ,
49034924 [
@@ -4913,6 +4934,7 @@ export default function ChatView(props: ChatViewProps) {
49134934 setLastInvokedScriptByProjectId ,
49144935 environmentId ,
49154936 openTerminal ,
4937+ openPreview ,
49164938 activeKnownTerminalIds ,
49174939 allocatableActiveTerminalIds ,
49184940 runningTerminalIds ,
0 commit comments