forked from openclaw/openclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchannel-plugins.ts
More file actions
151 lines (143 loc) · 4.07 KB
/
Copy pathchannel-plugins.ts
File metadata and controls
151 lines (143 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import type {
ChannelCapabilities,
ChannelId,
ChannelMessagingAdapter,
ChannelOutboundAdapter,
ChannelPlugin,
} from "../channels/plugins/types.js";
import type { PluginRegistry } from "../plugins/registry.js";
export type TestChannelRegistration = {
pluginId: string;
plugin: unknown;
source: string;
};
export const createTestRegistry = (channels: TestChannelRegistration[] = []): PluginRegistry => ({
plugins: [],
tools: [],
hooks: [],
typedHooks: [],
channels: channels as unknown as PluginRegistry["channels"],
channelSetups: channels.map((entry) => ({
pluginId: entry.pluginId,
plugin: entry.plugin as PluginRegistry["channelSetups"][number]["plugin"],
source: entry.source,
enabled: true,
})),
providers: [],
speechProviders: [],
mediaUnderstandingProviders: [],
imageGenerationProviders: [],
webSearchProviders: [],
gatewayHandlers: {},
httpRoutes: [],
cliRegistrars: [],
services: [],
commands: [],
conversationBindingResolvedHandlers: [],
diagnostics: [],
});
export const createChannelTestPluginBase = (params: {
id: ChannelId;
label?: string;
docsPath?: string;
markdownCapable?: boolean;
capabilities?: ChannelCapabilities;
config?: Partial<ChannelPlugin["config"]>;
}): Pick<ChannelPlugin, "id" | "meta" | "capabilities" | "config"> => ({
id: params.id,
meta: {
id: params.id,
label: params.label ?? String(params.id),
selectionLabel: params.label ?? String(params.id),
docsPath: params.docsPath ?? `/channels/${params.id}`,
blurb: "test stub.",
...(params.markdownCapable !== undefined ? { markdownCapable: params.markdownCapable } : {}),
},
capabilities: params.capabilities ?? { chatTypes: ["direct"] },
config: {
listAccountIds: () => ["default"],
resolveAccount: () => ({}),
...params.config,
},
});
export const createMSTeamsTestPluginBase = (): Pick<
ChannelPlugin,
"id" | "meta" | "capabilities" | "config"
> => {
const base = createChannelTestPluginBase({
id: "msteams",
label: "Microsoft Teams",
docsPath: "/channels/msteams",
config: { listAccountIds: () => [], resolveAccount: () => ({}) },
});
return {
...base,
meta: {
...base.meta,
selectionLabel: "Microsoft Teams (Bot Framework)",
blurb: "Teams SDK; enterprise support.",
aliases: ["teams"],
},
};
};
export const createMSTeamsTestPlugin = (params?: {
aliases?: string[];
outbound?: ChannelOutboundAdapter;
}): ChannelPlugin => {
const base = createMSTeamsTestPluginBase();
return {
...base,
meta: {
...base.meta,
...(params?.aliases ? { aliases: params.aliases } : {}),
},
...(params?.outbound ? { outbound: params.outbound } : {}),
};
};
export const createOutboundTestPlugin = (params: {
id: ChannelId;
outbound: ChannelOutboundAdapter;
messaging?: ChannelMessagingAdapter;
label?: string;
docsPath?: string;
capabilities?: ChannelCapabilities;
}): ChannelPlugin => ({
...createChannelTestPluginBase({
id: params.id,
label: params.label,
docsPath: params.docsPath,
capabilities: params.capabilities,
config: { listAccountIds: () => [] },
}),
outbound: params.outbound,
...(params.messaging ? { messaging: params.messaging } : {}),
});
export type BindingResolverTestPlugin = Pick<
ChannelPlugin,
"id" | "meta" | "capabilities" | "config"
> & {
setup?: Pick<NonNullable<ChannelPlugin["setup"]>, "resolveBindingAccountId">;
};
export const createBindingResolverTestPlugin = (params: {
id: ChannelId;
label?: string;
docsPath?: string;
capabilities?: ChannelCapabilities;
config?: Partial<ChannelPlugin["config"]>;
resolveBindingAccountId?: NonNullable<ChannelPlugin["setup"]>["resolveBindingAccountId"];
}): BindingResolverTestPlugin => ({
...createChannelTestPluginBase({
id: params.id,
label: params.label,
docsPath: params.docsPath,
capabilities: params.capabilities,
config: params.config,
}),
...(params.resolveBindingAccountId
? {
setup: {
resolveBindingAccountId: params.resolveBindingAccountId,
},
}
: {}),
});