Repository navigation
AIエージェントに行き先を相談できるチャット画面とエントリバナーを追加 - #6479
Conversation
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_017SRZ31WjnRgkhn3N9LoNyY
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAI目的地案内機能を追加しました。リモート設定による公開制御、チャット通信、候補駅表示、目的地選択の共通化、専用画面とナビゲーション、英語・日本語リソースを実装しています。 ChangesAI目的地案内
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant 利用者
participant DestinationAgentScreen
participant useDestinationAgent
participant workerApi
participant GraphQL
利用者->>DestinationAgentScreen: 行き先を入力して送信
DestinationAgentScreen->>useDestinationAgent: 会話履歴を渡す
useDestinationAgent->>workerApi: POST /agent/chat
workerApi-->>useDestinationAgent: 返信と駅候補
useDestinationAgent-->>DestinationAgentScreen: 応答結果
DestinationAgentScreen->>GraphQL: 候補駅情報を取得
GraphQL-->>DestinationAgentScreen: 駅・路線情報
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (5)
src/hooks/useDestinationSelection.ts (2)
155-162: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value冗長なガードとコメント不一致。
Line 156-160 で
selectedStation.line?.idを既に確認済みのため、Line 176-178 の再チェックは到達不能です。またコメント(Line 155)は「lineId と stationId」と書かれていますが実際にはgroupIdを検証しています。Also applies to: 175-178
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/hooks/useDestinationSelection.ts` around lines 155 - 162, useDestinationSelection の選択処理で、既に確認済みの selectedStation.line?.id を重複して検証している到達不能なガードを削除または統合してください。あわせて、ガード直前のコメントを実際に検証している groupId の内容と一致するよう更新してください。
133-274: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win連続タップ時に古い選択の結果が後勝ちで atom を上書きする可能性があります。
useLazyGraphQLQueryは内部 state を requestId で保護しますが、executeの戻り値は古いリクエストでも解決されるため、この関数は await 後にpendingStations/pendingStation/pendingLineを無条件で書き込みます。候補カードを素早く連続タップすると、先行選択のレスポンスが後の選択の状態を上書きし得ます。呼び出しごとの世代カウンタ(DestinationAgentScreenのconversationGenRefと同様の ref)で古い結果を破棄する形が安全です。♻️ 世代カウンタによるガード例
+ const selectionGenRef = useRef(0); + const handleDestinationSelected = useCallback( async (selectedStation: Station) => { + const gen = ++selectionGenRef.current; setSelectBoundModalVisible(true);以降の各
awaitの直後でif (gen !== selectionGenRef.current) return;を挟みます。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/hooks/useDestinationSelection.ts` around lines 133 - 274, Protect handleDestinationSelected against stale results from rapid consecutive selections by adding a ref-backed selection generation counter and incrementing it for each invocation. Capture the generation at the start, then after every awaited fetch—fetchRouteTypes, fetchStationsByLineId, and fetchStationsByLineGroupId—return immediately when it no longer matches the current generation before updating pendingStation, pendingStations, pendingLine, or navigation state; include the ref in the callback dependencies as appropriate.src/screens/DestinationAgent/AgentInputBar.tsx (2)
88-91: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
isJapanese相当のセッション定数ではないためuseMemoは妥当ですが、簡素化できます。三項演算子1つのため
useMemoのコストのほうが大きい可能性があります。素の式で十分です。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/screens/DestinationAgent/AgentInputBar.tsx` around lines 88 - 91, Simplify the fontFamily assignment in the AgentInputBar component by removing the useMemo wrapper and using the existing isLEDTheme ternary expression directly. Remove any now-unused useMemo import while preserving the selected FONTS.JFDotJiskan24h and FONTS.RobotoRegular values.
19-20: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win閾値は
AGENT_MAX_MESSAGE_LENGTHから導出してください。
450はAGENT_MAX_MESSAGE_LENGTHが 500 であることを前提としたマジックナンバーで、上限を変更すると無言でずれます。♻️ 提案
-// 残量が見えないと困る領域に入ってから出す(500 - 50) -const COUNTER_VISIBLE_THRESHOLD = 450; +// 残り 50 文字を切ったら残量を表示する +const COUNTER_VISIBLE_THRESHOLD = AGENT_MAX_MESSAGE_LENGTH - 50;
AGENT_MAX_MESSAGE_LENGTHの import はファイル先頭にあるものをそのまま使えます。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/screens/DestinationAgent/AgentInputBar.tsx` around lines 19 - 20, Update COUNTER_VISIBLE_THRESHOLD in AgentInputBar so it is derived from the imported AGENT_MAX_MESSAGE_LENGTH rather than the hard-coded 450 value, preserving the existing 50-character margin.src/screens/DestinationAgent/AgentMessageBubble.tsx (1)
63-79: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winスクリーンリーダーで発話者が判別できません。
視覚的には左右の配置と色で user / assistant を区別していますが、読み上げでは本文のみになります。
accessibilityLabelに話者を含めると会話の流れが伝わります。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/screens/DestinationAgent/AgentMessageBubble.tsx` around lines 63 - 79, Update the accessible label on the message container in AgentMessageBubble so it includes the speaker identity (user or assistant) together with the message content. Preserve the existing visual styles and ensure the screen reader announces the speaker before the message text.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/hooks/useDestinationSelection.ts`:
- Around line 86-90: Update the train-type selection flow in this hook so an
explicit user action sets trainTypeListModalVisible to true, providing the
missing opening path for TrainTypeListModal. Reuse the existing handler or add a
dedicated handler near handleTrainTypeSelected, and preserve the existing
select-bound modal behavior where applicable.
In `@src/screens/DestinationAgent/index.tsx`:
- Around line 305-312:
エラー復帰処理のsetInputText(text)を、現在の入力欄が空の場合にのみ実行するようDestinationAgentの送信失敗ブロックを更新してください。送信中にユーザが新しく入力した内容は保持し、既存のentries削除とエラー通知は変更しないでください。
- Around line 260-267: Update the sending flow in DestinationAgent around
sendMessages so sendingRef.current and setSending(false) execute in a finally
block, including when sendMessages rejects. Keep the existing successful send
behavior unchanged while ensuring the typing indicator and send button are
always reset.
---
Nitpick comments:
In `@src/hooks/useDestinationSelection.ts`:
- Around line 155-162: useDestinationSelection の選択処理で、既に確認済みの
selectedStation.line?.id
を重複して検証している到達不能なガードを削除または統合してください。あわせて、ガード直前のコメントを実際に検証している groupId
の内容と一致するよう更新してください。
- Around line 133-274: Protect handleDestinationSelected against stale results
from rapid consecutive selections by adding a ref-backed selection generation
counter and incrementing it for each invocation. Capture the generation at the
start, then after every awaited fetch—fetchRouteTypes, fetchStationsByLineId,
and fetchStationsByLineGroupId—return immediately when it no longer matches the
current generation before updating pendingStation, pendingStations, pendingLine,
or navigation state; include the ref in the callback dependencies as
appropriate.
In `@src/screens/DestinationAgent/AgentInputBar.tsx`:
- Around line 88-91: Simplify the fontFamily assignment in the AgentInputBar
component by removing the useMemo wrapper and using the existing isLEDTheme
ternary expression directly. Remove any now-unused useMemo import while
preserving the selected FONTS.JFDotJiskan24h and FONTS.RobotoRegular values.
- Around line 19-20: Update COUNTER_VISIBLE_THRESHOLD in AgentInputBar so it is
derived from the imported AGENT_MAX_MESSAGE_LENGTH rather than the hard-coded
450 value, preserving the existing 50-character margin.
In `@src/screens/DestinationAgent/AgentMessageBubble.tsx`:
- Around line 63-79: Update the accessible label on the message container in
AgentMessageBubble so it includes the speaker identity (user or assistant)
together with the message content. Preserve the existing visual styles and
ensure the screen reader announces the speaker before the message text.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3885cda3-a462-41b2-ac28-a489a22ac7ff
📒 Files selected for processing (18)
assets/translations/en.jsonassets/translations/ja.jsonsrc/components/Chip.tsxsrc/hooks/useAIAgentFeatureEnabled.tssrc/hooks/useDestinationAgent.test.tssrc/hooks/useDestinationAgent.tssrc/hooks/useDestinationSelection.tssrc/lib/remoteConfig.test.tssrc/lib/remoteConfig.tssrc/screens/DestinationAgent/AgentEmptyState.tsxsrc/screens/DestinationAgent/AgentEntryBanner.tsxsrc/screens/DestinationAgent/AgentHeader.tsxsrc/screens/DestinationAgent/AgentInputBar.tsxsrc/screens/DestinationAgent/AgentMessageBubble.tsxsrc/screens/DestinationAgent/AgentTypingIndicator.tsxsrc/screens/DestinationAgent/index.tsxsrc/screens/RouteSearchScreen.tsxsrc/stacks/MainStack.tsx
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_017SRZ31WjnRgkhn3N9LoNyY
CodeRabbit Autofix 適用結果未解決スレッド 3 件を検証し、1 件を修正しました。 適用(コミット
スキップ:
検証: |
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_017SRZ31WjnRgkhn3N9LoNyY
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_017SRZ31WjnRgkhn3N9LoNyY
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_017SRZ31WjnRgkhn3N9LoNyY
概要
Issue-driven 開発の親タスク #6473 で定義された「駅名を知らなくても連想できる言葉で行き先を決定できる」体験の PoC として、AI エージェントと対話して行き先を決めるチャット画面をアプリ側に実装しました。設計は
docs/spec/ai-agent/architecture.md(#6476)/docs/spec/ai-agent/ui.md(#6478)で FIX 済みの内容に、Figma の確定デザイン(v10 ファイル node 1650-91)を反映しています。BFF 側(
/agent/chat)は TrainLCD/BFF リポジトリで別途実装予定のためスコープ外です。機能は Remote Configai_agent_enabled(既定false)とisDevAppの二重ゲートで守られており、本番ビルドには露出しません。変更の種類
変更内容
src/screens/DestinationAgent/(新規): チャット画面DestinationAgentScreenと専用コンポーネント(AgentHeader/AgentMessageBubble/AgentTypingIndicator/AgentEmptyState/AgentInputBar/AgentEntryBanner)を co-locate。空状態(例文チップ・免責)、タイピングインジケータ、LED テーマ分岐、タブレット最大幅 700 対応を含むAgentMessageBubbleは AI 応答の Markdown 強調(**text**)を太字としてインライン描画(フル Markdown は解釈しない)src/hooks/useDestinationAgent.ts(新規):/agent/chat呼び出しフック。callable 互換ワイヤ形式 + セッション JWT、履歴 12 件 / 500 字のクライアント側切り詰め、30 秒タイムアウト、rateLimited/timeout/networkのエラー分類src/hooks/useDestinationSelection.ts(新規):RouteSearchScreenの行き先決定ロジック(GET_ROUTE_TYPES_LIGHT→ 種別決定 →pendingStations構築)を共有フックへ抽出し、検索結果タップと提案カードタップを同一のSelectBoundModalフローへ合流src/hooks/useAIAgentFeatureEnabled.ts(新規):ai_agent_enabledのuseSyncExternalStore購読 + PoC 期間中のisDevAppAND ゲートsrc/lib/remoteConfig.ts:ai_agent_enabledキー追加(フォールバックfalseのキルスイッチ)src/screens/RouteSearchScreen.tsx: 選択ロジックを共有フックへ移設し、検索バー直下に AI 相談エントリバナーを追加(フラグ off 時は非表示・従来レイアウト維持)src/stacks/MainStack.tsx:DestinationAgent画面を登録assets/translations/{ja,en}.json: UI 文言 15 キー追加src/components/Chip.tsx:accessibilityRole="button"を付与GET_STATIONS_BY_IDSでStation完全体を再取得してからCommonCardで描画(lineNamesの名称一致による路線解決は不使用)。ユーザバブルは WCAG AA 準拠の#0071CEuseDestinationAgent.test.ts(正常 / refused / 429 / 5xx / ネットワーク / タイムアウト / 切り詰め)、remoteConfig.test.tsに 5 ケースリグレッションリスクと緩和
RouteSearchScreenの選択ロジック共有フック化が最大のリスク。ロジックは挙動を変えずに移設し、既存RouteSearchScreen.test.tsxが無修正で通過することを確認済みai_agent_enabledをfalseにするだけで全クライアントから機能が消える開発プロセス(#6475 の実装備考)
テスト
npm run lintが通ることnpm testが通ることnpm run typecheckが通ることローカルで
npm run lint(596 ファイル指摘なし)/npx jest(195 suites / 2104 tests 全通過)/npm run typecheck(エラーなし)を実行。BFF 未実装のため実機での結合確認と UI 手動 QA(キーボード追従・LED テーマ・multiline 高さ)は未実施で、dev ビルドで別途行います。関連Issue
Closes #6475
Refs #6473
スクリーンショット(任意)
🤖 Generated with Claude Code
https://claude.ai/code/session_017SRZ31WjnRgkhn3N9LoNyY
Summary by CodeRabbit