bailinghub 0.5.0 → 0.6.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/README.en.md +146 -185
- package/README.md +135 -206
- package/THIRD_PARTY_NOTICES.md +6 -7
- package/assets/readme-demo-evidence.en-dark.svg +82 -0
- package/assets/readme-demo-evidence.en.svg +82 -0
- package/assets/readme-demo-evidence.zh-CN-dark.svg +82 -0
- package/assets/readme-demo-evidence.zh-CN.svg +82 -0
- package/assets/readme-entry-points.en-dark.svg +71 -0
- package/assets/readme-entry-points.en.svg +71 -0
- package/assets/readme-entry-points.zh-CN-dark.svg +71 -0
- package/assets/readme-entry-points.zh-CN.svg +71 -0
- package/assets/readme-product-overview.en-dark.svg +87 -0
- package/assets/readme-product-overview.en.svg +87 -0
- package/assets/readme-product-overview.zh-CN-dark.svg +87 -0
- package/assets/readme-product-overview.zh-CN.svg +87 -0
- package/docker-compose.images.yml +2 -2
- package/docs/AGENT_AUTH_API.en.md +25 -9
- package/docs/AGENT_AUTH_API.md +17 -5
- package/docs/AGENT_CLIENT_QUICKSTART.en.md +90 -18
- package/docs/AGENT_CLIENT_QUICKSTART.md +74 -16
- package/docs/AGENT_CONVERSATION_AUDIT.en.md +194 -0
- package/docs/AGENT_CONVERSATION_AUDIT.md +111 -0
- package/docs/CHANGELOG.en.md +23 -0
- package/docs/CHANGELOG.md +23 -0
- package/docs/INDEPENDENT_VALIDATION.en.md +4 -4
- package/docs/INDEPENDENT_VALIDATION.md +4 -4
- package/docs/README.en.md +7 -0
- package/docs/README.md +7 -0
- package/docs/RELEASE_NOTES_v0.5.1.en.md +45 -0
- package/docs/RELEASE_NOTES_v0.5.1.md +45 -0
- package/docs/RELEASE_NOTES_v0.6.0.en.md +51 -0
- package/docs/RELEASE_NOTES_v0.6.0.md +51 -0
- package/docs/user-guide/README.en.md +1 -0
- package/docs/user-guide/README.md +1 -0
- package/docs/user-guide/console-map.en.md +2 -0
- package/docs/user-guide/console-map.md +2 -1
- package/docs/user-guide/conversations.en.md +40 -0
- package/docs/user-guide/conversations.md +40 -0
- package/package.json +1 -1
- package/scripts/check-doc-links.mjs +3 -0
- package/scripts/check-image-tags.sh +1 -1
- package/scripts/check-release-consistency.test.mjs +5 -5
- package/scripts/e2e-console.mjs +89 -0
- package/scripts/generate-readme-assets.mjs +488 -7
- package/scripts/install.sh +1 -1
- package/scripts/publish-images.sh +1 -1
- package/scripts/release-audit.mjs +2 -0
- package/scripts/verify-github-repo.mjs +2 -0
- package/sql/057_agent_conversation_audit.sql +55 -0
- package/src/app/agent-conversation-audit.ts +30 -0
- package/src/app/oss-edition.ts +1 -0
- package/src/core/config/agent-direct-console-selection.test.ts +22 -0
- package/src/core/runtime/agent-conversation-audit.test.ts +38 -0
- package/src/core/runtime/agent-conversation-audit.ts +159 -0
- package/src/infrastructure/config/config-agent-auth-repository.test.ts +36 -0
- package/src/infrastructure/config/config-agent-auth-repository.ts +97 -0
- package/src/infrastructure/config/config-agent-client-runtime-repository.test.ts +38 -0
- package/src/infrastructure/config/config-agent-client-runtime-repository.ts +54 -0
- package/src/infrastructure/config/config-agent-conversation-audit-repository.test.ts +146 -0
- package/src/infrastructure/config/config-agent-conversation-audit-repository.ts +262 -0
- package/src/infrastructure/config/configstore.ts +5 -0
- package/src/routes/admin-agent-clients.test.ts +120 -0
- package/src/routes/admin-agent-clients.ts +161 -0
- package/src/routes/admin-conversation-audit.ts +46 -0
- package/src/routes/admin-runtime.test.ts +38 -0
- package/src/routes/admin-runtime.ts +14 -3
- package/src/routes/admin.ts +6 -0
- package/src/routes/agent-api.ts +2 -0
- package/src/routes/agent-conversation-audit.test.ts +131 -0
- package/src/routes/agent-conversation-audit.ts +33 -0
- package/src/test-support/agent-conversation-audit-fixture.ts +123 -0
- package/web/console/assets/{Accounts-D4RRm5D1.js → Accounts-Ca_VnSu9.js} +1 -1
- package/web/console/assets/AgentClients-BPIvlLYY.js +1 -0
- package/web/console/assets/AgentClients-DsWADpzr.css +1 -0
- package/web/console/assets/{Approvals-CsTTKb8o.js → Approvals-CMvPWacY.js} +1 -1
- package/web/console/assets/{Audit-BzvZ7JZw.js → Audit-CIRqOCnL.js} +1 -1
- package/web/console/assets/{BrandLockup-CYcA93wh.js → BrandLockup-BrytmTTH.js} +1 -1
- package/web/console/assets/{Channels-DRQZggqM.js → Channels-CApxH2TB.js} +1 -1
- package/web/console/assets/{ChatEntries-BUB7BWKU.js → ChatEntries-CJon3bWJ.js} +1 -1
- package/web/console/assets/Clients-BSA1rlTB.js +3 -0
- package/web/console/assets/Clients-CNIVs7Qn.css +1 -0
- package/web/console/assets/{Cost-BZgFf1yM.js → Cost-BbhlQFP8.js} +1 -1
- package/web/console/assets/{Credentials-BTe2Q07j.js → Credentials-kqr1W0K7.js} +1 -1
- package/web/console/assets/{Diagnostics-WL-buYli.js → Diagnostics-Kljt9XTH.js} +1 -1
- package/web/console/assets/{Executors-CGZ-7Xmp.js → Executors-DnsB-Xz4.js} +1 -1
- package/web/console/assets/{HelpTip-CT07o3kB.js → HelpTip-i-KJhf5s.js} +1 -1
- package/web/console/assets/{Kb-VVw8oGsT.js → Kb-DLZSAFWP.js} +2 -2
- package/web/console/assets/{Login-rwvmBBPl.js → Login-DiTjPWmN.js} +1 -1
- package/web/console/assets/{Projects-CexaCEY1.js → Projects-CXcVCgCD.js} +1 -1
- package/web/console/assets/Routes-CXGl9SMM.css +1 -0
- package/web/console/assets/Routes-DN9_d9Po.js +124 -0
- package/web/console/assets/Runs-Cwbe6thL.js +3 -0
- package/web/console/assets/Runs-D8UmjP5G.css +1 -0
- package/web/console/assets/{Setup-Djh5yadQ.js → Setup-FqoCKmfZ.js} +1 -1
- package/web/console/assets/Shell-BEqpONiy.js +1 -0
- package/web/console/assets/Shell-D9Uw-fsa.css +1 -0
- package/web/console/assets/{StorageBuckets-CQBR41W1.js → StorageBuckets-CkORbYXY.js} +1 -1
- package/web/console/assets/{SystemSettings-DgnopekD.js → SystemSettings-gTQAazu7.js} +1 -1
- package/web/console/assets/{SystemStatus-Bj8-kPt2.js → SystemStatus-DAmUUNqO.js} +1 -1
- package/web/console/assets/{Targets-BAfCt_nH.js → Targets-CZmDcjsE.js} +1 -1
- package/web/console/assets/{Tools-xjd0NZdE.js → Tools-CIHInlHL.js} +1 -1
- package/web/console/assets/index-BkLbd7Cc.js +2 -0
- package/web/console/assets/{index-DZEQL_yy.js → index-QnmD7N7F.js} +1 -1
- package/web/console/assets/{request-DkNPOweH.js → request-r7GHVJzw.js} +1 -1
- package/web/console/assets/{schema-CgPWAu1_.js → schema-BVn_hB7M.js} +1 -1
- package/web/console/assets/{util-SiQC2MJh.js → util-4bN2dv7B.js} +1 -1
- package/web/console/assets/{vendor-element-D7WRzHhy.js → vendor-element-CZoEjZr8.js} +1 -1
- package/web/console/assets/vendor-mammoth-BUEEDX6A.js +231 -0
- package/web/console/index.html +2 -2
- package/web-admin/package-lock.json +3 -3
- package/web-admin/src/agent-direct-selection.ts +21 -0
- package/web-admin/src/components/ClientConversations.vue +244 -0
- package/web-admin/src/components/conversation-audit.ts +121 -0
- package/web-admin/src/layout/Shell.vue +1 -1
- package/web-admin/src/pages/AgentClients.vue +254 -0
- package/web-admin/src/pages/Clients.vue +4 -2
- package/web-admin/src/pages/Routes.vue +54 -5
- package/web-admin/src/pages/Runs.vue +73 -17
- package/web-admin/src/router.ts +2 -0
- package/web-admin/tests/conversation-audit.fixture.mjs +182 -0
- package/web-admin/tests/conversation-audit.test.mjs +93 -0
- package/web/console/assets/Clients-CQ_MonGL.css +0 -1
- package/web/console/assets/Clients-HhCyrxfz.js +0 -3
- package/web/console/assets/Routes-B9ZHbQAp.js +0 -124
- package/web/console/assets/Routes-BbkFpi6Y.css +0 -1
- package/web/console/assets/Runs-4zDD9VOC.css +0 -1
- package/web/console/assets/Runs-BzFNPTwD.js +0 -3
- package/web/console/assets/Shell-BVIjmoY8.css +0 -1
- package/web/console/assets/Shell-kn763smL.js +0 -1
- package/web/console/assets/index-DfJA7iJS.js +0 -2
- package/web/console/assets/vendor-mammoth-DvgsHdlx.js +0 -231
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="agent-clients-page">
|
|
3
|
+
<el-card shadow="never">
|
|
4
|
+
<template #header>
|
|
5
|
+
<div class="head">
|
|
6
|
+
<div>
|
|
7
|
+
<b>智能体客户端</b>
|
|
8
|
+
<HelpTip title="和执行器有什么区别">
|
|
9
|
+
<p><b>智能体客户端</b>在本地理解用户意图、选择能力并完成多步编排;中枢继续负责业务身份、授权、审批、执行与审计。</p>
|
|
10
|
+
<p><b>执行器</b>是中枢下发 Job、由本地运行时执行本地任务后回报结果。两者是独立概念。</p>
|
|
11
|
+
<p>本页聚合现有接入方、Agent Session 和 Agent Run,不创建第二套接入方配置。</p>
|
|
12
|
+
<p>每个接入方只配置一个不绑定账号、租户或门店的业务授权入口;账号切换与租户选择由业务授权页完成。</p>
|
|
13
|
+
</HelpTip>
|
|
14
|
+
</div>
|
|
15
|
+
<div class="actions">
|
|
16
|
+
<el-select v-model="days" size="small" style="width: 108px" @change="loadOverview">
|
|
17
|
+
<el-option :value="7" label="近 7 天" />
|
|
18
|
+
<el-option :value="30" label="近 30 天" />
|
|
19
|
+
<el-option :value="90" label="近 90 天" />
|
|
20
|
+
</el-select>
|
|
21
|
+
<el-button size="small" :loading="loading" @click="refreshAll">刷新</el-button>
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
24
|
+
</template>
|
|
25
|
+
|
|
26
|
+
<div v-loading="loading" class="overview">
|
|
27
|
+
<div class="metric primary"><span>客户端应用</span><b>{{ int(summary.agent_auth_enabled) }}</b><em>共 {{ int(summary.applications) }} 个接入方</em></div>
|
|
28
|
+
<div class="metric"><span>有效授权设备</span><b>{{ int(summary.sessions?.active) }}</b><em>总会话 {{ int(summary.sessions?.total) }}</em></div>
|
|
29
|
+
<div class="metric"><span>Agent Run</span><b>{{ int(summary.runs) }}</b><em>{{ int(summary.conversations) }} 个本地会话</em></div>
|
|
30
|
+
<div class="metric"><span>工具调用</span><b>{{ int(summary.tool_calls) }}</b><em>审批 {{ int(approvalTotal) }} 次</em></div>
|
|
31
|
+
<div class="metric"><span>累计 Token</span><b>{{ int(summary.total_tokens) }}</b><em>由客户端公开 usage 汇总</em></div>
|
|
32
|
+
<div class="metric" :class="{ danger: Number(summary.failure_rate || 0) > 0.1 }"><span>失败率</span><b>{{ percent(summary.failure_rate) }}</b><em>{{ int(summary.failed) }} 个失败或取消</em></div>
|
|
33
|
+
</div>
|
|
34
|
+
</el-card>
|
|
35
|
+
|
|
36
|
+
<el-card shadow="never">
|
|
37
|
+
<template #header>
|
|
38
|
+
<div class="section-head">
|
|
39
|
+
<div><b>客户端应用</b><span>复用“接入方”配置;只有设置 Agent 授权页后才能发起浏览器登录。</span></div>
|
|
40
|
+
<el-button size="small" @click="router.push('/clients')">管理接入方</el-button>
|
|
41
|
+
</div>
|
|
42
|
+
</template>
|
|
43
|
+
<el-empty v-if="!applications.length" description="还没有接入方" />
|
|
44
|
+
<el-table v-else :data="applications" size="small">
|
|
45
|
+
<el-table-column label="应用" :width="180">
|
|
46
|
+
<template #default="{ row }"><div class="stack"><b>{{ row.name || row.app_id }}</b><code>{{ row.app_id }}</code></div></template>
|
|
47
|
+
</el-table-column>
|
|
48
|
+
<el-table-column label="Agent 登录" :min-width="240" show-overflow-tooltip>
|
|
49
|
+
<template #default="{ row }">
|
|
50
|
+
<div class="stack">
|
|
51
|
+
<div><el-tag size="small" effect="plain" :type="row.enabled && row.agent_auth_enabled ? 'success' : 'info'">{{ row.enabled && row.agent_auth_enabled ? '可授权' : '未开放' }}</el-tag></div>
|
|
52
|
+
<span class="muted mono">{{ row.agent_authorize_url || '未配置授权页' }}</span>
|
|
53
|
+
</div>
|
|
54
|
+
</template>
|
|
55
|
+
</el-table-column>
|
|
56
|
+
<el-table-column label="允许 Workspace" :width="180">
|
|
57
|
+
<template #default="{ row }"><div class="tags"><el-tag v-for="route in previewRoutes(row.allowed_routes)" :key="route" size="small" effect="plain" type="info">{{ route }}</el-tag></div></template>
|
|
58
|
+
</el-table-column>
|
|
59
|
+
<el-table-column label="近期开销" :width="150" align="right">
|
|
60
|
+
<template #default="{ row }"><div class="stack right"><span>{{ int(row.stats.runs) }} Run / {{ int(row.stats.tool_calls) }} 调用</span><span class="muted">{{ int(row.stats.total_tokens) }} Token</span></div></template>
|
|
61
|
+
</el-table-column>
|
|
62
|
+
<el-table-column :width="160" align="right">
|
|
63
|
+
<template #default="{ row }">
|
|
64
|
+
<el-button link type="primary" :disabled="!row.agent_auth_enabled || !eligibleWorkspaces(row).length" @click="openConnection(row)">生成连接配置</el-button>
|
|
65
|
+
<el-button link @click="router.push('/clients')">编辑</el-button>
|
|
66
|
+
</template>
|
|
67
|
+
</el-table-column>
|
|
68
|
+
</el-table>
|
|
69
|
+
</el-card>
|
|
70
|
+
|
|
71
|
+
<el-card shadow="never">
|
|
72
|
+
<template #header>
|
|
73
|
+
<div class="section-head">
|
|
74
|
+
<div><b>授权设备与 Agent Session</b><span>远程撤销后,后续 access/refresh token 都会失效;本地客户端需要重新登录。</span></div>
|
|
75
|
+
<div class="actions">
|
|
76
|
+
<el-select v-model="sessionFilter.client_app_id" clearable filterable size="small" placeholder="全部应用" style="width: 190px" @change="resetSessions">
|
|
77
|
+
<el-option v-for="app in applications" :key="app.app_id" :label="app.name || app.app_id" :value="app.app_id" />
|
|
78
|
+
</el-select>
|
|
79
|
+
<el-select v-model="sessionFilter.state" size="small" style="width: 112px" @change="resetSessions">
|
|
80
|
+
<el-option value="all" label="全部状态" />
|
|
81
|
+
<el-option value="active" label="有效" />
|
|
82
|
+
<el-option value="expired" label="已过期" />
|
|
83
|
+
<el-option value="revoked" label="已撤销" />
|
|
84
|
+
</el-select>
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
</template>
|
|
88
|
+
<el-empty v-if="!sessions.length" description="当前筛选下没有 Agent Session" />
|
|
89
|
+
<el-table v-else v-loading="sessionsLoading" :data="sessions" size="small">
|
|
90
|
+
<el-table-column label="设备" :width="170">
|
|
91
|
+
<template #default="{ row }"><div class="stack"><b>{{ row.device_label || '未命名设备' }}</b><code>{{ shortId(row.session_id) }}</code></div></template>
|
|
92
|
+
</el-table-column>
|
|
93
|
+
<el-table-column label="业务主体" :width="150">
|
|
94
|
+
<template #default="{ row }"><div class="stack"><span>{{ row.principal?.id || row.on_behalf_of }}</span><span class="muted">{{ row.principal?.tenant || '未声明租户' }}</span></div></template>
|
|
95
|
+
</el-table-column>
|
|
96
|
+
<el-table-column label="应用 / Workspace" :min-width="190">
|
|
97
|
+
<template #default="{ row }"><div class="stack"><code>{{ row.client_app_id }}</code><span class="muted">{{ (row.allowed_routes || []).join('、') || '无可用路由' }}</span></div></template>
|
|
98
|
+
</el-table-column>
|
|
99
|
+
<el-table-column label="活跃与有效期" :width="185">
|
|
100
|
+
<template #default="{ row }"><div class="stack"><span>活跃 {{ fmtTime(row.last_seen_at) }}</span><span class="muted">到期 {{ fmtTime(row.refresh_expires_at) }}</span></div></template>
|
|
101
|
+
</el-table-column>
|
|
102
|
+
<el-table-column label="状态" :width="80"><template #default="{ row }"><el-tag size="small" effect="plain" :type="stateType(row.state)">{{ stateText(row.state) }}</el-tag></template></el-table-column>
|
|
103
|
+
<el-table-column :width="90" align="right">
|
|
104
|
+
<template #default="{ row }"><el-button v-if="row.state !== 'revoked'" link type="danger" :loading="revoking === row.session_id" @click="revoke(row)">远程撤销</el-button><span v-else class="muted">已处理</span></template>
|
|
105
|
+
</el-table-column>
|
|
106
|
+
</el-table>
|
|
107
|
+
<div v-if="sessionTotal > sessionPageSize" class="pagination">
|
|
108
|
+
<el-pagination v-model:current-page="sessionPage" :page-size="sessionPageSize" :total="sessionTotal" layout="prev, pager, next, total" @current-change="loadSessions" />
|
|
109
|
+
</div>
|
|
110
|
+
</el-card>
|
|
111
|
+
|
|
112
|
+
<el-dialog v-model="connection.open" title="生成智能体客户端连接配置" width="620px">
|
|
113
|
+
<el-alert type="info" :closable="false" show-icon title="这里只生成公开连接元数据,不包含业务 URL、业务身份、Client Token、Agent Token 或模型密钥。" />
|
|
114
|
+
<p class="connection-note"><code>connectionName</code> 只是本机连接选择器。登录时会统一打开接入方配置的业务授权页,由该页面确认当前账号与租户。</p>
|
|
115
|
+
<el-form label-position="top" class="connection-form">
|
|
116
|
+
<el-form-item label="Hub 地址"><el-input :model-value="hubUrl" readonly class="mono" /></el-form-item>
|
|
117
|
+
<div class="form-grid">
|
|
118
|
+
<el-form-item label="Client App ID"><el-input :model-value="connection.app_id" readonly class="mono" /></el-form-item>
|
|
119
|
+
<el-form-item label="Connection Name"><el-input v-model="connection.name" maxlength="128" class="mono" /></el-form-item>
|
|
120
|
+
</div>
|
|
121
|
+
<el-form-item label="Workspace">
|
|
122
|
+
<el-select v-model="connection.workspace" style="width: 100%"><el-option v-for="workspace in connection.workspaces" :key="workspace.route" :label="workspace.name + '(' + workspace.route + ')'" :value="workspace.route" /></el-select>
|
|
123
|
+
</el-form-item>
|
|
124
|
+
</el-form>
|
|
125
|
+
<div class="code-block"><pre>{{ connectionJson }}</pre></div>
|
|
126
|
+
<div class="code-block"><pre>{{ connectionCommand }}</pre></div>
|
|
127
|
+
<template #footer><el-button @click="connection.open = false">关闭</el-button><el-button @click="copy(connectionJson)">复制 JSON</el-button><el-button type="primary" @click="copy(connectionCommand)">复制 DSH 命令</el-button></template>
|
|
128
|
+
</el-dialog>
|
|
129
|
+
</div>
|
|
130
|
+
</template>
|
|
131
|
+
|
|
132
|
+
<script setup lang="ts">
|
|
133
|
+
import { computed, onMounted, reactive, ref } from 'vue';
|
|
134
|
+
import { useRouter } from 'vue-router';
|
|
135
|
+
import { ElMessage, ElMessageBox } from 'element-plus';
|
|
136
|
+
import HelpTip from '../components/HelpTip.vue';
|
|
137
|
+
import { kernelFetch, kernelOrigin } from '../runtime-path';
|
|
138
|
+
|
|
139
|
+
interface Workspace { route: string; name: string; description?: string }
|
|
140
|
+
interface Stats { runs: number; conversations: number; completed: number; failed: number; tool_calls: number; total_tokens: number; approvals: Record<string, number> }
|
|
141
|
+
interface Application { app_id: string; name: string; enabled: boolean; agent_auth_enabled: boolean; agent_authorize_url?: string | null; allowed_routes: string[]; last_used_at?: string | null; stats: Stats }
|
|
142
|
+
interface SessionRow { session_id: string; client_app_id: string; device_label: string; principal?: { id?: string; tenant?: string; roles?: string[] }; on_behalf_of: string; allowed_routes: string[]; last_seen_at?: string; refresh_expires_at: string; state: 'active' | 'expired' | 'revoked' }
|
|
143
|
+
|
|
144
|
+
const router = useRouter();
|
|
145
|
+
const days = ref(30);
|
|
146
|
+
const loading = ref(false);
|
|
147
|
+
const sessionsLoading = ref(false);
|
|
148
|
+
const revoking = ref('');
|
|
149
|
+
const applications = ref<Application[]>([]);
|
|
150
|
+
const workspaces = ref<Workspace[]>([]);
|
|
151
|
+
const sessions = ref<SessionRow[]>([]);
|
|
152
|
+
const sessionTotal = ref(0);
|
|
153
|
+
const sessionPage = ref(1);
|
|
154
|
+
const sessionPageSize = 50;
|
|
155
|
+
const summary = reactive<any>({ applications: 0, agent_auth_enabled: 0, sessions: {}, runs: 0, conversations: 0, failed: 0, tool_calls: 0, total_tokens: 0, failure_rate: 0, approvals: {} });
|
|
156
|
+
const sessionFilter = reactive({ client_app_id: '', state: 'all' });
|
|
157
|
+
const connection = reactive<{ open: boolean; app_id: string; name: string; workspace: string; workspaces: Workspace[] }>({ open: false, app_id: '', name: '', workspace: '', workspaces: [] });
|
|
158
|
+
const hubUrl = computed(() => kernelOrigin());
|
|
159
|
+
const approvalTotal = computed(() => Object.values(summary.approvals || {}).reduce((sum: number, value) => sum + Number(value || 0), 0));
|
|
160
|
+
const connectionJson = computed(() => JSON.stringify({ hubUrl: hubUrl.value, clientAppId: connection.app_id, workspace: connection.workspace, connectionName: connection.name.trim() || 'default' }, null, 2));
|
|
161
|
+
const connectionCommand = computed(() => `/bailinghub connections add ${quote(connection.name.trim() || 'default')} ${quote(hubUrl.value)} ${quote(connection.app_id)} ${quote(connection.workspace)}`);
|
|
162
|
+
|
|
163
|
+
function quote(value: string): string { return JSON.stringify(value); }
|
|
164
|
+
function int(value: unknown): string { return new Intl.NumberFormat('zh-CN').format(Number(value || 0)); }
|
|
165
|
+
function percent(value: unknown): string { return `${(Number(value || 0) * 100).toFixed(1)}%`; }
|
|
166
|
+
function shortId(value: string): string { return value ? `${value.slice(0, 8)}…${value.slice(-4)}` : '—'; }
|
|
167
|
+
function fmtTime(value?: string | null): string { return value ? new Date(value).toLocaleString('zh-CN', { hour12: false }) : '从未'; }
|
|
168
|
+
function stateText(value: SessionRow['state']): string { return value === 'active' ? '有效' : value === 'expired' ? '已过期' : '已撤销'; }
|
|
169
|
+
function stateType(value: SessionRow['state']): 'success' | 'warning' | 'info' { return value === 'active' ? 'success' : value === 'expired' ? 'warning' : 'info'; }
|
|
170
|
+
function previewRoutes(routes: string[]): string[] { return routes.includes('*') ? ['全部 Workspace'] : routes.slice(0, 4); }
|
|
171
|
+
function eligibleWorkspaces(app: Application): Workspace[] { return workspaces.value.filter((workspace) => app.allowed_routes.includes('*') || app.allowed_routes.includes(workspace.route)); }
|
|
172
|
+
|
|
173
|
+
async function loadOverview(): Promise<void> {
|
|
174
|
+
loading.value = true;
|
|
175
|
+
try {
|
|
176
|
+
const response = await kernelFetch(`/admin/api/agent-clients/overview?days=${days.value}`);
|
|
177
|
+
if (!response.ok) throw new Error((await response.json().catch(() => ({}))).error || '加载失败');
|
|
178
|
+
const data = await response.json();
|
|
179
|
+
applications.value = data.applications || [];
|
|
180
|
+
workspaces.value = data.workspaces || [];
|
|
181
|
+
Object.assign(summary, data.summary || {});
|
|
182
|
+
} catch (error) { ElMessage.error(error instanceof Error ? error.message : '加载智能体客户端失败'); }
|
|
183
|
+
finally { loading.value = false; }
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function loadSessions(): Promise<void> {
|
|
187
|
+
sessionsLoading.value = true;
|
|
188
|
+
try {
|
|
189
|
+
const params = new URLSearchParams({
|
|
190
|
+
state: sessionFilter.state,
|
|
191
|
+
limit: String(sessionPageSize),
|
|
192
|
+
offset: String((sessionPage.value - 1) * sessionPageSize),
|
|
193
|
+
});
|
|
194
|
+
if (sessionFilter.client_app_id) params.set('client_app_id', sessionFilter.client_app_id);
|
|
195
|
+
const response = await kernelFetch(`/admin/api/agent-clients/sessions?${params}`);
|
|
196
|
+
if (!response.ok) throw new Error((await response.json().catch(() => ({}))).error || '加载失败');
|
|
197
|
+
const data = await response.json();
|
|
198
|
+
sessions.value = data.list || [];
|
|
199
|
+
sessionTotal.value = Number(data.total || 0);
|
|
200
|
+
} catch (error) { ElMessage.error(error instanceof Error ? error.message : '加载授权设备失败'); }
|
|
201
|
+
finally { sessionsLoading.value = false; }
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async function refreshAll(): Promise<void> { await Promise.all([loadOverview(), loadSessions()]); }
|
|
205
|
+
async function resetSessions(): Promise<void> { sessionPage.value = 1; await loadSessions(); }
|
|
206
|
+
function openConnection(app: Application): void {
|
|
207
|
+
const options = eligibleWorkspaces(app);
|
|
208
|
+
connection.app_id = app.app_id;
|
|
209
|
+
connection.name = app.app_id.replace(/[^a-zA-Z0-9._-]+/g, '-').replace(/^-+|-+$/g, '') || 'default';
|
|
210
|
+
connection.workspaces = options;
|
|
211
|
+
connection.workspace = options[0]?.route || '';
|
|
212
|
+
connection.open = true;
|
|
213
|
+
}
|
|
214
|
+
async function copy(value: string): Promise<void> { await navigator.clipboard.writeText(value); ElMessage.success('已复制'); }
|
|
215
|
+
async function revoke(row: SessionRow): Promise<void> {
|
|
216
|
+
await ElMessageBox.confirm(`撤销设备“${row.device_label || shortId(row.session_id)}”的 Agent Session?撤销后需要重新登录授权。`, '远程撤销', { type: 'warning', confirmButtonText: '确认撤销' });
|
|
217
|
+
revoking.value = row.session_id;
|
|
218
|
+
try {
|
|
219
|
+
const response = await kernelFetch(`/admin/api/agent-clients/sessions/${row.session_id}/revoke`, { method: 'POST' });
|
|
220
|
+
if (!response.ok) throw new Error((await response.json().catch(() => ({}))).error || '撤销失败');
|
|
221
|
+
ElMessage.success('Agent Session 已撤销');
|
|
222
|
+
await refreshAll();
|
|
223
|
+
} catch (error) { ElMessage.error(error instanceof Error ? error.message : '撤销失败'); }
|
|
224
|
+
finally { revoking.value = ''; }
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
onMounted(refreshAll);
|
|
228
|
+
</script>
|
|
229
|
+
|
|
230
|
+
<style scoped>
|
|
231
|
+
.agent-clients-page { display: grid; gap: 16px; }
|
|
232
|
+
.head, .section-head, .actions { display: flex; align-items: center; gap: 10px; }
|
|
233
|
+
.head, .section-head { justify-content: space-between; }
|
|
234
|
+
.section-head > div:first-child { display: flex; align-items: baseline; gap: 10px; }
|
|
235
|
+
.section-head span, .muted { color: var(--el-text-color-secondary); font-size: 12px; }
|
|
236
|
+
.overview { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
|
|
237
|
+
.metric { min-width: 0; padding: 16px; border: 1px solid var(--el-border-color-lighter); border-radius: 10px; background: var(--el-fill-color-blank); }
|
|
238
|
+
.metric span, .metric em { display: block; color: var(--el-text-color-secondary); font-style: normal; font-size: 12px; }
|
|
239
|
+
.metric b { display: block; margin: 8px 0 5px; font-size: 24px; line-height: 1; }
|
|
240
|
+
.metric.primary { border-color: color-mix(in srgb, var(--el-color-primary) 34%, transparent); background: color-mix(in srgb, var(--el-color-primary) 7%, transparent); }
|
|
241
|
+
.metric.danger b { color: var(--el-color-danger); }
|
|
242
|
+
.stack { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
|
|
243
|
+
.stack.right { align-items: flex-end; }
|
|
244
|
+
.mono, code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
|
|
245
|
+
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
246
|
+
.connection-form { margin-top: 18px; }
|
|
247
|
+
.connection-note { margin: 12px 0 0; color: var(--el-text-color-secondary); font-size: 12px; line-height: 1.6; }
|
|
248
|
+
.pagination { display: flex; justify-content: flex-end; padding-top: 14px; }
|
|
249
|
+
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
|
|
250
|
+
.code-block { margin-top: 10px; padding: 12px; overflow: auto; border-radius: 8px; background: #111827; color: #e5e7eb; }
|
|
251
|
+
.code-block pre { margin: 0; white-space: pre-wrap; word-break: break-all; font-size: 12px; }
|
|
252
|
+
@media (max-width: 1280px) { .overview { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
|
|
253
|
+
@media (max-width: 760px) { .overview, .form-grid { grid-template-columns: 1fr; } .head, .section-head { align-items: flex-start; flex-direction: column; } }
|
|
254
|
+
</style>
|
|
@@ -99,11 +99,13 @@
|
|
|
99
99
|
<el-input v-model="form.name" placeholder="如 业务系统" />
|
|
100
100
|
</el-form-item>
|
|
101
101
|
<el-form-item>
|
|
102
|
-
<template #label>{{ fieldTitle('agent_authorize_url', 'Agent
|
|
102
|
+
<template #label>{{ fieldTitle('agent_authorize_url', 'Agent 授权入口') }} <HelpTip :title="fieldTitle('agent_authorize_url', 'Agent 授权入口')">
|
|
103
103
|
<p>{{ fieldDesc('agent_authorize_url', '本地 Agent 发起登录时打开的业务系统网页。') }}</p>
|
|
104
|
+
<p>同一接入方只配置一个<b>稳定、统一的业务授权入口</b>,不要绑定具体账号、租户或门店。该页面负责业务登录、切换账号和选择租户;业务后端再从当前服务端登录态派生可信 <code>principal</code> / <code>on_behalf_of</code>。</p>
|
|
105
|
+
<p>本地插件不会填写或选择业务 URL,也不能用 <code>connectionName</code> 指定业务身份。</p>
|
|
104
106
|
<p>留空表示不开放 Agent 登录。生产必须使用 HTTPS;本机联调可使用带端口的 <code>127.0.0.1</code> / <code>::1</code> HTTP URL。</p>
|
|
105
107
|
</HelpTip></template>
|
|
106
|
-
<el-input v-model="form.agent_authorize_url" placeholder="https://business.example.com/agent
|
|
108
|
+
<el-input v-model="form.agent_authorize_url" placeholder="https://business.example.com/agent/authorize" class="mono" />
|
|
107
109
|
</el-form-item>
|
|
108
110
|
<el-form-item>
|
|
109
111
|
<template #label>{{ fieldTitle('allowed_routes', '可调路由') }} <span v-if="fieldRequired('allowed_routes')" class="field-required">*</span> <HelpTip :title="fieldTitle('allowed_routes', '可调路由')">
|
|
@@ -620,6 +620,12 @@
|
|
|
620
620
|
<p>只有精确列入的写工具才会暴露给本地 Agent。候选项来自已选工具源的 <code>/tools</code> 编译结果,并且必须已被上方 scope 放行。</p>
|
|
621
621
|
<p>可手动填写尚未拉取到的 operationId,但不允许 <code>*</code> 或其他通配符。</p>
|
|
622
622
|
</HelpTip></template>
|
|
623
|
+
<div class="agent-direct-write-actions">
|
|
624
|
+
<span>当前目录已选 {{ agentDirectSelectedCatalogWriteCount }} / {{ agentDirectWriteOptions.length }}</span>
|
|
625
|
+
<el-button size="small" type="primary" plain :disabled="!agentDirectWriteOptions.length || agentDirectAllCurrentWritesSelected"
|
|
626
|
+
@click="selectAllCurrentAgentDirectWrites">全选当前写操作({{ agentDirectWriteOptions.length }})</el-button>
|
|
627
|
+
<el-button size="small" :disabled="!agentDirect.write_tools.length" @click="clearAgentDirectWrites">清空</el-button>
|
|
628
|
+
</div>
|
|
623
629
|
<el-select v-model="agentDirect.write_tools" multiple filterable allow-create default-first-option
|
|
624
630
|
style="width: 100%" placeholder="选择写操作,或手填精确 operationId" @change="onAgentDirectNamesChange('write_tools')">
|
|
625
631
|
<el-option v-for="tool in agentDirectWriteOptions" :key="tool.name" :value="tool.name" :label="tool.name">
|
|
@@ -632,7 +638,7 @@
|
|
|
632
638
|
</div>
|
|
633
639
|
</el-option>
|
|
634
640
|
</el-select>
|
|
635
|
-
<div class="field-hint"
|
|
641
|
+
<div class="field-hint">“全选当前”保存的是此刻工具目录的精确 operationId 快照,不会自动授权未来新增写操作;只读工具仍按工具源 scope 与业务主体权限自动暴露。</div>
|
|
636
642
|
</el-form-item>
|
|
637
643
|
<el-form-item>
|
|
638
644
|
<template #label>额外强制审批 <HelpTip title="额外强制审批">
|
|
@@ -853,6 +859,7 @@
|
|
|
853
859
|
<script setup lang="ts">
|
|
854
860
|
import { computed, onMounted, reactive, ref } from 'vue';
|
|
855
861
|
import { ElMessage } from 'element-plus/es/components/message/index';
|
|
862
|
+
import { ElMessageBox } from 'element-plus/es/components/message-box/index';
|
|
856
863
|
import { WarningFilled } from '@element-plus/icons-vue';
|
|
857
864
|
import { api } from '../request';
|
|
858
865
|
import { openDoc } from '../docs';
|
|
@@ -862,6 +869,7 @@ import { useMe } from '../store';
|
|
|
862
869
|
import { LLM_PROVIDERS, detectProvider } from '../llm-catalog';
|
|
863
870
|
import { schemaDescription, schemaRequired, schemaTitle, useConfigSchema } from '../schema';
|
|
864
871
|
import { kernelOrigin } from '../runtime-path';
|
|
872
|
+
import { EXACT_OPERATION_ID_RE, includesAllCurrentOperationIds, mergeExactOperationIds } from '../agent-direct-selection';
|
|
865
873
|
|
|
866
874
|
const s = useMe();
|
|
867
875
|
const routeSchema = useConfigSchema('route');
|
|
@@ -1102,6 +1110,14 @@ const agentDirectToolOptions = computed<AgentDirectToolOption[]>(() => {
|
|
|
1102
1110
|
});
|
|
1103
1111
|
const agentDirectWriteOptions = computed(() => agentDirectToolOptions.value.filter((tool) => !tool.readonly && tool.allowed));
|
|
1104
1112
|
const agentDirectReadonlyCount = computed(() => agentDirectToolOptions.value.filter((tool) => tool.readonly && tool.allowed).length);
|
|
1113
|
+
const agentDirectCurrentWriteNames = computed(() => agentDirectWriteOptions.value.map((tool) => tool.name));
|
|
1114
|
+
const agentDirectSelectedCatalogWriteCount = computed(() => {
|
|
1115
|
+
const selected = new Set(agentDirect.write_tools);
|
|
1116
|
+
return agentDirectCurrentWriteNames.value.filter((name) => selected.has(name)).length;
|
|
1117
|
+
});
|
|
1118
|
+
const agentDirectAllCurrentWritesSelected = computed(() => (
|
|
1119
|
+
includesAllCurrentOperationIds(agentDirect.write_tools, agentDirectCurrentWriteNames.value)
|
|
1120
|
+
));
|
|
1105
1121
|
const agentDirectApprovalOptions = computed<AgentDirectToolOption[]>(() => {
|
|
1106
1122
|
const catalog = new Map(agentDirectToolOptions.value.map((tool) => [tool.name, tool]));
|
|
1107
1123
|
return agentDirect.write_tools.map((name) => catalog.get(name) ?? {
|
|
@@ -1115,14 +1131,13 @@ const agentDirectApprovalOptions = computed<AgentDirectToolOption[]>(() => {
|
|
|
1115
1131
|
});
|
|
1116
1132
|
});
|
|
1117
1133
|
|
|
1118
|
-
const OPERATION_ID_RE = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/;
|
|
1119
1134
|
type AgentDirectListField = 'write_tools' | 'force_approval_tools';
|
|
1120
1135
|
function onAgentDirectNamesChange(field: AgentDirectListField): void {
|
|
1121
1136
|
agentDirect.configured = true;
|
|
1122
1137
|
const values = agentDirect[field].map((value) => String(value).trim()).filter(Boolean);
|
|
1123
|
-
const invalid = values.filter((value) => !
|
|
1138
|
+
const invalid = values.filter((value) => !EXACT_OPERATION_ID_RE.test(value));
|
|
1124
1139
|
if (invalid.length) {
|
|
1125
|
-
agentDirect[field] = [...new Set(values.filter((value) =>
|
|
1140
|
+
agentDirect[field] = [...new Set(values.filter((value) => EXACT_OPERATION_ID_RE.test(value)))];
|
|
1126
1141
|
ElMessage.warning(invalid.includes('*') ? '本地 Agent 工具不允许 *,请选择或填写精确 operationId' : 'operationId 只允许字母、数字和下划线,且以字母或下划线开头');
|
|
1127
1142
|
} else {
|
|
1128
1143
|
agentDirect[field] = [...new Set(values)];
|
|
@@ -1143,6 +1158,29 @@ function onAgentDirectNamesChange(field: AgentDirectListField): void {
|
|
|
1143
1158
|
}
|
|
1144
1159
|
}
|
|
1145
1160
|
}
|
|
1161
|
+
async function selectAllCurrentAgentDirectWrites(): Promise<void> {
|
|
1162
|
+
const current = agentDirectCurrentWriteNames.value;
|
|
1163
|
+
if (!current.length || agentDirectAllCurrentWritesSelected.value) return;
|
|
1164
|
+
try {
|
|
1165
|
+
await ElMessageBox.confirm(
|
|
1166
|
+
`将把当前工具目录中的 ${current.length} 个写 operationId 精确加入本地 Agent 白名单。未来新增写操作不会自动获得授权,ACC 风险、主体与审批治理仍然生效。`,
|
|
1167
|
+
'全选当前写操作',
|
|
1168
|
+
{ type: 'warning', confirmButtonText: '确认全选', cancelButtonText: '取消' },
|
|
1169
|
+
);
|
|
1170
|
+
} catch {
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
agentDirect.configured = true;
|
|
1174
|
+
agentDirect.write_tools = mergeExactOperationIds(agentDirect.write_tools, current);
|
|
1175
|
+
ElMessage.success(`已选择当前 ${current.length} 个写操作,保存路由后生效`);
|
|
1176
|
+
}
|
|
1177
|
+
function clearAgentDirectWrites(): void {
|
|
1178
|
+
if (!agentDirect.write_tools.length) return;
|
|
1179
|
+
agentDirect.configured = true;
|
|
1180
|
+
agentDirect.write_tools = [];
|
|
1181
|
+
agentDirect.force_approval_tools = [];
|
|
1182
|
+
ElMessage.info('已清空写操作授权及其额外强制审批项,保存路由后生效');
|
|
1183
|
+
}
|
|
1146
1184
|
function agentToolRiskType(risk: string): 'success' | 'warning' | 'danger' | 'info' {
|
|
1147
1185
|
if (risk === 'high') return 'danger';
|
|
1148
1186
|
if (risk === 'medium') return 'warning';
|
|
@@ -1151,7 +1189,7 @@ function agentToolRiskType(risk: string): 'success' | 'warning' | 'danger' | 'in
|
|
|
1151
1189
|
}
|
|
1152
1190
|
function validateAgentDirectNames(field: AgentDirectListField, label: string): string[] {
|
|
1153
1191
|
const names = agentDirect[field].map((value) => String(value).trim()).filter(Boolean);
|
|
1154
|
-
if (names.some((name) => !
|
|
1192
|
+
if (names.some((name) => !EXACT_OPERATION_ID_RE.test(name))) throw new Error(`${label}只允许精确 operationId,不允许 * 或其他通配符`);
|
|
1155
1193
|
return [...new Set(names)];
|
|
1156
1194
|
}
|
|
1157
1195
|
|
|
@@ -1894,6 +1932,17 @@ onMounted(async () => {
|
|
|
1894
1932
|
font-size: 12px;
|
|
1895
1933
|
line-height: 1.6;
|
|
1896
1934
|
}
|
|
1935
|
+
.agent-direct-write-actions {
|
|
1936
|
+
display: flex;
|
|
1937
|
+
align-items: center;
|
|
1938
|
+
justify-content: flex-end;
|
|
1939
|
+
gap: 8px;
|
|
1940
|
+
width: 100%;
|
|
1941
|
+
margin-bottom: 8px;
|
|
1942
|
+
color: var(--el-text-color-secondary);
|
|
1943
|
+
font-size: 12px;
|
|
1944
|
+
}
|
|
1945
|
+
.agent-direct-write-actions span { margin-right: auto; }
|
|
1897
1946
|
.agent-tool-option {
|
|
1898
1947
|
display: flex;
|
|
1899
1948
|
align-items: center;
|