-
Notifications
You must be signed in to change notification settings - Fork 1
Updates AI SDK and dependencies #150
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
Conversation
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.
WalkthroughThis PR upgrades AI SDK dependencies and migrates imports from the 'ai' package to the '@AI-SDK' namespace. It introduces a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~28 minutes
Areas requiring extra attention:
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
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 (2)
web/src/services/loggingService.ts (1)
91-105: Consider simplifying the message mapping.Since
ChatMessagealready 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
Messagetype 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 usingsatisfiesinstead ofasfor type-safe object literals.The object literals are cast to
ChatMessageusingas, but this bypasses TypeScript's type checking. While'system'is valid forChatMessageRole, usingsatisfies(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
ChatMessagewithout losing type inference.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
web/package-lock.jsonis 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.tsxweb/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/rscto@ai-sdk/rscis 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/rscis 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/rscis consistent with the SDK upgrade. BothuseActionsanduseAIStateare 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.33→5.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 forChatMessage,Feedback, andUIStateNodeare 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 thenameproperty verification request—it's not required by AI SDK.The message mapping has been correctly simplified to include only
roleandcontent, 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 ofnamedoes 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 forChatMessageandWonkActionsare correct.Also applies to: 6-6, 15-15
30-34: LGTM!The explicit typing of
aiStateasChatHistoryandmessagesasChatMessage[], along with the typed mapping parameter, correctly reflects the new type system.
39-40: The removal of theuserprop is safe and can be approved.The
UserMessagecomponent definesuseras an optional prop (user?: string), but the prop is never used in the component's JSX rendering. Removing it inaiProvider.tsxhas no impact on functionality or user experience. However, there is an inconsistency:chatInput.tsxstill passes the unuseduserprop (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
ChatMessagetype system is properly defined and integrated throughout the codebase. No lingering references to the oldMessagetype were found, confirming successful migration across all files.web/src/services/loggingService.ts (1)
5-6: LGTM!The import correctly uses
import typefor the type-onlyChatMessageimport, which aligns with the PR's migration from theaipackage'sMessagetype to the localChatMessagetype.web/src/services/historyService.ts (3)
19-24: LGTM!The import correctly groups
ChatMessagewith other types from@/models/chat, maintaining clean import organization.
173-179: LGTM!The
saveChatfunction signature correctly updated to useChatMessage[]for themessagesparameter, 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
filterOutSystemMessagesfunction correctly filters messages whererole !== 'system', which aligns with theChatMessageRoletype that is defined as'system' | 'user' | 'assistant'.web/src/services/chatService.ts (3)
11-11: LGTM!The import correctly uses
import typefor 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 ingetSearchResultsElasticandgetSearchResultsPgSQL.
132-134: LGTM!The parameter type change from
EmbeddingModelV1Embedding[]tonumber[][]is a cleaner representation of the embedding vectors and reduces coupling to the AI SDK's internal types.Also applies to: 173-176
Updates AI SDK and related dependencies to the latest versions.
@ai-sdk/openaito^2.0.88and@ai-sdk/rscto^1.0.117.aito version5.0.114.zodas a dependency.@ai-sdk/rscfor improved AI state management and actions.Summary by CodeRabbit
Chores
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.