evolcore 0.0.39 → 0.0.41-test.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +93 -0
- package/README.md +31 -20
- package/bin/codex-managed-hook.mjs +11 -0
- package/bin/ec-safe-output.js +25 -3
- package/dist/agents/baseagent-availability.js +1 -0
- package/dist/agents/claude-runner.js +53 -152
- package/dist/agents/codex-runner.js +485 -241
- package/dist/agents/ecagent-runner.js +48 -18
- package/dist/agents/gemini-runner.js +27 -8
- package/dist/agents/runner-types.js +39 -9
- package/dist/aun/ability-device-routing.js +26 -0
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/aid/control-aid.js +23 -98
- package/dist/aun/aid/ownership-operation.js +1 -3
- package/dist/aun/group/identity.js +8 -0
- package/dist/aun/group/invite-service.js +6 -0
- package/dist/aun/msg/managed-operation.js +4 -4
- package/dist/aun/msg/p2p.js +28 -12
- package/dist/aun/storage/download.js +30 -0
- package/dist/aun/storage/index.js +14 -6
- package/dist/channels/aun.js +99 -52
- package/dist/channels/daemon.js +24 -4
- package/dist/channels/dingtalk.js +8 -2
- package/dist/channels/feishu.js +6 -1
- package/dist/channels/wecom.js +7 -3
- package/dist/cli/agent-command.js +2 -0
- package/dist/cli/agent-create.js +121 -23
- package/dist/cli/agent.js +10 -3
- package/dist/cli/aid-bind-command.js +4 -1
- package/dist/cli/aun-commands.js +82 -22
- package/dist/cli/daemon-commands.js +260 -26
- package/dist/cli/index.js +25 -13
- package/dist/cli/memory-command.js +33 -14
- package/dist/cli/restart-monitor.js +52 -13
- package/dist/cli/session-command.js +128 -13
- package/dist/cli/stats.js +60 -4
- package/dist/cli/task-context.js +1 -0
- package/dist/cli/trigger-command.js +2 -2
- package/dist/config/access-policy.js +2 -0
- package/dist/config/config-field-policy.js +1 -0
- package/dist/config/config-operation-service.js +17 -6
- package/dist/config/gateway-config.js +1 -1
- package/dist/config/peer-role-resolver.js +10 -8
- package/dist/contracts/ecweb-service-protocol.js +44 -0
- package/dist/core/agent-application-service.js +11 -1
- package/dist/core/agent-ipc-registration.js +4 -0
- package/dist/core/agent-runtime.js +6 -0
- package/dist/core/auth/agent-delegation.js +87 -9
- package/dist/core/auth/auth-gateway.js +3 -1
- package/dist/core/auth/authorization-audit.js +25 -4
- package/dist/core/auth/debug-context.js +5 -1
- package/dist/core/auth/operation-catalog.js +24 -0
- package/dist/core/command/agent-control.js +91 -12
- package/dist/core/command/command-handler.js +64 -47
- package/dist/core/command/connect-menu.js +23 -2
- package/dist/core/command/menu-catalog.js +49 -12
- package/dist/core/command/menu-handler.js +110 -105
- package/dist/core/command/menu-protocol.js +29 -3
- package/dist/core/command/role-menu.js +7 -6
- package/dist/core/command/slash-gate.js +22 -5
- package/dist/core/command/slash-handler.js +121 -102
- package/dist/core/event-catalog.js +17 -0
- package/dist/core/interaction-router.js +2 -1
- package/dist/core/ipc-registration.js +44 -8
- package/dist/core/memory/batch-meta.js +2 -0
- package/dist/core/memory/consolidation-context.js +42 -51
- package/dist/core/memory/consolidation-ops-records.js +39 -7
- package/dist/core/memory/consolidation-trigger.js +72 -65
- package/dist/core/memory/consolidation.js +226 -20
- package/dist/core/memory/memory-writer.js +160 -34
- package/dist/core/memory/relation-idle-monitor.js +287 -0
- package/dist/core/memory/relation-sweep.js +206 -0
- package/dist/core/message/aun-ipc-sender.js +31 -5
- package/dist/core/message/aun-request-registry.js +97 -3
- package/dist/core/message/im-renderer.js +4 -0
- package/dist/core/message/message-admission.js +8 -4
- package/dist/core/message/message-bridge.js +96 -53
- package/dist/core/message/message-log.js +72 -0
- package/dist/core/message/message-queue.js +11 -5
- package/dist/core/message/outbound.js +70 -0
- package/dist/core/message/peer-mode.js +7 -2
- package/dist/core/message/response-engine.js +633 -191
- package/dist/core/model/model-catalog.js +7 -6
- package/dist/core/ownership/owner-resolver.js +384 -178
- package/dist/core/permission/ec-command-parser.js +129 -8
- package/dist/core/permission/tool-policy.js +35 -14
- package/dist/core/role/runtime-policy.js +64 -0
- package/dist/core/session/session-capsule.js +197 -0
- package/dist/core/session/session-manager.js +172 -18
- package/dist/core/session/session-mapper.js +2 -0
- package/dist/core/system-session/memory.js +3 -18
- package/dist/ecweb/basic-settings-service.js +709 -0
- package/dist/ecweb/providers-service.js +172 -0
- package/dist/index.js +95 -7
- package/dist/ipc.js +100 -19
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +48 -0
- package/dist/stats/index.js +3 -3
- package/dist/stats/price-resolver.js +304 -5
- package/dist/stats/query.js +328 -3
- package/dist/stats/writer.js +79 -6
- package/dist/trigger/application-service.js +12 -0
- package/dist/trigger/authorization.js +2 -2
- package/dist/trigger/feedback.js +18 -7
- package/dist/trigger/history.js +36 -0
- package/dist/trigger/manager.js +20 -3
- package/dist/trigger/parser.js +6 -3
- package/dist/trigger/patch.js +1 -1
- package/dist/trigger/scheduler.js +3 -0
- package/dist/trigger/system-definitions.js +43 -7
- package/dist/trigger/validation.js +13 -5
- package/dist/utils/ecweb-supervisor.js +31 -10
- package/dist/utils/error-utils.js +22 -4
- package/dist/utils/evolcore-version.js +3 -2
- package/dist/utils/host-info.js +52 -0
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +1 -1
- package/dist/utils/upgrade-jobs.js +45 -5
- package/ecagent/dist/harness/agent-harness.js +4 -1
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/aun/ABILITY_CALLING.md +20 -2
- package/kits/docs/evolcore/INDEX.md +3 -2
- package/kits/docs/evolcore/agent-create.md +3 -2
- package/kits/docs/evolcore/agent.md +1 -1
- package/kits/docs/evolcore/aid.md +29 -12
- package/kits/docs/evolcore/config.md +9 -7
- package/kits/docs/evolcore/event.md +1 -0
- package/kits/docs/evolcore/fs.md +5 -0
- package/kits/docs/evolcore/memory-architecture.md +3 -4
- package/kits/docs/evolcore/memory-consolidation.md +28 -7
- package/kits/docs/evolcore/memory-tags.md +1 -1
- package/kits/docs/evolcore/memory.md +1 -1
- package/kits/docs/evolcore/menu-client.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +38 -0
- package/kits/docs/evolcore/msg.md +18 -2
- package/kits/docs/evolcore/session.md +14 -0
- package/kits/eck_manifest.json +3 -3
- package/kits/rules/04-relation.md +3 -2
- package/kits/schemas/agent-config.schema.13.json +20 -1
- package/kits/skills/aid-ability/SKILL.md +35 -6
- package/kits/templates/memory-consolidation/generalize.md +32 -4
- package/kits/templates/memory-consolidation/notes.md +2 -2
- package/kits/templates/memory-consolidation/promote.md +10 -2
- package/kits/templates/session-capsule/recovery.md +5 -0
- package/kits/templates/session-capsule/renew.md +5 -0
- package/kits/templates/system-fragments/baseagent.md +5 -0
- package/kits/templates/system-fragments/bootstrap.md +6 -6
- package/kits/templates/system-fragments/channel.md +1 -1
- package/kits/templates/system-fragments/memory.md +12 -3
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/{rules/07-memory-and-thread.md → templates/system-fragments/thread.md} +17 -80
- package/package.json +3 -3
- package/dist/stats/billing.js +0 -215
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* relation-sweep.ts — 关系整理链
|
|
3
|
+
*
|
|
4
|
+
* 一个关系空闲 / 兜底到期后,对它依次跑:
|
|
5
|
+
*
|
|
6
|
+
* notes → generalize → promote(仅 owner 关系)→ profile → forget(关系层)
|
|
7
|
+
*
|
|
8
|
+
* 每一步在上一步收尾之后才判定要不要做(notes 新产出的 to-generalize 要被第 2 步看到),
|
|
9
|
+
* 没有候选的步骤跳过,一个候选都没有就一个会话都不起。所有步骤走同一个整理队列,同 agent 串行。
|
|
10
|
+
* 触发来源记为 `relation-idle`,静默不反馈。
|
|
11
|
+
*
|
|
12
|
+
* 链中途收到新入站不中断:兜底本就发生在聊天进行中,主会话只写 pending,链写 consolidated。
|
|
13
|
+
*
|
|
14
|
+
* 群聊 notes 会按发言人用 `--peer` 把记忆写进发言人自己的关系。那些关系不一定有入站
|
|
15
|
+
* (发言人从不私聊),所以链结束时把它们交给 onSweepFinished 的 touchedPeerKeys,
|
|
16
|
+
* 由调用方各自补一轮整理(不再继续传播)。
|
|
17
|
+
*/
|
|
18
|
+
import { logger } from '../../utils/logger.js';
|
|
19
|
+
import { RELATION_SWEEP_ORDER, isRelationModeDue } from './consolidation-trigger.js';
|
|
20
|
+
/** 单步整理会话迟迟不收尾时,链最多等这么久就放弃(整理会话自身 15 分钟超时,留余量)。 */
|
|
21
|
+
const DEFAULT_STEP_WATCHDOG_MS = 30 * 60_000;
|
|
22
|
+
/**
|
|
23
|
+
* 写进会话 metadata 的 relationSweepId 带上步骤序号:`<链 id>#<步骤序号>`。
|
|
24
|
+
* 看门狗放弃的那一步,会话之后才收尾时,回调里的序号对不上当前步骤,直接忽略,
|
|
25
|
+
* 不会被误认成下一步的收尾而让链提前推进。
|
|
26
|
+
*/
|
|
27
|
+
function stepTag(sweepId, step) {
|
|
28
|
+
return `${sweepId}#${step}`;
|
|
29
|
+
}
|
|
30
|
+
function parseStepTag(tag) {
|
|
31
|
+
const idx = tag.lastIndexOf('#');
|
|
32
|
+
if (idx <= 0)
|
|
33
|
+
return undefined;
|
|
34
|
+
const step = Number(tag.slice(idx + 1));
|
|
35
|
+
if (!Number.isInteger(step))
|
|
36
|
+
return undefined;
|
|
37
|
+
return { sweepId: tag.slice(0, idx), step };
|
|
38
|
+
}
|
|
39
|
+
let sweepSeq = 0;
|
|
40
|
+
export class RelationSweepRunner {
|
|
41
|
+
deps;
|
|
42
|
+
sweeps = new Map();
|
|
43
|
+
isModeDue;
|
|
44
|
+
stepWatchdogMs;
|
|
45
|
+
constructor(deps) {
|
|
46
|
+
this.deps = deps;
|
|
47
|
+
this.isModeDue = deps.isModeDue ?? isRelationModeDue;
|
|
48
|
+
this.stepWatchdogMs = deps.stepWatchdogMs ?? DEFAULT_STEP_WATCHDOG_MS;
|
|
49
|
+
}
|
|
50
|
+
/** 开始一条整理链。保证之后恰好调用一次 onSweepFinished。 */
|
|
51
|
+
start(request) {
|
|
52
|
+
const id = `sweep-${Date.now().toString(36)}-${(++sweepSeq).toString(36)}`;
|
|
53
|
+
const state = {
|
|
54
|
+
id,
|
|
55
|
+
request,
|
|
56
|
+
remaining: [...RELATION_SWEEP_ORDER],
|
|
57
|
+
ran: [],
|
|
58
|
+
touched: new Set(),
|
|
59
|
+
step: 0,
|
|
60
|
+
};
|
|
61
|
+
this.sweeps.set(id, state);
|
|
62
|
+
void this.deps.resolveOwner(request.selfAid)
|
|
63
|
+
.catch(() => undefined)
|
|
64
|
+
.then(ownerAid => {
|
|
65
|
+
state.ownerAid = ownerAid;
|
|
66
|
+
return this.advance(state);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** 整理会话收尾回调(来自 finalizer 的 onSessionFinalized)。 */
|
|
70
|
+
onSessionFinalized(info) {
|
|
71
|
+
const state = this.currentStep(info.relationSweepId, info.sessionId);
|
|
72
|
+
if (!state)
|
|
73
|
+
return;
|
|
74
|
+
if (state.request.propagate) {
|
|
75
|
+
for (const peerKey of info.touchedPeerKeys) {
|
|
76
|
+
if (peerKey !== state.request.peerKey)
|
|
77
|
+
state.touched.add(peerKey);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
this.stepDone(state);
|
|
81
|
+
}
|
|
82
|
+
/** 排队后拉起失败的通知(来自 ConsolidationQueue.setLaunchFailedListener)。 */
|
|
83
|
+
onLaunchFailed(params) {
|
|
84
|
+
const state = this.currentStep(params.relationSweepId);
|
|
85
|
+
if (!state)
|
|
86
|
+
return;
|
|
87
|
+
this.stepDone(state);
|
|
88
|
+
}
|
|
89
|
+
/** 回调对应的是某条链**正在等的那一步**时返回该链;过期步骤、无关会话返回 undefined。 */
|
|
90
|
+
currentStep(tag, sessionId) {
|
|
91
|
+
if (tag) {
|
|
92
|
+
const parsed = parseStepTag(tag);
|
|
93
|
+
if (!parsed)
|
|
94
|
+
return undefined;
|
|
95
|
+
const state = this.sweeps.get(parsed.sweepId);
|
|
96
|
+
if (!state || !state.waiting || state.step !== parsed.step)
|
|
97
|
+
return undefined;
|
|
98
|
+
return state;
|
|
99
|
+
}
|
|
100
|
+
// 收尾时读不到会话 metadata(会话记录已丢失):按会话 ID 认领
|
|
101
|
+
if (!sessionId)
|
|
102
|
+
return undefined;
|
|
103
|
+
for (const state of this.sweeps.values()) {
|
|
104
|
+
if (state.waiting && state.waitingSessionId === sessionId)
|
|
105
|
+
return state;
|
|
106
|
+
}
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
/** 测试与诊断用:在跑的链数量。 */
|
|
110
|
+
get activeCount() {
|
|
111
|
+
return this.sweeps.size;
|
|
112
|
+
}
|
|
113
|
+
stepDone(state) {
|
|
114
|
+
if (state.watchdog)
|
|
115
|
+
clearTimeout(state.watchdog);
|
|
116
|
+
state.watchdog = undefined;
|
|
117
|
+
state.waiting = undefined;
|
|
118
|
+
state.waitingSessionId = undefined;
|
|
119
|
+
void this.advance(state);
|
|
120
|
+
}
|
|
121
|
+
async advance(state) {
|
|
122
|
+
const { selfAid, peerKey, route } = state.request;
|
|
123
|
+
while (state.remaining.length > 0) {
|
|
124
|
+
const mode = state.remaining.shift();
|
|
125
|
+
const agent = this.deps.getAgent(selfAid);
|
|
126
|
+
const memoryConfig = agent?.config?.memory;
|
|
127
|
+
let due = false;
|
|
128
|
+
try {
|
|
129
|
+
due = this.isModeDue({ mode, selfAid, peerKey, ownerAid: state.ownerAid, config: memoryConfig });
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
logger.warn(`[Memory] 关系整理链判定失败(peerKey=${peerKey},mode=${mode}): ${error?.message}`);
|
|
133
|
+
}
|
|
134
|
+
if (!due)
|
|
135
|
+
continue;
|
|
136
|
+
if (!agent?.baseagent)
|
|
137
|
+
break;
|
|
138
|
+
const taskCtx = {
|
|
139
|
+
selfAid,
|
|
140
|
+
peerKey,
|
|
141
|
+
baseagent: agent.baseagent,
|
|
142
|
+
...(route ? {
|
|
143
|
+
channel: route.channel,
|
|
144
|
+
channelId: route.channelId,
|
|
145
|
+
peerId: route.peerId,
|
|
146
|
+
chatType: route.chatType,
|
|
147
|
+
...(route.channelKey ? { channelKey: route.channelKey } : {}),
|
|
148
|
+
...(route.threadId ? { threadId: route.threadId } : {}),
|
|
149
|
+
} : {}),
|
|
150
|
+
};
|
|
151
|
+
// 先挂上等待标记再入队:会话可能在 enqueue 返回前就收尾,收尾回调要能认出这一步
|
|
152
|
+
const token = ++state.step;
|
|
153
|
+
state.waiting = mode;
|
|
154
|
+
let launched = null;
|
|
155
|
+
try {
|
|
156
|
+
launched = await this.deps.enqueue({
|
|
157
|
+
taskCtx,
|
|
158
|
+
mode,
|
|
159
|
+
triggeredBy: 'relation-idle',
|
|
160
|
+
ownerAid: state.ownerAid,
|
|
161
|
+
forgetAfterDays: memoryConfig?.forgetAfterDays,
|
|
162
|
+
...(mode === 'forget' ? { scopeOverride: 'relation' } : {}),
|
|
163
|
+
relationSweepId: stepTag(state.id, token),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
logger.warn(`[Memory] 关系整理链入队失败(peerKey=${peerKey},mode=${mode}): ${error?.message}`);
|
|
168
|
+
}
|
|
169
|
+
if (state.step !== token || state.waiting !== mode) {
|
|
170
|
+
// enqueue 返回前这一步已经收尾,后续由那次 stepDone 推进
|
|
171
|
+
if (launched)
|
|
172
|
+
state.ran.push(mode);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (!launched) {
|
|
176
|
+
// 立即拉起失败:这一步作废,继续下一步
|
|
177
|
+
state.waiting = undefined;
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
state.ran.push(mode);
|
|
181
|
+
if (launched.executionSessionId)
|
|
182
|
+
state.waitingSessionId = launched.executionSessionId;
|
|
183
|
+
state.watchdog = setTimeout(() => {
|
|
184
|
+
logger.warn(`[Memory] 关系整理链等待收尾超时,跳过该步(peerKey=${peerKey},mode=${mode})`);
|
|
185
|
+
this.stepDone(state);
|
|
186
|
+
}, this.stepWatchdogMs);
|
|
187
|
+
state.watchdog.unref?.();
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
this.finish(state);
|
|
191
|
+
}
|
|
192
|
+
finish(state) {
|
|
193
|
+
if (!this.sweeps.delete(state.id))
|
|
194
|
+
return;
|
|
195
|
+
const { selfAid, peerKey } = state.request;
|
|
196
|
+
if (state.ran.length > 0) {
|
|
197
|
+
logger.info(`[Memory] 关系整理链结束(aid=${selfAid},peerKey=${peerKey}):${state.ran.join(' → ')}`);
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
this.deps.onSweepFinished({ selfAid, peerKey, ran: state.ran, touchedPeerKeys: [...state.touched] });
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
logger.warn(`[Memory] 关系整理链结束回调失败(peerKey=${peerKey}): ${error?.message}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveAunSendDevice } from '../../aun/ability-device-routing.js';
|
|
1
2
|
import crypto from 'crypto';
|
|
2
3
|
import { authorizeDelegatedAunMsgSend, } from '../auth/agent-delegation.js';
|
|
3
4
|
import { formatChannelKey, tryParseChannelKey } from '../channel-loader.js';
|
|
@@ -14,7 +15,9 @@ import { sameGroupAid } from '../../aun/group/identity.js';
|
|
|
14
15
|
import { resolveThreadRouteTarget } from '../thread/thread-route.js';
|
|
15
16
|
import { isTopicThreadId, parseMainTopicId, safeFormatMainTopicId, sessionLocalTopicId } from '../thread/topic-id.js';
|
|
16
17
|
import { ThreadService } from '../thread/thread-service.js';
|
|
17
|
-
import { getAunRequestRegistry, requestTtlSeconds } from './aun-request-registry.js';
|
|
18
|
+
import { getAunRequestRegistry, requestDiagnostics, requestTtlSeconds } from './aun-request-registry.js';
|
|
19
|
+
import { parseJsonObjectArgument } from '../permission/ec-command-parser.js';
|
|
20
|
+
const TASK_ID_MESSAGE_PAYLOAD_TYPES = new Set(['text', 'link', 'image', 'video', 'voice', 'file']);
|
|
18
21
|
/** payload.debug 只是诊断字段:取不到时照常发送,不带 debug。 */
|
|
19
22
|
async function resolveOutboundDebug(resolver, sessionId) {
|
|
20
23
|
if (!resolver || !sessionId)
|
|
@@ -241,18 +244,21 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
241
244
|
});
|
|
242
245
|
const sender = async (params) => {
|
|
243
246
|
let textFile;
|
|
247
|
+
let payloadFile;
|
|
244
248
|
try {
|
|
245
249
|
if (params.argv !== undefined) {
|
|
246
250
|
const command = resolveManagedSendArgv(params.argv);
|
|
247
251
|
textFile = command.textFile;
|
|
252
|
+
payloadFile = command.payloadFile;
|
|
248
253
|
params = { ...params, ...command };
|
|
249
254
|
}
|
|
250
255
|
else if (!params.aid || !params.to || !params.scope) {
|
|
251
256
|
return { ok: false, code: 'INVALID_REQUEST', error: 'Managed AUN sends require command parameters' };
|
|
252
257
|
}
|
|
258
|
+
params.deviceId = resolveAunSendDevice(params.deviceId, params.scope, params.payload);
|
|
253
259
|
}
|
|
254
260
|
catch (error) {
|
|
255
|
-
return { ok: false, code: 'INVALID_ARGUMENT', error: error instanceof Error ? error.message : String(error) };
|
|
261
|
+
return { ok: false, code: error.code ?? 'INVALID_ARGUMENT', error: error instanceof Error ? error.message : String(error) };
|
|
256
262
|
}
|
|
257
263
|
// 活跃任务走内存上下文;调试会话(--as-session)和已结束的会话没有内存记录,
|
|
258
264
|
// 这时从会话本身重建,否则跨话题复查会静默不创建(getTaskRuntimeContext 返回 null)。
|
|
@@ -330,7 +336,7 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
330
336
|
? { selfAid: delegation.grant.selfAid, projectPath: runtime.projectPath,
|
|
331
337
|
sessionRuntimeDir: delegation.grant.sessionRuntimeDir, cwd: runtime.projectPath }
|
|
332
338
|
: undefined;
|
|
333
|
-
if ((textFile || params.file) && !fileScope)
|
|
339
|
+
if ((textFile || payloadFile || params.file) && !fileScope)
|
|
334
340
|
throw new Error('Current task project context is unavailable');
|
|
335
341
|
if (textFile) {
|
|
336
342
|
const text = new TextDecoder('utf-8', { fatal: true }).decode(readTriggerLocalFile(textFile, fileScope));
|
|
@@ -338,9 +344,14 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
338
344
|
throw new Error('Message file must contain nonempty UTF-8 text');
|
|
339
345
|
params.payload = { type: 'text', text };
|
|
340
346
|
}
|
|
347
|
+
if (payloadFile) {
|
|
348
|
+
const raw = new TextDecoder('utf-8', { fatal: true }).decode(readTriggerLocalFile(payloadFile, fileScope));
|
|
349
|
+
params.payload = parseJsonObjectArgument(raw, '--payload-file');
|
|
350
|
+
}
|
|
341
351
|
if (params.file) {
|
|
342
352
|
params.file = { ...params.file, filePath: resolveAttachmentLocalPath(params.file.filePath, fileScope) };
|
|
343
353
|
}
|
|
354
|
+
params.deviceId = resolveAunSendDevice(params.deviceId, params.scope, params.payload);
|
|
344
355
|
if (params.payload && params.rawPayload !== true)
|
|
345
356
|
params.payload = withAunAttention(params.payload);
|
|
346
357
|
const currentRelation = runtime?.channel === 'aun' && runtime.selfAid === params.aid
|
|
@@ -350,7 +361,11 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
350
361
|
? params.payload.thread_id.trim() : params.thread ?? (currentRelation ? runtime?.threadId : undefined);
|
|
351
362
|
}
|
|
352
363
|
catch (error) {
|
|
353
|
-
return {
|
|
364
|
+
return {
|
|
365
|
+
ok: false,
|
|
366
|
+
code: error?.code ?? 'INVALID_LOCAL_FILE',
|
|
367
|
+
error: error instanceof Error ? error.message : String(error),
|
|
368
|
+
};
|
|
354
369
|
}
|
|
355
370
|
const inst = channelInstances.find((candidate) => {
|
|
356
371
|
if (candidate.channelType !== 'aun')
|
|
@@ -408,6 +423,10 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
408
423
|
if (!payload) {
|
|
409
424
|
return { ok: false, error: 'message payload is required', code: 'INVALID_PAYLOAD' };
|
|
410
425
|
}
|
|
426
|
+
if (params.rawPayload !== true && runtime?.taskId
|
|
427
|
+
&& typeof payload.type === 'string' && TASK_ID_MESSAGE_PAYLOAD_TYPES.has(payload.type)) {
|
|
428
|
+
payload = { ...payload, task_id: runtime.taskId };
|
|
429
|
+
}
|
|
411
430
|
// 托管 argv 通道(runManagedSend)先前不带 log 元数据:群聊 sendDaemonGroupMsg
|
|
412
431
|
// 自身会写日志,私聊 sendDaemonMsg 只在 args.log 存在时才写,于是同一份
|
|
413
432
|
// `ec msg send` 在私聊下不落 messages.jsonl,话题历史里查不到已发出的消息。
|
|
@@ -464,6 +483,7 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
464
483
|
preparedRequest = getAunRequestRegistry().prepare({
|
|
465
484
|
selfAid: params.aid,
|
|
466
485
|
targetAid: params.to,
|
|
486
|
+
targetDeviceId: params.deviceId,
|
|
467
487
|
payload,
|
|
468
488
|
timeoutMs: params.timeoutMs ?? 60_000,
|
|
469
489
|
...(runtime && delegation.grant ? { origin: {
|
|
@@ -597,6 +617,7 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
597
617
|
}
|
|
598
618
|
const sent = await ch.sendDaemonMsg({
|
|
599
619
|
to: params.to,
|
|
620
|
+
deviceId: params.deviceId,
|
|
600
621
|
payload,
|
|
601
622
|
rawPayload: params.rawPayload,
|
|
602
623
|
ttl: requestTtl,
|
|
@@ -611,7 +632,10 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
611
632
|
const request = getAunRequestRegistry().markFailed(params.aid, preparedRequest.requestId, transportError);
|
|
612
633
|
if (request?.state === 'completed') {
|
|
613
634
|
return { ok: true, request_id: preparedRequest.requestId, request_state: request.state,
|
|
614
|
-
|
|
635
|
+
...(request.responsePayload ? { response: request.responsePayload } : {}),
|
|
636
|
+
...(request.responses ? { responses: request.responses } : {}),
|
|
637
|
+
...(request ? { request_diagnostics: requestDiagnostics(request) } : {}),
|
|
638
|
+
transport_error: transportError, retryable: false, sent: true };
|
|
615
639
|
}
|
|
616
640
|
return { ...sent, ok: false, request_id: preparedRequest.requestId, request_state: request?.state ?? 'failed' };
|
|
617
641
|
}
|
|
@@ -622,6 +646,8 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
|
|
|
622
646
|
request_id: preparedRequest.requestId,
|
|
623
647
|
request_state: completed?.state ?? 'unknown',
|
|
624
648
|
...(completed?.responsePayload ? { response: completed.responsePayload } : {}),
|
|
649
|
+
...(completed?.responses ? { responses: completed.responses } : {}),
|
|
650
|
+
...(completed ? { request_diagnostics: requestDiagnostics(completed) } : {}),
|
|
625
651
|
};
|
|
626
652
|
}
|
|
627
653
|
if (params.thread && params.checkEveryMs !== undefined && sent.ok && sent.message_id && threadRoute) {
|
|
@@ -3,6 +3,31 @@ import path from 'path';
|
|
|
3
3
|
import crypto from 'crypto';
|
|
4
4
|
import { resolvePaths } from '../../paths.js';
|
|
5
5
|
import { appendJsonlDurable } from '../session/session-fs-store.js';
|
|
6
|
+
import { isAidWideDeviceStatusQuery } from '../../aun/ability-device-routing.js';
|
|
7
|
+
export function requestDiagnostics(record) {
|
|
8
|
+
const ignoredReason = record.lastIgnoredResponse?.reason;
|
|
9
|
+
const unresolved = record.state !== 'completed' && record.state !== 'failed';
|
|
10
|
+
return {
|
|
11
|
+
state: record.state,
|
|
12
|
+
...(record.responseMode ? { responseMode: record.responseMode } : {}),
|
|
13
|
+
...(record.responses ? { responseCount: record.responses.length } : {}),
|
|
14
|
+
...(record.targetDeviceId ? { targetDeviceId: record.targetDeviceId } : {}),
|
|
15
|
+
...(record.responseDeviceId ? { responseDeviceId: record.responseDeviceId } : {}),
|
|
16
|
+
...(record.transportStatus ? { transportStatus: record.transportStatus } : {}),
|
|
17
|
+
ackReceived: !!record.ackMessageId,
|
|
18
|
+
...(record.ackMessageId ? { ackMessageId: record.ackMessageId } : {}),
|
|
19
|
+
...(record.deadlineAt !== undefined ? { deadlineAt: record.deadlineAt } : {}),
|
|
20
|
+
updatedAt: record.updatedAt,
|
|
21
|
+
...(record.lastIgnoredResponse ? { lastIgnoredResponse: record.lastIgnoredResponse } : {}),
|
|
22
|
+
...(unresolved && (ignoredReason === 'response_device_mismatch' || ignoredReason === 'response_device_id_missing')
|
|
23
|
+
? { reason: ignoredReason }
|
|
24
|
+
: record.state === 'pending' && record.ackMessageId
|
|
25
|
+
? { reason: 'provider_ack_without_final_result' }
|
|
26
|
+
: record.state === 'pending'
|
|
27
|
+
? { reason: 'no_final_response_before_deadline' }
|
|
28
|
+
: {}),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
6
31
|
const DEFAULT_REQUEST_TIMEOUT_MS = 60_000;
|
|
7
32
|
const MAX_TIMER_MS = 2_147_483_647;
|
|
8
33
|
/** AUN message.send accepts volatile TTL values from 1 through 3600 seconds. */
|
|
@@ -107,6 +132,7 @@ export class AunRequestRegistry {
|
|
|
107
132
|
const record = {
|
|
108
133
|
selfAid: params.selfAid,
|
|
109
134
|
targetAid: params.targetAid,
|
|
135
|
+
...(params.targetDeviceId ? { targetDeviceId: params.targetDeviceId } : {}),
|
|
110
136
|
requestId: chosen,
|
|
111
137
|
correlationKind,
|
|
112
138
|
correlationKeys: keys,
|
|
@@ -115,6 +141,15 @@ export class AunRequestRegistry {
|
|
|
115
141
|
createdAt: now,
|
|
116
142
|
updatedAt: now,
|
|
117
143
|
deadlineAt: now + timeoutMs,
|
|
144
|
+
...(!params.targetDeviceId && isAidWideDeviceStatusQuery(params.payload) ? {
|
|
145
|
+
responseMode: 'all_devices',
|
|
146
|
+
responseCorrelation: {
|
|
147
|
+
abilityPath: params.payload.ability_path,
|
|
148
|
+
definitionId: params.payload.definition_id,
|
|
149
|
+
operationId: params.payload.operation_id,
|
|
150
|
+
},
|
|
151
|
+
responses: [],
|
|
152
|
+
} : {}),
|
|
118
153
|
};
|
|
119
154
|
const payload = { ...params.payload };
|
|
120
155
|
if (!requestId && !callId)
|
|
@@ -136,6 +171,9 @@ export class AunRequestRegistry {
|
|
|
136
171
|
const current = this.get(selfAid, requestId);
|
|
137
172
|
if (current?.state === 'completed' || current?.state === 'failed')
|
|
138
173
|
return current;
|
|
174
|
+
if (current?.responseMode === 'all_devices' && current.responses?.length) {
|
|
175
|
+
return this.update(selfAid, requestId, { state: 'completed', error });
|
|
176
|
+
}
|
|
139
177
|
return this.update(selfAid, requestId, { state: 'failed', error });
|
|
140
178
|
}
|
|
141
179
|
update(selfAid, requestId, patch) {
|
|
@@ -170,9 +208,51 @@ export class AunRequestRegistry {
|
|
|
170
208
|
const payload = params.payload;
|
|
171
209
|
const keys = [stringValue(payload.request_id), stringValue(payload.call_id)].filter((value) => !!value);
|
|
172
210
|
for (const key of keys) {
|
|
173
|
-
const record = this.
|
|
211
|
+
const record = this.get(params.selfAid, key);
|
|
174
212
|
if (!record || record.targetAid !== params.fromAid || ['failed', 'completed'].includes(record.state))
|
|
175
213
|
continue;
|
|
214
|
+
if (record.targetDeviceId && record.targetDeviceId !== params.fromDeviceId) {
|
|
215
|
+
const reason = params.fromDeviceId
|
|
216
|
+
? 'response_device_mismatch'
|
|
217
|
+
: 'response_device_id_missing';
|
|
218
|
+
return this.updateWithoutNotify(params.selfAid, record.requestId, {
|
|
219
|
+
lastIgnoredResponse: {
|
|
220
|
+
messageId: params.messageId,
|
|
221
|
+
...(params.fromDeviceId ? { responseDeviceId: params.fromDeviceId } : {}),
|
|
222
|
+
reason,
|
|
223
|
+
receivedAt: Date.now(),
|
|
224
|
+
},
|
|
225
|
+
ignoredResponseCount: (record.ignoredResponseCount ?? 0) + 1,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
if (record.responseMode === 'all_devices') {
|
|
229
|
+
// Device identity is authenticated transport metadata, never payload data.
|
|
230
|
+
// Keep each device's terminal result and do not finish on the first one.
|
|
231
|
+
if (!stringValue(params.fromDeviceId) || !record.deadlineAt || Date.now() >= record.deadlineAt)
|
|
232
|
+
continue;
|
|
233
|
+
const expected = record.responseCorrelation;
|
|
234
|
+
if (payload.type !== 'ability' || !['ack', 'result'].includes(String(payload.role))
|
|
235
|
+
|| payload.ability_path !== expected?.abilityPath
|
|
236
|
+
|| payload.definition_id !== expected?.definitionId
|
|
237
|
+
|| payload.operation_id !== expected?.operationId)
|
|
238
|
+
continue;
|
|
239
|
+
if (this.isIntermediateResponse(payload)) {
|
|
240
|
+
return this.updateWithoutNotify(params.selfAid, record.requestId, {
|
|
241
|
+
ackMessageId: params.messageId, ackPayload: payload,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
const responses = record.responses ?? [];
|
|
245
|
+
if (responses.some(response => response.responseDeviceId === params.fromDeviceId))
|
|
246
|
+
return record;
|
|
247
|
+
return this.updateWithoutNotify(params.selfAid, record.requestId, {
|
|
248
|
+
responses: [...responses, {
|
|
249
|
+
responseMessageId: params.messageId,
|
|
250
|
+
responseDeviceId: params.fromDeviceId,
|
|
251
|
+
responsePayload: payload,
|
|
252
|
+
receivedAt: Date.now(),
|
|
253
|
+
}],
|
|
254
|
+
});
|
|
255
|
+
}
|
|
176
256
|
if (this.isIntermediateResponse(payload)) {
|
|
177
257
|
return this.updateWithoutNotify(params.selfAid, record.requestId, {
|
|
178
258
|
ackMessageId: params.messageId,
|
|
@@ -182,6 +262,7 @@ export class AunRequestRegistry {
|
|
|
182
262
|
const updated = this.update(params.selfAid, record.requestId, {
|
|
183
263
|
state: 'completed',
|
|
184
264
|
responseMessageId: params.messageId,
|
|
265
|
+
...(params.fromDeviceId ? { responseDeviceId: params.fromDeviceId } : {}),
|
|
185
266
|
responsePayload: payload,
|
|
186
267
|
});
|
|
187
268
|
return updated;
|
|
@@ -191,6 +272,11 @@ export class AunRequestRegistry {
|
|
|
191
272
|
get(selfAid, requestId) {
|
|
192
273
|
this.ensureLoaded(selfAid);
|
|
193
274
|
const record = this.records.get(this.key(selfAid, requestId));
|
|
275
|
+
if (record?.responseMode === 'all_devices' && !['failed', 'completed'].includes(record.state)
|
|
276
|
+
&& record.deadlineAt !== undefined && record.deadlineAt <= Date.now()) {
|
|
277
|
+
const state = record.responses?.length ? 'completed' : 'pending';
|
|
278
|
+
return record.state === state ? record : this.update(selfAid, record.requestId, { state });
|
|
279
|
+
}
|
|
194
280
|
if (record && record.state === 'sent' && record.deadlineAt !== undefined && record.deadlineAt <= Date.now()) {
|
|
195
281
|
return this.update(selfAid, record.requestId, { state: 'pending' });
|
|
196
282
|
}
|
|
@@ -202,8 +288,16 @@ export class AunRequestRegistry {
|
|
|
202
288
|
return current;
|
|
203
289
|
const normalizedTimeoutMs = normalizeTimeoutMs(timeoutMs);
|
|
204
290
|
const waitMs = Math.max(0, Math.min(normalizedTimeoutMs, current.deadlineAt ? current.deadlineAt - Date.now() : normalizedTimeoutMs));
|
|
291
|
+
const finishWindow = () => {
|
|
292
|
+
const record = this.get(selfAid, requestId);
|
|
293
|
+
if (!record || ['completed', 'failed', 'unknown'].includes(record.state))
|
|
294
|
+
return record;
|
|
295
|
+
return this.update(selfAid, requestId, {
|
|
296
|
+
state: record.responseMode === 'all_devices' && record.responses?.length ? 'completed' : 'pending',
|
|
297
|
+
});
|
|
298
|
+
};
|
|
205
299
|
if (waitMs === 0)
|
|
206
|
-
return
|
|
300
|
+
return finishWindow();
|
|
207
301
|
return new Promise(resolve => {
|
|
208
302
|
const key = this.key(selfAid, requestId);
|
|
209
303
|
const callback = (record) => { clearTimeout(timer); resolve(record); };
|
|
@@ -215,7 +309,7 @@ export class AunRequestRegistry {
|
|
|
215
309
|
return;
|
|
216
310
|
if (this.waiters.get(key)?.size === 0)
|
|
217
311
|
this.waiters.delete(key);
|
|
218
|
-
resolve(
|
|
312
|
+
resolve(finishWindow());
|
|
219
313
|
}, waitMs);
|
|
220
314
|
});
|
|
221
315
|
}
|
|
@@ -398,6 +398,10 @@ export class IMRenderer {
|
|
|
398
398
|
durationMs: opts.durationMs,
|
|
399
399
|
});
|
|
400
400
|
}
|
|
401
|
+
/** Durable system notices use the same task route and serialized send queue. */
|
|
402
|
+
async sendSystemNotice(text, subtype) {
|
|
403
|
+
await this.sendPayload({ kind: 'system.notice', text, subtype });
|
|
404
|
+
}
|
|
401
405
|
/** 发送不进入 activity/thought 历史、也不代表执行活跃的任务级 notice。 */
|
|
402
406
|
async sendStatusNotice(message, severity = 'info', subtype, details) {
|
|
403
407
|
const payload = {
|
|
@@ -128,16 +128,20 @@ export function evaluateOrdinaryInboundAdmission(context) {
|
|
|
128
128
|
const policy = context.policy;
|
|
129
129
|
if (!policy)
|
|
130
130
|
return { allow: false, reason: 'invalid_access_policy', context };
|
|
131
|
+
if (context.isOwner)
|
|
132
|
+
return { allow: true, reason: 'owner', context };
|
|
133
|
+
if (context.primaryId && policy.allowedAids?.includes(context.primaryId)) {
|
|
134
|
+
return { allow: true, reason: 'allowed_aid', context };
|
|
135
|
+
}
|
|
136
|
+
if (policy.allowExternalContacts === false) {
|
|
137
|
+
return { allow: false, reason: 'external_contacts_disabled', context };
|
|
138
|
+
}
|
|
131
139
|
if (context.chatType === 'group') {
|
|
132
|
-
if (context.isOwner)
|
|
133
|
-
return { allow: true, reason: 'owner', context };
|
|
134
140
|
if (policy.policyMode === 'open' || policy.policyMode === 'contacts') {
|
|
135
141
|
return { allow: true, reason: 'group_channel_allowed', context };
|
|
136
142
|
}
|
|
137
143
|
return { allow: false, reason: 'owners', context };
|
|
138
144
|
}
|
|
139
|
-
if (context.isOwner)
|
|
140
|
-
return { allow: true, reason: 'owner', context };
|
|
141
145
|
if (policy.policyMode === 'open')
|
|
142
146
|
return { allow: true, reason: 'open', context };
|
|
143
147
|
if (policy.policyMode === 'owners')
|