refactor: dedupe channel plugin shared assembly
This commit is contained in:
parent
3cc83cb81e
commit
cd5c2f4cb2
@ -1144,6 +1144,9 @@ Use SDK subpaths instead of the monolithic `openclaw/plugin-sdk` import when
|
|||||||
authoring plugins:
|
authoring plugins:
|
||||||
|
|
||||||
- `openclaw/plugin-sdk/core` for the smallest generic plugin-facing contract.
|
- `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`,
|
- Domain subpaths such as `openclaw/plugin-sdk/channel-config-helpers`,
|
||||||
`openclaw/plugin-sdk/channel-config-schema`,
|
`openclaw/plugin-sdk/channel-config-schema`,
|
||||||
`openclaw/plugin-sdk/channel-policy`,
|
`openclaw/plugin-sdk/channel-policy`,
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import {
|
|||||||
createScopedAccountConfigAccessors,
|
createScopedAccountConfigAccessors,
|
||||||
createScopedChannelConfigBase,
|
createScopedChannelConfigBase,
|
||||||
} from "openclaw/plugin-sdk/channel-config-helpers";
|
} from "openclaw/plugin-sdk/channel-config-helpers";
|
||||||
|
import { createChannelPluginBase } from "openclaw/plugin-sdk/core";
|
||||||
import {
|
import {
|
||||||
buildChannelConfigSchema,
|
buildChannelConfigSchema,
|
||||||
DiscordConfigSchema,
|
DiscordConfigSchema,
|
||||||
@ -58,12 +59,10 @@ export function createDiscordPluginBase(params: {
|
|||||||
| "config"
|
| "config"
|
||||||
| "setup"
|
| "setup"
|
||||||
> {
|
> {
|
||||||
return {
|
return createChannelPluginBase({
|
||||||
id: DISCORD_CHANNEL,
|
id: DISCORD_CHANNEL,
|
||||||
meta: {
|
|
||||||
...getChatChannelMeta(DISCORD_CHANNEL),
|
|
||||||
},
|
|
||||||
setupWizard: discordSetupWizard,
|
setupWizard: discordSetupWizard,
|
||||||
|
meta: { ...getChatChannelMeta(DISCORD_CHANNEL) },
|
||||||
capabilities: {
|
capabilities: {
|
||||||
chatTypes: ["direct", "channel", "thread"],
|
chatTypes: ["direct", "channel", "thread"],
|
||||||
polls: true,
|
polls: true,
|
||||||
@ -90,5 +89,16 @@ export function createDiscordPluginBase(params: {
|
|||||||
...discordConfigAccessors,
|
...discordConfigAccessors,
|
||||||
},
|
},
|
||||||
setup: params.setup,
|
setup: params.setup,
|
||||||
};
|
}) as Pick<
|
||||||
|
ChannelPlugin<ResolvedDiscordAccount>,
|
||||||
|
| "id"
|
||||||
|
| "meta"
|
||||||
|
| "setupWizard"
|
||||||
|
| "capabilities"
|
||||||
|
| "streaming"
|
||||||
|
| "reload"
|
||||||
|
| "configSchema"
|
||||||
|
| "config"
|
||||||
|
| "setup"
|
||||||
|
>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import {
|
|||||||
buildAccountScopedDmSecurityPolicy,
|
buildAccountScopedDmSecurityPolicy,
|
||||||
collectAllowlistProviderRestrictSendersWarnings,
|
collectAllowlistProviderRestrictSendersWarnings,
|
||||||
} from "openclaw/plugin-sdk/channel-policy";
|
} from "openclaw/plugin-sdk/channel-policy";
|
||||||
|
import { createChannelPluginBase } from "openclaw/plugin-sdk/core";
|
||||||
import {
|
import {
|
||||||
buildChannelConfigSchema,
|
buildChannelConfigSchema,
|
||||||
DEFAULT_ACCOUNT_ID,
|
DEFAULT_ACCOUNT_ID,
|
||||||
@ -47,7 +48,7 @@ export function createIMessagePluginBase(params: {
|
|||||||
| "security"
|
| "security"
|
||||||
| "setup"
|
| "setup"
|
||||||
> {
|
> {
|
||||||
return {
|
return createChannelPluginBase({
|
||||||
id: IMESSAGE_CHANNEL,
|
id: IMESSAGE_CHANNEL,
|
||||||
meta: {
|
meta: {
|
||||||
...getChatChannelMeta(IMESSAGE_CHANNEL),
|
...getChatChannelMeta(IMESSAGE_CHANNEL),
|
||||||
@ -115,5 +116,16 @@ export function createIMessagePluginBase(params: {
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
setup: params.setup,
|
setup: params.setup,
|
||||||
};
|
}) as Pick<
|
||||||
|
ChannelPlugin<ResolvedIMessageAccount>,
|
||||||
|
| "id"
|
||||||
|
| "meta"
|
||||||
|
| "setupWizard"
|
||||||
|
| "capabilities"
|
||||||
|
| "reload"
|
||||||
|
| "configSchema"
|
||||||
|
| "config"
|
||||||
|
| "security"
|
||||||
|
| "setup"
|
||||||
|
>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import {
|
|||||||
buildAccountScopedDmSecurityPolicy,
|
buildAccountScopedDmSecurityPolicy,
|
||||||
collectAllowlistProviderRestrictSendersWarnings,
|
collectAllowlistProviderRestrictSendersWarnings,
|
||||||
} from "openclaw/plugin-sdk/channel-policy";
|
} from "openclaw/plugin-sdk/channel-policy";
|
||||||
|
import { createChannelPluginBase } from "openclaw/plugin-sdk/core";
|
||||||
import {
|
import {
|
||||||
buildChannelConfigSchema,
|
buildChannelConfigSchema,
|
||||||
DEFAULT_ACCOUNT_ID,
|
DEFAULT_ACCOUNT_ID,
|
||||||
@ -59,7 +60,7 @@ export function createSignalPluginBase(params: {
|
|||||||
| "security"
|
| "security"
|
||||||
| "setup"
|
| "setup"
|
||||||
> {
|
> {
|
||||||
return {
|
return createChannelPluginBase({
|
||||||
id: SIGNAL_CHANNEL,
|
id: SIGNAL_CHANNEL,
|
||||||
meta: {
|
meta: {
|
||||||
...getChatChannelMeta(SIGNAL_CHANNEL),
|
...getChatChannelMeta(SIGNAL_CHANNEL),
|
||||||
@ -129,5 +130,17 @@ export function createSignalPluginBase(params: {
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
setup: params.setup,
|
setup: params.setup,
|
||||||
};
|
}) as Pick<
|
||||||
|
ChannelPlugin<ResolvedSignalAccount>,
|
||||||
|
| "id"
|
||||||
|
| "meta"
|
||||||
|
| "setupWizard"
|
||||||
|
| "capabilities"
|
||||||
|
| "streaming"
|
||||||
|
| "reload"
|
||||||
|
| "configSchema"
|
||||||
|
| "config"
|
||||||
|
| "security"
|
||||||
|
| "setup"
|
||||||
|
>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import {
|
|||||||
createScopedAccountConfigAccessors,
|
createScopedAccountConfigAccessors,
|
||||||
createScopedChannelConfigBase,
|
createScopedChannelConfigBase,
|
||||||
} from "openclaw/plugin-sdk/channel-config-helpers";
|
} from "openclaw/plugin-sdk/channel-config-helpers";
|
||||||
|
import { createChannelPluginBase } from "openclaw/plugin-sdk/core";
|
||||||
import {
|
import {
|
||||||
formatDocsLink,
|
formatDocsLink,
|
||||||
hasConfiguredSecretInput,
|
hasConfiguredSecretInput,
|
||||||
@ -176,7 +177,7 @@ export function createSlackPluginBase(params: {
|
|||||||
| "config"
|
| "config"
|
||||||
| "setup"
|
| "setup"
|
||||||
> {
|
> {
|
||||||
return {
|
return createChannelPluginBase({
|
||||||
id: SLACK_CHANNEL,
|
id: SLACK_CHANNEL,
|
||||||
meta: {
|
meta: {
|
||||||
...getChatChannelMeta(SLACK_CHANNEL),
|
...getChatChannelMeta(SLACK_CHANNEL),
|
||||||
@ -220,5 +221,17 @@ export function createSlackPluginBase(params: {
|
|||||||
...slackConfigAccessors,
|
...slackConfigAccessors,
|
||||||
},
|
},
|
||||||
setup: params.setup,
|
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,
|
createScopedAccountConfigAccessors,
|
||||||
createScopedChannelConfigBase,
|
createScopedChannelConfigBase,
|
||||||
} from "openclaw/plugin-sdk/channel-config-helpers";
|
} from "openclaw/plugin-sdk/channel-config-helpers";
|
||||||
|
import { createChannelPluginBase } from "openclaw/plugin-sdk/core";
|
||||||
import {
|
import {
|
||||||
buildChannelConfigSchema,
|
buildChannelConfigSchema,
|
||||||
getChatChannelMeta,
|
getChatChannelMeta,
|
||||||
@ -79,7 +80,7 @@ export function createTelegramPluginBase(params: {
|
|||||||
ChannelPlugin<ResolvedTelegramAccount>,
|
ChannelPlugin<ResolvedTelegramAccount>,
|
||||||
"id" | "meta" | "setupWizard" | "capabilities" | "reload" | "configSchema" | "config" | "setup"
|
"id" | "meta" | "setupWizard" | "capabilities" | "reload" | "configSchema" | "config" | "setup"
|
||||||
> {
|
> {
|
||||||
return {
|
return createChannelPluginBase({
|
||||||
id: TELEGRAM_CHANNEL,
|
id: TELEGRAM_CHANNEL,
|
||||||
meta: {
|
meta: {
|
||||||
...getChatChannelMeta(TELEGRAM_CHANNEL),
|
...getChatChannelMeta(TELEGRAM_CHANNEL),
|
||||||
@ -133,5 +134,8 @@ export function createTelegramPluginBase(params: {
|
|||||||
...telegramConfigAccessors,
|
...telegramConfigAccessors,
|
||||||
},
|
},
|
||||||
setup: params.setup,
|
setup: params.setup,
|
||||||
};
|
}) as Pick<
|
||||||
|
ChannelPlugin<ResolvedTelegramAccount>,
|
||||||
|
"id" | "meta" | "setupWizard" | "capabilities" | "reload" | "configSchema" | "config" | "setup"
|
||||||
|
>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import {
|
|||||||
collectAllowlistProviderGroupPolicyWarnings,
|
collectAllowlistProviderGroupPolicyWarnings,
|
||||||
collectOpenGroupPolicyRouteAllowlistWarnings,
|
collectOpenGroupPolicyRouteAllowlistWarnings,
|
||||||
} from "openclaw/plugin-sdk/channel-policy";
|
} from "openclaw/plugin-sdk/channel-policy";
|
||||||
|
import { createChannelPluginBase } from "openclaw/plugin-sdk/core";
|
||||||
import {
|
import {
|
||||||
buildChannelConfigSchema,
|
buildChannelConfigSchema,
|
||||||
DEFAULT_ACCOUNT_ID,
|
DEFAULT_ACCOUNT_ID,
|
||||||
@ -96,7 +97,7 @@ export function createWhatsAppPluginBase(params: {
|
|||||||
| "setup"
|
| "setup"
|
||||||
| "groups"
|
| "groups"
|
||||||
> {
|
> {
|
||||||
return {
|
return createChannelPluginBase({
|
||||||
id: WHATSAPP_CHANNEL,
|
id: WHATSAPP_CHANNEL,
|
||||||
meta: {
|
meta: {
|
||||||
...getChatChannelMeta(WHATSAPP_CHANNEL),
|
...getChatChannelMeta(WHATSAPP_CHANNEL),
|
||||||
@ -218,5 +219,18 @@ export function createWhatsAppPluginBase(params: {
|
|||||||
resolveToolPolicy: resolveWhatsAppGroupToolPolicy,
|
resolveToolPolicy: resolveWhatsAppGroupToolPolicy,
|
||||||
resolveGroupIntroHint: resolveWhatsAppGroupIntroHint,
|
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 type { ChannelPlugin } from "../channels/plugins/types.plugin.js";
|
||||||
|
import { getChatChannelMeta } from "../channels/registry.js";
|
||||||
import { emptyPluginConfigSchema } from "../plugins/config-schema.js";
|
import { emptyPluginConfigSchema } from "../plugins/config-schema.js";
|
||||||
import type { PluginRuntime } from "../plugins/runtime/types.js";
|
import type { PluginRuntime } from "../plugins/runtime/types.js";
|
||||||
import type {
|
import type {
|
||||||
@ -130,6 +131,42 @@ type DefinedPluginEntry = {
|
|||||||
register: NonNullable<OpenClawPluginDefinition["register"]>;
|
register: NonNullable<OpenClawPluginDefinition["register"]>;
|
||||||
} & Pick<OpenClawPluginDefinition, "kind">;
|
} & 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(
|
function resolvePluginConfigSchema(
|
||||||
configSchema: DefinePluginEntryOptions["configSchema"] = emptyPluginConfigSchema,
|
configSchema: DefinePluginEntryOptions["configSchema"] = emptyPluginConfigSchema,
|
||||||
): OpenClawPluginConfigSchema {
|
): OpenClawPluginConfigSchema {
|
||||||
@ -185,3 +222,27 @@ export function defineChannelPluginEntry<TPlugin extends ChannelPlugin>({
|
|||||||
export function defineSetupPluginEntry<TPlugin>(plugin: TPlugin) {
|
export function defineSetupPluginEntry<TPlugin>(plugin: TPlugin) {
|
||||||
return { plugin };
|
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.definePluginEntry).toBe("function");
|
||||||
expect(typeof coreSdk.defineChannelPluginEntry).toBe("function");
|
expect(typeof coreSdk.defineChannelPluginEntry).toBe("function");
|
||||||
expect(typeof coreSdk.defineSetupPluginEntry).toBe("function");
|
expect(typeof coreSdk.defineSetupPluginEntry).toBe("function");
|
||||||
|
expect(typeof coreSdk.createChannelPluginBase).toBe("function");
|
||||||
expect(typeof coreSdk.optionalStringEnum).toBe("function");
|
expect(typeof coreSdk.optionalStringEnum).toBe("function");
|
||||||
expect("runPassiveAccountLifecycle" in asExports(coreSdk)).toBe(false);
|
expect("runPassiveAccountLifecycle" in asExports(coreSdk)).toBe(false);
|
||||||
expect("createLoggerBackedRuntime" in asExports(coreSdk)).toBe(false);
|
expect("createLoggerBackedRuntime" in asExports(coreSdk)).toBe(false);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user