Skip to content

Conversation

@joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented Oct 7, 2025


PR-Codex overview

This PR introduces a default in-memory session store for thirdweb AI instances and allows users to pass their own session store. It also updates the ThirdwebProvider and related types to accommodate this new functionality.

Detailed summary

  • Added a default in-memory session store for thirdweb AI.
  • Updated ThirdwebConfig to include an optional sessionStore.
  • Modified ThirdwebProvider to use the provided sessionStore or default to in-memory store.
  • Changed SessionStore from a class to an interface.
  • Introduced InMemorySessionStore class implementing SessionStore methods.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features
    • Default shared in-memory session store for AI sessions with an option to provide a custom session store.
    • Exported SessionStore type to support custom implementations.
  • Style
    • Reasoning panel constrained to a maximum width for improved readability.
  • Chores
    • Added changeset entry for a patch release of the AI SDK provider.

@changeset-bot
Copy link

changeset-bot bot commented Oct 7, 2025

🦋 Changeset detected

Latest commit: c4c3303

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

This PR includes changesets to release 1 package
Name Type
@thirdweb-dev/ai-sdk-provider 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

@vercel
Copy link

vercel bot commented Oct 7, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
docs-v2 Ready Ready Preview Comment Oct 7, 2025 9:02am
nebula Ready Ready Preview Comment Oct 7, 2025 9:02am
thirdweb_playground Ready Ready Preview Comment Oct 7, 2025 9:02am
thirdweb-www Ready Ready Preview Comment Oct 7, 2025 9:02am
wallet-ui Ready Ready Preview Comment Oct 7, 2025 9:02am

@github-actions github-actions bot added Playground Changes involving the Playground codebase. packages labels Oct 7, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 7, 2025

Walkthrough

Adds 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

Cohort / File(s) Summary of changes
Session store implementation & provider defaulting
packages/ai-sdk-provider/src/provider.ts
Introduce exported SessionStore interface, add InMemorySessionStore implementation and memorySessionStore singleton; ThirdwebProvider initializes this.session from `config.sessionStore
Public types and exports
packages/ai-sdk-provider/src/types.ts, packages/ai-sdk-provider/src/exports/thirdweb.ts
Import and expose SessionStore; add optional sessionStore?: SessionStore to ThirdwebConfig; include type SessionStore in public exports.
Playground UI tweak
apps/playground-web/src/app/ai/ai-sdk/components/chat-container.tsx
Adjust Reasoning component className from w-full to w-full max-w-md (styling change only).
Release metadata
.changeset/eleven-kings-fix.md
Add changeset entry describing default shared in-memory session store and option to pass a custom session store.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description includes the unchanged commented-out template instructions and a PR-Codex overview but none of the required sections from the repository’s description template such as a formatted title, a Linear issue tag, Notes for the reviewer, or How to test are populated, so it does not conform to the expected structure or provide critical context for reviewers. Please remove the placeholder template comments and replace them with the actual content sections mandated by the repository template, including the formatted PR title, any relevant issue or ticket reference, a Notes for the reviewer section outlining context and important details, and a How to test section specifying testing steps.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title focuses on the primary change of adding a default in-memory session store with an option for a custom store and correctly uses the [AI-SDK-provider] prefix, making it clear and concise for reviewers.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch _AI-SDK_Add_default_in-memory_session_store_with_custom_store_option

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.

Comment @coderabbitai help to get the list of available commands and usage tips.

@joaquim-verges joaquim-verges changed the title [AI-SDK] Add default in-memory session store with custom store option [AI-SDK-provider] Add default in-memory session store with custom store option Oct 7, 2025
@joaquim-verges joaquim-verges marked this pull request as ready for review October 7, 2025 08:40
@joaquim-verges joaquim-verges requested review from a team as code owners October 7, 2025 08:40
@codecov
Copy link

codecov bot commented Oct 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.04%. Comparing base (68b48f4) to head (c4c3303).
⚠️ Report is 1 commits behind head on main.

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           
Flag Coverage Δ
packages 55.04% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@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.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between 68b48f4 and b648b71.

📒 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 @/types or local types.ts barrels
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless 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 @/types where applicable
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless 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.ts
  • packages/ai-sdk-provider/src/provider.ts
  • apps/playground-web/src/app/ai/ai-sdk/components/chat-container.tsx
  • packages/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.ts
  • packages/ai-sdk-provider/src/provider.ts
  • apps/playground-web/src/app/ai/ai-sdk/components/chat-container.tsx
  • packages/ai-sdk-provider/src/types.ts
.changeset/*.md

📄 CodeRabbit inference engine (AGENTS.md)

.changeset/*.md: Each change in packages/* 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
Use NavLink for internal navigation with automatic active states in dashboard and playground apps
Use Tailwind CSS only – no inline styles or CSS modules
Use cn() from @/lib/utils for conditional class logic
Use design system tokens (e.g., bg-card, border-border, text-muted-foreground)
Server Components (Node edge): Start files with import "server-only";
Client Components (browser): Begin files with 'use client';
Always call getAuthToken() to retrieve JWT from cookies on server side
Use Authorization: Bearer header – never embed tokens in URLs
Return typed results (e.g., Project[], User[]) – avoid any
Wrap client-side data fetching calls in React Query (@tanstack/react-query)
Use descriptive, stable queryKeys for React Query cache hits
Configure staleTime/cacheTime in React Query based on freshness (default ≥ 60s)
Keep tokens secret via internal API routes or server actions
Never import posthog-js in 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.ts file

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 getSessionId and 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.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 64.6 KB (0%) 1.3 s (0%) 189 ms (+120.28% 🔺) 1.5 s
thirdweb (cjs) 365.75 KB (0%) 7.4 s (0%) 763 ms (-1.32% 🔽) 8.1 s
thirdweb (minimal + tree-shaking) 5.73 KB (0%) 115 ms (0%) 89 ms (+2337.47% 🔺) 204 ms
thirdweb/chains (tree-shaking) 526 B (0%) 11 ms (0%) 27 ms (+1144.86% 🔺) 37 ms
thirdweb/react (minimal + tree-shaking) 19.13 KB (0%) 383 ms (0%) 66 ms (+1702.74% 🔺) 449 ms

Copy link
Contributor

@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.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between b648b71 and c4c3303.

📒 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 @/types or local types.ts barrels
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless 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 @/types where applicable
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless 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.ts
  • packages/ai-sdk-provider/src/provider.ts
  • packages/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.ts
  • packages/ai-sdk-provider/src/provider.ts
  • packages/ai-sdk-provider/src/exports/thirdweb.ts
**/types.ts

📄 CodeRabbit inference engine (AGENTS.md)

Provide and re‑use local type barrels in a types.ts file

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.

@joaquim-verges joaquim-verges merged commit 71a1e58 into main Oct 7, 2025
24 of 25 checks passed
@joaquim-verges joaquim-verges deleted the _AI-SDK_Add_default_in-memory_session_store_with_custom_store_option branch October 7, 2025 09:00
@joaquim-verges joaquim-verges mentioned this pull request Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages Playground Changes involving the Playground codebase.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants