import {z} from 'zod' export type PolicyMetricSettings = {verifiedProperties?: Array | undefined, excludedPhrases?: Array | undefined, voicemailScript?: string | undefined, screeningBrief?: string | undefined, toolDefinitionIds?: Array | undefined, knowledgeBaseDocumentIds?: Array | undefined}; export type UpdateMetricPolicyInput = {name?: string | undefined, status?: ('ACTIVE' | 'INACTIVE') | undefined, conditions?: (Array<{conditions: Array<{conditionType: 'AGENT' | 'CALL_SOURCE' | 'CALL_PROPERTY' | 'INTEGRATION', conditionKey: string, conditionOperator?: ('EQUALS' | 'NOT_EQUALS' | 'CONTAINS' | 'STARTS_WITH' | 'GREATER_THAN' | 'LESS_THAN' | 'GREATER_THAN_OR_EQUALS' | 'LESS_THAN_OR_EQUALS' | null) | undefined, conditionValue?: (string | null) | undefined}>}>) | undefined, metrics?: (Array<{id: string, settings?: (PolicyMetricSettings | null) | undefined}>) | undefined}; export type UpdateApiV1MetricPoliciesPolicyIdArgs = {policyId: string, body: UpdateMetricPolicyInput}; export type UpdateApiV1MetricPoliciesPolicyIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const policyMetricSettings = z.object({verifiedProperties: z.array(z.string().min(1).max(200)).optional(), excludedPhrases: z.array(z.string().min(1).max(200)).optional(), voicemailScript: z.string().min(1).max(4000).optional(), screeningBrief: z.string().min(1).max(4000).optional(), toolDefinitionIds: z.array(z.string()).optional(), knowledgeBaseDocumentIds: z.array(z.string()).optional()}); export const metricPolicyResponse = z.object({id: z.string(), name: z.string(), type: z.enum(["SYSTEM", "USER"]), status: z.enum(["ACTIVE", "INACTIVE"]), conditions: z.array(z.object({conditions: z.array(z.object({conditionType: z.enum(["AGENT", "CALL_SOURCE", "CALL_PROPERTY", "INTEGRATION"]), conditionKey: z.string(), conditionOperator: z.enum(["EQUALS", "NOT_EQUALS", "CONTAINS", "STARTS_WITH", "GREATER_THAN", "LESS_THAN", "GREATER_THAN_OR_EQUALS", "LESS_THAN_OR_EQUALS"]).nullable(), conditionValue: z.string().nullable()}))})).nullable(), metrics: z.array(z.object({id: z.string(), settings: policyMetricSettings.nullable()})), createdAt: z.string(), updatedAt: z.string()}); export const updateApiV1MetricPoliciesPolicyIdResponse = z.object({data: metricPolicyResponse}); 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 a metric policy * * PUT /v1/metric/policies/{policyId} */ export const updateApiV1MetricPoliciesPolicyId = async (args: UpdateApiV1MetricPoliciesPolicyIdArgs, options?: UpdateApiV1MetricPoliciesPolicyIdOptions) => { const {baseUrl = "https://api.roark.ai", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/metric/policies/${encodeURIComponent(String(args.policyId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiV1MetricPoliciesPolicyIdResponse, await res.json()) };