@valerypopoff/rivet2-core 2.0.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/LICENSE +7 -0
- package/README.md +15 -0
- package/dist/cjs/bundle.cjs +28772 -0
- package/dist/cjs/bundle.cjs.map +7 -0
- package/dist/esm/api/createProcessor.js +116 -0
- package/dist/esm/api/looseDataValue.js +16 -0
- package/dist/esm/api/processSettings.js +16 -0
- package/dist/esm/api/streaming.js +116 -0
- package/dist/esm/exports.js +48 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/integrations/AudioProvider.js +1 -0
- package/dist/esm/integrations/CodeRunner.js +44 -0
- package/dist/esm/integrations/DatasetProvider.js +92 -0
- package/dist/esm/integrations/EmbeddingGenerator.js +1 -0
- package/dist/esm/integrations/GptTokenizerTokenizer.js +67 -0
- package/dist/esm/integrations/LLMProvider.js +1 -0
- package/dist/esm/integrations/Tokenizer.js +1 -0
- package/dist/esm/integrations/VectorDatabase.js +1 -0
- package/dist/esm/integrations/enableIntegrations.js +3 -0
- package/dist/esm/integrations/integrations.js +19 -0
- package/dist/esm/integrations/mcp/MCPBase.js +87 -0
- package/dist/esm/integrations/mcp/MCPProvider.js +23 -0
- package/dist/esm/integrations/mcp/MCPUtils.js +33 -0
- package/dist/esm/integrations/openai/OpenAIEmbeddingGenerator.js +23 -0
- package/dist/esm/model/CycleDetector.js +43 -0
- package/dist/esm/model/DataValue.js +188 -0
- package/dist/esm/model/Dataset.js +1 -0
- package/dist/esm/model/EditorDefinition.js +1 -0
- package/dist/esm/model/ExecutorProtocol.js +1 -0
- package/dist/esm/model/GraphPreprocessor.js +97 -0
- package/dist/esm/model/GraphProcessor.js +1136 -0
- package/dist/esm/model/NodeBase.js +11 -0
- package/dist/esm/model/NodeBodySpec.js +1 -0
- package/dist/esm/model/NodeDefinition.js +12 -0
- package/dist/esm/model/NodeExecutionPlanner.js +82 -0
- package/dist/esm/model/NodeGraph.js +14 -0
- package/dist/esm/model/NodeImpl.js +57 -0
- package/dist/esm/model/NodeRegistration.js +146 -0
- package/dist/esm/model/Nodes.js +279 -0
- package/dist/esm/model/PluginLoadSpec.js +1 -0
- package/dist/esm/model/ProcessContext.js +1 -0
- package/dist/esm/model/ProcessContextBuilder.js +33 -0
- package/dist/esm/model/Project.js +2 -0
- package/dist/esm/model/ProjectReferenceLoader.js +1 -0
- package/dist/esm/model/RecordingPlayer.js +262 -0
- package/dist/esm/model/RegistryAssembly.js +53 -0
- package/dist/esm/model/RivetPlugin.js +1 -0
- package/dist/esm/model/RivetUIContext.js +1 -0
- package/dist/esm/model/Settings.js +1 -0
- package/dist/esm/model/SplitRunProcessor.js +98 -0
- package/dist/esm/model/SubprocessorBridge.js +82 -0
- package/dist/esm/model/chat/aiSdkMessages.js +105 -0
- package/dist/esm/model/chat/aiSdkStreaming.js +38 -0
- package/dist/esm/model/chat/aiSdkTools.js +10 -0
- package/dist/esm/model/chat/chatCost.js +33 -0
- package/dist/esm/model/chat/chatMessages.js +47 -0
- package/dist/esm/model/chat/openAIChatRequest.js +110 -0
- package/dist/esm/model/chat/openAIChatRuntime.js +220 -0
- package/dist/esm/model/chat/streamChatResponse.js +97 -0
- package/dist/esm/model/chat/tokenBudget.js +16 -0
- package/dist/esm/model/chat-v2/aiSdkBridge.js +88 -0
- package/dist/esm/model/chat-v2/chatV2EditorCache.js +107 -0
- package/dist/esm/model/chat-v2/chatV2Errors.js +255 -0
- package/dist/esm/model/chat-v2/chatV2FeatureCompatibility.js +16 -0
- package/dist/esm/model/chat-v2/chatV2Pipeline.js +387 -0
- package/dist/esm/model/chat-v2/chatV2ResponseFormat.js +57 -0
- package/dist/esm/model/chat-v2/chatV2Retry.js +41 -0
- package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +242 -0
- package/dist/esm/model/chat-v2/chatV2Shared.js +285 -0
- package/dist/esm/model/chat-v2/chatV2Types.js +1 -0
- package/dist/esm/model/chat-v2/index.js +10 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeData.js +56 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +475 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +90 -0
- package/dist/esm/model/chat-v2/messageConverter.js +173 -0
- package/dist/esm/model/chat-v2/modelRegistry.js +23 -0
- package/dist/esm/model/chat-v2/providerOptions.js +202 -0
- package/dist/esm/model/chat-v2/toolContinuation.js +108 -0
- package/dist/esm/model/chat-v2/toolConverter.js +4 -0
- package/dist/esm/model/interpolationInputDefinition.js +36 -0
- package/dist/esm/model/loopControllerBreak.js +4 -0
- package/dist/esm/model/nodes/AbortGraphNode.js +100 -0
- package/dist/esm/model/nodes/AppendToDatasetNode.js +115 -0
- package/dist/esm/model/nodes/ArrayNode.js +144 -0
- package/dist/esm/model/nodes/AssembleMessageNode.js +209 -0
- package/dist/esm/model/nodes/AssemblePromptNode.js +151 -0
- package/dist/esm/model/nodes/AudioNode.js +101 -0
- package/dist/esm/model/nodes/BooleanNode.js +74 -0
- package/dist/esm/model/nodes/CallGraphNode.js +135 -0
- package/dist/esm/model/nodes/ChatLoopNode.js +150 -0
- package/dist/esm/model/nodes/ChatNode.js +56 -0
- package/dist/esm/model/nodes/ChatNodeBase.js +912 -0
- package/dist/esm/model/nodes/ChunkNode.js +166 -0
- package/dist/esm/model/nodes/CoalesceNode.js +104 -0
- package/dist/esm/model/nodes/CodeNode.js +197 -0
- package/dist/esm/model/nodes/CommentNode.js +71 -0
- package/dist/esm/model/nodes/CompareNode.js +144 -0
- package/dist/esm/model/nodes/ContextNode.js +99 -0
- package/dist/esm/model/nodes/CreateDatasetNode.js +71 -0
- package/dist/esm/model/nodes/CronNode.js +248 -0
- package/dist/esm/model/nodes/DatasetNearestNeigborsNode.js +97 -0
- package/dist/esm/model/nodes/DelayNode.js +105 -0
- package/dist/esm/model/nodes/DelegateFunctionCallNode.js +175 -0
- package/dist/esm/model/nodes/DestructureNode.js +110 -0
- package/dist/esm/model/nodes/DocumentNode.js +183 -0
- package/dist/esm/model/nodes/EvaluateNode.js +141 -0
- package/dist/esm/model/nodes/ExpressionNode.js +143 -0
- package/dist/esm/model/nodes/ExternalCallNode.js +162 -0
- package/dist/esm/model/nodes/ExtractJsonNode.js +122 -0
- package/dist/esm/model/nodes/ExtractMarkdownCodeBlocksNode.js +100 -0
- package/dist/esm/model/nodes/ExtractObjectPathNode.js +159 -0
- package/dist/esm/model/nodes/ExtractRegexNode.js +200 -0
- package/dist/esm/model/nodes/ExtractYamlNode.js +214 -0
- package/dist/esm/model/nodes/FilterNode.js +73 -0
- package/dist/esm/model/nodes/GetAllDatasetsNode.js +53 -0
- package/dist/esm/model/nodes/GetDatasetRowNode.js +99 -0
- package/dist/esm/model/nodes/GetEmbeddingNode.js +130 -0
- package/dist/esm/model/nodes/GetGlobalNode.js +139 -0
- package/dist/esm/model/nodes/GraphInputNode.js +132 -0
- package/dist/esm/model/nodes/GraphOutputNode.js +104 -0
- package/dist/esm/model/nodes/GraphReferenceNode.js +128 -0
- package/dist/esm/model/nodes/HashNode.js +97 -0
- package/dist/esm/model/nodes/HttpCallNode.js +592 -0
- package/dist/esm/model/nodes/IfElseNode.js +138 -0
- package/dist/esm/model/nodes/IfNode.js +129 -0
- package/dist/esm/model/nodes/ImageNode.js +107 -0
- package/dist/esm/model/nodes/JSFilterNode.js +69 -0
- package/dist/esm/model/nodes/JSMapNode.js +69 -0
- package/dist/esm/model/nodes/JoinNode.js +135 -0
- package/dist/esm/model/nodes/LLMChatV2Node.js +234 -0
- package/dist/esm/model/nodes/ListGraphsNode.js +61 -0
- package/dist/esm/model/nodes/LoadDatasetNode.js +83 -0
- package/dist/esm/model/nodes/LoopControllerNode.js +206 -0
- package/dist/esm/model/nodes/LoopUntilNode.js +214 -0
- package/dist/esm/model/nodes/MCPDiscoveryNode.js +214 -0
- package/dist/esm/model/nodes/MCPGetPromptNode.js +234 -0
- package/dist/esm/model/nodes/MCPToolCallNode.js +262 -0
- package/dist/esm/model/nodes/MatchNode.js +160 -0
- package/dist/esm/model/nodes/NumberNode.js +86 -0
- package/dist/esm/model/nodes/ObjectNode.js +152 -0
- package/dist/esm/model/nodes/PassthroughNode.js +78 -0
- package/dist/esm/model/nodes/PlayAudioNode.js +61 -0
- package/dist/esm/model/nodes/PopNode.js +89 -0
- package/dist/esm/model/nodes/PromptNode.js +248 -0
- package/dist/esm/model/nodes/RaceInputsNode.js +85 -0
- package/dist/esm/model/nodes/RaiseEventNode.js +84 -0
- package/dist/esm/model/nodes/RandomNumberNode.js +117 -0
- package/dist/esm/model/nodes/ReadAllFilesNode.js +210 -0
- package/dist/esm/model/nodes/ReadDirectoryNode.js +171 -0
- package/dist/esm/model/nodes/ReadFileNode.js +114 -0
- package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +199 -0
- package/dist/esm/model/nodes/ReplaceDatasetNode.js +118 -0
- package/dist/esm/model/nodes/SetGlobalNode.js +124 -0
- package/dist/esm/model/nodes/ShuffleNode.js +64 -0
- package/dist/esm/model/nodes/SliceNode.js +99 -0
- package/dist/esm/model/nodes/SplitNode.js +101 -0
- package/dist/esm/model/nodes/SubGraphNode.js +180 -0
- package/dist/esm/model/nodes/TextNode.js +125 -0
- package/dist/esm/model/nodes/ToJsonNode.js +78 -0
- package/dist/esm/model/nodes/ToMarkdownTableNode.js +119 -0
- package/dist/esm/model/nodes/ToTreeNode.js +133 -0
- package/dist/esm/model/nodes/ToYamlNode.js +68 -0
- package/dist/esm/model/nodes/ToolNode.js +172 -0
- package/dist/esm/model/nodes/TrimChatMessagesNode.js +120 -0
- package/dist/esm/model/nodes/URLReferenceNode.js +79 -0
- package/dist/esm/model/nodes/UserInputNode.js +109 -0
- package/dist/esm/model/nodes/VectorNearestNeighborsNode.js +127 -0
- package/dist/esm/model/nodes/VectorStoreNode.js +124 -0
- package/dist/esm/model/nodes/WaitForEventNode.js +88 -0
- package/dist/esm/model/nodes/codeNodeErrorDiagnostics.js +104 -0
- package/dist/esm/model/nodes/jsListCallbackHelpers.js +196 -0
- package/dist/esm/model/nodes/jsValueInterpolation.js +163 -0
- package/dist/esm/model/nodes/toolCallDelegation.js +159 -0
- package/dist/esm/native/BaseDir.js +32 -0
- package/dist/esm/native/BrowserNativeApi.js +19 -0
- package/dist/esm/native/NativeApi.js +1 -0
- package/dist/esm/plugins/anthropic/anthropic.js +208 -0
- package/dist/esm/plugins/anthropic/fetchEventSource.js +107 -0
- package/dist/esm/plugins/anthropic/index.js +2 -0
- package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +767 -0
- package/dist/esm/plugins/anthropic/plugin.js +26 -0
- package/dist/esm/plugins/assemblyAi/LemurActionItemsNode.js +75 -0
- package/dist/esm/plugins/assemblyAi/LemurQaNode.js +155 -0
- package/dist/esm/plugins/assemblyAi/LemurSummaryNode.js +79 -0
- package/dist/esm/plugins/assemblyAi/LemurTaskNode.js +82 -0
- package/dist/esm/plugins/assemblyAi/TranscribeAudioNode.js +126 -0
- package/dist/esm/plugins/assemblyAi/index.js +2 -0
- package/dist/esm/plugins/assemblyAi/lemurHelpers.js +114 -0
- package/dist/esm/plugins/assemblyAi/plugin.js +32 -0
- package/dist/esm/plugins/autoevals/AutoEvalsNode.js +223 -0
- package/dist/esm/plugins/autoevals/index.js +2 -0
- package/dist/esm/plugins/autoevals/plugin.js +8 -0
- package/dist/esm/plugins/gentrace/index.js +3 -0
- package/dist/esm/plugins/gentrace/plugin.js +195 -0
- package/dist/esm/plugins/google/google.js +165 -0
- package/dist/esm/plugins/google/index.js +2 -0
- package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +584 -0
- package/dist/esm/plugins/google/plugin.js +39 -0
- package/dist/esm/plugins/huggingface/index.js +2 -0
- package/dist/esm/plugins/huggingface/nodes/ChatHuggingFace.js +243 -0
- package/dist/esm/plugins/huggingface/nodes/TextToImageHuggingFace.js +189 -0
- package/dist/esm/plugins/huggingface/plugin.js +26 -0
- package/dist/esm/plugins/openai/handleOpenaiError.js +17 -0
- package/dist/esm/plugins/openai/index.js +2 -0
- package/dist/esm/plugins/openai/nodes/AttachAssistantFileNode.js +123 -0
- package/dist/esm/plugins/openai/nodes/CreateAssistantNode.js +289 -0
- package/dist/esm/plugins/openai/nodes/CreateThreadMessageNode.js +176 -0
- package/dist/esm/plugins/openai/nodes/CreateThreadNode.js +157 -0
- package/dist/esm/plugins/openai/nodes/DeleteAssistantNode.js +104 -0
- package/dist/esm/plugins/openai/nodes/DeleteThreadNode.js +97 -0
- package/dist/esm/plugins/openai/nodes/GetAssistantNode.js +118 -0
- package/dist/esm/plugins/openai/nodes/GetOpenAIFileNode.js +100 -0
- package/dist/esm/plugins/openai/nodes/GetThreadNode.js +108 -0
- package/dist/esm/plugins/openai/nodes/ListAssistantsNode.js +202 -0
- package/dist/esm/plugins/openai/nodes/ListOpenAIFilesNode.js +94 -0
- package/dist/esm/plugins/openai/nodes/ListThreadMessagesNode.js +224 -0
- package/dist/esm/plugins/openai/nodes/RunThreadNode.js +630 -0
- package/dist/esm/plugins/openai/nodes/ThreadMessageNode.js +143 -0
- package/dist/esm/plugins/openai/nodes/UploadFileNode.js +121 -0
- package/dist/esm/plugins/openai/plugin.js +44 -0
- package/dist/esm/plugins/pinecone/PineconeVectorDatabase.js +88 -0
- package/dist/esm/plugins/pinecone/index.js +2 -0
- package/dist/esm/plugins/pinecone/plugin.js +19 -0
- package/dist/esm/plugins.js +29 -0
- package/dist/esm/recording/ExecutionRecorder.js +273 -0
- package/dist/esm/recording/RecordedEvents.js +1 -0
- package/dist/esm/utils/assertNever.js +3 -0
- package/dist/esm/utils/base64.js +38 -0
- package/dist/esm/utils/chatMessageToOpenAIChatCompletionMessage.js +73 -0
- package/dist/esm/utils/coerceType.js +326 -0
- package/dist/esm/utils/compatibility.js +27 -0
- package/dist/esm/utils/copyToClipboard.js +10 -0
- package/dist/esm/utils/defaults.js +2 -0
- package/dist/esm/utils/emitDetached.js +12 -0
- package/dist/esm/utils/errors.js +7 -0
- package/dist/esm/utils/expectType.js +34 -0
- package/dist/esm/utils/fetchEventSource.js +120 -0
- package/dist/esm/utils/genericUtilFunctions.js +25 -0
- package/dist/esm/utils/getPluginConfig.js +23 -0
- package/dist/esm/utils/handleEscapeCharacters.js +11 -0
- package/dist/esm/utils/index.js +17 -0
- package/dist/esm/utils/inputs.js +16 -0
- package/dist/esm/utils/interpolation.js +286 -0
- package/dist/esm/utils/misc.js +1 -0
- package/dist/esm/utils/newId.js +4 -0
- package/dist/esm/utils/openai.js +206 -0
- package/dist/esm/utils/orderedStringPortIds.js +27 -0
- package/dist/esm/utils/outputs.js +14 -0
- package/dist/esm/utils/pQueueCompat.js +12 -0
- package/dist/esm/utils/paths.js +80 -0
- package/dist/esm/utils/providerStreamParsing.js +14 -0
- package/dist/esm/utils/runtimeLogging.js +121 -0
- package/dist/esm/utils/serialization/serialization.js +77 -0
- package/dist/esm/utils/serialization/serializationHelpers.js +63 -0
- package/dist/esm/utils/serialization/serializationUtils.js +112 -0
- package/dist/esm/utils/serialization/serialization_v1.js +19 -0
- package/dist/esm/utils/serialization/serialization_v2.js +24 -0
- package/dist/esm/utils/serialization/serialization_v3.js +100 -0
- package/dist/esm/utils/serialization/serialization_v4.js +156 -0
- package/dist/esm/utils/symbols.js +2 -0
- package/dist/esm/utils/time.js +14 -0
- package/dist/esm/utils/typeSafety.js +42 -0
- package/dist/esm/vendor/fnv1a.js +80 -0
- package/dist/types/api/createProcessor.d.ts +56 -0
- package/dist/types/api/looseDataValue.d.ts +4 -0
- package/dist/types/api/processSettings.d.ts +4 -0
- package/dist/types/api/streaming.d.ts +56 -0
- package/dist/types/exports.d.ts +49 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/integrations/AudioProvider.d.ts +4 -0
- package/dist/types/integrations/CodeRunner.d.ts +19 -0
- package/dist/types/integrations/DatasetProvider.d.ts +33 -0
- package/dist/types/integrations/EmbeddingGenerator.d.ts +3 -0
- package/dist/types/integrations/GptTokenizerTokenizer.d.ts +20 -0
- package/dist/types/integrations/LLMProvider.d.ts +7 -0
- package/dist/types/integrations/Tokenizer.d.ts +11 -0
- package/dist/types/integrations/VectorDatabase.d.ts +7 -0
- package/dist/types/integrations/enableIntegrations.d.ts +1 -0
- package/dist/types/integrations/integrations.d.ts +12 -0
- package/dist/types/integrations/mcp/MCPBase.d.ts +18 -0
- package/dist/types/integrations/mcp/MCPProvider.d.ts +153 -0
- package/dist/types/integrations/mcp/MCPUtils.d.ts +9 -0
- package/dist/types/integrations/openai/OpenAIEmbeddingGenerator.d.ts +10 -0
- package/dist/types/model/CycleDetector.d.ts +2 -0
- package/dist/types/model/DataValue.d.ts +160 -0
- package/dist/types/model/Dataset.d.ts +19 -0
- package/dist/types/model/EditorDefinition.d.ts +176 -0
- package/dist/types/model/ExecutorProtocol.d.ts +216 -0
- package/dist/types/model/GraphPreprocessor.d.ts +24 -0
- package/dist/types/model/GraphProcessor.d.ts +210 -0
- package/dist/types/model/NodeBase.d.ts +116 -0
- package/dist/types/model/NodeBodySpec.d.ts +19 -0
- package/dist/types/model/NodeDefinition.d.ts +13 -0
- package/dist/types/model/NodeExecutionPlanner.d.ts +28 -0
- package/dist/types/model/NodeGraph.d.ts +15 -0
- package/dist/types/model/NodeImpl.d.ts +56 -0
- package/dist/types/model/NodeRegistration.d.ts +29 -0
- package/dist/types/model/Nodes.d.ts +112 -0
- package/dist/types/model/PluginLoadSpec.d.ts +17 -0
- package/dist/types/model/ProcessContext.d.ts +110 -0
- package/dist/types/model/ProcessContextBuilder.d.ts +41 -0
- package/dist/types/model/Project.d.ts +31 -0
- package/dist/types/model/ProjectReferenceLoader.d.ts +5 -0
- package/dist/types/model/RecordingPlayer.d.ts +27 -0
- package/dist/types/model/RegistryAssembly.d.ts +42 -0
- package/dist/types/model/RivetPlugin.d.ts +51 -0
- package/dist/types/model/RivetUIContext.d.ts +27 -0
- package/dist/types/model/Settings.d.ts +20 -0
- package/dist/types/model/SplitRunProcessor.d.ts +31 -0
- package/dist/types/model/SubprocessorBridge.d.ts +13 -0
- package/dist/types/model/chat/aiSdkMessages.d.ts +3 -0
- package/dist/types/model/chat/aiSdkStreaming.d.ts +9 -0
- package/dist/types/model/chat/aiSdkTools.d.ts +3 -0
- package/dist/types/model/chat/chatCost.d.ts +30 -0
- package/dist/types/model/chat/chatMessages.d.ts +5 -0
- package/dist/types/model/chat/openAIChatRequest.d.ts +39 -0
- package/dist/types/model/chat/openAIChatRuntime.d.ts +61 -0
- package/dist/types/model/chat/streamChatResponse.d.ts +27 -0
- package/dist/types/model/chat/tokenBudget.d.ts +3 -0
- package/dist/types/model/chat-v2/aiSdkBridge.d.ts +2 -0
- package/dist/types/model/chat-v2/chatV2EditorCache.d.ts +25 -0
- package/dist/types/model/chat-v2/chatV2Errors.d.ts +23 -0
- package/dist/types/model/chat-v2/chatV2FeatureCompatibility.d.ts +12 -0
- package/dist/types/model/chat-v2/chatV2Pipeline.d.ts +2 -0
- package/dist/types/model/chat-v2/chatV2ResponseFormat.d.ts +24 -0
- package/dist/types/model/chat-v2/chatV2Retry.d.ts +5 -0
- package/dist/types/model/chat-v2/chatV2RuntimeOptions.d.ts +12 -0
- package/dist/types/model/chat-v2/chatV2Shared.d.ts +56 -0
- package/dist/types/model/chat-v2/chatV2Types.d.ts +110 -0
- package/dist/types/model/chat-v2/index.d.ts +10 -0
- package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +73 -0
- package/dist/types/model/chat-v2/llmChatV2NodeEditors.d.ts +4 -0
- package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +23 -0
- package/dist/types/model/chat-v2/messageConverter.d.ts +8 -0
- package/dist/types/model/chat-v2/modelRegistry.d.ts +296 -0
- package/dist/types/model/chat-v2/providerOptions.d.ts +59 -0
- package/dist/types/model/chat-v2/toolContinuation.d.ts +15 -0
- package/dist/types/model/chat-v2/toolConverter.d.ts +3 -0
- package/dist/types/model/interpolationInputDefinition.d.ts +16 -0
- package/dist/types/model/loopControllerBreak.d.ts +3 -0
- package/dist/types/model/nodes/AbortGraphNode.d.ts +22 -0
- package/dist/types/model/nodes/AppendToDatasetNode.d.ts +21 -0
- package/dist/types/model/nodes/ArrayNode.d.ts +20 -0
- package/dist/types/model/nodes/AssembleMessageNode.d.ts +23 -0
- package/dist/types/model/nodes/AssemblePromptNode.d.ts +23 -0
- package/dist/types/model/nodes/AudioNode.d.ts +20 -0
- package/dist/types/model/nodes/BooleanNode.d.ts +19 -0
- package/dist/types/model/nodes/CallGraphNode.d.ts +16 -0
- package/dist/types/model/nodes/ChatLoopNode.d.ts +21 -0
- package/dist/types/model/nodes/ChatNode.d.ts +17 -0
- package/dist/types/model/nodes/ChatNodeBase.d.ts +85 -0
- package/dist/types/model/nodes/ChunkNode.d.ts +22 -0
- package/dist/types/model/nodes/CoalesceNode.d.ts +14 -0
- package/dist/types/model/nodes/CodeNode.d.ts +27 -0
- package/dist/types/model/nodes/CommentNode.d.ts +20 -0
- package/dist/types/model/nodes/CompareNode.d.ts +19 -0
- package/dist/types/model/nodes/ContextNode.d.ts +24 -0
- package/dist/types/model/nodes/CreateDatasetNode.d.ts +13 -0
- package/dist/types/model/nodes/CronNode.d.ts +34 -0
- package/dist/types/model/nodes/DatasetNearestNeigborsNode.d.ts +19 -0
- package/dist/types/model/nodes/DelayNode.d.ts +20 -0
- package/dist/types/model/nodes/DelegateFunctionCallNode.d.ts +28 -0
- package/dist/types/model/nodes/DestructureNode.d.ts +19 -0
- package/dist/types/model/nodes/DocumentNode.d.ts +28 -0
- package/dist/types/model/nodes/EvaluateNode.d.ts +19 -0
- package/dist/types/model/nodes/ExpressionNode.d.ts +21 -0
- package/dist/types/model/nodes/ExternalCallNode.d.ts +22 -0
- package/dist/types/model/nodes/ExtractJsonNode.d.ts +13 -0
- package/dist/types/model/nodes/ExtractMarkdownCodeBlocksNode.d.ts +12 -0
- package/dist/types/model/nodes/ExtractObjectPathNode.d.ts +22 -0
- package/dist/types/model/nodes/ExtractRegexNode.d.ts +22 -0
- package/dist/types/model/nodes/ExtractYamlNode.d.ts +21 -0
- package/dist/types/model/nodes/FilterNode.d.ts +13 -0
- package/dist/types/model/nodes/GetAllDatasetsNode.d.ts +14 -0
- package/dist/types/model/nodes/GetDatasetRowNode.d.ts +19 -0
- package/dist/types/model/nodes/GetEmbeddingNode.d.ts +24 -0
- package/dist/types/model/nodes/GetGlobalNode.d.ts +29 -0
- package/dist/types/model/nodes/GraphInputNode.d.ts +24 -0
- package/dist/types/model/nodes/GraphOutputNode.d.ts +22 -0
- package/dist/types/model/nodes/GraphReferenceNode.d.ts +22 -0
- package/dist/types/model/nodes/HashNode.d.ts +17 -0
- package/dist/types/model/nodes/HttpCallNode.d.ts +32 -0
- package/dist/types/model/nodes/IfElseNode.d.ts +18 -0
- package/dist/types/model/nodes/IfNode.d.ts +17 -0
- package/dist/types/model/nodes/ImageNode.d.ts +20 -0
- package/dist/types/model/nodes/JSFilterNode.d.ts +19 -0
- package/dist/types/model/nodes/JSMapNode.d.ts +19 -0
- package/dist/types/model/nodes/JoinNode.d.ts +21 -0
- package/dist/types/model/nodes/LLMChatV2Node.d.ts +20 -0
- package/dist/types/model/nodes/ListGraphsNode.d.ts +14 -0
- package/dist/types/model/nodes/LoadDatasetNode.d.ts +17 -0
- package/dist/types/model/nodes/LoopControllerNode.d.ts +20 -0
- package/dist/types/model/nodes/LoopUntilNode.d.ts +32 -0
- package/dist/types/model/nodes/MCPDiscoveryNode.d.ts +9 -0
- package/dist/types/model/nodes/MCPGetPromptNode.d.ts +23 -0
- package/dist/types/model/nodes/MCPToolCallNode.d.ts +26 -0
- package/dist/types/model/nodes/MatchNode.d.ts +20 -0
- package/dist/types/model/nodes/NumberNode.d.ts +21 -0
- package/dist/types/model/nodes/ObjectNode.d.ts +19 -0
- package/dist/types/model/nodes/PassthroughNode.d.ts +14 -0
- package/dist/types/model/nodes/PlayAudioNode.d.ts +15 -0
- package/dist/types/model/nodes/PopNode.d.ts +19 -0
- package/dist/types/model/nodes/PromptNode.d.ts +25 -0
- package/dist/types/model/nodes/RaceInputsNode.d.ts +16 -0
- package/dist/types/model/nodes/RaiseEventNode.d.ts +22 -0
- package/dist/types/model/nodes/RandomNumberNode.d.ts +23 -0
- package/dist/types/model/nodes/ReadAllFilesNode.d.ts +30 -0
- package/dist/types/model/nodes/ReadDirectoryNode.d.ts +30 -0
- package/dist/types/model/nodes/ReadFileNode.d.ts +23 -0
- package/dist/types/model/nodes/ReferencedGraphAliasNode.d.ts +31 -0
- package/dist/types/model/nodes/ReplaceDatasetNode.d.ts +21 -0
- package/dist/types/model/nodes/SetGlobalNode.d.ts +23 -0
- package/dist/types/model/nodes/ShuffleNode.d.ts +12 -0
- package/dist/types/model/nodes/SliceNode.d.ts +22 -0
- package/dist/types/model/nodes/SplitNode.d.ts +19 -0
- package/dist/types/model/nodes/SubGraphNode.d.ts +29 -0
- package/dist/types/model/nodes/TextNode.d.ts +19 -0
- package/dist/types/model/nodes/ToJsonNode.d.ts +18 -0
- package/dist/types/model/nodes/ToMarkdownTableNode.d.ts +19 -0
- package/dist/types/model/nodes/ToTreeNode.d.ts +21 -0
- package/dist/types/model/nodes/ToYamlNode.d.ts +13 -0
- package/dist/types/model/nodes/ToolNode.d.ts +25 -0
- package/dist/types/model/nodes/TrimChatMessagesNode.d.ts +20 -0
- package/dist/types/model/nodes/URLReferenceNode.d.ts +19 -0
- package/dist/types/model/nodes/UserInputNode.d.ts +20 -0
- package/dist/types/model/nodes/VectorNearestNeighborsNode.d.ts +24 -0
- package/dist/types/model/nodes/VectorStoreNode.d.ts +22 -0
- package/dist/types/model/nodes/WaitForEventNode.d.ts +21 -0
- package/dist/types/model/nodes/codeNodeErrorDiagnostics.d.ts +9 -0
- package/dist/types/model/nodes/jsListCallbackHelpers.d.ts +23 -0
- package/dist/types/model/nodes/jsValueInterpolation.d.ts +11 -0
- package/dist/types/model/nodes/toolCallDelegation.d.ts +29 -0
- package/dist/types/native/BaseDir.d.ts +29 -0
- package/dist/types/native/BrowserNativeApi.d.ts +9 -0
- package/dist/types/native/NativeApi.d.ts +17 -0
- package/dist/types/plugins/anthropic/anthropic.d.ts +315 -0
- package/dist/types/plugins/anthropic/fetchEventSource.d.ts +11 -0
- package/dist/types/plugins/anthropic/index.d.ts +2 -0
- package/dist/types/plugins/anthropic/nodes/ChatAnthropicNode.d.ts +40 -0
- package/dist/types/plugins/anthropic/plugin.d.ts +2 -0
- package/dist/types/plugins/assemblyAi/LemurActionItemsNode.d.ts +6 -0
- package/dist/types/plugins/assemblyAi/LemurQaNode.d.ts +22 -0
- package/dist/types/plugins/assemblyAi/LemurSummaryNode.d.ts +8 -0
- package/dist/types/plugins/assemblyAi/LemurTaskNode.d.ts +8 -0
- package/dist/types/plugins/assemblyAi/TranscribeAudioNode.d.ts +7 -0
- package/dist/types/plugins/assemblyAi/index.d.ts +2 -0
- package/dist/types/plugins/assemblyAi/lemurHelpers.d.ts +67 -0
- package/dist/types/plugins/assemblyAi/plugin.d.ts +2 -0
- package/dist/types/plugins/autoevals/AutoEvalsNode.d.ts +8 -0
- package/dist/types/plugins/autoevals/index.d.ts +2 -0
- package/dist/types/plugins/autoevals/plugin.d.ts +2 -0
- package/dist/types/plugins/gentrace/index.d.ts +2 -0
- package/dist/types/plugins/gentrace/plugin.d.ts +10 -0
- package/dist/types/plugins/google/google.d.ts +129 -0
- package/dist/types/plugins/google/index.d.ts +2 -0
- package/dist/types/plugins/google/nodes/ChatGoogleNode.d.ts +35 -0
- package/dist/types/plugins/google/plugin.d.ts +2 -0
- package/dist/types/plugins/huggingface/index.d.ts +2 -0
- package/dist/types/plugins/huggingface/nodes/ChatHuggingFace.d.ts +24 -0
- package/dist/types/plugins/huggingface/nodes/TextToImageHuggingFace.d.ts +20 -0
- package/dist/types/plugins/huggingface/plugin.d.ts +2 -0
- package/dist/types/plugins/openai/handleOpenaiError.d.ts +1 -0
- package/dist/types/plugins/openai/index.d.ts +2 -0
- package/dist/types/plugins/openai/nodes/AttachAssistantFileNode.d.ts +10 -0
- package/dist/types/plugins/openai/nodes/CreateAssistantNode.d.ts +26 -0
- package/dist/types/plugins/openai/nodes/CreateThreadMessageNode.d.ts +15 -0
- package/dist/types/plugins/openai/nodes/CreateThreadNode.d.ts +13 -0
- package/dist/types/plugins/openai/nodes/DeleteAssistantNode.d.ts +8 -0
- package/dist/types/plugins/openai/nodes/DeleteThreadNode.d.ts +8 -0
- package/dist/types/plugins/openai/nodes/GetAssistantNode.d.ts +8 -0
- package/dist/types/plugins/openai/nodes/GetOpenAIFileNode.d.ts +8 -0
- package/dist/types/plugins/openai/nodes/GetThreadNode.d.ts +8 -0
- package/dist/types/plugins/openai/nodes/ListAssistantsNode.d.ts +14 -0
- package/dist/types/plugins/openai/nodes/ListOpenAIFilesNode.d.ts +8 -0
- package/dist/types/plugins/openai/nodes/ListThreadMessagesNode.d.ts +16 -0
- package/dist/types/plugins/openai/nodes/RunThreadNode.d.ts +28 -0
- package/dist/types/plugins/openai/nodes/ThreadMessageNode.d.ts +14 -0
- package/dist/types/plugins/openai/nodes/UploadFileNode.d.ts +7 -0
- package/dist/types/plugins/openai/plugin.d.ts +2 -0
- package/dist/types/plugins/pinecone/PineconeVectorDatabase.d.ts +9 -0
- package/dist/types/plugins/pinecone/index.d.ts +2 -0
- package/dist/types/plugins/pinecone/plugin.d.ts +2 -0
- package/dist/types/plugins.d.ts +22 -0
- package/dist/types/recording/ExecutionRecorder.d.ts +27 -0
- package/dist/types/recording/RecordedEvents.d.ts +114 -0
- package/dist/types/utils/assertNever.d.ts +1 -0
- package/dist/types/utils/base64.d.ts +3 -0
- package/dist/types/utils/chatMessageToOpenAIChatCompletionMessage.d.ts +5 -0
- package/dist/types/utils/coerceType.d.ts +6 -0
- package/dist/types/utils/compatibility.d.ts +3 -0
- package/dist/types/utils/copyToClipboard.d.ts +1 -0
- package/dist/types/utils/defaults.d.ts +2 -0
- package/dist/types/utils/emitDetached.d.ts +11 -0
- package/dist/types/utils/errors.d.ts +2 -0
- package/dist/types/utils/expectType.d.ts +3 -0
- package/dist/types/utils/fetchEventSource.d.ts +12 -0
- package/dist/types/utils/genericUtilFunctions.d.ts +21 -0
- package/dist/types/utils/getPluginConfig.d.ts +2 -0
- package/dist/types/utils/handleEscapeCharacters.d.ts +2 -0
- package/dist/types/utils/index.d.ts +17 -0
- package/dist/types/utils/inputs.d.ts +3 -0
- package/dist/types/utils/interpolation.d.ts +26 -0
- package/dist/types/utils/misc.d.ts +1 -0
- package/dist/types/utils/newId.d.ts +1 -0
- package/dist/types/utils/openai.d.ts +784 -0
- package/dist/types/utils/orderedStringPortIds.d.ts +10 -0
- package/dist/types/utils/outputs.d.ts +3 -0
- package/dist/types/utils/pQueueCompat.d.ts +10 -0
- package/dist/types/utils/paths.d.ts +8 -0
- package/dist/types/utils/providerStreamParsing.d.ts +1 -0
- package/dist/types/utils/runtimeLogging.d.ts +10 -0
- package/dist/types/utils/serialization/serialization.d.ts +12 -0
- package/dist/types/utils/serialization/serializationHelpers.d.ts +27 -0
- package/dist/types/utils/serialization/serializationUtils.d.ts +16 -0
- package/dist/types/utils/serialization/serialization_v1.d.ts +3 -0
- package/dist/types/utils/serialization/serialization_v2.d.ts +3 -0
- package/dist/types/utils/serialization/serialization_v3.d.ts +19 -0
- package/dist/types/utils/serialization/serialization_v4.d.ts +9 -0
- package/dist/types/utils/symbols.d.ts +3 -0
- package/dist/types/utils/time.d.ts +22 -0
- package/dist/types/utils/typeSafety.d.ts +37 -0
- package/dist/types/vendor/fnv1a.d.ts +9 -0
- package/package.json +77 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function getCostForTokens(tokenCount, costPerThousand) {
|
|
2
|
+
return (tokenCount / 1000) * costPerThousand;
|
|
3
|
+
}
|
|
4
|
+
export function calculatePromptAndCompletionCost(inputTokenCount, outputTokenCount, costs) {
|
|
5
|
+
const promptCost = getCostForTokens(inputTokenCount, costs.prompt);
|
|
6
|
+
const completionCost = getCostForTokens(outputTokenCount, costs.completion);
|
|
7
|
+
return {
|
|
8
|
+
promptCost,
|
|
9
|
+
completionCost,
|
|
10
|
+
totalCost: promptCost + completionCost,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function calculateAudioUsageCost(usage, costs) {
|
|
14
|
+
const promptCost = getCostForTokens(usage.prompt_tokens_details.text_tokens, costs.prompt);
|
|
15
|
+
const completionCost = getCostForTokens(usage.completion_tokens_details.text_tokens, costs.completion);
|
|
16
|
+
const audioPromptCost = getCostForTokens(usage.prompt_tokens_details.audio_tokens, costs.audioPrompt ?? 0);
|
|
17
|
+
const audioCompletionCost = getCostForTokens(usage.completion_tokens_details.audio_tokens, costs.audioCompletion ?? 0);
|
|
18
|
+
return {
|
|
19
|
+
promptCost,
|
|
20
|
+
completionCost,
|
|
21
|
+
audioPromptCost,
|
|
22
|
+
audioCompletionCost,
|
|
23
|
+
totalCost: promptCost + completionCost + audioPromptCost + audioCompletionCost,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function getOutputTokensForCostCalculation(usage, fallbackTokenCount) {
|
|
27
|
+
if (!usage?.completion_tokens_details) {
|
|
28
|
+
return fallbackTokenCount;
|
|
29
|
+
}
|
|
30
|
+
return usage.completion_tokens_details.rejected_prediction_tokens > 0
|
|
31
|
+
? usage.completion_tokens_details.rejected_prediction_tokens
|
|
32
|
+
: usage.completion_tokens;
|
|
33
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { coerceType, coerceTypeOptional } from '../../utils/coerceType.js';
|
|
2
|
+
import { getScalarTypeOf, isArrayDataValue } from '../DataValue.js';
|
|
3
|
+
export function coercePromptToChatMessages(prompt, options = {}) {
|
|
4
|
+
if (!prompt) {
|
|
5
|
+
if (options.requirePrompt) {
|
|
6
|
+
throw new Error('Prompt is required');
|
|
7
|
+
}
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
const value = prompt;
|
|
11
|
+
if (value.type === 'chat-message') {
|
|
12
|
+
return [value.value];
|
|
13
|
+
}
|
|
14
|
+
if (value.type === 'chat-message[]') {
|
|
15
|
+
return [...value.value];
|
|
16
|
+
}
|
|
17
|
+
if (value.type === 'string') {
|
|
18
|
+
return [{ type: 'user', message: value.value }];
|
|
19
|
+
}
|
|
20
|
+
if (value.type === 'string[]') {
|
|
21
|
+
return value.value.map((entry) => ({ type: 'user', message: entry }));
|
|
22
|
+
}
|
|
23
|
+
if (isArrayDataValue(value)) {
|
|
24
|
+
const stringValues = value.value.map((entry) => coerceType({
|
|
25
|
+
type: getScalarTypeOf(value.type),
|
|
26
|
+
value: entry,
|
|
27
|
+
}, 'string'));
|
|
28
|
+
return stringValues.filter((entry) => entry != null).map((entry) => ({ type: 'user', message: entry }));
|
|
29
|
+
}
|
|
30
|
+
const coercedMessage = coerceTypeOptional(value, 'chat-message');
|
|
31
|
+
if (coercedMessage != null) {
|
|
32
|
+
return [coercedMessage];
|
|
33
|
+
}
|
|
34
|
+
const coercedString = coerceTypeOptional(value, 'string');
|
|
35
|
+
return coercedString != null ? [{ type: 'user', message: coerceType(value, 'string') }] : [];
|
|
36
|
+
}
|
|
37
|
+
export function prependSystemPrompt(messages, systemPrompt) {
|
|
38
|
+
if (!systemPrompt) {
|
|
39
|
+
return messages;
|
|
40
|
+
}
|
|
41
|
+
const systemMessage = coerceType(systemPrompt, 'string');
|
|
42
|
+
const nextMessages = [...messages];
|
|
43
|
+
if (nextMessages.length > 0 && nextMessages[0].type === 'system') {
|
|
44
|
+
nextMessages.splice(0, 1);
|
|
45
|
+
}
|
|
46
|
+
return [{ type: 'system', message: systemMessage }, ...nextMessages];
|
|
47
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { coerceType, coerceTypeOptional } from '../../utils/coerceType.js';
|
|
2
|
+
import { getInputOrData } from '../../utils/inputs.js';
|
|
3
|
+
export function resolveChatToolChoice(data, inputs) {
|
|
4
|
+
const toolChoiceMode = getInputOrData(data, inputs, 'toolChoice', 'string');
|
|
5
|
+
if (!toolChoiceMode || !data.enableFunctionUse) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
if (toolChoiceMode === 'function') {
|
|
9
|
+
return {
|
|
10
|
+
type: 'function',
|
|
11
|
+
function: {
|
|
12
|
+
name: getInputOrData(data, inputs, 'toolChoiceFunction', 'string'),
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return toolChoiceMode;
|
|
17
|
+
}
|
|
18
|
+
export function resolveChatResponseSchema(inputs) {
|
|
19
|
+
const responseSchemaInput = inputs['responseSchema'];
|
|
20
|
+
if (responseSchemaInput?.type === 'gpt-function') {
|
|
21
|
+
return responseSchemaInput.value.parameters;
|
|
22
|
+
}
|
|
23
|
+
if (responseSchemaInput != null) {
|
|
24
|
+
return coerceType(responseSchemaInput, 'object');
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
export function resolveOpenAIResponseFormat(data, inputs) {
|
|
29
|
+
const responseFormat = getInputOrData(data, inputs, 'responseFormat');
|
|
30
|
+
if (!responseFormat?.trim()) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
if (responseFormat === 'json') {
|
|
34
|
+
return { type: 'json_object' };
|
|
35
|
+
}
|
|
36
|
+
if (responseFormat === 'json_schema') {
|
|
37
|
+
return {
|
|
38
|
+
type: 'json_schema',
|
|
39
|
+
json_schema: {
|
|
40
|
+
name: getInputOrData(data, inputs, 'responseSchemaName', 'string') || 'response_schema',
|
|
41
|
+
strict: true,
|
|
42
|
+
schema: resolveChatResponseSchema(inputs) ?? {},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
type: 'text',
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export function resolveAdditionalHeaders(data, inputs) {
|
|
51
|
+
const headersFromData = (data.headers ?? []).reduce((acc, header) => {
|
|
52
|
+
acc[header.key] = header.value;
|
|
53
|
+
return acc;
|
|
54
|
+
}, {});
|
|
55
|
+
return data.useHeadersInput
|
|
56
|
+
? coerceTypeOptional(inputs['headers'], 'object') ?? headersFromData
|
|
57
|
+
: headersFromData;
|
|
58
|
+
}
|
|
59
|
+
export function resolveAdditionalParameters(data, inputs) {
|
|
60
|
+
const additionalParametersFromData = (data.additionalParameters ?? []).reduce((acc, param) => {
|
|
61
|
+
acc[param.key] = Number.isNaN(parseFloat(param.value)) ? param.value : parseFloat(param.value);
|
|
62
|
+
return acc;
|
|
63
|
+
}, {});
|
|
64
|
+
return data.useAdditionalParametersInput
|
|
65
|
+
? coerceTypeOptional(inputs['additionalParameters'], 'object') ??
|
|
66
|
+
additionalParametersFromData
|
|
67
|
+
: additionalParametersFromData;
|
|
68
|
+
}
|
|
69
|
+
export function resolveChatTools(inputs) {
|
|
70
|
+
const functions = coerceTypeOptional(inputs['functions'], 'gpt-function[]');
|
|
71
|
+
return (functions ?? []).map((fn) => ({
|
|
72
|
+
function: fn,
|
|
73
|
+
type: 'function',
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
export function resolvePredictionObject(data, inputs) {
|
|
77
|
+
const predictedOutput = data.usePredictedOutput
|
|
78
|
+
? coerceTypeOptional(inputs['predictedOutput'], 'string[]')
|
|
79
|
+
: undefined;
|
|
80
|
+
if (!predictedOutput) {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
return predictedOutput.length === 1
|
|
84
|
+
? { type: 'content', content: predictedOutput[0] }
|
|
85
|
+
: { type: 'content', content: predictedOutput.map((part) => ({ type: 'text', text: part })) };
|
|
86
|
+
}
|
|
87
|
+
export function resolveAudioAndModalities(data, inputs) {
|
|
88
|
+
const voice = getInputOrData(data, inputs, 'audioVoice');
|
|
89
|
+
let modalities = [];
|
|
90
|
+
if (data.modalitiesIncludeText) {
|
|
91
|
+
modalities.push('text');
|
|
92
|
+
}
|
|
93
|
+
if (data.modalitiesIncludeAudio) {
|
|
94
|
+
modalities.push('audio');
|
|
95
|
+
if (!voice) {
|
|
96
|
+
throw new Error('Audio voice must be specified if audio is enabled.');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (modalities.length === 0) {
|
|
100
|
+
modalities = undefined;
|
|
101
|
+
}
|
|
102
|
+
const audio = modalities?.includes('audio')
|
|
103
|
+
? {
|
|
104
|
+
voice,
|
|
105
|
+
format: getInputOrData(data, inputs, 'audioFormat') ??
|
|
106
|
+
'wav',
|
|
107
|
+
}
|
|
108
|
+
: undefined;
|
|
109
|
+
return { modalities, audio };
|
|
110
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { base64ToUint8Array } from '../../utils/base64.js';
|
|
2
|
+
import { getError } from '../../utils/errors.js';
|
|
3
|
+
import { calculateAudioUsageCost, calculatePromptAndCompletionCost, getOutputTokensForCostCalculation } from './chatCost.js';
|
|
4
|
+
import { applyStreamedFunctionCallOutputs, applyToolCallDeltas, createAssistantMessagesOutput } from './streamChatResponse.js';
|
|
5
|
+
import { setRequestAndResponseTokenOutputs } from './tokenBudget.js';
|
|
6
|
+
export async function applyOpenAINonStreamingResponse(params) {
|
|
7
|
+
const { response, output, messages, isMultiResponse, modalities, audioFormat, modelCosts, durationMs } = params;
|
|
8
|
+
if (isMultiResponse) {
|
|
9
|
+
output['response'] = {
|
|
10
|
+
type: 'string[]',
|
|
11
|
+
value: response.choices.map((choice) => choice.message.content ?? ''),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
output['response'] = {
|
|
16
|
+
type: 'string',
|
|
17
|
+
value: response.choices[0].message.content ?? '',
|
|
18
|
+
};
|
|
19
|
+
output['all-messages'] = {
|
|
20
|
+
type: 'chat-message[]',
|
|
21
|
+
value: [
|
|
22
|
+
...messages,
|
|
23
|
+
{
|
|
24
|
+
type: 'assistant',
|
|
25
|
+
message: response.choices[0].message.content ?? '',
|
|
26
|
+
function_calls: undefined,
|
|
27
|
+
isCacheBreakpoint: false,
|
|
28
|
+
function_call: undefined,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (modalities?.includes('audio')) {
|
|
34
|
+
const audioData = response.choices[0].message.audio;
|
|
35
|
+
output['audio'] = {
|
|
36
|
+
type: 'audio',
|
|
37
|
+
value: {
|
|
38
|
+
data: base64ToUint8Array(audioData.data),
|
|
39
|
+
mediaType: audioFormatToMediaType(audioFormat ?? 'wav'),
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
output['audioTranscript'] = {
|
|
43
|
+
type: 'string',
|
|
44
|
+
value: audioData.transcript,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
output['duration'] = { type: 'number', value: durationMs };
|
|
48
|
+
if (response.usage) {
|
|
49
|
+
output['usage'] = {
|
|
50
|
+
type: 'object',
|
|
51
|
+
value: response.usage,
|
|
52
|
+
};
|
|
53
|
+
const usageCosts = calculateAudioUsageCost(response.usage, {
|
|
54
|
+
prompt: modelCosts?.prompt ?? 0,
|
|
55
|
+
completion: modelCosts?.completion ?? 0,
|
|
56
|
+
audioPrompt: modelCosts?.audioPrompt ?? 0,
|
|
57
|
+
audioCompletion: modelCosts?.audioCompletion ?? 0,
|
|
58
|
+
});
|
|
59
|
+
output['cost'] = {
|
|
60
|
+
type: 'number',
|
|
61
|
+
value: usageCosts.totalCost,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export async function applyOpenAIStreamingResponse(params) {
|
|
66
|
+
const { chunks, output, messages, isMultiResponse, parallelFunctionCalling, context, tokenizer, tokenizerInfo, inputTokenCount: initialInputTokenCount, numberOfChoices, useServerTokenCalculation, modelCosts, } = params;
|
|
67
|
+
const responseChoicesParts = [];
|
|
68
|
+
const functionCalls = [];
|
|
69
|
+
let usage;
|
|
70
|
+
let throttleLastCalledTime = Date.now();
|
|
71
|
+
const onPartialOutput = (partialOutput) => {
|
|
72
|
+
const now = Date.now();
|
|
73
|
+
if (now - throttleLastCalledTime > (context.settings.throttleChatNode ?? 100)) {
|
|
74
|
+
context.onPartialOutputs?.(partialOutput);
|
|
75
|
+
throttleLastCalledTime = now;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
for await (const chunk of chunks) {
|
|
79
|
+
if (chunk.usage) {
|
|
80
|
+
usage = chunk.usage;
|
|
81
|
+
}
|
|
82
|
+
if (!chunk.choices) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
for (const { delta, index } of chunk.choices) {
|
|
86
|
+
if (delta.content != null) {
|
|
87
|
+
responseChoicesParts[index] ??= [];
|
|
88
|
+
responseChoicesParts[index].push(delta.content);
|
|
89
|
+
}
|
|
90
|
+
if (delta.tool_calls) {
|
|
91
|
+
functionCalls[index] ??= [];
|
|
92
|
+
applyToolCallDeltas(functionCalls, index, delta.tool_calls);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (isMultiResponse) {
|
|
96
|
+
output['response'] = {
|
|
97
|
+
type: 'string[]',
|
|
98
|
+
value: responseChoicesParts.map((parts) => parts.join('')),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
output['response'] = {
|
|
103
|
+
type: 'string',
|
|
104
|
+
value: responseChoicesParts[0]?.join('') ?? '',
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
applyStreamedFunctionCallOutputs(output, functionCalls, isMultiResponse, parallelFunctionCalling);
|
|
108
|
+
onPartialOutput(output);
|
|
109
|
+
}
|
|
110
|
+
context.onPartialOutputs?.(output);
|
|
111
|
+
if (!isMultiResponse) {
|
|
112
|
+
output['all-messages'] = createAssistantMessagesOutput(messages, responseChoicesParts[0]?.join('') ?? '', functionCalls[0]);
|
|
113
|
+
}
|
|
114
|
+
if (responseChoicesParts.length === 0 && functionCalls.length === 0) {
|
|
115
|
+
throw new Error('No response from OpenAI');
|
|
116
|
+
}
|
|
117
|
+
let inputTokenCount = initialInputTokenCount;
|
|
118
|
+
let outputTokenCount = 0;
|
|
119
|
+
if (usage) {
|
|
120
|
+
inputTokenCount = usage.prompt_tokens;
|
|
121
|
+
outputTokenCount = usage.completion_tokens;
|
|
122
|
+
}
|
|
123
|
+
output['in-messages'] = { type: 'chat-message[]', value: messages };
|
|
124
|
+
setRequestAndResponseTokenOutputs(output, inputTokenCount * (numberOfChoices ?? 1), outputTokenCount);
|
|
125
|
+
if (!useServerTokenCalculation) {
|
|
126
|
+
let responseTokenCount = 0;
|
|
127
|
+
for (const choiceParts of responseChoicesParts) {
|
|
128
|
+
responseTokenCount += await tokenizer.getTokenCountForString(choiceParts.join(), tokenizerInfo);
|
|
129
|
+
}
|
|
130
|
+
outputTokenCount = responseTokenCount;
|
|
131
|
+
setRequestAndResponseTokenOutputs(output, inputTokenCount * (numberOfChoices ?? 1), outputTokenCount);
|
|
132
|
+
}
|
|
133
|
+
const outputTokensForCostCalculation = getOutputTokensForCostCalculation(usage, outputTokenCount);
|
|
134
|
+
const { promptCost, completionCost, totalCost } = calculatePromptAndCompletionCost(inputTokenCount, outputTokensForCostCalculation, modelCosts);
|
|
135
|
+
if (usage) {
|
|
136
|
+
output['usage'] = {
|
|
137
|
+
type: 'object',
|
|
138
|
+
value: {
|
|
139
|
+
...usage,
|
|
140
|
+
prompt_cost: promptCost,
|
|
141
|
+
completion_cost: completionCost,
|
|
142
|
+
total_cost: totalCost,
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
output['usage'] = {
|
|
148
|
+
type: 'object',
|
|
149
|
+
value: {
|
|
150
|
+
prompt_tokens: inputTokenCount,
|
|
151
|
+
completion_tokens: outputTokenCount,
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
output['cost'] = { type: 'number', value: totalCost };
|
|
156
|
+
output['__hidden_token_count'] = { type: 'number', value: inputTokenCount + outputTokenCount };
|
|
157
|
+
}
|
|
158
|
+
export function handleOpenAIRetryableFailure(params) {
|
|
159
|
+
const { originalError, context } = params;
|
|
160
|
+
let err = originalError;
|
|
161
|
+
if (String(originalError).includes('fetch failed') && originalError && typeof originalError === 'object' && 'cause' in originalError) {
|
|
162
|
+
const originalCause = originalError.cause;
|
|
163
|
+
const cause = getError(originalCause) instanceof AggregateError
|
|
164
|
+
? originalCause.errors[0]
|
|
165
|
+
: getError(originalCause);
|
|
166
|
+
err = cause;
|
|
167
|
+
}
|
|
168
|
+
if (context.signal.aborted) {
|
|
169
|
+
throw new Error('Aborted');
|
|
170
|
+
}
|
|
171
|
+
context.trace(`ChatNode failed, retrying: ${String(err)}`);
|
|
172
|
+
const retriesLeft = err && typeof err === 'object' && 'retriesLeft' in err ? err.retriesLeft : undefined;
|
|
173
|
+
if (String(err).includes('terminated') ||
|
|
174
|
+
String(originalError).includes('terminated') ||
|
|
175
|
+
String(err).includes('fetch failed')) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (!(err instanceof Error) || !('status' in err)) {
|
|
179
|
+
if (err && typeof err === 'object' && 'code' in err) {
|
|
180
|
+
throw err;
|
|
181
|
+
}
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const openAIError = err;
|
|
185
|
+
if (openAIError.status === 429 && retriesLeft) {
|
|
186
|
+
context.onPartialOutputs?.({
|
|
187
|
+
['response']: {
|
|
188
|
+
type: 'string',
|
|
189
|
+
value: 'OpenAI API rate limit exceeded, retrying...',
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (openAIError.status === 408 && retriesLeft) {
|
|
195
|
+
context.onPartialOutputs?.({
|
|
196
|
+
['response']: {
|
|
197
|
+
type: 'string',
|
|
198
|
+
value: 'OpenAI API timed out, retrying...',
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (openAIError.status >= 400 && openAIError.status < 500) {
|
|
204
|
+
throw new Error(openAIError.message);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function audioFormatToMediaType(format) {
|
|
208
|
+
switch (format) {
|
|
209
|
+
case 'wav':
|
|
210
|
+
return 'audio/wav';
|
|
211
|
+
case 'mp3':
|
|
212
|
+
return 'audio/mpeg';
|
|
213
|
+
case 'flac':
|
|
214
|
+
return 'audio/flac';
|
|
215
|
+
case 'opus':
|
|
216
|
+
return 'audio/opus';
|
|
217
|
+
case 'pcm16':
|
|
218
|
+
return 'audio/wav';
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export function applyToolCallDeltas(functionCalls, choiceIndex, toolCalls) {
|
|
2
|
+
functionCalls[choiceIndex] ??= [];
|
|
3
|
+
for (const toolCall of toolCalls) {
|
|
4
|
+
functionCalls[choiceIndex][toolCall.index] ??= {
|
|
5
|
+
type: 'function',
|
|
6
|
+
arguments: '',
|
|
7
|
+
lastParsedArguments: undefined,
|
|
8
|
+
name: '',
|
|
9
|
+
id: '',
|
|
10
|
+
};
|
|
11
|
+
const currentCall = functionCalls[choiceIndex][toolCall.index];
|
|
12
|
+
if (toolCall.id) {
|
|
13
|
+
currentCall.id = toolCall.id;
|
|
14
|
+
}
|
|
15
|
+
if (toolCall.function.name) {
|
|
16
|
+
currentCall.name += toolCall.function.name;
|
|
17
|
+
}
|
|
18
|
+
if (toolCall.function.arguments) {
|
|
19
|
+
currentCall.arguments += toolCall.function.arguments;
|
|
20
|
+
try {
|
|
21
|
+
currentCall.lastParsedArguments = JSON.parse(currentCall.arguments);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// Ignore partial JSON fragments until the stream completes.
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function applyStreamedFunctionCallOutputs(output, functionCalls, isMultiResponse, parallelFunctionCalling) {
|
|
30
|
+
if (functionCalls.length === 0) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (isMultiResponse) {
|
|
34
|
+
output['function-call'] = {
|
|
35
|
+
type: 'object[]',
|
|
36
|
+
value: functionCalls.map((calls) => ({
|
|
37
|
+
name: calls[0]?.name,
|
|
38
|
+
arguments: calls[0]?.lastParsedArguments,
|
|
39
|
+
id: calls[0]?.id,
|
|
40
|
+
})),
|
|
41
|
+
};
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (parallelFunctionCalling) {
|
|
45
|
+
output['function-calls'] = {
|
|
46
|
+
type: 'object[]',
|
|
47
|
+
value: functionCalls[0].map((functionCall) => ({
|
|
48
|
+
name: functionCall.name,
|
|
49
|
+
arguments: functionCall.lastParsedArguments,
|
|
50
|
+
id: functionCall.id,
|
|
51
|
+
})),
|
|
52
|
+
};
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
output['function-call'] = {
|
|
56
|
+
type: 'object',
|
|
57
|
+
value: {
|
|
58
|
+
name: functionCalls[0][0]?.name,
|
|
59
|
+
arguments: functionCalls[0][0]?.lastParsedArguments,
|
|
60
|
+
id: functionCalls[0][0]?.id,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export function createAssistantMessagesOutput(messages, response, functionCalls, options = {}) {
|
|
65
|
+
const functionCallMode = options.functionCallMode ?? 'first';
|
|
66
|
+
const singleFunctionCall = functionCallMode === 'never'
|
|
67
|
+
? undefined
|
|
68
|
+
: functionCallMode === 'only'
|
|
69
|
+
? functionCalls?.length === 1
|
|
70
|
+
? functionCalls[0]
|
|
71
|
+
: undefined
|
|
72
|
+
: functionCalls?.[0];
|
|
73
|
+
return {
|
|
74
|
+
type: 'chat-message[]',
|
|
75
|
+
value: [
|
|
76
|
+
...messages,
|
|
77
|
+
{
|
|
78
|
+
type: 'assistant',
|
|
79
|
+
message: response,
|
|
80
|
+
function_call: singleFunctionCall
|
|
81
|
+
? {
|
|
82
|
+
name: singleFunctionCall.name,
|
|
83
|
+
arguments: singleFunctionCall.arguments,
|
|
84
|
+
id: singleFunctionCall.id,
|
|
85
|
+
}
|
|
86
|
+
: undefined,
|
|
87
|
+
function_calls: functionCalls && functionCalls.length > 0
|
|
88
|
+
? functionCalls.map((fc) => ({
|
|
89
|
+
name: fc.name,
|
|
90
|
+
arguments: fc.arguments,
|
|
91
|
+
id: fc.id,
|
|
92
|
+
}))
|
|
93
|
+
: undefined,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { addWarning } from '../../utils/outputs.js';
|
|
2
|
+
export function clampMaxTokensToModelLimit(output, model, inputTokenCount, maxTokens, modelMaxTokens) {
|
|
3
|
+
if (inputTokenCount >= modelMaxTokens) {
|
|
4
|
+
throw new Error(`The model ${model} can only handle ${modelMaxTokens} tokens, but ${inputTokenCount} were provided in the prompts alone.`);
|
|
5
|
+
}
|
|
6
|
+
if (inputTokenCount + maxTokens <= modelMaxTokens) {
|
|
7
|
+
return maxTokens;
|
|
8
|
+
}
|
|
9
|
+
const message = `The model can only handle a maximum of ${modelMaxTokens} tokens, but the prompts and max tokens together exceed this limit. The max tokens has been reduced to ${modelMaxTokens - inputTokenCount}.`;
|
|
10
|
+
addWarning(output, message);
|
|
11
|
+
return Math.floor((modelMaxTokens - inputTokenCount) * 0.95);
|
|
12
|
+
}
|
|
13
|
+
export function setRequestAndResponseTokenOutputs(output, requestTokens, responseTokens) {
|
|
14
|
+
output['requestTokens'] = { type: 'number', value: requestTokens };
|
|
15
|
+
output['responseTokens'] = { type: 'number', value: responseTokens };
|
|
16
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { streamText } from 'ai';
|
|
2
|
+
import { consumeAiSdkStream } from '../chat/aiSdkStreaming.js';
|
|
3
|
+
function keepPromiseHandled(value) {
|
|
4
|
+
const promise = Promise.resolve(value);
|
|
5
|
+
void promise.catch(() => undefined);
|
|
6
|
+
return promise;
|
|
7
|
+
}
|
|
8
|
+
function isPromiseLike(value) {
|
|
9
|
+
return (value != null &&
|
|
10
|
+
(typeof value === 'object' || typeof value === 'function') &&
|
|
11
|
+
typeof value.then === 'function');
|
|
12
|
+
}
|
|
13
|
+
function markOptionalPromiseHandled(value) {
|
|
14
|
+
if (isPromiseLike(value)) {
|
|
15
|
+
void keepPromiseHandled(value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function defaultStreamExecutor(args) {
|
|
19
|
+
const result = streamText(args);
|
|
20
|
+
return {
|
|
21
|
+
fullStream: result.fullStream,
|
|
22
|
+
finishReason: 'finishReason' in result
|
|
23
|
+
? keepPromiseHandled(Promise.resolve(result.finishReason).then((value) => (value == null ? undefined : String(value))))
|
|
24
|
+
: undefined,
|
|
25
|
+
providerMetadata: 'providerMetadata' in result
|
|
26
|
+
? keepPromiseHandled(Promise.resolve(result.providerMetadata))
|
|
27
|
+
: undefined,
|
|
28
|
+
requestStatus: 200,
|
|
29
|
+
usage: 'usage' in result
|
|
30
|
+
? keepPromiseHandled(Promise.resolve(result.usage))
|
|
31
|
+
: undefined,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async function resolveOptionalValue(value) {
|
|
35
|
+
return value == null ? undefined : await value;
|
|
36
|
+
}
|
|
37
|
+
async function executeStream(options, executor) {
|
|
38
|
+
const args = {
|
|
39
|
+
model: options.model,
|
|
40
|
+
messages: options.messages,
|
|
41
|
+
};
|
|
42
|
+
if (options.tools !== undefined)
|
|
43
|
+
args.tools = options.tools;
|
|
44
|
+
if (options.maxTokens !== undefined)
|
|
45
|
+
args.maxOutputTokens = options.maxTokens;
|
|
46
|
+
if (options.temperature !== undefined)
|
|
47
|
+
args.temperature = options.temperature;
|
|
48
|
+
if (options.topP !== undefined)
|
|
49
|
+
args.topP = options.topP;
|
|
50
|
+
if (options.topK !== undefined)
|
|
51
|
+
args.topK = options.topK;
|
|
52
|
+
if (options.presencePenalty !== undefined)
|
|
53
|
+
args.presencePenalty = options.presencePenalty;
|
|
54
|
+
if (options.frequencyPenalty !== undefined)
|
|
55
|
+
args.frequencyPenalty = options.frequencyPenalty;
|
|
56
|
+
if (options.stopSequences !== undefined)
|
|
57
|
+
args.stopSequences = options.stopSequences;
|
|
58
|
+
if (options.seed !== undefined)
|
|
59
|
+
args.seed = options.seed;
|
|
60
|
+
if (options.responseOutput !== undefined)
|
|
61
|
+
args.output = options.responseOutput;
|
|
62
|
+
if (options.providerOptions !== undefined)
|
|
63
|
+
args.providerOptions = options.providerOptions;
|
|
64
|
+
if (options.toolChoice !== undefined)
|
|
65
|
+
args.toolChoice = options.toolChoice;
|
|
66
|
+
if (options.abortSignal !== undefined)
|
|
67
|
+
args.abortSignal = options.abortSignal;
|
|
68
|
+
const handle = await executor(args);
|
|
69
|
+
markOptionalPromiseHandled(handle.finishReason);
|
|
70
|
+
markOptionalPromiseHandled(handle.providerMetadata);
|
|
71
|
+
markOptionalPromiseHandled(handle.requestStatus);
|
|
72
|
+
markOptionalPromiseHandled(handle.usage);
|
|
73
|
+
const streamed = await consumeAiSdkStream(handle.fullStream, (text, functionCalls) => {
|
|
74
|
+
options.onPartialOutput?.({ text, functionCalls });
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
responseText: streamed.responseText,
|
|
78
|
+
functionCalls: streamed.functionCalls,
|
|
79
|
+
usage: streamed.usage ?? (await resolveOptionalValue(handle.usage)),
|
|
80
|
+
reasoning: streamed.reasoning,
|
|
81
|
+
finishReason: await resolveOptionalValue(handle.finishReason),
|
|
82
|
+
providerMetadata: await resolveOptionalValue(handle.providerMetadata),
|
|
83
|
+
requestStatus: await resolveOptionalValue(handle.requestStatus),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export async function streamChatV2(options) {
|
|
87
|
+
return executeStream(options, options.executeStream ?? defaultStreamExecutor);
|
|
88
|
+
}
|