// 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.optional(),
  name: z.string().min(1).max(255).nullish(),
})

/**
 * AgentConfigSnapshotSummaryResponse
 */
export const zAgentConfigSnapshotSummaryResponse = z.object({
  agent_id: z.string().nullish(),
  created_at: z.string().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'])

/**
 * 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.optional(),
  active_config_snapshot_id: z.string().nullish(),
  agent_kind: zAgentKind,
  app_id: z.string().nullish(),
  archived_at: z.string().nullish(),
  archived_by: z.string().nullish(),
  created_at: z.string().nullish(),
  created_by: z.string().nullish(),
  description: z.string(),
  icon: z.string().nullish(),
  icon_background: z.string().nullish(),
  icon_type: zAgentIconType.optional(),
  id: z.string(),
  name: z.string(),
  scope: zAgentScope,
  source: zAgentSource,
  status: zAgentStatus,
  updated_at: z.string().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.optional(),
  active_config_snapshot_id: z.string().nullish(),
  agent_kind: zAgentKind,
  app_id: z.string().nullish(),
  archived_at: z.string().nullish(),
  archived_by: z.string().nullish(),
  created_at: z.string().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.optional(),
  id: z.string(),
  in_current_workflow_count: z.int().optional().default(0),
  is_in_current_workflow: z.boolean().optional().default(false),
  name: z.string(),
  scope: zAgentScope,
  source: zAgentSource,
  status: zAgentStatus,
  updated_at: z.string().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),
})

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

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

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

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

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

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

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

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

/**
 * AgentSoulKnowledgeConfig
 */
export const zAgentSoulKnowledgeConfig = z.object({
  datasets: z.array(z.record(z.string(), z.unknown())).optional(),
  query_config: z.record(z.string(), z.unknown()).optional(),
  query_mode: zAgentKnowledgeQueryMode.optional(),
})

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

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

/**
 * 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.optional(),
  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.unknown()).optional(),
  tool_name: z.string().min(1).max(255),
})

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

/**
 * AgentSoulConfig
 */
export const zAgentSoulConfig = z.object({
  app_features: z.record(z.string(), z.unknown()).optional(),
  app_variables: z.array(zAppVariableConfig).optional(),
  env: zAgentSoulEnvConfig.optional(),
  human: zAgentSoulHumanConfig.optional(),
  knowledge: zAgentSoulKnowledgeConfig.optional(),
  memory: zAgentSoulMemoryConfig.optional(),
  misc_legacy: z.record(z.string(), z.unknown()).optional(),
  model: zAgentSoulModelConfig.optional(),
  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.optional(),
  name: z.string().min(1).max(255),
  version_note: z.string().nullish(),
})

/**
 * AgentConfigSnapshotDetailResponse
 */
export const zAgentConfigSnapshotDetailResponse = z.object({
  agent_id: z.string().nullish(),
  config_snapshot: zAgentSoulConfig,
  created_at: z.string().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.record(z.string(), z.never())

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
