Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡ Introduce a new high-performing standalone chat API #1200

Merged
merged 40 commits into from
Mar 21, 2024

Conversation

baptisteArno
Copy link
Owner

@baptisteArno baptisteArno commented Jan 31, 2024

Closes #1154

Summary by CodeRabbit

  • New Features

    • Added authentication functionality for user sessions in chat API.
    • Introduced chat-related API endpoints for starting, previewing, and continuing chat sessions, and streaming messages.
    • Implemented WhatsApp API webhook handling for receiving and processing messages.
    • Added environment variable NEXT_PUBLIC_CHAT_API_URL for chat API URL configuration.
  • Bug Fixes

    • Adjusted file upload logic to correctly determine the API host.
    • Fixed message streaming URL in chat integration with OpenAI.
  • Documentation

    • Updated guides for creating blocks, local installation, self-hosting, and deployment to use bun instead of pnpm.
  • Refactor

    • Refactored chat API functionalities to use modular architecture.
    • Simplified client log saving and session update functionalities by using external functions.
    • Transitioned package management and workflow commands to use bun.
  • Chores

    • Switched to bun for package management in Dockerfiles and GitHub workflows.
    • Added new Dockerfile for chat API service setup with Bun framework.
    • Updated .prettierignore and documentation with new commands.
  • Style

    • No visible changes to end-users.
  • Tests

    • No visible changes to end-users.
  • Revert

    • No reverts in this release.

Copy link

vercel bot commented Jan 31, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
builder-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2024 9:15am
landing-page-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2024 9:15am
viewer-v2 🔄 Building (Inspect) Visit Preview Mar 21, 2024 9:15am

Copy link

coderabbitai bot commented Jan 31, 2024

Important

Auto Review Skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Walkthrough

The comprehensive changes detail the migration of Typebot's chat API to a standalone server, addressing limitations encountered in serverless environments, particularly with long-running processes like AI operations and issues with WhatsApp webhook retries causing duplicate messages. The migration enhances the chat API's capability to manage sessions, handle chat-related functionalities, integrate with WhatsApp, and streamline operations with the introduction of the Bun package manager for better efficiency and performance.

Changes

File Pattern Change Summary
apps/chat-api/src/... Introduced and enhanced chat API functionalities including authentication, session management, message streaming, and integration with Elysia framework.
apps/viewer/src/..., packages/bot-engine/apiHandlers/... Refactored chat-related functionalities to utilize centralized API handlers for starting chats, continuing chats, logging, and session updates.
packages/bot-engine/blocks/..., packages/bot-engine/whatsapp/... Adjusted logic for OpenAI chat completions, WhatsApp message handling, and credential management.
.github/workflows/... Updated CI/CD workflows to use bun instead of pnpm for package management and deployment tasks.
Dockerfile, chatApi.Dockerfile Migrated to oven/bun base image and adapted commands for Bun in Docker environments.
apps/docs/..., packages/forge/cli/..., packages/lib/playwright/... Documentation and tooling updates to reflect the migration to bun for development and deployment processes.

Assessment against linked issues

Objective Addressed Explanation
Migrate chat API to a standalone server (#1154)
Address serverless environment limitations for long-running processes (#1154)
Resolve WhatsApp webhook retry issue resulting in duplicate messages (#1154) The standalone server allows for immediate "OK" responses to WhatsApp while continuing processing, addressing the retry issue.
Utilize Elysia framework for enhanced API management (#1154)
Improve package management and deployment efficiency with bun (#1154)

The changes thoroughly address the primary objectives outlined in the linked issue, focusing on migrating the chat API to a standalone server to overcome the limitations of serverless environments, particularly for long-running processes and the handling of WhatsApp webhook retries. The adoption of the Elysia framework and the shift to bun for package management and deployment tasks further enhance the efficiency and performance of the chat API.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3b27f16 and 686802a.
Files ignored due to path filters (10)
  • apps/builder/package.json is excluded by: !**/*.json
  • apps/chat-api/package.json is excluded by: !**/*.json
  • apps/chat-api/tsconfig.json is excluded by: !**/*.json
  • apps/docs/openapi/viewer.json is excluded by: !**/*.json
  • apps/landing-page/package.json is excluded by: !**/*.json
  • apps/viewer/package.json is excluded by: !**/*.json
  • packages/bot-engine/package.json is excluded by: !**/*.json
  • packages/emails/package.json is excluded by: !**/*.json
  • packages/lib/package.json is excluded by: !**/*.json
  • pnpm-lock.yaml is excluded by: !**/*.yaml
Files selected for processing (33)
  • apps/builder/src/features/whatsapp/startWhatsAppPreview.ts (1 hunks)
  • apps/chat-api/src/auth.ts (1 hunks)
  • apps/chat-api/src/index.ts (1 hunks)
  • apps/chat-api/src/runtimes/api/app.ts (1 hunks)
  • apps/chat-api/src/runtimes/api/continueChat.ts (1 hunks)
  • apps/chat-api/src/runtimes/api/getMessageStream.ts (1 hunks)
  • apps/chat-api/src/runtimes/api/legacy/getOpenAIChatCompletionStream.ts (1 hunks)
  • apps/chat-api/src/runtimes/api/saveClientLogs.ts (1 hunks)
  • apps/chat-api/src/runtimes/api/startChat.ts (1 hunks)
  • apps/chat-api/src/runtimes/api/startChatPreview.ts (1 hunks)
  • apps/chat-api/src/runtimes/api/updateTypebotInSession.ts (1 hunks)
  • apps/chat-api/src/runtimes/whatsapp/app.ts (1 hunks)
  • apps/chat-api/src/runtimes/whatsapp/receiveMessage.ts (1 hunks)
  • apps/chat-api/src/runtimes/whatsapp/receiveMessagePreview.ts (1 hunks)
  • apps/viewer/src/app/api/v1/sessions/[sessionId]/streamMessage/route.ts (1 hunks)
  • apps/viewer/src/features/chat/api/continueChat.ts (2 hunks)
  • apps/viewer/src/features/chat/api/saveClientLogs.ts (2 hunks)
  • apps/viewer/src/features/chat/api/startChat.ts (2 hunks)
  • apps/viewer/src/features/chat/api/startChatPreview.ts (2 hunks)
  • apps/viewer/src/features/chat/api/updateTypebotInSession.ts (2 hunks)
  • packages/bot-engine/blocks/integrations/legacy/openai/createChatCompletionOpenAI.ts (1 hunks)
  • packages/bot-engine/blocks/integrations/zemanticAi/executeZemanticAiBlock.ts (2 hunks)
  • packages/bot-engine/forge/executeForgedBlock.ts (3 hunks)
  • packages/bot-engine/queries/getCredentials.ts (1 hunks)
  • packages/bot-engine/whatsapp/sendChatReplyToWhatsApp.ts (5 hunks)
  • packages/bot-engine/whatsapp/sendWhatsAppMessage.ts (2 hunks)
  • packages/embeds/js/src/features/blocks/inputs/fileUpload/components/FileUploadForm.tsx (2 hunks)
  • packages/embeds/js/src/features/blocks/integrations/openai/streamChat.ts (1 hunks)
  • packages/embeds/js/src/queries/startChatQuery.ts (1 hunks)
  • packages/embeds/js/src/utils/guessApiHost.ts (1 hunks)
  • packages/env/env.ts (2 hunks)
  • packages/schemas/features/chat/schema.ts (1 hunks)
  • packages/schemas/features/whatsapp.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/schemas/features/whatsapp.ts
Additional comments: 25
packages/bot-engine/queries/getCredentials.ts (1)
  • 3-6: The implementation of getCredentials is concise and follows best practices for database querying with Prisma. The function is correctly marked as async and properly awaits the Prisma call. This ensures that the function can be used reliably in asynchronous contexts without risking unhandled promises.
apps/chat-api/src/index.ts (1)
  • 1-10: The setup of the Elysia server with apiRuntime and whatsAppRuntime is correctly implemented. The server's configuration to listen on a port from an environment variable with a fallback to 3002 is a good practice, ensuring flexibility in deployment environments. The logging statement for server status is also a good practice for observability.
packages/embeds/js/src/utils/guessApiHost.ts (1)
  • 9-16: The update to guessApiHost introducing the ignoreChatApiUrl parameter is logically sound and provides a clear conditional return based on the parameter's value. Ensure that all callers of this function are updated to handle the potential undefined return value, which could affect the application's behavior if not properly managed.
packages/bot-engine/whatsapp/sendWhatsAppMessage.ts (1)
  • 19-31: Switching to the ky library for the sendWhatsAppMessage function and adapting the request syntax accordingly is correctly implemented. The use of template literals for URL construction and the inclusion of authorization headers follow best practices for HTTP requests. Ensure that the transition from got to ky has been tested thoroughly, especially regarding error handling and response parsing, as these areas can sometimes behave differently between libraries.
apps/viewer/src/features/chat/api/saveClientLogs.ts (1)
  • 21-23: Refactoring saveClientLogs to delegate its functionality to saveClientLogsFn from a different module is a good practice, promoting code reusability and separation of concerns. Ensure that error handling is adequately addressed either within saveClientLogsFn or in the calling context to maintain robustness.
apps/viewer/src/features/chat/api/startChat.ts (1)
  • 18-24: Refactoring the startChat function to use startChatFn from the chat API runtime and focusing on response handling, including CORS headers, is an effective way to simplify the API layer. This change properly delegates the responsibility of starting a chat to the chat API runtime, aligning with best practices for API design. Ensure that CORS policies are consistently applied across all endpoints to avoid potential cross-origin issues.
apps/viewer/src/features/chat/api/updateTypebotInSession.ts (1)
  • 22-24: Simplifying the updateTypebotInSession function by delegating its core logic to updateTypebotInSessionFn from the chat API runtime is a good practice. This change enhances modularity and ensures that the API layer remains focused on handling requests and responses. Ensure that updateTypebotInSessionFn includes comprehensive error handling to manage any issues that may arise during the update process.
apps/chat-api/src/runtimes/whatsapp/app.ts (1)
  • 5-33: Setting up the WhatsApp runtime for the Elysia server with endpoints for receiving WhatsApp messages and previews is correctly implemented. The structure of the routes, including parameter usage and request body validation, aligns with best practices for API design. The delegation to receiveMessage and receiveMessagePreview for handling requests ensures a clean separation of concerns. Ensure that these delegated functions include robust error handling and validation to manage any potential issues with incoming requests.
apps/chat-api/src/auth.ts (1)
  • 5-12: The update to getAuthenticatedUserId to support E2E testing environments by returning a mocked user ID based on an environment variable is a practical approach for testing. The function's structure, including the extraction and authentication of bearer tokens, follows best practices for API authentication. Ensure that the use of the NEXT_PUBLIC_E2E_TEST environment variable is documented and that its implications for security are carefully considered in production environments.
apps/viewer/src/features/chat/api/continueChat.ts (1)
  • 25-32: Refactoring the continueChat function to use continueChatFn from the chat API runtime and focusing on response handling, including CORS headers, is an effective way to simplify the API layer. This change properly delegates the responsibility of continuing a chat to the chat API runtime, aligning with best practices for API design. Ensure that CORS policies are consistently applied across all endpoints to avoid potential cross-origin issues.
apps/viewer/src/features/chat/api/startChatPreview.ts (1)
  • 31-39: Refactoring the startChatPreview function to directly use startChatPreviewFn from the chat API runtime simplifies the API layer by removing direct logic for preview chat session management. This change promotes modularity and ensures that the API layer remains focused on handling requests and responses. Ensure that startChatPreviewFn includes comprehensive error handling to manage any issues that may arise during the preview process.
apps/chat-api/src/runtimes/whatsapp/receiveMessagePreview.ts (1)
  • 10-31: The implementation of receiveMessagePreview for handling WhatsApp message previews is correctly done, including validation of the required environment variable and processing of the received message. The use of TRPCError for error handling and the extraction of contact details from the message payload follow best practices. Ensure that the function is thoroughly tested, especially the error paths, to confirm that it behaves as expected under various scenarios.
apps/chat-api/src/runtimes/whatsapp/receiveMessage.ts (1)
  • 11-35: The receiveMessage function's implementation for processing incoming WhatsApp messages is correctly done, including the extraction and validation of message content and sender details. The delegation to resumeWhatsAppFlow for further processing ensures a clean separation of concerns and promotes code reuse. Ensure that the function includes comprehensive error handling to manage any issues that may arise during message processing.
apps/chat-api/src/runtimes/api/saveClientLogs.ts (1)
  • 12-48: The implementation of saveClientLogs within the chat API runtime is well-structured, including robust session validation, error handling with TRPCError, and log details formatting using formatLogDetails. This function ensures that only valid sessions can save logs, enhancing data integrity. Ensure that the error handling paths are thoroughly tested to confirm that appropriate responses are returned for various error conditions.
apps/viewer/src/app/api/v1/sessions/[sessionId]/streamMessage/route.ts (1)
  • 25-44: Defining an API route for streaming messages with proper handling of OPTIONS and POST methods is correctly implemented. The conditional logic for environments that may not support streaming, such as Vercel, is a thoughtful inclusion. Ensure that the use of getMessageStream for obtaining the stream is thoroughly tested, especially the error handling and streaming mechanics, to confirm that it behaves as expected across different environments and scenarios.
apps/chat-api/src/runtimes/api/startChatPreview.ts (1)
  • 16-78: The implementation of startChatPreview within the chat API runtime for handling chat preview initiation is well-structured, including session management and state saving. The use of startSession, restartSession, and saveStateToDatabase for managing session states ensures that the function can handle various scenarios effectively. Ensure that the function is thoroughly tested, especially the session state updates and error handling paths, to confirm that it behaves as expected under different conditions.
apps/chat-api/src/runtimes/api/legacy/getOpenAIChatCompletionStream.ts (1)
  • 14-58: The implementation of getOpenAIChatCompletionStream for creating a chat completion stream with OpenAI is correctly done, including credentials retrieval, decryption, and OpenAI API interaction. The use of decryptV2 for credentials decryption and the careful handling of missing credentials are best practices. Ensure that the interaction with the OpenAI API, especially the stream creation and error handling, is thoroughly tested to confirm that it behaves as expected under various scenarios.
apps/builder/src/features/whatsapp/startWhatsAppPreview.ts (1)
  • 117-117: The addition of isStreamEnabled: false to the startSession call explicitly disables streaming for WhatsApp previews. Ensure this behavior aligns with the intended functionality and does not negatively impact the user experience or session management.
packages/bot-engine/blocks/integrations/legacy/openai/createChatCompletionOpenAI.ts (1)
  • 92-93: The addition of !process.env.VERCEL_ENV as a condition within the createChatCompletionOpenAI function suggests an intention to alter behavior based on the environment. Verify that this condition correctly implements the desired logic across different environments without causing unintended side effects.
packages/bot-engine/forge/executeForgedBlock.ts (2)
  • 21-22: The addition of the env import from @typebot.io/env suggests changes in how environment variables are managed. Ensure that this new approach is consistently applied across the application and aligns with the overall strategy for environment variable management.
  • 44-44: The use of getCredentials instead of direct database queries for retrieving credentials abstracts the credentials retrieval process. Confirm that getCredentials correctly handles all scenarios, including error handling and credentials validation, to ensure robustness.
packages/bot-engine/whatsapp/sendChatReplyToWhatsApp.ts (1)
  • 13-13: The switch from got to ky for handling HTTP errors may affect how errors are processed and logged. Ensure that this change is tested thoroughly to confirm that error handling remains effective and consistent with the application's requirements.
packages/schemas/features/chat/schema.ts (1)
  • 227-227: The introduction of default values for isStreamEnabled and isOnlyRegistering in the startPreviewChatInputSchema standardizes the behavior of chat previews. Confirm that setting these fields to false by default aligns with the intended functionality and does not inadvertently affect chat preview behavior.
packages/embeds/js/src/features/blocks/inputs/fileUpload/components/FileUploadForm.tsx (1)
  • 59-60: The conditional assignment of apiHost using guessApiHost({ ignoreChatApiUrl: true }) when props.context.apiHost is falsy enhances the flexibility in determining the API host. Ensure this logic accurately reflects the intended behavior and does not lead to incorrect API host determination in any scenario.
packages/env/env.ts (1)
  • 98-98: The introduction of NEXT_PUBLIC_CHAT_API_URL as an environment variable allows for configurable chat API URLs. Ensure that this variable is correctly utilized throughout the application and that its presence or absence is handled appropriately in all scenarios where the chat API URL is needed.

packages/bot-engine/whatsapp/sendChatReplyToWhatsApp.ts Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 686802a and c63f3c5.
Files ignored due to path filters (5)
  • apps/chat-api/package.json is excluded by: !**/*.json
  • apps/chat-api/tsconfig.json is excluded by: !**/*.json
  • apps/viewer/package.json is excluded by: !**/*.json
  • package.json is excluded by: !**/*.json
  • pnpm-lock.yaml is excluded by: !**/*.yaml
Files selected for processing (17)
  • apps/chat-api/src/runtimes/api/app.ts (1 hunks)
  • apps/chat-api/src/runtimes/whatsapp/app.ts (1 hunks)
  • apps/viewer/src/app/api/v1/sessions/[sessionId]/streamMessage/route.ts (1 hunks)
  • apps/viewer/src/features/chat/api/continueChat.ts (2 hunks)
  • apps/viewer/src/features/chat/api/saveClientLogs.ts (2 hunks)
  • apps/viewer/src/features/chat/api/startChat.ts (2 hunks)
  • apps/viewer/src/features/chat/api/startChatPreview.ts (2 hunks)
  • apps/viewer/src/features/chat/api/updateTypebotInSession.ts (2 hunks)
  • packages/bot-engine/apiHandlers/continueChat.ts (1 hunks)
  • packages/bot-engine/apiHandlers/getMessageStream.ts (1 hunks)
  • packages/bot-engine/apiHandlers/legacy/getOpenAIChatCompletionStream.ts (1 hunks)
  • packages/bot-engine/apiHandlers/receiveMessage.ts (1 hunks)
  • packages/bot-engine/apiHandlers/receiveMessagePreview.ts (1 hunks)
  • packages/bot-engine/apiHandlers/saveClientLogs.ts (1 hunks)
  • packages/bot-engine/apiHandlers/startChat.ts (1 hunks)
  • packages/bot-engine/apiHandlers/startChatPreview.ts (1 hunks)
  • packages/bot-engine/apiHandlers/updateTypebotInSession.ts (1 hunks)
Files skipped from review as they are similar to previous changes (7)
  • apps/chat-api/src/runtimes/api/app.ts
  • apps/chat-api/src/runtimes/whatsapp/app.ts
  • apps/viewer/src/app/api/v1/sessions/[sessionId]/streamMessage/route.ts
  • apps/viewer/src/features/chat/api/saveClientLogs.ts
  • apps/viewer/src/features/chat/api/startChat.ts
  • apps/viewer/src/features/chat/api/startChatPreview.ts
  • apps/viewer/src/features/chat/api/updateTypebotInSession.ts
Additional comments: 13
apps/viewer/src/features/chat/api/continueChat.ts (2)
  • 4-4: The import of continueChat as continueChatFn from @typebot.io/bot-engine/apiHandlers/continueChat is correctly done to avoid naming conflicts with the local continueChat function. This is a good practice.
  • 25-32: The mutation logic correctly handles the response from continueChatFn, including setting CORS headers if corsOrigin is present in the response. This is a good implementation for handling cross-origin requests securely. However, ensure that the CORS policy aligns with the application's security requirements.
packages/bot-engine/apiHandlers/receiveMessagePreview.ts (1)
  • 11-15: The error handling for the absence of WHATSAPP_PREVIEW_FROM_PHONE_NUMBER_ID in the environment variables is correctly implemented, throwing a TRPCError with an appropriate message. This ensures that the function does not proceed without necessary configuration.
packages/bot-engine/apiHandlers/receiveMessage.ts (1)
  • 25-34: The logic to proceed only if a phoneNumberId is found is correctly implemented, returning an appropriate message if not found. This ensures that the function does not proceed without necessary information, which is crucial for identifying the session.
packages/bot-engine/apiHandlers/saveClientLogs.ts (2)
  • 13-20: The check for the existence of a session and throwing a TRPCError if not found is correctly implemented. This ensures that logs are not attempted to be saved for a non-existent session.
  • 24-29: The check for the existence of a resultId in the session's state and throwing a TRPCError if not found is correctly implemented. This is important for ensuring that logs are associated with a specific result within a session.
packages/bot-engine/apiHandlers/startChatPreview.ts (1)
  • 16-77: The startChatPreview function correctly orchestrates the session start process, including handling the case where only registration is required and saving the session state to the database. The use of conditional logic to determine the session handling based on isOnlyRegistering is well-implemented. However, ensure that the restartSession and saveStateToDatabase functions properly handle all edge cases and potential errors to maintain data integrity.
packages/bot-engine/apiHandlers/legacy/getOpenAIChatCompletionStream.ts (2)
  • 25-28: The decryption of OpenAI credentials is correctly implemented using decryptV2. Ensure that the encryption and decryption processes are secure and that the encryption keys are managed securely.
  • 50-57: The creation of the OpenAI chat completion stream is correctly implemented, including handling of default model and temperature settings. However, ensure that error handling is robust, especially for potential API errors from OpenAI, to gracefully handle and log such failures.
packages/bot-engine/apiHandlers/startChat.ts (1)
  • 16-90: The startChat function correctly orchestrates the session start process, including handling CORS origins and filtering potentially sensitive logs. The logic to determine corsOrigin based on allowed origins and the request origin is well-implemented. Ensure that CORS policies are correctly configured to prevent unauthorized cross-origin requests. Additionally, the filtering of potentially sensitive logs is a good practice for privacy and security.
packages/bot-engine/apiHandlers/continueChat.ts (1)
  • 14-85: The continueChat function correctly handles the continuation of a chat session, including session expiration checks, CORS origin handling, and updating the session state in the database. The logic to determine if a session is expired and to set the corsOrigin is well-implemented. Ensure that the session expiration logic aligns with the application's requirements and that CORS policies are correctly configured. Additionally, consider adding more robust error handling and logging throughout the function to aid in debugging and operational monitoring.
packages/bot-engine/apiHandlers/updateTypebotInSession.ts (1)
  • 16-60: The updateTypebotInSession function correctly updates the Typebot within a session, including authorization checks and updating the session state in the database. The use of Prisma to query and update the database is correctly implemented. Ensure that the authorization logic is comprehensive and secure, preventing unauthorized users from updating Typebot configurations. Additionally, consider adding more detailed error handling and logging to provide better insights into operation failures.
packages/bot-engine/apiHandlers/getMessageStream.ts (1)
  • 21-122: The getMessageStream function correctly handles the retrieval of message streams for different types of blocks, including OpenAI integration blocks. The logic to decrypt credentials and handle different block types is well-implemented. However, ensure that error handling is robust, especially for potential API errors and decryption failures, to gracefully handle and log such failures. Additionally, consider validating the block options and credentials to ensure they meet the expected format before proceeding with the operation.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c63f3c5 and f13639d.
Files ignored due to path filters (13)
  • apps/builder/package.json is excluded by: !**/*.json
  • apps/chat-api/package.json is excluded by: !**/*.json
  • apps/docs/package.json is excluded by: !**/*.json
  • apps/viewer/package.json is excluded by: !**/*.json
  • package.json is excluded by: !**/*.json
  • packages/deprecated/bot-engine/package.json is excluded by: !**/*.json
  • packages/deprecated/typebot-js/package.json is excluded by: !**/*.json
  • packages/emails/package.json is excluded by: !**/*.json
  • packages/embeds/js/package.json is excluded by: !**/*.json
  • packages/embeds/wordpress/package.json is excluded by: !**/*.json
  • packages/prisma/package.json is excluded by: !**/*.json
  • pnpm-lock.yaml is excluded by: !**/*.yaml
  • pnpm-workspace.yaml is excluded by: !**/*.yaml
Files selected for processing (17)
  • .github/workflows/check-and-report-chats-usage.yml (1 hunks)
  • .github/workflows/clean-database.yml (1 hunks)
  • .github/workflows/publish-lib-to-npm.yml (1 hunks)
  • .github/workflows/publish-typebot-js.yml (1 hunks)
  • .github/workflows/publish-typebot-nextjs.yml (1 hunks)
  • .github/workflows/publish-typebot-react.yml (1 hunks)
  • .husky/pre-commit (1 hunks)
  • Dockerfile (4 hunks)
  • apps/builder/.prettierignore (1 hunks)
  • apps/docs/contribute/guides/create-block.mdx (1 hunks)
  • apps/docs/contribute/guides/documentation.mdx (1 hunks)
  • apps/docs/contribute/guides/local-installation.mdx (3 hunks)
  • apps/docs/self-hosting/deploy/manual.mdx (2 hunks)
  • apps/docs/self-hosting/deploy/vercel.mdx (2 hunks)
  • apps/docs/self-hosting/guides/planetscale.mdx (1 hunks)
  • packages/forge/cli/index.ts (1 hunks)
  • packages/lib/playwright/baseConfig.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • apps/builder/.prettierignore
Additional comments: 30
.husky/pre-commit (1)
  • 4-4: The script uses bun lint && bun format:check which assumes specific scripts are defined in the package.json. Verify these scripts exist and are correctly configured for bun.
.github/workflows/publish-typebot-js.yml (1)
  • 15-18: The workflow has been updated to use bun for package management and build tasks. Ensure that all bun commands are compatible with the project's configuration and that the bun environment is correctly set up in the CI environment.
.github/workflows/publish-typebot-react.yml (1)
  • 15-18: Similar to the previous workflow, confirm that bun commands are correctly configured and that the CI environment supports bun.
.github/workflows/publish-typebot-nextjs.yml (1)
  • 15-18: Again, ensure bun commands are properly set up and compatible with the project's setup, and verify the CI environment's compatibility with bun.
.github/workflows/clean-database.yml (1)
  • 20-22: Check that the bun turbo run db:cleanDatabase command is correctly implemented in the project and that bun is properly configured in the CI environment for database cleaning tasks.
.github/workflows/publish-lib-to-npm.yml (1)
  • 15-22: Ensure that the bun commands and the bun config set command for setting the NPM_TOKEN are correctly used and that the CI environment is set up to support bun.
apps/docs/self-hosting/guides/planetscale.mdx (1)
  • 10-10: Confirm that the bun db:push command is correctly documented and that users are aware of any prerequisites or configurations needed to use bun for database operations.
packages/lib/playwright/baseConfig.ts (1)
  • 19-19: Verify that the bun start command is correctly configured in the project to be used with Playwright tests and that the environment supports bun.
.github/workflows/check-and-report-chats-usage.yml (1)
  • 32-34: Ensure that the bun commands are correctly set up for the script execution in the CI environment and that bun is properly configured for running the checkAndReportChatsUsage task.
apps/docs/contribute/guides/documentation.mdx (1)
  • 46-46: Confirm that the bun dev command is correctly documented for running the docs in dev mode and that users are aware of any prerequisites or configurations needed to use bun.
apps/docs/contribute/guides/local-installation.mdx (5)
  • 14-14: Ensure that the documentation correctly guides users to install the Bun CLI and that the link provided is accessible and accurate.
  • 22-22: Verify that the bun i command for installing dependencies is correctly documented and that users are aware of any prerequisites or configurations needed to use bun.
  • 38-38: Confirm that the bun dev command for starting the project in dev mode is correctly documented and that users are aware of any prerequisites or configurations needed to use bun.
  • 55-55: Ensure that the bun dev command for starting the landing page in dev mode is correctly documented and that users are aware of any prerequisites or configurations needed to use bun.
  • 62-62: Verify that the bun dev command for starting the docs in dev mode is correctly documented and that users are aware of any prerequisites or configurations needed to use bun.
Dockerfile (6)
  • 1-1: Ensure that the base image oven/bun is compatible with the project's requirements and that all necessary dependencies are correctly installed.
  • 13-13: Confirm that the bun --global install turbo command is correctly used for installing turbo globally in the Docker image.
  • 22-25: Verify that the file copying paths and dependencies are correctly adjusted for the bun environment and that all necessary files are included in the Docker image.
  • 29-29: Ensure that the bun turbo run build command is correctly configured for building the project within the Docker image.
  • 39-40: Check that the copying of next-runtime-env and its dependencies is correctly handled for runtime public variable injection in the Docker image.
  • 44-45: Confirm that the Prisma package and its dependencies are correctly copied and that the schema generation command is properly configured in the Docker image.
apps/docs/self-hosting/deploy/vercel.mdx (2)
  • 48-48: Verify that the bun turbo build --filter=builder... && bun db:migrate command is correctly documented for building and migrating the database when deploying the builder on Vercel.
  • 63-63: Ensure that the bun turbo build --filter=viewer... && bun db:migrate command is correctly documented for building and migrating the database when deploying the viewer on Vercel.
apps/docs/self-hosting/deploy/manual.mdx (6)
  • 38-38: Confirm that the documentation correctly guides users to install the Bun CLI for manual deployment and that the link provided is accessible and accurate.
  • 48-48: Ensure that the bun prisma generate && bun db:migrate command for database setup and migration is correctly documented for manual deployment.
  • 54-54: Verify that the bun install command for installing dependencies is correctly documented for manual deployment.
  • 60-60: Confirm that the bun run build:apps command for building the apps is correctly documented for manual deployment.
  • 75-81: Ensure that the bun start command and its usage for deploying the builder with PM2 are correctly documented for manual deployment.
  • 94-100: Verify that the bun start command and its usage for deploying the viewer with PM2 are correctly documented for manual deployment.
packages/forge/cli/index.ts (1)
  • 90-90: Confirm that the bun install command is correctly used in the CLI tool for installing dependencies and that it is compatible with the project's setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate chat API to a standalone server
1 participant