Browse Source

feat: wire editable system prompt modal to session config

Co-authored-by: CodeFree <codefree@chinatelcom.cn>
feat/agent-independence
npmrun 2 months ago
parent
commit
5418dc7ede
  1. 4
      app/components/agent/AgentToolbar.vue
  2. 22
      app/pages/chat/[agentSlug]/index.vue

4
app/components/agent/AgentToolbar.vue

@ -50,8 +50,8 @@ const emit = defineEmits<{
</div> </div>
<!-- System prompt button --> <!-- System prompt button -->
<button class="icon-btn" title="系统提示词" @click="emit('showPrompt')"> <button class="icon-btn" title="系统提示词设置" @click="emit('showPrompt')">
<Icon name="lucide:info" /> <Icon name="lucide:settings-2" />
</button> </button>
</div> </div>
</div> </div>

22
app/pages/chat/[agentSlug]/index.vue

@ -19,7 +19,13 @@ const isMobile = useMediaQuery('(max-width: 767.98px)');
const sidebarCollapsed = ref(false); const sidebarCollapsed = ref(false);
const mobileSidebarOpen = ref(false); const mobileSidebarOpen = ref(false);
const showPromptModal = ref(false); const showPromptModal = ref(false);
const systemPromptText = ref(""); const agentSystemPrompt = ref("");
const systemPromptText = computed(() =>
sessions.currentSession.value?.systemPrompt?.trim() || agentSystemPrompt.value || "",
);
const isCustomPrompt = computed(() =>
!!(sessions.currentSession.value?.systemPrompt?.trim()),
);
const preferredModelId = ref<number | null>(null); const preferredModelId = ref<number | null>(null);
const guestDefaultModelId = ref<number | null>(null); const guestDefaultModelId = ref<number | null>(null);
@ -146,12 +152,20 @@ async function loadSystemPrompt() {
const res = await $fetch<{ code: number; data: { systemPrompt?: string } }>( const res = await $fetch<{ code: number; data: { systemPrompt?: string } }>(
`/api/agents/${agentSlug.value}/info`, `/api/agents/${agentSlug.value}/info`,
); );
systemPromptText.value = res.data?.systemPrompt ?? ""; agentSystemPrompt.value = res.data?.systemPrompt ?? "";
} catch { } catch {
systemPromptText.value = ""; agentSystemPrompt.value = "";
} }
} }
async function handleSavePrompt(prompt: string | null) {
if (!sessions.currentSessionId.value) return;
await sessions.updateSessionConfig(sessions.currentSessionId.value, { systemPrompt: prompt });
const { $toast } = useNuxtApp();
$toast?.success?.("系统提示词已更新");
showPromptModal.value = false;
}
watch( watch(
() => sessions.currentSessionId.value, () => sessions.currentSessionId.value,
async (sid) => { async (sid) => {
@ -293,6 +307,8 @@ onMounted(async () => {
<AgentSystemPromptModal <AgentSystemPromptModal
:show="showPromptModal" :show="showPromptModal"
:system-prompt="systemPromptText" :system-prompt="systemPromptText"
:is-custom="isCustomPrompt"
@close="showPromptModal = false" @close="showPromptModal = false"
@save="handleSavePrompt"
/> />
</template> </template>

Loading…
Cancel
Save