import {z} from 'zod' export type ModelProvider = 'OPENAI' | 'AZURE_OPENAI' | 'ANTHROPIC' | 'GOOGLE' | 'DEEPSEEK' | 'XAI' | 'OLLAMA' | 'AWS' | 'CEREBRAS' | 'FIREWORKS' | 'GROQ' | 'MOONSHOT' | 'MINIMAX' | 'PERPLEXITY' | 'TOGETHER' | 'ZAI' | 'META'; export type TextContentPart = {type: 'text', text: string}; export type ToolCallFunction = {type: 'function', name: string, arguments: string}; export type ToolCallContentPart = {type: 'tool_call', tool_call_id: string, tool_call: ToolCallFunction}; export type ToolResultContentPart = {type: 'tool_result', tool_call_id: string, tool_result: boolean | number | number | string | {[key: string]: unknown} | Array | null}; export type PromptMessage = {role: 'user' | 'assistant' | 'model' | 'ai' | 'tool' | 'system' | 'developer', content: string | Array}; export type PromptChatTemplate = {type: 'chat', messages: Array}; export type PromptStringTemplate = {type: 'string', template: string}; export type PromptTemplateType = 'STR' | 'CHAT'; export type PromptTemplateFormat = 'MUSTACHE' | 'F_STRING' | 'NONE'; export type PromptOpenAIInvocationParametersContent = {temperature?: number | undefined, max_tokens?: number | undefined, max_completion_tokens?: number | undefined, frequency_penalty?: number | undefined, presence_penalty?: number | undefined, top_p?: number | undefined, seed?: number | undefined, stop?: Array | undefined, reasoning_effort?: ('none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh') | undefined, extra_body?: {[key: string]: unknown} | undefined}; export type PromptOpenAIInvocationParameters = {type: 'openai', openai: PromptOpenAIInvocationParametersContent}; export type PromptAzureOpenAIInvocationParametersContent = {temperature?: number | undefined, max_tokens?: number | undefined, max_completion_tokens?: number | undefined, frequency_penalty?: number | undefined, presence_penalty?: number | undefined, top_p?: number | undefined, seed?: number | undefined, stop?: Array | undefined, reasoning_effort?: ('none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh') | undefined, extra_body?: {[key: string]: unknown} | undefined}; export type PromptAzureOpenAIInvocationParameters = {type: 'azure_openai', azure_openai: PromptAzureOpenAIInvocationParametersContent}; export type PromptAnthropicOutputConfig = {effort?: ('low' | 'medium' | 'high' | 'xhigh' | 'max') | undefined}; export type PromptAnthropicThinkingConfigDisabled = {type: 'disabled'}; export type PromptAnthropicThinkingConfigEnabled = {type: 'enabled', budget_tokens: number, display?: ('summarized' | 'omitted') | undefined}; export type PromptAnthropicThinkingConfigAdaptive = {type: 'adaptive', display?: ('summarized' | 'omitted') | undefined}; export type PromptAnthropicInvocationParametersContent = {max_tokens: number, temperature?: number | undefined, top_p?: number | undefined, stop_sequences?: Array | undefined, output_config?: PromptAnthropicOutputConfig | undefined, thinking?: (PromptAnthropicThinkingConfigDisabled | PromptAnthropicThinkingConfigEnabled | PromptAnthropicThinkingConfigAdaptive) | undefined, extra_body?: {[key: string]: unknown} | undefined}; export type PromptAnthropicInvocationParameters = {type: 'anthropic', anthropic: PromptAnthropicInvocationParametersContent}; export type PromptGoogleThinkingConfig = {thinking_budget?: number | undefined, thinking_level?: ('minimal' | 'low' | 'medium' | 'high') | undefined, include_thoughts?: boolean | undefined}; export type PromptGoogleInvocationParametersContent = {temperature?: number | undefined, max_output_tokens?: number | undefined, stop_sequences?: Array | undefined, presence_penalty?: number | undefined, frequency_penalty?: number | undefined, top_p?: number | undefined, top_k?: number | undefined, thinking_config?: PromptGoogleThinkingConfig | undefined}; export type PromptGoogleInvocationParameters = {type: 'google', google: PromptGoogleInvocationParametersContent}; export type PromptDeepSeekInvocationParametersContent = {temperature?: number | undefined, max_tokens?: number | undefined, max_completion_tokens?: number | undefined, frequency_penalty?: number | undefined, presence_penalty?: number | undefined, top_p?: number | undefined, seed?: number | undefined, stop?: Array | undefined, reasoning_effort?: ('none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh') | undefined, extra_body?: {[key: string]: unknown} | undefined}; export type PromptDeepSeekInvocationParameters = {type: 'deepseek', deepseek: PromptDeepSeekInvocationParametersContent}; export type PromptXAIInvocationParametersContent = {temperature?: number | undefined, max_tokens?: number | undefined, max_completion_tokens?: number | undefined, frequency_penalty?: number | undefined, presence_penalty?: number | undefined, top_p?: number | undefined, seed?: number | undefined, stop?: Array | undefined, reasoning_effort?: ('none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh') | undefined, extra_body?: {[key: string]: unknown} | undefined}; export type PromptXAIInvocationParameters = {type: 'xai', xai: PromptXAIInvocationParametersContent}; export type PromptOllamaInvocationParametersContent = {temperature?: number | undefined, max_tokens?: number | undefined, max_completion_tokens?: number | undefined, frequency_penalty?: number | undefined, presence_penalty?: number | undefined, top_p?: number | undefined, seed?: number | undefined, stop?: Array | undefined, reasoning_effort?: ('none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh') | undefined, extra_body?: {[key: string]: unknown} | undefined}; export type PromptOllamaInvocationParameters = {type: 'ollama', ollama: PromptOllamaInvocationParametersContent}; export type PromptAwsInvocationParametersContent = {max_tokens?: number | undefined, temperature?: number | undefined, top_p?: number | undefined, stop_sequences?: Array | undefined}; export type PromptAwsInvocationParameters = {type: 'aws', aws: PromptAwsInvocationParametersContent}; export type PromptCerebrasInvocationParametersContent = {temperature?: number | undefined, max_tokens?: number | undefined, max_completion_tokens?: number | undefined, frequency_penalty?: number | undefined, presence_penalty?: number | undefined, top_p?: number | undefined, seed?: number | undefined, stop?: Array | undefined, reasoning_effort?: ('none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh') | undefined, extra_body?: {[key: string]: unknown} | undefined}; export type PromptCerebrasInvocationParameters = {type: 'cerebras', cerebras: PromptCerebrasInvocationParametersContent}; export type PromptFireworksInvocationParametersContent = {temperature?: number | undefined, max_tokens?: number | undefined, max_completion_tokens?: number | undefined, frequency_penalty?: number | undefined, presence_penalty?: number | undefined, top_p?: number | undefined, seed?: number | undefined, stop?: Array | undefined, reasoning_effort?: ('none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh') | undefined, extra_body?: {[key: string]: unknown} | undefined}; export type PromptFireworksInvocationParameters = {type: 'fireworks', fireworks: PromptFireworksInvocationParametersContent}; export type PromptGroqInvocationParametersContent = {temperature?: number | undefined, max_tokens?: number | undefined, max_completion_tokens?: number | undefined, frequency_penalty?: number | undefined, presence_penalty?: number | undefined, top_p?: number | undefined, seed?: number | undefined, stop?: Array | undefined, reasoning_effort?: ('none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh') | undefined, extra_body?: {[key: string]: unknown} | undefined}; export type PromptGroqInvocationParameters = {type: 'groq', groq: PromptGroqInvocationParametersContent}; export type PromptMoonshotInvocationParametersContent = {temperature?: number | undefined, max_tokens?: number | undefined, max_completion_tokens?: number | undefined, frequency_penalty?: number | undefined, presence_penalty?: number | undefined, top_p?: number | undefined, seed?: number | undefined, stop?: Array | undefined, reasoning_effort?: ('none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh') | undefined, extra_body?: {[key: string]: unknown} | undefined}; export type PromptMoonshotInvocationParameters = {type: 'moonshot', moonshot: PromptMoonshotInvocationParametersContent}; export type PromptPerplexityInvocationParametersContent = {temperature?: number | undefined, max_tokens?: number | undefined, max_completion_tokens?: number | undefined, frequency_penalty?: number | undefined, presence_penalty?: number | undefined, top_p?: number | undefined, seed?: number | undefined, stop?: Array | undefined, reasoning_effort?: ('none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh') | undefined, extra_body?: {[key: string]: unknown} | undefined}; export type PromptPerplexityInvocationParameters = {type: 'perplexity', perplexity: PromptPerplexityInvocationParametersContent}; export type PromptTogetherInvocationParametersContent = {temperature?: number | undefined, max_tokens?: number | undefined, max_completion_tokens?: number | undefined, frequency_penalty?: number | undefined, presence_penalty?: number | undefined, top_p?: number | undefined, seed?: number | undefined, stop?: Array | undefined, reasoning_effort?: ('none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh') | undefined, extra_body?: {[key: string]: unknown} | undefined}; export type PromptTogetherInvocationParameters = {type: 'together', together: PromptTogetherInvocationParametersContent}; export type PromptZAIInvocationParametersContent = {temperature?: number | undefined, max_tokens?: number | undefined, max_completion_tokens?: number | undefined, frequency_penalty?: number | undefined, presence_penalty?: number | undefined, top_p?: number | undefined, seed?: number | undefined, stop?: Array | undefined, reasoning_effort?: ('none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh') | undefined, extra_body?: {[key: string]: unknown} | undefined}; export type PromptZAIInvocationParameters = {type: 'zai', zai: PromptZAIInvocationParametersContent}; export type PromptMetaInvocationParametersContent = {temperature?: number | undefined, max_tokens?: number | undefined, max_completion_tokens?: number | undefined, frequency_penalty?: number | undefined, presence_penalty?: number | undefined, top_p?: number | undefined, seed?: number | undefined, stop?: Array | undefined, reasoning_effort?: ('none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh') | undefined, extra_body?: {[key: string]: unknown} | undefined}; export type PromptMetaInvocationParameters = {type: 'meta', meta: PromptMetaInvocationParametersContent}; export type PromptToolFunctionDefinition = {name: string, description?: string | undefined, parameters?: {[key: string]: unknown} | undefined, strict?: boolean | undefined}; export type PromptToolFunction = {type: 'function', function: PromptToolFunctionDefinition}; export type PromptToolRaw = {type: 'raw', raw: {[key: string]: unknown}}; export type PromptToolChoiceNone = {type: 'none'}; export type PromptToolChoiceZeroOrMore = {type: 'zero_or_more'}; export type PromptToolChoiceOneOrMore = {type: 'one_or_more'}; export type PromptToolChoiceSpecificFunctionTool = {type: 'specific_function', function_name: string}; export type PromptTools = {type: 'tools', tools: Array, tool_choice?: (PromptToolChoiceNone | PromptToolChoiceZeroOrMore | PromptToolChoiceOneOrMore | PromptToolChoiceSpecificFunctionTool) | undefined, disable_parallel_tool_calls?: boolean | undefined}; export type PromptResponseFormatJSONSchemaDefinition = {name: string, description?: string | undefined, schema?: {[key: string]: unknown} | undefined, strict?: boolean | undefined}; export type PromptResponseFormatJSONSchema = {type: 'json_schema', json_schema: PromptResponseFormatJSONSchemaDefinition}; export type PromptVersionData = {description?: (string | null) | undefined, metadata?: {[key: string]: unknown} | undefined, model_provider: ModelProvider, model_name: string, template: PromptChatTemplate | PromptStringTemplate, template_type: PromptTemplateType, template_format: PromptTemplateFormat, invocation_parameters: PromptOpenAIInvocationParameters | PromptAzureOpenAIInvocationParameters | PromptAnthropicInvocationParameters | PromptGoogleInvocationParameters | PromptDeepSeekInvocationParameters | PromptXAIInvocationParameters | PromptOllamaInvocationParameters | PromptAwsInvocationParameters | PromptCerebrasInvocationParameters | PromptFireworksInvocationParameters | PromptGroqInvocationParameters | PromptMoonshotInvocationParameters | PromptPerplexityInvocationParameters | PromptTogetherInvocationParameters | PromptZAIInvocationParameters | PromptMetaInvocationParameters, tools?: (PromptTools | null) | undefined, response_format?: (PromptResponseFormatJSONSchema | null) | undefined}; export type Identifier = string; export type PromptVersionTagData = {name: Identifier, description?: (string | null) | undefined}; export type CreatePromptVersionRequestBody = {version: PromptVersionData, tags?: (Array | null) | undefined}; export type CreateApiV1PromptsPromptIdentifierVersionsArgs = {prompt_identifier: string, body: CreatePromptVersionRequestBody}; export type CreateApiV1PromptsPromptIdentifierVersionsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const modelProvider = z.enum(["OPENAI", "AZURE_OPENAI", "ANTHROPIC", "GOOGLE", "DEEPSEEK", "XAI", "OLLAMA", "AWS", "CEREBRAS", "FIREWORKS", "GROQ", "MOONSHOT", "MINIMAX", "PERPLEXITY", "TOGETHER", "ZAI", "META"]); export const textContentPart = z.object({type: z.literal("text"), text: z.string()}); export const toolCallFunction = z.object({type: z.literal("function"), name: z.string(), arguments: z.string()}); export const toolCallContentPart = z.object({type: z.literal("tool_call"), tool_call_id: z.string(), tool_call: toolCallFunction}); export const toolResultContentPart = z.object({type: z.literal("tool_result"), tool_call_id: z.string(), tool_result: z.union([z.boolean(), z.number().int(), z.number(), z.string(), z.record(z.string(), z.unknown()), z.array(z.unknown())]).nullable()}); export const promptMessage = z.object({role: z.enum(["user", "assistant", "model", "ai", "tool", "system", "developer"]), content: z.union([z.string(), z.array(z.discriminatedUnion("type", [textContentPart, toolCallContentPart, toolResultContentPart]))])}); export const promptChatTemplate = z.object({type: z.literal("chat"), messages: z.array(promptMessage)}); export const promptStringTemplate = z.object({type: z.literal("string"), template: z.string()}); export const promptTemplateType = z.enum(["STR", "CHAT"]); export const promptTemplateFormat = z.enum(["MUSTACHE", "F_STRING", "NONE"]); export const promptOpenAIInvocationParametersContent = z.object({temperature: z.number().optional(), max_tokens: z.number().int().optional(), max_completion_tokens: z.number().int().optional(), frequency_penalty: z.number().optional(), presence_penalty: z.number().optional(), top_p: z.number().optional(), seed: z.number().int().optional(), stop: z.array(z.string()).optional(), reasoning_effort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional(), extra_body: z.record(z.string(), z.unknown()).optional()}); export const promptOpenAIInvocationParameters = z.object({type: z.literal("openai"), openai: promptOpenAIInvocationParametersContent}); export const promptAzureOpenAIInvocationParametersContent = z.object({temperature: z.number().optional(), max_tokens: z.number().int().optional(), max_completion_tokens: z.number().int().optional(), frequency_penalty: z.number().optional(), presence_penalty: z.number().optional(), top_p: z.number().optional(), seed: z.number().int().optional(), stop: z.array(z.string()).optional(), reasoning_effort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional(), extra_body: z.record(z.string(), z.unknown()).optional()}); export const promptAzureOpenAIInvocationParameters = z.object({type: z.literal("azure_openai"), azure_openai: promptAzureOpenAIInvocationParametersContent}); export const promptAnthropicOutputConfig = z.object({effort: z.enum(["low", "medium", "high", "xhigh", "max"]).optional()}); export const promptAnthropicThinkingConfigDisabled = z.object({type: z.literal("disabled")}); export const promptAnthropicThinkingConfigEnabled = z.object({type: z.literal("enabled"), budget_tokens: z.number().int().gte(1024), display: z.enum(["summarized", "omitted"]).optional()}); export const promptAnthropicThinkingConfigAdaptive = z.object({type: z.literal("adaptive"), display: z.enum(["summarized", "omitted"]).optional()}); export const promptAnthropicInvocationParametersContent = z.object({max_tokens: z.number().int(), temperature: z.number().optional(), top_p: z.number().optional(), stop_sequences: z.array(z.string()).optional(), output_config: promptAnthropicOutputConfig.optional(), thinking: z.discriminatedUnion("type", [promptAnthropicThinkingConfigDisabled, promptAnthropicThinkingConfigEnabled, promptAnthropicThinkingConfigAdaptive]).optional(), extra_body: z.record(z.string(), z.unknown()).optional()}); export const promptAnthropicInvocationParameters = z.object({type: z.literal("anthropic"), anthropic: promptAnthropicInvocationParametersContent}); export const promptGoogleThinkingConfig = z.object({thinking_budget: z.number().int().optional(), thinking_level: z.enum(["minimal", "low", "medium", "high"]).optional(), include_thoughts: z.boolean().optional()}); export const promptGoogleInvocationParametersContent = z.object({temperature: z.number().optional(), max_output_tokens: z.number().int().optional(), stop_sequences: z.array(z.string()).optional(), presence_penalty: z.number().optional(), frequency_penalty: z.number().optional(), top_p: z.number().optional(), top_k: z.number().int().optional(), thinking_config: promptGoogleThinkingConfig.optional()}); export const promptGoogleInvocationParameters = z.object({type: z.literal("google"), google: promptGoogleInvocationParametersContent}); export const promptDeepSeekInvocationParametersContent = z.object({temperature: z.number().optional(), max_tokens: z.number().int().optional(), max_completion_tokens: z.number().int().optional(), frequency_penalty: z.number().optional(), presence_penalty: z.number().optional(), top_p: z.number().optional(), seed: z.number().int().optional(), stop: z.array(z.string()).optional(), reasoning_effort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional(), extra_body: z.record(z.string(), z.unknown()).optional()}); export const promptDeepSeekInvocationParameters = z.object({type: z.literal("deepseek"), deepseek: promptDeepSeekInvocationParametersContent}); export const promptXAIInvocationParametersContent = z.object({temperature: z.number().optional(), max_tokens: z.number().int().optional(), max_completion_tokens: z.number().int().optional(), frequency_penalty: z.number().optional(), presence_penalty: z.number().optional(), top_p: z.number().optional(), seed: z.number().int().optional(), stop: z.array(z.string()).optional(), reasoning_effort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional(), extra_body: z.record(z.string(), z.unknown()).optional()}); export const promptXAIInvocationParameters = z.object({type: z.literal("xai"), xai: promptXAIInvocationParametersContent}); export const promptOllamaInvocationParametersContent = z.object({temperature: z.number().optional(), max_tokens: z.number().int().optional(), max_completion_tokens: z.number().int().optional(), frequency_penalty: z.number().optional(), presence_penalty: z.number().optional(), top_p: z.number().optional(), seed: z.number().int().optional(), stop: z.array(z.string()).optional(), reasoning_effort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional(), extra_body: z.record(z.string(), z.unknown()).optional()}); export const promptOllamaInvocationParameters = z.object({type: z.literal("ollama"), ollama: promptOllamaInvocationParametersContent}); export const promptAwsInvocationParametersContent = z.object({max_tokens: z.number().int().optional(), temperature: z.number().optional(), top_p: z.number().optional(), stop_sequences: z.array(z.string()).optional()}); export const promptAwsInvocationParameters = z.object({type: z.literal("aws"), aws: promptAwsInvocationParametersContent}); export const promptCerebrasInvocationParametersContent = z.object({temperature: z.number().optional(), max_tokens: z.number().int().optional(), max_completion_tokens: z.number().int().optional(), frequency_penalty: z.number().optional(), presence_penalty: z.number().optional(), top_p: z.number().optional(), seed: z.number().int().optional(), stop: z.array(z.string()).optional(), reasoning_effort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional(), extra_body: z.record(z.string(), z.unknown()).optional()}); export const promptCerebrasInvocationParameters = z.object({type: z.literal("cerebras"), cerebras: promptCerebrasInvocationParametersContent}); export const promptFireworksInvocationParametersContent = z.object({temperature: z.number().optional(), max_tokens: z.number().int().optional(), max_completion_tokens: z.number().int().optional(), frequency_penalty: z.number().optional(), presence_penalty: z.number().optional(), top_p: z.number().optional(), seed: z.number().int().optional(), stop: z.array(z.string()).optional(), reasoning_effort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional(), extra_body: z.record(z.string(), z.unknown()).optional()}); export const promptFireworksInvocationParameters = z.object({type: z.literal("fireworks"), fireworks: promptFireworksInvocationParametersContent}); export const promptGroqInvocationParametersContent = z.object({temperature: z.number().optional(), max_tokens: z.number().int().optional(), max_completion_tokens: z.number().int().optional(), frequency_penalty: z.number().optional(), presence_penalty: z.number().optional(), top_p: z.number().optional(), seed: z.number().int().optional(), stop: z.array(z.string()).optional(), reasoning_effort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional(), extra_body: z.record(z.string(), z.unknown()).optional()}); export const promptGroqInvocationParameters = z.object({type: z.literal("groq"), groq: promptGroqInvocationParametersContent}); export const promptMoonshotInvocationParametersContent = z.object({temperature: z.number().optional(), max_tokens: z.number().int().optional(), max_completion_tokens: z.number().int().optional(), frequency_penalty: z.number().optional(), presence_penalty: z.number().optional(), top_p: z.number().optional(), seed: z.number().int().optional(), stop: z.array(z.string()).optional(), reasoning_effort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional(), extra_body: z.record(z.string(), z.unknown()).optional()}); export const promptMoonshotInvocationParameters = z.object({type: z.literal("moonshot"), moonshot: promptMoonshotInvocationParametersContent}); export const promptPerplexityInvocationParametersContent = z.object({temperature: z.number().optional(), max_tokens: z.number().int().optional(), max_completion_tokens: z.number().int().optional(), frequency_penalty: z.number().optional(), presence_penalty: z.number().optional(), top_p: z.number().optional(), seed: z.number().int().optional(), stop: z.array(z.string()).optional(), reasoning_effort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional(), extra_body: z.record(z.string(), z.unknown()).optional()}); export const promptPerplexityInvocationParameters = z.object({type: z.literal("perplexity"), perplexity: promptPerplexityInvocationParametersContent}); export const promptTogetherInvocationParametersContent = z.object({temperature: z.number().optional(), max_tokens: z.number().int().optional(), max_completion_tokens: z.number().int().optional(), frequency_penalty: z.number().optional(), presence_penalty: z.number().optional(), top_p: z.number().optional(), seed: z.number().int().optional(), stop: z.array(z.string()).optional(), reasoning_effort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional(), extra_body: z.record(z.string(), z.unknown()).optional()}); export const promptTogetherInvocationParameters = z.object({type: z.literal("together"), together: promptTogetherInvocationParametersContent}); export const promptZAIInvocationParametersContent = z.object({temperature: z.number().optional(), max_tokens: z.number().int().optional(), max_completion_tokens: z.number().int().optional(), frequency_penalty: z.number().optional(), presence_penalty: z.number().optional(), top_p: z.number().optional(), seed: z.number().int().optional(), stop: z.array(z.string()).optional(), reasoning_effort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional(), extra_body: z.record(z.string(), z.unknown()).optional()}); export const promptZAIInvocationParameters = z.object({type: z.literal("zai"), zai: promptZAIInvocationParametersContent}); export const promptMetaInvocationParametersContent = z.object({temperature: z.number().optional(), max_tokens: z.number().int().optional(), max_completion_tokens: z.number().int().optional(), frequency_penalty: z.number().optional(), presence_penalty: z.number().optional(), top_p: z.number().optional(), seed: z.number().int().optional(), stop: z.array(z.string()).optional(), reasoning_effort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional(), extra_body: z.record(z.string(), z.unknown()).optional()}); export const promptMetaInvocationParameters = z.object({type: z.literal("meta"), meta: promptMetaInvocationParametersContent}); export const promptToolFunctionDefinition = z.object({name: z.string(), description: z.string().optional(), parameters: z.record(z.string(), z.unknown()).optional(), strict: z.boolean().optional()}); export const promptToolFunction = z.object({type: z.literal("function"), function: promptToolFunctionDefinition}); export const promptToolRaw = z.object({type: z.literal("raw"), raw: z.record(z.string(), z.unknown())}); export const promptToolChoiceNone = z.object({type: z.literal("none")}); export const promptToolChoiceZeroOrMore = z.object({type: z.literal("zero_or_more")}); export const promptToolChoiceOneOrMore = z.object({type: z.literal("one_or_more")}); export const promptToolChoiceSpecificFunctionTool = z.object({type: z.literal("specific_function"), function_name: z.string()}); export const promptTools = z.object({type: z.literal("tools"), tools: z.array(z.discriminatedUnion("type", [promptToolFunction, promptToolRaw])), tool_choice: z.discriminatedUnion("type", [promptToolChoiceNone, promptToolChoiceZeroOrMore, promptToolChoiceOneOrMore, promptToolChoiceSpecificFunctionTool]).optional(), disable_parallel_tool_calls: z.boolean().optional()}); export const promptResponseFormatJSONSchemaDefinition = z.object({name: z.string(), description: z.string().optional(), schema: z.record(z.string(), z.unknown()).optional(), strict: z.boolean().optional()}); export const promptResponseFormatJSONSchema = z.object({type: z.literal("json_schema"), json_schema: promptResponseFormatJSONSchemaDefinition}); export const promptVersion = z.object({description: z.string().nullable().optional(), metadata: z.record(z.string(), z.unknown()).optional(), model_provider: modelProvider, model_name: z.string(), template: z.discriminatedUnion("type", [promptChatTemplate, promptStringTemplate]), template_type: promptTemplateType, template_format: promptTemplateFormat, invocation_parameters: z.discriminatedUnion("type", [promptOpenAIInvocationParameters, promptAzureOpenAIInvocationParameters, promptAnthropicInvocationParameters, promptGoogleInvocationParameters, promptDeepSeekInvocationParameters, promptXAIInvocationParameters, promptOllamaInvocationParameters, promptAwsInvocationParameters, promptCerebrasInvocationParameters, promptFireworksInvocationParameters, promptGroqInvocationParameters, promptMoonshotInvocationParameters, promptPerplexityInvocationParameters, promptTogetherInvocationParameters, promptZAIInvocationParameters, promptMetaInvocationParameters]), tools: promptTools.nullable().optional(), response_format: promptResponseFormatJSONSchema.nullable().optional(), id: z.string(), created_at: z.string()}); export const createPromptVersionResponseBody = z.object({data: promptVersion}); 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 }; /** * Create prompt version * * POST /v1/prompts/{prompt_identifier}/versions */ export const createApiV1PromptsPromptIdentifierVersions = async (args: CreateApiV1PromptsPromptIdentifierVersionsArgs, options: CreateApiV1PromptsPromptIdentifierVersionsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/prompts/${encodeURIComponent(String(args.prompt_identifier))}/versions${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(createPromptVersionResponseBody, await res.json()) };