Skip to content

Commit 8ec69f1

Browse files
sameelarifkamath
andauthored
history fixes (#613)
* fix actFromObserve history * Update lib/StagehandPage.ts Co-authored-by: Anirudh Kamath <github@kamath.io> --------- Co-authored-by: Anirudh Kamath <github@kamath.io>
1 parent 566e587 commit 8ec69f1

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/StagehandPage.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class StagehandPage {
5555
private _history: Array<HistoryEntry> = [];
5656

5757
public get history(): ReadonlyArray<HistoryEntry> {
58-
return this._history;
58+
return Object.freeze([...this._history]);
5959
}
6060

6161
constructor(
@@ -457,9 +457,14 @@ export class StagehandPage {
457457
}
458458
}
459459

460-
private addToHistory(
460+
public addToHistory(
461461
method: HistoryEntry["method"],
462-
parameters: unknown,
462+
parameters:
463+
| ActOptions
464+
| ExtractOptions<z.AnyZodObject>
465+
| ObserveOptions
466+
| { url: string; options: GotoOptions }
467+
| string,
463468
result?: unknown,
464469
): void {
465470
this._history.push({
@@ -543,13 +548,15 @@ export class StagehandPage {
543548
},
544549
});
545550

546-
// `useVision` is no longer passed to the handler
547-
return this.actHandler.observeAct(
551+
const result = await this.actHandler.observeAct(
548552
actionOrOptions,
549553
this.observeHandler,
550554
llmClient,
551555
requestId,
552556
);
557+
558+
this.addToHistory("act", actionOrOptions, result);
559+
return result;
553560
} catch (err: unknown) {
554561
if (err instanceof StagehandError || err instanceof StagehandAPIError) {
555562
throw err;

0 commit comments

Comments
 (0)