FlowiseAI / FlowiseChatEmbed

334 stars 1.35k forks source link

Feat: Add server proxy for standalone deployment #271

Closed toi500 closed 1 week ago

toi500 commented 3 weeks ago

Enhanced Chatflow Management and Security in Embed Server

This PR introduces significant improvements to chatflow management, security, and developer experience, making it easier to configure and deploy secure embedded chatbots.

Easy Flow Management with Environment Variables:

Enhanced web.js Access Control:

Improved Documentation:

Embed Script Display Utility:

Strengthened Server Security:

toi500 commented 3 weeks ago

@HenryHengZJ, our friend @saatchi-david gave me a good idea tonight when we were talking on Discord.

We could extend the proxy to support multiple chatflows for the same deployment. I think that the easiest way to do this is by adding a CHATFLOWS JSON configuration:

Backend (.env):

CHATFLOWS={
    "default": "ce158a4f-989f-467b-9a9f4-d0f3f7def6b7, *",
    "support": "f5d84d3a-2c72-4853-8574-37a4a87dd5c4, www.support-site.com",
    "sales": "89b7e421-9f3a-4669-8a6f-9b7d3e31739c, www.sales-site.com"
}

Frontend:

<script type="module">
        import Chatbot from './web.js'

        // Support chatflow
        Chatbot.init({
            chatflowid: 'support/proxy',  // Uses support flow
            apiHost: 'http://localhost:3000'
        })
    </script>
saatchi-david commented 3 weeks ago

(Cross-posting from Discord) That's exactly the functionality I was hoping for. Awesome. Would be awesome to see something like that more baked into flowise, potentially as an addition to the "Allowed Domains" interface. Or maybe more appropriate to replace that tab with a "security" tab where users could specify allowed domains and toggle the proxy functionality.

On a related note, Henry mentioned exploring adding more control/security for the config overrides. Just thinking out loud, but I could imagine the security tab including a toggle to disable the config overrides as well.

Taking that a step further... it would be awesome if we could specify defaults for each of the config options from within flowise, preventing the need to handle so much with the embed. Then from flowise, have the overrides disabled by default, and have the option to enable specific ones as needed.

This would consolidate configuration to the flowise interface, simplifying setup by reducing the need to update code, and by default create a more secure setup. Then if users need to control something via override, they can enable only what they need, e.g. maybe only the session ID, and not have the risk of things like prompt and model being overridden by the user.

toi500 commented 3 weeks ago

-- off topic --

@saatchi-david, I don't want to go off-topic too much here, but I agree 100%. The overrideConfig limitation is definitely something they are already cooking, and I think it is a brilliant idea. It will reduce the risk of hijacking a lot. It would be much less attractive to mess around with other people's flows. And I really hope they bring back together Flowise and the Embed Chatbot in the future for Flowise Cloud for an effective proxy implementation you just described. Not a easy task though.

--

In relation to this PR and my last comment, I think it makes sense to have just one deployment to manage multiple embedded chatbots from different flows.

toi500 commented 3 weeks ago

@saatchi-david @HenryHengZJ I've added the multi-flow feature. I managed to do it entirely through.envconfiguration, so all variables are in one place. All of this is built on top of the current implementation, and no changes are needed in the FlowiseAI repository.

This approach is much better. Testing it now.

HenryHengZJ commented 3 weeks ago

thank you! let me know when its ready to review

toi500 commented 2 weeks ago

@HenryHengZJ I have removed the legacy /proxy sufix (from the original single-flow implementation) and now it is ready to review.

toi500 commented 1 week ago

@HenryHengZJ I have made the requested changes. Please review.