Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

148 KB
Raw Blame
import { apiMutator } from '../../../../frontend/src/lib/api-orval-mutator'
/**
 * Auto-generated from the Django backend OpenAPI schema.
 * To modify these types, update the Django serializers or views, then run:
 *   hogli build:openapi
 * Questions or issues? #team-devex on Slack
 *
 * PostHog API - generated
 * OpenAPI spec version: 1.0.0
 */
import type {
    ActivitySummaryApi,
    ActivitySummarySearchResultApi,
    ActivitySummaryVersionApi,
    AnomalyInsightResponseApi,
    AnomalySearchResponseApi,
    CancelReportCheckRequestApi,
    CommitDiffResponseApi,
    CreateReportCheckRequestApi,
    EditReportRequestApi,
    EditReportResponseApi,
    EmitFindingRequestApi,
    EmitFindingResponseApi,
    EmitReportRequestApi,
    EmitReportResponseApi,
    FleetFindingsSummaryApi,
    ForgetRequestApi,
    ForgetResponseApi,
    InboxOnboardingDraftApi,
    InboxOnboardingStateApi,
    InboxSummaryApi,
    LighthouseAuditRequestApi,
    LighthouseAuditResponseApi,
    MonthlyUsageApi,
    PaginatedPauseStateResponseListApi,
    PaginatedSignalReportArtefactListApi,
    PaginatedSignalReportCheckListApi,
    PaginatedSignalReportListListApi,
    PaginatedSignalSourceConfigListApi,
    PatchedPullRequestReviewCommentUpdateApi,
    PatchedReviewerExclusionUpdateApi,
    PatchedSignalReportArtefactLogUpdateApi,
    PatchedSignalReportContentUpdateApi,
    PatchedSignalScoutConfigUpdateApi,
    PatchedSignalSourceConfigApi,
    PauseResponseApi,
    PauseUntilRequestApi,
    PersonalRankingApi,
    ProjectProfileApi,
    PullRequestChecksResponseApi,
    PullRequestCiStatusesResponseApi,
    PullRequestCommentsResponseApi,
    PullRequestReviewCommentCreateApi,
    PullRequestReviewCommentCreateResponseApi,
    PullRequestReviewCommentReactionCreateApi,
    PullRequestReviewCommentReactionCreateResponseApi,
    RankingOutcomesResponseApi,
    RecordCheckResultRequestApi,
    RecordCheckResultResponseApi,
    RecordStructuredOutputRequestApi,
    RecordStructuredOutputResponseApi,
    RememberRequestApi,
    ReportReadStateRequestApi,
    ReportReadStateResponseApi,
    ReportSignalsResponseApi,
    ReportSpendApi,
    ReviewerExclusionApi,
    ReviewerExclusionCreateApi,
    ReviewerExclusionCreateResultApi,
    ScoutChatTaskApi,
    ScoutChatTaskCreateApi,
    ScoutCheckSummaryApi,
    ScoutEmissionReportLinkApi,
    ScoutMemberApi,
    ScoutMetadataApi,
    ScoutNoteApi,
    ScoutNoteCreateRequestApi,
    ScoutRubricDocumentApi,
    ScoutRubricGenerateApi,
    ScoutRubricSaveApi,
    ScoutRunIdsBatchRequestApi,
    ScoutSuggestionItemApi,
    ScoutSuggestionRefreshApi,
    ScoutSuggestionSetApi,
    ScoutToolCatalogueApi,
    ScoutTrialComparisonApi,
    ScoutTrialComparisonArchiveRequestApi,
    ScoutTrialComparisonHistoryApi,
    ScoutTrialComparisonQueryApi,
    ScoutTrialComparisonRequestApi,
    ScoutTrialEvaluationApi,
    ScoutTrialEvaluationRequestApi,
    ScoutTrialHistoryApi,
    ScoutTrialLaunchApi,
    ScoutTrialResultApi,
    ScoutTrialSetupApi,
    ScoutTrialStartedApi,
    ScratchpadEntryApi,
    SignalReportApi,
    SignalReportArtefactApi,
    SignalReportArtefactLogCreateApi,
    SignalReportArtefactWriteApi,
    SignalReportArtefactWriteResponseApi,
    SignalReportBulkClaimRequestApi,
    SignalReportBulkClaimResponseApi,
    SignalReportBulkStateRequestApi,
    SignalReportBulkStateResponseApi,
    SignalReportCheckApi,
    SignalReportCheckReplacementApi,
    SignalReportClaimApi,
    SignalReportDeletionStatusApi,
    SignalReportFeedbackRequestApi,
    SignalReportFeedbackResponseApi,
    SignalReportFeedbackStateApi,
    SignalReportLeaveReviewersApi,
    SignalReportMergeRequestApi,
    SignalReportMergeResponseApi,
    SignalReportMetricRefreshRequestApi,
    SignalReportMetricRefreshResponseApi,
    SignalReportPriorityUpdateApi,
    SignalReportRefundRequestApi,
    SignalReportRefundResponseApi,
    SignalReportRefundSummaryResponseApi,
    SignalReportReingestionStatusApi,
    SignalReportSectionCountsApi,
    SignalReportSourceMetadataRequestApi,
    SignalReportSourceMetadataResponseApi,
    SignalReportStateRequestApi,
    SignalReportSuggestedReviewersArtefactApi,
    SignalReportTaskActionListResponseApi,
    SignalReportTaskActionRunRequestApi,
    SignalReportTaskActionRunResponseApi,
    SignalScoutConfigApi,
    SignalScoutConfigCreateApi,
    SignalScoutCreateApi,
    SignalScoutCreateResponseApi,
    SignalScoutEmissionApi,
    SignalScoutManualRunApi,
    SignalScoutManualRunRequestApi,
    SignalScoutPrecheckTestApi,
    SignalScoutPrecheckTestRequestApi,
    SignalScoutRunDetailApi,
    SignalScoutRunSummaryApi,
    SignalSourceConfigApi,
    SignalTeamConfigApi,
    SignalUserAutonomyConfigApi,
    SignalUserAutonomyConfigCreateApi,
    SignalsActivitySummaryMembersSearchParams,
    SignalsActivitySummaryVersionsRetrieveParams,
    SignalsAnomaliesInsightRetrieveParams,
    SignalsAnomaliesSearchRetrieveParams,
    SignalsMonthlyUsageParams,
    SignalsProcessingListParams,
    SignalsReportArtefactsListParams,
    SignalsReportChecksListParams,
    SignalsReportPrChecksParams,
    SignalsReportPrCommentsParams,
    SignalsReportPrReviewCommentDestroyParams,
    SignalsReportPrReviewCommentReactionDestroyParams,
    SignalsReportPrReviewCommentReactionsCreateParams,
    SignalsReportPrReviewCommentUpdateParams,
    SignalsReportPrReviewCommentsCreateParams,
    SignalsReportsAvailableReviewersRetrieve200,
    SignalsReportsAvailableReviewersRetrieveParams,
    SignalsReportsForMeRetrieveParams,
    SignalsReportsListParams,
    SignalsReportsPrCiStatusesParams,
    SignalsReportsSectionCountsRetrieveParams,
    SignalsScoutConfigListParams,
    SignalsScoutConfigSyncParams,
    SignalsScoutConfigTrialComparisonHistoryParams,
    SignalsScoutConfigTrialComparisonRetrieveParams,
    SignalsScoutConfigTrialEvaluationRetrieveParams,
    SignalsScoutConfigTrialHistoryParams,
    SignalsScoutConfigTrialResultParams,
    SignalsScoutConfigTrialSetupParams,
    SignalsScoutMembersListParams,
    SignalsScoutNotesListParams,
    SignalsScoutProjectProfileGetParams,
    SignalsScoutReportCheckListParams,
    SignalsScoutReportChecksListParams,
    SignalsScoutRunsFindingsSummaryParams,
    SignalsScoutRunsListParams,
    SignalsScoutRunsRecentEmissionsParams,
    SignalsScoutRunsRecentPerScoutParams,
    SignalsScoutScratchpadSearchParams,
    SignalsSourceConfigsListParams,
    SourceSpendApi,
    SpendOverviewApi,
    SubmitMonitoringResultRequestApi,
    SubmitMonitoringResultResponseApi,
} from './api.schemas'

// https://stackoverflow.com/questions/49579094/typescript-conditional-types-filter-out-readonly-properties-pick-only-requir/49579497#49579497
type IfEquals<X, Y, A = X, B = never> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? A : B

type WritableKeys<T> = {
    [P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, P>
}[keyof T]

type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
type DistributeReadOnlyOverUnions<T> = T extends any ? NonReadonly<T> : never

type Writable<T> = Pick<T, WritableKeys<T>>
type NonReadonly<T> = [T] extends [UnionToIntersection<T>]
    ? {
          [P in keyof Writable<T>]: T[P] extends object ? NonReadonly<NonNullable<T[P]>> : T[P]
      }
    : DistributeReadOnlyOverUnions<T>

export const getSignalsActivitySummaryListUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/activity_summary/`
}

/**
 * @summary Get your activity summary
 */
export const signalsActivitySummaryList = async (
    projectId: string,
    options?: RequestInit
): Promise<ActivitySummaryApi> => {
    return apiMutator<ActivitySummaryApi>(getSignalsActivitySummaryListUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsActivitySummaryVersionsRetrieveUrl = (
    projectId: string,
    params?: SignalsActivitySummaryVersionsRetrieveParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/activity_summary/versions/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/activity_summary/versions/`
}

/**
 * @summary List your activity summary versions
 */
export const signalsActivitySummaryVersionsRetrieve = async (
    projectId: string,
    params?: SignalsActivitySummaryVersionsRetrieveParams,
    options?: RequestInit
): Promise<ActivitySummaryVersionApi[]> => {
    return apiMutator<ActivitySummaryVersionApi[]>(getSignalsActivitySummaryVersionsRetrieveUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsActivitySummaryMembersSearchUrl = (
    projectId: string,
    params?: SignalsActivitySummaryMembersSearchParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/activity_summary_members/search/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/activity_summary_members/search/`
}

/**
 * Find the project members whose activity summary matches a topic, an object or a product, including people who only open the work and never edit it. Returns 404 when the search is not available for this project.
 * @summary Search member activity summaries
 */
export const signalsActivitySummaryMembersSearch = async (
    projectId: string,
    params?: SignalsActivitySummaryMembersSearchParams,
    options?: RequestInit
): Promise<ActivitySummarySearchResultApi> => {
    return apiMutator<ActivitySummarySearchResultApi>(getSignalsActivitySummaryMembersSearchUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsAnomaliesInsightRetrieveUrl = (
    projectId: string,
    params: SignalsAnomaliesInsightRetrieveParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/anomalies/insight/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/anomalies/insight/`
}

/**
 * Read-only anomaly rates of the saved trends insights that anomaly scoring checks.
 * @summary Get the scored anomaly history of an insight
 */
export const signalsAnomaliesInsightRetrieve = async (
    projectId: string,
    params: SignalsAnomaliesInsightRetrieveParams,
    options?: RequestInit
): Promise<AnomalyInsightResponseApi> => {
    return apiMutator<AnomalyInsightResponseApi>(getSignalsAnomaliesInsightRetrieveUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsAnomaliesSearchRetrieveUrl = (
    projectId: string,
    params?: SignalsAnomaliesSearchRetrieveParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/anomalies/search/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/anomalies/search/`
}

/**
 * Read-only anomaly rates of the saved trends insights that anomaly scoring checks.
 * @summary Search anomalous insight series
 */
export const signalsAnomaliesSearchRetrieve = async (
    projectId: string,
    params?: SignalsAnomaliesSearchRetrieveParams,
    options?: RequestInit
): Promise<AnomalySearchResponseApi> => {
    return apiMutator<AnomalySearchResponseApi>(getSignalsAnomaliesSearchRetrieveUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsConfigListUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/config/`
}

/**
 * Team-level signal autonomy config (singleton per team).
 *
 * GET  /signals/config/  → retrieve
 * POST /signals/config/  → update
 * @summary Read the project's signals config
 */
export const signalsConfigList = async (projectId: string, options?: RequestInit): Promise<SignalTeamConfigApi> => {
    return apiMutator<SignalTeamConfigApi>(getSignalsConfigListUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsConfigCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/config/`
}

/**
 * Partial update of the per-project singleton. Omitted fields keep their value.
 * @summary Update the project's signals config
 */
export const signalsConfigCreate = async (
    projectId: string,
    signalTeamConfigApi?: NonReadonly<SignalTeamConfigApi>,
    options?: RequestInit
): Promise<SignalTeamConfigApi> => {
    return apiMutator<SignalTeamConfigApi>(getSignalsConfigCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalTeamConfigApi),
    })
}

export const getSignalsInboxSummaryListUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/inbox_summary/`
}

export const signalsInboxSummaryList = async (projectId: string, options?: RequestInit): Promise<InboxSummaryApi> => {
    return apiMutator<InboxSummaryApi>(getSignalsInboxSummaryListUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsOnboardingListUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/onboarding/`
}

export const signalsOnboardingList = async (
    projectId: string,
    options?: RequestInit
): Promise<InboxOnboardingStateApi> => {
    return apiMutator<InboxOnboardingStateApi>(getSignalsOnboardingListUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsOnboardingCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/onboarding/`
}

export const signalsOnboardingCreate = async (
    projectId: string,
    inboxOnboardingDraftApi: InboxOnboardingDraftApi,
    options?: RequestInit
): Promise<InboxOnboardingStateApi> => {
    return apiMutator<InboxOnboardingStateApi>(getSignalsOnboardingCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(inboxOnboardingDraftApi),
    })
}

export const getSignalsOnboardingCompleteCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/onboarding/complete/`
}

export const signalsOnboardingCompleteCreate = async (
    projectId: string,
    inboxOnboardingDraftApi: InboxOnboardingDraftApi,
    options?: RequestInit
): Promise<InboxOnboardingStateApi> => {
    return apiMutator<InboxOnboardingStateApi>(getSignalsOnboardingCompleteCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(inboxOnboardingDraftApi),
    })
}

export const getSignalsOnboardingExposeCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/onboarding/expose/`
}

export const signalsOnboardingExposeCreate = async (
    projectId: string,
    options?: RequestInit
): Promise<InboxOnboardingStateApi> => {
    return apiMutator<InboxOnboardingStateApi>(getSignalsOnboardingExposeCreateUrl(projectId), {
        ...options,
        method: 'POST',
    })
}

export const getSignalsProcessingListUrl = (projectId: string, params?: SignalsProcessingListParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/processing/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/processing/`
}

/**
 * Return current processing state including pause status.
 */
export const signalsProcessingList = async (
    projectId: string,
    params?: SignalsProcessingListParams,
    options?: RequestInit
): Promise<PaginatedPauseStateResponseListApi> => {
    return apiMutator<PaginatedPauseStateResponseListApi>(getSignalsProcessingListUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsProcessingPauseUpdateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/processing/pause/`
}

/**
 * View and control signal processing pipeline state for a team.
 */
export const signalsProcessingPauseUpdate = async (
    projectId: string,
    pauseUntilRequestApi: PauseUntilRequestApi,
    options?: RequestInit
): Promise<PauseResponseApi> => {
    return apiMutator<PauseResponseApi>(getSignalsProcessingPauseUpdateUrl(projectId), {
        ...options,
        method: 'PUT',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(pauseUntilRequestApi),
    })
}

export const getSignalsProcessingPauseDestroyUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/processing/pause/`
}

/**
 * View and control signal processing pipeline state for a team.
 */
export const signalsProcessingPauseDestroy = async (
    projectId: string,
    options?: RequestInit
): Promise<PauseResponseApi> => {
    return apiMutator<PauseResponseApi>(getSignalsProcessingPauseDestroyUrl(projectId), {
        ...options,
        method: 'DELETE',
    })
}

export const getSignalsReportsListUrl = (projectId: string, params?: SignalsReportsListParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/reports/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/reports/`
}

export const signalsReportsList = async (
    projectId: string,
    params?: SignalsReportsListParams,
    options?: RequestInit
): Promise<PaginatedSignalReportListListApi> => {
    return apiMutator<PaginatedSignalReportListListApi>(getSignalsReportsListUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReportsCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/reports/`
}

/**
 * File a complete inbox report yourself, with the same validation and safety judge a scout report passes. The report surfaces at the status `actionability` implies, or is suppressed. It never starts an implementation run or opens a pull request on its own, now or after a later edit: start one from the report's actions. Safe to retry: a resend returns the first report with `idempotent_replay` true. Each person can file a limited number of reports per project per day.
 * @summary File an inbox report
 */
export const signalsReportsCreate = async (
    projectId: string,
    emitReportRequestApi: EmitReportRequestApi,
    options?: RequestInit
): Promise<EmitReportResponseApi> => {
    return apiMutator<EmitReportResponseApi>(getSignalsReportsCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(emitReportRequestApi),
    })
}

export const getSignalsReportsRetrieveUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/`
}

export const signalsReportsRetrieve = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<SignalReportApi> => {
    return apiMutator<SignalReportApi>(getSignalsReportsRetrieveUrl(projectId, id), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReportsPartialUpdateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/`
}

/**
 * Edit the human-facing title and/or summary (description) of a signal report, addressed by id. Both fields are optional — supply only the ones you want to change; at least one is required. Every other report field (status, weights, judgments) is managed by the signals pipeline and cannot be set here. Returns the full updated report.
 * @summary Edit a report's title or summary
 */
export const signalsReportsPartialUpdate = async (
    projectId: string,
    id: string,
    patchedSignalReportContentUpdateApi?: PatchedSignalReportContentUpdateApi,
    options?: RequestInit
): Promise<SignalReportApi> => {
    return apiMutator<SignalReportApi>(getSignalsReportsPartialUpdateUrl(projectId, id), {
        ...options,
        method: 'PATCH',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(patchedSignalReportContentUpdateApi),
    })
}

export const getSignalsReportsDestroyUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/`
}

/**
 * Soft-delete a report and its signals via the deletion workflow.
 * @summary Delete a signal report
 */
export const signalsReportsDestroy = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<SignalReportDeletionStatusApi> => {
    return apiMutator<SignalReportDeletionStatusApi>(getSignalsReportsDestroyUrl(projectId, id), {
        ...options,
        method: 'DELETE',
    })
}

export const getSignalsReportsActionsListUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/actions/`
}

/**
 * List the actions on this report that start an agent run, read from the report's current state. `get_it_merged` is available only while the report has an open, approved pull request. `make_it_green` is available only while CI fails on the report's open pull request. `suggested_prompt` has one entry per prompt the report suggests. Start one with the run endpoint.
 * @summary List the report actions that start an agent run
 */
export const signalsReportsActionsList = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<SignalReportTaskActionListResponseApi> => {
    return apiMutator<SignalReportTaskActionListResponseApi>(getSignalsReportsActionsListUrl(projectId, id), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReportsActionsRunCreateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/actions/run/`
}

/**
 * Create a task linked to the report and start its first run in the background, with the instructions the inbox uses for the same action. `ask` sends your own message with the framing of the inbox's Ask AI. The run shows in the report's runs and counts toward the report's task limit. Nobody can answer questions in a background run, so the agent writes a note to the report's work log when it needs a decision.
 * @summary Start a report action as a background agent run
 */
export const signalsReportsActionsRunCreate = async (
    projectId: string,
    id: string,
    signalReportTaskActionRunRequestApi: SignalReportTaskActionRunRequestApi,
    options?: RequestInit
): Promise<SignalReportTaskActionRunResponseApi> => {
    return apiMutator<SignalReportTaskActionRunResponseApi>(getSignalsReportsActionsRunCreateUrl(projectId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalReportTaskActionRunRequestApi),
    })
}

export const getSignalsReportsClaimUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/claim/`
}

/**
 * Start or update work for the current user, internal task, or external agent. Supply claim_id to resume, pull_requests to add PRs, takeover=true to explicitly take ownership, or release=true to end ownership while preserving work history and PR links. Adding PRs needs task:write as well as inbox:write.
 * @summary Claim or release a signal report
 */
export const signalsReportsClaim = async (
    projectId: string,
    id: string,
    signalReportClaimApi?: SignalReportClaimApi,
    options?: RequestInit
): Promise<SignalReportApi> => {
    return apiMutator<SignalReportApi>(getSignalsReportsClaimUrl(projectId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalReportClaimApi),
    })
}

export const getSignalsReportsFeedbackCreateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/feedback/`
}

/**
 * Record the thumbs rating at the end of a report, with an optional note. For browser-session requests the rating is persisted as a per-person report action, which counts as consumption evidence for the scout that authored the report (scouts whose output nobody consumes are eventually paused); requests authenticated any other way record no action. When a note is present and the report was authored by a scout, the note is also forwarded to that scout as a steering note it reads on its next run; for any other report there is nothing to steer. The report's state is never changed.
 * @summary Leave feedback on a report
 */
export const signalsReportsFeedbackCreate = async (
    projectId: string,
    id: string,
    signalReportFeedbackRequestApi: SignalReportFeedbackRequestApi,
    options?: RequestInit
): Promise<SignalReportFeedbackResponseApi> => {
    return apiMutator<SignalReportFeedbackResponseApi>(getSignalsReportsFeedbackCreateUrl(projectId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalReportFeedbackRequestApi),
    })
}

export const getSignalsReportsFeedbackStateRetrieveUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/feedback_state/`
}

export const signalsReportsFeedbackStateRetrieve = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<SignalReportFeedbackStateApi> => {
    return apiMutator<SignalReportFeedbackStateApi>(getSignalsReportsFeedbackStateRetrieveUrl(projectId, id), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReportsMergeCreateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/merge/`
}

/**
 * Fold one or more duplicate reports into this report, which survives. The sources' signals, work-log artefacts, pull requests, task runs and checks move onto the survivor, the survivor's signal counters take on theirs, and each source is archived with a 'duplicate of' link back to the survivor. A source's open pull request stays open, because the survivor holds it after the move. Pick the survivor deliberately: prefer the older report, and prefer the one with an open implementation PR or an active claim. Any active claim on a source is released, so re-claim the survivor if you were working on one. Titles and summaries are not combined, so edit it afterwards if it needs a rewrite. A merged report keeps its URL but cannot be restored, because its signals now belong to the survivor.
 * @summary Merge duplicate reports into this one
 */
export const signalsReportsMergeCreate = async (
    projectId: string,
    id: string,
    signalReportMergeRequestApi: SignalReportMergeRequestApi,
    options?: RequestInit
): Promise<SignalReportMergeResponseApi> => {
    return apiMutator<SignalReportMergeResponseApi>(getSignalsReportsMergeCreateUrl(projectId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalReportMergeRequestApi),
    })
}

export const getSignalsReportPrChecksUrl = (projectId: string, id: string, params?: SignalsReportPrChecksParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/reports/${id}/pr_checks/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/reports/${id}/pr_checks/`
}

/**
 * Fetch the CI status (GitHub Actions check runs and legacy commit statuses) of the pull request attached to the report, via the team's GitHub integration.
 * @summary Fetch CI checks for a report's implementation PR
 */
export const signalsReportPrChecks = async (
    projectId: string,
    id: string,
    params?: SignalsReportPrChecksParams,
    options?: RequestInit
): Promise<PullRequestChecksResponseApi> => {
    return apiMutator<PullRequestChecksResponseApi>(getSignalsReportPrChecksUrl(projectId, id, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReportPrCommentsUrl = (
    projectId: string,
    id: string,
    params?: SignalsReportPrCommentsParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/reports/${id}/pr_comments/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/reports/${id}/pr_comments/`
}

/**
 * Fetch the pull request's conversation comments and inline review comments, merged chronologically, via the team's GitHub integration.
 * @summary Fetch comments for a report's implementation PR
 */
export const signalsReportPrComments = async (
    projectId: string,
    id: string,
    params?: SignalsReportPrCommentsParams,
    options?: RequestInit
): Promise<PullRequestCommentsResponseApi> => {
    return apiMutator<PullRequestCommentsResponseApi>(getSignalsReportPrCommentsUrl(projectId, id, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReportPrReviewCommentsCreateUrl = (
    projectId: string,
    id: string,
    params?: SignalsReportPrReviewCommentsCreateParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/reports/${id}/pr_review_comments/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/reports/${id}/pr_review_comments/`
}

/**
 * Post an inline review comment on the report's implementation pull request, attributed to the requesting user's own GitHub identity via their personal GitHub connection. Either replies to an existing thread (`in_reply_to`) or starts a new thread on a diff line (`path` + `line`).
 * @summary Post an inline review comment on a report's implementation PR
 */
export const signalsReportPrReviewCommentsCreate = async (
    projectId: string,
    id: string,
    pullRequestReviewCommentCreateApi: PullRequestReviewCommentCreateApi,
    params?: SignalsReportPrReviewCommentsCreateParams,
    options?: RequestInit
): Promise<PullRequestReviewCommentCreateResponseApi> => {
    return apiMutator<PullRequestReviewCommentCreateResponseApi>(
        getSignalsReportPrReviewCommentsCreateUrl(projectId, id, params),
        {
            ...options,
            method: 'POST',
            headers: { 'Content-Type': 'application/json', ...options?.headers },
            body: JSON.stringify(pullRequestReviewCommentCreateApi),
        }
    )
}

export const getSignalsReportPrReviewCommentUpdateUrl = (
    projectId: string,
    id: string,
    commentId: string,
    params?: SignalsReportPrReviewCommentUpdateParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/reports/${id}/pr_review_comments/${commentId}/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/reports/${id}/pr_review_comments/${commentId}/`
}

/**
 * @summary Edit one of the requesting user's own review comments
 */
export const signalsReportPrReviewCommentUpdate = async (
    projectId: string,
    id: string,
    commentId: string,
    patchedPullRequestReviewCommentUpdateApi?: PatchedPullRequestReviewCommentUpdateApi,
    params?: SignalsReportPrReviewCommentUpdateParams,
    options?: RequestInit
): Promise<PullRequestReviewCommentCreateResponseApi> => {
    return apiMutator<PullRequestReviewCommentCreateResponseApi>(
        getSignalsReportPrReviewCommentUpdateUrl(projectId, id, commentId, params),
        {
            ...options,
            method: 'PATCH',
            headers: { 'Content-Type': 'application/json', ...options?.headers },
            body: JSON.stringify(patchedPullRequestReviewCommentUpdateApi),
        }
    )
}

export const getSignalsReportPrReviewCommentDestroyUrl = (
    projectId: string,
    id: string,
    commentId: string,
    params?: SignalsReportPrReviewCommentDestroyParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/reports/${id}/pr_review_comments/${commentId}/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/reports/${id}/pr_review_comments/${commentId}/`
}

/**
 * @summary Delete one of the requesting user's own review comments
 */
export const signalsReportPrReviewCommentDestroy = async (
    projectId: string,
    id: string,
    commentId: string,
    params?: SignalsReportPrReviewCommentDestroyParams,
    options?: RequestInit
): Promise<void> => {
    return apiMutator<void>(getSignalsReportPrReviewCommentDestroyUrl(projectId, id, commentId, params), {
        ...options,
        method: 'DELETE',
    })
}

export const getSignalsReportPrReviewCommentReactionsCreateUrl = (
    projectId: string,
    id: string,
    commentId: string,
    params?: SignalsReportPrReviewCommentReactionsCreateParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/reports/${id}/pr_review_comments/${commentId}/reactions/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/reports/${id}/pr_review_comments/${commentId}/reactions/`
}

/**
 * @summary React to a review comment as the requesting user
 */
export const signalsReportPrReviewCommentReactionsCreate = async (
    projectId: string,
    id: string,
    commentId: string,
    pullRequestReviewCommentReactionCreateApi: PullRequestReviewCommentReactionCreateApi,
    params?: SignalsReportPrReviewCommentReactionsCreateParams,
    options?: RequestInit
): Promise<PullRequestReviewCommentReactionCreateResponseApi> => {
    return apiMutator<PullRequestReviewCommentReactionCreateResponseApi>(
        getSignalsReportPrReviewCommentReactionsCreateUrl(projectId, id, commentId, params),
        {
            ...options,
            method: 'POST',
            headers: { 'Content-Type': 'application/json', ...options?.headers },
            body: JSON.stringify(pullRequestReviewCommentReactionCreateApi),
        }
    )
}

export const getSignalsReportPrReviewCommentReactionDestroyUrl = (
    projectId: string,
    id: string,
    commentId: string,
    reactionId: string,
    params?: SignalsReportPrReviewCommentReactionDestroyParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/reports/${id}/pr_review_comments/${commentId}/reactions/${reactionId}/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/reports/${id}/pr_review_comments/${commentId}/reactions/${reactionId}/`
}

/**
 * @summary Remove one of the requesting user's own reactions from a review comment
 */
export const signalsReportPrReviewCommentReactionDestroy = async (
    projectId: string,
    id: string,
    commentId: string,
    reactionId: string,
    params?: SignalsReportPrReviewCommentReactionDestroyParams,
    options?: RequestInit
): Promise<void> => {
    return apiMutator<void>(
        getSignalsReportPrReviewCommentReactionDestroyUrl(projectId, id, commentId, reactionId, params),
        {
            ...options,
            method: 'DELETE',
        }
    )
}

export const getSignalsReportsPriorityUpdateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/priority/`
}

/**
 * Append an attributed priority correction, preserving the previous judgment for future learning.
 * @summary Change a report's priority
 */
export const signalsReportsPriorityUpdate = async (
    projectId: string,
    id: string,
    signalReportPriorityUpdateApi: SignalReportPriorityUpdateApi,
    options?: RequestInit
): Promise<SignalReportApi> => {
    return apiMutator<SignalReportApi>(getSignalsReportsPriorityUpdateUrl(projectId, id), {
        ...options,
        method: 'PUT',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalReportPriorityUpdateApi),
    })
}

export const getSignalsReportsRefundCreateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/refund/`
}

/**
 * Refund the flat charge for this report's implementation PR and archive the report. Refunds auto-approve: the charge is either excluded from usage before it is ever reported to billing (refund on the same UTC day as the PR run) or returned as a Stripe customer-balance credit on the next invoice. A refunded PR does not count toward the free monthly PR allowance. One refund per report, ever — repeat calls return the existing refund with already_refunded=true. The report is archived as part of the refund (a resolved report stays resolved) and can't be restored afterwards.
 * @summary Refund a report's implementation PR
 */
export const signalsReportsRefundCreate = async (
    projectId: string,
    id: string,
    signalReportRefundRequestApi: SignalReportRefundRequestApi,
    options?: RequestInit
): Promise<SignalReportRefundResponseApi> => {
    return apiMutator<SignalReportRefundResponseApi>(getSignalsReportsRefundCreateUrl(projectId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalReportRefundRequestApi),
    })
}

export const getSignalsReportsReingestCreateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/reingest/`
}

/**
 * Re-ingest a report's signals (same team access as other report actions).
 * @summary Re-ingest a report's signals
 */
export const signalsReportsReingestCreate = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<SignalReportReingestionStatusApi> => {
    return apiMutator<SignalReportReingestionStatusApi>(getSignalsReportsReingestCreateUrl(projectId, id), {
        ...options,
        method: 'POST',
    })
}

export const getSignalsReportsReviewersUpdateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/reviewers/`
}

/**
 * Apply a human reviewer edit, including on reports without a reviewer artefact.
 * @summary Set a report's suggested reviewers
 */
export const signalsReportsReviewersUpdate = async (
    projectId: string,
    id: string,
    signalReportArtefactWriteApi: SignalReportArtefactWriteApi,
    options?: RequestInit
): Promise<SignalReportSuggestedReviewersArtefactApi> => {
    return apiMutator<SignalReportSuggestedReviewersArtefactApi>(getSignalsReportsReviewersUpdateUrl(projectId, id), {
        ...options,
        method: 'PUT',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalReportArtefactWriteApi),
    })
}

export const getSignalsReportsReviewersMeCreateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/reviewers/me/`
}

/**
 * Take the calling user off this report's suggested reviewers, and record why. The other reviewers stay, and the report stays open. Succeeds whether or not the caller was on the list.
 * @summary Step off a report's suggested reviewers, with a reason
 */
export const signalsReportsReviewersMeCreate = async (
    projectId: string,
    id: string,
    signalReportLeaveReviewersApi?: SignalReportLeaveReviewersApi,
    options?: RequestInit
): Promise<void> => {
    return apiMutator<void>(getSignalsReportsReviewersMeCreateUrl(projectId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalReportLeaveReviewersApi),
    })
}

export const getSignalsReportsReviewersMeDestroyUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/reviewers/me/`
}

/**
 * Take the calling user off this report's suggested reviewers, leaving the other reviewers as they are. The report itself is untouched: it stays open for whoever is left, and for the project. Succeeds whether or not the caller was on the list. POST to the same path to say why.
 * @summary Step off a report's suggested reviewers
 */
export const signalsReportsReviewersMeDestroy = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<void> => {
    return apiMutator<void>(getSignalsReportsReviewersMeDestroyUrl(projectId, id), {
        ...options,
        method: 'DELETE',
    })
}

export const getSignalsReportsSignalsRetrieveUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/signals/`
}

/**
 * Fetch all signals for a report from ClickHouse, including full metadata.
 * @summary List a report's signals
 */
export const signalsReportsSignalsRetrieve = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<ReportSignalsResponseApi> => {
    return apiMutator<ReportSignalsResponseApi>(getSignalsReportsSignalsRetrieveUrl(projectId, id), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReportSpendUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/spend/`
}

export const signalsReportSpend = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<ReportSpendApi> => {
    return apiMutator<ReportSpendApi>(getSignalsReportSpendUrl(projectId, id), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReportsStateCreateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/state/`
}

/**
 * Transition a report to a new state. The model validates allowed transitions, except that a
 * verdict the report already holds (dismissing a suppressed report, resolving a resolved one)
 * is a 200 that records the dismissal feedback without touching the status.
 *
 * The request body is validated by SignalReportStateRequestSerializer — only the
 * fields it declares (state, dismissal_reason, dismissal_note, corrected_repository,
 * snooze_for) are read, and only snooze_for is ever forwarded to transition_to. Any
 * other key is ignored, so internal transition_to kwargs (reset_weight, error, ...)
 * can't be injected.
 *
 * Body: {
 *     "state": "suppressed" | "potential" | "resolved",
 *     # Optional dismissal feedback (honored when state == "suppressed", "potential", or "resolved"):
 *     "dismissal_reason": "<canonical reason code, see SIGNAL_REPORT_DISMISSAL_REASON_CHOICES>",
 *     "dismissal_note": "free-form text",
 *     # Optional, only allowed with dismissal_reason == "wrong_repo":
 *     "corrected_repository": "owner/repo the report should have targeted",
 *     # Optional, only honored for state == "potential":
 *     "snooze_for": <number of additional signals before re-promotion>,
 * }
 */
export const signalsReportsStateCreate = async (
    projectId: string,
    id: string,
    signalReportStateRequestApi: SignalReportStateRequestApi,
    options?: RequestInit
): Promise<SignalReportApi> => {
    return apiMutator<SignalReportApi>(getSignalsReportsStateCreateUrl(projectId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalReportStateRequestApi),
    })
}

export const getSignalsReportsViewedCreateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${id}/viewed/`
}

/**
 * Record that the caller opened this report's detail view. One row per person per report is kept (repeat views bump a counter), and the record counts as consumption evidence for the scout that authored the report — scouts whose reports nobody consumes are eventually paused. Intended as fire-and-forget from the inbox UI when a person opens a report. Only browser-session requests leave a record; a call with any other credential (personal API key, OAuth token) returns 204 but records nothing.
 * @summary Record that a person viewed a report
 */
export const signalsReportsViewedCreate = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<void> => {
    return apiMutator<void>(getSignalsReportsViewedCreateUrl(projectId, id), {
        ...options,
        method: 'POST',
    })
}

export const getSignalsReportArtefactsListUrl = (
    projectId: string,
    reportId: string,
    params?: SignalsReportArtefactsListParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/reports/${reportId}/artefacts/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/reports/${reportId}/artefacts/`
}

/**
 * List every artefact on a report — the full work log: signal findings (the evidence behind the report), status judgments (safety / actionability / priority, repo selection, suggested reviewers — the newest row of each status type is canonical), and log entries (code references, commits, task runs, notes). `suggested_reviewers` content is enriched with PostHog user info at read time. `ranking_score` content keeps only the head fields of each model's metadata; get the artefact by id for the full metadata.
 * @summary List a report's artefacts
 */
export const signalsReportArtefactsList = async (
    projectId: string,
    reportId: string,
    params?: SignalsReportArtefactsListParams,
    options?: RequestInit
): Promise<PaginatedSignalReportArtefactListApi> => {
    return apiMutator<PaginatedSignalReportArtefactListApi>(
        getSignalsReportArtefactsListUrl(projectId, reportId, params),
        {
            ...options,
            method: 'GET',
        }
    )
}

export const getSignalsReportArtefactsCreateUrl = (projectId: string, reportId: string) => {
    return `/api/projects/${projectId}/signals/reports/${reportId}/artefacts/`
}

/**
 * Append an artefact to a report (see artefact_type for the writable types). Everything is append-only: log entries (code reference, commit, task run, note) accumulate, while status types (safety / actionability / priority judgments, repo selection, suggested reviewers, channel assignments) are latest-wins — appending a new version supersedes the previous one as the report's canonical status. Content is validated against the type's schema.
 * @summary Append an artefact to a report
 */
export const signalsReportArtefactsCreate = async (
    projectId: string,
    reportId: string,
    signalReportArtefactLogCreateApi: SignalReportArtefactLogCreateApi,
    options?: RequestInit
): Promise<SignalReportArtefactWriteResponseApi> => {
    return apiMutator<SignalReportArtefactWriteResponseApi>(getSignalsReportArtefactsCreateUrl(projectId, reportId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalReportArtefactLogCreateApi),
    })
}

export const getSignalsReportArtefactsRetrieveUrl = (projectId: string, reportId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${reportId}/artefacts/${id}/`
}

/**
 * Get one artefact by id, content parsed (and reviewers enriched) the same way as the list. A `ranking_score` keeps its full model metadata.
 * @summary Get a single artefact
 */
export const signalsReportArtefactsRetrieve = async (
    projectId: string,
    reportId: string,
    id: string,
    options?: RequestInit
): Promise<SignalReportArtefactApi> => {
    return apiMutator<SignalReportArtefactApi>(getSignalsReportArtefactsRetrieveUrl(projectId, reportId, id), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReportArtefactsPartialUpdateUrl = (projectId: string, reportId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${reportId}/artefacts/${id}/`
}

/**
 * Replace the content of an existing artefact, addressed by id. The new content is validated against the artefact's type schema. Editing the latest row of a status type changes the report's canonical status (latest-wins); to re-assess while keeping history, append a new artefact instead. Attribution is creation-time only — edits don't reassign it.
 * @summary Replace an artefact's content
 */
export const signalsReportArtefactsPartialUpdate = async (
    projectId: string,
    reportId: string,
    id: string,
    patchedSignalReportArtefactLogUpdateApi?: PatchedSignalReportArtefactLogUpdateApi,
    options?: RequestInit
): Promise<SignalReportArtefactWriteResponseApi> => {
    return apiMutator<SignalReportArtefactWriteResponseApi>(
        getSignalsReportArtefactsPartialUpdateUrl(projectId, reportId, id),
        {
            ...options,
            method: 'PATCH',
            headers: { 'Content-Type': 'application/json', ...options?.headers },
            body: JSON.stringify(patchedSignalReportArtefactLogUpdateApi),
        }
    )
}

export const getSignalsReportArtefactsDestroyUrl = (projectId: string, reportId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${reportId}/artefacts/${id}/`
}

/**
 * Delete an artefact, addressed by id. Deleting the latest row of a status type reverts the report's canonical status to the previous version (latest-wins over what remains). `task_run` artefacts are an append-only work log and cannot be deleted. Neither can the types this API cannot write, which the pipeline owns: `autostart_skip`, `check_authoring`, `check_cancelled`, `check_expired`, `check_observation`, `check_result`, `check_scheduled`, `code_review`, `impact_measurement_plan`, `implementation_decision`, `implementation_dispatch`, `implementation_handover`, `implementation_replacement`, `pr_owner_assignment`, `pull_request`, `ranking_score`, `report_link`, `reviewer_corrections`, `scout_note_left`, `source_issue`, `summary_change`, `task_run`, `title_change`, `video_segment`, `work_claim`, `work_release`.
 * @summary Delete an artefact
 */
export const signalsReportArtefactsDestroy = async (
    projectId: string,
    reportId: string,
    id: string,
    options?: RequestInit
): Promise<void> => {
    return apiMutator<void>(getSignalsReportArtefactsDestroyUrl(projectId, reportId, id), {
        ...options,
        method: 'DELETE',
    })
}

export const getSignalsReportArtefactsDiffUrl = (projectId: string, reportId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${reportId}/artefacts/${id}/diff/`
}

/**
 * Fetch the unified diff for a `commit` artefact via the team's GitHub integration. A commit linked to a report pull request uses GitHub's durable pull request diff. A commit without that link compares the branch's current tip with the default branch.
 * @summary Fetch the diff for a commit artefact
 */
export const signalsReportArtefactsDiff = async (
    projectId: string,
    reportId: string,
    id: string,
    options?: RequestInit
): Promise<CommitDiffResponseApi> => {
    return apiMutator<CommitDiffResponseApi>(getSignalsReportArtefactsDiffUrl(projectId, reportId, id), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReportChecksListUrl = (
    projectId: string,
    reportId: string,
    params?: SignalsReportChecksListParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/reports/${reportId}/checks/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/reports/${reportId}/checks/`
}

/**
 * List the forward-looking checks on a report. A check says what must stay true after the report was acted on, and the coordinator records each verdict as a `check_result` artefact on the report.
 * @summary List a report's checks
 */
export const signalsReportChecksList = async (
    projectId: string,
    reportId: string,
    params?: SignalsReportChecksListParams,
    options?: RequestInit
): Promise<PaginatedSignalReportCheckListApi> => {
    return apiMutator<PaginatedSignalReportCheckListApi>(getSignalsReportChecksListUrl(projectId, reportId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReportChecksRetrieveUrl = (projectId: string, reportId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${reportId}/checks/${id}/`
}

/**
 * Checks attached to a signal report: read, approve, replace metrics, and cancel.
 *
 * There is no create here. A check is authored by a scout run or by the research pipeline, both
 * through `report_check_authoring.create_check`. An `agent` check puts its author's prose in front
 * of a privileged scout run, and `task:write` does not authorize that, so no caller-facing
 * endpoint accepts one. Anyone who can read the report can read its checks, and a person can
 * still stop one.
 *
 * There is no in-place update: a check is a claim about the future, and editing its threshold
 * after a result would make the recorded verdict unreadable. Replacing an open metric check
 * cancels the old row and creates a new one in one transaction.
 * @summary Get a single check
 */
export const signalsReportChecksRetrieve = async (
    projectId: string,
    reportId: string,
    id: string,
    options?: RequestInit
): Promise<SignalReportCheckApi> => {
    return apiMutator<SignalReportCheckApi>(getSignalsReportChecksRetrieveUrl(projectId, reportId, id), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReportChecksDestroyUrl = (projectId: string, reportId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${reportId}/checks/${id}/`
}

/**
 * Stop a check that is still open — active, or pending its report resolving. Its recorded results stay on the report.
 * @summary Cancel a check
 */
export const signalsReportChecksDestroy = async (
    projectId: string,
    reportId: string,
    id: string,
    options?: RequestInit
): Promise<SignalReportCheckApi> => {
    return apiMutator<SignalReportCheckApi>(getSignalsReportChecksDestroyUrl(projectId, reportId, id), {
        ...options,
        method: 'DELETE',
    })
}

export const getSignalsReportChecksApproveCreateUrl = (projectId: string, reportId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${reportId}/checks/${id}/approve/`
}

/**
 * Record a person's quality signal. Approval does not affect scheduling or execution.
 * @summary Approve a follow-up check
 */
export const signalsReportChecksApproveCreate = async (
    projectId: string,
    reportId: string,
    id: string,
    options?: RequestInit
): Promise<SignalReportCheckApi> => {
    return apiMutator<SignalReportCheckApi>(getSignalsReportChecksApproveCreateUrl(projectId, reportId, id), {
        ...options,
        method: 'POST',
    })
}

export const getSignalsReportChecksReplaceCreateUrl = (projectId: string, reportId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reports/${reportId}/checks/${id}/replace/`
}

/**
 * Atomically replace an open agent or metric check with a metric check. The old check stays live if the new one is invalid.
 * @summary Replace a follow-up check with a metric
 */
export const signalsReportChecksReplaceCreate = async (
    projectId: string,
    reportId: string,
    id: string,
    signalReportCheckReplacementApi: SignalReportCheckReplacementApi,
    options?: RequestInit
): Promise<SignalReportCheckApi> => {
    return apiMutator<SignalReportCheckApi>(getSignalsReportChecksReplaceCreateUrl(projectId, reportId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalReportCheckReplacementApi),
    })
}

export const getSignalsReportsAvailableReviewersRetrieveUrl = (
    projectId: string,
    params?: SignalsReportsAvailableReviewersRetrieveParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/reports/available_reviewers/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/reports/available_reviewers/`
}

/**
 * @summary List the org members who can be suggested as reviewers
 */
export const signalsReportsAvailableReviewersRetrieve = async (
    projectId: string,
    params?: SignalsReportsAvailableReviewersRetrieveParams,
    options?: RequestInit
): Promise<SignalsReportsAvailableReviewersRetrieve200> => {
    return apiMutator<SignalsReportsAvailableReviewersRetrieve200>(
        getSignalsReportsAvailableReviewersRetrieveUrl(projectId, params),
        {
            ...options,
            method: 'GET',
        }
    )
}

export const getSignalsReportsBulkStateCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/reports/bulk-state/`
}

/**
 * Transition many reports to a new state in one call.
 *
 * Each id is processed independently: a report whose transition isn't allowed from its
 * current status is reported as `skipped` (a 409 on the single-report endpoint) and the
 * rest still go through. Returns one result per requested id (in request order, after
 * de-duplication) plus per-outcome counts. The whole call is 200 even on partial failure —
 * inspect `results` / the counts to see what happened.
 */
export const signalsReportsBulkStateCreate = async (
    projectId: string,
    signalReportBulkStateRequestApi: SignalReportBulkStateRequestApi,
    options?: RequestInit
): Promise<SignalReportBulkStateResponseApi> => {
    return apiMutator<SignalReportBulkStateResponseApi>(getSignalsReportsBulkStateCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalReportBulkStateRequestApi),
    })
}

export const getSignalsReportsBulkClaimUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/reports/bulk_claim/`
}

/**
 * Claim many reports for the current user, internal task, or external agent in one call. Each id is claimed independently, and the call is 200 even when some claims are refused: inspect `results` and the counts. Use the single-report claim endpoint to release a claim or to add pull requests.
 * @summary Claim many signal reports
 */
export const signalsReportsBulkClaim = async (
    projectId: string,
    signalReportBulkClaimRequestApi: SignalReportBulkClaimRequestApi,
    options?: RequestInit
): Promise<SignalReportBulkClaimResponseApi> => {
    return apiMutator<SignalReportBulkClaimResponseApi>(getSignalsReportsBulkClaimUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalReportBulkClaimRequestApi),
    })
}

export const getSignalsReportsForMeRetrieveUrl = (projectId: string, params?: SignalsReportsForMeRetrieveParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/reports/for_me/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/reports/for_me/`
}

/**
 * Your open inbox reports, ranked for you by one language model call over your activity summary, the reports that need you and the ranking model's predictions. Each entry has a reason and a compact report. The request never waits on the model. By default it returns the last stored list quickly, and `checked_at` says how current it is. Pass `max_age_minutes` to check an older list against every candidate report, which can take some seconds. `refresh`, `focus` and your first request start a background build and set `building: true`. With no stored list, the request returns your reports in inbox order with `fallback_reason: building`. Pass `wait_seconds` to wait a short time for the new list. Only the user the list is about can read it.
 * @summary Get your personal ranked inbox
 */
export const signalsReportsForMeRetrieve = async (
    projectId: string,
    params?: SignalsReportsForMeRetrieveParams,
    options?: RequestInit
): Promise<PersonalRankingApi> => {
    return apiMutator<PersonalRankingApi>(getSignalsReportsForMeRetrieveUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReportsPrCiStatusesUrl = (projectId: string, params: SignalsReportsPrCiStatusesParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/reports/pr_ci_statuses/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/reports/pr_ci_statuses/`
}

/**
 * Resolve the coarse CI rollup of the pull requests several reports opened, so a list of reports can show which pull requests are red without opening each report. One GitHub call covers the whole batch, and the answers are cached briefly and shared across callers. A report is left out when it has no open implementation pull request, and also when GitHub could not answer for it (no integration reaches the repository, a rate limit, an upstream failure), so a caller shows no CI state for it rather than an error. For the individual checks behind the rollup, use `pr_checks`.
 * @summary Fetch CI status for several reports' implementation PRs
 */
export const signalsReportsPrCiStatuses = async (
    projectId: string,
    params: SignalsReportsPrCiStatusesParams,
    options?: RequestInit
): Promise<PullRequestCiStatusesResponseApi> => {
    return apiMutator<PullRequestCiStatusesResponseApi>(getSignalsReportsPrCiStatusesUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReportsRankingOutcomesListUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/reports/ranking_outcomes/`
}

/**
 * What each public outcome of the served ranking model predicts, with its horizon, cohort, base rate and readability from the model that scored this project's reports. Users who cannot see the ranking model get status not_available and no outcomes.
 * @summary List the ranking model's public outcomes
 */
export const signalsReportsRankingOutcomesList = async (
    projectId: string,
    options?: RequestInit
): Promise<RankingOutcomesResponseApi> => {
    return apiMutator<RankingOutcomesResponseApi>(getSignalsReportsRankingOutcomesListUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReportsReadStateCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/reports/read_state/`
}

export const signalsReportsReadStateCreate = async (
    projectId: string,
    reportReadStateRequestApi: ReportReadStateRequestApi,
    options?: RequestInit
): Promise<ReportReadStateResponseApi> => {
    return apiMutator<ReportReadStateResponseApi>(getSignalsReportsReadStateCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(reportReadStateRequestApi),
    })
}

export const getSignalsReportsRefreshMetricsCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/reports/refresh_metrics/`
}

/**
 * Re-run the stored metric queries of the given reports through the query cache and save the newest values as their snapshots. Call it when a person opens the inbox list or a report, with the ids on screen. Report titles and summaries are point-in-time text and never change here; only value, value_at, and series do, and legacy comparisons are cleared. A snapshot measured in the last 15 minutes is served as is. Each call runs at most 40 source series inside a 20-second budget, row metrics first; the rest keep their previous snapshot until the next open. Returns snapshot-only metrics for every requested report the caller can read whose status is ready or pending_input. A report in any other status is left out of the response, and its saved snapshots stay as they are.
 * @summary Refresh the saved metric snapshots of the reports on screen
 */
export const signalsReportsRefreshMetricsCreate = async (
    projectId: string,
    signalReportMetricRefreshRequestApi: SignalReportMetricRefreshRequestApi,
    options?: RequestInit
): Promise<SignalReportMetricRefreshResponseApi> => {
    return apiMutator<SignalReportMetricRefreshResponseApi>(getSignalsReportsRefreshMetricsCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalReportMetricRefreshRequestApi),
    })
}

export const getSignalsReportsRefundSummaryRetrieveUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/reports/refund-summary/`
}

/**
 * Aggregate credited-path refunds across the whole organization for the current billing period — counts only, no per-team detail. The billing usage widget needs this because billing usage is org-wide while reports (and their refunds) are team-scoped: subtract the refunded credits from billing usage to show the net PR count. Excluded-path refunds never reach billing usage, so no adjustment is needed for them. Also carries the org's live billable credits for the period (billing's recorded usage lags by up to a day), so the widget can count just-created PRs and react to same-day refunds.
 * @summary Summarize credited PR refunds for the billing period
 */
export const signalsReportsRefundSummaryRetrieve = async (
    projectId: string,
    options?: RequestInit
): Promise<SignalReportRefundSummaryResponseApi> => {
    return apiMutator<SignalReportRefundSummaryResponseApi>(getSignalsReportsRefundSummaryRetrieveUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReportsSectionCountsRetrieveUrl = (
    projectId: string,
    params?: SignalsReportsSectionCountsRetrieveParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/reports/section_counts/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/reports/section_counts/`
}

/**
 * Count the ready reports with and without an implementation pull request, in one query. Accepts the list's filters, so each count matches a `count_only` list request with `status=ready` and the matching `has_implementation_pr`. Rejects `status`, `has_implementation_pr`, `include_all_statuses` and `view`, because the counts set those.
 */
export const signalsReportsSectionCountsRetrieve = async (
    projectId: string,
    params?: SignalsReportsSectionCountsRetrieveParams,
    options?: RequestInit
): Promise<SignalReportSectionCountsApi> => {
    return apiMutator<SignalReportSectionCountsApi>(getSignalsReportsSectionCountsRetrieveUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReportsSourceMetadataCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/reports/source_metadata/`
}

/**
 * Read which source products contributed signals to each given report, and which scout authored it. These values come from ClickHouse, so the inbox list skips them (`include_source_metadata=false`) and calls this after the rows render. Returns one entry per requested id. An id with no signals in this project gets empty values.
 * @summary Get the source products and authoring scout of the reports on screen
 */
export const signalsReportsSourceMetadataCreate = async (
    projectId: string,
    signalReportSourceMetadataRequestApi: SignalReportSourceMetadataRequestApi,
    options?: RequestInit
): Promise<SignalReportSourceMetadataResponseApi> => {
    return apiMutator<SignalReportSourceMetadataResponseApi>(getSignalsReportsSourceMetadataCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalReportSourceMetadataRequestApi),
    })
}

export const getSignalsReviewerExclusionsListUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/reviewer_exclusions/`
}

/**
 * List the standing instructions that keep you off automatic reviewer selection, active and revoked.
 * @summary List your reviewer exclusions
 */
export const signalsReviewerExclusionsList = async (
    projectId: string,
    options?: RequestInit
): Promise<ReviewerExclusionApi[]> => {
    return apiMutator<ReviewerExclusionApi[]>(getSignalsReviewerExclusionsListUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReviewerExclusionsCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/reviewer_exclusions/`
}

/**
 * @summary Stay off automatic reviewer selection in an area
 */
export const signalsReviewerExclusionsCreate = async (
    projectId: string,
    reviewerExclusionCreateApi: ReviewerExclusionCreateApi,
    options?: RequestInit
): Promise<ReviewerExclusionCreateResultApi> => {
    return apiMutator<ReviewerExclusionCreateResultApi>(getSignalsReviewerExclusionsCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(reviewerExclusionCreateApi),
    })
}

export const getSignalsReviewerExclusionsRetrieveUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reviewer_exclusions/${id}/`
}

/**
 * @summary Get one of your reviewer exclusions
 */
export const signalsReviewerExclusionsRetrieve = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<ReviewerExclusionApi> => {
    return apiMutator<ReviewerExclusionApi>(getSignalsReviewerExclusionsRetrieveUrl(projectId, id), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsReviewerExclusionsPartialUpdateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reviewer_exclusions/${id}/`
}

/**
 * @summary Change one of your reviewer exclusions
 */
export const signalsReviewerExclusionsPartialUpdate = async (
    projectId: string,
    id: string,
    patchedReviewerExclusionUpdateApi?: PatchedReviewerExclusionUpdateApi,
    options?: RequestInit
): Promise<ReviewerExclusionApi> => {
    return apiMutator<ReviewerExclusionApi>(getSignalsReviewerExclusionsPartialUpdateUrl(projectId, id), {
        ...options,
        method: 'PATCH',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(patchedReviewerExclusionUpdateApi),
    })
}

export const getSignalsReviewerExclusionsRevokeCreateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/reviewer_exclusions/${id}/revoke/`
}

/**
 * Make you eligible for automatic reviewer selection in this area again. Revoking does not add you to any report, and it does not change old reports.
 * @summary Revoke one of your reviewer exclusions
 */
export const signalsReviewerExclusionsRevokeCreate = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<ReviewerExclusionApi> => {
    return apiMutator<ReviewerExclusionApi>(getSignalsReviewerExclusionsRevokeCreateUrl(projectId, id), {
        ...options,
        method: 'POST',
    })
}

export const getSignalsScoutCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/scout/`
}

/**
 * Create a scout skill and its runnable config atomically. Give it a `display_name` — the label people read, kept exactly as written — and the scout's permanent skill name is generated from it, with a numeric suffix when that name is taken, so two scouts may share a label without sharing an identity. Pass `name` instead to pick that identifier yourself; any valid skill name works, since the config row is what makes a skill a scout. The skill always receives the report-channel tools. The optional config controls schedule, enablement, dry-run posture, network access, and typed destinations such as Slack. Repeating the same definition is safe and applies any supplied config fields; reusing an explicit `name` for a different definition returns 409.
 * @summary Create a scout
 */
export const signalsScoutCreate = async (
    projectId: string,
    signalScoutCreateApi: SignalScoutCreateApi,
    options?: RequestInit
): Promise<SignalScoutCreateResponseApi> => {
    return apiMutator<SignalScoutCreateResponseApi>(getSignalsScoutCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalScoutCreateApi),
    })
}

export const getSignalsScoutChatTasksCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/scout/chat_tasks/`
}

/**
 * Create and run a cloud task for one of the fixed scout chat templates (suggest a scout, fleet overview, recent signals). The prompt is server-owned; an `author_scout` chat can carry the user's request, which the server fences inside that prompt. The response carries the task id to navigate to.
 * @summary Start a scout chat task
 */
export const signalsScoutChatTasksCreate = async (
    projectId: string,
    scoutChatTaskCreateApi: ScoutChatTaskCreateApi,
    options?: RequestInit
): Promise<ScoutChatTaskApi> => {
    return apiMutator<ScoutChatTaskApi>(getSignalsScoutChatTasksCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(scoutChatTaskCreateApi),
    })
}

export const getSignalsScoutConfigListUrl = (projectId: string, params?: SignalsScoutConfigListParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/scout/configs/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/scout/configs/`
}

/**
 * List the per-(team, skill) scout configs for this project. Each row includes its `display_name` (the label people read), its `skill_name` (the permanent identifier), its schedule (rolling `run_interval_minutes`, or a project-local `run_cron_schedule` when set), `enabled`, `emit` posture, and `tags`. A freshly authored scout skill appears here once its config is registered, either explicitly via create or by the coordinator's next tick. Pass `tags` to narrow the fleet to the scouts carrying at least one of the given labels, and `search` to narrow it to the scouts matching a substring of either name.
 * @summary List scout configs
 */
export const signalsScoutConfigList = async (
    projectId: string,
    params?: SignalsScoutConfigListParams,
    options?: RequestInit
): Promise<SignalScoutConfigApi[]> => {
    return apiMutator<SignalScoutConfigApi[]>(getSignalsScoutConfigListUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutConfigCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/scout/configs/`
}

/**
 * Register the config for a skill immediately, without waiting for the coordinator to auto-register it — and the way to make a skill without the `signals-scout-` prefix a scout at all. The same call can optionally set `run_interval_minutes`, a cron `run_cron_schedule`, `enabled`, `emit`, `network_access`, and output destinations. The skill must already exist on this project. Upsert: if a config already exists for the skill, the provided fields are applied to it. Registering puts the skill's body on the schedule as the scout's prompt, so this call needs `llm_skill:write` and editor access to skills on top of `signal_scout:write`, like creating a scout.
 * @summary Create a scout config
 */
export const signalsScoutConfigCreate = async (
    projectId: string,
    signalScoutConfigCreateApi: SignalScoutConfigCreateApi,
    options?: RequestInit
): Promise<SignalScoutConfigApi> => {
    return apiMutator<SignalScoutConfigApi>(getSignalsScoutConfigCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalScoutConfigCreateApi),
    })
}

export const getSignalsScoutConfigUpdateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/scout/configs/${id}/`
}

/**
 * Tune one scout: change its schedule (rolling `run_interval_minutes`, or a cron `run_cron_schedule` that takes precedence when set), `enabled`, `emit` (dry-run) posture, `network_access` (trusted-domain allowlist vs full access for the scout's sandbox), or output destinations. `skill_name` is fixed. Enabling records `enabled_by` and is activity-logged since it drives spend.
 * @summary Update a scout config
 */
export const signalsScoutConfigUpdate = async (
    projectId: string,
    id: string,
    patchedSignalScoutConfigUpdateApi?: PatchedSignalScoutConfigUpdateApi,
    options?: RequestInit
): Promise<SignalScoutConfigApi> => {
    return apiMutator<SignalScoutConfigApi>(getSignalsScoutConfigUpdateUrl(projectId, id), {
        ...options,
        method: 'PATCH',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(patchedSignalScoutConfigUpdateApi),
    })
}

export const getSignalsScoutConfigDestroyUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/scout/configs/${id}/`
}

/**
 * Delete one scout config by its `id`, removing the per-(team, skill) schedule/emit row outright. The point is cleaning up an orphaned config whose skill was archived or deleted — it lingers in `list` with an empty `description`, never runs (the coordinator skips it and the skill can't load), but can't otherwise be removed over the API. Deletion is activity-logged. Note: auto-registration only scans live `signals-scout-*` skills, so a config deleted for one of those is back on the coordinator's next tick. A scout under any other name does not come back on its own: its config stays deleted until you re-register it, and its skill still reads as a scout meanwhile. To retire a live scout, archive its skill (or set `enabled=false` to make it inert) rather than deleting the config. A scout whose `scout_role` is `operational` cannot be deleted: it is part of the self-driving system rather than the project's own fleet.
 * @summary Delete a scout config
 */
export const signalsScoutConfigDestroy = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<void> => {
    return apiMutator<void>(getSignalsScoutConfigDestroyUrl(projectId, id), {
        ...options,
        method: 'DELETE',
    })
}

export const getSignalsScoutConfigPrecheckTestUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/scout/configs/${id}/precheck_test/`
}

/**
 * Run a scout's pre-check query once and return its rows, without starting a run and without saving anything. The query gets the same `{since}` and `{now}` values the next scheduled run would get, so the result says whether that run would start or skip. Pass `precheck_query` to try a query before you save it, or omit it to try the effective one: the saved query, or the default the scout's skill ships. A query error comes back in the `error` field with a 200, because a scheduled run treats it as a reason to run.
 * @summary Test a scout pre-check
 */
export const signalsScoutConfigPrecheckTest = async (
    projectId: string,
    id: string,
    signalScoutPrecheckTestRequestApi?: SignalScoutPrecheckTestRequestApi,
    options?: RequestInit
): Promise<SignalScoutPrecheckTestApi> => {
    return apiMutator<SignalScoutPrecheckTestApi>(getSignalsScoutConfigPrecheckTestUrl(projectId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalScoutPrecheckTestRequestApi),
    })
}

export const getSignalsScoutConfigRunUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/scout/configs/${id}/run/`
}

/**
 * Dispatch one on-demand run of this scout immediately, regardless of its schedule. Useful to test a scout right after authoring it, or to refresh its findings on demand. The run executes asynchronously on the worker and inherits every guard the scheduled path has: it is forbidden if scouts are not enabled for the project (403), and skipped if self-driving is paused at the project's pull request limit, or the project is over its daily report limit or daily run budget (429), or a run for this scout is already in progress (409). A manual run counts against the same daily run budget as scheduled runs, so repeated manual runs of the same scout can exhaust the project's daily allowance. A manual run does not change the scout's schedule or `last_run_at`. A disabled scout can still be run this way (to test before enabling). Pass an optional `note` to steer this one run without leaving a scout note that would steer every later run too. Returns immediately with the workflow id: poll the scout's runs for the result.
 * @summary Run a scout now
 */
export const signalsScoutConfigRun = async (
    projectId: string,
    id: string,
    signalScoutManualRunRequestApi?: SignalScoutManualRunRequestApi,
    options?: RequestInit
): Promise<SignalScoutManualRunApi> => {
    return apiMutator<SignalScoutManualRunApi>(getSignalsScoutConfigRunUrl(projectId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalScoutManualRunRequestApi),
    })
}

export const getSignalsScoutConfigTrialUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/scout/configs/${id}/trial/`
}

/**
 * Run a prompt, model, or effort variant against live data with private memory and report capture.
 * @summary Run a private scout variant
 */
export const signalsScoutConfigTrial = async (
    projectId: string,
    id: string,
    scoutTrialLaunchApi: ScoutTrialLaunchApi,
    options?: RequestInit
): Promise<ScoutTrialStartedApi> => {
    return apiMutator<ScoutTrialStartedApi>(getSignalsScoutConfigTrialUrl(projectId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(scoutTrialLaunchApi),
    })
}

export const getSignalsScoutConfigTrialComparisonCreateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/scout/configs/${id}/trial_comparison/`
}

/**
 * Freeze variants and the reviewed rubric, then run scouts and judge their results in the background.
 * @summary Run and judge a private scout comparison
 */
export const signalsScoutConfigTrialComparisonCreate = async (
    projectId: string,
    id: string,
    scoutTrialComparisonRequestApi: ScoutTrialComparisonRequestApi,
    options?: RequestInit
): Promise<ScoutTrialComparisonApi> => {
    return apiMutator<ScoutTrialComparisonApi>(getSignalsScoutConfigTrialComparisonCreateUrl(projectId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(scoutTrialComparisonRequestApi),
    })
}

export const getSignalsScoutConfigTrialComparisonArchiveUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/scout/configs/${id}/trial_comparison_archive/`
}

/**
 * Hide a finished trial from history or restore it without deleting results or starting any work.
 * @summary Archive or restore a saved scout trial
 */
export const signalsScoutConfigTrialComparisonArchive = async (
    projectId: string,
    id: string,
    scoutTrialComparisonArchiveRequestApi: ScoutTrialComparisonArchiveRequestApi,
    options?: RequestInit
): Promise<ScoutTrialComparisonApi> => {
    return apiMutator<ScoutTrialComparisonApi>(getSignalsScoutConfigTrialComparisonArchiveUrl(projectId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(scoutTrialComparisonArchiveRequestApi),
    })
}

export const getSignalsScoutConfigTrialComparisonHistoryUrl = (
    projectId: string,
    id: string,
    params?: SignalsScoutConfigTrialComparisonHistoryParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/scout/configs/${id}/trial_comparison_history/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/scout/configs/${id}/trial_comparison_history/`
}

/**
 * Read recent comparisons, including those saved before any scout run started.
 * @summary List your saved scout comparisons
 */
export const signalsScoutConfigTrialComparisonHistory = async (
    projectId: string,
    id: string,
    params?: SignalsScoutConfigTrialComparisonHistoryParams,
    options?: RequestInit
): Promise<ScoutTrialComparisonHistoryApi> => {
    return apiMutator<ScoutTrialComparisonHistoryApi>(
        getSignalsScoutConfigTrialComparisonHistoryUrl(projectId, id, params),
        {
            ...options,
            method: 'GET',
        }
    )
}

export const getSignalsScoutConfigTrialComparisonRetrieveUrl = (
    projectId: string,
    id: string,
    params: SignalsScoutConfigTrialComparisonRetrieveParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/scout/configs/${id}/trial_comparison_result/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/scout/configs/${id}/trial_comparison_result/`
}

/**
 * Read comparison progress and its saved report without starting any scout or judge calls.
 * @summary Read a saved scout comparison
 */
export const signalsScoutConfigTrialComparisonRetrieve = async (
    projectId: string,
    id: string,
    params: SignalsScoutConfigTrialComparisonRetrieveParams,
    options?: RequestInit
): Promise<ScoutTrialComparisonApi> => {
    return apiMutator<ScoutTrialComparisonApi>(getSignalsScoutConfigTrialComparisonRetrieveUrl(projectId, id, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutConfigTrialComparisonResumeUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/scout/configs/${id}/trial_comparison_resume/`
}

/**
 * Recover the same comparison without repeating saved scout runs or judge attempts.
 * @summary Resume a saved scout comparison
 */
export const signalsScoutConfigTrialComparisonResume = async (
    projectId: string,
    id: string,
    scoutTrialComparisonQueryApi: ScoutTrialComparisonQueryApi,
    options?: RequestInit
): Promise<ScoutTrialComparisonApi> => {
    return apiMutator<ScoutTrialComparisonApi>(getSignalsScoutConfigTrialComparisonResumeUrl(projectId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(scoutTrialComparisonQueryApi),
    })
}

export const getSignalsScoutConfigTrialEvaluationCreateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/scout/configs/${id}/trial_evaluation/`
}

/**
 * Freeze rubric and evidence, then judge explicit variant groups without changing production scouts.
 * @summary Score a private scout comparison
 */
export const signalsScoutConfigTrialEvaluationCreate = async (
    projectId: string,
    id: string,
    scoutTrialEvaluationRequestApi: ScoutTrialEvaluationRequestApi,
    options?: RequestInit
): Promise<ScoutTrialEvaluationApi> => {
    return apiMutator<ScoutTrialEvaluationApi>(getSignalsScoutConfigTrialEvaluationCreateUrl(projectId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(scoutTrialEvaluationRequestApi),
    })
}

export const getSignalsScoutConfigTrialEvaluationRetrieveUrl = (
    projectId: string,
    id: string,
    params: SignalsScoutConfigTrialEvaluationRetrieveParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/scout/configs/${id}/trial_evaluation_result/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/scout/configs/${id}/trial_evaluation_result/`
}

/**
 * Read saved scores, criterion evidence and baseline differences without starting model calls.
 * @summary Read a private scout comparison evaluation
 */
export const signalsScoutConfigTrialEvaluationRetrieve = async (
    projectId: string,
    id: string,
    params: SignalsScoutConfigTrialEvaluationRetrieveParams,
    options?: RequestInit
): Promise<ScoutTrialEvaluationApi> => {
    return apiMutator<ScoutTrialEvaluationApi>(getSignalsScoutConfigTrialEvaluationRetrieveUrl(projectId, id, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutConfigTrialHistoryUrl = (
    projectId: string,
    id: string,
    params?: SignalsScoutConfigTrialHistoryParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/scout/configs/${id}/trial_history/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/scout/configs/${id}/trial_history/`
}

/**
 * Read recent private runs for the requesting operator in the internal comparison editor.
 * @summary List your private scout comparison runs
 */
export const signalsScoutConfigTrialHistory = async (
    projectId: string,
    id: string,
    params?: SignalsScoutConfigTrialHistoryParams,
    options?: RequestInit
): Promise<ScoutTrialHistoryApi> => {
    return apiMutator<ScoutTrialHistoryApi>(getSignalsScoutConfigTrialHistoryUrl(projectId, id, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutConfigTrialResultUrl = (
    projectId: string,
    id: string,
    params: SignalsScoutConfigTrialResultParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/scout/configs/${id}/trial_result/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/scout/configs/${id}/trial_result/`
}

/**
 * Read a trial's existing run status and its privately captured reports and memory changes.
 * @summary Read a private scout trial result
 */
export const signalsScoutConfigTrialResult = async (
    projectId: string,
    id: string,
    params: SignalsScoutConfigTrialResultParams,
    options?: RequestInit
): Promise<ScoutTrialResultApi> => {
    return apiMutator<ScoutTrialResultApi>(getSignalsScoutConfigTrialResultUrl(projectId, id, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutConfigTrialSetupUrl = (
    projectId: string,
    id: string,
    params?: SignalsScoutConfigTrialSetupParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/scout/configs/${id}/trial_setup/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/scout/configs/${id}/trial_setup/`
}

/**
 * Read comparison readiness and source settings for the internal comparison editor.
 * @summary Inspect a private scout comparison
 */
export const signalsScoutConfigTrialSetup = async (
    projectId: string,
    id: string,
    params?: SignalsScoutConfigTrialSetupParams,
    options?: RequestInit
): Promise<ScoutTrialSetupApi> => {
    return apiMutator<ScoutTrialSetupApi>(getSignalsScoutConfigTrialSetupUrl(projectId, id, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutConfigSyncUrl = (projectId: string, params?: SignalsScoutConfigSyncParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/scout/configs/sync/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/scout/configs/sync/`
}

/**
 * Materialize the scout fleet for this project on demand (idempotent): seed the canonical `signals-scout-*` skills, create a default-schedule config for any scout lacking one, retire the skills whose canonical scout no longer ships, and return all scout configs. Normally the Temporal coordinator does this on its next tick; this action exists so the scout UIs and setup flows (e.g. the wizard's self-driving program) can hand the user a tunable fleet immediately. With surface=onboarding, new configs stay disabled until explicitly activated.
 * @summary Sync scout configs
 */
export const signalsScoutConfigSync = async (
    projectId: string,
    params?: SignalsScoutConfigSyncParams,
    options?: RequestInit
): Promise<SignalScoutConfigApi[]> => {
    return apiMutator<SignalScoutConfigApi[]>(getSignalsScoutConfigSyncUrl(projectId, params), {
        ...options,
        method: 'POST',
    })
}

export const getSignalsScoutConfigToolCatalogueUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/scout/configs/tool_catalogue/`
}

/**
 * List every MCP tool a scout could be configured with. Each entry carries the tool's name, label, one-line summary, category, and required scopes, plus `holdable`: whether a scout run can hold every scope the tool needs, and `missing_scopes`: what it would have to be granted on top of the baseline preset. The response also returns the scout scope presets and the write scopes a person can grant to one scout, so a caller can show why a tool is out of reach. Tools a successor has replaced are left out. A tool can carry a `feature_flag`, which resolves per project: evaluate it for the project you are configuring before you offer the tool. Read-only, and the same for every project.
 * @summary List the MCP tool catalogue
 */
export const signalsScoutConfigToolCatalogue = async (
    projectId: string,
    options?: RequestInit
): Promise<ScoutToolCatalogueApi> => {
    return apiMutator<ScoutToolCatalogueApi>(getSignalsScoutConfigToolCatalogueUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutMembersListUrl = (projectId: string, params?: SignalsScoutMembersListParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/scout/members/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/scout/members/`
}

/**
 * Return the people who can review work on this project — one row per member with access to it, each with their `user_uuid`, `email`, `first_name`/`last_name`, resolved GitHub `login` (null when they have no linked GitHub identity), and the `teams` they're on. The cold-start reviewer-routing path: when a finding's owner can't be read off a fetched entity's `created_by` and there's no cached `reviewer:<area>` memory or inbox precedent, list members, match the owner by email/name, then put their resolved `github_login` in `suggested_reviewers` on `emit-report` / `edit-report`. Pass `team` to resolve a team slug to the people on it, maintainers first. Pass `search` to narrow a large roster; the result is capped at 200. When `search` or `team` narrows the result to 10 members or fewer, each row also carries `activity`: the member's recent work, so you can check they are close to the affected area. Strictly team-scoped.
 * @summary List project members for reviewer routing
 */
export const signalsScoutMembersList = async (
    projectId: string,
    params?: SignalsScoutMembersListParams,
    options?: RequestInit
): Promise<ScoutMemberApi[]> => {
    return apiMutator<ScoutMemberApi[]>(getSignalsScoutMembersListUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutMetadataGetUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/scout/metadata/current/`
}

/**
 * Return the project's scout metadata: whether it is enrolled, the current announcement banner (e.g. an alpha run-limit notice, or null when unset), and the enforced run limits with current usage. Limits reflect what the coordinator actually applies at dispatch, so a user can see the real throttle rather than what they assume they set. All values come from the `signals-scout` flag payload, so the banner and caps can change with no deploy.
 * @summary Get scout metadata
 */
export const signalsScoutMetadataGet = async (projectId: string, options?: RequestInit): Promise<ScoutMetadataApi> => {
    return apiMutator<ScoutMetadataApi>(getSignalsScoutMetadataGetUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutNotesListUrl = (projectId: string, params?: SignalsScoutNotesListParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/scout/notes/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/scout/notes/`
}

/**
 * Return the steering notes left for this project's scouts, newest first. Pass `skill_name` to get the notes addressed to one scout (or one pipeline audience, e.g. `pipeline:report-research`) plus the general (blank-target) fleet-wide notes — the shape a scout run reads at cold start. Omit `skill_name` to browse every note. Expired notes are excluded unless `include_expired=true`; `only_without_expiry=true` keeps only the standing notes that have no `expires_at`. `date_from` / `date_to` are a half-open window on `created_at` (`>= date_from`, `< date_to`); pass `date_to` (the `created_at` of the oldest note seen) to walk past the cap. Pass `text` to keep only the notes whose content contains it, case-insensitively. Results capped at 500.
 * @summary List scout notes
 */
export const signalsScoutNotesList = async (
    projectId: string,
    params?: SignalsScoutNotesListParams,
    options?: RequestInit
): Promise<ScoutNoteApi[]> => {
    return apiMutator<ScoutNoteApi[]>(getSignalsScoutNotesListUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutNotesCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/scout/notes/`
}

/**
 * Leave a steering note the scout fleet reads on its next runs. Address it to one scout via `skill_name` (a configured scout), to one stage of the report pipeline via a reserved audience (`pipeline:report-research`), or omit it for a general note every scout sees. Each call creates a new note (no upsert); delete retires one. Attributed to the authenticated user.
 * @summary Leave a note for the scouts
 */
export const signalsScoutNotesCreate = async (
    projectId: string,
    scoutNoteCreateRequestApi: ScoutNoteCreateRequestApi,
    options?: RequestInit
): Promise<ScoutNoteApi> => {
    return apiMutator<ScoutNoteApi>(getSignalsScoutNotesCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(scoutNoteCreateRequestApi),
    })
}

export const getSignalsScoutNotesDestroyUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/scout/notes/${id}/`
}

/**
 * Delete one note by its `id`, retiring it from every scout's view. Use this when a note has been acted on or no longer applies; time-boxed notes can instead carry an `expires_at` and retire themselves.
 * @summary Delete a scout note
 */
export const signalsScoutNotesDestroy = async (projectId: string, id: string, options?: RequestInit): Promise<void> => {
    return apiMutator<void>(getSignalsScoutNotesDestroyUrl(projectId, id), {
        ...options,
        method: 'DELETE',
    })
}

export const getSignalsScoutProjectProfileGetUrl = (
    projectId: string,
    params?: SignalsScoutProjectProfileGetParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/scout/project_profile/current/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/scout/project_profile/current/`
}

/**
 * Return the team's deterministic project profile. The response opens with a compact `summary` envelope carrying the emit gate and the inbox report counts, then the full `payload`. The inventory runs to tens of kilobytes, so a client that truncates a long tool result still keeps the gate. Pass `summary_only=true` to omit `payload` entirely. For the internal scout token the response reflects the newest non-expired cached row or a freshly-built one (lazy compute on cache miss); `force_refresh=true` skips the cache and rebuilds from authoritative sources. Public read callers (session auth or a `signal_scout:read` PAK) get the newest stored profile whatever its age, with `stale=true` when it is past `expires_at`. They never build inline: when the team has no profile, the call starts a background build and returns 404, so retry in a minute. Read this at the start of a run to orient on the team's product mix, integrations, warehouse sources, signal coverage, and existing inbox surface.
 * @summary Get the current project profile
 */
export const signalsScoutProjectProfileGet = async (
    projectId: string,
    params?: SignalsScoutProjectProfileGetParams,
    options?: RequestInit
): Promise<ProjectProfileApi> => {
    return apiMutator<ProjectProfileApi>(getSignalsScoutProjectProfileGetUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutRubricsRetrieveUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/scout/rubrics/${id}/`
}

export const signalsScoutRubricsRetrieve = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<ScoutRubricDocumentApi> => {
    return apiMutator<ScoutRubricDocumentApi>(getSignalsScoutRubricsRetrieveUrl(projectId, id), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutRubricsUpdateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/scout/rubrics/${id}/`
}

export const signalsScoutRubricsUpdate = async (
    projectId: string,
    id: string,
    scoutRubricSaveApi: ScoutRubricSaveApi,
    options?: RequestInit
): Promise<ScoutRubricDocumentApi> => {
    return apiMutator<ScoutRubricDocumentApi>(getSignalsScoutRubricsUpdateUrl(projectId, id), {
        ...options,
        method: 'PUT',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(scoutRubricSaveApi),
    })
}

export const getSignalsScoutRubricsGenerateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/scout/rubrics/${id}/generate/`
}

export const signalsScoutRubricsGenerate = async (
    projectId: string,
    id: string,
    scoutRubricGenerateApi?: ScoutRubricGenerateApi,
    options?: RequestInit
): Promise<ScoutRubricDocumentApi> => {
    return apiMutator<ScoutRubricDocumentApi>(getSignalsScoutRubricsGenerateUrl(projectId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(scoutRubricGenerateApi),
    })
}

export const getSignalsScoutRunsListUrl = (projectId: string, params?: SignalsScoutRunsListParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/scout/runs/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/scout/runs/`
}

/**
 * Return the most recent `SignalScoutRun` summaries for this project, newest first. Used by the headless scout to dedupe against work other runs already covered. ILIKE matches on `summary`. `date_from` / `date_to` are a half-open window on `created_at` (`>= date_from`, `< date_to`); pass `date_to` on subsequent calls to walk past the 100-row cap. Pass `emitted=true` to see only runs that surfaced at least one finding. Pass `skill_name` (optionally with `skill_version`) to scope to a single scout. Results capped at 100.
 * @summary Search recent agent runs
 */
export const signalsScoutRunsList = async (
    projectId: string,
    params?: SignalsScoutRunsListParams,
    options?: RequestInit
): Promise<SignalScoutRunSummaryApi[]> => {
    return apiMutator<SignalScoutRunSummaryApi[]>(getSignalsScoutRunsListUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutRunsRetrieveUrl = (projectId: string, runId: string) => {
    return `/api/projects/${projectId}/signals/scout/runs/${runId}/`
}

/**
 * Return the full `SignalScoutRun` row. Status, timing, and error flow from the linked `tasks.TaskRun`. Strictly team-scoped — a UUID belonging to another team returns 404.
 * @summary Get a run by ID
 */
export const signalsScoutRunsRetrieve = async (
    projectId: string,
    runId: string,
    options?: RequestInit
): Promise<SignalScoutRunDetailApi> => {
    return apiMutator<SignalScoutRunDetailApi>(getSignalsScoutRunsRetrieveUrl(projectId, runId), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutRecordCheckResultUrl = (projectId: string, runId: string) => {
    return `/api/projects/${projectId}/signals/scout/runs/${runId}/check-result/`
}

/**
 * Close the follow-up check this run was dispatched to answer. The run note carries the check id and what to establish; this call is the only thing that records the answer, so a run that investigates and says nothing leaves the check unanswered. The verdict lands on the report as a `check_result` entry people read in the inbox. `failed` retires the check, `passed` re-arms a recurring one, and `errored` retries it. `inconclusive` with the `awaiting_data` reason looks again later, and any other reason ends the check. Send the outcome you actually reached rather than the one that closes the loop. A run may close the check it was dispatched for, or a check on its own scout that is due or waiting on a run.
 * @summary Record the verdict on a report check
 */
export const signalsScoutRecordCheckResult = async (
    projectId: string,
    runId: string,
    recordCheckResultRequestApi: RecordCheckResultRequestApi,
    options?: RequestInit
): Promise<RecordCheckResultResponseApi> => {
    return apiMutator<RecordCheckResultResponseApi>(getSignalsScoutRecordCheckResultUrl(projectId, runId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(recordCheckResultRequestApi),
    })
}

export const getSignalsScoutEditReportUrl = (projectId: string, runId: string) => {
    return `/api/projects/${projectId}/signals/scout/runs/${runId}/edit-report/`
}

/**
 * Rewrite a report's title/summary, append a note or fresh evidence, set its suggested reviewers, and/or point it at another repository. Can target ANY of the project's inbox reports, not just scout-authored ones — so the edit is attributed to this scout. Reviewers and repository are how you rescue a report that surfaced routed to no one or against the wrong codebase: each replaces what the report holds and re-runs autostart, so a report that was missing a qualifying reviewer or a repository can open a draft PR. The response carries the repository the report holds after the edit, and the call fails when a repository it named did not land. Set `actionability` and/or `priority` (each with its explanation) when new evidence changed your judgment: each replaces the report's decision and re-runs autostart, without changing the report's inbox status. `tags` replaces the report's slug tags, and an omitted `tags` keeps them. Title/summary edits are best-effort: the pipeline may later re-research them. Set `supersedes_implementation` alongside a rewrite when the fix changed. Verified automated predecessor PRs close only after the replacement completes with verified open PRs.
 * @summary Edit an existing report for a run
 */
export const signalsScoutEditReport = async (
    projectId: string,
    runId: string,
    editReportRequestApi: EditReportRequestApi,
    options?: RequestInit
): Promise<EditReportResponseApi> => {
    return apiMutator<EditReportResponseApi>(getSignalsScoutEditReportUrl(projectId, runId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(editReportRequestApi),
    })
}

export const getSignalsScoutRunsEmissionsUrl = (projectId: string, runId: string) => {
    return `/api/projects/${projectId}/signals/scout/runs/${runId}/emissions/`
}

/**
 * Return the findings a `SignalScoutRun` emitted to the inbox, newest first — one row per emit with its `description` (the finding text as surfaced), `severity`, and the deterministic `source_id` that joins back to the underlying signal. Lets a team and its agents see *what* a run surfaced without parsing `emitted_finding_ids` or scanning the signal store. Strictly team-scoped — a run UUID belonging to another team returns 404.
 * @summary List a run's emitted findings
 */
export const signalsScoutRunsEmissions = async (
    projectId: string,
    runId: string,
    options?: RequestInit
): Promise<SignalScoutEmissionApi[]> => {
    return apiMutator<SignalScoutEmissionApi[]>(getSignalsScoutRunsEmissionsUrl(projectId, runId), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutRunsEmissionReportsUrl = (projectId: string, runId: string) => {
    return `/api/projects/${projectId}/signals/scout/runs/${runId}/emissions/reports/`
}

/**
 * Best-effort reverse of the report -> signals link. For each finding the run emitted, resolve the inbox `SignalReport` (if any) its underlying signal grouped into by walking the deterministic `source_id` back through the signal store. `report` is null when the finding hasn't grouped into a report yet, was de-duplicated away, or its signal was deleted. Lets the scout UI surface which inbox report a finding contributed to — the reverse of the report's evidence list. Strictly team-scoped — a run UUID belonging to another team returns 404.
 * @summary List the inbox reports a run's findings linked to
 */
export const signalsScoutRunsEmissionReports = async (
    projectId: string,
    runId: string,
    options?: RequestInit
): Promise<ScoutEmissionReportLinkApi[]> => {
    return apiMutator<ScoutEmissionReportLinkApi[]>(getSignalsScoutRunsEmissionReportsUrl(projectId, runId), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutEmitReportUrl = (projectId: string, runId: string) => {
    return `/api/projects/${projectId}/signals/scout/runs/${runId}/emit-report/`
}

/**
 * The second emit channel: author a complete `SignalReport` directly instead of emitting a weak signal. The report passes the safety judge, then surfaces at the status the scout's `actionability` call implies (or is suppressed). Backing `evidence` is written as bound signals so the report behaves like a pipeline report. Safe to retry: resending an emission returns the report the first call authored (`idempotent_replay` true) rather than a second one, keyed on `idempotency_key` or, without one, on the report's content. Use `reports` to find a report from an earlier run and `edit-report` to update it instead of authoring a near-duplicate.
 * @summary Author a full report for a run
 */
export const signalsScoutEmitReport = async (
    projectId: string,
    runId: string,
    emitReportRequestApi: EmitReportRequestApi,
    options?: RequestInit
): Promise<EmitReportResponseApi> => {
    return apiMutator<EmitReportResponseApi>(getSignalsScoutEmitReportUrl(projectId, runId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(emitReportRequestApi),
    })
}

export const getSignalsScoutEmitSignalUrl = (projectId: string, runId: string) => {
    return `/api/projects/${projectId}/signals/scout/runs/${runId}/emit-signal/`
}

/**
 * Fire `emit_signal` with `source_product = signals_scout`. The `finding_id` is baked into the deterministic `Signal.source_id = run:<id>:finding:<id>` for traceability, but this is NOT idempotent — a second call with the same `finding_id` emits a second signal, so do not retry an emit that may have already succeeded.
 * @summary Emit a finding for a run
 */
export const signalsScoutEmitSignal = async (
    projectId: string,
    runId: string,
    emitFindingRequestApi: EmitFindingRequestApi,
    options?: RequestInit
): Promise<EmitFindingResponseApi> => {
    return apiMutator<EmitFindingResponseApi>(getSignalsScoutEmitSignalUrl(projectId, runId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(emitFindingRequestApi),
    })
}

export const getSignalsScoutLighthouseAuditUrl = (projectId: string, runId: string) => {
    return `/api/projects/${projectId}/signals/scout/runs/${runId}/lighthouse-audit/`
}

/**
 * Load one page in a real browser and return what makes it slow — most usefully the element the browser chose as the Largest Contentful Paint, and where the LCP time went. Field data says a route is slow; this says which element and why, so a finding can name it instead of guessing from source. Restricted to public PostHog pages: the browser signs in to nothing, so a page behind a login would report the login screen's numbers. One throttled cold load is not a p75 over real users — corroborate a field finding with it, never replace one. Capped at 5 audits per run.
 * @summary Run a Lighthouse audit for a run
 */
export const signalsScoutLighthouseAudit = async (
    projectId: string,
    runId: string,
    lighthouseAuditRequestApi: LighthouseAuditRequestApi,
    options?: RequestInit
): Promise<LighthouseAuditResponseApi> => {
    return apiMutator<LighthouseAuditResponseApi>(getSignalsScoutLighthouseAuditUrl(projectId, runId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(lighthouseAuditRequestApi),
    })
}

export const getSignalsScoutSubmitMonitoringResultUrl = (projectId: string, runId: string) => {
    return `/api/projects/${projectId}/signals/scout/runs/${runId}/monitoring_result/`
}

/**
 * Submit the assigned Monitoring check's evidence and verdict while the scout is running. Only the owning Monitoring scout can call this endpoint. The server derives the check, attempt, definition, and fixed window from the run. Validation errors record nothing: correct the fields and retry in the same run. An identical accepted submission is idempotent. This records an evaluation and leaves the report in Monitoring.
 * @summary Submit the result of an authored Monitoring check
 */
export const signalsScoutSubmitMonitoringResult = async (
    projectId: string,
    runId: string,
    submitMonitoringResultRequestApi: SubmitMonitoringResultRequestApi,
    options?: RequestInit
): Promise<SubmitMonitoringResultResponseApi> => {
    return apiMutator<SubmitMonitoringResultResponseApi>(getSignalsScoutSubmitMonitoringResultUrl(projectId, runId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(submitMonitoringResultRequestApi),
    })
}

export const getSignalsScoutRecordOutputUrl = (projectId: string, runId: string) => {
    return `/api/projects/${projectId}/signals/scout/runs/${runId}/record-output/`
}

/**
 * The structured-output channel: record schema-validated records this run produced. Opt-in via the scout config's `structured_output_schema` (a JSON Schema describing one record) — without it the call fails closed, as it does for a dry-run scout (emit off). All-or-nothing: any invalid record fails the whole call with nothing written, so fix and resubmit the batch. Each accepted record lands in the project's event stream as a `$scout_structured_output` event — query them like any event (insights, SQL over `events`). Recording is idempotent: event ids are deterministic, so resubmitting an identical batch (e.g. retrying after a 503) cannot double-count.
 * @summary Record structured output for a run
 */
export const signalsScoutRecordOutput = async (
    projectId: string,
    runId: string,
    recordStructuredOutputRequestApi: RecordStructuredOutputRequestApi,
    options?: RequestInit
): Promise<RecordStructuredOutputResponseApi> => {
    return apiMutator<RecordStructuredOutputResponseApi>(getSignalsScoutRecordOutputUrl(projectId, runId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(recordStructuredOutputRequestApi),
    })
}

export const getSignalsScoutReportCheckCancelUrl = (projectId: string, runId: string) => {
    return `/api/projects/${projectId}/signals/scout/runs/${runId}/report-check-cancel/`
}

/**
 * Stop a check that is no longer worth running — the claim it re-measures has changed, or a better check replaces it. Results it already recorded stay on the report. A check that has already finished cannot be cancelled.
 * @summary Cancel a follow-up check
 */
export const signalsScoutReportCheckCancel = async (
    projectId: string,
    runId: string,
    cancelReportCheckRequestApi: CancelReportCheckRequestApi,
    options?: RequestInit
): Promise<ScoutCheckSummaryApi> => {
    return apiMutator<ScoutCheckSummaryApi>(getSignalsScoutReportCheckCancelUrl(projectId, runId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(cancelReportCheckRequestApi),
    })
}

export const getSignalsScoutReportCheckCreateUrl = (projectId: string, runId: string) => {
    return `/api/projects/${projectId}/signals/scout/runs/${runId}/report-check-create/`
}

/**
 * Schedule a re-measurement of a report's claim, so whether the fix held becomes a stored fact instead of something a future run has to remember to look for. A `metric_threshold` check runs one bounded Trends query and compares the result. An `agent` check runs a scout instead, for a claim no single number settles.
 * @summary Write a follow-up check on a report
 */
export const signalsScoutReportCheckCreate = async (
    projectId: string,
    runId: string,
    createReportCheckRequestApi: CreateReportCheckRequestApi,
    options?: RequestInit
): Promise<ScoutCheckSummaryApi> => {
    return apiMutator<ScoutCheckSummaryApi>(getSignalsScoutReportCheckCreateUrl(projectId, runId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(createReportCheckRequestApi),
    })
}

export const getSignalsScoutReportChecksListUrl = (
    projectId: string,
    runId: string,
    params: SignalsScoutReportChecksListParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/scout/runs/${runId}/report-checks/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/scout/runs/${runId}/report-checks/`
}

/**
 * Every check on one report, newest first. Read this before writing one: a report already carrying a check for the same claim needs no second one, and a report holds at most five open checks at a time.
 * @summary List a report's follow-up checks
 */
export const signalsScoutReportChecksList = async (
    projectId: string,
    runId: string,
    params: SignalsScoutReportChecksListParams,
    options?: RequestInit
): Promise<ScoutCheckSummaryApi[]> => {
    return apiMutator<ScoutCheckSummaryApi[]>(getSignalsScoutReportChecksListUrl(projectId, runId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutRunsEmissionsBatchUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/scout/runs/emissions/batch/`
}

/**
 * Batched form of the per-run emissions endpoint: return the findings every requested `SignalScoutRun` emitted, flattened newest-first, in a single request. Each row carries its `run_id`, so the caller can regroup by run. The findings UI uses this to load the whole recent window in one round-trip instead of one request per run. Strictly team-scoped — run ids belonging to another team contribute no rows (no per-run 404; one stale id never fails the batch).
 * @summary List emitted findings for many runs at once
 */
export const signalsScoutRunsEmissionsBatch = async (
    projectId: string,
    scoutRunIdsBatchRequestApi: ScoutRunIdsBatchRequestApi,
    options?: RequestInit
): Promise<SignalScoutEmissionApi[]> => {
    return apiMutator<SignalScoutEmissionApi[]>(getSignalsScoutRunsEmissionsBatchUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(scoutRunIdsBatchRequestApi),
    })
}

export const getSignalsScoutRunsRecentEmissionsUrl = (
    projectId: string,
    params?: SignalsScoutRunsRecentEmissionsParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/scout/runs/emissions/recent/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/scout/runs/emissions/recent/`
}

/**
 * Return the team's recently emitted scout findings across *every* run, newest first — the cross-run counterpart to the per-run `emissions` action. Each row carries its `run_id`, so you can regroup by run without first listing runs and fanning out one `emissions` call each. Pass `skill_name` to scope to a single scout, and `date_from` / `date_to` (a half-open window on `emitted_at`) to bound or paginate — set `date_to` to the oldest emission's `emitted_at` to walk back past the limit. Pure Postgres, no ClickHouse round-trip. Capped at 200 rows (default 50).
 * @summary List recent emitted findings across all runs
 */
export const signalsScoutRunsRecentEmissions = async (
    projectId: string,
    params?: SignalsScoutRunsRecentEmissionsParams,
    options?: RequestInit
): Promise<SignalScoutEmissionApi[]> => {
    return apiMutator<SignalScoutEmissionApi[]>(getSignalsScoutRunsRecentEmissionsUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutRunsEmissionReportsBatchUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/scout/runs/emissions/reports/batch/`
}

/**
 * Batched form of the per-run emission-reports endpoint. For every finding the requested runs emitted, resolve the inbox `SignalReport` (if any) its signal grouped into — all in a single ClickHouse round-trip rather than one query per run, which is what made the findings page slow to open. `report` is null when a finding hasn't grouped yet, was de-duplicated, or its signal was deleted. Strictly team-scoped — run ids belonging to another team contribute no rows.
 * @summary List the inbox reports many runs' findings linked to
 */
export const signalsScoutRunsEmissionReportsBatch = async (
    projectId: string,
    scoutRunIdsBatchRequestApi: ScoutRunIdsBatchRequestApi,
    options?: RequestInit
): Promise<ScoutEmissionReportLinkApi[]> => {
    return apiMutator<ScoutEmissionReportLinkApi[]>(getSignalsScoutRunsEmissionReportsBatchUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(scoutRunIdsBatchRequestApi),
    })
}

export const getSignalsScoutRunsFindingsSummaryUrl = (
    projectId: string,
    params?: SignalsScoutRunsFindingsSummaryParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/scout/runs/findings/summary/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/scout/runs/findings/summary/`
}

/**
 * Return a cheap fleet-wide tally of the output the scout troop produced in the recent window — the finding count, the distinct reports authored/edited via the report channel, the number of distinct scouts behind them, and the latest output time. Backs the 'Scout findings' callout so it renders from one query instead of the client paging through the whole runs window. Counts runs that emitted at least one finding (`emitted_count > 0`) or authored/edited an inbox report within the last `window_hours` (default 72), capped to the most recent 120 such runs so the count matches what the findings list renders. Strictly team-scoped.
 * @summary Summarise recent scout output across the fleet
 */
export const signalsScoutRunsFindingsSummary = async (
    projectId: string,
    params?: SignalsScoutRunsFindingsSummaryParams,
    options?: RequestInit
): Promise<FleetFindingsSummaryApi> => {
    return apiMutator<FleetFindingsSummaryApi>(getSignalsScoutRunsFindingsSummaryUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutRunsRecentPerScoutUrl = (
    projectId: string,
    params?: SignalsScoutRunsRecentPerScoutParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/scout/runs/recent-per-scout/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/scout/runs/recent-per-scout/`
}

/**
 * Return the most recent `per_scout_limit` runs of *every* configured scout on the project (default 25), newest-first across the fleet. The per-scout probe is the point: a fleet-wide time window has to serve hourly and weekly scouts from one result cap, so the busy scouts crowd out the sparse ones and a scout's visible history shrinks as the rest of the fleet gets busier. Probing each `skill_name` gives every scout the same depth of history whatever its schedule, and bounds the response at scouts x `per_scout_limit` rather than at the fleet's run rate. Only scouts that still have a config are covered, so runs left behind by a deleted or renamed scout are excluded. Runs older than the staleness guard are excluded too, so a scout that stopped running reads as stale instead of healthy — `max_age_days` (default 30) is that guard's floor, which each scout's own cadence extends. Use `list` instead when you want a literal time window or a text/emitted filter. Pass `skill_name` to probe one scout only. Strictly team-scoped.
 * @summary List each scout's most recent runs
 */
export const signalsScoutRunsRecentPerScout = async (
    projectId: string,
    params?: SignalsScoutRunsRecentPerScoutParams,
    options?: RequestInit
): Promise<SignalScoutRunSummaryApi[]> => {
    return apiMutator<SignalScoutRunSummaryApi[]>(getSignalsScoutRunsRecentPerScoutUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutReportCheckListUrl = (projectId: string, params: SignalsScoutReportCheckListParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/scout/runs/report-checks/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/scout/runs/report-checks/`
}

/**
 * Every check on one report, newest first. The `report_id` is the only input. Read this before writing one: a report already carrying a check for the same claim needs no second one, and a report holds at most five open checks at a time.
 * @summary List a report's follow-up checks
 */
export const signalsScoutReportCheckList = async (
    projectId: string,
    params: SignalsScoutReportCheckListParams,
    options?: RequestInit
): Promise<ScoutCheckSummaryApi[]> => {
    return apiMutator<ScoutCheckSummaryApi[]>(getSignalsScoutReportCheckListUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutScratchpadSearchUrl = (projectId: string, params?: SignalsScoutScratchpadSearchParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/scout/scratchpad/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/scout/scratchpad/`
}

/**
 * Return `SignalScratchpad` entries for this project, newest-first. ILIKE matches on `content` and `key`; pass `key` instead for an exact single-entry lookup, and `skill_name` to keep the entries one scout (or `pipeline:*` stage) created. `date_from` / `date_to` are a half-open window on `updated_at` (`>= date_from`, `< date_to`); pass `date_to` (the `updated_at` of the oldest entry seen) on subsequent calls to walk past the cap. Entries whose `expires_at` has passed are excluded unless `include_expired=true`, and are hard-deleted by a daily janitor once their expiry is more than two weeks in the past. Pass `keys_only=true` to scan keys without pulling entry bodies, or `content_max_chars` to cap each `content` to a preview — both keep a wide orientation scan from returning every entry's full prose. Results capped at 1000.
 * @summary Search the scout scratchpad
 */
export const signalsScoutScratchpadSearch = async (
    projectId: string,
    params?: SignalsScoutScratchpadSearchParams,
    options?: RequestInit
): Promise<ScratchpadEntryApi[]> => {
    return apiMutator<ScratchpadEntryApi[]>(getSignalsScoutScratchpadSearchUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutScratchpadRememberUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/scout/scratchpad/`
}

/**
 * Upsert a memory keyed on `(team, key)`. Re-using a key updates the existing entry in place. A write carries the entry's whole state, so `expires_at` is set when passed and cleared when omitted.
 * @summary Remember a scratchpad entry
 */
export const signalsScoutScratchpadRemember = async (
    projectId: string,
    rememberRequestApi: RememberRequestApi,
    options?: RequestInit
): Promise<ScratchpadEntryApi> => {
    return apiMutator<ScratchpadEntryApi>(getSignalsScoutScratchpadRememberUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(rememberRequestApi),
    })
}

export const getSignalsScoutScratchpadForgetUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/scout/scratchpad/forget/`
}

/**
 * Delete an entry by key. Returns `deleted=false` if no row matched.
 * @summary Forget a scratchpad entry by key
 */
export const signalsScoutScratchpadForget = async (
    projectId: string,
    forgetRequestApi: ForgetRequestApi,
    options?: RequestInit
): Promise<ForgetResponseApi> => {
    return apiMutator<ForgetResponseApi>(getSignalsScoutScratchpadForgetUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(forgetRequestApi),
    })
}

export const getSignalsScoutSuggestionsListUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/scout/suggestions/`
}

/**
 * Return the pre-computed scout suggestions for this project: up to five picks, best first, each either a PostHog-authored scout to turn on or a drafted custom scout. Dismissed and already-created suggestions are omitted. An empty `items` with status `empty` means no batch has been generated yet; the interactive `scout-chat-tasks` path still works.
 * @summary Get suggested scouts for this project
 */
export const signalsScoutSuggestionsList = async (
    projectId: string,
    options?: RequestInit
): Promise<ScoutSuggestionSetApi> => {
    return apiMutator<ScoutSuggestionSetApi>(getSignalsScoutSuggestionsListUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsScoutSuggestionsDismissUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/scout/suggestions/${id}/dismiss/`
}

/**
 * Hide one suggestion from this project's batch. Dismissal is remembered across refreshes by skill name, so the same suggestion is not shown again.
 * @summary Dismiss a suggested scout
 */
export const signalsScoutSuggestionsDismiss = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<ScoutSuggestionItemApi> => {
    return apiMutator<ScoutSuggestionItemApi>(getSignalsScoutSuggestionsDismissUrl(projectId, id), {
        ...options,
        method: 'POST',
    })
}

export const getSignalsScoutSuggestionsRefreshUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/scout/suggestions/refresh/`
}

/**
 * Re-run the suggestion scan for this project now instead of waiting for the scheduled refresh. Runs headlessly; poll the list endpoint for the new batch (`generated_at` advances). Capped per project per day.
 * @summary Refresh suggested scouts
 */
export const signalsScoutSuggestionsRefresh = async (
    projectId: string,
    options?: RequestInit
): Promise<ScoutSuggestionRefreshApi> => {
    return apiMutator<ScoutSuggestionRefreshApi>(getSignalsScoutSuggestionsRefreshUrl(projectId), {
        ...options,
        method: 'POST',
    })
}

export const getSignalsSourceConfigsListUrl = (projectId: string, params?: SignalsSourceConfigsListParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/source_configs/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/source_configs/`
}

export const signalsSourceConfigsList = async (
    projectId: string,
    params?: SignalsSourceConfigsListParams,
    options?: RequestInit
): Promise<PaginatedSignalSourceConfigListApi> => {
    return apiMutator<PaginatedSignalSourceConfigListApi>(getSignalsSourceConfigsListUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsSourceConfigsCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/source_configs/`
}

export const signalsSourceConfigsCreate = async (
    projectId: string,
    signalSourceConfigApi: NonReadonly<SignalSourceConfigApi>,
    options?: RequestInit
): Promise<SignalSourceConfigApi> => {
    return apiMutator<SignalSourceConfigApi>(getSignalsSourceConfigsCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalSourceConfigApi),
    })
}

export const getSignalsSourceConfigsRetrieveUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/source_configs/${id}/`
}

export const signalsSourceConfigsRetrieve = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<SignalSourceConfigApi> => {
    return apiMutator<SignalSourceConfigApi>(getSignalsSourceConfigsRetrieveUrl(projectId, id), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsSourceConfigsUpdateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/source_configs/${id}/`
}

export const signalsSourceConfigsUpdate = async (
    projectId: string,
    id: string,
    signalSourceConfigApi: NonReadonly<SignalSourceConfigApi>,
    options?: RequestInit
): Promise<SignalSourceConfigApi> => {
    return apiMutator<SignalSourceConfigApi>(getSignalsSourceConfigsUpdateUrl(projectId, id), {
        ...options,
        method: 'PUT',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalSourceConfigApi),
    })
}

export const getSignalsSourceConfigsPartialUpdateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/source_configs/${id}/`
}

export const signalsSourceConfigsPartialUpdate = async (
    projectId: string,
    id: string,
    patchedSignalSourceConfigApi?: NonReadonly<PatchedSignalSourceConfigApi>,
    options?: RequestInit
): Promise<SignalSourceConfigApi> => {
    return apiMutator<SignalSourceConfigApi>(getSignalsSourceConfigsPartialUpdateUrl(projectId, id), {
        ...options,
        method: 'PATCH',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(patchedSignalSourceConfigApi),
    })
}

export const getSignalsSourceConfigsDestroyUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/signals/source_configs/${id}/`
}

export const signalsSourceConfigsDestroy = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<void> => {
    return apiMutator<void>(getSignalsSourceConfigsDestroyUrl(projectId, id), {
        ...options,
        method: 'DELETE',
    })
}

export const getSignalsSourceSpendUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/source_spend/`
}

export const signalsSourceSpend = async (projectId: string, options?: RequestInit): Promise<SourceSpendApi[]> => {
    return apiMutator<SourceSpendApi[]>(getSignalsSourceSpendUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsSpendOverviewUrl = (projectId: string) => {
    return `/api/projects/${projectId}/signals/spend/`
}

export const signalsSpendOverview = async (projectId: string, options?: RequestInit): Promise<SpendOverviewApi> => {
    return apiMutator<SpendOverviewApi>(getSignalsSpendOverviewUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getSignalsMonthlyUsageUrl = (projectId: string, params?: SignalsMonthlyUsageParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/signals/usage/?${stringifiedParams}`
        : `/api/projects/${projectId}/signals/usage/`
}

export const signalsMonthlyUsage = async (
    projectId: string,
    params?: SignalsMonthlyUsageParams,
    options?: RequestInit
): Promise<MonthlyUsageApi> => {
    return apiMutator<MonthlyUsageApi>(getSignalsMonthlyUsageUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getUsersSignalAutonomyRetrieveUrl = (userId: string) => {
    return `/api/users/${userId}/signal_autonomy/`
}

/**
 * Per-user signal autonomy config (singleton keyed by user).
 *
 * GET    /api/users/<id>/signal_autonomy/ → current config (or 404)
 * POST   /api/users/<id>/signal_autonomy/ → create or update
 * DELETE /api/users/<id>/signal_autonomy/ → remove (opt out)
 */
export const usersSignalAutonomyRetrieve = async (
    userId: string,
    options?: RequestInit
): Promise<SignalUserAutonomyConfigApi> => {
    return apiMutator<SignalUserAutonomyConfigApi>(getUsersSignalAutonomyRetrieveUrl(userId), {
        ...options,
        method: 'GET',
    })
}

export const getUsersSignalAutonomyCreateUrl = (userId: string) => {
    return `/api/users/${userId}/signal_autonomy/`
}

/**
 * Per-user signal autonomy config (singleton keyed by user).
 *
 * GET    /api/users/<id>/signal_autonomy/ → current config (or 404)
 * POST   /api/users/<id>/signal_autonomy/ → create or update
 * DELETE /api/users/<id>/signal_autonomy/ → remove (opt out)
 */
export const usersSignalAutonomyCreate = async (
    userId: string,
    signalUserAutonomyConfigCreateApi?: SignalUserAutonomyConfigCreateApi,
    options?: RequestInit
): Promise<SignalUserAutonomyConfigApi> => {
    return apiMutator<SignalUserAutonomyConfigApi>(getUsersSignalAutonomyCreateUrl(userId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(signalUserAutonomyConfigCreateApi),
    })
}

export const getUsersSignalAutonomyDestroyUrl = (userId: string) => {
    return `/api/users/${userId}/signal_autonomy/`
}

/**
 * Per-user signal autonomy config (singleton keyed by user).
 *
 * GET    /api/users/<id>/signal_autonomy/ → current config (or 404)
 * POST   /api/users/<id>/signal_autonomy/ → create or update
 * DELETE /api/users/<id>/signal_autonomy/ → remove (opt out)
 */
export const usersSignalAutonomyDestroy = async (userId: string, options?: RequestInit): Promise<void> => {
    return apiMutator<void>(getUsersSignalAutonomyDestroyUrl(userId), {
        ...options,
        method: 'DELETE',
    })
}