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

import * as z from 'zod'

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

/**
 * RosterAgentUpdatePayload
 */
export const zRosterAgentUpdatePayload = z.object({
  description: z.string().nullish(),
  icon: z.string().max(255).nullish(),
  icon_background: z.string().max(255).nullish(),
  icon_type: zAgentIconType.nullish(),
  name: z.string().min(1).max(255).nullish(),
  role: z.string().max(255).nullish(),
})

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

/**
 * AgentConfigSnapshotListResponse
 */
export const zAgentConfigSnapshotListResponse = z.object({
  data: z.array(zAgentConfigSnapshotSummaryResponse),
})

/**
 * AgentKind
 *
 * Agent implementation family.
 *
 * This leaves room for future non-Dify agent implementations while keeping
 * the current roster/workflow APIs scoped to Dify Agent.
 */
export const zAgentKind = z.enum(['dify_agent'])

/**
 * AgentPublishedReferenceResponse
 */
export const zAgentPublishedReferenceResponse = z.object({
  app_id: z.string(),
  app_mode: z.string(),
  app_name: z.string(),
  node_ids: z.array(z.string()).optional(),
  workflow_id: z.string(),
  workflow_version: z.string(),
})

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

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

/**
 * AgentRosterResponse
 */
export const zAgentRosterResponse = z.object({
  active_config_snapshot: zAgentConfigSnapshotSummaryResponse.nullish(),
  active_config_snapshot_id: z.string().nullish(),
  agent_kind: zAgentKind,
  app_id: z.string().nullish(),
  archived_at: z.int().nullish(),
  archived_by: z.string().nullish(),
  created_at: z.int().nullish(),
  created_by: z.string().nullish(),
  description: z.string(),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: zAgentIconType.nullish(),
  id: z.string(),
  name: z.string(),
  published_node_reference_count: z.int().optional().default(0),
  published_reference_count: z.int().optional().default(0),
  published_references: z.array(zAgentPublishedReferenceResponse).optional(),
  role: z.string().optional().default(''),
  scope: zAgentScope,
  source: zAgentSource,
  status: zAgentStatus,
  updated_at: z.int().nullish(),
  updated_by: z.string().nullish(),
  workflow_id: z.string().nullish(),
  workflow_node_id: z.string().nullish(),
})

/**
 * AgentRosterListResponse
 */
export const zAgentRosterListResponse = z.object({
  data: z.array(zAgentRosterResponse),
  has_more: z.boolean(),
  limit: z.int(),
  page: z.int(),
  total: z.int(),
})

/**
 * AgentInviteOptionResponse
 */
export const zAgentInviteOptionResponse = z.object({
  active_config_snapshot: zAgentConfigSnapshotSummaryResponse.nullish(),
  active_config_snapshot_id: z.string().nullish(),
  agent_kind: zAgentKind,
  app_id: z.string().nullish(),
  archived_at: z.int().nullish(),
  archived_by: z.string().nullish(),
  created_at: z.int().nullish(),
  created_by: z.string().nullish(),
  description: z.string(),
  existing_node_ids: z.array(z.string()).optional(),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: zAgentIconType.nullish(),
  id: z.string(),
  in_current_workflow_count: z.int().optional().default(0),
  is_in_current_workflow: z.boolean().optional().default(false),
  name: z.string(),
  published_node_reference_count: z.int().optional().default(0),
  published_reference_count: z.int().optional().default(0),
  published_references: z.array(zAgentPublishedReferenceResponse).optional(),
  role: z.string().optional().default(''),
  scope: zAgentScope,
  source: zAgentSource,
  status: zAgentStatus,
  updated_at: z.int().nullish(),
  updated_by: z.string().nullish(),
  workflow_id: z.string().nullish(),
  workflow_node_id: z.string().nullish(),
})

/**
 * AgentInviteOptionsResponse
 */
export const zAgentInviteOptionsResponse = z.object({
  data: z.array(zAgentInviteOptionResponse),
  has_more: z.boolean(),
  limit: z.int(),
  page: z.int(),
  total: z.int(),
})

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

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

/**
 * AgentConfigRevisionOperation
 *
 * Audit operation recorded for Agent Soul version/revision changes.
 */
export const zAgentConfigRevisionOperation = z.enum([
  'create_version',
  'save_current_version',
  'save_new_agent',
  'save_new_version',
  'save_to_roster',
])

/**
 * AgentConfigRevisionResponse
 */
export const zAgentConfigRevisionResponse = z.object({
  created_at: z.int().nullish(),
  created_by: z.string().nullish(),
  current_snapshot_id: z.string(),
  id: z.string(),
  operation: zAgentConfigRevisionOperation,
  previous_snapshot_id: z.string().nullish(),
  revision: z.int(),
  summary: z.string().nullish(),
  version_note: z.string().nullish(),
})

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

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

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

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

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

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

/**
 * AgentKnowledgeQueryConfig
 */
export const zAgentKnowledgeQueryConfig = z.object({
  query: z.string().nullish(),
  score_threshold: z.number().gte(0).lte(1).nullish(),
  score_threshold_enabled: z.boolean().nullish(),
  top_k: z.int().gte(1).nullish(),
})

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

/**
 * AgentSoulKnowledgeConfig
 */
export const zAgentSoulKnowledgeConfig = z.object({
  datasets: z.array(zAgentKnowledgeDatasetConfig).optional(),
  query_config: zAgentKnowledgeQueryConfig.optional(),
  query_mode: zAgentKnowledgeQueryMode.nullish(),
})

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

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

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

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

/**
 * 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(),
  variable: z.string().max(255).nullish(),
})

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

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

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

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

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

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

/**
 * AgentSoulDifyToolConfig
 *
 * One Dify Plugin Tool configured on Agent Soul.
 *
 * The API backend prepares this persisted product shape into
 * ``DifyPluginToolConfig`` before sending a run request to Agent backend.
 * ``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: z.string().optional().default('plugin'),
  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({
  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(),
})

/**
 * AgentSoulConfig
 */
export const zAgentSoulConfig = z.object({
  app_features: zAgentSoulAppFeaturesConfig.optional(),
  app_variables: z.array(zAppVariableConfig).optional(),
  env: zAgentSoulEnvConfig.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),
  skills_files: zAgentSoulSkillsFilesConfig.optional(),
  tools: zAgentSoulToolsConfig.optional(),
})

/**
 * RosterAgentCreatePayload
 */
export const zRosterAgentCreatePayload = z.object({
  agent_soul: zAgentSoulConfig.optional(),
  description: z.string().optional().default(''),
  icon: z.string().max(255).nullish(),
  icon_background: z.string().max(255).nullish(),
  icon_type: zAgentIconType.nullish(),
  name: z.string().min(1).max(255),
  role: z.string().max(255).optional().default(''),
  version_note: z.string().nullish(),
})

/**
 * AgentConfigSnapshotDetailResponse
 */
export const zAgentConfigSnapshotDetailResponse = z.object({
  agent_id: z.string().nullish(),
  config_snapshot: zAgentSoulConfig,
  created_at: z.int().nullish(),
  created_by: z.string().nullish(),
  id: z.string(),
  revisions: z.array(zAgentConfigRevisionResponse).optional(),
  summary: z.string().nullish(),
  version: z.int(),
  version_note: z.string().nullish(),
})

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

/**
 * Agent roster list
 */
export const zGetAgentsResponse = zAgentRosterListResponse

export const zPostAgentsBody = zRosterAgentCreatePayload

/**
 * Agent created
 */
export const zPostAgentsResponse = zAgentRosterResponse

export const zGetAgentsInviteOptionsQuery = z.object({
  app_id: z.string().optional(),
  keyword: z.string().optional(),
  limit: z.int().gte(1).lte(100).optional().default(20),
  page: z.int().gte(1).optional().default(1),
})

/**
 * Agent invite options
 */
export const zGetAgentsInviteOptionsResponse = zAgentInviteOptionsResponse

export const zDeleteAgentsByAgentIdPath = z.object({
  agent_id: z.string(),
})

/**
 * Agent archived
 */
export const zDeleteAgentsByAgentIdResponse = z.void()

export const zGetAgentsByAgentIdPath = z.object({
  agent_id: z.string(),
})

/**
 * Agent detail
 */
export const zGetAgentsByAgentIdResponse = zAgentRosterResponse

export const zPatchAgentsByAgentIdBody = zRosterAgentUpdatePayload

export const zPatchAgentsByAgentIdPath = z.object({
  agent_id: z.string(),
})

/**
 * Agent updated
 */
export const zPatchAgentsByAgentIdResponse = zAgentRosterResponse

export const zGetAgentsByAgentIdVersionsPath = z.object({
  agent_id: z.string(),
})

/**
 * Agent versions
 */
export const zGetAgentsByAgentIdVersionsResponse = zAgentConfigSnapshotListResponse

export const zGetAgentsByAgentIdVersionsByVersionIdPath = z.object({
  agent_id: z.string(),
  version_id: z.string(),
})

/**
 * Agent version detail
 */
export const zGetAgentsByAgentIdVersionsByVersionIdResponse = zAgentConfigSnapshotDetailResponse
