bailinghub 0.6.1 → 0.7.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 +9 -5
- package/README.md +8 -5
- 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.md +4 -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/CHANGELOG.en.md +14 -1
- package/docs/CHANGELOG.md +14 -1
- package/docs/INDEPENDENT_VALIDATION.en.md +4 -4
- package/docs/INDEPENDENT_VALIDATION.md +4 -4
- package/docs/LOCAL_AGENT_SETUP.en.md +116 -0
- package/docs/LOCAL_AGENT_SETUP.md +116 -0
- package/docs/README.en.md +6 -0
- package/docs/README.md +6 -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/SDK.en.md +31 -0
- package/docs/user-guide/conversations.en.md +4 -2
- package/docs/user-guide/conversations.md +4 -2
- package/package.json +1 -1
- package/schemas/config/route.schema.json +15 -2
- package/scripts/check-doc-links.mjs +1 -0
- package/scripts/check-image-tags.sh +1 -1
- package/scripts/check-release-consistency.test.mjs +2 -2
- package/scripts/install.sh +1 -1
- package/scripts/publish-images.sh +1 -1
- package/scripts/release-audit.mjs +1 -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 +1 -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/README.en.md +15 -0
- package/sql/README.md +25 -0
- package/src/app/agent-conversation-audit.ts +20 -0
- package/src/app/agent-system-info.ts +41 -0
- package/src/app/agent-tool-invocations.ts +16 -4
- package/src/core/config/agent-setup.ts +37 -0
- package/src/core/config/client-agent-setup.ts +25 -0
- 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 +43 -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/types.ts +15 -0
- package/src/core/runtime/agent-conversation-audit.test.ts +19 -1
- package/src/core/runtime/agent-conversation-audit.ts +39 -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-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-client-repository.ts +21 -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/configstore.ts +7 -3
- 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-client-agent-setup.test.ts +93 -0
- package/src/routes/admin-dispatch-config.ts +2 -0
- package/src/routes/agent-api.ts +7 -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/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/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-ChL9k-XA.js} +1 -1
- package/web/console/assets/AgentClients-Bs7UgVDj.js +1 -0
- package/web/console/assets/AgentClients-DkgPTEbq.css +1 -0
- package/web/console/assets/{Approvals-CMvPWacY.js → Approvals-Bs6FGbp2.js} +1 -1
- package/web/console/assets/{Audit-CIRqOCnL.js → Audit-4WWYhkFM.js} +1 -1
- package/web/console/assets/{BrandLockup-BrytmTTH.js → BrandLockup-D2GhCipL.js} +1 -1
- package/web/console/assets/{Channels-CApxH2TB.js → Channels-CmoGpiCJ.js} +1 -1
- package/web/console/assets/{ChatEntries-CJon3bWJ.js → ChatEntries-BFRMtwta.js} +1 -1
- package/web/console/assets/Clients-CSHIsaWU.css +1 -0
- package/web/console/assets/Clients-DGkkSXyA.js +3 -0
- package/web/console/assets/{Cost-BbhlQFP8.js → Cost-BmGt0MfS.js} +1 -1
- package/web/console/assets/{Credentials-kqr1W0K7.js → Credentials-CR-sYINT.js} +1 -1
- package/web/console/assets/{Diagnostics-Kljt9XTH.js → Diagnostics-DAPbKSJp.js} +1 -1
- package/web/console/assets/{Executors-DnsB-Xz4.js → Executors-CgpiT3o8.js} +1 -1
- package/web/console/assets/{Kb-DLZSAFWP.js → Kb-Cm9dVSQw.js} +1 -1
- package/web/console/assets/{Login-DiTjPWmN.js → Login-CyUcsTZ_.js} +1 -1
- package/web/console/assets/{Projects-CXcVCgCD.js → Projects-DldFPgWg.js} +1 -1
- package/web/console/assets/Routes-DkMIjMQA.css +1 -0
- package/web/console/assets/Routes-DubfjlBD.js +124 -0
- package/web/console/assets/Runs-1hxgkuR4.js +3 -0
- package/web/console/assets/Runs-CvGTV8I-.css +1 -0
- package/web/console/assets/{Setup-FqoCKmfZ.js → Setup-DBLOnI2_.js} +1 -1
- package/web/console/assets/{Shell-BEqpONiy.js → Shell-gJ5Vz_E7.js} +1 -1
- package/web/console/assets/{StorageBuckets-CkORbYXY.js → StorageBuckets-DkDW16tj.js} +1 -1
- package/web/console/assets/{SystemSettings-gTQAazu7.js → SystemSettings-cDkudo2y.js} +1 -1
- package/web/console/assets/{SystemStatus-DAmUUNqO.js → SystemStatus-DZd6s8OX.js} +1 -1
- package/web/console/assets/{Targets-CZmDcjsE.js → Targets-DYNGq1NU.js} +1 -1
- package/web/console/assets/{Tools-CIHInlHL.js → Tools-DpWM59vV.js} +1 -1
- package/web/console/assets/{index-BkLbd7Cc.js → index-DGqs28gI.js} +2 -2
- package/web/console/assets/{request-r7GHVJzw.js → request-B7MLvOqo.js} +1 -1
- package/web/console/assets/{schema-BVn_hB7M.js → schema-CMuwjYdJ.js} +1 -1
- package/web/console/index.html +1 -1
- package/web-admin/scripts/subject-display-ui.mjs +78 -0
- package/web-admin/src/components/AgentSetupPanel.vue +262 -0
- package/web-admin/src/components/ClientConversations.vue +21 -4
- package/web-admin/src/components/conversation-audit.ts +20 -0
- package/web-admin/src/pages/AgentClients.vue +97 -23
- package/web-admin/src/pages/Clients.vue +4 -1
- package/web-admin/src/pages/Routes.vue +10 -1
- 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
|
@@ -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,7 @@ 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',
|
|
132
133
|
'docs/RELEASE_NOTES_v0.6.1.md',
|
|
133
134
|
'docs/RELEASE_NOTES_v0.6.0.md',
|
|
134
135
|
'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 = [
|
package/sdk/php7/README.md
CHANGED
|
@@ -215,6 +215,37 @@ $result = $agentAuth->approve(
|
|
|
215
215
|
|
|
216
216
|
完整关系与 HTTP 契约见中枢文档 `docs/AGENT_CLIENT_QUICKSTART.md` 和 `docs/AGENT_AUTH_API.md`。
|
|
217
217
|
|
|
218
|
+
**Core 0.7.0 配套的生命周期接口**支持核对和收回现有授权。请同时升级本 SDK 下载包与 Core。PHP 7.3 版与 PHP 8.1+ 版方法和语义一致:
|
|
219
|
+
|
|
220
|
+
```php
|
|
221
|
+
$page = $agentAuth->listSessions(array('tenant' => (string) $tenantId, 'limit' => 20));
|
|
222
|
+
$context = $agentAuth->context($authorizationId);
|
|
223
|
+
$session = isset($context['session']) ? $context['session'] : null;
|
|
224
|
+
$revoked = $agentAuth->revokeAuthorization($authorizationId);
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
默认每页 20 条、最大 100;下一页保留全部筛选条件并传 `next_cursor`,null 表示结束。按操作人
|
|
228
|
+
筛选必须同时传 `principal_id` 与 `tenant`,无租户用 `tenant => ''`。分页反映当前状态,不是跨请求
|
|
229
|
+
快照。`session` 缺失/null 不可猜测;`active` 不保证业务账号仍有权限,过期按 refresh 生命周期判断。
|
|
230
|
+
撤销同一授权可幂等重试,503/超时或 consumed 映射缺失的 404 不代表成功。后端先确认管理权限,
|
|
231
|
+
再调用这些方法;Client Token 不进入浏览器。完整字段见
|
|
232
|
+
[Agent Auth v1](../../docs/AGENT_AUTH_API.md)。
|
|
233
|
+
|
|
234
|
+
### 授权后显示业务名称
|
|
235
|
+
|
|
236
|
+
Core 0.7.0 支持批准授权时附上服务端读取的业务名称。原四参数调用保持兼容;第五参数可选,名称可用于门店、公司、项目等业务对象。
|
|
237
|
+
|
|
238
|
+
```php
|
|
239
|
+
$result = $agentAuth->approve($authorizationId, $principal, $onBehalfOf, $allowedRoutes, array('name' => $accountName));
|
|
240
|
+
$session = $agentAuth->updateSubjectDisplay($sessionId, array('name' => $accountName));
|
|
241
|
+
// 仅清除显示信息,不撤销或替换授权:
|
|
242
|
+
$session = $agentAuth->updateSubjectDisplay($sessionId, null);
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
名称由业务后端从真实记录读取,不参与身份或权限判断;更新只允许当前接入方自己的有效会话。
|
|
246
|
+
旧授权没有名称时显示待同步,不需要重新登录或重建连接。详见
|
|
247
|
+
[授权名称与三方职责](../../docs/AGENT_SUBJECT_DISPLAY.md)。
|
|
248
|
+
|
|
218
249
|
## 范例
|
|
219
250
|
|
|
220
251
|
- `examples/build-spec.php`:完整 builder 范例(覆盖全部字段;与 8.x 版同源,跑同一个跨语言契约测试)
|
|
@@ -27,12 +27,54 @@ final class AgentAuth
|
|
|
27
27
|
return $this->hub->get('/agent-auth/v1/authorizations/' . rawurlencode($authorizationId));
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* 查询当前接入方的授权会话;principal_id 必须同时指定 tenant。
|
|
32
|
+
* tenant='' 精确选择无租户主体,省略 tenant 则不按租户过滤。
|
|
33
|
+
* @param array $filters authorization_id/on_behalf_of/principal_id/tenant/state/limit/cursor
|
|
34
|
+
* @return array
|
|
35
|
+
*/
|
|
36
|
+
public function listSessions(array $filters = array())
|
|
37
|
+
{
|
|
38
|
+
$allowed = array('authorization_id', 'on_behalf_of', 'principal_id', 'tenant', 'state', 'limit', 'cursor');
|
|
39
|
+
foreach ($filters as $key => $value) {
|
|
40
|
+
if (!in_array($key, $allowed, true)) {
|
|
41
|
+
throw new InvalidArgumentException('未知会话筛选字段');
|
|
42
|
+
}
|
|
43
|
+
if ($key === 'authorization_id') {
|
|
44
|
+
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)) {
|
|
45
|
+
throw new InvalidArgumentException('authorization_id 必须是 UUID');
|
|
46
|
+
}
|
|
47
|
+
} elseif (in_array($key, array('on_behalf_of', 'principal_id', 'tenant'), true)) {
|
|
48
|
+
self::assertFilterString($value, $key, $key === 'on_behalf_of' ? 191 : 128, $key === 'tenant');
|
|
49
|
+
} elseif ($key === 'state' && !in_array($value, array('active', 'expired', 'revoked'), true)) {
|
|
50
|
+
throw new InvalidArgumentException('state 必须是 active、expired 或 revoked');
|
|
51
|
+
} elseif ($key === 'limit' && (!is_int($value) || $value < 1 || $value > 100)) {
|
|
52
|
+
throw new InvalidArgumentException('limit 必须是 1 到 100 的整数');
|
|
53
|
+
} elseif ($key === 'cursor' && (!is_string($value) || strlen($value) > 2048 || !preg_match('/^[A-Za-z0-9_-]+$/D', $value))) {
|
|
54
|
+
throw new InvalidArgumentException('cursor 必须是非空、不带填充的 base64url 字符串,长度不超过 2048');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (array_key_exists('principal_id', $filters) && !array_key_exists('tenant', $filters)) {
|
|
58
|
+
throw new InvalidArgumentException('principal_id 必须同时指定 tenant');
|
|
59
|
+
}
|
|
60
|
+
$query = http_build_query($filters, '', '&', PHP_QUERY_RFC3986);
|
|
61
|
+
return $this->hub->get('/agent-auth/v1/sessions' . ($query === '' ? '' : '?' . $query));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** @return array */
|
|
65
|
+
public function revokeAuthorization($authorizationId)
|
|
66
|
+
{
|
|
67
|
+
self::assertId($authorizationId, 'authorizationId');
|
|
68
|
+
return $this->hub->post('/agent-auth/v1/authorizations/' . rawurlencode($authorizationId) . '/revoke', array());
|
|
69
|
+
}
|
|
70
|
+
|
|
30
71
|
/**
|
|
31
72
|
* @param array $principal 业务后端从当前登录态推导的主体,必须包含 id
|
|
32
73
|
* @param array $allowedRoutes 本次授权允许的路由标识
|
|
74
|
+
* @param array|null $subjectDisplay 业务服务端提供的显示名称,不参与身份判定
|
|
33
75
|
* @return array
|
|
34
76
|
*/
|
|
35
|
-
public function approve($authorizationId, array $principal, $onBehalfOf, array $allowedRoutes)
|
|
77
|
+
public function approve($authorizationId, array $principal, $onBehalfOf, array $allowedRoutes, $subjectDisplay = null)
|
|
36
78
|
{
|
|
37
79
|
self::assertId($authorizationId, 'authorizationId');
|
|
38
80
|
if (!isset($principal['id']) || trim((string) $principal['id']) === '') {
|
|
@@ -47,11 +89,16 @@ final class AgentAuth
|
|
|
47
89
|
if (!isset($principal['roles'])) {
|
|
48
90
|
$principal['roles'] = array();
|
|
49
91
|
}
|
|
50
|
-
|
|
92
|
+
$body = array(
|
|
51
93
|
'principal' => $principal,
|
|
52
94
|
'on_behalf_of' => $onBehalfOf,
|
|
53
95
|
'allowed_routes' => array_values($allowedRoutes),
|
|
54
|
-
)
|
|
96
|
+
);
|
|
97
|
+
// Existing four-argument calls keep their original HTTP shape for older Core versions.
|
|
98
|
+
if (func_num_args() >= 5) {
|
|
99
|
+
$body['subject_display'] = self::normalizeSubjectDisplay($subjectDisplay);
|
|
100
|
+
}
|
|
101
|
+
return $this->hub->post('/agent-auth/v1/authorizations/' . rawurlencode($authorizationId) . '/approve', $body);
|
|
55
102
|
}
|
|
56
103
|
|
|
57
104
|
/** @return array */
|
|
@@ -68,10 +115,58 @@ final class AgentAuth
|
|
|
68
115
|
return $this->hub->post('/agent-auth/v1/sessions/' . rawurlencode($sessionId) . '/revoke', array());
|
|
69
116
|
}
|
|
70
117
|
|
|
118
|
+
/**
|
|
119
|
+
* 同步当前接入方已有有效授权的显示名称;不修改身份、权限或有效期。
|
|
120
|
+
* @param array{name:string}|null $subjectDisplay 业务服务端读取的名称,null 表示清除
|
|
121
|
+
* @return array
|
|
122
|
+
*/
|
|
123
|
+
public function updateSubjectDisplay($sessionId, $subjectDisplay)
|
|
124
|
+
{
|
|
125
|
+
self::assertId($sessionId, 'sessionId');
|
|
126
|
+
return $this->hub->request('PUT', '/agent-auth/v1/sessions/' . rawurlencode($sessionId) . '/subject-display', array(
|
|
127
|
+
'subject_display' => self::normalizeSubjectDisplay($subjectDisplay),
|
|
128
|
+
));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private static function normalizeSubjectDisplay($value)
|
|
132
|
+
{
|
|
133
|
+
if ($value === null) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
if (!is_array($value) || array_keys($value) !== array('name') || !is_string($value['name'])) {
|
|
137
|
+
throw new InvalidArgumentException('subjectDisplay 只能包含字符串 name');
|
|
138
|
+
}
|
|
139
|
+
$name = $value['name'];
|
|
140
|
+
// Reject controls before trimming; line breaks must not become a valid one-line name.
|
|
141
|
+
if (preg_match('//u', $name) !== 1 || preg_match('/[\x00-\x1f\x7f-\x9f\x{2028}\x{2029}]/u', $name)) {
|
|
142
|
+
throw new InvalidArgumentException('subjectDisplay.name 必须是无控制字符的单行文本');
|
|
143
|
+
}
|
|
144
|
+
$name = preg_replace('/^[\p{Z}\x{FEFF}]+|[\p{Z}\x{FEFF}]+$/u', '', $name);
|
|
145
|
+
self::assertFilterString($name, 'subjectDisplay.name', 120, false);
|
|
146
|
+
return array('name' => $name);
|
|
147
|
+
}
|
|
148
|
+
|
|
71
149
|
private static function assertId($value, $name)
|
|
72
150
|
{
|
|
73
|
-
if (!is_string($value) || !preg_match('/^[0-9a-f-]{
|
|
151
|
+
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)) {
|
|
74
152
|
throw new InvalidArgumentException($name . ' 必须是 UUID');
|
|
75
153
|
}
|
|
76
154
|
}
|
|
155
|
+
|
|
156
|
+
private static function assertFilterString($value, $name, $max, $allowEmpty)
|
|
157
|
+
{
|
|
158
|
+
if (!is_string($value) || (!$allowEmpty && $value === '') ||
|
|
159
|
+
preg_match('/[\x00-\x1f\x7f]|^[\p{Z}\x{FEFF}]|[\p{Z}\x{FEFF}]$/u', $value) ||
|
|
160
|
+
preg_match_all('/./us', $value, $characters) === false) {
|
|
161
|
+
throw new InvalidArgumentException($name . ' 必须是无首尾空白或控制字符的有效字符串');
|
|
162
|
+
}
|
|
163
|
+
// 与 HTTP 服务端的 UTF-16 长度一致,不依赖 mbstring 扩展。
|
|
164
|
+
$length = 0;
|
|
165
|
+
foreach ($characters[0] as $character) {
|
|
166
|
+
$length += strlen($character) > 3 ? 2 : 1;
|
|
167
|
+
}
|
|
168
|
+
if ($length > $max) {
|
|
169
|
+
throw new InvalidArgumentException($name . ' 长度超出限制');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
77
172
|
}
|
|
@@ -74,7 +74,8 @@ final class HubClient
|
|
|
74
74
|
$headers = array('Authorization: Bearer ' . $this->token);
|
|
75
75
|
$content = '';
|
|
76
76
|
if ($body !== null) {
|
|
77
|
-
|
|
77
|
+
// Hub API 请求顶层是对象,空参数也发送 {}(例如 deny/revoke)。
|
|
78
|
+
$content = $body === array() ? '{}' : json_encode($body, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
78
79
|
if ($content === false) {
|
|
79
80
|
$content = '{}';
|
|
80
81
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- Additive opt-in for cross-client/route audit membership. Legacy v1 rows keep
|
|
2
|
+
-- their original single binding; no Session, run, invocation or text is moved.
|
|
3
|
+
ALTER TABLE `bz_agent_conversation_audits` ADD COLUMN `membership_version` TINYINT UNSIGNED NOT NULL DEFAULT 1 COMMENT '1=legacy common binding, 2=explicit per-member binding';
|
|
4
|
+
|
|
5
|
+
ALTER TABLE `bz_agent_conversation_members` ADD COLUMN `client_app_id` VARCHAR(64) DEFAULT NULL COMMENT 'Frozen original Client App, NULL for legacy v1';
|
|
6
|
+
|
|
7
|
+
ALTER TABLE `bz_agent_conversation_members` ADD COLUMN `route_key` VARCHAR(64) DEFAULT NULL COMMENT 'Frozen original route/workspace, NULL for legacy v1';
|
|
8
|
+
|
|
9
|
+
ALTER TABLE `bz_agent_conversation_members` ADD COLUMN `client_name` VARCHAR(128) DEFAULT NULL COMMENT 'Display snapshot only, never identity or authorization';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
-- Optional business-supplied display metadata. Existing authorizations remain
|
|
2
|
+
-- unnamed; no inference from device labels, identities, route names or history.
|
|
3
|
+
ALTER TABLE `bz_agent_authorizations` ADD COLUMN `subject_display` JSON DEFAULT NULL COMMENT 'Business subject display only, never an authorization identity';
|
|
4
|
+
|
|
5
|
+
ALTER TABLE `bz_agent_sessions` ADD COLUMN `subject_display` JSON DEFAULT NULL COMMENT 'Current business subject display, independent of frozen audit labels';
|
package/sql/README.en.md
CHANGED
|
@@ -18,6 +18,21 @@ A small immutable catalog records the filename, original byte checksum, and leng
|
|
|
18
18
|
|
|
19
19
|
Duplicate-column or duplicate-index errors are tolerated only when the live object exactly matches the official `ADD COLUMN` or `ADD INDEX` statement. Other SQL errors remain fatal.
|
|
20
20
|
|
|
21
|
+
## Unreleased candidate: 059 authorization subject display
|
|
22
|
+
|
|
23
|
+
`059_agent_subject_display.sql` adds one nullable JSON column named `subject_display`,
|
|
24
|
+
with a NULL default, to each of `bz_agent_authorizations` and `bz_agent_sessions`.
|
|
25
|
+
Existing rows stay NULL (name pending sync); device names, local aliases and identity
|
|
26
|
+
values are not used to invent names. No principal, scope, credential, Session or
|
|
27
|
+
archive record is rewritten. Business backends can later name the original session
|
|
28
|
+
through the [authorization name API](../docs/AGENT_SUBJECT_DISPLAY.en.md).
|
|
29
|
+
|
|
30
|
+
Explicitly apply 059 through the existing migration entry point before starting this
|
|
31
|
+
candidate runtime. Custom Hosts must package the official SQL and implement the optional
|
|
32
|
+
display-update repository method. An older Host explicitly reports unavailable for
|
|
33
|
+
new naming operations while accepting the original approval request without a name.
|
|
34
|
+
These candidate files do not indicate that a deployment or migration has occurred.
|
|
35
|
+
|
|
21
36
|
## Migration Rules
|
|
22
37
|
|
|
23
38
|
Schema files are part of the deployment safety boundary.
|
package/sql/README.md
CHANGED
|
@@ -16,6 +16,31 @@ npm run db:init # 按文件名顺序应用所有未应用的结构文件
|
|
|
16
16
|
- **错误码容错兜底**:`IF NOT EXISTS` 自身幂等;加列/索引遇到 1060/1061 时,只有实际列/索引结构与官方语句一致才按已完成处理,跑完即记账,此后走账本快路径。
|
|
17
17
|
- **失败关闭**:账本出现既不属于活动序列、也不属于固化退役证据的文件,或者任一已记账摘要不匹配时,会在补录摘要或执行新迁移前拒绝继续。
|
|
18
18
|
|
|
19
|
+
## 未发布候选:058 跨系统归档成员绑定
|
|
20
|
+
|
|
21
|
+
`058_agent_conversation_member_bindings.sql` 是尚未发布的增量候选,只给已有归档增加
|
|
22
|
+
`membership_version`(默认 1),给成员增加 `client_app_id`、`route_key`、`client_name`(默认 NULL)。
|
|
23
|
+
057 保持原样;已应用 057 的实例不重复建表,也不回填或移动 Session、run、invocation、正文和旧成员身份。
|
|
24
|
+
旧记录按 v1 的共同绑定解释,NULL 不能冒充逐成员系统或路由证据。
|
|
25
|
+
|
|
26
|
+
Host 需把官方 SQL 一起打包,并通过现有迁移入口显式执行;运行时启动不自动迁移。
|
|
27
|
+
沿用上述迁移账本、摘要及结构核对,不引入另一套迁移引擎。仅有 057、缺少任一 058 新列,
|
|
28
|
+
或旧 Host 未实现可选跨绑定仓储方法时,能力探测不能返回跨绑定支持;旧 v1 功能保持兼容。
|
|
29
|
+
跨系统只在同一 Hub 和同一 Host 数据域内组合独立授权,不能跨租户拼库。
|
|
30
|
+
完整候选协议见 [Agent 对话审计](../docs/AGENT_CONVERSATION_AUDIT.md#未发布候选跨系统成员绑定)。
|
|
31
|
+
|
|
32
|
+
## 未发布候选:059 授权主体展示信息
|
|
33
|
+
|
|
34
|
+
`059_agent_subject_display.sql` 给 `bz_agent_authorizations` 和 `bz_agent_sessions`
|
|
35
|
+
各增加一个可空、默认 NULL 的 JSON 列 `subject_display`,独立保存授权主体的展示名称。
|
|
36
|
+
旧记录保留 NULL,表示名称待同步;不从设备名、用户备注或身份标识推断名称。
|
|
37
|
+
不改写 principal、授权范围、凭据、Session 或归档记录。业务后端以后可通过
|
|
38
|
+
[授权名称接口](../docs/AGENT_SUBJECT_DISPLAY.md) 为原会话补名。
|
|
39
|
+
|
|
40
|
+
升级到此候选运行时前,先通过现有迁移入口显式应用 059;自定义 Host 也需打包官方 SQL,
|
|
41
|
+
并实现可选的名称更新仓储方法。旧 Host 不支持新命名操作时明确返回 unavailable,
|
|
42
|
+
仍可使用原不带名称的授权请求。此目录提供候选结构,不代表已经部署或执行迁移。
|
|
43
|
+
|
|
19
44
|
## 写结构文件的铁律
|
|
20
45
|
|
|
21
46
|
结构文件是部署方数据安全的边界。守住这三条,发布后的结构同步才可预期。
|
|
@@ -3,6 +3,8 @@ import type { AgentToolAuthContext } from './agent-tool-invocations';
|
|
|
3
3
|
import {
|
|
4
4
|
auditUuid, parseCreateConversationAudit, parseConversationAuditEvents, ConversationAuditError,
|
|
5
5
|
CONVERSATION_AUDIT_SCHEMA, CONVERSATION_AUDIT_ACK_SCHEMA,
|
|
6
|
+
CONVERSATION_AUDIT_CREATE_V2_SCHEMA, CONVERSATION_AUDIT_CAPABILITIES_SCHEMA,
|
|
7
|
+
CONVERSATION_AUDIT_MEMBER_BINDINGS, parseCreateCrossBindingConversationAudit,
|
|
6
8
|
} from '../core/runtime/agent-conversation-audit';
|
|
7
9
|
|
|
8
10
|
function repository(configStore: ConfigStoreContract | null) {
|
|
@@ -13,10 +15,28 @@ function repository(configStore: ConfigStoreContract | null) {
|
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export async function createConversationAuditFor(store: ConfigStoreContract | null, auth: AgentToolAuthContext, body: unknown) {
|
|
18
|
+
if (body && typeof body === 'object' && 'schema' in body && body.schema === CONVERSATION_AUDIT_CREATE_V2_SCHEMA) {
|
|
19
|
+
const input = parseCreateCrossBindingConversationAudit(body);
|
|
20
|
+
const repo = repository(store);
|
|
21
|
+
if (typeof repo.createCrossBinding !== 'function' || typeof repo.supportsCrossBindingMembers !== 'function' ||
|
|
22
|
+
await repo.supportsCrossBindingMembers() !== true) {
|
|
23
|
+
throw new ConversationAuditError(503, 'conversation_audit_cross_binding_unavailable', 'Cross-binding conversation audit storage is unavailable.');
|
|
24
|
+
}
|
|
25
|
+
return { schema: CONVERSATION_AUDIT_SCHEMA, ...await repo.createCrossBinding(auth, input) };
|
|
26
|
+
}
|
|
16
27
|
const input = parseCreateConversationAudit(body);
|
|
17
28
|
return { schema: CONVERSATION_AUDIT_SCHEMA, ...await repository(store).create(auth, input) };
|
|
18
29
|
}
|
|
19
30
|
|
|
31
|
+
/** No sessions, account names, identifiers or transcript data are discovered here. */
|
|
32
|
+
export async function conversationAuditCapabilitiesFor(store: ConfigStoreContract | null) {
|
|
33
|
+
const repo = store?.agentConversationAudit;
|
|
34
|
+
const supported = typeof repo?.createCrossBinding === 'function' && typeof repo.supportsCrossBindingMembers === 'function' &&
|
|
35
|
+
await repo.supportsCrossBindingMembers() === true;
|
|
36
|
+
return { schema: CONVERSATION_AUDIT_CAPABILITIES_SCHEMA,
|
|
37
|
+
cross_binding_members: supported, member_bindings: CONVERSATION_AUDIT_MEMBER_BINDINGS };
|
|
38
|
+
}
|
|
39
|
+
|
|
20
40
|
export async function confirmConversationAuditFor(store: ConfigStoreContract | null, auth: AgentToolAuthContext, id: string, body: unknown) {
|
|
21
41
|
if (!body || typeof body !== 'object' || Array.isArray(body) || Object.keys(body).length) {
|
|
22
42
|
throw new ConversationAuditError(400, 'invalid_request', 'Member confirmation requires an empty object; identity comes from the bearer.');
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import type { AgentSystemInfo } from '../core/contracts/types';
|
|
3
|
+
import { routeAgentClientConfig, routeAgentSystemInfo } from '../core/config/route-config';
|
|
4
|
+
import { agentDirectToolsConfig } from '../core/config/tools-config';
|
|
5
|
+
import type { ConfigStoreContract } from '../infrastructure/config/configstore';
|
|
6
|
+
import { resolveAgentRouteFor, type AgentToolAuthContext } from './agent-tool-invocations';
|
|
7
|
+
|
|
8
|
+
export const AGENT_SYSTEM_INFO_SCHEMA = 'bailing.agent-system-info.v1';
|
|
9
|
+
|
|
10
|
+
export interface AgentSystemInfoResponse {
|
|
11
|
+
schema_version: typeof AGENT_SYSTEM_INFO_SCHEMA;
|
|
12
|
+
binding: { client_app_id: string; session_id: string; workspace: string };
|
|
13
|
+
metadata_status: 'configured' | 'missing';
|
|
14
|
+
revision: string | null;
|
|
15
|
+
system: AgentSystemInfo | null;
|
|
16
|
+
tool_status: 'not_loaded';
|
|
17
|
+
availability: 'unknown' | 'unavailable';
|
|
18
|
+
unavailable_reason?: 'agent_client_disabled' | 'agent_direct_disabled';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Read only the selected route's product description; no tool, context or run services are used. */
|
|
22
|
+
export async function getAgentSystemInfoFor(
|
|
23
|
+
configStore: ConfigStoreContract | null,
|
|
24
|
+
auth: AgentToolAuthContext,
|
|
25
|
+
workspace: string,
|
|
26
|
+
): Promise<AgentSystemInfoResponse> {
|
|
27
|
+
const route = await resolveAgentRouteFor({ configStore }, auth, workspace);
|
|
28
|
+
const system = routeAgentSystemInfo(route);
|
|
29
|
+
const unavailableReason = !routeAgentClientConfig(route) ? 'agent_client_disabled'
|
|
30
|
+
: !agentDirectToolsConfig(route.tools) ? 'agent_direct_disabled' : undefined;
|
|
31
|
+
return {
|
|
32
|
+
schema_version: AGENT_SYSTEM_INFO_SCHEMA,
|
|
33
|
+
binding: { client_app_id: auth.client.app_id, session_id: auth.session.session_id, workspace: route.route_key },
|
|
34
|
+
metadata_status: system ? 'configured' : 'missing',
|
|
35
|
+
revision: system ? createHash('sha256').update(JSON.stringify({ schema_version: AGENT_SYSTEM_INFO_SCHEMA, system })).digest('hex') : null,
|
|
36
|
+
system,
|
|
37
|
+
tool_status: 'not_loaded',
|
|
38
|
+
availability: unavailableReason ? 'unavailable' : 'unknown',
|
|
39
|
+
...(unavailableReason ? { unavailable_reason: unavailableReason } : {}),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -295,16 +295,24 @@ function probeJob(auth: AgentToolAuthContext, route: Route, now: string): Job {
|
|
|
295
295
|
};
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
-
|
|
298
|
+
/** Shared identity/route boundary. Metadata reads do not require the direct-tool switch. */
|
|
299
|
+
export async function resolveAgentRouteFor(
|
|
300
|
+
deps: Pick<ToolProxyDeps, 'configStore'>,
|
|
301
|
+
auth: AgentToolAuthContext,
|
|
302
|
+
routeKey: string,
|
|
303
|
+
options: { requireDirectTools?: boolean } = {},
|
|
304
|
+
): Promise<Route> {
|
|
299
305
|
if (!deps.configStore) throw new AgentToolApiError(503, 'agent_tools_unavailable', 'Agent tools require the MySQL control plane.');
|
|
300
306
|
if (!ROUTE_RE.test(routeKey) || routeKey === 'auto') throw new AgentToolApiError(400, 'invalid_route', 'The configured route is invalid.');
|
|
301
|
-
if (!clientAllowsRoute(auth.client, routeKey) || !sessionAllowsRoute(auth.session, routeKey)) {
|
|
307
|
+
if (auth.session.client_app_id !== auth.client.app_id || !clientAllowsRoute(auth.client, routeKey) || !sessionAllowsRoute(auth.session, routeKey)) {
|
|
302
308
|
throw new AgentToolApiError(403, 'route_not_allowed', 'The Agent Session is not allowed to use this route.');
|
|
303
309
|
}
|
|
304
310
|
const route = await deps.configStore.routes.get(routeKey);
|
|
305
311
|
if (!route?.enabled) throw new AgentToolApiError(404, 'route_unavailable', 'The configured route is unavailable.');
|
|
306
|
-
|
|
307
|
-
if (
|
|
312
|
+
// Keep the existing direct-tool rejection order before audience evaluation.
|
|
313
|
+
if (options.requireDirectTools && !agentDirectToolsConfig(route.tools)) {
|
|
314
|
+
throw new AgentToolApiError(403, 'agent_direct_disabled', 'Direct Agent tools are not enabled for this route.');
|
|
315
|
+
}
|
|
308
316
|
const principal = {
|
|
309
317
|
...auth.session.principal,
|
|
310
318
|
roles: [...auth.session.principal.roles],
|
|
@@ -316,6 +324,10 @@ async function resolveDirectRoute(deps: ToolProxyDeps, auth: AgentToolAuthContex
|
|
|
316
324
|
return route;
|
|
317
325
|
}
|
|
318
326
|
|
|
327
|
+
async function resolveDirectRoute(deps: ToolProxyDeps, auth: AgentToolAuthContext, routeKey: string): Promise<Route> {
|
|
328
|
+
return resolveAgentRouteFor(deps, auth, routeKey, { requireDirectTools: true });
|
|
329
|
+
}
|
|
330
|
+
|
|
319
331
|
async function resolveSurface(deps: ToolProxyDeps, auth: AgentToolAuthContext, routeKey: string): Promise<AgentToolSurface> {
|
|
320
332
|
const route = await resolveDirectRoute(deps, auth, routeKey);
|
|
321
333
|
const direct = agentDirectToolsConfig(route.tools)!;
|