evolcore 0.0.43-test.6 → 0.0.43-test.8
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 +95 -0
- package/bin/ecmsg.js +188 -58
- package/dist/agent-template/jobs.js +62 -0
- package/dist/agent-template/runtime.js +214 -0
- package/dist/agent-template/service.js +465 -0
- package/dist/agent-template/tool-runner.js +45 -0
- package/dist/agent-template/types.js +5 -0
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/claude-runner.js +1 -1
- package/dist/agents/codex/app-server-client.js +22 -0
- package/dist/agents/codex-runner.js +69 -2
- package/dist/aun/aid/agentmd.js +56 -1
- package/dist/aun/aid/client.js +3 -1
- package/dist/aun/menu/client.js +3 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/channels/aun.js +277 -49
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +7 -3
- package/dist/cli/agent-template.js +124 -0
- package/dist/cli/aun-commands.js +2 -2
- package/dist/cli/ctl-command.js +2 -1
- package/dist/cli/daemon-commands.js +11 -66
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +35 -2
- package/dist/cli/events-command.js +109 -0
- package/dist/cli/index.js +60 -14
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/net-check.js +1 -1
- package/dist/cli/restart-monitor.js +160 -83
- package/dist/cli/services-command.js +137 -0
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +103 -13
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/boot-log.js +8 -8
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +0 -7
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/schema-migration.js +45 -15
- package/dist/config-store.js +2 -1
- package/dist/core/agent-ipc-registration.js +25 -4
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +106 -10
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-authorizer.js +2 -0
- package/dist/core/auth/operation-catalog.js +29 -0
- package/dist/core/baseagent-loader.js +60 -130
- package/dist/core/channel-loader.js +10 -1
- package/dist/core/channel-runtime.js +20 -12
- package/dist/core/command/agent-control.js +12 -2
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/agent-template-menu.js +147 -0
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +80 -17
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +468 -0
- package/dist/core/command/menu-catalog.js +15 -0
- package/dist/core/command/menu-handler.js +216 -90
- package/dist/core/command/menu-protocol.js +71 -13
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +34 -42
- package/dist/core/command/team-workspace-bootstrap.js +350 -0
- package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
- package/dist/core/command/team-workspace-initializer.js +2 -0
- package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
- package/dist/core/command/team-workspace-job-store.js +88 -0
- package/dist/core/command/team-workspace-management-service.js +2 -0
- package/dist/core/command/team-workspace-management-store.js +96 -0
- package/dist/core/command/team-workspace-management.js +265 -0
- package/dist/core/command/team-workspace-members-menu.js +88 -0
- package/dist/core/command/team-workspace-store.js +612 -0
- package/dist/core/command/team-workspace-team.js +193 -0
- package/dist/core/daemon-control.js +22 -5
- package/dist/core/daemon-lifecycle.js +323 -191
- package/dist/core/handoff/runtime.js +45 -13
- package/dist/core/invoke/executors/index.js +13 -0
- package/dist/core/invoke/executors/media.js +283 -0
- package/dist/core/invoke/executors/text.js +198 -0
- package/dist/core/invoke/invoke-service.js +157 -0
- package/dist/core/invoke/style-router.js +48 -0
- package/dist/core/invoke/types.js +19 -0
- package/dist/core/ipc-registration.js +50 -7
- package/dist/core/legacy-rename.js +41 -0
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +252 -17
- package/dist/core/message/im-renderer.js +116 -85
- package/dist/core/message/message-bridge.js +4 -0
- package/dist/core/message/message-queue.js +66 -15
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/pending-hints.js +29 -5
- package/dist/core/message/response-engine.js +194 -61
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +50 -5
- package/dist/core/ownership/owner-resolver.js +7 -0
- package/dist/core/pack-auth.js +94 -0
- package/dist/core/pack-install.js +194 -0
- package/dist/core/permission/ec-command-parser.js +51 -17
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/rate-window.js +48 -0
- package/dist/core/relation/peer-identity.js +28 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +67 -28
- package/dist/core/session/session-idle-monitor.js +59 -19
- package/dist/core/session/session-manager.js +13 -4
- package/dist/core/task/task-recovery-service.js +13 -2
- package/dist/core/thread/command-parser.js +9 -2
- package/dist/core/thread/thread-operation.js +21 -2
- package/dist/core/thread/thread-route.js +13 -2
- package/dist/core/thread/thread-service.js +52 -3
- package/dist/directory/owner-directory-admission.js +40 -53
- package/dist/directory/owner-directory-cache.js +89 -113
- package/dist/directory/owner-directory-query-operation.js +8 -10
- package/dist/eck/kit-renderer.js +7 -5
- package/dist/eck/message-renderer.js +2 -0
- package/dist/ecweb/basic-settings-service.js +1 -1
- package/dist/ecweb/message-context-service.js +0 -4
- package/dist/ecweb/runtime/lifecycle.js +6 -2
- package/dist/ecweb/runtime/supervisor.js +19 -4
- package/dist/event-center/admission-materializer.js +124 -0
- package/dist/event-center/bus-gate.js +154 -0
- package/dist/event-center/bus-host.js +307 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +127 -0
- package/dist/event-center/daemon.js +44 -0
- package/dist/event-center/directory-source.js +55 -0
- package/dist/event-center/dispatcher.js +157 -0
- package/dist/event-center/event-log.js +110 -0
- package/dist/event-center/index-generator.js +73 -0
- package/dist/event-center/ipc-operation.js +423 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +207 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +463 -0
- package/dist/event-center/runtime.js +837 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +51 -0
- package/dist/event-center/validation.js +435 -0
- package/dist/index.js +424 -135
- package/dist/ipc.js +106 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +5 -1
- package/dist/proxy/service-supervisor.js +13 -4
- package/dist/response-system/engines/v1/index.js +0 -1
- package/dist/response-system/engines/v1/proactive-flow.js +4 -2
- package/dist/response-system/modes/single-session/index.js +1 -1
- package/dist/services/dispatcher.js +100 -0
- package/dist/services/idempotency.js +90 -0
- package/dist/services/identity.js +52 -0
- package/dist/services/index-generator.js +70 -0
- package/dist/services/index.js +449 -0
- package/dist/services/ipc-operation.js +550 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +215 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +98 -0
- package/dist/services/script-runner.js +422 -0
- package/dist/services/service-payload.js +70 -0
- package/dist/services/types.js +18 -0
- package/dist/services/validation.js +297 -0
- package/dist/trigger/application-service.js +18 -0
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/scheduler.js +38 -0
- package/dist/trigger/script-sandbox.js +170 -24
- package/dist/utils/cross-platform.js +24 -10
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +6 -3
- package/dist/utils/process-introspect.js +45 -9
- package/dist/utils/startup-trace.js +74 -37
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +9 -15
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +3 -1
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/agent.md +22 -1
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/event-center.md +227 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +5 -3
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-protocol.md +28 -1
- package/kits/docs/evolcore/msg.md +21 -9
- package/kits/docs/evolcore/provider.md +3 -1
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +294 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/docs/evolcore/thread-chain.md +15 -3
- package/kits/eck_manifest.json +26 -0
- package/kits/rules/02-navigation.md +10 -1
- package/kits/rules/06-channel.md +1 -0
- package/kits/schemas/_meta.json +17 -6
- package/kits/schemas/agent-config.schema.19.json +5 -7
- package/kits/schemas/agent-config.schema.20.json +936 -0
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/skills/.switches.json +1 -5
- package/kits/skills/ability/SKILL.md +56 -0
- package/kits/skills/ability/references/calling.md +56 -0
- package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
- package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
- package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
- package/kits/skills/ec-agent-create/SKILL.md +0 -1
- package/kits/skills/ec-group/SKILL.md +5 -8
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/personal-assistant/SKILL.md +6 -6
- package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
- package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
- package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
- package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/message-fragments/item.md +1 -1
- package/kits/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/reply.md +1 -5
- package/kits/templates/system-fragments/thread.md +13 -10
- package/package.json +5 -6
- package/scripts/agent-template/index.mjs +40 -0
- package/scripts/agent-template/inspect.mjs +240 -0
- package/scripts/agent-template/overlay.mjs +71 -0
- package/scripts/agent-template/pack.mjs +169 -0
- package/scripts/agent-template/shared/common.mjs +235 -0
- package/scripts/agent-template/shared/evolcore.mjs +75 -0
- package/scripts/agent-template/shared/plan.mjs +129 -0
- package/scripts/agent-template/shared/team-schema.json +70 -0
- package/scripts/agent-template/shared/template-contract.mjs +154 -0
- package/scripts/agent-template/shared/template-package.mjs +265 -0
- package/scripts/agent-template/shared/template-runtime.mjs +80 -0
- package/scripts/agent-template/shared/template.mjs +142 -0
- package/dist/cli/pa-workspace-command.js +0 -225
- package/dist/core/command/pa-workspace-store.js +0 -468
- package/dist/core/relation/pa-team.js +0 -132
- package/kits/docs/evolcore/pa-workspace.md +0 -51
- package/kits/skills/aid-ability/SKILL.md +0 -244
- package/kits/skills/ec-ability/SKILL.md +0 -67
- package/kits/skills/ec-ability/references/workflows.md +0 -15
|
@@ -20,8 +20,22 @@ import { buildEnvelope } from './message-utils.js';
|
|
|
20
20
|
import { sessionTopicThreadId } from '../thread/topic-id.js';
|
|
21
21
|
import { getAunRequestRegistry, requestDiagnostics, requestTtlSeconds } from './aun-request-registry.js';
|
|
22
22
|
import { parseJsonObjectArgument } from '../permission/ec-command-parser.js';
|
|
23
|
-
import { parsePeerKey } from '../relation/peer-identity.js';
|
|
23
|
+
import { formatPeerKey, parsePeerKey } from '../relation/peer-identity.js';
|
|
24
|
+
import { logger } from '../../utils/logger.js';
|
|
24
25
|
const TASK_ID_MESSAGE_PAYLOAD_TYPES = new Set(['text', 'link', 'image', 'video', 'voice', 'file']);
|
|
26
|
+
function normalizeAid(value) {
|
|
27
|
+
return String(value ?? '').trim().replace(/^@/, '').toLowerCase();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 是否为「发给自己的本端 AID」(self-address)。
|
|
31
|
+
*
|
|
32
|
+
* 不是跨主体通讯,因此不适用联系人准入,也不能拿它做话题对端的一致性校验。
|
|
33
|
+
*/
|
|
34
|
+
function isSelfAidTarget(selfAid, targetAid) {
|
|
35
|
+
const self = normalizeAid(selfAid);
|
|
36
|
+
const target = normalizeAid(targetAid);
|
|
37
|
+
return !!self && !!target && self === target;
|
|
38
|
+
}
|
|
25
39
|
/** payload.debug 只是诊断字段:取不到时照常发送,不带 debug。 */
|
|
26
40
|
async function resolveOutboundDebug(resolver, sessionId) {
|
|
27
41
|
if (!resolver || !sessionId)
|
|
@@ -248,6 +262,172 @@ async function applyManagedCrossThreadSendEffects(input) {
|
|
|
248
262
|
* targetThreadId 里。主话题 id 含两个完整 AID 与冒号,塞进名称又长又难读,
|
|
249
263
|
* 统一缩成 `main`。
|
|
250
264
|
*/
|
|
265
|
+
/**
|
|
266
|
+
* 跨话题自派(self-address):把刚刚发给自己那条消息,直接投进话题 T 所属的会话队列。
|
|
267
|
+
*
|
|
268
|
+
* 三条不变量:
|
|
269
|
+
* 1. **落点由话题索引决定,不由 `to` 决定**。`to` 是本端自己,用它算会话会落到
|
|
270
|
+
* 「我↔我」的目录;真实对端在话题条目里。
|
|
271
|
+
* 2. **`messageId` 复用 AUN 返回的 `message_id`**,跨设备与重启重放天然同键,
|
|
272
|
+
* 队列去重与 `claimInboundMessage` 都能生效。
|
|
273
|
+
* 3. **失败不抛**:AUN 那一跳已经把消息发出去了,本地投递失败只能作为
|
|
274
|
+
* `self_delivery_error` 回报,不能把「已发送」变成「发送失败」。
|
|
275
|
+
*/
|
|
276
|
+
/**
|
|
277
|
+
* 跨话题自派的派活指令只进本机队列,对端在 App 里看不到。这里补一条普通消息
|
|
278
|
+
* 给话题对端,让对话里能看到「我给自己派了什么」;正文完整,首行标明这是
|
|
279
|
+
* 本端给自己派的任务,不带图标。失败只告警——任务已经入队,通知不该反过来
|
|
280
|
+
* 影响投递。
|
|
281
|
+
*/
|
|
282
|
+
async function sendSelfDispatchNotice(input) {
|
|
283
|
+
const instance = input.channelInstances.find(candidate => (candidate.adapter.channelKey === input.session.metadata?.channelKey
|
|
284
|
+
|| candidate.adapter.channelName === input.session.channel));
|
|
285
|
+
const channel = instance?.channel;
|
|
286
|
+
if (!channel || typeof channel.sendDaemonMsg !== 'function') {
|
|
287
|
+
logger.warn('[AUN] self-dispatch notice skipped: AUN channel instance not found');
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
// 对端是人类就发普通文本,App 直接当消息渲染;对端是 agent 就发 notice,
|
|
291
|
+
// 避免把「跨话题自派」当成一条要它执行的聊天消息。
|
|
292
|
+
let peerType = input.peerType;
|
|
293
|
+
if (!peerType && typeof channel.fetchPeerInfo === 'function') {
|
|
294
|
+
try {
|
|
295
|
+
peerType = (await channel.fetchPeerInfo(input.to))?.type ?? undefined;
|
|
296
|
+
}
|
|
297
|
+
catch { /* 类型解析失败按非人类处理,宁可发 notice */ }
|
|
298
|
+
}
|
|
299
|
+
const selfName = typeof channel.getSelfName === 'function'
|
|
300
|
+
? String(channel.getSelfName() || '').trim() : '';
|
|
301
|
+
const text = `${selfName ? `${selfName} 给自己派了一个任务:` : '自己给自己派了一个任务:'}\n${input.text}`;
|
|
302
|
+
const isHuman = peerType === 'human';
|
|
303
|
+
const payload = isHuman
|
|
304
|
+
? { type: 'text', text }
|
|
305
|
+
: { type: 'notice', subtype: 'self_dispatch', severity: 'info', text };
|
|
306
|
+
if (input.threadId)
|
|
307
|
+
payload.thread_id = input.threadId;
|
|
308
|
+
try {
|
|
309
|
+
const result = await channel.sendDaemonMsg({
|
|
310
|
+
to: input.to,
|
|
311
|
+
payload,
|
|
312
|
+
...(typeof input.encrypted === 'boolean' ? { encrypt: input.encrypted } : {}),
|
|
313
|
+
log: {
|
|
314
|
+
content: text,
|
|
315
|
+
sessionId: input.sessionId,
|
|
316
|
+
threadId: input.threadId ?? null,
|
|
317
|
+
msgType: 'text',
|
|
318
|
+
payloadType: isHuman ? 'text' : 'notice',
|
|
319
|
+
source: 'msg',
|
|
320
|
+
},
|
|
321
|
+
});
|
|
322
|
+
if (result && result.ok === false) {
|
|
323
|
+
logger.warn(`[AUN] self-dispatch notice failed: ${result.error ?? 'unknown'}`);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
catch (error) {
|
|
327
|
+
logger.warn(`[AUN] self-dispatch notice failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
async function deliverSelfAddressed(input) {
|
|
331
|
+
const { params, sent, threadRoute } = input;
|
|
332
|
+
if (!sent.ok)
|
|
333
|
+
return { deliveryError: 'transport send failed' };
|
|
334
|
+
if (!threadRoute)
|
|
335
|
+
return { deliveryError: 'topic index entry is unavailable' };
|
|
336
|
+
if (!input.sessionManager || !input.messageQueue) {
|
|
337
|
+
return { deliveryError: 'self-address delivery is not configured' };
|
|
338
|
+
}
|
|
339
|
+
let session;
|
|
340
|
+
try {
|
|
341
|
+
session = await input.sessionManager.getSessionById(threadRoute.sessionId);
|
|
342
|
+
}
|
|
343
|
+
catch (error) {
|
|
344
|
+
return { deliveryError: `session lookup failed: ${error instanceof Error ? error.message : String(error)}` };
|
|
345
|
+
}
|
|
346
|
+
if (!session)
|
|
347
|
+
return { deliveryError: `target session not found: ${threadRoute.sessionId}` };
|
|
348
|
+
// 跨话题自派仍然是「(本端, 话题对端) 这个话题里」的内部任务,消息对端必须保持
|
|
349
|
+
// 话题对端。写成自己会让会话元数据、回复目标和角色解析全部指向本端:话题显示
|
|
350
|
+
// 成「我↔我」、回复无处可投(静默丢失)、权限从话题对端漂移。
|
|
351
|
+
// 「这是我自己派的活」由 source=self-address 表达,渲染层据此在信封头署名本端。
|
|
352
|
+
const topicPeerId = String(session.channelId || '').trim() || params.to;
|
|
353
|
+
const storedPeerName = String(session.metadata?.peerName || '').trim();
|
|
354
|
+
const topicPeerName = storedPeerName && storedPeerName !== params.aid ? storedPeerName : topicPeerId;
|
|
355
|
+
const topicPeerType = String(session.metadata?.peerType || '').trim() || undefined;
|
|
356
|
+
const message = {
|
|
357
|
+
channel: session.channel,
|
|
358
|
+
channelType: session.channelType,
|
|
359
|
+
channelId: session.channelId,
|
|
360
|
+
selfAID: params.aid,
|
|
361
|
+
baseagent: session.baseagent,
|
|
362
|
+
threadId: sessionTopicThreadId(session) ?? '',
|
|
363
|
+
chatType: session.chatType === 'group' ? 'group' : 'private',
|
|
364
|
+
peerId: topicPeerId,
|
|
365
|
+
peerName: topicPeerName,
|
|
366
|
+
...(topicPeerType ? { peerType: topicPeerType } : {}),
|
|
367
|
+
content: input.content,
|
|
368
|
+
messageId: sent.message_id,
|
|
369
|
+
timestamp: sent.timestamp ?? Date.now(),
|
|
370
|
+
source: 'self-address',
|
|
371
|
+
encrypted: input.encrypted,
|
|
372
|
+
replyContext: {
|
|
373
|
+
threadId: sessionTopicThreadId(session) ?? undefined,
|
|
374
|
+
sessionId: session.id,
|
|
375
|
+
},
|
|
376
|
+
...(session.chatType === 'group' ? { groupId: session.channelId } : {}),
|
|
377
|
+
};
|
|
378
|
+
// 信封头的对端角色必须取话题对端:缺省时队列按 message.peerId(本端)算成
|
|
379
|
+
// visitor,与任务实际以 owner 权限运行矛盾,模型会误判自己没有权限。
|
|
380
|
+
let enqueueRole;
|
|
381
|
+
if (session.chatType !== 'group') {
|
|
382
|
+
try {
|
|
383
|
+
const { resolvePeerRoleDetail } = await import('../../config/peer-role-resolver.js');
|
|
384
|
+
enqueueRole = resolvePeerRoleDetail({
|
|
385
|
+
selfAid: params.aid,
|
|
386
|
+
channelKey: session.channel,
|
|
387
|
+
channelType: 'aun',
|
|
388
|
+
chatType: 'private',
|
|
389
|
+
actorId: session.channelId,
|
|
390
|
+
conversationId: session.channelId,
|
|
391
|
+
peerType: undefined,
|
|
392
|
+
}).effectiveRole ?? undefined;
|
|
393
|
+
}
|
|
394
|
+
catch {
|
|
395
|
+
// 角色解析失败按缺省处理,不影响投递。
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
try {
|
|
399
|
+
await input.messageQueue.enqueue(session.id, message, session.projectPath, {
|
|
400
|
+
interruptible: false,
|
|
401
|
+
agentName: params.aid,
|
|
402
|
+
...(enqueueRole ? { role: enqueueRole } : {}),
|
|
403
|
+
sessionKeyField: session.sessionKey,
|
|
404
|
+
selfAID: params.aid,
|
|
405
|
+
// 入队即返回:调用方(CLI)不需要等模型跑完,回执只表达「已投递」。
|
|
406
|
+
resolveOnPersist: true,
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
catch (error) {
|
|
410
|
+
return { deliveryError: `enqueue failed: ${error instanceof Error ? error.message : String(error)}` };
|
|
411
|
+
}
|
|
412
|
+
// 不写本机入站历史:这条记录的 from 是本端,客户端会把「本端 → 本端」当成
|
|
413
|
+
// 一条独立会话(App 里表现为同一话题出现两个对话:一个正常的对端会话,一个
|
|
414
|
+
// 「自己与自己」)。派活指令本身已经在队列里;对端可见副本由下面的
|
|
415
|
+
// sendSelfDispatchNotice 负责,历史里也由它那条出站记录表达。
|
|
416
|
+
// 派活指令本身只在本机队列;给话题对端补一条可见副本(App 里能看到)。
|
|
417
|
+
if (input.channelInstances && input.channelInstances.length > 0) {
|
|
418
|
+
await sendSelfDispatchNotice({
|
|
419
|
+
channelInstances: input.channelInstances,
|
|
420
|
+
session,
|
|
421
|
+
to: topicPeerId,
|
|
422
|
+
peerType: topicPeerType,
|
|
423
|
+
threadId: sessionTopicThreadId(session),
|
|
424
|
+
text: input.content,
|
|
425
|
+
encrypted: input.encrypted,
|
|
426
|
+
sessionId: session.id,
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
return { sessionId: session.id };
|
|
430
|
+
}
|
|
251
431
|
function targetTopicLabel(topicId) {
|
|
252
432
|
if (!topicId)
|
|
253
433
|
return 'unknown';
|
|
@@ -256,7 +436,7 @@ function targetTopicLabel(topicId) {
|
|
|
256
436
|
return topicId;
|
|
257
437
|
return 'main';
|
|
258
438
|
}
|
|
259
|
-
export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegationRegistry, responseEngine, handoffRuntime, sessionManager, createCrossThreadReviewTrigger, }) {
|
|
439
|
+
export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegationRegistry, responseEngine, handoffRuntime, sessionManager, messageQueue, createCrossThreadReviewTrigger, }) {
|
|
260
440
|
ipcServer.setAunRequestGetExecutor(async (params) => {
|
|
261
441
|
if (!params.sessionId || !params.delegationToken) {
|
|
262
442
|
return { ok: false, code: 'DELEGATION_REQUIRED', error: 'Request queries require an active delegated session' };
|
|
@@ -361,11 +541,14 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
361
541
|
}
|
|
362
542
|
}
|
|
363
543
|
const runtimeCausation = runtime?.causation;
|
|
544
|
+
// 跨话题自派(self-address):收件人是本端自己,话题归属仍是 (自端, 对端)。
|
|
545
|
+
// 此时 `params.to` 不是「话题对端」,不能拿它做话题一致性校验。
|
|
546
|
+
const selfAddressed = isSelfAidTarget(params.aid, params.to);
|
|
364
547
|
// 话题引用解析:`threadRef` 是调用方写的原值(可能是主话题 id),
|
|
365
548
|
// `threadRoute` 非空即"这是跨话题发送"——与话题 id 是否为空无关。
|
|
366
549
|
const threadRef = params.thread;
|
|
367
550
|
const threadRoute = threadRef
|
|
368
|
-
? resolveThreadRouteTarget(params.aid, threadRef, params.scope, params.to)
|
|
551
|
+
? resolveThreadRouteTarget(params.aid, threadRef, params.scope, params.to, { allowSelfTarget: selfAddressed })
|
|
369
552
|
: undefined;
|
|
370
553
|
if (threadRef && !threadRoute) {
|
|
371
554
|
return { ok: false, code: 'TOPIC_NOT_FOUND', error: `话题不存在或不属于目标对端: ${threadRef}` };
|
|
@@ -379,18 +562,39 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
379
562
|
: undefined;
|
|
380
563
|
const isSystemEvent = params.trustedSystemEvent === true
|
|
381
564
|
&& params.payload?.type === 'event' && params.payload.event === 'topic.renamed';
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
565
|
+
// 非托管跨话题自派:调用方没有委托凭证,用本机 controlToken 证明「本机控制面调用」。
|
|
566
|
+
// 只有「跨话题自派 + 会话级 msg 发送」走这条,其余(含一切发给对端的发送)仍必须走委托链。
|
|
567
|
+
const localSelfSend = !isSystemEvent
|
|
568
|
+
&& params.localControl === true
|
|
569
|
+
&& selfAddressed
|
|
570
|
+
&& params.scope === 'msg'
|
|
571
|
+
&& !params.originSessionId;
|
|
572
|
+
const delegation = localSelfSend
|
|
573
|
+
? {
|
|
574
|
+
ok: true,
|
|
575
|
+
// 跨话题自派不需要「来源会话→目标关系」的授权:本机控制面就是本端自身。
|
|
576
|
+
grant: {
|
|
577
|
+
selfAid: params.aid,
|
|
578
|
+
actorId: params.aid,
|
|
579
|
+
channel: formatChannelKey({ type: 'aun', selfAID: params.aid, name: 'main' }),
|
|
580
|
+
channelType: 'aun',
|
|
581
|
+
chatType: 'private',
|
|
582
|
+
peerKey: formatPeerKey('aun', params.aid),
|
|
583
|
+
sessionId: '',
|
|
584
|
+
},
|
|
585
|
+
}
|
|
586
|
+
: await authorizeDelegatedAunMsgSend(agentDelegationRegistry, {
|
|
587
|
+
delegationToken: params.delegationToken,
|
|
588
|
+
delegationCommandHash: params.delegationCommandHash,
|
|
589
|
+
sessionId: params.originSessionId,
|
|
590
|
+
messageId: params.originMessageId,
|
|
591
|
+
aid: params.aid,
|
|
592
|
+
to: params.to,
|
|
593
|
+
scope: params.scope,
|
|
594
|
+
action: params.file ? 'file' : 'send',
|
|
595
|
+
threadRouted: !!threadRoute,
|
|
596
|
+
isSystemEvent,
|
|
597
|
+
});
|
|
394
598
|
if (!delegation.ok) {
|
|
395
599
|
return {
|
|
396
600
|
ok: false,
|
|
@@ -457,7 +661,10 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
457
661
|
if (!ch) {
|
|
458
662
|
return { ok: false, error: `AUN channel not found for ${params.aid}`, code: 'AUN_CHANNEL_NOT_FOUND' };
|
|
459
663
|
}
|
|
460
|
-
|
|
664
|
+
// 跨话题自派(`--to <本端AID>`):收件人就是自己,不属于跨主体通讯,跳过联系人准入。
|
|
665
|
+
// 不放进 evaluateAppContactAdmission 内部:那是通用准入判定,其它调用方
|
|
666
|
+
// (入站、handoff 等)也用它,在函数内开口子会扩散到所有路径。
|
|
667
|
+
if (params.scope === 'msg' && !isSelfAidTarget(params.aid, params.to)) {
|
|
461
668
|
const admission = await evaluateOutboundContactAdmission({ selfAid: params.aid, targetAid: params.to });
|
|
462
669
|
if (!admission.allow) {
|
|
463
670
|
const decision = evaluateAppContactAdmission(params.aid, params.to);
|
|
@@ -566,6 +773,11 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
566
773
|
if (params.rawPayload !== true && isTopicThreadId(params.thread) && typeof payload.thread_id !== 'string') {
|
|
567
774
|
payload = { ...payload, thread_id: params.thread };
|
|
568
775
|
}
|
|
776
|
+
// 跨话题自派:在线上载荷显式打标。客户端(尤其观察者转发/入站解析)不必只靠
|
|
777
|
+
// `from == to` 推断,可直接认这个字段;同 AID 的其它设备也据此区分「自己派给自己」。
|
|
778
|
+
if (selfAddressed && params.rawPayload !== true) {
|
|
779
|
+
payload = { ...payload, self_dispatch: true };
|
|
780
|
+
}
|
|
569
781
|
let preparedRequest;
|
|
570
782
|
let requestTtl;
|
|
571
783
|
if (params.scope === 'msg' && params.returnPolicy === 'required') {
|
|
@@ -600,7 +812,10 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
600
812
|
getAunRequestRegistry().markSending(params.aid, preparedRequest.requestId);
|
|
601
813
|
}
|
|
602
814
|
let targetSessionId;
|
|
603
|
-
|
|
815
|
+
// 跨话题自派一律跳过 handoff:目标会话是按话题索引解析出的 (自端, 对端) 会话,
|
|
816
|
+
// 而 handoff 用 `to`(=本端)作为 channelId 去 getOrCreateSession,会建出
|
|
817
|
+
// 「我↔我」的错误会话目录。话题内与跨话题同此处理(D14)。
|
|
818
|
+
if (!selfAddressed && params.originSessionId && params.originMessageId && params.returnPolicy !== 'required') {
|
|
604
819
|
try {
|
|
605
820
|
const created = await handoffRuntime.createOutbound({
|
|
606
821
|
selfAid: params.aid,
|
|
@@ -766,6 +981,26 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
766
981
|
...(completed ? { request_diagnostics: requestDiagnostics(completed) } : {}),
|
|
767
982
|
};
|
|
768
983
|
}
|
|
984
|
+
// 跨话题自派:AUN 那一跳只负责让同 AID 的其它设备看到这条消息,本机不会再收到
|
|
985
|
+
// 回环(SDK 按设备屏蔽 self-sync;即便收到也会被 AID 级身份过滤丢弃)。
|
|
986
|
+
// 「自己处理这条任务」必须由这里直接入队,落点是话题 T 所属的会话。
|
|
987
|
+
if (selfAddressed) {
|
|
988
|
+
const delivered = await deliverSelfAddressed({
|
|
989
|
+
params,
|
|
990
|
+
sent,
|
|
991
|
+
threadRoute,
|
|
992
|
+
sessionManager,
|
|
993
|
+
messageQueue,
|
|
994
|
+
channelInstances,
|
|
995
|
+
content: params.log?.content ?? classifyAunPayloadForLog(payload).content,
|
|
996
|
+
encrypted: encrypt,
|
|
997
|
+
});
|
|
998
|
+
if (delivered.deliveryError)
|
|
999
|
+
sent.self_delivery_error = delivered.deliveryError;
|
|
1000
|
+
if (delivered.sessionId)
|
|
1001
|
+
sent.self_session_id = delivered.sessionId;
|
|
1002
|
+
return sent;
|
|
1003
|
+
}
|
|
769
1004
|
if (params.thread && params.checkEveryMs !== undefined && sent.ok && sent.message_id && threadRoute) {
|
|
770
1005
|
const effects = await applyManagedCrossThreadSendEffects({
|
|
771
1006
|
runtime,
|