bailinghub 0.6.1 → 0.8.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 +8 -7
- package/README.md +7 -7
- package/docker-compose.images.yml +2 -2
- package/docs/AGENT_AUTH_API.en.md +112 -1
- package/docs/AGENT_AUTH_API.md +99 -1
- package/docs/AGENT_CLIENT_QUICKSTART.en.md +32 -5
- package/docs/AGENT_CLIENT_QUICKSTART.md +27 -4
- package/docs/AGENT_CLIENT_RUNTIME_API.en.md +46 -0
- package/docs/AGENT_CLIENT_RUNTIME_API.md +38 -1
- package/docs/AGENT_CONVERSATION_AUDIT.en.md +109 -4
- package/docs/AGENT_CONVERSATION_AUDIT.md +84 -3
- package/docs/AGENT_SUBJECT_DISPLAY.en.md +95 -0
- package/docs/AGENT_SUBJECT_DISPLAY.md +95 -0
- package/docs/AGENT_SYSTEM_INFO.en.md +99 -0
- package/docs/AGENT_SYSTEM_INFO.md +97 -0
- package/docs/AGENT_TASK_CONTROL.en.md +25 -0
- package/docs/AGENT_TASK_CONTROL.md +94 -0
- package/docs/AGENT_TASK_CONTROL_FOUNDATION.md +134 -0
- package/docs/CHANGELOG.en.md +24 -1
- package/docs/CHANGELOG.md +24 -1
- package/docs/COMPATIBILITY.en.md +2 -0
- package/docs/CONTRACT.en.md +2 -0
- package/docs/CONTRACT.md +2 -0
- package/docs/GENERATED_ARTIFACTS.en.md +46 -0
- package/docs/GENERATED_ARTIFACTS.md +108 -0
- package/docs/INDEPENDENT_VALIDATION.en.md +4 -4
- package/docs/INDEPENDENT_VALIDATION.md +4 -4
- package/docs/INVOCATION_RECEIPTS.md +111 -0
- package/docs/LOCAL_AGENT_SETUP.en.md +116 -0
- package/docs/LOCAL_AGENT_SETUP.md +116 -0
- package/docs/README.en.md +9 -0
- package/docs/README.md +9 -0
- package/docs/RELEASE_NOTES_NEXT.en.md +3 -0
- package/docs/RELEASE_NOTES_NEXT.md +3 -0
- package/docs/RELEASE_NOTES_v0.7.0.en.md +116 -0
- package/docs/RELEASE_NOTES_v0.7.0.md +116 -0
- package/docs/RELEASE_NOTES_v0.8.0.en.md +40 -0
- package/docs/RELEASE_NOTES_v0.8.0.md +62 -0
- package/docs/SDK.en.md +31 -0
- package/docs/TOOL_RATE_LIMITS.md +50 -0
- package/docs/UPGRADE_v0.8.0.en.md +71 -0
- package/docs/UPGRADE_v0.8.0.md +73 -0
- package/docs/user-guide/conversations.en.md +4 -2
- package/docs/user-guide/conversations.md +4 -2
- package/docs//345/205/274/345/256/271/346/200/247/344/270/216/345/215/207/347/272/247.md +2 -0
- package/package.json +1 -1
- package/schemas/config/route.schema.json +16 -2
- package/schemas/config/tool-provider.schema.json +2 -1
- package/scripts/check-doc-links.mjs +2 -0
- package/scripts/check-image-tags.sh +1 -1
- package/scripts/check-release-consistency.test.mjs +2 -2
- package/scripts/e2e-console.mjs +32 -2
- package/scripts/install.sh +1 -1
- package/scripts/publish-images.sh +1 -1
- package/scripts/release-audit.mjs +2 -0
- package/scripts/sdk-agent-auth-lifecycle-check.mjs +178 -0
- package/scripts/sdk-runtime-test.mjs +5 -2
- package/scripts/verify-github-repo.mjs +2 -0
- package/sdk/php/README.md +29 -0
- package/sdk/php/src/AgentAuth.php +100 -4
- package/sdk/php/src/HubClient.php +2 -1
- package/sdk/php7/README.md +31 -0
- package/sdk/php7/src/AgentAuth.php +99 -4
- package/sdk/php7/src/HubClient.php +2 -1
- package/sql/058_agent_conversation_member_bindings.sql +9 -0
- package/sql/059_agent_subject_display.sql +5 -0
- package/sql/060_agent_artifacts.sql +11 -0
- package/sql/061_tool_rate_limit_policies.sql +3 -0
- package/sql/062_agent_task_control.sql +92 -0
- package/sql/README.en.md +15 -0
- package/sql/README.md +25 -0
- package/src/adapters/storage/object-storage.ts +15 -3
- package/src/adapters/storage/oss-signature.test.ts +40 -0
- package/src/adapters/storage/oss-signature.ts +21 -0
- package/src/app/agent-artifacts.test.ts +165 -0
- package/src/app/agent-artifacts.ts +85 -0
- package/src/app/agent-client-runtime.test.ts +76 -1
- package/src/app/agent-client-runtime.ts +13 -0
- package/src/app/agent-conversation-audit.ts +20 -0
- package/src/app/agent-invocation-snapshot.ts +35 -0
- package/src/app/agent-system-info.ts +41 -0
- package/src/app/agent-task-control.ts +187 -0
- package/src/app/agent-task-runtime.ts +68 -0
- package/src/app/agent-tool-invocations.test.ts +329 -1
- package/src/app/agent-tool-invocations.ts +239 -14
- package/src/app/agent-tool-job.test.ts +11 -1
- package/src/app/agent-tool-job.ts +8 -1
- package/src/app/builtin-tools.ts +4 -0
- package/src/app/oss-edition.ts +1 -0
- package/src/app/tool-approvals.ts +4 -0
- package/src/app/tool-assembly.ts +5 -0
- package/src/core/config/agent-setup.ts +37 -0
- package/src/core/config/artifact-config.ts +15 -0
- package/src/core/config/client-agent-setup.ts +25 -0
- package/src/core/config/config-codec.ts +3 -1
- package/src/core/config/config-models.ts +11 -1
- package/src/core/config/config-schema.test.ts +11 -0
- package/src/core/config/route-config.test.ts +28 -0
- package/src/core/config/route-config.ts +44 -4
- package/src/core/contracts/agent-subject-display.test.ts +19 -0
- package/src/core/contracts/agent-subject-display.ts +36 -0
- package/src/core/contracts/tool-rate-limits.test.ts +59 -0
- package/src/core/contracts/tool-rate-limits.ts +48 -0
- package/src/core/contracts/tools.ts +122 -43
- package/src/core/contracts/types.ts +18 -1
- package/src/core/runtime/agent-conversation-audit.test.ts +19 -1
- package/src/core/runtime/agent-conversation-audit.ts +39 -0
- package/src/core/runtime/agent-task-control.test.ts +114 -0
- package/src/core/runtime/agent-task-control.ts +227 -0
- package/src/infrastructure/config/config-agent-artifact-repository.ts +32 -0
- package/src/infrastructure/config/config-agent-auth-business-sessions.test.ts +120 -0
- package/src/infrastructure/config/config-agent-auth-lifecycle-race.test.ts +152 -0
- package/src/infrastructure/config/config-agent-auth-repository.test.ts +2 -0
- package/src/infrastructure/config/config-agent-auth-repository.ts +208 -18
- package/src/infrastructure/config/config-agent-client-runtime-repository.ts +7 -1
- package/src/infrastructure/config/config-agent-conversation-audit-cross-binding.test.ts +120 -0
- package/src/infrastructure/config/config-agent-conversation-audit-repository.ts +117 -23
- package/src/infrastructure/config/config-agent-subject-display.test.ts +103 -0
- package/src/infrastructure/config/config-agent-task-control-journal-mysql.test.ts +315 -0
- package/src/infrastructure/config/config-agent-task-control-mysql.test.ts +331 -0
- package/src/infrastructure/config/config-agent-task-control-repository.ts +640 -0
- package/src/infrastructure/config/config-client-repository.ts +21 -0
- package/src/infrastructure/config/config-rate-limit-ledger.integration.test.ts +52 -0
- package/src/infrastructure/config/config-rate-limit-ledger.ts +48 -0
- package/src/infrastructure/config/config-route-agent-setup.test.ts +59 -0
- package/src/infrastructure/config/config-route-repository.ts +24 -0
- package/src/infrastructure/config/config-storage-bucket-repository.ts +2 -2
- package/src/infrastructure/config/config-tool-provider-repository.ts +4 -4
- package/src/infrastructure/config/configstore.ts +16 -4
- package/src/infrastructure/schema/core-schema-migrator.test.ts +90 -0
- package/src/routes/admin-access.ts +37 -0
- package/src/routes/admin-agent-clients.ts +11 -0
- package/src/routes/admin-agent-setup.test.ts +130 -0
- package/src/routes/admin-agent-setup.ts +68 -0
- package/src/routes/admin-agent-tasks.ts +32 -0
- package/src/routes/admin-client-agent-setup.test.ts +93 -0
- package/src/routes/admin-dispatch-config.ts +2 -0
- package/src/routes/admin-tool-providers.test.ts +22 -0
- package/src/routes/admin-tool-providers.ts +9 -1
- package/src/routes/admin.ts +3 -0
- package/src/routes/agent-api.test.ts +76 -0
- package/src/routes/agent-api.ts +49 -1
- package/src/routes/agent-artifacts.ts +29 -0
- package/src/routes/agent-auth-lifecycle-http.test.ts +177 -0
- package/src/routes/agent-auth-lifecycle.test.ts +193 -0
- package/src/routes/agent-auth.test.ts +1 -1
- package/src/routes/agent-auth.ts +206 -16
- package/src/routes/agent-conversation-audit-cross-binding-http.test.ts +122 -0
- package/src/routes/agent-conversation-audit.ts +8 -2
- package/src/routes/agent-subject-display-http.test.ts +145 -0
- package/src/routes/agent-system-info.test.ts +132 -0
- package/src/routes/agent-task-control-http-mysql.test.ts +246 -0
- package/src/routes/private.ts +1 -0
- package/src/routes/run.ts +2 -1
- package/src/test-support/agent-auth-business-query-fixture.ts +43 -0
- package/src/test-support/agent-auth-lifecycle-fixture.ts +288 -0
- package/src/test-support/agent-conversation-audit-fixture.ts +30 -6
- package/src/test-support/agent-conversation-audit-http-fixture.ts +84 -0
- package/src/test-support/agent-task-control-mysql-fixture.ts +75 -0
- package/web/connect/bailing-connect-php.tgz +0 -0
- package/web/connect/bailing-connect-php7.tgz +0 -0
- package/web/console/assets/{Accounts-Ca_VnSu9.js → Accounts-BRCR3O0P.js} +1 -1
- package/web/console/assets/AgentClients-Bf7sUUs_.js +1 -0
- package/web/console/assets/AgentClients-i52AI6YV.css +1 -0
- package/web/console/assets/AgentTasks--bqL_QKg.js +2 -0
- package/web/console/assets/AgentTasks-C8ox3TyS.css +1 -0
- package/web/console/assets/{Approvals-CMvPWacY.js → Approvals-BIbZvInm.js} +1 -1
- package/web/console/assets/{Audit-CIRqOCnL.js → Audit-KyPSmBdZ.js} +1 -1
- package/web/console/assets/{BrandLockup-BrytmTTH.js → BrandLockup-Sv5DU2G6.js} +1 -1
- package/web/console/assets/{Channels-CApxH2TB.js → Channels-B9n4fbxg.js} +1 -1
- package/web/console/assets/{ChatEntries-CJon3bWJ.js → ChatEntries-xsOCUXi_.js} +1 -1
- package/web/console/assets/Clients-CI3DBDHf.js +3 -0
- package/web/console/assets/Clients-CSHIsaWU.css +1 -0
- package/web/console/assets/{Cost-BbhlQFP8.js → Cost-JgNXQPlN.js} +1 -1
- package/web/console/assets/{Credentials-kqr1W0K7.js → Credentials-B5UUUdt0.js} +1 -1
- package/web/console/assets/{Diagnostics-Kljt9XTH.js → Diagnostics-BMGciWQb.js} +1 -1
- package/web/console/assets/{Executors-DnsB-Xz4.js → Executors-CRbboOCZ.js} +1 -1
- package/web/console/assets/{Kb-DLZSAFWP.js → Kb-CgLNGjRp.js} +1 -1
- package/web/console/assets/{Login-DiTjPWmN.js → Login-C52JmXzx.js} +1 -1
- package/web/console/assets/{Projects-CXcVCgCD.js → Projects-CDOvHPVS.js} +1 -1
- package/web/console/assets/Routes-DkMIjMQA.css +1 -0
- package/web/console/assets/Routes-X9vHLpKW.js +124 -0
- package/web/console/assets/Runs-CvGTV8I-.css +1 -0
- package/web/console/assets/Runs-DYNDXsqk.js +3 -0
- package/web/console/assets/{Setup-FqoCKmfZ.js → Setup-B91P6i1x.js} +1 -1
- package/web/console/assets/Shell-Bj6C8Hgo.css +1 -0
- package/web/console/assets/Shell-BsRa7bQQ.js +1 -0
- package/web/console/assets/StorageBuckets-CVgpZRWY.css +1 -0
- package/web/console/assets/StorageBuckets-DkuDM0oX.js +1 -0
- package/web/console/assets/{SystemSettings-gTQAazu7.js → SystemSettings-B7Mqj3k1.js} +1 -1
- package/web/console/assets/{SystemStatus-DAmUUNqO.js → SystemStatus-Db93b6dc.js} +1 -1
- package/web/console/assets/{Targets-CZmDcjsE.js → Targets-CuuIYeZO.js} +1 -1
- package/web/console/assets/Tools-CHiqz9XZ.js +2 -0
- package/web/console/assets/Tools-DU8ei6sd.css +1 -0
- package/web/console/assets/index-UGvfF3Xr.js +2 -0
- package/web/console/assets/{request-r7GHVJzw.js → request-DeGya810.js} +1 -1
- package/web/console/assets/{schema-BVn_hB7M.js → schema-BqlqLw1R.js} +1 -1
- package/web/console/index.html +1 -1
- package/web-admin/scripts/agent-task-control-smoke.mjs +120 -0
- package/web-admin/scripts/subject-display-ui.mjs +78 -0
- package/web-admin/src/components/AgentSetupPanel.vue +275 -0
- package/web-admin/src/components/ClientConversations.vue +21 -4
- package/web-admin/src/components/ToolRateLimitEditor.vue +28 -0
- package/web-admin/src/components/conversation-audit.ts +20 -0
- package/web-admin/src/layout/Shell.vue +1 -1
- package/web-admin/src/pages/AgentClients.vue +99 -23
- package/web-admin/src/pages/AgentTasks.vue +281 -0
- package/web-admin/src/pages/Clients.vue +4 -1
- package/web-admin/src/pages/Routes.vue +10 -1
- package/web-admin/src/pages/StorageBuckets.vue +6 -6
- package/web-admin/src/pages/Tools.vue +53 -4
- package/web-admin/src/router.ts +2 -0
- package/web-admin/tests/conversation-audit.fixture.mjs +13 -10
- package/web-admin/tests/conversation-audit.test.mjs +63 -1
- package/web/console/assets/AgentClients-BPIvlLYY.js +0 -1
- package/web/console/assets/AgentClients-DsWADpzr.css +0 -1
- package/web/console/assets/Clients-BSA1rlTB.js +0 -3
- package/web/console/assets/Clients-CNIVs7Qn.css +0 -1
- package/web/console/assets/Routes-CXGl9SMM.css +0 -1
- package/web/console/assets/Routes-DN9_d9Po.js +0 -124
- package/web/console/assets/Runs-Cwbe6thL.js +0 -3
- package/web/console/assets/Runs-D8UmjP5G.css +0 -1
- package/web/console/assets/Shell-BEqpONiy.js +0 -1
- package/web/console/assets/Shell-D9Uw-fsa.css +0 -1
- package/web/console/assets/StorageBuckets-CkORbYXY.js +0 -1
- package/web/console/assets/StorageBuckets-GnXnVvF0.css +0 -1
- package/web/console/assets/Tools-A20oaMaQ.css +0 -1
- package/web/console/assets/Tools-CIHInlHL.js +0 -2
- package/web/console/assets/index-BkLbd7Cc.js +0 -2
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
如果你管理同一系统里的 A、B 两家门店,过去可能要先切换账户,再分别提问。配套的新客户端可以让你先选好本次对话允许使用的授权,再由 Agent 为每次操作选择对应账户。门店只是示例;它也可以是同一系统中的两个业务账户。
|
|
6
6
|
|
|
7
|
+
在同一中枢里,也可选择商城与库存两个系统:先查库存,再使用商城允许的改价或上架动作。系统说明解释各自用途,授权名称展示实际业务对象;两边商品映射需已确认。见[v0.7.0 场景说明](../RELEASE_NOTES_v0.7.0.md)。
|
|
8
|
+
|
|
7
9
|
## 开始前需要什么
|
|
8
10
|
|
|
9
|
-
部署者准备 BailingHub **0.
|
|
11
|
+
部署者准备 BailingHub **0.7.0**;本地客户端使用 **dsh-bailinghub 0.5.0**,它依赖独立的 **bailinghub-mcp-server 0.5.0** SDK。使用自研客户端时,开发者需要接入会话范围、原始可见历史和归档接口。单独升级中枢,不会让旧客户端自动上传完整对话。
|
|
10
12
|
|
|
11
13
|
业务系统已经接入并开放了需要的操作,你也已经分别完成 A、B 的业务授权。此次升级不要求重写既有业务能力或审批规则。还没有接入业务系统时,先运行[公开 Docker Demo](../DEMO.md)了解查询、审批和执行;该 Demo 不替代多账户客户端的安装与授权。
|
|
12
14
|
|
|
@@ -37,4 +39,4 @@
|
|
|
37
39
|
|
|
38
40
|
当前归档范围是客户端实际可见的文本与原执行关联,不包含隐藏推理、附件或任意本地工具的原始输出。只看到了某份授权的执行摘要、却没有完整原文的旧记录,仍会明确表示原文缺失。
|
|
39
41
|
|
|
40
|
-
部署与升级请看 [v0.
|
|
42
|
+
部署与升级请看 [v0.7.0 说明](../RELEASE_NOTES_v0.7.0.md);客户端开发者请看[接入指南](../AGENT_CLIENT_QUICKSTART.md)及[完整对话接口](../AGENT_CONVERSATION_AUDIT.md)。
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# 百灵中枢 · 兼容性与升级策略
|
|
2
2
|
|
|
3
|
+
> Core 0.8.0 task enrollment persists on original Agent Sessions. Do not downgrade an enrolled deployment to a version that ignores enforcement markers. See [upgrade boundaries](UPGRADE_v0.8.0.md).
|
|
4
|
+
|
|
3
5
|
> 这份策略用于公开发布后的版本演进。目标是让绝大多数升级都能平滑完成:拉新版、执行数据库结构同步、重启 hub;已配置的路由、凭证、工具源、聊天入口不需要重配。破坏性变更必须显式说明,并提供过渡窗口。
|
|
4
6
|
|
|
5
7
|
---
|
package/package.json
CHANGED
|
@@ -131,12 +131,26 @@
|
|
|
131
131
|
"agent_client": {
|
|
132
132
|
"type": "object",
|
|
133
133
|
"title": "本地 Agent Runtime",
|
|
134
|
-
"description": "本地 Agent
|
|
134
|
+
"description": "本地 Agent 编排的显式开关、系统说明、补充指令和每轮主动工具上限;缺省时兼容 tools.agent_direct.enabled。",
|
|
135
135
|
"additionalProperties": false,
|
|
136
136
|
"properties": {
|
|
137
137
|
"enabled": { "type": "boolean" },
|
|
138
138
|
"instructions": { "type": "string", "maxLength": 20000 },
|
|
139
|
-
"active_tool_limit": { "type": "integer", "minimum": 1, "maximum": 12 }
|
|
139
|
+
"active_tool_limit": { "type": "integer", "minimum": 1, "maximum": 12 },
|
|
140
|
+
"artifact_upload": {"type": "object", "additionalProperties": false, "required": ["enabled"], "properties": {"enabled": {"type": "boolean"}, "bucket": {"type": "string", "pattern": "^[a-zA-Z0-9_-]{1,64}$"}, "max_bytes": {"type": "integer", "minimum": 1, "maximum": 6291456}, "allowed_mimes": {"type": "array", "minItems": 1, "uniqueItems": true, "items": {"enum": ["image/png", "image/jpeg", "image/webp"]}}}, "allOf": [{"if": {"properties": {"enabled": {"const": true}}}, "then": {"required": ["bucket"]}}]},
|
|
141
|
+
"system_info": {
|
|
142
|
+
"type": "object",
|
|
143
|
+
"title": "业务系统说明",
|
|
144
|
+
"description": "首次查找工具前可读取的产品定位数据;不授予工具权限,也不作为模型系统指令。",
|
|
145
|
+
"additionalProperties": false,
|
|
146
|
+
"required": ["name", "summary", "domains", "boundaries"],
|
|
147
|
+
"properties": {
|
|
148
|
+
"name": { "type": "string", "minLength": 1, "maxLength": 120, "pattern": "^(?=.*\\S)[^\\u0000-\\u001f\\u007f]+$", "title": "系统名称" },
|
|
149
|
+
"summary": { "type": "string", "minLength": 1, "maxLength": 400, "pattern": "^(?=.*\\S)[^\\u0000-\\u001f\\u007f]+$", "title": "简短用途" },
|
|
150
|
+
"domains": { "type": "array", "maxItems": 6, "items": { "type": "string", "minLength": 1, "maxLength": 120, "pattern": "^(?=.*\\S)[^\\u0000-\\u001f\\u007f]+$" }, "title": "典型业务方向" },
|
|
151
|
+
"boundaries": { "type": "array", "maxItems": 6, "items": { "type": "string", "minLength": 1, "maxLength": 160, "pattern": "^(?=.*\\S)[^\\u0000-\\u001f\\u007f]+$" }, "title": "业务边界" }
|
|
152
|
+
}
|
|
153
|
+
}
|
|
140
154
|
}
|
|
141
155
|
},
|
|
142
156
|
"budget": {
|
|
@@ -43,7 +43,8 @@
|
|
|
43
43
|
"secret": { "type": "string", "minLength": 1, "title": "签名密钥", "description": "中枢与业务工具源共享的 HMAC 密钥,用于工具调用、spec 拉取与授权探针验签。" },
|
|
44
44
|
"log_payload": { "type": "boolean", "title": "审计粒度", "description": "控制工具调用参数在审计中记录全量值还是只记录键名;敏感工具仍强制脱敏。" },
|
|
45
45
|
"timeout_ms": { "type": "integer", "minimum": 1000, "maximum": 60000, "title": "单次调用超时", "description": "中枢等待单个工具接口响应的最长毫秒数。" },
|
|
46
|
-
"rate_limit_per_min": { "type": "integer", "minimum": 0, "title": "
|
|
46
|
+
"rate_limit_per_min": { "type": "integer", "minimum": 0, "maximum": 1000000, "title": "工具源总限额", "description": "该工具源的所有工具、用户、授权和会话共用每分钟调度额度;0 只关闭总闸,单工具策略仍独立生效。" },
|
|
47
|
+
"tool_rate_limits": {"type": "object", "additionalProperties": false, "title": "中枢单工具限额策略", "description": "指定工具覆盖优先于默认策略;默认继承业务声明,支持自定义或关闭中枢限额。每个工具按工具源共享计数。", "properties": {"default": {"oneOf": [{"type": "object", "additionalProperties": false, "required": ["mode"], "properties": {"mode": {"enum": ["inherit", "disabled"]}}}, {"type": "object", "additionalProperties": false, "required": ["mode", "count", "window"], "properties": {"mode": {"const": "custom"}, "count": {"type": "integer", "minimum": 1, "maximum": 1000000}, "window": {"enum": ["1s", "1m", "1h", "1d"]}}}]}, "overrides": {"type": "object", "maxProperties": 1000, "propertyNames": {"pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$"}, "additionalProperties": {"oneOf": [{"type": "object", "additionalProperties": false, "required": ["mode"], "properties": {"mode": {"enum": ["inherit", "disabled"]}}}, {"type": "object", "additionalProperties": false, "required": ["mode", "count", "window"], "properties": {"mode": {"const": "custom"}, "count": {"type": "integer", "minimum": 1, "maximum": 1000000}, "window": {"enum": ["1s", "1m", "1h", "1d"]}}}]}}}},
|
|
47
48
|
"auto_refresh_min": { "type": "integer", "minimum": 0, "maximum": 1440, "title": "自动刷新", "description": "URL 模式下按分钟自动拉取新 spec;0 表示关闭。" },
|
|
48
49
|
"enabled": { "type": "boolean", "title": "启用", "description": "关闭后该工具源不会再向路由提供业务工具。" },
|
|
49
50
|
"description": { "type": "string", "title": "说明", "description": "给后台维护者看的备注,不参与运行期决策。" },
|
|
@@ -103,6 +103,8 @@ const englishCompanions = {
|
|
|
103
103
|
'docs/RELEASE_NOTES_v0.3.4.md': 'docs/RELEASE_NOTES_v0.3.4.en.md',
|
|
104
104
|
'docs/RELEASE_NOTES_v0.5.0.md': 'docs/RELEASE_NOTES_v0.5.0.en.md',
|
|
105
105
|
'docs/RELEASE_NOTES_v0.5.1.md': 'docs/RELEASE_NOTES_v0.5.1.en.md',
|
|
106
|
+
'docs/RELEASE_NOTES_v0.8.0.md': 'docs/RELEASE_NOTES_v0.8.0.en.md',
|
|
107
|
+
'docs/RELEASE_NOTES_v0.7.0.md': 'docs/RELEASE_NOTES_v0.7.0.en.md',
|
|
106
108
|
'docs/RELEASE_NOTES_v0.6.1.md': 'docs/RELEASE_NOTES_v0.6.1.en.md',
|
|
107
109
|
'docs/RELEASE_NOTES_v0.6.0.md': 'docs/RELEASE_NOTES_v0.6.0.en.md',
|
|
108
110
|
'docs/TOOLS_DESIGN.md': 'docs/TOOLS_DESIGN.en.md',
|
|
@@ -9,7 +9,7 @@ REGISTRY="${BAILING_IMAGE_REGISTRY:-$DEFAULT_REGISTRY}"
|
|
|
9
9
|
NAMESPACE="${BAILING_IMAGE_NAMESPACE:-$DEFAULT_NAMESPACE}"
|
|
10
10
|
PACKAGE_VERSION="$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' package.json | head -1)"
|
|
11
11
|
TAG="${BAILING_IMAGE_TAG:-$PACKAGE_VERSION}"
|
|
12
|
-
[ -n "$TAG" ] || TAG="0.
|
|
12
|
+
[ -n "$TAG" ] || TAG="0.8.0"
|
|
13
13
|
MYSQL_TAG="${BAILING_MYSQL_IMAGE_TAG:-8.4}"
|
|
14
14
|
MYSQL_IMAGE="${BAILING_MYSQL_IMAGE:-$REGISTRY/$NAMESPACE/bailing-mysql:$MYSQL_TAG}"
|
|
15
15
|
PLATFORM="${BAILING_IMAGE_PLATFORM:-linux/amd64}"
|
|
@@ -38,8 +38,8 @@ function updateJson(root, relativePath, update) {
|
|
|
38
38
|
test('current release surface is internally consistent', () => {
|
|
39
39
|
const result = checkReleaseConsistency({ root: repoRoot });
|
|
40
40
|
assert.deepEqual(result.findings, []);
|
|
41
|
-
assert.equal(result.version, '0.
|
|
42
|
-
assert.equal(result.stableVersion, '0.
|
|
41
|
+
assert.equal(result.version, '0.8.0');
|
|
42
|
+
assert.equal(result.stableVersion, '0.8.0');
|
|
43
43
|
assert.equal(result.publishTag, 'latest');
|
|
44
44
|
});
|
|
45
45
|
|
package/scripts/e2e-console.mjs
CHANGED
|
@@ -57,6 +57,7 @@ const fixtures = {
|
|
|
57
57
|
},
|
|
58
58
|
authz_probe: { status: 'pass' },
|
|
59
59
|
auto_refresh_min: 60,
|
|
60
|
+
rate_limit_per_min: 120, timeout_ms: 10000, log_payload: false,
|
|
60
61
|
}],
|
|
61
62
|
clients: [{ app_id: 'demo-app', name: 'Demo 业务系统', token: '****oken', allowed_routes: ['demo_support'], allowed_channels: [], rate_limit_per_min: 60, enabled: true }],
|
|
62
63
|
routes: [{ route_key: 'demo_support', name: 'Demo 售后助手', target: 'demo-agent', enabled: true, tools: { sources: [{ provider: 'demo-business', allow: ['demo.*'] }], max_calls: 5 } }],
|
|
@@ -292,7 +293,15 @@ async function mockApi(context) {
|
|
|
292
293
|
}
|
|
293
294
|
if (url.pathname === '/admin/api/credentials') return route.fulfill({ json: fixtures.credentials });
|
|
294
295
|
if (url.pathname === '/admin/api/targets') return route.fulfill({ json: fixtures.targets });
|
|
295
|
-
if (url.pathname === '/admin/api/tool-providers')
|
|
296
|
+
if (url.pathname === '/admin/api/tool-providers') {
|
|
297
|
+
if (route.request().method() === 'POST') {
|
|
298
|
+
const payload = route.request().postDataJSON();
|
|
299
|
+
Object.assign(fixtures.providers[0], payload);
|
|
300
|
+
return route.fulfill({ json: { ok: true } });
|
|
301
|
+
}
|
|
302
|
+
return route.fulfill({ json: fixtures.providers });
|
|
303
|
+
}
|
|
304
|
+
if (/^\/admin\/api\/tool-providers\/[^/]+\/tools$/.test(url.pathname)) return route.fulfill({ json: { tools: [{ name: 'list_demo_orders', scope: 'demo.order.read' }] } });
|
|
296
305
|
if (url.pathname === '/admin/api/clients') return route.fulfill({ json: fixtures.clients });
|
|
297
306
|
if (url.pathname === '/admin/api/routes') return route.fulfill({ json: fixtures.routes });
|
|
298
307
|
if (url.pathname === '/admin/api/runs') return route.fulfill({ json: fixtures.runs });
|
|
@@ -401,7 +410,28 @@ try {
|
|
|
401
410
|
if (!await signedPolicy.isChecked()) throw new Error('采用实测结果后应选择签名保护');
|
|
402
411
|
await page.getByRole('button', { name: '取消' }).click();
|
|
403
412
|
|
|
404
|
-
await page.getByRole('
|
|
413
|
+
await page.getByRole('button', { name: '编辑' }).first().click();
|
|
414
|
+
await page.getByRole('tab', { name: '治理', exact: true }).click();
|
|
415
|
+
await expectVisible(page, '工具源总限额');
|
|
416
|
+
await expectVisible(page, '用户、授权和会话共用');
|
|
417
|
+
const defaultPolicy = page.locator('.limit-editor').first();
|
|
418
|
+
await defaultPolicy.locator('.el-select__wrapper').first().click();
|
|
419
|
+
await page.getByRole('option', { name: '自定义中枢限额', exact: true }).click();
|
|
420
|
+
await defaultPolicy.getByRole('spinbutton').fill('1000');
|
|
421
|
+
await page.getByRole('button', { name: '添加工具覆盖', exact: true }).click();
|
|
422
|
+
await page.getByText('选择或输入工具名', { exact: true }).click();
|
|
423
|
+
await page.getByRole('option', { name: 'list_demo_orders', exact: true }).last().click();
|
|
424
|
+
await page.getByRole('button', { name: '保存', exact: true }).click();
|
|
425
|
+
await expectVisible(page, '已保存');
|
|
426
|
+
if (fixtures.providers[0].tool_rate_limits.default.count !== 1000 || fixtures.providers[0].tool_rate_limits.default.window !== '1h') throw new Error('custom hour policy not saved');
|
|
427
|
+
if (fixtures.providers[0].tool_rate_limits.overrides.list_demo_orders.mode !== 'inherit') throw new Error('per-tool override not saved');
|
|
428
|
+
await page.getByRole('button', { name: '编辑' }).first().click();
|
|
429
|
+
await page.getByRole('tab', { name: '治理', exact: true }).click();
|
|
430
|
+
if (await page.locator('.limit-editor').first().getByRole('spinbutton').inputValue() !== '1000') throw new Error('saved policy did not restore');
|
|
431
|
+
if (process.env.BAILING_RATE_SCREENSHOT) await page.screenshot({ path: process.env.BAILING_RATE_SCREENSHOT, fullPage: true });
|
|
432
|
+
await page.getByRole('button', { name: '取消', exact: true }).click();
|
|
433
|
+
|
|
434
|
+
await page.getByRole('menuitem', { name: '任务', exact: true }).click();
|
|
405
435
|
const auditRadio = page.getByRole('radio', { name: '客户端完整对话', exact: true });
|
|
406
436
|
if (!await auditRadio.isChecked()) throw new Error('任务会话页应默认展示客户端完整对话');
|
|
407
437
|
const auditList = page.locator('aside[aria-label="客户端对话列表"]');
|
package/scripts/install.sh
CHANGED
|
@@ -275,7 +275,7 @@ write_env() {
|
|
|
275
275
|
TOOL_SECRET="${DEMO_TOOL_SECRET:-$(secret)}"
|
|
276
276
|
CLIENT_TOKEN="${DEMO_CLIENT_TOKEN:-$(secret)}"
|
|
277
277
|
IMAGE_TAG="${BAILING_IMAGE_TAG:-$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$APP_DIR/package.json" | head -1)}"
|
|
278
|
-
[ -n "$IMAGE_TAG" ] || IMAGE_TAG="0.
|
|
278
|
+
[ -n "$IMAGE_TAG" ] || IMAGE_TAG="0.8.0"
|
|
279
279
|
IMAGE_REGISTRY="${BAILING_IMAGE_REGISTRY:-$DEFAULT_IMAGE_REGISTRY}"
|
|
280
280
|
IMAGE_NAMESPACE="${BAILING_IMAGE_NAMESPACE:-$DEFAULT_IMAGE_NAMESPACE}"
|
|
281
281
|
cat > "$ENV_FILE" <<EOF
|
|
@@ -9,7 +9,7 @@ REGISTRY="${BAILING_IMAGE_REGISTRY:-$DEFAULT_REGISTRY}"
|
|
|
9
9
|
NAMESPACE="${BAILING_IMAGE_NAMESPACE:-$DEFAULT_NAMESPACE}"
|
|
10
10
|
PACKAGE_VERSION="$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' package.json | head -1)"
|
|
11
11
|
TAG="${BAILING_IMAGE_TAG:-$PACKAGE_VERSION}"
|
|
12
|
-
[ -n "$TAG" ] || TAG="0.
|
|
12
|
+
[ -n "$TAG" ] || TAG="0.8.0"
|
|
13
13
|
NODE_IMAGE="${BAILING_NODE_IMAGE:-node:22-bookworm-slim}"
|
|
14
14
|
PLATFORM="${BAILING_IMAGE_PLATFORM:-linux/amd64}"
|
|
15
15
|
PUSH="${BAILING_PUSH_IMAGES:-0}"
|
|
@@ -37,6 +37,8 @@ const requiredRepoFiles = [
|
|
|
37
37
|
'docs/RELEASE_NOTES_v0.3.4.md',
|
|
38
38
|
'docs/RELEASE_NOTES_v0.5.0.md',
|
|
39
39
|
'docs/RELEASE_NOTES_v0.5.1.md',
|
|
40
|
+
'docs/RELEASE_NOTES_v0.7.0.md',
|
|
41
|
+
'docs/RELEASE_NOTES_v0.8.0.md',
|
|
40
42
|
'docs/RELEASE_NOTES_v0.6.1.md',
|
|
41
43
|
'docs/RELEASE_NOTES_v0.6.0.md',
|
|
42
44
|
'docs/CHANGELOG.md',
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { createServer } from 'node:http';
|
|
2
|
+
|
|
3
|
+
// Invoked by sdk-runtime-test.mjs so lifecycle checks share its runtime matrix.
|
|
4
|
+
export async function checkAgentAuthLifecycle({ root, runAsync, ok, closeServer }) {
|
|
5
|
+
const authorizationId = '11111111-1111-4111-8111-111111111111';
|
|
6
|
+
const unmappedId = '33333333-3333-4333-8333-333333333333';
|
|
7
|
+
const sessionId = '22222222-2222-4222-8222-222222222222';
|
|
8
|
+
const session = { session_id: sessionId, state: 'revoked', expires_at: '2030-02-01T00:00:00.000Z', revoked_at: '2030-01-02T00:00:00.000Z' };
|
|
9
|
+
const item = {
|
|
10
|
+
...session, authorization_id: authorizationId, client_app_id: 'merchant-agent',
|
|
11
|
+
device_label: 'Test device', principal: { id: '用户 +/?&=😀', tenant: '租户&=' },
|
|
12
|
+
on_behalf_of: 'tenant:user +/?&=😀', allowed_routes: ['staff-route'],
|
|
13
|
+
created_at: '2030-01-01T00:00:00.000Z', last_seen_at: '2030-01-01T01:00:00.000Z',
|
|
14
|
+
};
|
|
15
|
+
const filters = {
|
|
16
|
+
authorization_id: authorizationId, on_behalf_of: item.on_behalf_of,
|
|
17
|
+
principal_id: item.principal.id, tenant: item.principal.tenant,
|
|
18
|
+
state: 'revoked', limit: 100, cursor: 'next_page-1',
|
|
19
|
+
};
|
|
20
|
+
const invalid = [
|
|
21
|
+
{ unknown: 'field' }, { client_app_id: 'other-app' }, { 0: 'active' },
|
|
22
|
+
{ authorization_id: null }, { authorization_id: '-'.repeat(36) },
|
|
23
|
+
{ authorization_id: '11111111-1111-0111-8111-111111111111' },
|
|
24
|
+
{ authorization_id: '11111111-1111-4111-0111-111111111111' },
|
|
25
|
+
{ on_behalf_of: '' }, { on_behalf_of: 'x'.repeat(192) }, { on_behalf_of: [] },
|
|
26
|
+
{ principal_id: 'u' }, { principal_id: '', tenant: '' },
|
|
27
|
+
{ principal_id: 'u'.repeat(129), tenant: '' },
|
|
28
|
+
{ tenant: null }, { tenant: 't'.repeat(129) },
|
|
29
|
+
{ on_behalf_of: ' user' }, { tenant: 'tenant ' }, { tenant: '\uFEFFtenant' },
|
|
30
|
+
{ tenant: 'a\u0000b' }, { tenant: 'a\u007fb' },
|
|
31
|
+
{ tenant: '😀'.repeat(65) }, { state: 'all' }, { state: [] },
|
|
32
|
+
{ limit: 0 }, { limit: 101 }, { limit: '20' }, { limit: 1.5 }, { limit: true },
|
|
33
|
+
{ cursor: '' }, { cursor: null }, { cursor: 'with=' }, { cursor: 'with+' },
|
|
34
|
+
{ cursor: 'with/' }, { cursor: 'next\n' }, { cursor: 'a'.repeat(2049) },
|
|
35
|
+
];
|
|
36
|
+
const invalidDisplays = [
|
|
37
|
+
{}, { name: '' }, { name: ' ' }, { name: 42 }, { name: 'a', scope: '*' },
|
|
38
|
+
{ name: 'a'.repeat(121) }, { name: '😀'.repeat(61) }, { name: 'a\nb' },
|
|
39
|
+
{ name: '\ta' }, { name: 'a\u007f' }, { name: 'a\u0085' }, { name: 'a\u2028b' },
|
|
40
|
+
{ name: 'a\u2029b' }, [], 'Account A',
|
|
41
|
+
];
|
|
42
|
+
const requests = [];
|
|
43
|
+
const server = createServer(async (req, res) => {
|
|
44
|
+
let body = '';
|
|
45
|
+
for await (const chunk of req) body += chunk;
|
|
46
|
+
requests.push({ method: req.method, url: req.url, body, headers: req.headers });
|
|
47
|
+
res.setHeader('Content-Type', 'application/json');
|
|
48
|
+
const url = new URL(req.url, 'http://fixture.invalid');
|
|
49
|
+
if (url.pathname === `/agent-auth/v1/authorizations/${authorizationId}`) {
|
|
50
|
+
res.end(JSON.stringify({ status: 'consumed', requested_routes: ['staff-route'], session }));
|
|
51
|
+
} else if (url.pathname === `/agent-auth/v1/authorizations/${unmappedId}`) {
|
|
52
|
+
res.end(JSON.stringify({ status: 'consumed', requested_routes: ['staff-route'], session: null }));
|
|
53
|
+
} else if (url.pathname === '/agent-auth/v1/sessions') {
|
|
54
|
+
res.end(JSON.stringify({ list: [item], next_cursor: url.search ? null : 'next_page-1' }));
|
|
55
|
+
} else if (url.pathname === `/agent-auth/v1/authorizations/${authorizationId}/revoke`) {
|
|
56
|
+
res.end(JSON.stringify({ authorization_id: authorizationId, revoked: true, session_id: sessionId }));
|
|
57
|
+
} else if (url.pathname === `/agent-auth/v1/authorizations/${authorizationId}/approve`) {
|
|
58
|
+
res.end(JSON.stringify({ redirect_uri: 'http://127.0.0.1:12345/callback?code=synthetic-code' }));
|
|
59
|
+
} else if (url.pathname === `/agent-auth/v1/sessions/${sessionId}/subject-display`) {
|
|
60
|
+
const display = JSON.parse(body).subject_display;
|
|
61
|
+
res.end(JSON.stringify({ ...item, state: 'active', subject_display: display, subject_display_status: display ? 'provided' : 'missing' }));
|
|
62
|
+
} else if (url.pathname.endsWith('/deny') || url.pathname.endsWith('/revoke') || url.pathname === '/body-check') {
|
|
63
|
+
res.end('{}');
|
|
64
|
+
} else {
|
|
65
|
+
res.statusCode = 404;
|
|
66
|
+
res.end('{"error":"not found"}');
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
await new Promise((resolve, reject) => { server.once('error', reject); server.listen(0, '127.0.0.1', resolve); });
|
|
70
|
+
const encoded = (value) => Buffer.from(JSON.stringify(value)).toString('base64');
|
|
71
|
+
try {
|
|
72
|
+
for (const variant of ['php', 'php7']) {
|
|
73
|
+
const command = variant === 'php7' ? (process.env.BAILING_SDK_PHP7_BINARY || 'php') : 'php';
|
|
74
|
+
const start = requests.length;
|
|
75
|
+
const result = await runAsync(command, ['-r', `
|
|
76
|
+
require '${root}/sdk/${variant}/src/HubClient.php';
|
|
77
|
+
require '${root}/sdk/${variant}/src/AgentAuth.php';
|
|
78
|
+
$auth = new Bailing\\Connect\\AgentAuth('http://127.0.0.1:${server.address().port}', 'synthetic-client-token');
|
|
79
|
+
$out = array('runtime' => PHP_VERSION);
|
|
80
|
+
$out['context'] = $auth->context('${authorizationId}');
|
|
81
|
+
$out['unmapped'] = $auth->context('${unmappedId}');
|
|
82
|
+
$out['default'] = $auth->listSessions();
|
|
83
|
+
$out['filtered'] = $auth->listSessions(json_decode(base64_decode('${encoded(filters)}'), true));
|
|
84
|
+
$out['tenantless'] = $auth->listSessions(array('principal_id' => 'u', 'tenant' => '', 'limit' => 1));
|
|
85
|
+
$out['tenant'] = $auth->listSessions(array('tenant' => str_repeat('😀', 64)));
|
|
86
|
+
$out['revoke'] = $auth->revokeAuthorization('${authorizationId}');
|
|
87
|
+
$out['repeat'] = $auth->revokeAuthorization('${authorizationId}');
|
|
88
|
+
$auth->deny('${authorizationId}');
|
|
89
|
+
$auth->revokeSession('${sessionId}');
|
|
90
|
+
$hub = new Bailing\\Connect\\HubClient('http://127.0.0.1:${server.address().port}', 'synthetic-client-token');
|
|
91
|
+
$hub->post('/body-check', array('nested' => array(), 'value' => 'kept'));
|
|
92
|
+
$hub->post('/body-check', array('nonempty-list'));
|
|
93
|
+
$principal = array('id' => 'user-a', 'tenant' => 'tenant-a');
|
|
94
|
+
$out['approveOld'] = $auth->approve('${authorizationId}', $principal, 'tenant-a:user-a', array('staff-route'));
|
|
95
|
+
$out['approveNamed'] = $auth->approve('${authorizationId}', $principal, 'tenant-a:user-a', array('staff-route'), array('name' => ' Account A '));
|
|
96
|
+
$out['approveMissing'] = $auth->approve('${authorizationId}', $principal, 'tenant-a:user-a', array('staff-route'), null);
|
|
97
|
+
$out['named'] = $auth->updateSubjectDisplay('${sessionId}', array('name' => ' Account A '));
|
|
98
|
+
$out['cleared'] = $auth->updateSubjectDisplay('${sessionId}', null);
|
|
99
|
+
$out['unicodeName'] = $auth->updateSubjectDisplay('${sessionId}', array('name' => str_repeat('😀', 60)));
|
|
100
|
+
$out['invalidDisplays'] = array();
|
|
101
|
+
foreach (json_decode(base64_decode('${encoded(invalidDisplays)}'), true) as $display) {
|
|
102
|
+
try { $auth->updateSubjectDisplay('${sessionId}', $display); $out['invalidDisplays'][] = false; }
|
|
103
|
+
catch (Throwable $e) { $out['invalidDisplays'][] = true; }
|
|
104
|
+
try { $auth->approve('${authorizationId}', $principal, 'tenant-a:user-a', array('staff-route'), $display); $out['invalidDisplays'][] = false; }
|
|
105
|
+
catch (Throwable $e) { $out['invalidDisplays'][] = true; }
|
|
106
|
+
}
|
|
107
|
+
try { $auth->updateSubjectDisplay('${sessionId}', array('name' => "\\xFF")); $out['invalidDisplayUtf8'] = false; }
|
|
108
|
+
catch (Throwable $e) { $out['invalidDisplayUtf8'] = true; }
|
|
109
|
+
try { $auth->updateSubjectDisplay('not-a-uuid', null); $out['invalidDisplayId'] = false; }
|
|
110
|
+
catch (Throwable $e) { $out['invalidDisplayId'] = true; }
|
|
111
|
+
$out['invalid'] = array();
|
|
112
|
+
foreach (json_decode(base64_decode('${encoded(invalid)}'), true) as $filters) {
|
|
113
|
+
try { $auth->listSessions($filters); $out['invalid'][] = false; }
|
|
114
|
+
catch (InvalidArgumentException $e) { $out['invalid'][] = true; }
|
|
115
|
+
}
|
|
116
|
+
try { $auth->listSessions(array('tenant' => "\\xFF")); $out['invalidUtf8'] = false; }
|
|
117
|
+
catch (InvalidArgumentException $e) { $out['invalidUtf8'] = true; }
|
|
118
|
+
try { $auth->revokeAuthorization('not-a-uuid'); $out['invalidId'] = false; }
|
|
119
|
+
catch (InvalidArgumentException $e) { $out['invalidId'] = true; }
|
|
120
|
+
echo json_encode($out, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
121
|
+
`]);
|
|
122
|
+
let data;
|
|
123
|
+
try { data = JSON.parse(result.stdout); } catch {}
|
|
124
|
+
const captured = requests.slice(start);
|
|
125
|
+
const label = `${variant.toUpperCase()} AgentAuth lifecycle`;
|
|
126
|
+
ok(`${label} runs on PHP ${data?.runtime ?? 'unknown'}`, result.status === 0 && !!data, result.stderr || result.stdout);
|
|
127
|
+
ok(`${label} preserves consumed context and missing-session projection`,
|
|
128
|
+
JSON.stringify(data?.context?.session) === JSON.stringify(session)
|
|
129
|
+
&& data?.context?.requested_routes?.[0] === 'staff-route'
|
|
130
|
+
&& data?.unmapped?.session === null);
|
|
131
|
+
ok(`${label} returns list metadata and opaque/null cursors unchanged`,
|
|
132
|
+
JSON.stringify(data?.default?.list) === JSON.stringify([item])
|
|
133
|
+
&& data?.default?.next_cursor === 'next_page-1' && data?.filtered?.next_cursor === null);
|
|
134
|
+
const listRequests = captured.filter((request) => request.url.startsWith('/agent-auth/v1/sessions') && request.method === 'GET');
|
|
135
|
+
const query = new URL(listRequests[1]?.url ?? '/', 'http://fixture.invalid');
|
|
136
|
+
ok(`${label} uses only whitelisted RFC3986 query fields without broadening`,
|
|
137
|
+
listRequests[0]?.url === '/agent-auth/v1/sessions'
|
|
138
|
+
&& JSON.stringify(Object.fromEntries(query.searchParams)) === JSON.stringify(Object.fromEntries(Object.entries(filters).map(([key, value]) => [key, String(value)])))
|
|
139
|
+
&& listRequests[1]?.url.includes('%20') && !listRequests[1]?.url.includes('+')
|
|
140
|
+
&& listRequests[2]?.url === '/agent-auth/v1/sessions?principal_id=u&tenant=&limit=1'
|
|
141
|
+
&& new URL(listRequests[3]?.url ?? '/', 'http://fixture.invalid').searchParams.get('tenant') === '😀'.repeat(64));
|
|
142
|
+
ok(`${label} rejects ${invalid.length + 2} invalid filters/IDs before HTTP`,
|
|
143
|
+
data?.invalid?.length === invalid.length && data.invalid.every(Boolean)
|
|
144
|
+
&& data?.invalidUtf8 === true && data?.invalidId === true && captured.length === 18);
|
|
145
|
+
ok(`${label} uses idempotent revoke-authorization path and empty object bodies`,
|
|
146
|
+
JSON.stringify(data?.revoke) === JSON.stringify({ authorization_id: authorizationId, revoked: true, session_id: sessionId })
|
|
147
|
+
&& JSON.stringify(data?.repeat) === JSON.stringify(data?.revoke)
|
|
148
|
+
&& captured.slice(6, 10).every((request) => request.method === 'POST' && request.body === '{}')
|
|
149
|
+
&& captured[6]?.url === `/agent-auth/v1/authorizations/${authorizationId}/revoke`
|
|
150
|
+
&& captured[7]?.url === captured[6]?.url);
|
|
151
|
+
ok(`${label} keeps non-empty HubClient bodies unchanged`,
|
|
152
|
+
captured[10]?.body === '{"nested":[],"value":"kept"}' && captured[11]?.body === '["nonempty-list"]');
|
|
153
|
+
const approvals = captured.filter((request) => request.url.endsWith('/approve'));
|
|
154
|
+
ok(`${label} keeps four-argument approval compatible and transmits explicit display/null`,
|
|
155
|
+
approvals.length === 3 && approvals.every((request) => request.method === 'POST')
|
|
156
|
+
&& !Object.hasOwn(JSON.parse(approvals[0].body), 'subject_display')
|
|
157
|
+
&& JSON.stringify(JSON.parse(approvals[1].body).subject_display) === JSON.stringify({ name: 'Account A' })
|
|
158
|
+
&& JSON.parse(approvals[2].body).subject_display === null
|
|
159
|
+
&& JSON.parse(approvals[1].body).principal.id === 'user-a');
|
|
160
|
+
const updates = captured.filter((request) => request.url.endsWith('/subject-display'));
|
|
161
|
+
ok(`${label} updates only display via PUT and preserves returned session metadata`,
|
|
162
|
+
updates.length === 3 && updates.every((request) => request.method === 'PUT'
|
|
163
|
+
&& Object.keys(JSON.parse(request.body)).join(',') === 'subject_display')
|
|
164
|
+
&& data?.named?.subject_display?.name === 'Account A' && data?.named?.subject_display_status === 'provided'
|
|
165
|
+
&& data?.named?.session_id === sessionId && data?.named?.principal?.id === item.principal.id
|
|
166
|
+
&& data?.cleared?.subject_display === null && data?.cleared?.subject_display_status === 'missing'
|
|
167
|
+
&& data?.unicodeName?.subject_display?.name === '😀'.repeat(60));
|
|
168
|
+
ok(`${label} rejects invalid display objects, controls, length, UTF-8 and IDs before HTTP`,
|
|
169
|
+
data?.invalidDisplays?.length === invalidDisplays.length * 2 && data.invalidDisplays.every(Boolean)
|
|
170
|
+
&& data?.invalidDisplayUtf8 === true && data?.invalidDisplayId === true && captured.length === 18);
|
|
171
|
+
ok(`${label} sends only server-side Client Token headers`, captured.every((request) =>
|
|
172
|
+
request.headers.authorization === 'Bearer synthetic-client-token'
|
|
173
|
+
&& !request.url.includes('synthetic-client-token') && !request.body.includes('synthetic-client-token')));
|
|
174
|
+
}
|
|
175
|
+
} finally {
|
|
176
|
+
await closeServer(server);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -2,6 +2,7 @@ import { spawn, spawnSync } from 'node:child_process';
|
|
|
2
2
|
import { createServer } from 'node:http';
|
|
3
3
|
import { dirname, resolve } from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { checkAgentAuthLifecycle } from './sdk-agent-auth-lifecycle-check.mjs';
|
|
5
6
|
import {
|
|
6
7
|
HubClient,
|
|
7
8
|
authzProbeResponse,
|
|
@@ -103,7 +104,7 @@ ok('PHP protected spec response is private/no-store', php.status === 0 && php.st
|
|
|
103
104
|
ok('PHP explicit public spec helper works', php.status === 0 && php.stdout.split('\n')[4] === 'public-helper', php.stderr || php.stdout);
|
|
104
105
|
ok('PHP legacy null-public signature remains compatible', php.status === 0 && php.stdout.split('\n')[5] === 'legacy-null', php.stderr || php.stdout);
|
|
105
106
|
|
|
106
|
-
const php7 = run('php', ['-r', `
|
|
107
|
+
const php7 = run(process.env.BAILING_SDK_PHP7_BINARY || 'php', ['-r', `
|
|
107
108
|
require '${root}/sdk/php7/src/Ticket.php';
|
|
108
109
|
require '${root}/sdk/php7/src/HubClient.php';
|
|
109
110
|
require '${root}/sdk/php7/src/AgentAuth.php';
|
|
@@ -176,7 +177,7 @@ let php7AgentAuth;
|
|
|
176
177
|
try {
|
|
177
178
|
const address = agentAuthServer.address();
|
|
178
179
|
const baseUrl = `http://127.0.0.1:${address.port}`;
|
|
179
|
-
php7AgentAuth = await runAsync('php', ['-r', `
|
|
180
|
+
php7AgentAuth = await runAsync(process.env.BAILING_SDK_PHP7_BINARY || 'php', ['-r', `
|
|
180
181
|
require '${root}/sdk/php7/src/HubClient.php';
|
|
181
182
|
require '${root}/sdk/php7/src/AgentAuth.php';
|
|
182
183
|
$authorizationId = '${authorizationId}';
|
|
@@ -261,6 +262,8 @@ ok('PHP7 HubClient does not follow a Bearer-authenticated redirect',
|
|
|
261
262
|
php7AgentAuthData?.redirect === 'HTTP 302'
|
|
262
263
|
&& !agentAuthRequests.some((request) => request.url === '/agent-auth-leak'));
|
|
263
264
|
|
|
265
|
+
await checkAgentAuthLifecycle({ root, runAsync, ok, closeServer });
|
|
266
|
+
|
|
264
267
|
console.log(`\n结果:通过 ${pass} / 失败 ${fail}`);
|
|
265
268
|
process.exit(fail ? 1 : 0);
|
|
266
269
|
|
|
@@ -129,6 +129,8 @@ const requiredFiles = [
|
|
|
129
129
|
'docs/RELEASE_NOTES_v0.3.4.md',
|
|
130
130
|
'docs/RELEASE_NOTES_v0.5.0.md',
|
|
131
131
|
'docs/RELEASE_NOTES_v0.5.1.md',
|
|
132
|
+
'docs/RELEASE_NOTES_v0.7.0.md',
|
|
133
|
+
'docs/RELEASE_NOTES_v0.8.0.md',
|
|
132
134
|
'docs/RELEASE_NOTES_v0.6.1.md',
|
|
133
135
|
'docs/RELEASE_NOTES_v0.6.0.md',
|
|
134
136
|
'docs/CHANGELOG.md',
|
package/sdk/php/README.md
CHANGED
|
@@ -221,6 +221,35 @@ $result = $agentAuth->approve(
|
|
|
221
221
|
|
|
222
222
|
`principal` 和 `on_behalf_of` 必须由业务后端从当前登录态生成,不得从前端表单原样透传。该协议只绑定业务身份、路由与设备会话,不承载套餐、付费或权益字段。
|
|
223
223
|
|
|
224
|
+
**Core 0.7.0 配套的生命周期接口**支持核对和收回现有授权。请同时升级本 SDK 下载包与 Core。业务后端可以先查询自己有权管理的租户,再按原授权记录撤销:
|
|
225
|
+
|
|
226
|
+
```php
|
|
227
|
+
$page = $agentAuth->listSessions(['tenant' => (string) $tenantId, 'limit' => 20]);
|
|
228
|
+
$session = $agentAuth->context($authorizationId)['session'] ?? null;
|
|
229
|
+
$revoked = $agentAuth->revokeAuthorization($authorizationId);
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
`listSessions()` 默认 20 条,最大 100;下一页原样保留筛选条件并传 `next_cursor`,返回 null 即结束。
|
|
233
|
+
按操作人筛选必须同时传 `principal_id` 与 `tenant`,无租户用 `tenant => ''`。分页反映当前状态,
|
|
234
|
+
不是跨请求快照。`session` 缺失/null 不可猜测;`active` 不保证业务账号仍有权限,过期按 refresh
|
|
235
|
+
生命周期判断。撤销可按同一授权 ID 幂等重试,503/超时或 consumed 映射缺失的 404 不代表成功。
|
|
236
|
+
Client Token 与管理权限判断均留在业务后端;字段规则见上方 Agent Auth 契约。
|
|
237
|
+
|
|
238
|
+
### 授权后显示业务名称
|
|
239
|
+
|
|
240
|
+
Core 0.7.0 支持批准授权时附上服务端读取的业务名称。原四参数调用保持兼容;第五参数可选,名称可用于门店、公司、项目等业务对象。
|
|
241
|
+
|
|
242
|
+
```php
|
|
243
|
+
$result = $agentAuth->approve($authorizationId, $principal, $onBehalfOf, $allowedRoutes, array('name' => $accountName));
|
|
244
|
+
$session = $agentAuth->updateSubjectDisplay($sessionId, array('name' => $accountName));
|
|
245
|
+
// 仅清除显示信息,不撤销或替换授权:
|
|
246
|
+
$session = $agentAuth->updateSubjectDisplay($sessionId, null);
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
名称由业务后端从真实记录读取,不参与身份或权限判断;更新只允许当前接入方自己的有效会话。
|
|
250
|
+
旧授权没有名称时显示待同步,不需要重新登录或重建连接。详见
|
|
251
|
+
[授权名称与三方职责](../../docs/AGENT_SUBJECT_DISPLAY.md)。
|
|
252
|
+
|
|
224
253
|
## CI 集成
|
|
225
254
|
|
|
226
255
|
```bash
|
|
@@ -28,12 +28,55 @@ final class AgentAuth
|
|
|
28
28
|
return $this->hub->get('/agent-auth/v1/authorizations/' . rawurlencode($authorizationId));
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* 查询当前接入方的授权会话;principal_id 必须同时指定 tenant。
|
|
33
|
+
* tenant='' 精确选择无租户主体,省略 tenant 则不按租户过滤。
|
|
34
|
+
*
|
|
35
|
+
* @param array{authorization_id?:string,on_behalf_of?:string,principal_id?:string,tenant?:string,state?:string,limit?:int,cursor?:string} $filters
|
|
36
|
+
* @return array<string,mixed>
|
|
37
|
+
*/
|
|
38
|
+
public function listSessions(array $filters = []): array
|
|
39
|
+
{
|
|
40
|
+
$allowed = ['authorization_id', 'on_behalf_of', 'principal_id', 'tenant', 'state', 'limit', 'cursor'];
|
|
41
|
+
foreach ($filters as $key => $value) {
|
|
42
|
+
if (!in_array($key, $allowed, true)) {
|
|
43
|
+
throw new InvalidArgumentException('未知会话筛选字段');
|
|
44
|
+
}
|
|
45
|
+
if ($key === 'authorization_id') {
|
|
46
|
+
if (!is_string($value) || !preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iD', $value)) {
|
|
47
|
+
throw new InvalidArgumentException('authorization_id 必须是 UUID');
|
|
48
|
+
}
|
|
49
|
+
} elseif (in_array($key, ['on_behalf_of', 'principal_id', 'tenant'], true)) {
|
|
50
|
+
self::assertFilterString($value, $key, $key === 'on_behalf_of' ? 191 : 128, $key === 'tenant');
|
|
51
|
+
} elseif ($key === 'state' && !in_array($value, ['active', 'expired', 'revoked'], true)) {
|
|
52
|
+
throw new InvalidArgumentException('state 必须是 active、expired 或 revoked');
|
|
53
|
+
} elseif ($key === 'limit' && (!is_int($value) || $value < 1 || $value > 100)) {
|
|
54
|
+
throw new InvalidArgumentException('limit 必须是 1 到 100 的整数');
|
|
55
|
+
} elseif ($key === 'cursor' && (!is_string($value) || strlen($value) > 2048 || !preg_match('/^[A-Za-z0-9_-]+$/D', $value))) {
|
|
56
|
+
throw new InvalidArgumentException('cursor 必须是非空、不带填充的 base64url 字符串,长度不超过 2048');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (array_key_exists('principal_id', $filters) && !array_key_exists('tenant', $filters)) {
|
|
60
|
+
throw new InvalidArgumentException('principal_id 必须同时指定 tenant');
|
|
61
|
+
}
|
|
62
|
+
$query = http_build_query($filters, '', '&', PHP_QUERY_RFC3986);
|
|
63
|
+
return $this->hub->get('/agent-auth/v1/sessions' . ($query === '' ? '' : '?' . $query));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @return array<string,mixed> */
|
|
67
|
+
public function revokeAuthorization(string $authorizationId): array
|
|
68
|
+
{
|
|
69
|
+
self::assertId($authorizationId, 'authorizationId');
|
|
70
|
+
return $this->hub->post('/agent-auth/v1/authorizations/' . rawurlencode($authorizationId) . '/revoke', []);
|
|
71
|
+
}
|
|
72
|
+
|
|
31
73
|
/**
|
|
32
74
|
* @param array{id:string,tenant?:string,roles?:array<int,string>,audience?:string,channel?:string} $principal
|
|
75
|
+
* @param array{name:string}|null $subjectDisplay Optional server-sourced display name; never an identity key.
|
|
33
76
|
* @param array<int,string> $allowedRoutes
|
|
34
77
|
* @return array<string,mixed>
|
|
35
78
|
*/
|
|
36
|
-
public function approve(string $authorizationId, array $principal, string $onBehalfOf, array $allowedRoutes): array
|
|
79
|
+
public function approve(string $authorizationId, array $principal, string $onBehalfOf, array $allowedRoutes, ?array $subjectDisplay = null): array
|
|
37
80
|
{
|
|
38
81
|
self::assertId($authorizationId, 'authorizationId');
|
|
39
82
|
if (!isset($principal['id']) || trim((string) $principal['id']) === '') {
|
|
@@ -48,11 +91,16 @@ final class AgentAuth
|
|
|
48
91
|
if (!isset($principal['roles'])) {
|
|
49
92
|
$principal['roles'] = [];
|
|
50
93
|
}
|
|
51
|
-
|
|
94
|
+
$body = [
|
|
52
95
|
'principal' => $principal,
|
|
53
96
|
'on_behalf_of' => $onBehalfOf,
|
|
54
97
|
'allowed_routes' => array_values($allowedRoutes),
|
|
55
|
-
]
|
|
98
|
+
];
|
|
99
|
+
// Existing four-argument calls keep their original HTTP shape for older Core versions.
|
|
100
|
+
if (func_num_args() >= 5) {
|
|
101
|
+
$body['subject_display'] = self::normalizeSubjectDisplay($subjectDisplay);
|
|
102
|
+
}
|
|
103
|
+
return $this->hub->post('/agent-auth/v1/authorizations/' . rawurlencode($authorizationId) . '/approve', $body);
|
|
56
104
|
}
|
|
57
105
|
|
|
58
106
|
/** @return array<string,mixed> */
|
|
@@ -69,10 +117,58 @@ final class AgentAuth
|
|
|
69
117
|
return $this->hub->post('/agent-auth/v1/sessions/' . rawurlencode($sessionId) . '/revoke', []);
|
|
70
118
|
}
|
|
71
119
|
|
|
120
|
+
/**
|
|
121
|
+
* 同步当前接入方已有有效授权的显示名称;不修改身份、权限或有效期。
|
|
122
|
+
* @param array{name:string}|null $subjectDisplay 业务服务端读取的名称,null 表示清除
|
|
123
|
+
* @return array
|
|
124
|
+
*/
|
|
125
|
+
public function updateSubjectDisplay(string $sessionId, ?array $subjectDisplay): array
|
|
126
|
+
{
|
|
127
|
+
self::assertId($sessionId, 'sessionId');
|
|
128
|
+
return $this->hub->request('PUT', '/agent-auth/v1/sessions/' . rawurlencode($sessionId) . '/subject-display', [
|
|
129
|
+
'subject_display' => self::normalizeSubjectDisplay($subjectDisplay),
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private static function normalizeSubjectDisplay(mixed $value): ?array
|
|
134
|
+
{
|
|
135
|
+
if ($value === null) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
if (!is_array($value) || array_keys($value) !== ['name'] || !is_string($value['name'])) {
|
|
139
|
+
throw new InvalidArgumentException('subjectDisplay 只能包含字符串 name');
|
|
140
|
+
}
|
|
141
|
+
$name = $value['name'];
|
|
142
|
+
// Reject controls before trimming; line breaks must not become a valid one-line name.
|
|
143
|
+
if (preg_match('//u', $name) !== 1 || preg_match('/[\x00-\x1f\x7f-\x9f\x{2028}\x{2029}]/u', $name)) {
|
|
144
|
+
throw new InvalidArgumentException('subjectDisplay.name 必须是无控制字符的单行文本');
|
|
145
|
+
}
|
|
146
|
+
$name = preg_replace('/^[\p{Z}\x{FEFF}]+|[\p{Z}\x{FEFF}]+$/u', '', $name);
|
|
147
|
+
self::assertFilterString($name, 'subjectDisplay.name', 120, false);
|
|
148
|
+
return ['name' => $name];
|
|
149
|
+
}
|
|
150
|
+
|
|
72
151
|
private static function assertId(string $value, string $name): void
|
|
73
152
|
{
|
|
74
|
-
if (!preg_match('/^[0-9a-f-]{
|
|
153
|
+
if (!preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iD', $value)) {
|
|
75
154
|
throw new InvalidArgumentException($name . ' 必须是 UUID');
|
|
76
155
|
}
|
|
77
156
|
}
|
|
157
|
+
|
|
158
|
+
private static function assertFilterString(mixed $value, string $name, int $max, bool $allowEmpty): void
|
|
159
|
+
{
|
|
160
|
+
if (!is_string($value) || (!$allowEmpty && $value === '') ||
|
|
161
|
+
preg_match('/[\x00-\x1f\x7f]|^[\p{Z}\x{FEFF}]|[\p{Z}\x{FEFF}]$/u', $value) ||
|
|
162
|
+
preg_match_all('/./us', $value, $characters) === false) {
|
|
163
|
+
throw new InvalidArgumentException($name . ' 必须是无首尾空白或控制字符的有效字符串');
|
|
164
|
+
}
|
|
165
|
+
// 与 HTTP 服务端的 UTF-16 长度一致,不依赖 mbstring 扩展。
|
|
166
|
+
$length = 0;
|
|
167
|
+
foreach ($characters[0] as $character) {
|
|
168
|
+
$length += strlen($character) > 3 ? 2 : 1;
|
|
169
|
+
}
|
|
170
|
+
if ($length > $max) {
|
|
171
|
+
throw new InvalidArgumentException($name . ' 长度超出限制');
|
|
172
|
+
}
|
|
173
|
+
}
|
|
78
174
|
}
|
|
@@ -90,7 +90,8 @@ final class HubClient
|
|
|
90
90
|
$headers = ['Authorization: Bearer ' . $this->token];
|
|
91
91
|
$content = '';
|
|
92
92
|
if ($body !== null) {
|
|
93
|
-
|
|
93
|
+
// Hub API 请求顶层是对象,空参数也发送 {}(例如 deny/revoke)。
|
|
94
|
+
$content = $body === [] ? '{}' : (json_encode($body, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?: '{}');
|
|
94
95
|
$headers[] = 'Content-Type: application/json';
|
|
95
96
|
}
|
|
96
97
|
$http = [
|