import {z} from 'zod' export type GetApiV1AccountIdIncidentsIncidentIdAiSummaryArgs = {accountId: string, incidentId: string}; export type GetApiV1AccountIdIncidentsIncidentIdAiSummaryOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const incidentAiSummaryCommandPayload = z.object({command: z.string().optional(), entityId: z.string().optional(), entityType: z.string().optional(), parameters: z.record(z.string(), z.unknown()).optional()}); export const incidentAiSummaryRecommendedAction = z.object({actionId: z.string().optional(), target: z.string().optional(), rationale: z.string().optional(), source: z.string().optional(), priority: z.number().int().optional(), commandPayload: incidentAiSummaryCommandPayload.optional()}); export const incidentAiSummaryOutput = z.object({name: z.string().optional(), description: z.string().optional(), actionsSummary: z.string().optional(), recommendedActions: z.array(incidentAiSummaryRecommendedAction).optional()}); export const incidentAiSummaryFacts = z.object({factsRelevantHash: z.string().optional(), severity: z.string().optional(), signalSources: z.array(z.string()).optional(), lastUpdatedAt: z.string().optional(), schemaVersion: z.string().optional(), missingTypes: z.array(z.string()).optional()}); export const incidentAiSummary = z.object({accountId: z.string().optional(), incidentId: z.string().optional(), state: z.string().optional(), reason: z.string().optional(), generatedAt: z.string().optional(), confidence: z.number().nullable().optional(), output: incidentAiSummaryOutput.optional(), facts: incidentAiSummaryFacts.optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Retrieves an AI summary for the specified incident. * * GET /v1/{accountId}/incidents/{incidentId}/ai-summary */ export const getApiV1AccountIdIncidentsIncidentIdAiSummary = async (args: GetApiV1AccountIdIncidentsIncidentIdAiSummaryArgs, options?: GetApiV1AccountIdIncidentsIncidentIdAiSummaryOptions) => { const {baseUrl = "https://api.usa.cloud.watchguard.com/rest/threatsync/management", fetch: fetchFn = fetch, ApiKeyAuth, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("WatchGuard-API-Key", ApiKeyAuth) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/${encodeURIComponent(String(args.accountId))}/incidents/${encodeURIComponent(String(args.incidentId))}/ai-summary${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(incidentAiSummary, await res.json()) };