This commit is contained in:
闫旭隆
2026-01-09 11:22:42 +08:00
parent f4314c3ede
commit 202d1cb5ba
1066 changed files with 179639 additions and 7618 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,156 @@
/**
* Sandbox types for the Claude Code Agent SDK
*
* This file is the single source of truth for sandbox configuration types.
* Both the SDK and the settings validation import from here.
*/
import { z } from 'zod';
/**
* Network configuration schema for sandbox.
*/
export declare const SandboxNetworkConfigSchema: z.ZodOptional<z.ZodObject<{
allowedDomains: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
allowAllUnixSockets: z.ZodOptional<z.ZodBoolean>;
allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
httpProxyPort: z.ZodOptional<z.ZodNumber>;
socksProxyPort: z.ZodOptional<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
allowedDomains?: string[];
allowUnixSockets?: string[];
allowAllUnixSockets?: boolean;
allowLocalBinding?: boolean;
httpProxyPort?: number;
socksProxyPort?: number;
}, {
allowedDomains?: string[];
allowUnixSockets?: string[];
allowAllUnixSockets?: boolean;
allowLocalBinding?: boolean;
httpProxyPort?: number;
socksProxyPort?: number;
}>>;
/**
* Sandbox settings schema.
*/
export declare const SandboxSettingsSchema: z.ZodObject<{
enabled: z.ZodOptional<z.ZodBoolean>;
autoAllowBashIfSandboxed: z.ZodOptional<z.ZodBoolean>;
allowUnsandboxedCommands: z.ZodOptional<z.ZodBoolean>;
network: z.ZodOptional<z.ZodObject<{
allowedDomains: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
allowAllUnixSockets: z.ZodOptional<z.ZodBoolean>;
allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
httpProxyPort: z.ZodOptional<z.ZodNumber>;
socksProxyPort: z.ZodOptional<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
allowedDomains?: string[];
allowUnixSockets?: string[];
allowAllUnixSockets?: boolean;
allowLocalBinding?: boolean;
httpProxyPort?: number;
socksProxyPort?: number;
}, {
allowedDomains?: string[];
allowUnixSockets?: string[];
allowAllUnixSockets?: boolean;
allowLocalBinding?: boolean;
httpProxyPort?: number;
socksProxyPort?: number;
}>>;
ignoreViolations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
enableWeakerNestedSandbox: z.ZodOptional<z.ZodBoolean>;
excludedCommands: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
ripgrep: z.ZodOptional<z.ZodObject<{
command: z.ZodString;
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
command?: string;
args?: string[];
}, {
command?: string;
args?: string[];
}>>;
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
enabled: z.ZodOptional<z.ZodBoolean>;
autoAllowBashIfSandboxed: z.ZodOptional<z.ZodBoolean>;
allowUnsandboxedCommands: z.ZodOptional<z.ZodBoolean>;
network: z.ZodOptional<z.ZodObject<{
allowedDomains: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
allowAllUnixSockets: z.ZodOptional<z.ZodBoolean>;
allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
httpProxyPort: z.ZodOptional<z.ZodNumber>;
socksProxyPort: z.ZodOptional<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
allowedDomains?: string[];
allowUnixSockets?: string[];
allowAllUnixSockets?: boolean;
allowLocalBinding?: boolean;
httpProxyPort?: number;
socksProxyPort?: number;
}, {
allowedDomains?: string[];
allowUnixSockets?: string[];
allowAllUnixSockets?: boolean;
allowLocalBinding?: boolean;
httpProxyPort?: number;
socksProxyPort?: number;
}>>;
ignoreViolations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
enableWeakerNestedSandbox: z.ZodOptional<z.ZodBoolean>;
excludedCommands: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
ripgrep: z.ZodOptional<z.ZodObject<{
command: z.ZodString;
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
command?: string;
args?: string[];
}, {
command?: string;
args?: string[];
}>>;
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
enabled: z.ZodOptional<z.ZodBoolean>;
autoAllowBashIfSandboxed: z.ZodOptional<z.ZodBoolean>;
allowUnsandboxedCommands: z.ZodOptional<z.ZodBoolean>;
network: z.ZodOptional<z.ZodObject<{
allowedDomains: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
allowAllUnixSockets: z.ZodOptional<z.ZodBoolean>;
allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
httpProxyPort: z.ZodOptional<z.ZodNumber>;
socksProxyPort: z.ZodOptional<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
allowedDomains?: string[];
allowUnixSockets?: string[];
allowAllUnixSockets?: boolean;
allowLocalBinding?: boolean;
httpProxyPort?: number;
socksProxyPort?: number;
}, {
allowedDomains?: string[];
allowUnixSockets?: string[];
allowAllUnixSockets?: boolean;
allowLocalBinding?: boolean;
httpProxyPort?: number;
socksProxyPort?: number;
}>>;
ignoreViolations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
enableWeakerNestedSandbox: z.ZodOptional<z.ZodBoolean>;
excludedCommands: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
ripgrep: z.ZodOptional<z.ZodObject<{
command: z.ZodString;
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
command?: string;
args?: string[];
}, {
command?: string;
args?: string[];
}>>;
}, z.ZodTypeAny, "passthrough">>;
export type SandboxSettings = z.infer<typeof SandboxSettingsSchema>;
export type SandboxNetworkConfig = NonNullable<z.infer<typeof SandboxNetworkConfigSchema>>;
export type SandboxIgnoreViolations = NonNullable<SandboxSettings['ignoreViolations']>;

View File

@ -0,0 +1,105 @@
import { type AccountInfo, type PermissionMode, type SDKMessage, type SDKUserMessage, type HookInput, type HookEvent, type PermissionUpdate, type ModelInfo, type SlashCommand, type AgentDefinition, type McpServerConfigForProcessTransport } from './agentSdkTypes.js';
import type { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
export type SDKControlInitializeRequest = {
subtype: 'initialize';
hooks?: Partial<Record<HookEvent, SDKHookCallbackMatcher[]>>;
sdkMcpServers?: string[];
jsonSchema?: Record<string, unknown>;
systemPrompt?: string;
appendSystemPrompt?: string;
agents?: Record<string, AgentDefinition>;
};
export type SDKControlInitializeResponse = {
commands: SlashCommand[];
output_style: string;
available_output_styles: string[];
models: ModelInfo[];
account: AccountInfo;
};
export type SDKControlInterruptRequest = {
subtype: 'interrupt';
};
export type SDKControlPermissionRequest = {
subtype: 'can_use_tool';
tool_name: string;
input: Record<string, unknown>;
permission_suggestions?: PermissionUpdate[];
blocked_path?: string;
decision_reason?: string;
tool_use_id: string;
agent_id?: string;
};
export type SDKControlSetPermissionModeRequest = {
subtype: 'set_permission_mode';
mode: PermissionMode;
};
export type SDKControlSetModelRequest = {
subtype: 'set_model';
model?: string;
};
export type SDKControlSetMaxThinkingTokensRequest = {
subtype: 'set_max_thinking_tokens';
max_thinking_tokens: number | null;
};
export type SDKControlMcpStatusRequest = {
subtype: 'mcp_status';
};
export type SDKControlRewindFilesRequest = {
subtype: 'rewind_files';
user_message_id: string;
};
export type SDKHookCallbackMatcher = {
matcher?: string;
hookCallbackIds: string[];
/** Timeout in seconds for all hooks in this matcher */
timeout?: number;
};
export type SDKHookCallbackRequest = {
subtype: 'hook_callback';
callback_id: string;
input: HookInput;
tool_use_id?: string;
};
export type SDKControlMcpMessageRequest = {
subtype: 'mcp_message';
server_name: string;
message: JSONRPCMessage;
};
export type SDKControlMcpSetServersRequest = {
subtype: 'mcp_set_servers';
servers: Record<string, McpServerConfigForProcessTransport>;
};
export type SDKControlMcpSetServersResponse = {
added: string[];
removed: string[];
errors: Record<string, string>;
};
export type SDKControlRequest = {
type: 'control_request';
request_id: string;
request: SDKControlInterruptRequest | SDKControlPermissionRequest | SDKControlInitializeRequest | SDKControlSetPermissionModeRequest | SDKControlSetModelRequest | SDKControlSetMaxThinkingTokensRequest | SDKControlMcpStatusRequest | SDKHookCallbackRequest | SDKControlMcpMessageRequest | SDKControlRewindFilesRequest | SDKControlMcpSetServersRequest;
};
export type SDKControlResponse = {
type: 'control_response';
response: ControlResponse | ControlErrorResponse;
};
export type ControlResponse = {
subtype: 'success';
request_id: string;
response?: Record<string, unknown>;
};
export type ControlErrorResponse = {
subtype: 'error';
request_id: string;
error: string;
pending_permission_requests?: SDKControlRequest[];
};
export type SDKControlCancelRequest = {
type: 'control_cancel_request';
request_id: string;
};
export type SDKKeepAliveMessage = {
type: 'keep_alive';
};
export type StdoutMessage = SDKMessage | SDKControlResponse | SDKControlRequest | SDKControlCancelRequest | SDKKeepAliveMessage;
export type StdinMessage = SDKUserMessage | SDKControlRequest | SDKControlResponse | SDKKeepAliveMessage;