bailinghub 0.3.4 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitignore +5 -0
- package/README.en.md +6 -1
- package/README.md +6 -0
- package/SECURITY.md +11 -0
- package/docker-compose.images.yml +2 -2
- package/docs/AGENT_AUTH_API.en.md +175 -0
- package/docs/AGENT_AUTH_API.md +190 -0
- package/docs/AGENT_CLIENT_QUICKSTART.en.md +212 -0
- package/docs/AGENT_CLIENT_QUICKSTART.md +206 -0
- package/docs/AGENT_CLIENT_RUNTIME_API.en.md +157 -0
- package/docs/AGENT_CLIENT_RUNTIME_API.md +107 -0
- package/docs/CHANGELOG.en.md +59 -1
- package/docs/CHANGELOG.md +27 -1
- package/docs/COMPATIBILITY.en.md +25 -0
- package/docs/CONTRACT.en.md +79 -8
- package/docs/CONTRACT.md +36 -6
- package/docs/INDEPENDENT_VALIDATION.en.md +4 -4
- package/docs/INDEPENDENT_VALIDATION.md +4 -4
- package/docs/QUICKSTART.en.md +6 -0
- package/docs/QUICKSTART.md +1 -1
- package/docs/README.en.md +8 -0
- package/docs/README.md +8 -0
- package/docs/RELEASE_NOTES_v0.4.0.en.md +39 -0
- package/docs/RELEASE_NOTES_v0.4.0.md +39 -0
- package/docs/RELEASE_NOTES_v0.5.0.en.md +41 -0
- package/docs/RELEASE_NOTES_v0.5.0.md +41 -0
- package/docs/STREAMING.en.md +32 -0
- package/docs/STREAMING.md +8 -2
- package/docs/WIDGET_RENDERERS.en.md +123 -6
- package/docs/WIDGET_RENDERERS.md +75 -6
- package/docs/user-guide/console-map.en.md +1 -2
- package/docs/user-guide/console-map.md +2 -2
- package/docs//345/205/274/345/256/271/346/200/247/344/270/216/345/215/207/347/272/247.md +9 -0
- package/package.json +3 -2
- package/schemas/config/chat-entry.schema.json +2 -1
- package/schemas/config/client.schema.json +7 -0
- package/schemas/config/common.schema.json +30 -0
- package/schemas/config/route.schema.json +11 -0
- package/scripts/check-doc-links.mjs +1 -0
- package/scripts/check-image-tags.sh +1 -1
- package/scripts/check-release-consistency.test.mjs +5 -5
- package/scripts/e2e-console.mjs +144 -0
- package/scripts/export-oss.mjs +5 -12
- package/scripts/install.sh +1 -1
- package/scripts/public-content-denylist.mjs +82 -0
- package/scripts/public-content-denylist.test.mjs +53 -0
- package/scripts/publish-images.sh +1 -1
- package/scripts/release-audit.mjs +8 -12
- package/scripts/sdk-runtime-test.mjs +171 -7
- package/scripts/security-scan.mjs +8 -5
- package/scripts/validate-examples.mjs +3 -1
- package/scripts/verify-github-repo.mjs +7 -11
- package/scripts/verify-oss-export.mjs +6 -12
- package/scripts/widget-renderer-test.mjs +244 -16
- package/sdk/php/README.md +27 -1
- package/sdk/php/src/AgentAuth.php +78 -0
- package/sdk/php/src/HubClient.php +3 -0
- package/sdk/php7/README.md +32 -2
- package/sdk/php7/src/AgentAuth.php +77 -0
- package/sdk/php7/src/HubClient.php +3 -0
- package/sql/055_agent_auth.sql +72 -0
- package/sql/056_agent_client_runtime.sql +60 -0
- package/src/adapters/channels/wecom-api.ts +1 -1
- package/src/app/agent-client-runtime.test.ts +221 -0
- package/src/app/agent-client-runtime.ts +408 -0
- package/src/app/agent-tool-invocations.test.ts +462 -0
- package/src/app/agent-tool-invocations.ts +795 -0
- package/src/app/agent-tool-job.test.ts +62 -0
- package/src/app/agent-tool-job.ts +41 -0
- package/src/app/auth.ts +2 -1
- package/src/app/kernel.ts +2 -0
- package/src/app/runtime-context.ts +8 -0
- package/src/app/tool-approvals.ts +5 -1
- package/src/app/tool-assembly.ts +19 -1
- package/src/app/tool-context.ts +2 -1
- package/src/core/config/config-codec.ts +2 -1
- package/src/core/config/config-models.test.ts +28 -1
- package/src/core/config/config-models.ts +46 -3
- package/src/core/config/config-schema.test.ts +8 -0
- package/src/core/config/route-config.test.ts +15 -0
- package/src/core/config/route-config.ts +36 -0
- package/src/core/config/tools-config.test.ts +58 -1
- package/src/core/config/tools-config.ts +84 -0
- package/src/core/contracts/tools.ts +162 -29
- package/src/core/contracts/types.ts +38 -1
- package/src/core/platform/chat-form.test.ts +147 -0
- package/src/core/platform/chat-form.ts +402 -0
- package/src/core/platform/version.ts +1 -1
- package/src/core/runtime/agent-client-trace.test.ts +154 -0
- package/src/core/runtime/agent-client-trace.ts +288 -0
- package/src/core/runtime/execution-runtime.test.ts +61 -0
- package/src/core/runtime/execution-runtime.ts +17 -0
- package/src/core/runtime/launch-runtime.ts +13 -0
- package/src/core/runtime/trace-runtime.test.ts +18 -1
- package/src/core/runtime/trace-runtime.ts +28 -3
- package/src/core/state/state-codec.ts +2 -0
- package/src/infrastructure/config/config-agent-auth-repository.test.ts +147 -0
- package/src/infrastructure/config/config-agent-auth-repository.ts +356 -0
- package/src/infrastructure/config/config-agent-client-runtime-repository.ts +253 -0
- package/src/infrastructure/config/config-approval-ledger.test.ts +32 -0
- package/src/infrastructure/config/config-approval-ledger.ts +16 -0
- package/src/infrastructure/config/config-client-repository.ts +3 -3
- package/src/infrastructure/config/config-conversation-ledger.test.ts +69 -0
- package/src/infrastructure/config/config-conversation-ledger.ts +8 -7
- package/src/infrastructure/config/config-observability-ledger.test.ts +50 -0
- package/src/infrastructure/config/config-observability-ledger.ts +65 -10
- package/src/infrastructure/config/config-route-repository.ts +4 -3
- package/src/infrastructure/config/configstore.ts +14 -3
- package/src/infrastructure/state/state-mysql.ts +2 -2
- package/src/kernel-api/v1/contracts.ts +8 -0
- package/src/routes/admin-runtime.test.ts +214 -0
- package/src/routes/admin-runtime.ts +82 -2
- package/src/routes/agent-api.test.ts +379 -0
- package/src/routes/agent-api.ts +251 -0
- package/src/routes/agent-auth.test.ts +276 -0
- package/src/routes/agent-auth.ts +395 -0
- package/src/routes/approvals.ts +4 -1
- package/src/routes/chat.test.ts +319 -7
- package/src/routes/chat.ts +166 -21
- package/src/routes/critical-routes.test.ts +235 -1
- package/src/routes/private-default.ts +2 -1
- package/src/routes/private.ts +16 -1
- package/src/routes/run.ts +79 -13
- package/web/connect/bailing-connect-php.tgz +0 -0
- package/web/connect/bailing-connect-php7.tgz +0 -0
- package/web/console/assets/{Accounts-CAwrtBiS.js → Accounts-D4RRm5D1.js} +1 -1
- package/web/console/assets/{Approvals-C2BZ86T3.js → Approvals-CsTTKb8o.js} +1 -1
- package/web/console/assets/{Audit-B-E4Y_Up.js → Audit-BzvZ7JZw.js} +1 -1
- package/web/console/assets/{BrandLockup-C18u8Lx5.js → BrandLockup-CYcA93wh.js} +1 -1
- package/web/console/assets/{Channels-DTy8ylH-.js → Channels-DRQZggqM.js} +1 -1
- package/web/console/assets/ChatEntries-BUB7BWKU.js +7 -0
- package/web/console/assets/ChatEntries-DsYtcXN6.css +1 -0
- package/web/console/assets/Clients-CQ_MonGL.css +1 -0
- package/web/console/assets/Clients-HhCyrxfz.js +3 -0
- package/web/console/assets/{Cost-2SSYs1AT.js → Cost-BZgFf1yM.js} +1 -1
- package/web/console/assets/{Credentials-B79LtxCE.js → Credentials-BTe2Q07j.js} +1 -1
- package/web/console/assets/{Diagnostics-BakcRYvb.js → Diagnostics-WL-buYli.js} +1 -1
- package/web/console/assets/{Executors-BXoyo28u.js → Executors-CGZ-7Xmp.js} +1 -1
- package/web/console/assets/{Kb-ISbzquab.js → Kb-VVw8oGsT.js} +1 -1
- package/web/console/assets/{Login-Dlu6Wgcf.js → Login-rwvmBBPl.js} +1 -1
- package/web/console/assets/{Projects-DFzmtnqg.js → Projects-CexaCEY1.js} +1 -1
- package/web/console/assets/Routes-B9ZHbQAp.js +124 -0
- package/web/console/assets/Routes-BbkFpi6Y.css +1 -0
- package/web/console/assets/Runs-4zDD9VOC.css +1 -0
- package/web/console/assets/Runs-BzFNPTwD.js +3 -0
- package/web/console/assets/{Setup-CrBAV-b9.js → Setup-Djh5yadQ.js} +1 -1
- package/web/console/assets/{Shell-B1a8DvXQ.js → Shell-kn763smL.js} +1 -1
- package/web/console/assets/{StorageBuckets-BRfL_eHb.js → StorageBuckets-CQBR41W1.js} +1 -1
- package/web/console/assets/{SystemSettings-CyirVLbq.js → SystemSettings-DgnopekD.js} +1 -1
- package/web/console/assets/{SystemStatus-DZ_OR7sk.js → SystemStatus-Bj8-kPt2.js} +1 -1
- package/web/console/assets/{Targets-CtIMa66c.js → Targets-BAfCt_nH.js} +1 -1
- package/web/console/assets/{Tools-BfDZHt01.js → Tools-xjd0NZdE.js} +1 -1
- package/web/console/assets/{index-DBiByFiO.js → index-DfJA7iJS.js} +2 -2
- package/web/console/assets/{request-DY2cxQqZ.js → request-DkNPOweH.js} +1 -1
- package/web/console/assets/{schema-6mCQ7rR5.js → schema-CgPWAu1_.js} +1 -1
- package/web/console/index.html +1 -1
- package/web/widget/widget.js +493 -14
- package/web-admin/src/pages/ChatEntries.vue +18 -6
- package/web-admin/src/pages/Clients.vue +11 -3
- package/web-admin/src/pages/Routes.vue +282 -16
- package/web-admin/src/pages/Runs.vue +159 -38
- package/web/console/assets/ChatEntries-9xbRiQov.css +0 -1
- package/web/console/assets/ChatEntries-DvD-4IeE.js +0 -7
- package/web/console/assets/Clients--D7NQJKk.css +0 -1
- package/web/console/assets/Clients-DWs9JFr0.js +0 -3
- package/web/console/assets/Routes-B-hm9HGY.js +0 -124
- package/web/console/assets/Routes-DWGQN5Pv.css +0 -1
- package/web/console/assets/Runs-CUtSsPW-.css +0 -1
- package/web/console/assets/Runs-hMRu1im3.js +0 -3
|
@@ -111,6 +111,7 @@
|
|
|
111
111
|
<el-form-item>
|
|
112
112
|
<template #label>站点 Origin <HelpTip title="Origin 白名单">
|
|
113
113
|
<p>一行一个,如 <code>https://www.example.com</code>。留空 = 不限(试用模式),<b>正式上线建议配置</b>。</p>
|
|
114
|
+
<p>只填 <code>scheme://host[:port]</code>,不要带业务路径、查询参数或 <code>#</code> 片段;保存时会规范化并去重。</p>
|
|
114
115
|
<p>它只防"别家网页盗嵌"——<b>小程序 / 服务端调用不带浏览器 Origin 头,不会被白名单拦截</b>,可放心配。</p>
|
|
115
116
|
</HelpTip></template>
|
|
116
117
|
<el-input v-model="form.origins_text" type="textarea" :rows="3" class="mono" placeholder="https://www.example.com" />
|
|
@@ -162,6 +163,14 @@
|
|
|
162
163
|
<p class="muted">适合当工作台用、要读长回答/表格的场景;轻量问答可保持关闭。手机端面板本就接近全屏,此开关自动不生效。</p></HelpTip></template>
|
|
163
164
|
<el-switch v-model="form.resizable" />
|
|
164
165
|
</el-form-item>
|
|
166
|
+
<el-form-item>
|
|
167
|
+
<template #label>默认展开 <HelpTip title="嵌入后默认展开">
|
|
168
|
+
<p>开启后,业务页面加载嵌入脚本时会直接展开聊天窗口,访客仍可手动最小化。</p>
|
|
169
|
+
<p class="muted">关闭时默认只显示气泡按钮;已显式使用 <code>data-open="1"</code> 的嵌入代码仍会展开。</p>
|
|
170
|
+
</HelpTip></template>
|
|
171
|
+
<el-switch v-model="form.default_open" />
|
|
172
|
+
<span class="state-copy">{{ form.default_open ? '加载即展开' : '默认显示气泡' }}</span>
|
|
173
|
+
</el-form-item>
|
|
165
174
|
<el-form-item>
|
|
166
175
|
<template #label>AI 内容提示 <HelpTip title="AI 内容提示">
|
|
167
176
|
<p>开启后,每条 AI 回复下方显示「由 AI 生成,请结合实际业务结果核验」,复制回复时也会附带该提示。</p>
|
|
@@ -409,7 +418,7 @@ const open = ref(false);
|
|
|
409
418
|
const editing = ref(false);
|
|
410
419
|
const saving = ref(false);
|
|
411
420
|
const chatFormTab = ref<'basic' | 'appearance' | 'publish'>('basic');
|
|
412
|
-
const APPEARANCE_DEFAULTS = { title_align: 'center', width: 400, height: 600, position: 'right', offset_x: 24, offset_y: 24, avatar: '', launcher_icon: '', resizable: false, ai_notice: true, powered_by_visible: true, powered_by_text: '' };
|
|
421
|
+
const APPEARANCE_DEFAULTS = { title_align: 'center', width: 400, height: 600, position: 'right', offset_x: 24, offset_y: 24, avatar: '', launcher_icon: '', default_open: false, resizable: false, ai_notice: true, powered_by_visible: true, powered_by_text: '' };
|
|
413
422
|
const form = reactive({ entry_key: '', name: '', route_key: '', origins_text: '', ticket_client: '', bucket: '', title: '', greeting: '', color: '#3fb950', ...APPEARANCE_DEFAULTS, rate_limit_per_min: 20, description: '', enabled: true });
|
|
414
423
|
const entryToggleKey = ref('');
|
|
415
424
|
|
|
@@ -556,7 +565,7 @@ function openEdit(row: any): void {
|
|
|
556
565
|
position: ap.position === 'left' ? 'left' : 'right',
|
|
557
566
|
offset_x: Number.isFinite(Number(ap.offset_x)) ? Number(ap.offset_x) : 24,
|
|
558
567
|
offset_y: Number.isFinite(Number(ap.offset_y)) ? Number(ap.offset_y) : 24,
|
|
559
|
-
avatar: ap.avatar || '', launcher_icon: ap.launcher_icon || '', resizable: !!ap.resizable, ai_notice: ap.ai_notice !== false,
|
|
568
|
+
avatar: ap.avatar || '', launcher_icon: ap.launcher_icon || '', default_open: !!ap.default_open, resizable: !!ap.resizable, ai_notice: ap.ai_notice !== false,
|
|
560
569
|
powered_by_visible: ap.powered_by_visible !== false, powered_by_text: ap.powered_by_text || '',
|
|
561
570
|
rate_limit_per_min: row.rate_limit_per_min, description: row.description || '', enabled: !!row.enabled,
|
|
562
571
|
});
|
|
@@ -596,9 +605,10 @@ async function delPageRule(id: number): Promise<void> {
|
|
|
596
605
|
async function save(): Promise<void> {
|
|
597
606
|
saving.value = true;
|
|
598
607
|
try {
|
|
608
|
+
const origins = form.origins_text.split('\n').map((s) => s.trim()).filter(Boolean);
|
|
599
609
|
const body = {
|
|
600
610
|
entry_key: form.entry_key || undefined, name: form.name.trim(), route_key: form.route_key,
|
|
601
|
-
allowed_origins:
|
|
611
|
+
allowed_origins: origins,
|
|
602
612
|
ticket_client: form.ticket_client || undefined, bucket: form.bucket || undefined,
|
|
603
613
|
title: form.title.trim() || undefined, greeting: form.greeting.trim() || undefined,
|
|
604
614
|
color: form.color || undefined, rate_limit_per_min: form.rate_limit_per_min,
|
|
@@ -607,6 +617,7 @@ async function save(): Promise<void> {
|
|
|
607
617
|
position: form.position, offset_x: form.offset_x, offset_y: form.offset_y,
|
|
608
618
|
...(form.avatar.trim() ? { avatar: form.avatar.trim() } : {}),
|
|
609
619
|
...(form.launcher_icon.trim() ? { launcher_icon: form.launcher_icon.trim() } : {}),
|
|
620
|
+
...(form.default_open ? { default_open: true } : {}),
|
|
610
621
|
...(form.resizable ? { resizable: true } : {}),
|
|
611
622
|
...(form.ai_notice === false ? { ai_notice: false } : {}),
|
|
612
623
|
...(form.powered_by_visible === false ? { powered_by_visible: false } : {}),
|
|
@@ -615,12 +626,13 @@ async function save(): Promise<void> {
|
|
|
615
626
|
description: form.description.trim() || undefined, enabled: form.enabled,
|
|
616
627
|
};
|
|
617
628
|
const r = await api<{ entry_key: string }>('/admin/api/chat-entries', { method: 'POST', body: JSON.stringify(body) });
|
|
618
|
-
ElMessage.success('已保存');
|
|
619
629
|
open.value = false;
|
|
620
630
|
await load();
|
|
631
|
+
const savedRow = list.value.find((x) => x.entry_key === r.entry_key);
|
|
632
|
+
const savedOriginCount = Array.isArray(savedRow?.allowed_origins) ? savedRow.allowed_origins.filter(Boolean).length : 0;
|
|
633
|
+
ElMessage.success(savedOriginCount ? `已保存,Origin 白名单已限制 ${savedOriginCount} 个站点` : '已保存,当前未限制 Origin');
|
|
621
634
|
if (!editing.value) { // 新建后直接亮嵌入代码,少一次寻找
|
|
622
|
-
|
|
623
|
-
if (row) openEmbed(row);
|
|
635
|
+
if (savedRow) openEmbed(savedRow);
|
|
624
636
|
}
|
|
625
637
|
} catch (e) { ElMessage.error((e as Error).message); }
|
|
626
638
|
finally { saving.value = false; }
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
<div class="protection-stack">
|
|
57
57
|
<div>
|
|
58
58
|
<el-tag size="small" effect="plain" :type="row.enabled ? 'success' : 'info'">{{ row.enabled ? '已启用' : '已停用' }}</el-tag>
|
|
59
|
+
<el-tag v-if="row.agent_authorize_url" size="small" effect="plain" type="primary">Agent 登录</el-tag>
|
|
59
60
|
<el-tag v-if="hasBudget(row)" size="small" effect="plain" type="danger">预算闸</el-tag>
|
|
60
61
|
</div>
|
|
61
62
|
<span class="muted">限速 {{ row.rate_limit_per_min ? row.rate_limit_per_min + '/分' : '不限' }}</span>
|
|
@@ -97,6 +98,13 @@
|
|
|
97
98
|
</HelpTip></template>
|
|
98
99
|
<el-input v-model="form.name" placeholder="如 业务系统" />
|
|
99
100
|
</el-form-item>
|
|
101
|
+
<el-form-item>
|
|
102
|
+
<template #label>{{ fieldTitle('agent_authorize_url', 'Agent 授权页') }} <HelpTip :title="fieldTitle('agent_authorize_url', 'Agent 授权页')">
|
|
103
|
+
<p>{{ fieldDesc('agent_authorize_url', '本地 Agent 发起登录时打开的业务系统网页。') }}</p>
|
|
104
|
+
<p>留空表示不开放 Agent 登录。生产必须使用 HTTPS;本机联调可使用带端口的 <code>127.0.0.1</code> / <code>::1</code> HTTP URL。</p>
|
|
105
|
+
</HelpTip></template>
|
|
106
|
+
<el-input v-model="form.agent_authorize_url" placeholder="https://business.example.com/agent-authorize" class="mono" />
|
|
107
|
+
</el-form-item>
|
|
100
108
|
<el-form-item>
|
|
101
109
|
<template #label>{{ fieldTitle('allowed_routes', '可调路由') }} <span v-if="fieldRequired('allowed_routes')" class="field-required">*</span> <HelpTip :title="fieldTitle('allowed_routes', '可调路由')">
|
|
102
110
|
<p>{{ fieldDesc('allowed_routes', '该接入方可触发哪些 route。') }}</p>
|
|
@@ -188,7 +196,7 @@ const ticketOf = ref<Record<string, string[]>>({});
|
|
|
188
196
|
const open = ref(false);
|
|
189
197
|
const editing = ref(false);
|
|
190
198
|
const saving = ref(false);
|
|
191
|
-
const form = reactive({ app_id: '', name: '', allowed_routes: [] as string[], allowed_channels: [] as string[], rate_limit_per_min: 60, description: '', enabled: true });
|
|
199
|
+
const form = reactive({ app_id: '', name: '', agent_authorize_url: '', allowed_routes: [] as string[], allowed_channels: [] as string[], rate_limit_per_min: 60, description: '', enabled: true });
|
|
192
200
|
const budget = reactive<{ enabled: boolean; window: 'hour' | 'day' | 'month'; hard_cost_usd?: number; hard_tokens?: number }>({ enabled: false, window: 'day', hard_cost_usd: undefined, hard_tokens: undefined });
|
|
193
201
|
let budgetRest: Record<string, unknown> = {};
|
|
194
202
|
|
|
@@ -254,13 +262,13 @@ function budgetPayload(): Record<string, unknown> | undefined {
|
|
|
254
262
|
}
|
|
255
263
|
function openCreate(): void {
|
|
256
264
|
editing.value = false;
|
|
257
|
-
Object.assign(form, { app_id: '', name: '', allowed_routes: [], allowed_channels: [], rate_limit_per_min: 60, description: '', enabled: true });
|
|
265
|
+
Object.assign(form, { app_id: '', name: '', agent_authorize_url: '', allowed_routes: [], allowed_channels: [], rate_limit_per_min: 60, description: '', enabled: true });
|
|
258
266
|
resetBudget();
|
|
259
267
|
open.value = true;
|
|
260
268
|
}
|
|
261
269
|
function openEdit(row: any): void {
|
|
262
270
|
editing.value = true;
|
|
263
|
-
Object.assign(form, { app_id: row.app_id, name: row.name, allowed_routes: [...(row.allowed_routes || [])], allowed_channels: [...(row.allowed_channels || [])], rate_limit_per_min: row.rate_limit_per_min ?? 60, description: row.description || '', enabled: !!row.enabled });
|
|
271
|
+
Object.assign(form, { app_id: row.app_id, name: row.name, agent_authorize_url: row.agent_authorize_url || '', allowed_routes: [...(row.allowed_routes || [])], allowed_channels: [...(row.allowed_channels || [])], rate_limit_per_min: row.rate_limit_per_min ?? 60, description: row.description || '', enabled: !!row.enabled });
|
|
264
272
|
hydrateBudget(row.budget);
|
|
265
273
|
open.value = true;
|
|
266
274
|
}
|
|
@@ -374,6 +374,23 @@
|
|
|
374
374
|
</HelpTip></template>
|
|
375
375
|
<el-input v-model="mem.summary_model" placeholder="留空=用本路由凭证默认模型" class="mono" />
|
|
376
376
|
</el-form-item>
|
|
377
|
+
<el-form-item>
|
|
378
|
+
<template #label>本地 Agent Runtime <HelpTip title="本地 Agent Runtime">
|
|
379
|
+
<p>开启后,已通过业务网页授权的本地 Agent 可以读取本路由的安全运行档、会话记忆和按需工具定义,并在本地完成编排。</p>
|
|
380
|
+
<p>它仍复用 <code>tools.agent_direct</code> 的工具授权与审批治理;这里只配置本地编排补充指令和每轮主动披露数量,不会返回模型凭证或工具源密钥。</p>
|
|
381
|
+
</HelpTip></template>
|
|
382
|
+
<el-switch v-model="agentClient.enabled" @change="agentClient.configured = true" />
|
|
383
|
+
</el-form-item>
|
|
384
|
+
<template v-if="agentClient.enabled">
|
|
385
|
+
<el-form-item label="本地编排补充指令">
|
|
386
|
+
<el-input v-model="agentClient.instructions" type="textarea" :rows="4" maxlength="20000" show-word-limit
|
|
387
|
+
placeholder="可选:仅给本地 Agent 的补充规则;路由系统提示词会安全抽取并一并下发" @input="agentClient.configured = true" />
|
|
388
|
+
</el-form-item>
|
|
389
|
+
<el-form-item label="每轮主动工具数">
|
|
390
|
+
<el-input-number v-model="agentClient.active_tool_limit" :min="1" :max="12" @change="agentClient.configured = true" />
|
|
391
|
+
<div class="muted hint">每轮只返回最相关的完整 typed tools;其余授权能力可通过搜索按需发现,避免全量 schema 撑大上下文。</div>
|
|
392
|
+
</el-form-item>
|
|
393
|
+
</template>
|
|
377
394
|
<el-form-item>
|
|
378
395
|
<template #label>成本预算闸 <HelpTip title="成本预算闸">
|
|
379
396
|
<p>按本路由在指定窗口内的历史用量做入口硬限。达到成本或 token 上限后,新任务会直接记为 <code>rejected</code>,不会再进入模型、执行器或工具链路。</p>
|
|
@@ -577,6 +594,65 @@
|
|
|
577
594
|
</el-select>
|
|
578
595
|
</el-form-item>
|
|
579
596
|
</div>
|
|
597
|
+
<template v-if="agentClient.enabled || agentDirect.configured || agentDirect.enabled">
|
|
598
|
+
<div class="form-section-title agent-direct-title">
|
|
599
|
+
<span>本地 Agent 直连工具</span>
|
|
600
|
+
<HelpTip title="本地 Agent 直连工具">
|
|
601
|
+
<p>仅用于已通过业务身份授权的本地 Agent Runtime。本地 Agent 负责编排,中枢仍在每次调用时执行路由、主体、ACC 风险与审批治理。</p>
|
|
602
|
+
<p>开启后只读工具按上方 scope 白名单自动可见;写工具还必须在下方按精确 <code>operationId</code> 再授权,不接受 <code>*</code>。</p>
|
|
603
|
+
</HelpTip>
|
|
604
|
+
</div>
|
|
605
|
+
<el-form-item label="允许本地 Agent 直调">
|
|
606
|
+
<el-switch v-model="agentDirect.enabled" @change="agentDirect.configured = true" />
|
|
607
|
+
</el-form-item>
|
|
608
|
+
<el-alert v-if="agentClient.enabled && !agentDirect.enabled" class="agent-direct-alert" type="warning" :closable="false" show-icon
|
|
609
|
+
title="本地 Agent Runtime 已开启,但直连工具面未开启;本地 Agent 不会获得这条路由的业务工具。" />
|
|
610
|
+
<template v-if="agentDirect.enabled">
|
|
611
|
+
<el-alert class="agent-direct-alert" type="info" :closable="false" show-icon
|
|
612
|
+
title="这里只放行本地 Agent 工具面,不会把工具源密钥或模型凭证下发到本地。" />
|
|
613
|
+
<el-alert v-if="form.permission === 'readonly'" class="agent-direct-alert" type="warning" :closable="false" show-icon
|
|
614
|
+
title="当前路由权限档为只读;即使列出写 operationId,运行时也不会暴露写工具。" />
|
|
615
|
+
<div v-if="agentDirectToolOptions.length" class="agent-direct-catalog-summary">
|
|
616
|
+
已从当前工具源读取 {{ agentDirectToolOptions.length }} 个 operationId:{{ agentDirectReadonlyCount }} 个只读自动继承,{{ agentDirectWriteOptions.length }} 个写操作可精确授权。
|
|
617
|
+
</div>
|
|
618
|
+
<el-form-item>
|
|
619
|
+
<template #label>允许的写操作 <HelpTip title="本地 Agent 写操作白名单">
|
|
620
|
+
<p>只有精确列入的写工具才会暴露给本地 Agent。候选项来自已选工具源的 <code>/tools</code> 编译结果,并且必须已被上方 scope 放行。</p>
|
|
621
|
+
<p>可手动填写尚未拉取到的 operationId,但不允许 <code>*</code> 或其他通配符。</p>
|
|
622
|
+
</HelpTip></template>
|
|
623
|
+
<el-select v-model="agentDirect.write_tools" multiple filterable allow-create default-first-option
|
|
624
|
+
style="width: 100%" placeholder="选择写操作,或手填精确 operationId" @change="onAgentDirectNamesChange('write_tools')">
|
|
625
|
+
<el-option v-for="tool in agentDirectWriteOptions" :key="tool.name" :value="tool.name" :label="tool.name">
|
|
626
|
+
<div class="agent-tool-option">
|
|
627
|
+
<code>{{ tool.name }}</code>
|
|
628
|
+
<span class="agent-tool-option__meta">{{ tool.providers.join(' / ') }} · {{ tool.scope }}</span>
|
|
629
|
+
<el-tag size="small" type="warning" effect="plain">写入</el-tag>
|
|
630
|
+
<el-tag size="small" :type="agentToolRiskType(tool.risk)" effect="plain">{{ tool.risk }} 风险</el-tag>
|
|
631
|
+
<el-tag v-if="tool.confirm_required || tool.risk === 'high'" size="small" type="danger" effect="plain">ACC 已需审批</el-tag>
|
|
632
|
+
</div>
|
|
633
|
+
</el-option>
|
|
634
|
+
</el-select>
|
|
635
|
+
<div class="field-hint">只读工具不需逐个列出;开启直调后会按工具源 scope 与业务主体权限自动暴露。</div>
|
|
636
|
+
</el-form-item>
|
|
637
|
+
<el-form-item>
|
|
638
|
+
<template #label>额外强制审批 <HelpTip title="额外强制审批">
|
|
639
|
+
<p>默认完全继承工具 ACC 声明的风险和审批要求。只在路由希望比 ACC 更严格时,才把已允许的写 operationId 加入这个子集。</p>
|
|
640
|
+
<p>这个列表只能从“允许的写操作”中选,不会放宽 ACC 原有治理。</p>
|
|
641
|
+
</HelpTip></template>
|
|
642
|
+
<el-select v-model="agentDirect.force_approval_tools" multiple filterable allow-create default-first-option
|
|
643
|
+
style="width: 100%" placeholder="留空 = 完全继承 ACC 审批声明" @change="onAgentDirectNamesChange('force_approval_tools')">
|
|
644
|
+
<el-option v-for="tool in agentDirectApprovalOptions" :key="tool.name" :value="tool.name" :label="tool.name">
|
|
645
|
+
<div class="agent-tool-option">
|
|
646
|
+
<code>{{ tool.name }}</code>
|
|
647
|
+
<span v-if="tool.providers.length" class="agent-tool-option__meta">{{ tool.providers.join(' / ') }}<template v-if="tool.scope"> · {{ tool.scope }}</template></span>
|
|
648
|
+
<span v-else class="agent-tool-option__meta">手动 operationId</span>
|
|
649
|
+
<el-tag size="small" :type="agentToolRiskType(tool.risk)" effect="plain">{{ tool.risk }} 风险</el-tag>
|
|
650
|
+
</div>
|
|
651
|
+
</el-option>
|
|
652
|
+
</el-select>
|
|
653
|
+
</el-form-item>
|
|
654
|
+
</template>
|
|
655
|
+
</template>
|
|
580
656
|
<template v-if="tl.sources.length">
|
|
581
657
|
<el-form-item label="单任务业务工具调用上限">
|
|
582
658
|
<el-input-number v-model="tl.max_calls" :min="1" :max="50" />
|
|
@@ -844,14 +920,28 @@ interface ToolSourceForm {
|
|
|
844
920
|
allow: string[];
|
|
845
921
|
subject_field: string;
|
|
846
922
|
scopeOptions: Array<{ scope: string; names: string[] }>;
|
|
923
|
+
toolOptions: ProviderToolOption[];
|
|
847
924
|
scopesLoading: boolean;
|
|
848
925
|
rest: Record<string, unknown>;
|
|
849
926
|
}
|
|
927
|
+
interface ProviderToolOption {
|
|
928
|
+
name: string;
|
|
929
|
+
scope: string;
|
|
930
|
+
readonly: boolean;
|
|
931
|
+
risk: string;
|
|
932
|
+
confirm_required: boolean;
|
|
933
|
+
provider: string;
|
|
934
|
+
}
|
|
935
|
+
interface AgentDirectToolOption extends Omit<ProviderToolOption, 'provider'> {
|
|
936
|
+
providers: string[];
|
|
937
|
+
allowed: boolean;
|
|
938
|
+
}
|
|
850
939
|
let toolSourceSeq = 0;
|
|
851
940
|
function newToolSource(over: Partial<ToolSourceForm> = {}): ToolSourceForm {
|
|
852
|
-
return { form_key: `tool-source-${++toolSourceSeq}`, provider: '', allow: [], subject_field: '', scopeOptions: [], scopesLoading: false, rest: {}, ...over };
|
|
941
|
+
return { form_key: `tool-source-${++toolSourceSeq}`, provider: '', allow: [], subject_field: '', scopeOptions: [], toolOptions: [], scopesLoading: false, rest: {}, ...over };
|
|
853
942
|
}
|
|
854
943
|
const tl = reactive({ sources: [] as ToolSourceForm[], max_calls: 5, send_channels: [] as string[] });
|
|
944
|
+
const agentDirect = reactive({ configured: false, enabled: false, write_tools: [] as string[], force_approval_tools: [] as string[] });
|
|
855
945
|
const ap = reactive({ type: '', url: '' });
|
|
856
946
|
const au = reactive({
|
|
857
947
|
enabled: false, auto: false, anonymous: false, priority: 0,
|
|
@@ -859,8 +949,9 @@ const au = reactive({
|
|
|
859
949
|
tenants: [] as string[], roles: [] as string[], principals: [] as string[], audiences: [] as string[],
|
|
860
950
|
});
|
|
861
951
|
const mem = reactive({ recent_messages: 12, recent_budget_chars: 3500, summary_enabled: false, summary_trigger_chars: 4000, summary_keep_recent: 6, summary_model: '' });
|
|
952
|
+
const agentClient = reactive({ configured: false, inherited: false, enabled: false, instructions: '', active_tool_limit: 8 });
|
|
862
953
|
const budget = reactive<{ enabled: boolean; window: 'hour' | 'day' | 'month'; hard_cost_usd?: number; hard_tokens?: number }>({ enabled: false, window: 'day', hard_cost_usd: undefined, hard_tokens: undefined });
|
|
863
|
-
let llmRest: Record<string, unknown> = {}, inputRest: Record<string, unknown> = {}, knRest: Record<string, unknown> = {}, dvRest: Record<string, unknown> = {}, rtRest: Record<string, unknown> = {}, tlRest: Record<string, unknown> = {}, builtinRest: Record<string, unknown> = {}, sendRest: Record<string, unknown> = {}, apRest: Record<string, unknown> = {}, audienceRest: Record<string, unknown> = {}, memRest: Record<string, unknown> = {}, budgetRest: Record<string, unknown> = {};
|
|
954
|
+
let llmRest: Record<string, unknown> = {}, inputRest: Record<string, unknown> = {}, knRest: Record<string, unknown> = {}, dvRest: Record<string, unknown> = {}, rtRest: Record<string, unknown> = {}, tlRest: Record<string, unknown> = {}, agentDirectRest: Record<string, unknown> = {}, builtinRest: Record<string, unknown> = {}, sendRest: Record<string, unknown> = {}, apRest: Record<string, unknown> = {}, audienceRest: Record<string, unknown> = {}, memRest: Record<string, unknown> = {}, agentClientRest: Record<string, unknown> = {}, budgetRest: Record<string, unknown> = {};
|
|
864
955
|
|
|
865
956
|
// 会话策略只对 /run API 触发生效;聊天入口与渠道入站走自己的 scope 自动续聊、不读此项。
|
|
866
957
|
// 算出当前编辑路由被哪些入口/渠道使用,据此提示用户「本项在这条路由下到底有没有用」。
|
|
@@ -878,6 +969,11 @@ function splitKnown(obj: unknown, keys: string[]): [Record<string, unknown>, Rec
|
|
|
878
969
|
for (const [k, v] of Object.entries((obj ?? {}) as Record<string, unknown>)) (keys.includes(k) ? known : rest)[k] = v;
|
|
879
970
|
return [known, rest];
|
|
880
971
|
}
|
|
972
|
+
function stringArray(value: unknown): string[] {
|
|
973
|
+
if (Array.isArray(value)) return value.map((item) => String(item)).filter(Boolean);
|
|
974
|
+
if (typeof value === 'string' && value) return value.split(',').map((item) => item.trim()).filter(Boolean);
|
|
975
|
+
return [];
|
|
976
|
+
}
|
|
881
977
|
|
|
882
978
|
// ---- 关联注册表的下拉数据(无权限时静默退化为手输——下拉都带 allow-create) ----
|
|
883
979
|
const credOptions = ref<Array<{ name: string; default_model?: string; base_url?: string; enabled: boolean }>>([]);
|
|
@@ -958,12 +1054,23 @@ const notifyChannels = computed(() => notifyTargetsRaw.value.map((t) => {
|
|
|
958
1054
|
}));
|
|
959
1055
|
|
|
960
1056
|
async function loadScopes(source: ToolSourceForm): Promise<void> {
|
|
961
|
-
source.scopesLoading = true; source.scopeOptions = [];
|
|
1057
|
+
source.scopesLoading = true; source.scopeOptions = []; source.toolOptions = [];
|
|
962
1058
|
try {
|
|
963
|
-
const d = await api<{ tools: Array<{ name: string; scope: string }> }>('/admin/api/tool-providers/' + encodeURIComponent(source.provider) + '/tools');
|
|
1059
|
+
const d = await api<{ tools: Array<{ name: string; scope: string; readonly: boolean; risk: string; confirm_required: boolean }> }>('/admin/api/tool-providers/' + encodeURIComponent(source.provider) + '/tools');
|
|
964
1060
|
const m = new Map<string, string[]>();
|
|
965
|
-
for (const t of d.tools) {
|
|
1061
|
+
for (const t of d.tools) {
|
|
1062
|
+
if (!m.has(t.scope)) m.set(t.scope, []);
|
|
1063
|
+
m.get(t.scope)!.push(t.name);
|
|
1064
|
+
}
|
|
966
1065
|
source.scopeOptions = Array.from(m, ([scope, names]) => ({ scope, names }));
|
|
1066
|
+
source.toolOptions = d.tools.map((tool) => ({
|
|
1067
|
+
name: tool.name,
|
|
1068
|
+
scope: tool.scope,
|
|
1069
|
+
readonly: tool.readonly === true,
|
|
1070
|
+
risk: String(tool.risk || 'unknown'),
|
|
1071
|
+
confirm_required: tool.confirm_required === true,
|
|
1072
|
+
provider: source.provider,
|
|
1073
|
+
}));
|
|
967
1074
|
} catch { /* 无权限/源异常 → 手输 scope(allow-create) */ }
|
|
968
1075
|
finally { source.scopesLoading = false; }
|
|
969
1076
|
}
|
|
@@ -974,6 +1081,80 @@ function onProviderChange(source: ToolSourceForm): void {
|
|
|
974
1081
|
function addToolSource(): void { tl.sources.push(newToolSource()); }
|
|
975
1082
|
function removeToolSource(index: number): void { tl.sources.splice(index, 1); }
|
|
976
1083
|
|
|
1084
|
+
const agentDirectToolOptions = computed<AgentDirectToolOption[]>(() => {
|
|
1085
|
+
const merged = new Map<string, AgentDirectToolOption>();
|
|
1086
|
+
for (const source of tl.sources) {
|
|
1087
|
+
for (const tool of source.toolOptions) {
|
|
1088
|
+
const allowed = source.allow.includes('*') || source.allow.includes(tool.scope);
|
|
1089
|
+
const current = merged.get(tool.name);
|
|
1090
|
+
if (current) {
|
|
1091
|
+
if (!current.providers.includes(tool.provider)) current.providers.push(tool.provider);
|
|
1092
|
+
current.allowed ||= allowed;
|
|
1093
|
+
current.readonly &&= tool.readonly;
|
|
1094
|
+
current.confirm_required ||= tool.confirm_required;
|
|
1095
|
+
if (['unknown', 'low', 'medium', 'high'].indexOf(tool.risk) > ['unknown', 'low', 'medium', 'high'].indexOf(current.risk)) current.risk = tool.risk;
|
|
1096
|
+
continue;
|
|
1097
|
+
}
|
|
1098
|
+
merged.set(tool.name, { ...tool, providers: [tool.provider], allowed });
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
return Array.from(merged.values()).sort((a, b) => a.name.localeCompare(b.name));
|
|
1102
|
+
});
|
|
1103
|
+
const agentDirectWriteOptions = computed(() => agentDirectToolOptions.value.filter((tool) => !tool.readonly && tool.allowed));
|
|
1104
|
+
const agentDirectReadonlyCount = computed(() => agentDirectToolOptions.value.filter((tool) => tool.readonly && tool.allowed).length);
|
|
1105
|
+
const agentDirectApprovalOptions = computed<AgentDirectToolOption[]>(() => {
|
|
1106
|
+
const catalog = new Map(agentDirectToolOptions.value.map((tool) => [tool.name, tool]));
|
|
1107
|
+
return agentDirect.write_tools.map((name) => catalog.get(name) ?? {
|
|
1108
|
+
name,
|
|
1109
|
+
scope: '',
|
|
1110
|
+
readonly: false,
|
|
1111
|
+
risk: 'unknown',
|
|
1112
|
+
confirm_required: false,
|
|
1113
|
+
providers: [],
|
|
1114
|
+
allowed: false,
|
|
1115
|
+
});
|
|
1116
|
+
});
|
|
1117
|
+
|
|
1118
|
+
const OPERATION_ID_RE = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/;
|
|
1119
|
+
type AgentDirectListField = 'write_tools' | 'force_approval_tools';
|
|
1120
|
+
function onAgentDirectNamesChange(field: AgentDirectListField): void {
|
|
1121
|
+
agentDirect.configured = true;
|
|
1122
|
+
const values = agentDirect[field].map((value) => String(value).trim()).filter(Boolean);
|
|
1123
|
+
const invalid = values.filter((value) => !OPERATION_ID_RE.test(value));
|
|
1124
|
+
if (invalid.length) {
|
|
1125
|
+
agentDirect[field] = [...new Set(values.filter((value) => OPERATION_ID_RE.test(value)))];
|
|
1126
|
+
ElMessage.warning(invalid.includes('*') ? '本地 Agent 工具不允许 *,请选择或填写精确 operationId' : 'operationId 只允许字母、数字和下划线,且以字母或下划线开头');
|
|
1127
|
+
} else {
|
|
1128
|
+
agentDirect[field] = [...new Set(values)];
|
|
1129
|
+
}
|
|
1130
|
+
if (field === 'write_tools') {
|
|
1131
|
+
const writes = new Set(agentDirect.write_tools);
|
|
1132
|
+
const removed = agentDirect.force_approval_tools.filter((name) => !writes.has(name));
|
|
1133
|
+
if (removed.length) {
|
|
1134
|
+
agentDirect.force_approval_tools = agentDirect.force_approval_tools.filter((name) => writes.has(name));
|
|
1135
|
+
ElMessage.info('已同步移除不再允许写入的强制审批项');
|
|
1136
|
+
}
|
|
1137
|
+
} else {
|
|
1138
|
+
const writes = new Set(agentDirect.write_tools);
|
|
1139
|
+
const outside = agentDirect.force_approval_tools.filter((name) => !writes.has(name));
|
|
1140
|
+
if (outside.length) {
|
|
1141
|
+
agentDirect.force_approval_tools = agentDirect.force_approval_tools.filter((name) => writes.has(name));
|
|
1142
|
+
ElMessage.warning('额外强制审批只能选已允许的写 operationId');
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
function agentToolRiskType(risk: string): 'success' | 'warning' | 'danger' | 'info' {
|
|
1147
|
+
if (risk === 'high') return 'danger';
|
|
1148
|
+
if (risk === 'medium') return 'warning';
|
|
1149
|
+
if (risk === 'low') return 'success';
|
|
1150
|
+
return 'info';
|
|
1151
|
+
}
|
|
1152
|
+
function validateAgentDirectNames(field: AgentDirectListField, label: string): string[] {
|
|
1153
|
+
const names = agentDirect[field].map((value) => String(value).trim()).filter(Boolean);
|
|
1154
|
+
if (names.some((name) => !OPERATION_ID_RE.test(name))) throw new Error(`${label}只允许精确 operationId,不允许 * 或其他通配符`);
|
|
1155
|
+
return [...new Set(names)];
|
|
1156
|
+
}
|
|
1157
|
+
|
|
977
1158
|
// 调度目标插座:下拉来自注册表(无权限时退化为唯一内置目标)
|
|
978
1159
|
const targetOptions = ref<Array<{ name: string; kind: string; needs_project: boolean; enabled: boolean; description?: string }>>([
|
|
979
1160
|
{ name: 'llm', kind: 'inhub', needs_project: false, enabled: true },
|
|
@@ -1024,6 +1205,7 @@ function featureTags(row: any): RouteFeatureTag[] {
|
|
|
1024
1205
|
if (row.audience?.auto || row.audience?.keywords?.length) tags.push({ label: '自动分诊', type: 'warning' });
|
|
1025
1206
|
else if (row.audience) tags.push({ label: '受众闸', type: 'warning' });
|
|
1026
1207
|
if (row.memory?.summary_enabled) tags.push({ label: '摘要记忆', type: 'info' });
|
|
1208
|
+
if (row.agent_client?.enabled === true || (!row.agent_client && row.tools?.agent_direct?.enabled === true)) tags.push({ label: '本地 Agent', type: 'primary' });
|
|
1027
1209
|
return tags.length ? tags : [{ label: '基础路由', type: 'info' }];
|
|
1028
1210
|
}
|
|
1029
1211
|
// 可执行性:只看「有没有在线执行器认领这个 target」(权限是提示词、不再依赖执行器能力上报)。inhub 目标在中枢内跑、恒可执行。
|
|
@@ -1045,11 +1227,13 @@ function resetSubForms(): void {
|
|
|
1045
1227
|
Object.assign(dv, { type: '', url: '', channel: '', to_field: '', to: '' });
|
|
1046
1228
|
Object.assign(rt, { max: 0, backoff_ms: 5000 });
|
|
1047
1229
|
Object.assign(tl, { sources: [], max_calls: 5, send_channels: [] });
|
|
1230
|
+
Object.assign(agentDirect, { configured: false, enabled: false, write_tools: [], force_approval_tools: [] });
|
|
1048
1231
|
Object.assign(ap, { type: '', url: '' }); builtinRest = {}; sendRest = {}; apRest = {};
|
|
1049
1232
|
Object.assign(au, { enabled: false, auto: false, anonymous: false, priority: 0, keywords: [], clients: [], channels: [], tenants: [], roles: [], principals: [], audiences: [] });
|
|
1050
1233
|
Object.assign(mem, { recent_messages: 12, recent_budget_chars: 3500, summary_enabled: false, summary_trigger_chars: 4000, summary_keep_recent: 6, summary_model: '' });
|
|
1234
|
+
Object.assign(agentClient, { configured: false, inherited: false, enabled: false, instructions: '', active_tool_limit: 8 });
|
|
1051
1235
|
Object.assign(budget, { enabled: false, window: 'day', hard_cost_usd: undefined, hard_tokens: undefined });
|
|
1052
|
-
llmRest = {}; inputRest = {}; knRest = {}; dvRest = {}; rtRest = {}; tlRest = {}; audienceRest = {}; memRest = {}; budgetRest = {};
|
|
1236
|
+
llmRest = {}; inputRest = {}; knRest = {}; dvRest = {}; rtRest = {}; tlRest = {}; agentDirectRest = {}; audienceRest = {}; memRest = {}; agentClientRest = {}; budgetRest = {};
|
|
1053
1237
|
}
|
|
1054
1238
|
function openCreate(): void {
|
|
1055
1239
|
editing.value = false;
|
|
@@ -1124,23 +1308,22 @@ function openEdit(row: any): void {
|
|
|
1124
1308
|
Object.assign(dv, { type: String(d['type'] ?? ''), url: String(d['url'] ?? ''), channel: String(d['channel'] ?? ''), to_field: String(d['to_field'] ?? ''), to: String(d['to'] ?? '') }); dvRest = dr;
|
|
1125
1309
|
const [t, tr] = splitKnown(row.retry, ['max', 'backoff_ms']);
|
|
1126
1310
|
Object.assign(rt, { max: Number(t['max'] ?? 0), backoff_ms: Number(t['backoff_ms'] ?? 5000) }); rtRest = tr;
|
|
1127
|
-
const [w, wr] = splitKnown(row.tools, ['sources', 'max_calls', 'builtin', 'approval']);
|
|
1311
|
+
const [w, wr] = splitKnown(row.tools, ['sources', 'max_calls', 'builtin', 'approval', 'agent_direct']);
|
|
1128
1312
|
tlRest = wr;
|
|
1129
1313
|
tl.max_calls = Number(w['max_calls'] ?? 5);
|
|
1130
1314
|
const [aud, audRest] = splitKnown(row.audience, ['enabled', 'auto', 'anonymous', 'priority', 'keywords', 'clients', 'channels', 'tenants', 'roles', 'principals', 'audiences']);
|
|
1131
|
-
const arr = (v: unknown): string[] => Array.isArray(v) ? v.map((x) => String(x)).filter(Boolean) : (typeof v === 'string' && v ? v.split(',').map((x) => x.trim()).filter(Boolean) : []);
|
|
1132
1315
|
Object.assign(au, {
|
|
1133
1316
|
enabled: row.audience ? aud['enabled'] !== false : false,
|
|
1134
1317
|
auto: aud['auto'] === true,
|
|
1135
1318
|
anonymous: aud['anonymous'] === true,
|
|
1136
1319
|
priority: Number(aud['priority'] ?? 0),
|
|
1137
|
-
keywords:
|
|
1138
|
-
clients:
|
|
1139
|
-
channels:
|
|
1140
|
-
tenants:
|
|
1141
|
-
roles:
|
|
1142
|
-
principals:
|
|
1143
|
-
audiences:
|
|
1320
|
+
keywords: stringArray(aud['keywords']),
|
|
1321
|
+
clients: stringArray(aud['clients']),
|
|
1322
|
+
channels: stringArray(aud['channels']),
|
|
1323
|
+
tenants: stringArray(aud['tenants']),
|
|
1324
|
+
roles: stringArray(aud['roles']),
|
|
1325
|
+
principals: stringArray(aud['principals']),
|
|
1326
|
+
audiences: stringArray(aud['audiences']),
|
|
1144
1327
|
});
|
|
1145
1328
|
audienceRest = audRest;
|
|
1146
1329
|
if (Array.isArray(w['sources'])) {
|
|
@@ -1155,6 +1338,26 @@ function openEdit(row: any): void {
|
|
|
1155
1338
|
})];
|
|
1156
1339
|
});
|
|
1157
1340
|
}
|
|
1341
|
+
const directRaw = w['agent_direct'];
|
|
1342
|
+
if (directRaw && typeof directRaw === 'object' && !Array.isArray(directRaw)) {
|
|
1343
|
+
const [direct, directRest] = splitKnown(directRaw, ['enabled', 'write_tools', 'force_approval_tools', 'unattended_write_tools']);
|
|
1344
|
+
const writeTools = stringArray(direct['write_tools']);
|
|
1345
|
+
const forceApprovalTools = Object.prototype.hasOwnProperty.call(direct, 'force_approval_tools')
|
|
1346
|
+
? stringArray(direct['force_approval_tools'])
|
|
1347
|
+
: Object.prototype.hasOwnProperty.call(direct, 'unattended_write_tools')
|
|
1348
|
+
? writeTools.filter((name) => !new Set(stringArray(direct['unattended_write_tools'])).has(name))
|
|
1349
|
+
: [];
|
|
1350
|
+
Object.assign(agentDirect, {
|
|
1351
|
+
configured: true,
|
|
1352
|
+
enabled: direct['enabled'] === true,
|
|
1353
|
+
write_tools: writeTools,
|
|
1354
|
+
force_approval_tools: forceApprovalTools,
|
|
1355
|
+
});
|
|
1356
|
+
agentDirectRest = directRest;
|
|
1357
|
+
} else if (directRaw !== undefined) {
|
|
1358
|
+
// 旧数据若不是对象,不能结构化编辑,但仍按原值 round-trip,不静默丢失。
|
|
1359
|
+
tlRest = { ...tlRest, agent_direct: directRaw };
|
|
1360
|
+
}
|
|
1158
1361
|
if (w['builtin'] && typeof w['builtin'] === 'object') {
|
|
1159
1362
|
const [bi, br] = splitKnown(w['builtin'], ['send_message']);
|
|
1160
1363
|
builtinRest = br;
|
|
@@ -1176,6 +1379,16 @@ function openEdit(row: any): void {
|
|
|
1176
1379
|
summary_enabled: me['summary_enabled'] === true, summary_trigger_chars: Number(me['summary_trigger_chars'] ?? 4000),
|
|
1177
1380
|
summary_keep_recent: Number(me['summary_keep_recent'] ?? 6), summary_model: String(me['summary_model'] ?? ''),
|
|
1178
1381
|
}); memRest = mr;
|
|
1382
|
+
const [ac, acr] = splitKnown(row.agent_client, ['enabled', 'instructions', 'active_tool_limit']);
|
|
1383
|
+
const directAgentClientDefault = row.tools?.agent_direct?.enabled === true;
|
|
1384
|
+
const inheritedAgentClient = !row.agent_client && directAgentClientDefault;
|
|
1385
|
+
Object.assign(agentClient, {
|
|
1386
|
+
configured: !!row.agent_client,
|
|
1387
|
+
inherited: inheritedAgentClient,
|
|
1388
|
+
enabled: ac['enabled'] === false ? false : ac['enabled'] === true || directAgentClientDefault,
|
|
1389
|
+
instructions: String(ac['instructions'] ?? ''),
|
|
1390
|
+
active_tool_limit: Number(ac['active_tool_limit'] ?? 8),
|
|
1391
|
+
}); agentClientRest = acr;
|
|
1179
1392
|
const [bu, bur] = splitKnown(row.budget, ['enabled', 'window', 'window_hours', 'hard_cost_usd', 'hard_tokens', 'soft_cost_usd', 'soft_tokens']);
|
|
1180
1393
|
const windowFromHours = Number(bu['window_hours']) === 1 ? 'hour' : Number(bu['window_hours']) === 720 ? 'month' : 'day';
|
|
1181
1394
|
const win = ['hour', 'day', 'month'].includes(String(bu['window'])) ? String(bu['window']) as 'hour' | 'day' | 'month' : windowFromHours;
|
|
@@ -1216,6 +1429,19 @@ async function save(): Promise<void> {
|
|
|
1216
1429
|
? drop({ ...(tl.send_channels.length || Object.keys(sendRest).length ? { send_message: { channels: tl.send_channels, ...sendRest } } : {}), ...builtinRest })
|
|
1217
1430
|
: undefined;
|
|
1218
1431
|
const approvalCfg = ap.type ? drop({ type: ap.type, ...(ap.type === 'business_webhook' ? { url: TR(ap.url) } : {}), ...apRest }) : undefined;
|
|
1432
|
+
const directWriteTools = validateAgentDirectNames('write_tools', '本地 Agent 允许的写操作');
|
|
1433
|
+
const directForceApprovalTools = validateAgentDirectNames('force_approval_tools', '本地 Agent 额外强制审批');
|
|
1434
|
+
const directWrites = new Set(directWriteTools);
|
|
1435
|
+
const directForceOutsideWrites = directForceApprovalTools.filter((name) => !directWrites.has(name));
|
|
1436
|
+
if (directForceOutsideWrites.length) throw new Error(`额外强制审批必须是已允许写操作的子集:${directForceOutsideWrites.join(', ')}`);
|
|
1437
|
+
const agentDirectCfg = (agentDirect.configured || agentDirect.enabled || directWriteTools.length || directForceApprovalTools.length || Object.keys(agentDirectRest).length)
|
|
1438
|
+
? {
|
|
1439
|
+
enabled: agentDirect.enabled,
|
|
1440
|
+
...(directWriteTools.length ? { write_tools: directWriteTools } : {}),
|
|
1441
|
+
...(directForceApprovalTools.length ? { force_approval_tools: directForceApprovalTools } : {}),
|
|
1442
|
+
...agentDirectRest,
|
|
1443
|
+
}
|
|
1444
|
+
: undefined;
|
|
1219
1445
|
const hasAudienceFilters = au.keywords.length || au.clients.length || au.channels.length || au.tenants.length || au.roles.length || au.principals.length || au.audiences.length;
|
|
1220
1446
|
const audienceCfg = (au.enabled || au.auto || au.anonymous || au.priority !== 0 || hasAudienceFilters || Object.keys(audienceRest).length)
|
|
1221
1447
|
? drop({
|
|
@@ -1278,11 +1504,12 @@ async function save(): Promise<void> {
|
|
|
1278
1504
|
: undefined,
|
|
1279
1505
|
retry: rt.max > 0 ? { max: rt.max, backoff_ms: rt.backoff_ms, ...rtRest } : undefined,
|
|
1280
1506
|
// tools:业务工具源(sources)、全局调用预算、中枢内置动作与审批承接分离。
|
|
1281
|
-
tools: (sourceCfgs.length || builtinCfg || approvalCfg || Object.keys(tlRest).length)
|
|
1507
|
+
tools: (sourceCfgs.length || builtinCfg || approvalCfg || agentDirectCfg || Object.keys(tlRest).length)
|
|
1282
1508
|
? {
|
|
1283
1509
|
...(sourceCfgs.length ? { sources: sourceCfgs, max_calls: tl.max_calls } : {}),
|
|
1284
1510
|
...(builtinCfg ? { builtin: builtinCfg } : {}),
|
|
1285
1511
|
...(approvalCfg ? { approval: approvalCfg } : {}),
|
|
1512
|
+
...(agentDirectCfg ? { agent_direct: agentDirectCfg } : {}),
|
|
1286
1513
|
...tlRest,
|
|
1287
1514
|
}
|
|
1288
1515
|
: undefined,
|
|
@@ -1295,6 +1522,14 @@ async function save(): Promise<void> {
|
|
|
1295
1522
|
...memRest,
|
|
1296
1523
|
}
|
|
1297
1524
|
: undefined,
|
|
1525
|
+
agent_client: (agentClient.configured || agentClient.inherited || agentClient.enabled || agentClient.instructions.trim() || agentClient.active_tool_limit !== 8 || Object.keys(agentClientRest).length)
|
|
1526
|
+
? {
|
|
1527
|
+
enabled: agentClient.enabled,
|
|
1528
|
+
...(agentClient.instructions.trim() ? { instructions: agentClient.instructions.trim() } : {}),
|
|
1529
|
+
...(agentClient.active_tool_limit !== 8 ? { active_tool_limit: agentClient.active_tool_limit } : {}),
|
|
1530
|
+
...agentClientRest,
|
|
1531
|
+
}
|
|
1532
|
+
: undefined,
|
|
1298
1533
|
budget: (budget.enabled && (Number(budget.hard_cost_usd) > 0 || Number(budget.hard_tokens) > 0 || Object.keys(budgetRest).length))
|
|
1299
1534
|
? {
|
|
1300
1535
|
enabled: true,
|
|
@@ -1651,6 +1886,37 @@ onMounted(async () => {
|
|
|
1651
1886
|
border-top: 1px solid var(--el-border-color-lighter);
|
|
1652
1887
|
}
|
|
1653
1888
|
.tool-source-editor__head { margin-bottom: 10px; font-size: 12px; }
|
|
1889
|
+
.agent-direct-title { margin-top: 6px; }
|
|
1890
|
+
.agent-direct-alert { margin: -4px 0 14px; }
|
|
1891
|
+
.agent-direct-catalog-summary {
|
|
1892
|
+
margin: -4px 0 14px;
|
|
1893
|
+
color: var(--el-text-color-secondary);
|
|
1894
|
+
font-size: 12px;
|
|
1895
|
+
line-height: 1.6;
|
|
1896
|
+
}
|
|
1897
|
+
.agent-tool-option {
|
|
1898
|
+
display: flex;
|
|
1899
|
+
align-items: center;
|
|
1900
|
+
gap: 7px;
|
|
1901
|
+
min-width: 0;
|
|
1902
|
+
}
|
|
1903
|
+
.agent-tool-option code {
|
|
1904
|
+
flex: 0 1 auto;
|
|
1905
|
+
overflow: hidden;
|
|
1906
|
+
color: var(--el-text-color-primary);
|
|
1907
|
+
font-family: var(--bz-mono);
|
|
1908
|
+
font-size: 12px;
|
|
1909
|
+
text-overflow: ellipsis;
|
|
1910
|
+
}
|
|
1911
|
+
.agent-tool-option__meta {
|
|
1912
|
+
flex: 1 1 auto;
|
|
1913
|
+
min-width: 0;
|
|
1914
|
+
overflow: hidden;
|
|
1915
|
+
color: var(--el-text-color-secondary);
|
|
1916
|
+
font-size: 11px;
|
|
1917
|
+
text-overflow: ellipsis;
|
|
1918
|
+
white-space: nowrap;
|
|
1919
|
+
}
|
|
1654
1920
|
.field-hint { margin-top: 4px; font-size: 12px; line-height: 1.6; color: var(--el-text-color-secondary); }
|
|
1655
1921
|
.field-hint code { font-family: var(--bz-mono); font-size: 11px; background: var(--el-fill-color-light); padding: 1px 4px; }
|
|
1656
1922
|
@media (max-width: 900px) {
|