import {z} from 'zod' export type Mention = {configurationId?: string | undefined}; export type Context = {username: string, timezone: string, fullName?: string | undefined, email?: string | undefined, profilePictureUrl?: string | undefined, selectedSpaceIds?: Array | undefined, excludedRetrievalTags?: (Array | null) | undefined, hostSelection?: (string | null) | undefined, agenticMessageData?: ({type?: ('run_agent' | 'agent_handover') | undefined, originMessageId?: string | undefined}) | undefined}; export type ModelSelection = {providerId: string, modelId: string, reasoningEffort?: ('none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'maximal' | 'light') | undefined}; export type Message = {content: string, mentions: Array, context?: Context | undefined, modelSelection?: ModelSelection | undefined}; export type CreateApiApiV1WWIdAssistantConversationsCIdMessagesArgs = {wId: string, cId: string, body: Message}; export type CreateApiApiV1WWIdAssistantConversationsCIdMessagesOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const mention = z.object({configurationId: z.string().optional()}); export const context = z.object({username: z.string(), timezone: z.string(), fullName: z.string().optional(), email: z.string().optional(), profilePictureUrl: z.string().optional(), selectedSpaceIds: z.array(z.string()).optional(), excludedRetrievalTags: z.array(z.string()).nullable().optional(), hostSelection: z.string().nullable().optional(), agenticMessageData: z.object({type: z.enum(["run_agent", "agent_handover"]).optional(), originMessageId: z.string().optional()}).optional()}); export const modelSelection = z.object({providerId: z.string(), modelId: z.string(), reasoningEffort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh", "maximal", "light"]).optional()}); export const message = z.object({content: z.string(), mentions: z.array(mention), context: context.optional(), modelSelection: modelSelection.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 }; /** * Create a message * * POST /api/v1/w/{wId}/assistant/conversations/{cId}/messages */ export const createApiApiV1WWIdAssistantConversationsCIdMessages = async (args: CreateApiApiV1WWIdAssistantConversationsCIdMessagesArgs, options?: CreateApiApiV1WWIdAssistantConversationsCIdMessagesOptions) => { const {baseUrl = "https://dust.tt", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/w/${encodeURIComponent(String(args.wId))}/assistant/conversations/${encodeURIComponent(String(args.cId))}/messages${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(message, await res.json()) };