@magemetrics/core 0.13.0 → 0.14.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.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { sha256 } from '@noble/hashes/sha2.js';
2
- import z9, { z } from 'zod';
2
+ import z10, { z } from 'zod';
3
3
  import { GoTrueClient } from '@supabase/auth-js';
4
4
  import createApiClient2 from 'openapi-fetch';
5
+ import { DefaultChatTransport } from 'ai';
5
6
  import dayjs from 'dayjs';
6
7
  import customParseFormat from 'dayjs/plugin/customParseFormat.js';
7
8
  import relativeTime from 'dayjs/plugin/relativeTime.js';
8
9
  import timezone from 'dayjs/plugin/timezone.js';
9
10
  import utc from 'dayjs/plugin/utc.js';
10
- import { DefaultChatTransport } from 'ai';
11
11
 
12
12
  // ../shared/dist/src/api/client/middleware.js
13
13
  var HEADER_CLIENT_VERSION = "X-Client-Version";
@@ -58,7 +58,7 @@ var addApiKeyHeader = (apiKey) => {
58
58
 
59
59
  // package.json
60
60
  var package_default = {
61
- version: "0.13.0"};
61
+ version: "0.14.0"};
62
62
 
63
63
  // src/core/MageMetricsEventEmitter.ts
64
64
  var MageMetricsEventEmitter = class {
@@ -139,8 +139,9 @@ var DirectAuthProvider = class {
139
139
  removeEventListener(type, listener) {
140
140
  this.events.removeEventListener(type, listener);
141
141
  }
142
+ destroy() {
143
+ }
142
144
  setState(state) {
143
- this.state = state;
144
145
  this.state = state;
145
146
  this.events.dispatch("authStateChange", state);
146
147
  }
@@ -152,7 +153,7 @@ var hashString = (value) => {
152
153
  return Array.from(hash).map((b) => b.toString(16).padStart(2, "0")).join("");
153
154
  };
154
155
 
155
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@8.5.0_zod@4.3.6/node_modules/@asteasolutions/zod-to-openapi/dist/index.mjs
156
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@8.5.0_zod@4.4.3/node_modules/@asteasolutions/zod-to-openapi/dist/index.mjs
156
157
  function __rest(s, e) {
157
158
  var t = {};
158
159
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -482,7 +483,7 @@ function getOpenApiConfiguration(refOrOpenapi, metadataOrOptions, options) {
482
483
  };
483
484
  }
484
485
 
485
- // ../../node_modules/.pnpm/hono@4.12.15/node_modules/hono/dist/router/reg-exp-router/node.js
486
+ // ../../node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/router/reg-exp-router/node.js
486
487
  new Set(".\\+*[^]$()");
487
488
  var createRoute = (routeConfig) => {
488
489
  const route = {
@@ -627,26 +628,26 @@ var ExchangeExternalToken = createRoute({
627
628
  }
628
629
  }
629
630
  });
630
- var MintEmbedTokenInputSchema = z.object({
631
+ var CreateEmbedTokenInputSchema = z.object({
631
632
  uid: ExternalUserIdSchema,
632
633
  attributes: z.record(z.string(), z.unknown()),
633
634
  applicationName: z.string().trim().min(1).optional()
634
635
  });
635
- var MintEmbedTokenOutputSchema = z.object({
636
+ var CreateEmbedTokenOutputSchema = z.object({
636
637
  token: z.string(),
637
638
  expires_at: z.iso.datetime()
638
639
  });
639
640
  createRoute({
640
641
  method: "post",
641
- path: "/api/v1/auth/mintEmbedToken",
642
- operationId: "mintEmbedToken",
642
+ path: "/api/v1/auth/embed-tokens",
643
+ operationId: "createEmbedToken",
643
644
  tags: ["internal"],
644
645
  request: {
645
646
  body: {
646
647
  required: true,
647
648
  content: {
648
649
  "application/json": {
649
- schema: MintEmbedTokenInputSchema
650
+ schema: CreateEmbedTokenInputSchema
650
651
  }
651
652
  }
652
653
  }
@@ -655,10 +656,10 @@ createRoute({
655
656
  200: {
656
657
  content: {
657
658
  "application/json": {
658
- schema: MintEmbedTokenOutputSchema
659
+ schema: CreateEmbedTokenOutputSchema
659
660
  }
660
661
  },
661
- description: "Mint a short-lived Magemetrics embed assertion"
662
+ description: "Create a short-lived Magemetrics embed assertion token"
662
663
  },
663
664
  400: {
664
665
  content: {
@@ -690,7 +691,77 @@ createRoute({
690
691
  schema: z.object({ error: z.string() })
691
692
  }
692
693
  },
693
- description: "Unable to mint an embed token"
694
+ description: "Unable to create an embed token"
695
+ }
696
+ }
697
+ });
698
+ var CreateMcpUserTokenInputSchema = z.object({
699
+ uid: ExternalUserIdSchema,
700
+ attributes: z.record(z.string(), z.unknown()),
701
+ applicationName: z.string().trim().min(1).optional(),
702
+ expiresInSeconds: z.number().int().positive().max(86400).optional()
703
+ });
704
+ var CreateMcpUserTokenOutputSchema = z.object({
705
+ token: z.string(),
706
+ expires_at: z.iso.datetime()
707
+ });
708
+ createRoute({
709
+ method: "post",
710
+ path: "/api/v1/auth/mcp-user-tokens",
711
+ operationId: "createMcpUserToken",
712
+ tags: ["internal"],
713
+ request: {
714
+ body: {
715
+ required: true,
716
+ content: {
717
+ "application/json": {
718
+ schema: CreateMcpUserTokenInputSchema
719
+ }
720
+ }
721
+ }
722
+ },
723
+ responses: {
724
+ 200: {
725
+ content: {
726
+ "application/json": {
727
+ schema: CreateMcpUserTokenOutputSchema
728
+ }
729
+ },
730
+ description: "Create a short-lived MCP user token"
731
+ },
732
+ 400: {
733
+ content: {
734
+ "application/json": {
735
+ schema: z.object({ error: z.string() })
736
+ }
737
+ },
738
+ description: "Invalid input"
739
+ },
740
+ 401: {
741
+ content: {
742
+ "application/json": {
743
+ schema: z.object({ error: z.string() })
744
+ }
745
+ },
746
+ description: "Authentication required"
747
+ },
748
+ 403: {
749
+ content: {
750
+ "application/json": {
751
+ schema: z.object({ error: z.string() })
752
+ }
753
+ },
754
+ description: "Service account required"
755
+ },
756
+ 500: {
757
+ content: {
758
+ "application/json": {
759
+ schema: z.object({
760
+ error: z.string()
761
+ })
762
+ }
763
+ },
764
+ description: "Unable to create an MCP user token"
694
765
  }
695
766
  }
696
767
  });
@@ -710,6 +781,7 @@ var ExternalAuthProvider = class {
710
781
  processedJwt = /* @__PURE__ */ Symbol("initial");
711
782
  userId = null;
712
783
  events = new MageMetricsEventEmitter();
784
+ authSubscription = null;
713
785
  constructor(config) {
714
786
  this.config = config;
715
787
  }
@@ -773,6 +845,12 @@ var ExternalAuthProvider = class {
773
845
  stopAutoRefresh() {
774
846
  return this.supabaseClient?.stopAutoRefresh();
775
847
  }
848
+ destroy() {
849
+ this.authSubscription?.unsubscribe();
850
+ this.authSubscription = null;
851
+ void this.supabaseClient?.stopAutoRefresh();
852
+ this.supabaseClient = null;
853
+ }
776
854
  async getApiInformation() {
777
855
  if (!this.noAuthApiClient || !this.authApiResponse) {
778
856
  this.noAuthApiClient = createApiClient2({
@@ -800,7 +878,9 @@ var ExternalAuthProvider = class {
800
878
  storage: this.config.storage,
801
879
  ...this.config.authOptions
802
880
  });
803
- this.supabaseClient.onAuthStateChange((event, session) => {
881
+ const {
882
+ data: { subscription }
883
+ } = this.supabaseClient.onAuthStateChange((event, session) => {
804
884
  console.debug("Supabase auth state change:", event, !!session);
805
885
  if (event === "SIGNED_IN" && session?.user) {
806
886
  if (this.userId !== session.user.id && this.userId !== null) {
@@ -817,6 +897,7 @@ var ExternalAuthProvider = class {
817
897
  this.setState("initializing");
818
898
  }
819
899
  });
900
+ this.authSubscription = subscription;
820
901
  }
821
902
  }
822
903
  async handleAuthentication() {
@@ -913,6 +994,39 @@ var ExternalAuthProvider = class {
913
994
  }
914
995
  }
915
996
  };
997
+ var isToolResultMessage = (message) => {
998
+ if (message.role !== "assistant") {
999
+ return false;
1000
+ }
1001
+ return message.parts.some(
1002
+ (part) => part.type.startsWith("tool-") && "state" in part && part.state === "output-available"
1003
+ );
1004
+ };
1005
+ var MageMetricsChatTransport = class extends DefaultChatTransport {
1006
+ constructor(apiUrl, flowId, options) {
1007
+ super({
1008
+ ...options,
1009
+ api: `${apiUrl}/api/v1/chat/${flowId}`,
1010
+ prepareSendMessagesRequest({ messages, id: chatId, body }) {
1011
+ const lastMessage = messages.at(-1);
1012
+ if (lastMessage && isToolResultMessage(lastMessage)) {
1013
+ lastMessage.metadata = {
1014
+ ...typeof lastMessage.metadata === "object" ? lastMessage.metadata : void 0,
1015
+ isFrontendToolSubmission: true
1016
+ };
1017
+ }
1018
+ const chatHints = body?.chatHints;
1019
+ return {
1020
+ body: {
1021
+ message: lastMessage,
1022
+ id: chatId,
1023
+ ...chatHints ? { chatHints } : {}
1024
+ }
1025
+ };
1026
+ }
1027
+ });
1028
+ }
1029
+ };
916
1030
  var SupabaseHeaderSchema = z.object({
917
1031
  [HEADER_SP_TOKEN]: z.string().optional()
918
1032
  });
@@ -975,6 +1089,201 @@ var BusinessExplanationSchema = z.object({
975
1089
  explanation: z.string()
976
1090
  }))
977
1091
  });
1092
+ dayjs.extend(relativeTime);
1093
+ dayjs.extend(customParseFormat);
1094
+ dayjs.extend(utc);
1095
+ dayjs.extend(timezone);
1096
+ var daysjs_default = dayjs;
1097
+
1098
+ // ../shared/dist/src/data/FormattedData.js
1099
+ var numberFormatCache = /* @__PURE__ */ new Map();
1100
+ var getNumberFormatter = (minimumFractionDigits, maximumFractionDigits, useGrouping) => {
1101
+ const key = `${minimumFractionDigits}:${maximumFractionDigits}:${useGrouping}`;
1102
+ let formatter = numberFormatCache.get(key);
1103
+ if (!formatter) {
1104
+ formatter = new Intl.NumberFormat(void 0, {
1105
+ minimumFractionDigits,
1106
+ maximumFractionDigits,
1107
+ useGrouping
1108
+ });
1109
+ numberFormatCache.set(key, formatter);
1110
+ }
1111
+ return formatter;
1112
+ };
1113
+ var formatWithAutoPrecision = (value, options = {}) => {
1114
+ const { minPrecision = 0, maxPrecision = 6, trimZeros = true, useGrouping = true } = options;
1115
+ if (typeof value !== "number" || isNaN(value)) {
1116
+ return String(value);
1117
+ }
1118
+ if (value === 0) {
1119
+ return "0";
1120
+ }
1121
+ const absValue = Math.abs(value);
1122
+ let maximumFractionDigits;
1123
+ if (absValue >= 1e3) {
1124
+ maximumFractionDigits = 0;
1125
+ } else if (absValue >= 100) {
1126
+ maximumFractionDigits = 1;
1127
+ } else if (absValue >= 10) {
1128
+ maximumFractionDigits = 2;
1129
+ } else if (absValue >= 1) {
1130
+ maximumFractionDigits = 3;
1131
+ } else if (absValue >= 0.1) {
1132
+ maximumFractionDigits = 4;
1133
+ } else if (absValue >= 0.01) {
1134
+ maximumFractionDigits = 5;
1135
+ } else {
1136
+ maximumFractionDigits = maxPrecision;
1137
+ if (absValue > 0) {
1138
+ const exponent = Math.floor(Math.log10(absValue));
1139
+ if (exponent < 0) {
1140
+ maximumFractionDigits = Math.min(Math.abs(exponent) + 2, maxPrecision);
1141
+ }
1142
+ }
1143
+ }
1144
+ maximumFractionDigits = Math.max(maximumFractionDigits, minPrecision);
1145
+ const formatter = getNumberFormatter(trimZeros ? 0 : maximumFractionDigits, maximumFractionDigits, useGrouping);
1146
+ return formatter.format(value);
1147
+ };
1148
+ var MIN_VALID_YEAR = 1900;
1149
+ var MAX_VALID_YEAR = 2200;
1150
+ var zonedatetime = (format, zone) => ({ format, type: "zonedatetime", zone });
1151
+ var datetime = (format) => ({ format, type: "datetime" });
1152
+ var date = (format) => ({ format, type: "date" });
1153
+ var DATE_FORMATS = [
1154
+ // ISO 8601 formats
1155
+ zonedatetime("YYYY-MM-DDTHH:mm:ss.SSSZ", "UTC"),
1156
+ zonedatetime("YYYY-MM-DDTHH:mm:ssZ", "UTC"),
1157
+ zonedatetime("YYYY-MM-DDTHH:mmZ", "UTC"),
1158
+ datetime("YYYY-MM-DDTHH:mm:ss"),
1159
+ datetime("YYYY-MM-DDTHH:mm"),
1160
+ date("YYYY-MM-DDT"),
1161
+ // Standard date formats
1162
+ date("YYYY-MM-DD"),
1163
+ date("YYYY/MM/DD"),
1164
+ date("DD-MM-YYYY"),
1165
+ date("DD/MM/YYYY"),
1166
+ date("MM-DD-YYYY"),
1167
+ date("MM/DD/YYYY"),
1168
+ // Date time formats
1169
+ datetime("YYYY-MM-DD HH:mm:ss"),
1170
+ datetime("YYYY-MM-DD HH:mm"),
1171
+ datetime("YYYY/MM/DD HH:mm:ss"),
1172
+ datetime("YYYY/MM/DD HH:mm"),
1173
+ datetime("DD-MM-YYYY HH:mm:ss"),
1174
+ datetime("DD-MM-YYYY HH:mm"),
1175
+ datetime("DD/MM/YYYY HH:mm:ss"),
1176
+ datetime("DD/MM/YYYY HH:mm"),
1177
+ datetime("MM-DD-YYYY HH:mm:ss"),
1178
+ datetime("MM-DD-YYYY HH:mm"),
1179
+ datetime("MM/DD/YYYY HH:mm:ss"),
1180
+ datetime("MM/DD/YYYY HH:mm")
1181
+ ];
1182
+ var isDateString = (value) => {
1183
+ if (typeof value !== "string")
1184
+ return { isValid: false };
1185
+ const stripped = value.replace(/[-/.:\s]/g, "");
1186
+ if (/^\d+$/.test(stripped)) {
1187
+ if (stripped.length < 6)
1188
+ return { isValid: false };
1189
+ if (value.length === stripped.length)
1190
+ return { isValid: false };
1191
+ }
1192
+ if (stripped.length > "YYYY-MM-DDTHH:mm:ss.SSS+00:00".length) {
1193
+ return { isValid: false };
1194
+ }
1195
+ for (const format of DATE_FORMATS) {
1196
+ let date2;
1197
+ try {
1198
+ if (format.type === "zonedatetime") {
1199
+ date2 = daysjs_default.tz(value, format.format, format.zone);
1200
+ } else {
1201
+ date2 = daysjs_default(value, format.format, true);
1202
+ }
1203
+ } catch {
1204
+ continue;
1205
+ }
1206
+ if (date2.isValid()) {
1207
+ const year = date2.year();
1208
+ if (year < MIN_VALID_YEAR || year > MAX_VALID_YEAR)
1209
+ continue;
1210
+ const isDateTime = format.type === "zonedatetime" || format.type == "datetime";
1211
+ return {
1212
+ isValid: true,
1213
+ parsedDate: date2,
1214
+ isDateTime
1215
+ };
1216
+ }
1217
+ }
1218
+ return { isValid: false };
1219
+ };
1220
+ var formatDataValue = (value, { replaceNullValue = true, formatHint } = {}) => {
1221
+ if (value === null || value === void 0) {
1222
+ return {
1223
+ display: replaceNullValue ? "empty" : null,
1224
+ sortValue: null
1225
+ };
1226
+ }
1227
+ let processedValue = value;
1228
+ if (typeof processedValue === "string") {
1229
+ try {
1230
+ const parsed = JSON.parse(processedValue);
1231
+ processedValue = parsed;
1232
+ } catch {
1233
+ }
1234
+ }
1235
+ if (processedValue && typeof processedValue === "object" && Object.keys(processedValue).length === 1 && "value" in processedValue) {
1236
+ const extractedValue = processedValue.value;
1237
+ const dateResult2 = isDateString(extractedValue);
1238
+ if (dateResult2.isValid) {
1239
+ return {
1240
+ display: dateResult2.isDateTime ? dateResult2.parsedDate.format("YYYY-MM-DD HH:mm:ss") : dateResult2.parsedDate.format("YYYY-MM-DD"),
1241
+ sortValue: dateResult2.parsedDate.valueOf()
1242
+ };
1243
+ }
1244
+ return {
1245
+ display: String(extractedValue),
1246
+ sortValue: extractedValue
1247
+ };
1248
+ }
1249
+ const dateResult = isDateString(processedValue);
1250
+ if (dateResult.isValid) {
1251
+ return {
1252
+ display: dateResult.isDateTime ? dateResult.parsedDate.format("YYYY-MM-DD HH:mm:ss") : dateResult.parsedDate.format("YYYY-MM-DD"),
1253
+ sortValue: dateResult.parsedDate.valueOf()
1254
+ };
1255
+ }
1256
+ if (typeof processedValue === "object") {
1257
+ const stringified = JSON.stringify(processedValue, null, 2);
1258
+ return {
1259
+ display: stringified,
1260
+ sortValue: stringified
1261
+ };
1262
+ }
1263
+ if (typeof processedValue === "boolean") {
1264
+ return {
1265
+ display: String(processedValue),
1266
+ sortValue: processedValue ? 1 : 0
1267
+ };
1268
+ }
1269
+ if (typeof processedValue === "number") {
1270
+ if (formatHint?.isLikelyYear !== void 0) {
1271
+ return {
1272
+ display: formatHint.isLikelyYear ? String(processedValue) : formatWithAutoPrecision(processedValue),
1273
+ sortValue: processedValue
1274
+ };
1275
+ }
1276
+ return {
1277
+ display: processedValue >= MIN_VALID_YEAR && processedValue <= MAX_VALID_YEAR && Number.isInteger(processedValue) ? String(processedValue) : formatWithAutoPrecision(processedValue),
1278
+ sortValue: processedValue
1279
+ };
1280
+ }
1281
+ return {
1282
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
1283
+ display: String(processedValue),
1284
+ sortValue: processedValue
1285
+ };
1286
+ };
978
1287
 
979
1288
  // ../shared/dist/src/schemas/flows.js
980
1289
  var FlowStepSchema = z.object({
@@ -1001,10 +1310,16 @@ z.object({
1001
1310
  database: z.string()
1002
1311
  });
1003
1312
  var FrontendFlowSchema = DatabaseFlowSchema.omit({
1004
- flow_steps: true
1313
+ flow_steps: true,
1314
+ context_tokens: true,
1315
+ acc_input_tokens: true,
1316
+ acc_output_tokens: true
1005
1317
  });
1006
1318
  var FrontendRecentFlowsSchema = DatabaseFlowSchema.omit({
1007
- flow_steps: true
1319
+ flow_steps: true,
1320
+ context_tokens: true,
1321
+ acc_input_tokens: true,
1322
+ acc_output_tokens: true
1008
1323
  });
1009
1324
  var ReportColumnSchema = z.looseObject({
1010
1325
  position: z.number().nonnegative().optional(),
@@ -1087,12 +1402,17 @@ z.object({
1087
1402
  unit: z.string().nullish(),
1088
1403
  canonical_data_type: CanonicalDataTypeSchema.nullish()
1089
1404
  });
1405
+ var ColumnFormatHintSchema = z.object({
1406
+ isNumeric: z.boolean().optional(),
1407
+ isLikelyYear: z.boolean().optional()
1408
+ });
1090
1409
  var FrontendReportColumnsSchema = z.object({
1091
1410
  ...ReportColumnsSchema.element.shape,
1092
1411
  dataType: z.string(),
1093
1412
  renderType: z.string().optional(),
1094
1413
  unit: z.string().optional(),
1095
- canonicalDataType: CanonicalDataTypeSchema.optional()
1414
+ canonicalDataType: CanonicalDataTypeSchema.optional(),
1415
+ formatHint: ColumnFormatHintSchema.optional()
1096
1416
  }).array().openapi("ReportColumns");
1097
1417
  z.object({
1098
1418
  goal: z.string(),
@@ -1285,9 +1605,33 @@ var columnsQueryParams = z.string().transform((str) => {
1285
1605
  },
1286
1606
  type: "string"
1287
1607
  });
1608
+
1609
+ // ../shared/dist/src/schemas/chat/fileUpload.js
1610
+ var CHAT_MAX_FILE_SIZE = 10 * 1024 * 1024;
1611
+ var CHAT_MAX_TOTAL_FILE_BYTES_FOR_LLM = 15 * 1024 * 1024;
1612
+ var CHAT_MAX_COMBINED_FILE_SIZE = CHAT_MAX_TOTAL_FILE_BYTES_FOR_LLM;
1288
1613
  var CHAT_MAX_FILE_COUNT = 10;
1614
+ var UPLOADED_FILE_REF_PREFIX = "uploaded-file:";
1289
1615
  var CHAT_ALLOWED_FILE_MEDIA_TYPES = /* @__PURE__ */ new Set(["application/pdf"]);
1290
- [...CHAT_ALLOWED_FILE_MEDIA_TYPES].join(",");
1616
+ var CHAT_FILE_ACCEPT = [...CHAT_ALLOWED_FILE_MEDIA_TYPES].join(",");
1617
+ var getUploadedFileIdFromUrl = (url) => {
1618
+ if (!url.startsWith(UPLOADED_FILE_REF_PREFIX)) {
1619
+ return null;
1620
+ }
1621
+ const uploadedFileId = url.slice(UPLOADED_FILE_REF_PREFIX.length);
1622
+ return uploadedFileId.length > 0 ? uploadedFileId : null;
1623
+ };
1624
+ var toUploadedFileRefUrl = (uploadedFileId) => `${UPLOADED_FILE_REF_PREFIX}${uploadedFileId}`;
1625
+ var validateUploadedFiles = (uploadedFiles) => {
1626
+ if (uploadedFiles.length > CHAT_MAX_FILE_COUNT) {
1627
+ throw new Error(`Too many files: ${uploadedFiles.length}. Maximum is ${CHAT_MAX_FILE_COUNT}.`);
1628
+ }
1629
+ const combinedSize = uploadedFiles.reduce((sum, uploadedFile) => sum + uploadedFile.size_bytes, 0);
1630
+ if (combinedSize > CHAT_MAX_COMBINED_FILE_SIZE) {
1631
+ const limitMB = Math.round(CHAT_MAX_COMBINED_FILE_SIZE / (1024 * 1024));
1632
+ throw new Error(`Combined file size exceeds maximum of ${limitMB} MB.`);
1633
+ }
1634
+ };
1291
1635
  var UploadedFileIdSchema = z.uuid();
1292
1636
  var UploadedFileSchema = z.object({
1293
1637
  uploadedFileId: UploadedFileIdSchema,
@@ -1546,6 +1890,15 @@ var ExportReportData = createRoute({
1546
1890
  }
1547
1891
  }
1548
1892
  });
1893
+ var DataServiceErrorCodeSchema = z.enum([
1894
+ "QUERY_LIMIT_EXCEEDED",
1895
+ "QUERY_TIMEOUT",
1896
+ "QUERY_EXECUTION_FAILED"
1897
+ ]);
1898
+ var DataServiceErrorResponseSchema = z.object({
1899
+ error: z.string(),
1900
+ code: DataServiceErrorCodeSchema
1901
+ });
1549
1902
  var GetReportData = createRoute({
1550
1903
  method: "get",
1551
1904
  path: "/api/v1/data-reports/{report_id}/data",
@@ -1582,10 +1935,8 @@ var GetReportData = createRoute({
1582
1935
  500: {
1583
1936
  description: "Something wrong happened",
1584
1937
  content: {
1585
- "application/json": {
1586
- schema: z.object({
1587
- error: z.string()
1588
- })
1938
+ "application/json": {
1939
+ schema: DataServiceErrorResponseSchema
1589
1940
  }
1590
1941
  }
1591
1942
  }
@@ -1623,9 +1974,7 @@ var GetReportRowCount = createRoute({
1623
1974
  description: "Something wrong happened",
1624
1975
  content: {
1625
1976
  "application/json": {
1626
- schema: z.object({
1627
- error: z.string()
1628
- })
1977
+ schema: DataServiceErrorResponseSchema
1629
1978
  }
1630
1979
  }
1631
1980
  }
@@ -1845,7 +2194,7 @@ createRoute({
1845
2194
  operationId: "getColumnLineage",
1846
2195
  tags: ["public"],
1847
2196
  request: {
1848
- headers: SupabaseHeaderSchema,
2197
+ headers: SupabaseScopedHeaderSchema,
1849
2198
  body: {
1850
2199
  required: true,
1851
2200
  content: {
@@ -2082,6 +2431,49 @@ var CreateFlow = createRoute({
2082
2431
  }
2083
2432
  }
2084
2433
  });
2434
+ var PromptStarterSchema = z.object({
2435
+ id: z.number(),
2436
+ title: z.string(),
2437
+ template: z.string(),
2438
+ is_default: z.boolean()
2439
+ }).describe("Prompt starter template").openapi("PromptStarter");
2440
+
2441
+ // ../shared/dist/src/endpoints/companion/promptStarters.routes.js
2442
+ var MAX_PROMPT_STARTERS = 3;
2443
+ var GetPromptStarters = createRoute({
2444
+ method: "get",
2445
+ path: "/api/v1/prompt-starters",
2446
+ operationId: "getPromptStarters",
2447
+ tags: ["public"],
2448
+ request: {
2449
+ headers: SupabaseHeaderSchema,
2450
+ query: z.object({
2451
+ input: z.string().optional()
2452
+ })
2453
+ },
2454
+ responses: {
2455
+ 200: {
2456
+ description: "List available prompt starters",
2457
+ content: {
2458
+ "application/json": {
2459
+ schema: z.object({
2460
+ starters: PromptStarterSchema.array().min(0).max(MAX_PROMPT_STARTERS)
2461
+ })
2462
+ }
2463
+ }
2464
+ },
2465
+ 500: {
2466
+ description: "Something wrong happened",
2467
+ content: {
2468
+ "application/json": {
2469
+ schema: z.object({
2470
+ error: z.string()
2471
+ })
2472
+ }
2473
+ }
2474
+ }
2475
+ }
2476
+ });
2085
2477
  var FrontendRecommendationsSchema = z.object({
2086
2478
  starter: z.string(),
2087
2479
  explanation: z.string(),
@@ -2158,20 +2550,20 @@ var CreateSpeechToken = createRoute({
2158
2550
  }
2159
2551
  }
2160
2552
  });
2161
- z9.discriminatedUnion("status", [
2162
- z9.object({
2163
- status: z9.literal("error"),
2164
- error: z9.string()
2553
+ z10.discriminatedUnion("status", [
2554
+ z10.object({
2555
+ status: z10.literal("error"),
2556
+ error: z10.string()
2165
2557
  }),
2166
- z9.object({
2167
- status: z9.literal("success"),
2168
- flowId: z9.string()
2558
+ z10.object({
2559
+ status: z10.literal("success"),
2560
+ flowId: z10.string()
2169
2561
  })
2170
2562
  ]);
2171
- var TriggerFlowBody = z9.object({
2172
- triggerId: z9.string(),
2173
- variables: z9.record(z9.string(), z9.string()),
2174
- applicationName: z9.string().optional()
2563
+ var TriggerFlowBody = z10.object({
2564
+ triggerId: z10.string(),
2565
+ variables: z10.record(z10.string(), z10.string()),
2566
+ applicationName: z10.string().optional()
2175
2567
  });
2176
2568
  var TriggerFlow = createRoute({
2177
2569
  method: "post",
@@ -2195,9 +2587,9 @@ var TriggerFlow = createRoute({
2195
2587
  description: "Flow id",
2196
2588
  content: {
2197
2589
  "application/json": {
2198
- schema: z9.object({
2199
- status: z9.literal("success"),
2200
- flowId: z9.string()
2590
+ schema: z10.object({
2591
+ status: z10.literal("success"),
2592
+ flowId: z10.string()
2201
2593
  })
2202
2594
  }
2203
2595
  }
@@ -2205,8 +2597,8 @@ var TriggerFlow = createRoute({
2205
2597
  400: {
2206
2598
  content: {
2207
2599
  "application/json": {
2208
- schema: z9.object({
2209
- error: z9.string()
2600
+ schema: z10.object({
2601
+ error: z10.string()
2210
2602
  })
2211
2603
  }
2212
2604
  },
@@ -2215,7 +2607,7 @@ var TriggerFlow = createRoute({
2215
2607
  404: {
2216
2608
  content: {
2217
2609
  "application/json": {
2218
- schema: z9.object({ error: z9.string() })
2610
+ schema: z10.object({ error: z10.string() })
2219
2611
  }
2220
2612
  },
2221
2613
  description: "Unable to retrieve trigger with this id"
@@ -2224,8 +2616,8 @@ var TriggerFlow = createRoute({
2224
2616
  description: "Something wrong happened",
2225
2617
  content: {
2226
2618
  "application/json": {
2227
- schema: z9.object({
2228
- error: z9.string()
2619
+ schema: z10.object({
2620
+ error: z10.string()
2229
2621
  })
2230
2622
  }
2231
2623
  }
@@ -2255,9 +2647,9 @@ createRoute({
2255
2647
  description: "Flow id",
2256
2648
  content: {
2257
2649
  "application/json": {
2258
- schema: z9.object({
2259
- status: z9.literal("success"),
2260
- flowId: z9.string()
2650
+ schema: z10.object({
2651
+ status: z10.literal("success"),
2652
+ flowId: z10.string()
2261
2653
  })
2262
2654
  }
2263
2655
  }
@@ -2265,8 +2657,8 @@ createRoute({
2265
2657
  400: {
2266
2658
  content: {
2267
2659
  "application/json": {
2268
- schema: z9.object({
2269
- error: z9.string()
2660
+ schema: z10.object({
2661
+ error: z10.string()
2270
2662
  })
2271
2663
  }
2272
2664
  },
@@ -2275,7 +2667,7 @@ createRoute({
2275
2667
  404: {
2276
2668
  content: {
2277
2669
  "application/json": {
2278
- schema: z9.object({ error: z9.string() })
2670
+ schema: z10.object({ error: z10.string() })
2279
2671
  }
2280
2672
  },
2281
2673
  description: "Unable to retrieve trigger with this id"
@@ -2284,8 +2676,8 @@ createRoute({
2284
2676
  description: "Something wrong happened",
2285
2677
  content: {
2286
2678
  "application/json": {
2287
- schema: z9.object({
2288
- error: z9.string()
2679
+ schema: z10.object({
2680
+ error: z10.string()
2289
2681
  })
2290
2682
  }
2291
2683
  }
@@ -3050,7 +3442,8 @@ z.object({
3050
3442
  // Nullable with a default so pre-migration rows (where the column is absent)
3051
3443
  // parse cleanly — undefined input becomes null output.
3052
3444
  post_processors: z.array(PostProcessorConfigSchema).nullable().default(null),
3053
- agent_version_id: z.uuid().nullable().default(null)
3445
+ agent_version_id: z.uuid().nullable().default(null),
3446
+ cached_from: z.uuid().nullable().default(null)
3054
3447
  });
3055
3448
  z.object({
3056
3449
  user_id: z.uuid(),
@@ -3068,6 +3461,7 @@ z.object({
3068
3461
  model_config: ModelConfigSchema.optional(),
3069
3462
  post_processors: z.array(PostProcessorConfigSchema).optional(),
3070
3463
  agent_version_id: z.uuid().optional(),
3464
+ cached_from: z.uuid().optional(),
3071
3465
  started_at: z.string().optional(),
3072
3466
  completed_at: z.string().optional()
3073
3467
  });
@@ -3080,229 +3474,41 @@ z.object({
3080
3474
  chat_messages: z.array(AgentChatMessageSchema).optional(),
3081
3475
  input_data: z.record(z.string(), z.unknown()).optional(),
3082
3476
  output_data: z.record(z.string(), z.unknown()).optional(),
3083
- tasks: AgentTasksStateSchema.optional(),
3084
- error_message: z.string().optional(),
3085
- model_config: ModelConfigSchema.optional(),
3086
- last_heartbeat_at: z.string().nullable().optional(),
3087
- post_processors: z.array(PostProcessorConfigSchema).optional()
3088
- });
3089
- var StartAgentRunRequestSchema = z.object({
3090
- agent_id: z.uuid(),
3091
- inputs: z.record(z.string(), z.unknown()).default({}),
3092
- execution_context: ExecutionContextInputSchema.optional()
3093
- }).openapi("StartAgentRunRequest");
3094
- var AgentRunResponseSchema = z.object({
3095
- id: z.uuid(),
3096
- agent_id: z.uuid().nullable(),
3097
- status: AgentRunStatusSchema,
3098
- created_at: z.string(),
3099
- started_at: z.string().nullable(),
3100
- completed_at: z.string().nullable(),
3101
- input_data: z.record(z.string(), z.unknown()).nullable(),
3102
- output_data: z.record(z.string(), z.unknown()).nullable(),
3103
- tasks: AgentTasksStateSchema.nullable().optional(),
3104
- error_message: z.string().nullable(),
3105
- execution_context: ResolvedExecutionContextSchema.nullable().optional(),
3106
- agent_version_id: z.uuid().nullable().optional(),
3107
- cached: z.boolean().optional()
3108
- }).openapi("AgentRunResponse");
3109
- z.object({
3110
- status: AgentRunStatusSchema.optional(),
3111
- agent_id: z.uuid().optional(),
3112
- agent_type: AgentTypeSchema.optional(),
3113
- limit: z.number().int().positive().max(100).default(20)
3114
- });
3115
- dayjs.extend(relativeTime);
3116
- dayjs.extend(customParseFormat);
3117
- dayjs.extend(utc);
3118
- dayjs.extend(timezone);
3119
- var daysjs_default = dayjs;
3120
-
3121
- // ../shared/dist/src/data/FormattedData.js
3122
- var numberFormatCache = /* @__PURE__ */ new Map();
3123
- var getNumberFormatter = (minimumFractionDigits, maximumFractionDigits, useGrouping) => {
3124
- const key = `${minimumFractionDigits}:${maximumFractionDigits}:${useGrouping}`;
3125
- let formatter = numberFormatCache.get(key);
3126
- if (!formatter) {
3127
- formatter = new Intl.NumberFormat(void 0, {
3128
- minimumFractionDigits,
3129
- maximumFractionDigits,
3130
- useGrouping
3131
- });
3132
- numberFormatCache.set(key, formatter);
3133
- }
3134
- return formatter;
3135
- };
3136
- var formatWithAutoPrecision = (value, options = {}) => {
3137
- const { minPrecision = 0, maxPrecision = 6, trimZeros = true, useGrouping = true } = options;
3138
- if (typeof value !== "number" || isNaN(value)) {
3139
- return String(value);
3140
- }
3141
- if (value === 0) {
3142
- return "0";
3143
- }
3144
- const absValue = Math.abs(value);
3145
- let maximumFractionDigits;
3146
- if (absValue >= 1e3) {
3147
- maximumFractionDigits = 0;
3148
- } else if (absValue >= 100) {
3149
- maximumFractionDigits = 1;
3150
- } else if (absValue >= 10) {
3151
- maximumFractionDigits = 2;
3152
- } else if (absValue >= 1) {
3153
- maximumFractionDigits = 3;
3154
- } else if (absValue >= 0.1) {
3155
- maximumFractionDigits = 4;
3156
- } else if (absValue >= 0.01) {
3157
- maximumFractionDigits = 5;
3158
- } else {
3159
- maximumFractionDigits = maxPrecision;
3160
- if (absValue > 0) {
3161
- const exponent = Math.floor(Math.log10(absValue));
3162
- if (exponent < 0) {
3163
- maximumFractionDigits = Math.min(Math.abs(exponent) + 2, maxPrecision);
3164
- }
3165
- }
3166
- }
3167
- maximumFractionDigits = Math.max(maximumFractionDigits, minPrecision);
3168
- const formatter = getNumberFormatter(trimZeros ? 0 : maximumFractionDigits, maximumFractionDigits, useGrouping);
3169
- return formatter.format(value);
3170
- };
3171
- var MIN_VALID_YEAR = 1900;
3172
- var MAX_VALID_YEAR = 2200;
3173
- var zonedatetime = (format, zone) => ({ format, type: "zonedatetime", zone });
3174
- var datetime = (format) => ({ format, type: "datetime" });
3175
- var date = (format) => ({ format, type: "date" });
3176
- var DATE_FORMATS = [
3177
- // ISO 8601 formats
3178
- zonedatetime("YYYY-MM-DDTHH:mm:ss.SSSZ", "UTC"),
3179
- zonedatetime("YYYY-MM-DDTHH:mm:ssZ", "UTC"),
3180
- zonedatetime("YYYY-MM-DDTHH:mmZ", "UTC"),
3181
- datetime("YYYY-MM-DDTHH:mm:ss"),
3182
- datetime("YYYY-MM-DDTHH:mm"),
3183
- date("YYYY-MM-DDT"),
3184
- // Standard date formats
3185
- date("YYYY-MM-DD"),
3186
- date("YYYY/MM/DD"),
3187
- date("DD-MM-YYYY"),
3188
- date("DD/MM/YYYY"),
3189
- date("MM-DD-YYYY"),
3190
- date("MM/DD/YYYY"),
3191
- // Date time formats
3192
- datetime("YYYY-MM-DD HH:mm:ss"),
3193
- datetime("YYYY-MM-DD HH:mm"),
3194
- datetime("YYYY/MM/DD HH:mm:ss"),
3195
- datetime("YYYY/MM/DD HH:mm"),
3196
- datetime("DD-MM-YYYY HH:mm:ss"),
3197
- datetime("DD-MM-YYYY HH:mm"),
3198
- datetime("DD/MM/YYYY HH:mm:ss"),
3199
- datetime("DD/MM/YYYY HH:mm"),
3200
- datetime("MM-DD-YYYY HH:mm:ss"),
3201
- datetime("MM-DD-YYYY HH:mm"),
3202
- datetime("MM/DD/YYYY HH:mm:ss"),
3203
- datetime("MM/DD/YYYY HH:mm")
3204
- ];
3205
- var isDateString = (value) => {
3206
- if (typeof value !== "string")
3207
- return { isValid: false };
3208
- const stripped = value.replace(/[-/.:\s]/g, "");
3209
- if (/^\d+$/.test(stripped)) {
3210
- if (stripped.length < 6)
3211
- return { isValid: false };
3212
- if (value.length === stripped.length)
3213
- return { isValid: false };
3214
- }
3215
- if (stripped.length > "YYYY-MM-DDTHH:mm:ss.SSS+00:00".length) {
3216
- return { isValid: false };
3217
- }
3218
- for (const format of DATE_FORMATS) {
3219
- let date2;
3220
- try {
3221
- if (format.type === "zonedatetime") {
3222
- date2 = daysjs_default.tz(value, format.format, format.zone);
3223
- } else {
3224
- date2 = daysjs_default(value, format.format, true);
3225
- }
3226
- } catch {
3227
- continue;
3228
- }
3229
- if (date2.isValid()) {
3230
- const year = date2.year();
3231
- if (year < MIN_VALID_YEAR || year > MAX_VALID_YEAR)
3232
- continue;
3233
- const isDateTime = format.type === "zonedatetime" || format.type == "datetime";
3234
- return {
3235
- isValid: true,
3236
- parsedDate: date2,
3237
- isDateTime
3238
- };
3239
- }
3240
- }
3241
- return { isValid: false };
3242
- };
3243
- var formatDataValue = (value, { replaceNullValue } = {
3244
- replaceNullValue: true
3245
- }) => {
3246
- if (value === null || value === void 0) {
3247
- return {
3248
- display: replaceNullValue ? "empty" : null,
3249
- sortValue: null
3250
- };
3251
- }
3252
- let processedValue = value;
3253
- if (typeof processedValue === "string") {
3254
- try {
3255
- const parsed = JSON.parse(processedValue);
3256
- processedValue = parsed;
3257
- } catch {
3258
- }
3259
- }
3260
- if (processedValue && typeof processedValue === "object" && Object.keys(processedValue).length === 1 && "value" in processedValue) {
3261
- const extractedValue = processedValue.value;
3262
- const dateResult2 = isDateString(extractedValue);
3263
- if (dateResult2.isValid) {
3264
- return {
3265
- display: dateResult2.isDateTime ? dateResult2.parsedDate.format("YYYY-MM-DD HH:mm:ss") : dateResult2.parsedDate.format("YYYY-MM-DD"),
3266
- sortValue: dateResult2.parsedDate.valueOf()
3267
- };
3268
- }
3269
- return {
3270
- display: String(extractedValue),
3271
- sortValue: extractedValue
3272
- };
3273
- }
3274
- const dateResult = isDateString(processedValue);
3275
- if (dateResult.isValid) {
3276
- return {
3277
- display: dateResult.isDateTime ? dateResult.parsedDate.format("YYYY-MM-DD HH:mm:ss") : dateResult.parsedDate.format("YYYY-MM-DD"),
3278
- sortValue: dateResult.parsedDate.valueOf()
3279
- };
3280
- }
3281
- if (typeof processedValue === "object") {
3282
- const stringified = JSON.stringify(processedValue, null, 2);
3283
- return {
3284
- display: stringified,
3285
- sortValue: stringified
3286
- };
3287
- }
3288
- if (typeof processedValue === "boolean") {
3289
- return {
3290
- display: String(processedValue),
3291
- sortValue: processedValue ? 1 : 0
3292
- };
3293
- }
3294
- if (typeof processedValue === "number") {
3295
- return {
3296
- display: processedValue >= MIN_VALID_YEAR && processedValue <= MAX_VALID_YEAR && Number.isInteger(processedValue) ? String(processedValue) : formatWithAutoPrecision(processedValue),
3297
- sortValue: processedValue
3298
- };
3299
- }
3300
- return {
3301
- // eslint-disable-next-line @typescript-eslint/no-base-to-string
3302
- display: String(processedValue),
3303
- sortValue: processedValue
3304
- };
3305
- };
3477
+ tasks: AgentTasksStateSchema.optional(),
3478
+ error_message: z.string().optional(),
3479
+ model_config: ModelConfigSchema.optional(),
3480
+ last_heartbeat_at: z.string().nullable().optional(),
3481
+ post_processors: z.array(PostProcessorConfigSchema).optional()
3482
+ });
3483
+ var StartAgentRunRequestSchema = z.object({
3484
+ agent_id: z.uuid(),
3485
+ inputs: z.record(z.string(), z.unknown()).default({}),
3486
+ execution_context: ExecutionContextInputSchema.optional()
3487
+ }).openapi("StartAgentRunRequest");
3488
+ var AgentRunResponseSchema = z.object({
3489
+ id: z.uuid(),
3490
+ agent_id: z.uuid().nullable(),
3491
+ status: AgentRunStatusSchema,
3492
+ created_at: z.string(),
3493
+ started_at: z.string().nullable(),
3494
+ completed_at: z.string().nullable(),
3495
+ input_data: z.record(z.string(), z.unknown()).nullable(),
3496
+ output_data: z.record(z.string(), z.unknown()).nullable(),
3497
+ tasks: AgentTasksStateSchema.nullable().optional(),
3498
+ error_message: z.string().nullable(),
3499
+ execution_context: ResolvedExecutionContextSchema.nullable().optional(),
3500
+ agent_version_id: z.uuid().nullable().optional(),
3501
+ cached: z.boolean().optional(),
3502
+ cached_from: z.uuid().nullable().optional(),
3503
+ report_count: z.number().int().nonnegative().default(0),
3504
+ visualization_count: z.number().int().nonnegative().default(0)
3505
+ }).openapi("AgentRunResponse");
3506
+ z.object({
3507
+ status: AgentRunStatusSchema.optional(),
3508
+ agent_id: z.uuid().optional(),
3509
+ agent_type: AgentTypeSchema.optional(),
3510
+ limit: z.number().int().positive().max(100).default(20)
3511
+ });
3306
3512
 
3307
3513
  // ../shared/dist/src/schemas/visualizations.js
3308
3514
  var commonConfigProperties = {
@@ -3446,6 +3652,14 @@ var FrontendVisualizationSchema = VisualizationSchema.omit({
3446
3652
  is_sample: true,
3447
3653
  data_summary: true
3448
3654
  });
3655
+ var isFrontendV1Visualization = (visualization) => {
3656
+ return !("config_version" in visualization.configuration);
3657
+ };
3658
+ var isFrontendV2Visualization = (visualization) => {
3659
+ return "config_version" in visualization.configuration && // we currently have only 2 versions
3660
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
3661
+ visualization.configuration.config_version === 2;
3662
+ };
3449
3663
  var VisualizationMetadataSchema = z.object({
3450
3664
  wasSampled: z.boolean(),
3451
3665
  originalCount: z.number(),
@@ -3459,6 +3673,14 @@ var FrontendVisualizationWithDataSchema = FrontendVisualizationSchema.extend({
3459
3673
  data: VisualizationDataSchema,
3460
3674
  _metadata: VisualizationMetadataSchema
3461
3675
  });
3676
+ var isFrontendV1VisualizationWithData = (visualization) => {
3677
+ return !("config_version" in visualization.configuration);
3678
+ };
3679
+ var isFrontendV2VisualizationWithData = (visualization) => {
3680
+ return "config_version" in visualization.configuration && // we currently have only 2 versions
3681
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
3682
+ visualization.configuration.config_version === 2;
3683
+ };
3462
3684
 
3463
3685
  // ../shared/dist/src/endpoints/agents/runs.routes.js
3464
3686
  var AgentRunIdParam = z.object({ id: z.uuid() }).openapi("AgentRunId");
@@ -3795,39 +4017,6 @@ var ListVisualizationsForFlow = createRoute({
3795
4017
  }
3796
4018
  }
3797
4019
  });
3798
- var isToolResultMessage = (message) => {
3799
- if (message.role !== "assistant") {
3800
- return false;
3801
- }
3802
- return message.parts.some(
3803
- (part) => part.type.startsWith("tool-") && "state" in part && part.state === "output-available"
3804
- );
3805
- };
3806
- var MageMetricsChatTransport = class extends DefaultChatTransport {
3807
- constructor(apiUrl, flowId, options) {
3808
- super({
3809
- ...options,
3810
- api: `${apiUrl}/api/v1/chat/${flowId}`,
3811
- prepareSendMessagesRequest({ messages, id: chatId, body }) {
3812
- const lastMessage = messages.at(-1);
3813
- if (lastMessage && isToolResultMessage(lastMessage)) {
3814
- lastMessage.metadata = {
3815
- ...typeof lastMessage.metadata === "object" ? lastMessage.metadata : void 0,
3816
- isFrontendToolSubmission: true
3817
- };
3818
- }
3819
- const chatHints = body?.chatHints;
3820
- return {
3821
- body: {
3822
- message: lastMessage,
3823
- id: chatId,
3824
- ...chatHints ? { chatHints } : {}
3825
- }
3826
- };
3827
- }
3828
- });
3829
- }
3830
- };
3831
4020
 
3832
4021
  // src/core/resolvable.ts
3833
4022
  var resolve = (value) => {
@@ -3940,6 +4129,16 @@ var MageMetricsClient = class {
3940
4129
  async logout() {
3941
4130
  await this.authProvider.logout();
3942
4131
  }
4132
+ /**
4133
+ * Clean up all resources held by this client.
4134
+ * Unsubscribes auth state listeners, stops auto-refresh timers,
4135
+ * and removes global event listeners (e.g. visibilitychange).
4136
+ *
4137
+ * Call this before discarding a client instance to prevent leaks.
4138
+ */
4139
+ destroy() {
4140
+ this.authProvider.destroy();
4141
+ }
3943
4142
  auth = {
3944
4143
  startAutoRefresh: () => {
3945
4144
  const supabaseClient = this.authProvider.getSupabaseClient();
@@ -4335,29 +4534,23 @@ var MageMetricsClient = class {
4335
4534
  },
4336
4535
  fetchReportData: async (reportId, { columns, limit, sorting, filters, cursor }, signal) => {
4337
4536
  const params = toSearchParams({ limit, sorting, filters, cursor });
4338
- const { data, error } = await this.internalApiClient.GET(
4339
- GetReportData.path,
4340
- {
4341
- params: {
4342
- path: {
4343
- report_id: reportId
4344
- },
4345
- query: {
4346
- columns: columns?.join(","),
4347
- limit: params.limit,
4348
- order: params.order,
4349
- cursor: params.cursor,
4350
- filter: params.filter
4351
- }
4537
+ const { data } = await this.internalApiClient.GET(GetReportData.path, {
4538
+ params: {
4539
+ path: {
4540
+ report_id: reportId
4352
4541
  },
4353
- signal
4354
- }
4355
- );
4356
- if (error) {
4357
- console.error(
4358
- `Failed to fetch data for report ${reportId}: ${error.error}`
4359
- );
4360
- throw new Error(`Failed to fetch data for flow data ${reportId}`);
4542
+ query: {
4543
+ columns: columns?.join(","),
4544
+ limit: params.limit,
4545
+ order: params.order,
4546
+ cursor: params.cursor,
4547
+ filter: params.filter
4548
+ }
4549
+ },
4550
+ signal
4551
+ });
4552
+ if (!data) {
4553
+ throw new Error(`Missing report data payload for report ${reportId}`);
4361
4554
  }
4362
4555
  return data;
4363
4556
  },
@@ -4428,6 +4621,28 @@ var MageMetricsClient = class {
4428
4621
  });
4429
4622
  }
4430
4623
  return data.recommendations;
4624
+ },
4625
+ getPromptStarters: async (input) => {
4626
+ await this.waitForAuth();
4627
+ const { data, error, response } = await this.internalApiClient.GET(
4628
+ GetPromptStarters.path,
4629
+ {
4630
+ params: {
4631
+ query: {
4632
+ input
4633
+ }
4634
+ }
4635
+ }
4636
+ );
4637
+ if (error) {
4638
+ throw new ApiError(error.error, response, {
4639
+ status: response.status,
4640
+ statusText: response.statusText,
4641
+ url: response.url,
4642
+ method: "GET"
4643
+ });
4644
+ }
4645
+ return data.starters;
4431
4646
  }
4432
4647
  };
4433
4648
  client() {
@@ -4446,4 +4661,432 @@ var MageMetricsClient = class {
4446
4661
  }
4447
4662
  };
4448
4663
 
4449
- export { BrowserStorageAdapter, CHECK_KEY, DirectAuthProvider, ExternalAuthProvider, MageMetricsClient, MageMetricsEventEmitter, MemoryStorageAdapter, TOKEN_STORAGE_KEY, getPublicApiClient };
4664
+ // src/core/chat.ts
4665
+ var hasOnlyInitialUserMessage = (messages) => {
4666
+ return messages.length === 1 && messages[0]?.role === "user";
4667
+ };
4668
+ var ASK_USER_QUESTION = "askUserQuestion";
4669
+ var optionSchema = z.object({
4670
+ label: z.string().describe("Option display text (1-5 words)"),
4671
+ description: z.string().describe("Explanation of the option")
4672
+ });
4673
+ var questionSchema = z.object({
4674
+ question: z.string().describe("The question to ask the user"),
4675
+ // Truncate at 30 chars; describe() says 20 to provide margin for the LLM
4676
+ header: z.string().transform((s) => s.slice(0, 30)).describe("Short label (max 20 chars)"),
4677
+ multiSelect: z.boolean().describe("Allow multiple selections"),
4678
+ options: z.array(optionSchema).min(2).max(4).describe("Available options for the user to choose from")
4679
+ });
4680
+ z.object({
4681
+ questions: z.array(questionSchema).min(1).max(4).describe("Questions to ask the user (1-4 questions)")
4682
+ });
4683
+ var SuccessVersion = z.object({
4684
+ status: z.literal("success"),
4685
+ answers: z.record(z.string(), z.string()).describe("Map of question text to user's answer")
4686
+ });
4687
+ var ErrorVersion = z.object({
4688
+ status: z.literal("error"),
4689
+ message: z.string()
4690
+ });
4691
+ var askUserQuestionResultSchema = z.discriminatedUnion("status", [
4692
+ SuccessVersion,
4693
+ ErrorVersion
4694
+ ]);
4695
+ z.object({
4696
+ tool: z.literal(ASK_USER_QUESTION).default(ASK_USER_QUESTION),
4697
+ result: askUserQuestionResultSchema
4698
+ });
4699
+
4700
+ // ../shared/dist/src/ai/schema/message.js
4701
+ var isAskUserQuestionPart = (part) => {
4702
+ return part.type === `tool-${ASK_USER_QUESTION}`;
4703
+ };
4704
+ var getMessageTextContent = (message) => {
4705
+ const content = message.parts.reduce((content2, part) => {
4706
+ if (part.type === "text") {
4707
+ return content2 + part.text;
4708
+ }
4709
+ return content2;
4710
+ }, "");
4711
+ if (content.trim().length === 0) {
4712
+ return void 0;
4713
+ }
4714
+ return content;
4715
+ };
4716
+ var GENERATE_DATA_REPORT = "generateDataReport";
4717
+ var SqlErrorCategory = z.enum([
4718
+ // Infrastructure errors (retriable - SQL might still be valid)
4719
+ "timeout",
4720
+ "connection_error",
4721
+ "auth_error",
4722
+ "resource_exhausted",
4723
+ // SQL Schema errors (SQL references non-existent objects)
4724
+ "table_not_found",
4725
+ "column_not_found",
4726
+ "schema_not_found",
4727
+ "view_not_found",
4728
+ "function_not_found",
4729
+ // SQL Syntax errors
4730
+ "syntax_error",
4731
+ // SQL Semantic errors
4732
+ "ambiguous_column",
4733
+ "type_mismatch",
4734
+ "invalid_cast",
4735
+ "invalid_argument",
4736
+ // SQL Runtime errors
4737
+ "division_by_zero",
4738
+ "constraint_violation",
4739
+ // Access errors
4740
+ "permission_denied",
4741
+ // Fallback
4742
+ "unknown"
4743
+ ]);
4744
+ var SqlGenerationErrorInfo = z.object({
4745
+ error_message: z.string(),
4746
+ category: SqlErrorCategory,
4747
+ details: z.string().nullish(),
4748
+ hint: z.string().nullish(),
4749
+ line_num: z.number().nullish(),
4750
+ col_num: z.number().nullish()
4751
+ });
4752
+ var SuccessVersion2 = z.object({
4753
+ status: z.literal("success"),
4754
+ public: z.object({
4755
+ flowDataId: z.number(),
4756
+ reportId: z.string(),
4757
+ answer: z.string().nullish(),
4758
+ title: z.string().nullish()
4759
+ }),
4760
+ private: z.object({
4761
+ sql: z.string(),
4762
+ dataReportSummary: z.string()
4763
+ })
4764
+ });
4765
+ var RedactedSuccessVersion = SuccessVersion2.omit({
4766
+ private: true
4767
+ });
4768
+ var ErrorVersion2 = z.object({
4769
+ status: z.literal("error"),
4770
+ message: z.string(),
4771
+ errorInfo: SqlGenerationErrorInfo.optional(),
4772
+ failedSql: z.string().optional()
4773
+ });
4774
+ var RedactedErrorVersion = z.object({
4775
+ status: z.literal("error"),
4776
+ category: SqlErrorCategory.optional()
4777
+ });
4778
+ var GenerateDataReportResponse = z.object({
4779
+ tool: z.literal(GENERATE_DATA_REPORT).default(GENERATE_DATA_REPORT),
4780
+ result: z.discriminatedUnion("status", [SuccessVersion2, ErrorVersion2]).optional()
4781
+ });
4782
+ GenerateDataReportResponse.extend({
4783
+ result: z.discriminatedUnion("status", [
4784
+ SuccessVersion2.omit({ private: true }),
4785
+ RedactedErrorVersion
4786
+ ]).optional()
4787
+ });
4788
+ z.object({
4789
+ rawRequest: z.string().describe("The user message that triggered this tool call. Usually exactly what they typed. For edge cases like 'do it again' or option selection '2', resolve to the actual request content. Do not extrapolate or add assumptions."),
4790
+ userRequest: z.string().describe("Complete, self-contained description of the data report to generate."),
4791
+ isNewAnalysisGoal: z.boolean().describe("Indicates whether this request represents a new analysis goal very different from the current conversation flow (true), or continues/modifies the existing analysis (false)."),
4792
+ difficultyLevel: z.enum(["simple", "moderate", "complex"]).describe("Complexity level of the SQL query based on the user request.")
4793
+ });
4794
+ var outputResultSchema = z.discriminatedUnion("status", [SuccessVersion2, ErrorVersion2]).optional();
4795
+ z.object({
4796
+ tool: z.literal(GENERATE_DATA_REPORT),
4797
+ result: outputResultSchema
4798
+ });
4799
+ z.object({
4800
+ tool: z.literal(GENERATE_DATA_REPORT),
4801
+ result: z.discriminatedUnion("status", [
4802
+ RedactedSuccessVersion,
4803
+ RedactedErrorVersion
4804
+ ]).optional()
4805
+ });
4806
+ var GENERATE_VISUALIZATION = "generateVisualization";
4807
+ var SuccessVersion3 = z.object({
4808
+ status: z.literal("success"),
4809
+ public: z.object({
4810
+ flowDataId: z.number(),
4811
+ reportId: z.string(),
4812
+ flowDataVisualizationId: z.number(),
4813
+ visualizationId: z.string(),
4814
+ title: z.string().nullish(),
4815
+ type: z.string().nullish()
4816
+ }),
4817
+ private: z.object({
4818
+ sql: z.string().optional(),
4819
+ dataReportSummary: z.string().optional()
4820
+ })
4821
+ });
4822
+ var RedactedSuccessVersion2 = SuccessVersion3.omit({
4823
+ private: true
4824
+ });
4825
+ var ErrorVersion3 = z.object({
4826
+ status: z.literal("error"),
4827
+ message: z.string()
4828
+ });
4829
+ var GenerateVisualizationResponse = z.object({
4830
+ tool: z.literal(GENERATE_VISUALIZATION).default(GENERATE_VISUALIZATION),
4831
+ result: z.discriminatedUnion("status", [SuccessVersion3, ErrorVersion3]).optional()
4832
+ });
4833
+ GenerateVisualizationResponse.extend({
4834
+ result: z.discriminatedUnion("status", [
4835
+ SuccessVersion3.omit({ private: true }),
4836
+ ErrorVersion3
4837
+ ]).optional()
4838
+ });
4839
+ z.object({
4840
+ reportId: z.number().or(z.uuid()).describe("The ID (legacy numeric id, or new uuid) of the report to visualize. Use output from generateDataReport."),
4841
+ chartType: z.enum(["bar", "line/area", "scatter", "pie"]).describe("Type of visualization to generate"),
4842
+ explanations: z.string().describe("Mandatory instructions for the visualization engine. This must include: 1) Aggregation logic (e.g., 'Sum revenue', 'Count IDs'), 2) Grouping details, 3) Limits for high-cardinality data (e.g., 'Sort descending and keep only the Top 10 results'), and 4) The specific columns to display on the plot (identifying metrics, axis, and dimensions).")
4843
+ });
4844
+ var outputResultSchema2 = z.discriminatedUnion("status", [SuccessVersion3, ErrorVersion3]).optional();
4845
+ z.object({
4846
+ tool: z.literal(GENERATE_VISUALIZATION),
4847
+ result: outputResultSchema2
4848
+ });
4849
+ z.object({
4850
+ tool: z.literal(GENERATE_VISUALIZATION),
4851
+ result: z.discriminatedUnion("status", [RedactedSuccessVersion2, ErrorVersion3]).optional()
4852
+ });
4853
+ var GET_AVAILABLE_COLUMNS_FOR_TABLE = "getAvailableColumnsForTable";
4854
+ var SuccessVersion4 = z.object({
4855
+ status: z.literal("success"),
4856
+ public: z.looseObject({}),
4857
+ private: z.object({
4858
+ message: z.string().optional(),
4859
+ columns: z.object({
4860
+ name: z.string(),
4861
+ data_type: z.string().nullable(),
4862
+ description: z.string().nullable(),
4863
+ null_percentage: z.number().nullable(),
4864
+ unique_values: z.number().nullable(),
4865
+ sample_values: z.array(z.any()).nullable()
4866
+ }).array()
4867
+ })
4868
+ });
4869
+ var RedactedSuccessVersion3 = SuccessVersion4.omit({
4870
+ private: true
4871
+ });
4872
+ var ErrorVersion4 = z.object({
4873
+ status: z.literal("error"),
4874
+ message: z.string()
4875
+ });
4876
+ var GetAvailableColumnsForTableResponse = z.object({
4877
+ tool: z.literal(GET_AVAILABLE_COLUMNS_FOR_TABLE).default(GET_AVAILABLE_COLUMNS_FOR_TABLE),
4878
+ result: z.discriminatedUnion("status", [SuccessVersion4, ErrorVersion4]).optional()
4879
+ });
4880
+ GetAvailableColumnsForTableResponse.extend({
4881
+ result: z.discriminatedUnion("status", [
4882
+ SuccessVersion4.omit({ private: true }),
4883
+ ErrorVersion4
4884
+ ]).optional()
4885
+ });
4886
+ z.object({
4887
+ dataset: z.string().describe("The dataset (schema) the table belongs to."),
4888
+ table_name: z.string().describe("A table name of the database for which to retrieve all column names and information.")
4889
+ });
4890
+ var outputResultSchema3 = z.discriminatedUnion("status", [SuccessVersion4, ErrorVersion4]).optional();
4891
+ z.object({
4892
+ tool: z.literal(GET_AVAILABLE_COLUMNS_FOR_TABLE),
4893
+ result: outputResultSchema3
4894
+ });
4895
+ z.object({
4896
+ tool: z.literal(GET_AVAILABLE_COLUMNS_FOR_TABLE),
4897
+ result: z.discriminatedUnion("status", [RedactedSuccessVersion3, ErrorVersion4]).optional()
4898
+ });
4899
+ var GET_AVAILABLE_TABLES = "getAvailableTables";
4900
+ var SuccessVersion5 = z.object({
4901
+ status: z.literal("success"),
4902
+ public: z.looseObject({}),
4903
+ private: z.object({
4904
+ tables: z.array(z.object({
4905
+ dataset: z.string(),
4906
+ table_name: z.string(),
4907
+ description: z.string().nullable()
4908
+ }))
4909
+ })
4910
+ });
4911
+ var RedactedSuccessVersion4 = SuccessVersion5.omit({
4912
+ private: true
4913
+ });
4914
+ var ErrorVersion5 = z.object({
4915
+ status: z.literal("error"),
4916
+ message: z.string()
4917
+ });
4918
+ var GetAvailableTablesResponse = z.object({
4919
+ tool: z.literal(GET_AVAILABLE_TABLES).default(GET_AVAILABLE_TABLES),
4920
+ result: z.discriminatedUnion("status", [SuccessVersion5, ErrorVersion5]).optional()
4921
+ });
4922
+ GetAvailableTablesResponse.extend({
4923
+ result: z.discriminatedUnion("status", [
4924
+ SuccessVersion5.omit({ private: true }),
4925
+ ErrorVersion5
4926
+ ]).optional()
4927
+ });
4928
+ z.object({}).describe("This tool requires no parameters and returns all table names available in the database.");
4929
+ var outputResultSchema4 = z.discriminatedUnion("status", [SuccessVersion5, ErrorVersion5]).optional();
4930
+ z.object({
4931
+ tool: z.literal(GET_AVAILABLE_TABLES),
4932
+ result: outputResultSchema4
4933
+ });
4934
+ z.object({
4935
+ tool: z.literal(GET_AVAILABLE_TABLES),
4936
+ result: z.discriminatedUnion("status", [RedactedSuccessVersion4, ErrorVersion5]).optional()
4937
+ });
4938
+ var PAGINATE_DATA_REPORT = "paginateDataReport";
4939
+ z.object({
4940
+ reportId: z.number().describe("The ID of the report to fetch data from"),
4941
+ limit: z.number().optional().default(50).describe("Number of rows to fetch (default 50)"),
4942
+ offset: z.number().optional().default(0).describe("Row offset - skip this many rows from the start (default 0)"),
4943
+ skipSampleRows: z.boolean().optional().default(true).describe("Skip rows already shown in the data_sample from generateDataReport (default true). Set to false only if you need to re-fetch from the beginning.")
4944
+ });
4945
+ var SuccessVersion6 = z.object({
4946
+ status: z.literal("success"),
4947
+ public: z.object({
4948
+ totalRows: z.number(),
4949
+ fetchedRows: z.number(),
4950
+ offset: z.number(),
4951
+ hasMore: z.boolean()
4952
+ }),
4953
+ /* the data is in the private field to avoid sending it to the frontend
4954
+ * this is not a security feature as the user has access to the report anyway */
4955
+ private: z.object({
4956
+ data: z.array(z.record(z.string(), z.unknown()))
4957
+ })
4958
+ });
4959
+ var RedactedSuccessVersion5 = SuccessVersion6.omit({
4960
+ private: true
4961
+ });
4962
+ var ErrorVersion6 = z.object({
4963
+ status: z.literal("error"),
4964
+ message: z.string()
4965
+ });
4966
+ var PaginateDataReportResponse = z.object({
4967
+ tool: z.literal(PAGINATE_DATA_REPORT).default(PAGINATE_DATA_REPORT),
4968
+ result: z.discriminatedUnion("status", [SuccessVersion6, ErrorVersion6]).optional()
4969
+ });
4970
+ PaginateDataReportResponse.extend({
4971
+ result: z.discriminatedUnion("status", [RedactedSuccessVersion5, ErrorVersion6]).optional()
4972
+ });
4973
+ var outputResultSchema5 = z.discriminatedUnion("status", [SuccessVersion6, ErrorVersion6]).optional();
4974
+ z.object({
4975
+ tool: z.literal(PAGINATE_DATA_REPORT),
4976
+ result: outputResultSchema5
4977
+ });
4978
+ z.object({
4979
+ tool: z.literal(PAGINATE_DATA_REPORT),
4980
+ result: z.discriminatedUnion("status", [RedactedSuccessVersion5, ErrorVersion6]).optional()
4981
+ });
4982
+ var THINK = "think";
4983
+ var outputResultSchema6 = z.object({
4984
+ status: z.literal("success"),
4985
+ public: z.looseObject({}),
4986
+ private: z.looseObject({})
4987
+ });
4988
+ var ThinkResponse = z.object({
4989
+ tool: z.literal(THINK).default(THINK),
4990
+ result: outputResultSchema6.optional()
4991
+ });
4992
+ ThinkResponse.extend({
4993
+ result: outputResultSchema6.omit({ private: true }).optional()
4994
+ });
4995
+ z.object({
4996
+ thought: z.string().describe("A thought to think about.")
4997
+ });
4998
+ var VALUE_BASED_COLUMN_SEARCH = "valueBasedColumnSearch";
4999
+ var SuccessVersion7 = z.object({
5000
+ status: z.literal("success"),
5001
+ public: z.looseObject({}),
5002
+ private: z.object({
5003
+ message: z.string().optional(),
5004
+ columns: z.object({
5005
+ name: z.string(),
5006
+ data_type: z.string().nullable(),
5007
+ description: z.string().nullable(),
5008
+ table: z.object({
5009
+ table_name: z.string(),
5010
+ description: z.string().nullable()
5011
+ }),
5012
+ matched_values: z.string().array()
5013
+ }).array()
5014
+ })
5015
+ });
5016
+ var RedactedSuccessVersion6 = SuccessVersion7.omit({
5017
+ private: true
5018
+ });
5019
+ var ErrorVersion7 = z.object({
5020
+ status: z.literal("error"),
5021
+ message: z.string()
5022
+ });
5023
+ var ValueBasedColumnSearchResponse = z.object({
5024
+ tool: z.literal(VALUE_BASED_COLUMN_SEARCH).default(VALUE_BASED_COLUMN_SEARCH),
5025
+ result: z.discriminatedUnion("status", [SuccessVersion7, ErrorVersion7]).optional()
5026
+ });
5027
+ ValueBasedColumnSearchResponse.extend({
5028
+ result: z.discriminatedUnion("status", [
5029
+ SuccessVersion7.omit({ private: true }),
5030
+ ErrorVersion7
5031
+ ]).optional()
5032
+ });
5033
+ z.object({
5034
+ value: z.string().describe("A literal data value as it would appear in a cell (e.g. 'France', 'PRD-00123', 'Apple iPhone'). Must NOT be a column name or concept.")
5035
+ });
5036
+ var outputResultSchema7 = z.discriminatedUnion("status", [SuccessVersion7, ErrorVersion7]).optional();
5037
+ z.object({
5038
+ tool: z.literal(VALUE_BASED_COLUMN_SEARCH),
5039
+ result: outputResultSchema7
5040
+ });
5041
+ z.object({
5042
+ tool: z.literal(VALUE_BASED_COLUMN_SEARCH),
5043
+ result: z.discriminatedUnion("status", [RedactedSuccessVersion6, ErrorVersion7]).optional()
5044
+ });
5045
+ var WEB_SEARCH = "webSearch";
5046
+ var Source = z.object({
5047
+ sourceType: z.literal("url"),
5048
+ id: z.string(),
5049
+ url: z.string(),
5050
+ title: z.string()
5051
+ });
5052
+ var SuccessVersion8 = z.object({
5053
+ status: z.literal("success"),
5054
+ public: z.object({
5055
+ sources: z.array(Source).optional().describe("Array of source objects.")
5056
+ }),
5057
+ private: z.object({
5058
+ answer: z.string().optional().describe("The answer from the search results, if successful.")
5059
+ })
5060
+ });
5061
+ var RedactedSuccessVersion7 = SuccessVersion8.omit({
5062
+ private: true
5063
+ });
5064
+ var ErrorVersion8 = z.object({
5065
+ status: z.literal("error"),
5066
+ message: z.string()
5067
+ });
5068
+ var WebSearchToolResponse = z.object({
5069
+ tool: z.literal("search").default("search"),
5070
+ result: z.discriminatedUnion("status", [SuccessVersion8, ErrorVersion8]).optional()
5071
+ });
5072
+ WebSearchToolResponse.extend({
5073
+ result: z.discriminatedUnion("status", [
5074
+ SuccessVersion8.omit({ private: true }),
5075
+ ErrorVersion8
5076
+ ]).optional()
5077
+ });
5078
+ z.object({
5079
+ query: z.string().describe("Specific search query focused on external factors that relate to the current analysis (e.g., 'China India trade policy changes 2024', 'housing market interest rates Q3 2024'). Should target actionable business context, not general information."),
5080
+ fromDate: z.iso.date().optional().describe("Only include content published after this date (YYYY-MM-DD). Useful for recent news or time-specific analysis."),
5081
+ toDate: z.iso.date().optional().describe("Only include content published before this date (YYYY-MM-DD). Combine with fromDate for a date range.")
5082
+ });
5083
+ var outputResultSchema8 = z.discriminatedUnion("status", [SuccessVersion8, ErrorVersion8]).optional();
5084
+ z.object({
5085
+ result: outputResultSchema8
5086
+ });
5087
+ z.object({
5088
+ tool: z.literal("search"),
5089
+ result: z.discriminatedUnion("status", [RedactedSuccessVersion7, ErrorVersion8]).optional()
5090
+ });
5091
+
5092
+ export { ASK_USER_QUESTION, BrowserStorageAdapter, CHAT_ALLOWED_FILE_MEDIA_TYPES, CHAT_FILE_ACCEPT, CHAT_MAX_COMBINED_FILE_SIZE, CHAT_MAX_FILE_COUNT, CHAT_MAX_FILE_SIZE, CHECK_KEY, DirectAuthProvider, ExternalAuthProvider, GENERATE_DATA_REPORT, GENERATE_VISUALIZATION, GET_AVAILABLE_COLUMNS_FOR_TABLE, GET_AVAILABLE_TABLES, MageMetricsChatTransport, MageMetricsClient, MageMetricsEventEmitter, MemoryStorageAdapter, PAGINATE_DATA_REPORT, THINK, TOKEN_STORAGE_KEY, UPLOADED_FILE_REF_PREFIX, VALUE_BASED_COLUMN_SEARCH, WEB_SEARCH, getMessageTextContent, getPublicApiClient, getUploadedFileIdFromUrl, hasOnlyInitialUserMessage, isAskUserQuestionPart, isFrontendV1Visualization, isFrontendV1VisualizationWithData, isFrontendV2Visualization, isFrontendV2VisualizationWithData, toSearchParams, toUploadedFileRefUrl, validateUploadedFiles };