@magemetrics/core 0.5.3 → 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,535 +677,120 @@ 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
- }
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
+ }
1197
794
  }
1198
795
  }
1199
796
  });
@@ -1228,150 +825,20 @@ var RetrieveRecentFlows = createRoute({
1228
825
  }
1229
826
  }
1230
827
  });
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
- }
1302
- }
1303
- }
1304
- });
1305
- createRoute({
1306
- // this endpoint is deprecated and will be removed in the future
1307
- hide: true,
1308
- method: "get",
1309
- path: "/api/v1/flows/{flowId}/data",
1310
- operationId: "retrieveFlowData",
1311
- request: {
1312
- headers: SupabaseHeaderSchema,
1313
- params: FlowIdParam,
1314
- 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
- })
1323
- })
1324
- },
1325
- responses: {
1326
- 200: {
1327
- description: "The content of the flow",
1328
- content: {
1329
- "application/json": {
1330
- schema: ReportDataSchema
1331
- }
1332
- }
1333
- },
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
- 500: {
1343
- description: "Something wrong happened",
1344
- content: {
1345
- "application/json": {
1346
- schema: z.object({
1347
- error: z.string()
1348
- })
1349
- }
1350
- }
1351
- }
1352
- }
1353
- });
1354
- var GetReportData = createRoute({
1355
- method: "get",
1356
- path: "/api/v1/data-reports/{report_id}/data",
1357
- operationId: "getDataReportData",
1358
- request: {
1359
- 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
- })
828
+ var GetReportColumns = createRoute({
829
+ method: "get",
830
+ path: "/api/v1/data-reports/{report_id}/columns",
831
+ operationId: "getDataReportColumns",
832
+ request: {
833
+ headers: SupabaseHeaderSchema,
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,25 +1755,85 @@ var CreateSpeechToken = createRoute({
2362
1755
  }
2363
1756
  }
2364
1757
  });
2365
- var End2EndApiResponseSchema = z5.discriminatedUnion("status", [
2366
- z5.object({
2367
- status: z5.literal("error"),
2368
- error: z5.string()
2369
- }),
2370
- z5.object({
2371
- status: z5.literal("success"),
2372
- flowId: z5.string()
2373
- })
2374
- ]);
2375
- var TriggerFlowBody = z5.object({
2376
- triggerId: z5.string(),
2377
- variables: z5.record(z5.string(), z5.string()),
2378
- applicationName: z5.string().optional()
2379
- });
2380
- var TriggerFlow = createRoute({
1758
+ z5.discriminatedUnion("status", [
1759
+ z5.object({
1760
+ status: z5.literal("error"),
1761
+ error: z5.string()
1762
+ }),
1763
+ z5.object({
1764
+ status: z5.literal("success"),
1765
+ flowId: z5.string()
1766
+ })
1767
+ ]);
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({
1774
+ method: "post",
1775
+ path: "/api/v1/trigger-flow",
1776
+ operationId: "triggerFlow",
1777
+ request: {
1778
+ headers: SupabaseHeaderSchema,
1779
+ body: {
1780
+ required: true,
1781
+ description: "Trigger flow request body",
1782
+ content: {
1783
+ "application/json": {
1784
+ schema: TriggerFlowBody
1785
+ }
1786
+ }
1787
+ }
1788
+ },
1789
+ responses: {
1790
+ 200: {
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",
1821
+ content: {
1822
+ "application/json": {
1823
+ schema: z5.object({
1824
+ error: z5.string()
1825
+ })
1826
+ }
1827
+ }
1828
+ }
1829
+ }
1830
+ });
1831
+ createRoute({
1832
+ hide: true,
1833
+ deprecated: true,
2381
1834
  method: "post",
2382
1835
  path: "/api/v1/trigger-flow/",
2383
- operationId: "triggerFlow",
1836
+ operationId: "triggerFlowOld",
2384
1837
  request: {
2385
1838
  headers: SupabaseHeaderSchema,
2386
1839
  body: {
@@ -2398,14 +1851,19 @@ var TriggerFlow = createRoute({
2398
1851
  description: "Flow id",
2399
1852
  content: {
2400
1853
  "application/json": {
2401
- schema: End2EndApiResponseSchema
1854
+ schema: z5.object({
1855
+ status: z5.literal("success"),
1856
+ flowId: z5.string()
1857
+ })
2402
1858
  }
2403
1859
  }
2404
1860
  },
2405
1861
  400: {
2406
1862
  content: {
2407
1863
  "application/json": {
2408
- schema: z5.object({ error: z5.string() })
1864
+ schema: z5.object({
1865
+ error: z5.string()
1866
+ })
2409
1867
  }
2410
1868
  },
2411
1869
  description: "Invalid template or variable values"
@@ -2532,10 +1990,12 @@ var hashString = (value) => {
2532
1990
  };
2533
1991
 
2534
1992
  // ../shared/dist/src/schemas/canvas.js
1993
+ var DATA_REPORT_LABEL = "dataReport";
1994
+ var VISUALIZATION_LABEL = "visualization";
2535
1995
  var CanvasSchema = z.object({
2536
1996
  company_id: z.number(),
2537
1997
  created_at: z.string(),
2538
- id: z.string().uuid(),
1998
+ id: z.uuid(),
2539
1999
  title: z.string().nullable(),
2540
2000
  updated_at: z.string(),
2541
2001
  is_removed: z.boolean(),
@@ -2569,6 +2029,22 @@ var CanvasIdParam = CanvasSchema.shape.id.openapi("CanvasId", {
2569
2029
  type: "string",
2570
2030
  format: "uuid"
2571
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
+ ]);
2572
2048
 
2573
2049
  // ../shared/dist/src/endpoints/companion/canvas.routes.js
2574
2050
  var ListCanvases = createRoute({
@@ -2811,163 +2287,371 @@ var GetCanvasForFlow = createRoute({
2811
2287
  }
2812
2288
  }
2813
2289
  });
2814
- var QuickActionSchema = z.object({
2815
- label: z.string(),
2816
- 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
+ }
2817
2329
  });
2818
- var QuickActionsSchema = QuickActionSchema.array();
2819
- 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
2820
2532
  z.object({
2821
- type: z.literal("dataReport"),
2822
- flowDataId: z.number(),
2823
- flowId: z.string(),
2824
- title: z.string(),
2825
- bookmarked: z.boolean(),
2826
- answer: z.string().nullable()
2533
+ type: z.literal("line/area"),
2534
+ ...commonConfigProperties,
2535
+ ...cartesianConfigProperties
2827
2536
  }),
2537
+ // Scatter chart
2828
2538
  z.object({
2829
- type: z.literal("visualization"),
2830
- flowId: z.string(),
2831
- flowDataId: z.number(),
2832
- flowDataVisualizationId: z.number(),
2833
- title: z.string(),
2834
- bookmarked: z.boolean()
2539
+ type: z.literal("scatter"),
2540
+ ...commonConfigProperties,
2541
+ ...cartesianConfigProperties
2835
2542
  }),
2543
+ // Pie chart
2836
2544
  z.object({
2837
- type: z.literal("message")
2545
+ type: z.literal("pie"),
2546
+ ...commonConfigProperties,
2547
+ nameKey: z.string(),
2548
+ dataKey: z.string()
2838
2549
  })
2839
2550
  ]);
2840
-
2841
- // ../shared/dist/src/endpoints/companion/chat.routes.js
2842
- createRoute({
2843
- hide: true,
2844
- method: "get",
2845
- path: "/api/v1/chat/{flowId}/timeline",
2846
- operationId: "retrieveChatTimeline",
2847
- request: {
2848
- headers: SupabaseHeaderSchema,
2849
- params: FlowIdParam
2850
- },
2851
- responses: {
2852
- 200: {
2853
- description: "The timeline of generated insights for the flow",
2854
- content: {
2855
- "application/json": {
2856
- schema: FrontendTimelineItemSchema.array()
2857
- }
2858
- }
2859
- },
2860
- 404: {
2861
- content: {
2862
- "application/json": {
2863
- schema: z.object({ error: z.string() })
2864
- }
2865
- },
2866
- description: "Unable to retrieve flow with this id"
2867
- },
2868
- 500: {
2869
- description: "Something wrong happened",
2870
- content: {
2871
- "application/json": {
2872
- schema: z.object({
2873
- error: z.string()
2874
- })
2875
- }
2876
- }
2877
- }
2878
- }
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()
2879
2611
  });
2880
- var ChatMessages = createRoute({
2881
- method: "get",
2882
- path: "/api/v1/chat/{flowId}/messages",
2883
- operationId: "retrieveChatMessages",
2884
- request: {
2885
- headers: SupabaseHeaderSchema,
2886
- params: FlowIdParam
2887
- },
2888
- responses: {
2889
- 200: {
2890
- description: "The messages from the given flow",
2891
- content: {
2892
- "application/json": {
2893
- // we don't want to have to write a parser for Vercel AI messages
2894
- schema: z.object({ messages: z.looseObject({}).array() })
2895
- }
2896
- }
2897
- },
2898
- 404: {
2899
- content: {
2900
- "application/json": {
2901
- schema: z.object({ error: z.string() })
2902
- }
2903
- },
2904
- description: "Unable to retrieve flow with this id"
2905
- },
2906
- 500: {
2907
- description: "Something wrong happened",
2908
- content: {
2909
- "application/json": {
2910
- schema: z.object({
2911
- error: z.string()
2912
- })
2913
- }
2914
- }
2915
- }
2916
- }
2612
+ var V1VisualizationSchema = z.object({
2613
+ ...BaseVisualizationSchema.shape,
2614
+ configuration: V1VisualizationConfigurationSchema
2917
2615
  });
2918
- createRoute({
2919
- hide: true,
2920
- method: "post",
2921
- path: "/api/v1/chat/{flowId}/quick-actions",
2922
- request: {
2923
- headers: SupabaseHeaderSchema,
2924
- params: FlowIdParam,
2925
- body: {
2926
- content: {
2927
- "application/json": {
2928
- schema: z.object({
2929
- content: z.string()
2930
- })
2931
- }
2932
- }
2933
- }
2934
- },
2935
- responses: {
2936
- 200: {
2937
- description: "The quick actions for the given message",
2938
- content: {
2939
- "application/json": {
2940
- schema: QuickActionsSchema
2941
- }
2942
- }
2943
- },
2944
- 400: {
2945
- content: {
2946
- "application/json": {
2947
- schema: z.object({ error: z.string() })
2948
- }
2949
- },
2950
- description: "The provided content is invalid"
2951
- },
2952
- 404: {
2953
- content: {
2954
- "application/json": {
2955
- schema: z.object({ error: z.string() })
2956
- }
2957
- },
2958
- description: "Unable to retrieve flow with this id"
2959
- },
2960
- 500: {
2961
- description: "Something wrong happened",
2962
- content: {
2963
- "application/json": {
2964
- schema: z.object({
2965
- error: z.string()
2966
- })
2967
- }
2968
- }
2969
- }
2970
- }
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
2971
2655
  });
2972
2656
 
2973
2657
  // ../shared/dist/src/endpoints/visualizations.routes.js
@@ -3117,7 +2801,7 @@ var toSearchParams = ({ cursor, filters, sorting, limit }) => {
3117
2801
 
3118
2802
  // package.json
3119
2803
  var package_default = {
3120
- version: "0.5.3"};
2804
+ version: "0.5.4"};
3121
2805
  var MageMetricsChatTransport = class extends DefaultChatTransport {
3122
2806
  constructor(apiUrl, flowId, options) {
3123
2807
  super({
@@ -3395,7 +3079,7 @@ var MageMetricsClient = class {
3395
3079
  return { flowId: data.flowId };
3396
3080
  } else {
3397
3081
  const { triggerId, variables } = request;
3398
- const { data, response } = await this.internalApiClient.POST(
3082
+ const { data, error, response } = await this.internalApiClient.POST(
3399
3083
  TriggerFlow.path,
3400
3084
  {
3401
3085
  body: {
@@ -3405,17 +3089,13 @@ var MageMetricsClient = class {
3405
3089
  }
3406
3090
  }
3407
3091
  );
3408
- if (!data || data.status === "error") {
3409
- throw new ApiError(
3410
- data?.error ?? "Failed to trigger flow",
3411
- response,
3412
- {
3413
- status: response.status,
3414
- statusText: response.statusText,
3415
- url: response.url,
3416
- method: "POST"
3417
- }
3418
- );
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
+ });
3419
3099
  }
3420
3100
  return { flowId: data.flowId };
3421
3101
  }