import {z} from 'zod' export type OpenAISystemMessage = {content: string, role?: 'system' | undefined}; export type OpenAIDeveloperMessage = {content: string, role?: 'developer' | undefined}; export type OpenAITextBlock = {text: string, type?: 'text' | undefined}; export type OpenAIImageURL = {url: string, detail?: ('auto' | 'low' | 'high' | null) | undefined}; export type OpenAIImageBlock = {image_url: OpenAIImageURL, type?: 'image_url' | undefined}; export type OpenAIAudioBase64 = {data: string, format: 'wav' | 'mp3'}; export type OpenAIAudioBlock = {input_audio: OpenAIAudioBase64, type?: 'input_audio' | undefined}; export type OpenAIFileURL = {filename: string, file_data: string}; export type OpenAIFileBlock = {file: OpenAIFileURL, type?: 'file' | undefined}; export type OpenAIUserMessage = {content: string | Array, role?: 'user' | undefined}; export type OpenAIRefusalBlock = {refusal: string, type?: 'refusal' | undefined}; export type OpenAIAudio = {id: string, data?: (string | null) | undefined, transcript?: (string | null) | undefined}; export type OpenAIFunction = {arguments: string, name: string}; export type OpenAIToolCall = {id: string, function: OpenAIFunction, type?: 'function' | undefined}; export type OpenAIAssistantMessage = {content?: (string | Array | Array | OpenAIRefusalBlock | null) | undefined, name?: (string | null) | undefined, audio?: (OpenAIAudio | null) | undefined, refusal?: (string | null) | undefined, tool_calls?: (Array | null) | undefined, role?: 'assistant' | undefined}; export type OpenAIToolMessage = {content: string | Array, tool_call_id: string, role?: 'tool' | undefined}; export type AnthropicTextBlock = {text: string, type?: 'text' | undefined}; export type AnthropicBase64Source = {data: string, media_type: string, type?: 'base64' | undefined}; export type AnthropicURLSource = {url: string, type?: 'url' | undefined}; export type AnthropicImageBlock = {source: AnthropicBase64Source | AnthropicURLSource, type?: 'image' | undefined}; export type AnthropicFileBlock = {source: AnthropicBase64Source | AnthropicURLSource, type?: 'document' | undefined}; export type JSONValue = boolean | number | number | string | {[key: string]: JSONValue} | Array | null; export type AnthropicToolUseBlock = {id: string, input: JSONValue, name: string, type?: 'tool_use' | undefined}; export type AnthropicToolResultBlock = {tool_use_id: string, content: string | Array, is_error?: (boolean | null) | undefined, type?: 'tool_result' | undefined}; export type AnthropicMessage = {content: string | Array, role: 'user' | 'assistant'}; export type SimpleProviderMessage = {role: 'system' | 'developer' | 'user' | 'assistant', content: string}; export type VertexTextPart = {text: string}; export type VertexInlineData = {mimeType: string, data: string}; export type VertexInlineDataPart = {inlineData: VertexInlineData}; export type VertexFunctionCall = {name: string, args: {[key: string]: unknown}}; export type VertexFunctionCallPart = {functionCall: VertexFunctionCall, thoughtSignature?: (string | null) | undefined}; export type VertexFunctionResponse = {name: string, response: JSONValue}; export type VertexFunctionResponsePart = {functionResponse: VertexFunctionResponse}; export type VertexMessage = {parts: Array, role?: ('model' | 'user') | undefined}; export type BedrockTextBlock = {text: string, type?: 'text' | undefined}; export type BedrockJsonBlock = {json: JSONValue, type?: 'json' | undefined}; export type BedrockSource = {bytes: string}; export type BedrockImageContent = {format: string, source: BedrockSource}; export type BedrockImageBlock = {image: BedrockImageContent, type?: 'image' | undefined}; export type BedrockDocumentContent = {format: string, name: string, source: BedrockSource}; export type BedrockDocumentBlock = {document: BedrockDocumentContent, type?: 'document' | undefined}; export type BedrockToolUseBlockContent = {toolUseId: string, name: string, input: JSONValue}; export type BedrockToolUseBlock = {toolUse: BedrockToolUseBlockContent, type?: 'toolUse' | undefined}; export type BedrockToolResultBlockContent = {toolUseId: string, content: Array, status?: ('success' | 'error' | null) | undefined}; export type BedrockToolResultBlock = {toolResult: BedrockToolResultBlockContent, type?: 'toolResult' | undefined}; export type BedrockConverseMessage = {role: 'user' | 'assistant', content: Array}; export type OpenAIResponsesOutputTextContent = {text: string, annotations?: Array | undefined, type?: 'output_text' | undefined}; export type OpenAIResponsesInputTextContent = {text: string, type?: 'input_text' | undefined}; export type OpenAIResponsesRefusalContent = {refusal: string, type?: 'refusal' | undefined}; export type OpenAIResponsesInputImageContent = {image_url: string, detail?: ('auto' | 'low' | 'high' | null) | undefined, type?: 'input_image' | undefined}; export type OpenAIResponsesInputFileContent = {file_data: string, filename?: (string | null) | undefined, type?: 'input_file' | undefined}; export type OpenAIResponsesMessageItem = {role: 'user' | 'system' | 'developer' | 'assistant', content: Array | string, id?: (string | null) | undefined, status?: (string | null) | undefined, type?: 'message' | undefined}; export type OpenAIResponsesFunctionCallItem = {name: string, arguments: string, call_id?: (string | null) | undefined, id?: (string | null) | undefined, status?: (string | null) | undefined, type?: 'function_call' | undefined}; export type OpenAIResponsesFunctionCallOutputItem = {output: string, call_id?: (string | null) | undefined, id?: (string | null) | undefined, type?: 'function_call_output' | undefined}; export type OpenAIResponsesReasoningItem = {id?: (string | null) | undefined, summary?: (Array | null) | undefined, type?: 'reasoning' | undefined}; export type OpenAIResponsesBuiltinToolItem = {type: string, id?: (string | null) | undefined, status?: (string | null) | undefined}; export type CreateApiApiV2ProjectsProjectIdCompletionsCompletionIdArgs = {project_id: string, completion_id: string, body: {new_messages?: (Array | Array | Array | Array | Array | Array | null) | undefined, eval_results?: ({[key: string]: number | boolean} | null) | undefined}}; export type CreateApiApiV2ProjectsProjectIdCompletionsCompletionIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV2ProjectsProjectIdCompletionsCompletionIdResponse = z.object({completion_id: z.string()}); 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 Completion * * POST /api/v2/projects/{project_id}/completions/{completion_id} */ export const createApiApiV2ProjectsProjectIdCompletionsCompletionId = async (args: CreateApiApiV2ProjectsProjectIdCompletionsCompletionIdArgs, options: CreateApiApiV2ProjectsProjectIdCompletionsCompletionIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/projects/${encodeURIComponent(String(args.project_id))}/completions/${encodeURIComponent(String(args.completion_id))}${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(createApiApiV2ProjectsProjectIdCompletionsCompletionIdResponse, await res.json()) };