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
package/.gitignore
CHANGED
package/README.en.md
CHANGED
|
@@ -217,6 +217,9 @@ export default buildOpenApiSpec({
|
|
|
217
217
|
- [Docker Demo](docs/DEMO.en.md)
|
|
218
218
|
- [Independent Validation Task](docs/INDEPENDENT_VALIDATION.en.md)
|
|
219
219
|
- [HTTP Contract](docs/CONTRACT.en.md)
|
|
220
|
+
- [Agent Client v1 Integration Guide](docs/AGENT_CLIENT_QUICKSTART.en.md)
|
|
221
|
+
- [Agent Auth v1](docs/AGENT_AUTH_API.en.md)
|
|
222
|
+
- [Agent Client Runtime v1](docs/AGENT_CLIENT_RUNTIME_API.en.md)
|
|
220
223
|
- [Kernel Host API v1](docs/KERNEL_HOST_API.en.md)
|
|
221
224
|
- [Business Tools and Governance](docs/TOOLS.en.md)
|
|
222
225
|
- [SDK Guide](docs/SDK.en.md)
|
|
@@ -229,7 +232,7 @@ export default buildOpenApiSpec({
|
|
|
229
232
|
- [Tool Governance](docs/TOOLS_DESIGN.en.md)
|
|
230
233
|
- [AI-Friendly Tool Design](docs/AI_FRIENDLY_TOOLS.en.md)
|
|
231
234
|
- [Third-Party Integration](docs/INTEGRATION.en.md)
|
|
232
|
-
- [Latest Release Notes](docs/RELEASE_NOTES_v0.
|
|
235
|
+
- [Latest Release Notes](docs/RELEASE_NOTES_v0.5.0.en.md)
|
|
233
236
|
- [v0.1.7 Release Notes](docs/RELEASE_NOTES_v0.1.7.en.md)
|
|
234
237
|
- [v0.1.6 Release Notes](docs/RELEASE_NOTES_v0.1.6.en.md)
|
|
235
238
|
- [v0.1.5 Release Notes](docs/RELEASE_NOTES_v0.1.5.en.md)
|
|
@@ -251,6 +254,8 @@ Useful reports include the business context, expected behavior, a minimal reprod
|
|
|
251
254
|
|
|
252
255
|
We welcome independent distributions, industry adaptations, executors, connectors, and independent ACC implementations. Community projects may keep their own names, directions, and governance. Reusable improvements are welcome upstream, and strong independent projects may request a future listing on the official ecosystem surface. A listing is not certification, a service warranty, or a transfer of maintenance responsibility. See [Community Derivatives And Ecosystem Collaboration](docs/ECOSYSTEM.en.md).
|
|
253
256
|
|
|
257
|
+
DeepSeek Harness users can install the independent community plugin [dsh-bailinghub](https://github.com/bailinghub/bailinghub-dsh-plugin) so the local Agent performs reasoning, planning, and multi-step tool selection while BailingHub continues to own trusted business identity, capability filtering, approvals, execution, and audit. The plugin consumes the host-neutral `bailinghub-mcp-server/sdk`, does not enter the BailingHub Core distribution, and does not imply DeepSeek development, certification, or endorsement. See the [Agent Client v1 Integration Guide](docs/AGENT_CLIENT_QUICKSTART.en.md) for deployer, business-developer, and end-user configuration ownership.
|
|
258
|
+
|
|
254
259
|
## Open-Source Foundations and Third-Party Software
|
|
255
260
|
|
|
256
261
|
BailingHub adopts the open [Agent Capability Contract (ACC)](https://www.agentcapability.org), runs its service on Node.js and TypeScript, builds its console with Vue, Element Plus, and Pinia, and uses an independent MySQL service as the default persistent runtime.
|
package/README.md
CHANGED
|
@@ -192,6 +192,9 @@ BAILING_SMOKE_RUN_ROUTE=<route-key> npm run smoke
|
|
|
192
192
|
| `docs/user-guide/` | 使用者指南:面向业务负责人、产品经理、系统管理员和实施顾问,按业务场景说明为什么需要中枢、后台怎么配、配完交给开发者什么 |
|
|
193
193
|
| `docs/CONTRACT.md` | **边界契约**:`/run`、聊天入口、工具调用/签名、回送、降级、鉴权——业务与中枢唯一的「缝」 |
|
|
194
194
|
| `docs/CLIENT_API.md` | **生态接入稳定面**:版本化 Client API、机器契约、兼容规则与 Dify/n8n 跨仓门禁 |
|
|
195
|
+
| `docs/AGENT_CLIENT_QUICKSTART.md` | **智能体客户端接入**:Core、业务授权页、通用 SDK 与本地宿主插件如何从零串起来 |
|
|
196
|
+
| `docs/AGENT_AUTH_API.md` | **Agent Auth v1**:业务登录态、PKCE、Client Token 与可撤销 Agent Session 的语言无关契约 |
|
|
197
|
+
| `docs/AGENT_CLIENT_RUNTIME_API.md` | **Agent Client Runtime v1**:本地编排所需的工作区、上下文、能力搜索、工具调用与可见结果回传契约 |
|
|
195
198
|
| `docs/QUICKSTART.md` | 从零部署到第一条路由跑通的操作手册 |
|
|
196
199
|
| `docs/QUICKSTART.en.md` | English quickstart for Docker demo, first route, and first business tool |
|
|
197
200
|
| `docs/DEMO.md` | Docker Demo:20 分钟跑通 Agent 调业务工具闭环 |
|
|
@@ -230,6 +233,7 @@ BAILING_SMOKE_RUN_ROUTE=<route-key> npm run smoke
|
|
|
230
233
|
| `docs/RELEASE_NOTES_v0.3.2.md` | `v0.3.2` 受管演示数据引导说明 |
|
|
231
234
|
| `docs/RELEASE_NOTES_v0.3.3.md` | `v0.3.3` npm 发布来源元数据纠偏说明 |
|
|
232
235
|
| `docs/RELEASE_NOTES_v0.3.4.md` | `v0.3.4` 匿名预览与可信业务身份引导说明 |
|
|
236
|
+
| `docs/RELEASE_NOTES_v0.5.0.md` | `v0.5.0` 可撤销本地 Agent 授权与受治理本地编排说明 |
|
|
233
237
|
| `docs/RELEASE_NOTES_v0.1.0.md` | 首个公开版本的发布说明 |
|
|
234
238
|
| `docs/兼容性与升级.md` | 版本发布策略:SemVer、稳定契约、数据库结构纪律、发布记录要求 |
|
|
235
239
|
| `sql/` | 中枢**独立**状态库 DDL(`bz_` 前缀,按序号演进);数据库结构演进纪律见 [sql/README.md](sql/README.md) |
|
|
@@ -262,6 +266,8 @@ BailingHub 当前公开版本仍处于早期验证阶段。我们希望它经得
|
|
|
262
266
|
|
|
263
267
|
我们欢迎社区创建独立发行版、行业适配、执行器、连接器和 ACC 独立实现。衍生项目可以保持自己的名称、方向与治理;通用改进欢迎回到上游,优秀的独立项目未来也可以申请在官方生态页面展示。展示不代表官方认证、服务担保或维护责任转移。完整原则见 [社区衍生与生态合作](docs/ECOSYSTEM.md)。
|
|
264
268
|
|
|
269
|
+
DeepSeek Harness 用户可以安装独立社区插件 [dsh-bailinghub](https://github.com/bailinghub/bailinghub-dsh-plugin),让本地 Agent 负责理解、规划和多步工具选择,同时继续由 BailingHub 负责可信业务身份、能力裁剪、审批、执行与审计。该插件通过宿主无关的 `bailinghub-mcp-server/sdk` 接入,不进入 BailingHub Core 发行包,也不代表 DeepSeek 官方开发、认证或背书。部署者、业务开发者和最终用户分别需要配置什么,见 [Agent Client v1 接入指南](docs/AGENT_CLIENT_QUICKSTART.md)。
|
|
270
|
+
|
|
265
271
|
## 开源基础与第三方软件
|
|
266
272
|
|
|
267
273
|
百灵中枢采用开放的 [ACC(Agent Capability Contract)](https://www.agentcapability.org) 能力声明契约,服务端基于 Node.js / TypeScript,控制台基于 Vue / Element Plus / Pinia,默认使用独立的 MySQL 服务持久化运行状态。
|
package/SECURITY.md
CHANGED
|
@@ -28,3 +28,14 @@ We aim to acknowledge reports within 3 business days.
|
|
|
28
28
|
- Docker Compose intentionally has no default `BAILING_TOKEN`. Generate one with `openssl rand -hex 32`, persist it in a local `.env` or secret manager, and rotate it if it may have been exposed.
|
|
29
29
|
- Business tools must verify `X-Bailing-Signature` and must perform their own authorization using `X-Bailing-On-Behalf-Of`.
|
|
30
30
|
- High-risk tools should use `risk=high`, `x-agent-capability.approval.required`, or parameter-level confirmation rules.
|
|
31
|
+
|
|
32
|
+
## Private release denylist
|
|
33
|
+
|
|
34
|
+
Public source audits include generic checks for private keys, personal access tokens, and local user paths. Deployment-specific exact text must not be added to repository scripts, tests, comments, or examples.
|
|
35
|
+
|
|
36
|
+
Maintainers can supply deployment-specific markers at audit time through either:
|
|
37
|
+
|
|
38
|
+
- `BAILING_PUBLIC_DENYLIST_JSON`: a JSON array of exact strings, intended for a protected CI secret;
|
|
39
|
+
- `BAILING_PUBLIC_DENYLIST_FILE`: an absolute path to a JSON array stored outside the repository, preferred for local release rehearsals.
|
|
40
|
+
|
|
41
|
+
For example, a protected test environment may set `BAILING_PUBLIC_DENYLIST_JSON='["DEPLOYMENT_ONLY_MARKER_ALPHA_42"]'`. Audit failures report only the marker index and never echo its value. The external file path is rejected when it resolves inside the repository.
|
|
@@ -18,7 +18,7 @@ services:
|
|
|
18
18
|
retries: 30
|
|
19
19
|
|
|
20
20
|
demo-business:
|
|
21
|
-
image: ${BAILING_DEMO_BUSINESS_IMAGE:-crpi-xm97pbcjrmf5in3s.cn-shanghai.personal.cr.aliyuncs.com/bailinghub/bailing-demo-business:0.
|
|
21
|
+
image: ${BAILING_DEMO_BUSINESS_IMAGE:-crpi-xm97pbcjrmf5in3s.cn-shanghai.personal.cr.aliyuncs.com/bailinghub/bailing-demo-business:0.5.0}
|
|
22
22
|
environment:
|
|
23
23
|
DEMO_HOST: 0.0.0.0
|
|
24
24
|
DEMO_PORT: 19080
|
|
@@ -29,7 +29,7 @@ services:
|
|
|
29
29
|
- "${BAILING_DEMO_PUBLIC_PORT:-19080}:19080"
|
|
30
30
|
|
|
31
31
|
bailinghub:
|
|
32
|
-
image: ${BAILINGHUB_IMAGE:-crpi-xm97pbcjrmf5in3s.cn-shanghai.personal.cr.aliyuncs.com/bailinghub/bailinghub:0.
|
|
32
|
+
image: ${BAILINGHUB_IMAGE:-crpi-xm97pbcjrmf5in3s.cn-shanghai.personal.cr.aliyuncs.com/bailinghub/bailinghub:0.5.0}
|
|
33
33
|
depends_on:
|
|
34
34
|
mysql:
|
|
35
35
|
condition: service_healthy
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# Agent Auth v1
|
|
2
|
+
|
|
3
|
+
English | [简体中文](AGENT_AUTH_API.md)
|
|
4
|
+
|
|
5
|
+
Agent Auth v1 binds a local Agent's browser authorization to an existing authenticated business
|
|
6
|
+
session and issues a revocable Agent Session. BailingHub supplies the protocol and server-side SDK
|
|
7
|
+
methods. The business system owns its login page, consent UI, user/tenant/role decisions, and final
|
|
8
|
+
business authorization.
|
|
9
|
+
|
|
10
|
+
See the [Agent Client v1 Integration Guide](AGENT_CLIENT_QUICKSTART.en.md) for the full component
|
|
11
|
+
relationship. This protocol does not carry subscription, billing, model credentials, or business
|
|
12
|
+
API secrets.
|
|
13
|
+
|
|
14
|
+
## 1. Parties and credentials
|
|
15
|
+
|
|
16
|
+
| Party | Identifier or credential | Boundary |
|
|
17
|
+
|---|---|---|
|
|
18
|
+
| local Agent SDK | public `client_app_id`, PKCE, loopback callback | no Client Token or business password |
|
|
19
|
+
| business authorization backend | BailingHub Client Token | server-only context/approve/deny/revoke calls |
|
|
20
|
+
| BailingHub Core | authorization and session ledger | stores only SHA-256 token hashes |
|
|
21
|
+
| business tool endpoint | Tool Provider Secret and business ACL | revalidates every real invocation |
|
|
22
|
+
|
|
23
|
+
`client_app_id` is public. The Client Token is a backend secret and must never enter browser
|
|
24
|
+
JavaScript, local plugin settings, URLs, screenshots, or logs.
|
|
25
|
+
|
|
26
|
+
## 2. Client registration
|
|
27
|
+
|
|
28
|
+
Create a BailingHub client with a stable public `app_id` such as `merchant-agent`, the business
|
|
29
|
+
system's HTTPS `agent_authorize_url`, the minimum `allowed_routes`, `enabled=true`, and a reasonable
|
|
30
|
+
rate limit. Production authorization pages require HTTPS. Explicit-port `127.0.0.1` or `::1` HTTP
|
|
31
|
+
URLs are allowed only for local development.
|
|
32
|
+
|
|
33
|
+
## 3. Flow
|
|
34
|
+
|
|
35
|
+
```text
|
|
36
|
+
Local SDK BailingHub business page/backend
|
|
37
|
+
| POST authorizations | |
|
|
38
|
+
|------------------------->| |
|
|
39
|
+
| authorization_url | |
|
|
40
|
+
|<-------------------------| |
|
|
41
|
+
| open browser ------------------------------------------>|
|
|
42
|
+
| |<-- context (Client Token) ----|
|
|
43
|
+
| |<-- approve/deny ---------------|
|
|
44
|
+
|<---- loopback redirect --|-------------------------------|
|
|
45
|
+
| POST token + PKCE ------>| |
|
|
46
|
+
| Agent Session tokens <---| |
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The SDK creates random state, a PKCE verifier/challenge, and a random loopback callback. Core
|
|
50
|
+
appends only `authorization_id` to the registered business page. The business backend derives the
|
|
51
|
+
trusted principal from its current server session, approves or denies the request, and returns the
|
|
52
|
+
Core-generated redirect. The SDK exchanges the one-time code with PKCE and stores the resulting
|
|
53
|
+
session in a secure local credential store.
|
|
54
|
+
|
|
55
|
+
## 4. Endpoints
|
|
56
|
+
|
|
57
|
+
### 4.1 Create authorization
|
|
58
|
+
|
|
59
|
+
`POST /agent-auth/v1/authorizations`
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"client_app_id": "merchant-agent",
|
|
64
|
+
"redirect_uri": "http://127.0.0.1:49152/callback",
|
|
65
|
+
"state": "random-csrf-state",
|
|
66
|
+
"requested_routes": ["order-assistant"],
|
|
67
|
+
"device_label": "My workstation",
|
|
68
|
+
"code_challenge": "<PKCE-S256-base64url>",
|
|
69
|
+
"code_challenge_method": "S256"
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The response contains `authorization_id`, the configured business `authorization_url`, and
|
|
74
|
+
`expires_in: 600`. The callback must be an explicit-port loopback HTTP URL. Public callbacks,
|
|
75
|
+
URL credentials, `auto`, and `*` routes are rejected. v1 host adapters should request one workspace
|
|
76
|
+
per connection.
|
|
77
|
+
|
|
78
|
+
### 4.2 Read context from the business backend
|
|
79
|
+
|
|
80
|
+
`GET /agent-auth/v1/authorizations/{authorization_id}` with:
|
|
81
|
+
|
|
82
|
+
```http
|
|
83
|
+
Authorization: Bearer <BUSINESS_CLIENT_TOKEN>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The response exposes only client name, device name, requested routes, status, and expiry metadata.
|
|
87
|
+
|
|
88
|
+
### 4.3 Approve or deny from the business backend
|
|
89
|
+
|
|
90
|
+
`POST /agent-auth/v1/authorizations/{authorization_id}/approve`
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"principal": {
|
|
95
|
+
"id": "user-42",
|
|
96
|
+
"tenant": "tenant-7",
|
|
97
|
+
"roles": ["manager"],
|
|
98
|
+
"audience": "internal"
|
|
99
|
+
},
|
|
100
|
+
"on_behalf_of": "tenant-7:user-42",
|
|
101
|
+
"allowed_routes": ["order-assistant"]
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Use the Client Token Bearer header. Derive `principal`, `on_behalf_of`, and `allowed_routes` from
|
|
106
|
+
the authenticated backend session and current permission data, never from browser claims, query
|
|
107
|
+
parameters, or model output. The approved set must be within both the pending request and the
|
|
108
|
+
client allowlist.
|
|
109
|
+
|
|
110
|
+
Deny with `POST /agent-auth/v1/authorizations/{authorization_id}/deny` and `{}`. Both endpoints
|
|
111
|
+
return a Core-generated `redirect_uri`; navigate only to that value.
|
|
112
|
+
|
|
113
|
+
### 4.4 Exchange and refresh
|
|
114
|
+
|
|
115
|
+
`POST /agent-auth/v1/token`
|
|
116
|
+
|
|
117
|
+
Authorization-code exchange:
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"grant_type": "authorization_code",
|
|
122
|
+
"client_app_id": "merchant-agent",
|
|
123
|
+
"code": "<one-time-code>",
|
|
124
|
+
"redirect_uri": "http://127.0.0.1:49152/callback",
|
|
125
|
+
"code_verifier": "<PKCE-verifier>"
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Refresh rotation:
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"grant_type": "refresh_token",
|
|
134
|
+
"client_app_id": "merchant-agent",
|
|
135
|
+
"refresh_token": "<refresh-token>"
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Access tokens default to 15 minutes and refresh sessions to 30 days. Every refresh rotates the
|
|
140
|
+
refresh token; reuse of an old token fails closed. Store both tokens in the operating system's
|
|
141
|
+
secure credential store, never in connection metadata or plugin settings.
|
|
142
|
+
|
|
143
|
+
### 4.5 Inspect and revoke
|
|
144
|
+
|
|
145
|
+
- `GET /agent-auth/v1/session`: Agent access Bearer; returns non-secret session metadata.
|
|
146
|
+
- `POST /agent-auth/v1/revoke`: revoke with Agent access Bearer, or with a
|
|
147
|
+
`client_app_id + refresh_token` body.
|
|
148
|
+
- `POST /agent-auth/v1/sessions/{session_id}/revoke`: business backend Client Token; revokes a
|
|
149
|
+
session owned by that client.
|
|
150
|
+
|
|
151
|
+
Revoke sessions when an employee leaves, a tenant is disabled, a device is lost, or business
|
|
152
|
+
authority changes. Business tool endpoints still revalidate current permission on every call.
|
|
153
|
+
|
|
154
|
+
## 5. Business-page rules
|
|
155
|
+
|
|
156
|
+
- The page belongs to the business system; the SDK does not inject a universal UI.
|
|
157
|
+
- Require the normal business login before consent.
|
|
158
|
+
- Show the current account, tenant, device, and requested workspace clearly.
|
|
159
|
+
- Keep the Client Token in the backend; the page holds only `authorization_id`.
|
|
160
|
+
- Use `Cache-Control: no-store` and never export tokens to analytics or error reporting.
|
|
161
|
+
- Treat repeated, expired, and completed requests as terminal.
|
|
162
|
+
- Apply the business system's normal CSRF, CSP, clickjacking, and open-redirect defenses.
|
|
163
|
+
|
|
164
|
+
## 6. Errors and recovery
|
|
165
|
+
|
|
166
|
+
- `invalid_client`: disabled client, missing authorization page, or disallowed route.
|
|
167
|
+
- `invalid_request`: invalid fields, PKCE, callback, route, or principal.
|
|
168
|
+
- `route_not_allowed`: approval exceeds the request or client allowlist.
|
|
169
|
+
- `invalid_grant`: invalid, expired, replayed, or mismatched code/PKCE/refresh token.
|
|
170
|
+
- `access_denied`: the user rejected the request.
|
|
171
|
+
- `401 unauthorized`: invalid business Client Token or Agent access token.
|
|
172
|
+
- `409/410`: already processed or expired authorization.
|
|
173
|
+
|
|
174
|
+
On refresh failure, never fall back to an admin token, Client Token, or anonymous access. Isolate
|
|
175
|
+
the invalid session and require a new browser authorization.
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# Agent Auth v1
|
|
2
|
+
|
|
3
|
+
[English](AGENT_AUTH_API.en.md) | 简体中文
|
|
4
|
+
|
|
5
|
+
Agent Auth v1 把本地智能体的一次浏览器授权绑定到业务系统现有登录态,并签发可撤销的
|
|
6
|
+
Agent Session。BailingHub 提供协议与服务端 SDK 方法;业务系统负责自己的登录页、授权页样式、
|
|
7
|
+
用户/租户/角色判断和最终业务权限校验。
|
|
8
|
+
|
|
9
|
+
完整组件关系见 [Agent Client v1 接入指南](AGENT_CLIENT_QUICKSTART.md)。本协议不承载套餐、付费、
|
|
10
|
+
模型凭据或业务 API Secret。
|
|
11
|
+
|
|
12
|
+
## 1. 参与方与凭据
|
|
13
|
+
|
|
14
|
+
| 参与方 | 使用的标识/凭据 | 边界 |
|
|
15
|
+
|---|---|---|
|
|
16
|
+
| 本地 Agent SDK | 公开 `client_app_id`、PKCE、loopback callback | 不持有 Client Token 或业务密码 |
|
|
17
|
+
| 业务授权后端 | 接入方 Client Token | 只在服务端调用 context/approve/deny/revoke |
|
|
18
|
+
| BailingHub Core | Agent authorization/session 账本 | 只存 access/refresh token 的 SHA-256 摘要 |
|
|
19
|
+
| 业务工具端点 | Tool Provider Secret 与业务权限表 | 每次真实调用仍重新验签并校验权限 |
|
|
20
|
+
|
|
21
|
+
`client_app_id` 是公开客户端标识。Client Token 是业务后端秘密,不能进入浏览器 JavaScript、
|
|
22
|
+
本地插件配置、URL、截图或日志。
|
|
23
|
+
|
|
24
|
+
## 2. 前置配置
|
|
25
|
+
|
|
26
|
+
中枢管理员在“接入方”创建应用并配置:
|
|
27
|
+
|
|
28
|
+
- `app_id`:稳定的公开客户端标识,例如 `merchant-agent`;
|
|
29
|
+
- `agent_authorize_url`:业务系统自己的 HTTPS 授权页,例如
|
|
30
|
+
`https://business.example.com/agent/authorize`;
|
|
31
|
+
- `allowed_routes`:该应用最多可申请的 route;
|
|
32
|
+
- `enabled=true` 与合理限速。
|
|
33
|
+
|
|
34
|
+
生产授权页只允许 HTTPS。本机开发可以使用带显式端口的 `127.0.0.1` 或 `::1` HTTP URL。
|
|
35
|
+
|
|
36
|
+
## 3. 授权流程
|
|
37
|
+
|
|
38
|
+
```text
|
|
39
|
+
本地 SDK BailingHub 业务授权页/后端
|
|
40
|
+
| POST authorizations | |
|
|
41
|
+
|------------------------->| |
|
|
42
|
+
| authorization_url | |
|
|
43
|
+
|<-------------------------| |
|
|
44
|
+
| 浏览器打开 -------------------------------------------->|
|
|
45
|
+
| |<-- context (Client Token) ----|
|
|
46
|
+
| |<-- approve/deny ---------------|
|
|
47
|
+
|<---- loopback redirect --|-------------------------------|
|
|
48
|
+
| POST token + PKCE ------>| |
|
|
49
|
+
| Agent Session tokens <---| |
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
1. SDK 生成随机 `state`、PKCE verifier/challenge 和随机 loopback callback;
|
|
53
|
+
2. Core 创建 10 分钟有效的授权请求,返回业务授权页 URL;
|
|
54
|
+
3. Core 只向配置好的授权页追加 `authorization_id`;
|
|
55
|
+
4. 业务页要求用户先完成业务系统登录;
|
|
56
|
+
5. 业务后端用 Client Token 查询上下文,并从当前服务端登录态推导可信身份;
|
|
57
|
+
6. 批准后 Core 返回锁定 callback 的 `redirect_uri`,浏览器跳转回本机;
|
|
58
|
+
7. SDK 用一次性 code 和 PKCE verifier 换取 Agent Session;
|
|
59
|
+
8. 后续 Runtime 请求使用短期 access token,SDK 用轮换 refresh token 续期。
|
|
60
|
+
|
|
61
|
+
## 4. HTTP 端点
|
|
62
|
+
|
|
63
|
+
### 4.1 本地 SDK:创建授权请求
|
|
64
|
+
|
|
65
|
+
`POST /agent-auth/v1/authorizations`
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"client_app_id": "merchant-agent",
|
|
70
|
+
"redirect_uri": "http://127.0.0.1:49152/callback",
|
|
71
|
+
"state": "random-csrf-state",
|
|
72
|
+
"requested_routes": ["order-assistant"],
|
|
73
|
+
"device_label": "My workstation",
|
|
74
|
+
"code_challenge": "<PKCE-S256-base64url>",
|
|
75
|
+
"code_challenge_method": "S256"
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"authorization_id": "<uuid>",
|
|
82
|
+
"authorization_url": "https://business.example.com/agent/authorize?authorization_id=<uuid>",
|
|
83
|
+
"expires_in": 600
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
callback 必须是带显式端口的 loopback HTTP URL;不接受公网 callback、任意域名或 URL 用户名/密码。
|
|
88
|
+
v1 每次请求至少一个且最多 64 个明确 route,不接受 `auto` 或 `*`。宿主适配器首版应按一条连接
|
|
89
|
+
申请一个 workspace。
|
|
90
|
+
|
|
91
|
+
### 4.2 业务后端:查询授权上下文
|
|
92
|
+
|
|
93
|
+
`GET /agent-auth/v1/authorizations/{authorization_id}`
|
|
94
|
+
|
|
95
|
+
```http
|
|
96
|
+
Authorization: Bearer <BUSINESS_CLIENT_TOKEN>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
响应只包含应用名、设备名、请求的 routes、状态和过期时间,不包含 PKCE、callback 或 token。
|
|
100
|
+
|
|
101
|
+
### 4.3 业务后端:批准或拒绝
|
|
102
|
+
|
|
103
|
+
`POST /agent-auth/v1/authorizations/{authorization_id}/approve`
|
|
104
|
+
|
|
105
|
+
```http
|
|
106
|
+
Authorization: Bearer <BUSINESS_CLIENT_TOKEN>
|
|
107
|
+
Content-Type: application/json
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
```json
|
|
111
|
+
{
|
|
112
|
+
"principal": {
|
|
113
|
+
"id": "user-42",
|
|
114
|
+
"tenant": "tenant-7",
|
|
115
|
+
"roles": ["manager"],
|
|
116
|
+
"audience": "internal"
|
|
117
|
+
},
|
|
118
|
+
"on_behalf_of": "tenant-7:user-42",
|
|
119
|
+
"allowed_routes": ["order-assistant"]
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`principal`、`on_behalf_of` 和 `allowed_routes` 必须由业务后端根据当前登录态和权限表生成;不得信任
|
|
124
|
+
浏览器表单、query 参数或模型输出。批准范围必须同时属于本次请求与接入方 `allowed_routes`。
|
|
125
|
+
|
|
126
|
+
拒绝使用 `POST /agent-auth/v1/authorizations/{authorization_id}/deny`,body 为 `{}`。approve/deny
|
|
127
|
+
都返回一个由 Core 构造的 `redirect_uri`;页面只能跳转该值,不得接受浏览器自带的回调地址。
|
|
128
|
+
|
|
129
|
+
### 4.4 本地 SDK:兑换与刷新
|
|
130
|
+
|
|
131
|
+
`POST /agent-auth/v1/token`
|
|
132
|
+
|
|
133
|
+
授权码兑换:
|
|
134
|
+
|
|
135
|
+
```json
|
|
136
|
+
{
|
|
137
|
+
"grant_type": "authorization_code",
|
|
138
|
+
"client_app_id": "merchant-agent",
|
|
139
|
+
"code": "<one-time-code>",
|
|
140
|
+
"redirect_uri": "http://127.0.0.1:49152/callback",
|
|
141
|
+
"code_verifier": "<PKCE-verifier>"
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
refresh token 轮换:
|
|
146
|
+
|
|
147
|
+
```json
|
|
148
|
+
{
|
|
149
|
+
"grant_type": "refresh_token",
|
|
150
|
+
"client_app_id": "merchant-agent",
|
|
151
|
+
"refresh_token": "<refresh-token>"
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
access token 默认 15 分钟有效,refresh session 默认 30 天有效;每次刷新都会轮换 refresh token。
|
|
156
|
+
重复使用旧 refresh token会失败关闭。SDK 应把 access/refresh token 保存到系统安全凭据存储,而不是
|
|
157
|
+
连接元数据或插件配置。
|
|
158
|
+
|
|
159
|
+
### 4.5 会话查询与撤销
|
|
160
|
+
|
|
161
|
+
- `GET /agent-auth/v1/session`:Agent access token Bearer,返回当前会话的非秘密元数据;
|
|
162
|
+
- `POST /agent-auth/v1/revoke`:可用 Agent access token 撤销,或用
|
|
163
|
+
`client_app_id + refresh_token` body 撤销;
|
|
164
|
+
- `POST /agent-auth/v1/sessions/{session_id}/revoke`:业务后端使用 Client Token 撤销该应用的会话。
|
|
165
|
+
|
|
166
|
+
员工离职、租户禁用、设备丢失或业务权限撤销时,业务系统应主动撤销相关会话。即使会话尚未撤销,
|
|
167
|
+
业务工具端点仍必须在每次调用时按当前权限表重新裁决。
|
|
168
|
+
|
|
169
|
+
## 5. 业务授权页实现规则
|
|
170
|
+
|
|
171
|
+
- 页面属于业务系统,不由 SDK 自动注入;可以完全继承业务系统自己的 UI 风格;
|
|
172
|
+
- 未登录先跳业务登录,登录完成后回到同一授权请求;
|
|
173
|
+
- 明确展示当前账号、租户、设备名和申请的 workspace;
|
|
174
|
+
- 授权页前端只持有 `authorization_id`,Client Token 只在后端;
|
|
175
|
+
- 所有响应使用 `Cache-Control: no-store`,不要在分析、监控或错误上报中记录 token;
|
|
176
|
+
- 对重复、过期、已处理请求给出明确终态,不重新批准;
|
|
177
|
+
- CSP、CSRF、点击劫持和开放重定向防护沿用业务系统生产安全基线。
|
|
178
|
+
|
|
179
|
+
## 6. 错误与恢复
|
|
180
|
+
|
|
181
|
+
- `invalid_client`:应用未启用、未配置授权页或 route 不在应用白名单;
|
|
182
|
+
- `invalid_request`:字段、PKCE、callback、route 或主体格式不合法;
|
|
183
|
+
- `route_not_allowed`:业务后端批准了请求之外或应用未允许的 route;
|
|
184
|
+
- `invalid_grant`:code/PKCE/refresh token 无效、过期、重放或不匹配;
|
|
185
|
+
- `access_denied`:用户拒绝授权;
|
|
186
|
+
- `401 unauthorized`:业务后端 Client Token 或 Agent access token 无效;
|
|
187
|
+
- `409/410`:请求已处理或已过期。
|
|
188
|
+
|
|
189
|
+
客户端遇到刷新失败不得回退为管理员 Token、Client Token 或匿名调用;应清理/隔离失效会话并要求
|
|
190
|
+
用户重新执行浏览器授权。
|