evolcore 0.0.43-test.1 → 0.0.43-test.3
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 +31 -1
- package/README.md +22 -0
- package/dist/agents/claude-runner.js +26 -2
- package/dist/agents/codex/app-server-client.js +12 -0
- package/dist/agents/codex-runner.js +49 -8
- package/dist/agents/ecagent-runner.js +39 -15
- package/dist/agents/gemini-runner.js +15 -12
- package/dist/agents/tool-time-context.js +55 -0
- package/dist/aun/aid/agentmd.js +21 -1
- package/dist/aun/menu/client.js +1 -1
- package/dist/aun/model-headers.js +17 -0
- package/dist/aun/msg/p2p.js +7 -2
- package/dist/channels/aun.js +522 -50
- package/dist/channels/builtin-plugins.js +16 -11
- package/dist/channels/daemon.js +4 -0
- package/dist/channels/dingtalk.js +83 -31
- package/dist/channels/feishu.js +29 -13
- package/dist/channels/qqbot.js +32 -11
- package/dist/channels/wechat.js +13 -3
- package/dist/channels/wecom.js +67 -27
- package/dist/cli/agent-command.js +3 -86
- package/dist/cli/agent-create.js +20 -6
- package/dist/cli/agent.js +1 -79
- package/dist/cli/aun-commands.js +18 -19
- package/dist/cli/config.js +1 -1
- package/dist/cli/daemon-commands.js +47 -2
- package/dist/cli/data-command.js +9 -1
- package/dist/cli/debug-mode.js +1 -1
- package/dist/cli/diag.js +1 -1
- package/dist/cli/directory.js +149 -91
- package/dist/cli/getmeta-command.js +1 -1
- package/dist/cli/index.js +79 -22
- package/dist/cli/init.js +1 -23
- package/dist/cli/link-rules.js +1 -1
- package/dist/cli/managed-command-guard.js +0 -1
- package/dist/cli/pa-workspace-command.js +36 -2
- package/dist/cli/peer.js +3 -2
- package/dist/cli/restart-monitor.js +17 -3
- package/dist/cli/role.js +1 -1
- package/dist/cli/session-command.js +1 -1
- package/dist/cli/stats.js +2 -2
- package/dist/cli/task-context.js +3 -1
- package/dist/cli/thread-command.js +1 -1
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/builtin-role-templates.js +2 -2
- package/dist/config/builtin-roles.js +2 -1
- package/dist/config/config-field-policy.js +7 -2
- package/dist/config/config-manager.js +32 -10
- package/dist/config/peer-role-resolver.js +23 -1
- package/dist/config/role-schema.js +29 -4
- package/dist/config/role-service.js +12 -7
- package/dist/config/role-store.js +30 -8
- package/dist/config-store.js +75 -4
- package/dist/core/agent-ipc-registration.js +16 -59
- package/dist/core/auth/auth-gateway.js +14 -4
- package/dist/core/auth/authorization-audit.js +52 -14
- package/dist/core/auth/operation-authorizer.js +17 -11
- package/dist/core/auth/operation-catalog.js +5 -13
- package/dist/core/channel-loader.js +152 -16
- package/dist/core/channel-runtime.js +5 -0
- package/dist/core/command/agent-control.js +2 -1
- package/dist/core/command/agentmd-menu-request.js +50 -0
- package/dist/core/command/agentmd-menu.js +156 -0
- package/dist/core/command/cli-intent-parser.js +0 -8
- package/dist/core/command/command-handler.js +47 -40
- package/dist/core/command/connect-menu.js +7 -3
- package/dist/core/command/menu-catalog.js +16 -2
- package/dist/core/command/menu-handler.js +107 -14
- package/dist/core/command/menu-protocol.js +28 -0
- package/dist/core/command/role-menu.js +23 -9
- package/dist/core/command/slash-handler.js +139 -51
- package/dist/core/daemon-file-cache.js +3 -3
- package/dist/core/daemon-lifecycle.js +9 -1
- package/dist/core/evolagent-registry.js +5 -4
- package/dist/core/evolagent.js +10 -12
- package/dist/core/handoff/argv-parse.js +115 -0
- package/dist/core/handoff/ipc-registration.js +1 -1
- package/dist/core/ipc-registration.js +19 -2
- package/dist/core/lifecycle-notice.js +185 -0
- package/dist/core/memory/consolidation.js +8 -1
- package/dist/core/memory/relation-sweep.js +20 -8
- package/dist/core/message/aun-ipc-sender.js +35 -2
- package/dist/core/message/contact-admission.js +530 -0
- package/dist/core/message/im-renderer.js +111 -16
- package/dist/core/message/message-admission.js +29 -54
- package/dist/core/message/message-bridge.js +62 -8
- package/dist/core/message/message-utils.js +9 -5
- package/dist/core/message/peer-mode.js +55 -13
- package/dist/core/message/response-engine.js +298 -78
- package/dist/core/message/retry-scheduler.js +4 -0
- package/dist/core/ownership/owner-resolver.js +72 -34
- package/dist/core/permission/ec-command-parser.js +25 -38
- package/dist/core/permission/readonly-shell-query.js +34 -8
- package/dist/core/permission/tool-policy.js +50 -5
- package/dist/core/relation/pa-team.js +127 -0
- package/dist/core/role/runtime-policy.js +18 -5
- package/dist/core/session/session-manager.js +9 -1
- package/dist/core/soul.js +66 -0
- package/dist/core/system-session/memory.js +2 -2
- package/dist/core/thread/thread-service.js +6 -4
- package/dist/directory/contact-admission-paths.js +9 -0
- package/dist/directory/owner-directory-admission.js +125 -29
- package/dist/directory/owner-directory-cache.js +554 -58
- package/dist/directory/owner-directory-identity.js +60 -0
- package/dist/directory/owner-directory-markdown.js +154 -58
- package/dist/directory/owner-directory-policy.js +108 -0
- package/dist/directory/owner-directory-query-operation.js +399 -90
- package/dist/directory/owner-directory-remarks.js +29 -2
- package/dist/directory/owner-directory-request-operation.js +76 -0
- package/dist/directory/owner-directory-scope.js +35 -4
- package/dist/directory/owner-directory-search.js +118 -33
- package/dist/directory/owner-directory-store.js +117 -30
- package/dist/directory/owner-directory-text.js +60 -0
- package/dist/eck/kit-renderer.js +18 -8
- package/dist/eck/manifest-engine.js +55 -6
- package/dist/ecweb/basic-settings-service.js +2 -2
- package/dist/ecweb/message-context-service.js +28 -16
- package/dist/index.js +20 -5
- package/dist/ipc.js +1 -1
- package/dist/paths.js +29 -1
- package/dist/product.js +1 -0
- package/dist/response-system/config-resolver.js +1 -1
- package/dist/response-system/engines/v1/index.js +2 -1
- package/dist/response-system/modes/single-session/index.js +7 -2
- package/dist/trigger/scheduler.js +7 -4
- package/dist/trigger/validation.js +4 -0
- package/dist/utils/error-utils.js +12 -7
- package/dist/utils/logger.js +13 -4
- package/dist/utils/npm-ops.js +2 -2
- package/dist/utils/windows-autostart.js +1 -1
- package/ecagent/README.md +18 -0
- package/ecagent/dist/agent-loop.js +43 -1
- package/ecagent/dist/harness/agent-harness.d.ts +2 -0
- package/ecagent/dist/harness/agent-harness.js +24 -8
- package/ecagent/dist/harness/compaction/compaction.js +3 -0
- package/ecagent/dist/harness/types.d.ts +1 -0
- package/kits/docs/INDEX.md +1 -0
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/context-assembly.md +21 -6
- package/kits/docs/eck_templates/INDEX.template.md +1 -2
- package/kits/docs/evolcore/INDEX.md +4 -1
- package/kits/docs/evolcore/agent-create.md +5 -5
- package/kits/docs/evolcore/agent.md +4 -9
- package/kits/docs/evolcore/directory.md +227 -0
- package/kits/docs/evolcore/ecweb-lifecycle.md +26 -0
- package/kits/docs/evolcore/file-navigation.md +265 -0
- package/kits/docs/evolcore/menu-protocol.md +55 -0
- package/kits/docs/evolcore/msg.md +1 -0
- package/kits/docs/evolcore/peer.md +2 -1
- package/kits/docs/evolcore/response.md +7 -1
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/tool-authorization.md +1 -1
- package/kits/docs/evolcore/trigger.md +4 -0
- package/kits/docs/identity/ROLE_DETAIL.md +2 -0
- package/kits/docs/prompt-loading-architecture.md +6 -2
- package/kits/eck_manifest.auxiliary.json +1 -0
- package/kits/eck_manifest.json +64 -7
- package/kits/eck_manifest.memory.json +93 -4
- package/kits/rules/01-overview.md +2 -2
- package/kits/rules/03-identity.md +10 -9
- package/kits/rules/05-venue.md +2 -4
- package/kits/rules/06-channel.md +1 -1
- package/kits/schemas/_meta.json +44 -3
- package/kits/schemas/agent-config.schema.18.json +5 -0
- package/kits/schemas/agent-config.schema.19.json +924 -0
- package/kits/schemas/agent-config.schema.20.json +925 -0
- package/kits/schemas/relation-config.schema.12.json +289 -0
- package/kits/schemas/relation-config.schema.13.json +289 -0
- package/kits/schemas/role-config.schema.2.json +215 -0
- package/kits/schemas/role-config.schema.3.json +1038 -0
- package/kits/schemas/role-registry.schema.1.json +3 -2
- package/kits/skills/ec-skill/scripts/cli.mjs +3 -2
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/personal-assistant/SKILL.md +109 -53
- package/kits/skills/personal-assistant/references/02-bootstrap.md +73 -30
- package/kits/skills/personal-assistant/scripts/clean.mjs +35 -18
- package/kits/skills/personal-assistant/scripts/init.mjs +41 -2
- package/kits/skills/personal-assistant/scripts/lib/persona.mjs +185 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +55 -4
- package/kits/skills/personal-assistant/scripts/pa.mjs +173 -0
- package/kits/skills/personal-assistant/scripts/uninstall.mjs +130 -0
- package/kits/skills/personal-assistant/templates/persona-section.md +3 -3
- package/kits/templates/message-fragments/handoff-request-to-target.md +1 -1
- package/kits/templates/soul/00-GUIDE.md +39 -0
- package/kits/templates/soul/01-identity.md +5 -0
- package/kits/templates/soul/02-persona.md +11 -0
- package/kits/templates/soul/03-duties.md +5 -0
- package/kits/templates/soul/04-working-style.md +5 -0
- package/kits/templates/system-fragments/bootstrap.md +7 -7
- package/kits/templates/system-fragments/channel.md +2 -2
- package/kits/templates/system-fragments/commands.md +3 -2
- package/kits/templates/system-fragments/directory-contacts.md +9 -0
- package/kits/templates/system-fragments/memory.md +1 -1
- package/kits/templates/system-fragments/personal-assistant.md +50 -0
- package/kits/templates/system-fragments/reply.md +7 -0
- package/kits/templates/system-fragments/session.md +6 -2
- package/package.json +3 -2
- package/dist/cli/handoff-command.js +0 -353
- package/dist/directory/owner-directory-remark-operation.js +0 -147
- package/kits/docs/evolcore/self-summary.md +0 -29
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
1
2
|
import { logger } from '../../utils/logger.js';
|
|
2
3
|
import { summarizeToolInput, summarizeToolInputForDisplay, toolInputForDisplay } from '../../utils/tool-summary.js';
|
|
3
4
|
import { getErrorMessage, getToolResultErrorText, isContextTooLongText } from '../../utils/error-utils.js';
|
|
@@ -5,6 +6,7 @@ import { tagErrorTextWithEvolcoreVersion } from '../../utils/evolcore-version.js
|
|
|
5
6
|
import { DEFAULT_FLUSH_DELAY_MS } from '../../types.js';
|
|
6
7
|
import { classifyAunToolErrorCode, normalizeToolErrorClassification } from '../permission/tool-error-code.js';
|
|
7
8
|
import { foldSubtaskTerminal } from './subtask-tool-projection.js';
|
|
9
|
+
import { isNoopText, mayBeNoopText } from './message-utils.js';
|
|
8
10
|
function toolApprovalMetadata(event) {
|
|
9
11
|
if (!event || event.executed !== false || !event.decisionSource || event.decisionSource === 'runner')
|
|
10
12
|
return {};
|
|
@@ -25,6 +27,7 @@ export class IMRenderer {
|
|
|
25
27
|
opts;
|
|
26
28
|
itemsQueue = [];
|
|
27
29
|
textBuffer = '';
|
|
30
|
+
deferredProactiveText = [];
|
|
28
31
|
timer;
|
|
29
32
|
lastFlush = Date.now();
|
|
30
33
|
allText = '';
|
|
@@ -35,6 +38,7 @@ export class IMRenderer {
|
|
|
35
38
|
/** 串行发送队列:保证消息按序到达 */
|
|
36
39
|
sendChain = Promise.resolve();
|
|
37
40
|
activityRecordChain = Promise.resolve();
|
|
41
|
+
pendingAutomaticText;
|
|
38
42
|
/** proactive:是否已发过 text 文本(用于去重 complete.result) */
|
|
39
43
|
hasEmittedText = false;
|
|
40
44
|
/** 自增 callId 兜底(runner 没提供时用) */
|
|
@@ -57,6 +61,10 @@ export class IMRenderer {
|
|
|
57
61
|
constructor(opts) {
|
|
58
62
|
this.opts = opts;
|
|
59
63
|
const send = opts.send;
|
|
64
|
+
// Only durable task-activity recording needs to gate publication. Keep
|
|
65
|
+
// renderer-only callers synchronous when no store is configured.
|
|
66
|
+
if (!opts.recordActivity)
|
|
67
|
+
return;
|
|
60
68
|
this.opts = { ...opts, send: payload => {
|
|
61
69
|
// Capture the current barrier: later activities must not hold this send.
|
|
62
70
|
const recorded = this.activityRecordChain;
|
|
@@ -67,11 +75,13 @@ export class IMRenderer {
|
|
|
67
75
|
return this.opts.suppressActivityItems ?? this.opts.suppressActivities ?? false;
|
|
68
76
|
}
|
|
69
77
|
suppressIntermediateText() {
|
|
78
|
+
if (this.opts.noopSentinel)
|
|
79
|
+
return true;
|
|
70
80
|
return this.opts.suppressIntermediateText ?? this.opts.suppressActivities ?? false;
|
|
71
81
|
}
|
|
72
82
|
// ── 公开接口 ──
|
|
73
83
|
/** 推入 AgentEvent,按 chatmode 投影 */
|
|
74
|
-
emit(event) {
|
|
84
|
+
emit(event, suppressTextProjection = false) {
|
|
75
85
|
try {
|
|
76
86
|
const correlatedEvent = event.type === 'tool_use' || event.type === 'tool_result'
|
|
77
87
|
? { ...event, correlationId: event.correlationId ?? event.callId }
|
|
@@ -96,7 +106,7 @@ export class IMRenderer {
|
|
|
96
106
|
catch {
|
|
97
107
|
// logger.event 失败不影响业务
|
|
98
108
|
}
|
|
99
|
-
if (this.opts.envelope.chatmode === 'proactive') {
|
|
109
|
+
if (this.opts.envelope.chatmode === 'proactive' && !suppressTextProjection) {
|
|
100
110
|
this.emitProactive(event);
|
|
101
111
|
}
|
|
102
112
|
// interactive 模式由 MessageProcessor 显式调 addText/addToolCall/... 推入 items
|
|
@@ -105,6 +115,16 @@ export class IMRenderer {
|
|
|
105
115
|
async flush(isFinal, attention) {
|
|
106
116
|
await this.activityRecordChain;
|
|
107
117
|
if (this.opts.envelope.chatmode === 'proactive') {
|
|
118
|
+
if (isFinal) {
|
|
119
|
+
const pending = this.deferredProactiveText;
|
|
120
|
+
this.deferredProactiveText = [];
|
|
121
|
+
if (!isNoopText(pending.map(item => item.text).join(''), this.opts.noopSentinel || undefined)) {
|
|
122
|
+
for (const item of pending) {
|
|
123
|
+
this.recordActivity(item);
|
|
124
|
+
await this.sendPayload({ kind: 'activity.batch', items: [item] });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
108
128
|
// proactive 是 fire-and-forget,无 pending buffer;只需放出仍被扣住的工具结果
|
|
109
129
|
this.releaseHeldToolResults();
|
|
110
130
|
await this.activityRecordChain;
|
|
@@ -120,11 +140,11 @@ export class IMRenderer {
|
|
|
120
140
|
}
|
|
121
141
|
/** 是否有 pending 内容 */
|
|
122
142
|
hasContent() {
|
|
123
|
-
return this.textBuffer.length > 0 || this.itemsQueue.some(it => it.kind !== 'text') || this.hasHeldToolResults();
|
|
143
|
+
return !!this.pendingAutomaticText || this.textBuffer.length > 0 || this.deferredProactiveText.length > 0 || this.itemsQueue.some(it => it.kind !== 'text') || this.hasHeldToolResults();
|
|
124
144
|
}
|
|
125
145
|
/** 是否有会抑制兜底错误消息的正文/过程内容;lifecycle 边界不算。 */
|
|
126
146
|
hasNonLifecycleContent() {
|
|
127
|
-
return this.textBuffer.trim().length > 0 || this.hasHeldToolResults() || this.itemsQueue.some(it => {
|
|
147
|
+
return !!this.pendingAutomaticText || this.textBuffer.trim().length > 0 || this.hasHeldToolResults() || this.itemsQueue.some(it => {
|
|
128
148
|
if (it.kind === 'text')
|
|
129
149
|
return it.text.trim().length > 0;
|
|
130
150
|
if (this.subtaskItems.has(it))
|
|
@@ -140,12 +160,14 @@ export class IMRenderer {
|
|
|
140
160
|
}
|
|
141
161
|
/** 是否有待发送的文本 */
|
|
142
162
|
hasTextPending() {
|
|
143
|
-
return this.textBuffer.length > 0;
|
|
163
|
+
return !!this.pendingAutomaticText || this.textBuffer.length > 0;
|
|
144
164
|
}
|
|
145
165
|
/** flush 当前 textBuffer 作为独立的 result.text(非 final),然后清空 buffer */
|
|
146
166
|
async flushText() {
|
|
147
167
|
if (this.opts.envelope.chatmode === 'proactive')
|
|
148
168
|
return;
|
|
169
|
+
if (this.pendingAutomaticText)
|
|
170
|
+
await this.retryAutomaticText();
|
|
149
171
|
if (this.textBuffer.length === 0)
|
|
150
172
|
return;
|
|
151
173
|
// 文件标记过滤后若只剩空白,应立即消费;尤其避免 final-only
|
|
@@ -167,6 +189,8 @@ export class IMRenderer {
|
|
|
167
189
|
this.itemsQueue = this.itemsQueue.filter(it => it.kind !== 'text');
|
|
168
190
|
return;
|
|
169
191
|
}
|
|
192
|
+
if (mayBeNoopText(rawText, this.opts.noopSentinel || undefined))
|
|
193
|
+
return;
|
|
170
194
|
if (this.timer) {
|
|
171
195
|
clearTimeout(this.timer);
|
|
172
196
|
this.timer = undefined;
|
|
@@ -182,11 +206,12 @@ export class IMRenderer {
|
|
|
182
206
|
};
|
|
183
207
|
this.sentContent = true;
|
|
184
208
|
try {
|
|
185
|
-
await this.
|
|
209
|
+
await this.sendAutomaticText(payload);
|
|
186
210
|
}
|
|
187
211
|
catch (error) {
|
|
188
212
|
// A failed durable enqueue must remain retryable by the final flush.
|
|
189
|
-
this.
|
|
213
|
+
if (this.opts.envelope.chatmode !== 'paactive')
|
|
214
|
+
this.textBuffer = rawText + this.textBuffer;
|
|
190
215
|
throw error;
|
|
191
216
|
}
|
|
192
217
|
this.lastFlush = Date.now();
|
|
@@ -209,6 +234,8 @@ export class IMRenderer {
|
|
|
209
234
|
this.itemsQueue = [];
|
|
210
235
|
this.textBuffer = '';
|
|
211
236
|
this.allText = '';
|
|
237
|
+
this.deferredProactiveText = [];
|
|
238
|
+
this.pendingAutomaticText = undefined;
|
|
212
239
|
}
|
|
213
240
|
/** 仅丢弃尚未发送的正文,保留 notice/tool 等活动项。 */
|
|
214
241
|
discardPendingText() {
|
|
@@ -218,10 +245,12 @@ export class IMRenderer {
|
|
|
218
245
|
}
|
|
219
246
|
this.itemsQueue = this.itemsQueue.filter(it => it.kind !== 'text');
|
|
220
247
|
this.textBuffer = '';
|
|
248
|
+
this.deferredProactiveText = [];
|
|
249
|
+
this.pendingAutomaticText = undefined;
|
|
221
250
|
}
|
|
222
251
|
/** 当前 buffer 中尚未 flush 的文本 */
|
|
223
252
|
getRemainingText() {
|
|
224
|
-
return this.textBuffer;
|
|
253
|
+
return (this.pendingAutomaticText?.item.text ?? '') + this.textBuffer;
|
|
225
254
|
}
|
|
226
255
|
// ── 文本/活动注入(替代 StreamFlusher.addText/addActivity)──
|
|
227
256
|
/** 添加文本片段(流式 text) */
|
|
@@ -602,7 +631,7 @@ export class IMRenderer {
|
|
|
602
631
|
isFinal: false,
|
|
603
632
|
};
|
|
604
633
|
this.sentContent = true;
|
|
605
|
-
await this.
|
|
634
|
+
await this.sendAutomaticText(payload);
|
|
606
635
|
this.lastFlush = Date.now();
|
|
607
636
|
this.flushCount++;
|
|
608
637
|
return true;
|
|
@@ -686,6 +715,51 @@ export class IMRenderer {
|
|
|
686
715
|
this.sendChain = handled.catch(() => { });
|
|
687
716
|
return handled;
|
|
688
717
|
}
|
|
718
|
+
/** Model output and renderer text notices share PA's automatic-text outlet.
|
|
719
|
+
* Explicit sends, command receipts and interaction fallbacks bypass it.
|
|
720
|
+
*/
|
|
721
|
+
async sendAutomaticText(payload) {
|
|
722
|
+
if (isNoopText(payload.text, this.opts.noopSentinel || undefined))
|
|
723
|
+
return;
|
|
724
|
+
if (this.opts.envelope.chatmode !== 'paactive')
|
|
725
|
+
return this.sendPayload(payload);
|
|
726
|
+
try {
|
|
727
|
+
// Another flush may have started while this one awaited a tool batch.
|
|
728
|
+
// Never replace its in-flight or failed text item with this payload.
|
|
729
|
+
while (this.pendingAutomaticText)
|
|
730
|
+
await this.retryAutomaticText();
|
|
731
|
+
}
|
|
732
|
+
catch (error) {
|
|
733
|
+
// This payload has not been recorded yet; preserve it behind the older
|
|
734
|
+
// pending item so a later flush can retry both without loss or overlap.
|
|
735
|
+
this.textBuffer = payload.text + this.textBuffer;
|
|
736
|
+
throw error;
|
|
737
|
+
}
|
|
738
|
+
const item = {
|
|
739
|
+
kind: 'text',
|
|
740
|
+
text: payload.text,
|
|
741
|
+
...(payload.metadata?.forkAnchor ? { forkAnchor: payload.metadata.forkAnchor } : {}),
|
|
742
|
+
};
|
|
743
|
+
this.recordActivity(item, `activity-${randomUUID().replace(/-/g, '')}`);
|
|
744
|
+
this.pendingAutomaticText = { item };
|
|
745
|
+
await this.retryAutomaticText();
|
|
746
|
+
}
|
|
747
|
+
/** Keep a failed, already-recorded text item separate from newly buffered text. */
|
|
748
|
+
retryAutomaticText() {
|
|
749
|
+
const pending = this.pendingAutomaticText;
|
|
750
|
+
if (!pending)
|
|
751
|
+
return Promise.resolve();
|
|
752
|
+
if (!pending.delivery) {
|
|
753
|
+
pending.delivery = this.sendPayload({ kind: 'activity.batch', items: [pending.item] }).then(() => {
|
|
754
|
+
if (this.pendingAutomaticText === pending)
|
|
755
|
+
this.pendingAutomaticText = undefined;
|
|
756
|
+
}, error => {
|
|
757
|
+
pending.delivery = undefined;
|
|
758
|
+
throw error;
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
return pending.delivery;
|
|
762
|
+
}
|
|
689
763
|
scheduleFlush() {
|
|
690
764
|
if (this.timer) {
|
|
691
765
|
return;
|
|
@@ -731,6 +805,8 @@ export class IMRenderer {
|
|
|
731
805
|
const nonThinking = this.itemsQueue.filter(it => it.kind !== 'text');
|
|
732
806
|
if (nonThinking.length === 0)
|
|
733
807
|
return;
|
|
808
|
+
if (this.pendingAutomaticText)
|
|
809
|
+
await this.retryAutomaticText();
|
|
734
810
|
if (this.timer) {
|
|
735
811
|
clearTimeout(this.timer);
|
|
736
812
|
this.timer = undefined;
|
|
@@ -765,6 +841,8 @@ export class IMRenderer {
|
|
|
765
841
|
clearTimeout(this.timer);
|
|
766
842
|
this.timer = undefined;
|
|
767
843
|
}
|
|
844
|
+
if (this.pendingAutomaticText)
|
|
845
|
+
await this.retryAutomaticText();
|
|
768
846
|
// 显式 flush(轮次结束、出错收尾)时放出被扣住的后台占位结果;定时 flush 不放,
|
|
769
847
|
// 否则长时间后台任务会在终态到达前就把占位结果发出去。放出的结果随本次 flush 一起发,
|
|
770
848
|
// 不需要它重新挂上的定时器。
|
|
@@ -786,7 +864,10 @@ export class IMRenderer {
|
|
|
786
864
|
item.text = item.text.replace(this.opts.fileMarkerPattern, '');
|
|
787
865
|
}
|
|
788
866
|
}
|
|
789
|
-
if (
|
|
867
|
+
if (isFinal && isNoopText(this.textBuffer, this.opts.noopSentinel || undefined)) {
|
|
868
|
+
this.discardPendingText();
|
|
869
|
+
}
|
|
870
|
+
else if (!this.hasSendableText(this.textBuffer, isFinal ? 'final' : 'flush')) {
|
|
790
871
|
this.textBuffer = '';
|
|
791
872
|
}
|
|
792
873
|
else if (isFinal && this.opts.fileMarkerPattern) {
|
|
@@ -831,6 +912,8 @@ export class IMRenderer {
|
|
|
831
912
|
if (!isFinal && this.textBuffer.length > 0) {
|
|
832
913
|
if (this.suppressIntermediateText())
|
|
833
914
|
return;
|
|
915
|
+
if (mayBeNoopText(this.textBuffer, this.opts.noopSentinel || undefined))
|
|
916
|
+
return;
|
|
834
917
|
// A timer cannot decide whether this is the final answer. Keep it for
|
|
835
918
|
// an explicit boundary; known commentary can still be sent immediately.
|
|
836
919
|
if (scheduled && this.opts.deferTextUntilBoundary && this.currentTextPhase !== 'commentary')
|
|
@@ -845,10 +928,11 @@ export class IMRenderer {
|
|
|
845
928
|
};
|
|
846
929
|
this.sentContent = true;
|
|
847
930
|
try {
|
|
848
|
-
await this.
|
|
931
|
+
await this.sendAutomaticText(payload);
|
|
849
932
|
}
|
|
850
933
|
catch (error) {
|
|
851
|
-
this.
|
|
934
|
+
if (this.opts.envelope.chatmode !== 'paactive')
|
|
935
|
+
this.textBuffer = text + this.textBuffer;
|
|
852
936
|
throw error;
|
|
853
937
|
}
|
|
854
938
|
this.lastFlush = Date.now();
|
|
@@ -866,10 +950,11 @@ export class IMRenderer {
|
|
|
866
950
|
payload.attention = attention;
|
|
867
951
|
this.sentContent = true;
|
|
868
952
|
try {
|
|
869
|
-
await this.
|
|
953
|
+
await this.sendAutomaticText(payload);
|
|
870
954
|
}
|
|
871
955
|
catch (error) {
|
|
872
|
-
this.
|
|
956
|
+
if (this.opts.envelope.chatmode !== 'paactive')
|
|
957
|
+
this.textBuffer = finalText + this.textBuffer;
|
|
873
958
|
throw error;
|
|
874
959
|
}
|
|
875
960
|
this.lastFlush = Date.now();
|
|
@@ -956,15 +1041,25 @@ export class IMRenderer {
|
|
|
956
1041
|
this.emitProactiveItem(item);
|
|
957
1042
|
}
|
|
958
1043
|
/** Serialize persistence and resource preparation before publishing items. */
|
|
959
|
-
recordActivity(item) {
|
|
1044
|
+
recordActivity(item, activityId) {
|
|
960
1045
|
this.activityRecordChain = this.activityRecordChain.then(async () => {
|
|
961
|
-
|
|
1046
|
+
if (activityId === undefined)
|
|
1047
|
+
await this.opts.recordActivity?.(item);
|
|
1048
|
+
else
|
|
1049
|
+
await this.opts.recordActivity?.(item, activityId);
|
|
962
1050
|
}).catch(error => {
|
|
963
1051
|
logger.warn(`[IMRenderer] task activity record failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
964
1052
|
});
|
|
965
1053
|
}
|
|
966
1054
|
/** proactive:单个 ThoughtItem 包成 activity.batch[1] 发出。 */
|
|
967
1055
|
emitProactiveItem(item) {
|
|
1056
|
+
if (item.kind === 'text' || (item.kind === 'summary' && !item.is_error)) {
|
|
1057
|
+
if (this.opts.noopSentinel || this.deferredProactiveText.length > 0
|
|
1058
|
+
|| mayBeNoopText(item.text)) {
|
|
1059
|
+
this.deferredProactiveText.push(item);
|
|
1060
|
+
return;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
968
1063
|
this.recordActivity(item);
|
|
969
1064
|
const evolCommand = item.kind === 'tool_call' ? item.evolCommand : undefined;
|
|
970
1065
|
const payload = evolCommand
|
|
@@ -3,11 +3,9 @@ import { resolvePeerView, resolvePrincipal, } from '../../config/peer-book.js';
|
|
|
3
3
|
import { isValidAid } from '../../aun/aid/validation.js';
|
|
4
4
|
import { readOwnerDirectoryMembership } from '../../directory/owner-directory-admission.js';
|
|
5
5
|
import { resolveAunPeerKind } from '../relation/peer-identity.js';
|
|
6
|
+
import { evaluateAppContactAdmission } from './contact-admission.js';
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* 顺序与入站一致:本地拉黑 → Owner/个人助理 → 黑名单 → 白名单
|
|
10
|
-
* → `allowAllContacts` 总开关 → 名录内部/外部档。
|
|
8
|
+
* AUN 出站私聊固定使用 app-v1,与入站保持相同的绑定和联系人判定。
|
|
11
9
|
* 群聊的准入单位是群,出站到群不做发言人判定。
|
|
12
10
|
*/
|
|
13
11
|
export async function evaluateOutboundContactAdmission(input) {
|
|
@@ -21,57 +19,19 @@ export async function evaluateOutboundContactAdmission(input) {
|
|
|
21
19
|
const target = await resolveAunPeerKind(selfAid, targetAid);
|
|
22
20
|
if (target.kind === 'group')
|
|
23
21
|
return { allow: true, status: 'group' };
|
|
24
|
-
let
|
|
25
|
-
try {
|
|
26
|
-
policy = readAccessPolicy(selfAid);
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
return { allow: false, code: 'CONTACT_POLICY_INVALID', status: 'absent', error: error instanceof Error ? error.message : String(error) };
|
|
30
|
-
}
|
|
31
|
-
let view;
|
|
22
|
+
let decision;
|
|
32
23
|
try {
|
|
33
|
-
|
|
24
|
+
decision = evaluateAppContactAdmission(selfAid, targetAid);
|
|
34
25
|
}
|
|
35
26
|
catch (error) {
|
|
36
27
|
return { allow: false, code: 'CONTACT_POLICY_INVALID', status: 'absent', error: error instanceof Error ? error.message : String(error) };
|
|
37
28
|
}
|
|
38
|
-
if (
|
|
39
|
-
return { allow:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return { allow: false, code: 'CONTACT_DENIED', status: 'denied', error: `目标 ${targetAid} 在 Owner 配置的黑名单 deniedAids 中,当前无法联系` };
|
|
45
|
-
}
|
|
46
|
-
if (policy.allowedAids?.includes(targetAid))
|
|
47
|
-
return { allow: true, status: 'allowed_aid' };
|
|
48
|
-
// 总开关:压过名录三档(含名录不可用)。拉黑与 deniedAids 已在本行之前判定。
|
|
49
|
-
if (policy.allowAllContacts === true)
|
|
50
|
-
return { allow: true, status: 'all_contacts' };
|
|
51
|
-
const membership = readOwnerDirectoryMembership(selfAid, targetAid);
|
|
52
|
-
switch (membership?.category) {
|
|
53
|
-
case 'unavailable':
|
|
54
|
-
return { allow: false, code: 'CONTACT_DIRECTORY_UNAVAILABLE', status: 'unavailable', error: 'Owner 名录当前不可用,无法确认目标身份,已拒绝发送;如需无条件联系请开启 allowAllContacts' };
|
|
55
|
-
case 'owner':
|
|
56
|
-
return { allow: true, status: 'owner' };
|
|
57
|
-
case 'assistant':
|
|
58
|
-
return { allow: true, status: 'internal' };
|
|
59
|
-
case 'agent':
|
|
60
|
-
case 'human':
|
|
61
|
-
case 'other': {
|
|
62
|
-
if (membership.internal) {
|
|
63
|
-
return policy.allowInternalContacts !== false
|
|
64
|
-
? { allow: true, status: 'internal' }
|
|
65
|
-
: { allow: false, code: 'CONTACT_INTERNAL_DISABLED', status: 'disabled', error: '当前 Agent 不接受内部联系,Owner 未开启 allowInternalContacts 与 allowAllContacts' };
|
|
66
|
-
}
|
|
67
|
-
return policy.allowExternalContacts === true
|
|
68
|
-
? { allow: true, status: 'external' }
|
|
69
|
-
: { allow: false, code: 'CONTACT_EXTERNAL_DISABLED', status: 'disabled', error: '当前 Agent 不接受外部联系,Owner 未开启 allowExternalContacts 与 allowAllContacts' };
|
|
70
|
-
}
|
|
71
|
-
case 'not_found':
|
|
72
|
-
default:
|
|
73
|
-
return { allow: false, code: 'CONTACT_ALL_CONTACTS_DISABLED', status: 'disabled', error: `目标 ${targetAid} 不在当前 Agent 的 Owner 名录中,Owner 未开启 allowAllContacts` };
|
|
74
|
-
}
|
|
29
|
+
if (decision.allow)
|
|
30
|
+
return { allow: true, status: decision.reason === 'owner' ? 'owner' : decision.reason === 'temporary' ? 'temporary' : 'contact' };
|
|
31
|
+
return { allow: false, code: decision.reason === 'unavailable' ? 'CONTACT_DIRECTORY_UNAVAILABLE'
|
|
32
|
+
: decision.reason === 'blocked' ? 'CONTACT_BLOCKED' : 'CONTACT_DENIED',
|
|
33
|
+
status: decision.reason === 'unavailable' ? 'unavailable' : decision.reason === 'blocked' ? 'blocked' : 'denied',
|
|
34
|
+
error: `联系人准入未通过:${decision.reason}` };
|
|
75
35
|
}
|
|
76
36
|
export function evaluateInboundAdmissionPreflight(input) {
|
|
77
37
|
const selfAid = String(input.selfAid || '').trim();
|
|
@@ -147,13 +107,16 @@ export function evaluateInboundAdmissionPreflight(input) {
|
|
|
147
107
|
*
|
|
148
108
|
* - `owner` / `assistant`:恒放行,不受任何开关与名单影响。
|
|
149
109
|
* - 命中条目且属于本 Owner → `allowInternalContacts`。
|
|
150
|
-
* - 命中条目但归属其他 Owner(或缺失归属)→ `
|
|
110
|
+
* - 命中条目但归属其他 Owner(或缺失归属)→ `effectiveAllowExternalContacts`
|
|
111
|
+
* (显式配置 > 个人助理缺省 true > false,与注入共用同一个判据)。
|
|
151
112
|
* - 未命中 → 返回 undefined,由调用方按 `allowAllContacts` 决定。
|
|
152
113
|
* - 名录不可用 → 拒绝,不回退放行(`allowAllContacts` 与白名单都在调用方更早处置)。
|
|
153
114
|
*
|
|
154
115
|
* 拒绝发生在业务路由之前,被拒的名录发送者不会收到自动回复。
|
|
155
116
|
*/
|
|
156
117
|
export function evaluateOwnerDirectoryInboundAdmission(context) {
|
|
118
|
+
if (context.channelType === 'aun')
|
|
119
|
+
return undefined;
|
|
157
120
|
if (context.trustedHandoffEcho || context.isOwner || !context.primaryId || !context.policy)
|
|
158
121
|
return undefined;
|
|
159
122
|
const membership = readOwnerDirectoryMembership(context.selfAid, context.primaryId);
|
|
@@ -175,7 +138,10 @@ export function evaluateOwnerDirectoryInboundAdmission(context) {
|
|
|
175
138
|
? { allow: true, reason: membership.category === 'agent' ? 'internal_agent' : 'internal_contact', context }
|
|
176
139
|
: { allow: false, reason: 'internal_contacts_disabled', context };
|
|
177
140
|
}
|
|
178
|
-
|
|
141
|
+
// 外部档取"显式配置 > 个人助理判据"的最终值:注入每轮都按这个值渲染,
|
|
142
|
+
// 准入若读补齐后的 `policy.allowExternalContacts`(缺省 false),
|
|
143
|
+
// 个人助理就会出现"目录里能看到人、对方发进来却被拒"。
|
|
144
|
+
return membership.effectiveAllowExternalContacts === true
|
|
179
145
|
? { allow: true, reason: membership.category === 'agent' ? 'external_agent' : 'external_contact', context }
|
|
180
146
|
: { allow: false, reason: 'external_contacts_disabled', context };
|
|
181
147
|
}
|
|
@@ -209,9 +175,18 @@ function evaluateOrdinaryAdmission(context) {
|
|
|
209
175
|
return { allow: true, reason: 'owner', context };
|
|
210
176
|
return { allow: true, reason: 'group_channel_allowed', context };
|
|
211
177
|
}
|
|
212
|
-
// Owner
|
|
213
|
-
|
|
178
|
+
// Non-AUN channels retain their Owner shortcut; AUN Owner admission comes
|
|
179
|
+
// from the current app-v1 relation binding below.
|
|
180
|
+
if (context.isOwner && context.channelType !== 'aun')
|
|
214
181
|
return { allow: true, reason: 'owner', context };
|
|
182
|
+
if (context.channelType === 'aun') {
|
|
183
|
+
const decision = evaluateAppContactAdmission(context.selfAid, context.primaryId ?? context.actorId);
|
|
184
|
+
if (decision.allow)
|
|
185
|
+
return { allow: true, reason: decision.reason === 'owner' ? 'owner'
|
|
186
|
+
: decision.reason === 'temporary' ? 'temporary_contact' : 'allowed_aid', context };
|
|
187
|
+
return { allow: false, reason: decision.reason === 'unavailable' ? 'owner_directory_unavailable'
|
|
188
|
+
: decision.reason === 'blocked' ? 'denied_aid' : 'all_contacts_disabled', context };
|
|
189
|
+
}
|
|
215
190
|
const directoryDecision = evaluateOwnerDirectoryInboundAdmission(context);
|
|
216
191
|
// Owner 与个人助理恒放行,不受黑名单影响。
|
|
217
192
|
if (directoryDecision?.allow
|
|
@@ -5,6 +5,8 @@ import { createHash, randomBytes } from 'crypto';
|
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { agentStorageMenuService, isAgentStorageMenuRequest } from '../command/agent-storage-menu.js';
|
|
8
|
+
import { agentMdMenuService } from '../command/agentmd-menu.js';
|
|
9
|
+
import { containsAgentMdMenuRequest } from '../command/agentmd-menu-request.js';
|
|
8
10
|
import { logger, logPreview } from '../../utils/logger.js';
|
|
9
11
|
import { StreamDebouncer } from './stream-debouncer.js';
|
|
10
12
|
import { appendMessageLog, appendMessageLogStrict, buildInboundEntry, isTransientProtocolMessage } from './message-log.js';
|
|
@@ -17,6 +19,7 @@ import { listStaticAgentAdmins, listStaticAgentOwners, resolvePeerRoleDetail, }
|
|
|
17
19
|
import { resolvePeerView, resolvePeerDisplayLabel, resolvePrincipal } from '../../config/peer-book.js';
|
|
18
20
|
import { findPeerRequestNote, expirePendingPeerRequests, reviewPeerRequest, submitPeerRequest, peerRequestSubmissionProtocolResult, queryOwnPeerRequestStatus, } from '../../config/peer-request-service.js';
|
|
19
21
|
import { isValidAid } from '../../aun/aid/validation.js';
|
|
22
|
+
import { prepareOwnerDirectoryAdmission } from '../../directory/owner-directory-admission.js';
|
|
20
23
|
import { PeerIdentityCache, formatPeerKey } from '../relation/peer-identity.js';
|
|
21
24
|
import { ownerResolver, refreshOwnershipForAuthorization, OWNERSHIP_CACHE_MAX_AGE_MS } from '../ownership/owner-resolver.js';
|
|
22
25
|
import { isTopicSession, sessionLocalTopicId } from '../thread/topic-id.js';
|
|
@@ -24,6 +27,7 @@ import { resolveEffective } from '../../config/config-manager.js';
|
|
|
24
27
|
import { createDecisionInferenceProvider } from '../inference/text-inference.js';
|
|
25
28
|
import { AutoMentionGate } from './auto-mention-gate.js';
|
|
26
29
|
import { syncGroupRulesContext } from '../../eck/group-rules-sync.js';
|
|
30
|
+
import { readSoulContent } from '../soul.js';
|
|
27
31
|
import { authorizeAccess, buildAuthSubject } from '../auth/auth-gateway.js';
|
|
28
32
|
import { MenuDiagnosticLimiter, MenuRequestDeduper, hasValidMenuId, menuFailure, menuPayloadFingerprint, menuSuccess, normalizeMenuError, parseMenuControl, validateMenuRequest, evaluateEvolMenuVersionGate, evolMenuResponseTransportMetadata, isAunMenuTokenRequired, menuCommandForName, normalizeMenuResponseTiming, withMenuProcessingTime, logMenuRequestCompleted, logMenuRequestReceived, } from '../command/menu-protocol.js';
|
|
29
33
|
import { resolveExplicitMenuExecutionContext, validateMenuCatalogArgs, validateMenuValueBatchArgs } from '../command/menu-catalog.js';
|
|
@@ -38,7 +42,6 @@ import { createAgentPolicyAuthorization, createSessionFullAccessAuthorization }
|
|
|
38
42
|
import { auditFullAccessEvent } from '../auth/authorization-audit.js';
|
|
39
43
|
import { DIAGNOSTIC_AGENT_AID, DiagnosticSessionRouter, parseDiagnosticEvent, isDiagnosticSessionActive } from '../command/diag-service.js';
|
|
40
44
|
import { consumeAdmissionReplyBudget, clearAdmissionReplyBudgets, evaluateInboundAdmissionPreflight, evaluateOrdinaryInboundAdmission, evaluateOwnerDirectoryInboundAdmission, } from './message-admission.js';
|
|
41
|
-
import { prepareOwnerDirectoryAdmission } from '../../directory/owner-directory-admission.js';
|
|
42
45
|
const CONTACT_REJECTION_NOTICE = '[rejection] Not accepting messages from you.';
|
|
43
46
|
const REJECTABLE_PEER_TYPES = new Set(['ai', 'bot', 'agent', 'service']);
|
|
44
47
|
const REJECTION_MAX = 3;
|
|
@@ -128,10 +131,10 @@ export class MessageBridge {
|
|
|
128
131
|
logger.debug(`[MessageBridge] Decision context group rules unavailable: ${String(error)}`);
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
|
-
//
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
134
|
-
resources.personal =
|
|
134
|
+
// 个人设定在 personal/soul/ 下,按文件名拼接;机制指南与空分册不算个人资料。
|
|
135
|
+
const personal = readSoulContent(item.selfAid);
|
|
136
|
+
if (personal)
|
|
137
|
+
resources.personal = personal;
|
|
135
138
|
if (item.projectPath) {
|
|
136
139
|
const files = [];
|
|
137
140
|
let current = path.resolve(item.projectPath);
|
|
@@ -480,6 +483,10 @@ export class MessageBridge {
|
|
|
480
483
|
catch { /* slash command */ }
|
|
481
484
|
if (!requestMatch && !protocolType)
|
|
482
485
|
return false;
|
|
486
|
+
if (context.channelType === 'aun') {
|
|
487
|
+
// The App owns requests; retired commands cannot create a second approval state.
|
|
488
|
+
return true;
|
|
489
|
+
}
|
|
483
490
|
// Slash commands keep their human-facing response semantics. Structured
|
|
484
491
|
// App requests use contact.request.response and never fall through to the
|
|
485
492
|
// normal command/session pipeline.
|
|
@@ -920,7 +927,8 @@ export class MessageBridge {
|
|
|
920
927
|
actorId,
|
|
921
928
|
trustedHandoffEcho,
|
|
922
929
|
});
|
|
923
|
-
if (admissionPreflight.allow &&
|
|
930
|
+
if (admissionPreflight.allow && resolvedChannelType !== 'aun'
|
|
931
|
+
&& !trustedHandoffEcho && !admissionPreflight.context.isOwner) {
|
|
924
932
|
if (selfAid && admissionPreflight.context.primaryId) {
|
|
925
933
|
await prepareOwnerDirectoryAdmission(selfAid, admissionPreflight.context.primaryId);
|
|
926
934
|
}
|
|
@@ -1006,7 +1014,8 @@ export class MessageBridge {
|
|
|
1006
1014
|
const admissionDecision = evaluateOrdinaryInboundAdmission(admissionPreflight.context);
|
|
1007
1015
|
// 名录不可用等硬性拒绝不回自动提示,静默丢弃;其余拒绝才发控制面提示。
|
|
1008
1016
|
const directoryDenied = !admissionDecision.allow && (admissionDecision.reason === 'owner_directory_unavailable');
|
|
1009
|
-
|
|
1017
|
+
const appControl = resolvedChannelType === 'aun' && menuControl.isMenu;
|
|
1018
|
+
if (!appControl && !admissionDecision.allow && (!isPrivateMenuTokenRequest || directoryDenied)) {
|
|
1010
1019
|
if (chatType === 'private' && !directoryDenied) {
|
|
1011
1020
|
if (menuControl.isMenu) {
|
|
1012
1021
|
if (hasValidMenuId(menuControl)) {
|
|
@@ -1863,6 +1872,7 @@ export class MessageBridge {
|
|
|
1863
1872
|
...authSubject,
|
|
1864
1873
|
requestId: parsed.id,
|
|
1865
1874
|
menuEncrypted: msg.encrypted === true,
|
|
1875
|
+
menuTransportChatType: msg.chatType || 'private',
|
|
1866
1876
|
fromControlChannel: authSubject.fromControlChannel || msg.isControlChannel === true,
|
|
1867
1877
|
...(activeSession?.id ? { sessionId: activeSession.id } : {}),
|
|
1868
1878
|
};
|
|
@@ -1922,6 +1932,15 @@ export class MessageBridge {
|
|
|
1922
1932
|
}));
|
|
1923
1933
|
return;
|
|
1924
1934
|
}
|
|
1935
|
+
if (deduped.replayed && containsAgentMdMenuRequest(parsed.request)) {
|
|
1936
|
+
try {
|
|
1937
|
+
await agentMdMenuService.preflight(menuAuthSubject);
|
|
1938
|
+
}
|
|
1939
|
+
catch (error) {
|
|
1940
|
+
await this.sendMenuResponse(adapter, channel, msg, menuFailure(header, normalizeMenuError(error)));
|
|
1941
|
+
return;
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1925
1944
|
// A replay may have awaited an in-flight request; check again before release.
|
|
1926
1945
|
if (isStorageRequest) {
|
|
1927
1946
|
try {
|
|
@@ -1940,6 +1959,41 @@ export class MessageBridge {
|
|
|
1940
1959
|
? { ...deduped.value, warning: responseWarning }
|
|
1941
1960
|
: deduped.value;
|
|
1942
1961
|
await this.sendMenuResponse(adapter, channel, msg, response);
|
|
1962
|
+
// The request carries the conversation route; the daemon cannot infer
|
|
1963
|
+
// which App topic is open. This is reliable content, separate from the
|
|
1964
|
+
// device-targeted/volatile Menu acknowledgement, and emitted once per write.
|
|
1965
|
+
const changedModel = response.data && typeof response.data === 'object'
|
|
1966
|
+
? response.data.model : undefined;
|
|
1967
|
+
if (!deduped.replayed && channelType === 'aun' && !msg.isControlChannel
|
|
1968
|
+
&& parsed.type === 'menu.update' && parsed.name === 'model'
|
|
1969
|
+
&& !response.error && typeof changedModel === 'string' && adapter?.send) {
|
|
1970
|
+
try {
|
|
1971
|
+
await adapter.send(buildEnvelope({
|
|
1972
|
+
channel,
|
|
1973
|
+
channelId: msg.channelId,
|
|
1974
|
+
agentName: this.agentRegistry?.resolveByChannel(channel)?.name ?? msg.selfAID,
|
|
1975
|
+
operationId: `model-change:${msg.messageId || parsed.id}`,
|
|
1976
|
+
replyContext: {
|
|
1977
|
+
delivery: msg.replyContext?.delivery,
|
|
1978
|
+
threadId: msg.threadId,
|
|
1979
|
+
suppressPeerMention: true,
|
|
1980
|
+
metadata: {
|
|
1981
|
+
encrypted: msg.encrypted === true,
|
|
1982
|
+
operationId: `model-change:${msg.messageId || parsed.id}`,
|
|
1983
|
+
},
|
|
1984
|
+
},
|
|
1985
|
+
}), {
|
|
1986
|
+
kind: 'system.notice',
|
|
1987
|
+
subtype: 'model.changed',
|
|
1988
|
+
text: `模型已切换为${changedModel},下一轮对话生效`,
|
|
1989
|
+
});
|
|
1990
|
+
}
|
|
1991
|
+
catch (error) {
|
|
1992
|
+
// The configuration write succeeded; notification delivery must not
|
|
1993
|
+
// turn its acknowledgement into a false configuration failure.
|
|
1994
|
+
logger.warn(`[MenuControl] model change notice failed: request=${parsed.id} error=${error}`);
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1943
1997
|
const deferredEffect = afterResponse;
|
|
1944
1998
|
if (!deduped.replayed && deferredEffect) {
|
|
1945
1999
|
try {
|
|
@@ -2110,7 +2164,7 @@ export class MessageBridge {
|
|
|
2110
2164
|
metadata: {
|
|
2111
2165
|
...(msg.replyContext?.metadata ?? {}),
|
|
2112
2166
|
...evolMenuResponseTransportMetadata(msg.protectedHeaders?.sdk_version, msg.protectedHeaders?.menu_volatile_v1),
|
|
2113
|
-
...(isAgentStorageMenuRequest(request) ? { encrypted: true } : {}),
|
|
2167
|
+
...(isAgentStorageMenuRequest(request) || containsAgentMdMenuRequest(request) ? { encrypted: true } : {}),
|
|
2114
2168
|
},
|
|
2115
2169
|
};
|
|
2116
2170
|
if (msg.channelType === 'aun' && !replyContext.delivery) {
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 消息处理工具函数
|
|
3
|
-
*
|
|
4
|
-
* 从 message-processor.ts 提取的独立工具函数,供 ResponseEngine 和其他模块使用。
|
|
5
|
-
*/
|
|
6
1
|
import { sessionLocalTopicId, sessionTopicThreadId } from '../thread/topic-id.js';
|
|
7
2
|
import { renderCommandCardAsText, renderActionAsText } from '../interaction-router.js';
|
|
3
|
+
export const DEFAULT_NOOP_SENTINEL = '[[NOOP]]';
|
|
4
|
+
export function isNoopText(text, sentinel = DEFAULT_NOOP_SENTINEL) {
|
|
5
|
+
return sentinel.length > 0 && text.trimStart().startsWith(sentinel);
|
|
6
|
+
}
|
|
7
|
+
export function mayBeNoopText(text, sentinel = DEFAULT_NOOP_SENTINEL) {
|
|
8
|
+
const prefix = text.trimStart();
|
|
9
|
+
return sentinel.length > 0 && prefix.length > 0
|
|
10
|
+
&& (sentinel.startsWith(prefix) || prefix.startsWith(sentinel));
|
|
11
|
+
}
|
|
8
12
|
/** A legacy adapter resolved its send call without providing a structured receipt. */
|
|
9
13
|
export const LEGACY_INTERACTION_ACCEPTED = 'legacy-accepted';
|
|
10
14
|
export function isInteractionSendAccepted(result) {
|