@dbx-tools/appkit-mastra 0.9.187 → 0.9.188

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/package.json CHANGED
@@ -36,23 +36,23 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@databricks/appkit": "0.81.0",
39
- "@dbx-tools/appkit": "^0.9.187",
40
- "@dbx-tools/appkit-model-gateway": "^0.9.187",
41
- "@dbx-tools/cache": "^0.9.187",
42
- "@dbx-tools/core": "^0.9.187",
43
- "@dbx-tools/databricks": "^0.9.187",
44
- "@dbx-tools/fs": "^0.9.187",
45
- "@dbx-tools/genie": "^0.9.187",
46
- "@dbx-tools/model": "^0.9.187",
47
- "@dbx-tools/model-protocol": "^0.9.187",
48
- "@dbx-tools/path": "^0.9.187",
49
- "@dbx-tools/postgres": "^0.9.187",
50
- "@dbx-tools/shared-core": "^0.9.187",
51
- "@dbx-tools/shared-fs": "^0.9.187",
52
- "@dbx-tools/shared-genie": "^0.9.187",
53
- "@dbx-tools/shared-mastra": "^0.9.187",
54
- "@dbx-tools/shared-model": "^0.9.187",
55
- "@dbx-tools/shared-model-gateway": "^0.9.187",
39
+ "@dbx-tools/appkit": "^0.9.188",
40
+ "@dbx-tools/appkit-model-gateway": "^0.9.188",
41
+ "@dbx-tools/cache": "^0.9.188",
42
+ "@dbx-tools/core": "^0.9.188",
43
+ "@dbx-tools/databricks": "^0.9.188",
44
+ "@dbx-tools/fs": "^0.9.188",
45
+ "@dbx-tools/genie": "^0.9.188",
46
+ "@dbx-tools/model": "^0.9.188",
47
+ "@dbx-tools/model-protocol": "^0.9.188",
48
+ "@dbx-tools/path": "^0.9.188",
49
+ "@dbx-tools/postgres": "^0.9.188",
50
+ "@dbx-tools/shared-core": "^0.9.188",
51
+ "@dbx-tools/shared-fs": "^0.9.188",
52
+ "@dbx-tools/shared-genie": "^0.9.188",
53
+ "@dbx-tools/shared-mastra": "^0.9.188",
54
+ "@dbx-tools/shared-model": "^0.9.188",
55
+ "@dbx-tools/shared-model-gateway": "^0.9.188",
56
56
  "@mastra/ai-sdk": "1.10.5",
57
57
  "@mastra/core": "1.71.0",
58
58
  "@mastra/express": "1.5.15",
@@ -90,7 +90,7 @@
90
90
  "./package.json": "./package.json"
91
91
  }
92
92
  },
93
- "version": "0.9.187",
93
+ "version": "0.9.188",
94
94
  "types": "./lib/index.d.ts",
95
95
  "dbxToolsConfig": {
96
96
  "tags": [
package/src/config.ts CHANGED
@@ -17,7 +17,11 @@
17
17
  import { getExecutionContext, type BasePluginConfig, type ConfigSchema } from "@databricks/appkit";
18
18
  import { type ExecutionContextLike, type IdentityMode, IDENTITY_MODES } from "@dbx-tools/appkit";
19
19
  import type { BrandContext } from "@dbx-tools/shared-core";
20
- import type { FeedbackModeOption } from "@dbx-tools/shared-mastra";
20
+ import {
21
+ type FeedbackModeOption,
22
+ type GenieVisualizationMode,
23
+ GenieVisualizationModeSchema,
24
+ } from "@dbx-tools/shared-mastra";
21
25
  import type { AgentConfig } from "@mastra/core/agent";
22
26
  import type { RequestContext } from "@mastra/core/request-context";
23
27
  import { MASTRA_RESOURCE_ID_KEY, MASTRA_THREAD_ID_KEY } from "@mastra/core/request-context";
@@ -484,6 +488,13 @@ export interface MastraPluginConfig extends BasePluginConfig {
484
488
  * this option.
485
489
  */
486
490
  genieAgentMode?: boolean;
491
+ /**
492
+ * Direct Genie charts use AppKit inference by default. Set `"image"` to
493
+ * display Genie's original PNG in the Chart tab and keep the query's Table
494
+ * tab. Uses the same Agent Mode conversation and OBO identity; no chart
495
+ * planner, MCP, or image transformation is involved.
496
+ */
497
+ genieVisualization?: GenieVisualizationMode;
487
498
  /**
488
499
  * TTL for the in-memory Genie space metadata cache, in
489
500
  * milliseconds. Defaults to 5 minutes. The Genie agent calls
@@ -804,6 +815,12 @@ export const MASTRA_CONFIG_SCHEMA: ConfigSchema = {
804
815
  description:
805
816
  "Use the streaming Genie Agent Mode API for agent-backed ask_genie. Defaults to true; false forces legacy polling. Feature-disabled or preview-toggle responses fall back automatically before streaming. Direct Genie chat always requires Agent Mode.",
806
817
  },
818
+ genieVisualization: {
819
+ type: "string",
820
+ enum: [...GenieVisualizationModeSchema.options],
821
+ description:
822
+ "Direct Genie chart renderer. Defaults to appkit; image displays Genie's original PNG with the backing query in the Table tab, using the same Agent Mode conversation and OBO identity.",
823
+ },
807
824
  genieSpaceCacheTtlMs: {
808
825
  type: "number",
809
826
  description: "TTL in ms for the Genie space metadata cache. Defaults to 5 minutes.",
package/src/genie-chat.ts CHANGED
@@ -26,6 +26,10 @@ import {
26
26
  type GenieWriterEvent,
27
27
  type GenieConversationPartData,
28
28
  GENIE_CONVERSATION_PART_TYPE,
29
+ type GenieVisualizationMode,
30
+ GenieVisualizationEmbedSchema,
31
+ encodeGenieVisualizationEmbed,
32
+ GENIE_VISUALIZATION_MARKER,
29
33
  } from "@dbx-tools/shared-mastra";
30
34
  import type { MastraDBMessage } from "@mastra/core/agent";
31
35
  import type { MastraMemory } from "@mastra/core/memory";
@@ -57,6 +61,8 @@ export interface GenieChatSpace {
57
61
  alias: string;
58
62
  /** Genie `space_id`. */
59
63
  spaceId: string;
64
+ /** Chart renderer for direct turns and reloaded history. Defaults to AppKit. */
65
+ visualization?: GenieVisualizationMode;
60
66
  }
61
67
 
62
68
  /**
@@ -68,11 +74,11 @@ export interface GenieChatSpace {
68
74
  * Agent Mode's Markdown copy of a query result is dropped because either embed
69
75
  * renders the same rows.
70
76
  */
71
- export function genieAnswerText(message: GenieMessage): string {
77
+ export function genieAnswerText(message: GenieMessage, space?: GenieChatSpace): string {
72
78
  const attachments = message.attachments ?? [];
73
79
  const statementsByQuery = new Map<string, string>();
74
80
  const queriesByVisualization = new Map<string, string>();
75
- const visualizedQueries = new Set<string>();
81
+ const visualizationMarkers = new Map<string, string>();
76
82
  for (const attachment of attachments) {
77
83
  const statementId = attachment.query?.statement_id;
78
84
  if (statementId && attachment.attachment_id) {
@@ -80,7 +86,27 @@ export function genieAnswerText(message: GenieMessage): string {
80
86
  }
81
87
  if (attachment.attachment_id && attachment.viz?.query_attachment_id) {
82
88
  queriesByVisualization.set(attachment.attachment_id, attachment.viz.query_attachment_id);
83
- visualizedQueries.add(attachment.viz.query_attachment_id);
89
+ }
90
+ }
91
+ for (const [visualizationId, queryId] of queriesByVisualization) {
92
+ const statementId = statementsByQuery.get(queryId);
93
+ if (!statementId) continue;
94
+ if (space?.visualization !== "image") {
95
+ visualizationMarkers.set(visualizationId, formatMarker("visualization", statementId));
96
+ continue;
97
+ }
98
+ const reference = GenieVisualizationEmbedSchema.safeParse({
99
+ alias: space.alias,
100
+ conversation_id: message.conversation_id,
101
+ message_id: message.message_id || message.id,
102
+ attachment_id: visualizationId,
103
+ statementId,
104
+ });
105
+ if (reference.success) {
106
+ visualizationMarkers.set(
107
+ visualizationId,
108
+ formatMarker(GENIE_VISUALIZATION_MARKER, encodeGenieVisualizationEmbed(reference.data)),
109
+ );
84
110
  }
85
111
  }
86
112
 
@@ -93,8 +119,9 @@ export function genieAnswerText(message: GenieMessage): string {
93
119
  if (visualizationId) {
94
120
  const queryId = queriesByVisualization.get(visualizationId);
95
121
  const statementId = queryId ? statementsByQuery.get(queryId) : undefined;
96
- if (statementId) {
97
- sections.push(formatMarker("visualization", statementId));
122
+ const marker = visualizationMarkers.get(visualizationId);
123
+ if (statementId && marker) {
124
+ sections.push(marker);
98
125
  inlineStatements.add(statementId);
99
126
  }
100
127
  continue;
@@ -108,10 +135,12 @@ export function genieAnswerText(message: GenieMessage): string {
108
135
  if (!statementId || inlineStatements.has(statementId)) continue;
109
136
  const description = attachment.query?.description?.trim();
110
137
  if (description) sections.push(description);
138
+ const visualizationId = [...queriesByVisualization].find(
139
+ ([, queryId]) => queryId === attachment.attachment_id,
140
+ )?.[0];
111
141
  sections.push(
112
- attachment.attachment_id && visualizedQueries.has(attachment.attachment_id)
113
- ? formatMarker("visualization", statementId)
114
- : formatMarker("data", statementId),
142
+ (visualizationId ? visualizationMarkers.get(visualizationId) : undefined) ??
143
+ formatMarker("data", statementId),
115
144
  );
116
145
  }
117
146
  if (sections.length === 0 && message.error?.error) sections.push(message.error.error);
@@ -303,7 +332,7 @@ export function genieMessageToUiMessages(
303
332
  input,
304
333
  output: { message },
305
334
  };
306
- const answer = genieAnswerText(message);
335
+ const answer = genieAnswerText(message, space);
307
336
  const assistantParts = [
308
337
  toolPart,
309
338
  ...progress,
@@ -510,7 +539,7 @@ export function genieChatStream(options: {
510
539
  : { type: "tool-output-available", toolCallId, output: { message: finalMessage } },
511
540
  );
512
541
  writer.write({ type: "finish-step" });
513
- const answer = genieAnswerText(finalMessage);
542
+ const answer = genieAnswerText(finalMessage, space);
514
543
  if (answer) {
515
544
  const textId = id();
516
545
  writer.write({ type: "start-step" });
package/src/plugin.ts CHANGED
@@ -69,7 +69,7 @@ import {
69
69
  requestUserId,
70
70
  useServicePrincipal,
71
71
  } from "@dbx-tools/appkit";
72
- import { sendGenieMessageFeedback } from "@dbx-tools/genie";
72
+ import { downloadGenieVisualization, sendGenieMessageFeedback } from "@dbx-tools/genie";
73
73
  import { modelCatalog } from "@dbx-tools/model";
74
74
  import {
75
75
  combineAbortSignals,
@@ -91,6 +91,7 @@ import {
91
91
  MASTRA_ROUTES,
92
92
  genieRoutePath,
93
93
  GenieChatRequestSchema,
94
+ GenieVisualizationModeSchema,
94
95
  } from "@dbx-tools/shared-mastra";
95
96
  import { type ServingEndpointSummary, toModelDisplayName } from "@dbx-tools/shared-model";
96
97
  import { workflowRoute } from "@mastra/ai-sdk";
@@ -806,10 +807,22 @@ export class MastraPlugin extends Plugin<MastraPluginConfig> {
806
807
  const spaceFor = (req: express.Request, res: express.Response): GenieChatSpace | undefined => {
807
808
  const alias = firstNonEmpty(req.params.alias) ?? "";
808
809
  const configured = resolveGenieSpaces(this.config, this.context)[alias];
809
- if (configured) return { alias, spaceId: configured.spaceId };
810
+ if (configured) {
811
+ return {
812
+ alias,
813
+ spaceId: configured.spaceId,
814
+ visualization: this.config.genieVisualization,
815
+ };
816
+ }
810
817
  res.status(404).json({ error: `Unknown Genie space alias "${alias}"` });
811
818
  return undefined;
812
819
  };
820
+ const requestVisualization = (req: express.Request): GenieChatSpace["visualization"] => {
821
+ const raw = typeof req.query.visualization === "string" ? req.query.visualization : undefined;
822
+ if (!raw) return undefined;
823
+ const parsed = GenieVisualizationModeSchema.safeParse(raw);
824
+ return parsed.success ? parsed.data : undefined;
825
+ };
813
826
  /** Bridge the connection `close` event onto an abort signal. */
814
827
  const closeSignal = (res: express.Response): AbortSignal => {
815
828
  const controller = new AbortController();
@@ -831,7 +844,16 @@ export class MastraPlugin extends Plugin<MastraPluginConfig> {
831
844
  .json({ error: "question is required", fields: invalidFields(parsed.error) });
832
845
  return;
833
846
  }
834
- await this.asUser(req).streamGenieChat(res, space, parsed.data, closeSignal(res));
847
+ const request = parsed.data;
848
+ await this.asUser(req).streamGenieChat(
849
+ res,
850
+ {
851
+ ...space,
852
+ visualization: request.visualization ?? space.visualization,
853
+ },
854
+ request,
855
+ closeSignal(res),
856
+ );
835
857
  },
836
858
  });
837
859
  this.route(router, {
@@ -862,7 +884,10 @@ export class MastraPlugin extends Plugin<MastraPluginConfig> {
862
884
  const result = await this.asUser(req).genieConversationRead((client) =>
863
885
  listGenieThreadMessages({
864
886
  client,
865
- space,
887
+ space: {
888
+ ...space,
889
+ visualization: requestVisualization(req) ?? space.visualization,
890
+ },
866
891
  conversationId: threadId,
867
892
  }),
868
893
  );
@@ -873,6 +898,48 @@ export class MastraPlugin extends Plugin<MastraPluginConfig> {
873
898
  res.json({ messages: result.data });
874
899
  },
875
900
  });
901
+ this.route(router, {
902
+ name: "genieVisualization",
903
+ method: "get",
904
+ path: path(
905
+ threads,
906
+ ":threadId",
907
+ messages,
908
+ ":messageId",
909
+ MASTRA_ROUTES.attachments,
910
+ ":attachmentId",
911
+ MASTRA_ROUTES.visualization,
912
+ ),
913
+ handler: async (req, res) => {
914
+ const space = spaceFor(req, res);
915
+ if (!space) return;
916
+ const signal = closeSignal(res);
917
+ const result = await this.asUser(req).genieConversationRead((client) =>
918
+ downloadGenieVisualization(
919
+ {
920
+ space_id: space.spaceId,
921
+ conversation_id: firstNonEmpty(req.params.threadId) ?? "",
922
+ message_id: firstNonEmpty(req.params.messageId) ?? "",
923
+ attachment_id: firstNonEmpty(req.params.attachmentId) ?? "",
924
+ },
925
+ { workspaceClient: client, context: signal },
926
+ ),
927
+ );
928
+ if (signal.aborted) return;
929
+ res.setHeader("Cache-Control", "private, no-store");
930
+ res.setHeader("X-Content-Type-Options", "nosniff");
931
+ if (!result.ok) {
932
+ this.sendFailure(
933
+ res,
934
+ result,
935
+ "genie-visualization",
936
+ "Could not download the Genie visualization",
937
+ );
938
+ return;
939
+ }
940
+ res.type("image/png").send(Buffer.from(result.data));
941
+ },
942
+ });
876
943
  this.route(router, {
877
944
  name: "genieThreadDelete",
878
945
  method: "delete",