Skip to content

Commit 2a1acec

Browse files
committed
refactor: reuse account status helpers in bundled channels
1 parent 87722d6 commit 2a1acec

File tree

5 files changed

+39
-30
lines changed

5 files changed

+39
-30
lines changed

extensions/imessage/runtime-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export {
22
DEFAULT_ACCOUNT_ID,
33
PAIRING_APPROVED_MESSAGE,
4+
buildComputedAccountStatusSnapshot,
45
buildChannelConfigSchema,
56
collectStatusIssuesFromLastError,
67
formatTrimmedAllowFromEntries,

extensions/imessage/src/channel.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
55
import { resolveOutboundSendDep } from "openclaw/plugin-sdk/outbound-runtime";
66
import { buildOutboundBaseSessionKey, type RoutePeer } from "openclaw/plugin-sdk/routing";
77
import {
8+
buildComputedAccountStatusSnapshot,
89
collectStatusIssuesFromLastError,
910
DEFAULT_ACCOUNT_ID,
1011
formatTrimmedAllowFromEntries,
@@ -206,21 +207,21 @@ export const imessagePlugin: ChannelPlugin<ResolvedIMessageAccount> = {
206207
}),
207208
probeAccount: async ({ timeoutMs }) =>
208209
await (await loadIMessageChannelRuntime()).probeIMessageAccount(timeoutMs),
209-
buildAccountSnapshot: ({ account, runtime, probe }) => ({
210-
accountId: account.accountId,
211-
name: account.name,
212-
enabled: account.enabled,
213-
configured: account.configured,
214-
running: runtime?.running ?? false,
215-
lastStartAt: runtime?.lastStartAt ?? null,
216-
lastStopAt: runtime?.lastStopAt ?? null,
217-
lastError: runtime?.lastError ?? null,
218-
cliPath: runtime?.cliPath ?? account.config.cliPath ?? null,
219-
dbPath: runtime?.dbPath ?? account.config.dbPath ?? null,
220-
probe,
221-
lastInboundAt: runtime?.lastInboundAt ?? null,
222-
lastOutboundAt: runtime?.lastOutboundAt ?? null,
223-
}),
210+
buildAccountSnapshot: ({ account, runtime, probe }) =>
211+
buildComputedAccountStatusSnapshot(
212+
{
213+
accountId: account.accountId,
214+
name: account.name,
215+
enabled: account.enabled,
216+
configured: account.configured,
217+
runtime,
218+
probe,
219+
},
220+
{
221+
cliPath: runtime?.cliPath ?? account.config.cliPath ?? null,
222+
dbPath: runtime?.dbPath ?? account.config.dbPath ?? null,
223+
},
224+
),
224225
resolveAccountState: ({ enabled }) => (enabled ? "enabled" : "disabled"),
225226
},
226227
gateway: {

extensions/matrix/src/channel.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
resolveMatrixTargetIdentity,
4242
} from "./matrix/target-ids.js";
4343
import {
44+
buildComputedAccountStatusSnapshot,
4445
buildChannelConfigSchema,
4546
buildProbeChannelStatusSummary,
4647
collectStatusIssuesFromLastError,
@@ -412,20 +413,22 @@ export const matrixPlugin: ChannelPlugin<ResolvedMatrixAccount> = {
412413
};
413414
}
414415
},
415-
buildAccountSnapshot: ({ account, runtime, probe }) => ({
416-
accountId: account.accountId,
417-
name: account.name,
418-
enabled: account.enabled,
419-
configured: account.configured,
420-
baseUrl: account.homeserver,
421-
running: runtime?.running ?? false,
422-
lastStartAt: runtime?.lastStartAt ?? null,
423-
lastStopAt: runtime?.lastStopAt ?? null,
424-
lastError: runtime?.lastError ?? null,
425-
probe,
426-
lastProbeAt: runtime?.lastProbeAt ?? null,
427-
...buildTrafficStatusSummary(runtime),
428-
}),
416+
buildAccountSnapshot: ({ account, runtime, probe }) =>
417+
buildComputedAccountStatusSnapshot(
418+
{
419+
accountId: account.accountId,
420+
name: account.name,
421+
enabled: account.enabled,
422+
configured: account.configured,
423+
runtime,
424+
probe,
425+
},
426+
{
427+
baseUrl: account.homeserver,
428+
lastProbeAt: runtime?.lastProbeAt ?? null,
429+
...buildTrafficStatusSummary(runtime),
430+
},
431+
),
429432
},
430433
gateway: {
431434
startAccount: async (ctx) => {

src/plugin-sdk/imessage.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ export {
4242
export { IMessageConfigSchema } from "../config/zod-schema.providers-core.js";
4343

4444
export { resolveChannelMediaMaxBytes } from "../channels/plugins/media-limits.js";
45-
export { collectStatusIssuesFromLastError } from "./status-helpers.js";
45+
export {
46+
buildComputedAccountStatusSnapshot,
47+
collectStatusIssuesFromLastError,
48+
} from "./status-helpers.js";
4649
export {
4750
monitorIMessageProvider,
4851
probeIMessage,

src/plugin-sdk/matrix.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ export { formatResolvedUnresolvedNote } from "./resolution-notes.js";
148148
export { runPluginCommandWithTimeout } from "./run-command.js";
149149
export { createLoggerBackedRuntime, resolveRuntimeEnv } from "./runtime.js";
150150
export {
151+
buildComputedAccountStatusSnapshot,
151152
buildProbeChannelStatusSummary,
152153
collectStatusIssuesFromLastError,
153154
} from "./status-helpers.js";

0 commit comments

Comments
 (0)