mirror of
https://github.com/Routstr/routstrd.git
synced 2026-08-12 04:53:21 +00:00
Replace direct store.getState().clientIds access with a shared utility: - getClientsFromStore(store) for daemon/local usage - getClientsList() for remote CLI usage via daemon API This ensures integration refresh logic and client management work consistently whether running inside the daemon or connecting to a remote daemon where store access is unavailable. Updated: - src/daemon/index.ts: use getClientsFromStore for integration refresh - src/daemon/http/index.ts: use getClientsFromStore in /clients endpoints - src/utils/daemon-client.ts: use getClientsList in ensureDaemonClient - src/cli.ts: use getClientsList in clients list command
67 lines
1.4 KiB
TypeScript
67 lines
1.4 KiB
TypeScript
import { callDaemon } from "./daemon-client";
|
|
|
|
export interface ClientEntry {
|
|
clientId: string;
|
|
name: string;
|
|
apiKey: string;
|
|
createdAt: number;
|
|
lastUsed?: number | null;
|
|
}
|
|
|
|
/**
|
|
* Read the clients list directly from the SDK store.
|
|
* Use this when running inside the daemon (local mode).
|
|
*/
|
|
export function getClientsFromStore(store: { getState(): any }): ClientEntry[] {
|
|
const state = store.getState();
|
|
const clientIds = state.clientIds || [];
|
|
return clientIds.map(
|
|
(c: {
|
|
clientId: string;
|
|
name: string;
|
|
apiKey: string;
|
|
createdAt: number;
|
|
lastUsed?: number | null;
|
|
}) => ({
|
|
clientId: c.clientId,
|
|
name: c.name,
|
|
apiKey: c.apiKey,
|
|
createdAt: c.createdAt,
|
|
lastUsed: c.lastUsed,
|
|
}),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Fetch the clients list from the daemon API.
|
|
* Use this when running remotely (CLI in remote mode).
|
|
*/
|
|
export async function getClientsList(): Promise<ClientEntry[]> {
|
|
const result = await callDaemon("/clients");
|
|
const clients = (
|
|
result.output as
|
|
| {
|
|
clients?: Array<{
|
|
id: string;
|
|
name: string;
|
|
apiKey: string;
|
|
createdAt: number;
|
|
lastUsed?: number | null;
|
|
}>;
|
|
}
|
|
| undefined
|
|
)?.clients;
|
|
|
|
if (!clients) {
|
|
return [];
|
|
}
|
|
|
|
return clients.map((c) => ({
|
|
clientId: c.id,
|
|
name: c.name,
|
|
apiKey: c.apiKey,
|
|
createdAt: c.createdAt,
|
|
lastUsed: c.lastUsed,
|
|
}));
|
|
}
|