Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: auto-fetch the fleet host API key when a peer is selected

[._.]/ Adam Eivy6294ea97245f
diff --git a/client/src/components/providers/FleetProviderSetup.jsx b/client/src/components/providers/FleetProviderSetup.jsx
index fa77cac120..b2fb09297d 100644
--- a/client/src/components/providers/FleetProviderSetup.jsx
+++ b/client/src/components/providers/FleetProviderSetup.jsx
@@ -101,36 +101,43 @@ export default function FleetProviderSetup({ peers = [], onClose, onCreate, onCo
);
const endpoint = normalizeEndpoint(endpointInput);
- const selectPeer = (peerId) => {
- setSelectedPeerId(peerId);
- const peer = availablePeers.find(({ id }) => id === peerId);
- setEndpointInput(peer ? endpointForPeer(peer) : '');
- };
-
- useEffect(() => {
- if (initialPeerId && availablePeers.length > 0 && !endpointInput) {
- selectPeer(initialPeerId);
- }
- }, [initialPeerId, availablePeers]);
-
- const handleFetchKey = async () => {
- if (!selectedPeerId) return;
+ const fetchKeyFor = async (peerId) => {
+ if (!peerId) return;
setFetchingKey(true);
setError('');
try {
- const res = await revealFleetPeerHostKey(selectedPeerId, { silent: true });
+ const res = await revealFleetPeerHostKey(peerId, { silent: true });
if (res?.apiKey) {
setApiKey(res.apiKey);
} else {
setError('Host did not return an API key. Enter it manually.');
}
} catch (err) {
- setError(err?.message || 'Could not retrieve API key from host.');
+ setError(err?.message || 'Could not retrieve API key from host. Enter it manually.');
} finally {
setFetchingKey(false);
}
};
+ // Selecting a known peer auto-fetches its key too — a user who only fills the
+ // pre-populated fields and clicks Create must not be stopped by a manual
+ // "Fetch API key" click they had no reason to expect: submit rejects a blank
+ // key, but nothing upstream of that prompts for it.
+ const selectPeer = (peerId) => {
+ setSelectedPeerId(peerId);
+ const peer = availablePeers.find(({ id }) => id === peerId);
+ setEndpointInput(peer ? endpointForPeer(peer) : '');
+ if (peerId) fetchKeyFor(peerId);
+ };
+
+ useEffect(() => {
+ if (initialPeerId && availablePeers.length > 0 && !endpointInput) {
+ selectPeer(initialPeerId);
+ }
+ }, [initialPeerId, availablePeers]);
+
+ const handleFetchKey = () => fetchKeyFor(selectedPeerId);
+
const selectHarness = (next) => {
setHarness(next);
setName(next === 'tui' ? 'Fleet GPU · OpenCode TUI' : 'Fleet GPU · API');
diff --git a/client/src/components/providers/FleetProviderSetup.test.jsx b/client/src/components/providers/FleetProviderSetup.test.jsx
index 1db6c190de..a3de83cf22 100644
--- a/client/src/components/providers/FleetProviderSetup.test.jsx
+++ b/client/src/components/providers/FleetProviderSetup.test.jsx
@@ -34,6 +34,42 @@ describe('FleetProviderSetup', () => {
expect(endpointInput.value).toBe('http://workstation.tailnet.ts.net:18022/v1');
});
+ it('auto-fetches the API key as soon as a peer is selected from the URL, with no extra click', async () => {
+ api.revealFleetPeerHostKey.mockResolvedValue({ apiKey: 'auto-fetched-key-123456789012' });
+
+ render(
+ <MemoryRouter initialEntries={['/ai/fleet?fleetStep=client&peerId=peer-1']}>
+ <FleetProviderSetup peers={peers} onClose={() => {}} onCreate={vi.fn()} />
+ </MemoryRouter>
+ );
+
+ await waitFor(() => {
+ expect(api.revealFleetPeerHostKey).toHaveBeenCalledWith('peer-1', { silent: true });
+ });
+ await waitFor(() => {
+ expect(screen.getByPlaceholderText('Enter host API key').value).toBe('auto-fetched-key-123456789012');
+ });
+ });
+
+ it('auto-fetches the API key when a peer is chosen from the dropdown, not just from the URL', async () => {
+ api.revealFleetPeerHostKey.mockResolvedValue({ apiKey: 'dropdown-fetched-key-12345678' });
+
+ render(
+ <MemoryRouter initialEntries={['/ai/fleet?fleetStep=client']}>
+ <FleetProviderSetup peers={peers} onClose={() => {}} onCreate={vi.fn()} />
+ </MemoryRouter>
+ );
+
+ fireEvent.change(screen.getByLabelText('Known PortOS peer'), { target: { value: 'peer-2' } });
+
+ await waitFor(() => {
+ expect(api.revealFleetPeerHostKey).toHaveBeenCalledWith('peer-2', { silent: true });
+ });
+ await waitFor(() => {
+ expect(screen.getByPlaceholderText('Enter host API key').value).toBe('dropdown-fetched-key-12345678');
+ });
+ });
+
it('fetches API key from host when clicked', async () => {
api.revealFleetPeerHostKey.mockResolvedValue({ apiKey: 'host-secret-key-123456789012' });