import {z} from 'zod' export type ChatCompletionToolParamFunctionChunk = {name: string, description?: string | undefined, parameters?: {[key: string]: unknown} | undefined, strict?: boolean | undefined, eager_input_streaming?: boolean | undefined}; export type ChatCompletionCachedContent = {type: 'ephemeral', ttl?: ('5m' | '1h') | undefined} | {[key: string]: unknown}; export type ChatCompletionToolParam = {type: 'function' | string, function: ChatCompletionToolParamFunctionChunk, cache_control?: ChatCompletionCachedContent | undefined, allowed_callers?: Array | undefined, eager_input_streaming?: boolean | undefined}; export type ChatCompletionToolCallFunctionChunk = {name?: (string | null) | undefined, arguments?: string | undefined, provider_specific_fields?: ({[key: string]: unknown} | null) | undefined}; export type ChatCompletionToolCallChunk = {id: string | null, type: 'function', function: ChatCompletionToolCallFunctionChunk, index: number}; export type ChatCompletionMessageToolCall = {[key: string]: unknown}; export type ChatCompletionTextObject = {type: 'text', text: string, cache_control?: ChatCompletionCachedContent | undefined}; export type ChatCompletionImageUrlObject = {url: string, detail?: string | undefined, format?: string | undefined}; export type ChatCompletionImageObject = {type: 'image_url', image_url: string | ChatCompletionImageUrlObject}; export type InputAudio = {data: string, format: 'wav' | 'mp3'}; export type ChatCompletionAudioObject = {input_audio: InputAudio, type: 'input_audio'}; export type DocumentObject = {type: 'text', media_type: string, data: string}; export type CitationsObject = {enabled: boolean}; export type ChatCompletionDocumentObject = {type: 'document', source: DocumentObject, title: string, context: string, citations: CitationsObject | null}; export type ChatCompletionVideoUrlObject = {url: string, detail?: string | undefined}; export type ChatCompletionVideoObject = {type: 'video_url', video_url: string | ChatCompletionVideoUrlObject}; export type ChatCompletionFileObjectFile = {file_data?: string | undefined, file_id?: string | undefined, filename?: string | undefined, format?: string | undefined, detail?: string | undefined, video_metadata?: {[key: string]: unknown} | undefined}; export type ChatCompletionFileObject = {type: 'file', file: ChatCompletionFileObjectFile}; export type ChatCompletionUserMessage = {role: 'user', content: string | Array, cache_control?: ChatCompletionCachedContent | undefined}; export type ChatCompletionThinkingBlock = {type: 'thinking', thinking?: string | undefined, signature?: (string | null) | undefined, cache_control?: ({[key: string]: unknown} | ChatCompletionCachedContent | null) | undefined} | {[key: string]: unknown}; export type ChatCompletionRedactedThinkingBlock = {type: 'redacted_thinking', data?: string | undefined, cache_control?: ({[key: string]: unknown} | ChatCompletionCachedContent | null) | undefined} | {[key: string]: unknown}; export type ChatCompletionAssistantToolCall = {id: string | null, type: 'function', function: ChatCompletionToolCallFunctionChunk}; export type ChatCompletionReasoningSummaryTextBlock = {type: 'summary_text', text?: string | undefined} | {[key: string]: unknown}; export type ChatCompletionReasoningItem = {type: 'reasoning', id?: string | undefined, encrypted_content?: (string | null) | undefined, summary?: Array | undefined} | {[key: string]: unknown}; export type ChatCompletionAssistantMessage = {role: 'assistant', content?: (string | Array | null) | undefined, name?: (string | null) | undefined, tool_calls?: (Array | null) | undefined, function_call?: (ChatCompletionToolCallFunctionChunk | null) | undefined, reasoning_content?: (string | null) | undefined, cache_control?: ChatCompletionCachedContent | undefined, thinking_blocks?: (Array | null) | undefined, reasoning_items?: (Array | null) | undefined}; export type ChatCompletionToolReferenceObject = {type: 'tool_reference', tool_name: string}; export type ChatCompletionToolMessage = {role: 'tool', content: string | Array, tool_call_id: string}; export type ChatCompletionSystemMessage = {role: 'system', content: string | Array, name?: string | undefined, cache_control?: ChatCompletionCachedContent | undefined}; export type ChatCompletionFunctionMessage = {role: 'function', content: string | Array | null, name: string, tool_call_id: string | null}; export type ChatCompletionDeveloperMessage = {role: 'developer', content: string | Array, name?: string | undefined, cache_control?: ChatCompletionCachedContent | undefined}; export type GenericGuardrailAPIInputs = {texts?: Array | undefined, images?: Array | undefined, tools?: Array | undefined, tool_calls?: (Array | Array) | undefined, structured_messages?: (Array) | undefined, model?: (string | null) | undefined, stream_holdback_chars?: Array | undefined}; export type TestPoliciesAndGuardrailsRequest = {policy_names?: (Array | null) | undefined, guardrail_names?: (Array | null) | undefined, inputs_list?: Array | undefined, request_data?: {[key: string]: unknown} | undefined, input_type?: ('request' | 'response') | undefined, agent_id?: (string | null) | undefined}; export type CreateApiUtilsTestPoliciesAndGuardrailsArgs = {body: TestPoliciesAndGuardrailsRequest}; export type CreateApiUtilsTestPoliciesAndGuardrailsOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiUtilsTestPoliciesAndGuardrailsResponse = z.unknown(); 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 }; /** * Test Policies And Guardrails * * POST /utils/test_policies_and_guardrails */ export const createApiUtilsTestPoliciesAndGuardrails = async (args: CreateApiUtilsTestPoliciesAndGuardrailsArgs, options: CreateApiUtilsTestPoliciesAndGuardrailsOptions) => { const {baseUrl, 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("x-litellm-api-key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/utils/test_policies_and_guardrails${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(createApiUtilsTestPoliciesAndGuardrailsResponse, await res.json()) };