-
Notifications
You must be signed in to change notification settings - Fork 620
[AI-SDK-provider] Add default in-memory session store with custom store option #8211
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
[AI-SDK-provider] Add default in-memory session store with custom store option #8211
Conversation
🦋 Changeset detectedLatest commit: c4c3303 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
WalkthroughAdds a SessionStore interface, a concrete InMemorySessionStore implementation and a shared singleton, exposes SessionStore in public exports, and lets ThirdwebProvider default to a provided sessionStore or the in-memory singleton. Also updates ThirdwebConfig to accept sessionStore, a small UI width tweak, and a changeset entry. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor App
participant Provider as ThirdwebProvider
participant Cfg as ThirdwebConfig
participant Store as SessionStore
participant Mem as memorySessionStore (InMemorySessionStore)
App->>Provider: new ThirdwebProvider(Cfg)
alt Cfg.sessionStore provided
Provider->>Store: use provided sessionStore
else no sessionStore
Provider->>Mem: use memorySessionStore (singleton)
end
App->>Provider: getSessionId(chatId)
Provider->>Store: getSessionId(chatId)
Store-->>Provider: sessionId | null
Provider-->>App: sessionId | null
note right of Store: Interface: getSessionId(chatId): string|null\nsetSessionId(chatId, sessionId): void\nclearSessionId(chatId): void
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8211 +/- ##
=======================================
Coverage 55.04% 55.04%
=======================================
Files 919 919
Lines 60569 60569
Branches 4127 4127
=======================================
Hits 33338 33338
Misses 27127 27127
Partials 104 104
🚀 New features to boost your workflow:
|
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (5)
.changeset/eleven-kings-fix.md(1 hunks)apps/playground-web/src/app/ai/ai-sdk/components/chat-container.tsx(1 hunks)packages/ai-sdk-provider/src/exports/thirdweb.ts(1 hunks)packages/ai-sdk-provider/src/provider.ts(2 hunks)packages/ai-sdk-provider/src/types.ts(2 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each file to one stateless, single-responsibility function for clarity
Re-use shared types from@/typesor localtypes.tsbarrels
Prefer type aliases over interface except for nominal shapes
Avoidanyandunknownunless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial,Pick, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose
**/*.{ts,tsx}: Use explicit function declarations and explicit return types in TypeScript
Limit each file to one stateless, single‑responsibility function
Re‑use shared types from@/typeswhere applicable
Prefertypealiases overinterfaceexcept for nominal shapes
Avoidanyandunknownunless unavoidable; narrow generics when possible
Prefer composition over inheritance; use utility types (Partial, Pick, etc.)
Lazy‑import optional features and avoid top‑level side‑effects to reduce bundle size
Files:
packages/ai-sdk-provider/src/exports/thirdweb.tspackages/ai-sdk-provider/src/provider.tsapps/playground-web/src/app/ai/ai-sdk/components/chat-container.tsxpackages/ai-sdk-provider/src/types.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Load heavy dependencies inside async paths to keep initial bundle lean (lazy loading)
Files:
packages/ai-sdk-provider/src/exports/thirdweb.tspackages/ai-sdk-provider/src/provider.tsapps/playground-web/src/app/ai/ai-sdk/components/chat-container.tsxpackages/ai-sdk-provider/src/types.ts
.changeset/*.md
📄 CodeRabbit inference engine (AGENTS.md)
.changeset/*.md: Each change inpackages/*must include a changeset for the appropriate package
Version bump rules: patch for non‑API changes; minor for new/modified public API
Files:
.changeset/eleven-kings-fix.md
apps/{dashboard,playground-web}/**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
apps/{dashboard,playground-web}/**/*.{ts,tsx}: Import UI primitives from@/components/ui/*(Button, Input, Select, Tabs, Card, Sidebar, Badge, Separator) in dashboard and playground apps
UseNavLinkfor internal navigation with automatic active states in dashboard and playground apps
Use Tailwind CSS only – no inline styles or CSS modules
Usecn()from@/lib/utilsfor conditional class logic
Use design system tokens (e.g.,bg-card,border-border,text-muted-foreground)
Server Components (Node edge): Start files withimport "server-only";
Client Components (browser): Begin files with'use client';
Always callgetAuthToken()to retrieve JWT from cookies on server side
UseAuthorization: Bearerheader – never embed tokens in URLs
Return typed results (e.g.,Project[],User[]) – avoidany
Wrap client-side data fetching calls in React Query (@tanstack/react-query)
Use descriptive, stablequeryKeysfor React Query cache hits
ConfigurestaleTime/cacheTimein React Query based on freshness (default ≥ 60s)
Keep tokens secret via internal API routes or server actions
Never importposthog-jsin server components
Files:
apps/playground-web/src/app/ai/ai-sdk/components/chat-container.tsx
**/types.ts
📄 CodeRabbit inference engine (AGENTS.md)
Provide and re‑use local type barrels in a
types.tsfile
Files:
packages/ai-sdk-provider/src/types.ts
🧬 Code graph analysis (2)
packages/ai-sdk-provider/src/provider.ts (1)
packages/ai-sdk-provider/src/exports/thirdweb.ts (1)
SessionStore(4-4)
packages/ai-sdk-provider/src/types.ts (1)
packages/ai-sdk-provider/src/provider.ts (1)
SessionStore(584-588)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Size
- GitHub Check: Analyze (javascript)
🔇 Additional comments (7)
apps/playground-web/src/app/ai/ai-sdk/components/chat-container.tsx (1)
79-79: LGTM!The max-width constraint appropriately limits the reasoning block width for better readability.
packages/ai-sdk-provider/src/provider.ts (4)
584-588: LGTM!The SessionStore interface is well-designed with clear method signatures and explicit return types. The three-method contract provides a clean abstraction for session persistence.
590-602: LGTM!The InMemorySessionStore implementation correctly uses Map for storage, with proper null handling in
getSessionIdand explicit return types on all methods.
604-605: LGTM!The singleton pattern is appropriate for sharing session state across multiple ThirdwebProvider instances, aligning with the PR objective of a default in-memory store.
547-547: LGTM!The fallback pattern correctly uses the provided sessionStore from config or defaults to the shared memorySessionStore singleton.
packages/ai-sdk-provider/src/types.ts (1)
9-9: LGTM!The SessionStore import is correctly placed, and the optional sessionStore property is well-documented, clearly explaining the fallback to the default in-memory store.
Also applies to: 30-34
packages/ai-sdk-provider/src/exports/thirdweb.ts (1)
1-5: LGTM!The SessionStore type export is correctly added to the public API surface, following the existing export pattern and making the interface available to package consumers.
size-limit report 📦
|
b648b71 to
c4c3303
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/ai-sdk-provider/src/provider.ts (1)
590-602: Consider documenting unbounded growth behavior.The InMemorySessionStore implementation is correct but uses an unbounded Map that will grow indefinitely. For development or simple use cases this is fine, but consider adding a JSDoc comment noting that this store has no eviction policy and users with long-running applications should implement their own SessionStore with appropriate memory management.
Example documentation:
+/** + * In-memory session store implementation. + * Note: This store has no eviction policy and will grow unbounded. + * For production use with long-running applications, consider implementing + * a custom SessionStore with appropriate memory management. + */ class InMemorySessionStore implements SessionStore {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (5)
.changeset/eleven-kings-fix.md(1 hunks)apps/playground-web/src/app/ai/ai-sdk/components/chat-container.tsx(1 hunks)packages/ai-sdk-provider/src/exports/thirdweb.ts(1 hunks)packages/ai-sdk-provider/src/provider.ts(2 hunks)packages/ai-sdk-provider/src/types.ts(2 hunks)
✅ Files skipped from review due to trivial changes (1)
- .changeset/eleven-kings-fix.md
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/playground-web/src/app/ai/ai-sdk/components/chat-container.tsx
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each file to one stateless, single-responsibility function for clarity
Re-use shared types from@/typesor localtypes.tsbarrels
Prefer type aliases over interface except for nominal shapes
Avoidanyandunknownunless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial,Pick, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose
**/*.{ts,tsx}: Use explicit function declarations and explicit return types in TypeScript
Limit each file to one stateless, single‑responsibility function
Re‑use shared types from@/typeswhere applicable
Prefertypealiases overinterfaceexcept for nominal shapes
Avoidanyandunknownunless unavoidable; narrow generics when possible
Prefer composition over inheritance; use utility types (Partial, Pick, etc.)
Lazy‑import optional features and avoid top‑level side‑effects to reduce bundle size
Files:
packages/ai-sdk-provider/src/types.tspackages/ai-sdk-provider/src/provider.tspackages/ai-sdk-provider/src/exports/thirdweb.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Load heavy dependencies inside async paths to keep initial bundle lean (lazy loading)
Files:
packages/ai-sdk-provider/src/types.tspackages/ai-sdk-provider/src/provider.tspackages/ai-sdk-provider/src/exports/thirdweb.ts
**/types.ts
📄 CodeRabbit inference engine (AGENTS.md)
Provide and re‑use local type barrels in a
types.tsfile
Files:
packages/ai-sdk-provider/src/types.ts
🧬 Code graph analysis (2)
packages/ai-sdk-provider/src/types.ts (1)
packages/ai-sdk-provider/src/provider.ts (1)
SessionStore(584-588)
packages/ai-sdk-provider/src/provider.ts (1)
packages/ai-sdk-provider/src/exports/thirdweb.ts (1)
SessionStore(3-3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Lint Packages
- GitHub Check: E2E Tests (pnpm, webpack)
- GitHub Check: Size
- GitHub Check: Analyze (javascript)
🔇 Additional comments (6)
packages/ai-sdk-provider/src/types.ts (2)
2-2: LGTM!Type-only import is correctly used for the SessionStore interface.
30-34: LGTM!The sessionStore property is well-documented and correctly typed. The JSDoc clearly explains the default behavior and the optional nature aligns with the PR's intent to provide flexibility.
packages/ai-sdk-provider/src/provider.ts (3)
584-588: LGTM!The SessionStore interface is well-designed with explicit return types and provides a clear contract for session management. Using an interface here is appropriate for defining this behavioral contract.
604-605: LGTM!The singleton pattern is appropriate here for providing a shared default session store across all ThirdwebProvider instances.
547-547: LGTM!The fallback pattern correctly uses the provided session store or defaults to the shared in-memory store.
packages/ai-sdk-provider/src/exports/thirdweb.ts (1)
1-5: LGTM!The SessionStore type export is correctly structured and consistent with the existing exports, enabling consumers to implement custom session stores.

PR-Codex overview
This PR introduces a default in-memory session store for
thirdweb AIinstances and allows users to pass their own session store. It also updates theThirdwebProviderand related types to accommodate this new functionality.Detailed summary
thirdweb AI.ThirdwebConfigto include an optionalsessionStore.ThirdwebProviderto use the providedsessionStoreor default to in-memory store.SessionStorefrom a class to an interface.InMemorySessionStoreclass implementingSessionStoremethods.Summary by CodeRabbit