@qwen-code/channel-dws 0.22.2-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,168 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Qwen Team
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { PollingChannelBase, type ChannelAgentBridge, type ChannelBaseOptions, type ChannelConfig, type ChannelTaskLifecycleEvent, type CreatePairingRequestResult, type Envelope } from '@qwen-code/channel-base';
7
+ import { type DwsClientLike, type DwsImMessage, type DwsImTarget } from './dws-client.js';
8
+ interface DwsConfig extends ChannelConfig {
9
+ profile?: unknown;
10
+ watchTodos?: unknown;
11
+ }
12
+ interface PersistedImTarget {
13
+ conversationId: string;
14
+ target: DwsImTarget;
15
+ }
16
+ interface PersistedTodoState {
17
+ taskId: string;
18
+ fingerprint: string;
19
+ }
20
+ interface PersistedNotificationCheckpoint {
21
+ startTime: number;
22
+ endTime: number;
23
+ cursor: string;
24
+ }
25
+ interface PersistedDocumentNotification {
26
+ documentId: string;
27
+ commentKey: string;
28
+ request: string;
29
+ messageId: string;
30
+ conversationId: string;
31
+ senderId: string;
32
+ senderName: string;
33
+ retryAttempts?: number;
34
+ nextRetryAt?: number;
35
+ }
36
+ interface PersistedPendingMessage {
37
+ source: {
38
+ kind: 'direct';
39
+ } | {
40
+ kind: 'group-all';
41
+ } | {
42
+ kind: 'group';
43
+ conversationId: string;
44
+ };
45
+ message: DwsImMessage;
46
+ }
47
+ interface DwsCursor {
48
+ version: 1;
49
+ selfProfile?: string;
50
+ selfSenderIds: string[];
51
+ documentIds?: string[];
52
+ notificationWatermark?: number;
53
+ mentionWatermark?: number;
54
+ notificationCheckpoint?: PersistedNotificationCheckpoint;
55
+ mentionCheckpoint?: PersistedNotificationCheckpoint;
56
+ pendingDocumentNotifications?: PersistedDocumentNotification[];
57
+ pendingMessages?: PersistedPendingMessage[];
58
+ processedMessages: string[];
59
+ imTargets: PersistedImTarget[];
60
+ todosInitialized?: boolean;
61
+ todoTasks?: PersistedTodoState[];
62
+ pairingNotifications?: string[];
63
+ inboundFailures?: PersistedInboundFailure[];
64
+ }
65
+ /**
66
+ * Per-message failure accounting for the inbound turn path.
67
+ *
68
+ * A message whose turn throws is never marked processed and never advances
69
+ * the watermark, so history polling re-fetched and re-ran it as a FULL agent
70
+ * turn every poll, forever — one model call per iteration, with no cap and no
71
+ * backoff, while the pinned watermark made the query window grow without
72
+ * bound and the throw starved every newer message behind it. Pending-document
73
+ * replay already had exactly this accounting; the failure-retry path had
74
+ * none.
75
+ */
76
+ interface PersistedInboundFailure {
77
+ key: string;
78
+ attempts: number;
79
+ }
80
+ export declare class DwsChannel extends PollingChannelBase<DwsCursor> {
81
+ private readonly documentSet;
82
+ private readonly todoTargets;
83
+ private readonly userInstructions?;
84
+ private readonly client;
85
+ private readonly imStates;
86
+ private readonly watchTodos;
87
+ private readonly inboundReactionTargets;
88
+ private readonly activeReactionKeys;
89
+ private readonly sessionReactionKeys;
90
+ private readonly notifiedSenderPairingNotifications;
91
+ private readonly processingMessages;
92
+ private pollAbortController;
93
+ private lifecycleGeneration;
94
+ private connectionStartedAt;
95
+ private lastTodoPollAt;
96
+ private connected;
97
+ private notificationWatermarkPulledBack;
98
+ constructor(name: string, config: DwsConfig & Record<string, unknown>, bridge: ChannelAgentBridge, options?: ChannelBaseOptions, client?: DwsClientLike);
99
+ protected createInitialCursor(): DwsCursor;
100
+ protected validateCursor(parsed: unknown): DwsCursor | null;
101
+ connect(): Promise<void>;
102
+ private rememberDocumentId;
103
+ disconnect(): void;
104
+ supportsProactiveSend(): boolean;
105
+ protected get pollInterval(): number;
106
+ protected get todoPollInterval(): number;
107
+ protected preflightInbound(envelope: Envelope): boolean | Promise<boolean>;
108
+ protected onPairingRequired(chatId: string, result: CreatePairingRequestResult, threadId?: string, senderId?: string): Promise<void>;
109
+ sendMessage(chatId: string, text: string): Promise<void>;
110
+ private sendImText;
111
+ protected sendThreadMessage(chatId: string, threadId: string | undefined, text: string): Promise<void>;
112
+ protected sendResponseMessage(chatId: string, text: string, sessionId: string): Promise<void>;
113
+ protected pollOnce(): Promise<void>;
114
+ private pollTodos;
115
+ private processTodoTask;
116
+ private rememberTodoState;
117
+ private rememberPairingNotification;
118
+ private clearPairingNotifications;
119
+ private startImSource;
120
+ private startImSourceWithRetry;
121
+ private waitForImRetry;
122
+ private scheduleImRestart;
123
+ private logImError;
124
+ private handleImMessage;
125
+ private processImMessage;
126
+ /**
127
+ * Account one failed inbound turn, and drop the message once its budget is
128
+ * spent.
129
+ *
130
+ * Returns whether the caller should rethrow. Under budget it should — the
131
+ * throw is what drives redelivery retry, and existing contracts depend on
132
+ * it. Once the budget is spent the message is marked processed and the
133
+ * error is swallowed: the throw used to abort the caller's sorted loop, so
134
+ * one poison message starved every newer message behind it and never
135
+ * cleared, because nothing ever marked it processed.
136
+ *
137
+ * `dropMessage` is what "stop re-running this" means for the caller's
138
+ * surface. Marking the key processed is right for a message, but a todo is
139
+ * re-fetched by fingerprint and a document notification carries its own
140
+ * key, so those pass their own.
141
+ */
142
+ private recordInboundFailure;
143
+ private clearInboundFailure;
144
+ private rememberPendingMessage;
145
+ private removePendingMessage;
146
+ private processDocumentNotification;
147
+ private replayPendingMessages;
148
+ private replayPendingDocumentNotifications;
149
+ private hasPendingDocumentNotification;
150
+ private rememberPendingDocumentNotification;
151
+ private removePendingDocumentNotification;
152
+ private deferPendingDocumentNotification;
153
+ private reactionKey;
154
+ private rememberInboundReactionTarget;
155
+ private logReactionFailure;
156
+ private untrackSessionReaction;
157
+ private startReaction;
158
+ private stopReaction;
159
+ protected onTaskLifecycle(event: ChannelTaskLifecycleEvent): void;
160
+ onSessionDied(sessionId: string): void;
161
+ private isSelfMessage;
162
+ private readDocumentContext;
163
+ private rememberImTarget;
164
+ private findImTarget;
165
+ private markProcessedMessage;
166
+ }
167
+ export {};
168
+ //# sourceMappingURL=dws-channel.d.ts.map
@@ -0,0 +1 @@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