You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

236 lines
19 KiB

import { defineComponent, ref, reactive, computed, useSSRContext } from 'vue';
import { ssrRenderAttrs, ssrIncludeBooleanAttr, ssrLooseContain, ssrLooseEqual, ssrRenderList, ssrRenderAttr, ssrInterpolate, ssrRenderStyle, ssrRenderClass, ssrRenderComponent } from 'vue/server-renderer';
import { u as useApi } from './useApi-B-E5eLsI.mjs';
import { u as useToast } from './useToast-CS21XT61.mjs';
import { L as LANG_OPTIONS } from './useLangOptions-DMhiAuTa.mjs';
import { _ as __nuxt_component_0 } from './LangSelect-C_QPlcDf.mjs';
import { _ as _export_sfc } from './server.mjs';
import './useLoading-D4zrSa2m.mjs';
import '../nitro/nitro.mjs';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'node:crypto';
import 'node:url';
import '../routes/renderer.mjs';
import 'vue-bundle-renderer/runtime';
import 'unhead/server';
import 'devalue';
import 'unhead/utils';
import 'pinia';
import 'perfect-debounce';
const CAT_STT = 1;
const CAT_TTS = 2;
const CAT_MT = 3;
const CAT_AST = 4;
const CAT_LLM = 5;
const CAT_STS = 7;
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "agents",
__ssrInlineRender: true,
setup(__props) {
const AGENT_TYPES = [
{ value: "chat", label: "对话", icon: "💬", hint: "STT → LLM → TTS 三段拼接", color: "#b45309", bg: "#fef9c3" },
{ value: "translate", label: "翻译", icon: "🧩", hint: "STT → MT → TTS 三段拼接", color: "#059669", bg: "#dcfce7" },
{ value: "sts-chat", label: "端到端对话", icon: "⚡", hint: "单个 STS 服务直接完成语音对话", color: "#be185d", bg: "#fce7f3" },
{ value: "ast-translate", label: "端到端翻译", icon: "🚀", hint: "单个 AST 服务直接完成语音翻译", color: "#c2410c", bg: "#fff7ed" }
];
const SLOTS = {
chat: [
{ key: "stt_svc_id", slot: "STT", label: "语音识别", cat: CAT_STT, color: "#1664ff" },
{ key: "llm_svc_id", slot: "LLM", label: "大语言模型", cat: CAT_LLM, color: "#b45309" },
{ key: "tts_svc_id", slot: "TTS", label: "语音合成", cat: CAT_TTS, color: "#7c3aed" }
],
translate: [
{ key: "stt_svc_id", slot: "STT", label: "语音识别", cat: CAT_STT, color: "#1664ff" },
{ key: "mt_svc_id", slot: "MT", label: "机器翻译", cat: CAT_MT, color: "#059669" },
{ key: "tts_svc_id", slot: "TTS", label: "语音合成", cat: CAT_TTS, color: "#7c3aed" }
],
"sts-chat": [{ key: "sts_svc_id", slot: "STS", label: "端到端语音对话", cat: CAT_STS, color: "#be185d" }],
"ast-translate": [{ key: "ast_svc_id", slot: "AST", label: "端到端语音翻译", cat: CAT_AST, color: "#f97316" }]
};
function slotsOfType(t) {
return SLOTS[t] ?? [];
}
useApi();
useToast();
const scopeApp = ref("");
const scopeApps = ref([]);
const agents2 = ref([]);
const allSvcs = ref([]);
const modalOpen = ref(false);
const isEditing = ref(false);
const submitting = ref(false);
function emptyForm() {
return {
app_name: "",
id: "",
name: "",
type: "translate",
description: "",
avatar_url: "",
enable: true,
stt_svc_id: "",
llm_svc_id: "",
tts_svc_id: "",
mt_svc_id: "",
sts_svc_id: "",
ast_svc_id: "",
system_prompt: "",
gender: 0,
greeting_enabled: false,
greeting_text: "",
support_langs: "",
default_lang: "",
voice_map: [],
sort: 0
};
}
const form = reactive(emptyForm());
const isChatType = computed(() => form.type === "chat" || form.type === "sts-chat");
const supportedLangOptions = computed(() => {
const codes = (form.support_langs || "").split(",").map((x) => x.trim()).filter(Boolean);
if (!codes.length) return LANG_OPTIONS;
return LANG_OPTIONS.filter((o) => codes.includes(o.code));
});
const grouped = computed(
() => AGENT_TYPES.map((t) => ({
...t,
type: t.value,
items: agents2.value.filter((a) => a.type === t.value).sort((a, b) => (b.sort || 0) - (a.sort || 0) || (a.name || "").localeCompare(b.name || ""))
})).filter((g) => g.items.length)
);
function svcsByCat(cat) {
return allSvcs.value.filter(
(s) => s.enable && (s.categories || "").split(",").map(Number).includes(cat)
);
}
function svcName(id) {
if (!id) return "未配置";
const s = allSvcs.value.find((x) => x.id === id);
return s ? s.name : id;
}
function pipelineOf(a) {
return slotsOfType(a.type).map((s) => ({ slot: s.slot, color: s.color, id: a[s.key] }));
}
return (_ctx, _push, _parent, _attrs) => {
_push(`<div${ssrRenderAttrs(_attrs)} data-v-463df649><div class="flex items-center justify-between mb-5 flex-wrap gap-3" data-v-463df649><div data-v-463df649><h2 class="text-lg font-semibold text-slate-800" data-v-463df649>Agent 配置</h2><p class="text-xs text-slate-400 mt-1" data-v-463df649> 把已配置的第三方服务编排成可下发客户端的智能体。四种类型按需引用不同服务;通话翻译规则只能引用「翻译」与「端到端翻译」两类。 </p></div><div class="flex items-center gap-3" data-v-463df649><span class="text-sm text-slate-500" data-v-463df649>作用域</span><select class="select select-bordered select-sm" data-v-463df649><option value="" data-v-463df649${ssrIncludeBooleanAttr(Array.isArray(scopeApp.value) ? ssrLooseContain(scopeApp.value, "") : ssrLooseEqual(scopeApp.value, "")) ? " selected" : ""}>全局默认</option><!--[-->`);
ssrRenderList(scopeApps.value, (a) => {
_push(`<option${ssrRenderAttr("value", a)} data-v-463df649${ssrIncludeBooleanAttr(Array.isArray(scopeApp.value) ? ssrLooseContain(scopeApp.value, a) : ssrLooseEqual(scopeApp.value, a)) ? " selected" : ""}>${ssrInterpolate(a)}</option>`);
});
_push(`<!--]--></select><button class="btn btn-primary btn-sm text-white" data-v-463df649>+ 新建 Agent</button></div></div>`);
if (!agents2.value.length) {
_push(`<div class="text-center py-20 text-slate-300" data-v-463df649><div class="text-5xl mb-3" data-v-463df649>🤖</div><p class="text-sm" data-v-463df649>当前作用域下还没有 Agent</p><p class="text-xs mt-1" data-v-463df649>先在「第三方服务配置」里配好服务,再来把它们组装成 Agent</p></div>`);
} else {
_push(`<!---->`);
}
_push(`<!--[-->`);
ssrRenderList(grouped.value, (g) => {
_push(`<div class="mb-6" data-v-463df649><div class="flex items-center gap-2 mb-3" data-v-463df649><span class="type-tag" style="${ssrRenderStyle({ background: g.bg, color: g.color })}" data-v-463df649>${ssrInterpolate(g.icon)} ${ssrInterpolate(g.label)}</span><span class="text-xs text-slate-400" data-v-463df649>${ssrInterpolate(g.hint)}</span><span class="text-xs text-slate-300" data-v-463df649>·</span><span class="text-xs text-slate-400" data-v-463df649>${ssrInterpolate(g.items.length)} 个</span></div><div class="agent-grid" data-v-463df649><!--[-->`);
ssrRenderList(g.items, (a) => {
_push(`<div class="agent-card" data-v-463df649><div class="flex items-start justify-between gap-2" data-v-463df649><div class="min-w-0" data-v-463df649><div class="font-semibold text-sm text-slate-800 truncate" data-v-463df649>${ssrInterpolate(a.name || a.id)}</div><div class="text-[11px] text-slate-400 mt-0.5 truncate" data-v-463df649>${ssrInterpolate(a.id)}</div></div><div class="flex items-center gap-1 flex-shrink-0" data-v-463df649>`);
if (a.enable) {
_push(`<span class="badge badge-success badge-xs" data-v-463df649>启用</span>`);
} else {
_push(`<span class="badge badge-ghost badge-xs" data-v-463df649>停用</span>`);
}
_push(`<button class="btn btn-ghost btn-xs text-error" data-v-463df649>删除</button></div></div>`);
if (a.description) {
_push(`<p class="text-xs text-slate-500 mt-2 line-clamp-2" data-v-463df649>${ssrInterpolate(a.description)}</p>`);
} else {
_push(`<!---->`);
}
_push(`<div class="flex flex-wrap items-center gap-1.5 mt-3" data-v-463df649><!--[-->`);
ssrRenderList(pipelineOf(a), (s) => {
_push(`<span class="svc-pill" style="${ssrRenderStyle({ background: s.color })}" data-v-463df649>${ssrInterpolate(s.slot)}: ${ssrInterpolate(svcName(s.id))}</span>`);
});
_push(`<!--]--></div>`);
if (a.support_langs) {
_push(`<div class="text-[11px] text-slate-400 mt-2 truncate" data-v-463df649> 支持语言:${ssrInterpolate(a.support_langs)}</div>`);
} else {
_push(`<!---->`);
}
_push(`</div>`);
});
_push(`<!--]--></div></div>`);
});
_push(`<!--]--><div class="ag-overlay" style="${ssrRenderStyle(modalOpen.value ? null : { display: "none" })}" data-v-463df649><div class="ag-box" data-v-463df649><div class="flex items-center justify-between mb-4" data-v-463df649><div class="flex items-center gap-3" data-v-463df649><h3 class="text-base font-semibold text-slate-800" data-v-463df649>${ssrInterpolate(isEditing.value ? "编辑 Agent" : "新建 Agent")}</h3><span class="scope-chip" data-v-463df649>${ssrInterpolate(scopeApp.value || "全局默认")}</span></div><button class="btn btn-ghost btn-xs" data-v-463df649>✕ 关闭</button></div><section class="ed-section" data-v-463df649><div class="ed-section-title" data-v-463df649>类型</div><div class="type-row" data-v-463df649><!--[-->`);
ssrRenderList(AGENT_TYPES, (t) => {
_push(`<button type="button" class="${ssrRenderClass([{ on: form.type === t.value, locked: isEditing.value && form.type !== t.value }, "ttab"])}"${ssrIncludeBooleanAttr(isEditing.value) ? " disabled" : ""} data-v-463df649><span class="ttab-title" data-v-463df649>${ssrInterpolate(t.icon)} ${ssrInterpolate(t.label)}</span><span class="ttab-desc" data-v-463df649>${ssrInterpolate(t.hint)}</span></button>`);
});
_push(`<!--]--></div>`);
if (isEditing.value) {
_push(`<p class="ed-tip" data-v-463df649>类型创建后不可更改;需要换类型请新建一个 Agent。</p>`);
} else {
_push(`<!---->`);
}
_push(`</section><section class="ed-section" data-v-463df649><div class="ed-section-title" data-v-463df649>基本信息</div><div class="grid grid-cols-2 gap-3" data-v-463df649><div data-v-463df649><span class="ed-label" data-v-463df649>Agent ID <i class="req" data-v-463df649>*</i></span><input${ssrRenderAttr("value", form.id)}${ssrIncludeBooleanAttr(isEditing.value) ? " disabled" : ""} class="input input-bordered input-sm w-full" placeholder="如 trans-cn-en(作用域内唯一,创建后不可改)" data-v-463df649></div><div data-v-463df649><span class="ed-label" data-v-463df649>名称 <i class="req" data-v-463df649>*</i></span><input${ssrRenderAttr("value", form.name)} class="input input-bordered input-sm w-full" placeholder="展示名,如 中英实时翻译" data-v-463df649></div></div><div class="mt-3" data-v-463df649><span class="ed-label" data-v-463df649>描述</span><input${ssrRenderAttr("value", form.description)} class="input input-bordered input-sm w-full" placeholder="这个 Agent 用在什么场景" data-v-463df649></div><div class="grid grid-cols-3 gap-3 mt-3" data-v-463df649><div data-v-463df649><span class="ed-label" data-v-463df649>头像 URL</span><input${ssrRenderAttr("value", form.avatar_url)} class="input input-bordered input-sm w-full" placeholder="可留空" data-v-463df649></div><div data-v-463df649><span class="ed-label" data-v-463df649>排序(越大越靠前)</span><input${ssrRenderAttr("value", form.sort)} type="number" class="input input-bordered input-sm w-full" data-v-463df649></div><div data-v-463df649><span class="ed-label" data-v-463df649>音色性别偏好</span><select class="select select-bordered select-sm w-full" data-v-463df649><option${ssrRenderAttr("value", 0)} data-v-463df649${ssrIncludeBooleanAttr(Array.isArray(form.gender) ? ssrLooseContain(form.gender, 0) : ssrLooseEqual(form.gender, 0)) ? " selected" : ""}>不限</option><option${ssrRenderAttr("value", 1)} data-v-463df649${ssrIncludeBooleanAttr(Array.isArray(form.gender) ? ssrLooseContain(form.gender, 1) : ssrLooseEqual(form.gender, 1)) ? " selected" : ""}>男</option><option${ssrRenderAttr("value", 2)} data-v-463df649${ssrIncludeBooleanAttr(Array.isArray(form.gender) ? ssrLooseContain(form.gender, 2) : ssrLooseEqual(form.gender, 2)) ? " selected" : ""}>女</option></select></div></div></section><section class="ed-section" data-v-463df649><div class="ed-section-title" data-v-463df649>服务编排</div><div class="slot-row" data-v-463df649><!--[-->`);
ssrRenderList(slotsOfType(form.type), (s, i) => {
_push(`<!--[--><div class="slot-item" data-v-463df649><span class="stage-tag" style="${ssrRenderStyle({ background: s.color })}" data-v-463df649>${ssrInterpolate(s.slot)}</span><span class="ed-label inline" data-v-463df649>${ssrInterpolate(s.label)}</span><select class="select select-bordered select-sm w-full" data-v-463df649><option value="" disabled data-v-463df649${ssrIncludeBooleanAttr(Array.isArray(form[s.key]) ? ssrLooseContain(form[s.key], "") : ssrLooseEqual(form[s.key], "")) ? " selected" : ""}>${ssrInterpolate(svcsByCat(s.cat).length ? "请选择服务" : "(无可用服务,请先去第三方服务配置里添加)")}</option><!--[-->`);
ssrRenderList(svcsByCat(s.cat), (v) => {
_push(`<option${ssrRenderAttr("value", v.id)} data-v-463df649${ssrIncludeBooleanAttr(Array.isArray(form[s.key]) ? ssrLooseContain(form[s.key], v.id) : ssrLooseEqual(form[s.key], v.id)) ? " selected" : ""}>${ssrInterpolate(v.name)}</option>`);
});
_push(`<!--]--></select></div>`);
if (i < slotsOfType(form.type).length - 1) {
_push(`<span class="slot-arrow" data-v-463df649>→</span>`);
} else {
_push(`<!---->`);
}
_push(`<!--]-->`);
});
_push(`<!--]--></div></section><section class="ed-section" data-v-463df649><div class="ed-section-title" data-v-463df649>语言与音色</div><div class="grid grid-cols-2 gap-3" data-v-463df649><div data-v-463df649><span class="ed-label" data-v-463df649>支持语言(多选)</span>`);
_push(ssrRenderComponent(__nuxt_component_0, {
modelValue: form.support_langs,
"onUpdate:modelValue": ($event) => form.support_langs = $event,
multiple: ""
}, null, _parent));
_push(`</div><div data-v-463df649><span class="ed-label" data-v-463df649>默认语言</span>`);
_push(ssrRenderComponent(__nuxt_component_0, {
modelValue: form.default_lang,
"onUpdate:modelValue": ($event) => form.default_lang = $event,
options: supportedLangOptions.value
}, null, _parent));
_push(`</div></div><div class="mt-3" data-v-463df649><div class="flex items-center justify-between mb-1" data-v-463df649><span class="ed-label mb-0" data-v-463df649>音色覆盖(不填则用 TTS 服务自带默认音色)</span><button class="btn btn-ghost btn-xs" data-v-463df649>+ 添加一行</button></div>`);
if (!form.voice_map.length) {
_push(`<div class="text-xs text-slate-300 py-2" data-v-463df649>未设置音色覆盖</div>`);
} else {
_push(`<!---->`);
}
_push(`<!--[-->`);
ssrRenderList(form.voice_map, (v, i) => {
_push(`<div class="voice-row" data-v-463df649><select class="select select-bordered select-xs" data-v-463df649><option value="" data-v-463df649${ssrIncludeBooleanAttr(Array.isArray(v.language) ? ssrLooseContain(v.language, "") : ssrLooseEqual(v.language, "")) ? " selected" : ""}>(语言)</option><!--[-->`);
ssrRenderList(supportedLangOptions.value, (o) => {
_push(`<option${ssrRenderAttr("value", o.code)} data-v-463df649${ssrIncludeBooleanAttr(Array.isArray(v.language) ? ssrLooseContain(v.language, o.code) : ssrLooseEqual(v.language, o.code)) ? " selected" : ""}>${ssrInterpolate(o.code)} · ${ssrInterpolate(o.name)}</option>`);
});
_push(`<!--]--></select><select class="select select-bordered select-xs" data-v-463df649><option${ssrRenderAttr("value", 0)} data-v-463df649${ssrIncludeBooleanAttr(Array.isArray(v.gender) ? ssrLooseContain(v.gender, 0) : ssrLooseEqual(v.gender, 0)) ? " selected" : ""}>不限</option><option${ssrRenderAttr("value", 1)} data-v-463df649${ssrIncludeBooleanAttr(Array.isArray(v.gender) ? ssrLooseContain(v.gender, 1) : ssrLooseEqual(v.gender, 1)) ? " selected" : ""}>男</option><option${ssrRenderAttr("value", 2)} data-v-463df649${ssrIncludeBooleanAttr(Array.isArray(v.gender) ? ssrLooseContain(v.gender, 2) : ssrLooseEqual(v.gender, 2)) ? " selected" : ""}>女</option></select><input${ssrRenderAttr("value", v.voice)} class="input input-bordered input-xs flex-1" placeholder="音色名,如 zh-CN-XiaoxiaoNeural" data-v-463df649><button class="btn btn-ghost btn-xs text-error" data-v-463df649>删除</button></div>`);
});
_push(`<!--]--></div></section>`);
if (isChatType.value) {
_push(`<section class="ed-section" data-v-463df649><div class="ed-section-title" data-v-463df649>对话设定</div><div data-v-463df649><span class="ed-label" data-v-463df649>系统提示词</span><textarea class="textarea textarea-bordered w-full text-xs" rows="3" placeholder="定义这个智能体的人设与行为" data-v-463df649>${ssrInterpolate(form.system_prompt)}</textarea></div><div class="mt-3" data-v-463df649><label class="flex items-center gap-2 text-sm cursor-pointer" data-v-463df649><input${ssrIncludeBooleanAttr(Array.isArray(form.greeting_enabled) ? ssrLooseContain(form.greeting_enabled, null) : form.greeting_enabled) ? " checked" : ""} type="checkbox" class="checkbox checkbox-sm checkbox-primary" data-v-463df649><span data-v-463df649>开场白</span></label>`);
if (form.greeting_enabled) {
_push(`<input${ssrRenderAttr("value", form.greeting_text)} class="input input-bordered input-sm w-full mt-2" placeholder="接通后先说的一句话" data-v-463df649>`);
} else {
_push(`<!---->`);
}
_push(`</div></section>`);
} else {
_push(`<!---->`);
}
_push(`<div class="ed-footer" data-v-463df649><label class="flex items-center gap-2 text-sm cursor-pointer" data-v-463df649><input${ssrIncludeBooleanAttr(Array.isArray(form.enable) ? ssrLooseContain(form.enable, null) : form.enable) ? " checked" : ""} type="checkbox" class="checkbox checkbox-sm checkbox-primary" data-v-463df649><span data-v-463df649>启用</span></label><div class="flex gap-2" data-v-463df649><button class="btn btn-ghost btn-sm" data-v-463df649>取消</button><button class="btn btn-primary btn-sm text-white"${ssrIncludeBooleanAttr(submitting.value) ? " disabled" : ""} data-v-463df649>保存</button></div></div></div></div></div>`);
};
}
});
const _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
const ssrContext = useSSRContext();
(ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("pages/agents.vue");
return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
const agents = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-463df649"]]);
export { agents as default };
//# sourceMappingURL=agents-sIgrTlD1.mjs.map