evolcore 0.0.46 → 0.0.48
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 +93 -0
- package/bin/ec-build.mjs +86 -0
- package/dist/agent-template/jobs.js +12 -4
- package/dist/agent-template/runtime.js +139 -39
- package/dist/agent-template/service.js +66 -13
- package/dist/agents/baseagent.js +60 -20
- package/dist/agents/claude-runner.js +43 -18
- package/dist/agents/codex/app-server-client.js +32 -23
- package/dist/agents/codex-runner.js +31 -16
- package/dist/agents/ecagent-runner.js +7 -4
- package/dist/agents/gemini-runner.js +5 -2
- package/dist/agents/runner-types.js +5 -21
- package/dist/aun/aid/agentmd.js +5 -1
- package/dist/aun/group/fs-download.js +1 -1
- package/dist/aun/service-proxy.js +4 -2
- package/dist/build-identity.json +1 -0
- package/dist/channels/aun.js +100 -32
- package/dist/channels/daemon.js +10 -26
- package/dist/cli/aun-commands.js +86 -51
- package/dist/cli/code-stats.js +19 -8
- package/dist/cli/command-log.js +1 -1
- package/dist/cli/daemon-commands.js +65 -76
- package/dist/cli/daemon-lifecycle-client.js +17 -3
- package/dist/cli/directory.js +7 -1
- package/dist/cli/ecmsg-gateway.js +5 -2
- package/dist/cli/index.js +2 -8
- package/dist/cli/init-channel.js +6 -8
- package/dist/cli/init.js +74 -46
- package/dist/cli/invoke-command.js +1 -1
- package/dist/cli/provider-command.js +74 -13
- package/dist/cli/restart-monitor.js +104 -28
- package/dist/cli/role.js +61 -17
- package/dist/cli/stats.js +3 -3
- package/dist/cli/task-context.js +83 -15
- package/dist/cli/thread-command.js +16 -51
- package/dist/cli/upgrade-command.js +4 -2
- package/dist/config/boot-log.js +3 -9
- package/dist/config/builtin-roles.js +5 -7
- package/dist/config/config-manager.js +31 -23
- package/dist/config/daemon-services.js +30 -3
- package/dist/config/gateway-config.js +2 -2
- package/dist/config/invoke-ipc-service.js +6 -4
- package/dist/config/peer-bind-code.js +3 -4
- package/dist/config/peer-book-store.js +59 -218
- package/dist/config/peer-book.js +26 -27
- package/dist/config/peer-role-resolver.js +16 -1
- package/dist/config/provider-identity-migration.js +161 -6
- package/dist/config/provider-ipc-service.js +56 -11
- package/dist/config/provider-menu-request.js +24 -5
- package/dist/config/provider-templates.js +127 -0
- package/dist/config/providers-config.js +59 -8
- package/dist/config/providers-management.js +467 -49
- package/dist/config/role-command-service.js +248 -1
- package/dist/config/schema-migration.js +228 -20
- package/dist/config/schema-registry.js +6 -2
- package/dist/core/agent-application-service.js +6 -1
- package/dist/core/agent-runtime.js +10 -5
- package/dist/core/auth/agent-delegation.js +10 -4
- package/dist/core/auth/auth-gateway.js +2 -1
- package/dist/core/auth/delegation-authorization.js +3 -0
- package/dist/core/auth/delegation-diagnostics.js +56 -15
- package/dist/core/auth/operation-authorizer.js +26 -1
- package/dist/core/auth/operation-catalog.js +28 -64
- package/dist/core/capability/providers/codex-capability-provider.js +7 -8
- package/dist/core/channel-loader.js +18 -0
- package/dist/core/command/agent-control.js +32 -0
- package/dist/core/command/command-handler.js +81 -85
- package/dist/core/command/menu-catalog.js +1 -0
- package/dist/core/command/menu-handler.js +65 -153
- package/dist/core/command/menu-protocol.js +7 -1
- package/dist/core/command/provider-menu.js +13 -3
- package/dist/core/command/role-menu.js +47 -23
- package/dist/core/command/slash-handler.js +30 -49
- package/dist/core/command/team-workspace-items.js +81 -12
- package/dist/core/command/team-workspace-team.js +9 -71
- package/dist/core/command/topic-slash.js +9 -30
- package/dist/core/daemon-bootstrap.js +19 -10
- package/dist/core/daemon-control.js +8 -10
- package/dist/core/daemon-lifecycle.js +50 -40
- package/dist/core/evolagent-registry.js +22 -3
- package/dist/core/file-integrity/store.js +2 -0
- package/dist/core/handoff/runtime.js +37 -1
- package/dist/core/host-snapshot.js +9 -4
- package/dist/core/inference/text-inference.js +3 -1
- package/dist/core/initialization/service.js +31 -8
- package/dist/core/interaction-router.js +3 -0
- package/dist/core/invoke/executors/text.js +72 -19
- package/dist/core/ipc-registration.js +6 -4
- package/dist/core/memory/consolidation.js +6 -6
- package/dist/core/message/aun-ipc-sender.js +165 -55
- package/dist/core/message/im-renderer.js +1 -1
- package/dist/core/message/message-bridge.js +51 -334
- package/dist/core/message/message-log.js +5 -0
- package/dist/core/message/message-queue.js +22 -0
- package/dist/core/message/message-utils.js +8 -0
- package/dist/core/message/response-engine.js +429 -116
- package/dist/core/message/send-routing.js +5 -1
- package/dist/core/model/catalog-service.js +31 -11
- package/dist/core/model/model-capabilities.js +22 -4
- package/dist/core/model/model-catalog.js +1 -0
- package/dist/core/ownership/owner-resolver.js +355 -60
- package/dist/core/permission/protected-paths.js +6 -6
- package/dist/core/relation/peer-identity.js +28 -2
- package/dist/core/relation/same-owner-proof.js +81 -111
- package/dist/core/session/adapters/claude-session-file-adapter.js +1 -1
- package/dist/core/session/adapters/codex-session-file-adapter.js +96 -15
- package/dist/core/session/session-file-health.js +49 -14
- package/dist/core/session/session-fs-store.js +91 -35
- package/dist/core/session/session-manager.js +68 -24
- package/dist/core/session/session-mapper.js +14 -34
- package/dist/core/session/session-transcript.js +5 -1
- package/dist/core/task/task-activity-store.js +84 -0
- package/dist/core/task/task-image-resources.js +1 -1
- package/dist/core/task/task-recovery-service.js +12 -0
- package/dist/core/thread/command-parser.js +7 -12
- package/dist/core/thread/thread-context-storage.js +3 -2
- package/dist/core/thread/thread-operation.js +2 -13
- package/dist/core/thread/thread-service.js +15 -46
- package/dist/directory/owner-directory-admission.js +1 -1
- package/dist/directory/owner-directory-cache.js +45 -28
- package/dist/directory/owner-directory-markdown.js +13 -1
- package/dist/directory/owner-directory-query-operation.js +29 -3
- package/dist/directory/owner-directory-remarks.js +11 -3
- package/dist/eck/message-renderer.js +84 -24
- package/dist/ecweb/basic-settings-service.js +3 -1
- package/dist/ecweb/message-context-service.js +1 -1
- package/dist/ecweb/pairing.js +4 -3
- package/dist/ecweb/providers-service.js +26 -1
- package/dist/ecweb/runtime/lifecycle.js +82 -23
- package/dist/ecweb/runtime/proxy-access.js +74 -0
- package/dist/ecweb/runtime/supervisor.js +6 -17
- package/dist/event-center/registry.js +13 -2
- package/dist/event-center/runtime.js +103 -11
- package/dist/event-center/script-runner.js +5 -5
- package/dist/index.js +129 -93
- package/dist/ipc.js +15 -3
- package/dist/outputs/events.js +62 -0
- package/dist/outputs/protocol.js +102 -0
- package/dist/outputs/service.js +279 -0
- package/dist/paths.js +3 -0
- package/dist/proxy/manager.js +43 -13
- package/dist/services/index.js +89 -4
- package/dist/services/ipc-operation.js +4 -15
- package/dist/services/pack-manager.js +12 -1
- package/dist/services/router.js +21 -6
- package/dist/services/script-runner.js +5 -4
- package/dist/services/validation.js +1 -1
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +19 -0
- package/dist/stats/index.js +1 -1
- package/dist/stats/{price-resolver.js → model-resolver.js} +305 -24
- package/dist/stats/normalizer.js +2 -0
- package/dist/stats/query.js +35 -27
- package/dist/stats/role-budget.js +5 -2
- package/dist/stats/writer.js +10 -6
- package/dist/trigger/audit.js +7 -0
- package/dist/trigger/authorization.js +105 -11
- package/dist/trigger/feedback.js +10 -0
- package/dist/trigger/history.js +37 -11
- package/dist/trigger/ipc-service.js +12 -1
- package/dist/trigger/manager.js +1 -0
- package/dist/trigger/scheduler.js +11 -5
- package/dist/trigger/script-executor.js +2 -1
- package/dist/trigger/script-sandbox.js +9 -3
- package/dist/trigger/state.js +7 -0
- package/dist/trigger/validation.js +22 -0
- package/dist/utils/aid-bind.js +155 -18
- package/dist/utils/atomic-write.js +3 -3
- package/dist/utils/cross-platform.js +97 -31
- package/dist/utils/error-dict.json +94 -4
- package/dist/utils/error-utils.js +40 -4
- package/dist/utils/evolcore-version.js +36 -65
- package/dist/utils/instance-registry.js +61 -0
- package/dist/utils/msg-diag.js +1 -0
- package/dist/utils/process-introspect.js +158 -8
- package/dist/utils/process-tree.js +50 -2
- package/dist/utils/upgrade-jobs.js +4 -4
- package/dist/utils/windows-shell-trust.js +2 -0
- package/dist/workbench/protocol.js +80 -0
- package/dist/workbench/service.js +359 -0
- package/ecagent/dist/types.d.ts +6 -2
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +2 -2
- package/kits/docs/evolcore/aid.md +3 -1
- package/kits/docs/evolcore/config.md +12 -0
- package/kits/docs/evolcore/directory.md +22 -3
- package/kits/docs/evolcore/ecweb-lifecycle.md +15 -0
- package/kits/docs/evolcore/model.md +10 -0
- package/kits/docs/evolcore/peer.md +19 -65
- package/kits/docs/evolcore/provider.md +133 -5
- package/kits/docs/evolcore/role.md +80 -0
- package/kits/docs/evolcore/services.md +6 -6
- package/kits/docs/evolcore/team-workspace.md +1 -1
- package/kits/docs/evolcore/thread-chain.md +14 -15
- package/kits/docs/evolcore/tool-authorization.md +5 -0
- package/kits/docs/evolcore/trigger.md +10 -0
- package/kits/eck_message_manifest.json +12 -0
- package/kits/provider-templates.json +1213 -0
- package/kits/rules/04-relation.md +3 -3
- package/kits/schemas/_meta.json +14 -2
- package/kits/schemas/contact-book.schema.4.json +52 -0
- package/kits/schemas/providers.schema.3.json +200 -0
- package/kits/skills/.switches.json +4 -0
- package/kits/skills/ability/references/calling.md +1 -1
- package/kits/skills/ec-group/SKILL.md +2 -2
- package/kits/skills/ec-identity/SKILL.md +19 -72
- package/kits/skills/ec-provider/SKILL.md +221 -0
- package/kits/skills/ec-provider/scripts/check-model.mjs +80 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/skills/thread-ops/SKILL.md +34 -21
- package/kits/templates/message-fragments/group-batch-item.md +1 -1
- package/kits/templates/message-fragments/group-batch.md +1 -1
- package/kits/templates/message-fragments/inject-default.md +1 -1
- package/kits/templates/message-fragments/interrupt-insert.md +1 -0
- package/kits/templates/message-fragments/item-group.md +1 -1
- package/kits/templates/message-fragments/item-private.md +1 -1
- package/kits/templates/message-fragments/thread-context.md +1 -1
- package/kits/templates/message-fragments/trigger-session.md +1 -1
- package/kits/templates/message-fragments/trigger-thread-check.md +1 -1
- package/kits/templates/roles/admin.json +2 -19
- package/kits/templates/roles/member.json +0 -3
- package/kits/templates/system-fragments/baseagent.md +6 -0
- package/kits/templates/system-fragments/commands.md +3 -3
- package/kits/templates/system-fragments/managed-runtime.md +1 -1
- package/kits/templates/system-fragments/relation.md +1 -1
- package/kits/templates/system-fragments/thread.md +6 -5
- package/package.json +6 -4
- package/scripts/agent-template/inspect.mjs +4 -1
- package/scripts/agent-template/shared/common.mjs +2 -3
- package/scripts/agent-template/shared/template-contract.mjs +2 -1
- package/scripts/agent-template/shared/template-package.mjs +9 -2
- package/scripts/agent-template/shared/template-runtime.mjs +20 -5
- package/scripts/agent-template/team-pack.mjs +6 -3
- package/dist/cli/peer.js +0 -127
- package/dist/config/peer-operation-service.js +0 -132
- package/dist/config/peer-request-service.js +0 -532
- package/dist/core/command/connect-menu.js +0 -624
|
@@ -15,17 +15,14 @@ import { resolvePaths } from '../paths.js';
|
|
|
15
15
|
import { ownerResolver, OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, OWNERSHIP_CACHE_MAX_AGE_MS } from './ownership/owner-resolver.js';
|
|
16
16
|
import { subscribeUpgradeJob } from '../utils/upgrade-jobs.js';
|
|
17
17
|
import { subscribeTemplateJob } from '../agent-template/service.js';
|
|
18
|
-
import { ecwebInitializationService } from './initialization/service.js';
|
|
19
18
|
const controlMenuDeduper = new MenuRequestDeduper();
|
|
20
19
|
export function startDaemonControlAid({ daemonCfg, cmdHandler, bindService, diagService, getProcessOwners, ecwebSupervisor, onServiceProxyManager, connectChannel, startupTrace, waitForServices, }) {
|
|
21
|
-
if (!daemonCfg.aid)
|
|
22
|
-
return undefined;
|
|
23
20
|
const aunPath = resolvePaths().root;
|
|
24
|
-
const certKey = path.join(aunPath, 'AIDs', daemonCfg.aid, 'private', 'key.json');
|
|
25
|
-
if (!fs.existsSync(certKey)) {
|
|
21
|
+
const certKey = daemonCfg.aid ? path.join(aunPath, 'AIDs', daemonCfg.aid, 'private', 'key.json') : undefined;
|
|
22
|
+
if (certKey && !fs.existsSync(certKey)) {
|
|
26
23
|
logger.warn(`控制 AID 证书缺失:${daemonCfg.aid}(AUN 控制通道后台重连;如需重建运行 ec init)`);
|
|
27
24
|
}
|
|
28
|
-
const controlChannel = new AUNChannel({
|
|
25
|
+
const controlChannel = daemonCfg.aid ? new AUNChannel({
|
|
29
26
|
aid: daemonCfg.aid,
|
|
30
27
|
agentName: daemonCfg.aid,
|
|
31
28
|
channelName: 'control',
|
|
@@ -33,8 +30,8 @@ export function startDaemonControlAid({ daemonCfg, cmdHandler, bindService, diag
|
|
|
33
30
|
defaultEncrypt: daemonCfg.aun?.defaultEncrypt,
|
|
34
31
|
aunTrace: daemonCfg.debug?.aunTrace,
|
|
35
32
|
aunSdkLog: daemonCfg.debug?.aunSdkLog,
|
|
36
|
-
});
|
|
37
|
-
const serviceProxyManager = new ServiceProxyManager({ providerAid: daemonCfg.aid, controlChannel, ecwebSupervisor: ecwebSupervisor ?? undefined, startupTrace });
|
|
33
|
+
}) : undefined;
|
|
34
|
+
const serviceProxyManager = new ServiceProxyManager({ providerAid: daemonCfg.aid ?? '', controlChannel, ecwebSupervisor: ecwebSupervisor ?? undefined, startupTrace });
|
|
38
35
|
onServiceProxyManager?.(serviceProxyManager);
|
|
39
36
|
let stopping = false;
|
|
40
37
|
onShutdown(() => { stopping = true; return serviceProxyManager.stop(); });
|
|
@@ -53,6 +50,8 @@ export function startDaemonControlAid({ daemonCfg, cmdHandler, bindService, diag
|
|
|
53
50
|
void proxyStartup.catch((error) => {
|
|
54
51
|
logger.warn(`ServiceProxy manager 启动失败(不影响 daemon 主流程): ${error?.message || error}`);
|
|
55
52
|
});
|
|
53
|
+
if (!controlChannel)
|
|
54
|
+
return undefined;
|
|
56
55
|
controlChannel.onMessage(async (opts) => {
|
|
57
56
|
const text = (opts.content || '').trim();
|
|
58
57
|
let activeMenuRequest;
|
|
@@ -120,8 +119,7 @@ export function startDaemonControlAid({ daemonCfg, cmdHandler, bindService, diag
|
|
|
120
119
|
}
|
|
121
120
|
};
|
|
122
121
|
if (bindService && parsed?.type === 'bind.request') {
|
|
123
|
-
const response = await
|
|
124
|
-
?? await bindService.handleRequest(parsed, opts.peerId);
|
|
122
|
+
const response = await bindService.handleRequest(parsed, opts.peerId, opts.encrypted === true);
|
|
125
123
|
if (response) {
|
|
126
124
|
await controlChannel.sendStructuredOrThrow(opts.channelId, response, controlReplyContext(opts));
|
|
127
125
|
}
|
|
@@ -111,35 +111,37 @@ export async function discoverStartupWork(options) {
|
|
|
111
111
|
else
|
|
112
112
|
plan.requiredExternalAids.add(aid);
|
|
113
113
|
};
|
|
114
|
-
const queueStarted = Date.now();
|
|
115
|
-
let queueItems = 0;
|
|
116
|
-
let queueFiles = 0;
|
|
117
114
|
let queueSnapshot;
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
115
|
+
const queueCapture = (async () => {
|
|
116
|
+
const queueStarted = Date.now();
|
|
117
|
+
let queueItems = 0;
|
|
118
|
+
let queueFiles = 0;
|
|
119
|
+
try {
|
|
120
|
+
const queue = await json(options.queuePath);
|
|
121
|
+
if (queue !== undefined) {
|
|
122
|
+
queueFiles = 1;
|
|
123
|
+
queueSnapshot = parseQueueSnapshot(queue);
|
|
124
|
+
for (const bucket of [...queueSnapshot.queues, ...(queueSnapshot.active ?? [])]) {
|
|
125
|
+
for (const item of bucket.items) {
|
|
126
|
+
queueItems++;
|
|
127
|
+
noteMessage(item.message, bucket.queueKey);
|
|
128
|
+
for (const part of item.parts ?? [])
|
|
129
|
+
noteMessage(part.message, bucket.queueKey);
|
|
130
|
+
}
|
|
129
131
|
}
|
|
130
132
|
}
|
|
131
133
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
134
|
+
catch (error) {
|
|
135
|
+
plan.recoveryIndexAids.clear();
|
|
136
|
+
for (const aid of known)
|
|
137
|
+
uncertain(aid, error);
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
options.onScan?.({ phase: 'queue', durationMs: Date.now() - queueStarted, files: queueFiles, items: queueItems });
|
|
141
|
+
options.onQueueCaptured?.(queueSnapshot);
|
|
142
|
+
}
|
|
143
|
+
return Date.now();
|
|
144
|
+
})();
|
|
143
145
|
const triggerDir = options.triggerDir ?? agentTriggersDir;
|
|
144
146
|
const scanTriggers = async (aid) => {
|
|
145
147
|
const started = Date.now();
|
|
@@ -190,10 +192,13 @@ export async function discoverStartupWork(options) {
|
|
|
190
192
|
const loopStart = performance.eventLoopUtilization();
|
|
191
193
|
loopDelay.enable();
|
|
192
194
|
try {
|
|
193
|
-
await Promise.all([daemonTriggerScan, ...Array.from({ length: Math.min(4, aids.length) }, async () => {
|
|
195
|
+
await Promise.all([queueCapture, daemonTriggerScan, ...Array.from({ length: Math.min(4, aids.length) }, async () => {
|
|
194
196
|
while (next < aids.length) {
|
|
195
197
|
const aid = aids[next++];
|
|
196
198
|
const scanSessions = async () => {
|
|
199
|
+
// Trigger evidence is independent of the queue. Session history and
|
|
200
|
+
// idle classification still require the captured recovery index.
|
|
201
|
+
const now = await queueCapture;
|
|
197
202
|
// A complete queue snapshot covers executions, including consumed hints.
|
|
198
203
|
// Do not enumerate historical chat/topic directories on the normal path.
|
|
199
204
|
if (hasIndexedRecovery(queueSnapshot, aid))
|
|
@@ -304,7 +309,7 @@ export async function discoverStartupWork(options) {
|
|
|
304
309
|
options.onScan?.({ phase: 'sessions', aid, durationMs: Date.now() - started, files, directories: chats,
|
|
305
310
|
directoryMs, threadDirectoryMs, metadataMs, readMaxMs, io });
|
|
306
311
|
};
|
|
307
|
-
//
|
|
312
|
+
// Start independent read-only evidence under the four-owner budget.
|
|
308
313
|
// Positive work can admit a busy owner early; idle classification
|
|
309
314
|
// still waits for both scans and the primary's daemon-owned Triggers.
|
|
310
315
|
await Promise.all([
|
|
@@ -324,7 +329,7 @@ export async function discoverStartupWork(options) {
|
|
|
324
329
|
}
|
|
325
330
|
return plan;
|
|
326
331
|
}
|
|
327
|
-
/** One concurrent channel connection per CPU
|
|
332
|
+
/** One concurrent channel connection per available CPU, capped at eight. */
|
|
328
333
|
export function startupConnectionBudget() {
|
|
329
334
|
let cpuParallelism = 1;
|
|
330
335
|
try {
|
|
@@ -333,7 +338,7 @@ export function startupConnectionBudget() {
|
|
|
333
338
|
cpuParallelism = available;
|
|
334
339
|
}
|
|
335
340
|
catch { /* Retain the one-CPU budget when detection is unavailable. */ }
|
|
336
|
-
return { cpuParallelism, concurrency: cpuParallelism };
|
|
341
|
+
return { cpuParallelism, concurrency: Math.min(cpuParallelism, 8) };
|
|
337
342
|
}
|
|
338
343
|
/** Bounded admission for startup side effects. Dependency waits belong outside this queue. */
|
|
339
344
|
export class StartupTaskQueue {
|
|
@@ -657,6 +662,15 @@ export function createDaemonShutdown({ disposePluginResources, lifecycleNotices,
|
|
|
657
662
|
if (shutdownInProgress)
|
|
658
663
|
return;
|
|
659
664
|
shutdownInProgress = true;
|
|
665
|
+
// Include pre-teardown notices and quiescing in the real stop boundary.
|
|
666
|
+
const trace = new StartupTracer('daemon', {
|
|
667
|
+
kind: 'stop',
|
|
668
|
+
traceId: traceId || undefined,
|
|
669
|
+
processStartMs: Date.now(),
|
|
670
|
+
});
|
|
671
|
+
trace.setMeta('signal', signal || shutdownSignal);
|
|
672
|
+
trace.setMeta('via', traceId ? 'ipc' : 'signal');
|
|
673
|
+
const preparationStartedAt = Date.now();
|
|
660
674
|
cancelStartup?.();
|
|
661
675
|
if (signal)
|
|
662
676
|
shutdownSignal = signal;
|
|
@@ -672,6 +686,8 @@ export function createDaemonShutdown({ disposePluginResources, lifecycleNotices,
|
|
|
672
686
|
// 异步的(发送前 await ownerResolver.refresh)。若不等它,stopOwnership 会在准入
|
|
673
687
|
// 恢复执行前清空 resolver,snapshot() 重建空 subject 后一律判 unavailable,
|
|
674
688
|
// 下线通知就会被 CONTACT_DENIED 拦下。
|
|
689
|
+
const offlineStartedAt = Date.now();
|
|
690
|
+
trace.addSpan('daemon.shutdown', preparationStartedAt, offlineStartedAt);
|
|
675
691
|
try {
|
|
676
692
|
await withDeadline(lifecycleNotices?.sendOffline(shutdownSignal), OFFLINE_TOTAL_BUDGET_MS);
|
|
677
693
|
}
|
|
@@ -679,6 +695,10 @@ export function createDaemonShutdown({ disposePluginResources, lifecycleNotices,
|
|
|
679
695
|
// A synchronous throw must not abort the exit; the notice is best-effort.
|
|
680
696
|
logger.warn(`[Shutdown] offline notice failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
681
697
|
}
|
|
698
|
+
finally {
|
|
699
|
+
trace.addSpan('daemon.offlineNotices', offlineStartedAt, Date.now());
|
|
700
|
+
}
|
|
701
|
+
const quiesceStartedAt = Date.now();
|
|
682
702
|
// Detaching ownership emits invalidations. Stop listeners first so those
|
|
683
703
|
// invalidations cannot enqueue refreshes against a resolver being destroyed.
|
|
684
704
|
for (const channel of [...channelInstances.map(instance => instance.channel), controlChannel]) {
|
|
@@ -697,17 +717,7 @@ export function createDaemonShutdown({ disposePluginResources, lifecycleNotices,
|
|
|
697
717
|
const pid = process.pid;
|
|
698
718
|
const ppid = process.ppid;
|
|
699
719
|
logger.info(`\n\nShutting down gracefully... (signal=${shutdownSignal}, pid=${pid}, ppid=${ppid})`);
|
|
700
|
-
|
|
701
|
-
// daemon 可能已经跑了几小时。traceId 由 `ec stop` 通过 IPC 带进来,
|
|
702
|
-
// 没有的话(信号退出、超时兜底)自己生成一条独立的记录。
|
|
703
|
-
const trace = new StartupTracer('daemon', {
|
|
704
|
-
kind: 'stop',
|
|
705
|
-
traceId: traceId || undefined,
|
|
706
|
-
processStartMs: Date.now(),
|
|
707
|
-
});
|
|
708
|
-
trace.setMeta('signal', shutdownSignal);
|
|
709
|
-
trace.setMeta('via', traceId ? 'ipc' : 'signal');
|
|
710
|
-
trace.addSpan('daemon.shutdown', trace.startedAtMs, Date.now());
|
|
720
|
+
trace.addSpan('daemon.quiesceChannels', quiesceStartedAt, Date.now());
|
|
711
721
|
const ipcStopStartedAt = Date.now();
|
|
712
722
|
ipcServer.stopCpuTracking();
|
|
713
723
|
ipcServer.stop();
|
|
@@ -11,6 +11,7 @@ import { ensureInitialRoleRegistry } from '../config/role-service.js';
|
|
|
11
11
|
import { resolveAgentLifecycle } from '../config/lifecycle.js';
|
|
12
12
|
import { getOwners, getPrimaryOwner, ownerResolver } from './ownership/owner-resolver.js';
|
|
13
13
|
import { configuredOwnerList } from '../config/owner-config.js';
|
|
14
|
+
import { assertTemplateInstallationReady } from '../agent-template/jobs.js';
|
|
14
15
|
// ── Channel Fingerprint ───────────────────────────────────────────────────
|
|
15
16
|
// 用于检测多 agent 之间复用同一外部凭证的冲突(appId、aid、token 等)。
|
|
16
17
|
// 格式:{type}:{primaryKey}
|
|
@@ -101,7 +102,9 @@ export class EvolAgentRegistry {
|
|
|
101
102
|
this.registerErrorAgent(raw, `${precheck.code}: ${precheck.detail}`);
|
|
102
103
|
continue;
|
|
103
104
|
}
|
|
104
|
-
|
|
105
|
+
// Reuse the mtime-checked reads populated during enumeration; changes
|
|
106
|
+
// still reload through ConfigManager's normal atomic reader.
|
|
107
|
+
const merged = resolveEffective({ self: expandedRaw.aid }, { cache: true });
|
|
105
108
|
const agent = new EvolAgent(raw, merged);
|
|
106
109
|
ensureAgentDirSkeleton(expandedRaw.aid);
|
|
107
110
|
ensureInitialRoleRegistry(expandedRaw.aid);
|
|
@@ -230,12 +233,16 @@ export class EvolAgentRegistry {
|
|
|
230
233
|
list() {
|
|
231
234
|
return [...this.agents.values()].map(a => this.toInfo(a));
|
|
232
235
|
}
|
|
236
|
+
/** Current runtime instances, including disabled/error Agents, without display-file reads. */
|
|
237
|
+
allAgents() {
|
|
238
|
+
return [...this.agents.values()];
|
|
239
|
+
}
|
|
233
240
|
invalidateAgentDisplayCache(aid) {
|
|
234
241
|
invalidateAgentDisplayName(aid);
|
|
235
242
|
this.personalNameCache.delete(aid);
|
|
236
243
|
}
|
|
237
244
|
runnableAgents() {
|
|
238
|
-
return
|
|
245
|
+
return this.allAgents().filter(a => a.status === 'stopped');
|
|
239
246
|
}
|
|
240
247
|
getSkipped() {
|
|
241
248
|
return [...this.skipped];
|
|
@@ -293,10 +300,11 @@ export class EvolAgentRegistry {
|
|
|
293
300
|
logger.info(`[EvolAgentRegistry] Hot-loaded agent: ${aid}`);
|
|
294
301
|
return agent;
|
|
295
302
|
}
|
|
296
|
-
async reload(aidOrName, hooks) {
|
|
303
|
+
async reload(aidOrName, hooks, options = {}) {
|
|
297
304
|
const oldAgent = this.agents.get(aidOrName);
|
|
298
305
|
if (!oldAgent)
|
|
299
306
|
throw new Error(`Agent "${aidOrName}" not found`);
|
|
307
|
+
assertTemplateInstallationReady(oldAgent.aid, options.recoveryJobId);
|
|
300
308
|
await hooks.beforeAgentOperation?.(oldAgent.aid);
|
|
301
309
|
const expandedRaw = loadAgent(oldAgent.aid);
|
|
302
310
|
if (!expandedRaw)
|
|
@@ -310,6 +318,16 @@ export class EvolAgentRegistry {
|
|
|
310
318
|
const raw = readConfig(ConfigTarget.Agent, { self: oldAgent.aid }, { cache: true }) ?? expandedRaw;
|
|
311
319
|
ownerResolver.setAgentConfiguredOwners(oldAgent.aid, configuredOwnerList(raw));
|
|
312
320
|
const merged = resolveEffective({ self: raw.aid }, {});
|
|
321
|
+
if (oldAgent.status === 'disabled' && raw.enabled === false
|
|
322
|
+
|| (options.preserveStopped && oldAgent.status === 'stopped' || options.restoreStopped) && raw.enabled !== false) {
|
|
323
|
+
oldAgent.swapConfig(raw, merged);
|
|
324
|
+
oldAgent.invalidatePersonaCache();
|
|
325
|
+
if (options.restoreStopped && raw.enabled !== false) {
|
|
326
|
+
oldAgent.status = 'stopped';
|
|
327
|
+
this.manuallyStopped.add(oldAgent.aid);
|
|
328
|
+
}
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
313
331
|
if (oldAgent.status === 'disabled' && raw.enabled !== false) {
|
|
314
332
|
oldAgent.swapConfig(raw, merged);
|
|
315
333
|
const hotLoad = globalThis.__evolcore_hotLoadAgent;
|
|
@@ -561,6 +579,7 @@ export class EvolAgentRegistry {
|
|
|
561
579
|
}
|
|
562
580
|
async startAgent(aidOrName, hooks) {
|
|
563
581
|
assertAgentAidAvailable(aidOrName);
|
|
582
|
+
assertTemplateInstallationReady(aidOrName);
|
|
564
583
|
const agent = this.agents.get(aidOrName);
|
|
565
584
|
if (!agent)
|
|
566
585
|
throw new Error(`Agent "${aidOrName}" not found`);
|
|
@@ -192,6 +192,8 @@ function verifyLocked(filePath, key, opts) {
|
|
|
192
192
|
const db = getDb();
|
|
193
193
|
const row = db.prepare('SELECT sha256, package_version FROM file_integrity WHERE file_path = ?').get(key);
|
|
194
194
|
if (!row) {
|
|
195
|
+
if (opts?.requireRegistered)
|
|
196
|
+
return { status: 'tampered', actual, restorable: false };
|
|
195
197
|
// 用已读字节登记,避免二次读文件时内容已变
|
|
196
198
|
persistBytes(key, bytes, undefined, fs.statSync(filePath).mtime, packageVersion);
|
|
197
199
|
logger.info(`[file-integrity] auto-registered path=${key} sha256=${short(actual)}`);
|
|
@@ -9,7 +9,7 @@ import { recordCausationSpan } from '../causation/audit.js';
|
|
|
9
9
|
import { logger } from '../../utils/logger.js';
|
|
10
10
|
import { setImmediate as yieldToIo } from 'node:timers/promises';
|
|
11
11
|
import { replyContextFromSession } from '../message/message-utils.js';
|
|
12
|
-
import { sessionTopicThreadId } from '../thread/topic-id.js';
|
|
12
|
+
import { safeFormatMainTopicId, sessionTopicThreadId } from '../thread/topic-id.js';
|
|
13
13
|
const HANDOFF_STALE_WARN_MS = 12 * 60 * 60 * 1000;
|
|
14
14
|
const HANDOFF_RETENTION_MS = 72 * 60 * 60 * 1000;
|
|
15
15
|
const HANDOFF_LARGE_AGGREGATE_COUNT = 10;
|
|
@@ -92,12 +92,48 @@ export class HandoffRuntime {
|
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
const targetChatType = input.targetChatType;
|
|
95
|
+
const expectedTarget = input.expectedTarget;
|
|
96
|
+
if (expectedTarget) {
|
|
97
|
+
const targetChannelKeyType = tryParseChannelKey(targetChannelKey)?.type;
|
|
98
|
+
const expectedMainThread = safeFormatMainTopicId(input.selfAid, expectedTarget.channelId);
|
|
99
|
+
const threadMatches = expectedTarget.threadId
|
|
100
|
+
? input.thread === expectedTarget.threadId
|
|
101
|
+
: !input.thread || input.thread === expectedMainThread;
|
|
102
|
+
if (input.to !== expectedTarget.channelId || targetChatType !== expectedTarget.chatType
|
|
103
|
+
|| targetChannelType !== expectedTarget.channelType || targetChannelKeyType !== expectedTarget.channelType
|
|
104
|
+
|| !threadMatches) {
|
|
105
|
+
throw Object.assign(new Error('Handoff request does not match the verified send route'), {
|
|
106
|
+
code: 'AUN_OUTBOUND_ROUTE_MISMATCH',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (expectedTarget.sessionId) {
|
|
110
|
+
const indexedTarget = await this.sessionManager.getSessionById(expectedTarget.sessionId);
|
|
111
|
+
if (!indexedTarget || indexedTarget.selfAID !== input.selfAid
|
|
112
|
+
|| indexedTarget.channelType !== expectedTarget.channelType
|
|
113
|
+
|| indexedTarget.channelId !== expectedTarget.channelId
|
|
114
|
+
|| indexedTarget.chatType !== expectedTarget.chatType
|
|
115
|
+
|| sessionTopicThreadId(indexedTarget) !== expectedTarget.threadId) {
|
|
116
|
+
throw Object.assign(new Error('Indexed handoff session does not match the verified send route'), {
|
|
117
|
+
code: 'AUN_OUTBOUND_ROUTE_MISMATCH',
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
95
122
|
const target = await this.sessionManager.getOrCreateSession(targetChannelKey, input.to, origin.projectPath, input.thread, {
|
|
96
123
|
channelKey: targetChannelKey,
|
|
97
124
|
peerId: input.to,
|
|
98
125
|
...(targetChatType === 'group' ? { groupId: input.to } : {}),
|
|
99
126
|
}, undefined, input.to, targetChatType, origin.baseagent, input.selfAid, targetChannelType, targetChatType === 'group' ? 'group' : 'agent');
|
|
100
127
|
throwIfAborted(input.signal);
|
|
128
|
+
const expected = input.expectedTarget;
|
|
129
|
+
if (expected && ((expected.sessionId && target.id !== expected.sessionId)
|
|
130
|
+
|| target.selfAID !== input.selfAid
|
|
131
|
+
|| target.channelType !== expected.channelType || target.channelId !== expected.channelId
|
|
132
|
+
|| target.chatType !== expected.chatType || sessionTopicThreadId(target) !== expected.threadId)) {
|
|
133
|
+
throw Object.assign(new Error('Resolved handoff session does not match the verified send route'), {
|
|
134
|
+
code: 'AUN_OUTBOUND_ROUTE_MISMATCH',
|
|
135
|
+
});
|
|
136
|
+
}
|
|
101
137
|
if (target.id === origin.id) {
|
|
102
138
|
if (input.handoffContext !== undefined)
|
|
103
139
|
throw new Error('handoff context requires a different target session');
|
|
@@ -150,11 +150,15 @@ export function createHostSnapshotProvider(deps) {
|
|
|
150
150
|
staticState.cachedAt = new Date().toISOString();
|
|
151
151
|
writeStaticCache({ virtualization: staticState.virtualization, runtimes: staticState.runtimes, cachedAt: staticState.cachedAt });
|
|
152
152
|
};
|
|
153
|
-
const
|
|
153
|
+
const getHost = () => {
|
|
154
154
|
const host = readHostInfo(versions.evolcore, resolvePaths().root, { runtimes: staticState.runtimes });
|
|
155
155
|
host.os.virtualization = staticState.virtualization;
|
|
156
156
|
// CPU 只有 daemon 有采样值;采样未启动时宁可给 null,也不给一个骗人的数字。
|
|
157
157
|
host.hardware.cpuUsagePercent = deps.getSystemCpuPercent?.() ?? null;
|
|
158
|
+
return host;
|
|
159
|
+
};
|
|
160
|
+
const getSnapshot = () => {
|
|
161
|
+
const host = getHost();
|
|
158
162
|
const agents = deps.agentRegistry.list();
|
|
159
163
|
let totalPending = 0;
|
|
160
164
|
let totalProcessing = 0;
|
|
@@ -201,7 +205,8 @@ export function createHostSnapshotProvider(deps) {
|
|
|
201
205
|
},
|
|
202
206
|
};
|
|
203
207
|
};
|
|
204
|
-
//
|
|
205
|
-
|
|
206
|
-
|
|
208
|
+
// The daemon schedules these informational child processes after Ready.
|
|
209
|
+
if (deps.autoProbe !== false)
|
|
210
|
+
setImmediate(() => { void probe(); });
|
|
211
|
+
return { getHost, getSnapshot, refresh: probe };
|
|
207
212
|
}
|
|
@@ -5,7 +5,7 @@ import { appendRequestPath, appendV1RequestPath } from '../../agents/request-ide
|
|
|
5
5
|
import { assertExplicitProviderModelAllowed, resolveServiceSelection } from '../../config/providers.js';
|
|
6
6
|
import { eligibleServiceFallbackModels } from '../model/model-fallback.js';
|
|
7
7
|
import { RetryScheduler } from '../message/retry-scheduler.js';
|
|
8
|
-
import { classifyError, ErrorType } from '../../utils/error-utils.js';
|
|
8
|
+
import { classifyError, errorQuestionRule, ErrorType } from '../../utils/error-utils.js';
|
|
9
9
|
import { resolveProjectDefaultPath } from '../../utils/project-path.js';
|
|
10
10
|
/** 决策判定用的系统提示词:把 state 与问题一起喂给通用模型,要求只回 JSON。 */
|
|
11
11
|
const DECISION_SYSTEM_PROMPT = 'Evaluate the provided state against each question and its criteria. '
|
|
@@ -75,6 +75,8 @@ async function completeServiceRequest(input) {
|
|
|
75
75
|
input.request.signal?.throwIfAborted();
|
|
76
76
|
if (error?.name === 'AbortError')
|
|
77
77
|
throw error;
|
|
78
|
+
if (errorQuestionRule(error))
|
|
79
|
+
throw error;
|
|
78
80
|
if (classifyError(error) !== ErrorType.MODEL_UNAVAILABLE && error?.status !== 404)
|
|
79
81
|
throw error;
|
|
80
82
|
if (!scheduler) {
|
|
@@ -68,12 +68,14 @@ function qrSvg(payload) {
|
|
|
68
68
|
export class EcwebInitializationService {
|
|
69
69
|
deps;
|
|
70
70
|
agentInitializer;
|
|
71
|
+
runtimeControlAid;
|
|
71
72
|
ownerRecoveryAt = new Map();
|
|
72
73
|
queue = Promise.resolve();
|
|
73
74
|
constructor(deps = {}) {
|
|
74
75
|
this.deps = deps;
|
|
75
76
|
}
|
|
76
77
|
setAgentInitializer(service) { this.agentInitializer = service; }
|
|
78
|
+
setRuntimeControlAid(aid) { this.runtimeControlAid = () => aid; }
|
|
77
79
|
exclusive(action) {
|
|
78
80
|
const result = this.queue.then(action);
|
|
79
81
|
this.queue = result.catch(() => undefined);
|
|
@@ -94,9 +96,10 @@ export class EcwebInitializationService {
|
|
|
94
96
|
fs.chmodSync(file, 0o600);
|
|
95
97
|
}
|
|
96
98
|
read(workflowId) {
|
|
97
|
-
const aid = this.deps.controlAid ? this.deps.controlAid()
|
|
99
|
+
const aid = this.deps.controlAid ? this.deps.controlAid()
|
|
100
|
+
: this.runtimeControlAid ? this.runtimeControlAid() : loadDaemonConfig().aid;
|
|
98
101
|
if (!aid || !isValidAid(aid))
|
|
99
|
-
fail('CONTROL_AID_NOT_READY', '
|
|
102
|
+
fail('CONTROL_AID_NOT_READY', '主机身份待准备,请在本机运行 ec init --web,准备身份并重启后继续', 409);
|
|
100
103
|
let state;
|
|
101
104
|
try {
|
|
102
105
|
state = atomicReadJson(this.file(workflowId));
|
|
@@ -125,7 +128,7 @@ export class EcwebInitializationService {
|
|
|
125
128
|
if (this.deps.refreshOwner)
|
|
126
129
|
return this.deps.refreshOwner(aid, { force });
|
|
127
130
|
const { ownerResolver, OWNERSHIP_AUTHORIZATION_MAX_AGE_MS } = await import('../ownership/owner-resolver.js');
|
|
128
|
-
return ownerResolver.refresh(aid, { force, maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, allowTransient:
|
|
131
|
+
return ownerResolver.refresh(aid, { force, maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, allowTransient: false, source });
|
|
129
132
|
}
|
|
130
133
|
async bind(aid, owner) {
|
|
131
134
|
if (this.deps.bindOwner)
|
|
@@ -134,7 +137,9 @@ export class EcwebInitializationService {
|
|
|
134
137
|
return ownerResolver.bind(aid, owner);
|
|
135
138
|
}
|
|
136
139
|
async verifiedOwner(state, force = true, source = 'initialization.operation') {
|
|
137
|
-
|
|
140
|
+
return this.applyVerifiedOwner(state, await this.ownership(state.controlAid, force, source));
|
|
141
|
+
}
|
|
142
|
+
applyVerifiedOwner(state, view) {
|
|
138
143
|
const owner = view.consensusStatus === 'consensus' && view.ownerAid && isValidAid(view.ownerAid)
|
|
139
144
|
&& view.ownerAid !== state.controlAid ? view.ownerAid : undefined;
|
|
140
145
|
if (owner && state.ownerAid && state.ownerAid !== owner)
|
|
@@ -209,7 +214,7 @@ export class EcwebInitializationService {
|
|
|
209
214
|
}
|
|
210
215
|
return defaults;
|
|
211
216
|
}
|
|
212
|
-
async view(state) {
|
|
217
|
+
async view(state, forceOwnership = false) {
|
|
213
218
|
if (state.creation && !state.agent) {
|
|
214
219
|
const { aid, name, project } = state.creation.plan;
|
|
215
220
|
state.agent = { aid, name, project };
|
|
@@ -240,13 +245,25 @@ export class EcwebInitializationService {
|
|
|
240
245
|
}
|
|
241
246
|
}
|
|
242
247
|
const bindingPending = !!state.binding?.ownerAid && ['pending', 'unknown'].includes(state.binding.status);
|
|
243
|
-
|
|
248
|
+
// Stable display polls can reuse valid consensus; pending binds need a fresh
|
|
249
|
+
// observation, and mutations retain their separate forced authorization.
|
|
250
|
+
const ownership = await this.ownership(state.controlAid, forceOwnership || bindingPending, bindingPending ? 'initialization.binding' : 'initialization.view');
|
|
251
|
+
const ownerAid = this.applyVerifiedOwner(state, ownership);
|
|
252
|
+
const pending = bindingPending || ['requesting', 'submitted'].includes(ownership.requestStatus ?? '')
|
|
253
|
+
|| (ownership.task?.operation === 'bind' && ownership.task.status === 'pending');
|
|
254
|
+
const ownershipStatus = ownerAid ? 'bound' : ownership.consensusStatus === 'single_sided' ? 'pending'
|
|
255
|
+
: ['unbound', 'released'].includes(ownership.consensusStatus) ? pending ? 'pending' : 'unbound' : 'unknown';
|
|
244
256
|
const binding = state.binding;
|
|
245
257
|
const scannable = binding?.status === 'created' && binding.expiresAt > this.now();
|
|
246
258
|
return {
|
|
247
259
|
status: state.step === 'ready' ? 'completed' : state.step === 'welcome' ? 'pending' : 'in_progress',
|
|
248
260
|
step: ownerAid ? state.step === 'welcome' || state.step === 'binding' ? 'configuration' : state.step : state.step === 'welcome' ? 'welcome' : 'binding',
|
|
249
261
|
controlAid: state.controlAid, ownerAid: ownerAid ?? null, updatedAt: state.updatedAt,
|
|
262
|
+
ownership: {
|
|
263
|
+
status: ownershipStatus, consensusStatus: ownership.consensusStatus,
|
|
264
|
+
code: ownership.refreshFailure?.code ?? null,
|
|
265
|
+
reason: ownership.refreshFailure?.reason ?? ownership.reason ?? null,
|
|
266
|
+
},
|
|
250
267
|
binding: binding ? {
|
|
251
268
|
id: binding.id, status: binding.status === 'bound' && !ownerAid ? 'unknown' : binding.status,
|
|
252
269
|
expiresAt: binding.expiresAt,
|
|
@@ -420,8 +437,14 @@ export class EcwebInitializationService {
|
|
|
420
437
|
return { status: 200, body: { success: true, data: await this.view(state) } };
|
|
421
438
|
}
|
|
422
439
|
if (input.method === 'POST' && (pathname === '/api/init/binding-sessions' || pathname === '/api/init/binding-sessions/refresh')) {
|
|
423
|
-
|
|
424
|
-
|
|
440
|
+
const data = await this.view(state, true);
|
|
441
|
+
const ownership = data.ownership;
|
|
442
|
+
if (ownership.status === 'bound')
|
|
443
|
+
return { status: 200, body: { success: true, data } };
|
|
444
|
+
if (ownership.status === 'unknown')
|
|
445
|
+
fail('OWNERSHIP_UNAVAILABLE', ownership.reason || '主机 Owner 状态暂时无法确认,请重试', 503);
|
|
446
|
+
if (ownership.status === 'pending')
|
|
447
|
+
return { status: 202, body: { success: true, data } };
|
|
425
448
|
if (state.binding?.ownerAid)
|
|
426
449
|
fail('BIND_PENDING', '绑定已提交,请先在 EVOL APP 确认并查询结果,不能重复创建', 409);
|
|
427
450
|
if (pathname.endsWith('/refresh') || !state.binding || state.binding.expiresAt <= this.now()) {
|
|
@@ -48,6 +48,7 @@ export class InteractionRouter {
|
|
|
48
48
|
const pending = {
|
|
49
49
|
blocking: opts?.blocking !== false,
|
|
50
50
|
retainOnRejected: opts?.retainOnRejected === true,
|
|
51
|
+
requireEncrypted: opts?.requireEncrypted === true,
|
|
51
52
|
callback,
|
|
52
53
|
sessionId,
|
|
53
54
|
initiatorId: opts?.initiatorId,
|
|
@@ -85,6 +86,8 @@ export class InteractionRouter {
|
|
|
85
86
|
const handler = this.handlers.get(response.id);
|
|
86
87
|
if (!handler)
|
|
87
88
|
return false;
|
|
89
|
+
if (handler.requireEncrypted && response.encrypted !== true)
|
|
90
|
+
return false;
|
|
88
91
|
// Initiator 校验(集中式 backstop):非发起者的操作直接丢弃,不消费 handler、不解除等待,
|
|
89
92
|
// 让真正的发起者仍可继续操作。身份只信渠道传入的已认证 operatorId(来自消息信封,非 payload 自报)。
|
|
90
93
|
// 渠道层若已自行校验(如飞书的 reject toast),此处不会重复命中(operatorId 已匹配)。
|