Skip to content

Commit f71f445

Browse files
committed
Status: lazy-load read-only account inspectors
1 parent 986b772 commit f71f445

10 files changed

+78
-48
lines changed

src/channels/plugins/status.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ async function buildSnapshotFromAccount<ResolvedAccount>(params: {
4141
};
4242
}
4343

44-
function inspectChannelAccount<ResolvedAccount>(params: {
44+
async function inspectChannelAccount<ResolvedAccount>(params: {
4545
plugin: ChannelPlugin<ResolvedAccount>;
4646
cfg: OpenClawConfig;
4747
accountId: string;
48-
}): ResolvedAccount | null {
48+
}): Promise<ResolvedAccount | null> {
4949
return (params.plugin.config.inspectAccount?.(params.cfg, params.accountId) ??
50-
inspectReadOnlyChannelAccount({
50+
(await inspectReadOnlyChannelAccount({
5151
channelId: params.plugin.id,
5252
cfg: params.cfg,
5353
accountId: params.accountId,
54-
})) as ResolvedAccount | null;
54+
}))) as ResolvedAccount | null;
5555
}
5656

5757
export async function buildReadOnlySourceChannelAccountSnapshot<ResolvedAccount>(params: {
@@ -62,7 +62,7 @@ export async function buildReadOnlySourceChannelAccountSnapshot<ResolvedAccount>
6262
probe?: unknown;
6363
audit?: unknown;
6464
}): Promise<ChannelAccountSnapshot | null> {
65-
const inspectedAccount = inspectChannelAccount(params);
65+
const inspectedAccount = await inspectChannelAccount(params);
6666
if (!inspectedAccount) {
6767
return null;
6868
}
@@ -80,7 +80,7 @@ export async function buildChannelAccountSnapshot<ResolvedAccount>(params: {
8080
probe?: unknown;
8181
audit?: unknown;
8282
}): Promise<ChannelAccountSnapshot> {
83-
const inspectedAccount = inspectChannelAccount(params);
83+
const inspectedAccount = await inspectChannelAccount(params);
8484
const account =
8585
inspectedAccount ?? params.plugin.config.resolveAccount(params.cfg, params.accountId);
8686
return await buildSnapshotFromAccount({
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export {
2+
inspectDiscordAccount,
3+
type InspectedDiscordAccount,
4+
} from "../../extensions/discord/src/account-inspect.js";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export {
2+
inspectSlackAccount,
3+
type InspectedSlackAccount,
4+
} from "../../extensions/slack/src/account-inspect.js";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export {
2+
inspectTelegramAccount,
3+
type InspectedTelegramAccount,
4+
} from "../../extensions/telegram/src/account-inspect.js";

src/channels/read-only-account-inspect.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,55 @@
1-
import {
2-
inspectDiscordAccount,
3-
type InspectedDiscordAccount,
4-
} from "../../extensions/discord/src/account-inspect.js";
5-
import {
6-
inspectSlackAccount,
7-
type InspectedSlackAccount,
8-
} from "../../extensions/slack/src/account-inspect.js";
9-
import {
10-
inspectTelegramAccount,
11-
type InspectedTelegramAccount,
12-
} from "../../extensions/telegram/src/account-inspect.js";
131
import type { OpenClawConfig } from "../config/config.js";
142
import type { ChannelId } from "./plugins/types.js";
153

4+
type DiscordInspectModule = typeof import("./read-only-account-inspect.discord.runtime.js");
5+
type SlackInspectModule = typeof import("./read-only-account-inspect.slack.runtime.js");
6+
type TelegramInspectModule = typeof import("./read-only-account-inspect.telegram.runtime.js");
7+
8+
let discordInspectModulePromise: Promise<DiscordInspectModule> | undefined;
9+
let slackInspectModulePromise: Promise<SlackInspectModule> | undefined;
10+
let telegramInspectModulePromise: Promise<TelegramInspectModule> | undefined;
11+
12+
function loadDiscordInspectModule() {
13+
discordInspectModulePromise ??= import("./read-only-account-inspect.discord.runtime.js");
14+
return discordInspectModulePromise;
15+
}
16+
17+
function loadSlackInspectModule() {
18+
slackInspectModulePromise ??= import("./read-only-account-inspect.slack.runtime.js");
19+
return slackInspectModulePromise;
20+
}
21+
22+
function loadTelegramInspectModule() {
23+
telegramInspectModulePromise ??= import("./read-only-account-inspect.telegram.runtime.js");
24+
return telegramInspectModulePromise;
25+
}
26+
1627
export type ReadOnlyInspectedAccount =
17-
| InspectedDiscordAccount
18-
| InspectedSlackAccount
19-
| InspectedTelegramAccount;
28+
| Awaited<ReturnType<DiscordInspectModule["inspectDiscordAccount"]>>
29+
| Awaited<ReturnType<SlackInspectModule["inspectSlackAccount"]>>
30+
| Awaited<ReturnType<TelegramInspectModule["inspectTelegramAccount"]>>;
2031

21-
export function inspectReadOnlyChannelAccount(params: {
32+
export async function inspectReadOnlyChannelAccount(params: {
2233
channelId: ChannelId;
2334
cfg: OpenClawConfig;
2435
accountId?: string | null;
25-
}): ReadOnlyInspectedAccount | null {
36+
}): Promise<ReadOnlyInspectedAccount | null> {
2637
if (params.channelId === "discord") {
38+
const { inspectDiscordAccount } = await loadDiscordInspectModule();
2739
return inspectDiscordAccount({
2840
cfg: params.cfg,
2941
accountId: params.accountId,
3042
});
3143
}
3244
if (params.channelId === "slack") {
45+
const { inspectSlackAccount } = await loadSlackInspectModule();
3346
return inspectSlackAccount({
3447
cfg: params.cfg,
3548
accountId: params.accountId,
3649
});
3750
}
3851
if (params.channelId === "telegram") {
52+
const { inspectTelegramAccount } = await loadTelegramInspectModule();
3953
return inspectTelegramAccount({
4054
cfg: params.cfg,
4155
accountId: params.accountId,

src/commands/channel-account-context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ export async function resolveDefaultChannelAccountContext(
7979

8080
const inspected =
8181
plugin.config.inspectAccount?.(cfg, defaultAccountId) ??
82-
inspectReadOnlyChannelAccount({
82+
(await inspectReadOnlyChannelAccount({
8383
channelId: plugin.id,
8484
cfg,
8585
accountId: defaultAccountId,
86-
});
86+
}));
8787

8888
let account = inspected;
8989
if (!account) {

src/commands/health.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,14 @@ const buildSessionSummary = (storePath: string) => {
165165
const asRecord = (value: unknown): Record<string, unknown> | null =>
166166
value && typeof value === "object" ? (value as Record<string, unknown>) : null;
167167

168-
function inspectHealthAccount(
169-
plugin: ChannelPlugin,
170-
cfg: OpenClawConfig,
171-
accountId: string,
172-
): unknown {
168+
async function inspectHealthAccount(plugin: ChannelPlugin, cfg: OpenClawConfig, accountId: string) {
173169
return (
174170
plugin.config.inspectAccount?.(cfg, accountId) ??
175-
inspectReadOnlyChannelAccount({
171+
(await inspectReadOnlyChannelAccount({
176172
channelId: plugin.id,
177173
cfg,
178174
accountId,
179-
})
175+
}))
180176
);
181177
}
182178

@@ -206,7 +202,7 @@ async function resolveHealthAccountContext(params: {
206202
diagnostics.push(
207203
`${params.plugin.id}:${params.accountId}: failed to resolve account (${formatErrorMessage(error)}).`,
208204
);
209-
account = inspectHealthAccount(params.plugin, params.cfg, params.accountId);
205+
account = await inspectHealthAccount(params.plugin, params.cfg, params.accountId);
210206
}
211207

212208
if (!account) {

src/commands/status-all/channels.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,27 @@ function formatTokenHint(token: string, opts: { showSecrets: boolean }): string
9191
return `${head}${tail} · len ${t.length}`;
9292
}
9393

94-
function inspectChannelAccount(plugin: ChannelPlugin, cfg: OpenClawConfig, accountId: string) {
94+
async function inspectChannelAccount(
95+
plugin: ChannelPlugin,
96+
cfg: OpenClawConfig,
97+
accountId: string,
98+
) {
9599
return (
96100
plugin.config.inspectAccount?.(cfg, accountId) ??
97-
inspectReadOnlyChannelAccount({
101+
(await inspectReadOnlyChannelAccount({
98102
channelId: plugin.id,
99103
cfg,
100104
accountId,
101-
})
105+
}))
102106
);
103107
}
104108

105109
async function resolveChannelAccountRow(
106110
params: ResolvedChannelAccountRowParams,
107111
): Promise<ChannelAccountRow> {
108112
const { plugin, cfg, sourceConfig, accountId } = params;
109-
const sourceInspectedAccount = inspectChannelAccount(plugin, sourceConfig, accountId);
110-
const resolvedInspectedAccount = inspectChannelAccount(plugin, cfg, accountId);
113+
const sourceInspectedAccount = await inspectChannelAccount(plugin, sourceConfig, accountId);
114+
const resolvedInspectedAccount = await inspectChannelAccount(plugin, cfg, accountId);
111115
const resolvedInspection = resolvedInspectedAccount as {
112116
enabled?: boolean;
113117
configured?: boolean;

src/infra/channel-summary.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,18 @@ const buildAccountDetails = (params: {
105105
return details;
106106
};
107107

108-
function inspectChannelAccount(plugin: ChannelPlugin, cfg: OpenClawConfig, accountId: string) {
108+
async function inspectChannelAccount(
109+
plugin: ChannelPlugin,
110+
cfg: OpenClawConfig,
111+
accountId: string,
112+
) {
109113
return (
110114
plugin.config.inspectAccount?.(cfg, accountId) ??
111-
inspectReadOnlyChannelAccount({
115+
(await inspectReadOnlyChannelAccount({
112116
channelId: plugin.id,
113117
cfg,
114118
accountId,
115-
})
119+
}))
116120
);
117121
}
118122

@@ -135,8 +139,8 @@ export async function buildChannelSummary(
135139
const entries: ChannelAccountEntry[] = [];
136140

137141
for (const accountId of resolvedAccountIds) {
138-
const sourceInspectedAccount = inspectChannelAccount(plugin, sourceConfig, accountId);
139-
const resolvedInspectedAccount = inspectChannelAccount(plugin, effective, accountId);
142+
const sourceInspectedAccount = await inspectChannelAccount(plugin, sourceConfig, accountId);
143+
const resolvedInspectedAccount = await inspectChannelAccount(plugin, effective, accountId);
140144
const resolvedInspection = resolvedInspectedAccount as {
141145
enabled?: boolean;
142146
configured?: boolean;

src/security/audit-channel.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,17 @@ export async function collectChannelSecurityFindings(params: {
144144
const findings: SecurityAuditFinding[] = [];
145145
const sourceConfig = params.sourceConfig ?? params.cfg;
146146

147-
const inspectChannelAccount = (
147+
const inspectChannelAccount = async (
148148
plugin: (typeof params.plugins)[number],
149149
cfg: OpenClawConfig,
150150
accountId: string,
151151
) =>
152152
plugin.config.inspectAccount?.(cfg, accountId) ??
153-
inspectReadOnlyChannelAccount({
153+
(await inspectReadOnlyChannelAccount({
154154
channelId: plugin.id,
155155
cfg,
156156
accountId,
157-
});
157+
}));
158158

159159
const asAccountRecord = (value: unknown): Record<string, unknown> | null =>
160160
value && typeof value === "object" && !Array.isArray(value)
@@ -166,8 +166,8 @@ export async function collectChannelSecurityFindings(params: {
166166
accountId: string,
167167
) => {
168168
const diagnostics: string[] = [];
169-
const sourceInspectedAccount = inspectChannelAccount(plugin, sourceConfig, accountId);
170-
const resolvedInspectedAccount = inspectChannelAccount(plugin, params.cfg, accountId);
169+
const sourceInspectedAccount = await inspectChannelAccount(plugin, sourceConfig, accountId);
170+
const resolvedInspectedAccount = await inspectChannelAccount(plugin, params.cfg, accountId);
171171
const sourceInspection = sourceInspectedAccount as {
172172
enabled?: boolean;
173173
configured?: boolean;

0 commit comments

Comments
 (0)