modelfusion 0.57.1 → 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.
@@ -1,19 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadApiKey = void 0;
4
- const LoadAPIKeyError_1 = require("./LoadAPIKeyError");
4
+ const LoadAPIKeyError_js_1 = require("./LoadAPIKeyError.cjs");
5
5
  function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName = "apiKey", description, }) {
6
6
  if (apiKey != null) {
7
7
  return apiKey;
8
8
  }
9
9
  if (typeof process === "undefined") {
10
- throw new LoadAPIKeyError_1.LoadAPIKeyError({
10
+ throw new LoadAPIKeyError_js_1.LoadAPIKeyError({
11
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
12
  });
13
13
  }
14
14
  apiKey = process.env[environmentVariableName];
15
15
  if (apiKey == null) {
16
- throw new LoadAPIKeyError_1.LoadAPIKeyError({
16
+ throw new LoadAPIKeyError_js_1.LoadAPIKeyError({
17
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
18
  });
19
19
  }
@@ -1,4 +1,4 @@
1
- import { LoadAPIKeyError } from "./LoadAPIKeyError";
1
+ import { LoadAPIKeyError } from "./LoadAPIKeyError.js";
2
2
  export function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName = "apiKey", description, }) {
3
3
  if (apiKey != null) {
4
4
  return apiKey;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modelfusion",
3
3
  "description": "Build multimodal applications, chatbots, and agents with JavaScript and TypeScript.",
4
- "version": "0.57.1",
4
+ "version": "0.57.2",
5
5
  "author": "Lars Grammel",
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -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
+ });