@browserbasehq/stagehand 3.0.6-alpha-90530b776ae6790751c318ca215c51c0e2f7c79d → 3.0.6-alpha-4e051b23add7ae276b0dbead38b4587838cfc1c1
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.
- package/dist/index.d.ts +156 -6
- package/dist/index.js +55 -9
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { GoogleVertexProviderSettings as GoogleVertexProviderSettings$1 } from '
|
|
|
5
5
|
import { LanguageModelV2 } from '@ai-sdk/provider';
|
|
6
6
|
import { ClientOptions as ClientOptions$1 } from 'openai';
|
|
7
7
|
import { Client, ClientOptions as ClientOptions$3 } from '@modelcontextprotocol/sdk/client/index.js';
|
|
8
|
-
import { ToolSet, StreamTextResult, ModelMessage, wrapLanguageModel, generateObject, generateText, streamText, streamObject, experimental_generateImage, embed, embedMany, experimental_transcribe, experimental_generateSpeech } from 'ai';
|
|
8
|
+
import { ToolSet, PrepareStepFunction, GenerateTextOnStepFinishCallback, StreamTextOnStepFinishCallback, StreamTextOnErrorCallback, StreamTextOnChunkCallback, StreamTextOnFinishCallback, StepResult, StreamTextResult, ModelMessage, wrapLanguageModel, generateObject, generateText, streamText, streamObject, experimental_generateImage, embed, embedMany, experimental_transcribe, experimental_generateSpeech } from 'ai';
|
|
9
9
|
import { Page as Page$1 } from 'playwright-core';
|
|
10
10
|
export { Page as PlaywrightPage } from 'playwright-core';
|
|
11
11
|
import { Page as Page$2 } from 'puppeteer-core';
|
|
@@ -784,6 +784,10 @@ declare class PageNotFoundError extends StagehandError {
|
|
|
784
784
|
declare class ConnectionTimeoutError extends StagehandError {
|
|
785
785
|
constructor(message: string);
|
|
786
786
|
}
|
|
787
|
+
declare class StreamingCallbacksInNonStreamingModeError extends StagehandError {
|
|
788
|
+
readonly invalidCallbacks: string[];
|
|
789
|
+
constructor(invalidCallbacks: string[]);
|
|
790
|
+
}
|
|
787
791
|
|
|
788
792
|
declare class AISdkClient extends LLMClient {
|
|
789
793
|
type: "aisdk";
|
|
@@ -1594,7 +1598,7 @@ declare class Page {
|
|
|
1594
1598
|
}
|
|
1595
1599
|
|
|
1596
1600
|
interface AgentContext {
|
|
1597
|
-
options:
|
|
1601
|
+
options: AgentExecuteOptionsBase;
|
|
1598
1602
|
maxSteps: number;
|
|
1599
1603
|
systemPrompt: string;
|
|
1600
1604
|
allTools: ToolSet;
|
|
@@ -1637,12 +1641,156 @@ interface AgentResult {
|
|
|
1637
1641
|
type AgentStreamResult = StreamTextResult<ToolSet, never> & {
|
|
1638
1642
|
result: Promise<AgentResult>;
|
|
1639
1643
|
};
|
|
1640
|
-
|
|
1644
|
+
/**
|
|
1645
|
+
* Base callbacks shared between execute (non-streaming) and streaming modes.
|
|
1646
|
+
*/
|
|
1647
|
+
interface AgentCallbacks {
|
|
1648
|
+
/**
|
|
1649
|
+
* Optional function called before each step to modify settings.
|
|
1650
|
+
* You can change the model, tool choices, active tools, system prompt,
|
|
1651
|
+
* and input messages for each step.
|
|
1652
|
+
*/
|
|
1653
|
+
prepareStep?: PrepareStepFunction<ToolSet>;
|
|
1654
|
+
/**
|
|
1655
|
+
* Callback called when each step (LLM call) is finished.
|
|
1656
|
+
* This is called for intermediate steps as well as the final step.
|
|
1657
|
+
*/
|
|
1658
|
+
onStepFinish?: GenerateTextOnStepFinishCallback<ToolSet> | StreamTextOnStepFinishCallback<ToolSet>;
|
|
1659
|
+
}
|
|
1660
|
+
/**
|
|
1661
|
+
* Error message type for streaming-only callbacks used in non-streaming mode.
|
|
1662
|
+
* This provides a clear error message when users try to use streaming callbacks without stream: true.
|
|
1663
|
+
*/
|
|
1664
|
+
type StreamingCallbackNotAvailable = "This callback requires 'stream: true' in AgentConfig. Set stream: true to use streaming callbacks like onChunk, onFinish, onError, and onAbort.";
|
|
1665
|
+
/**
|
|
1666
|
+
* Callbacks specific to the non-streaming execute method.
|
|
1667
|
+
*/
|
|
1668
|
+
interface AgentExecuteCallbacks extends AgentCallbacks {
|
|
1669
|
+
/**
|
|
1670
|
+
* Callback called when each step (LLM call) is finished.
|
|
1671
|
+
*/
|
|
1672
|
+
onStepFinish?: GenerateTextOnStepFinishCallback<ToolSet>;
|
|
1673
|
+
/**
|
|
1674
|
+
* NOT AVAILABLE in non-streaming mode.
|
|
1675
|
+
* This callback requires `stream: true` in AgentConfig.
|
|
1676
|
+
*
|
|
1677
|
+
* @example
|
|
1678
|
+
* ```typescript
|
|
1679
|
+
* // Enable streaming to use onChunk:
|
|
1680
|
+
* const agent = stagehand.agent({ stream: true });
|
|
1681
|
+
* await agent.execute({
|
|
1682
|
+
* instruction: "...",
|
|
1683
|
+
* callbacks: { onChunk: async (chunk) => console.log(chunk) }
|
|
1684
|
+
* });
|
|
1685
|
+
* ```
|
|
1686
|
+
*/
|
|
1687
|
+
onChunk?: StreamingCallbackNotAvailable;
|
|
1688
|
+
/**
|
|
1689
|
+
* NOT AVAILABLE in non-streaming mode.
|
|
1690
|
+
* This callback requires `stream: true` in AgentConfig.
|
|
1691
|
+
*
|
|
1692
|
+
* @example
|
|
1693
|
+
* ```typescript
|
|
1694
|
+
* // Enable streaming to use onFinish:
|
|
1695
|
+
* const agent = stagehand.agent({ stream: true });
|
|
1696
|
+
* await agent.execute({
|
|
1697
|
+
* instruction: "...",
|
|
1698
|
+
* callbacks: { onFinish: (event) => console.log("Done!", event) }
|
|
1699
|
+
* });
|
|
1700
|
+
* ```
|
|
1701
|
+
*/
|
|
1702
|
+
onFinish?: StreamingCallbackNotAvailable;
|
|
1703
|
+
/**
|
|
1704
|
+
* NOT AVAILABLE in non-streaming mode.
|
|
1705
|
+
* This callback requires `stream: true` in AgentConfig.
|
|
1706
|
+
*
|
|
1707
|
+
* @example
|
|
1708
|
+
* ```typescript
|
|
1709
|
+
* // Enable streaming to use onError:
|
|
1710
|
+
* const agent = stagehand.agent({ stream: true });
|
|
1711
|
+
* await agent.execute({
|
|
1712
|
+
* instruction: "...",
|
|
1713
|
+
* callbacks: { onError: ({ error }) => console.error(error) }
|
|
1714
|
+
* });
|
|
1715
|
+
* ```
|
|
1716
|
+
*/
|
|
1717
|
+
onError?: StreamingCallbackNotAvailable;
|
|
1718
|
+
/**
|
|
1719
|
+
* NOT AVAILABLE in non-streaming mode.
|
|
1720
|
+
* This callback requires `stream: true` in AgentConfig.
|
|
1721
|
+
*
|
|
1722
|
+
* @example
|
|
1723
|
+
* ```typescript
|
|
1724
|
+
* // Enable streaming to use onAbort:
|
|
1725
|
+
* const agent = stagehand.agent({ stream: true });
|
|
1726
|
+
* await agent.execute({
|
|
1727
|
+
* instruction: "...",
|
|
1728
|
+
* callbacks: { onAbort: (event) => console.log("Aborted", event.steps) }
|
|
1729
|
+
* });
|
|
1730
|
+
* ```
|
|
1731
|
+
*/
|
|
1732
|
+
onAbort?: StreamingCallbackNotAvailable;
|
|
1733
|
+
}
|
|
1734
|
+
/**
|
|
1735
|
+
* Callbacks specific to the streaming mode.
|
|
1736
|
+
*/
|
|
1737
|
+
interface AgentStreamCallbacks extends AgentCallbacks {
|
|
1738
|
+
/**
|
|
1739
|
+
* Callback called when each step (LLM call) is finished during streaming.
|
|
1740
|
+
*/
|
|
1741
|
+
onStepFinish?: StreamTextOnStepFinishCallback<ToolSet>;
|
|
1742
|
+
/**
|
|
1743
|
+
* Callback called when an error occurs during streaming.
|
|
1744
|
+
* Use this to log errors or handle error states.
|
|
1745
|
+
*/
|
|
1746
|
+
onError?: StreamTextOnErrorCallback;
|
|
1747
|
+
/**
|
|
1748
|
+
* Callback called for each chunk of the stream.
|
|
1749
|
+
* Stream processing will pause until the callback promise resolves.
|
|
1750
|
+
*/
|
|
1751
|
+
onChunk?: StreamTextOnChunkCallback<ToolSet>;
|
|
1752
|
+
/**
|
|
1753
|
+
* Callback called when the stream finishes.
|
|
1754
|
+
*/
|
|
1755
|
+
onFinish?: StreamTextOnFinishCallback<ToolSet>;
|
|
1756
|
+
/**
|
|
1757
|
+
* Callback called when the stream is aborted.
|
|
1758
|
+
*/
|
|
1759
|
+
onAbort?: (event: {
|
|
1760
|
+
steps: Array<StepResult<ToolSet>>;
|
|
1761
|
+
}) => PromiseLike<void> | void;
|
|
1762
|
+
}
|
|
1763
|
+
/**
|
|
1764
|
+
* Base options for agent execution (without callbacks).
|
|
1765
|
+
*/
|
|
1766
|
+
interface AgentExecuteOptionsBase {
|
|
1641
1767
|
instruction: string;
|
|
1642
1768
|
maxSteps?: number;
|
|
1643
1769
|
page?: Page$1 | Page$2 | Page$3 | Page;
|
|
1644
1770
|
highlightCursor?: boolean;
|
|
1645
1771
|
}
|
|
1772
|
+
/**
|
|
1773
|
+
* Options for non-streaming agent execution.
|
|
1774
|
+
* Only accepts AgentExecuteCallbacks (no streaming-specific callbacks like onChunk, onFinish).
|
|
1775
|
+
*/
|
|
1776
|
+
interface AgentExecuteOptions extends AgentExecuteOptionsBase {
|
|
1777
|
+
/**
|
|
1778
|
+
* Callbacks for non-streaming agent execution.
|
|
1779
|
+
* For streaming callbacks (onChunk, onFinish, onError, onAbort), use stream: true in AgentConfig.
|
|
1780
|
+
*/
|
|
1781
|
+
callbacks?: AgentExecuteCallbacks;
|
|
1782
|
+
}
|
|
1783
|
+
/**
|
|
1784
|
+
* Options for streaming agent execution.
|
|
1785
|
+
* Accepts AgentStreamCallbacks including onChunk, onFinish, onError, and onAbort.
|
|
1786
|
+
*/
|
|
1787
|
+
interface AgentStreamExecuteOptions extends AgentExecuteOptionsBase {
|
|
1788
|
+
/**
|
|
1789
|
+
* Callbacks for streaming agent execution.
|
|
1790
|
+
* Includes streaming-specific callbacks: onChunk, onFinish, onError, onAbort.
|
|
1791
|
+
*/
|
|
1792
|
+
callbacks?: AgentStreamCallbacks;
|
|
1793
|
+
}
|
|
1646
1794
|
type AgentType = "openai" | "anthropic" | "google" | "microsoft";
|
|
1647
1795
|
declare const AVAILABLE_CUA_MODELS: readonly ["openai/computer-use-preview", "openai/computer-use-preview-2025-03-11", "anthropic/claude-3-7-sonnet-latest", "anthropic/claude-haiku-4-5-20251001", "anthropic/claude-sonnet-4-20250514", "anthropic/claude-sonnet-4-5-20250929", "google/gemini-2.5-computer-use-preview-10-2025", "microsoft/fara-7b"];
|
|
1648
1796
|
type AvailableCuaModel = (typeof AVAILABLE_CUA_MODELS)[number];
|
|
@@ -1776,13 +1924,15 @@ type AgentConfig = {
|
|
|
1776
1924
|
/**
|
|
1777
1925
|
* Agent instance returned when stream: true is set in AgentConfig.
|
|
1778
1926
|
* execute() returns a streaming result that can be consumed incrementally.
|
|
1927
|
+
* Accepts AgentStreamExecuteOptions with streaming-specific callbacks.
|
|
1779
1928
|
*/
|
|
1780
1929
|
interface StreamingAgentInstance {
|
|
1781
|
-
execute: (instructionOrOptions: string |
|
|
1930
|
+
execute: (instructionOrOptions: string | AgentStreamExecuteOptions) => Promise<AgentStreamResult>;
|
|
1782
1931
|
}
|
|
1783
1932
|
/**
|
|
1784
1933
|
* Agent instance returned when stream is false or not set in AgentConfig.
|
|
1785
1934
|
* execute() returns a result after the agent completes.
|
|
1935
|
+
* Accepts AgentExecuteOptions with non-streaming callbacks only.
|
|
1786
1936
|
*/
|
|
1787
1937
|
interface NonStreamingAgentInstance {
|
|
1788
1938
|
execute: (instructionOrOptions: string | AgentExecuteOptions) => Promise<AgentResult>;
|
|
@@ -2115,7 +2265,7 @@ declare class V3 {
|
|
|
2115
2265
|
agent(options: AgentConfig & {
|
|
2116
2266
|
stream: true;
|
|
2117
2267
|
}): {
|
|
2118
|
-
execute: (instructionOrOptions: string |
|
|
2268
|
+
execute: (instructionOrOptions: string | AgentStreamExecuteOptions) => Promise<AgentStreamResult>;
|
|
2119
2269
|
};
|
|
2120
2270
|
agent(options?: AgentConfig & {
|
|
2121
2271
|
stream?: false;
|
|
@@ -2249,4 +2399,4 @@ declare class V3Evaluator {
|
|
|
2249
2399
|
private _evaluateWithMultipleScreenshots;
|
|
2250
2400
|
}
|
|
2251
2401
|
|
|
2252
|
-
export { type AISDKCustomProvider, type AISDKProvider, AISdkClient, AVAILABLE_CUA_MODELS, type ActOptions, type ActResult, type Action, type ActionExecutionResult, type AgentAction, type AgentConfig, type AgentContext, type AgentExecuteOptions, type AgentExecutionOptions, type AgentHandlerOptions, type AgentInstance, type AgentModelConfig, AgentProvider, type AgentProviderType, type AgentResult, AgentScreenshotProviderError, type AgentState, type AgentStreamResult, type AgentType, AnnotatedScreenshotText, type AnthropicClientOptions, type AnthropicContentBlock, type AnthropicJsonSchemaObject, type AnthropicMessage, type AnthropicTextBlock, type AnthropicToolResult, type AnyPage, type AvailableCuaModel, type AvailableModel, BrowserbaseSessionNotFoundError, CaptchaTimeoutError, type ChatCompletionOptions, type ChatMessage, type ChatMessageContent, type ChatMessageImageContent, type ChatMessageTextContent, type ClientOptions, type ComputerCallItem, ConnectionTimeoutError, type ConsoleListener, ConsoleMessage, ContentFrameNotFoundError, type CreateChatCompletionOptions, CreateChatCompletionResponseError, CuaModelRequiredError, ElementNotVisibleError, ExperimentalApiConflictError, ExperimentalNotConfiguredError, type ExtractOptions, type ExtractResult, type FunctionCallItem, type GoogleServiceAccountCredentials, type GoogleVertexProviderSettings, HandlerNotInitializedError, type HistoryEntry, type InferStagehandSchema, InvalidAISDKModelFormatError, type JsonSchema, type JsonSchemaDocument, type JsonSchemaProperty, LLMClient, type LLMParsedResponse, type LLMResponse, LLMResponseError, type LLMTool, type LLMUsage, LOG_LEVEL_NAMES, type LoadState, type LocalBrowserLaunchOptions, type LogLevel, type LogLine, type Logger, MCPConnectionError, MissingEnvironmentVariableError, MissingLLMConfigurationError, type ModelConfiguration, type ModelProvider, type NonStreamingAgentInstance, type ObserveOptions, type OpenAIClientOptions, Page, PageNotFoundError, Response$1 as Response, ResponseBodyError, type ResponseInputItem, type ResponseItem, ResponseParseError, V3 as Stagehand, StagehandAPIError, StagehandAPIUnauthorizedError, StagehandClickError, StagehandDefaultError, StagehandDomProcessError, StagehandElementNotFoundError, StagehandEnvironmentError, StagehandError, StagehandEvalError, StagehandHttpError, StagehandIframeError, StagehandInitError, StagehandInvalidArgumentError, type StagehandMetrics, StagehandMissingArgumentError, StagehandNotInitializedError, StagehandResponseBodyError, StagehandResponseParseError, StagehandServerError, StagehandShadowRootMissingError, StagehandShadowSegmentEmptyError, StagehandShadowSegmentNotFoundError, type StagehandZodObject, type StagehandZodSchema, type StreamingAgentInstance, TimeoutError, type ToolUseItem, UnsupportedAISDKModelProviderError, UnsupportedModelError, UnsupportedModelProviderError, V3, type V3Env, V3Evaluator, V3FunctionName, type V3Options, XPathResolutionError, ZodSchemaValidationError, connectToMCPServer, defaultExtractSchema, getZodType, injectUrls, isRunningInBun, isZod3Schema, isZod4Schema, jsonSchemaToZod, loadApiKeyFromEnv, modelToAgentProviderMap, pageTextSchema, providerEnvVarMap, toGeminiSchema, toJsonSchema, transformSchema, trimTrailingTextNode, validateZodSchema };
|
|
2402
|
+
export { type AISDKCustomProvider, type AISDKProvider, AISdkClient, AVAILABLE_CUA_MODELS, type ActOptions, type ActResult, type Action, type ActionExecutionResult, type AgentAction, type AgentCallbacks, type AgentConfig, type AgentContext, type AgentExecuteCallbacks, type AgentExecuteOptions, type AgentExecuteOptionsBase, type AgentExecutionOptions, type AgentHandlerOptions, type AgentInstance, type AgentModelConfig, AgentProvider, type AgentProviderType, type AgentResult, AgentScreenshotProviderError, type AgentState, type AgentStreamCallbacks, type AgentStreamExecuteOptions, type AgentStreamResult, type AgentType, AnnotatedScreenshotText, type AnthropicClientOptions, type AnthropicContentBlock, type AnthropicJsonSchemaObject, type AnthropicMessage, type AnthropicTextBlock, type AnthropicToolResult, type AnyPage, type AvailableCuaModel, type AvailableModel, BrowserbaseSessionNotFoundError, CaptchaTimeoutError, type ChatCompletionOptions, type ChatMessage, type ChatMessageContent, type ChatMessageImageContent, type ChatMessageTextContent, type ClientOptions, type ComputerCallItem, ConnectionTimeoutError, type ConsoleListener, ConsoleMessage, ContentFrameNotFoundError, type CreateChatCompletionOptions, CreateChatCompletionResponseError, CuaModelRequiredError, ElementNotVisibleError, ExperimentalApiConflictError, ExperimentalNotConfiguredError, type ExtractOptions, type ExtractResult, type FunctionCallItem, type GoogleServiceAccountCredentials, type GoogleVertexProviderSettings, HandlerNotInitializedError, type HistoryEntry, type InferStagehandSchema, InvalidAISDKModelFormatError, type JsonSchema, type JsonSchemaDocument, type JsonSchemaProperty, LLMClient, type LLMParsedResponse, type LLMResponse, LLMResponseError, type LLMTool, type LLMUsage, LOG_LEVEL_NAMES, type LoadState, type LocalBrowserLaunchOptions, type LogLevel, type LogLine, type Logger, MCPConnectionError, MissingEnvironmentVariableError, MissingLLMConfigurationError, type ModelConfiguration, type ModelProvider, type NonStreamingAgentInstance, type ObserveOptions, type OpenAIClientOptions, Page, PageNotFoundError, Response$1 as Response, ResponseBodyError, type ResponseInputItem, type ResponseItem, ResponseParseError, V3 as Stagehand, StagehandAPIError, StagehandAPIUnauthorizedError, StagehandClickError, StagehandDefaultError, StagehandDomProcessError, StagehandElementNotFoundError, StagehandEnvironmentError, StagehandError, StagehandEvalError, StagehandHttpError, StagehandIframeError, StagehandInitError, StagehandInvalidArgumentError, type StagehandMetrics, StagehandMissingArgumentError, StagehandNotInitializedError, StagehandResponseBodyError, StagehandResponseParseError, StagehandServerError, StagehandShadowRootMissingError, StagehandShadowSegmentEmptyError, StagehandShadowSegmentNotFoundError, type StagehandZodObject, type StagehandZodSchema, type StreamingAgentInstance, StreamingCallbacksInNonStreamingModeError, TimeoutError, type ToolUseItem, UnsupportedAISDKModelProviderError, UnsupportedModelError, UnsupportedModelProviderError, V3, type V3Env, V3Evaluator, V3FunctionName, type V3Options, XPathResolutionError, ZodSchemaValidationError, connectToMCPServer, defaultExtractSchema, getZodType, injectUrls, isRunningInBun, isZod3Schema, isZod4Schema, jsonSchemaToZod, loadApiKeyFromEnv, modelToAgentProviderMap, pageTextSchema, providerEnvVarMap, toGeminiSchema, toJsonSchema, transformSchema, trimTrailingTextNode, validateZodSchema };
|
package/dist/index.js
CHANGED
|
@@ -141,12 +141,12 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
141
141
|
var STAGEHAND_VERSION;
|
|
142
142
|
var init_version = __esm({
|
|
143
143
|
"lib/version.ts"() {
|
|
144
|
-
STAGEHAND_VERSION = "3.0.6-alpha-
|
|
144
|
+
STAGEHAND_VERSION = "3.0.6-alpha-4e051b23add7ae276b0dbead38b4587838cfc1c1";
|
|
145
145
|
}
|
|
146
146
|
});
|
|
147
147
|
|
|
148
148
|
// lib/v3/types/public/sdkErrors.ts
|
|
149
|
-
var StagehandError, StagehandDefaultError, StagehandEnvironmentError, MissingEnvironmentVariableError, UnsupportedModelError, UnsupportedModelProviderError, UnsupportedAISDKModelProviderError, InvalidAISDKModelFormatError, StagehandNotInitializedError, BrowserbaseSessionNotFoundError, CaptchaTimeoutError, MissingLLMConfigurationError, HandlerNotInitializedError, StagehandInvalidArgumentError, StagehandElementNotFoundError, AgentScreenshotProviderError, StagehandMissingArgumentError, CreateChatCompletionResponseError, StagehandEvalError, StagehandDomProcessError, StagehandClickError, LLMResponseError, StagehandIframeError, ContentFrameNotFoundError, XPathResolutionError, ExperimentalApiConflictError, ExperimentalNotConfiguredError, CuaModelRequiredError, ZodSchemaValidationError, StagehandInitError, MCPConnectionError, StagehandShadowRootMissingError, StagehandShadowSegmentEmptyError, StagehandShadowSegmentNotFoundError, ElementNotVisibleError, ResponseBodyError, ResponseParseError, TimeoutError, PageNotFoundError, ConnectionTimeoutError;
|
|
149
|
+
var StagehandError, StagehandDefaultError, StagehandEnvironmentError, MissingEnvironmentVariableError, UnsupportedModelError, UnsupportedModelProviderError, UnsupportedAISDKModelProviderError, InvalidAISDKModelFormatError, StagehandNotInitializedError, BrowserbaseSessionNotFoundError, CaptchaTimeoutError, MissingLLMConfigurationError, HandlerNotInitializedError, StagehandInvalidArgumentError, StagehandElementNotFoundError, AgentScreenshotProviderError, StagehandMissingArgumentError, CreateChatCompletionResponseError, StagehandEvalError, StagehandDomProcessError, StagehandClickError, LLMResponseError, StagehandIframeError, ContentFrameNotFoundError, XPathResolutionError, ExperimentalApiConflictError, ExperimentalNotConfiguredError, CuaModelRequiredError, ZodSchemaValidationError, StagehandInitError, MCPConnectionError, StagehandShadowRootMissingError, StagehandShadowSegmentEmptyError, StagehandShadowSegmentNotFoundError, ElementNotVisibleError, ResponseBodyError, ResponseParseError, TimeoutError, PageNotFoundError, ConnectionTimeoutError, StreamingCallbacksInNonStreamingModeError;
|
|
150
150
|
var init_sdkErrors = __esm({
|
|
151
151
|
"lib/v3/types/public/sdkErrors.ts"() {
|
|
152
152
|
init_version();
|
|
@@ -406,6 +406,14 @@ ${JSON.stringify(issues, null, 2)}`);
|
|
|
406
406
|
super(`Connection timeout: ${message}`);
|
|
407
407
|
}
|
|
408
408
|
};
|
|
409
|
+
StreamingCallbacksInNonStreamingModeError = class extends StagehandError {
|
|
410
|
+
constructor(invalidCallbacks) {
|
|
411
|
+
super(
|
|
412
|
+
`Streaming-only callback(s) "${invalidCallbacks.join('", "')}" cannot be used in non-streaming mode. Set 'stream: true' in AgentConfig to use these callbacks.`
|
|
413
|
+
);
|
|
414
|
+
this.invalidCallbacks = invalidCallbacks;
|
|
415
|
+
}
|
|
416
|
+
};
|
|
409
417
|
}
|
|
410
418
|
});
|
|
411
419
|
|
|
@@ -25971,6 +25979,7 @@ __export(v3_exports, {
|
|
|
25971
25979
|
StagehandShadowRootMissingError: () => StagehandShadowRootMissingError,
|
|
25972
25980
|
StagehandShadowSegmentEmptyError: () => StagehandShadowSegmentEmptyError,
|
|
25973
25981
|
StagehandShadowSegmentNotFoundError: () => StagehandShadowSegmentNotFoundError,
|
|
25982
|
+
StreamingCallbacksInNonStreamingModeError: () => StreamingCallbacksInNonStreamingModeError,
|
|
25974
25983
|
TimeoutError: () => TimeoutError,
|
|
25975
25984
|
UnsupportedAISDKModelProviderError: () => UnsupportedAISDKModelProviderError,
|
|
25976
25985
|
UnsupportedModelError: () => UnsupportedModelError,
|
|
@@ -30298,7 +30307,7 @@ var V3AgentHandler = class {
|
|
|
30298
30307
|
}
|
|
30299
30308
|
});
|
|
30300
30309
|
}
|
|
30301
|
-
createStepHandler(state) {
|
|
30310
|
+
createStepHandler(state, userCallback) {
|
|
30302
30311
|
return (event) => __async(this, null, function* () {
|
|
30303
30312
|
var _a4;
|
|
30304
30313
|
this.logger({
|
|
@@ -30341,6 +30350,9 @@ var V3AgentHandler = class {
|
|
|
30341
30350
|
}
|
|
30342
30351
|
state.currentPageUrl = (yield this.v3.context.awaitActivePage()).url();
|
|
30343
30352
|
}
|
|
30353
|
+
if (userCallback) {
|
|
30354
|
+
yield userCallback(event);
|
|
30355
|
+
}
|
|
30344
30356
|
});
|
|
30345
30357
|
}
|
|
30346
30358
|
execute(instructionOrOptions) {
|
|
@@ -30355,6 +30367,21 @@ var V3AgentHandler = class {
|
|
|
30355
30367
|
wrappedModel,
|
|
30356
30368
|
initialPageUrl
|
|
30357
30369
|
} = yield this.prepareAgent(instructionOrOptions);
|
|
30370
|
+
const callbacks = instructionOrOptions.callbacks;
|
|
30371
|
+
if (callbacks) {
|
|
30372
|
+
const streamingOnlyCallbacks = [
|
|
30373
|
+
"onChunk",
|
|
30374
|
+
"onFinish",
|
|
30375
|
+
"onError",
|
|
30376
|
+
"onAbort"
|
|
30377
|
+
];
|
|
30378
|
+
const invalidCallbacks = streamingOnlyCallbacks.filter(
|
|
30379
|
+
(name) => callbacks[name] != null
|
|
30380
|
+
);
|
|
30381
|
+
if (invalidCallbacks.length > 0) {
|
|
30382
|
+
throw new StreamingCallbacksInNonStreamingModeError(invalidCallbacks);
|
|
30383
|
+
}
|
|
30384
|
+
}
|
|
30358
30385
|
const state = {
|
|
30359
30386
|
collectedReasoning: [],
|
|
30360
30387
|
actions: [],
|
|
@@ -30371,7 +30398,8 @@ var V3AgentHandler = class {
|
|
|
30371
30398
|
stopWhen: (result2) => this.handleStop(result2, maxSteps),
|
|
30372
30399
|
temperature: 1,
|
|
30373
30400
|
toolChoice: "auto",
|
|
30374
|
-
|
|
30401
|
+
prepareStep: callbacks == null ? void 0 : callbacks.prepareStep,
|
|
30402
|
+
onStepFinish: this.createStepHandler(state, callbacks == null ? void 0 : callbacks.onStepFinish)
|
|
30375
30403
|
});
|
|
30376
30404
|
return this.consolidateMetricsAndResult(startTime, state, result);
|
|
30377
30405
|
} catch (error) {
|
|
@@ -30400,6 +30428,7 @@ var V3AgentHandler = class {
|
|
|
30400
30428
|
wrappedModel,
|
|
30401
30429
|
initialPageUrl
|
|
30402
30430
|
} = yield this.prepareAgent(instructionOrOptions);
|
|
30431
|
+
const callbacks = instructionOrOptions.callbacks;
|
|
30403
30432
|
const state = {
|
|
30404
30433
|
collectedReasoning: [],
|
|
30405
30434
|
actions: [],
|
|
@@ -30431,11 +30460,19 @@ var V3AgentHandler = class {
|
|
|
30431
30460
|
stopWhen: (result) => this.handleStop(result, maxSteps),
|
|
30432
30461
|
temperature: 1,
|
|
30433
30462
|
toolChoice: "auto",
|
|
30434
|
-
|
|
30435
|
-
|
|
30436
|
-
|
|
30463
|
+
prepareStep: callbacks == null ? void 0 : callbacks.prepareStep,
|
|
30464
|
+
onStepFinish: this.createStepHandler(state, callbacks == null ? void 0 : callbacks.onStepFinish),
|
|
30465
|
+
onError: (event) => {
|
|
30466
|
+
if (callbacks == null ? void 0 : callbacks.onError) {
|
|
30467
|
+
callbacks.onError(event);
|
|
30468
|
+
}
|
|
30469
|
+
handleError(event.error);
|
|
30437
30470
|
},
|
|
30471
|
+
onChunk: callbacks == null ? void 0 : callbacks.onChunk,
|
|
30438
30472
|
onFinish: (event) => {
|
|
30473
|
+
if (callbacks == null ? void 0 : callbacks.onFinish) {
|
|
30474
|
+
callbacks.onFinish(event);
|
|
30475
|
+
}
|
|
30439
30476
|
try {
|
|
30440
30477
|
const result = this.consolidateMetricsAndResult(
|
|
30441
30478
|
startTime,
|
|
@@ -62370,6 +62407,7 @@ var V3Context = class _V3Context {
|
|
|
62370
62407
|
yield this.conn.enableAutoAttach();
|
|
62371
62408
|
const targets = yield this.conn.getTargets();
|
|
62372
62409
|
for (const t2 of targets) {
|
|
62410
|
+
if (t2.attached) continue;
|
|
62373
62411
|
try {
|
|
62374
62412
|
yield this.conn.attachToTarget(t2.targetId);
|
|
62375
62413
|
} catch (e2) {
|
|
@@ -64286,6 +64324,9 @@ Do not ask follow up questions, the user will trust your judgement.`
|
|
|
64286
64324
|
return {
|
|
64287
64325
|
execute: (instructionOrOptions) => __async(this, null, function* () {
|
|
64288
64326
|
return withInstanceLogContext(this.instanceId, () => __async(this, null, function* () {
|
|
64327
|
+
if (typeof instructionOrOptions === "object" && instructionOrOptions.callbacks && !this.experimental) {
|
|
64328
|
+
throw new ExperimentalNotConfiguredError("Agent callbacks");
|
|
64329
|
+
}
|
|
64289
64330
|
if (isStreaming) {
|
|
64290
64331
|
if (!this.experimental) {
|
|
64291
64332
|
throw new ExperimentalNotConfiguredError("Agent streaming");
|
|
@@ -64301,7 +64342,9 @@ Do not ask follow up questions, the user will trust your judgement.`
|
|
|
64301
64342
|
return replayed;
|
|
64302
64343
|
}
|
|
64303
64344
|
}
|
|
64304
|
-
const streamResult = yield handler2.stream(
|
|
64345
|
+
const streamResult = yield handler2.stream(
|
|
64346
|
+
instructionOrOptions
|
|
64347
|
+
);
|
|
64305
64348
|
if (cacheContext2) {
|
|
64306
64349
|
return this.agentCache.wrapStreamForCaching(
|
|
64307
64350
|
cacheContext2,
|
|
@@ -64339,7 +64382,9 @@ Do not ask follow up questions, the user will trust your judgement.`
|
|
|
64339
64382
|
page.mainFrameId()
|
|
64340
64383
|
);
|
|
64341
64384
|
} else {
|
|
64342
|
-
result = yield handler.execute(
|
|
64385
|
+
result = yield handler.execute(
|
|
64386
|
+
instructionOrOptions
|
|
64387
|
+
);
|
|
64343
64388
|
}
|
|
64344
64389
|
if (recording) {
|
|
64345
64390
|
agentSteps = this.endAgentReplayRecording();
|
|
@@ -64654,6 +64699,7 @@ I'm providing ${screenshots.length} screenshots showing the progression of the t
|
|
|
64654
64699
|
StagehandShadowRootMissingError,
|
|
64655
64700
|
StagehandShadowSegmentEmptyError,
|
|
64656
64701
|
StagehandShadowSegmentNotFoundError,
|
|
64702
|
+
StreamingCallbacksInNonStreamingModeError,
|
|
64657
64703
|
TimeoutError,
|
|
64658
64704
|
UnsupportedAISDKModelProviderError,
|
|
64659
64705
|
UnsupportedModelError,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@browserbasehq/stagehand",
|
|
3
|
-
"version": "3.0.6-alpha-
|
|
3
|
+
"version": "3.0.6-alpha-4e051b23add7ae276b0dbead38b4587838cfc1c1",
|
|
4
4
|
"description": "An AI web browsing framework focused on simplicity and extensibility.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|