import {z} from 'zod' export type GetApiApiProjectsArgs = {'filter[fulltext]'?: string | undefined, 'filter[hasInterfaces]'?: string | undefined, 'filter[has_form_interfaces]'?: string | undefined, 'filter[is_managed]'?: string | undefined, 'filter[manage_type]'?: string | undefined, include?: string | undefined, sort?: string | undefined}; export type GetApiApiProjectsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiProjectsResponse = z.object({data: z.array(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({overview: z.object({data: z.object({type: z.string(), id: z.string()})}).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(), formInterfaces: z.object({data: z.array(z.object({type: z.string(), id: z.string()}))}).optional(), chatInterfaces: z.object({data: z.array(z.unknown())}).optional()}).optional()})), meta: z.object({total: z.number().int()}), links: z.object({first: z.string(), last: z.string()}), included: z.array(z.object({id: z.string(), type: z.string(), attributes: z.object({firstAgentName: z.string().optional(), firstIntegrationServiceType: z.string().optional(), firstKnowledgeBaseName: z.string().optional(), totalAgentCount: z.number().int().optional(), totalIntegrationCount: z.number().int().optional(), totalKnowledgeBaseCount: z.number().int().optional(), name: z.string().optional(), email: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), projectId: z.string().optional(), agentId: z.string().nullable().optional(), 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()}), links: z.object({self: z.string()}).optional(), relationships: z.object({project: z.object({data: z.object({type: z.string(), id: z.string()})})}).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 }; /** * index * * GET /api/projects */ export const getApiApiProjects = async (args: GetApiApiProjectsArgs, options?: GetApiApiProjectsOptions) => { 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['filter[fulltext]'] != null) query.append("filter[fulltext]", String(args['filter[fulltext]'])) if (args['filter[hasInterfaces]'] != null) query.append("filter[hasInterfaces]", String(args['filter[hasInterfaces]'])) if (args['filter[has_form_interfaces]'] != null) query.append("filter[has_form_interfaces]", String(args['filter[has_form_interfaces]'])) if (args['filter[is_managed]'] != null) query.append("filter[is_managed]", String(args['filter[is_managed]'])) if (args['filter[manage_type]'] != null) query.append("filter[manage_type]", String(args['filter[manage_type]'])) if (args.include != null) query.append("include", String(args.include)) if (args.sort != null) query.append("sort", String(args.sort)) if (ApiKeyAuth !== undefined) headers.set('authorization', `TD1 ${ApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/projects${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(getApiApiProjectsResponse, await res.json()) };