@yuktishaalaa/yuktai 4.6.3 → 4.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -193,30 +193,178 @@ interface YuktaiGridProps<T = Record<string, unknown>> {
193
193
  onRowClick?: (row: T, index: number) => void;
194
194
  onSortChange?: (sort: SortConfig | null) => void;
195
195
  className?: string;
196
+ /** Voice input language of the embedded assistant (default: follows `locale`). */
197
+ inputLanguage?: "en-US" | "te-IN";
198
+ /** Prefix for tool names, e.g. "ratnalabala_poems" → "ratnalabala_poems_search". */
199
+ toolName?: string;
200
+ /** Agent-facing tool descriptions, e.g. { search: "Search Telugu poems by title or text." } */
201
+ toolDescriptions?: Partial<Record<"search" | "count" | "columns" | "get_row" | "highlight" | "select" | "open" | "filter" | "clear_filters" | "sort" | "clear_sort", string>>;
202
+ /**
203
+ * Expose the grid's tools to AI agents via WebMCP (document.modelContext).
204
+ * Uses exactly the same tools as the embedded assistant.
205
+ */
206
+ webmcp?: boolean;
207
+ /** Real WebMCP registration status (state, registered tools, errors). */
208
+ onWebMCPStatusChange?: (status: {
209
+ state: "unsupported" | "registering" | "ready" | "partial" | "error";
210
+ registered: string[];
211
+ errors: {
212
+ tool: string;
213
+ message: string;
214
+ }[];
215
+ }) => void;
216
+ /** Every result from the Agent (assistant or WebMCP), e.g. for logging. */
217
+ onAgentResult?: (result: {
218
+ success: boolean;
219
+ message: string;
220
+ tool?: string;
221
+ }) => void;
196
222
  }
197
223
 
198
- type YuktaiGridPropsWithHighlight<T extends Record<string, unknown>> = YuktaiGridProps<T> & {
199
- highlightIds?: (string | number)[];
200
- highlightColor?: string;
201
- autoScrollToHighlight?: boolean;
224
+ declare function YuktaiGrid<T extends Record<string, unknown>>({ data, columns, rowKey, view, mobileBreakpoint, theme, locale, ai, search, selectable, selectedKeys, onSelectionChange, pagination, loading, highlightIds, highlightColor, autoScrollToHighlight, onRowClick, onSortChange, empty, className, inputLanguage, toolName, toolDescriptions, webmcp, onWebMCPStatusChange, onAgentResult, }: YuktaiGridProps<T>): react_jsx_runtime.JSX.Element;
225
+
226
+ /**
227
+ * gridTools — the ONE place where YuktaiGrid tools are defined.
228
+ *
229
+ * Both the in-page Agent (useYuktaiGridAgent) and WebMCP (YuktaiGridWebMCP)
230
+ * should get their tools from `createGridTools()`, so the list an agent sees
231
+ * can never drift from the list the UI shows.
232
+ *
233
+ * Rules every tool follows:
234
+ * 1. One row-ID strategy: `getRowId(row, context.rowKey)` everywhere.
235
+ * `rowKey` must match YuktaiGrid's `rowKey` prop (default "id").
236
+ * 2. One result shape: { success, message, data?, error?: { code } }.
237
+ * 3. Never claim success for something that didn't happen:
238
+ * missing callback → NOT_SUPPORTED, unknown row → NOT_FOUND.
239
+ * 4. Never throw: tool execution is wrapped, errors become INTERNAL results.
240
+ *
241
+ * Backward compatible with 4.6.x: the existing exports keep their names and
242
+ * parameters; results only gain an optional `error` field.
243
+ */
244
+ type GridToolColumn = {
245
+ key: string;
246
+ label: string;
247
+ type?: "text" | "number" | "date";
248
+ };
249
+ type GridToolErrorCode = "NOT_FOUND" | "NOT_SUPPORTED" | "INVALID_INPUT" | "INTERNAL";
250
+ type GridToolFilterOperator = "contains" | "equals" | "startsWith" | "endsWith" | "greaterThan" | "lessThan" | "between";
251
+ type GridToolFilter = {
252
+ key: string;
253
+ operator: GridToolFilterOperator;
254
+ value: string | number | [number, number];
255
+ };
256
+ type GridToolSort = {
257
+ key: string;
258
+ direction: "asc" | "desc";
259
+ };
260
+ /** Language of `message` (shown to people). Agent descriptions stay English. */
261
+ type GridToolLocale = "en" | "te";
262
+ type GridToolContext<T> = {
263
+ data: T[];
264
+ columns: GridToolColumn[];
265
+ /** Field used as the row ID by every tool (default "id"). Match YuktaiGrid's rowKey. */
266
+ rowKey?: string;
267
+ /** Language for result messages (default "en"). */
268
+ locale?: GridToolLocale;
269
+ /** Filters currently applied, so a new filter can be merged in. */
270
+ filters?: GridToolFilter[];
271
+ onSelectRow?: (id: string) => void;
272
+ onHighlightRows?: (ids: string[]) => void;
273
+ onOpenRow?: (id: string) => void;
274
+ onFiltersChange?: (filters: GridToolFilter[]) => void;
275
+ onSortChange?: (sort: GridToolSort | null) => void;
202
276
  };
203
- declare function YuktaiGrid<T extends Record<string, unknown>>({ data, columns, rowKey, view, mobileBreakpoint, theme, locale, search, selectable, selectedKeys, onSelectionChange, pagination, loading, highlightIds, highlightColor, autoScrollToHighlight, onRowClick, onSortChange, empty, className, }: YuktaiGridPropsWithHighlight<T>): react_jsx_runtime.JSX.Element;
277
+ type GridToolResult<T = unknown> = {
278
+ success: boolean;
279
+ message: string;
280
+ data?: T;
281
+ error?: {
282
+ code: GridToolErrorCode;
283
+ };
284
+ };
285
+ /** A tool ready for the Agent and for WebMCP `registerTool`. */
286
+ type GridTool = {
287
+ name: string;
288
+ title: string;
289
+ /** For AI agents (English works best for tool selection). Never shown in the UI. */
290
+ description: string;
291
+ /** Short label for the UI, in the grid's locale. */
292
+ label: string;
293
+ inputSchema: Record<string, unknown>;
294
+ execute: (input: Record<string, unknown>) => Promise<GridToolResult>;
295
+ };
296
+ type CreateGridToolsOptions = {
297
+ /** Tool name prefix, e.g. "ratnalabala_poems" → "ratnalabala_poems_search". */
298
+ name?: string;
299
+ /** Override agent descriptions per tool, keyed by the short tool id ("search", "open", …). */
300
+ descriptions?: Partial<Record<GridToolId, string>>;
301
+ };
302
+ type GridToolId = "search" | "count" | "columns" | "get_row" | "highlight" | "select" | "open" | "filter" | "clear_filters" | "sort" | "clear_sort";
303
+ /** The single row-ID rule used by every tool. */
304
+ declare function getRowId(row: unknown, rowKey?: string): string;
305
+ /**
306
+ * Applies filters to rows — exported so YuktaiGrid filters its rows with
307
+ * exactly the same rules the filter tool uses to count matches.
308
+ */
309
+ declare function applyGridFilters<T>(data: T[], columns: GridToolColumn[], filters: GridToolFilter[]): T[];
310
+ /** Maps grid columns (any type) to tool columns (text / number / date). */
311
+ declare function toGridToolColumns(columns: {
312
+ key: string;
313
+ label: string;
314
+ type?: string;
315
+ }[]): GridToolColumn[];
316
+ declare function searchGrid<T extends Record<string, unknown>>(context: GridToolContext<T>, query: string): GridToolResult<T[]>;
317
+ declare function countGrid<T>(context: GridToolContext<T>): GridToolResult<number>;
318
+ declare function getColumns<T>(context: GridToolContext<T>): GridToolResult<GridToolColumn[]>;
319
+ declare function getRow<T extends Record<string, unknown>>(context: GridToolContext<T>, id: string): GridToolResult<T>;
320
+ declare function highlightRows<T extends Record<string, unknown>>(context: GridToolContext<T>, ids: string[]): GridToolResult<string[]>;
321
+ declare function selectRow<T extends Record<string, unknown>>(context: GridToolContext<T>, id: string): GridToolResult<string>;
322
+ declare function openRow<T extends Record<string, unknown>>(context: GridToolContext<T>, id: string): GridToolResult<string>;
323
+ declare function filterGrid<T extends Record<string, unknown>>(context: GridToolContext<T>, filter: GridToolFilter): GridToolResult<{
324
+ filters: GridToolFilter[];
325
+ count: number;
326
+ }>;
327
+ declare function clearFilters<T>(context: GridToolContext<T>): GridToolResult<GridToolFilter[]>;
328
+ declare function sortGrid<T>(context: GridToolContext<T>, key: string, direction?: "asc" | "desc"): GridToolResult<GridToolSort>;
329
+ declare function clearSort<T>(context: GridToolContext<T>): GridToolResult<null>;
330
+ /**
331
+ * Builds the tool list used by BOTH the Agent and WebMCP.
332
+ * Only tools the grid can actually perform are included — e.g. "open" is
333
+ * left out when no onOpenRow callback is given — so agents never see a tool
334
+ * that would just return NOT_SUPPORTED.
335
+ */
336
+ declare function createGridTools<T extends Record<string, unknown>>(context: GridToolContext<T>, options?: CreateGridToolsOptions): GridTool[];
204
337
 
205
338
  interface UseGridOptions<T> {
206
339
  data: T[];
207
340
  columns: GridColumn<T>[];
208
341
  pagination?: boolean | PaginationConfig;
209
342
  mobileBreakpoint?: number;
343
+ /** Locale for text sorting, e.g. "te-IN" (default: browser locale) */
344
+ locale?: string;
345
+ /** Starting filters (optional) */
346
+ initialFilters?: GridToolFilter[];
210
347
  }
211
348
  interface UseGridReturn<T> {
212
349
  displayedData: T[];
350
+ /** All matching rows (search + filters + sort), before pagination */
351
+ rows: T[];
213
352
  totalCount: number;
214
353
  filteredCount: number;
215
354
  sort: SortConfig | null;
216
355
  toggleSort: (key: string) => void;
356
+ /** Set sort directly (null clears it) */
357
+ setSort: (sort: SortConfig | null) => void;
217
358
  clearSort: () => void;
218
359
  searchQuery: string;
219
360
  setSearchQuery: (q: string) => void;
361
+ filters: GridToolFilter[];
362
+ setFilters: (filters: GridToolFilter[]) => void;
363
+ /** Add or replace the filter for one column */
364
+ setFilter: (filter: GridToolFilter) => void;
365
+ /** Remove the filter for one column */
366
+ removeFilter: (key: string) => void;
367
+ clearFilters: () => void;
220
368
  page: number;
221
369
  pageSize: number;
222
370
  totalPages: number;
@@ -227,6 +375,7 @@ interface UseGridReturn<T> {
227
375
  }
228
376
  declare function useGrid<T extends Record<string, unknown>>(options: UseGridOptions<T>): UseGridReturn<T>;
229
377
 
378
+ type Language = "en-US" | "te-IN";
230
379
  interface YuktaiGridAIProps<T> {
231
380
  data: T[];
232
381
  columns: {
@@ -234,83 +383,171 @@ interface YuktaiGridAIProps<T> {
234
383
  label: string;
235
384
  type?: "number" | "text" | "date";
236
385
  }[];
237
- onSearch: (query: string) => void;
386
+ /**
387
+ * Used only when no `agent` is given (4.6.x behaviour).
388
+ * With an agent, every action goes through agent.ask() instead.
389
+ */
390
+ onSearch?: (query: string) => void;
238
391
  onSort?: (key: string, dir: "asc" | "desc") => void;
239
392
  theme?: "light" | "dark";
240
- language?: "en-US" | "en-IN" | "hi-IN" | "te-IN";
393
+ /**
394
+ * Language of AI UI and AI responses.
395
+ * Default: English.
396
+ */
397
+ language?: Language;
398
+ /**
399
+ * Language used by browser voice recognition.
400
+ * Default: English.
401
+ */
402
+ inputLanguage?: Language;
403
+ /**
404
+ * When true, AI is rendered inside the grid.
405
+ * When false, AI uses the floating assistant UI.
406
+ */
407
+ embedded?: boolean;
408
+ /**
409
+ * The grid Agent (from useYuktaiGridAgent). When given, search / sort /
410
+ * filter / open / clear requests are sent to agent.ask() — the same
411
+ * pipeline WebMCP uses — and the Agent's result message is shown.
412
+ * Questions like "highest / average / total" are still answered here.
413
+ */
414
+ agent?: {
415
+ ask: (text: string) => Promise<{
416
+ success: boolean;
417
+ message: string;
418
+ }>;
419
+ loading?: boolean;
420
+ };
421
+ /** Called when the person switches the voice input language. */
422
+ onInputLanguageChange?: (language: Language) => void;
241
423
  }
242
- declare function YuktaiGridAI<T extends Record<string, unknown>>({ data, columns, onSearch, onSort, theme, language, }: YuktaiGridAIProps<T>): react_jsx_runtime.JSX.Element;
424
+ declare function YuktaiGridAI<T extends Record<string, unknown>>({ data, columns, onSearch, onSort, theme, language, inputLanguage, embedded, agent, onInputLanguageChange, }: YuktaiGridAIProps<T>): react_jsx_runtime.JSX.Element;
243
425
 
426
+ type ModelContextTool = {
427
+ name: string;
428
+ title: string;
429
+ description: string;
430
+ inputSchema: Record<string, unknown>;
431
+ execute: (input: any) => Promise<unknown> | unknown;
432
+ };
244
433
  declare global {
245
434
  interface Document {
246
435
  modelContext?: {
247
- registerTool: (tool: {
248
- name: string;
249
- title: string;
250
- description: string;
251
- inputSchema: Record<string, unknown>;
252
- execute: (input: any) => Promise<unknown> | unknown;
253
- }, options?: {
436
+ registerTool: (tool: ModelContextTool, options?: {
254
437
  signal?: AbortSignal;
255
438
  }) => Promise<void>;
256
439
  };
257
440
  }
258
441
  }
442
+ type WebMCPState = "unsupported" | "registering" | "ready" | "partial" | "error";
443
+ type WebMCPStatus = {
444
+ state: WebMCPState;
445
+ /** Tools that the browser actually accepted */
446
+ registered: string[];
447
+ errors: {
448
+ tool: string;
449
+ message: string;
450
+ }[];
451
+ };
259
452
  type WebMCPColumn = {
260
453
  key: string;
261
454
  label: string;
262
455
  type?: "text" | "number" | "date";
263
456
  };
264
457
  type YuktaiGridWebMCPProps<T> = {
265
- data: T[];
266
- columns: WebMCPColumn[];
267
- name?: string;
458
+ /**
459
+ * Ready-made tools (YuktaiGrid passes its own list here). When given,
460
+ * data/columns/callbacks below are not needed.
461
+ */
462
+ tools?: GridTool[];
463
+ data?: T[];
464
+ columns?: WebMCPColumn[];
465
+ rowKey?: string;
466
+ locale?: GridToolLocale;
268
467
  onSelectRow?: (id: string) => void;
269
468
  onHighlightRows?: (ids: string[]) => void;
270
469
  onOpenRow?: (id: string) => void;
470
+ /** Tool name prefix (default "yuktai_grid") */
471
+ name?: string;
472
+ /** Agent-facing descriptions per tool, e.g. { search: "Search Telugu poems…" } */
473
+ descriptions?: CreateGridToolsOptions["descriptions"];
474
+ /** Called whenever the registration status changes */
475
+ onStatusChange?: (status: WebMCPStatus) => void;
271
476
  };
272
- declare function YuktaiGridWebMCP<T extends Record<string, unknown>>({ data, columns, name, onSelectRow, onHighlightRows, onOpenRow, }: YuktaiGridWebMCPProps<T>): null;
477
+ declare function YuktaiGridWebMCP<T extends Record<string, unknown>>({ tools: toolsProp, data, columns, rowKey, locale, onSelectRow, onHighlightRows, onOpenRow, name, descriptions, onStatusChange, }: YuktaiGridWebMCPProps<T>): null;
273
478
 
274
479
  type GridAgentTool = {
275
480
  name: string;
276
481
  description: string;
482
+ /** Optional UI label (e.g. Telugu). createGridTools() provides it. */
483
+ label?: string;
484
+ /** Optional JSON schema; its `required` list is checked before running. */
485
+ inputSchema?: Record<string, unknown>;
277
486
  execute: (input: Record<string, unknown>) => Promise<unknown> | unknown;
278
487
  };
488
+ type GridAgentErrorCode = GridToolErrorCode | "NOT_UNDERSTOOD";
489
+ type GridAgentResult<T = unknown> = Omit<GridToolResult<T>, "error"> & {
490
+ error?: {
491
+ code: GridAgentErrorCode;
492
+ };
493
+ /** Full name of the tool that produced this result */
494
+ tool?: string;
495
+ };
496
+ type GridAgentStep = {
497
+ id: number;
498
+ tool: string;
499
+ input: Record<string, unknown>;
500
+ result: GridAgentResult;
501
+ source: "tool" | "ask";
502
+ at: number;
503
+ };
504
+ type GridIntent = {
505
+ kind: "tool";
506
+ tool: string;
507
+ input: Record<string, unknown>;
508
+ }
509
+ /** "open <something>": search for it, then open the first match */
510
+ | {
511
+ kind: "open";
512
+ text: string;
513
+ };
514
+ type GridIntentContext = {
515
+ columns: {
516
+ key: string;
517
+ label: string;
518
+ }[];
519
+ locale: GridToolLocale;
520
+ };
279
521
  type YuktaiGridAgentProps = {
280
522
  tools: GridAgentTool[];
281
- onResult?: (result: unknown) => void;
523
+ onResult?: (result: GridAgentResult) => void;
282
524
  onError?: (error: Error) => void;
525
+ /** Language of the agent's own messages (default "en"). */
526
+ locale?: GridToolLocale;
527
+ /** Columns, so ask() can understand "sort by <column>". */
528
+ columns?: {
529
+ key: string;
530
+ label: string;
531
+ }[];
532
+ /** Row ID field — must match the grid's rowKey (default "id"). */
533
+ rowKey?: string;
534
+ /** Replace the built-in regex intent parser (e.g. with an on-device LLM). */
535
+ parseIntent?: (text: string, context: GridIntentContext) => GridIntent | null;
536
+ /** How many steps to keep in history (default 20). */
537
+ historyLimit?: number;
283
538
  };
284
- declare function useYuktaiGridAgent({ tools, onResult, onError, }: YuktaiGridAgentProps): {
539
+ /** Built-in parser: exported so it can be tested and reused. */
540
+ declare function parseGridIntent(text: string, context: GridIntentContext): GridIntent | null;
541
+ declare function useYuktaiGridAgent({ tools, onResult, onError, locale, columns, rowKey, parseIntent, historyLimit, }: YuktaiGridAgentProps): {
285
542
  loading: boolean;
286
543
  tools: GridAgentTool[];
287
- executeTool: (name: string, input?: Record<string, unknown>) => Promise<unknown>;
288
- };
289
-
290
- type GridToolColumn = {
291
- key: string;
292
- label: string;
293
- type?: "text" | "number" | "date";
544
+ executeTool: (name: string, input?: Record<string, unknown>) => Promise<GridAgentResult<unknown>>;
545
+ ask: (text: string) => Promise<GridAgentResult>;
546
+ lastResult: GridAgentResult<unknown> | null;
547
+ lastError: Error | null;
548
+ history: GridAgentStep[];
549
+ clearHistory: () => void;
294
550
  };
295
- type GridToolContext<T> = {
296
- data: T[];
297
- columns: GridToolColumn[];
298
- onSelectRow?: (id: string) => void;
299
- onHighlightRows?: (ids: string[]) => void;
300
- onOpenRow?: (id: string) => void;
301
- };
302
- type GridToolResult<T = unknown> = {
303
- success: boolean;
304
- message: string;
305
- data?: T;
306
- };
307
- declare function searchGrid<T extends Record<string, unknown>>(context: GridToolContext<T>, query: string): GridToolResult<T[]>;
308
- declare function countGrid<T>(context: GridToolContext<T>): GridToolResult<number>;
309
- declare function getColumns<T>(context: GridToolContext<T>): GridToolResult<GridToolColumn[]>;
310
- declare function getRow<T extends Record<string, unknown>>(context: GridToolContext<T>, id: string): GridToolResult<T>;
311
- declare function highlightRows<T extends Record<string, unknown>>(context: GridToolContext<T>, ids: string[]): GridToolResult<string[]>;
312
- declare function selectRow<T extends Record<string, unknown>>(context: GridToolContext<T>, id: string): GridToolResult<string>;
313
- declare function openRow<T extends Record<string, unknown>>(context: GridToolContext<T>, id: string): GridToolResult<string>;
314
551
 
315
552
  interface IconProps extends React.SVGAttributes<SVGSVGElement> {
316
553
  /** Size in pixels — applied to both width and height. Default: 20 */
@@ -377,4 +614,4 @@ declare const YuktAI: {
377
614
  scan(): A11yReport;
378
615
  };
379
616
 
380
- export { type A11yConfig, type A11yFix, type A11yReport, type AIFeatures, CheckIcon, ChevronLeftIcon, ChevronRightIcon, CloseIcon, type ColorBlindMode, type FilterConfig, type FilterOperator, type GridAgentTool, type GridColumn, type GridLocale, type GridTheme, type GridToolColumn, type GridToolContext, type GridToolResult, type GridTranslations, IconBase, type IconProps, type PaginationConfig, Runtime, SearchIcon, type Severity, type SortConfig, type SortDirection, SortDownIcon, SortUpIcon, type ViewMode, type VoiceFeatures, YuktAI, YuktAIWrapper, type YuktAIWrapperProps, YuktaiGrid, YuktaiGridAI, type YuktaiGridAIProps, useYuktaiGridAgent as YuktaiGridAgent, type YuktaiGridAgentProps, type YuktaiGridProps, YuktaiGridWebMCP, type YuktaiGridWebMCPProps, aiPlugin, countGrid, YuktAIWrapper as default, getColumns, getRow, highlightRows, openRow, searchGrid, selectRow, useGrid, useYuktaiGridAgent, voicePlugin, wcagPlugin as wcag, wcagPlugin };
617
+ export { type A11yConfig, type A11yFix, type A11yReport, type AIFeatures, CheckIcon, ChevronLeftIcon, ChevronRightIcon, CloseIcon, type ColorBlindMode, type CreateGridToolsOptions, type FilterConfig, type FilterOperator, type GridAgentErrorCode, type GridAgentResult, type GridAgentStep, type GridAgentTool, type GridColumn, type GridIntent, type GridIntentContext, type GridLocale, type GridTheme, type GridTool, type GridToolColumn, type GridToolContext, type GridToolErrorCode, type GridToolFilter, type GridToolFilterOperator, type GridToolId, type GridToolLocale, type GridToolResult, type GridToolSort, type GridTranslations, IconBase, type IconProps, type PaginationConfig, Runtime, SearchIcon, type Severity, type SortConfig, type SortDirection, SortDownIcon, SortUpIcon, type UseGridOptions, type UseGridReturn, type ViewMode, type VoiceFeatures, type WebMCPState, type WebMCPStatus, YuktAI, YuktAIWrapper, type YuktAIWrapperProps, YuktaiGrid, YuktaiGridAI, type YuktaiGridAIProps, useYuktaiGridAgent as YuktaiGridAgent, type YuktaiGridAgentProps, type YuktaiGridProps, YuktaiGridWebMCP, type YuktaiGridWebMCPProps, aiPlugin, applyGridFilters, clearFilters, clearSort, countGrid, createGridTools, YuktAIWrapper as default, filterGrid, getColumns, getRow, getRowId, highlightRows, openRow, parseGridIntent, searchGrid, selectRow, sortGrid, toGridToolColumns, useGrid, useYuktaiGridAgent, voicePlugin, wcagPlugin as wcag, wcagPlugin };