evolcore 0.0.48 → 0.0.49
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/CHANGELOG.md +34 -0
- package/dist/agent-template/runtime.js +5 -2
- package/dist/agents/codex-runner.js +5 -1
- package/dist/aun/msg/p2p.js +2 -1
- package/dist/build-identity.json +1 -1
- package/dist/channels/aun.js +643 -273
- package/dist/cli/directory.js +6 -1
- package/dist/cli/index.js +7 -1
- package/dist/cli/managed-command-guard.js +2 -0
- package/dist/cli/model.js +20 -5
- package/dist/cli/quota.js +89 -0
- package/dist/cli/role.js +1 -0
- package/dist/cli/services-command.js +1 -0
- package/dist/cli/team-workspace-command.js +56 -2
- package/dist/config/config-field-policy.js +71 -1
- package/dist/config/config-manager.js +11 -1
- package/dist/config/providers-config.js +8 -4
- package/dist/config/providers-management.js +11 -3
- package/dist/config/resolved-config-op.js +3 -2
- package/dist/core/auth/delegation-authorization.js +33 -26
- package/dist/core/auth/operation-catalog.js +9 -0
- package/dist/core/command/cli-intent-parser.js +13 -0
- package/dist/core/command/command-handler.js +45 -2
- package/dist/core/command/menu-handler.js +6 -1
- package/dist/core/command/menu-protocol.js +24 -0
- package/dist/core/command/remote-shell.js +565 -0
- package/dist/core/daemon-control.js +57 -1
- package/dist/core/daemon-lifecycle.js +16 -2
- package/dist/core/evolagent-registry.js +6 -2
- package/dist/core/ipc-registration.js +1 -0
- package/dist/core/message/aun-ipc-sender.js +118 -56
- package/dist/core/message/contact-admission.js +91 -6
- package/dist/core/message/contact-pending-inbound.js +113 -0
- package/dist/core/message/contact-thread-approval.js +212 -0
- package/dist/core/message/im-renderer.js +40 -1
- package/dist/core/message/message-admission.js +5 -39
- package/dist/core/message/message-bridge.js +92 -39
- package/dist/core/message/message-log.js +24 -0
- package/dist/core/message/message-queue.js +97 -15
- package/dist/core/message/response-engine.js +151 -18
- package/dist/core/model/config-scope.js +6 -14
- package/dist/core/model/model-diagnostics.js +19 -0
- package/dist/core/model/model-fallback.js +13 -2
- package/dist/core/pack-auth.js +3 -0
- package/dist/core/pack-install.js +1 -1
- package/dist/core/permission/ec-command-parser.js +106 -19
- package/dist/core/permission/services-path-acl.js +451 -0
- package/dist/core/permission/tool-policy.js +5 -1
- package/dist/core/relation/peer-identity.js +13 -0
- package/dist/core/task/task-recovery-service.js +1 -0
- package/dist/core/thread/topic-id.js +15 -0
- package/dist/directory/owner-directory-admission.js +11 -8
- package/dist/directory/owner-directory-cache.js +19 -0
- package/dist/directory/owner-directory-markdown.js +1 -1
- package/dist/directory/owner-directory-policy.js +5 -30
- package/dist/directory/owner-directory-request-operation.js +5 -2
- package/dist/eck/kit-renderer.js +1 -1
- package/dist/eck/message-renderer.js +28 -5
- package/dist/ecweb/runtime/supervisor.js +36 -8
- package/dist/event-center/center-config.js +9 -5
- package/dist/event-center/dispatcher.js +10 -1
- package/dist/event-center/ipc-operation.js +19 -0
- package/dist/event-center/registry.js +20 -5
- package/dist/event-center/runtime.js +10 -7
- package/dist/index.js +4 -0
- package/dist/ipc.js +25 -1
- package/dist/outputs/authorization.js +16 -0
- package/dist/outputs/cards.js +336 -0
- package/dist/outputs/events.js +3 -2
- package/dist/outputs/protocol.js +1 -0
- package/dist/outputs/service.js +2 -15
- package/dist/services/index.js +29 -5
- package/dist/services/ipc-operation.js +84 -0
- package/dist/services/pack-manager.js +1 -0
- package/dist/services/service-payload.js +13 -7
- package/dist/stats/budget.js +1 -1
- package/dist/stats/model-resolver.js +2 -2
- package/dist/stats/quota-query.js +95 -0
- package/dist/trigger/script-sandbox.js +12 -0
- package/dist/utils/atomic-write.js +22 -8
- package/dist/utils/evolcore-version.js +2 -2
- package/dist/utils/host-info.js +100 -1
- package/dist/utils/npm-ops.js +43 -8
- package/dist/workbench/service.js +1 -1
- package/kits/docs/evolcore/INDEX.md +2 -0
- package/kits/docs/evolcore/aid.md +25 -0
- package/kits/docs/evolcore/config.md +4 -1
- package/kits/docs/evolcore/directory.md +8 -9
- package/kits/docs/evolcore/msg.md +9 -0
- package/kits/docs/evolcore/provider.md +1 -1
- package/kits/docs/evolcore/quota.md +54 -0
- package/kits/docs/evolcore/role.md +3 -0
- package/kits/docs/evolcore/stats.md +2 -0
- package/kits/docs/evolcore/trigger.md +2 -0
- package/kits/schemas/agent-config.schema.20.json +24 -0
- package/kits/skills/.switches.json +4 -0
- package/kits/skills/agent-output-cards/SKILL.md +57 -0
- package/kits/skills/ec-provider/SKILL.md +57 -8
- package/kits/templates/roles/visitor.json +1 -0
- package/kits/templates/system-fragments/commands.md +1 -0
- package/kits/templates/system-fragments/directory-contacts.md +3 -4
- package/kits/templates/system-fragments/thread.md +1 -0
- package/kits/templates/system-fragments/venue.md +11 -0
- package/package.json +2 -2
- package/scripts/agent-template/inspect.mjs +46 -10
- package/scripts/agent-template/shared/common.mjs +9 -3
- package/scripts/agent-template/shared/team-schema.json +6 -4
- package/scripts/agent-template/shared/template-contract.mjs +60 -10
- package/scripts/agent-template/shared/template-package.mjs +182 -21
- package/scripts/agent-template/shared/template-runtime.mjs +35 -2
- package/scripts/agent-template/shared/template.mjs +2 -2
- package/scripts/agent-template/team-pack.mjs +46 -11
package/dist/cli/directory.js
CHANGED
|
@@ -74,7 +74,12 @@ function output(result, json) {
|
|
|
74
74
|
}
|
|
75
75
|
switch (result.action) {
|
|
76
76
|
case 'request': {
|
|
77
|
-
|
|
77
|
+
if (result.status === 'queued') {
|
|
78
|
+
console.log(`✓ 已将加密 friend.invite.v1 加好友申请排入发送队列,目标=${result.targetAid} outbox_id=${result.outbox_id ?? '-'}`);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
console.log(`✓ 已向 ${result.targetAid} 发送加密 friend.invite.v1 加好友申请,message_id=${result.message_id ?? '-'}`);
|
|
82
|
+
}
|
|
78
83
|
console.log('发送成功只表示申请已提交;请等待 Evol App 处理并同步联系人名录,再重试原消息。');
|
|
79
84
|
return;
|
|
80
85
|
}
|
package/dist/cli/index.js
CHANGED
|
@@ -72,6 +72,7 @@ AUN:
|
|
|
72
72
|
invoke 统一模型调用:按 provider 的 style 路由到内置执行器
|
|
73
73
|
ability 按 AID 管理能力插件、运行、发布和作业
|
|
74
74
|
stats Token 用量与费用统计
|
|
75
|
+
quota 查询 Agent 和对端的生效限额、已用与剩余额度
|
|
75
76
|
skill EC 技能管理:加载、安装、启停与索引刷新
|
|
76
77
|
diagnose 检查启动环境
|
|
77
78
|
version 显示组件版本
|
|
@@ -108,7 +109,7 @@ export const KNOWN_TOP_LEVEL_COMMANDS = new Set([
|
|
|
108
109
|
'agent', 'aid', 'rpc', 'diag', 'menu-client',
|
|
109
110
|
'storage', 'fs', 'msg', 'thread', 'events', 'services',
|
|
110
111
|
'session', 'getmeta', 'group', 'model', 'skill', 'response',
|
|
111
|
-
'config', 'peer', 'directory', 'role', 'stats',
|
|
112
|
+
'config', 'peer', 'directory', 'role', 'stats', 'quota',
|
|
112
113
|
'provider', 'invoke', 'ability',
|
|
113
114
|
// 版本三个别名在 switch 之前统一处理(含只在早期分支出现的 -V)。
|
|
114
115
|
'version', '-v', '-V', '--version',
|
|
@@ -691,6 +692,11 @@ export async function main(args) {
|
|
|
691
692
|
await handleStats(strippedArgs.slice(1));
|
|
692
693
|
break;
|
|
693
694
|
}
|
|
695
|
+
case 'quota': {
|
|
696
|
+
const { cmdQuota } = await import('./quota.js');
|
|
697
|
+
await cmdQuota(strippedArgs.slice(1));
|
|
698
|
+
break;
|
|
699
|
+
}
|
|
694
700
|
case 'version':
|
|
695
701
|
case '-v':
|
|
696
702
|
case '--version': {
|
|
@@ -59,6 +59,8 @@ const MANAGED_TASK_COMMANDS = new Set([
|
|
|
59
59
|
// `stats` reads the usage database directly. It authorizes each managed call
|
|
60
60
|
// against the task's relation role in `resolveManagedStatsScope`.
|
|
61
61
|
'stats',
|
|
62
|
+
// Quota reads validate task credentials and scope inside quota.op.
|
|
63
|
+
'quota',
|
|
62
64
|
'status',
|
|
63
65
|
'storage',
|
|
64
66
|
'task',
|
package/dist/cli/model.js
CHANGED
|
@@ -18,6 +18,7 @@ import { getCatalog, getModelInfo, catalogEfforts, resolveCatalogModel, assertCa
|
|
|
18
18
|
import { constrainResolvedModelForRole, filterModelsForRole, validateModelSelectionForRole, } from '../core/model/model-permission.js';
|
|
19
19
|
import { resolvePaths } from '../paths.js';
|
|
20
20
|
import { daemonUnavailableMessage, queryDaemon } from './help.js';
|
|
21
|
+
import { readTaskRuntimeContextFromEnv } from './task-context.js';
|
|
21
22
|
import { parsePeerKey } from '../core/relation/peer-identity.js';
|
|
22
23
|
import { resolvePeerRoleDetail } from '../config/peer-role-resolver.js';
|
|
23
24
|
import { AGENT_DELEGATION_TOKEN_ENV, readDelegationCredential } from '../core/auth/agent-delegation.js';
|
|
@@ -189,7 +190,7 @@ Commands:
|
|
|
189
190
|
list 列出可用模型,标注当前 Agent 级模型
|
|
190
191
|
current 显示 Agent 级模型(经角色约束)+ 来源
|
|
191
192
|
info <model-id> 查看单个模型详情(厂商/上下文/价格/模态/effort/状态)
|
|
192
|
-
use <model-id> 设置 Agent
|
|
193
|
+
use <model-id> 设置 Agent 级模型(托管会话省略 --self;--self 仅可用于等于本端 AID)
|
|
193
194
|
reset 清除 Agent 级模型与推理强度,回落到较低优先级配置
|
|
194
195
|
effort <level> 设置 Agent 级推理强度(low|medium|high|xhigh|max|auto)
|
|
195
196
|
check 诊断网关连通性与模型可用性(分阶段输出进度)
|
|
@@ -203,6 +204,7 @@ Commands:
|
|
|
203
204
|
修改 Agent 级后,该 Agent 所有会话的下一条消息即时生效。
|
|
204
205
|
角色策略请通过角色策略编辑器修改。
|
|
205
206
|
托管会话内省略 --self/--peer/--role 时,命令作用于当前会话;写操作仅当前 Agent 的 owner/admin 可用。
|
|
207
|
+
托管会话的写操作不接受指向其他 Agent 的 --self,也不接受 --peer/--role;--self <本端 AID> 等同省略。
|
|
206
208
|
|
|
207
209
|
Options:
|
|
208
210
|
--self <aid> 本端 AID
|
|
@@ -216,7 +218,8 @@ Options:
|
|
|
216
218
|
ec model list
|
|
217
219
|
ec model current --self bot.agentid.pub --peer aun#alice.agentid.pub
|
|
218
220
|
ec model info deepseek-v4-pro
|
|
219
|
-
ec model use opus
|
|
221
|
+
ec model use opus # 托管会话(作用于当前 Agent)
|
|
222
|
+
ec model use opus --self bot.agentid.pub # 非托管终端
|
|
220
223
|
ec model effort high --self bot.agentid.pub
|
|
221
224
|
ec model reset --self bot.agentid.pub
|
|
222
225
|
ec model check --self bot.agentid.pub`;
|
|
@@ -485,9 +488,21 @@ export async function cmdModel(args) {
|
|
|
485
488
|
return;
|
|
486
489
|
}
|
|
487
490
|
if (process.env.EVOLCORE_SESSION_ID) {
|
|
488
|
-
if (!['list', 'current', 'info', 'check'].includes(sub)
|
|
489
|
-
|
|
490
|
-
|
|
491
|
+
if (!['list', 'current', 'info', 'check'].includes(sub)) {
|
|
492
|
+
if (args.some(arg => arg === '--peer' || arg === '--role')) {
|
|
493
|
+
fail(formatJson, 'NOT_ALLOWED', 'Managed model writes cannot select --peer or --role');
|
|
494
|
+
}
|
|
495
|
+
const selfIndex = args.indexOf('--self');
|
|
496
|
+
if (selfIndex !== -1) {
|
|
497
|
+
// 托管写入只作用于当前会话的 Agent;`--self <本端 AID>` 是幂等写法,
|
|
498
|
+
// 与省略等价,按 help 的示例照抄不应失败。
|
|
499
|
+
const requested = args[selfIndex + 1];
|
|
500
|
+
const own = process.env.EVOLCORE_SELF_AID || readTaskRuntimeContextFromEnv()?.selfAid;
|
|
501
|
+
if (!own || requested !== own) {
|
|
502
|
+
fail(formatJson, 'NOT_ALLOWED', 'Managed model writes apply to the current session Agent; omit --self (--self must equal the current AID)');
|
|
503
|
+
}
|
|
504
|
+
args = args.slice(0, selfIndex).concat(args.slice(selfIndex + 2));
|
|
505
|
+
}
|
|
491
506
|
}
|
|
492
507
|
await runManagedCliOperation(['model', ...args], formatJson, sub === 'check' ? 60_000 : 10_000);
|
|
493
508
|
return;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { resolvePaths } from '../paths.js';
|
|
3
|
+
import { readDelegationCredential } from '../core/auth/agent-delegation.js';
|
|
4
|
+
import { parseQuotaCommand } from '../stats/quota-query.js';
|
|
5
|
+
import { daemonUnavailableMessage, queryDaemon, wantsHelp } from './help.js';
|
|
6
|
+
const HELP = `用法: ec quota status [--self <agent-aid>] [--peer <aid|channel#id>] [--format text|json]
|
|
7
|
+
|
|
8
|
+
查询 Agent 预算及对端的角色费用配额(上限、已用、剩余、周期、独立/共享、是否受限)。
|
|
9
|
+
查看或修改角色额度规则使用 ec role quota show|set|disable|inherit。
|
|
10
|
+
托管会话默认当前 Agent 和当前对端;宿主终端必须指定 --self,省略 --peer 时只查 Agent。
|
|
11
|
+
Owner/Admin 可查询指定对端;普通对端只可查询当前关系,不返回 Agent 总用量。
|
|
12
|
+
群聊默认查询当前发言人在本群生效的角色额度。
|
|
13
|
+
角色额度与一般预算分别返回,币种与计费口径不混算;-1 表示不限额。
|
|
14
|
+
|
|
15
|
+
ec quota status
|
|
16
|
+
ec quota status --peer alice.agentid.cn --format json
|
|
17
|
+
ec quota status --self bot.agentid.cn --format json`;
|
|
18
|
+
export async function cmdQuota(args) {
|
|
19
|
+
if (!args.length || wantsHelp(args)) {
|
|
20
|
+
console.log(HELP);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const json = args.some((arg, index) => arg === '--format=json' || arg === '--format' && args[index + 1] === 'json');
|
|
24
|
+
try {
|
|
25
|
+
parseQuotaCommand(args);
|
|
26
|
+
const sessionId = process.env.EVOLCORE_SESSION_ID;
|
|
27
|
+
const delegationToken = readDelegationCredential();
|
|
28
|
+
const managed = sessionId !== undefined || delegationToken !== undefined;
|
|
29
|
+
if (managed && (!sessionId || !delegationToken))
|
|
30
|
+
throw Object.assign(new Error('Current task delegation is required'), { code: 'DELEGATION_REQUIRED' });
|
|
31
|
+
let controlToken;
|
|
32
|
+
if (!managed) {
|
|
33
|
+
try {
|
|
34
|
+
controlToken = fs.readFileSync(resolvePaths().controlToken, 'utf8').trim();
|
|
35
|
+
}
|
|
36
|
+
catch { }
|
|
37
|
+
}
|
|
38
|
+
const { response, transportError } = await queryDaemon(resolvePaths().socket, {
|
|
39
|
+
type: 'quota.op', argv: ['quota', ...args],
|
|
40
|
+
...(managed ? { sessionId, delegationToken } : { controlToken }),
|
|
41
|
+
}, 30_000);
|
|
42
|
+
if (!response)
|
|
43
|
+
throw Object.assign(new Error(daemonUnavailableMessage(transportError, 'Unable to connect to the evolcore daemon')), { code: 'DAEMON_UNAVAILABLE' });
|
|
44
|
+
if (!response.ok || !response.result)
|
|
45
|
+
throw Object.assign(new Error(response.error ?? 'Quota query failed'), { code: response.code ?? 'QUOTA_QUERY_FAILED' });
|
|
46
|
+
if (json)
|
|
47
|
+
console.log(JSON.stringify(response.result, null, 2));
|
|
48
|
+
else
|
|
49
|
+
console.log(formatQuota(response.result));
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
const failure = { ok: false, code: error.code ?? 'QUOTA_QUERY_FAILED', error: error.message ?? String(error) };
|
|
53
|
+
if (json)
|
|
54
|
+
console.log(JSON.stringify(failure));
|
|
55
|
+
else
|
|
56
|
+
console.error(`❌ [${failure.code}] ${failure.error}`);
|
|
57
|
+
process.exitCode = 1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export function formatQuota(result) {
|
|
61
|
+
const lines = [`Agent: ${result.selfAid}`];
|
|
62
|
+
const amount = (value, currency) => value < 0 ? '不限额' : `${value.toFixed(4)} ${currency}`;
|
|
63
|
+
const budget = (status) => {
|
|
64
|
+
for (const [label, limit, used, remaining] of [
|
|
65
|
+
['日预算', status.daily_limit_usd, status.daily_used_usd, status.daily_remaining_usd],
|
|
66
|
+
['月预算', status.monthly_limit_usd, status.monthly_used_usd, status.monthly_remaining_usd],
|
|
67
|
+
])
|
|
68
|
+
lines.push(` ${label}: 上限 ${amount(limit, 'USD')} / 已用 ${amount(used, 'USD')} / 剩余 ${amount(remaining, 'USD')}`);
|
|
69
|
+
};
|
|
70
|
+
if (result.agent.budget)
|
|
71
|
+
budget(result.agent.budget);
|
|
72
|
+
else
|
|
73
|
+
lines.push(' Agent 总预算用量: 仅 Owner/Admin 可见');
|
|
74
|
+
if (result.relation) {
|
|
75
|
+
const relation = result.relation;
|
|
76
|
+
const quota = relation.roleQuota;
|
|
77
|
+
lines.push(`对端: ${relation.peerKey}${relation.chatType === 'group' ? ` / 发言人 ${relation.actorId}` : ''}`);
|
|
78
|
+
lines.push(` 角色: ${quota.role} / ${quota.scope === 'role' ? '同角色共享额度' : '每个对端独立额度'}`);
|
|
79
|
+
lines.push(` 角色限额: ${quota.enabled ? '启用' : '不限制'}${quota.reason ? ` (${quota.reason})` : ''}`);
|
|
80
|
+
lines.push(` 上限 ${amount(quota.limit_amount, quota.currency)} / 已用 ${amount(quota.used_amount, quota.currency)} / 剩余 ${amount(quota.remaining_amount, quota.currency)}`);
|
|
81
|
+
lines.push(` 重置周期: ${quota.reset_mode} / 计费: ${quota.cost_basis}`);
|
|
82
|
+
if (relation.budget) {
|
|
83
|
+
lines.push(' 对端生效的一般预算(按 Agent 总用量计算):');
|
|
84
|
+
budget(relation.budget);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
lines.push(`当前是否被额度阻止: ${result.hard_blocked ? '是' : '否'}`);
|
|
88
|
+
return lines.join('\n');
|
|
89
|
+
}
|
package/dist/cli/role.js
CHANGED
|
@@ -112,6 +112,7 @@ function printHelp() {
|
|
|
112
112
|
申请不会立即改变权限,只记录一条待审批请求,交由本 Agent 的 owner 审批。
|
|
113
113
|
approve / reject 只能由本 Agent 的 owner 执行;审批通过后才写入关系角色。
|
|
114
114
|
quota 管理角色定义 usageLimits,不是消息准入频率 access.requestLimit。
|
|
115
|
+
quota show 查看角色额度规则及继承结果;查询具体对端已用和剩余使用 ec quota status。
|
|
115
116
|
quota set 不自动启用限制;需要时明确传 --enabled true。disable 保留金额等设置。
|
|
116
117
|
inherit 删除角色自己的额度覆盖,恢复使用 member 额度;set 会将当前继承值物化为本角色配置。
|
|
117
118
|
owner/admin 不受角色配额限制;自定义角色没有显式额度时继承 member。
|
|
@@ -17,6 +17,7 @@ const HELP = `ec services — 服务路由运维
|
|
|
17
17
|
ec services ledger <包名> [--tail N] [--aid <aid>] 台账
|
|
18
18
|
ec services tail <包名> [--tail N] [--aid <aid>] 服务消息日志
|
|
19
19
|
ec services doctor [<包名>] [--aid <aid>] 诊断
|
|
20
|
+
ec services repair-acl [--aid <aid>] 收紧 services/ 的 NTFS ACL(幂等,仅 Windows)
|
|
20
21
|
ec services reload [--aid <aid>] 重载(全部包)
|
|
21
22
|
ec services enable / disable [--aid <aid>] 总闸
|
|
22
23
|
ec services rules show [<type>] [--aid <aid>] 调用准入规则
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import crypto from 'node:crypto';
|
|
2
4
|
import { authorizeLocalCommand } from './task-context.js';
|
|
3
|
-
import { agentWorkspaceDir } from '../paths.js';
|
|
5
|
+
import { agentOutputDir, agentWorkspaceDir, resolvePaths } from '../paths.js';
|
|
6
|
+
import { ipcQuery } from '../ipc.js';
|
|
7
|
+
import { readDelegationCredential, hashCurrentDelegatedCommand } from '../core/auth/agent-delegation.js';
|
|
8
|
+
import { publishOutputCard, removeOutputCard } from '../outputs/cards.js';
|
|
4
9
|
import { readTeamWorkspaceNavigation, upsertTeamWorkspaceNavigation, removeTeamWorkspaceNavigation, updateTeamWorkspaceNavigation, } from '../core/command/team-workspace-store.js';
|
|
5
10
|
import { readTeamMembers, updateTeamMembers } from '../core/command/team-workspace-team.js';
|
|
6
11
|
import { TeamWorkspaceBootstrapService, TeamWorkspaceInitializer } from '../core/command/team-workspace-bootstrap.js';
|
|
@@ -11,8 +16,10 @@ const USAGE = `用法: ec team workspace init [--workspace <绝对路径>]
|
|
|
11
16
|
ec team navigation update --replace-json <entries-json> [--expected-revision <n>]
|
|
12
17
|
ec team members show
|
|
13
18
|
ec team members update --members-json <aids-json>
|
|
19
|
+
ec team cards publish --file <card.json>
|
|
20
|
+
ec team cards remove --id <card-id>
|
|
14
21
|
|
|
15
|
-
所有命令只输出 JSON
|
|
22
|
+
所有命令只输出 JSON;cards 命令只允许当前 Agent Owner 的 AUN 私聊托管会话。`;
|
|
16
23
|
class TeamWorkspaceCommandError extends Error {
|
|
17
24
|
code;
|
|
18
25
|
constructor(code, message) {
|
|
@@ -55,6 +62,23 @@ function expectedRevision(args, current) {
|
|
|
55
62
|
return revision;
|
|
56
63
|
}
|
|
57
64
|
function output(value) { process.stdout.write(`${JSON.stringify(value, null, 2)}\n`); }
|
|
65
|
+
async function publishCardChanged(aid, id, revision) {
|
|
66
|
+
const sessionId = process.env.EVOLCORE_SESSION_ID;
|
|
67
|
+
const delegationToken = sessionId ? readDelegationCredential() : undefined;
|
|
68
|
+
if (sessionId && !delegationToken)
|
|
69
|
+
return false;
|
|
70
|
+
try {
|
|
71
|
+
const response = await ipcQuery(resolvePaths().socket, {
|
|
72
|
+
type: 'events.op', argv: ['native-publish', 'team.output-cards.changed', '--aid', aid,
|
|
73
|
+
'--data', JSON.stringify({ sourceAid: aid, revision, cursor: `${revision}.1`, id })],
|
|
74
|
+
...(sessionId && delegationToken ? { sessionId, delegationToken, delegationCommandHash: hashCurrentDelegatedCommand() } : {}),
|
|
75
|
+
}, 5_000, { throwOnError: false });
|
|
76
|
+
return response?.ok === true;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
58
82
|
function assertOwnerContext(context) {
|
|
59
83
|
if (context.channel !== 'aun' || context.chatType !== 'private' || context.peerRole !== 'owner' || !context.selfAid || !context.peerId) {
|
|
60
84
|
throw new TeamWorkspaceCommandError('NOT_ALLOWED', 'Team workspace commands require the current Agent Owner in an AUN private chat');
|
|
@@ -74,6 +98,36 @@ export async function cmdTeamWorkspace(rawArgs) {
|
|
|
74
98
|
try {
|
|
75
99
|
const context = await authorizeLocalCommand(['team', ...rawArgs]);
|
|
76
100
|
assertOwnerContext(context);
|
|
101
|
+
if (rawArgs[0] === 'cards' && rawArgs[1] === 'publish') {
|
|
102
|
+
assertFlags(rawArgs.slice(2), ['--file']);
|
|
103
|
+
const fileIndex = rawArgs.indexOf('--file');
|
|
104
|
+
if (rawArgs.length !== 4 || fileIndex < 0)
|
|
105
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', USAGE);
|
|
106
|
+
const source = path.resolve(rawArgs[fileIndex + 1]);
|
|
107
|
+
let manifest;
|
|
108
|
+
try {
|
|
109
|
+
manifest = JSON.parse(fs.readFileSync(source, 'utf8'));
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
throw new TeamWorkspaceCommandError('INVALID_CARD', `Cannot read a valid card JSON file: ${source}`);
|
|
113
|
+
}
|
|
114
|
+
const card = publishOutputCard(context.selfAid, manifest, agentOutputDir);
|
|
115
|
+
const notified = await publishCardChanged(context.selfAid, card.id, card.version);
|
|
116
|
+
output({ ok: true, id: card.id, version: card.version, path: path.relative(agentOutputDir(context.selfAid), path.join(agentOutputDir(context.selfAid), '.cards', `${card.id}.json`)).split(path.sep).join('/'), notified });
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (rawArgs[0] === 'cards' && rawArgs[1] === 'remove') {
|
|
120
|
+
assertFlags(rawArgs.slice(2), ['--id']);
|
|
121
|
+
const idIndex = rawArgs.indexOf('--id');
|
|
122
|
+
if (rawArgs.length !== 4 || idIndex < 0)
|
|
123
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', USAGE);
|
|
124
|
+
const id = rawArgs[idIndex + 1];
|
|
125
|
+
const removed = removeOutputCard(context.selfAid, id, agentOutputDir);
|
|
126
|
+
const revision = crypto.createHash('sha256').update(`${context.selfAid}:${id}:${Date.now()}`).digest('hex').slice(0, 24);
|
|
127
|
+
const notified = removed && await publishCardChanged(context.selfAid, id, revision);
|
|
128
|
+
output({ ok: true, id, removed, notified: notified || false });
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
77
131
|
if (rawArgs[0] === 'workspace' && rawArgs[1] === 'init') {
|
|
78
132
|
const pathIndex = rawArgs.indexOf('--workspace');
|
|
79
133
|
const workspace = pathIndex >= 0 ? rawArgs[pathIndex + 1] : undefined;
|
|
@@ -34,7 +34,7 @@ export function isAgentOnlyModelField(fieldPath) {
|
|
|
34
34
|
return parts.length === 3
|
|
35
35
|
&& parts[0] === 'baseagents'
|
|
36
36
|
&& SUPPORTED_BASEAGENTS.has(parts[1])
|
|
37
|
-
&& (parts[2] === 'model' || parts[2] === 'effort' || parts[2] === 'reasoning');
|
|
37
|
+
&& (parts[2] === 'model' || parts[2] === 'effort' || parts[2] === 'reasoning' || parts[2] === 'fallback');
|
|
38
38
|
}
|
|
39
39
|
/** Baseagent selection is Agent-owned as well. */
|
|
40
40
|
export function isAgentOnlyBaseagentField(fieldPath) {
|
|
@@ -96,6 +96,15 @@ export function resolveConfigFieldRule(fieldPath, scope) {
|
|
|
96
96
|
const top = parts[0];
|
|
97
97
|
if (SENSITIVE_TOP_FIELDS.has(top))
|
|
98
98
|
return { class: 'sensitive' };
|
|
99
|
+
if (field === 'version')
|
|
100
|
+
return scalar(field, 'member-version', 'owner-only');
|
|
101
|
+
if (top === 'update') {
|
|
102
|
+
if (field === 'update')
|
|
103
|
+
return { ...readonlyObject('update'), access: 'owner-only' };
|
|
104
|
+
if (field === 'update.publisher')
|
|
105
|
+
return scalar('update', 'aid', 'owner-only');
|
|
106
|
+
return field === 'update.mode' ? scalar('update', 'update-mode', 'owner-only') : { class: 'unknown' };
|
|
107
|
+
}
|
|
99
108
|
if (top === 'Services') {
|
|
100
109
|
return parts.length === 3 && /^[A-Za-z0-9_-]+$/u.test(parts[1]) && ['provider', 'model', 'effort'].includes(parts[2])
|
|
101
110
|
? scalar(field, parts[2] === 'effort' ? 'effort' : 'string', 'owner-only')
|
|
@@ -115,6 +124,9 @@ export function resolveConfigFieldRule(fieldPath, scope) {
|
|
|
115
124
|
return scalar(permissionKey, 'string');
|
|
116
125
|
if ((leaf === 'effort' || leaf === 'reasoning') && parts.length === 3)
|
|
117
126
|
return scalar(permissionKey, 'effort');
|
|
127
|
+
// 降级链是模型选择的一部分:Agent 级可写,但每项都要能换供应商,故 owner-only。
|
|
128
|
+
if (leaf === 'fallback' && parts.length === 3)
|
|
129
|
+
return scalar(permissionKey, 'fallback-chain', 'owner-only');
|
|
118
130
|
if (baseagent === 'claude' && (leaf === 'agentProgressSummaries' || leaf === 'excludeDynamicSections') && parts.length === 3) {
|
|
119
131
|
return scalar(permissionKey, 'boolean');
|
|
120
132
|
}
|
|
@@ -281,6 +293,50 @@ export function relationFieldWriteOperation(fieldPath) {
|
|
|
281
293
|
return 'mentionmode.update';
|
|
282
294
|
return undefined;
|
|
283
295
|
}
|
|
296
|
+
const MAX_FALLBACK_ITEMS = 3;
|
|
297
|
+
const PROVIDER_ID_PATTERN = /^[A-Za-z0-9_-]+$/;
|
|
298
|
+
/**
|
|
299
|
+
* 降级链的值是 JSON 数组,每项必须同时给出 provider / model / effort:
|
|
300
|
+
* 降级可能换用不同供应商的不同模型,缺任何一项都无法构造请求。
|
|
301
|
+
*/
|
|
302
|
+
function parseFallbackChainValue(fieldPath, raw) {
|
|
303
|
+
let parsed;
|
|
304
|
+
try {
|
|
305
|
+
parsed = JSON.parse(raw);
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
return { ok: false, reason: `Config field ${fieldPath} requires a JSON array of {provider, model, effort}` };
|
|
309
|
+
}
|
|
310
|
+
if (!Array.isArray(parsed)) {
|
|
311
|
+
return { ok: false, reason: `Config field ${fieldPath} requires a JSON array of {provider, model, effort}` };
|
|
312
|
+
}
|
|
313
|
+
if (parsed.length > MAX_FALLBACK_ITEMS) {
|
|
314
|
+
return { ok: false, reason: `Config field ${fieldPath} accepts at most ${MAX_FALLBACK_ITEMS} fallback entries` };
|
|
315
|
+
}
|
|
316
|
+
const entries = [];
|
|
317
|
+
for (const [index, item] of parsed.entries()) {
|
|
318
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) {
|
|
319
|
+
return { ok: false, reason: `Config field ${fieldPath} entry ${index} must be an object` };
|
|
320
|
+
}
|
|
321
|
+
const extra = Object.keys(item)
|
|
322
|
+
.filter(key => !['provider', 'model', 'effort'].includes(key));
|
|
323
|
+
if (extra.length) {
|
|
324
|
+
return { ok: false, reason: `Config field ${fieldPath} entry ${index} has unsupported keys: ${extra.join(', ')}` };
|
|
325
|
+
}
|
|
326
|
+
const { provider, model, effort } = item;
|
|
327
|
+
if (typeof provider !== 'string' || !PROVIDER_ID_PATTERN.test(provider)) {
|
|
328
|
+
return { ok: false, reason: `Config field ${fieldPath} entry ${index} needs a provider id` };
|
|
329
|
+
}
|
|
330
|
+
if (typeof model !== 'string' || !model.trim()) {
|
|
331
|
+
return { ok: false, reason: `Config field ${fieldPath} entry ${index} needs a non-empty model` };
|
|
332
|
+
}
|
|
333
|
+
if (typeof effort !== 'string' || !EFFORTS.has(effort)) {
|
|
334
|
+
return { ok: false, reason: `Config field ${fieldPath} entry ${index} needs an effort of ${[...EFFORTS].join(', ')}` };
|
|
335
|
+
}
|
|
336
|
+
entries.push({ provider, model: model.trim(), effort });
|
|
337
|
+
}
|
|
338
|
+
return { ok: true, value: entries };
|
|
339
|
+
}
|
|
284
340
|
export function parseConfigFieldValue(fieldPath, rawValue) {
|
|
285
341
|
const rule = resolveConfigFieldRule(fieldPath);
|
|
286
342
|
if (rule.class !== 'safe-scalar' || !rule.valueKind) {
|
|
@@ -290,6 +346,18 @@ export function parseConfigFieldValue(fieldPath, rawValue) {
|
|
|
290
346
|
return { ok: false, reason: `Config field ${fieldPath} requires a string CLI value` };
|
|
291
347
|
const raw = rawValue.trim();
|
|
292
348
|
switch (rule.valueKind) {
|
|
349
|
+
case 'member-version':
|
|
350
|
+
return /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/.test(rawValue)
|
|
351
|
+
? { ok: true, value: rawValue }
|
|
352
|
+
: { ok: false, reason: `Config field ${fieldPath} must be an explicit x.y.z version` };
|
|
353
|
+
case 'aid':
|
|
354
|
+
return isValidAid(rawValue)
|
|
355
|
+
? { ok: true, value: rawValue }
|
|
356
|
+
: { ok: false, reason: `Config field ${fieldPath} must be a valid AID` };
|
|
357
|
+
case 'update-mode':
|
|
358
|
+
return ['auto', 'manual', 'disabled'].includes(rawValue)
|
|
359
|
+
? { ok: true, value: rawValue }
|
|
360
|
+
: { ok: false, reason: `Config field ${fieldPath} must be auto, manual, or disabled` };
|
|
293
361
|
case 'string':
|
|
294
362
|
return raw ? { ok: true, value: raw } : { ok: false, reason: `Config field ${fieldPath} cannot be empty` };
|
|
295
363
|
case 'baseagent':
|
|
@@ -330,6 +398,8 @@ export function parseConfigFieldValue(fieldPath, rawValue) {
|
|
|
330
398
|
return EFFORTS.has(raw)
|
|
331
399
|
? { ok: true, value: raw }
|
|
332
400
|
: { ok: false, reason: `Config field ${fieldPath} must be one of ${[...EFFORTS].join(', ')}; use unset for auto` };
|
|
401
|
+
case 'fallback-chain':
|
|
402
|
+
return parseFallbackChainValue(fieldPath, raw);
|
|
333
403
|
case 'chatmode':
|
|
334
404
|
if (fieldPath.trim() === 'chatmode.group') {
|
|
335
405
|
return raw === 'proactive'
|
|
@@ -1299,6 +1299,12 @@ function validateProcessOnlyFields(target, value) {
|
|
|
1299
1299
|
if (target === ConfigTarget.Process || !value || typeof value !== 'object')
|
|
1300
1300
|
return [];
|
|
1301
1301
|
const errors = [];
|
|
1302
|
+
if (target === ConfigTarget.Defaults || target === ConfigTarget.Relation) {
|
|
1303
|
+
for (const field of ['version', 'update'])
|
|
1304
|
+
if (Object.prototype.hasOwnProperty.call(value, field)) {
|
|
1305
|
+
errors.push(`/${field} is only allowed in Agent config`);
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1302
1308
|
if (Object.prototype.hasOwnProperty.call(value, 'debug')) {
|
|
1303
1309
|
errors.push('/debug is only allowed in process config');
|
|
1304
1310
|
}
|
|
@@ -1592,13 +1598,15 @@ function stripStaticOwnerField(config) {
|
|
|
1592
1598
|
if (!config)
|
|
1593
1599
|
return config;
|
|
1594
1600
|
if (!Object.prototype.hasOwnProperty.call(config, 'owner')
|
|
1601
|
+
&& !Object.prototype.hasOwnProperty.call(config, 'version')
|
|
1602
|
+
&& !Object.prototype.hasOwnProperty.call(config, 'update')
|
|
1595
1603
|
&& !Object.prototype.hasOwnProperty.call(config, 'owners')
|
|
1596
1604
|
&& !Object.prototype.hasOwnProperty.call(config, 'admins')
|
|
1597
1605
|
&& !Object.prototype.hasOwnProperty.call(config, 'access')
|
|
1598
1606
|
&& !Object.prototype.hasOwnProperty.call(config, 'groupSlashRequireMentions')
|
|
1599
1607
|
&& !Object.prototype.hasOwnProperty.call(config, 'fullaccess'))
|
|
1600
1608
|
return config;
|
|
1601
|
-
const { owner: _owner, owners: _owners, admins: _admins, access: _access, groupSlashRequireMentions: _groupSlashRequireMentions, fullaccess: _fullaccess, ...rest } = config;
|
|
1609
|
+
const { owner: _owner, version: _memberVersion, update: _update, owners: _owners, admins: _admins, access: _access, groupSlashRequireMentions: _groupSlashRequireMentions, fullaccess: _fullaccess, ...rest } = config;
|
|
1602
1610
|
return rest;
|
|
1603
1611
|
}
|
|
1604
1612
|
function stripDefaultsLegacyModelFields(config) {
|
|
@@ -1652,6 +1660,8 @@ export function resolveEffective(sel, opts = {}) {
|
|
|
1652
1660
|
const effective = {
|
|
1653
1661
|
$schema_version: config.$schema_version ?? currentVersion('agent-config'),
|
|
1654
1662
|
aid: config.aid ?? sel.self ?? '',
|
|
1663
|
+
...(config.version !== undefined ? { version: config.version } : {}),
|
|
1664
|
+
...(config.update !== undefined ? { update: config.update } : {}),
|
|
1655
1665
|
enabled: config.enabled,
|
|
1656
1666
|
lifecycle: config.lifecycle,
|
|
1657
1667
|
initialized: config.initialized,
|
|
@@ -102,6 +102,13 @@ function validProviderBaseUrl(value) {
|
|
|
102
102
|
return false;
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
+
export function resolveProviderBaseUrl(providerId, value) {
|
|
106
|
+
const baseUrl = resolveProviderEnvironmentValue(providerId, 'baseUrl', value);
|
|
107
|
+
if (!validProviderBaseUrl(baseUrl)) {
|
|
108
|
+
throw new Error(`Provider ${providerId} common.baseUrl must resolve to a valid http(s) URL`);
|
|
109
|
+
}
|
|
110
|
+
return baseUrl;
|
|
111
|
+
}
|
|
105
112
|
export function providerNameFromBaseUrl(baseUrl) {
|
|
106
113
|
const hostname = new URL(baseUrl).hostname.replace(/\.$/u, '');
|
|
107
114
|
if (isIP(hostname.replace(/^\[|\]$/gu, '')))
|
|
@@ -402,10 +409,7 @@ export function resolveProviderService(providerId, serviceType, config, defaultS
|
|
|
402
409
|
if (fixedStyle && service.style && service.style !== fixedStyle) {
|
|
403
410
|
throw new Error(`Provider ${providerId} service ${serviceType} must use style ${fixedStyle}`);
|
|
404
411
|
}
|
|
405
|
-
const resolvedBaseUrl =
|
|
406
|
-
if (!validProviderBaseUrl(resolvedBaseUrl)) {
|
|
407
|
-
throw new Error(`Provider ${providerId} common.baseUrl must resolve to a valid http(s) URL`);
|
|
408
|
-
}
|
|
412
|
+
const resolvedBaseUrl = resolveProviderBaseUrl(providerId, provider.common.baseUrl);
|
|
409
413
|
if (provider.domain !== undefined)
|
|
410
414
|
providerIdentity({ ...provider, common: { ...provider.common, baseUrl: resolvedBaseUrl } });
|
|
411
415
|
const base = resolvedBaseUrl.endsWith('/') ? resolvedBaseUrl : `${resolvedBaseUrl}/`;
|
|
@@ -7,11 +7,19 @@ import { ConfigTarget, mutateConfig, notifyConfigWrite } from './config-manager.
|
|
|
7
7
|
import { atomicReadJson } from '../utils/atomic-write.js';
|
|
8
8
|
import { readProvidersFile, validateProvidersFile } from './providers.js';
|
|
9
9
|
import { initializationRuntimePlan, providerEnvironmentVariable, providerNameFromBaseUrlIfStatic, resolveProviderId, resolveProviderService, resolveProviderServiceForBaseagent, validateProviderName } from './providers-config.js';
|
|
10
|
-
import { providerIdentity } from './provider-identity.js';
|
|
10
|
+
import { providerIdentity as storedProviderIdentity } from './provider-identity.js';
|
|
11
11
|
import { planProviderIdentityMigration } from './provider-identity-migration.js';
|
|
12
12
|
import { isInteractionSendAccepted, sendInteractionPayload } from '../core/message/message-utils.js';
|
|
13
|
-
import { providerServiceCredentials, providerServiceTypeForBaseagent } from './providers-config.js';
|
|
13
|
+
import { providerServiceCredentials, providerServiceTypeForBaseagent, resolveProviderBaseUrl } from './providers-config.js';
|
|
14
14
|
import { generateProviderTemplate, parseProviderTemplateInput } from './provider-templates.js';
|
|
15
|
+
/** Derive a missing identity during management without changing the stored URL reference. */
|
|
16
|
+
function providerIdentity(provider) {
|
|
17
|
+
if (provider.domain !== undefined || !providerEnvironmentVariable(provider.common.baseUrl)) {
|
|
18
|
+
return storedProviderIdentity(provider);
|
|
19
|
+
}
|
|
20
|
+
const baseUrl = resolveProviderBaseUrl('draft', provider.common.baseUrl);
|
|
21
|
+
return storedProviderIdentity({ ...provider, common: { ...provider.common, baseUrl } });
|
|
22
|
+
}
|
|
15
23
|
/** Shared template preview/merge; raw credentials never belong in a public response. */
|
|
16
24
|
export function prepareProviderTemplate(templateId, value, file = resolvePaths().providersConfig, draft) {
|
|
17
25
|
const input = parseProviderTemplateInput(value);
|
|
@@ -705,7 +713,7 @@ function assertProviderDomainUnchanged(previous, next) {
|
|
|
705
713
|
}
|
|
706
714
|
catch (error) {
|
|
707
715
|
const code = error?.code;
|
|
708
|
-
if (previous.domain === undefined &&
|
|
716
|
+
if (previous.domain === undefined && ['PROVIDER_DOMAIN_REQUIRED', 'PROVIDER_DOMAIN_INVALID', 'PROVIDER_BASE_URL_MISSING'].includes(code ?? '')) {
|
|
709
717
|
if (previous.common.baseUrl === next.common.baseUrl) {
|
|
710
718
|
if (next.domain !== undefined)
|
|
711
719
|
next.domain = providerIdentity(next).domain;
|
|
@@ -122,14 +122,15 @@ function resolveFieldCommand(argv, subcommand, options = {}) {
|
|
|
122
122
|
reason: 'Agent role policies are managed through the role policy editor',
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
+
// defaults.json 仍只允许手工编辑;Agent 级的 baseagents.<ba>.fallback 走正常字段写入。
|
|
125
126
|
const canContainFallback = field === 'baseagents'
|
|
126
127
|
|| /^baseagents\.[^.]+$/.test(field)
|
|
127
128
|
|| /^baseagents\.[^.]+\.fallback(?:\.|$)/.test(field);
|
|
128
|
-
if (subcommand !== 'get' && canContainFallback) {
|
|
129
|
+
if (subcommand !== 'get' && canContainFallback && selector.scope === 'defaults') {
|
|
129
130
|
return {
|
|
130
131
|
ok: false,
|
|
131
132
|
code: 'DEFAULTS_FILE_ONLY',
|
|
132
|
-
reason: 'Baseagent fallback is configured
|
|
133
|
+
reason: 'Baseagent fallback is configured in agents/defaults.json; edit that file and run `ec config validate --default`',
|
|
133
134
|
};
|
|
134
135
|
}
|
|
135
136
|
const fieldRule = resolveConfigFieldRule(field, selector.scope);
|
|
@@ -199,35 +199,42 @@ export function createDelegatedInvokeOperationExecutor({ agentDelegationRegistry
|
|
|
199
199
|
});
|
|
200
200
|
};
|
|
201
201
|
}
|
|
202
|
+
/** Resolve task identity once; each operation still authorizes its own target and scope. */
|
|
203
|
+
export async function resolveDelegatedIdentity(params, dependencies, invalidSessionCode = 'INVALID_DELEGATION') {
|
|
204
|
+
const validation = params.delegationGrant
|
|
205
|
+
? { ok: true, grant: params.delegationGrant }
|
|
206
|
+
: dependencies.agentDelegationRegistry?.validate(params.delegationToken, params.sessionId, params.delegationCommandHash);
|
|
207
|
+
if (!validation?.ok)
|
|
208
|
+
return {
|
|
209
|
+
ok: false, code: validation?.code ?? 'DELEGATION_REQUIRED',
|
|
210
|
+
error: validation?.reason ?? 'Valid task delegation is required',
|
|
211
|
+
};
|
|
212
|
+
const grant = validation.grant;
|
|
213
|
+
const session = await dependencies.sessionManager.getSessionById(params.sessionId);
|
|
214
|
+
if (!session || session.selfAID !== grant.selfAid || grant.sessionId !== params.sessionId) {
|
|
215
|
+
return { ok: false, code: invalidSessionCode, error: 'Delegation does not match the current session' };
|
|
216
|
+
}
|
|
217
|
+
let conversationId;
|
|
218
|
+
try {
|
|
219
|
+
conversationId = parsePeerKey(grant.peerKey).channelId;
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
return { ok: false, code: 'INVALID_DELEGATION', error: 'delegation contains an invalid relation key' };
|
|
223
|
+
}
|
|
224
|
+
const subject = buildAuthSubject({
|
|
225
|
+
selfAid: grant.selfAid, sessionId: params.sessionId, actorId: grant.actorId,
|
|
226
|
+
channel: grant.channel, channelType: grant.channelType, channelId: conversationId,
|
|
227
|
+
chatType: grant.chatType, conversationId, processOwners: dependencies.getProcessOwners(),
|
|
228
|
+
...trustedExecutionIdentityInput(grant),
|
|
229
|
+
});
|
|
230
|
+
return { ok: true, grant, session, subject };
|
|
231
|
+
}
|
|
202
232
|
export function createDelegationAuthorizer({ agentDelegationRegistry, sessionManager, getProcessOwners, }) {
|
|
203
233
|
return async function authorizeManagedAgentOperation(params, operation) {
|
|
204
|
-
const delegation = params
|
|
205
|
-
? { ok: true, grant: params.delegationGrant }
|
|
206
|
-
: agentDelegationRegistry.validate(params.delegationToken, params.sessionId, params.delegationCommandHash);
|
|
234
|
+
const delegation = await resolveDelegatedIdentity(params, { agentDelegationRegistry, sessionManager, getProcessOwners });
|
|
207
235
|
if (!delegation.ok)
|
|
208
|
-
return
|
|
209
|
-
const
|
|
210
|
-
if (!session || session.selfAID !== delegation.grant.selfAid) {
|
|
211
|
-
return { ok: false, code: 'INVALID_DELEGATION', error: 'delegation does not match the current session' };
|
|
212
|
-
}
|
|
213
|
-
let conversationId;
|
|
214
|
-
try {
|
|
215
|
-
conversationId = parsePeerKey(delegation.grant.peerKey).channelId;
|
|
216
|
-
}
|
|
217
|
-
catch {
|
|
218
|
-
return { ok: false, code: 'INVALID_DELEGATION', error: 'delegation contains an invalid relation key' };
|
|
219
|
-
}
|
|
220
|
-
const subject = buildAuthSubject({
|
|
221
|
-
selfAid: delegation.grant.selfAid,
|
|
222
|
-
actorId: delegation.grant.actorId,
|
|
223
|
-
channel: delegation.grant.channel,
|
|
224
|
-
channelType: delegation.grant.channelType,
|
|
225
|
-
channelId: conversationId,
|
|
226
|
-
chatType: delegation.grant.chatType,
|
|
227
|
-
conversationId,
|
|
228
|
-
processOwners: getProcessOwners(),
|
|
229
|
-
...trustedExecutionIdentityInput(delegation.grant),
|
|
230
|
-
});
|
|
236
|
+
return delegation;
|
|
237
|
+
const { subject } = delegation;
|
|
231
238
|
if (params.targetAid
|
|
232
239
|
&& params.targetAid !== delegation.grant.selfAid
|
|
233
240
|
&& subject.dataScope !== 'daemon'
|
|
@@ -1024,6 +1024,15 @@ const OPERATIONS = [
|
|
|
1024
1024
|
authorizationPolicy: { authority: 'trusted-fullaccess' },
|
|
1025
1025
|
},
|
|
1026
1026
|
// ── Stats Operations ──
|
|
1027
|
+
{
|
|
1028
|
+
id: 'quota.read',
|
|
1029
|
+
category: 'read',
|
|
1030
|
+
dangerous: false,
|
|
1031
|
+
defaultScopes: ['relation'],
|
|
1032
|
+
description: '查询 Agent 与当前关系的生效额度及余额',
|
|
1033
|
+
sources: ['agent-tool'],
|
|
1034
|
+
authorizationTarget: 'current-agent',
|
|
1035
|
+
},
|
|
1027
1036
|
{
|
|
1028
1037
|
id: 'stats.summary',
|
|
1029
1038
|
category: 'read',
|