mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-19 05:50:47 +00:00
refactor: dedupe channel plugin shared assembly
This commit is contained in:
@@ -1144,6 +1144,9 @@ Use SDK subpaths instead of the monolithic `openclaw/plugin-sdk` import when
|
||||
authoring plugins:
|
||||
|
||||
- `openclaw/plugin-sdk/core` for the smallest generic plugin-facing contract.
|
||||
It also carries small assembly helpers such as
|
||||
`definePluginEntry`, `defineChannelPluginEntry`, `defineSetupPluginEntry`,
|
||||
and `createChannelPluginBase` for bundled or third-party plugin entry wiring.
|
||||
- Domain subpaths such as `openclaw/plugin-sdk/channel-config-helpers`,
|
||||
`openclaw/plugin-sdk/channel-config-schema`,
|
||||
`openclaw/plugin-sdk/channel-policy`,
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
createScopedAccountConfigAccessors,
|
||||
createScopedChannelConfigBase,
|
||||
} from "openclaw/plugin-sdk/channel-config-helpers";
|
||||
import { createChannelPluginBase } from "openclaw/plugin-sdk/core";
|
||||
import {
|
||||
buildChannelConfigSchema,
|
||||
DiscordConfigSchema,
|
||||
@@ -58,12 +59,10 @@ export function createDiscordPluginBase(params: {
|
||||
| "config"
|
||||
| "setup"
|
||||
> {
|
||||
return {
|
||||
return createChannelPluginBase({
|
||||
id: DISCORD_CHANNEL,
|
||||
meta: {
|
||||
...getChatChannelMeta(DISCORD_CHANNEL),
|
||||
},
|
||||
setupWizard: discordSetupWizard,
|
||||
meta: { ...getChatChannelMeta(DISCORD_CHANNEL) },
|
||||
capabilities: {
|
||||
chatTypes: ["direct", "channel", "thread"],
|
||||
polls: true,
|
||||
@@ -90,5 +89,16 @@ export function createDiscordPluginBase(params: {
|
||||
...discordConfigAccessors,
|
||||
},
|
||||
setup: params.setup,
|
||||
};
|
||||
}) as Pick<
|
||||
ChannelPlugin<ResolvedDiscordAccount>,
|
||||
| "id"
|
||||
| "meta"
|
||||
| "setupWizard"
|
||||
| "capabilities"
|
||||
| "streaming"
|
||||
| "reload"
|
||||
| "configSchema"
|
||||
| "config"
|
||||
| "setup"
|
||||
>;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
buildAccountScopedDmSecurityPolicy,
|
||||
collectAllowlistProviderRestrictSendersWarnings,
|
||||
} from "openclaw/plugin-sdk/channel-policy";
|
||||
import { createChannelPluginBase } from "openclaw/plugin-sdk/core";
|
||||
import {
|
||||
buildChannelConfigSchema,
|
||||
DEFAULT_ACCOUNT_ID,
|
||||
@@ -47,7 +48,7 @@ export function createIMessagePluginBase(params: {
|
||||
| "security"
|
||||
| "setup"
|
||||
> {
|
||||
return {
|
||||
return createChannelPluginBase({
|
||||
id: IMESSAGE_CHANNEL,
|
||||
meta: {
|
||||
...getChatChannelMeta(IMESSAGE_CHANNEL),
|
||||
@@ -115,5 +116,16 @@ export function createIMessagePluginBase(params: {
|
||||
}),
|
||||
},
|
||||
setup: params.setup,
|
||||
};
|
||||
}) as Pick<
|
||||
ChannelPlugin<ResolvedIMessageAccount>,
|
||||
| "id"
|
||||
| "meta"
|
||||
| "setupWizard"
|
||||
| "capabilities"
|
||||
| "reload"
|
||||
| "configSchema"
|
||||
| "config"
|
||||
| "security"
|
||||
| "setup"
|
||||
>;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
buildAccountScopedDmSecurityPolicy,
|
||||
collectAllowlistProviderRestrictSendersWarnings,
|
||||
} from "openclaw/plugin-sdk/channel-policy";
|
||||
import { createChannelPluginBase } from "openclaw/plugin-sdk/core";
|
||||
import {
|
||||
buildChannelConfigSchema,
|
||||
DEFAULT_ACCOUNT_ID,
|
||||
@@ -59,7 +60,7 @@ export function createSignalPluginBase(params: {
|
||||
| "security"
|
||||
| "setup"
|
||||
> {
|
||||
return {
|
||||
return createChannelPluginBase({
|
||||
id: SIGNAL_CHANNEL,
|
||||
meta: {
|
||||
...getChatChannelMeta(SIGNAL_CHANNEL),
|
||||
@@ -129,5 +130,17 @@ export function createSignalPluginBase(params: {
|
||||
}),
|
||||
},
|
||||
setup: params.setup,
|
||||
};
|
||||
}) as Pick<
|
||||
ChannelPlugin<ResolvedSignalAccount>,
|
||||
| "id"
|
||||
| "meta"
|
||||
| "setupWizard"
|
||||
| "capabilities"
|
||||
| "streaming"
|
||||
| "reload"
|
||||
| "configSchema"
|
||||
| "config"
|
||||
| "security"
|
||||
| "setup"
|
||||
>;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
createScopedAccountConfigAccessors,
|
||||
createScopedChannelConfigBase,
|
||||
} from "openclaw/plugin-sdk/channel-config-helpers";
|
||||
import { createChannelPluginBase } from "openclaw/plugin-sdk/core";
|
||||
import {
|
||||
formatDocsLink,
|
||||
hasConfiguredSecretInput,
|
||||
@@ -176,7 +177,7 @@ export function createSlackPluginBase(params: {
|
||||
| "config"
|
||||
| "setup"
|
||||
> {
|
||||
return {
|
||||
return createChannelPluginBase({
|
||||
id: SLACK_CHANNEL,
|
||||
meta: {
|
||||
...getChatChannelMeta(SLACK_CHANNEL),
|
||||
@@ -220,5 +221,17 @@ export function createSlackPluginBase(params: {
|
||||
...slackConfigAccessors,
|
||||
},
|
||||
setup: params.setup,
|
||||
};
|
||||
}) as Pick<
|
||||
ChannelPlugin<ResolvedSlackAccount>,
|
||||
| "id"
|
||||
| "meta"
|
||||
| "setupWizard"
|
||||
| "capabilities"
|
||||
| "agentPrompt"
|
||||
| "streaming"
|
||||
| "reload"
|
||||
| "configSchema"
|
||||
| "config"
|
||||
| "setup"
|
||||
>;
|
||||
}
|
||||
|
||||
1776
extensions/telegram/src/bot-handlers.runtime.ts
Normal file
1776
extensions/telegram/src/bot-handlers.runtime.ts
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,7 @@ import {
|
||||
createScopedAccountConfigAccessors,
|
||||
createScopedChannelConfigBase,
|
||||
} from "openclaw/plugin-sdk/channel-config-helpers";
|
||||
import { createChannelPluginBase } from "openclaw/plugin-sdk/core";
|
||||
import {
|
||||
buildChannelConfigSchema,
|
||||
getChatChannelMeta,
|
||||
@@ -79,7 +80,7 @@ export function createTelegramPluginBase(params: {
|
||||
ChannelPlugin<ResolvedTelegramAccount>,
|
||||
"id" | "meta" | "setupWizard" | "capabilities" | "reload" | "configSchema" | "config" | "setup"
|
||||
> {
|
||||
return {
|
||||
return createChannelPluginBase({
|
||||
id: TELEGRAM_CHANNEL,
|
||||
meta: {
|
||||
...getChatChannelMeta(TELEGRAM_CHANNEL),
|
||||
@@ -133,5 +134,8 @@ export function createTelegramPluginBase(params: {
|
||||
...telegramConfigAccessors,
|
||||
},
|
||||
setup: params.setup,
|
||||
};
|
||||
}) as Pick<
|
||||
ChannelPlugin<ResolvedTelegramAccount>,
|
||||
"id" | "meta" | "setupWizard" | "capabilities" | "reload" | "configSchema" | "config" | "setup"
|
||||
>;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
collectAllowlistProviderGroupPolicyWarnings,
|
||||
collectOpenGroupPolicyRouteAllowlistWarnings,
|
||||
} from "openclaw/plugin-sdk/channel-policy";
|
||||
import { createChannelPluginBase } from "openclaw/plugin-sdk/core";
|
||||
import {
|
||||
buildChannelConfigSchema,
|
||||
DEFAULT_ACCOUNT_ID,
|
||||
@@ -96,7 +97,7 @@ export function createWhatsAppPluginBase(params: {
|
||||
| "setup"
|
||||
| "groups"
|
||||
> {
|
||||
return {
|
||||
return createChannelPluginBase({
|
||||
id: WHATSAPP_CHANNEL,
|
||||
meta: {
|
||||
...getChatChannelMeta(WHATSAPP_CHANNEL),
|
||||
@@ -218,5 +219,18 @@ export function createWhatsAppPluginBase(params: {
|
||||
resolveToolPolicy: resolveWhatsAppGroupToolPolicy,
|
||||
resolveGroupIntroHint: resolveWhatsAppGroupIntroHint,
|
||||
},
|
||||
};
|
||||
}) as Pick<
|
||||
ChannelPlugin<ResolvedWhatsAppAccount>,
|
||||
| "id"
|
||||
| "meta"
|
||||
| "setupWizard"
|
||||
| "capabilities"
|
||||
| "reload"
|
||||
| "gatewayMethods"
|
||||
| "configSchema"
|
||||
| "config"
|
||||
| "security"
|
||||
| "setup"
|
||||
| "groups"
|
||||
>;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { ChannelPlugin } from "../channels/plugins/types.plugin.js";
|
||||
import { getChatChannelMeta } from "../channels/registry.js";
|
||||
import { emptyPluginConfigSchema } from "../plugins/config-schema.js";
|
||||
import type { PluginRuntime } from "../plugins/runtime/types.js";
|
||||
import type {
|
||||
@@ -130,6 +131,42 @@ type DefinedPluginEntry = {
|
||||
register: NonNullable<OpenClawPluginDefinition["register"]>;
|
||||
} & Pick<OpenClawPluginDefinition, "kind">;
|
||||
|
||||
type CreateChannelPluginBaseOptions<TResolvedAccount> = {
|
||||
id: ChannelPlugin<TResolvedAccount>["id"];
|
||||
meta?: Partial<NonNullable<ChannelPlugin<TResolvedAccount>["meta"]>>;
|
||||
setupWizard?: NonNullable<ChannelPlugin<TResolvedAccount>["setupWizard"]>;
|
||||
capabilities?: ChannelPlugin<TResolvedAccount>["capabilities"];
|
||||
agentPrompt?: ChannelPlugin<TResolvedAccount>["agentPrompt"];
|
||||
streaming?: ChannelPlugin<TResolvedAccount>["streaming"];
|
||||
reload?: ChannelPlugin<TResolvedAccount>["reload"];
|
||||
gatewayMethods?: ChannelPlugin<TResolvedAccount>["gatewayMethods"];
|
||||
configSchema?: ChannelPlugin<TResolvedAccount>["configSchema"];
|
||||
config?: ChannelPlugin<TResolvedAccount>["config"];
|
||||
security?: ChannelPlugin<TResolvedAccount>["security"];
|
||||
setup: NonNullable<ChannelPlugin<TResolvedAccount>["setup"]>;
|
||||
groups?: ChannelPlugin<TResolvedAccount>["groups"];
|
||||
};
|
||||
|
||||
type CreatedChannelPluginBase<TResolvedAccount> = Pick<
|
||||
ChannelPlugin<TResolvedAccount>,
|
||||
"id" | "meta" | "setup"
|
||||
> &
|
||||
Partial<
|
||||
Pick<
|
||||
ChannelPlugin<TResolvedAccount>,
|
||||
| "setupWizard"
|
||||
| "capabilities"
|
||||
| "agentPrompt"
|
||||
| "streaming"
|
||||
| "reload"
|
||||
| "gatewayMethods"
|
||||
| "configSchema"
|
||||
| "config"
|
||||
| "security"
|
||||
| "groups"
|
||||
>
|
||||
>;
|
||||
|
||||
function resolvePluginConfigSchema(
|
||||
configSchema: DefinePluginEntryOptions["configSchema"] = emptyPluginConfigSchema,
|
||||
): OpenClawPluginConfigSchema {
|
||||
@@ -185,3 +222,27 @@ export function defineChannelPluginEntry<TPlugin extends ChannelPlugin>({
|
||||
export function defineSetupPluginEntry<TPlugin>(plugin: TPlugin) {
|
||||
return { plugin };
|
||||
}
|
||||
|
||||
// Shared base object for channel plugins that only need to override a few optional surfaces.
|
||||
export function createChannelPluginBase<TResolvedAccount>(
|
||||
params: CreateChannelPluginBaseOptions<TResolvedAccount>,
|
||||
): CreatedChannelPluginBase<TResolvedAccount> {
|
||||
return {
|
||||
id: params.id,
|
||||
meta: {
|
||||
...getChatChannelMeta(params.id as Parameters<typeof getChatChannelMeta>[0]),
|
||||
...params.meta,
|
||||
},
|
||||
...(params.setupWizard ? { setupWizard: params.setupWizard } : {}),
|
||||
...(params.capabilities ? { capabilities: params.capabilities } : {}),
|
||||
...(params.agentPrompt ? { agentPrompt: params.agentPrompt } : {}),
|
||||
...(params.streaming ? { streaming: params.streaming } : {}),
|
||||
...(params.reload ? { reload: params.reload } : {}),
|
||||
...(params.gatewayMethods ? { gatewayMethods: params.gatewayMethods } : {}),
|
||||
...(params.configSchema ? { configSchema: params.configSchema } : {}),
|
||||
...(params.config ? { config: params.config } : {}),
|
||||
...(params.security ? { security: params.security } : {}),
|
||||
...(params.groups ? { groups: params.groups } : {}),
|
||||
setup: params.setup,
|
||||
} as CreatedChannelPluginBase<TResolvedAccount>;
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ describe("plugin-sdk subpath exports", () => {
|
||||
expect(typeof coreSdk.definePluginEntry).toBe("function");
|
||||
expect(typeof coreSdk.defineChannelPluginEntry).toBe("function");
|
||||
expect(typeof coreSdk.defineSetupPluginEntry).toBe("function");
|
||||
expect(typeof coreSdk.createChannelPluginBase).toBe("function");
|
||||
expect(typeof coreSdk.optionalStringEnum).toBe("function");
|
||||
expect("runPassiveAccountLifecycle" in asExports(coreSdk)).toBe(false);
|
||||
expect("createLoggerBackedRuntime" in asExports(coreSdk)).toBe(false);
|
||||
|
||||
Reference in New Issue
Block a user