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
package/dist/channels/aun.js
CHANGED
|
@@ -27,14 +27,17 @@ import { appendMessageLog, appendMessageLogStrict, buildOutboundEntry, buildInbo
|
|
|
27
27
|
import { createSendFileMarkerPattern } from '../core/message/file-markers.js';
|
|
28
28
|
import { chatDirPath } from '../core/session/session-fs-store.js';
|
|
29
29
|
import { readSessionLoopConfig, resolveSessionLoopTarget } from '../core/session/session-idle-monitor.js';
|
|
30
|
-
import { sessionFullAccessStatus } from '../core/role/runtime-policy.js';
|
|
30
|
+
import { resolveRuntimePermissionMode, sessionFullAccessStatus } from '../core/role/runtime-policy.js';
|
|
31
31
|
import { readTopicLabel, readTopicStatus } from '../core/session/session-mapper.js';
|
|
32
32
|
import { appendHintAddDetailed, appendHintRemoveDetailed, appendHintPromoteDetailed, parseInjectRequest, peekHints, withHintTargetLock } from '../core/message/pending-hints.js';
|
|
33
33
|
import { appendAidLifecycle } from '../aun/aid/identity.js';
|
|
34
34
|
import { getAidStore, loadClient, SLOT } from '../aun/aid/store.js';
|
|
35
|
+
import { classifyServicePayloadType, getServiceRouter, readLocalSelfIdentity, } from '../services/index.js';
|
|
36
|
+
import { agentServicesDir } from '../paths.js';
|
|
35
37
|
import { MAX_AUN_ATTACHMENT_SIZE, uploadBufferAndBuildPayload, uploadFileAndBuildPayload } from '../aun/msg/upload.js';
|
|
36
38
|
import { loadAgent } from '../config-store.js';
|
|
37
39
|
import { configuredOwnerList, firstConfiguredOwner } from '../config/owner-config.js';
|
|
40
|
+
import { resolvePeerRoleDetail } from '../config/peer-role-resolver.js';
|
|
38
41
|
import { resolveAgentLifecycle } from '../config/lifecycle.js';
|
|
39
42
|
import { resolveEffective } from '../config/config-manager.js';
|
|
40
43
|
import { isManagementRole } from '../config/builtin-roles.js';
|
|
@@ -407,6 +410,7 @@ const AUN_PERMANENT_STRING_CODES = new Set([
|
|
|
407
410
|
const AUN_RETRYABLE_STRING_CODES = new Set([
|
|
408
411
|
'network_error', 'connection_error', 'timeout', 'timed_out', 'rate_limited',
|
|
409
412
|
'too_many_requests', 'temporarily_unavailable', 'server_error', 'aun_not_connected',
|
|
413
|
+
'contact_directory_unavailable', 'contact_ownership_unavailable',
|
|
410
414
|
]);
|
|
411
415
|
function errorRecord(value) {
|
|
412
416
|
return value && typeof value === 'object' && !Array.isArray(value)
|
|
@@ -498,6 +502,8 @@ export function classifyAunSendFailure(value, fallback = 'AUN send failed') {
|
|
|
498
502
|
const retryByName = /(?:timeout|connection|rate.?limit|temporar(?:y|ily)|unavailable|network|socket)/i.test(details.name ?? '');
|
|
499
503
|
const relayTargetMissing = text.includes('relay_target_not_found') || text.includes('relay target not found');
|
|
500
504
|
const rpcHandlerTimeout = numericCode === -32004 && /rpc handler timeout/i.test(text);
|
|
505
|
+
const gatewayWarming = numericCode === -32020
|
|
506
|
+
&& details.message === 'Gateway is warming; retry via another gateway';
|
|
501
507
|
// -32013 is otherwise permanent, but "client signature cert unavailable" is
|
|
502
508
|
// the gateway failing to resolve the signer's certificate while the local
|
|
503
509
|
// cert is valid and auth succeeded. It clears server-side, so keep the
|
|
@@ -550,6 +556,7 @@ export function classifyAunSendFailure(value, fallback = 'AUN send failed') {
|
|
|
550
556
|
else if (AUN_RETRYABLE_ERROR_CODES.has(numericCode ?? Number.NaN)
|
|
551
557
|
|| transientHttpStatus
|
|
552
558
|
|| rpcHandlerTimeout
|
|
559
|
+
|| gatewayWarming
|
|
553
560
|
|| signatureCertUnavailable
|
|
554
561
|
|| AUN_RETRYABLE_STRING_CODES.has(stringCode)
|
|
555
562
|
|| retryByName
|
|
@@ -801,6 +808,14 @@ export class AUNChannel {
|
|
|
801
808
|
ownerDirectoryRetryAttempts = 0;
|
|
802
809
|
ownerDirectoryResolvedSignature;
|
|
803
810
|
store = null;
|
|
811
|
+
/** 服务路由实例(懒建;services/router.json 不存在时也建,只是总闸关闭)。 */
|
|
812
|
+
serviceRouter = null;
|
|
813
|
+
/**
|
|
814
|
+
* 本 agent 的工程目录,由插件从 `ChannelBuildContext.defaultProjectPath` 注入。
|
|
815
|
+
* 与 `onProjectPathRequest`(附件落盘)同源;服务脚本沙箱的 cwd 也用它,
|
|
816
|
+
* 保证同一条 invoke 链路上所有消费方看到的是同一个目录。
|
|
817
|
+
*/
|
|
818
|
+
defaultProjectPath;
|
|
804
819
|
/** 实际连接的网关 URL(来自 authenticate() 返回值 / connection.state 事件),替代旧 (client as any)._gatewayUrl。 */
|
|
805
820
|
gatewayUrl = '';
|
|
806
821
|
projectPathProvider;
|
|
@@ -908,7 +923,9 @@ export class AUNChannel {
|
|
|
908
923
|
if (!beforeSend) {
|
|
909
924
|
const blocked = this.appContactOutboundBlock(params.to, { chatType: 'private' }, payload, params);
|
|
910
925
|
if (blocked) {
|
|
911
|
-
throw Object.assign(new Error(blocked.error), {
|
|
926
|
+
throw Object.assign(new Error(blocked.error), {
|
|
927
|
+
code: blocked.code, retryable: blocked.status === 'retry',
|
|
928
|
+
});
|
|
912
929
|
}
|
|
913
930
|
}
|
|
914
931
|
}
|
|
@@ -1641,6 +1658,15 @@ export class AUNChannel {
|
|
|
1641
1658
|
logger.warn(`${this.logPrefix()} topic.renamed failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1642
1659
|
});
|
|
1643
1660
|
}
|
|
1661
|
+
/** Quiesce callbacks before the shared resolver is detached, while offline sends still work. */
|
|
1662
|
+
prepareShutdown() {
|
|
1663
|
+
this.intentionalDisconnect = true;
|
|
1664
|
+
this.configuredOwnerBindEpoch++;
|
|
1665
|
+
this.stopOwnerDirectoryRefresh();
|
|
1666
|
+
if (this.reconnectTimer)
|
|
1667
|
+
clearTimeout(this.reconnectTimer);
|
|
1668
|
+
this.reconnectTimer = null;
|
|
1669
|
+
}
|
|
1644
1670
|
stopOwnerDirectoryRefresh() {
|
|
1645
1671
|
this.ownerDirectoryWatch?.stop();
|
|
1646
1672
|
this.ownerDirectoryWatch = undefined;
|
|
@@ -1756,13 +1782,15 @@ export class AUNChannel {
|
|
|
1756
1782
|
const selfAid = this.config.aid.replace(/^@/, '');
|
|
1757
1783
|
const client = this.client;
|
|
1758
1784
|
logger.debug(`${this.logPrefix()} getOwnerDirectoryRuntime called: selfAid=${selfAid}, connected=${this.connected}, pureIdentity=${!!this.config.pureIdentity}`);
|
|
1759
|
-
if (!client || !this.connected || this.config.pureIdentity) {
|
|
1785
|
+
if (!client || !this.connected || this.intentionalDisconnect || this.config.pureIdentity) {
|
|
1760
1786
|
logger.debug(`${this.logPrefix()} getOwnerDirectoryRuntime early return: client=${!!client}, connected=${this.connected}, pureIdentity=${!!this.config.pureIdentity}`);
|
|
1761
1787
|
return;
|
|
1762
1788
|
}
|
|
1763
1789
|
// Let Core and the SDK reuse valid consensus; explicit authorization/bind operations
|
|
1764
1790
|
// own their fresh checks. Material changes invalidate the SDK cache themselves.
|
|
1765
1791
|
const ownership = await ownerResolver.refresh(selfAid, { allowTransient: true, source: 'directory.runtime' });
|
|
1792
|
+
if (this.intentionalDisconnect || this.client !== client || !this.connected)
|
|
1793
|
+
return;
|
|
1766
1794
|
const ownerAid = ownerResolver.owner(selfAid);
|
|
1767
1795
|
logger.info(`${this.logPrefix()} ownerResolver result: selfAid=${selfAid}, ownerAid=${ownerAid || 'undefined'}`);
|
|
1768
1796
|
if (ownership.refreshFailure) {
|
|
@@ -1990,11 +2018,12 @@ export class AUNChannel {
|
|
|
1990
2018
|
if (runtime.ownerAid !== senderAid || !sameContactBinding(binding, currentContactBinding(selfAid)))
|
|
1991
2019
|
return;
|
|
1992
2020
|
runtime.cache.saveAuthorization(parsed);
|
|
1993
|
-
|
|
1994
|
-
// 授权被撤销/拒绝时 saveAuthorization 已经清掉凭证和快照,这里无事可做:
|
|
1995
|
-
// 下一次 owner.directory.changed 会写 pending,准入回落到"名录不可用"。
|
|
1996
|
-
if (runtime.cache.scopeAccess('contacts') !== 'authorized')
|
|
2021
|
+
if (runtime.cache.isRevoked())
|
|
1997
2022
|
return;
|
|
2023
|
+
logger.info(`${this.logPrefix()} owner.directory.grant: grant applied for ${selfAid}`);
|
|
2024
|
+
// 撤销/拒绝时 saveAuthorization 已经清掉本地快照,这里无事可做:
|
|
2025
|
+
// 持久化撤权边界会阻止后续 changed 或共享广播恢复旧快照。
|
|
2026
|
+
// 生效时 grant 清除撤权状态,并触发拉取。
|
|
1998
2027
|
// 授权是 Owner 的主动操作,用户点完就在等结果。写标记 + 立即拉取 + 落地,
|
|
1999
2028
|
// 不再等"下一条入站消息"——那条消息可能几小时后才来。
|
|
2000
2029
|
await runtime.cache.handleOwnerChangedEvent(senderAid);
|
|
@@ -2315,10 +2344,27 @@ export class AUNChannel {
|
|
|
2315
2344
|
setAidStatsCollector(collector) {
|
|
2316
2345
|
this.aidStatsCollector = collector;
|
|
2317
2346
|
}
|
|
2347
|
+
transportListeners = new Set();
|
|
2348
|
+
onTransportState(listener) {
|
|
2349
|
+
this.transportListeners.add(listener);
|
|
2350
|
+
return () => { this.transportListeners.delete(listener); };
|
|
2351
|
+
}
|
|
2318
2352
|
setAidStatus(status, extra) {
|
|
2353
|
+
const wasReady = this.aidState.status === 'connected';
|
|
2319
2354
|
this.aidState.status = status;
|
|
2320
2355
|
if (extra)
|
|
2321
2356
|
Object.assign(this.aidState, extra);
|
|
2357
|
+
const ready = status === 'connected';
|
|
2358
|
+
if (ready !== wasReady) {
|
|
2359
|
+
for (const listener of this.transportListeners) {
|
|
2360
|
+
try {
|
|
2361
|
+
listener(ready);
|
|
2362
|
+
}
|
|
2363
|
+
catch (error) {
|
|
2364
|
+
logger.warn(`${this.logPrefix()} transport listener failed: ${error}`);
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2322
2368
|
}
|
|
2323
2369
|
async connect() {
|
|
2324
2370
|
this.intentionalDisconnect = false;
|
|
@@ -2425,6 +2471,12 @@ export class AUNChannel {
|
|
|
2425
2471
|
// Peer snapshots refresh lazily on the next lookup. The self name is
|
|
2426
2472
|
// held separately by this channel, so refresh it with the existing API.
|
|
2427
2473
|
if (aid === (this._aid || this.config.aid)) {
|
|
2474
|
+
// 名片 type/exttype 是 requires 判定的依据:变更后重新扫描包。
|
|
2475
|
+
if (this.serviceRouter) {
|
|
2476
|
+
const identity = readLocalSelfIdentity(aid) ?? { aid, type: 'agent', exttype: '' };
|
|
2477
|
+
this.serviceRouter.ensureStarted(identity);
|
|
2478
|
+
this.serviceRouter.reload();
|
|
2479
|
+
}
|
|
2428
2480
|
void refreshAgentDisplayName(aid).then(name => {
|
|
2429
2481
|
if (!name || !isCurrentClient() || this.intentionalDisconnect)
|
|
2430
2482
|
return;
|
|
@@ -2925,7 +2977,7 @@ export class AUNChannel {
|
|
|
2925
2977
|
}
|
|
2926
2978
|
async downloadAttachment(att, channelId, delivery) {
|
|
2927
2979
|
const ownerAid = att.owner_aid
|
|
2928
|
-
|| (delivery?.chatType === 'private' ? channelId : '')
|
|
2980
|
+
|| (delivery?.chatType === 'private' && !delivery.service ? channelId : '')
|
|
2929
2981
|
|| this._aid
|
|
2930
2982
|
|| '';
|
|
2931
2983
|
const objectKey = att.object_key;
|
|
@@ -3275,7 +3327,50 @@ export class AUNChannel {
|
|
|
3275
3327
|
}
|
|
3276
3328
|
return;
|
|
3277
3329
|
}
|
|
3330
|
+
// ── 服务路由:应答与请求分两支,应答优先。 ──
|
|
3331
|
+
// 应答必须早于请求分支,否则会被 unmatched 静默丢弃,等待者永远收不到结果。
|
|
3332
|
+
// 插在这里(claim 之前):服务分支无条件自己 claim 一次,之后既有路径原样不动。
|
|
3333
|
+
const serviceKind = classifyServicePayloadType(msg.payload?.type);
|
|
3334
|
+
if (serviceKind === 'result') {
|
|
3335
|
+
// 交给既有请求注册表匹配;命中后由它更新记录并唤醒等待者。
|
|
3336
|
+
const matched = getAunRequestRegistry().resolveIncoming({
|
|
3337
|
+
selfAid: this._aid || this.config.aid,
|
|
3338
|
+
fromAid,
|
|
3339
|
+
fromDeviceId: typeof msg.sender_device_id === 'string' ? msg.sender_device_id : undefined,
|
|
3340
|
+
messageId,
|
|
3341
|
+
payload: msg.payload,
|
|
3342
|
+
encrypted: !!env.encrypted,
|
|
3343
|
+
transport: 'p2p',
|
|
3344
|
+
});
|
|
3345
|
+
if (matched)
|
|
3346
|
+
return;
|
|
3347
|
+
logger.debug(`${this.logPrefix()} Unmatched service result: mid=${messageId} from=${fromAid}`);
|
|
3348
|
+
return;
|
|
3349
|
+
}
|
|
3350
|
+
if (serviceKind === 'request') {
|
|
3351
|
+
if (!this.claimInboundMessage('private', messageId, seq))
|
|
3352
|
+
return;
|
|
3353
|
+
await this.handleServiceMessage({
|
|
3354
|
+
fromAid,
|
|
3355
|
+
messageId,
|
|
3356
|
+
encrypted: !!env.encrypted,
|
|
3357
|
+
receivedAt,
|
|
3358
|
+
payload: (msg.payload && typeof msg.payload === 'object') ? msg.payload : {},
|
|
3359
|
+
});
|
|
3360
|
+
return;
|
|
3361
|
+
}
|
|
3278
3362
|
const appOwned = !this.config.pureIdentity;
|
|
3363
|
+
// ── 事件中心隔离(P1)──
|
|
3364
|
+
// AUN pubsub 事件(aun.pubsub/1)在传输层是加密 P2P 消息,与聊天共用 message.received 流。
|
|
3365
|
+
// 只凭受保护头判定(SDK 归一化后的可信信号;payload.type 可伪造,不单独作为依据),
|
|
3366
|
+
// 在去重表/observer 镜像/身份解析/入站日志/回声过滤之前早退:
|
|
3367
|
+
// 事件只由 EventService 的 onEvent 消费,消息层不产生会话、不进 thread。
|
|
3368
|
+
const earlyProtectedHeaders = verifiedProtectedHeaders(msg, env);
|
|
3369
|
+
if (earlyProtectedHeaders?.message_class === 'sdk_control'
|
|
3370
|
+
&& earlyProtectedHeaders.sdk_control_protocol === 'aun.pubsub') {
|
|
3371
|
+
logger.debug(`${this.logPrefix()} P2P dropped: pubsub control envelope (mid=${messageId})`);
|
|
3372
|
+
return;
|
|
3373
|
+
}
|
|
3279
3374
|
if (!appOwned && !this.claimInboundMessage('private', messageId, seq))
|
|
3280
3375
|
return;
|
|
3281
3376
|
const protectedHeaders = verifiedProtectedHeaders(msg, env);
|
|
@@ -3366,6 +3461,18 @@ export class AUNChannel {
|
|
|
3366
3461
|
logger.info(`${this.logPrefix()} P2P dropped terminal error: from=${fromAid || 'unknown'} mid=${messageId}`);
|
|
3367
3462
|
return;
|
|
3368
3463
|
}
|
|
3464
|
+
// ── services 模式:常规消息只认 Owner,其余一律不进 Agent。 ──
|
|
3465
|
+
// 判定放在准入之后、observer 镜像之前:blocked 静默,非 Owner 回引导语。
|
|
3466
|
+
// 只认本机名片 type === 'services';普通 agent 完全不受影响。
|
|
3467
|
+
if (appOwned && readLocalSelfIdentity(this.config.aid)?.type === 'services') {
|
|
3468
|
+
const decision = evaluateAppContactAdmission(this.config.aid, fromAid);
|
|
3469
|
+
if (!decision.allow || decision.reason !== 'owner') {
|
|
3470
|
+
if (decision.reason !== 'blocked') {
|
|
3471
|
+
await this.replyServiceModeRejection(fromAid, inboundType, !!env.encrypted);
|
|
3472
|
+
}
|
|
3473
|
+
return;
|
|
3474
|
+
}
|
|
3475
|
+
}
|
|
3369
3476
|
// Observer forward (inbound):在所有过滤之前转发原始明文 payload。
|
|
3370
3477
|
// forwardInbound 内部排除 self-echo 与 from-owner。
|
|
3371
3478
|
// 显式排除 observer.inject:它是 owner 对本 agent 的控制消息,不应镜像给观察者
|
|
@@ -4602,7 +4709,8 @@ export class AUNChannel {
|
|
|
4602
4709
|
if (!config)
|
|
4603
4710
|
return undefined;
|
|
4604
4711
|
const lifecycle = resolveAgentLifecycle(config);
|
|
4605
|
-
|
|
4712
|
+
// Legacy Owner hints are initialization inputs; active Agents need no automatic bind reconciliation.
|
|
4713
|
+
if (lifecycle === null || lifecycle === 'active')
|
|
4606
4714
|
return undefined;
|
|
4607
4715
|
return firstConfiguredOwner(config);
|
|
4608
4716
|
}
|
|
@@ -4822,6 +4930,126 @@ export class AUNChannel {
|
|
|
4822
4930
|
onProjectPathRequest(provider) {
|
|
4823
4931
|
this.projectPathProvider = provider;
|
|
4824
4932
|
}
|
|
4933
|
+
/**
|
|
4934
|
+
* 注入本 agent 的工程目录(`ChannelBuildContext.defaultProjectPath`)。
|
|
4935
|
+
* 服务脚本在非 fullaccess 档位下以它为沙箱 cwd;未注入时服务脚本按
|
|
4936
|
+
* `SCRIPT_SANDBOX_UNAVAILABLE` 明确拒绝,不回落 `process.cwd()`——
|
|
4937
|
+
* 后者会把整个 EvolCore 仓当成工程目录,沙箱边界会被悄悄放大。
|
|
4938
|
+
*/
|
|
4939
|
+
setDefaultProjectPath(projectPath) {
|
|
4940
|
+
const trimmed = projectPath?.trim();
|
|
4941
|
+
this.defaultProjectPath = trimmed ? trimmed : undefined;
|
|
4942
|
+
}
|
|
4943
|
+
// ── 服务路由 ────────────────────────────────────────────────────────────
|
|
4944
|
+
/** 供 daemon 启动时预热与 IPC 运维取用(不改变懒建语义)。 */
|
|
4945
|
+
getServiceRouter() {
|
|
4946
|
+
return this.ensureServiceRouter();
|
|
4947
|
+
}
|
|
4948
|
+
/**
|
|
4949
|
+
* 懒建服务路由实例并完成首次扫描。
|
|
4950
|
+
* identity 用本地名片(不触发网络);requires 判定与 ECK 变量读同一份。
|
|
4951
|
+
*/
|
|
4952
|
+
ensureServiceRouter() {
|
|
4953
|
+
if (this.serviceRouter)
|
|
4954
|
+
return this.serviceRouter;
|
|
4955
|
+
const aid = this.config.aid;
|
|
4956
|
+
const identity = readLocalSelfIdentity(aid) ?? { aid, type: 'agent', exttype: '' };
|
|
4957
|
+
this.serviceRouter = getServiceRouter(aid, agentServicesDir(aid), {
|
|
4958
|
+
aid,
|
|
4959
|
+
identity: () => readLocalSelfIdentity(aid) ?? identity,
|
|
4960
|
+
// 与 trigger / 事件中心同源:agent 的工程目录。沙箱要求绝对真实目录,
|
|
4961
|
+
// 存在性与 H/L 分类由 buildTriggerScriptLaunch 自己校验并明确报错。
|
|
4962
|
+
getProjectPath: () => this.defaultProjectPath,
|
|
4963
|
+
permissionMode: () => resolveRuntimePermissionMode({ selfAid: aid }).effectiveValue,
|
|
4964
|
+
// bypass + owner 才免沙箱;角色取调用方(service 消息的 from)。解析失败按未知处理。
|
|
4965
|
+
resolvePeerRole: fromAid => {
|
|
4966
|
+
try {
|
|
4967
|
+
return resolvePeerRoleDetail({
|
|
4968
|
+
selfAid: aid,
|
|
4969
|
+
channelKey: `aun#${aid}#main`,
|
|
4970
|
+
channelType: 'aun',
|
|
4971
|
+
chatType: 'private',
|
|
4972
|
+
actorId: fromAid,
|
|
4973
|
+
conversationId: fromAid,
|
|
4974
|
+
}).effectiveRole;
|
|
4975
|
+
}
|
|
4976
|
+
catch {
|
|
4977
|
+
return undefined;
|
|
4978
|
+
}
|
|
4979
|
+
},
|
|
4980
|
+
});
|
|
4981
|
+
this.serviceRouter.ensureStarted(identity);
|
|
4982
|
+
return this.serviceRouter;
|
|
4983
|
+
}
|
|
4984
|
+
/**
|
|
4985
|
+
* services 模式下给非 Owner 的引导回复。
|
|
4986
|
+
* 协议消息(menu./bind./observer./friend./contact.request.)一律静默;受限流(builtin),超限静默。
|
|
4987
|
+
*/
|
|
4988
|
+
async replyServiceModeRejection(toAid, inboundType, encrypted) {
|
|
4989
|
+
const type = typeof inboundType === 'string' ? inboundType : '';
|
|
4990
|
+
if (type.startsWith('menu.') || type.startsWith('bind.') || type.startsWith('observer.')
|
|
4991
|
+
|| type.startsWith('friend.') || type.startsWith('contact.request.'))
|
|
4992
|
+
return;
|
|
4993
|
+
const router = this.ensureServiceRouter();
|
|
4994
|
+
const limit = router.consumeBuiltinQuota(toAid);
|
|
4995
|
+
if (!limit.allow)
|
|
4996
|
+
return;
|
|
4997
|
+
const text = `我是服务节点,只接受 Owner 的直接消息。\n可用的服务调用方式:ec services describe ${this.config.aid}\n如需联系,请通过 Owner 申请。`;
|
|
4998
|
+
const result = await this.sendStructuredResult(toAid, { type: 'text', text }, {
|
|
4999
|
+
delivery: { chatType: 'private' },
|
|
5000
|
+
metadata: { encrypted, source: 'daemon' },
|
|
5001
|
+
});
|
|
5002
|
+
if (!result.ok) {
|
|
5003
|
+
logger.debug(`${this.logPrefix()} Service-mode rejection not delivered: code=${result.code ?? 'UNKNOWN'} to=${toAid}`);
|
|
5004
|
+
}
|
|
5005
|
+
}
|
|
5006
|
+
/** 服务调用的准入判决。blocked 静默;其余未通过回 NOT_AUTHORIZED。 */
|
|
5007
|
+
serviceAdmission(fromAid) {
|
|
5008
|
+
const decision = evaluateAppContactAdmission(this.config.aid, fromAid);
|
|
5009
|
+
if (decision.allow)
|
|
5010
|
+
return { admission: 'allow' };
|
|
5011
|
+
if (decision.reason === 'blocked')
|
|
5012
|
+
return { admission: 'blocked' };
|
|
5013
|
+
return { admission: 'not_authorized', requestContact: currentContactBinding(this.config.aid)?.owner_aid };
|
|
5014
|
+
}
|
|
5015
|
+
/**
|
|
5016
|
+
* 入站服务消息(请求支)。调用方已完成 claim。
|
|
5017
|
+
* 应答支不经过这里——那由 AunRequestRegistry 在消息层更早匹配。
|
|
5018
|
+
*/
|
|
5019
|
+
async handleServiceMessage(input) {
|
|
5020
|
+
const router = this.ensureServiceRouter();
|
|
5021
|
+
const payload = input.payload;
|
|
5022
|
+
const rawType = typeof payload.type === 'string' ? payload.type : '';
|
|
5023
|
+
const requestId = typeof payload.request_id === 'string' && payload.request_id
|
|
5024
|
+
? payload.request_id
|
|
5025
|
+
: input.messageId;
|
|
5026
|
+
const message = {
|
|
5027
|
+
type: rawType,
|
|
5028
|
+
requestId,
|
|
5029
|
+
requestIdGenerated: requestId === input.messageId,
|
|
5030
|
+
fromAid: input.fromAid,
|
|
5031
|
+
messageId: input.messageId,
|
|
5032
|
+
encrypted: input.encrypted,
|
|
5033
|
+
payload,
|
|
5034
|
+
receivedAt: input.receivedAt,
|
|
5035
|
+
};
|
|
5036
|
+
const { admission, requestContact } = this.serviceAdmission(input.fromAid);
|
|
5037
|
+
const reply = await router.handleRequest(message, { admission, requestContact });
|
|
5038
|
+
if (!reply.shouldSend)
|
|
5039
|
+
return;
|
|
5040
|
+
await this.sendServiceReply(input.fromAid, input.messageId, input.encrypted, reply);
|
|
5041
|
+
}
|
|
5042
|
+
/** 回复:点对点、带 service 标记位,不带 threadId/topicName/chatmode。 */
|
|
5043
|
+
async sendServiceReply(toAid, replyToMessageId, encrypted, reply) {
|
|
5044
|
+
const result = await this.sendStructuredResult(toAid, reply.payload, {
|
|
5045
|
+
delivery: { chatType: 'private', service: { type: reply.type, requestId: reply.requestId } },
|
|
5046
|
+
metadata: { encrypted, source: 'daemon' },
|
|
5047
|
+
replyToMessageId,
|
|
5048
|
+
});
|
|
5049
|
+
if (!result.ok) {
|
|
5050
|
+
logger.warn(`${this.logPrefix()} Service reply send failed: type=${reply.type} code=${result.code ?? 'UNKNOWN'} error=${result.error ?? ''}`);
|
|
5051
|
+
}
|
|
5052
|
+
}
|
|
4825
5053
|
setSessionStateResolver(resolver) {
|
|
4826
5054
|
this.sessionStateResolver = resolver;
|
|
4827
5055
|
}
|
|
@@ -5289,6 +5517,10 @@ export class AUNChannel {
|
|
|
5289
5517
|
}
|
|
5290
5518
|
}
|
|
5291
5519
|
appContactOutboundBlock(channelId, delivery, payload, params) {
|
|
5520
|
+
// 服务回复是对一次已到达请求的应答,不是主动联系;且拒绝信息本身必须能送达,
|
|
5521
|
+
// 否则调用方只会看到超时。
|
|
5522
|
+
if (delivery.chatType === 'private' && delivery.service)
|
|
5523
|
+
return undefined;
|
|
5292
5524
|
if (delivery.chatType === 'group' || this.config.pureIdentity
|
|
5293
5525
|
|| this.hasContactControlPermit(channelId, payload, params))
|
|
5294
5526
|
return undefined;
|
|
@@ -5299,15 +5531,40 @@ export class AUNChannel {
|
|
|
5299
5531
|
if (decision.allow)
|
|
5300
5532
|
return undefined;
|
|
5301
5533
|
return { status: decision.reason === 'unavailable' ? 'retry' : 'permanent',
|
|
5302
|
-
code: '
|
|
5534
|
+
code: decision.reason === 'unavailable' ? 'CONTACT_DIRECTORY_UNAVAILABLE' : 'CONTACT_DENIED',
|
|
5535
|
+
error: `联系人准入未通过:${decision.reason}` };
|
|
5303
5536
|
}
|
|
5304
5537
|
async prepareAppContactOutbound(channelId, delivery, payload, params) {
|
|
5538
|
+
if (delivery.chatType === 'private' && delivery.service)
|
|
5539
|
+
return undefined;
|
|
5305
5540
|
if (delivery.chatType === 'private' && !this.config.pureIdentity
|
|
5306
|
-
&& !this.hasContactControlPermit(channelId, payload, params)
|
|
5541
|
+
&& !this.hasContactControlPermit(channelId, payload, params)
|
|
5542
|
+
&& !this.acceptsVerifiedOwnership(channelId, payload, params)) {
|
|
5307
5543
|
await ownerResolver.refresh(this.config.aid, { maxAgeMs: OWNERSHIP_CACHE_MAX_AGE_MS, allowTransient: true });
|
|
5308
5544
|
}
|
|
5309
5545
|
return this.appContactOutboundBlock(channelId, delivery, payload, params);
|
|
5310
5546
|
}
|
|
5547
|
+
/**
|
|
5548
|
+
* A caller that already holds the consensus may skip the refresh round-trip.
|
|
5549
|
+
*
|
|
5550
|
+
* Only lifecycle notices qualify, and only toward their own Owner. Shutdown is
|
|
5551
|
+
* the reason this exists: the offline notice runs while the daemon is tearing
|
|
5552
|
+
* down, so a network refresh would outlive the AUN connection it needs.
|
|
5553
|
+
* Admission itself is unchanged — the block below still demands a live
|
|
5554
|
+
* consensus in the resolver cache, so this skips the check of the cache's
|
|
5555
|
+
* freshness, never the requirement that a consensus exists.
|
|
5556
|
+
*/
|
|
5557
|
+
acceptsVerifiedOwnership(channelId, payload, params) {
|
|
5558
|
+
if (params?.ownershipVerified !== true)
|
|
5559
|
+
return false;
|
|
5560
|
+
const notice = payload;
|
|
5561
|
+
if (!notice || notice.type !== 'notice'
|
|
5562
|
+
|| (notice.subtype !== 'agent.online' && notice.subtype !== 'agent.offline'))
|
|
5563
|
+
return false;
|
|
5564
|
+
// Even if the flag ever leaked, it cannot widen admission: the target must be
|
|
5565
|
+
// the Owner the live consensus names, which admission allows unconditionally.
|
|
5566
|
+
return currentContactBinding(this.config.aid)?.owner_aid === channelId;
|
|
5567
|
+
}
|
|
5311
5568
|
async sendAunPayload(channelId, payload, context, label) {
|
|
5312
5569
|
const delivery = this.requireDelivery(channelId, context);
|
|
5313
5570
|
const blocked = await this.prepareAppContactOutbound(channelId, delivery, payload);
|
|
@@ -5323,7 +5580,7 @@ export class AUNChannel {
|
|
|
5323
5580
|
logger.error(`${this.logPrefix()} Dropped durable AUN payload: invalid payload.mentions (${detail}) code=${code} channel=${channelId}`);
|
|
5324
5581
|
return { ok: false, status: 'permanent', error: detail, code };
|
|
5325
5582
|
}
|
|
5326
|
-
if (delivery.chatType === 'private') {
|
|
5583
|
+
if (delivery.chatType === 'private' && !delivery.service) {
|
|
5327
5584
|
normalizedPayload = this.withCurrentTopicName(channelId, normalizedPayload);
|
|
5328
5585
|
}
|
|
5329
5586
|
if (!this.client || !this.connected) {
|
|
@@ -5348,6 +5605,12 @@ export class AUNChannel {
|
|
|
5348
5605
|
// Truncate payload if too large (AUN SDK limit: 1MB)
|
|
5349
5606
|
const friendPayload = typeof payload.type === 'string' && payload.type.startsWith('friend.');
|
|
5350
5607
|
const truncatedPayload = friendPayload ? payloadWithCausationRef : this.truncatePayloadIfNeeded(await this.withSessionState(channelId, payloadWithCausationRef, context), label);
|
|
5608
|
+
if (payload.type === 'activity' && truncatedPayload.type !== 'activity') {
|
|
5609
|
+
return {
|
|
5610
|
+
ok: false, status: 'permanent', code: 'PAYLOAD_TOO_LARGE',
|
|
5611
|
+
error: 'activity payload cannot fit the AUN limit without losing its structure',
|
|
5612
|
+
};
|
|
5613
|
+
}
|
|
5351
5614
|
const params = { payload: truncatedPayload, encrypt };
|
|
5352
5615
|
const isMenuPayload = typeof truncatedPayload.type === 'string' && truncatedPayload.type.startsWith('menu.');
|
|
5353
5616
|
if (!isGroup && ['menu.response', 'menu.event'].includes(truncatedPayload.type))
|
|
@@ -5904,7 +6167,7 @@ export class AUNChannel {
|
|
|
5904
6167
|
code: 'INVALID_REQUEST_TTL',
|
|
5905
6168
|
};
|
|
5906
6169
|
}
|
|
5907
|
-
const contactBlock = await this.prepareAppContactOutbound(args.to, { chatType: 'private' }, finalPayload, { encrypt: args.encrypt, rawPayload: preserveRawPayload });
|
|
6170
|
+
const contactBlock = await this.prepareAppContactOutbound(args.to, args.service ? { chatType: 'private', service: args.service } : { chatType: 'private' }, finalPayload, { encrypt: args.encrypt, rawPayload: preserveRawPayload, ownershipVerified: args.ownershipVerified === true });
|
|
5908
6171
|
if (contactBlock)
|
|
5909
6172
|
return { ok: false, code: contactBlock.code, error: contactBlock.error };
|
|
5910
6173
|
if (preserveRawPayload && jsonUtf8Size(finalPayload) > AUN_MAX_PAYLOAD_SIZE) {
|
|
@@ -5941,7 +6204,8 @@ export class AUNChannel {
|
|
|
5941
6204
|
peerKey: formatPeerKey('aun', args.to),
|
|
5942
6205
|
});
|
|
5943
6206
|
}
|
|
5944
|
-
|
|
6207
|
+
// 服务调用不是会话消息:不注入 chatmode,避免对端入站日志与脚本 data 被会话字段污染。
|
|
6208
|
+
if (chatmode && !finalPayload.chatmode && !args.service)
|
|
5945
6209
|
finalPayload.chatmode = chatmode;
|
|
5946
6210
|
const parentCausation = preserveRawPayload ? undefined : normalizeCausation(args.causation);
|
|
5947
6211
|
const outboundCausation = parentCausation ? deriveCausation(parentCausation) : undefined;
|
|
@@ -5952,7 +6216,7 @@ export class AUNChannel {
|
|
|
5952
6216
|
}
|
|
5953
6217
|
if (args.debug)
|
|
5954
6218
|
finalPayload.debug = { ...args.debug, sentAt: localTimestamp() };
|
|
5955
|
-
if (!preserveRawPayload) {
|
|
6219
|
+
if (!preserveRawPayload && !args.service) {
|
|
5956
6220
|
finalPayload = this.withCurrentTopicName(args.to, finalPayload);
|
|
5957
6221
|
}
|
|
5958
6222
|
if (!preserveRawPayload) {
|
|
@@ -5987,7 +6251,12 @@ export class AUNChannel {
|
|
|
5987
6251
|
}
|
|
5988
6252
|
this.forwardOutbound(result, args.debug);
|
|
5989
6253
|
let logWritten = false;
|
|
5990
|
-
|
|
6254
|
+
// 自发(`--to <本端AID>`)不写出站日志:chatDir 会按 (to=本端, self=本端) 算成
|
|
6255
|
+
// 「我↔我」目录,`ThreadService.listPeers` 的磁盘兜底会把它列成真实对端,
|
|
6256
|
+
// 而话题 T 的历史里也会凭空多出一条「发给本端自己」的出站记录。
|
|
6257
|
+
// 「自己收到了什么」由本地注入那条入站记录(source='self-address')表达。
|
|
6258
|
+
const selfAddressed = args.to.replace(/^@/, '').toLowerCase() === this.config.aid.replace(/^@/, '').toLowerCase();
|
|
6259
|
+
if (!selfAddressed && args.log?.content !== undefined) {
|
|
5991
6260
|
const classified = classifyAunPayloadForLog(finalPayload);
|
|
5992
6261
|
const chatDir = chatDirPath(resolvePaths().sessionsDir, 'aun', args.to, this.config.aid);
|
|
5993
6262
|
fs.mkdirSync(chatDir, { recursive: true });
|
|
@@ -6052,6 +6321,7 @@ export class AUNChannel {
|
|
|
6052
6321
|
// Preserve the notice verbatim: no session state, topic name or mentions.
|
|
6053
6322
|
rawPayload: true,
|
|
6054
6323
|
ttl,
|
|
6324
|
+
ownershipVerified: args.ownershipVerified,
|
|
6055
6325
|
});
|
|
6056
6326
|
}
|
|
6057
6327
|
/** Public contracts use this AID's existing authenticated storage connection. */
|
|
@@ -6297,7 +6567,7 @@ export class AUNChannel {
|
|
|
6297
6567
|
payload.chatmode = context.metadata.chatmode;
|
|
6298
6568
|
if (context?.metadata?.forkAnchor)
|
|
6299
6569
|
payload.fork_anchor = context.metadata.forkAnchor;
|
|
6300
|
-
if (delivery.chatType === 'private') {
|
|
6570
|
+
if (delivery.chatType === 'private' && !delivery.service) {
|
|
6301
6571
|
Object.assign(payload, this.withCurrentTopicName(channelId, payload));
|
|
6302
6572
|
}
|
|
6303
6573
|
const causation = normalizeCausation(context?.metadata?.causation);
|
|
@@ -6704,7 +6974,7 @@ export class AUNChannel {
|
|
|
6704
6974
|
if (context?.debug)
|
|
6705
6975
|
payloadWithChatmode.debug = { ...context.debug, sentAt: localTimestamp() };
|
|
6706
6976
|
let thoughtPayload = payloadWithChatmode;
|
|
6707
|
-
if (delivery.chatType === 'private') {
|
|
6977
|
+
if (delivery.chatType === 'private' && !delivery.service) {
|
|
6708
6978
|
thoughtPayload = this.withCurrentTopicName(channelId, thoughtPayload);
|
|
6709
6979
|
}
|
|
6710
6980
|
thoughtPayload = this.limitThoughtPayload(thoughtPayload);
|
|
@@ -6753,7 +7023,7 @@ export class AUNChannel {
|
|
|
6753
7023
|
if (!isThoughtTooLargeError(error))
|
|
6754
7024
|
throw error;
|
|
6755
7025
|
thoughtPayload = this.thoughtPayloadFallback(thoughtPayload);
|
|
6756
|
-
if (delivery.chatType === 'private') {
|
|
7026
|
+
if (delivery.chatType === 'private' && !delivery.service) {
|
|
6757
7027
|
thoughtPayload = this.withCurrentTopicName(channelId, thoughtPayload);
|
|
6758
7028
|
}
|
|
6759
7029
|
params.payload = thoughtPayload;
|
|
@@ -6812,7 +7082,7 @@ export class AUNChannel {
|
|
|
6812
7082
|
finalPayload.thread_id = context.threadId;
|
|
6813
7083
|
if (context?.replyToMessageId && !finalPayload.ref_message_id)
|
|
6814
7084
|
finalPayload.ref_message_id = context.replyToMessageId;
|
|
6815
|
-
if (!isGroup) {
|
|
7085
|
+
if (!isGroup && !delivery.service) {
|
|
6816
7086
|
Object.assign(finalPayload, this.withCurrentTopicName(channelId, finalPayload));
|
|
6817
7087
|
}
|
|
6818
7088
|
const isMenuPayload = typeof finalPayload.type === 'string' && finalPayload.type.startsWith('menu.');
|
|
@@ -6853,7 +7123,8 @@ export class AUNChannel {
|
|
|
6853
7123
|
return { ok: false, ...failure };
|
|
6854
7124
|
}
|
|
6855
7125
|
logger.info(`${this.logPrefix()} message.send (${payload.type}) ok: to=${this.peerLabel(targetAid)} mid=${mid} encrypt=${encrypt}`);
|
|
6856
|
-
|
|
7126
|
+
// 服务回复不进 observer 镜像(回归 13)。
|
|
7127
|
+
if (!isMenuPayload && !delivery.service)
|
|
6857
7128
|
this.forwardOutbound(result);
|
|
6858
7129
|
return { ok: true, messageId: mid };
|
|
6859
7130
|
}
|
|
@@ -7132,7 +7403,7 @@ export class AUNChannel {
|
|
|
7132
7403
|
attachment: { ...attachment },
|
|
7133
7404
|
context,
|
|
7134
7405
|
}), context);
|
|
7135
|
-
if (!isGroup) {
|
|
7406
|
+
if (!isGroup && !delivery.service) {
|
|
7136
7407
|
Object.assign(filePayload, this.withCurrentTopicName(channelId, filePayload));
|
|
7137
7408
|
}
|
|
7138
7409
|
const fileTargetAid = channelId;
|
|
@@ -7464,8 +7735,8 @@ export class AUNChannel {
|
|
|
7464
7735
|
async sendCustomPayload(channelId, payload, context) {
|
|
7465
7736
|
// Validate the route even when disconnected; callers must never be able
|
|
7466
7737
|
// to bypass the fail-closed AUN routing contract. This compatibility API
|
|
7467
|
-
// is
|
|
7468
|
-
//
|
|
7738
|
+
// is best-effort while offline except for Menu responses, whose callers
|
|
7739
|
+
// must receive the failure to retry or report the delivery outcome.
|
|
7469
7740
|
const delivery = this.requireDelivery(channelId, context);
|
|
7470
7741
|
context = this.withDelivery(context, delivery);
|
|
7471
7742
|
// SDK 0.3.0 E2EE requires payload to be an object
|
|
@@ -7485,6 +7756,11 @@ export class AUNChannel {
|
|
|
7485
7756
|
return;
|
|
7486
7757
|
}
|
|
7487
7758
|
if (!this.connected || !this.client) {
|
|
7759
|
+
if (payloadObj.type === 'menu.response') {
|
|
7760
|
+
throw Object.assign(new Error('AUN channel is not connected'), {
|
|
7761
|
+
name: 'AUNSendError', code: 'AUN_NOT_CONNECTED', retryable: true,
|
|
7762
|
+
});
|
|
7763
|
+
}
|
|
7488
7764
|
logger.debug(`${this.logPrefix()} Custom payload skipped while disconnected: channel=${channelId}`);
|
|
7489
7765
|
return;
|
|
7490
7766
|
}
|
|
@@ -7497,8 +7773,7 @@ export class AUNChannel {
|
|
|
7497
7773
|
* 传入预算时到点就往下走,不再等 SDK。
|
|
7498
7774
|
*/
|
|
7499
7775
|
async disconnect(clientCloseBudgetMs) {
|
|
7500
|
-
this.
|
|
7501
|
-
this.configuredOwnerBindEpoch++;
|
|
7776
|
+
this.prepareShutdown();
|
|
7502
7777
|
if (this.client) {
|
|
7503
7778
|
unregisterSameOwnerClient(this.config.aid, this.client);
|
|
7504
7779
|
ownerResolver.detachClient(this.config.aid, this.client);
|
|
@@ -7751,6 +8026,8 @@ export class AUNChannelPlugin {
|
|
|
7751
8026
|
aunTrace: ctx.debug?.aunTrace,
|
|
7752
8027
|
aunSdkLog: ctx.debug?.aunSdkLog,
|
|
7753
8028
|
});
|
|
8029
|
+
// 工程目录:服务脚本沙箱 cwd 与附件落盘共用同一个来源。
|
|
8030
|
+
channel.setDefaultProjectPath(ctx.defaultProjectPath);
|
|
7754
8031
|
const mode = resolveShowActivities(inst);
|
|
7755
8032
|
const adapter = {
|
|
7756
8033
|
channelName: inst.name,
|
|
@@ -7976,13 +8253,12 @@ export class AUNChannelPlugin {
|
|
|
7976
8253
|
continue;
|
|
7977
8254
|
}
|
|
7978
8255
|
const aunPayload = channel.buildActivityPayload(envelope, replyCtx, item);
|
|
7979
|
-
if (envelope.chatmode === 'proactive') {
|
|
8256
|
+
if (envelope.chatmode === 'proactive' && envelope.activityTransport !== 'message') {
|
|
7980
8257
|
await channel.sendThought(channelId, envelope.taskId, aunPayload, replyCtx);
|
|
7981
8258
|
}
|
|
7982
8259
|
else {
|
|
7983
|
-
//
|
|
7984
|
-
//
|
|
7985
|
-
// outbox queue while preserving the common delivery contract.
|
|
8260
|
+
// The PA's proactive activities share interactive's reliable
|
|
8261
|
+
// activity outbox without changing the execution flow.
|
|
7986
8262
|
const result = await channel.sendReliableStructured(channelId, aunPayload, replyCtx, channel.activityLogText(item));
|
|
7987
8263
|
// Test and legacy adapters may stub this method without a
|
|
7988
8264
|
// structured result; the call itself still proves acceptance.
|