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

import * as z from 'zod'

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/**
 * WorkflowRunForListResponse
 */
export const zWorkflowRunForListResponse = z.object({
  created_at: z.int().nullish(),
  created_by_account: zSimpleAccount.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: zSimpleAccount.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: zSimpleAccount.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(),
  status: z.string().nullish(),
  title: z.string().nullish(),
})

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

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

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

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

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

/**
 * WorkflowResponse
 */
export const zWorkflowResponse = z.object({
  conversation_variables: z.array(zWorkflowConversationVariableResponse),
  created_at: z.int(),
  created_by: zSimpleAccount.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: zSimpleAccount.nullish(),
  version: z.string(),
})

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

export const zPostSnippetsBySnippetIdWorkflowsDraftBody = zSnippetDraftSyncPayload

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

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

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

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

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

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

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

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

export const zPostSnippetsBySnippetIdWorkflowsDraftIterationNodesByNodeIdRunBody
  = zSnippetIterationNodeRunPayload

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

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

export const zPostSnippetsBySnippetIdWorkflowsDraftLoopNodesByNodeIdRunBody
  = zSnippetLoopNodeRunPayload

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

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

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

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

export const zPostSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdRunBody
  = zSnippetDraftNodeRunPayload

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

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

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

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

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

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

export const zPostSnippetsBySnippetIdWorkflowsDraftRunBody = zSnippetDraftRunPayload

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

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

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

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

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

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

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

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

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

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

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

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

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

export const zPatchSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdBody
  = zWorkflowDraftVariableUpdatePayload

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

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

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

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

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

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

export const zPostSnippetsBySnippetIdWorkflowsPublishBody = zPublishWorkflowPayload

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

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

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

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