import {z} from 'zod' export type GetApiApiV1alpha1AssistantTrademeConversationsConversationIdArtifactsArgs = {conversation_id: string, include_unpresented?: boolean | undefined, include_snapshots?: boolean | undefined, authorization?: (string | null) | undefined, 'accept-nodes'?: (Array | null) | undefined}; export type GetApiApiV1alpha1AssistantTrademeConversationsConversationIdArtifactsOptions = {baseUrl: string, AnvilBearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const artifactHead = z.object({id: z.string(), uri: z.string(), artifactType: z.string(), provenance: z.string(), payload: z.record(z.string(), z.unknown()), versionId: z.string(), versionOrdinal: z.number().int(), parentVersionId: z.string().nullable().optional(), author: z.string().nullable().optional(), nameHint: z.string().nullable().optional(), presentedAt: z.string().nullable().optional(), lastChangedAt: z.string().nullable().optional()}); export const conversationArtifactsResponse = z.object({artifacts: z.array(artifactHead)}); 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 }; /** * List artifacts * * GET /api/v1alpha1/assistant/trademe/conversations/{conversation_id}/artifacts */ export const getApiApiV1alpha1AssistantTrademeConversationsConversationIdArtifacts = async (args: GetApiApiV1alpha1AssistantTrademeConversationsConversationIdArtifactsArgs, options: GetApiApiV1alpha1AssistantTrademeConversationsConversationIdArtifactsOptions) => { const {baseUrl, fetch: fetchFn = fetch, AnvilBearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.include_unpresented != null) query.append("include_unpresented", String(args.include_unpresented)) if (args.include_snapshots != null) query.append("include_snapshots", String(args.include_snapshots)) if (args.authorization != null) headers.set("authorization", String(args.authorization)) if (args['accept-nodes'] != null) headers.set("accept-nodes", args['accept-nodes'].join(',')) if (AnvilBearerToken !== undefined) headers.set('authorization', `Bearer ${AnvilBearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1alpha1/assistant/trademe/conversations/${encodeURIComponent(String(args.conversation_id))}/artifacts${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(conversationArtifactsResponse, await res.json()) };