Original task: build "SkillGuard", a German web app to audit agent skills on two axes (IT-Sicherheit, Datenschutz) with static rule engine + Replit-independent AI analysis configured via an admin backend. This session: - Fixed frontend TS errors: lucide-react name collisions (Badge from ui, Activity from lucide), widened apiType to AiProviderApiType, added queryKey to useGetScan. - Verified all pages render in German (Dashboard, Prüfen, Bericht, Verlauf, Admin) and the full scan flow works end-to-end (malicious sample -> verdict block). Code-review-driven hardening: - POST /api/scans now returns the full ScanDetail (files + findings) to match the OpenAPI contract, instead of only the summary. - AI provider error bodies are redacted (token, Bearer, sk- patterns) before being returned/persisted, and provider fetches now have a 60s timeout. - ZIP parsing now enforces limits (max files, total + per-file size) to mitigate zip-bomb DoS. Updated replit.md (project overview, decisions, gotchas) and added a memory note on lucide-react icon name collisions.
1160 lines
31 KiB
TypeScript
1160 lines
31 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,
|
|
DashboardSummary,
|
|
HealthStatus,
|
|
Prompt,
|
|
PromptUpdate,
|
|
ProviderTestResult,
|
|
Rule,
|
|
RuleUpdate,
|
|
Scan,
|
|
ScanDetail,
|
|
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 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 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 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 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 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 = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/rules`
|
|
}
|
|
|
|
/**
|
|
* @summary List the static rule catalog
|
|
*/
|
|
export const listRules = async ( options?: RequestInit): Promise<Rule[]> => {
|
|
|
|
return customFetch<Rule[]>(getListRulesUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListRulesQueryKey = () => {
|
|
return [
|
|
`/api/rules`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListRulesQueryOptions = <TData = Awaited<ReturnType<typeof listRules>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listRules>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListRulesQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listRules>>> = ({ signal }) => listRules({ 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>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listRules>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListRulesQueryOptions(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));
|
|
}
|
|
|