modelfusion 0.43.0 → 0.44.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/README.md CHANGED
@@ -476,19 +476,17 @@ const result = await guard(
476
476
  [
477
477
  // ...
478
478
  ],
479
- [
480
- fixStructure({
481
- modifyInputForRetry: async ({ input, error }) => [
482
- ...input,
483
- OpenAIChatMessage.functionCall(null, {
484
- name: error.structureName,
485
- arguments: error.valueText,
486
- }),
487
- OpenAIChatMessage.user(error.message),
488
- OpenAIChatMessage.user("Please fix the error and try again."),
489
- ],
490
- }),
491
- ]
479
+ fixStructure({
480
+ modifyInputForRetry: async ({ input, error }) => [
481
+ ...input,
482
+ OpenAIChatMessage.functionCall(null, {
483
+ name: error.structureName,
484
+ arguments: error.valueText,
485
+ }),
486
+ OpenAIChatMessage.user(error.message),
487
+ OpenAIChatMessage.user("Please fix the error and try again."),
488
+ ],
489
+ })
492
490
  );
493
491
  ```
494
492
 
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
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
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.withRun = exports.getRun = void 0;
27
+ let runStorage;
28
+ const isNode = typeof process !== "undefined" &&
29
+ process.versions != null &&
30
+ process.versions.node != null;
31
+ async function ensureLoaded() {
32
+ if (!isNode)
33
+ return Promise.resolve();
34
+ if (!runStorage) {
35
+ const { AsyncLocalStorage } = await Promise.resolve().then(() => __importStar(require("node:async_hooks")));
36
+ runStorage = new AsyncLocalStorage();
37
+ }
38
+ return Promise.resolve();
39
+ }
40
+ /**
41
+ * Returns the run stored in an AsyncLocalStorage if running in Node.js. It can be set with `withRun()`.
42
+ */
43
+ async function getRun(run) {
44
+ await ensureLoaded();
45
+ return run ?? runStorage?.getStore();
46
+ }
47
+ exports.getRun = getRun;
48
+ /**
49
+ * Stores the run in an AsyncLocalStorage if running in Node.js. It can be retrieved with `getRun()`.
50
+ */
51
+ async function withRun(run, callback) {
52
+ await ensureLoaded();
53
+ if (runStorage != null) {
54
+ await runStorage.run(run, callback);
55
+ }
56
+ else {
57
+ await callback();
58
+ }
59
+ }
60
+ exports.withRun = withRun;
@@ -0,0 +1,9 @@
1
+ import { Run } from "./Run";
2
+ /**
3
+ * Returns the run stored in an AsyncLocalStorage if running in Node.js. It can be set with `withRun()`.
4
+ */
5
+ export declare function getRun(run?: Run): Promise<Run | undefined>;
6
+ /**
7
+ * Stores the run in an AsyncLocalStorage if running in Node.js. It can be retrieved with `getRun()`.
8
+ */
9
+ export declare function withRun(run: Run, callback: () => PromiseLike<void>): Promise<void>;
package/core/getRun.js ADDED
@@ -0,0 +1,32 @@
1
+ let runStorage;
2
+ const isNode = typeof process !== "undefined" &&
3
+ process.versions != null &&
4
+ process.versions.node != null;
5
+ async function ensureLoaded() {
6
+ if (!isNode)
7
+ return Promise.resolve();
8
+ if (!runStorage) {
9
+ const { AsyncLocalStorage } = await import("node:async_hooks");
10
+ runStorage = new AsyncLocalStorage();
11
+ }
12
+ return Promise.resolve();
13
+ }
14
+ /**
15
+ * Returns the run stored in an AsyncLocalStorage if running in Node.js. It can be set with `withRun()`.
16
+ */
17
+ export async function getRun(run) {
18
+ await ensureLoaded();
19
+ return run ?? runStorage?.getStore();
20
+ }
21
+ /**
22
+ * Stores the run in an AsyncLocalStorage if running in Node.js. It can be retrieved with `getRun()`.
23
+ */
24
+ export async function withRun(run, callback) {
25
+ await ensureLoaded();
26
+ if (runStorage != null) {
27
+ await runStorage.run(run, callback);
28
+ }
29
+ else {
30
+ await callback();
31
+ }
32
+ }
package/core/index.cjs CHANGED
@@ -24,4 +24,5 @@ __exportStar(require("./GlobalFunctionObservers.cjs"), exports);
24
24
  __exportStar(require("./Run.cjs"), exports);
25
25
  __exportStar(require("./Vector.cjs"), exports);
26
26
  __exportStar(require("./api/index.cjs"), exports);
27
+ __exportStar(require("./getRun.cjs"), exports);
27
28
  __exportStar(require("./structure/index.cjs"), exports);
package/core/index.d.ts CHANGED
@@ -8,4 +8,5 @@ export * from "./GlobalFunctionObservers.js";
8
8
  export * from "./Run.js";
9
9
  export * from "./Vector.js";
10
10
  export * from "./api/index.js";
11
+ export * from "./getRun.js";
11
12
  export * from "./structure/index.js";
package/core/index.js CHANGED
@@ -8,4 +8,5 @@ export * from "./GlobalFunctionObservers.js";
8
8
  export * from "./Run.js";
9
9
  export * from "./Vector.js";
10
10
  export * from "./api/index.js";
11
+ export * from "./getRun.js";
11
12
  export * from "./structure/index.js";
package/guard/guard.cjs CHANGED
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.guard = void 0;
4
4
  async function guard(execute, input, guards, options) {
5
+ if (typeof guards === "function") {
6
+ guards = [guards];
7
+ }
5
8
  const maxRetries = options?.maxRetries ?? 1;
6
9
  let attempts = 0;
7
10
  while (attempts <= maxRetries) {
package/guard/guard.d.ts CHANGED
@@ -22,7 +22,7 @@ export type Guard<INPUT, OUTPUT> = ({ type, input, output, error, }: OutputResul
22
22
  } | {
23
23
  action: "passThrough";
24
24
  } | undefined>;
25
- export declare function guard<INPUT, OUTPUT>(execute: (input: INPUT) => PromiseLike<OUTPUT>, input: INPUT, guards: Array<Guard<INPUT, OUTPUT>>, options?: {
25
+ export declare function guard<INPUT, OUTPUT>(execute: (input: INPUT) => PromiseLike<OUTPUT>, input: INPUT, guards: Array<Guard<INPUT, OUTPUT>> | Guard<INPUT, OUTPUT>, options?: {
26
26
  maxRetries: number;
27
27
  }): Promise<OUTPUT | undefined>;
28
28
  export {};
package/guard/guard.js CHANGED
@@ -1,4 +1,7 @@
1
1
  export async function guard(execute, input, guards, options) {
2
+ if (typeof guards === "function") {
3
+ guards = [guards];
4
+ }
2
5
  const maxRetries = options?.maxRetries ?? 1;
3
6
  let attempts = 0;
4
7
  while (attempts <= maxRetries) {
@@ -7,6 +7,7 @@ const GlobalFunctionLogging_js_1 = require("../core/GlobalFunctionLogging.cjs");
7
7
  const GlobalFunctionObservers_js_1 = require("../core/GlobalFunctionObservers.cjs");
8
8
  const AbortError_js_1 = require("../core/api/AbortError.cjs");
9
9
  const getFunctionCallLogger_js_1 = require("../core/getFunctionCallLogger.cjs");
10
+ const getRun_js_1 = require("../core/getRun.cjs");
10
11
  const DurationMeasurement_js_1 = require("../util/DurationMeasurement.cjs");
11
12
  const runSafe_js_1 = require("../util/runSafe.cjs");
12
13
  class ModelFunctionPromise extends Promise {
@@ -54,7 +55,7 @@ function executeCall({ model, options, input, functionType, generateResponse, })
54
55
  }
55
56
  exports.executeCall = executeCall;
56
57
  async function doExecuteCall({ model, options, input, functionType, generateResponse, }) {
57
- const run = options?.run;
58
+ const run = await (0, getRun_js_1.getRun)(options?.run);
58
59
  const settings = model.settings;
59
60
  const eventSource = new FunctionEventSource_js_1.FunctionEventSource({
60
61
  observers: [
@@ -84,7 +85,12 @@ async function doExecuteCall({ model, options, input, functionType, generateResp
84
85
  eventType: "started",
85
86
  ...startMetadata,
86
87
  });
87
- const result = await (0, runSafe_js_1.runSafe)(() => generateResponse(options));
88
+ const result = await (0, runSafe_js_1.runSafe)(() => generateResponse({
89
+ functionId: options?.functionId,
90
+ logging: options?.logging,
91
+ observers: options?.observers,
92
+ run,
93
+ }));
88
94
  const finishMetadata = {
89
95
  eventType: "finished",
90
96
  ...startMetadata,
@@ -4,6 +4,7 @@ import { getGlobalFunctionLogging } from "../core/GlobalFunctionLogging.js";
4
4
  import { getGlobalFunctionObservers } from "../core/GlobalFunctionObservers.js";
5
5
  import { AbortError } from "../core/api/AbortError.js";
6
6
  import { getFunctionCallLogger } from "../core/getFunctionCallLogger.js";
7
+ import { getRun } from "../core/getRun.js";
7
8
  import { startDurationMeasurement } from "../util/DurationMeasurement.js";
8
9
  import { runSafe } from "../util/runSafe.js";
9
10
  export class ModelFunctionPromise extends Promise {
@@ -49,7 +50,7 @@ export function executeCall({ model, options, input, functionType, generateRespo
49
50
  }));
50
51
  }
51
52
  async function doExecuteCall({ model, options, input, functionType, generateResponse, }) {
52
- const run = options?.run;
53
+ const run = await getRun(options?.run);
53
54
  const settings = model.settings;
54
55
  const eventSource = new FunctionEventSource({
55
56
  observers: [
@@ -79,7 +80,12 @@ async function doExecuteCall({ model, options, input, functionType, generateResp
79
80
  eventType: "started",
80
81
  ...startMetadata,
81
82
  });
82
- const result = await runSafe(() => generateResponse(options));
83
+ const result = await runSafe(() => generateResponse({
84
+ functionId: options?.functionId,
85
+ logging: options?.logging,
86
+ observers: options?.observers,
87
+ run,
88
+ }));
83
89
  const finishMetadata = {
84
90
  eventType: "finished",
85
91
  ...startMetadata,
@@ -11,6 +11,7 @@ const GlobalFunctionLogging_js_1 = require("../../core/GlobalFunctionLogging.cjs
11
11
  const GlobalFunctionObservers_js_1 = require("../../core/GlobalFunctionObservers.cjs");
12
12
  const AbortError_js_1 = require("../../core/api/AbortError.cjs");
13
13
  const getFunctionCallLogger_js_1 = require("../../core/getFunctionCallLogger.cjs");
14
+ const getRun_js_1 = require("../../core/getRun.cjs");
14
15
  const DurationMeasurement_js_1 = require("../../util/DurationMeasurement.cjs");
15
16
  const runSafe_js_1 = require("../../util/runSafe.cjs");
16
17
  const AsyncIterableResultPromise_js_1 = require("../AsyncIterableResultPromise.cjs");
@@ -19,7 +20,7 @@ function streamStructure(model, structureDefinition, prompt, options) {
19
20
  }
20
21
  exports.streamStructure = streamStructure;
21
22
  async function doStreamStructure(model, structureDefinition, prompt, options) {
22
- const run = options?.run;
23
+ const run = await (0, getRun_js_1.getRun)(options?.run);
23
24
  const settings = model.settings;
24
25
  const eventSource = new FunctionEventSource_js_1.FunctionEventSource({
25
26
  observers: [
@@ -50,7 +51,12 @@ async function doStreamStructure(model, structureDefinition, prompt, options) {
50
51
  ...startMetadata,
51
52
  });
52
53
  const result = await (0, runSafe_js_1.runSafe)(async () => {
53
- const deltaIterable = await model.doStreamStructure(structureDefinition, prompt, options);
54
+ const deltaIterable = await model.doStreamStructure(structureDefinition, prompt, {
55
+ functionId: options?.functionId,
56
+ logging: options?.logging,
57
+ observers: options?.observers,
58
+ run,
59
+ });
54
60
  return (async function* () {
55
61
  function reportError(error) {
56
62
  const finishMetadata = {
@@ -5,6 +5,7 @@ import { getGlobalFunctionLogging } from "../../core/GlobalFunctionLogging.js";
5
5
  import { getGlobalFunctionObservers } from "../../core/GlobalFunctionObservers.js";
6
6
  import { AbortError } from "../../core/api/AbortError.js";
7
7
  import { getFunctionCallLogger } from "../../core/getFunctionCallLogger.js";
8
+ import { getRun } from "../../core/getRun.js";
8
9
  import { startDurationMeasurement } from "../../util/DurationMeasurement.js";
9
10
  import { runSafe } from "../../util/runSafe.js";
10
11
  import { AsyncIterableResultPromise } from "../AsyncIterableResultPromise.js";
@@ -12,7 +13,7 @@ export function streamStructure(model, structureDefinition, prompt, options) {
12
13
  return new AsyncIterableResultPromise(doStreamStructure(model, structureDefinition, prompt, options));
13
14
  }
14
15
  async function doStreamStructure(model, structureDefinition, prompt, options) {
15
- const run = options?.run;
16
+ const run = await getRun(options?.run);
16
17
  const settings = model.settings;
17
18
  const eventSource = new FunctionEventSource({
18
19
  observers: [
@@ -43,7 +44,12 @@ async function doStreamStructure(model, structureDefinition, prompt, options) {
43
44
  ...startMetadata,
44
45
  });
45
46
  const result = await runSafe(async () => {
46
- const deltaIterable = await model.doStreamStructure(structureDefinition, prompt, options);
47
+ const deltaIterable = await model.doStreamStructure(structureDefinition, prompt, {
48
+ functionId: options?.functionId,
49
+ logging: options?.logging,
50
+ observers: options?.observers,
51
+ run,
52
+ });
47
53
  return (async function* () {
48
54
  function reportError(error) {
49
55
  const finishMetadata = {
@@ -7,6 +7,7 @@ const GlobalFunctionLogging_js_1 = require("../../core/GlobalFunctionLogging.cjs
7
7
  const GlobalFunctionObservers_js_1 = require("../../core/GlobalFunctionObservers.cjs");
8
8
  const AbortError_js_1 = require("../../core/api/AbortError.cjs");
9
9
  const getFunctionCallLogger_js_1 = require("../../core/getFunctionCallLogger.cjs");
10
+ const getRun_js_1 = require("../../core/getRun.cjs");
10
11
  const DurationMeasurement_js_1 = require("../../util/DurationMeasurement.cjs");
11
12
  const runSafe_js_1 = require("../../util/runSafe.cjs");
12
13
  const AsyncIterableResultPromise_js_1 = require("../AsyncIterableResultPromise.cjs");
@@ -15,7 +16,7 @@ function streamText(model, prompt, options) {
15
16
  }
16
17
  exports.streamText = streamText;
17
18
  async function doStreamText(model, prompt, options) {
18
- const run = options?.run;
19
+ const run = await (0, getRun_js_1.getRun)(options?.run);
19
20
  const eventSource = new FunctionEventSource_js_1.FunctionEventSource({
20
21
  observers: [
21
22
  ...(0, getFunctionCallLogger_js_1.getFunctionCallLogger)(options?.logging ?? (0, GlobalFunctionLogging_js_1.getGlobalFunctionLogging)()),
@@ -45,7 +46,12 @@ async function doStreamText(model, prompt, options) {
45
46
  ...startMetadata,
46
47
  });
47
48
  const result = await (0, runSafe_js_1.runSafe)(async () => {
48
- const deltaIterable = await model.doStreamText(prompt, options);
49
+ const deltaIterable = await model.doStreamText(prompt, {
50
+ functionId: options?.functionId,
51
+ logging: options?.logging,
52
+ observers: options?.observers,
53
+ run,
54
+ });
49
55
  return (async function* () {
50
56
  let accumulatedText = "";
51
57
  let lastFullDelta;
@@ -4,6 +4,7 @@ import { getGlobalFunctionLogging } from "../../core/GlobalFunctionLogging.js";
4
4
  import { getGlobalFunctionObservers } from "../../core/GlobalFunctionObservers.js";
5
5
  import { AbortError } from "../../core/api/AbortError.js";
6
6
  import { getFunctionCallLogger } from "../../core/getFunctionCallLogger.js";
7
+ import { getRun } from "../../core/getRun.js";
7
8
  import { startDurationMeasurement } from "../../util/DurationMeasurement.js";
8
9
  import { runSafe } from "../../util/runSafe.js";
9
10
  import { AsyncIterableResultPromise } from "../AsyncIterableResultPromise.js";
@@ -11,7 +12,7 @@ export function streamText(model, prompt, options) {
11
12
  return new AsyncIterableResultPromise(doStreamText(model, prompt, options));
12
13
  }
13
14
  async function doStreamText(model, prompt, options) {
14
- const run = options?.run;
15
+ const run = await getRun(options?.run);
15
16
  const eventSource = new FunctionEventSource({
16
17
  observers: [
17
18
  ...getFunctionCallLogger(options?.logging ?? getGlobalFunctionLogging()),
@@ -41,7 +42,12 @@ async function doStreamText(model, prompt, options) {
41
42
  ...startMetadata,
42
43
  });
43
44
  const result = await runSafe(async () => {
44
- const deltaIterable = await model.doStreamText(prompt, options);
45
+ const deltaIterable = await model.doStreamText(prompt, {
46
+ functionId: options?.functionId,
47
+ logging: options?.logging,
48
+ observers: options?.observers,
49
+ run,
50
+ });
45
51
  return (async function* () {
46
52
  let accumulatedText = "";
47
53
  let lastFullDelta;
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.43.0",
4
+ "version": "0.44.0",
5
5
  "author": "Lars Grammel",
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -7,10 +7,11 @@ const GlobalFunctionLogging_js_1 = require("../core/GlobalFunctionLogging.cjs");
7
7
  const GlobalFunctionObservers_js_1 = require("../core/GlobalFunctionObservers.cjs");
8
8
  const AbortError_js_1 = require("../core/api/AbortError.cjs");
9
9
  const getFunctionCallLogger_js_1 = require("../core/getFunctionCallLogger.cjs");
10
+ const getRun_js_1 = require("../core/getRun.cjs");
10
11
  const DurationMeasurement_js_1 = require("../util/DurationMeasurement.cjs");
11
12
  const runSafe_js_1 = require("../util/runSafe.cjs");
12
13
  async function retrieve(retriever, query, options) {
13
- const run = options?.run;
14
+ const run = await (0, getRun_js_1.getRun)(options?.run);
14
15
  const eventSource = new FunctionEventSource_js_1.FunctionEventSource({
15
16
  observers: [
16
17
  ...(0, getFunctionCallLogger_js_1.getFunctionCallLogger)(options?.logging ?? (0, GlobalFunctionLogging_js_1.getGlobalFunctionLogging)()),
@@ -36,7 +37,12 @@ async function retrieve(retriever, query, options) {
36
37
  eventType: "started",
37
38
  ...startMetadata,
38
39
  });
39
- const result = await (0, runSafe_js_1.runSafe)(() => retriever.retrieve(query, options));
40
+ const result = await (0, runSafe_js_1.runSafe)(() => retriever.retrieve(query, {
41
+ functionId: options?.functionId,
42
+ logging: options?.logging,
43
+ observers: options?.observers,
44
+ run,
45
+ }));
40
46
  const finishMetadata = {
41
47
  eventType: "finished",
42
48
  ...startMetadata,
@@ -4,10 +4,11 @@ import { getGlobalFunctionLogging } from "../core/GlobalFunctionLogging.js";
4
4
  import { getGlobalFunctionObservers } from "../core/GlobalFunctionObservers.js";
5
5
  import { AbortError } from "../core/api/AbortError.js";
6
6
  import { getFunctionCallLogger } from "../core/getFunctionCallLogger.js";
7
+ import { getRun } from "../core/getRun.js";
7
8
  import { startDurationMeasurement } from "../util/DurationMeasurement.js";
8
9
  import { runSafe } from "../util/runSafe.js";
9
10
  export async function retrieve(retriever, query, options) {
10
- const run = options?.run;
11
+ const run = await getRun(options?.run);
11
12
  const eventSource = new FunctionEventSource({
12
13
  observers: [
13
14
  ...getFunctionCallLogger(options?.logging ?? getGlobalFunctionLogging()),
@@ -33,7 +34,12 @@ export async function retrieve(retriever, query, options) {
33
34
  eventType: "started",
34
35
  ...startMetadata,
35
36
  });
36
- const result = await runSafe(() => retriever.retrieve(query, options));
37
+ const result = await runSafe(() => retriever.retrieve(query, {
38
+ functionId: options?.functionId,
39
+ logging: options?.logging,
40
+ observers: options?.observers,
41
+ run,
42
+ }));
37
43
  const finishMetadata = {
38
44
  eventType: "finished",
39
45
  ...startMetadata,
@@ -7,6 +7,7 @@ const GlobalFunctionLogging_js_1 = require("../core/GlobalFunctionLogging.cjs");
7
7
  const GlobalFunctionObservers_js_1 = require("../core/GlobalFunctionObservers.cjs");
8
8
  const AbortError_js_1 = require("../core/api/AbortError.cjs");
9
9
  const getFunctionCallLogger_js_1 = require("../core/getFunctionCallLogger.cjs");
10
+ const getRun_js_1 = require("../core/getRun.cjs");
10
11
  const DurationMeasurement_js_1 = require("../util/DurationMeasurement.cjs");
11
12
  const runSafe_js_1 = require("../util/runSafe.cjs");
12
13
  const ToolExecutionError_js_1 = require("./ToolExecutionError.cjs");
@@ -54,7 +55,7 @@ function executeTool(tool, input, options) {
54
55
  exports.executeTool = executeTool;
55
56
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
57
  async function doExecuteTool(tool, input, options) {
57
- const run = options?.run;
58
+ const run = await (0, getRun_js_1.getRun)(options?.run);
58
59
  const eventSource = new FunctionEventSource_js_1.FunctionEventSource({
59
60
  observers: [
60
61
  ...(0, getFunctionCallLogger_js_1.getFunctionCallLogger)(options?.logging ?? (0, GlobalFunctionLogging_js_1.getGlobalFunctionLogging)()),
@@ -81,7 +82,12 @@ async function doExecuteTool(tool, input, options) {
81
82
  timestamp: durationMeasurement.startDate,
82
83
  startTimestamp: durationMeasurement.startDate,
83
84
  });
84
- const result = await (0, runSafe_js_1.runSafe)(() => tool.execute(input, options));
85
+ const result = await (0, runSafe_js_1.runSafe)(() => tool.execute(input, {
86
+ functionId: options?.functionId,
87
+ logging: options?.logging,
88
+ observers: options?.observers,
89
+ run,
90
+ }));
85
91
  const finishMetadata = {
86
92
  ...metadata,
87
93
  eventType: "finished",
@@ -4,6 +4,7 @@ import { getGlobalFunctionLogging } from "../core/GlobalFunctionLogging.js";
4
4
  import { getGlobalFunctionObservers } from "../core/GlobalFunctionObservers.js";
5
5
  import { AbortError } from "../core/api/AbortError.js";
6
6
  import { getFunctionCallLogger } from "../core/getFunctionCallLogger.js";
7
+ import { getRun } from "../core/getRun.js";
7
8
  import { startDurationMeasurement } from "../util/DurationMeasurement.js";
8
9
  import { runSafe } from "../util/runSafe.js";
9
10
  import { ToolExecutionError } from "./ToolExecutionError.js";
@@ -49,7 +50,7 @@ export function executeTool(tool, input, options) {
49
50
  }
50
51
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
52
  async function doExecuteTool(tool, input, options) {
52
- const run = options?.run;
53
+ const run = await getRun(options?.run);
53
54
  const eventSource = new FunctionEventSource({
54
55
  observers: [
55
56
  ...getFunctionCallLogger(options?.logging ?? getGlobalFunctionLogging()),
@@ -76,7 +77,12 @@ async function doExecuteTool(tool, input, options) {
76
77
  timestamp: durationMeasurement.startDate,
77
78
  startTimestamp: durationMeasurement.startDate,
78
79
  });
79
- const result = await runSafe(() => tool.execute(input, options));
80
+ const result = await runSafe(() => tool.execute(input, {
81
+ functionId: options?.functionId,
82
+ logging: options?.logging,
83
+ observers: options?.observers,
84
+ run,
85
+ }));
80
86
  const finishMetadata = {
81
87
  ...metadata,
82
88
  eventType: "finished",