mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-10-25 17:22:27 +08:00
A provider's /models endpoint only returns model IDs, so a model picked from the fetched list left its context window, output limit, reasoning levels, and modalities empty, while the same model in a preset had them. When a model is picked in the Codex, OpenClaw, Hermes, OpenCode, or MiniMax Code form, look up its metadata field by field: 1. the preset model with the same endpoint (hand-verified values); 2. the models.dev provider whose API endpoint matches; 3. the vendor's own models.dev entry, without its price. Endpoints match only when host and path are equal after dropping a trailing version segment or request path, so plans that share a host (z.ai standard vs Coding Plan, OpenCode Zen vs Go) never borrow each other's values. Models are never matched by name across providers: the same model ID often has very different context windows per deployment. Only empty fields are filled, and reasoning or image input is only ever turned on. models.dev is prefetched once the model list is fetched and shared with the usage pricing import; when it arrives late the row is filled again, located by its stable row key. A single toast asks the user to review what was filled.
26 lines
767 B
TypeScript
26 lines
767 B
TypeScript
import { createElement, type ReactElement, type ReactNode } from "react";
|
||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||
import { render, type RenderOptions } from "@testing-library/react";
|
||
|
||
export const createTestQueryClient = () =>
|
||
new QueryClient({
|
||
defaultOptions: {
|
||
queries: {
|
||
retry: false,
|
||
},
|
||
},
|
||
});
|
||
|
||
/** `render`,外面包一层 QueryClientProvider(`rerender` 也保留)。 */
|
||
export const renderWithQueryClient = (
|
||
ui: ReactElement,
|
||
options?: Omit<RenderOptions, "wrapper">,
|
||
) => {
|
||
const client = createTestQueryClient();
|
||
return render(ui, {
|
||
...options,
|
||
wrapper: ({ children }: { children: ReactNode }) =>
|
||
createElement(QueryClientProvider, { client }, children),
|
||
});
|
||
};
|