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

import * as z from 'zod'

/**
 * AppImportPayload
 */
export const zAppImportPayload = z.object({
  app_id: z.string().nullish(),
  description: z.string().nullish(),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: z.string().nullish(),
  mode: z.string(),
  name: z.string().nullish(),
  yaml_content: z.string().nullish(),
  yaml_url: z.string().nullish(),
})

/**
 * WorkflowOnlineUsersPayload
 */
export const zWorkflowOnlineUsersPayload = z.object({
  app_ids: z.array(z.string()).optional(),
})

/**
 * WorkflowRunCountResponse
 */
export const zWorkflowRunCountResponse = z.object({
  failed: z.int(),
  partial_succeeded: z.int(),
  running: z.int(),
  stopped: z.int(),
  succeeded: z.int(),
  total: z.int(),
})

/**
 * HumanInputFormPreviewPayload
 */
export const zHumanInputFormPreviewPayload = z.object({
  inputs: z.record(z.string(), z.unknown()).optional(),
})

/**
 * HumanInputFormPreviewResponse
 */
export const zHumanInputFormPreviewResponse = z.object({
  actions: z.array(z.record(z.string(), z.unknown())).optional(),
  display_in_ui: z.boolean().nullish(),
  expiration_time: z.int().nullish(),
  form_content: z.string(),
  form_id: z.string(),
  form_token: z.string().nullish(),
  inputs: z.array(z.record(z.string(), z.unknown())).optional(),
  node_id: z.string(),
  node_title: z.string(),
  resolved_default_values: z.record(z.string(), z.unknown()).optional(),
})

/**
 * HumanInputFormSubmitPayload
 */
export const zHumanInputFormSubmitPayload = z.object({
  action: z.string(),
  form_inputs: z.record(z.string(), z.unknown()),
  inputs: z.record(z.string(), z.unknown()),
})

/**
 * HumanInputFormSubmitResponse
 */
export const zHumanInputFormSubmitResponse = z.record(z.string(), z.unknown())

/**
 * IterationNodeRunPayload
 */
export const zIterationNodeRunPayload = z.object({
  inputs: z.record(z.string(), z.unknown()).nullish(),
})

/**
 * LoopNodeRunPayload
 */
export const zLoopNodeRunPayload = z.object({
  inputs: z.record(z.string(), z.unknown()).nullish(),
})

/**
 * AdvancedChatWorkflowRunPayload
 */
export const zAdvancedChatWorkflowRunPayload = z.object({
  conversation_id: z.string().nullish(),
  files: z.array(z.record(z.string(), z.unknown())).nullish(),
  inputs: z.record(z.string(), z.unknown()).nullish(),
  parent_message_id: z.string().nullish(),
  query: z.string().optional().default(''),
})

/**
 * AgentConfigFileUploadPayload
 */
export const zAgentConfigFileUploadPayload = z.object({
  upload_file_id: z.string(),
})

/**
 * AgentConfigDeleteResponse
 */
export const zAgentConfigDeleteResponse = z.object({
  removed_names: z.array(z.string()).optional(),
  result: z.literal('success'),
})

/**
 * AgentConfigDownloadResponse
 */
export const zAgentConfigDownloadResponse = z.object({
  url: z.string(),
})

/**
 * AgentConfigFilePreviewResponse
 */
export const zAgentConfigFilePreviewResponse = z.object({
  binary: z.boolean(),
  name: z.string(),
  size: z.int().nullish(),
  text: z.string().nullish(),
  truncated: z.boolean(),
})

/**
 * AgentConfigSkillFilePreviewResponse
 */
export const zAgentConfigSkillFilePreviewResponse = z.object({
  binary: z.boolean(),
  path: z.string(),
  size: z.int().nullish(),
  text: z.string().nullish(),
  truncated: z.boolean(),
})

/**
 * AgentDriveDownloadResponse
 */
export const zAgentDriveDownloadResponse = z.object({
  url: z.string(),
})

/**
 * AgentDrivePreviewResponse
 */
export const zAgentDrivePreviewResponse = z.object({
  binary: z.boolean(),
  key: z.string(),
  size: z.int().nullish(),
  text: z.string().nullish(),
  truncated: z.boolean(),
})

/**
 * AgentDriveDeleteResponse
 */
export const zAgentDriveDeleteResponse = z.object({
  removed_keys: z.array(z.string()).optional(),
  result: z.string(),
})

/**
 * AgentDriveFilePayload
 */
export const zAgentDriveFilePayload = z.object({
  upload_file_id: z.string(),
})

/**
 * AnnotationReplyPayload
 */
export const zAnnotationReplyPayload = z.object({
  embedding_model_name: z.string(),
  embedding_provider_name: z.string(),
  score_threshold: z.number(),
})

/**
 * AnnotationJobStatusResponse
 */
export const zAnnotationJobStatusResponse = z.object({
  job_id: z.string(),
  job_status: z.union([z.enum(['completed', 'error', 'processing', 'waiting']), z.string()]),
})

/**
 * AnnotationJobStatusDetailResponse
 */
export const zAnnotationJobStatusDetailResponse = z.object({
  error_msg: z.string().optional().default(''),
  job_id: z.string(),
  job_status: z.union([z.enum(['completed', 'error', 'processing', 'waiting']), z.string()]),
})

/**
 * AnnotationSettingUpdatePayload
 */
export const zAnnotationSettingUpdatePayload = z.object({
  score_threshold: z.number(),
})

/**
 * CreateAnnotationPayload
 */
export const zCreateAnnotationPayload = z.object({
  annotation_reply: z.record(z.string(), z.unknown()).nullish(),
  answer: z.string().nullish(),
  content: z.string().nullish(),
  message_id: z.string().nullish(),
  question: z.string().nullish(),
})

/**
 * Annotation
 */
export const zAnnotation = z.object({
  answer: z.string().nullish(),
  created_at: z.int().nullish(),
  hit_count: z.int().nullish(),
  id: z.string(),
  question: z.string().nullish(),
})

/**
 * AnnotationList
 */
export const zAnnotationList = z.object({
  data: z.array(zAnnotation),
  has_more: z.boolean(),
  limit: z.int(),
  page: z.int(),
  total: z.int(),
})

/**
 * AnnotationBatchImportResponse
 */
export const zAnnotationBatchImportResponse = z.object({
  error_msg: z.string().nullish(),
  job_id: z.string().nullish(),
  job_status: z.string().nullish(),
  record_count: z.int().nullish(),
})

/**
 * AnnotationCountResponse
 */
export const zAnnotationCountResponse = z.object({
  count: z.int(),
})

/**
 * AnnotationExportList
 */
export const zAnnotationExportList = z.object({
  data: z.array(zAnnotation),
})

/**
 * UpdateAnnotationPayload
 */
export const zUpdateAnnotationPayload = z.object({
  annotation_reply: z.record(z.string(), z.unknown()).nullish(),
  answer: z.string().nullish(),
  content: z.string().nullish(),
  question: z.string().nullish(),
})

/**
 * AppApiStatusPayload
 */
export const zAppApiStatusPayload = z.object({
  enable_api: z.boolean(),
})

/**
 * AudioTranscriptResponse
 */
export const zAudioTranscriptResponse = z.object({
  text: z.string(),
})

/**
 * SuggestedQuestionsResponse
 */
export const zSuggestedQuestionsResponse = z.object({
  data: z.array(z.string()),
})

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

/**
 * CompletionMessagePayload
 */
export const zCompletionMessagePayload = z.object({
  files: z.array(z.unknown()).nullish(),
  inputs: z.record(z.string(), z.unknown()),
  model_config: z.record(z.string(), z.unknown()).optional(),
  query: z.string().optional().default(''),
  response_mode: z.enum(['blocking', 'streaming']).optional().default('blocking'),
  retriever_from: z.string().optional().default('dev'),
})

/**
 * ConvertToWorkflowPayload
 */
export const zConvertToWorkflowPayload = z.object({
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: z.string().nullish(),
  name: z.string().nullish(),
})

/**
 * NewAppResponse
 */
export const zNewAppResponse = z.object({
  new_app_id: z.string(),
  permission_keys: z.array(z.string()).optional(),
})

/**
 * AppExportResponse
 */
export const zAppExportResponse = z.object({
  data: z.string(),
})

/**
 * MessageFeedbackPayload
 */
export const zMessageFeedbackPayload = z.object({
  content: z.string().nullish(),
  message_id: z.string(),
  rating: z.enum(['dislike', 'like']).nullish(),
})

/**
 * TextFileResponse
 */
export const zTextFileResponse = z.string()

/**
 * ModelConfigRequest
 */
export const zModelConfigRequest = z.object({
  agent_mode: z.record(z.string(), z.unknown()).nullish(),
  configs: z.record(z.string(), z.unknown()).nullish(),
  dataset_configs: z.record(z.string(), z.unknown()).nullish(),
  model: z.string().nullish(),
  more_like_this: z.record(z.string(), z.unknown()).nullish(),
  opening_statement: z.string().nullish(),
  provider: z.string().nullish(),
  retrieval_model: z.record(z.string(), z.unknown()).nullish(),
  speech_to_text: z.record(z.string(), z.unknown()).nullish(),
  suggested_questions: z.array(z.string()).nullish(),
  text_to_speech: z.record(z.string(), z.unknown()).nullish(),
  tools: z.array(z.record(z.string(), z.unknown())).nullish(),
})

/**
 * AppNamePayload
 */
export const zAppNamePayload = z.object({
  name: z.string().min(1),
})

/**
 * RedirectUrlResponse
 */
export const zRedirectUrlResponse = z.object({
  redirect_url: z.string(),
})

/**
 * MCPServerCreatePayload
 */
export const zMcpServerCreatePayload = z.object({
  description: z.string().nullish(),
  parameters: z.record(z.string(), z.unknown()),
})

/**
 * MCPServerUpdatePayload
 */
export const zMcpServerUpdatePayload = z.object({
  description: z.string().nullish(),
  id: z.string(),
  parameters: z.record(z.string(), z.unknown()),
  status: z.string().nullish(),
})

/**
 * AppSiteUpdatePayload
 */
export const zAppSiteUpdatePayload = z.object({
  chat_color_theme: z.string().nullish(),
  chat_color_theme_inverted: z.boolean().nullish(),
  copyright: z.string().nullish(),
  custom_disclaimer: z.string().nullish(),
  customize_domain: z.string().nullish(),
  customize_token_strategy: z.enum(['allow', 'must', 'not_allow']).nullish(),
  default_language: z.string().nullish(),
  description: z.string().nullish(),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: z.string().nullish(),
  input_placeholder: z.string().nullish(),
  privacy_policy: z.string().nullish(),
  prompt_public: z.boolean().nullish(),
  show_workflow_steps: z.boolean().nullish(),
  title: z.string().nullish(),
  use_icon_as_answer_icon: z.boolean().nullish(),
})

/**
 * AppSiteResponse
 */
export const zAppSiteResponse = z.object({
  app_id: z.string(),
  code: z.string().nullish(),
  copyright: z.string().nullish(),
  custom_disclaimer: z.string().nullish(),
  customize_domain: z.string().nullish(),
  customize_token_strategy: z.string(),
  default_language: z.string(),
  description: z.string().nullish(),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  input_placeholder: z.string().nullish(),
  privacy_policy: z.string().nullish(),
  prompt_public: z.boolean(),
  show_workflow_steps: z.boolean(),
  title: z.string(),
  use_icon_as_answer_icon: z.boolean(),
})

/**
 * AppSiteStatusPayload
 */
export const zAppSiteStatusPayload = z.object({
  enable_site: z.boolean(),
})

/**
 * TextToSpeechPayload
 */
export const zTextToSpeechPayload = z.object({
  message_id: z.string().nullish(),
  streaming: z.boolean().nullish(),
  text: z.string(),
  voice: z.string().nullish(),
})

/**
 * AppTraceResponse
 */
export const zAppTraceResponse = z.object({
  enabled: z.boolean().optional().default(false),
  tracing_provider: z.string().nullish(),
})

/**
 * AppTracePayload
 */
export const zAppTracePayload = z.object({
  enabled: z.boolean(),
  tracing_provider: z.string().nullish(),
})

/**
 * TraceAppConfigResponse
 */
export const zTraceAppConfigResponse = z.object({
  app_id: z.string().nullish(),
  created_at: z.string().nullish(),
  error: z.string().nullish(),
  has_not_configured: z.boolean().nullish(),
  id: z.string().nullish(),
  is_active: z.boolean().nullish(),
  result: z.string().nullish(),
  tracing_config: z.record(z.string(), z.unknown()).nullish(),
  tracing_provider: z.string().nullish(),
  updated_at: z.string().nullish(),
})

/**
 * TraceConfigPayload
 */
export const zTraceConfigPayload = z.object({
  tracing_config: z.record(z.string(), z.unknown()),
  tracing_provider: z.string(),
})

/**
 * ParserEnable
 */
export const zParserEnable = z.object({
  enable_trigger: z.boolean(),
  trigger_id: z.string(),
})

/**
 * WorkflowTriggerResponse
 */
export const zWorkflowTriggerResponse = z.object({
  created_at: z.iso.datetime().nullish(),
  icon: z.string(),
  id: z.string(),
  node_id: z.string(),
  provider_name: z.string(),
  status: z.string(),
  title: z.string(),
  trigger_type: z.string(),
  updated_at: z.iso.datetime().nullish(),
})

/**
 * WorkflowTriggerListResponse
 */
export const zWorkflowTriggerListResponse = z.object({
  data: z.array(zWorkflowTriggerResponse),
})

/**
 * WorkflowRunExportResponse
 */
export const zWorkflowRunExportResponse = z.object({
  presigned_url: z.string().nullish(),
  presigned_url_expires_at: z.string().nullish(),
  status: z.string(),
})

/**
 * SandboxReadResponse
 */
export const zSandboxReadResponse = z.object({
  binary: z.boolean(),
  path: z.string(),
  size: z.int().nullish(),
  text: z.string().nullish(),
  truncated: z.boolean(),
})

/**
 * WorkflowAgentSandboxUploadPayload
 */
export const zWorkflowAgentSandboxUploadPayload = z.object({
  node_execution_id: z.string().nullish(),
  path: z.string().min(1),
})

/**
 * SandboxUploadResponse
 */
export const zSandboxUploadResponse = z.object({
  url: z.string(),
})

/**
 * WorkflowCommentCreatePayload
 */
export const zWorkflowCommentCreatePayload = z.object({
  content: z.string(),
  mentioned_user_ids: z.array(z.string()).optional(),
  position_x: z.number(),
  position_y: z.number(),
})

/**
 * WorkflowCommentCreate
 */
export const zWorkflowCommentCreate = z.object({
  created_at: z.int().nullish(),
  id: z.string(),
})

/**
 * WorkflowCommentUpdatePayload
 */
export const zWorkflowCommentUpdatePayload = z.object({
  content: z.string(),
  mentioned_user_ids: z.array(z.string()).nullish(),
  position_x: z.number().nullish(),
  position_y: z.number().nullish(),
})

/**
 * WorkflowCommentUpdate
 */
export const zWorkflowCommentUpdate = z.object({
  id: z.string(),
  updated_at: z.int().nullish(),
})

/**
 * WorkflowCommentReplyPayload
 */
export const zWorkflowCommentReplyPayload = z.object({
  content: z.string(),
  mentioned_user_ids: z.array(z.string()).optional(),
})

/**
 * WorkflowCommentReplyCreate
 */
export const zWorkflowCommentReplyCreate = z.object({
  created_at: z.int().nullish(),
  id: z.string(),
})

/**
 * WorkflowCommentReplyUpdate
 */
export const zWorkflowCommentReplyUpdate = z.object({
  id: z.string(),
  updated_at: z.int().nullish(),
})

/**
 * WorkflowCommentResolve
 */
export const zWorkflowCommentResolve = z.object({
  id: z.string(),
  resolved: z.boolean(),
  resolved_at: z.int().nullish(),
  resolved_by: z.string().nullish(),
})

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

/**
 * DefaultBlockConfigResponse
 */
export const zDefaultBlockConfigResponse = z.record(z.string(), z.unknown())

/**
 * SyncDraftWorkflowPayload
 */
export const zSyncDraftWorkflowPayload = z.object({
  _is_collaborative: z.boolean().optional().default(false),
  conversation_variables: z.array(z.record(z.string(), z.unknown())).optional(),
  environment_variables: z.array(z.record(z.string(), z.unknown())).optional(),
  features: z.record(z.string(), z.unknown()),
  graph: z.record(z.string(), z.unknown()),
  hash: z.string().nullish(),
})

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

/**
 * HumanInputDeliveryTestPayload
 */
export const zHumanInputDeliveryTestPayload = z.object({
  delivery_method_id: z.string(),
  inputs: z.record(z.string(), z.unknown()).optional(),
})

/**
 * EmptyObjectResponse
 */
export const zEmptyObjectResponse = z.record(z.string(), z.unknown())

/**
 * 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(),
})

/**
 * DraftWorkflowNodeRunPayload
 */
export const zDraftWorkflowNodeRunPayload = z.object({
  files: z.array(z.record(z.string(), z.unknown())).nullish(),
  inputs: z.record(z.string(), z.unknown()),
  query: z.string().optional().default(''),
})

/**
 * DraftWorkflowRunPayload
 */
export const zDraftWorkflowRunPayload = z.object({
  datasource_info_list: z.array(z.record(z.string(), z.unknown())),
  datasource_type: z.string(),
  inputs: z.record(z.string(), z.unknown()),
  start_node_id: z.string(),
})

/**
 * EventStreamResponse
 */
export const zEventStreamResponse = z.string()

export const zDraftWorkflowTriggerRunRequest = z.object({
  node_id: z.string(),
})

/**
 * DraftWorkflowTriggerRunAllPayload
 */
export const zDraftWorkflowTriggerRunAllPayload = z.object({
  node_ids: z.array(z.string()),
})

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(),
})

/**
 * WebhookTriggerResponse
 */
export const zWebhookTriggerResponse = z.object({
  created_at: z.iso.datetime().nullish(),
  id: z.string(),
  node_id: z.string(),
  webhook_debug_url: z.string(),
  webhook_id: z.string(),
  webhook_url: z.string(),
})

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

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

/**
 * ApiKeyItem
 */
export const zApiKeyItem = z.object({
  created_at: z.int().nullish(),
  id: z.string(),
  last_used_at: z.int().nullish(),
  token: z.string(),
  type: z.string(),
})

/**
 * ApiKeyList
 */
export const zApiKeyList = z.object({
  data: z.array(zApiKeyItem),
})

/**
 * IconType
 */
export const zIconType = z.enum(['emoji', 'image', 'link'])

/**
 * CreateAppPayload
 */
export const zCreateAppPayload = z.object({
  description: z.string().max(400).nullish(),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: zIconType.nullish(),
  mode: z.enum(['advanced-chat', 'agent-chat', 'chat', 'completion', 'workflow']),
  name: z.string().min(1),
})

/**
 * UpdateAppPayload
 */
export const zUpdateAppPayload = z.object({
  description: z.string().max(400).nullish(),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: zIconType.nullish(),
  max_active_requests: z.int().nullish(),
  name: z.string().min(1),
  use_icon_as_answer_icon: z.boolean().nullish(),
})

/**
 * CopyAppPayload
 */
export const zCopyAppPayload = z.object({
  description: z.string().max(400).nullish(),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: zIconType.nullish(),
  name: z.string().nullish(),
})

/**
 * AppIconPayload
 */
export const zAppIconPayload = z.object({
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: zIconType.nullish(),
})

/**
 * DeletedTool
 */
export const zDeletedTool = z.object({
  provider_id: z.string(),
  tool_name: z.string(),
  type: z.string(),
})

/**
 * AppModelConfigResponse
 */
export const zAppModelConfigResponse = z.object({
  agent_mode: z.unknown().nullish(),
  annotation_reply: z.unknown().nullish(),
  chat_prompt_config: z.unknown().nullish(),
  completion_prompt_config: z.unknown().nullish(),
  created_at: z.int().nullish(),
  created_by: z.string().nullish(),
  dataset_configs: z.unknown().nullish(),
  dataset_query_variable: z.string().nullish(),
  external_data_tools: z.unknown().nullish(),
  file_upload: z.unknown().nullish(),
  model: z.unknown().nullish(),
  more_like_this: z.unknown().nullish(),
  opening_statement: z.string().nullish(),
  pre_prompt: z.string().nullish(),
  prompt_type: z.string().nullish(),
  retriever_resource: z.unknown().nullish(),
  sensitive_word_avoidance: z.unknown().nullish(),
  speech_to_text: z.unknown().nullish(),
  suggested_questions: z.unknown().nullish(),
  suggested_questions_after_answer: z.unknown().nullish(),
  text_to_speech: z.unknown().nullish(),
  updated_at: z.int().nullish(),
  updated_by: z.string().nullish(),
  user_input_form: z.unknown().nullish(),
})

/**
 * AppDetailSiteResponse
 */
export const zAppDetailSiteResponse = z.object({
  access_token: z.string().nullish(),
  app_base_url: z.string().nullish(),
  chat_color_theme: z.string().nullish(),
  chat_color_theme_inverted: z.boolean().nullish(),
  code: z.string().nullish(),
  copyright: z.string().nullish(),
  created_at: z.int().nullish(),
  created_by: z.string().nullish(),
  custom_disclaimer: z.string().nullish(),
  customize_domain: z.string().nullish(),
  customize_token_strategy: z.string().nullish(),
  default_language: z.string().nullish(),
  description: z.string().nullish(),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: z.union([z.string(), zIconType]).nullish(),
  icon_url: z.string().nullable(),
  input_placeholder: z.string().nullish(),
  privacy_policy: z.string().nullish(),
  prompt_public: z.boolean().nullish(),
  show_workflow_steps: z.boolean().nullish(),
  title: z.string().nullish(),
  updated_at: z.int().nullish(),
  updated_by: z.string().nullish(),
  use_icon_as_answer_icon: z.boolean().nullish(),
})

/**
 * Tag
 */
export const zTag = z.object({
  id: z.string(),
  name: z.string(),
  type: z.string(),
})

/**
 * WorkflowPartial
 */
export const zWorkflowPartial = z.object({
  created_at: z.int().nullish(),
  created_by: z.string().nullish(),
  id: z.string(),
  updated_at: z.int().nullish(),
  updated_by: z.string().nullish(),
})

/**
 * AppDetailWithSite
 */
export const zAppDetailWithSite = z.object({
  access_mode: z.string().nullish(),
  api_base_url: z.string().nullish(),
  app_id: z.string().nullish(),
  bound_agent_id: z.string().nullish(),
  created_at: z.int().nullish(),
  created_by: z.string().nullish(),
  deleted_tools: z.array(zDeletedTool).optional(),
  description: z.string().nullish(),
  enable_api: z.boolean(),
  enable_site: z.boolean(),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: z.string().nullish(),
  icon_url: z.string().nullable(),
  id: z.string(),
  maintainer: z.string().nullish(),
  max_active_requests: z.int().nullish(),
  mode: z.string(),
  model_config: zAppModelConfigResponse.nullish(),
  name: z.string(),
  permission_keys: z.array(z.string()).optional(),
  site: zAppDetailSiteResponse.nullish(),
  tags: z.array(zTag).optional(),
  tracing: z.unknown().nullish(),
  updated_at: z.int().nullish(),
  updated_by: z.string().nullish(),
  use_icon_as_answer_icon: z.boolean().nullish(),
  workflow: zWorkflowPartial.nullish(),
})

/**
 * AppDetail
 */
export const zAppDetail = z.object({
  access_mode: z.string().nullish(),
  created_at: z.int().nullish(),
  created_by: z.string().nullish(),
  description: z.string().nullish(),
  enable_api: z.boolean(),
  enable_site: z.boolean(),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  id: z.string(),
  maintainer: z.string().nullish(),
  mode: z.string(),
  model_config: zAppModelConfigResponse.nullish(),
  name: z.string(),
  permission_keys: z.array(z.string()).optional(),
  tags: z.array(zTag).optional(),
  tracing: z.unknown().nullish(),
  updated_at: z.int().nullish(),
  updated_by: z.string().nullish(),
  use_icon_as_answer_icon: z.boolean().nullish(),
  workflow: zWorkflowPartial.nullish(),
})

/**
 * ImportStatus
 */
export const zImportStatus = z.enum(['completed', 'completed-with-warnings', 'failed', 'pending'])

/**
 * DslImportWarning
 *
 * Portable DSL reference that could not be restored in the target workspace.
 */
export const zDslImportWarning = z.object({
  code: z.string(),
  details: z.record(z.string(), z.unknown()).optional(),
  message: z.string(),
  path: z.string(),
})

/**
 * Import
 */
export const zImport = z.object({
  app_id: z.string().nullish(),
  app_mode: z.string().nullish(),
  current_dsl_version: z.string().optional().default('0.7.0'),
  error: z.string().optional().default(''),
  id: z.string(),
  imported_dsl_version: z.string().optional().default(''),
  permission_keys: z.array(z.string()).optional(),
  status: zImportStatus,
  warnings: z.array(zDslImportWarning).optional(),
})

/**
 * AppImportResponse
 */
export const zAppImportResponse = z.object({
  app_id: z.string().nullish(),
  app_mode: z.string().nullish(),
  current_dsl_version: z.string(),
  error: z.string().optional().default(''),
  id: z.string(),
  imported_dsl_version: z.string().optional().default(''),
  status: zImportStatus,
  warnings: z.array(zDslImportWarning).optional(),
})

/**
 * RecentAppResponse
 */
export const zRecentAppResponse = z.object({
  author_name: z.string().nullish(),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: zIconType.nullish(),
  icon_url: z.string().nullable(),
  id: z.string(),
  maintainer: z.string().nullish(),
  mode: z.enum(['advanced-chat', 'agent-chat', 'chat', 'completion', 'workflow']),
  name: z.string(),
  permission_keys: z.array(z.string()).optional(),
  updated_at: z.int(),
})

/**
 * RecentAppListResponse
 */
export const zRecentAppListResponse = z.object({
  data: z.array(zRecentAppResponse),
})

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

/**
 * AgentConfigVersionResponse
 */
export const zAgentConfigVersionResponse = z.object({
  id: z.string(),
  kind: z.enum(['build_draft', 'draft', 'snapshot']),
  writable: z.boolean(),
})

/**
 * AgentConfigFileItemResponse
 */
export const zAgentConfigFileItemResponse = z.object({
  file_id: z.string().nullish(),
  hash: z.string().nullish(),
  id: z.string(),
  is_missing: z.boolean().optional().default(false),
  mime_type: z.string().nullish(),
  name: z.string(),
  size: z.int().nullish(),
})

/**
 * AgentConfigFileListResponse
 */
export const zAgentConfigFileListResponse = z.object({
  agent_id: z.string(),
  config_version: zAgentConfigVersionResponse,
  items: z.array(zAgentConfigFileItemResponse).optional(),
})

/**
 * AgentConfigFileUploadResponse
 */
export const zAgentConfigFileUploadResponse = z.object({
  config_version: zAgentConfigVersionResponse,
  file: zAgentConfigFileItemResponse,
})

/**
 * AgentConfigFileItemsResponse
 */
export const zAgentConfigFileItemsResponse = z.object({
  items: z.array(zAgentConfigFileItemResponse).optional(),
})

/**
 * AgentConfigSkillItemResponse
 */
export const zAgentConfigSkillItemResponse = z.object({
  description: z.string().optional().default(''),
  file_id: z.string().nullish(),
  hash: z.string().nullish(),
  id: z.string(),
  is_missing: z.boolean().optional().default(false),
  mime_type: z.string().nullish(),
  name: z.string(),
  size: z.int().nullish(),
})

/**
 * AgentConfigSkillListResponse
 */
export const zAgentConfigSkillListResponse = z.object({
  agent_id: z.string(),
  config_version: zAgentConfigVersionResponse,
  items: z.array(zAgentConfigSkillItemResponse).optional(),
})

/**
 * AgentConfigSkillUploadResponse
 */
export const zAgentConfigSkillUploadResponse = z.object({
  config_version: zAgentConfigVersionResponse,
  skill: zAgentConfigSkillItemResponse,
})

/**
 * AgentConfigSkillItemsResponse
 */
export const zAgentConfigSkillItemsResponse = z.object({
  items: z.array(zAgentConfigSkillItemResponse).optional(),
})

/**
 * AgentConfigManifestResponse
 */
export const zAgentConfigManifestResponse = z.object({
  agent_id: z.string(),
  config_version: zAgentConfigVersionResponse,
  env_keys: z.array(z.string()).optional(),
  files: zAgentConfigFileItemsResponse.optional(),
  note: z.string().optional().default(''),
  skills: zAgentConfigSkillItemsResponse.optional(),
})

/**
 * AgentConfigSkillFileResponse
 */
export const zAgentConfigSkillFileResponse = z.object({
  downloadable: z.boolean(),
  name: z.string(),
  path: z.string(),
  previewable: z.boolean(),
  type: z.enum(['directory', 'file']),
})

/**
 * AgentConfigSkillMarkdownResponse
 */
export const zAgentConfigSkillMarkdownResponse = z.object({
  binary: z.literal(false),
  path: z.literal('SKILL.md'),
  size: z.int().nullish(),
  text: z.string(),
  truncated: z.boolean(),
})

/**
 * AgentConfigSkillInspectResponse
 */
export const zAgentConfigSkillInspectResponse = z.object({
  description: z.string().optional().default(''),
  file_tree: z.array(z.record(z.string(), z.unknown())).nullish(),
  files: z.array(zAgentConfigSkillFileResponse).optional(),
  hash: z.string().nullish(),
  id: z.string(),
  mime_type: z.string().nullish(),
  name: z.string(),
  size: z.int().nullish(),
  skill_md: zAgentConfigSkillMarkdownResponse,
  source: z.literal('config_skill_zip'),
  warnings: z.array(z.string()).optional(),
})

/**
 * AgentDriveItemResponse
 */
export const zAgentDriveItemResponse = z.object({
  created_at: z.int().nullish(),
  file_kind: z.string(),
  hash: z.string().nullish(),
  is_skill: z.boolean().nullish(),
  key: z.string(),
  mime_type: z.string().nullish(),
  size: z.int().nullish(),
  skill_metadata: z.string().nullish(),
})

/**
 * AgentDriveListResponse
 */
export const zAgentDriveListResponse = z.object({
  items: z.array(zAgentDriveItemResponse).optional(),
})

/**
 * AgentDriveSkillItemResponse
 */
export const zAgentDriveSkillItemResponse = z.object({
  archive_key: z.string().nullish(),
  created_at: z.int().nullish(),
  description: z.string(),
  hash: z.string().nullish(),
  mime_type: z.string().nullish(),
  name: z.string(),
  path: z.string(),
  size: z.int().nullish(),
  skill_md_key: z.string(),
})

/**
 * AgentDriveSkillListResponse
 */
export const zAgentDriveSkillListResponse = z.object({
  items: z.array(zAgentDriveSkillItemResponse).optional(),
})

/**
 * AgentDriveSkillFileResponse
 */
export const zAgentDriveSkillFileResponse = z.object({
  available_in_drive: z.boolean(),
  drive_key: z.string().nullish(),
  name: z.string(),
  path: z.string(),
  type: z.string(),
})

/**
 * AgentDriveSkillMarkdownResponse
 */
export const zAgentDriveSkillMarkdownResponse = z.object({
  binary: z.boolean(),
  key: z.string(),
  size: z.int().nullish(),
  text: z.string().nullish(),
  truncated: z.boolean(),
})

/**
 * AgentDriveSkillInspectResponse
 */
export const zAgentDriveSkillInspectResponse = z.object({
  archive_key: z.string().nullish(),
  created_at: z.int().nullish(),
  description: z.string(),
  file_tree: z.array(z.record(z.string(), z.unknown())).optional(),
  files: z.array(zAgentDriveSkillFileResponse).optional(),
  hash: z.string().nullish(),
  mime_type: z.string().nullish(),
  name: z.string(),
  path: z.string(),
  size: z.int().nullish(),
  skill_md: zAgentDriveSkillMarkdownResponse,
  skill_md_key: z.string(),
  source: z.string(),
  warnings: z.array(z.string()).optional(),
})

/**
 * AgentDriveFileResponse
 */
export const zAgentDriveFileResponse = z.object({
  drive_key: z.string(),
  file_id: z.string(),
  mime_type: z.string().nullish(),
  name: z.string(),
  size: z.int().nullish(),
})

/**
 * AgentDriveFileCommitResponse
 */
export const zAgentDriveFileCommitResponse = z.object({
  file: zAgentDriveFileResponse,
})

/**
 * AgentLogMetaResponse
 */
export const zAgentLogMetaResponse = z.object({
  agent_mode: z.string(),
  elapsed_time: z.number().nullish(),
  executor: z.string(),
  iterations: z.int(),
  start_time: z.string(),
  status: z.string(),
  total_tokens: z.int(),
})

/**
 * SkillManifest
 *
 * Validated metadata extracted from a Skill package.
 */
export const zSkillManifest = z.object({
  description: z.string(),
  entry_path: z.string(),
  files: z.array(z.string()),
  hash: z.string(),
  name: z.string(),
  size: z.int(),
})

/**
 * AgentUploadedSkillResponse
 */
export const zAgentUploadedSkillResponse = z.object({
  archive_key: z.string().nullish(),
  description: z.string(),
  name: z.string(),
  path: z.string(),
  skill_md_key: z.string(),
})

/**
 * AgentSkillUploadResponse
 */
export const zAgentSkillUploadResponse = z.object({
  manifest: zSkillManifest,
  skill: zAgentUploadedSkillResponse,
})

/**
 * AnnotationSettingEmbeddingModelResponse
 */
export const zAnnotationSettingEmbeddingModelResponse = z.object({
  embedding_model_name: z.string().nullish(),
  embedding_provider_name: z.string().nullish(),
})

/**
 * AnnotationSettingResponse
 */
export const zAnnotationSettingResponse = z.object({
  embedding_model: zAnnotationSettingEmbeddingModelResponse.nullish(),
  enabled: z.boolean(),
  id: z.string().nullish(),
  score_threshold: z.number().nullish(),
})

/**
 * AnnotationHitHistory
 */
export const zAnnotationHitHistory = z.object({
  created_at: z.int().nullish(),
  id: z.string(),
  match: z.string().nullish(),
  question: z.string().nullish(),
  response: z.string().nullish(),
  score: z.number().nullish(),
  source: z.string().nullish(),
})

/**
 * AnnotationHitHistoryList
 */
export const zAnnotationHitHistoryList = z.object({
  data: z.array(zAnnotationHitHistory),
  has_more: z.boolean(),
  limit: z.int(),
  page: z.int(),
  total: z.int(),
})

/**
 * FeedbackStat
 */
export const zFeedbackStat = z.object({
  dislike: z.int(),
  like: z.int(),
})

/**
 * ConversationVariableResponse
 */
export const zConversationVariableResponse = z.object({
  created_at: z.int().nullish(),
  description: z.string().nullish(),
  id: z.string(),
  name: z.string(),
  updated_at: z.int().nullish(),
  value: z.string().nullish(),
  value_type: z.string(),
})

/**
 * PaginatedConversationVariableResponse
 */
export const zPaginatedConversationVariableResponse = z.object({
  data: z.array(zConversationVariableResponse),
  has_more: z.boolean(),
  limit: z.int(),
  page: z.int(),
  total: z.int(),
})

/**
 * AgentThought
 */
export const zAgentThought = z.object({
  answer: z.string().nullish(),
  chain_id: z.string().nullish(),
  created_at: z.int().nullish(),
  files: z.array(z.string()),
  id: z.string(),
  message_id: z.string(),
  observation: z.string().nullish(),
  position: z.int(),
  thought: z.string().nullish(),
  tool: z.string().nullish(),
  tool_input: z.string().nullish(),
  tool_labels: zJsonValue,
})

/**
 * MessageFile
 */
export const zMessageFile = z.object({
  belongs_to: z.string().nullish(),
  filename: z.string(),
  id: z.string(),
  mime_type: z.string().nullish(),
  size: z.int().nullish(),
  transfer_method: z.string(),
  type: z.string(),
  upload_file_id: z.string().nullish(),
  url: z.string().nullish(),
})

/**
 * AppMCPServerStatus
 *
 * AppMCPServer Status Enum
 */
export const zAppMcpServerStatus = z.enum(['active', 'inactive', 'normal'])

/**
 * AppMCPServerResponse
 */
export const zAppMcpServerResponse = z.object({
  created_at: z.int().nullish(),
  description: z.string(),
  id: z.string(),
  name: z.string(),
  parameters: z.union([z.record(z.string(), z.unknown()), z.array(z.unknown()), z.string()]),
  server_code: z.string(),
  status: zAppMcpServerStatus,
  updated_at: z.int().nullish(),
})

/**
 * AverageResponseTimeStatisticItem
 */
export const zAverageResponseTimeStatisticItem = z.object({
  date: z.string(),
  latency: z.number(),
})

/**
 * AverageResponseTimeStatisticResponse
 */
export const zAverageResponseTimeStatisticResponse = z.object({
  data: z.array(zAverageResponseTimeStatisticItem),
})

/**
 * AverageSessionInteractionStatisticItem
 */
export const zAverageSessionInteractionStatisticItem = z.object({
  date: z.string(),
  interactions: z.number(),
})

/**
 * AverageSessionInteractionStatisticResponse
 */
export const zAverageSessionInteractionStatisticResponse = z.object({
  data: z.array(zAverageSessionInteractionStatisticItem),
})

/**
 * DailyConversationStatisticItem
 */
export const zDailyConversationStatisticItem = z.object({
  conversation_count: z.int(),
  date: z.string(),
})

/**
 * DailyConversationStatisticResponse
 */
export const zDailyConversationStatisticResponse = z.object({
  data: z.array(zDailyConversationStatisticItem),
})

/**
 * DailyTerminalStatisticItem
 */
export const zDailyTerminalStatisticItem = z.object({
  date: z.string(),
  terminal_count: z.int(),
})

/**
 * DailyTerminalStatisticResponse
 */
export const zDailyTerminalStatisticResponse = z.object({
  data: z.array(zDailyTerminalStatisticItem),
})

/**
 * DailyMessageStatisticItem
 */
export const zDailyMessageStatisticItem = z.object({
  date: z.string(),
  message_count: z.int(),
})

/**
 * DailyMessageStatisticResponse
 */
export const zDailyMessageStatisticResponse = z.object({
  data: z.array(zDailyMessageStatisticItem),
})

/**
 * DailyTokenCostStatisticItem
 */
export const zDailyTokenCostStatisticItem = z.object({
  currency: z.string().nullish(),
  date: z.string(),
  token_count: z.int().nullish(),
  total_price: z
    .string()
    .regex(/^(?![-+.]*$)[+-]?0*\d*\.?\d*$/)
    .nullish(),
})

/**
 * DailyTokenCostStatisticResponse
 */
export const zDailyTokenCostStatisticResponse = z.object({
  data: z.array(zDailyTokenCostStatisticItem),
})

/**
 * TokensPerSecondStatisticItem
 */
export const zTokensPerSecondStatisticItem = z.object({
  date: z.string(),
  tps: z.number(),
})

/**
 * TokensPerSecondStatisticResponse
 */
export const zTokensPerSecondStatisticResponse = z.object({
  data: z.array(zTokensPerSecondStatisticItem),
})

/**
 * UserSatisfactionRateStatisticItem
 */
export const zUserSatisfactionRateStatisticItem = z.object({
  date: z.string(),
  rate: z.number(),
})

/**
 * UserSatisfactionRateStatisticResponse
 */
export const zUserSatisfactionRateStatisticResponse = z.object({
  data: z.array(zUserSatisfactionRateStatisticItem),
})

/**
 * TextToSpeechVoiceResponse
 */
export const zTextToSpeechVoiceResponse = z.object({
  name: z.string(),
  value: z.string(),
})

/**
 * TextToSpeechVoiceListResponse
 *
 * Available voices
 */
export const zTextToSpeechVoiceListResponse = z.array(zTextToSpeechVoiceResponse)

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

/**
 * AdvancedChatWorkflowRunForListResponse
 */
export const zAdvancedChatWorkflowRunForListResponse = z.object({
  conversation_id: z.string().nullish(),
  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(),
  message_id: z.string().nullish(),
  retry_index: z.int().nullish(),
  status: z.string().nullish(),
  total_steps: z.int().nullish(),
  total_tokens: z.int().nullish(),
  version: z.string().nullish(),
})

/**
 * AdvancedChatWorkflowRunPaginationResponse
 */
export const zAdvancedChatWorkflowRunPaginationResponse = z.object({
  data: z.array(zAdvancedChatWorkflowRunForListResponse),
  has_more: z.boolean(),
  limit: z.int(),
})

/**
 * 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),
})

/**
 * SandboxFileEntryResponse
 */
export const zSandboxFileEntryResponse = z.object({
  mtime: z.int().nullish(),
  name: z.string(),
  size: z.int().nullish(),
  type: z.enum(['dir', 'file', 'other', 'symlink']),
})

/**
 * SandboxListResponse
 */
export const zSandboxListResponse = z.object({
  entries: z.array(zSandboxFileEntryResponse).optional(),
  path: z.string(),
  truncated: z.boolean().optional().default(false),
})

/**
 * AccountWithRoleResponse
 */
export const zAccountWithRoleResponse = z.object({
  avatar: z.string().nullish(),
  avatar_url: z.string().nullable(),
  created_at: z.int().nullish(),
  email: z.string(),
  id: z.string(),
  last_active_at: z.int().nullish(),
  last_login_at: z.int().nullish(),
  name: z.string(),
  role: z.string(),
  roles: z.array(z.record(z.string(), z.string())).optional(),
  status: z.string(),
})

/**
 * WorkflowCommentMentionUsersPayload
 */
export const zWorkflowCommentMentionUsersPayload = z.object({
  users: z.array(zAccountWithRoleResponse),
})

/**
 * WorkflowCommentAccount
 */
export const zWorkflowCommentAccount = z.object({
  avatar_url: z.string().nullable(),
  email: z.string(),
  id: z.string(),
  name: z.string(),
})

/**
 * WorkflowCommentBasic
 */
export const zWorkflowCommentBasic = z.object({
  content: z.string(),
  created_at: z.int().nullish(),
  created_by: z.string(),
  created_by_account: zWorkflowCommentAccount.nullish(),
  id: z.string(),
  mention_count: z.int(),
  participants: z.array(zWorkflowCommentAccount),
  position_x: z.number(),
  position_y: z.number(),
  reply_count: z.int(),
  resolved: z.boolean(),
  resolved_at: z.int().nullish(),
  resolved_by: z.string().nullish(),
  resolved_by_account: zWorkflowCommentAccount.nullish(),
  updated_at: z.int().nullish(),
})

/**
 * WorkflowCommentBasicList
 */
export const zWorkflowCommentBasicList = z.object({
  data: z.array(zWorkflowCommentBasic),
})

/**
 * WorkflowCommentMention
 */
export const zWorkflowCommentMention = z.object({
  mentioned_user_account: zWorkflowCommentAccount.nullish(),
  mentioned_user_id: z.string(),
  reply_id: z.string().nullish(),
})

/**
 * WorkflowCommentReply
 */
export const zWorkflowCommentReply = z.object({
  content: z.string(),
  created_at: z.int().nullish(),
  created_by: z.string(),
  created_by_account: zWorkflowCommentAccount.nullish(),
  id: z.string(),
})

/**
 * WorkflowCommentDetail
 */
export const zWorkflowCommentDetail = z.object({
  content: z.string(),
  created_at: z.int().nullish(),
  created_by: z.string(),
  created_by_account: zWorkflowCommentAccount.nullish(),
  id: z.string(),
  mentions: z.array(zWorkflowCommentMention),
  position_x: z.number(),
  position_y: z.number(),
  replies: z.array(zWorkflowCommentReply),
  resolved: z.boolean(),
  resolved_at: z.int().nullish(),
  resolved_by: z.string().nullish(),
  resolved_by_account: zWorkflowCommentAccount.nullish(),
  updated_at: z.int().nullish(),
})

/**
 * WorkflowAverageAppInteractionStatisticItem
 */
export const zWorkflowAverageAppInteractionStatisticItem = z.object({
  date: z.string(),
  interactions: z.number(),
})

/**
 * WorkflowAverageAppInteractionStatisticResponse
 */
export const zWorkflowAverageAppInteractionStatisticResponse = z.object({
  data: z.array(zWorkflowAverageAppInteractionStatisticItem),
})

/**
 * WorkflowDailyRunsStatisticItem
 */
export const zWorkflowDailyRunsStatisticItem = z.object({
  date: z.string(),
  runs: z.int(),
})

/**
 * WorkflowDailyRunsStatisticResponse
 */
export const zWorkflowDailyRunsStatisticResponse = z.object({
  data: z.array(zWorkflowDailyRunsStatisticItem),
})

/**
 * WorkflowDailyTerminalsStatisticItem
 */
export const zWorkflowDailyTerminalsStatisticItem = z.object({
  date: z.string(),
  terminal_count: z.int(),
})

/**
 * WorkflowDailyTerminalsStatisticResponse
 */
export const zWorkflowDailyTerminalsStatisticResponse = z.object({
  data: z.array(zWorkflowDailyTerminalsStatisticItem),
})

/**
 * WorkflowDailyTokenCostStatisticItem
 */
export const zWorkflowDailyTokenCostStatisticItem = z.object({
  date: z.string(),
  token_count: z.int(),
})

/**
 * WorkflowDailyTokenCostStatisticResponse
 */
export const zWorkflowDailyTokenCostStatisticResponse = z.object({
  data: z.array(zWorkflowDailyTokenCostStatisticItem),
})

/**
 * 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(),
})

/**
 * WorkflowResponse
 */
export const zWorkflowResponse = 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(),
  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(),
})

/**
 * WorkflowPaginationResponse
 */
export const zWorkflowPaginationResponse = z.object({
  has_more: z.boolean(),
  items: z.array(zWorkflowResponse),
  limit: z.int(),
  page: z.int(),
})

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

/**
 * ConversationVariableUpdatePayload
 */
export const zConversationVariableUpdatePayload = z.object({
  conversation_variables: z.array(zConversationVariableItemPayload),
})

/**
 * 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),
})

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

/**
 * EnvironmentVariableUpdatePayload
 */
export const zEnvironmentVariableUpdatePayload = z.object({
  environment_variables: z.array(zEnvironmentVariableItemPayload),
})

/**
 * 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(),
})

/**
 * WorkflowExecutionStatus
 */
export const zWorkflowExecutionStatus = z.enum([
  'failed',
  'partial-succeeded',
  'paused',
  'running',
  'scheduled',
  'stopped',
  'succeeded',
])

/**
 * NodeStatus
 *
 * Coarse node-level status used by Inspector to pick a banner.
 */
export const zNodeStatus = z.enum(['failed', 'idle', 'ready', 'running'])

/**
 * NodeOutputStatus
 *
 * Lifecycle status of a single declared output within a run.
 */
export const zNodeOutputStatus = z.enum([
  'failed',
  'not_produced',
  'output_check_failed',
  'pending',
  'ready',
  'running',
  'type_check_failed',
])

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

/**
 * OutputPreviewView
 */
export const zOutputPreviewView = z.object({
  node_id: z.string(),
  output_name: z.string(),
  status: zNodeOutputStatus,
  type: zDeclaredOutputType.nullish(),
  value: z.unknown().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(),
})

/**
 * ModelConfigPartial
 */
export const zModelConfigPartial = z.object({
  created_at: z.int().nullish(),
  created_by: z.string().nullish(),
  model: z.unknown().nullish(),
  pre_prompt: z.string().nullish(),
  updated_at: z.int().nullish(),
  updated_by: z.string().nullish(),
})

/**
 * AppPartial
 */
export const zAppPartial = z.object({
  access_mode: z.string().nullish(),
  app_id: z.string().nullish(),
  author_name: z.string().nullish(),
  bound_agent_id: z.string().nullish(),
  create_user_name: z.string().nullish(),
  created_at: z.int().nullish(),
  created_by: z.string().nullish(),
  description: z.string().nullish(),
  has_draft_trigger: z.boolean().nullish(),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: z.string().nullish(),
  icon_url: z.string().nullable(),
  id: z.string(),
  is_starred: z.boolean().optional().default(false),
  maintainer: z.string().nullish(),
  max_active_requests: z.int().nullish(),
  mode: z.string(),
  model_config: zModelConfigPartial.nullish(),
  name: z.string(),
  permission_keys: z.array(z.string()).optional(),
  tags: z.array(zTag).optional(),
  updated_at: z.int().nullish(),
  updated_by: z.string().nullish(),
  use_icon_as_answer_icon: z.boolean().nullish(),
  workflow: zWorkflowPartial.nullish(),
})

/**
 * AppPagination
 */
export const zAppPagination = z.object({
  data: z.array(zAppPartial),
  has_more: z.boolean(),
  limit: z.int(),
  page: z.int(),
  total: z.int(),
})

/**
 * PluginDependencyType
 */
export const zPluginDependencyType = z.enum(['github', 'marketplace', 'package'])

/**
 * Github
 */
export const zGithub = z.object({
  github_plugin_unique_identifier: z.string(),
  package: z.string(),
  repo: z.string(),
  version: z.string(),
})

/**
 * Marketplace
 */
export const zMarketplace = z.object({
  marketplace_plugin_unique_identifier: z.string(),
  version: z.string().nullish(),
})

/**
 * Package
 */
export const zPackage = z.object({
  plugin_unique_identifier: z.string(),
  version: z.string().nullish(),
})

/**
 * PluginDependency
 */
export const zPluginDependency = z.object({
  current_identifier: z.string().nullish(),
  type: zPluginDependencyType,
  value: z.union([zGithub, zMarketplace, zPackage]),
})

/**
 * CheckDependenciesResult
 */
export const zCheckDependenciesResult = z.object({
  leaked_dependencies: z.array(zPluginDependency).optional(),
})

/**
 * WorkflowOnlineUser
 */
export const zWorkflowOnlineUser = z.object({
  avatar: z.string().nullish(),
  user_id: z.string(),
  username: z.string(),
})

/**
 * WorkflowOnlineUsersByApp
 */
export const zWorkflowOnlineUsersByApp = z.object({
  app_id: z.string(),
  users: z.array(zWorkflowOnlineUser),
})

/**
 * WorkflowOnlineUsersResponse
 */
export const zWorkflowOnlineUsersResponse = z.object({
  data: z.array(zWorkflowOnlineUsersByApp),
})

/**
 * AgentToolCallResponse
 */
export const zAgentToolCallResponse = z.object({
  error: z.string().nullish(),
  status: z.string(),
  time_cost: z.union([z.number(), z.int()]),
  tool_icon: z.unknown().optional(),
  tool_input: z.record(z.string(), z.unknown()),
  tool_label: z.string(),
  tool_name: z.string(),
  tool_output: z.record(z.string(), z.unknown()),
  tool_parameters: z.record(z.string(), z.unknown()),
})

/**
 * AgentIterationLogResponse
 */
export const zAgentIterationLogResponse = z.object({
  created_at: z.string(),
  files: z.array(z.unknown()).optional(),
  thought: z.string().nullish(),
  tokens: z.int(),
  tool_calls: z.array(zAgentToolCallResponse),
  tool_raw: z.record(z.string(), z.unknown()),
})

/**
 * AgentLogResponse
 */
export const zAgentLogResponse = z.object({
  files: z.array(z.unknown()).optional(),
  iterations: z.array(zAgentIterationLogResponse),
  meta: zAgentLogMetaResponse,
})

/**
 * EnvSuggestion
 */
export const zEnvSuggestion = z.object({
  key: z.string(),
  reason: z.string().optional().default(''),
  secret_likely: z.boolean().optional().default(false),
})

/**
 * CliToolSuggestion
 */
export const zCliToolSuggestion = z.object({
  command: z.string().optional().default(''),
  description: z.string().optional().default(''),
  env_suggestions: z.array(zEnvSuggestion).optional(),
  inferred_from: z.string().optional().default(''),
  install_commands: z.array(z.string()).optional(),
  name: z.string(),
})

/**
 * SkillToolInferenceResult
 */
export const zSkillToolInferenceResult = z.object({
  cli_tools: z.array(zCliToolSuggestion).optional(),
  inferable: z.boolean(),
  reason: z.string().nullish(),
})

/**
 * SimpleModelConfig
 */
export const zSimpleModelConfig = z.object({
  model: zJsonValue.nullish(),
  pre_prompt: z.string().nullish(),
})

/**
 * StatusCount
 */
export const zStatusCount = z.object({
  failed: z.int(),
  partial_success: z.int(),
  paused: z.int(),
  success: z.int(),
})

/**
 * ConversationWithSummary
 */
export const zConversationWithSummary = z.object({
  admin_feedback_stats: zFeedbackStat.nullish(),
  annotated: z.boolean(),
  created_at: z.int().nullish(),
  from_account_id: z.string().nullish(),
  from_account_name: z.string().nullish(),
  from_end_user_id: z.string().nullish(),
  from_end_user_session_id: z.string().nullish(),
  from_source: z.string(),
  id: z.string(),
  message_count: z.int(),
  model_config: zSimpleModelConfig.nullish(),
  name: z.string(),
  read_at: z.int().nullish(),
  status: z.string(),
  status_count: zStatusCount.nullish(),
  summary: z.string(),
  updated_at: z.int().nullish(),
  user_feedback_stats: zFeedbackStat.nullish(),
})

/**
 * ConversationWithSummaryPagination
 */
export const zConversationWithSummaryPagination = z.object({
  data: z.array(zConversationWithSummary),
  has_more: z.boolean(),
  limit: z.int(),
  page: z.int(),
  total: z.int(),
})

/**
 * LLMMode
 *
 * Enum class for large language model mode.
 */
export const zLlmMode = z.enum(['chat', 'completion'])

/**
 * ModelConfig
 */
export const zModelConfig = z.object({
  completion_params: z.record(z.string(), z.unknown()).optional(),
  mode: zLlmMode,
  name: z.string(),
  provider: z.string(),
})

/**
 * ConversationDetail
 */
export const zConversationDetail = z.object({
  admin_feedback_stats: zFeedbackStat.nullish(),
  annotated: z.boolean(),
  created_at: z.int().nullish(),
  from_account_id: z.string().nullish(),
  from_end_user_id: z.string().nullish(),
  from_source: z.string(),
  id: z.string(),
  introduction: z.string().nullish(),
  message_count: z.int(),
  model_config: zModelConfig.nullish(),
  status: z.string(),
  updated_at: z.int().nullish(),
  user_feedback_stats: zFeedbackStat.nullish(),
})

/**
 * SimpleMessageDetail
 */
export const zSimpleMessageDetail = z.object({
  answer: z.string(),
  inputs: z.record(z.string(), zJsonValue),
  message: z.string(),
  query: z.string(),
})

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

/**
 * ConversationAnnotation
 */
export const zConversationAnnotation = z.object({
  account: zSimpleAccount.nullish(),
  content: z.string(),
  created_at: z.int().nullish(),
  id: z.string(),
  question: z.string().nullish(),
})

/**
 * Conversation
 */
export const zConversation = z.object({
  admin_feedback_stats: zFeedbackStat.nullish(),
  annotation: zConversationAnnotation.nullish(),
  created_at: z.int().nullish(),
  from_account_id: z.string().nullish(),
  from_account_name: z.string().nullish(),
  from_end_user_id: z.string().nullish(),
  from_end_user_session_id: z.string().nullish(),
  from_source: z.string(),
  id: z.string(),
  message: zSimpleMessageDetail.nullish(),
  model_config: zSimpleModelConfig.nullish(),
  read_at: z.int().nullish(),
  status: z.string(),
  updated_at: z.int().nullish(),
  user_feedback_stats: zFeedbackStat.nullish(),
})

/**
 * ConversationPagination
 */
export const zConversationPagination = z.object({
  data: z.array(zConversation),
  has_more: z.boolean(),
  limit: z.int(),
  page: z.int(),
  total: z.int(),
})

/**
 * ConversationAnnotationHitHistory
 */
export const zConversationAnnotationHitHistory = z.object({
  annotation_create_account: zSimpleAccount.nullish(),
  annotation_id: z.string(),
  created_at: z.int().nullish(),
})

/**
 * Feedback
 */
export const zFeedback = z.object({
  content: z.string().nullish(),
  from_account: zSimpleAccount.nullish(),
  from_end_user_id: z.string().nullish(),
  from_source: z.string(),
  rating: z.string(),
})

/**
 * MessageDetail
 */
export const zMessageDetail = z.object({
  agent_thoughts: z.array(zAgentThought),
  annotation: zConversationAnnotation.nullish(),
  annotation_hit_history: zConversationAnnotationHitHistory.nullish(),
  answer: z.string(),
  answer_tokens: z.int(),
  conversation_id: z.string(),
  created_at: z.int().nullish(),
  error: z.string().nullish(),
  feedbacks: z.array(zFeedback),
  from_account_id: z.string().nullish(),
  from_end_user_id: z.string().nullish(),
  from_source: z.string(),
  id: z.string(),
  inputs: z.record(z.string(), zJsonValue),
  message: zJsonValue,
  message_files: z.array(zMessageFile),
  message_tokens: z.int(),
  metadata: zJsonValue,
  parent_message_id: z.string().nullish(),
  provider_response_latency: z.number(),
  query: z.string(),
  status: z.string(),
  workflow_run_id: z.string().nullish(),
})

/**
 * ConversationMessageDetail
 */
export const zConversationMessageDetail = z.object({
  created_at: z.int().nullish(),
  from_account_id: z.string().nullish(),
  from_end_user_id: z.string().nullish(),
  from_source: z.string(),
  id: z.string(),
  message: zMessageDetail.nullish(),
  model_config: zModelConfig.nullish(),
  status: z.string(),
})

/**
 * ExecutionContentType
 */
export const zExecutionContentType = z.enum(['human_input'])

/**
 * WorkflowRunForLogResponse
 */
export const zWorkflowRunForLogResponse = z.object({
  created_at: z.int().nullish(),
  elapsed_time: z.number().nullish(),
  error: z.string().nullish(),
  exceptions_count: z.int().nullish(),
  finished_at: z.int().nullish(),
  id: z.string(),
  status: z.string().nullish(),
  total_steps: z.int().nullish(),
  total_tokens: z.int().nullish(),
  triggered_from: z.string().nullish(),
  version: z.string().nullish(),
})

/**
 * WorkflowAppLogPartialResponse
 */
export const zWorkflowAppLogPartialResponse = z.object({
  created_at: z.int().nullish(),
  created_by_account: zSimpleAccountResponse.nullish(),
  created_by_end_user: zSimpleEndUser.nullish(),
  created_by_role: z.string().nullish(),
  created_from: z.string().nullish(),
  details: z.unknown().optional(),
  id: z.string(),
  workflow_run: zWorkflowRunForLogResponse.nullish(),
})

/**
 * WorkflowAppLogPaginationResponse
 */
export const zWorkflowAppLogPaginationResponse = z.object({
  data: z.array(zWorkflowAppLogPartialResponse),
  has_more: z.boolean(),
  limit: z.int(),
  page: z.int(),
  total: z.int(),
})

/**
 * WorkflowRunForArchivedLogResponse
 */
export const zWorkflowRunForArchivedLogResponse = z.object({
  elapsed_time: z.number().nullish(),
  id: z.string(),
  status: z.string().nullish(),
  total_tokens: z.int().nullish(),
  triggered_from: z.string().nullish(),
})

/**
 * WorkflowArchivedLogPartialResponse
 */
export const zWorkflowArchivedLogPartialResponse = z.object({
  created_at: z.int().nullish(),
  created_by_account: zSimpleAccountResponse.nullish(),
  created_by_end_user: zSimpleEndUser.nullish(),
  id: z.string(),
  trigger_metadata: z.unknown().optional(),
  workflow_run: zWorkflowRunForArchivedLogResponse.nullish(),
})

/**
 * WorkflowArchivedLogPaginationResponse
 */
export const zWorkflowArchivedLogPaginationResponse = z.object({
  data: z.array(zWorkflowArchivedLogPartialResponse),
  has_more: z.boolean(),
  limit: z.int(),
  page: z.int(),
  total: z.int(),
})

/**
 * WorkflowFeatureTogglePayload
 */
export const zWorkflowFeatureTogglePayload = z.object({
  enabled: z.boolean().nullish(),
})

/**
 * WorkflowSensitiveWordAvoidancePayload
 */
export const zWorkflowSensitiveWordAvoidancePayload = z.object({
  config: z.record(z.string(), z.unknown()).nullish(),
  enabled: z.boolean().nullish(),
  type: z.string().nullish(),
})

/**
 * WorkflowSuggestedQuestionsAfterAnswerPayload
 */
export const zWorkflowSuggestedQuestionsAfterAnswerPayload = z.object({
  enabled: z.boolean().nullish(),
  model: z.record(z.string(), z.unknown()).nullish(),
  prompt: z.string().nullish(),
})

/**
 * WorkflowTextToSpeechPayload
 */
export const zWorkflowTextToSpeechPayload = z.object({
  autoPlay: z.string().nullish(),
  enabled: z.boolean().nullish(),
  language: z.string().nullish(),
  voice: z.string().nullish(),
})

/**
 * 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(),
})

/**
 * 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,
})

/**
 * 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(),
})

/**
 * 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(),
})

/**
 * CheckResultView
 *
 * ``type_check`` / ``output_check`` per-output summary block.
 */
export const zCheckResultView = z.object({
  passed: z.boolean(),
  reason: z.string().nullish(),
})

/**
 * NodeOutputView
 */
export const zNodeOutputView = z.object({
  name: z.string(),
  output_check: zCheckResultView.nullish(),
  retried: z.int().optional().default(0),
  status: zNodeOutputStatus,
  type: zDeclaredOutputType.nullish(),
  type_check: zCheckResultView.nullish(),
  value_preview: z.unknown().optional(),
})

/**
 * NodeOutputsView
 */
export const zNodeOutputsView = z.object({
  node_completed_at: z.iso.datetime().nullish(),
  node_display_name: z.string(),
  node_id: z.string(),
  node_kind: z.string(),
  node_started_at: z.iso.datetime().nullish(),
  node_status: zNodeStatus,
  outputs: z.array(zNodeOutputView).optional(),
})

/**
 * WorkflowRunSnapshotView
 */
export const zWorkflowRunSnapshotView = z.object({
  node_outputs: z.array(zNodeOutputsView).optional(),
  workflow_run_id: z.string(),
  workflow_run_status: zWorkflowExecutionStatus,
})

export const zJsonValue2 = z.unknown()

/**
 * HumanInputFormSubmissionData
 */
export const zHumanInputFormSubmissionData = z.object({
  action_id: z.string(),
  action_text: z.string(),
  node_id: z.string(),
  node_title: z.string(),
  rendered_content: z.string(),
  submitted_data: z.record(z.string(), zJsonValue2).nullish(),
})

/**
 * WorkflowFileUploadTransferPayload
 */
export const zWorkflowFileUploadTransferPayload = z.object({
  enabled: z.boolean().nullish(),
  number_limits: z.int().nullish(),
  transfer_methods: z.array(z.string()).nullish(),
})

/**
 * WorkflowFileUploadImagePayload
 */
export const zWorkflowFileUploadImagePayload = z.object({
  detail: z.string().nullish(),
  enabled: z.boolean().nullish(),
  number_limits: z.int().nullish(),
  transfer_methods: z.array(z.string()).nullish(),
})

/**
 * WorkflowFileUploadPreviewConfigPayload
 */
export const zWorkflowFileUploadPreviewConfigPayload = z.object({
  file_type_list: z.array(z.string()).nullish(),
  mode: z.string().nullish(),
})

/**
 * WorkflowFileUploadPayload
 */
export const zWorkflowFileUploadPayload = 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(),
  audio: zWorkflowFileUploadTransferPayload.nullish(),
  custom: zWorkflowFileUploadTransferPayload.nullish(),
  document: zWorkflowFileUploadTransferPayload.nullish(),
  enabled: z.boolean().nullish(),
  fileUploadConfig: z.record(z.string(), z.unknown()).nullish(),
  image: zWorkflowFileUploadImagePayload.nullish(),
  number_limits: z.int().nullish(),
  preview_config: zWorkflowFileUploadPreviewConfigPayload.nullish(),
  video: zWorkflowFileUploadTransferPayload.nullish(),
})

/**
 * WorkflowFeaturesConfigPayload
 */
export const zWorkflowFeaturesConfigPayload = z.object({
  file_upload: zWorkflowFileUploadPayload.nullish(),
  opening_statement: z.string().nullish(),
  retriever_resource: zWorkflowFeatureTogglePayload.nullish(),
  sensitive_word_avoidance: zWorkflowSensitiveWordAvoidancePayload.nullish(),
  speech_to_text: zWorkflowFeatureTogglePayload.nullish(),
  suggested_questions: z.array(z.string()).nullish(),
  suggested_questions_after_answer: zWorkflowSuggestedQuestionsAfterAnswerPayload.nullish(),
  text_to_speech: zWorkflowTextToSpeechPayload.nullish(),
})

/**
 * WorkflowFeaturesPayload
 */
export const zWorkflowFeaturesPayload = z.object({
  features: zWorkflowFeaturesConfigPayload,
})

/**
 * 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,
})

/**
 * ButtonStyle
 *
 * Button styles for user actions.
 */
export const zButtonStyle = z.enum(['accent', 'default', 'ghost', 'primary'])

/**
 * UserActionConfig
 *
 * User action configuration.
 */
export const zUserActionConfig = z.object({
  button_style: zButtonStyle.optional().default('default'),
  id: z.string().max(20),
  title: z.string().max(100),
})

/**
 * 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',
])

/**
 * FileInputConfig
 */
export const zFileInputConfig = 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(),
  output_variable_name: z.string(),
  type: z.literal('file').optional().default('file'),
})

/**
 * FileListInputConfig
 */
export const zFileListInputConfig = 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(),
  number_limits: z.int().gte(0).optional().default(0),
  output_variable_name: z.string(),
  type: z.literal('file-list').optional().default('file-list'),
})

/**
 * 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(),
})

/**
 * ValueSourceType
 *
 * ValueSourceType records whether the value comes from a static setting
 * in form definition, or a variable while the workflow is running.
 */
export const zValueSourceType = z.enum(['constant', 'variable'])

/**
 * StringSource
 *
 * Default configuration for form inputs.
 */
export const zStringSource = z.object({
  selector: z.array(z.string()).optional(),
  type: zValueSourceType,
  value: z.string().optional().default(''),
})

/**
 * ParagraphInputConfig
 *
 * Form input definition.
 */
export const zParagraphInputConfig = z.object({
  default: zStringSource.nullish(),
  output_variable_name: z.string(),
  type: z.literal('paragraph').optional().default('paragraph'),
})

/**
 * StringListSource
 */
export const zStringListSource = z.object({
  selector: z.array(z.string()).optional(),
  type: zValueSourceType,
  value: z.array(z.string()).optional(),
})

/**
 * SelectInputConfig
 */
export const zSelectInputConfig = z.object({
  option_source: zStringListSource,
  output_variable_name: z.string(),
  type: z.literal('select').optional().default('select'),
})

export const zFormInputConfig = z.discriminatedUnion('type', [
  zParagraphInputConfig.extend({ type: z.literal('paragraph') }),
  zSelectInputConfig.extend({ type: z.literal('select') }),
  zFileInputConfig.extend({ type: z.literal('file') }),
  zFileListInputConfig.extend({ type: z.literal('file-list') }),
])

/**
 * HumanInputFormDefinition
 */
export const zHumanInputFormDefinition = z.object({
  actions: z.array(zUserActionConfig).optional(),
  display_in_ui: z.boolean().optional().default(false),
  expiration_time: z.int(),
  form_content: z.string(),
  form_id: z.string(),
  form_token: z.string().nullish(),
  inputs: z.array(zFormInputConfig).optional(),
  node_id: z.string(),
  node_title: z.string(),
  resolved_default_values: z.record(z.string(), z.unknown()).optional(),
})

/**
 * HumanInputContent
 */
export const zHumanInputContent = z.object({
  form_definition: zHumanInputFormDefinition.nullish(),
  form_submission_data: zHumanInputFormSubmissionData.nullish(),
  submitted: z.boolean(),
  type: zExecutionContentType.optional().default('human_input'),
  workflow_run_id: z.string(),
})

/**
 * MessageDetailResponse
 */
export const zMessageDetailResponse = z.object({
  agent_thoughts: z.array(zAgentThought),
  annotation: zConversationAnnotation.nullish(),
  annotation_hit_history: zConversationAnnotationHitHistory.nullish(),
  answer: z.string(),
  answer_tokens: z.int(),
  conversation_id: z.string(),
  created_at: z.int().nullish(),
  error: z.string().nullish(),
  extra_contents: z.array(zHumanInputContent).optional(),
  feedbacks: z.array(zFeedback),
  from_account_id: z.string().nullish(),
  from_end_user_id: z.string().nullish(),
  from_source: z.string(),
  id: z.string(),
  inputs: z.record(z.string(), zJsonValue),
  message: zJsonValue,
  message_files: z.array(zMessageFile),
  message_tokens: z.int(),
  metadata: zJsonValue,
  parent_message_id: z.string().nullish(),
  provider_response_latency: z.number(),
  query: z.string(),
  status: z.string(),
  workflow_run_id: z.string().nullish(),
})

/**
 * MessageInfiniteScrollPaginationResponse
 */
export const zMessageInfiniteScrollPaginationResponse = z.object({
  data: z.array(zMessageDetailResponse),
  has_more: z.boolean(),
  limit: z.int(),
})

/**
 * 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(),
})

/**
 * GeneratedAppResponse
 */
export const zGeneratedAppResponseWritable = zJsonValue

/**
 * AppPartial
 */
export const zAppPartialWritable = z.object({
  access_mode: z.string().nullish(),
  app_id: z.string().nullish(),
  author_name: z.string().nullish(),
  bound_agent_id: z.string().nullish(),
  create_user_name: z.string().nullish(),
  created_at: z.int().nullish(),
  created_by: z.string().nullish(),
  description: z.string().nullish(),
  has_draft_trigger: z.boolean().nullish(),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: z.string().nullish(),
  id: z.string(),
  is_starred: z.boolean().optional().default(false),
  maintainer: z.string().nullish(),
  max_active_requests: z.int().nullish(),
  mode: z.string(),
  model_config: zModelConfigPartial.nullish(),
  name: z.string(),
  permission_keys: z.array(z.string()).optional(),
  tags: z.array(zTag).optional(),
  updated_at: z.int().nullish(),
  updated_by: z.string().nullish(),
  use_icon_as_answer_icon: z.boolean().nullish(),
  workflow: zWorkflowPartial.nullish(),
})

/**
 * AppPagination
 */
export const zAppPaginationWritable = z.object({
  data: z.array(zAppPartialWritable),
  has_more: z.boolean(),
  limit: z.int(),
  page: z.int(),
  total: z.int(),
})

/**
 * AppDetailSiteResponse
 */
export const zAppDetailSiteResponseWritable = z.object({
  access_token: z.string().nullish(),
  app_base_url: z.string().nullish(),
  chat_color_theme: z.string().nullish(),
  chat_color_theme_inverted: z.boolean().nullish(),
  code: z.string().nullish(),
  copyright: z.string().nullish(),
  created_at: z.int().nullish(),
  created_by: z.string().nullish(),
  custom_disclaimer: z.string().nullish(),
  customize_domain: z.string().nullish(),
  customize_token_strategy: z.string().nullish(),
  default_language: z.string().nullish(),
  description: z.string().nullish(),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: z.union([z.string(), zIconType]).nullish(),
  input_placeholder: z.string().nullish(),
  privacy_policy: z.string().nullish(),
  prompt_public: z.boolean().nullish(),
  show_workflow_steps: z.boolean().nullish(),
  title: z.string().nullish(),
  updated_at: z.int().nullish(),
  updated_by: z.string().nullish(),
  use_icon_as_answer_icon: z.boolean().nullish(),
})

/**
 * AppDetailWithSite
 */
export const zAppDetailWithSiteWritable = z.object({
  access_mode: z.string().nullish(),
  api_base_url: z.string().nullish(),
  app_id: z.string().nullish(),
  bound_agent_id: z.string().nullish(),
  created_at: z.int().nullish(),
  created_by: z.string().nullish(),
  deleted_tools: z.array(zDeletedTool).optional(),
  description: z.string().nullish(),
  enable_api: z.boolean(),
  enable_site: z.boolean(),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: z.string().nullish(),
  id: z.string(),
  maintainer: z.string().nullish(),
  max_active_requests: z.int().nullish(),
  mode: z.string(),
  model_config: zAppModelConfigResponse.nullish(),
  name: z.string(),
  permission_keys: z.array(z.string()).optional(),
  site: zAppDetailSiteResponseWritable.nullish(),
  tags: z.array(zTag).optional(),
  tracing: z.unknown().nullish(),
  updated_at: z.int().nullish(),
  updated_by: z.string().nullish(),
  use_icon_as_answer_icon: z.boolean().nullish(),
  workflow: zWorkflowPartial.nullish(),
})

/**
 * RecentAppResponse
 */
export const zRecentAppResponseWritable = z.object({
  author_name: z.string().nullish(),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: zIconType.nullish(),
  id: z.string(),
  maintainer: z.string().nullish(),
  mode: z.enum(['advanced-chat', 'agent-chat', 'chat', 'completion', 'workflow']),
  name: z.string(),
  permission_keys: z.array(z.string()).optional(),
  updated_at: z.int(),
})

/**
 * RecentAppListResponse
 */
export const zRecentAppListResponseWritable = z.object({
  data: z.array(zRecentAppResponseWritable),
})

/**
 * AccountWithRoleResponse
 */
export const zAccountWithRoleResponseWritable = z.object({
  avatar: z.string().nullish(),
  created_at: z.int().nullish(),
  email: z.string(),
  id: z.string(),
  last_active_at: z.int().nullish(),
  last_login_at: z.int().nullish(),
  name: z.string(),
  role: z.string(),
  roles: z.array(z.record(z.string(), z.string())).optional(),
  status: z.string(),
})

/**
 * WorkflowCommentMentionUsersPayload
 */
export const zWorkflowCommentMentionUsersPayloadWritable = z.object({
  users: z.array(zAccountWithRoleResponseWritable),
})

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

/**
 * WorkflowCommentBasic
 */
export const zWorkflowCommentBasicWritable = z.object({
  content: z.string(),
  created_at: z.int().nullish(),
  created_by: z.string(),
  created_by_account: zWorkflowCommentAccountWritable.nullish(),
  id: z.string(),
  mention_count: z.int(),
  participants: z.array(zWorkflowCommentAccountWritable),
  position_x: z.number(),
  position_y: z.number(),
  reply_count: z.int(),
  resolved: z.boolean(),
  resolved_at: z.int().nullish(),
  resolved_by: z.string().nullish(),
  resolved_by_account: zWorkflowCommentAccountWritable.nullish(),
  updated_at: z.int().nullish(),
})

/**
 * WorkflowCommentBasicList
 */
export const zWorkflowCommentBasicListWritable = z.object({
  data: z.array(zWorkflowCommentBasicWritable),
})

/**
 * WorkflowCommentMention
 */
export const zWorkflowCommentMentionWritable = z.object({
  mentioned_user_account: zWorkflowCommentAccountWritable.nullish(),
  mentioned_user_id: z.string(),
  reply_id: z.string().nullish(),
})

/**
 * WorkflowCommentReply
 */
export const zWorkflowCommentReplyWritable = z.object({
  content: z.string(),
  created_at: z.int().nullish(),
  created_by: z.string(),
  created_by_account: zWorkflowCommentAccountWritable.nullish(),
  id: z.string(),
})

/**
 * WorkflowCommentDetail
 */
export const zWorkflowCommentDetailWritable = z.object({
  content: z.string(),
  created_at: z.int().nullish(),
  created_by: z.string(),
  created_by_account: zWorkflowCommentAccountWritable.nullish(),
  id: z.string(),
  mentions: z.array(zWorkflowCommentMentionWritable),
  position_x: z.number(),
  position_y: z.number(),
  replies: z.array(zWorkflowCommentReplyWritable),
  resolved: z.boolean(),
  resolved_at: z.int().nullish(),
  resolved_by: z.string().nullish(),
  resolved_by_account: zWorkflowCommentAccountWritable.nullish(),
  updated_at: z.int().nullish(),
})

export const zGetAppsQuery = z.object({
  creator_ids: z.array(z.string()).optional(),
  is_created_by_me: z.boolean().optional(),
  limit: z.int().gte(1).lte(100).optional().default(20),
  mode: z
    .enum([
      'advanced-chat',
      'agent',
      'agent-chat',
      'all',
      'channel',
      'chat',
      'completion',
      'workflow',
    ])
    .optional()
    .default('all'),
  name: z.string().optional(),
  page: z.int().gte(1).lte(99999).optional().default(1),
  sort_by: z
    .enum(['earliest_created', 'last_modified', 'recently_created'])
    .optional()
    .default('last_modified'),
  tag_ids: z.array(z.string()).optional(),
})

/**
 * Success
 */
export const zGetAppsResponse = zAppPagination

export const zPostAppsBody = zCreateAppPayload

/**
 * App created successfully
 */
export const zPostAppsResponse = zAppDetailWithSite

export const zPostAppsImportsBody = zAppImportPayload

/**
 * Import completed
 */
export const zPostAppsImportsResponse = zImport

export const zGetAppsImportsByAppIdCheckDependenciesPath = z.object({
  app_id: z.string(),
})

/**
 * Dependencies checked
 */
export const zGetAppsImportsByAppIdCheckDependenciesResponse = zCheckDependenciesResult

export const zPostAppsImportsByImportIdConfirmPath = z.object({
  import_id: z.string(),
})

/**
 * Import confirmed
 */
export const zPostAppsImportsByImportIdConfirmResponse = zImport

export const zGetAppsRecentQuery = z.object({
  limit: z.int().gte(1).lte(8).optional().default(8),
})

/**
 * Success
 */
export const zGetAppsRecentResponse = zRecentAppListResponse

export const zGetAppsStarredQuery = z.object({
  creator_ids: z.array(z.string()).optional(),
  is_created_by_me: z.boolean().optional(),
  limit: z.int().gte(1).lte(100).optional().default(20),
  mode: z
    .enum([
      'advanced-chat',
      'agent',
      'agent-chat',
      'all',
      'channel',
      'chat',
      'completion',
      'workflow',
    ])
    .optional()
    .default('all'),
  name: z.string().optional(),
  page: z.int().gte(1).lte(99999).optional().default(1),
  sort_by: z
    .enum(['earliest_created', 'last_modified', 'recently_created'])
    .optional()
    .default('last_modified'),
  tag_ids: z.array(z.string()).optional(),
})

/**
 * Success
 */
export const zGetAppsStarredResponse = zAppPagination

export const zPostAppsWorkflowsOnlineUsersBody = zWorkflowOnlineUsersPayload

/**
 * Workflow online users retrieved successfully
 */
export const zPostAppsWorkflowsOnlineUsersResponse = zWorkflowOnlineUsersResponse

export const zDeleteAppsByAppIdPath = z.object({
  app_id: z.uuid(),
})

/**
 * App deleted successfully
 */
export const zDeleteAppsByAppIdResponse = z.void()

export const zGetAppsByAppIdPath = z.object({
  app_id: z.uuid(),
})

/**
 * Success
 */
export const zGetAppsByAppIdResponse = zAppDetailWithSite

export const zPutAppsByAppIdBody = zUpdateAppPayload

export const zPutAppsByAppIdPath = z.object({
  app_id: z.uuid(),
})

/**
 * App updated successfully
 */
export const zPutAppsByAppIdResponse = zAppDetailWithSite

export const zGetAppsByAppIdAdvancedChatWorkflowRunsPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdAdvancedChatWorkflowRunsQuery = z.object({
  last_id: z.string().optional(),
  limit: z.int().gte(1).lte(100).optional().default(20),
  status: z.enum(['failed', 'partial-succeeded', 'running', 'stopped', 'succeeded']).optional(),
  triggered_from: z.enum(['app-run', 'debugging']).optional(),
})

/**
 * Workflow runs retrieved successfully
 */
export const zGetAppsByAppIdAdvancedChatWorkflowRunsResponse =
  zAdvancedChatWorkflowRunPaginationResponse

export const zGetAppsByAppIdAdvancedChatWorkflowRunsCountPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdAdvancedChatWorkflowRunsCountQuery = z.object({
  status: z.enum(['failed', 'partial-succeeded', 'running', 'stopped', 'succeeded']).optional(),
  time_range: z.string().optional(),
  triggered_from: z.enum(['app-run', 'debugging']).optional(),
})

/**
 * Workflow runs count retrieved successfully
 */
export const zGetAppsByAppIdAdvancedChatWorkflowRunsCountResponse = zWorkflowRunCountResponse

export const zPostAppsByAppIdAdvancedChatWorkflowsDraftHumanInputNodesByNodeIdFormPreviewBody =
  zHumanInputFormPreviewPayload

export const zPostAppsByAppIdAdvancedChatWorkflowsDraftHumanInputNodesByNodeIdFormPreviewPath =
  z.object({
    app_id: z.uuid(),
    node_id: z.string(),
  })

/**
 * Human input form preview
 */
export const zPostAppsByAppIdAdvancedChatWorkflowsDraftHumanInputNodesByNodeIdFormPreviewResponse =
  zHumanInputFormPreviewResponse

export const zPostAppsByAppIdAdvancedChatWorkflowsDraftHumanInputNodesByNodeIdFormRunBody =
  zHumanInputFormSubmitPayload

export const zPostAppsByAppIdAdvancedChatWorkflowsDraftHumanInputNodesByNodeIdFormRunPath =
  z.object({
    app_id: z.uuid(),
    node_id: z.string(),
  })

/**
 * Human input form submission result
 */
export const zPostAppsByAppIdAdvancedChatWorkflowsDraftHumanInputNodesByNodeIdFormRunResponse =
  zHumanInputFormSubmitResponse

export const zPostAppsByAppIdAdvancedChatWorkflowsDraftIterationNodesByNodeIdRunBody =
  zIterationNodeRunPayload

export const zPostAppsByAppIdAdvancedChatWorkflowsDraftIterationNodesByNodeIdRunPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

/**
 * Iteration node run started successfully
 */
export const zPostAppsByAppIdAdvancedChatWorkflowsDraftIterationNodesByNodeIdRunResponse =
  zGeneratedAppResponse

export const zPostAppsByAppIdAdvancedChatWorkflowsDraftLoopNodesByNodeIdRunBody =
  zLoopNodeRunPayload

export const zPostAppsByAppIdAdvancedChatWorkflowsDraftLoopNodesByNodeIdRunPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

/**
 * Loop node run started successfully
 */
export const zPostAppsByAppIdAdvancedChatWorkflowsDraftLoopNodesByNodeIdRunResponse =
  zGeneratedAppResponse

export const zPostAppsByAppIdAdvancedChatWorkflowsDraftRunBody = zAdvancedChatWorkflowRunPayload

export const zPostAppsByAppIdAdvancedChatWorkflowsDraftRunPath = z.object({
  app_id: z.uuid(),
})

/**
 * Workflow run started successfully
 */
export const zPostAppsByAppIdAdvancedChatWorkflowsDraftRunResponse = zGeneratedAppResponse

export const zGetAppsByAppIdAgentConfigFilesPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdAgentConfigFilesQuery = z.object({
  draft_type: z.enum(['debug_build', 'draft']).optional(),
  node_id: z.string().optional(),
  version_id: z.string().optional(),
})

/**
 * Config files
 */
export const zGetAppsByAppIdAgentConfigFilesResponse = zAgentConfigFileListResponse

export const zPostAppsByAppIdAgentConfigFilesBody = zAgentConfigFileUploadPayload

export const zPostAppsByAppIdAgentConfigFilesPath = z.object({
  app_id: z.uuid(),
})

export const zPostAppsByAppIdAgentConfigFilesQuery = z.object({
  draft_type: z.enum(['debug_build', 'draft']).optional(),
  node_id: z.string().optional(),
  version_id: z.string().optional(),
})

/**
 * Uploaded config file
 */
export const zPostAppsByAppIdAgentConfigFilesResponse = zAgentConfigFileUploadResponse

export const zDeleteAppsByAppIdAgentConfigFilesByNamePath = z.object({
  app_id: z.uuid(),
  name: z.string(),
})

export const zDeleteAppsByAppIdAgentConfigFilesByNameQuery = z.object({
  draft_type: z.enum(['debug_build', 'draft']).optional(),
  node_id: z.string().optional(),
  version_id: z.string().optional(),
})

/**
 * Config file deleted
 */
export const zDeleteAppsByAppIdAgentConfigFilesByNameResponse = zAgentConfigDeleteResponse

export const zGetAppsByAppIdAgentConfigFilesByNameDownloadPath = z.object({
  app_id: z.uuid(),
  name: z.string(),
})

export const zGetAppsByAppIdAgentConfigFilesByNameDownloadQuery = z.object({
  draft_type: z.enum(['debug_build', 'draft']).optional(),
  node_id: z.string().optional(),
  version_id: z.string().optional(),
})

/**
 * Config file download URL
 */
export const zGetAppsByAppIdAgentConfigFilesByNameDownloadResponse = zAgentConfigDownloadResponse

export const zGetAppsByAppIdAgentConfigFilesByNamePreviewPath = z.object({
  app_id: z.uuid(),
  name: z.string(),
})

export const zGetAppsByAppIdAgentConfigFilesByNamePreviewQuery = z.object({
  draft_type: z.enum(['debug_build', 'draft']).optional(),
  node_id: z.string().optional(),
  version_id: z.string().optional(),
})

/**
 * Preview
 */
export const zGetAppsByAppIdAgentConfigFilesByNamePreviewResponse = zAgentConfigFilePreviewResponse

export const zGetAppsByAppIdAgentConfigManifestPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdAgentConfigManifestQuery = z.object({
  draft_type: z.enum(['debug_build', 'draft']).optional(),
  node_id: z.string().optional(),
  version_id: z.string().optional(),
})

/**
 * Agent config manifest
 */
export const zGetAppsByAppIdAgentConfigManifestResponse = zAgentConfigManifestResponse

export const zGetAppsByAppIdAgentConfigSkillsPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdAgentConfigSkillsQuery = z.object({
  draft_type: z.enum(['debug_build', 'draft']).optional(),
  node_id: z.string().optional(),
  version_id: z.string().optional(),
})

/**
 * Config skills
 */
export const zGetAppsByAppIdAgentConfigSkillsResponse = zAgentConfigSkillListResponse

export const zPostAppsByAppIdAgentConfigSkillsUploadBody = z.object({
  file: z.custom<Blob | File>((value) => value instanceof Blob || value instanceof File),
})

export const zPostAppsByAppIdAgentConfigSkillsUploadPath = z.object({
  app_id: z.uuid(),
})

export const zPostAppsByAppIdAgentConfigSkillsUploadQuery = z.object({
  draft_type: z.enum(['debug_build', 'draft']).optional(),
  node_id: z.string().optional(),
  version_id: z.string().optional(),
})

/**
 * Uploaded config skill
 */
export const zPostAppsByAppIdAgentConfigSkillsUploadResponse = zAgentConfigSkillUploadResponse

export const zDeleteAppsByAppIdAgentConfigSkillsByNamePath = z.object({
  app_id: z.uuid(),
  name: z.string(),
})

export const zDeleteAppsByAppIdAgentConfigSkillsByNameQuery = z.object({
  draft_type: z.enum(['debug_build', 'draft']).optional(),
  node_id: z.string().optional(),
  version_id: z.string().optional(),
})

/**
 * Config skill deleted
 */
export const zDeleteAppsByAppIdAgentConfigSkillsByNameResponse = zAgentConfigDeleteResponse

export const zGetAppsByAppIdAgentConfigSkillsByNameDownloadPath = z.object({
  app_id: z.uuid(),
  name: z.string(),
})

export const zGetAppsByAppIdAgentConfigSkillsByNameDownloadQuery = z.object({
  draft_type: z.enum(['debug_build', 'draft']).optional(),
  node_id: z.string().optional(),
  version_id: z.string().optional(),
})

/**
 * Config skill download URL
 */
export const zGetAppsByAppIdAgentConfigSkillsByNameDownloadResponse = zAgentConfigDownloadResponse

export const zGetAppsByAppIdAgentConfigSkillsByNameFilesContentPath = z.object({
  app_id: z.uuid(),
  name: z.string(),
})

/**
 * Success
 */
export const zGetAppsByAppIdAgentConfigSkillsByNameFilesContentResponse = z.record(
  z.string(),
  z.unknown(),
)

export const zGetAppsByAppIdAgentConfigSkillsByNameFilesDownloadPath = z.object({
  app_id: z.uuid(),
  name: z.string(),
})

export const zGetAppsByAppIdAgentConfigSkillsByNameFilesDownloadQuery = z.object({
  draft_type: z.enum(['debug_build', 'draft']).optional(),
  node_id: z.string().optional(),
  path: z.string(),
  version_id: z.string().optional(),
})

/**
 * Config skill file download URL
 */
export const zGetAppsByAppIdAgentConfigSkillsByNameFilesDownloadResponse =
  zAgentConfigDownloadResponse

export const zGetAppsByAppIdAgentConfigSkillsByNameFilesPreviewPath = z.object({
  app_id: z.uuid(),
  name: z.string(),
})

export const zGetAppsByAppIdAgentConfigSkillsByNameFilesPreviewQuery = z.object({
  draft_type: z.enum(['debug_build', 'draft']).optional(),
  node_id: z.string().optional(),
  path: z.string(),
  version_id: z.string().optional(),
})

/**
 * Config skill file preview
 */
export const zGetAppsByAppIdAgentConfigSkillsByNameFilesPreviewResponse =
  zAgentConfigSkillFilePreviewResponse

export const zGetAppsByAppIdAgentConfigSkillsByNameInspectPath = z.object({
  app_id: z.uuid(),
  name: z.string(),
})

export const zGetAppsByAppIdAgentConfigSkillsByNameInspectQuery = z.object({
  draft_type: z.enum(['debug_build', 'draft']).optional(),
  node_id: z.string().optional(),
  version_id: z.string().optional(),
})

/**
 * Config skill inspect view
 */
export const zGetAppsByAppIdAgentConfigSkillsByNameInspectResponse =
  zAgentConfigSkillInspectResponse

export const zGetAppsByAppIdAgentDriveFilesPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdAgentDriveFilesQuery = z.object({
  node_id: z.string().optional(),
  prefix: z.string().optional().default(''),
})

/**
 * Drive entries
 */
export const zGetAppsByAppIdAgentDriveFilesResponse = zAgentDriveListResponse

export const zGetAppsByAppIdAgentDriveFilesDownloadPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdAgentDriveFilesDownloadQuery = z.object({
  key: z.string().min(1),
  node_id: z.string().optional(),
})

/**
 * Signed URL
 */
export const zGetAppsByAppIdAgentDriveFilesDownloadResponse = zAgentDriveDownloadResponse

export const zGetAppsByAppIdAgentDriveFilesPreviewPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdAgentDriveFilesPreviewQuery = z.object({
  key: z.string().min(1),
  node_id: z.string().optional(),
})

/**
 * Preview
 */
export const zGetAppsByAppIdAgentDriveFilesPreviewResponse = zAgentDrivePreviewResponse

export const zGetAppsByAppIdAgentDriveSkillsPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdAgentDriveSkillsQuery = z.object({
  node_id: z.string().optional(),
  prefix: z.string().optional().default(''),
})

/**
 * Drive skills
 */
export const zGetAppsByAppIdAgentDriveSkillsResponse = zAgentDriveSkillListResponse

export const zGetAppsByAppIdAgentDriveSkillsBySkillPathInspectPath = z.object({
  app_id: z.uuid(),
  skill_path: z.string(),
})

export const zGetAppsByAppIdAgentDriveSkillsBySkillPathInspectQuery = z.object({
  node_id: z.string().optional(),
})

/**
 * Drive skill inspect view
 */
export const zGetAppsByAppIdAgentDriveSkillsBySkillPathInspectResponse =
  zAgentDriveSkillInspectResponse

export const zDeleteAppsByAppIdAgentFilesPath = z.object({
  app_id: z.uuid(),
})

export const zDeleteAppsByAppIdAgentFilesQuery = z.object({
  key: z.string().min(1),
  node_id: z.string().optional(),
})

/**
 * File removed
 */
export const zDeleteAppsByAppIdAgentFilesResponse = zAgentDriveDeleteResponse

export const zPostAppsByAppIdAgentFilesBody = zAgentDriveFilePayload

export const zPostAppsByAppIdAgentFilesPath = z.object({
  app_id: z.uuid(),
})

export const zPostAppsByAppIdAgentFilesQuery = z.object({
  node_id: z.string().optional(),
})

/**
 * File committed into the agent drive
 */
export const zPostAppsByAppIdAgentFilesResponse = zAgentDriveFileCommitResponse

export const zGetAppsByAppIdAgentLogsPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdAgentLogsQuery = z.object({
  conversation_id: z.string(),
  message_id: z.string(),
})

/**
 * Agent logs retrieved successfully
 */
export const zGetAppsByAppIdAgentLogsResponse = zAgentLogResponse

export const zPostAppsByAppIdAgentSkillsUploadBody = z.object({
  file: z.custom<Blob | File>((value) => value instanceof Blob || value instanceof File),
})

export const zPostAppsByAppIdAgentSkillsUploadPath = z.object({
  app_id: z.uuid(),
})

export const zPostAppsByAppIdAgentSkillsUploadQuery = z.object({
  node_id: z.string().optional(),
})

/**
 * Skill uploaded into drive
 */
export const zPostAppsByAppIdAgentSkillsUploadResponse = zAgentSkillUploadResponse

export const zDeleteAppsByAppIdAgentSkillsBySlugPath = z.object({
  app_id: z.uuid(),
  slug: z.string(),
})

export const zDeleteAppsByAppIdAgentSkillsBySlugQuery = z.object({
  node_id: z.string().optional(),
})

/**
 * Skill removed
 */
export const zDeleteAppsByAppIdAgentSkillsBySlugResponse = zAgentDriveDeleteResponse

export const zPostAppsByAppIdAgentSkillsBySlugInferToolsPath = z.object({
  app_id: z.uuid(),
  slug: z.string(),
})

export const zPostAppsByAppIdAgentSkillsBySlugInferToolsQuery = z.object({
  node_id: z.string().optional(),
})

/**
 * Inference result (draft suggestions, nothing persisted)
 */
export const zPostAppsByAppIdAgentSkillsBySlugInferToolsResponse = zSkillToolInferenceResult

export const zPostAppsByAppIdAnnotationReplyByActionBody = zAnnotationReplyPayload

export const zPostAppsByAppIdAnnotationReplyByActionPath = z.object({
  action: z.string(),
  app_id: z.uuid(),
})

/**
 * Action completed successfully
 */
export const zPostAppsByAppIdAnnotationReplyByActionResponse = zAnnotationJobStatusResponse

export const zGetAppsByAppIdAnnotationReplyByActionStatusByJobIdPath = z.object({
  action: z.string(),
  app_id: z.uuid(),
  job_id: z.uuid(),
})

/**
 * Job status retrieved successfully
 */
export const zGetAppsByAppIdAnnotationReplyByActionStatusByJobIdResponse =
  zAnnotationJobStatusDetailResponse

export const zGetAppsByAppIdAnnotationSettingPath = z.object({
  app_id: z.uuid(),
})

/**
 * Annotation settings retrieved successfully
 */
export const zGetAppsByAppIdAnnotationSettingResponse = zAnnotationSettingResponse

export const zPostAppsByAppIdAnnotationSettingsByAnnotationSettingIdBody =
  zAnnotationSettingUpdatePayload

export const zPostAppsByAppIdAnnotationSettingsByAnnotationSettingIdPath = z.object({
  annotation_setting_id: z.uuid(),
  app_id: z.uuid(),
})

/**
 * Settings updated successfully
 */
export const zPostAppsByAppIdAnnotationSettingsByAnnotationSettingIdResponse =
  zAnnotationSettingResponse

export const zDeleteAppsByAppIdAnnotationsPath = z.object({
  app_id: z.uuid(),
})

/**
 * Annotations deleted successfully
 */
export const zDeleteAppsByAppIdAnnotationsResponse = z.void()

export const zGetAppsByAppIdAnnotationsPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdAnnotationsQuery = z.object({
  keyword: z.string().optional().default(''),
  limit: z.int().gte(1).optional().default(20),
  page: z.int().gte(1).optional().default(1),
})

/**
 * Annotations retrieved successfully
 */
export const zGetAppsByAppIdAnnotationsResponse = zAnnotationList

export const zPostAppsByAppIdAnnotationsBody = zCreateAnnotationPayload

export const zPostAppsByAppIdAnnotationsPath = z.object({
  app_id: z.uuid(),
})

/**
 * Annotation created successfully
 */
export const zPostAppsByAppIdAnnotationsResponse = zAnnotation

export const zPostAppsByAppIdAnnotationsBatchImportPath = z.object({
  app_id: z.uuid(),
})

/**
 * Batch import started successfully
 */
export const zPostAppsByAppIdAnnotationsBatchImportResponse = zAnnotationBatchImportResponse

export const zGetAppsByAppIdAnnotationsBatchImportStatusByJobIdPath = z.object({
  app_id: z.uuid(),
  job_id: z.uuid(),
})

/**
 * Job status retrieved successfully
 */
export const zGetAppsByAppIdAnnotationsBatchImportStatusByJobIdResponse =
  zAnnotationJobStatusDetailResponse

export const zGetAppsByAppIdAnnotationsCountPath = z.object({
  app_id: z.uuid(),
})

/**
 * Annotation count retrieved successfully
 */
export const zGetAppsByAppIdAnnotationsCountResponse = zAnnotationCountResponse

export const zGetAppsByAppIdAnnotationsExportPath = z.object({
  app_id: z.uuid(),
})

/**
 * Annotations exported successfully
 */
export const zGetAppsByAppIdAnnotationsExportResponse = zAnnotationExportList

export const zDeleteAppsByAppIdAnnotationsByAnnotationIdPath = z.object({
  annotation_id: z.uuid(),
  app_id: z.uuid(),
})

/**
 * Annotation deleted successfully
 */
export const zDeleteAppsByAppIdAnnotationsByAnnotationIdResponse = z.void()

export const zPostAppsByAppIdAnnotationsByAnnotationIdBody = zUpdateAnnotationPayload

export const zPostAppsByAppIdAnnotationsByAnnotationIdPath = z.object({
  annotation_id: z.uuid(),
  app_id: z.uuid(),
})

export const zPostAppsByAppIdAnnotationsByAnnotationIdResponse = z.union([zAnnotation, z.void()])

export const zGetAppsByAppIdAnnotationsByAnnotationIdHitHistoriesPath = z.object({
  annotation_id: z.uuid(),
  app_id: z.uuid(),
})

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

/**
 * Hit histories retrieved successfully
 */
export const zGetAppsByAppIdAnnotationsByAnnotationIdHitHistoriesResponse =
  zAnnotationHitHistoryList

export const zPostAppsByAppIdApiEnableBody = zAppApiStatusPayload

export const zPostAppsByAppIdApiEnablePath = z.object({
  app_id: z.uuid(),
})

/**
 * API status updated successfully
 */
export const zPostAppsByAppIdApiEnableResponse = zAppDetail

export const zPostAppsByAppIdAudioToTextBody = z.object({
  file: z.custom<Blob | File>((value) => value instanceof Blob || value instanceof File),
})

export const zPostAppsByAppIdAudioToTextPath = z.object({
  app_id: z.uuid(),
})

/**
 * Audio transcription successful
 */
export const zPostAppsByAppIdAudioToTextResponse = zAudioTranscriptResponse

export const zGetAppsByAppIdChatConversationsPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdChatConversationsQuery = z.object({
  annotation_status: z.enum(['all', 'annotated', 'not_annotated']).optional().default('all'),
  end: z.string().optional(),
  keyword: z.string().optional(),
  limit: z.int().gte(1).lte(100).optional().default(20),
  page: z.int().gte(1).lte(99999).optional().default(1),
  sort_by: z
    .enum(['-created_at', '-updated_at', 'created_at', 'updated_at'])
    .optional()
    .default('-updated_at'),
  start: z.string().optional(),
})

/**
 * Success
 */
export const zGetAppsByAppIdChatConversationsResponse = zConversationWithSummaryPagination

export const zDeleteAppsByAppIdChatConversationsByConversationIdPath = z.object({
  app_id: z.uuid(),
  conversation_id: z.uuid(),
})

/**
 * Conversation deleted successfully
 */
export const zDeleteAppsByAppIdChatConversationsByConversationIdResponse = z.void()

export const zGetAppsByAppIdChatConversationsByConversationIdPath = z.object({
  app_id: z.uuid(),
  conversation_id: z.uuid(),
})

/**
 * Success
 */
export const zGetAppsByAppIdChatConversationsByConversationIdResponse = zConversationDetail

export const zGetAppsByAppIdChatMessagesPath = z.object({
  app_id: z.uuid(),
})

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

/**
 * Success
 */
export const zGetAppsByAppIdChatMessagesResponse = zMessageInfiniteScrollPaginationResponse

export const zGetAppsByAppIdChatMessagesByMessageIdSuggestedQuestionsPath = z.object({
  app_id: z.uuid(),
  message_id: z.uuid(),
})

/**
 * Suggested questions retrieved successfully
 */
export const zGetAppsByAppIdChatMessagesByMessageIdSuggestedQuestionsResponse =
  zSuggestedQuestionsResponse

export const zPostAppsByAppIdChatMessagesByTaskIdStopPath = z.object({
  app_id: z.uuid(),
  task_id: z.string(),
})

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

export const zGetAppsByAppIdCompletionConversationsPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdCompletionConversationsQuery = z.object({
  annotation_status: z.enum(['all', 'annotated', 'not_annotated']).optional().default('all'),
  end: z.string().optional(),
  keyword: z.string().optional(),
  limit: z.int().gte(1).lte(100).optional().default(20),
  page: z.int().gte(1).lte(99999).optional().default(1),
  start: z.string().optional(),
})

/**
 * Success
 */
export const zGetAppsByAppIdCompletionConversationsResponse = zConversationPagination

export const zDeleteAppsByAppIdCompletionConversationsByConversationIdPath = z.object({
  app_id: z.uuid(),
  conversation_id: z.uuid(),
})

/**
 * Conversation deleted successfully
 */
export const zDeleteAppsByAppIdCompletionConversationsByConversationIdResponse = z.void()

export const zGetAppsByAppIdCompletionConversationsByConversationIdPath = z.object({
  app_id: z.uuid(),
  conversation_id: z.uuid(),
})

/**
 * Success
 */
export const zGetAppsByAppIdCompletionConversationsByConversationIdResponse =
  zConversationMessageDetail

export const zPostAppsByAppIdCompletionMessagesBody = zCompletionMessagePayload

export const zPostAppsByAppIdCompletionMessagesPath = z.object({
  app_id: z.uuid(),
})

/**
 * Completion generated successfully
 */
export const zPostAppsByAppIdCompletionMessagesResponse = z.record(z.string(), z.unknown())

export const zPostAppsByAppIdCompletionMessagesByTaskIdStopPath = z.object({
  app_id: z.uuid(),
  task_id: z.string(),
})

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

export const zGetAppsByAppIdConversationVariablesPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdConversationVariablesQuery = z.object({
  conversation_id: z.string(),
})

/**
 * Conversation variables retrieved successfully
 */
export const zGetAppsByAppIdConversationVariablesResponse = zPaginatedConversationVariableResponse

export const zPostAppsByAppIdConvertToWorkflowBody = zConvertToWorkflowPayload

export const zPostAppsByAppIdConvertToWorkflowPath = z.object({
  app_id: z.uuid(),
})

/**
 * Application converted to workflow successfully
 */
export const zPostAppsByAppIdConvertToWorkflowResponse = zNewAppResponse

export const zPostAppsByAppIdCopyBody = zCopyAppPayload

export const zPostAppsByAppIdCopyPath = z.object({
  app_id: z.uuid(),
})

export const zPostAppsByAppIdCopyResponse = z.union([zAppDetailWithSite, zAppImportResponse])

export const zGetAppsByAppIdExportPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdExportQuery = z.object({
  include_secret: z.boolean().optional().default(false),
  workflow_id: z.string().optional(),
})

/**
 * App exported successfully
 */
export const zGetAppsByAppIdExportResponse = zAppExportResponse

export const zPostAppsByAppIdFeedbacksBody = zMessageFeedbackPayload

export const zPostAppsByAppIdFeedbacksPath = z.object({
  app_id: z.uuid(),
})

/**
 * Feedback updated successfully
 */
export const zPostAppsByAppIdFeedbacksResponse = zSimpleResultResponse

export const zGetAppsByAppIdFeedbacksExportPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdFeedbacksExportQuery = z.object({
  end_date: z.string().optional(),
  format: z.enum(['csv', 'json']).optional().default('csv'),
  from_source: z.enum(['admin', 'user']).optional(),
  has_comment: z.boolean().optional(),
  rating: z.enum(['dislike', 'like']).optional(),
  start_date: z.string().optional(),
})

/**
 * Feedback data exported successfully
 */
export const zGetAppsByAppIdFeedbacksExportResponse = zTextFileResponse

export const zPostAppsByAppIdIconBody = zAppIconPayload

export const zPostAppsByAppIdIconPath = z.object({
  app_id: z.uuid(),
})

/**
 * Icon updated successfully
 */
export const zPostAppsByAppIdIconResponse = zAppDetail

export const zGetAppsByAppIdMessagesByMessageIdPath = z.object({
  app_id: z.uuid(),
  message_id: z.uuid(),
})

/**
 * Message retrieved successfully
 */
export const zGetAppsByAppIdMessagesByMessageIdResponse = zMessageDetailResponse

export const zPostAppsByAppIdModelConfigBody = zModelConfigRequest

export const zPostAppsByAppIdModelConfigPath = z.object({
  app_id: z.uuid(),
})

/**
 * Model configuration updated successfully
 */
export const zPostAppsByAppIdModelConfigResponse = zSimpleResultResponse

export const zPostAppsByAppIdNameBody = zAppNamePayload

export const zPostAppsByAppIdNamePath = z.object({
  app_id: z.uuid(),
})

/**
 * Name availability checked
 */
export const zPostAppsByAppIdNameResponse = zAppDetail

export const zPostAppsByAppIdPublishToCreatorsPlatformPath = z.object({
  app_id: z.uuid(),
})

/**
 * Success
 */
export const zPostAppsByAppIdPublishToCreatorsPlatformResponse = zRedirectUrlResponse

export const zGetAppsByAppIdServerPath = z.object({
  app_id: z.uuid(),
})

/**
 * MCP server configuration retrieved successfully
 */
export const zGetAppsByAppIdServerResponse = zAppMcpServerResponse

export const zPostAppsByAppIdServerBody = zMcpServerCreatePayload

export const zPostAppsByAppIdServerPath = z.object({
  app_id: z.uuid(),
})

/**
 * MCP server configuration created successfully
 */
export const zPostAppsByAppIdServerResponse = zAppMcpServerResponse

export const zPutAppsByAppIdServerBody = zMcpServerUpdatePayload

export const zPutAppsByAppIdServerPath = z.object({
  app_id: z.uuid(),
})

/**
 * MCP server configuration updated successfully
 */
export const zPutAppsByAppIdServerResponse = zAppMcpServerResponse

export const zPostAppsByAppIdSiteBody = zAppSiteUpdatePayload

export const zPostAppsByAppIdSitePath = z.object({
  app_id: z.uuid(),
})

/**
 * Site configuration updated successfully
 */
export const zPostAppsByAppIdSiteResponse = zAppSiteResponse

export const zPostAppsByAppIdSiteEnableBody = zAppSiteStatusPayload

export const zPostAppsByAppIdSiteEnablePath = z.object({
  app_id: z.uuid(),
})

/**
 * Site status updated successfully
 */
export const zPostAppsByAppIdSiteEnableResponse = zAppDetail

export const zPostAppsByAppIdSiteAccessTokenResetPath = z.object({
  app_id: z.uuid(),
})

/**
 * Access token reset successfully
 */
export const zPostAppsByAppIdSiteAccessTokenResetResponse = zAppSiteResponse

export const zDeleteAppsByAppIdStarPath = z.object({
  app_id: z.uuid(),
})

/**
 * Success
 */
export const zDeleteAppsByAppIdStarResponse = zSimpleResultResponse

export const zPostAppsByAppIdStarPath = z.object({
  app_id: z.uuid(),
})

/**
 * Success
 */
export const zPostAppsByAppIdStarResponse = zSimpleResultResponse

export const zGetAppsByAppIdStatisticsAverageResponseTimePath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdStatisticsAverageResponseTimeQuery = z.object({
  end: z.string().optional(),
  start: z.string().optional(),
})

/**
 * Average response time statistics retrieved successfully
 */
export const zGetAppsByAppIdStatisticsAverageResponseTimeResponse =
  zAverageResponseTimeStatisticResponse

export const zGetAppsByAppIdStatisticsAverageSessionInteractionsPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdStatisticsAverageSessionInteractionsQuery = z.object({
  end: z.string().optional(),
  start: z.string().optional(),
})

/**
 * Average session interaction statistics retrieved successfully
 */
export const zGetAppsByAppIdStatisticsAverageSessionInteractionsResponse =
  zAverageSessionInteractionStatisticResponse

export const zGetAppsByAppIdStatisticsDailyConversationsPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdStatisticsDailyConversationsQuery = z.object({
  end: z.string().optional(),
  start: z.string().optional(),
})

/**
 * Daily conversation statistics retrieved successfully
 */
export const zGetAppsByAppIdStatisticsDailyConversationsResponse =
  zDailyConversationStatisticResponse

export const zGetAppsByAppIdStatisticsDailyEndUsersPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdStatisticsDailyEndUsersQuery = z.object({
  end: z.string().optional(),
  start: z.string().optional(),
})

/**
 * Daily terminal statistics retrieved successfully
 */
export const zGetAppsByAppIdStatisticsDailyEndUsersResponse = zDailyTerminalStatisticResponse

export const zGetAppsByAppIdStatisticsDailyMessagesPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdStatisticsDailyMessagesQuery = z.object({
  end: z.string().optional(),
  start: z.string().optional(),
})

/**
 * Daily message statistics retrieved successfully
 */
export const zGetAppsByAppIdStatisticsDailyMessagesResponse = zDailyMessageStatisticResponse

export const zGetAppsByAppIdStatisticsTokenCostsPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdStatisticsTokenCostsQuery = z.object({
  end: z.string().optional(),
  start: z.string().optional(),
})

/**
 * Daily token cost statistics retrieved successfully
 */
export const zGetAppsByAppIdStatisticsTokenCostsResponse = zDailyTokenCostStatisticResponse

export const zGetAppsByAppIdStatisticsTokensPerSecondPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdStatisticsTokensPerSecondQuery = z.object({
  end: z.string().optional(),
  start: z.string().optional(),
})

/**
 * Tokens per second statistics retrieved successfully
 */
export const zGetAppsByAppIdStatisticsTokensPerSecondResponse = zTokensPerSecondStatisticResponse

export const zGetAppsByAppIdStatisticsUserSatisfactionRatePath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdStatisticsUserSatisfactionRateQuery = z.object({
  end: z.string().optional(),
  start: z.string().optional(),
})

/**
 * User satisfaction rate statistics retrieved successfully
 */
export const zGetAppsByAppIdStatisticsUserSatisfactionRateResponse =
  zUserSatisfactionRateStatisticResponse

export const zPostAppsByAppIdTextToAudioBody = zTextToSpeechPayload

export const zPostAppsByAppIdTextToAudioPath = z.object({
  app_id: z.uuid(),
})

/**
 * Text to speech conversion successful
 */
export const zPostAppsByAppIdTextToAudioResponse = z.record(z.string(), z.unknown())

export const zGetAppsByAppIdTextToAudioVoicesPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdTextToAudioVoicesQuery = z.object({
  language: z.string(),
})

/**
 * TTS voices retrieved successfully
 */
export const zGetAppsByAppIdTextToAudioVoicesResponse = zTextToSpeechVoiceListResponse

export const zGetAppsByAppIdTracePath = z.object({
  app_id: z.uuid(),
})

/**
 * Trace configuration retrieved successfully
 */
export const zGetAppsByAppIdTraceResponse = zAppTraceResponse

export const zPostAppsByAppIdTraceBody = zAppTracePayload

export const zPostAppsByAppIdTracePath = z.object({
  app_id: z.uuid(),
})

/**
 * Trace configuration updated successfully
 */
export const zPostAppsByAppIdTraceResponse = zSimpleResultResponse

export const zDeleteAppsByAppIdTraceConfigPath = z.object({
  app_id: z.uuid(),
})

export const zDeleteAppsByAppIdTraceConfigQuery = z.object({
  tracing_provider: z.string(),
})

/**
 * Tracing configuration deleted successfully
 */
export const zDeleteAppsByAppIdTraceConfigResponse = z.void()

export const zGetAppsByAppIdTraceConfigPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdTraceConfigQuery = z.object({
  tracing_provider: z.string(),
})

/**
 * Tracing configuration retrieved successfully
 */
export const zGetAppsByAppIdTraceConfigResponse = zTraceAppConfigResponse

export const zPatchAppsByAppIdTraceConfigBody = zTraceConfigPayload

export const zPatchAppsByAppIdTraceConfigPath = z.object({
  app_id: z.uuid(),
})

/**
 * Tracing configuration updated successfully
 */
export const zPatchAppsByAppIdTraceConfigResponse = zTraceAppConfigResponse

export const zPostAppsByAppIdTraceConfigBody = zTraceConfigPayload

export const zPostAppsByAppIdTraceConfigPath = z.object({
  app_id: z.uuid(),
})

/**
 * Tracing configuration created successfully
 */
export const zPostAppsByAppIdTraceConfigResponse = zTraceAppConfigResponse

export const zPostAppsByAppIdTriggerEnableBody = zParserEnable

export const zPostAppsByAppIdTriggerEnablePath = z.object({
  app_id: z.uuid(),
})

/**
 * Success
 */
export const zPostAppsByAppIdTriggerEnableResponse = zWorkflowTriggerResponse

export const zGetAppsByAppIdTriggersPath = z.object({
  app_id: z.uuid(),
})

/**
 * Success
 */
export const zGetAppsByAppIdTriggersResponse = zWorkflowTriggerListResponse

export const zGetAppsByAppIdWorkflowAppLogsPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdWorkflowAppLogsQuery = z.object({
  created_at__after: z.iso.datetime().optional(),
  created_at__before: z.iso.datetime().optional(),
  created_by_account: z.string().optional(),
  created_by_end_user_session_id: z.string().optional(),
  detail: z.boolean().optional().default(false),
  keyword: z.string().optional(),
  limit: z.int().gte(1).lte(100).optional().default(20),
  page: z.int().gte(1).lte(99999).optional().default(1),
  status: z
    .enum(['failed', 'partial-succeeded', 'paused', 'running', 'scheduled', 'stopped', 'succeeded'])
    .optional(),
})

/**
 * Workflow app logs retrieved successfully
 */
export const zGetAppsByAppIdWorkflowAppLogsResponse = zWorkflowAppLogPaginationResponse

export const zGetAppsByAppIdWorkflowArchivedLogsPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdWorkflowArchivedLogsQuery = z.object({
  created_at__after: z.iso.datetime().optional(),
  created_at__before: z.iso.datetime().optional(),
  created_by_account: z.string().optional(),
  created_by_end_user_session_id: z.string().optional(),
  detail: z.boolean().optional().default(false),
  keyword: z.string().optional(),
  limit: z.int().gte(1).lte(100).optional().default(20),
  page: z.int().gte(1).lte(99999).optional().default(1),
  status: z
    .enum(['failed', 'partial-succeeded', 'paused', 'running', 'scheduled', 'stopped', 'succeeded'])
    .optional(),
})

/**
 * Workflow archived logs retrieved successfully
 */
export const zGetAppsByAppIdWorkflowArchivedLogsResponse = zWorkflowArchivedLogPaginationResponse

export const zGetAppsByAppIdWorkflowRunsPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdWorkflowRunsQuery = z.object({
  last_id: z.string().optional(),
  limit: z.int().gte(1).lte(100).optional().default(20),
  status: z.enum(['failed', 'partial-succeeded', 'running', 'stopped', 'succeeded']).optional(),
  triggered_from: z.enum(['app-run', 'debugging']).optional(),
})

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

export const zGetAppsByAppIdWorkflowRunsCountPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdWorkflowRunsCountQuery = z.object({
  status: z.enum(['failed', 'partial-succeeded', 'running', 'stopped', 'succeeded']).optional(),
  time_range: z.string().optional(),
  triggered_from: z.enum(['app-run', 'debugging']).optional(),
})

/**
 * Workflow runs count retrieved successfully
 */
export const zGetAppsByAppIdWorkflowRunsCountResponse = zWorkflowRunCountResponse

export const zPostAppsByAppIdWorkflowRunsTasksByTaskIdStopPath = z.object({
  app_id: z.uuid(),
  task_id: z.string(),
})

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

export const zGetAppsByAppIdWorkflowRunsByRunIdPath = z.object({
  app_id: z.uuid(),
  run_id: z.uuid(),
})

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

export const zGetAppsByAppIdWorkflowRunsByRunIdExportPath = z.object({
  app_id: z.uuid(),
  run_id: z.uuid(),
})

/**
 * Export URL generated
 */
export const zGetAppsByAppIdWorkflowRunsByRunIdExportResponse = zWorkflowRunExportResponse

export const zGetAppsByAppIdWorkflowRunsByRunIdNodeExecutionsPath = z.object({
  app_id: z.uuid(),
  run_id: z.uuid(),
})

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

export const zGetAppsByAppIdWorkflowRunsByWorkflowRunIdAgentNodesByNodeIdSandboxFilesPath =
  z.object({
    app_id: z.uuid(),
    node_id: z.string(),
    workflow_run_id: z.uuid(),
  })

export const zGetAppsByAppIdWorkflowRunsByWorkflowRunIdAgentNodesByNodeIdSandboxFilesQuery =
  z.object({
    node_execution_id: z.string().optional(),
    path: z.string().optional().default('.'),
  })

/**
 * Listing returned
 */
export const zGetAppsByAppIdWorkflowRunsByWorkflowRunIdAgentNodesByNodeIdSandboxFilesResponse =
  zSandboxListResponse

export const zGetAppsByAppIdWorkflowRunsByWorkflowRunIdAgentNodesByNodeIdSandboxFilesReadPath =
  z.object({
    app_id: z.uuid(),
    node_id: z.string(),
    workflow_run_id: z.uuid(),
  })

export const zGetAppsByAppIdWorkflowRunsByWorkflowRunIdAgentNodesByNodeIdSandboxFilesReadQuery =
  z.object({
    node_execution_id: z.string().optional(),
    path: z.string().min(1),
  })

/**
 * Preview returned
 */
export const zGetAppsByAppIdWorkflowRunsByWorkflowRunIdAgentNodesByNodeIdSandboxFilesReadResponse =
  zSandboxReadResponse

export const zPostAppsByAppIdWorkflowRunsByWorkflowRunIdAgentNodesByNodeIdSandboxFilesUploadBody =
  zWorkflowAgentSandboxUploadPayload

export const zPostAppsByAppIdWorkflowRunsByWorkflowRunIdAgentNodesByNodeIdSandboxFilesUploadPath =
  z.object({
    app_id: z.uuid(),
    node_id: z.string(),
    workflow_run_id: z.uuid(),
  })

/**
 * Uploaded
 */
export const zPostAppsByAppIdWorkflowRunsByWorkflowRunIdAgentNodesByNodeIdSandboxFilesUploadResponse =
  zSandboxUploadResponse

export const zGetAppsByAppIdWorkflowCommentsPath = z.object({
  app_id: z.uuid(),
})

/**
 * Comments retrieved successfully
 */
export const zGetAppsByAppIdWorkflowCommentsResponse = zWorkflowCommentBasicList

export const zPostAppsByAppIdWorkflowCommentsBody = zWorkflowCommentCreatePayload

export const zPostAppsByAppIdWorkflowCommentsPath = z.object({
  app_id: z.uuid(),
})

/**
 * Comment created successfully
 */
export const zPostAppsByAppIdWorkflowCommentsResponse = zWorkflowCommentCreate

export const zGetAppsByAppIdWorkflowCommentsMentionUsersPath = z.object({
  app_id: z.uuid(),
})

/**
 * Mentionable users retrieved successfully
 */
export const zGetAppsByAppIdWorkflowCommentsMentionUsersResponse =
  zWorkflowCommentMentionUsersPayload

export const zDeleteAppsByAppIdWorkflowCommentsByCommentIdPath = z.object({
  app_id: z.uuid(),
  comment_id: z.string(),
})

/**
 * Comment deleted successfully
 */
export const zDeleteAppsByAppIdWorkflowCommentsByCommentIdResponse = z.void()

export const zGetAppsByAppIdWorkflowCommentsByCommentIdPath = z.object({
  app_id: z.uuid(),
  comment_id: z.string(),
})

/**
 * Comment retrieved successfully
 */
export const zGetAppsByAppIdWorkflowCommentsByCommentIdResponse = zWorkflowCommentDetail

export const zPutAppsByAppIdWorkflowCommentsByCommentIdBody = zWorkflowCommentUpdatePayload

export const zPutAppsByAppIdWorkflowCommentsByCommentIdPath = z.object({
  app_id: z.uuid(),
  comment_id: z.string(),
})

/**
 * Comment updated successfully
 */
export const zPutAppsByAppIdWorkflowCommentsByCommentIdResponse = zWorkflowCommentUpdate

export const zPostAppsByAppIdWorkflowCommentsByCommentIdRepliesBody = zWorkflowCommentReplyPayload

export const zPostAppsByAppIdWorkflowCommentsByCommentIdRepliesPath = z.object({
  app_id: z.uuid(),
  comment_id: z.string(),
})

/**
 * Reply created successfully
 */
export const zPostAppsByAppIdWorkflowCommentsByCommentIdRepliesResponse =
  zWorkflowCommentReplyCreate

export const zDeleteAppsByAppIdWorkflowCommentsByCommentIdRepliesByReplyIdPath = z.object({
  app_id: z.uuid(),
  comment_id: z.string(),
  reply_id: z.string(),
})

/**
 * Reply deleted successfully
 */
export const zDeleteAppsByAppIdWorkflowCommentsByCommentIdRepliesByReplyIdResponse = z.void()

export const zPutAppsByAppIdWorkflowCommentsByCommentIdRepliesByReplyIdBody =
  zWorkflowCommentReplyPayload

export const zPutAppsByAppIdWorkflowCommentsByCommentIdRepliesByReplyIdPath = z.object({
  app_id: z.uuid(),
  comment_id: z.string(),
  reply_id: z.string(),
})

/**
 * Reply updated successfully
 */
export const zPutAppsByAppIdWorkflowCommentsByCommentIdRepliesByReplyIdResponse =
  zWorkflowCommentReplyUpdate

export const zPostAppsByAppIdWorkflowCommentsByCommentIdResolvePath = z.object({
  app_id: z.uuid(),
  comment_id: z.string(),
})

/**
 * Comment resolved successfully
 */
export const zPostAppsByAppIdWorkflowCommentsByCommentIdResolveResponse = zWorkflowCommentResolve

export const zGetAppsByAppIdWorkflowStatisticsAverageAppInteractionsPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdWorkflowStatisticsAverageAppInteractionsQuery = z.object({
  end: z.string().optional(),
  start: z.string().optional(),
})

/**
 * Average app interaction statistics retrieved successfully
 */
export const zGetAppsByAppIdWorkflowStatisticsAverageAppInteractionsResponse =
  zWorkflowAverageAppInteractionStatisticResponse

export const zGetAppsByAppIdWorkflowStatisticsDailyConversationsPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdWorkflowStatisticsDailyConversationsQuery = z.object({
  end: z.string().optional(),
  start: z.string().optional(),
})

/**
 * Daily runs statistics retrieved successfully
 */
export const zGetAppsByAppIdWorkflowStatisticsDailyConversationsResponse =
  zWorkflowDailyRunsStatisticResponse

export const zGetAppsByAppIdWorkflowStatisticsDailyTerminalsPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdWorkflowStatisticsDailyTerminalsQuery = z.object({
  end: z.string().optional(),
  start: z.string().optional(),
})

/**
 * Daily terminals statistics retrieved successfully
 */
export const zGetAppsByAppIdWorkflowStatisticsDailyTerminalsResponse =
  zWorkflowDailyTerminalsStatisticResponse

export const zGetAppsByAppIdWorkflowStatisticsTokenCostsPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdWorkflowStatisticsTokenCostsQuery = z.object({
  end: z.string().optional(),
  start: z.string().optional(),
})

/**
 * Daily token cost statistics retrieved successfully
 */
export const zGetAppsByAppIdWorkflowStatisticsTokenCostsResponse =
  zWorkflowDailyTokenCostStatisticResponse

export const zGetAppsByAppIdWorkflowsPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdWorkflowsQuery = z.object({
  limit: z.int().gte(1).lte(100).optional().default(10),
  named_only: z.boolean().optional().default(false),
  page: z.int().gte(1).lte(99999).optional().default(1),
  user_id: z.string().optional(),
})

/**
 * Published workflows retrieved successfully
 */
export const zGetAppsByAppIdWorkflowsResponse = zWorkflowPaginationResponse

export const zGetAppsByAppIdWorkflowsDefaultWorkflowBlockConfigsPath = z.object({
  app_id: z.uuid(),
})

/**
 * Default block configurations retrieved successfully
 */
export const zGetAppsByAppIdWorkflowsDefaultWorkflowBlockConfigsResponse =
  zDefaultBlockConfigsResponse

export const zGetAppsByAppIdWorkflowsDefaultWorkflowBlockConfigsByBlockTypePath = z.object({
  app_id: z.uuid(),
  block_type: z.string(),
})

export const zGetAppsByAppIdWorkflowsDefaultWorkflowBlockConfigsByBlockTypeQuery = z.object({
  q: z.string().optional(),
})

/**
 * Default block configuration retrieved successfully
 */
export const zGetAppsByAppIdWorkflowsDefaultWorkflowBlockConfigsByBlockTypeResponse =
  zDefaultBlockConfigResponse

export const zGetAppsByAppIdWorkflowsDraftPath = z.object({
  app_id: z.uuid(),
})

/**
 * Draft workflow retrieved successfully
 */
export const zGetAppsByAppIdWorkflowsDraftResponse = zWorkflowResponse

export const zPostAppsByAppIdWorkflowsDraftBody = zSyncDraftWorkflowPayload

export const zPostAppsByAppIdWorkflowsDraftPath = z.object({
  app_id: z.uuid(),
})

/**
 * Draft workflow synced successfully
 */
export const zPostAppsByAppIdWorkflowsDraftResponse = zSyncDraftWorkflowResponse

export const zGetAppsByAppIdWorkflowsDraftConversationVariablesPath = z.object({
  app_id: z.uuid(),
})

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

export const zPostAppsByAppIdWorkflowsDraftConversationVariablesBody =
  zConversationVariableUpdatePayload

export const zPostAppsByAppIdWorkflowsDraftConversationVariablesPath = z.object({
  app_id: z.uuid(),
})

/**
 * Conversation variables updated successfully
 */
export const zPostAppsByAppIdWorkflowsDraftConversationVariablesResponse = zSimpleResultResponse

export const zGetAppsByAppIdWorkflowsDraftEnvironmentVariablesPath = z.object({
  app_id: z.uuid(),
})

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

export const zPostAppsByAppIdWorkflowsDraftEnvironmentVariablesBody =
  zEnvironmentVariableUpdatePayload

export const zPostAppsByAppIdWorkflowsDraftEnvironmentVariablesPath = z.object({
  app_id: z.uuid(),
})

/**
 * Environment variables updated successfully
 */
export const zPostAppsByAppIdWorkflowsDraftEnvironmentVariablesResponse = zSimpleResultResponse

export const zPostAppsByAppIdWorkflowsDraftFeaturesBody = zWorkflowFeaturesPayload

export const zPostAppsByAppIdWorkflowsDraftFeaturesPath = z.object({
  app_id: z.uuid(),
})

/**
 * Workflow features updated successfully
 */
export const zPostAppsByAppIdWorkflowsDraftFeaturesResponse = zSimpleResultResponse

export const zPostAppsByAppIdWorkflowsDraftHumanInputNodesByNodeIdDeliveryTestBody =
  zHumanInputDeliveryTestPayload

export const zPostAppsByAppIdWorkflowsDraftHumanInputNodesByNodeIdDeliveryTestPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

/**
 * Human input delivery test result
 */
export const zPostAppsByAppIdWorkflowsDraftHumanInputNodesByNodeIdDeliveryTestResponse =
  zEmptyObjectResponse

export const zPostAppsByAppIdWorkflowsDraftHumanInputNodesByNodeIdFormPreviewBody =
  zHumanInputFormPreviewPayload

export const zPostAppsByAppIdWorkflowsDraftHumanInputNodesByNodeIdFormPreviewPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

/**
 * Human input form preview
 */
export const zPostAppsByAppIdWorkflowsDraftHumanInputNodesByNodeIdFormPreviewResponse =
  zHumanInputFormPreviewResponse

export const zPostAppsByAppIdWorkflowsDraftHumanInputNodesByNodeIdFormRunBody =
  zHumanInputFormSubmitPayload

export const zPostAppsByAppIdWorkflowsDraftHumanInputNodesByNodeIdFormRunPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

/**
 * Human input form submission result
 */
export const zPostAppsByAppIdWorkflowsDraftHumanInputNodesByNodeIdFormRunResponse =
  zHumanInputFormSubmitResponse

export const zPostAppsByAppIdWorkflowsDraftIterationNodesByNodeIdRunBody = zIterationNodeRunPayload

export const zPostAppsByAppIdWorkflowsDraftIterationNodesByNodeIdRunPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

/**
 * Workflow iteration node run started successfully
 */
export const zPostAppsByAppIdWorkflowsDraftIterationNodesByNodeIdRunResponse = zGeneratedAppResponse

export const zPostAppsByAppIdWorkflowsDraftLoopNodesByNodeIdRunBody = zLoopNodeRunPayload

export const zPostAppsByAppIdWorkflowsDraftLoopNodesByNodeIdRunPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

/**
 * Workflow loop node run started successfully
 */
export const zPostAppsByAppIdWorkflowsDraftLoopNodesByNodeIdRunResponse = zGeneratedAppResponse

export const zGetAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

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

/**
 * Workflow agent composer state
 */
export const zGetAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerResponse =
  zWorkflowAgentComposerResponse

export const zPutAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerBody = zComposerSavePayload

export const zPutAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

/**
 * Workflow agent composer saved
 */
export const zPutAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerResponse =
  zWorkflowAgentComposerResponse

export const zGetAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerCandidatesPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

/**
 * Workflow agent composer candidates
 */
export const zGetAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerCandidatesResponse =
  zAgentComposerCandidatesResponse

export const zPostAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerCopyFromRosterBody =
  zWorkflowComposerCopyFromRosterPayload

export const zPostAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerCopyFromRosterPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

/**
 * Workflow roster agent copied to inline agent
 */
export const zPostAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerCopyFromRosterResponse =
  zWorkflowAgentComposerResponse

export const zPostAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerImpactBody =
  zComposerSavePayload

export const zPostAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerImpactPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

/**
 * Workflow agent composer impact
 */
export const zPostAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerImpactResponse =
  zAgentComposerImpactResponse

export const zPostAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerSaveToRosterBody =
  zComposerSavePayload

export const zPostAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerSaveToRosterPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

/**
 * Workflow agent composer saved to roster
 */
export const zPostAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerSaveToRosterResponse =
  zWorkflowAgentComposerResponse

export const zPostAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerValidateBody =
  zComposerSavePayload

export const zPostAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerValidatePath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

/**
 * Workflow agent composer validation result
 */
export const zPostAppsByAppIdWorkflowsDraftNodesByNodeIdAgentComposerValidateResponse =
  zAgentComposerValidateResponse

export const zGetAppsByAppIdWorkflowsDraftNodesByNodeIdLastRunPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

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

export const zPostAppsByAppIdWorkflowsDraftNodesByNodeIdRunBody = zDraftWorkflowNodeRunPayload

export const zPostAppsByAppIdWorkflowsDraftNodesByNodeIdRunPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

/**
 * Node run started successfully
 */
export const zPostAppsByAppIdWorkflowsDraftNodesByNodeIdRunResponse =
  zWorkflowRunNodeExecutionResponse

export const zPostAppsByAppIdWorkflowsDraftNodesByNodeIdTriggerRunPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

/**
 * Trigger event received and node executed successfully
 */
export const zPostAppsByAppIdWorkflowsDraftNodesByNodeIdTriggerRunResponse = zGeneratedAppResponse

export const zDeleteAppsByAppIdWorkflowsDraftNodesByNodeIdVariablesPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

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

export const zGetAppsByAppIdWorkflowsDraftNodesByNodeIdVariablesPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
})

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

export const zPostAppsByAppIdWorkflowsDraftRunBody = zDraftWorkflowRunPayload

export const zPostAppsByAppIdWorkflowsDraftRunPath = z.object({
  app_id: z.uuid(),
})

/**
 * Draft workflow run started successfully
 */
export const zPostAppsByAppIdWorkflowsDraftRunResponse = zGeneratedAppResponse

export const zGetAppsByAppIdWorkflowsDraftRunsByRunIdNodeOutputsPath = z.object({
  app_id: z.uuid(),
  run_id: z.uuid(),
})

/**
 * Workflow run node outputs
 */
export const zGetAppsByAppIdWorkflowsDraftRunsByRunIdNodeOutputsResponse = zWorkflowRunSnapshotView

export const zGetAppsByAppIdWorkflowsDraftRunsByRunIdNodeOutputsEventsPath = z.object({
  app_id: z.uuid(),
  run_id: z.uuid(),
})

/**
 * Workflow run node output event stream
 */
export const zGetAppsByAppIdWorkflowsDraftRunsByRunIdNodeOutputsEventsResponse =
  zEventStreamResponse

export const zGetAppsByAppIdWorkflowsDraftRunsByRunIdNodeOutputsByNodeIdPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
  run_id: z.uuid(),
})

/**
 * Workflow run node output detail
 */
export const zGetAppsByAppIdWorkflowsDraftRunsByRunIdNodeOutputsByNodeIdResponse = zNodeOutputsView

export const zGetAppsByAppIdWorkflowsDraftRunsByRunIdNodeOutputsByNodeIdByOutputNamePreviewPath =
  z.object({
    app_id: z.uuid(),
    node_id: z.string(),
    output_name: z.string(),
    run_id: z.uuid(),
  })

/**
 * Workflow run node output preview
 */
export const zGetAppsByAppIdWorkflowsDraftRunsByRunIdNodeOutputsByNodeIdByOutputNamePreviewResponse =
  zOutputPreviewView

export const zGetAppsByAppIdWorkflowsDraftSystemVariablesPath = z.object({
  app_id: z.uuid(),
})

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

export const zPostAppsByAppIdWorkflowsDraftTriggerRunBody = zDraftWorkflowTriggerRunRequest

export const zPostAppsByAppIdWorkflowsDraftTriggerRunPath = z.object({
  app_id: z.uuid(),
})

/**
 * Trigger event received and workflow executed successfully
 */
export const zPostAppsByAppIdWorkflowsDraftTriggerRunResponse = zGeneratedAppResponse

export const zPostAppsByAppIdWorkflowsDraftTriggerRunAllBody = zDraftWorkflowTriggerRunAllPayload

export const zPostAppsByAppIdWorkflowsDraftTriggerRunAllPath = z.object({
  app_id: z.uuid(),
})

/**
 * Workflow executed successfully
 */
export const zPostAppsByAppIdWorkflowsDraftTriggerRunAllResponse = zGeneratedAppResponse

export const zDeleteAppsByAppIdWorkflowsDraftVariablesPath = z.object({
  app_id: z.uuid(),
})

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

export const zGetAppsByAppIdWorkflowsDraftVariablesPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdWorkflowsDraftVariablesQuery = 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 zGetAppsByAppIdWorkflowsDraftVariablesResponse = zWorkflowDraftVariableListWithoutValue

export const zDeleteAppsByAppIdWorkflowsDraftVariablesByVariableIdPath = z.object({
  app_id: z.uuid(),
  variable_id: z.uuid(),
})

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

export const zGetAppsByAppIdWorkflowsDraftVariablesByVariableIdPath = z.object({
  app_id: z.uuid(),
  variable_id: z.uuid(),
})

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

export const zPatchAppsByAppIdWorkflowsDraftVariablesByVariableIdBody =
  zWorkflowDraftVariableUpdatePayload

export const zPatchAppsByAppIdWorkflowsDraftVariablesByVariableIdPath = z.object({
  app_id: z.uuid(),
  variable_id: z.uuid(),
})

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

export const zPutAppsByAppIdWorkflowsDraftVariablesByVariableIdResetPath = z.object({
  app_id: z.uuid(),
  variable_id: z.uuid(),
})

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

export const zGetAppsByAppIdWorkflowsPublishPath = z.object({
  app_id: z.uuid(),
})

/**
 * Published workflow retrieved successfully, or null if not found
 */
export const zGetAppsByAppIdWorkflowsPublishResponse = zWorkflowResponse

export const zPostAppsByAppIdWorkflowsPublishBody = zPublishWorkflowPayload

export const zPostAppsByAppIdWorkflowsPublishPath = z.object({
  app_id: z.uuid(),
})

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

export const zGetAppsByAppIdWorkflowsPublishedRunsByRunIdNodeOutputsPath = z.object({
  app_id: z.uuid(),
  run_id: z.uuid(),
})

/**
 * Workflow run node outputs
 */
export const zGetAppsByAppIdWorkflowsPublishedRunsByRunIdNodeOutputsResponse =
  zWorkflowRunSnapshotView

export const zGetAppsByAppIdWorkflowsPublishedRunsByRunIdNodeOutputsEventsPath = z.object({
  app_id: z.uuid(),
  run_id: z.uuid(),
})

/**
 * Workflow run node output event stream
 */
export const zGetAppsByAppIdWorkflowsPublishedRunsByRunIdNodeOutputsEventsResponse =
  zEventStreamResponse

export const zGetAppsByAppIdWorkflowsPublishedRunsByRunIdNodeOutputsByNodeIdPath = z.object({
  app_id: z.uuid(),
  node_id: z.string(),
  run_id: z.uuid(),
})

/**
 * Workflow run node output detail
 */
export const zGetAppsByAppIdWorkflowsPublishedRunsByRunIdNodeOutputsByNodeIdResponse =
  zNodeOutputsView

export const zGetAppsByAppIdWorkflowsPublishedRunsByRunIdNodeOutputsByNodeIdByOutputNamePreviewPath =
  z.object({
    app_id: z.uuid(),
    node_id: z.string(),
    output_name: z.string(),
    run_id: z.uuid(),
  })

/**
 * Workflow run node output preview
 */
export const zGetAppsByAppIdWorkflowsPublishedRunsByRunIdNodeOutputsByNodeIdByOutputNamePreviewResponse =
  zOutputPreviewView

export const zGetAppsByAppIdWorkflowsTriggersWebhookPath = z.object({
  app_id: z.uuid(),
})

export const zGetAppsByAppIdWorkflowsTriggersWebhookQuery = z.object({
  node_id: z.string(),
})

/**
 * Success
 */
export const zGetAppsByAppIdWorkflowsTriggersWebhookResponse = zWebhookTriggerResponse

export const zDeleteAppsByAppIdWorkflowsByWorkflowIdPath = z.object({
  app_id: z.uuid(),
  workflow_id: z.string(),
})

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

export const zPatchAppsByAppIdWorkflowsByWorkflowIdBody = zWorkflowUpdatePayload

export const zPatchAppsByAppIdWorkflowsByWorkflowIdPath = z.object({
  app_id: z.uuid(),
  workflow_id: z.string(),
})

/**
 * Workflow updated successfully
 */
export const zPatchAppsByAppIdWorkflowsByWorkflowIdResponse = zWorkflowResponse

export const zPostAppsByAppIdWorkflowsByWorkflowIdRestorePath = z.object({
  app_id: z.uuid(),
  workflow_id: z.string(),
})

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

export const zGetAppsByResourceIdApiKeysPath = z.object({
  resource_id: z.uuid(),
})

/**
 * API keys retrieved successfully
 */
export const zGetAppsByResourceIdApiKeysResponse = zApiKeyList

export const zPostAppsByResourceIdApiKeysPath = z.object({
  resource_id: z.uuid(),
})

/**
 * API key created successfully
 */
export const zPostAppsByResourceIdApiKeysResponse = zApiKeyItem

export const zDeleteAppsByResourceIdApiKeysByApiKeyIdPath = z.object({
  api_key_id: z.uuid(),
  resource_id: z.uuid(),
})

/**
 * API key deleted successfully
 */
export const zDeleteAppsByResourceIdApiKeysByApiKeyIdResponse = z.void()

export const zGetAppsByServerIdServerRefreshPath = z.object({
  server_id: z.uuid(),
})

/**
 * MCP server refreshed successfully
 */
export const zGetAppsByServerIdServerRefreshResponse = zAppMcpServerResponse
