@lightdash/query-sdk 3.96.0 → 3.97.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/features.js CHANGED
@@ -169,6 +169,13 @@ export const SDK_FEATURES = [
169
169
  description: 'Author-written guidance for the AI analysis — language and formatting rules (e.g. British English, amounts in EUR) and a line or two of domain vocabulary — applied to every summary the app shows.',
170
170
  wiring: "Pass the guidance where the app renders its view-level analysis: useInsights({ instructions: '<guidance>' }), or the instructions prop on the shipped InsightsSummary component. One string per app; keep it to a few short sentences.",
171
171
  },
172
+ {
173
+ key: 'analysis-on-load',
174
+ appliesTo: ['data_app'],
175
+ label: 'AI analysis on load',
176
+ description: 'Run the AI analysis as soon as the app loads, without the viewer clicking Analyse. A stored analysis of the same rows is reused.',
177
+ wiring: 'Only when the user asks for it: set the analyseOnLoad prop on the shipped InsightsSummary component, or useInsights({ analyseOnLoad: true }) in a custom block. One value per app.',
178
+ },
172
179
  {
173
180
  key: 'ai-prompt',
174
181
  appliesTo: ['data_app'],
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "3.96.0";
1
+ export declare const SDK_VERSION = "3.97.0";
@@ -1,2 +1,2 @@
1
1
  // Generated by scripts/generateSdkVersion.mjs (prebuild) — do not edit.
2
- export const SDK_VERSION = '3.96.0';
2
+ export const SDK_VERSION = '3.97.0';
@@ -69,6 +69,8 @@ export type InsightsRequestMessage = {
69
69
  /** Author guidance the host forwards to the analysis model, set via
70
70
  * `useInsights({ instructions })`. One string per app. */
71
71
  instructions?: string;
72
+ /** Set via `useInsights({ analyseOnLoad })`; absent = not declared. */
73
+ analyseOnLoad?: boolean;
72
74
  };
73
75
  export type InsightAction = {
74
76
  action: 'analyse';
@@ -98,6 +100,8 @@ export declare const EMPTY_INSIGHTS: InsightsPayload;
98
100
  export declare const parseInsightsPayload: (value: unknown) => InsightsPayload | null;
99
101
  /** Module-internal (exported for tests); `useInsights({ instructions })` wraps it. */
100
102
  export declare const setInsightInstructions: (value: string | undefined) => void;
103
+ /** Module-internal (exported for tests); `useInsights({ analyseOnLoad })` wraps it. */
104
+ export declare const setInsightAnalyseOnLoad: (value: boolean | undefined) => void;
101
105
  /**
102
106
  * Listen for the host's analysis and ask for the current one now. Called by
103
107
  * `createClient()` on the postMessage transport. One listener per bundle.
@@ -119,6 +123,9 @@ export type ViewInsightsOptions = {
119
123
  * line or two of domain vocabulary. One string per app (the last value
120
124
  * set wins); the host caps its length. */
121
125
  instructions?: string;
126
+ /** Analyse the view as soon as its queries settle, without a click.
127
+ * A stored analysis of the same rows is reused. One value per app. */
128
+ analyseOnLoad?: boolean;
122
129
  };
123
130
  export type ViewInsights = InsightsPayload & {
124
131
  /** Ask the host to analyse the current view (or re-analyse when stale). */
@@ -155,6 +162,7 @@ export declare function useHostAiAvailable(): boolean;
155
162
  *
156
163
  * const view = useInsights(); // executive summary + every anomaly
157
164
  * const view = useInsights({ instructions: 'Use British English.' });
165
+ * const view = useInsights({ analyseOnLoad: true });
158
166
  * const orders = useLightdash(ordersQuery);
159
167
  * const insights = useInsights(orders); // anomalies on this chart's rows
160
168
  *
package/dist/insights.js CHANGED
@@ -128,12 +128,17 @@ let activeCleanup = null;
128
128
  let inUse = false;
129
129
  // App-wide author guidance for the analysis model; last writer wins.
130
130
  let authorInstructions = null;
131
+ // App-wide analyse-on-load choice; null = not declared, last writer wins.
132
+ let authorAnalyseOnLoad = null;
131
133
  const requestMessage = () => ({
132
134
  type: INSIGHTS_REQUEST_MESSAGE,
133
135
  ...(inUse ? { inUse: true } : {}),
134
136
  ...(authorInstructions !== null
135
137
  ? { instructions: authorInstructions }
136
138
  : {}),
139
+ ...(authorAnalyseOnLoad !== null
140
+ ? { analyseOnLoad: authorAnalyseOnLoad }
141
+ : {}),
137
142
  });
138
143
  const markInUse = () => {
139
144
  if (inUse)
@@ -149,6 +154,14 @@ export const setInsightInstructions = (value) => {
149
154
  authorInstructions = next;
150
155
  hostWindow?.postMessage(requestMessage(), '*');
151
156
  };
157
+ /** Module-internal (exported for tests); `useInsights({ analyseOnLoad })` wraps it. */
158
+ export const setInsightAnalyseOnLoad = (value) => {
159
+ const next = value ?? null;
160
+ if (next === authorAnalyseOnLoad)
161
+ return;
162
+ authorAnalyseOnLoad = next;
163
+ hostWindow?.postMessage(requestMessage(), '*');
164
+ };
152
165
  const createStore = () => {
153
166
  let payload = EMPTY_INSIGHTS;
154
167
  const listeners = new Set();
@@ -304,6 +317,22 @@ export function useInsights(sourceOrOptions) {
304
317
  declaredInstructionsRef.current = true;
305
318
  setInsightInstructions(instructions);
306
319
  }, [instructions]);
320
+ const analyseOnLoad = source === undefined
321
+ ? sourceOrOptions
322
+ ?.analyseOnLoad
323
+ : undefined;
324
+ const declaredAnalyseOnLoadRef = useRef(false);
325
+ useEffect(() => {
326
+ if (analyseOnLoad === undefined) {
327
+ if (!declaredAnalyseOnLoadRef.current)
328
+ return;
329
+ declaredAnalyseOnLoadRef.current = false;
330
+ setInsightAnalyseOnLoad(undefined);
331
+ return;
332
+ }
333
+ declaredAnalyseOnLoadRef.current = true;
334
+ setInsightAnalyseOnLoad(analyseOnLoad);
335
+ }, [analyseOnLoad]);
307
336
  const payload = useInsightsPayload();
308
337
  const investigate = useCallback((anomalyId) => postInsightAction({ action: 'investigate', anomalyId }), []);
309
338
  const canContinue = payload.canContinue;
@@ -360,6 +389,7 @@ export function resetInsightsState() {
360
389
  hostWindow = null;
361
390
  inUse = false;
362
391
  authorInstructions = null;
392
+ authorAnalyseOnLoad = null;
363
393
  mounted.clear();
364
394
  flushScheduled = false;
365
395
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/query-sdk",
3
- "version": "3.96.0",
3
+ "version": "3.97.0",
4
4
  "private": false,
5
5
  "description": "SDK for building custom data apps against the Lightdash semantic layer",
6
6
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  }
27
27
  },
28
28
  "devDependencies": {
29
- "@lightdash/common": "3.96.0",
29
+ "@lightdash/common": "3.97.0",
30
30
  "@types/node": "22.13.1",
31
31
  "@types/react": "19.3.0",
32
32
  "@types/react-dom": "19.3.0",