index.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982
  1. <template>
  2. <div class="wb-page pack-page">
  3. <section class="pack-panel">
  4. <header class="pack-panel__head">
  5. <div class="pack-panel__heading">
  6. <div class="pack-panel__title-row">
  7. <h3 class="pack-panel__title">场景包</h3>
  8. <a-tooltip :title="packPanelTip" placement="bottomLeft" :overlay-style="{ maxWidth: '460px' }">
  9. <Icon icon="i-mdi:information-outline" class="pack-panel__tip" tabindex="0" />
  10. </a-tooltip>
  11. <span class="pack-panel__count">共 {{ packList.length }} 个</span>
  12. </div>
  13. </div>
  14. <div class="pack-panel__tools">
  15. <a-input
  16. v-model:value="queryParams.keyword"
  17. class="pack-search"
  18. placeholder="搜索场景包名称"
  19. allow-clear
  20. @press-enter="handleQuery"
  21. >
  22. <template #prefix>
  23. <Icon icon="i-mdi:magnify" class="pack-search__icon" />
  24. </template>
  25. </a-input>
  26. <a-select v-model:value="queryParams.status" class="pack-status-select" placeholder="全部状态" allow-clear>
  27. <a-select-option value="0">启用</a-select-option>
  28. <a-select-option value="1">停用</a-select-option>
  29. </a-select>
  30. <a-button type="primary" @click="handleQuery">查询</a-button>
  31. <a-button @click="resetQuery">重置</a-button>
  32. <a-button type="primary" @click="handleAdd"> 新增 </a-button>
  33. </div>
  34. </header>
  35. <div class="pack-panel__body">
  36. <a-spin :spinning="loading">
  37. <div v-if="packList.length" class="pack-grid">
  38. <article v-for="record in packList" :key="String(record.id)" class="pack-card">
  39. <div class="pack-card__head">
  40. <div class="pack-card__identity">
  41. <span class="pack-card__avatar">
  42. <Icon icon="i-mdi:package-variant-closed" :size="20" />
  43. </span>
  44. <div class="pack-card__name-wrap">
  45. <h4 class="pack-card__name" :title="record.packName">{{ record.packName || '-' }}</h4>
  46. <span class="pack-card__code" :title="record.packCode">{{ record.packCode || '-' }}</span>
  47. </div>
  48. </div>
  49. <a-tag :color="record.status === '0' ? 'success' : 'error'">
  50. {{ record.status === '0' ? '启用' : '停用' }}
  51. </a-tag>
  52. </div>
  53. <p class="pack-card__desc">{{ record.description || '暂无用途说明' }}</p>
  54. <div class="pack-card__capabilities">
  55. <a-tag class="cell-tag">业务工具 {{ record.toolBindings?.length || 0 }}</a-tag>
  56. <a-tag color="warning" class="cell-tag">MCP 工具 {{ record.mcpToolBindings?.length || 0 }}</a-tag>
  57. <a-tag color="success" class="cell-tag">技能 {{ record.skillIds?.length || 0 }}</a-tag>
  58. </div>
  59. <div class="pack-card__footer">
  60. <span class="pack-card__time">更新于 {{ record.updateTime || '-' }}</span>
  61. <div class="pack-card__actions">
  62. <a-button type="link" size="small" @click="handleView(record)">查看</a-button>
  63. <a-button type="link" size="small" @click="handleUpdate(record)">修改</a-button>
  64. <a-button danger type="link" size="small" @click="handleDelete(record)">删除</a-button>
  65. </div>
  66. </div>
  67. </article>
  68. </div>
  69. <a-empty v-else description="暂无场景包" :image-style="{ height: '72px' }" />
  70. </a-spin>
  71. </div>
  72. </section>
  73. <BasicModal
  74. v-model:open="dialog.visible"
  75. :title="dialog.title"
  76. :width="900"
  77. :height="640"
  78. :min-height="520"
  79. :can-fullscreen="false"
  80. :confirm-loading="buttonLoading"
  81. ok-text="确 定"
  82. cancel-text="取 消"
  83. wrap-class-name="pack-modal"
  84. @ok="submitForm"
  85. @cancel="cancel"
  86. >
  87. <a-form ref="packFormRef" :model="form" :rules="rules" :label-col="{ style: { width: '130px' } }">
  88. <a-form-item name="packCode">
  89. <template #label>
  90. <span class="wb-label-tip">
  91. 场景包编码
  92. <a-tooltip title="唯一标识,创建后不可修改;会作为任务快照保存。">
  93. <Icon icon="i-mdi:information-outline" class="wb-label-tip__icon" tabindex="0" />
  94. </a-tooltip>
  95. </span>
  96. </template>
  97. <a-input
  98. v-model:value="form.packCode"
  99. :disabled="!!form.id"
  100. placeholder="小写字母开头,可含数字、下划线、短横线"
  101. />
  102. </a-form-item>
  103. <a-form-item name="packName">
  104. <template #label><span class="wb-label-tip">场景包名称</span></template>
  105. <a-input v-model:value="form.packName" placeholder="如:财务场景包 / 人力场景包" />
  106. </a-form-item>
  107. <a-form-item name="description">
  108. <template #label>
  109. <span class="wb-label-tip">
  110. 用途说明
  111. <a-tooltip title="创建任务时会展示给用户,请写清「适合哪些角色 / 什么场景使用」。">
  112. <Icon icon="i-mdi:information-outline" class="wb-label-tip__icon" tabindex="0" />
  113. </a-tooltip>
  114. </span>
  115. </template>
  116. <a-textarea v-model:value="form.description" :rows="2" placeholder="适合哪些角色 / 什么场景使用" />
  117. </a-form-item>
  118. <a-form-item name="toolBindings">
  119. <template #label>
  120. <span class="wb-label-tip">
  121. 业务工具
  122. <a-tooltip>
  123. <template #title>
  124. <div class="tip-content">
  125. 叠加到智能体既有绑定之上;<b>同一工具以包内决策优先</b>。写入类工具建议设为「需确认」。
  126. </div>
  127. </template>
  128. <Icon icon="i-mdi:information-outline" class="wb-label-tip__icon" tabindex="0" />
  129. </a-tooltip>
  130. </span>
  131. </template>
  132. <a-select
  133. v-model:value="selectedToolCodes"
  134. mode="multiple"
  135. allow-clear
  136. placeholder="请选择包内业务工具"
  137. style="width: 100%"
  138. >
  139. <a-select-option
  140. v-for="item in toolOptions"
  141. :key="item.toolCode"
  142. :label="item.toolName"
  143. :value="item.toolCode"
  144. >
  145. <span>{{ item.toolName }}</span>
  146. <span class="option-suffix">{{ item.toolType === '0' ? '只读' : '写入' }}</span>
  147. </a-select-option>
  148. </a-select>
  149. </a-form-item>
  150. <a-form-item v-if="form.toolBindings?.length">
  151. <template #label>
  152. <span class="wb-label-tip">
  153. 工具授权
  154. <a-tooltip title="允许:直接执行;需确认:调用前暂停,等待用户在对话页确认;禁止:不允许调用。">
  155. <Icon icon="i-mdi:information-outline" class="wb-label-tip__icon" tabindex="0" />
  156. </a-tooltip>
  157. </span>
  158. </template>
  159. <div class="binding-list">
  160. <div v-for="bind in form.toolBindings" :key="bind.toolCode" class="binding-row">
  161. <span class="binding-name">{{ toolLabel(bind.toolCode) }}</span>
  162. <a-select v-model:value="bind.decision" size="small" style="width: 150px">
  163. <a-select-option v-for="item in DECISION_OPTIONS" :key="item.value" :value="item.value">
  164. {{ item.label }}
  165. </a-select-option>
  166. </a-select>
  167. </div>
  168. </div>
  169. </a-form-item>
  170. <a-form-item name="mcpToolBindings">
  171. <template #label>
  172. <span class="wb-label-tip">
  173. 外部 MCP 工具
  174. <a-tooltip>
  175. <template #title>
  176. <div class="tip-content">
  177. 仅装配包内勾选项且必须在该连接的工具白名单内;<b>未选包的任务不接入任何 MCP 工具</b>。
  178. 连接未配置工具白名单时无可选项,请先到「MCP 客户端」页填写。
  179. </div>
  180. </template>
  181. <Icon icon="i-mdi:information-outline" class="wb-label-tip__icon" tabindex="0" />
  182. </a-tooltip>
  183. </span>
  184. </template>
  185. <a-select
  186. v-model:value="selectedMcpKeys"
  187. mode="multiple"
  188. allow-clear
  189. placeholder="请选择包内 MCP 工具"
  190. :options="mcpSelectOptions"
  191. style="width: 100%"
  192. />
  193. </a-form-item>
  194. <a-form-item v-if="form.mcpToolBindings?.length">
  195. <template #label>
  196. <span class="wb-label-tip">
  197. MCP 授权
  198. <a-tooltip title="允许:直接执行;需确认:调用前暂停,等待用户在对话页确认;禁止:不允许调用。">
  199. <Icon icon="i-mdi:information-outline" class="wb-label-tip__icon" tabindex="0" />
  200. </a-tooltip>
  201. </span>
  202. </template>
  203. <div class="binding-list">
  204. <div
  205. v-for="bind in form.mcpToolBindings"
  206. :key="mcpKey(bind.mcpClientId, bind.toolName)"
  207. class="binding-row"
  208. >
  209. <span class="binding-name"> {{ serverNameOf(bind.mcpClientId) }} · {{ bind.toolName }} </span>
  210. <a-select v-model:value="bind.decision" size="small" style="width: 150px">
  211. <a-select-option v-for="item in DECISION_OPTIONS" :key="item.value" :value="item.value">
  212. {{ item.label }}
  213. </a-select-option>
  214. </a-select>
  215. </div>
  216. </div>
  217. </a-form-item>
  218. <a-form-item name="skillIds">
  219. <template #label>
  220. <span class="wb-label-tip">
  221. 技能
  222. <a-tooltip
  223. title="叠加到智能体既有技能绑定之上;仍按提问用户的技能生效范围过滤(仅列当前用户可见的技能)。"
  224. >
  225. <Icon icon="i-mdi:information-outline" class="wb-label-tip__icon" tabindex="0" />
  226. </a-tooltip>
  227. </span>
  228. </template>
  229. <a-select
  230. v-model:value="form.skillIds"
  231. mode="multiple"
  232. allow-clear
  233. placeholder="请选择包内技能"
  234. style="width: 100%"
  235. >
  236. <a-select-option v-for="item in skillOptions" :key="item.id" :label="item.name" :value="item.id" />
  237. </a-select>
  238. </a-form-item>
  239. <a-form-item name="status">
  240. <template #label><span class="wb-label-tip">状态</span></template>
  241. <a-radio-group v-model:value="form.status">
  242. <a-radio value="0">启用</a-radio>
  243. <a-radio value="1">停用</a-radio>
  244. </a-radio-group>
  245. </a-form-item>
  246. <a-form-item name="remark">
  247. <template #label><span class="wb-label-tip">备注</span></template>
  248. <a-textarea v-model:value="form.remark" :rows="2" placeholder="请输入备注" />
  249. </a-form-item>
  250. </a-form>
  251. </BasicModal>
  252. <BasicModal
  253. v-model:open="detail.visible"
  254. title="场景包详情"
  255. :width="900"
  256. :height="620"
  257. :min-height="520"
  258. :can-fullscreen="false"
  259. wrap-class-name="pack-modal"
  260. >
  261. <template v-if="detail.record">
  262. <a-descriptions :column="2" bordered size="small" class="detail-summary">
  263. <a-descriptions-item label="场景包编码">{{ detail.record.packCode || '-' }}</a-descriptions-item>
  264. <a-descriptions-item label="场景包名称">{{ detail.record.packName || '-' }}</a-descriptions-item>
  265. <a-descriptions-item label="状态">
  266. <a-tag :color="detail.record.status === '0' ? 'success' : 'error'">
  267. {{ detail.record.status === '0' ? '启用' : '停用' }}
  268. </a-tag>
  269. </a-descriptions-item>
  270. <a-descriptions-item label="创建人">{{ detail.record.createByName || '-' }}</a-descriptions-item>
  271. <a-descriptions-item label="用途说明" :span="2">{{ detail.record.description || '-' }}</a-descriptions-item>
  272. <a-descriptions-item label="业务工具" :span="2">
  273. <template v-if="detail.record.toolBindings?.length">
  274. <a-tag
  275. v-for="bind in detail.record.toolBindings"
  276. :key="bind.toolCode"
  277. class="cell-tag"
  278. :color="decisionTagColor(bind.decision)"
  279. >
  280. {{ bind.toolName || bind.toolCode }} · {{ decisionLabel(bind.decision) }}
  281. </a-tag>
  282. </template>
  283. <span v-else class="wb-muted">未配置</span>
  284. </a-descriptions-item>
  285. <a-descriptions-item label="外部 MCP 工具" :span="2">
  286. <template v-if="detail.record.mcpToolBindings?.length">
  287. <a-tag
  288. v-for="bind in detail.record.mcpToolBindings"
  289. :key="mcpKey(bind.mcpClientId, bind.toolName)"
  290. class="cell-tag"
  291. :color="decisionTagColor(bind.decision)"
  292. >
  293. {{ bind.serverName || bind.mcpClientId }} · {{ bind.toolName }} · {{ decisionLabel(bind.decision) }}
  294. </a-tag>
  295. </template>
  296. <span v-else class="wb-muted">未配置(该会话不接入 MCP 工具)</span>
  297. </a-descriptions-item>
  298. <a-descriptions-item label="技能" :span="2">
  299. <template v-if="detail.record.skillNames?.length">
  300. <a-tag v-for="name in detail.record.skillNames" :key="name" class="cell-tag" color="success">
  301. {{ name }}
  302. </a-tag>
  303. </template>
  304. <span v-else class="wb-muted">未配置</span>
  305. </a-descriptions-item>
  306. <a-descriptions-item label="备注" :span="2">{{ detail.record.remark || '-' }}</a-descriptions-item>
  307. <a-descriptions-item label="创建时间">{{ detail.record.createTime || '-' }}</a-descriptions-item>
  308. <a-descriptions-item label="更新时间">{{ detail.record.updateTime || '-' }}</a-descriptions-item>
  309. </a-descriptions>
  310. </template>
  311. <template #footer>
  312. <a-button @click="detail.visible = false">关 闭</a-button>
  313. </template>
  314. </BasicModal>
  315. </div>
  316. </template>
  317. <script lang="ts" setup name="WorkbenchAgentPack">
  318. import { computed, onMounted, reactive, ref } from 'vue';
  319. import {
  320. AButton,
  321. ADescriptions,
  322. ADescriptionsItem,
  323. AEmpty,
  324. AForm,
  325. AFormItem,
  326. AInput,
  327. ARadio,
  328. ARadioGroup,
  329. ASelect,
  330. ASelectOption,
  331. ASpin,
  332. ATag,
  333. ATextarea,
  334. ATooltip,
  335. Modal,
  336. message,
  337. } from '@/workbench/components/ant';
  338. import { Icon } from '@/core/components/Icon';
  339. import { BasicModal } from '@/core/components/Modal';
  340. import {
  341. addScenarioPack,
  342. delScenarioPack,
  343. getScenarioPack,
  344. listScenarioPack,
  345. scenarioPackMcpOptions,
  346. updateScenarioPack,
  347. } from '@/workbench/api/pack';
  348. import { visibleSkillOptions } from '@/workbench/api/skill';
  349. import { listTool } from '@/workbench/api/tool';
  350. const packPanelTip =
  351. '场景包按角色 / 部门把业务工具、外部 MCP 工具与技能打包;用户在创建任务时选定并固化到任务,' +
  352. '包内能力叠加到智能体既有绑定之上(同一工具以包内决策优先)。未选包的任务不接入任何 MCP 工具。';
  353. /** 工具授权决策选项 */
  354. const DECISION_OPTIONS = [
  355. { label: '允许', value: '0' },
  356. { label: '需确认', value: '1' },
  357. { label: '禁止', value: '2' },
  358. ];
  359. const packList = ref<any[]>([]);
  360. const toolOptions = ref<any[]>([]);
  361. const mcpOptions = ref<any[]>([]);
  362. const skillOptions = ref<any[]>([]);
  363. const loading = ref(true);
  364. const buttonLoading = ref(false);
  365. const packFormRef = ref<any>();
  366. const queryParams = reactive({
  367. keyword: '' as string,
  368. status: undefined as any,
  369. });
  370. const initFormData = {
  371. id: undefined as any,
  372. packCode: undefined as any,
  373. packName: undefined as any,
  374. description: undefined as any,
  375. status: '0',
  376. remark: undefined as any,
  377. toolBindings: [] as any[],
  378. mcpToolBindings: [] as any[],
  379. skillIds: [] as any[],
  380. };
  381. const dialog = reactive<{ visible: boolean; title: string }>({
  382. visible: false,
  383. title: '',
  384. });
  385. const form = ref<any>({ ...initFormData });
  386. /** 详情弹窗(查看场景包完整信息,只读) */
  387. const detail = reactive<{ visible: boolean; record: any | null }>({
  388. visible: false,
  389. record: null,
  390. });
  391. /** MCP 工具选择值:连接主键::远端工具名 */
  392. const mcpKey = (mcpClientId?: string | number, toolName?: string) => `${mcpClientId}::${toolName}`;
  393. /** MCP 工具下拉(按连接分组) */
  394. const mcpSelectOptions = computed(() =>
  395. mcpOptions.value.map((group) => ({
  396. label: group.serverName,
  397. options: (group.tools || []).map((toolName: string) => ({
  398. label: toolName,
  399. value: mcpKey(group.mcpClientId, toolName),
  400. })),
  401. })),
  402. );
  403. /** 业务工具多选(保留已选工具的授权决策) */
  404. const selectedToolCodes = computed<string[]>({
  405. get: () => (form.value.toolBindings ?? []).map((bind: any) => bind.toolCode),
  406. set: (codes: string[]) => {
  407. const exists = new Map((form.value.toolBindings ?? []).map((bind: any) => [bind.toolCode, bind]));
  408. form.value.toolBindings = codes.map((code) => exists.get(code) ?? { toolCode: code, decision: '0' });
  409. },
  410. });
  411. /** MCP 工具多选(保留已选工具的授权决策) */
  412. const selectedMcpKeys = computed<string[]>({
  413. get: () => (form.value.mcpToolBindings ?? []).map((bind: any) => mcpKey(bind.mcpClientId, bind.toolName)),
  414. set: (keys: string[]) => {
  415. const exists = new Map(
  416. (form.value.mcpToolBindings ?? []).map((bind: any) => [mcpKey(bind.mcpClientId, bind.toolName), bind]),
  417. );
  418. form.value.mcpToolBindings = keys.map((key): any => {
  419. const found = exists.get(key);
  420. if (found) {
  421. return found;
  422. }
  423. const idx = key.indexOf('::');
  424. return { mcpClientId: key.slice(0, idx), toolName: key.slice(idx + 2), decision: '0' };
  425. });
  426. },
  427. });
  428. /** 工具显示名(工具停用 / 删除时回落到编码,避免下拉与列表空白) */
  429. const toolLabel = (toolCode?: string) =>
  430. toolOptions.value.find((item) => item.toolCode === toolCode)?.toolName ?? toolCode ?? '-';
  431. /** Server 名称(连接停用 / 删除时回落到主键) */
  432. const serverNameOf = (mcpClientId?: string | number) =>
  433. mcpOptions.value.find((item) => String(item.mcpClientId) === String(mcpClientId))?.serverName ??
  434. String(mcpClientId ?? '-');
  435. const decisionLabel = (decision?: string) =>
  436. DECISION_OPTIONS.find((item) => item.value === decision)?.label ?? '允许';
  437. const decisionTagColor = (decision?: string) => {
  438. if (decision === '1') {
  439. return 'warning';
  440. }
  441. if (decision === '2') {
  442. return 'error';
  443. }
  444. return 'success';
  445. };
  446. /** 表单校验规则 */
  447. const rules: any = computed(() => ({
  448. packCode: [
  449. { required: true, message: '场景包编码不能为空', trigger: 'blur' },
  450. {
  451. pattern: /^[a-z][a-z0-9_-]{1,63}$/,
  452. message: '小写字母开头,仅含小写字母、数字、下划线或短横线,长度 2~64 位',
  453. trigger: 'blur',
  454. },
  455. ],
  456. packName: [{ required: true, message: '场景包名称不能为空', trigger: 'blur' }],
  457. }));
  458. /** 查询场景包列表 */
  459. const getList = async () => {
  460. loading.value = true;
  461. try {
  462. const res = await listScenarioPack(queryParams);
  463. packList.value = res?.rows ?? [];
  464. } finally {
  465. loading.value = false;
  466. }
  467. };
  468. /** 加载表单依赖的三类选项(逐项降级:单项失败仅置空该项并汇总警告) */
  469. const loadOptions = async () => {
  470. const [toolRes, mcpRes, skillRes] = await Promise.allSettled([
  471. listTool({ pageNum: 1, pageSize: 200, status: '0' }),
  472. scenarioPackMcpOptions(),
  473. visibleSkillOptions(),
  474. ]);
  475. const failed: string[] = [];
  476. if (toolRes.status === 'fulfilled') {
  477. toolOptions.value = toolRes.value?.rows ?? [];
  478. } else {
  479. failed.push('业务工具');
  480. }
  481. if (mcpRes.status === 'fulfilled') {
  482. mcpOptions.value = mcpRes.value ?? [];
  483. } else {
  484. failed.push('外部 MCP 工具');
  485. }
  486. if (skillRes.status === 'fulfilled') {
  487. skillOptions.value = skillRes.value ?? [];
  488. } else {
  489. failed.push('技能');
  490. }
  491. if (failed.length) {
  492. message.warning(`以下选项加载失败(可能缺少相应权限):${failed.join('、')}`);
  493. }
  494. };
  495. const handleQuery = () => {
  496. getList();
  497. };
  498. const resetQuery = () => {
  499. queryParams.keyword = '';
  500. queryParams.status = undefined;
  501. getList();
  502. };
  503. /** 重置表单为初始值 */
  504. const reset = () => {
  505. form.value = { ...initFormData, toolBindings: [], mcpToolBindings: [], skillIds: [] };
  506. packFormRef.value?.resetFields?.();
  507. };
  508. /** 新增按钮操作 */
  509. const handleAdd = () => {
  510. reset();
  511. dialog.title = '新增场景包';
  512. dialog.visible = true;
  513. };
  514. /** 查看按钮操作(拉取完整字段后只读展示) */
  515. const handleView = async (row: any) => {
  516. detail.record = (await getScenarioPack(row.id)) ?? null;
  517. detail.visible = true;
  518. };
  519. /** 修改按钮操作 */
  520. const handleUpdate = async (row: any) => {
  521. reset();
  522. const record = await getScenarioPack(row.id);
  523. form.value = {
  524. id: record.id,
  525. packCode: record.packCode,
  526. packName: record.packName,
  527. description: record.description,
  528. status: record.status ?? '0',
  529. remark: record.remark,
  530. toolBindings: (record.toolBindings ?? []).map((bind: any) => ({ ...bind })),
  531. mcpToolBindings: (record.mcpToolBindings ?? []).map((bind: any) => ({ ...bind })),
  532. skillIds: [...(record.skillIds ?? [])],
  533. };
  534. dialog.title = '修改场景包';
  535. dialog.visible = true;
  536. };
  537. /** 取消按钮 */
  538. const cancel = () => {
  539. reset();
  540. dialog.visible = false;
  541. };
  542. /** 提交按钮 */
  543. const submitForm = async () => {
  544. try {
  545. await packFormRef.value?.validate();
  546. } catch {
  547. return;
  548. }
  549. buttonLoading.value = true;
  550. try {
  551. const payload: any = {
  552. ...form.value,
  553. toolBindings: (form.value.toolBindings ?? []).filter((bind: any) => !!bind.toolCode),
  554. mcpToolBindings: (form.value.mcpToolBindings ?? []).filter((bind: any) => !!bind.toolName),
  555. skillIds: (form.value.skillIds ?? []).filter((id: any) => id !== undefined && id !== null && id !== ''),
  556. };
  557. if (payload.id) {
  558. await updateScenarioPack(payload);
  559. message.success('修改成功');
  560. } else {
  561. delete payload.id;
  562. await addScenarioPack(payload);
  563. message.success('新增成功');
  564. }
  565. dialog.visible = false;
  566. await getList();
  567. } finally {
  568. buttonLoading.value = false;
  569. }
  570. };
  571. /** 删除按钮操作 */
  572. const handleDelete = async (row: any) => {
  573. const ok = await new Promise<boolean>((resolve) => {
  574. Modal.confirm({
  575. title: '提示',
  576. content: `是否确认删除场景包「${row.packName || row.id}」?`,
  577. okText: '确定',
  578. cancelText: '取消',
  579. onOk: () => resolve(true),
  580. onCancel: () => resolve(false),
  581. });
  582. });
  583. if (!ok) {
  584. return;
  585. }
  586. await delScenarioPack(row.id);
  587. message.success('删除成功');
  588. await getList();
  589. };
  590. onMounted(() => {
  591. loadOptions();
  592. getList();
  593. });
  594. </script>
  595. <style scoped lang="less">
  596. .pack-page {
  597. height: 100%;
  598. padding: 8px 10px;
  599. overflow: hidden;
  600. background: #f4f6fa;
  601. }
  602. .pack-panel {
  603. display: flex;
  604. flex: 1 1 auto;
  605. flex-direction: column;
  606. min-height: 0;
  607. overflow: hidden;
  608. background: #fff;
  609. border: 1px solid #e7ebf3;
  610. border-radius: 14px;
  611. box-shadow: 0 1px 2px rgb(16 24 40 / 4%);
  612. }
  613. .pack-panel__head {
  614. display: flex;
  615. flex: 0 0 auto;
  616. flex-wrap: wrap;
  617. align-items: center;
  618. gap: 12px;
  619. min-height: 56px;
  620. padding: 10px 14px;
  621. border-bottom: 1px solid #eff2f7;
  622. }
  623. .pack-panel__heading {
  624. flex: 1 1 320px;
  625. min-width: 0;
  626. }
  627. .pack-panel__title-row {
  628. display: flex;
  629. align-items: center;
  630. min-width: 0;
  631. gap: 8px;
  632. }
  633. .pack-panel__title {
  634. position: relative;
  635. margin: 0;
  636. padding-left: 11px;
  637. color: #111827;
  638. font-size: 15px;
  639. font-weight: 600;
  640. line-height: 22px;
  641. &::before {
  642. position: absolute;
  643. top: 4px;
  644. bottom: 4px;
  645. left: 0;
  646. width: 3px;
  647. border-radius: 2px;
  648. background: #2a50ec;
  649. content: '';
  650. }
  651. }
  652. .pack-panel__tip {
  653. color: #98a2b3;
  654. font-size: 16px;
  655. cursor: help;
  656. }
  657. .pack-panel__count {
  658. margin-left: 2px;
  659. color: #5b6577;
  660. font-size: 12px;
  661. font-variant-numeric: tabular-nums;
  662. }
  663. .pack-panel__tools {
  664. display: flex;
  665. flex: 0 0 auto;
  666. flex-wrap: wrap;
  667. align-items: center;
  668. gap: 8px;
  669. }
  670. .pack-search {
  671. width: 280px;
  672. }
  673. .pack-status-select {
  674. width: 140px;
  675. }
  676. .pack-search__icon {
  677. color: #98a2b3;
  678. }
  679. .pack-panel__tools :deep(.ant-btn) {
  680. height: 30px;
  681. padding: 0 14px;
  682. border-radius: 8px;
  683. font-size: 12px;
  684. font-weight: 500;
  685. }
  686. .pack-panel__tools :deep(.ant-input),
  687. .pack-panel__tools :deep(.ant-input-affix-wrapper),
  688. .pack-panel__tools :deep(.ant-select),
  689. .pack-panel__tools :deep(.ant-select-selector) {
  690. height: 32px;
  691. border-color: #e7ebf3;
  692. border-radius: 8px;
  693. font-size: 12px;
  694. }
  695. .pack-panel__tools :deep(.ant-input-affix-wrapper) {
  696. padding: 0 10px;
  697. }
  698. .pack-panel__tools :deep(.ant-input-affix-wrapper > .ant-input) {
  699. height: 100%;
  700. padding: 0;
  701. background: transparent;
  702. border: 0;
  703. border-radius: 0;
  704. box-shadow: none;
  705. }
  706. .pack-panel__tools :deep(.ant-select-selector) {
  707. padding: 0 10px;
  708. }
  709. .pack-panel__tools :deep(.ant-select-selection-item),
  710. .pack-panel__tools :deep(.ant-select-selection-placeholder) {
  711. font-size: 12px;
  712. line-height: 30px;
  713. }
  714. .pack-panel__body {
  715. flex: 1 1 auto;
  716. min-height: 0;
  717. padding: 14px;
  718. overflow: auto;
  719. background: #f8fafc;
  720. }
  721. .pack-panel__body :deep(.ant-empty) {
  722. margin: 48px 0;
  723. }
  724. .pack-grid {
  725. display: grid;
  726. grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  727. gap: 12px;
  728. }
  729. .pack-card {
  730. display: flex;
  731. flex-direction: column;
  732. min-width: 0;
  733. min-height: 220px;
  734. padding: 14px;
  735. background: #fff;
  736. border: 1px solid #e7ebf3;
  737. border-radius: 12px;
  738. box-shadow: 0 1px 2px rgb(16 24 40 / 3%);
  739. transition:
  740. border-color 0.15s ease,
  741. box-shadow 0.15s ease;
  742. }
  743. .pack-card:hover {
  744. border-color: #bfcdfb;
  745. box-shadow: 0 6px 18px rgb(42 80 236 / 8%);
  746. }
  747. .pack-card__head {
  748. display: flex;
  749. align-items: flex-start;
  750. justify-content: space-between;
  751. gap: 10px;
  752. }
  753. .pack-card__identity {
  754. display: flex;
  755. min-width: 0;
  756. gap: 10px;
  757. }
  758. .pack-card__avatar {
  759. display: inline-flex;
  760. flex: 0 0 38px;
  761. align-items: center;
  762. justify-content: center;
  763. width: 38px;
  764. height: 38px;
  765. color: #2a50ec;
  766. background: #eef2ff;
  767. border-radius: 10px;
  768. }
  769. .pack-card__name-wrap {
  770. min-width: 0;
  771. }
  772. .pack-card__name {
  773. margin: 0;
  774. overflow: hidden;
  775. color: #111827;
  776. font-size: 15px;
  777. font-weight: 600;
  778. line-height: 22px;
  779. text-overflow: ellipsis;
  780. white-space: nowrap;
  781. }
  782. .pack-card__code {
  783. display: block;
  784. margin-top: 2px;
  785. overflow: hidden;
  786. color: #98a2b3;
  787. font-size: 12px;
  788. line-height: 18px;
  789. text-overflow: ellipsis;
  790. white-space: nowrap;
  791. }
  792. .pack-card__desc {
  793. display: -webkit-box;
  794. min-height: 40px;
  795. margin: 12px 0 0;
  796. overflow: hidden;
  797. color: #5b6577;
  798. font-size: 12px;
  799. line-height: 20px;
  800. -webkit-box-orient: vertical;
  801. -webkit-line-clamp: 2;
  802. }
  803. .pack-card__capabilities {
  804. display: flex;
  805. flex-wrap: wrap;
  806. gap: 6px;
  807. margin-top: 12px;
  808. padding-top: 12px;
  809. border-top: 1px dashed #eff2f7;
  810. }
  811. .pack-card__capabilities :deep(.ant-tag) {
  812. margin-inline-end: 0;
  813. font-size: 11px;
  814. line-height: 20px;
  815. }
  816. .pack-card__footer {
  817. display: flex;
  818. align-items: center;
  819. justify-content: space-between;
  820. gap: 12px;
  821. margin-top: auto;
  822. padding-top: 12px;
  823. border-top: 1px solid #eff2f7;
  824. }
  825. .pack-card__time {
  826. overflow: hidden;
  827. color: #98a2b3;
  828. font-size: 11px;
  829. line-height: 18px;
  830. text-overflow: ellipsis;
  831. white-space: nowrap;
  832. }
  833. .pack-card__actions {
  834. display: flex;
  835. align-items: center;
  836. gap: 2px;
  837. }
  838. .pack-card__actions :deep(.ant-btn-link) {
  839. padding: 0 4px;
  840. font-size: 12px;
  841. }
  842. .wb-label-tip__icon {
  843. color: #98a2b3;
  844. font-size: 13px;
  845. }
  846. .tip-content {
  847. line-height: 1.6;
  848. }
  849. .cell-tag {
  850. margin: 2px 4px 2px 0;
  851. }
  852. .option-suffix {
  853. float: right;
  854. color: #98a2b3;
  855. font-size: 12px;
  856. }
  857. .binding-list {
  858. width: 100%;
  859. max-height: 220px;
  860. overflow-y: auto;
  861. }
  862. .binding-row {
  863. display: flex;
  864. align-items: center;
  865. justify-content: space-between;
  866. gap: 12px;
  867. padding: 4px 0;
  868. }
  869. .binding-name {
  870. flex: 1;
  871. overflow: hidden;
  872. text-overflow: ellipsis;
  873. white-space: nowrap;
  874. }
  875. .detail-summary {
  876. margin-bottom: 12px;
  877. :deep(.ant-descriptions-item-label) {
  878. min-width: 110px;
  879. }
  880. }
  881. @media (max-width: 900px) {
  882. .pack-panel__head {
  883. align-items: flex-start;
  884. }
  885. .pack-panel__tools {
  886. width: 100%;
  887. }
  888. .pack-search {
  889. flex: 1 1 180px;
  890. width: auto;
  891. }
  892. }
  893. :global(.pack-modal .ant-modal) {
  894. height: auto !important;
  895. }
  896. </style>