@polos/sdk 0.1.1 → 0.1.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.
package/dist/index.d.cts CHANGED
@@ -129,6 +129,20 @@ interface BatchWorkflowInput {
129
129
  /** Timeout in seconds for the sub-workflow execution */
130
130
  runTimeoutSeconds?: number | undefined;
131
131
  }
132
+ /**
133
+ * Result of a single workflow in a batch invocation.
134
+ * Matches Python BatchStepResult.
135
+ */
136
+ interface BatchStepResult<T = unknown> {
137
+ /** The workflow ID that was invoked */
138
+ workflowId: string;
139
+ /** Whether the workflow completed successfully */
140
+ success: boolean;
141
+ /** The result from the workflow (if successful) */
142
+ result: T | null;
143
+ /** Error message (if failed) */
144
+ error: string | null;
145
+ }
132
146
  /**
133
147
  * Configuration for agent invocation.
134
148
  * Matches Python AgentRunConfig.
@@ -217,7 +231,7 @@ interface StepHelper {
217
231
  /**
218
232
  * Invoke multiple workflows and wait for all results.
219
233
  */
220
- batchInvokeAndWait<T>(key: string, items: BatchWorkflowInput[]): Promise<T[]>;
234
+ batchInvokeAndWait<T>(key: string, items: BatchWorkflowInput[]): Promise<BatchStepResult<T>[]>;
221
235
  /**
222
236
  * Wait for a time duration.
223
237
  */
@@ -276,7 +290,7 @@ interface StepHelper {
276
290
  /**
277
291
  * Invoke multiple agent workflows in batch and wait for all results.
278
292
  */
279
- batchAgentInvokeAndWait<T>(key: string, configs: AgentRunConfig[]): Promise<T[]>;
293
+ batchAgentInvokeAndWait<T>(key: string, configs: AgentRunConfig[]): Promise<BatchStepResult<T>[]>;
280
294
  /**
281
295
  * Create a custom traced span around an async operation.
282
296
  */
@@ -662,6 +676,7 @@ declare function defineWorkflow<TPayload = unknown, TState = unknown, TResult =
662
676
  * LLM-specific metadata (description, JSON schema parameters).
663
677
  */
664
678
 
679
+ type ToolApproval = 'always' | 'none';
665
680
  /**
666
681
  * LLM tool definition format (OpenAI/Anthropic compatible).
667
682
  */
@@ -693,6 +708,10 @@ interface DefineToolConfig<TInput = unknown, TOutput = unknown, TState = unknown
693
708
  onStart?: HookHandler<TInput, TState> | Hook<TInput, TState> | (HookHandler<TInput, TState> | Hook<TInput, TState>)[] | undefined;
694
709
  /** Hook(s) to run after tool completion */
695
710
  onEnd?: HookHandler<TInput, TState> | Hook<TInput, TState> | (HookHandler<TInput, TState> | Hook<TInput, TState>)[] | undefined;
711
+ /** Whether to auto-register in the global workflow registry (default: true) */
712
+ autoRegister?: boolean | undefined;
713
+ /** Require human approval before tool execution. @default undefined (no approval) */
714
+ approval?: ToolApproval | undefined;
696
715
  }
697
716
  /**
698
717
  * A Workflow with tool-specific LLM metadata.
@@ -1628,6 +1647,10 @@ declare class OrchestratorClient {
1628
1647
  private readonly timeout;
1629
1648
  private readonly maxRetries;
1630
1649
  constructor(config: OrchestratorClientConfig);
1650
+ /**
1651
+ * Get the API URL.
1652
+ */
1653
+ getApiUrl(): string;
1631
1654
  /**
1632
1655
  * Get the project ID.
1633
1656
  */
@@ -2132,8 +2155,8 @@ declare class DuplicateWorkflowError extends Error {
2132
2155
  */
2133
2156
  interface WorkflowRegistry {
2134
2157
  /**
2135
- * Register a workflow.
2136
- * @throws DuplicateWorkflowError if workflow ID is already registered
2158
+ * Register a workflow. If a workflow with the same ID is already
2159
+ * registered, it is silently replaced.
2137
2160
  */
2138
2161
  register(workflow: Workflow): void;
2139
2162
  /**
@@ -2983,6 +3006,8 @@ interface LLMUsage {
2983
3006
  input_tokens: number;
2984
3007
  output_tokens: number;
2985
3008
  total_tokens: number;
3009
+ cache_read_input_tokens?: number | undefined;
3010
+ cache_creation_input_tokens?: number | undefined;
2986
3011
  }
2987
3012
  /**
2988
3013
  * A tool call made by the LLM
@@ -3125,6 +3150,10 @@ declare function convertVercelUsageToPython(usage: {
3125
3150
  inputTokens: number | undefined;
3126
3151
  outputTokens: number | undefined;
3127
3152
  totalTokens?: number | undefined;
3153
+ inputTokenDetails?: {
3154
+ cacheReadTokens?: number | undefined;
3155
+ cacheWriteTokens?: number | undefined;
3156
+ };
3128
3157
  }): LLMUsage;
3129
3158
  /**
3130
3159
  * Convert Vercel finish reason (kebab-case) to Python format (snake_case).
@@ -3504,6 +3533,8 @@ interface DefineAgentConfig {
3504
3533
  guardrailMaxRetries?: number | undefined;
3505
3534
  /** Number of conversation history messages to retain (default: 10) */
3506
3535
  conversationHistory?: number | undefined;
3536
+ /** Publish text_delta and tool_call events to the workflow topic for all invocations */
3537
+ streamToWorkflow?: boolean | undefined;
3507
3538
  }
3508
3539
  /**
3509
3540
  * Payload for agent run() and stream() calls.
@@ -3770,4 +3801,536 @@ declare function generateTraceIdFromExecutionId(executionId: string): string;
3770
3801
  */
3771
3802
  declare function isOtelAvailable(): boolean;
3772
3803
 
3773
- export { type Agent, type AgentConfig, type AgentContext, type AgentResult, AgentRunConfig, type AgentRunOptions, type AgentRunPayload, type AgentStep, type AgentStream, type AgentStreamEvent, type AgentStreamPayload, type AgentStreamResult, type AgentWorkflow, type BatchEventPayload, type BatchWorkflowInput, type ClientBatchWorkflowInput, type ClientInvokeOptions, type CoreMessage$1 as CoreMessage, type DefineAgentConfig, type DefineGuardrailOptions, type DefineHookOptions, type DefineToolConfig, DuplicateWorkflowError, type Event, type EventData, type EventItem, type EventPayload, type EventTriggerPayload, type EventsApi, type ExecuteGuardrailsOptions, type ExecuteHooksOptions, type ExecuteWorkflowOptions, type ExecutionContext, type ExecutionData, ExecutionHandle, type ExecutionHandleFields, type ExecutionResult, type FinishReason, type GenerateConfig, type Guardrail$1 as Guardrail, type GuardrailChainResult, type GuardrailContext$1 as GuardrailContext, GuardrailError, type GuardrailHandler, GuardrailResult$1 as GuardrailResult, type GuardrailResultType, type Hook, type HookChainResult, type HookContext, HookExecutionError, type HookHandler, HookResult, type HookResultType, type InferPayload, type InferResult, type InferState, type InvokeOptions, LLM, type LLMGenerateOptions, type LLMGeneratePayload, type LLMGenerateResult, type LLMProvider, type LLMResponse, type LLMStreamEvent, type LLMStreamPayload, type LLMToolCall, type LLMToolResult, type LLMUsage, type LlmToolDefinition, type Logger, type Guardrail as MiddlewareGuardrail, type GuardrailContext as MiddlewareGuardrailContext, GuardrailResult as MiddlewareGuardrailResult, OrchestratorApiError, OrchestratorClient, type OrchestratorClientConfig, type OtelConfig, PolosClient, type PolosClientConfig, type PublishEventFn, type PublishEventOptions, Queue, type QueueConfig$1 as QueueConfig, type QueueOptions, type ResumeOptions, type ScheduleConfig, type SchedulePayload, type SchedulesApi, StateSizeError, StateValidationError, StepExecutionError, type StepHelper, type StepInfo, type StepOptions, type StepStore, type StopCondition, type StopConditionContext, type StreamEvent, StreamResult, type StreamTopicOptions, type StreamWorkflowOptions, type SuspendOptions, type TextDeltaEvent, type TokenUsage, type Tool, type ToolCall, type ToolCallEvent, type ToolConfig, type ToolHandler, type ToolResult, type ToolResultInfo, type ToolWorkflow, WaitError, type WaitForEventOptions, type WaitForOptions, Worker, type WorkerConfig, type WorkerExecutionData, WorkerServer, type WorkerServerConfig, type Workflow, type WorkflowConfig, type WorkflowContext, type WorkflowEvent, type WorkflowHandle, type WorkflowHandler, WorkflowNotFoundError, type WorkflowRegistry, type WorkflowRunClient, type WorkflowRunOptions, type WorkflowStatus, agentStreamFunction, batchAgentInvoke, batchInvoke, composeGuardrails, composeHooks, conditionalHook, convertFinishReason, convertMiddlewareToolCallToPython, convertPythonToolCallToMiddleware, convertToolResultsToMessages, convertToolsToVercel, convertVercelToolCallToPython, convertVercelUsageToPython, createLogger, createStepHelper, createStepStore, createWorkflowRegistry, defineAgent, defineGuardrail, defineHook, defineTool, defineWorkflow, executeGuardrailChain, executeGuardrailsOrThrow, executeHookChain, executeHooksOrThrow, executeWorkflow, executedTool, extractTraceparent, generateTraceIdFromExecutionId, getTracer, globalRegistry, hasText, initializeOtel, initializeState, isAgentWorkflow, isGuardrail, isHook, isOtelAvailable, isToolWorkflow, isWaitError, llmGenerate, llmStream, maxSteps, maxTokens, normalizeGuardrail, normalizeGuardrails, normalizeHook, normalizeHooks, retry, serializeFinalState, sleep, stopCondition, validateState };
3804
+ /**
3805
+ * Ask-user tool — lets agents ask questions and receive answers from the user.
3806
+ *
3807
+ * Uses ctx.step.suspend() to pause the workflow, emit a suspend event with a
3808
+ * _form schema, and wait for the user to respond via client.resume(). Supports
3809
+ * both structured form fields and simple free-text responses.
3810
+ */
3811
+
3812
+ /**
3813
+ * Create the ask_user tool for agent-to-user communication.
3814
+ *
3815
+ * When an agent calls this tool, the workflow suspends and emits a suspend
3816
+ * event with a `_form` schema. The client handles the event, collects the
3817
+ * user's response, and resumes the workflow with the response data.
3818
+ *
3819
+ * @example
3820
+ * ```typescript
3821
+ * import { createAskUserTool } from '@polos/sdk';
3822
+ *
3823
+ * const askUser = createAskUserTool();
3824
+ * // Add to agent tools array
3825
+ * ```
3826
+ */
3827
+ declare function createAskUserTool(): ToolWorkflow;
3828
+
3829
+ /**
3830
+ * Web search tool — lets agents search the web for current information.
3831
+ *
3832
+ * Defaults to the Tavily Search API using raw fetch() (no additional
3833
+ * dependencies). Users can plug in any search provider via a custom
3834
+ * function.
3835
+ *
3836
+ * @example
3837
+ * ```typescript
3838
+ * import { createWebSearchTool } from '@polos/sdk';
3839
+ *
3840
+ * // Tavily with env var (TAVILY_API_KEY)
3841
+ * const webSearch = createWebSearchTool();
3842
+ *
3843
+ * // Custom provider
3844
+ * const webSearch = createWebSearchTool({
3845
+ * search: async (query, opts) => {
3846
+ * const res = await mySearchApi(query, opts.maxResults);
3847
+ * return { query, results: res.items };
3848
+ * },
3849
+ * });
3850
+ * ```
3851
+ */
3852
+
3853
+ /** A single search result item. */
3854
+ interface WebSearchResultItem {
3855
+ title: string;
3856
+ url: string;
3857
+ /** Snippet or summary of the page content. */
3858
+ content: string;
3859
+ /** Relevance score, 0–1. */
3860
+ score?: number | undefined;
3861
+ /** Publication date in ISO 8601 format. */
3862
+ publishedDate?: string | undefined;
3863
+ }
3864
+ /** Full search result returned by the tool. */
3865
+ interface WebSearchResult {
3866
+ query: string;
3867
+ results: WebSearchResultItem[];
3868
+ /** AI-generated summary (Tavily feature). */
3869
+ answer?: string | undefined;
3870
+ }
3871
+ /** Options forwarded to the search function at call time. */
3872
+ interface WebSearchOptions {
3873
+ maxResults: number;
3874
+ topic: 'general' | 'news';
3875
+ }
3876
+ /** Signature for a custom search provider function. */
3877
+ type WebSearchFunction = (query: string, options: WebSearchOptions) => Promise<WebSearchResult>;
3878
+ /** Tavily-specific configuration knobs. */
3879
+ interface TavilySearchConfig {
3880
+ /** Tavily API key. Falls back to the TAVILY_API_KEY environment variable. */
3881
+ apiKey?: string;
3882
+ /** Search depth. @default 'basic' */
3883
+ searchDepth?: 'basic' | 'advanced';
3884
+ /** Include an AI-generated answer in the response. @default true */
3885
+ includeAnswer?: boolean;
3886
+ /** Include raw page content in results. @default false */
3887
+ includeRawContent?: boolean;
3888
+ /** Tavily API base URL. @default 'https://api.tavily.com' */
3889
+ baseUrl?: string;
3890
+ }
3891
+ /** Configuration for createWebSearchTool(). */
3892
+ interface WebSearchToolConfig extends TavilySearchConfig {
3893
+ /** Custom search provider. When set, overrides the built-in Tavily implementation. */
3894
+ search?: WebSearchFunction;
3895
+ /** Default maximum results per query. @default 5 */
3896
+ maxResults?: number;
3897
+ /** Default topic filter. @default 'general' */
3898
+ topic?: 'general' | 'news';
3899
+ /** Tool identifier exposed to the LLM. @default 'web_search' */
3900
+ toolId?: string;
3901
+ /** Require human approval before execution. */
3902
+ approval?: ToolApproval;
3903
+ }
3904
+ /**
3905
+ * Create a web search tool for agent use.
3906
+ *
3907
+ * By default uses the Tavily Search API via raw fetch(). Pass a custom
3908
+ * `search` function to use any other provider.
3909
+ *
3910
+ * @example
3911
+ * ```typescript
3912
+ * // Tavily with env var
3913
+ * const webSearch = createWebSearchTool();
3914
+ *
3915
+ * // Tavily with explicit key
3916
+ * const webSearch = createWebSearchTool({ apiKey: 'tvly-xxx' });
3917
+ *
3918
+ * // Custom provider
3919
+ * const webSearch = createWebSearchTool({
3920
+ * search: async (query, opts) => {
3921
+ * const res = await myApi(query, opts.maxResults);
3922
+ * return { query, results: res.items };
3923
+ * },
3924
+ * });
3925
+ * ```
3926
+ */
3927
+ declare function createWebSearchTool(config?: WebSearchToolConfig): ToolWorkflow;
3928
+
3929
+ /**
3930
+ * Shared types for the execution framework.
3931
+ *
3932
+ * Defines interfaces for execution environments, command results,
3933
+ * file operations, and configuration.
3934
+ */
3935
+ /**
3936
+ * Abstract interface for an execution environment (Docker, E2B, Local).
3937
+ * All sandbox tools operate against this interface.
3938
+ */
3939
+ interface ExecutionEnvironment {
3940
+ /** Environment type discriminator */
3941
+ readonly type: 'local' | 'docker' | 'e2b';
3942
+ /** Execute a shell command in the environment */
3943
+ exec(command: string, opts?: ExecOptions): Promise<ExecResult>;
3944
+ /** Read a file's contents as UTF-8 text */
3945
+ readFile(path: string): Promise<string>;
3946
+ /** Write content to a file, creating parent directories as needed */
3947
+ writeFile(path: string, content: string): Promise<void>;
3948
+ /** Check whether a file exists */
3949
+ fileExists(path: string): Promise<boolean>;
3950
+ /** Find files matching a glob pattern */
3951
+ glob(pattern: string, opts?: GlobOptions): Promise<string[]>;
3952
+ /** Search file contents for a pattern */
3953
+ grep(pattern: string, opts?: GrepOptions): Promise<GrepMatch[]>;
3954
+ /** Initialize the environment (create container, connect to sandbox, etc.) */
3955
+ initialize(): Promise<void>;
3956
+ /** Tear down the environment (remove container, kill sandbox, etc.) */
3957
+ destroy(): Promise<void>;
3958
+ /** Get the current working directory inside the environment */
3959
+ getCwd(): string;
3960
+ /** Get environment metadata */
3961
+ getInfo(): EnvironmentInfo;
3962
+ }
3963
+ /**
3964
+ * Options for command execution.
3965
+ */
3966
+ interface ExecOptions {
3967
+ /** Working directory for the command */
3968
+ cwd?: string | undefined;
3969
+ /** Environment variables to set */
3970
+ env?: Record<string, string> | undefined;
3971
+ /** Timeout in seconds (default: 300) */
3972
+ timeout?: number | undefined;
3973
+ /** Data to pipe to stdin */
3974
+ stdin?: string | undefined;
3975
+ }
3976
+ /**
3977
+ * Result of a command execution.
3978
+ */
3979
+ interface ExecResult {
3980
+ /** Process exit code (0 = success) */
3981
+ exitCode: number;
3982
+ /** Standard output */
3983
+ stdout: string;
3984
+ /** Standard error */
3985
+ stderr: string;
3986
+ /** Execution duration in milliseconds */
3987
+ durationMs: number;
3988
+ /** Whether output was truncated due to size limits */
3989
+ truncated: boolean;
3990
+ }
3991
+ /**
3992
+ * Options for glob file search.
3993
+ */
3994
+ interface GlobOptions {
3995
+ /** Working directory for the search */
3996
+ cwd?: string | undefined;
3997
+ /** Glob patterns to exclude */
3998
+ ignore?: string[] | undefined;
3999
+ }
4000
+ /**
4001
+ * Options for grep content search.
4002
+ */
4003
+ interface GrepOptions {
4004
+ /** Working directory for the search */
4005
+ cwd?: string | undefined;
4006
+ /** File glob patterns to include (e.g., "*.ts") */
4007
+ include?: string[] | undefined;
4008
+ /** Maximum number of matches to return */
4009
+ maxResults?: number | undefined;
4010
+ /** Number of context lines around each match */
4011
+ contextLines?: number | undefined;
4012
+ }
4013
+ /**
4014
+ * A single grep match result.
4015
+ */
4016
+ interface GrepMatch {
4017
+ /** File path (relative to search root) */
4018
+ path: string;
4019
+ /** Line number of the match */
4020
+ line: number;
4021
+ /** The matching line text */
4022
+ text: string;
4023
+ /** Context lines around the match */
4024
+ context?: string | undefined;
4025
+ }
4026
+ /**
4027
+ * Metadata about an execution environment.
4028
+ */
4029
+ interface EnvironmentInfo {
4030
+ /** Environment type */
4031
+ type: 'local' | 'docker' | 'e2b';
4032
+ /** Current working directory */
4033
+ cwd: string;
4034
+ /** Sandbox/container identifier (container ID for Docker, sandbox ID for E2B) */
4035
+ sandboxId?: string | undefined;
4036
+ /** Operating system info */
4037
+ os?: string | undefined;
4038
+ }
4039
+ /**
4040
+ * Configuration for a Docker execution environment.
4041
+ */
4042
+ interface DockerEnvironmentConfig {
4043
+ /** Docker image to use (e.g., "node:20-slim") */
4044
+ image: string;
4045
+ /** Host directory to mount as workspace */
4046
+ workspaceDir: string;
4047
+ /** Working directory inside the container (default: "/workspace") */
4048
+ containerWorkdir?: string | undefined;
4049
+ /** Environment variables to set in the container */
4050
+ env?: Record<string, string> | undefined;
4051
+ /** Memory limit (e.g., "512m", "2g") */
4052
+ memory?: string | undefined;
4053
+ /** CPU limit (e.g., "1", "0.5") */
4054
+ cpus?: string | undefined;
4055
+ /** Network mode (default: "none") */
4056
+ network?: string | undefined;
4057
+ /** Command to run after container creation (e.g., "npm install") */
4058
+ setupCommand?: string | undefined;
4059
+ }
4060
+ /**
4061
+ * Configuration for an E2B execution environment.
4062
+ */
4063
+ interface E2BEnvironmentConfig {
4064
+ /** E2B template name (default: "base") */
4065
+ template?: string | undefined;
4066
+ /** E2B API key (defaults to E2B_API_KEY env var) */
4067
+ apiKey?: string | undefined;
4068
+ /** Sandbox timeout in seconds (default: 3600) */
4069
+ timeout?: number | undefined;
4070
+ /** Working directory inside the sandbox */
4071
+ cwd?: string | undefined;
4072
+ /** Environment variables */
4073
+ env?: Record<string, string> | undefined;
4074
+ /** Setup command to run after sandbox creation */
4075
+ setupCommand?: string | undefined;
4076
+ }
4077
+ /**
4078
+ * Configuration for a local execution environment.
4079
+ */
4080
+ interface LocalEnvironmentConfig {
4081
+ /** Working directory (default: process.cwd()) */
4082
+ cwd?: string | undefined;
4083
+ /** Restrict file operations to this directory */
4084
+ pathRestriction?: string | undefined;
4085
+ }
4086
+ /**
4087
+ * Configuration for the exec tool's security and behavior.
4088
+ */
4089
+ interface ExecToolConfig {
4090
+ /** Security mode: allow-always (default), allowlist, or always require approval */
4091
+ security?: 'allow-always' | 'allowlist' | 'approval-always' | undefined;
4092
+ /** Allowed command patterns (for allowlist mode) */
4093
+ allowlist?: string[] | undefined;
4094
+ /** Default command timeout in seconds (default: 300) */
4095
+ timeout?: number | undefined;
4096
+ /** Maximum output characters before truncation (default: 100000) */
4097
+ maxOutputChars?: number | undefined;
4098
+ }
4099
+ /**
4100
+ * Configuration for the sandboxTools() factory.
4101
+ */
4102
+ interface SandboxToolsConfig {
4103
+ /** Environment type (default: "docker") */
4104
+ env?: 'local' | 'docker' | 'e2b' | undefined;
4105
+ /** Working directory override */
4106
+ cwd?: string | undefined;
4107
+ /** Subset of tools to include (default: all) */
4108
+ tools?: ('exec' | 'read' | 'write' | 'edit' | 'glob' | 'grep')[] | undefined;
4109
+ /** Docker environment configuration */
4110
+ docker?: DockerEnvironmentConfig | undefined;
4111
+ /** E2B environment configuration */
4112
+ e2b?: E2BEnvironmentConfig | undefined;
4113
+ /** Local environment configuration */
4114
+ local?: LocalEnvironmentConfig | undefined;
4115
+ /** Exec tool configuration */
4116
+ exec?: ExecToolConfig | undefined;
4117
+ /** Approval mode for file-mutating tools (write, edit). Defaults to 'always' for local env. */
4118
+ fileApproval?: 'always' | 'none' | undefined;
4119
+ }
4120
+
4121
+ /**
4122
+ * Sandbox tools factory.
4123
+ *
4124
+ * Creates a set of tools (exec, read, write, edit, glob, grep) that share
4125
+ * a lazily-initialized execution environment via closure. The environment
4126
+ * is created on first tool use and reused for all subsequent calls.
4127
+ *
4128
+ * @example
4129
+ * ```typescript
4130
+ * import { defineAgent, sandboxTools } from '@polos/sdk';
4131
+ *
4132
+ * const agent = defineAgent({
4133
+ * id: 'solver',
4134
+ * tools: sandboxTools({
4135
+ * env: 'docker',
4136
+ * docker: { image: 'node:20', workspaceDir: '/path/to/project' },
4137
+ * }),
4138
+ * });
4139
+ * ```
4140
+ */
4141
+
4142
+ /**
4143
+ * Return type for sandboxTools — an array of ToolWorkflow with a cleanup method.
4144
+ */
4145
+ interface SandboxToolsResult extends Array<ToolWorkflow> {
4146
+ /** Destroy the shared execution environment (remove container, etc.) */
4147
+ cleanup(): Promise<void>;
4148
+ }
4149
+ /**
4150
+ * Create sandbox tools for AI agents.
4151
+ *
4152
+ * Returns an array of ToolWorkflow that can be passed directly to defineAgent().
4153
+ * All tools share a single execution environment that is lazily created on first use.
4154
+ *
4155
+ * The returned array has a `cleanup()` method for destroying the environment.
4156
+ */
4157
+ declare function sandboxTools(config?: SandboxToolsConfig): SandboxToolsResult;
4158
+
4159
+ /**
4160
+ * Docker execution environment.
4161
+ *
4162
+ * Runs commands inside a Docker container and accesses files via bind mount
4163
+ * for optimal performance. The container runs `sleep infinity` and commands
4164
+ * are executed via `docker exec`.
4165
+ */
4166
+
4167
+ /**
4168
+ * Docker-based execution environment.
4169
+ *
4170
+ * Creates a persistent Docker container with a bind-mounted workspace.
4171
+ * Commands run inside the container via `docker exec`, while file
4172
+ * operations use the host filesystem through the bind mount for speed.
4173
+ */
4174
+ declare class DockerEnvironment implements ExecutionEnvironment {
4175
+ readonly type: "docker";
4176
+ private containerId;
4177
+ private containerName;
4178
+ private readonly config;
4179
+ private readonly containerWorkdir;
4180
+ private readonly maxOutputChars;
4181
+ constructor(config: DockerEnvironmentConfig, maxOutputChars?: number);
4182
+ initialize(): Promise<void>;
4183
+ exec(command: string, opts?: ExecOptions): Promise<ExecResult>;
4184
+ readFile(filePath: string): Promise<string>;
4185
+ writeFile(filePath: string, content: string): Promise<void>;
4186
+ fileExists(filePath: string): Promise<boolean>;
4187
+ glob(pattern: string, opts?: GlobOptions): Promise<string[]>;
4188
+ grep(pattern: string, opts?: GrepOptions): Promise<GrepMatch[]>;
4189
+ destroy(): Promise<void>;
4190
+ getCwd(): string;
4191
+ getInfo(): EnvironmentInfo;
4192
+ /**
4193
+ * Translate a container path to the corresponding host filesystem path.
4194
+ * Validates the path stays within the workspace to prevent traversal.
4195
+ */
4196
+ toHostPath(containerPath: string): string;
4197
+ /**
4198
+ * Translate a host filesystem path to the corresponding container path.
4199
+ */
4200
+ toContainerPath(hostPath: string): string;
4201
+ private assertInitialized;
4202
+ }
4203
+
4204
+ /**
4205
+ * Evaluate a command against an allowlist of glob patterns.
4206
+ *
4207
+ * Matches the full command string against each pattern.
4208
+ * Patterns support `*` wildcards (e.g., `node *`, `npm *`, `*`).
4209
+ *
4210
+ * @param command - The shell command to check
4211
+ * @param patterns - Array of glob patterns to match against
4212
+ * @returns Whether the command matches any pattern in the allowlist
4213
+ */
4214
+ declare function evaluateAllowlist(command: string, patterns: string[]): boolean;
4215
+ /**
4216
+ * Assert that a file path stays within a restriction directory.
4217
+ * Throws if path traversal is detected.
4218
+ *
4219
+ * @param filePath - The file path to check
4220
+ * @param restriction - The base directory paths must stay within
4221
+ * @throws Error if the resolved path escapes the restriction directory
4222
+ */
4223
+ declare function assertSafePath(filePath: string, restriction: string): void;
4224
+
4225
+ /**
4226
+ * Output utilities for the execution framework.
4227
+ *
4228
+ * Provides functions for truncating large outputs, detecting binary content,
4229
+ * parsing grep output, and stripping ANSI escape codes.
4230
+ */
4231
+
4232
+ /**
4233
+ * Truncate output that exceeds the maximum character limit.
4234
+ *
4235
+ * Keeps the first 20K characters (head) and last 80K characters (tail)
4236
+ * of a 100K max, with a truncation message in between.
4237
+ */
4238
+ declare function truncateOutput(output: string, maxChars?: number): {
4239
+ text: string;
4240
+ truncated: boolean;
4241
+ };
4242
+ /**
4243
+ * Detect binary content by checking for null bytes in the first 8KB.
4244
+ */
4245
+ declare function isBinary(buffer: Buffer): boolean;
4246
+ /**
4247
+ * Parse `grep -rn` output into structured GrepMatch objects.
4248
+ *
4249
+ * Expected format: `filepath:linenum:matched text`
4250
+ */
4251
+ declare function parseGrepOutput(output: string): GrepMatch[];
4252
+ /**
4253
+ * Strip ANSI escape codes from text.
4254
+ */
4255
+ declare function stripAnsi(text: string): string;
4256
+
4257
+ /**
4258
+ * Exec tool — run shell commands inside the execution environment.
4259
+ */
4260
+
4261
+ /**
4262
+ * Create the exec tool for running shell commands.
4263
+ */
4264
+ declare function createExecTool(getEnv: () => Promise<ExecutionEnvironment>, config?: ExecToolConfig): ToolWorkflow;
4265
+
4266
+ /**
4267
+ * Path-based approval for read-only sandbox tools.
4268
+ *
4269
+ * When pathRestriction is set, read-only tools (read, glob, grep) allow
4270
+ * operations within the restricted path without approval. Operations
4271
+ * outside the restriction suspend for user approval.
4272
+ */
4273
+
4274
+ /**
4275
+ * Configuration for path-restricted approval on read-only tools.
4276
+ */
4277
+ interface PathRestrictionConfig {
4278
+ /** Directory to allow without approval. Paths outside require approval. */
4279
+ pathRestriction: string;
4280
+ }
4281
+
4282
+ /**
4283
+ * Read tool — read file contents from the execution environment.
4284
+ *
4285
+ * When pathRestriction is set, reads within the restriction proceed
4286
+ * without approval. Reads outside the restriction suspend for user approval.
4287
+ */
4288
+
4289
+ /**
4290
+ * Create the read tool for reading file contents.
4291
+ */
4292
+ declare function createReadTool(getEnv: () => Promise<ExecutionEnvironment>, pathConfig?: PathRestrictionConfig): ToolWorkflow;
4293
+
4294
+ /**
4295
+ * Write tool — create or overwrite files in the execution environment.
4296
+ */
4297
+
4298
+ /**
4299
+ * Create the write tool for writing file contents.
4300
+ */
4301
+ declare function createWriteTool(getEnv: () => Promise<ExecutionEnvironment>, approval?: ToolApproval): ToolWorkflow;
4302
+
4303
+ /**
4304
+ * Edit tool — find-and-replace text in files in the execution environment.
4305
+ */
4306
+
4307
+ /**
4308
+ * Create the edit tool for find-and-replace in files.
4309
+ */
4310
+ declare function createEditTool(getEnv: () => Promise<ExecutionEnvironment>, approval?: ToolApproval): ToolWorkflow;
4311
+
4312
+ /**
4313
+ * Glob tool — find files by pattern in the execution environment.
4314
+ *
4315
+ * When pathRestriction is set, searches within the restriction proceed
4316
+ * without approval. Custom cwd outside the restriction suspends for approval.
4317
+ */
4318
+
4319
+ /**
4320
+ * Create the glob tool for finding files by pattern.
4321
+ */
4322
+ declare function createGlobTool(getEnv: () => Promise<ExecutionEnvironment>, pathConfig?: PathRestrictionConfig): ToolWorkflow;
4323
+
4324
+ /**
4325
+ * Grep tool — search file contents by pattern in the execution environment.
4326
+ *
4327
+ * When pathRestriction is set, searches within the restriction proceed
4328
+ * without approval. Custom cwd outside the restriction suspends for approval.
4329
+ */
4330
+
4331
+ /**
4332
+ * Create the grep tool for searching file contents.
4333
+ */
4334
+ declare function createGrepTool(getEnv: () => Promise<ExecutionEnvironment>, pathConfig?: PathRestrictionConfig): ToolWorkflow;
4335
+
4336
+ export { type Agent, type AgentConfig, type AgentContext, type AgentResult, AgentRunConfig, type AgentRunOptions, type AgentRunPayload, type AgentStep, type AgentStream, type AgentStreamEvent, type AgentStreamPayload, type AgentStreamResult, type AgentWorkflow, type BatchEventPayload, type BatchStepResult, type BatchWorkflowInput, type ClientBatchWorkflowInput, type ClientInvokeOptions, type CoreMessage$1 as CoreMessage, type DefineAgentConfig, type DefineGuardrailOptions, type DefineHookOptions, type DefineToolConfig, DockerEnvironment, type DockerEnvironmentConfig, DuplicateWorkflowError, type E2BEnvironmentConfig, type EnvironmentInfo, type Event, type EventData, type EventItem, type EventPayload, type EventTriggerPayload, type EventsApi, type ExecOptions, type ExecResult, type ExecToolConfig, type ExecuteGuardrailsOptions, type ExecuteHooksOptions, type ExecuteWorkflowOptions, type ExecutionContext, type ExecutionData, type ExecutionEnvironment, ExecutionHandle, type ExecutionHandleFields, type ExecutionResult, type FinishReason, type GenerateConfig, type GlobOptions, type GrepMatch, type GrepOptions, type Guardrail$1 as Guardrail, type GuardrailChainResult, type GuardrailContext$1 as GuardrailContext, GuardrailError, type GuardrailHandler, GuardrailResult$1 as GuardrailResult, type GuardrailResultType, type Hook, type HookChainResult, type HookContext, HookExecutionError, type HookHandler, HookResult, type HookResultType, type InferPayload, type InferResult, type InferState, type InvokeOptions, LLM, type LLMGenerateOptions, type LLMGeneratePayload, type LLMGenerateResult, type LLMProvider, type LLMResponse, type LLMStreamEvent, type LLMStreamPayload, type LLMToolCall, type LLMToolResult, type LLMUsage, type LlmToolDefinition, type LocalEnvironmentConfig, type Logger, type Guardrail as MiddlewareGuardrail, type GuardrailContext as MiddlewareGuardrailContext, GuardrailResult as MiddlewareGuardrailResult, OrchestratorApiError, OrchestratorClient, type OrchestratorClientConfig, type OtelConfig, PolosClient, type PolosClientConfig, type PublishEventFn, type PublishEventOptions, Queue, type QueueConfig$1 as QueueConfig, type QueueOptions, type ResumeOptions, type SandboxToolsConfig, type SandboxToolsResult, type ScheduleConfig, type SchedulePayload, type SchedulesApi, StateSizeError, StateValidationError, StepExecutionError, type StepHelper, type StepInfo, type StepOptions, type StepStore, type StopCondition, type StopConditionContext, type StreamEvent, StreamResult, type StreamTopicOptions, type StreamWorkflowOptions, type SuspendOptions, type TavilySearchConfig, type TextDeltaEvent, type TokenUsage, type Tool, type ToolApproval, type ToolCall, type ToolCallEvent, type ToolConfig, type ToolHandler, type ToolResult, type ToolResultInfo, type ToolWorkflow, WaitError, type WaitForEventOptions, type WaitForOptions, type WebSearchFunction, type WebSearchOptions, type WebSearchResult, type WebSearchResultItem, type WebSearchToolConfig, Worker, type WorkerConfig, type WorkerExecutionData, WorkerServer, type WorkerServerConfig, type Workflow, type WorkflowConfig, type WorkflowContext, type WorkflowEvent, type WorkflowHandle, type WorkflowHandler, WorkflowNotFoundError, type WorkflowRegistry, type WorkflowRunClient, type WorkflowRunOptions, type WorkflowStatus, agentStreamFunction, assertSafePath, batchAgentInvoke, batchInvoke, composeGuardrails, composeHooks, conditionalHook, convertFinishReason, convertMiddlewareToolCallToPython, convertPythonToolCallToMiddleware, convertToolResultsToMessages, convertToolsToVercel, convertVercelToolCallToPython, convertVercelUsageToPython, createAskUserTool, createEditTool, createExecTool, createGlobTool, createGrepTool, createLogger, createReadTool, createStepHelper, createStepStore, createWebSearchTool, createWorkflowRegistry, createWriteTool, defineAgent, defineGuardrail, defineHook, defineTool, defineWorkflow, evaluateAllowlist, executeGuardrailChain, executeGuardrailsOrThrow, executeHookChain, executeHooksOrThrow, executeWorkflow, executedTool, extractTraceparent, generateTraceIdFromExecutionId, getTracer, globalRegistry, hasText, initializeOtel, initializeState, isAgentWorkflow, isBinary, isGuardrail, isHook, isOtelAvailable, isToolWorkflow, isWaitError, llmGenerate, llmStream, maxSteps, maxTokens, normalizeGuardrail, normalizeGuardrails, normalizeHook, normalizeHooks, parseGrepOutput, retry, sandboxTools, serializeFinalState, sleep, stopCondition, stripAnsi, truncateOutput, validateState };