evolcore 0.0.40 → 0.0.41-test.1
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 +94 -1
- package/bin/codex-managed-hook.mjs +11 -0
- package/bin/ec-safe-output.js +11 -1
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/baseagent.js +20 -43
- package/dist/agents/claude-runner.js +197 -197
- package/dist/agents/codex-runner.js +535 -259
- package/dist/agents/ecagent-runner.js +31 -12
- package/dist/agents/gemini-runner.js +27 -7
- package/dist/agents/runner-types.js +11 -3
- package/dist/aun/ability-device-routing.js +26 -0
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/group/fs-download.js +39 -0
- package/dist/aun/group/identity.js +36 -13
- package/dist/aun/group/operations.js +5 -0
- package/dist/aun/msg/managed-operation.js +72 -11
- package/dist/aun/msg/p2p.js +32 -7
- package/dist/aun/service-proxy.js +36 -12
- package/dist/aun/storage/download.js +30 -0
- package/dist/aun/storage/index.js +14 -6
- package/dist/channels/aun.js +367 -24
- package/dist/channels/daemon.js +39 -5
- package/dist/cli/agent-command.js +2 -0
- package/dist/cli/agent-create.js +98 -19
- package/dist/cli/agent.js +10 -3
- package/dist/cli/aun-commands.js +85 -41
- package/dist/cli/daemon-commands.js +678 -688
- package/dist/cli/fs-command.js +64 -2
- package/dist/cli/index.js +48 -4
- package/dist/cli/managed-command-guard.js +4 -0
- package/dist/cli/model.js +40 -40
- package/dist/cli/proxy-command.js +92 -0
- package/dist/cli/restart-monitor.js +17 -0
- package/dist/cli/role.js +85 -0
- package/dist/cli/session-command.js +128 -13
- package/dist/cli/stats.js +60 -4
- package/dist/cli/trigger-command.js +2 -2
- package/dist/config/access-policy.js +8 -1
- package/dist/config/boot-log.js +38 -1
- package/dist/config/config-field-policy.js +5 -32
- package/dist/config/config-manager.js +46 -39
- package/dist/config/config-operation-service.js +8 -11
- package/dist/config/contact-book-store.js +47 -21
- package/dist/config/contact-book.js +18 -12
- package/dist/config/contact-operation-service.js +3 -4
- package/dist/config/contact-request-service.js +11 -0
- package/dist/config/daemon-services.js +11 -0
- package/dist/config/gateway-config.js +89 -595
- package/dist/config/peer-role-resolver.js +15 -11
- package/dist/config/providers-config.js +12 -7
- package/dist/config/providers-import.js +3 -21
- package/dist/config/resolved-config-op.js +3 -0
- package/dist/config/role-command-service.js +166 -0
- package/dist/config/role-request-service.js +193 -0
- package/dist/config/schema-migration.js +686 -25
- package/dist/config-store.js +79 -3
- package/dist/contracts/ecweb-instance.js +41 -0
- package/dist/contracts/ecweb-service-protocol.js +3 -1
- package/dist/core/agent-application-service.js +11 -1
- package/dist/core/agent-ipc-registration.js +4 -0
- package/dist/core/agent-runtime.js +1 -1
- package/dist/core/auth/agent-delegation.js +82 -6
- package/dist/core/auth/auth-gateway.js +1 -1
- package/dist/core/auth/authorization-audit.js +37 -9
- package/dist/core/auth/delegation-authorization.js +3 -1
- package/dist/core/auth/operation-authorizer.js +15 -0
- package/dist/core/auth/operation-catalog.js +39 -6
- package/dist/core/command/agent-control.js +94 -19
- package/dist/core/command/agent-storage-menu.js +5 -3
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +105 -145
- package/dist/core/command/connect-menu.js +31 -2
- package/dist/core/command/data-root-resolver.js +5 -4
- package/dist/core/command/memory-slash.js +16 -8
- package/dist/core/command/menu-catalog.js +6 -6
- package/dist/core/command/menu-handler.js +87 -163
- package/dist/core/command/menu-protocol.js +9 -2
- package/dist/core/command/role-menu.js +148 -30
- package/dist/core/command/slash-gate.js +13 -10
- package/dist/core/command/slash-handler.js +157 -352
- package/dist/core/daemon-control.js +8 -14
- package/dist/core/event-catalog.js +15 -0
- package/dist/core/evolagent-registry.js +4 -4
- package/dist/core/evolagent.js +2 -2
- package/dist/core/inference/text-inference.js +31 -40
- package/dist/core/ipc-registration.js +24 -3
- package/dist/core/memory/consolidation-context.js +51 -5
- package/dist/core/memory/consolidation-ops-records.js +1 -1
- package/dist/core/memory/consolidation-trigger.js +190 -190
- package/dist/core/memory/consolidation.js +316 -29
- package/dist/core/memory/forget-log.js +96 -0
- package/dist/core/memory/index-manager.js +27 -5
- package/dist/core/memory/memory-admin.js +45 -5
- package/dist/core/memory/memory-writer.js +163 -18
- package/dist/core/memory/relation-idle-monitor.js +119 -58
- package/dist/core/memory/relation-sweep.js +44 -39
- package/dist/core/message/aun-ipc-sender.js +34 -7
- package/dist/core/message/aun-request-registry.js +97 -3
- package/dist/core/message/im-renderer.js +11 -4
- package/dist/core/message/message-admission.js +97 -8
- package/dist/core/message/message-bridge.js +71 -24
- package/dist/core/message/message-log.js +55 -0
- package/dist/core/message/message-queue.js +5 -5
- package/dist/core/message/response-engine.js +387 -144
- package/dist/core/model/catalog-service.js +4 -2
- package/dist/core/model/config-scope.js +24 -64
- package/dist/core/model/field-scope.js +1 -1
- package/dist/core/model/model-catalog.js +37 -47
- package/dist/core/model/model-diagnostics.js +4 -3
- package/dist/core/model/model-fallback.js +10 -7
- package/dist/core/model/model-permission.js +3 -2
- package/dist/core/ownership/owner-resolver.js +25 -23
- package/dist/core/permission/ec-command-parser.js +138 -5
- package/dist/core/permission/sandbox-runtime.js +18 -1
- package/dist/core/permission/tool-policy.js +42 -10
- package/dist/core/relation/peer-identity.js +64 -1
- package/dist/core/role/runtime-policy.js +72 -13
- package/dist/core/session/session-capsule.js +197 -0
- package/dist/core/session/session-idle-monitor.js +1 -1
- package/dist/core/session/session-manager.js +168 -14
- package/dist/core/session/session-mapper.js +2 -0
- package/dist/core/session/session-renew.js +3 -3
- package/dist/core/skill/index-generator.js +15 -5
- package/dist/core/system-session/memory.js +6 -1
- package/dist/core/thread/thread-service.js +19 -6
- package/dist/directory/owner-directory-admission.js +95 -0
- package/dist/directory/owner-directory-authorization.js +309 -0
- package/dist/directory/owner-directory-cache.js +635 -0
- package/dist/eck/kit-renderer.js +2 -2
- package/dist/ecweb/basic-settings-service.js +33 -40
- package/dist/ecweb/message-context-service.js +110 -0
- package/dist/index.js +79 -17
- package/dist/ipc.js +189 -17
- package/dist/paths.js +4 -0
- package/dist/proxy/command.js +122 -0
- package/dist/proxy/ipc-service.js +68 -0
- package/dist/proxy/manager.js +485 -0
- package/dist/proxy/service-supervisor.js +603 -0
- package/dist/response-system/engines/v1/proactive-flow.js +16 -6
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +15 -0
- package/dist/stats/index.js +2 -2
- package/dist/stats/price-resolver.js +304 -5
- package/dist/stats/query.js +82 -3
- package/dist/stats/writer.js +38 -5
- package/dist/trigger/feedback.js +18 -7
- package/dist/trigger/manager.js +20 -3
- package/dist/trigger/parser.js +6 -3
- package/dist/trigger/patch.js +1 -1
- package/dist/trigger/system-definitions.js +43 -7
- package/dist/trigger/validation.js +13 -5
- package/dist/utils/cross-platform.js +14 -0
- package/dist/utils/ecweb-supervisor.js +258 -83
- package/dist/utils/error-utils.js +16 -2
- package/dist/utils/logger.js +24 -5
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +5 -3
- package/dist/utils/upgrade-jobs.js +45 -5
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/aun/ABILITY_CALLING.md +20 -2
- package/kits/docs/channels/aun.md +9 -0
- package/kits/docs/evolcore/INDEX.md +2 -1
- package/kits/docs/evolcore/agent-create.md +3 -2
- package/kits/docs/evolcore/agent.md +1 -1
- package/kits/docs/evolcore/config.md +18 -7
- package/kits/docs/evolcore/contact.md +3 -0
- package/kits/docs/evolcore/event.md +1 -0
- package/kits/docs/evolcore/fs.md +16 -0
- package/kits/docs/evolcore/memory-architecture.md +2 -2
- package/kits/docs/evolcore/memory-consolidation.md +32 -8
- package/kits/docs/evolcore/memory.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +36 -0
- package/kits/docs/evolcore/model.md +23 -20
- package/kits/docs/evolcore/msg.md +21 -8
- package/kits/docs/evolcore/session.md +14 -0
- package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
- package/kits/schemas/_meta.json +37 -4
- package/kits/schemas/agent-config.schema.13.json +23 -3
- package/kits/schemas/agent-config.schema.16.json +891 -0
- package/kits/schemas/daemon.schema.9.json +366 -0
- package/kits/schemas/defaults.schema.5.json +406 -127
- package/kits/schemas/relation-config.schema.11.json +260 -0
- package/kits/schemas/role-config.schema.1.json +7 -7
- package/kits/skills/.switches.json +3 -7
- package/kits/skills/aid-ability/SKILL.md +35 -6
- package/kits/skills/ec-service-proxy/SKILL.md +118 -0
- package/kits/skills/ec-trigger/SKILL.md +13 -5
- package/kits/skills/personal-assistant/SKILL.md +176 -0
- package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
- package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
- package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
- package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
- package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
- package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
- package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
- package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
- package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
- package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
- package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
- package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
- package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
- package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
- package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
- package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
- package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
- package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
- package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
- package/kits/templates/memory-consolidation/forget.md +19 -6
- package/kits/templates/memory-consolidation/notes.md +1 -1
- package/kits/templates/memory-consolidation/profile.md +2 -2
- package/kits/templates/memory-consolidation/promote.md +20 -3
- package/kits/templates/roles/member.json +8 -1
- package/kits/templates/session-capsule/recovery.md +5 -0
- package/kits/templates/session-capsule/renew.md +5 -0
- package/kits/templates/system-fragments/baseagent.md +2 -2
- package/kits/templates/system-fragments/bootstrap.md +6 -6
- package/kits/templates/system-fragments/channel.md +1 -1
- package/kits/templates/system-fragments/memory.md +4 -4
- package/package.json +7 -3
- package/dist/stats/billing.js +0 -215
|
@@ -2,10 +2,9 @@ import crypto from 'crypto';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { isValidAid } from '../../aun/aid/validation.js';
|
|
5
|
-
import { isExplicitGroupId } from '../../aun/group/index.js';
|
|
6
5
|
import { isStaticAgentOwner } from '../../config/peer-role-resolver.js';
|
|
7
6
|
import { agentDir, agentRelationSharedDir } from '../../paths.js';
|
|
8
|
-
import { formatPeerKey } from '../relation/peer-identity.js';
|
|
7
|
+
import { formatPeerKey, readAunPeerKind } from '../relation/peer-identity.js';
|
|
9
8
|
export class DataRootError extends Error {
|
|
10
9
|
code;
|
|
11
10
|
data;
|
|
@@ -27,7 +26,8 @@ function isInside(root, candidate) {
|
|
|
27
26
|
}
|
|
28
27
|
function authenticatedPrincipal(subject) {
|
|
29
28
|
const principalId = String(subject.principalId ?? '').trim();
|
|
30
|
-
if (!isValidAid(principalId) ||
|
|
29
|
+
if (!isValidAid(principalId) || !subject.selfAid
|
|
30
|
+
|| readAunPeerKind(subject.selfAid, principalId, { routeKind: 'private' }).kind !== 'private') {
|
|
31
31
|
throw new DataRootError('ROOT_FORBIDDEN', 'A verified private AUN principal is required');
|
|
32
32
|
}
|
|
33
33
|
return principalId;
|
|
@@ -71,7 +71,8 @@ export class DataRootResolver {
|
|
|
71
71
|
throw new DataRootError('ROOT_FORBIDDEN', 'Only the Agent owner may select another relation');
|
|
72
72
|
}
|
|
73
73
|
const peerAid = explicitPeerAid || principalId;
|
|
74
|
-
|
|
74
|
+
const kind = readAunPeerKind(targetAid, peerAid, peerAid === principalId ? { routeKind: 'private' } : {});
|
|
75
|
+
if (!isValidAid(peerAid) || kind.kind !== 'private') {
|
|
75
76
|
throw new DataRootError('INVALID_ARGUMENT', 'args.peerAid must identify an AUN private-chat peer');
|
|
76
77
|
}
|
|
77
78
|
const peerKey = formatPeerKey('aun', peerAid);
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { CONSOLIDATION_MODES, MODE_SCOPE } from '../memory/consolidation-context.js';
|
|
11
11
|
import { formatQueueDetails } from '../memory/consolidation-queue-format.js';
|
|
12
|
+
import { FORGET_REASON_MAX_CHARS, normalizeForgetReason } from '../memory/forget-log.js';
|
|
12
13
|
import { MEMORY_SCOPES, isMemoryScope, memoryOverview, listMemoryFiles, formatMemoryFiles, readMemoryIndex, showMemoryFile, formatPendingNotes, showPendingNote, reindexScope, dropNote, archiveMemoryFile, restoreMemoryFile, } from '../memory/memory-admin.js';
|
|
13
14
|
const USAGE = [
|
|
14
15
|
'用法:',
|
|
@@ -19,8 +20,8 @@ const USAGE = [
|
|
|
19
20
|
' /memory index <scope> 查看 MEMORY.md 索引',
|
|
20
21
|
' /memory list <scope> [archived] 正式 / 已归档记忆列表',
|
|
21
22
|
' /memory show <scope> <slug> [archived] 查看单条记忆',
|
|
22
|
-
' /memory archive <scope> <slug> 归档记忆(可用 restore
|
|
23
|
-
' /memory restore <scope> <slug> 恢复已归档记忆',
|
|
23
|
+
' /memory archive <scope> <slug> [理由] 归档记忆(可用 restore 恢复),理由记入遗忘日志',
|
|
24
|
+
' /memory restore <scope> <slug> [理由] 恢复已归档记忆',
|
|
24
25
|
' /memory reindex <scope> 重建索引',
|
|
25
26
|
' /memory consolidate [mode] [scope] 拉起整理(mode: notes|generalize|promote|profile|forget;forget 需指定 scope)',
|
|
26
27
|
'scope: relation | agent | owner',
|
|
@@ -89,8 +90,8 @@ export function memoryHelpEntries(ctx) {
|
|
|
89
90
|
if (view.includes('relation'))
|
|
90
91
|
add('/memory note', '查看单条 note', '<slug>');
|
|
91
92
|
if (write.length > 0) {
|
|
92
|
-
add('/memory archive', '归档一条记忆', '<scope> <slug>');
|
|
93
|
-
add('/memory restore', '恢复已归档记忆', '<scope> <slug>');
|
|
93
|
+
add('/memory archive', '归档一条记忆', '<scope> <slug> [理由]');
|
|
94
|
+
add('/memory restore', '恢复已归档记忆', '<scope> <slug> [理由]');
|
|
94
95
|
if (write.includes('relation'))
|
|
95
96
|
add('/memory note drop', '撤销一条 note', '<slug>');
|
|
96
97
|
}
|
|
@@ -187,13 +188,20 @@ export async function handleMemorySlash(ctx) {
|
|
|
187
188
|
if (isPayload(scope))
|
|
188
189
|
return scope;
|
|
189
190
|
if (!args[2])
|
|
190
|
-
return error(`用法: /memory ${sub} <scope> <slug
|
|
191
|
+
return error(`用法: /memory ${sub} <scope> <slug> [理由]`);
|
|
192
|
+
// 理由可空(记「未注明理由」),给了就按遗忘理由的上限校验
|
|
193
|
+
const reason = normalizeForgetReason(args.slice(3).join(' '));
|
|
194
|
+
if ([...reason].length > FORGET_REASON_MAX_CHARS) {
|
|
195
|
+
return error(`理由不能超过 ${FORGET_REASON_MAX_CHARS} 字(当前 ${[...reason].length} 字)`);
|
|
196
|
+
}
|
|
197
|
+
const log = { reason, actorAid: ctx.actorAid };
|
|
191
198
|
if (sub === 'archive') {
|
|
192
|
-
await archiveMemoryFile(target, scope, args[2]);
|
|
199
|
+
await archiveMemoryFile(target, scope, args[2], log);
|
|
193
200
|
return result(`✅ 已归档 ${scope}/${args[2]},索引已重建\n恢复: /memory restore ${scope} ${args[2]}`);
|
|
194
201
|
}
|
|
195
|
-
await restoreMemoryFile(target, scope, args[2]);
|
|
196
|
-
|
|
202
|
+
const restored = await restoreMemoryFile(target, scope, args[2], log);
|
|
203
|
+
const from = restored.stamped ? `(取的是最新归档 ${restored.restoredFrom})` : '';
|
|
204
|
+
return result(`✅ 已恢复 ${scope}/${args[2]}${from},索引已重建`);
|
|
197
205
|
}
|
|
198
206
|
if (sub === 'reindex') {
|
|
199
207
|
const scope = needScope(args[1], true);
|
|
@@ -85,7 +85,7 @@ const ENTRIES = [
|
|
|
85
85
|
type: 'setting',
|
|
86
86
|
contexts: ['private_relation'],
|
|
87
87
|
name: 'session',
|
|
88
|
-
label: '
|
|
88
|
+
label: '当前会话 fullaccess',
|
|
89
89
|
section: 'relation_behavior',
|
|
90
90
|
order: 6,
|
|
91
91
|
query: { cmd: '/session', args: { view: 'fullaccess' }, operation: 'session.fullaccess.current', scope: 'relation' },
|
|
@@ -93,8 +93,7 @@ const ENTRIES = [
|
|
|
93
93
|
valueSchema: { type: 'boolean' },
|
|
94
94
|
control: 'toggle',
|
|
95
95
|
},
|
|
96
|
-
|
|
97
|
-
relation('effort.relation', 'effort', '推理强度', 20, '/effort', 'model.effort.current', { options: { cmd: '/effort', operation: 'model.effort.current', scope: 'relation', mode: 'dynamic', dependsOn: ['model.relation'] }, update: { cmd: '/effort', operation: 'model.effort', scope: 'relation' }, control: 'select' }),
|
|
96
|
+
// 模型与推理强度只在 Agent 级配置(见 model.agent / effort.agent),关系菜单不再提供。
|
|
98
97
|
relation('chatmode.relation', 'chatmode', '对话模式', 30, '/chatmode', 'chatmode.current', { options: { cmd: '/chatmode', operation: 'chatmode.current', scope: 'relation', mode: 'static', items: [{ value: 'interactive', label: '交互模式' }, { value: 'proactive', label: '主动模式' }] }, update: { cmd: '/chatmode', operation: 'chatmode.update', scope: 'relation' }, control: 'select' }),
|
|
99
98
|
relation('activity.relation', 'activity', '中间输出', 40, '/activity', 'activity.current', { options: { cmd: '/activity', operation: 'activity.current', scope: 'relation', mode: 'static', items: [{ value: 'all', label: '私聊显示' }, { value: 'text', label: '仅文字进展' }, { value: 'none', label: '全部静默' }] }, update: { cmd: '/activity', operation: 'activity.update', scope: 'relation' }, control: 'select' }),
|
|
100
99
|
{ id: 'task.activities', type: 'list', contexts: ['private_relation', 'group_relation'], name: 'task', label: '任务活动', section: 'relation_behavior', order: 45, query: { cmd: '/task', args: { view: 'activities' }, operation: 'task.activity.read', scope: 'relation', mode: 'dynamic' }, control: 'list' },
|
|
@@ -121,6 +120,7 @@ const ENTRIES = [
|
|
|
121
120
|
{ id: 'system.paircode', type: 'action', contexts: ['process'], name: 'system', label: '获取配对码', section: 'process', order: 35, action: { cmd: '/system', action: 'paircode', operation: 'system.paircode', scope: 'process' } },
|
|
122
121
|
{ id: 'agent.list', type: 'list', contexts: ['process'], name: 'agent', label: 'Agent 列表', section: 'process', order: 40, options: { cmd: '/agent', args: { options: 'all' }, operation: 'agent.list', scope: 'control', mode: 'dynamic' }, control: 'list' },
|
|
123
122
|
{ id: 'agent.create', type: 'action', contexts: ['process'], name: 'agent', label: '创建 Agent', section: 'process', order: 50, action: { cmd: '/agent', action: 'create', operation: 'agent.create', scope: 'control' } },
|
|
123
|
+
{ id: 'agent.initialize', type: 'action', contexts: ['process'], name: 'agent', label: '初始化 Agent', section: 'process', order: 55, action: { cmd: '/agent', action: 'initialize', operation: 'agent.initialize', scope: 'control' } },
|
|
124
124
|
{ id: 'agent.reload', type: 'action', contexts: ['process'], name: 'agent', label: '重载 Agent', section: 'process', order: 60, action: { cmd: '/agent', action: 'reload', operation: 'agent.reload', scope: 'control' } },
|
|
125
125
|
{ id: 'agent.delete', type: 'action', contexts: ['process'], name: 'agent', label: '删除 Agent', section: 'process', order: 70, action: { cmd: '/agent', action: 'delete', operation: 'agent.delete', scope: 'control' } },
|
|
126
126
|
];
|
|
@@ -433,7 +433,7 @@ export async function getMenuCatalog(input) {
|
|
|
433
433
|
entries.push({ id: entry.id, type: entry.type, name: entry.name, label: entry.label, section: entry.section, order: entry.order, target: { scope: context.kind === 'agent' ? 'agent' : context.kind === 'process' ? 'process' : 'relation', ...(context.self ? { self: context.self } : {}), ...(context.peerKey ? { peerKey: context.peerKey } : {}) }, valueSchema: entry.valueSchema ?? { type: 'object' }, operations, wire: { name: entry.name, operations: { ...(wireBinding(entry.query, context) ? { query: wireBinding(entry.query, context) } : {}), ...(wireBinding(entry.options, context) ? { options: wireBinding(entry.options, context) } : {}), ...(wireBinding(entry.update, context) ? { update: wireBinding(entry.update, context) } : {}), ...(wireBinding(entry.action, context) ? { action: wireBinding(entry.action, context) } : {}) } }, ui: { control: entry.control ?? 'action' } });
|
|
434
434
|
if (entry.id === 'session.loop' || entry.id === 'session.fullaccess') {
|
|
435
435
|
const loopEntry = entries[entries.length - 1];
|
|
436
|
-
let target = { level: 'relation-main', scope: '
|
|
436
|
+
let target = { level: 'relation-main', scope: 'relation' };
|
|
437
437
|
if ((entry.id === 'session.loop' || entry.id === 'session.fullaccess') && input.resolveLoopTarget) {
|
|
438
438
|
try {
|
|
439
439
|
target = await input.resolveLoopTarget(context);
|
|
@@ -457,9 +457,9 @@ export async function getMenuCatalog(input) {
|
|
|
457
457
|
loopEntry.target = {
|
|
458
458
|
level: target.level,
|
|
459
459
|
sessionId: target.sessionId,
|
|
460
|
-
scope: target.level === 'topic-session' ? 'session' : '
|
|
460
|
+
scope: target.level === 'topic-session' ? 'session' : 'relation',
|
|
461
461
|
};
|
|
462
|
-
loopEntry.label = '
|
|
462
|
+
loopEntry.label = '当前会话 fullaccess';
|
|
463
463
|
loopEntry.ui = { control: entry.control };
|
|
464
464
|
}
|
|
465
465
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { memoryHelpEntries } from './memory-slash.js';
|
|
2
2
|
import { getBaseagentSnapshot, loadedBaseagentIds } from '../../agents/baseagent-availability.js';
|
|
3
|
-
import { normalizePeer,
|
|
3
|
+
import { normalizePeer, writeAgentModelConfig } from '../model/config-scope.js';
|
|
4
4
|
import { formatPeerKey } from '../relation/peer-identity.js';
|
|
5
5
|
import { modelMatches, getCatalog, getBaseagentCatalog, resolveCatalogModel, assertCatalogSelectable, CONFIGURABLE_EFFORTS, configurableEfforts } from '../model/model-catalog.js';
|
|
6
6
|
import { constrainResolvedModelForRole, filterModelsForRole, validateModelSelectionForRole } from '../model/model-permission.js';
|
|
@@ -26,7 +26,9 @@ import { loadDefaults, loadDaemonConfig } from '../../config-store.js';
|
|
|
26
26
|
import { WEB_PACKAGE_NAME, RESTART_REQUEST_ID_ENV, RUNTIME_HOME_ENV, SESSION_ID_ENV } from '../../product.js';
|
|
27
27
|
import { read as cfgRead, resolveEffective, resolveEffectiveFieldWithSource, routeFieldPath, write as cfgWrite, ConfigTarget, } from '../../config/config-manager.js';
|
|
28
28
|
import { execAgentAction, execAgentQuery, execAgentOptions, execAidAvatar, resolveProjectPath } from './agent-control.js';
|
|
29
|
-
import {
|
|
29
|
+
import { readInitialization } from '../../cli/agent-create.js';
|
|
30
|
+
import { isValidAid } from '../../aun/aid/validation.js';
|
|
31
|
+
import { gatewayList, gatewayUpdate, gatewayDelete, gatewayTest, gatewayModels, gatewaySetPrice } from '../../config/gateway-config.js';
|
|
30
32
|
import { displaySessionTitle } from '../session/session-title.js';
|
|
31
33
|
import { buildTranscriptTurns } from '../session/session-transcript.js';
|
|
32
34
|
import { buildForkHistorySnapshot, pageForkHistory } from '../session/session-manager.js';
|
|
@@ -42,7 +44,7 @@ import { isUnsupportedBaseagentConfigField } from '../../config/config-field-pol
|
|
|
42
44
|
import { splitConfigBatchGetArgv } from '../../cli/cli-argv.js';
|
|
43
45
|
import { chatmodeFieldForPeer, isPrivateChatmodeRoleLocked, resolveChatModeForField } from '../message/peer-mode.js';
|
|
44
46
|
import { PUBLIC_PERMISSION_MODES } from '../permission/mode.js';
|
|
45
|
-
import { isAgentFullAccessOwner, resolveRuntimePermissionMode, resolveRuntimeStringField, sessionFullAccessStatus, validateRuntimeStringFieldOverride, } from '../role/runtime-policy.js';
|
|
47
|
+
import { isAgentFullAccessOwner, resolveRuntimePermissionMode, resolveRuntimeStringField, sessionFullAccessStatus, updateRelationSessionFullAccess, validateRuntimeStringFieldOverride, } from '../role/runtime-policy.js';
|
|
46
48
|
import { isManagementRole } from '../../config/builtin-roles.js';
|
|
47
49
|
import { SYSTEM_CONTROL_CHANNEL } from '../system-channels.js';
|
|
48
50
|
import { logger } from '../../utils/logger.js';
|
|
@@ -733,11 +735,15 @@ function readMenuPermission(target) {
|
|
|
733
735
|
source: decision.decidedBy === 'role' ? 'role' : 'builtin',
|
|
734
736
|
};
|
|
735
737
|
}
|
|
738
|
+
/**
|
|
739
|
+
* 模型参数只在 Agent 级。旧客户端可能仍带 scope=relation 查询:读取结果与 Agent 级相同,
|
|
740
|
+
* 一律解析到 Agent 级;写入的鉴权固定为 agent scope(见 intent 映射)。
|
|
741
|
+
*/
|
|
736
742
|
function menuModelScope(args) {
|
|
737
|
-
const raw = menuStringArg(args, 'scope') ?? '
|
|
743
|
+
const raw = menuStringArg(args, 'scope') ?? 'agent';
|
|
738
744
|
if (raw === 'agent' || raw === 'relation')
|
|
739
|
-
return
|
|
740
|
-
return { error: `无效 scope: ${raw}
|
|
745
|
+
return 'agent';
|
|
746
|
+
return { error: `无效 scope: ${raw},模型参数只在 agent 级配置`, code: 'INVALID_SCOPE' };
|
|
741
747
|
}
|
|
742
748
|
function resolveMenuModelTarget(params) {
|
|
743
749
|
const scope = menuModelScope(params.args);
|
|
@@ -766,32 +772,10 @@ function resolveMenuModelTarget(params) {
|
|
|
766
772
|
?? this.parseDefaultBaseagent?.();
|
|
767
773
|
if (!baseagent)
|
|
768
774
|
return { error: '缺少 baseagent 参数', code: 'MISSING_BASEAGENT' };
|
|
769
|
-
|
|
770
|
-
if (scope === 'agent') {
|
|
771
|
-
return { scope, sel, role: params.role, baseagent, field: params.field, fieldPath: `baseagents.${baseagent}.${params.field}` };
|
|
772
|
-
}
|
|
773
|
-
const explicitPeer = menuStringArg(params.args, 'peer') ?? menuStringArg(params.args, 'peerKey');
|
|
774
|
-
let peerKey;
|
|
775
|
-
if (explicitPeer) {
|
|
776
|
-
const normalized = normalizeMenuPeer(explicitPeer);
|
|
777
|
-
if (typeof normalized !== 'string')
|
|
778
|
-
return normalized;
|
|
779
|
-
peerKey = normalized;
|
|
780
|
-
}
|
|
781
|
-
else {
|
|
782
|
-
const chatType = params.session?.chatType ?? params.explicitChatType ?? 'private';
|
|
783
|
-
const channelType = this.resolveChannelType?.(params.channel) ?? params.session?.channelType;
|
|
784
|
-
const peerKeyId = chatType === 'group'
|
|
785
|
-
? (params.session?.metadata?.groupId || params.channelId)
|
|
786
|
-
: (params.userId || params.session?.metadata?.peerId || params.channelId);
|
|
787
|
-
if (channelType && peerKeyId)
|
|
788
|
-
peerKey = formatPeerKey(channelType, peerKeyId);
|
|
789
|
-
}
|
|
790
|
-
if (!peerKey)
|
|
791
|
-
return { error: 'relation scope 需要 peer/peerKey,或可推导的当前对端', code: 'MISSING_PEER' };
|
|
792
|
-
return { scope, sel: { ...sel, peerKey }, role: params.role, baseagent, field: params.field, fieldPath: `baseagents.${baseagent}.${params.field}` };
|
|
775
|
+
return { scope, sel: { self }, role: params.role, baseagent, field: params.field, fieldPath: `baseagents.${baseagent}.${params.field}` };
|
|
793
776
|
}
|
|
794
|
-
|
|
777
|
+
/** 只读 Agent 级配置(含角色约束);未配置返回 null,不回落 runner 自带默认值。 */
|
|
778
|
+
function readMenuModel(target, _agent, _agentSessionId) {
|
|
795
779
|
try {
|
|
796
780
|
const fieldPath = menuModelConfigFieldPath(target);
|
|
797
781
|
const resolved = resolveEffectiveFieldWithSource(fieldPath, target.sel, { cache: true });
|
|
@@ -801,7 +785,7 @@ function readMenuModel(target, agent, agentSessionId) {
|
|
|
801
785
|
role: target.role,
|
|
802
786
|
baseagent: target.baseagent,
|
|
803
787
|
model: resolved.value,
|
|
804
|
-
resolveModelId: typeof
|
|
788
|
+
resolveModelId: typeof _agent?.resolveModelId === 'function' ? _agent.resolveModelId.bind(_agent) : undefined,
|
|
805
789
|
});
|
|
806
790
|
if (decision.model) {
|
|
807
791
|
return { value: decision.model, source: decision.constrained ? 'role' : toMenuSource(resolved.source) };
|
|
@@ -823,13 +807,7 @@ function readMenuModel(target, agent, agentSessionId) {
|
|
|
823
807
|
}
|
|
824
808
|
}
|
|
825
809
|
catch { }
|
|
826
|
-
|
|
827
|
-
? (typeof agent?.getModel === 'function' ? agent.getModel() : agent?.name)
|
|
828
|
-
: (typeof agent?.getEffort === 'function' ? agent.getEffort() : undefined);
|
|
829
|
-
return {
|
|
830
|
-
value: fallback ?? null,
|
|
831
|
-
source: fallback == null ? null : 'runner',
|
|
832
|
-
};
|
|
810
|
+
return { value: null, source: null };
|
|
833
811
|
}
|
|
834
812
|
function menuActivityScope(args) {
|
|
835
813
|
const raw = menuStringArg(args, 'scope') ?? 'relation';
|
|
@@ -893,10 +871,10 @@ function writeMenuActivity(target, value) {
|
|
|
893
871
|
}
|
|
894
872
|
function writeMenuModel(target, value) {
|
|
895
873
|
if (target.field === 'model') {
|
|
896
|
-
|
|
874
|
+
writeAgentModelConfig(target.sel.self, target.baseagent, { model: value });
|
|
897
875
|
}
|
|
898
876
|
else {
|
|
899
|
-
|
|
877
|
+
writeAgentModelConfig(target.sel.self, target.baseagent, { effort: value });
|
|
900
878
|
}
|
|
901
879
|
}
|
|
902
880
|
export function isProcessLevelOwner(peerId, owners) {
|
|
@@ -965,7 +943,9 @@ function buildMenuIntent(verb, cmdBase, args, action, value, fromControlChannel
|
|
|
965
943
|
source: 'menu',
|
|
966
944
|
args: { ...payload, ...(extra ?? {}) },
|
|
967
945
|
});
|
|
968
|
-
|
|
946
|
+
// 读取与写入都固定为 agent scope;客户端可能仍带 scope=relation,忽略它。
|
|
947
|
+
const modelScope = 'agent';
|
|
948
|
+
void args?.scope;
|
|
969
949
|
if (verb === 'query') {
|
|
970
950
|
if (cmdBase === '/baseagent-models')
|
|
971
951
|
return intent('baseagent.models.list', 'process');
|
|
@@ -1046,10 +1026,11 @@ function buildMenuIntent(verb, cmdBase, args, action, value, fromControlChannel
|
|
|
1046
1026
|
if (verb === 'update') {
|
|
1047
1027
|
if (cmdBase === '/baseagent')
|
|
1048
1028
|
return intent('agent.baseagent.update', 'agent', { baseagent: value });
|
|
1029
|
+
// 模型参数只在 Agent 级:写入一律按 agent scope 鉴权(仅 owner/admin)。
|
|
1049
1030
|
if (cmdBase === '/model')
|
|
1050
|
-
return intent('model.use',
|
|
1031
|
+
return intent('model.use', 'agent', { model: value });
|
|
1051
1032
|
if (cmdBase === '/effort')
|
|
1052
|
-
return intent('model.effort',
|
|
1033
|
+
return intent('model.effort', 'agent', { effort: value });
|
|
1053
1034
|
if (cmdBase === '/chatmode')
|
|
1054
1035
|
return intent('chatmode.update', args?.scope === 'agent' ? 'agent' : 'relation', { value });
|
|
1055
1036
|
if (cmdBase === '/mention')
|
|
@@ -1481,7 +1462,7 @@ export function getMenuItems(role, chatType = 'private', scope = 'agent', authSu
|
|
|
1481
1462
|
if (authSubject) {
|
|
1482
1463
|
const relationArgs = operationScope === 'relation'
|
|
1483
1464
|
? buildRelationIntentArgs({ selfAid: authSubject.selfAid, peerKey: authSubject.peerKey })
|
|
1484
|
-
: {};
|
|
1465
|
+
: operationScope === 'agent' && authSubject.selfAid ? { self: authSubject.selfAid } : {};
|
|
1485
1466
|
return authorizeOperation({
|
|
1486
1467
|
source: 'menu',
|
|
1487
1468
|
intent: { operation, scope: operationScope, source: 'menu', args: relationArgs },
|
|
@@ -1498,8 +1479,9 @@ export function getMenuItems(role, chatType = 'private', scope = 'agent', authSu
|
|
|
1498
1479
|
}).allow;
|
|
1499
1480
|
};
|
|
1500
1481
|
const canReadModel = canOperation('model.list', 'relation') || canOperation('model.current', 'relation');
|
|
1501
|
-
|
|
1502
|
-
const
|
|
1482
|
+
// 模型参数只在 Agent 级:切换与调强度都是 Agent 级写操作,仅 owner/admin。
|
|
1483
|
+
const canUseModel = canOperation('model.use', 'agent');
|
|
1484
|
+
const canSetEffort = canOperation('model.effort', 'agent');
|
|
1503
1485
|
const canSetChatmode = canOperation('chatmode.update', 'relation');
|
|
1504
1486
|
const canSetMentionmode = normalizedChatType === 'group' && canOperation('mentionmode.update', 'relation');
|
|
1505
1487
|
const canReadPermission = canOperation('permission.current', 'relation');
|
|
@@ -1968,7 +1950,7 @@ export async function getSubMenuItems(cmd, channel, channelId, userId, args, ove
|
|
|
1968
1950
|
const rawModels = catalog.models.map(m => m.id);
|
|
1969
1951
|
const models = filterModelsForRole(optionsIdentity.role, target.baseagent, rawModels, model => resolveCatalogModel(catalog, model), target.sel.self);
|
|
1970
1952
|
const requestedModel = menuStringArg(args, 'model') ?? menuStringArg(args, 'current');
|
|
1971
|
-
const currentModel = requestedModel || readMenuModel(target, agent, session?.agentSessionId).value ||
|
|
1953
|
+
const currentModel = requestedModel || readMenuModel(target, agent, session?.agentSessionId).value || '';
|
|
1972
1954
|
if (models.length > 0)
|
|
1973
1955
|
return models.map((m) => ({ value: m, label: modelDisplayLabel(agent, m) + (catalog.models.find(e => e.id === m)?.verification === 'unverified' ? ' [unverified]' : ''), selected: modelMatches(agent, m, currentModel) }));
|
|
1974
1956
|
}
|
|
@@ -2035,7 +2017,10 @@ export async function getSubMenuItems(cmd, channel, channelId, userId, args, ove
|
|
|
2035
2017
|
}
|
|
2036
2018
|
const requestedModel = menuStringArg(args, 'model') ?? menuStringArg(args, 'currentModel');
|
|
2037
2019
|
const modelTarget = { ...target, field: 'model', fieldPath: `baseagents.${target.baseagent}.model` };
|
|
2038
|
-
const currentModel = requestedModel ||
|
|
2020
|
+
const currentModel = requestedModel || readMenuModel(modelTarget, agent, session?.agentSessionId).value;
|
|
2021
|
+
// Agent 级没有模型时没有可选的推理强度。
|
|
2022
|
+
if (!currentModel)
|
|
2023
|
+
return [];
|
|
2039
2024
|
const efforts = await getAvailableEfforts(agent, currentModel);
|
|
2040
2025
|
const currentEffort = menuStringArg(args, 'effort') ?? menuStringArg(args, 'current') ?? readMenuModel(target, agent, session?.agentSessionId).value ?? 'auto';
|
|
2041
2026
|
const allItems = [...efforts, 'auto'];
|
|
@@ -2162,7 +2147,7 @@ export async function execMenuQuery(cmd, channel, channelId, userId, args, expli
|
|
|
2162
2147
|
return { error: '/fa 需要同一身份同时具备 Agent Owner 和 daemon Owner 权限', code: 'FORBIDDEN' };
|
|
2163
2148
|
}
|
|
2164
2149
|
const status = sessionFullAccessStatus(session, principalId);
|
|
2165
|
-
return { data: { ...status, sessionId: session.id
|
|
2150
|
+
return { data: { ...status, sessionId: session.id } };
|
|
2166
2151
|
}
|
|
2167
2152
|
const storageRequest = { type: 'menu.query', cmd, args };
|
|
2168
2153
|
if (isAgentStorageMenuRequest(storageRequest)) {
|
|
@@ -3061,15 +3046,18 @@ export async function execMenuUpdate(cmd, value, channel, channelId, userId, ove
|
|
|
3061
3046
|
return { error: '/fa 需要私聊中同一身份同时具备 Agent Owner 和 daemon Owner 权限', code: 'FORBIDDEN' };
|
|
3062
3047
|
}
|
|
3063
3048
|
try {
|
|
3049
|
+
const status = sessionFullAccessStatus(session, principalId);
|
|
3050
|
+
if (status.globalEnabled) {
|
|
3051
|
+
return { data: { ...status, sessionId: session.id, ignored: true,
|
|
3052
|
+
message: 'Agent 全局 fullaccess 已开启,局部设置未修改。' } };
|
|
3053
|
+
}
|
|
3064
3054
|
if (isTopicSession(session)) {
|
|
3065
|
-
this.sessionManager.updateSessionFullAccess(session.id, {
|
|
3055
|
+
session = this.sessionManager.updateSessionFullAccess(session.id, {
|
|
3056
|
+
enabled: value, authorizedBy: principalId,
|
|
3057
|
+
});
|
|
3066
3058
|
}
|
|
3067
3059
|
else {
|
|
3068
|
-
|
|
3069
|
-
if (!config)
|
|
3070
|
-
return { error: '找不到当前 Agent 配置', code: 'NOT_FOUND' };
|
|
3071
|
-
config.fullaccess = { enabled: value };
|
|
3072
|
-
cfgWrite(ConfigTarget.Agent, config, { self: subject.selfAid });
|
|
3060
|
+
updateRelationSessionFullAccess(session, { enabled: value, authorizedBy: principalId });
|
|
3073
3061
|
}
|
|
3074
3062
|
auditFullAccessEvent({
|
|
3075
3063
|
event: value ? 'fullaccess.session-policy.configured' : 'fullaccess.session-policy.deescalated',
|
|
@@ -3079,9 +3067,9 @@ export async function execMenuUpdate(cmd, value, channel, channelId, userId, ove
|
|
|
3079
3067
|
agentAid: subject.selfAid,
|
|
3080
3068
|
sessionId: session.id,
|
|
3081
3069
|
authorizedBy: principalId,
|
|
3082
|
-
reason: isTopicSession(session) ? 'topic session fullaccess updated via Menu' : '
|
|
3070
|
+
reason: isTopicSession(session) ? 'topic session fullaccess updated via Menu' : 'relation main-session fullaccess updated via Menu',
|
|
3083
3071
|
});
|
|
3084
|
-
return { data: {
|
|
3072
|
+
return { data: { ...sessionFullAccessStatus(session, principalId), sessionId: session.id } };
|
|
3085
3073
|
}
|
|
3086
3074
|
catch (error) {
|
|
3087
3075
|
return menuResultFailure(error);
|
|
@@ -3229,113 +3217,20 @@ export async function execMenuUpdate(cmd, value, channel, channelId, userId, ove
|
|
|
3229
3217
|
return { error: `无效 baseagent: ${arg},可选: ${valid.join(' / ')}`, code: 'INVALID_VALUE' };
|
|
3230
3218
|
}
|
|
3231
3219
|
const previousBaseagent = evolagent.baseagent;
|
|
3232
|
-
const sessionTopicId = sessionTopicThreadId(session);
|
|
3233
|
-
if (session && sessionTopicId) {
|
|
3234
|
-
if (transportReplyContext?.threadId !== sessionTopicId) {
|
|
3235
|
-
return { error: '话题路由上下文不匹配,拒绝切换', code: 'THREAD_CONTEXT_MISMATCH' };
|
|
3236
|
-
}
|
|
3237
|
-
if (typeof this.messageQueue.withSessionBarrier !== 'function') {
|
|
3238
|
-
return { error: '当前运行环境不支持安全话题切换', code: 'NOT_SUPPORTED' };
|
|
3239
|
-
}
|
|
3240
|
-
const sessionKey = this.getQueueKey(session, channel, channelId);
|
|
3241
|
-
const currentAgent = this.getAgent(channel, session.baseagent);
|
|
3242
|
-
const outcome = await this.messageQueue.withSessionBarrier(sessionKey, async (snapshot) => {
|
|
3243
|
-
const latest = await this.sessionManager.getSessionById?.(session.id);
|
|
3244
|
-
if (!latest || sessionTopicThreadId(latest) !== sessionTopicId) {
|
|
3245
|
-
return { error: '话题会话不存在或归属已变化', code: 'NOT_FOUND' };
|
|
3246
|
-
}
|
|
3247
|
-
const busy = !!latest.processingState
|
|
3248
|
-
|| !!latest.metadata?.turnState?.active
|
|
3249
|
-
|| snapshot.active
|
|
3250
|
-
|| snapshot.queued > 0
|
|
3251
|
-
|| snapshot.dispatching
|
|
3252
|
-
|| this.messageQueue.isProcessing?.(sessionKey)
|
|
3253
|
-
|| (this.messageQueue.getQueueLength?.(sessionKey) ?? 0) > 0
|
|
3254
|
-
|| currentAgent.hasActiveStream(sessionKey);
|
|
3255
|
-
if (busy) {
|
|
3256
|
-
return { error: '当前话题会话忙碌,无法切换 baseagent', code: 'BUSY' };
|
|
3257
|
-
}
|
|
3258
|
-
try {
|
|
3259
|
-
evolagent.setActiveBaseagent(arg);
|
|
3260
|
-
await this.sessionManager.rotateTopicBackend({
|
|
3261
|
-
sessionId: latest.id,
|
|
3262
|
-
expectedThreadId: sessionTopicId,
|
|
3263
|
-
baseagent: arg,
|
|
3264
|
-
});
|
|
3265
|
-
return { ok: true };
|
|
3266
|
-
}
|
|
3267
|
-
catch (error) {
|
|
3268
|
-
try {
|
|
3269
|
-
evolagent.setActiveBaseagent(previousBaseagent);
|
|
3270
|
-
}
|
|
3271
|
-
catch { }
|
|
3272
|
-
return { error: error instanceof Error ? error.message : String(error), code: 'EXEC_FAILED' };
|
|
3273
|
-
}
|
|
3274
|
-
});
|
|
3275
|
-
if ('error' in outcome)
|
|
3276
|
-
return outcome;
|
|
3277
|
-
this.eventBus.publish({
|
|
3278
|
-
type: 'agent:baseagent-changed',
|
|
3279
|
-
aid: evolagent.aid,
|
|
3280
|
-
baseagent: arg,
|
|
3281
|
-
previousBaseagent,
|
|
3282
|
-
scope: 'agent',
|
|
3283
|
-
timestamp: Date.now(),
|
|
3284
|
-
});
|
|
3285
|
-
return { data: {
|
|
3286
|
-
baseagent: arg,
|
|
3287
|
-
previousBaseagent,
|
|
3288
|
-
baseagentChanged: previousBaseagent !== arg,
|
|
3289
|
-
scope: 'agent',
|
|
3290
|
-
sessionId: session.id,
|
|
3291
|
-
threadId: sessionTopicId,
|
|
3292
|
-
sessionIdChanged: false,
|
|
3293
|
-
notice: '已切换 Baseagent: ' + previousBaseagent + ' → ' + arg + ',话题会话 ID 保持不变',
|
|
3294
|
-
} };
|
|
3295
|
-
}
|
|
3296
3220
|
try {
|
|
3297
3221
|
evolagent.setActiveBaseagent(arg);
|
|
3298
3222
|
}
|
|
3299
3223
|
catch (error) {
|
|
3300
3224
|
return { error: error instanceof Error ? error.message : String(error), code: 'INVALID_VALUE' };
|
|
3301
3225
|
}
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
catch (error) {
|
|
3311
|
-
// The new Evolcore session is already active; backend cleanup is best effort.
|
|
3312
|
-
logger.warn(`[Menu] baseagent switch cleanup failed: session=${session.id}: ${error instanceof Error ? error.message : String(error)}`);
|
|
3313
|
-
}
|
|
3314
|
-
}
|
|
3315
|
-
this.eventBus.publish({
|
|
3316
|
-
type: 'agent:baseagent-changed',
|
|
3317
|
-
aid: evolagent.aid,
|
|
3318
|
-
baseagent: arg,
|
|
3319
|
-
previousBaseagent,
|
|
3320
|
-
scope: 'agent',
|
|
3321
|
-
timestamp: Date.now(),
|
|
3322
|
-
});
|
|
3323
|
-
return { data: {
|
|
3324
|
-
baseagent: arg,
|
|
3325
|
-
previousBaseagent,
|
|
3326
|
-
baseagentChanged: previousBaseagent !== arg,
|
|
3327
|
-
scope: 'agent',
|
|
3328
|
-
sessionId: newSession.id,
|
|
3329
|
-
notice: `已切换 Baseagent: ${previousBaseagent} → ${arg},已创建新的主会话`,
|
|
3330
|
-
} };
|
|
3331
|
-
}
|
|
3332
|
-
catch (error) {
|
|
3333
|
-
try {
|
|
3334
|
-
evolagent.setActiveBaseagent(previousBaseagent);
|
|
3335
|
-
}
|
|
3336
|
-
catch { }
|
|
3337
|
-
return { error: `创建新会话失败:${error instanceof Error ? error.message : String(error)}`, code: 'EXEC_FAILED' };
|
|
3338
|
-
}
|
|
3226
|
+
this.eventBus.publish({ type: 'agent:baseagent-changed', aid: evolagent.aid,
|
|
3227
|
+
baseagent: arg, previousBaseagent, scope: 'agent', timestamp: Date.now() });
|
|
3228
|
+
return { data: {
|
|
3229
|
+
baseagent: arg, previousBaseagent, baseagentChanged: previousBaseagent !== arg, scope: 'agent',
|
|
3230
|
+
sessionId: session?.id, sessionIdChanged: false,
|
|
3231
|
+
notice: `新会话默认 Baseagent: ${previousBaseagent} → ${arg}`
|
|
3232
|
+
+ (session ? `,当前会话继续使用 ${session.baseagent}` : ''),
|
|
3233
|
+
} };
|
|
3339
3234
|
}
|
|
3340
3235
|
if (cmdBase === '/model') {
|
|
3341
3236
|
const target = resolveMenuModelTarget.call(this, {
|
|
@@ -3413,7 +3308,10 @@ export async function execMenuUpdate(cmd, value, channel, channelId, userId, ove
|
|
|
3413
3308
|
return target;
|
|
3414
3309
|
const agent = this.getAgent(channel, target.baseagent);
|
|
3415
3310
|
const modelTarget = { ...target, field: 'model', fieldPath: `baseagents.${target.baseagent}.model` };
|
|
3416
|
-
const currentModel =
|
|
3311
|
+
const currentModel = readMenuModel(modelTarget, agent, session?.agentSessionId).value;
|
|
3312
|
+
if (!currentModel) {
|
|
3313
|
+
return { error: '当前 Agent 未配置模型,请先设置模型', code: 'MODEL_NOT_CONFIGURED' };
|
|
3314
|
+
}
|
|
3417
3315
|
const validEfforts = await getAvailableEfforts(agent, currentModel);
|
|
3418
3316
|
const allValid = [...validEfforts, 'auto'];
|
|
3419
3317
|
if (!allValid.includes(arg)) {
|
|
@@ -3699,7 +3597,7 @@ export async function execMenuAction(cmd, action, args, channel, channelId, user
|
|
|
3699
3597
|
if (authDenied)
|
|
3700
3598
|
return authDenied;
|
|
3701
3599
|
// ── /gateway action(进程级,gate 已确保 fromControlChannel) ──
|
|
3702
|
-
// test=连通性测试;delete=删除配置;models=模型+价格;set-price
|
|
3600
|
+
// test=连通性测试;delete=删除配置;models=模型+价格;set-price=改网关价格。
|
|
3703
3601
|
if (cmdBase === '/gateway') {
|
|
3704
3602
|
if (action === 'test')
|
|
3705
3603
|
return await gatewayTest(args);
|
|
@@ -3709,8 +3607,6 @@ export async function execMenuAction(cmd, action, args, channel, channelId, user
|
|
|
3709
3607
|
return await gatewayModels(args);
|
|
3710
3608
|
if (action === 'set-price')
|
|
3711
3609
|
return gatewaySetPrice(args);
|
|
3712
|
-
if (action === 'sync-env')
|
|
3713
|
-
return await gatewaySyncEnv(args);
|
|
3714
3610
|
return { error: `不支持 gateway action: ${action}`, code: 'NOT_SUPPORTED' };
|
|
3715
3611
|
}
|
|
3716
3612
|
const isMenuAdmin = isManagementRole(authIdentity.role);
|
|
@@ -3767,6 +3663,34 @@ export async function execMenuAction(cmd, action, args, channel, channelId, user
|
|
|
3767
3663
|
if (action === 'create') {
|
|
3768
3664
|
a.project = resolveProjectPath(a.project, a.aid ?? '', loadDefaults());
|
|
3769
3665
|
}
|
|
3666
|
+
else if (action === 'initialize' && a.resume !== true) {
|
|
3667
|
+
const suppliedPlan = a.plan && typeof a.plan === 'object' && !Array.isArray(a.plan) ? a.plan : undefined;
|
|
3668
|
+
const aid = suppliedPlan?.aid ?? a.aid ?? '';
|
|
3669
|
+
if (typeof aid !== 'string' || !isValidAid(aid))
|
|
3670
|
+
return { error: '无效 Agent AID', code: 'INVALID_ARGS' };
|
|
3671
|
+
if ([suppliedPlan?.project, a.project].some(project => project !== undefined && typeof project !== 'string')) {
|
|
3672
|
+
return { error: 'project 必须是字符串', code: 'INVALID_ARGS' };
|
|
3673
|
+
}
|
|
3674
|
+
const explicitProject = typeof suppliedPlan?.project === 'string' && suppliedPlan.project.trim()
|
|
3675
|
+
? suppliedPlan.project
|
|
3676
|
+
: typeof a.project === 'string' && a.project.trim()
|
|
3677
|
+
? a.project
|
|
3678
|
+
: undefined;
|
|
3679
|
+
let previousProject;
|
|
3680
|
+
if (!explicitProject) {
|
|
3681
|
+
try {
|
|
3682
|
+
previousProject = readInitialization(aid)?.plan.project;
|
|
3683
|
+
}
|
|
3684
|
+
catch {
|
|
3685
|
+
return { error: '初始化状态无效', code: 'INITIALIZE_STATE_INVALID' };
|
|
3686
|
+
}
|
|
3687
|
+
}
|
|
3688
|
+
const project = previousProject ?? resolveProjectPath(explicitProject, aid, loadDefaults());
|
|
3689
|
+
if (suppliedPlan)
|
|
3690
|
+
a.plan = { ...suppliedPlan, project };
|
|
3691
|
+
else
|
|
3692
|
+
a.project = project;
|
|
3693
|
+
}
|
|
3770
3694
|
// queue-clear:清空指定 agent 的待处理消息(不影响处理中),直接走 messageQueue。
|
|
3771
3695
|
if (action === 'queue-clear') {
|
|
3772
3696
|
if (!a.aid)
|
|
@@ -31,7 +31,8 @@ export function parseMenuEvent(value) {
|
|
|
31
31
|
export function buildMenuClientProtectedHeaders(input) {
|
|
32
32
|
const clientName = input.clientName ?? 'evol';
|
|
33
33
|
if (clientName === 'ec-menu-client') {
|
|
34
|
-
|
|
34
|
+
// Menu compatibility uses the base version; installed/logged versions retain the test suffix.
|
|
35
|
+
const clientVersion = input.clientVersion?.trim().replace(/-test\.(0|[1-9]\d*)$/, '');
|
|
35
36
|
if (!parseStableSemver(clientVersion)) {
|
|
36
37
|
throw Object.assign(new Error('ec-menu-client requires a stable X.Y.Z client version'), { code: 'INVALID_CLIENT' });
|
|
37
38
|
}
|
|
@@ -498,7 +499,7 @@ const INVALID_ARGUMENT_CODES = new Set([
|
|
|
498
499
|
'ARGUMENT_MISMATCH', 'INVALID_ARGS', 'INVALID_DELEGATION',
|
|
499
500
|
'INVALID_FIELD', 'INVALID_REVISION', 'INVALID_SCOPE', 'INVALID_TYPE', 'INVALID_VALUE', 'MISSING_AID',
|
|
500
501
|
'MISSING_ARGV', 'MISSING_BASEAGENT', 'MISSING_CMD', 'MISSING_PEER', 'MISSING_VALUE',
|
|
501
|
-
'REVISION_REQUIRED', 'ROLE_VIOLATION',
|
|
502
|
+
'REVISION_REQUIRED', 'ROLE_VIOLATION', 'INITIALIZE_FIELDS_REQUIRED',
|
|
502
503
|
]);
|
|
503
504
|
const STABLE_CODES = new Set([
|
|
504
505
|
'ROLE_ACCESS_DENIED', 'PERMISSION_DENIED', 'UNAUTHORIZED', 'FORBIDDEN',
|
|
@@ -515,6 +516,12 @@ const STABLE_CODES = new Set([
|
|
|
515
516
|
'LOOP_TRIGGER_NOT_FOUND', 'LOOP_TRIGGER_DISABLED', 'LOOP_TRIGGER_INVALID',
|
|
516
517
|
'ROOT_NOT_FOUND', 'ROOT_FORBIDDEN', 'ROOT_EXPIRED', 'ROOT_SCOPE_MISMATCH', 'ROOT_PEER_MISMATCH',
|
|
517
518
|
'INVALID_ROOT_ID', 'MISSING_ROOT_ID', 'INVALID_ROOT_PATH', 'NOT_A_DIRECTORY', 'FILE_TOO_LARGE',
|
|
519
|
+
// Agent initialization uses these codes to distinguish a retryable failure,
|
|
520
|
+
// an actor mismatch, and a plan/state conflict at the App boundary.
|
|
521
|
+
'INITIALIZE_PLAN_CONFLICT', 'INITIALIZE_OWNER_MISMATCH', 'INITIALIZE_CANCELLED',
|
|
522
|
+
'INITIALIZE_STATE_INVALID', 'INITIALIZE_TARGET_CHANGED', 'INITIALIZE_TARGET_EXISTS',
|
|
523
|
+
'INITIALIZE_AGENTMD_VERIFY_FAILED', 'INITIALIZE_OWNER_CONFLICT', 'INITIALIZE_AVATAR_FAILED',
|
|
524
|
+
'INITIALIZE_FAILED', 'MODEL_UNAVAILABLE',
|
|
518
525
|
]);
|
|
519
526
|
export function normalizeMenuError(error) {
|
|
520
527
|
const source = error && typeof error === 'object' ? error : {};
|