import {z} from 'zod' export type PatchApiApiAgentsIdArgs = {id: string, body: {data: {type: string, id: string, attributes: {name: string, projectId?: string | undefined, modelType: string, maxToolIterations?: number | undefined, temperature?: number | undefined, outputs?: (Array<{name: string, functionName: string, jsonSchema: string, functionDescription?: string | undefined, artifactType?: ('IMAGE_ID_OUTPUT' | 'MARKDOWN_TEXT_OUTPUT' | 'REACT_OUTPUT' | 'PRESENTATION') | undefined, artifactContentType?: ('IMAGE_ID_OUTPUT' | 'MARKDOWN_TEXT_OUTPUT' | 'REACT_OUTPUT' | 'PRESENTATION') | undefined}>) | undefined, systemPrompt?: (string | null) | undefined, starterMessage?: (string | null) | undefined, reasoningEffort?: ('NONE' | 'MINIMAL' | 'LOW' | 'MEDIUM' | 'HIGH') | undefined, tools?: (Array<{toolTargetId: string, toolTargetType: string, targetFunction: string, functionName: string, functionDescription?: string | undefined, agentOutputMode?: ('RETURN' | 'SHOW' | null) | undefined, agentPromptSchema?: string | undefined, agentPromptTemplate?: string | undefined, inheritChatFiles?: boolean | undefined}>) | undefined, variables?: (Array<{name: string, toolTargetId: string, toolTargetType: string, targetFunction: string, functionArgumentsText?: string | undefined}>) | undefined}}}}; export type PatchApiApiAgentsIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiApiAgentsIdResponse = z.object({data: z.object({id: z.string(), type: z.string(), links: z.object({self: z.string()}), attributes: z.object({createdAt: z.string(), updatedAt: z.string(), projectId: z.string(), name: z.string(), systemPrompt: z.string(), starterMessage: z.string(), modelType: z.string(), maxToolIterations: z.number().int(), temperature: z.number(), reasoningEffort: z.string(), isManaged: z.boolean(), outputs: z.array(z.object({name: z.string(), functionName: z.string(), functionDescription: z.unknown(), jsonSchema: z.string(), artifactType: z.enum(["IMAGE_ID_OUTPUT", "MARKDOWN_TEXT_OUTPUT", "REACT_OUTPUT", "PRESENTATION"]).nullable(), artifactContentType: z.unknown()})), tools: z.array(z.unknown()), variables: z.array(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 }; /** * update * * PATCH /api/agents/{id} */ export const patchApiApiAgentsId = async (args: PatchApiApiAgentsIdArgs, options?: PatchApiApiAgentsIdOptions) => { const {baseUrl = "https://llm-api.treasuredata.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/vnd.api+json") if (ApiKeyAuth !== undefined) headers.set('authorization', `TD1 ${ApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/agents/${encodeURIComponent(String(args.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(patchApiApiAgentsIdResponse, await res.json()) };