@magemetrics/core 0.0.60 → 0.1.1
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 +835 -20
- package/dist/index.js +22 -61
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import utc from 'dayjs/plugin/utc.js';
|
|
|
7
7
|
import { GoTrueClient } from '@supabase/auth-js';
|
|
8
8
|
import createApiClient from 'openapi-fetch';
|
|
9
9
|
import { sha256 } from '@noble/hashes/sha2';
|
|
10
|
+
import { DefaultChatTransport } from 'ai';
|
|
10
11
|
|
|
11
12
|
// ../shared/dist/src/api/client/middleware.js
|
|
12
13
|
var HEADER_CLIENT_VERSION = "X-Client-Version";
|
|
@@ -53,7 +54,7 @@ var addApiKeyHeader = (apiKey) => {
|
|
|
53
54
|
};
|
|
54
55
|
};
|
|
55
56
|
|
|
56
|
-
// ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@7.3.
|
|
57
|
+
// ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@7.3.4_zod@3.25.76/node_modules/@asteasolutions/zod-to-openapi/dist/index.mjs
|
|
57
58
|
function __rest(s, e) {
|
|
58
59
|
var t = {};
|
|
59
60
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -93,13 +94,13 @@ function extendZodWithOpenApi(zod) {
|
|
|
93
94
|
if (isZodType(this, "ZodObject")) {
|
|
94
95
|
const originalExtend = this.extend;
|
|
95
96
|
result.extend = function(...args) {
|
|
96
|
-
var _a2, _b2, _c2, _d2, _e2, _f2;
|
|
97
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2;
|
|
97
98
|
const extendedResult = originalExtend.apply(this, args);
|
|
98
99
|
extendedResult._def.openapi = {
|
|
99
100
|
_internal: {
|
|
100
|
-
extendedFrom: ((_b2 = (_a2 = this._def.openapi) === null || _a2 === void 0 ? void 0 : _a2._internal) === null || _b2 === void 0 ? void 0 : _b2.refId) ? { refId: (_d2 = (_c2 = this._def.openapi) === null || _c2 === void 0 ? void 0 : _c2._internal) === null || _d2 === void 0 ? void 0 : _d2.refId, schema: this } : (_e2 = this._def.openapi) === null || _e2 === void 0 ? void 0 : _e2._internal.extendedFrom
|
|
101
|
+
extendedFrom: ((_b2 = (_a2 = this._def.openapi) === null || _a2 === void 0 ? void 0 : _a2._internal) === null || _b2 === void 0 ? void 0 : _b2.refId) ? { refId: (_d2 = (_c2 = this._def.openapi) === null || _c2 === void 0 ? void 0 : _c2._internal) === null || _d2 === void 0 ? void 0 : _d2.refId, schema: this } : (_f2 = (_e2 = this._def.openapi) === null || _e2 === void 0 ? void 0 : _e2._internal) === null || _f2 === void 0 ? void 0 : _f2.extendedFrom
|
|
101
102
|
},
|
|
102
|
-
metadata: (
|
|
103
|
+
metadata: (_g2 = extendedResult._def.openapi) === null || _g2 === void 0 ? void 0 : _g2.metadata
|
|
103
104
|
};
|
|
104
105
|
return extendedResult;
|
|
105
106
|
};
|
|
@@ -2177,7 +2178,7 @@ var End2EndApiResponseSchema = z.discriminatedUnion("status", [
|
|
|
2177
2178
|
flowId: z.string()
|
|
2178
2179
|
})
|
|
2179
2180
|
]);
|
|
2180
|
-
|
|
2181
|
+
createRoute({
|
|
2181
2182
|
method: "post",
|
|
2182
2183
|
path: "/api/v1/end2end",
|
|
2183
2184
|
operationId: "runEnd2EndFlow",
|
|
@@ -2369,7 +2370,7 @@ var hashString = (value) => {
|
|
|
2369
2370
|
|
|
2370
2371
|
// package.json
|
|
2371
2372
|
var package_default = {
|
|
2372
|
-
version: "0.
|
|
2373
|
+
version: "0.1.1"};
|
|
2373
2374
|
|
|
2374
2375
|
// src/core/MageMetricsEventEmitter.ts
|
|
2375
2376
|
var MageMetricsEventEmitter = class {
|
|
@@ -2419,6 +2420,20 @@ var CHECK_KEY = "mm-ai-check-key";
|
|
|
2419
2420
|
|
|
2420
2421
|
// src/core/MageMetricsClient.ts
|
|
2421
2422
|
var MM_CLIENT_VERSION = package_default.version;
|
|
2423
|
+
var MageMetricsChatTransport = class extends DefaultChatTransport {
|
|
2424
|
+
constructor(apiUrl, flowId, options) {
|
|
2425
|
+
super({
|
|
2426
|
+
...options,
|
|
2427
|
+
headers: {
|
|
2428
|
+
[HEADER_CLIENT_VERSION]: MM_CLIENT_VERSION
|
|
2429
|
+
},
|
|
2430
|
+
api: `${apiUrl}/api/v1/chat/${flowId}`,
|
|
2431
|
+
prepareSendMessagesRequest({ messages, id: chatId }) {
|
|
2432
|
+
return { body: { message: messages.at(-1), id: chatId } };
|
|
2433
|
+
}
|
|
2434
|
+
});
|
|
2435
|
+
}
|
|
2436
|
+
};
|
|
2422
2437
|
var getPublicApiClient = (apiUrl, apiKey) => {
|
|
2423
2438
|
const client = createApiClient({ baseUrl: apiUrl });
|
|
2424
2439
|
client.use(throwOnError);
|
|
@@ -2537,60 +2552,6 @@ var MageMetricsClient = class {
|
|
|
2537
2552
|
}
|
|
2538
2553
|
return data;
|
|
2539
2554
|
},
|
|
2540
|
-
/**
|
|
2541
|
-
* @deprecated Use `createFlow` instead.
|
|
2542
|
-
* @param request the user request
|
|
2543
|
-
* @returns the id of the created flow
|
|
2544
|
-
*/
|
|
2545
|
-
startFlow: async (request) => {
|
|
2546
|
-
await this.waitForAuth();
|
|
2547
|
-
if (!this.internalApiClient) throw new Error("API client not ready");
|
|
2548
|
-
if ("query" in request) {
|
|
2549
|
-
const { data, response } = await this.internalApiClient.POST(
|
|
2550
|
-
RunEnd2EndFlowRoute.path,
|
|
2551
|
-
{
|
|
2552
|
-
body: {
|
|
2553
|
-
userQuery: request.query,
|
|
2554
|
-
isNewAnalysisGoal: true,
|
|
2555
|
-
difficultyLevel: "complex"
|
|
2556
|
-
}
|
|
2557
|
-
}
|
|
2558
|
-
);
|
|
2559
|
-
if (!data || data.status === "error") {
|
|
2560
|
-
throw new ApiError(data?.error ?? "Failed to start flow", response, {
|
|
2561
|
-
status: response.status,
|
|
2562
|
-
statusText: response.statusText,
|
|
2563
|
-
url: response.url,
|
|
2564
|
-
method: "POST"
|
|
2565
|
-
});
|
|
2566
|
-
}
|
|
2567
|
-
return data.flowId;
|
|
2568
|
-
} else {
|
|
2569
|
-
const { triggerId, variables } = request;
|
|
2570
|
-
const { data, response } = await this.internalApiClient.POST(
|
|
2571
|
-
TriggerFlow.path,
|
|
2572
|
-
{
|
|
2573
|
-
body: {
|
|
2574
|
-
triggerId,
|
|
2575
|
-
variables
|
|
2576
|
-
}
|
|
2577
|
-
}
|
|
2578
|
-
);
|
|
2579
|
-
if (!data || data.status === "error") {
|
|
2580
|
-
throw new ApiError(
|
|
2581
|
-
data?.error ?? "Failed to trigger flow",
|
|
2582
|
-
response,
|
|
2583
|
-
{
|
|
2584
|
-
status: response.status,
|
|
2585
|
-
statusText: response.statusText,
|
|
2586
|
-
url: response.url,
|
|
2587
|
-
method: "POST"
|
|
2588
|
-
}
|
|
2589
|
-
);
|
|
2590
|
-
}
|
|
2591
|
-
return data.flowId;
|
|
2592
|
-
}
|
|
2593
|
-
},
|
|
2594
2555
|
createFlow: async (request) => {
|
|
2595
2556
|
await this.waitForAuth();
|
|
2596
2557
|
if (!this.internalApiClient) throw new Error("API client not ready");
|
|
@@ -2918,6 +2879,6 @@ var MageMetricsClient = class {
|
|
|
2918
2879
|
}
|
|
2919
2880
|
};
|
|
2920
2881
|
|
|
2921
|
-
export { BrowserStorageAdapter, CHECK_KEY, MageMetricsClient, MageMetricsEventEmitter, MemoryStorageAdapter, TOKEN_STORAGE_KEY, getPublicApiClient };
|
|
2882
|
+
export { BrowserStorageAdapter, CHECK_KEY, MageMetricsChatTransport, MageMetricsClient, MageMetricsEventEmitter, MemoryStorageAdapter, TOKEN_STORAGE_KEY, getPublicApiClient };
|
|
2922
2883
|
//# sourceMappingURL=index.js.map
|
|
2923
2884
|
//# sourceMappingURL=index.js.map
|