feat: 插件管理及域名和智能体对应
This commit is contained in:
1 parent
eb61b332a2
commit
e9e4c181b9
9 files changed
+414
-27
No files matched your search
@@ -8,12 +8,115 @@ export interface PromptPrefixSettings {
|
||||
prompt_prefix: string;
|
||||
}
|
||||
|
||||
export interface PluginDomainAgentMappingDto {
|
||||
id: string;
|
||||
domain: string;
|
||||
agent_id: string;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
export interface PluginManagementSettings {
|
||||
domainAgentMappings: Array<{
|
||||
id: string;
|
||||
domain: string;
|
||||
agentId: string;
|
||||
enabled: boolean;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface PluginManagementUpdate {
|
||||
domainAgentMappings?: Array<{
|
||||
id: string;
|
||||
domain: string;
|
||||
agentId: string;
|
||||
enabled: boolean;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface PromptPrefixUpdate {
|
||||
enabled?: boolean;
|
||||
switch_label?: string;
|
||||
prompt_prefix?: string;
|
||||
}
|
||||
|
||||
function fromPluginManagementDto(data: {
|
||||
domain_agent_mappings: PluginDomainAgentMappingDto[];
|
||||
}): PluginManagementSettings {
|
||||
return {
|
||||
domainAgentMappings: (data.domain_agent_mappings ?? []).map((item) => ({
|
||||
id: item.id,
|
||||
domain: item.domain,
|
||||
agentId: item.agent_id,
|
||||
enabled: item.enabled,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
function toPluginManagementDto(body: PluginManagementUpdate) {
|
||||
return {
|
||||
domain_agent_mappings: (body.domainAgentMappings ?? []).map((item) => ({
|
||||
id: item.id,
|
||||
domain: item.domain,
|
||||
agent_id: item.agentId,
|
||||
enabled: item.enabled,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
export async function loadPluginManagementSettings(): Promise<PluginManagementSettings> {
|
||||
const response = await apiFetch(
|
||||
`${getBackendBaseURL()}/api/system-settings/plugin-management`,
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to load plugin management settings: ${response.status}`,
|
||||
);
|
||||
}
|
||||
const data = (await response.json()) as {
|
||||
domain_agent_mappings: PluginDomainAgentMappingDto[];
|
||||
};
|
||||
const mapped = fromPluginManagementDto(data);
|
||||
writeYLog({
|
||||
optType: OptType.view,
|
||||
optDetail: "CM助手-全量-系统设置-插件管理查看",
|
||||
url: "/api/system-settings/plugin-management",
|
||||
returnParam: mapped,
|
||||
});
|
||||
return mapped;
|
||||
}
|
||||
|
||||
export async function updatePluginManagementSettings(
|
||||
body: PluginManagementUpdate,
|
||||
): Promise<PluginManagementSettings> {
|
||||
const payload = toPluginManagementDto(body);
|
||||
const response = await apiFetch(
|
||||
`${getBackendBaseURL()}/api/system-settings/plugin-management`,
|
||||
{
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload),
|
||||
},
|
||||
);
|
||||
if (!response.ok) {
|
||||
const detail = await response
|
||||
.json()
|
||||
.catch(() => ({ detail: "Failed to update plugin management settings" }));
|
||||
throw new Error(detail.detail ?? "Failed to update plugin management settings");
|
||||
}
|
||||
const data = (await response.json()) as {
|
||||
domain_agent_mappings: PluginDomainAgentMappingDto[];
|
||||
};
|
||||
const mapped = fromPluginManagementDto(data);
|
||||
writeYLog({
|
||||
optType: OptType.edit,
|
||||
optDetail: "CM助手-全量-系统设置-插件管理编辑",
|
||||
url: "/api/system-settings/plugin-management",
|
||||
reqParam: payload,
|
||||
returnParam: mapped,
|
||||
});
|
||||
return mapped;
|
||||
}
|
||||
|
||||
export async function loadPromptPrefixSettings(): Promise<PromptPrefixSettings> {
|
||||
const response = await apiFetch(
|
||||
`${getBackendBaseURL()}/api/system-settings/prompt-prefix`,
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
loadCitationDisplaySettings,
|
||||
loadLeaderboardSettings,
|
||||
loadModelConcurrencySettings,
|
||||
loadPluginManagementSettings,
|
||||
loadPrivateSquareStatus,
|
||||
loadPromptPrefixSettings,
|
||||
loadPublishSquares,
|
||||
@@ -17,6 +18,7 @@ import {
|
||||
updateCitationDisplaySettings,
|
||||
updateLeaderboardSettings,
|
||||
updateModelConcurrencySettings,
|
||||
updatePluginManagementSettings,
|
||||
updatePrivateSquareSettings,
|
||||
updatePromptPrefixSettings,
|
||||
updatePublishSquares,
|
||||
@@ -25,6 +27,7 @@ import {
|
||||
type CitationDisplayUpdate,
|
||||
type LeaderboardSettingsUpdate,
|
||||
type ModelConcurrencyUpdate,
|
||||
type PluginManagementUpdate,
|
||||
type PrivateSquareUpdate,
|
||||
type PromptPrefixUpdate,
|
||||
type PublishSquaresUpdate,
|
||||
@@ -41,6 +44,7 @@ const CITATION_DISPLAY_KEY = ["systemSettings", "citationDisplay"] as const;
|
||||
const LEADERBOARD_KEY = ["systemSettings", "leaderboard"] as const;
|
||||
const SKILL_COMPRESSION_KEY = ["systemSettings", "skillCompression"] as const;
|
||||
const MODEL_CONCURRENCY_KEY = ["systemSettings", "modelConcurrency"] as const;
|
||||
const PLUGIN_MANAGEMENT_KEY = ["systemSettings", "pluginManagement"] as const;
|
||||
|
||||
export function usePromptPrefixSettings() {
|
||||
return useQuery({
|
||||
@@ -263,6 +267,27 @@ export function useUpdateModelConcurrencySettings() {
|
||||
});
|
||||
}
|
||||
|
||||
export function usePluginManagementSettings() {
|
||||
return useQuery({
|
||||
queryKey: PLUGIN_MANAGEMENT_KEY,
|
||||
queryFn: () => loadPluginManagementSettings(),
|
||||
staleTime: 60_000,
|
||||
refetchOnWindowFocus: false,
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdatePluginManagementSettings() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (body: PluginManagementUpdate) =>
|
||||
updatePluginManagementSettings(body),
|
||||
onSuccess: (data) => {
|
||||
queryClient.setQueryData(PLUGIN_MANAGEMENT_KEY, data);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useLeaderboardSettings() {
|
||||
return useQuery({
|
||||
queryKey: LEADERBOARD_KEY,
|
||||
|
||||
Reference in new issue
Block a user