/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2026 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import { GridAIState } from '../utils/handleAIResponse.js'; import { GridHandle } from '../interfaces/index.js'; interface AxiosLikeResponse { data: T; status: number; statusText: string; headers: Record; } type AxiosLikeInstance = (url: string, config: GridAIRequestConfig) => Promise; /** * Configuration for an HTTP request made by the Grid AI Assistant. * Replaces direct usage of AxiosRequestConfig. */ export interface GridAIRequestConfig { /** HTTP method. */ method?: string; /** Request headers. */ headers?: Record; /** Whether to include credentials (cookies) in cross-origin requests. */ withCredentials?: boolean; /** Expected response type. */ responseType?: 'json' | 'text'; /** AbortSignal for request cancellation. */ signal?: AbortSignal; /** Additional options passed to the underlying HTTP client. */ [key: string]: unknown; } /** * Normalized HTTP response returned by the Grid AI Assistant. * Replaces direct usage of AxiosResponse. */ export interface GridAIResponse { /** Parsed response body. */ data: T; /** HTTP status code. */ status: number; /** HTTP status text. */ statusText: string; /** Response headers. */ headers: Record; /** Request configuration. Included for backward compatibility with AxiosResponse. */ config?: unknown; /** The underlying request object. Included for backward compatibility with AxiosResponse. */ request?: unknown; /** Allow additional properties for backward compatibility with AxiosResponse. */ [key: string]: unknown; } /** * Optional custom HTTP client that customers can provide * to override the default fetch-based transport. */ export interface GridAIHttpClient { /** Execute an HTTP request. */ request(url: string, config: GridAIRequestConfig): Promise; } /** * Creates a GridAIHttpClient backed by a customer-provided axios instance. * * @example * ```tsx * import axios from 'axios'; * import { createAxiosAIClient } from '@progress/kendo-react-grid'; * * * ``` */ export declare function createAxiosAIClient(axiosInstance: AxiosLikeInstance): GridAIHttpClient; /** * Represents the request data structure for the Grid AI request. */ export interface GridAIRequestData { /** * The role or context for the AI request. */ role: string; /** * The array of column definitions with their field names. */ columns: Array<{ field: string; id?: string; values?: any[]; }>; /** * The headers object containing key-value pairs for the request. */ headers: Record; /** * The prompt message sent to the AI assistant. */ promptMessage: string; /** * The request configuration options for the HTTP request. */ requestOptions: GridAIRequestConfig & { url?: string; cancelToken?: unknown; }; } /** * Options for the useGridAIRequest hook. */ export interface UseGridAIRequestOptions { /** * The URL to send the AI request to. */ requestUrl?: string; /** * Additional HTTP request options. */ requestOptions?: GridAIRequestConfig; /** * Optional custom HTTP client. * When provided, overrides the built-in fetch-based transport. */ httpClient?: GridAIHttpClient; /** * The role for the AI request. Defaults to 'user'. */ role?: string; /** * The columns to include in the request. */ columns?: Array<{ field: string; id?: string; values?: any[]; }>; /** * The current grid state. */ gridState?: GridAIState; /** * Reference to grid methods. */ gridRef?: Pick | null; /** * Callback fired before the request is sent. */ onPromptRequest?: (request: GridAIRequestData, isRetry?: boolean) => void; /** * Callback fired when the response is received successfully. */ onResponseSuccess?: (response: GridAIResponse, promptMessage?: string, isRetry?: boolean) => void; /** * Callback fired when the response returns an error. */ onResponseError?: (error: any) => void; /** * Callback fired when the grid state should be updated. */ onStateChange?: (newState: GridAIState) => void; /** * Callback fired when messages are received from AI. */ onMessages?: (messages: string[], promptMessage?: string, isRetry?: boolean) => void; /** * Callback fired when PDF export is requested. */ onExportPdf?: () => void; } /** * Return type for the useGridAIRequest hook. */ export interface UseGridAIRequestReturn { /** * Whether a request is currently loading. */ loading: boolean; /** * Whether a request is currently streaming. */ streaming: boolean; /** * Send a prompt request to the AI. */ sendRequest: (promptMessage: string, isRetry?: boolean) => void; /** * Cancel the current request. */ cancelRequest: () => void; } /** * A custom hook that encapsulates the AI request logic for the Grid. * This hook can be used by both GridToolbarAIAssistant and SmartBox components. * * @param options - Configuration options for the hook * @returns Object containing loading state and request methods * * @example * ```tsx * const { loading, streaming, sendRequest, cancelRequest } = useGridAIRequest({ * requestUrl: '/api/ai/grid', * columns: gridColumns, * gridState: currentState, * gridRef: gridRef.current, * onStateChange: (newState) => setGridState(newState), * onMessages: (messages) => console.log(messages) * }); * * // Send a request * sendRequest('Sort by price descending'); * * // Cancel if needed * cancelRequest(); * ``` */ export declare function useGridAIRequest(options: UseGridAIRequestOptions): UseGridAIRequestReturn; export {};