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

Feat/cloudflare kv support #2642

Draft
wants to merge 35 commits into
base: main
Choose a base branch
from

Conversation

Mrinank-Bhowmick
Copy link
Contributor

@Mrinank-Bhowmick Mrinank-Bhowmick commented Feb 28, 2025

Fixes #2504
Some changes that needs to be reviewed -
I imported { TABLE_THREADS } from '@mastra/core/storage' directly, because MastraStorage.TABLE_THREADS was showing deprecated.

VSCode Warning VSCode Warning

Some helper functions that were done because of REST API implementation.

Functionality Cloudflare KV Upstash Redis
Get Value getKV(key) redis.get(key)
Set Value putKV(key, value) redis.set(key, value)
Delete Key deleteKV(key) redis.del(key)
List Keys listKV(prefix) redis.keys(pattern)
Sorted Set (Order) Custom JSON handling zadd, zrank, zrange
Workflow Snapshot putKV, getKV (JSON) redis.set, redis.get

Note: I took some help from chatgpt to structure this code for clarity, but I ensured the correctness of the mappings based on my understanding.

Copy link

codesandbox bot commented Feb 28, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

changeset-bot bot commented Feb 28, 2025

🦋 Changeset detected

Latest commit: b550643

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@mastra/cloudflare Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Feb 28, 2025

@Mrinank-Bhowmick is attempting to deploy a commit to the Mastra Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

promptless bot commented Feb 28, 2025

📝 Documentation updates detected! You can review documentation updates here

@NikAiyer NikAiyer self-requested a review February 28, 2025 19:26
Copy link
Collaborator

@NikAiyer NikAiyer left a comment

Choose a reason for hiding this comment

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

Can you add some tests, docs, and a README for this storage class? You can use cursor to follow the examples set by other storage classes.

@Mrinank-Bhowmick Mrinank-Bhowmick marked this pull request as draft March 1, 2025 05:20
@Mrinank-Bhowmick
Copy link
Contributor Author

Can you add some tests, docs, and a README for this storage class? You can use cursor to follow the examples set by other storage classes.

Thanks for the review! I will make those changes, but I need some time as I am currently busy with my exams. Once they are over, I will resume work aggressively.

@smorimoto
Copy link
Contributor

Thanks a lot for this!

@Mrinank-Bhowmick
Copy link
Contributor Author

@NikAiyer
I tried but for some reason, i dont know why _mastra_threads giving error, other than that everything was fine.

/examples/memory-with-libsql
image

Cloudflare KV
image

@Mrinank-Bhowmick Mrinank-Bhowmick marked this pull request as ready for review March 11, 2025 17:29
Copy link

promptless bot commented Mar 11, 2025

📝 Documentation updates detected! You can review documentation updates here

Copy link
Contributor

@TylerBarnes TylerBarnes left a comment

Choose a reason for hiding this comment

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

Looking good! Needs tests though :) Cursor or windsurf can write them. Copy the upstash ones from stores/upstash/src/storage/upstash.test.ts and tell cursor that you copied those tests from upstash and it needs to update them to test cloudflare/src/storage/index.ts

@NikAiyer NikAiyer marked this pull request as draft March 17, 2025 17:36
Copy link

New, updated, and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@ai-sdk/anthropic@1.1.15 None +2 5.08 MB vercel-release-bot
npm/@ai-sdk/anthropic@1.1.17 None +2 5.08 MB vercel-release-bot
npm/@ai-sdk/cohere@1.1.15 None +2 4.64 MB vercel-release-bot
npm/@ai-sdk/fireworks@0.1.14 None +3 4.85 MB vercel-release-bot
npm/@ai-sdk/groq@1.1.14 None +2 4.63 MB vercel-release-bot
npm/@ai-sdk/openai@1.1.151.2.1 None +2 5.17 MB vercel-release-bot
npm/@ai-sdk/openai@1.1.151.2.5 None +2 5.48 MB vercel-release-bot
npm/@ai-sdk/react@1.1.21 None +6 9.96 MB jaredpalmer, vercel-release-bot
npm/@assistant-ui/react-markdown@0.7.21 None 0 188 kB yonom
npm/@assistant-ui/react-syntax-highlighter@0.7.10 None 0 15.7 kB yonom
npm/@assistant-ui/react-ui@0.1.8 None 0 714 kB yonom
npm/@assistant-ui/react@0.7.85 environment, network +1 3.96 MB yonom
npm/@assistant-ui/react@0.7.91 environment, network +1 4.01 MB yonom
npm/@babel/core@7.26.9 environment, filesystem, unsafe +13 7.86 MB nicolo-ribaudo
npm/@babel/helper-module-imports@7.25.9 Transitive: environment +8 5.98 MB nicolo-ribaudo
npm/@babel/preset-env@7.26.9 Transitive: environment +82 8.09 MB existentialism, hzoo, jlhwung, ...1 more
npm/@babel/preset-typescript@7.26.0 Transitive: environment +21 6.87 MB nicolo-ribaudo
npm/@changesets/cli@2.28.1 Transitive: environment, filesystem +20 1.14 MB andarist, changesets-release-bot, emmatown, ...1 more
npm/@clack/prompts@0.8.2 None +1 421 kB natemoo-re
npm/@cloudflare/workers-types@4.20250313.0 None 0 0 B
npm/@codemirror/lang-json@6.0.1 Transitive: environment +7 2.34 MB marijn
npm/@dagrejs/dagre@1.1.4 None +1 489 kB davidnewell
npm/@datastax/astra-db-ts@1.5.0 eval, network 0 502 kB toptobes
npm/@deepgram/sdk@3.11.2 environment, network +1 1.09 MB deepgramai
npm/@eslint/eslintrc@3.3.0 None 0 0 B
npm/@google-cloud/speech@6.7.1 environment +3 6.91 MB google-wombot
npm/@google-cloud/text-to-speech@5.8.1 environment 0 2.98 MB google-wombot
npm/@hey-api/client-fetch@0.3.4 None 0 118 kB mrlubos
npm/@hono/node-server@1.13.8 network 0 172 kB yusukebe
npm/@hono/swagger-ui@0.5.1 None 0 21.2 kB yusukebe
npm/@hookform/resolvers@3.10.0 None 0 711 kB bluebill1049, jorisre, kotarella1110
npm/@inquirer/prompts@7.3.3 Transitive: environment +13 361 kB sboudrias
npm/@jest/globals@29.7.0 None +5 91.5 kB simenb
npm/@lezer/highlight@1.2.1 None +1 338 kB marijn
npm/@libsql/client@0.14.0 Transitive: network +4 484 kB penberg
npm/@llamaindex/core@0.4.23 Transitive: environment, eval +1 3.16 MB himself_65
npm/@llamaindex/env@0.1.29 environment +3 1.69 MB himself_65
npm/@lukeed/uuid@2.0.1 None +1 15.7 kB lukeed
npm/@microsoft/api-extractor@7.52.1 Transitive: filesystem +3 5.75 MB microsoft1es, odspnpm
npm/@modelcontextprotocol/sdk@1.7.0 None 0 3.64 MB jspahrsummers
npm/@neon-rs/load@0.1.82 None 0 10.7 kB dherman
npm/@next/env@13.5.8, 14.2.2215.2.2 None 0 0 B
npm/@opentelemetry/api@1.9.0 None 0 1.22 MB pichlermarc
npm/@opentelemetry/auto-instrumentations-node@0.56.1 environment 0 77.8 kB dyladan
npm/@opentelemetry/core@1.30.1 environment, unsafe 0 909 kB dyladan

🚮 Removed packages: npm/@types/node@20.17.19, npm/@types/react-dom@18.3.5, npm/@types/react@18.3.18, npm/@vercel/analytics@1.5.0, npm/clsx@2.1.1, npm/eslint-config-next@14.2.14, npm/eslint@8.57.1, npm/lucide-react@0.436.0, npm/next-sitemap@4.2.3, npm/next@14.2.22, npm/nextra-theme-docs@3.3.1, npm/nextra@3.3.1, npm/react-dom@18.3.1, npm/react@18.3.1, npm/tailwind-merge@2.6.0, npm/tailwindcss@3.4.17, npm/tsx@4.19.3

View full report↗︎

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.

Support for Cloudflare KV
4 participants