@browserbasehq/orca 3.2.0-preview.2 → 3.2.0-preview.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/cjs/lib/utils.d.ts +0 -1
  2. package/dist/cjs/lib/utils.js +0 -4
  3. package/dist/cjs/lib/utils.js.map +1 -1
  4. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js +6 -4
  5. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
  6. package/dist/cjs/lib/v3/agent/GoogleCUAClient.js +6 -4
  7. package/dist/cjs/lib/v3/agent/GoogleCUAClient.js.map +1 -1
  8. package/dist/cjs/lib/v3/agent/OpenAICUAClient.js +6 -4
  9. package/dist/cjs/lib/v3/agent/OpenAICUAClient.js.map +1 -1
  10. package/dist/cjs/lib/v3/flowLogger.d.ts +103 -62
  11. package/dist/cjs/lib/v3/flowLogger.js +773 -362
  12. package/dist/cjs/lib/v3/flowLogger.js.map +1 -1
  13. package/dist/cjs/lib/v3/handlers/handlerUtils/actHandlerUtils.js +33 -21
  14. package/dist/cjs/lib/v3/handlers/handlerUtils/actHandlerUtils.js.map +1 -1
  15. package/dist/cjs/lib/v3/handlers/v3AgentHandler.d.ts +4 -0
  16. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js +31 -1
  17. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  18. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js +12 -10
  19. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
  20. package/dist/cjs/lib/v3/llm/aisdk.js +16 -10
  21. package/dist/cjs/lib/v3/llm/aisdk.js.map +1 -1
  22. package/dist/cjs/lib/v3/types/public/options.d.ts +0 -5
  23. package/dist/cjs/lib/v3/types/public/options.js.map +1 -1
  24. package/dist/cjs/lib/v3/understudy/cdp.d.ts +12 -3
  25. package/dist/cjs/lib/v3/understudy/cdp.js +10 -83
  26. package/dist/cjs/lib/v3/understudy/cdp.js.map +1 -1
  27. package/dist/cjs/lib/v3/understudy/page.js +17 -32
  28. package/dist/cjs/lib/v3/understudy/page.js.map +1 -1
  29. package/dist/cjs/lib/v3/v3.d.ts +0 -5
  30. package/dist/cjs/lib/v3/v3.js +157 -174
  31. package/dist/cjs/lib/v3/v3.js.map +1 -1
  32. package/dist/esm/lib/utils.d.ts +0 -1
  33. package/dist/esm/lib/utils.js +0 -3
  34. package/dist/esm/lib/utils.js.map +1 -1
  35. package/dist/esm/lib/v3/agent/AnthropicCUAClient.js +7 -5
  36. package/dist/esm/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
  37. package/dist/esm/lib/v3/agent/GoogleCUAClient.js +7 -5
  38. package/dist/esm/lib/v3/agent/GoogleCUAClient.js.map +1 -1
  39. package/dist/esm/lib/v3/agent/OpenAICUAClient.js +7 -5
  40. package/dist/esm/lib/v3/agent/OpenAICUAClient.js.map +1 -1
  41. package/dist/esm/lib/v3/flowLogger.d.ts +103 -62
  42. package/dist/esm/lib/v3/flowLogger.js +762 -356
  43. package/dist/esm/lib/v3/flowLogger.js.map +1 -1
  44. package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js +34 -22
  45. package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js.map +1 -1
  46. package/dist/esm/lib/v3/handlers/v3AgentHandler.d.ts +4 -0
  47. package/dist/esm/lib/v3/handlers/v3AgentHandler.js +32 -2
  48. package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  49. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js +13 -11
  50. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
  51. package/dist/esm/lib/v3/llm/aisdk.js +17 -11
  52. package/dist/esm/lib/v3/llm/aisdk.js.map +1 -1
  53. package/dist/esm/lib/v3/types/public/options.d.ts +0 -5
  54. package/dist/esm/lib/v3/types/public/options.js.map +1 -1
  55. package/dist/esm/lib/v3/understudy/cdp.d.ts +12 -3
  56. package/dist/esm/lib/v3/understudy/cdp.js +10 -83
  57. package/dist/esm/lib/v3/understudy/cdp.js.map +1 -1
  58. package/dist/esm/lib/v3/understudy/page.js +18 -33
  59. package/dist/esm/lib/v3/understudy/page.js.map +1 -1
  60. package/dist/esm/lib/v3/v3.d.ts +0 -5
  61. package/dist/esm/lib/v3/v3.js +158 -175
  62. package/dist/esm/lib/v3/v3.js.map +1 -1
  63. package/package.json +1 -1
  64. package/dist/cjs/lib/v3/eventStore.d.ts +0 -41
  65. package/dist/cjs/lib/v3/eventStore.js +0 -375
  66. package/dist/cjs/lib/v3/eventStore.js.map +0 -1
  67. package/dist/esm/lib/v3/eventStore.d.ts +0 -41
  68. package/dist/esm/lib/v3/eventStore.js +0 -363
  69. package/dist/esm/lib/v3/eventStore.js.map +0 -1
@@ -1,76 +1,124 @@
1
- import { EventEmitter } from "node:events";
1
+ import fs from "node:fs";
2
+ import pino from "pino";
2
3
  import type { LanguageModelMiddleware } from "ai";
3
- export type FlowEventData = Record<string, unknown>;
4
- export type FlowEventInput = Omit<FlowEvent, "eventId" | "createdAt" | "sessionId" | "eventParentIds" | "data"> & {
5
- eventId?: string;
6
- eventIdSuffix?: string;
7
- createdAt?: string;
8
- sessionId?: string;
9
- eventParentIds?: string[];
10
- data?: FlowEventData;
11
- };
12
- export declare class FlowEvent {
13
- static createEventId(eventIdSuffix: string): string;
14
- eventType: string;
15
- eventId: string;
16
- eventParentIds: string[];
17
- createdAt: string;
18
- sessionId: string;
19
- data: FlowEventData;
20
- constructor(input: FlowEventInput);
4
+ import type { V3Options } from "./types/public/index.js";
5
+ interface FlowLoggerMetrics {
6
+ taskStartTime?: number;
7
+ stepStartTime?: number;
8
+ actionStartTime?: number;
9
+ llmRequests: number;
10
+ llmInputTokens: number;
11
+ llmOutputTokens: number;
12
+ cdpEvents: number;
21
13
  }
22
14
  export interface FlowLoggerContext {
15
+ logger: pino.Logger;
16
+ metrics: FlowLoggerMetrics;
23
17
  sessionId: string;
24
- eventBus: EventEmitter;
25
- parentEvents: FlowEvent[];
18
+ sessionDir: string;
19
+ configDir: string;
20
+ initPromise: Promise<void>;
21
+ initialized: boolean;
22
+ taskId: string | null;
23
+ stepId: string | null;
24
+ stepLabel: string | null;
25
+ actionId: string | null;
26
+ actionLabel: string | null;
27
+ fileStreams: {
28
+ agent: fs.WriteStream | null;
29
+ stagehand: fs.WriteStream | null;
30
+ understudy: fs.WriteStream | null;
31
+ cdp: fs.WriteStream | null;
32
+ llm: fs.WriteStream | null;
33
+ jsonl: fs.WriteStream | null;
34
+ };
26
35
  }
27
- type AsyncOriginalMethod<TArgs extends unknown[] = unknown[], TResult = unknown, TThis = unknown> = (this: TThis, ...args: TArgs) => Promise<TResult>;
28
- type FlowLoggerLogOptions = FlowEventInput & {
29
- context?: FlowLoggerContext;
30
- };
31
- export declare class FlowLogger {
32
- private static cloneContext;
33
- private static emit;
34
- private static runWithAutoStatusEventLogging;
36
+ /**
37
+ * Get the config directory. Returns empty string if logging is disabled.
38
+ */
39
+ export declare function getConfigDir(): string;
40
+ /**
41
+ * Format a prompt preview from LLM messages for logging.
42
+ * Returns format like: "some text... +{5.8kb image} +{schema} +{12 tools}"
43
+ */
44
+ export declare function formatLlmPromptPreview(messages: Array<{
45
+ role: string;
46
+ content: unknown;
47
+ }>, options?: {
48
+ toolCount?: number;
49
+ hasSchema?: boolean;
50
+ }): string | undefined;
51
+ /**
52
+ * Extract a text preview from CUA-style messages.
53
+ * Accepts various message formats (Anthropic, OpenAI, Google).
54
+ */
55
+ export declare function formatCuaPromptPreview(messages: unknown[], maxLen?: number): string | undefined;
56
+ /** Format CUA response output for logging */
57
+ export declare function formatCuaResponsePreview(output: unknown, maxLen?: number): string;
58
+ export declare class SessionFileLogger {
35
59
  /**
36
60
  * Initialize a new logging context. Call this at the start of a session.
61
+ * If BROWSERBASE_CONFIG_DIR is not set, logging is disabled.
62
+ */
63
+ static init(sessionId: string, v3Options?: V3Options): void;
64
+ private static initAsync;
65
+ static close(): Promise<void>;
66
+ static get sessionId(): string | null;
67
+ static get sessionDir(): string | null;
68
+ /**
69
+ * Get the current logger context object.
70
+ */
71
+ static getContext(): FlowLoggerContext | null;
72
+ /**
73
+ * Start a new task and log it.
37
74
  */
38
- static init(sessionId: string, eventBus: EventEmitter): FlowLoggerContext;
39
- static close(context?: FlowLoggerContext | null): Promise<void>;
40
- static get currentContext(): FlowLoggerContext;
41
- static wrapWithLogging<TMethod extends AsyncOriginalMethod>(options: FlowLoggerLogOptions): <TWrappedMethod extends AsyncOriginalMethod<Parameters<TMethod>, Awaited<ReturnType<TMethod>>, ThisParameterType<TMethod>>>(originalMethod: TWrappedMethod) => TWrappedMethod;
42
- static runWithLogging<TMethod extends AsyncOriginalMethod>(options: FlowLoggerLogOptions, originalMethod: TMethod, params: Readonly<Parameters<TMethod>>): Promise<Awaited<ReturnType<TMethod>>>;
43
- static runWithLogging<TResult>(options: FlowLoggerLogOptions, originalMethod: AsyncOriginalMethod<[], TResult>, params: ReadonlyArray<unknown>): Promise<Awaited<TResult>>;
44
- private static readonly NOISY_CDP_EVENTS;
75
+ static logAgentTaskStarted({ invocation, args, }: {
76
+ invocation: string;
77
+ args?: unknown | unknown[];
78
+ }): void;
79
+ /**
80
+ * Log task completion with metrics summary.
81
+ */
82
+ static logAgentTaskCompleted(options?: {
83
+ cacheHit?: boolean;
84
+ }): void;
85
+ static logStagehandStepEvent({ invocation, args, label, }: {
86
+ invocation: string;
87
+ args?: unknown | unknown[];
88
+ label: string;
89
+ }): string;
90
+ static logStagehandStepCompleted(): void;
91
+ static logUnderstudyActionEvent({ actionType, target, args, }: {
92
+ actionType: string;
93
+ target?: string;
94
+ args?: unknown | unknown[];
95
+ }): string;
96
+ static logUnderstudyActionCompleted(): void;
45
97
  private static logCdpEvent;
46
- static logCdpCallEvent(context: FlowLoggerContext, data: {
98
+ static logCdpCallEvent(data: {
47
99
  method: string;
48
100
  params?: object;
49
101
  targetId?: string | null;
50
- }): FlowEvent | null;
51
- static logCdpResponseEvent(context: FlowLoggerContext, parentEvent: Pick<FlowEvent, "eventId" | "eventParentIds">, data: {
52
- method: string;
53
- result?: unknown;
54
- error?: string;
55
- targetId?: string | null;
56
- }): void;
57
- static logCdpMessageEvent(context: FlowLoggerContext, parentEvent: Pick<FlowEvent, "eventId" | "eventParentIds">, data: {
102
+ }, ctx?: FlowLoggerContext | null): void;
103
+ static logCdpMessageEvent(data: {
58
104
  method: string;
59
105
  params?: unknown;
60
106
  targetId?: string | null;
61
- }): void;
107
+ }, ctx?: FlowLoggerContext | null): void;
62
108
  static logLlmRequest({ requestId, model, prompt, }: {
63
109
  requestId: string;
64
110
  model: string;
111
+ operation: string;
65
112
  prompt?: string;
66
- }): void;
113
+ }, explicitCtx?: FlowLoggerContext | null): void;
67
114
  static logLlmResponse({ requestId, model, output, inputTokens, outputTokens, }: {
68
115
  requestId: string;
69
116
  model: string;
117
+ operation: string;
70
118
  output?: string;
71
119
  inputTokens?: number;
72
120
  outputTokens?: number;
73
- }): void;
121
+ }, explicitCtx?: FlowLoggerContext | null): void;
74
122
  /**
75
123
  * Create middleware for wrapping language models with LLM call logging.
76
124
  * Returns a no-op middleware when logging is disabled.
@@ -78,21 +126,14 @@ export declare class FlowLogger {
78
126
  static createLlmLoggingMiddleware(modelId: string): Pick<LanguageModelMiddleware, "wrapGenerate">;
79
127
  }
80
128
  /**
81
- * Format a prompt summary from LLM messages for logging.
82
- * Returns format like: "some text +{5.8kb image} +{schema} +{12 tools}"
129
+ * Method decorator for logging understudy actions with automatic start/complete.
130
+ * Logs all arguments automatically. No-op when CONFIG_DIR is empty.
83
131
  */
84
- export declare function extractLlmPromptSummary(messages: Array<{
85
- role: string;
86
- content: unknown;
87
- }>, options?: {
88
- toolCount?: number;
89
- hasSchema?: boolean;
90
- }): string | undefined;
132
+ export declare function logAction(actionType: string): <T extends (...args: never[]) => Promise<unknown>>(originalMethod: T) => T;
91
133
  /**
92
- * Extract a text summary from CUA-style messages.
93
- * Accepts various message formats (Anthropic, OpenAI, Google).
134
+ * Method decorator for logging Stagehand step events (act, extract, observe).
135
+ * Only adds logging - does NOT wrap with withInstanceLogContext (caller handles that).
136
+ * No-op when CONFIG_DIR is empty.
94
137
  */
95
- export declare function extractLlmCuaPromptSummary(messages: unknown[]): string | undefined;
96
- /** Format a CUA response summary for logging */
97
- export declare function extractLlmCuaResponseSummary(output: unknown): string;
138
+ export declare function logStagehandStep(invocation: string, label: string): <T extends (...args: never[]) => Promise<unknown>>(originalMethod: T) => T;
98
139
  export {};