evolcore 0.0.47 → 0.0.48
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 +56 -1
- package/bin/ec-build.mjs +86 -0
- package/dist/agent-template/jobs.js +12 -4
- package/dist/agent-template/runtime.js +139 -39
- package/dist/agent-template/service.js +66 -13
- package/dist/agents/baseagent.js +60 -20
- package/dist/agents/claude-runner.js +34 -17
- package/dist/agents/codex-runner.js +31 -16
- package/dist/agents/ecagent-runner.js +7 -4
- package/dist/agents/gemini-runner.js +5 -2
- package/dist/agents/runner-types.js +5 -21
- package/dist/aun/aid/agentmd.js +5 -1
- package/dist/aun/service-proxy.js +4 -2
- package/dist/build-identity.json +1 -0
- package/dist/channels/aun.js +81 -24
- package/dist/channels/daemon.js +9 -25
- package/dist/cli/aun-commands.js +86 -51
- package/dist/cli/code-stats.js +19 -8
- package/dist/cli/command-log.js +1 -1
- package/dist/cli/daemon-commands.js +44 -43
- package/dist/cli/directory.js +7 -1
- package/dist/cli/ecmsg-gateway.js +5 -2
- package/dist/cli/index.js +2 -8
- package/dist/cli/init-channel.js +4 -6
- package/dist/cli/init.js +72 -50
- package/dist/cli/invoke-command.js +1 -1
- package/dist/cli/provider-command.js +74 -13
- package/dist/cli/role.js +61 -17
- package/dist/cli/stats.js +3 -3
- package/dist/cli/thread-command.js +16 -51
- package/dist/config/boot-log.js +3 -9
- package/dist/config/builtin-roles.js +5 -7
- package/dist/config/config-manager.js +2 -6
- package/dist/config/daemon-services.js +30 -3
- package/dist/config/gateway-config.js +2 -2
- package/dist/config/invoke-ipc-service.js +6 -4
- package/dist/config/peer-bind-code.js +3 -4
- package/dist/config/peer-book-store.js +62 -229
- package/dist/config/peer-book.js +26 -27
- package/dist/config/peer-role-resolver.js +16 -1
- package/dist/config/provider-identity-migration.js +4 -1
- package/dist/config/provider-ipc-service.js +56 -11
- package/dist/config/provider-menu-request.js +24 -5
- package/dist/config/provider-templates.js +127 -0
- package/dist/config/providers-config.js +59 -8
- package/dist/config/providers-management.js +467 -49
- package/dist/config/role-command-service.js +248 -1
- package/dist/config/schema-migration.js +105 -4
- package/dist/core/agent-application-service.js +6 -1
- package/dist/core/agent-runtime.js +4 -0
- package/dist/core/auth/agent-delegation.js +2 -1
- package/dist/core/auth/auth-gateway.js +2 -1
- package/dist/core/auth/delegation-authorization.js +3 -0
- package/dist/core/auth/operation-authorizer.js +25 -0
- package/dist/core/auth/operation-catalog.js +28 -64
- package/dist/core/capability/providers/codex-capability-provider.js +7 -8
- package/dist/core/channel-loader.js +18 -0
- package/dist/core/command/agent-control.js +32 -0
- package/dist/core/command/command-handler.js +81 -85
- package/dist/core/command/menu-catalog.js +1 -0
- package/dist/core/command/menu-handler.js +61 -149
- package/dist/core/command/menu-protocol.js +7 -1
- package/dist/core/command/provider-menu.js +13 -3
- package/dist/core/command/role-menu.js +47 -23
- package/dist/core/command/slash-handler.js +26 -43
- package/dist/core/command/team-workspace-items.js +81 -12
- package/dist/core/command/team-workspace-team.js +9 -71
- package/dist/core/command/topic-slash.js +9 -30
- package/dist/core/daemon-bootstrap.js +8 -1
- package/dist/core/daemon-control.js +7 -7
- package/dist/core/evolagent-registry.js +14 -1
- package/dist/core/file-integrity/store.js +2 -0
- package/dist/core/handoff/runtime.js +37 -1
- package/dist/core/inference/text-inference.js +3 -1
- package/dist/core/initialization/service.js +11 -6
- package/dist/core/interaction-router.js +3 -0
- package/dist/core/invoke/executors/text.js +72 -19
- package/dist/core/ipc-registration.js +2 -1
- package/dist/core/message/aun-ipc-sender.js +165 -55
- package/dist/core/message/im-renderer.js +1 -1
- package/dist/core/message/message-bridge.js +51 -334
- package/dist/core/message/message-log.js +5 -0
- package/dist/core/message/message-queue.js +22 -0
- package/dist/core/message/message-utils.js +8 -0
- package/dist/core/message/response-engine.js +429 -116
- package/dist/core/message/send-routing.js +5 -1
- package/dist/core/model/catalog-service.js +31 -11
- package/dist/core/model/model-capabilities.js +22 -4
- package/dist/core/model/model-catalog.js +1 -0
- package/dist/core/ownership/owner-resolver.js +328 -50
- package/dist/core/permission/protected-paths.js +6 -6
- package/dist/core/relation/peer-identity.js +23 -1
- package/dist/core/relation/same-owner-proof.js +81 -112
- package/dist/core/session/adapters/codex-session-file-adapter.js +96 -15
- package/dist/core/session/session-file-health.js +13 -7
- package/dist/core/session/session-fs-store.js +91 -35
- package/dist/core/session/session-manager.js +68 -24
- package/dist/core/session/session-mapper.js +14 -34
- package/dist/core/session/session-transcript.js +5 -1
- package/dist/core/task/task-activity-store.js +84 -0
- package/dist/core/task/task-recovery-service.js +12 -0
- package/dist/core/thread/command-parser.js +7 -12
- package/dist/core/thread/thread-context-storage.js +3 -2
- package/dist/core/thread/thread-operation.js +2 -13
- package/dist/core/thread/thread-service.js +15 -46
- package/dist/directory/owner-directory-admission.js +1 -1
- package/dist/directory/owner-directory-cache.js +45 -28
- package/dist/directory/owner-directory-markdown.js +13 -1
- package/dist/directory/owner-directory-query-operation.js +29 -3
- package/dist/directory/owner-directory-remarks.js +11 -3
- package/dist/eck/message-renderer.js +84 -24
- package/dist/ecweb/basic-settings-service.js +3 -1
- package/dist/ecweb/message-context-service.js +1 -1
- package/dist/ecweb/pairing.js +4 -3
- package/dist/ecweb/providers-service.js +26 -1
- package/dist/ecweb/runtime/lifecycle.js +18 -8
- package/dist/ecweb/runtime/proxy-access.js +74 -0
- package/dist/ecweb/runtime/supervisor.js +4 -2
- package/dist/event-center/registry.js +13 -2
- package/dist/event-center/runtime.js +103 -11
- package/dist/event-center/script-runner.js +5 -5
- package/dist/index.js +92 -59
- package/dist/ipc.js +13 -2
- package/dist/outputs/events.js +62 -0
- package/dist/outputs/protocol.js +102 -0
- package/dist/outputs/service.js +279 -0
- package/dist/paths.js +3 -0
- package/dist/proxy/manager.js +43 -13
- package/dist/services/index.js +89 -4
- package/dist/services/ipc-operation.js +4 -15
- package/dist/services/pack-manager.js +12 -1
- package/dist/services/router.js +21 -6
- package/dist/services/script-runner.js +5 -4
- package/dist/services/validation.js +1 -1
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +19 -0
- package/dist/stats/index.js +1 -1
- package/dist/stats/{price-resolver.js → model-resolver.js} +305 -24
- package/dist/stats/normalizer.js +2 -0
- package/dist/stats/query.js +35 -27
- package/dist/stats/role-budget.js +5 -2
- package/dist/stats/writer.js +10 -6
- package/dist/trigger/audit.js +7 -0
- package/dist/trigger/authorization.js +105 -11
- package/dist/trigger/feedback.js +10 -0
- package/dist/trigger/history.js +37 -11
- package/dist/trigger/ipc-service.js +12 -1
- package/dist/trigger/manager.js +1 -0
- package/dist/trigger/scheduler.js +7 -5
- package/dist/trigger/script-executor.js +2 -1
- package/dist/trigger/script-sandbox.js +9 -3
- package/dist/trigger/validation.js +22 -0
- package/dist/utils/cross-platform.js +73 -26
- package/dist/utils/error-dict.json +94 -4
- package/dist/utils/error-utils.js +27 -4
- package/dist/utils/evolcore-version.js +36 -65
- package/dist/utils/msg-diag.js +1 -0
- package/dist/utils/process-introspect.js +12 -7
- package/dist/utils/process-tree.js +50 -2
- package/dist/utils/windows-shell-trust.js +2 -0
- package/dist/workbench/protocol.js +80 -0
- package/dist/workbench/service.js +359 -0
- package/ecagent/dist/types.d.ts +6 -2
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +2 -2
- package/kits/docs/evolcore/config.md +12 -0
- package/kits/docs/evolcore/directory.md +22 -3
- package/kits/docs/evolcore/ecweb-lifecycle.md +15 -0
- package/kits/docs/evolcore/model.md +10 -0
- package/kits/docs/evolcore/peer.md +19 -65
- package/kits/docs/evolcore/provider.md +123 -3
- package/kits/docs/evolcore/role.md +80 -0
- package/kits/docs/evolcore/services.md +6 -6
- package/kits/docs/evolcore/team-workspace.md +1 -1
- package/kits/docs/evolcore/thread-chain.md +14 -15
- package/kits/docs/evolcore/tool-authorization.md +5 -0
- package/kits/docs/evolcore/trigger.md +10 -0
- package/kits/eck_message_manifest.json +12 -0
- package/kits/provider-templates.json +1213 -0
- package/kits/rules/04-relation.md +3 -3
- package/kits/schemas/_meta.json +14 -2
- package/kits/schemas/contact-book.schema.4.json +52 -0
- package/kits/schemas/providers.schema.3.json +200 -0
- package/kits/skills/.switches.json +4 -0
- package/kits/skills/ability/references/calling.md +1 -1
- package/kits/skills/ec-group/SKILL.md +2 -2
- package/kits/skills/ec-identity/SKILL.md +19 -72
- package/kits/skills/ec-provider/SKILL.md +221 -0
- package/kits/skills/ec-provider/scripts/check-model.mjs +80 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/skills/thread-ops/SKILL.md +34 -21
- package/kits/templates/message-fragments/group-batch-item.md +1 -1
- package/kits/templates/message-fragments/group-batch.md +1 -1
- package/kits/templates/message-fragments/inject-default.md +1 -1
- package/kits/templates/message-fragments/interrupt-insert.md +1 -0
- package/kits/templates/message-fragments/item-group.md +1 -1
- package/kits/templates/message-fragments/item-private.md +1 -1
- package/kits/templates/message-fragments/thread-context.md +1 -1
- package/kits/templates/message-fragments/trigger-session.md +1 -1
- package/kits/templates/message-fragments/trigger-thread-check.md +1 -1
- package/kits/templates/roles/admin.json +2 -19
- package/kits/templates/roles/member.json +0 -3
- package/kits/templates/system-fragments/baseagent.md +6 -0
- package/kits/templates/system-fragments/commands.md +3 -3
- package/kits/templates/system-fragments/managed-runtime.md +1 -1
- package/kits/templates/system-fragments/relation.md +1 -1
- package/kits/templates/system-fragments/thread.md +6 -5
- package/package.json +6 -4
- package/scripts/agent-template/inspect.mjs +4 -1
- package/scripts/agent-template/shared/common.mjs +2 -3
- package/scripts/agent-template/shared/template-contract.mjs +2 -1
- package/scripts/agent-template/shared/template-package.mjs +9 -2
- package/scripts/agent-template/shared/template-runtime.mjs +20 -5
- package/scripts/agent-template/team-pack.mjs +6 -3
- package/dist/cli/peer.js +0 -127
- package/dist/config/peer-operation-service.js +0 -132
- package/dist/config/peer-request-service.js +0 -532
- package/dist/core/command/connect-menu.js +0 -624
|
@@ -13,6 +13,9 @@ import { toSdkAllowlist, toSdkCatalog } from './pack-manager.js';
|
|
|
13
13
|
import { eventListenerOff, EventCenterError, errorCode, errorMessage } from './types.js';
|
|
14
14
|
import { countActiveSubscribers, evaluateEventBusRequest } from './bus-gate.js';
|
|
15
15
|
import { RateWindow } from '../core/rate-window.js';
|
|
16
|
+
import { assertOutputEventRequest, outputAllowlist, PRIVATE_PROJECTION_EVENTS } from '../outputs/events.js';
|
|
17
|
+
import { OUTPUT_EVENT } from '../outputs/protocol.js';
|
|
18
|
+
import { ownerResolver, OWNERSHIP_AUTHORIZATION_MAX_AGE_MS } from '../core/ownership/owner-resolver.js';
|
|
16
19
|
/** SDK app.pubsub.v1 事件载荷 → 归一化事件。 */
|
|
17
20
|
export function toReceivedEvent(busAid, payload) {
|
|
18
21
|
const eventName = typeof payload.event_name === 'string' ? payload.event_name : '';
|
|
@@ -92,10 +95,61 @@ export class EventRuntime {
|
|
|
92
95
|
get packs() { return this.current?.state.enabledPacks ?? []; }
|
|
93
96
|
get resolutions() { return this.current?.resolutions ?? new Map(); }
|
|
94
97
|
get center() { return this.current?.center; }
|
|
98
|
+
get nativeOutputAvailable() { return this.current?.center.enabled === true && this.busHost.status === 'running' && this.busHost.gateInstalled; }
|
|
99
|
+
nativeOutputPublisher;
|
|
100
|
+
nativeOutputFlight;
|
|
101
|
+
nativeOutputPending = new Map();
|
|
102
|
+
outputOwnerOff;
|
|
103
|
+
async publishNativeOutput(data) {
|
|
104
|
+
return this.publishNativeProjection(OUTPUT_EVENT, data);
|
|
105
|
+
}
|
|
106
|
+
async publishNativeProjection(event, data) {
|
|
107
|
+
if (!PRIVATE_PROJECTION_EVENTS.some(value => value === event))
|
|
108
|
+
return;
|
|
109
|
+
if (!this.nativeOutputAvailable)
|
|
110
|
+
return;
|
|
111
|
+
this.nativeOutputPending.set(event, data);
|
|
112
|
+
if (this.nativeOutputFlight)
|
|
113
|
+
return this.nativeOutputFlight;
|
|
114
|
+
this.nativeOutputFlight = (async () => {
|
|
115
|
+
// Bound a burst to one in-flight notification and one latest invalidation.
|
|
116
|
+
while (this.nativeOutputPending.size && this.nativeOutputAvailable) {
|
|
117
|
+
const [event, latest] = this.nativeOutputPending.entries().next().value;
|
|
118
|
+
this.nativeOutputPending.delete(event);
|
|
119
|
+
const handle = await this.ensureClient();
|
|
120
|
+
if (!handle || !this.nativeOutputAvailable)
|
|
121
|
+
return;
|
|
122
|
+
const owner = await ownerResolver.refresh(this.options.aid, { source: 'outputs.publish',
|
|
123
|
+
maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, allowTransient: false });
|
|
124
|
+
if (!await this.rematerialize())
|
|
125
|
+
return;
|
|
126
|
+
if (owner.authorizationStatus !== 'verified' || owner.refreshFailure?.fallbackUsed
|
|
127
|
+
|| (owner.validUntil ?? 0) <= Date.now() || !this.nativeOutputAvailable)
|
|
128
|
+
return;
|
|
129
|
+
const events = new Set([...PRIVATE_PROJECTION_EVENTS, ...(this.registeredPubBuses.get(this.options.aid) ?? [])]);
|
|
130
|
+
if (this.nativeOutputPublisher !== handle || PRIVATE_PROJECTION_EVENTS.some(value => !this.registeredPubBuses.get(this.options.aid)?.has(value))) {
|
|
131
|
+
await handle.EventService.authorize(this.options.aid, 'pub', 'allowlist', [...events]);
|
|
132
|
+
this.registeredPubBuses.set(this.options.aid, events);
|
|
133
|
+
this.nativeOutputPublisher = handle;
|
|
134
|
+
}
|
|
135
|
+
const currentOwner = ownerResolver.snapshot(this.options.aid);
|
|
136
|
+
if (currentOwner.authorizationStatus !== 'verified' || currentOwner.refreshFailure?.fallbackUsed
|
|
137
|
+
|| (currentOwner.validUntil ?? 0) <= Date.now() || currentOwner.ownerAid !== owner.ownerAid
|
|
138
|
+
|| currentOwner.revision !== owner.revision || !this.nativeOutputAvailable)
|
|
139
|
+
return;
|
|
140
|
+
await handle.EventService.publish(this.options.aid, event, latest, { ttlSeconds: 30, schemaVersion: 1 });
|
|
141
|
+
}
|
|
142
|
+
})().finally(() => { this.nativeOutputFlight = undefined; this.nativeOutputPending.clear(); });
|
|
143
|
+
return this.nativeOutputFlight;
|
|
144
|
+
}
|
|
95
145
|
/** 启动:Bus(可选)→ 订阅 → 发布。任何一侧失败只记日志/台账,不影响其它侧。 */
|
|
96
146
|
async start(input) {
|
|
97
147
|
this.closed = false;
|
|
98
148
|
this.current = input;
|
|
149
|
+
this.outputOwnerOff ??= ownerResolver.onUpdate(aid => {
|
|
150
|
+
if (aid === this.options.aid && !this.closed)
|
|
151
|
+
void this.rematerialize();
|
|
152
|
+
});
|
|
99
153
|
this.configureRematerializeTimer();
|
|
100
154
|
this.configureContactsWatcher();
|
|
101
155
|
// 1. Bus 宿主(center.enabled 且目录非空)。
|
|
@@ -131,22 +185,28 @@ export class EventRuntime {
|
|
|
131
185
|
*/
|
|
132
186
|
deployableAllowlist(input) {
|
|
133
187
|
if (input.materializedAllowlist)
|
|
134
|
-
return input.materializedAllowlist;
|
|
188
|
+
return this.protectOutputAllowlist(input, input.materializedAllowlist);
|
|
135
189
|
if (this.current?.materializedAllowlist)
|
|
136
|
-
return this.current.materializedAllowlist;
|
|
190
|
+
return this.protectOutputAllowlist(input, this.current.materializedAllowlist);
|
|
137
191
|
if (!this.options.materializeAllowlist)
|
|
138
|
-
return toSdkAllowlist(input.center);
|
|
192
|
+
return this.protectOutputAllowlist(input, toSdkAllowlist(input.center));
|
|
139
193
|
const materialized = this.options.materializeAllowlist(input.center, input.state.catalog.map(entry => entry.event));
|
|
140
|
-
return materialized.degraded ? undefined : materialized.allowlist;
|
|
194
|
+
return materialized.degraded ? undefined : this.protectOutputAllowlist(input, materialized.allowlist);
|
|
195
|
+
}
|
|
196
|
+
protectOutputAllowlist(input, allowlist) {
|
|
197
|
+
return input.state.catalog.some(entry => entry.event === OUTPUT_EVENT)
|
|
198
|
+
? outputAllowlist(this.options.aid, { degraded: false, admittedAids: [], allowlist }).allowlist
|
|
199
|
+
: allowlist;
|
|
141
200
|
}
|
|
142
201
|
async updateCenter(center, materialized) {
|
|
143
202
|
// 与 reconfigure / reconcile 同队列:三者都改写 `current` 并下发 bus 配置。
|
|
144
203
|
await this.runExclusive(async () => {
|
|
145
204
|
if (!this.current)
|
|
146
205
|
return;
|
|
147
|
-
|
|
206
|
+
const allowlist = this.protectOutputAllowlist(this.current, materialized.allowlist);
|
|
207
|
+
this.current = { ...this.current, center, materializedAllowlist: allowlist };
|
|
148
208
|
if (center.enabled && this.current.state.catalog.length > 0 && !materialized.degraded) {
|
|
149
|
-
await this.busHost.apply({ catalog: toSdkCatalog(this.current.state.catalog), allowlist
|
|
209
|
+
await this.busHost.apply({ catalog: toSdkCatalog(this.current.state.catalog), allowlist });
|
|
150
210
|
}
|
|
151
211
|
else if (!center.enabled || this.current.state.catalog.length === 0) {
|
|
152
212
|
await this.busHost.apply(null);
|
|
@@ -172,21 +232,32 @@ export class EventRuntime {
|
|
|
172
232
|
const current = this.current;
|
|
173
233
|
const materializer = this.options.materializeAllowlist;
|
|
174
234
|
if (!current || !materializer || !current.center.enabled || current.state.catalog.length === 0)
|
|
175
|
-
return;
|
|
235
|
+
return false;
|
|
176
236
|
try {
|
|
177
237
|
const result = materializer(current.center, current.state.catalog.map(entry => entry.event));
|
|
178
238
|
if (result.degraded) {
|
|
179
239
|
logger.warn(`[EventCenter] ${this.options.aid} admission materialization degraded: ${result.reason ?? 'unknown'}`);
|
|
180
|
-
|
|
240
|
+
// Preserve ordinary event rules while still revoking a stale private
|
|
241
|
+
// output lease when the unrelated contacts snapshot is unavailable.
|
|
242
|
+
if (current.materializedAllowlist && current.state.catalog.some(entry => entry.event === OUTPUT_EVENT)) {
|
|
243
|
+
const protectedList = outputAllowlist(this.options.aid, { ...result, allowlist: current.materializedAllowlist }).allowlist;
|
|
244
|
+
await this.busHost.apply({ catalog: toSdkCatalog(current.state.catalog), allowlist: protectedList });
|
|
245
|
+
if (this.current === current)
|
|
246
|
+
this.current = { ...current, materializedAllowlist: protectedList };
|
|
247
|
+
}
|
|
248
|
+
return false;
|
|
181
249
|
}
|
|
182
|
-
|
|
250
|
+
const allowlist = this.protectOutputAllowlist(current, result.allowlist);
|
|
251
|
+
await this.busHost.apply({ catalog: toSdkCatalog(current.state.catalog), allowlist });
|
|
183
252
|
if (this.current === current)
|
|
184
|
-
this.current = { ...current, materializedAllowlist:
|
|
253
|
+
this.current = { ...current, materializedAllowlist: allowlist };
|
|
185
254
|
this.busHost.refreshGate();
|
|
186
255
|
this.reportGateStatus();
|
|
256
|
+
return true;
|
|
187
257
|
}
|
|
188
258
|
catch (error) {
|
|
189
259
|
logger.warn(`[EventCenter] ${this.options.aid} admission rematerialization failed: ${errorMessage(error)}`);
|
|
260
|
+
return false;
|
|
190
261
|
}
|
|
191
262
|
}
|
|
192
263
|
/**
|
|
@@ -203,6 +274,7 @@ export class EventRuntime {
|
|
|
203
274
|
const previous = this.current;
|
|
204
275
|
this.closed = false;
|
|
205
276
|
this.current = input;
|
|
277
|
+
this.nativeOutputPublisher = undefined;
|
|
206
278
|
this.configureRematerializeTimer();
|
|
207
279
|
this.configureContactsWatcher();
|
|
208
280
|
// 配置已变(新包集合/新解析结果):接入重试从头计退避,随后 diff 自会重排队列。
|
|
@@ -459,6 +531,12 @@ export class EventRuntime {
|
|
|
459
531
|
set.add(event);
|
|
460
532
|
desired.set(target.busAid, set);
|
|
461
533
|
}
|
|
534
|
+
if (this.nativeOutputAvailable && this.nativeOutputPublisher) {
|
|
535
|
+
const events = desired.get(this.options.aid) ?? new Set();
|
|
536
|
+
for (const event of PRIVATE_PROJECTION_EVENTS)
|
|
537
|
+
events.add(event);
|
|
538
|
+
desired.set(this.options.aid, events);
|
|
539
|
+
}
|
|
462
540
|
if (desired.size === 0)
|
|
463
541
|
return;
|
|
464
542
|
const handle = await this.ensureClient();
|
|
@@ -753,10 +831,24 @@ export class EventRuntime {
|
|
|
753
831
|
}
|
|
754
832
|
async close() {
|
|
755
833
|
this.closed = true;
|
|
834
|
+
this.outputOwnerOff?.();
|
|
835
|
+
this.outputOwnerOff = undefined;
|
|
836
|
+
this.nativeOutputPublisher = undefined;
|
|
837
|
+
this.nativeOutputPending.clear();
|
|
756
838
|
await this.stopConnections();
|
|
757
839
|
this.current = undefined;
|
|
758
840
|
}
|
|
759
|
-
gateRemoteRequest(senderAid, request, service) {
|
|
841
|
+
async gateRemoteRequest(senderAid, request, service) {
|
|
842
|
+
if (request.op === 'catalog' && this.current?.state.catalog.some(entry => entry.event === OUTPUT_EVENT)) {
|
|
843
|
+
// Catalog visibility is decided by the SDK's materialized ACL. Refresh
|
|
844
|
+
// it before discovery so a previous Owner cannot see the private event.
|
|
845
|
+
await ownerResolver.refresh(this.options.aid, { source: 'outputs.catalog',
|
|
846
|
+
maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, allowTransient: false });
|
|
847
|
+
if (!await this.rematerialize()) {
|
|
848
|
+
throw Object.assign(new Error('Private output catalog authorization is unavailable'), { code: 'FORBIDDEN' });
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
await assertOutputEventRequest(this.options.aid, senderAid, request, service);
|
|
760
852
|
const current = this.current;
|
|
761
853
|
const materializer = this.options.materializeAllowlist;
|
|
762
854
|
if (!current || !materializer)
|
|
@@ -73,7 +73,9 @@ export class ScriptRunner {
|
|
|
73
73
|
let launch;
|
|
74
74
|
let sandboxFallbackReason;
|
|
75
75
|
try {
|
|
76
|
-
|
|
76
|
+
const built = this.buildLaunch(pack, handler, event, executable, scriptPath, scriptArgs);
|
|
77
|
+
// Unsandboxed launches have no directory preparation or new authorization gap.
|
|
78
|
+
launch = built instanceof Promise ? await built : built;
|
|
77
79
|
if (launch.prepare) {
|
|
78
80
|
try {
|
|
79
81
|
// 探针必须设上限:沙箱 provisioning 挂住时这里会无限等待,dispatcher 的
|
|
@@ -171,16 +173,14 @@ export class ScriptRunner {
|
|
|
171
173
|
role: publisherRole,
|
|
172
174
|
};
|
|
173
175
|
const trigger = this.syntheticTrigger(pack, handler, executable);
|
|
174
|
-
|
|
176
|
+
return buildTriggerScriptLaunch({
|
|
175
177
|
trigger,
|
|
176
178
|
triggerDir: pack.dir,
|
|
177
179
|
scriptPath,
|
|
178
180
|
scriptArgs,
|
|
179
181
|
projectPath,
|
|
180
182
|
executionAuthorization: authorization,
|
|
181
|
-
});
|
|
182
|
-
// 沙箱环境由 buildSandboxEnvironment 派生(密钥已剔除);这里叠加事件契约变量。
|
|
183
|
-
return { ...launch, env: { ...launch.env, ...ecEnv } };
|
|
183
|
+
}).then(launch => ({ ...launch, env: { ...launch.env, ...ecEnv } }));
|
|
184
184
|
}
|
|
185
185
|
buildEcEnv(pack, event) {
|
|
186
186
|
return {
|
package/dist/index.js
CHANGED
|
@@ -15,12 +15,11 @@ import { CodexSessionFileAdapter } from './core/session/adapters/codex-session-f
|
|
|
15
15
|
import { GeminiSessionFileAdapter } from './core/session/adapters/gemini-session-file-adapter.js';
|
|
16
16
|
import { EcagentSessionFileAdapter } from './core/session/adapters/ecagent-session-file-adapter.js';
|
|
17
17
|
import { loadDefaults, loadAllAgents, migrateIdentitiesIfNeeded, loadDaemonConfig, initializeEckSnapshotsConfig } from './config-store.js';
|
|
18
|
+
import { RoleQuotaQuestions } from './config/role-command-service.js';
|
|
18
19
|
import { inspectClaudeSandboxDependencies, formatClaudeSandboxDependencies } from './core/permission/sandbox-runtime.js';
|
|
19
20
|
import { migrateRelationSharedDirectories } from './core/relation/shared-data.js';
|
|
20
21
|
import { DEFAULT_ECWEB_PORT, ecwebService, serviceRuntimeMode } from './config/daemon-services.js';
|
|
21
22
|
import { ConfigTarget, clearConfiguredOwnerAfterConsensus, onConfigWrite, } from './config/config-manager.js';
|
|
22
|
-
import { expirePendingPeerRequests } from './config/peer-request-service.js';
|
|
23
|
-
import { synchronizeOwnershipPeersSync } from './config/peer-book-store.js';
|
|
24
23
|
import { createSessionIdentityResolver } from './config/peer-role-resolver.js';
|
|
25
24
|
import { initializeStartupConfig, prepareStartupConfig, recordStartupConfig } from './config/boot-log.js';
|
|
26
25
|
import { CONFIG_SCHEMA_VERSION } from './types.js';
|
|
@@ -32,7 +31,6 @@ import { GeminiAgentPlugin } from './agents/gemini-runner.js';
|
|
|
32
31
|
// 不要静态导入 ecagent-runner:它连带整个 ecagent 运行时(typebox 占了模块图
|
|
33
32
|
// 三分之一的 resolve),而绝大多数部署并不使用 ecagent。这里用懒加载外壳。
|
|
34
33
|
import { EcagentAgentPluginLazy } from './agents/ecagent-plugin-lazy.js';
|
|
35
|
-
import { AUNChannelPlugin } from './channels/aun.js';
|
|
36
34
|
import { registerAbilityPlatform } from './ability/daemon.js';
|
|
37
35
|
import { assertAunEncryptionSeedPolicy } from './aun/aid/encryption-seed-policy.js';
|
|
38
36
|
import { BindService } from './utils/aid-bind.js';
|
|
@@ -48,6 +46,7 @@ import { HandoffRuntime } from './core/handoff/runtime.js';
|
|
|
48
46
|
import { startDaemonControlAid } from './core/daemon-control.js';
|
|
49
47
|
import { createDelegationAuthorizer } from './core/auth/delegation-authorization.js';
|
|
50
48
|
import { registerProxyIpcExecutor } from './proxy/ipc-service.js';
|
|
49
|
+
import { readServiceProxySnapshot } from './proxy/manager.js';
|
|
51
50
|
import { ownerResolver, getDaemonOwners, getPrimaryOwner } from './core/ownership/owner-resolver.js';
|
|
52
51
|
import { StartupTaskQueue, startupConnectionBudget, StartupGate, discoverStartupWork, recoverStartupObserverHints, StartupHandoffRecovery, resumePendingSessions, createDaemonShutdown, daemonConversationTotalExecutionMs, daemonConversationWatchdogMs, daemonIdleTimeoutMs, startupTaskReadiness, } from './core/daemon-lifecycle.js';
|
|
53
52
|
import { createLifecycleNoticeService } from './core/lifecycle-notice.js';
|
|
@@ -72,7 +71,7 @@ import { releaseSessionPathGrants } from './core/permission/session-path-grants.
|
|
|
72
71
|
import { InteractionRouter } from './core/interaction-router.js';
|
|
73
72
|
import { GroupInviteReviewService } from './aun/group/invite-service.js';
|
|
74
73
|
import { AgentDelegationRegistry, } from './core/auth/agent-delegation.js';
|
|
75
|
-
import { ChannelLoader } from './core/channel-loader.js';
|
|
74
|
+
import { ChannelLoader, registerBuiltinChannelPlugins } from './core/channel-loader.js';
|
|
76
75
|
import { registerChannelInstance as registerChannelRuntimeInstance, createChannelStartupNotifications, registerChannelHealthNotifications, bindStartupChannelsToAgents, createAgentStorageClientResolver, createDefaultChannelPolicy, createChannelConnectionRuntime, preloadChannelThreads, } from './core/channel-runtime.js';
|
|
77
76
|
import { createIpcStatusProvider, registerDaemonIpc } from './core/ipc-registration.js';
|
|
78
77
|
import { AgentLoader } from './core/baseagent-loader.js';
|
|
@@ -93,6 +92,8 @@ import { authenticatedTriggerActor as authenticateTriggerActor, authenticatedTri
|
|
|
93
92
|
import { TargetSessionLockRegistry } from './trigger/session-lock.js';
|
|
94
93
|
import { buildTriggerScheduler, createTriggerChannelResolver, TriggerSchedulerRegistry } from './trigger/application-service.js';
|
|
95
94
|
import { createDaemonEventCenter } from './event-center/daemon.js';
|
|
95
|
+
import { setOutputChangePublisher } from './outputs/service.js';
|
|
96
|
+
import { setWorkbenchChangePublisher, setWorkbenchRuntimeProvider, notifyWorkbenchRuntimeChanged } from './workbench/service.js';
|
|
96
97
|
import { DaemonChannel } from './channels/daemon.js';
|
|
97
98
|
import { DAEMON_RUNTIME_EPOCH_ENV, ensureProcessManagedTempDir } from './cli/task-context.js';
|
|
98
99
|
import fs from 'fs';
|
|
@@ -269,7 +270,7 @@ async function main() {
|
|
|
269
270
|
priorityStartupGate.settle('cancelled');
|
|
270
271
|
normalStartupGate.settle('cancelled');
|
|
271
272
|
});
|
|
272
|
-
//
|
|
273
|
+
// Read build-time markers after task admission; startup never hashes the tree.
|
|
273
274
|
// Keep status pending until the background release instead of competing
|
|
274
275
|
// with recovery metadata reads. Bootstrap-only daemons have no task gate.
|
|
275
276
|
void trace.track('daemon.versionReport', async (phase) => {
|
|
@@ -331,7 +332,7 @@ async function main() {
|
|
|
331
332
|
}
|
|
332
333
|
if (bindBootstrapMode && process.env.EVOLCORE_WEB_INIT !== '1' && daemonCfg.aid && loadAllAgents().agents.length === 0) {
|
|
333
334
|
priorityStartupGate.settle('ready');
|
|
334
|
-
await runBindBootstrapDaemon(daemonCfg);
|
|
335
|
+
await runBindBootstrapDaemon(daemonCfg, ecwebSupervisor);
|
|
335
336
|
// The pairing-only daemon has no Agent task gate.
|
|
336
337
|
normalStartupGate.settle('ready');
|
|
337
338
|
return;
|
|
@@ -667,14 +668,6 @@ async function main() {
|
|
|
667
668
|
trace.mark('daemon.channelInstances', `${channelInstances.length} 个渠道实例`);
|
|
668
669
|
logger.info(`✓ Created ${channelInstances.length} channel instance(s)`);
|
|
669
670
|
let bootstrapService;
|
|
670
|
-
const contactRequestExpiryTimer = daemonPluginLifecycle.setInterval(() => {
|
|
671
|
-
for (const agent of agentRegistry.runnableAgents()) {
|
|
672
|
-
void expirePendingPeerRequests(agent.aid).catch(error => {
|
|
673
|
-
logger.warn(`[contact-request] Pending expiry sweep failed: self=${agent.aid} error=${error instanceof Error ? error.message : String(error)}`);
|
|
674
|
-
});
|
|
675
|
-
}
|
|
676
|
-
}, 60_000);
|
|
677
|
-
contactRequestExpiryTimer.unref?.();
|
|
678
671
|
const bindService = daemonCfg.aid
|
|
679
672
|
? new BindService({
|
|
680
673
|
receiverAid: daemonCfg.aid,
|
|
@@ -692,14 +685,6 @@ async function main() {
|
|
|
692
685
|
if (startupCancelled)
|
|
693
686
|
return;
|
|
694
687
|
permissionGateway.revalidatePendingApprovals(subjectAid);
|
|
695
|
-
if (agentRegistry.get(subjectAid)) {
|
|
696
|
-
try {
|
|
697
|
-
synchronizeOwnershipPeersSync(subjectAid);
|
|
698
|
-
}
|
|
699
|
-
catch (error) {
|
|
700
|
-
logOwnershipEvent('contacts.sync_failed', { subjectAid, ownerAid, errorCode: ownershipErrorCode(error) }, true);
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
688
|
if (!ownerAid)
|
|
704
689
|
return;
|
|
705
690
|
initializationServiceForOwnerRecovery?.resumeForOwner(subjectAid, ownerAid);
|
|
@@ -868,6 +853,31 @@ async function main() {
|
|
|
868
853
|
return (client ?? null);
|
|
869
854
|
},
|
|
870
855
|
});
|
|
856
|
+
setOutputChangePublisher((aid, data) => {
|
|
857
|
+
void eventCenter.publishAgentEvent(aid, 'team.outputs.changed', data).catch(() => { });
|
|
858
|
+
}, aid => eventCenter.get(aid)?.runtime.nativeOutputAvailable === true);
|
|
859
|
+
setWorkbenchChangePublisher((aid, data) => {
|
|
860
|
+
void eventCenter.publishAgentEvent(aid, 'team.workbench.changed', data).catch(() => { });
|
|
861
|
+
}, aid => eventCenter.get(aid)?.runtime.nativeOutputAvailable === true);
|
|
862
|
+
setWorkbenchRuntimeProvider(aid => {
|
|
863
|
+
const agent = agentRegistry.get(aid);
|
|
864
|
+
return agent ? { status: agent.status, tasks: responseEngine.getWorkbenchTasks(aid) } : undefined;
|
|
865
|
+
});
|
|
866
|
+
const workbenchLifecycle = (event) => {
|
|
867
|
+
if ('aid' in event && typeof event.aid === 'string')
|
|
868
|
+
notifyWorkbenchRuntimeChanged(event.aid);
|
|
869
|
+
};
|
|
870
|
+
for (const type of ['agent:started', 'agent:stopped', 'agent:enabled', 'agent:disabled', 'agent:error']) {
|
|
871
|
+
eventBus.subscribe(type, workbenchLifecycle);
|
|
872
|
+
}
|
|
873
|
+
onShutdown(() => {
|
|
874
|
+
setWorkbenchRuntimeProvider();
|
|
875
|
+
setWorkbenchChangePublisher();
|
|
876
|
+
setOutputChangePublisher(undefined);
|
|
877
|
+
for (const type of ['agent:started', 'agent:stopped', 'agent:enabled', 'agent:disabled', 'agent:error']) {
|
|
878
|
+
eventBus.unsubscribe(type, workbenchLifecycle);
|
|
879
|
+
}
|
|
880
|
+
});
|
|
871
881
|
cmdHandler.setEventCenter(eventCenter);
|
|
872
882
|
// ECK 能力清单变量:只读两个运行时的内存包集合,不扫目录。
|
|
873
883
|
responseEngine.setCapabilityIndexes(selfAid => ({
|
|
@@ -1148,6 +1158,7 @@ async function main() {
|
|
|
1148
1158
|
pendingFile,
|
|
1149
1159
|
upmsg,
|
|
1150
1160
|
});
|
|
1161
|
+
let getProxyTransport;
|
|
1151
1162
|
const startupObserverRecoveries = [];
|
|
1152
1163
|
let startupRecoveryPending = true;
|
|
1153
1164
|
const lifecycleNotices = createLifecycleNoticeService({
|
|
@@ -1292,17 +1303,7 @@ async function main() {
|
|
|
1292
1303
|
return triggerSchedulers.statusSummary(from, Date.now());
|
|
1293
1304
|
},
|
|
1294
1305
|
getStatusSnapshot,
|
|
1295
|
-
getServiceProxySnapshot: () => (
|
|
1296
|
-
source: 'daemon-config',
|
|
1297
|
-
items: (daemonCfg.services ?? []).filter(service => !!service.proxy || service.name === 'ecweb').map(service => ({
|
|
1298
|
-
name: service.name,
|
|
1299
|
-
serviceEnabled: service.enabled === true,
|
|
1300
|
-
proxyEnabled: service.proxy?.enabled === true,
|
|
1301
|
-
source: service.proxy?.source ?? null,
|
|
1302
|
-
serviceType: service.proxy?.serviceType ?? null,
|
|
1303
|
-
visibility: service.proxy?.visibility ?? null,
|
|
1304
|
-
})),
|
|
1305
|
-
}),
|
|
1306
|
+
getServiceProxySnapshot: () => readServiceProxySnapshot(getProxyTransport?.()),
|
|
1306
1307
|
}), async (argv, sessionId, delegationToken, delegationCommandHash) => {
|
|
1307
1308
|
const delegation = agentDelegationRegistry.validate(delegationToken, sessionId, delegationCommandHash);
|
|
1308
1309
|
if (!delegation.ok)
|
|
@@ -1435,6 +1436,7 @@ async function main() {
|
|
|
1435
1436
|
initializationServiceForOwnerRecovery = agentInitializationService;
|
|
1436
1437
|
agentApplicationService.setInitializationService(agentInitializationService);
|
|
1437
1438
|
cmdHandler.setAgentApplicationService(agentApplicationService);
|
|
1439
|
+
const templateRecoveryMutes = new Set();
|
|
1438
1440
|
setAgentTemplateService(createAgentTemplateRuntime({
|
|
1439
1441
|
holdHandoff: (aid, token) => handoffRuntime.holdAgent(aid, token),
|
|
1440
1442
|
initialization: agentInitializationService, application: agentApplicationService,
|
|
@@ -1446,7 +1448,9 @@ async function main() {
|
|
|
1446
1448
|
&& instance.channel.getAidState?.()?.status === 'connected');
|
|
1447
1449
|
},
|
|
1448
1450
|
registry: agentRegistry, coordinator: reloadCoordinator,
|
|
1449
|
-
reloadInsideGate: async (aid) => {
|
|
1451
|
+
reloadInsideGate: async (aid, recoveryJobId, restoreStopped) => {
|
|
1452
|
+
await agentRegistry.reload(aid, reloadHooks, { recoveryJobId, preserveStopped: true, restoreStopped });
|
|
1453
|
+
},
|
|
1450
1454
|
getControl: () => controlChannel,
|
|
1451
1455
|
waitForControl: async () => {
|
|
1452
1456
|
const deadline = Date.now() + 60_000;
|
|
@@ -1456,19 +1460,35 @@ async function main() {
|
|
|
1456
1460
|
},
|
|
1457
1461
|
getScheduler: aid => triggerSchedulers.get(aid),
|
|
1458
1462
|
recoveryComplete: (aid, succeeded) => {
|
|
1459
|
-
if (succeeded && templateStartupRecovery.pending.has(aid)) {
|
|
1463
|
+
if (succeeded && (templateStartupRecovery.pending.has(aid) || templateRecoveryMutes.has(aid))) {
|
|
1460
1464
|
const agent = agentRegistry.get(aid);
|
|
1461
|
-
if (agent)
|
|
1465
|
+
if (agent && agent.status !== 'disabled')
|
|
1462
1466
|
messageQueue.unmuteAgent(agent.name);
|
|
1467
|
+
if (agent?.error === 'Template installation requires recovery')
|
|
1468
|
+
delete agent.error;
|
|
1463
1469
|
templateStartupRecovery.pending.delete(aid);
|
|
1470
|
+
templateRecoveryMutes.delete(aid);
|
|
1464
1471
|
}
|
|
1465
1472
|
},
|
|
1466
|
-
block: aid => {
|
|
1473
|
+
block: async (aid) => {
|
|
1467
1474
|
const agent = agentRegistry.get(aid);
|
|
1468
|
-
if (agent)
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1475
|
+
if (!agent)
|
|
1476
|
+
return;
|
|
1477
|
+
agent.status = 'disabled';
|
|
1478
|
+
agent.error = 'Template installation requires recovery';
|
|
1479
|
+
if (!messageQueue.isAgentMuted(agent.name))
|
|
1480
|
+
templateRecoveryMutes.add(aid);
|
|
1481
|
+
messageQueue.muteAgent(agent.name);
|
|
1482
|
+
const { createRunnerReloadTransaction } = await import('./core/runner-reload-transaction.js');
|
|
1483
|
+
const runners = createRunnerReloadTransaction({ aid, agentMap, staged: [] });
|
|
1484
|
+
runners.commit();
|
|
1485
|
+
const settlements = await Promise.allSettled([
|
|
1486
|
+
messageQueue.interruptByAgentAndWait(agent.name), triggerSchedulers.remove(aid), runners.finalize(),
|
|
1487
|
+
...agent.channelInstanceNames().map(name => reloadHooks.disconnectChannel(name)),
|
|
1488
|
+
]);
|
|
1489
|
+
const failures = settlements.filter(result => result.status === 'rejected');
|
|
1490
|
+
if (failures.length)
|
|
1491
|
+
throw new AggregateError(failures.map(result => result.reason), 'Template runtime cleanup incomplete');
|
|
1472
1492
|
},
|
|
1473
1493
|
}));
|
|
1474
1494
|
for (const aid of templateStartupRecovery.pending) {
|
|
@@ -1574,6 +1594,7 @@ async function main() {
|
|
|
1574
1594
|
waitForServices: waitForBackgroundStartup,
|
|
1575
1595
|
connectChannel: channel => trace.track('daemon.controlChannelConnect', phase => connectionQueue.run(() => { phase('running'); return channel.connect(); }, () => !startupCancelled), undefined, { initialPhase: 'queued' }),
|
|
1576
1596
|
onServiceProxyManager: manager => {
|
|
1597
|
+
getProxyTransport = () => manager.transportSnapshot();
|
|
1577
1598
|
const authorizeManagedOperation = createDelegationAuthorizer({
|
|
1578
1599
|
agentDelegationRegistry,
|
|
1579
1600
|
sessionManager,
|
|
@@ -1586,6 +1607,36 @@ async function main() {
|
|
|
1586
1607
|
});
|
|
1587
1608
|
},
|
|
1588
1609
|
});
|
|
1610
|
+
if (controlChannel && daemonCfg.aid) {
|
|
1611
|
+
const channel = controlChannel;
|
|
1612
|
+
const daemonAid = daemonCfg.aid;
|
|
1613
|
+
const quotaQuestions = new RoleQuotaQuestions(interactionRouter);
|
|
1614
|
+
channel.interactionCallback = response => interactionRouter.handleAsync({ ...response, channelKey: 'control' });
|
|
1615
|
+
processor.setRoleQuotaNotifier(request => quotaQuestions.present({ request, daemonAid, transport: {
|
|
1616
|
+
channelKey: 'control',
|
|
1617
|
+
send: async (ownerAid, interaction) => {
|
|
1618
|
+
if (interaction.kind.kind !== 'action')
|
|
1619
|
+
return false;
|
|
1620
|
+
const card = interaction.kind;
|
|
1621
|
+
const result = await channel.sendContentPayload(ownerAid, {
|
|
1622
|
+
type: 'action_card', title: card.title, text: card.body, sensitive: true,
|
|
1623
|
+
actions: [...card.buttons.map(button => ({ label: button.label, value: button.key, behavior: 'reply' })),
|
|
1624
|
+
{ label: '输入新额度', behavior: 'compose', sensitive: true,
|
|
1625
|
+
compose_timeout_ms: Math.max(0, interaction.expiresAt - Date.now()) }],
|
|
1626
|
+
}, { contentKind: 'card', dedupeKey: interaction.id,
|
|
1627
|
+
ttl: Math.max(0, interaction.expiresAt - Date.now()),
|
|
1628
|
+
context: { delivery: { chatType: 'private' }, metadata: { encrypted: true } },
|
|
1629
|
+
postSend: { type: 'register_interaction_card', requestId: interaction.id, isCommandCard: false,
|
|
1630
|
+
initiatorAid: ownerAid, sensitive: true, expiresAt: interaction.expiresAt, delivery: { chatType: 'private' } }, });
|
|
1631
|
+
return ((result.status === undefined || result.status === 'sent') && !!result.messageId)
|
|
1632
|
+
|| ((result.status === 'retry' || result.queued === true) && !!result.outboxId);
|
|
1633
|
+
},
|
|
1634
|
+
invalidate: id => channel.invalidateInteraction(id),
|
|
1635
|
+
notice: async (ownerAid, text) => {
|
|
1636
|
+
await channel.sendStructuredOrThrow(ownerAid, { type: 'notice', text, subtype: 'role_quota' }, { delivery: { chatType: 'private' }, metadata: { encrypted: true } });
|
|
1637
|
+
},
|
|
1638
|
+
} }));
|
|
1639
|
+
}
|
|
1589
1640
|
// ── 连接所有渠道(后台首连,AUN/任意渠道故障不阻塞 daemon 主流程)──
|
|
1590
1641
|
trace.point('daemon.channelConnectDispatch');
|
|
1591
1642
|
const channelConnectTimings = new Map(channelInstances.map(instance => {
|
|
@@ -2094,21 +2145,3 @@ if (isMainScript(import.meta.url)) {
|
|
|
2094
2145
|
process.exit(1);
|
|
2095
2146
|
});
|
|
2096
2147
|
}
|
|
2097
|
-
async function registerBuiltinChannelPlugins(channelLoader) {
|
|
2098
|
-
channelLoader.register(new AUNChannelPlugin());
|
|
2099
|
-
const providers = [
|
|
2100
|
-
['feishu', async () => new (await import('./channels/feishu.js')).FeishuChannelPlugin()],
|
|
2101
|
-
['wechat', async () => new (await import('./channels/wechat.js')).WechatChannelPlugin()],
|
|
2102
|
-
['dingtalk', async () => new (await import('./channels/dingtalk.js')).DingtalkChannelPlugin()],
|
|
2103
|
-
['qqbot', async () => new (await import('./channels/qqbot.js')).QQBotChannelPlugin()],
|
|
2104
|
-
['wecom', async () => new (await import('./channels/wecom.js')).WecomChannelPlugin()],
|
|
2105
|
-
];
|
|
2106
|
-
for (const [channelType, load] of providers) {
|
|
2107
|
-
try {
|
|
2108
|
-
channelLoader.register(await load());
|
|
2109
|
-
}
|
|
2110
|
-
catch (error) {
|
|
2111
|
-
channelLoader.recordProviderFailure(channelType, error);
|
|
2112
|
-
}
|
|
2113
|
-
}
|
|
2114
|
-
}
|
package/dist/ipc.js
CHANGED
|
@@ -2481,8 +2481,19 @@ export class IpcServer {
|
|
|
2481
2481
|
if (!this.roleOperationExecutor)
|
|
2482
2482
|
return { ok: false, code: 'NOT_CONFIGURED', error: 'role.op not configured' };
|
|
2483
2483
|
const { argv, sessionId, delegationToken } = cmd;
|
|
2484
|
-
if (!Array.isArray(argv) || argv.some(value => typeof value !== 'string')
|
|
2485
|
-
return { ok: false, code: 'INVALID_REQUEST', error: '
|
|
2484
|
+
if (!Array.isArray(argv) || argv.some(value => typeof value !== 'string')) {
|
|
2485
|
+
return { ok: false, code: 'INVALID_REQUEST', error: 'invalid argv' };
|
|
2486
|
+
}
|
|
2487
|
+
const delegated = cmd.sessionId !== undefined || cmd.delegationToken !== undefined
|
|
2488
|
+
|| cmd.actorSessionId !== undefined;
|
|
2489
|
+
if (!delegated) {
|
|
2490
|
+
if (!this.hasValidControlToken(cmd.controlToken)) {
|
|
2491
|
+
return { ok: false, code: 'CONTROL_TOKEN_REQUIRED', error: 'Host role operations require a valid control token' };
|
|
2492
|
+
}
|
|
2493
|
+
return await this.roleOperationExecutor(argv, '', undefined, undefined, true);
|
|
2494
|
+
}
|
|
2495
|
+
if (!sessionId) {
|
|
2496
|
+
return { ok: false, code: 'INVALID_REQUEST', error: 'missing sessionId' };
|
|
2486
2497
|
}
|
|
2487
2498
|
if (delegationToken !== undefined && typeof delegationToken !== 'string') {
|
|
2488
2499
|
return { ok: false, code: 'INVALID_DELEGATION', error: 'delegationToken must be a string' };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ownerResolver, OWNERSHIP_AUTHORIZATION_MAX_AGE_MS } from '../core/ownership/owner-resolver.js';
|
|
2
|
+
import { OUTPUT_EVENT } from './protocol.js';
|
|
3
|
+
import { WORKBENCH_EVENT } from '../workbench/protocol.js';
|
|
4
|
+
export const PRIVATE_PROJECTION_EVENTS = [OUTPUT_EVENT, WORKBENCH_EVENT];
|
|
5
|
+
/** Fixed event shares the configured Bus. No pack, connection or switch is created. */
|
|
6
|
+
export function registerOutputEvent(state) {
|
|
7
|
+
const conflicts = state.enabledPacks.filter(pack => pack.register.some(item => PRIVATE_PROJECTION_EVENTS.some(event => event === item.event)));
|
|
8
|
+
for (const pack of conflicts)
|
|
9
|
+
state.invalidPacks.push({ id: pack.id, errors: ['Owner-private projection events are reserved native events'] });
|
|
10
|
+
const ids = new Set(conflicts.map(pack => pack.id));
|
|
11
|
+
state.enabledPacks = state.enabledPacks.filter(pack => !ids.has(pack.id));
|
|
12
|
+
state.catalog = state.catalog.filter(item => !PRIVATE_PROJECTION_EVENTS.some(event => event === item.event) && !ids.has(item.sourcePackId));
|
|
13
|
+
for (const event of PRIVATE_PROJECTION_EVENTS)
|
|
14
|
+
state.catalog.push({ event, ttl: 30, maxTtl: 60,
|
|
15
|
+
schemaVersion: 1, sourcePackId: event === OUTPUT_EVENT ? 'builtin.outputs' : 'builtin.workbench' });
|
|
16
|
+
}
|
|
17
|
+
export function outputAllowlist(aid, result) {
|
|
18
|
+
const owner = ownerResolver.snapshot(aid);
|
|
19
|
+
const subscriber = owner.authorizationStatus === 'verified' && !owner.refreshFailure?.fallbackUsed
|
|
20
|
+
&& (owner.validUntil ?? 0) > Date.now() ? owner.ownerAid : undefined;
|
|
21
|
+
const allowlist = { ...result.allowlist };
|
|
22
|
+
// The SDK ORs wildcard ACLs with named ACLs. Expand them over the other
|
|
23
|
+
// registered events so a stale Owner cannot retain this private subscription.
|
|
24
|
+
const wildcard = allowlist['*'];
|
|
25
|
+
if (wildcard) {
|
|
26
|
+
for (const [event, raw] of Object.entries(allowlist)) {
|
|
27
|
+
if (event === '*' || PRIVATE_PROJECTION_EVENTS.some(privateEvent => privateEvent === event))
|
|
28
|
+
continue;
|
|
29
|
+
const entry = raw;
|
|
30
|
+
allowlist[event] = Object.fromEntries(['publish_aids', 'subscribe_aids'].map(key => [key,
|
|
31
|
+
[...new Set([...(Array.isArray(entry?.[key]) ? entry[key] : []),
|
|
32
|
+
...(Array.isArray(wildcard[key]) ? wildcard[key] : [])])],
|
|
33
|
+
]));
|
|
34
|
+
}
|
|
35
|
+
delete allowlist['*'];
|
|
36
|
+
}
|
|
37
|
+
for (const event of PRIVATE_PROJECTION_EVENTS)
|
|
38
|
+
allowlist[event] = { publish_aids: [aid], subscribe_aids: subscriber ? [subscriber] : [] };
|
|
39
|
+
return { ...result, allowlist };
|
|
40
|
+
}
|
|
41
|
+
export async function assertOutputEventRequest(aid, sender, request, service) {
|
|
42
|
+
const lease = request.op === 'renew' && typeof request.lease_id === 'string'
|
|
43
|
+
? service?.leases?.get(request.lease_id) : undefined;
|
|
44
|
+
const names = [request.event_name, ...(Array.isArray(request.events) ? request.events : []),
|
|
45
|
+
...(Array.isArray(request.scope) ? request.scope.map(item => item?.event_name) : []),
|
|
46
|
+
...(lease?.scope?.map(item => item.event_name) ?? [])];
|
|
47
|
+
if (!PRIVATE_PROJECTION_EVENTS.some(event => names.includes(event)))
|
|
48
|
+
return;
|
|
49
|
+
const scope = Array.isArray(request.scope) ? request.scope : lease?.scope;
|
|
50
|
+
const actions = scope?.map(item => item?.action)
|
|
51
|
+
?? request.actions;
|
|
52
|
+
const publisherOnly = Array.isArray(actions) && actions.length > 0 && actions.every(action => action === 'publish');
|
|
53
|
+
if (sender === aid && (request.op === 'publish' ||
|
|
54
|
+
(request.op === 'authorize' || request.op === 'renew') && publisherOnly))
|
|
55
|
+
return;
|
|
56
|
+
const owner = await ownerResolver.refresh(aid, { maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS,
|
|
57
|
+
source: 'outputs.events', allowTransient: false });
|
|
58
|
+
if (request.op !== 'publish' && owner.authorizationStatus === 'verified'
|
|
59
|
+
&& !owner.refreshFailure?.fallbackUsed && (owner.validUntil ?? 0) > Date.now() && owner.ownerAid === sender)
|
|
60
|
+
return;
|
|
61
|
+
throw Object.assign(new Error('Output events require the current protocol Owner'), { code: 'FORBIDDEN' });
|
|
62
|
+
}
|