@alpic80/rivet-core 1.19.1-aidon.1
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 +176 -0
- package/dist/cjs/bundle.cjs +18915 -0
- package/dist/cjs/bundle.cjs.map +7 -0
- package/dist/esm/api/createProcessor.js +131 -0
- package/dist/esm/api/streaming.js +116 -0
- package/dist/esm/exports.js +32 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/integrations/AudioProvider.js +1 -0
- package/dist/esm/integrations/DatasetProvider.js +92 -0
- package/dist/esm/integrations/EmbeddingGenerator.js +1 -0
- package/dist/esm/integrations/GptTokenizerTokenizer.js +65 -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/openai/OpenAIEmbeddingGenerator.js +23 -0
- package/dist/esm/model/DataValue.js +176 -0
- package/dist/esm/model/Dataset.js +1 -0
- package/dist/esm/model/EditorDefinition.js +1 -0
- package/dist/esm/model/GraphProcessor.js +1198 -0
- package/dist/esm/model/NodeBase.js +1 -0
- package/dist/esm/model/NodeBodySpec.js +1 -0
- package/dist/esm/model/NodeDefinition.js +12 -0
- package/dist/esm/model/NodeGraph.js +14 -0
- package/dist/esm/model/NodeImpl.js +49 -0
- package/dist/esm/model/NodeRegistration.js +144 -0
- package/dist/esm/model/Nodes.js +227 -0
- package/dist/esm/model/PluginLoadSpec.js +1 -0
- package/dist/esm/model/ProcessContext.js +1 -0
- package/dist/esm/model/Project.js +2 -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/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 +199 -0
- package/dist/esm/model/nodes/AssemblePromptNode.js +129 -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 +136 -0
- package/dist/esm/model/nodes/ChatNode.js +964 -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 +136 -0
- package/dist/esm/model/nodes/CommentNode.js +69 -0
- package/dist/esm/model/nodes/CompareNode.js +138 -0
- package/dist/esm/model/nodes/ContextNode.js +99 -0
- package/dist/esm/model/nodes/CreateDatasetNode.js +71 -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 +136 -0
- package/dist/esm/model/nodes/DestructureNode.js +86 -0
- package/dist/esm/model/nodes/EvaluateNode.js +141 -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 +128 -0
- package/dist/esm/model/nodes/ExtractRegexNode.js +201 -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/GptFunctionNode.js +169 -0
- package/dist/esm/model/nodes/GraphInputNode.js +130 -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 +257 -0
- package/dist/esm/model/nodes/IfElseNode.js +138 -0
- package/dist/esm/model/nodes/IfNode.js +124 -0
- package/dist/esm/model/nodes/ImageNode.js +107 -0
- package/dist/esm/model/nodes/JoinNode.js +135 -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/MatchNode.js +137 -0
- package/dist/esm/model/nodes/NumberNode.js +86 -0
- package/dist/esm/model/nodes/ObjectNode.js +121 -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 +227 -0
- package/dist/esm/model/nodes/RaceInputsNode.js +86 -0
- package/dist/esm/model/nodes/RaiseEventNode.js +84 -0
- package/dist/esm/model/nodes/RandomNumberNode.js +106 -0
- package/dist/esm/model/nodes/ReadDirectoryNode.js +165 -0
- package/dist/esm/model/nodes/ReadFileNode.js +114 -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 +100 -0
- package/dist/esm/model/nodes/SplitNode.js +101 -0
- package/dist/esm/model/nodes/SubGraphNode.js +181 -0
- package/dist/esm/model/nodes/TextNode.js +97 -0
- package/dist/esm/model/nodes/ToJsonNode.js +78 -0
- package/dist/esm/model/nodes/ToYamlNode.js +68 -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 +111 -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/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/aidon/index.js +2 -0
- package/dist/esm/plugins/aidon/nodes/ChatAidonNode.js +215 -0
- package/dist/esm/plugins/aidon/plugin.js +9 -0
- package/dist/esm/plugins/anthropic/anthropic.js +187 -0
- package/dist/esm/plugins/anthropic/fetchEventSource.js +106 -0
- package/dist/esm/plugins/anthropic/index.js +2 -0
- package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +652 -0
- package/dist/esm/plugins/anthropic/plugin.js +18 -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 +125 -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 +2 -0
- package/dist/esm/plugins/gentrace/plugin.js +192 -0
- package/dist/esm/plugins/google/google.js +60 -0
- package/dist/esm/plugins/google/index.js +2 -0
- package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +364 -0
- package/dist/esm/plugins/google/plugin.js +32 -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 +145 -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 +21 -0
- package/dist/esm/recording/ExecutionRecorder.js +177 -0
- package/dist/esm/recording/RecordedEvents.js +1 -0
- package/dist/esm/utils/assertNever.js +3 -0
- package/dist/esm/utils/base64.js +25 -0
- package/dist/esm/utils/chatMessageToOpenAIChatCompletionMessage.js +60 -0
- package/dist/esm/utils/coerceType.js +322 -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/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 +14 -0
- package/dist/esm/utils/inputs.js +16 -0
- package/dist/esm/utils/interpolation.js +6 -0
- package/dist/esm/utils/misc.js +1 -0
- package/dist/esm/utils/newId.js +4 -0
- package/dist/esm/utils/openai.js +219 -0
- package/dist/esm/utils/outputs.js +14 -0
- package/dist/esm/utils/serialization/serialization.js +86 -0
- package/dist/esm/utils/serialization/serializationUtils.js +13 -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 +145 -0
- package/dist/esm/utils/serialization/serialization_v4.js +200 -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/types/api/createProcessor.d.ts +37 -0
- package/dist/types/api/streaming.d.ts +56 -0
- package/dist/types/exports.d.ts +33 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/integrations/AudioProvider.d.ts +4 -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/openai/OpenAIEmbeddingGenerator.d.ts +10 -0
- package/dist/types/model/DataValue.d.ts +138 -0
- package/dist/types/model/Dataset.d.ts +19 -0
- package/dist/types/model/EditorDefinition.d.ts +142 -0
- package/dist/types/model/GraphProcessor.d.ts +192 -0
- package/dist/types/model/NodeBase.d.ts +110 -0
- package/dist/types/model/NodeBodySpec.d.ts +19 -0
- package/dist/types/model/NodeDefinition.d.ts +13 -0
- package/dist/types/model/NodeGraph.d.ts +15 -0
- package/dist/types/model/NodeImpl.d.ts +55 -0
- package/dist/types/model/NodeRegistration.d.ts +24 -0
- package/dist/types/model/Nodes.d.ts +84 -0
- package/dist/types/model/PluginLoadSpec.d.ts +17 -0
- package/dist/types/model/ProcessContext.d.ts +69 -0
- package/dist/types/model/Project.d.ts +17 -0
- package/dist/types/model/RivetPlugin.d.ts +45 -0
- package/dist/types/model/RivetUIContext.d.ts +18 -0
- package/dist/types/model/Settings.d.ts +15 -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 +20 -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/ChatNode.d.ts +77 -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 +21 -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/DatasetNearestNeigborsNode.d.ts +19 -0
- package/dist/types/model/nodes/DelayNode.d.ts +20 -0
- package/dist/types/model/nodes/DelegateFunctionCallNode.d.ts +25 -0
- package/dist/types/model/nodes/DestructureNode.d.ts +18 -0
- package/dist/types/model/nodes/EvaluateNode.d.ts +19 -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 +19 -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/GptFunctionNode.d.ts +25 -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 +27 -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/JoinNode.d.ts +21 -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/MatchNode.d.ts +19 -0
- package/dist/types/model/nodes/NumberNode.d.ts +21 -0
- package/dist/types/model/nodes/ObjectNode.d.ts +18 -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 +23 -0
- package/dist/types/model/nodes/RaceInputsNode.d.ts +17 -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/ReadDirectoryNode.d.ts +30 -0
- package/dist/types/model/nodes/ReadFileNode.d.ts +23 -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 +18 -0
- package/dist/types/model/nodes/ToJsonNode.d.ts +18 -0
- package/dist/types/model/nodes/ToYamlNode.d.ts +13 -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 +21 -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/native/BaseDir.d.ts +29 -0
- package/dist/types/native/BrowserNativeApi.d.ts +11 -0
- package/dist/types/native/NativeApi.d.ts +17 -0
- package/dist/types/plugins/aidon/index.d.ts +2 -0
- package/dist/types/plugins/aidon/nodes/ChatAidonNode.d.ts +3 -0
- package/dist/types/plugins/aidon/plugin.d.ts +2 -0
- package/dist/types/plugins/anthropic/anthropic.d.ts +216 -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 +30 -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 +5 -0
- package/dist/types/plugins/google/google.d.ts +60 -0
- package/dist/types/plugins/google/index.d.ts +2 -0
- package/dist/types/plugins/google/nodes/ChatGoogleNode.d.ts +27 -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 +20 -0
- package/dist/types/recording/ExecutionRecorder.d.ts +25 -0
- package/dist/types/recording/RecordedEvents.d.ts +100 -0
- package/dist/types/utils/assertNever.d.ts +1 -0
- package/dist/types/utils/base64.d.ts +2 -0
- package/dist/types/utils/chatMessageToOpenAIChatCompletionMessage.d.ts +3 -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/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 +14 -0
- package/dist/types/utils/inputs.d.ts +3 -0
- package/dist/types/utils/interpolation.d.ts +1 -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 +739 -0
- package/dist/types/utils/outputs.d.ts +3 -0
- package/dist/types/utils/serialization/serialization.d.ts +12 -0
- package/dist/types/utils/serialization/serializationUtils.d.ts +6 -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/package.json +97 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { match } from 'ts-pattern';
|
|
2
|
+
import { uint8ArrayToBase64 } from './index.js';
|
|
3
|
+
export async function chatMessageToOpenAIChatCompletionMessage(message) {
|
|
4
|
+
const onlyStringContent = (message) => {
|
|
5
|
+
const parts = Array.isArray(message.message) ? message.message : [message.message];
|
|
6
|
+
const stringContent = parts
|
|
7
|
+
.map((part) => {
|
|
8
|
+
if (typeof part !== 'string') {
|
|
9
|
+
throw new Error('System prompt must be a string');
|
|
10
|
+
}
|
|
11
|
+
return part;
|
|
12
|
+
})
|
|
13
|
+
.join('\n\n');
|
|
14
|
+
return stringContent;
|
|
15
|
+
};
|
|
16
|
+
return match(message)
|
|
17
|
+
.with({ type: 'system' }, (m) => ({ role: m.type, content: onlyStringContent(m) }))
|
|
18
|
+
.with({ type: 'user' }, async (m) => {
|
|
19
|
+
const parts = Array.isArray(m.message) ? m.message : [m.message];
|
|
20
|
+
if (parts.length === 1 && typeof parts[0] === 'string') {
|
|
21
|
+
return { role: m.type, content: parts[0] };
|
|
22
|
+
}
|
|
23
|
+
const chatMessageParts = await Promise.all(parts.map(async (part) => {
|
|
24
|
+
if (typeof part === 'string') {
|
|
25
|
+
return { type: 'text', text: part };
|
|
26
|
+
}
|
|
27
|
+
const url = part.type === 'url' ? part.url : `data:${part.mediaType};base64,${await uint8ArrayToBase64(part.data)}`;
|
|
28
|
+
return {
|
|
29
|
+
type: 'image_url',
|
|
30
|
+
image_url: { url },
|
|
31
|
+
};
|
|
32
|
+
}));
|
|
33
|
+
return { role: m.type, content: chatMessageParts };
|
|
34
|
+
})
|
|
35
|
+
.with({ type: 'assistant' }, (m) => ({
|
|
36
|
+
role: m.type,
|
|
37
|
+
content: onlyStringContent(m),
|
|
38
|
+
tool_calls: m.function_calls
|
|
39
|
+
? m.function_calls.map((fc) => ({
|
|
40
|
+
id: fc.id ?? 'unknown_function_call',
|
|
41
|
+
type: 'function',
|
|
42
|
+
function: fc,
|
|
43
|
+
}))
|
|
44
|
+
: m.function_call
|
|
45
|
+
? [
|
|
46
|
+
{
|
|
47
|
+
id: m.function_call.id ?? 'unknown_function_call',
|
|
48
|
+
type: 'function',
|
|
49
|
+
function: m.function_call,
|
|
50
|
+
},
|
|
51
|
+
]
|
|
52
|
+
: undefined,
|
|
53
|
+
}))
|
|
54
|
+
.with({ type: 'function' }, (m) => ({
|
|
55
|
+
role: 'tool',
|
|
56
|
+
content: onlyStringContent(m),
|
|
57
|
+
tool_call_id: m.name ?? 'unknown_function_call',
|
|
58
|
+
}))
|
|
59
|
+
.exhaustive();
|
|
60
|
+
}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { match } from 'ts-pattern';
|
|
2
|
+
import { getScalarTypeOf, isArrayDataType, isArrayDataValue, unwrapDataValue, } from '../model/DataValue.js';
|
|
3
|
+
import { expectTypeOptional } from './expectType.js';
|
|
4
|
+
export function coerceTypeOptional(wrapped, type) {
|
|
5
|
+
const value = wrapped ? unwrapDataValue(wrapped) : undefined;
|
|
6
|
+
// Coerce 'true' to [true] for example
|
|
7
|
+
if (isArrayDataType(type) && !isArrayDataValue(value)) {
|
|
8
|
+
const coerced = coerceTypeOptional(value, getScalarTypeOf(type));
|
|
9
|
+
if (coerced === undefined) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
return [coerced];
|
|
13
|
+
}
|
|
14
|
+
// Coerce foo[] to bar[]
|
|
15
|
+
if (isArrayDataType(type) && isArrayDataValue(value) && getScalarTypeOf(type) !== getScalarTypeOf(value.type)) {
|
|
16
|
+
return value.value.map((v) => coerceTypeOptional({ type: getScalarTypeOf(value.type), value: v }, getScalarTypeOf(type)));
|
|
17
|
+
}
|
|
18
|
+
const result = match(type)
|
|
19
|
+
.with('string', () => coerceToString(value))
|
|
20
|
+
.with('boolean', () => coerceToBoolean(value))
|
|
21
|
+
.with('chat-message', () => coerceToChatMessage(value))
|
|
22
|
+
.with('number', () => coerceToNumber(value))
|
|
23
|
+
.with('object', () => coerceToObject(value))
|
|
24
|
+
.with('binary', () => coerceToBinary(value))
|
|
25
|
+
.with('graph-reference', () => coerceToGraphReference(value))
|
|
26
|
+
.otherwise(() => {
|
|
27
|
+
if (!value) {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
if (getScalarTypeOf(value.type) === 'any' || getScalarTypeOf(type) === 'any') {
|
|
31
|
+
return value.value;
|
|
32
|
+
}
|
|
33
|
+
return expectTypeOptional(value, type);
|
|
34
|
+
});
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
export function coerceType(value, type) {
|
|
38
|
+
const result = coerceTypeOptional(value, type);
|
|
39
|
+
if (result === undefined) {
|
|
40
|
+
throw new Error(`Expected value of type ${type} but got undefined`);
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
export function inferType(value) {
|
|
45
|
+
if (value === undefined) {
|
|
46
|
+
return { type: 'any', value: undefined };
|
|
47
|
+
}
|
|
48
|
+
if (value === null) {
|
|
49
|
+
return { type: 'any', value: null };
|
|
50
|
+
}
|
|
51
|
+
if (typeof value === 'function') {
|
|
52
|
+
return { type: 'fn<any>', value: value };
|
|
53
|
+
}
|
|
54
|
+
if (typeof value === 'string') {
|
|
55
|
+
return { type: 'string', value };
|
|
56
|
+
}
|
|
57
|
+
if (typeof value === 'boolean') {
|
|
58
|
+
return { type: 'boolean', value };
|
|
59
|
+
}
|
|
60
|
+
if (typeof value === 'number') {
|
|
61
|
+
return { type: 'number', value };
|
|
62
|
+
}
|
|
63
|
+
if (value instanceof Date) {
|
|
64
|
+
return { type: 'datetime', value: value.toISOString() };
|
|
65
|
+
}
|
|
66
|
+
if (Array.isArray(value)) {
|
|
67
|
+
if (value.length === 0) {
|
|
68
|
+
return { type: 'any[]', value: [] };
|
|
69
|
+
}
|
|
70
|
+
const inferredType = inferType(value[0]);
|
|
71
|
+
return { type: inferredType.type + '[]', value };
|
|
72
|
+
}
|
|
73
|
+
if (typeof value === 'object') {
|
|
74
|
+
return { type: 'object', value: value };
|
|
75
|
+
}
|
|
76
|
+
throw new Error(`Cannot infer type of value: ${value}`);
|
|
77
|
+
}
|
|
78
|
+
function coerceToString(value) {
|
|
79
|
+
if (!value) {
|
|
80
|
+
return '';
|
|
81
|
+
}
|
|
82
|
+
if (isArrayDataValue(value)) {
|
|
83
|
+
return value.value
|
|
84
|
+
.map((v) => coerceTypeOptional({ type: getScalarTypeOf(value.type), value: v }, 'string'))
|
|
85
|
+
.join('\n');
|
|
86
|
+
}
|
|
87
|
+
if (value.type === 'string') {
|
|
88
|
+
return value.value;
|
|
89
|
+
}
|
|
90
|
+
if (value.type === 'boolean') {
|
|
91
|
+
return value.value.toString();
|
|
92
|
+
}
|
|
93
|
+
if (value.type === 'number') {
|
|
94
|
+
return value.value.toString();
|
|
95
|
+
}
|
|
96
|
+
if (value.type === 'date') {
|
|
97
|
+
return value.value;
|
|
98
|
+
}
|
|
99
|
+
if (value.type === 'time') {
|
|
100
|
+
return value.value;
|
|
101
|
+
}
|
|
102
|
+
if (value.type === 'datetime') {
|
|
103
|
+
return value.value;
|
|
104
|
+
}
|
|
105
|
+
if (value.type === 'chat-message') {
|
|
106
|
+
const messageParts = Array.isArray(value.value.message) ? value.value.message : [value.value.message];
|
|
107
|
+
const singleString = messageParts
|
|
108
|
+
.map((part) => {
|
|
109
|
+
if (typeof part === 'string') {
|
|
110
|
+
return part;
|
|
111
|
+
}
|
|
112
|
+
return part.type === 'url' ? `(Image: ${part.url})` : '(Image)';
|
|
113
|
+
})
|
|
114
|
+
.join('\n\n');
|
|
115
|
+
return singleString;
|
|
116
|
+
}
|
|
117
|
+
if (value.value === undefined) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
if (value.value === null) {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
if (typeof value.value === 'object' && !Array.isArray(value.value)) {
|
|
124
|
+
return JSON.stringify(value.value);
|
|
125
|
+
}
|
|
126
|
+
// Don't know, so try to infer it from the type of the value
|
|
127
|
+
// Any and object are basically the same...
|
|
128
|
+
if (value.type === 'any' || value.type === 'object') {
|
|
129
|
+
const inferred = inferType(value.value);
|
|
130
|
+
return coerceTypeOptional(inferred, 'string');
|
|
131
|
+
}
|
|
132
|
+
return JSON.stringify(value.value);
|
|
133
|
+
}
|
|
134
|
+
function coerceToChatMessage(value) {
|
|
135
|
+
const chatMessage = coerceToChatMessageRaw(value);
|
|
136
|
+
if (chatMessage?.type === 'assistant') {
|
|
137
|
+
// Double check that arguments is a string, stringify if needed
|
|
138
|
+
if (chatMessage.function_call?.arguments && typeof chatMessage.function_call.arguments !== 'string') {
|
|
139
|
+
chatMessage.function_call.arguments = JSON.stringify(chatMessage.function_call.arguments);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return chatMessage;
|
|
143
|
+
}
|
|
144
|
+
function coerceToChatMessageRaw(value) {
|
|
145
|
+
if (!value || value.value == null) {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
if (value.type === 'chat-message') {
|
|
149
|
+
return value.value;
|
|
150
|
+
}
|
|
151
|
+
if (value.type === 'string') {
|
|
152
|
+
return { type: 'user', message: value.value };
|
|
153
|
+
}
|
|
154
|
+
if (value.type === 'object' &&
|
|
155
|
+
'type' in value.value &&
|
|
156
|
+
'message' in value.value &&
|
|
157
|
+
typeof value.value.type === 'string' &&
|
|
158
|
+
typeof value.value.message === 'string') {
|
|
159
|
+
return value.value;
|
|
160
|
+
}
|
|
161
|
+
if (value.type === 'any') {
|
|
162
|
+
const inferred = inferType(value.value);
|
|
163
|
+
return coerceTypeOptional(inferred, 'chat-message');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function coerceToBoolean(value) {
|
|
167
|
+
if (!value || !value.value) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
if (isArrayDataValue(value)) {
|
|
171
|
+
return value.value
|
|
172
|
+
.map((v) => coerceTypeOptional({ type: value.type.replace('[]', ''), value: v }, 'boolean'))
|
|
173
|
+
.every((v) => v);
|
|
174
|
+
}
|
|
175
|
+
if (value.type === 'string') {
|
|
176
|
+
return value.value.length > 0 && value.value !== 'false';
|
|
177
|
+
}
|
|
178
|
+
if (value.type === 'boolean') {
|
|
179
|
+
return value.value;
|
|
180
|
+
}
|
|
181
|
+
if (value.type === 'number') {
|
|
182
|
+
return value.value !== 0;
|
|
183
|
+
}
|
|
184
|
+
if (value.type === 'date') {
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
if (value.type === 'time') {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
if (value.type === 'datetime') {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
if (value.type === 'chat-message') {
|
|
194
|
+
const hasValue = (Array.isArray(value.value.message) && value.value.message.length > 0) ||
|
|
195
|
+
(typeof value.value.message === 'string' && value.value.message.length > 0) ||
|
|
196
|
+
(typeof value.value.message === 'object' &&
|
|
197
|
+
'type' in value.value.message &&
|
|
198
|
+
value.value.message.type === 'url' &&
|
|
199
|
+
value.value.message.url.length > 0);
|
|
200
|
+
return hasValue;
|
|
201
|
+
}
|
|
202
|
+
return !!value.value;
|
|
203
|
+
}
|
|
204
|
+
function coerceToNumber(value) {
|
|
205
|
+
if (!value || value.value == null) {
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
if (isArrayDataValue(value)) {
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
if (value.type === 'string') {
|
|
212
|
+
return parseFloat(value.value);
|
|
213
|
+
}
|
|
214
|
+
if (value.type === 'boolean') {
|
|
215
|
+
return value.value ? 1 : 0;
|
|
216
|
+
}
|
|
217
|
+
if (value.type === 'number') {
|
|
218
|
+
return value.value;
|
|
219
|
+
}
|
|
220
|
+
if (value.type === 'date') {
|
|
221
|
+
return new Date(value.value).valueOf();
|
|
222
|
+
}
|
|
223
|
+
if (value.type === 'time') {
|
|
224
|
+
return new Date(value.value).valueOf();
|
|
225
|
+
}
|
|
226
|
+
if (value.type === 'datetime') {
|
|
227
|
+
return new Date(value.value).valueOf();
|
|
228
|
+
}
|
|
229
|
+
if (value.type === 'chat-message') {
|
|
230
|
+
if (typeof value.value.message === 'string') {
|
|
231
|
+
return parseFloat(value.value.message);
|
|
232
|
+
}
|
|
233
|
+
if (Array.isArray(value.value.message) &&
|
|
234
|
+
value.value.message.length === 1 &&
|
|
235
|
+
typeof value.value.message[0] === 'string') {
|
|
236
|
+
return parseFloat(value.value.message[0]);
|
|
237
|
+
}
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
if (value.type === 'any' || value.type === 'object') {
|
|
241
|
+
const inferred = inferType(value.value);
|
|
242
|
+
return coerceTypeOptional(inferred, 'number');
|
|
243
|
+
}
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
function coerceToObject(value) {
|
|
247
|
+
if (!value || value.value == null) {
|
|
248
|
+
return undefined;
|
|
249
|
+
}
|
|
250
|
+
return value.value; // Whatever, consider anything an object
|
|
251
|
+
}
|
|
252
|
+
function coerceToBinary(value) {
|
|
253
|
+
if (!value || value.value == null) {
|
|
254
|
+
return undefined;
|
|
255
|
+
}
|
|
256
|
+
if (value.type === 'binary') {
|
|
257
|
+
return value.value;
|
|
258
|
+
}
|
|
259
|
+
if (value.type === 'string') {
|
|
260
|
+
return new TextEncoder().encode(value.value);
|
|
261
|
+
}
|
|
262
|
+
if (value.type === 'boolean') {
|
|
263
|
+
return new TextEncoder().encode(value.value.toString());
|
|
264
|
+
}
|
|
265
|
+
if (value.type === 'vector' || value.type === 'number[]') {
|
|
266
|
+
return new Uint8Array(value.value);
|
|
267
|
+
}
|
|
268
|
+
if (value.type === 'number') {
|
|
269
|
+
return new Uint8Array([value.value]);
|
|
270
|
+
}
|
|
271
|
+
if (value.type === 'audio' || value.type === 'image') {
|
|
272
|
+
return value.value.data;
|
|
273
|
+
}
|
|
274
|
+
return new TextEncoder().encode(JSON.stringify(value.value));
|
|
275
|
+
}
|
|
276
|
+
function coerceToGraphReference(value) {
|
|
277
|
+
if (!value || value.value == null) {
|
|
278
|
+
return undefined;
|
|
279
|
+
}
|
|
280
|
+
if (value.type === 'graph-reference') {
|
|
281
|
+
return value.value;
|
|
282
|
+
}
|
|
283
|
+
if (value.type === 'string') {
|
|
284
|
+
return { graphName: value.value, graphId: '' };
|
|
285
|
+
}
|
|
286
|
+
if (value.type === 'object' && 'graphName' in value.value && 'graphId' in value.value) {
|
|
287
|
+
return value.value;
|
|
288
|
+
}
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
export function canBeCoercedAny(from, to) {
|
|
292
|
+
for (const fromType of Array.isArray(from) ? from : [from]) {
|
|
293
|
+
for (const toType of Array.isArray(to) ? to : [to]) {
|
|
294
|
+
if (canBeCoerced(fromType, toType)) {
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
// TODO hard to keep in sync with coerceType
|
|
302
|
+
export function canBeCoerced(from, to) {
|
|
303
|
+
if (to === 'any' || from === 'any') {
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
if (isArrayDataType(to) && isArrayDataType(from)) {
|
|
307
|
+
return canBeCoerced(getScalarTypeOf(from), getScalarTypeOf(to));
|
|
308
|
+
}
|
|
309
|
+
if (isArrayDataType(to) && !isArrayDataType(from)) {
|
|
310
|
+
return canBeCoerced(from, getScalarTypeOf(to));
|
|
311
|
+
}
|
|
312
|
+
if (isArrayDataType(from) && !isArrayDataType(to)) {
|
|
313
|
+
return to === 'string' || to === 'object';
|
|
314
|
+
}
|
|
315
|
+
if (to === 'gpt-function') {
|
|
316
|
+
return from === 'object';
|
|
317
|
+
}
|
|
318
|
+
if (to === 'audio' || to === 'binary' || to === 'image') {
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { isArrayDataType } from '../model/DataValue.js';
|
|
2
|
+
export function isDataTypeAccepted(inputType, accepted) {
|
|
3
|
+
inputType = Array.isArray(inputType) ? inputType : [inputType];
|
|
4
|
+
accepted = Array.isArray(accepted) ? accepted : [accepted];
|
|
5
|
+
for (const input of inputType) {
|
|
6
|
+
for (const accept of accepted) {
|
|
7
|
+
if (isDataTypeCompatible(input, accept)) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
export function isDataTypeCompatible(inputType, accepted) {
|
|
15
|
+
// Any is always compatible on either side
|
|
16
|
+
if (inputType === 'any' || accepted === 'any') {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
// If they're both arrays, and either is 'any[]', it's compatible
|
|
20
|
+
if (isArrayDataType(inputType) && isArrayDataType(accepted) && (inputType === 'any[]' || accepted === 'any[]')) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
if (inputType === accepted) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const copyToClipboard = (text) => {
|
|
2
|
+
const textarea = document.createElement('textarea');
|
|
3
|
+
textarea.textContent = text;
|
|
4
|
+
textarea.style.position = 'absolute';
|
|
5
|
+
textarea.style.left = '-9999px';
|
|
6
|
+
document.body.appendChild(textarea);
|
|
7
|
+
textarea.select();
|
|
8
|
+
document.execCommand('copy');
|
|
9
|
+
document.body.removeChild(textarea);
|
|
10
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Gets an Error from an unknown error object (strict unknown errors is enabled, helper util). */
|
|
2
|
+
export function getError(error) {
|
|
3
|
+
const errorInstance = typeof error === 'object' && error instanceof Error
|
|
4
|
+
? error
|
|
5
|
+
: new Error(error != null ? error.toString() : 'Unknown error');
|
|
6
|
+
return errorInstance;
|
|
7
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getScalarTypeOf, isArrayDataType, isFunctionDataType, isScalarDataValue, unwrapDataValue, } from '../model/DataValue.js';
|
|
2
|
+
export function expectType(value, type) {
|
|
3
|
+
// Allow a string to be expected for a string[], just return an array of one element
|
|
4
|
+
if (isArrayDataType(type) && isScalarDataValue(value) && getScalarTypeOf(type) === value.type) {
|
|
5
|
+
return [value.value];
|
|
6
|
+
}
|
|
7
|
+
if (type === 'any' || type === 'any[]' || value?.type === 'any' || value?.type === 'any[]') {
|
|
8
|
+
return value?.value;
|
|
9
|
+
}
|
|
10
|
+
if ((isFunctionDataType(type) && value?.type === `fn<${type}>`) || type === 'fn<any>') {
|
|
11
|
+
return (() => value.value);
|
|
12
|
+
}
|
|
13
|
+
if (value?.type !== type) {
|
|
14
|
+
throw new Error(`Expected value of type ${type} but got ${value?.type}`);
|
|
15
|
+
}
|
|
16
|
+
return value.value;
|
|
17
|
+
}
|
|
18
|
+
export function expectTypeOptional(value, type) {
|
|
19
|
+
if (value === undefined) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
// Allow a string to be expected for a string[], just return an array of one element
|
|
23
|
+
if (isArrayDataType(type) && isScalarDataValue(value) && getScalarTypeOf(type) === value.type) {
|
|
24
|
+
return [value.value];
|
|
25
|
+
}
|
|
26
|
+
// We allow a fn<string> to be expected for a string, so unwrap it on demand
|
|
27
|
+
if (isFunctionDataType(value.type) && value.type === `fn<${type}>`) {
|
|
28
|
+
value = unwrapDataValue(value);
|
|
29
|
+
}
|
|
30
|
+
if (value.type !== type) {
|
|
31
|
+
throw new Error(`Expected value of type ${type} but got ${value?.type}`);
|
|
32
|
+
}
|
|
33
|
+
return value.value;
|
|
34
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { getError } from './errors.js';
|
|
2
|
+
import { DEFAULT_CHAT_NODE_TIMEOUT } from './defaults.js';
|
|
3
|
+
// https://github.com/openai/openai-node/issues/18#issuecomment-1518715285
|
|
4
|
+
export class EventSourceResponse extends Response {
|
|
5
|
+
name;
|
|
6
|
+
timeout;
|
|
7
|
+
streams;
|
|
8
|
+
constructor(body, init, timeout) {
|
|
9
|
+
if (body == null) {
|
|
10
|
+
super(null, init);
|
|
11
|
+
this.name = 'EventSourceResponse';
|
|
12
|
+
this.streams = null;
|
|
13
|
+
this.timeout = timeout;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const [bodyForString, bodyForEvents] = body.tee();
|
|
17
|
+
const streams = createEventStream(bodyForEvents);
|
|
18
|
+
// By passing our transformed stream into the Response constructor, we prevent anyone
|
|
19
|
+
// from accidentally accessing the raw response.body stream.
|
|
20
|
+
super(bodyForString, init);
|
|
21
|
+
this.name = 'EventSourceResponse';
|
|
22
|
+
this.streams = streams;
|
|
23
|
+
this.timeout = timeout;
|
|
24
|
+
}
|
|
25
|
+
async *events() {
|
|
26
|
+
if (this.streams == null) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const reader = this.streams.eventStream.getReader();
|
|
30
|
+
try {
|
|
31
|
+
while (true) {
|
|
32
|
+
const { done, value } = await this.raceWithTimeout(reader.read(), this.timeout);
|
|
33
|
+
if (done) {
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
yield value;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
try {
|
|
41
|
+
reader.releaseLock();
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
console.error(`Failed to release read lock on event source: ${getError(err).toString()}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async raceWithTimeout(promise, timeout) {
|
|
49
|
+
const raceTimeout = timeout ?? DEFAULT_CHAT_NODE_TIMEOUT;
|
|
50
|
+
// eslint-disable-next-line no-async-promise-executor -- Error handled correctly
|
|
51
|
+
return new Promise(async (resolve, reject) => {
|
|
52
|
+
const timer = setTimeout(() => {
|
|
53
|
+
reject(new Error('Timeout: API response took too long.'));
|
|
54
|
+
}, raceTimeout);
|
|
55
|
+
try {
|
|
56
|
+
const result = await promise;
|
|
57
|
+
clearTimeout(timer);
|
|
58
|
+
resolve(result);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
clearTimeout(timer);
|
|
62
|
+
reject(error);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export default async function fetchEventSource(url, init, timeout) {
|
|
68
|
+
const headers = {
|
|
69
|
+
...init?.headers,
|
|
70
|
+
accept: 'text/event-stream',
|
|
71
|
+
};
|
|
72
|
+
const response = await fetch(url, {
|
|
73
|
+
...init,
|
|
74
|
+
headers,
|
|
75
|
+
});
|
|
76
|
+
return new EventSourceResponse(response.body, response, timeout);
|
|
77
|
+
}
|
|
78
|
+
class LineSplitter {
|
|
79
|
+
separator;
|
|
80
|
+
buffer = '';
|
|
81
|
+
constructor(separator = /\n+/) {
|
|
82
|
+
this.separator = separator;
|
|
83
|
+
}
|
|
84
|
+
transform(chunk, controller) {
|
|
85
|
+
this.buffer += chunk;
|
|
86
|
+
const lines = this.buffer.split(this.separator);
|
|
87
|
+
this.buffer = lines.pop() ?? '';
|
|
88
|
+
for (const line of lines) {
|
|
89
|
+
controller.enqueue(line);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
flush(controller) {
|
|
93
|
+
if (this.buffer.length > 0) {
|
|
94
|
+
controller.enqueue(this.buffer);
|
|
95
|
+
this.buffer = '';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function createEventStream(body) {
|
|
100
|
+
if (body == null) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const textStream = body.pipeThrough(new TextDecoderStream());
|
|
104
|
+
const eventStream = textStream.pipeThrough(new TransformStream(new LineSplitter())).pipeThrough(new TransformStream({
|
|
105
|
+
transform(line, controller) {
|
|
106
|
+
if (line.trim().length === 0) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (line.startsWith('data: ')) {
|
|
110
|
+
const data = line.slice(6).trim();
|
|
111
|
+
controller.enqueue(data);
|
|
112
|
+
}
|
|
113
|
+
else if (line.startsWith('event: ')) {
|
|
114
|
+
const event = line.slice(7).trim();
|
|
115
|
+
controller.enqueue(`[${event}]`);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
}));
|
|
119
|
+
return { eventStream, textStream };
|
|
120
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function isNotNull(value) {
|
|
2
|
+
return value != null;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Checks that the given tuple is exhaustive, ie. it represents all possible values in the union T.
|
|
6
|
+
* Note that this function returns a function, so the function needs to be called like
|
|
7
|
+
* `SpecificStrings.exhaustiveTuple<Furniture>()('v1', 'v2', ...)`.
|
|
8
|
+
* If you miss a value, the type error will tell you which value you missed.
|
|
9
|
+
*
|
|
10
|
+
* Taken from https://stackoverflow.com/a/55266531/
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* type Furniture = 'chair' | 'table' | 'lamp' | 'ottoman';
|
|
14
|
+
* const furniture = SpecificStrings.exhaustiveTuple<Furniture>()('chair', 'table', 'lamp', 'ottoman');
|
|
15
|
+
*
|
|
16
|
+
* // error, argument of type '"chair"' is not assignable to parameter of type '"You are missing ottoman"'.
|
|
17
|
+
* const missingFurniture = SpecificStrings.exhaustiveTuple<Furniture>()('chair', 'table', 'lamp');
|
|
18
|
+
*/
|
|
19
|
+
export const exhaustiveTuple = () =>
|
|
20
|
+
// impressive inference from TS: it knows when the condition and the true branch can't both be satisfied
|
|
21
|
+
(...x) => x;
|
|
22
|
+
/**
|
|
23
|
+
* See exhaustiveTuple above. Does the same thing except returns a Set, not an array.
|
|
24
|
+
*/
|
|
25
|
+
export const exhaustiveSet = () => (...x) => new Set(x);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function getPluginConfig(plugin, settings, name) {
|
|
2
|
+
if (!plugin) {
|
|
3
|
+
return undefined;
|
|
4
|
+
}
|
|
5
|
+
const configSpec = plugin?.configSpec?.[name];
|
|
6
|
+
if (!configSpec) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const pluginSettings = settings.pluginSettings?.[plugin.id];
|
|
10
|
+
if (pluginSettings) {
|
|
11
|
+
const value = pluginSettings[name];
|
|
12
|
+
if (!value || typeof value !== 'string') {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
const envFallback = configSpec.pullEnvironmentVariable;
|
|
18
|
+
const envFallbackName = envFallback === true ? name : envFallback;
|
|
19
|
+
if (envFallbackName && settings.pluginEnv?.[envFallbackName]) {
|
|
20
|
+
return settings.pluginEnv[envFallbackName];
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Let the user type things like \n and \t in the editor, and they'll be replaced with the actual characters. */
|
|
2
|
+
export function handleEscapeCharacters(inputString) {
|
|
3
|
+
// Would use negative lookbehind but not supported in some recent safari versions >.<
|
|
4
|
+
return inputString
|
|
5
|
+
.replace(/([^\\]|^)\\n/g, '$1\n')
|
|
6
|
+
.replace(/([^\\]|^)\\t/g, '$1\t')
|
|
7
|
+
.replace(/([^\\]|^)\\r/g, '$1\r')
|
|
8
|
+
.replace(/([^\\]|^)\\f/g, '$1\f')
|
|
9
|
+
.replace(/([^\\]|^)\\b/g, '$1\b')
|
|
10
|
+
.replace(/([^\\]|^)\\v/g, '$1\v');
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './coerceType.js';
|
|
2
|
+
export * from './expectType.js';
|
|
3
|
+
export * from './errors.js';
|
|
4
|
+
export * from './serialization/serialization.js';
|
|
5
|
+
export * from './outputs.js';
|
|
6
|
+
export * from './base64.js';
|
|
7
|
+
export * from './inputs.js';
|
|
8
|
+
export * from './misc.js';
|
|
9
|
+
export * from './getPluginConfig.js';
|
|
10
|
+
export * from './newId.js';
|
|
11
|
+
export * from './serialization/serializationUtils.js';
|
|
12
|
+
export * from './handleEscapeCharacters.js';
|
|
13
|
+
export * from './compatibility.js';
|
|
14
|
+
export * from './defaults.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { coerceTypeOptional } from './coerceType.js';
|
|
2
|
+
import { entries } from './typeSafety.js';
|
|
3
|
+
export function getInputOrData(data, inputs, inputAndDataKey, type, useInputToggleDataKey) {
|
|
4
|
+
if (!useInputToggleDataKey) {
|
|
5
|
+
const capitalized = inputAndDataKey[0].toUpperCase() + inputAndDataKey.slice(1);
|
|
6
|
+
const key = `use${capitalized}Input`;
|
|
7
|
+
useInputToggleDataKey = key;
|
|
8
|
+
}
|
|
9
|
+
const value = data[useInputToggleDataKey] && inputs[inputAndDataKey] != null
|
|
10
|
+
? coerceTypeOptional(inputs[inputAndDataKey], type ?? 'string') ?? data[inputAndDataKey]
|
|
11
|
+
: data[inputAndDataKey];
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
export function cleanHeaders(headers) {
|
|
15
|
+
return Object.fromEntries(entries(headers).filter(([key]) => key.trim()));
|
|
16
|
+
}
|