import {z} from 'zod' export type GetApiApiV1ProjectsProjectUuidAiAgentsAgentUuidSuggestionsArgs = {projectUuid: string, agentUuid: string, threadUuid?: string | undefined, afterMessageUuid?: string | undefined, enableSqlMode?: boolean | undefined}; export type GetApiApiV1ProjectsProjectUuidAiAgentsAgentUuidSuggestionsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const agentSuggestionTool = z.enum(["generateDashboard", "generateVisualization", "runSql", "findContent"]); export const agentSuggestionPromptChip = z.object({defaults: z.object({timeframe: z.string().nullable(), metrics: z.array(z.string()), dimensions: z.array(z.string()), explore: z.string().nullable()}), tool: agentSuggestionTool, label: z.string(), kind: z.literal("prompt")}); export const agentSuggestionNavigateChip = z.object({url: z.string(), label: z.string(), kind: z.literal("navigate")}); export const agentSuggestion = z.union([agentSuggestionPromptChip, agentSuggestionNavigateChip]); export const apiAgentSuggestionsResponse = z.object({results: z.object({chips: z.array(agentSuggestion)}), status: z.literal("ok")}); 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 }; /** * GET /api/v1/projects/{projectUuid}/aiAgents/{agentUuid}/suggestions */ export const getApiApiV1ProjectsProjectUuidAiAgentsAgentUuidSuggestions = async (args: GetApiApiV1ProjectsProjectUuidAiAgentsAgentUuidSuggestionsArgs, options: GetApiApiV1ProjectsProjectUuidAiAgentsAgentUuidSuggestionsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.threadUuid != null) query.append("threadUuid", String(args.threadUuid)) if (args.afterMessageUuid != null) query.append("afterMessageUuid", String(args.afterMessageUuid)) if (args.enableSqlMode != null) query.append("enableSqlMode", String(args.enableSqlMode)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/projects/${encodeURIComponent(String(args.projectUuid))}/aiAgents/${encodeURIComponent(String(args.agentUuid))}/suggestions${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(apiAgentSuggestionsResponse, await res.json()) };