import {z} from 'zod' export type FieldConfigurationItemMetadata = {min_score?: number | undefined, max_score?: number | undefined, middle_score?: (number | null) | undefined, min_criteria?: string | undefined, max_criteria?: string | undefined, middle_criteria?: (string | null) | undefined}; export type UpdateFieldConfigurationItemRequest = {title?: string | undefined, contents?: string | undefined, description?: string | undefined, promptType?: string | undefined, contentType?: string | undefined, responseType?: string | undefined, options?: Array | undefined, dependsOn?: Array | undefined, maxValues?: (number | null) | undefined, allowLongResponse?: (boolean | null) | undefined, extractQuotes?: (boolean | null) | undefined, analysisLevel?: ('conversation' | 'deal' | 'lead' | 'contact' | 'account') | undefined, metadata?: FieldConfigurationItemMetadata | undefined}; export type PatchApiFieldConfigurationsIdItemsItemIdArgs = {id: string, itemId: string, body: UpdateFieldConfigurationItemRequest}; export type PatchApiFieldConfigurationsIdItemsItemIdOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const fieldConfigurationItemMetadata = z.object({min_score: z.number().optional(), max_score: z.number().optional(), middle_score: z.number().nullable().optional(), min_criteria: z.string().optional(), max_criteria: z.string().optional(), middle_criteria: z.string().nullable().optional()}); export const fieldConfigurationItem = z.object({uuid: z.string(), fieldConfigurationUUID: z.string(), title: z.string(), category: z.enum(["CRM", "Indicators", "BuiltInInsight", "CustomInsight"]), contents: z.string(), description: z.string().optional(), promptType: z.string(), contentType: z.string(), responseType: z.string().optional(), options: z.array(z.string()).optional(), dependsOn: z.array(z.string()).optional(), maxValues: z.number().int().optional(), allowLongResponse: z.boolean(), extractQuotes: z.boolean(), availableToAllClients: z.boolean(), analysisLevel: z.enum(["conversation", "deal", "lead", "contact", "account"]).optional(), metadata: fieldConfigurationItemMetadata.optional(), createdAt: z.string(), lastModifiedAt: z.string()}); export const fieldConfigurationItemResponse = z.object({data: fieldConfigurationItem.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 }; /** * Update Field Configuration Item * * PATCH /field-configurations/{id}/items/{itemId} */ export const patchApiFieldConfigurationsIdItemsItemId = async (args: PatchApiFieldConfigurationsIdItemsItemIdArgs, options?: PatchApiFieldConfigurationsIdItemsItemIdOptions) => { const {baseUrl = "https://api.attention.tech/v2", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("Authorization", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/field-configurations/${encodeURIComponent(String(args.id))}/items/${encodeURIComponent(String(args.itemId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(fieldConfigurationItemResponse, await res.json()) };