resources

This commit is contained in:
2026-02-24 16:44:22 +00:00
parent d6ffe43a11
commit 05f0d0e8f7
39 changed files with 1385 additions and 1057 deletions
+2 -2
View File
@@ -9,8 +9,8 @@ export { useRecentModels } from './useRecentModels';
export { usePlans } from './usePlans';
export { useLandingPage } from './useLandingPage';
export { useServerSettings } from './useServerSettings';
export { useResources, getResourceCategory } from './useResources';
export type { Resource, ResourceCredentials, ResourceConnectionConfig, PingResult, ResourceCategory } from './useResources';
export { useResources } from './useResources';
export type { ResourceSummary, ResourceDetail, PingResult } from './useResources';
export { useChatSessions } from './useChatSessions';
export type { UseChatSessionsType } from './useChatSessions';
export { useChatGroups } from './useChatGroups';
+31 -38
View File
@@ -1,32 +1,21 @@
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { useClient } from 'hooks/useClient';
export type ResourceCredentials = {
apiKey?: string;
username?: string;
password?: string;
};
export type ResourceConnectionConfig = {
url: string;
credentials?: ResourceCredentials;
};
export type Resource = {
id: string;
export type ResourceSummary = {
dirName: string;
name: string;
subtitle: string;
type: string;
port: string | null;
description: string;
installCommand: string | null;
uninstallCommand: string | null;
manageCommand: string | null;
verifyCommand: string | null;
updateCommand: string | null;
installed: boolean;
version: string | null;
connectionConfig: ResourceConnectionConfig | null;
scope: 'native' | 'global';
config: Record<string, string>;
};
export type ResourceDetail = ResourceSummary & {
body: string;
rawFrontmatter: string;
filePath: string;
configPath: string;
chatSessionId: string | null;
guidePath: string;
};
export type PingResult = {
@@ -34,10 +23,6 @@ export type PingResult = {
latencyMs: number | null;
};
export type ResourceCategory = 'api-based' | 'local-cli';
export const getResourceCategory = (r: Resource): ResourceCategory => (r.port ? 'api-based' : 'local-cli');
const RESOURCES_KEY = ['RESOURCES'];
export const useResources = () => {
@@ -46,23 +31,31 @@ export const useResources = () => {
const { data: resources, isLoading } = useQuery({
queryKey: RESOURCES_KEY,
queryFn: () => client.get<Resource[]>('/server-settings/resources'),
queryFn: () => client.get<ResourceSummary[]>('/server-settings/resources'),
});
const saveConnectionConfig = async (id: string, config: Partial<ResourceConnectionConfig>) => {
await client.patch(`/server-settings/resources/config/${id}`, config);
const getDetail = (name: string) =>
client.get<ResourceDetail>(`/server-settings/resources/${name}`);
const saveConfig = async (name: string, config: Record<string, string | null>) => {
await client.patch(`/server-settings/resources/${name}/config`, config);
queryClient.invalidateQueries({ queryKey: RESOURCES_KEY });
};
const pingResource = async (id: string, url?: string) => {
return client.post<PingResult>(`/server-settings/resources/${id}/ping`, { url });
};
const runCommand = async (id: string, action: string) => {
const result = await client.post<{ exitCode: number; output: string }>(`/server-settings/resources/${id}/run`, { action });
const createResource = async (name: string) => {
const result = await client.post<{ name: string; dirName: string }>('/server-settings/resources', { name });
queryClient.invalidateQueries({ queryKey: RESOURCES_KEY });
return result;
};
return { resources, isLoading, saveConnectionConfig, pingResource, runCommand };
const deleteResource = async (name: string) => {
await client.delete(`/server-settings/resources/${name}`);
queryClient.invalidateQueries({ queryKey: RESOURCES_KEY });
};
const pingResource = async (name: string, url?: string) => {
return client.post<PingResult>(`/server-settings/resources/${name}/ping`, { url });
};
return { resources, isLoading, getDetail, saveConfig, createResource, deleteResource, pingResource };
};