import {z} from 'zod' export type ProtosAiV1GetMemoriesByIdsRequest = {deploymentId?: string | undefined, memoryIds?: Array | undefined}; export type CreateApiApiAiDeploymentsDeploymentIdMemoriesIdsArgs = {deploymentId: string, body: ProtosAiV1GetMemoriesByIdsRequest}; export type CreateApiApiAiDeploymentsDeploymentIdMemoriesIdsOptions = {baseUrl: string, SemgrepWebToken?: string | undefined, fetch?: typeof fetch | undefined}; export const protosAiV1AiMemorySource = z.object({note: z.string().optional(), createdBy: z.string().optional(), createdAt: z.string().optional(), sampleIssueId: z.string().optional(), prCommentUrl: z.string().optional(), reviewCommentId: z.string().optional()}); export const protosAiV1AiMemorySuggestionSources = z.object({sources: z.array(protosAiV1AiMemorySource).optional()}); export const protosAiV1MemoryPreanalysisCounts = z.object({newlyTruePositive: z.string().optional(), newlyFalsePositive: z.string().optional(), remainsTruePositive: z.string().optional(), remainsFalsePositive: z.string().optional()}); export const protosAiV1Memory = z.object({id: z.string().optional(), content: z.string().optional(), ruleId: z.string().optional(), ruleName: z.string().optional(), repositoryId: z.string().optional(), repositoryName: z.string().optional(), createdAt: z.string().optional(), createdBy: z.string().optional(), context: z.array(z.string()).optional(), stage: z.enum(["AI_MEMORY_STAGE_LIVE", "AI_MEMORY_STAGE_SUGGESTED", "AI_MEMORY_STAGE_DELETED"]).optional(), pathPrefixes: z.array(z.string()).optional(), suggestionSources: protosAiV1AiMemorySuggestionSources.optional(), preanalysisCounts: protosAiV1MemoryPreanalysisCounts.optional(), vulnerabilityClass: z.string().optional(), projectTagId: z.number().int().optional()}); export const protosAiV1GetMemoriesByIdsResponse = z.object({memories: z.array(protosAiV1Memory).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 }; /** * Get memories by ids * * POST /api/ai/deployments/{deploymentId}/memories/ids * * Also accepts auth: SemgrepJWT */ export const createApiApiAiDeploymentsDeploymentIdMemoriesIds = async (args: CreateApiApiAiDeploymentsDeploymentIdMemoriesIdsArgs, options: CreateApiApiAiDeploymentsDeploymentIdMemoriesIdsOptions) => { const {baseUrl, fetch: fetchFn = fetch, SemgrepWebToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (SemgrepWebToken !== undefined) headers.set('authorization', `Bearer ${SemgrepWebToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/ai/deployments/${encodeURIComponent(String(args.deploymentId))}/memories/ids${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(protosAiV1GetMemoriesByIdsResponse, await res.json()) };