[Claimed #2019] fix(core): add FlowLogger parity for Microsoft CUA

Merged
GI
7mo ago
+153-0

Mirrored from external contributor PR #2019 after approval by @pirate.

Original author: @BABTUNA
Original PR: https://github.com/browserbase/stagehand/pull/2019
Approved source head SHA: 54b258b01fa9e29ea5e044f50c7dbe159364690b

@BABTUNA, please continue any follow-up discussion on this mirrored PR. When the external PR gets new commits, this same internal PR will be marked stale until the latest external commit is approved and refreshed here.

Original description

Title
fix(core): add FlowLogger parity for Microsoft CUA

Description

why

MicrosoftCUAClient was the only CUA provider not emitting FlowLogger LLM
request/response events.
OpenAI, Google, and Anthropic clients already emit these events, so
Microsoft CUA lacked observability parity.

what changed

  • Added FlowLogger imports and request/response logging to
    MicrosoftCUAClient:
    • FlowLogger.logLlmRequest(...) before the model call
    • FlowLogger.logLlmResponse(...) after a successful response
  • Added request ID correlation via uuidv7 so request/response pair
    correctly in logs.
  • Kept existing execution behavior unchanged (logging-only change).
  • Added unit tests for Microsoft CUA logging behavior:
    • emits request + response on success
    • emits only request when the model call fails

test plan

  • prettier --check on touched files
  • eslint on touched files
  • tsc -p packages/core/tsconfig.json --noEmit
  • Added unit test file:
    • packages/core/tests/unit/microsoft-cua-client.test.ts

Summary by cubic

Add LLM request/response logging to MicrosoftCUAClient to match other providers and improve observability. This brings Microsoft CUA to parity with OpenAI, Google, and Anthropic clients.

  • Bug Fixes
    • Emit FlowLogger.logLlmRequest before the model call and FlowLogger.logLlmResponse after success.
    • Correlate events with a requestId using uuid v7.
    • No behavior changes to execution; logging-only.
    • Added unit tests for success (request + response) and failure (request only).