evolcore 0.0.40 → 0.0.41-test.1
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 +94 -1
- package/bin/codex-managed-hook.mjs +11 -0
- package/bin/ec-safe-output.js +11 -1
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/baseagent.js +20 -43
- package/dist/agents/claude-runner.js +197 -197
- package/dist/agents/codex-runner.js +535 -259
- package/dist/agents/ecagent-runner.js +31 -12
- package/dist/agents/gemini-runner.js +27 -7
- package/dist/agents/runner-types.js +11 -3
- package/dist/aun/ability-device-routing.js +26 -0
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/group/fs-download.js +39 -0
- package/dist/aun/group/identity.js +36 -13
- package/dist/aun/group/operations.js +5 -0
- package/dist/aun/msg/managed-operation.js +72 -11
- package/dist/aun/msg/p2p.js +32 -7
- package/dist/aun/service-proxy.js +36 -12
- package/dist/aun/storage/download.js +30 -0
- package/dist/aun/storage/index.js +14 -6
- package/dist/channels/aun.js +367 -24
- package/dist/channels/daemon.js +39 -5
- package/dist/cli/agent-command.js +2 -0
- package/dist/cli/agent-create.js +98 -19
- package/dist/cli/agent.js +10 -3
- package/dist/cli/aun-commands.js +85 -41
- package/dist/cli/daemon-commands.js +678 -688
- package/dist/cli/fs-command.js +64 -2
- package/dist/cli/index.js +48 -4
- package/dist/cli/managed-command-guard.js +4 -0
- package/dist/cli/model.js +40 -40
- package/dist/cli/proxy-command.js +92 -0
- package/dist/cli/restart-monitor.js +17 -0
- package/dist/cli/role.js +85 -0
- package/dist/cli/session-command.js +128 -13
- package/dist/cli/stats.js +60 -4
- package/dist/cli/trigger-command.js +2 -2
- package/dist/config/access-policy.js +8 -1
- package/dist/config/boot-log.js +38 -1
- package/dist/config/config-field-policy.js +5 -32
- package/dist/config/config-manager.js +46 -39
- package/dist/config/config-operation-service.js +8 -11
- package/dist/config/contact-book-store.js +47 -21
- package/dist/config/contact-book.js +18 -12
- package/dist/config/contact-operation-service.js +3 -4
- package/dist/config/contact-request-service.js +11 -0
- package/dist/config/daemon-services.js +11 -0
- package/dist/config/gateway-config.js +89 -595
- package/dist/config/peer-role-resolver.js +15 -11
- package/dist/config/providers-config.js +12 -7
- package/dist/config/providers-import.js +3 -21
- package/dist/config/resolved-config-op.js +3 -0
- package/dist/config/role-command-service.js +166 -0
- package/dist/config/role-request-service.js +193 -0
- package/dist/config/schema-migration.js +686 -25
- package/dist/config-store.js +79 -3
- package/dist/contracts/ecweb-instance.js +41 -0
- package/dist/contracts/ecweb-service-protocol.js +3 -1
- package/dist/core/agent-application-service.js +11 -1
- package/dist/core/agent-ipc-registration.js +4 -0
- package/dist/core/agent-runtime.js +1 -1
- package/dist/core/auth/agent-delegation.js +82 -6
- package/dist/core/auth/auth-gateway.js +1 -1
- package/dist/core/auth/authorization-audit.js +37 -9
- package/dist/core/auth/delegation-authorization.js +3 -1
- package/dist/core/auth/operation-authorizer.js +15 -0
- package/dist/core/auth/operation-catalog.js +39 -6
- package/dist/core/command/agent-control.js +94 -19
- package/dist/core/command/agent-storage-menu.js +5 -3
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +105 -145
- package/dist/core/command/connect-menu.js +31 -2
- package/dist/core/command/data-root-resolver.js +5 -4
- package/dist/core/command/memory-slash.js +16 -8
- package/dist/core/command/menu-catalog.js +6 -6
- package/dist/core/command/menu-handler.js +87 -163
- package/dist/core/command/menu-protocol.js +9 -2
- package/dist/core/command/role-menu.js +148 -30
- package/dist/core/command/slash-gate.js +13 -10
- package/dist/core/command/slash-handler.js +157 -352
- package/dist/core/daemon-control.js +8 -14
- package/dist/core/event-catalog.js +15 -0
- package/dist/core/evolagent-registry.js +4 -4
- package/dist/core/evolagent.js +2 -2
- package/dist/core/inference/text-inference.js +31 -40
- package/dist/core/ipc-registration.js +24 -3
- package/dist/core/memory/consolidation-context.js +51 -5
- package/dist/core/memory/consolidation-ops-records.js +1 -1
- package/dist/core/memory/consolidation-trigger.js +190 -190
- package/dist/core/memory/consolidation.js +316 -29
- package/dist/core/memory/forget-log.js +96 -0
- package/dist/core/memory/index-manager.js +27 -5
- package/dist/core/memory/memory-admin.js +45 -5
- package/dist/core/memory/memory-writer.js +163 -18
- package/dist/core/memory/relation-idle-monitor.js +119 -58
- package/dist/core/memory/relation-sweep.js +44 -39
- package/dist/core/message/aun-ipc-sender.js +34 -7
- package/dist/core/message/aun-request-registry.js +97 -3
- package/dist/core/message/im-renderer.js +11 -4
- package/dist/core/message/message-admission.js +97 -8
- package/dist/core/message/message-bridge.js +71 -24
- package/dist/core/message/message-log.js +55 -0
- package/dist/core/message/message-queue.js +5 -5
- package/dist/core/message/response-engine.js +387 -144
- package/dist/core/model/catalog-service.js +4 -2
- package/dist/core/model/config-scope.js +24 -64
- package/dist/core/model/field-scope.js +1 -1
- package/dist/core/model/model-catalog.js +37 -47
- package/dist/core/model/model-diagnostics.js +4 -3
- package/dist/core/model/model-fallback.js +10 -7
- package/dist/core/model/model-permission.js +3 -2
- package/dist/core/ownership/owner-resolver.js +25 -23
- package/dist/core/permission/ec-command-parser.js +138 -5
- package/dist/core/permission/sandbox-runtime.js +18 -1
- package/dist/core/permission/tool-policy.js +42 -10
- package/dist/core/relation/peer-identity.js +64 -1
- package/dist/core/role/runtime-policy.js +72 -13
- package/dist/core/session/session-capsule.js +197 -0
- package/dist/core/session/session-idle-monitor.js +1 -1
- package/dist/core/session/session-manager.js +168 -14
- package/dist/core/session/session-mapper.js +2 -0
- package/dist/core/session/session-renew.js +3 -3
- package/dist/core/skill/index-generator.js +15 -5
- package/dist/core/system-session/memory.js +6 -1
- package/dist/core/thread/thread-service.js +19 -6
- package/dist/directory/owner-directory-admission.js +95 -0
- package/dist/directory/owner-directory-authorization.js +309 -0
- package/dist/directory/owner-directory-cache.js +635 -0
- package/dist/eck/kit-renderer.js +2 -2
- package/dist/ecweb/basic-settings-service.js +33 -40
- package/dist/ecweb/message-context-service.js +110 -0
- package/dist/index.js +79 -17
- package/dist/ipc.js +189 -17
- package/dist/paths.js +4 -0
- package/dist/proxy/command.js +122 -0
- package/dist/proxy/ipc-service.js +68 -0
- package/dist/proxy/manager.js +485 -0
- package/dist/proxy/service-supervisor.js +603 -0
- package/dist/response-system/engines/v1/proactive-flow.js +16 -6
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +15 -0
- package/dist/stats/index.js +2 -2
- package/dist/stats/price-resolver.js +304 -5
- package/dist/stats/query.js +82 -3
- package/dist/stats/writer.js +38 -5
- package/dist/trigger/feedback.js +18 -7
- package/dist/trigger/manager.js +20 -3
- package/dist/trigger/parser.js +6 -3
- package/dist/trigger/patch.js +1 -1
- package/dist/trigger/system-definitions.js +43 -7
- package/dist/trigger/validation.js +13 -5
- package/dist/utils/cross-platform.js +14 -0
- package/dist/utils/ecweb-supervisor.js +258 -83
- package/dist/utils/error-utils.js +16 -2
- package/dist/utils/logger.js +24 -5
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +5 -3
- package/dist/utils/upgrade-jobs.js +45 -5
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/aun/ABILITY_CALLING.md +20 -2
- package/kits/docs/channels/aun.md +9 -0
- package/kits/docs/evolcore/INDEX.md +2 -1
- package/kits/docs/evolcore/agent-create.md +3 -2
- package/kits/docs/evolcore/agent.md +1 -1
- package/kits/docs/evolcore/config.md +18 -7
- package/kits/docs/evolcore/contact.md +3 -0
- package/kits/docs/evolcore/event.md +1 -0
- package/kits/docs/evolcore/fs.md +16 -0
- package/kits/docs/evolcore/memory-architecture.md +2 -2
- package/kits/docs/evolcore/memory-consolidation.md +32 -8
- package/kits/docs/evolcore/memory.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +36 -0
- package/kits/docs/evolcore/model.md +23 -20
- package/kits/docs/evolcore/msg.md +21 -8
- package/kits/docs/evolcore/session.md +14 -0
- package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
- package/kits/schemas/_meta.json +37 -4
- package/kits/schemas/agent-config.schema.13.json +23 -3
- package/kits/schemas/agent-config.schema.16.json +891 -0
- package/kits/schemas/daemon.schema.9.json +366 -0
- package/kits/schemas/defaults.schema.5.json +406 -127
- package/kits/schemas/relation-config.schema.11.json +260 -0
- package/kits/schemas/role-config.schema.1.json +7 -7
- package/kits/skills/.switches.json +3 -7
- package/kits/skills/aid-ability/SKILL.md +35 -6
- package/kits/skills/ec-service-proxy/SKILL.md +118 -0
- package/kits/skills/ec-trigger/SKILL.md +13 -5
- package/kits/skills/personal-assistant/SKILL.md +176 -0
- package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
- package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
- package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
- package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
- package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
- package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
- package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
- package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
- package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
- package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
- package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
- package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
- package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
- package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
- package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
- package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
- package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
- package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
- package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
- package/kits/templates/memory-consolidation/forget.md +19 -6
- package/kits/templates/memory-consolidation/notes.md +1 -1
- package/kits/templates/memory-consolidation/profile.md +2 -2
- package/kits/templates/memory-consolidation/promote.md +20 -3
- package/kits/templates/roles/member.json +8 -1
- 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 +2 -2
- 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 +4 -4
- package/package.json +7 -3
- package/dist/stats/billing.js +0 -215
|
@@ -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
|
}
|
|
@@ -15,6 +15,7 @@ export class IMRenderer {
|
|
|
15
15
|
sentContent = false;
|
|
16
16
|
flushCount = 0;
|
|
17
17
|
messageTimestamps = [];
|
|
18
|
+
loggedBlankTextDiagnostic = false;
|
|
18
19
|
/** 串行发送队列:保证消息按序到达 */
|
|
19
20
|
sendChain = Promise.resolve();
|
|
20
21
|
/** proactive:是否已发过 text 文本(用于去重 complete.result) */
|
|
@@ -119,7 +120,7 @@ export class IMRenderer {
|
|
|
119
120
|
return;
|
|
120
121
|
if (this.textBuffer.length === 0)
|
|
121
122
|
return;
|
|
122
|
-
//
|
|
123
|
+
// 文件标记过滤后若只剩空白,应立即消费;尤其避免 final-only
|
|
123
124
|
// 模式把工具调用前的空白继续带到最终回复。
|
|
124
125
|
const rawText = this.opts.fileMarkerPattern
|
|
125
126
|
? this.textBuffer.replace(this.opts.fileMarkerPattern, '')
|
|
@@ -398,6 +399,10 @@ export class IMRenderer {
|
|
|
398
399
|
durationMs: opts.durationMs,
|
|
399
400
|
});
|
|
400
401
|
}
|
|
402
|
+
/** Durable system notices use the same task route and serialized send queue. */
|
|
403
|
+
async sendSystemNotice(text, subtype) {
|
|
404
|
+
await this.sendPayload({ kind: 'system.notice', text, subtype });
|
|
405
|
+
}
|
|
401
406
|
/** 发送不进入 activity/thought 历史、也不代表执行活跃的任务级 notice。 */
|
|
402
407
|
async sendStatusNotice(message, severity = 'info', subtype, details) {
|
|
403
408
|
const payload = {
|
|
@@ -534,10 +539,12 @@ export class IMRenderer {
|
|
|
534
539
|
hasSendableText(text, source) {
|
|
535
540
|
if (text.trim())
|
|
536
541
|
return true;
|
|
537
|
-
//
|
|
538
|
-
|
|
542
|
+
// One task can flush several whitespace-only stream deltas. Keep one debug
|
|
543
|
+
// signal for diagnosis without emitting a WARN for every expected empty body.
|
|
544
|
+
if (text.length > 0 && !this.loggedBlankTextDiagnostic) {
|
|
545
|
+
this.loggedBlankTextDiagnostic = true;
|
|
539
546
|
const { envelope, agentAid } = this.opts;
|
|
540
|
-
logger.
|
|
547
|
+
logger.debug(`[IMRenderer] Skipped whitespace-only text: code=EMPTY_MESSAGE source=${source} task=${envelope.taskId} session=${envelope.sessionId ?? '<none>'} agent=${agentAid ?? envelope.agentName} textLength=${text.length} text=${JSON.stringify(text.slice(0, 80))}`);
|
|
541
548
|
}
|
|
542
549
|
return false;
|
|
543
550
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { AccessPolicyError, readAccessPolicy, } from '../../config/access-policy.js';
|
|
2
2
|
import { getContactSnapshot, isAcceptedContact, resolveContactView, resolvePrincipal, } from '../../config/contact-book.js';
|
|
3
3
|
import { isValidAid } from '../../aun/aid/validation.js';
|
|
4
|
-
import { expirePendingContactRequests } from '../../config/contact-request-service.js';
|
|
4
|
+
import { addContact, expirePendingContactRequests } from '../../config/contact-request-service.js';
|
|
5
|
+
import { readOwnerDirectoryMembership } from '../../directory/owner-directory-admission.js';
|
|
6
|
+
import { readAunPeerKind, resolveAunPeerKind } from '../relation/peer-identity.js';
|
|
5
7
|
/** Validate managed private AUN sends against the sender's local contact policy. */
|
|
6
8
|
export async function evaluateOutboundContactAdmission(input) {
|
|
7
9
|
const selfAid = String(input.selfAid || '').trim();
|
|
@@ -34,8 +36,12 @@ export async function evaluateOutboundContactAdmission(input) {
|
|
|
34
36
|
const view = resolveContactView(selfAid, targetAid);
|
|
35
37
|
if (view.isOwner)
|
|
36
38
|
return { allow: true, status: 'owner' };
|
|
37
|
-
if (entry && (entry.status === undefined || entry.status === 'active'))
|
|
38
|
-
|
|
39
|
+
if (entry && (entry.status === undefined || entry.status === 'active')) {
|
|
40
|
+
const kind = readAunPeerKind(selfAid, targetAid);
|
|
41
|
+
return kind.kind === 'private' ? { allow: true, status: 'active' }
|
|
42
|
+
: { allow: false, code: 'CONTACT_POLICY_INVALID', status: 'absent',
|
|
43
|
+
error: `Cannot establish private contact type (${kind.reason}): ${targetAid}` };
|
|
44
|
+
}
|
|
39
45
|
const status = entry?.status ?? 'absent';
|
|
40
46
|
if (status === 'blocked')
|
|
41
47
|
return { allow: false, code: 'CONTACT_BLOCKED', status, error: `目标联系人 ${targetAid} 已被拉黑。请先解除拉黑:ec contact unblock ${targetAid} --self ${selfAid}` };
|
|
@@ -50,6 +56,58 @@ export async function evaluateOutboundContactAdmission(input) {
|
|
|
50
56
|
return { allow: false, code: 'CONTACT_POLICY_INVALID', status: 'absent', error: error instanceof Error ? error.message : String(error) };
|
|
51
57
|
}
|
|
52
58
|
}
|
|
59
|
+
/** An explicit managed private send establishes the target as an active contact. */
|
|
60
|
+
export async function ensureOutboundContactForSend(input) {
|
|
61
|
+
const selfAid = String(input.selfAid || '').trim();
|
|
62
|
+
const targetAid = String(input.targetAid || '').trim();
|
|
63
|
+
if (!isValidAid(selfAid) || !isValidAid(targetAid))
|
|
64
|
+
return evaluateOutboundContactAdmission(input);
|
|
65
|
+
input = { ...input, selfAid, targetAid };
|
|
66
|
+
const target = await resolveAunPeerKind(selfAid, targetAid);
|
|
67
|
+
if (target.kind !== 'private') {
|
|
68
|
+
return {
|
|
69
|
+
allow: false, code: 'CONTACT_POLICY_INVALID', status: 'absent',
|
|
70
|
+
error: target.kind === 'group' ? `Target ${targetAid} is a group AID; use group send`
|
|
71
|
+
: `Cannot establish private target type (${target.reason}): ${targetAid}`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const admission = await evaluateOutboundContactAdmission(input);
|
|
75
|
+
if (!admission.allow && (admission.code === 'CONTACT_BLOCKED' || admission.code === 'CONTACT_POLICY_INVALID')) {
|
|
76
|
+
return admission;
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const view = resolveContactView(input.selfAid, input.targetAid);
|
|
80
|
+
if (view.isOwner || (view.source === 'contact' && view.status === 'active'))
|
|
81
|
+
return admission;
|
|
82
|
+
await addContact({
|
|
83
|
+
selfAid: input.selfAid,
|
|
84
|
+
primaryId: input.targetAid,
|
|
85
|
+
actorId: input.actorId,
|
|
86
|
+
});
|
|
87
|
+
return evaluateOutboundContactAdmission(input);
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
const current = await evaluateOutboundContactAdmission(input);
|
|
91
|
+
if (!current.allow && current.code === 'CONTACT_BLOCKED')
|
|
92
|
+
return current;
|
|
93
|
+
if (current.allow) {
|
|
94
|
+
try {
|
|
95
|
+
const view = resolveContactView(input.selfAid, input.targetAid);
|
|
96
|
+
if (view.isOwner || (view.source === 'contact' && view.status === 'active'))
|
|
97
|
+
return current;
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// Return the original mutation error below.
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
allow: false,
|
|
105
|
+
code: 'CONTACT_POLICY_INVALID',
|
|
106
|
+
status: 'absent',
|
|
107
|
+
error: error instanceof Error ? error.message : String(error),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
53
111
|
export function evaluateInboundAdmissionPreflight(input) {
|
|
54
112
|
const selfAid = String(input.selfAid || '').trim();
|
|
55
113
|
const channelType = String(input.channelType || '').trim().toLowerCase();
|
|
@@ -122,27 +180,58 @@ export function evaluateInboundAdmissionPreflight(input) {
|
|
|
122
180
|
}
|
|
123
181
|
return { allow: true, context };
|
|
124
182
|
}
|
|
183
|
+
/** Directory rules also guard control routes; a denied directory sender receives no automatic reply. */
|
|
184
|
+
export function evaluateOwnerDirectoryInboundAdmission(context) {
|
|
185
|
+
if (context.trustedHandoffEcho || context.isOwner || !context.primaryId || !context.policy)
|
|
186
|
+
return undefined;
|
|
187
|
+
const membership = readOwnerDirectoryMembership(context.selfAid, context.primaryId);
|
|
188
|
+
if (!membership)
|
|
189
|
+
return undefined;
|
|
190
|
+
if (membership.agents === 'found') {
|
|
191
|
+
return context.policy.allowOwnerAgentDirectory !== false
|
|
192
|
+
? { allow: true, reason: 'owner_directory_agent', context }
|
|
193
|
+
: { allow: false, reason: 'owner_agent_directory_disabled', context };
|
|
194
|
+
}
|
|
195
|
+
// Resolve the higher-priority Agent category before admitting a contact.
|
|
196
|
+
if (membership.agents === 'unavailable')
|
|
197
|
+
return { allow: false, reason: 'owner_directory_unavailable', context };
|
|
198
|
+
if (membership.contacts === 'found') {
|
|
199
|
+
return context.policy.allowOwnerDirectoryContacts !== false
|
|
200
|
+
? { allow: true, reason: 'owner_directory_contact', context }
|
|
201
|
+
: { allow: false, reason: 'owner_directory_contacts_disabled', context };
|
|
202
|
+
}
|
|
203
|
+
if (membership.contacts === 'unavailable')
|
|
204
|
+
return { allow: false, reason: 'owner_directory_unavailable', context };
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
125
207
|
export function evaluateOrdinaryInboundAdmission(context) {
|
|
126
208
|
if (context.trustedHandoffEcho)
|
|
127
209
|
return { allow: true, reason: 'trusted_handoff', context };
|
|
128
210
|
const policy = context.policy;
|
|
129
211
|
if (!policy)
|
|
130
212
|
return { allow: false, reason: 'invalid_access_policy', context };
|
|
213
|
+
if (context.isOwner)
|
|
214
|
+
return { allow: true, reason: 'owner', context };
|
|
215
|
+
const directoryDecision = evaluateOwnerDirectoryInboundAdmission(context);
|
|
216
|
+
if (directoryDecision)
|
|
217
|
+
return directoryDecision;
|
|
218
|
+
if (context.primaryId && policy.allowedAids?.includes(context.primaryId)) {
|
|
219
|
+
return { allow: true, reason: 'allowed_aid', context };
|
|
220
|
+
}
|
|
221
|
+
if (policy.allowExternalContacts === false) {
|
|
222
|
+
return { allow: false, reason: 'external_contacts_disabled', context };
|
|
223
|
+
}
|
|
131
224
|
if (context.chatType === 'group') {
|
|
132
|
-
if (context.isOwner)
|
|
133
|
-
return { allow: true, reason: 'owner', context };
|
|
134
225
|
if (policy.policyMode === 'open' || policy.policyMode === 'contacts') {
|
|
135
226
|
return { allow: true, reason: 'group_channel_allowed', context };
|
|
136
227
|
}
|
|
137
228
|
return { allow: false, reason: 'owners', context };
|
|
138
229
|
}
|
|
139
|
-
if (context.isOwner)
|
|
140
|
-
return { allow: true, reason: 'owner', context };
|
|
141
230
|
if (policy.policyMode === 'open')
|
|
142
231
|
return { allow: true, reason: 'open', context };
|
|
143
232
|
if (policy.policyMode === 'owners')
|
|
144
233
|
return { allow: false, reason: 'owners', context };
|
|
145
|
-
if (context.primaryId && isAcceptedContact(context.selfAid, context.primaryId)) {
|
|
234
|
+
if (context.primaryId && isAcceptedContact(context.selfAid, context.primaryId, context.channelType === 'aun' && context.chatType === 'private' ? 'private' : undefined)) {
|
|
146
235
|
return { allow: true, reason: 'contact', context };
|
|
147
236
|
}
|
|
148
237
|
return { allow: false, reason: 'contact_required', context };
|
|
@@ -19,7 +19,7 @@ import { findContactRequestNote, expirePendingContactRequests, reviewContactRequ
|
|
|
19
19
|
import { isValidAid } from '../../aun/aid/validation.js';
|
|
20
20
|
import { PeerIdentityCache, formatPeerKey } from '../relation/peer-identity.js';
|
|
21
21
|
import { ownerResolver } from '../ownership/owner-resolver.js';
|
|
22
|
-
import {
|
|
22
|
+
import { isTopicSession, sessionLocalTopicId } from '../thread/topic-id.js';
|
|
23
23
|
import { resolveEffective } from '../../config/config-manager.js';
|
|
24
24
|
import { createDecisionInferenceProvider } from '../inference/text-inference.js';
|
|
25
25
|
import { AutoMentionGate } from './auto-mention-gate.js';
|
|
@@ -39,9 +39,11 @@ import { recordCausationSpan } from '../causation/audit.js';
|
|
|
39
39
|
import { renderActionAsText } from '../interaction-router.js';
|
|
40
40
|
import { planApprovalRoute } from '../permission/approval-gateway.js';
|
|
41
41
|
import { guardGroupSlashCommand, parseFullAccessCommand } from '../command/slash-gate.js';
|
|
42
|
-
import { createAgentPolicyAuthorization, createSessionFullAccessAuthorization
|
|
42
|
+
import { createAgentPolicyAuthorization, createSessionFullAccessAuthorization } from '../role/runtime-policy.js';
|
|
43
|
+
import { auditFullAccessEvent } from '../auth/authorization-audit.js';
|
|
43
44
|
import { DIAGNOSTIC_AGENT_AID, DiagnosticSessionRouter, parseDiagnosticEvent, isDiagnosticSessionActive } from '../command/diag-service.js';
|
|
44
|
-
import { consumeAdmissionReplyBudget, clearAdmissionReplyBudgets, evaluateInboundAdmissionPreflight, evaluateOrdinaryInboundAdmission, } from './message-admission.js';
|
|
45
|
+
import { consumeAdmissionReplyBudget, clearAdmissionReplyBudgets, evaluateInboundAdmissionPreflight, evaluateOrdinaryInboundAdmission, evaluateOwnerDirectoryInboundAdmission, } from './message-admission.js';
|
|
46
|
+
import { prepareOwnerDirectoryAdmission } from '../../directory/owner-directory-admission.js';
|
|
45
47
|
const CONTACT_REJECTION_NOTICE = '[rejection] Not accepting messages from you.';
|
|
46
48
|
const REJECTABLE_PEER_TYPES = new Set(['ai', 'bot', 'agent', 'service']);
|
|
47
49
|
const REJECTION_MAX = 3;
|
|
@@ -117,16 +119,16 @@ export class MessageBridge {
|
|
|
117
119
|
const config = resolveEffective({
|
|
118
120
|
self: item.selfAid,
|
|
119
121
|
peerKey: formatPeerKey('aun', item.groupId),
|
|
120
|
-
}, { cache: true
|
|
121
|
-
const model = config.Services?.decision
|
|
122
|
-
const provider = createDecisionInferenceProvider(config.
|
|
122
|
+
}, { cache: true });
|
|
123
|
+
const model = config.Services?.decision?.model?.trim();
|
|
124
|
+
const provider = createDecisionInferenceProvider(config.Services);
|
|
123
125
|
return model && provider ? { model, provider } : undefined;
|
|
124
126
|
},
|
|
125
127
|
resolveResources: async (item) => {
|
|
126
128
|
const config = resolveEffective({
|
|
127
129
|
self: item.selfAid,
|
|
128
130
|
peerKey: formatPeerKey('aun', item.groupId),
|
|
129
|
-
}, { cache: true
|
|
131
|
+
}, { cache: true });
|
|
130
132
|
const resources = {};
|
|
131
133
|
if (config.groupRules?.mode !== 'ignore') {
|
|
132
134
|
try {
|
|
@@ -164,7 +166,7 @@ export class MessageBridge {
|
|
|
164
166
|
resolveQuietWindowMs: item => resolveEffective({
|
|
165
167
|
self: item.selfAid,
|
|
166
168
|
peerKey: formatPeerKey('aun', item.groupId),
|
|
167
|
-
}, { cache: true
|
|
169
|
+
}, { cache: true }).autoMentionQuietWindowMs,
|
|
168
170
|
resolveMessageState: item => {
|
|
169
171
|
if (!item.messageId)
|
|
170
172
|
return 'missing';
|
|
@@ -531,6 +533,7 @@ export class MessageBridge {
|
|
|
531
533
|
applicantAid: context.primaryId,
|
|
532
534
|
note: requestMatch[1],
|
|
533
535
|
sourceChannelKey: context.channelKey,
|
|
536
|
+
routeKind: 'private',
|
|
534
537
|
});
|
|
535
538
|
if ((submission.code === 'submitted' || submission.code === 'resubmitted') && submission.requestId) {
|
|
536
539
|
void this.deliverContactReviewCard(context.selfAid, context.primaryId, submission, owningAgent)
|
|
@@ -595,6 +598,7 @@ export class MessageBridge {
|
|
|
595
598
|
applicantAid: context.primaryId,
|
|
596
599
|
note: typeof protocolPayload?.note === 'string' ? protocolPayload.note : undefined,
|
|
597
600
|
sourceChannelKey: context.channelKey,
|
|
601
|
+
routeKind: 'private',
|
|
598
602
|
});
|
|
599
603
|
result = contactRequestSubmissionProtocolResult(submission);
|
|
600
604
|
if ((submission.code === 'submitted' || submission.code === 'resubmitted') && submission.requestId) {
|
|
@@ -706,6 +710,9 @@ export class MessageBridge {
|
|
|
706
710
|
await sendReply(msg.channelId, payload.text, msg.replyContext);
|
|
707
711
|
}
|
|
708
712
|
admissionDeniedNotice(context, channelType) {
|
|
713
|
+
if (context.policy?.allowExternalContacts === false) {
|
|
714
|
+
return '当前 Agent 不接受外部联系消息,请由 Owner 将你的 AID 加入允许名单。';
|
|
715
|
+
}
|
|
709
716
|
if (context.contactStatus === 'pending') {
|
|
710
717
|
return '联系人申请审核中;可再次发送 /request 更新说明。';
|
|
711
718
|
}
|
|
@@ -949,6 +956,16 @@ export class MessageBridge {
|
|
|
949
956
|
actorId,
|
|
950
957
|
trustedHandoffEcho,
|
|
951
958
|
});
|
|
959
|
+
if (admissionPreflight.allow && !trustedHandoffEcho && !admissionPreflight.context.isOwner) {
|
|
960
|
+
if (selfAid && admissionPreflight.context.primaryId) {
|
|
961
|
+
await prepareOwnerDirectoryAdmission(selfAid, admissionPreflight.context.primaryId);
|
|
962
|
+
}
|
|
963
|
+
const directoryDecision = evaluateOwnerDirectoryInboundAdmission(admissionPreflight.context);
|
|
964
|
+
if (directoryDecision && !directoryDecision.allow) {
|
|
965
|
+
logger.info(`[MessageBridge] Owner directory admission denied before control routing: self=${selfAid} actor=${actorId ?? '<none>'} reason=${directoryDecision.reason}`);
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
}
|
|
952
969
|
if (!trustedHandoffEcho && await this.handleContactRequestProtocol({
|
|
953
970
|
context: admissionPreflight.context,
|
|
954
971
|
msg,
|
|
@@ -1006,8 +1023,11 @@ export class MessageBridge {
|
|
|
1006
1023
|
return;
|
|
1007
1024
|
}
|
|
1008
1025
|
const admissionDecision = evaluateOrdinaryInboundAdmission(admissionPreflight.context);
|
|
1009
|
-
|
|
1010
|
-
|
|
1026
|
+
const directoryDenied = !admissionDecision.allow && (admissionDecision.reason === 'owner_directory_contacts_disabled'
|
|
1027
|
+
|| admissionDecision.reason === 'owner_agent_directory_disabled'
|
|
1028
|
+
|| admissionDecision.reason === 'owner_directory_unavailable');
|
|
1029
|
+
if (!admissionDecision.allow && (!isPrivateMenuTokenRequest || directoryDenied)) {
|
|
1030
|
+
if (chatType === 'private' && !directoryDenied) {
|
|
1011
1031
|
if (menuControl.isMenu) {
|
|
1012
1032
|
if (hasValidMenuId(menuControl)) {
|
|
1013
1033
|
const header = { id: menuControl.id, ...(menuControl.name?.trim() ? { name: menuControl.name } : {}) };
|
|
@@ -1186,9 +1206,9 @@ export class MessageBridge {
|
|
|
1186
1206
|
return;
|
|
1187
1207
|
}
|
|
1188
1208
|
}
|
|
1189
|
-
// /fa
|
|
1190
|
-
//
|
|
1191
|
-
//
|
|
1209
|
+
// /fa on/off controls the current session; other non-empty arguments
|
|
1210
|
+
// request one fullaccess run. Only this trusted inbound path can create
|
|
1211
|
+
// the per-call authorization carried into ResponseEngine.
|
|
1192
1212
|
const fullAccessCommand = parseFullAccessCommand(content);
|
|
1193
1213
|
if (fullAccessCommand.matched) {
|
|
1194
1214
|
const groupGuard = guardGroupSlashCommand(content, chatType);
|
|
@@ -1200,9 +1220,39 @@ export class MessageBridge {
|
|
|
1200
1220
|
await sendReply(msg.channelId, '❌ /fa 只能由用户直接发送', msg.replyContext);
|
|
1201
1221
|
return;
|
|
1202
1222
|
}
|
|
1203
|
-
if (fullAccessCommand.action === '
|
|
1204
|
-
|
|
1205
|
-
|
|
1223
|
+
if (fullAccessCommand.action === 'prompt') {
|
|
1224
|
+
if (!authSubject.isDaemonOwner || !authSubject.principalId) {
|
|
1225
|
+
auditFullAccessEvent({
|
|
1226
|
+
event: 'fullaccess.command.rejected',
|
|
1227
|
+
source: 'fullaccess-command',
|
|
1228
|
+
decision: 'deny',
|
|
1229
|
+
actorId: authSubject.principalId ?? authSubject.actorId,
|
|
1230
|
+
processRole: authSubject.processRole,
|
|
1231
|
+
messageId: msg.messageId,
|
|
1232
|
+
reason: '仅可信 daemon-owner 可以使用 fullaccess',
|
|
1233
|
+
});
|
|
1234
|
+
await sendReply(msg.channelId, '❌ 仅可信 daemon-owner 可以使用 fullaccess', msg.replyContext);
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
if (!msg.messageLogContent)
|
|
1238
|
+
msg.messageLogContent = content;
|
|
1239
|
+
content = fullAccessCommand.prompt;
|
|
1240
|
+
executionPermissionOverride = {
|
|
1241
|
+
permissionMode: 'fullaccess',
|
|
1242
|
+
processRole: 'fullaccess-run',
|
|
1243
|
+
dataScope: 'daemon',
|
|
1244
|
+
source: 'fullaccess-command',
|
|
1245
|
+
authorizedBy: authSubject.principalId,
|
|
1246
|
+
};
|
|
1247
|
+
logger.warn(`[MessageBridge] fullaccess command accepted: channel=${channelName} `
|
|
1248
|
+
+ `actor=${authSubject.principalId} message=${msg.messageId ?? '<none>'}`);
|
|
1249
|
+
auditFullAccessEvent({
|
|
1250
|
+
event: 'fullaccess.command.accepted',
|
|
1251
|
+
source: 'fullaccess-command',
|
|
1252
|
+
actorId: authSubject.principalId,
|
|
1253
|
+
processRole: authSubject.processRole,
|
|
1254
|
+
messageId: msg.messageId,
|
|
1255
|
+
});
|
|
1206
1256
|
}
|
|
1207
1257
|
}
|
|
1208
1258
|
// 0. 仅阻止协议遥测进入 session / model / messages.jsonl;协议本身已在
|
|
@@ -1251,7 +1301,7 @@ export class MessageBridge {
|
|
|
1251
1301
|
let autoMode = false;
|
|
1252
1302
|
if (resolvedChannelType === 'aun' && chatType === 'group' && selfAid && msg.source !== 'handoff') {
|
|
1253
1303
|
try {
|
|
1254
|
-
const config = resolveEffective({ self: selfAid, peerKey: formatPeerKey('aun', msg.groupId || msg.channelId) }, { cache: true
|
|
1304
|
+
const config = resolveEffective({ self: selfAid, peerKey: formatPeerKey('aun', msg.groupId || msg.channelId) }, { cache: true });
|
|
1255
1305
|
autoMode = config.mentionMode === 'auto';
|
|
1256
1306
|
}
|
|
1257
1307
|
catch (error) {
|
|
@@ -1477,18 +1527,15 @@ export class MessageBridge {
|
|
|
1477
1527
|
});
|
|
1478
1528
|
session = renewResult.session;
|
|
1479
1529
|
if (!executionPermissionOverride && selfAid && owningAgent?.aid === selfAid) {
|
|
1480
|
-
executionPermissionOverride =
|
|
1530
|
+
executionPermissionOverride = createAgentPolicyAuthorization({
|
|
1531
|
+
agentAid: selfAid, actor: roleDetail.actor, chatType,
|
|
1532
|
+
source: msg.source, peerType: msg.peerType,
|
|
1533
|
+
}) ?? createSessionFullAccessAuthorization({
|
|
1481
1534
|
session,
|
|
1482
1535
|
actor: roleDetail.actor,
|
|
1483
1536
|
source: msg.source,
|
|
1484
1537
|
peerType: msg.peerType,
|
|
1485
1538
|
});
|
|
1486
|
-
if (!executionPermissionOverride && isMainSession(session) && !hasSessionFullAccessOverride(session)) {
|
|
1487
|
-
executionPermissionOverride = createAgentPolicyAuthorization({
|
|
1488
|
-
agentAid: selfAid, actor: roleDetail.actor, chatType,
|
|
1489
|
-
source: msg.source, peerType: msg.peerType,
|
|
1490
|
-
});
|
|
1491
|
-
}
|
|
1492
1539
|
}
|
|
1493
1540
|
if ('renewed' in renewResult && renewResult.renewed) {
|
|
1494
1541
|
const notice = '已自动切换到新会话';
|
|
@@ -341,6 +341,59 @@ export function appendMessageLogStrict(chatDir, entry, durable = false) {
|
|
|
341
341
|
rememberMessageId(chatDir, entry.msgId);
|
|
342
342
|
notifyInbound(chatDir, entry);
|
|
343
343
|
}
|
|
344
|
+
/** Attach a capsule reference to the first admitted message of a renewed backend. */
|
|
345
|
+
export function associateMessageCapsule(chatDir, sessionId, capsuleId, messageId, timestamp) {
|
|
346
|
+
if (!capsuleId || (!messageId && timestamp === undefined))
|
|
347
|
+
return false;
|
|
348
|
+
const file = messageLogPath(chatDir);
|
|
349
|
+
if (!fs.existsSync(file))
|
|
350
|
+
return false;
|
|
351
|
+
try {
|
|
352
|
+
const lines = fs.readFileSync(file, 'utf8').split('\n');
|
|
353
|
+
let changed = false;
|
|
354
|
+
for (let index = lines.length - 1; index >= 0; index--) {
|
|
355
|
+
if (!lines[index]?.trim())
|
|
356
|
+
continue;
|
|
357
|
+
let entry;
|
|
358
|
+
try {
|
|
359
|
+
entry = JSON.parse(lines[index]);
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
if (entry.sessionId !== sessionId || entry.dir !== 'in' || isTransientProtocolMessage(entry)
|
|
365
|
+
|| entry.msgType === 'command' || entry.content?.trim().startsWith('/renew'))
|
|
366
|
+
continue;
|
|
367
|
+
if (messageId && entry.msgId !== messageId)
|
|
368
|
+
continue;
|
|
369
|
+
if (!messageId && entry.ts !== timestamp)
|
|
370
|
+
continue;
|
|
371
|
+
if (entry.capsuleId)
|
|
372
|
+
return entry.capsuleId === capsuleId;
|
|
373
|
+
entry.capsuleId = capsuleId;
|
|
374
|
+
lines[index] = JSON.stringify(entry);
|
|
375
|
+
changed = true;
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
if (!changed)
|
|
379
|
+
return false;
|
|
380
|
+
const temp = `${file}.capsule.tmp`;
|
|
381
|
+
const descriptor = fs.openSync(temp, 'w', 0o600);
|
|
382
|
+
try {
|
|
383
|
+
fs.writeFileSync(descriptor, lines.join('\n'));
|
|
384
|
+
fs.fsyncSync(descriptor);
|
|
385
|
+
}
|
|
386
|
+
finally {
|
|
387
|
+
fs.closeSync(descriptor);
|
|
388
|
+
}
|
|
389
|
+
fs.renameSync(temp, file);
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
catch (error) {
|
|
393
|
+
logger.warn(`[MessageLog] Failed to associate capsule ${capsuleId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
344
397
|
export function buildInboundEntry(opts) {
|
|
345
398
|
const ts = opts.timestamp || Date.now();
|
|
346
399
|
const isCommandCapable = !opts.msgType || opts.msgType === 'text' || opts.msgType === 'quote' || opts.msgType === 'action_card_reply';
|
|
@@ -351,6 +404,7 @@ export function buildInboundEntry(opts) {
|
|
|
351
404
|
...(opts.gatewaySeq !== undefined ? { gatewaySeq: opts.gatewaySeq } : {}),
|
|
352
405
|
time: formatTimestampMs(ts),
|
|
353
406
|
sessionId: opts.sessionId,
|
|
407
|
+
capsuleId: opts.capsuleId,
|
|
354
408
|
threadId: opts.threadId ?? null,
|
|
355
409
|
dir: 'in',
|
|
356
410
|
from: opts.from,
|
|
@@ -384,6 +438,7 @@ export function buildOutboundEntry(opts) {
|
|
|
384
438
|
ts,
|
|
385
439
|
time: formatTimestampMs(ts),
|
|
386
440
|
sessionId: opts.sessionId,
|
|
441
|
+
capsuleId: opts.capsuleId,
|
|
387
442
|
threadId: opts.threadId ?? null,
|
|
388
443
|
dir: 'out',
|
|
389
444
|
from: opts.from,
|
|
@@ -78,11 +78,11 @@ export class MessageQueue {
|
|
|
78
78
|
this.activeTerminalReasons.set(queueKey, reason);
|
|
79
79
|
let interruption;
|
|
80
80
|
try {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
:
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
const active = this.activeStates.get(queueKey);
|
|
82
|
+
const target = active?.taskId && Number.isSafeInteger(active.generation)
|
|
83
|
+
? { taskId: active.taskId, generation: active.generation }
|
|
84
|
+
: undefined;
|
|
85
|
+
interruption = Promise.resolve(this.interruptCallback(sessionKey, baseagent, evolagentName, reason, timeout, strict, target));
|
|
86
86
|
}
|
|
87
87
|
catch (error) {
|
|
88
88
|
interruption = Promise.reject(error);
|