evolcore 0.0.43-test.5 → 0.0.43-test.7
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 +281 -81
- package/dist/agents/baseagent-availability.js +20 -5
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +19 -4
- package/dist/agents/codex/app-server-client.js +36 -3
- package/dist/agents/codex-runner.js +75 -8
- package/dist/aun/group/invite-service.js +3 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/aun/service-proxy.js +18 -6
- package/dist/channels/aun.js +306 -30
- package/dist/cli/agent-create.js +18 -8
- package/dist/cli/aun-commands.js +9 -1
- package/dist/cli/daemon-commands.js +34 -65
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +38 -3
- package/dist/cli/events-command.js +73 -0
- package/dist/cli/index.js +31 -14
- package/dist/cli/init.js +75 -0
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/provider-command.js +1 -1
- package/dist/cli/restart-monitor.js +67 -50
- package/dist/cli/services-command.js +111 -0
- package/dist/cli/task-context.js +38 -1
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +6 -2
- package/dist/cli/watch-logs.js +6 -4
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/boot-log.js +6 -4
- package/dist/config/builtin-roles.js +2 -2
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +1 -8
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/peer-role-resolver.js +1 -1
- package/dist/config/provider-identity-migration.js +92 -17
- package/dist/config/provider-local-sync.js +2 -0
- package/dist/config/providers-config.js +13 -0
- package/dist/config/providers-management.js +100 -10
- package/dist/config/role-service.js +8 -8
- package/dist/config/role-store.js +22 -22
- package/dist/config/schema-migration.js +86 -88
- package/dist/config/snapshot.js +70 -41
- package/dist/config-store.js +2 -1
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +146 -15
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-catalog.js +20 -0
- package/dist/core/baseagent-loader.js +75 -42
- package/dist/core/channel-loader.js +45 -13
- package/dist/core/channel-runtime.js +116 -45
- package/dist/core/command/agent-control.js +1 -1
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +58 -16
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +338 -0
- package/dist/core/command/menu-catalog.js +8 -0
- package/dist/core/command/menu-handler.js +206 -87
- package/dist/core/command/menu-protocol.js +142 -22
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/role-menu.js +27 -15
- 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 +45 -15
- package/dist/core/daemon-lifecycle.js +478 -75
- package/dist/core/handoff/dispatcher.js +9 -3
- package/dist/core/handoff/runtime.js +130 -42
- package/dist/core/handoff/store.js +190 -2
- package/dist/core/handoff/types.js +5 -0
- package/dist/core/initialization/service.js +4 -4
- 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 +51 -11
- package/dist/core/lifecycle-notice.js +10 -4
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +149 -19
- package/dist/core/message/im-renderer.js +28 -84
- package/dist/core/message/message-bridge.js +57 -4
- package/dist/core/message/message-queue.js +46 -4
- 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 +4 -10
- package/dist/core/message/response-engine.js +163 -52
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +55 -7
- package/dist/core/ownership/owner-resolver.js +8 -0
- package/dist/core/permission/ec-command-parser.js +14 -3
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +24 -0
- package/dist/core/session/adapters/codex-session-file-adapter.js +80 -0
- package/dist/core/session/adapters/ecagent-session-file-adapter.js +22 -0
- package/dist/core/session/adapters/gemini-session-file-adapter.js +39 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +163 -3
- package/dist/core/session/session-idle-monitor.js +9 -1
- package/dist/core/session/session-manager.js +36 -2
- 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/directory/owner-directory-admission.js +42 -30
- package/dist/directory/owner-directory-cache.js +143 -126
- package/dist/directory/owner-directory-query-operation.js +9 -8
- package/dist/eck/kit-renderer.js +7 -5
- package/dist/ecweb/basic-settings-service.js +1 -1
- package/dist/ecweb/message-context-service.js +0 -4
- package/dist/ecweb/runtime/lifecycle.js +14 -8
- package/dist/ecweb/runtime/supervisor.js +62 -30
- package/dist/event-center/admission-materializer.js +114 -0
- package/dist/event-center/bus-gate.js +136 -0
- package/dist/event-center/bus-host.js +290 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +100 -0
- package/dist/event-center/client-factory.js +50 -0
- package/dist/event-center/daemon.js +45 -0
- package/dist/event-center/directory-source.js +53 -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 +63 -0
- package/dist/event-center/ipc-operation.js +308 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +202 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +238 -0
- package/dist/event-center/runtime.js +641 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +35 -0
- package/dist/event-center/validation.js +413 -0
- package/dist/index.js +751 -268
- package/dist/ipc.js +66 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +43 -18
- package/dist/proxy/service-supervisor.js +78 -35
- package/dist/response-system/engines/v1/index.js +0 -1
- 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 +458 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +204 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +95 -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 +21 -1
- package/dist/trigger/audit.js +19 -4
- package/dist/trigger/authorization.js +14 -5
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/history.js +176 -7
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/manager.js +1 -3
- package/dist/trigger/scheduler.js +78 -5
- package/dist/trigger/script-sandbox.js +118 -22
- package/dist/utils/cross-platform.js +175 -13
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/host-info.js +11 -8
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/npm-ops.js +48 -0
- package/dist/utils/process-introspect.js +109 -10
- package/dist/utils/startup-trace.js +222 -44
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +10 -17
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +5 -2
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/ctl.md +2 -1
- package/kits/docs/evolcore/event-center.md +207 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +3 -2
- package/kits/docs/evolcore/group.md +2 -2
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +21 -0
- package/kits/docs/evolcore/msg.md +27 -8
- package/kits/docs/evolcore/provider.md +23 -3
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +277 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/eck_manifest.json +45 -7
- package/kits/eck_message_manifest.json +3 -3
- package/kits/rules/02-navigation.md +10 -1
- package/kits/rules/06-channel.md +5 -6
- 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/daemon.schema.1.json +5 -0
- package/kits/schemas/daemon.schema.2.json +5 -0
- package/kits/schemas/daemon.schema.3.json +2 -1
- package/kits/schemas/daemon.schema.4.json +2 -1
- package/kits/schemas/daemon.schema.5.json +2 -1
- package/kits/schemas/daemon.schema.6.json +1 -1
- package/kits/schemas/daemon.schema.7.json +1 -1
- package/kits/schemas/daemon.schema.8.json +2 -1
- package/kits/schemas/daemon.schema.9.json +2 -1
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/schemas/role-registry.schema.1.json +2 -2
- package/kits/schemas/single-session.schema.1.json +1 -1
- package/kits/schemas/single-session.schema.2.json +1 -1
- package/kits/schemas/single-session.schema.3.json +1 -1
- 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 +8 -5
- 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/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +9 -7
- package/kits/templates/system-fragments/reply.md +2 -6
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +11 -9
- package/package.json +5 -6
- 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
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
1
|
import { logger } from '../../utils/logger.js';
|
|
3
2
|
import { summarizeToolInput, summarizeToolInputForDisplay, toolInputForDisplay } from '../../utils/tool-summary.js';
|
|
4
3
|
import { getErrorMessage, getToolResultErrorText, isContextTooLongText } from '../../utils/error-utils.js';
|
|
@@ -38,8 +37,7 @@ export class IMRenderer {
|
|
|
38
37
|
/** 串行发送队列:保证消息按序到达 */
|
|
39
38
|
sendChain = Promise.resolve();
|
|
40
39
|
activityRecordChain = Promise.resolve();
|
|
41
|
-
|
|
42
|
-
/** proactive:是否已发过 text 文本(用于去重 complete.result) */
|
|
40
|
+
/** 是否已投影 text 文本(用于去重 complete.result)。 */
|
|
43
41
|
hasEmittedText = false;
|
|
44
42
|
/** 自增 callId 兜底(runner 没提供时用) */
|
|
45
43
|
syntheticCallSeq = 0;
|
|
@@ -79,6 +77,9 @@ export class IMRenderer {
|
|
|
79
77
|
return true;
|
|
80
78
|
return this.opts.suppressIntermediateText ?? this.opts.suppressActivities ?? false;
|
|
81
79
|
}
|
|
80
|
+
usesProactiveBehavior() {
|
|
81
|
+
return this.opts.envelope.chatmode === 'proactive';
|
|
82
|
+
}
|
|
82
83
|
// ── 公开接口 ──
|
|
83
84
|
/** 推入 AgentEvent,按 chatmode 投影 */
|
|
84
85
|
emit(event, suppressTextProjection = false) {
|
|
@@ -106,7 +107,7 @@ export class IMRenderer {
|
|
|
106
107
|
catch {
|
|
107
108
|
// logger.event 失败不影响业务
|
|
108
109
|
}
|
|
109
|
-
if (this.
|
|
110
|
+
if (this.usesProactiveBehavior() && !suppressTextProjection) {
|
|
110
111
|
this.emitProactive(event);
|
|
111
112
|
}
|
|
112
113
|
// interactive 模式由 MessageProcessor 显式调 addText/addToolCall/... 推入 items
|
|
@@ -114,7 +115,7 @@ export class IMRenderer {
|
|
|
114
115
|
/** 强制刷新所有 pending 事件 */
|
|
115
116
|
async flush(isFinal, attention) {
|
|
116
117
|
await this.activityRecordChain;
|
|
117
|
-
if (this.
|
|
118
|
+
if (this.usesProactiveBehavior()) {
|
|
118
119
|
if (isFinal) {
|
|
119
120
|
const pending = this.deferredProactiveText;
|
|
120
121
|
this.deferredProactiveText = [];
|
|
@@ -127,7 +128,7 @@ export class IMRenderer {
|
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
|
-
//
|
|
131
|
+
// Proactive behavior is fire-and-forget; only release any held tool results.
|
|
131
132
|
this.releaseHeldToolResults();
|
|
132
133
|
await this.activityRecordChain;
|
|
133
134
|
return;
|
|
@@ -136,17 +137,17 @@ export class IMRenderer {
|
|
|
136
137
|
}
|
|
137
138
|
/** 仅 flush activities,保留 textBuffer(用于中间 complete 事件) */
|
|
138
139
|
async flushActivitiesOnly() {
|
|
139
|
-
if (this.
|
|
140
|
+
if (this.usesProactiveBehavior())
|
|
140
141
|
return;
|
|
141
142
|
return this.flushActivitiesInternal();
|
|
142
143
|
}
|
|
143
144
|
/** 是否有 pending 内容 */
|
|
144
145
|
hasContent() {
|
|
145
|
-
return
|
|
146
|
+
return this.textBuffer.length > 0 || this.deferredProactiveText.length > 0 || this.itemsQueue.some(it => it.kind !== 'text') || this.hasHeldToolResults();
|
|
146
147
|
}
|
|
147
148
|
/** 是否有会抑制兜底错误消息的正文/过程内容;lifecycle 边界不算。 */
|
|
148
149
|
hasNonLifecycleContent() {
|
|
149
|
-
return
|
|
150
|
+
return this.textBuffer.trim().length > 0 || this.hasHeldToolResults() || this.itemsQueue.some(it => {
|
|
150
151
|
if (it.kind === 'text')
|
|
151
152
|
return it.text.trim().length > 0;
|
|
152
153
|
if (this.subtaskItems.has(it))
|
|
@@ -162,14 +163,12 @@ export class IMRenderer {
|
|
|
162
163
|
}
|
|
163
164
|
/** 是否有待发送的文本 */
|
|
164
165
|
hasTextPending() {
|
|
165
|
-
return
|
|
166
|
+
return this.textBuffer.length > 0;
|
|
166
167
|
}
|
|
167
168
|
/** flush 当前 textBuffer 作为独立的 result.text(非 final),然后清空 buffer */
|
|
168
169
|
async flushText() {
|
|
169
|
-
if (this.
|
|
170
|
+
if (this.usesProactiveBehavior())
|
|
170
171
|
return;
|
|
171
|
-
if (this.pendingAutomaticText)
|
|
172
|
-
await this.retryAutomaticText();
|
|
173
172
|
if (this.textBuffer.length === 0)
|
|
174
173
|
return;
|
|
175
174
|
// 文件标记过滤后若只剩空白,应立即消费;尤其避免 final-only
|
|
@@ -208,12 +207,10 @@ export class IMRenderer {
|
|
|
208
207
|
};
|
|
209
208
|
this.sentContent = true;
|
|
210
209
|
try {
|
|
211
|
-
await this.
|
|
210
|
+
await this.sendPayload(payload);
|
|
212
211
|
}
|
|
213
212
|
catch (error) {
|
|
214
|
-
|
|
215
|
-
if (this.opts.envelope.chatmode !== 'paactive')
|
|
216
|
-
this.textBuffer = rawText + this.textBuffer;
|
|
213
|
+
this.textBuffer = rawText + this.textBuffer;
|
|
217
214
|
throw error;
|
|
218
215
|
}
|
|
219
216
|
this.lastFlush = Date.now();
|
|
@@ -237,7 +234,6 @@ export class IMRenderer {
|
|
|
237
234
|
this.textBuffer = '';
|
|
238
235
|
this.allText = '';
|
|
239
236
|
this.deferredProactiveText = [];
|
|
240
|
-
this.pendingAutomaticText = undefined;
|
|
241
237
|
}
|
|
242
238
|
/** 仅丢弃尚未发送的正文,保留 notice/tool 等活动项。 */
|
|
243
239
|
discardPendingText() {
|
|
@@ -248,16 +244,15 @@ export class IMRenderer {
|
|
|
248
244
|
this.itemsQueue = this.itemsQueue.filter(it => it.kind !== 'text');
|
|
249
245
|
this.textBuffer = '';
|
|
250
246
|
this.deferredProactiveText = [];
|
|
251
|
-
this.pendingAutomaticText = undefined;
|
|
252
247
|
}
|
|
253
248
|
/** 当前 buffer 中尚未 flush 的文本 */
|
|
254
249
|
getRemainingText() {
|
|
255
|
-
return
|
|
250
|
+
return this.textBuffer;
|
|
256
251
|
}
|
|
257
252
|
// ── 文本/活动注入(替代 StreamFlusher.addText/addActivity)──
|
|
258
253
|
/** 添加文本片段(流式 text) */
|
|
259
254
|
async addText(text, outputTokens, turn, assistantUuid, phase) {
|
|
260
|
-
if (this.
|
|
255
|
+
if (this.usesProactiveBehavior())
|
|
261
256
|
return;
|
|
262
257
|
const sameAssistant = this.currentAssistantUuid === assistantUuid;
|
|
263
258
|
// In deferred AUN private delivery, only explicit text_start/tool_use
|
|
@@ -295,7 +290,7 @@ export class IMRenderer {
|
|
|
295
290
|
addToolCall(name, input, callId, descText, turn, outputTokens, assistantUuid) {
|
|
296
291
|
if (callId && this.preflightDenialCallIds.has(callId))
|
|
297
292
|
return;
|
|
298
|
-
if (this.
|
|
293
|
+
if (this.usesProactiveBehavior())
|
|
299
294
|
return;
|
|
300
295
|
this.emitProgress('tool_call', outputTokens, turn, { toolName: name, callId });
|
|
301
296
|
const displayInput = toolInputForDisplay(name, input);
|
|
@@ -328,7 +323,7 @@ export class IMRenderer {
|
|
|
328
323
|
addToolResult(name, ok, result, error, callId, durationMs, descText, classification, assistantUuid) {
|
|
329
324
|
if (callId && this.preflightDenialCallIds.has(callId))
|
|
330
325
|
return;
|
|
331
|
-
if (this.
|
|
326
|
+
if (this.usesProactiveBehavior())
|
|
332
327
|
return;
|
|
333
328
|
const normalizedClassification = !ok
|
|
334
329
|
? normalizeToolErrorClassification(classification ?? {})
|
|
@@ -370,7 +365,7 @@ export class IMRenderer {
|
|
|
370
365
|
if (item.kind !== 'tool_result')
|
|
371
366
|
return;
|
|
372
367
|
this.toolResultCallIds.add(item.call_id);
|
|
373
|
-
if (this.
|
|
368
|
+
if (this.usesProactiveBehavior()) {
|
|
374
369
|
this.emitProactiveItem(item);
|
|
375
370
|
return;
|
|
376
371
|
}
|
|
@@ -495,7 +490,7 @@ export class IMRenderer {
|
|
|
495
490
|
}
|
|
496
491
|
/** 添加进度提示 */
|
|
497
492
|
addProgress(text, opts = {}) {
|
|
498
|
-
if (this.
|
|
493
|
+
if (this.usesProactiveBehavior())
|
|
499
494
|
return;
|
|
500
495
|
if (this.suppressActivityItems())
|
|
501
496
|
return;
|
|
@@ -558,7 +553,7 @@ export class IMRenderer {
|
|
|
558
553
|
...(text !== undefined && { text }),
|
|
559
554
|
...(metadata !== undefined && { metadata }),
|
|
560
555
|
};
|
|
561
|
-
if (this.
|
|
556
|
+
if (this.usesProactiveBehavior()) {
|
|
562
557
|
this.emitProactiveItem(item);
|
|
563
558
|
return;
|
|
564
559
|
}
|
|
@@ -578,7 +573,7 @@ export class IMRenderer {
|
|
|
578
573
|
*/
|
|
579
574
|
addSubtaskActivity(item) {
|
|
580
575
|
this.subtaskItems.add(item);
|
|
581
|
-
if (this.
|
|
576
|
+
if (this.usesProactiveBehavior()) {
|
|
582
577
|
this.emitProactiveItem(item);
|
|
583
578
|
return;
|
|
584
579
|
}
|
|
@@ -605,7 +600,7 @@ export class IMRenderer {
|
|
|
605
600
|
/** 添加系统提示 / 通知。force=true 仅跳过入队门禁;最终 flush 仍遵守 activity 抑制。 */
|
|
606
601
|
addNotice(text, severity, subtype, force = false) {
|
|
607
602
|
// proactive 模式:只放行真·终态错误,机务噪音(压缩/重试)和 emit 已覆盖的 subtype 均不发。
|
|
608
|
-
if (this.
|
|
603
|
+
if (this.usesProactiveBehavior()) {
|
|
609
604
|
if (subtype == null || !IMRenderer.PROACTIVE_NOTICE_ALLOW.has(subtype))
|
|
610
605
|
return;
|
|
611
606
|
this.emitProactiveItem({ kind: 'notice', text, severity, subtype });
|
|
@@ -621,7 +616,7 @@ export class IMRenderer {
|
|
|
621
616
|
}
|
|
622
617
|
/** 通过系统通知发送运行状态,并保持与已有正文的发送顺序。 */
|
|
623
618
|
async sendOperationalNotice(text, subtype) {
|
|
624
|
-
if (!this.opts.operationalNoticesEnabled || this.
|
|
619
|
+
if (!this.opts.operationalNoticesEnabled || this.usesProactiveBehavior() || !text)
|
|
625
620
|
return false;
|
|
626
621
|
if (!this.hasSendableText(text, 'operational-notice'))
|
|
627
622
|
return false;
|
|
@@ -712,51 +707,6 @@ export class IMRenderer {
|
|
|
712
707
|
this.sendChain = handled.catch(() => { });
|
|
713
708
|
return handled;
|
|
714
709
|
}
|
|
715
|
-
/** Model output uses PA's automatic-text outlet.
|
|
716
|
-
* System notices, explicit sends, command receipts and interaction fallbacks bypass it.
|
|
717
|
-
*/
|
|
718
|
-
async sendAutomaticText(payload) {
|
|
719
|
-
if (this.opts.noopSentinel && isNoopText(payload.text, this.opts.noopSentinel))
|
|
720
|
-
return;
|
|
721
|
-
if (this.opts.envelope.chatmode !== 'paactive')
|
|
722
|
-
return this.sendPayload(payload);
|
|
723
|
-
try {
|
|
724
|
-
// Another flush may have started while this one awaited a tool batch.
|
|
725
|
-
// Never replace its in-flight or failed text item with this payload.
|
|
726
|
-
while (this.pendingAutomaticText)
|
|
727
|
-
await this.retryAutomaticText();
|
|
728
|
-
}
|
|
729
|
-
catch (error) {
|
|
730
|
-
// This payload has not been recorded yet; preserve it behind the older
|
|
731
|
-
// pending item so a later flush can retry both without loss or overlap.
|
|
732
|
-
this.textBuffer = payload.text + this.textBuffer;
|
|
733
|
-
throw error;
|
|
734
|
-
}
|
|
735
|
-
const item = {
|
|
736
|
-
kind: 'text',
|
|
737
|
-
text: payload.text,
|
|
738
|
-
...(payload.metadata?.forkAnchor ? { forkAnchor: payload.metadata.forkAnchor } : {}),
|
|
739
|
-
};
|
|
740
|
-
this.recordActivity(item, `activity-${randomUUID().replace(/-/g, '')}`);
|
|
741
|
-
this.pendingAutomaticText = { item };
|
|
742
|
-
await this.retryAutomaticText();
|
|
743
|
-
}
|
|
744
|
-
/** Keep a failed, already-recorded text item separate from newly buffered text. */
|
|
745
|
-
retryAutomaticText() {
|
|
746
|
-
const pending = this.pendingAutomaticText;
|
|
747
|
-
if (!pending)
|
|
748
|
-
return Promise.resolve();
|
|
749
|
-
if (!pending.delivery) {
|
|
750
|
-
pending.delivery = this.sendPayload({ kind: 'activity.batch', items: [pending.item] }).then(() => {
|
|
751
|
-
if (this.pendingAutomaticText === pending)
|
|
752
|
-
this.pendingAutomaticText = undefined;
|
|
753
|
-
}, error => {
|
|
754
|
-
pending.delivery = undefined;
|
|
755
|
-
throw error;
|
|
756
|
-
});
|
|
757
|
-
}
|
|
758
|
-
return pending.delivery;
|
|
759
|
-
}
|
|
760
710
|
scheduleFlush() {
|
|
761
711
|
if (this.timer) {
|
|
762
712
|
return;
|
|
@@ -802,8 +752,6 @@ export class IMRenderer {
|
|
|
802
752
|
const nonThinking = this.itemsQueue.filter(it => it.kind !== 'text');
|
|
803
753
|
if (nonThinking.length === 0)
|
|
804
754
|
return;
|
|
805
|
-
if (this.pendingAutomaticText)
|
|
806
|
-
await this.retryAutomaticText();
|
|
807
755
|
if (this.timer) {
|
|
808
756
|
clearTimeout(this.timer);
|
|
809
757
|
this.timer = undefined;
|
|
@@ -838,8 +786,6 @@ export class IMRenderer {
|
|
|
838
786
|
clearTimeout(this.timer);
|
|
839
787
|
this.timer = undefined;
|
|
840
788
|
}
|
|
841
|
-
if (this.pendingAutomaticText)
|
|
842
|
-
await this.retryAutomaticText();
|
|
843
789
|
// 显式 flush(轮次结束、出错收尾)时放出被扣住的后台占位结果;定时 flush 不放,
|
|
844
790
|
// 否则长时间后台任务会在终态到达前就把占位结果发出去。放出的结果随本次 flush 一起发,
|
|
845
791
|
// 不需要它重新挂上的定时器。
|
|
@@ -925,11 +871,10 @@ export class IMRenderer {
|
|
|
925
871
|
};
|
|
926
872
|
this.sentContent = true;
|
|
927
873
|
try {
|
|
928
|
-
await this.
|
|
874
|
+
await this.sendPayload(payload);
|
|
929
875
|
}
|
|
930
876
|
catch (error) {
|
|
931
|
-
|
|
932
|
-
this.textBuffer = text + this.textBuffer;
|
|
877
|
+
this.textBuffer = text + this.textBuffer;
|
|
933
878
|
throw error;
|
|
934
879
|
}
|
|
935
880
|
this.lastFlush = Date.now();
|
|
@@ -947,11 +892,10 @@ export class IMRenderer {
|
|
|
947
892
|
payload.attention = attention;
|
|
948
893
|
this.sentContent = true;
|
|
949
894
|
try {
|
|
950
|
-
await this.
|
|
895
|
+
await this.sendPayload(payload);
|
|
951
896
|
}
|
|
952
897
|
catch (error) {
|
|
953
|
-
|
|
954
|
-
this.textBuffer = finalText + this.textBuffer;
|
|
898
|
+
this.textBuffer = finalText + this.textBuffer;
|
|
955
899
|
throw error;
|
|
956
900
|
}
|
|
957
901
|
this.lastFlush = Date.now();
|
|
@@ -7,6 +7,7 @@ import path from 'path';
|
|
|
7
7
|
import { agentStorageMenuService, isAgentStorageMenuRequest } from '../command/agent-storage-menu.js';
|
|
8
8
|
import { agentMdMenuService } from '../command/agentmd-menu.js';
|
|
9
9
|
import { containsAgentMdMenuRequest } from '../command/agentmd-menu-request.js';
|
|
10
|
+
import { currentContactBinding, sameContactBinding } from './contact-admission.js';
|
|
10
11
|
import { logger, logPreview } from '../../utils/logger.js';
|
|
11
12
|
import { StreamDebouncer } from './stream-debouncer.js';
|
|
12
13
|
import { appendMessageLog, appendMessageLogStrict, buildInboundEntry, isTransientProtocolMessage } from './message-log.js';
|
|
@@ -29,7 +30,7 @@ import { AutoMentionGate } from './auto-mention-gate.js';
|
|
|
29
30
|
import { syncGroupRulesContext } from '../../eck/group-rules-sync.js';
|
|
30
31
|
import { readSoulContent } from '../soul.js';
|
|
31
32
|
import { authorizeAccess, buildAuthSubject } from '../auth/auth-gateway.js';
|
|
32
|
-
import { MenuDiagnosticLimiter, MenuRequestDeduper, hasValidMenuId, menuFailure, menuPayloadFingerprint, menuSuccess, normalizeMenuError, parseMenuControl, validateMenuRequest, evaluateEvolMenuVersionGate, evolMenuResponseTransportMetadata, isAunMenuTokenRequired, menuCommandForName, normalizeMenuResponseTiming, withMenuProcessingTime, logMenuRequestCompleted, logMenuRequestReceived, } from '../command/menu-protocol.js';
|
|
33
|
+
import { MenuDiagnosticLimiter, deliverMenuResponse, isRetryableMenuTransportError, MenuRequestDeduper, hasValidMenuId, menuFailure, menuPayloadFingerprint, menuSuccess, normalizeMenuError, parseMenuControl, validateMenuRequest, evaluateEvolMenuVersionGate, evolMenuResponseTransportMetadata, isAunMenuTokenRequired, menuCommandForName, normalizeMenuResponseTiming, withMenuProcessingTime, beginMenuDeliveryTiming, logMenuRequestCompleted, logMenuRequestReceived, logMenuResponseRetry, } from '../command/menu-protocol.js';
|
|
33
34
|
import { resolveExplicitMenuExecutionContext, validateMenuCatalogArgs, validateMenuValueBatchArgs } from '../command/menu-catalog.js';
|
|
34
35
|
import { MenuTokenStore } from '../command/menu-token-store.js';
|
|
35
36
|
import { SessionRenewService } from '../session/session-renew.js';
|
|
@@ -1785,7 +1786,11 @@ export class MessageBridge {
|
|
|
1785
1786
|
}
|
|
1786
1787
|
}
|
|
1787
1788
|
catch (error) {
|
|
1788
|
-
|
|
1789
|
+
if (isRetryableMenuTransportError(error)) {
|
|
1790
|
+
logger.warn(`[MessageBridge] Retryable response delivery unavailable for ${channelName}:`, error);
|
|
1791
|
+
}
|
|
1792
|
+
else
|
|
1793
|
+
logger.error(`[MessageBridge] Error in onMessage handler for ${channelName}:`, error);
|
|
1789
1794
|
}
|
|
1790
1795
|
finally {
|
|
1791
1796
|
releaseAdmission?.();
|
|
@@ -2054,6 +2059,10 @@ export class MessageBridge {
|
|
|
2054
2059
|
}
|
|
2055
2060
|
return menuSuccess(header, this.cmdHandler.getMenuItems(identity.role, msg.chatType || 'private', msg.isControlChannel ? 'control' : 'agent', authSubject));
|
|
2056
2061
|
case 'menu.query': {
|
|
2062
|
+
if (name === 'menu' && args?.view === 'queries') {
|
|
2063
|
+
const data = await this.cmdHandler.execMenuQueryBatch(channel, msg.channelId, authSubject, args, msg.isControlChannel ? 'control' : 'agent', transportReplyContext);
|
|
2064
|
+
return menuSuccess(header, data);
|
|
2065
|
+
}
|
|
2057
2066
|
if (name === 'menu' && args?.view === 'values') {
|
|
2058
2067
|
validateMenuValueBatchArgs(args);
|
|
2059
2068
|
const data = await this.cmdHandler.execMenuValueBatch(channel, msg.channelId, authSubject, args, args.context, msg.isControlChannel ? 'control' : 'agent', transportReplyContext);
|
|
@@ -2182,9 +2191,51 @@ export class MessageBridge {
|
|
|
2182
2191
|
agentName,
|
|
2183
2192
|
replyContext,
|
|
2184
2193
|
});
|
|
2194
|
+
const selfAid = this.menuTokenOwnerAid(channel, msg);
|
|
2195
|
+
const binding = selfAid ? currentContactBinding(selfAid) : undefined;
|
|
2196
|
+
const currentSubject = () => buildAuthSubject({
|
|
2197
|
+
selfAid, actorId: msg.peerId, channel, channelType: msg.channelType || 'aun',
|
|
2198
|
+
channelId: msg.channelId, chatType: msg.chatType || 'private', conversationId: msg.channelId,
|
|
2199
|
+
peerType: msg.peerType,
|
|
2200
|
+
roleDetail: this.resolveInboundRole({ selfAid, channelKey: channel, channelType: msg.channelType || 'aun',
|
|
2201
|
+
chatType: msg.chatType || 'private', actorId: msg.peerId, conversationId: msg.channelId, peerType: msg.peerType }),
|
|
2202
|
+
fromControlChannel: msg.isControlChannel, processOwners: [...(this.processOwnersProvider?.() ?? [])],
|
|
2203
|
+
});
|
|
2204
|
+
// A changed role must not receive a cached response authorized by its old role.
|
|
2205
|
+
const initialSubject = msg.channelType === 'aun' && !response.error ? currentSubject() : undefined;
|
|
2206
|
+
const deliveryTiming = beginMenuDeliveryTiming(msg);
|
|
2207
|
+
let deliveryOutcome;
|
|
2185
2208
|
try {
|
|
2186
|
-
await
|
|
2187
|
-
|
|
2209
|
+
await deliverMenuResponse(async () => {
|
|
2210
|
+
Object.assign(timedResponse, withMenuProcessingTime(timedResponse, msg));
|
|
2211
|
+
await adapter.send(envelope, { kind: 'custom', channelType: channel, payload: timedResponse });
|
|
2212
|
+
}, {
|
|
2213
|
+
canRetry: async () => {
|
|
2214
|
+
if (msg.channelType !== 'aun' || !selfAid || !binding
|
|
2215
|
+
|| !sameContactBinding(binding, currentContactBinding(selfAid)))
|
|
2216
|
+
return false;
|
|
2217
|
+
if (this.processor.getChannelInfo?.(channel)?.adapter !== adapter)
|
|
2218
|
+
return false;
|
|
2219
|
+
if (response.error)
|
|
2220
|
+
return true;
|
|
2221
|
+
const subject = currentSubject();
|
|
2222
|
+
if (!authorizeAccess(subject).allow || subject.role !== initialSubject?.role
|
|
2223
|
+
|| subject.processRole !== initialSubject.processRole)
|
|
2224
|
+
return false;
|
|
2225
|
+
if (isAunMenuTokenRequired() && request.type !== 'menu.token.request'
|
|
2226
|
+
&& !this.menuTokenStore.use(selfAid, msg.peerId, request.menu_token, { deviceId: msg.peerDeviceId, slotId: msg.peerSlotId }))
|
|
2227
|
+
return false;
|
|
2228
|
+
if (isAgentStorageMenuRequest(request))
|
|
2229
|
+
agentStorageMenuService.preflight(request, { ...subject, menuEncrypted: msg.encrypted === true }, false);
|
|
2230
|
+
if (containsAgentMdMenuRequest(request))
|
|
2231
|
+
await agentMdMenuService.preflight({ ...subject, menuEncrypted: msg.encrypted === true, menuTransportChatType: msg.chatType || 'private' });
|
|
2232
|
+
return sameContactBinding(binding, currentContactBinding(selfAid))
|
|
2233
|
+
&& this.processor.getChannelInfo?.(channel)?.adapter === adapter;
|
|
2234
|
+
},
|
|
2235
|
+
onRetry: (attempt, error, delay) => logMenuResponseRetry(request, flowContext, attempt, delay, error),
|
|
2236
|
+
onComplete: outcome => { deliveryOutcome = outcome; },
|
|
2237
|
+
});
|
|
2238
|
+
logMenuRequestCompleted(request, timedResponse, flowContext, { delivery: 'sent', ...deliveryOutcome, ...deliveryTiming() });
|
|
2188
2239
|
const upgradeData = 'data' in response ? response.data : undefined;
|
|
2189
2240
|
if (request.type === 'menu.action' && request.action === 'upgrade' && (request.name === 'system' || request.cmd === '/system') && upgradeData?.jobId) {
|
|
2190
2241
|
const jobId = upgradeData.jobId;
|
|
@@ -2201,6 +2252,8 @@ export class MessageBridge {
|
|
|
2201
2252
|
delivery: 'failed',
|
|
2202
2253
|
reason: 'transport-error',
|
|
2203
2254
|
transportError: error,
|
|
2255
|
+
...deliveryOutcome,
|
|
2256
|
+
...deliveryTiming(),
|
|
2204
2257
|
});
|
|
2205
2258
|
throw error;
|
|
2206
2259
|
}
|
|
@@ -50,12 +50,16 @@ export class MessageQueue {
|
|
|
50
50
|
queueKeyToSessionKey = new Map(); // queueKey → sessionKey(human-readable 格式)
|
|
51
51
|
droppedTriggerSessionIds = new Set();
|
|
52
52
|
shuttingDown = false;
|
|
53
|
+
blockedReason;
|
|
54
|
+
blockedQueues = new Map();
|
|
55
|
+
readinessRetry;
|
|
53
56
|
shutdownPromise;
|
|
54
57
|
/** 逻辑队列桥接:管理出队顺序(响应模式可注入自定义策略,默认 FIFO) */
|
|
55
58
|
logicalQueue = new LogicalQueueBridge();
|
|
56
59
|
enqueueSequence = 0;
|
|
57
60
|
constructor(handler, options) {
|
|
58
61
|
this.handler = handler;
|
|
62
|
+
this.blockedReason = options?.blockedReason;
|
|
59
63
|
this.persistencePath = options?.persistencePath;
|
|
60
64
|
this.dedupPath = options?.dedupPath
|
|
61
65
|
?? (this.persistencePath ? `${this.persistencePath}.dedup.json` : undefined);
|
|
@@ -694,6 +698,9 @@ export class MessageQueue {
|
|
|
694
698
|
if (this.shutdownPromise)
|
|
695
699
|
return this.shutdownPromise;
|
|
696
700
|
this.shuttingDown = true;
|
|
701
|
+
if (this.readinessRetry)
|
|
702
|
+
clearTimeout(this.readinessRetry);
|
|
703
|
+
this.readinessRetry = undefined;
|
|
697
704
|
const allActive = Array.from(this.activeBatches.entries());
|
|
698
705
|
const active = allActive.filter(([queueKey]) => !this.activeTerminalReasons.has(queueKey));
|
|
699
706
|
const barriers = [];
|
|
@@ -942,11 +949,32 @@ export class MessageQueue {
|
|
|
942
949
|
return restored;
|
|
943
950
|
}
|
|
944
951
|
startRestored() {
|
|
952
|
+
if (this.shuttingDown)
|
|
953
|
+
return;
|
|
945
954
|
for (const [queueKey, queue] of this.queues) {
|
|
946
955
|
if (queue.length > 0 && !this.processing.has(queueKey))
|
|
947
956
|
void this.processNext(queueKey);
|
|
948
957
|
}
|
|
949
958
|
}
|
|
959
|
+
retryBlockedQueues() {
|
|
960
|
+
if (this.readinessRetry || this.shuttingDown)
|
|
961
|
+
return;
|
|
962
|
+
this.readinessRetry = setTimeout(() => {
|
|
963
|
+
this.readinessRetry = undefined;
|
|
964
|
+
for (const key of this.blockedQueues.keys()) {
|
|
965
|
+
const head = this.queues.get(key)?.[0];
|
|
966
|
+
if (!head) {
|
|
967
|
+
this.blockedQueues.delete(key);
|
|
968
|
+
continue;
|
|
969
|
+
}
|
|
970
|
+
if (!this.processing.has(key) && !this.blockedReason?.(head.message))
|
|
971
|
+
void this.processNext(key);
|
|
972
|
+
}
|
|
973
|
+
if (this.blockedQueues.size)
|
|
974
|
+
this.retryBlockedQueues();
|
|
975
|
+
}, 1000);
|
|
976
|
+
this.readinessRetry.unref?.();
|
|
977
|
+
}
|
|
950
978
|
consumeDroppedTriggerSessionIds() {
|
|
951
979
|
const sessionIds = [...this.droppedTriggerSessionIds];
|
|
952
980
|
this.droppedTriggerSessionIds.clear();
|
|
@@ -1221,6 +1249,7 @@ export class MessageQueue {
|
|
|
1221
1249
|
}
|
|
1222
1250
|
const queue = this.queues.get(queueKey);
|
|
1223
1251
|
if (!queue || queue.length === 0) {
|
|
1252
|
+
this.blockedQueues.delete(queueKey);
|
|
1224
1253
|
logger.info(`[Queue] processNext: queue empty, releasing key=${queueKey}`);
|
|
1225
1254
|
this.processing.delete(queueKey);
|
|
1226
1255
|
this.processingAgent.delete(queueKey);
|
|
@@ -1239,6 +1268,19 @@ export class MessageQueue {
|
|
|
1239
1268
|
// 逻辑队列重排:让响应模式的出队策略决定队首(默认 FIFO,不改变顺序)
|
|
1240
1269
|
if (queue[0]?.message.source !== 'owner-inject' && queue[0]?.message.attentionPolicy !== 'interrupt')
|
|
1241
1270
|
this.logicalQueue.reorderPhysical(queueKey, queue);
|
|
1271
|
+
const blocked = this.blockedReason?.(queue[0].message);
|
|
1272
|
+
if (blocked) {
|
|
1273
|
+
if (this.blockedQueues.get(queueKey) !== blocked) {
|
|
1274
|
+
logger.info(`[Queue] waiting: key=${queueKey} dependency=${blocked}`);
|
|
1275
|
+
}
|
|
1276
|
+
this.blockedQueues.set(queueKey, blocked);
|
|
1277
|
+
this.processing.delete(queueKey);
|
|
1278
|
+
this.processingAgent.delete(queueKey);
|
|
1279
|
+
this.activeStates.delete(queueKey);
|
|
1280
|
+
this.retryBlockedQueues();
|
|
1281
|
+
return;
|
|
1282
|
+
}
|
|
1283
|
+
this.blockedQueues.delete(queueKey);
|
|
1242
1284
|
// 贪心合并:群聊按完整时间线,旧路径/私聊按 peerId
|
|
1243
1285
|
const items = this.dequeueGreedy(queue);
|
|
1244
1286
|
// 同步逻辑队列:移除所有被合并处理的消息
|
|
@@ -1385,7 +1427,7 @@ export class MessageQueue {
|
|
|
1385
1427
|
const first = queue.shift();
|
|
1386
1428
|
const result = [first];
|
|
1387
1429
|
if (this.isOriginHandoff(first.message)) {
|
|
1388
|
-
while (queue.length > 0 && this.canMergeOriginHandoffs(first, queue[0])) {
|
|
1430
|
+
while (queue.length > 0 && !this.blockedReason?.(queue[0].message) && this.canMergeOriginHandoffs(first, queue[0])) {
|
|
1389
1431
|
result.push(queue.shift());
|
|
1390
1432
|
}
|
|
1391
1433
|
if (result.length > 1) {
|
|
@@ -1401,7 +1443,7 @@ export class MessageQueue {
|
|
|
1401
1443
|
if (mergeSubmittedResume) {
|
|
1402
1444
|
const remaining = [];
|
|
1403
1445
|
for (const item of queue) {
|
|
1404
|
-
if (!this.isMergeBarrier(item.message) && this.canDequeueAfterSubmittedResume(first, item)) {
|
|
1446
|
+
if (!this.blockedReason?.(item.message) && !this.isMergeBarrier(item.message) && this.canDequeueAfterSubmittedResume(first, item)) {
|
|
1405
1447
|
result.push(item);
|
|
1406
1448
|
}
|
|
1407
1449
|
else {
|
|
@@ -1421,7 +1463,7 @@ export class MessageQueue {
|
|
|
1421
1463
|
else if (mergeGroupTimeline) {
|
|
1422
1464
|
const remaining = [];
|
|
1423
1465
|
for (const item of queue) {
|
|
1424
|
-
if (!this.isMergeBarrier(item.message) && this.canDequeueGroupTimeline(first, item)) {
|
|
1466
|
+
if (!this.blockedReason?.(item.message) && !this.isMergeBarrier(item.message) && this.canDequeueGroupTimeline(first, item)) {
|
|
1425
1467
|
result.push(item);
|
|
1426
1468
|
}
|
|
1427
1469
|
else {
|
|
@@ -1433,7 +1475,7 @@ export class MessageQueue {
|
|
|
1433
1475
|
result.sort((a, b) => this.firstTimestamp(a) - this.firstTimestamp(b));
|
|
1434
1476
|
}
|
|
1435
1477
|
else {
|
|
1436
|
-
while (queue.length > 0 && !this.isMergeBarrier(queue[0].message) && queue[0].message.peerId === mergeKey) {
|
|
1478
|
+
while (queue.length > 0 && !this.blockedReason?.(queue[0].message) && !this.isMergeBarrier(queue[0].message) && queue[0].message.peerId === mergeKey) {
|
|
1437
1479
|
result.push(queue.shift());
|
|
1438
1480
|
}
|
|
1439
1481
|
}
|
|
@@ -33,6 +33,7 @@ export function buildEnvelope(opts) {
|
|
|
33
33
|
channelId: opts.channelId,
|
|
34
34
|
agentName: opts.agentName ?? '<unknown>',
|
|
35
35
|
chatmode: opts.chatmode ?? 'interactive',
|
|
36
|
+
...(opts.activityTransport ? { activityTransport: opts.activityTransport } : {}),
|
|
36
37
|
delivery,
|
|
37
38
|
replyContext,
|
|
38
39
|
causation: opts.causation,
|
|
@@ -64,8 +65,15 @@ export function isDeliveryTarget(value) {
|
|
|
64
65
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
65
66
|
return false;
|
|
66
67
|
const route = value;
|
|
67
|
-
if (route.chatType === 'private')
|
|
68
|
-
|
|
68
|
+
if (route.chatType === 'private') {
|
|
69
|
+
if (route.service === undefined)
|
|
70
|
+
return true;
|
|
71
|
+
const service = route.service;
|
|
72
|
+
// fail-closed:形状不对就判为非法路由,让调用方拿到 AUN_OUTBOUND_ROUTE_REQUIRED,
|
|
73
|
+
// 而不是悄悄走上服务豁免分支绕过联系人准入。
|
|
74
|
+
return !!service && typeof service === 'object' && !Array.isArray(service)
|
|
75
|
+
&& typeof service.type === 'string' && typeof service.requestId === 'string';
|
|
76
|
+
}
|
|
69
77
|
return route.chatType === 'group'
|
|
70
78
|
&& typeof route.groupId === 'string'
|
|
71
79
|
&& route.groupId.trim().length > 0;
|
|
@@ -2,59 +2,33 @@ import { loadSchema } from '../../config/schema-registry.js';
|
|
|
2
2
|
import { resolveEffective } from '../../config/config-manager.js';
|
|
3
3
|
import { resolveRuntimeStringField } from '../role/runtime-policy.js';
|
|
4
4
|
import { isManagementRole } from '../../config/builtin-roles.js';
|
|
5
|
-
|
|
6
|
-
export const CHAT_MODES = ['interactive', 'proactive', 'paactive'];
|
|
5
|
+
export const CHAT_MODES = ['interactive', 'proactive'];
|
|
7
6
|
export function isChatMode(value) {
|
|
8
7
|
return CHAT_MODES.includes(value);
|
|
9
8
|
}
|
|
10
|
-
/**
|
|
11
|
-
export function supportsPaactive(params) {
|
|
12
|
-
const channelType = params.channelType ?? params.peerKey?.split('#')[0];
|
|
13
|
-
return channelType === 'aun'
|
|
14
|
-
&& params.chatType === 'private'
|
|
15
|
-
&& normalizePeerType(params.peerType) === 'human'
|
|
16
|
-
&& params.role === 'owner'
|
|
17
|
-
&& (params.lifecycle === undefined || params.lifecycle === 'active')
|
|
18
|
-
&& (params.sessionType === undefined || params.sessionType === 'main');
|
|
19
|
-
}
|
|
20
|
-
/** Keep unsupported inherited PA settings from becoming output-as-reply mode. */
|
|
9
|
+
/** Apply scene constraints to the configured chat mode. */
|
|
21
10
|
export function chatModeForScene(value, params) {
|
|
22
11
|
if (params.chatType === 'group' || normalizePeerType(params.peerType) === 'group')
|
|
23
12
|
return 'proactive';
|
|
24
|
-
if (value === 'paactive' && supportsPaactive(params))
|
|
25
|
-
return value;
|
|
26
13
|
if (value === 'interactive' || value === 'proactive')
|
|
27
14
|
return value;
|
|
28
|
-
|
|
29
|
-
const kind = normalizePeerType(params.peerType);
|
|
30
|
-
if (kind === 'system' || kind === 'service')
|
|
31
|
-
return 'interactive';
|
|
32
|
-
if (kind === 'agent'
|
|
33
|
-
|| isPrivateChatmodeRoleLocked(chatmodeFieldForPeer(params.chatType, params.peerType), params.role))
|
|
34
|
-
return 'proactive';
|
|
35
|
-
}
|
|
36
|
-
const fallback = chatmodeFactoryDefaults()[chatmodeFieldForPeer(params.chatType, params.peerType)];
|
|
37
|
-
return fallback === 'paactive' ? 'interactive' : fallback;
|
|
15
|
+
return chatmodeFactoryDefaults()[chatmodeFieldForPeer(params.chatType, params.peerType)];
|
|
38
16
|
}
|
|
39
17
|
/** Resolve the effective chat mode from the ConfigManager layering context. */
|
|
40
18
|
export function resolveChatMode(params) {
|
|
41
19
|
let configured;
|
|
42
|
-
let lifecycle = params.lifecycle;
|
|
43
20
|
try {
|
|
44
21
|
const effective = resolveEffective({
|
|
45
22
|
self: params.self,
|
|
46
23
|
peerKey: params.peerKey,
|
|
47
24
|
}, { cache: true });
|
|
48
25
|
configured = effective.chatmode;
|
|
49
|
-
if (lifecycle === undefined)
|
|
50
|
-
lifecycle = resolveAgentLifecycle(effective);
|
|
51
26
|
}
|
|
52
27
|
catch {
|
|
53
28
|
configured = undefined;
|
|
54
29
|
}
|
|
55
30
|
const kind = normalizePeerType(params.peerType);
|
|
56
|
-
// Group conversations always use proactive delivery
|
|
57
|
-
// paactive are private-chat presentation modes.
|
|
31
|
+
// Group conversations always use proactive delivery.
|
|
58
32
|
if (params.chatType === 'group' || kind === 'group')
|
|
59
33
|
return 'proactive';
|
|
60
34
|
// 运行时硬约束(非配置项):system/service 始终 interactive;agent 始终 proactive
|
|
@@ -63,8 +37,7 @@ export function resolveChatMode(params) {
|
|
|
63
37
|
if (kind === 'agent')
|
|
64
38
|
return 'proactive';
|
|
65
39
|
const field = chatmodeFieldForPeer(params.chatType, params.peerType);
|
|
66
|
-
// 人类私聊的基础角色门槛:owner/admin
|
|
67
|
-
// paactive 另由 supportsPaactive 限定为 owner,其余角色直接 proactive。
|
|
40
|
+
// 人类私聊的基础角色门槛:owner/admin 才解析分层配置,其余角色直接 proactive。
|
|
68
41
|
if (isPrivateChatmodeRoleLocked(field, params.role))
|
|
69
42
|
return 'proactive';
|
|
70
43
|
const decision = resolveRuntimeStringField({
|
|
@@ -74,11 +47,11 @@ export function resolveChatMode(params) {
|
|
|
74
47
|
configuredValue: configured?.[field],
|
|
75
48
|
});
|
|
76
49
|
const effectiveValue = decision.effectiveValue;
|
|
77
|
-
return chatModeForScene(effectiveValue,
|
|
50
|
+
return chatModeForScene(effectiveValue, params);
|
|
78
51
|
}
|
|
79
52
|
/**
|
|
80
53
|
* 人类私聊(chatmode.private)是否被角色锁定为 proactive。
|
|
81
|
-
* interactive 需要 owner/admin
|
|
54
|
+
* interactive 需要 owner/admin。
|
|
82
55
|
*/
|
|
83
56
|
export function isPrivateChatmodeRoleLocked(field, role) {
|
|
84
57
|
return field === 'private' && !isManagementRole(role);
|