semiotic 3.5.4 → 3.6.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.
Files changed (94) hide show
  1. package/CLAUDE.md +61 -3
  2. package/README.md +17 -10
  3. package/ai/dist/mcp-server.js +249 -2
  4. package/ai/schema.json +34 -9
  5. package/ai/system-prompt.md +1 -1
  6. package/dist/components/ai/audienceProfile.d.ts +90 -0
  7. package/dist/components/ai/audiences.d.ts +31 -0
  8. package/dist/components/ai/chartCapabilities.d.ts +55 -0
  9. package/dist/components/ai/chartCapabilityTypes.d.ts +196 -0
  10. package/dist/components/ai/diffProfile.d.ts +51 -0
  11. package/dist/components/ai/inferIntent.d.ts +24 -0
  12. package/dist/components/ai/intents.d.ts +34 -0
  13. package/dist/components/ai/profileData.d.ts +16 -0
  14. package/dist/components/ai/qualityFixtures.d.ts +2 -0
  15. package/dist/components/ai/qualityScorecard.d.ts +82 -0
  16. package/dist/components/ai/repairChartConfig.d.ts +73 -0
  17. package/dist/components/ai/streamingTypes.d.ts +64 -0
  18. package/dist/components/ai/suggestCharts.d.ts +76 -0
  19. package/dist/components/ai/suggestDashboard.d.ts +92 -0
  20. package/dist/components/ai/suggestStreamCharts.d.ts +34 -0
  21. package/dist/components/ai/suggestStretchCharts.d.ts +60 -0
  22. package/dist/components/ai/useChartSuggestions.d.ts +22 -0
  23. package/dist/components/charts/geo/ChoroplethMap.capability.d.ts +2 -0
  24. package/dist/components/charts/geo/DistanceCartogram.capability.d.ts +2 -0
  25. package/dist/components/charts/geo/FlowMap.capability.d.ts +2 -0
  26. package/dist/components/charts/geo/ProportionalSymbolMap.capability.d.ts +2 -0
  27. package/dist/components/charts/index.d.ts +1 -1
  28. package/dist/components/charts/network/ChordDiagram.capability.d.ts +2 -0
  29. package/dist/components/charts/network/CirclePack.capability.d.ts +2 -0
  30. package/dist/components/charts/network/ForceDirectedGraph.capability.d.ts +2 -0
  31. package/dist/components/charts/network/OrbitDiagram.capability.d.ts +2 -0
  32. package/dist/components/charts/network/ProcessSankey.capability.d.ts +2 -0
  33. package/dist/components/charts/network/SankeyDiagram.capability.d.ts +2 -0
  34. package/dist/components/charts/network/TreeDiagram.capability.d.ts +2 -0
  35. package/dist/components/charts/network/Treemap.capability.d.ts +2 -0
  36. package/dist/components/charts/ordinal/BarChart.capability.d.ts +2 -0
  37. package/dist/components/charts/ordinal/BoxPlot.capability.d.ts +2 -0
  38. package/dist/components/charts/ordinal/DonutChart.capability.d.ts +2 -0
  39. package/dist/components/charts/ordinal/DotPlot.capability.d.ts +2 -0
  40. package/dist/components/charts/ordinal/FunnelChart.capability.d.ts +2 -0
  41. package/dist/components/charts/ordinal/GaugeChart.capability.d.ts +2 -0
  42. package/dist/components/charts/ordinal/GroupedBarChart.capability.d.ts +2 -0
  43. package/dist/components/charts/ordinal/Histogram.capability.d.ts +2 -0
  44. package/dist/components/charts/ordinal/Histogram.d.ts +4 -2
  45. package/dist/components/charts/ordinal/LikertChart.capability.d.ts +2 -0
  46. package/dist/components/charts/ordinal/LikertChart.d.ts +1 -1
  47. package/dist/components/charts/ordinal/LikertChart.defaults.d.ts +1 -0
  48. package/dist/components/charts/ordinal/PieChart.capability.d.ts +2 -0
  49. package/dist/components/charts/ordinal/RidgelinePlot.capability.d.ts +2 -0
  50. package/dist/components/charts/ordinal/StackedBarChart.capability.d.ts +2 -0
  51. package/dist/components/charts/ordinal/SwarmPlot.capability.d.ts +2 -0
  52. package/dist/components/charts/ordinal/SwimlaneChart.capability.d.ts +2 -0
  53. package/dist/components/charts/ordinal/ViolinPlot.capability.d.ts +2 -0
  54. package/dist/components/charts/realtime/RealtimeHeatmap.capability.d.ts +2 -0
  55. package/dist/components/charts/realtime/RealtimeHistogram.capability.d.ts +2 -0
  56. package/dist/components/charts/realtime/RealtimeLineChart.capability.d.ts +2 -0
  57. package/dist/components/charts/realtime/RealtimeSwarmChart.capability.d.ts +2 -0
  58. package/dist/components/charts/realtime/RealtimeWaterfallChart.capability.d.ts +2 -0
  59. package/dist/components/charts/realtime/TemporalHistogram.capability.d.ts +7 -0
  60. package/dist/components/charts/shared/chartSpecs.d.ts +0 -34
  61. package/dist/components/charts/xy/AreaChart.capability.d.ts +10 -0
  62. package/dist/components/charts/xy/BubbleChart.capability.d.ts +2 -0
  63. package/dist/components/charts/xy/CandlestickChart.capability.d.ts +2 -0
  64. package/dist/components/charts/xy/ConnectedScatterplot.capability.d.ts +2 -0
  65. package/dist/components/charts/xy/DifferenceChart.capability.d.ts +8 -0
  66. package/dist/components/charts/xy/Heatmap.capability.d.ts +9 -0
  67. package/dist/components/charts/xy/LineChart.capability.d.ts +9 -0
  68. package/dist/components/charts/xy/MinimapChart.capability.d.ts +2 -0
  69. package/dist/components/charts/xy/MultiAxisLineChart.capability.d.ts +2 -0
  70. package/dist/components/charts/xy/QuadrantChart.capability.d.ts +2 -0
  71. package/dist/components/charts/xy/QuadrantChart.d.ts +5 -2
  72. package/dist/components/charts/xy/QuadrantChart.defaults.d.ts +2 -0
  73. package/dist/components/charts/xy/Scatterplot.capability.d.ts +2 -0
  74. package/dist/components/charts/xy/StackedAreaChart.capability.d.ts +2 -0
  75. package/dist/components/data/DataSummarizer.d.ts +45 -0
  76. package/dist/components/semiotic-ai.d.ts +35 -0
  77. package/dist/components/semiotic-xy.d.ts +1 -1
  78. package/dist/components/semiotic.d.ts +1 -1
  79. package/dist/components/store/useChartFocus.d.ts +43 -0
  80. package/dist/components/store/useChartInterrogation.d.ts +141 -0
  81. package/dist/ordinal.min.js +1 -1
  82. package/dist/ordinal.module.min.js +1 -1
  83. package/dist/semiotic-ai.d.ts +35 -0
  84. package/dist/semiotic-ai.min.js +1 -1
  85. package/dist/semiotic-ai.module.min.js +1 -1
  86. package/dist/semiotic-utils.min.js +1 -1
  87. package/dist/semiotic-utils.module.min.js +1 -1
  88. package/dist/semiotic-xy.d.ts +1 -1
  89. package/dist/semiotic.d.ts +1 -1
  90. package/dist/semiotic.min.js +1 -1
  91. package/dist/semiotic.module.min.js +1 -1
  92. package/dist/xy.min.js +1 -1
  93. package/dist/xy.module.min.js +1 -1
  94. package/package.json +13 -4
@@ -0,0 +1,45 @@
1
+ import type { Datum } from "../charts/shared/datumTypes";
2
+ export type FieldType = "numeric" | "categorical" | "date" | "unknown";
3
+ export interface NumericFieldSummary {
4
+ type: "numeric";
5
+ min: number;
6
+ max: number;
7
+ mean: number;
8
+ median: number;
9
+ }
10
+ export interface DateFieldSummary {
11
+ type: "date";
12
+ min: string;
13
+ max: string;
14
+ }
15
+ export interface CategoricalFieldSummary {
16
+ type: "categorical";
17
+ distinctCount: number;
18
+ topValues: ReadonlyArray<{
19
+ value: string;
20
+ count: number;
21
+ }>;
22
+ distinctValues?: ReadonlyArray<string>;
23
+ }
24
+ export interface UnknownFieldSummary {
25
+ type: "unknown";
26
+ }
27
+ export type FieldSummary = NumericFieldSummary | DateFieldSummary | CategoricalFieldSummary | UnknownFieldSummary;
28
+ export interface DataSummary {
29
+ rowCount: number;
30
+ fields: Record<string, FieldSummary>;
31
+ sample: ReadonlyArray<Datum>;
32
+ }
33
+ export interface SummarizeOptions {
34
+ maxDistinct?: number;
35
+ sampleSize?: number;
36
+ /** Scan up to this many rows when discovering field keys (handles ragged rows). */
37
+ keyScanRows?: number;
38
+ }
39
+ /**
40
+ * Summarize a dataset for an LLM. Returns row count, per-field statistics, and a small sample.
41
+ *
42
+ * Designed so a model can answer questions about ranges, peaks, distributions, and categories
43
+ * without seeing the full dataset.
44
+ */
45
+ export declare function summarizeData(data: ReadonlyArray<Datum> | null | undefined, options?: SummarizeOptions): DataSummary;
@@ -66,6 +66,41 @@ export { serializeSelections, deserializeSelections } from "./export/selectionSe
66
66
  export type { SerializedSelections, SerializedSelection, SerializedFieldSelection } from "./export/selectionSerializer";
67
67
  export { fromVegaLite } from "./data/fromVegaLite";
68
68
  export type { VegaLiteSpec, VegaLiteEncoding } from "./data/fromVegaLite";
69
+ export { useChartInterrogation } from "./store/useChartInterrogation";
70
+ export type { UseChartInterrogationOptions, UseChartInterrogationResult, InterrogationContext, InterrogationFocus, InterrogationResult, InterrogationQuery, InterrogationMessage, } from "./store/useChartInterrogation";
71
+ export { useChartFocus } from "./store/useChartFocus";
72
+ export type { UseChartFocusOptions } from "./store/useChartFocus";
73
+ export { summarizeData } from "./data/DataSummarizer";
74
+ export type { DataSummary, FieldSummary, FieldType, NumericFieldSummary, DateFieldSummary, CategoricalFieldSummary, UnknownFieldSummary, SummarizeOptions, } from "./data/DataSummarizer";
75
+ export { profileData } from "./ai/profileData";
76
+ export type { ProfileDataOptions } from "./ai/profileData";
77
+ export { suggestCharts, scoreChart, explainCapabilityFit } from "./ai/suggestCharts";
78
+ export type { SuggestChartsOptions, RejectedCapability, ExplainCapabilityFitResult, } from "./ai/suggestCharts";
79
+ export { inferIntent } from "./ai/inferIntent";
80
+ export type { InferIntentResult } from "./ai/inferIntent";
81
+ export { suggestDashboard } from "./ai/suggestDashboard";
82
+ export type { DashboardPanel, DashboardSuggestion, SuggestDashboardOptions, } from "./ai/suggestDashboard";
83
+ export { applyAudienceBias, effectiveFamiliarity, stretchFamiliarityCeiling, } from "./ai/audienceProfile";
84
+ export type { AudienceProfile, AudienceTarget, AudienceBiasResult, } from "./ai/audienceProfile";
85
+ export { executivePersona, analystPersona, dataScientistPersona, BUILT_IN_AUDIENCES, } from "./ai/audiences";
86
+ export { suggestStretchCharts } from "./ai/suggestStretchCharts";
87
+ export type { StretchSuggestion, SuggestStretchChartsOptions, } from "./ai/suggestStretchCharts";
88
+ export { suggestStreamCharts, registerStreamChartCapability, unregisterStreamChartCapability, getStreamCapabilities, } from "./ai/suggestStreamCharts";
89
+ export type { SuggestStreamChartsOptions } from "./ai/suggestStreamCharts";
90
+ export type { StreamSchema, StreamFieldSchema, StreamFieldKind, StreamChartCapability, StreamIntentScorer, StreamSuggestion, } from "./ai/streamingTypes";
91
+ export { diffProfile } from "./ai/diffProfile";
92
+ export type { ProfileDiff, FieldTypeChange, PrimaryRoleChange, PrimaryRole } from "./ai/diffProfile";
93
+ export { repairChartConfig } from "./ai/repairChartConfig";
94
+ export type { RepairResult, RepairOkResult, RepairAlternativeResult, RepairUnknownResult, RepairOptions, } from "./ai/repairChartConfig";
95
+ export { runQualityScorecard } from "./ai/qualityScorecard";
96
+ export type { ScorecardFixture, ScorecardReport, PerCapabilityScore, PerFixtureScore, } from "./ai/qualityScorecard";
97
+ export { CANONICAL_FIXTURES } from "./ai/qualityFixtures";
98
+ export { useChartSuggestions } from "./ai/useChartSuggestions";
99
+ export type { UseChartSuggestionsOptions, UseChartSuggestionsResult } from "./ai/useChartSuggestions";
100
+ export { getCapabilities, getCapability, registerChartCapability, unregisterChartCapability, LineChartCapability, AreaChartCapability, StackedAreaChartCapability, ScatterplotCapability, ConnectedScatterplotCapability, BubbleChartCapability, QuadrantChartCapability, MultiAxisLineChartCapability, MinimapChartCapability, DifferenceChartCapability, CandlestickChartCapability, HeatmapCapability, BarChartCapability, GroupedBarChartCapability, StackedBarChartCapability, DotPlotCapability, PieChartCapability, DonutChartCapability, FunnelChartCapability, GaugeChartCapability, LikertChartCapability, SwimlaneChartCapability, HistogramCapability, BoxPlotCapability, SwarmPlotCapability, ViolinPlotCapability, RidgelinePlotCapability, ForceDirectedGraphCapability, SankeyDiagramCapability, ChordDiagramCapability, ProcessSankeyCapability, TreeDiagramCapability, TreemapCapability, CirclePackCapability, OrbitDiagramCapability, ChoroplethMapCapability, ProportionalSymbolMapCapability, FlowMapCapability, DistanceCartogramCapability, } from "./ai/chartCapabilities";
101
+ export type { ChartCapability, ChartDataProfile, ChartFamily, ChartImportPath, ChartRubric, ChartVariant, FieldCandidate, FieldKind, FitResult, IntentScorer, Suggestion, } from "./ai/chartCapabilityTypes";
102
+ export { listIntents, getIntent, registerIntent, BUILT_IN_INTENT_IDS } from "./ai/intents";
103
+ export type { BuiltInIntentId, IntentId, IntentDescriptor } from "./ai/intents";
69
104
  export { useChartObserver } from "./store/useObservation";
70
105
  export type { UseChartObserverOptions, UseChartObserverResult } from "./store/useObservation";
71
106
  export type { ChartObservation, OnObservationCallback, HoverObservation, HoverEndObservation, BrushObservation, BrushEndObservation, SelectionObservation, SelectionEndObservation, ClickObservation, ClickEndObservation } from "./store/ObservationStore";
@@ -28,7 +28,7 @@ export type { ScatterplotProps } from "./charts/xy/Scatterplot";
28
28
  export type { ConnectedScatterplotProps } from "./charts/xy/ConnectedScatterplot";
29
29
  export type { BubbleChartProps } from "./charts/xy/BubbleChart";
30
30
  export type { HeatmapProps } from "./charts/xy/Heatmap";
31
- export type { QuadrantChartProps } from "./charts/xy/QuadrantChart";
31
+ export type { QuadrantChartProps, QuadrantsConfig, QuadrantsConfigOverride, QuadrantConfig, CenterlineStyle } from "./charts/xy/QuadrantChart";
32
32
  export type { MultiAxisLineChartProps } from "./charts/xy/MultiAxisLineChart";
33
33
  export type { CandlestickChartProps } from "./charts/xy/CandlestickChart";
34
34
  export type { XYCustomChartProps } from "./charts/custom/XYCustomChart";
@@ -25,7 +25,7 @@ import { RealtimeWaterfallChart } from "./charts/realtime/RealtimeWaterfallChart
25
25
  import { RealtimeHeatmap } from "./charts/realtime/RealtimeHeatmap";
26
26
  export { StreamXYFrame, StreamOrdinalFrame, StreamNetworkFrame, Scatterplot, ConnectedScatterplot, LineChart, AreaChart, DifferenceChart, StackedAreaChart, Heatmap, BubbleChart, BarChart, StackedBarChart, LikertChart, SwarmPlot, BoxPlot, Histogram, ViolinPlot, RidgelinePlot, DotPlot, ForceDirectedGraph, ChordDiagram, SankeyDiagram, ProcessSankey, TreeDiagram, PieChart, DonutChart, GaugeChart, FunnelChart, GroupedBarChart, SwimlaneChart, Treemap, CirclePack, OrbitDiagram, ScatterplotMatrix, MinimapChart, QuadrantChart, MultiAxisLineChart, CandlestickChart, XYCustomChart, NetworkCustomChart, OrdinalCustomChart, LinkedCharts, ThemeProvider, useTheme, exportChart, toConfig, fromConfig, toURL, fromURL, copyConfig, configToJSX, serializeSelections, deserializeSelections, fromVegaLite, ChartErrorBoundary, ChartContainer, ChartGrid, CategoryColorProvider, useCategoryColors, ContextLayout, DetailsPanel, Tooltip, MultiLineTooltip, normalizeTooltip, RingBuffer, IncrementalExtent, RealtimeLineChart, RealtimeTemporalHistogram, RealtimeHistogram, TemporalHistogram, RealtimeSwarmChart, RealtimeWaterfallChart, RealtimeHeatmap, createHatchPattern };
27
27
  export type { LegendLayout } from "./types/legendTypes";
28
- export { ScatterplotProps, ConnectedScatterplotProps, LineChartProps, AreaChartProps, SemanticGradientStop, DifferenceChartProps, StackedAreaChartProps, HeatmapProps, BubbleChartProps, BarChartProps, StackedBarChartProps, LikertChartProps, SwarmPlotProps, BoxPlotProps, HistogramProps, ViolinPlotProps, DotPlotProps, PieChartProps, DonutChartProps, GaugeChartProps, GaugeThreshold, FunnelChartProps, GroupedBarChartProps, SwimlaneChartProps, RidgelinePlotProps, OrbitDiagramProps, OrbitNode, ForceDirectedGraphProps, ChordDiagramProps, SankeyDiagramProps, ProcessSankeyProps, ProcessSankeyTick, TreeDiagramProps, TreemapProps, CirclePackProps, ScatterplotMatrixProps, MinimapChartProps, MinimapConfig, QuadrantChartProps, MultiAxisLineChartProps, MultiAxisSeriesConfig, CandlestickChartProps, QuadrantsConfig, QuadrantConfig, CenterlineStyle, BaseChartProps, AxisConfig, Accessor, ChartAccessor, ChartMode } from "./charts";
28
+ export { ScatterplotProps, ConnectedScatterplotProps, LineChartProps, AreaChartProps, SemanticGradientStop, DifferenceChartProps, StackedAreaChartProps, HeatmapProps, BubbleChartProps, BarChartProps, StackedBarChartProps, LikertChartProps, SwarmPlotProps, BoxPlotProps, HistogramProps, ViolinPlotProps, DotPlotProps, PieChartProps, DonutChartProps, GaugeChartProps, GaugeThreshold, FunnelChartProps, GroupedBarChartProps, SwimlaneChartProps, RidgelinePlotProps, OrbitDiagramProps, OrbitNode, ForceDirectedGraphProps, ChordDiagramProps, SankeyDiagramProps, ProcessSankeyProps, ProcessSankeyTick, TreeDiagramProps, TreemapProps, CirclePackProps, ScatterplotMatrixProps, MinimapChartProps, MinimapConfig, QuadrantChartProps, MultiAxisLineChartProps, MultiAxisSeriesConfig, CandlestickChartProps, QuadrantsConfig, QuadrantsConfigOverride, QuadrantConfig, CenterlineStyle, BaseChartProps, AxisConfig, Accessor, ChartAccessor, ChartMode } from "./charts";
29
29
  export type { StreamXYFrameProps, StreamXYFrameHandle, StreamChartType, RuntimeMode, SceneNode, Changeset, StreamScales, StreamLayout, CurveType, CanvasRendererFn, XYFrameAxisConfig, BandConfig } from "./stream/types";
30
30
  export type { StreamRendererFn } from "./stream/renderers/types";
31
31
  export type { StreamOrdinalFrameProps, StreamOrdinalFrameHandle, OrdinalChartType, OrdinalScales, OrdinalSceneNode } from "./stream/ordinalTypes";
@@ -0,0 +1,43 @@
1
+ import type { ChartObservation } from "./ObservationStore";
2
+ import type { InterrogationFocus } from "./useChartInterrogation";
3
+ export interface UseChartFocusOptions {
4
+ /** Limit attention to a specific chart instance. Required when the page has more than one. */
5
+ chartId?: string;
6
+ /**
7
+ * Which observation types count as "focused." Default is hover + click +
8
+ * selection — anything that signals user attention. Set to ["click"] for
9
+ * sticky-focus UIs where hover doesn't change the AI's reference point.
10
+ */
11
+ types?: ChartObservation["type"][];
12
+ }
13
+ /**
14
+ * Convenience hook: returns the latest `InterrogationFocus` for use with
15
+ * `useChartInterrogation`'s `focus` option. Internally subscribes to the
16
+ * observation store and converts the latest matching observation into the
17
+ * focus shape.
18
+ *
19
+ * Pair with `<Chart onObservation={…} chartId="myChart" />` and an
20
+ * `<ObservationProvider>` ancestor.
21
+ *
22
+ * Returns `null` when no qualifying observation has fired yet.
23
+ *
24
+ * @example
25
+ * function ChartWithChat({ data }) {
26
+ * const focus = useChartFocus({ chartId: "sales" })
27
+ * const { ask, history, annotations } = useChartInterrogation({
28
+ * data,
29
+ * focus, // ← latest hovered/clicked datum threads in
30
+ * onQuery: async (q, ctx) => {
31
+ * // ctx.focus is the same `focus` value passed above
32
+ * return askLLM({ question: q, focus: ctx.focus, summary: ctx.summary })
33
+ * },
34
+ * })
35
+ * return (
36
+ * <>
37
+ * <LineChart data={data} chartId="sales" annotations={annotations} />
38
+ * <YourChatUI history={history} onAsk={ask} />
39
+ * </>
40
+ * )
41
+ * }
42
+ */
43
+ export declare function useChartFocus(options?: UseChartFocusOptions): InterrogationFocus | null;
@@ -0,0 +1,141 @@
1
+ import type { Datum } from "../charts/shared/datumTypes";
2
+ import { type DataSummary } from "../data/DataSummarizer";
3
+ import type { ChartDataProfile, Suggestion } from "../ai/chartCapabilityTypes";
4
+ import type { IntentId } from "../ai/intents";
5
+ /**
6
+ * Identifies a single point of interest on the chart — typically the datum
7
+ * the user is currently hovering, clicked, or otherwise focused on. When
8
+ * provided, the LLM gets the explicit signal that the user is asking
9
+ * "about *this specific point*" rather than the chart at large.
10
+ */
11
+ export interface InterrogationFocus {
12
+ /** The row the user is focused on. */
13
+ datum: Datum;
14
+ /** Pixel x coordinate, when known. Useful for anchoring response annotations. */
15
+ x?: number;
16
+ /** Pixel y coordinate, when known. */
17
+ y?: number;
18
+ /** Optional source label — "hover" / "click" / "selection". Surfaces in the LLM prompt. */
19
+ source?: "hover" | "click" | "selection" | "manual";
20
+ }
21
+ export interface InterrogationContext {
22
+ /** The data extracted from the chart (or whatever caller passed in). */
23
+ data: ReadonlyArray<Datum>;
24
+ /** Statistical summary, ready to send to an LLM. */
25
+ summary: DataSummary;
26
+ /** Shape profile — present when `includeProfile` or `includeSuggestions` is enabled. */
27
+ profile?: ChartDataProfile;
28
+ /** Heuristic chart suggestions — present when `includeSuggestions` is enabled. */
29
+ suggestions?: ReadonlyArray<Suggestion>;
30
+ /** Optional caller-supplied chart component name (e.g. "LineChart"). */
31
+ componentName?: string;
32
+ /** Optional caller-supplied chart props (accessor names, scales, etc.). */
33
+ props?: Record<string, unknown>;
34
+ /**
35
+ * The current focused datum — what the user is interactively pointing at.
36
+ * Lets the LLM tailor responses to a specific point ("why is *this* one
37
+ * higher than the rest?") and to anchor visual responses (callouts,
38
+ * comments) back at the same coordinates.
39
+ */
40
+ focus?: InterrogationFocus;
41
+ }
42
+ export interface InterrogationResult {
43
+ /** Natural-language answer to display to the user. */
44
+ answer: string;
45
+ /** Optional Semiotic annotations to overlay on the chart. */
46
+ annotations?: ReadonlyArray<Datum>;
47
+ }
48
+ export type InterrogationQuery = (query: string, context: InterrogationContext) => Promise<InterrogationResult>;
49
+ export interface InterrogationMessage {
50
+ role: "user" | "assistant";
51
+ text: string;
52
+ }
53
+ export interface UseChartInterrogationOptions {
54
+ /** Data backing the chart. Use whatever shape the chart consumes (rows, nodes, etc.). */
55
+ data: ReadonlyArray<Datum> | null | undefined;
56
+ /** Async handler — typically calls your LLM with the query + summary. */
57
+ onQuery: InterrogationQuery;
58
+ /** Annotations to seed the merged set (e.g. existing chart annotations). */
59
+ initialAnnotations?: ReadonlyArray<Datum>;
60
+ /** Optional context passed through to onQuery for richer prompts. */
61
+ componentName?: string;
62
+ /** Optional context passed through to onQuery. */
63
+ props?: Record<string, unknown>;
64
+ /**
65
+ * Include the shape `profile` in the interrogation context. Required to let an LLM
66
+ * reason about candidate axes, distinct counts, hierarchy/network/geo detection, etc.
67
+ */
68
+ includeProfile?: boolean;
69
+ /**
70
+ * Include heuristic chart `suggestions` in the interrogation context. Implies `includeProfile`.
71
+ * Lets an LLM answer "would another chart show this better?" without re-deriving rules.
72
+ */
73
+ includeSuggestions?: boolean;
74
+ /** When `includeSuggestions` is true, rank by this intent. */
75
+ suggestionsIntent?: IntentId | IntentId[];
76
+ /** When `includeSuggestions` is true, cap the suggestion list. Default 5. */
77
+ suggestionsMax?: number;
78
+ /**
79
+ * The point on the chart the user is currently focused on. Forwarded to
80
+ * onQuery so an LLM can answer "about this specific datum" rather than
81
+ * "about the chart in general." Typically wired from a chart's
82
+ * `onObservation` callback or the convenience `useChartFocus` hook.
83
+ */
84
+ focus?: InterrogationFocus | null;
85
+ }
86
+ export interface UseChartInterrogationResult {
87
+ /** Ask a question. Updates history, annotations, loading, and error. */
88
+ ask: (query: string) => Promise<void>;
89
+ /**
90
+ * Append an AI-initiated message to the transcript without a user query.
91
+ *
92
+ * Use for proactive narration — a streaming watcher that detected an
93
+ * anomaly, a background analysis that surfaced an insight, an LLM that
94
+ * decided to volunteer information mid-session. Synchronous; no `onQuery`
95
+ * call. Annotations merge into the chart's `annotations` array like
96
+ * any other AI response.
97
+ *
98
+ * @example
99
+ * announce({
100
+ * text: "Spike detected at 14:32 — 3.2σ above rolling mean.",
101
+ * annotations: [{ type: "callout", ts: now, value: 850, note: "Slow query?" }],
102
+ * })
103
+ */
104
+ announce: (message: {
105
+ text: string;
106
+ annotations?: ReadonlyArray<Datum>;
107
+ }) => void;
108
+ /** Conversation history, oldest first. */
109
+ history: ReadonlyArray<InterrogationMessage>;
110
+ /** Statistical summary of the data — memoized, safe to pass to a prompt. */
111
+ summary: DataSummary;
112
+ /** Merged annotations: initial + latest AI response. Pass to the chart's `annotations` prop. */
113
+ annotations: ReadonlyArray<Datum>;
114
+ /** True while onQuery is in flight. */
115
+ loading: boolean;
116
+ /** Last error from onQuery, if any. */
117
+ error: Error | null;
118
+ /** Clear history, AI annotations, and error. */
119
+ reset: () => void;
120
+ }
121
+ /**
122
+ * Headless interrogation hook — a sibling to `useChartObserver`.
123
+ *
124
+ * Generates an LLM-friendly statistical summary of your chart's data, runs queries through
125
+ * a caller-supplied `onQuery`, and merges any annotations the response returns so the chart
126
+ * can highlight what the model is talking about.
127
+ *
128
+ * The hook owns no UI. Render whatever input/transcript surface fits your product.
129
+ *
130
+ * @example
131
+ * const { ask, history, annotations, loading } = useChartInterrogation({
132
+ * data,
133
+ * onQuery: async (q, ctx) => {
134
+ * const res = await fetch("/api/chat", { method: "POST", body: JSON.stringify({ q, summary: ctx.summary }) })
135
+ * return res.json()
136
+ * },
137
+ * })
138
+ *
139
+ * <LineChart data={data} annotations={annotations} ... />
140
+ */
141
+ export declare function useChartInterrogation(options: UseChartInterrogationOptions): UseChartInterrogationResult;