modelfusion 0.90.0 → 0.92.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.
Files changed (57) hide show
  1. package/README.md +9 -4
  2. package/core/FunctionOptions.d.ts +3 -11
  3. package/core/LogFormat.cjs +10 -0
  4. package/core/LogFormat.d.ts +9 -0
  5. package/core/LogFormat.js +9 -0
  6. package/core/ModelFusionConfiguration.cjs +21 -0
  7. package/core/ModelFusionConfiguration.d.ts +6 -0
  8. package/core/ModelFusionConfiguration.js +14 -0
  9. package/core/api/ApiCallError.cjs +9 -1
  10. package/core/api/ApiCallError.d.ts +4 -1
  11. package/core/api/ApiCallError.js +9 -1
  12. package/core/api/RetryError.cjs +12 -2
  13. package/core/api/RetryError.d.ts +3 -1
  14. package/core/api/RetryError.js +12 -2
  15. package/core/api/postToApi.cjs +8 -1
  16. package/core/api/postToApi.d.ts +1 -0
  17. package/core/api/postToApi.js +8 -1
  18. package/core/executeFunctionCall.cjs +4 -4
  19. package/core/executeFunctionCall.js +4 -4
  20. package/core/getFunctionCallLogger.cjs +21 -5
  21. package/core/getFunctionCallLogger.js +21 -5
  22. package/core/index.cjs +15 -2
  23. package/core/index.d.ts +2 -2
  24. package/core/index.js +2 -2
  25. package/core/schema/JSONParseError.cjs +2 -7
  26. package/core/schema/JSONParseError.d.ts +1 -2
  27. package/core/schema/JSONParseError.js +2 -7
  28. package/model-function/executeStandardCall.cjs +4 -4
  29. package/model-function/executeStandardCall.js +4 -4
  30. package/model-function/executeStreamCall.cjs +4 -4
  31. package/model-function/executeStreamCall.js +4 -4
  32. package/model-provider/index.cjs +1 -0
  33. package/model-provider/index.d.ts +1 -0
  34. package/model-provider/index.js +1 -0
  35. package/model-provider/openai/chat/OpenAIChatStreamIterable.cjs +1 -1
  36. package/model-provider/openai/chat/OpenAIChatStreamIterable.js +1 -1
  37. package/model-provider/whispercpp/WhisperCppApiConfiguration.cjs +15 -0
  38. package/model-provider/whispercpp/WhisperCppApiConfiguration.d.ts +11 -0
  39. package/model-provider/whispercpp/WhisperCppApiConfiguration.js +11 -0
  40. package/model-provider/whispercpp/WhisperCppFacade.cjs +13 -0
  41. package/model-provider/whispercpp/WhisperCppFacade.d.ts +4 -0
  42. package/model-provider/whispercpp/WhisperCppFacade.js +8 -0
  43. package/model-provider/whispercpp/WhisperCppTranscriptionModel.cjs +117 -0
  44. package/model-provider/whispercpp/WhisperCppTranscriptionModel.d.ts +29 -0
  45. package/model-provider/whispercpp/WhisperCppTranscriptionModel.js +113 -0
  46. package/model-provider/whispercpp/index.cjs +32 -0
  47. package/model-provider/whispercpp/index.d.ts +3 -0
  48. package/model-provider/whispercpp/index.js +3 -0
  49. package/package.json +1 -1
  50. package/tool/execute-tool/executeTool.cjs +3 -4
  51. package/tool/execute-tool/executeTool.js +3 -4
  52. package/core/GlobalFunctionLogging.cjs +0 -12
  53. package/core/GlobalFunctionLogging.d.ts +0 -3
  54. package/core/GlobalFunctionLogging.js +0 -7
  55. package/core/GlobalFunctionObservers.cjs +0 -12
  56. package/core/GlobalFunctionObservers.d.ts +0 -3
  57. package/core/GlobalFunctionObservers.js +0 -7
package/README.md CHANGED
@@ -23,11 +23,11 @@
23
23
  - **Resilience and Robustness**: ModelFusion ensures seamless operation through automatic retries, throttling, and error handling mechanisms.
24
24
  - **Server**: ModelFusion provides a Fastify plugin that exposes a ModelFusion flow as a REST endpoint that uses server-sent events.
25
25
 
26
- ## Quick Install
27
-
28
26
  > [!NOTE]
29
27
  > ModelFusion is in its initial development phase. The main API is now mostly stable, but until version 1.0 there may be breaking changes. Feedback and suggestions are welcome.
30
28
 
29
+ ## Quick Install
30
+
31
31
  ```sh
32
32
  npm install modelfusion
33
33
  ```
@@ -40,6 +40,9 @@ Or use a template:
40
40
 
41
41
  ## Usage Examples
42
42
 
43
+ > [!TIP]
44
+ > The basic examples are a great way to get started and to explore in parallel with the [documentation](https://modelfusion.dev/). You can find them in the [examples/basic](https://github.com/lgrammel/modelfusion/tree/main/examples/basic) folder.
45
+
43
46
  You can provide API keys for the different [integrations](https://modelfusion.dev/integration/model-provider/) using environment variables (e.g., `OPENAI_API_KEY`) or pass them into the model constructors as options.
44
47
 
45
48
  ### [Generate Text](https://modelfusion.dev/guide/function/generate-text)
@@ -182,7 +185,7 @@ const transcription = await generateTranscription(
182
185
  );
183
186
  ```
184
187
 
185
- Providers: [OpenAI (Whisper)](https://modelfusion.dev/integration/model-provider/openai)
188
+ Providers: [OpenAI (Whisper)](https://modelfusion.dev/integration/model-provider/openai), [Whisper.cpp](https://modelfusion.dev/integration/model-provider/whispercpp)
186
189
 
187
190
  ### [Generate Structure](https://modelfusion.dev/guide/function/generate-structure#generatestructure)
188
191
 
@@ -633,7 +636,9 @@ ModelFusion provides an [observer framework](https://modelfusion.dev/guide/util/
633
636
  #### Global Logging Example
634
637
 
635
638
  ```ts
636
- setGlobalFunctionLogging("detailed-object"); // log full events
639
+ import { modelfusion } from "modelfusion";
640
+
641
+ modelfusion.setLogFormat("detailed-object"); // log full events
637
642
  ```
638
643
 
639
644
  ### [Server](https://modelfusion.dev/guide/server/)
@@ -1,5 +1,6 @@
1
- import { Run } from "./Run.js";
2
1
  import { FunctionObserver } from "./FunctionObserver.js";
2
+ import { LogFormat } from "./LogFormat.js";
3
+ import { Run } from "./Run.js";
3
4
  /**
4
5
  * Additional settings for ModelFusion functions.
5
6
  */
@@ -12,7 +13,7 @@ export type FunctionOptions = {
12
13
  * Optional logging to use for the function. Logs are sent to the console.
13
14
  * Overrides the global function logging setting.
14
15
  */
15
- logging?: FunctionLogging;
16
+ logging?: LogFormat;
16
17
  /**
17
18
  * Optional observers that are called when the function is invoked.
18
19
  */
@@ -27,12 +28,3 @@ export type FunctionOptions = {
27
28
  */
28
29
  parentCallId?: string | undefined;
29
30
  };
30
- /**
31
- * The logging to use for the function. Logs are sent to the console.
32
- *
33
- * - `off` or undefined: No logging.
34
- * - `basic-text`: Log the timestamp and the type of event as a single line of text.
35
- * - `detailed-object`: Log everything except the original response as an object to the console.
36
- * - `detailed-json`: Log everything except the original response as a JSON string to the console.
37
- */
38
- export type FunctionLogging = undefined | "off" | "basic-text" | "detailed-object" | "detailed-json";
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /**
3
+ * The logging output format to use, e.g. for functions. Logs are sent to the console.
4
+ *
5
+ * - `off` or undefined: No logging.
6
+ * - `basic-text`: Log the timestamp and the type of event as a single line of text.
7
+ * - `detailed-object`: Log everything except the original response as an object to the console.
8
+ * - `detailed-json`: Log everything except the original response as a JSON string to the console.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The logging output format to use, e.g. for functions. Logs are sent to the console.
3
+ *
4
+ * - `off` or undefined: No logging.
5
+ * - `basic-text`: Log the timestamp and the type of event as a single line of text.
6
+ * - `detailed-object`: Log everything except the original response as an object to the console.
7
+ * - `detailed-json`: Log everything except the original response as a JSON string to the console.
8
+ */
9
+ export type LogFormat = undefined | "off" | "basic-text" | "detailed-object" | "detailed-json";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The logging output format to use, e.g. for functions. Logs are sent to the console.
3
+ *
4
+ * - `off` or undefined: No logging.
5
+ * - `basic-text`: Log the timestamp and the type of event as a single line of text.
6
+ * - `detailed-object`: Log everything except the original response as an object to the console.
7
+ * - `detailed-json`: Log everything except the original response as a JSON string to the console.
8
+ */
9
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLogFormat = exports.setLogFormat = exports.getFunctionObservers = exports.setFunctionObservers = void 0;
4
+ let globalLogFormat = undefined;
5
+ let globalFunctionObservers = [];
6
+ function setFunctionObservers(functionObservers) {
7
+ globalFunctionObservers = functionObservers;
8
+ }
9
+ exports.setFunctionObservers = setFunctionObservers;
10
+ function getFunctionObservers() {
11
+ return globalFunctionObservers;
12
+ }
13
+ exports.getFunctionObservers = getFunctionObservers;
14
+ function setLogFormat(format) {
15
+ globalLogFormat = format;
16
+ }
17
+ exports.setLogFormat = setLogFormat;
18
+ function getLogFormat() {
19
+ return globalLogFormat;
20
+ }
21
+ exports.getLogFormat = getLogFormat;
@@ -0,0 +1,6 @@
1
+ import { FunctionObserver } from "./FunctionObserver.js";
2
+ import { LogFormat } from "./LogFormat.js";
3
+ export declare function setFunctionObservers(functionObservers: FunctionObserver[]): void;
4
+ export declare function getFunctionObservers(): FunctionObserver[];
5
+ export declare function setLogFormat(format: LogFormat): void;
6
+ export declare function getLogFormat(): LogFormat;
@@ -0,0 +1,14 @@
1
+ let globalLogFormat = undefined;
2
+ let globalFunctionObservers = [];
3
+ export function setFunctionObservers(functionObservers) {
4
+ globalFunctionObservers = functionObservers;
5
+ }
6
+ export function getFunctionObservers() {
7
+ return globalFunctionObservers;
8
+ }
9
+ export function setLogFormat(format) {
10
+ globalLogFormat = format;
11
+ }
12
+ export function getLogFormat() {
13
+ return globalLogFormat;
14
+ }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApiCallError = void 0;
4
4
  class ApiCallError extends Error {
5
- constructor({ message, url, requestBodyValues, statusCode, cause, isRetryable = statusCode != null &&
5
+ constructor({ message, url, requestBodyValues, statusCode, responseBody, cause, isRetryable = statusCode != null &&
6
6
  (statusCode === 429 || statusCode >= 500), }) {
7
7
  super(message);
8
8
  Object.defineProperty(this, "url", {
@@ -23,6 +23,12 @@ class ApiCallError extends Error {
23
23
  writable: true,
24
24
  value: void 0
25
25
  });
26
+ Object.defineProperty(this, "responseBody", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: void 0
31
+ });
26
32
  Object.defineProperty(this, "cause", {
27
33
  enumerable: true,
28
34
  configurable: true,
@@ -39,6 +45,7 @@ class ApiCallError extends Error {
39
45
  this.url = url;
40
46
  this.requestBodyValues = requestBodyValues;
41
47
  this.statusCode = statusCode;
48
+ this.responseBody = responseBody;
42
49
  this.cause = cause;
43
50
  this.isRetryable = isRetryable;
44
51
  }
@@ -49,6 +56,7 @@ class ApiCallError extends Error {
49
56
  url: this.url,
50
57
  requestBodyValues: this.requestBodyValues,
51
58
  statusCode: this.statusCode,
59
+ responseBody: this.responseBody,
52
60
  cause: this.cause,
53
61
  isRetryable: this.isRetryable,
54
62
  };
@@ -2,13 +2,15 @@ export declare class ApiCallError extends Error {
2
2
  readonly url: string;
3
3
  readonly requestBodyValues: unknown;
4
4
  readonly statusCode?: number;
5
+ readonly responseBody?: string;
5
6
  readonly cause?: unknown;
6
7
  readonly isRetryable: boolean;
7
- constructor({ message, url, requestBodyValues, statusCode, cause, isRetryable, }: {
8
+ constructor({ message, url, requestBodyValues, statusCode, responseBody, cause, isRetryable, }: {
8
9
  message: string;
9
10
  url: string;
10
11
  requestBodyValues: unknown;
11
12
  statusCode?: number;
13
+ responseBody?: string;
12
14
  cause?: unknown;
13
15
  isRetryable?: boolean;
14
16
  });
@@ -18,6 +20,7 @@ export declare class ApiCallError extends Error {
18
20
  url: string;
19
21
  requestBodyValues: unknown;
20
22
  statusCode: number | undefined;
23
+ responseBody: string | undefined;
21
24
  cause: unknown;
22
25
  isRetryable: boolean;
23
26
  };
@@ -1,5 +1,5 @@
1
1
  export class ApiCallError extends Error {
2
- constructor({ message, url, requestBodyValues, statusCode, cause, isRetryable = statusCode != null &&
2
+ constructor({ message, url, requestBodyValues, statusCode, responseBody, cause, isRetryable = statusCode != null &&
3
3
  (statusCode === 429 || statusCode >= 500), }) {
4
4
  super(message);
5
5
  Object.defineProperty(this, "url", {
@@ -20,6 +20,12 @@ export class ApiCallError extends Error {
20
20
  writable: true,
21
21
  value: void 0
22
22
  });
23
+ Object.defineProperty(this, "responseBody", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: void 0
28
+ });
23
29
  Object.defineProperty(this, "cause", {
24
30
  enumerable: true,
25
31
  configurable: true,
@@ -36,6 +42,7 @@ export class ApiCallError extends Error {
36
42
  this.url = url;
37
43
  this.requestBodyValues = requestBodyValues;
38
44
  this.statusCode = statusCode;
45
+ this.responseBody = responseBody;
39
46
  this.cause = cause;
40
47
  this.isRetryable = isRetryable;
41
48
  }
@@ -46,6 +53,7 @@ export class ApiCallError extends Error {
46
53
  url: this.url,
47
54
  requestBodyValues: this.requestBodyValues,
48
55
  statusCode: this.statusCode,
56
+ responseBody: this.responseBody,
49
57
  cause: this.cause,
50
58
  isRetryable: this.isRetryable,
51
59
  };
@@ -4,13 +4,20 @@ exports.RetryError = void 0;
4
4
  class RetryError extends Error {
5
5
  constructor({ message, reason, errors, }) {
6
6
  super(message);
7
- Object.defineProperty(this, "errors", {
7
+ // note: property order determines debugging output
8
+ Object.defineProperty(this, "reason", {
8
9
  enumerable: true,
9
10
  configurable: true,
10
11
  writable: true,
11
12
  value: void 0
12
13
  });
13
- Object.defineProperty(this, "reason", {
14
+ Object.defineProperty(this, "lastError", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: void 0
19
+ });
20
+ Object.defineProperty(this, "errors", {
14
21
  enumerable: true,
15
22
  configurable: true,
16
23
  writable: true,
@@ -19,12 +26,15 @@ class RetryError extends Error {
19
26
  this.name = "RetryError";
20
27
  this.reason = reason;
21
28
  this.errors = errors;
29
+ // separate our last error to make debugging via log easier:
30
+ this.lastError = errors[errors.length - 1];
22
31
  }
23
32
  toJSON() {
24
33
  return {
25
34
  name: this.name,
26
35
  message: this.message,
27
36
  reason: this.reason,
37
+ lastError: this.lastError,
28
38
  errors: this.errors,
29
39
  };
30
40
  }
@@ -1,7 +1,8 @@
1
1
  export type RetryErrorReason = "maxTriesExceeded" | "errorNotRetryable" | "abort";
2
2
  export declare class RetryError extends Error {
3
- readonly errors: Array<unknown>;
4
3
  readonly reason: RetryErrorReason;
4
+ readonly lastError: unknown;
5
+ readonly errors: Array<unknown>;
5
6
  constructor({ message, reason, errors, }: {
6
7
  message: string;
7
8
  reason: RetryErrorReason;
@@ -11,6 +12,7 @@ export declare class RetryError extends Error {
11
12
  name: string;
12
13
  message: string;
13
14
  reason: RetryErrorReason;
15
+ lastError: unknown;
14
16
  errors: unknown[];
15
17
  };
16
18
  }
@@ -1,13 +1,20 @@
1
1
  export class RetryError extends Error {
2
2
  constructor({ message, reason, errors, }) {
3
3
  super(message);
4
- Object.defineProperty(this, "errors", {
4
+ // note: property order determines debugging output
5
+ Object.defineProperty(this, "reason", {
5
6
  enumerable: true,
6
7
  configurable: true,
7
8
  writable: true,
8
9
  value: void 0
9
10
  });
10
- Object.defineProperty(this, "reason", {
11
+ Object.defineProperty(this, "lastError", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: void 0
16
+ });
17
+ Object.defineProperty(this, "errors", {
11
18
  enumerable: true,
12
19
  configurable: true,
13
20
  writable: true,
@@ -16,12 +23,15 @@ export class RetryError extends Error {
16
23
  this.name = "RetryError";
17
24
  this.reason = reason;
18
25
  this.errors = errors;
26
+ // separate our last error to make debugging via log easier:
27
+ this.lastError = errors[errors.length - 1];
19
28
  }
20
29
  toJSON() {
21
30
  return {
22
31
  name: this.name,
23
32
  message: this.message,
24
33
  reason: this.reason,
34
+ lastError: this.lastError,
25
35
  errors: this.errors,
26
36
  };
27
37
  }
@@ -1,14 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.postToApi = exports.postJsonToApi = exports.createAudioMpegResponseHandler = exports.createTextResponseHandler = exports.createJsonResponseHandler = void 0;
4
+ const ZodSchema_js_1 = require("../schema/ZodSchema.cjs");
5
+ const parseJSON_js_1 = require("../schema/parseJSON.cjs");
4
6
  const ApiCallError_js_1 = require("./ApiCallError.cjs");
5
7
  const createJsonResponseHandler = (responseSchema) => async ({ response, url, requestBodyValues }) => {
6
- const parsedResult = responseSchema.safeParse(await response.json());
8
+ const responseBody = await response.text();
9
+ const parsedResult = (0, parseJSON_js_1.safeParseJSON)({
10
+ text: responseBody,
11
+ schema: new ZodSchema_js_1.ZodSchema(responseSchema),
12
+ });
7
13
  if (!parsedResult.success) {
8
14
  throw new ApiCallError_js_1.ApiCallError({
9
15
  message: "Invalid JSON response",
10
16
  cause: parsedResult.error,
11
17
  statusCode: response.status,
18
+ responseBody,
12
19
  url,
13
20
  requestBodyValues,
14
21
  });
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ import { ZodSchema } from "../schema/ZodSchema.js";
2
3
  import { z } from "zod";
3
4
  import { ApiCallError } from "./ApiCallError.js";
4
5
  export type ResponseHandler<T> = (options: {
@@ -1,11 +1,18 @@
1
+ import { ZodSchema } from "../schema/ZodSchema.js";
2
+ import { safeParseJSON } from "../schema/parseJSON.js";
1
3
  import { ApiCallError } from "./ApiCallError.js";
2
4
  export const createJsonResponseHandler = (responseSchema) => async ({ response, url, requestBodyValues }) => {
3
- const parsedResult = responseSchema.safeParse(await response.json());
5
+ const responseBody = await response.text();
6
+ const parsedResult = safeParseJSON({
7
+ text: responseBody,
8
+ schema: new ZodSchema(responseSchema),
9
+ });
4
10
  if (!parsedResult.success) {
5
11
  throw new ApiCallError({
6
12
  message: "Invalid JSON response",
7
13
  cause: parsedResult.error,
8
14
  statusCode: response.status,
15
+ responseBody,
9
16
  url,
10
17
  requestBodyValues,
11
18
  });
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.executeFunctionCall = void 0;
4
4
  const nanoid_1 = require("nanoid");
5
5
  const FunctionEventSource_js_1 = require("./FunctionEventSource.cjs");
6
- const GlobalFunctionLogging_js_1 = require("./GlobalFunctionLogging.cjs");
7
- const GlobalFunctionObservers_js_1 = require("./GlobalFunctionObservers.cjs");
6
+ const ModelFusionConfiguration_js_1 = require("./ModelFusionConfiguration.cjs");
7
+ const ModelFusionConfiguration_js_2 = require("./ModelFusionConfiguration.cjs");
8
8
  const AbortError_js_1 = require("./api/AbortError.cjs");
9
9
  const getFunctionCallLogger_js_1 = require("./getFunctionCallLogger.cjs");
10
10
  const getRun_js_1 = require("./getRun.cjs");
@@ -14,8 +14,8 @@ async function executeFunctionCall({ options, input, functionType, execute, inpu
14
14
  const run = await (0, getRun_js_1.getRun)(options?.run);
15
15
  const eventSource = new FunctionEventSource_js_1.FunctionEventSource({
16
16
  observers: [
17
- ...(0, getFunctionCallLogger_js_1.getFunctionCallLogger)(options?.logging ?? (0, GlobalFunctionLogging_js_1.getGlobalFunctionLogging)()),
18
- ...(0, GlobalFunctionObservers_js_1.getGlobalFunctionObservers)(),
17
+ ...(0, getFunctionCallLogger_js_1.getFunctionCallLogger)(options?.logging ?? (0, ModelFusionConfiguration_js_1.getLogFormat)()),
18
+ ...(0, ModelFusionConfiguration_js_2.getFunctionObservers)(),
19
19
  ...(run?.functionObserver != null ? [run.functionObserver] : []),
20
20
  ...(options?.observers ?? []),
21
21
  ],
@@ -1,7 +1,7 @@
1
1
  import { nanoid as createId } from "nanoid";
2
2
  import { FunctionEventSource } from "./FunctionEventSource.js";
3
- import { getGlobalFunctionLogging } from "./GlobalFunctionLogging.js";
4
- import { getGlobalFunctionObservers } from "./GlobalFunctionObservers.js";
3
+ import { getLogFormat } from "./ModelFusionConfiguration.js";
4
+ import { getFunctionObservers } from "./ModelFusionConfiguration.js";
5
5
  import { AbortError } from "./api/AbortError.js";
6
6
  import { getFunctionCallLogger } from "./getFunctionCallLogger.js";
7
7
  import { getRun } from "./getRun.js";
@@ -11,8 +11,8 @@ export async function executeFunctionCall({ options, input, functionType, execut
11
11
  const run = await getRun(options?.run);
12
12
  const eventSource = new FunctionEventSource({
13
13
  observers: [
14
- ...getFunctionCallLogger(options?.logging ?? getGlobalFunctionLogging()),
15
- ...getGlobalFunctionObservers(),
14
+ ...getFunctionCallLogger(options?.logging ?? getLogFormat()),
15
+ ...getFunctionObservers(),
16
16
  ...(run?.functionObserver != null ? [run.functionObserver] : []),
17
17
  ...(options?.observers ?? []),
18
18
  ],
@@ -45,11 +45,27 @@ const detailedObjectObserver = {
45
45
  ),
46
46
  };
47
47
  }
48
- // filter all undefined properties from event for cleaner console output:
49
- event = Object.fromEntries(
50
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
51
- Object.entries(event).filter(([_, v]) => v !== undefined));
52
- console.log(event);
48
+ // filter all hard-to-read properties from event for cleaner console output:
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
+ function cleanObject(obj) {
51
+ if (obj instanceof Date || typeof obj === "string") {
52
+ return obj;
53
+ }
54
+ if (obj !== null && typeof obj === "object") {
55
+ return Object.fromEntries(Object.entries(obj)
56
+ .filter(([_, v] // eslint-disable-line @typescript-eslint/no-unused-vars
57
+ ) => v !== undefined && // filter all undefined properties
58
+ !(v instanceof Buffer) // remove all buffers
59
+ )
60
+ .map(([k, v]) => [k, cleanObject(v)])
61
+ .filter(([_, v]) => v !== undefined) // eslint-disable-line @typescript-eslint/no-unused-vars
62
+ );
63
+ }
64
+ return obj;
65
+ }
66
+ // Clean the event object
67
+ const cleanedEvent = cleanObject(event);
68
+ console.log(cleanedEvent);
53
69
  },
54
70
  };
55
71
  const detailedJsonObserver = {
@@ -41,11 +41,27 @@ const detailedObjectObserver = {
41
41
  ),
42
42
  };
43
43
  }
44
- // filter all undefined properties from event for cleaner console output:
45
- event = Object.fromEntries(
46
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
47
- Object.entries(event).filter(([_, v]) => v !== undefined));
48
- console.log(event);
44
+ // filter all hard-to-read properties from event for cleaner console output:
45
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
+ function cleanObject(obj) {
47
+ if (obj instanceof Date || typeof obj === "string") {
48
+ return obj;
49
+ }
50
+ if (obj !== null && typeof obj === "object") {
51
+ return Object.fromEntries(Object.entries(obj)
52
+ .filter(([_, v] // eslint-disable-line @typescript-eslint/no-unused-vars
53
+ ) => v !== undefined && // filter all undefined properties
54
+ !(v instanceof Buffer) // remove all buffers
55
+ )
56
+ .map(([k, v]) => [k, cleanObject(v)])
57
+ .filter(([_, v]) => v !== undefined) // eslint-disable-line @typescript-eslint/no-unused-vars
58
+ );
59
+ }
60
+ return obj;
61
+ }
62
+ // Clean the event object
63
+ const cleanedEvent = cleanObject(event);
64
+ console.log(cleanedEvent);
49
65
  },
50
66
  };
51
67
  const detailedJsonObserver = {
package/core/index.cjs CHANGED
@@ -10,18 +10,31 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
13
18
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
19
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
20
  };
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
16
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.modelfusion = void 0;
17
30
  __exportStar(require("./DefaultRun.cjs"), exports);
18
31
  __exportStar(require("./ExecuteFunctionEvent.cjs"), exports);
19
32
  __exportStar(require("./FunctionEvent.cjs"), exports);
20
33
  __exportStar(require("./FunctionEventSource.cjs"), exports);
21
34
  __exportStar(require("./FunctionObserver.cjs"), exports);
22
35
  __exportStar(require("./FunctionOptions.cjs"), exports);
23
- __exportStar(require("./GlobalFunctionLogging.cjs"), exports);
24
- __exportStar(require("./GlobalFunctionObservers.cjs"), exports);
36
+ __exportStar(require("./LogFormat.cjs"), exports);
37
+ exports.modelfusion = __importStar(require("./ModelFusionConfiguration.cjs"));
25
38
  __exportStar(require("./Run.cjs"), exports);
26
39
  __exportStar(require("./Vector.cjs"), exports);
27
40
  __exportStar(require("./api/index.cjs"), exports);
package/core/index.d.ts CHANGED
@@ -4,8 +4,8 @@ export * from "./FunctionEvent.js";
4
4
  export * from "./FunctionEventSource.js";
5
5
  export * from "./FunctionObserver.js";
6
6
  export * from "./FunctionOptions.js";
7
- export * from "./GlobalFunctionLogging.js";
8
- export * from "./GlobalFunctionObservers.js";
7
+ export * from "./LogFormat.js";
8
+ export * as modelfusion from "./ModelFusionConfiguration.js";
9
9
  export * from "./Run.js";
10
10
  export * from "./Vector.js";
11
11
  export * from "./api/index.js";
package/core/index.js CHANGED
@@ -4,8 +4,8 @@ export * from "./FunctionEvent.js";
4
4
  export * from "./FunctionEventSource.js";
5
5
  export * from "./FunctionObserver.js";
6
6
  export * from "./FunctionOptions.js";
7
- export * from "./GlobalFunctionLogging.js";
8
- export * from "./GlobalFunctionObservers.js";
7
+ export * from "./LogFormat.js";
8
+ export * as modelfusion from "./ModelFusionConfiguration.js";
9
9
  export * from "./Run.js";
10
10
  export * from "./Vector.js";
11
11
  export * from "./api/index.js";
@@ -7,7 +7,8 @@ class JSONParseError extends Error {
7
7
  super(`JSON parsing failed: ` +
8
8
  `Text: ${text}.\n` +
9
9
  `Error message: ${(0, getErrorMessage_js_1.getErrorMessage)(cause)}`);
10
- Object.defineProperty(this, "structureName", {
10
+ // note: property order determines debugging output
11
+ Object.defineProperty(this, "text", {
11
12
  enumerable: true,
12
13
  configurable: true,
13
14
  writable: true,
@@ -19,12 +20,6 @@ class JSONParseError extends Error {
19
20
  writable: true,
20
21
  value: void 0
21
22
  });
22
- Object.defineProperty(this, "text", {
23
- enumerable: true,
24
- configurable: true,
25
- writable: true,
26
- value: void 0
27
- });
28
23
  this.name = "JSONParseError";
29
24
  this.cause = cause;
30
25
  this.text = text;
@@ -1,7 +1,6 @@
1
1
  export declare class JSONParseError extends Error {
2
- readonly structureName: string;
3
- readonly cause: unknown;
4
2
  readonly text: string;
3
+ readonly cause: unknown;
5
4
  constructor({ text, cause }: {
6
5
  text: string;
7
6
  cause: unknown;
@@ -4,7 +4,8 @@ export class JSONParseError extends Error {
4
4
  super(`JSON parsing failed: ` +
5
5
  `Text: ${text}.\n` +
6
6
  `Error message: ${getErrorMessage(cause)}`);
7
- Object.defineProperty(this, "structureName", {
7
+ // note: property order determines debugging output
8
+ Object.defineProperty(this, "text", {
8
9
  enumerable: true,
9
10
  configurable: true,
10
11
  writable: true,
@@ -16,12 +17,6 @@ export class JSONParseError extends Error {
16
17
  writable: true,
17
18
  value: void 0
18
19
  });
19
- Object.defineProperty(this, "text", {
20
- enumerable: true,
21
- configurable: true,
22
- writable: true,
23
- value: void 0
24
- });
25
20
  this.name = "JSONParseError";
26
21
  this.cause = cause;
27
22
  this.text = text;
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.executeStandardCall = void 0;
4
4
  const nanoid_1 = require("nanoid");
5
5
  const FunctionEventSource_js_1 = require("../core/FunctionEventSource.cjs");
6
- const GlobalFunctionLogging_js_1 = require("../core/GlobalFunctionLogging.cjs");
7
- const GlobalFunctionObservers_js_1 = require("../core/GlobalFunctionObservers.cjs");
6
+ const ModelFusionConfiguration_js_1 = require("../core/ModelFusionConfiguration.cjs");
7
+ const ModelFusionConfiguration_js_2 = require("../core/ModelFusionConfiguration.cjs");
8
8
  const AbortError_js_1 = require("../core/api/AbortError.cjs");
9
9
  const getFunctionCallLogger_js_1 = require("../core/getFunctionCallLogger.cjs");
10
10
  const getRun_js_1 = require("../core/getRun.cjs");
@@ -15,8 +15,8 @@ async function executeStandardCall({ model, options, input, functionType, genera
15
15
  const settings = model.settings;
16
16
  const eventSource = new FunctionEventSource_js_1.FunctionEventSource({
17
17
  observers: [
18
- ...(0, getFunctionCallLogger_js_1.getFunctionCallLogger)(options?.logging ?? (0, GlobalFunctionLogging_js_1.getGlobalFunctionLogging)()),
19
- ...(0, GlobalFunctionObservers_js_1.getGlobalFunctionObservers)(),
18
+ ...(0, getFunctionCallLogger_js_1.getFunctionCallLogger)(options?.logging ?? (0, ModelFusionConfiguration_js_1.getLogFormat)()),
19
+ ...(0, ModelFusionConfiguration_js_2.getFunctionObservers)(),
20
20
  ...(settings.observers ?? []),
21
21
  ...(run?.functionObserver != null ? [run.functionObserver] : []),
22
22
  ...(options?.observers ?? []),