// This file is auto-generated by @hey-api/openapi-ts

import * as z from 'zod'

/**
 * SimpleResultResponse
 */
export const zSimpleResultResponse = z.object({
  result: z.string(),
})

/**
 * DefaultBlockConfigsResponse
 */
export const zDefaultBlockConfigsResponse = z.array(z.record(z.string(), z.unknown()))

/**
 * SnippetDraftSyncPayload
 *
 * Payload for syncing snippet draft workflow.
 */
export const zSnippetDraftSyncPayload = z.object({
  conversation_variables: z.array(z.record(z.string(), z.unknown())).nullish(),
  graph: z.record(z.string(), z.unknown()),
  hash: z.string().nullish(),
  input_fields: z.array(z.record(z.string(), z.unknown())).nullish(),
})

/**
 * WorkflowRestoreResponse
 */
export const zWorkflowRestoreResponse = z.object({
  hash: z.string(),
  result: z.string(),
  updated_at: z.int(),
})

/**
 * SnippetDraftConfigResponse
 */
export const zSnippetDraftConfigResponse = z.object({
  parallel_depth_limit: z.int(),
})

/**
 * SnippetIterationNodeRunPayload
 *
 * Payload for running an iteration node in snippet draft workflow.
 */
export const zSnippetIterationNodeRunPayload = z.object({
  inputs: z.record(z.string(), z.unknown()).nullish(),
})

/**
 * SnippetLoopNodeRunPayload
 *
 * Payload for running a loop node in snippet draft workflow.
 */
export const zSnippetLoopNodeRunPayload = z.object({
  inputs: z.record(z.string(), z.unknown()).nullish(),
})

/**
 * WorkflowComposerCopyFromRosterPayload
 */
export const zWorkflowComposerCopyFromRosterPayload = z.object({
  idempotency_key: z.string().max(255).nullish(),
  source_agent_id: z.string().min(1).max(255),
  source_snapshot_id: z.string().max(255).nullish(),
})

/**
 * SnippetDraftNodeRunPayload
 *
 * Payload for running a single node in snippet draft workflow.
 */
export const zSnippetDraftNodeRunPayload = z.object({
  files: z.array(z.record(z.string(), z.unknown())).nullish(),
  inputs: z.record(z.string(), z.unknown()),
  query: z.string().optional().default(''),
})

/**
 * SnippetDraftRunPayload
 *
 * Payload for running snippet draft workflow.
 */
export const zSnippetDraftRunPayload = z.object({
  files: z.array(z.record(z.string(), z.unknown())).nullish(),
  inputs: z.record(z.string(), z.unknown()),
})

export const zWorkflowDraftVariable = z.object({
  description: z.string().optional(),
  edited: z.boolean().optional(),
  full_content: z.record(z.string(), z.unknown()).optional(),
  id: z.string().optional(),
  is_truncated: z.boolean().optional(),
  name: z.string().optional(),
  selector: z.array(z.string()).optional(),
  type: z.string().optional(),
  value: z
    .union([
      z.string(),
      z.int(),
      z.number(),
      z.boolean(),
      z.record(z.string(), z.unknown()),
      z.array(z.unknown()),
    ])
    .nullish(),
  value_type: z.string().optional(),
  visible: z.boolean().optional(),
})

export const zWorkflowDraftVariableList = z.object({
  items: z.array(zWorkflowDraftVariable).optional(),
})

/**
 * WorkflowDraftVariableUpdatePayload
 */
export const zWorkflowDraftVariableUpdatePayload = z.object({
  name: z.string().nullish(),
  value: z.unknown().nullish(),
})

/**
 * PublishWorkflowPayload
 *
 * Payload for publishing snippet workflow.
 */
export const zPublishWorkflowPayload = z.object({
  knowledge_base_setting: z.record(z.string(), z.unknown()).nullish(),
  marked_comment: z.string().max(100).nullish(),
  marked_name: z.string().max(20).nullish(),
})

/**
 * WorkflowPublishResponse
 */
export const zWorkflowPublishResponse = z.object({
  created_at: z.int(),
  result: z.string(),
})

/**
 * WorkflowUpdatePayload
 */
export const zWorkflowUpdatePayload = z.object({
  marked_comment: z.string().max(100).nullish(),
  marked_name: z.string().max(20).nullish(),
})

/**
 * SimpleAccountResponse
 */
export const zSimpleAccountResponse = z.object({
  email: z.string(),
  id: z.string(),
  name: z.string(),
})

/**
 * WorkflowRunForListResponse
 */
export const zWorkflowRunForListResponse = z.object({
  created_at: z.int().nullish(),
  created_by_account: zSimpleAccountResponse.nullish(),
  elapsed_time: z.number().nullish(),
  exceptions_count: z.int().nullish(),
  finished_at: z.int().nullish(),
  id: z.string(),
  retry_index: z.int().nullish(),
  status: z.string().nullish(),
  total_steps: z.int().nullish(),
  total_tokens: z.int().nullish(),
  version: z.string().nullish(),
})

/**
 * WorkflowRunPaginationResponse
 */
export const zWorkflowRunPaginationResponse = z.object({
  data: z.array(zWorkflowRunForListResponse),
  has_more: z.boolean(),
  limit: z.int(),
})

/**
 * SimpleEndUser
 */
export const zSimpleEndUser = z.object({
  id: z.string(),
  is_anonymous: z.boolean(),
  session_id: z.string().nullish(),
  type: z.string(),
})

/**
 * WorkflowRunDetailResponse
 */
export const zWorkflowRunDetailResponse = z.object({
  created_at: z.int().nullish(),
  created_by_account: zSimpleAccountResponse.nullish(),
  created_by_end_user: zSimpleEndUser.nullish(),
  created_by_role: z.string().nullish(),
  elapsed_time: z.number().nullish(),
  error: z.string().nullish(),
  exceptions_count: z.int().nullish(),
  finished_at: z.int().nullish(),
  graph: z.unknown(),
  id: z.string(),
  inputs: z.unknown(),
  outputs: z.unknown(),
  status: z.string().nullish(),
  total_steps: z.int().nullish(),
  total_tokens: z.int().nullish(),
  version: z.string().nullish(),
})

/**
 * WorkflowRunNodeExecutionResponse
 */
export const zWorkflowRunNodeExecutionResponse = z.object({
  created_at: z.int().nullish(),
  created_by_account: zSimpleAccountResponse.nullish(),
  created_by_end_user: zSimpleEndUser.nullish(),
  created_by_role: z.string().nullish(),
  elapsed_time: z.number().nullish(),
  error: z.string().nullish(),
  execution_metadata: z.unknown().optional(),
  extras: z.unknown().optional(),
  finished_at: z.int().nullish(),
  id: z.string(),
  index: z.int().nullish(),
  inputs: z.unknown().optional(),
  inputs_truncated: z.boolean().nullish(),
  node_id: z.string().nullish(),
  node_type: z.string().nullish(),
  outputs: z.unknown().optional(),
  outputs_truncated: z.boolean().nullish(),
  predecessor_node_id: z.string().nullish(),
  process_data: z.unknown().optional(),
  process_data_truncated: z.boolean().nullish(),
  retry_index: z.int().nullish(),
  status: z.string().nullish(),
  title: z.string().nullish(),
})

/**
 * WorkflowRunNodeExecutionListResponse
 */
export const zWorkflowRunNodeExecutionListResponse = z.object({
  data: z.array(zWorkflowRunNodeExecutionResponse),
})

/**
 * WorkflowConversationVariableResponse
 */
export const zWorkflowConversationVariableResponse = z.object({
  description: z.string(),
  id: z.string(),
  name: z.string(),
  value: z.unknown(),
  value_type: z.string(),
})

/**
 * WorkflowEnvironmentVariableResponse
 */
export const zWorkflowEnvironmentVariableResponse = z.object({
  description: z.string(),
  id: z.string(),
  name: z.string(),
  value: z.unknown(),
  value_type: z.string(),
})

/**
 * PipelineVariableResponse
 */
export const zPipelineVariableResponse = z.object({
  allowed_file_extensions: z.array(z.string()).nullish(),
  allowed_file_types: z.array(z.string()).nullish(),
  allowed_file_upload_methods: z.array(z.string()).nullish(),
  belong_to_node_id: z.string(),
  default_value: z.unknown().optional(),
  label: z.string(),
  max_length: z.int().nullish(),
  options: z.array(z.string()).nullish(),
  placeholder: z.string().nullish(),
  required: z.boolean(),
  tooltips: z.string().nullish(),
  type: z.string(),
  unit: z.string().nullish(),
  variable: z.string(),
})

/**
 * SnippetWorkflowResponse
 */
export const zSnippetWorkflowResponse = z.object({
  conversation_variables: z.array(zWorkflowConversationVariableResponse),
  created_at: z.int(),
  created_by: zSimpleAccountResponse.nullish(),
  environment_variables: z.array(zWorkflowEnvironmentVariableResponse),
  features: z.record(z.string(), z.unknown()),
  graph: z.record(z.string(), z.unknown()),
  hash: z.string(),
  id: z.string(),
  input_fields: z.array(z.record(z.string(), z.unknown())).optional(),
  marked_comment: z.string(),
  marked_name: z.string(),
  rag_pipeline_variables: z.array(zPipelineVariableResponse),
  tool_published: z.boolean(),
  updated_at: z.int(),
  updated_by: zSimpleAccountResponse.nullish(),
  version: z.string(),
})

/**
 * SnippetWorkflowPaginationResponse
 */
export const zSnippetWorkflowPaginationResponse = z.object({
  has_more: z.boolean(),
  items: z.array(zSnippetWorkflowResponse),
  limit: z.int(),
  page: z.int(),
})

/**
 * EnvironmentVariableItemResponse
 */
export const zEnvironmentVariableItemResponse = z.object({
  description: z.string().nullish(),
  editable: z.boolean(),
  edited: z.boolean(),
  id: z.string(),
  name: z.string(),
  selector: z.array(z.string()),
  type: z.string(),
  value: z.unknown(),
  value_type: z.string(),
  visible: z.boolean(),
})

/**
 * EnvironmentVariableListResponse
 */
export const zEnvironmentVariableListResponse = z.object({
  items: z.array(zEnvironmentVariableItemResponse),
})

export const zJsonValue = z
  .union([
    z.string(),
    z.int(),
    z.number(),
    z.boolean(),
    z.record(z.string(), z.unknown()),
    z.array(z.unknown()),
  ])
  .nullable()

/**
 * GeneratedAppResponse
 */
export const zGeneratedAppResponse = zJsonValue

/**
 * AgentConfigSnapshotSummaryResponse
 */
export const zAgentConfigSnapshotSummaryResponse = z.object({
  agent_id: z.string().nullish(),
  created_at: z.int().nullish(),
  created_by: z.string().nullish(),
  display_version: z.int().nullish(),
  id: z.string(),
  snapshot_version: z.int().nullish(),
  summary: z.string().nullish(),
  version: z.int(),
  version_note: z.string().nullish(),
})

/**
 * ComposerSaveStrategy
 */
export const zComposerSaveStrategy = z.enum([
  'node_job_only',
  'save_as_new_agent',
  'save_as_new_version',
  'save_to_current_version',
  'save_to_roster',
])

/**
 * AgentComposerSoulLockResponse
 */
export const zAgentComposerSoulLockResponse = z.object({
  can_unlock: z.boolean().optional().default(false),
  locked: z.boolean(),
  reason: z.string().nullish(),
})

/**
 * ComposerBindingPayload
 */
export const zComposerBindingPayload = z.object({
  agent_id: z.string().nullish(),
  binding_type: z.enum(['inline_agent', 'roster_agent']),
  current_snapshot_id: z.string().nullish(),
})

/**
 * AgentIconType
 *
 * Supported icon storage formats for Agent roster entries.
 */
export const zAgentIconType = z.enum(['emoji', 'image', 'link'])

/**
 * ComposerSoulLockPayload
 */
export const zComposerSoulLockPayload = z.object({
  locked: z.boolean().optional().default(true),
  unlocked_from_version_id: z.string().nullish(),
})

/**
 * ComposerVariant
 */
export const zComposerVariant = z.enum(['agent_app', 'workflow'])

/**
 * ComposerCandidateCapabilities
 */
export const zComposerCandidateCapabilities = z.object({
  human_roster_available: z.boolean().optional().default(false),
})

/**
 * AgentComposerImpactBindingResponse
 */
export const zAgentComposerImpactBindingResponse = z.object({
  app_id: z.string(),
  node_id: z.string(),
  workflow_id: z.string(),
})

/**
 * AgentComposerImpactResponse
 */
export const zAgentComposerImpactResponse = z.object({
  bindings: z.array(zAgentComposerImpactBindingResponse).optional(),
  current_snapshot_id: z.string().nullish(),
  workflow_node_count: z.int(),
})

/**
 * ComposerKnowledgePlaceholderResponse
 */
export const zComposerKnowledgePlaceholderResponse = z.object({
  id: z.string(),
  placeholder_name: z.string(),
})

/**
 * ComposerValidationWarningResponse
 */
export const zComposerValidationWarningResponse = z.object({
  code: z.string(),
  id: z.string().nullish(),
  kind: z.string().nullish(),
  message: z.string().nullish(),
  surface: z.string().nullish(),
})

/**
 * AgentComposerValidateResponse
 */
export const zAgentComposerValidateResponse = z.object({
  errors: z.array(z.string()).optional(),
  knowledge_retrieval_placeholder: z.array(zComposerKnowledgePlaceholderResponse).optional(),
  result: z.literal('success'),
  warnings: z.array(zComposerValidationWarningResponse).optional(),
})

/**
 * ComposerValidationFindingsResponse
 */
export const zComposerValidationFindingsResponse = z.object({
  knowledge_retrieval_placeholder: z.array(zComposerKnowledgePlaceholderResponse).optional(),
  warnings: z.array(zComposerValidationWarningResponse).optional(),
})

export const zWorkflowDraftVariableWithoutValue = z.object({
  description: z.string().optional(),
  edited: z.boolean().optional(),
  id: z.string().optional(),
  is_truncated: z.boolean().optional(),
  name: z.string().optional(),
  selector: z.array(z.string()).optional(),
  type: z.string().optional(),
  value_type: z.string().optional(),
  visible: z.boolean().optional(),
})

export const zWorkflowDraftVariableListWithoutValue = z.object({
  items: z.array(zWorkflowDraftVariableWithoutValue).optional(),
  total: z.int().optional(),
})

/**
 * AgentScope
 *
 * Visibility and lifecycle scope of an Agent record.
 */
export const zAgentScope = z.enum(['roster', 'workflow_only'])

/**
 * AgentSource
 *
 * Origin that created or imported the Agent.
 */
export const zAgentSource = z.enum(['agent_app', 'imported', 'roster', 'system', 'workflow'])

/**
 * AgentStatus
 *
 * Soft lifecycle state for Agent records.
 */
export const zAgentStatus = z.enum(['active', 'archived'])

/**
 * AgentComposerAgentResponse
 */
export const zAgentComposerAgentResponse = z.object({
  active_config_snapshot_id: z.string().nullish(),
  app_id: z.string().nullish(),
  backing_app_id: z.string().nullish(),
  description: z.string(),
  hidden_app_backed: z.boolean().optional().default(false),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: z.string().nullish(),
  id: z.string(),
  name: z.string(),
  role: z.string().nullish(),
  scope: zAgentScope,
  source: zAgentSource.nullish(),
  status: zAgentStatus,
})

/**
 * AppVariableConfig
 */
export const zAppVariableConfig = z.object({
  default: z.unknown().optional(),
  name: z.string().min(1).max(255),
  required: z.boolean().optional().default(false),
  type: z.string().min(1).max(64),
})

/**
 * AgentConfigFileRefConfig
 *
 * Stable Agent Soul reference to one config file payload.
 */
export const zAgentConfigFileRefConfig = z.object({
  file_id: z.string().max(255).optional().default(''),
  file_kind: z.enum(['tool_file', 'upload_file']),
  hash: z.string().nullish(),
  is_missing: z.boolean().optional().default(false),
  mime_type: z.string().nullish(),
  name: z.string().min(1).max(255),
  size: z.int().nullish(),
})

/**
 * AgentConfigSkillRefConfig
 *
 * Stable Agent Soul reference to one normalized skill archive.
 */
export const zAgentConfigSkillRefConfig = z.object({
  description: z.string().optional().default(''),
  file_id: z.string().max(255).optional().default(''),
  file_kind: z.literal('tool_file').optional().default('tool_file'),
  hash: z.string().nullish(),
  is_missing: z.boolean().optional().default(false),
  mime_type: z.string().nullish().default('application/zip'),
  name: z.string().min(1).max(255),
  size: z.int().nullish(),
})

/**
 * AgentSoulPromptConfig
 */
export const zAgentSoulPromptConfig = z.object({
  system_prompt: z.string().optional().default(''),
})

/**
 * WorkflowAgentBindingType
 *
 * How a workflow node is bound to an Agent.
 */
export const zWorkflowAgentBindingType = z.enum(['inline_agent', 'roster_agent'])

/**
 * AgentComposerBindingResponse
 */
export const zAgentComposerBindingResponse = z.object({
  agent_id: z.string().nullish(),
  binding_type: zWorkflowAgentBindingType,
  current_snapshot_id: z.string().nullish(),
  id: z.string(),
  node_id: z.string(),
  workflow_id: z.string(),
})

/**
 * DeclaredOutputFileConfig
 *
 * File-type output metadata. Both lists empty means "any file accepted".
 */
export const zDeclaredOutputFileConfig = z.object({
  extensions: z.array(z.string()).optional(),
  mime_types: z.array(z.string()).optional(),
})

/**
 * DeclaredOutputType
 */
export const zDeclaredOutputType = z.enum([
  'array',
  'boolean',
  'file',
  'number',
  'object',
  'string',
])

/**
 * DeclaredArrayItem
 *
 * Per-item shape for an ``array``-typed declared output.
 *
 * PRD §OUTPUT 配置框 keeps arrays one level deep on first version; nested arrays
 * are rejected so the runtime type checker and JSON Schema stay easy to reason
 * about. Stage 4 §4.2.
 */
export const zDeclaredArrayItem = z.object({
  children: z
    .array(
      z.object({
        array_item: z
          .object({
            children: z.array(z.record(z.string(), z.unknown())).optional(),
            description: z.string().nullish(),
            type: z.enum(['array', 'boolean', 'file', 'number', 'object', 'string']).optional(),
          })
          .nullish(),
        children: z.array(z.record(z.string(), z.unknown())).optional(),
        description: z.string().nullish(),
        file: z.record(z.string(), z.unknown()).nullish(),
        name: z.string(),
        required: z.boolean().optional(),
        type: z.enum(['array', 'boolean', 'file', 'number', 'object', 'string']),
      }),
    )
    .optional(),
  description: z.string().nullish(),
  type: zDeclaredOutputType,
})

/**
 * AgentHumanContactConfig
 */
export const zAgentHumanContactConfig = z.object({
  channel: z.string().max(64).nullish(),
  contact_id: z.string().max(255).nullish(),
  contact_method: z.string().max(64).nullish(),
  email: z.string().max(255).nullish(),
  human_id: z.string().max(255).nullish(),
  id: z.string().max(255).nullish(),
  method: z.string().max(64).nullish(),
  name: z.string().max(255).nullish(),
  tenant_id: z.string().max(255).nullish(),
})

/**
 * WorkflowNodeJobMode
 */
export const zWorkflowNodeJobMode = z.enum(['let_agent_figure_it_out', 'tell_agent_what_to_do'])

/**
 * WorkflowPreviousNodeOutputRef
 */
export const zWorkflowPreviousNodeOutputRef = z.object({
  key: z.string().max(255).nullish(),
  name: z.string().max(255).nullish(),
  node_id: z.string().max(255).nullish(),
  output: z.string().max(255).nullish(),
  selector: z.array(z.union([z.string(), z.int(), z.number(), z.boolean(), z.null()])).nullish(),
  value_selector: z
    .array(z.union([z.string(), z.int(), z.number(), z.boolean(), z.null()]))
    .nullish(),
  variable: z.string().max(255).nullish(),
  variable_selector: z
    .array(z.union([z.string(), z.int(), z.number(), z.boolean(), z.null()]))
    .nullish(),
})

/**
 * AgentComposerNodeJobCandidatesResponse
 */
export const zAgentComposerNodeJobCandidatesResponse = z.object({
  declare_output_types: z.array(zDeclaredOutputType).optional(),
  human_contacts: z.array(zAgentHumanContactConfig).optional(),
  previous_node_outputs: z.array(zWorkflowPreviousNodeOutputRef).optional(),
})

/**
 * AgentComposerDifyToolCandidateResponse
 */
export const zAgentComposerDifyToolCandidateResponse = z.object({
  description: z.string().nullish(),
  granularity: z.string().nullish(),
  id: z.string().nullish(),
  name: z.string().nullish(),
  plugin_id: z.string().nullish(),
  provider: z.string().nullish(),
  provider_id: z.string().nullish(),
  tools_count: z.int().nullish(),
})

/**
 * AgentFeatureToggleConfig
 */
export const zAgentFeatureToggleConfig = z.object({
  enabled: z.boolean().optional().default(false),
})

/**
 * AgentTextToSpeechFeatureConfig
 */
export const zAgentTextToSpeechFeatureConfig = z.object({
  autoPlay: z.string().nullish(),
  enabled: z.boolean().optional().default(false),
  language: z.string().nullish(),
  voice: z.string().nullish(),
})

/**
 * AgentEnvVariableConfig
 */
export const zAgentEnvVariableConfig = z.object({
  default: z
    .union([
      z.string(),
      z.int(),
      z.number(),
      z.boolean(),
      z.array(z.string()),
      z.array(z.int()),
      z.array(z.number()),
      z.array(z.boolean()),
    ])
    .nullish(),
  env_name: z.string().max(255).nullish(),
  key: z.string().max(255).nullish(),
  name: z.string().max(255).nullish(),
  required: z.boolean().optional().default(false),
  type: z.string().max(64).nullish(),
  value: z
    .union([
      z.string(),
      z.int(),
      z.number(),
      z.boolean(),
      z.array(z.string()),
      z.array(z.int()),
      z.array(z.number()),
      z.array(z.boolean()),
    ])
    .nullish(),
  variable: z.string().max(255).nullish(),
})

/**
 * AgentFileRefConfig
 */
export const zAgentFileRefConfig = z.object({
  drive_key: z.string().max(512).nullish(),
  file_id: z.string().max(255).nullish(),
  id: z.string().max(255).nullish(),
  name: z.string().max(255).nullish(),
  reference: z.string().max(255).nullish(),
  remote_url: z.string().nullish(),
  tenant_id: z.string().max(255).nullish(),
  transfer_method: z.string().max(64).nullish(),
  type: z.string().max(64).nullish(),
  upload_file_id: z.string().max(255).nullish(),
  url: z.string().nullish(),
})

/**
 * WorkflowNodeJobMetadata
 */
export const zWorkflowNodeJobMetadata = z.object({
  agent_soul: z.record(z.string(), z.unknown()).nullish(),
  file_refs: z.array(zAgentFileRefConfig).nullish(),
})

/**
 * AgentSkillRefConfig
 */
export const zAgentSkillRefConfig = z.object({
  description: z.string().nullish(),
  file_id: z.string().max(255).nullish(),
  full_archive_file_id: z.string().max(255).nullish(),
  full_archive_key: z.string().max(512).nullish(),
  id: z.string().max(255).nullish(),
  manifest_files: z.array(z.string()).nullish(),
  name: z.string().max(255).nullish(),
  path: z.string().nullish(),
  skill_md_file_id: z.string().max(255).nullish(),
  skill_md_key: z.string().max(512).nullish(),
})

/**
 * AgentSoulFilesConfig
 */
export const zAgentSoulFilesConfig = z.object({
  files: z.array(zAgentFileRefConfig).optional(),
  skills: z.array(zAgentSkillRefConfig).optional(),
})

/**
 * AgentHumanToolConfig
 */
export const zAgentHumanToolConfig = z.object({
  description: z.string().nullish(),
  enabled: z.boolean().optional().default(true),
  name: z.string().max(255).nullish(),
})

/**
 * AgentSoulHumanConfig
 */
export const zAgentSoulHumanConfig = z.object({
  contacts: z.array(zAgentHumanContactConfig).optional(),
  tools: z.array(zAgentHumanToolConfig).optional(),
})

/**
 * AgentMemoryArtifactConfig
 */
export const zAgentMemoryArtifactConfig = z.object({
  id: z.string().max(255).nullish(),
  name: z.string().max(255).nullish(),
  type: z.string().max(64).nullish(),
  url: z.string().nullish(),
})

/**
 * AgentSoulMemoryConfig
 */
export const zAgentSoulMemoryConfig = z.object({
  artifacts: z.array(zAgentMemoryArtifactConfig).optional(),
  budget: z.string().nullish(),
  scope: z.string().nullish(),
})

/**
 * AgentSoulModelCredentialRef
 *
 * Reference to model credentials resolved only at runtime.
 */
export const zAgentSoulModelCredentialRef = z.object({
  id: z.string().max(255).nullish(),
  provider: z.string().max(255).nullish(),
  type: z.string().min(1).max(64),
})

/**
 * AgentSandboxProviderConfig
 */
export const zAgentSandboxProviderConfig = z.object({
  cpu: z.int().gte(1).nullish(),
  env: z.array(zAgentEnvVariableConfig).optional(),
  image: z.string().nullish(),
  working_dir: z.string().nullish(),
})

/**
 * AgentSoulSandboxConfig
 */
export const zAgentSoulSandboxConfig = z.object({
  config: zAgentSandboxProviderConfig.optional(),
  provider: z.string().nullish(),
})

/**
 * OutputErrorStrategy
 *
 * Per-output failure handling strategy.
 *
 * Mirrors ``graphon.ErrorStrategy`` but scoped to a single declared output of
 * a Workflow Agent Node. The runtime applies the strategy after type check or
 * output check fails and any configured retry attempts have been exhausted.
 */
export const zOutputErrorStrategy = z.enum(['default_value', 'fail_branch', 'stop'])

/**
 * DeclaredOutputRetryConfig
 *
 * Per-output retry configuration that mirrors ``graphon.RetryConfig`` shape.
 */
export const zDeclaredOutputRetryConfig = z.object({
  enabled: z.boolean().optional().default(false),
  max_retries: z.int().gte(0).lte(10).optional().default(0),
  retry_interval_ms: z.int().gte(0).lte(60000).optional().default(0),
})

/**
 * DeclaredOutputFailureStrategy
 *
 * Per-output failure handling.
 *
 * A single strategy applies to both ``type_check`` and ``output_check`` failures
 * (PRD does not distinguish them at the UX level). Stage 4 §4.4.
 */
export const zDeclaredOutputFailureStrategy = z.object({
  default_value: z.unknown().optional(),
  on_failure: zOutputErrorStrategy.optional().default('stop'),
  retry: zDeclaredOutputRetryConfig.optional(),
})

/**
 * AgentCliToolAuthorizationStatus
 *
 * Authorization state for Agent-scoped CLI tools.
 *
 * Missing status keeps backward compatibility with draft rows and CLI tools that
 * do not need pre-authorization. Explicit denied-like states are blocked by the
 * composer/publish validators and skipped by runtime request builders.
 */
export const zAgentCliToolAuthorizationStatus = z.enum([
  'allowed',
  'authorized',
  'denied',
  'forbidden',
  'not_required',
  'pending',
  'pre_authorized',
  'unauthorized',
])

/**
 * AgentPermissionConfig
 */
export const zAgentPermissionConfig = z.object({
  allowed: z.boolean().nullish(),
  state: z.string().max(64).nullish(),
  status: z.string().max(64).nullish(),
})

/**
 * AgentSecretRefConfig
 */
export const zAgentSecretRefConfig = z.object({
  credential_id: z.string().max(255).nullish(),
  env_name: z.string().max(255).nullish(),
  id: z.string().max(255).nullish(),
  key: z.string().max(255).nullish(),
  name: z.string().max(255).nullish(),
  permission: zAgentPermissionConfig.nullish(),
  permission_status: z.string().max(64).nullish(),
  provider: z.string().max(255).nullish(),
  provider_credential_id: z.string().max(255).nullish(),
  ref: z.string().max(255).nullish(),
  type: z.string().max(64).nullish(),
  value: z.string().nullish(),
  variable: z.string().max(255).nullish(),
})

/**
 * AgentSoulEnvConfig
 */
export const zAgentSoulEnvConfig = z.object({
  secret_refs: z.array(zAgentSecretRefConfig).optional(),
  variables: z.array(zAgentEnvVariableConfig).optional(),
})

/**
 * AgentCliToolEnvConfig
 */
export const zAgentCliToolEnvConfig = z.object({
  secret_refs: z.array(zAgentSecretRefConfig).optional(),
  variables: z.array(zAgentEnvVariableConfig).optional(),
})

/**
 * AgentCliToolRiskLevel
 *
 * Risk marker for CLI tool bootstrap commands.
 */
export const zAgentCliToolRiskLevel = z.enum(['dangerous', 'safe', 'unknown'])

/**
 * AgentCliToolConfig
 */
export const zAgentCliToolConfig = z.object({
  approved: z.boolean().optional().default(false),
  authorization_status: zAgentCliToolAuthorizationStatus.nullish(),
  command: z.string().nullish(),
  dangerous: z.boolean().optional().default(false),
  dangerous_accepted: z.boolean().optional().default(false),
  dangerous_acknowledged: z.boolean().optional().default(false),
  dangerous_command: z.boolean().optional().default(false),
  description: z.string().nullish(),
  enabled: z.boolean().optional().default(true),
  env: zAgentCliToolEnvConfig.optional(),
  id: z.string().max(255).nullish(),
  inferred_from: z.string().max(255).nullish(),
  install: z.string().nullish(),
  install_command: z.string().nullish(),
  install_commands: z.array(z.string()).optional(),
  invoke_metadata: z.record(z.string(), z.unknown()).optional(),
  label: z.string().max(255).nullish(),
  name: z.string().max(255).nullish(),
  permission: zAgentPermissionConfig.nullish(),
  pre_authorized: z.boolean().nullish(),
  requires_confirmation: z.boolean().optional().default(false),
  risk_accepted: z.boolean().optional().default(false),
  risk_level: zAgentCliToolRiskLevel.nullish(),
  setup_command: z.string().nullish(),
  tool_name: z.string().max(255).nullish(),
})

/**
 * AgentComposerKnowledgeDatasetCandidateResponse
 */
export const zAgentComposerKnowledgeDatasetCandidateResponse = z.object({
  description: z.string().nullish(),
  id: z.string().max(255).nullish(),
  missing: z.boolean().optional().default(false),
  name: z.string().max(255).nullish(),
})

/**
 * AgentComposerKnowledgeSetCandidateResponse
 */
export const zAgentComposerKnowledgeSetCandidateResponse = z.object({
  datasets: z.array(zAgentComposerKnowledgeDatasetCandidateResponse).optional(),
  description: z.string().nullish(),
  id: z.string(),
  missing_dataset_ids: z.array(z.string()).optional(),
  name: z.string(),
})

/**
 * AgentComposerSoulCandidatesResponse
 */
export const zAgentComposerSoulCandidatesResponse = z.object({
  cli_tools: z.array(zAgentCliToolConfig).optional(),
  dify_tools: z.array(zAgentComposerDifyToolCandidateResponse).optional(),
  human_contacts: z.array(zAgentHumanContactConfig).optional(),
  knowledge_sets: z.array(zAgentComposerKnowledgeSetCandidateResponse).optional(),
})

/**
 * AgentComposerCandidatesResponse
 */
export const zAgentComposerCandidatesResponse = z.object({
  allowed_node_job_candidates: zAgentComposerNodeJobCandidatesResponse.optional(),
  allowed_soul_candidates: zAgentComposerSoulCandidatesResponse.optional(),
  capabilities: zComposerCandidateCapabilities.optional(),
  truncated: z.boolean().optional().default(false),
  variant: zComposerVariant,
})

/**
 * FileType
 */
export const zFileType = z.enum(['audio', 'custom', 'document', 'image', 'video'])

/**
 * FileTransferMethod
 */
export const zFileTransferMethod = z.enum([
  'datasource_file',
  'local_file',
  'remote_url',
  'tool_file',
])

/**
 * AgentFileUploadImageFeatureConfig
 */
export const zAgentFileUploadImageFeatureConfig = z.object({
  enabled: z.boolean().optional().default(true),
})

/**
 * AgentFileUploadFeatureConfig
 */
export const zAgentFileUploadFeatureConfig = z.object({
  allowed_file_extensions: z.array(z.string()).optional(),
  allowed_file_types: z.array(zFileType).optional(),
  allowed_file_upload_methods: z.array(zFileTransferMethod).optional(),
  enabled: z.boolean().optional().default(true),
  image: zAgentFileUploadImageFeatureConfig.optional(),
  number_limits: z.int().optional().default(3),
})

/**
 * AgentSuggestedQuestionsAfterAnswerModelConfig
 *
 * Legacy Chat App model config used only for follow-up question generation.
 */
export const zAgentSuggestedQuestionsAfterAnswerModelConfig = z.object({
  completion_params: z.record(z.string(), z.unknown()).nullish(),
  mode: z.string().max(64).nullish(),
  name: z.string().min(1).max(255),
  provider: z.string().min(1).max(255),
})

/**
 * AgentSuggestedQuestionsAfterAnswerFeatureConfig
 */
export const zAgentSuggestedQuestionsAfterAnswerFeatureConfig = z.object({
  enabled: z.boolean().optional().default(false),
  model: zAgentSuggestedQuestionsAfterAnswerModelConfig.nullish(),
  prompt: z.string().nullish(),
})

/**
 * AgentKnowledgeDatasetConfig
 */
export const zAgentKnowledgeDatasetConfig = z.object({
  description: z.string().nullish(),
  id: z.string().max(255).nullish(),
  name: z.string().max(255).nullish(),
})

/**
 * AgentModelResponseFormatConfig
 */
export const zAgentModelResponseFormatConfig = z.object({
  type: z.string().max(64).nullish(),
})

/**
 * AgentSoulModelSettings
 */
export const zAgentSoulModelSettings = z.object({
  frequency_penalty: z.number().nullish(),
  max_tokens: z.int().nullish(),
  presence_penalty: z.number().nullish(),
  response_format: zAgentModelResponseFormatConfig.nullish(),
  stop: z.array(z.string()).nullish(),
  temperature: z.number().nullish(),
  top_p: z.number().nullish(),
})

/**
 * AgentSoulModelConfig
 *
 * Stable model selection for Agent runtime without storing secret values.
 */
export const zAgentSoulModelConfig = z.object({
  credential_ref: zAgentSoulModelCredentialRef.nullish(),
  model: z.string().min(1).max(255),
  model_provider: z.string().min(1).max(255),
  model_settings: zAgentSoulModelSettings.optional(),
  plugin_id: z.string().min(1).max(255),
})

/**
 * DeclaredOutputCheckConfig
 *
 * File-output content check via a model-based comparison against a benchmark file.
 *
 * Per PRD §OUTPUT 配置框, output check is **file-only** and optional. Stage 4 §4.3.
 */
export const zDeclaredOutputCheckConfig = z.object({
  benchmark_file_ref: zAgentFileRefConfig.nullish(),
  enabled: z.boolean().optional().default(false),
  model_ref: zAgentSoulModelConfig.nullish(),
  prompt: z.string().nullish(),
})

/**
 * DeclaredOutputConfig
 *
 * One declared output of a Workflow Agent Node.
 *
 * Stage 4 normalizes the shape: ``check`` is singular (was ``checks: list`` in
 * stage 3), and ``failure_strategy`` defaults to a populated value so runtime
 * code can call ``output.failure_strategy.on_failure`` without None-guards.
 */
export const zDeclaredOutputConfig = z.object({
  array_item: zDeclaredArrayItem.nullish(),
  check: zDeclaredOutputCheckConfig.nullish(),
  children: z
    .array(
      z.object({
        array_item: z
          .object({
            children: z.array(z.record(z.string(), z.unknown())).optional(),
            description: z.string().nullish(),
            type: z.enum(['array', 'boolean', 'file', 'number', 'object', 'string']).optional(),
          })
          .nullish(),
        children: z.array(z.record(z.string(), z.unknown())).optional(),
        description: z.string().nullish(),
        file: z.record(z.string(), z.unknown()).nullish(),
        name: z.string(),
        required: z.boolean().optional(),
        type: z.enum(['array', 'boolean', 'file', 'number', 'object', 'string']),
      }),
    )
    .optional(),
  description: z.string().nullish(),
  failure_strategy: zDeclaredOutputFailureStrategy.optional(),
  file: zDeclaredOutputFileConfig.nullish(),
  id: z.string().nullish(),
  name: z.string().min(1).max(255),
  required: z.boolean().optional().default(true),
  type: zDeclaredOutputType,
})

/**
 * WorkflowNodeJobConfig
 */
export const zWorkflowNodeJobConfig = z.object({
  declared_outputs: z.array(zDeclaredOutputConfig).optional(),
  human_contacts: z.array(zAgentHumanContactConfig).optional(),
  metadata: zWorkflowNodeJobMetadata.optional(),
  mode: zWorkflowNodeJobMode.optional().default('tell_agent_what_to_do'),
  previous_node_output_refs: z.array(zWorkflowPreviousNodeOutputRef).optional(),
  schema_version: z.int().optional().default(1),
  workflow_prompt: z.string().optional().default(''),
})

/**
 * AgentSoulDifyToolCredentialRef
 *
 * Reference to a stored Dify Plugin Tool credential.
 *
 * Secret values are resolved only at runtime. The legacy ``credential_id``
 * field is accepted by :class:`AgentSoulDifyToolConfig` and normalized here so
 * old Agent tool payloads can be read while new payloads stay explicit.
 */
export const zAgentSoulDifyToolCredentialRef = z.object({
  id: z.string().max(255).nullish(),
  provider: z.string().max(255).nullish(),
  type: z.enum(['provider', 'tool']).optional().default('tool'),
})

/**
 * ToolProviderType
 *
 * Enum class for tool provider
 */
export const zToolProviderType = z.enum([
  'api',
  'app',
  'builtin',
  'dataset-retrieval',
  'mcp',
  'plugin',
  'workflow',
])

/**
 * AgentSoulDifyToolConfig
 *
 * One Dify tool configured on Agent Soul.
 *
 * The API backend prepares this persisted product shape into
 * either ``DifyPluginToolConfig`` or ``DifyCoreToolConfig`` before sending a
 * run request to Agent backend. ``plugin`` providers keep the direct
 * ``dify.plugin.tools`` transport; ``builtin`` / ``api`` / ``workflow`` /
 * ``mcp`` providers are prepared for ``dify.core.tools``. ``provider_id``
 * keeps compatibility with existing Agent tool config payloads; new callers
 * should send ``plugin_id`` + ``provider`` when available.
 */
export const zAgentSoulDifyToolConfig = z.object({
  credential_ref: zAgentSoulDifyToolCredentialRef.nullish(),
  credential_type: z.enum(['api-key', 'oauth2', 'unauthorized']).optional().default('api-key'),
  description: z.string().nullish(),
  enabled: z.boolean().optional().default(true),
  name: z.string().max(255).nullish(),
  plugin_id: z.string().max(255).nullish(),
  provider: z.string().max(255).nullish(),
  provider_id: z.string().max(255).nullish(),
  provider_type: zToolProviderType,
  runtime_parameters: z
    .record(
      z.string(),
      z
        .union([
          z.string(),
          z.int(),
          z.number(),
          z.boolean(),
          z.array(z.string()),
          z.array(z.int()),
          z.array(z.number()),
          z.array(z.boolean()),
        ])
        .nullable(),
    )
    .optional(),
  tool_name: z.string().min(1).max(255).nullish(),
})

/**
 * AgentSoulToolsConfig
 */
export const zAgentSoulToolsConfig = z.object({
  cli_tools: z.array(zAgentCliToolConfig).optional(),
  dify_tools: z.array(zAgentSoulDifyToolConfig).optional(),
})

/**
 * AgentModerationIOConfig
 */
export const zAgentModerationIoConfig = z.object({
  enabled: z.boolean().optional().default(false),
  preset_response: z.string().nullish(),
})

/**
 * AgentModerationProviderConfig
 */
export const zAgentModerationProviderConfig = z.object({
  api_based_extension_id: z.string().nullish(),
  inputs_config: zAgentModerationIoConfig.nullish(),
  keywords: z.string().nullish(),
  outputs_config: zAgentModerationIoConfig.nullish(),
})

/**
 * AgentSensitiveWordAvoidanceFeatureConfig
 */
export const zAgentSensitiveWordAvoidanceFeatureConfig = z.object({
  config: zAgentModerationProviderConfig.nullish(),
  enabled: z.boolean().optional().default(false),
  type: z.string().nullish(),
})

/**
 * AgentSoulAppFeaturesConfig
 */
export const zAgentSoulAppFeaturesConfig = z.object({
  file_upload: zAgentFileUploadFeatureConfig.optional(),
  opening_statement: z.string().nullish(),
  retriever_resource: zAgentFeatureToggleConfig.nullish(),
  sensitive_word_avoidance: zAgentSensitiveWordAvoidanceFeatureConfig.nullish(),
  speech_to_text: zAgentFeatureToggleConfig.nullish(),
  suggested_questions: z.array(z.string()).nullish(),
  suggested_questions_after_answer: zAgentSuggestedQuestionsAfterAnswerFeatureConfig.nullish(),
  text_to_speech: zAgentTextToSpeechFeatureConfig.nullish(),
})

/**
 * AgentKnowledgeModelConfig
 */
export const zAgentKnowledgeModelConfig = z.object({
  completion_params: z.record(z.string(), z.unknown()).optional(),
  mode: z.string().min(1).max(64),
  name: z.string().min(1).max(255),
  provider: z.string().min(1).max(255),
})

/**
 * AgentKnowledgeQueryMode
 */
export const zAgentKnowledgeQueryMode = z.enum(['generated_query', 'user_query'])

/**
 * AgentKnowledgeQueryConfig
 *
 * Per-set query policy for Agent v2 knowledge retrieval.
 *
 * Agent v2 stores knowledge as explicit ``knowledge.sets`` rather than the
 * legacy flat ``datasets`` / ``query_mode`` / ``query_config`` shape. Each
 * set owns its own query policy. Mode-dependent completeness, such as
 * requiring ``value`` for ``user_query``, is enforced by composer publish
 * validation so draft saves can persist partially configured knowledge sets.
 */
export const zAgentKnowledgeQueryConfig = z.object({
  mode: zAgentKnowledgeQueryMode,
  value: z.string().nullish(),
})

/**
 * AgentKnowledgeRerankingModelConfig
 */
export const zAgentKnowledgeRerankingModelConfig = z.object({
  model: z.string().min(1).max(255),
  provider: z.string().min(1).max(255),
})

/**
 * AgentKnowledgeWeightedScoreConfig
 */
export const zAgentKnowledgeWeightedScoreConfig = z.object({
  keyword_setting: z.record(z.string(), z.unknown()).nullish(),
  vector_setting: z.record(z.string(), z.unknown()).nullish(),
  weight_type: z.string().max(64).nullish(),
})

/**
 * AgentKnowledgeRetrievalConfig
 *
 * Per-set retrieval policy for Agent v2 knowledge retrieval.
 *
 * Retrieval settings now live on each knowledge set instead of one shared
 * flat config. Mode-dependent completeness, such as requiring ``top_k`` for
 * ``multiple`` or a model for ``single``, is enforced by composer publish
 * validation so draft saves can persist partially configured knowledge sets.
 */
export const zAgentKnowledgeRetrievalConfig = z.object({
  mode: z.enum(['multiple', 'single']),
  model: zAgentKnowledgeModelConfig.nullish(),
  reranking_enable: z.boolean().optional().default(true),
  reranking_mode: z.string().optional().default('reranking_model'),
  reranking_model: zAgentKnowledgeRerankingModelConfig.nullish(),
  score_threshold: z.number().gte(0).lte(1).nullish(),
  top_k: z.int().gte(1).nullish(),
  weights: zAgentKnowledgeWeightedScoreConfig.nullish(),
})

/**
 * AgentKnowledgeMetadataCondition
 */
export const zAgentKnowledgeMetadataCondition = z.object({
  comparison_operator: z.enum([
    '<',
    '=',
    '>',
    'after',
    'before',
    'contains',
    'empty',
    'end with',
    'in',
    'is',
    'is not',
    'not contains',
    'not empty',
    'not in',
    'start with',
    '≠',
    '≤',
    '≥',
  ]),
  name: z.string().min(1).max(255),
  value: z.union([z.string(), z.array(z.string()), z.number()]).nullish(),
})

/**
 * AgentKnowledgeMetadataConditions
 */
export const zAgentKnowledgeMetadataConditions = z.object({
  conditions: z.array(zAgentKnowledgeMetadataCondition).optional(),
  logical_operator: z.enum(['and', 'or']).optional().default('and'),
})

/**
 * AgentKnowledgeMetadataFilteringConfig
 *
 * Per-set metadata filtering policy.
 *
 * The Python attribute uses ``metadata_model_config`` for clarity because the
 * model belongs to metadata filtering specifically, while the external API and
 * generated schema keep the historical ``model_config`` field name via alias.
 * Mode-dependent completeness is enforced by composer publish validation so
 * draft saves can persist partially configured metadata filters.
 */
export const zAgentKnowledgeMetadataFilteringConfig = z.object({
  conditions: zAgentKnowledgeMetadataConditions.nullish(),
  mode: z.enum(['automatic', 'disabled', 'manual']).optional().default('disabled'),
  model_config: zAgentKnowledgeModelConfig.nullish(),
})

/**
 * AgentKnowledgeSetConfig
 *
 * One explicit knowledge set in Agent v2.
 *
 * ``knowledge.sets`` replaces the old flat knowledge config. Each set owns
 * its datasets plus query, retrieval, and metadata policies. An individual
 * set must contain at least one dataset id even though the overall knowledge
 * section may be empty, which is how callers express "no knowledge layer".
 */
export const zAgentKnowledgeSetConfig = z.object({
  datasets: z.array(zAgentKnowledgeDatasetConfig),
  description: z.string().nullish(),
  id: z.string().min(1).max(255),
  metadata_filtering: zAgentKnowledgeMetadataFilteringConfig.optional(),
  name: z.string().min(1).max(255),
  query: zAgentKnowledgeQueryConfig,
  retrieval: zAgentKnowledgeRetrievalConfig,
})

/**
 * AgentSoulKnowledgeConfig
 *
 * Top-level Agent v2 knowledge config.
 *
 * Agent v2 models knowledge as explicit sets instead of one flat
 * ``datasets`` / ``query_mode`` / ``query_config`` block. An empty ``sets``
 * list means no knowledge layer should be emitted at runtime, while set-name
 * uniqueness stays case-insensitive because runtime selection addresses sets
 * by name.
 */
export const zAgentSoulKnowledgeConfig = z.object({
  sets: z.array(zAgentKnowledgeSetConfig).optional(),
})

/**
 * AgentSoulConfig
 */
export const zAgentSoulConfig = z.object({
  app_features: zAgentSoulAppFeaturesConfig.optional(),
  app_variables: z.array(zAppVariableConfig).optional(),
  config_files: z.array(zAgentConfigFileRefConfig).optional(),
  config_note: z.string().optional().default(''),
  config_skills: z.array(zAgentConfigSkillRefConfig).optional(),
  env: zAgentSoulEnvConfig.optional(),
  files: zAgentSoulFilesConfig.optional(),
  human: zAgentSoulHumanConfig.optional(),
  knowledge: zAgentSoulKnowledgeConfig.optional(),
  memory: zAgentSoulMemoryConfig.optional(),
  misc_legacy: zAgentSoulAppFeaturesConfig.optional(),
  model: zAgentSoulModelConfig.nullish(),
  prompt: zAgentSoulPromptConfig.optional(),
  sandbox: zAgentSoulSandboxConfig.optional(),
  schema_version: z.int().optional().default(1),
  tools: zAgentSoulToolsConfig.optional(),
})

/**
 * WorkflowAgentComposerResponse
 */
export const zWorkflowAgentComposerResponse = z.object({
  active_config_snapshot: zAgentConfigSnapshotSummaryResponse.nullish(),
  agent: zAgentComposerAgentResponse.nullish(),
  agent_soul: zAgentSoulConfig,
  app_id: z.string().nullish(),
  backing_app_id: z.string().nullish(),
  binding: zAgentComposerBindingResponse.nullish(),
  chat_endpoint: z.string().nullish(),
  debug_conversation_has_messages: z.boolean().optional().default(false),
  debug_conversation_id: z.string().nullish(),
  debug_conversation_message_count: z.int().optional().default(0),
  effective_declared_outputs: z.array(zDeclaredOutputConfig).optional(),
  hidden_app_backed: z.boolean().optional().default(false),
  impact_summary: zAgentComposerImpactResponse.nullish(),
  node_id: z.string().nullish(),
  node_job: zWorkflowNodeJobConfig,
  save_options: z.array(zComposerSaveStrategy),
  soul_lock: zAgentComposerSoulLockResponse,
  validation: zComposerValidationFindingsResponse.nullish(),
  variant: z.literal('workflow'),
  workflow_id: z.string().nullish(),
})

/**
 * ComposerSavePayload
 */
export const zComposerSavePayload = z.object({
  agent_soul: zAgentSoulConfig.nullish(),
  binding: zComposerBindingPayload.nullish(),
  client_revision_id: z.string().nullish(),
  description: z.string().nullish(),
  icon: z.string().max(255).nullish(),
  icon_background: z.string().max(255).nullish(),
  icon_type: zAgentIconType.nullish(),
  idempotency_key: z.string().nullish(),
  new_agent_name: z.string().min(1).max(255).nullish(),
  node_job: zWorkflowNodeJobConfig.nullish(),
  role: z.string().max(255).nullish(),
  save_strategy: zComposerSaveStrategy,
  soul_lock: zComposerSoulLockPayload.optional(),
  variant: zComposerVariant,
  version_note: z.string().nullish(),
})

export const zGetSnippetsBySnippetIdWorkflowRunsPath = z.object({
  snippet_id: z.uuid(),
})

export const zGetSnippetsBySnippetIdWorkflowRunsQuery = z.object({
  last_id: z.string().optional(),
  limit: z.int().gte(1).lte(100).optional().default(20),
})

/**
 * Workflow runs retrieved successfully
 */
export const zGetSnippetsBySnippetIdWorkflowRunsResponse = zWorkflowRunPaginationResponse

export const zPostSnippetsBySnippetIdWorkflowRunsTasksByTaskIdStopPath = z.object({
  snippet_id: z.uuid(),
  task_id: z.string(),
})

/**
 * Task stopped successfully
 */
export const zPostSnippetsBySnippetIdWorkflowRunsTasksByTaskIdStopResponse = zSimpleResultResponse

export const zGetSnippetsBySnippetIdWorkflowRunsByRunIdPath = z.object({
  run_id: z.uuid(),
  snippet_id: z.uuid(),
})

/**
 * Workflow run detail retrieved successfully
 */
export const zGetSnippetsBySnippetIdWorkflowRunsByRunIdResponse = zWorkflowRunDetailResponse

export const zGetSnippetsBySnippetIdWorkflowRunsByRunIdNodeExecutionsPath = z.object({
  run_id: z.uuid(),
  snippet_id: z.uuid(),
})

/**
 * Node executions retrieved successfully
 */
export const zGetSnippetsBySnippetIdWorkflowRunsByRunIdNodeExecutionsResponse =
  zWorkflowRunNodeExecutionListResponse

export const zGetSnippetsBySnippetIdWorkflowsPath = z.object({
  snippet_id: z.uuid(),
})

export const zGetSnippetsBySnippetIdWorkflowsQuery = z.object({
  limit: z.int().gte(1).lte(100).optional().default(10),
  page: z.int().gte(1).lte(99999).optional().default(1),
})

/**
 * Published workflows retrieved successfully
 */
export const zGetSnippetsBySnippetIdWorkflowsResponse = zSnippetWorkflowPaginationResponse

export const zGetSnippetsBySnippetIdWorkflowsDefaultWorkflowBlockConfigsPath = z.object({
  snippet_id: z.uuid(),
})

/**
 * Default block configs retrieved successfully
 */
export const zGetSnippetsBySnippetIdWorkflowsDefaultWorkflowBlockConfigsResponse =
  zDefaultBlockConfigsResponse

export const zGetSnippetsBySnippetIdWorkflowsDraftPath = z.object({
  snippet_id: z.uuid(),
})

/**
 * Draft workflow retrieved successfully
 */
export const zGetSnippetsBySnippetIdWorkflowsDraftResponse = zSnippetWorkflowResponse

export const zPostSnippetsBySnippetIdWorkflowsDraftBody = zSnippetDraftSyncPayload

export const zPostSnippetsBySnippetIdWorkflowsDraftPath = z.object({
  snippet_id: z.uuid(),
})

/**
 * Draft workflow synced successfully
 */
export const zPostSnippetsBySnippetIdWorkflowsDraftResponse = zWorkflowRestoreResponse

export const zGetSnippetsBySnippetIdWorkflowsDraftConfigPath = z.object({
  snippet_id: z.uuid(),
})

/**
 * Draft config retrieved successfully
 */
export const zGetSnippetsBySnippetIdWorkflowsDraftConfigResponse = zSnippetDraftConfigResponse

export const zGetSnippetsBySnippetIdWorkflowsDraftConversationVariablesPath = z.object({
  snippet_id: z.uuid(),
})

/**
 * Conversation variables retrieved successfully
 */
export const zGetSnippetsBySnippetIdWorkflowsDraftConversationVariablesResponse =
  zWorkflowDraftVariableList

export const zGetSnippetsBySnippetIdWorkflowsDraftEnvironmentVariablesPath = z.object({
  snippet_id: z.uuid(),
})

/**
 * Environment variables retrieved successfully
 */
export const zGetSnippetsBySnippetIdWorkflowsDraftEnvironmentVariablesResponse =
  zEnvironmentVariableListResponse

export const zPostSnippetsBySnippetIdWorkflowsDraftIterationNodesByNodeIdRunBody =
  zSnippetIterationNodeRunPayload

export const zPostSnippetsBySnippetIdWorkflowsDraftIterationNodesByNodeIdRunPath = z.object({
  node_id: z.string(),
  snippet_id: z.uuid(),
})

/**
 * Iteration node run started successfully (SSE stream)
 */
export const zPostSnippetsBySnippetIdWorkflowsDraftIterationNodesByNodeIdRunResponse =
  zGeneratedAppResponse

export const zPostSnippetsBySnippetIdWorkflowsDraftLoopNodesByNodeIdRunBody =
  zSnippetLoopNodeRunPayload

export const zPostSnippetsBySnippetIdWorkflowsDraftLoopNodesByNodeIdRunPath = z.object({
  node_id: z.string(),
  snippet_id: z.uuid(),
})

/**
 * Loop node run started successfully (SSE stream)
 */
export const zPostSnippetsBySnippetIdWorkflowsDraftLoopNodesByNodeIdRunResponse =
  zGeneratedAppResponse

export const zGetSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerPath = z.object({
  node_id: z.string(),
  snippet_id: z.uuid(),
})

export const zGetSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerQuery = z.object({
  snapshot_id: z.string().max(255).optional(),
})

/**
 * Snippet agent composer state
 */
export const zGetSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerResponse =
  zWorkflowAgentComposerResponse

export const zPutSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerBody =
  zComposerSavePayload

export const zPutSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerPath = z.object({
  node_id: z.string(),
  snippet_id: z.uuid(),
})

/**
 * Snippet agent composer saved
 */
export const zPutSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerResponse =
  zWorkflowAgentComposerResponse

export const zGetSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerCandidatesPath =
  z.object({
    node_id: z.string(),
    snippet_id: z.uuid(),
  })

/**
 * Snippet agent composer candidates
 */
export const zGetSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerCandidatesResponse =
  zAgentComposerCandidatesResponse

export const zPostSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerCopyFromRosterBody =
  zWorkflowComposerCopyFromRosterPayload

export const zPostSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerCopyFromRosterPath =
  z.object({
    node_id: z.string(),
    snippet_id: z.uuid(),
  })

/**
 * Roster agent copied into snippet
 */
export const zPostSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerCopyFromRosterResponse =
  zWorkflowAgentComposerResponse

export const zPostSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerImpactBody =
  zComposerSavePayload

export const zPostSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerImpactPath = z.object({
  node_id: z.string(),
  snippet_id: z.uuid(),
})

/**
 * Snippet agent composer impact
 */
export const zPostSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerImpactResponse =
  zAgentComposerImpactResponse

export const zPostSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerSaveToRosterBody =
  zComposerSavePayload

export const zPostSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerSaveToRosterPath =
  z.object({
    node_id: z.string(),
    snippet_id: z.uuid(),
  })

/**
 * Snippet agent saved to roster
 */
export const zPostSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerSaveToRosterResponse =
  zWorkflowAgentComposerResponse

export const zPostSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerValidateBody =
  zComposerSavePayload

export const zPostSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerValidatePath =
  z.object({
    node_id: z.string(),
    snippet_id: z.uuid(),
  })

/**
 * Snippet agent composer validation
 */
export const zPostSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdAgentComposerValidateResponse =
  zAgentComposerValidateResponse

export const zGetSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdLastRunPath = z.object({
  node_id: z.string(),
  snippet_id: z.uuid(),
})

/**
 * Node last run retrieved successfully
 */
export const zGetSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdLastRunResponse =
  zWorkflowRunNodeExecutionResponse

export const zPostSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdRunBody =
  zSnippetDraftNodeRunPayload

export const zPostSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdRunPath = z.object({
  node_id: z.string(),
  snippet_id: z.uuid(),
})

/**
 * Node run completed successfully
 */
export const zPostSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdRunResponse =
  zWorkflowRunNodeExecutionResponse

export const zDeleteSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdVariablesPath = z.object({
  node_id: z.string(),
  snippet_id: z.uuid(),
})

/**
 * Node variables deleted successfully
 */
export const zDeleteSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdVariablesResponse = z.void()

export const zGetSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdVariablesPath = z.object({
  node_id: z.string(),
  snippet_id: z.uuid(),
})

/**
 * Node variables retrieved successfully
 */
export const zGetSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdVariablesResponse =
  zWorkflowDraftVariableList

export const zPostSnippetsBySnippetIdWorkflowsDraftRunBody = zSnippetDraftRunPayload

export const zPostSnippetsBySnippetIdWorkflowsDraftRunPath = z.object({
  snippet_id: z.uuid(),
})

/**
 * Draft workflow run started successfully (SSE stream)
 */
export const zPostSnippetsBySnippetIdWorkflowsDraftRunResponse = zGeneratedAppResponse

export const zGetSnippetsBySnippetIdWorkflowsDraftSystemVariablesPath = z.object({
  snippet_id: z.uuid(),
})

/**
 * System variables retrieved successfully
 */
export const zGetSnippetsBySnippetIdWorkflowsDraftSystemVariablesResponse =
  zWorkflowDraftVariableList

export const zDeleteSnippetsBySnippetIdWorkflowsDraftVariablesPath = z.object({
  snippet_id: z.uuid(),
})

/**
 * Workflow variables deleted successfully
 */
export const zDeleteSnippetsBySnippetIdWorkflowsDraftVariablesResponse = z.void()

export const zGetSnippetsBySnippetIdWorkflowsDraftVariablesPath = z.object({
  snippet_id: z.uuid(),
})

export const zGetSnippetsBySnippetIdWorkflowsDraftVariablesQuery = z.object({
  limit: z.int().gte(1).lte(100).optional().default(20),
  page: z.int().gte(1).lte(100000).optional().default(1),
})

/**
 * Workflow variables retrieved successfully
 */
export const zGetSnippetsBySnippetIdWorkflowsDraftVariablesResponse =
  zWorkflowDraftVariableListWithoutValue

export const zDeleteSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdPath = z.object({
  snippet_id: z.uuid(),
  variable_id: z.uuid(),
})

/**
 * Variable deleted successfully
 */
export const zDeleteSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdResponse = z.void()

export const zGetSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdPath = z.object({
  snippet_id: z.uuid(),
  variable_id: z.uuid(),
})

/**
 * Variable retrieved successfully
 */
export const zGetSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdResponse =
  zWorkflowDraftVariable

export const zPatchSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdBody =
  zWorkflowDraftVariableUpdatePayload

export const zPatchSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdPath = z.object({
  snippet_id: z.uuid(),
  variable_id: z.uuid(),
})

/**
 * Variable updated successfully
 */
export const zPatchSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdResponse =
  zWorkflowDraftVariable

export const zPutSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdResetPath = z.object({
  snippet_id: z.uuid(),
  variable_id: z.uuid(),
})

export const zPutSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdResetResponse = z.union([
  zWorkflowDraftVariable,
  z.void(),
])

export const zGetSnippetsBySnippetIdWorkflowsPublishPath = z.object({
  snippet_id: z.uuid(),
})

/**
 * Published workflow retrieved successfully
 */
export const zGetSnippetsBySnippetIdWorkflowsPublishResponse = zSnippetWorkflowResponse

export const zPostSnippetsBySnippetIdWorkflowsPublishBody = zPublishWorkflowPayload

export const zPostSnippetsBySnippetIdWorkflowsPublishPath = z.object({
  snippet_id: z.uuid(),
})

/**
 * Workflow published successfully
 */
export const zPostSnippetsBySnippetIdWorkflowsPublishResponse = zWorkflowPublishResponse

export const zPatchSnippetsBySnippetIdWorkflowsByWorkflowIdBody = zWorkflowUpdatePayload

export const zPatchSnippetsBySnippetIdWorkflowsByWorkflowIdPath = z.object({
  snippet_id: z.uuid(),
  workflow_id: z.string(),
})

/**
 * Workflow updated successfully
 */
export const zPatchSnippetsBySnippetIdWorkflowsByWorkflowIdResponse = zSnippetWorkflowResponse

export const zPostSnippetsBySnippetIdWorkflowsByWorkflowIdRestorePath = z.object({
  snippet_id: z.uuid(),
  workflow_id: z.string(),
})

/**
 * Workflow restored successfully
 */
export const zPostSnippetsBySnippetIdWorkflowsByWorkflowIdRestoreResponse = zWorkflowRestoreResponse
