Skip to content
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

スライドモードの追加 #127

Merged
merged 25 commits into from
Aug 13, 2024
Merged

スライドモードの追加 #127

merged 25 commits into from
Aug 13, 2024

Conversation

tegnike
Copy link
Owner

@tegnike tegnike commented Aug 13, 2024

Summary by CodeRabbit

  • 新機能

    • スライドプレゼンテーション用の新しいJSONファイルとMarkdownテンプレートを追加しました。
    • AIキャラクターとのインタラクションや、YouTubeライブストリーミング機能を強化しました。
    • スライドモードの設定を管理する新しいUIコンポーネントを追加しました。
    • スライドのナビゲーションと再生制御を管理する新しいコンポーネントを追加しました。
  • バグ修正

    • メッセージ入力コンポーネントがスライド再生中に無効になるように修正しました。
  • ドキュメント

    • 新しいプレゼンテーションガイドとスクリプトテンプレートを追加しました。
  • スタイル

    • プレゼンテーション用のカスタムテーマとCSSスタイルを追加しました。

Copy link

vercel bot commented Aug 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
aituber-kit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 13, 2024 7:48pm

Copy link

coderabbitai bot commented Aug 13, 2024

Walkthrough

新しい機能や改善が追加され、スライドプレゼンテーション機能が強化されました。これにより、ユーザーはよりインタラクティブな体験ができるようになり、スライドとAIの統合が進みました。プレゼンテーションの設定や表示方法が改善され、さまざまなファイルに新しいスタイルや翻訳が追加され、全体的なユーザー体験が向上しています。

Changes

ファイル 変更の概要
demo copy/... プレゼンテーション用の構造化されたスクリプトやテンプレート、スタイルを提供する新しいJSONおよびMarkdownファイルが追加されました。
locales/... スライド関連の設定をサポートするための日本語、英語、韓国語、中国語の翻訳が追加されました。
package.json Marp関連の新しい依存関係が追加され、プレゼンテーション機能の強化が図られました。
public/slides/demo/... AITuberKitのスライドモードに関する設定、ガイド、およびテーマスタイルが追加されました。
src/components/... スライド管理、設定、メニューのインタラクティブ機能を強化するための複数のReactコンポーネントが更新されました。
src/features/chat/handlers.ts メッセージ処理に関する非同期関数が追加され、AI応答処理が改善されました。
src/features/slide/slideAIHelpers.ts ユーザーコメントをスクリプト文書と照合する新しい関数judgeSlideが追加されました。
src/pages/api/... MarkdownスライドをHTMLに変換するAPIエンドポイントとスライドに関連する補足テキストを取得するAPIエンドポイントが追加されました。
src/utils/englishToJapanese.json 新しい英語から日本語への翻訳エントリが追加され、現代用語のカバレッジが拡充されました。
tailwind.config.js zIndexプロパティの新しい設定が追加され、デザインにおけるスタッキングコンテクストの制御が向上しました。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI
    participant SlideStore
    participant AI
    participant API

    User->>UI: スライドモードを開始
    UI->>SlideStore: スライドの状態を取得
    SlideStore->>UI: 現在のスライド情報
    UI->>API: MarkdownをHTMLに変換リクエスト
    API-->>UI: HTMLを返す
    UI->>AI: 質問を送信
    AI-->>UI: AIの応答を受け取る
    UI->>User: スライドを表示
Loading

Poem

🐇 新たな機能のうねりに、
スライドが輝き、動き出す。
うさぎは跳ねて、喜び舞い、
AIと共に、夢を描く。
みんなで楽しむ、プレゼンの夜、
笑顔と知恵、集まりぬ。


Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 5

Outside diff range, codebase verification and nitpick comments (9)
demo copy/slides.md (1)

20-20: 見出しレベルの調整

見出しのレベルがH2からH3に飛んでいます。見出しレベルは一段ずつ増やすことをお勧めします。

- ### サブタイトル
+ ## サブタイトル
Tools
Markdownlint

20-20: Expected: h2; Actual: h3
Heading levels should only increment by one level at a time

(MD001, heading-increment)

src/pages/api/getSupplement.ts (1)

16-29: エラーハンドリングの改善

ファイル読み込みエラーのログ出力が含まれていますが、エラーメッセージに具体的なファイルパスを含めない方が安全です。

console.error('Error reading supplement file:', error);
src/pages/api/convertMarkdown.ts (1)

41-41: エラーログに詳細を追加

エラーログに詳細な情報を含めることで、デバッグが容易になります。例えば、slideName やファイルパスをログに含めることが考えられます。

console.error(`Error processing ${slideName}:`, error)
public/slides/demo/slides.md (2)

11-11: 画像に代替テキストを追加

画像には代替テキストを追加してください。これにより、アクセシビリティが向上します。

![AITuberKitのロゴ](/slides/demo/images/logo.png)
Tools
Markdownlint

11-11: null
Images should have alternate text (alt text)

(MD045, no-alt-text)


24-24: URLをリンクとしてマークダウン化

裸のURLをリンクとしてマークダウン化することで、より読みやすくなります。

- ※ まだの方は[AITuberKitの解説note](https://note.com/nike_cha_n/n/ne98acb25e00f)を参照
Tools
Markdownlint

24-24: null
Bare URL used

(MD034, no-bare-urls)

public/slides/demo/supplement.txt (1)

1-97: 補足情報の内容

このファイルは、スライド機能の使用方法に関する詳細な説明を提供しています。以下の点に注意してください:

  1. 冗長な表現: 「ことができる」という表現が複数箇所で冗長に使用されています。簡潔にするために見直すことを検討してください。
  2. 手順の明確さ: 各機能の使用手順が明確に記載されています。特に、APIキーの設定やサーバーの起動手順が具体的です。
  3. 関連情報のリンク: 他のリポジトリやドキュメントへのリンクが提供されており、参考になります。

全体として、内容は非常に役立ちますが、表現の簡潔さを改善する余地があります。

- ことができます。
+ 可能です。
Tools
LanguageTool

[uncategorized] ~38-~38: 「ことができる」という表現は冗長な可能性があります。
Context: ...応じて声の設定を行います。 - VOICEVOXの場合は複数の選択肢から話者を選ぶことができます。予めVOICEVOXアプリを起動しておく必要があります。 -...

(DOUSI_KOTOGADEKIRU)


[uncategorized] ~56-~56: 「ことができる」という表現は冗長な可能性があります。
Context: ...するのを確認します。 5. 会話継続モードをONにすると、コメントが無いときにAIが自ら発言することができます。 外部連携モード(β版) - WebSocketでサーバ...

(DOUSI_KOTOGADEKIRU)


[uncategorized] ~59-~59: 「ことができる」という表現は冗長な可能性があります。
Context: ...- WebSocketでサーバーアプリにメッセージを送信して、レスポンスを取得することができます。 - 上記2つと異なり、フロントアプリで完結しないため少し難易度が高いで...

(DOUSI_KOTOGADEKIRU)


[uncategorized] ~79-~79: 「ことができる」という表現は冗長な可能性があります。
Context: ...でください。 環境変数の設定 - 一部の設定値は .env ファイルの内容を参照することができます。 - 設定画面で入力した場合は、その値が優先されます。 その他 -...

(DOUSI_KOTOGADEKIRU)


[uncategorized] ~83-~83: 「ことができる」という表現は冗長な可能性があります。
Context: ...した場合は、その値が優先されます。 その他 - 会話履歴は設定画面でリセットすることができます。 - 各種設定項目はブラウザに保存されます。 - コードブロックで囲まれ...

(DOUSI_KOTOGADEKIRU)

src/features/stores/settings.ts (1)

122-122: ストア名の変更が完全に実施されていません。

settingsStore という古いストア名が多くの場所で使用されています。以下のファイルや行での更新が必要です:

  • src/pages/_app.tsx
  • src/features/youtube/youtubeComments.ts
  • src/features/messages/speakCharacter.ts
  • src/utils/migrateStore.ts
  • src/components/chatLog.tsx
  • src/components/messageInputContainer.tsx
  • src/features/chat/handlers.ts
  • src/components/assistantText.tsx
  • src/components/form.tsx
  • src/components/useYoutube.tsx
  • src/components/menu.tsx
  • src/components/useWebSocket.tsx
  • src/components/introduction.tsx
  • src/features/chat/difyChat.ts
  • src/components/settings/log.tsx
  • src/components/settings/slide.tsx
  • src/components/settings/index.tsx
  • src/components/settings/websocket.tsx
  • src/components/settings/youtube.tsx
  • src/components/settings/language.tsx
  • src/components/settings/modelProvider.tsx
  • src/components/settings/advancedSettings.tsx
  • src/features/slide/slideAIHelpers.ts
  • src/components/settings/character.tsx
  • src/components/settings/voice.tsx

これらの箇所でストア名を 'aitube-kit-settings' に変更してください。

Analysis chain

設定ストアの名前変更は明確です。

設定のコンテキストを明確にするための変更です。

ストアへのすべての参照が更新されていることを確認してください。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to the renamed settings store.

# Test: Search for the old and new store names. Expect: Only occurrences of the new name.
rg --type ts 'aitube-kit-settings'

Length of output: 101


Script:

#!/bin/bash
# Description: Check for any remaining references to the old store name.

# Test: Search for the old store name 'settings' to ensure no outdated references remain.
rg --type ts 'settings'

Length of output: 15527

src/components/marpSlides.tsx (1)

41-84: Markdown変換プロセスにエラーハンドリングを追加してください。

convertMarkdown関数内でエラーが発生した場合に備えて、適切なエラーハンドリングを実装することをお勧めします。特に、fetchリクエストやHTMLのパース中にエラーが発生する可能性があります。

  • fetchのエラーハンドリングを追加する。
  • HTMLパースのエラーハンドリングを追加する。
Analysis chain

Markdown変換プロセスのエラーハンドリングを確認してください。

MarkdownからHTMLへの変換中にエラーが適切に処理されていることを確認してください。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify error handling in the markdown conversion process.

# Test: Search for error handling in the conversion process. Expect: Proper error handling.
rg --type js --type jsx --type ts --type tsx 'convertMarkdown'

Length of output: 90


Script:

#!/bin/bash
# Description: Verify error handling in the markdown conversion process.

# Test: Search for error handling in the conversion process. Expect: Proper error handling.
rg --type js --type ts --type tsx 'convertMarkdown'

Length of output: 79


Script:

#!/bin/bash
# Description: Verify error handling in the markdown conversion process.

# Test: Search for error handling in the conversion process. Expect: Proper error handling.
rg 'convertMarkdown'

Length of output: 235

src/features/chat/handlers.ts (1)

Line range hint 473-473:
TODO: メッセージ処理の改善が必要です。

メッセージ処理のロジックを改善する必要があります。
このタスクのためにGitHubのissueを作成しましょうか?

Tools
Biome

[error] 40-41: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ed44330 and 84a233f.

Files ignored due to path filters (6)
  • package-lock.json is excluded by !**/package-lock.json
  • public/slides/demo/images/demo-folder.png is excluded by !**/*.png
  • public/slides/demo/images/file-structure.png is excluded by !**/*.png
  • public/slides/demo/images/logo.png is excluded by !**/*.png
  • public/slides/demo/images/settings-screen.png is excluded by !**/*.png
  • public/slides/demo/images/start-button.png is excluded by !**/*.png
Files selected for processing (35)
  • demo copy/scripts.json (1 hunks)
  • demo copy/slides.md (1 hunks)
  • demo copy/supplement.json (1 hunks)
  • demo copy/theme.css (1 hunks)
  • locales/ja/translation.json (2 hunks)
  • package.json (1 hunks)
  • public/slides/demo/scripts.json (1 hunks)
  • public/slides/demo/slides.md (1 hunks)
  • public/slides/demo/supplement.txt (1 hunks)
  • public/slides/demo/theme.css (1 hunks)
  • public/slides/sample.txt (1 hunks)
  • src/components/assistantText.tsx (1 hunks)
  • src/components/form.tsx (2 hunks)
  • src/components/marpSlides.tsx (1 hunks)
  • src/components/menu.tsx (4 hunks)
  • src/components/messageInput.tsx (4 hunks)
  • src/components/settings/index.tsx (2 hunks)
  • src/components/settings/modelProvider.tsx (3 hunks)
  • src/components/settings/slide.tsx (1 hunks)
  • src/components/settings/youtube.tsx (2 hunks)
  • src/components/slideContent.tsx (1 hunks)
  • src/components/slideControls.tsx (1 hunks)
  • src/components/slideText.tsx (1 hunks)
  • src/components/useYoutube.tsx (1 hunks)
  • src/components/vrmViewer.tsx (1 hunks)
  • src/features/chat/handlers.ts (9 hunks)
  • src/features/slide/slideAIHelpers.ts (1 hunks)
  • src/features/stores/home.ts (3 hunks)
  • src/features/stores/menu.ts (1 hunks)
  • src/features/stores/settings.ts (2 hunks)
  • src/features/stores/slide.ts (1 hunks)
  • src/pages/api/convertMarkdown.ts (1 hunks)
  • src/pages/api/getSupplement.ts (1 hunks)
  • src/utils/englishToJapanese.json (11 hunks)
  • tailwind.config.js (1 hunks)
Files skipped from review due to trivial changes (5)
  • demo copy/supplement.json
  • demo copy/theme.css
  • src/components/assistantText.tsx
  • src/components/useYoutube.tsx
  • src/components/vrmViewer.tsx
Additional context used
Biome
src/components/slideContent.tsx

[error] 13-13: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)

src/features/chat/handlers.ts

[error] 40-41: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

LanguageTool
demo copy/slides.md

[uncategorized] ~32-~32: 文法ミスがあります。"名詞を"見る
Context: ... 名前 --- # H1 あいうえおabcde ## H2 あいうえおabcde ### H3 あいうえおab...

(O)


[uncategorized] ~34-~34: 文法ミスがあります。"名詞を"見る
Context: ...ader: ヘッダー --> # H1 あいうえおabcde ## H2 あいうえおabcde ### H3 あいうえおabcde #### H4 あいうえお...

(O)


[uncategorized] ~36-~36: 文法ミスがあります。"名詞を"見る
Context: ...1 あいうえおabcde ## H2 あいうえおabcde ### H3 あいうえおabcde #### H4 あいうえおabcde ##### H5 あいう...

(O)


[uncategorized] ~38-~38: 文法ミスがあります。"名詞を"見る
Context: ...あいうえおabcde ### H3 あいうえおabcde #### H4 あいうえおabcde ##### H5 あいうえおabcde ![bg right:...

(O)


[uncategorized] ~40-~40: 文法ミスがあります。"名詞を"見る
Context: ...うえおabcde #### H4 あいうえおabcde ##### H5 あいうえおabcde ![bg right:33% height:100](https...

(O)

public/slides/demo/supplement.txt

[uncategorized] ~38-~38: 「ことができる」という表現は冗長な可能性があります。
Context: ...応じて声の設定を行います。 - VOICEVOXの場合は複数の選択肢から話者を選ぶことができます。予めVOICEVOXアプリを起動しておく必要があります。 -...

(DOUSI_KOTOGADEKIRU)


[uncategorized] ~56-~56: 「ことができる」という表現は冗長な可能性があります。
Context: ...するのを確認します。 5. 会話継続モードをONにすると、コメントが無いときにAIが自ら発言することができます。 外部連携モード(β版) - WebSocketでサーバ...

(DOUSI_KOTOGADEKIRU)


[uncategorized] ~59-~59: 「ことができる」という表現は冗長な可能性があります。
Context: ...- WebSocketでサーバーアプリにメッセージを送信して、レスポンスを取得することができます。 - 上記2つと異なり、フロントアプリで完結しないため少し難易度が高いで...

(DOUSI_KOTOGADEKIRU)


[uncategorized] ~79-~79: 「ことができる」という表現は冗長な可能性があります。
Context: ...でください。 環境変数の設定 - 一部の設定値は .env ファイルの内容を参照することができます。 - 設定画面で入力した場合は、その値が優先されます。 その他 -...

(DOUSI_KOTOGADEKIRU)


[uncategorized] ~83-~83: 「ことができる」という表現は冗長な可能性があります。
Context: ...した場合は、その値が優先されます。 その他 - 会話履歴は設定画面でリセットすることができます。 - 各種設定項目はブラウザに保存されます。 - コードブロックで囲まれ...

(DOUSI_KOTOGADEKIRU)

Markdownlint
demo copy/slides.md

20-20: Expected: h2; Actual: h3
Heading levels should only increment by one level at a time

(MD001, heading-increment)

public/slides/demo/slides.md

24-24: null
Bare URL used

(MD034, no-bare-urls)


11-11: null
Images should have alternate text (alt text)

(MD045, no-alt-text)

Additional comments not posted (56)
src/features/stores/menu.ts (1)

8-8: slideVisible プロパティの追加を確認しました。

このプロパティはメニューのスライド表示を管理するために追加されました。既存のコードとの統合や機能への影響を確認してください。

Also applies to: 16-16

Verification successful

slideVisible プロパティの統合が確認されました。

slideVisible は、複数のコンポーネントで使用されており、メニューのスライド表示を管理するために適切に統合されています。以下のファイルで確認されました:

  • src/components/form.tsx
  • src/components/settings/slide.tsx
  • src/components/menu.tsx

これにより、スライド表示の管理が一貫して行われていることが確認できました。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify integration and usage of `slideVisible` in the codebase.

# Test: Check for usage and integration of `slideVisible`. Expect: Proper integration.
rg --type ts $'slideVisible'

Length of output: 721

src/components/slideText.tsx (1)

1-14: 新しいコンポーネント SlideText の追加を確認しました。

このコンポーネントは homeStore からメッセージを取得し表示します。コンポーネントの統合やベストプラクティスへの準拠を確認してください。

Verification successful

SlideTextコンポーネントの統合が確認されました。

  • SlideTextは他のファイルでインポートされ、使用されています。これにより、コードベースへの適切な統合が確認されました。
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify integration and usage of `SlideText` in the codebase.

# Test: Check for usage and integration of `SlideText`. Expect: Proper integration.
rg --type tsx $'SlideText'

Length of output: 53


Script:

#!/bin/bash
# Find all .tsx files and search for the usage of `SlideText` within them.
fd --extension tsx --exec rg 'SlideText' {}

Length of output: 136

src/features/stores/slide.ts (1)

10-22: 状態管理の確認を推奨

selectedSlideDocsの状態が適切に管理され、使用されていることを確認してください。この状態が他のコンポーネントで正しく利用されているかを確認することをお勧めします。

public/slides/sample.txt (1)

10-15: プレースホルダーの置換確認

{{SCRIPTS}}{{SUPPLEMENT}}のプレースホルダーが実行時に正しく置換されることを確認してください。これにより、プレゼンテーションの一貫性が保たれます。

demo copy/slides.md (1)

32-40: 文法の確認

LanguageToolが文法ミスを指摘していますが、見出しの例として意図的に使われている可能性があります。確認してください。

Tools
LanguageTool

[uncategorized] ~32-~32: 文法ミスがあります。"名詞を"見る
Context: ... 名前 --- # H1 あいうえおabcde ## H2 あいうえおabcde ### H3 あいうえおab...

(O)


[uncategorized] ~34-~34: 文法ミスがあります。"名詞を"見る
Context: ...ader: ヘッダー --> # H1 あいうえおabcde ## H2 あいうえおabcde ### H3 あいうえおabcde #### H4 あいうえお...

(O)


[uncategorized] ~36-~36: 文法ミスがあります。"名詞を"見る
Context: ...1 あいうえおabcde ## H2 あいうえおabcde ### H3 あいうえおabcde #### H4 あいうえおabcde ##### H5 あいう...

(O)


[uncategorized] ~38-~38: 文法ミスがあります。"名詞を"見る
Context: ...あいうえおabcde ### H3 あいうえおabcde #### H4 あいうえおabcde ##### H5 あいうえおabcde ![bg right:...

(O)


[uncategorized] ~40-~40: 文法ミスがあります。"名詞を"見る
Context: ...うえおabcde #### H4 あいうえおabcde ##### H5 あいうえおabcde ![bg right:33% height:100](https...

(O)

tailwind.config.js (1)

45-47: zIndexの追加が正しく行われています

新しいzIndexエントリ「5」が追加され、問題なく設定されています。

public/slides/demo/scripts.json (1)

1-42: このJSONファイルは適切に構成されています。

スライドの内容と注釈が明確に記述されており、JSONの構造も正しいです。

src/components/form.tsx (2)

4-11: インポートの変更は適切です。

新しい状態管理とコンポーネントに必要なインポートが追加されています。


Line range hint 16-58: コンポーネントのロジックは適切に実装されています。

slideModeslideVisibleに基づく条件付きレンダリングが機能を向上させています。

package.json (1)

24-25: 新しい依存関係の追加は適切です。

Marp関連の依存関係が追加され、プレゼンテーション機能を強化しています。

src/features/stores/home.ts (3)

17-17: 新しいプロパティ slideMessages の追加

slideMessages プロパティが TransientState インターフェースに追加されました。スライドメッセージを管理するための重要な機能拡張です。


44-44: slideMessages の初期化

homeStore の初期化で slideMessages が空の配列として設定されています。この初期化は正しく、状態管理を強化します。


66-66: ストア名の変更

ストア名が 'home' から 'aitube-kit-home' に変更されています。この変更は、ストアの識別やリファクタリングに影響を与える可能性があります。アプリケーション全体でこの変更が正しく反映されていることを確認してください。

Verification successful

ストア名の変更が正しく反映されています

コードベース全体で、古いストア名 'home' の直接的な参照は見つかりませんでした。ストア名の変更は正しく行われています。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the updated store name `aitube-kit-home` across the codebase.

# Test: Search for the old and new store names. Expect: No occurrences of the old name.
rg --type js --type ts 'home' | rg -v 'aitube-kit-home'

Length of output: 7609

src/components/settings/slide.tsx (1)

8-76: Slide コンポーネントの実装

この新しいコンポーネントは、スライドモードの設定を管理します。以下の点に注目してください:

  1. useEffect の使用: selectedSlideDocs が未設定の場合にデフォルト値を設定しています。これは適切な初期化方法です。
  2. toggleSlideMode 関数: スライドモードの切り替えと関連するモードの設定を行っています。状態管理が適切に行われています。
  3. UI 要素: TextButton と入力フィールドが適切に使用されています。アクセシビリティとユーザーエクスペリエンスを考慮してください。

全体として、コンポーネントの実装は良好です。

public/slides/demo/theme.css (7)

4-9: CSS変数の使用は良いです。

テーマの一貫性を保ち、更新を容易にするためにCSS変数を使用しています。


11-18: セクションのスタイルは良いです。

背景色やフォントのスタイルが明確で、一貫性があります。


20-32: 見出しのスタイルは適切です。

見出しの視認性とテーマの一貫性を確保しています。


34-82: リストのスタイルは効果的です。

カスタムリストスタイルは読みやすさを向上させ、ユニークな外観を提供します。


84-92: ネストされたリストのスタイルは適切です。

インデントとスペースを適切に調整し、読みやすさを維持しています。


94-98: 画像のスタイルは良いです。

丸みを帯びた角とレスポンシブなサイズを確保し、視覚的な魅力を高めています。


100-139: レイアウトのスタイルは効果的です。

フレックスボックスレイアウトを使用して、レスポンシブで中央揃えのデザインを確保しています。

src/components/settings/index.tsx (2)

16-16: Slideコンポーネントのインポートは正しいです。

新しいコンポーネントの統合が示されています。


94-101: SlideSettingsセクションの追加は一貫性があります。

他の設定セクションと整合性を保ちながら、新しい機能を追加しています。

src/features/stores/settings.ts (1)

61-61: slideModeプロパティの追加は適切です。

機能を強化するための追加です。

このプロパティの使用がコードベース全体で一貫していることを確認してください。

Verification successful

slideModeプロパティの使用がコードベース全体で一貫しています。

  • menu.tsxform.tsxsettings/youtube.tsxsettings/slide.tsxsettings/modelProvider.tsxchat/handlers.tsで使用されています。
  • 各コンポーネントでの使用は、スライドモードの状態を切り替えたり、チェックしたりするために一貫しています。
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all occurrences of `slideMode` in the codebase.

# Test: Search for the usage of `slideMode`. Expect: Consistent usage across the codebase.
rg --type ts 'slideMode'

Length of output: 1161

src/features/slide/slideAIHelpers.ts (1)

6-72: コードは良さそうですが、AIサービスの統合を確認してください。

この新しい関数 judgeSlide は、AIサービスを利用してユーザーのコメントを評価します。コードは適切に構造化されており、エラーハンドリングも実装されています。

ただし、AIサービスの統合が正しく行われているかを確認してください。

Verification successful

AIサービスの統合は正しく行われています。

judgeSlide 関数で使用されている getOpenAIChatResponsegetAnthropicChatResponse の両方が、それぞれのAIサービスと正しく統合されています。これにより、OpenAIとAnthropicのAPIとの通信が適切に行われています。

  • getOpenAIChatResponse は、APIキーの検証とOpenAI APIへのリクエストを適切に処理しています。
  • getAnthropicChatResponse は、AnthropicのAPIへのPOSTリクエストを行い、レスポンスを正しく処理しています。

これにより、judgeSlide 関数でのAIサービスの統合は問題ありません。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of AI services by checking the usage of `getOpenAIChatResponse` and `getAnthropicChatResponse`.

# Test: Search for the function implementations. Expect: Correct integration with AI services.
ast-grep --lang typescript --pattern $'function getOpenAIChatResponse($$$) { $$$ }'
ast-grep --lang typescript --pattern $'function getAnthropicChatResponse($$$) { $$$ }'

Length of output: 2515

demo copy/scripts.json (1)

1-41: JSON構造は良好です。

このJSONファイルは、プレゼンテーション用のスライドを適切に表現しています。各スライドの内容とノートが詳細に記載されています。

src/components/messageInput.tsx (1)

Line range hint 26-90:
変更は良好ですが、状態管理を確認してください。

slidePlaying 状態を追加することで、スライド再生中のユーザー入力を制限する機能が適切に実装されています。キー押下処理のロジックも改善されており、意図しない送信を防いでいます。

ただし、状態管理が正しく行われているかを確認してください。

Verification successful

状態管理の確認が完了しました。

slidePlaying の状態管理は、slideStore を通じて適切に実装されています。isPlaying 状態は、他のコンポーネントでも一貫して使用されており、状態の変更も slideStore.setState を用いて正しく管理されています。

  • slideStore の定義: src/features/stores/slide.ts
  • slidePlaying の使用: src/components/messageInput.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the state management for `slidePlaying` by checking its usage in the codebase.

# Test: Search for the `slideStore` usage. Expect: Correct state management for `isPlaying`.
ast-grep --lang typescript --pattern $'const slidePlaying = slideStore((s) => s.isPlaying)'

Length of output: 92


Script:

#!/bin/bash
# Description: Search for the definition and usage of `slideStore` in the codebase.

# Search for the definition of `slideStore`.
rg 'slideStore' -A 5

# Search for any imports related to `slideStore`.
rg 'import .*slideStore' -A 2

Length of output: 9110

src/components/settings/youtube.tsx (2)

18-18: slideModeの使用を確認してください。

slideModeが正しく設定され、他の部分で適切に使用されていることを確認してください。

Verification successful

slideModeは適切に使用されています。

slideModeは複数のファイルで一貫して使用されており、settingsStoreから取得され、条件付きレンダリングや状態管理に利用されています。

  • src/components/form.tsx
  • src/components/menu.tsx
  • src/components/settings/youtube.tsx
  • src/components/settings/slide.tsx
  • src/features/chat/handlers.ts

この確認により、slideModeがコードベース内で適切に統合されていることが確認されました。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `slideMode` in the codebase.

# Test: Search for the usage of `slideMode`. Expect: Relevant usage in the codebase.
rg --type js --type jsx --type ts --type tsx 'slideMode'

Length of output: 84


Script:

#!/bin/bash
# Description: Verify the usage of `slideMode` in the codebase.

# Corrected Test: Search for the usage of `slideMode`. Expect: Relevant usage in the codebase.
rg --type js --type ts --type tsx 'slideMode'

Length of output: 73


Script:

#!/bin/bash
# Description: Verify the usage of `slideMode` in the codebase.

# Corrected Test: Search for the usage of `slideMode`. Expect: Relevant usage in the codebase.
rg --type js --type ts 'slideMode'

Length of output: 1171


99-101: disabledプロパティのロジックを確認してください。

slideModeがtrueの場合に要素が無効になることを確認してください。

locales/ja/translation.json (4)

6-6: "SlideSettings"の追加が正しいです。

新しいスライド設定の翻訳が正しく追加されています。


104-104: "SlideMode"の追加が正しいです。

スライドモードの翻訳が正しく追加されています。


105-105: "SelectedSlideDocs"の追加が正しいです。

選択されたスライドドキュメントの翻訳が正しく追加されています。


106-106: "SlideModeDescription"の追加が正しいです。

スライドモードの説明が正しく翻訳されています。

src/components/marpSlides.tsx (10)

1-6: インポートが正しいです。

必要なモジュールが正しくインポートされています。


12-15: goToSlide関数が正しいです。

スライドのインデックスが正しく更新されています。


18-24: 状態管理が正しいです。

状態変数が正しく初期化され、使用されています。


26-39: スライドの可視性管理が正しいです。

現在のスライドインデックスに基づいてスライドの可視性が正しく更新されています。


86-101: カスタムCSSの適用が正しいです。

カスタムCSSが正しく適用され、コンポーネントのアンマウント時に削除されています。


103-118: readSlide関数が正しいです。

スライドスクリプトが正しく取得され、メッセージ処理に統合されています。


122-134: nextSlide関数が正しいです。

スライドの状態が正しく更新され、スライドデッキの終わりが適切に処理されています。


136-140: prevSlide関数が正しいです。

スライドインデックスが正しく更新されています。


142-150: toggleIsPlaying関数が正しいです。

再生状態が正しく管理され、再生中にスライドが読み込まれています。


162-199: コンポーネントのレンダリングが正しいです。

スライドコンテンツとコントロールが正しく構造化され、スタイルが適用されています。

src/components/menu.tsx (5)

7-7: スライドストアのインポートが適切です。

slideStore のインポートは、スライド関連の状態管理に必要です。


21-22: スライド関連の状態変数の使用が適切です。

slideModeslideVisibleslidePlaying は、スライド機能の管理に必要です。

Also applies to: 27-27


34-34: スライドドキュメントとコンテンツの状態管理が適切です。

selectedSlideDocsmarkdownContent の状態管理は、スライドコンテンツの動的表示に必要です。

Also applies to: 37-37


183-193: スライドとトグルボタンのレンダリングロジックが適切です。

スライドとトグルボタンの条件付きレンダリングは、スライド管理機能と一致しています。


198-198: MarpSlides コンポーネントのレンダリング条件が適切です。

slideModeslideVisible に基づいて MarpSlides がレンダリングされるため、スライドが正しく表示されます。

src/components/settings/modelProvider.tsx (3)

5-5: インポートが適切です。

slideStoreuseCallback のインポートは、新しい機能のために必要です。

Also applies to: 9-9


40-68: handleAIServiceChange 関数のロジックが適切です。

AIサービスの変更を処理するためのロジックが中央集約され、パフォーマンスが最適化されています。


79-81: onChange ハンドラーの統合が適切です。

handleAIServiceChange を使用することで、メンテナンス性と明確さが向上しています。

src/features/chat/handlers.ts (5)

5-5: インポートが適切です。

judgeSlidegoToSlide のインポートは、チャットハンドラーでのスライド機能統合に必要です。

Also applies to: 9-10


20-127: processReceivedMessage 関数のロジックが適切です。

メッセージ処理のモジュール化により、コードの明確さと関心の分離が向上しています。

Tools
Biome

[error] 40-41: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


199-224: processAIResponse への統合が適切です。

processReceivedMessage の統合により、メンテナンス性が向上しています。


397-431: スライド関連のロジックが適切です。

handleSendChatFn 内のスライド関連ロジックにより、動的なスライド操作がサポートされています。


40-41: オプショナルチェーンの使用を検討してください。

プロパティアクセスの安全性を向上させるために、オプショナルチェーンを使用することを検討してください。

  const handleAIServiceChange = useCallback(
    (newService: keyof typeof defaultModels) => {
      settingsStore.setState({
        selectAIService: newService,
        selectAIModel: defaultModels[newService],
      })

Likely invalid or redundant comment.

Tools
Biome

[error] 40-41: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

{marpitContainer && (
<div
style={{ width: '100%', height: '100%', overflow: 'hidden' }}
dangerouslySetInnerHTML={{ __html: marpitContainer.outerHTML }}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

セキュリティリスク: dangerouslySetInnerHTMLの使用を避ける

dangerouslySetInnerHTMLを使用すると、XSS攻撃のリスクが高まります。信頼できるデータのみを使用するか、別の方法でHTMLをレンダリングすることを検討してください。

Tools
Biome

[error] 13-13: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)

Comment on lines +10 to +11
if (req.method === 'POST') {
const { slideName } = req.body as { slideName: string }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

リクエストボディのバリデーションを追加

slideName がリクエストボディに含まれていることを確認するバリデーションを追加すると、より堅牢なコードになります。

if (!slideName) {
  return res.status(400).json({ message: 'slideName is required' })
}

Comment on lines +12 to +13
if (typeof slideDocs !== 'string') {
return res.status(400).json({ error: 'Invalid slideDocs parameter' })
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

パラメータ検証の強化

slideDocsパラメータの検証が不足しています。パスのトラバーサル攻撃を防ぐために、パラメータをより厳密に検証することをお勧めします。

// Example: Validate slideDocs to ensure it does not contain directory traversal sequences
if (!/^[\w-]+$/.test(slideDocs)) {
  return res.status(400).json({ error: 'Invalid slideDocs parameter' });
}

Comment on lines +21 to +28
return (
<div
style={{
display: 'flex',
justifyContent: 'center',
marginTop: '20px',
}}
>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

スタイルの外部化を検討

インラインスタイルを外部のスタイルシートに移動することで、スタイルの再利用性とメンテナンス性が向上します。

// Example: Move styles to a CSS module or styled-components
const containerStyle = {
  display: 'flex',
  justifyContent: 'center',
  marginTop: '20px',
}

Comment on lines 39 to 43
useEffect(() => {
fetch(`/slides/${selectedSlideDocs}/slides.md`)
.then((response) => response.text())
.then((text) => setMarkdownContent(text))
}, [selectedSlideDocs])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

エラーハンドリングを追加してください。

useEffect 内でマークダウンコンテンツを取得する際に、エラーハンドリングを追加すると、より堅牢になります。

  useEffect(() => {
    fetch(`/slides/${selectedSlideDocs}/slides.md`)
      .then((response) => response.text())
      .then((text) => setMarkdownContent(text))
+     .catch((error) => console.error('Failed to fetch markdown content:', error))
  }, [selectedSlideDocs])
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
useEffect(() => {
fetch(`/slides/${selectedSlideDocs}/slides.md`)
.then((response) => response.text())
.then((text) => setMarkdownContent(text))
}, [selectedSlideDocs])
useEffect(() => {
fetch(`/slides/${selectedSlideDocs}/slides.md`)
.then((response) => response.text())
.then((text) => setMarkdownContent(text))
.catch((error) => console.error('Failed to fetch markdown content:', error))
}, [selectedSlideDocs])

Copy link

@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: 6

Outside diff range, codebase verification and nitpick comments (4)
src/pages/api/getSlideFolders.ts (1)

14-17: エラーハンドリングを強化してください。

エラーが発生した際に詳細な情報をログに記録することは重要ですが、ユーザーに返すエラーメッセージも改善する余地があります。エラーの内容に応じて異なるメッセージを返すことを検討してください。

src/features/chat/handlers.ts (3)

215-227: エラーハンドリングを強化してください。

ストリームが終了した際に残りのメッセージを処理する部分で、エラーハンドリングが不足しています。例外が発生した場合に備えて、適切なエラーハンドリングを追加することを検討してください。


Line range hint 236-282:
ロジックを簡素化してください。

aiTextLogの処理部分は複雑で、読みづらいです。役割ごとに処理を分け、関数に切り出すことで、コードの可読性を向上させることができます。

const mergeMessages = (messages: Message[]): Message[] => {
  let lastImageUrl = ''
  return messages.reduce((acc: Message[], item: Message) => {
    // ここにロジックを移動
    return acc
  }, [])
}

aiTextLog = mergeMessages(aiTextLog).filter((item) => item.content !== '')

398-435: エラーハンドリングを強化してください。

スライドモードの処理中にエラーが発生した場合、ユーザーに適切なフィードバックを提供するために、エラーハンドリングを改善することを検討してください。

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 84a233f and f5c3175.

Files selected for processing (6)
  • src/components/menu.tsx (4 hunks)
  • src/components/settings/slide.tsx (1 hunks)
  • src/components/slides.tsx (1 hunks)
  • src/features/chat/handlers.ts (9 hunks)
  • src/pages/api/convertMarkdown.ts (1 hunks)
  • src/pages/api/getSlideFolders.ts (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • src/components/menu.tsx
  • src/components/settings/slide.tsx
  • src/pages/api/convertMarkdown.ts
Additional context used
Biome
src/features/chat/handlers.ts

[error] 40-41: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Additional comments not posted (3)
src/components/slides.tsx (3)

74-80: 動的に追加したスタイルのクリーンアップを確認してください。

useEffect内でスタイルを動的に追加していますが、アンマウント時に必ずクリーンアップすることが重要です。現在のコードはクリーンアップを行っていますが、他のuseEffectでも同様の確認が必要です。


103-120: useCallbackの依存関係を確認してください。

readSlide関数のuseCallbackフックにおいて、selectedSlideDocsのみが依存関係に含まれていますが、他の依存関係が必要かどうかを確認してください。例えば、requireで読み込むスクリプトが変更される可能性がある場合、依存関係を適切に設定する必要があります。


122-134: useCallbackを使用してパフォーマンスを最適化してください。

nextSlide関数はuseCallbackでメモ化されていますが、依存関係にslideCountisPlayingが含まれています。これらの依存関係が変更される頻度が高い場合、パフォーマンスに影響を与える可能性があります。必要に応じて、依存関係を見直してください。

import fs from 'fs'
import path from 'path'

export default function handler(req: any, res: any) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

非同期処理を使用することを検討してください。

現在、fs.readdirSyncを使用してディレクトリを同期的に読み込んでいますが、非同期バージョンのfs.promises.readdirを使用することで、パフォーマンスが向上し、サーバーの応答性が高まる可能性があります。

- const folders = fs.readdirSync(slidesDir, { withFileTypes: true })
+ const folders = await fs.promises.readdir(slidesDir, { withFileTypes: true })

Committable suggestion was skipped due to low confidence.


型安全性を向上させましょう。

reqresの型としてanyを使用していますが、NextApiRequestNextApiResponseを使用することで型安全性を向上させることができます。

- export default function handler(req: any, res: any) {
+ import { NextApiRequest, NextApiResponse } from 'next'
+ export default function handler(req: NextApiRequest, res: NextApiResponse) {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export default function handler(req: any, res: any) {
import { NextApiRequest, NextApiResponse } from 'next'
export default function handler(req: NextApiRequest, res: NextApiResponse) {

Comment on lines +26 to +39
useEffect(() => {
const currentMarpitContainer = document.querySelector('.marpit')
if (currentMarpitContainer) {
const slides = currentMarpitContainer.querySelectorAll(':scope > svg')
slides.forEach((slide, i) => {
const svgElement = slide as SVGElement
if (i === currentSlide) {
svgElement.style.display = 'block'
} else {
svgElement.style.display = 'none'
}
})
}
}, [currentSlide, marpitContainer])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useEffectのロジックを簡素化してください。

このuseEffectフックではスライドの表示を管理していますが、ロジックが複雑です。例えば、スライドの表示/非表示を管理する部分を別の関数に切り出すことで、可読性を向上させることができます。

useEffect(() => {
  const updateSlideVisibility = (slides, currentSlide) => {
    slides.forEach((slide, i) => {
      slide.style.display = i === currentSlide ? 'block' : 'none'
    })
  }

  const currentMarpitContainer = document.querySelector('.marpit')
  if (currentMarpitContainer) {
    const slides = currentMarpitContainer.querySelectorAll(':scope > svg')
    updateSlideVisibility(slides, currentSlide)
  }
}, [currentSlide, marpitContainer])

Comment on lines +164 to +198
<div
className="absolute"
style={{
width: '80vw',
height: 'calc(80vw * (9 / 16))',
top: 'calc((100vh - 80vw * (9 / 16)) / 2)',
right: 0,
left: 0,
margin: 'auto',
}}
>
<SlideContent marpitContainer={marpitContainer} />
</div>
<div
className="absolute"
style={{
width: '80vw',
top: 'calc((100vh + 80vw * (7 / 16)) / 2)',
right: 0,
left: 0,
margin: 'auto',
zIndex: 10,
}}
>
<SlideControls
currentSlide={currentSlide}
slideCount={slideCount}
isPlaying={isPlaying}
prevSlide={prevSlide}
nextSlide={nextSlide}
toggleIsPlaying={toggleIsPlaying}
/>
</div>
</>
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

スタイルのインライン指定を改善してください。

インラインスタイルを使用すると、スタイルの管理が難しくなることがあります。スタイルをCSSクラスに移動することを検討してください。これにより、スタイルの再利用性と可読性が向上します。

<div className="slide-container">
  <SlideContent marpitContainer={marpitContainer} />
</div>
<div className="slide-controls">
  <SlideControls
    currentSlide={currentSlide}
    slideCount={slideCount}
    isPlaying={isPlaying}
    prevSlide={prevSlide}
    nextSlide={nextSlide}
    toggleIsPlaying={toggleIsPlaying}
  />
</div>
.slide-container {
  width: 80vw;
  height: calc(80vw * (9 / 16));
  top: calc((100vh - 80vw * (9 / 16)) / 2);
  right: 0;
  left: 0;
  margin: auto;
}

.slide-controls {
  width: 80vw;
  top: calc((100vh + 80vw * (7 / 16)) / 2);
  right: 0;
  left: 0;
  margin: auto;
  z-index: 10;
}

Comment on lines +199 to +213
// 完全な文を処理
const sentenceMatch = receivedMessage.match(/^(.+?[。..!?!?\n])/)
if (sentenceMatch) {
let sentence = sentenceMatch[0]
receivedMessage = receivedMessage.slice(sentence.length)

await processReceivedMessage(
sentence,
sentences,
aiTextLog,
tag,
isCodeBlock,
codeBlockText
)
if (sentenceMatch?.[0]) {
let sentence = sentenceMatch[0]
// 区切った文字をsentencesに追加
sentences.push(sentence)
// 区切った文字の残りでreceivedMessageを更新
receivedMessage = receivedMessage.slice(sentence.length).trimStart()

// 発話不要/不可能な文字列だった場合はスキップ
if (
!sentence.includes('```') &&
!sentence.replace(
/^[\s\u3000\t\n\r\[\(\{「[(【『〈《〔{«‹〘〚〛〙›»〕》〉』】)]」\}\)\]'"''""・、。,.!?!?::;;\-_=+~~**@@##$$%%^^&&||\\\//``]+$/gu,
''
)
) {
continue
}

// タグと返答を結合(音声再生で使用される)
let aiText = `${tag} ${sentence}`
console.log('aiText', aiText)

if (isCodeBlock && !sentence.includes('```')) {
codeBlockText += sentence
continue
}

if (sentence.includes('```')) {
if (isCodeBlock) {
// コードブロックの終了処理
const [codeEnd, ...restOfSentence] = sentence.split('```')
aiTextLog.push({
role: 'code',
content: codeBlockText + codeEnd,
})
aiText += `${tag} ${restOfSentence.join('```') || ''}`

// AssistantMessage欄の更新
homeStore.setState({ assistantMessage: sentences.join(' ') })

codeBlockText = ''
isCodeBlock = false
} else {
// コードブロックの開始処理
isCodeBlock = true
;[aiText, codeBlockText] = aiText.split('```')
}

sentence = sentence.replace(/```/g, '')
}

const aiTalks = textsToScreenplay([aiText], ss.koeiroParam)
aiTextLog.push({ role: 'assistant', content: sentence })

// 文ごとに音声を生成 & 再生、返答を表示
const currentAssistantMessage = sentences.join(' ')
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ロジックを簡素化してください。

processAIResponse関数内での文の処理ロジックが複雑です。processReceivedMessageを呼び出す部分を関数に切り出すことで、コードの可読性とメンテナンス性を向上させることができます。

const processSentence = async (sentence: string) => {
  await processReceivedMessage(
    sentence,
    sentences,
    aiTextLog,
    tag,
    isCodeBlock,
    codeBlockText
  )
}

if (sentenceMatch) {
  let sentence = sentenceMatch[0]
  receivedMessage = receivedMessage.slice(sentence.length)
  await processSentence(sentence)
}

Comment on lines +40 to +41
while (receivedMessage.length > 0) {
const sentenceMatch = receivedMessage.match(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

オプショナルチェーンを使用してください。

receivedMessage.matchの結果を使用する際に、オプショナルチェーンを使用することで、コードの安全性と可読性を向上させることができます。

- const sentenceMatch = receivedMessage.match(/^(.+?[。..!?!?\n]|.{20,}[、,])/)
+ const sentenceMatch = receivedMessage.match(/^(.+?[。..!?!?\n]|.{20,}[、,])/)?.[0]
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
while (receivedMessage.length > 0) {
const sentenceMatch = receivedMessage.match(
while (receivedMessage.length > 0) {
const sentenceMatch = receivedMessage.match(/^(.+?[。..!?!?\n]|.{20,}[、,])/)?.[0]
Tools
Biome

[error] 40-41: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f5c3175 and 645385f.

Files selected for processing (4)
  • locales/en/translation.json (2 hunks)
  • locales/ko/translation.json (2 hunks)
  • locales/zh/translation.json (2 hunks)
  • src/pages/api/getSlideFolders.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/pages/api/getSlideFolders.ts
Additional comments not posted (12)
locales/zh/translation.json (4)

6-6: エントリ「SlideSettings」は正しく翻訳されています。
このエントリは既存のスタイルと一貫しています。


103-103: エントリ「SlideMode」は正しく翻訳されています。
このエントリは文脈に合っています。


104-104: エントリ「SelectedSlideDocs」は正しく翻訳されています。
このエントリは他のエントリと一貫しています。


105-105: エントリ「SlideModeDescription」は正しく翻訳されています。
このエントリは明確な説明を提供しています。

locales/ko/translation.json (4)

6-6: エントリ「SlideSettings」は正しく翻訳されています。
このエントリは既存のスタイルと一貫しています。


103-103: エントリ「SlideMode」は正しく翻訳されています。
このエントリは文脈に合っています。


104-104: エントリ「SelectedSlideDocs」は正しく翻訳されています。
このエントリは他のエントリと一貫しています。


105-105: エントリ「SlideModeDescription」は正しく翻訳されています。
このエントリは明確な説明を提供しています。

locales/en/translation.json (4)

6-6: エントリ「SlideSettings」は正しく翻訳されています。
このエントリは既存のスタイルと一貫しています。


103-103: エントリ「SlideMode」は正しく翻訳されています。
このエントリは文脈に合っています。


104-104: エントリ「SelectedSlideDocs」は正しく翻訳されています。
このエントリは他のエントリと一貫しています。


105-105: エントリ「SlideModeDescription」は正しく翻訳されています。
このエントリは明確な説明を提供しています。

@tegnike tegnike changed the base branch from main to develop August 13, 2024 19:52
@tegnike tegnike merged commit 52af2d7 into develop Aug 13, 2024
3 checks passed
@tegnike tegnike deleted the feature/add-slide-mode branch August 18, 2024 16: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.

1 participant