Skip to content

Commit 0ff9eb5

Browse files
committed
greptile comment fixes
1 parent 318aef5 commit 0ff9eb5

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

lib/index.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -944,14 +944,20 @@ export class Stagehand {
944944
// Otherwise treat as a local path if provided as string (kept for compatibility)
945945
return f;
946946
}
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) {
949954
return { name: f.name, mimeType: f.mimeType, buffer: f.buffer } as {
950955
name: string;
951956
mimeType: string;
952957
buffer: Buffer;
953958
};
954959
}
960+
955961
throw new StagehandError(
956962
"Invalid FileSpec. Provide an http(s) URL, a path, or { buffer, name, mimeType }",
957963
);
@@ -981,12 +987,10 @@ export class Stagehand {
981987
(el): boolean => {
982988
const tagName = el.tagName.toLowerCase();
983989
const type = (el as HTMLInputElement).type;
984-
console.log(`DEBUG: Element tagName=${tagName}, type=${type}`);
985990
return tagName === "input" && type === "file";
986991
},
987992
)
988-
.catch((e) => {
989-
console.log(`DEBUG: evaluate failed:`, e);
993+
.catch(() => {
990994
return false;
991995
});
992996

@@ -1003,7 +1007,7 @@ export class Stagehand {
10031007
? new URL(file).pathname.split("/").pop() || undefined
10041008
: typeof file === "string"
10051009
? file.split("/").pop()
1006-
: file?.name,
1010+
: ('name' in file ? file.name : undefined),
10071011
message: "File attached via direct input",
10081012
});
10091013
}
@@ -1030,7 +1034,7 @@ export class Stagehand {
10301034
? new URL(file).pathname.split("/").pop() || undefined
10311035
: typeof file === "string"
10321036
? file.split("/").pop()
1033-
: file?.name,
1037+
: ('name' in file ? file.name : undefined),
10341038
message: "File attached via file chooser",
10351039
});
10361040
}
@@ -1101,7 +1105,7 @@ export class Stagehand {
11011105
? new URL(file).pathname.split("/").pop() || undefined
11021106
: typeof file === "string"
11031107
? file.split("/").pop()
1104-
: file?.name,
1108+
: ('name' in file ? file.name : undefined),
11051109
message: "File attached via heuristic input lookup",
11061110
});
11071111
}

lib/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"version": "2.4.1",
44
"private": true,
55
"description": "Core Stagehand library sources",
6-
"main": "./index.js",
7-
"module": "./index.js",
8-
"types": "./index.d.ts",
6+
"main": "../dist/index.js",
7+
"module": "../dist/index.js",
8+
"types": "../dist/index.d.ts",
99
"scripts": {
1010
"build-dom-scripts": "tsx dom/genDomScripts.ts",
1111
"build-js": "tsup index.ts --dts",

types/stagehand.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,15 @@ export type FileSpec =
299299
| string
300300
| {
301301
/** Absolute path on disk to the file. */
302-
path?: string;
302+
path: string;
303+
}
304+
| {
303305
/** Name to use for the file (required if using buffer). */
304-
name?: string;
306+
name: string;
305307
/** MIME type for the file (required if using buffer). */
306-
mimeType?: string;
308+
mimeType: string;
307309
/** Raw file bytes (requires name + mimeType). */
308-
buffer?: Buffer;
310+
buffer: Buffer;
309311
};
310312

311313
export interface UploadResult {

0 commit comments

Comments
 (0)