@@ -944,14 +944,20 @@ export class Stagehand {
944
944
// Otherwise treat as a local path if provided as string (kept for compatibility)
945
945
return f ;
946
946
}
947
- if ( f ?. path ) return f . path ;
948
- if ( f ?. buffer && f ?. name && f ?. mimeType ) {
947
+
948
+ // Handle discriminated union types
949
+ if ( 'path' in f && f . path ) {
950
+ return f . path ;
951
+ }
952
+
953
+ if ( 'buffer' in f && 'name' in f && 'mimeType' in f && f . buffer && f . name && f . mimeType ) {
949
954
return { name : f . name , mimeType : f . mimeType , buffer : f . buffer } as {
950
955
name : string ;
951
956
mimeType : string ;
952
957
buffer : Buffer ;
953
958
} ;
954
959
}
960
+
955
961
throw new StagehandError (
956
962
"Invalid FileSpec. Provide an http(s) URL, a path, or { buffer, name, mimeType }" ,
957
963
) ;
@@ -981,12 +987,10 @@ export class Stagehand {
981
987
( el ) : boolean => {
982
988
const tagName = el . tagName . toLowerCase ( ) ;
983
989
const type = ( el as HTMLInputElement ) . type ;
984
- console . log ( `DEBUG: Element tagName=${ tagName } , type=${ type } ` ) ;
985
990
return tagName === "input" && type === "file" ;
986
991
} ,
987
992
)
988
- . catch ( ( e ) => {
989
- console . log ( `DEBUG: evaluate failed:` , e ) ;
993
+ . catch ( ( ) => {
990
994
return false ;
991
995
} ) ;
992
996
@@ -1003,7 +1007,7 @@ export class Stagehand {
1003
1007
? new URL ( file ) . pathname . split ( "/" ) . pop ( ) || undefined
1004
1008
: typeof file === "string"
1005
1009
? file . split ( "/" ) . pop ( )
1006
- : file ? .name ,
1010
+ : ( 'name' in file ? file . name : undefined ) ,
1007
1011
message : "File attached via direct input" ,
1008
1012
} ) ;
1009
1013
}
@@ -1030,7 +1034,7 @@ export class Stagehand {
1030
1034
? new URL ( file ) . pathname . split ( "/" ) . pop ( ) || undefined
1031
1035
: typeof file === "string"
1032
1036
? file . split ( "/" ) . pop ( )
1033
- : file ? .name ,
1037
+ : ( 'name' in file ? file . name : undefined ) ,
1034
1038
message : "File attached via file chooser" ,
1035
1039
} ) ;
1036
1040
}
@@ -1101,7 +1105,7 @@ export class Stagehand {
1101
1105
? new URL ( file ) . pathname . split ( "/" ) . pop ( ) || undefined
1102
1106
: typeof file === "string"
1103
1107
? file . split ( "/" ) . pop ( )
1104
- : file ? .name ,
1108
+ : ( 'name' in file ? file . name : undefined ) ,
1105
1109
message : "File attached via heuristic input lookup" ,
1106
1110
} ) ;
1107
1111
}
0 commit comments