@@ -3,23 +3,30 @@ import type { AppleToolHost } from '@agent-device/contracts/platform';
33export function createAppleToolHost ( ) : AppleToolHost {
44 return Object . freeze ( {
55 isXcrunAvailable : async ( signal ?: AbortSignal ) => {
6- signal ?. throwIfAborted ( ) ;
7- const { resolveAppleToolProvider } = await import ( './platforms/apple/core/tool-provider.ts' ) ;
8- signal ?. throwIfAborted ( ) ;
9- const available = await resolveAppleToolProvider ( ) . whichCommand ( 'xcrun' ) ;
10- signal ?. throwIfAborted ( ) ;
6+ const { resolveAppleToolProvider } = await awaitPreservingAbortReason (
7+ async ( ) => await import ( './platforms/apple/core/tool-provider.ts' ) ,
8+ signal ,
9+ ) ;
10+ const available = await awaitPreservingAbortReason (
11+ async ( ) => await resolveAppleToolProvider ( ) . whichCommand ( 'xcrun' ) ,
12+ signal ,
13+ ) ;
1114 return available ;
1215 } ,
1316 run : async ( request , signal ) => {
14- signal ?. throwIfAborted ( ) ;
15- const { runXcrun } = await import ( './platforms/apple/core/tool-provider.ts' ) ;
16- signal ?. throwIfAborted ( ) ;
17- const result = await runXcrun ( [ request . tool , ...request . args ] , {
18- allowFailure : request . allowFailure ,
17+ const { runXcrun } = await awaitPreservingAbortReason (
18+ async ( ) => await import ( './platforms/apple/core/tool-provider.ts' ) ,
19+ signal ,
20+ ) ;
21+ const result = await awaitPreservingAbortReason (
22+ async ( ) =>
23+ await runXcrun ( [ request . tool , ...request . args ] , {
24+ allowFailure : request . allowFailure ,
25+ signal,
26+ timeoutMs : request . timeoutMs ,
27+ } ) ,
1928 signal ,
20- timeoutMs : request . timeoutMs ,
21- } ) ;
22- signal ?. throwIfAborted ( ) ;
29+ ) ;
2330 return {
2431 stdout : result . stdout ,
2532 stderr : result . stderr ,
@@ -28,3 +35,18 @@ export function createAppleToolHost(): AppleToolHost {
2835 } ,
2936 } ) ;
3037}
38+
39+ async function awaitPreservingAbortReason < T > (
40+ operation : ( ) => Promise < T > ,
41+ signal ?: AbortSignal ,
42+ ) : Promise < T > {
43+ signal ?. throwIfAborted ( ) ;
44+ try {
45+ const result = await operation ( ) ;
46+ signal ?. throwIfAborted ( ) ;
47+ return result ;
48+ } catch ( error ) {
49+ signal ?. throwIfAborted ( ) ;
50+ throw error ;
51+ }
52+ }
0 commit comments