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

export type ClientOptions = {
  baseUrl: `${string}://${string}/openapi/v1` | (string & {})
}

export type AccountPayload = {
  email: string
  id: string
  name: string
}

export type AccountResponse = {
  account?: AccountPayload
  default_workspace_id?: string | null
  subject_email?: string | null
  subject_issuer?: string | null
  subject_type: string
  workspaces?: Array<WorkspacePayload>
}

export type AppDescribeInfo = {
  author?: string | null
  description?: string | null
  id: string
  is_agent?: boolean
  mode: string
  name: string
  service_api_enabled: boolean
  tags?: Array<TagItem>
  updated_at?: string | null
}

export type AppDescribeQuery = {
  fields?: Array<string> | null
  workspace_id?: string | null
}

export type AppDescribeResponse = {
  info?: AppDescribeInfo
  input_schema?: {
    [key: string]: unknown
  } | null
  parameters?: {
    [key: string]: unknown
  } | null
}

export type AppInfoResponse = {
  author?: string | null
  description?: string | null
  id: string
  mode: string
  name: string
  tags?: Array<TagItem>
}

export type AppListQuery = {
  limit?: number
  mode?: AppMode
  name?: string | null
  page?: number
  tag?: string | null
  workspace_id: string
}

export type AppListResponse = {
  data: Array<AppListRow>
  has_more: boolean
  limit: number
  page: number
  total: number
}

export type AppListRow = {
  created_by_name?: string | null
  description?: string | null
  id: string
  mode: AppMode
  name: string
  tags?: Array<TagItem>
  updated_at?: string | null
  workspace_id?: string | null
  workspace_name?: string | null
}

export type AppMode
  = | 'advanced-chat'
    | 'agent-chat'
    | 'channel'
    | 'chat'
    | 'completion'
    | 'rag-pipeline'
    | 'workflow'

export type AppRunRequest = {
  auto_generate_name?: boolean
  conversation_id?: string | null
  files?: Array<{
    [key: string]: unknown
  }> | null
  inputs: {
    [key: string]: unknown
  }
  query?: string | null
  workflow_id?: string | null
  workspace_id?: string | null
}

export type DeviceCodeRequest = {
  client_id: string
  device_label: string
}

export type DeviceCodeResponse = {
  device_code: string
  expires_in: number
  interval: number
  user_code: string
  verification_uri: string
}

export type DeviceLookupQuery = {
  user_code: string
}

export type DeviceLookupResponse = {
  client_id?: string | null
  expires_in_remaining?: number
  valid: boolean
}

export type DeviceMutateRequest = {
  user_code: string
}

export type DeviceMutateResponse = {
  status: string
}

export type DevicePollRequest = {
  client_id: string
  device_code: string
}

export type FileResponse = {
  conversation_id?: string | null
  created_at?: number | null
  created_by?: string | null
  extension?: string | null
  file_key?: string | null
  id: string
  mime_type?: string | null
  name: string
  original_url?: string | null
  preview_url?: string | null
  size: number
  source_url?: string | null
  tenant_id?: string | null
  user_id?: string | null
}

export type HumanInputFormSubmitPayload = {
  action: string
  inputs: {
    [key: string]: JsonValue
  }
}

export type JsonValue = unknown

export type MemberActionResponse = {
  result?: string
}

export type MemberInvitePayload = {
  email: string
  role: 'admin' | 'normal'
}

export type MemberInviteResponse = {
  email: string
  invite_url: string
  member_id: string
  result?: string
  role: string
  tenant_id: string
}

export type MemberListQuery = {
  limit?: number
  page?: number
}

export type MemberListResponse = {
  data: Array<MemberResponse>
  has_more: boolean
  limit: number
  page: number
  total: number
}

export type MemberResponse = {
  avatar?: string | null
  email: string
  id: string
  name: string
  role: string
  status: string
}

export type MemberRoleUpdatePayload = {
  role: 'admin' | 'normal'
}

export type MessageMetadata = {
  retriever_resources?: Array<{
    [key: string]: unknown
  }>
  usage?: UsageInfo
}

export type PermittedExternalAppsListQuery = {
  limit?: number
  mode?: AppMode
  name?: string | null
  page?: number
}

export type PermittedExternalAppsListResponse = {
  data: Array<AppListRow>
  has_more: boolean
  limit: number
  page: number
  total: number
}

export type RevokeResponse = {
  status: string
}

export type ServerVersionResponse = {
  edition: 'CLOUD' | 'SELF_HOSTED'
  version: string
}

export type SessionListResponse = {
  data: Array<SessionRow>
  has_more: boolean
  limit: number
  page: number
  total: number
}

export type SessionRow = {
  client_id: string
  created_at?: string | null
  device_label: string
  expires_at?: string | null
  id: string
  last_used_at?: string | null
  prefix: string
}

export type TagItem = {
  name: string
}

export type UsageInfo = {
  completion_tokens?: number
  prompt_tokens?: number
  total_tokens?: number
}

export type WorkflowRunData = {
  created_at?: number | null
  elapsed_time?: number | null
  error?: string | null
  finished_at?: number | null
  id: string
  outputs?: {
    [key: string]: unknown
  }
  status: string
  total_steps?: number | null
  total_tokens?: number | null
  workflow_id: string
}

export type WorkspaceDetailResponse = {
  created_at?: string | null
  current: boolean
  id: string
  name: string
  role: string
  status: string
}

export type WorkspaceListResponse = {
  workspaces: Array<WorkspaceSummaryResponse>
}

export type WorkspacePayload = {
  id: string
  name: string
  role: string
}

export type WorkspaceSummaryResponse = {
  current: boolean
  id: string
  name: string
  role: string
  status: string
}

export type GetHealthData = {
  body?: never
  path?: never
  query?: never
  url: '/_health'
}

export type GetHealthResponses = {
  200: {
    [key: string]: unknown
  }
}

export type GetHealthResponse = GetHealthResponses[keyof GetHealthResponses]

export type GetVersionData = {
  body?: never
  path?: never
  query?: never
  url: '/_version'
}

export type GetVersionResponses = {
  200: ServerVersionResponse
}

export type GetVersionResponse = GetVersionResponses[keyof GetVersionResponses]

export type GetAccountData = {
  body?: never
  path?: never
  query?: never
  url: '/account'
}

export type GetAccountResponses = {
  200: AccountResponse
}

export type GetAccountResponse = GetAccountResponses[keyof GetAccountResponses]

export type GetAccountSessionsData = {
  body?: never
  path?: never
  query?: never
  url: '/account/sessions'
}

export type GetAccountSessionsResponses = {
  200: SessionListResponse
}

export type GetAccountSessionsResponse
  = GetAccountSessionsResponses[keyof GetAccountSessionsResponses]

export type DeleteAccountSessionsSelfData = {
  body?: never
  path?: never
  query?: never
  url: '/account/sessions/self'
}

export type DeleteAccountSessionsSelfResponses = {
  200: RevokeResponse
}

export type DeleteAccountSessionsSelfResponse
  = DeleteAccountSessionsSelfResponses[keyof DeleteAccountSessionsSelfResponses]

export type DeleteAccountSessionsBySessionIdData = {
  body?: never
  path: {
    session_id: string
  }
  query?: never
  url: '/account/sessions/{session_id}'
}

export type DeleteAccountSessionsBySessionIdResponses = {
  200: RevokeResponse
}

export type DeleteAccountSessionsBySessionIdResponse
  = DeleteAccountSessionsBySessionIdResponses[keyof DeleteAccountSessionsBySessionIdResponses]

export type GetAppsData = {
  body?: never
  path?: never
  query: {
    limit?: number
    mode?: string
    name?: string
    page?: number
    tag?: string
    workspace_id: string
  }
  url: '/apps'
}

export type GetAppsResponses = {
  200: AppListResponse
}

export type GetAppsResponse = GetAppsResponses[keyof GetAppsResponses]

export type GetAppsByAppIdDescribeData = {
  body?: never
  path: {
    app_id: string
  }
  query?: {
    fields?: Array<string>
    workspace_id?: string
  }
  url: '/apps/{app_id}/describe'
}

export type GetAppsByAppIdDescribeResponses = {
  200: AppDescribeResponse
}

export type GetAppsByAppIdDescribeResponse
  = GetAppsByAppIdDescribeResponses[keyof GetAppsByAppIdDescribeResponses]

export type PostAppsByAppIdFilesUploadData = {
  body?: never
  path: {
    app_id: string
  }
  query?: never
  url: '/apps/{app_id}/files/upload'
}

export type PostAppsByAppIdFilesUploadErrors = {
  400: {
    [key: string]: unknown
  }
  401: {
    [key: string]: unknown
  }
  413: {
    [key: string]: unknown
  }
  415: {
    [key: string]: unknown
  }
}

export type PostAppsByAppIdFilesUploadError
  = PostAppsByAppIdFilesUploadErrors[keyof PostAppsByAppIdFilesUploadErrors]

export type PostAppsByAppIdFilesUploadResponses = {
  201: FileResponse
}

export type PostAppsByAppIdFilesUploadResponse
  = PostAppsByAppIdFilesUploadResponses[keyof PostAppsByAppIdFilesUploadResponses]

export type GetAppsByAppIdFormHumanInputByFormTokenData = {
  body?: never
  path: {
    app_id: string
    form_token: string
  }
  query?: never
  url: '/apps/{app_id}/form/human_input/{form_token}'
}

export type GetAppsByAppIdFormHumanInputByFormTokenResponses = {
  200: {
    [key: string]: unknown
  }
}

export type GetAppsByAppIdFormHumanInputByFormTokenResponse
  = GetAppsByAppIdFormHumanInputByFormTokenResponses[keyof GetAppsByAppIdFormHumanInputByFormTokenResponses]

export type PostAppsByAppIdFormHumanInputByFormTokenData = {
  body: HumanInputFormSubmitPayload
  path: {
    app_id: string
    form_token: string
  }
  query?: never
  url: '/apps/{app_id}/form/human_input/{form_token}'
}

export type PostAppsByAppIdFormHumanInputByFormTokenResponses = {
  200: {
    [key: string]: unknown
  }
}

export type PostAppsByAppIdFormHumanInputByFormTokenResponse
  = PostAppsByAppIdFormHumanInputByFormTokenResponses[keyof PostAppsByAppIdFormHumanInputByFormTokenResponses]

export type PostAppsByAppIdRunData = {
  body: AppRunRequest
  path: {
    app_id: string
  }
  query?: never
  url: '/apps/{app_id}/run'
}

export type PostAppsByAppIdRunResponses = {
  200: {
    [key: string]: unknown
  }
}

export type PostAppsByAppIdRunResponse
  = PostAppsByAppIdRunResponses[keyof PostAppsByAppIdRunResponses]

export type GetAppsByAppIdTasksByTaskIdEventsData = {
  body?: never
  path: {
    app_id: string
    task_id: string
  }
  query?: never
  url: '/apps/{app_id}/tasks/{task_id}/events'
}

export type GetAppsByAppIdTasksByTaskIdEventsResponses = {
  200: {
    [key: string]: unknown
  }
}

export type GetAppsByAppIdTasksByTaskIdEventsResponse
  = GetAppsByAppIdTasksByTaskIdEventsResponses[keyof GetAppsByAppIdTasksByTaskIdEventsResponses]

export type PostAppsByAppIdTasksByTaskIdStopData = {
  body?: never
  path: {
    app_id: string
    task_id: string
  }
  query?: never
  url: '/apps/{app_id}/tasks/{task_id}/stop'
}

export type PostAppsByAppIdTasksByTaskIdStopResponses = {
  200: {
    [key: string]: unknown
  }
}

export type PostAppsByAppIdTasksByTaskIdStopResponse
  = PostAppsByAppIdTasksByTaskIdStopResponses[keyof PostAppsByAppIdTasksByTaskIdStopResponses]

export type PostOauthDeviceApproveData = {
  body: DeviceMutateRequest
  path?: never
  query?: never
  url: '/oauth/device/approve'
}

export type PostOauthDeviceApproveResponses = {
  200: DeviceMutateResponse
}

export type PostOauthDeviceApproveResponse
  = PostOauthDeviceApproveResponses[keyof PostOauthDeviceApproveResponses]

export type PostOauthDeviceCodeData = {
  body: DeviceCodeRequest
  path?: never
  query?: never
  url: '/oauth/device/code'
}

export type PostOauthDeviceCodeResponses = {
  200: DeviceCodeResponse
}

export type PostOauthDeviceCodeResponse
  = PostOauthDeviceCodeResponses[keyof PostOauthDeviceCodeResponses]

export type PostOauthDeviceDenyData = {
  body: DeviceMutateRequest
  path?: never
  query?: never
  url: '/oauth/device/deny'
}

export type PostOauthDeviceDenyResponses = {
  200: DeviceMutateResponse
}

export type PostOauthDeviceDenyResponse
  = PostOauthDeviceDenyResponses[keyof PostOauthDeviceDenyResponses]

export type GetOauthDeviceLookupData = {
  body?: never
  path?: never
  query: {
    user_code: string
  }
  url: '/oauth/device/lookup'
}

export type GetOauthDeviceLookupResponses = {
  200: DeviceLookupResponse
}

export type GetOauthDeviceLookupResponse
  = GetOauthDeviceLookupResponses[keyof GetOauthDeviceLookupResponses]

export type PostOauthDeviceTokenData = {
  body: DevicePollRequest
  path?: never
  query?: never
  url: '/oauth/device/token'
}

export type PostOauthDeviceTokenResponses = {
  200: {
    [key: string]: unknown
  }
}

export type PostOauthDeviceTokenResponse
  = PostOauthDeviceTokenResponses[keyof PostOauthDeviceTokenResponses]

export type GetPermittedExternalAppsData = {
  body?: never
  path?: never
  query?: never
  url: '/permitted-external-apps'
}

export type GetPermittedExternalAppsResponses = {
  200: PermittedExternalAppsListResponse
}

export type GetPermittedExternalAppsResponse
  = GetPermittedExternalAppsResponses[keyof GetPermittedExternalAppsResponses]

export type GetWorkspacesData = {
  body?: never
  path?: never
  query?: never
  url: '/workspaces'
}

export type GetWorkspacesResponses = {
  200: WorkspaceListResponse
}

export type GetWorkspacesResponse = GetWorkspacesResponses[keyof GetWorkspacesResponses]

export type GetWorkspacesByWorkspaceIdData = {
  body?: never
  path: {
    workspace_id: string
  }
  query?: never
  url: '/workspaces/{workspace_id}'
}

export type GetWorkspacesByWorkspaceIdResponses = {
  200: WorkspaceDetailResponse
}

export type GetWorkspacesByWorkspaceIdResponse
  = GetWorkspacesByWorkspaceIdResponses[keyof GetWorkspacesByWorkspaceIdResponses]

export type GetWorkspacesByWorkspaceIdMembersData = {
  body?: never
  path: {
    workspace_id: string
  }
  query?: {
    limit?: number
    page?: number
  }
  url: '/workspaces/{workspace_id}/members'
}

export type GetWorkspacesByWorkspaceIdMembersResponses = {
  200: MemberListResponse
}

export type GetWorkspacesByWorkspaceIdMembersResponse
  = GetWorkspacesByWorkspaceIdMembersResponses[keyof GetWorkspacesByWorkspaceIdMembersResponses]

export type PostWorkspacesByWorkspaceIdMembersData = {
  body: MemberInvitePayload
  path: {
    workspace_id: string
  }
  query?: never
  url: '/workspaces/{workspace_id}/members'
}

export type PostWorkspacesByWorkspaceIdMembersResponses = {
  201: MemberInviteResponse
}

export type PostWorkspacesByWorkspaceIdMembersResponse
  = PostWorkspacesByWorkspaceIdMembersResponses[keyof PostWorkspacesByWorkspaceIdMembersResponses]

export type DeleteWorkspacesByWorkspaceIdMembersByMemberIdData = {
  body?: never
  path: {
    member_id: string
    workspace_id: string
  }
  query?: never
  url: '/workspaces/{workspace_id}/members/{member_id}'
}

export type DeleteWorkspacesByWorkspaceIdMembersByMemberIdResponses = {
  200: MemberActionResponse
}

export type DeleteWorkspacesByWorkspaceIdMembersByMemberIdResponse
  = DeleteWorkspacesByWorkspaceIdMembersByMemberIdResponses[keyof DeleteWorkspacesByWorkspaceIdMembersByMemberIdResponses]

export type PutWorkspacesByWorkspaceIdMembersByMemberIdRoleData = {
  body: MemberRoleUpdatePayload
  path: {
    member_id: string
    workspace_id: string
  }
  query?: never
  url: '/workspaces/{workspace_id}/members/{member_id}/role'
}

export type PutWorkspacesByWorkspaceIdMembersByMemberIdRoleResponses = {
  200: MemberActionResponse
}

export type PutWorkspacesByWorkspaceIdMembersByMemberIdRoleResponse
  = PutWorkspacesByWorkspaceIdMembersByMemberIdRoleResponses[keyof PutWorkspacesByWorkspaceIdMembersByMemberIdRoleResponses]

export type PostWorkspacesByWorkspaceIdSwitchData = {
  body?: never
  path: {
    workspace_id: string
  }
  query?: never
  url: '/workspaces/{workspace_id}/switch'
}

export type PostWorkspacesByWorkspaceIdSwitchResponses = {
  200: WorkspaceDetailResponse
}

export type PostWorkspacesByWorkspaceIdSwitchResponse
  = PostWorkspacesByWorkspaceIdSwitchResponses[keyof PostWorkspacesByWorkspaceIdSwitchResponses]
