Migrating AI: Removing Dependencies For A Leaner Core

by Editorial Team 54 views
Iklan Headers

Hey folks! Let's dive into a crucial step in our AI migration journey: removing AI dependencies from our core package. This is all about streamlining our code, reducing bundle sizes, and making things more efficient. This guide will walk you through the process, the tasks involved, and why it's a game-changer for our project.

The Goal: A Dependency-Free Core

The main objective here is straightforward: to eliminate all AI-related dependencies from the packages/core/package.json file. Why are we doing this? Well, it boils down to optimizing our application. By moving AI services to the agents-worker, we're creating a more modular and lightweight core package. This means a smaller bundle size, faster load times, and a more focused codebase. Ultimately, we're aiming for a more maintainable and scalable application. This task is the final step of the AI migration, designed to reduce the dash worker bundle size and improve overall performance. The migration involves moving AI services to the agents-worker, which handles all AI-related tasks separately. The core package, which is the heart of our application, should not be burdened with AI dependencies. It keeps the core package clean, efficient, and easier to manage. Imagine having a super-fast core, that is what we are aiming for.

To achieve this goal, we need to carefully remove all AI-related dependencies from the core package. This involves identifying and removing specific packages that are related to the AI services we have migrated to the agents-worker. We will then update the lockfile to reflect the changes, run type checks to ensure there are no errors, and lint our code to maintain code quality. After completing these steps, we'll verify that the dash bundle size has been reduced. This is a crucial step that ensures the changes have had the desired impact on the application's performance. By keeping the core package focused and free from unnecessary dependencies, we can achieve better efficiency and easier maintenance of our application.

Dependencies We're Saying Goodbye To

So, what exactly are we removing? Here's the hit list of dependencies we're waving goodbye to:

  • @ai-sdk/anthropic
  • @ai-sdk/google
  • @ai-sdk/openai
  • @openai/agents
  • agents
  • ai

These packages contain the AI-related functionalities that are now handled by the agents-worker. By removing them from the core package, we ensure that the core remains lean and focused on its primary responsibilities. Remember, our goal is to streamline the core, making it more efficient and easier to maintain. These dependencies, while essential, are no longer needed in the core package, so removing them is a necessary step towards optimizing our application. We're essentially decoupling the core from the AI services, which improves overall performance.

Prerequisites: The Road to Success

Before we dive into the tasks, let's make sure we've laid the groundwork. We need to have completed several prerequisite phases to ensure a smooth transition. Think of these as checkpoints along the way. They ensure that all necessary components are in place before we start removing dependencies. Here's a quick rundown:

  • Phase 1: Product link processing moved: This ensures that product link processing has been successfully migrated to the new system.
  • Phase 2: Image/vision services moved: All image and vision services must be transferred to the agents-worker.
  • Phase 3: Complex services moved: Complex services should also be migrated to ensure they are handled by the agents-worker.
  • Dash routes updated to use RPC: All dash routes must be updated to use RPC (Remote Procedure Call).
  • All typecheck passes: Make sure all type checks pass to ensure the codebase is free of errors. This is crucial for maintaining code quality.

Having these prerequisites completed ensures a smooth and efficient removal process. It also validates that all AI-related functionalities have been properly transferred to the agents-worker, making the core package ready for the dependency removal process. These are not merely tasks; they are essential preconditions that guarantee a successful transition and help maintain the stability and efficiency of our application. Each prerequisite ensures that the migration process is carried out correctly and that no critical functionality is lost during the removal process.

Task Breakdown: The How-To Guide

Alright, let's get into the nitty-gritty. Here's a step-by-step guide to removing the AI dependencies:

  1. Remove AI deps from packages/core/package.json: Open up the packages/core/package.json file and carefully remove all the dependencies listed above (the ones we're saying goodbye to). Make sure you're deleting the correct entries to avoid any issues.
  2. Run pnpm install to update lockfile: After removing the dependencies, run pnpm install. This command updates the lockfile to reflect the changes you've made. It's essential to ensure that the project dependencies are up-to-date and consistent.
  3. Run pnpm typecheck - should pass (no AI imports in core): This is crucial. Run the typecheck command to ensure that there are no type errors in your codebase. This step confirms that the core package no longer has any AI-related imports. A successful typecheck indicates that the dependency removal was successful.
  4. Run pnpm lint: Run the lint command to ensure that the code adheres to the project's coding standards and best practices. This step helps maintain code quality and consistency across the project.
  5. Verify dash bundle size reduced: After completing the steps above, check the dash bundle size to confirm that it has been reduced. This is a crucial step that validates the changes have had the desired impact on the application's performance. You can use various tools to measure the bundle size and confirm that it is indeed smaller. A reduced bundle size indicates that the core package is leaner and more efficient.

By following these tasks, you'll successfully remove the AI dependencies from the core package, contributing to a more optimized and efficient application. Each step is critical for ensuring that the migration is done correctly and that the application functions as expected. Remember, attention to detail is key in this process.

Important Note: Agent DOs

Here's a key point to keep in mind: Agent DOs (VideoGenAgent, StudioGenerationAgent, WorkspaceAgent) will stay in the core package, but they will run in the agents-worker at runtime. This means that while the core package will not have direct AI dependencies, the agents-worker will have its own AI dependencies to handle the execution of these agents. So, the agents themselves remain in the core, but their execution is offloaded to the agents-worker, which handles the AI-related tasks. This design allows us to maintain a clean separation of concerns and ensure that the core package remains lightweight and focused.

Context: Why This Matters

This entire process is the final step in our AI migration, and its primary purpose is to reduce the dash worker bundle size. By removing AI dependencies from the core package, we are making the dash worker smaller, which leads to faster load times and improved performance. This is a critical step in optimizing our application and ensuring a better user experience. Think of it as a spring cleaning for our code, removing unnecessary clutter and making everything run smoother. In the end, we want a faster, more efficient, and more maintainable application. This means less code in the core, and everything running smoothly within the agents-worker framework. The goal is to create a more efficient and user-friendly platform. So, we're not just cleaning up code; we're also making our application better for everyone involved.