evolcore 0.0.47 → 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 +56 -1
- 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 +34 -17
- 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/service-proxy.js +4 -2
- package/dist/build-identity.json +1 -0
- package/dist/channels/aun.js +81 -24
- package/dist/channels/daemon.js +9 -25
- 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 +44 -43
- 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 +4 -6
- package/dist/cli/init.js +72 -50
- package/dist/cli/invoke-command.js +1 -1
- package/dist/cli/provider-command.js +74 -13
- package/dist/cli/role.js +61 -17
- package/dist/cli/stats.js +3 -3
- package/dist/cli/thread-command.js +16 -51
- package/dist/config/boot-log.js +3 -9
- package/dist/config/builtin-roles.js +5 -7
- package/dist/config/config-manager.js +2 -6
- 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 +62 -229
- package/dist/config/peer-book.js +26 -27
- package/dist/config/peer-role-resolver.js +16 -1
- package/dist/config/provider-identity-migration.js +4 -1
- 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 +105 -4
- package/dist/core/agent-application-service.js +6 -1
- package/dist/core/agent-runtime.js +4 -0
- package/dist/core/auth/agent-delegation.js +2 -1
- package/dist/core/auth/auth-gateway.js +2 -1
- package/dist/core/auth/delegation-authorization.js +3 -0
- package/dist/core/auth/operation-authorizer.js +25 -0
- 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 +61 -149
- 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 +26 -43
- 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 +8 -1
- package/dist/core/daemon-control.js +7 -7
- package/dist/core/evolagent-registry.js +14 -1
- package/dist/core/file-integrity/store.js +2 -0
- package/dist/core/handoff/runtime.js +37 -1
- package/dist/core/inference/text-inference.js +3 -1
- package/dist/core/initialization/service.js +11 -6
- package/dist/core/interaction-router.js +3 -0
- package/dist/core/invoke/executors/text.js +72 -19
- package/dist/core/ipc-registration.js +2 -1
- 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 +328 -50
- package/dist/core/permission/protected-paths.js +6 -6
- package/dist/core/relation/peer-identity.js +23 -1
- package/dist/core/relation/same-owner-proof.js +81 -112
- package/dist/core/session/adapters/codex-session-file-adapter.js +96 -15
- package/dist/core/session/session-file-health.js +13 -7
- 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-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 +18 -8
- package/dist/ecweb/runtime/proxy-access.js +74 -0
- package/dist/ecweb/runtime/supervisor.js +4 -2
- 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 +92 -59
- package/dist/ipc.js +13 -2
- 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 +7 -5
- package/dist/trigger/script-executor.js +2 -1
- package/dist/trigger/script-sandbox.js +9 -3
- package/dist/trigger/validation.js +22 -0
- package/dist/utils/cross-platform.js +73 -26
- package/dist/utils/error-dict.json +94 -4
- package/dist/utils/error-utils.js +27 -4
- package/dist/utils/evolcore-version.js +36 -65
- package/dist/utils/msg-diag.js +1 -0
- package/dist/utils/process-introspect.js +12 -7
- package/dist/utils/process-tree.js +50 -2
- 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/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 +123 -3
- 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
|
@@ -17,7 +17,8 @@ import { normalizeGroupAid, sameGroupAid } from '../../aun/group/identity.js';
|
|
|
17
17
|
import { resolveThreadRouteTarget } from '../thread/thread-route.js';
|
|
18
18
|
import { isTopicThreadId, parseMainTopicId, safeFormatMainTopicId, sessionLocalTopicId } from '../thread/topic-id.js';
|
|
19
19
|
import { ThreadService } from '../thread/thread-service.js';
|
|
20
|
-
import {
|
|
20
|
+
import { diagLog } from '../../utils/msg-diag.js';
|
|
21
|
+
import { buildEnvelope, DEFAULT_NOOP_SENTINEL } from './message-utils.js';
|
|
21
22
|
import { sessionTopicThreadId } from '../thread/topic-id.js';
|
|
22
23
|
import { getAunRequestRegistry, requestDiagnostics, requestTtlSeconds } from './aun-request-registry.js';
|
|
23
24
|
import { canonicalizeEvolcoreCommandArgv, parseJsonObjectArgument } from '../permission/ec-command-parser.js';
|
|
@@ -171,7 +172,9 @@ async function sendViaSessionAdapter(handoff, targetSession, instance, getOutbou
|
|
|
171
172
|
}
|
|
172
173
|
async function applyManagedCrossThreadSendEffects(input) {
|
|
173
174
|
const originSessionId = input.grant.sessionId;
|
|
174
|
-
const
|
|
175
|
+
const conversationId = input.runtime?.channelId;
|
|
176
|
+
const originPeer = conversationId && !/^(trigger|bg):/.test(conversationId)
|
|
177
|
+
? conversationId : parsePeerKey(input.grant.peerKey).channelId;
|
|
175
178
|
// 来源话题 id:话题用原 id;主话题用"本端+对端"拼出的规范 id(展示与持久化用)。
|
|
176
179
|
const originThreadId = isTopicThreadId(input.runtime?.threadId)
|
|
177
180
|
? input.runtime.threadId
|
|
@@ -188,6 +191,14 @@ async function applyManagedCrossThreadSendEffects(input) {
|
|
|
188
191
|
: ThreadService.findMainSessionEntry(input.selfAid, input.targetChannelId);
|
|
189
192
|
const originThreadName = originEntry?.name || (originThreadId || originPeer);
|
|
190
193
|
const originPeerName = originEntry?.peerName || originPeer;
|
|
194
|
+
// 来源话题对端的主体类型:运行时上下文是唯一来源;伪对端不写。
|
|
195
|
+
const originPeerType = (() => {
|
|
196
|
+
const type = String(input.runtime?.peerType ?? '').trim();
|
|
197
|
+
const peerId = String(input.runtime?.peerId ?? '');
|
|
198
|
+
if (!type || peerId.startsWith('trigger:') || peerId.startsWith('bg:'))
|
|
199
|
+
return undefined;
|
|
200
|
+
return type;
|
|
201
|
+
})();
|
|
191
202
|
const targetThreadName = targetEntry?.name || input.targetThreadId;
|
|
192
203
|
const targetPeerName = targetEntry?.peerName || input.targetChannelId;
|
|
193
204
|
const { buildCrossThreadReviewPrompt } = await import('../../cli/aun-commands.js');
|
|
@@ -205,44 +216,49 @@ async function applyManagedCrossThreadSendEffects(input) {
|
|
|
205
216
|
});
|
|
206
217
|
let createdTriggerId;
|
|
207
218
|
let triggerError;
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
:
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
219
|
+
// `--check-every none`:跳过 Trigger,只保留 inbox(「我发过」是事实,定时唤醒是可选项)。
|
|
220
|
+
if (input.durationMs !== undefined) {
|
|
221
|
+
try {
|
|
222
|
+
if (!input.createCrossThreadReviewTrigger)
|
|
223
|
+
throw new Error('cross-thread Trigger authorization is unavailable');
|
|
224
|
+
const { buildThreadCheckTrigger } = await import('../../cli/aun-commands.js');
|
|
225
|
+
const definition = buildThreadCheckTrigger({
|
|
226
|
+
agentAid: input.selfAid,
|
|
227
|
+
id: triggerId,
|
|
228
|
+
name: triggerName,
|
|
229
|
+
prompt,
|
|
230
|
+
everyMs: input.durationMs,
|
|
231
|
+
checkEvery: input.checkEveryLabel,
|
|
232
|
+
// 目标话题所属渠道:从话题索引取,取不到时按 AUN 主渠兜底(历史行为)。
|
|
233
|
+
// 硬写 AUN 会让飞书等渠道的目标话题把 Trigger 的 feedback.target 指向错渠道。
|
|
234
|
+
channelKey: targetEntry?.channelType
|
|
235
|
+
? formatChannelKey({ type: targetEntry.channelType, selfAID: input.selfAid, name: 'main' })
|
|
236
|
+
: formatChannelKey({ type: 'aun', selfAID: input.selfAid, name: 'main' }),
|
|
237
|
+
targetChannelId: input.targetChannelId,
|
|
238
|
+
targetThreadId: input.targetThreadId,
|
|
239
|
+
originThreadId,
|
|
240
|
+
originPeer,
|
|
241
|
+
feedbackChatType: input.feedbackChatType,
|
|
242
|
+
originalText: input.contentSummary,
|
|
243
|
+
firstSentAt: input.timestamp,
|
|
244
|
+
originThreadName,
|
|
245
|
+
originPeerName,
|
|
246
|
+
originPeerType,
|
|
247
|
+
targetThreadName,
|
|
248
|
+
});
|
|
249
|
+
const created = await input.createCrossThreadReviewTrigger({
|
|
250
|
+
agentAid: input.selfAid,
|
|
251
|
+
grant: input.grant,
|
|
252
|
+
definition,
|
|
253
|
+
});
|
|
254
|
+
createdTriggerId = created.id;
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
// 失败原因随发送回执返回给调用方:只打 daemon 日志时,CLI 照样显示"已投递",
|
|
258
|
+
// 复查静默缺失无人察觉(2026-10-20 firstSentAt 类型错误即如此)。
|
|
259
|
+
triggerError = error instanceof Error ? error.message : String(error);
|
|
260
|
+
console.warn(`⚠ Trigger 创建失败: ${triggerError}(inbox 仍会写入)`);
|
|
261
|
+
}
|
|
246
262
|
}
|
|
247
263
|
try {
|
|
248
264
|
ThreadService.appendInbox(input.selfAid, {
|
|
@@ -251,6 +267,9 @@ async function applyManagedCrossThreadSendEffects(input) {
|
|
|
251
267
|
timestamp: input.timestamp,
|
|
252
268
|
originThreadId,
|
|
253
269
|
originPeer,
|
|
270
|
+
// 显示名随条目落盘:渲染时不必再查话题索引,也保住了改名前的历史值。
|
|
271
|
+
...(originPeerName && originPeerName !== originPeer ? { originPeerName } : {}),
|
|
272
|
+
...(originPeerType ? { originPeerType } : {}),
|
|
254
273
|
originSessionId,
|
|
255
274
|
targetSessionId: input.targetSessionId,
|
|
256
275
|
...(createdTriggerId ? { triggerId: createdTriggerId } : {}),
|
|
@@ -379,6 +398,7 @@ async function deliverSelfAddressed(input) {
|
|
|
379
398
|
messageId: sent.message_id,
|
|
380
399
|
timestamp: sent.timestamp ?? Date.now(),
|
|
381
400
|
source: 'self-address',
|
|
401
|
+
selfAddressedMeta: { noopSentinel: DEFAULT_NOOP_SENTINEL },
|
|
382
402
|
encrypted: input.encrypted,
|
|
383
403
|
replyContext: {
|
|
384
404
|
threadId: sessionTopicThreadId(session) ?? undefined,
|
|
@@ -465,7 +485,7 @@ function targetTopicLabel(topicId) {
|
|
|
465
485
|
return 'main';
|
|
466
486
|
}
|
|
467
487
|
/** Resolve gateway options only from an authenticated task and local topic evidence. */
|
|
468
|
-
async function resolveGatewaySend(argv, grant, runtime) {
|
|
488
|
+
async function resolveGatewaySend(argv, grant, runtime, session) {
|
|
469
489
|
if (argv[1] !== 'send' || grant.channelType !== 'aun' || !runtime) {
|
|
470
490
|
throw new Error('An active AUN task is required for gateway sends');
|
|
471
491
|
}
|
|
@@ -473,12 +493,28 @@ async function resolveGatewaySend(argv, grant, runtime) {
|
|
|
473
493
|
if (!parsed.ok)
|
|
474
494
|
throw new Error(parsed.error);
|
|
475
495
|
const { route: options, text, passthrough } = parsed;
|
|
476
|
-
|
|
496
|
+
if (runtime.selfAid !== grant.selfAid || (runtime.sessionId && runtime.sessionId !== grant.sessionId)
|
|
497
|
+
|| session && (session.id !== grant.sessionId || session.selfAID !== grant.selfAid)) {
|
|
498
|
+
throw Object.assign(new Error('Current conversation does not match the delegated task'), { code: 'SCOPE_MISMATCH' });
|
|
499
|
+
}
|
|
500
|
+
// The grant identifies the authorizing actor. A target-session Trigger may
|
|
501
|
+
// run in another conversation, whose recipient and topic remain authoritative.
|
|
502
|
+
// Dedicated daemon Trigger sessions have no channel peer; preserve their
|
|
503
|
+
// origin-based send behavior. A target_session task has a real conversation.
|
|
504
|
+
const daemonSession = session?.channelType === 'daemon';
|
|
505
|
+
const currentPeer = daemonSession ? parsePeerKey(grant.peerKey).channelId : session?.channelId ?? runtime.channelId;
|
|
506
|
+
const currentChannelType = daemonSession ? grant.channelType : session?.channelType ?? runtime.channel;
|
|
507
|
+
const currentChatType = daemonSession ? grant.chatType : session?.chatType ?? runtime.chatType;
|
|
508
|
+
const currentThreadId = daemonSession ? undefined : session ? sessionTopicThreadId(session) : runtime.threadId;
|
|
509
|
+
if (!currentPeer || currentChannelType !== 'aun'
|
|
510
|
+
|| (currentChatType !== 'private' && currentChatType !== 'group')) {
|
|
511
|
+
throw Object.assign(new Error('Current AUN conversation route is unavailable'), { code: 'AUN_OUTBOUND_ROUTE_REQUIRED' });
|
|
512
|
+
}
|
|
477
513
|
const resolveKind = async (target) => {
|
|
478
514
|
if (normalizeAid(target) === normalizeAid(currentPeer))
|
|
479
|
-
return
|
|
515
|
+
return currentChatType;
|
|
480
516
|
if (normalizeAid(target) === normalizeAid(grant.selfAid))
|
|
481
|
-
return
|
|
517
|
+
return currentChatType;
|
|
482
518
|
const local = readAunPeerKind(grant.selfAid, target)?.kind;
|
|
483
519
|
if (local === 'private' || local === 'group')
|
|
484
520
|
return local;
|
|
@@ -522,8 +558,8 @@ async function resolveGatewaySend(argv, grant, runtime) {
|
|
|
522
558
|
encrypt: options.encrypt,
|
|
523
559
|
inboundTriggered: runtime.inboundEncrypted !== undefined,
|
|
524
560
|
inboundEncrypted: runtime.inboundEncrypted === true, }, {
|
|
525
|
-
selfAid: grant.selfAid, channelType:
|
|
526
|
-
peerId: currentPeer, threadId: isTopicThreadId(
|
|
561
|
+
selfAid: grant.selfAid, channelType: currentChannelType, chatType: currentChatType,
|
|
562
|
+
peerId: currentPeer, threadId: isTopicThreadId(currentThreadId) ? currentThreadId : undefined,
|
|
527
563
|
}, deps);
|
|
528
564
|
if (!route.ok)
|
|
529
565
|
throw Object.assign(new Error(route.message), { code: route.code });
|
|
@@ -564,7 +600,7 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
564
600
|
return request ? { ok: true, request: request }
|
|
565
601
|
: { ok: false, code: 'REQUEST_NOT_FOUND', error: `request not found: ${params.requestId}` };
|
|
566
602
|
});
|
|
567
|
-
const sender = async (params, inspectedGrant) => {
|
|
603
|
+
const sender = async (params, inspectedGrant, gatewayRoute) => {
|
|
568
604
|
let textFile;
|
|
569
605
|
let payloadFile;
|
|
570
606
|
try {
|
|
@@ -597,9 +633,13 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
597
633
|
}
|
|
598
634
|
const grant = authorization.grant;
|
|
599
635
|
if (params.argv[0] === MESSAGE_CLI_BIN) {
|
|
600
|
-
const
|
|
636
|
+
const session = sessionManager ? await sessionManager.getSessionById(params.originSessionId) : undefined;
|
|
637
|
+
if (sessionManager && !session) {
|
|
638
|
+
return { ok: false, code: 'AUN_OUTBOUND_ROUTE_REQUIRED', error: 'Current conversation session is unavailable', sent: false };
|
|
639
|
+
}
|
|
640
|
+
const resolved = await resolveGatewaySend(params.argv, grant, responseEngine.getTaskRuntimeContext(params.originSessionId), session);
|
|
601
641
|
// 只变更执行参数,审批仍绑定网关的原始命令;下游继续校验目标并消费一次审批。
|
|
602
|
-
const result = await sender({ ...params, argv: resolved.argv }, grant);
|
|
642
|
+
const result = await sender({ ...params, argv: resolved.argv }, grant, resolved.route);
|
|
603
643
|
return { ...result, send_route: resolved.route };
|
|
604
644
|
}
|
|
605
645
|
const command = resolveManagedSendArgv(params.argv, {
|
|
@@ -644,6 +684,12 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
644
684
|
// 跨话题自派(self-address):收件人是本端自己,话题归属仍是 (自端, 对端)。
|
|
645
685
|
// 此时 `params.to` 不是「话题对端」,不能拿它做话题一致性校验。
|
|
646
686
|
const selfAddressed = isSelfAidTarget(params.aid, params.to);
|
|
687
|
+
// The downstream argv intentionally omits same-topic --thread/--check-every.
|
|
688
|
+
// Restore the verified topic independently of the authorization relation;
|
|
689
|
+
// keeping checkEveryMs unset prevents another review Trigger.
|
|
690
|
+
if (gatewayRoute && !gatewayRoute.crossTopic && isTopicThreadId(gatewayRoute.threadId)) {
|
|
691
|
+
params.thread = gatewayRoute.threadId;
|
|
692
|
+
}
|
|
647
693
|
// 话题引用解析:`threadRef` 是调用方写的原值(可能是主话题 id),
|
|
648
694
|
// `threadRoute` 非空即"这是跨话题发送"——与话题 id 是否为空无关。
|
|
649
695
|
const threadRef = params.thread;
|
|
@@ -653,7 +699,9 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
653
699
|
if (threadRef && !threadRoute) {
|
|
654
700
|
return { ok: false, code: 'TOPIC_NOT_FOUND', error: `话题不存在或不属于目标对端: ${threadRef}` };
|
|
655
701
|
}
|
|
656
|
-
|
|
702
|
+
// Topic lookup also restores the current topic; cross-topic side effects
|
|
703
|
+
// must follow the verified route rather than the presence of a topic ID.
|
|
704
|
+
const threadRouted = !!threadRoute && (gatewayRoute?.crossTopic ?? true);
|
|
657
705
|
// 规范目标 id:话题保留原 id;主话题用双方拼出的规范形态(用于 Trigger 标签与通知)。
|
|
658
706
|
const targetTopicId = threadRoute
|
|
659
707
|
? (isTopicThreadId(threadRef)
|
|
@@ -669,6 +717,12 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
669
717
|
&& selfAddressed
|
|
670
718
|
&& params.scope === 'msg'
|
|
671
719
|
&& !params.originSessionId;
|
|
720
|
+
const grantPeerId = inspectedGrant ? parsePeerKey(inspectedGrant.peerKey).channelId : undefined;
|
|
721
|
+
const authorizationTargetRouted = threadRouted || !!gatewayRoute && !!inspectedGrant && !!grantPeerId && (gatewayRoute.peer.channelType !== inspectedGrant.channelType
|
|
722
|
+
|| gatewayRoute.peer.peerKind !== inspectedGrant.chatType
|
|
723
|
+
|| (gatewayRoute.peer.channelType === 'aun'
|
|
724
|
+
? normalizeAid(gatewayRoute.peer.id) !== normalizeAid(grantPeerId)
|
|
725
|
+
: gatewayRoute.peer.id !== grantPeerId));
|
|
672
726
|
const delegation = localSelfSend
|
|
673
727
|
? {
|
|
674
728
|
ok: true,
|
|
@@ -692,7 +746,7 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
692
746
|
to: params.to,
|
|
693
747
|
scope: params.scope,
|
|
694
748
|
action: params.file ? 'file' : 'send',
|
|
695
|
-
threadRouted:
|
|
749
|
+
threadRouted: authorizationTargetRouted,
|
|
696
750
|
isSystemEvent,
|
|
697
751
|
});
|
|
698
752
|
if (!delegation.ok) {
|
|
@@ -735,6 +789,20 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
735
789
|
&& !!runtime.channelId && (params.scope === 'group' ? sameGroupAid(runtime.channelId, params.to) : runtime.channelId === params.to);
|
|
736
790
|
params.thread = params.rawPayload === true ? params.thread : typeof params.payload?.thread_id === 'string' && params.payload.thread_id.trim()
|
|
737
791
|
? params.payload.thread_id.trim() : params.thread ?? (currentRelation ? runtime?.threadId : undefined);
|
|
792
|
+
if (gatewayRoute) {
|
|
793
|
+
const topicId = isTopicThreadId(params.thread) ? params.thread
|
|
794
|
+
: safeFormatMainTopicId(params.aid, gatewayRoute.peer.id);
|
|
795
|
+
const payloadThread = params.payload?.thread_id;
|
|
796
|
+
const expectedThread = isTopicThreadId(gatewayRoute.threadId) ? gatewayRoute.threadId : undefined;
|
|
797
|
+
if (params.aid !== gatewayRoute.self || params.to !== gatewayRoute.recipientId
|
|
798
|
+
|| params.scope !== (gatewayRoute.peer.peerKind === 'group' ? 'group' : 'msg')
|
|
799
|
+
|| topicId !== gatewayRoute.threadId
|
|
800
|
+
|| (payloadThread !== undefined && payloadThread !== expectedThread)) {
|
|
801
|
+
throw Object.assign(new Error('Message recipient or topic conflicts with the resolved send route'), {
|
|
802
|
+
code: 'AUN_OUTBOUND_ROUTE_MISMATCH',
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
}
|
|
738
806
|
}
|
|
739
807
|
catch (error) {
|
|
740
808
|
return {
|
|
@@ -925,6 +993,13 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
925
993
|
payload,
|
|
926
994
|
encrypt,
|
|
927
995
|
thread: params.thread,
|
|
996
|
+
...(gatewayRoute ? { expectedTarget: {
|
|
997
|
+
channelType: gatewayRoute.peer.channelType,
|
|
998
|
+
channelId: gatewayRoute.peer.id,
|
|
999
|
+
chatType: gatewayRoute.peer.peerKind,
|
|
1000
|
+
threadId: isTopicThreadId(gatewayRoute.threadId) ? gatewayRoute.threadId : undefined,
|
|
1001
|
+
...(threadRoute ? { sessionId: threadRoute.sessionId } : {}),
|
|
1002
|
+
} } : {}),
|
|
928
1003
|
targetChatType: params.scope === 'group' ? 'group' : 'private',
|
|
929
1004
|
// 目标会话可能属于别的渠道(如飞书话题):带上它自己的 channelKey,
|
|
930
1005
|
// 否则会按 AUN 主渠建会话,投递到错误的渠道。
|
|
@@ -942,7 +1017,8 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
942
1017
|
handoffContext: params.handoffContext,
|
|
943
1018
|
// 跨话题发送的目标侧上下文由话题链(thread-inbox)负责注入;
|
|
944
1019
|
// handoff 只管投递,回复时不再拼"本地发言"段。
|
|
945
|
-
|
|
1020
|
+
// `--check-every none` 也写 inbox(只是不建 Trigger),所以判据只看向量本身。
|
|
1021
|
+
threadRouted,
|
|
946
1022
|
originAuthorization: {
|
|
947
1023
|
actorId: delegation.grant.actorId,
|
|
948
1024
|
channelKey: delegation.grant.channel,
|
|
@@ -962,9 +1038,24 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
962
1038
|
handoff_id: created.handoff.handoff_id,
|
|
963
1039
|
target_session_id: created.targetSession.id,
|
|
964
1040
|
};
|
|
1041
|
+
// 跨话题走 handoff,不会进入下面的直发分支:诊断在这里单独补一对,
|
|
1042
|
+
// 用入队时刻记 aun_out,用 handoff 的目标 message_id(已投递时)记 send_ok。
|
|
1043
|
+
diagLog('aun_out', {
|
|
1044
|
+
aid: params.aid, from: params.aid, to: params.to,
|
|
1045
|
+
taskId: runtime?.taskId, sessionId: params.originSessionId,
|
|
1046
|
+
text: params.log?.content ?? classifyAunPayloadForLog(payload).content,
|
|
1047
|
+
});
|
|
1048
|
+
if (response.message_id) {
|
|
1049
|
+
diagLog('send_ok', {
|
|
1050
|
+
aid: params.aid, from: params.aid, to: params.to,
|
|
1051
|
+
taskId: runtime?.taskId, sessionId: params.originSessionId,
|
|
1052
|
+
msgId: response.message_id,
|
|
1053
|
+
text: params.log?.content ?? classifyAunPayloadForLog(payload).content,
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
965
1056
|
// 排队未投递(无 message_id)时也要写 inbox + 建复查:handoff 已不再
|
|
966
1057
|
// 承载目标侧上下文,跳过这里就会丢上下文。
|
|
967
|
-
if (threadRouted &&
|
|
1058
|
+
if (threadRouted && threadRoute) {
|
|
968
1059
|
const effects = await applyManagedCrossThreadSendEffects({
|
|
969
1060
|
runtime,
|
|
970
1061
|
selfAid: params.aid,
|
|
@@ -1005,10 +1096,22 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
1005
1096
|
}
|
|
1006
1097
|
}
|
|
1007
1098
|
const debug = await resolveOutboundDebug(sessionId => responseEngine.getOutboundDebug(sessionId), params.originSessionId);
|
|
1099
|
+
// 主动发送路径(ecmsg send / ec msg send / ec group send)不经过
|
|
1100
|
+
// deliverTextEntry,出站诊断需要在这里单独打点,否则 diag 里查不到 agent 手发的消息。
|
|
1101
|
+
const diagText = params.log?.content ?? classifyAunPayloadForLog(payload).content;
|
|
1102
|
+
const diagCommon = {
|
|
1103
|
+
aid: params.aid,
|
|
1104
|
+
from: params.aid,
|
|
1105
|
+
to: params.to,
|
|
1106
|
+
taskId: runtime?.taskId,
|
|
1107
|
+
sessionId: runtime?.sessionId ?? params.originSessionId,
|
|
1108
|
+
text: diagText,
|
|
1109
|
+
};
|
|
1008
1110
|
if (params.scope === 'group') {
|
|
1009
1111
|
if (typeof ch.sendDaemonGroupMsg !== 'function') {
|
|
1010
1112
|
return { ok: false, error: 'AUN channel does not support daemon group sends', code: 'AUN_GROUP_UNSUPPORTED' };
|
|
1011
1113
|
}
|
|
1114
|
+
diagLog('aun_out', diagCommon);
|
|
1012
1115
|
const sent = await ch.sendDaemonGroupMsg({
|
|
1013
1116
|
groupId: params.to,
|
|
1014
1117
|
payload,
|
|
@@ -1018,7 +1121,7 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
1018
1121
|
model: typeof debug?.model === 'string' ? debug.model : undefined,
|
|
1019
1122
|
log: params.log ? { ...params.log, sessionId: targetSessionId ?? params.log.sessionId } : undefined,
|
|
1020
1123
|
});
|
|
1021
|
-
if (
|
|
1124
|
+
if (threadRouted && params.thread && sent.ok && sent.message_id && threadRoute) {
|
|
1022
1125
|
const effects = await applyManagedCrossThreadSendEffects({
|
|
1023
1126
|
runtime,
|
|
1024
1127
|
selfAid: params.aid,
|
|
@@ -1040,11 +1143,14 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
1040
1143
|
if (effects.triggerError)
|
|
1041
1144
|
sent.trigger_error = effects.triggerError;
|
|
1042
1145
|
}
|
|
1146
|
+
if (sent.ok && sent.message_id)
|
|
1147
|
+
diagLog('send_ok', { ...diagCommon, msgId: sent.message_id });
|
|
1043
1148
|
return sent;
|
|
1044
1149
|
}
|
|
1045
1150
|
if (typeof ch.sendDaemonMsg !== 'function') {
|
|
1046
1151
|
return { ok: false, error: 'AUN channel does not support daemon private sends', code: 'AUN_MSG_UNSUPPORTED' };
|
|
1047
1152
|
}
|
|
1153
|
+
diagLog('aun_out', diagCommon);
|
|
1048
1154
|
const sent = await ch.sendDaemonMsg({
|
|
1049
1155
|
to: params.to,
|
|
1050
1156
|
deviceId: params.deviceId,
|
|
@@ -1057,6 +1163,10 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
1057
1163
|
model: typeof debug?.model === 'string' ? debug.model : undefined,
|
|
1058
1164
|
log: params.log ? { ...params.log, sessionId: targetSessionId ?? params.log.sessionId } : undefined,
|
|
1059
1165
|
});
|
|
1166
|
+
// send_ok 只看网关是否返回 message_id,与 aun_out 的差值即发送失败次数;
|
|
1167
|
+
// 放在各个 return 分支之前,request / self-addressed 路径也不会漏记。
|
|
1168
|
+
if (sent.ok && sent.message_id)
|
|
1169
|
+
diagLog('send_ok', { ...diagCommon, msgId: sent.message_id });
|
|
1060
1170
|
if (preparedRequest) {
|
|
1061
1171
|
if (!sent.ok || !sent.message_id) {
|
|
1062
1172
|
const transportError = sent.error || 'transport send failed';
|
|
@@ -1103,7 +1213,7 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
1103
1213
|
sent.self_session_id = delivered.sessionId;
|
|
1104
1214
|
return sent;
|
|
1105
1215
|
}
|
|
1106
|
-
if (
|
|
1216
|
+
if (threadRouted && params.thread && sent.ok && sent.message_id && threadRoute) {
|
|
1107
1217
|
const effects = await applyManagedCrossThreadSendEffects({
|
|
1108
1218
|
runtime,
|
|
1109
1219
|
selfAid: params.aid,
|
|
@@ -1163,7 +1163,7 @@ export class IMRenderer {
|
|
|
1163
1163
|
case 'compact':
|
|
1164
1164
|
return {
|
|
1165
1165
|
kind: 'notice',
|
|
1166
|
-
text:
|
|
1166
|
+
text: `会话压缩完成 (压缩前 tokens: ${event.preTokens})`,
|
|
1167
1167
|
severity: 'info',
|
|
1168
1168
|
subtype: 'compact',
|
|
1169
1169
|
};
|