import {z} from 'zod' export type AnthropicBeta = string | 'message-batches-2024-09-24' | 'prompt-caching-2024-07-31' | 'computer-use-2024-10-22' | 'computer-use-2025-01-24' | 'pdfs-2024-09-25' | 'token-counting-2024-11-01' | 'token-efficient-tools-2025-02-19' | 'output-128k-2025-02-19' | 'files-api-2025-04-14' | 'mcp-client-2025-04-04' | 'mcp-client-2025-11-20' | 'dev-full-thinking-2025-05-14' | 'interleaved-thinking-2025-05-14' | 'code-execution-2025-05-22' | 'extended-cache-ttl-2025-04-11' | 'context-1m-2025-08-07' | 'context-management-2025-06-27' | 'model-context-window-exceeded-2025-08-26' | 'skills-2025-10-02' | 'fast-mode-2026-02-01' | 'output-300k-2026-03-24' | 'user-profiles-2026-03-24' | 'user-profiles-2026-08-18' | 'user-profiles-2026-09-04' | 'advisor-tool-2026-03-01' | 'managed-agents-2026-04-01' | 'cache-diagnosis-2026-04-07' | 'dreaming-2026-04-21' | 'thinking-token-count-2026-05-13' | 'server-side-fallback-2026-06-01' | 'server-side-fallback-2026-07-01' | 'fallback-credit-2026-06-01' | 'fallback-credit-2026-07-01' | 'agent-memory-2026-07-22' | 'mid-conversation-tool-changes-2026-07-01' | 'compact-2026-01-12' | 'computer-use-2025-11-24' | 'mcp-tunnels-2026-06-22' | 'structured-outputs-2025-11-13' | 'task-budgets-2026-03-13' | 'thinking-display-updates-2026-08-18' | 'ce-user-management-2026-07-13' | 'mid-conversation-output-config-2026-07-01' | 'thinking-binding-controls-2026-08-01' | 'mid-conversation-system-clear-at-2026-08-21' | 'compact-2026-09-04' | 'inline-tools-2026-09-15' | 'mcp-client-2026-09-15' | 'ce-plugins-2026-09-01' | 'spend-limit-reads-2026-09-26' | 'telemetry-destinations-2026-08-11' | 'webhooks-2026-10-07' | 'admin-user-sign-out-2026-10-08' | 'message-threads-2026-08-12' | 'analytics-usage-cost-2026-08-24' | 'experimental-claude-tag-2026-10-21'; export type GetApiV1SessionsSessionIdThreadsThreadIdEventsBetaTrueArgs = {'anthropic-version'?: string | undefined, 'anthropic-beta'?: Array | undefined, session_id: string, thread_id: string, limit?: number | undefined, page?: string | undefined, 'anthropic-workspace-id'?: string | undefined}; export type GetApiV1SessionsSessionIdThreadsThreadIdEventsBetaTrueOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const betaManagedAgentsImageSource = z.discriminatedUnion("type", [z.object({type: z.literal("base64"), media_type: z.string().min(1), data: z.string().min(1)}), z.object({type: z.literal("url"), url: z.string().min(1)}), z.object({type: z.literal("file"), file_id: z.string().min(1)})]); export const betaManagedAgentsDocumentSource = z.discriminatedUnion("type", [z.object({type: z.literal("base64"), media_type: z.string().min(1), data: z.string().min(1)}), z.object({type: z.literal("text"), media_type: z.literal("text/plain"), data: z.string().min(1)}), z.object({type: z.literal("url"), url: z.string().min(1)}), z.object({type: z.literal("file"), file_id: z.string().min(1)})]); export const betaManagedAgentsUserContentBlock = z.discriminatedUnion("type", [z.object({type: z.literal("text"), text: z.string().min(1)}), z.object({type: z.literal("image"), source: betaManagedAgentsImageSource}), z.object({type: z.literal("document"), source: betaManagedAgentsDocumentSource, title: z.string().nullable().optional(), context: z.string().nullable().optional()}), z.object({type: z.literal("redacted")})]); export const betaTimestamp = z.string(); export const betaManagedAgentsUserToolConfirmationResult = z.enum(["allow", "deny"]); export const betaManagedAgentsSearchResultContent = z.object({type: z.literal("text"), text: z.string().min(1)}); export const betaManagedAgentsSearchResultCitations = z.object({enabled: z.boolean()}); export const betaManagedAgentsToolResultContentBlock = z.discriminatedUnion("type", [z.object({type: z.literal("text"), text: z.string().min(1)}), z.object({type: z.literal("image"), source: betaManagedAgentsImageSource}), z.object({type: z.literal("document"), source: betaManagedAgentsDocumentSource, title: z.string().nullable().optional(), context: z.string().nullable().optional()}), z.object({type: z.literal("search_result"), source: z.string().min(1), title: z.string().min(1), content: z.array(betaManagedAgentsSearchResultContent), citations: betaManagedAgentsSearchResultCitations})]); export const betaManagedAgentsStruct = z.record(z.string(), z.unknown()); export const betaManagedAgentsAgentMessageContentBlock = z.discriminatedUnion("type", [z.object({type: z.literal("text"), text: z.string().min(1)}), z.object({type: z.literal("redacted")})]); export const betaManagedAgentsAgentEvaluatedPermission = z.enum(["allow", "ask", "deny"]); export const betaManagedAgentsAgentToolEvaluationAlwaysAllow = z.object({type: z.literal("always_allow")}); export const betaManagedAgentsAgentToolEvaluationAlwaysAsk = z.object({type: z.literal("always_ask")}); export const betaManagedAgentsAgentAutoEvaluatedPermissionAllow = z.object({type: z.literal("allow")}); export const betaManagedAgentsAgentAutoEvaluatedPermissionAsk = z.object({type: z.literal("ask"), reason_code: z.string().max(64)}); export const betaManagedAgentsAgentAutoEvaluatedPermissionDeny = z.object({type: z.literal("deny"), reason_code: z.string().max(64)}); export const betaManagedAgentsAgentAutoEvaluatedPermission = z.discriminatedUnion("type", [betaManagedAgentsAgentAutoEvaluatedPermissionAllow, betaManagedAgentsAgentAutoEvaluatedPermissionAsk, betaManagedAgentsAgentAutoEvaluatedPermissionDeny]); export const betaManagedAgentsAgentToolEvaluationAuto = z.object({type: z.literal("auto"), evaluated_permission: betaManagedAgentsAgentAutoEvaluatedPermission}); export const betaManagedAgentsAgentToolEvaluation = z.discriminatedUnion("type", [betaManagedAgentsAgentToolEvaluationAlwaysAllow, betaManagedAgentsAgentToolEvaluationAlwaysAsk, betaManagedAgentsAgentToolEvaluationAuto]); export const betaManagedAgentsRetryStatus = z.discriminatedUnion("type", [z.object({type: z.literal("retrying")}), z.object({type: z.literal("exhausted")}), z.object({type: z.literal("terminal")})]); export const betaManagedAgentsSessionStopDetails = z.object({type: z.literal("refusal"), category: z.enum(["cyber", "bio", "frontier_llm", "reasoning_extraction", "general_harms"]).nullable(), explanation: z.string().nullable()}); export const betaManagedAgentsSpanModelUsage = z.object({input_tokens: z.number().int(), output_tokens: z.number().int(), cache_creation_input_tokens: z.number().int(), cache_read_input_tokens: z.number().int(), speed: z.enum(["standard", "fast"]).nullable().optional()}); export const betaManagedAgentsFileRubric = z.object({type: z.literal("file"), file_id: z.string()}); export const betaManagedAgentsTextRubric = z.object({type: z.literal("text"), content: z.string()}); export const betaManagedAgentsRubric = z.discriminatedUnion("type", [betaManagedAgentsFileRubric, betaManagedAgentsTextRubric]); export const betaManagedAgentsModel = z.union([z.literal("claude-haiku-5-5"), z.literal("claude-sonnet-5-5"), z.literal("claude-opus-5-5"), z.literal("claude-fable-5-1"), z.literal("claude-sonnet-5"), z.literal("claude-fable-5"), z.literal("claude-opus-5"), z.literal("claude-opus-4-8"), z.literal("claude-opus-4-7"), z.literal("claude-opus-4-6"), z.literal("claude-sonnet-4-6"), z.literal("claude-haiku-4-5"), z.literal("claude-haiku-4-5-20251001"), z.literal("claude-opus-4-5"), z.literal("claude-opus-4-5-20251101"), z.literal("claude-sonnet-4-5"), z.literal("claude-sonnet-4-5-20250929"), z.string()]); export const betaManagedAgentsSpeed = z.enum(["standard", "fast"]); export const betaManagedAgentsEffort = z.discriminatedUnion("type", [z.object({type: z.literal("low")}), z.object({type: z.literal("medium")}), z.object({type: z.literal("high")}), z.object({type: z.literal("xhigh")}), z.object({type: z.literal("max")})]); export const betaManagedAgentsModelConfig = z.object({id: betaManagedAgentsModel, speed: betaManagedAgentsSpeed.optional(), effort: betaManagedAgentsEffort.optional(), inference_geo: z.string().optional()}); export const betaManagedAgentsPermissionPolicy = z.discriminatedUnion("type", [z.object({type: z.literal("always_allow")}), z.object({type: z.literal("always_ask")}), z.object({type: z.literal("auto")})]); export const betaManagedAgentsAgentToolsetDefaultConfig = z.object({enabled: z.boolean(), permission_policy: betaManagedAgentsPermissionPolicy}); export const betaManagedAgentsWebFetchUrlSourceUserInput = z.discriminatedUnion("type", [z.object({type: z.literal("all")}), z.object({type: z.literal("none")})]); export const betaManagedAgentsWebFetchUrlSourceToolReference = z.object({type: z.literal("tool_reference"), name: z.string().min(1).max(128)}); export const betaManagedAgentsWebFetchUrlSourceToolFilter = z.discriminatedUnion("type", [z.object({type: z.literal("all")}), z.object({type: z.literal("none")}), z.object({type: z.literal("only"), tools: z.array(betaManagedAgentsWebFetchUrlSourceToolReference)}), z.object({type: z.literal("except"), tools: z.array(betaManagedAgentsWebFetchUrlSourceToolReference)})]); export const betaManagedAgentsUserLocation = z.object({type: z.literal("approximate"), city: z.string().min(1).max(255).nullable().optional(), region: z.string().min(1).max(255).nullable().optional(), country: z.string().nullable().optional(), timezone: z.string().min(1).max(255).nullable().optional()}); export const betaManagedAgentsAgentToolConfigUnion = z.discriminatedUnion("type", [z.object({type: z.literal("bash"), name: z.literal("bash"), enabled: z.boolean(), permission_policy: betaManagedAgentsPermissionPolicy}), z.object({type: z.literal("edit"), name: z.literal("edit"), enabled: z.boolean(), permission_policy: betaManagedAgentsPermissionPolicy}), z.object({type: z.literal("read"), name: z.literal("read"), enabled: z.boolean(), permission_policy: betaManagedAgentsPermissionPolicy}), z.object({type: z.literal("write"), name: z.literal("write"), enabled: z.boolean(), permission_policy: betaManagedAgentsPermissionPolicy}), z.object({type: z.literal("glob"), name: z.literal("glob"), enabled: z.boolean(), permission_policy: betaManagedAgentsPermissionPolicy}), z.object({type: z.literal("grep"), name: z.literal("grep"), enabled: z.boolean(), permission_policy: betaManagedAgentsPermissionPolicy}), z.object({type: z.literal("web_fetch"), name: z.literal("web_fetch"), enabled: z.boolean(), permission_policy: betaManagedAgentsPermissionPolicy, allowed_domains: z.array(z.string()).optional(), blocked_domains: z.array(z.string()).optional(), max_content_tokens: z.number().int().nullable().optional(), url_sources: z.object({user_input: betaManagedAgentsWebFetchUrlSourceUserInput.nullable(), client_tool_results: betaManagedAgentsWebFetchUrlSourceToolFilter.nullable(), server_tool_results: betaManagedAgentsWebFetchUrlSourceToolFilter.nullable()}).nullable()}), z.object({type: z.literal("web_search"), name: z.literal("web_search"), enabled: z.boolean(), permission_policy: betaManagedAgentsPermissionPolicy, allowed_domains: z.array(z.string()).optional(), blocked_domains: z.array(z.string()).optional(), user_location: betaManagedAgentsUserLocation.nullable().optional()})]); export const betaManagedAgentsMCPToolsetDefaultConfig = z.object({enabled: z.boolean(), permission_policy: betaManagedAgentsPermissionPolicy}); export const betaManagedAgentsMCPToolConfig = z.object({name: z.string(), enabled: z.boolean(), permission_policy: betaManagedAgentsPermissionPolicy}); export const betaManagedAgentsCustomToolInputSchema = z.object({properties: z.record(z.string(), z.unknown()).nullable().optional(), required: z.array(z.string()).nullable().optional(), type: z.literal("object")}).and(z.record(z.string(), z.unknown())); export const betaManagedAgentsAgentTool = z.discriminatedUnion("type", [z.object({type: z.literal("agent_toolset_20260401"), default_config: betaManagedAgentsAgentToolsetDefaultConfig, configs: z.array(betaManagedAgentsAgentToolConfigUnion)}), z.object({type: z.literal("mcp_toolset"), mcp_server_name: z.string(), default_config: betaManagedAgentsMCPToolsetDefaultConfig, configs: z.array(betaManagedAgentsMCPToolConfig)}), z.object({type: z.literal("custom"), name: z.string(), description: z.string(), input_schema: betaManagedAgentsCustomToolInputSchema})]); export const betaManagedAgentsMCPServer = z.object({type: z.literal("url"), name: z.string(), url: z.string()}); export const betaManagedAgentsAnthropicSkill = z.object({type: z.literal("anthropic"), skill_id: z.string(), version: z.string()}); export const betaManagedAgentsCustomSkill = z.object({type: z.literal("custom"), skill_id: z.string(), version: z.string()}); export const betaManagedAgentsSkill = z.discriminatedUnion("type", [betaManagedAgentsAnthropicSkill, betaManagedAgentsCustomSkill]); export const betaManagedAgentsAwsRoleExecutionIdentity = z.object({type: z.literal("aws_role"), role_arn: z.string()}); export const betaManagedAgentsServiceAccountExecutionIdentity = z.object({type: z.literal("service_account")}); export const betaManagedAgentsExecutionIdentity = z.discriminatedUnion("type", [betaManagedAgentsAwsRoleExecutionIdentity, betaManagedAgentsServiceAccountExecutionIdentity]); export const betaManagedAgentsSessionThreadAgent = z.object({type: z.literal("agent"), id: z.string(), version: z.number().int(), name: z.string(), description: z.string().nullable(), model: betaManagedAgentsModelConfig, system: z.string().nullable(), tools: z.array(betaManagedAgentsAgentTool), mcp_servers: z.array(betaManagedAgentsMCPServer), skills: z.array(betaManagedAgentsSkill), execution_identity: betaManagedAgentsExecutionIdentity}); export const betaManagedAgentsAdvisor = z.object({type: z.literal("advisor"), model: z.string()}); export const betaManagedAgentsSessionRosterEntry = z.discriminatedUnion("type", [betaManagedAgentsSessionThreadAgent, betaManagedAgentsAdvisor]); export const betaManagedAgentsMultiagentInlineAgentsEnabled = z.object({type: z.literal("enabled")}); export const betaManagedAgentsMultiagentInlineAgentsDisabled = z.object({type: z.literal("disabled")}); export const betaManagedAgentsMultiagentInlineAgents = z.discriminatedUnion("type", [betaManagedAgentsMultiagentInlineAgentsEnabled, betaManagedAgentsMultiagentInlineAgentsDisabled]); export const betaManagedAgentsSessionMultiagentWorkflowsEnabled = z.object({type: z.literal("enabled"), inline_agents: betaManagedAgentsMultiagentInlineAgents, predefined_agents: z.array(betaManagedAgentsSessionThreadAgent)}); export const betaManagedAgentsMultiagentWorkflowsDisabled = z.object({type: z.literal("disabled")}); export const betaManagedAgentsSessionMultiagentWorkflows = z.discriminatedUnion("type", [betaManagedAgentsSessionMultiagentWorkflowsEnabled, betaManagedAgentsMultiagentWorkflowsDisabled]); export const betaManagedAgentsSessionMultiagentSubagentsEnabled = z.object({type: z.literal("enabled"), inline_agents: betaManagedAgentsMultiagentInlineAgents, predefined_agents: z.array(betaManagedAgentsSessionThreadAgent)}); export const betaManagedAgentsMultiagentSubagentsDisabled = z.object({type: z.literal("disabled")}); export const betaManagedAgentsSessionMultiagentSubagents = z.discriminatedUnion("type", [betaManagedAgentsSessionMultiagentSubagentsEnabled, betaManagedAgentsMultiagentSubagentsDisabled]); export const betaManagedAgentsMultiagentAdvisorEnabled = z.object({type: z.literal("enabled"), model: z.string()}); export const betaManagedAgentsMultiagentAdvisorDisabled = z.object({type: z.literal("disabled")}); export const betaManagedAgentsMultiagentAdvisor = z.discriminatedUnion("type", [betaManagedAgentsMultiagentAdvisorEnabled, betaManagedAgentsMultiagentAdvisorDisabled]); export const betaManagedAgentsSessionAgent = z.object({type: z.literal("agent"), id: z.string(), version: z.number().int(), name: z.string(), description: z.string().nullable(), model: betaManagedAgentsModelConfig, system: z.string().nullable(), tools: z.array(betaManagedAgentsAgentTool), mcp_servers: z.array(betaManagedAgentsMCPServer), skills: z.array(betaManagedAgentsSkill), multiagent: z.discriminatedUnion("type", [z.object({type: z.literal("coordinator"), agents: z.array(betaManagedAgentsSessionRosterEntry)}), z.object({type: z.literal("multiagent_20261001"), workflows: betaManagedAgentsSessionMultiagentWorkflows, subagents: betaManagedAgentsSessionMultiagentSubagents, advisor: betaManagedAgentsMultiagentAdvisor})]).nullable(), execution_identity: betaManagedAgentsExecutionIdentity}); export const betaCurrency = z.literal("USD"); export const betaMonetaryAmount = z.object({currency: betaCurrency, amount: z.string()}); export const betaManagedAgentsSystemContentBlock = z.object({type: z.literal("text"), text: z.string().min(1)}); export const betaManagedAgentsCacheCreationUsage = z.object({ephemeral_1h_input_tokens: z.number().int().optional(), ephemeral_5m_input_tokens: z.number().int().optional()}); export const betaManagedAgentsServerToolUsage = z.object({web_search_requests: z.number().int().optional(), web_fetch_requests: z.number().int().optional()}); export const betaManagedAgentsSessionUsageSnapshot = z.object({input_tokens: z.number().int().optional(), output_tokens: z.number().int().optional(), cache_read_input_tokens: z.number().int().optional(), cache_creation: betaManagedAgentsCacheCreationUsage.optional(), list_cost: betaMonetaryAmount.optional(), server_tool_use: betaManagedAgentsServerToolUsage.optional(), active_seconds: z.number().optional()}); export const betaManagedAgentsBudget = z.object({type: z.literal("limit"), max_list_cost: betaMonetaryAmount}); export const betaManagedAgentsWorkflowRunPhase = z.object({id: z.string(), name: z.string(), description: z.string().nullable()}); export const betaManagedAgentsWorkflowRunError = z.discriminatedUnion("type", [z.object({type: z.literal("timeout_error"), message: z.string()}), z.object({type: z.literal("program_error"), message: z.string()}), z.object({type: z.literal("unknown_error"), message: z.string()}), z.object({type: z.literal("thread_limit_error"), message: z.string()}), z.object({type: z.literal("max_workflow_runs_error"), message: z.string()})]); export const betaManagedAgentsWorkflowRunResult = z.discriminatedUnion("type", [z.object({type: z.literal("completed")}), z.object({type: z.literal("error"), error: betaManagedAgentsWorkflowRunError}), z.object({type: z.literal("stopped")})]); export const betaManagedAgentsSessionEvent = z.discriminatedUnion("type", [z.object({type: z.literal("user.message"), id: z.string(), content: z.array(betaManagedAgentsUserContentBlock), processed_at: betaTimestamp.nullable().optional()}), z.object({type: z.literal("user.interrupt"), id: z.string(), processed_at: betaTimestamp.nullable().optional(), session_thread_id: z.string().nullable().optional()}), z.object({type: z.literal("user.tool_confirmation"), id: z.string(), tool_use_id: z.string(), result: betaManagedAgentsUserToolConfirmationResult, deny_message: z.string().max(10000).nullable().optional(), processed_at: betaTimestamp.nullable().optional(), session_thread_id: z.string().nullable().optional()}), z.object({type: z.literal("user.custom_tool_result"), id: z.string(), custom_tool_use_id: z.string(), content: z.array(betaManagedAgentsToolResultContentBlock).optional(), is_error: z.boolean().nullable().optional(), processed_at: betaTimestamp.nullable().optional(), session_thread_id: z.string().nullable().optional()}), z.object({type: z.literal("agent.custom_tool_use"), id: z.string(), name: z.string(), input: betaManagedAgentsStruct, processed_at: betaTimestamp, session_thread_id: z.string().nullable().optional()}), z.object({type: z.literal("agent.message"), id: z.string(), content: z.array(betaManagedAgentsAgentMessageContentBlock), processed_at: betaTimestamp}), z.object({type: z.literal("agent.thinking"), id: z.string(), processed_at: betaTimestamp}), z.object({type: z.literal("agent.mcp_tool_use"), id: z.string(), name: z.string(), mcp_server_name: z.string(), input: betaManagedAgentsStruct, processed_at: betaTimestamp, evaluated_permission: betaManagedAgentsAgentEvaluatedPermission.optional(), session_thread_id: z.string().nullable().optional(), evaluation: betaManagedAgentsAgentToolEvaluation.optional()}), z.object({type: z.literal("agent.mcp_tool_result"), id: z.string(), mcp_tool_use_id: z.string(), content: z.array(betaManagedAgentsToolResultContentBlock).optional(), is_error: z.boolean().nullable().optional(), processed_at: betaTimestamp}), z.object({type: z.literal("agent.tool_use"), id: z.string(), name: z.string(), input: betaManagedAgentsStruct, processed_at: betaTimestamp, evaluated_permission: betaManagedAgentsAgentEvaluatedPermission.optional(), session_thread_id: z.string().nullable().optional(), evaluation: betaManagedAgentsAgentToolEvaluation.optional()}), z.object({type: z.literal("agent.tool_result"), id: z.string(), tool_use_id: z.string(), content: z.array(betaManagedAgentsToolResultContentBlock).optional(), is_error: z.boolean().nullable().optional(), processed_at: betaTimestamp}), z.object({type: z.literal("agent.thread_message_received"), id: z.string(), processed_at: betaTimestamp, from_agent_name: z.string().nullable().optional(), content: z.array(betaManagedAgentsUserContentBlock), from_session_thread_id: z.string()}), z.object({type: z.literal("agent.thread_message_sent"), id: z.string(), processed_at: betaTimestamp, to_agent_name: z.string().nullable().optional(), content: z.array(betaManagedAgentsUserContentBlock), to_session_thread_id: z.string()}), z.object({type: z.literal("agent.thread_context_compacted"), id: z.string(), processed_at: betaTimestamp}), z.object({type: z.literal("session.error"), id: z.string(), processed_at: betaTimestamp, error: z.discriminatedUnion("type", [z.object({type: z.literal("unknown_error"), message: z.string(), retry_status: betaManagedAgentsRetryStatus}), z.object({type: z.literal("model_overloaded_error"), message: z.string(), retry_status: betaManagedAgentsRetryStatus}), z.object({type: z.literal("model_rate_limited_error"), message: z.string(), retry_status: betaManagedAgentsRetryStatus}), z.object({type: z.literal("model_request_failed_error"), message: z.string(), retry_status: betaManagedAgentsRetryStatus}), z.object({type: z.literal("mcp_connection_failed_error"), message: z.string(), retry_status: betaManagedAgentsRetryStatus, mcp_server_name: z.string()}), z.object({type: z.literal("mcp_authentication_failed_error"), message: z.string(), retry_status: betaManagedAgentsRetryStatus, mcp_server_name: z.string()}), z.object({type: z.literal("billing_error"), message: z.string(), retry_status: betaManagedAgentsRetryStatus}), z.object({type: z.literal("credential_host_unreachable_error"), message: z.string(), retry_status: betaManagedAgentsRetryStatus, vault_id: z.string(), credential_id: z.string()}), z.object({type: z.literal("tool_use_limit_reached_error"), message: z.string(), retry_status: betaManagedAgentsRetryStatus}), z.object({type: z.literal("compaction_limit_reached_error"), message: z.string(), retry_status: betaManagedAgentsRetryStatus}), z.object({type: z.literal("repository_authentication_error"), message: z.string(), retry_status: betaManagedAgentsRetryStatus, repository_url: z.string().nullable()}), z.object({type: z.literal("repository_forbidden_error"), message: z.string(), retry_status: betaManagedAgentsRetryStatus, repository_url: z.string().nullable()}), z.object({type: z.literal("repository_not_found_error"), message: z.string(), retry_status: betaManagedAgentsRetryStatus, repository_url: z.string().nullable()}), z.object({type: z.literal("repository_checkout_error"), message: z.string(), retry_status: betaManagedAgentsRetryStatus, repository_url: z.string().nullable()}), z.object({type: z.literal("repository_clone_error"), message: z.string(), retry_status: betaManagedAgentsRetryStatus, repository_url: z.string().nullable()})])}), z.object({type: z.literal("session.status_rescheduled"), id: z.string(), processed_at: betaTimestamp}), z.object({type: z.literal("session.status_running"), id: z.string(), processed_at: betaTimestamp}), z.object({type: z.literal("session.status_idle"), id: z.string(), processed_at: betaTimestamp, stop_details: betaManagedAgentsSessionStopDetails.nullable(), stop_reason: z.discriminatedUnion("type", [z.object({type: z.literal("end_turn")}), z.object({type: z.literal("requires_action"), event_ids: z.array(z.string())}), z.object({type: z.literal("retries_exhausted")}), z.object({type: z.literal("budget_reached")}), z.object({type: z.literal("refusal")})])}), z.object({type: z.literal("session.status_terminated"), id: z.string(), processed_at: betaTimestamp}), z.object({type: z.literal("session.thread_created"), id: z.string(), processed_at: betaTimestamp, agent_name: z.string(), session_thread_id: z.string(), workflow_run_id: z.string().nullable()}), z.object({type: z.literal("span.outcome_evaluation_start"), id: z.string(), processed_at: betaTimestamp, iteration: z.number().int(), outcome_id: z.string()}), z.object({type: z.literal("span.outcome_evaluation_end"), id: z.string(), processed_at: betaTimestamp, outcome_evaluation_start_id: z.string(), iteration: z.number().int(), result: z.string(), explanation: z.string(), usage: betaManagedAgentsSpanModelUsage, outcome_id: z.string()}), z.object({type: z.literal("span.model_request_start"), id: z.string(), processed_at: betaTimestamp}), z.object({type: z.literal("span.model_request_end"), id: z.string(), processed_at: betaTimestamp, is_error: z.boolean().nullable(), model_usage: betaManagedAgentsSpanModelUsage, model_request_start_id: z.string()}), z.object({type: z.literal("span.outcome_evaluation_ongoing"), id: z.string(), processed_at: betaTimestamp, iteration: z.number().int(), outcome_id: z.string()}), z.object({type: z.literal("user.define_outcome"), id: z.string(), processed_at: betaTimestamp, outcome_id: z.string(), description: z.string(), max_iterations: z.number().int().nullable(), rubric: betaManagedAgentsRubric}), z.object({type: z.literal("session.deleted"), id: z.string(), processed_at: betaTimestamp}), z.object({type: z.literal("session.thread_status_running"), id: z.string(), session_thread_id: z.string(), processed_at: betaTimestamp, agent_name: z.string()}), z.object({type: z.literal("session.thread_status_idle"), id: z.string(), session_thread_id: z.string(), processed_at: betaTimestamp, agent_name: z.string(), stop_details: betaManagedAgentsSessionStopDetails.nullable(), stop_reason: z.discriminatedUnion("type", [z.object({type: z.literal("end_turn")}), z.object({type: z.literal("requires_action"), event_ids: z.array(z.string())}), z.object({type: z.literal("retries_exhausted")}), z.object({type: z.literal("budget_reached")}), z.object({type: z.literal("refusal")})])}), z.object({type: z.literal("session.thread_status_terminated"), id: z.string(), session_thread_id: z.string(), processed_at: betaTimestamp, agent_name: z.string()}), z.object({type: z.literal("user.tool_result"), id: z.string(), tool_use_id: z.string(), content: z.array(betaManagedAgentsToolResultContentBlock).optional(), is_error: z.boolean().nullable().optional(), processed_at: betaTimestamp.nullable().optional(), session_thread_id: z.string().nullable().optional()}), z.object({type: z.literal("session.thread_status_rescheduled"), id: z.string(), session_thread_id: z.string(), processed_at: betaTimestamp, agent_name: z.string()}), z.object({type: z.literal("session.updated"), id: z.string(), processed_at: betaTimestamp, title: z.string().nullable().optional(), metadata: z.record(z.string(), z.string()).optional(), agent: betaManagedAgentsSessionAgent.nullable().optional(), budget: z.object({type: z.literal("limit"), max_list_cost: betaMonetaryAmount}).nullable().optional()}), z.object({type: z.literal("system.message"), id: z.string(), content: z.array(betaManagedAgentsSystemContentBlock), processed_at: betaTimestamp.nullable().optional()}), z.object({type: z.literal("session.usage"), id: z.string(), processed_at: betaTimestamp, usage: betaManagedAgentsSessionUsageSnapshot, budget: betaManagedAgentsBudget.nullable().optional()}), z.object({type: z.literal("workflow_run.created"), id: z.string(), processed_at: betaTimestamp, workflow_run_id: z.string(), name: z.string(), description: z.string().nullable(), phases: z.array(betaManagedAgentsWorkflowRunPhase)}), z.object({type: z.literal("workflow_run.status_ended"), id: z.string(), processed_at: betaTimestamp, workflow_run_id: z.string(), result: betaManagedAgentsWorkflowRunResult}), z.object({type: z.literal("workflow_run.phase_started"), id: z.string(), processed_at: betaTimestamp, workflow_run_id: z.string(), workflow_run_phase_id: z.string()}), z.object({type: z.literal("workflow_run.phase_ended"), id: z.string(), processed_at: betaTimestamp, workflow_run_id: z.string(), workflow_run_phase_id: z.string(), phase_started_id: z.string()}), z.object({type: z.literal("workflow_run.status_running"), id: z.string(), processed_at: betaTimestamp, workflow_run_id: z.string()}), z.object({type: z.literal("workflow_run.status_idle"), id: z.string(), processed_at: betaTimestamp, workflow_run_id: z.string()}), z.object({type: z.literal("workflow_run.error"), id: z.string(), processed_at: betaTimestamp, workflow_run_id: z.string().nullable(), error: betaManagedAgentsWorkflowRunError})]); export const betaManagedAgentsListSessionThreadEvents = z.object({data: z.array(betaManagedAgentsSessionEvent).optional(), next_page: z.string().nullable().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * List Session Thread Events * * GET /v1/sessions/{session_id}/threads/{thread_id}/events?beta=true */ export const getApiV1SessionsSessionIdThreadsThreadIdEventsBetaTrue = async (args: GetApiV1SessionsSessionIdThreadsThreadIdEventsBetaTrueArgs, options?: GetApiV1SessionsSessionIdThreadsThreadIdEventsBetaTrueOptions) => { const {baseUrl = "https://api.anthropic.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['anthropic-version'] != null) headers.set("anthropic-version", String(args['anthropic-version'])) if (args['anthropic-beta'] != null) headers.set("anthropic-beta", args['anthropic-beta'].join(',')) if (args.limit != null) query.append("limit", String(args.limit)) if (args.page != null) query.append("page", String(args.page)) if (args['anthropic-workspace-id'] != null) headers.set("anthropic-workspace-id", String(args['anthropic-workspace-id'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/sessions/${encodeURIComponent(String(args.session_id))}/threads/${encodeURIComponent(String(args.thread_id))}/events?beta=true${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(betaManagedAgentsListSessionThreadEvents, await res.json()) };