From 795f1f438b1dc881c194b23bdfeb7c855b5b7566 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 17 Mar 2026 08:37:02 -0700 Subject: [PATCH] refactor: expose lazy runtime helper to plugins --- extensions/bluebubbles/src/actions.ts | 2 +- extensions/bluebubbles/src/channel.ts | 2 +- extensions/feishu/src/channel.ts | 2 +- extensions/googlechat/src/channel.ts | 2 +- extensions/matrix/src/channel.ts | 2 +- extensions/msteams/src/channel.ts | 2 +- extensions/zalo/src/actions.ts | 2 +- scripts/lib/plugin-sdk-entrypoints.json | 1 + src/plugin-sdk/lazy-runtime.ts | 5 + src/plugins/contracts/auth.contract.test.ts | 2 +- src/plugins/runtime/runtime-discord.ts | 158 +++++++------------- src/plugins/runtime/runtime-slack.ts | 76 ++++------ src/plugins/runtime/runtime-telegram.ts | 108 ++++--------- src/plugins/runtime/runtime-whatsapp.ts | 37 ++--- src/shared/lazy-runtime.ts | 8 + 15 files changed, 147 insertions(+), 262 deletions(-) create mode 100644 src/plugin-sdk/lazy-runtime.ts diff --git a/extensions/bluebubbles/src/actions.ts b/extensions/bluebubbles/src/actions.ts index 47eedf97511..bd797f5ee53 100644 --- a/extensions/bluebubbles/src/actions.ts +++ b/extensions/bluebubbles/src/actions.ts @@ -11,7 +11,7 @@ import { type ChannelMessageActionAdapter, type ChannelMessageActionName, } from "openclaw/plugin-sdk/bluebubbles"; -import { createLazyRuntimeSurface } from "../../../src/shared/lazy-runtime.js"; +import { createLazyRuntimeSurface } from "openclaw/plugin-sdk/lazy-runtime"; import { resolveBlueBubblesAccount } from "./accounts.js"; import { getCachedBlueBubblesPrivateApiStatus, isMacOS26OrHigher } from "./probe.js"; import { normalizeSecretInputString } from "./secret-input.js"; diff --git a/extensions/bluebubbles/src/channel.ts b/extensions/bluebubbles/src/channel.ts index f3f3cdd7eb3..5343fb501a2 100644 --- a/extensions/bluebubbles/src/channel.ts +++ b/extensions/bluebubbles/src/channel.ts @@ -18,7 +18,7 @@ import { buildAccountScopedDmSecurityPolicy, collectOpenGroupPolicyRestrictSendersWarnings, } from "openclaw/plugin-sdk/channel-policy"; -import { createLazyRuntimeSurface } from "../../../src/shared/lazy-runtime.js"; +import { createLazyRuntimeSurface } from "openclaw/plugin-sdk/lazy-runtime"; import { listBlueBubblesAccountIds, type ResolvedBlueBubblesAccount, diff --git a/extensions/feishu/src/channel.ts b/extensions/feishu/src/channel.ts index c2df79e0028..ace8592497d 100644 --- a/extensions/feishu/src/channel.ts +++ b/extensions/feishu/src/channel.ts @@ -12,7 +12,7 @@ import { PAIRING_APPROVED_MESSAGE, } from "openclaw/plugin-sdk/feishu"; import type { ChannelMessageActionName } from "openclaw/plugin-sdk/feishu"; -import { createLazyRuntimeSurface } from "../../../src/shared/lazy-runtime.js"; +import { createLazyRuntimeSurface } from "openclaw/plugin-sdk/lazy-runtime"; import { resolveFeishuAccount, resolveFeishuCredentials, diff --git a/extensions/googlechat/src/channel.ts b/extensions/googlechat/src/channel.ts index 84715321ce8..ffccbb9bbac 100644 --- a/extensions/googlechat/src/channel.ts +++ b/extensions/googlechat/src/channel.ts @@ -27,7 +27,7 @@ import { type OpenClawConfig, } from "openclaw/plugin-sdk/googlechat"; import { GoogleChatConfigSchema } from "openclaw/plugin-sdk/googlechat"; -import { createLazyRuntimeSurface } from "../../../src/shared/lazy-runtime.js"; +import { createLazyRuntimeSurface } from "openclaw/plugin-sdk/lazy-runtime"; import { buildPassiveProbedChannelStatusSummary } from "../../shared/channel-status-summary.js"; import { listGoogleChatAccountIds, diff --git a/extensions/matrix/src/channel.ts b/extensions/matrix/src/channel.ts index 03007151d18..777017dcbf8 100644 --- a/extensions/matrix/src/channel.ts +++ b/extensions/matrix/src/channel.ts @@ -7,6 +7,7 @@ import { buildOpenGroupPolicyWarning, collectAllowlistProviderGroupPolicyWarnings, } from "openclaw/plugin-sdk/channel-policy"; +import { createLazyRuntimeSurface } from "openclaw/plugin-sdk/lazy-runtime"; import { buildChannelConfigSchema, buildProbeChannelStatusSummary, @@ -15,7 +16,6 @@ import { PAIRING_APPROVED_MESSAGE, type ChannelPlugin, } from "openclaw/plugin-sdk/matrix"; -import { createLazyRuntimeSurface } from "../../../src/shared/lazy-runtime.js"; import { buildTrafficStatusSummary } from "../../shared/channel-status-summary.js"; import { matrixMessageActions } from "./actions.js"; import { MatrixConfigSchema } from "./config-schema.js"; diff --git a/extensions/msteams/src/channel.ts b/extensions/msteams/src/channel.ts index e337566e483..7400f61e819 100644 --- a/extensions/msteams/src/channel.ts +++ b/extensions/msteams/src/channel.ts @@ -1,5 +1,6 @@ import { formatAllowFromLowercase } from "openclaw/plugin-sdk/allow-from"; import { collectAllowlistProviderRestrictSendersWarnings } from "openclaw/plugin-sdk/channel-policy"; +import { createLazyRuntimeSurface } from "openclaw/plugin-sdk/lazy-runtime"; import type { ChannelMessageActionName, ChannelPlugin, @@ -14,7 +15,6 @@ import { MSTeamsConfigSchema, PAIRING_APPROVED_MESSAGE, } from "openclaw/plugin-sdk/msteams"; -import { createLazyRuntimeSurface } from "../../../src/shared/lazy-runtime.js"; import { resolveMSTeamsGroupToolPolicy } from "./policy.js"; import type { ProbeMSTeamsResult } from "./probe.js"; import { diff --git a/extensions/zalo/src/actions.ts b/extensions/zalo/src/actions.ts index b492a57a6dc..67b6f42b8a7 100644 --- a/extensions/zalo/src/actions.ts +++ b/extensions/zalo/src/actions.ts @@ -1,10 +1,10 @@ +import { createLazyRuntimeSurface } from "openclaw/plugin-sdk/lazy-runtime"; import type { ChannelMessageActionAdapter, ChannelMessageActionName, OpenClawConfig, } from "openclaw/plugin-sdk/zalo"; import { extractToolSend, jsonResult, readStringParam } from "openclaw/plugin-sdk/zalo"; -import { createLazyRuntimeSurface } from "../../../src/shared/lazy-runtime.js"; import { listEnabledZaloAccounts } from "./accounts.js"; type ZaloActionsRuntime = typeof import("./actions.runtime.js").zaloActionsRuntime; diff --git a/scripts/lib/plugin-sdk-entrypoints.json b/scripts/lib/plugin-sdk-entrypoints.json index 6e41a759867..cad41b15fca 100644 --- a/scripts/lib/plugin-sdk-entrypoints.json +++ b/scripts/lib/plugin-sdk-entrypoints.json @@ -47,6 +47,7 @@ "irc", "llm-task", "lobster", + "lazy-runtime", "matrix", "mattermost", "memory-core", diff --git a/src/plugin-sdk/lazy-runtime.ts b/src/plugin-sdk/lazy-runtime.ts new file mode 100644 index 00000000000..ef8d7039373 --- /dev/null +++ b/src/plugin-sdk/lazy-runtime.ts @@ -0,0 +1,5 @@ +export { + createLazyRuntimeMethod, + createLazyRuntimeMethodBinder, + createLazyRuntimeSurface, +} from "../shared/lazy-runtime.js"; diff --git a/src/plugins/contracts/auth.contract.test.ts b/src/plugins/contracts/auth.contract.test.ts index 40a82482edd..355ceb43962 100644 --- a/src/plugins/contracts/auth.contract.test.ts +++ b/src/plugins/contracts/auth.contract.test.ts @@ -20,7 +20,7 @@ type LoginQwenPortalOAuth = type GithubCopilotLoginCommand = (typeof import("openclaw/plugin-sdk/provider-auth"))["githubCopilotLoginCommand"]; type CreateVpsAwareHandlers = - (typeof import("../../commands/oauth-flow.js"))["createVpsAwareOAuthHandlers"]; + (typeof import("../provider-oauth-flow.js"))["createVpsAwareOAuthHandlers"]; const loginOpenAICodexOAuthMock = vi.hoisted(() => vi.fn()); const loginQwenPortalOAuthMock = vi.hoisted(() => vi.fn()); diff --git a/src/plugins/runtime/runtime-discord.ts b/src/plugins/runtime/runtime-discord.ts index 4878bff3d81..6203fa6c2d8 100644 --- a/src/plugins/runtime/runtime-discord.ts +++ b/src/plugins/runtime/runtime-discord.ts @@ -9,121 +9,71 @@ import { setThreadBindingMaxAgeBySessionKey, unbindThreadBindingsBySessionKey, } from "../../../extensions/discord/src/monitor/thread-bindings.js"; -import { createLazyRuntimeMethod, createLazyRuntimeSurface } from "../../shared/lazy-runtime.js"; +import { + createLazyRuntimeMethodBinder, + createLazyRuntimeSurface, +} from "../../shared/lazy-runtime.js"; import { createDiscordTypingLease } from "./runtime-discord-typing.js"; import type { PluginRuntimeChannel } from "./types-channel.js"; -type RuntimeDiscordOps = typeof import("./runtime-discord-ops.runtime.js").runtimeDiscordOps; - const loadRuntimeDiscordOps = createLazyRuntimeSurface( () => import("./runtime-discord-ops.runtime.js"), ({ runtimeDiscordOps }) => runtimeDiscordOps, ); -const auditChannelPermissionsLazy = createLazyRuntimeMethod< - RuntimeDiscordOps, - Parameters, - ReturnType ->(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.auditChannelPermissions); +const bindDiscordRuntimeMethod = createLazyRuntimeMethodBinder(loadRuntimeDiscordOps); -const listDirectoryGroupsLiveLazy = createLazyRuntimeMethod< - RuntimeDiscordOps, - Parameters, - ReturnType ->(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.listDirectoryGroupsLive); - -const listDirectoryPeersLiveLazy = createLazyRuntimeMethod< - RuntimeDiscordOps, - Parameters, - ReturnType ->(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.listDirectoryPeersLive); - -const probeDiscordLazy = createLazyRuntimeMethod< - RuntimeDiscordOps, - Parameters, - ReturnType ->(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.probeDiscord); - -const resolveChannelAllowlistLazy = createLazyRuntimeMethod< - RuntimeDiscordOps, - Parameters, - ReturnType ->(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.resolveChannelAllowlist); - -const resolveUserAllowlistLazy = createLazyRuntimeMethod< - RuntimeDiscordOps, - Parameters, - ReturnType ->(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.resolveUserAllowlist); - -const sendComponentMessageLazy = createLazyRuntimeMethod< - RuntimeDiscordOps, - Parameters, - ReturnType ->(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.sendComponentMessage); - -const sendMessageDiscordLazy = createLazyRuntimeMethod< - RuntimeDiscordOps, - Parameters, - ReturnType ->(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.sendMessageDiscord); - -const sendPollDiscordLazy = createLazyRuntimeMethod< - RuntimeDiscordOps, - Parameters, - ReturnType ->(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.sendPollDiscord); - -const monitorDiscordProviderLazy = createLazyRuntimeMethod< - RuntimeDiscordOps, - Parameters, - ReturnType ->(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.monitorDiscordProvider); - -const sendTypingDiscordLazy = createLazyRuntimeMethod< - RuntimeDiscordOps, - Parameters, - ReturnType ->(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.typing.pulse); - -const editMessageDiscordLazy = createLazyRuntimeMethod< - RuntimeDiscordOps, - Parameters, - ReturnType ->(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.conversationActions.editMessage); - -const deleteMessageDiscordLazy = createLazyRuntimeMethod< - RuntimeDiscordOps, - Parameters, - ReturnType ->( - loadRuntimeDiscordOps, +const auditChannelPermissionsLazy = bindDiscordRuntimeMethod( + (runtimeDiscordOps) => runtimeDiscordOps.auditChannelPermissions, +); +const listDirectoryGroupsLiveLazy = bindDiscordRuntimeMethod( + (runtimeDiscordOps) => runtimeDiscordOps.listDirectoryGroupsLive, +); +const listDirectoryPeersLiveLazy = bindDiscordRuntimeMethod( + (runtimeDiscordOps) => runtimeDiscordOps.listDirectoryPeersLive, +); +const probeDiscordLazy = bindDiscordRuntimeMethod( + (runtimeDiscordOps) => runtimeDiscordOps.probeDiscord, +); +const resolveChannelAllowlistLazy = bindDiscordRuntimeMethod( + (runtimeDiscordOps) => runtimeDiscordOps.resolveChannelAllowlist, +); +const resolveUserAllowlistLazy = bindDiscordRuntimeMethod( + (runtimeDiscordOps) => runtimeDiscordOps.resolveUserAllowlist, +); +const sendComponentMessageLazy = bindDiscordRuntimeMethod( + (runtimeDiscordOps) => runtimeDiscordOps.sendComponentMessage, +); +const sendMessageDiscordLazy = bindDiscordRuntimeMethod( + (runtimeDiscordOps) => runtimeDiscordOps.sendMessageDiscord, +); +const sendPollDiscordLazy = bindDiscordRuntimeMethod( + (runtimeDiscordOps) => runtimeDiscordOps.sendPollDiscord, +); +const monitorDiscordProviderLazy = bindDiscordRuntimeMethod( + (runtimeDiscordOps) => runtimeDiscordOps.monitorDiscordProvider, +); +const sendTypingDiscordLazy = bindDiscordRuntimeMethod( + (runtimeDiscordOps) => runtimeDiscordOps.typing.pulse, +); +const editMessageDiscordLazy = bindDiscordRuntimeMethod( + (runtimeDiscordOps) => runtimeDiscordOps.conversationActions.editMessage, +); +const deleteMessageDiscordLazy = bindDiscordRuntimeMethod( (runtimeDiscordOps) => runtimeDiscordOps.conversationActions.deleteMessage, ); - -const pinMessageDiscordLazy = createLazyRuntimeMethod< - RuntimeDiscordOps, - Parameters, - ReturnType ->(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.conversationActions.pinMessage); - -const unpinMessageDiscordLazy = createLazyRuntimeMethod< - RuntimeDiscordOps, - Parameters, - ReturnType ->(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.conversationActions.unpinMessage); - -const createThreadDiscordLazy = createLazyRuntimeMethod< - RuntimeDiscordOps, - Parameters, - ReturnType ->(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.conversationActions.createThread); - -const editChannelDiscordLazy = createLazyRuntimeMethod< - RuntimeDiscordOps, - Parameters, - ReturnType ->(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.conversationActions.editChannel); +const pinMessageDiscordLazy = bindDiscordRuntimeMethod( + (runtimeDiscordOps) => runtimeDiscordOps.conversationActions.pinMessage, +); +const unpinMessageDiscordLazy = bindDiscordRuntimeMethod( + (runtimeDiscordOps) => runtimeDiscordOps.conversationActions.unpinMessage, +); +const createThreadDiscordLazy = bindDiscordRuntimeMethod( + (runtimeDiscordOps) => runtimeDiscordOps.conversationActions.createThread, +); +const editChannelDiscordLazy = bindDiscordRuntimeMethod( + (runtimeDiscordOps) => runtimeDiscordOps.conversationActions.editChannel, +); export function createRuntimeDiscord(): PluginRuntimeChannel["discord"] { return { diff --git a/src/plugins/runtime/runtime-slack.ts b/src/plugins/runtime/runtime-slack.ts index 30742195ad6..9f1cab0f094 100644 --- a/src/plugins/runtime/runtime-slack.ts +++ b/src/plugins/runtime/runtime-slack.ts @@ -1,60 +1,38 @@ -import { createLazyRuntimeMethod, createLazyRuntimeSurface } from "../../shared/lazy-runtime.js"; +import { + createLazyRuntimeMethodBinder, + createLazyRuntimeSurface, +} from "../../shared/lazy-runtime.js"; import type { PluginRuntimeChannel } from "./types-channel.js"; -type RuntimeSlackOps = typeof import("./runtime-slack-ops.runtime.js").runtimeSlackOps; - const loadRuntimeSlackOps = createLazyRuntimeSurface( () => import("./runtime-slack-ops.runtime.js"), ({ runtimeSlackOps }) => runtimeSlackOps, ); -const listDirectoryGroupsLiveLazy = createLazyRuntimeMethod< - RuntimeSlackOps, - Parameters, - ReturnType ->(loadRuntimeSlackOps, (runtimeSlackOps) => runtimeSlackOps.listDirectoryGroupsLive); +const bindSlackRuntimeMethod = createLazyRuntimeMethodBinder(loadRuntimeSlackOps); -const listDirectoryPeersLiveLazy = createLazyRuntimeMethod< - RuntimeSlackOps, - Parameters, - ReturnType ->(loadRuntimeSlackOps, (runtimeSlackOps) => runtimeSlackOps.listDirectoryPeersLive); - -const probeSlackLazy = createLazyRuntimeMethod< - RuntimeSlackOps, - Parameters, - ReturnType ->(loadRuntimeSlackOps, (runtimeSlackOps) => runtimeSlackOps.probeSlack); - -const resolveChannelAllowlistLazy = createLazyRuntimeMethod< - RuntimeSlackOps, - Parameters, - ReturnType ->(loadRuntimeSlackOps, (runtimeSlackOps) => runtimeSlackOps.resolveChannelAllowlist); - -const resolveUserAllowlistLazy = createLazyRuntimeMethod< - RuntimeSlackOps, - Parameters, - ReturnType ->(loadRuntimeSlackOps, (runtimeSlackOps) => runtimeSlackOps.resolveUserAllowlist); - -const sendMessageSlackLazy = createLazyRuntimeMethod< - RuntimeSlackOps, - Parameters, - ReturnType ->(loadRuntimeSlackOps, (runtimeSlackOps) => runtimeSlackOps.sendMessageSlack); - -const monitorSlackProviderLazy = createLazyRuntimeMethod< - RuntimeSlackOps, - Parameters, - ReturnType ->(loadRuntimeSlackOps, (runtimeSlackOps) => runtimeSlackOps.monitorSlackProvider); - -const handleSlackActionLazy = createLazyRuntimeMethod< - RuntimeSlackOps, - Parameters, - ReturnType ->(loadRuntimeSlackOps, (runtimeSlackOps) => runtimeSlackOps.handleSlackAction); +const listDirectoryGroupsLiveLazy = bindSlackRuntimeMethod( + (runtimeSlackOps) => runtimeSlackOps.listDirectoryGroupsLive, +); +const listDirectoryPeersLiveLazy = bindSlackRuntimeMethod( + (runtimeSlackOps) => runtimeSlackOps.listDirectoryPeersLive, +); +const probeSlackLazy = bindSlackRuntimeMethod((runtimeSlackOps) => runtimeSlackOps.probeSlack); +const resolveChannelAllowlistLazy = bindSlackRuntimeMethod( + (runtimeSlackOps) => runtimeSlackOps.resolveChannelAllowlist, +); +const resolveUserAllowlistLazy = bindSlackRuntimeMethod( + (runtimeSlackOps) => runtimeSlackOps.resolveUserAllowlist, +); +const sendMessageSlackLazy = bindSlackRuntimeMethod( + (runtimeSlackOps) => runtimeSlackOps.sendMessageSlack, +); +const monitorSlackProviderLazy = bindSlackRuntimeMethod( + (runtimeSlackOps) => runtimeSlackOps.monitorSlackProvider, +); +const handleSlackActionLazy = bindSlackRuntimeMethod( + (runtimeSlackOps) => runtimeSlackOps.handleSlackAction, +); export function createRuntimeSlack(): PluginRuntimeChannel["slack"] { return { diff --git a/src/plugins/runtime/runtime-telegram.ts b/src/plugins/runtime/runtime-telegram.ts index b83df21670f..f8d71de11e0 100644 --- a/src/plugins/runtime/runtime-telegram.ts +++ b/src/plugins/runtime/runtime-telegram.ts @@ -5,104 +5,54 @@ import { setTelegramThreadBindingMaxAgeBySessionKey, } from "../../../extensions/telegram/src/thread-bindings.js"; import { resolveTelegramToken } from "../../../extensions/telegram/src/token.js"; -import { createLazyRuntimeMethod, createLazyRuntimeSurface } from "../../shared/lazy-runtime.js"; +import { + createLazyRuntimeMethodBinder, + createLazyRuntimeSurface, +} from "../../shared/lazy-runtime.js"; import { createTelegramTypingLease } from "./runtime-telegram-typing.js"; import type { PluginRuntimeChannel } from "./types-channel.js"; -type RuntimeTelegramOps = typeof import("./runtime-telegram-ops.runtime.js").runtimeTelegramOps; - const loadRuntimeTelegramOps = createLazyRuntimeSurface( () => import("./runtime-telegram-ops.runtime.js"), ({ runtimeTelegramOps }) => runtimeTelegramOps, ); -const auditGroupMembershipLazy = createLazyRuntimeMethod< - RuntimeTelegramOps, - Parameters, - ReturnType ->(loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.auditGroupMembership); +const bindTelegramRuntimeMethod = createLazyRuntimeMethodBinder(loadRuntimeTelegramOps); -const probeTelegramLazy = createLazyRuntimeMethod< - RuntimeTelegramOps, - Parameters, - ReturnType ->(loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.probeTelegram); - -const sendMessageTelegramLazy = createLazyRuntimeMethod< - RuntimeTelegramOps, - Parameters, - ReturnType ->(loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.sendMessageTelegram); - -const sendPollTelegramLazy = createLazyRuntimeMethod< - RuntimeTelegramOps, - Parameters, - ReturnType ->(loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.sendPollTelegram); - -const monitorTelegramProviderLazy = createLazyRuntimeMethod< - RuntimeTelegramOps, - Parameters, - ReturnType ->(loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.monitorTelegramProvider); - -const sendTypingTelegramLazy = createLazyRuntimeMethod< - RuntimeTelegramOps, - Parameters, - ReturnType ->(loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.typing.pulse); - -const editMessageTelegramLazy = createLazyRuntimeMethod< - RuntimeTelegramOps, - Parameters, - ReturnType ->( - loadRuntimeTelegramOps, +const auditGroupMembershipLazy = bindTelegramRuntimeMethod( + (runtimeTelegramOps) => runtimeTelegramOps.auditGroupMembership, +); +const probeTelegramLazy = bindTelegramRuntimeMethod( + (runtimeTelegramOps) => runtimeTelegramOps.probeTelegram, +); +const sendMessageTelegramLazy = bindTelegramRuntimeMethod( + (runtimeTelegramOps) => runtimeTelegramOps.sendMessageTelegram, +); +const sendPollTelegramLazy = bindTelegramRuntimeMethod( + (runtimeTelegramOps) => runtimeTelegramOps.sendPollTelegram, +); +const monitorTelegramProviderLazy = bindTelegramRuntimeMethod( + (runtimeTelegramOps) => runtimeTelegramOps.monitorTelegramProvider, +); +const sendTypingTelegramLazy = bindTelegramRuntimeMethod( + (runtimeTelegramOps) => runtimeTelegramOps.typing.pulse, +); +const editMessageTelegramLazy = bindTelegramRuntimeMethod( (runtimeTelegramOps) => runtimeTelegramOps.conversationActions.editMessage, ); - -const editMessageReplyMarkupTelegramLazy = createLazyRuntimeMethod< - RuntimeTelegramOps, - Parameters, - ReturnType ->( - loadRuntimeTelegramOps, +const editMessageReplyMarkupTelegramLazy = bindTelegramRuntimeMethod( (runtimeTelegramOps) => runtimeTelegramOps.conversationActions.editReplyMarkup, ); - -const deleteMessageTelegramLazy = createLazyRuntimeMethod< - RuntimeTelegramOps, - Parameters, - ReturnType ->( - loadRuntimeTelegramOps, +const deleteMessageTelegramLazy = bindTelegramRuntimeMethod( (runtimeTelegramOps) => runtimeTelegramOps.conversationActions.deleteMessage, ); - -const renameForumTopicTelegramLazy = createLazyRuntimeMethod< - RuntimeTelegramOps, - Parameters, - ReturnType ->( - loadRuntimeTelegramOps, +const renameForumTopicTelegramLazy = bindTelegramRuntimeMethod( (runtimeTelegramOps) => runtimeTelegramOps.conversationActions.renameTopic, ); - -const pinMessageTelegramLazy = createLazyRuntimeMethod< - RuntimeTelegramOps, - Parameters, - ReturnType ->( - loadRuntimeTelegramOps, +const pinMessageTelegramLazy = bindTelegramRuntimeMethod( (runtimeTelegramOps) => runtimeTelegramOps.conversationActions.pinMessage, ); - -const unpinMessageTelegramLazy = createLazyRuntimeMethod< - RuntimeTelegramOps, - Parameters, - ReturnType ->( - loadRuntimeTelegramOps, +const unpinMessageTelegramLazy = bindTelegramRuntimeMethod( (runtimeTelegramOps) => runtimeTelegramOps.conversationActions.unpinMessage, ); diff --git a/src/plugins/runtime/runtime-whatsapp.ts b/src/plugins/runtime/runtime-whatsapp.ts index 63871bc08f8..e3b38710ce1 100644 --- a/src/plugins/runtime/runtime-whatsapp.ts +++ b/src/plugins/runtime/runtime-whatsapp.ts @@ -6,15 +6,13 @@ import { readWebSelfId, webAuthExists, } from "../../../extensions/whatsapp/src/auth-store.js"; -import { createLazyRuntimeMethod, createLazyRuntimeSurface } from "../../shared/lazy-runtime.js"; +import { + createLazyRuntimeMethodBinder, + createLazyRuntimeSurface, +} from "../../shared/lazy-runtime.js"; import { createRuntimeWhatsAppLoginTool } from "./runtime-whatsapp-login-tool.js"; import type { PluginRuntime } from "./types.js"; -type RuntimeWhatsAppOutbound = - typeof import("./runtime-whatsapp-outbound.runtime.js").runtimeWhatsAppOutbound; -type RuntimeWhatsAppLogin = - typeof import("./runtime-whatsapp-login.runtime.js").runtimeWhatsAppLogin; - const loadWebOutbound = createLazyRuntimeSurface( () => import("./runtime-whatsapp-outbound.runtime.js"), ({ runtimeWhatsAppOutbound }) => runtimeWhatsAppOutbound, @@ -25,23 +23,18 @@ const loadWebLogin = createLazyRuntimeSurface( ({ runtimeWhatsAppLogin }) => runtimeWhatsAppLogin, ); -const sendMessageWhatsAppLazy = createLazyRuntimeMethod< - RuntimeWhatsAppOutbound, - Parameters, - ReturnType ->(loadWebOutbound, (runtimeWhatsAppOutbound) => runtimeWhatsAppOutbound.sendMessageWhatsApp); +const bindWhatsAppOutboundMethod = createLazyRuntimeMethodBinder(loadWebOutbound); +const bindWhatsAppLoginMethod = createLazyRuntimeMethodBinder(loadWebLogin); -const sendPollWhatsAppLazy = createLazyRuntimeMethod< - RuntimeWhatsAppOutbound, - Parameters, - ReturnType ->(loadWebOutbound, (runtimeWhatsAppOutbound) => runtimeWhatsAppOutbound.sendPollWhatsApp); - -const loginWebLazy = createLazyRuntimeMethod< - RuntimeWhatsAppLogin, - Parameters, - ReturnType ->(loadWebLogin, (runtimeWhatsAppLogin) => runtimeWhatsAppLogin.loginWeb); +const sendMessageWhatsAppLazy = bindWhatsAppOutboundMethod( + (runtimeWhatsAppOutbound) => runtimeWhatsAppOutbound.sendMessageWhatsApp, +); +const sendPollWhatsAppLazy = bindWhatsAppOutboundMethod( + (runtimeWhatsAppOutbound) => runtimeWhatsAppOutbound.sendPollWhatsApp, +); +const loginWebLazy = bindWhatsAppLoginMethod( + (runtimeWhatsAppLogin) => runtimeWhatsAppLogin.loginWeb, +); const startWebLoginWithQrLazy: PluginRuntime["channel"]["whatsapp"]["startWebLoginWithQr"] = async ( ...args diff --git a/src/shared/lazy-runtime.ts b/src/shared/lazy-runtime.ts index 3edaa865f50..cbbccfe7dec 100644 --- a/src/shared/lazy-runtime.ts +++ b/src/shared/lazy-runtime.ts @@ -19,3 +19,11 @@ export function createLazyRuntimeMethod(load: () => Promise) { + return function ( + select: (surface: TSurface) => (...args: TArgs) => TResult, + ): (...args: TArgs) => Promise> { + return createLazyRuntimeMethod(load, select); + }; +}