1- import type { generateCore } from "@/core" ;
2- import { generateBuilderManager } from "@/builder/builderManager" ;
31import { computed , readonly , Ref , ref , unref } from "vue" ;
42import { useWriterTracking } from "./useWriterTracking" ;
3+ import type { BuilderManager , Core } from "@/writerTypes" ;
4+ import { inject } from "vue" ;
5+ import injectionKeys from "@/injectionKeys" ;
56
67interface RunBlueprintResponse {
78 ok : boolean ;
@@ -19,7 +20,7 @@ interface RunBlueprintResponse {
1920}
2021
2122function runBlueprint (
22- wf : ReturnType < typeof generateCore > ,
23+ wf : Core ,
2324 blueprintComponentId : string ,
2425 branchId ?: string ,
2526) {
@@ -44,27 +45,21 @@ function runBlueprint(
4445 }
4546
4647 wf . forwardEvent (
47- branchId ?
48- new CustomEvent (
49- "wf-run-blueprint-branch" ,
50- {
51- detail : {
52- callback,
53- handler : "run_blueprint_branch" ,
54- payload : { "branch_id" : branchId }
55- } ,
56- }
57- ) :
58- new CustomEvent (
59- "wf-run-blueprint" ,
60- {
61- detail : {
62- callback,
63- handler : "run_blueprint_by_id" ,
64- payload : { blueprint_id : blueprintComponentId } ,
65- } ,
66- }
67- ) ,
48+ branchId
49+ ? new CustomEvent ( "wf-run-blueprint-branch" , {
50+ detail : {
51+ callback,
52+ handler : "run_blueprint_branch" ,
53+ payload : { branch_id : branchId } ,
54+ } ,
55+ } )
56+ : new CustomEvent ( "wf-run-blueprint" , {
57+ detail : {
58+ callback,
59+ handler : "run_blueprint_by_id" ,
60+ payload : { blueprint_id : blueprintComponentId } ,
61+ } ,
62+ } ) ,
6863 null ,
6964 true ,
7065 ) . catch ( ( err ) => {
@@ -74,10 +69,7 @@ function runBlueprint(
7469 } ) ;
7570}
7671
77- function stopBlueprintRun (
78- wf : ReturnType < typeof generateCore > ,
79- runId : string ,
80- ) {
72+ function stopBlueprintRun ( wf : Core , runId : string ) {
8173 return new Promise < void > ( ( res , rej ) => {
8274 const tracking = useWriterTracking ( wf ) ;
8375 tracking . track ( "blueprints_run_stopped" ) ;
@@ -86,23 +78,25 @@ function stopBlueprintRun(
8678 new CustomEvent ( "wf-stop-blueprint" , {
8779 detail : {
8880 handler : "stop_blueprint_run" ,
89- payload : { run_id : runId } ,
81+ payload : { run_id : runId } ,
9082 } ,
9183 } ) ,
9284 null ,
9385 true ,
9486 )
9587 . then ( ( ) => res ( ) )
9688 . catch ( ( err ) => {
97- tracking . track ( "blueprints_run_stop_failed" , { error : String ( err ) } ) ;
89+ tracking . track ( "blueprints_run_stop_failed" , {
90+ error : String ( err ) ,
91+ } ) ;
9892 rej ( err ) ;
9993 } ) ;
10094 } ) ;
10195}
10296
10397export function useBlueprintRun (
104- wf : ReturnType < typeof generateCore > ,
105- wfbm : ReturnType < typeof generateBuilderManager > ,
98+ wf : Core ,
99+ wfbm : BuilderManager ,
106100 blueprintComponentId : string | Ref < string > ,
107101) {
108102 const isRunning = ref ( false ) ;
@@ -119,7 +113,7 @@ export function useBlueprintRun(
119113
120114 async function stop ( ) {
121115 const activeRunId = wfbm . activeBlueprintRunId . value ;
122- if ( ! activeRunId ) return ;
116+ if ( ! activeRunId ) return ;
123117 await stopBlueprintRun ( wf , activeRunId ) ;
124118 }
125119
@@ -130,10 +124,11 @@ export type BlueprintsRunListItem = { blueprintId: string; branchId: string };
130124type MaybeRef < T > = T | Ref < T > ;
131125
132126export function useBlueprintsRun (
133- wf : ReturnType < typeof generateCore > ,
127+ wf : Core ,
134128 blueprintComponentIds : MaybeRef < BlueprintsRunListItem [ ] > ,
135129) {
136130 const runningBlueprintIds = ref < string [ ] > ( [ ] ) ;
131+ const socketTimeout = inject ( injectionKeys . socketTimeout ) ;
137132
138133 async function handleRunBlueprint ( {
139134 blueprintId,
@@ -142,6 +137,7 @@ export function useBlueprintsRun(
142137 if ( runningBlueprintIds . value . includes ( blueprintId ) ) return ;
143138
144139 try {
140+ if ( socketTimeout ) socketTimeout . prevent . value = true ;
145141 runningBlueprintIds . value = [
146142 blueprintId ,
147143 ...runningBlueprintIds . value ,
@@ -151,6 +147,7 @@ export function useBlueprintsRun(
151147 runningBlueprintIds . value = runningBlueprintIds . value . filter (
152148 ( id ) => id !== blueprintId ,
153149 ) ;
150+ if ( socketTimeout ) socketTimeout . prevent . value = false ;
154151 }
155152 }
156153 async function run ( ) {
0 commit comments