@yuktishaalaa/yuktai 4.6.4 → 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,25 +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
- 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, }: YuktaiGridProps<T>): react_jsx_runtime.JSX.Element;
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;
276
+ };
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[];
199
337
 
200
338
  interface UseGridOptions<T> {
201
339
  data: T[];
202
340
  columns: GridColumn<T>[];
203
341
  pagination?: boolean | PaginationConfig;
204
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[];
205
347
  }
206
348
  interface UseGridReturn<T> {
207
349
  displayedData: T[];
350
+ /** All matching rows (search + filters + sort), before pagination */
351
+ rows: T[];
208
352
  totalCount: number;
209
353
  filteredCount: number;
210
354
  sort: SortConfig | null;
211
355
  toggleSort: (key: string) => void;
356
+ /** Set sort directly (null clears it) */
357
+ setSort: (sort: SortConfig | null) => void;
212
358
  clearSort: () => void;
213
359
  searchQuery: string;
214
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;
215
368
  page: number;
216
369
  pageSize: number;
217
370
  totalPages: number;
@@ -230,7 +383,11 @@ interface YuktaiGridAIProps<T> {
230
383
  label: string;
231
384
  type?: "number" | "text" | "date";
232
385
  }[];
233
- 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;
234
391
  onSort?: (key: string, dir: "asc" | "desc") => void;
235
392
  theme?: "light" | "dark";
236
393
  /**
@@ -248,80 +405,150 @@ interface YuktaiGridAIProps<T> {
248
405
  * When false, AI uses the floating assistant UI.
249
406
  */
250
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;
251
423
  }
252
- declare function YuktaiGridAI<T extends Record<string, unknown>>({ data, columns, onSearch, onSort, theme, language, inputLanguage, embedded, }: 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;
253
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
+ };
254
433
  declare global {
255
434
  interface Document {
256
435
  modelContext?: {
257
- registerTool: (tool: {
258
- name: string;
259
- title: string;
260
- description: string;
261
- inputSchema: Record<string, unknown>;
262
- execute: (input: any) => Promise<unknown> | unknown;
263
- }, options?: {
436
+ registerTool: (tool: ModelContextTool, options?: {
264
437
  signal?: AbortSignal;
265
438
  }) => Promise<void>;
266
439
  };
267
440
  }
268
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
+ };
269
452
  type WebMCPColumn = {
270
453
  key: string;
271
454
  label: string;
272
455
  type?: "text" | "number" | "date";
273
456
  };
274
457
  type YuktaiGridWebMCPProps<T> = {
275
- data: T[];
276
- columns: WebMCPColumn[];
277
- 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;
278
467
  onSelectRow?: (id: string) => void;
279
468
  onHighlightRows?: (ids: string[]) => void;
280
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;
281
476
  };
282
- 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;
283
478
 
284
479
  type GridAgentTool = {
285
480
  name: string;
286
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>;
287
486
  execute: (input: Record<string, unknown>) => Promise<unknown> | unknown;
288
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
+ };
289
521
  type YuktaiGridAgentProps = {
290
522
  tools: GridAgentTool[];
291
- onResult?: (result: unknown) => void;
523
+ onResult?: (result: GridAgentResult) => void;
292
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;
293
538
  };
294
- 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): {
295
542
  loading: boolean;
296
543
  tools: GridAgentTool[];
297
- executeTool: (name: string, input?: Record<string, unknown>) => Promise<unknown>;
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;
298
550
  };
299
551
 
300
- type GridToolColumn = {
301
- key: string;
302
- label: string;
303
- type?: "text" | "number" | "date";
304
- };
305
- type GridToolContext<T> = {
306
- data: T[];
307
- columns: GridToolColumn[];
308
- onSelectRow?: (id: string) => void;
309
- onHighlightRows?: (ids: string[]) => void;
310
- onOpenRow?: (id: string) => void;
311
- };
312
- type GridToolResult<T = unknown> = {
313
- success: boolean;
314
- message: string;
315
- data?: T;
316
- };
317
- declare function searchGrid<T extends Record<string, unknown>>(context: GridToolContext<T>, query: string): GridToolResult<T[]>;
318
- declare function countGrid<T>(context: GridToolContext<T>): GridToolResult<number>;
319
- declare function getColumns<T>(context: GridToolContext<T>): GridToolResult<GridToolColumn[]>;
320
- declare function getRow<T extends Record<string, unknown>>(context: GridToolContext<T>, id: string): GridToolResult<T>;
321
- declare function highlightRows<T extends Record<string, unknown>>(context: GridToolContext<T>, ids: string[]): GridToolResult<string[]>;
322
- declare function selectRow<T extends Record<string, unknown>>(context: GridToolContext<T>, id: string): GridToolResult<string>;
323
- declare function openRow<T extends Record<string, unknown>>(context: GridToolContext<T>, id: string): GridToolResult<string>;
324
-
325
552
  interface IconProps extends React.SVGAttributes<SVGSVGElement> {
326
553
  /** Size in pixels — applied to both width and height. Default: 20 */
327
554
  size?: number | string;
@@ -387,4 +614,4 @@ declare const YuktAI: {
387
614
  scan(): A11yReport;
388
615
  };
389
616
 
390
- 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 };