bailinghub 0.7.0 → 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 +6 -9
- package/README.md +6 -9
- package/docker-compose.images.yml +2 -2
- package/docs/AGENT_CLIENT_RUNTIME_API.en.md +46 -0
- package/docs/AGENT_CLIENT_RUNTIME_API.md +34 -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 +11 -1
- package/docs/CHANGELOG.md +11 -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/README.en.md +3 -0
- package/docs/README.md +3 -0
- package/docs/RELEASE_NOTES_NEXT.en.md +2 -2
- package/docs/RELEASE_NOTES_NEXT.md +2 -2
- package/docs/RELEASE_NOTES_v0.8.0.en.md +40 -0
- package/docs/RELEASE_NOTES_v0.8.0.md +62 -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//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 +1 -0
- package/schemas/config/tool-provider.schema.json +2 -1
- 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/e2e-console.mjs +32 -2
- package/scripts/install.sh +1 -1
- package/scripts/publish-images.sh +1 -1
- package/scripts/release-audit.mjs +1 -0
- package/scripts/verify-github-repo.mjs +1 -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/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-invocation-snapshot.ts +35 -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 +223 -10
- 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/artifact-config.ts +15 -0
- package/src/core/config/config-codec.ts +3 -1
- package/src/core/config/config-models.ts +11 -1
- package/src/core/config/route-config.ts +3 -2
- 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 +3 -1
- 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-client-runtime-repository.ts +7 -1
- 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-rate-limit-ledger.integration.test.ts +52 -0
- package/src/infrastructure/config/config-rate-limit-ledger.ts +48 -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 +9 -1
- package/src/routes/admin-agent-tasks.ts +32 -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 +42 -1
- package/src/routes/agent-artifacts.ts +29 -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-task-control-mysql-fixture.ts +75 -0
- package/web/console/assets/{Accounts-ChL9k-XA.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-Bs6FGbp2.js → Approvals-BIbZvInm.js} +1 -1
- package/web/console/assets/{Audit-4WWYhkFM.js → Audit-KyPSmBdZ.js} +1 -1
- package/web/console/assets/{BrandLockup-D2GhCipL.js → BrandLockup-Sv5DU2G6.js} +1 -1
- package/web/console/assets/{Channels-CmoGpiCJ.js → Channels-B9n4fbxg.js} +1 -1
- package/web/console/assets/{ChatEntries-BFRMtwta.js → ChatEntries-xsOCUXi_.js} +1 -1
- package/web/console/assets/{Clients-DGkkSXyA.js → Clients-CI3DBDHf.js} +1 -1
- package/web/console/assets/{Cost-BmGt0MfS.js → Cost-JgNXQPlN.js} +1 -1
- package/web/console/assets/{Credentials-CR-sYINT.js → Credentials-B5UUUdt0.js} +1 -1
- package/web/console/assets/{Diagnostics-DAPbKSJp.js → Diagnostics-BMGciWQb.js} +1 -1
- package/web/console/assets/{Executors-CgpiT3o8.js → Executors-CRbboOCZ.js} +1 -1
- package/web/console/assets/{Kb-Cm9dVSQw.js → Kb-CgLNGjRp.js} +1 -1
- package/web/console/assets/{Login-CyUcsTZ_.js → Login-C52JmXzx.js} +1 -1
- package/web/console/assets/{Projects-DldFPgWg.js → Projects-CDOvHPVS.js} +1 -1
- package/web/console/assets/{Routes-DubfjlBD.js → Routes-X9vHLpKW.js} +1 -1
- package/web/console/assets/{Runs-1hxgkuR4.js → Runs-DYNDXsqk.js} +1 -1
- package/web/console/assets/{Setup-DBLOnI2_.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-cDkudo2y.js → SystemSettings-B7Mqj3k1.js} +1 -1
- package/web/console/assets/{SystemStatus-DZd6s8OX.js → SystemStatus-Db93b6dc.js} +1 -1
- package/web/console/assets/{Targets-DYNGq1NU.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-B7MLvOqo.js → request-DeGya810.js} +1 -1
- package/web/console/assets/{schema-CMuwjYdJ.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/src/components/AgentSetupPanel.vue +13 -0
- package/web-admin/src/components/ToolRateLimitEditor.vue +28 -0
- package/web-admin/src/layout/Shell.vue +1 -1
- package/web-admin/src/pages/AgentClients.vue +3 -1
- package/web-admin/src/pages/AgentTasks.vue +281 -0
- 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/console/assets/AgentClients-Bs7UgVDj.js +0 -1
- package/web/console/assets/AgentClients-DkgPTEbq.css +0 -1
- package/web/console/assets/Shell-D9Uw-fsa.css +0 -1
- package/web/console/assets/Shell-gJ5Vz_E7.js +0 -1
- package/web/console/assets/StorageBuckets-DkDW16tj.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-DpWM59vV.js +0 -2
- package/web/console/assets/index-DGqs28gI.js +0 -2
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { randomBytes, randomUUID } from 'node:crypto';
|
|
3
|
+
import { createServer, type Server } from 'node:http';
|
|
4
|
+
import test from 'node:test';
|
|
5
|
+
import type { AppConfig } from '../core/config/config';
|
|
6
|
+
import type { Principal } from '../app/auth';
|
|
7
|
+
import { send } from '../app/http';
|
|
8
|
+
import { ConfigStore } from '../infrastructure/config/configstore';
|
|
9
|
+
import { MysqlStore } from '../infrastructure/state/state-mysql';
|
|
10
|
+
import type { ToolProxyDeps } from '../app/tool-proxy';
|
|
11
|
+
import { handleAgentApiHttpFor } from './agent-api';
|
|
12
|
+
import { handleAdminAgentTasksApiFor } from './admin-agent-tasks';
|
|
13
|
+
import { tokenHash } from './agent-auth';
|
|
14
|
+
import { openTaskMysqlFixture, seedTaskMysqlMembers, taskMysqlConfigPath } from '../test-support/agent-task-control-mysql-fixture';
|
|
15
|
+
|
|
16
|
+
const listen = (server: Server) => new Promise<string>((resolve) => server.listen(0, '127.0.0.1', () => {
|
|
17
|
+
const address = server.address(); assert.ok(address && typeof address === 'object'); resolve(`http://127.0.0.1:${address.port}`);
|
|
18
|
+
}));
|
|
19
|
+
const close = (server: Server) => new Promise<void>((resolve, reject) => server.close((error) => error ? reject(error) : resolve()));
|
|
20
|
+
const id = () => randomBytes(32).toString('hex');
|
|
21
|
+
const tools = ['product_update', 'inventory_read', 'product_review'];
|
|
22
|
+
function spec() {
|
|
23
|
+
const operation = (name: string, write: boolean, approval: boolean) => ({
|
|
24
|
+
operationId: name, summary: name,
|
|
25
|
+
'x-agent-capability': { version: 1, enabled: true, scope: write ? 'products.write' : 'inventory.read', subject: { required: true },
|
|
26
|
+
...(approval ? { risk: { level: 'high' } } : {}) },
|
|
27
|
+
...(write ? { requestBody: { content: { 'application/json': { schema: { type: 'object', properties: { id: { type: 'integer' } }, required: ['id'], additionalProperties: false } } } } }
|
|
28
|
+
: { parameters: [{ name: 'id', in: 'query', schema: { type: 'integer' } }] }),
|
|
29
|
+
});
|
|
30
|
+
return JSON.stringify({ openapi: '3.0.0', info: { title: 'Example shop and inventory', version: '1' }, paths: {
|
|
31
|
+
'/product': { post: operation('product_update', true, false) },
|
|
32
|
+
'/inventory': { get: operation('inventory_read', false, false) },
|
|
33
|
+
'/review': { post: operation('product_review', true, true) },
|
|
34
|
+
} });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
test('task control gates real HTTP dispatch through the persisted Core runtime', { skip: !taskMysqlConfigPath }, async (t) => {
|
|
38
|
+
const pool = await openTaskMysqlFixture();
|
|
39
|
+
const owner = { get: async () => pool, close: async () => undefined };
|
|
40
|
+
const config = new ConfigStore({} as AppConfig['state']['mysql'], owner);
|
|
41
|
+
const state = new MysqlStore({} as AppConfig['state']['mysql'], owner);
|
|
42
|
+
await config.init(); await state.init();
|
|
43
|
+
const requests: Array<{ url: string; subject: string }> = [];
|
|
44
|
+
let dropResponse = false;
|
|
45
|
+
let holdBusinessResponse: Promise<void> | null = null;
|
|
46
|
+
let dropCoreAck = false;
|
|
47
|
+
const business = createServer(async (req, res) => {
|
|
48
|
+
requests.push({ url: req.url ?? '', subject: String(req.headers['x-agent-on-behalf-of'] ?? '') });
|
|
49
|
+
if (dropResponse) { req.socket.destroy(); return; }
|
|
50
|
+
if (holdBusinessResponse) await holdBusinessResponse;
|
|
51
|
+
send(res, 200, { ok: true, synthetic: true });
|
|
52
|
+
});
|
|
53
|
+
const businessUrl = await listen(business);
|
|
54
|
+
const cfg = { brand: { name: 'BailingHub' }, server: { token: 'synthetic-test-server-secret' } } as AppConfig;
|
|
55
|
+
const toolProxyDeps: ToolProxyDeps = { cfg, configStore: config, stateStore: state, toolIndex: null,
|
|
56
|
+
now: () => new Date().toISOString(), sleep: async () => undefined };
|
|
57
|
+
let legacyRuns = 0;
|
|
58
|
+
const core = createServer(async (req, res) => {
|
|
59
|
+
try {
|
|
60
|
+
const url = new URL(req.url!, 'http://127.0.0.1');
|
|
61
|
+
if (dropCoreAck && url.pathname === '/agent-api/v1/tool-invocations' && req.method === 'POST') {
|
|
62
|
+
dropCoreAck = false;
|
|
63
|
+
res.end = (() => { res.destroy(); return res; }) as typeof res.end;
|
|
64
|
+
}
|
|
65
|
+
if (url.pathname.startsWith('/admin/')) {
|
|
66
|
+
const principal: Principal = req.headers.authorization === 'Bearer synthetic-admin'
|
|
67
|
+
? { kind: 'admin', via: 'token' } : { kind: 'admin', via: 'session', role: 'viewer' };
|
|
68
|
+
if (await handleAdminAgentTasksApiFor(config, req.method!, url.pathname, req, res, principal)) return;
|
|
69
|
+
}
|
|
70
|
+
if (await handleAgentApiHttpFor({ configStore: config, stateStore: state, isPaused: () => false, toolProxyDeps,
|
|
71
|
+
handleRun: async (_req, result) => { legacyRuns++; send(result, 200, {}); } }, req, res, url)) return;
|
|
72
|
+
send(res, 404, { error: 'not_found' });
|
|
73
|
+
} catch (error) { send(res, 500, { error: error instanceof Error ? error.message : 'test_server_error' }); }
|
|
74
|
+
});
|
|
75
|
+
const coreUrl = await listen(core);
|
|
76
|
+
const request = async (path: string, bearer: string, body?: unknown) => {
|
|
77
|
+
const response = await fetch(`${coreUrl}${path}`, { method: body === undefined ? 'GET' : 'POST',
|
|
78
|
+
headers: { authorization: `Bearer ${bearer}`, 'content-type': 'application/json' }, ...(body === undefined ? {} : { body: JSON.stringify(body) }) });
|
|
79
|
+
return { status: response.status, body: await response.json() as any };
|
|
80
|
+
};
|
|
81
|
+
const setup = async (maxWrites: number | null = 2, longClientId = false) => {
|
|
82
|
+
const members = await seedTaskMysqlMembers(pool);
|
|
83
|
+
const bearers: string[] = [];
|
|
84
|
+
for (const member of members) {
|
|
85
|
+
if (longClientId) {
|
|
86
|
+
const fullId = `business-${id()}`.slice(0, 64);
|
|
87
|
+
await pool.query('UPDATE bz_clients SET app_id=? WHERE app_id=?', [fullId, member.clientAppId]);
|
|
88
|
+
await pool.query('UPDATE bz_agent_sessions SET client_app_id=? WHERE session_id=?', [fullId, member.sessionId]);
|
|
89
|
+
await pool.query('UPDATE bz_agent_client_runs SET client_app_id=? WHERE run_id=?', [fullId, member.runId]);
|
|
90
|
+
member.clientAppId = fullId;
|
|
91
|
+
}
|
|
92
|
+
const bearer = `bha_${randomBytes(32).toString('base64url')}`; bearers.push(bearer);
|
|
93
|
+
await pool.query('UPDATE bz_agent_sessions SET access_token_hash=? WHERE session_id=?', [tokenHash(bearer), member.sessionId]);
|
|
94
|
+
await config.toolProviders.upsert({ name: member.clientAppId, base_url: businessUrl, secret: 'synthetic-provider-secret',
|
|
95
|
+
enabled: true, spec_source: 'inline', spec_json: spec(), log_payload: false, timeout_ms: 1000, rate_limit_per_min: 0, auto_refresh_min: 0 });
|
|
96
|
+
const route = (await config.routes.get(member.route))!;
|
|
97
|
+
await config.routes.upsert({ ...route, permission: 'full', audience: { enabled: true, roles: ['manager'], clients: [member.clientAppId] },
|
|
98
|
+
tools: { sources: [{ provider: member.clientAppId, allow: ['products.write', 'inventory.read'] }], max_calls: 12,
|
|
99
|
+
agent_direct: { enabled: true, write_tools: ['product_update', 'product_review'] } }, agent_client: { enabled: true } });
|
|
100
|
+
}
|
|
101
|
+
const body = { request_id: randomUUID(), members: members.map((m) => ({ session_id: m.sessionId, client_app_id: m.clientAppId,
|
|
102
|
+
workspace: m.route, client_conversation_id: m.clientConversationId, allowed_tools: tools })),
|
|
103
|
+
policy: { max_write_calls: maxWrites, max_concurrent: 2, expires_at: null } };
|
|
104
|
+
const created = await request('/admin/api/agent-tasks', 'synthetic-admin', body);
|
|
105
|
+
assert.equal(created.status, 200, JSON.stringify(created.body));
|
|
106
|
+
const task = created.body;
|
|
107
|
+
const binding = { schema_version: 'bailing.agent-task-binding.v1', task_id: task.task_id, scope_hash: task.scope_hash };
|
|
108
|
+
const turnBody = (index = 0) => ({ client_conversation_id: members[index]!.clientConversationId, client_turn_id: randomUUID(),
|
|
109
|
+
user_message_id: randomUUID(), user_input: 'synthetic product task', task_binding: binding });
|
|
110
|
+
const turn = async (index = 0) => {
|
|
111
|
+
const result = await request(`/agent-api/v1/workspaces/${members[index]!.route}/turns`, bearers[index]!, turnBody(index));
|
|
112
|
+
assert.equal(result.status, 200, JSON.stringify(result.body)); assert.deepEqual(result.body.task_binding, binding); return result.body;
|
|
113
|
+
};
|
|
114
|
+
const invoke = async (context: any, tool = 'product_update', index = 0, invocationId = id()) => {
|
|
115
|
+
const input = { invocation_id: invocationId, route: members[index]!.route, capability_revision: context.capability_revision,
|
|
116
|
+
agent_run_id: context.run_id, tool, arguments: { id: 1 } };
|
|
117
|
+
return { ...await request('/agent-api/v1/tool-invocations', bearers[index]!, input), input };
|
|
118
|
+
};
|
|
119
|
+
const detail = () => request(`/admin/api/agent-tasks/${task.task_id}`, 'synthetic-admin');
|
|
120
|
+
const control = async (action: string) => {
|
|
121
|
+
const current = (await detail()).body.task;
|
|
122
|
+
const result = await request(`/admin/api/agent-tasks/${task.task_id}/control`, 'synthetic-admin', {
|
|
123
|
+
request_id: randomUUID(), expected_revision: current.revision, action });
|
|
124
|
+
assert.equal(result.status, 200, JSON.stringify(result.body)); return result.body;
|
|
125
|
+
};
|
|
126
|
+
return { members, bearers, task, body, binding, turnBody, turn, invoke, detail, control };
|
|
127
|
+
};
|
|
128
|
+
try {
|
|
129
|
+
await t.test('admin scope creation is idempotent, snapshots disclose only the original member, and omission cannot bypass task admission', async () => {
|
|
130
|
+
const fx = await setup();
|
|
131
|
+
assert.equal((await request('/admin/api/agent-tasks', 'synthetic-admin', fx.body)).body.task_id, fx.task.task_id);
|
|
132
|
+
assert.equal((await request('/admin/api/agent-tasks', fx.bearers[0]!, fx.body)).status, 403);
|
|
133
|
+
const capabilities = await request('/agent-api/v1/task-control/capabilities', fx.bearers[0]!);
|
|
134
|
+
assert.equal(capabilities.body.supported, true); assert.equal(capabilities.body.mode, 'required');
|
|
135
|
+
const snapshot = await request(`/agent-api/v1/tasks/${fx.task.task_id}?workspace=${fx.members[0]!.route}&client_conversation_id=${fx.members[0]!.clientConversationId}`, fx.bearers[0]!);
|
|
136
|
+
assert.equal(snapshot.status, 200); assert.equal(snapshot.body.member_count, 2);
|
|
137
|
+
assert.equal(snapshot.body.member.session_id, fx.members[0]!.sessionId);
|
|
138
|
+
assert.equal(JSON.stringify(snapshot.body).includes(fx.members[1]!.sessionId), false);
|
|
139
|
+
assert.equal(JSON.stringify(snapshot.body).includes('identityHash'), false);
|
|
140
|
+
const { task_binding: _binding, ...withoutTask } = fx.turnBody();
|
|
141
|
+
const omitted = await request(`/agent-api/v1/workspaces/${fx.members[0]!.route}/turns`, fx.bearers[0]!, withoutTask);
|
|
142
|
+
assert.equal(omitted.body.error, 'TASK_REQUIRED');
|
|
143
|
+
const legacy = await request('/agent-api/v1/run', fx.bearers[0]!, {});
|
|
144
|
+
assert.equal(legacy.body.error, 'TASK_REQUIRED'); assert.equal(legacyRuns, 0);
|
|
145
|
+
const [rows]: any = await pool.query('SELECT COUNT(*) AS n FROM bz_agent_client_runs WHERE client_turn_id=?', [withoutTask.client_turn_id]);
|
|
146
|
+
assert.equal(Number(rows[0].n), 0);
|
|
147
|
+
});
|
|
148
|
+
await t.test('two systems and new turns share cumulative writes; readonly calls do not spend write budget; fences survive result persistence', async () => {
|
|
149
|
+
const fx = await setup(2); const before = requests.length;
|
|
150
|
+
const a = await fx.turn(0), b = await fx.turn(1);
|
|
151
|
+
for (const [context, index] of [[a, 0], [b, 1]] as const) {
|
|
152
|
+
const result = await fx.invoke(context, 'product_update', index);
|
|
153
|
+
assert.equal(result.body.state, 'executed', JSON.stringify(result.body));
|
|
154
|
+
const duplicate = await request('/agent-api/v1/tool-invocations', fx.bearers[index]!, result.input);
|
|
155
|
+
assert.equal(duplicate.body.state, 'executed');
|
|
156
|
+
}
|
|
157
|
+
const next = await fx.turn(0);
|
|
158
|
+
assert.equal((await fx.invoke(next)).body.error, 'TASK_WRITE_BUDGET_EXHAUSTED');
|
|
159
|
+
assert.equal((await fx.invoke(next, 'inventory_read')).body.state, 'executed');
|
|
160
|
+
assert.equal(requests.length - before, 3);
|
|
161
|
+
const detail = (await fx.detail()).body;
|
|
162
|
+
assert.equal(detail.task.counters.write_consumed, 2); assert.equal(detail.task.counters.write_reserved, 0);
|
|
163
|
+
assert.equal(detail.task.counters.active_permits, 0);
|
|
164
|
+
for (const invocation of detail.invocations) {
|
|
165
|
+
const job = (await state.getJob(invocation.job_id))!;
|
|
166
|
+
assert.equal(job.metadata.agent_task_id, fx.task.task_id); assert.equal(job.metadata.agent_dispatch_attempted, true);
|
|
167
|
+
assert.ok(job.metadata.agent_task_permit_id); assert.equal(job.metadata.agent_frozen_arguments, undefined);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
await t.test('approval only reserves; paused resume cannot consume approval; inspection is read only; explicit original resume dispatches once', async () => {
|
|
171
|
+
const fx = await setup(1); const before = requests.length;
|
|
172
|
+
const context = await fx.turn(); const result = await fx.invoke(context, 'product_review');
|
|
173
|
+
assert.equal(result.body.state, 'awaiting_approval', JSON.stringify(result.body));
|
|
174
|
+
const approvalId = result.body.approval_id;
|
|
175
|
+
assert.equal((await fx.detail()).body.task.counters.write_reserved, 1);
|
|
176
|
+
await pool.query("UPDATE bz_tool_approvals SET status='approved' WHERE id=?", [approvalId]);
|
|
177
|
+
await fx.control('pause');
|
|
178
|
+
const path = `/agent-api/v1/tool-invocations/${result.input.invocation_id}`;
|
|
179
|
+
const receipt = await request(`${path}/receipt`, fx.bearers[0]!);
|
|
180
|
+
assert.equal(receipt.body.read_only, true, JSON.stringify(receipt)); assert.equal(receipt.body.approval.status, 'approved');
|
|
181
|
+
const paused = await request(`${path}/resume`, fx.bearers[0]!, {});
|
|
182
|
+
assert.equal(paused.body.error, 'TASK_PAUSED', JSON.stringify(paused.body));
|
|
183
|
+
const [rows]: any = await pool.query('SELECT used_at FROM bz_tool_approvals WHERE id=?', [approvalId]);
|
|
184
|
+
assert.equal(rows[0].used_at, null); assert.equal(requests.length, before);
|
|
185
|
+
await fx.control('resume');
|
|
186
|
+
const resumed = await request(`${path}/resume`, fx.bearers[0]!, {});
|
|
187
|
+
assert.equal(resumed.body.state, 'executed', JSON.stringify(resumed.body));
|
|
188
|
+
assert.equal((await request(`${path}/resume`, fx.bearers[0]!, {})).body.state, 'executed');
|
|
189
|
+
assert.equal(requests.length, before + 1);
|
|
190
|
+
assert.equal((await fx.detail()).body.task.counters.write_consumed, 1);
|
|
191
|
+
});
|
|
192
|
+
await t.test('lost business response holds the original reservation and permit; resume never duplicates the write', async () => {
|
|
193
|
+
const fx = await setup(1); const before = requests.length; const context = await fx.turn();
|
|
194
|
+
dropResponse = true;
|
|
195
|
+
const result = await fx.invoke(context); dropResponse = false;
|
|
196
|
+
assert.equal(result.body.state, 'reconciliation_required', JSON.stringify(result.body));
|
|
197
|
+
const retried = await request(`/agent-api/v1/tool-invocations/${result.input.invocation_id}/resume`, fx.bearers[0]!, {});
|
|
198
|
+
assert.equal(retried.body.state, 'reconciliation_required'); assert.equal(requests.length, before + 1);
|
|
199
|
+
const counters = (await fx.detail()).body.task.counters;
|
|
200
|
+
assert.equal(counters.write_reserved, 1); assert.equal(counters.write_consumed, 0); assert.equal(counters.active_permits, 1);
|
|
201
|
+
});
|
|
202
|
+
await t.test('revoking any original member blocks dispatch in the other system; cancel does not unenroll the Session', async () => {
|
|
203
|
+
const fx = await setup(); const before = requests.length; const context = await fx.turn();
|
|
204
|
+
await pool.query('UPDATE bz_agent_sessions SET revoked_at=NOW() WHERE session_id=?', [fx.members[1]!.sessionId]);
|
|
205
|
+
assert.equal((await fx.invoke(context)).body.error, 'TASK_SCOPE_BLOCKED');
|
|
206
|
+
assert.equal(requests.length, before); assert.equal((await fx.detail()).body.task.state, 'blocked');
|
|
207
|
+
await fx.control('cancel');
|
|
208
|
+
const { task_binding: _binding, ...withoutTask } = fx.turnBody();
|
|
209
|
+
assert.equal((await request(`/agent-api/v1/workspaces/${fx.members[0]!.route}/turns`, fx.bearers[0]!, withoutTask)).body.error, 'TASK_REQUIRED');
|
|
210
|
+
});
|
|
211
|
+
await t.test('a lost Core acknowledgement is recovered from the original journal without a second business request', async () => {
|
|
212
|
+
const fx = await setup(1); const context = await fx.turn(); const before = requests.length;
|
|
213
|
+
const invocationId = id(); dropCoreAck = true;
|
|
214
|
+
await assert.rejects(fx.invoke(context, 'product_update', 0, invocationId));
|
|
215
|
+
const receipt = await request(`/agent-api/v1/tool-invocations/${invocationId}/receipt`, fx.bearers[0]!);
|
|
216
|
+
assert.equal(receipt.body.result.state, 'executed', JSON.stringify(receipt));
|
|
217
|
+
assert.equal((await request(`/agent-api/v1/tool-invocations/${invocationId}/resume`, fx.bearers[0]!, {})).body.state, 'executed');
|
|
218
|
+
assert.equal(requests.length, before + 1); assert.equal((await fx.detail()).body.task.counters.write_consumed, 1);
|
|
219
|
+
});
|
|
220
|
+
await t.test('maximum-length client IDs dispatch and inspect without losing the full authorization identity', async () => {
|
|
221
|
+
const fx = await setup(1, true); const context = await fx.turn(); const before = requests.length;
|
|
222
|
+
const result = await fx.invoke(context);
|
|
223
|
+
assert.equal(result.body.state, 'executed', JSON.stringify(result.body)); assert.equal(requests.length, before + 1);
|
|
224
|
+
const invocation = (await fx.detail()).body.invocations[0]; const job = (await state.getJob(invocation.job_id))!;
|
|
225
|
+
assert.equal(job.source.length, 32); assert.equal(job.client_app_id, fx.members[0]!.clientAppId); assert.equal(job.client_app_id!.length, 64);
|
|
226
|
+
const receipt = await request(`/agent-api/v1/tool-invocations/${result.input.invocation_id}/receipt`, fx.bearers[0]!);
|
|
227
|
+
assert.equal(receipt.body.result.state, 'executed', JSON.stringify(receipt.body));
|
|
228
|
+
});
|
|
229
|
+
await t.test('read and write share concurrency; cancel retains prior permits and accepts their late receipts', async () => {
|
|
230
|
+
const fx = await setup(4); const context = await fx.turn(); const before = requests.length;
|
|
231
|
+
let release!: () => void; holdBusinessResponse = new Promise<void>((resolve) => { release = resolve; });
|
|
232
|
+
const pending = [fx.invoke(context), fx.invoke(context, 'inventory_read')];
|
|
233
|
+
try {
|
|
234
|
+
for (let i = 0; requests.length < before + 2 && i < 100; i++) await new Promise((resolve) => setTimeout(resolve, 5));
|
|
235
|
+
assert.equal(requests.length, before + 2);
|
|
236
|
+
assert.equal((await fx.invoke(context, 'inventory_read')).body.error, 'TASK_CONCURRENCY_EXHAUSTED');
|
|
237
|
+
assert.equal((await fx.detail()).body.task.counters.active_permits, 2);
|
|
238
|
+
await fx.control('cancel');
|
|
239
|
+
} finally { holdBusinessResponse = null; release(); }
|
|
240
|
+
const results = await Promise.all(pending); results.forEach((result) => assert.equal(result.body.state, 'executed', JSON.stringify(result.body)));
|
|
241
|
+
const detail = (await fx.detail()).body.task;
|
|
242
|
+
assert.equal(detail.state, 'cancelled'); assert.equal(detail.counters.active_permits, 0); assert.equal(detail.counters.write_consumed, 1);
|
|
243
|
+
assert.equal((await fx.invoke(context)).body.error, 'TASK_CANCELLED'); assert.equal(requests.length, before + 2);
|
|
244
|
+
});
|
|
245
|
+
} finally { await close(core); await close(business); await pool.end(); }
|
|
246
|
+
});
|
package/src/routes/private.ts
CHANGED
|
@@ -121,6 +121,7 @@ export async function handlePrivateHttpFor(deps: PrivateHttpDeps, req: IncomingM
|
|
|
121
121
|
handleRun: deps.handleRun,
|
|
122
122
|
toolProxyDeps: toolProxyDeps(deps),
|
|
123
123
|
kbService: deps.kbService,
|
|
124
|
+
artifactRoot: deps.cfg.runtimeRoot ?? deps.cfg.root,
|
|
124
125
|
}, req, res, url)) return;
|
|
125
126
|
|
|
126
127
|
if (method === 'POST' && path === '/admin/login') {
|
package/src/routes/run.ts
CHANGED
|
@@ -36,7 +36,8 @@ function agentAllowsRoute(principal: Extract<Principal, { kind: 'agent' }>, rout
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
function agentUserMetadata(value: Record<string, unknown>): Record<string, unknown> {
|
|
39
|
-
return Object.fromEntries(Object.entries(value).filter(([key]) => !AGENT_RESERVED_METADATA_FIELDS.has(key)
|
|
39
|
+
return Object.fromEntries(Object.entries(value).filter(([key]) => !AGENT_RESERVED_METADATA_FIELDS.has(key)
|
|
40
|
+
&& !key.startsWith('agent_task') && key !== 'task_binding' && key !== 'task_id'));
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
function agentSubjectScope(principal: Extract<Principal, { kind: 'agent' }>): string {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { createHash, randomBytes, randomUUID } from 'node:crypto';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { createPool, type Pool } from 'mysql2/promise';
|
|
5
|
+
import { migrateBailingHubCoreSchema } from '../infrastructure/schema/core-schema-migrator';
|
|
6
|
+
|
|
7
|
+
/** Opt-in, disposable loopback database only. Never reads application configuration. */
|
|
8
|
+
export const taskMysqlConfigPath = process.env.BAILING_TASK_TEST_MYSQL_CONFIG;
|
|
9
|
+
|
|
10
|
+
export async function openTaskMysqlFixture(): Promise<Pool> {
|
|
11
|
+
assert.ok(taskMysqlConfigPath, 'Explicit disposable test database configuration is required');
|
|
12
|
+
const input = JSON.parse(readFileSync(taskMysqlConfigPath, 'utf8'));
|
|
13
|
+
assert.equal(input.host, '127.0.0.1', 'Task tests must use a local disposable database');
|
|
14
|
+
assert.match(input.database, /^bailing_task_test(?:_[a-z0-9]+)?$/, 'Dedicated test database required');
|
|
15
|
+
const mysql = { host: input.host, port: Number(input.port), database: input.database,
|
|
16
|
+
user: input.user, password: input.password, connectionLimit: 8 };
|
|
17
|
+
await migrateBailingHubCoreSchema({ mysql });
|
|
18
|
+
const repeated = await migrateBailingHubCoreSchema({ mysql });
|
|
19
|
+
assert.deepEqual(repeated.appliedFiles, [], 'Repeated migration must not replay SQL');
|
|
20
|
+
assert.equal(repeated.executedStatements, 0);
|
|
21
|
+
return createPool({ ...mysql, timezone: 'Z', dateStrings: true });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Only synthetic shop/inventory identities and empty conversation bodies. */
|
|
25
|
+
export async function seedTaskMysqlMembers(pool: Pool) {
|
|
26
|
+
const suffix = randomBytes(5).toString('hex');
|
|
27
|
+
const conversationId = `conversation-${suffix}`;
|
|
28
|
+
const members = [];
|
|
29
|
+
for (const system of ['shop', 'inventory']) {
|
|
30
|
+
const sessionId = randomUUID();
|
|
31
|
+
const clientAppId = `${system}-${suffix}`;
|
|
32
|
+
const route = `${system}-${suffix}`;
|
|
33
|
+
const runId = randomUUID();
|
|
34
|
+
const principal = { id: 'example-operator', tenant: `${system}-example`, roles: ['manager'] };
|
|
35
|
+
const subject = `${system}-example:example-operator`;
|
|
36
|
+
await pool.query('INSERT INTO bz_clients (app_id,name,token,allowed_routes,rate_limit_per_min,enabled,agent_authorize_url,created_at,updated_at) VALUES (?,?,?,?,0,1,?,NOW(),NOW())',
|
|
37
|
+
[clientAppId, `Example ${system}`, randomBytes(16).toString('hex'), JSON.stringify([route]), 'https://business.example.com/authorize']);
|
|
38
|
+
await pool.query('INSERT INTO bz_routes (route_key,name,enabled,profile,tools,agent_client,created_at,updated_at) VALUES (?,?,1,?,?,?,?,NOW())',
|
|
39
|
+
[route, `Example ${system}`, 'general', JSON.stringify({ agent_direct: { enabled: true } }), JSON.stringify({ enabled: true }), '2026-01-01 00:00:00']);
|
|
40
|
+
await pool.query('INSERT INTO bz_agent_sessions (session_id,client_app_id,device_label,principal_json,on_behalf_of,allowed_routes,access_token_hash,access_expires_at,refresh_expires_at,created_at,updated_at) VALUES (?,?,?,?,?,?,?,\'2099-01-01\',\'2099-02-01\',NOW(),NOW())',
|
|
41
|
+
[sessionId, clientAppId, `Example ${system}`, JSON.stringify(principal), subject, JSON.stringify([route]), randomBytes(32).toString('hex')]);
|
|
42
|
+
await pool.query('INSERT INTO bz_agent_client_runs (run_id,session_id,client_app_id,route_key,thread_id,client_conversation_id,client_turn_id,user_message_id,request_hash,user_input,status,created_at,updated_at) VALUES (?,?,?,?,1,?,?,?,?,\'\',\'context_ready\',NOW(),NOW())',
|
|
43
|
+
[runId, sessionId, clientAppId, route, conversationId, `turn-${suffix}`, `message-${system}-${suffix}`, 'a'.repeat(64)]);
|
|
44
|
+
members.push({ sessionId, clientAppId, route, clientConversationId: conversationId, runId, principal, subject });
|
|
45
|
+
}
|
|
46
|
+
return members;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function seedTaskMysqlInvocation(pool: Pool, member: Awaited<ReturnType<typeof seedTaskMysqlMembers>>[number],
|
|
50
|
+
options: { tool?: string; readonly?: boolean; approvalRequired?: boolean; runId?: string; extraMetadata?: Record<string, unknown> } = {}) {
|
|
51
|
+
const invocationId = randomBytes(32).toString('hex');
|
|
52
|
+
const jobId = randomUUID();
|
|
53
|
+
const tool = options.tool ?? 'product_update';
|
|
54
|
+
const runId = options.runId ?? member.runId;
|
|
55
|
+
const argsHash = 'b'.repeat(64);
|
|
56
|
+
const executionFingerprint = 'c'.repeat(64);
|
|
57
|
+
const metadata = {
|
|
58
|
+
agent_tool_job_marker: 'bailing.agent-tool-job.v1', principal: member.principal,
|
|
59
|
+
agent_tool_call_v1: true, agent_dispatch_attempted: false,
|
|
60
|
+
agent_invocation_id: invocationId, agent_run_id: runId,
|
|
61
|
+
agent_route: member.route, agent_tool: tool,
|
|
62
|
+
agent_args_hash: argsHash, agent_capability_revision: 'd'.repeat(64),
|
|
63
|
+
agent_execution_fingerprint: executionFingerprint,
|
|
64
|
+
agent_task_tool_contract: { schema_version: 'bailing.agent-task-tool-contract.v1',
|
|
65
|
+
readonly: options.readonly === true, approval_required: options.approvalRequired === true,
|
|
66
|
+
args_hash: argsHash, execution_fingerprint: executionFingerprint },
|
|
67
|
+
...options.extraMetadata,
|
|
68
|
+
};
|
|
69
|
+
const requestId = `agent-tool:${createHash('sha256').update(`bailing.agent-tool.v1\0${member.sessionId}\0${invocationId}`).digest('hex')}`;
|
|
70
|
+
await pool.query('INSERT INTO bz_jobs (job_id,request_id,status,profile,target,source,session_id,client_app_id,agent_session_id,on_behalf_of,metadata,dispatch,created_at,updated_at) VALUES (?,?,\'running\',\'general\',\'agent-tool-v1\',?,?,?,?,?,?,?,NOW(),NOW())',
|
|
71
|
+
[jobId, requestId, `agent-tool:${member.clientAppId}`, runId, member.clientAppId, member.sessionId, member.subject,
|
|
72
|
+
JSON.stringify(metadata), JSON.stringify({ route_key: member.route })]);
|
|
73
|
+
return { sessionId: member.sessionId, runId, invocationId, jobId, tool, argsHash, executionFingerprint,
|
|
74
|
+
readonly: options.readonly === true, approvalRequired: options.approvalRequired === true };
|
|
75
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{aj as K,E as V}from"./vendor-element-CZoEjZr8.js";import{a as C}from"./request-
|
|
1
|
+
import{aj as K,E as V}from"./vendor-element-CZoEjZr8.js";import{a as C}from"./request-DeGya810.js";import{f as W,c as X}from"./util-4bN2dv7B.js";import{u as Y}from"./index-UGvfF3Xr.js";import{H as c}from"./HelpTip-i-KJhf5s.js";import{d as Z,z as h,c as L,S as n,J as t,R as O,r as _,ai as i,o as b,e as o,Q as r,P as s,u as ee,I as E,O as $,a3 as le,q as te}from"./vendor-vue-B2uhHUfE.js";import{_ as ne}from"./_plugin-vue_export-helper-DlAUqK2U.js";const ae={class:"head"},oe={class:"account-main"},se={class:"account-stack"},de={class:"muted"},ie={class:"account-stack"},ue={class:"muted"},re=Z({__name:"Accounts",setup(me){const y={admin:"全能",kb_editor:"知识库维护",viewer:"只读任务"},N=Y(),x=_([]),T=_(["admin","kb_editor","viewer"]),u=_(!1),m=_(!1),w=_(!1),d=te({username:"",display_name:"",role:"kb_editor",password:"",enabled:!0});async function g(){var e;const a=await C("/admin/api/admins");x.value=a.list,(e=a.roles)!=null&&e.length&&(T.value=a.roles)}function S(a){return a==="admin"?"admin":a==="kb_editor"?"kb_editor":a==="viewer"?"viewer":a}function M(a){return a?`最近登录 ${W(a)}`:"从未登录"}function j(){m.value=!1,Object.assign(d,{username:"",display_name:"",role:"kb_editor",password:"",enabled:!0}),u.value=!0}function q(a){m.value=!0,Object.assign(d,{username:a.username,display_name:a.display_name||"",role:a.role,password:"",enabled:!!a.enabled}),u.value=!0}async function D(){w.value=!0;try{const a=await C("/admin/api/admins",{method:"POST",body:JSON.stringify(d)});u.value=!1,await g(),a.generated_password?(await K.alert(`账号 ${a.username} 的初始密码(只显示这一次,请立即发给使用人):
|
|
2
2
|
|
|
3
3
|
${a.generated_password}`,"账号已创建",{confirmButtonText:"复制密码"}).catch(()=>{}),await X(a.generated_password,"密码已复制")):V.success("已保存")}catch(a){V.error(a.message)}finally{w.value=!1}}async function I(a){try{await C("/admin/api/admins/"+encodeURIComponent(a),{method:"DELETE"}),await g()}catch(e){V.error(e.message)}}return h(g),(a,e)=>{const p=i("el-button"),v=i("el-table-column"),U=i("el-tag"),R=i("el-popconfirm"),z=i("el-table"),A=i("el-card"),k=i("el-input"),f=i("el-form-item"),H=i("el-option"),J=i("el-select"),P=i("el-switch"),F=i("el-form"),Q=i("el-drawer");return b(),L(O,null,[n(A,{shadow:"never"},{header:t(()=>[o("div",ae,[e[9]||(e[9]=o("b",null,"后台账号",-1)),e[10]||(e[10]=s()),n(c,{title:"后台账号 / 角色"},{default:t(()=>[...e[7]||(e[7]=[o("p",null,"后台账号只用于维护中枢控制台,不等同于业务系统用户,也不参与聊天/工具调用的业务身份。",-1),o("p",null,[s("角色决定可见板块与管理权限:"),o("code",null,"admin"),s(" 管全局配置,"),o("code",null,"kb_editor"),s(" 维护知识库,"),o("code",null,"viewer"),s(" 查看运行记录。")],-1)])]),_:1}),n(p,{type:"primary",style:{"margin-left":"auto"},onClick:j},{default:t(()=>[...e[8]||(e[8]=[s("新建账号",-1)])]),_:1})])]),default:t(()=>[n(z,{data:x.value},{default:t(()=>[n(v,{label:"账号","min-width":"240","show-overflow-tooltip":""},{default:t(({row:l})=>[o("div",oe,[o("b",null,r(l.display_name||l.username),1),o("code",null,r(l.username),1)])]),_:1}),n(v,{label:"角色权限","min-width":"220"},{default:t(({row:l})=>[o("div",se,[n(U,{type:l.role==="admin"?"warning":"info",effect:"plain"},{default:t(()=>[s(r(S(l.role)),1)]),_:2},1032,["type"]),o("span",de,r(y[l.role]||"自定义角色"),1)])]),_:1}),n(v,{label:"登录状态","min-width":"190"},{default:t(({row:l})=>[o("div",ie,[n(U,{type:l.enabled?"success":"info",effect:"plain"},{default:t(()=>[s(r(l.enabled?"启用":"停用"),1)]),_:2},1032,["type"]),o("span",ue,r(M(l.last_login_at)),1)])]),_:1}),n(v,{"min-width":"80",align:"right"},{default:t(({row:l})=>{var B;return[n(p,{link:"",type:"primary",onClick:G=>q(l)},{default:t(()=>[...e[11]||(e[11]=[s("编辑",-1)])]),_:1},8,["onClick"]),l.username!==((B=ee(N).me)==null?void 0:B.username)?(b(),E(R,{key:0,title:"删除该账号?其登录会话立即失效。",width:"240",onConfirm:G=>I(l.username)},{reference:t(()=>[n(p,{link:"",type:"danger"},{default:t(()=>[...e[12]||(e[12]=[s("删",-1)])]),_:1})]),_:1},8,["onConfirm"])):$("",!0)]}),_:1})]),_:1},8,["data"])]),_:1}),n(Q,{modelValue:u.value,"onUpdate:modelValue":e[6]||(e[6]=l=>u.value=l),title:m.value?"编辑账号":"新建账号",size:"420px"},{footer:t(()=>[n(p,{onClick:e[5]||(e[5]=l=>u.value=!1)},{default:t(()=>[...e[22]||(e[22]=[s("取消",-1)])]),_:1}),n(p,{type:"primary",loading:w.value,onClick:D},{default:t(()=>[...e[23]||(e[23]=[s("保存",-1)])]),_:1},8,["loading"])]),default:t(()=>[n(F,{"label-position":"top"},{default:t(()=>[n(f,null,{label:t(()=>[...e[13]||(e[13]=[s("用户名 ",-1),o("span",{class:"field-required"},"必填",-1)])]),default:t(()=>[n(k,{modelValue:d.username,"onUpdate:modelValue":e[0]||(e[0]=l=>d.username=l),disabled:m.value,placeholder:"如 ops-admin",class:"mono"},null,8,["modelValue","disabled"])]),_:1}),n(f,{label:"显示名(可选)"},{default:t(()=>[n(k,{modelValue:d.display_name,"onUpdate:modelValue":e[1]||(e[1]=l=>d.display_name=l)},null,8,["modelValue"])]),_:1}),n(f,null,{label:t(()=>[e[15]||(e[15]=s("角色 ",-1)),e[16]||(e[16]=o("span",{class:"field-required"},"必填",-1)),e[17]||(e[17]=s()),n(c,{title:"角色"},{default:t(()=>[...e[14]||(e[14]=[o("p",null,[o("b",null,"admin"),s(":管理全局配置与账号;"),o("b",null,"kb_editor"),s(":维护知识库;"),o("b",null,"viewer"),s(":只读查看运行记录。")],-1)])]),_:1})]),default:t(()=>[n(J,{modelValue:d.role,"onUpdate:modelValue":e[2]||(e[2]=l=>d.role=l),style:{width:"100%"}},{default:t(()=>[(b(!0),L(O,null,le(T.value,l=>(b(),E(H,{key:l,value:l,label:l+(y[l]?"("+y[l]+")":"")},null,8,["value","label"]))),128))]),_:1},8,["modelValue"])]),_:1}),n(f,null,{label:t(()=>[e[19]||(e[19]=s("密码 ",-1)),n(c,{title:"密码"},{default:t(()=>[...e[18]||(e[18]=[o("p",null,"新建时留空会自动生成,并只显示一次。编辑时留空表示不修改;填写后该账号其他登录会话会立即下线。",-1)])]),_:1})]),default:t(()=>[n(k,{modelValue:d.password,"onUpdate:modelValue":e[3]||(e[3]=l=>d.password=l),type:"password","show-password":"",autocomplete:"new-password",placeholder:"至少 8 位"},null,8,["modelValue"])]),_:1}),m.value?(b(),E(f,{key:0},{label:t(()=>[e[21]||(e[21]=s("启用 ",-1)),n(c,{title:"启用状态"},{default:t(()=>[...e[20]||(e[20]=[o("p",null,"停用账号会立即使其登录会话失效。",-1)])]),_:1})]),default:t(()=>[n(P,{modelValue:d.enabled,"onUpdate:modelValue":e[4]||(e[4]=l=>d.enabled=l)},null,8,["modelValue"])]),_:1})):$("",!0)]),_:1})]),_:1},8,["modelValue","title"])],64)}}}),we=ne(re,[["__scopeId","data-v-f7ba53c9"]]);export{we as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as Fe,n as ll,I as g,J as n,ai as _,o as d,K as de,c as w,e as l,Q as r,S as a,P as m,O as U,R as N,a3 as E,L as He,u as T,U as Be,r as C,q as re,m as le,as as Ke,z as tl,aC as al,aB as nl}from"./vendor-vue-B2uhHUfE.js";import{aj as Ze,E as Z}from"./vendor-element-CZoEjZr8.js";import{H as ol}from"./HelpTip-i-KJhf5s.js";import{u as Qe,k as Je,b as sl}from"./index-UGvfF3Xr.js";import{_ as Ge}from"./_plugin-vue_export-helper-DlAUqK2U.js";const il={class:"setup-panel"},ul={class:"setup-header"},dl={class:"setup-steps","aria-label":"接入配置步骤"},rl=["disabled","onClick"],pl={class:"setup-section"},cl={class:"section-footer"},ml={class:"workspace-selector"},vl={key:2},fl={class:"setup-section"},_l={class:"model-preview"},bl={class:"setup-section"},gl={class:"field-note"},yl={class:"source-heading"},wl={key:2,class:"inline-error"},kl={class:"source-top"},Vl={class:"catalog-action"},$l={key:0,class:"inline-error"},Cl={class:"field-note"},Ul={class:"section-footer"},hl={class:"setup-section"},Sl={class:"check-item"},xl={class:"check-item"},zl=Fe({__name:"AgentSetupPanel",props:{modelValue:{type:Boolean},appId:{},workspaces:{},initialWorkspace:{}},emits:["update:modelValue","saved","connect"],setup(xe,{emit:ge}){const A=xe,z=Qe(),M=ge,ye=["授权入口","系统说明","工具与审批","检查连接"],J=C(0),te=C(!1),ie=C(""),k=C(null),F=C(null),we=C(""),P=C(!1),W=C(""),R=C(null),j=C(""),pe=C(!1),X=C(""),V=C(!1),Y=C([]),b=re({enabled:!1,bucket:"",max_bytes:6291456,allowed_mimes:["image/png","image/jpeg","image/webp"]}),L=re({enabled:!1,instructions:"",active_tool_limit:8}),S=re({name:"",summary:"",domains:[],boundaries:[]}),x=re({enabled:!1,write_tools:[],force_approval_tools:[]}),H=C([]),ce=C([]),ae=C("");let f=0,Pe=0;const q=s=>JSON.parse(JSON.stringify(s)),me=()=>{var s;return k.value?{enabled:k.value.enabled,agent_authorize_url:((s=k.value.agent_authorize_url)==null?void 0:s.trim())||null,allowed_routes:k.value.allowed_routes}:null},ve=le(()=>!!k.value&&JSON.stringify(me())!==we.value),ke=le(()=>A.workspaces.filter(s=>{var e,c;return((e=k.value)==null?void 0:e.allowed_routes.includes("*"))||((c=k.value)==null?void 0:c.allowed_routes.includes(s.route))})),ze=le(()=>A.workspaces.filter(s=>{var e,c;return((e=F.value)==null?void 0:e.allowed_routes.includes("*"))||((c=F.value)==null?void 0:c.allowed_routes.includes(s.route))})),Ve=()=>!!(S.name||S.summary||S.domains.length||S.boundaries.length);function be(){var c,p,h,v;const s={...((c=R.value)==null?void 0:c.agent_client)||{},...L};(b.enabled||(h=(p=R.value)==null?void 0:p.agent_client)!=null&&h.artifact_upload)&&(s.artifact_upload={...q(b),bucket:b.bucket||void 0}),Ve()?s.system_info=q(S):delete s.system_info;const e={...((v=R.value)==null?void 0:v.agent_direct)||{},enabled:x.enabled};return delete e.unattended_write_tools,x.write_tools.length?e.write_tools=[...x.write_tools]:delete e.write_tools,x.force_approval_tools.length?e.force_approval_tools=[...x.force_approval_tools]:delete e.force_approval_tools,{agent_client:s,agent_direct:e,tool_sources:H.value.map(G=>q(G.config))}}const ee=le(()=>!!R.value&&JSON.stringify(be())!==j.value),Ne=le(()=>{const s=new Map;for(const e of H.value)for(const c of e._tools)!c.readonly&&(e.config.allow.includes("*")||e.config.allow.includes(c.scope))&&s.set(c.name,c);return[...s.values()]});function je(s){return s.enabled?s.runtime_enabled?s.direct_enabled?s.source_count?`连接与工具通道已配置${s.system_info_configured?"":";建议补充系统说明"}`:"工具调用已开启;尚未关联工具源":"可配置连接;业务工具调用尚未开启":"尚未启用本地智能体":"工作空间已停用"}async function ne(s,e){const c=await Je(s,e),p=await c.json().catch(()=>({}));if(!c.ok)throw c.status===409?new Error("配置已被其他操作更新。请关闭面板后重新打开,核对最新配置再保存。"):c.status===403?new Error("当前账号没有这部分配置的读取或修改权限,请联系中枢管理员。"):p.error==="agent_setup_unsupported"?new Error("当前宿主尚不支持集中保存,请升级配套宿主后再试。"):new Error(p.error||"请求失败,请稍后重试");return p}async function $e(){Se();const s=++f;te.value=!0;try{const e=await ne(`/admin/api/clients/${encodeURIComponent(A.appId)}/agent-setup`);if(s!==f||!A.modelValue)return;k.value=q(e),F.value=q(e),we.value=JSON.stringify(me());const c=A.initialWorkspace&&ke.value.find(p=>p.route===A.initialWorkspace);c&&(J.value=1,await Ue(c.route))}catch(e){s===f&&(ie.value=oe(e))}finally{s===f&&(te.value=!1)}}function oe(s){return s instanceof Error?s.message:"操作失败"}async function Ce(){var p;if(!k.value||P.value||V.value||!z.can("clients:write"))return;const s=f,e=k.value.app_id,c=q({expected_revision:k.value.revision,...me()});P.value=!0;try{const h=await ne(`/admin/api/clients/${encodeURIComponent(e)}/agent-setup`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)});if(s!==f||((p=k.value)==null?void 0:p.app_id)!==e||!A.modelValue)return;k.value=q(h),F.value=q(h),we.value=JSON.stringify(me()),M("saved"),Z.success("授权入口已保存")}catch(h){s===f&&Z.error(oe(h))}finally{s===f&&(P.value=!1)}}async function Ue(s){if(P.value||V.value||ee.value&&!await fe())return;const e=++f;W.value=s,R.value=null,j.value="",X.value="",pe.value=!0;try{const c=await ne(`/admin/api/routes/${encodeURIComponent(s)}/agent-setup`);if(e!==f||!A.modelValue)return;he(c),Oe(e),z.can("storage:read")&&ne("/admin/api/storage-buckets").then(p=>{e===f&&(Y.value=p.map(h=>({name:h.name,kind:h.kind,enabled:h.enabled})))}).catch(()=>{})}catch(c){e===f&&(X.value=oe(c))}finally{e===f&&(pe.value=!1,te.value=!1)}}function he(s){var p,h,v,G,I,D;R.value=s,Object.assign(b,{enabled:!1,bucket:"",max_bytes:6291456,allowed_mimes:["image/png","image/jpeg","image/webp"]},q(((p=s.agent_client)==null?void 0:p.artifact_upload)||{})),Object.assign(L,{enabled:((h=s.agent_client)==null?void 0:h.enabled)??((v=s.agent_direct)==null?void 0:v.enabled)===!0,instructions:((G=s.agent_client)==null?void 0:G.instructions)||"",active_tool_limit:((I=s.agent_client)==null?void 0:I.active_tool_limit)||8}),Object.assign(S,q(((D=s.agent_client)==null?void 0:D.system_info)||{name:"",summary:"",domains:[],boundaries:[]}));const e=s.agent_direct||{},c=e.write_tools||[];Object.assign(x,{enabled:e.enabled===!0,write_tools:[...c],force_approval_tools:[...e.force_approval_tools||(Array.isArray(e.unattended_write_tools)?c.filter(K=>!e.unattended_write_tools.includes(K)):[])]}),H.value=(s.tool_sources||[]).map(K=>Ie(K)),j.value=JSON.stringify(be())}async function Oe(s){ae.value="";try{const e=await ne("/admin/api/tool-providers");s===f&&(ce.value=e)}catch{s===f&&(ae.value="暂时无法读取工具源目录。现有配置保留,也可以手工填写已登记的工具源标识。")}}function Ie(s={}){return{config:{...q(s),provider:s.provider||"",allow:[...s.allow||[]]},_key:++Pe,_tools:[],_loaded:!1,_loading:!1,_error:""}}function u(){H.value.push(Ie())}function t(s){s._tools=[],s._loaded=!1,s._error=""}function y(s){return[...new Set(s._tools.map(e=>e.scope))]}function O(s,e){return!s.config.allow.includes("*")&&!s.config.allow.includes(e.scope)?"范围未包含":e.readonly?"已纳入查询范围":x.write_tools.includes(e.name)?"已列入写操作清单":"未开放写入"}async function We(s){const e=s.config.provider,c=f;s._loading=!0,s._error="";try{const p=await ne(`/admin/api/tool-providers/${encodeURIComponent(e)}/tools`);if(c!==f||s.config.provider!==e||!H.value.includes(s))return;s._tools=p.tools||[];const h=Array.isArray(p.skipped)?p.skipped.length:Number(p.skipped||0),v=[p.note,h?`${h} 个声明未通过编译`:"",Array.isArray(p.warnings)&&p.warnings.length?`${p.warnings.length} 项目录提醒`:""].filter(Boolean);s._loaded=!p.note,s._error=v.join(";")}catch(p){c===f&&s.config.provider===e&&(s._error=`${oe(p)};这不代表该工具源没有能力。`)}finally{s._loading=!1}}async function Q(){if(!R.value||P.value||V.value||!z.can("routes:write"))return;if(Ve()&&(!S.name.trim()||!S.summary.trim())){Z.warning("填写系统说明时,系统名称和一句话介绍都需要提供。");return}if(S.domains.some(p=>!p.trim()||p.length>120)||S.boundaries.some(p=>!p.trim()||p.length>160)){Z.warning("业务方向每项不超过120字,系统边界每项不超过160字。");return}if([...x.write_tools,...x.force_approval_tools].some(p=>!/^[A-Za-z_][A-Za-z0-9_]*$/.test(p))||x.force_approval_tools.some(p=>!x.write_tools.includes(p))){Z.warning("写操作需要精确operationId;额外审批只能选择已允许的写操作。");return}const s=f,e=W.value,c=q({expected_revision:R.value.revision,...be()});V.value=!0;try{const p=await ne(`/admin/api/routes/${encodeURIComponent(e)}/agent-setup`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)});if(s!==f||W.value!==e||!A.modelValue)return;he(p),M("saved"),Z.success("工作空间配置已保存")}catch(p){s===f&&Z.error(oe(p))}finally{s===f&&(V.value=!1)}}async function fe(){try{return await Ze.confirm("有未保存的修改,离开会放弃这些修改。","离开配置",{confirmButtonText:"放弃修改",cancelButtonText:"继续编辑",type:"warning"}),!0}catch{return!1}}async function _e(s){P.value||V.value||(ve.value||ee.value)&&!await fe()||(M("update:modelValue",!1),s())}function Se(){f++,P.value=!1,V.value=!1,J.value=0,k.value=null,F.value=null,R.value=null,W.value="",H.value=[],ie.value="",X.value="",te.value=!1}return ll(()=>[A.modelValue,A.appId],()=>{A.modelValue&&A.appId&&$e()}),(s,e)=>{const c=_("el-button"),p=_("el-alert"),h=_("el-input"),v=_("el-form-item"),G=_("el-switch"),I=_("el-option"),D=_("el-select"),K=_("el-form"),ue=_("el-empty"),Te=_("el-divider"),Ae=_("router-link"),i=_("el-input-number"),B=_("el-table-column"),Re=_("el-table"),Xe=_("el-collapse-item"),Ye=_("el-collapse"),el=_("el-drawer"),qe=Ke("loading");return d(),g(el,{"model-value":xe.modelValue,size:"min(1080px, 96vw)","with-header":!1,"before-close":_e,onClosed:Se},{default:n(()=>{var De,Le,Me;return[de((d(),w("div",il,[l("header",ul,[l("div",null,[e[18]||(e[18]=l("span",{class:"eyebrow"},"本地智能体接入",-1)),l("h2",null,r(((De=k.value)==null?void 0:De.name)||"配置接入"),1),e[19]||(e[19]=l("p",null,"在这里完成授权入口、系统介绍与工具范围配置。",-1))]),a(c,{onClick:e[0]||(e[0]=o=>_e(()=>M("update:modelValue",!1)))},{default:n(()=>[...e[20]||(e[20]=[m("关闭",-1)])]),_:1})]),ie.value?(d(),g(p,{key:0,type:"error",title:ie.value,closable:!1,"show-icon":""},null,8,["title"])):U("",!0),k.value?(d(),w(N,{key:1},[l("nav",dl,[(d(),w(N,null,E(ye,(o,se)=>l("button",{key:o,class:He({active:J.value===se}),disabled:P.value||V.value,onClick:$=>J.value=se},[l("span",null,r(se+1),1),m(r(o),1)],10,rl)),64))]),de(l("section",pl,[e[25]||(e[25]=l("h3",null,"让用户通过业务系统确认身份",-1)),e[26]||(e[26]=l("p",{class:"description"},"复用当前接入方。账号、租户和业务权限仍由业务授权页确认。",-1)),T(z).can("clients:write")?U("",!0):(d(),g(p,{key:0,type:"info",closable:!1,title:"当前账号可查看授权入口,保存需要接入方管理权限。"})),a(K,{"label-position":"top",disabled:P.value||!T(z).can("clients:write")},{default:n(()=>[a(v,{label:"接入方标识"},{default:n(()=>[a(h,{"model-value":k.value.app_id,readonly:""},null,8,["model-value"])]),_:1}),a(v,{label:"允许此接入方连接中枢"},{default:n(()=>[a(G,{modelValue:k.value.enabled,"onUpdate:modelValue":e[1]||(e[1]=o=>k.value.enabled=o)},null,8,["modelValue"]),e[21]||(e[21]=l("span",{class:"inline-note"},"停用会影响此接入方的其他入口。",-1))]),_:1}),a(v,{label:"业务授权入口"},{default:n(()=>[a(h,{modelValue:k.value.agent_authorize_url,"onUpdate:modelValue":e[2]||(e[2]=o=>k.value.agent_authorize_url=o),placeholder:"https://business.example.com/agent/authorize",maxlength:"2048"},null,8,["modelValue"]),e[22]||(e[22]=l("div",{class:"field-note"},"填写业务系统提供的固定 HTTPS 地址。用户将在该页面登录并确认本次授权。",-1))]),_:1}),a(v,{label:"允许连接的工作空间"},{default:n(()=>[a(D,{modelValue:k.value.allowed_routes,"onUpdate:modelValue":e[3]||(e[3]=o=>k.value.allowed_routes=o),multiple:"",filterable:"","allow-create":"","default-first-option":"",style:{width:"100%"},placeholder:"选择已存在的工作空间"},{default:n(()=>[(d(!0),w(N,null,E(xe.workspaces,o=>(d(),g(I,{key:o.route,label:`${o.name} · ${o.route}`,value:o.route},null,8,["label","value"]))),128)),a(I,{value:"*",label:"所有工作空间(包含以后新增的空间)"})]),_:1},8,["modelValue"]),e[23]||(e[23]=l("div",{class:"field-note"},"工作空间对应中枢现有业务路由。这里限定接入范围,不授予业务账号额外权限。",-1))]),_:1})]),_:1},8,["disabled"]),l("div",cl,[l("span",null,r(ve.value?"授权入口有未保存修改":"授权入口配置已同步"),1),a(c,{type:"primary",loading:P.value,disabled:!ve.value||!T(z).can("clients:write"),onClick:Ce},{default:n(()=>[...e[24]||(e[24]=[m("保存授权入口",-1)])]),_:1},8,["loading","disabled"])])],512),[[Be,J.value===0]]),J.value===1||J.value===2?(d(),w(N,{key:0},[l("div",ml,[e[27]||(e[27]=l("div",null,[l("b",null,"配置哪个工作空间"),l("p",null,"以下设置保存在原业务路由中,使用同一路由的接入方会共享这些设置。")],-1)),a(D,{"model-value":W.value,disabled:P.value||V.value,filterable:"",placeholder:"选择一个工作空间",onChange:Ue},{default:n(()=>[(d(!0),w(N,null,E(ke.value,o=>(d(),g(I,{key:o.route,label:`${o.name} · ${o.route}`,value:o.route},null,8,["label","value"]))),128))]),_:1},8,["model-value","disabled"])]),X.value?(d(),g(p,{key:0,type:"error",title:X.value,closable:!1,"show-icon":""},null,8,["title"])):U("",!0),W.value?U("",!0):(d(),g(ue,{key:1,description:ke.value.length?"在上方选择要配置的工作空间。":"还没有可选工作空间,请先在授权入口中关联一个已有空间。"},null,8,["description"])),W.value?de((d(),w("div",vl,[R.value?(d(),w(N,{key:0},[R.value.enabled?U("",!0):(d(),g(p,{key:0,title:"这个工作空间已停用。完成配置后,还需在业务路由中恢复空间运行。",type:"warning",closable:!1,"show-icon":""})),de(l("section",fl,[e[31]||(e[31]=l("h3",null,"让智能体先知道这个系统负责什么",-1)),e[32]||(e[32]=l("p",{class:"description"},"说明会在首次搜索工具前提供给已选中的授权。它描述系统定位,具体可执行动作仍以授权后的工具查询为准。",-1)),a(K,{"label-position":"top",disabled:V.value||!T(z).can("routes:write")},{default:n(()=>[a(v,{label:"启用本地智能体"},{default:n(()=>[a(G,{modelValue:L.enabled,"onUpdate:modelValue":e[4]||(e[4]=o=>L.enabled=o)},null,8,["modelValue"]),e[28]||(e[28]=l("span",{class:"inline-note"},"开启本地会话编排;工具调用在下一步单独设置。",-1))]),_:1}),a(v,{label:"业务系统名称"},{default:n(()=>[a(h,{modelValue:S.name,"onUpdate:modelValue":e[5]||(e[5]=o=>S.name=o),placeholder:"例如:客户服务系统",maxlength:"120","show-word-limit":""},null,8,["modelValue"])]),_:1}),a(v,{label:"一句话介绍"},{default:n(()=>[a(h,{modelValue:S.summary,"onUpdate:modelValue":e[6]||(e[6]=o=>S.summary=o),placeholder:"例如:处理客户咨询、服务工单和售后跟进。",maxlength:"400","show-word-limit":""},null,8,["modelValue"])]),_:1}),a(v,{label:"典型业务方向"},{default:n(()=>[a(D,{modelValue:S.domains,"onUpdate:modelValue":e[7]||(e[7]=o=>S.domains=o),multiple:"",filterable:"","allow-create":"","default-first-option":"","multiple-limit":6,style:{width:"100%"},placeholder:"输入一个方向后按回车,最多6项"},{default:n(()=>[(d(!0),w(N,null,E(S.domains,o=>(d(),g(I,{key:o,label:o,value:o},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])]),_:1}),a(v,{label:"系统边界"},{default:n(()=>[a(D,{modelValue:S.boundaries,"onUpdate:modelValue":e[8]||(e[8]=o=>S.boundaries=o),multiple:"",filterable:"","allow-create":"","default-first-option":"","multiple-limit":6,style:{width:"100%"},placeholder:"例如:财务结算由其他系统负责;最多6项"},{default:n(()=>[(d(!0),w(N,null,E(S.boundaries,o=>(d(),g(I,{key:o,label:o,value:o},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])]),_:1})]),_:1},8,["disabled"]),l("div",_l,[e[29]||(e[29]=l("span",null,"智能体看到的系统定位",-1)),l("b",null,r(S.name||"系统定位未提供"),1),l("p",null,r(S.summary||"尚未配置说明,客户端仍可按原流程查询已授权的业务工具。"),1),e[30]||(e[30]=l("small",null,"说明仅供目标选择参考 · 工具可能尚未加载 · 不代表已获得写入权限",-1))])],512),[[Be,J.value===1]]),de(l("section",bl,[e[47]||(e[47]=l("h3",null,"限定智能体可以使用的业务动作",-1)),e[48]||(e[48]=l("p",{class:"description"},"工作空间的工具源与范围继续复用原配置。开启后仍会逐次校验业务身份、权限和审批。",-1)),R.value.permission==="readonly"?(d(),g(p,{key:0,title:"这个工作空间的权限档为只读。即使填写写操作清单,也不会开放写入;如需调整,请在业务路由的权限与治理中核对。",type:"warning",closable:!1,"show-icon":""})):U("",!0),a(K,{"label-position":"top",disabled:V.value||!T(z).can("routes:write")},{default:n(()=>[a(v,{label:"允许本地智能体调用工具"},{default:n(()=>[a(G,{modelValue:x.enabled,"onUpdate:modelValue":e[9]||(e[9]=o=>x.enabled=o)},null,8,["modelValue"])]),_:1}),L.enabled&&!x.enabled?(d(),g(p,{key:0,title:"本地会话已启用,但业务工具调用未开启。用户可以完成授权,暂时无法通过此空间发现或操作业务工具。",type:"warning",closable:!1,"show-icon":""})):U("",!0),a(Te,{"content-position":"left"},{default:n(()=>[...e[33]||(e[33]=[m("生成图片上传",-1)])]),_:1}),a(v,{label:"允许上传生成图片"},{default:n(()=>[a(G,{modelValue:b.enabled,"onUpdate:modelValue":e[10]||(e[10]=o=>b.enabled=o)},null,8,["modelValue"]),e[34]||(e[34]=l("div",{class:"field-note"},"将智能体生成的图片保存到所选媒体存储,返回 URL 供商品等业务使用。上传不等于已修改业务数据。",-1))]),_:1}),b.enabled?(d(),w(N,{key:1},[a(v,{label:"保存到哪个媒体存储"},{default:n(()=>[a(D,{modelValue:b.bucket,"onUpdate:modelValue":e[11]||(e[11]=o=>b.bucket=o),filterable:"","allow-create":"",placeholder:"选择已登记的存储",style:{width:"100%"}},{default:n(()=>[(d(!0),w(N,null,E(Y.value,o=>(d(),g(I,{key:o.name,value:o.name,label:`${o.name} · ${o.kind}${o.enabled?"":"(已停用)"}`,disabled:!o.enabled},null,8,["value","label","disabled"]))),128))]),_:1},8,["modelValue"]),l("div",gl,[a(Ae,{to:"/storage"},{default:n(()=>[...e[35]||(e[35]=[m("前往媒体存储配置 COS/OSS 或本地存储",-1)])]),_:1}),e[36]||(e[36]=m("。此处不填写密钥。文件由部署方管理,不随会话结束清理。",-1))])]),_:1}),a(v,{label:"单张图片大小上限(字节)"},{default:n(()=>[a(i,{modelValue:b.max_bytes,"onUpdate:modelValue":e[12]||(e[12]=o=>b.max_bytes=o),min:1,max:6291456},null,8,["modelValue"]),e[37]||(e[37]=l("span",{class:"inline-note"},"默认 6 MiB",-1))]),_:1}),a(v,{label:"允许的图片类型"},{default:n(()=>[a(D,{modelValue:b.allowed_mimes,"onUpdate:modelValue":e[13]||(e[13]=o=>b.allowed_mimes=o),multiple:""},{default:n(()=>[(d(),w(N,null,E(["image/png","image/jpeg","image/webp"],o=>a(I,{key:o,label:o,value:o},null,8,["label","value"])),64))]),_:1},8,["modelValue"])]),_:1})],64)):U("",!0),a(Te,{"content-position":"left"},{default:n(()=>[...e[38]||(e[38]=[m("业务工具",-1)])]),_:1}),l("div",yl,[e[40]||(e[40]=l("b",null,"使用哪些工具源",-1)),a(c,{size:"small",disabled:V.value||!T(z).can("routes:write"),onClick:u},{default:n(()=>[...e[39]||(e[39]=[m("添加工具源",-1)])]),_:1},8,["disabled"])]),ae.value?(d(),w("p",wl,r(ae.value),1)):U("",!0),H.value.length?U("",!0):(d(),g(ue,{key:3,description:"尚未关联工具源。添加已有业务工具源并选择范围。","image-size":56})),(d(!0),w(N,null,E(H.value,(o,se)=>(d(),w("div",{class:"source-card",key:o._key},[l("div",kl,[l("b",null,"工具源 "+r(se+1),1),a(c,{link:"",type:"danger",disabled:V.value||!T(z).can("routes:write"),onClick:$=>H.value.splice(se,1)},{default:n(()=>[...e[41]||(e[41]=[m("移除",-1)])]),_:1},8,["disabled","onClick"])]),a(v,{label:"已登记的工具源"},{default:n(()=>[a(D,{modelValue:o.config.provider,"onUpdate:modelValue":$=>o.config.provider=$,filterable:"","allow-create":"",style:{width:"100%"},onChange:$=>t(o)},{default:n(()=>[(d(!0),w(N,null,E(ce.value,$=>(d(),g(I,{key:$.name,value:$.name,label:$.description?`${$.name} · ${$.description}`:$.name},null,8,["value","label"]))),128))]),_:1},8,["modelValue","onUpdate:modelValue","onChange"])]),_:2},1024),a(v,{label:"允许的工具范围(scope)"},{default:n(()=>[a(D,{modelValue:o.config.allow,"onUpdate:modelValue":$=>o.config.allow=$,multiple:"",filterable:"","allow-create":"","default-first-option":"",style:{width:"100%"},placeholder:"选择范围或输入精确scope"},{default:n(()=>[(d(!0),w(N,null,E(y(o),$=>(d(),g(I,{key:$,value:$,label:$},null,8,["value","label"]))),128)),a(I,{value:"*",label:"全部scope(包含该工具源以后新增的scope)"})]),_:2},1032,["modelValue","onUpdate:modelValue"]),e[42]||(e[42]=l("div",{class:"field-note"},"只读工具按范围开放;写操作还需要下方的精确清单。",-1))]),_:2},1024),l("div",Vl,[a(c,{size:"small",disabled:!o.config.provider,loading:o._loading,onClick:$=>We(o)},{default:n(()=>[...e[43]||(e[43]=[m("读取工具目录",-1)])]),_:1},8,["disabled","loading","onClick"]),l("span",null,r(o._loaded?`${o._tools.length} 个已声明工具`:"尚未读取目录,可手工填写已知scope和操作标识"),1)]),o._error?(d(),w("p",$l,r(o._error),1)):U("",!0),o._tools.length?(d(),g(Re,{key:1,data:o._tools,size:"small","max-height":"240",style:{"margin-top":"14px"}},{default:n(()=>[a(B,{label:"业务动作","min-width":"200","show-overflow-tooltip":""},{default:n(({row:$})=>[l("span",null,r($.description||$.name),1),l("div",Cl,r($.name),1)]),_:1}),a(B,{label:"类型",width:"70"},{default:n(({row:$})=>[m(r($.readonly?"查询":"写入"),1)]),_:1}),a(B,{label:"当前配置","min-width":"150"},{default:n(({row:$})=>[m(r(O(o,$)),1)]),_:2},1024)]),_:2},1032,["data"])):U("",!0)]))),128)),a(v,{label:"允许的写操作",class:"write-field"},{default:n(()=>[a(D,{modelValue:x.write_tools,"onUpdate:modelValue":e[14]||(e[14]=o=>x.write_tools=o),multiple:"",filterable:"","allow-create":"","default-first-option":"",style:{width:"100%"},placeholder:"留空时不开放写操作;只接受精确operationId"},{default:n(()=>[(d(!0),w(N,null,E(Ne.value,o=>(d(),g(I,{key:o.name,value:o.name,label:`${o.name} · ${o.scope}${o.confirm_required||o.risk==="high"?" · 原规则需审批":""}`},null,8,["value","label"]))),128))]),_:1},8,["modelValue"]),e[44]||(e[44]=l("div",{class:"field-note"},"不能填写 *。选中的操作仍须通过原 scope、主体、风险与审批规则。",-1))]),_:1}),a(v,{label:"额外要求审批的写操作"},{default:n(()=>[a(D,{modelValue:x.force_approval_tools,"onUpdate:modelValue":e[15]||(e[15]=o=>x.force_approval_tools=o),multiple:"",filterable:"",style:{width:"100%"},placeholder:"可进一步收紧审批要求"},{default:n(()=>[(d(!0),w(N,null,E(x.write_tools,o=>(d(),g(I,{key:o,value:o,label:o},null,8,["value","label"]))),128))]),_:1},8,["modelValue"]),e[45]||(e[45]=l("div",{class:"field-note"},"这里只增加审批要求,不会取消工具本身要求的审批。",-1))]),_:1})]),_:1},8,["disabled"]),a(Ye,null,{default:n(()=>[a(Xe,{title:"高级运行设置",name:"advanced"},{default:n(()=>[a(K,{"label-position":"top",disabled:V.value||!T(z).can("routes:write")},{default:n(()=>[a(v,{label:"每轮主动加载的工具上限"},{default:n(()=>[a(i,{modelValue:L.active_tool_limit,"onUpdate:modelValue":e[16]||(e[16]=o=>L.active_tool_limit=o),min:1,max:12},null,8,["modelValue"])]),_:1}),a(v,{label:"本地编排补充规则"},{default:n(()=>[a(h,{modelValue:L.instructions,"onUpdate:modelValue":e[17]||(e[17]=o=>L.instructions=o),type:"textarea",rows:3,maxlength:"20000"},null,8,["modelValue"]),e[46]||(e[46]=l("div",{class:"field-note"},"延续已有运行规则;系统介绍应填写在上一步。",-1))]),_:1})]),_:1},8,["disabled"])]),_:1})]),_:1})],512),[[Be,J.value===2]]),l("div",Ul,[l("span",null,r(T(z).can("routes:write")?ee.value?"工作空间有未保存修改":"工作空间配置已同步":"当前账号没有工作空间修改权限"),1),a(c,{type:"primary",loading:V.value,disabled:!ee.value||!T(z).can("routes:write"),onClick:Q},{default:n(()=>[...e[49]||(e[49]=[m("保存工作空间",-1)])]),_:1},8,["loading","disabled"])])],64)):U("",!0)])),[[qe,pe.value]]):U("",!0)],64)):U("",!0),de(l("section",hl,[e[53]||(e[53]=l("h3",null,"检查已保存的接入配置",-1)),e[54]||(e[54]=l("p",{class:"description"},"连接配置只包含中枢地址、接入方和工作空间。用户登录后,实际可用工具会按原业务授权确定。",-1)),ve.value||ee.value?(d(),g(p,{key:0,title:"还有未保存的修改。下方状态和连接配置仅反映已保存内容。",type:"warning",closable:!1,"show-icon":""})):U("",!0),l("div",Sl,[e[50]||(e[50]=l("span",null,"接入方",-1)),l("b",null,r((Le=F.value)!=null&&Le.enabled?"已启用":"已停用"),1)]),l("div",xl,[e[51]||(e[51]=l("span",null,"业务授权入口",-1)),l("b",null,r((Me=F.value)!=null&&Me.agent_authorize_url?"已配置":"尚未配置"),1)]),(d(!0),w(N,null,E(ze.value,o=>{var se,$;return d(),w("div",{key:o.route,class:"workspace-result"},[l("div",null,[l("b",null,r(o.name),1),l("code",null,r(o.route),1)]),l("p",null,r(je(o)),1),a(c,{type:"primary",plain:"",size:"small",disabled:!((se=F.value)!=null&&se.enabled)||!(($=F.value)!=null&&$.agent_authorize_url)||!o.enabled||!o.runtime_enabled,onClick:ft=>M("connect",{app_id:k.value.app_id,workspace:o.route})},{default:n(()=>[...e[52]||(e[52]=[m("生成连接配置",-1)])]),_:1},8,["disabled","onClick"])])}),128)),ze.value.length?U("",!0):(d(),g(ue,{key:1,description:"尚无可连接的工作空间。请先保存授权入口配置。","image-size":70})),e[55]||(e[55]=l("p",{class:"field-note"},"系统说明缺失不会阻断已有连接;工具范围与服务可用性将在授权后进一步校验。",-1))],512),[[Be,J.value===3]])],64)):U("",!0)])),[[qe,te.value]])]}),_:1},8,["model-value"])}}}),Nl=Ge(zl,[["__scopeId","data-v-4099c86e"]]),jl={class:"agent-clients-page"},Ol={class:"page-navigation"},Il={class:"actions"},Tl={class:"head"},Al={class:"actions"},Rl={class:"overview"},Bl={class:"metric primary"},El={class:"metric"},Jl={class:"metric"},Pl={class:"metric"},Wl={class:"metric"},ql={class:"section-head"},Dl={key:0,class:"muted"},Ll={class:"stack"},Ml={class:"stack"},Fl={class:"muted"},Hl={class:"tags"},Kl={class:"stack right"},Zl={class:"muted"},Ql={class:"section-head"},Gl={class:"actions"},Xl={class:"stack"},Yl={class:"subject-name"},et={class:"muted"},lt={class:"stack"},tt={class:"stack"},at={class:"muted"},nt={class:"stack"},ot={class:"muted"},st={class:"stack"},it={class:"muted"},ut={key:1,class:"muted"},dt={key:2,class:"pagination"},rt={class:"subject-name"},pt={class:"form-grid"},ct={class:"code-block"},mt={class:"code-block"},Ee=50,vt=Fe({__name:"AgentClients",setup(xe){const ge=al(),A=Qe(),z=nl(),M=C("setup"),ye=C(30),J=C(!1),te=C(!1),ie=C(""),k=C([]),F=le(()=>{const u=z.query.workspace;return typeof u=="string"?k.value.filter(t=>t.allowed_routes.includes("*")||t.allowed_routes.includes(u)):k.value}),we=C([]),P=C([]),W=re({open:!1,appId:"",workspace:""}),R=C([]),j=C(null),pe=C(0),X=C(1),V=re({applications:0,agent_auth_enabled:0,sessions:{},runs:0,conversations:0,failed:0,tool_calls:0,total_tokens:0,failure_rate:0,approvals:{}}),Y=re({client_app_id:"",state:"all"}),b=re({open:!1,app_id:"",name:"",workspace:"",workspaces:[]}),L=le(()=>sl()),S=le(()=>Object.values(V.approvals||{}).reduce((u,t)=>u+Number(t||0),0)),x=le(()=>JSON.stringify({hubUrl:L.value,clientAppId:b.app_id,workspace:b.workspace,connectionName:b.name.trim()||"default"},null,2)),H=le(()=>`/bailinghub connections add ${ae(b.name.trim()||"default")} ${ae(L.value)} ${ae(b.app_id)} ${ae(b.workspace)}`);function ce(u){var y;const t=(y=u.subject_display)==null?void 0:y.name;return u.subject_display_status==="provided"&&typeof t=="string"?t:""}function ae(u){return JSON.stringify(u)}function f(u){return new Intl.NumberFormat("zh-CN").format(Number(u||0))}function Pe(u){return`${(Number(u||0)*100).toFixed(1)}%`}function q(u){return u?`${u.slice(0,8)}…${u.slice(-4)}`:"—"}function me(u){return u?new Date(u).toLocaleString("zh-CN",{hour12:!1}):"从未"}function ve(u){return u==="active"?"有效":u==="expired"?"已过期":"已撤销"}function ke(u){return u==="active"?"success":u==="expired"?"warning":"info"}function ze(u){return u.includes("*")?["全部 Workspace"]:u.slice(0,4)}function Ve(u){return P.value.filter(t=>u.allowed_routes.includes("*")||u.allowed_routes.includes(t.route))}function be(u){return Ve(u).filter(t=>t.enabled&&t.runtime_enabled)}function ee(u){return u.enabled&&u.agent_auth_enabled&&be(u).length>0}function Ne(u){if(!u.enabled)return"接入方已停用,需先恢复接入";if(!u.agent_auth_enabled)return"尚未配置业务授权入口";const t=Ve(u);if(!t.length)return"尚未关联现有工作空间";const y=t.filter(O=>O.enabled&&O.runtime_enabled);return y.length?y.some(O=>O.direct_enabled)?y.some(O=>O.direct_enabled&&O.source_count)?y.some(O=>!O.system_info_configured)?"建议补充系统说明,帮助智能体首次选择目标":"连接与工具通道已配置;实际可用动作以业务授权为准":"工具通道已开启;尚需配置业务工具源":"连接入口已准备好;业务工具调用尚未开启":"尚无已启用本地智能体的工作空间"}function je(u,t=""){W.appId=u.app_id,W.workspace=t,W.open=!0}function ne(u){const t=k.value.find(y=>y.app_id===u.app_id);t&&(he(t),b.workspace=u.workspace)}async function $e(){J.value=!0;try{const u=await Je(`/admin/api/agent-clients/overview?days=${ye.value}`);if(!u.ok)throw new Error((await u.json().catch(()=>({}))).error||"加载失败");const t=await u.json();k.value=t.applications||[],we.value=t.workspaces||[],P.value=t.setup_workspaces||[],Object.assign(V,t.summary||{})}catch(u){Z.error(u instanceof Error?u.message:"加载智能体客户端失败")}finally{J.value=!1}}async function oe(){te.value=!0;try{const u=new URLSearchParams({state:Y.state,limit:String(Ee),offset:String((X.value-1)*Ee)});Y.client_app_id&&u.set("client_app_id",Y.client_app_id);const t=await Je(`/admin/api/agent-clients/sessions?${u}`);if(!t.ok)throw new Error((await t.json().catch(()=>({}))).error||"加载失败");const y=await t.json();R.value=y.list||[],pe.value=Number(y.total||0)}catch(u){Z.error(u instanceof Error?u.message:"加载授权设备失败")}finally{te.value=!1}}async function Ce(){await Promise.all([$e(),oe()])}async function Ue(){X.value=1,await oe()}function he(u){var y;const t=be(u);b.app_id=u.app_id,b.name=u.app_id.replace(/[^a-zA-Z0-9._-]+/g,"-").replace(/^-+|-+$/g,"")||"default",b.workspaces=t,b.workspace=((y=t[0])==null?void 0:y.route)||"",b.open=!0}async function Oe(u){await navigator.clipboard.writeText(u),Z.success("已复制")}async function Ie(u){await Ze.confirm(`撤销设备“${u.device_label||q(u.session_id)}”的 Agent Session?撤销后需要重新登录授权。`,"远程撤销",{type:"warning",confirmButtonText:"确认撤销"}),ie.value=u.session_id;try{const t=await Je(`/admin/api/agent-clients/sessions/${u.session_id}/revoke`,{method:"POST"});if(!t.ok)throw new Error((await t.json().catch(()=>({}))).error||"撤销失败");Z.success("Agent Session 已撤销"),await Ce()}catch(t){Z.error(t instanceof Error?t.message:"撤销失败")}finally{ie.value=""}}return tl(async()=>{await Ce();const u=typeof z.query.workspace=="string"?z.query.workspace:"",t=typeof z.query.app=="string"?z.query.app:"",y=k.value.filter(O=>t?O.app_id===t:u&&(O.allowed_routes.includes("*")||O.allowed_routes.includes(u)));y.length===1&&je(y[0],u)}),(u,t)=>{const y=_("el-button"),O=_("el-radio-button"),We=_("el-radio-group"),Q=_("el-option"),fe=_("el-select"),_e=_("el-card"),Se=_("el-empty"),s=_("el-table-column"),e=_("el-tag"),c=_("el-tooltip"),p=_("el-table"),h=_("el-pagination"),v=_("el-descriptions-item"),G=_("el-descriptions"),I=_("el-dialog"),D=_("el-alert"),K=_("el-input"),ue=_("el-form-item"),Te=_("el-form"),Ae=Ke("loading");return d(),w("div",jl,[l("div",Ol,[t[19]||(t[19]=l("div",null,[l("b",null,"本地智能体"),l("span",null,"配置接入与管理授权设备")],-1)),l("div",Il,[T(A).can("clients:read")&&T(A).hasModule("agent-tasks")?(d(),g(y,{key:0,onClick:t[0]||(t[0]=i=>T(ge).push("/agent-tasks"))},{default:n(()=>[...t[16]||(t[16]=[m("任务控制",-1)])]),_:1})):U("",!0),a(We,{modelValue:M.value,"onUpdate:modelValue":t[1]||(t[1]=i=>M.value=i)},{default:n(()=>[a(O,{value:"setup"},{default:n(()=>[...t[17]||(t[17]=[m("接入配置",-1)])]),_:1}),a(O,{value:"activity"},{default:n(()=>[...t[18]||(t[18]=[m("设备与运行",-1)])]),_:1})]),_:1},8,["modelValue"])])]),M.value==="activity"?(d(),g(_e,{key:0,shadow:"never"},{header:n(()=>[l("div",Tl,[l("div",null,[t[21]||(t[21]=l("b",null,"智能体客户端",-1)),a(ol,{title:"和执行器有什么区别"},{default:n(()=>[...t[20]||(t[20]=[l("p",null,[l("b",null,"智能体客户端"),m("在本地理解用户意图、选择能力并完成多步编排;中枢继续负责业务身份、授权、审批、执行与审计。")],-1),l("p",null,[l("b",null,"执行器"),m("是中枢下发 Job、由本地运行时执行本地任务后回报结果。两者是独立概念。")],-1),l("p",null,"在“配置接入”中集中设置授权入口、系统说明和工具范围;设置仍保存在原接入方与业务路由中。",-1),l("p",null,"每个接入方只配置一个不绑定账号、租户或门店的业务授权入口;账号切换与租户选择由业务授权页完成。",-1)])]),_:1})]),l("div",Al,[a(fe,{modelValue:ye.value,"onUpdate:modelValue":t[2]||(t[2]=i=>ye.value=i),size:"small",style:{width:"108px"},onChange:$e},{default:n(()=>[a(Q,{value:7,label:"近 7 天"}),a(Q,{value:30,label:"近 30 天"}),a(Q,{value:90,label:"近 90 天"})]),_:1},8,["modelValue"]),a(y,{size:"small",loading:J.value,onClick:Ce},{default:n(()=>[...t[22]||(t[22]=[m("刷新",-1)])]),_:1},8,["loading"])])])]),default:n(()=>{var i,B;return[de((d(),w("div",Rl,[l("div",Bl,[t[23]||(t[23]=l("span",null,"客户端应用",-1)),l("b",null,r(f(V.agent_auth_enabled)),1),l("em",null,"共 "+r(f(V.applications))+" 个接入方",1)]),l("div",El,[t[24]||(t[24]=l("span",null,"有效授权设备",-1)),l("b",null,r(f((i=V.sessions)==null?void 0:i.active)),1),l("em",null,"总会话 "+r(f((B=V.sessions)==null?void 0:B.total)),1)]),l("div",Jl,[t[25]||(t[25]=l("span",null,"Agent Run",-1)),l("b",null,r(f(V.runs)),1),l("em",null,r(f(V.conversations))+" 个本地会话",1)]),l("div",Pl,[t[26]||(t[26]=l("span",null,"工具调用",-1)),l("b",null,r(f(V.tool_calls)),1),l("em",null,"审批 "+r(f(S.value))+" 次",1)]),l("div",Wl,[t[27]||(t[27]=l("span",null,"累计 Token",-1)),l("b",null,r(f(V.total_tokens)),1),t[28]||(t[28]=l("em",null,"由客户端公开 usage 汇总",-1))]),l("div",{class:He(["metric",{danger:Number(V.failure_rate||0)>.1}])},[t[29]||(t[29]=l("span",null,"失败率",-1)),l("b",null,r(Pe(V.failure_rate)),1),l("em",null,r(f(V.failed))+" 个失败或取消",1)],2)])),[[Ae,J.value]])]}),_:1})):U("",!0),M.value==="setup"?(d(),g(_e,{key:1,shadow:"never",class:"setup-intro"},{default:n(()=>[...t[30]||(t[30]=[l("div",null,[l("span",{class:"intro-kicker"},"从接入到业务操作"),l("h2",null,"把一个业务系统接给本地智能体"),l("p",null,"选中下方应用,按顺序完成授权入口、系统说明和工具范围。连接、业务授权与实际执行分别检查。")],-1),l("div",{class:"intro-flow"},[l("span",null,"1 授权入口"),l("i",null,"→"),l("span",null,"2 系统说明"),l("i",null,"→"),l("span",null,"3 工具与审批"),l("i",null,"→"),l("span",null,"4 检查连接")],-1)])]),_:1})):U("",!0),M.value==="setup"?(d(),g(_e,{key:2,shadow:"never"},{header:n(()=>[l("div",ql,[t[32]||(t[32]=l("div",null,[l("b",null,"业务系统接入"),l("span",null,"在一个入口完成本地智能体配置;授权记录与用量请切换到“设备与运行”。")],-1)),a(y,{size:"small",onClick:t[3]||(t[3]=i=>T(ge).push("/clients"))},{default:n(()=>[...t[31]||(t[31]=[m("新建接入方",-1)])]),_:1})])]),default:n(()=>[T(z).query.workspace?(d(),w("p",Dl,[m("以下为允许使用工作空间 "+r(T(z).query.workspace)+" 的接入方,请选择要配置的应用。",1),a(y,{link:"",onClick:t[4]||(t[4]=i=>T(ge).replace("/agent-clients"))},{default:n(()=>[...t[33]||(t[33]=[m("显示全部",-1)])]),_:1})])):U("",!0),F.value.length?(d(),g(p,{key:2,data:F.value,size:"small"},{default:n(()=>[a(s,{label:"应用",width:180},{default:n(({row:i})=>[l("div",Ll,[l("b",null,r(i.name||i.app_id),1),l("code",null,r(i.app_id),1)])]),_:1}),a(s,{label:"接入配置状态","min-width":270},{default:n(({row:i})=>[l("div",Ml,[l("div",null,[a(e,{size:"small",effect:"plain",type:ee(i)?"success":"warning"},{default:n(()=>[m(r(ee(i)?"连接条件已配置":"待完成配置"),1)]),_:2},1032,["type"])]),l("span",Fl,r(Ne(i)),1)])]),_:1}),a(s,{label:"工作空间",width:180},{default:n(({row:i})=>[l("div",Hl,[(d(!0),w(N,null,E(ze(i.allowed_routes),B=>(d(),g(e,{key:B,size:"small",effect:"plain",type:"info"},{default:n(()=>[m(r(B),1)]),_:2},1024))),128))])]),_:1}),a(s,{label:"近期开销",width:150,align:"right"},{default:n(({row:i})=>[l("div",Kl,[l("span",null,r(f(i.stats.runs))+" Run / "+r(f(i.stats.tool_calls))+" 调用",1),l("span",Zl,r(f(i.stats.total_tokens))+" Token",1)])]),_:1}),a(s,{width:210,align:"right"},{default:n(({row:i})=>[a(y,{size:"small",type:"primary",plain:"",onClick:B=>je(i)},{default:n(()=>[...t[34]||(t[34]=[m("配置接入",-1)])]),_:1},8,["onClick"]),a(c,{content:ee(i)?"复制公开连接信息,随后在客户端登录授权":Ne(i)},{default:n(()=>[l("span",null,[a(y,{link:"",disabled:!ee(i),onClick:B=>he(i)},{default:n(()=>[...t[35]||(t[35]=[m("连接配置",-1)])]),_:1},8,["disabled","onClick"])])]),_:2},1032,["content"])]),_:1})]),_:1},8,["data"])):(d(),g(Se,{key:1,description:"当前没有匹配的接入方,请先创建接入方并关联工作空间。"}))]),_:1})):U("",!0),M.value==="activity"?(d(),g(_e,{key:3,shadow:"never"},{header:n(()=>[l("div",Ql,[t[36]||(t[36]=l("div",null,[l("b",null,"业务授权与设备"),l("span",null,"授权名称由业务系统同步;设备名称用于区分使用端。远程撤销后需要重新登录授权。")],-1)),l("div",Gl,[a(fe,{modelValue:Y.client_app_id,"onUpdate:modelValue":t[5]||(t[5]=i=>Y.client_app_id=i),clearable:"",filterable:"",size:"small",placeholder:"全部应用",style:{width:"190px"},onChange:Ue},{default:n(()=>[(d(!0),w(N,null,E(k.value,i=>(d(),g(Q,{key:i.app_id,label:i.name||i.app_id,value:i.app_id},null,8,["label","value"]))),128))]),_:1},8,["modelValue"]),a(fe,{modelValue:Y.state,"onUpdate:modelValue":t[6]||(t[6]=i=>Y.state=i),size:"small",style:{width:"112px"},onChange:Ue},{default:n(()=>[a(Q,{value:"all",label:"全部状态"}),a(Q,{value:"active",label:"有效"}),a(Q,{value:"expired",label:"已过期"}),a(Q,{value:"revoked",label:"已撤销"})]),_:1},8,["modelValue"])])])]),default:n(()=>[R.value.length?de((d(),g(p,{key:1,data:R.value,size:"small","row-key":"session_id"},{default:n(()=>[a(s,{label:"授权名称","min-width":180},{default:n(({row:i})=>[l("div",Xl,[l("b",Yl,r(ce(i)||"待同步"),1),l("span",et,r(ce(i)?"业务系统提供":"业务系统尚未提供名称"),1)])]),_:1}),a(s,{label:"设备",width:170},{default:n(({row:i})=>[l("div",lt,[l("b",null,r(i.device_label||"未命名设备"),1),l("code",null,r(q(i.session_id)),1)])]),_:1}),a(s,{label:"业务主体",width:150},{default:n(({row:i})=>{var B,Re;return[l("div",tt,[l("span",null,r(((B=i.principal)==null?void 0:B.id)||i.on_behalf_of),1),l("span",at,r(((Re=i.principal)==null?void 0:Re.tenant)||"未声明租户"),1)])]}),_:1}),a(s,{label:"应用 / Workspace","min-width":190},{default:n(({row:i})=>[l("div",nt,[l("code",null,r(i.client_app_id),1),l("span",ot,r((i.allowed_routes||[]).join("、")||"无可用路由"),1)])]),_:1}),a(s,{label:"活跃与有效期",width:185},{default:n(({row:i})=>[l("div",st,[l("span",null,"活跃 "+r(me(i.last_seen_at)),1),l("span",it,"到期 "+r(me(i.refresh_expires_at)),1)])]),_:1}),a(s,{label:"状态",width:80},{default:n(({row:i})=>[a(e,{size:"small",effect:"plain",type:ke(i.state)},{default:n(()=>[m(r(ve(i.state)),1)]),_:2},1032,["type"])]),_:1}),a(s,{width:130,align:"right"},{default:n(({row:i})=>[a(y,{link:"",onClick:B=>j.value=i},{default:n(()=>[...t[37]||(t[37]=[m("详情",-1)])]),_:1},8,["onClick"]),i.state!=="revoked"?(d(),g(y,{key:0,link:"",type:"danger",loading:ie.value===i.session_id,onClick:B=>Ie(i)},{default:n(()=>[...t[38]||(t[38]=[m("远程撤销",-1)])]),_:1},8,["loading","onClick"])):(d(),w("span",ut,"已处理"))]),_:1})]),_:1},8,["data"])),[[Ae,te.value]]):(d(),g(Se,{key:0,description:"当前筛选下没有 Agent Session"})),pe.value>Ee?(d(),w("div",dt,[a(h,{"current-page":X.value,"onUpdate:currentPage":t[7]||(t[7]=i=>X.value=i),"page-size":Ee,total:pe.value,layout:"prev, pager, next, total",onCurrentChange:oe},null,8,["current-page","total"])])):U("",!0)]),_:1})):U("",!0),a(I,{"model-value":!!j.value,title:"业务授权详情",width:"min(640px, 94vw)","onUpdate:modelValue":t[8]||(t[8]=i=>{i||(j.value=null)})},{default:n(()=>[j.value?(d(),w(N,{key:0},[a(G,{column:1,border:""},{default:n(()=>[a(v,{label:"授权名称"},{default:n(()=>[l("span",rt,r(ce(j.value)||"待同步"),1)]),_:1}),a(v,{label:"名称来源"},{default:n(()=>[m(r(ce(j.value)?"业务系统提供":"业务系统尚未提供;旧授权可由原业务系统同步名称"),1)]),_:1}),a(v,{label:"设备名称"},{default:n(()=>[m(r(j.value.device_label||"未命名设备"),1)]),_:1}),a(v,{label:"接入应用"},{default:n(()=>[l("code",null,r(j.value.client_app_id),1)]),_:1}),a(v,{label:"授权记录"},{default:n(()=>[l("code",null,r(j.value.session_id),1)]),_:1}),a(v,{label:"业务主体"},{default:n(()=>{var i;return[m(r(((i=j.value.principal)==null?void 0:i.id)||j.value.on_behalf_of),1)]}),_:1}),a(v,{label:"租户"},{default:n(()=>{var i;return[m(r(((i=j.value.principal)==null?void 0:i.tenant)||"未声明租户"),1)]}),_:1}),a(v,{label:"工作空间"},{default:n(()=>[m(r(j.value.allowed_routes.join("、")),1)]),_:1}),a(v,{label:"状态"},{default:n(()=>[m(r(ve(j.value.state)),1)]),_:1})]),_:1}),t[39]||(t[39]=l("p",{class:"connection-note"},"名称只帮助识别授权。相同名称可能对应不同授权,权限、会话范围和执行记录仍按原授权绑定。名称更新不修改历史对话中的标签。",-1))],64)):U("",!0)]),_:1},8,["model-value"]),a(Nl,{modelValue:W.open,"onUpdate:modelValue":t[9]||(t[9]=i=>W.open=i),"app-id":W.appId,"initial-workspace":W.workspace,workspaces:P.value,onSaved:$e,onConnect:ne},null,8,["modelValue","app-id","initial-workspace","workspaces"]),a(I,{modelValue:b.open,"onUpdate:modelValue":t[15]||(t[15]=i=>b.open=i),title:"生成智能体客户端连接配置",width:"620px"},{footer:n(()=>[a(y,{onClick:t[12]||(t[12]=i=>b.open=!1)},{default:n(()=>[...t[40]||(t[40]=[m("关闭",-1)])]),_:1}),a(y,{onClick:t[13]||(t[13]=i=>Oe(x.value))},{default:n(()=>[...t[41]||(t[41]=[m("复制 JSON",-1)])]),_:1}),a(y,{type:"primary",onClick:t[14]||(t[14]=i=>Oe(H.value))},{default:n(()=>[...t[42]||(t[42]=[m("复制 DSH 命令",-1)])]),_:1})]),default:n(()=>[a(D,{type:"info",closable:!1,"show-icon":"",title:"这里只生成公开连接元数据,不包含业务 URL、业务身份、Client Token、Agent Token 或模型密钥。"}),t[43]||(t[43]=l("p",{class:"connection-note"},[l("code",null,"connectionName"),m(" 只是本机连接选择器。登录时会统一打开接入方配置的业务授权页,由该页面确认当前账号与租户。")],-1)),a(Te,{"label-position":"top",class:"connection-form"},{default:n(()=>[a(ue,{label:"Hub 地址"},{default:n(()=>[a(K,{"model-value":L.value,readonly:"",class:"mono"},null,8,["model-value"])]),_:1}),l("div",pt,[a(ue,{label:"Client App ID"},{default:n(()=>[a(K,{"model-value":b.app_id,readonly:"",class:"mono"},null,8,["model-value"])]),_:1}),a(ue,{label:"Connection Name"},{default:n(()=>[a(K,{modelValue:b.name,"onUpdate:modelValue":t[10]||(t[10]=i=>b.name=i),maxlength:"128",class:"mono"},null,8,["modelValue"])]),_:1})]),a(ue,{label:"Workspace"},{default:n(()=>[a(fe,{modelValue:b.workspace,"onUpdate:modelValue":t[11]||(t[11]=i=>b.workspace=i),style:{width:"100%"}},{default:n(()=>[(d(!0),w(N,null,E(b.workspaces,i=>(d(),g(Q,{key:i.route,label:i.name+"("+i.route+")",value:i.route},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])]),_:1})]),_:1}),l("div",ct,[l("pre",null,r(x.value),1)]),l("div",mt,[l("pre",null,r(H.value),1)])]),_:1},8,["modelValue"])])}}}),kt=Ge(vt,[["__scopeId","data-v-dce97866"]]);export{kt as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.setup-panel[data-v-4099c86e]{max-width:920px;margin:auto;color:var(--el-text-color-primary)}.setup-header[data-v-4099c86e]{display:flex;justify-content:space-between;gap:20px;align-items:flex-start;padding:8px 0 24px}.eyebrow[data-v-4099c86e]{font-size:12px;color:var(--el-color-primary);font-weight:600}.setup-header h2[data-v-4099c86e]{font-size:24px;margin:7px 0 9px}.setup-header p[data-v-4099c86e],.description[data-v-4099c86e]{color:var(--el-text-color-secondary);font-size:14px;line-height:1.7;margin:0}.setup-steps[data-v-4099c86e]{display:grid;grid-template-columns:repeat(4,1fr);gap:8px;padding:6px;background:var(--el-fill-color-light);border-radius:12px;margin-bottom:24px}.setup-steps button[data-v-4099c86e]{border:0;background:transparent;text-align:left;padding:12px 10px;color:var(--el-text-color-secondary);cursor:pointer;border-radius:8px;font:inherit;font-size:13px}.setup-steps button span[data-v-4099c86e]{display:inline-flex;width:24px;height:24px;align-items:center;justify-content:center;border-radius:50%;margin-right:7px;background:var(--el-fill-color-darker)}.setup-steps button.active[data-v-4099c86e]{background:var(--el-bg-color);color:var(--el-color-primary);box-shadow:0 2px 8px #00000008}.setup-steps button.active span[data-v-4099c86e]{background:var(--el-color-primary-light-9);color:var(--el-color-primary)}.setup-section[data-v-4099c86e]{padding:4px 4px 16px}.setup-section h3[data-v-4099c86e]{font-size:18px;margin:8px 0 9px}.description[data-v-4099c86e]{margin-bottom:22px}.field-note[data-v-4099c86e],.inline-note[data-v-4099c86e]{font-size:12px;line-height:1.7;color:var(--el-text-color-secondary)}.field-note[data-v-4099c86e]{margin-top:7px;width:100%}.inline-note[data-v-4099c86e]{margin-left:12px}.section-footer[data-v-4099c86e]{display:flex;justify-content:space-between;align-items:center;padding:18px 0;border-top:1px solid var(--el-border-color-lighter);gap:14px}.section-footer span[data-v-4099c86e]{font-size:12px;color:var(--el-text-color-secondary)}.workspace-selector[data-v-4099c86e]{padding:18px;background:var(--el-fill-color-light);border-radius:10px;margin-bottom:22px;display:grid;grid-template-columns:1fr 290px;gap:20px;align-items:center}.workspace-selector p[data-v-4099c86e]{font-size:12px;line-height:1.7;color:var(--el-text-color-secondary);margin:7px 0 0}.model-preview[data-v-4099c86e]{padding:20px;background:var(--el-color-primary-light-9);border:1px solid var(--el-color-primary-light-7);border-radius:10px}.model-preview span[data-v-4099c86e],.model-preview b[data-v-4099c86e]{display:block}.model-preview span[data-v-4099c86e]{font-size:12px;color:var(--el-color-primary);margin-bottom:10px}.model-preview p[data-v-4099c86e]{font-size:14px;line-height:1.7}.model-preview small[data-v-4099c86e]{font-size:12px;color:var(--el-text-color-secondary)}.source-heading[data-v-4099c86e],.source-top[data-v-4099c86e],.catalog-action[data-v-4099c86e]{display:flex;justify-content:space-between;align-items:center;gap:12px}.source-heading[data-v-4099c86e]{margin:24px 0 12px}.source-card[data-v-4099c86e]{border:1px solid var(--el-border-color-light);border-radius:10px;padding:16px;margin-bottom:12px}.source-top[data-v-4099c86e]{margin-bottom:18px}.catalog-action[data-v-4099c86e]{justify-content:flex-start}.catalog-action span[data-v-4099c86e]{font-size:12px;color:var(--el-text-color-secondary)}.write-field[data-v-4099c86e]{margin-top:24px}.inline-error[data-v-4099c86e]{color:var(--el-color-danger);font-size:12px;line-height:1.6}.check-item[data-v-4099c86e]{display:flex;justify-content:space-between;padding:17px 2px;border-bottom:1px solid var(--el-border-color-lighter);font-size:14px}.workspace-result[data-v-4099c86e]{display:grid;grid-template-columns:1fr auto;gap:12px;padding:20px;border:1px solid var(--el-border-color-light);border-radius:10px;margin:16px 0}.workspace-result code[data-v-4099c86e]{display:block;color:var(--el-text-color-secondary);font-size:12px;margin-top:6px}.workspace-result p[data-v-4099c86e]{grid-row:2;grid-column:1/-1;font-size:13px;margin:0;color:var(--el-text-color-secondary)}@media(max-width:760px){.setup-steps[data-v-4099c86e]{grid-template-columns:1fr 1fr}.workspace-selector[data-v-4099c86e]{grid-template-columns:1fr}.setup-header h2[data-v-4099c86e]{font-size:20px}.catalog-action[data-v-4099c86e]{align-items:flex-start;flex-direction:column}.inline-note[data-v-4099c86e]{display:block;margin-left:0}.workspace-result[data-v-4099c86e]{grid-template-columns:1fr}.workspace-result p[data-v-4099c86e]{grid-row:auto}}.agent-clients-page[data-v-dce97866]{display:grid;gap:16px}.page-navigation[data-v-dce97866]{display:flex;justify-content:space-between;align-items:center;gap:16px}.page-navigation b[data-v-dce97866]{font-size:20px}.page-navigation span[data-v-dce97866]{display:block;font-size:13px;color:var(--el-text-color-secondary);margin-top:7px}.setup-intro[data-v-dce97866]{border-color:var(--el-color-primary-light-7);background:linear-gradient(120deg,var(--el-color-primary-light-9),var(--el-bg-color) 70%)}.intro-kicker[data-v-dce97866]{font-size:12px;color:var(--el-color-primary);font-weight:600}.setup-intro h2[data-v-dce97866]{font-size:21px;margin:8px 0 10px}.setup-intro p[data-v-dce97866]{font-size:13px;color:var(--el-text-color-secondary);line-height:1.7;margin:0}.intro-flow[data-v-dce97866]{display:flex;flex-wrap:wrap;align-items:center;gap:16px;margin-top:22px;font-size:13px}.intro-flow span[data-v-dce97866]{padding:7px 11px;background:var(--el-bg-color);border:1px solid var(--el-border-color-lighter);border-radius:6px}.intro-flow i[data-v-dce97866]{font-style:normal;color:var(--el-text-color-placeholder)}.head[data-v-dce97866],.section-head[data-v-dce97866],.actions[data-v-dce97866]{display:flex;align-items:center;gap:10px}.head[data-v-dce97866],.section-head[data-v-dce97866]{justify-content:space-between}.section-head>div[data-v-dce97866]:first-child{display:flex;align-items:baseline;gap:10px}.section-head span[data-v-dce97866],.muted[data-v-dce97866]{color:var(--el-text-color-secondary);font-size:12px}.overview[data-v-dce97866]{display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:12px}.metric[data-v-dce97866]{min-width:0;padding:16px;border:1px solid var(--el-border-color-lighter);border-radius:10px;background:var(--el-fill-color-blank)}.metric span[data-v-dce97866],.metric em[data-v-dce97866]{display:block;color:var(--el-text-color-secondary);font-style:normal;font-size:12px}.metric b[data-v-dce97866]{display:block;margin:8px 0 5px;font-size:24px;line-height:1}.metric.primary[data-v-dce97866]{border-color:color-mix(in srgb,var(--el-color-primary) 34%,transparent);background:color-mix(in srgb,var(--el-color-primary) 7%,transparent)}.metric.danger b[data-v-dce97866]{color:var(--el-color-danger)}.stack[data-v-dce97866]{display:flex;flex-direction:column;gap:5px;min-width:0}.subject-name[data-v-dce97866]{overflow-wrap:anywhere;white-space:pre-wrap}.stack.right[data-v-dce97866]{align-items:flex-end}.mono[data-v-dce97866],code[data-v-dce97866]{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace}.tags[data-v-dce97866]{display:flex;flex-wrap:wrap;gap:6px}.connection-form[data-v-dce97866]{margin-top:18px}.connection-note[data-v-dce97866]{margin:12px 0 0;color:var(--el-text-color-secondary);font-size:12px;line-height:1.6}.pagination[data-v-dce97866]{display:flex;justify-content:flex-end;padding-top:14px}.form-grid[data-v-dce97866]{display:grid;grid-template-columns:1fr 1fr;gap:12px}.code-block[data-v-dce97866]{margin-top:10px;padding:12px;overflow:auto;border-radius:8px;background:#111827;color:#e5e7eb}.code-block pre[data-v-dce97866]{margin:0;white-space:pre-wrap;word-break:break-all;font-size:12px}@media(max-width:1280px){.overview[data-v-dce97866]{grid-template-columns:repeat(3,minmax(0,1fr))}}@media(max-width:760px){.overview[data-v-dce97866],.form-grid[data-v-dce97866]{grid-template-columns:1fr}.head[data-v-dce97866],.section-head[data-v-dce97866]{align-items:flex-start;flex-direction:column}}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{d as he,z as Fe,c as w,e as t,S as s,J as o,u as Ze,I as f,O as y,aC as He,aB as We,m as Xe,r as v,ai as k,o as r,P as p,Q as i,K as Te,a0 as Ue,R as B,a3 as X,as as Qe}from"./vendor-vue-B2uhHUfE.js";import{E as ne,aj as Ge}from"./vendor-element-CZoEjZr8.js";import{a as M}from"./request-DeGya810.js";import{u as Ye,c as el}from"./index-UGvfF3Xr.js";import{_ as ll}from"./_plugin-vue_export-helper-DlAUqK2U.js";const tl={class:"task-control-page"},al={class:"task-heading"},nl={class:"actions"},ol={class:"muted"},sl={class:"muted"},il={class:"muted"},ul={key:0,class:"load-more"},dl={class:"section-heading"},rl={class:"section-heading"},vl={class:"actions"},pl={class:"field-note"},cl={class:"form-grid"},_l={class:"form-grid policy-grid"},fl={class:"enrollment-notice"},ml={class:"detail-body"},yl={class:"section-heading"},kl={class:"task-id"},gl={class:"muted"},wl={class:"detail-metrics"},bl={class:"date-value"},Vl={key:2,class:"control-panel"},Sl={class:"actions"},Cl={class:"section-heading"},xl={class:"binding-note"},Il={class:"invocation-ids"},Tl={class:"muted"},Ul={class:"muted"},$l={key:3,class:"load-more"},Al=he({__name:"AgentTasks",setup(El){const oe=He(),se=We(),me=Ye(),P=Xe(()=>me.can("clients:write")),ie=v([]),A=v(!1),z=v(""),Q=v(null),d=v(null),ue=v(!1),q=v(!1),j=v(""),V=v(!1),G=v([]),J=v(null);let h=0;const F=v(!1),E=v(!1),D=v(""),g=v(null),S=v([]),de=v(0),re=v([]),ve=v(!1),Y=v(""),C=v([]),x=v("bounded"),I=v(),T=v(1),N=v(""),O=v(!1),L=v(!1),U=v(null),ee=()=>{var l;return`bailing:task-create:v1:${el()}:${((l=me.me)==null?void 0:l.username)??""}`},pe=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,ye=l=>`${l.slice(0,8)}…${l.slice(-4)}`,le=(l,e="—")=>l?new Date(l).toLocaleString("zh-CN",{hour12:!1}):e,ce=l=>!!(l.policy.expires_at&&Date.parse(l.policy.expires_at)<=Date.now()),ke=l=>l===null?"不限":l===0?"0(只读)":String(l);function ge(l){return l.state==="cancelled"?"已取消":ce(l)?"已过期":{active:"运行可用",paused:"已暂停",blocked:"整组阻断"}[l.state]}function we(l){return l.state==="cancelled"?"info":ce(l)||l.state==="paused"?"warning":l.state==="blocked"?"danger":"success"}const $e=l=>l===null?"不扣写预算":{reserved:"已预留",consumed:"已计入",released:"已释放"}[l]??"未知",Ae=l=>({none:"未获许可",held:"执行中",unknown:"结果未知",settled:"已结算"})[l]??"未知",Ee=l=>l===null?"待确认":{confirmed_dispatched:"已确认派发",confirmed_not_dispatched:"已确认未派发",unknown:"结果未知,保留占用"}[l]??"未知";function te(l){const e=l instanceof Error?l.message:"未知错误",n={TASK_UNSUPPORTED:"当前实例尚未启用任务控制,请确认版本与迁移状态。",TASK_UNAVAILABLE:"任务服务暂时不可用,请保留原请求重试。",TASK_MEMBER_MISMATCH:"原授权、工作空间或本地会话不匹配,请核对精确标识。",TASK_SCOPE_BLOCKED:"至少一个原成员的授权或身份核验未通过,整组范围已阻断。",TASK_REVISION_CONFLICT:"任务已被其他操作更新,已重新读取快照;请根据新状态决定是否操作。",TASK_CONFLICT:"此请求已关联不同内容,请先核对原创建结果。",TASK_INVALID_INPUT:"字段格式不正确,请核对原标识、精确工具名及预算。",TASK_EXPIRED:"任务已过期,不能继续派发。",TASK_CANCELLED:"任务已取消,不能继续。",TASK_CONTROL_CONFLICT:"当前状态不允许该操作,请刷新快照。",TASK_RECORD_INVALID:"任务记录校验未通过,请由管理员检查。"};return n[e]?`${n[e]}(${e})`:`请求未完成,请重试。${e}`}async function Z(l=!1){if(!A.value){A.value=!0,z.value="";try{const e=new URLSearchParams({limit:"30"});l&&Q.value&&e.set("before",Q.value);const n=await M(`/admin/api/agent-tasks?${e}`);ie.value=l?[...ie.value,...n.items]:n.items,Q.value=n.next_cursor}catch(e){z.value=te(e)}finally{A.value=!1}}}async function ae(l){var e;((e=d.value)==null?void 0:e.task_id)!==l&&(d.value=null,V.value=!1,G.value=[],J.value=null),ue.value=!0,oe.replace({query:{task:l}}),await H(l)}function De(){h++,oe.replace({query:{}})}async function H(l,e=!1){const n=++h;q.value=!0,V.value=!1,j.value="";try{const _=new URLSearchParams({limit:"30"});e&&J.value&&_.set("before",J.value);const c=await M(`/admin/api/agent-tasks/${encodeURIComponent(l)}?${_}`);if(n!==h)return;d.value=c.task,V.value=!0,G.value=e?[...G.value,...c.invocations]:c.invocations,J.value=c.next_cursor}catch(_){n===h&&(j.value=te(_))}finally{n===h&&(q.value=!1)}}async function be(l=!1){ve.value=!0;try{const e=await M(`/admin/api/agent-clients/sessions?state=active&limit=50&offset=${l?S.value.length:0}`);S.value=l?[...S.value,...e.list]:e.list,de.value=e.total}catch{Y.value="暂时无法读取授权目录。可稍后重试,或手工填写经过核对的原授权标识;不会自动选择其他授权。"}finally{ve.value=!1}}function Ne(l){var e;return`${l.subject_display_status==="provided"&&((e=l.subject_display)==null?void 0:e.name)||"授权名称待同步"} · ${l.client_app_id} · ${l.device_label||"未命名设备"} · ${ye(l.session_id)}`}function Oe(l){const e=S.value.find(n=>n.session_id===l.session_id);return e?e.allowed_routes.includes("*")?re.value:e.allowed_routes.map(n=>re.value.find(_=>_.route===n)??{route:n,name:n}):[]}function Le(l,e){const n=S.value.find(_=>_.session_id===e);l.client_app_id=(n==null?void 0:n.client_app_id)??"",l.workspace="",l.tools=""}function Ve(){C.value.push({key:crypto.randomUUID(),manual:!1,session_id:"",client_app_id:"",workspace:"",client_conversation_id:"",tools:""})}function Ke(l){C.value=l.members.map(n=>({key:crypto.randomUUID(),manual:!0,session_id:n.session_id,client_app_id:n.client_app_id,workspace:n.workspace,client_conversation_id:n.client_conversation_id,tools:n.allowed_tools.join(`
|
|
2
|
+
`)})),x.value=l.policy.max_write_calls===null?"unlimited":l.policy.max_write_calls===0?"readonly":"bounded",I.value=l.policy.max_write_calls??void 0,T.value=l.policy.max_concurrent;const e=l.policy.expires_at?new Date(l.policy.expires_at):null;N.value=e?new Date(e.getTime()-e.getTimezoneOffset()*6e4).toISOString().slice(0,16):"",O.value=!0}async function Re(){P.value&&(D.value="",Y.value="",g.value?Ke(g.value):(C.value=[],Ve(),x.value="bounded",I.value=void 0,T.value=1,N.value="",O.value=!1),F.value=!0,await Promise.allSettled([be(),M("/admin/api/agent-clients/overview?days=30").then(l=>{re.value=l.workspaces})]))}function Be(){if(!O.value)throw new Error("请先确认原授权在所有会话中的持续约束。");const l=C.value.map((n,_)=>{const c=n.tools.split(/[\s,,、]+/).filter(Boolean);if(!pe.test(n.session_id)||!n.client_app_id.trim()||n.client_app_id!==n.client_app_id.trim()||!/^[a-z0-9][a-z0-9_-]{1,63}$/.test(n.workspace)||n.workspace==="auto"||!/^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/.test(n.client_conversation_id))throw new Error(`成员 ${_+1}:请填写有效的原 Session、Client、工作空间和本地会话标识。`);if(!c.length||c.length>256||!c.every(m=>/^[A-Za-z_][A-Za-z0-9_]{0,63}$/.test(m)))throw new Error(`成员 ${_+1}:请填写 1–256 个精确工具名,不接受通配符。`);return{session_id:n.session_id.toLowerCase(),client_app_id:n.client_app_id,workspace:n.workspace,client_conversation_id:n.client_conversation_id,allowed_tools:[...new Set(c)].sort()}});if(new Set(l.map(n=>JSON.stringify([n.session_id,n.workspace,n.client_conversation_id]))).size!==l.length)throw new Error("存在重复的原授权、工作空间与本地会话组合。");if(x.value==="bounded"&&(!Number.isSafeInteger(I.value)||I.value<1))throw new Error("请填写累计写调用次数,或明确选择只读 / 不限。");if(!Number.isSafeInteger(T.value)||T.value<1)throw new Error("并发上限至少为 1。");const e=N.value?new Date(N.value):null;if(e&&(!Number.isFinite(e.getTime())||e.getTime()<=Date.now()))throw new Error("截止时间必须晚于当前时间。");return{request_id:crypto.randomUUID(),members:l,policy:{max_write_calls:x.value==="unlimited"?null:x.value==="readonly"?0:I.value,max_concurrent:T.value,expires_at:(e==null?void 0:e.toISOString())??null}}}async function Se(){if(!(!P.value||E.value)){D.value="";try{if(!g.value){const l=Be();sessionStorage.setItem(ee(),JSON.stringify(l)),g.value=l}}catch(l){D.value=l instanceof Error?l.message:"无法保留原创建请求,请检查浏览器存储。";return}E.value=!0;try{const l=await M("/admin/api/agent-tasks",{method:"POST",body:JSON.stringify(g.value)});sessionStorage.removeItem(ee()),g.value=null,F.value=!1,ne.success("任务已创建,原授权已纳入持续任务约束。"),await Z(),await ae(l.task_id)}catch(l){const e=l instanceof Error&&["TASK_INVALID_INPUT","TASK_MEMBER_MISMATCH","TASK_SCOPE_BLOCKED","TASK_EXPIRED"].includes(l.message);e&&(sessionStorage.removeItem(ee()),g.value=null),D.value=`${te(l)} ${e?"尚未创建,可修正后重新提交。":"原请求已保留,可重试核对结果。"}`}finally{E.value=!1}}}async function _e(l){if(!d.value||!V.value||!P.value||L.value)return;const e=d.value,n={pause:"停止新的派发许可。已获得许可的在途调用仍可能完成,现有预算和原调用保留。",resume:"重新核验整组授权并允许后续派发。不会增加预算,也不会执行或重放待处理业务。",cancel:"取消后此任务不能继续,也不会回滚业务。原授权在所有会话中仍须绑定任务。"};try{await Ge.confirm(n[l],{pause:"暂停任务",resume:"继续任务",cancel:"取消任务"}[l],{type:l==="cancel"?"warning":"info",confirmButtonText:"确认",cancelButtonText:"返回"})}catch{return}L.value=!0,(!U.value||U.value.taskId!==e.task_id||U.value.action!==l)&&(U.value={taskId:e.task_id,request_id:crypto.randomUUID(),expected_revision:e.revision,action:l});const{taskId:_,...c}=U.value;try{await M(`/admin/api/agent-tasks/${encodeURIComponent(_)}/control`,{method:"POST",body:JSON.stringify(c)}),U.value=null,ne.success("任务控制状态已更新;没有派发业务操作。"),await H(_),await Z()}catch(m){const K=te(m);m instanceof Error&&m.message==="TASK_REVISION_CONFLICT"&&(U.value=null,await H(_)),j.value=V.value?K:`${K} 请成功刷新快照后再操作。`}finally{L.value=!1}}async function Me(){try{await navigator.clipboard.writeText(d.value.task_id),ne.success("已复制任务 ID")}catch{ne.warning("复制失败,可选中上方任务 ID 手工复制。")}}return Fe(()=>{try{const l=JSON.parse(sessionStorage.getItem(ee())||"null");l&&pe.test(l.request_id)&&Array.isArray(l.members)&&l.members.length&&l.policy&&(g.value=l)}catch{}Z(),typeof se.query.task=="string"&&pe.test(se.query.task)&&ae(se.query.task)}),(l,e)=>{const n=k("el-button"),_=k("el-card"),c=k("el-alert"),m=k("el-table-column"),K=k("el-tag"),Ce=k("el-table"),Pe=k("el-switch"),W=k("el-option"),fe=k("el-select"),b=k("el-form-item"),R=k("el-input"),xe=k("el-input-number"),ze=k("el-checkbox"),qe=k("el-form"),je=k("el-dialog"),Je=k("el-drawer"),Ie=Qe("loading");return r(),w("div",tl,[t("header",al,[e[20]||(e[20]=t("div",null,[t("div",{class:"eyebrow"},"本地智能体 / 运行边界"),t("h1",null,"任务控制"),t("p",null,"为一项连续业务任务固定授权范围、累计写预算和同时执行数量。")],-1)),t("div",nl,[s(n,{onClick:e[0]||(e[0]=a=>Ze(oe).push("/agent-clients"))},{default:o(()=>[...e[18]||(e[18]=[p("智能体客户端",-1)])]),_:1}),s(n,{loading:A.value,onClick:e[1]||(e[1]=a=>Z())},{default:o(()=>[...e[19]||(e[19]=[p("刷新",-1)])]),_:1},8,["loading"]),P.value?(r(),f(n,{key:0,type:"primary",onClick:Re},{default:o(()=>[p(i(g.value?"继续原创建":"创建受控任务"),1)]),_:1})):y("",!0)])]),s(_,{shadow:"never",class:"explanation"},{default:o(()=>[...e[21]||(e[21]=[t("div",{class:"explanation-grid"},[t("div",null,[t("b",null,"例如:商城上架商品,再核对库存"),t("p",null,"明确选定商城和库存系统的原授权、工作空间、本地会话及工具。保留各系统原有权限与审批。")]),t("div",null,[t("b",null,"累计写预算 ≠ 每分钟限流"),t("p",null,"按业务写调用计数,包含待确认的预留;不是商品数量,也不是成功次数。读取不扣写预算,仍受并发限制。")]),t("div",null,[t("b",null,"暂停只阻止新的派发"),t("p",null,"已获许可的调用仍可能完成。继续不补充预算、不执行或重放业务;取消不会撤回已产生的变化。")])],-1)])]),_:1}),z.value?(r(),f(c,{key:0,type:"error",closable:!1,title:z.value,"show-icon":""},null,8,["title"])):y("",!0),s(_,{shadow:"never"},{header:o(()=>[...e[22]||(e[22]=[t("div",{class:"section-heading"},[t("b",null,"已创建的任务"),t("span",{class:"muted"},"范围与预算创建后固定 · 点击任务查看原调用")],-1)])]),default:o(()=>[Te((r(),f(Ce,{data:ie.value,"row-key":"task_id",onRowClick:e[2]||(e[2]=a=>ae(a.task_id))},{empty:o(()=>[t("span",null,i(z.value?"未能取得任务列表,请重试。":"还没有受控任务。创建前请先确认客户端支持任务绑定。"),1)]),default:o(()=>[s(m,{label:"任务","min-width":"160"},{default:o(({row:a})=>[s(n,{link:"",type:"primary",onClick:Ue($=>ae(a.task_id),["stop"])},{default:o(()=>[p(i(ye(a.task_id)),1)]),_:2},1032,["onClick"]),t("div",ol,i(le(a.created_at)),1)]),_:1}),s(m,{label:"固定范围","min-width":"190"},{default:o(({row:a})=>[t("b",null,i(a.members.length)+" 个成员",1),t("div",sl,i([...new Set(a.members.map($=>$.workspace))].join(" · ")),1)]),_:1}),s(m,{label:"状态",width:"100"},{default:o(({row:a})=>[s(K,{type:we(a),effect:"plain"},{default:o(()=>[p(i(ge(a)),1)]),_:2},1032,["type"])]),_:1}),s(m,{label:"累计写调用","min-width":"160"},{default:o(({row:a})=>[t("b",null,i(a.counters.write_reserved+a.counters.write_consumed)+" / "+i(ke(a.policy.max_write_calls)),1),t("div",il,"预留 "+i(a.counters.write_reserved)+" · 已派发 "+i(a.counters.write_consumed),1)]),_:1}),s(m,{label:"执行中 / 并发上限",width:"150"},{default:o(({row:a})=>[p(i(a.counters.active_permits)+" / "+i(a.policy.max_concurrent),1)]),_:1}),s(m,{label:"截止时间","min-width":"165"},{default:o(({row:a})=>[p(i(le(a.policy.expires_at,"不设截止")),1)]),_:1})]),_:1},8,["data"])),[[Ie,A.value]]),Q.value?(r(),w("div",ul,[s(n,{loading:A.value,onClick:e[3]||(e[3]=a=>Z(!0))},{default:o(()=>[...e[23]||(e[23]=[p("加载更多",-1)])]),_:1},8,["loading"])])):y("",!0)]),_:1}),s(je,{modelValue:F.value,"onUpdate:modelValue":e[11]||(e[11]=a=>F.value=a),title:"创建受控任务",width:"min(920px, 96vw)",top:"5vh","body-class":"bailing-task-create-body","close-on-click-modal":!1},{footer:o(()=>[s(n,{disabled:E.value,onClick:e[10]||(e[10]=a=>F.value=!1)},{default:o(()=>[p(i(g.value?"稍后继续":"取消"),1)]),_:1},8,["disabled"]),s(n,{type:"primary",loading:E.value,disabled:!g.value&&!O.value,onClick:Se},{default:o(()=>[p(i(g.value?"重试原创建请求":"确认范围并创建"),1)]),_:1},8,["loading","disabled"])]),default:o(()=>[g.value?(r(),f(c,{key:0,type:"warning",closable:!1,"show-icon":"",title:"已保留原创建请求。重试会核对同一请求,不会换一个请求重复创建。"})):y("",!0),Y.value?(r(),f(c,{key:1,type:"info",closable:!1,title:Y.value},null,8,["title"])):y("",!0),s(qe,{"label-position":"top",class:"creation-form",disabled:E.value||!!g.value,onSubmit:Ue(Se,["prevent"])},{default:o(()=>[t("div",dl,[e[25]||(e[25]=t("h2",null,"1. 固定业务范围",-1)),s(n,{disabled:C.value.length>=64,onClick:Ve},{default:o(()=>[...e[24]||(e[24]=[p("添加授权成员",-1)])]),_:1},8,["disabled"])]),e[34]||(e[34]=t("p",{class:"muted"},"仅同一中枢。每个成员需对应客户端选中的原授权和真实本地会话 ID;不能填写显示名称代替标识。",-1)),(r(!0),w(B,null,X(C.value,(a,$)=>(r(),w("article",{key:a.key,class:"member-editor"},[t("div",rl,[t("b",null,"成员 "+i($+1),1),t("div",vl,[s(Pe,{modelValue:a.manual,"onUpdate:modelValue":u=>a.manual=u,"active-text":"手工填写标识"},null,8,["modelValue","onUpdate:modelValue"]),C.value.length>1?(r(),f(n,{key:0,link:"",type:"danger",onClick:u=>C.value.splice($,1)},{default:o(()=>[...e[26]||(e[26]=[p("移除",-1)])]),_:1},8,["onClick"])):y("",!0)])]),a.manual?y("",!0):(r(),f(b,{key:0,label:"原业务授权"},{default:o(()=>[s(fe,{modelValue:a.session_id,"onUpdate:modelValue":u=>a.session_id=u,filterable:"",placeholder:"按业务授权名称、设备或 Session 选择",onChange:u=>Le(a,u)},{default:o(()=>[(r(!0),w(B,null,X(S.value,u=>(r(),f(W,{key:u.session_id,value:u.session_id,label:Ne(u)},null,8,["value","label"]))),128))]),_:1},8,["modelValue","onUpdate:modelValue","onChange"]),t("div",pl,[p("名称仅帮助识别;保存的是原 Session。"+i(S.value.length)+" / "+i(de.value)+" 个有效授权已加载。",1),S.value.length<de.value?(r(),f(n,{key:0,link:"",loading:ve.value,onClick:e[4]||(e[4]=u=>be(!0))},{default:o(()=>[...e[27]||(e[27]=[p("加载更多",-1)])]),_:1},8,["loading"])):y("",!0)])]),_:2},1024)),t("div",cl,[s(b,{label:"Agent Session ID"},{default:o(()=>[s(R,{modelValue:a.session_id,"onUpdate:modelValue":u=>a.session_id=u,readonly:!a.manual,placeholder:"原授权的 UUID"},null,8,["modelValue","onUpdate:modelValue","readonly"])]),_:2},1024),s(b,{label:"接入方 Client App ID"},{default:o(()=>[s(R,{modelValue:a.client_app_id,"onUpdate:modelValue":u=>a.client_app_id=u,readonly:!a.manual,maxlength:"64",placeholder:"例如 shop-app"},null,8,["modelValue","onUpdate:modelValue","readonly"])]),_:2},1024),s(b,{label:"工作空间 Workspace"},{default:o(()=>[a.manual?(r(),f(R,{key:0,modelValue:a.workspace,"onUpdate:modelValue":u=>a.workspace=u,maxlength:"64",placeholder:"原授权允许的工作空间"},null,8,["modelValue","onUpdate:modelValue"])):(r(),f(fe,{key:1,modelValue:a.workspace,"onUpdate:modelValue":u=>a.workspace=u,placeholder:"明确选择工作空间"},{default:o(()=>[(r(!0),w(B,null,X(Oe(a),u=>(r(),f(W,{key:u.route,label:`${u.name||u.route}(${u.route})`,value:u.route},null,8,["label","value"]))),128))]),_:2},1032,["modelValue","onUpdate:modelValue"]))]),_:2},1024),s(b,{label:"本地会话 ID"},{default:o(()=>[s(R,{modelValue:a.client_conversation_id,"onUpdate:modelValue":u=>a.client_conversation_id=u,maxlength:"128",placeholder:"从客户端宿主取得,区分于 Session ID"},null,8,["modelValue","onUpdate:modelValue"])]),_:2},1024)]),s(b,{label:"允许的精确工具名称"},{default:o(()=>[s(R,{modelValue:a.tools,"onUpdate:modelValue":u=>a.tools=u,type:"textarea",rows:2,placeholder:"每行一个或用逗号分隔,例如 product_update、inventory_read;不接受 *"},null,8,["modelValue","onUpdate:modelValue"]),e[28]||(e[28]=t("div",{class:"field-note"},"填写此目标真实存在的工具名。任务范围只收窄权限,不会开通工具或绕过审批。",-1))]),_:2},1024)]))),128)),e[35]||(e[35]=t("h2",null,"2. 设置累计预算与并发",-1)),t("div",_l,[s(b,{label:"累计写调用预算"},{default:o(()=>[s(fe,{modelValue:x.value,"onUpdate:modelValue":e[5]||(e[5]=a=>x.value=a)},{default:o(()=>[s(W,{value:"bounded",label:"限制累计写调用次数"}),s(W,{value:"readonly",label:"0 次:仅允许读取"}),s(W,{value:"unlimited",label:"不限累计写调用次数"})]),_:1},8,["modelValue"]),x.value==="bounded"?(r(),f(xe,{key:0,modelValue:I.value,"onUpdate:modelValue":e[6]||(e[6]=a=>I.value=a),min:1,max:1e9,precision:0,placeholder:"填写次数"},null,8,["modelValue"])):y("",!0)]),_:1}),s(b,{label:"同时执行上限"},{default:o(()=>[s(xe,{modelValue:T.value,"onUpdate:modelValue":e[7]||(e[7]=a=>T.value=a),min:1,max:1e4,precision:0},null,8,["modelValue"]),e[29]||(e[29]=t("div",{class:"field-note"},"读取和写入共同占用。结果未知时继续占用,不自动再执行。",-1))]),_:1}),s(b,{label:"截止时间(可空)"},{default:o(()=>[s(R,{modelValue:N.value,"onUpdate:modelValue":e[8]||(e[8]=a=>N.value=a),type:"datetime-local",clearable:""},null,8,["modelValue"]),e[30]||(e[30]=t("div",{class:"field-note"},"留空即不设截止。按浏览器本地时区填写,保存为 UTC。",-1))]),_:1})]),t("div",fl,[e[32]||(e[32]=t("b",null,"此设置会持续约束所选原授权",-1)),e[33]||(e[33]=t("p",null,"创建成功后,这些 Agent Session 在所有本地会话中都必须绑定明确的受控任务;省略任务将不能访问业务。取消当前任务也不会恢复不受任务约束的访问。客户端需先具备任务绑定能力,已有其他会话也需安排对应任务。",-1)),s(ze,{modelValue:O.value,"onUpdate:modelValue":e[9]||(e[9]=a=>O.value=a)},{default:o(()=>[...e[31]||(e[31]=[p("我已确认客户端支持任务绑定,并理解原授权在其他会话中的持续约束。",-1)])]),_:1},8,["modelValue"])])]),_:1},8,["disabled"]),D.value?(r(),f(c,{key:2,type:"error",closable:!1,"show-icon":"",title:D.value},null,8,["title"])):y("",!0)]),_:1},8,["modelValue"]),s(Je,{modelValue:ue.value,"onUpdate:modelValue":e[17]||(e[17]=a=>ue.value=a),title:"受控任务详情",size:"min(1040px, 96vw)",onClosed:De},{default:o(()=>[j.value?(r(),f(c,{key:0,type:"error",closable:!1,title:j.value,"show-icon":""},null,8,["title"])):y("",!0),Te((r(),w("div",ml,[d.value?(r(),w(B,{key:0},[t("div",yl,[t("div",null,[s(K,{type:we(d.value),effect:"plain"},{default:o(()=>[p(i(ge(d.value)),1)]),_:1},8,["type"]),t("code",kl,i(d.value.task_id),1)]),s(n,{loading:q.value,onClick:e[12]||(e[12]=a=>H(d.value.task_id))},{default:o(()=>[...e[36]||(e[36]=[p("刷新快照",-1)])]),_:1},8,["loading"])]),t("p",gl,"更新于 "+i(le(d.value.updated_at))+" · 控制修订 "+i(d.value.revision)+" · 记录序号 "+i(d.value.ledger_sequence)+"。此快照不是派发许可。",1),t("div",wl,[t("div",null,[e[37]||(e[37]=t("span",null,"累计写调用 / 预算",-1)),t("b",null,i(d.value.counters.write_reserved+d.value.counters.write_consumed)+" / "+i(ke(d.value.policy.max_write_calls)),1),t("small",null,"预留 "+i(d.value.counters.write_reserved)+" · 已确认派发 "+i(d.value.counters.write_consumed),1)]),t("div",null,[e[38]||(e[38]=t("span",null,"执行中 / 并发上限",-1)),t("b",null,i(d.value.counters.active_permits)+" / "+i(d.value.policy.max_concurrent),1),e[39]||(e[39]=t("small",null,"包含结果未知、尚未结算的许可",-1))]),t("div",null,[e[40]||(e[40]=t("span",null,"截止时间",-1)),t("b",bl,i(le(d.value.policy.expires_at,"不设截止")),1),t("small",null,i(d.value.members.length)+" 个固定成员",1)])]),d.value.state==="blocked"?(r(),f(c,{key:0,type:"warning",closable:!1,title:"原成员身份或授权核验未通过。请先处理原因,再暂停并重新核验;不能移除成员后继续。"})):y("",!0),d.value.state==="cancelled"?(r(),f(c,{key:1,type:"info",closable:!1,title:"任务已取消,不能继续。原调用回执仍可核对,已发生的业务变化不会撤回。"})):y("",!0),P.value?(r(),w("div",Vl,[e[44]||(e[44]=t("div",null,[t("b",null,"控制后续派发"),t("p",null,"暂停保留在途调用;继续不补预算、不执行待办;取消不可恢复,也不回滚业务。")],-1)),t("div",Sl,[s(n,{disabled:L.value||!V.value||!["active","blocked"].includes(d.value.state),onClick:e[13]||(e[13]=a=>_e("pause"))},{default:o(()=>[...e[41]||(e[41]=[p("暂停",-1)])]),_:1},8,["disabled"]),s(n,{type:"primary",plain:"",disabled:L.value||!V.value||d.value.state!=="paused"||ce(d.value),onClick:e[14]||(e[14]=a=>_e("resume"))},{default:o(()=>[...e[42]||(e[42]=[p("继续",-1)])]),_:1},8,["disabled"]),s(n,{type:"danger",plain:"",disabled:L.value||!V.value||d.value.state==="cancelled",onClick:e[15]||(e[15]=a=>_e("cancel"))},{default:o(()=>[...e[43]||(e[43]=[p("取消任务",-1)])]),_:1},8,["disabled"])])])):y("",!0),e[57]||(e[57]=t("h2",null,"固定的业务范围",-1)),(r(!0),w(B,null,X(d.value.members,(a,$)=>(r(),w("article",{key:`${a.session_id}:${a.workspace}:${a.client_conversation_id}`,class:"member-snapshot"},[t("div",Cl,[t("b",null,"成员 "+i($+1)+" · "+i(a.client_app_id)+" / "+i(a.workspace),1)]),t("dl",null,[e[45]||(e[45]=t("dt",null,"原授权 Session",-1)),t("dd",null,[t("code",null,i(a.session_id),1)]),e[46]||(e[46]=t("dt",null,"本地会话",-1)),t("dd",null,[t("code",null,i(a.client_conversation_id),1)]),e[47]||(e[47]=t("dt",null,"精确工具",-1)),t("dd",null,[(r(!0),w(B,null,X(a.allowed_tools,u=>(r(),f(K,{key:u,type:"info",effect:"plain"},{default:o(()=>[p(i(u),1)]),_:2},1024))),128))])])]))),128)),t("div",xl,[e[49]||(e[49]=t("b",null,"交给客户端宿主的任务标识",-1)),e[50]||(e[50]=t("p",null,"宿主读取任务并核对全部已选原授权后绑定。任务 ID 不替代业务授权,也不交给模型自行选择。",-1)),s(n,{size:"small",onClick:Me},{default:o(()=>[...e[48]||(e[48]=[p("复制任务 ID",-1)])]),_:1})]),e[58]||(e[58]=t("h2",null,"原调用记录",-1)),e[59]||(e[59]=t("p",{class:"muted"},"这里只读取关联和执行状态,不查询业务正文,也不会继续或重新派发调用。已派发不代表业务成功。",-1)),s(Ce,{data:G.value,size:"small","row-key":"invocation_id"},{empty:o(()=>[...e[55]||(e[55]=[p("尚无关联调用。创建任务本身不会执行业务。",-1)])]),default:o(()=>[s(m,{type:"expand"},{default:o(({row:a})=>[t("dl",Il,[e[51]||(e[51]=t("dt",null,"原调用",-1)),t("dd",null,[t("code",null,i(a.invocation_id),1)]),e[52]||(e[52]=t("dt",null,"原授权",-1)),t("dd",null,[t("code",null,i(a.session_id),1)]),e[53]||(e[53]=t("dt",null,"原运行",-1)),t("dd",null,[t("code",null,i(a.run_id),1)]),e[54]||(e[54]=t("dt",null,"原 Job",-1)),t("dd",null,[t("code",null,i(a.job_id),1)])])]),_:1}),s(m,{label:"工具","min-width":"170"},{default:o(({row:a})=>[t("code",null,i(a.tool),1),t("div",Tl,i(a.readonly?"读取":"写入")+" · 第 "+i(a.attempt)+" 次许可",1)]),_:1}),s(m,{label:"写预算",width:"100"},{default:o(({row:a})=>[p(i($e(a.budget_state)),1)]),_:1}),s(m,{label:"执行许可",width:"100"},{default:o(({row:a})=>[p(i(Ae(a.permit_state)),1)]),_:1}),s(m,{label:"派发结果","min-width":"150"},{default:o(({row:a})=>[p(i(Ee(a.outcome)),1),t("div",Ul,i(a.terminal?"原操作已结束":"原操作未结束"),1)]),_:1})]),_:1},8,["data"]),J.value?(r(),w("div",$l,[s(n,{loading:q.value,onClick:e[16]||(e[16]=a=>H(d.value.task_id,!0))},{default:o(()=>[...e[56]||(e[56]=[p("加载更多原调用",-1)])]),_:1},8,["loading"])])):y("",!0)],64)):y("",!0)])),[[Ie,q.value]])]),_:1},8,["modelValue"])])}}}),Rl=ll(Al,[["__scopeId","data-v-d7b3f50d"]]);export{Rl as default};
|