CrossRelay stage 2: Codex /v1/responses relay, config.toml manager, Codex page
This commit is contained in:
1 parent
404704171d
commit
5112f7ca06
30 files changed
+3539
-72
No files matched your search
+19
-4
@@ -61,12 +61,27 @@ export const api = {
|
||||
request<Provider>(`/api/providers/${id}`, { method: "PUT", body: JSON.stringify(input) }),
|
||||
deleteProvider: (id: string) =>
|
||||
request<{ deleted: string }>(`/api/providers/${id}`, { method: "DELETE" }),
|
||||
applyProvider: (id: string) =>
|
||||
request<ApplyResult>(`/api/providers/${id}/apply`, { method: "POST", body: "{}" }),
|
||||
restore: () => request<{ restored_from: string }>("/api/restore", { method: "POST", body: "{}" }),
|
||||
listBackups: () => request<{ items: BackupInfo[] }>("/api/backups"),
|
||||
applyProvider: (id: string, target: ApplyTarget = "claude") =>
|
||||
request<ApplyResult>(`/api/providers/${id}/apply`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ target }),
|
||||
}),
|
||||
restore: (input: RestoreInput = {}) =>
|
||||
request<{ restored_from: string }>("/api/restore", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(input),
|
||||
}),
|
||||
listBackups: (target: ApplyTarget = "claude") =>
|
||||
request<{ items: BackupInfo[] }>(`/api/backups?target=${target}`),
|
||||
getSettings: () => request<Settings>("/api/settings"),
|
||||
updateSettings: (patch: Partial<Settings>) =>
|
||||
request<Settings>("/api/settings", { method: "PUT", body: JSON.stringify(patch) }),
|
||||
listLogs: () => request<{ items: LogEntry[] }>("/api/logs"),
|
||||
};
|
||||
|
||||
export type ApplyTarget = "claude" | "codex";
|
||||
|
||||
export interface RestoreInput {
|
||||
target?: ApplyTarget;
|
||||
backup?: string;
|
||||
}
|
||||
+7
-6
@@ -5,7 +5,7 @@ export const queryKeys = {
|
||||
status: ["status"] as const,
|
||||
providers: ["providers"] as const,
|
||||
logs: ["logs"] as const,
|
||||
backups: ["backups"] as const,
|
||||
backups: (target: string) => ["backups", target] as const,
|
||||
settings: ["settings"] as const,
|
||||
};
|
||||
|
||||
@@ -21,8 +21,8 @@ export function useLogs() {
|
||||
return useQuery({ queryKey: queryKeys.logs, queryFn: api.listLogs, refetchInterval: 5000 });
|
||||
}
|
||||
|
||||
export function useBackups() {
|
||||
return useQuery({ queryKey: queryKeys.backups, queryFn: api.listBackups });
|
||||
export function useBackups(target: "claude" | "codex") {
|
||||
return useQuery({ queryKey: queryKeys.backups(target), queryFn: () => api.listBackups(target) });
|
||||
}
|
||||
|
||||
export function useSettings() {
|
||||
@@ -33,7 +33,7 @@ function invalidateAll(queryClient: ReturnType<typeof useQueryClient>) {
|
||||
return Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.providers }),
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.status }),
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.backups }),
|
||||
queryClient.invalidateQueries({ queryKey: ["backups"] }),
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.settings }),
|
||||
]);
|
||||
}
|
||||
@@ -53,7 +53,8 @@ export function useProviderMutations() {
|
||||
onSuccess: () => invalidateAll(queryClient),
|
||||
});
|
||||
const apply = useMutation({
|
||||
mutationFn: (id: string) => api.applyProvider(id),
|
||||
mutationFn: ({ id, target }: { id: string; target: "claude" | "codex" }) =>
|
||||
api.applyProvider(id, target),
|
||||
onSuccess: () => invalidateAll(queryClient),
|
||||
});
|
||||
return { create, update, remove, apply };
|
||||
@@ -62,7 +63,7 @@ export function useProviderMutations() {
|
||||
export function useRestore() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: () => api.restore(),
|
||||
mutationFn: (input: Parameters<typeof api.restore>[0]) => api.restore(input),
|
||||
onSuccess: () => invalidateAll(queryClient),
|
||||
});
|
||||
}
|
||||
|
||||
+40
-9
@@ -14,6 +14,7 @@ export interface Provider {
|
||||
api_key: string;
|
||||
models: Models;
|
||||
enabled_for_claude: boolean;
|
||||
enabled_for_codex: boolean;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
@@ -37,6 +38,7 @@ export interface Status {
|
||||
port: number;
|
||||
uptime_sec: number;
|
||||
active_claude_provider: ActiveProvider | null;
|
||||
active_codex_provider: ActiveProvider | null;
|
||||
stats: Stats;
|
||||
language: string;
|
||||
port_mode: string;
|
||||
@@ -69,7 +71,14 @@ export interface Settings {
|
||||
|
||||
export interface ApplyResult {
|
||||
provider: Provider;
|
||||
env: Record<string, string>;
|
||||
env?: Record<string, string>;
|
||||
injection?: Injection;
|
||||
}
|
||||
|
||||
export interface Injection {
|
||||
model_provider: string;
|
||||
table: Record<string, string>;
|
||||
prior_provider?: string;
|
||||
}
|
||||
|
||||
export interface Preset {
|
||||
@@ -78,25 +87,47 @@ export interface Preset {
|
||||
models: Models;
|
||||
}
|
||||
|
||||
const CODEX_EXTRAS = ["gpt-5-codex", "gpt-5", "codex-mini-latest"];
|
||||
|
||||
export const PRESETS: Preset[] = [
|
||||
{
|
||||
key: "deepseek",
|
||||
base_url: "https://api.deepseek.com/v1",
|
||||
models: { default: "deepseek-chat", sonnet: "deepseek-chat", haiku: "deepseek-chat", opus: "deepseek-chat" },
|
||||
models: withCodexExtras({
|
||||
default: "deepseek-chat",
|
||||
sonnet: "deepseek-chat",
|
||||
haiku: "deepseek-chat",
|
||||
opus: "deepseek-chat",
|
||||
}, "deepseek-chat"),
|
||||
},
|
||||
{
|
||||
key: "moonshot",
|
||||
base_url: "https://api.moonshot.cn/v1",
|
||||
models: {
|
||||
default: "kimi-k2-0905-preview",
|
||||
sonnet: "kimi-k2-0905-preview",
|
||||
haiku: "kimi-k2-0905-preview",
|
||||
opus: "kimi-k2-0905-preview",
|
||||
},
|
||||
models: withCodexExtras(
|
||||
{
|
||||
default: "kimi-k2-0905-preview",
|
||||
sonnet: "kimi-k2-0905-preview",
|
||||
haiku: "kimi-k2-0905-preview",
|
||||
opus: "kimi-k2-0905-preview",
|
||||
},
|
||||
"kimi-k2-0905-preview",
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "zhipu",
|
||||
base_url: "https://open.bigmodel.cn/api/paas/v4",
|
||||
models: { default: "glm-4.6", sonnet: "glm-4.6", haiku: "glm-4.6", opus: "glm-4.6" },
|
||||
models: withCodexExtras(
|
||||
{
|
||||
default: "glm-4.6",
|
||||
sonnet: "glm-4.6",
|
||||
haiku: "glm-4.6",
|
||||
opus: "glm-4.6",
|
||||
},
|
||||
"glm-4.6",
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
function withCodexExtras(models: Models, upstream: string): Models {
|
||||
return { ...models, extra: Object.fromEntries(CODEX_EXTRAS.map((m) => [m, upstream])) };
|
||||
}
|
||||
Reference in new issue
Block a user