mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-22 22:52:03 +00:00
refactor(plugin-sdk): remove channel-specific sdk shims
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
import {
|
||||
monitorIMessageProvider,
|
||||
probeIMessage,
|
||||
sendMessageIMessage,
|
||||
} from "../../plugin-sdk/imessage.js";
|
||||
import type { PluginRuntimeChannel } from "./types-channel.js";
|
||||
|
||||
export function createRuntimeIMessage(): PluginRuntimeChannel["imessage"] {
|
||||
return {
|
||||
monitorIMessageProvider,
|
||||
probeIMessage,
|
||||
sendMessageIMessage,
|
||||
};
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
import {
|
||||
auditTelegramGroupMembership as auditTelegramGroupMembershipImpl,
|
||||
monitorTelegramProvider as monitorTelegramProviderImpl,
|
||||
probeTelegram as probeTelegramImpl,
|
||||
} from "../../plugin-sdk/telegram.js";
|
||||
import {
|
||||
deleteMessageTelegram as deleteMessageTelegramImpl,
|
||||
editMessageReplyMarkupTelegram as editMessageReplyMarkupTelegramImpl,
|
||||
editMessageTelegram as editMessageTelegramImpl,
|
||||
pinMessageTelegram as pinMessageTelegramImpl,
|
||||
renameForumTopicTelegram as renameForumTopicTelegramImpl,
|
||||
sendMessageTelegram as sendMessageTelegramImpl,
|
||||
sendPollTelegram as sendPollTelegramImpl,
|
||||
sendTypingTelegram as sendTypingTelegramImpl,
|
||||
unpinMessageTelegram as unpinMessageTelegramImpl,
|
||||
} from "../../plugin-sdk/telegram.js";
|
||||
import type { PluginRuntimeChannel } from "./types-channel.js";
|
||||
|
||||
type RuntimeTelegramOps = Pick<
|
||||
PluginRuntimeChannel["telegram"],
|
||||
| "auditGroupMembership"
|
||||
| "probeTelegram"
|
||||
| "sendMessageTelegram"
|
||||
| "sendPollTelegram"
|
||||
| "monitorTelegramProvider"
|
||||
> & {
|
||||
typing: Pick<PluginRuntimeChannel["telegram"]["typing"], "pulse">;
|
||||
conversationActions: Pick<
|
||||
PluginRuntimeChannel["telegram"]["conversationActions"],
|
||||
| "editMessage"
|
||||
| "editReplyMarkup"
|
||||
| "deleteMessage"
|
||||
| "renameTopic"
|
||||
| "pinMessage"
|
||||
| "unpinMessage"
|
||||
>;
|
||||
};
|
||||
|
||||
export const runtimeTelegramOps = {
|
||||
auditGroupMembership: auditTelegramGroupMembershipImpl,
|
||||
probeTelegram: probeTelegramImpl,
|
||||
sendMessageTelegram: sendMessageTelegramImpl,
|
||||
sendPollTelegram: sendPollTelegramImpl,
|
||||
monitorTelegramProvider: monitorTelegramProviderImpl,
|
||||
typing: {
|
||||
pulse: sendTypingTelegramImpl,
|
||||
},
|
||||
conversationActions: {
|
||||
editMessage: editMessageTelegramImpl,
|
||||
editReplyMarkup: editMessageReplyMarkupTelegramImpl,
|
||||
deleteMessage: deleteMessageTelegramImpl,
|
||||
renameTopic: renameForumTopicTelegramImpl,
|
||||
pinMessage: pinMessageTelegramImpl,
|
||||
unpinMessage: unpinMessageTelegramImpl,
|
||||
},
|
||||
} satisfies RuntimeTelegramOps;
|
||||
@@ -1,101 +0,0 @@
|
||||
import {
|
||||
collectTelegramUnmentionedGroupIds,
|
||||
resolveTelegramToken,
|
||||
setTelegramThreadBindingIdleTimeoutBySessionKey,
|
||||
setTelegramThreadBindingMaxAgeBySessionKey,
|
||||
telegramMessageActions,
|
||||
} from "../../plugin-sdk/telegram.js";
|
||||
import {
|
||||
createLazyRuntimeMethodBinder,
|
||||
createLazyRuntimeSurface,
|
||||
} from "../../shared/lazy-runtime.js";
|
||||
import { createTelegramTypingLease } from "./runtime-telegram-typing.js";
|
||||
import type { PluginRuntimeChannel } from "./types-channel.js";
|
||||
|
||||
const loadRuntimeTelegramOps = createLazyRuntimeSurface(
|
||||
() => import("./runtime-telegram-ops.runtime.js"),
|
||||
({ runtimeTelegramOps }) => runtimeTelegramOps,
|
||||
);
|
||||
|
||||
const bindTelegramRuntimeMethod = createLazyRuntimeMethodBinder(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 = bindTelegramRuntimeMethod(
|
||||
(runtimeTelegramOps) => runtimeTelegramOps.conversationActions.editReplyMarkup,
|
||||
);
|
||||
const deleteMessageTelegramLazy = bindTelegramRuntimeMethod(
|
||||
(runtimeTelegramOps) => runtimeTelegramOps.conversationActions.deleteMessage,
|
||||
);
|
||||
const renameForumTopicTelegramLazy = bindTelegramRuntimeMethod(
|
||||
(runtimeTelegramOps) => runtimeTelegramOps.conversationActions.renameTopic,
|
||||
);
|
||||
const pinMessageTelegramLazy = bindTelegramRuntimeMethod(
|
||||
(runtimeTelegramOps) => runtimeTelegramOps.conversationActions.pinMessage,
|
||||
);
|
||||
const unpinMessageTelegramLazy = bindTelegramRuntimeMethod(
|
||||
(runtimeTelegramOps) => runtimeTelegramOps.conversationActions.unpinMessage,
|
||||
);
|
||||
|
||||
export function createRuntimeTelegram(): PluginRuntimeChannel["telegram"] {
|
||||
return {
|
||||
auditGroupMembership: auditGroupMembershipLazy,
|
||||
collectUnmentionedGroupIds: collectTelegramUnmentionedGroupIds,
|
||||
probeTelegram: probeTelegramLazy,
|
||||
resolveTelegramToken,
|
||||
sendMessageTelegram: sendMessageTelegramLazy,
|
||||
sendPollTelegram: sendPollTelegramLazy,
|
||||
monitorTelegramProvider: monitorTelegramProviderLazy,
|
||||
messageActions: telegramMessageActions,
|
||||
threadBindings: {
|
||||
setIdleTimeoutBySessionKey: setTelegramThreadBindingIdleTimeoutBySessionKey,
|
||||
setMaxAgeBySessionKey: setTelegramThreadBindingMaxAgeBySessionKey,
|
||||
},
|
||||
typing: {
|
||||
pulse: sendTypingTelegramLazy,
|
||||
start: async ({ to, accountId, cfg, intervalMs, messageThreadId }) =>
|
||||
await createTelegramTypingLease({
|
||||
to,
|
||||
accountId,
|
||||
cfg,
|
||||
intervalMs,
|
||||
messageThreadId,
|
||||
pulse: async ({ to, accountId, cfg, messageThreadId }) =>
|
||||
await sendTypingTelegramLazy(to, {
|
||||
accountId,
|
||||
cfg,
|
||||
messageThreadId,
|
||||
}),
|
||||
}),
|
||||
},
|
||||
conversationActions: {
|
||||
editMessage: editMessageTelegramLazy,
|
||||
editReplyMarkup: editMessageReplyMarkupTelegramLazy,
|
||||
clearReplyMarkup: async (chatIdInput, messageIdInput, opts = {}) =>
|
||||
await editMessageReplyMarkupTelegramLazy(chatIdInput, messageIdInput, [], opts),
|
||||
deleteMessage: deleteMessageTelegramLazy,
|
||||
renameTopic: renameForumTopicTelegramLazy,
|
||||
pinMessage: pinMessageTelegramLazy,
|
||||
unpinMessage: unpinMessageTelegramLazy,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -20,6 +20,15 @@ type UpsertChannelPairingRequestForAccount = (
|
||||
params: Omit<Parameters<UpsertChannelPairingRequest>[0], "accountId"> & { accountId: string },
|
||||
) => ReturnType<UpsertChannelPairingRequest>;
|
||||
|
||||
export type RuntimeThreadBindingLifecycleRecord =
|
||||
| import("../../infra/outbound/session-binding-service.js").SessionBindingRecord
|
||||
| {
|
||||
boundAt: number;
|
||||
lastActivityAt: number;
|
||||
idleTimeoutMs?: number;
|
||||
maxAgeMs?: number;
|
||||
};
|
||||
|
||||
export type PluginRuntimeChannel = {
|
||||
text: {
|
||||
chunkByNewline: typeof import("../../auto-reply/chunk.js").chunkByNewline;
|
||||
@@ -93,6 +102,23 @@ export type PluginRuntimeChannel = {
|
||||
shouldComputeCommandAuthorized: typeof import("../../auto-reply/command-detection.js").shouldComputeCommandAuthorized;
|
||||
shouldHandleTextCommands: typeof import("../../auto-reply/commands-registry.js").shouldHandleTextCommands;
|
||||
};
|
||||
outbound: {
|
||||
loadAdapter: typeof import("../../channels/plugins/outbound/load.js").loadChannelOutboundAdapter;
|
||||
};
|
||||
threadBindings: {
|
||||
setIdleTimeoutBySessionKey: (params: {
|
||||
channelId: "discord" | "matrix" | "telegram";
|
||||
targetSessionKey: string;
|
||||
accountId?: string;
|
||||
idleTimeoutMs: number;
|
||||
}) => RuntimeThreadBindingLifecycleRecord[];
|
||||
setMaxAgeBySessionKey: (params: {
|
||||
channelId: "discord" | "matrix" | "telegram";
|
||||
targetSessionKey: string;
|
||||
accountId?: string;
|
||||
maxAgeMs: number;
|
||||
}) => RuntimeThreadBindingLifecycleRecord[];
|
||||
};
|
||||
discord: {
|
||||
messageActions: typeof import("../../plugin-sdk/discord.js").discordMessageActions;
|
||||
auditChannelPermissions: typeof import("../../plugin-sdk/discord.js").auditDiscordChannelPermissions;
|
||||
@@ -146,53 +172,6 @@ export type PluginRuntimeChannel = {
|
||||
monitorSlackProvider: typeof import("../../plugin-sdk/slack.js").monitorSlackProvider;
|
||||
handleSlackAction: typeof import("../../plugin-sdk/slack.js").handleSlackAction;
|
||||
};
|
||||
telegram: {
|
||||
auditGroupMembership: typeof import("../../plugin-sdk/telegram.js").auditTelegramGroupMembership;
|
||||
collectUnmentionedGroupIds: typeof import("../../plugin-sdk/telegram.js").collectTelegramUnmentionedGroupIds;
|
||||
probeTelegram: typeof import("../../plugin-sdk/telegram.js").probeTelegram;
|
||||
resolveTelegramToken: typeof import("../../plugin-sdk/telegram.js").resolveTelegramToken;
|
||||
sendMessageTelegram: typeof import("../../plugin-sdk/telegram.js").sendMessageTelegram;
|
||||
sendPollTelegram: typeof import("../../plugin-sdk/telegram.js").sendPollTelegram;
|
||||
monitorTelegramProvider: typeof import("../../plugin-sdk/telegram.js").monitorTelegramProvider;
|
||||
messageActions: typeof import("../../plugin-sdk/telegram.js").telegramMessageActions;
|
||||
threadBindings: {
|
||||
setIdleTimeoutBySessionKey: typeof import("../../plugin-sdk/telegram.js").setTelegramThreadBindingIdleTimeoutBySessionKey;
|
||||
setMaxAgeBySessionKey: typeof import("../../plugin-sdk/telegram.js").setTelegramThreadBindingMaxAgeBySessionKey;
|
||||
};
|
||||
typing: {
|
||||
pulse: typeof import("../../plugin-sdk/telegram.js").sendTypingTelegram;
|
||||
start: (params: {
|
||||
to: string;
|
||||
accountId?: string;
|
||||
cfg?: ReturnType<typeof import("../../config/config.js").loadConfig>;
|
||||
intervalMs?: number;
|
||||
messageThreadId?: number;
|
||||
}) => Promise<{
|
||||
refresh: () => Promise<void>;
|
||||
stop: () => void;
|
||||
}>;
|
||||
};
|
||||
conversationActions: {
|
||||
editMessage: typeof import("../../plugin-sdk/telegram.js").editMessageTelegram;
|
||||
editReplyMarkup: typeof import("../../plugin-sdk/telegram.js").editMessageReplyMarkupTelegram;
|
||||
clearReplyMarkup: (
|
||||
chatIdInput: string | number,
|
||||
messageIdInput: string | number,
|
||||
opts?: {
|
||||
token?: string;
|
||||
accountId?: string;
|
||||
verbose?: boolean;
|
||||
api?: import("../../plugin-sdk/telegram.js").TelegramApiOverride;
|
||||
retry?: import("../../infra/retry.js").RetryConfig;
|
||||
cfg?: ReturnType<typeof import("../../config/config.js").loadConfig>;
|
||||
},
|
||||
) => Promise<{ ok: true; messageId: string; chatId: string }>;
|
||||
deleteMessage: typeof import("../../plugin-sdk/telegram.js").deleteMessageTelegram;
|
||||
renameTopic: typeof import("../../plugin-sdk/telegram.js").renameForumTopicTelegram;
|
||||
pinMessage: typeof import("../../plugin-sdk/telegram.js").pinMessageTelegram;
|
||||
unpinMessage: typeof import("../../plugin-sdk/telegram.js").unpinMessageTelegram;
|
||||
};
|
||||
};
|
||||
matrix: {
|
||||
threadBindings: {
|
||||
setIdleTimeoutBySessionKey: typeof import("../../plugin-sdk/matrix.js").setMatrixThreadBindingIdleTimeoutBySessionKey;
|
||||
@@ -205,11 +184,6 @@ export type PluginRuntimeChannel = {
|
||||
monitorSignalProvider: typeof import("../../plugin-sdk/signal.js").monitorSignalProvider;
|
||||
messageActions: typeof import("../../plugin-sdk/signal.js").signalMessageActions;
|
||||
};
|
||||
imessage: {
|
||||
monitorIMessageProvider: typeof import("../../plugin-sdk/imessage.js").monitorIMessageProvider;
|
||||
probeIMessage: typeof import("../../plugin-sdk/imessage.js").probeIMessage;
|
||||
sendMessageIMessage: typeof import("../../plugin-sdk/imessage.js").sendMessageIMessage;
|
||||
};
|
||||
whatsapp: {
|
||||
getActiveWebListener: typeof import("./runtime-whatsapp-boundary.js").getActiveWebListener;
|
||||
getWebAuthAgeMs: typeof import("./runtime-whatsapp-boundary.js").getWebAuthAgeMs;
|
||||
|
||||
Reference in New Issue
Block a user