Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tidy-pants-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@browserbasehq/stagehand": patch
---

Update logging
13 changes: 13 additions & 0 deletions packages/core/lib/v3/handlers/actHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export class ActHandler {

const llmClient = this.resolveLlmClient(model);

v3Logger({
category: "action",
message: `[act] ${instruction}`,
level: 1,
});

const doObserveAndAct = async (): Promise<ActResult> => {
await waitForDomNetworkQuiet(
page.mainFrame(),
Expand Down Expand Up @@ -325,6 +331,13 @@ export class ActHandler {
): Promise<ActResult> {
const settleTimeout = domSettleTimeoutMs ?? this.defaultDomSettleTimeoutMs;
const effectiveClient = llmClientOverride ?? this.llmClient;

v3Logger({
category: "action",
message: `[act] ${action.description}`,
level: 1,
});

const method = action.method?.trim();
if (!method || method === "not-supported") {
v3Logger({
Expand Down
5 changes: 1 addition & 4 deletions packages/core/lib/v3/handlers/extractHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,8 @@ export class ExtractHandler {

v3Logger({
category: "extraction",
message: "Starting extraction using a11y snapshot",
message: instruction ? `[extract] ${instruction}` : "[extract] Extracting page text",
level: 1,
auxiliary: instruction
? { instruction: { value: instruction, type: "string" } }
: undefined,
});

// Normalize schema: if instruction provided without schema, use defaultExtractSchema
Expand Down
13 changes: 5 additions & 8 deletions packages/core/lib/v3/handlers/handlerUtils/actHandlerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export async function performUnderstudyMethod(
}
}

await handlePossibleNavigation("action", selectorRaw, initialUrl, frame);
await handlePossibleNavigation(initialUrl, frame);
} catch (e) {
const msg = e instanceof Error ? e.message : String(e);
const stack = e instanceof Error ? e.stack : undefined;
Expand Down Expand Up @@ -608,7 +608,7 @@ export async function waitForDomNetworkQuiet(
v3Logger({
category: "dom",
message: "⏳ forcing completion of stalled iframe document",
level: 1,
level: 2,
auxiliary: {
url: { value: (m.url ?? "").slice(0, 120), type: "string" },
},
Expand Down Expand Up @@ -651,16 +651,13 @@ export async function waitForDomNetworkQuiet(
}

async function handlePossibleNavigation(
actionDescription: string,
xpath: string,
initialUrl: string,
frame: Frame,
): Promise<void> {
v3Logger({
category: "action",
message: `${actionDescription}, checking for page navigation`,
message: `checking for page navigation`,
level: 1,
auxiliary: { xpath: { value: xpath, type: "string" } },
});

// We only have a frame-scoped session, so detect navigation by URL change.
Expand All @@ -670,14 +667,14 @@ async function handlePossibleNavigation(
v3Logger({
category: "action",
message: "new page (frame) URL detected",
level: 1,
level: 2,
auxiliary: { url: { value: afterUrl, type: "string" } },
});
} else {
v3Logger({
category: "action",
message: "no new (frame) URL detected",
level: 1,
level: 2,
auxiliary: { url: { value: afterUrl, type: "string" } },
});
}
Expand Down
8 changes: 1 addition & 7 deletions packages/core/lib/v3/handlers/observeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,8 @@ export class ObserveHandler {
const doObserve = async (): Promise<Action[]> => {
v3Logger({
category: "observation",
message: "starting observation",
message: `[observe] ${effectiveInstruction}`,
level: 1,
auxiliary: {
instruction: {
value: effectiveInstruction,
type: "string",
},
},
});

// Build the hybrid snapshot (a11y-centric text tree + lookup maps)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/v3/llm/aisdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class AISdkClient extends LLMClient {
this.logger?.({
category: "aisdk",
message: "response",
level: 1,
level: 2,
auxiliary: {
response: {
value: JSON.stringify({
Expand Down
Loading