@dbx-tools/ui-mastra 0.9.212 → 0.9.213

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/index.support.ts CHANGED
@@ -12,6 +12,7 @@ export * as genieClient from "./src/support/genie-client.ts";
12
12
  export * as mastraClient from "./src/support/mastra-client.ts";
13
13
  export * as modelSelection from "./src/support/model-selection.ts";
14
14
  export * as requestContext from "./src/support/request-context.ts";
15
+ export * as statementPresentation from "./src/support/statement-presentation.ts";
15
16
  export * as threadLabels from "./src/support/thread-labels.ts";
16
17
  export * as threadPersistence from "./src/support/thread-persistence.ts";
17
18
  export * as threadSessions from "./src/support/thread-sessions.ts";
@@ -34,6 +35,8 @@ export { messageTextFromParts } from "./src/support/message-text.ts";
34
35
  export { defaultReasoningEffort, modelStorageKey, readStoredModel, storeSelectedModel } from "./src/support/model-selection.ts";
35
36
  export { snapshotRequestContext } from "./src/support/request-context.ts";
36
37
  export type { MastraRequestContextInput, MastraRequestContextSource } from "./src/support/request-context.ts";
38
+ export { statementColumnLabel, statementCellText } from "./src/support/statement-presentation.ts";
39
+ export type { StatementColumnPresentation } from "./src/support/statement-presentation.ts";
37
40
  export { threadTitle, relativeTime } from "./src/support/thread-labels.ts";
38
41
  export { threadStorageKey } from "./src/support/thread-persistence.ts";
39
42
  export { DEFAULT_THREAD_SESSION_KEY, createThreadSession, isSessionRunning, lastUserMessage, interruptedTurnMessages, conversationRequestMessages, enqueueSteer, removeSteer, reorderSteers, sessionKey } from "./src/support/thread-sessions.ts";
package/index.ts CHANGED
@@ -3,4 +3,4 @@
3
3
  // Hand edits are overwritten on the next generation; this file is read-only.
4
4
 
5
5
  export const PACKAGE_IDENTIFIER = "@dbx-tools/ui-mastra";
6
- export const PACKAGE_VERSION = "0.9.212";
6
+ export const PACKAGE_VERSION = "0.9.213";
package/package.json CHANGED
@@ -37,13 +37,13 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@databricks/appkit-ui": "0.81.0",
40
- "@dbx-tools/shared-auth": "0.9.212",
41
- "@dbx-tools/shared-core": "0.9.212",
42
- "@dbx-tools/shared-genie": "0.9.212",
43
- "@dbx-tools/shared-mastra": "0.9.212",
44
- "@dbx-tools/shared-model": "0.9.212",
45
- "@dbx-tools/shared-model-gateway": "0.9.212",
46
- "@dbx-tools/ui": "0.9.212",
40
+ "@dbx-tools/shared-auth": "0.9.213",
41
+ "@dbx-tools/shared-core": "0.9.213",
42
+ "@dbx-tools/shared-genie": "0.9.213",
43
+ "@dbx-tools/shared-mastra": "0.9.213",
44
+ "@dbx-tools/shared-model": "0.9.213",
45
+ "@dbx-tools/shared-model-gateway": "0.9.213",
46
+ "@dbx-tools/ui": "0.9.213",
47
47
  "@mastra/client-js": "1.50.0",
48
48
  "@mastra/core": "1.71.0",
49
49
  "@tanstack/react-table": "^8.21.3",
@@ -61,7 +61,7 @@
61
61
  "publishConfig": {
62
62
  "access": "public"
63
63
  },
64
- "version": "0.9.212",
64
+ "version": "0.9.213",
65
65
  "types": "index.ts",
66
66
  "dbxToolsConfig": {
67
67
  "tags": [
@@ -112,6 +112,10 @@ export function GenieImageTabs({
112
112
  rows={data.rows}
113
113
  rowCount={data.rowCount}
114
114
  truncated={data.truncated}
115
+ statementColumns={data.visualization.manifest.schema.columns.map((column) => ({
116
+ name: column.name,
117
+ typeName: column.type_name,
118
+ }))}
115
119
  />
116
120
  ) : (
117
121
  <p role="status" className="py-3 text-sm text-muted-foreground">
@@ -31,6 +31,11 @@ import {
31
31
  } from "lucide-react";
32
32
  import React, { useMemo, useState } from "react";
33
33
  import { downloadFile } from "../support/download.ts";
34
+ import {
35
+ statementCellText,
36
+ statementColumnLabel,
37
+ type StatementColumnPresentation,
38
+ } from "../support/statement-presentation.ts";
34
39
 
35
40
  // Interactive result table plus the cell/label/CSV helpers it and the
36
41
  // markdown table renderer share. Built on `@tanstack/react-table` over
@@ -195,6 +200,7 @@ export const DataGrid = ({
195
200
  truncated,
196
201
  rowCount,
197
202
  humanizeHeaders = false,
203
+ statementColumns,
198
204
  }: {
199
205
  columns: string[];
200
206
  rows: DataRow[];
@@ -206,21 +212,35 @@ export const DataGrid = ({
206
212
  * human-authored and would be mangled by the tokenizer.
207
213
  */
208
214
  humanizeHeaders?: boolean;
215
+ /**
216
+ * Statement manifest metadata. When present, cells receive best-effort
217
+ * Databricks-style number formatting and headers retain analytics acronyms.
218
+ */
219
+ statementColumns?: StatementColumnPresentation[];
209
220
  }) => {
210
221
  const [sorting, setSorting] = useState<SortingState>([]);
211
222
  const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
212
223
 
213
- const columnDefs = useMemo<ColumnDef<DataRow>[]>(
214
- () =>
215
- columns.map((col): ColumnDef<DataRow> => ({
224
+ const columnDefs = useMemo<ColumnDef<DataRow>[]>(() => {
225
+ const statementColumnByName = new Map(statementColumns?.map((column) => [column.name, column]));
226
+ return columns.map((col): ColumnDef<DataRow> => {
227
+ const statementColumn = statementColumnByName.get(col);
228
+ return {
216
229
  id: col,
217
230
  accessorFn: (row) => row[col],
218
- header: humanizeHeaders ? humanizeLabel(col) : col,
219
- cell: (info) => renderDataCell(info.getValue()),
231
+ header: statementColumn
232
+ ? statementColumnLabel(col)
233
+ : humanizeHeaders
234
+ ? humanizeLabel(col)
235
+ : col,
236
+ cell: (info) =>
237
+ renderDataCell(
238
+ statementColumn ? statementCellText(statementColumn, info.getValue()) : info.getValue(),
239
+ ),
220
240
  sortUndefined: "last",
221
- })),
222
- [columns, humanizeHeaders],
223
- );
241
+ };
242
+ });
243
+ }, [columns, humanizeHeaders, statementColumns]);
224
244
 
225
245
  const table = useReactTable({
226
246
  data: rows,
@@ -179,6 +179,10 @@ const DataSlot = ({ statementId }: { statementId: string }) => {
179
179
  truncated={data.truncated}
180
180
  rowCount={data.rowCount}
181
181
  humanizeHeaders
182
+ statementColumns={data.visualization.manifest.schema.columns.map((column) => ({
183
+ name: column.name,
184
+ typeName: column.type_name,
185
+ }))}
182
186
  />
183
187
  );
184
188
  };
@@ -23,7 +23,7 @@
23
23
  * @module
24
24
  */
25
25
 
26
- import { capitalize, toLabel, toSlugWithOptions, escapeHtml } from "@dbx-tools/shared-core";
26
+ import { capitalize, toSlugWithOptions, escapeHtml } from "@dbx-tools/shared-core";
27
27
  import {
28
28
  type Chart,
29
29
  type StatementData,
@@ -38,6 +38,11 @@ import { normalizeChartOption } from "./chart-option.ts";
38
38
  import { LIGHT_CHART_CHROME } from "./chart-theme.ts";
39
39
  import { downloadFile } from "./download.ts";
40
40
  import { messageTextFromParts } from "./message-text.ts";
41
+ import {
42
+ statementCellText,
43
+ statementColumnLabel,
44
+ type StatementColumnPresentation,
45
+ } from "./statement-presentation.ts";
41
46
 
42
47
  /**
43
48
  * Output formats {@link exportChat} can produce.
@@ -353,11 +358,19 @@ async function dataTableHtml(
353
358
  ): Promise<string | null> {
354
359
  const data = await safeStatement(resolver, id, visualization);
355
360
  if (!data || data.rows.length === 0) return null;
356
- const head = data.columns.map((c) => `<th>${escapeHtml(toLabel(c))}</th>`).join("");
361
+ const presentation = statementPresentation(data);
362
+ const head = data.columns
363
+ .map((column) => `<th>${escapeHtml(statementColumnLabel(column))}</th>`)
364
+ .join("");
357
365
  const body = data.rows
358
366
  .map(
359
367
  (row) =>
360
- `<tr>${data.columns.map((c) => `<td>${escapeHtml(cellText(row[c]))}</td>`).join("")}</tr>`,
368
+ `<tr>${data.columns
369
+ .map(
370
+ (column) =>
371
+ `<td>${escapeHtml(statementCellText(presentation.get(column) ?? { name: column }, row[column]))}</td>`,
372
+ )
373
+ .join("")}</tr>`,
361
374
  )
362
375
  .join("");
363
376
  const note = data.truncated
@@ -425,10 +438,16 @@ async function dataTableMarkdown(
425
438
  ): Promise<string | null> {
426
439
  const data = await safeStatement(resolver, id, visualization);
427
440
  if (!data || data.rows.length === 0) return null;
428
- const header = `| ${data.columns.map((c) => mdCell(toLabel(c))).join(" | ")} |`;
441
+ const presentation = statementPresentation(data);
442
+ const header = `| ${data.columns.map((column) => mdCell(statementColumnLabel(column))).join(" | ")} |`;
429
443
  const sep = `| ${data.columns.map(() => "---").join(" | ")} |`;
430
444
  const rows = data.rows.map(
431
- (row) => `| ${data.columns.map((c) => mdCell(cellText(row[c]))).join(" | ")} |`,
445
+ (row) =>
446
+ `| ${data.columns
447
+ .map((column) =>
448
+ mdCell(statementCellText(presentation.get(column) ?? { name: column }, row[column])),
449
+ )
450
+ .join(" | ")} |`,
432
451
  );
433
452
  const note = data.truncated ? `\n\n_Showing ${data.rows.length} of ${data.rowCount} rows._` : "";
434
453
  return `${[header, sep, ...rows].join("\n")}${note}`;
@@ -458,11 +477,14 @@ async function safeStatement(
458
477
  }
459
478
  }
460
479
 
461
- /** Stringify a table cell value for display. */
462
- function cellText(value: unknown): string {
463
- if (value == null) return "";
464
- if (typeof value === "object") return JSON.stringify(value);
465
- return String(value);
480
+ /** Index the manifest's SQL types by the raw result-column names. */
481
+ function statementPresentation(data: StatementData): Map<string, StatementColumnPresentation> {
482
+ return new Map(
483
+ data.visualization.manifest.schema.columns.map((column) => [
484
+ column.name,
485
+ { name: column.name, typeName: column.type_name },
486
+ ]),
487
+ );
466
488
  }
467
489
 
468
490
  /** Escape a Markdown table cell (pipes / newlines would break the row). */
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Best-effort presentation for Statement Execution results.
3
+ *
4
+ * Genie and Statement Execution expose raw SQL aliases and values but not the
5
+ * labels and number formats Databricks' first-party result grids derive for
6
+ * display. These helpers apply the same class of presentation without changing
7
+ * the raw row values used for sorting and CSV export.
8
+ *
9
+ * @module
10
+ */
11
+
12
+ import { toLabel } from "@dbx-tools/shared-core";
13
+
14
+ /** Column metadata available from a Statement Execution manifest. */
15
+ export interface StatementColumnPresentation {
16
+ /** Raw result-column name used as the row key. */
17
+ name: string;
18
+ /** SQL base type from the statement manifest. */
19
+ typeName?: string;
20
+ }
21
+
22
+ const ANALYTICS_ACRONYMS = new Map([
23
+ ["api", "API"],
24
+ ["dbu", "DBU"],
25
+ ["id", "ID"],
26
+ ["ids", "IDs"],
27
+ ["kpi", "KPI"],
28
+ ["kpis", "KPIs"],
29
+ ["ly", "LY"],
30
+ ["mom", "MoM"],
31
+ ["mtd", "MTD"],
32
+ ["pct", "%"],
33
+ ["perc", "%"],
34
+ ["percent", "%"],
35
+ ["percentage", "%"],
36
+ ["pspw", "PSPW"],
37
+ ["qoq", "QoQ"],
38
+ ["sql", "SQL"],
39
+ ["usd", "USD"],
40
+ ["wow", "WoW"],
41
+ ["yoy", "YoY"],
42
+ ["ytd", "YTD"],
43
+ ]);
44
+
45
+ const PERCENT_TOKENS = new Set(["pct", "perc", "percent", "percentage"]);
46
+ const CURRENCY_TOKENS = new Set([
47
+ "amount",
48
+ "cost",
49
+ "dollar",
50
+ "dollars",
51
+ "margin",
52
+ "price",
53
+ "profit",
54
+ "revenue",
55
+ "sales",
56
+ "spend",
57
+ "usd",
58
+ ]);
59
+ const WHOLE_NUMBER_TOKENS = new Set([
60
+ "count",
61
+ "day",
62
+ "days",
63
+ "gallon",
64
+ "gallons",
65
+ "guest",
66
+ "guests",
67
+ "hour",
68
+ "hours",
69
+ "pspw",
70
+ "unit",
71
+ "units",
72
+ ]);
73
+ const INTEGER_SQL_TYPES = new Set([
74
+ "BIGINT",
75
+ "BYTE",
76
+ "INT",
77
+ "INTEGER",
78
+ "LONG",
79
+ "SHORT",
80
+ "SMALLINT",
81
+ "TINYINT",
82
+ ]);
83
+
84
+ const NUMBER_FORMAT = new Intl.NumberFormat("en-US", {
85
+ maximumFractionDigits: 2,
86
+ });
87
+ const WHOLE_NUMBER_FORMAT = new Intl.NumberFormat("en-US", {
88
+ maximumFractionDigits: 0,
89
+ });
90
+ const CURRENCY_FORMAT = new Intl.NumberFormat("en-US", {
91
+ style: "currency",
92
+ currency: "USD",
93
+ minimumFractionDigits: 2,
94
+ maximumFractionDigits: 2,
95
+ });
96
+ const PERCENT_FORMAT = new Intl.NumberFormat("en-US", {
97
+ style: "percent",
98
+ minimumFractionDigits: 2,
99
+ maximumFractionDigits: 2,
100
+ });
101
+
102
+ function nameTokens(name: string): string[] {
103
+ return name.toLowerCase().match(/[a-z0-9]+/g) ?? [];
104
+ }
105
+
106
+ function hasToken(tokens: string[], candidates: Set<string>): boolean {
107
+ return tokens.some((token) => candidates.has(token));
108
+ }
109
+
110
+ /** Humanize a raw statement alias while retaining common analytics acronyms. */
111
+ export function statementColumnLabel(name: string): string {
112
+ return toLabel(name)
113
+ .split(" ")
114
+ .map((token) => ANALYTICS_ACRONYMS.get(token.toLowerCase()) ?? token)
115
+ .join(" ");
116
+ }
117
+
118
+ /**
119
+ * Format a statement cell for on-screen and document presentation.
120
+ *
121
+ * The API does not expose Metric View display formats. Percentage and currency
122
+ * semantics therefore come from explicit alias tokens, while SQL integer types
123
+ * and count-like names use grouped whole numbers. Unknown numeric measures keep
124
+ * up to two decimals. Non-numeric values pass through unchanged.
125
+ */
126
+ export function statementCellText(column: StatementColumnPresentation, value: unknown): string {
127
+ if (value == null) return "";
128
+ if (typeof value !== "number" || !Number.isFinite(value)) return String(value);
129
+
130
+ const tokens = nameTokens(column.name);
131
+ if (hasToken(tokens, PERCENT_TOKENS)) return PERCENT_FORMAT.format(value);
132
+ if (hasToken(tokens, CURRENCY_TOKENS)) return CURRENCY_FORMAT.format(value);
133
+ if (
134
+ INTEGER_SQL_TYPES.has(column.typeName?.toUpperCase() ?? "") ||
135
+ hasToken(tokens, WHOLE_NUMBER_TOKENS)
136
+ ) {
137
+ return WHOLE_NUMBER_FORMAT.format(value);
138
+ }
139
+ return NUMBER_FORMAT.format(value);
140
+ }