-
Notifications
You must be signed in to change notification settings - Fork 105
feat: add DatabaseTaskStore with Drizzle ORM support
#213
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @benclarkegithub, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the SDK's task management capabilities by introducing a robust, database-backed solution for task persistence. It allows applications to maintain task state across restarts and scale more effectively by offloading task storage from memory to a relational database. This change provides a critical feature for production deployments, ensuring task data integrity and availability. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
DatabaseTaskStore with Drizzle ORM supportDatabaseTaskStore with Drizzle ORM support
- Add `delete` method to TaskStore interface and InMemoryTaskStore - Add DatabaseTaskStore for persistent task storage using Drizzle ORM - Support SQLite, PostgreSQL, and MySQL databases - Export via new entry point `@a2a-js/sdk/server/drizzle` - Add drizzle-orm as optional peer dependency - Update README with installation and usage examples
6833f74 to
53d9491
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a DatabaseTaskStore for persistent task storage using Drizzle ORM, which is a great addition for production environments. The implementation supports SQLite, PostgreSQL, and MySQL, and the new feature is well-documented in the README with clear installation and usage instructions. The changes to the TaskStore interface and InMemoryTaskStore are also correct.
I have a couple of suggestions to improve the implementation in database_task_store.ts regarding a documentation example and improving type safety for better long-term maintainability. Overall, this is a solid contribution.
| * const sqlite = new Database('tasks.db'); | ||
| * const db = drizzle(sqlite); | ||
| * | ||
| * const taskStore = new DatabaseTaskStore(db, sqliteTasks); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example usage in the JSDoc for the DatabaseTaskStore constructor is incorrect. The constructor expects a single options object, but the example shows two arguments. Please update the example to match the constructor's signature and the examples in the README.
| * const taskStore = new DatabaseTaskStore(db, sqliteTasks); | |
| * const taskStore = new DatabaseTaskStore({ db, table: sqliteTasks, dialect: 'sqlite' }); |
| export type DrizzleDatabase = { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| select: () => SelectQueryBuilder<any>; | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| insert: <TTable = any>(table: TTable) => InsertQueryBuilder; | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| delete: <TTable = any>(table: TTable) => DeleteQueryBuilder; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the comment on lines 28-29 explains that this type is intentionally broad, using any throughout the related query builder types (lines 40-63) reduces type safety and leads to runtime checks for properties that could be verified at compile time (e.g., in the save method).
For improved maintainability, consider defining these types more strictly. Even without adding direct dependencies on DB drivers, you could use more specific structural types that better reflect the Drizzle API. This would enhance type safety and developer experience when using or extending this class.
|
Hi @benclarkegithub, thank you for the PR! Drizzle looks like a reasonable choice to me and overall I agree that providing DB-backed implementation out of the box is important. However there is one piece missing currently which in my opinion prevents us from developing a reasonable OOTB implementation. Task store has no access to authentication context, so it's not possible to attribute tasks to users started them. Adopting such schema currently is going to cause problems with migrating it later as backfilling won't be possible. Also it doesn't play well with There is a WIP support of authentication concept started in #195 (not released yet), it may require a few more things to work with DB properly:
Also adding a I am going to address authentication parts mentioned above and will get back to you so that we can discuss it further. Thank you! |
# Description Pass `ServerCallContext` to `TaskStore` to allow DB-backed stores. Enhance comments for `User`, stating that `userName` is a unique identifier. Re #213
|
Hi @benclarkegithub, with #235 A few more high-level questions to clarify:
|
deletemethod to TaskStore interface and InMemoryTaskStore@a2a-js/sdk/server/drizzleDescription
Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
CONTRIBUTINGGuide.fix:which represents bug fixes, and correlates to a SemVer patch.feat:represents a new feature, and correlates to a SemVer minor.feat!:, orfix!:,refactor!:, etc., which represent a breaking change (indicated by the!) and will result in a SemVer major.Fixes #114 🦕