@nextclaw/channel-runtime 0.2.1 → 0.2.3
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.
- package/package.json +2 -2
- package/dist/index.d.ts +0 -349
- package/dist/index.js +0 -4207
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nextclaw/channel-runtime",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Runtime implementations for NextClaw builtin channel plugins.",
|
|
6
6
|
"type": "module",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"undici": "^6.21.0",
|
|
30
30
|
"ws": "^8.18.0",
|
|
31
31
|
"socket.io-msgpack-parser": "^3.0.2",
|
|
32
|
-
"@nextclaw/core": "0.9.
|
|
32
|
+
"@nextclaw/core": "0.9.3"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/mailparser": "^3.4.6",
|
package/dist/index.d.ts
DELETED
|
@@ -1,349 +0,0 @@
|
|
|
1
|
-
import { MessageBus, Config, SessionManager } from '@nextclaw/core';
|
|
2
|
-
|
|
3
|
-
type InboundAttachmentErrorCode = "too_large" | "download_failed" | "http_error" | "invalid_payload";
|
|
4
|
-
type InboundAttachment = {
|
|
5
|
-
id?: string;
|
|
6
|
-
name?: string;
|
|
7
|
-
path?: string;
|
|
8
|
-
url?: string;
|
|
9
|
-
mimeType?: string;
|
|
10
|
-
size?: number;
|
|
11
|
-
source?: string;
|
|
12
|
-
status?: "ready" | "remote-only";
|
|
13
|
-
errorCode?: InboundAttachmentErrorCode;
|
|
14
|
-
};
|
|
15
|
-
type OutboundMessage = {
|
|
16
|
-
channel: string;
|
|
17
|
-
chatId: string;
|
|
18
|
-
content: string;
|
|
19
|
-
replyTo?: string | null;
|
|
20
|
-
media: string[];
|
|
21
|
-
metadata: Record<string, unknown>;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
declare abstract class BaseChannel<TConfig extends Record<string, unknown>> {
|
|
25
|
-
protected config: TConfig;
|
|
26
|
-
protected bus: MessageBus;
|
|
27
|
-
protected running: boolean;
|
|
28
|
-
constructor(config: TConfig, bus: MessageBus);
|
|
29
|
-
abstract get name(): string;
|
|
30
|
-
abstract start(): Promise<void>;
|
|
31
|
-
abstract stop(): Promise<void>;
|
|
32
|
-
abstract send(msg: OutboundMessage): Promise<void>;
|
|
33
|
-
handleControlMessage(_msg: OutboundMessage): Promise<boolean>;
|
|
34
|
-
isAllowed(senderId: string): boolean;
|
|
35
|
-
protected handleMessage(params: {
|
|
36
|
-
senderId: string;
|
|
37
|
-
chatId: string;
|
|
38
|
-
content: string;
|
|
39
|
-
attachments?: InboundAttachment[];
|
|
40
|
-
metadata?: Record<string, unknown>;
|
|
41
|
-
}): Promise<void>;
|
|
42
|
-
get isRunning(): boolean;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
declare class DingTalkChannel extends BaseChannel<Config["channels"]["dingtalk"]> {
|
|
46
|
-
name: string;
|
|
47
|
-
private client;
|
|
48
|
-
private accessToken;
|
|
49
|
-
private tokenExpiry;
|
|
50
|
-
constructor(config: Config["channels"]["dingtalk"], bus: MessageBus);
|
|
51
|
-
start(): Promise<void>;
|
|
52
|
-
stop(): Promise<void>;
|
|
53
|
-
send(msg: OutboundMessage): Promise<void>;
|
|
54
|
-
private handleRobotMessage;
|
|
55
|
-
private getAccessToken;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
declare class DiscordChannel extends BaseChannel<Config["channels"]["discord"]> {
|
|
59
|
-
private sessionManager?;
|
|
60
|
-
private coreConfig?;
|
|
61
|
-
name: string;
|
|
62
|
-
private client;
|
|
63
|
-
private readonly typingController;
|
|
64
|
-
private readonly commandRegistry;
|
|
65
|
-
constructor(config: Config["channels"]["discord"], bus: MessageBus, sessionManager?: SessionManager | undefined, coreConfig?: Config | undefined);
|
|
66
|
-
start(): Promise<void>;
|
|
67
|
-
stop(): Promise<void>;
|
|
68
|
-
handleControlMessage(msg: OutboundMessage): Promise<boolean>;
|
|
69
|
-
send(msg: OutboundMessage): Promise<void>;
|
|
70
|
-
private handleIncoming;
|
|
71
|
-
private handleInteraction;
|
|
72
|
-
private handleSlashCommand;
|
|
73
|
-
private replyInteraction;
|
|
74
|
-
private registerSlashCommands;
|
|
75
|
-
private buildSlashCommandPayloads;
|
|
76
|
-
private resolveProxyAgent;
|
|
77
|
-
private resolveAccountId;
|
|
78
|
-
private isAllowedByPolicy;
|
|
79
|
-
private resolveMentionState;
|
|
80
|
-
private resolveInboundAttachment;
|
|
81
|
-
private startTyping;
|
|
82
|
-
private stopTyping;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
declare class EmailChannel extends BaseChannel<Config["channels"]["email"]> {
|
|
86
|
-
name: string;
|
|
87
|
-
private lastSubjectByChat;
|
|
88
|
-
private lastMessageIdByChat;
|
|
89
|
-
private processedUids;
|
|
90
|
-
private maxProcessedUids;
|
|
91
|
-
constructor(config: Config["channels"]["email"], bus: MessageBus);
|
|
92
|
-
start(): Promise<void>;
|
|
93
|
-
stop(): Promise<void>;
|
|
94
|
-
send(msg: OutboundMessage): Promise<void>;
|
|
95
|
-
private validateConfig;
|
|
96
|
-
private replySubject;
|
|
97
|
-
private fetchNewMessages;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
declare class FeishuChannel extends BaseChannel<Config["channels"]["feishu"]> {
|
|
101
|
-
name: string;
|
|
102
|
-
private client;
|
|
103
|
-
private wsClient;
|
|
104
|
-
private processedMessageIds;
|
|
105
|
-
private processedSet;
|
|
106
|
-
constructor(config: Config["channels"]["feishu"], bus: MessageBus);
|
|
107
|
-
start(): Promise<void>;
|
|
108
|
-
stop(): Promise<void>;
|
|
109
|
-
send(msg: OutboundMessage): Promise<void>;
|
|
110
|
-
private handleIncoming;
|
|
111
|
-
private isDuplicate;
|
|
112
|
-
private addReaction;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
declare class MochatChannel extends BaseChannel<Config["channels"]["mochat"]> {
|
|
116
|
-
name: string;
|
|
117
|
-
private socket;
|
|
118
|
-
private wsConnected;
|
|
119
|
-
private wsReady;
|
|
120
|
-
private stateDir;
|
|
121
|
-
private cursorPath;
|
|
122
|
-
private sessionCursor;
|
|
123
|
-
private cursorSaveTimer;
|
|
124
|
-
private sessionSet;
|
|
125
|
-
private panelSet;
|
|
126
|
-
private autoDiscoverSessions;
|
|
127
|
-
private autoDiscoverPanels;
|
|
128
|
-
private coldSessions;
|
|
129
|
-
private sessionByConverse;
|
|
130
|
-
private seenSet;
|
|
131
|
-
private seenQueue;
|
|
132
|
-
private delayStates;
|
|
133
|
-
private fallbackMode;
|
|
134
|
-
private sessionFallbackTasks;
|
|
135
|
-
private panelFallbackTasks;
|
|
136
|
-
private refreshTimer;
|
|
137
|
-
private targetLocks;
|
|
138
|
-
private refreshInFlight;
|
|
139
|
-
constructor(config: Config["channels"]["mochat"], bus: MessageBus);
|
|
140
|
-
start(): Promise<void>;
|
|
141
|
-
stop(): Promise<void>;
|
|
142
|
-
send(msg: OutboundMessage): Promise<void>;
|
|
143
|
-
private seedTargetsFromConfig;
|
|
144
|
-
private startSocketClient;
|
|
145
|
-
private subscribeAll;
|
|
146
|
-
private subscribeSessions;
|
|
147
|
-
private subscribePanels;
|
|
148
|
-
private socketCall;
|
|
149
|
-
private refreshLoopTick;
|
|
150
|
-
private refreshTargets;
|
|
151
|
-
private refreshSessionsDirectory;
|
|
152
|
-
private refreshPanels;
|
|
153
|
-
private ensureFallbackWorkers;
|
|
154
|
-
private stopFallbackWorkers;
|
|
155
|
-
private sessionWatchWorker;
|
|
156
|
-
private panelPollWorker;
|
|
157
|
-
private handleWatchPayload;
|
|
158
|
-
private processInboundEvent;
|
|
159
|
-
private rememberMessageId;
|
|
160
|
-
private enqueueDelayedEntry;
|
|
161
|
-
private flushDelayedEntries;
|
|
162
|
-
private dispatchEntries;
|
|
163
|
-
private cancelDelayTimers;
|
|
164
|
-
private handleNotifyChatMessage;
|
|
165
|
-
private handleNotifyInboxAppend;
|
|
166
|
-
private markSessionCursor;
|
|
167
|
-
private loadSessionCursors;
|
|
168
|
-
private saveSessionCursors;
|
|
169
|
-
private postJson;
|
|
170
|
-
private apiSend;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
declare class QQChannel extends BaseChannel<Config["channels"]["qq"]> {
|
|
174
|
-
name: string;
|
|
175
|
-
private bot;
|
|
176
|
-
private processedIds;
|
|
177
|
-
private processedSet;
|
|
178
|
-
private senderNameCache;
|
|
179
|
-
private reconnectTimer;
|
|
180
|
-
private connectTask;
|
|
181
|
-
private reconnectAttempt;
|
|
182
|
-
private readonly reconnectBaseMs;
|
|
183
|
-
private readonly reconnectMaxMs;
|
|
184
|
-
constructor(config: Config["channels"]["qq"], bus: MessageBus);
|
|
185
|
-
start(): Promise<void>;
|
|
186
|
-
stop(): Promise<void>;
|
|
187
|
-
send(msg: OutboundMessage): Promise<void>;
|
|
188
|
-
private sendByMessageType;
|
|
189
|
-
private handleIncoming;
|
|
190
|
-
private resolveSenderName;
|
|
191
|
-
private decorateSpeakerPrefix;
|
|
192
|
-
private sanitizeSpeakerToken;
|
|
193
|
-
private extractDeclaredName;
|
|
194
|
-
private isDuplicate;
|
|
195
|
-
private sendWithTokenRetry;
|
|
196
|
-
private isTokenExpiredError;
|
|
197
|
-
private isDisallowedUrlParamError;
|
|
198
|
-
private toQqSafeText;
|
|
199
|
-
private extractBlockedUrlToken;
|
|
200
|
-
private tryConnect;
|
|
201
|
-
private connect;
|
|
202
|
-
private createBot;
|
|
203
|
-
private handleSessionDead;
|
|
204
|
-
private scheduleReconnect;
|
|
205
|
-
private clearReconnectTimer;
|
|
206
|
-
private teardownBot;
|
|
207
|
-
private safeStopBot;
|
|
208
|
-
private getBackoffDelayMs;
|
|
209
|
-
private formatError;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
declare class SlackChannel extends BaseChannel<Config["channels"]["slack"]> {
|
|
213
|
-
name: string;
|
|
214
|
-
private webClient;
|
|
215
|
-
private socketClient;
|
|
216
|
-
private botUserId;
|
|
217
|
-
private botId;
|
|
218
|
-
constructor(config: Config["channels"]["slack"], bus: MessageBus);
|
|
219
|
-
start(): Promise<void>;
|
|
220
|
-
stop(): Promise<void>;
|
|
221
|
-
send(msg: OutboundMessage): Promise<void>;
|
|
222
|
-
private handleEvent;
|
|
223
|
-
private isAllowedInSlack;
|
|
224
|
-
private shouldRespondInChannel;
|
|
225
|
-
private stripBotMention;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
declare class TelegramChannel extends BaseChannel<Config["channels"]["telegram"]> {
|
|
229
|
-
private sessionManager?;
|
|
230
|
-
name: string;
|
|
231
|
-
private bot;
|
|
232
|
-
private botUserId;
|
|
233
|
-
private botUsername;
|
|
234
|
-
private readonly typingController;
|
|
235
|
-
private readonly streamPreview;
|
|
236
|
-
private transcriber;
|
|
237
|
-
constructor(config: Config["channels"]["telegram"], bus: MessageBus, groqApiKey?: string, sessionManager?: SessionManager | undefined);
|
|
238
|
-
start(): Promise<void>;
|
|
239
|
-
stop(): Promise<void>;
|
|
240
|
-
handleControlMessage(msg: OutboundMessage): Promise<boolean>;
|
|
241
|
-
send(msg: OutboundMessage): Promise<void>;
|
|
242
|
-
private handleIncoming;
|
|
243
|
-
private dispatchToBus;
|
|
244
|
-
private startTyping;
|
|
245
|
-
private stopTyping;
|
|
246
|
-
private resolveAccountId;
|
|
247
|
-
private maybeAddAckReaction;
|
|
248
|
-
private isAllowedByPolicy;
|
|
249
|
-
private resolveMentionState;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
declare class WeComChannel extends BaseChannel<Config["channels"]["wecom"]> {
|
|
253
|
-
name: string;
|
|
254
|
-
private server;
|
|
255
|
-
private accessToken;
|
|
256
|
-
private tokenExpiry;
|
|
257
|
-
private processedIds;
|
|
258
|
-
private processedSet;
|
|
259
|
-
constructor(config: Config["channels"]["wecom"], bus: MessageBus);
|
|
260
|
-
start(): Promise<void>;
|
|
261
|
-
stop(): Promise<void>;
|
|
262
|
-
send(msg: OutboundMessage): Promise<void>;
|
|
263
|
-
private handleCallbackRequest;
|
|
264
|
-
private handleVerificationRequest;
|
|
265
|
-
private handleInboundMessageRequest;
|
|
266
|
-
private verifySignature;
|
|
267
|
-
private getAccessToken;
|
|
268
|
-
private isDuplicate;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
declare class WhatsAppChannel extends BaseChannel<Config["channels"]["whatsapp"]> {
|
|
272
|
-
name: string;
|
|
273
|
-
private ws;
|
|
274
|
-
private connected;
|
|
275
|
-
constructor(config: Config["channels"]["whatsapp"], bus: MessageBus);
|
|
276
|
-
start(): Promise<void>;
|
|
277
|
-
stop(): Promise<void>;
|
|
278
|
-
send(msg: OutboundMessage): Promise<void>;
|
|
279
|
-
private handleBridgeMessage;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
type BuiltinChannelCreateContext = {
|
|
283
|
-
config: Config;
|
|
284
|
-
bus: MessageBus;
|
|
285
|
-
sessionManager?: SessionManager;
|
|
286
|
-
};
|
|
287
|
-
type BuiltinChannelRuntime = {
|
|
288
|
-
id: BuiltinChannelId;
|
|
289
|
-
isEnabled: (config: Config) => boolean;
|
|
290
|
-
createChannel: (context: BuiltinChannelCreateContext) => unknown;
|
|
291
|
-
};
|
|
292
|
-
declare const BUILTIN_CHANNEL_RUNTIMES: {
|
|
293
|
-
readonly telegram: {
|
|
294
|
-
readonly id: "telegram";
|
|
295
|
-
readonly isEnabled: (config: Config) => boolean;
|
|
296
|
-
readonly createChannel: (context: BuiltinChannelCreateContext) => TelegramChannel;
|
|
297
|
-
};
|
|
298
|
-
readonly whatsapp: {
|
|
299
|
-
readonly id: "whatsapp";
|
|
300
|
-
readonly isEnabled: (config: Config) => boolean;
|
|
301
|
-
readonly createChannel: (context: BuiltinChannelCreateContext) => WhatsAppChannel;
|
|
302
|
-
};
|
|
303
|
-
readonly discord: {
|
|
304
|
-
readonly id: "discord";
|
|
305
|
-
readonly isEnabled: (config: Config) => boolean;
|
|
306
|
-
readonly createChannel: (context: BuiltinChannelCreateContext) => DiscordChannel;
|
|
307
|
-
};
|
|
308
|
-
readonly feishu: {
|
|
309
|
-
readonly id: "feishu";
|
|
310
|
-
readonly isEnabled: (config: Config) => boolean;
|
|
311
|
-
readonly createChannel: (context: BuiltinChannelCreateContext) => FeishuChannel;
|
|
312
|
-
};
|
|
313
|
-
readonly mochat: {
|
|
314
|
-
readonly id: "mochat";
|
|
315
|
-
readonly isEnabled: (config: Config) => boolean;
|
|
316
|
-
readonly createChannel: (context: BuiltinChannelCreateContext) => MochatChannel;
|
|
317
|
-
};
|
|
318
|
-
readonly dingtalk: {
|
|
319
|
-
readonly id: "dingtalk";
|
|
320
|
-
readonly isEnabled: (config: Config) => boolean;
|
|
321
|
-
readonly createChannel: (context: BuiltinChannelCreateContext) => DingTalkChannel;
|
|
322
|
-
};
|
|
323
|
-
readonly wecom: {
|
|
324
|
-
readonly id: "wecom";
|
|
325
|
-
readonly isEnabled: (config: Config) => boolean;
|
|
326
|
-
readonly createChannel: (context: BuiltinChannelCreateContext) => WeComChannel;
|
|
327
|
-
};
|
|
328
|
-
readonly email: {
|
|
329
|
-
readonly id: "email";
|
|
330
|
-
readonly isEnabled: (config: Config) => boolean;
|
|
331
|
-
readonly createChannel: (context: BuiltinChannelCreateContext) => EmailChannel;
|
|
332
|
-
};
|
|
333
|
-
readonly slack: {
|
|
334
|
-
readonly id: "slack";
|
|
335
|
-
readonly isEnabled: (config: Config) => boolean;
|
|
336
|
-
readonly createChannel: (context: BuiltinChannelCreateContext) => SlackChannel;
|
|
337
|
-
};
|
|
338
|
-
readonly qq: {
|
|
339
|
-
readonly id: "qq";
|
|
340
|
-
readonly isEnabled: (config: Config) => boolean;
|
|
341
|
-
readonly createChannel: (context: BuiltinChannelCreateContext) => QQChannel;
|
|
342
|
-
};
|
|
343
|
-
};
|
|
344
|
-
type BuiltinChannelId = keyof typeof BUILTIN_CHANNEL_RUNTIMES;
|
|
345
|
-
declare const BUILTIN_CHANNEL_PLUGIN_IDS: BuiltinChannelId[];
|
|
346
|
-
declare function listBuiltinChannelRuntimes(): BuiltinChannelRuntime[];
|
|
347
|
-
declare function resolveBuiltinChannelRuntime(channelId: string): BuiltinChannelRuntime;
|
|
348
|
-
|
|
349
|
-
export { BUILTIN_CHANNEL_PLUGIN_IDS, type BuiltinChannelId, type BuiltinChannelRuntime, DingTalkChannel, DiscordChannel, EmailChannel, FeishuChannel, MochatChannel, QQChannel, SlackChannel, TelegramChannel, WeComChannel, WhatsAppChannel, listBuiltinChannelRuntimes, resolveBuiltinChannelRuntime };
|