import {z} from 'zod' 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 ContentFragment = {title: string, content?: string | undefined, contentType?: string | undefined, url?: string | undefined, fileId?: string | undefined, path?: (string | null) | undefined, processedPath?: (string | null) | undefined, skipFileProcessing?: boolean | undefined, nodeId?: string | undefined, nodeDataSourceViewId?: string | undefined, context?: Context | undefined}; export type CreateApiApiV1WWIdAssistantConversationsCIdContentFragmentsArgs = {wId: string, cId: string, body: ContentFragment}; export type CreateApiApiV1WWIdAssistantConversationsCIdContentFragmentsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; 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 contentFragment = z.object({title: z.string(), content: z.string().optional(), contentType: z.string().optional(), url: z.string().optional(), fileId: z.string().optional(), path: z.string().nullable().optional(), processedPath: z.string().nullable().optional(), skipFileProcessing: z.boolean().optional(), nodeId: z.string().optional(), nodeDataSourceViewId: z.string().optional(), context: context.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 content fragment * * POST /api/v1/w/{wId}/assistant/conversations/{cId}/content_fragments */ export const createApiApiV1WWIdAssistantConversationsCIdContentFragments = async (args: CreateApiApiV1WWIdAssistantConversationsCIdContentFragmentsArgs, options?: CreateApiApiV1WWIdAssistantConversationsCIdContentFragmentsOptions) => { 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))}/content_fragments${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(contentFragment, await res.json()) };