Skip to content

refactor: extract shared AI API logic into useAIFetch composable#1439

Merged
yanglbme merged 3 commits intomainfrom
refactor/ai
Apr 6, 2026
Merged

refactor: extract shared AI API logic into useAIFetch composable#1439
yanglbme merged 3 commits intomainfrom
refactor/ai

Conversation

@yanglbme
Copy link
Copy Markdown
Member

@yanglbme yanglbme commented Apr 6, 2026

  • Add useAIFetch composable with buildAIHeaders, resolveEndpointUrl, fetchSSE (streaming), and fetchJSON (non-streaming) utilities
  • Refactor AIConfig and AIImageConfig to use shared header/URL/fetch helpers
  • Refactor AIAssistantPanel to use fetchSSE for stream parsing

- Add useAIFetch composable with buildAIHeaders, resolveEndpointUrl,
  fetchSSE (streaming), and fetchJSON (non-streaming) utilities
  - Refactor AIConfig and AIImageConfig to use shared header/URL/fetch
    helpers
    - Refactor AIAssistantPanel to use fetchSSE for stream parsing
    - Refactor ToolBoxPopover to use fetchSSE for stream parsing
    - Merge duplicate generateImage/regenerateWithPrompt into single
      doGenerateImage in AIImageGeneratorPanel
      - Remove ~190 lines of duplicated code across 5 components
Copilot AI review requested due to automatic review settings April 6, 2026 13:11
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

🚀 Surge Preview has been successfully deployed!

Preview URL: https://doocs-md-preview-pr-1439.surge.sh

Built with commit 258cba7

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the web app’s AI integration by extracting shared request header building, endpoint URL resolution, and streaming/non-streaming fetch helpers into a new useAIFetch composable, then updating the AI chat/image UI to use the shared utilities.

Changes:

  • Added useAIFetch with buildAIHeaders, resolveEndpointUrl, fetchSSE, and fetchJSON.
  • Refactored AI chat/image config “test connection” flows to use shared header/URL + fetchJSON.
  • Refactored streaming chat/toolbox flows to use fetchSSE and centralize SSE parsing.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
apps/web/src/composables/useAIFetch.ts New shared AI fetch utilities (headers, endpoint normalization, SSE + JSON fetch helpers).
apps/web/src/components/ai/tool-box/ToolBoxPopover.vue Uses shared header/URL helpers and fetchSSE for streaming toolbox actions.
apps/web/src/components/ai/image-generator/AIImageGeneratorPanel.vue Reuses shared header/URL helpers and consolidates image generation logic.
apps/web/src/components/ai/image-generator/AIImageConfig.vue Uses shared header/URL helpers and fetchJSON for connection testing.
apps/web/src/components/ai/chat-box/AIConfig.vue Uses shared header/URL helpers and fetchJSON for connection testing.
apps/web/src/components/ai/chat-box/AIAssistantPanel.vue Uses shared header/URL helpers and fetchSSE for streaming response parsing.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

🚀 Cloudflare Workers Preview has been successfully deployed!

Preview URL: https://md-pr-1439.doocs.workers.dev

Built with commit 258cba7

@yanglbme yanglbme merged commit 8145337 into main Apr 6, 2026
2 checks passed
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

🗑️ Cloudflare Workers preview deployment has been cleaned up.

@yanglbme yanglbme deleted the refactor/ai branch April 6, 2026 13:36
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