refactor: consolidate lazy runtime surfaces

This commit is contained in:
Peter Steinberger
2026-03-17 00:58:46 -07:00
parent 449127b474
commit 9648e7fecb
47 changed files with 602 additions and 730 deletions

View File

@@ -9,123 +9,121 @@ import {
setThreadBindingMaxAgeBySessionKey,
unbindThreadBindingsBySessionKey,
} from "../../../extensions/discord/src/monitor/thread-bindings.js";
import { createLazyRuntimeMethod, 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;
let runtimeDiscordOpsPromise: Promise<RuntimeDiscordOps> | null = null;
const loadRuntimeDiscordOps = createLazyRuntimeSurface(
() => import("./runtime-discord-ops.runtime.js"),
({ runtimeDiscordOps }) => runtimeDiscordOps,
);
function loadRuntimeDiscordOps() {
runtimeDiscordOpsPromise ??= import("./runtime-discord-ops.runtime.js").then(
({ runtimeDiscordOps }) => runtimeDiscordOps,
);
return runtimeDiscordOpsPromise;
}
const auditChannelPermissionsLazy = createLazyRuntimeMethod<
RuntimeDiscordOps,
Parameters<PluginRuntimeChannel["discord"]["auditChannelPermissions"]>,
ReturnType<PluginRuntimeChannel["discord"]["auditChannelPermissions"]>
>(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.auditChannelPermissions);
const auditChannelPermissionsLazy: PluginRuntimeChannel["discord"]["auditChannelPermissions"] =
async (...args) => {
const runtimeDiscordOps = await loadRuntimeDiscordOps();
return runtimeDiscordOps.auditChannelPermissions(...args);
};
const listDirectoryGroupsLiveLazy = createLazyRuntimeMethod<
RuntimeDiscordOps,
Parameters<PluginRuntimeChannel["discord"]["listDirectoryGroupsLive"]>,
ReturnType<PluginRuntimeChannel["discord"]["listDirectoryGroupsLive"]>
>(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.listDirectoryGroupsLive);
const listDirectoryGroupsLiveLazy: PluginRuntimeChannel["discord"]["listDirectoryGroupsLive"] =
async (...args) => {
const runtimeDiscordOps = await loadRuntimeDiscordOps();
return runtimeDiscordOps.listDirectoryGroupsLive(...args);
};
const listDirectoryPeersLiveLazy = createLazyRuntimeMethod<
RuntimeDiscordOps,
Parameters<PluginRuntimeChannel["discord"]["listDirectoryPeersLive"]>,
ReturnType<PluginRuntimeChannel["discord"]["listDirectoryPeersLive"]>
>(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.listDirectoryPeersLive);
const listDirectoryPeersLiveLazy: PluginRuntimeChannel["discord"]["listDirectoryPeersLive"] =
async (...args) => {
const runtimeDiscordOps = await loadRuntimeDiscordOps();
return runtimeDiscordOps.listDirectoryPeersLive(...args);
};
const probeDiscordLazy = createLazyRuntimeMethod<
RuntimeDiscordOps,
Parameters<PluginRuntimeChannel["discord"]["probeDiscord"]>,
ReturnType<PluginRuntimeChannel["discord"]["probeDiscord"]>
>(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.probeDiscord);
const probeDiscordLazy: PluginRuntimeChannel["discord"]["probeDiscord"] = async (...args) => {
const runtimeDiscordOps = await loadRuntimeDiscordOps();
return runtimeDiscordOps.probeDiscord(...args);
};
const resolveChannelAllowlistLazy = createLazyRuntimeMethod<
RuntimeDiscordOps,
Parameters<PluginRuntimeChannel["discord"]["resolveChannelAllowlist"]>,
ReturnType<PluginRuntimeChannel["discord"]["resolveChannelAllowlist"]>
>(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.resolveChannelAllowlist);
const resolveChannelAllowlistLazy: PluginRuntimeChannel["discord"]["resolveChannelAllowlist"] =
async (...args) => {
const runtimeDiscordOps = await loadRuntimeDiscordOps();
return runtimeDiscordOps.resolveChannelAllowlist(...args);
};
const resolveUserAllowlistLazy = createLazyRuntimeMethod<
RuntimeDiscordOps,
Parameters<PluginRuntimeChannel["discord"]["resolveUserAllowlist"]>,
ReturnType<PluginRuntimeChannel["discord"]["resolveUserAllowlist"]>
>(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.resolveUserAllowlist);
const resolveUserAllowlistLazy: PluginRuntimeChannel["discord"]["resolveUserAllowlist"] = async (
...args
) => {
const runtimeDiscordOps = await loadRuntimeDiscordOps();
return runtimeDiscordOps.resolveUserAllowlist(...args);
};
const sendComponentMessageLazy = createLazyRuntimeMethod<
RuntimeDiscordOps,
Parameters<PluginRuntimeChannel["discord"]["sendComponentMessage"]>,
ReturnType<PluginRuntimeChannel["discord"]["sendComponentMessage"]>
>(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.sendComponentMessage);
const sendComponentMessageLazy: PluginRuntimeChannel["discord"]["sendComponentMessage"] = async (
...args
) => {
const runtimeDiscordOps = await loadRuntimeDiscordOps();
return runtimeDiscordOps.sendComponentMessage(...args);
};
const sendMessageDiscordLazy = createLazyRuntimeMethod<
RuntimeDiscordOps,
Parameters<PluginRuntimeChannel["discord"]["sendMessageDiscord"]>,
ReturnType<PluginRuntimeChannel["discord"]["sendMessageDiscord"]>
>(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.sendMessageDiscord);
const sendMessageDiscordLazy: PluginRuntimeChannel["discord"]["sendMessageDiscord"] = async (
...args
) => {
const runtimeDiscordOps = await loadRuntimeDiscordOps();
return runtimeDiscordOps.sendMessageDiscord(...args);
};
const sendPollDiscordLazy = createLazyRuntimeMethod<
RuntimeDiscordOps,
Parameters<PluginRuntimeChannel["discord"]["sendPollDiscord"]>,
ReturnType<PluginRuntimeChannel["discord"]["sendPollDiscord"]>
>(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.sendPollDiscord);
const sendPollDiscordLazy: PluginRuntimeChannel["discord"]["sendPollDiscord"] = async (...args) => {
const runtimeDiscordOps = await loadRuntimeDiscordOps();
return runtimeDiscordOps.sendPollDiscord(...args);
};
const monitorDiscordProviderLazy = createLazyRuntimeMethod<
RuntimeDiscordOps,
Parameters<PluginRuntimeChannel["discord"]["monitorDiscordProvider"]>,
ReturnType<PluginRuntimeChannel["discord"]["monitorDiscordProvider"]>
>(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.monitorDiscordProvider);
const monitorDiscordProviderLazy: PluginRuntimeChannel["discord"]["monitorDiscordProvider"] =
async (...args) => {
const runtimeDiscordOps = await loadRuntimeDiscordOps();
return runtimeDiscordOps.monitorDiscordProvider(...args);
};
const sendTypingDiscordLazy = createLazyRuntimeMethod<
RuntimeDiscordOps,
Parameters<PluginRuntimeChannel["discord"]["typing"]["pulse"]>,
ReturnType<PluginRuntimeChannel["discord"]["typing"]["pulse"]>
>(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.typing.pulse);
const sendTypingDiscordLazy: PluginRuntimeChannel["discord"]["typing"]["pulse"] = async (
...args
) => {
const runtimeDiscordOps = await loadRuntimeDiscordOps();
return runtimeDiscordOps.typing.pulse(...args);
};
const editMessageDiscordLazy = createLazyRuntimeMethod<
RuntimeDiscordOps,
Parameters<PluginRuntimeChannel["discord"]["conversationActions"]["editMessage"]>,
ReturnType<PluginRuntimeChannel["discord"]["conversationActions"]["editMessage"]>
>(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.conversationActions.editMessage);
const editMessageDiscordLazy: PluginRuntimeChannel["discord"]["conversationActions"]["editMessage"] =
async (...args) => {
const runtimeDiscordOps = await loadRuntimeDiscordOps();
return runtimeDiscordOps.conversationActions.editMessage(...args);
};
const deleteMessageDiscordLazy = createLazyRuntimeMethod<
RuntimeDiscordOps,
Parameters<PluginRuntimeChannel["discord"]["conversationActions"]["deleteMessage"]>,
ReturnType<PluginRuntimeChannel["discord"]["conversationActions"]["deleteMessage"]>
>(
loadRuntimeDiscordOps,
(runtimeDiscordOps) => runtimeDiscordOps.conversationActions.deleteMessage,
);
const deleteMessageDiscordLazy: PluginRuntimeChannel["discord"]["conversationActions"]["deleteMessage"] =
async (...args) => {
const runtimeDiscordOps = await loadRuntimeDiscordOps();
return runtimeDiscordOps.conversationActions.deleteMessage(...args);
};
const pinMessageDiscordLazy = createLazyRuntimeMethod<
RuntimeDiscordOps,
Parameters<PluginRuntimeChannel["discord"]["conversationActions"]["pinMessage"]>,
ReturnType<PluginRuntimeChannel["discord"]["conversationActions"]["pinMessage"]>
>(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.conversationActions.pinMessage);
const pinMessageDiscordLazy: PluginRuntimeChannel["discord"]["conversationActions"]["pinMessage"] =
async (...args) => {
const runtimeDiscordOps = await loadRuntimeDiscordOps();
return runtimeDiscordOps.conversationActions.pinMessage(...args);
};
const unpinMessageDiscordLazy = createLazyRuntimeMethod<
RuntimeDiscordOps,
Parameters<PluginRuntimeChannel["discord"]["conversationActions"]["unpinMessage"]>,
ReturnType<PluginRuntimeChannel["discord"]["conversationActions"]["unpinMessage"]>
>(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.conversationActions.unpinMessage);
const unpinMessageDiscordLazy: PluginRuntimeChannel["discord"]["conversationActions"]["unpinMessage"] =
async (...args) => {
const runtimeDiscordOps = await loadRuntimeDiscordOps();
return runtimeDiscordOps.conversationActions.unpinMessage(...args);
};
const createThreadDiscordLazy = createLazyRuntimeMethod<
RuntimeDiscordOps,
Parameters<PluginRuntimeChannel["discord"]["conversationActions"]["createThread"]>,
ReturnType<PluginRuntimeChannel["discord"]["conversationActions"]["createThread"]>
>(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.conversationActions.createThread);
const createThreadDiscordLazy: PluginRuntimeChannel["discord"]["conversationActions"]["createThread"] =
async (...args) => {
const runtimeDiscordOps = await loadRuntimeDiscordOps();
return runtimeDiscordOps.conversationActions.createThread(...args);
};
const editChannelDiscordLazy: PluginRuntimeChannel["discord"]["conversationActions"]["editChannel"] =
async (...args) => {
const runtimeDiscordOps = await loadRuntimeDiscordOps();
return runtimeDiscordOps.conversationActions.editChannel(...args);
};
const editChannelDiscordLazy = createLazyRuntimeMethod<
RuntimeDiscordOps,
Parameters<PluginRuntimeChannel["discord"]["conversationActions"]["editChannel"]>,
ReturnType<PluginRuntimeChannel["discord"]["conversationActions"]["editChannel"]>
>(loadRuntimeDiscordOps, (runtimeDiscordOps) => runtimeDiscordOps.conversationActions.editChannel);
export function createRuntimeDiscord(): PluginRuntimeChannel["discord"] {
return {

View File

@@ -1,65 +1,60 @@
import { createLazyRuntimeMethod, createLazyRuntimeSurface } from "../../shared/lazy-runtime.js";
import type { PluginRuntimeChannel } from "./types-channel.js";
type RuntimeSlackOps = typeof import("./runtime-slack-ops.runtime.js").runtimeSlackOps;
let runtimeSlackOpsPromise: Promise<RuntimeSlackOps> | null = null;
const loadRuntimeSlackOps = createLazyRuntimeSurface(
() => import("./runtime-slack-ops.runtime.js"),
({ runtimeSlackOps }) => runtimeSlackOps,
);
function loadRuntimeSlackOps() {
runtimeSlackOpsPromise ??= import("./runtime-slack-ops.runtime.js").then(
({ runtimeSlackOps }) => runtimeSlackOps,
);
return runtimeSlackOpsPromise;
}
const listDirectoryGroupsLiveLazy = createLazyRuntimeMethod<
RuntimeSlackOps,
Parameters<PluginRuntimeChannel["slack"]["listDirectoryGroupsLive"]>,
ReturnType<PluginRuntimeChannel["slack"]["listDirectoryGroupsLive"]>
>(loadRuntimeSlackOps, (runtimeSlackOps) => runtimeSlackOps.listDirectoryGroupsLive);
const listDirectoryGroupsLiveLazy: PluginRuntimeChannel["slack"]["listDirectoryGroupsLive"] =
async (...args) => {
const runtimeSlackOps = await loadRuntimeSlackOps();
return runtimeSlackOps.listDirectoryGroupsLive(...args);
};
const listDirectoryPeersLiveLazy = createLazyRuntimeMethod<
RuntimeSlackOps,
Parameters<PluginRuntimeChannel["slack"]["listDirectoryPeersLive"]>,
ReturnType<PluginRuntimeChannel["slack"]["listDirectoryPeersLive"]>
>(loadRuntimeSlackOps, (runtimeSlackOps) => runtimeSlackOps.listDirectoryPeersLive);
const listDirectoryPeersLiveLazy: PluginRuntimeChannel["slack"]["listDirectoryPeersLive"] = async (
...args
) => {
const runtimeSlackOps = await loadRuntimeSlackOps();
return runtimeSlackOps.listDirectoryPeersLive(...args);
};
const probeSlackLazy = createLazyRuntimeMethod<
RuntimeSlackOps,
Parameters<PluginRuntimeChannel["slack"]["probeSlack"]>,
ReturnType<PluginRuntimeChannel["slack"]["probeSlack"]>
>(loadRuntimeSlackOps, (runtimeSlackOps) => runtimeSlackOps.probeSlack);
const probeSlackLazy: PluginRuntimeChannel["slack"]["probeSlack"] = async (...args) => {
const runtimeSlackOps = await loadRuntimeSlackOps();
return runtimeSlackOps.probeSlack(...args);
};
const resolveChannelAllowlistLazy = createLazyRuntimeMethod<
RuntimeSlackOps,
Parameters<PluginRuntimeChannel["slack"]["resolveChannelAllowlist"]>,
ReturnType<PluginRuntimeChannel["slack"]["resolveChannelAllowlist"]>
>(loadRuntimeSlackOps, (runtimeSlackOps) => runtimeSlackOps.resolveChannelAllowlist);
const resolveChannelAllowlistLazy: PluginRuntimeChannel["slack"]["resolveChannelAllowlist"] =
async (...args) => {
const runtimeSlackOps = await loadRuntimeSlackOps();
return runtimeSlackOps.resolveChannelAllowlist(...args);
};
const resolveUserAllowlistLazy = createLazyRuntimeMethod<
RuntimeSlackOps,
Parameters<PluginRuntimeChannel["slack"]["resolveUserAllowlist"]>,
ReturnType<PluginRuntimeChannel["slack"]["resolveUserAllowlist"]>
>(loadRuntimeSlackOps, (runtimeSlackOps) => runtimeSlackOps.resolveUserAllowlist);
const resolveUserAllowlistLazy: PluginRuntimeChannel["slack"]["resolveUserAllowlist"] = async (
...args
) => {
const runtimeSlackOps = await loadRuntimeSlackOps();
return runtimeSlackOps.resolveUserAllowlist(...args);
};
const sendMessageSlackLazy = createLazyRuntimeMethod<
RuntimeSlackOps,
Parameters<PluginRuntimeChannel["slack"]["sendMessageSlack"]>,
ReturnType<PluginRuntimeChannel["slack"]["sendMessageSlack"]>
>(loadRuntimeSlackOps, (runtimeSlackOps) => runtimeSlackOps.sendMessageSlack);
const sendMessageSlackLazy: PluginRuntimeChannel["slack"]["sendMessageSlack"] = async (...args) => {
const runtimeSlackOps = await loadRuntimeSlackOps();
return runtimeSlackOps.sendMessageSlack(...args);
};
const monitorSlackProviderLazy = createLazyRuntimeMethod<
RuntimeSlackOps,
Parameters<PluginRuntimeChannel["slack"]["monitorSlackProvider"]>,
ReturnType<PluginRuntimeChannel["slack"]["monitorSlackProvider"]>
>(loadRuntimeSlackOps, (runtimeSlackOps) => runtimeSlackOps.monitorSlackProvider);
const monitorSlackProviderLazy: PluginRuntimeChannel["slack"]["monitorSlackProvider"] = async (
...args
) => {
const runtimeSlackOps = await loadRuntimeSlackOps();
return runtimeSlackOps.monitorSlackProvider(...args);
};
const handleSlackActionLazy: PluginRuntimeChannel["slack"]["handleSlackAction"] = async (
...args
) => {
const runtimeSlackOps = await loadRuntimeSlackOps();
return runtimeSlackOps.handleSlackAction(...args);
};
const handleSlackActionLazy = createLazyRuntimeMethod<
RuntimeSlackOps,
Parameters<PluginRuntimeChannel["slack"]["handleSlackAction"]>,
ReturnType<PluginRuntimeChannel["slack"]["handleSlackAction"]>
>(loadRuntimeSlackOps, (runtimeSlackOps) => runtimeSlackOps.handleSlackAction);
export function createRuntimeSlack(): PluginRuntimeChannel["slack"] {
return {

View File

@@ -5,94 +5,106 @@ 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 { createTelegramTypingLease } from "./runtime-telegram-typing.js";
import type { PluginRuntimeChannel } from "./types-channel.js";
type RuntimeTelegramOps = typeof import("./runtime-telegram-ops.runtime.js").runtimeTelegramOps;
let runtimeTelegramOpsPromise: Promise<RuntimeTelegramOps> | null = null;
const loadRuntimeTelegramOps = createLazyRuntimeSurface(
() => import("./runtime-telegram-ops.runtime.js"),
({ runtimeTelegramOps }) => runtimeTelegramOps,
);
function loadRuntimeTelegramOps() {
runtimeTelegramOpsPromise ??= import("./runtime-telegram-ops.runtime.js").then(
({ runtimeTelegramOps }) => runtimeTelegramOps,
);
return runtimeTelegramOpsPromise;
}
const auditGroupMembershipLazy = createLazyRuntimeMethod<
RuntimeTelegramOps,
Parameters<PluginRuntimeChannel["telegram"]["auditGroupMembership"]>,
ReturnType<PluginRuntimeChannel["telegram"]["auditGroupMembership"]>
>(loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.auditGroupMembership);
const auditGroupMembershipLazy: PluginRuntimeChannel["telegram"]["auditGroupMembership"] = async (
...args
) => {
const runtimeTelegramOps = await loadRuntimeTelegramOps();
return runtimeTelegramOps.auditGroupMembership(...args);
};
const probeTelegramLazy = createLazyRuntimeMethod<
RuntimeTelegramOps,
Parameters<PluginRuntimeChannel["telegram"]["probeTelegram"]>,
ReturnType<PluginRuntimeChannel["telegram"]["probeTelegram"]>
>(loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.probeTelegram);
const probeTelegramLazy: PluginRuntimeChannel["telegram"]["probeTelegram"] = async (...args) => {
const runtimeTelegramOps = await loadRuntimeTelegramOps();
return runtimeTelegramOps.probeTelegram(...args);
};
const sendMessageTelegramLazy = createLazyRuntimeMethod<
RuntimeTelegramOps,
Parameters<PluginRuntimeChannel["telegram"]["sendMessageTelegram"]>,
ReturnType<PluginRuntimeChannel["telegram"]["sendMessageTelegram"]>
>(loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.sendMessageTelegram);
const sendMessageTelegramLazy: PluginRuntimeChannel["telegram"]["sendMessageTelegram"] = async (
...args
) => {
const runtimeTelegramOps = await loadRuntimeTelegramOps();
return runtimeTelegramOps.sendMessageTelegram(...args);
};
const sendPollTelegramLazy = createLazyRuntimeMethod<
RuntimeTelegramOps,
Parameters<PluginRuntimeChannel["telegram"]["sendPollTelegram"]>,
ReturnType<PluginRuntimeChannel["telegram"]["sendPollTelegram"]>
>(loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.sendPollTelegram);
const sendPollTelegramLazy: PluginRuntimeChannel["telegram"]["sendPollTelegram"] = async (
...args
) => {
const runtimeTelegramOps = await loadRuntimeTelegramOps();
return runtimeTelegramOps.sendPollTelegram(...args);
};
const monitorTelegramProviderLazy = createLazyRuntimeMethod<
RuntimeTelegramOps,
Parameters<PluginRuntimeChannel["telegram"]["monitorTelegramProvider"]>,
ReturnType<PluginRuntimeChannel["telegram"]["monitorTelegramProvider"]>
>(loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.monitorTelegramProvider);
const monitorTelegramProviderLazy: PluginRuntimeChannel["telegram"]["monitorTelegramProvider"] =
async (...args) => {
const runtimeTelegramOps = await loadRuntimeTelegramOps();
return runtimeTelegramOps.monitorTelegramProvider(...args);
};
const sendTypingTelegramLazy = createLazyRuntimeMethod<
RuntimeTelegramOps,
Parameters<PluginRuntimeChannel["telegram"]["typing"]["pulse"]>,
ReturnType<PluginRuntimeChannel["telegram"]["typing"]["pulse"]>
>(loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.typing.pulse);
const sendTypingTelegramLazy: PluginRuntimeChannel["telegram"]["typing"]["pulse"] = async (
...args
) => {
const runtimeTelegramOps = await loadRuntimeTelegramOps();
return runtimeTelegramOps.typing.pulse(...args);
};
const editMessageTelegramLazy = createLazyRuntimeMethod<
RuntimeTelegramOps,
Parameters<PluginRuntimeChannel["telegram"]["conversationActions"]["editMessage"]>,
ReturnType<PluginRuntimeChannel["telegram"]["conversationActions"]["editMessage"]>
>(
loadRuntimeTelegramOps,
(runtimeTelegramOps) => runtimeTelegramOps.conversationActions.editMessage,
);
const editMessageTelegramLazy: PluginRuntimeChannel["telegram"]["conversationActions"]["editMessage"] =
async (...args) => {
const runtimeTelegramOps = await loadRuntimeTelegramOps();
return runtimeTelegramOps.conversationActions.editMessage(...args);
};
const editMessageReplyMarkupTelegramLazy = createLazyRuntimeMethod<
RuntimeTelegramOps,
Parameters<PluginRuntimeChannel["telegram"]["conversationActions"]["editReplyMarkup"]>,
ReturnType<PluginRuntimeChannel["telegram"]["conversationActions"]["editReplyMarkup"]>
>(
loadRuntimeTelegramOps,
(runtimeTelegramOps) => runtimeTelegramOps.conversationActions.editReplyMarkup,
);
const editMessageReplyMarkupTelegramLazy: PluginRuntimeChannel["telegram"]["conversationActions"]["editReplyMarkup"] =
async (...args) => {
const runtimeTelegramOps = await loadRuntimeTelegramOps();
return runtimeTelegramOps.conversationActions.editReplyMarkup(...args);
};
const deleteMessageTelegramLazy = createLazyRuntimeMethod<
RuntimeTelegramOps,
Parameters<PluginRuntimeChannel["telegram"]["conversationActions"]["deleteMessage"]>,
ReturnType<PluginRuntimeChannel["telegram"]["conversationActions"]["deleteMessage"]>
>(
loadRuntimeTelegramOps,
(runtimeTelegramOps) => runtimeTelegramOps.conversationActions.deleteMessage,
);
const deleteMessageTelegramLazy: PluginRuntimeChannel["telegram"]["conversationActions"]["deleteMessage"] =
async (...args) => {
const runtimeTelegramOps = await loadRuntimeTelegramOps();
return runtimeTelegramOps.conversationActions.deleteMessage(...args);
};
const renameForumTopicTelegramLazy = createLazyRuntimeMethod<
RuntimeTelegramOps,
Parameters<PluginRuntimeChannel["telegram"]["conversationActions"]["renameTopic"]>,
ReturnType<PluginRuntimeChannel["telegram"]["conversationActions"]["renameTopic"]>
>(
loadRuntimeTelegramOps,
(runtimeTelegramOps) => runtimeTelegramOps.conversationActions.renameTopic,
);
const renameForumTopicTelegramLazy: PluginRuntimeChannel["telegram"]["conversationActions"]["renameTopic"] =
async (...args) => {
const runtimeTelegramOps = await loadRuntimeTelegramOps();
return runtimeTelegramOps.conversationActions.renameTopic(...args);
};
const pinMessageTelegramLazy = createLazyRuntimeMethod<
RuntimeTelegramOps,
Parameters<PluginRuntimeChannel["telegram"]["conversationActions"]["pinMessage"]>,
ReturnType<PluginRuntimeChannel["telegram"]["conversationActions"]["pinMessage"]>
>(
loadRuntimeTelegramOps,
(runtimeTelegramOps) => runtimeTelegramOps.conversationActions.pinMessage,
);
const pinMessageTelegramLazy: PluginRuntimeChannel["telegram"]["conversationActions"]["pinMessage"] =
async (...args) => {
const runtimeTelegramOps = await loadRuntimeTelegramOps();
return runtimeTelegramOps.conversationActions.pinMessage(...args);
};
const unpinMessageTelegramLazy: PluginRuntimeChannel["telegram"]["conversationActions"]["unpinMessage"] =
async (...args) => {
const runtimeTelegramOps = await loadRuntimeTelegramOps();
return runtimeTelegramOps.conversationActions.unpinMessage(...args);
};
const unpinMessageTelegramLazy = createLazyRuntimeMethod<
RuntimeTelegramOps,
Parameters<PluginRuntimeChannel["telegram"]["conversationActions"]["unpinMessage"]>,
ReturnType<PluginRuntimeChannel["telegram"]["conversationActions"]["unpinMessage"]>
>(
loadRuntimeTelegramOps,
(runtimeTelegramOps) => runtimeTelegramOps.conversationActions.unpinMessage,
);
export function createRuntimeTelegram(): PluginRuntimeChannel["telegram"] {
return {

View File

@@ -6,6 +6,7 @@ import {
readWebSelfId,
webAuthExists,
} from "../../../extensions/whatsapp/src/auth-store.js";
import { createLazyRuntimeMethod, createLazyRuntimeSurface } from "../../shared/lazy-runtime.js";
import { createRuntimeWhatsAppLoginTool } from "./runtime-whatsapp-login-tool.js";
import type { PluginRuntime } from "./types.js";
@@ -14,24 +15,33 @@ type RuntimeWhatsAppOutbound =
type RuntimeWhatsAppLogin =
typeof import("./runtime-whatsapp-login.runtime.js").runtimeWhatsAppLogin;
const sendMessageWhatsAppLazy: PluginRuntime["channel"]["whatsapp"]["sendMessageWhatsApp"] = async (
...args
) => {
const runtimeWhatsAppOutbound = await loadWebOutbound();
return runtimeWhatsAppOutbound.sendMessageWhatsApp(...args);
};
const loadWebOutbound = createLazyRuntimeSurface(
() => import("./runtime-whatsapp-outbound.runtime.js"),
({ runtimeWhatsAppOutbound }) => runtimeWhatsAppOutbound,
);
const sendPollWhatsAppLazy: PluginRuntime["channel"]["whatsapp"]["sendPollWhatsApp"] = async (
...args
) => {
const runtimeWhatsAppOutbound = await loadWebOutbound();
return runtimeWhatsAppOutbound.sendPollWhatsApp(...args);
};
const loadWebLogin = createLazyRuntimeSurface(
() => import("./runtime-whatsapp-login.runtime.js"),
({ runtimeWhatsAppLogin }) => runtimeWhatsAppLogin,
);
const loginWebLazy: PluginRuntime["channel"]["whatsapp"]["loginWeb"] = async (...args) => {
const runtimeWhatsAppLogin = await loadWebLogin();
return runtimeWhatsAppLogin.loginWeb(...args);
};
const sendMessageWhatsAppLazy = createLazyRuntimeMethod<
RuntimeWhatsAppOutbound,
Parameters<PluginRuntime["channel"]["whatsapp"]["sendMessageWhatsApp"]>,
ReturnType<PluginRuntime["channel"]["whatsapp"]["sendMessageWhatsApp"]>
>(loadWebOutbound, (runtimeWhatsAppOutbound) => runtimeWhatsAppOutbound.sendMessageWhatsApp);
const sendPollWhatsAppLazy = createLazyRuntimeMethod<
RuntimeWhatsAppOutbound,
Parameters<PluginRuntime["channel"]["whatsapp"]["sendPollWhatsApp"]>,
ReturnType<PluginRuntime["channel"]["whatsapp"]["sendPollWhatsApp"]>
>(loadWebOutbound, (runtimeWhatsAppOutbound) => runtimeWhatsAppOutbound.sendPollWhatsApp);
const loginWebLazy = createLazyRuntimeMethod<
RuntimeWhatsAppLogin,
Parameters<PluginRuntime["channel"]["whatsapp"]["loginWeb"]>,
ReturnType<PluginRuntime["channel"]["whatsapp"]["loginWeb"]>
>(loadWebLogin, (runtimeWhatsAppLogin) => runtimeWhatsAppLogin.loginWeb);
const startWebLoginWithQrLazy: PluginRuntime["channel"]["whatsapp"]["startWebLoginWithQr"] = async (
...args
@@ -64,26 +74,10 @@ let webLoginQrPromise: Promise<
typeof import("../../../extensions/whatsapp/src/login-qr.js")
> | null = null;
let webChannelPromise: Promise<typeof import("../../channels/web/index.js")> | null = null;
let webOutboundPromise: Promise<RuntimeWhatsAppOutbound> | null = null;
let webLoginPromise: Promise<RuntimeWhatsAppLogin> | null = null;
let whatsappActionsPromise: Promise<
typeof import("../../agents/tools/whatsapp-actions.js")
> | null = null;
function loadWebOutbound() {
webOutboundPromise ??= import("./runtime-whatsapp-outbound.runtime.js").then(
({ runtimeWhatsAppOutbound }) => runtimeWhatsAppOutbound,
);
return webOutboundPromise;
}
function loadWebLogin() {
webLoginPromise ??= import("./runtime-whatsapp-login.runtime.js").then(
({ runtimeWhatsAppLogin }) => runtimeWhatsAppLogin,
);
return webLoginPromise;
}
function loadWebLoginQr() {
webLoginQrPromise ??= import("../../../extensions/whatsapp/src/login-qr.js");
return webLoginQrPromise;