feat(prompts): add prompts loader and configuration management
- Implemented a new prompts loader in `loader.go` to manage prompt templates and configurations. - Introduced caching mechanism for prompt configurations to optimize loading. - Added functions to apply platform-specific prompt template overrides. - Created unit tests in `loader_test.go` to validate prompt configuration loading and reloading behavior. - Ensured that the last valid configuration is retained in case of errors during reload.
This commit is contained in:
@@ -72,11 +72,26 @@ const platformAppearanceMap: Record<string, { color: string; surface: string; gl
|
||||
kimi: { color: "#111827", surface: "#f3f4f6", glyph: "K" },
|
||||
};
|
||||
|
||||
const trackingPlatformOptions = [
|
||||
{ label: "全部", value: "all" },
|
||||
{ label: "DeepSeek", value: "deepseek" },
|
||||
{ label: "千问", value: "qwen" },
|
||||
{ label: "豆包", value: "doubao" },
|
||||
] as const;
|
||||
|
||||
const trackingPlatformIds = new Set<string>(
|
||||
trackingPlatformOptions
|
||||
.map((item) => item.value)
|
||||
.filter((value) => value !== "all"),
|
||||
);
|
||||
|
||||
const selectedBrandId = useStorage<number | null>("tracking_selected_brand", null);
|
||||
const selectedKeywordId = useStorage<number | null>("tracking_selected_keyword", null);
|
||||
const selectedPlatformId = useStorage<string>("tracking_selected_ai_platform_id", "all");
|
||||
const selectedBusinessDate = useStorage<string>("tracking_selected_business_date", trackingToday);
|
||||
const pluginPreparing = ref(false);
|
||||
|
||||
selectedPlatformId.value = normalizeTrackingPlatformId(selectedPlatformId.value);
|
||||
selectedBusinessDate.value = normalizeTrackingBusinessDate(selectedBusinessDate.value) ?? trackingToday;
|
||||
|
||||
const brandsQuery = useQuery({
|
||||
@@ -151,17 +166,28 @@ watch(
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
watch([selectedBrandId, selectedKeywordId, selectedBusinessDate], ([brandId, keywordId, businessDate]) => {
|
||||
watch(
|
||||
() => route.query.ai_platform_id,
|
||||
(value) => {
|
||||
selectedPlatformId.value = normalizeTrackingPlatformId(value);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
watch([selectedBrandId, selectedKeywordId, selectedPlatformId, selectedBusinessDate], ([brandId, keywordId, platformId, businessDate]) => {
|
||||
const nextBrandId = brandId ? String(brandId) : undefined;
|
||||
const nextKeywordId = keywordId ? String(keywordId) : undefined;
|
||||
const nextPlatformId = platformId !== "all" ? platformId : undefined;
|
||||
const nextBusinessDate = normalizeTrackingBusinessDate(businessDate) ?? trackingToday;
|
||||
const currentBrandId = normalizeQueryValue(route.query.brand_id) || undefined;
|
||||
const currentKeywordId = normalizeQueryValue(route.query.keyword_id) || undefined;
|
||||
const currentPlatformId = normalizeTrackingPlatformId(route.query.ai_platform_id);
|
||||
const currentBusinessDate = normalizeTrackingBusinessDate(route.query.business_date) ?? trackingToday;
|
||||
|
||||
if (
|
||||
currentBrandId === nextBrandId &&
|
||||
currentKeywordId === nextKeywordId &&
|
||||
currentPlatformId === (nextPlatformId ?? "all") &&
|
||||
currentBusinessDate === nextBusinessDate
|
||||
) {
|
||||
return;
|
||||
@@ -172,6 +198,7 @@ watch([selectedBrandId, selectedKeywordId, selectedBusinessDate], ([brandId, key
|
||||
query: {
|
||||
...(nextBrandId ? { brand_id: nextBrandId } : {}),
|
||||
...(nextKeywordId ? { keyword_id: nextKeywordId } : {}),
|
||||
...(nextPlatformId ? { ai_platform_id: nextPlatformId } : {}),
|
||||
business_date: nextBusinessDate,
|
||||
},
|
||||
});
|
||||
@@ -208,13 +235,21 @@ async function ensureMonitoringPluginReady(options?: { silent?: boolean }): Prom
|
||||
}
|
||||
|
||||
const dashboardQuery = useQuery({
|
||||
queryKey: computed(() => ["tracking", "dashboard", selectedBrandId.value, selectedKeywordId.value, selectedBusinessDate.value]),
|
||||
queryKey: computed(() => [
|
||||
"tracking",
|
||||
"dashboard",
|
||||
selectedBrandId.value,
|
||||
selectedKeywordId.value,
|
||||
selectedPlatformId.value,
|
||||
selectedBusinessDate.value,
|
||||
]),
|
||||
enabled: computed(() => Boolean(selectedBrandId.value)),
|
||||
queryFn: () =>
|
||||
monitoringApi.dashboardComposite({
|
||||
brand_id: selectedBrandId.value ?? undefined,
|
||||
keyword_id: selectedKeywordId.value,
|
||||
days: trackingMaxHistoryDays,
|
||||
ai_platform_id: selectedPlatformId.value !== "all" ? selectedPlatformId.value : undefined,
|
||||
business_date: selectedBusinessDate.value,
|
||||
}),
|
||||
});
|
||||
@@ -451,6 +486,7 @@ function openQuestion(question: MonitoringHotQuestion): void {
|
||||
business_date: selectedBusinessDate.value,
|
||||
date_from: selectedBusinessDate.value,
|
||||
date_to: selectedBusinessDate.value,
|
||||
...(selectedPlatformId.value !== "all" ? { ai_platform_id: selectedPlatformId.value } : {}),
|
||||
...(selectedKeywordId.value ? { keyword_id: String(selectedKeywordId.value) } : {}),
|
||||
},
|
||||
});
|
||||
@@ -554,6 +590,14 @@ function normalizeQueryValue(value: unknown): string {
|
||||
return String(Array.isArray(value) ? value[0] ?? "" : value ?? "").trim();
|
||||
}
|
||||
|
||||
function normalizeTrackingPlatformId(value: unknown): string {
|
||||
const normalized = normalizeQueryValue(value).toLowerCase();
|
||||
if (!normalized) {
|
||||
return "all";
|
||||
}
|
||||
return trackingPlatformIds.has(normalized) ? normalized : "all";
|
||||
}
|
||||
|
||||
function normalizeTrackingBusinessDate(value: unknown): string | null {
|
||||
const normalized = normalizeQueryValue(value);
|
||||
if (!normalized) {
|
||||
@@ -588,6 +632,14 @@ function disableTrackingDate(current: dayjs.Dayjs): boolean {
|
||||
>
|
||||
<template #actions>
|
||||
<a-space wrap align="center" class="tracking-actions-wrap">
|
||||
<div class="tracking-action-item">
|
||||
<span class="tracking-action-label">平台</span>
|
||||
<a-select
|
||||
v-model:value="selectedPlatformId"
|
||||
class="tracking-select"
|
||||
:options="trackingPlatformOptions"
|
||||
/>
|
||||
</div>
|
||||
<div class="tracking-action-item">
|
||||
<span class="tracking-action-label">品牌</span>
|
||||
<a-select
|
||||
|
||||
Reference in New Issue
Block a user