evolcore 0.0.48 → 0.0.50
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 +97 -0
- package/bin/ecmsg.js +9 -4
- package/dist/ability/caller/authorization.js +21 -0
- package/dist/ability/caller/command.js +164 -0
- package/dist/ability/caller/contract.js +102 -0
- package/dist/ability/caller/daemon.js +158 -0
- package/dist/ability/caller/service.js +380 -0
- package/dist/ability/command-contract.js +5 -0
- package/dist/ability/daemon.js +5 -1
- package/dist/ability/interop-v1.js +10 -3
- package/dist/ability/management.js +1 -0
- package/dist/agent-template/jobs.js +173 -1
- package/dist/agent-template/runtime.js +285 -8
- package/dist/agent-template/service.js +1159 -40
- package/dist/agent-template/types.js +2 -1
- package/dist/agents/baseagent-availability.js +27 -3
- package/dist/agents/baseagent-capability-adapter.js +102 -0
- package/dist/agents/baseagent-plugin-descriptor.js +274 -0
- package/dist/agents/baseagent-plugin-loader.js +145 -0
- package/dist/agents/baseagent.js +68 -2
- package/dist/agents/claude-gateway/agent-registration.js +389 -0
- package/dist/agents/claude-gateway/binding.js +96 -0
- package/dist/agents/claude-gateway/inbox.js +138 -0
- package/dist/agents/claude-gateway/index.js +125 -0
- package/dist/agents/claude-gateway/listing.js +330 -0
- package/dist/agents/claude-gateway/router.js +328 -0
- package/dist/agents/claude-gateway/sessions.js +128 -0
- package/dist/agents/claude-gateway/terminal.js +250 -0
- package/dist/agents/claude-gateway/transcript.js +272 -0
- package/dist/agents/claude-gateway/types.js +14 -0
- package/dist/agents/claude-runner.js +6 -10
- package/dist/agents/codex-runner.js +9 -2
- package/dist/agents/{gemini-runner.js → gemini/gemini-runner.js} +17 -17
- package/dist/{core/session/adapters → agents/gemini}/gemini-session-file-adapter.js +2 -2
- package/dist/agents/gemini/index.js +51 -0
- package/dist/aun/aid/control-aid.js +52 -32
- package/dist/aun/group/invite-service.js +6 -36
- package/dist/aun/group/operations.js +6 -0
- package/dist/aun/msg/mention-schema.js +1 -1
- package/dist/aun/msg/p2p.js +31 -2
- package/dist/aun/msg/upload.js +126 -3
- package/dist/build-identity.json +1 -1
- package/dist/channels/aun.js +1175 -457
- package/dist/cli/ability-command.js +42 -0
- package/dist/cli/agent-command.js +20 -1
- package/dist/cli/agent-create.js +78 -18
- package/dist/cli/agent-template.js +5 -3
- package/dist/cli/agent.js +91 -0
- package/dist/cli/aun-commands.js +92 -34
- package/dist/cli/bench.js +5 -2
- package/dist/cli/config.js +22 -6
- package/dist/cli/daemon-commands.js +245 -101
- package/dist/cli/directory.js +6 -1
- package/dist/cli/ecmsg-gateway.js +11 -9
- package/dist/cli/index.js +30 -5
- package/dist/cli/init.js +39 -63
- package/dist/cli/managed-command-guard.js +3 -0
- package/dist/cli/menu-client.js +32 -7
- package/dist/cli/model.js +20 -5
- package/dist/cli/pay-command.js +30 -0
- package/dist/cli/provider-command.js +6 -2
- package/dist/cli/quota.js +89 -0
- package/dist/cli/restart-monitor.js +2 -2
- package/dist/cli/role.js +1 -0
- package/dist/cli/services-command.js +12 -9
- package/dist/cli/team-workspace-command.js +56 -2
- package/dist/cli/thread-command.js +78 -12
- package/dist/config/access-policy.js +16 -3
- package/dist/config/config-field-policy.js +88 -9
- package/dist/config/config-manager.js +97 -47
- package/dist/config/config-operation-service.js +22 -1
- package/dist/config/gateway-config.js +9 -8
- package/dist/config/owner-config.js +0 -16
- package/dist/config/peer-role-resolver.js +1 -7
- package/dist/config/providers-config.js +107 -20
- package/dist/config/providers-management.js +45 -21
- package/dist/config/resolved-config-op.js +4 -44
- package/dist/config/schema-migration.js +78 -5
- package/dist/config/schema-registry.js +52 -7
- package/dist/config-store.js +1309 -17
- package/dist/core/agent-application-service.js +220 -1
- package/dist/core/agent-ipc-registration.js +19 -2
- package/dist/core/agent-reload-coordinator.js +5 -0
- package/dist/core/agent-runtime.js +198 -54
- package/dist/core/auth/agent-delegation.js +14 -0
- package/dist/core/auth/delegation-authorization.js +33 -26
- package/dist/core/auth/operation-authorizer.js +16 -1
- package/dist/core/auth/operation-catalog.js +59 -7
- package/dist/core/baseagent-loader.js +30 -3
- package/dist/core/capability/capability-manager.js +16 -7
- package/dist/core/channel-runtime.js +4 -2
- package/dist/core/command/agent-control.js +20 -2
- package/dist/core/command/agent-template-menu.js +4 -3
- package/dist/core/command/cli-intent-parser.js +28 -0
- package/dist/core/command/command-handler.js +45 -2
- package/dist/core/command/menu-catalog.js +20 -4
- package/dist/core/command/menu-file-path.js +70 -0
- package/dist/core/command/menu-handler.js +97 -73
- package/dist/core/command/menu-protocol.js +29 -0
- package/dist/core/command/menu-query-batch.js +2 -2
- package/dist/core/command/private-mention-menu.js +71 -0
- package/dist/core/command/remote-shell.js +565 -0
- package/dist/core/command/slash-handler.js +17 -26
- package/dist/core/command/team-workspace-bootstrap.js +2 -1
- package/dist/core/command/topic-slash.js +7 -1
- package/dist/core/daemon-bootstrap.js +0 -4
- package/dist/core/daemon-control.js +58 -1
- package/dist/core/daemon-lifecycle.js +29 -7
- package/dist/core/evolagent-registry.js +18 -9
- package/dist/core/handoff/runtime.js +1 -1
- package/dist/core/host-snapshot.js +8 -3
- package/dist/core/initialization/service.js +3 -0
- package/dist/core/interaction-router.js +130 -0
- package/dist/core/ipc-registration.js +5 -0
- package/dist/core/memory/consolidation-context.js +2 -1
- package/dist/core/memory/consolidation.js +35 -64
- package/dist/core/message/aun-ipc-sender.js +213 -74
- package/dist/core/message/aun-request-registry.js +31 -0
- package/dist/core/message/contact-admission.js +91 -6
- package/dist/core/message/contact-pending-inbound.js +113 -0
- package/dist/core/message/contact-thread-approval.js +212 -0
- package/dist/core/message/im-renderer.js +40 -1
- package/dist/core/message/message-admission.js +5 -39
- package/dist/core/message/message-bridge.js +197 -45
- package/dist/core/message/message-log.js +32 -0
- package/dist/core/message/message-queue.js +102 -18
- package/dist/core/message/peer-mode.js +15 -4
- package/dist/core/message/response-engine.js +174 -26
- package/dist/core/message/send-options.js +37 -3
- package/dist/core/message/send-routing.js +11 -7
- package/dist/core/model/config-scope.js +6 -14
- package/dist/core/model/model-catalog.js +5 -5
- package/dist/core/model/model-diagnostics.js +19 -0
- package/dist/core/model/model-fallback.js +13 -2
- package/dist/core/ownership/owner-resolver.js +12 -86
- package/dist/core/pack-auth.js +7 -0
- package/dist/core/pack-install.js +1 -1
- package/dist/core/permission/ec-command-parser.js +288 -77
- package/dist/core/permission/protected-paths.js +64 -9
- package/dist/core/permission/services-path-acl.js +458 -0
- package/dist/core/permission/tool-policy.js +26 -10
- package/dist/core/relation/peer-identity.js +13 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +6 -2
- package/dist/core/session/adapters/codex-session-file-adapter.js +4 -0
- package/dist/core/session/session-manager.js +47 -10
- package/dist/core/session/session-mapper.js +16 -0
- package/dist/core/skill/index-generator.js +2 -3
- package/dist/core/skill/switch-resolver.js +3 -0
- package/dist/core/task/task-recovery-service.js +1 -0
- package/dist/core/thread/command-parser.js +4 -1
- package/dist/core/thread/ipc-operation.js +4 -2
- package/dist/core/thread/thread-operation.js +25 -10
- package/dist/core/thread/thread-service.js +294 -55
- package/dist/core/thread/topic-id.js +67 -2
- package/dist/core/thread/types.js +15 -1
- package/dist/directory/owner-directory-admission.js +11 -8
- package/dist/directory/owner-directory-cache.js +19 -0
- package/dist/directory/owner-directory-markdown.js +1 -1
- package/dist/directory/owner-directory-policy.js +5 -30
- package/dist/directory/owner-directory-request-operation.js +5 -2
- package/dist/eck/kit-renderer.js +3 -2
- package/dist/eck/message-renderer.js +28 -5
- package/dist/ecweb/basic-settings-service.js +5 -9
- package/dist/ecweb/providers-service.js +4 -2
- package/dist/ecweb/runtime/supervisor.js +36 -8
- package/dist/event-center/center-config.js +9 -5
- package/dist/event-center/dispatcher.js +10 -1
- package/dist/event-center/ipc-operation.js +19 -0
- package/dist/event-center/registry.js +20 -5
- package/dist/event-center/runtime.js +10 -7
- package/dist/index.js +120 -41
- package/dist/ipc.js +83 -3
- package/dist/outputs/authorization.js +16 -0
- package/dist/outputs/cards.js +336 -0
- package/dist/outputs/events.js +3 -2
- package/dist/outputs/protocol.js +1 -0
- package/dist/outputs/service.js +2 -15
- package/dist/paths.js +48 -1
- package/dist/pay/command.js +38 -0
- package/dist/pay/protocol.js +136 -0
- package/dist/pay/runtime.js +188 -0
- package/dist/pay/service.js +384 -0
- package/dist/pay/store.js +81 -0
- package/dist/response-system/engines/v1/proactive-flow.js +29 -2
- package/dist/services/dispatcher.js +23 -5
- package/dist/services/host/main.js +388 -0
- package/dist/services/host/protocol.js +118 -0
- package/dist/services/host/resident.js +310 -0
- package/dist/services/host-client.js +386 -0
- package/dist/services/host-deploy.js +180 -0
- package/dist/services/host-launch.js +117 -0
- package/dist/services/host-recycle.js +203 -0
- package/dist/services/host-runtime.js +802 -0
- package/dist/services/idempotency.js +44 -86
- package/dist/services/index-generator.js +4 -3
- package/dist/services/index.js +204 -22
- package/dist/services/ipc-operation.js +288 -44
- package/dist/services/pack-manager.js +1 -0
- package/dist/services/script-runner.js +515 -83
- package/dist/services/service-payload.js +13 -7
- package/dist/services/validation.js +109 -4
- package/dist/stats/budget.js +1 -1
- package/dist/stats/model-resolver.js +2 -2
- package/dist/stats/quota-query.js +95 -0
- package/dist/trigger/application-service.js +6 -4
- package/dist/trigger/local-files.js +19 -9
- package/dist/trigger/scheduler.js +22 -12
- package/dist/trigger/script-sandbox.js +51 -8
- package/dist/utils/aid-bind.js +3 -0
- package/dist/utils/atomic-write.js +22 -8
- package/dist/utils/evolcore-version.js +2 -2
- package/dist/utils/host-info.js +173 -1
- package/dist/utils/logger.js +2 -2
- package/dist/utils/media-cache.js +190 -43
- package/dist/utils/npm-ops.js +43 -8
- package/dist/utils/restart-safety.js +14 -1
- package/dist/utils/system-memory.js +113 -25
- package/dist/utils/systemd-lifecycle.js +154 -0
- package/dist/utils/windows-shell-trust.js +7 -3
- package/dist/workbench/service.js +1 -1
- package/kits/docs/INDEX.md +3 -2
- package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +1 -0
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/evolcore/INDEX.md +9 -6
- package/kits/docs/evolcore/agent.md +36 -1
- package/kits/docs/evolcore/aid.md +45 -3
- package/kits/docs/evolcore/config.md +5 -2
- package/kits/docs/evolcore/directory.md +8 -9
- package/kits/docs/evolcore/group.md +2 -1
- package/kits/docs/evolcore/memory-tags.md +2 -0
- package/kits/docs/evolcore/menu-client.md +3 -3
- package/kits/docs/evolcore/menu-protocol.md +7 -0
- package/kits/docs/evolcore/model.md +3 -0
- package/kits/docs/evolcore/msg.md +77 -10
- package/kits/docs/evolcore/pay.md +34 -0
- package/kits/docs/evolcore/provider.md +22 -1
- package/kits/docs/evolcore/quota.md +54 -0
- package/kits/docs/evolcore/role.md +3 -0
- package/kits/docs/evolcore/services.md +46 -18
- package/kits/docs/evolcore/stats.md +2 -0
- package/kits/docs/evolcore/thread-chain.md +2 -0
- package/kits/docs/evolcore/tool-authorization.md +10 -0
- package/kits/docs/evolcore/trigger.md +2 -0
- package/kits/rules/01-overview.md +11 -32
- package/kits/rules/02-navigation.md +7 -0
- package/kits/rules/06-channel.md +3 -3
- package/kits/schemas/_meta.json +38 -5
- package/kits/schemas/agent-config.schema.20.json +24 -0
- package/kits/schemas/agent-config.schema.21.json +974 -0
- package/kits/schemas/agent-config.schema.22.json +977 -0
- package/kits/schemas/agent-config.schema.23.json +958 -0
- package/kits/schemas/daemon.schema.10.json +373 -0
- package/kits/schemas/daemon.schema.9.json +12 -0
- package/kits/schemas/defaults.schema.7.json +472 -0
- package/kits/schemas/providers.schema.3.json +18 -2
- package/kits/schemas/relation-config.schema.13.json +289 -0
- package/kits/skills/.switches.json +17 -1
- package/kits/skills/ability/SKILL.md +229 -34
- package/kits/skills/ability/STRUCTURE.md +333 -0
- package/kits/skills/ability/references/cli.md +208 -0
- package/kits/skills/ability/references/development.md +107 -37
- package/kits/skills/ability/references/management.md +106 -46
- package/kits/skills/ability/references/runtime-protocol.md +65 -63
- package/kits/skills/agent-output-cards/SKILL.md +64 -0
- package/kits/skills/ec-group/SKILL.md +8 -6
- package/kits/skills/ec-group/TASK.md +186 -0
- package/kits/skills/ec-group/WORKLOG.md +180 -0
- package/kits/skills/ec-group-collaboration/SKILL.md +3 -3
- package/kits/skills/ec-pay/SKILL.md +101 -0
- package/kits/skills/ec-pay/references/pay-cli.md +110 -0
- package/kits/skills/ec-provider/SKILL.md +58 -9
- package/kits/skills/{ec-service-proxy → ec-proxy}/SKILL.md +8 -5
- package/kits/skills/ec-service-call/SKILL.md +135 -0
- package/kits/skills/ec-service-pack/SKILL.md +277 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/templates/memory-consolidation/notes.md +2 -2
- package/kits/templates/memory-consolidation/workflow.md +46 -0
- package/kits/templates/roles/visitor.json +1 -0
- package/kits/templates/system-fragments/channel.md +13 -4
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/directory-contacts.md +3 -4
- package/kits/templates/system-fragments/reply.md +1 -0
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +27 -128
- package/kits/templates/system-fragments/venue.md +27 -0
- package/package.json +4 -5
- package/scripts/agent-template/inspect.mjs +79 -29
- package/scripts/agent-template/overlay.mjs +20 -2
- package/scripts/agent-template/shared/common.mjs +24 -6
- package/scripts/agent-template/shared/team-schema.json +23 -5
- package/scripts/agent-template/shared/template-contract.mjs +107 -17
- package/scripts/agent-template/shared/template-package.mjs +254 -29
- package/scripts/agent-template/shared/template-runtime.mjs +145 -2
- package/scripts/agent-template/shared/template.mjs +67 -9
- package/scripts/agent-template/team-pack.mjs +132 -41
- package/scripts/agent-template/team-preview.mjs +249 -5
- package/kits/docs/aun/ABILITY_CALLING.md +0 -280
- package/kits/docs/evolcore/ability.md +0 -185
- package/kits/skills/ability/references/calling.md +0 -56
- package/kits/skills/ability/references/contract-checklist.md +0 -37
- package/kits/skills/ability/references/recovery.md +0 -27
- /package/dist/{core/capability/providers → agents/gemini}/gemini-capability-provider.js +0 -0
|
@@ -16,6 +16,27 @@
|
|
|
16
16
|
* 对端凭空建出一个叫 `main:…` 的话题。它只用于本端寻址、持久化与展示。
|
|
17
17
|
*/
|
|
18
18
|
export const MAIN_TOPIC_PREFIX = 'main:';
|
|
19
|
+
/** Decode relation/session selectors while retaining native channel ID case. */
|
|
20
|
+
export function normalizeThreadPeer(input) {
|
|
21
|
+
const raw = String(input ?? '').trim();
|
|
22
|
+
if (!raw)
|
|
23
|
+
return undefined;
|
|
24
|
+
const value = raw.includes('#') ? raw.split('#').at(-1) : raw;
|
|
25
|
+
try {
|
|
26
|
+
return decodeURIComponent(value).trim() || undefined;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return value || undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function sameThreadPeer(a, b, channelType = 'aun') {
|
|
33
|
+
const left = normalizeThreadPeer(a);
|
|
34
|
+
const right = normalizeThreadPeer(b);
|
|
35
|
+
return !!left && !!right && (channelType === 'aun' ? left.toLowerCase() === right.toLowerCase() : left === right);
|
|
36
|
+
}
|
|
37
|
+
export function isInternalThreadPeer(peer) {
|
|
38
|
+
return /^(bg:|trigger:|daemon:|memory:)/.test(peer);
|
|
39
|
+
}
|
|
19
40
|
// CLI 创建时间戳形式,客户端可创建 UUID 形式;原值参与索引与双端寻址,不改写大小写。
|
|
20
41
|
const TIMESTAMP_TOPIC_ID_RE = /^thread-[0-9]+-[0-9a-f]{4}-[0-9a-f]{4}$/;
|
|
21
42
|
const UUID_TOPIC_ID_RE = /^thread-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
@@ -36,10 +57,39 @@ function isTopicAidSegment(value) {
|
|
|
36
57
|
return false;
|
|
37
58
|
return labels.every(label => /^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$/.test(label));
|
|
38
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* 建话题时对端形态的**初步筛查**。
|
|
62
|
+
*
|
|
63
|
+
* 门槛刻意低于 `isValidAid`(三级以上):群 AID(`g-xxx.agentid.cn`)只有两级,
|
|
64
|
+
* 卡死会把合法的群话题挡掉。这里只排除结构上不可能是 AID 的输入——
|
|
65
|
+
* 空值、单级标签、带下划线/冒号/空格的段、以 `-` 起止的标签。
|
|
66
|
+
*
|
|
67
|
+
* 真正的身份确认交给名片缓存(`createThread` 里的 peerUnverified 标记),
|
|
68
|
+
* 不做网络校验:建话题本身不发送任何东西,离线场景必须能建。
|
|
69
|
+
*/
|
|
70
|
+
export function isTopicPeerAid(value) {
|
|
71
|
+
return typeof value === 'string' && isTopicAidSegment(normalizeTopicAid(value));
|
|
72
|
+
}
|
|
39
73
|
/** 统一输入形态:去空白与 `@` 前缀。不做域名展开、不改大小写。 */
|
|
40
74
|
export function normalizeTopicAid(value) {
|
|
41
75
|
return String(value ?? '').trim().replace(/^@/, '');
|
|
42
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* 话题对端是否就是本端自己。
|
|
79
|
+
*
|
|
80
|
+
* 话题是「本端 ↔ 对端」的两端结构,对端写成自己会得到残缺结构:会话元数据、
|
|
81
|
+
* 回复目标和角色解析全部指向本端,消息发得进去却没有人真正接收。
|
|
82
|
+
*
|
|
83
|
+
* 放在这里而不是 `thread-service`:创建侧与发送路由侧都要用,而发送路由是
|
|
84
|
+
* 不依赖 IO 的纯函数模块。比较按 AUN 的 AID 口径,大小写不敏感。
|
|
85
|
+
*/
|
|
86
|
+
export function isSelfTopicPeer(peer, selfAid) {
|
|
87
|
+
const normalizedPeer = normalizeTopicAid(typeof peer === 'string' ? peer : '');
|
|
88
|
+
const normalizedSelf = normalizeTopicAid(typeof selfAid === 'string' ? selfAid : '');
|
|
89
|
+
if (!normalizedPeer || !normalizedSelf)
|
|
90
|
+
return false;
|
|
91
|
+
return normalizedPeer.toLowerCase() === normalizedSelf.toLowerCase();
|
|
92
|
+
}
|
|
43
93
|
/**
|
|
44
94
|
* 由关系两端生成规范主话题 id。
|
|
45
95
|
*
|
|
@@ -79,9 +129,9 @@ export function mainTopicPeer(topicId, selfAid) {
|
|
|
79
129
|
if (!parsed)
|
|
80
130
|
return undefined;
|
|
81
131
|
const self = normalizeTopicAid(selfAid);
|
|
82
|
-
if (parsed.aidA
|
|
132
|
+
if (sameThreadPeer(parsed.aidA, self))
|
|
83
133
|
return parsed.aidB;
|
|
84
|
-
if (parsed.aidB
|
|
134
|
+
if (sameThreadPeer(parsed.aidB, self))
|
|
85
135
|
return parsed.aidA;
|
|
86
136
|
return undefined;
|
|
87
137
|
}
|
|
@@ -126,6 +176,21 @@ export function isMainSessionThreadId(value) {
|
|
|
126
176
|
export function isTopicThreadId(value) {
|
|
127
177
|
return typeof value === 'string' && value !== '' && !isMainSessionThreadId(value);
|
|
128
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Normalize a local thread identity for the specified relation. Explicit main IDs
|
|
181
|
+
* must name these two peers; topic IDs still need their caller's index checks.
|
|
182
|
+
* Main identities remain local and must never be emitted as wire thread_id.
|
|
183
|
+
*/
|
|
184
|
+
export function normalizeThreadIdForPeer(value, selfAid, peerId) {
|
|
185
|
+
if (isTopicThreadId(value))
|
|
186
|
+
return value;
|
|
187
|
+
if (!isMainSessionThreadId(value))
|
|
188
|
+
return undefined;
|
|
189
|
+
const main = safeFormatMainTopicId(selfAid, peerId);
|
|
190
|
+
if (typeof value === 'string' && isMainTopicId(value) && canonicalizeMainTopicId(value) !== main)
|
|
191
|
+
return undefined;
|
|
192
|
+
return main;
|
|
193
|
+
}
|
|
129
194
|
/** 别名:旧代码中广泛使用的 isSubTopicThreadId,语义与 isTopicThreadId 完全一致。 */
|
|
130
195
|
export const isSubTopicThreadId = isTopicThreadId;
|
|
131
196
|
/**
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { readTopicStatusLenient } from '../session/session-mapper.js';
|
|
2
|
+
import { isInternalThreadPeer, isTopicPeerAid, isTopicThreadId, normalizeThreadPeer } from './topic-id.js';
|
|
3
|
+
/** Shared index gate for both explicit topic operations and passive session creation. */
|
|
4
|
+
export function sanitizeIndexEntry(entry) {
|
|
5
|
+
const peer = normalizeThreadPeer(entry.peer);
|
|
6
|
+
const channelType = entry.channelType || 'aun';
|
|
7
|
+
if (!peer || isInternalThreadPeer(peer) || channelType === 'daemon')
|
|
8
|
+
return { ok: false, reason: 'internal or empty peer' };
|
|
9
|
+
if ((channelType === 'aun' && !isTopicPeerAid(peer)) || /[\x00-\x1f\x7f]/.test(peer)) {
|
|
10
|
+
return { ok: false, reason: `invalid ${channelType} peer ${peer}` };
|
|
11
|
+
}
|
|
12
|
+
if (!isTopicThreadId(entry.threadId))
|
|
13
|
+
return { ok: false, reason: `invalid threadId ${entry.threadId}` };
|
|
14
|
+
return { ok: true, entry: { ...entry, peer, channelType, topicStatus: readTopicStatusLenient(entry.topicStatus) } };
|
|
15
|
+
}
|
|
@@ -247,37 +247,40 @@ export function readOwnerDirectoryMembership(selfAid, aid, appOwned = false) {
|
|
|
247
247
|
return { category: 'unavailable' };
|
|
248
248
|
}
|
|
249
249
|
const effectiveAllowExternalContacts = resolveAllowExternalContacts(selfAid, snapshot);
|
|
250
|
+
// `blockedAids` 是快照级字段,与调用方是否 appOwned 无关:以前只在 appOwned 分支里
|
|
251
|
+
// 计算,导致团队校验(不传 appOwned)读到 blocked=undefined,被屏蔽的联系人仍能被
|
|
252
|
+
// 拉进团队。这里统一算出来,两个分支共用。
|
|
253
|
+
const blocked = snapshot.blockedAids?.includes(aid) ?? false;
|
|
250
254
|
if (appOwned) {
|
|
251
255
|
const entry = snapshot.entries.find(item => item.aid === aid);
|
|
252
|
-
const blocked = snapshot.blockedAids?.includes(aid) ?? false;
|
|
253
256
|
const scopeExcluded = entry?.agent_scope?.mode === 'selected' && !entry.agent_scope.agent_aids.includes(selfAid);
|
|
254
257
|
const internal = entry ? isInternalEntry(entry, ownerRefAid(snapshot, ownerAid)) : undefined;
|
|
255
258
|
return { category: entry ? (entry.type === 'agent' ? 'agent' : entry.type === 'human' ? 'human' : 'other') : 'not_found',
|
|
256
259
|
entry, blocked, scopeExcluded, internal, effectiveAllowExternalContacts };
|
|
257
260
|
}
|
|
258
261
|
if (aid === ownerAid || snapshot.owner?.aid === aid) {
|
|
259
|
-
return { category: 'owner', internal: true, effectiveAllowExternalContacts };
|
|
262
|
+
return { category: 'owner', internal: true, blocked, effectiveAllowExternalContacts };
|
|
260
263
|
}
|
|
261
264
|
if (snapshot.personalAssistant?.aid === aid) {
|
|
262
|
-
return { category: 'assistant', internal: true, effectiveAllowExternalContacts };
|
|
265
|
+
return { category: 'assistant', internal: true, blocked, effectiveAllowExternalContacts };
|
|
263
266
|
}
|
|
264
267
|
if (aid === selfAid)
|
|
265
|
-
return { category: 'agent', internal: true, effectiveAllowExternalContacts };
|
|
268
|
+
return { category: 'agent', internal: true, blocked, effectiveAllowExternalContacts };
|
|
266
269
|
const entry = snapshot.entries.find(item => item.aid === aid);
|
|
267
270
|
if (!entry)
|
|
268
|
-
return { category: 'not_found', effectiveAllowExternalContacts };
|
|
271
|
+
return { category: 'not_found', blocked, effectiveAllowExternalContacts };
|
|
269
272
|
// 内外判据只有一个来源:Owner 身份块里的 aid。
|
|
270
273
|
const ownerRef = ownerRefAid(snapshot, ownerAid);
|
|
271
274
|
const internal = isInternalEntry(entry, ownerRef);
|
|
272
275
|
const type = entry.type;
|
|
273
276
|
if (type === 'agent')
|
|
274
|
-
return { category: 'agent', internal, entry, effectiveAllowExternalContacts };
|
|
277
|
+
return { category: 'agent', internal, entry, blocked, effectiveAllowExternalContacts };
|
|
275
278
|
if (type === 'human')
|
|
276
|
-
return { category: 'human', internal, entry, effectiveAllowExternalContacts };
|
|
279
|
+
return { category: 'human', internal, entry, blocked, effectiveAllowExternalContacts };
|
|
277
280
|
// 协议外的 type(`ai`、`codeagent`、缺失…)落 `other`:它既不是会发消息的
|
|
278
281
|
// agent/human,也不是协议允许的 service/device/org/custom/host,用途未知。
|
|
279
282
|
// 准入仍按内外分档(与宿主类型一致),只是不假装知道它是什么。
|
|
280
|
-
return { category: 'other', internal, entry, effectiveAllowExternalContacts };
|
|
283
|
+
return { category: 'other', internal, entry, blocked, effectiveAllowExternalContacts };
|
|
281
284
|
}
|
|
282
285
|
catch (error) {
|
|
283
286
|
const code = error && typeof error === 'object' && 'code' in error
|
|
@@ -1018,6 +1018,7 @@ export class OwnerDirectoryCache {
|
|
|
1018
1018
|
for (const scope of OWNER_DIRECTORY_SCOPES)
|
|
1019
1019
|
this._writeSyncStamp(scope);
|
|
1020
1020
|
this.refreshMarkdown();
|
|
1021
|
+
this.notifySnapshotApplied();
|
|
1021
1022
|
return true;
|
|
1022
1023
|
}
|
|
1023
1024
|
const fetched = this._readSharedCache();
|
|
@@ -1117,6 +1118,23 @@ export class OwnerDirectoryCache {
|
|
|
1117
1118
|
*
|
|
1118
1119
|
* 完整性由阶段一保证(`_assertComplete`);这里只跳过"拉取之后权限被撤"的范围。
|
|
1119
1120
|
*/
|
|
1121
|
+
notifySnapshotApplied() {
|
|
1122
|
+
if (!this.canApply())
|
|
1123
|
+
return;
|
|
1124
|
+
try {
|
|
1125
|
+
this.options.onSnapshotApplied?.();
|
|
1126
|
+
}
|
|
1127
|
+
catch (error) {
|
|
1128
|
+
logger.warn('[OwnerDirectoryCache] onSnapshotApplied failed:', error);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
/** Used only while durable inbound messages await approval. Honors Owner-wide backoff. */
|
|
1132
|
+
async reconcilePendingContacts() {
|
|
1133
|
+
if (!this.readPendingUpdate())
|
|
1134
|
+
await this.handleOwnerChangedEvent(this.options.ownerAid);
|
|
1135
|
+
await this.processPendingIfNeeded();
|
|
1136
|
+
await this.applyFromSharedCache();
|
|
1137
|
+
}
|
|
1120
1138
|
async _applyAll(fetched) {
|
|
1121
1139
|
const apply = async () => {
|
|
1122
1140
|
if (!this.canApply())
|
|
@@ -1140,6 +1158,7 @@ export class OwnerDirectoryCache {
|
|
|
1140
1158
|
const epoch = coordinatorFor(this.options.ownerAid).epoch;
|
|
1141
1159
|
if (epoch)
|
|
1142
1160
|
this.appliedGeneration = epoch.generation;
|
|
1161
|
+
this.notifySnapshotApplied();
|
|
1143
1162
|
}
|
|
1144
1163
|
// ── 共享缓存($EVOLCORE_HOME/data/owner-directory/<ownerAid>/) ────────────
|
|
1145
1164
|
_sharedCacheDir() {
|
|
@@ -170,7 +170,7 @@ export function renderOwnerDirectoryMarkdown(input) {
|
|
|
170
170
|
'- `ec directory refresh`:立即同步一次,然后重算本文件。怀疑名录过期时用。',
|
|
171
171
|
'- `ec directory blocked`:查被拉黑的主体。名录里不渲染黑名单,要判断某人能不能联系就查这个。',
|
|
172
172
|
'- `ec directory request <AID> [--note <说明>]`:给一个**还不在名录里**的人发加好友申请。',
|
|
173
|
-
'
|
|
173
|
+
' 向目标发送显式好友邀请,仅表示已提交;普通消息出站无需先入录,入站仍按当前许可判断。',
|
|
174
174
|
'- 需要名片原文时:`ec aid agentmd get <AID>`。',
|
|
175
175
|
`- **备注不走命令**:直接写 \`${remarksExamplePath(input)}\`,frontmatter 用 \`aid\`/\`remark\`/\`updated_at\`,正文写「什么事找他」,写完 \`ec directory refresh\`。文件名须与 \`aid\` 一致,否则整条作废。`,
|
|
176
176
|
];
|
|
@@ -13,8 +13,8 @@ import { ConfigTarget, read } from '../config/config-manager.js';
|
|
|
13
13
|
/**
|
|
14
14
|
* 外部联系开关的最终值:**显式配置 > 个人助理判据 > false**。
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* 个人助理默认接收外部联系人的入站;其余 agent 默认关闭,
|
|
17
|
+
* 可由 Owner 打开。普通出站不使用此开关。
|
|
18
18
|
*/
|
|
19
19
|
export function resolveAllowExternalContacts(selfAid, snapshot,
|
|
20
20
|
/** 显式配置;缺省时从配置文件读。测试用来固定优先级。 */
|
|
@@ -100,32 +100,7 @@ export function resolveOwnerDirectoryRenderPolicy(selfAid, snapshot) {
|
|
|
100
100
|
allowedAids: policy.allowedAids ?? [],
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
-
/**
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
* 发出去却被拒"。
|
|
107
|
-
*
|
|
108
|
-
* 判据顺序照搬准入:总开关 > 名单(白名单命中即通)> 内部档 / 外部档。
|
|
109
|
-
* 黑名单**参与**这里:它是 Owner 显式指定的拒绝,总开关也翻不动它。
|
|
110
|
-
*/
|
|
111
|
-
export function resolveEntryContactable(selfAid, snapshot, entry) {
|
|
112
|
-
let policy;
|
|
113
|
-
try {
|
|
114
|
-
policy = readAccessPolicy(selfAid);
|
|
115
|
-
}
|
|
116
|
-
catch {
|
|
117
|
-
// 配置读不出不等于"谁都不能联系":外部档仍按"显式配置 > 个人助理判据"回落,
|
|
118
|
-
// 与注入侧口径保持一致(那份快照在同样的失败下也只关掉外部与总开关)。
|
|
119
|
-
return entry.internal === true || resolveAllowExternalContacts(selfAid, snapshot) === true;
|
|
120
|
-
}
|
|
121
|
-
if (policy.deniedAids?.includes(entry.aid))
|
|
122
|
-
return false;
|
|
123
|
-
if (entry.internal === true)
|
|
124
|
-
return policy.allowInternalContacts !== false;
|
|
125
|
-
if (policy.allowedAids?.includes(entry.aid))
|
|
126
|
-
return true;
|
|
127
|
-
if (policy.allowAllContacts === true)
|
|
128
|
-
return true;
|
|
129
|
-
// 同 `resolveOwnerDirectoryRenderPolicy`:传 undefined 让函数自己去读显式配置。
|
|
130
|
-
return resolveAllowExternalContacts(selfAid, snapshot) === true;
|
|
103
|
+
/** Ordinary outbound messaging is independent of inbound contact admission. */
|
|
104
|
+
export function resolveEntryContactable(_selfAid, _snapshot, _entry) {
|
|
105
|
+
return true;
|
|
131
106
|
}
|
|
@@ -62,12 +62,15 @@ export async function executeDirectoryRequestCommand(command, send) {
|
|
|
62
62
|
};
|
|
63
63
|
try {
|
|
64
64
|
const result = await send({ from: command.selfAid, to: command.targetAid, payload, encrypt: true });
|
|
65
|
-
if (!result.ok || !result.message_id) {
|
|
65
|
+
if (!result.ok || (!result.message_id && result.status !== 'queued')) {
|
|
66
66
|
return { ok: false, code: String(result.code ?? 'FRIEND_INVITE_FAILED'),
|
|
67
67
|
error: `向目标 ${command.targetAid} 发送加好友申请失败:${result.error ?? '未获得消息发送回执'}` };
|
|
68
68
|
}
|
|
69
69
|
return { ok: true, action: 'request', selfAid: command.selfAid, targetAid: command.targetAid,
|
|
70
|
-
status: '
|
|
70
|
+
status: result.status === 'queued' ? 'queued' : 'sent',
|
|
71
|
+
...(result.message_id ? { message_id: result.message_id } : {}),
|
|
72
|
+
...(result.outbox_id ? { outbox_id: result.outbox_id } : {}),
|
|
73
|
+
};
|
|
71
74
|
}
|
|
72
75
|
catch (error) {
|
|
73
76
|
return { ok: false, code: 'FRIEND_INVITE_FAILED',
|
package/dist/eck/kit-renderer.js
CHANGED
|
@@ -232,7 +232,7 @@ const PARAM_DESCRIPTIONS = {
|
|
|
232
232
|
CURRENT_PROJECT: '当前项目完整路径',
|
|
233
233
|
AGENT_DIR: '当前 agent 数据根目录',
|
|
234
234
|
PERSONAL_DIR: '当前 agent 个人数据目录',
|
|
235
|
-
RELATIONS_DIR: '当前 agent
|
|
235
|
+
RELATIONS_DIR: '当前 agent 关系数据目录(历史消息里的 $RELATIONS_DIR/... 前缀即此绝对路径)',
|
|
236
236
|
VENUES_DIR: '当前 agent 环境数据目录',
|
|
237
237
|
selfAid: '当前 agent 的 AID',
|
|
238
238
|
selfName: '当前 agent 的显示名',
|
|
@@ -248,7 +248,7 @@ const PARAM_DESCRIPTIONS = {
|
|
|
248
248
|
personalAssistantName: '个人助理的显示名(名录快照)',
|
|
249
249
|
isPersonalAssistant: '当前 agent 是否就是 Owner 的个人助理(即时比较,读不到身份时为 false)',
|
|
250
250
|
isOwner: '当前 agent 是否就是协议确认的 Owner(即时比较;Owner 通常是人,一般恒为 false)',
|
|
251
|
-
contactsState: '
|
|
251
|
+
contactsState: '出站可发送与入站须准入的说明',
|
|
252
252
|
peerId: '对端在该渠道的原生 ID',
|
|
253
253
|
peerKey: '对端跨渠道唯一标识(channel#urlEncode(peerId))',
|
|
254
254
|
peerName: '对端显示名',
|
|
@@ -265,6 +265,7 @@ const PARAM_DESCRIPTIONS = {
|
|
|
265
265
|
channel: '渠道类型(aun/feishu/wechat/dingtalk/qqbot/wecom)',
|
|
266
266
|
venueUid: '场所唯一标识(预留)',
|
|
267
267
|
mentionMode: '群 @ 处理模式(mention-only=被@才响应 / disabled=所有消息都响应 / auto=按上下文判断)',
|
|
268
|
+
privateMentionMode: '私聊 @ 处理策略(mention-only=被@才响应 / disabled=所有消息都响应);Agent 级、Owner 专属',
|
|
268
269
|
groupHistoryAvailable: '本地群历史读取能力是否可用',
|
|
269
270
|
clientType: '客户端类型(desktop/web/mobile)',
|
|
270
271
|
permissionMode: '权限模式(readonly/auto/request/bypass;旧值会安全迁移)',
|
|
@@ -16,7 +16,17 @@ const MESSAGE_MANIFEST_FILE = 'eck_message_manifest.json';
|
|
|
16
16
|
// ── time formatting (per IANA timezone) ──
|
|
17
17
|
function timeParts(epochMs, timeZone, opts) {
|
|
18
18
|
const d = new Date(epochMs);
|
|
19
|
-
|
|
19
|
+
// 时区可能来自客户端上报(sender_ctx.timezone)或 agent 配置,非法 IANA 名会让
|
|
20
|
+
// Intl 抛 RangeError——那会整个消息渲染失败、消息直接丢给模型。这里退化为本机时区,
|
|
21
|
+
// 宁可时间基准退回本地,也不能让一条消息因为时区串写错而整条渲染不出来。
|
|
22
|
+
let p;
|
|
23
|
+
try {
|
|
24
|
+
p = new Intl.DateTimeFormat('en-US', { ...(timeZone ? { timeZone } : {}), ...opts }).formatToParts(d);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
logger.debug(`[MessageRenderer] invalid timezone ignored: ${String(timeZone)}`);
|
|
28
|
+
p = new Intl.DateTimeFormat('en-US', opts).formatToParts(d);
|
|
29
|
+
}
|
|
20
30
|
const out = {};
|
|
21
31
|
for (const part of p)
|
|
22
32
|
out[part.type] = part.value;
|
|
@@ -70,8 +80,14 @@ function speakerRelationOf(item, sessionVars) {
|
|
|
70
80
|
return String(item.speakerRelation
|
|
71
81
|
?? (String(sessionVars.chatType ?? '') === 'group' ? 'visitor' : (item.peerRole ?? sessionVars.peerRole ?? 'visitor')));
|
|
72
82
|
}
|
|
73
|
-
/**
|
|
74
|
-
|
|
83
|
+
/**
|
|
84
|
+
* `ctx: scene=… · activity=… · location=地址(纬度,经度 ±精度, 采集于 时刻)`;无 sender_ctx 返回空串。
|
|
85
|
+
*
|
|
86
|
+
* 精度与采集时刻缺省时**整段不写**——缺省的含义是「发件人没上报」,不是「精确」也
|
|
87
|
+
* 不是「就是此刻」。坐标恒定保留 6 位小数(协议原值的展示形态),精度另以 `±Nm` 标注,
|
|
88
|
+
* 两者语义分离:小数位只表示上报精度,不表示真实定位精度。
|
|
89
|
+
*/
|
|
90
|
+
function formatSenderCtx(ctx, timeZone) {
|
|
75
91
|
if (!ctx)
|
|
76
92
|
return '';
|
|
77
93
|
const parts = [];
|
|
@@ -83,7 +99,14 @@ function formatSenderCtx(ctx) {
|
|
|
83
99
|
if (loc && Number.isFinite(loc.latitude_e6) && Number.isFinite(loc.longitude_e6)) {
|
|
84
100
|
const lat = (loc.latitude_e6 / 1e6).toFixed(6);
|
|
85
101
|
const lon = (loc.longitude_e6 / 1e6).toFixed(6);
|
|
86
|
-
|
|
102
|
+
let coord = `${lat},${lon}`;
|
|
103
|
+
if (Number.isFinite(loc.accuracy_m) && loc.accuracy_m > 0) {
|
|
104
|
+
coord += ` ±${Math.round(loc.accuracy_m)}m`;
|
|
105
|
+
}
|
|
106
|
+
if (Number.isFinite(loc.timestamp_ms) && loc.timestamp_ms > 0) {
|
|
107
|
+
coord += `, 采集于 ${formatLocalTime(loc.timestamp_ms, timeZone)}`;
|
|
108
|
+
}
|
|
109
|
+
parts.push(`location=${loc.address ? `${loc.address}(${coord})` : coord}`);
|
|
87
110
|
}
|
|
88
111
|
return parts.length > 0 ? `ctx: ${parts.join(' · ')}` : '';
|
|
89
112
|
}
|
|
@@ -236,7 +259,7 @@ function renderOneItem(item, sessionVars, sessionCache, contentSentinel, compact
|
|
|
236
259
|
speakerRelation: speakerRelationOf(item, sessionVars),
|
|
237
260
|
// `mid:` 是恒出现字段:缺 messageId(非 AUN 渠道)时保留占位,不能让整段消失。
|
|
238
261
|
messageId: item.messageId ?? '-',
|
|
239
|
-
senderCtxLine: formatSenderCtx(item.senderCtx),
|
|
262
|
+
senderCtxLine: formatSenderCtx(item.senderCtx, tz),
|
|
240
263
|
batchItem: compact || undefined,
|
|
241
264
|
// 跨话题委托提醒:原消息与来源会话,供回查定位。
|
|
242
265
|
threadContextMessageId: item.threadContext?.messageId,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import { isSupportedBaseagent } from '../agents/baseagent.js';
|
|
1
2
|
import crypto from 'node:crypto';
|
|
2
3
|
import { assertProjectPathConfig } from '../utils/project-path.js';
|
|
3
4
|
import { ConfigTarget, mutateConfig, read, validateConfig, } from '../config/config-manager.js';
|
|
4
5
|
import { getLogStreamStates, LOG_LEVELS } from '../utils/logger.js';
|
|
5
6
|
import { resolveDaemonServices } from '../config/daemon-services.js';
|
|
6
|
-
const BASEAGENTS = ['claude', 'codex', 'gemini', 'ecagent'];
|
|
7
|
-
const BASEAGENT_SET = new Set(BASEAGENTS);
|
|
8
7
|
const EFFORTS = new Set(['low', 'medium', 'high', 'xhigh', 'max']);
|
|
9
8
|
const PROHIBITED_PATH_SEGMENTS = new Set(['__proto__', 'prototype', 'constructor']);
|
|
10
9
|
const HEADER_NAME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/u;
|
|
@@ -200,10 +199,7 @@ export function readBasicSettings() {
|
|
|
200
199
|
const rawDefaults = readSettingsFile('defaults');
|
|
201
200
|
const daemon = rawDaemon ? clone(rawDaemon) : {};
|
|
202
201
|
daemon.services = resolveDaemonServices(daemon.services);
|
|
203
|
-
|
|
204
|
-
delete daemon.owner;
|
|
205
|
-
delete daemon.owners;
|
|
206
|
-
}
|
|
202
|
+
// The daemon config no longer carries an Owner field; nothing to redact here.
|
|
207
203
|
return {
|
|
208
204
|
ok: true,
|
|
209
205
|
daemon,
|
|
@@ -245,9 +241,9 @@ function isAllowedPath(file, fieldPath) {
|
|
|
245
241
|
return true;
|
|
246
242
|
const block = baseagentBlockPath(fieldPath);
|
|
247
243
|
if (block)
|
|
248
|
-
return
|
|
244
|
+
return isSupportedBaseagent(block);
|
|
249
245
|
const parsed = baseagentPath(fieldPath);
|
|
250
|
-
return !!parsed &&
|
|
246
|
+
return !!parsed && isSupportedBaseagent(parsed.baseagent) && (BASEAGENT_FIELDS[parsed.baseagent] ?? new Set(['model', 'provider', 'effort', 'fallback'])).has(parsed.field);
|
|
251
247
|
}
|
|
252
248
|
function assertString(value, fieldPath, options = {}) {
|
|
253
249
|
if (typeof value !== 'string')
|
|
@@ -495,7 +491,7 @@ function validateDefaultsValue(fieldPath, value) {
|
|
|
495
491
|
return;
|
|
496
492
|
}
|
|
497
493
|
if (fieldPath === 'active_baseagent') {
|
|
498
|
-
if (!
|
|
494
|
+
if (!isSupportedBaseagent(String(value)))
|
|
499
495
|
throw makeError(`${fieldPath} is invalid`, 'INVALID_SETTINGS_VALUE');
|
|
500
496
|
return;
|
|
501
497
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isProviderModelPattern, providerModelLiteralId, providerModelEnabled, readProvidersFile, resolveProviderService } from '../config/providers.js';
|
|
2
|
-
import { resolveProviderId } from '../config/providers-config.js';
|
|
2
|
+
import { providerApiKeyEntries, resolveProviderId } from '../config/providers-config.js';
|
|
3
3
|
import { createProvider, importOrMergeBaseagentProvider, parseProviderImport, previewProviderImport, previewProviderValue, readProviderForExport, readProvidersSnapshot, resolveProviderDraftService, saveProviderChanges, updateProvider, prepareProviderTemplate, previewProviderTemplate, } from '../config/providers-management.js';
|
|
4
4
|
import { readProviderTemplates, providerTemplateDetail } from '../config/provider-templates.js';
|
|
5
5
|
import { listBaseagentImportSources, providerFromBaseagent } from '../config/providers-import.js';
|
|
@@ -176,7 +176,9 @@ export async function handleProvidersService(input) {
|
|
|
176
176
|
const provider = registry.providers[resolveProviderId(providerId, registry)];
|
|
177
177
|
if (!provider)
|
|
178
178
|
return response(404, { success: false, error: 'Provider not found' });
|
|
179
|
-
|
|
179
|
+
// apiKey stays the primary for existing clients; apiKeys exposes the whole pool.
|
|
180
|
+
const apiKeys = providerApiKeyEntries(provider.common.apiKey);
|
|
181
|
+
return response(200, { success: true, data: { apiKey: apiKeys[0] || '', apiKeys } });
|
|
180
182
|
}
|
|
181
183
|
if (input.method === 'GET' && parts[1] === 'models' && parts.length === 2) {
|
|
182
184
|
const serviceType = query.serviceType || '';
|
|
@@ -13,6 +13,7 @@ import { sanitizeMenuLogValue } from '../../core/command/menu-protocol.js';
|
|
|
13
13
|
import { stopEcwebProcess } from './lifecycle.js';
|
|
14
14
|
import { sanitizeServiceEnvironment } from '../../core/permission/shell-environment.js';
|
|
15
15
|
const INSTANCE_FILE_RE = /^(?:ecweb|watch-web)-\d+\.json$/;
|
|
16
|
+
const OCCUPIED_PORT_DISCOVERY_MS = 3000;
|
|
16
17
|
function sleep(ms) {
|
|
17
18
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
18
19
|
}
|
|
@@ -226,7 +227,10 @@ export function createEcwebSupervisor(options) {
|
|
|
226
227
|
};
|
|
227
228
|
const waitForHealthyInstance = async (timeoutMs) => {
|
|
228
229
|
const deadline = Date.now() + timeoutMs;
|
|
230
|
+
const port = desiredPort;
|
|
229
231
|
do {
|
|
232
|
+
if (stopping || !desiredEnabled || runtimeMode !== 'managed' || desiredPort !== port)
|
|
233
|
+
return null;
|
|
230
234
|
const found = await findHealthyInstance();
|
|
231
235
|
if (found)
|
|
232
236
|
return found;
|
|
@@ -336,16 +340,40 @@ export function createEcwebSupervisor(options) {
|
|
|
336
340
|
scheduleRecovery();
|
|
337
341
|
return;
|
|
338
342
|
}
|
|
339
|
-
const
|
|
340
|
-
|
|
343
|
+
const port = desiredPort;
|
|
344
|
+
let occupiedPids = await platform.findProcessByPortAsync(port);
|
|
345
|
+
if (stopping || !desiredEnabled || runtimeMode !== 'managed' || desiredPort !== port)
|
|
341
346
|
return;
|
|
342
347
|
if (occupiedPids.length > 0) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
//
|
|
346
|
-
//
|
|
347
|
-
|
|
348
|
-
|
|
348
|
+
// A CLI-started instance can bind before publishing its record or
|
|
349
|
+
// becoming healthy. Give discovery a bounded window before treating
|
|
350
|
+
// that normal startup overlap as a failure. Only a verified instance
|
|
351
|
+
// from this HOME can be adopted; unknown port owners stay untouched.
|
|
352
|
+
const existing = await waitForHealthyInstance(OCCUPIED_PORT_DISCOVERY_MS);
|
|
353
|
+
if (stopping || !desiredEnabled || runtimeMode !== 'managed' || desiredPort !== port)
|
|
354
|
+
return;
|
|
355
|
+
if (existing && await setActiveFromEntry(existing, false)) {
|
|
356
|
+
if (stopping || !desiredEnabled || runtimeMode !== 'managed' || desiredPort !== port)
|
|
357
|
+
return;
|
|
358
|
+
healthy = true;
|
|
359
|
+
checkedAt = Date.now();
|
|
360
|
+
launchRequested = false;
|
|
361
|
+
cancelRecovery();
|
|
362
|
+
failureCount = 0;
|
|
363
|
+
hasBeenReady = true;
|
|
364
|
+
settleInitialHealth?.('ok');
|
|
365
|
+
options.logger.info(`✓ ECWeb supervisor 接管现有实例 (PID: ${existing.record.pid}, 端口: ${existing.record.port})`);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
occupiedPids = await platform.findProcessByPortAsync(port);
|
|
369
|
+
if (stopping || !desiredEnabled || runtimeMode !== 'managed' || desiredPort !== port)
|
|
370
|
+
return;
|
|
371
|
+
if (occupiedPids.length > 0) {
|
|
372
|
+
options.logger.error(`ECWeb 本次启动失败:端口 ${port} 被占用 (PID: ${occupiedPids.join(', ')})`);
|
|
373
|
+
failureCount = failureThreshold;
|
|
374
|
+
scheduleRecovery();
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
349
377
|
}
|
|
350
378
|
fs.mkdirSync(resolvePaths().logs, { recursive: true });
|
|
351
379
|
fs.appendFileSync(logFile, `\n# daemon supervisor start ${new Date().toISOString()}\n`);
|
|
@@ -10,9 +10,9 @@ import { logger } from '../utils/logger.js';
|
|
|
10
10
|
import { EventCenterError } from './types.js';
|
|
11
11
|
import { AID_PATTERN, validateCenterConfig } from './validation.js';
|
|
12
12
|
export const EVENTS_CONFIG_JSON = 'events-config.json';
|
|
13
|
-
function defaultCenterConfig() {
|
|
13
|
+
function defaultCenterConfig(enabled = false) {
|
|
14
14
|
return {
|
|
15
|
-
enabled
|
|
15
|
+
enabled, authMode: 'allowlist',
|
|
16
16
|
admission: { coupling: 'on', rematerializeMs: 300_000 },
|
|
17
17
|
rules: {}, rateLimit: { perMinute: 60, perHour: 600 },
|
|
18
18
|
};
|
|
@@ -22,8 +22,12 @@ function readCenterConfig(filePath, migrateLegacyRules) {
|
|
|
22
22
|
try {
|
|
23
23
|
rawText = fs.readFileSync(filePath, 'utf8');
|
|
24
24
|
}
|
|
25
|
-
catch {
|
|
26
|
-
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error.code === 'ENOENT') {
|
|
27
|
+
return { config: defaultCenterConfig(true), exists: false, errors: [] };
|
|
28
|
+
}
|
|
29
|
+
return { config: defaultCenterConfig(), exists: true,
|
|
30
|
+
errors: [`Cannot read ${EVENTS_CONFIG_JSON}: ${error instanceof Error ? error.message : String(error)}`] };
|
|
27
31
|
}
|
|
28
32
|
let raw;
|
|
29
33
|
try {
|
|
@@ -54,7 +58,7 @@ function readCenterConfig(filePath, migrateLegacyRules) {
|
|
|
54
58
|
}
|
|
55
59
|
return { config: validated.value, exists: true, errors: [] };
|
|
56
60
|
}
|
|
57
|
-
/**
|
|
61
|
+
/** 缺少配置时启用默认通知;显式关闭、非法和不可读配置保持关闭。 */
|
|
58
62
|
export function loadCenterConfig(eventsDir) {
|
|
59
63
|
migrateLegacyFileName(eventsDir, 'center.json', EVENTS_CONFIG_JSON, 'events config');
|
|
60
64
|
return readCenterConfig(path.join(eventsDir, EVENTS_CONFIG_JSON), true);
|
|
@@ -17,13 +17,18 @@ function resolveEntryBus(resolutions, packId, entry) {
|
|
|
17
17
|
export class EventDispatcher {
|
|
18
18
|
scriptRunner;
|
|
19
19
|
limits;
|
|
20
|
+
canDispatch;
|
|
20
21
|
queues = new Map();
|
|
21
22
|
running = 0;
|
|
22
23
|
closed = false;
|
|
23
24
|
idleResolvers = [];
|
|
24
|
-
constructor(scriptRunner, limits = DEFAULT_DISPATCHER_LIMITS) {
|
|
25
|
+
constructor(scriptRunner, limits = DEFAULT_DISPATCHER_LIMITS, canDispatch = () => true) {
|
|
25
26
|
this.scriptRunner = scriptRunner;
|
|
26
27
|
this.limits = limits;
|
|
28
|
+
this.canDispatch = canDispatch;
|
|
29
|
+
}
|
|
30
|
+
isBusy() {
|
|
31
|
+
return this.running > 0 || !this.isEmpty();
|
|
27
32
|
}
|
|
28
33
|
setLimits(limits) {
|
|
29
34
|
this.limits = { ...this.limits, ...limits };
|
|
@@ -40,6 +45,10 @@ export class EventDispatcher {
|
|
|
40
45
|
const log = EventLog.forPack(pack);
|
|
41
46
|
// 写前日志:received 一定先落盘。
|
|
42
47
|
log.writeReceived(event);
|
|
48
|
+
if (!this.canDispatch()) {
|
|
49
|
+
log.writeDropped(event, 'agent_mutation_paused');
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
43
52
|
if (entry.filter && !this.matches(entry.filter, event)) {
|
|
44
53
|
log.writeFiltered(event, 'filter_mismatch');
|
|
45
54
|
continue;
|
|
@@ -13,6 +13,7 @@ import { installPack, listPackDirs, removePack, setPackEnabled } from '../core/p
|
|
|
13
13
|
import { CenterConfigStore } from './center-config.js';
|
|
14
14
|
import { agentEventsDir } from '../paths.js';
|
|
15
15
|
import { authorizePackTarget, packOperation } from '../core/pack-auth.js';
|
|
16
|
+
import { OUTPUT_CARDS_EVENT } from '../outputs/protocol.js';
|
|
16
17
|
const HELP = `ec events — 事件中心运维
|
|
17
18
|
|
|
18
19
|
用法:
|
|
@@ -121,6 +122,9 @@ export function parseEventsArgv(argv) {
|
|
|
121
122
|
parsed.command = `rules:${positional[0] ?? ''}`;
|
|
122
123
|
parsed.event = parsed.event ?? positional[1];
|
|
123
124
|
}
|
|
125
|
+
else if (command === 'native-publish') {
|
|
126
|
+
parsed.nativeEvent = positional[0];
|
|
127
|
+
}
|
|
124
128
|
return parsed;
|
|
125
129
|
}
|
|
126
130
|
function resolveAid(deps, parsed, opts = {}) {
|
|
@@ -200,6 +204,21 @@ async function execute(deps, parsed) {
|
|
|
200
204
|
});
|
|
201
205
|
if (!auth.allowed)
|
|
202
206
|
return { ok: false, code: auth.code, error: auth.error };
|
|
207
|
+
if (command === 'native-publish') {
|
|
208
|
+
const data = parsed.data;
|
|
209
|
+
if (parsed.caller?.kind !== 'managed' || parsed.caller.selfAid !== aid
|
|
210
|
+
|| parsed.caller.peerRole !== 'owner'
|
|
211
|
+
|| parsed.nativeEvent !== OUTPUT_CARDS_EVENT || !data || typeof data !== 'object' || Array.isArray(data)
|
|
212
|
+
|| data.sourceAid !== aid || typeof data.revision !== 'string'
|
|
213
|
+
|| typeof data.cursor !== 'string') {
|
|
214
|
+
return { ok: false, code: 'NOT_ALLOWED', error: 'Native output-card notifications may only be published for the current Agent' };
|
|
215
|
+
}
|
|
216
|
+
const published = await deps.registry.publishAgentEvent(aid, OUTPUT_CARDS_EVENT, data);
|
|
217
|
+
if (!published) {
|
|
218
|
+
return { ok: false, code: 'EVENT_CENTER_NOT_RUNNING', error: `output-card notifications are unavailable for ${aid}` };
|
|
219
|
+
}
|
|
220
|
+
return { ok: true, result: { aid, event: OUTPUT_CARDS_EVENT } };
|
|
221
|
+
}
|
|
203
222
|
if (command === 'reload') {
|
|
204
223
|
await deps.registry.reload(aid);
|
|
205
224
|
const unit = deps.registry.get(aid);
|