import {z} from 'zod' export type LLMObsUpdatePromptDataAttributes = {description?: string | undefined, title?: string | undefined}; export type LLMObsPromptType = 'prompt-templates'; export type LLMObsUpdatePromptData = {attributes: LLMObsUpdatePromptDataAttributes, type: LLMObsPromptType}; export type LLMObsUpdatePromptRequest = {data: LLMObsUpdatePromptData}; export type PatchApiApiV2LlmObsV1PromptsPromptIdArgs = {prompt_id: string, body: LLMObsUpdatePromptRequest}; export type PatchApiApiV2LlmObsV1PromptsPromptIdOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, appKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const lLMObsPromptDataset = z.object({id: z.string(), name: z.string().optional()}); export const lLMObsPromptResponseSource = z.enum(["registry", "code"]); export const lLMObsPromptDataAttributes = z.object({author: z.string().optional(), created_at: z.string().optional(), created_from: z.string(), datasets: z.array(lLMObsPromptDataset).optional(), description: z.string().optional(), extracted_from: z.string().optional(), in_registry: z.boolean(), last_seen_at: z.string().optional(), last_version_created_at: z.string().optional(), ml_app: z.string().optional(), ml_apps: z.array(z.string()).optional(), num_versions: z.number().int(), prompt_id: z.string(), source: lLMObsPromptResponseSource, tags: z.array(z.string()).optional(), title: z.string().optional()}); export const lLMObsPromptType = z.literal("prompt-templates"); export const lLMObsPromptData = z.object({attributes: lLMObsPromptDataAttributes, id: z.string(), type: lLMObsPromptType}); export const lLMObsPromptResponse = z.object({data: lLMObsPromptData}); 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 an Agent Observability prompt * * PATCH /api/v2/llm-obs/v1/prompts/{prompt_id} * * Also accepts auth: AuthZ */ export const patchApiApiV2LlmObsV1PromptsPromptId = async (args: PatchApiApiV2LlmObsV1PromptsPromptIdArgs, options?: PatchApiApiV2LlmObsV1PromptsPromptIdOptions) => { const {baseUrl = "https://api.datadoghq.com", fetch: fetchFn = fetch, apiKeyAuth, appKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") 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: "PATCH", 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(lLMObsPromptResponse, await res.json()) };