






















@@ -1,9 +1,10 @@
1-import { listChannelPlugins } from "../channels/plugins/index.js";
21import type { OutboundSendDeps } from "../infra/outbound/send-deps.js";
32import { createLazyRuntimeSurface } from "../shared/lazy-runtime.js";
43import type { CliDeps } from "./deps.types.js";
5-import { createOutboundSendDepsFromCliSource } from "./outbound-send-mapping.js";
6-import { createChannelOutboundRuntimeSend } from "./send-runtime/channel-outbound-send.js";
4+import {
5+CLI_OUTBOUND_SEND_FACTORY,
6+createOutboundSendDepsFromCliSource,
7+} from "./outbound-send-mapping.js";
7889/**
910 * Lazy-loaded per-channel send functions, keyed by channel ID.
@@ -17,6 +18,35 @@ type RuntimeSendModule = {
1718runtimeSend: RuntimeSend;
1819};
192021+const NON_CHANNEL_DEP_KEYS = new Set([
22+"__proto__",
23+"constructor",
24+"cron",
25+"cronConfig",
26+"cronEnabled",
27+"defaultAgentId",
28+"enqueueSystemEvent",
29+"getQueueSize",
30+"hasOwnProperty",
31+"inspect",
32+"log",
33+"migrateOrphanedSessionKeys",
34+"nowMs",
35+"onEvent",
36+"requestHeartbeatNow",
37+"resolveSessionStorePath",
38+"runHeartbeatOnce",
39+"runIsolatedAgentJob",
40+"runtime",
41+"sendCronFailureAlert",
42+"sessionStorePath",
43+"storePath",
44+"then",
45+"toJSON",
46+"toString",
47+"valueOf",
48+]);
49+2050// Per-channel module caches for lazy loading.
2151const senderCache = new Map<string, Promise<RuntimeSend>>();
2252@@ -41,22 +71,40 @@ function createLazySender(
4171}
42724373export function createDefaultDeps(): CliDeps {
44-// Keep the default dependency barrel limited to lazy senders so callers that
45-// only need outbound deps do not pull channel runtime boundaries on import.
4674const deps: CliDeps = {};
47-for (const plugin of listChannelPlugins()) {
48-deps[plugin.id] = createLazySender(
49-plugin.id,
50-async () =>
51-({
52-runtimeSend: createChannelOutboundRuntimeSend({
53-channelId: plugin.id,
54-unavailableMessage: `${plugin.meta.label ?? plugin.id} outbound adapter is unavailable.`,
55-}) as RuntimeSend,
56-}) satisfies RuntimeSendModule,
57-);
58-}
59-return deps;
75+const resolveSender = (channelId: string) =>
76+createLazySender(channelId, async () => {
77+const { createChannelOutboundRuntimeSend } =
78+await import("./send-runtime/channel-outbound-send.js");
79+return {
80+runtimeSend: createChannelOutboundRuntimeSend({
81+channelId: channelId as import("../channels/plugins/types.public.js").ChannelId,
82+unavailableMessage: `${channelId} outbound adapter is unavailable.`,
83+}) as RuntimeSend,
84+} satisfies RuntimeSendModule;
85+});
86+87+Object.defineProperty(deps, CLI_OUTBOUND_SEND_FACTORY, {
88+configurable: false,
89+enumerable: false,
90+value: resolveSender,
91+writable: false,
92+});
93+94+return new Proxy(deps, {
95+get(target, property, receiver) {
96+if (typeof property !== "string") {
97+return Reflect.get(target, property, receiver);
98+}
99+const existing = Reflect.get(target, property, receiver);
100+if (existing !== undefined || NON_CHANNEL_DEP_KEYS.has(property)) {
101+return existing;
102+}
103+const sender = resolveSender(property);
104+Reflect.set(target, property, sender, receiver);
105+return sender;
106+},
107+});
60108}
6110962110export function createOutboundSendDeps(deps: CliDeps): OutboundSendDeps {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。