moltbot-channel-feishu 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,377 @@
1
+ /**
2
+ * Type declarations for clawdbot/plugin-sdk.
3
+ * This stub allows strict TypeScript compilation against the peer dependency.
4
+ */
5
+
6
+ declare module "clawdbot/plugin-sdk" {
7
+ export const DEFAULT_ACCOUNT_ID: string;
8
+ export const PAIRING_APPROVED_MESSAGE: string;
9
+ export const DEFAULT_GROUP_HISTORY_LIMIT: number;
10
+
11
+ export function emptyPluginConfigSchema(): unknown;
12
+ export function addWildcardAllowFrom(allowFrom?: (string | number)[]): (string | number)[];
13
+ export function formatDocsLink(path: string, label: string): string;
14
+
15
+ // History management
16
+ export interface HistoryEntry {
17
+ sender: string;
18
+ body: string;
19
+ timestamp: number;
20
+ messageId?: string;
21
+ }
22
+
23
+ export function buildPendingHistoryContextFromMap(params: {
24
+ historyMap: Map<string, HistoryEntry[]>;
25
+ historyKey: string;
26
+ limit: number;
27
+ currentMessage: string;
28
+ formatEntry: (entry: HistoryEntry) => string;
29
+ }): string;
30
+
31
+ export function recordPendingHistoryEntryIfEnabled(params: {
32
+ historyMap: Map<string, HistoryEntry[]>;
33
+ historyKey: string;
34
+ limit: number;
35
+ entry: HistoryEntry;
36
+ }): void;
37
+
38
+ export function clearHistoryEntriesIfEnabled(params: {
39
+ historyMap: Map<string, HistoryEntry[]>;
40
+ historyKey: string;
41
+ limit: number;
42
+ }): void;
43
+
44
+ // Reply dispatcher
45
+ export interface ReplyPayload {
46
+ text?: string;
47
+ [key: string]: unknown;
48
+ }
49
+
50
+ export interface ReplyPrefixContext {
51
+ responsePrefix: string;
52
+ responsePrefixContextProvider: () => unknown;
53
+ onModelSelected: (model: string) => void;
54
+ }
55
+
56
+ export function createReplyPrefixContext(params: {
57
+ cfg: ClawdbotConfig;
58
+ agentId: string;
59
+ }): ReplyPrefixContext;
60
+
61
+ export interface TypingCallbacks {
62
+ onReplyStart: () => Promise<void>;
63
+ onIdle?: () => void;
64
+ }
65
+
66
+ export function createTypingCallbacks(params: {
67
+ start: () => Promise<void>;
68
+ stop: () => Promise<void>;
69
+ onStartError?: (err: unknown) => void;
70
+ onStopError?: (err: unknown) => void;
71
+ }): TypingCallbacks;
72
+
73
+ export function logTypingFailure(params: {
74
+ log: (message: string) => void;
75
+ channel: string;
76
+ action: string;
77
+ error: unknown;
78
+ }): void;
79
+
80
+ // Runtime types
81
+ export type DmPolicy = "open" | "pairing" | "allowlist";
82
+
83
+ export interface RuntimeEnv {
84
+ log?: (message: string) => void;
85
+ error?: (message: string) => void;
86
+ [key: string]: unknown;
87
+ }
88
+
89
+ export interface PluginRuntime {
90
+ channel: {
91
+ routing: {
92
+ resolveAgentRoute(params: {
93
+ cfg: ClawdbotConfig;
94
+ channel: string;
95
+ peer: { kind: string; id: string };
96
+ }): { sessionKey: string; accountId: string; agentId: string };
97
+ };
98
+ reply: {
99
+ resolveEnvelopeFormatOptions(cfg: ClawdbotConfig): unknown;
100
+ formatAgentEnvelope(params: {
101
+ channel: string;
102
+ from: string;
103
+ timestamp: Date | number;
104
+ envelope: unknown;
105
+ body: string;
106
+ }): string;
107
+ finalizeInboundContext(params: Record<string, unknown>): unknown;
108
+ createReplyDispatcherWithTyping(params: {
109
+ responsePrefix: string;
110
+ responsePrefixContextProvider: () => unknown;
111
+ humanDelay: unknown;
112
+ onReplyStart: () => Promise<void>;
113
+ deliver: (payload: ReplyPayload) => Promise<void>;
114
+ onError: (err: unknown, info: { kind: string }) => void;
115
+ onIdle?: () => void;
116
+ }): {
117
+ dispatcher: unknown;
118
+ replyOptions: Record<string, unknown>;
119
+ markDispatchIdle: () => void;
120
+ };
121
+ dispatchReplyFromConfig(params: {
122
+ ctx: unknown;
123
+ cfg: ClawdbotConfig;
124
+ dispatcher: unknown;
125
+ replyOptions: unknown;
126
+ }): Promise<{ queuedFinal: boolean; counts: { final: number } }>;
127
+ resolveHumanDelayConfig(cfg: ClawdbotConfig, agentId: string): unknown;
128
+ };
129
+ text: {
130
+ resolveTextChunkLimit(params: {
131
+ cfg: ClawdbotConfig;
132
+ channel: string;
133
+ defaultLimit: number;
134
+ }): number;
135
+ resolveChunkMode(cfg: ClawdbotConfig, channel: string): string;
136
+ resolveMarkdownTableMode(params: { cfg: ClawdbotConfig; channel: string }): string;
137
+ convertMarkdownTables(text: string, mode: string): string;
138
+ chunkTextWithMode(text: string, limit: number, mode: string): string[];
139
+ };
140
+ };
141
+ system: {
142
+ enqueueSystemEvent(
143
+ message: string,
144
+ params: {
145
+ sessionKey: string;
146
+ contextKey: string;
147
+ }
148
+ ): void;
149
+ };
150
+ [key: string]: unknown;
151
+ }
152
+
153
+ export interface ClawdbotConfig {
154
+ channels?: {
155
+ feishu?: Record<string, unknown>;
156
+ [key: string]: unknown;
157
+ };
158
+ messages?: {
159
+ groupChat?: {
160
+ historyLimit?: number;
161
+ };
162
+ };
163
+ [key: string]: unknown;
164
+ }
165
+
166
+ export interface ClawdbotPluginApi {
167
+ runtime: PluginRuntime;
168
+ registerChannel(params: { plugin: ChannelPlugin<unknown> }): void;
169
+ }
170
+
171
+ export interface ChannelGroupContext {
172
+ cfg: ClawdbotConfig;
173
+ groupId?: string | null;
174
+ [key: string]: unknown;
175
+ }
176
+
177
+ export interface GroupToolPolicyConfig {
178
+ allow?: string[];
179
+ deny?: string[];
180
+ }
181
+
182
+ export interface WizardPrompter {
183
+ note(message: string, title?: string): Promise<void>;
184
+ text(params: {
185
+ message: string;
186
+ placeholder?: string;
187
+ initialValue?: string;
188
+ validate?: (value: string | undefined) => string | undefined;
189
+ }): Promise<string | symbol>;
190
+ confirm(params: { message: string; initialValue?: boolean }): Promise<boolean>;
191
+ select<T>(params: {
192
+ message: string;
193
+ options: { value: T; label: string }[];
194
+ initialValue?: T;
195
+ }): Promise<T | symbol>;
196
+ }
197
+
198
+ export interface ChannelOnboardingDmPolicy {
199
+ label: string;
200
+ channel: string;
201
+ policyKey: string;
202
+ allowFromKey: string;
203
+ getCurrent(cfg: ClawdbotConfig): DmPolicy;
204
+ setPolicy(cfg: ClawdbotConfig, policy: DmPolicy): ClawdbotConfig;
205
+ promptAllowFrom(params: {
206
+ cfg: ClawdbotConfig;
207
+ prompter: WizardPrompter;
208
+ }): Promise<ClawdbotConfig>;
209
+ }
210
+
211
+ export interface ChannelOnboardingAdapter {
212
+ channel: string;
213
+ getStatus(params: { cfg: ClawdbotConfig }): Promise<{
214
+ channel: string;
215
+ configured: boolean;
216
+ statusLines: string[];
217
+ selectionHint?: string;
218
+ quickstartScore?: number;
219
+ }>;
220
+ configure(params: {
221
+ cfg: ClawdbotConfig;
222
+ prompter: WizardPrompter;
223
+ }): Promise<{ cfg: ClawdbotConfig; accountId: string }>;
224
+ dmPolicy: ChannelOnboardingDmPolicy;
225
+ disable(cfg: ClawdbotConfig): ClawdbotConfig;
226
+ }
227
+
228
+ export interface ChannelPluginCapabilities {
229
+ chatTypes: string[];
230
+ polls: boolean;
231
+ threads: boolean;
232
+ media: boolean;
233
+ reactions: boolean;
234
+ edit: boolean;
235
+ reply: boolean;
236
+ }
237
+
238
+ export interface ChannelPluginOutbound {
239
+ deliveryMode: string;
240
+ chunkerMode: string;
241
+ textChunkLimit: number;
242
+ chunker(text: string, limit: number): string[];
243
+ sendText(params: {
244
+ cfg: ClawdbotConfig;
245
+ to: string;
246
+ text: string;
247
+ }): Promise<{ channel: string; messageId: string; chatId: string }>;
248
+ sendMedia(params: {
249
+ cfg: ClawdbotConfig;
250
+ to: string;
251
+ text?: string;
252
+ mediaUrl?: string;
253
+ }): Promise<{ channel: string; messageId: string; chatId: string }>;
254
+ }
255
+
256
+ export interface ChannelPluginStatus {
257
+ defaultRuntime: {
258
+ accountId: string;
259
+ running: boolean;
260
+ lastStartAt: null;
261
+ lastStopAt: null;
262
+ lastError: null;
263
+ port: null;
264
+ };
265
+ buildChannelSummary(params: { snapshot: Record<string, unknown> }): Record<string, unknown>;
266
+ probeAccount(params: { cfg: ClawdbotConfig }): Promise<{
267
+ ok: boolean;
268
+ error?: string;
269
+ appId?: string;
270
+ botName?: string;
271
+ botOpenId?: string;
272
+ }>;
273
+ buildAccountSnapshot(params: {
274
+ account: { accountId: string; enabled: boolean; configured: boolean };
275
+ runtime?: Record<string, unknown>;
276
+ probe?: Record<string, unknown>;
277
+ }): Record<string, unknown>;
278
+ }
279
+
280
+ export interface ChannelPluginGateway {
281
+ startAccount(ctx: {
282
+ cfg: ClawdbotConfig;
283
+ accountId: string;
284
+ runtime?: RuntimeEnv;
285
+ abortSignal?: AbortSignal;
286
+ setStatus(status: Record<string, unknown>): void;
287
+ log?: { info(msg: string): void; error(msg: string): void };
288
+ }): Promise<void>;
289
+ }
290
+
291
+ export interface ChannelPlugin<TAccount> {
292
+ id: string;
293
+ meta: {
294
+ id: string;
295
+ label: string;
296
+ selectionLabel: string;
297
+ docsPath: string;
298
+ docsLabel: string;
299
+ blurb: string;
300
+ aliases: string[];
301
+ order: number;
302
+ };
303
+ pairing?: {
304
+ idLabel: string;
305
+ normalizeAllowEntry(entry: string): string;
306
+ notifyApproval(params: { cfg: ClawdbotConfig; id: string }): Promise<void>;
307
+ };
308
+ capabilities: ChannelPluginCapabilities;
309
+ agentPrompt?: {
310
+ messageToolHints(): string[];
311
+ };
312
+ groups?: {
313
+ resolveToolPolicy(params: ChannelGroupContext): GroupToolPolicyConfig | undefined;
314
+ };
315
+ reload?: { configPrefixes: string[] };
316
+ threading?: {
317
+ resolveReplyToMode?(params: { cfg: ClawdbotConfig; accountId?: string | null; chatType?: string | null }): "off" | "first" | "all";
318
+ };
319
+ configSchema?: { schema: Record<string, unknown> };
320
+ config: {
321
+ listAccountIds(): string[];
322
+ resolveAccount(cfg: ClawdbotConfig): TAccount;
323
+ defaultAccountId(): string;
324
+ setAccountEnabled(params: { cfg: ClawdbotConfig; enabled: boolean }): ClawdbotConfig;
325
+ deleteAccount(params: { cfg: ClawdbotConfig }): ClawdbotConfig;
326
+ isConfigured(account: TAccount, cfg: ClawdbotConfig): boolean;
327
+ describeAccount(account: TAccount): {
328
+ accountId: string;
329
+ enabled: boolean;
330
+ configured: boolean;
331
+ };
332
+ resolveAllowFrom(params: { cfg: ClawdbotConfig }): (string | number)[];
333
+ formatAllowFrom(params: { allowFrom: (string | number)[] }): string[];
334
+ };
335
+ security?: {
336
+ collectWarnings(params: { cfg: ClawdbotConfig }): string[];
337
+ };
338
+ setup?: {
339
+ resolveAccountId(): string;
340
+ applyAccountConfig(params: { cfg: ClawdbotConfig }): ClawdbotConfig;
341
+ };
342
+ onboarding: ChannelOnboardingAdapter;
343
+ messaging: {
344
+ normalizeTarget(target: string): string | null;
345
+ targetResolver: {
346
+ looksLikeId(id: string): boolean;
347
+ hint: string;
348
+ };
349
+ };
350
+ directory: {
351
+ self(): Promise<null>;
352
+ listPeers(params: {
353
+ cfg: ClawdbotConfig;
354
+ query?: string;
355
+ limit?: number;
356
+ }): Promise<{ kind: "user"; id: string; name?: string }[]>;
357
+ listGroups(params: {
358
+ cfg: ClawdbotConfig;
359
+ query?: string;
360
+ limit?: number;
361
+ }): Promise<{ kind: "group"; id: string; name?: string }[]>;
362
+ listPeersLive(params: {
363
+ cfg: ClawdbotConfig;
364
+ query?: string;
365
+ limit?: number;
366
+ }): Promise<{ kind: "user"; id: string; name?: string }[]>;
367
+ listGroupsLive(params: {
368
+ cfg: ClawdbotConfig;
369
+ query?: string;
370
+ limit?: number;
371
+ }): Promise<{ kind: "group"; id: string; name?: string }[]>;
372
+ };
373
+ outbound: ChannelPluginOutbound;
374
+ status: ChannelPluginStatus;
375
+ gateway: ChannelPluginGateway;
376
+ }
377
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Feishu/Lark message event types.
3
+ * Strictly typed to match SDK event payloads.
4
+ */
5
+
6
+ /** Sender identity in a message event */
7
+ export interface MessageSender {
8
+ sender_id: {
9
+ open_id?: string;
10
+ user_id?: string;
11
+ union_id?: string;
12
+ };
13
+ sender_type?: string;
14
+ tenant_key?: string;
15
+ }
16
+
17
+ /** Message payload in a message event */
18
+ export interface MessagePayload {
19
+ message_id: string;
20
+ root_id?: string;
21
+ parent_id?: string;
22
+ chat_id: string;
23
+ chat_type: "p2p" | "group";
24
+ message_type: string;
25
+ content: string;
26
+ mentions?: MessageMention[];
27
+ }
28
+
29
+ /** Mention in a message */
30
+ export interface MessageMention {
31
+ key: string;
32
+ id: {
33
+ open_id?: string;
34
+ user_id?: string;
35
+ union_id?: string;
36
+ };
37
+ name: string;
38
+ tenant_key?: string;
39
+ }
40
+
41
+ /** im.message.receive_v1 event data */
42
+ export interface MessageReceivedEvent {
43
+ sender: MessageSender;
44
+ message: MessagePayload;
45
+ }
46
+
47
+ /** im.chat.member.bot.added_v1 event data */
48
+ export interface BotAddedEvent {
49
+ chat_id: string;
50
+ operator_id: {
51
+ open_id?: string;
52
+ user_id?: string;
53
+ union_id?: string;
54
+ };
55
+ external: boolean;
56
+ operator_tenant_key?: string;
57
+ }
58
+
59
+ /** im.chat.member.bot.deleted_v1 event data */
60
+ export interface BotRemovedEvent {
61
+ chat_id: string;
62
+ }
63
+
64
+ /** Event handler function type */
65
+ export type EventHandler<T> = (data: T) => Promise<void>;
66
+
67
+ /** Registered event handlers */
68
+ export interface EventHandlers {
69
+ onMessageReceived?: EventHandler<MessageReceivedEvent>;
70
+ onBotAdded?: EventHandler<BotAddedEvent>;
71
+ onBotRemoved?: EventHandler<BotRemovedEvent>;
72
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Type definitions barrel export.
3
+ */
4
+
5
+ export * from "./events.js";
6
+ export * from "./messages.js";
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Message-related types for API operations.
3
+ */
4
+
5
+ /** Target ID type for message sending */
6
+ export type ReceiveIdType = "open_id" | "user_id" | "union_id" | "chat_id";
7
+
8
+ /** Domain selection */
9
+ export type FeishuDomain = "feishu" | "lark";
10
+
11
+ /** Connection mode (websocket only) */
12
+ export type ConnectionMode = "websocket";
13
+
14
+ /** DM access policy */
15
+ export type DmPolicy = "open" | "pairing" | "allowlist";
16
+
17
+ /** Group access policy */
18
+ export type GroupPolicy = "open" | "allowlist" | "disabled";
19
+
20
+ /** Chat type */
21
+ export type ChatType = "p2p" | "group";
22
+
23
+ /** Parameters for sending a text message */
24
+ export interface SendTextParams {
25
+ to: string;
26
+ text: string;
27
+ replyToMessageId?: string;
28
+ }
29
+
30
+ /** Parameters for sending an interactive card */
31
+ export interface SendCardParams {
32
+ to: string;
33
+ card: Record<string, unknown>;
34
+ replyToMessageId?: string;
35
+ }
36
+
37
+ /** Parameters for editing a message */
38
+ export interface EditMessageParams {
39
+ messageId: string;
40
+ text: string;
41
+ }
42
+
43
+ /** Result of sending a message */
44
+ export interface SendResult {
45
+ messageId: string;
46
+ chatId: string;
47
+ }
48
+
49
+ /** Retrieved message information */
50
+ export interface MessageInfo {
51
+ messageId: string;
52
+ chatId: string;
53
+ senderId?: string;
54
+ senderOpenId?: string;
55
+ content: string;
56
+ contentType: string;
57
+ createTime?: number;
58
+ }
59
+
60
+ /** Parsed message context for internal processing */
61
+ export interface ParsedMessage {
62
+ chatId: string;
63
+ messageId: string;
64
+ senderId: string;
65
+ senderOpenId: string;
66
+ senderName?: string;
67
+ chatType: ChatType;
68
+ mentionedBot: boolean;
69
+ rootId?: string;
70
+ parentId?: string;
71
+ content: string;
72
+ contentType: string;
73
+ }
74
+
75
+ /** Parameters for uploading an image */
76
+ export interface UploadImageParams {
77
+ image: Buffer | string;
78
+ imageType?: "message" | "avatar";
79
+ }
80
+
81
+ /** Result of image upload */
82
+ export interface ImageUploadResult {
83
+ imageKey: string;
84
+ }
85
+
86
+ /** File type for upload */
87
+ export type FileType = "opus" | "mp4" | "pdf" | "doc" | "xls" | "ppt" | "stream";
88
+
89
+ /** Parameters for uploading a file */
90
+ export interface UploadFileParams {
91
+ file: Buffer | string;
92
+ fileName: string;
93
+ fileType: FileType;
94
+ duration?: number;
95
+ }
96
+
97
+ /** Result of file upload */
98
+ export interface FileUploadResult {
99
+ fileKey: string;
100
+ }
101
+
102
+ /** Parameters for sending media */
103
+ export interface SendMediaParams {
104
+ to: string;
105
+ mediaUrl?: string;
106
+ mediaBuffer?: Buffer;
107
+ fileName?: string;
108
+ replyToMessageId?: string;
109
+ }
110
+
111
+ /** Parameters for sending an already-uploaded image */
112
+ export interface SendImageParams {
113
+ to: string;
114
+ imageKey: string;
115
+ replyToMessageId?: string;
116
+ }
117
+
118
+ /** Parameters for sending an already-uploaded file */
119
+ export interface SendFileParams {
120
+ to: string;
121
+ fileKey: string;
122
+ replyToMessageId?: string;
123
+ }
124
+
125
+ /** Reaction information */
126
+ export interface Reaction {
127
+ reactionId: string;
128
+ emojiType: string;
129
+ operatorType: "app" | "user";
130
+ operatorId: string;
131
+ }
132
+
133
+ /** Parameters for adding a reaction */
134
+ export interface AddReactionParams {
135
+ messageId: string;
136
+ emojiType: string;
137
+ }
138
+
139
+ /** Parameters for removing a reaction */
140
+ export interface RemoveReactionParams {
141
+ messageId: string;
142
+ reactionId: string;
143
+ }
144
+
145
+ /** User from directory */
146
+ export interface DirectoryUser {
147
+ kind: "user";
148
+ id: string;
149
+ name?: string;
150
+ }
151
+
152
+ /** Group from directory */
153
+ export interface DirectoryGroup {
154
+ kind: "group";
155
+ id: string;
156
+ name?: string;
157
+ }
158
+
159
+ /** Parameters for directory listing */
160
+ export interface ListDirectoryParams {
161
+ query?: string;
162
+ limit?: number;
163
+ }
164
+
165
+ /** Probe result for connection testing */
166
+ export interface ProbeResult {
167
+ ok: boolean;
168
+ error?: string;
169
+ appId?: string;
170
+ botName?: string;
171
+ botOpenId?: string;
172
+ }