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

import * as z from 'zod'

/**
 * InstalledAppCreatePayload
 */
export const zInstalledAppCreatePayload = z.object({
  app_id: z.string(),
})

/**
 * SimpleMessageResponse
 */
export const zSimpleMessageResponse = z.object({
  message: z.string(),
})

/**
 * InstalledAppUpdatePayload
 */
export const zInstalledAppUpdatePayload = z.object({
  is_pinned: z.boolean().nullish(),
})

/**
 * SimpleResultMessageResponse
 */
export const zSimpleResultMessageResponse = z.object({
  message: z.string(),
  result: z.string(),
})

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

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

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

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

/**
 * ConversationRenamePayload
 */
export const zConversationRenamePayload = z.object({
  auto_generate: z.boolean().optional().default(false),
  name: z.string().nullish(),
})

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

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

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

/**
 * ExploreAppMetaResponse
 */
export const zExploreAppMetaResponse = z.object({
  tool_icons: z.record(z.string(), z.unknown()).optional(),
})

/**
 * SavedMessageCreatePayload
 */
export const zSavedMessageCreatePayload = z.object({
  message_id: z.string(),
})

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

/**
 * AudioBinaryResponse
 */
export const zAudioBinaryResponse = z.custom<Blob | File>()

/**
 * WorkflowRunPayload
 */
export const zWorkflowRunPayload = z.object({
  files: z.array(z.record(z.string(), z.unknown())).nullish(),
  inputs: z.record(z.string(), z.unknown()),
})

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

/**
 * SimpleConversation
 */
export const zSimpleConversation = z.object({
  created_at: z.int().nullish(),
  id: z.string(),
  inputs: z.record(z.string(), zJsonValue),
  introduction: z.string().nullish(),
  name: z.string(),
  status: z.string(),
  updated_at: z.int().nullish(),
})

/**
 * ConversationInfiniteScrollPagination
 */
export const zConversationInfiniteScrollPagination = z.object({
  data: z.array(zSimpleConversation),
  has_more: z.boolean(),
  limit: z.int(),
})

export const zJsonObject = z.record(z.string(), z.unknown())

/**
 * SystemParameters
 */
export const zSystemParameters = z.object({
  audio_file_size_limit: z.int(),
  file_size_limit: z.int(),
  image_file_size_limit: z.int(),
  video_file_size_limit: z.int(),
  workflow_file_upload_limit: z.int(),
})

/**
 * Parameters
 */
export const zParameters = z.object({
  annotation_reply: zJsonObject,
  file_upload: zJsonObject,
  more_like_this: zJsonObject,
  opening_statement: z.string().nullish(),
  retriever_resource: zJsonObject,
  sensitive_word_avoidance: zJsonObject,
  speech_to_text: zJsonObject,
  suggested_questions: z.array(z.string()),
  suggested_questions_after_answer: zJsonObject,
  system_parameters: zSystemParameters,
  text_to_speech: zJsonObject,
  user_input_form: z.array(zJsonObject),
})

/**
 * InstalledAppInfoResponse
 */
export const zInstalledAppInfoResponse = z.object({
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: z.string().nullish(),
  id: z.string(),
  mode: z.string().nullish(),
  name: z.string().nullish(),
  use_icon_as_answer_icon: z.boolean().nullish(),
})

/**
 * InstalledAppResponse
 */
export const zInstalledAppResponse = z.object({
  app: zInstalledAppInfoResponse,
  app_owner_tenant_id: z.string(),
  editable: z.boolean(),
  id: z.string(),
  is_pinned: z.boolean(),
  last_used_at: z.int().nullish(),
  uninstallable: z.boolean(),
})

/**
 * InstalledAppListResponse
 */
export const zInstalledAppListResponse = z.object({
  installed_apps: z.array(zInstalledAppResponse),
})

/**
 * AgentThought
 */
export const zAgentThought = z.object({
  chain_id: z.string().nullish(),
  created_at: z.int().nullish(),
  files: z.array(z.string()),
  id: z.string(),
  message_chain_id: z.string().nullish(),
  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,
})

/**
 * SimpleFeedback
 */
export const zSimpleFeedback = z.object({
  rating: z.string().nullish(),
})

export const zJsonValueType = z.unknown()

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

/**
 * SavedMessageItem
 */
export const zSavedMessageItem = z.object({
  answer: z.string(),
  created_at: z.int().nullish(),
  feedback: zSimpleFeedback.nullish(),
  id: z.string(),
  inputs: z.record(z.string(), zJsonValueType),
  message_files: z.array(zMessageFile),
  query: z.string(),
})

/**
 * SavedMessageInfiniteScrollPagination
 */
export const zSavedMessageInfiniteScrollPagination = z.object({
  data: z.array(zSavedMessageItem),
  has_more: z.boolean(),
  limit: z.int(),
})

/**
 * RetrieverResource
 */
export const zRetrieverResource = z.object({
  content: z.string().nullish(),
  created_at: z.int().nullish(),
  data_source_type: z.string().nullish(),
  dataset_id: z.string().nullish(),
  dataset_name: z.string().nullish(),
  document_id: z.string().nullish(),
  document_name: z.string().nullish(),
  hit_count: z.int().nullish(),
  id: z.string().optional(),
  index_node_hash: z.string().nullish(),
  message_id: z.string().optional(),
  position: z.int(),
  score: z.number().nullish(),
  segment_id: z.string().nullish(),
  segment_position: z.int().nullish(),
  summary: z.string().nullish(),
  word_count: z.int().nullish(),
})

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

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

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

/**
 * ValueSourceType
 *
 * ValueSourceType records whether the value comes from a static setting
 * in form definiton, 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(),
})

/**
 * MessageListItem
 */
export const zMessageListItem = z.object({
  agent_thoughts: z.array(zAgentThought),
  answer: z.string(),
  conversation_id: z.string(),
  created_at: z.int().nullish(),
  error: z.string().nullish(),
  extra_contents: z.array(zHumanInputContent),
  feedback: zSimpleFeedback.nullish(),
  id: z.string(),
  inputs: z.record(z.string(), zJsonValueType),
  message_files: z.array(zMessageFile),
  parent_message_id: z.string().nullish(),
  query: z.string(),
  retriever_resources: z.array(zRetrieverResource),
  status: z.string(),
})

/**
 * MessageInfiniteScrollPagination
 */
export const zMessageInfiniteScrollPagination = z.object({
  data: z.array(zMessageListItem),
  has_more: z.boolean(),
  limit: z.int(),
})

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

/**
 * Success
 */
export const zGetInstalledAppsResponse = zInstalledAppListResponse

export const zPostInstalledAppsBody = zInstalledAppCreatePayload

/**
 * Success
 */
export const zPostInstalledAppsResponse = zSimpleMessageResponse

export const zDeleteInstalledAppsByInstalledAppIdPath = z.object({
  installed_app_id: z.string(),
})

/**
 * App uninstalled successfully
 */
export const zDeleteInstalledAppsByInstalledAppIdResponse = z.void()

export const zPatchInstalledAppsByInstalledAppIdBody = zInstalledAppUpdatePayload

export const zPatchInstalledAppsByInstalledAppIdPath = z.object({
  installed_app_id: z.string(),
})

/**
 * Success
 */
export const zPatchInstalledAppsByInstalledAppIdResponse = zSimpleResultMessageResponse

export const zPostInstalledAppsByInstalledAppIdAudioToTextPath = z.object({
  installed_app_id: z.string(),
})

/**
 * Success
 */
export const zPostInstalledAppsByInstalledAppIdAudioToTextResponse = zAudioTranscriptResponse

export const zPostInstalledAppsByInstalledAppIdChatMessagesBody = zChatMessagePayload

export const zPostInstalledAppsByInstalledAppIdChatMessagesPath = z.object({
  installed_app_id: z.string(),
})

/**
 * Success
 */
export const zPostInstalledAppsByInstalledAppIdChatMessagesResponse = zGeneratedAppResponse

export const zPostInstalledAppsByInstalledAppIdChatMessagesByTaskIdStopPath = z.object({
  installed_app_id: z.string(),
  task_id: z.string(),
})

/**
 * Success
 */
export const zPostInstalledAppsByInstalledAppIdChatMessagesByTaskIdStopResponse
  = zSimpleResultResponse

export const zPostInstalledAppsByInstalledAppIdCompletionMessagesBody
  = zCompletionMessageExplorePayload

export const zPostInstalledAppsByInstalledAppIdCompletionMessagesPath = z.object({
  installed_app_id: z.string(),
})

/**
 * Success
 */
export const zPostInstalledAppsByInstalledAppIdCompletionMessagesResponse = zGeneratedAppResponse

export const zPostInstalledAppsByInstalledAppIdCompletionMessagesByTaskIdStopPath = z.object({
  installed_app_id: z.string(),
  task_id: z.string(),
})

/**
 * Success
 */
export const zPostInstalledAppsByInstalledAppIdCompletionMessagesByTaskIdStopResponse
  = zSimpleResultResponse

export const zGetInstalledAppsByInstalledAppIdConversationsPath = z.object({
  installed_app_id: z.string(),
})

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

/**
 * Success
 */
export const zGetInstalledAppsByInstalledAppIdConversationsResponse
  = zConversationInfiniteScrollPagination

export const zDeleteInstalledAppsByInstalledAppIdConversationsByCIdPath = z.object({
  c_id: z.string(),
  installed_app_id: z.string(),
})

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

export const zPostInstalledAppsByInstalledAppIdConversationsByCIdNameBody
  = zConversationRenamePayload

export const zPostInstalledAppsByInstalledAppIdConversationsByCIdNamePath = z.object({
  c_id: z.string(),
  installed_app_id: z.string(),
})

/**
 * Conversation renamed successfully
 */
export const zPostInstalledAppsByInstalledAppIdConversationsByCIdNameResponse = zSimpleConversation

export const zPatchInstalledAppsByInstalledAppIdConversationsByCIdPinPath = z.object({
  c_id: z.string(),
  installed_app_id: z.string(),
})

/**
 * Success
 */
export const zPatchInstalledAppsByInstalledAppIdConversationsByCIdPinResponse = zResultResponse

export const zPatchInstalledAppsByInstalledAppIdConversationsByCIdUnpinPath = z.object({
  c_id: z.string(),
  installed_app_id: z.string(),
})

/**
 * Success
 */
export const zPatchInstalledAppsByInstalledAppIdConversationsByCIdUnpinResponse = zResultResponse

export const zGetInstalledAppsByInstalledAppIdMessagesPath = z.object({
  installed_app_id: z.string(),
})

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

/**
 * Success
 */
export const zGetInstalledAppsByInstalledAppIdMessagesResponse = zMessageInfiniteScrollPagination

export const zPostInstalledAppsByInstalledAppIdMessagesByMessageIdFeedbacksBody
  = zMessageFeedbackPayload

export const zPostInstalledAppsByInstalledAppIdMessagesByMessageIdFeedbacksPath = z.object({
  installed_app_id: z.string(),
  message_id: z.string(),
})

/**
 * Feedback submitted successfully
 */
export const zPostInstalledAppsByInstalledAppIdMessagesByMessageIdFeedbacksResponse
  = zResultResponse

export const zGetInstalledAppsByInstalledAppIdMessagesByMessageIdMoreLikeThisPath = z.object({
  installed_app_id: z.string(),
  message_id: z.string(),
})

export const zGetInstalledAppsByInstalledAppIdMessagesByMessageIdMoreLikeThisQuery = z.object({
  response_mode: z.enum(['blocking', 'streaming']),
})

/**
 * Success
 */
export const zGetInstalledAppsByInstalledAppIdMessagesByMessageIdMoreLikeThisResponse
  = zGeneratedAppResponse

export const zGetInstalledAppsByInstalledAppIdMessagesByMessageIdSuggestedQuestionsPath = z.object({
  installed_app_id: z.string(),
  message_id: z.string(),
})

/**
 * Success
 */
export const zGetInstalledAppsByInstalledAppIdMessagesByMessageIdSuggestedQuestionsResponse
  = zSuggestedQuestionsResponse

export const zGetInstalledAppsByInstalledAppIdMetaPath = z.object({
  installed_app_id: z.string(),
})

/**
 * Success
 */
export const zGetInstalledAppsByInstalledAppIdMetaResponse = zExploreAppMetaResponse

export const zGetInstalledAppsByInstalledAppIdParametersPath = z.object({
  installed_app_id: z.string(),
})

/**
 * Success
 */
export const zGetInstalledAppsByInstalledAppIdParametersResponse = zParameters

export const zGetInstalledAppsByInstalledAppIdSavedMessagesPath = z.object({
  installed_app_id: z.string(),
})

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

/**
 * Success
 */
export const zGetInstalledAppsByInstalledAppIdSavedMessagesResponse
  = zSavedMessageInfiniteScrollPagination

export const zPostInstalledAppsByInstalledAppIdSavedMessagesBody = zSavedMessageCreatePayload

export const zPostInstalledAppsByInstalledAppIdSavedMessagesPath = z.object({
  installed_app_id: z.string(),
})

/**
 * Success
 */
export const zPostInstalledAppsByInstalledAppIdSavedMessagesResponse = zResultResponse

export const zDeleteInstalledAppsByInstalledAppIdSavedMessagesByMessageIdPath = z.object({
  installed_app_id: z.string(),
  message_id: z.string(),
})

/**
 * Saved message deleted successfully
 */
export const zDeleteInstalledAppsByInstalledAppIdSavedMessagesByMessageIdResponse = z.void()

export const zPostInstalledAppsByInstalledAppIdTextToAudioBody = zTextToAudioPayload

export const zPostInstalledAppsByInstalledAppIdTextToAudioPath = z.object({
  installed_app_id: z.string(),
})

/**
 * Success
 */
export const zPostInstalledAppsByInstalledAppIdTextToAudioResponse = zAudioBinaryResponse

export const zPostInstalledAppsByInstalledAppIdWorkflowsRunBody = zWorkflowRunPayload

export const zPostInstalledAppsByInstalledAppIdWorkflowsRunPath = z.object({
  installed_app_id: z.string(),
})

/**
 * Success
 */
export const zPostInstalledAppsByInstalledAppIdWorkflowsRunResponse = zGeneratedAppResponse

export const zPostInstalledAppsByInstalledAppIdWorkflowsTasksByTaskIdStopPath = z.object({
  installed_app_id: z.string(),
  task_id: z.string(),
})

/**
 * Success
 */
export const zPostInstalledAppsByInstalledAppIdWorkflowsTasksByTaskIdStopResponse
  = zSimpleResultResponse
