modelfusion 0.57.0 → 0.57.2
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/core/api/ApiCallError.cjs +11 -0
- package/core/api/ApiCallError.d.ts +9 -0
- package/core/api/ApiCallError.js +11 -0
- package/core/api/LoadAPIKeyError.cjs +16 -0
- package/core/api/LoadAPIKeyError.d.ts +9 -0
- package/core/api/LoadAPIKeyError.js +12 -0
- package/core/api/RetryError.cjs +8 -0
- package/core/api/RetryError.d.ts +6 -0
- package/core/api/RetryError.js +8 -0
- package/core/api/loadApiKey.cjs +7 -2
- package/core/api/loadApiKey.js +7 -2
- package/package.json +1 -1
- package/server/fastify/FileSystemLogger.cjs +7 -6
- package/server/fastify/FileSystemLogger.d.ts +1 -1
- package/server/fastify/FileSystemLogger.js +7 -6
- package/server/fastify/modelFusionFlowPlugin.cjs +1 -0
- package/server/fastify/modelFusionFlowPlugin.js +1 -0
- package/util/JSONParseError.cjs +8 -0
- package/util/JSONParseError.d.ts +6 -0
- package/util/JSONParseError.js +8 -0
- package/util/runSafe.test.cjs +50 -0
- package/util/runSafe.test.d.ts +1 -0
- package/util/runSafe.test.js +48 -0
@@ -41,5 +41,16 @@ class ApiCallError extends Error {
|
|
41
41
|
this.cause = cause;
|
42
42
|
this.isRetryable = isRetryable;
|
43
43
|
}
|
44
|
+
toJSON() {
|
45
|
+
return {
|
46
|
+
name: this.name,
|
47
|
+
message: this.message,
|
48
|
+
url: this.url,
|
49
|
+
requestBodyValues: this.requestBodyValues,
|
50
|
+
statusCode: this.statusCode,
|
51
|
+
cause: this.cause,
|
52
|
+
isRetryable: this.isRetryable,
|
53
|
+
};
|
54
|
+
}
|
44
55
|
}
|
45
56
|
exports.ApiCallError = ApiCallError;
|
@@ -12,4 +12,13 @@ export declare class ApiCallError extends Error {
|
|
12
12
|
cause?: unknown;
|
13
13
|
isRetryable?: boolean;
|
14
14
|
});
|
15
|
+
toJSON(): {
|
16
|
+
name: string;
|
17
|
+
message: string;
|
18
|
+
url: string;
|
19
|
+
requestBodyValues: unknown;
|
20
|
+
statusCode: number;
|
21
|
+
cause: unknown;
|
22
|
+
isRetryable: boolean;
|
23
|
+
};
|
15
24
|
}
|
package/core/api/ApiCallError.js
CHANGED
@@ -38,4 +38,15 @@ export class ApiCallError extends Error {
|
|
38
38
|
this.cause = cause;
|
39
39
|
this.isRetryable = isRetryable;
|
40
40
|
}
|
41
|
+
toJSON() {
|
42
|
+
return {
|
43
|
+
name: this.name,
|
44
|
+
message: this.message,
|
45
|
+
url: this.url,
|
46
|
+
requestBodyValues: this.requestBodyValues,
|
47
|
+
statusCode: this.statusCode,
|
48
|
+
cause: this.cause,
|
49
|
+
isRetryable: this.isRetryable,
|
50
|
+
};
|
51
|
+
}
|
41
52
|
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.LoadAPIKeyError = void 0;
|
4
|
+
class LoadAPIKeyError extends Error {
|
5
|
+
constructor({ message }) {
|
6
|
+
super(message);
|
7
|
+
this.name = "LoadAPIKeyError";
|
8
|
+
}
|
9
|
+
toJSON() {
|
10
|
+
return {
|
11
|
+
name: this.name,
|
12
|
+
message: this.message,
|
13
|
+
};
|
14
|
+
}
|
15
|
+
}
|
16
|
+
exports.LoadAPIKeyError = LoadAPIKeyError;
|
package/core/api/RetryError.cjs
CHANGED
@@ -20,5 +20,13 @@ class RetryError extends Error {
|
|
20
20
|
this.reason = reason;
|
21
21
|
this.errors = errors;
|
22
22
|
}
|
23
|
+
toJSON() {
|
24
|
+
return {
|
25
|
+
name: this.name,
|
26
|
+
message: this.message,
|
27
|
+
reason: this.reason,
|
28
|
+
errors: this.errors,
|
29
|
+
};
|
30
|
+
}
|
23
31
|
}
|
24
32
|
exports.RetryError = RetryError;
|
package/core/api/RetryError.d.ts
CHANGED
package/core/api/RetryError.js
CHANGED
package/core/api/loadApiKey.cjs
CHANGED
@@ -1,16 +1,21 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.loadApiKey = void 0;
|
4
|
+
const LoadAPIKeyError_js_1 = require("./LoadAPIKeyError.cjs");
|
4
5
|
function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName = "apiKey", description, }) {
|
5
6
|
if (apiKey != null) {
|
6
7
|
return apiKey;
|
7
8
|
}
|
8
9
|
if (typeof process === "undefined") {
|
9
|
-
throw new
|
10
|
+
throw new LoadAPIKeyError_js_1.LoadAPIKeyError({
|
11
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter into the API configuration. Environment variables is not supported in this environment.`,
|
12
|
+
});
|
10
13
|
}
|
11
14
|
apiKey = process.env[environmentVariableName];
|
12
15
|
if (apiKey == null) {
|
13
|
-
throw new
|
16
|
+
throw new LoadAPIKeyError_js_1.LoadAPIKeyError({
|
17
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter into the API configuration or set it as an environment variable named ${environmentVariableName}.`,
|
18
|
+
});
|
14
19
|
}
|
15
20
|
return apiKey;
|
16
21
|
}
|
package/core/api/loadApiKey.js
CHANGED
@@ -1,13 +1,18 @@
|
|
1
|
+
import { LoadAPIKeyError } from "./LoadAPIKeyError.js";
|
1
2
|
export function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName = "apiKey", description, }) {
|
2
3
|
if (apiKey != null) {
|
3
4
|
return apiKey;
|
4
5
|
}
|
5
6
|
if (typeof process === "undefined") {
|
6
|
-
throw new
|
7
|
+
throw new LoadAPIKeyError({
|
8
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter into the API configuration. Environment variables is not supported in this environment.`,
|
9
|
+
});
|
7
10
|
}
|
8
11
|
apiKey = process.env[environmentVariableName];
|
9
12
|
if (apiKey == null) {
|
10
|
-
throw new
|
13
|
+
throw new LoadAPIKeyError({
|
14
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter into the API configuration or set it as an environment variable named ${environmentVariableName}.`,
|
15
|
+
});
|
11
16
|
}
|
12
17
|
return apiKey;
|
13
18
|
}
|
package/package.json
CHANGED
@@ -28,15 +28,16 @@ class FileSystemLogger {
|
|
28
28
|
});
|
29
29
|
}
|
30
30
|
}
|
31
|
-
async logError(
|
31
|
+
async logError({ run, error, message, }) {
|
32
32
|
const timestamp = Date.now();
|
33
33
|
try {
|
34
|
-
const logPath = this.logPath(
|
35
|
-
|
34
|
+
const logPath = this.logPath(run);
|
35
|
+
await node_fs_1.promises.mkdir(logPath, { recursive: true });
|
36
|
+
await node_fs_1.promises.writeFile((0, node_path_1.join)(logPath, `${timestamp}-error.json`), JSON.stringify({
|
36
37
|
timestamp: new Date(timestamp).toISOString(),
|
37
|
-
runId:
|
38
|
-
message
|
39
|
-
error
|
38
|
+
runId: run.runId,
|
39
|
+
message,
|
40
|
+
error,
|
40
41
|
}));
|
41
42
|
}
|
42
43
|
catch (error) {
|
@@ -25,15 +25,16 @@ export class FileSystemLogger {
|
|
25
25
|
});
|
26
26
|
}
|
27
27
|
}
|
28
|
-
async logError(
|
28
|
+
async logError({ run, error, message, }) {
|
29
29
|
const timestamp = Date.now();
|
30
30
|
try {
|
31
|
-
const logPath = this.logPath(
|
32
|
-
|
31
|
+
const logPath = this.logPath(run);
|
32
|
+
await fs.mkdir(logPath, { recursive: true });
|
33
|
+
await fs.writeFile(join(logPath, `${timestamp}-error.json`), JSON.stringify({
|
33
34
|
timestamp: new Date(timestamp).toISOString(),
|
34
|
-
runId:
|
35
|
-
message
|
36
|
-
error
|
35
|
+
runId: run.runId,
|
36
|
+
message,
|
37
|
+
error,
|
37
38
|
}));
|
38
39
|
}
|
39
40
|
catch (error) {
|
package/util/JSONParseError.cjs
CHANGED
@@ -29,5 +29,13 @@ class JSONParseError extends Error {
|
|
29
29
|
this.cause = cause;
|
30
30
|
this.valueText = valueText;
|
31
31
|
}
|
32
|
+
toJSON() {
|
33
|
+
return {
|
34
|
+
name: this.name,
|
35
|
+
message: this.message,
|
36
|
+
cause: this.cause,
|
37
|
+
valueText: this.valueText,
|
38
|
+
};
|
39
|
+
}
|
32
40
|
}
|
33
41
|
exports.JSONParseError = JSONParseError;
|
package/util/JSONParseError.d.ts
CHANGED
package/util/JSONParseError.js
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const vitest_1 = require("vitest");
|
4
|
+
const runSafe_js_1 = require("./runSafe.cjs");
|
5
|
+
(0, vitest_1.test)("catch thrown error in sync function", async () => {
|
6
|
+
const error = new Error("test error");
|
7
|
+
const result = await (0, runSafe_js_1.runSafe)(() => {
|
8
|
+
throw error;
|
9
|
+
});
|
10
|
+
(0, vitest_1.expect)(result).toEqual({
|
11
|
+
ok: false,
|
12
|
+
error,
|
13
|
+
});
|
14
|
+
});
|
15
|
+
(0, vitest_1.test)("catch thrown error in async function", async () => {
|
16
|
+
const error = new Error("test error");
|
17
|
+
const result = await (0, runSafe_js_1.runSafe)(async () => {
|
18
|
+
throw error;
|
19
|
+
});
|
20
|
+
(0, vitest_1.expect)(result).toEqual({
|
21
|
+
ok: false,
|
22
|
+
error,
|
23
|
+
});
|
24
|
+
});
|
25
|
+
(0, vitest_1.test)("catch thrown string", async () => {
|
26
|
+
const result = await (0, runSafe_js_1.runSafe)(async () => {
|
27
|
+
throw "test error";
|
28
|
+
});
|
29
|
+
(0, vitest_1.expect)(result).toEqual({
|
30
|
+
ok: false,
|
31
|
+
error: "test error",
|
32
|
+
});
|
33
|
+
});
|
34
|
+
(0, vitest_1.test)("catch rejected Promise", async () => {
|
35
|
+
const error = new Error("test error");
|
36
|
+
const result = await (0, runSafe_js_1.runSafe)(async () => {
|
37
|
+
return Promise.reject(error);
|
38
|
+
});
|
39
|
+
(0, vitest_1.expect)(result).toEqual({
|
40
|
+
ok: false,
|
41
|
+
error,
|
42
|
+
});
|
43
|
+
});
|
44
|
+
(0, vitest_1.test)("no error", async () => {
|
45
|
+
const result = await (0, runSafe_js_1.runSafe)(async () => "result");
|
46
|
+
(0, vitest_1.expect)(result).toEqual({
|
47
|
+
ok: true,
|
48
|
+
value: "result",
|
49
|
+
});
|
50
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { expect, test } from "vitest";
|
2
|
+
import { runSafe } from "./runSafe.js";
|
3
|
+
test("catch thrown error in sync function", async () => {
|
4
|
+
const error = new Error("test error");
|
5
|
+
const result = await runSafe(() => {
|
6
|
+
throw error;
|
7
|
+
});
|
8
|
+
expect(result).toEqual({
|
9
|
+
ok: false,
|
10
|
+
error,
|
11
|
+
});
|
12
|
+
});
|
13
|
+
test("catch thrown error in async function", async () => {
|
14
|
+
const error = new Error("test error");
|
15
|
+
const result = await runSafe(async () => {
|
16
|
+
throw error;
|
17
|
+
});
|
18
|
+
expect(result).toEqual({
|
19
|
+
ok: false,
|
20
|
+
error,
|
21
|
+
});
|
22
|
+
});
|
23
|
+
test("catch thrown string", async () => {
|
24
|
+
const result = await runSafe(async () => {
|
25
|
+
throw "test error";
|
26
|
+
});
|
27
|
+
expect(result).toEqual({
|
28
|
+
ok: false,
|
29
|
+
error: "test error",
|
30
|
+
});
|
31
|
+
});
|
32
|
+
test("catch rejected Promise", async () => {
|
33
|
+
const error = new Error("test error");
|
34
|
+
const result = await runSafe(async () => {
|
35
|
+
return Promise.reject(error);
|
36
|
+
});
|
37
|
+
expect(result).toEqual({
|
38
|
+
ok: false,
|
39
|
+
error,
|
40
|
+
});
|
41
|
+
});
|
42
|
+
test("no error", async () => {
|
43
|
+
const result = await runSafe(async () => "result");
|
44
|
+
expect(result).toEqual({
|
45
|
+
ok: true,
|
46
|
+
value: "result",
|
47
|
+
});
|
48
|
+
});
|