import {z} from 'zod' export type AnnotationContextItem = {kind?: 'annotation' | undefined, measurement_id: string}; export type RegionContextItem = {kind?: 'region' | undefined, page_id: string, x: number, y: number, width: number, height: number}; export type UiState = {active_takeoff_tool?: (string | null) | undefined, active_markup_tool?: (string | null) | undefined, selected_measurement_ids?: Array | undefined, selected_annotation_ids?: Array | undefined, total_selected?: (number | null) | undefined}; export type MessageContext = {active_page_id?: (string | null) | undefined, items?: (Array) | undefined, ui_state?: (UiState | null) | undefined}; export type OverlaySheetStatus = {page_id: string, page_identity_id: string, from_page_id: string, to_page_id: string, status: 'pending' | 'diffed' | 'summarized' | 'misaligned' | 'failed', change_count: number}; export type OverlayChangeInstance = {page_id: string, x: number, y: number, width: number, height: number}; export type OverlayChange = {change_id: string, page_id: string, x: number, y: number, width: number, height: number, title?: (string | null) | undefined, summary?: (string | null) | undefined, significance?: ('substantive' | 'administrative' | 'cosmetic' | null) | undefined, confidence?: (number | null) | undefined, cloud_marked?: boolean | undefined, instances?: (Array | null) | undefined, dead_ink?: number | undefined, new_ink?: number | undefined}; export type OverlayChangeSet = {from_revision_id: string, to_revision_id: string, fingerprint: string, status: 'running' | 'ready' | 'partial', canceled?: boolean | undefined, truncated?: boolean | undefined, sheets: Array, changes: Array}; export type OverlayChangeSetArtifact = {kind?: 'overlay_change_set' | undefined, version?: 2 | undefined, body: OverlayChangeSet}; export type PostMessageRequest = {content: string, context?: (MessageContext | null) | undefined, client_artifacts?: Array | undefined}; export type CreateApiApiV1ConversationsConversationIdMessagesArgs = {conversation_id: string, rev?: (string | null) | undefined, body: PostMessageRequest}; export type CreateApiApiV1ConversationsConversationIdMessagesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const createApiApiV1ConversationsConversationIdMessagesResponse = z.unknown(); 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 }; /** * Post Message * * POST /api/v1/conversations/{conversation_id}/messages */ export const createApiApiV1ConversationsConversationIdMessages = async (args: CreateApiApiV1ConversationsConversationIdMessagesArgs, options: CreateApiApiV1ConversationsConversationIdMessagesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.rev != null) query.append("rev", String(args.rev)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/conversations/${encodeURIComponent(String(args.conversation_id))}/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(createApiApiV1ConversationsConversationIdMessagesResponse, await res.json()) };