modelfusion 0.104.0 → 0.106.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/CHANGELOG.md +60 -0
- package/README.md +8 -10
- package/core/DefaultRun.cjs +0 -4
- package/core/DefaultRun.d.ts +0 -2
- package/core/DefaultRun.js +0 -4
- package/core/ExtensionFunctionEvent.d.ts +11 -0
- package/core/FunctionEvent.d.ts +2 -2
- package/extension/index.cjs +22 -3
- package/extension/index.d.ts +5 -1
- package/extension/index.js +4 -1
- package/index.cjs +0 -3
- package/index.d.ts +0 -3
- package/index.js +0 -3
- package/model-function/Delta.d.ts +1 -2
- package/model-function/executeStreamCall.cjs +6 -4
- package/model-function/executeStreamCall.d.ts +2 -2
- package/model-function/executeStreamCall.js +6 -4
- package/model-function/generate-speech/streamSpeech.cjs +1 -2
- package/model-function/generate-speech/streamSpeech.js +1 -2
- package/model-function/generate-structure/StructureFromTextStreamingModel.cjs +25 -29
- package/model-function/generate-structure/StructureFromTextStreamingModel.d.ts +3 -1
- package/model-function/generate-structure/StructureFromTextStreamingModel.js +25 -29
- package/model-function/generate-structure/StructureGenerationModel.d.ts +2 -0
- package/model-function/generate-structure/jsonStructurePrompt.cjs +42 -6
- package/model-function/generate-structure/jsonStructurePrompt.d.ts +12 -1
- package/model-function/generate-structure/jsonStructurePrompt.js +42 -5
- package/model-function/generate-structure/streamStructure.cjs +7 -8
- package/model-function/generate-structure/streamStructure.d.ts +1 -1
- package/model-function/generate-structure/streamStructure.js +7 -8
- package/model-function/generate-text/PromptTemplateFullTextModel.cjs +35 -0
- package/model-function/generate-text/PromptTemplateFullTextModel.d.ts +41 -0
- package/model-function/generate-text/PromptTemplateFullTextModel.js +31 -0
- package/model-function/generate-text/PromptTemplateTextGenerationModel.d.ts +2 -1
- package/model-function/generate-text/PromptTemplateTextGenerationModel.js +1 -1
- package/model-function/generate-text/PromptTemplateTextStreamingModel.cjs +3 -0
- package/model-function/generate-text/PromptTemplateTextStreamingModel.d.ts +2 -1
- package/model-function/generate-text/PromptTemplateTextStreamingModel.js +3 -0
- package/model-function/generate-text/TextGenerationModel.d.ts +2 -1
- package/model-function/generate-text/index.cjs +1 -0
- package/model-function/generate-text/index.d.ts +1 -0
- package/model-function/generate-text/index.js +1 -0
- package/model-function/generate-text/prompt-template/AlpacaPromptTemplate.cjs +2 -2
- package/model-function/generate-text/prompt-template/AlpacaPromptTemplate.js +1 -1
- package/model-function/generate-text/prompt-template/ChatMLPromptTemplate.cjs +8 -5
- package/model-function/generate-text/prompt-template/ChatMLPromptTemplate.js +7 -4
- package/model-function/generate-text/prompt-template/ChatPrompt.cjs +42 -0
- package/model-function/generate-text/prompt-template/ChatPrompt.d.ts +27 -5
- package/model-function/generate-text/prompt-template/ChatPrompt.js +41 -1
- package/model-function/generate-text/prompt-template/{Content.cjs → ContentPart.cjs} +1 -1
- package/model-function/generate-text/prompt-template/ContentPart.d.ts +30 -0
- package/model-function/generate-text/prompt-template/{Content.js → ContentPart.js} +1 -1
- package/model-function/generate-text/prompt-template/InstructionPrompt.d.ts +3 -2
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.cjs +8 -5
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.d.ts +1 -1
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.js +6 -3
- package/model-function/generate-text/prompt-template/NeuralChatPromptTemplate.cjs +8 -4
- package/model-function/generate-text/prompt-template/NeuralChatPromptTemplate.js +6 -2
- package/model-function/generate-text/prompt-template/TextPromptTemplate.cjs +8 -4
- package/model-function/generate-text/prompt-template/TextPromptTemplate.js +6 -2
- package/model-function/generate-text/prompt-template/VicunaPromptTemplate.cjs +7 -3
- package/model-function/generate-text/prompt-template/VicunaPromptTemplate.js +6 -2
- package/model-function/generate-text/prompt-template/index.cjs +1 -1
- package/model-function/generate-text/prompt-template/index.d.ts +1 -1
- package/model-function/generate-text/prompt-template/index.js +1 -1
- package/model-function/generate-text/streamText.cjs +27 -28
- package/model-function/generate-text/streamText.d.ts +1 -0
- package/model-function/generate-text/streamText.js +27 -28
- package/model-function/index.cjs +0 -1
- package/model-function/index.d.ts +0 -1
- package/model-function/index.js +0 -1
- package/model-provider/anthropic/AnthropicPromptTemplate.cjs +7 -3
- package/model-provider/anthropic/AnthropicPromptTemplate.js +5 -1
- package/model-provider/anthropic/AnthropicTextGenerationModel.cjs +8 -14
- package/model-provider/anthropic/AnthropicTextGenerationModel.d.ts +11 -2
- package/model-provider/anthropic/AnthropicTextGenerationModel.js +8 -14
- package/model-provider/anthropic/AnthropicTextGenerationModel.test.cjs +44 -0
- package/model-provider/anthropic/AnthropicTextGenerationModel.test.js +42 -0
- package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +3 -3
- package/model-provider/cohere/CohereTextGenerationModel.cjs +6 -44
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +49 -15
- package/model-provider/cohere/CohereTextGenerationModel.js +7 -45
- package/model-provider/cohere/CohereTextGenerationModel.test.cjs +33 -0
- package/model-provider/cohere/CohereTextGenerationModel.test.js +31 -0
- package/model-provider/elevenlabs/ElevenLabsSpeechModel.cjs +1 -2
- package/model-provider/elevenlabs/ElevenLabsSpeechModel.js +1 -2
- package/model-provider/llamacpp/LlamaCppBakLLaVA1PromptTemplate.cjs +6 -1
- package/model-provider/llamacpp/LlamaCppBakLLaVA1PromptTemplate.js +6 -1
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +7 -14
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +171 -20
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +8 -15
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.test.cjs +37 -0
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.test.js +35 -0
- package/model-provider/mistral/MistralChatModel.cjs +30 -104
- package/model-provider/mistral/MistralChatModel.d.ts +47 -14
- package/model-provider/mistral/MistralChatModel.js +30 -104
- package/model-provider/mistral/MistralChatModel.test.cjs +51 -0
- package/model-provider/mistral/MistralChatModel.test.js +49 -0
- package/model-provider/mistral/MistralPromptTemplate.cjs +11 -4
- package/model-provider/mistral/MistralPromptTemplate.js +9 -2
- package/model-provider/mistral/MistralTextEmbeddingModel.d.ts +13 -13
- package/model-provider/ollama/OllamaChatModel.cjs +7 -43
- package/model-provider/ollama/OllamaChatModel.d.ts +67 -14
- package/model-provider/ollama/OllamaChatModel.js +8 -44
- package/model-provider/ollama/OllamaChatModel.test.cjs +27 -0
- package/model-provider/ollama/OllamaChatModel.test.js +25 -0
- package/model-provider/ollama/OllamaChatPromptTemplate.cjs +34 -4
- package/model-provider/ollama/OllamaChatPromptTemplate.js +34 -4
- package/model-provider/ollama/OllamaCompletionModel.cjs +22 -43
- package/model-provider/ollama/OllamaCompletionModel.d.ts +67 -10
- package/model-provider/ollama/OllamaCompletionModel.js +24 -45
- package/model-provider/ollama/OllamaCompletionModel.test.cjs +95 -13
- package/model-provider/ollama/OllamaCompletionModel.test.js +72 -13
- package/model-provider/openai/{chat/AbstractOpenAIChatModel.cjs → AbstractOpenAIChatModel.cjs} +71 -15
- package/model-provider/openai/{chat/AbstractOpenAIChatModel.d.ts → AbstractOpenAIChatModel.d.ts} +273 -19
- package/model-provider/openai/{chat/AbstractOpenAIChatModel.js → AbstractOpenAIChatModel.js} +71 -15
- package/model-provider/openai/{chat/OpenAIChatFunctionCallStructureGenerationModel.cjs → OpenAIChatFunctionCallStructureGenerationModel.cjs} +18 -2
- package/model-provider/openai/{chat/OpenAIChatFunctionCallStructureGenerationModel.d.ts → OpenAIChatFunctionCallStructureGenerationModel.d.ts} +41 -11
- package/model-provider/openai/{chat/OpenAIChatFunctionCallStructureGenerationModel.js → OpenAIChatFunctionCallStructureGenerationModel.js} +18 -2
- package/model-provider/openai/{chat/OpenAIChatMessage.d.ts → OpenAIChatMessage.d.ts} +3 -3
- package/model-provider/openai/{chat/OpenAIChatModel.cjs → OpenAIChatModel.cjs} +5 -5
- package/model-provider/openai/{chat/OpenAIChatModel.d.ts → OpenAIChatModel.d.ts} +12 -12
- package/model-provider/openai/{chat/OpenAIChatModel.js → OpenAIChatModel.js} +5 -5
- package/model-provider/openai/OpenAIChatModel.test.cjs +94 -0
- package/model-provider/openai/OpenAIChatModel.test.js +92 -0
- package/model-provider/openai/OpenAIChatPromptTemplate.cjs +114 -0
- package/model-provider/openai/{chat/OpenAIChatPromptTemplate.d.ts → OpenAIChatPromptTemplate.d.ts} +3 -3
- package/model-provider/openai/OpenAIChatPromptTemplate.js +107 -0
- package/model-provider/openai/OpenAICompletionModel.cjs +32 -84
- package/model-provider/openai/OpenAICompletionModel.d.ts +27 -10
- package/model-provider/openai/OpenAICompletionModel.js +33 -85
- package/model-provider/openai/OpenAICompletionModel.test.cjs +53 -0
- package/model-provider/openai/OpenAICompletionModel.test.js +51 -0
- package/model-provider/openai/OpenAIFacade.cjs +2 -2
- package/model-provider/openai/OpenAIFacade.d.ts +3 -3
- package/model-provider/openai/OpenAIFacade.js +2 -2
- package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +12 -12
- package/model-provider/openai/OpenAITranscriptionModel.d.ts +17 -17
- package/model-provider/openai/TikTokenTokenizer.d.ts +1 -1
- package/model-provider/openai/{chat/countOpenAIChatMessageTokens.cjs → countOpenAIChatMessageTokens.cjs} +2 -2
- package/model-provider/openai/{chat/countOpenAIChatMessageTokens.js → countOpenAIChatMessageTokens.js} +2 -2
- package/model-provider/openai/index.cjs +6 -7
- package/model-provider/openai/index.d.ts +5 -7
- package/model-provider/openai/index.js +5 -6
- package/model-provider/openai-compatible/OpenAICompatibleChatModel.cjs +4 -4
- package/model-provider/openai-compatible/OpenAICompatibleChatModel.d.ts +6 -6
- package/model-provider/openai-compatible/OpenAICompatibleChatModel.js +4 -4
- package/model-provider/stability/StabilityImageGenerationModel.d.ts +5 -5
- package/package.json +13 -24
- package/test/JsonTestServer.cjs +33 -0
- package/test/JsonTestServer.d.ts +7 -0
- package/test/JsonTestServer.js +29 -0
- package/test/StreamingTestServer.cjs +55 -0
- package/test/StreamingTestServer.d.ts +7 -0
- package/test/StreamingTestServer.js +51 -0
- package/test/arrayFromAsync.cjs +13 -0
- package/test/arrayFromAsync.d.ts +1 -0
- package/test/arrayFromAsync.js +9 -0
- package/tool/generate-tool-call/TextGenerationToolCallModel.cjs +1 -1
- package/tool/generate-tool-call/TextGenerationToolCallModel.d.ts +1 -1
- package/tool/generate-tool-call/TextGenerationToolCallModel.js +1 -1
- package/tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.d.ts +1 -11
- package/tool/generate-tool-calls-or-text/ToolCallsOrGenerateTextPromptTemplate.d.ts +12 -0
- package/tool/generate-tool-calls-or-text/ToolCallsOrGenerateTextPromptTemplate.js +1 -0
- package/tool/generate-tool-calls-or-text/index.cjs +1 -0
- package/tool/generate-tool-calls-or-text/index.d.ts +1 -0
- package/tool/generate-tool-calls-or-text/index.js +1 -0
- package/util/index.cjs +0 -1
- package/util/index.d.ts +0 -1
- package/util/index.js +0 -1
- package/util/streaming/createEventSourceResponseHandler.cjs +9 -0
- package/util/streaming/createEventSourceResponseHandler.d.ts +4 -0
- package/util/streaming/createEventSourceResponseHandler.js +5 -0
- package/util/streaming/createJsonStreamResponseHandler.cjs +9 -0
- package/util/streaming/createJsonStreamResponseHandler.d.ts +4 -0
- package/util/streaming/createJsonStreamResponseHandler.js +5 -0
- package/util/streaming/parseEventSourceStreamAsAsyncIterable.cjs +52 -0
- package/util/streaming/parseEventSourceStreamAsAsyncIterable.d.ts +6 -0
- package/util/streaming/parseEventSourceStreamAsAsyncIterable.js +48 -0
- package/util/streaming/parseJsonStreamAsAsyncIterable.cjs +21 -0
- package/util/streaming/parseJsonStreamAsAsyncIterable.d.ts +6 -0
- package/util/streaming/parseJsonStreamAsAsyncIterable.js +17 -0
- package/browser/MediaSourceAppender.cjs +0 -54
- package/browser/MediaSourceAppender.d.ts +0 -11
- package/browser/MediaSourceAppender.js +0 -50
- package/browser/convertAudioChunksToBase64.cjs +0 -8
- package/browser/convertAudioChunksToBase64.d.ts +0 -4
- package/browser/convertAudioChunksToBase64.js +0 -4
- package/browser/convertBlobToBase64.cjs +0 -23
- package/browser/convertBlobToBase64.d.ts +0 -1
- package/browser/convertBlobToBase64.js +0 -19
- package/browser/index.cjs +0 -22
- package/browser/index.d.ts +0 -6
- package/browser/index.js +0 -6
- package/browser/invokeFlow.cjs +0 -23
- package/browser/invokeFlow.d.ts +0 -8
- package/browser/invokeFlow.js +0 -19
- package/browser/readEventSource.cjs +0 -29
- package/browser/readEventSource.d.ts +0 -9
- package/browser/readEventSource.js +0 -25
- package/browser/readEventSourceStream.cjs +0 -35
- package/browser/readEventSourceStream.d.ts +0 -7
- package/browser/readEventSourceStream.js +0 -31
- package/composed-function/index.cjs +0 -19
- package/composed-function/index.d.ts +0 -3
- package/composed-function/index.js +0 -3
- package/composed-function/summarize/SummarizationFunction.d.ts +0 -4
- package/composed-function/summarize/summarizeRecursively.cjs +0 -19
- package/composed-function/summarize/summarizeRecursively.d.ts +0 -11
- package/composed-function/summarize/summarizeRecursively.js +0 -15
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.cjs +0 -25
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.d.ts +0 -24
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.js +0 -21
- package/cost/Cost.cjs +0 -38
- package/cost/Cost.d.ts +0 -16
- package/cost/Cost.js +0 -34
- package/cost/CostCalculator.d.ts +0 -8
- package/cost/calculateCost.cjs +0 -28
- package/cost/calculateCost.d.ts +0 -7
- package/cost/calculateCost.js +0 -24
- package/cost/index.cjs +0 -19
- package/cost/index.d.ts +0 -3
- package/cost/index.js +0 -3
- package/guard/GuardEvent.cjs +0 -2
- package/guard/GuardEvent.d.ts +0 -7
- package/guard/fixStructure.cjs +0 -75
- package/guard/fixStructure.d.ts +0 -64
- package/guard/fixStructure.js +0 -71
- package/guard/guard.cjs +0 -79
- package/guard/guard.d.ts +0 -29
- package/guard/guard.js +0 -75
- package/guard/index.cjs +0 -19
- package/guard/index.d.ts +0 -3
- package/guard/index.js +0 -3
- package/model-function/SuccessfulModelCall.cjs +0 -10
- package/model-function/SuccessfulModelCall.d.ts +0 -12
- package/model-function/SuccessfulModelCall.js +0 -6
- package/model-function/generate-text/prompt-template/Content.d.ts +0 -25
- package/model-provider/openai/OpenAICostCalculator.cjs +0 -89
- package/model-provider/openai/OpenAICostCalculator.d.ts +0 -6
- package/model-provider/openai/OpenAICostCalculator.js +0 -85
- package/model-provider/openai/chat/OpenAIChatModel.test.cjs +0 -61
- package/model-provider/openai/chat/OpenAIChatModel.test.js +0 -59
- package/model-provider/openai/chat/OpenAIChatPromptTemplate.cjs +0 -70
- package/model-provider/openai/chat/OpenAIChatPromptTemplate.js +0 -63
- package/model-provider/openai/chat/OpenAIChatStreamIterable.cjs +0 -156
- package/model-provider/openai/chat/OpenAIChatStreamIterable.d.ts +0 -19
- package/model-provider/openai/chat/OpenAIChatStreamIterable.js +0 -152
- package/server/fastify/AssetStorage.cjs +0 -2
- package/server/fastify/AssetStorage.d.ts +0 -17
- package/server/fastify/DefaultFlow.cjs +0 -22
- package/server/fastify/DefaultFlow.d.ts +0 -16
- package/server/fastify/DefaultFlow.js +0 -18
- package/server/fastify/FileSystemAssetStorage.cjs +0 -60
- package/server/fastify/FileSystemAssetStorage.d.ts +0 -19
- package/server/fastify/FileSystemAssetStorage.js +0 -56
- package/server/fastify/FileSystemLogger.cjs +0 -49
- package/server/fastify/FileSystemLogger.d.ts +0 -18
- package/server/fastify/FileSystemLogger.js +0 -45
- package/server/fastify/Flow.cjs +0 -2
- package/server/fastify/Flow.d.ts +0 -9
- package/server/fastify/FlowRun.cjs +0 -71
- package/server/fastify/FlowRun.d.ts +0 -28
- package/server/fastify/FlowRun.js +0 -67
- package/server/fastify/FlowSchema.cjs +0 -2
- package/server/fastify/FlowSchema.d.ts +0 -5
- package/server/fastify/Logger.cjs +0 -2
- package/server/fastify/Logger.d.ts +0 -13
- package/server/fastify/PathProvider.cjs +0 -34
- package/server/fastify/PathProvider.d.ts +0 -12
- package/server/fastify/PathProvider.js +0 -30
- package/server/fastify/index.cjs +0 -24
- package/server/fastify/index.d.ts +0 -8
- package/server/fastify/index.js +0 -8
- package/server/fastify/modelFusionFlowPlugin.cjs +0 -103
- package/server/fastify/modelFusionFlowPlugin.d.ts +0 -12
- package/server/fastify/modelFusionFlowPlugin.js +0 -99
- package/util/getAudioFileExtension.cjs +0 -29
- package/util/getAudioFileExtension.d.ts +0 -1
- package/util/getAudioFileExtension.js +0 -25
- /package/{composed-function/summarize/SummarizationFunction.cjs → core/ExtensionFunctionEvent.cjs} +0 -0
- /package/{composed-function/summarize/SummarizationFunction.js → core/ExtensionFunctionEvent.js} +0 -0
- /package/{cost/CostCalculator.js → model-provider/anthropic/AnthropicTextGenerationModel.test.d.ts} +0 -0
- /package/{guard/GuardEvent.js → model-provider/cohere/CohereTextGenerationModel.test.d.ts} +0 -0
- /package/model-provider/{openai/chat/OpenAIChatModel.test.d.ts → llamacpp/LlamaCppTextGenerationModel.test.d.ts} +0 -0
- /package/{server/fastify/AssetStorage.js → model-provider/mistral/MistralChatModel.test.d.ts} +0 -0
- /package/{server/fastify/Flow.js → model-provider/ollama/OllamaChatModel.test.d.ts} +0 -0
- /package/model-provider/openai/{chat/OpenAIChatMessage.cjs → OpenAIChatMessage.cjs} +0 -0
- /package/model-provider/openai/{chat/OpenAIChatMessage.js → OpenAIChatMessage.js} +0 -0
- /package/{server/fastify/FlowSchema.js → model-provider/openai/OpenAIChatModel.test.d.ts} +0 -0
- /package/{server/fastify/Logger.js → model-provider/openai/OpenAICompletionModel.test.d.ts} +0 -0
- /package/model-provider/openai/{chat/countOpenAIChatMessageTokens.d.ts → countOpenAIChatMessageTokens.d.ts} +0 -0
- /package/{cost/CostCalculator.cjs → tool/generate-tool-calls-or-text/ToolCallsOrGenerateTextPromptTemplate.cjs} +0 -0
@@ -1,63 +0,0 @@
|
|
1
|
-
import { OpenAIChatMessage } from "./OpenAIChatMessage.js";
|
2
|
-
/**
|
3
|
-
* OpenAIMessage[] identity chat format.
|
4
|
-
*/
|
5
|
-
export function identity() {
|
6
|
-
return { format: (prompt) => prompt, stopSequences: [] };
|
7
|
-
}
|
8
|
-
/**
|
9
|
-
* Formats a text prompt as an OpenAI chat prompt.
|
10
|
-
*/
|
11
|
-
export function text() {
|
12
|
-
return {
|
13
|
-
format: (prompt) => [OpenAIChatMessage.user(prompt)],
|
14
|
-
stopSequences: [],
|
15
|
-
};
|
16
|
-
}
|
17
|
-
/**
|
18
|
-
* Formats an instruction prompt as an OpenAI chat prompt.
|
19
|
-
*/
|
20
|
-
export function instruction() {
|
21
|
-
return {
|
22
|
-
format(prompt) {
|
23
|
-
const messages = [];
|
24
|
-
if (prompt.system != null) {
|
25
|
-
messages.push(OpenAIChatMessage.system(prompt.system));
|
26
|
-
}
|
27
|
-
messages.push(OpenAIChatMessage.user(prompt.instruction));
|
28
|
-
return messages;
|
29
|
-
},
|
30
|
-
stopSequences: [],
|
31
|
-
};
|
32
|
-
}
|
33
|
-
/**
|
34
|
-
* Formats a chat prompt as an OpenAI chat prompt.
|
35
|
-
*/
|
36
|
-
export function chat() {
|
37
|
-
return {
|
38
|
-
format(prompt) {
|
39
|
-
const messages = [];
|
40
|
-
if (prompt.system != null) {
|
41
|
-
messages.push(OpenAIChatMessage.system(prompt.system));
|
42
|
-
}
|
43
|
-
for (const { role, content } of prompt.messages) {
|
44
|
-
switch (role) {
|
45
|
-
case "user": {
|
46
|
-
messages.push(OpenAIChatMessage.user(content));
|
47
|
-
break;
|
48
|
-
}
|
49
|
-
case "assistant": {
|
50
|
-
messages.push(OpenAIChatMessage.assistant(content));
|
51
|
-
break;
|
52
|
-
}
|
53
|
-
default: {
|
54
|
-
const _exhaustiveCheck = role;
|
55
|
-
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
56
|
-
}
|
57
|
-
}
|
58
|
-
}
|
59
|
-
return messages;
|
60
|
-
},
|
61
|
-
stopSequences: [],
|
62
|
-
};
|
63
|
-
}
|
@@ -1,156 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.createOpenAIChatDeltaIterableQueue = void 0;
|
4
|
-
const zod_1 = require("zod");
|
5
|
-
const AsyncQueue_js_1 = require("../../../util/AsyncQueue.cjs");
|
6
|
-
const parseEventSourceStream_js_1 = require("../../../util/streaming/parseEventSourceStream.cjs");
|
7
|
-
const parseJSON_js_1 = require("../../../core/schema/parseJSON.cjs");
|
8
|
-
const ZodSchema_js_1 = require("../../../core/schema/ZodSchema.cjs");
|
9
|
-
const chatCompletionChunkSchema = zod_1.z.object({
|
10
|
-
object: zod_1.z.literal("chat.completion.chunk"),
|
11
|
-
id: zod_1.z.string(),
|
12
|
-
choices: zod_1.z.array(zod_1.z.object({
|
13
|
-
delta: zod_1.z.object({
|
14
|
-
role: zod_1.z.enum(["assistant", "user"]).optional(),
|
15
|
-
content: zod_1.z.string().nullable().optional(),
|
16
|
-
function_call: zod_1.z
|
17
|
-
.object({
|
18
|
-
name: zod_1.z.string().optional(),
|
19
|
-
arguments: zod_1.z.string().optional(),
|
20
|
-
})
|
21
|
-
.optional(),
|
22
|
-
tool_calls: zod_1.z
|
23
|
-
.array(zod_1.z.object({
|
24
|
-
id: zod_1.z.string(),
|
25
|
-
type: zod_1.z.literal("function"),
|
26
|
-
function: zod_1.z.object({
|
27
|
-
name: zod_1.z.string(),
|
28
|
-
arguments: zod_1.z.string(),
|
29
|
-
}),
|
30
|
-
}))
|
31
|
-
.optional(),
|
32
|
-
}),
|
33
|
-
finish_reason: zod_1.z
|
34
|
-
.enum([
|
35
|
-
"stop",
|
36
|
-
"length",
|
37
|
-
"tool_calls",
|
38
|
-
"content_filter",
|
39
|
-
"function_call",
|
40
|
-
])
|
41
|
-
.nullable()
|
42
|
-
.optional(),
|
43
|
-
index: zod_1.z.number(),
|
44
|
-
})),
|
45
|
-
created: zod_1.z.number(),
|
46
|
-
model: zod_1.z.string(),
|
47
|
-
system_fingerprint: zod_1.z.string().optional().nullable(),
|
48
|
-
});
|
49
|
-
const chatResponseStreamEventSchema = new ZodSchema_js_1.ZodSchema(zod_1.z.union([
|
50
|
-
chatCompletionChunkSchema,
|
51
|
-
zod_1.z.object({
|
52
|
-
object: zod_1.z.string().refine((obj) => obj !== "chat.completion.chunk", {
|
53
|
-
message: "Object must be 'chat.completion.chunk'",
|
54
|
-
}),
|
55
|
-
}),
|
56
|
-
]));
|
57
|
-
async function createOpenAIChatDeltaIterableQueue(stream, extractDeltaValue) {
|
58
|
-
const queue = new AsyncQueue_js_1.AsyncQueue();
|
59
|
-
const streamDelta = [];
|
60
|
-
// process the stream asynchonously (no 'await' on purpose):
|
61
|
-
(0, parseEventSourceStream_js_1.parseEventSourceStream)({ stream })
|
62
|
-
.then(async (events) => {
|
63
|
-
try {
|
64
|
-
for await (const event of events) {
|
65
|
-
const data = event.data;
|
66
|
-
if (data === "[DONE]") {
|
67
|
-
queue.close();
|
68
|
-
return;
|
69
|
-
}
|
70
|
-
const parseResult = (0, parseJSON_js_1.safeParseJSON)({
|
71
|
-
text: data,
|
72
|
-
schema: chatResponseStreamEventSchema,
|
73
|
-
});
|
74
|
-
if (!parseResult.success) {
|
75
|
-
queue.push({
|
76
|
-
type: "error",
|
77
|
-
error: parseResult.error,
|
78
|
-
});
|
79
|
-
// Note: the queue is not closed on purpose. Some providers might add additional
|
80
|
-
// chunks that are not parsable, and ModelFusion should be resilient to that.
|
81
|
-
continue;
|
82
|
-
}
|
83
|
-
const eventData = parseResult.data;
|
84
|
-
// ignore objects that are not "chat.completion.chunk" events.
|
85
|
-
// Such additional objects are e.g. sent by Azure OpenAI.
|
86
|
-
if (eventData.object !== "chat.completion.chunk") {
|
87
|
-
continue;
|
88
|
-
}
|
89
|
-
const completionChunk = eventData;
|
90
|
-
// reset delta for all existing streamDeltas
|
91
|
-
for (const delta of streamDelta) {
|
92
|
-
delta.delta = undefined;
|
93
|
-
}
|
94
|
-
for (let i = 0; i < completionChunk.choices.length; i++) {
|
95
|
-
const eventChoice = completionChunk.choices[i];
|
96
|
-
const index = eventChoice.index;
|
97
|
-
const delta = eventChoice.delta;
|
98
|
-
if (streamDelta[index] == null) {
|
99
|
-
streamDelta[index] = {
|
100
|
-
role: undefined,
|
101
|
-
content: "",
|
102
|
-
isComplete: false,
|
103
|
-
delta,
|
104
|
-
};
|
105
|
-
}
|
106
|
-
const choice = streamDelta[index];
|
107
|
-
choice.delta = delta;
|
108
|
-
if (eventChoice.finish_reason != null) {
|
109
|
-
choice.isComplete = true;
|
110
|
-
}
|
111
|
-
if (delta.content != undefined) {
|
112
|
-
choice.content += delta.content;
|
113
|
-
}
|
114
|
-
if (delta.function_call != undefined) {
|
115
|
-
if (choice.function_call == undefined) {
|
116
|
-
choice.function_call = {
|
117
|
-
name: "",
|
118
|
-
arguments: "",
|
119
|
-
};
|
120
|
-
}
|
121
|
-
if (delta.function_call.name != undefined) {
|
122
|
-
choice.function_call.name += delta.function_call.name;
|
123
|
-
}
|
124
|
-
if (delta.function_call.arguments != undefined) {
|
125
|
-
choice.function_call.arguments +=
|
126
|
-
delta.function_call.arguments;
|
127
|
-
}
|
128
|
-
}
|
129
|
-
if (delta.role != undefined) {
|
130
|
-
choice.role = delta.role;
|
131
|
-
}
|
132
|
-
}
|
133
|
-
// Since we're mutating the choices array in an async scenario,
|
134
|
-
// we need to make a deep copy:
|
135
|
-
const streamDeltaDeepCopy = JSON.parse(JSON.stringify(streamDelta));
|
136
|
-
queue.push({
|
137
|
-
type: "delta",
|
138
|
-
fullDelta: streamDeltaDeepCopy,
|
139
|
-
valueDelta: extractDeltaValue(streamDeltaDeepCopy),
|
140
|
-
});
|
141
|
-
}
|
142
|
-
}
|
143
|
-
catch (error) {
|
144
|
-
queue.push({ type: "error", error });
|
145
|
-
queue.close();
|
146
|
-
return;
|
147
|
-
}
|
148
|
-
})
|
149
|
-
.catch((error) => {
|
150
|
-
queue.push({ type: "error", error });
|
151
|
-
queue.close();
|
152
|
-
return;
|
153
|
-
});
|
154
|
-
return queue;
|
155
|
-
}
|
156
|
-
exports.createOpenAIChatDeltaIterableQueue = createOpenAIChatDeltaIterableQueue;
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import { Delta } from "../../../model-function/Delta.js";
|
2
|
-
export type OpenAIChatDelta = Array<{
|
3
|
-
role: "assistant" | "user" | undefined;
|
4
|
-
content: string;
|
5
|
-
function_call?: {
|
6
|
-
name: string;
|
7
|
-
arguments: string;
|
8
|
-
};
|
9
|
-
isComplete: boolean;
|
10
|
-
delta: {
|
11
|
-
role?: "assistant" | "user";
|
12
|
-
content?: string | null;
|
13
|
-
function_call?: {
|
14
|
-
name?: string;
|
15
|
-
arguments?: string;
|
16
|
-
};
|
17
|
-
} | undefined;
|
18
|
-
}>;
|
19
|
-
export declare function createOpenAIChatDeltaIterableQueue<VALUE>(stream: ReadableStream<Uint8Array>, extractDeltaValue: (delta: OpenAIChatDelta) => VALUE): Promise<AsyncIterable<Delta<VALUE>>>;
|
@@ -1,152 +0,0 @@
|
|
1
|
-
import { z } from "zod";
|
2
|
-
import { AsyncQueue } from "../../../util/AsyncQueue.js";
|
3
|
-
import { parseEventSourceStream } from "../../../util/streaming/parseEventSourceStream.js";
|
4
|
-
import { safeParseJSON } from "../../../core/schema/parseJSON.js";
|
5
|
-
import { ZodSchema } from "../../../core/schema/ZodSchema.js";
|
6
|
-
const chatCompletionChunkSchema = z.object({
|
7
|
-
object: z.literal("chat.completion.chunk"),
|
8
|
-
id: z.string(),
|
9
|
-
choices: z.array(z.object({
|
10
|
-
delta: z.object({
|
11
|
-
role: z.enum(["assistant", "user"]).optional(),
|
12
|
-
content: z.string().nullable().optional(),
|
13
|
-
function_call: z
|
14
|
-
.object({
|
15
|
-
name: z.string().optional(),
|
16
|
-
arguments: z.string().optional(),
|
17
|
-
})
|
18
|
-
.optional(),
|
19
|
-
tool_calls: z
|
20
|
-
.array(z.object({
|
21
|
-
id: z.string(),
|
22
|
-
type: z.literal("function"),
|
23
|
-
function: z.object({
|
24
|
-
name: z.string(),
|
25
|
-
arguments: z.string(),
|
26
|
-
}),
|
27
|
-
}))
|
28
|
-
.optional(),
|
29
|
-
}),
|
30
|
-
finish_reason: z
|
31
|
-
.enum([
|
32
|
-
"stop",
|
33
|
-
"length",
|
34
|
-
"tool_calls",
|
35
|
-
"content_filter",
|
36
|
-
"function_call",
|
37
|
-
])
|
38
|
-
.nullable()
|
39
|
-
.optional(),
|
40
|
-
index: z.number(),
|
41
|
-
})),
|
42
|
-
created: z.number(),
|
43
|
-
model: z.string(),
|
44
|
-
system_fingerprint: z.string().optional().nullable(),
|
45
|
-
});
|
46
|
-
const chatResponseStreamEventSchema = new ZodSchema(z.union([
|
47
|
-
chatCompletionChunkSchema,
|
48
|
-
z.object({
|
49
|
-
object: z.string().refine((obj) => obj !== "chat.completion.chunk", {
|
50
|
-
message: "Object must be 'chat.completion.chunk'",
|
51
|
-
}),
|
52
|
-
}),
|
53
|
-
]));
|
54
|
-
export async function createOpenAIChatDeltaIterableQueue(stream, extractDeltaValue) {
|
55
|
-
const queue = new AsyncQueue();
|
56
|
-
const streamDelta = [];
|
57
|
-
// process the stream asynchonously (no 'await' on purpose):
|
58
|
-
parseEventSourceStream({ stream })
|
59
|
-
.then(async (events) => {
|
60
|
-
try {
|
61
|
-
for await (const event of events) {
|
62
|
-
const data = event.data;
|
63
|
-
if (data === "[DONE]") {
|
64
|
-
queue.close();
|
65
|
-
return;
|
66
|
-
}
|
67
|
-
const parseResult = safeParseJSON({
|
68
|
-
text: data,
|
69
|
-
schema: chatResponseStreamEventSchema,
|
70
|
-
});
|
71
|
-
if (!parseResult.success) {
|
72
|
-
queue.push({
|
73
|
-
type: "error",
|
74
|
-
error: parseResult.error,
|
75
|
-
});
|
76
|
-
// Note: the queue is not closed on purpose. Some providers might add additional
|
77
|
-
// chunks that are not parsable, and ModelFusion should be resilient to that.
|
78
|
-
continue;
|
79
|
-
}
|
80
|
-
const eventData = parseResult.data;
|
81
|
-
// ignore objects that are not "chat.completion.chunk" events.
|
82
|
-
// Such additional objects are e.g. sent by Azure OpenAI.
|
83
|
-
if (eventData.object !== "chat.completion.chunk") {
|
84
|
-
continue;
|
85
|
-
}
|
86
|
-
const completionChunk = eventData;
|
87
|
-
// reset delta for all existing streamDeltas
|
88
|
-
for (const delta of streamDelta) {
|
89
|
-
delta.delta = undefined;
|
90
|
-
}
|
91
|
-
for (let i = 0; i < completionChunk.choices.length; i++) {
|
92
|
-
const eventChoice = completionChunk.choices[i];
|
93
|
-
const index = eventChoice.index;
|
94
|
-
const delta = eventChoice.delta;
|
95
|
-
if (streamDelta[index] == null) {
|
96
|
-
streamDelta[index] = {
|
97
|
-
role: undefined,
|
98
|
-
content: "",
|
99
|
-
isComplete: false,
|
100
|
-
delta,
|
101
|
-
};
|
102
|
-
}
|
103
|
-
const choice = streamDelta[index];
|
104
|
-
choice.delta = delta;
|
105
|
-
if (eventChoice.finish_reason != null) {
|
106
|
-
choice.isComplete = true;
|
107
|
-
}
|
108
|
-
if (delta.content != undefined) {
|
109
|
-
choice.content += delta.content;
|
110
|
-
}
|
111
|
-
if (delta.function_call != undefined) {
|
112
|
-
if (choice.function_call == undefined) {
|
113
|
-
choice.function_call = {
|
114
|
-
name: "",
|
115
|
-
arguments: "",
|
116
|
-
};
|
117
|
-
}
|
118
|
-
if (delta.function_call.name != undefined) {
|
119
|
-
choice.function_call.name += delta.function_call.name;
|
120
|
-
}
|
121
|
-
if (delta.function_call.arguments != undefined) {
|
122
|
-
choice.function_call.arguments +=
|
123
|
-
delta.function_call.arguments;
|
124
|
-
}
|
125
|
-
}
|
126
|
-
if (delta.role != undefined) {
|
127
|
-
choice.role = delta.role;
|
128
|
-
}
|
129
|
-
}
|
130
|
-
// Since we're mutating the choices array in an async scenario,
|
131
|
-
// we need to make a deep copy:
|
132
|
-
const streamDeltaDeepCopy = JSON.parse(JSON.stringify(streamDelta));
|
133
|
-
queue.push({
|
134
|
-
type: "delta",
|
135
|
-
fullDelta: streamDeltaDeepCopy,
|
136
|
-
valueDelta: extractDeltaValue(streamDeltaDeepCopy),
|
137
|
-
});
|
138
|
-
}
|
139
|
-
}
|
140
|
-
catch (error) {
|
141
|
-
queue.push({ type: "error", error });
|
142
|
-
queue.close();
|
143
|
-
return;
|
144
|
-
}
|
145
|
-
})
|
146
|
-
.catch((error) => {
|
147
|
-
queue.push({ type: "error", error });
|
148
|
-
queue.close();
|
149
|
-
return;
|
150
|
-
});
|
151
|
-
return queue;
|
152
|
-
}
|
@@ -1,17 +0,0 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
import { FlowRun } from "./FlowRun.js";
|
3
|
-
export type Asset = {
|
4
|
-
data: Buffer;
|
5
|
-
contentType: string;
|
6
|
-
name: string;
|
7
|
-
};
|
8
|
-
export interface AssetStorage {
|
9
|
-
storeAsset(options: {
|
10
|
-
run: FlowRun<unknown>;
|
11
|
-
asset: Asset;
|
12
|
-
}): Promise<void>;
|
13
|
-
readAsset(options: {
|
14
|
-
run: FlowRun<unknown>;
|
15
|
-
assetName: string;
|
16
|
-
}): Promise<Asset | null>;
|
17
|
-
}
|
@@ -1,22 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.DefaultFlow = void 0;
|
4
|
-
class DefaultFlow {
|
5
|
-
constructor({ schema, process, }) {
|
6
|
-
Object.defineProperty(this, "schema", {
|
7
|
-
enumerable: true,
|
8
|
-
configurable: true,
|
9
|
-
writable: true,
|
10
|
-
value: void 0
|
11
|
-
});
|
12
|
-
Object.defineProperty(this, "process", {
|
13
|
-
enumerable: true,
|
14
|
-
configurable: true,
|
15
|
-
writable: true,
|
16
|
-
value: void 0
|
17
|
-
});
|
18
|
-
this.schema = schema;
|
19
|
-
this.process = process;
|
20
|
-
}
|
21
|
-
}
|
22
|
-
exports.DefaultFlow = DefaultFlow;
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { FlowRun } from "./FlowRun.js";
|
2
|
-
import { FlowSchema } from "./FlowSchema.js";
|
3
|
-
export declare class DefaultFlow<INPUT, EVENT> {
|
4
|
-
readonly schema: FlowSchema<INPUT, EVENT>;
|
5
|
-
constructor({ schema, process, }: {
|
6
|
-
schema: FlowSchema<INPUT, EVENT>;
|
7
|
-
process: (options: {
|
8
|
-
input: INPUT;
|
9
|
-
run: FlowRun<EVENT>;
|
10
|
-
}) => Promise<void>;
|
11
|
-
});
|
12
|
-
process: (options: {
|
13
|
-
input: INPUT;
|
14
|
-
run: FlowRun<EVENT>;
|
15
|
-
}) => Promise<void>;
|
16
|
-
}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
export class DefaultFlow {
|
2
|
-
constructor({ schema, process, }) {
|
3
|
-
Object.defineProperty(this, "schema", {
|
4
|
-
enumerable: true,
|
5
|
-
configurable: true,
|
6
|
-
writable: true,
|
7
|
-
value: void 0
|
8
|
-
});
|
9
|
-
Object.defineProperty(this, "process", {
|
10
|
-
enumerable: true,
|
11
|
-
configurable: true,
|
12
|
-
writable: true,
|
13
|
-
value: void 0
|
14
|
-
});
|
15
|
-
this.schema = schema;
|
16
|
-
this.process = process;
|
17
|
-
}
|
18
|
-
}
|
@@ -1,60 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.FileSystemAssetStorage = void 0;
|
4
|
-
const node_fs_1 = require("node:fs");
|
5
|
-
const node_path_1 = require("node:path");
|
6
|
-
class FileSystemAssetStorage {
|
7
|
-
constructor({ path, logger, }) {
|
8
|
-
Object.defineProperty(this, "path", {
|
9
|
-
enumerable: true,
|
10
|
-
configurable: true,
|
11
|
-
writable: true,
|
12
|
-
value: void 0
|
13
|
-
});
|
14
|
-
Object.defineProperty(this, "logger", {
|
15
|
-
enumerable: true,
|
16
|
-
configurable: true,
|
17
|
-
writable: true,
|
18
|
-
value: void 0
|
19
|
-
});
|
20
|
-
this.path = path;
|
21
|
-
this.logger = logger;
|
22
|
-
}
|
23
|
-
async storeAsset({ run, asset, }) {
|
24
|
-
try {
|
25
|
-
const assetPath = this.path(run);
|
26
|
-
await node_fs_1.promises.mkdir(assetPath, { recursive: true });
|
27
|
-
await node_fs_1.promises.writeFile((0, node_path_1.join)(assetPath, asset.name), asset.data);
|
28
|
-
await node_fs_1.promises.writeFile((0, node_path_1.join)(assetPath, `${asset.name}.meta.json`), JSON.stringify({
|
29
|
-
name: asset.name,
|
30
|
-
contentType: asset.contentType,
|
31
|
-
}));
|
32
|
-
}
|
33
|
-
catch (error) {
|
34
|
-
this.logger.logError({
|
35
|
-
run,
|
36
|
-
message: `Failed to store asset ${asset.name}`,
|
37
|
-
error,
|
38
|
-
});
|
39
|
-
throw error;
|
40
|
-
}
|
41
|
-
}
|
42
|
-
async readAsset(options) {
|
43
|
-
try {
|
44
|
-
const assetPath = this.path(options.run);
|
45
|
-
const data = await node_fs_1.promises.readFile((0, node_path_1.join)(assetPath, options.assetName));
|
46
|
-
const meta = await node_fs_1.promises.readFile((0, node_path_1.join)(assetPath, `${options.assetName}.meta.json`));
|
47
|
-
const { name, contentType } = JSON.parse(meta.toString());
|
48
|
-
return { data, name, contentType };
|
49
|
-
}
|
50
|
-
catch (error) {
|
51
|
-
this.logger.logError({
|
52
|
-
run: options.run,
|
53
|
-
message: `Failed to read asset ${options.assetName}`,
|
54
|
-
error,
|
55
|
-
});
|
56
|
-
throw error;
|
57
|
-
}
|
58
|
-
}
|
59
|
-
}
|
60
|
-
exports.FileSystemAssetStorage = FileSystemAssetStorage;
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import type { Asset, AssetStorage } from "./AssetStorage.js";
|
2
|
-
import { FlowRun } from "./FlowRun.js";
|
3
|
-
import { Logger } from "./Logger.js";
|
4
|
-
export declare class FileSystemAssetStorage implements AssetStorage {
|
5
|
-
private readonly path;
|
6
|
-
private readonly logger;
|
7
|
-
constructor({ path, logger, }: {
|
8
|
-
path: (run: FlowRun<unknown>) => string;
|
9
|
-
logger: Logger;
|
10
|
-
});
|
11
|
-
storeAsset({ run, asset, }: {
|
12
|
-
run: FlowRun<unknown>;
|
13
|
-
asset: Asset;
|
14
|
-
}): Promise<void>;
|
15
|
-
readAsset(options: {
|
16
|
-
run: FlowRun<unknown>;
|
17
|
-
assetName: string;
|
18
|
-
}): Promise<Asset | null>;
|
19
|
-
}
|
@@ -1,56 +0,0 @@
|
|
1
|
-
import { promises as fs } from "node:fs";
|
2
|
-
import { join } from "node:path";
|
3
|
-
export class FileSystemAssetStorage {
|
4
|
-
constructor({ path, logger, }) {
|
5
|
-
Object.defineProperty(this, "path", {
|
6
|
-
enumerable: true,
|
7
|
-
configurable: true,
|
8
|
-
writable: true,
|
9
|
-
value: void 0
|
10
|
-
});
|
11
|
-
Object.defineProperty(this, "logger", {
|
12
|
-
enumerable: true,
|
13
|
-
configurable: true,
|
14
|
-
writable: true,
|
15
|
-
value: void 0
|
16
|
-
});
|
17
|
-
this.path = path;
|
18
|
-
this.logger = logger;
|
19
|
-
}
|
20
|
-
async storeAsset({ run, asset, }) {
|
21
|
-
try {
|
22
|
-
const assetPath = this.path(run);
|
23
|
-
await fs.mkdir(assetPath, { recursive: true });
|
24
|
-
await fs.writeFile(join(assetPath, asset.name), asset.data);
|
25
|
-
await fs.writeFile(join(assetPath, `${asset.name}.meta.json`), JSON.stringify({
|
26
|
-
name: asset.name,
|
27
|
-
contentType: asset.contentType,
|
28
|
-
}));
|
29
|
-
}
|
30
|
-
catch (error) {
|
31
|
-
this.logger.logError({
|
32
|
-
run,
|
33
|
-
message: `Failed to store asset ${asset.name}`,
|
34
|
-
error,
|
35
|
-
});
|
36
|
-
throw error;
|
37
|
-
}
|
38
|
-
}
|
39
|
-
async readAsset(options) {
|
40
|
-
try {
|
41
|
-
const assetPath = this.path(options.run);
|
42
|
-
const data = await fs.readFile(join(assetPath, options.assetName));
|
43
|
-
const meta = await fs.readFile(join(assetPath, `${options.assetName}.meta.json`));
|
44
|
-
const { name, contentType } = JSON.parse(meta.toString());
|
45
|
-
return { data, name, contentType };
|
46
|
-
}
|
47
|
-
catch (error) {
|
48
|
-
this.logger.logError({
|
49
|
-
run: options.run,
|
50
|
-
message: `Failed to read asset ${options.assetName}`,
|
51
|
-
error,
|
52
|
-
});
|
53
|
-
throw error;
|
54
|
-
}
|
55
|
-
}
|
56
|
-
}
|
@@ -1,49 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.FileSystemLogger = void 0;
|
4
|
-
const node_fs_1 = require("node:fs");
|
5
|
-
const node_path_1 = require("node:path");
|
6
|
-
class FileSystemLogger {
|
7
|
-
constructor({ path }) {
|
8
|
-
Object.defineProperty(this, "logPath", {
|
9
|
-
enumerable: true,
|
10
|
-
configurable: true,
|
11
|
-
writable: true,
|
12
|
-
value: void 0
|
13
|
-
});
|
14
|
-
this.logPath = path;
|
15
|
-
}
|
16
|
-
async logFunctionEvent({ run, event, }) {
|
17
|
-
const timestamp = event.startTimestamp.getTime();
|
18
|
-
try {
|
19
|
-
const logPath = this.logPath(run);
|
20
|
-
await node_fs_1.promises.mkdir(logPath, { recursive: true });
|
21
|
-
await node_fs_1.promises.writeFile((0, node_path_1.join)(logPath, `${timestamp}-${event.callId}-${event.functionId ?? event.functionType}-${event.eventType}.json`), JSON.stringify(event));
|
22
|
-
}
|
23
|
-
catch (error) {
|
24
|
-
this.logError({
|
25
|
-
run,
|
26
|
-
message: `Failed to write function event ${event.callId}`,
|
27
|
-
error,
|
28
|
-
});
|
29
|
-
}
|
30
|
-
}
|
31
|
-
async logError({ run, error, message, }) {
|
32
|
-
const timestamp = Date.now();
|
33
|
-
try {
|
34
|
-
const logPath = this.logPath(run);
|
35
|
-
await node_fs_1.promises.mkdir(logPath, { recursive: true });
|
36
|
-
await node_fs_1.promises.writeFile((0, node_path_1.join)(logPath, `${timestamp}-error.json`), JSON.stringify({
|
37
|
-
timestamp: new Date(timestamp).toISOString(),
|
38
|
-
runId: run.runId,
|
39
|
-
message,
|
40
|
-
error,
|
41
|
-
}));
|
42
|
-
}
|
43
|
-
catch (error) {
|
44
|
-
console.error(`Failed to write error log`);
|
45
|
-
console.error(error);
|
46
|
-
}
|
47
|
-
}
|
48
|
-
}
|
49
|
-
exports.FileSystemLogger = FileSystemLogger;
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import { FunctionEvent } from "../../core/FunctionEvent.js";
|
2
|
-
import { FlowRun } from "./FlowRun.js";
|
3
|
-
import { Logger } from "./Logger.js";
|
4
|
-
export declare class FileSystemLogger implements Logger {
|
5
|
-
private readonly logPath;
|
6
|
-
constructor({ path }: {
|
7
|
-
path: (run: FlowRun<unknown>) => string;
|
8
|
-
});
|
9
|
-
logFunctionEvent({ run, event, }: {
|
10
|
-
run: FlowRun<unknown>;
|
11
|
-
event: FunctionEvent;
|
12
|
-
}): Promise<void>;
|
13
|
-
logError({ run, error, message, }: {
|
14
|
-
run: FlowRun<unknown>;
|
15
|
-
message: string;
|
16
|
-
error: unknown;
|
17
|
-
}): Promise<void>;
|
18
|
-
}
|