Skip to content

Conversation

TensorNull
Copy link

@TensorNull TensorNull commented Sep 5, 2025

Related GitHub Issue

Open: #7688

Description

This PR integrates and hardens the CometAPI provider and improves the CometAPI Settings UX:

  • API fetcher

    • Accepts both OpenAI-like responses and CometAPI’s { success, data } shape with lenient Zod parsing.
    • Adds COMETAPI_IGNORE_PATTERNS and a compiled regex to filter out non-chat and utility models (image/audio/video/embeddings/moderation, etc.).
    • Adds a TODO to move to capability-based filtering once CometAPI upgrades the models API.
  • Router models plumbing

    • Only includes the cometapi entry in routerModels when an API key is present and the fetch succeeds (no default empty cometapi: {}).
    • Preserves per-provider error surfacing via singleRouterModelFetchResponse.
  • Provider runtime

    • Uses fallback models by default and merges API models when available.
    • Stable default model id and metadata paths preserved.
  • Webview Settings (CometAPI)

    • On-blur API key validation triggers model refresh and inline error feedback.
    • “Get CometAPI API Key” button shows when key is empty.
    • Always shows a non-empty list by merging dynamic models with fallback.
    • Hides ModelInfo for CometAPI only (renders a simple select without metadata) without changing shared ModelPicker API.
    • Adds zh-CN i18n keys where needed.
  • Types/Defaults

    • Refactors fallback models into a single readable array + builder for maintainability.

Test Procedure

Unit tests

  • Run the test suite; routerModels tests should pass with cometapi only present when a CometAPI API key is configured.
  • Error events for failed providers still emit singleRouterModelFetchResponse per provider.

Manual verification

  1. Without a CometAPI key:
    • Open Settings → CometAPI. A “Get CometAPI API Key” button is visible.
    • The model dropdown is populated from fallback models only.
    • No ModelInfo panel appears for CometAPI.
  2. With a valid CometAPI key:
    • Enter key and blur the input; models auto-refresh; no manual reopen required.
    • routerModels now includes cometapi populated from live API results (plus fallback merge).
    • Verify filtered models: ids containing “sd-”, “sdxl”, “dall-e”, “tts”, “whisper”, “embedding”, “moderation”, etc. are excluded.
  3. With an invalid key:
    • On blur, an inline error message is displayed from singleRouterModelFetchResponse.
  4. Router models envelope:
    • Confirm cometapi is not present when no key is provided; present when key exists and fetch succeeds.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the [Contributor Guidelines](/CONTRIBUTING.md).

Screenshots / Videos

  1. First time entering the CometAPI page
image
  1. If the CometAPI key is not verified, some default models will be provided for users to choose from.
2
  1. The correct CometAPI key can obtain filtered chat models
image

Documentation Updates

  • No documentation updates are required.

Additional Notes

Get in Touch

Discord: https://discord.gg/HMpuV6FCrG @james


Important

Integrates CometAPI as a new model provider, including API handling, model fetching, UI components, and validation support.

  • Behavior:
    • Adds CometAPIHandler in src/api/providers/cometapi.ts to handle CometAPI requests, supporting both OpenAI-like and CometAPI-specific response formats.
    • Integrates CometAPI into buildApiHandler() in src/api/index.ts.
    • Implements model fetching with getCometApiModels() in src/api/providers/fetchers/cometapi.ts, filtering out non-chat models.
  • Models:
    • Defines cometApiModels and default model info in packages/types/src/providers/cometapi.ts.
    • Updates providerSettingsSchema in packages/types/src/provider-settings.ts to include CometAPI settings.
  • UI:
    • Adds CometAPI component in webview-ui/src/components/settings/providers/CometAPI.tsx for settings UI.
    • Updates ApiOptions.tsx and ModelPicker.tsx to support CometAPI model selection.
    • Includes CometAPI in PROVIDERS and MODELS_BY_PROVIDER in constants.ts.
  • Validation:
    • Updates validate.ts to include CometAPI in API key and model validation.
    • Adds CometAPI to ProfileValidator in src/shared/ProfileValidator.ts.
  • Misc:
    • Adds CometAPI to SECRET_STATE_KEYS in global-settings.ts for secret management.
    • Updates webviewMessageHandler.ts to handle CometAPI model fetching and error reporting.

This description was created by Ellipsis for e676bf7. You can customize this summary. It will automatically update as commits are pushed.

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. enhancement New feature or request UI/UX UI/UX related or focused labels Sep 5, 2025
Copy link

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! I've reviewed the CometAPI provider integration and found several issues that need attention before merging.


// this should be changed to accurately filter chat models based on server-side fields, and remove the local regex-based ignore list and loose parsing logic.

// TODO(CometAPI): After the official model list interface is upgraded (returning richer type/capability fields or stable OpenAI compatible format)
Copy link

Choose a reason for hiding this comment

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

The regex-based filtering approach is fragile as noted in your TODO. Could we prioritize implementing capability-based filtering? This would be more maintainable and accurate than maintaining a regex pattern list.

Copy link
Author

Choose a reason for hiding this comment

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

The regex-based filtering approach is fragile as noted in your TODO. Could we prioritize implementing capability-based filtering? This would be more maintainable and accurate than maintaining a regex pattern list.

This will be improved after we complete the upgrade of the model list interface.

}

const url = `${baseUrl.replace(/\/$/, "")}/models`
console.log(`CometAPI: Fetching models from ${url}`)
Copy link

Choose a reason for hiding this comment

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

These console.log statements should be removed or wrapped in a debug condition before production. Consider using a debug flag or removing them entirely.

Copy link
Author

Choose a reason for hiding this comment

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

These console.log statements should be removed or wrapped in a debug condition before production. Consider using a debug flag or removing them entirely.

You are correct, I have already removed these statements.


export const cometApiDefaultModelInfo: ModelInfo = {
maxTokens: undefined, // Let system determine based on contextWindow
contextWindow: 200000, // Reasonable default for modern models
Copy link

Choose a reason for hiding this comment

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

Is a 200k context window a reasonable default for all models? This seems quite high and might not be accurate for many models. Consider using a more conservative default like 8192 or 16384.

Copy link
Author

Choose a reason for hiding this comment

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

Is a 200k context window a reasonable default for all models? This seems quite high and might not be accurate for many models. Consider using a more conservative default like 8192 or 16384.

Here I choose the same default parameters as LiteLLM, which will be improved after the model list interface is upgraded

if (axios.isAxiosError(error)) {
console.error(`CometAPI: API request failed: ${error.response?.status} ${error.response?.statusText}`)
console.error(`CometAPI: Response data:`, error.response?.data)
throw new Error(
Copy link

Choose a reason for hiding this comment

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

Could we make the error messages more specific? For example, distinguishing between authentication failures (401/403) vs network issues (timeout) vs server errors (500+) would help users troubleshoot.

Copy link
Author

Choose a reason for hiding this comment

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

Could we make the error messages more specific? For example, distinguishing between authentication failures (401/403) vs network issues (timeout) vs server errors (500+) would help users troubleshoot.

Good suggestion, I have added better error code feedback.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 5, 2025
TensorNull and others added 2 commits September 6, 2025 00:21
Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Sep 8, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Sep 8, 2025
@daniel-lxs
Copy link
Collaborator

Closing, please see #7688 (comment)

@daniel-lxs daniel-lxs closed this Sep 8, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Sep 8, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PR - Needs Preliminary Review size:XL This PR changes 500-999 lines, ignoring generated files. UI/UX UI/UX related or focused
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants