@qwen-code/channel-dingtalk 0.21.0-preview.0

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,102 @@
1
+ import { ChannelBase } from '@qwen-code/channel-base';
2
+ import type { ChannelConfig, ChannelBaseOptions, Envelope, ChannelAgentBridge, ChannelTaskLifecycleEvent, SessionTarget } from '@qwen-code/channel-base';
3
+ export declare class DingtalkChannel extends ChannelBase {
4
+ private client;
5
+ private readonly atSender;
6
+ private connectionManager?;
7
+ private seenMessages;
8
+ private mentionTargets;
9
+ private sessionMentionTargets;
10
+ private textReplySessions;
11
+ private bufferedMentionTargets;
12
+ private bufferedMentionTargetsBySession;
13
+ private dedupTimer?;
14
+ /** Map conversationId → latest sessionWebhook URL for sending replies. */
15
+ private webhooks;
16
+ private activeReactionKeys;
17
+ /** sessionId → reaction keys, so a dead session's reactions can be recalled. */
18
+ private sessionReactionKeys;
19
+ /**
20
+ * Real inbound message ids (insertion-ordered, size-capped). Unlike the
21
+ * TTL-swept seenMessages dedup map, entries survive long queue waits, so a
22
+ * turn that starts minutes after its message arrived still gets a reaction.
23
+ */
24
+ private inboundMessageIds;
25
+ /**
26
+ * Token cache for proactive sends. The stream SDK only refreshes its token
27
+ * on (re)connect, so a long-lived socket serves a stale one after ~2h.
28
+ */
29
+ private proactiveToken?;
30
+ constructor(name: string, config: ChannelConfig, bridge: ChannelAgentBridge, options?: ChannelBaseOptions);
31
+ private createClient;
32
+ private installStructuredDownstreamHandler;
33
+ private registerMessageHandler;
34
+ private onDownStream;
35
+ private callDownStreamHandler;
36
+ private decodeDownStream;
37
+ connect(): Promise<void>;
38
+ /**
39
+ * A group message with no conversationId can't be routed to a stable shared
40
+ * session (chatId would fall back to the expiring sessionWebhook), so it is
41
+ * dropped on ingestion. Exposed for testing the drop rule.
42
+ */
43
+ static isUnroutableGroupMessage(isGroup: boolean, conversationId: string | undefined): boolean;
44
+ private sendReply;
45
+ private sendTextReply;
46
+ sendMessage(chatId: string, text: string): Promise<void>;
47
+ supportsProactiveSend(): boolean;
48
+ protected supportsProactiveTarget(target: SessionTarget): boolean;
49
+ protected supportsProactiveWebhookTarget(target: SessionTarget): boolean;
50
+ /**
51
+ * Single-shot cold send: a failed chunk aborts the remainder (already-sent
52
+ * chunks are not recalled) and the error surfaces in the loop's lastError.
53
+ */
54
+ protected pushProactive(target: SessionTarget, text: string): Promise<void>;
55
+ private getProactiveToken;
56
+ private sendProactiveChunk;
57
+ private getAccessToken;
58
+ private emotionApi;
59
+ private attachReaction;
60
+ private recallReaction;
61
+ disconnect(): void;
62
+ /** Stable API targets are conversation or user IDs, never webhook URLs. */
63
+ private isStableTargetId;
64
+ private reactionKey;
65
+ private rememberInboundMessageId;
66
+ private logReactionFailure;
67
+ private startReaction;
68
+ private stopReaction;
69
+ /** Recall reactions left behind when a session dies without terminal lifecycle events. */
70
+ onSessionDied(sessionId: string): void;
71
+ protected onTaskLifecycle(event: ChannelTaskLifecycleEvent): void;
72
+ protected onPromptBufferDropped(_chatId: string, sessionId: string, messageIds: string[]): void;
73
+ protected onPromptBufferDrained(_chatId: string, sessionId: string, messageIds: string[]): void;
74
+ protected onPromptBuffered(_chatId: string, sessionId: string, messageId?: string): void;
75
+ protected onPromptStart(chatId: string, sessionId: string, messageId?: string): void;
76
+ handleInbound(envelope: Envelope): Promise<void>;
77
+ protected processInbound(envelope: Envelope): Promise<void>;
78
+ private untrackBufferedMentionTarget;
79
+ protected onPromptEnd(chatId: string, sessionId: string, messageId?: string): void;
80
+ protected sendResponseMessage(chatId: string, text: string, sessionId: string): Promise<void>;
81
+ /**
82
+ * Extract quoted/referenced message context from a reply.
83
+ * DingTalk provides this via text.repliedMsg (newer) or quoteMessage (legacy).
84
+ */
85
+ private extractQuotedContext;
86
+ /**
87
+ * Build a text summary from a repliedMsg, handling text, richText, and
88
+ * media message types with placeholders.
89
+ */
90
+ private summarizeRepliedContent;
91
+ /**
92
+ * Extract text and media download codes from an incoming DingTalk message.
93
+ * Handles text, richText, picture, file, audio, and video message types.
94
+ */
95
+ private extractContent;
96
+ /**
97
+ * Download a media file and attach it to the envelope.
98
+ * Images → base64 in envelope; files → saved to temp dir with path in text.
99
+ */
100
+ private attachMedia;
101
+ private onMessage;
102
+ }