@@ -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" ;
@@ -4890,12 +4891,32 @@ export default function ChatView(props: ChatViewProps) {
48904891 data : `${ script . command } \r` ,
48914892 } ,
48924893 } ) ;
4893- if ( writeResult . _tag === "Failure" && ! isAtomCommandInterrupted ( writeResult ) ) {
4894- const error = squashAtomCommandFailure ( writeResult ) ;
4895- setThreadError (
4896- activeThreadId ,
4897- error instanceof Error ? error . message : `Failed to run script "${ script . name } ".` ,
4898- ) ;
4894+ if ( writeResult . _tag === "Failure" ) {
4895+ if ( ! isAtomCommandInterrupted ( writeResult ) ) {
4896+ const error = squashAtomCommandFailure ( writeResult ) ;
4897+ setThreadError (
4898+ activeThreadId ,
4899+ error instanceof Error ? error . message : `Failed to run script "${ script . name } ".` ,
4900+ ) ;
4901+ }
4902+ return ;
4903+ }
4904+ if ( script . autoOpenPreview && script . previewUrl && isPreviewSupportedInRuntime ( ) ) {
4905+ const previewResult = await openUrlInPreview ( {
4906+ threadRef : activeThreadRef ,
4907+ url : resolveDiscoveredServerUrl ( activeThreadRef . environmentId , script . previewUrl ) ,
4908+ openPreview,
4909+ } ) ;
4910+ if ( previewResult . _tag === "Failure" && ! isAtomCommandInterrupted ( previewResult ) ) {
4911+ const error = squashAtomCommandFailure ( previewResult ) ;
4912+ toastManager . add (
4913+ stackedThreadToast ( {
4914+ type : "error" ,
4915+ title : "Could not open preview" ,
4916+ description : error instanceof Error ? error . message : "An unexpected error occurred." ,
4917+ } ) ,
4918+ ) ;
4919+ }
48994920 }
49004921 } ,
49014922 [
@@ -4911,6 +4932,7 @@ export default function ChatView(props: ChatViewProps) {
49114932 setLastInvokedScriptByProjectId ,
49124933 environmentId ,
49134934 openTerminal ,
4935+ openPreview ,
49144936 activeKnownTerminalIds ,
49154937 allocatableActiveTerminalIds ,
49164938 runningTerminalIds ,
0 commit comments