import {z} from 'zod' export type GetApiApiProjectsIdArgs = {id: string, include?: string | undefined}; export type GetApiApiProjectsIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiProjectsIdResponse = 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(), name: z.string(), description: z.unknown(), useRuntimeTextResource: z.boolean(), useParentSegment: z.boolean(), useWorkflowExecutor: z.boolean(), isManaged: z.boolean(), managedType: z.string()}), relationships: z.object({formInterfaces: z.object({data: z.array(z.object({type: z.string(), id: z.string()}))}).optional(), chatInterfaces: z.object({data: z.array(z.object({type: z.string(), id: z.string()}))}).optional()}).optional()}), included: z.array(z.object({id: z.string(), type: z.string(), links: z.object({self: z.string()}).nullable().optional(), attributes: z.object({createdAt: z.string().nullable().optional(), updatedAt: z.string().nullable().optional(), projectId: z.string().nullable().optional(), agentId: z.string().nullable().optional(), name: z.string(), promptTemplate: z.string().nullable().optional(), formJsonSchema: z.string().nullable().optional(), formUiSchema: z.unknown(), useTextResource: z.boolean().nullable().optional(), starterMessage: z.string().nullable().optional(), textInputEnabled: z.boolean().nullable().optional(), textInputAgentId: z.unknown(), isManaged: z.boolean().nullable().optional(), chatInterfaceButtons: z.array(z.unknown()).nullable().optional(), email: z.string().nullable().optional()}), relationships: z.object({project: z.object({data: z.object({type: z.string(), id: z.string()})}).nullable().optional(), createdBy: z.object({data: z.object({type: z.string(), id: z.string()})}).optional(), updatedBy: z.object({data: z.object({type: z.string(), id: z.string()})}).optional()}).nullable().optional()})).optional()}); 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 }; /** * show * * GET /api/projects/{id} */ export const getApiApiProjectsId = async (args: GetApiApiProjectsIdArgs, options?: GetApiApiProjectsIdOptions) => { const {baseUrl = "https://llm-api.treasuredata.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.api+json") if (args.include != null) query.append("include", String(args.include)) if (ApiKeyAuth !== undefined) headers.set('authorization', `TD1 ${ApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/projects/${encodeURIComponent(String(args.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(getApiApiProjectsIdResponse, await res.json()) };