@@ -8,6 +8,8 @@ import type { PluginChannelRegistration } from "../../plugins/registry-types.js"
|
8 | 8 | import { |
9 | 9 | getActivePluginChannelRegistry, |
10 | 10 | getActivePluginChannelRegistryVersion, |
| 11 | +getActivePluginRegistry, |
| 12 | +getActivePluginRegistryVersion, |
11 | 13 | } from "../../plugins/runtime.js"; |
12 | 14 | import type { DeliverableMessageChannel } from "../../utils/message-channel.js"; |
13 | 15 | |
@@ -22,6 +24,27 @@ function channelEntryCanSend(entry: PluginChannelRegistration | undefined): bool
|
22 | 24 | return Boolean(entry?.plugin?.outbound?.sendText ?? entry?.plugin?.message?.send?.text); |
23 | 25 | } |
24 | 26 | |
| 27 | +function findChannelEntry( |
| 28 | +registry: ReturnType<typeof getActivePluginRegistry>, |
| 29 | +channel: DeliverableMessageChannel, |
| 30 | +): PluginChannelRegistration | undefined { |
| 31 | +return registry?.channels?.find((entry) => entry?.plugin?.id === channel); |
| 32 | +} |
| 33 | + |
| 34 | +function canResolveSendCapableChannel(channel: DeliverableMessageChannel): boolean { |
| 35 | +const activeChannelRegistry = getActivePluginChannelRegistry(); |
| 36 | +const channelEntry = findChannelEntry(activeChannelRegistry, channel); |
| 37 | +if (channelEntryCanSend(channelEntry)) { |
| 38 | +return true; |
| 39 | +} |
| 40 | + |
| 41 | +const activeRegistry = getActivePluginRegistry(); |
| 42 | +if (activeRegistry && activeRegistry !== activeChannelRegistry) { |
| 43 | +return channelEntryCanSend(findChannelEntry(activeRegistry, channel)); |
| 44 | +} |
| 45 | +return false; |
| 46 | +} |
| 47 | + |
25 | 48 | /** Loads runtime plugins on demand when a selected outbound channel has only a setup shell. */ |
26 | 49 | export function bootstrapOutboundChannelPlugin(params: { |
27 | 50 | channel: DeliverableMessageChannel; |
@@ -32,15 +55,11 @@ export function bootstrapOutboundChannelPlugin(params: {
|
32 | 55 | return; |
33 | 56 | } |
34 | 57 | |
35 | | -const activeChannelRegistry = getActivePluginChannelRegistry(); |
36 | | -const activeChannelEntry = activeChannelRegistry?.channels?.find( |
37 | | -(entry) => entry?.plugin?.id === params.channel, |
38 | | -); |
39 | | -if (channelEntryCanSend(activeChannelEntry)) { |
| 58 | +if (canResolveSendCapableChannel(params.channel)) { |
40 | 59 | return; |
41 | 60 | } |
42 | 61 | |
43 | | -const attemptKey = `${getActivePluginChannelRegistryVersion()}:${params.channel}`; |
| 62 | +const attemptKey = `${getActivePluginChannelRegistryVersion()}:${getActivePluginRegistryVersion()}:${params.channel}`; |
44 | 63 | if (bootstrapAttempts.has(attemptKey)) { |
45 | 64 | return; |
46 | 65 | } |
@@ -61,6 +80,9 @@ export function bootstrapOutboundChannelPlugin(params: {
|
61 | 80 | allowGatewaySubagentBinding: true, |
62 | 81 | }, |
63 | 82 | }); |
| 83 | +if (!canResolveSendCapableChannel(params.channel)) { |
| 84 | +bootstrapAttempts.delete(attemptKey); |
| 85 | +} |
64 | 86 | } catch { |
65 | 87 | bootstrapAttempts.delete(attemptKey); |
66 | 88 | } |
|