import {z} from 'zod' export type GetApiApiV2LlmObsV1PromptsPromptIdArgs = {prompt_id: string, label?: string | undefined}; export type GetApiApiV2LlmObsV1PromptsPromptIdOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, appKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const lLMObsPromptChatMessage = z.object({content: z.string(), role: z.string()}); export const lLMObsPromptMessagePlaceholderType = z.literal("placeholder"); export const lLMObsPromptMessagePlaceholder = z.object({name: z.string().min(1), type: lLMObsPromptMessagePlaceholderType}); export const lLMObsPromptChatTemplateItem = z.union([lLMObsPromptChatMessage, lLMObsPromptMessagePlaceholder]); export const lLMObsPromptConfig = z.record(z.string(), z.unknown()); export const lLMObsPromptSDKDataAttributes = z.object({chat_template: z.array(lLMObsPromptChatTemplateItem).optional(), config: lLMObsPromptConfig.optional(), labels: z.array(z.string()).optional(), prompt_id: z.string().optional(), prompt_version_uuid: z.string().optional(), template: z.string().optional(), version: z.string().optional()}); export const lLMObsPromptType = z.literal("prompt-templates"); export const lLMObsPromptSDKData = z.object({attributes: lLMObsPromptSDKDataAttributes, id: z.string(), type: lLMObsPromptType}); export const lLMObsPromptSDKResponse = z.object({data: lLMObsPromptSDKData}); 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 }; /** * Get an Agent Observability prompt * * GET /api/v2/llm-obs/v1/prompts/{prompt_id} * * Also accepts auth: AuthZ */ export const getApiApiV2LlmObsV1PromptsPromptId = async (args: GetApiApiV2LlmObsV1PromptsPromptIdArgs, options?: GetApiApiV2LlmObsV1PromptsPromptIdOptions) => { const {baseUrl = "https://api.datadoghq.com", fetch: fetchFn = fetch, apiKeyAuth, appKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.label != null) query.append("label", String(args.label)) if (apiKeyAuth !== undefined) headers.set("DD-API-KEY", apiKeyAuth) if (appKeyAuth !== undefined) headers.set("DD-APPLICATION-KEY", appKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/llm-obs/v1/prompts/${encodeURIComponent(String(args.prompt_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(lLMObsPromptSDKResponse, await res.json()) };