@@ -12,6 +12,8 @@ import {
1212} from "./prompt" ;
1313import { appendSummary , writeTimestampedTxtFile } from "./inferenceLogUtils" ;
1414import type { InferStagehandSchema , StagehandZodObject } from "./v3/zodCompat" ;
15+ import { createChatCompletionViaEventBus } from "./v3/llm/llmEventBridge" ;
16+ import type { StagehandEventBus } from "./v3/eventBus" ;
1517
1618// Re-export for backward compatibility
1719export type { LLMParsedResponse , LLMUsage } from "./v3/llm/LLMClient" ;
@@ -21,6 +23,7 @@ export async function extract<T extends StagehandZodObject>({
2123 domElements,
2224 schema,
2325 llmClient,
26+ eventBus,
2427 logger,
2528 userProvidedInstructions,
2629 logInferenceToFile = false ,
@@ -29,6 +32,7 @@ export async function extract<T extends StagehandZodObject>({
2932 domElements : string ;
3033 schema : T ;
3134 llmClient : LLMClient ;
35+ eventBus : StagehandEventBus ;
3236 userProvidedInstructions ?: string ;
3337 logger : ( message : LogLine ) => void ;
3438 logInferenceToFile ?: boolean ;
@@ -74,7 +78,7 @@ export async function extract<T extends StagehandZodObject>({
7478
7579 const extractStartTime = Date . now ( ) ;
7680 const extractionResponse =
77- await llmClient . createChatCompletion < ExtractionResponse > ( {
81+ await createChatCompletionViaEventBus < ExtractionResponse > ( eventBus , {
7882 options : {
7983 messages : extractCallMessages ,
8084 response_model : {
@@ -139,7 +143,7 @@ export async function extract<T extends StagehandZodObject>({
139143
140144 const metadataStartTime = Date . now ( ) ;
141145 const metadataResponse =
142- await llmClient . createChatCompletion < MetadataResponse > ( {
146+ await createChatCompletionViaEventBus < MetadataResponse > ( eventBus , {
143147 options : {
144148 messages : metadataCallMessages ,
145149 response_model : {
@@ -224,13 +228,15 @@ export async function observe({
224228 instruction,
225229 domElements,
226230 llmClient,
231+ eventBus,
227232 userProvidedInstructions,
228233 logger,
229234 logInferenceToFile = false ,
230235} : {
231236 instruction : string ;
232237 domElements : string ;
233238 llmClient : LLMClient ;
239+ eventBus : StagehandEventBus ;
234240 userProvidedInstructions ?: string ;
235241 logger : ( message : LogLine ) => void ;
236242 logInferenceToFile ?: boolean ;
@@ -291,20 +297,23 @@ export async function observe({
291297 }
292298
293299 const start = Date . now ( ) ;
294- const rawResponse = await llmClient . createChatCompletion < ObserveResponse > ( {
295- options : {
296- messages,
297- response_model : {
298- schema : observeSchema ,
299- name : "Observation" ,
300+ const rawResponse = await createChatCompletionViaEventBus < ObserveResponse > (
301+ eventBus ,
302+ {
303+ options : {
304+ messages,
305+ response_model : {
306+ schema : observeSchema ,
307+ name : "Observation" ,
308+ } ,
309+ temperature : isGPT5 ? 1 : 0.1 ,
310+ top_p : 1 ,
311+ frequency_penalty : 0 ,
312+ presence_penalty : 0 ,
300313 } ,
301- temperature : isGPT5 ? 1 : 0.1 ,
302- top_p : 1 ,
303- frequency_penalty : 0 ,
304- presence_penalty : 0 ,
314+ logger,
305315 } ,
306- logger,
307- } ) ;
316+ ) ;
308317 const end = Date . now ( ) ;
309318 const usageTimeMs = end - start ;
310319
@@ -364,13 +373,15 @@ export async function act({
364373 instruction,
365374 domElements,
366375 llmClient,
376+ eventBus,
367377 userProvidedInstructions,
368378 logger,
369379 logInferenceToFile = false ,
370380} : {
371381 instruction : string ;
372382 domElements : string ;
373383 llmClient : LLMClient ;
384+ eventBus : StagehandEventBus ;
374385 userProvidedInstructions ?: string ;
375386 logger : ( message : LogLine ) => void ;
376387 logInferenceToFile ?: boolean ;
0 commit comments