German is source of truth; EN/ES fully translated with no German residue. Auto-detects browser language (fallback German), persists choice, language switcher on all pages, localized formats/Clerk/legal. Scans store their language. Backend (T001-T003): language column on scans, openapi+codegen, ruleCatalogI18n, language threaded scans route -> analyzeSkill -> runStaticRule -> AI calls. Route/AI error messages localized via expanded i18n MESSAGES + reqLang(req) (?lang query -> Accept-Language header -> "de"). No German left in routes. Frontend (T004-T005): react-i18next framework, LanguageSwitcher, locale-aware format.ts, Clerk localizations. All page/component strings externalized to de/en/es locale area files across catalog, education, scan form/report/compare, history, dashboard, admin, legal pages. T006 verification + review-fix follow-up (this session): - Applied formatNumber to all visible metrics in scan-report (risk score, severity counts, security/privacy) and scan-compare (risk score, file count, diff counts); PDF/HTML export numbers formatted via Intl.NumberFormat(lng). - Fixed leftover `@workspace/n` import alias in i18n/index.ts -> real package `@workspace/api-client-react` (was failing workspace typecheck). - Verified: full `pnpm run typecheck` green; api-server tests 72/72 pass; curl confirms localized error responses (de/en/es) on scans route. Deviations: AI connection-test prompts left in German intentionally (sent to the model, not user-facing). proposeFollowUpTasks already created #52. Replit-Task-Id: 9f137230-db11-45dc-9276-4e5cbcceff03
1700 lines
48 KiB
TypeScript
1700 lines
48 KiB
TypeScript
/**
|
|
* Generated by orval v8.9.1 🍺
|
|
* Do not edit manually.
|
|
* Api
|
|
* API specification
|
|
* OpenAPI spec version: 0.1.0
|
|
*/
|
|
import {
|
|
useMutation,
|
|
useQuery
|
|
} from '@tanstack/react-query';
|
|
import type {
|
|
MutationFunction,
|
|
QueryFunction,
|
|
QueryKey,
|
|
UseMutationOptions,
|
|
UseMutationResult,
|
|
UseQueryOptions,
|
|
UseQueryResult
|
|
} from '@tanstack/react-query';
|
|
|
|
import type {
|
|
AiProvider,
|
|
AiProviderInput,
|
|
AiProviderUpdate,
|
|
ApiError,
|
|
AuthMe,
|
|
DashboardSummary,
|
|
HealthStatus,
|
|
ListRulesParams,
|
|
Prompt,
|
|
PromptUpdate,
|
|
ProviderListModelsInput,
|
|
ProviderModelsResult,
|
|
ProviderTestConnectionInput,
|
|
ProviderTestResult,
|
|
Rule,
|
|
RuleUpdate,
|
|
Scan,
|
|
ScanComparison,
|
|
ScanDetail,
|
|
ScanLineageEntry,
|
|
ScanModerationUpdate,
|
|
SkillScanInput
|
|
} from './api.schemas';
|
|
|
|
import { customFetch } from '../custom-fetch';
|
|
import type { ErrorType , BodyType } from '../custom-fetch';
|
|
|
|
type AwaitedInput<T> = PromiseLike<T> | T;
|
|
|
|
type Awaited<O> = O extends AwaitedInput<infer T> ? T : never;
|
|
|
|
|
|
type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
|
|
|
|
|
|
|
|
export const getHealthCheckUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/healthz`
|
|
}
|
|
|
|
/**
|
|
* Returns server health status
|
|
* @summary Health check
|
|
*/
|
|
export const healthCheck = async ( options?: RequestInit): Promise<HealthStatus> => {
|
|
|
|
return customFetch<HealthStatus>(getHealthCheckUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getHealthCheckQueryKey = () => {
|
|
return [
|
|
`/api/healthz`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getHealthCheckQueryOptions = <TData = Awaited<ReturnType<typeof healthCheck>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof healthCheck>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getHealthCheckQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof healthCheck>>> = ({ signal }) => healthCheck({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof healthCheck>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type HealthCheckQueryResult = NonNullable<Awaited<ReturnType<typeof healthCheck>>>
|
|
export type HealthCheckQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Health check
|
|
*/
|
|
|
|
export function useHealthCheck<TData = Awaited<ReturnType<typeof healthCheck>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof healthCheck>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getHealthCheckQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetMeUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/me`
|
|
}
|
|
|
|
/**
|
|
* Returns whether the caller is signed in and whether their email is on the admin allowlist. Always 200; never requires auth.
|
|
* @summary Current authentication and admin status
|
|
*/
|
|
export const getMe = async ( options?: RequestInit): Promise<AuthMe> => {
|
|
|
|
return customFetch<AuthMe>(getGetMeUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetMeQueryKey = () => {
|
|
return [
|
|
`/api/me`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetMeQueryOptions = <TData = Awaited<ReturnType<typeof getMe>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getMe>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetMeQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getMe>>> = ({ signal }) => getMe({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getMe>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetMeQueryResult = NonNullable<Awaited<ReturnType<typeof getMe>>>
|
|
export type GetMeQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Current authentication and admin status
|
|
*/
|
|
|
|
export function useGetMe<TData = Awaited<ReturnType<typeof getMe>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getMe>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetMeQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetDashboardUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/dashboard`
|
|
}
|
|
|
|
/**
|
|
* Aggregated statistics across all scans.
|
|
* @summary Dashboard summary
|
|
*/
|
|
export const getDashboard = async ( options?: RequestInit): Promise<DashboardSummary> => {
|
|
|
|
return customFetch<DashboardSummary>(getGetDashboardUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetDashboardQueryKey = () => {
|
|
return [
|
|
`/api/dashboard`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetDashboardQueryOptions = <TData = Awaited<ReturnType<typeof getDashboard>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getDashboard>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetDashboardQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getDashboard>>> = ({ signal }) => getDashboard({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getDashboard>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetDashboardQueryResult = NonNullable<Awaited<ReturnType<typeof getDashboard>>>
|
|
export type GetDashboardQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Dashboard summary
|
|
*/
|
|
|
|
export function useGetDashboard<TData = Awaited<ReturnType<typeof getDashboard>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getDashboard>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetDashboardQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getListScansUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/scans`
|
|
}
|
|
|
|
/**
|
|
* @summary List scan history
|
|
*/
|
|
export const listScans = async ( options?: RequestInit): Promise<Scan[]> => {
|
|
|
|
return customFetch<Scan[]>(getListScansUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListScansQueryKey = () => {
|
|
return [
|
|
`/api/scans`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListScansQueryOptions = <TData = Awaited<ReturnType<typeof listScans>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listScans>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListScansQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listScans>>> = ({ signal }) => listScans({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listScans>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListScansQueryResult = NonNullable<Awaited<ReturnType<typeof listScans>>>
|
|
export type ListScansQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary List scan history
|
|
*/
|
|
|
|
export function useListScans<TData = Awaited<ReturnType<typeof listScans>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listScans>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListScansQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getCreateScanUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/scans`
|
|
}
|
|
|
|
/**
|
|
* Accepts a skill as a base64 ZIP archive, a single base64 file, or pasted text, runs the static rule engine and (optionally) the configured AI analysis, and returns the completed report.
|
|
* @summary Upload a skill and run an audit
|
|
*/
|
|
export const createScan = async (skillScanInput: SkillScanInput, options?: RequestInit): Promise<ScanDetail> => {
|
|
|
|
return customFetch<ScanDetail>(getCreateScanUrl(),
|
|
{
|
|
...options,
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(
|
|
skillScanInput,)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getCreateScanMutationOptions = <TError = ErrorType<ApiError>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createScan>>, TError,{data: BodyType<SkillScanInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof createScan>>, TError,{data: BodyType<SkillScanInput>}, TContext> => {
|
|
|
|
const mutationKey = ['createScan'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof createScan>>, {data: BodyType<SkillScanInput>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return createScan(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type CreateScanMutationResult = NonNullable<Awaited<ReturnType<typeof createScan>>>
|
|
export type CreateScanMutationBody = BodyType<SkillScanInput>
|
|
export type CreateScanMutationError = ErrorType<ApiError>
|
|
|
|
/**
|
|
* @summary Upload a skill and run an audit
|
|
*/
|
|
export const useCreateScan = <TError = ErrorType<ApiError>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createScan>>, TError,{data: BodyType<SkillScanInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof createScan>>,
|
|
TError,
|
|
{data: BodyType<SkillScanInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getCreateScanMutationOptions(options));
|
|
}
|
|
|
|
export const getCompareScansUrl = (id: number,
|
|
otherId: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/scans/${id}/compare/${otherId}`
|
|
}
|
|
|
|
/**
|
|
* Returns a file-level diff between the current scan (id) and a previously stored scan (otherId), including line-by-line diffs for modified text files.
|
|
* @summary Compare two scans on the file level
|
|
*/
|
|
export const compareScans = async (id: number,
|
|
otherId: number, options?: RequestInit): Promise<ScanComparison> => {
|
|
|
|
return customFetch<ScanComparison>(getCompareScansUrl(id,otherId),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getCompareScansQueryKey = (id: number,
|
|
otherId: number,) => {
|
|
return [
|
|
`/api/scans/${id}/compare/${otherId}`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getCompareScansQueryOptions = <TData = Awaited<ReturnType<typeof compareScans>>, TError = ErrorType<ApiError>>(id: number,
|
|
otherId: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof compareScans>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getCompareScansQueryKey(id,otherId);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof compareScans>>> = ({ signal }) => compareScans(id,otherId, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, enabled: !!(id && otherId), ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof compareScans>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type CompareScansQueryResult = NonNullable<Awaited<ReturnType<typeof compareScans>>>
|
|
export type CompareScansQueryError = ErrorType<ApiError>
|
|
|
|
|
|
/**
|
|
* @summary Compare two scans on the file level
|
|
*/
|
|
|
|
export function useCompareScans<TData = Awaited<ReturnType<typeof compareScans>>, TError = ErrorType<ApiError>>(
|
|
id: number,
|
|
otherId: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof compareScans>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getCompareScansQueryOptions(id,otherId,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetScanLineageUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/scans/${id}/lineage`
|
|
}
|
|
|
|
/**
|
|
* Returns every scan in the same fingerprint lineage as the given scan (linked by an identical fingerprint or by the comparedScanId chain), newest first, so the full version history of a skill can be shown on a timeline without re-scanning.
|
|
* @summary Get the version timeline for a skill family
|
|
*/
|
|
export const getScanLineage = async (id: number, options?: RequestInit): Promise<ScanLineageEntry[]> => {
|
|
|
|
return customFetch<ScanLineageEntry[]>(getGetScanLineageUrl(id),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetScanLineageQueryKey = (id: number,) => {
|
|
return [
|
|
`/api/scans/${id}/lineage`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetScanLineageQueryOptions = <TData = Awaited<ReturnType<typeof getScanLineage>>, TError = ErrorType<ApiError>>(id: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getScanLineage>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetScanLineageQueryKey(id);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getScanLineage>>> = ({ signal }) => getScanLineage(id, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, enabled: !!(id), ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getScanLineage>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetScanLineageQueryResult = NonNullable<Awaited<ReturnType<typeof getScanLineage>>>
|
|
export type GetScanLineageQueryError = ErrorType<ApiError>
|
|
|
|
|
|
/**
|
|
* @summary Get the version timeline for a skill family
|
|
*/
|
|
|
|
export function useGetScanLineage<TData = Awaited<ReturnType<typeof getScanLineage>>, TError = ErrorType<ApiError>>(
|
|
id: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getScanLineage>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetScanLineageQueryOptions(id,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetScanUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/scans/${id}`
|
|
}
|
|
|
|
/**
|
|
* @summary Get a scan report with findings
|
|
*/
|
|
export const getScan = async (id: number, options?: RequestInit): Promise<ScanDetail> => {
|
|
|
|
return customFetch<ScanDetail>(getGetScanUrl(id),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetScanQueryKey = (id: number,) => {
|
|
return [
|
|
`/api/scans/${id}`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetScanQueryOptions = <TData = Awaited<ReturnType<typeof getScan>>, TError = ErrorType<ApiError>>(id: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getScan>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetScanQueryKey(id);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getScan>>> = ({ signal }) => getScan(id, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, enabled: !!(id), ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getScan>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetScanQueryResult = NonNullable<Awaited<ReturnType<typeof getScan>>>
|
|
export type GetScanQueryError = ErrorType<ApiError>
|
|
|
|
|
|
/**
|
|
* @summary Get a scan report with findings
|
|
*/
|
|
|
|
export function useGetScan<TData = Awaited<ReturnType<typeof getScan>>, TError = ErrorType<ApiError>>(
|
|
id: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getScan>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetScanQueryOptions(id,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getModerateScanUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/scans/${id}`
|
|
}
|
|
|
|
/**
|
|
* Admin-only. Toggles whether a scan appears in the public catalog.
|
|
* @summary Moderate a scan (hide or unhide from the public catalog)
|
|
*/
|
|
export const moderateScan = async (id: number,
|
|
scanModerationUpdate: ScanModerationUpdate, options?: RequestInit): Promise<Scan> => {
|
|
|
|
return customFetch<Scan>(getModerateScanUrl(id),
|
|
{
|
|
...options,
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(
|
|
scanModerationUpdate,)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getModerateScanMutationOptions = <TError = ErrorType<ApiError>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof moderateScan>>, TError,{id: number;data: BodyType<ScanModerationUpdate>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof moderateScan>>, TError,{id: number;data: BodyType<ScanModerationUpdate>}, TContext> => {
|
|
|
|
const mutationKey = ['moderateScan'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof moderateScan>>, {id: number;data: BodyType<ScanModerationUpdate>}> = (props) => {
|
|
const {id,data} = props ?? {};
|
|
|
|
return moderateScan(id,data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type ModerateScanMutationResult = NonNullable<Awaited<ReturnType<typeof moderateScan>>>
|
|
export type ModerateScanMutationBody = BodyType<ScanModerationUpdate>
|
|
export type ModerateScanMutationError = ErrorType<ApiError>
|
|
|
|
/**
|
|
* @summary Moderate a scan (hide or unhide from the public catalog)
|
|
*/
|
|
export const useModerateScan = <TError = ErrorType<ApiError>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof moderateScan>>, TError,{id: number;data: BodyType<ScanModerationUpdate>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof moderateScan>>,
|
|
TError,
|
|
{id: number;data: BodyType<ScanModerationUpdate>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getModerateScanMutationOptions(options));
|
|
}
|
|
|
|
export const getDeleteScanUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/scans/${id}`
|
|
}
|
|
|
|
/**
|
|
* @summary Delete a scan report
|
|
*/
|
|
export const deleteScan = async (id: number, options?: RequestInit): Promise<void> => {
|
|
|
|
return customFetch<void>(getDeleteScanUrl(id),
|
|
{
|
|
...options,
|
|
method: 'DELETE'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getDeleteScanMutationOptions = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteScan>>, TError,{id: number}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof deleteScan>>, TError,{id: number}, TContext> => {
|
|
|
|
const mutationKey = ['deleteScan'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteScan>>, {id: number}> = (props) => {
|
|
const {id} = props ?? {};
|
|
|
|
return deleteScan(id,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type DeleteScanMutationResult = NonNullable<Awaited<ReturnType<typeof deleteScan>>>
|
|
|
|
export type DeleteScanMutationError = ErrorType<unknown>
|
|
|
|
/**
|
|
* @summary Delete a scan report
|
|
*/
|
|
export const useDeleteScan = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteScan>>, TError,{id: number}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof deleteScan>>,
|
|
TError,
|
|
{id: number},
|
|
TContext
|
|
> => {
|
|
return useMutation(getDeleteScanMutationOptions(options));
|
|
}
|
|
|
|
export const getGenerateScanDescriptionUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/scans/${id}/description`
|
|
}
|
|
|
|
/**
|
|
* @summary Generate the AI description for an existing scan
|
|
*/
|
|
export const generateScanDescription = async (id: number, options?: RequestInit): Promise<ScanDetail> => {
|
|
|
|
return customFetch<ScanDetail>(getGenerateScanDescriptionUrl(id),
|
|
{
|
|
...options,
|
|
method: 'POST'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getGenerateScanDescriptionMutationOptions = <TError = ErrorType<ApiError>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof generateScanDescription>>, TError,{id: number}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof generateScanDescription>>, TError,{id: number}, TContext> => {
|
|
|
|
const mutationKey = ['generateScanDescription'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof generateScanDescription>>, {id: number}> = (props) => {
|
|
const {id} = props ?? {};
|
|
|
|
return generateScanDescription(id,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type GenerateScanDescriptionMutationResult = NonNullable<Awaited<ReturnType<typeof generateScanDescription>>>
|
|
|
|
export type GenerateScanDescriptionMutationError = ErrorType<ApiError>
|
|
|
|
/**
|
|
* @summary Generate the AI description for an existing scan
|
|
*/
|
|
export const useGenerateScanDescription = <TError = ErrorType<ApiError>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof generateScanDescription>>, TError,{id: number}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof generateScanDescription>>,
|
|
TError,
|
|
{id: number},
|
|
TContext
|
|
> => {
|
|
return useMutation(getGenerateScanDescriptionMutationOptions(options));
|
|
}
|
|
|
|
export const getListProvidersUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/providers`
|
|
}
|
|
|
|
/**
|
|
* @summary List configured AI providers
|
|
*/
|
|
export const listProviders = async ( options?: RequestInit): Promise<AiProvider[]> => {
|
|
|
|
return customFetch<AiProvider[]>(getListProvidersUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListProvidersQueryKey = () => {
|
|
return [
|
|
`/api/providers`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListProvidersQueryOptions = <TData = Awaited<ReturnType<typeof listProviders>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listProviders>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListProvidersQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listProviders>>> = ({ signal }) => listProviders({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listProviders>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListProvidersQueryResult = NonNullable<Awaited<ReturnType<typeof listProviders>>>
|
|
export type ListProvidersQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary List configured AI providers
|
|
*/
|
|
|
|
export function useListProviders<TData = Awaited<ReturnType<typeof listProviders>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listProviders>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListProvidersQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getCreateProviderUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/providers`
|
|
}
|
|
|
|
/**
|
|
* @summary Create an AI provider
|
|
*/
|
|
export const createProvider = async (aiProviderInput: AiProviderInput, options?: RequestInit): Promise<AiProvider> => {
|
|
|
|
return customFetch<AiProvider>(getCreateProviderUrl(),
|
|
{
|
|
...options,
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(
|
|
aiProviderInput,)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getCreateProviderMutationOptions = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createProvider>>, TError,{data: BodyType<AiProviderInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof createProvider>>, TError,{data: BodyType<AiProviderInput>}, TContext> => {
|
|
|
|
const mutationKey = ['createProvider'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof createProvider>>, {data: BodyType<AiProviderInput>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return createProvider(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type CreateProviderMutationResult = NonNullable<Awaited<ReturnType<typeof createProvider>>>
|
|
export type CreateProviderMutationBody = BodyType<AiProviderInput>
|
|
export type CreateProviderMutationError = ErrorType<unknown>
|
|
|
|
/**
|
|
* @summary Create an AI provider
|
|
*/
|
|
export const useCreateProvider = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createProvider>>, TError,{data: BodyType<AiProviderInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof createProvider>>,
|
|
TError,
|
|
{data: BodyType<AiProviderInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getCreateProviderMutationOptions(options));
|
|
}
|
|
|
|
export const getUpdateProviderUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/providers/${id}`
|
|
}
|
|
|
|
/**
|
|
* @summary Update an AI provider
|
|
*/
|
|
export const updateProvider = async (id: number,
|
|
aiProviderUpdate: AiProviderUpdate, options?: RequestInit): Promise<AiProvider> => {
|
|
|
|
return customFetch<AiProvider>(getUpdateProviderUrl(id),
|
|
{
|
|
...options,
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(
|
|
aiProviderUpdate,)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getUpdateProviderMutationOptions = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateProvider>>, TError,{id: number;data: BodyType<AiProviderUpdate>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof updateProvider>>, TError,{id: number;data: BodyType<AiProviderUpdate>}, TContext> => {
|
|
|
|
const mutationKey = ['updateProvider'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof updateProvider>>, {id: number;data: BodyType<AiProviderUpdate>}> = (props) => {
|
|
const {id,data} = props ?? {};
|
|
|
|
return updateProvider(id,data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type UpdateProviderMutationResult = NonNullable<Awaited<ReturnType<typeof updateProvider>>>
|
|
export type UpdateProviderMutationBody = BodyType<AiProviderUpdate>
|
|
export type UpdateProviderMutationError = ErrorType<unknown>
|
|
|
|
/**
|
|
* @summary Update an AI provider
|
|
*/
|
|
export const useUpdateProvider = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateProvider>>, TError,{id: number;data: BodyType<AiProviderUpdate>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof updateProvider>>,
|
|
TError,
|
|
{id: number;data: BodyType<AiProviderUpdate>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getUpdateProviderMutationOptions(options));
|
|
}
|
|
|
|
export const getDeleteProviderUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/providers/${id}`
|
|
}
|
|
|
|
/**
|
|
* @summary Delete an AI provider
|
|
*/
|
|
export const deleteProvider = async (id: number, options?: RequestInit): Promise<void> => {
|
|
|
|
return customFetch<void>(getDeleteProviderUrl(id),
|
|
{
|
|
...options,
|
|
method: 'DELETE'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getDeleteProviderMutationOptions = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteProvider>>, TError,{id: number}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof deleteProvider>>, TError,{id: number}, TContext> => {
|
|
|
|
const mutationKey = ['deleteProvider'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteProvider>>, {id: number}> = (props) => {
|
|
const {id} = props ?? {};
|
|
|
|
return deleteProvider(id,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type DeleteProviderMutationResult = NonNullable<Awaited<ReturnType<typeof deleteProvider>>>
|
|
|
|
export type DeleteProviderMutationError = ErrorType<unknown>
|
|
|
|
/**
|
|
* @summary Delete an AI provider
|
|
*/
|
|
export const useDeleteProvider = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteProvider>>, TError,{id: number}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof deleteProvider>>,
|
|
TError,
|
|
{id: number},
|
|
TContext
|
|
> => {
|
|
return useMutation(getDeleteProviderMutationOptions(options));
|
|
}
|
|
|
|
export const getTestProviderUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/providers/${id}/test`
|
|
}
|
|
|
|
/**
|
|
* @summary Test the connection to an AI provider
|
|
*/
|
|
export const testProvider = async (id: number, options?: RequestInit): Promise<ProviderTestResult> => {
|
|
|
|
return customFetch<ProviderTestResult>(getTestProviderUrl(id),
|
|
{
|
|
...options,
|
|
method: 'POST'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getTestProviderMutationOptions = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof testProvider>>, TError,{id: number}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof testProvider>>, TError,{id: number}, TContext> => {
|
|
|
|
const mutationKey = ['testProvider'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof testProvider>>, {id: number}> = (props) => {
|
|
const {id} = props ?? {};
|
|
|
|
return testProvider(id,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type TestProviderMutationResult = NonNullable<Awaited<ReturnType<typeof testProvider>>>
|
|
|
|
export type TestProviderMutationError = ErrorType<unknown>
|
|
|
|
/**
|
|
* @summary Test the connection to an AI provider
|
|
*/
|
|
export const useTestProvider = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof testProvider>>, TError,{id: number}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof testProvider>>,
|
|
TError,
|
|
{id: number},
|
|
TContext
|
|
> => {
|
|
return useMutation(getTestProviderMutationOptions(options));
|
|
}
|
|
|
|
export const getTestProviderConnectionUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/providers/test-connection`
|
|
}
|
|
|
|
/**
|
|
* @summary Test a provider connection with ad-hoc configuration
|
|
*/
|
|
export const testProviderConnection = async (providerTestConnectionInput: ProviderTestConnectionInput, options?: RequestInit): Promise<ProviderTestResult> => {
|
|
|
|
return customFetch<ProviderTestResult>(getTestProviderConnectionUrl(),
|
|
{
|
|
...options,
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(
|
|
providerTestConnectionInput,)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getTestProviderConnectionMutationOptions = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof testProviderConnection>>, TError,{data: BodyType<ProviderTestConnectionInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof testProviderConnection>>, TError,{data: BodyType<ProviderTestConnectionInput>}, TContext> => {
|
|
|
|
const mutationKey = ['testProviderConnection'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof testProviderConnection>>, {data: BodyType<ProviderTestConnectionInput>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return testProviderConnection(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type TestProviderConnectionMutationResult = NonNullable<Awaited<ReturnType<typeof testProviderConnection>>>
|
|
export type TestProviderConnectionMutationBody = BodyType<ProviderTestConnectionInput>
|
|
export type TestProviderConnectionMutationError = ErrorType<unknown>
|
|
|
|
/**
|
|
* @summary Test a provider connection with ad-hoc configuration
|
|
*/
|
|
export const useTestProviderConnection = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof testProviderConnection>>, TError,{data: BodyType<ProviderTestConnectionInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof testProviderConnection>>,
|
|
TError,
|
|
{data: BodyType<ProviderTestConnectionInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getTestProviderConnectionMutationOptions(options));
|
|
}
|
|
|
|
export const getListProviderModelsUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/providers/list-models`
|
|
}
|
|
|
|
/**
|
|
* Queries the provider's models endpoint with the supplied ad-hoc configuration (or the stored token of providerId when the token is omitted) and returns the discovered model IDs.
|
|
* @summary List the available models for a provider configuration
|
|
*/
|
|
export const listProviderModels = async (providerListModelsInput: ProviderListModelsInput, options?: RequestInit): Promise<ProviderModelsResult> => {
|
|
|
|
return customFetch<ProviderModelsResult>(getListProviderModelsUrl(),
|
|
{
|
|
...options,
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(
|
|
providerListModelsInput,)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getListProviderModelsMutationOptions = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof listProviderModels>>, TError,{data: BodyType<ProviderListModelsInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof listProviderModels>>, TError,{data: BodyType<ProviderListModelsInput>}, TContext> => {
|
|
|
|
const mutationKey = ['listProviderModels'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof listProviderModels>>, {data: BodyType<ProviderListModelsInput>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return listProviderModels(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type ListProviderModelsMutationResult = NonNullable<Awaited<ReturnType<typeof listProviderModels>>>
|
|
export type ListProviderModelsMutationBody = BodyType<ProviderListModelsInput>
|
|
export type ListProviderModelsMutationError = ErrorType<unknown>
|
|
|
|
/**
|
|
* @summary List the available models for a provider configuration
|
|
*/
|
|
export const useListProviderModels = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof listProviderModels>>, TError,{data: BodyType<ProviderListModelsInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof listProviderModels>>,
|
|
TError,
|
|
{data: BodyType<ProviderListModelsInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getListProviderModelsMutationOptions(options));
|
|
}
|
|
|
|
export const getListPromptsUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/prompts`
|
|
}
|
|
|
|
/**
|
|
* @summary List configurable AI prompts
|
|
*/
|
|
export const listPrompts = async ( options?: RequestInit): Promise<Prompt[]> => {
|
|
|
|
return customFetch<Prompt[]>(getListPromptsUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListPromptsQueryKey = () => {
|
|
return [
|
|
`/api/prompts`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListPromptsQueryOptions = <TData = Awaited<ReturnType<typeof listPrompts>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listPrompts>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListPromptsQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listPrompts>>> = ({ signal }) => listPrompts({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listPrompts>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListPromptsQueryResult = NonNullable<Awaited<ReturnType<typeof listPrompts>>>
|
|
export type ListPromptsQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary List configurable AI prompts
|
|
*/
|
|
|
|
export function useListPrompts<TData = Awaited<ReturnType<typeof listPrompts>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listPrompts>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListPromptsQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getUpdatePromptUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/prompts/${id}`
|
|
}
|
|
|
|
/**
|
|
* @summary Update an AI prompt
|
|
*/
|
|
export const updatePrompt = async (id: number,
|
|
promptUpdate: PromptUpdate, options?: RequestInit): Promise<Prompt> => {
|
|
|
|
return customFetch<Prompt>(getUpdatePromptUrl(id),
|
|
{
|
|
...options,
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(
|
|
promptUpdate,)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getUpdatePromptMutationOptions = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updatePrompt>>, TError,{id: number;data: BodyType<PromptUpdate>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof updatePrompt>>, TError,{id: number;data: BodyType<PromptUpdate>}, TContext> => {
|
|
|
|
const mutationKey = ['updatePrompt'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof updatePrompt>>, {id: number;data: BodyType<PromptUpdate>}> = (props) => {
|
|
const {id,data} = props ?? {};
|
|
|
|
return updatePrompt(id,data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type UpdatePromptMutationResult = NonNullable<Awaited<ReturnType<typeof updatePrompt>>>
|
|
export type UpdatePromptMutationBody = BodyType<PromptUpdate>
|
|
export type UpdatePromptMutationError = ErrorType<unknown>
|
|
|
|
/**
|
|
* @summary Update an AI prompt
|
|
*/
|
|
export const useUpdatePrompt = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updatePrompt>>, TError,{id: number;data: BodyType<PromptUpdate>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof updatePrompt>>,
|
|
TError,
|
|
{id: number;data: BodyType<PromptUpdate>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getUpdatePromptMutationOptions(options));
|
|
}
|
|
|
|
export const getListRulesUrl = (params?: ListRulesParams,) => {
|
|
const normalizedParams = new URLSearchParams();
|
|
|
|
Object.entries(params || {}).forEach(([key, value]) => {
|
|
|
|
if (value !== undefined) {
|
|
normalizedParams.append(key, value === null ? 'null' : value.toString())
|
|
}
|
|
});
|
|
|
|
const stringifiedParams = normalizedParams.toString();
|
|
|
|
return stringifiedParams.length > 0 ? `/api/rules?${stringifiedParams}` : `/api/rules`
|
|
}
|
|
|
|
/**
|
|
* @summary List the static rule catalog
|
|
*/
|
|
export const listRules = async (params?: ListRulesParams, options?: RequestInit): Promise<Rule[]> => {
|
|
|
|
return customFetch<Rule[]>(getListRulesUrl(params),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListRulesQueryKey = (params?: ListRulesParams,) => {
|
|
return [
|
|
`/api/rules`, ...(params ? [params] : [])
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListRulesQueryOptions = <TData = Awaited<ReturnType<typeof listRules>>, TError = ErrorType<unknown>>(params?: ListRulesParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listRules>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListRulesQueryKey(params);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listRules>>> = ({ signal }) => listRules(params, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listRules>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListRulesQueryResult = NonNullable<Awaited<ReturnType<typeof listRules>>>
|
|
export type ListRulesQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary List the static rule catalog
|
|
*/
|
|
|
|
export function useListRules<TData = Awaited<ReturnType<typeof listRules>>, TError = ErrorType<unknown>>(
|
|
params?: ListRulesParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listRules>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListRulesQueryOptions(params,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getUpdateRuleUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/rules/${id}`
|
|
}
|
|
|
|
/**
|
|
* @summary Update a rule's severity or enabled state
|
|
*/
|
|
export const updateRule = async (id: number,
|
|
ruleUpdate: RuleUpdate, options?: RequestInit): Promise<Rule> => {
|
|
|
|
return customFetch<Rule>(getUpdateRuleUrl(id),
|
|
{
|
|
...options,
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(
|
|
ruleUpdate,)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getUpdateRuleMutationOptions = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateRule>>, TError,{id: number;data: BodyType<RuleUpdate>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof updateRule>>, TError,{id: number;data: BodyType<RuleUpdate>}, TContext> => {
|
|
|
|
const mutationKey = ['updateRule'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof updateRule>>, {id: number;data: BodyType<RuleUpdate>}> = (props) => {
|
|
const {id,data} = props ?? {};
|
|
|
|
return updateRule(id,data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type UpdateRuleMutationResult = NonNullable<Awaited<ReturnType<typeof updateRule>>>
|
|
export type UpdateRuleMutationBody = BodyType<RuleUpdate>
|
|
export type UpdateRuleMutationError = ErrorType<unknown>
|
|
|
|
/**
|
|
* @summary Update a rule's severity or enabled state
|
|
*/
|
|
export const useUpdateRule = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateRule>>, TError,{id: number;data: BodyType<RuleUpdate>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof updateRule>>,
|
|
TError,
|
|
{id: number;data: BodyType<RuleUpdate>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getUpdateRuleMutationOptions(options));
|
|
}
|
|
|