modelfusion 0.105.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 +11 -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/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-text/PromptTemplateTextGenerationModel.d.ts +2 -1
- package/model-function/generate-text/PromptTemplateTextGenerationModel.js +1 -1
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.cjs +1 -1
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.d.ts +1 -1
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.js +1 -1
- 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/cohere/CohereTextEmbeddingModel.d.ts +3 -3
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +6 -6
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +23 -23
- package/model-provider/mistral/MistralTextEmbeddingModel.d.ts +13 -13
- package/model-provider/ollama/OllamaChatModel.d.ts +9 -8
- package/model-provider/ollama/OllamaChatModel.js +1 -1
- package/model-provider/ollama/OllamaCompletionModel.d.ts +2 -1
- package/model-provider/ollama/OllamaCompletionModel.js +1 -1
- package/model-provider/ollama/OllamaCompletionModel.test.cjs +1 -7
- package/model-provider/ollama/OllamaCompletionModel.test.js +1 -7
- package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +12 -12
- package/model-provider/openai/OpenAITranscriptionModel.d.ts +11 -11
- package/model-provider/openai/index.cjs +0 -1
- package/model-provider/openai/index.d.ts +0 -1
- package/model-provider/openai/index.js +0 -1
- package/model-provider/stability/StabilityImageGenerationModel.d.ts +5 -5
- package/package.json +9 -20
- 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/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/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/GuardEvent.js +0 -1
- 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-provider/openai/OpenAICostCalculator.cjs +0 -89
- package/model-provider/openai/OpenAICostCalculator.d.ts +0 -6
- package/model-provider/openai/OpenAICostCalculator.js +0 -85
- package/server/fastify/AssetStorage.cjs +0 -2
- package/server/fastify/AssetStorage.d.ts +0 -17
- package/server/fastify/AssetStorage.js +0 -1
- 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/Flow.js +0 -1
- 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/FlowSchema.js +0 -1
- package/server/fastify/Logger.cjs +0 -2
- package/server/fastify/Logger.d.ts +0 -13
- package/server/fastify/Logger.js +0 -1
- 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.cjs → tool/generate-tool-calls-or-text/ToolCallsOrGenerateTextPromptTemplate.cjs} +0 -0
- /package/{cost/CostCalculator.js → tool/generate-tool-calls-or-text/ToolCallsOrGenerateTextPromptTemplate.js} +0 -0
@@ -1,10 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.extractSuccessfulModelCalls = void 0;
|
4
|
-
function extractSuccessfulModelCalls(runFunctionEvents) {
|
5
|
-
return runFunctionEvents.filter((event) => "model" in event &&
|
6
|
-
"result" in event &&
|
7
|
-
"status" in event.result &&
|
8
|
-
event.result.status === "success");
|
9
|
-
}
|
10
|
-
exports.extractSuccessfulModelCalls = extractSuccessfulModelCalls;
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import { FunctionEvent } from "../core/FunctionEvent.js";
|
2
|
-
import { ModelCallFinishedEvent } from "./ModelCallEvent.js";
|
3
|
-
export type SuccessfulModelCall = ModelCallFinishedEvent & {
|
4
|
-
result: {
|
5
|
-
status: "success";
|
6
|
-
};
|
7
|
-
};
|
8
|
-
export declare function extractSuccessfulModelCalls(runFunctionEvents: FunctionEvent[]): (ModelCallFinishedEvent & {
|
9
|
-
result: {
|
10
|
-
status: "success";
|
11
|
-
};
|
12
|
-
})[];
|
@@ -1,89 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.OpenAICostCalculator = void 0;
|
4
|
-
const OpenAICompletionModel_js_1 = require("./OpenAICompletionModel.cjs");
|
5
|
-
const OpenAIImageGenerationModel_js_1 = require("./OpenAIImageGenerationModel.cjs");
|
6
|
-
const OpenAISpeechModel_js_1 = require("./OpenAISpeechModel.cjs");
|
7
|
-
const OpenAITextEmbeddingModel_js_1 = require("./OpenAITextEmbeddingModel.cjs");
|
8
|
-
const OpenAITranscriptionModel_js_1 = require("./OpenAITranscriptionModel.cjs");
|
9
|
-
const OpenAIChatModel_js_1 = require("./OpenAIChatModel.cjs");
|
10
|
-
class OpenAICostCalculator {
|
11
|
-
constructor() {
|
12
|
-
Object.defineProperty(this, "provider", {
|
13
|
-
enumerable: true,
|
14
|
-
configurable: true,
|
15
|
-
writable: true,
|
16
|
-
value: "openai"
|
17
|
-
});
|
18
|
-
}
|
19
|
-
async calculateCostInMillicents(call) {
|
20
|
-
const type = call.functionType;
|
21
|
-
const model = call.model.modelName;
|
22
|
-
switch (type) {
|
23
|
-
case "generate-image": {
|
24
|
-
if (model == null) {
|
25
|
-
return null;
|
26
|
-
}
|
27
|
-
return (0, OpenAIImageGenerationModel_js_1.calculateOpenAIImageGenerationCostInMillicents)({
|
28
|
-
model: model,
|
29
|
-
settings: call.settings,
|
30
|
-
});
|
31
|
-
}
|
32
|
-
case "embed": {
|
33
|
-
if (model == null) {
|
34
|
-
return null;
|
35
|
-
}
|
36
|
-
if ((0, OpenAITextEmbeddingModel_js_1.isOpenAIEmbeddingModel)(model)) {
|
37
|
-
const responses = Array.isArray(call.result.response)
|
38
|
-
? call.result.response
|
39
|
-
: [call.result.response];
|
40
|
-
return (0, OpenAITextEmbeddingModel_js_1.calculateOpenAIEmbeddingCostInMillicents)({
|
41
|
-
model,
|
42
|
-
responses,
|
43
|
-
});
|
44
|
-
}
|
45
|
-
break;
|
46
|
-
}
|
47
|
-
case "generate-structure":
|
48
|
-
case "generate-text": {
|
49
|
-
if (model == null) {
|
50
|
-
return null;
|
51
|
-
}
|
52
|
-
if ((0, OpenAIChatModel_js_1.isOpenAIChatModel)(model)) {
|
53
|
-
return (0, OpenAIChatModel_js_1.calculateOpenAIChatCostInMillicents)({
|
54
|
-
model,
|
55
|
-
response: call.result.response,
|
56
|
-
});
|
57
|
-
}
|
58
|
-
if ((0, OpenAICompletionModel_js_1.isOpenAICompletionModel)(model)) {
|
59
|
-
return (0, OpenAICompletionModel_js_1.calculateOpenAICompletionCostInMillicents)({
|
60
|
-
model,
|
61
|
-
response: call.result.response,
|
62
|
-
});
|
63
|
-
}
|
64
|
-
break;
|
65
|
-
}
|
66
|
-
case "generate-transcription": {
|
67
|
-
if (model == null) {
|
68
|
-
return null;
|
69
|
-
}
|
70
|
-
return (0, OpenAITranscriptionModel_js_1.calculateOpenAITranscriptionCostInMillicents)({
|
71
|
-
model: model,
|
72
|
-
response: call.result
|
73
|
-
.response,
|
74
|
-
});
|
75
|
-
}
|
76
|
-
case "generate-speech": {
|
77
|
-
if (model == null) {
|
78
|
-
return null;
|
79
|
-
}
|
80
|
-
return (0, OpenAISpeechModel_js_1.calculateOpenAISpeechCostInMillicents)({
|
81
|
-
model: model,
|
82
|
-
input: call.input,
|
83
|
-
});
|
84
|
-
}
|
85
|
-
}
|
86
|
-
return null;
|
87
|
-
}
|
88
|
-
}
|
89
|
-
exports.OpenAICostCalculator = OpenAICostCalculator;
|
@@ -1,6 +0,0 @@
|
|
1
|
-
import { CostCalculator } from "../../cost/CostCalculator.js";
|
2
|
-
import { SuccessfulModelCall } from "../../model-function/SuccessfulModelCall.js";
|
3
|
-
export declare class OpenAICostCalculator implements CostCalculator {
|
4
|
-
readonly provider = "openai";
|
5
|
-
calculateCostInMillicents(call: SuccessfulModelCall): Promise<number | null>;
|
6
|
-
}
|
@@ -1,85 +0,0 @@
|
|
1
|
-
import { calculateOpenAICompletionCostInMillicents, isOpenAICompletionModel, } from "./OpenAICompletionModel.js";
|
2
|
-
import { calculateOpenAIImageGenerationCostInMillicents, } from "./OpenAIImageGenerationModel.js";
|
3
|
-
import { calculateOpenAISpeechCostInMillicents, } from "./OpenAISpeechModel.js";
|
4
|
-
import { calculateOpenAIEmbeddingCostInMillicents, isOpenAIEmbeddingModel, } from "./OpenAITextEmbeddingModel.js";
|
5
|
-
import { calculateOpenAITranscriptionCostInMillicents, } from "./OpenAITranscriptionModel.js";
|
6
|
-
import { calculateOpenAIChatCostInMillicents, isOpenAIChatModel, } from "./OpenAIChatModel.js";
|
7
|
-
export class OpenAICostCalculator {
|
8
|
-
constructor() {
|
9
|
-
Object.defineProperty(this, "provider", {
|
10
|
-
enumerable: true,
|
11
|
-
configurable: true,
|
12
|
-
writable: true,
|
13
|
-
value: "openai"
|
14
|
-
});
|
15
|
-
}
|
16
|
-
async calculateCostInMillicents(call) {
|
17
|
-
const type = call.functionType;
|
18
|
-
const model = call.model.modelName;
|
19
|
-
switch (type) {
|
20
|
-
case "generate-image": {
|
21
|
-
if (model == null) {
|
22
|
-
return null;
|
23
|
-
}
|
24
|
-
return calculateOpenAIImageGenerationCostInMillicents({
|
25
|
-
model: model,
|
26
|
-
settings: call.settings,
|
27
|
-
});
|
28
|
-
}
|
29
|
-
case "embed": {
|
30
|
-
if (model == null) {
|
31
|
-
return null;
|
32
|
-
}
|
33
|
-
if (isOpenAIEmbeddingModel(model)) {
|
34
|
-
const responses = Array.isArray(call.result.response)
|
35
|
-
? call.result.response
|
36
|
-
: [call.result.response];
|
37
|
-
return calculateOpenAIEmbeddingCostInMillicents({
|
38
|
-
model,
|
39
|
-
responses,
|
40
|
-
});
|
41
|
-
}
|
42
|
-
break;
|
43
|
-
}
|
44
|
-
case "generate-structure":
|
45
|
-
case "generate-text": {
|
46
|
-
if (model == null) {
|
47
|
-
return null;
|
48
|
-
}
|
49
|
-
if (isOpenAIChatModel(model)) {
|
50
|
-
return calculateOpenAIChatCostInMillicents({
|
51
|
-
model,
|
52
|
-
response: call.result.response,
|
53
|
-
});
|
54
|
-
}
|
55
|
-
if (isOpenAICompletionModel(model)) {
|
56
|
-
return calculateOpenAICompletionCostInMillicents({
|
57
|
-
model,
|
58
|
-
response: call.result.response,
|
59
|
-
});
|
60
|
-
}
|
61
|
-
break;
|
62
|
-
}
|
63
|
-
case "generate-transcription": {
|
64
|
-
if (model == null) {
|
65
|
-
return null;
|
66
|
-
}
|
67
|
-
return calculateOpenAITranscriptionCostInMillicents({
|
68
|
-
model: model,
|
69
|
-
response: call.result
|
70
|
-
.response,
|
71
|
-
});
|
72
|
-
}
|
73
|
-
case "generate-speech": {
|
74
|
-
if (model == null) {
|
75
|
-
return null;
|
76
|
-
}
|
77
|
-
return calculateOpenAISpeechCostInMillicents({
|
78
|
-
model: model,
|
79
|
-
input: call.input,
|
80
|
-
});
|
81
|
-
}
|
82
|
-
}
|
83
|
-
return null;
|
84
|
-
}
|
85
|
-
}
|
@@ -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 +0,0 @@
|
|
1
|
-
export {};
|
@@ -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
|
-
}
|
@@ -1,45 +0,0 @@
|
|
1
|
-
import { promises as fs } from "node:fs";
|
2
|
-
import { join } from "node:path";
|
3
|
-
export class FileSystemLogger {
|
4
|
-
constructor({ path }) {
|
5
|
-
Object.defineProperty(this, "logPath", {
|
6
|
-
enumerable: true,
|
7
|
-
configurable: true,
|
8
|
-
writable: true,
|
9
|
-
value: void 0
|
10
|
-
});
|
11
|
-
this.logPath = path;
|
12
|
-
}
|
13
|
-
async logFunctionEvent({ run, event, }) {
|
14
|
-
const timestamp = event.startTimestamp.getTime();
|
15
|
-
try {
|
16
|
-
const logPath = this.logPath(run);
|
17
|
-
await fs.mkdir(logPath, { recursive: true });
|
18
|
-
await fs.writeFile(join(logPath, `${timestamp}-${event.callId}-${event.functionId ?? event.functionType}-${event.eventType}.json`), JSON.stringify(event));
|
19
|
-
}
|
20
|
-
catch (error) {
|
21
|
-
this.logError({
|
22
|
-
run,
|
23
|
-
message: `Failed to write function event ${event.callId}`,
|
24
|
-
error,
|
25
|
-
});
|
26
|
-
}
|
27
|
-
}
|
28
|
-
async logError({ run, error, message, }) {
|
29
|
-
const timestamp = Date.now();
|
30
|
-
try {
|
31
|
-
const logPath = this.logPath(run);
|
32
|
-
await fs.mkdir(logPath, { recursive: true });
|
33
|
-
await fs.writeFile(join(logPath, `${timestamp}-error.json`), JSON.stringify({
|
34
|
-
timestamp: new Date(timestamp).toISOString(),
|
35
|
-
runId: run.runId,
|
36
|
-
message,
|
37
|
-
error,
|
38
|
-
}));
|
39
|
-
}
|
40
|
-
catch (error) {
|
41
|
-
console.error(`Failed to write error log`);
|
42
|
-
console.error(error);
|
43
|
-
}
|
44
|
-
}
|
45
|
-
}
|
package/server/fastify/Flow.cjs
DELETED
package/server/fastify/Flow.d.ts
DELETED
package/server/fastify/Flow.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,71 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.FlowRun = void 0;
|
4
|
-
const DefaultRun_js_1 = require("../../core/DefaultRun.cjs");
|
5
|
-
const AsyncQueue_js_1 = require("../../util/AsyncQueue.cjs");
|
6
|
-
class FlowRun extends DefaultRun_js_1.DefaultRun {
|
7
|
-
constructor({ paths, assetStorage, logger, }) {
|
8
|
-
super();
|
9
|
-
Object.defineProperty(this, "eventQueue", {
|
10
|
-
enumerable: true,
|
11
|
-
configurable: true,
|
12
|
-
writable: true,
|
13
|
-
value: new AsyncQueue_js_1.AsyncQueue()
|
14
|
-
});
|
15
|
-
Object.defineProperty(this, "assetStorage", {
|
16
|
-
enumerable: true,
|
17
|
-
configurable: true,
|
18
|
-
writable: true,
|
19
|
-
value: void 0
|
20
|
-
});
|
21
|
-
Object.defineProperty(this, "logger", {
|
22
|
-
enumerable: true,
|
23
|
-
configurable: true,
|
24
|
-
writable: true,
|
25
|
-
value: void 0
|
26
|
-
});
|
27
|
-
Object.defineProperty(this, "paths", {
|
28
|
-
enumerable: true,
|
29
|
-
configurable: true,
|
30
|
-
writable: true,
|
31
|
-
value: void 0
|
32
|
-
});
|
33
|
-
Object.defineProperty(this, "functionObserver", {
|
34
|
-
enumerable: true,
|
35
|
-
configurable: true,
|
36
|
-
writable: true,
|
37
|
-
value: {
|
38
|
-
onFunctionEvent: async (event) => {
|
39
|
-
this.logger.logFunctionEvent({
|
40
|
-
run: this,
|
41
|
-
event,
|
42
|
-
});
|
43
|
-
},
|
44
|
-
}
|
45
|
-
});
|
46
|
-
this.paths = paths;
|
47
|
-
this.assetStorage = assetStorage;
|
48
|
-
this.logger = logger;
|
49
|
-
}
|
50
|
-
publishEvent(event) {
|
51
|
-
this.eventQueue.push(event);
|
52
|
-
}
|
53
|
-
async storeBinaryAsset(asset) {
|
54
|
-
await this.assetStorage.storeAsset({
|
55
|
-
run: this,
|
56
|
-
asset,
|
57
|
-
});
|
58
|
-
return this.paths.getAssetUrl(this.runId, asset.name);
|
59
|
-
}
|
60
|
-
async storeTextAsset(asset) {
|
61
|
-
return this.storeBinaryAsset({
|
62
|
-
data: Buffer.from(asset.text),
|
63
|
-
contentType: asset.contentType,
|
64
|
-
name: asset.name,
|
65
|
-
});
|
66
|
-
}
|
67
|
-
finish() {
|
68
|
-
this.eventQueue.close();
|
69
|
-
}
|
70
|
-
}
|
71
|
-
exports.FlowRun = FlowRun;
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import { DefaultRun } from "../../core/DefaultRun.js";
|
2
|
-
import { FunctionEvent } from "../../core/FunctionEvent.js";
|
3
|
-
import { AsyncQueue } from "../../util/AsyncQueue.js";
|
4
|
-
import { Asset, AssetStorage } from "./AssetStorage.js";
|
5
|
-
import { Logger } from "./Logger.js";
|
6
|
-
import { PathProvider } from "./PathProvider.js";
|
7
|
-
export declare class FlowRun<EVENT> extends DefaultRun {
|
8
|
-
readonly eventQueue: AsyncQueue<EVENT>;
|
9
|
-
private readonly assetStorage;
|
10
|
-
private readonly logger;
|
11
|
-
private readonly paths;
|
12
|
-
constructor({ paths, assetStorage, logger, }: {
|
13
|
-
paths: PathProvider;
|
14
|
-
assetStorage: AssetStorage;
|
15
|
-
logger: Logger;
|
16
|
-
});
|
17
|
-
readonly functionObserver: {
|
18
|
-
onFunctionEvent: (event: FunctionEvent) => Promise<void>;
|
19
|
-
};
|
20
|
-
publishEvent(event: EVENT): void;
|
21
|
-
storeBinaryAsset(asset: Asset): Promise<string>;
|
22
|
-
storeTextAsset(asset: {
|
23
|
-
text: string;
|
24
|
-
contentType: string;
|
25
|
-
name: string;
|
26
|
-
}): Promise<string>;
|
27
|
-
finish(): void;
|
28
|
-
}
|