Merge branch 'dev' into hugo-shipping-notice

# Conflicts:
#	backend/app/api/chat.py
#	backend/app/services/agent_runtime_context/dify_inputs.py
#	backend/app/services/maintenance_chat_service.py
This commit is contained in:
hugo committed 2026-07-07 13:25:16 +08:00
commit fc694a8f43
55 files changed
+2107 -192

No files matched your search

@@ -116,6 +116,7 @@ export interface AdminAgentRegistrySchema {
models?: string[];
required_fields?: string[];
forced_capabilities?: Record<string, boolean>;
default_intent_routes?: string[];
handler_config_schema?: Record<string, unknown>;
}>;
handler_config_schemas: Record<string, unknown>;
@@ -7,8 +7,8 @@
*/
<script setup lang="ts">
import { computed, watch } from 'vue';
import { FileDown, Plus, Trash2, X } from 'lucide-vue-next';
import { computed, ref, watch } from 'vue';
import { ChevronDown, FileDown, 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 { ScheduleTask } from '@/shared/types/schedule.types';
@@ -52,6 +52,8 @@ const emit = defineEmits<{
const { t } = useI18n();
const optionLabels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
const advancedOpen = ref(false);
const intentRouteSearch = ref('');
const showDifyFields = computed(() => props.form.runtime_provider === 'dify' || props.form.runtime_provider === 'hybrid');
const showIframeFields = computed(() => props.form.runtime_provider === 'iframe');
@@ -67,6 +69,30 @@ const currentCatalogEntry = computed(() => (
const taskProgressForced = computed(() => catalogForcesTaskProgress(currentCatalogEntry.value));
const selectedIntentRouteOptions = computed(() => (
props.form.intent_routes
.map((key) => props.intentRouteOptions.find((item) => item.key === key))
.filter(Boolean) as IntentRouteOption[]
));
const intentRouteSummary = computed(() => {
if (!selectedIntentRouteOptions.value.length) return t('admin.agent.registry.intentRoutesNone');
return t('admin.agent.registry.intentRoutesSummary', {
count: selectedIntentRouteOptions.value.length,
names: selectedIntentRouteOptions.value.map((item) => item.label).join('、'),
});
});
const filteredIntentRouteOptions = computed(() => {
const keyword = intentRouteSearch.value.trim().toLowerCase();
if (!keyword) return props.intentRouteOptions;
return props.intentRouteOptions.filter((route) => (
route.key.toLowerCase().includes(keyword)
|| route.label.toLowerCase().includes(keyword)
|| String(route.description || '').toLowerCase().includes(keyword)
));
});
/**
* 切换 intent_route 勾选状态。
*/
@@ -84,6 +110,13 @@ const toggleIntentRoute = (route: string, checked: boolean) => {
void props.syncContentProfileFromIntentRoutes(props.form);
};
/**
* 移除已选 intent_route tag。
*/
const removeIntentRoute = (route: string) => {
toggleIntentRoute(route, false);
};
/**
* 套用 content_profile 默认欢迎语与推荐问题。
*/
@@ -303,29 +336,73 @@ const handleTrainingQuestionTypeChange = (form: AgentFormState, index: number) =
</div>
<div class="space-y-4">
<div class="space-y-2">
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.registry.intentRoutesLabel') }}</label>
<div class="grid grid-cols-1 gap-2 sm:grid-cols-2">
<label
v-for="route in intentRouteOptions"
:key="route.key"
class="inline-flex items-start gap-2 rounded-xl border border-default bg-white px-3 py-2 text-sm text-secondary"
>
<input
type="checkbox"
class="mt-0.5 accent-brand-600"
:checked="form.intent_routes.includes(route.key)"
@change="toggleIntentRoute(route.key, ($event.target as HTMLInputElement).checked)"
/>
<span>
<span class="font-medium text-primary">{{ route.label }}</span>
<span v-if="route.description" class="mt-1 block text-xs leading-5 text-muted">
{{ route.description }}
</span>
<div class="rounded-xl border border-default bg-white">
<button
type="button"
class="flex w-full items-center justify-between gap-3 px-4 py-3 text-left"
@click="advancedOpen = !advancedOpen"
>
<div>
<div class="text-sm font-semibold text-primary">{{ t('admin.agent.registry.advancedTitle') }}</div>
<div class="mt-1 text-xs text-muted">{{ intentRouteSummary }}</div>
</div>
<ChevronDown class="h-4 w-4 text-muted transition-transform" :class="{ 'rotate-180': advancedOpen }" />
</button>
<div v-if="advancedOpen" class="border-t border-default px-4 py-4">
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.registry.intentRoutesLabel') }}</label>
<div class="mt-2 flex flex-wrap gap-2 rounded-xl border border-default px-3 py-2">
<span
v-for="route in selectedIntentRouteOptions"
:key="route.key"
class="inline-flex items-center gap-1 rounded-full bg-surface-soft px-2.5 py-1 text-xs text-secondary"
>
{{ route.label }}
<button type="button" @click="removeIntentRoute(route.key)">
<X class="h-3 w-3" />
</button>
</span>
</label>
<span v-if="!selectedIntentRouteOptions.length" class="text-sm text-muted">
{{ t('admin.agent.registry.intentRoutesPlaceholder') }}
</span>
</div>
<div class="mt-3 rounded-xl border border-default">
<div class="flex items-center gap-2 border-b border-default px-3 py-2">
<Search class="h-4 w-4 text-muted" />
<input
v-model="intentRouteSearch"
type="search"
class="w-full bg-transparent text-sm outline-none"
:placeholder="t('admin.agent.registry.intentRoutesSearch')"
/>
</div>
<div class="max-h-56 overflow-y-auto p-2">
<label
v-for="route in filteredIntentRouteOptions"
:key="route.key"
class="flex cursor-pointer items-start gap-2 rounded-lg px-2 py-2 text-sm hover:bg-surface-soft"
>
<input
type="checkbox"
class="mt-0.5 accent-brand-600"
:checked="form.intent_routes.includes(route.key)"
@change="toggleIntentRoute(route.key, ($event.target as HTMLInputElement).checked)"
/>
<span>
<span class="font-medium text-primary">{{ route.label }}</span>
<span v-if="route.description" class="mt-1 block text-xs leading-5 text-muted">
{{ route.description }}
</span>
</span>
</label>
</div>
</div>
<p class="mt-2 text-xs leading-5 text-muted">{{ t('admin.agent.registry.intentRoutesHint') }}</p>
</div>
<p class="text-xs leading-5 text-muted">{{ t('admin.agent.registry.intentRoutesHint') }}</p>
</div>
<div class="space-y-2">
@@ -33,6 +33,18 @@ const shippingCatalogEntry: AgentTypeCatalogEntry = {
handler_config_schema: {},
};
const fixedAssetsCatalogEntry: AgentTypeCatalogEntry = {
agent_code: 'fixed_assets',
label: '固资管理',
conversation_mode_default: 'chat',
runtime_provider_default: 'dify',
default_intent_routes: ['text2sql'],
handler_config_schema: {
intent_routes: { type: 'array', items: 'string' },
content_profile: { type: 'string' },
},
};
describe('useAgentsAdminRegistry catalog switch', () => {
it('pruneHandlerFormFieldsForCatalog clears intent routes and content profile for empty schema', () => {
const form = createEmptyAgentForm();
@@ -68,4 +80,24 @@ describe('useAgentsAdminRegistry catalog switch', () => {
expect(payload.handler_config).toBeNull();
});
it('applyCatalogDefaultsToForm applies default_intent_routes when catalog supports intent_routes', () => {
const form = createEmptyAgentForm();
applyCatalogDefaultsToForm(form, genericCatalogEntry);
form.intent_routes = ['hr_leave'];
applyCatalogDefaultsToForm(form, fixedAssetsCatalogEntry);
expect(form.intent_routes).toEqual(['text2sql']);
});
it('applyCatalogDefaultsToForm clears intent routes when catalog schema lacks intent_routes', () => {
const form = createEmptyAgentForm();
applyCatalogDefaultsToForm(form, fixedAssetsCatalogEntry);
expect(form.intent_routes).toEqual(['text2sql']);
applyCatalogDefaultsToForm(form, shippingCatalogEntry);
expect(form.intent_routes).toEqual([]);
});
});
@@ -32,6 +32,8 @@ export interface AgentTypeCatalogEntry {
runtime_provider_default: string;
default_intent_routes?: string[];
runtime_handler?: string | null;
models?: string[];
@@ -232,6 +234,11 @@ export function applyCatalogDefaultsToForm(
pruneHandlerFormFieldsForCatalog(form, entry);
const schemaFields = new Set(handlerConfigSchemaFieldNames(entry));
if (schemaFields.has('intent_routes')) {
form.intent_routes = normalizeIntentRoutes(entry.default_intent_routes || []);
}
}
@@ -40,6 +40,7 @@ const { t } = useI18n();
<option value="">{{ t('admin.batchEdit.fields.keepUnchanged') }}</option>
<option value="user">{{ t('admin.role.user') }}</option>
<option value="hr">{{ t('admin.role.hr') }}</option>
<option value="maintenance_manager">{{ t('admin.role.maintenanceManager') }}</option>
<option value="admin">{{ t('admin.role.admin') }}</option>
</select>
</div>
@@ -88,6 +88,7 @@ const { t } = useI18n();
<select v-model="form.role" class="w-full border-default rounded-xl px-4 py-3 text-sm">
<option value="user">{{ t('admin.role.user') }}</option>
<option value="hr">{{ t('admin.role.hr') }}</option>
<option value="maintenance_manager">{{ t('admin.role.maintenanceManager') }}</option>
<option value="admin">{{ t('admin.role.admin') }}</option>
</select>
</div>