feat(cli-tools): share endpoint presets across every tool card
Each card kept its own copy of the localStorage preset logic inside BaseUrlSelect, so an endpoint saved on one card was invisible to the others until a reload, and a URL typed into the custom field was forgotten the moment the card collapsed. Move the store into cliEndpointPresets.js and publish a change event so open cards resync live. Applying settings now remembers the endpoint unless it matches a built-in option, and each card passes its configured URL as currentUrl so BaseUrlSelect can preselect the matching preset instead of always falling back to 127.0.0.1. Deleting a preset falls back to the first real option rather than clearing the field. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import { useState, useEffect, useRef } from "react";
|
||||
import { Card, Button, ModelSelectModal, ManualConfigModal } from "@/shared/components";
|
||||
import Image from "next/image";
|
||||
import BaseUrlSelect from "./BaseUrlSelect";
|
||||
import { rememberEndpoint } from "./cliEndpointPresets";
|
||||
import ApiKeySelect from "./ApiKeySelect";
|
||||
import { matchKnownEndpoint } from "./cliEndpointMatch";
|
||||
|
||||
@@ -35,6 +36,8 @@ export default function JcodeToolCard({
|
||||
const [customBaseUrl, setCustomBaseUrl] = useState("");
|
||||
const hasInitializedModel = useRef(false);
|
||||
|
||||
const currentBaseUrl = jcodeStatus?.config?.providers?.["9router"]?.base_url || "";
|
||||
|
||||
const getConfigStatus = () => {
|
||||
if (!jcodeStatus?.installed) return null;
|
||||
if (!jcodeStatus?.has9Router) return "not_configured";
|
||||
@@ -140,6 +143,8 @@ export default function JcodeToolCard({
|
||||
});
|
||||
const data = await res.json();
|
||||
if (res.ok) {
|
||||
// Remember the endpoint so it stays selectable next time
|
||||
rememberEndpoint(getEffectiveBaseUrl(), { tunnelPublicUrl, tailscaleUrl });
|
||||
setMessage({ type: "success", text: "Settings applied successfully!" });
|
||||
checkJcodeStatus();
|
||||
} else {
|
||||
@@ -295,6 +300,7 @@ id = "${selectedModel || "cc/claude-opus-4-7"}"`;
|
||||
tunnelPublicUrl={tunnelPublicUrl}
|
||||
tailscaleEnabled={tailscaleEnabled}
|
||||
tailscaleUrl={tailscaleUrl}
|
||||
currentUrl={currentBaseUrl}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user