Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@srkirkland
Copy link
Member

@srkirkland srkirkland commented Dec 17, 2025

Updates AI SDK and related dependencies to the latest versions.

  • Bumps @ai-sdk/openai to ^2.0.88 and @ai-sdk/rsc to ^1.0.117.
  • Updates ai to version 5.0.114.
  • Includes zod as a dependency.
  • Refactors codebase to use @ai-sdk/rsc for improved AI state management and actions.

Summary by CodeRabbit

  • Chores

    • Updated AI SDK and related dependencies to latest versions for improved stability and performance.
    • Added Zod for enhanced data validation.
  • Refactor

    • Improved internal type safety and consistency across chat and messaging systems.

✏️ Tip: You can customize this high-level summary in your review settings.

Updates AI SDK and related dependencies to the latest versions.

- Bumps `@ai-sdk/openai` to `^2.0.88` and `@ai-sdk/rsc` to `^1.0.117`.
- Updates `ai` to version `5.0.114`.
- Includes `zod` as a dependency.
- Refactors codebase to use `@ai-sdk/rsc` for improved AI state management and actions.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 17, 2025

Walkthrough

This PR upgrades AI SDK dependencies and migrates imports from the 'ai' package to the '@AI-SDK' namespace. It introduces a new ChatMessage type system, replacing the generic Message type throughout chat services, components, and utilities. API signatures across services are updated to use the new types, and the AI state structure is adjusted to nest focus within meta.

Changes

Cohort / File(s) Summary
Dependency Updates
web/package.json
Upgraded @ai-sdk/openai from ^0.0.29 to ^2.0.88, added @ai-sdk/rsc@^1.0.117, pinned ai to 5.0.114, and added [email protected].
Import Path Migrations
web/src/components/chat/answer/{chatActions, feedbackButtons, shareModal, wonkMessage}.tsx, web/src/components/chat/ask/{chatInput, defaultQuestions}.tsx, web/src/components/chat/main.tsx, web/src/lib/hooks/useStreamableText.ts
Updated import paths from 'ai/rsc' to '@ai-sdk/rsc' for hooks and utilities (useAIState, useActions, useUIState, StreamableValue, readStreamableValue). No logic changes.
Type Definitions
web/src/models/chat.ts
Added new ChatMessageRole type ('system' | 'user' | 'assistant'), new ChatMessage interface with id, role, and content fields, and updated ChatHistory.messages from Message[] to ChatMessage[].
Service Type Updates
web/src/services/{chatService, historyService, loggingService}.ts
Updated public API signatures to accept and return ChatMessage[] instead of Message[]; removed EmbeddingModelV1Embedding usage; added explicit return type annotations for getEmbeddings().
Internal Logic Updates
web/src/lib/{actions, aiProvider, util}.tsx
Swapped import sources to @ai-sdk/rsc, updated type references from Message to ChatMessage, adjusted AI state retrieval and mapping to use ChatHistory and nested meta.focus, converted some imports to type-only.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~28 minutes

  • Broad scope: 13+ files affected, but majority follows consistent import-migration pattern
  • Type system refactor: MessageChatMessage migration across services and utilities is pervasive but straightforward
  • Public API changes: Several service method signatures updated; verify all type migrations are complete and consistent
  • State structure change: Focus now nested in meta; verify aiProvider and service integrations handle this correctly

Areas requiring extra attention:

  • web/src/services/chatService.ts — multiple public API signatures changed; verify getEmbeddings, getSearchResultsElastic, and getSearchResultsPgSQL parameter/return types are used consistently across callers
  • web/src/lib/aiProvider.tsx — state shape changed (focus moved to meta); ensure type casting to ChatHistory works with actual AI state structure
  • web/src/lib/actions.tsx — type changes and removal of name property on message mappings; verify message transformation logic remains correct
  • Cross-file type consistency — ensure all files importing ChatMessage and using services receive properly typed messages

Possibly related PRs

Poem

🐰 A hop, a skip—deps take flight,

From ai to @ai-sdk bright!

Types refined, ChatMessage born,

Focus tucked in meta—reborn,

Messages flow, clean and right! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main objective: updating the AI SDK and its dependencies to newer versions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 srk/ai-sdk5

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

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 (2)
web/src/services/loggingService.ts (1)

91-105: Consider simplifying the message mapping.

Since ChatMessage already has exactly the properties being mapped (id, role, content), the explicit mapping is redundant. You could pass the messages directly or use a spread if you want to ensure a shallow copy.

   const chatLog: ChatLog = {
     user,
     llm_model: model,
     timestamp: new Date(),
-    messages: messages.map((m) => ({
-      id: m.id,
-      role: m.role,
-      content: m.content,
-    })),
+    messages: messages.map((m) => ({ ...m })),
     reaction: '',
     metadata: {
       vector: 'Elastic dense vector + cosine',
       chunk_strategy: 'recursive, large chunks',
     },
   };

Alternatively, if the Message type previously had additional properties that needed filtering, this explicit mapping makes sense as defensive coding against future type changes.

web/src/services/chatService.ts (1)

319-350: Consider using satisfies instead of as for type-safe object literals.

The object literals are cast to ChatMessage using as, but this bypasses TypeScript's type checking. While 'system' is valid for ChatMessageRole, using satisfies (available in TypeScript 4.9+, which this project uses) or explicit type constants would provide compile-time validation and better express intent:

+const SYSTEM_ROLE: ChatMessageRole = 'system';
+
 export const getSystemMessage = (docText: string) => {
   if (!docText) {
     return {
       id: '1',
-      role: 'system',
+      role: SYSTEM_ROLE,
       content:
         "Reply with: Sorry, I couldn't find enough information to answer your question",
-    } as ChatMessage;
+    } satisfies ChatMessage;

This ensures compile-time validation that all properties conform to ChatMessage without losing type inference.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1f0700c and 44c862d.

⛔ Files ignored due to path filters (1)
  • web/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (16)
  • web/package.json (3 hunks)
  • web/src/components/chat/answer/chatActions.tsx (1 hunks)
  • web/src/components/chat/answer/feedbackButtons.tsx (1 hunks)
  • web/src/components/chat/answer/shareModal.tsx (1 hunks)
  • web/src/components/chat/answer/wonkMessage.tsx (1 hunks)
  • web/src/components/chat/ask/chatInput.tsx (1 hunks)
  • web/src/components/chat/ask/defaultQuestions.tsx (1 hunks)
  • web/src/components/chat/main.tsx (1 hunks)
  • web/src/lib/actions.tsx (4 hunks)
  • web/src/lib/aiProvider.tsx (2 hunks)
  • web/src/lib/hooks/useStreamableText.ts (1 hunks)
  • web/src/lib/util.ts (1 hunks)
  • web/src/models/chat.ts (2 hunks)
  • web/src/services/chatService.ts (6 hunks)
  • web/src/services/historyService.ts (3 hunks)
  • web/src/services/loggingService.ts (4 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-07-26T21:01:50.746Z
Learnt from: laholstege
Repo: ucdavis/PolicyWonk PR: 6
File: src/app/auth/login/page.tsx:9-22
Timestamp: 2024-07-26T21:01:50.746Z
Learning: Using an asynchronous function in the `action` attribute is a standard pattern for server actions and mutations in Next.js's App Router, as per the Next.js documentation.

Applied to files:

  • web/src/components/chat/ask/chatInput.tsx
  • web/src/components/chat/answer/chatActions.tsx
🧬 Code graph analysis (5)
web/src/services/loggingService.ts (1)
web/src/models/chat.ts (1)
  • ChatMessage (7-11)
web/src/lib/util.ts (1)
web/src/models/chat.ts (1)
  • ChatMessage (7-11)
web/src/lib/aiProvider.tsx (2)
web/src/models/chat.ts (2)
  • ChatHistory (17-30)
  • ChatMessage (7-11)
web/src/components/chat/userMessage.tsx (1)
  • UserMessage (5-28)
web/src/services/historyService.ts (1)
web/src/models/chat.ts (1)
  • ChatMessage (7-11)
web/src/lib/actions.tsx (1)
web/src/models/chat.ts (1)
  • ChatMessage (7-11)
⏰ 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). (1)
  • GitHub Check: ucdavis.PolicyWonk (Build and push on main changes Build (always) / Push (main only))
🔇 Additional comments (24)
web/src/lib/hooks/useStreamableText.ts (1)

5-5: LGTM!

The import path migration from ai/rsc to @ai-sdk/rsc is consistent with the SDK upgrade. The hook logic and API remain unchanged.

web/src/components/chat/main.tsx (1)

4-4: LGTM!

The import migration to @ai-sdk/rsc is consistent with the broader SDK upgrade across the codebase.

web/src/components/chat/answer/chatActions.tsx (1)

4-4: LGTM!

The import migration is consistent with the SDK upgrade. The component logic remains unchanged.

web/src/components/chat/answer/shareModal.tsx (1)

4-4: LGTM!

The import migration to @ai-sdk/rsc is consistent with the SDK upgrade. Both useActions and useAIState are correctly imported from the new package path.

web/package.json (1)

16-17: All specified package versions exist and are accessible on npm.

This PR includes major version bumps and new dependencies:

  • @ai-sdk/openai: ^0.0.29^2.0.88 (latest)
  • ai: ^3.1.335.0.114 (latest is 5.0.115)
  • @ai-sdk/rsc: ^1.0.117 (new, latest)
  • zod: 3.25.76 (pinned to 3.x; note that zod 4.2.1 is available as a newer major version)

Verify that the major version upgrades do not introduce breaking changes, and consider whether staying on zod 3.x is intentional.

web/src/components/chat/answer/wonkMessage.tsx (1)

4-4: LGTM!

The import path migration from 'ai/rsc' to '@ai-sdk/rsc' is correct and aligns with the AI SDK upgrade.

web/src/components/chat/answer/feedbackButtons.tsx (1)

4-4: LGTM!

The import path migration is consistent with the AI SDK upgrade across the codebase.

web/src/components/chat/ask/defaultQuestions.tsx (1)

4-4: LGTM!

The import path migration and the updated property access (aiState.meta.focus) correctly reflect the new AI state structure where focus is nested within meta.

Also applies to: 17-17

web/src/components/chat/ask/chatInput.tsx (1)

4-4: LGTM!

The import path migration is consistent with the AI SDK upgrade.

web/src/lib/util.ts (1)

1-3: LGTM!

The type-only import and signature update to use ChatMessage[] correctly reflect the migration to the new type system.

web/src/lib/actions.tsx (3)

7-7: LGTM!

The import migration to '@ai-sdk/rsc' and the use of type-only imports for ChatMessage, Feedback, and UIStateNode are correct.

Also applies to: 12-12


88-95: LGTM!

The explicit typing of message arrays as ChatMessage[] is correct and aligns with the new type system.

Also applies to: 141-148


112-115: Remove the name property verification request—it's not required by AI SDK.

The message mapping has been correctly simplified to include only role and content, which are the only required properties for message objects passed to streamUI. The streamUI function accepts CoreSystemMessage, CoreUserMessage, CoreAssistantMessage, CoreToolMessage, or UIMessage types, and messages only require a role property and a content property. The removal of name does not break any AI SDK functionality.

web/src/lib/aiProvider.tsx (3)

1-1: LGTM!

The import migration to '@ai-sdk/rsc' and the use of type-only imports for ChatMessage and WonkActions are correct.

Also applies to: 6-6, 15-15


30-34: LGTM!

The explicit typing of aiState as ChatHistory and messages as ChatMessage[], along with the typed mapping parameter, correctly reflects the new type system.


39-40: The removal of the user prop is safe and can be approved.

The UserMessage component defines user as an optional prop (user?: string), but the prop is never used in the component's JSX rendering. Removing it in aiProvider.tsx has no impact on functionality or user experience. However, there is an inconsistency: chatInput.tsx still passes the unused user prop (lines 40-42). Consider removing it there as well for consistency, or document why the prop remains optional.

web/src/models/chat.ts (1)

5-11: Migration to ChatMessage verified as complete.

The ChatMessage type system is properly defined and integrated throughout the codebase. No lingering references to the old Message type were found, confirming successful migration across all files.

web/src/services/loggingService.ts (1)

5-6: LGTM!

The import correctly uses import type for the type-only ChatMessage import, which aligns with the PR's migration from the ai package's Message type to the local ChatMessage type.

web/src/services/historyService.ts (3)

19-24: LGTM!

The import correctly groups ChatMessage with other types from @/models/chat, maintaining clean import organization.


173-179: LGTM!

The saveChat function signature correctly updated to use ChatMessage[] for the messages parameter, consistent with the type migration across the codebase.


40-47: Type migration looks correct, existing TODO acknowledged.

The hard cast on line 42 is noted with a TODO comment. The filterOutSystemMessages function correctly filters messages where role !== 'system', which aligns with the ChatMessageRole type that is defined as 'system' | 'user' | 'assistant'.

web/src/services/chatService.ts (3)

11-11: LGTM!

The import correctly uses import type for type-only imports, following TypeScript best practices for types that are only used for type checking.


37-44: LGTM!

Explicitly typing the return value as Promise<number[][]> improves type clarity and aligns with the updated parameter types in getSearchResultsElastic and getSearchResultsPgSQL.


132-134: LGTM!

The parameter type change from EmbeddingModelV1Embedding[] to number[][] is a cleaner representation of the embedding vectors and reduces coupling to the AI SDK's internal types.

Also applies to: 173-176

@srkirkland srkirkland merged commit 11f6136 into main Dec 17, 2025
8 checks passed
@srkirkland srkirkland deleted the srk/ai-sdk5 branch December 17, 2025 21:39
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.

2 participants