@magemetrics/core 0.5.2 → 0.5.4

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,12 +1,12 @@
1
1
  import z5, { z } from 'zod';
2
+ import { GoTrueClient } from '@supabase/auth-js';
3
+ import createApiClient from 'openapi-fetch';
4
+ import { sha256 } from '@noble/hashes/sha2.js';
2
5
  import dayjs from 'dayjs';
3
6
  import customParseFormat from 'dayjs/plugin/customParseFormat.js';
4
7
  import relativeTime from 'dayjs/plugin/relativeTime.js';
5
8
  import timezone from 'dayjs/plugin/timezone.js';
6
9
  import utc from 'dayjs/plugin/utc.js';
7
- import { GoTrueClient } from '@supabase/auth-js';
8
- import createApiClient from 'openapi-fetch';
9
- import { sha256 } from '@noble/hashes/sha2.js';
10
10
  import { DefaultChatTransport } from 'ai';
11
11
 
12
12
  // ../shared/dist/src/api/client/middleware.js
@@ -54,7 +54,7 @@ var addApiKeyHeader = (apiKey) => {
54
54
  };
55
55
  };
56
56
 
57
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@8.1.0_zod@4.1.12/node_modules/@asteasolutions/zod-to-openapi/dist/index.mjs
57
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@8.1.0_zod@4.1.13/node_modules/@asteasolutions/zod-to-openapi/dist/index.mjs
58
58
  function __rest(s, e) {
59
59
  var t = {};
60
60
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -603,6 +603,17 @@ var ReportColumnSchema = z.looseObject({
603
603
  unique_count: z.number().nullable(),
604
604
  unique_percentage: z.number().nullable()
605
605
  });
606
+ var MaterializationStatusSchema = z.enum([
607
+ "completed",
608
+ "running",
609
+ "failed"
610
+ ]);
611
+ var MaterializationFieldsSchema = z.object({
612
+ is_materialized: z.boolean().nullable(),
613
+ last_materialized_at: z.string().nullable(),
614
+ materialized_error_message: z.string().nullable(),
615
+ materialized_status: MaterializationStatusSchema.nullable()
616
+ });
606
617
  var ReportSchema = z.object({
607
618
  created_at: z.string(),
608
619
  flow_id: z.string(),
@@ -619,7 +630,8 @@ var ReportSchema = z.object({
619
630
  }),
620
631
  bookmarked: z.boolean(),
621
632
  status: z.string().nullable(),
622
- is_removed: z.boolean()
633
+ is_removed: z.boolean(),
634
+ ...MaterializationFieldsSchema.shape
623
635
  });
624
636
  var FrontendReportSchema = ReportSchema.omit({
625
637
  sql: true,
@@ -665,680 +677,142 @@ var FrontendReportExplainabilitySchema = ReportExplainabilitySchema.omit({
665
677
  id: true,
666
678
  created_at: true
667
679
  });
668
- dayjs.extend(relativeTime);
669
- dayjs.extend(customParseFormat);
670
- dayjs.extend(utc);
671
- dayjs.extend(timezone);
672
- var daysjs_default = dayjs;
673
680
 
674
- // ../shared/dist/src/data/FormattedData.js
675
- var formatWithAutoPrecision = (value, options = {}) => {
676
- const { minPrecision = 0, maxPrecision = 6, trimZeros = true, useGrouping = true } = options;
677
- if (typeof value !== "number" || isNaN(value)) {
678
- return String(value);
679
- }
680
- if (value === 0) {
681
- return "0";
682
- }
683
- const absValue = Math.abs(value);
684
- let maximumFractionDigits;
685
- if (absValue >= 1e3) {
686
- maximumFractionDigits = 0;
687
- } else if (absValue >= 100) {
688
- maximumFractionDigits = 1;
689
- } else if (absValue >= 10) {
690
- maximumFractionDigits = 2;
691
- } else if (absValue >= 1) {
692
- maximumFractionDigits = 3;
693
- } else if (absValue >= 0.1) {
694
- maximumFractionDigits = 4;
695
- } else if (absValue >= 0.01) {
696
- maximumFractionDigits = 5;
697
- } else {
698
- maximumFractionDigits = maxPrecision;
699
- if (absValue > 0) {
700
- const exponent = Math.floor(Math.log10(absValue));
701
- if (exponent < 0) {
702
- maximumFractionDigits = Math.min(Math.abs(exponent) + 2, maxPrecision);
681
+ // ../shared/dist/src/endpoints/companion/flows.routes.js
682
+ var FlowIdParam = z.object({ flowId: z.uuid() }).openapi("FlowId", { type: "string" });
683
+ var FlowDataIdParam = z.object({ flowDataId: z.string().pipe(z.coerce.number()) }).openapi("FlowDataId", { type: "integer" });
684
+ var ReportId = z.string().pipe(z.coerce.number());
685
+ var ReportIdParam = z.object({ report_id: ReportId }).openapi("ReportId", { type: "integer" });
686
+ var RetrieveFlowDataReports = createRoute({
687
+ method: "get",
688
+ path: "/api/v1/flows/{flowId}/data-reports",
689
+ operationId: "retrieveFlowDataReports",
690
+ request: {
691
+ headers: SupabaseHeaderSchema,
692
+ params: FlowIdParam
693
+ },
694
+ responses: {
695
+ 200: {
696
+ description: "The data reports associated with the flow",
697
+ content: {
698
+ "application/json": {
699
+ schema: FrontendReportSchema.array()
700
+ }
703
701
  }
704
- }
705
- }
706
- maximumFractionDigits = Math.max(maximumFractionDigits, minPrecision);
707
- const formatter = new Intl.NumberFormat(void 0, {
708
- minimumFractionDigits: trimZeros ? 0 : maximumFractionDigits,
709
- maximumFractionDigits,
710
- useGrouping
711
- });
712
- return formatter.format(value);
713
- };
714
- var MIN_VALID_YEAR = 1900;
715
- var MAX_VALID_YEAR = 2200;
716
- var zonedatetime = (format, zone) => ({ format, type: "zonedatetime", zone });
717
- var datetime = (format) => ({ format, type: "datetime" });
718
- var date = (format) => ({ format, type: "date" });
719
- var DATE_FORMATS = [
720
- // ISO 8601 formats
721
- zonedatetime("YYYY-MM-DDTHH:mm:ss.SSSZ", "UTC"),
722
- zonedatetime("YYYY-MM-DDTHH:mm:ssZ", "UTC"),
723
- zonedatetime("YYYY-MM-DDTHH:mmZ", "UTC"),
724
- datetime("YYYY-MM-DDTHH:mm:ss"),
725
- datetime("YYYY-MM-DDTHH:mm"),
726
- date("YYYY-MM-DDT"),
727
- // Standard date formats
728
- date("YYYY-MM-DD"),
729
- date("YYYY/MM/DD"),
730
- date("DD-MM-YYYY"),
731
- date("DD/MM/YYYY"),
732
- date("MM-DD-YYYY"),
733
- date("MM/DD/YYYY"),
734
- // Date time formats
735
- datetime("YYYY-MM-DD HH:mm:ss"),
736
- datetime("YYYY-MM-DD HH:mm"),
737
- datetime("YYYY/MM/DD HH:mm:ss"),
738
- datetime("YYYY/MM/DD HH:mm"),
739
- datetime("DD-MM-YYYY HH:mm:ss"),
740
- datetime("DD-MM-YYYY HH:mm"),
741
- datetime("DD/MM/YYYY HH:mm:ss"),
742
- datetime("DD/MM/YYYY HH:mm"),
743
- datetime("MM-DD-YYYY HH:mm:ss"),
744
- datetime("MM-DD-YYYY HH:mm"),
745
- datetime("MM/DD/YYYY HH:mm:ss"),
746
- datetime("MM/DD/YYYY HH:mm")
747
- ];
748
- var isDateString = (value) => {
749
- if (typeof value !== "string")
750
- return { isValid: false };
751
- const stripped = value.replace(/[-/.:\s]/g, "");
752
- if (/^\d+$/.test(stripped)) {
753
- if (stripped.length < 6)
754
- return { isValid: false };
755
- if (value.length === stripped.length)
756
- return { isValid: false };
757
- }
758
- if (stripped.length > "YYYY-MM-DDTHH:mm:ss.SSS+00:00".length) {
759
- return { isValid: false };
760
- }
761
- for (const format of DATE_FORMATS) {
762
- let date2;
763
- try {
764
- if (format.type === "zonedatetime") {
765
- date2 = daysjs_default.tz(value, format.format, format.zone);
766
- } else {
767
- date2 = daysjs_default(value, format.format, true);
702
+ },
703
+ 404: {
704
+ content: {
705
+ "application/json": {
706
+ schema: z.object({ error: z.string() })
707
+ }
708
+ },
709
+ description: "Unable to retrieve flow with this id"
710
+ },
711
+ 500: {
712
+ description: "Something wrong happened",
713
+ content: {
714
+ "application/json": {
715
+ schema: z.object({
716
+ error: z.string()
717
+ })
718
+ }
768
719
  }
769
- } catch {
770
- continue;
771
- }
772
- if (date2.isValid()) {
773
- const year = date2.year();
774
- if (year < MIN_VALID_YEAR || year > MAX_VALID_YEAR)
775
- continue;
776
- const isDateTime = format.type === "zonedatetime" || format.type == "datetime";
777
- return {
778
- isValid: true,
779
- parsedDate: date2,
780
- isDateTime
781
- };
782
720
  }
783
721
  }
784
- return { isValid: false };
785
- };
786
- var formatDataValue = (value, { replaceNullValue } = {
787
- replaceNullValue: true
788
- }) => {
789
- if (value === null || value === void 0) {
790
- return {
791
- display: replaceNullValue ? "empty" : null,
792
- sortValue: null
793
- };
794
- }
795
- let processedValue = value;
796
- if (typeof processedValue === "string") {
797
- try {
798
- const parsed = JSON.parse(processedValue);
799
- processedValue = parsed;
800
- } catch {
722
+ });
723
+ createRoute({
724
+ method: "get",
725
+ path: "/api/v1/flows/{flowId}/data-reports/last/status",
726
+ operationId: "retrieveLatestDataReportStatus",
727
+ request: {
728
+ headers: SupabaseHeaderSchema,
729
+ params: FlowIdParam
730
+ },
731
+ responses: {
732
+ 200: {
733
+ description: "The status of the latest flow data for a given flow",
734
+ content: {
735
+ "application/json": {
736
+ schema: z.object({ status: z.string().nullable() })
737
+ }
738
+ }
739
+ },
740
+ 404: {
741
+ content: {
742
+ "application/json": {
743
+ schema: z.object({ error: z.string() })
744
+ }
745
+ },
746
+ description: "Unable to retrieve status for latest flow data of flow with this id"
747
+ },
748
+ 500: {
749
+ description: "Something wrong happened",
750
+ content: {
751
+ "application/json": {
752
+ schema: z.object({
753
+ error: z.string()
754
+ })
755
+ }
756
+ }
801
757
  }
802
758
  }
803
- if (processedValue && typeof processedValue === "object" && Object.keys(processedValue).length === 1 && "value" in processedValue) {
804
- const extractedValue = processedValue.value;
805
- const dateResult2 = isDateString(extractedValue);
806
- if (dateResult2.isValid) {
807
- return {
808
- display: dateResult2.isDateTime ? dateResult2.parsedDate.format("YYYY-MM-DD HH:mm:ss") : dateResult2.parsedDate.format("YYYY-MM-DD"),
809
- sortValue: dateResult2.parsedDate.valueOf()
810
- };
811
- }
812
- return {
813
- display: String(extractedValue),
814
- sortValue: extractedValue
815
- };
816
- }
817
- const dateResult = isDateString(processedValue);
818
- if (dateResult.isValid) {
819
- return {
820
- display: dateResult.isDateTime ? dateResult.parsedDate.format("YYYY-MM-DD HH:mm:ss") : dateResult.parsedDate.format("YYYY-MM-DD"),
821
- sortValue: dateResult.parsedDate.valueOf()
822
- };
823
- }
824
- if (typeof processedValue === "object") {
825
- const stringified = JSON.stringify(processedValue, null, 2);
826
- return {
827
- display: stringified,
828
- sortValue: stringified
829
- };
830
- }
831
- if (typeof processedValue === "boolean") {
832
- return {
833
- display: String(processedValue),
834
- sortValue: processedValue ? 1 : 0
835
- };
836
- }
837
- if (typeof processedValue === "number") {
838
- return {
839
- display: processedValue >= MIN_VALID_YEAR && processedValue <= MAX_VALID_YEAR && Number.isInteger(processedValue) ? String(processedValue) : formatWithAutoPrecision(processedValue),
840
- sortValue: processedValue
841
- };
842
- }
843
- return {
844
- // eslint-disable-next-line @typescript-eslint/no-base-to-string
845
- display: String(processedValue),
846
- sortValue: processedValue
847
- };
848
- };
849
-
850
- // ../shared/dist/src/schemas/visualizations.js
851
- var commonConfigProperties = {
852
- title: z.string()
853
- };
854
- var cartesianConfigProperties = {
855
- xAxisLabel: z.string(),
856
- yAxisLabel: z.string(),
857
- xAxisDataKey: z.string().optional(),
858
- yAxisDataKey: z.string().optional(),
859
- dimensionDataKey: z.string().optional(),
860
- valueColumns: z.array(z.string()).optional()
861
- };
862
- var V1VisualizationConfigurationSchema = z.discriminatedUnion("type", [
863
- // Bar chart
864
- z.object({
865
- type: z.literal("bar"),
866
- ...commonConfigProperties,
867
- ...cartesianConfigProperties
868
- }),
869
- // Line/Area chart
870
- z.object({
871
- type: z.literal("line/area"),
872
- ...commonConfigProperties,
873
- ...cartesianConfigProperties
874
- }),
875
- // Scatter chart
876
- z.object({
877
- type: z.literal("scatter"),
878
- ...commonConfigProperties,
879
- ...cartesianConfigProperties
880
- }),
881
- // Pie chart
882
- z.object({
883
- type: z.literal("pie"),
884
- ...commonConfigProperties,
885
- nameKey: z.string(),
886
- dataKey: z.string()
887
- })
888
- ]);
889
- var VisualizationConfigurationSchema = z.discriminatedUnion("type", [
890
- z.object({
891
- type: z.literal("bar"),
892
- ...commonConfigProperties,
893
- config_version: z.literal(2),
894
- xAxisLabel: z.string(),
895
- yAxisLabel: z.string(),
896
- categoryColumn: z.string(),
897
- secondaryCategoryColumn: z.string().optional(),
898
- valueColumn: z.string()
899
- }),
900
- // Line/Area chart - version 2: New format
901
- z.object({
902
- type: z.literal("line/area"),
903
- config_version: z.literal(2),
904
- ...commonConfigProperties,
905
- xAxisColumn: z.string(),
906
- valueColumns: z.array(z.string()),
907
- yAxisLabels: z.array(z.string())
908
- }),
909
- // Line/Area chart - categorical format (requires pivoting)
910
- z.object({
911
- type: z.literal("line/area-categorical"),
912
- ...commonConfigProperties,
913
- config_version: z.literal(2),
914
- valueColumn: z.string(),
915
- xAxisColumn: z.string(),
916
- xAxisLabel: z.string(),
917
- yAxisLabel: z.string(),
918
- categoryColumn: z.string()
919
- }),
920
- // Scatter chart - new format (v2)
921
- z.object({
922
- type: z.literal("scatter"),
923
- ...commonConfigProperties,
924
- config_version: z.literal(2),
925
- xAxisLabel: z.string(),
926
- yAxisLabel: z.string(),
927
- xAxisValueColumn: z.string(),
928
- yAxisValueColumn: z.string()
929
- }),
930
- // Pie chart - new format (v2)
931
- z.object({
932
- type: z.literal("pie"),
933
- ...commonConfigProperties,
934
- config_version: z.literal(2),
935
- categoryColumn: z.string(),
936
- valueColumn: z.string()
937
- })
938
- ]);
939
- var BaseVisualizationSchema = z.object({
940
- id: z.number(),
941
- flow_data_id: z.number(),
942
- created_at: z.string(),
943
- sql: z.string(),
944
- bookmarked: z.boolean(),
945
- data_sample: z.array(z.record(z.string(), z.unknown())),
946
- is_sample: z.boolean(),
947
- data_summary: z.record(z.string(), z.unknown())
948
- });
949
- var V1VisualizationSchema = z.object({
950
- ...BaseVisualizationSchema.shape,
951
- configuration: V1VisualizationConfigurationSchema
952
- });
953
- var VisualizationSchema = z.object({
954
- ...BaseVisualizationSchema.shape,
955
- configuration: VisualizationConfigurationSchema
956
- });
957
- var VisualizationDataSchema = z.array(z.record(
958
- z.string(),
959
- // any key
960
- z.union([
961
- // Date objects FIRST
962
- z.date(),
963
- z.coerce.number(),
964
- // Handle various data types including BigQueryDate
965
- z.unknown().transform((val) => formatDataValue(val).display)
966
- ])
967
- )).openapi("VisualizationData");
968
- var V1FrontendVisualizationSchema = V1VisualizationSchema.omit({
969
- sql: true,
970
- data_sample: true,
971
- is_sample: true,
972
- data_summary: true
973
- });
974
- var FrontendVisualizationSchema = VisualizationSchema.omit({
975
- sql: true,
976
- data_sample: true,
977
- is_sample: true,
978
- data_summary: true
979
- });
980
- var VisualizationMetadataSchema = z.object({
981
- wasSampled: z.boolean(),
982
- originalCount: z.number(),
983
- sampledCount: z.number()
984
- }).optional();
985
- var V1FrontendVisualizationWithDataSchema = V1FrontendVisualizationSchema.extend({
986
- data: VisualizationDataSchema,
987
- _metadata: VisualizationMetadataSchema
988
- });
989
- var FrontendVisualizationWithDataSchema = FrontendVisualizationSchema.extend({
990
- data: VisualizationDataSchema,
991
- _metadata: VisualizationMetadataSchema
992
- });
993
-
994
- // ../shared/dist/src/endpoints/companion/flows.routes.js
995
- var FlowIdParam = z.object({ flowId: z.string().uuid() }).openapi("FlowId", { type: "string" });
996
- var FlowDataIdParam = z.object({ flowDataId: z.string().pipe(z.coerce.number()) }).openapi("FlowDataId", { type: "integer" });
997
- var ReportId = z.string().pipe(z.coerce.number());
998
- var ReportIdParam = z.object({ report_id: ReportId }).openapi("ReportId", { type: "integer" });
999
- var RetrieveFlowDataReports = createRoute({
1000
- method: "get",
1001
- path: "/api/v1/flows/{flowId}/data-reports",
1002
- operationId: "retrieveFlowDataReports",
1003
- request: {
1004
- headers: SupabaseHeaderSchema,
1005
- params: FlowIdParam
1006
- },
1007
- responses: {
1008
- 200: {
1009
- description: "The data reports associated with the flow",
1010
- content: {
1011
- "application/json": {
1012
- schema: FrontendReportSchema.array()
1013
- }
1014
- }
1015
- },
1016
- 404: {
1017
- content: {
1018
- "application/json": {
1019
- schema: z.object({ error: z.string() })
1020
- }
1021
- },
1022
- description: "Unable to retrieve flow with this id"
1023
- },
1024
- 500: {
1025
- description: "Something wrong happened",
1026
- content: {
1027
- "application/json": {
1028
- schema: z.object({
1029
- error: z.string()
1030
- })
1031
- }
1032
- }
1033
- }
1034
- }
1035
- });
1036
- createRoute({
1037
- method: "get",
1038
- path: "/api/v1/flows/{flowId}/data-reports/last/status",
1039
- operationId: "retrieveLatestDataReportStatus",
1040
- request: {
1041
- headers: SupabaseHeaderSchema,
1042
- params: FlowIdParam
1043
- },
1044
- responses: {
1045
- 200: {
1046
- description: "The status of the latest flow data for a given flow",
1047
- content: {
1048
- "application/json": {
1049
- schema: z.object({ status: z.string().nullable() })
1050
- }
1051
- }
1052
- },
1053
- 404: {
1054
- content: {
1055
- "application/json": {
1056
- schema: z.object({ error: z.string() })
1057
- }
1058
- },
1059
- description: "Unable to retrieve status for latest flow data of flow with this id"
1060
- },
1061
- 500: {
1062
- description: "Something wrong happened",
1063
- content: {
1064
- "application/json": {
1065
- schema: z.object({
1066
- error: z.string()
1067
- })
1068
- }
1069
- }
1070
- }
1071
- }
1072
- });
1073
- createRoute({
1074
- // this endpoint is deprecated and will be removed in the future
1075
- hide: true,
1076
- method: "get",
1077
- path: "/api/v1/flows/{flowId}/insights",
1078
- operationId: "retrieveInsights",
1079
- request: {
1080
- headers: SupabaseHeaderSchema,
1081
- params: FlowIdParam,
1082
- query: z.object({
1083
- flowDataId: z.string().pipe(z.coerce.number()).optional().openapi({
1084
- param: {
1085
- required: false
1086
- },
1087
- type: "integer"
1088
- })
1089
- })
1090
- },
1091
- responses: {
1092
- 200: {
1093
- description: "The content of the flow",
1094
- content: {
1095
- "application/json": {
1096
- schema: z.object({
1097
- dataReports: FrontendReportSchema.array(),
1098
- visualizations: V1FrontendVisualizationSchema.array()
1099
- })
1100
- }
1101
- }
1102
- },
1103
- 404: {
1104
- content: {
1105
- "application/json": {
1106
- schema: z.object({ error: z.string() })
1107
- }
1108
- },
1109
- description: "Unable to retrieve flow with this id"
1110
- },
1111
- 500: {
1112
- description: "Something wrong happened",
1113
- content: {
1114
- "application/json": {
1115
- schema: z.object({
1116
- error: z.string()
1117
- })
1118
- }
1119
- }
1120
- }
1121
- }
1122
- });
1123
- createRoute({
1124
- // this endpoint is deprecated and will be removed in the future
1125
- hide: true,
1126
- method: "get",
1127
- path: "/api/v1/flows/{flowId}/columns",
1128
- operationId: "retrieveFlowColumns",
1129
- request: {
1130
- headers: SupabaseHeaderSchema,
1131
- params: FlowIdParam,
1132
- query: FlowDataIdParam
1133
- },
1134
- responses: {
1135
- 200: {
1136
- description: "A list containing the columns of the flow",
1137
- content: {
1138
- "application/json": {
1139
- schema: FrontendReportColumnsSchema
1140
- }
1141
- }
1142
- },
1143
- 404: {
1144
- content: {
1145
- "application/json": {
1146
- schema: z.object({ error: z.string() })
1147
- }
1148
- },
1149
- description: "Unable to retrieve flow with this id"
1150
- },
1151
- 500: {
1152
- description: "Something wrong happened",
1153
- content: {
1154
- "application/json": {
1155
- schema: z.object({
1156
- error: z.string()
1157
- })
1158
- }
1159
- }
1160
- }
1161
- }
1162
- });
1163
- var RetrieveFlow = createRoute({
1164
- method: "get",
1165
- path: "/api/v1/flows/{flowId}",
1166
- operationId: "retrieveFlow",
1167
- request: {
1168
- headers: SupabaseHeaderSchema,
1169
- params: FlowIdParam
1170
- },
1171
- responses: {
1172
- 200: {
1173
- description: "The flow with its steps",
1174
- content: {
1175
- "application/json": {
1176
- schema: FrontendFlowSchema
1177
- }
1178
- }
1179
- },
1180
- 404: {
1181
- content: {
1182
- "application/json": {
1183
- schema: z.object({ error: z.string() })
1184
- }
1185
- },
1186
- description: "Unable to retrieve flow with this id"
1187
- },
1188
- 500: {
1189
- description: "Something wrong happened",
1190
- content: {
1191
- "application/json": {
1192
- schema: z.object({
1193
- error: z.string()
1194
- })
1195
- }
1196
- }
1197
- }
1198
- }
1199
- });
1200
- var RetrieveRecentFlows = createRoute({
1201
- method: "get",
1202
- path: "/api/v1/recent-flows",
1203
- operationId: "retrieveRecentFlows",
1204
- request: {
1205
- headers: SupabaseHeaderSchema,
1206
- query: z.object({
1207
- limit: limitQueryParams
1208
- })
1209
- },
1210
- responses: {
1211
- 200: {
1212
- description: "A list of recent flows",
1213
- content: {
1214
- "application/json": {
1215
- schema: FrontendRecentFlowsSchema.array()
1216
- }
1217
- }
1218
- },
1219
- 500: {
1220
- description: "Something wrong happened",
1221
- content: {
1222
- "application/json": {
1223
- schema: z.object({
1224
- error: z.string()
1225
- })
1226
- }
1227
- }
1228
- }
1229
- }
1230
- });
1231
- var GetReportColumns = createRoute({
1232
- method: "get",
1233
- path: "/api/v1/data-reports/{report_id}/columns",
1234
- operationId: "getDataReportColumns",
1235
- request: {
1236
- headers: SupabaseHeaderSchema,
1237
- params: ReportIdParam
1238
- },
1239
- responses: {
1240
- 200: {
1241
- description: "A list containing the columns of the report",
1242
- content: {
1243
- "application/json": {
1244
- schema: FrontendReportColumnsSchema
1245
- }
1246
- }
1247
- },
1248
- 404: {
1249
- content: {
1250
- "application/json": {
1251
- schema: z.object({ error: z.string() })
1252
- }
1253
- },
1254
- description: "Unable to retrieve report with this id"
1255
- },
1256
- 500: {
1257
- description: "Something wrong happened",
1258
- content: {
1259
- "application/json": {
1260
- schema: z.object({
1261
- error: z.string()
1262
- })
1263
- }
1264
- }
1265
- }
1266
- }
1267
- });
1268
- var ExportReportData = createRoute({
1269
- method: "get",
1270
- path: "/api/v1/data-reports/{report_id}/export",
1271
- operationId: "exportReportData",
1272
- request: {
1273
- headers: SupabaseHeaderSchema,
1274
- params: ReportIdParam
1275
- },
1276
- responses: {
1277
- 200: {
1278
- description: "The report data exported in CSV format",
1279
- content: {
1280
- "text/csv": {
1281
- schema: z.string().describe("CSV formatted string of report data")
1282
- }
1283
- }
1284
- },
1285
- 404: {
1286
- content: {
1287
- "application/json": {
1288
- schema: z.object({ error: z.string() })
1289
- }
1290
- },
1291
- description: "Unable to retrieve flow with this id"
1292
- },
1293
- 500: {
1294
- description: "Something wrong happened",
1295
- content: {
1296
- "application/json": {
1297
- schema: z.object({
1298
- error: z.string()
1299
- })
1300
- }
1301
- }
759
+ });
760
+ var RetrieveFlow = createRoute({
761
+ method: "get",
762
+ path: "/api/v1/flows/{flowId}",
763
+ operationId: "retrieveFlow",
764
+ request: {
765
+ headers: SupabaseHeaderSchema,
766
+ params: FlowIdParam
767
+ },
768
+ responses: {
769
+ 200: {
770
+ description: "The flow with its steps",
771
+ content: {
772
+ "application/json": {
773
+ schema: FrontendFlowSchema
774
+ }
775
+ }
776
+ },
777
+ 404: {
778
+ content: {
779
+ "application/json": {
780
+ schema: z.object({ error: z.string() })
781
+ }
782
+ },
783
+ description: "Unable to retrieve flow with this id"
784
+ },
785
+ 500: {
786
+ description: "Something wrong happened",
787
+ content: {
788
+ "application/json": {
789
+ schema: z.object({
790
+ error: z.string()
791
+ })
792
+ }
793
+ }
1302
794
  }
1303
795
  }
1304
796
  });
1305
- createRoute({
1306
- // this endpoint is deprecated and will be removed in the future
1307
- hide: true,
797
+ var RetrieveRecentFlows = createRoute({
1308
798
  method: "get",
1309
- path: "/api/v1/flows/{flowId}/data",
1310
- operationId: "retrieveFlowData",
799
+ path: "/api/v1/recent-flows",
800
+ operationId: "retrieveRecentFlows",
1311
801
  request: {
1312
802
  headers: SupabaseHeaderSchema,
1313
- params: FlowIdParam,
1314
803
  query: z.object({
1315
- limit: limitQueryParams,
1316
- order: orderQueryParams,
1317
- cursor: cursorParams,
1318
- filter: filterQueryParams,
1319
- flowDataId: FlowDataIdParam.shape.flowDataId.openapi({
1320
- type: "integer",
1321
- param: { required: true }
1322
- })
804
+ limit: limitQueryParams
1323
805
  })
1324
806
  },
1325
807
  responses: {
1326
808
  200: {
1327
- description: "The content of the flow",
809
+ description: "A list of recent flows",
1328
810
  content: {
1329
811
  "application/json": {
1330
- schema: ReportDataSchema
812
+ schema: FrontendRecentFlowsSchema.array()
1331
813
  }
1332
814
  }
1333
815
  },
1334
- 404: {
1335
- content: {
1336
- "application/json": {
1337
- schema: z.object({ error: z.string() })
1338
- }
1339
- },
1340
- description: "Unable to retrieve flow with this id"
1341
- },
1342
816
  500: {
1343
817
  description: "Something wrong happened",
1344
818
  content: {
@@ -1351,27 +825,20 @@ createRoute({
1351
825
  }
1352
826
  }
1353
827
  });
1354
- var GetReportData = createRoute({
828
+ var GetReportColumns = createRoute({
1355
829
  method: "get",
1356
- path: "/api/v1/data-reports/{report_id}/data",
1357
- operationId: "getDataReportData",
830
+ path: "/api/v1/data-reports/{report_id}/columns",
831
+ operationId: "getDataReportColumns",
1358
832
  request: {
1359
833
  headers: SupabaseHeaderSchema,
1360
- params: ReportIdParam,
1361
- query: z.object({
1362
- columns: columnsQueryParams,
1363
- limit: limitQueryParams,
1364
- order: orderQueryParams,
1365
- cursor: cursorParams,
1366
- filter: filterQueryParams
1367
- })
834
+ params: ReportIdParam
1368
835
  },
1369
836
  responses: {
1370
837
  200: {
1371
- description: "The content of the report",
838
+ description: "A list containing the columns of the report",
1372
839
  content: {
1373
840
  "application/json": {
1374
- schema: ReportDataSchema
841
+ schema: FrontendReportColumnsSchema
1375
842
  }
1376
843
  }
1377
844
  },
@@ -1395,32 +862,20 @@ var GetReportData = createRoute({
1395
862
  }
1396
863
  }
1397
864
  });
1398
- createRoute({
1399
- // this endpoint is deprecated and will be removed in the future
1400
- hide: true,
865
+ var ExportReportData = createRoute({
1401
866
  method: "get",
1402
- path: "/api/v1/flows/{flowId}/count",
1403
- operationId: "retrieveFlowDataCount",
867
+ path: "/api/v1/data-reports/{report_id}/export",
868
+ operationId: "exportReportData",
1404
869
  request: {
1405
870
  headers: SupabaseHeaderSchema,
1406
- params: FlowIdParam,
1407
- query: z.object({
1408
- flowDataId: z.string().pipe(z.coerce.number()).openapi({
1409
- param: {
1410
- required: false
1411
- },
1412
- type: "integer"
1413
- })
1414
- })
871
+ params: ReportIdParam
1415
872
  },
1416
873
  responses: {
1417
874
  200: {
1418
- description: "The total count of rows in the flow",
875
+ description: "The report data exported in CSV format",
1419
876
  content: {
1420
- "application/json": {
1421
- schema: z.object({
1422
- count: z.number().int().nonnegative().describe("Total number of rows in the flow")
1423
- })
877
+ "text/csv": {
878
+ schema: z.string().describe("CSV formatted string of report data")
1424
879
  }
1425
880
  }
1426
881
  },
@@ -1444,22 +899,27 @@ createRoute({
1444
899
  }
1445
900
  }
1446
901
  });
1447
- var GetReportRowCount = createRoute({
902
+ var GetReportData = createRoute({
1448
903
  method: "get",
1449
- path: "/api/v1/data-reports/{report_id}/count",
1450
- operationId: "getDataReportRowCount",
904
+ path: "/api/v1/data-reports/{report_id}/data",
905
+ operationId: "getDataReportData",
1451
906
  request: {
1452
907
  headers: SupabaseHeaderSchema,
1453
- params: ReportIdParam
908
+ params: ReportIdParam,
909
+ query: z.object({
910
+ columns: columnsQueryParams,
911
+ limit: limitQueryParams,
912
+ order: orderQueryParams,
913
+ cursor: cursorParams,
914
+ filter: filterQueryParams
915
+ })
1454
916
  },
1455
917
  responses: {
1456
918
  200: {
1457
- description: "The total count of rows in the report",
919
+ description: "The content of the report",
1458
920
  content: {
1459
921
  "application/json": {
1460
- schema: z.object({
1461
- count: z.number().int().nonnegative().describe("Total number of rows in the report")
1462
- })
922
+ schema: ReportDataSchema
1463
923
  }
1464
924
  }
1465
925
  },
@@ -1483,22 +943,22 @@ var GetReportRowCount = createRoute({
1483
943
  }
1484
944
  }
1485
945
  });
1486
- createRoute({
1487
- // this endpoint is deprecated and will be removed in the future
1488
- hide: true,
946
+ var GetReportRowCount = createRoute({
1489
947
  method: "get",
1490
- path: "/api/v1/flow-data/{flowDataId}/feedback",
1491
- operationId: "retrieveFeedback",
948
+ path: "/api/v1/data-reports/{report_id}/count",
949
+ operationId: "getDataReportRowCount",
1492
950
  request: {
1493
951
  headers: SupabaseHeaderSchema,
1494
- params: FlowDataIdParam
952
+ params: ReportIdParam
1495
953
  },
1496
954
  responses: {
1497
955
  200: {
1498
- description: "The feedback for the flow data",
956
+ description: "The total count of rows in the report",
1499
957
  content: {
1500
958
  "application/json": {
1501
- schema: FeedbackSchema.nullable()
959
+ schema: z.object({
960
+ count: z.number().int().nonnegative().describe("Total number of rows in the report")
961
+ })
1502
962
  }
1503
963
  }
1504
964
  },
@@ -1508,7 +968,7 @@ createRoute({
1508
968
  schema: z.object({ error: z.string() })
1509
969
  }
1510
970
  },
1511
- description: "Unable to retrieve feedback"
971
+ description: "Unable to retrieve report with this id"
1512
972
  },
1513
973
  500: {
1514
974
  description: "Something wrong happened",
@@ -1559,43 +1019,6 @@ createRoute({
1559
1019
  }
1560
1020
  }
1561
1021
  });
1562
- createRoute({
1563
- // this endpoint is deprecated and will be removed in the future
1564
- hide: true,
1565
- method: "post",
1566
- path: "/api/v1/flow-data/{flowDataId}/feedback",
1567
- operationId: "upsertFeedback",
1568
- request: {
1569
- headers: SupabaseHeaderSchema,
1570
- params: FlowDataIdParam,
1571
- body: {
1572
- description: "The feedback for the flow data",
1573
- required: true,
1574
- content: {
1575
- "application/json": {
1576
- schema: z.object({
1577
- helpfulness: FeedbackSchema.shape.helpfulness
1578
- })
1579
- }
1580
- }
1581
- }
1582
- },
1583
- responses: {
1584
- 200: {
1585
- description: "Successfully upserted feedback"
1586
- },
1587
- 500: {
1588
- description: "Something wrong happened",
1589
- content: {
1590
- "application/json": {
1591
- schema: z.object({
1592
- error: z.string()
1593
- })
1594
- }
1595
- }
1596
- }
1597
- }
1598
- });
1599
1022
  createRoute({
1600
1023
  method: "post",
1601
1024
  path: "/api/v1/data-reports/{report_id}/feedback",
@@ -1631,40 +1054,6 @@ createRoute({
1631
1054
  }
1632
1055
  }
1633
1056
  });
1634
- createRoute({
1635
- // this endpoint is deprecated and will be removed in the future
1636
- hide: true,
1637
- method: "delete",
1638
- path: "/api/v1/flow-data/{flowDataId}/feedback",
1639
- operationId: "deleteFeedback",
1640
- request: {
1641
- headers: SupabaseHeaderSchema,
1642
- params: FlowDataIdParam
1643
- },
1644
- responses: {
1645
- 200: {
1646
- description: "Successfully deleted feedback"
1647
- },
1648
- 404: {
1649
- content: {
1650
- "application/json": {
1651
- schema: z.object({ error: z.string() })
1652
- }
1653
- },
1654
- description: "Unable to retrieve feedback"
1655
- },
1656
- 500: {
1657
- description: "Something wrong happened",
1658
- content: {
1659
- "application/json": {
1660
- schema: z.object({
1661
- error: z.string()
1662
- })
1663
- }
1664
- }
1665
- }
1666
- }
1667
- });
1668
1057
  createRoute({
1669
1058
  method: "delete",
1670
1059
  path: "/api/v1/data-reports/{report_id}/feedback",
@@ -1698,18 +1087,16 @@ createRoute({
1698
1087
  }
1699
1088
  });
1700
1089
  createRoute({
1701
- // this endpoint is deprecated and will be removed in the future
1702
- hide: true,
1703
1090
  method: "get",
1704
- path: "/api/v1/flow-data/{flowDataId}/explainability",
1705
- operationId: "retrieveFlowDataExplainability",
1091
+ path: "/api/v1/data-reports/{report_id}/explainability",
1092
+ operationId: "getDataReportExplainability",
1706
1093
  request: {
1707
1094
  headers: SupabaseHeaderSchema,
1708
- params: FlowDataIdParam
1095
+ params: ReportIdParam
1709
1096
  },
1710
1097
  responses: {
1711
1098
  200: {
1712
- description: "The explainability of the flow data",
1099
+ description: "The explainability of the report",
1713
1100
  content: {
1714
1101
  "application/json": {
1715
1102
  schema: FrontendReportExplainabilitySchema
@@ -1722,7 +1109,7 @@ createRoute({
1722
1109
  schema: z.object({ error: z.string() })
1723
1110
  }
1724
1111
  },
1725
- description: "Unable to retrieve flow with this id"
1112
+ description: "Unable to retrieve report with this id"
1726
1113
  },
1727
1114
  500: {
1728
1115
  description: "Something wrong happened",
@@ -1738,18 +1125,18 @@ createRoute({
1738
1125
  });
1739
1126
  createRoute({
1740
1127
  method: "get",
1741
- path: "/api/v1/data-reports/{report_id}/explainability",
1742
- operationId: "getDataReportExplainability",
1128
+ path: "/api/v1/data-reports/{report_id}",
1129
+ operationId: "getDataReport",
1743
1130
  request: {
1744
1131
  headers: SupabaseHeaderSchema,
1745
1132
  params: ReportIdParam
1746
1133
  },
1747
1134
  responses: {
1748
1135
  200: {
1749
- description: "The explainability of the report",
1136
+ description: "The visualizations for the report",
1750
1137
  content: {
1751
1138
  "application/json": {
1752
- schema: FrontendReportExplainabilitySchema
1139
+ schema: FrontendReportSchema
1753
1140
  }
1754
1141
  }
1755
1142
  },
@@ -1774,29 +1161,44 @@ createRoute({
1774
1161
  }
1775
1162
  });
1776
1163
  createRoute({
1777
- method: "get",
1778
- path: "/api/v1/data-reports/{report_id}",
1779
- operationId: "getDataReport",
1164
+ method: "post",
1165
+ path: "/api/v1/flow_data/v1/materialized_views/refresh",
1166
+ operationId: "refreshMaterializedViews",
1780
1167
  request: {
1781
1168
  headers: SupabaseHeaderSchema,
1782
- params: ReportIdParam
1169
+ body: {
1170
+ required: true,
1171
+ content: {
1172
+ "application/json": {
1173
+ schema: z.object({
1174
+ flow_data_ids: z.array(z.number().int()).min(1).describe("List of flow_data IDs to refresh")
1175
+ })
1176
+ }
1177
+ }
1178
+ }
1783
1179
  },
1784
1180
  responses: {
1785
1181
  200: {
1786
- description: "The visualizations for the report",
1182
+ description: "Successfully triggered refresh for materialized views",
1787
1183
  content: {
1788
1184
  "application/json": {
1789
- schema: FrontendReportSchema
1185
+ schema: z.object({
1186
+ status: z.literal("success"),
1187
+ /** Server timestamp when refresh was triggered (ISO 8601) */
1188
+ triggered_at: z.string()
1189
+ })
1790
1190
  }
1791
1191
  }
1792
1192
  },
1793
- 404: {
1193
+ 400: {
1194
+ description: "Invalid request",
1794
1195
  content: {
1795
1196
  "application/json": {
1796
- schema: z.object({ error: z.string() })
1197
+ schema: z.object({
1198
+ error: z.string()
1199
+ })
1797
1200
  }
1798
- },
1799
- description: "Unable to retrieve report with this id"
1201
+ }
1800
1202
  },
1801
1203
  500: {
1802
1204
  description: "Something wrong happened",
@@ -1811,37 +1213,28 @@ createRoute({
1811
1213
  }
1812
1214
  });
1813
1215
  createRoute({
1814
- hide: true,
1815
1216
  method: "get",
1816
- path: "/api/v1/data-reports/{report_id}/visualizations",
1817
- operationId: "getDataReportVisualizations",
1217
+ path: "/api/v1/flow_data/materialization-status",
1218
+ operationId: "getMaterializationStatus",
1818
1219
  request: {
1819
1220
  headers: SupabaseHeaderSchema,
1820
- params: ReportIdParam
1221
+ query: z.object({
1222
+ ids: z.string().transform((s) => s.split(",").map(Number)).describe("Comma-separated list of flow_data IDs")
1223
+ })
1821
1224
  },
1822
1225
  responses: {
1823
1226
  200: {
1824
- description: "The visualizations for the report",
1227
+ description: "Materialization status for the requested flow_data IDs",
1825
1228
  content: {
1826
1229
  "application/json": {
1827
- schema: z.object({
1828
- ...FrontendReportSchema.shape,
1829
- visualizations: z.union([
1830
- V1FrontendVisualizationSchema,
1831
- FrontendVisualizationSchema
1832
- ]).array()
1833
- })
1230
+ schema: z.array(z.object({
1231
+ id: z.number(),
1232
+ materialized_status: MaterializationStatusSchema.nullable(),
1233
+ last_materialized_at: z.string().nullable()
1234
+ }))
1834
1235
  }
1835
1236
  }
1836
1237
  },
1837
- 404: {
1838
- content: {
1839
- "application/json": {
1840
- schema: z.object({ error: z.string() })
1841
- }
1842
- },
1843
- description: "Unable to retrieve report with this id"
1844
- },
1845
1238
  500: {
1846
1239
  description: "Something wrong happened",
1847
1240
  content: {
@@ -2362,59 +1755,85 @@ var CreateSpeechToken = createRoute({
2362
1755
  }
2363
1756
  }
2364
1757
  });
2365
-
2366
- // ../shared/dist/src/endpoints/end2end/run.routes.js
2367
- var End2EndApiResponseSchema = z.discriminatedUnion("status", [
2368
- z.object({
2369
- status: z.literal("error"),
2370
- error: z.string()
1758
+ z5.discriminatedUnion("status", [
1759
+ z5.object({
1760
+ status: z5.literal("error"),
1761
+ error: z5.string()
2371
1762
  }),
2372
- z.object({
2373
- status: z.literal("success"),
2374
- flowId: z.string()
1763
+ z5.object({
1764
+ status: z5.literal("success"),
1765
+ flowId: z5.string()
2375
1766
  })
2376
1767
  ]);
2377
- createRoute({
1768
+ var TriggerFlowBody = z5.object({
1769
+ triggerId: z5.string(),
1770
+ variables: z5.record(z5.string(), z5.string()),
1771
+ applicationName: z5.string().optional()
1772
+ });
1773
+ var TriggerFlow = createRoute({
2378
1774
  method: "post",
2379
- path: "/api/v1/end2end",
2380
- operationId: "runEnd2EndFlow",
1775
+ path: "/api/v1/trigger-flow",
1776
+ operationId: "triggerFlow",
2381
1777
  request: {
2382
1778
  headers: SupabaseHeaderSchema,
2383
1779
  body: {
2384
1780
  required: true,
1781
+ description: "Trigger flow request body",
2385
1782
  content: {
2386
1783
  "application/json": {
2387
- schema: z.object({
2388
- userQuery: z.string(),
2389
- isNewAnalysisGoal: z.boolean().default(true),
2390
- difficultyLevel: z.enum(["simple", "moderate", "complex"]).default("complex")
2391
- })
1784
+ schema: TriggerFlowBody
2392
1785
  }
2393
1786
  }
2394
1787
  }
2395
1788
  },
2396
1789
  responses: {
2397
1790
  200: {
2398
- description: "Run the end2end flow",
1791
+ description: "Flow id",
1792
+ content: {
1793
+ "application/json": {
1794
+ schema: z5.object({
1795
+ status: z5.literal("success"),
1796
+ flowId: z5.string()
1797
+ })
1798
+ }
1799
+ }
1800
+ },
1801
+ 400: {
1802
+ content: {
1803
+ "application/json": {
1804
+ schema: z5.object({
1805
+ error: z5.string()
1806
+ })
1807
+ }
1808
+ },
1809
+ description: "Invalid template or variable values"
1810
+ },
1811
+ 404: {
1812
+ content: {
1813
+ "application/json": {
1814
+ schema: z5.object({ error: z5.string() })
1815
+ }
1816
+ },
1817
+ description: "Unable to retrieve trigger with this id"
1818
+ },
1819
+ 500: {
1820
+ description: "Something wrong happened",
2399
1821
  content: {
2400
1822
  "application/json": {
2401
- schema: End2EndApiResponseSchema
1823
+ schema: z5.object({
1824
+ error: z5.string()
1825
+ })
2402
1826
  }
2403
1827
  }
2404
1828
  }
2405
1829
  }
2406
1830
  });
2407
-
2408
- // ../shared/dist/src/endpoints/companion/triggers.routes.js
2409
- var TriggerFlowBody = z5.object({
2410
- triggerId: z5.string(),
2411
- variables: z5.record(z5.string(), z5.string()),
2412
- applicationName: z5.string().optional()
2413
- });
2414
- var TriggerFlow = createRoute({
1831
+ createRoute({
1832
+ hide: true,
1833
+ deprecated: true,
2415
1834
  method: "post",
2416
1835
  path: "/api/v1/trigger-flow/",
2417
- operationId: "triggerFlow",
1836
+ operationId: "triggerFlowOld",
2418
1837
  request: {
2419
1838
  headers: SupabaseHeaderSchema,
2420
1839
  body: {
@@ -2432,14 +1851,19 @@ var TriggerFlow = createRoute({
2432
1851
  description: "Flow id",
2433
1852
  content: {
2434
1853
  "application/json": {
2435
- schema: End2EndApiResponseSchema
1854
+ schema: z5.object({
1855
+ status: z5.literal("success"),
1856
+ flowId: z5.string()
1857
+ })
2436
1858
  }
2437
1859
  }
2438
1860
  },
2439
1861
  400: {
2440
1862
  content: {
2441
1863
  "application/json": {
2442
- schema: z5.object({ error: z5.string() })
1864
+ schema: z5.object({
1865
+ error: z5.string()
1866
+ })
2443
1867
  }
2444
1868
  },
2445
1869
  description: "Invalid template or variable values"
@@ -2566,10 +1990,12 @@ var hashString = (value) => {
2566
1990
  };
2567
1991
 
2568
1992
  // ../shared/dist/src/schemas/canvas.js
1993
+ var DATA_REPORT_LABEL = "dataReport";
1994
+ var VISUALIZATION_LABEL = "visualization";
2569
1995
  var CanvasSchema = z.object({
2570
1996
  company_id: z.number(),
2571
1997
  created_at: z.string(),
2572
- id: z.string().uuid(),
1998
+ id: z.uuid(),
2573
1999
  title: z.string().nullable(),
2574
2000
  updated_at: z.string(),
2575
2001
  is_removed: z.boolean(),
@@ -2603,6 +2029,22 @@ var CanvasIdParam = CanvasSchema.shape.id.openapi("CanvasId", {
2603
2029
  type: "string",
2604
2030
  format: "uuid"
2605
2031
  });
2032
+ var dataReportNodeSchema = z.object({
2033
+ type: z.literal(DATA_REPORT_LABEL),
2034
+ data: z.object({
2035
+ reportId: z.number()
2036
+ })
2037
+ });
2038
+ var visualizationNodeSchema = z.object({
2039
+ type: z.literal(VISUALIZATION_LABEL),
2040
+ data: z.object({
2041
+ visualizationId: z.number()
2042
+ })
2043
+ });
2044
+ z.discriminatedUnion("type", [
2045
+ dataReportNodeSchema,
2046
+ visualizationNodeSchema
2047
+ ]);
2606
2048
 
2607
2049
  // ../shared/dist/src/endpoints/companion/canvas.routes.js
2608
2050
  var ListCanvases = createRoute({
@@ -2845,163 +2287,371 @@ var GetCanvasForFlow = createRoute({
2845
2287
  }
2846
2288
  }
2847
2289
  });
2848
- var QuickActionSchema = z.object({
2849
- label: z.string(),
2850
- explanation: z.string()
2290
+
2291
+ // ../shared/dist/src/endpoints/companion/chat.routes.js
2292
+ var ChatMessages = createRoute({
2293
+ method: "get",
2294
+ path: "/api/v1/chat/{flowId}/messages",
2295
+ operationId: "retrieveChatMessages",
2296
+ request: {
2297
+ headers: SupabaseHeaderSchema,
2298
+ params: FlowIdParam
2299
+ },
2300
+ responses: {
2301
+ 200: {
2302
+ description: "The messages from the given flow",
2303
+ content: {
2304
+ "application/json": {
2305
+ // we don't want to have to write a parser for Vercel AI messages
2306
+ schema: z.object({ messages: z.looseObject({}).array() })
2307
+ }
2308
+ }
2309
+ },
2310
+ 404: {
2311
+ content: {
2312
+ "application/json": {
2313
+ schema: z.object({ error: z.string() })
2314
+ }
2315
+ },
2316
+ description: "Unable to retrieve flow with this id"
2317
+ },
2318
+ 500: {
2319
+ description: "Something wrong happened",
2320
+ content: {
2321
+ "application/json": {
2322
+ schema: z.object({
2323
+ error: z.string()
2324
+ })
2325
+ }
2326
+ }
2327
+ }
2328
+ }
2851
2329
  });
2852
- var QuickActionsSchema = QuickActionSchema.array();
2853
- var FrontendTimelineItemSchema = z.discriminatedUnion("type", [
2330
+ dayjs.extend(relativeTime);
2331
+ dayjs.extend(customParseFormat);
2332
+ dayjs.extend(utc);
2333
+ dayjs.extend(timezone);
2334
+ var daysjs_default = dayjs;
2335
+
2336
+ // ../shared/dist/src/data/FormattedData.js
2337
+ var formatWithAutoPrecision = (value, options = {}) => {
2338
+ const { minPrecision = 0, maxPrecision = 6, trimZeros = true, useGrouping = true } = options;
2339
+ if (typeof value !== "number" || isNaN(value)) {
2340
+ return String(value);
2341
+ }
2342
+ if (value === 0) {
2343
+ return "0";
2344
+ }
2345
+ const absValue = Math.abs(value);
2346
+ let maximumFractionDigits;
2347
+ if (absValue >= 1e3) {
2348
+ maximumFractionDigits = 0;
2349
+ } else if (absValue >= 100) {
2350
+ maximumFractionDigits = 1;
2351
+ } else if (absValue >= 10) {
2352
+ maximumFractionDigits = 2;
2353
+ } else if (absValue >= 1) {
2354
+ maximumFractionDigits = 3;
2355
+ } else if (absValue >= 0.1) {
2356
+ maximumFractionDigits = 4;
2357
+ } else if (absValue >= 0.01) {
2358
+ maximumFractionDigits = 5;
2359
+ } else {
2360
+ maximumFractionDigits = maxPrecision;
2361
+ if (absValue > 0) {
2362
+ const exponent = Math.floor(Math.log10(absValue));
2363
+ if (exponent < 0) {
2364
+ maximumFractionDigits = Math.min(Math.abs(exponent) + 2, maxPrecision);
2365
+ }
2366
+ }
2367
+ }
2368
+ maximumFractionDigits = Math.max(maximumFractionDigits, minPrecision);
2369
+ const formatter = new Intl.NumberFormat(void 0, {
2370
+ minimumFractionDigits: trimZeros ? 0 : maximumFractionDigits,
2371
+ maximumFractionDigits,
2372
+ useGrouping
2373
+ });
2374
+ return formatter.format(value);
2375
+ };
2376
+ var MIN_VALID_YEAR = 1900;
2377
+ var MAX_VALID_YEAR = 2200;
2378
+ var zonedatetime = (format, zone) => ({ format, type: "zonedatetime", zone });
2379
+ var datetime = (format) => ({ format, type: "datetime" });
2380
+ var date = (format) => ({ format, type: "date" });
2381
+ var DATE_FORMATS = [
2382
+ // ISO 8601 formats
2383
+ zonedatetime("YYYY-MM-DDTHH:mm:ss.SSSZ", "UTC"),
2384
+ zonedatetime("YYYY-MM-DDTHH:mm:ssZ", "UTC"),
2385
+ zonedatetime("YYYY-MM-DDTHH:mmZ", "UTC"),
2386
+ datetime("YYYY-MM-DDTHH:mm:ss"),
2387
+ datetime("YYYY-MM-DDTHH:mm"),
2388
+ date("YYYY-MM-DDT"),
2389
+ // Standard date formats
2390
+ date("YYYY-MM-DD"),
2391
+ date("YYYY/MM/DD"),
2392
+ date("DD-MM-YYYY"),
2393
+ date("DD/MM/YYYY"),
2394
+ date("MM-DD-YYYY"),
2395
+ date("MM/DD/YYYY"),
2396
+ // Date time formats
2397
+ datetime("YYYY-MM-DD HH:mm:ss"),
2398
+ datetime("YYYY-MM-DD HH:mm"),
2399
+ datetime("YYYY/MM/DD HH:mm:ss"),
2400
+ datetime("YYYY/MM/DD HH:mm"),
2401
+ datetime("DD-MM-YYYY HH:mm:ss"),
2402
+ datetime("DD-MM-YYYY HH:mm"),
2403
+ datetime("DD/MM/YYYY HH:mm:ss"),
2404
+ datetime("DD/MM/YYYY HH:mm"),
2405
+ datetime("MM-DD-YYYY HH:mm:ss"),
2406
+ datetime("MM-DD-YYYY HH:mm"),
2407
+ datetime("MM/DD/YYYY HH:mm:ss"),
2408
+ datetime("MM/DD/YYYY HH:mm")
2409
+ ];
2410
+ var isDateString = (value) => {
2411
+ if (typeof value !== "string")
2412
+ return { isValid: false };
2413
+ const stripped = value.replace(/[-/.:\s]/g, "");
2414
+ if (/^\d+$/.test(stripped)) {
2415
+ if (stripped.length < 6)
2416
+ return { isValid: false };
2417
+ if (value.length === stripped.length)
2418
+ return { isValid: false };
2419
+ }
2420
+ if (stripped.length > "YYYY-MM-DDTHH:mm:ss.SSS+00:00".length) {
2421
+ return { isValid: false };
2422
+ }
2423
+ for (const format of DATE_FORMATS) {
2424
+ let date2;
2425
+ try {
2426
+ if (format.type === "zonedatetime") {
2427
+ date2 = daysjs_default.tz(value, format.format, format.zone);
2428
+ } else {
2429
+ date2 = daysjs_default(value, format.format, true);
2430
+ }
2431
+ } catch {
2432
+ continue;
2433
+ }
2434
+ if (date2.isValid()) {
2435
+ const year = date2.year();
2436
+ if (year < MIN_VALID_YEAR || year > MAX_VALID_YEAR)
2437
+ continue;
2438
+ const isDateTime = format.type === "zonedatetime" || format.type == "datetime";
2439
+ return {
2440
+ isValid: true,
2441
+ parsedDate: date2,
2442
+ isDateTime
2443
+ };
2444
+ }
2445
+ }
2446
+ return { isValid: false };
2447
+ };
2448
+ var formatDataValue = (value, { replaceNullValue } = {
2449
+ replaceNullValue: true
2450
+ }) => {
2451
+ if (value === null || value === void 0) {
2452
+ return {
2453
+ display: replaceNullValue ? "empty" : null,
2454
+ sortValue: null
2455
+ };
2456
+ }
2457
+ let processedValue = value;
2458
+ if (typeof processedValue === "string") {
2459
+ try {
2460
+ const parsed = JSON.parse(processedValue);
2461
+ processedValue = parsed;
2462
+ } catch {
2463
+ }
2464
+ }
2465
+ if (processedValue && typeof processedValue === "object" && Object.keys(processedValue).length === 1 && "value" in processedValue) {
2466
+ const extractedValue = processedValue.value;
2467
+ const dateResult2 = isDateString(extractedValue);
2468
+ if (dateResult2.isValid) {
2469
+ return {
2470
+ display: dateResult2.isDateTime ? dateResult2.parsedDate.format("YYYY-MM-DD HH:mm:ss") : dateResult2.parsedDate.format("YYYY-MM-DD"),
2471
+ sortValue: dateResult2.parsedDate.valueOf()
2472
+ };
2473
+ }
2474
+ return {
2475
+ display: String(extractedValue),
2476
+ sortValue: extractedValue
2477
+ };
2478
+ }
2479
+ const dateResult = isDateString(processedValue);
2480
+ if (dateResult.isValid) {
2481
+ return {
2482
+ display: dateResult.isDateTime ? dateResult.parsedDate.format("YYYY-MM-DD HH:mm:ss") : dateResult.parsedDate.format("YYYY-MM-DD"),
2483
+ sortValue: dateResult.parsedDate.valueOf()
2484
+ };
2485
+ }
2486
+ if (typeof processedValue === "object") {
2487
+ const stringified = JSON.stringify(processedValue, null, 2);
2488
+ return {
2489
+ display: stringified,
2490
+ sortValue: stringified
2491
+ };
2492
+ }
2493
+ if (typeof processedValue === "boolean") {
2494
+ return {
2495
+ display: String(processedValue),
2496
+ sortValue: processedValue ? 1 : 0
2497
+ };
2498
+ }
2499
+ if (typeof processedValue === "number") {
2500
+ return {
2501
+ display: processedValue >= MIN_VALID_YEAR && processedValue <= MAX_VALID_YEAR && Number.isInteger(processedValue) ? String(processedValue) : formatWithAutoPrecision(processedValue),
2502
+ sortValue: processedValue
2503
+ };
2504
+ }
2505
+ return {
2506
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
2507
+ display: String(processedValue),
2508
+ sortValue: processedValue
2509
+ };
2510
+ };
2511
+
2512
+ // ../shared/dist/src/schemas/visualizations.js
2513
+ var commonConfigProperties = {
2514
+ title: z.string()
2515
+ };
2516
+ var cartesianConfigProperties = {
2517
+ xAxisLabel: z.string(),
2518
+ yAxisLabel: z.string(),
2519
+ xAxisDataKey: z.string().optional(),
2520
+ yAxisDataKey: z.string().optional(),
2521
+ dimensionDataKey: z.string().optional(),
2522
+ valueColumns: z.array(z.string()).optional()
2523
+ };
2524
+ var V1VisualizationConfigurationSchema = z.discriminatedUnion("type", [
2525
+ // Bar chart
2526
+ z.object({
2527
+ type: z.literal("bar"),
2528
+ ...commonConfigProperties,
2529
+ ...cartesianConfigProperties
2530
+ }),
2531
+ // Line/Area chart
2854
2532
  z.object({
2855
- type: z.literal("dataReport"),
2856
- flowDataId: z.number(),
2857
- flowId: z.string(),
2858
- title: z.string(),
2859
- bookmarked: z.boolean(),
2860
- answer: z.string().nullable()
2533
+ type: z.literal("line/area"),
2534
+ ...commonConfigProperties,
2535
+ ...cartesianConfigProperties
2861
2536
  }),
2537
+ // Scatter chart
2862
2538
  z.object({
2863
- type: z.literal("visualization"),
2864
- flowId: z.string(),
2865
- flowDataId: z.number(),
2866
- flowDataVisualizationId: z.number(),
2867
- title: z.string(),
2868
- bookmarked: z.boolean()
2539
+ type: z.literal("scatter"),
2540
+ ...commonConfigProperties,
2541
+ ...cartesianConfigProperties
2869
2542
  }),
2543
+ // Pie chart
2870
2544
  z.object({
2871
- type: z.literal("message")
2545
+ type: z.literal("pie"),
2546
+ ...commonConfigProperties,
2547
+ nameKey: z.string(),
2548
+ dataKey: z.string()
2872
2549
  })
2873
2550
  ]);
2874
-
2875
- // ../shared/dist/src/endpoints/companion/chat.routes.js
2876
- createRoute({
2877
- hide: true,
2878
- method: "get",
2879
- path: "/api/v1/chat/{flowId}/timeline",
2880
- operationId: "retrieveChatTimeline",
2881
- request: {
2882
- headers: SupabaseHeaderSchema,
2883
- params: FlowIdParam
2884
- },
2885
- responses: {
2886
- 200: {
2887
- description: "The timeline of generated insights for the flow",
2888
- content: {
2889
- "application/json": {
2890
- schema: FrontendTimelineItemSchema.array()
2891
- }
2892
- }
2893
- },
2894
- 404: {
2895
- content: {
2896
- "application/json": {
2897
- schema: z.object({ error: z.string() })
2898
- }
2899
- },
2900
- description: "Unable to retrieve flow with this id"
2901
- },
2902
- 500: {
2903
- description: "Something wrong happened",
2904
- content: {
2905
- "application/json": {
2906
- schema: z.object({
2907
- error: z.string()
2908
- })
2909
- }
2910
- }
2911
- }
2912
- }
2551
+ var VisualizationConfigurationSchema = z.discriminatedUnion("type", [
2552
+ z.object({
2553
+ type: z.literal("bar"),
2554
+ ...commonConfigProperties,
2555
+ config_version: z.literal(2),
2556
+ xAxisLabel: z.string(),
2557
+ yAxisLabel: z.string(),
2558
+ categoryColumn: z.string(),
2559
+ secondaryCategoryColumn: z.string().optional(),
2560
+ valueColumn: z.string()
2561
+ }),
2562
+ // Line/Area chart - version 2: New format
2563
+ z.object({
2564
+ type: z.literal("line/area"),
2565
+ config_version: z.literal(2),
2566
+ ...commonConfigProperties,
2567
+ xAxisColumn: z.string(),
2568
+ valueColumns: z.array(z.string()),
2569
+ yAxisLabels: z.array(z.string())
2570
+ }),
2571
+ // Line/Area chart - categorical format (requires pivoting)
2572
+ z.object({
2573
+ type: z.literal("line/area-categorical"),
2574
+ ...commonConfigProperties,
2575
+ config_version: z.literal(2),
2576
+ valueColumn: z.string(),
2577
+ xAxisColumn: z.string(),
2578
+ xAxisLabel: z.string(),
2579
+ yAxisLabel: z.string(),
2580
+ categoryColumn: z.string()
2581
+ }),
2582
+ // Scatter chart - new format (v2)
2583
+ z.object({
2584
+ type: z.literal("scatter"),
2585
+ ...commonConfigProperties,
2586
+ config_version: z.literal(2),
2587
+ xAxisLabel: z.string(),
2588
+ yAxisLabel: z.string(),
2589
+ xAxisValueColumn: z.string(),
2590
+ yAxisValueColumn: z.string()
2591
+ }),
2592
+ // Pie chart - new format (v2)
2593
+ z.object({
2594
+ type: z.literal("pie"),
2595
+ ...commonConfigProperties,
2596
+ config_version: z.literal(2),
2597
+ categoryColumn: z.string(),
2598
+ valueColumn: z.string()
2599
+ })
2600
+ ]);
2601
+ var BaseVisualizationSchema = z.object({
2602
+ id: z.number(),
2603
+ flow_data_id: z.number(),
2604
+ created_at: z.string(),
2605
+ sql: z.string(),
2606
+ bookmarked: z.boolean(),
2607
+ data_sample: z.array(z.record(z.string(), z.unknown())),
2608
+ is_sample: z.boolean(),
2609
+ data_summary: z.record(z.string(), z.unknown()),
2610
+ flow_data: MaterializationFieldsSchema.optional()
2913
2611
  });
2914
- var ChatMessages = createRoute({
2915
- method: "get",
2916
- path: "/api/v1/chat/{flowId}/messages",
2917
- operationId: "retrieveChatMessages",
2918
- request: {
2919
- headers: SupabaseHeaderSchema,
2920
- params: FlowIdParam
2921
- },
2922
- responses: {
2923
- 200: {
2924
- description: "The messages from the given flow",
2925
- content: {
2926
- "application/json": {
2927
- // we don't want to have to write a parser for Vercel AI messages
2928
- schema: z.object({ messages: z.looseObject({}).array() })
2929
- }
2930
- }
2931
- },
2932
- 404: {
2933
- content: {
2934
- "application/json": {
2935
- schema: z.object({ error: z.string() })
2936
- }
2937
- },
2938
- description: "Unable to retrieve flow with this id"
2939
- },
2940
- 500: {
2941
- description: "Something wrong happened",
2942
- content: {
2943
- "application/json": {
2944
- schema: z.object({
2945
- error: z.string()
2946
- })
2947
- }
2948
- }
2949
- }
2950
- }
2612
+ var V1VisualizationSchema = z.object({
2613
+ ...BaseVisualizationSchema.shape,
2614
+ configuration: V1VisualizationConfigurationSchema
2951
2615
  });
2952
- createRoute({
2953
- hide: true,
2954
- method: "post",
2955
- path: "/api/v1/chat/{flowId}/quick-actions",
2956
- request: {
2957
- headers: SupabaseHeaderSchema,
2958
- params: FlowIdParam,
2959
- body: {
2960
- content: {
2961
- "application/json": {
2962
- schema: z.object({
2963
- content: z.string()
2964
- })
2965
- }
2966
- }
2967
- }
2968
- },
2969
- responses: {
2970
- 200: {
2971
- description: "The quick actions for the given message",
2972
- content: {
2973
- "application/json": {
2974
- schema: QuickActionsSchema
2975
- }
2976
- }
2977
- },
2978
- 400: {
2979
- content: {
2980
- "application/json": {
2981
- schema: z.object({ error: z.string() })
2982
- }
2983
- },
2984
- description: "The provided content is invalid"
2985
- },
2986
- 404: {
2987
- content: {
2988
- "application/json": {
2989
- schema: z.object({ error: z.string() })
2990
- }
2991
- },
2992
- description: "Unable to retrieve flow with this id"
2993
- },
2994
- 500: {
2995
- description: "Something wrong happened",
2996
- content: {
2997
- "application/json": {
2998
- schema: z.object({
2999
- error: z.string()
3000
- })
3001
- }
3002
- }
3003
- }
3004
- }
2616
+ var VisualizationSchema = z.object({
2617
+ ...BaseVisualizationSchema.shape,
2618
+ configuration: VisualizationConfigurationSchema
2619
+ });
2620
+ var VisualizationDataSchema = z.array(z.record(
2621
+ z.string(),
2622
+ // any key
2623
+ z.union([
2624
+ // Date objects FIRST
2625
+ z.date(),
2626
+ z.coerce.number(),
2627
+ // Handle various data types including BigQueryDate
2628
+ z.unknown().transform((val) => formatDataValue(val).display)
2629
+ ])
2630
+ )).openapi("VisualizationData");
2631
+ var V1FrontendVisualizationSchema = V1VisualizationSchema.omit({
2632
+ sql: true,
2633
+ data_sample: true,
2634
+ is_sample: true,
2635
+ data_summary: true
2636
+ });
2637
+ var FrontendVisualizationSchema = VisualizationSchema.omit({
2638
+ sql: true,
2639
+ data_sample: true,
2640
+ is_sample: true,
2641
+ data_summary: true
2642
+ });
2643
+ var VisualizationMetadataSchema = z.object({
2644
+ wasSampled: z.boolean(),
2645
+ originalCount: z.number(),
2646
+ sampledCount: z.number()
2647
+ }).optional();
2648
+ var V1FrontendVisualizationWithDataSchema = V1FrontendVisualizationSchema.extend({
2649
+ data: VisualizationDataSchema,
2650
+ _metadata: VisualizationMetadataSchema
2651
+ });
2652
+ var FrontendVisualizationWithDataSchema = FrontendVisualizationSchema.extend({
2653
+ data: VisualizationDataSchema,
2654
+ _metadata: VisualizationMetadataSchema
3005
2655
  });
3006
2656
 
3007
2657
  // ../shared/dist/src/endpoints/visualizations.routes.js
@@ -3151,7 +2801,7 @@ var toSearchParams = ({ cursor, filters, sorting, limit }) => {
3151
2801
 
3152
2802
  // package.json
3153
2803
  var package_default = {
3154
- version: "0.5.2"};
2804
+ version: "0.5.4"};
3155
2805
  var MageMetricsChatTransport = class extends DefaultChatTransport {
3156
2806
  constructor(apiUrl, flowId, options) {
3157
2807
  super({
@@ -3429,7 +3079,7 @@ var MageMetricsClient = class {
3429
3079
  return { flowId: data.flowId };
3430
3080
  } else {
3431
3081
  const { triggerId, variables } = request;
3432
- const { data, response } = await this.internalApiClient.POST(
3082
+ const { data, error, response } = await this.internalApiClient.POST(
3433
3083
  TriggerFlow.path,
3434
3084
  {
3435
3085
  body: {
@@ -3439,17 +3089,13 @@ var MageMetricsClient = class {
3439
3089
  }
3440
3090
  }
3441
3091
  );
3442
- if (!data || data.status === "error") {
3443
- throw new ApiError(
3444
- data?.error ?? "Failed to trigger flow",
3445
- response,
3446
- {
3447
- status: response.status,
3448
- statusText: response.statusText,
3449
- url: response.url,
3450
- method: "POST"
3451
- }
3452
- );
3092
+ if (error) {
3093
+ throw new ApiError(error.error, response, {
3094
+ status: response.status,
3095
+ statusText: response.statusText,
3096
+ url: response.url,
3097
+ method: "POST"
3098
+ });
3453
3099
  }
3454
3100
  return { flowId: data.flowId };
3455
3101
  }