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:
2026-04-13 16:08:12 +08:00
parent 6066f43a7d
commit 1b01caac0f
21 changed files with 1630 additions and 392 deletions
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ReloadOutlined } from "@ant-design/icons-vue";
import { MinusCircleFilled, ReloadOutlined } from "@ant-design/icons-vue";
import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query";
import { message, notification } from "ant-design-vue";
import type {
@@ -86,7 +86,12 @@ watch(
}
selectionHydrated.value = false;
coverHydrated.value = false;
await refreshRuntime();
await Promise.allSettled([
refreshRuntime(),
props.articleId ? detailQuery.refetch() : Promise.resolve(),
accountsQuery.refetch(),
platformsQuery.refetch(),
]);
},
{ immediate: true },
);
@@ -96,7 +101,10 @@ watchEffect(() => {
return;
}
if (!coverHydrated.value && !detailQuery.isPending.value) {
if (!coverHydrated.value) {
if (detailQuery.isPending.value || detailQuery.isFetching.value) {
return;
}
const initialUrl = resolveApiURL(detailQuery.data.value?.cover_asset_url);
coverAssetUrl.value = initialUrl;
coverFileName.value = deriveCoverFileName(initialUrl);
@@ -110,8 +118,11 @@ watchEffect(() => {
if (
detailQuery.isPending.value ||
detailQuery.isFetching.value ||
accountsQuery.isPending.value ||
accountsQuery.isFetching.value ||
platformsQuery.isPending.value ||
platformsQuery.isFetching.value ||
runtimeLoading.value
) {
return;
@@ -475,35 +486,32 @@ function showPublishFailures(result: PublisherPublishResponse): void {
{{ coverRequired ? t("media.publish.messages.coverRequired") : t("media.publish.coverHint") }}
</p>
<div
v-if="effectiveCoverEnabled"
class="publish-modal__cover-body"
:class="{ 'publish-modal__cover-body--single': !coverAssetUrl }"
>
<button
type="button"
class="publish-modal__cover-preview"
@click="coverPickerOpen = true"
>
<template v-if="coverAssetUrl">
<img :src="coverAssetUrl" alt="cover preview" />
</template>
<template v-else>
<span class="publish-modal__cover-plus">+</span>
<span>{{ t("media.publish.coverUpload") }}</span>
</template>
</button>
<div v-if="effectiveCoverEnabled" class="publish-modal__cover-body">
<div class="publish-modal__cover-preview-wrap">
<button
type="button"
class="publish-modal__cover-preview"
@click="coverPickerOpen = true"
>
<template v-if="coverAssetUrl">
<img :src="coverAssetUrl" alt="cover preview" />
</template>
<template v-else>
<span class="publish-modal__cover-plus">+</span>
<span>{{ t("media.publish.coverUpload") }}</span>
</template>
</button>
<div v-if="coverAssetUrl" class="publish-modal__cover-side">
<div class="publish-modal__cover-actions">
<a-button @click="handleRemoveCover">
{{ t("article.editor.coverRemove") }}
</a-button>
</div>
<div class="publish-modal__cover-file">
{{ coverFileName || t("article.editor.coverSaved") }}
</div>
<button
v-if="coverAssetUrl"
type="button"
class="publish-modal__cover-remove"
:aria-label="t('article.editor.coverRemove')"
:title="t('article.editor.coverRemove')"
@click.stop="handleRemoveCover"
>
<MinusCircleFilled />
</button>
</div>
</div>
</section>
@@ -728,20 +736,21 @@ function showPublishFailures(result: PublisherPublishResponse): void {
}
.publish-modal__cover-body {
display: grid;
grid-template-columns: 176px minmax(0, 1fr);
gap: 16px;
display: flex;
margin-top: 14px;
}
.publish-modal__cover-body--single {
grid-template-columns: 176px;
.publish-modal__cover-preview-wrap {
position: relative;
width: 176px;
flex: 0 0 176px;
}
.publish-modal__cover-preview {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
min-height: 124px;
padding: 0;
border: 1px dashed #d3dceb;
@@ -774,22 +783,29 @@ function showPublishFailures(result: PublisherPublishResponse): void {
line-height: 1;
}
.publish-modal__cover-side {
.publish-modal__cover-remove {
position: absolute;
top: 8px;
right: 8px;
display: flex;
flex-direction: column;
gap: 12px;
align-items: center;
justify-content: center;
width: 26px;
height: 26px;
padding: 0;
border: 0;
border-radius: 999px;
background: rgba(255, 255, 255, 0.96);
box-shadow: 0 8px 20px rgba(15, 23, 42, 0.14);
color: #ff4d4f;
cursor: pointer;
transition: transform 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
}
.publish-modal__cover-actions {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.publish-modal__cover-file {
color: #667085;
font-size: 13px;
line-height: 1.7;
.publish-modal__cover-remove:hover {
transform: scale(1.04);
box-shadow: 0 10px 24px rgba(15, 23, 42, 0.18);
color: #ff7875;
}
@media (max-width: 860px) {
@@ -802,7 +818,7 @@ function showPublishFailures(result: PublisherPublishResponse): void {
}
.publish-modal__cover-body {
grid-template-columns: 1fr;
display: flex;
}
}
</style>