Merge branch 'dev' into hugo-shipping-notice
This commit is contained in:
commit
c778f40fbc
35 files changed
+996
-164
No files matched your search
@@ -76,7 +76,7 @@ const {
|
||||
const tableHeaderColumns = computed(() => [
|
||||
{ key: 'name', label: t('admin.agent.headers.name'), align: 'left' as const },
|
||||
{ key: 'type', label: t('admin.agent.headers.type'), align: 'left' as const },
|
||||
{ key: 'category', label: t('admin.agent.headers.category'), align: 'left' as const },
|
||||
{ key: 'aggregation', label: t('admin.agent.headers.aggregation'), align: 'left' as const },
|
||||
{ key: 'config', label: t('admin.agent.headers.config'), align: 'left' as const },
|
||||
{ key: 'status', label: t('admin.agent.headers.status'), align: 'left' as const },
|
||||
{ key: 'actions', label: t('admin.agent.headers.actions'), align: 'right' as const },
|
||||
@@ -84,16 +84,14 @@ const tableHeaderColumns = computed(() => [
|
||||
|
||||
const formatAgentCode = (agent: AgentRow) => agent.agent_code || 'generic';
|
||||
|
||||
/** 分类主行:一级分类 */
|
||||
const formatAgentCategoryPrimary = (agent: AgentRow) => {
|
||||
const category = String(agent.category || '').trim();
|
||||
return category || '—';
|
||||
};
|
||||
const formatAgentAggregationPrimary = (agent: AgentRow) => (
|
||||
agent.is_aggregate ? t('admin.agent.directory.aggregateMode') : t('admin.agent.directory.normalMode')
|
||||
);
|
||||
|
||||
/** 分类副行:二级分类 */
|
||||
const formatAgentCategorySecondary = (agent: AgentRow) => {
|
||||
const subCategory = String(agent.sub_category || '').trim();
|
||||
return subCategory || '—';
|
||||
const formatAgentAggregationSecondary = (agent: AgentRow) => {
|
||||
const memberCount = Number(agent.directory_member_count || agent.directory_members?.length || 0);
|
||||
if (agent.is_aggregate) return t('admin.agent.directory.memberCount', { count: memberCount });
|
||||
return t('admin.agent.directory.normalListHint');
|
||||
};
|
||||
|
||||
/** 配置列主行:Dify App ID 或 Iframe URL 摘要。 */
|
||||
@@ -251,11 +249,15 @@ onMounted(() => {
|
||||
</td>
|
||||
<td class="px-4 py-4 align-middle">
|
||||
<div class="agent-list-cell">
|
||||
<p class="truncate text-sm text-secondary" :title="formatAgentCategoryPrimary(agent)">
|
||||
{{ formatAgentCategoryPrimary(agent) }}
|
||||
<p
|
||||
class="truncate text-sm font-medium"
|
||||
:class="agent.is_aggregate ? 'text-brand-700' : 'text-secondary'"
|
||||
:title="formatAgentAggregationPrimary(agent)"
|
||||
>
|
||||
{{ formatAgentAggregationPrimary(agent) }}
|
||||
</p>
|
||||
<p class="truncate text-xs text-muted" :title="formatAgentCategorySecondary(agent)">
|
||||
{{ formatAgentCategorySecondary(agent) }}
|
||||
<p class="truncate text-xs text-muted" :title="formatAgentAggregationSecondary(agent)">
|
||||
{{ formatAgentAggregationSecondary(agent) }}
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
@@ -348,6 +350,7 @@ onMounted(() => {
|
||||
:content-profile-options="contentProfileOptions"
|
||||
:runtime-providers="runtimeProviders"
|
||||
:conversation-modes="conversationModes"
|
||||
:agent-options="agents"
|
||||
:sync-content-profile-from-intent-routes="syncContentProfileFromIntentRoutes"
|
||||
@close="showFormDialog = false"
|
||||
@save="saveAgentForm"
|
||||
|
||||
@@ -8,12 +8,16 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { ChevronDown, FileDown, Plus, Search, Trash2, X } from 'lucide-vue-next';
|
||||
import { ChevronDown, FileDown, FolderTree, Plus, Search, Trash2, X } from 'lucide-vue-next';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { AgentFormState, AgentGuideSummary } from '@/features/admin/types/agent.types';
|
||||
import type { AgentFormState, AgentGuideSummary, AgentRow } from '@/features/admin/types/agent.types';
|
||||
import type { ScheduleTask } from '@/shared/types/schedule.types';
|
||||
import type { AgentTypeCatalogEntry, IntentRouteOption } from '../composables/useAgentsAdminRegistry';
|
||||
import type { AdminContentProfileOption } from '@/features/admin/api/admin.api';
|
||||
import {
|
||||
DEFAULT_TRAINING_EMPLOYEE_CHAT_QUESTIONS,
|
||||
DEFAULT_TRAINING_HR_CHAT_QUESTIONS,
|
||||
} from '@/features/chat/training/trainingChatQuestions';
|
||||
import {
|
||||
applyCatalogDefaultsToForm,
|
||||
applyContentProfileTemplate,
|
||||
@@ -38,6 +42,7 @@ const props = defineProps<{
|
||||
contentProfileOptions: AdminContentProfileOption[];
|
||||
runtimeProviders: string[];
|
||||
conversationModes: string[];
|
||||
agentOptions: AgentRow[];
|
||||
syncContentProfileFromIntentRoutes: (form: AgentFormState) => Promise<void>;
|
||||
}>();
|
||||
|
||||
@@ -57,6 +62,7 @@ const { t } = useI18n();
|
||||
const optionLabels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
|
||||
const advancedOpen = ref(false);
|
||||
const intentRouteSearch = ref('');
|
||||
const directoryMemberSearch = ref('');
|
||||
|
||||
const showDifyFields = computed(() => props.form.runtime_provider === 'dify' || props.form.runtime_provider === 'hybrid');
|
||||
const showIframeFields = computed(() => props.form.runtime_provider === 'iframe');
|
||||
@@ -99,6 +105,49 @@ const filteredIntentRouteOptions = computed(() => {
|
||||
));
|
||||
});
|
||||
|
||||
const directoryMemberOptions = computed(() => {
|
||||
const currentId = Number(props.form.id || 0);
|
||||
const keyword = directoryMemberSearch.value.trim().toLowerCase();
|
||||
return props.agentOptions
|
||||
.filter((agent) => Number(agent.id) !== currentId)
|
||||
.filter((agent) => {
|
||||
if (!keyword) return true;
|
||||
return [
|
||||
agent.name,
|
||||
agent.description,
|
||||
agent.category,
|
||||
agent.sub_category,
|
||||
agent.agent_code,
|
||||
].some((value) => String(value || '').toLowerCase().includes(keyword));
|
||||
});
|
||||
});
|
||||
|
||||
const selectedDirectoryMembers = computed(() => (
|
||||
props.form.directory_member_ids
|
||||
.map((id) => props.agentOptions.find((agent) => agent.id === id))
|
||||
.filter(Boolean) as AgentRow[]
|
||||
));
|
||||
|
||||
const setAggregateMode = (enabled: boolean) => {
|
||||
props.form.is_aggregate = enabled;
|
||||
if (!enabled) {
|
||||
props.form.directory_member_ids = [];
|
||||
directoryMemberSearch.value = '';
|
||||
}
|
||||
};
|
||||
|
||||
const toggleDirectoryMember = (agentId: number, checked: boolean) => {
|
||||
const current = new Set(props.form.directory_member_ids);
|
||||
if (checked) {
|
||||
current.add(agentId);
|
||||
} else {
|
||||
current.delete(agentId);
|
||||
}
|
||||
props.form.directory_member_ids = props.agentOptions
|
||||
.map((agent) => agent.id)
|
||||
.filter((id) => current.has(id) && id !== props.form.id);
|
||||
};
|
||||
|
||||
/**
|
||||
* 切换 intent_route 勾选状态。
|
||||
*/
|
||||
@@ -138,6 +187,12 @@ const applySelectedContentProfileTemplate = (force = false) => {
|
||||
const handleTrainingWorkspaceToggle = () => {
|
||||
if (props.form.training_workspace_enabled) {
|
||||
props.form.content_profile = 'training';
|
||||
if (!props.form.training_employee_chat_questions_text.trim()) {
|
||||
props.form.training_employee_chat_questions_text = DEFAULT_TRAINING_EMPLOYEE_CHAT_QUESTIONS.join('\n');
|
||||
}
|
||||
if (!props.form.training_hr_chat_questions_text.trim()) {
|
||||
props.form.training_hr_chat_questions_text = DEFAULT_TRAINING_HR_CHAT_QUESTIONS.join('\n');
|
||||
}
|
||||
} else if (props.form.content_profile === 'training') {
|
||||
props.form.content_profile = '';
|
||||
}
|
||||
@@ -153,6 +208,16 @@ watch(
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
() => props.form.is_aggregate,
|
||||
(enabled) => {
|
||||
if (!enabled) {
|
||||
props.form.directory_member_ids = [];
|
||||
directoryMemberSearch.value = '';
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* 用户切换应用类型时应用 Catalog 默认值。
|
||||
*/
|
||||
@@ -297,38 +362,86 @@ const handleTrainingQuestionTypeChange = (form: AgentFormState, index: number) =
|
||||
</div>
|
||||
|
||||
<div class="col-span-1 md:col-span-2 rounded-2xl border border-default bg-surface-soft/40 p-4">
|
||||
<div class="mb-4 text-xs font-bold uppercase tracking-wider text-muted">{{ t('admin.agent.sections.category') }}</div>
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-3">
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.fields.category') }}</label>
|
||||
<input
|
||||
v-model="form.category"
|
||||
type="text"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.fields.categoryPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.fields.subCategory') }}</label>
|
||||
<input
|
||||
v-model="form.sub_category"
|
||||
type="text"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.fields.subCategoryPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.fields.sortOrder') }}</label>
|
||||
<input
|
||||
v-model.number="form.sort_order"
|
||||
type="number"
|
||||
min="0"
|
||||
step="1"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.fields.sortOrderPlaceholder')"
|
||||
/>
|
||||
<div class="flex flex-col gap-3 md:flex-row md:items-start md:justify-between">
|
||||
<div>
|
||||
<div class="flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-muted">
|
||||
<FolderTree class="h-4 w-4" />
|
||||
{{ t('admin.agent.directory.title') }}
|
||||
</div>
|
||||
<p class="mt-1 text-sm leading-6 text-secondary">{{ t('admin.agent.directory.subtitle') }}</p>
|
||||
</div>
|
||||
<span class="rounded-full bg-white px-3 py-1 text-xs font-medium text-secondary">
|
||||
{{ t('admin.agent.directory.selectedCount', { count: selectedDirectoryMembers.length }) }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid grid-cols-1 gap-3 md:grid-cols-2">
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-xl border px-4 py-3 text-left transition"
|
||||
:class="!form.is_aggregate ? 'border-brand-500 bg-brand-50 text-brand-700' : 'border-default bg-white text-secondary hover:bg-surface-soft'"
|
||||
@click="setAggregateMode(false)"
|
||||
>
|
||||
<span class="block text-sm font-semibold">{{ t('admin.agent.directory.normalMode') }}</span>
|
||||
<span class="mt-1 block text-xs leading-5">{{ t('admin.agent.directory.normalModeHint') }}</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-xl border px-4 py-3 text-left transition"
|
||||
:class="form.is_aggregate ? 'border-brand-500 bg-brand-50 text-brand-700' : 'border-default bg-white text-secondary hover:bg-surface-soft'"
|
||||
@click="setAggregateMode(true)"
|
||||
>
|
||||
<span class="block text-sm font-semibold">{{ t('admin.agent.directory.aggregateMode') }}</span>
|
||||
<span class="mt-1 block text-xs leading-5">{{ t('admin.agent.directory.aggregateModeHint') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<template v-if="form.is_aggregate">
|
||||
<div class="mt-4 flex items-center gap-2 rounded-xl border border-default bg-white px-3 py-2">
|
||||
<Search class="h-4 w-4 text-muted" />
|
||||
<input
|
||||
v-model="directoryMemberSearch"
|
||||
type="search"
|
||||
class="w-full bg-transparent text-sm outline-none"
|
||||
:placeholder="t('admin.agent.directory.searchPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="selectedDirectoryMembers.length" class="mt-3 flex flex-wrap gap-2">
|
||||
<span
|
||||
v-for="member in selectedDirectoryMembers"
|
||||
:key="member.id"
|
||||
class="inline-flex items-center gap-1 rounded-full bg-white px-2.5 py-1 text-xs text-secondary"
|
||||
>
|
||||
{{ member.name }}
|
||||
<button type="button" @click="toggleDirectoryMember(member.id, false)">
|
||||
<X class="h-3 w-3" />
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="mt-3 max-h-64 overflow-y-auto rounded-xl border border-default bg-white p-3">
|
||||
<div v-if="directoryMemberOptions.length === 0" class="px-3 py-4 text-center text-sm text-muted">
|
||||
{{ t('admin.agent.directory.emptyOptions') }}
|
||||
</div>
|
||||
<div v-else class="grid grid-cols-1 gap-2 sm:grid-cols-2 lg:grid-cols-3">
|
||||
<label
|
||||
v-for="agent in directoryMemberOptions"
|
||||
:key="agent.id"
|
||||
class="flex cursor-pointer items-center gap-2.5 rounded-lg border border-default px-3 py-2 text-sm hover:bg-surface-soft"
|
||||
:class="form.directory_member_ids.includes(agent.id) ? 'border-brand-400 bg-brand-50' : 'bg-white'"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
class="shrink-0 accent-brand-600"
|
||||
:checked="form.directory_member_ids.includes(agent.id)"
|
||||
@change="toggleDirectoryMember(agent.id, ($event.target as HTMLInputElement).checked)"
|
||||
/>
|
||||
<span class="min-w-0 truncate font-medium text-primary">{{ agent.name }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div
|
||||
@@ -565,6 +678,29 @@ const handleTrainingQuestionTypeChange = (form: AgentFormState, index: number) =
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.employeeChatQuestions') }}</label>
|
||||
<textarea
|
||||
v-model="form.training_employee_chat_questions_text"
|
||||
rows="6"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.employeeChatQuestionsPlaceholder')"
|
||||
/>
|
||||
<p class="text-xs leading-5 text-muted">{{ t('admin.agent.training.employeeChatQuestionsHint') }}</p>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.hrChatQuestions') }}</label>
|
||||
<textarea
|
||||
v-model="form.training_hr_chat_questions_text"
|
||||
rows="6"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.hrChatQuestionsPlaceholder')"
|
||||
/>
|
||||
<p class="text-xs leading-5 text-muted">{{ t('admin.agent.training.hrChatQuestionsHint') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-5 space-y-3">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
|
||||
@@ -24,6 +24,9 @@ import {
|
||||
} from '@/features/admin/api/admin.api';
|
||||
import { listAdminSchedules } from '@/features/admin/api/schedule.api';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import {
|
||||
resolveTrainingRoleChatQuestions,
|
||||
} from '@/features/chat/training/trainingChatQuestions';
|
||||
import type { AdminUserRow } from '@/features/admin/types/admin.types';
|
||||
import type {
|
||||
AgentFormState,
|
||||
@@ -115,21 +118,30 @@ const parseTrainingConfigFromExtra = (extra: Record<string, unknown> | undefined
|
||||
const hasTrainingContent = questionBank.length > 0
|
||||
|| Boolean(toMultilineText(merged.summary_points ?? merged.summaryPoints))
|
||||
|| Boolean(toMultilineText(merged.summary_checklist ?? merged.summaryChecklist));
|
||||
const workspaceEnabled =
|
||||
extra?.training_workspace_enabled === true
|
||||
|| extra?.training_workspace_enabled === 'true'
|
||||
|| extra?.training_mode === true
|
||||
|| extra?.training_mode === 'true'
|
||||
|| extra?.training_agent === true
|
||||
|| extra?.training_agent === 'true'
|
||||
|| hasTrainingContent;
|
||||
const employeeQuestions = resolveTrainingRoleChatQuestions(extra, 'employee');
|
||||
const hrQuestions = resolveTrainingRoleChatQuestions(extra, 'hr');
|
||||
|
||||
return {
|
||||
training_workspace_enabled:
|
||||
extra?.training_workspace_enabled === true
|
||||
|| extra?.training_workspace_enabled === 'true'
|
||||
|| extra?.training_mode === true
|
||||
|| extra?.training_mode === 'true'
|
||||
|| extra?.training_agent === true
|
||||
|| extra?.training_agent === 'true'
|
||||
|| hasTrainingContent,
|
||||
training_workspace_enabled: workspaceEnabled,
|
||||
training_pass_score: Number.isFinite(Number(merged.pass_score ?? merged.passScore))
|
||||
? Math.max(0, Math.min(100, Math.round(Number(merged.pass_score ?? merged.passScore))))
|
||||
: 90,
|
||||
training_summary_points_text: toMultilineText(merged.summary_points ?? merged.summaryPoints),
|
||||
training_summary_checklist_text: toMultilineText(merged.summary_checklist ?? merged.summaryChecklist),
|
||||
training_employee_chat_questions_text: employeeQuestions.configured || workspaceEnabled
|
||||
? toMultilineText(employeeQuestions.questions)
|
||||
: '',
|
||||
training_hr_chat_questions_text: hrQuestions.configured || workspaceEnabled
|
||||
? toMultilineText(hrQuestions.questions)
|
||||
: '',
|
||||
training_question_bank: questionBank,
|
||||
};
|
||||
};
|
||||
@@ -170,6 +182,8 @@ const hasTrainingConfigContent = (form: AgentFormState) => (
|
||||
form.training_workspace_enabled
|
||||
|| Boolean(form.training_summary_points_text.trim())
|
||||
|| Boolean(form.training_summary_checklist_text.trim())
|
||||
|| Boolean(form.training_employee_chat_questions_text.trim())
|
||||
|| Boolean(form.training_hr_chat_questions_text.trim())
|
||||
|| form.training_question_bank.length > 0
|
||||
);
|
||||
|
||||
@@ -461,6 +475,8 @@ export function useAgentsAdmin() {
|
||||
pass_score: Math.max(0, Math.min(100, Math.round(Number(form.value.training_pass_score) || 90))),
|
||||
summary_points: splitMultilineText(form.value.training_summary_points_text),
|
||||
summary_checklist: splitMultilineText(form.value.training_summary_checklist_text),
|
||||
employee_chat_suggested_questions: splitMultilineText(form.value.training_employee_chat_questions_text),
|
||||
hr_chat_suggested_questions: splitMultilineText(form.value.training_hr_chat_questions_text),
|
||||
question_bank: form.value.training_question_bank.map((question, index) => buildTrainingQuestionPayload(question, index)),
|
||||
};
|
||||
} else {
|
||||
|
||||
@@ -408,6 +408,7 @@ export function mapAgentRowToForm(
|
||||
welcome_message: String(agent.welcome_message || ''),
|
||||
|
||||
is_active: agent.is_active,
|
||||
is_aggregate: agent.is_aggregate === true,
|
||||
|
||||
category: String(agent.category || ''),
|
||||
|
||||
@@ -440,6 +441,9 @@ export function mapAgentRowToForm(
|
||||
tool_run_progress_enabled: agent.capabilities?.task_progress === true,
|
||||
|
||||
schedule_task_id: agent.bound_schedule_task_id ?? null,
|
||||
directory_member_ids: Array.isArray(agent.directory_members)
|
||||
? agent.directory_members.map((item) => Number(item.id)).filter((id) => Number.isInteger(id) && id > 0)
|
||||
: [],
|
||||
|
||||
};
|
||||
|
||||
@@ -518,6 +522,7 @@ export function buildAgentRegistryPayload(
|
||||
description: form.description,
|
||||
|
||||
is_active: form.is_active,
|
||||
is_aggregate: form.is_aggregate,
|
||||
|
||||
type: legacyType,
|
||||
|
||||
@@ -569,6 +574,7 @@ export function buildAgentRegistryPayload(
|
||||
handler_config,
|
||||
|
||||
extra_config,
|
||||
directory_member_ids: form.is_aggregate ? [...form.directory_member_ids] : [],
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ export interface AgentRow {
|
||||
dify_api_key?: string;
|
||||
dify_api_key_masked?: string;
|
||||
is_active: boolean;
|
||||
is_aggregate?: boolean;
|
||||
description?: string;
|
||||
type: 'api' | 'iframe';
|
||||
agent_code?: string;
|
||||
@@ -43,6 +44,18 @@ export interface AgentRow {
|
||||
bound_schedule_task_id?: number | null;
|
||||
handler_config?: Record<string, unknown> | null;
|
||||
extra_config?: Record<string, unknown>;
|
||||
directory_members?: AgentDirectoryMember[];
|
||||
directory_member_count?: number;
|
||||
}
|
||||
|
||||
export interface AgentDirectoryMember {
|
||||
id: number;
|
||||
name: string;
|
||||
description?: string | null;
|
||||
agent_code?: string | null;
|
||||
dify_app_id?: string | null;
|
||||
category?: string | null;
|
||||
sub_category?: string | null;
|
||||
}
|
||||
|
||||
export interface AgentSuggestedQuestionItem {
|
||||
@@ -94,6 +107,7 @@ export interface AgentFormState {
|
||||
suggested_questions_style: 'plain' | 'styled';
|
||||
suggested_questions: AgentSuggestedQuestionItem[];
|
||||
is_active: boolean;
|
||||
is_aggregate: boolean;
|
||||
category: string;
|
||||
sub_category: string;
|
||||
sort_order: number;
|
||||
@@ -109,7 +123,10 @@ export interface AgentFormState {
|
||||
training_pass_score: number;
|
||||
training_summary_points_text: string;
|
||||
training_summary_checklist_text: string;
|
||||
training_employee_chat_questions_text: string;
|
||||
training_hr_chat_questions_text: string;
|
||||
training_question_bank: AgentTrainingQuestionFormItem[];
|
||||
directory_member_ids: number[];
|
||||
}
|
||||
|
||||
export const createEmptyTrainingQuestionForm = (): AgentTrainingQuestionFormItem => ({
|
||||
@@ -139,6 +156,7 @@ export const createEmptyAgentForm = (
|
||||
suggested_questions_style: 'plain',
|
||||
suggested_questions: [],
|
||||
is_active: true,
|
||||
is_aggregate: false,
|
||||
category: '',
|
||||
sub_category: '',
|
||||
sort_order: 0,
|
||||
@@ -163,5 +181,8 @@ export const createEmptyAgentForm = (
|
||||
training_pass_score: 90,
|
||||
training_summary_points_text: '',
|
||||
training_summary_checklist_text: '',
|
||||
training_employee_chat_questions_text: '',
|
||||
training_hr_chat_questions_text: '',
|
||||
training_question_bank: [],
|
||||
directory_member_ids: [],
|
||||
});
|
||||
@@ -26,6 +26,7 @@ const {
|
||||
suggestedQuestionsStyle: 'plain' | 'styled';
|
||||
styledSections: WelcomeQuestionSection[];
|
||||
suggestedQuestions: WelcomeQuestionItem[];
|
||||
hideWelcomeTitle?: boolean;
|
||||
showThinkingBubble: boolean;
|
||||
isThinking: boolean;
|
||||
showChatRating: boolean;
|
||||
@@ -104,6 +105,7 @@ const isLatestAssistantMessage = (items: ChatMessage[], index: number) => {
|
||||
:suggested-questions-style="suggestedQuestionsStyle"
|
||||
:styled-sections="styledSections"
|
||||
:suggested-questions="suggestedQuestions"
|
||||
:hide-title="hideWelcomeTitle"
|
||||
@select-question="emit('select-question', $event)"
|
||||
/>
|
||||
|
||||
|
||||
@@ -45,7 +45,8 @@ const embeddedIframeSrc = computed(() => {
|
||||
return url ? String(url) : undefined;
|
||||
});
|
||||
const canManageMaintenance = computed(() => ['admin', 'maintenance_manager'].includes(String(page.currentUser?.role || '')));
|
||||
const hideWelcomePanel = computed(() => isTrainingAgentPage.value);
|
||||
const hideWelcomePanel = computed(() => false);
|
||||
const hideWelcomeTitle = computed(() => isTrainingAgentPage.value);
|
||||
const isTrainingWorkspaceExpanded = ref(false);
|
||||
const maintenancePanel = ref<'ledger' | 'record' | null>(null);
|
||||
const maintenanceEditRecord = ref<MaintenanceRecord | null>(null);
|
||||
@@ -243,6 +244,7 @@ watch(() => page.currentAgentId, () => {
|
||||
:tool-run-progress-title="page.toolRunProgressTitle"
|
||||
:show-scroll-to-bottom="page.showScrollToBottom"
|
||||
:hide-welcome-panel="hideWelcomePanel"
|
||||
:hide-welcome-title="hideWelcomeTitle"
|
||||
:pin-messages-to-bottom="!isTrainingAgentPage"
|
||||
:scroll-container-holder="page.scrollContainerHolder"
|
||||
@copy="page.copyToClipboard($event.message, $event.index)"
|
||||
|
||||
@@ -23,6 +23,7 @@ const props = defineProps<{
|
||||
suggestedQuestionsStyle: 'plain' | 'styled';
|
||||
styledSections: WelcomeQuestionSection[];
|
||||
suggestedQuestions: WelcomeQuestionItem[];
|
||||
hideTitle?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -32,18 +33,19 @@ const emit = defineEmits<{
|
||||
const { t } = useI18n();
|
||||
|
||||
const displayAgentName = computed(() => props.agentName || t('chat.assistantLabel'));
|
||||
const shouldShowTitle = computed(() => !props.hideTitle);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex h-full min-h-0 w-full flex-col items-center px-4 pb-2 pt-2 md:pb-3">
|
||||
<template v-if="suggestedQuestionsStyle === 'styled' && styledSections.length > 0">
|
||||
<h2 class="mb-8 mt-12 shrink-0 text-center text-2xl font-bold text-primary md:mt-16 md:text-3xl">
|
||||
<h2 v-if="shouldShowTitle" class="mb-8 mt-12 shrink-0 text-center text-2xl font-bold text-primary md:mt-16 md:text-3xl">
|
||||
<span>{{ $t('chat.welcomeAgentTitlePrefix') }}</span>
|
||||
<span class="mx-1 text-brand-600">{{ displayAgentName }}</span>
|
||||
<span>{{ $t('chat.welcomeAgentTitleSuffix') }}</span>
|
||||
</h2>
|
||||
|
||||
<div class="min-h-0 w-full flex-1 overflow-y-auto pb-2">
|
||||
<div class="min-h-0 w-full flex-1 overflow-y-auto pb-2" :class="shouldShowTitle ? '' : 'pt-4 md:pt-8'">
|
||||
<div class="mx-auto grid w-full max-w-4xl grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div
|
||||
v-for="(section, sectionIndex) in styledSections"
|
||||
@@ -74,13 +76,13 @@ const displayAgentName = computed(() => props.agentName || t('chat.assistantLabe
|
||||
</template>
|
||||
|
||||
<template v-else-if="suggestedQuestions.length > 0">
|
||||
<h2 class="mb-8 mt-12 shrink-0 text-center text-2xl font-bold text-primary md:mt-16 md:text-3xl">
|
||||
<h2 v-if="shouldShowTitle" class="mb-8 mt-12 shrink-0 text-center text-2xl font-bold text-primary md:mt-16 md:text-3xl">
|
||||
<span>{{ $t('chat.welcomeAgentTitlePrefix') }}</span>
|
||||
<span class="mx-1 text-brand-600">{{ displayAgentName }}</span>
|
||||
<span>{{ $t('chat.welcomeAgentTitleSuffix') }}</span>
|
||||
</h2>
|
||||
|
||||
<div class="min-h-0 w-full flex-1 overflow-y-auto pb-2">
|
||||
<div class="min-h-0 w-full flex-1 overflow-y-auto pb-2" :class="shouldShowTitle ? '' : 'pt-6 md:pt-10'">
|
||||
<div class="mx-auto mt-2 flex w-full max-w-3xl flex-wrap justify-center gap-3">
|
||||
<button
|
||||
v-for="(item, index) in suggestedQuestions"
|
||||
@@ -96,7 +98,7 @@ const displayAgentName = computed(() => props.agentName || t('chat.assistantLabe
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<h2 class="mt-12 text-center text-2xl font-bold text-primary md:mt-16 md:text-3xl">
|
||||
<h2 v-if="shouldShowTitle" class="mt-12 text-center text-2xl font-bold text-primary md:mt-16 md:text-3xl">
|
||||
<span>{{ $t('chat.welcomeAgentTitlePrefix') }}</span>
|
||||
<span class="mx-1 text-brand-600">{{ displayAgentName }}</span>
|
||||
<span>{{ $t('chat.welcomeAgentTitleSuffix') }}</span>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* features/chat/components/TrainingWorkspacePanel.vue
|
||||
* 用途:在培训 Agent 的聊天页顶部提供“员工培训 + 培训管理”一体化工作区。
|
||||
* 依赖:useTrainingWorkspace、lucide 图标、聊天页 currentAgent/currentUser。
|
||||
* 逻辑:只在培训 Agent 下渲染;员工角色默认直达展开工作区,管理角色保留问答视图,培训答题不再走聊天链路。
|
||||
* 逻辑:只在培训 Agent 下渲染;普通员工首次进入默认展开工作区,但新建/切换会话后保持收起,避免聊天过程中被自动展开打断。
|
||||
*/
|
||||
import { computed, reactive, ref, watch, type ShallowUnwrapRef } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
@@ -123,7 +123,8 @@ watch(
|
||||
() => props.newSessionTick,
|
||||
(tick, prevTick) => {
|
||||
if (!tick || tick === prevTick) return;
|
||||
userExpandedOverride.value = null;
|
||||
// [STEP 1] 新建对话或切换会话后统一收起工作区,避免聊天中因视图重建被自动展开。
|
||||
userExpandedOverride.value = false;
|
||||
applyDefaultExpandedState();
|
||||
},
|
||||
);
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
type AgentRegistryFields,
|
||||
} from '@/shared/utils/agent-registry.utils';
|
||||
import { matchesTrainingAgent } from '../training/trainingWorkspace.utils';
|
||||
import { resolveTrainingRoleChatQuestions } from '../training/trainingChatQuestions';
|
||||
import type { ChatDeps } from './chat.deps';
|
||||
import type { UseChatGuidesReturn } from './useChatGuides';
|
||||
|
||||
@@ -26,13 +27,6 @@ const ERP_KB = 'ERP知识库';
|
||||
const TRAINING_AGENT_DESCRIPTION =
|
||||
'我是你的新人培训助手,会在同一个聊天页面内带你完成视频学习、知识点复盘、逐题考试和结果复盘。';
|
||||
|
||||
const TRAINING_AGENT_QUESTIONS: AgentSuggestedQuestionItem[] = [
|
||||
{ question: '这次员工培训主要学习什么内容?', group: '培训问答' },
|
||||
{ question: '员工培训的通过规则是什么?', group: '培训问答' },
|
||||
{ question: '这次培训的试题范围有哪些?', group: '培训问答' },
|
||||
{ question: '培训记录会如何统计?', group: '培训问答' },
|
||||
];
|
||||
|
||||
const normalizeAgentSuggestedQuestions = (value: unknown): AgentSuggestedQuestionItem[] => {
|
||||
if (!Array.isArray(value)) return [];
|
||||
return value
|
||||
@@ -53,11 +47,12 @@ const normalizeAgentSuggestedQuestions = (value: unknown): AgentSuggestedQuestio
|
||||
export interface UseChatAgentOptions {
|
||||
deps: ChatDeps;
|
||||
currentAgentId: ComputedRef<number>;
|
||||
currentUser: ComputedRef<Record<string, unknown> | null>;
|
||||
chatGuides: Pick<UseChatGuidesReturn, 'loadGuides' | 'clearGuides'>;
|
||||
}
|
||||
|
||||
export function useChatAgent(options: UseChatAgentOptions) {
|
||||
const { deps, currentAgentId, chatGuides } = options;
|
||||
const { deps, currentAgentId, currentUser, chatGuides } = options;
|
||||
const { t, msg, router } = deps;
|
||||
|
||||
const currentAgent = ref<AgentRegistryFields | null>(null);
|
||||
@@ -70,6 +65,16 @@ export function useChatAgent(options: UseChatAgentOptions) {
|
||||
category?: string | null;
|
||||
sub_category?: string | null;
|
||||
sort_order?: number;
|
||||
is_aggregate?: boolean;
|
||||
directory_members?: Array<AgentRegistryFields & {
|
||||
id: number;
|
||||
name: string;
|
||||
description?: string | null;
|
||||
icon_url?: string;
|
||||
category?: string | null;
|
||||
sub_category?: string | null;
|
||||
sort_order?: number;
|
||||
}>;
|
||||
}>>([]);
|
||||
const showAgentPanel = ref(true);
|
||||
const selectedKb = ref(DEFAULT_KB);
|
||||
@@ -88,6 +93,10 @@ export function useChatAgent(options: UseChatAgentOptions) {
|
||||
: kbOptions.filter((option) => option !== ERP_KB)
|
||||
));
|
||||
const kbDropdownDisabled = computed(() => availableKbOptions.value.length <= 1);
|
||||
const isTrainingAdminViewer = computed(() => Boolean(
|
||||
(currentUser.value as { feature_permissions?: { training_hr_manage?: boolean } } | null)
|
||||
?.feature_permissions?.training_hr_manage,
|
||||
));
|
||||
|
||||
watch(canSelectErpKnowledgeBase, (allowed) => {
|
||||
if (allowed) {
|
||||
@@ -119,8 +128,18 @@ export function useChatAgent(options: UseChatAgentOptions) {
|
||||
const configured = normalizeAgentSuggestedQuestions(
|
||||
currentAgent.value?.suggested_questions,
|
||||
);
|
||||
if (matchesTrainingAgent(currentAgent.value)) {
|
||||
const roleQuestions = resolveTrainingRoleChatQuestions(
|
||||
currentAgent.value?.extra_config,
|
||||
isTrainingAdminViewer.value ? 'hr' : 'employee',
|
||||
);
|
||||
if (roleQuestions.configured) {
|
||||
return roleQuestions.questions.map((question) => ({ question, group: '' }));
|
||||
}
|
||||
if (configured.length > 0) return configured;
|
||||
return roleQuestions.questions.map((question) => ({ question, group: '' }));
|
||||
}
|
||||
if (configured.length > 0) return configured;
|
||||
if (matchesTrainingAgent(currentAgent.value)) return TRAINING_AGENT_QUESTIONS;
|
||||
return [];
|
||||
});
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ export function useChatPage() {
|
||||
};
|
||||
|
||||
const chatGuides = useChatGuides({ currentAgentId });
|
||||
const agent = useChatAgent({ deps, currentAgentId, chatGuides });
|
||||
const agent = useChatAgent({ deps, currentAgentId, currentUser: computed(() => currentUser.value), chatGuides });
|
||||
const attachmentApi = useChatAttachments({
|
||||
deps,
|
||||
currentAgentId,
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* features/chat/training/trainingChatQuestions.ts
|
||||
* 用途:统一维护员工培训 Agent 的员工版 / HR 版聊天常见问题默认值与解析逻辑。
|
||||
* 依赖:被 Admin 后台培训配置表单与 Chat 欢迎区共同引用,避免默认问题与字段名出现多份散落副本。
|
||||
* 逻辑:优先读取 extra_config.training_config 中的角色化问题列表;未配置时回退到内置示例,显式保存空数组时尊重为空。
|
||||
*/
|
||||
|
||||
export type TrainingChatQuestionRole = 'employee' | 'hr';
|
||||
|
||||
const TRAINING_ROLE_QUESTION_KEYS: Record<TrainingChatQuestionRole, string[]> = {
|
||||
employee: ['employee_chat_suggested_questions', 'learner_chat_suggested_questions'],
|
||||
hr: ['hr_chat_suggested_questions', 'admin_chat_suggested_questions'],
|
||||
};
|
||||
|
||||
export const DEFAULT_TRAINING_EMPLOYEE_CHAT_QUESTIONS = [
|
||||
'这次员工培训主要学习什么内容?',
|
||||
'完成培训需要经过哪些步骤?',
|
||||
'员工培训的通过规则是什么?',
|
||||
'开始考试前需要注意什么?',
|
||||
];
|
||||
|
||||
export const DEFAULT_TRAINING_HR_CHAT_QUESTIONS = [
|
||||
'现在有多少人参加了培训?',
|
||||
'当前培训通过率是多少?',
|
||||
'哪些员工还没有完成培训?',
|
||||
'我想查看本月培训成绩统计',
|
||||
];
|
||||
|
||||
const asRecord = (value: unknown): Record<string, unknown> => (
|
||||
value && typeof value === 'object' && !Array.isArray(value)
|
||||
? value as Record<string, unknown>
|
||||
: {}
|
||||
);
|
||||
|
||||
const cloneQuestions = (questions: string[]) => questions.map((item) => String(item || '').trim()).filter(Boolean);
|
||||
|
||||
/**
|
||||
* 归一化后台保存的常见问题数组。
|
||||
* AI 触发时机:培训配置允许 string[] 与 { question }[] 混存时,需要统一还原成纯文本列表供表单和聊天欢迎区复用。
|
||||
*/
|
||||
const normalizeTrainingChatQuestionList = (value: unknown): string[] => {
|
||||
if (!Array.isArray(value)) return [];
|
||||
return value
|
||||
.map((item) => {
|
||||
if (typeof item === 'string') return item.trim();
|
||||
if (!item || typeof item !== 'object') return '';
|
||||
return String((item as Record<string, unknown>).question || (item as Record<string, unknown>).text || '').trim();
|
||||
})
|
||||
.filter(Boolean);
|
||||
};
|
||||
|
||||
const getDefaultQuestions = (role: TrainingChatQuestionRole) => (
|
||||
role === 'hr'
|
||||
? cloneQuestions(DEFAULT_TRAINING_HR_CHAT_QUESTIONS)
|
||||
: cloneQuestions(DEFAULT_TRAINING_EMPLOYEE_CHAT_QUESTIONS)
|
||||
);
|
||||
|
||||
/**
|
||||
* 读取培训配置中的角色化聊天常见问题。
|
||||
* AI 触发时机:员工培训 Agent 需要按当前用户角色切换欢迎区问题时,必须先判断后台是否显式配置该角色问题,再决定是否回退默认示例。
|
||||
*/
|
||||
export const resolveTrainingRoleChatQuestions = (
|
||||
extraConfig: unknown,
|
||||
role: TrainingChatQuestionRole,
|
||||
): { configured: boolean; questions: string[] } => {
|
||||
const trainingConfig = asRecord(asRecord(extraConfig).training_config);
|
||||
const keys = TRAINING_ROLE_QUESTION_KEYS[role];
|
||||
const matchedKey = keys.find((key) => Object.prototype.hasOwnProperty.call(trainingConfig, key));
|
||||
if (!matchedKey) {
|
||||
return {
|
||||
configured: false,
|
||||
questions: getDefaultQuestions(role),
|
||||
};
|
||||
}
|
||||
return {
|
||||
configured: true,
|
||||
questions: normalizeTrainingChatQuestionList(trainingConfig[matchedKey]),
|
||||
};
|
||||
};
|
||||
@@ -32,6 +32,8 @@ export interface WorkspaceAgent {
|
||||
category?: string | null;
|
||||
sub_category?: string | null;
|
||||
sort_order?: number;
|
||||
is_aggregate?: boolean;
|
||||
directory_members?: WorkspaceAgent[];
|
||||
}
|
||||
|
||||
export interface WorkspaceQuickQuestion {
|
||||
|
||||
Reference in new issue
Block a user