Skip to content

fix: change fetch to http service#1577

Merged
chilingling merged 2 commits intoopentiny:release/v2.8.xfrom
hexqi:fix/mcp-http
Aug 12, 2025
Merged

fix: change fetch to http service#1577
chilingling merged 2 commits intoopentiny:release/v2.8.xfrom
hexqi:fix/mcp-http

Conversation

@hexqi
Copy link
Collaborator

@hexqi hexqi commented Aug 7, 2025

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

  • 替换fetch为HttpService,解决后端请求权限问题
  • 支持完全替换大模型列表

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Bug Fixes

    • Improved response handling to ensure more reliable data retrieval in certain scenarios.
  • Refactor

    • Updated internal HTTP request logic for better consistency and maintainability.
    • Modified component prop to make the type property optional for increased flexibility.
    • Adjusted AI model selection to prioritize custom models when available.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 7, 2025

Walkthrough

Four files were modified: an HTTP utility in the designer demo, a Vue component prop definition, a utility function for LLM API requests, and an AI model options function. The changes update return value fallback logic, make a prop optional, refactor POST request handling to use an internal HTTP client abstraction instead of the native fetch API, and adjust model options fallback behavior.

Changes

Cohort / File(s) Change Summary
HTTP Response Handling Update
designer-demo/src/composable/http/index.js
Modified preResponse to return res.data?.data if present, otherwise res.data.
Component Prop Optionalization
packages/plugins/robot/src/mcp/MarkdownRenderer.vue
Changed type prop from required to optional in the component's props definition.
HTTP Client Abstraction Refactor
packages/plugins/robot/src/mcp/utils.ts
Replaced native fetch with getMetaApi(META_SERVICE.Http).post in fetchLLM, returning parsed JSON.
AI Model Options Fallback Change
packages/plugins/robot/src/js/robotSetting.ts
Modified getAIModelOptions to return custom models if present; otherwise, return default models only.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant fetchLLM
    participant MetaApiHttp

    Caller->>fetchLLM: Call fetchLLM(url, body)
    fetchLLM->>MetaApiHttp: post(url, body)
    MetaApiHttp-->>fetchLLM: Parsed JSON response
    fetchLLM-->>Caller: JSON response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A nibble here, a tweak over there,
Optional props now float in the air.
HTTP calls take a new, tidy route—
No more fetch, just meta, how cute!
Models choose their own path to roam,
This bunny’s hopping through fields of code and home.
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b5146f2 and 4f2e81c.

📒 Files selected for processing (1)
  • packages/plugins/robot/src/js/robotSetting.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: gene9831
PR: opentiny/tiny-engine#1041
File: packages/plugins/datasource/src/DataSourceList.vue:138-138
Timestamp: 2025-01-14T10:06:25.508Z
Learning: PR #1041 in opentiny/tiny-engine is specifically for reverting Prettier v3 formatting to v2, without any logical code changes or syntax improvements.
Learnt from: gene9831
PR: opentiny/tiny-engine#1038
File: packages/plugins/block/index.js:24-24
Timestamp: 2025-01-14T08:42:18.574Z
Learning: In the tiny-engine project, breaking changes are documented in the changelog rather than in JSDoc comments or separate migration guides.
Learnt from: rhlin
PR: opentiny/tiny-engine#1011
File: packages/canvas/render/src/RenderMain.ts:82-88
Timestamp: 2025-01-14T08:50:50.226Z
Learning: For PR #1011, the focus is on resolving conflicts and migrating code, with architectural improvements deferred for future PRs.
Learnt from: gene9831
PR: opentiny/tiny-engine#917
File: docs/开始/快速上手.md:31-31
Timestamp: 2024-12-14T05:53:28.501Z
Learning: The latest stable version of `opentiny/tiny-engine-cli` is `2.0.0`, and documentation should reference this version instead of any release candidates.
Learnt from: chilingling
PR: opentiny/tiny-engine#817
File: packages/vue-generator/src/plugins/appendElePlusStylePlugin.js:46-50
Timestamp: 2024-10-09T01:47:35.507Z
Learning: In `appendElePlusStylePlugin.js`, the code uses `|| {}` to set default values when obtaining files, so additional null checks may not be necessary.
Learnt from: chilingling
PR: opentiny/tiny-engine#817
File: packages/vue-generator/src/plugins/appendElePlusStylePlugin.js:46-50
Timestamp: 2024-09-25T11:18:00.771Z
Learning: In `appendElePlusStylePlugin.js`, the code uses `|| {}` to set default values when obtaining files, so additional null checks may not be necessary.
🔇 Additional comments (1)
packages/plugins/robot/src/js/robotSetting.ts (1)

20-23: LGTM! Improved fallback logic for AI model options.

The change correctly implements an either/or fallback pattern instead of always concatenating both model lists. This prevents duplication and gives proper precedence to custom models when available, falling back to defaults only when needed.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
  • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@github-actions github-actions bot added bug Something isn't working release merge to release/ branch, before release period labels Aug 7, 2025
Copy link
Contributor

@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

🧹 Nitpick comments (1)
packages/plugins/robot/src/mcp/MarkdownRenderer.vue (1)

29-29: The type prop is defined but never used in the component.

While making the prop optional is fine, the type prop is not referenced anywhere in the template or script logic. Consider removing it entirely if it's not needed, or implement the logic to handle different content types if it serves a purpose.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3059a7 and b5146f2.

📒 Files selected for processing (3)
  • designer-demo/src/composable/http/index.js (1 hunks)
  • packages/plugins/robot/src/mcp/MarkdownRenderer.vue (1 hunks)
  • packages/plugins/robot/src/mcp/utils.ts (4 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: gene9831
PR: opentiny/tiny-engine#1041
File: packages/plugins/datasource/src/DataSourceList.vue:138-138
Timestamp: 2025-01-14T10:06:25.508Z
Learning: PR #1041 in opentiny/tiny-engine is specifically for reverting Prettier v3 formatting to v2, without any logical code changes or syntax improvements.
Learnt from: gene9831
PR: opentiny/tiny-engine#1038
File: packages/plugins/block/index.js:24-24
Timestamp: 2025-01-14T08:42:18.574Z
Learning: In the tiny-engine project, breaking changes are documented in the changelog rather than in JSDoc comments or separate migration guides.
Learnt from: rhlin
PR: opentiny/tiny-engine#1011
File: packages/canvas/render/src/RenderMain.ts:82-88
Timestamp: 2025-01-14T08:50:50.226Z
Learning: For PR #1011, the focus is on resolving conflicts and migrating code, with architectural improvements deferred for future PRs.
Learnt from: gene9831
PR: opentiny/tiny-engine#917
File: docs/开始/快速上手.md:31-31
Timestamp: 2024-12-14T05:53:28.501Z
Learning: The latest stable version of `opentiny/tiny-engine-cli` is `2.0.0`, and documentation should reference this version instead of any release candidates.
Learnt from: rhlin
PR: opentiny/tiny-engine#1011
File: packages/canvas/render/src/canvas-function/custom-renderer.ts:28-32
Timestamp: 2025-01-14T07:11:44.138Z
Learning: The locale and webComponent wrapper in `packages/canvas/render/src/canvas-function/custom-renderer.ts` are part of migrated code and will be improved in a future PR.
Learnt from: yy-wow
PR: opentiny/tiny-engine#886
File: packages/toolbars/logout/src/js/http.js:16-16
Timestamp: 2024-10-30T02:19:30.876Z
Learning: In the `packages/toolbars/logout/src/js/http.js` file, errors for the `requestLogout` function are handled by the user, so additional error handling within the function is not necessary.
Learnt from: chilingling
PR: opentiny/tiny-engine#817
File: packages/vue-generator/src/plugins/appendElePlusStylePlugin.js:46-50
Timestamp: 2024-10-09T01:47:35.507Z
Learning: In `appendElePlusStylePlugin.js`, the code uses `|| {}` to set default values when obtaining files, so additional null checks may not be necessary.
Learnt from: chilingling
PR: opentiny/tiny-engine#817
File: packages/vue-generator/src/plugins/appendElePlusStylePlugin.js:46-50
Timestamp: 2024-09-25T11:18:00.771Z
Learning: In `appendElePlusStylePlugin.js`, the code uses `|| {}` to set default values when obtaining files, so additional null checks may not be necessary.
📚 Learning: in `packages/common/component/metachilditem.vue`, when checking if `text` is an object in the comput...
Learnt from: gene9831
PR: opentiny/tiny-engine#830
File: packages/common/component/MetaChildItem.vue:50-56
Timestamp: 2024-10-15T02:45:17.168Z
Learning: In `packages/common/component/MetaChildItem.vue`, when checking if `text` is an object in the computed property `title`, ensure that `text` is not `null` because `typeof null === 'object'` in JavaScript. Use checks like `text && typeof text === 'object'` to safely handle `null` values.

Applied to files:

  • packages/plugins/robot/src/mcp/MarkdownRenderer.vue
📚 Learning: in `packages/toolbars/generate-code/src/http.js`, functions like `fetchpagelist` do not perform para...
Learnt from: yy-wow
PR: opentiny/tiny-engine#886
File: packages/toolbars/generate-code/src/http.js:37-37
Timestamp: 2024-10-30T02:19:46.574Z
Learning: In `packages/toolbars/generate-code/src/http.js`, functions like `fetchPageList` do not perform parameter validation since errors are handled by the caller.

Applied to files:

  • packages/plugins/robot/src/mcp/utils.ts
📚 Learning: in the tiny-engine project, the mockserver code uses es6 import syntax but is compiled to commonjs o...
Learnt from: hexqi
PR: opentiny/tiny-engine#1501
File: mockServer/src/tool/Common.js:79-82
Timestamp: 2025-07-03T09:22:59.512Z
Learning: In the tiny-engine project, the mockServer code uses ES6 import syntax but is compiled to CommonJS output. This means CommonJS globals like `__dirname` are available at runtime, while ES6 module-specific features like `import.meta` would cause runtime errors.

Applied to files:

  • packages/plugins/robot/src/mcp/utils.ts
📚 Learning: 在 `packages/common/composable` 目录中,`httpservice` 模块位于 `./http/index.js`,而不是 `./http.js`。...
Learnt from: yy-wow
PR: opentiny/tiny-engine#886
File: packages/common/composable/index.js:3-3
Timestamp: 2024-10-30T02:10:38.028Z
Learning: 在 `packages/common/composable` 目录中,`HttpService` 模块位于 `./http/index.js`,而不是 `./http.js`。

Applied to files:

  • designer-demo/src/composable/http/index.js
📚 Learning: in `packages/http/src/index.js`, using `return` inside a `foreach` loop's callback function exits th...
Learnt from: yy-wow
PR: opentiny/tiny-engine#863
File: packages/http/src/index.js:93-101
Timestamp: 2024-10-16T02:11:54.972Z
Learning: In `packages/http/src/index.js`, using `return` inside a `forEach` loop's callback function exits the current iteration and proceeds to the next, effectively skipping to the next element.

Applied to files:

  • designer-demo/src/composable/http/index.js
🧬 Code Graph Analysis (1)
packages/plugins/robot/src/mcp/utils.ts (2)
packages/register/src/common.ts (1)
  • getMetaApi (20-30)
packages/register/src/constants.ts (1)
  • META_SERVICE (1-23)
⏰ 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: push-check
🔇 Additional comments (5)
designer-demo/src/composable/http/index.js (1)

49-49: LGTM! Improved response data handling.

The updated fallback logic res.data?.data || res.data provides more robust handling of different response structures, which aligns well with the HTTP service migration.

packages/plugins/robot/src/mcp/utils.ts (4)

5-5: LGTM! Proper import of meta API services.

The import correctly brings in the meta service registry for HTTP abstraction.


18-23: LGTM! Successfully migrated from fetch to HTTP service.

The migration from fetch to getMetaApi(META_SERVICE.Http).post is well-executed. The meta API service handles JSON parsing automatically, eliminating the need for manual response processing.


84-84: LGTM! Correctly updated fetchLLM call.

The removal of .then(res => res.json()) is appropriate since the meta API HTTP service returns parsed JSON directly.


105-105: LGTM! Correctly updated fetchLLM call.

The removal of .then(res => res.json()) is consistent with the HTTP service migration that returns parsed JSON directly.

@chilingling chilingling merged commit 01eb9f6 into opentiny:release/v2.8.x Aug 12, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working release merge to release/ branch, before release period

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants