@magemetrics/core 0.11.6 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +244 -29
- package/dist/index.js +130 -43
- package/package.json +3 -3
- package/dist/index.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sha256 } from '@noble/hashes/sha2.js';
|
|
2
|
-
import
|
|
2
|
+
import z8, { z } from 'zod';
|
|
3
3
|
import { GoTrueClient } from '@supabase/auth-js';
|
|
4
4
|
import createApiClient2 from 'openapi-fetch';
|
|
5
5
|
import dayjs from 'dayjs';
|
|
@@ -58,7 +58,7 @@ var addApiKeyHeader = (apiKey) => {
|
|
|
58
58
|
|
|
59
59
|
// package.json
|
|
60
60
|
var package_default = {
|
|
61
|
-
version: "0.
|
|
61
|
+
version: "0.12.0"};
|
|
62
62
|
|
|
63
63
|
// src/core/MageMetricsEventEmitter.ts
|
|
64
64
|
var MageMetricsEventEmitter = class {
|
|
@@ -152,7 +152,7 @@ var hashString = (value) => {
|
|
|
152
152
|
return Array.from(hash).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
153
153
|
};
|
|
154
154
|
|
|
155
|
-
// ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@8.
|
|
155
|
+
// ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@8.5.0_zod@4.3.6/node_modules/@asteasolutions/zod-to-openapi/dist/index.mjs
|
|
156
156
|
function __rest(s, e) {
|
|
157
157
|
var t = {};
|
|
158
158
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -313,7 +313,7 @@ var Metadata = class {
|
|
|
313
313
|
}
|
|
314
314
|
static getOpenApiMetadata(zodSchema) {
|
|
315
315
|
const metadata = this.collectMetadata(zodSchema);
|
|
316
|
-
const _a = metadata !== null && metadata !== void 0 ? metadata : {}, rest = __rest(_a, ["_internal"]);
|
|
316
|
+
const _a = metadata !== null && metadata !== void 0 ? metadata : {}, { _internal } = _a, rest = __rest(_a, ["_internal"]);
|
|
317
317
|
return rest;
|
|
318
318
|
}
|
|
319
319
|
static getInternalMetadata(zodSchema) {
|
|
@@ -482,7 +482,7 @@ function getOpenApiConfiguration(refOrOpenapi, metadataOrOptions, options) {
|
|
|
482
482
|
};
|
|
483
483
|
}
|
|
484
484
|
|
|
485
|
-
// ../../node_modules/.pnpm/hono@4.12.
|
|
485
|
+
// ../../node_modules/.pnpm/hono@4.12.10/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
486
486
|
new Set(".\\+*[^]$()");
|
|
487
487
|
var createRoute = (routeConfig) => {
|
|
488
488
|
const route = {
|
|
@@ -856,6 +856,7 @@ var FEEDBACK_OPTIONS = [
|
|
|
856
856
|
];
|
|
857
857
|
var FeedbackSchema = z.object({
|
|
858
858
|
created_at: z.string(),
|
|
859
|
+
report_id: z.uuid(),
|
|
859
860
|
flow_data_id: z.number(),
|
|
860
861
|
helpfulness: z.enum(FEEDBACK_OPTIONS.map((option) => option.value)),
|
|
861
862
|
id: z.number()
|
|
@@ -917,7 +918,11 @@ var DatabaseFlowSchema = z.object({
|
|
|
917
918
|
title: z.string().nullable(),
|
|
918
919
|
user_id: z.string().nullable(),
|
|
919
920
|
application_id: z.number().nullable().optional(),
|
|
920
|
-
flow_steps: z.array(FlowStepSchema)
|
|
921
|
+
flow_steps: z.array(FlowStepSchema),
|
|
922
|
+
// Token usage tracking (provider-reported)
|
|
923
|
+
context_tokens: z.number().optional(),
|
|
924
|
+
acc_input_tokens: z.number().optional(),
|
|
925
|
+
acc_output_tokens: z.number().optional()
|
|
921
926
|
});
|
|
922
927
|
z.object({
|
|
923
928
|
table: z.string(),
|
|
@@ -964,7 +969,11 @@ var MaterializationFieldsSchema = z.object({
|
|
|
964
969
|
var ReportSchema = z.object({
|
|
965
970
|
created_at: z.string(),
|
|
966
971
|
flow_id: z.string(),
|
|
967
|
-
id: z.number()
|
|
972
|
+
id: z.number().openapi({
|
|
973
|
+
description: "Deprecated: use uuid.",
|
|
974
|
+
deprecated: true
|
|
975
|
+
}),
|
|
976
|
+
uuid: z.string(),
|
|
968
977
|
is_sample: z.boolean(),
|
|
969
978
|
schema: z.string(),
|
|
970
979
|
sql: z.string(),
|
|
@@ -1025,7 +1034,11 @@ var ReportExplainabilitySchema = z.object({
|
|
|
1025
1034
|
assumptions_score: z.number().nullish(),
|
|
1026
1035
|
assumptions_score_reason: z.string().nullish(),
|
|
1027
1036
|
id: z.number(),
|
|
1028
|
-
|
|
1037
|
+
report_id: z.uuid(),
|
|
1038
|
+
flow_data_id: z.number().openapi({
|
|
1039
|
+
description: "Deprecated: use report_id.",
|
|
1040
|
+
deprecated: true
|
|
1041
|
+
}),
|
|
1029
1042
|
created_at: z.string()
|
|
1030
1043
|
});
|
|
1031
1044
|
var FrontendReportExplainabilitySchema = ReportExplainabilitySchema.omit({
|
|
@@ -1196,11 +1209,34 @@ var columnsQueryParams = z.string().transform((str) => {
|
|
|
1196
1209
|
var CHAT_MAX_FILE_COUNT = 10;
|
|
1197
1210
|
var CHAT_ALLOWED_FILE_MEDIA_TYPES = /* @__PURE__ */ new Set(["application/pdf"]);
|
|
1198
1211
|
[...CHAT_ALLOWED_FILE_MEDIA_TYPES].join(",");
|
|
1212
|
+
var UploadedFileIdSchema = z.uuid();
|
|
1213
|
+
var UploadedFileSchema = z.object({
|
|
1214
|
+
uploadedFileId: UploadedFileIdSchema,
|
|
1215
|
+
filename: z.string(),
|
|
1216
|
+
mediaType: z.string(),
|
|
1217
|
+
sizeBytes: z.number().int().nonnegative()
|
|
1218
|
+
});
|
|
1219
|
+
z.object({
|
|
1220
|
+
uploadedFileId: UploadedFileIdSchema
|
|
1221
|
+
});
|
|
1222
|
+
var CreateUploadedFilePath = "/api/v1/uploaded-files";
|
|
1223
|
+
var DeleteUploadedFilePath = "/api/v1/uploaded-files/{uploadedFileId}";
|
|
1199
1224
|
|
|
1200
1225
|
// ../shared/dist/src/endpoints/companion/flows.routes.js
|
|
1201
1226
|
var FlowIdParam = z.object({ flowId: z.uuid() }).openapi("FlowId", { type: "string" });
|
|
1202
1227
|
var FlowDataIdParam = z.object({ flowDataId: z.string().pipe(z.coerce.number()) }).openapi("FlowDataId", { type: "integer" });
|
|
1203
|
-
var
|
|
1228
|
+
var parseReportId = (val, ctx) => {
|
|
1229
|
+
const num = Number(val);
|
|
1230
|
+
if (Number.isInteger(num) && num > 0)
|
|
1231
|
+
return num;
|
|
1232
|
+
const uuidResult = z.uuid().safeParse(val);
|
|
1233
|
+
if (uuidResult.success)
|
|
1234
|
+
return val;
|
|
1235
|
+
ctx.addIssue("report_id must be a positive integer or a valid UUID");
|
|
1236
|
+
return z.NEVER;
|
|
1237
|
+
};
|
|
1238
|
+
var ReportId = z.string().transform((val, ctx) => parseReportId(val, ctx)).openapi({ type: "string", description: "Numeric legacy ID or UUID" });
|
|
1239
|
+
var ReportIdFromBody = z.union([z.string(), z.number()]).transform((val, ctx) => parseReportId(String(val), ctx));
|
|
1204
1240
|
var ReportIdParam = z.object({ report_id: ReportId }).openapi("ReportId", { type: "integer" });
|
|
1205
1241
|
var CreateFlowFileSchema = z.object({
|
|
1206
1242
|
type: z.literal("file"),
|
|
@@ -1791,7 +1827,7 @@ createRoute({
|
|
|
1791
1827
|
content: {
|
|
1792
1828
|
"application/json": {
|
|
1793
1829
|
schema: z.object({
|
|
1794
|
-
flow_data_ids: z.array(
|
|
1830
|
+
flow_data_ids: z.array(ReportIdFromBody).min(1).describe("List of report IDs to refresh")
|
|
1795
1831
|
})
|
|
1796
1832
|
}
|
|
1797
1833
|
}
|
|
@@ -1840,7 +1876,7 @@ createRoute({
|
|
|
1840
1876
|
request: {
|
|
1841
1877
|
headers: SupabaseHeaderSchema,
|
|
1842
1878
|
query: z.object({
|
|
1843
|
-
ids: z.string().transform((s) => s.split(",").
|
|
1879
|
+
ids: z.string().transform((s) => s.split(",")).pipe(z.array(ReportId)).describe("Comma-separated list of reports IDs")
|
|
1844
1880
|
})
|
|
1845
1881
|
},
|
|
1846
1882
|
responses: {
|
|
@@ -1882,7 +1918,8 @@ var CreateFlow = createRoute({
|
|
|
1882
1918
|
schema: z.object({
|
|
1883
1919
|
userQuery: z.string(),
|
|
1884
1920
|
applicationName: z.string().optional(),
|
|
1885
|
-
files: z.array(CreateFlowFileSchema).max(CHAT_MAX_FILE_COUNT).optional()
|
|
1921
|
+
files: z.array(CreateFlowFileSchema).max(CHAT_MAX_FILE_COUNT).optional(),
|
|
1922
|
+
uploadedFileIds: z.array(UploadedFileIdSchema).max(CHAT_MAX_FILE_COUNT).optional()
|
|
1886
1923
|
})
|
|
1887
1924
|
}
|
|
1888
1925
|
}
|
|
@@ -1998,20 +2035,20 @@ var CreateSpeechToken = createRoute({
|
|
|
1998
2035
|
}
|
|
1999
2036
|
}
|
|
2000
2037
|
});
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
status:
|
|
2004
|
-
error:
|
|
2038
|
+
z8.discriminatedUnion("status", [
|
|
2039
|
+
z8.object({
|
|
2040
|
+
status: z8.literal("error"),
|
|
2041
|
+
error: z8.string()
|
|
2005
2042
|
}),
|
|
2006
|
-
|
|
2007
|
-
status:
|
|
2008
|
-
flowId:
|
|
2043
|
+
z8.object({
|
|
2044
|
+
status: z8.literal("success"),
|
|
2045
|
+
flowId: z8.string()
|
|
2009
2046
|
})
|
|
2010
2047
|
]);
|
|
2011
|
-
var TriggerFlowBody =
|
|
2012
|
-
triggerId:
|
|
2013
|
-
variables:
|
|
2014
|
-
applicationName:
|
|
2048
|
+
var TriggerFlowBody = z8.object({
|
|
2049
|
+
triggerId: z8.string(),
|
|
2050
|
+
variables: z8.record(z8.string(), z8.string()),
|
|
2051
|
+
applicationName: z8.string().optional()
|
|
2015
2052
|
});
|
|
2016
2053
|
var TriggerFlow = createRoute({
|
|
2017
2054
|
method: "post",
|
|
@@ -2035,9 +2072,9 @@ var TriggerFlow = createRoute({
|
|
|
2035
2072
|
description: "Flow id",
|
|
2036
2073
|
content: {
|
|
2037
2074
|
"application/json": {
|
|
2038
|
-
schema:
|
|
2039
|
-
status:
|
|
2040
|
-
flowId:
|
|
2075
|
+
schema: z8.object({
|
|
2076
|
+
status: z8.literal("success"),
|
|
2077
|
+
flowId: z8.string()
|
|
2041
2078
|
})
|
|
2042
2079
|
}
|
|
2043
2080
|
}
|
|
@@ -2045,8 +2082,8 @@ var TriggerFlow = createRoute({
|
|
|
2045
2082
|
400: {
|
|
2046
2083
|
content: {
|
|
2047
2084
|
"application/json": {
|
|
2048
|
-
schema:
|
|
2049
|
-
error:
|
|
2085
|
+
schema: z8.object({
|
|
2086
|
+
error: z8.string()
|
|
2050
2087
|
})
|
|
2051
2088
|
}
|
|
2052
2089
|
},
|
|
@@ -2055,7 +2092,7 @@ var TriggerFlow = createRoute({
|
|
|
2055
2092
|
404: {
|
|
2056
2093
|
content: {
|
|
2057
2094
|
"application/json": {
|
|
2058
|
-
schema:
|
|
2095
|
+
schema: z8.object({ error: z8.string() })
|
|
2059
2096
|
}
|
|
2060
2097
|
},
|
|
2061
2098
|
description: "Unable to retrieve trigger with this id"
|
|
@@ -2064,8 +2101,8 @@ var TriggerFlow = createRoute({
|
|
|
2064
2101
|
description: "Something wrong happened",
|
|
2065
2102
|
content: {
|
|
2066
2103
|
"application/json": {
|
|
2067
|
-
schema:
|
|
2068
|
-
error:
|
|
2104
|
+
schema: z8.object({
|
|
2105
|
+
error: z8.string()
|
|
2069
2106
|
})
|
|
2070
2107
|
}
|
|
2071
2108
|
}
|
|
@@ -2095,9 +2132,9 @@ createRoute({
|
|
|
2095
2132
|
description: "Flow id",
|
|
2096
2133
|
content: {
|
|
2097
2134
|
"application/json": {
|
|
2098
|
-
schema:
|
|
2099
|
-
status:
|
|
2100
|
-
flowId:
|
|
2135
|
+
schema: z8.object({
|
|
2136
|
+
status: z8.literal("success"),
|
|
2137
|
+
flowId: z8.string()
|
|
2101
2138
|
})
|
|
2102
2139
|
}
|
|
2103
2140
|
}
|
|
@@ -2105,8 +2142,8 @@ createRoute({
|
|
|
2105
2142
|
400: {
|
|
2106
2143
|
content: {
|
|
2107
2144
|
"application/json": {
|
|
2108
|
-
schema:
|
|
2109
|
-
error:
|
|
2145
|
+
schema: z8.object({
|
|
2146
|
+
error: z8.string()
|
|
2110
2147
|
})
|
|
2111
2148
|
}
|
|
2112
2149
|
},
|
|
@@ -2115,7 +2152,7 @@ createRoute({
|
|
|
2115
2152
|
404: {
|
|
2116
2153
|
content: {
|
|
2117
2154
|
"application/json": {
|
|
2118
|
-
schema:
|
|
2155
|
+
schema: z8.object({ error: z8.string() })
|
|
2119
2156
|
}
|
|
2120
2157
|
},
|
|
2121
2158
|
description: "Unable to retrieve trigger with this id"
|
|
@@ -2124,8 +2161,8 @@ createRoute({
|
|
|
2124
2161
|
description: "Something wrong happened",
|
|
2125
2162
|
content: {
|
|
2126
2163
|
"application/json": {
|
|
2127
|
-
schema:
|
|
2128
|
-
error:
|
|
2164
|
+
schema: z8.object({
|
|
2165
|
+
error: z8.string()
|
|
2129
2166
|
})
|
|
2130
2167
|
}
|
|
2131
2168
|
}
|
|
@@ -2844,7 +2881,12 @@ var VisualizationConfigurationSchema = z.discriminatedUnion("type", [
|
|
|
2844
2881
|
})
|
|
2845
2882
|
]);
|
|
2846
2883
|
var BaseVisualizationSchema = z.object({
|
|
2847
|
-
id: z.number()
|
|
2884
|
+
id: z.number().openapi({
|
|
2885
|
+
description: "Deprecated: use uuid.",
|
|
2886
|
+
deprecated: true
|
|
2887
|
+
}),
|
|
2888
|
+
uuid: z.string(),
|
|
2889
|
+
report_uuid: z.string(),
|
|
2848
2890
|
flow_data_id: z.number(),
|
|
2849
2891
|
created_at: z.string(),
|
|
2850
2892
|
sql: z.string(),
|
|
@@ -3234,7 +3276,7 @@ var MageMetricsClient = class {
|
|
|
3234
3276
|
body: {
|
|
3235
3277
|
userQuery: request.query,
|
|
3236
3278
|
applicationName: this.config.applicationName,
|
|
3237
|
-
|
|
3279
|
+
uploadedFileIds: request.uploadedFileIds
|
|
3238
3280
|
}
|
|
3239
3281
|
}
|
|
3240
3282
|
);
|
|
@@ -3270,6 +3312,53 @@ var MageMetricsClient = class {
|
|
|
3270
3312
|
return { flowId: data.flowId };
|
|
3271
3313
|
}
|
|
3272
3314
|
},
|
|
3315
|
+
uploadFile: async (file, flowId) => {
|
|
3316
|
+
await this.waitForAuth();
|
|
3317
|
+
const formData = new FormData();
|
|
3318
|
+
formData.append("file", file);
|
|
3319
|
+
const url = new URL(`${this.config.apiUrl}${CreateUploadedFilePath}`);
|
|
3320
|
+
if (flowId) {
|
|
3321
|
+
url.searchParams.set("flowId", flowId);
|
|
3322
|
+
}
|
|
3323
|
+
const response = await fetch(url, {
|
|
3324
|
+
method: "POST",
|
|
3325
|
+
headers: await this.getHeaders(),
|
|
3326
|
+
body: formData
|
|
3327
|
+
});
|
|
3328
|
+
const data = await response.json();
|
|
3329
|
+
if (!response.ok) {
|
|
3330
|
+
const error = typeof data === "object" && data !== null && "error" in data && typeof data.error === "string" ? data.error : "File upload failed";
|
|
3331
|
+
throw new ApiError(error, response, {
|
|
3332
|
+
status: response.status,
|
|
3333
|
+
statusText: response.statusText,
|
|
3334
|
+
url: response.url,
|
|
3335
|
+
method: "POST"
|
|
3336
|
+
});
|
|
3337
|
+
}
|
|
3338
|
+
return UploadedFileSchema.parse(data);
|
|
3339
|
+
},
|
|
3340
|
+
deleteUploadedFile: async (uploadedFileId) => {
|
|
3341
|
+
await this.waitForAuth();
|
|
3342
|
+
const path = DeleteUploadedFilePath.replace(
|
|
3343
|
+
"{uploadedFileId}",
|
|
3344
|
+
uploadedFileId
|
|
3345
|
+
);
|
|
3346
|
+
const response = await fetch(`${this.config.apiUrl}${path}`, {
|
|
3347
|
+
method: "DELETE",
|
|
3348
|
+
headers: await this.getHeaders()
|
|
3349
|
+
});
|
|
3350
|
+
if (response.ok) {
|
|
3351
|
+
return;
|
|
3352
|
+
}
|
|
3353
|
+
const data = await response.json().catch(() => null);
|
|
3354
|
+
const error = typeof data === "object" && data !== null && "error" in data && typeof data.error === "string" ? data.error : "Failed to delete uploaded file";
|
|
3355
|
+
throw new ApiError(error, response, {
|
|
3356
|
+
status: response.status,
|
|
3357
|
+
statusText: response.statusText,
|
|
3358
|
+
url: response.url,
|
|
3359
|
+
method: "DELETE"
|
|
3360
|
+
});
|
|
3361
|
+
},
|
|
3273
3362
|
canvas: {
|
|
3274
3363
|
list: async (query) => {
|
|
3275
3364
|
await this.waitForAuth();
|
|
@@ -3569,5 +3658,3 @@ var MageMetricsClient = class {
|
|
|
3569
3658
|
};
|
|
3570
3659
|
|
|
3571
3660
|
export { BrowserStorageAdapter, CHECK_KEY, DirectAuthProvider, ExternalAuthProvider, MageMetricsClient, MageMetricsEventEmitter, MemoryStorageAdapter, TOKEN_STORAGE_KEY, getPublicApiClient };
|
|
3572
|
-
//# sourceMappingURL=index.js.map
|
|
3573
|
-
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magemetrics/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.0",
|
|
5
5
|
"description": "MageMetrics client library",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"@noble/hashes": "^2.0.1",
|
|
37
37
|
"@supabase/auth-js": "^2.97.0",
|
|
38
38
|
"@xyflow/system": "^0.0.75",
|
|
39
|
-
"ai": "6.0.
|
|
39
|
+
"ai": "6.0.145",
|
|
40
40
|
"dayjs": "^1.11.20",
|
|
41
41
|
"openapi-fetch": "^0.17.0",
|
|
42
|
-
"type-fest": "^5.
|
|
42
|
+
"type-fest": "^5.5.0",
|
|
43
43
|
"zod": "^4.3.6"
|
|
44
44
|
}
|
|
45
45
|
}
|