Skip to content

Convert AI assistant from batch to streaming API#165

Draft
Copilot wants to merge 213 commits intomainfrom
copilot/convert-batch-to-stream
Draft

Convert AI assistant from batch to streaming API#165
Copilot wants to merge 213 commits intomainfrom
copilot/convert-batch-to-stream

Conversation

Copy link
Contributor

Copilot AI commented Dec 8, 2025

AI Assistant Streaming Implementation

完了した実装内容:

1. ストリーミングAPI関数の実装

  • streamChatResponse: Askモード用のストリーミング関数
  • streamCodeEdit: Editモード用のストリーミング関数
  • 旧バッチ関数(generateCodeEdit, generateChatResponse)の削除

2. useAIフックの更新

  • ストリーミング状態管理(streamingContent)の追加
  • リアルタイムでの増分更新処理
  • Editモードでのファイル編集時の特別な処理(コード生成中)

3. ChatContainerコンポーネントの更新

  • ストリーミングメッセージのリアルタイム表示
  • Markdownレンダリング対応
  • ストリーミングインジケーター表示

4. 品質保証

  • コードレビュー対応(未使用変数の削除)
  • 翻訳キーの確認
  • セキュリティチェック(CodeQL): 問題なし
  • ビルドチェック: 成功

5. バグ修正

  • 400エラー修正: &alt=sseパラメータを削除
  • Google AI API仕様に準拠したJSON形式のパース

技術的な詳細:

  • Gemini API: streamGenerateContentエンドポイントを使用
  • ストリーミング形式: 改行区切りのJSON形式(SSEではない)
  • リアルタイム表示: チャンクごとにUIを更新
  • Editモード: 完全なレスポンスを蓄積後にファイル変更をパース
  • 後方互換性: 既存のメッセージ構造とワークフローを維持

変更ファイル:

  • src/engine/ai/fetchAI.ts (修正: ストリーミングAPI実装)
  • src/hooks/ai/useAI.ts (43行変更)
  • src/components/AI/chat/ChatContainer.tsx (98行変更)
  • src/components/AI/AIPanel.tsx (2行変更)
Original prompt

今、ai assistantがbatch形式だからstream形式に修正しよう。Editモードでのファイル編集のコード生成中の時、その扱いに注意してね。


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 30 commits December 3, 2025 04:53
…ect access

Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
…ssues

Fix useProject hook state isolation bug and AI chat space race condition
…load

Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
…load

fix(i18n): Cache initial locale to prevent repeated warnings on page load
Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
…uote-handling

Fix inline highlighter quote handling for Shell and JS/TS nested expressions
…emes

Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
… use 500px

Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
…rowing

Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
…tead of fileRepository listener

Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
… EditorTab

Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
…support both editor and diff tabs

Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
Fix DiffTab and AIReviewTab Monaco theme handling, layout, and tab reuse
- Changed from defining separate pyxis-dark/pyxis-light themes to a single pyxis-custom theme
- pyxis-custom theme now dynamically adapts based on colors (light/dark detection)
- Added cache key based on editor-related color properties to avoid unnecessary re-definitions
- Theme is only re-defined when relevant color properties change
- setTheme('pyxis-custom') is called on every mount to ensure consistency

Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
- Use LIGHT_THEMES list to determine light/dark theme
- Accept themeName parameter instead of computing from colors
- Remove getColorsCacheKey function and use themeName for caching
- Update all callers to pass themeName from useTheme()

Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
Fix Monaco theme handling for DiffTab consistency
- Remove batch API functions (generateCodeEdit, generateChatResponse)
- Add streaming functions (streamCodeEdit, streamChatResponse)
- Update useAI hook to use streaming with real-time content updates
- Add streaming content display in ChatContainer with markdown rendering
- Update AIPanel to pass streaming content to ChatContainer

Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
- Remove unused streamingMessageId state variable
- Verify translation keys exist (ai.chatContainer.generating)

Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
Copilot AI changed the title [WIP] Update ai assistant to use stream format Convert AI assistant from batch to streaming API Dec 8, 2025
Copilot AI requested a review from Stasshe December 8, 2025 01:42
@Stasshe
Copy link
Owner

Stasshe commented Dec 8, 2025

@copilot
400errorになりました。
https://ai.google.dev/api/generate-content?hl=ja#endpoint
を参照して。

- Gemini streaming API doesn't use SSE format with &alt=sse
- Parse JSON objects directly from newline-delimited stream
- Process remaining buffer at end of stream
- Follows Google AI API documentation for streamGenerateContent

Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 8, 2025

@copilot
400errorになりました。
https://ai.google.dev/api/generate-content?hl=ja#endpoint
...

Fixed in b8f4c4d. The issue was that Gemini's streaming API doesn't use the &alt=sse parameter. The API returns newline-delimited JSON objects instead of SSE format. Updated both streamChatResponse and streamCodeEdit to parse JSON directly from the stream.

@Stasshe Stasshe temporarily deployed to copilot/convert-batch-to-stream - pyxis-code PR #165 December 8, 2025 01:58 — with Render Destroyed
@Stasshe Stasshe force-pushed the main branch 5 times, most recently from 576b8e0 to 1bcd144 Compare December 13, 2025 06:19
@Stasshe Stasshe force-pushed the main branch 5 times, most recently from 1e8a41c to a412fb3 Compare January 30, 2026 00:43
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