modelfusion 0.20.1 → 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 (149) hide show
  1. package/README.md +5 -7
  2. package/composed-function/summarize/SummarizationFunction.d.ts +3 -3
  3. package/composed-function/summarize/summarizeRecursively.d.ts +1 -1
  4. package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.d.ts +1 -1
  5. package/{run → core}/ConsoleLogger.cjs +1 -4
  6. package/core/ConsoleLogger.d.ts +5 -0
  7. package/core/ConsoleLogger.js +5 -0
  8. package/{run → core}/DefaultRun.cjs +2 -5
  9. package/{run → core}/DefaultRun.d.ts +5 -5
  10. package/{run → core}/DefaultRun.js +2 -5
  11. package/core/FunctionEvent.d.ts +75 -0
  12. package/{run/RunFunctionEventSource.js → core/FunctionEventSource.cjs} +7 -13
  13. package/core/FunctionEventSource.d.ts +12 -0
  14. package/{run/RunFunctionEventSource.cjs → core/FunctionEventSource.js} +3 -17
  15. package/core/FunctionObserver.d.ts +7 -0
  16. package/core/FunctionOptions.d.ts +19 -0
  17. package/core/GlobalFunctionObservers.cjs +12 -0
  18. package/core/GlobalFunctionObservers.d.ts +3 -0
  19. package/core/GlobalFunctionObservers.js +7 -0
  20. package/{run → core}/Run.d.ts +2 -2
  21. package/{run → core}/index.cjs +5 -5
  22. package/core/index.d.ts +9 -0
  23. package/core/index.js +9 -0
  24. package/index.cjs +1 -1
  25. package/index.d.ts +1 -1
  26. package/index.js +1 -1
  27. package/model-function/Model.d.ts +5 -2
  28. package/model-function/ModelCallEvent.d.ts +20 -5
  29. package/model-function/ModelFunctionOptions.d.ts +4 -0
  30. package/model-function/SuccessfulModelCall.cjs +6 -16
  31. package/model-function/SuccessfulModelCall.d.ts +2 -2
  32. package/model-function/SuccessfulModelCall.js +6 -16
  33. package/model-function/embed-text/TextEmbeddingEvent.d.ts +15 -17
  34. package/model-function/embed-text/TextEmbeddingModel.d.ts +3 -3
  35. package/model-function/embed-text/embedText.cjs +6 -67
  36. package/model-function/embed-text/embedText.d.ts +4 -4
  37. package/model-function/embed-text/embedText.js +6 -67
  38. package/model-function/executeCall.cjs +49 -14
  39. package/model-function/executeCall.d.ts +9 -10
  40. package/model-function/executeCall.js +49 -14
  41. package/model-function/generate-image/ImageGenerationEvent.d.ts +12 -16
  42. package/model-function/generate-image/ImageGenerationModel.d.ts +2 -2
  43. package/model-function/generate-image/generateImage.cjs +2 -30
  44. package/model-function/generate-image/generateImage.d.ts +2 -2
  45. package/model-function/generate-image/generateImage.js +2 -30
  46. package/model-function/generate-json/GenerateJsonModel.d.ts +2 -2
  47. package/model-function/generate-json/GenerateJsonOrTextModel.d.ts +2 -2
  48. package/model-function/generate-json/JsonGenerationEvent.d.ts +6 -21
  49. package/model-function/generate-json/JsonTextGenerationModel.d.ts +2 -2
  50. package/model-function/generate-json/generateJson.cjs +2 -30
  51. package/model-function/generate-json/generateJson.d.ts +2 -2
  52. package/model-function/generate-json/generateJson.js +2 -30
  53. package/model-function/generate-json/generateJsonOrText.cjs +2 -30
  54. package/model-function/generate-json/generateJsonOrText.d.ts +2 -2
  55. package/model-function/generate-json/generateJsonOrText.js +2 -30
  56. package/model-function/generate-text/TextGenerationEvent.d.ts +13 -15
  57. package/model-function/generate-text/TextGenerationModel.d.ts +3 -3
  58. package/model-function/generate-text/TextStreamingEvent.d.ts +7 -22
  59. package/model-function/generate-text/generateText.cjs +2 -30
  60. package/model-function/generate-text/generateText.d.ts +2 -2
  61. package/model-function/generate-text/generateText.js +2 -30
  62. package/model-function/generate-text/streamText.cjs +52 -42
  63. package/model-function/generate-text/streamText.d.ts +5 -5
  64. package/model-function/generate-text/streamText.js +52 -42
  65. package/model-function/index.cjs +1 -1
  66. package/model-function/index.d.ts +1 -1
  67. package/model-function/index.js +1 -1
  68. package/model-function/synthesize-speech/SpeechSynthesisEvent.d.ts +14 -15
  69. package/model-function/synthesize-speech/SpeechSynthesisModel.d.ts +2 -2
  70. package/model-function/synthesize-speech/synthesizeSpeech.cjs +2 -30
  71. package/model-function/synthesize-speech/synthesizeSpeech.d.ts +2 -2
  72. package/model-function/synthesize-speech/synthesizeSpeech.js +2 -30
  73. package/model-function/transcribe-speech/TranscriptionEvent.d.ts +12 -16
  74. package/model-function/transcribe-speech/TranscriptionModel.d.ts +2 -2
  75. package/model-function/transcribe-speech/transcribe.cjs +2 -30
  76. package/model-function/transcribe-speech/transcribe.d.ts +2 -2
  77. package/model-function/transcribe-speech/transcribe.js +2 -30
  78. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +3 -3
  79. package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +6 -6
  80. package/model-provider/cohere/CohereTextGenerationModel.d.ts +4 -4
  81. package/model-provider/cohere/CohereTokenizer.d.ts +1 -1
  82. package/model-provider/elevenlabs/ElevenLabsSpeechSynthesisModel.d.ts +2 -2
  83. package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.d.ts +3 -3
  84. package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +3 -3
  85. package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.d.ts +3 -3
  86. package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +4 -4
  87. package/model-provider/llamacpp/LlamaCppTokenizer.d.ts +1 -1
  88. package/model-provider/openai/OpenAIImageGenerationModel.d.ts +3 -3
  89. package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +3 -3
  90. package/model-provider/openai/OpenAITextGenerationModel.d.ts +4 -4
  91. package/model-provider/openai/OpenAITranscriptionModel.d.ts +3 -3
  92. package/model-provider/openai/chat/OpenAIChatModel.d.ts +5 -5
  93. package/model-provider/stability/StabilityImageGenerationModel.d.ts +3 -3
  94. package/package.json +1 -1
  95. package/prompt/PromptFormatTextGenerationModel.d.ts +3 -3
  96. package/text-chunk/SimilarTextChunksFromVectorIndexRetriever.cjs +1 -0
  97. package/text-chunk/SimilarTextChunksFromVectorIndexRetriever.d.ts +2 -2
  98. package/text-chunk/SimilarTextChunksFromVectorIndexRetriever.js +1 -0
  99. package/text-chunk/retrieve-text-chunks/TextChunkRetriever.d.ts +2 -2
  100. package/text-chunk/retrieve-text-chunks/retrieveTextChunks.d.ts +2 -2
  101. package/text-chunk/split/SplitFunction.d.ts +3 -3
  102. package/text-chunk/upsertTextChunks.d.ts +2 -2
  103. package/tool/ExecuteToolEvent.d.ts +9 -20
  104. package/tool/Tool.d.ts +3 -3
  105. package/tool/WebSearchTool.cjs +25 -0
  106. package/tool/WebSearchTool.d.ts +57 -1
  107. package/tool/WebSearchTool.js +25 -0
  108. package/tool/executeTool.cjs +39 -31
  109. package/tool/executeTool.d.ts +5 -4
  110. package/tool/executeTool.js +39 -31
  111. package/tool/useTool.cjs +2 -6
  112. package/tool/useTool.d.ts +2 -2
  113. package/tool/useTool.js +2 -6
  114. package/tool/useToolOrGenerateText.cjs +1 -3
  115. package/tool/useToolOrGenerateText.d.ts +2 -2
  116. package/tool/useToolOrGenerateText.js +1 -3
  117. package/util/DurationMeasurement.cjs +6 -0
  118. package/util/DurationMeasurement.d.ts +1 -0
  119. package/util/DurationMeasurement.js +6 -0
  120. package/util/api/postToApi.cjs +8 -0
  121. package/util/api/postToApi.js +8 -0
  122. package/vector-index/VectorIndex.d.ts +1 -1
  123. package/vector-index/memory/MemoryVectorIndex.d.ts +1 -1
  124. package/vector-index/pinecone/PineconeVectorIndex.d.ts +1 -1
  125. package/model-function/FunctionOptions.d.ts +0 -6
  126. package/run/ConsoleLogger.d.ts +0 -6
  127. package/run/ConsoleLogger.js +0 -8
  128. package/run/IdMetadata.d.ts +0 -7
  129. package/run/RunFunction.d.ts +0 -9
  130. package/run/RunFunctionEvent.d.ts +0 -12
  131. package/run/RunFunctionEventSource.d.ts +0 -13
  132. package/run/RunFunctionObserver.cjs +0 -2
  133. package/run/RunFunctionObserver.d.ts +0 -5
  134. package/run/RunFunctionObserver.js +0 -1
  135. package/run/index.d.ts +0 -9
  136. package/run/index.js +0 -9
  137. /package/{model-function/FunctionOptions.cjs → core/FunctionEvent.cjs} +0 -0
  138. /package/{model-function/FunctionOptions.js → core/FunctionEvent.js} +0 -0
  139. /package/{run/IdMetadata.cjs → core/FunctionObserver.cjs} +0 -0
  140. /package/{run/IdMetadata.js → core/FunctionObserver.js} +0 -0
  141. /package/{run/Run.cjs → core/FunctionOptions.cjs} +0 -0
  142. /package/{run/Run.js → core/FunctionOptions.js} +0 -0
  143. /package/{run/RunFunction.cjs → core/Run.cjs} +0 -0
  144. /package/{run/RunFunction.js → core/Run.js} +0 -0
  145. /package/{run → core}/Vector.cjs +0 -0
  146. /package/{run → core}/Vector.d.ts +0 -0
  147. /package/{run → core}/Vector.js +0 -0
  148. /package/{run/RunFunctionEvent.cjs → model-function/ModelFunctionOptions.cjs} +0 -0
  149. /package/{run/RunFunctionEvent.js → model-function/ModelFunctionOptions.js} +0 -0
@@ -1,13 +1,14 @@
1
- import { FunctionOptions } from "../model-function/FunctionOptions.js";
2
- import { Tool } from "./Tool.js";
3
1
  import { z } from "zod";
2
+ import { FunctionOptions } from "../core/FunctionOptions.js";
3
+ import { Tool } from "./Tool.js";
4
4
  export type ExecuteToolMetadata = {
5
5
  callId: string;
6
6
  runId?: string;
7
7
  sessionId?: string;
8
8
  userId?: string;
9
9
  functionId?: string;
10
- startEpochSeconds: number;
10
+ startTimestamp: Date;
11
+ finishTimestamp: Date;
11
12
  durationInMs: number;
12
13
  };
13
14
  export declare class ExecuteToolPromise<OUTPUT> extends Promise<OUTPUT> {
@@ -28,4 +29,4 @@ export declare class ExecuteToolPromise<OUTPUT> extends Promise<OUTPUT> {
28
29
  /**
29
30
  * `executeTool` directly executes a tool with the given parameters.
30
31
  */
31
- export declare function executeTool<TOOL extends Tool<any, any, any>>(tool: TOOL, input: z.infer<TOOL["inputSchema"]>, options?: FunctionOptions<undefined>): ExecuteToolPromise<ReturnType<TOOL["execute"]>>;
32
+ export declare function executeTool<TOOL extends Tool<any, any, any>>(tool: TOOL, input: z.infer<TOOL["inputSchema"]>, options?: FunctionOptions): ExecuteToolPromise<ReturnType<TOOL["execute"]>>;
@@ -1,5 +1,6 @@
1
1
  import { nanoid as createId } from "nanoid";
2
- import { RunFunctionEventSource } from "../run/RunFunctionEventSource.js";
2
+ import { FunctionEventSource } from "../core/FunctionEventSource.js";
3
+ import { getGlobalFunctionObservers } from "../core/GlobalFunctionObservers.js";
3
4
  import { startDurationMeasurement } from "../util/DurationMeasurement.js";
4
5
  import { AbortError } from "../util/api/AbortError.js";
5
6
  import { runSafe } from "../util/runSafe.js";
@@ -47,48 +48,56 @@ export function executeTool(tool, input, options) {
47
48
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
49
  async function doExecuteTool(tool, input, options) {
49
50
  const run = options?.run;
50
- const eventSource = new RunFunctionEventSource({
51
- observers: run?.observers ?? [],
51
+ const eventSource = new FunctionEventSource({
52
+ observers: [
53
+ ...getGlobalFunctionObservers(),
54
+ ...(run?.observers ?? []),
55
+ ...(options?.observers ?? []),
56
+ ],
52
57
  errorHandler: run?.errorHandler,
53
58
  });
54
59
  const durationMeasurement = startDurationMeasurement();
55
- const startMetadata = {
60
+ const metadata = {
61
+ functionType: "execute-tool",
56
62
  callId: `call-${createId()}`,
57
63
  runId: run?.runId,
58
64
  sessionId: run?.sessionId,
59
65
  userId: run?.userId,
60
66
  functionId: options?.functionId,
61
- startEpochSeconds: durationMeasurement.startEpochSeconds,
62
- };
63
- eventSource.notifyRunFunctionStarted({
64
- type: "execute-tool-started",
65
- metadata: startMetadata,
66
- tool: tool,
67
+ toolName: tool.name,
67
68
  input,
69
+ };
70
+ eventSource.notify({
71
+ ...metadata,
72
+ eventType: "started",
73
+ timestamp: durationMeasurement.startDate,
74
+ startTimestamp: durationMeasurement.startDate,
68
75
  });
69
76
  const result = await runSafe(() => tool.execute(input, options));
70
77
  const finishMetadata = {
71
- ...startMetadata,
78
+ ...metadata,
79
+ eventType: "finished",
80
+ timestamp: new Date(),
81
+ startTimestamp: durationMeasurement.startDate,
82
+ finishTimestamp: new Date(),
72
83
  durationInMs: durationMeasurement.durationInMs,
73
84
  };
74
85
  if (!result.ok) {
75
86
  if (result.isAborted) {
76
- eventSource.notifyRunFunctionFinished({
77
- type: "execute-tool-finished",
78
- status: "abort",
79
- metadata: finishMetadata,
80
- tool: tool,
81
- input,
87
+ eventSource.notify({
88
+ ...finishMetadata,
89
+ result: {
90
+ status: "abort",
91
+ },
82
92
  });
83
93
  throw new AbortError();
84
94
  }
85
- eventSource.notifyRunFunctionFinished({
86
- type: "execute-tool-finished",
87
- status: "failure",
88
- metadata: finishMetadata,
89
- tool: tool,
90
- input,
91
- error: result.error,
95
+ eventSource.notify({
96
+ ...finishMetadata,
97
+ result: {
98
+ status: "error",
99
+ error: result.error,
100
+ },
92
101
  });
93
102
  throw new ToolExecutionError({
94
103
  toolName: tool.name,
@@ -99,13 +108,12 @@ async function doExecuteTool(tool, input, options) {
99
108
  });
100
109
  }
101
110
  const output = result.output;
102
- eventSource.notifyRunFunctionFinished({
103
- type: "execute-tool-finished",
104
- status: "success",
105
- metadata: finishMetadata,
106
- tool: tool,
107
- input,
108
- output,
111
+ eventSource.notify({
112
+ ...finishMetadata,
113
+ result: {
114
+ status: "success",
115
+ output,
116
+ },
109
117
  });
110
118
  return {
111
119
  output,
package/tool/useTool.cjs CHANGED
@@ -18,15 +18,11 @@ async function useTool(model, tool, prompt, options) {
18
18
  name: tool.name,
19
19
  description: tool.description,
20
20
  schema: tool.inputSchema,
21
- }, () => prompt(tool), {
22
- ...(options ?? {}),
23
- }).asFullResponse();
21
+ }, () => prompt(tool), options).asFullResponse();
24
22
  return {
25
23
  tool: tool.name,
26
24
  parameters: value,
27
- result: await (0, executeTool_js_1.executeTool)(tool, value, {
28
- run: options?.run,
29
- }),
25
+ result: await (0, executeTool_js_1.executeTool)(tool, value, options),
30
26
  };
31
27
  }
32
28
  exports.useTool = useTool;
package/tool/useTool.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { FunctionOptions } from "../model-function/FunctionOptions.js";
1
+ import { ModelFunctionOptions } from "../model-function/ModelFunctionOptions.js";
2
2
  import { GenerateJsonModel, GenerateJsonModelSettings } from "../model-function/generate-json/GenerateJsonModel.js";
3
3
  import { Tool } from "./Tool.js";
4
4
  /**
@@ -8,7 +8,7 @@ import { Tool } from "./Tool.js";
8
8
  * the parameters (`parameters` property, typed),
9
9
  * and the result of the tool execution (`result` property, typed).
10
10
  */
11
- export declare function useTool<PROMPT, RESPONSE, SETTINGS extends GenerateJsonModelSettings, TOOL extends Tool<any, any, any>>(model: GenerateJsonModel<PROMPT, RESPONSE, SETTINGS>, tool: TOOL, prompt: (tool: TOOL) => PROMPT, options?: FunctionOptions<SETTINGS>): Promise<{
11
+ export declare function useTool<PROMPT, RESPONSE, SETTINGS extends GenerateJsonModelSettings, TOOL extends Tool<any, any, any>>(model: GenerateJsonModel<PROMPT, RESPONSE, SETTINGS>, tool: TOOL, prompt: (tool: TOOL) => PROMPT, options?: ModelFunctionOptions<SETTINGS>): Promise<{
12
12
  tool: TOOL["name"];
13
13
  parameters: TOOL["inputSchema"];
14
14
  result: Awaited<ReturnType<TOOL["execute"]>>;
package/tool/useTool.js CHANGED
@@ -15,14 +15,10 @@ export async function useTool(model, tool, prompt, options) {
15
15
  name: tool.name,
16
16
  description: tool.description,
17
17
  schema: tool.inputSchema,
18
- }, () => prompt(tool), {
19
- ...(options ?? {}),
20
- }).asFullResponse();
18
+ }, () => prompt(tool), options).asFullResponse();
21
19
  return {
22
20
  tool: tool.name,
23
21
  parameters: value,
24
- result: await executeTool(tool, value, {
25
- run: options?.run,
26
- }),
22
+ result: await executeTool(tool, value, options),
27
23
  };
28
24
  }
@@ -25,9 +25,7 @@ async function useToolOrGenerateText(model, tools, prompt, options) {
25
25
  throw new NoSuchToolError_js_1.NoSuchToolError(schema.toString());
26
26
  }
27
27
  const toolParameters = modelResponse.value;
28
- const result = await (0, executeTool_js_1.executeTool)(tool, toolParameters, {
29
- run: options?.run,
30
- });
28
+ const result = await (0, executeTool_js_1.executeTool)(tool, toolParameters, options);
31
29
  return {
32
30
  tool: schema,
33
31
  result,
@@ -1,4 +1,4 @@
1
- import { FunctionOptions } from "../model-function/FunctionOptions.js";
1
+ import { ModelFunctionOptions } from "../model-function/ModelFunctionOptions.js";
2
2
  import { GenerateJsonOrTextModel, GenerateJsonOrTextModelSettings, GenerateJsonOrTextPrompt } from "../model-function/generate-json/GenerateJsonOrTextModel.js";
3
3
  import { Tool } from "./Tool.js";
4
4
  type ToolArray<T extends Tool<any, any, any>[]> = T;
@@ -14,7 +14,7 @@ type ToToolUnion<T> = {
14
14
  } : never;
15
15
  }[keyof T];
16
16
  type ToOutputValue<TOOLS extends ToolArray<Tool<any, any, any>[]>> = ToToolUnion<ToToolMap<TOOLS>>;
17
- export declare function useToolOrGenerateText<PROMPT, RESPONSE, SETTINGS extends GenerateJsonOrTextModelSettings, TOOLS extends Array<Tool<any, any, any>>>(model: GenerateJsonOrTextModel<PROMPT, RESPONSE, SETTINGS>, tools: TOOLS, prompt: (tools: TOOLS) => PROMPT & GenerateJsonOrTextPrompt<RESPONSE>, options?: FunctionOptions<SETTINGS>): Promise<{
17
+ export declare function useToolOrGenerateText<PROMPT, RESPONSE, SETTINGS extends GenerateJsonOrTextModelSettings, TOOLS extends Array<Tool<any, any, any>>>(model: GenerateJsonOrTextModel<PROMPT, RESPONSE, SETTINGS>, tools: TOOLS, prompt: (tools: TOOLS) => PROMPT & GenerateJsonOrTextPrompt<RESPONSE>, options?: ModelFunctionOptions<SETTINGS>): Promise<{
18
18
  tool: null;
19
19
  parameters: null;
20
20
  result: null;
@@ -22,9 +22,7 @@ export async function useToolOrGenerateText(model, tools, prompt, options) {
22
22
  throw new NoSuchToolError(schema.toString());
23
23
  }
24
24
  const toolParameters = modelResponse.value;
25
- const result = await executeTool(tool, toolParameters, {
26
- run: options?.run,
27
- });
25
+ const result = await executeTool(tool, toolParameters, options);
28
26
  return {
29
27
  tool: schema,
30
28
  result,
@@ -20,6 +20,9 @@ class PerformanceNowDurationMeasurement {
20
20
  get startEpochSeconds() {
21
21
  return Math.floor((globalThis.performance.timeOrigin + this.startTime) / 1000);
22
22
  }
23
+ get startDate() {
24
+ return new Date(this.startEpochSeconds * 1000);
25
+ }
23
26
  get durationInMs() {
24
27
  return Math.ceil(globalThis.performance.now() - this.startTime);
25
28
  }
@@ -36,6 +39,9 @@ class DateDurationMeasurement {
36
39
  get startEpochSeconds() {
37
40
  return Math.floor(this.startTime / 1000);
38
41
  }
42
+ get startDate() {
43
+ return new Date(this.startTime);
44
+ }
39
45
  get durationInMs() {
40
46
  return Date.now() - this.startTime;
41
47
  }
@@ -1,5 +1,6 @@
1
1
  export declare function startDurationMeasurement(): DurationMeasurement;
2
2
  export interface DurationMeasurement {
3
3
  startEpochSeconds: number;
4
+ startDate: Date;
4
5
  durationInMs: number;
5
6
  }
@@ -16,6 +16,9 @@ class PerformanceNowDurationMeasurement {
16
16
  get startEpochSeconds() {
17
17
  return Math.floor((globalThis.performance.timeOrigin + this.startTime) / 1000);
18
18
  }
19
+ get startDate() {
20
+ return new Date(this.startEpochSeconds * 1000);
21
+ }
19
22
  get durationInMs() {
20
23
  return Math.ceil(globalThis.performance.now() - this.startTime);
21
24
  }
@@ -32,6 +35,9 @@ class DateDurationMeasurement {
32
35
  get startEpochSeconds() {
33
36
  return Math.floor(this.startTime / 1000);
34
37
  }
38
+ get startDate() {
39
+ return new Date(this.startTime);
40
+ }
35
41
  get durationInMs() {
36
42
  return Date.now() - this.startTime;
37
43
  }
@@ -105,6 +105,14 @@ const postToApi = async ({ url, headers = {}, body, successfulResponseHandler, f
105
105
  throw error;
106
106
  }
107
107
  }
108
+ // unwrap original error when fetch failed (for easier debugging):
109
+ if (error instanceof TypeError && error.message === "fetch failed") {
110
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
111
+ if (error.cause != null) {
112
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
113
+ throw error.cause;
114
+ }
115
+ }
108
116
  throw error;
109
117
  }
110
118
  };
@@ -98,6 +98,14 @@ export const postToApi = async ({ url, headers = {}, body, successfulResponseHan
98
98
  throw error;
99
99
  }
100
100
  }
101
+ // unwrap original error when fetch failed (for easier debugging):
102
+ if (error instanceof TypeError && error.message === "fetch failed") {
103
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
104
+ if (error.cause != null) {
105
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
106
+ throw error.cause;
107
+ }
108
+ }
101
109
  throw error;
102
110
  }
103
111
  };
@@ -1,4 +1,4 @@
1
- import { Vector } from "../run/Vector.js";
1
+ import { Vector } from "../core/Vector.js";
2
2
  export interface VectorIndex<DATA, INDEX> {
3
3
  upsertMany(data: Array<{
4
4
  id: string;
@@ -1,5 +1,5 @@
1
1
  import z from "zod";
2
- import { Vector } from "../../run/Vector.js";
2
+ import { Vector } from "../../core/Vector.js";
3
3
  import { VectorIndex } from "../VectorIndex.js";
4
4
  /**
5
5
  * A very simple vector index that stores all entries in memory. Useful when you only have
@@ -1,6 +1,6 @@
1
1
  import { VectorOperationsApi } from "@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch/index.js";
2
2
  import { z } from "zod";
3
- import { Vector } from "../../run/Vector.js";
3
+ import { Vector } from "../../core/Vector.js";
4
4
  import { VectorIndex } from "../VectorIndex.js";
5
5
  export declare class PineconeVectorIndex<DATA extends object | undefined> implements VectorIndex<DATA, PineconeVectorIndex<DATA>> {
6
6
  readonly index: VectorOperationsApi;
@@ -1,6 +0,0 @@
1
- import { Run } from "../run/Run.js";
2
- export interface FunctionOptions<SETTINGS> {
3
- functionId?: string;
4
- settings?: Partial<SETTINGS>;
5
- run?: Run;
6
- }
@@ -1,6 +0,0 @@
1
- import { RunFunctionFinishedEvent, RunFunctionStartedEvent } from "./RunFunctionEvent.js";
2
- import { RunFunctionObserver } from "./RunFunctionObserver.js";
3
- export declare class ConsoleLogger implements RunFunctionObserver {
4
- onRunFunctionStarted(event: RunFunctionStartedEvent): void;
5
- onRunFunctionFinished(event: RunFunctionFinishedEvent): void;
6
- }
@@ -1,8 +0,0 @@
1
- export class ConsoleLogger {
2
- onRunFunctionStarted(event) {
3
- console.log(JSON.stringify(event, null, 2));
4
- }
5
- onRunFunctionFinished(event) {
6
- console.log(JSON.stringify(event, null, 2));
7
- }
8
- }
@@ -1,7 +0,0 @@
1
- export type IdMetadata = {
2
- callId?: string | undefined;
3
- functionId?: string | undefined;
4
- runId?: string | undefined;
5
- sessionId?: string | undefined;
6
- userId?: string | undefined;
7
- };
@@ -1,9 +0,0 @@
1
- import { Run } from "./Run.js";
2
- /**
3
- * Standardized function signature for functions that are part of a run.
4
- *
5
- * This enables wrapping and chaining of run functions.
6
- */
7
- export type RunFunction<INPUT, OUTPUT> = (input: INPUT, options?: {
8
- run?: Run;
9
- }) => PromiseLike<OUTPUT>;
@@ -1,12 +0,0 @@
1
- import { ExecuteToolFinishedEvent, ExecuteToolStartedEvent } from "../tool/ExecuteToolEvent.js";
2
- import { ModelCallFinishedEvent, ModelCallStartedEvent } from "../model-function/ModelCallEvent.js";
3
- import { IdMetadata } from "./IdMetadata.js";
4
- export type RunFunctionEvent = RunFunctionStartedEvent | RunFunctionFinishedEvent;
5
- export type RunFunctionStartedEventMetadata = IdMetadata & {
6
- startEpochSeconds: number;
7
- };
8
- export type RunFunctionStartedEvent = ModelCallStartedEvent | ExecuteToolStartedEvent;
9
- export type RunFunctionFinishedEventMetadata = RunFunctionStartedEventMetadata & {
10
- durationInMs: number;
11
- };
12
- export type RunFunctionFinishedEvent = ModelCallFinishedEvent | ExecuteToolFinishedEvent;
@@ -1,13 +0,0 @@
1
- import { ErrorHandler } from "../util/ErrorHandler.js";
2
- import { RunFunctionFinishedEvent, RunFunctionStartedEvent } from "./RunFunctionEvent.js";
3
- import { RunFunctionObserver } from "./RunFunctionObserver.js";
4
- export declare class RunFunctionEventSource {
5
- readonly observers: RunFunctionObserver[];
6
- readonly errorHandler: ErrorHandler;
7
- constructor({ observers, errorHandler, }: {
8
- observers: RunFunctionObserver[];
9
- errorHandler?: ErrorHandler;
10
- });
11
- notifyRunFunctionStarted(event: RunFunctionStartedEvent): void;
12
- notifyRunFunctionFinished(event: RunFunctionFinishedEvent): void;
13
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +0,0 @@
1
- import { RunFunctionFinishedEvent, RunFunctionStartedEvent } from "./RunFunctionEvent.js";
2
- export type RunFunctionObserver = {
3
- onRunFunctionStarted?: (event: RunFunctionStartedEvent) => void;
4
- onRunFunctionFinished?: (event: RunFunctionFinishedEvent) => void;
5
- };
@@ -1 +0,0 @@
1
- export {};
package/run/index.d.ts DELETED
@@ -1,9 +0,0 @@
1
- export * from "./ConsoleLogger.js";
2
- export * from "./DefaultRun.js";
3
- export * from "./IdMetadata.js";
4
- export * from "./Run.js";
5
- export * from "./RunFunction.js";
6
- export * from "./RunFunctionEvent.js";
7
- export * from "./RunFunctionObserver.js";
8
- export * from "./RunFunctionEventSource.js";
9
- export * from "./Vector.js";
package/run/index.js DELETED
@@ -1,9 +0,0 @@
1
- export * from "./ConsoleLogger.js";
2
- export * from "./DefaultRun.js";
3
- export * from "./IdMetadata.js";
4
- export * from "./Run.js";
5
- export * from "./RunFunction.js";
6
- export * from "./RunFunctionEvent.js";
7
- export * from "./RunFunctionObserver.js";
8
- export * from "./RunFunctionEventSource.js";
9
- export * from "./Vector.js";
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes