@yuktishaalaa/yuktai 4.6.4 → 5.0.0

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