bailinghub 0.3.4 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitignore +5 -0
- package/README.en.md +6 -1
- package/README.md +6 -0
- package/SECURITY.md +11 -0
- package/docker-compose.images.yml +2 -2
- package/docs/AGENT_AUTH_API.en.md +175 -0
- package/docs/AGENT_AUTH_API.md +190 -0
- package/docs/AGENT_CLIENT_QUICKSTART.en.md +212 -0
- package/docs/AGENT_CLIENT_QUICKSTART.md +206 -0
- package/docs/AGENT_CLIENT_RUNTIME_API.en.md +157 -0
- package/docs/AGENT_CLIENT_RUNTIME_API.md +107 -0
- package/docs/CHANGELOG.en.md +59 -1
- package/docs/CHANGELOG.md +27 -1
- package/docs/COMPATIBILITY.en.md +25 -0
- package/docs/CONTRACT.en.md +79 -8
- package/docs/CONTRACT.md +36 -6
- package/docs/INDEPENDENT_VALIDATION.en.md +4 -4
- package/docs/INDEPENDENT_VALIDATION.md +4 -4
- package/docs/QUICKSTART.en.md +6 -0
- package/docs/QUICKSTART.md +1 -1
- package/docs/README.en.md +8 -0
- package/docs/README.md +8 -0
- package/docs/RELEASE_NOTES_v0.4.0.en.md +39 -0
- package/docs/RELEASE_NOTES_v0.4.0.md +39 -0
- package/docs/RELEASE_NOTES_v0.5.0.en.md +41 -0
- package/docs/RELEASE_NOTES_v0.5.0.md +41 -0
- package/docs/STREAMING.en.md +32 -0
- package/docs/STREAMING.md +8 -2
- package/docs/WIDGET_RENDERERS.en.md +123 -6
- package/docs/WIDGET_RENDERERS.md +75 -6
- package/docs/user-guide/console-map.en.md +1 -2
- package/docs/user-guide/console-map.md +2 -2
- package/docs//345/205/274/345/256/271/346/200/247/344/270/216/345/215/207/347/272/247.md +9 -0
- package/package.json +3 -2
- package/schemas/config/chat-entry.schema.json +2 -1
- package/schemas/config/client.schema.json +7 -0
- package/schemas/config/common.schema.json +30 -0
- package/schemas/config/route.schema.json +11 -0
- package/scripts/check-doc-links.mjs +1 -0
- package/scripts/check-image-tags.sh +1 -1
- package/scripts/check-release-consistency.test.mjs +5 -5
- package/scripts/e2e-console.mjs +144 -0
- package/scripts/export-oss.mjs +5 -12
- package/scripts/install.sh +1 -1
- package/scripts/public-content-denylist.mjs +82 -0
- package/scripts/public-content-denylist.test.mjs +53 -0
- package/scripts/publish-images.sh +1 -1
- package/scripts/release-audit.mjs +8 -12
- package/scripts/sdk-runtime-test.mjs +171 -7
- package/scripts/security-scan.mjs +8 -5
- package/scripts/validate-examples.mjs +3 -1
- package/scripts/verify-github-repo.mjs +7 -11
- package/scripts/verify-oss-export.mjs +6 -12
- package/scripts/widget-renderer-test.mjs +244 -16
- package/sdk/php/README.md +27 -1
- package/sdk/php/src/AgentAuth.php +78 -0
- package/sdk/php/src/HubClient.php +3 -0
- package/sdk/php7/README.md +32 -2
- package/sdk/php7/src/AgentAuth.php +77 -0
- package/sdk/php7/src/HubClient.php +3 -0
- package/sql/055_agent_auth.sql +72 -0
- package/sql/056_agent_client_runtime.sql +60 -0
- package/src/adapters/channels/wecom-api.ts +1 -1
- package/src/app/agent-client-runtime.test.ts +221 -0
- package/src/app/agent-client-runtime.ts +408 -0
- package/src/app/agent-tool-invocations.test.ts +462 -0
- package/src/app/agent-tool-invocations.ts +795 -0
- package/src/app/agent-tool-job.test.ts +62 -0
- package/src/app/agent-tool-job.ts +41 -0
- package/src/app/auth.ts +2 -1
- package/src/app/kernel.ts +2 -0
- package/src/app/runtime-context.ts +8 -0
- package/src/app/tool-approvals.ts +5 -1
- package/src/app/tool-assembly.ts +19 -1
- package/src/app/tool-context.ts +2 -1
- package/src/core/config/config-codec.ts +2 -1
- package/src/core/config/config-models.test.ts +28 -1
- package/src/core/config/config-models.ts +46 -3
- package/src/core/config/config-schema.test.ts +8 -0
- package/src/core/config/route-config.test.ts +15 -0
- package/src/core/config/route-config.ts +36 -0
- package/src/core/config/tools-config.test.ts +58 -1
- package/src/core/config/tools-config.ts +84 -0
- package/src/core/contracts/tools.ts +162 -29
- package/src/core/contracts/types.ts +38 -1
- package/src/core/platform/chat-form.test.ts +147 -0
- package/src/core/platform/chat-form.ts +402 -0
- package/src/core/platform/version.ts +1 -1
- package/src/core/runtime/agent-client-trace.test.ts +154 -0
- package/src/core/runtime/agent-client-trace.ts +288 -0
- package/src/core/runtime/execution-runtime.test.ts +61 -0
- package/src/core/runtime/execution-runtime.ts +17 -0
- package/src/core/runtime/launch-runtime.ts +13 -0
- package/src/core/runtime/trace-runtime.test.ts +18 -1
- package/src/core/runtime/trace-runtime.ts +28 -3
- package/src/core/state/state-codec.ts +2 -0
- package/src/infrastructure/config/config-agent-auth-repository.test.ts +147 -0
- package/src/infrastructure/config/config-agent-auth-repository.ts +356 -0
- package/src/infrastructure/config/config-agent-client-runtime-repository.ts +253 -0
- package/src/infrastructure/config/config-approval-ledger.test.ts +32 -0
- package/src/infrastructure/config/config-approval-ledger.ts +16 -0
- package/src/infrastructure/config/config-client-repository.ts +3 -3
- package/src/infrastructure/config/config-conversation-ledger.test.ts +69 -0
- package/src/infrastructure/config/config-conversation-ledger.ts +8 -7
- package/src/infrastructure/config/config-observability-ledger.test.ts +50 -0
- package/src/infrastructure/config/config-observability-ledger.ts +65 -10
- package/src/infrastructure/config/config-route-repository.ts +4 -3
- package/src/infrastructure/config/configstore.ts +14 -3
- package/src/infrastructure/state/state-mysql.ts +2 -2
- package/src/kernel-api/v1/contracts.ts +8 -0
- package/src/routes/admin-runtime.test.ts +214 -0
- package/src/routes/admin-runtime.ts +82 -2
- package/src/routes/agent-api.test.ts +379 -0
- package/src/routes/agent-api.ts +251 -0
- package/src/routes/agent-auth.test.ts +276 -0
- package/src/routes/agent-auth.ts +395 -0
- package/src/routes/approvals.ts +4 -1
- package/src/routes/chat.test.ts +319 -7
- package/src/routes/chat.ts +166 -21
- package/src/routes/critical-routes.test.ts +235 -1
- package/src/routes/private-default.ts +2 -1
- package/src/routes/private.ts +16 -1
- package/src/routes/run.ts +79 -13
- package/web/connect/bailing-connect-php.tgz +0 -0
- package/web/connect/bailing-connect-php7.tgz +0 -0
- package/web/console/assets/{Accounts-CAwrtBiS.js → Accounts-D4RRm5D1.js} +1 -1
- package/web/console/assets/{Approvals-C2BZ86T3.js → Approvals-CsTTKb8o.js} +1 -1
- package/web/console/assets/{Audit-B-E4Y_Up.js → Audit-BzvZ7JZw.js} +1 -1
- package/web/console/assets/{BrandLockup-C18u8Lx5.js → BrandLockup-CYcA93wh.js} +1 -1
- package/web/console/assets/{Channels-DTy8ylH-.js → Channels-DRQZggqM.js} +1 -1
- package/web/console/assets/ChatEntries-BUB7BWKU.js +7 -0
- package/web/console/assets/ChatEntries-DsYtcXN6.css +1 -0
- package/web/console/assets/Clients-CQ_MonGL.css +1 -0
- package/web/console/assets/Clients-HhCyrxfz.js +3 -0
- package/web/console/assets/{Cost-2SSYs1AT.js → Cost-BZgFf1yM.js} +1 -1
- package/web/console/assets/{Credentials-B79LtxCE.js → Credentials-BTe2Q07j.js} +1 -1
- package/web/console/assets/{Diagnostics-BakcRYvb.js → Diagnostics-WL-buYli.js} +1 -1
- package/web/console/assets/{Executors-BXoyo28u.js → Executors-CGZ-7Xmp.js} +1 -1
- package/web/console/assets/{Kb-ISbzquab.js → Kb-VVw8oGsT.js} +1 -1
- package/web/console/assets/{Login-Dlu6Wgcf.js → Login-rwvmBBPl.js} +1 -1
- package/web/console/assets/{Projects-DFzmtnqg.js → Projects-CexaCEY1.js} +1 -1
- package/web/console/assets/Routes-B9ZHbQAp.js +124 -0
- package/web/console/assets/Routes-BbkFpi6Y.css +1 -0
- package/web/console/assets/Runs-4zDD9VOC.css +1 -0
- package/web/console/assets/Runs-BzFNPTwD.js +3 -0
- package/web/console/assets/{Setup-CrBAV-b9.js → Setup-Djh5yadQ.js} +1 -1
- package/web/console/assets/{Shell-B1a8DvXQ.js → Shell-kn763smL.js} +1 -1
- package/web/console/assets/{StorageBuckets-BRfL_eHb.js → StorageBuckets-CQBR41W1.js} +1 -1
- package/web/console/assets/{SystemSettings-CyirVLbq.js → SystemSettings-DgnopekD.js} +1 -1
- package/web/console/assets/{SystemStatus-DZ_OR7sk.js → SystemStatus-Bj8-kPt2.js} +1 -1
- package/web/console/assets/{Targets-CtIMa66c.js → Targets-BAfCt_nH.js} +1 -1
- package/web/console/assets/{Tools-BfDZHt01.js → Tools-xjd0NZdE.js} +1 -1
- package/web/console/assets/{index-DBiByFiO.js → index-DfJA7iJS.js} +2 -2
- package/web/console/assets/{request-DY2cxQqZ.js → request-DkNPOweH.js} +1 -1
- package/web/console/assets/{schema-6mCQ7rR5.js → schema-CgPWAu1_.js} +1 -1
- package/web/console/index.html +1 -1
- package/web/widget/widget.js +493 -14
- package/web-admin/src/pages/ChatEntries.vue +18 -6
- package/web-admin/src/pages/Clients.vue +11 -3
- package/web-admin/src/pages/Routes.vue +282 -16
- package/web-admin/src/pages/Runs.vue +159 -38
- package/web/console/assets/ChatEntries-9xbRiQov.css +0 -1
- package/web/console/assets/ChatEntries-DvD-4IeE.js +0 -7
- package/web/console/assets/Clients--D7NQJKk.css +0 -1
- package/web/console/assets/Clients-DWs9JFr0.js +0 -3
- package/web/console/assets/Routes-B-hm9HGY.js +0 -124
- package/web/console/assets/Routes-DWGQN5Pv.css +0 -1
- package/web/console/assets/Runs-CUtSsPW-.css +0 -1
- package/web/console/assets/Runs-hMRu1im3.js +0 -3
|
@@ -18,6 +18,30 @@ export interface ToolApprovalConfig {
|
|
|
18
18
|
[key: string]: unknown;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* 本地 Agent 直调工具面是独立的明示授权,不从 route.permission 或 scope allow
|
|
23
|
+
* 推导。只读工具在 enabled=true 时可见;写工具必须按 operationId 精确列出。
|
|
24
|
+
* 已暴露写工具默认继承 ACC 风险/审批声明;只有再次精确列入
|
|
25
|
+
* force_approval_tools 才由路由额外强制审批。不接受通配符。
|
|
26
|
+
*
|
|
27
|
+
* unattended_write_tools 仅用于兼容私有候选的旧配置:存在该字段且没有新字段时,
|
|
28
|
+
* 仍按“其余 write_tools 强制审批”的旧语义解析;保存配置时应迁移为
|
|
29
|
+
* force_approval_tools,未配置任何审批覆盖即表示继承 ACC。
|
|
30
|
+
*/
|
|
31
|
+
export interface AgentDirectToolsConfig {
|
|
32
|
+
enabled: boolean;
|
|
33
|
+
write_tools?: string[];
|
|
34
|
+
force_approval_tools?: string[];
|
|
35
|
+
/** @deprecated 使用 force_approval_tools 明示额外强制审批。 */
|
|
36
|
+
unattended_write_tools?: string[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ResolvedAgentDirectToolsConfig {
|
|
40
|
+
enabled: true;
|
|
41
|
+
write_tools: string[];
|
|
42
|
+
force_approval_tools: string[];
|
|
43
|
+
}
|
|
44
|
+
|
|
21
45
|
export interface RouteToolsConfig {
|
|
22
46
|
sources?: ToolSourceConfig[];
|
|
23
47
|
max_calls?: number;
|
|
@@ -26,6 +50,7 @@ export interface RouteToolsConfig {
|
|
|
26
50
|
[key: string]: unknown;
|
|
27
51
|
};
|
|
28
52
|
approval?: ToolApprovalConfig;
|
|
53
|
+
agent_direct?: AgentDirectToolsConfig;
|
|
29
54
|
[key: string]: unknown;
|
|
30
55
|
}
|
|
31
56
|
|
|
@@ -71,6 +96,29 @@ export function approvalConfig(v: unknown): ToolApprovalConfig | null {
|
|
|
71
96
|
return type ? { ...ap, type } as ToolApprovalConfig : null;
|
|
72
97
|
}
|
|
73
98
|
|
|
99
|
+
export function agentDirectToolsConfig(v: unknown): ResolvedAgentDirectToolsConfig | null {
|
|
100
|
+
const cfg = routeToolsConfig(v);
|
|
101
|
+
const direct = record(cfg?.agent_direct);
|
|
102
|
+
if (!direct || direct.enabled !== true) return null;
|
|
103
|
+
const names = (value: unknown): string[] => Array.isArray(value)
|
|
104
|
+
? [...new Set(value.map((item) => String(item).trim()).filter(Boolean))]
|
|
105
|
+
: [];
|
|
106
|
+
const writeTools = names(direct.write_tools);
|
|
107
|
+
const hasForceApprovalTools = Object.prototype.hasOwnProperty.call(direct, 'force_approval_tools');
|
|
108
|
+
const hasLegacyUnattendedTools = Object.prototype.hasOwnProperty.call(direct, 'unattended_write_tools');
|
|
109
|
+
const legacyUnattendedTools = new Set(names(direct.unattended_write_tools));
|
|
110
|
+
const forceApprovalTools = hasForceApprovalTools
|
|
111
|
+
? names(direct.force_approval_tools)
|
|
112
|
+
: hasLegacyUnattendedTools
|
|
113
|
+
? writeTools.filter((name) => !legacyUnattendedTools.has(name))
|
|
114
|
+
: [];
|
|
115
|
+
return {
|
|
116
|
+
enabled: true,
|
|
117
|
+
write_tools: writeTools,
|
|
118
|
+
force_approval_tools: forceApprovalTools,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
74
122
|
export async function validateRouteToolsConfig(v: unknown, toolProviderExists?: ToolProviderExists): Promise<string | null> {
|
|
75
123
|
const toolsCfg = routeToolsConfig(v);
|
|
76
124
|
if (!toolsCfg || !Object.keys(toolsCfg).length) return null;
|
|
@@ -122,5 +170,41 @@ export async function validateRouteToolsConfig(v: unknown, toolProviderExists?:
|
|
|
122
170
|
}
|
|
123
171
|
}
|
|
124
172
|
|
|
173
|
+
|
|
174
|
+
if (toolsCfg.agent_direct !== undefined) {
|
|
175
|
+
const direct = record(toolsCfg.agent_direct);
|
|
176
|
+
if (!direct) return 'tools.agent_direct 必须是对象';
|
|
177
|
+
const known = new Set(['enabled', 'write_tools', 'force_approval_tools', 'unattended_write_tools']);
|
|
178
|
+
const unknown = Object.keys(direct).filter((key) => !known.has(key));
|
|
179
|
+
if (unknown.length) return `tools.agent_direct 包含未声明字段: ${unknown.join(',')}`;
|
|
180
|
+
if (typeof direct.enabled !== 'boolean') return 'tools.agent_direct.enabled 必须是布尔值';
|
|
181
|
+
const operationId = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/;
|
|
182
|
+
const parseNames = (field: 'write_tools' | 'force_approval_tools' | 'unattended_write_tools'): string[] | string => {
|
|
183
|
+
const raw = direct[field];
|
|
184
|
+
if (raw === undefined) return [];
|
|
185
|
+
if (!Array.isArray(raw)) return `tools.agent_direct.${field} 必须是 operationId 数组`;
|
|
186
|
+
const values = raw.map((item) => typeof item === 'string' ? item.trim() : '');
|
|
187
|
+
if (!values.length || values.some((item) => !operationId.test(item))) {
|
|
188
|
+
return `tools.agent_direct.${field} 只允许非空的精确 operationId,不允许通配符`;
|
|
189
|
+
}
|
|
190
|
+
if (new Set(values).size !== values.length) return `tools.agent_direct.${field} 不允许重复值`;
|
|
191
|
+
return values;
|
|
192
|
+
};
|
|
193
|
+
const writes = parseNames('write_tools');
|
|
194
|
+
if (typeof writes === 'string') return writes;
|
|
195
|
+
const forced = parseNames('force_approval_tools');
|
|
196
|
+
if (typeof forced === 'string') return forced;
|
|
197
|
+
const unattended = parseNames('unattended_write_tools');
|
|
198
|
+
if (typeof unattended === 'string') return unattended;
|
|
199
|
+
if (direct.force_approval_tools !== undefined && direct.unattended_write_tools !== undefined) {
|
|
200
|
+
return 'tools.agent_direct.force_approval_tools 与已弃用的 unattended_write_tools 不可同时配置';
|
|
201
|
+
}
|
|
202
|
+
const allowedWrites = new Set(writes);
|
|
203
|
+
const forcedOutside = forced.filter((name) => !allowedWrites.has(name));
|
|
204
|
+
if (forcedOutside.length) return `tools.agent_direct.force_approval_tools 必须是 write_tools 的子集: ${forcedOutside.join(',')}`;
|
|
205
|
+
const unattendedOutside = unattended.filter((name) => !allowedWrites.has(name));
|
|
206
|
+
if (unattendedOutside.length) return `tools.agent_direct.unattended_write_tools 必须是 write_tools 的子集: ${unattendedOutside.join(',')}`;
|
|
207
|
+
}
|
|
208
|
+
|
|
125
209
|
return null;
|
|
126
210
|
}
|
|
@@ -108,6 +108,100 @@ function normalizeToolArgs(args: Record<string, unknown>): { ok: true; args: Rec
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
const RESERVED_TOOL_HEADERS = new Set([
|
|
112
|
+
'authorization', 'cookie', 'host', 'content-length', 'connection', 'transfer-encoding',
|
|
113
|
+
'x-bailing-timestamp', 'x-bailing-signature', 'x-bailing-job-id', 'x-bailing-client',
|
|
114
|
+
'x-bailing-idempotency-key', 'x-bailing-on-behalf-of', 'x-bailing-conversation',
|
|
115
|
+
'x-bailing-tool-scope',
|
|
116
|
+
]);
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 服务端最后一道参数闸:MCP/Zod 只是客户端体验,不是信任边界。
|
|
120
|
+
* 这里拒绝顶层未声明参数、缺少必填项、基础类型/enum 不匹配以及保留治理头。
|
|
121
|
+
*/
|
|
122
|
+
function validateToolArguments(tool: ToolDefinition, args: Record<string, unknown>): string | null {
|
|
123
|
+
const properties = isRecord(tool.inputSchema['properties']) ? tool.inputSchema['properties'] as Record<string, unknown> : {};
|
|
124
|
+
// paramIn 也是 ACC/ToolDefinition 的显式参数声明。历史手工工具可能只在
|
|
125
|
+
// paramIn 声明 path/header/query 参数,而 inputSchema.properties 留空;这些参数
|
|
126
|
+
// 不是“未知参数”,但仍只能按已声明的位置出站。
|
|
127
|
+
const unknown = Object.keys(args).filter((key) => (
|
|
128
|
+
!Object.prototype.hasOwnProperty.call(properties, key)
|
|
129
|
+
&& !Object.prototype.hasOwnProperty.call(tool.paramIn, key)
|
|
130
|
+
));
|
|
131
|
+
if (unknown.length) return `unknown_arguments:${unknown.slice(0, 8).join(',')}`;
|
|
132
|
+
const required = Array.isArray(tool.inputSchema['required'])
|
|
133
|
+
? tool.inputSchema['required'].filter((item): item is string => typeof item === 'string')
|
|
134
|
+
: [];
|
|
135
|
+
const missing = required.filter((key) => args[key] === undefined);
|
|
136
|
+
if (missing.length) return `missing_required:${missing.slice(0, 8).join(',')}`;
|
|
137
|
+
for (const [key, value] of Object.entries(args)) {
|
|
138
|
+
const schema = isRecord(properties[key]) ? properties[key] as Record<string, unknown> : {};
|
|
139
|
+
const error = validateSchemaValue(value, schema, key, 0);
|
|
140
|
+
if (error) return error;
|
|
141
|
+
if (tool.paramIn[key] === 'header' && RESERVED_TOOL_HEADERS.has(key.toLowerCase())) {
|
|
142
|
+
return `reserved_header:${key}`;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function validateSchemaValue(value: unknown, schema: Record<string, unknown>, path: string, depth: number): string | null {
|
|
149
|
+
if (depth > 16) return `argument_too_deep:${path}`;
|
|
150
|
+
if (!valueMatchesSchemaType(value, schema)) return `argument_type:${path}`;
|
|
151
|
+
if (Array.isArray(schema['enum']) && !schema['enum'].some((candidate) => canonicalJson(candidate) === canonicalJson(value))) {
|
|
152
|
+
return `argument_enum:${path}`;
|
|
153
|
+
}
|
|
154
|
+
if (typeof value === 'string') {
|
|
155
|
+
const min = Number(schema['minLength']);
|
|
156
|
+
const max = Number(schema['maxLength']);
|
|
157
|
+
if (Number.isFinite(min) && value.length < min) return `argument_min_length:${path}`;
|
|
158
|
+
if (Number.isFinite(max) && value.length > max) return `argument_max_length:${path}`;
|
|
159
|
+
}
|
|
160
|
+
if (typeof value === 'number') {
|
|
161
|
+
const min = Number(schema['minimum']);
|
|
162
|
+
const max = Number(schema['maximum']);
|
|
163
|
+
if (Number.isFinite(min) && value < min) return `argument_minimum:${path}`;
|
|
164
|
+
if (Number.isFinite(max) && value > max) return `argument_maximum:${path}`;
|
|
165
|
+
}
|
|
166
|
+
if (Array.isArray(value)) {
|
|
167
|
+
const itemSchema = isRecord(schema['items']) ? schema['items'] as Record<string, unknown> : null;
|
|
168
|
+
if (value.length > 1000) return `argument_array_too_large:${path}`;
|
|
169
|
+
if (itemSchema) {
|
|
170
|
+
for (let i = 0; i < value.length; i++) {
|
|
171
|
+
const error = validateSchemaValue(value[i], itemSchema, `${path}[${i}]`, depth + 1);
|
|
172
|
+
if (error) return error;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (isRecord(value)) {
|
|
177
|
+
if (Object.keys(value).length > 256) return `argument_object_too_large:${path}`;
|
|
178
|
+
const properties = isRecord(schema['properties']) ? schema['properties'] as Record<string, unknown> : {};
|
|
179
|
+
const required = Array.isArray(schema['required'])
|
|
180
|
+
? schema['required'].filter((item): item is string => typeof item === 'string')
|
|
181
|
+
: [];
|
|
182
|
+
const missing = required.filter((key) => value[key] === undefined);
|
|
183
|
+
if (missing.length) return `missing_required:${path}.${missing[0]}`;
|
|
184
|
+
const additional = schema['additionalProperties'];
|
|
185
|
+
for (const [key, child] of Object.entries(value)) {
|
|
186
|
+
const declared = properties[key];
|
|
187
|
+
if (declared === undefined) {
|
|
188
|
+
if (additional === true) continue;
|
|
189
|
+
if (isRecord(additional)) {
|
|
190
|
+
const error = validateSchemaValue(child, additional, `${path}.${key}`, depth + 1);
|
|
191
|
+
if (error) return error;
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
return `unknown_argument:${path}.${key}`;
|
|
195
|
+
}
|
|
196
|
+
if (isRecord(declared)) {
|
|
197
|
+
const error = validateSchemaValue(child, declared, `${path}.${key}`, depth + 1);
|
|
198
|
+
if (error) return error;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
|
|
111
205
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
112
206
|
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
113
207
|
}
|
|
@@ -208,11 +302,28 @@ export interface ToolRuntime {
|
|
|
208
302
|
* 返回 null = 检索运行时不可用(索引未建/凭证不可用/embedding 临时挂)→ 调用方应降级回 progressive。retrievalMode=false 时不存在。 */
|
|
209
303
|
retrieve?(query: string): Promise<ToolRuntime['llmTools'] | null>;
|
|
210
304
|
/** 受闸调用:白名单复核→风险闸→限流→审计(fail-closed)→签名外发。返回回流 LLM 的文本(错误也以文本回流)。 */
|
|
211
|
-
invoke(name: string, args: Record<string, unknown>): Promise<
|
|
305
|
+
invoke(name: string, args: Record<string, unknown>): Promise<ToolInvokeResult>;
|
|
212
306
|
/** 下游是否已经进入“不允许自动重试、必须人工对账”的执行边界。 */
|
|
213
307
|
executionUncertainty(): ToolExecutionUncertainty | null;
|
|
214
308
|
}
|
|
215
309
|
|
|
310
|
+
export type ToolGovernanceState =
|
|
311
|
+
| 'executed'
|
|
312
|
+
| 'business_rejected'
|
|
313
|
+
| 'awaiting_approval'
|
|
314
|
+
| 'rejected_before_dispatch'
|
|
315
|
+
| 'reconciliation_required';
|
|
316
|
+
|
|
317
|
+
/** 工具调用的受治理结果;旧调用方仍可只读 ok/text/status。 */
|
|
318
|
+
export interface ToolInvokeResult {
|
|
319
|
+
ok: boolean;
|
|
320
|
+
text: string;
|
|
321
|
+
status: number;
|
|
322
|
+
governance_state?: ToolGovernanceState;
|
|
323
|
+
auto_retry_allowed?: boolean;
|
|
324
|
+
approval_id?: number;
|
|
325
|
+
}
|
|
326
|
+
|
|
216
327
|
/**
|
|
217
328
|
* 多工具源组合器:模型只看到一份工具面,调用时按工具名路由回所属工具源。
|
|
218
329
|
* 工具名必须在路由内全局唯一;上下文装配层会在运行前拒绝冲突,避免误调到错误业务系统。
|
|
@@ -255,7 +366,7 @@ export function composeToolRuntimes(runtimes: ToolRuntime[], maxCalls: number, a
|
|
|
255
366
|
} : {}),
|
|
256
367
|
async invoke(name, args) {
|
|
257
368
|
const runtime = owner.get(name);
|
|
258
|
-
if (!runtime) return { ok: false, text: `工具 ${name} 不在本路由白名单内,调用被拒。`, status: 0 };
|
|
369
|
+
if (!runtime) return { ok: false, text: `工具 ${name} 不在本路由白名单内,调用被拒。`, status: 0, governance_state: 'rejected_before_dispatch', auto_retry_allowed: false };
|
|
259
370
|
return runtime.invoke(name, args);
|
|
260
371
|
},
|
|
261
372
|
executionUncertainty() {
|
|
@@ -270,6 +381,8 @@ export function composeToolRuntimes(runtimes: ToolRuntime[], maxCalls: number, a
|
|
|
270
381
|
|
|
271
382
|
/** 审批车道句柄:由 server 接到 bz_tool_approvals + 送达插座。不注入时风险闸按未配置审批承接处理(一律拦)。 */
|
|
272
383
|
export interface ApprovalDeps {
|
|
384
|
+
/** 传统任务批准后由中枢重跑;Agent 直调由本地 Agent 用 invocation_id 续执行。 */
|
|
385
|
+
continuationMode?: 'rerun' | 'resume';
|
|
273
386
|
/** 查"已批准且未消费"的同快照审批单并原子消费;消费成功返回单号,否则 null */
|
|
274
387
|
consumeApproved(tool: string, hash: string): Promise<number | null>;
|
|
275
388
|
/** 查同快照 pending 单(去重:同一调用别重复开单) */
|
|
@@ -372,17 +485,25 @@ export function buildToolRuntime(d: ToolRuntimeDeps): ToolRuntime {
|
|
|
372
485
|
}
|
|
373
486
|
const t = byName.get(name);
|
|
374
487
|
// 闸1:白名单复核(与清单装配解耦的独立校验——清单多吐了也走不到执行)
|
|
375
|
-
if (!t) return { ok: false, text: `工具 ${name} 不在本路由白名单内,调用被拒。`, status: 0 };
|
|
488
|
+
if (!t) return { ok: false, text: `工具 ${name} 不在本路由白名单内,调用被拒。`, status: 0, governance_state: 'rejected_before_dispatch', auto_retry_allowed: false };
|
|
376
489
|
const normalized = normalizeToolArgs(args);
|
|
377
490
|
if (!normalized.ok) {
|
|
378
491
|
await d.audit('tool_blocked', { tool: name, scope: t.scope, reason: normalized.error }).catch(() => undefined);
|
|
379
|
-
return { ok: false, text: `工具 ${name} 参数不是合法 JSON 对象,调用已拒绝。请按工具参数 schema 重新传参。`, status: 0 };
|
|
492
|
+
return { ok: false, text: `工具 ${name} 参数不是合法 JSON 对象,调用已拒绝。请按工具参数 schema 重新传参。`, status: 0, governance_state: 'rejected_before_dispatch', auto_retry_allowed: false };
|
|
380
493
|
}
|
|
381
494
|
const callArgs = normalized.args;
|
|
495
|
+
const schemaError = validateToolArguments(t, callArgs);
|
|
496
|
+
if (schemaError) {
|
|
497
|
+
await d.audit('tool_blocked', { tool: name, scope: t.scope, reason: schemaError }).catch(() => undefined);
|
|
498
|
+
const mismatch = schemaError.startsWith('argument_type:')
|
|
499
|
+
? '参数类型与声明的 schema 不一致'
|
|
500
|
+
: '参数与声明的 schema 不一致';
|
|
501
|
+
return { ok: false, text: `工具 ${name} ${mismatch},调用已拒绝(${schemaError})。`, status: 0, governance_state: 'rejected_before_dispatch', auto_retry_allowed: false };
|
|
502
|
+
}
|
|
382
503
|
// 闸1.5:主体闸——ACC subject.required 的工具必须有操作主体(装配层已过滤看不见,这里防绕过双闸兜底)
|
|
383
504
|
if (t.requiresSubject && !d.onBehalfOf) {
|
|
384
505
|
await d.audit('tool_blocked', { tool: name, scope: t.scope, reason: 'requires-subject:任务无操作主体' }).catch(() => undefined);
|
|
385
|
-
return { ok: false, text: `工具 ${name} 需要明确的操作主体,当前任务没有可信身份(如匿名访客)。请告知用户登录后再操作或走人工流程。`, status: 0 };
|
|
506
|
+
return { ok: false, text: `工具 ${name} 需要明确的操作主体,当前任务没有可信身份(如匿名访客)。请告知用户登录后再操作或走人工流程。`, status: 0, governance_state: 'rejected_before_dispatch', auto_retry_allowed: false };
|
|
386
507
|
}
|
|
387
508
|
// 闸1.8:幂等账本——同 job 内"副作用工具"(非只读、非声明幂等)已执行过的相同调用,重试/崩溃恢复重跑时直接返回上次结果,
|
|
388
509
|
// 不重复执行(防写操作重复扣款)。放在审批闸之前:否则重跑时已消费的审批单会被当成"无批准"再次触发待审批,把重跑卡死。
|
|
@@ -431,9 +552,26 @@ export function buildToolRuntime(d: ToolRuntimeDeps): ToolRuntime {
|
|
|
431
552
|
idempotency_key: existing.idempotencyKey,
|
|
432
553
|
reason: existing.error ?? '检测到未完成的执行日志,禁止自动重放',
|
|
433
554
|
}).catch(() => undefined);
|
|
434
|
-
return { ok: false, text: executionUncertainty.message, status: 0 };
|
|
555
|
+
return { ok: false, text: executionUncertainty.message, status: 0, governance_state: 'reconciliation_required', auto_retry_allowed: false };
|
|
435
556
|
}
|
|
436
557
|
}
|
|
558
|
+
// 前置调度闸:任何可重试的限流都必须发生在审批单消费前。
|
|
559
|
+
// 请求尚未出站,不能把 429 伪装成业务拒绝,也不能白白用掉人工批准。
|
|
560
|
+
const toolLimited = d.rateLimit
|
|
561
|
+
? await d.rateLimit(`tool:${d.provider.name}:${name}`, t.rateLimitPerMin, 60)
|
|
562
|
+
: !allowRate(`tool:${d.provider.name}:${name}`, t.rateLimitPerMin);
|
|
563
|
+
const providerLimited = d.rateLimit
|
|
564
|
+
? await d.rateLimit(`provider:${d.provider.name}`, d.provider.rate_limit_per_min, 60)
|
|
565
|
+
: !allowRate(`provider:${d.provider.name}`, d.provider.rate_limit_per_min);
|
|
566
|
+
if (toolLimited || providerLimited) {
|
|
567
|
+
return {
|
|
568
|
+
ok: false,
|
|
569
|
+
text: `工具 ${name} 触发限流,稍后使用同一调用标识重试。`,
|
|
570
|
+
status: 429,
|
|
571
|
+
governance_state: 'rejected_before_dispatch',
|
|
572
|
+
auto_retry_allowed: true,
|
|
573
|
+
};
|
|
574
|
+
}
|
|
437
575
|
// 闸2:风险闸 + 审批车道(B 方案:先撤再来)。high / confirm-required 的调用:
|
|
438
576
|
// 有"已批准未消费"的同快照单 → 原子消费后放行;没有 → 开 pending 单推审批人,本次调用拒绝(任务正常收尾,批准后自动重跑)。
|
|
439
577
|
// 批准按 job+tool+args_hash 精确匹配——批的是"那一次调用",重跑换参数/换动作 = 重新走审批。
|
|
@@ -441,28 +579,28 @@ export function buildToolRuntime(d: ToolRuntimeDeps): ToolRuntime {
|
|
|
441
579
|
const confirmCheck = firstConfirmHit(t, callArgs);
|
|
442
580
|
if (confirmCheck.error) {
|
|
443
581
|
await d.audit('tool_blocked', { tool: name, scope: t.scope, reason: confirmCheck.error }).catch(() => undefined);
|
|
444
|
-
return { ok: false, text: `工具 ${name} 的审批条件参数类型不符合声明,调用已拒绝。请按工具参数 schema 重新传参。`, status: 0 };
|
|
582
|
+
return { ok: false, text: `工具 ${name} 的审批条件参数类型不符合声明,调用已拒绝。请按工具参数 schema 重新传参。`, status: 0, governance_state: 'rejected_before_dispatch', auto_retry_allowed: false };
|
|
445
583
|
}
|
|
446
584
|
const confirmHit = confirmCheck.hit;
|
|
447
585
|
const needsApproval = t.risk === 'high' || t.confirmRequired || !!confirmHit;
|
|
448
586
|
if (needsApproval) {
|
|
449
587
|
if (!d.approvals) { // 未接审批车道(理论不发生,server 总会注入):一律拦
|
|
450
588
|
await d.audit('tool_blocked', { tool: name, scope: t.scope, reason: approvalReason(t, confirmHit) }).catch(() => undefined);
|
|
451
|
-
return { ok: false, text: `工具 ${name} 属于需人工确认的高风险操作,当前不允许自动执行。请告知用户走人工流程。`, status: 0 };
|
|
589
|
+
return { ok: false, text: `工具 ${name} 属于需人工确认的高风险操作,当前不允许自动执行。请告知用户走人工流程。`, status: 0, governance_state: 'rejected_before_dispatch', auto_retry_allowed: false };
|
|
452
590
|
}
|
|
453
591
|
const hash = argsHash(callArgs);
|
|
454
592
|
approvalId = await d.approvals.consumeApproved(name, hash);
|
|
455
593
|
if (approvalId === null) {
|
|
456
594
|
const pendingId = await d.approvals.findPending(name, hash);
|
|
457
595
|
if (pendingId !== null) {
|
|
458
|
-
return { ok: false, text: `该操作已有待审批单(编号 ${pendingId}
|
|
596
|
+
return { ok: false, text: `该操作已有待审批单(编号 ${pendingId}),请勿重复提交。`, status: 0, governance_state: 'awaiting_approval', auto_retry_allowed: false, approval_id: pendingId };
|
|
459
597
|
}
|
|
460
598
|
// 参数漂移纠偏:同工具已有"已批准未消费"单但参数对不上(大脑重跑没按原样发,如 {id:25} 漂成 {name:"周杰伦"})。
|
|
461
599
|
// 不开新单空转审批——把批准的精确参数怼回去让大脑当场重发;安全零降级:执行仍只认精确匹配的原子消费。
|
|
462
600
|
const drifted = await d.approvals.findApprovedAnyArgs(name);
|
|
463
601
|
if (drifted) {
|
|
464
602
|
await d.audit('tool_args_drift', { tool: name, approval_id: drifted.id, got_args: JSON.stringify(callArgs).slice(0, 500) }).catch(() => undefined);
|
|
465
|
-
return { ok: false, text: `该工具已有人工批准的调用(审批单 ${drifted.id}
|
|
603
|
+
return { ok: false, text: `该工具已有人工批准的调用(审批单 ${drifted.id}),但你本次的参数与批准的不一致。请使用原审批快照续执行,不要更改参数。`, status: 0, governance_state: 'rejected_before_dispatch', auto_retry_allowed: false };
|
|
466
604
|
}
|
|
467
605
|
const argsJson = JSON.stringify(callArgs);
|
|
468
606
|
const reason = approvalReason(t, confirmHit);
|
|
@@ -476,20 +614,13 @@ export function buildToolRuntime(d: ToolRuntimeDeps): ToolRuntime {
|
|
|
476
614
|
const id = await d.approvals.create(snap);
|
|
477
615
|
await d.audit('tool_approval_pending', { approval_id: id, tool: name, scope: t.scope, risk: t.risk, confirm_required: t.confirmRequired, ...(confirmHit ? { confirm_when: confirmHit } : {}) }).catch(() => undefined);
|
|
478
616
|
await d.approvals.notify(id, { ...snap, args_json: argsJson.slice(0, 1000) }).catch(() => undefined);
|
|
479
|
-
|
|
617
|
+
const continuation = d.approvals.continuationMode === 'resume'
|
|
618
|
+
? '批准后请用本 invocation_id 续执行;中枢不会启动模型重跑。'
|
|
619
|
+
: '批准后系统会自动重跑原任务。';
|
|
620
|
+
return { ok: false, text: `工具 ${name} 属于需人工审批的操作,已提交审批单(编号 ${id})。${continuation}`, status: 0, governance_state: 'awaiting_approval', auto_retry_allowed: false, approval_id: id };
|
|
480
621
|
}
|
|
481
622
|
// 走到这 = 批准单已消费,放行执行(审计带 approval_id 闭环留痕)
|
|
482
623
|
}
|
|
483
|
-
// 闸3:限流(每工具 + 工具源总闸)
|
|
484
|
-
const toolLimited = d.rateLimit
|
|
485
|
-
? await d.rateLimit(`tool:${d.provider.name}:${name}`, t.rateLimitPerMin, 60)
|
|
486
|
-
: !allowRate(`tool:${d.provider.name}:${name}`, t.rateLimitPerMin);
|
|
487
|
-
const providerLimited = d.rateLimit
|
|
488
|
-
? await d.rateLimit(`provider:${d.provider.name}`, d.provider.rate_limit_per_min, 60)
|
|
489
|
-
: !allowRate(`provider:${d.provider.name}`, d.provider.rate_limit_per_min);
|
|
490
|
-
if (toolLimited || providerLimited) {
|
|
491
|
-
return { ok: false, text: `工具 ${name} 触发限流,稍后再试。`, status: 429 };
|
|
492
|
-
}
|
|
493
624
|
// 组装请求:path/header/query/body 各归其位;GET 未标位置的参数仍回落 query。
|
|
494
625
|
const query = new URLSearchParams();
|
|
495
626
|
const bodyObj: Record<string, unknown> = {};
|
|
@@ -535,7 +666,7 @@ export function buildToolRuntime(d: ToolRuntimeDeps): ToolRuntime {
|
|
|
535
666
|
reason: '执行日志不可用,请求未发出',
|
|
536
667
|
error: String(error).slice(0, 500),
|
|
537
668
|
}).catch(() => undefined);
|
|
538
|
-
return { ok: false, text: `工具 ${name}
|
|
669
|
+
return { ok: false, text: `工具 ${name} 的执行日志当前不可用,请求未发出。`, status: 0, governance_state: 'rejected_before_dispatch', auto_retry_allowed: false };
|
|
539
670
|
}
|
|
540
671
|
if (!reserved.inserted) {
|
|
541
672
|
if (reserved.entry.state === 'completed') {
|
|
@@ -556,7 +687,7 @@ export function buildToolRuntime(d: ToolRuntimeDeps): ToolRuntime {
|
|
|
556
687
|
idempotency_key: reserved.entry.idempotencyKey,
|
|
557
688
|
reason: reserved.entry.error ?? '并发或恢复路径检测到未完成执行日志',
|
|
558
689
|
}).catch(() => undefined);
|
|
559
|
-
return { ok: false, text: executionUncertainty.message, status: 0 };
|
|
690
|
+
return { ok: false, text: executionUncertainty.message, status: 0, governance_state: 'reconciliation_required', auto_retry_allowed: false };
|
|
560
691
|
}
|
|
561
692
|
}
|
|
562
693
|
|
|
@@ -568,6 +699,9 @@ export function buildToolRuntime(d: ToolRuntimeDeps): ToolRuntime {
|
|
|
568
699
|
const r = await fetch(d.provider.base_url.replace(/\/+$/, '') + pathWithQuery, {
|
|
569
700
|
method: t.method,
|
|
570
701
|
headers: {
|
|
702
|
+
// ACC 声明的普通业务头先放;下面的治理头由中枢最后覆盖。
|
|
703
|
+
// validateToolArguments 仍会显式拒绝保留头,这里是第二道防线。
|
|
704
|
+
...headers,
|
|
571
705
|
...(body ? { 'content-type': 'application/json' } : {}),
|
|
572
706
|
'x-bailing-timestamp': String(ts),
|
|
573
707
|
'x-bailing-signature': sigHeader,
|
|
@@ -578,7 +712,6 @@ export function buildToolRuntime(d: ToolRuntimeDeps): ToolRuntime {
|
|
|
578
712
|
// 来源会话坐标(非签名材料):业务侧自审批批准后据此 /send 回流到原会话;收件人权威仍以已验签的 on-behalf-of 为准
|
|
579
713
|
...(d.conversation ? { 'x-bailing-conversation': d.conversation } : {}),
|
|
580
714
|
'x-bailing-tool-scope': t.scope,
|
|
581
|
-
...headers,
|
|
582
715
|
},
|
|
583
716
|
body: body || undefined,
|
|
584
717
|
signal: AbortSignal.timeout(timeoutMs),
|
|
@@ -606,7 +739,7 @@ export function buildToolRuntime(d: ToolRuntimeDeps): ToolRuntime {
|
|
|
606
739
|
idempotency_key: idemKey,
|
|
607
740
|
reason: error,
|
|
608
741
|
}).catch(() => undefined);
|
|
609
|
-
return { ok: false, text: executionUncertainty.message, status: 0 };
|
|
742
|
+
return { ok: false, text: executionUncertainty.message, status: 0, governance_state: 'reconciliation_required', auto_retry_allowed: false };
|
|
610
743
|
}
|
|
611
744
|
}
|
|
612
745
|
// 回流给模型的:受上下文预算 truncateBytes 截断(与审计留存解耦)
|
|
@@ -632,7 +765,7 @@ export function buildToolRuntime(d: ToolRuntimeDeps): ToolRuntime {
|
|
|
632
765
|
idempotency_key: idemKey,
|
|
633
766
|
reason: executionUncertainty.reason,
|
|
634
767
|
}).catch(() => undefined);
|
|
635
|
-
return { ok: false, text: executionUncertainty.message, status: 0 };
|
|
768
|
+
return { ok: false, text: executionUncertainty.message, status: 0, governance_state: 'reconciliation_required', auto_retry_allowed: false };
|
|
636
769
|
}
|
|
637
770
|
}
|
|
638
771
|
// 审计留存:logFull 记全量响应(封顶 AUDIT_MAX_BYTES,超出记 resp_truncated);resp_bytes 始终记真实字节数。
|
|
@@ -660,7 +793,7 @@ export function buildToolRuntime(d: ToolRuntimeDeps): ToolRuntime {
|
|
|
660
793
|
reason,
|
|
661
794
|
message: `工具 ${name} 已产生业务响应,但审计证据不完整。为避免重复业务后果,本任务已禁止自动重试;请使用幂等键 ${idemKey} 人工对账。`,
|
|
662
795
|
};
|
|
663
|
-
return { ok: false, text: executionUncertainty.message, status: 0 };
|
|
796
|
+
return { ok: false, text: executionUncertainty.message, status: 0, governance_state: 'reconciliation_required', auto_retry_allowed: false };
|
|
664
797
|
}
|
|
665
798
|
throw error;
|
|
666
799
|
}
|
|
@@ -683,10 +816,10 @@ export function buildToolRuntime(d: ToolRuntimeDeps): ToolRuntime {
|
|
|
683
816
|
idempotency_key: idemKey,
|
|
684
817
|
reason: executionUncertainty.reason,
|
|
685
818
|
}).catch(() => undefined);
|
|
686
|
-
return { ok: false, text: executionUncertainty.message, status: 0 };
|
|
819
|
+
return { ok: false, text: executionUncertainty.message, status: 0, governance_state: 'reconciliation_required', auto_retry_allowed: false };
|
|
687
820
|
}
|
|
688
821
|
}
|
|
689
|
-
return { ok, text: retText, status };
|
|
822
|
+
return { ok, text: retText, status, governance_state: ok ? 'executed' : 'business_rejected', auto_retry_allowed: false };
|
|
690
823
|
},
|
|
691
824
|
};
|
|
692
825
|
}
|
|
@@ -20,6 +20,8 @@ export interface Job {
|
|
|
20
20
|
project: string;
|
|
21
21
|
source: string;
|
|
22
22
|
client_app_id?: string; // 触发方 app_id(admin token 触发为空)
|
|
23
|
+
agent_session_id?: string; // 本地 Agent 受信会话归属(非套餐/付费字段)
|
|
24
|
+
on_behalf_of?: string; // 业务侧批准的实际操作主体
|
|
23
25
|
thread_id?: number; // 对话线索(总账),finish 时回写 out 消息
|
|
24
26
|
session_id?: string;
|
|
25
27
|
input_preview: string;
|
|
@@ -124,6 +126,8 @@ export interface Client {
|
|
|
124
126
|
app_id: string;
|
|
125
127
|
name: string;
|
|
126
128
|
token: string;
|
|
129
|
+
/** 本地 Agent 登录时打开的业务侧授权页;未配置时不开放 Agent Auth。 */
|
|
130
|
+
agent_authorize_url?: string;
|
|
127
131
|
allowed_routes: string[]; // 路由白名单(触发 /run),['*'] = 全部
|
|
128
132
|
allowed_channels: string[]; // 主动出站渠道白名单(POST /send),['*'] = 全部,空 = 禁止(fail-closed)
|
|
129
133
|
rate_limit_per_min: number; // 0 = 不限
|
|
@@ -133,6 +137,32 @@ export interface Client {
|
|
|
133
137
|
last_used_at?: string;
|
|
134
138
|
}
|
|
135
139
|
|
|
140
|
+
/** 业务后端在 Agent 授权时提交的可信业务主体。 */
|
|
141
|
+
export interface AgentBusinessPrincipal {
|
|
142
|
+
id: string;
|
|
143
|
+
tenant?: string;
|
|
144
|
+
roles: string[];
|
|
145
|
+
audience?: string;
|
|
146
|
+
channel?: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* 可撤销的本地 Agent 会话。这是身份与审计归属,不是套餐、付费或用量归属。
|
|
151
|
+
* 令牌及其摘要不进入公开合同。
|
|
152
|
+
*/
|
|
153
|
+
export interface AgentSession {
|
|
154
|
+
session_id: string;
|
|
155
|
+
client_app_id: string;
|
|
156
|
+
device_label: string;
|
|
157
|
+
principal: AgentBusinessPrincipal;
|
|
158
|
+
on_behalf_of: string;
|
|
159
|
+
allowed_routes: string[];
|
|
160
|
+
created_at: string;
|
|
161
|
+
access_expires_at: string;
|
|
162
|
+
refresh_expires_at: string;
|
|
163
|
+
revoked_at?: string;
|
|
164
|
+
}
|
|
165
|
+
|
|
136
166
|
/** 模型凭证(后台可配,不硬编码):llm 对话与知识库 embedding 共用,按名引用。key 入库不回显。 */
|
|
137
167
|
export interface Credential {
|
|
138
168
|
name: string;
|
|
@@ -251,6 +281,12 @@ export interface Route {
|
|
|
251
281
|
tools?: Record<string, unknown>; // 工具治理层:{sources:[{provider,allow[],subject_field?,retrieval?}],max_calls?,builtin:{send_message:{channels[]}},approval:{type,url?}},见 docs/TOOLS_DESIGN.md
|
|
252
282
|
audience?: AudiencePolicy; // 身份/Audience 策略:谁能进本路由,route=auto 如何把意图分到本路由
|
|
253
283
|
memory?: Record<string, unknown>; // 记忆层:{recent_messages, recent_budget_chars, summary_enabled, summary_trigger_chars, summary_keep_recent, summary_model, ...},见 src/core/runtime/memory.ts
|
|
284
|
+
/** 本地 Agent Runtime 覆盖项。缺省且 tools.agent_direct.enabled=true 时按兼容默认启用。 */
|
|
285
|
+
agent_client?: {
|
|
286
|
+
enabled?: boolean;
|
|
287
|
+
instructions?: string;
|
|
288
|
+
active_tool_limit?: number;
|
|
289
|
+
};
|
|
254
290
|
budget?: Record<string, unknown>; // 成本预算闸:{window/window_hours, hard_cost_usd?, hard_tokens?, ...}
|
|
255
291
|
description?: string;
|
|
256
292
|
}
|
|
@@ -268,12 +304,13 @@ export interface ChatEntry {
|
|
|
268
304
|
title?: string;
|
|
269
305
|
greeting?: string;
|
|
270
306
|
color?: string;
|
|
271
|
-
appearance?: ChatAppearance; //
|
|
307
|
+
appearance?: ChatAppearance; // 外观(默认展开/窗口尺寸/标题对齐/气泡位置偏移/头像/自定义气泡图标/AI 提示);缺省走组件内置默认
|
|
272
308
|
description?: string;
|
|
273
309
|
}
|
|
274
310
|
|
|
275
311
|
/** 聊天组件外观:全可选,缺省走 widget.js 内置默认值。落 bz_chat_entries.appearance(JSON)。 */
|
|
276
312
|
export interface ChatAppearance {
|
|
313
|
+
default_open?: boolean; // 嵌入页加载后默认展开面板(默认 false;script data-open="1" 仍可强制展开)
|
|
277
314
|
width?: number; // 展开面板宽度 px(默认 400,受视口封顶)
|
|
278
315
|
height?: number; // 展开面板高度 px(默认 600,受视口封顶)
|
|
279
316
|
title_align?: 'center' | 'left'; // 标题对齐(默认 center)
|