modelfusion 0.21.0 → 0.22.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 (86) hide show
  1. package/composed-function/summarize/SummarizationFunction.d.ts +1 -1
  2. package/composed-function/summarize/summarizeRecursively.d.ts +1 -1
  3. package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.d.ts +1 -1
  4. package/{run → core}/DefaultRun.cjs +1 -1
  5. package/{run → core}/DefaultRun.js +1 -1
  6. package/{run → core}/FunctionEvent.d.ts +30 -6
  7. package/index.cjs +1 -1
  8. package/index.d.ts +1 -1
  9. package/index.js +1 -1
  10. package/model-function/Model.d.ts +1 -1
  11. package/model-function/ModelCallEvent.d.ts +20 -5
  12. package/model-function/ModelFunctionOptions.d.ts +1 -1
  13. package/model-function/SuccessfulModelCall.cjs +4 -2
  14. package/model-function/SuccessfulModelCall.d.ts +1 -1
  15. package/model-function/SuccessfulModelCall.js +4 -2
  16. package/model-function/embed-text/TextEmbeddingEvent.d.ts +12 -12
  17. package/model-function/embed-text/TextEmbeddingModel.d.ts +1 -1
  18. package/model-function/embed-text/embedText.cjs +6 -61
  19. package/model-function/embed-text/embedText.d.ts +1 -1
  20. package/model-function/embed-text/embedText.js +6 -61
  21. package/model-function/executeCall.cjs +32 -19
  22. package/model-function/executeCall.d.ts +4 -12
  23. package/model-function/executeCall.js +32 -19
  24. package/model-function/generate-image/ImageGenerationEvent.d.ts +9 -11
  25. package/model-function/generate-image/generateImage.cjs +2 -27
  26. package/model-function/generate-image/generateImage.js +2 -27
  27. package/model-function/generate-json/JsonGenerationEvent.d.ts +3 -16
  28. package/model-function/generate-json/generateJson.cjs +2 -27
  29. package/model-function/generate-json/generateJson.js +2 -27
  30. package/model-function/generate-json/generateJsonOrText.cjs +2 -27
  31. package/model-function/generate-json/generateJsonOrText.js +2 -27
  32. package/model-function/generate-text/TextGenerationEvent.d.ts +10 -10
  33. package/model-function/generate-text/TextStreamingEvent.d.ts +4 -17
  34. package/model-function/generate-text/generateText.cjs +2 -27
  35. package/model-function/generate-text/generateText.js +2 -27
  36. package/model-function/generate-text/streamText.cjs +24 -29
  37. package/model-function/generate-text/streamText.js +24 -29
  38. package/model-function/synthesize-speech/SpeechSynthesisEvent.d.ts +11 -10
  39. package/model-function/synthesize-speech/synthesizeSpeech.cjs +2 -28
  40. package/model-function/synthesize-speech/synthesizeSpeech.js +2 -28
  41. package/model-function/transcribe-speech/TranscriptionEvent.d.ts +9 -11
  42. package/model-function/transcribe-speech/transcribe.cjs +2 -27
  43. package/model-function/transcribe-speech/transcribe.js +2 -27
  44. package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +3 -3
  45. package/model-provider/cohere/CohereTokenizer.d.ts +1 -1
  46. package/model-provider/llamacpp/LlamaCppTokenizer.d.ts +1 -1
  47. package/package.json +1 -1
  48. package/text-chunk/split/SplitFunction.d.ts +1 -1
  49. package/tool/ExecuteToolEvent.d.ts +7 -16
  50. package/tool/Tool.d.ts +1 -1
  51. package/tool/WebSearchTool.cjs +25 -0
  52. package/tool/WebSearchTool.d.ts +56 -1
  53. package/tool/WebSearchTool.js +25 -0
  54. package/tool/executeTool.cjs +14 -8
  55. package/tool/executeTool.d.ts +1 -1
  56. package/tool/executeTool.js +14 -8
  57. package/vector-index/VectorIndex.d.ts +1 -1
  58. package/vector-index/memory/MemoryVectorIndex.d.ts +1 -1
  59. package/vector-index/pinecone/PineconeVectorIndex.d.ts +1 -1
  60. /package/{run → core}/ConsoleLogger.cjs +0 -0
  61. /package/{run → core}/ConsoleLogger.d.ts +0 -0
  62. /package/{run → core}/ConsoleLogger.js +0 -0
  63. /package/{run → core}/DefaultRun.d.ts +0 -0
  64. /package/{run → core}/FunctionEvent.cjs +0 -0
  65. /package/{run → core}/FunctionEvent.js +0 -0
  66. /package/{run → core}/FunctionEventSource.cjs +0 -0
  67. /package/{run → core}/FunctionEventSource.d.ts +0 -0
  68. /package/{run → core}/FunctionEventSource.js +0 -0
  69. /package/{run → core}/FunctionObserver.cjs +0 -0
  70. /package/{run → core}/FunctionObserver.d.ts +0 -0
  71. /package/{run → core}/FunctionObserver.js +0 -0
  72. /package/{run → core}/FunctionOptions.cjs +0 -0
  73. /package/{run → core}/FunctionOptions.d.ts +0 -0
  74. /package/{run → core}/FunctionOptions.js +0 -0
  75. /package/{run → core}/GlobalFunctionObservers.cjs +0 -0
  76. /package/{run → core}/GlobalFunctionObservers.d.ts +0 -0
  77. /package/{run → core}/GlobalFunctionObservers.js +0 -0
  78. /package/{run → core}/Run.cjs +0 -0
  79. /package/{run → core}/Run.d.ts +0 -0
  80. /package/{run → core}/Run.js +0 -0
  81. /package/{run → core}/Vector.cjs +0 -0
  82. /package/{run → core}/Vector.d.ts +0 -0
  83. /package/{run → core}/Vector.js +0 -0
  84. /package/{run → core}/index.cjs +0 -0
  85. /package/{run → core}/index.d.ts +0 -0
  86. /package/{run → core}/index.js +0 -0
@@ -1,17 +1,15 @@
1
1
  import { nanoid as createId } from "nanoid";
2
- import { FunctionEventSource } from "../run/FunctionEventSource.js";
3
- import { getGlobalFunctionObservers } from "../run/GlobalFunctionObservers.js";
2
+ import { FunctionEventSource } from "../core/FunctionEventSource.js";
3
+ import { getGlobalFunctionObservers } from "../core/GlobalFunctionObservers.js";
4
4
  import { startDurationMeasurement } from "../util/DurationMeasurement.js";
5
5
  import { AbortError } from "../util/api/AbortError.js";
6
6
  import { runSafe } from "../util/runSafe.js";
7
- export function executeCall({ model, options, getStartEvent, getAbortEvent, getFailureEvent, getSuccessEvent, generateResponse, extractOutputValue, }) {
7
+ export function executeCall({ model, options, input, functionType, generateResponse, extractOutputValue, }) {
8
8
  return new ModelFunctionPromise(doExecuteCall({
9
9
  model,
10
10
  options,
11
- getStartEvent,
12
- getAbortEvent,
13
- getFailureEvent,
14
- getSuccessEvent,
11
+ input,
12
+ functionType,
15
13
  generateResponse,
16
14
  extractOutputValue,
17
15
  }));
@@ -49,7 +47,7 @@ export class ModelFunctionPromise extends Promise {
49
47
  return this.outputPromise.finally(onfinally);
50
48
  }
51
49
  }
52
- async function doExecuteCall({ model, options, getStartEvent, getAbortEvent, getFailureEvent, getSuccessEvent, generateResponse, extractOutputValue, }) {
50
+ async function doExecuteCall({ model, options, input, functionType, generateResponse, extractOutputValue, }) {
53
51
  if (options?.settings != null) {
54
52
  model = model.withSettings(options.settings);
55
53
  options = {
@@ -77,13 +75,16 @@ async function doExecuteCall({ model, options, getStartEvent, getAbortEvent, get
77
75
  userId: run?.userId,
78
76
  functionId: options?.functionId,
79
77
  model: model.modelInformation,
78
+ functionType,
79
+ input,
80
+ settings,
80
81
  timestamp: durationMeasurement.startDate,
81
82
  startTimestamp: durationMeasurement.startDate,
82
83
  };
83
- eventSource.notify(getStartEvent({
84
+ eventSource.notify({
84
85
  ...startMetadata,
85
86
  eventType: "started",
86
- }, settings));
87
+ });
87
88
  const result = await runSafe(() => generateResponse({
88
89
  functionId: options?.functionId,
89
90
  settings,
@@ -97,24 +98,36 @@ async function doExecuteCall({ model, options, getStartEvent, getAbortEvent, get
97
98
  };
98
99
  if (!result.ok) {
99
100
  if (result.isAborted) {
100
- eventSource.notify(getAbortEvent({
101
+ eventSource.notify({
101
102
  ...finishMetadata,
102
- status: "abort",
103
- }, settings));
103
+ eventType: "finished",
104
+ result: {
105
+ status: "abort",
106
+ },
107
+ });
104
108
  throw new AbortError();
105
109
  }
106
- eventSource.notify(getFailureEvent({
110
+ eventSource.notify({
107
111
  ...finishMetadata,
108
- status: "error",
109
- }, settings, result.error));
112
+ eventType: "finished",
113
+ result: {
114
+ status: "error",
115
+ error: result.error,
116
+ },
117
+ });
110
118
  throw result.error;
111
119
  }
112
120
  const response = result.output;
113
121
  const output = extractOutputValue(response);
114
- eventSource.notify(getSuccessEvent({
122
+ eventSource.notify({
115
123
  ...finishMetadata,
116
- status: "success",
117
- }, settings, response, output));
124
+ eventType: "finished",
125
+ result: {
126
+ status: "success",
127
+ response,
128
+ output,
129
+ },
130
+ });
118
131
  return {
119
132
  output,
120
133
  response,
@@ -1,20 +1,18 @@
1
1
  import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
2
- export type ImageGenerationStartedEvent = BaseModelCallStartedEvent & {
2
+ export interface ImageGenerationStartedEvent extends BaseModelCallStartedEvent {
3
3
  functionType: "image-generation";
4
- settings: unknown;
5
- prompt: unknown;
6
- };
7
- export type ImageGenerationFinishedEvent = BaseModelCallFinishedEvent & {
8
- functionType: "image-generation";
9
- settings: unknown;
10
- prompt: unknown;
11
- } & ({
4
+ }
5
+ export type ImageGenerationFinishedEventResult = {
12
6
  status: "success";
13
7
  response: unknown;
14
- generatedImage: string;
8
+ output: string;
15
9
  } | {
16
10
  status: "error";
17
11
  error: unknown;
18
12
  } | {
19
13
  status: "abort";
20
- });
14
+ };
15
+ export interface ImageGenerationFinishedEvent extends BaseModelCallFinishedEvent {
16
+ functionType: "image-generation";
17
+ result: ImageGenerationFinishedEventResult;
18
+ }
@@ -19,37 +19,12 @@ const executeCall_js_1 = require("../executeCall.cjs");
19
19
  */
20
20
  function generateImage(model, prompt, options) {
21
21
  return (0, executeCall_js_1.executeCall)({
22
+ functionType: "image-generation",
23
+ input: prompt,
22
24
  model,
23
25
  options,
24
26
  generateResponse: (options) => model.generateImageResponse(prompt, options),
25
27
  extractOutputValue: model.extractBase64Image,
26
- getStartEvent: (metadata, settings) => ({
27
- ...metadata,
28
- functionType: "image-generation",
29
- settings,
30
- prompt,
31
- }),
32
- getAbortEvent: (metadata, settings) => ({
33
- ...metadata,
34
- functionType: "image-generation",
35
- settings,
36
- prompt,
37
- }),
38
- getFailureEvent: (metadata, settings, error) => ({
39
- ...metadata,
40
- functionType: "image-generation",
41
- settings,
42
- prompt,
43
- error,
44
- }),
45
- getSuccessEvent: (metadata, settings, response, output) => ({
46
- ...metadata,
47
- functionType: "image-generation",
48
- settings,
49
- prompt,
50
- response,
51
- generatedImage: output,
52
- }),
53
28
  });
54
29
  }
55
30
  exports.generateImage = generateImage;
@@ -16,36 +16,11 @@ import { executeCall } from "../executeCall.js";
16
16
  */
17
17
  export function generateImage(model, prompt, options) {
18
18
  return executeCall({
19
+ functionType: "image-generation",
20
+ input: prompt,
19
21
  model,
20
22
  options,
21
23
  generateResponse: (options) => model.generateImageResponse(prompt, options),
22
24
  extractOutputValue: model.extractBase64Image,
23
- getStartEvent: (metadata, settings) => ({
24
- ...metadata,
25
- functionType: "image-generation",
26
- settings,
27
- prompt,
28
- }),
29
- getAbortEvent: (metadata, settings) => ({
30
- ...metadata,
31
- functionType: "image-generation",
32
- settings,
33
- prompt,
34
- }),
35
- getFailureEvent: (metadata, settings, error) => ({
36
- ...metadata,
37
- functionType: "image-generation",
38
- settings,
39
- prompt,
40
- error,
41
- }),
42
- getSuccessEvent: (metadata, settings, response, output) => ({
43
- ...metadata,
44
- functionType: "image-generation",
45
- settings,
46
- prompt,
47
- response,
48
- generatedImage: output,
49
- }),
50
25
  });
51
26
  }
@@ -1,20 +1,7 @@
1
1
  import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
2
- export type JsonGenerationStartedEvent = BaseModelCallStartedEvent & {
2
+ export interface JsonGenerationStartedEvent extends BaseModelCallStartedEvent {
3
3
  functionType: "json-generation" | "json-or-text-generation";
4
- settings: unknown;
5
- prompt: unknown;
6
- };
4
+ }
7
5
  export type JsonGenerationFinishedEvent = BaseModelCallFinishedEvent & {
8
6
  functionType: "json-generation" | "json-or-text-generation";
9
- settings: unknown;
10
- prompt: unknown;
11
- } & ({
12
- status: "success";
13
- response: unknown;
14
- generatedJson: unknown;
15
- } | {
16
- status: "error";
17
- error: unknown;
18
- } | {
19
- status: "abort";
20
- });
7
+ };
@@ -6,6 +6,8 @@ const SchemaValidationError_js_1 = require("./SchemaValidationError.cjs");
6
6
  function generateJson(model, schemaDefinition, prompt, options) {
7
7
  const expandedPrompt = prompt(schemaDefinition);
8
8
  return (0, executeCall_js_1.executeCall)({
9
+ functionType: "json-generation",
10
+ input: expandedPrompt,
9
11
  model,
10
12
  options,
11
13
  generateResponse: (options) => model.generateJsonResponse(expandedPrompt, options),
@@ -21,33 +23,6 @@ function generateJson(model, schemaDefinition, prompt, options) {
21
23
  }
22
24
  return parseResult.data;
23
25
  },
24
- getStartEvent: (metadata, settings) => ({
25
- ...metadata,
26
- functionType: "json-generation",
27
- settings,
28
- prompt,
29
- }),
30
- getAbortEvent: (metadata, settings) => ({
31
- ...metadata,
32
- functionType: "json-generation",
33
- settings,
34
- prompt,
35
- }),
36
- getFailureEvent: (metadata, settings, error) => ({
37
- ...metadata,
38
- functionType: "json-generation",
39
- settings,
40
- prompt,
41
- error,
42
- }),
43
- getSuccessEvent: (metadata, settings, response, output) => ({
44
- ...metadata,
45
- functionType: "json-generation",
46
- settings,
47
- prompt,
48
- response,
49
- generatedJson: output,
50
- }),
51
26
  });
52
27
  }
53
28
  exports.generateJson = generateJson;
@@ -3,6 +3,8 @@ import { SchemaValidationError } from "./SchemaValidationError.js";
3
3
  export function generateJson(model, schemaDefinition, prompt, options) {
4
4
  const expandedPrompt = prompt(schemaDefinition);
5
5
  return executeCall({
6
+ functionType: "json-generation",
7
+ input: expandedPrompt,
6
8
  model,
7
9
  options,
8
10
  generateResponse: (options) => model.generateJsonResponse(expandedPrompt, options),
@@ -18,32 +20,5 @@ export function generateJson(model, schemaDefinition, prompt, options) {
18
20
  }
19
21
  return parseResult.data;
20
22
  },
21
- getStartEvent: (metadata, settings) => ({
22
- ...metadata,
23
- functionType: "json-generation",
24
- settings,
25
- prompt,
26
- }),
27
- getAbortEvent: (metadata, settings) => ({
28
- ...metadata,
29
- functionType: "json-generation",
30
- settings,
31
- prompt,
32
- }),
33
- getFailureEvent: (metadata, settings, error) => ({
34
- ...metadata,
35
- functionType: "json-generation",
36
- settings,
37
- prompt,
38
- error,
39
- }),
40
- getSuccessEvent: (metadata, settings, response, output) => ({
41
- ...metadata,
42
- functionType: "json-generation",
43
- settings,
44
- prompt,
45
- response,
46
- generatedJson: output,
47
- }),
48
23
  });
49
24
  }
@@ -7,6 +7,8 @@ const SchemaValidationError_js_1 = require("./SchemaValidationError.cjs");
7
7
  function generateJsonOrText(model, schemaDefinitions, prompt, options) {
8
8
  const expandedPrompt = prompt(schemaDefinitions);
9
9
  return (0, executeCall_js_1.executeCall)({
10
+ functionType: "json-or-text-generation",
11
+ input: expandedPrompt,
10
12
  model,
11
13
  options,
12
14
  generateResponse: (options) => model.generateJsonResponse(expandedPrompt, options),
@@ -34,33 +36,6 @@ function generateJsonOrText(model, schemaDefinitions, prompt, options) {
34
36
  text: text, // text is string | null, which is part of the response for schema values
35
37
  };
36
38
  },
37
- getStartEvent: (metadata, settings) => ({
38
- ...metadata,
39
- functionType: "json-or-text-generation",
40
- settings,
41
- prompt,
42
- }),
43
- getAbortEvent: (metadata, settings) => ({
44
- ...metadata,
45
- functionType: "json-or-text-generation",
46
- settings,
47
- prompt,
48
- }),
49
- getFailureEvent: (metadata, settings, error) => ({
50
- ...metadata,
51
- functionType: "json-or-text-generation",
52
- settings,
53
- prompt,
54
- error,
55
- }),
56
- getSuccessEvent: (metadata, settings, response, output) => ({
57
- ...metadata,
58
- functionType: "json-or-text-generation",
59
- settings,
60
- prompt,
61
- response,
62
- generatedJson: output,
63
- }),
64
39
  });
65
40
  }
66
41
  exports.generateJsonOrText = generateJsonOrText;
@@ -4,6 +4,8 @@ import { SchemaValidationError } from "./SchemaValidationError.js";
4
4
  export function generateJsonOrText(model, schemaDefinitions, prompt, options) {
5
5
  const expandedPrompt = prompt(schemaDefinitions);
6
6
  return executeCall({
7
+ functionType: "json-or-text-generation",
8
+ input: expandedPrompt,
7
9
  model,
8
10
  options,
9
11
  generateResponse: (options) => model.generateJsonResponse(expandedPrompt, options),
@@ -31,32 +33,5 @@ export function generateJsonOrText(model, schemaDefinitions, prompt, options) {
31
33
  text: text, // text is string | null, which is part of the response for schema values
32
34
  };
33
35
  },
34
- getStartEvent: (metadata, settings) => ({
35
- ...metadata,
36
- functionType: "json-or-text-generation",
37
- settings,
38
- prompt,
39
- }),
40
- getAbortEvent: (metadata, settings) => ({
41
- ...metadata,
42
- functionType: "json-or-text-generation",
43
- settings,
44
- prompt,
45
- }),
46
- getFailureEvent: (metadata, settings, error) => ({
47
- ...metadata,
48
- functionType: "json-or-text-generation",
49
- settings,
50
- prompt,
51
- error,
52
- }),
53
- getSuccessEvent: (metadata, settings, response, output) => ({
54
- ...metadata,
55
- functionType: "json-or-text-generation",
56
- settings,
57
- prompt,
58
- response,
59
- generatedJson: output,
60
- }),
61
36
  });
62
37
  }
@@ -1,20 +1,20 @@
1
1
  import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
2
- export type TextGenerationStartedEvent = BaseModelCallStartedEvent & {
2
+ export interface TextGenerationStartedEvent extends BaseModelCallStartedEvent {
3
3
  functionType: "text-generation";
4
- settings: unknown;
5
4
  prompt: unknown;
6
- };
7
- export type TextGenerationFinishedEvent = BaseModelCallFinishedEvent & {
8
- functionType: "text-generation";
9
- settings: unknown;
10
- prompt: unknown;
11
- } & ({
5
+ }
6
+ export type TextGenerationFinishedEventResult = {
12
7
  status: "success";
13
8
  response: unknown;
14
- generatedText: string;
9
+ output: string;
15
10
  } | {
16
11
  status: "error";
17
12
  error: unknown;
18
13
  } | {
19
14
  status: "abort";
20
- });
15
+ };
16
+ export interface TextGenerationFinishedEvent extends BaseModelCallFinishedEvent {
17
+ functionType: "text-generation";
18
+ prompt: unknown;
19
+ result: TextGenerationFinishedEventResult;
20
+ }
@@ -1,20 +1,7 @@
1
1
  import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
2
- export type TextStreamingStartedEvent = BaseModelCallStartedEvent & {
2
+ export interface TextStreamingStartedEvent extends BaseModelCallStartedEvent {
3
3
  functionType: "text-streaming";
4
- settings: unknown;
5
- prompt: unknown;
6
- };
7
- export type TextStreamingFinishedEvent = BaseModelCallFinishedEvent & {
4
+ }
5
+ export interface TextStreamingFinishedEvent extends BaseModelCallFinishedEvent {
8
6
  functionType: "text-streaming";
9
- settings: unknown;
10
- prompt: unknown;
11
- } & ({
12
- status: "success";
13
- response: unknown;
14
- generatedText: string;
15
- } | {
16
- status: "error";
17
- error: unknown;
18
- } | {
19
- status: "abort";
20
- });
7
+ }
@@ -18,6 +18,8 @@ function generateText(
18
18
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
19
  model, prompt, options) {
20
20
  return (0, executeCall_js_1.executeCall)({
21
+ functionType: "text-generation",
22
+ input: prompt,
21
23
  model,
22
24
  options,
23
25
  generateResponse: (options) => model.generateTextResponse(prompt, options),
@@ -27,33 +29,6 @@ model, prompt, options) {
27
29
  ? model.extractText(result).trim()
28
30
  : model.extractText(result);
29
31
  },
30
- getStartEvent: (metadata, settings) => ({
31
- ...metadata,
32
- functionType: "text-generation",
33
- settings,
34
- prompt,
35
- }),
36
- getAbortEvent: (metadata, settings) => ({
37
- ...metadata,
38
- functionType: "text-generation",
39
- settings,
40
- prompt,
41
- }),
42
- getFailureEvent: (metadata, settings, error) => ({
43
- ...metadata,
44
- functionType: "text-generation",
45
- settings,
46
- prompt,
47
- error,
48
- }),
49
- getSuccessEvent: (metadata, settings, response, output) => ({
50
- ...metadata,
51
- functionType: "text-generation",
52
- settings,
53
- prompt,
54
- response,
55
- generatedText: output,
56
- }),
57
32
  });
58
33
  }
59
34
  exports.generateText = generateText;
@@ -15,6 +15,8 @@ export function generateText(
15
15
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
16
  model, prompt, options) {
17
17
  return executeCall({
18
+ functionType: "text-generation",
19
+ input: prompt,
18
20
  model,
19
21
  options,
20
22
  generateResponse: (options) => model.generateTextResponse(prompt, options),
@@ -24,32 +26,5 @@ model, prompt, options) {
24
26
  ? model.extractText(result).trim()
25
27
  : model.extractText(result);
26
28
  },
27
- getStartEvent: (metadata, settings) => ({
28
- ...metadata,
29
- functionType: "text-generation",
30
- settings,
31
- prompt,
32
- }),
33
- getAbortEvent: (metadata, settings) => ({
34
- ...metadata,
35
- functionType: "text-generation",
36
- settings,
37
- prompt,
38
- }),
39
- getFailureEvent: (metadata, settings, error) => ({
40
- ...metadata,
41
- functionType: "text-generation",
42
- settings,
43
- prompt,
44
- error,
45
- }),
46
- getSuccessEvent: (metadata, settings, response, output) => ({
47
- ...metadata,
48
- functionType: "text-generation",
49
- settings,
50
- prompt,
51
- response,
52
- generatedText: output,
53
- }),
54
29
  });
55
30
  }
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.streamText = exports.StreamTextPromise = void 0;
4
4
  const nanoid_1 = require("nanoid");
5
- const FunctionEventSource_js_1 = require("../../run/FunctionEventSource.cjs");
6
- const GlobalFunctionObservers_js_1 = require("../../run/GlobalFunctionObservers.cjs");
5
+ const FunctionEventSource_js_1 = require("../../core/FunctionEventSource.cjs");
6
+ const GlobalFunctionObservers_js_1 = require("../../core/GlobalFunctionObservers.cjs");
7
7
  const DurationMeasurement_js_1 = require("../../util/DurationMeasurement.cjs");
8
8
  const AbortError_js_1 = require("../../util/api/AbortError.cjs");
9
9
  const runSafe_js_1 = require("../../util/runSafe.cjs");
@@ -74,15 +74,15 @@ async function doStreamText(model, prompt, options) {
74
74
  userId: run?.userId,
75
75
  functionId: options?.functionId,
76
76
  model: model.modelInformation,
77
+ functionType: "text-streaming",
78
+ input: prompt,
79
+ settings,
77
80
  timestamp: durationMeasurement.startDate,
78
81
  startTimestamp: durationMeasurement.startDate,
79
82
  };
80
83
  eventSource.notify({
81
84
  ...startMetadata,
82
- functionType: "text-streaming",
83
85
  eventType: "started",
84
- settings,
85
- prompt,
86
86
  });
87
87
  const result = await (0, runSafe_js_1.runSafe)(async () => (0, extractTextDeltas_js_1.extractTextDeltas)({
88
88
  deltaIterable: await model.generateDeltaStreamResponse(prompt, {
@@ -100,12 +100,11 @@ async function doStreamText(model, prompt, options) {
100
100
  };
101
101
  eventSource.notify({
102
102
  ...finishMetadata,
103
- functionType: "text-streaming",
104
- status: "success",
105
- settings,
106
- prompt,
107
- response: lastFullDelta,
108
- generatedText: fullText,
103
+ result: {
104
+ status: "success",
105
+ response: lastFullDelta,
106
+ output: fullText,
107
+ },
109
108
  });
110
109
  },
111
110
  onError: (error) => {
@@ -118,18 +117,16 @@ async function doStreamText(model, prompt, options) {
118
117
  eventSource.notify(error instanceof AbortError_js_1.AbortError
119
118
  ? {
120
119
  ...finishMetadata,
121
- functionType: "text-streaming",
122
- status: "abort",
123
- settings,
124
- prompt,
120
+ result: {
121
+ status: "abort",
122
+ },
125
123
  }
126
124
  : {
127
125
  ...finishMetadata,
128
- functionType: "text-streaming",
129
- status: "error",
130
- settings,
131
- prompt,
132
- error,
126
+ result: {
127
+ status: "error",
128
+ error,
129
+ },
133
130
  });
134
131
  },
135
132
  }));
@@ -143,20 +140,18 @@ async function doStreamText(model, prompt, options) {
143
140
  if (result.isAborted) {
144
141
  eventSource.notify({
145
142
  ...finishMetadata,
146
- functionType: "text-streaming",
147
- status: "abort",
148
- settings,
149
- prompt,
143
+ result: {
144
+ status: "abort",
145
+ },
150
146
  });
151
147
  throw new AbortError_js_1.AbortError();
152
148
  }
153
149
  eventSource.notify({
154
150
  ...finishMetadata,
155
- functionType: "text-streaming",
156
- status: "error",
157
- settings,
158
- prompt,
159
- error: result.error,
151
+ result: {
152
+ status: "error",
153
+ error: result.error,
154
+ },
160
155
  });
161
156
  throw result.error;
162
157
  }