@qwen-code/channel-wecom 0.28.1-preview.0 → 0.28.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/dist/index.d.ts CHANGED
@@ -3,6 +3,9 @@ export { WeComCallbackChannel } from './wecom-callback-adapter.js';
3
3
  export { callbackPlugin } from './callback-plugin.js';
4
4
  export { WeComWebhookChannel } from './WeComWebhookChannel.js';
5
5
  export { webhookPlugin } from './webhook-plugin.js';
6
+ export { ManagedWecomAdapter, wecomSettings } from './managed-wecom-adapter.js';
7
+ export type { WecomReplyContext, WecomSettings, ManagedWecomAdapterDeps, ManagedWecomAdapterOptions, } from './managed-wecom-adapter.js';
8
+ export { createManagedWecomDeps } from './managed-wecom-deps.js';
6
9
  import type { ChannelPlugin } from '@qwen-code/channel-base';
7
10
  export declare const plugin: ChannelPlugin;
8
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7D,eAAO,MAAM,MAAM,EAAE,aA+BpB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChF,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAGjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7D,eAAO,MAAM,MAAM,EAAE,aA+BpB,CAAC"}
package/dist/index.js CHANGED
@@ -3,6 +3,8 @@ export { WeComCallbackChannel } from './wecom-callback-adapter.js';
3
3
  export { callbackPlugin } from './callback-plugin.js';
4
4
  export { WeComWebhookChannel } from './WeComWebhookChannel.js';
5
5
  export { webhookPlugin } from './webhook-plugin.js';
6
+ export { ManagedWecomAdapter, wecomSettings } from './managed-wecom-adapter.js';
7
+ export { createManagedWecomDeps } from './managed-wecom-deps.js';
6
8
  import { WeComChannel } from './WeComAdapter.js';
7
9
  export const plugin = {
8
10
  channelType: 'wecom',
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,MAAM,CAAC,MAAM,MAAM,GAAkB;IACnC,WAAW,EAAE,OAAO;IACpB,WA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,WAAW,EAAE,OAAO;IACpB,WAAW,EAAE,OAAO;IACpB,oBAAoB,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;IACzC,yBAAyB,EAAE,CAAC,OAAO,CAAC;IACpC,UAAU,EAAE;QACV,MAAM,EAAE;YACN;gBACE,GAAG,EAAE,OAAO;gBACZ,KAAK,EAAE,QAAQ;gBACf,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,IAAI;gBACd,aAAa,EAAE,IAAI;aACpB;YACD;gBACE,GAAG,EAAE,QAAQ;gBACb,KAAK,EAAE,YAAY;gBACnB,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,IAAI;gBACd,aAAa,EAAE,IAAI;aACpB;YACD;gBACE,GAAG,EAAE,OAAO;gBACZ,KAAK,EAAE,eAAe;gBACtB,IAAI,EAAE,QAAQ;gBACd,aAAa,EAAE,IAAI;aACpB;SACF;KACF;IACD,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,CAC/C,IAAI,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC;CAClD,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Qwen Team
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { ManagedReceipt, ManagedInboundEvent } from '@qwen-code/channel-base';
7
+ export type { ManagedReceipt };
8
+ export declare const MANAGED_WECOM_PENDING_LIMIT = 32;
9
+ export declare const RECENT_LIMIT = 256;
10
+ export interface ManagedWecomPendingEvent {
11
+ eventId: string;
12
+ /**
13
+ * The full admission, persisted because the SDK pushes each message once
14
+ * and the provider never redelivers: after a restart the claim re-drives
15
+ * this exact event, never a rebuilt one.
16
+ */
17
+ event: ManagedInboundEvent;
18
+ inputId?: string;
19
+ held?: boolean;
20
+ }
21
+ export interface ManagedWecomOutboundSegment {
22
+ deliveryId: string;
23
+ ordinal: number;
24
+ messageId: string;
25
+ receipt?: ManagedReceipt;
26
+ }
27
+ export interface ManagedWecomState {
28
+ version: 1;
29
+ generation: number;
30
+ instanceRefusals?: number;
31
+ pending: ManagedWecomPendingEvent[];
32
+ outbound: ManagedWecomOutboundSegment[];
33
+ recent: string[];
34
+ }
35
+ export declare function validManagedWecomState(value: unknown): value is ManagedWecomState;
36
+ export declare class ManagedWecomStateStore {
37
+ readonly directory: string;
38
+ readonly file: string;
39
+ constructor(name: string, cwd: string, botId: string, identityKey?: string);
40
+ load(): ManagedWecomState | undefined;
41
+ save(state: ManagedWecomState): void;
42
+ }
43
+ //# sourceMappingURL=managed-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"managed-state.d.ts","sourceRoot":"","sources":["../src/managed-state.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoBH,OAAO,KAAK,EACV,cAAc,EACd,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AAEjC,YAAY,EAAE,cAAc,EAAE,CAAC;AAU/B,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAC9C,eAAO,MAAM,YAAY,MAAM,CAAC;AAEhC,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,KAAK,EAAE,mBAAmB,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,2BAA2B;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,CAAC,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,wBAAwB,EAAE,CAAC;IACpC,QAAQ,EAAE,2BAA2B,EAAE,CAAC;IACxC,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,iBAAiB,CAmF5B;AAED,qBAAa,sBAAsB;IACjC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,SAAK;IA4BtE,IAAI,IAAI,iBAAiB,GAAG,SAAS;IAiCrC,IAAI,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI;CAwBrC"}
@@ -0,0 +1,173 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Qwen Team
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { createHash, randomUUID } from 'node:crypto';
7
+ import { closeSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeFileSync, } from 'node:fs';
8
+ import { join } from 'node:path';
9
+ import { getGlobalQwenDir, getWorkspaceScopeDirName, MANAGED_OUTBOUND_LIMIT, validManagedReceipt, } from '@qwen-code/channel-base';
10
+ // The managed WeCom adapter's own locked state, mirroring the DingTalk store
11
+ // minus the webhook map: a WeCom reply travels over the live authenticated
12
+ // WebSocket keyed only by chatid, so there is no per-message bearer capability
13
+ // to persist. Every claim persists before its side effect, so a restart
14
+ // replays the same event or reports the same segment unknown, never a second
15
+ // input and never a second send. See
16
+ // docs/design/2026-11-16-managed-channel-wecom-adapter.md.
17
+ export const MANAGED_WECOM_PENDING_LIMIT = 32;
18
+ export const RECENT_LIMIT = 256;
19
+ export function validManagedWecomState(value) {
20
+ if (!value || typeof value !== 'object')
21
+ return false;
22
+ const state = value;
23
+ return (state.version === 1 &&
24
+ Number.isSafeInteger(state.generation) &&
25
+ state.generation >= 1 &&
26
+ (state.instanceRefusals === undefined ||
27
+ (Number.isSafeInteger(state.instanceRefusals) &&
28
+ state.instanceRefusals >= 0)) &&
29
+ Array.isArray(state.pending) &&
30
+ state.pending.length <= MANAGED_WECOM_PENDING_LIMIT &&
31
+ state.pending.every((entry) => entry &&
32
+ typeof entry.eventId === 'string' &&
33
+ entry.eventId.length > 0 &&
34
+ !!entry.event &&
35
+ typeof entry.event === 'object' &&
36
+ entry.event.platformEventId === entry.eventId &&
37
+ typeof entry.event.text === 'string' &&
38
+ (entry.event.subject === null ||
39
+ typeof entry.event.subject === 'string') &&
40
+ // The re-drive (resubmitPending) reads these fields; a partial state
41
+ // that loads would drop the already-accepted claim with a misleading
42
+ // line (allowlist) or submit it without chat/scope (open). Fail closed
43
+ // on any missing required field so the store refuses it for repair.
44
+ typeof entry.event.senderId === 'string' &&
45
+ entry.event.senderId.length > 0 &&
46
+ typeof entry.event.chatId === 'string' &&
47
+ entry.event.chatId.length > 0 &&
48
+ typeof entry.event.threadId === 'string' &&
49
+ entry.event.threadId.length > 0 &&
50
+ Number.isSafeInteger(entry.event.accountGeneration) &&
51
+ entry.event.accountGeneration >= 1 &&
52
+ entry.event.semanticRevision === 1 &&
53
+ !!entry.event.scope &&
54
+ entry.event.scope.kind === 'chat_thread' &&
55
+ // The nested carriers are load-bearing too: resubmitPending submits the
56
+ // whole event (the base contract fixes scope.senderId to null) and
57
+ // send() addresses the reply through replyContext.chatId and gates the
58
+ // whole delivery on replyContext.senderId (senderAllowed). Presence-only
59
+ // checks would load a hand-repaired state whose claim is then refused
60
+ // (scope) or whose reply settles rejected — silently, with no startup
61
+ // refusal naming the file — when chatId or senderId is missing.
62
+ entry.event.scope.senderId === null &&
63
+ typeof entry.event.scope.chatId === 'string' &&
64
+ entry.event.scope.chatId.length > 0 &&
65
+ typeof entry.event.scope.threadId === 'string' &&
66
+ entry.event.scope.threadId.length > 0 &&
67
+ Array.isArray(entry.event.attachments) &&
68
+ !!entry.event.replyContext &&
69
+ typeof entry.event.replyContext === 'object' &&
70
+ typeof entry.event.replyContext.chatId ===
71
+ 'string' &&
72
+ entry.event.replyContext.chatId.length > 0 &&
73
+ typeof entry.event.replyContext.senderId ===
74
+ 'string' &&
75
+ entry.event.replyContext.senderId.length >
76
+ 0 &&
77
+ (entry.inputId === undefined || typeof entry.inputId === 'string') &&
78
+ // held is persisted and re-read at startup; the stall re-arm reads
79
+ // truthiness while the lift and the probe sort require === true, so a
80
+ // non-boolean (e.g. "false") must fail closed, not load.
81
+ (entry.held === undefined || typeof entry.held === 'boolean')) &&
82
+ Array.isArray(state.outbound) &&
83
+ state.outbound.length <= MANAGED_OUTBOUND_LIMIT &&
84
+ state.outbound.every((entry) => entry &&
85
+ typeof entry.deliveryId === 'string' &&
86
+ entry.deliveryId.length > 0 &&
87
+ Number.isSafeInteger(entry.ordinal) &&
88
+ entry.ordinal >= 0 &&
89
+ typeof entry.messageId === 'string' &&
90
+ entry.messageId.length > 0 &&
91
+ validManagedReceipt(entry.receipt)) &&
92
+ Array.isArray(state.recent) &&
93
+ state.recent.length <= RECENT_LIMIT &&
94
+ state.recent.every((entry) => typeof entry === 'string'));
95
+ }
96
+ export class ManagedWecomStateStore {
97
+ directory;
98
+ file;
99
+ constructor(name, cwd, botId, identityKey = '') {
100
+ // The lock directory is keyed by the configured entry (channel name +
101
+ // botId) per workspace — NOT by destination — so two instances of the same
102
+ // bot entry contend for one connection lock even when they target different
103
+ // control-plane destinations: WeCom admits one connection per bot and kicks
104
+ // the other, so a per-destination lock would let both reach stream.connect()
105
+ // and displace each other. The ledger FILE beneath that directory is keyed
106
+ // by the full registration identity (control plane + tenant + channel +
107
+ // actor + workspace + cwd-relative), so a pending message staged under one
108
+ // registration is never loaded or replayed under another. The Legacy WeCom
109
+ // channel keeps no on-disk state and takes no lock.
110
+ const entryKey = createHash('sha256')
111
+ .update(`${name}\u0000${botId}`)
112
+ .digest('hex')
113
+ .slice(0, 16);
114
+ this.directory = join(getGlobalQwenDir(), 'channels', getWorkspaceScopeDirName(cwd), `wecom-${entryKey}`);
115
+ const ledgerKey = createHash('sha256')
116
+ .update(identityKey)
117
+ .digest('hex')
118
+ .slice(0, 16);
119
+ this.file = join(this.directory, `managed-state-${ledgerKey}.json`);
120
+ }
121
+ load() {
122
+ // Name the file and keep the cause, and keep an I/O failure distinguishable
123
+ // from a corrupt state: one entry directory now holds a ledger per
124
+ // registration, so the operator must know WHICH file is unreadable (e.g.
125
+ // EISDIR) versus merely invalid, while a sibling registration's healthy
126
+ // ledger sits beside it.
127
+ let raw;
128
+ try {
129
+ raw = readFileSync(this.file, 'utf8');
130
+ }
131
+ catch (error) {
132
+ if (error.code === 'ENOENT')
133
+ return undefined;
134
+ throw new Error(`Managed WeCom state at ${this.file} could not be read; restore it before restarting.`, { cause: error });
135
+ }
136
+ let value;
137
+ try {
138
+ value = JSON.parse(raw);
139
+ }
140
+ catch (error) {
141
+ throw new Error(`Managed WeCom state at ${this.file} is not valid JSON; restore it before restarting.`, { cause: error });
142
+ }
143
+ if (!validManagedWecomState(value)) {
144
+ throw new Error(`Managed WeCom state at ${this.file} is invalid; restore it before restarting.`);
145
+ }
146
+ return value;
147
+ }
148
+ save(state) {
149
+ mkdirSync(this.directory, { recursive: true, mode: 0o700 });
150
+ const temporary = join(this.directory, `${randomUUID()}.tmp`);
151
+ try {
152
+ const fd = openSync(temporary, 'wx', 0o600);
153
+ try {
154
+ writeFileSync(fd, JSON.stringify(state));
155
+ fsyncSync(fd);
156
+ }
157
+ finally {
158
+ closeSync(fd);
159
+ }
160
+ renameSync(temporary, this.file);
161
+ }
162
+ catch (error) {
163
+ // Keep the underlying fs error (ENOSPC/EACCES/EIO…) as the cause, like the
164
+ // DingTalk/GitHub/email sibling stores, so the adapter's loss diagnostic
165
+ // names the real fault instead of only the fixed sentence.
166
+ throw new Error('Managed WeCom state could not be saved; admission stopped.', { cause: error });
167
+ }
168
+ finally {
169
+ rmSync(temporary, { force: true });
170
+ }
171
+ }
172
+ }
173
+ //# sourceMappingURL=managed-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"managed-state.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EAAE,MAAM,CAAC,CAAC;QAC9D,IAAI,CAAC;YACH,MAAM,EAAE,GAAG,QAAQ,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;YAC5C,IAAI,CAAC;gBACH,aAAa,CAAC,EAAE,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;gBACzC,SAAS,CAAC,EAAE,CAAC,CAAC;YAChB,CAAC;oBAAS,CAAC;gBACT,SAAS,CAAC,EAAE,CAAC,CAAC;YAChB,CAAC;YACD,UAAU,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACnC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,2EAA2E;YAC3E,yEAAyE;YACzE,2DAA2D;YAC3D,MAAM,IAAI,KAAK,CACb,4DAA4D,EAC5D,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;QACJ,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Qwen Team
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { ManagedChannelPolicy, ManagedChannelControlPlane } from '@qwen-code/channel-base';
7
+ export type { ManagedReceipt } from './managed-state.js';
8
+ /** What a reply needs, committed with the input and echoed by the outbox. */
9
+ export interface WecomReplyContext {
10
+ chatId: string;
11
+ senderId: string;
12
+ botId: string;
13
+ }
14
+ export interface WecomSettings {
15
+ botId: string;
16
+ secret: string;
17
+ wsUrl?: string;
18
+ pollInterval: number;
19
+ /**
20
+ * True when a configured pollInterval was rejected and the default used.
21
+ * Reported by wecomSettings itself so the constructor's diagnostic never
22
+ * re-derives the clamp decision.
23
+ */
24
+ pollIntervalRewritten?: boolean;
25
+ }
26
+ /** A connected stream the adapter reads bot messages from. */
27
+ export interface ManagedWecomStreamClient {
28
+ connect(): Promise<void>;
29
+ disconnect(): void;
30
+ }
31
+ export interface ManagedWecomAdapterDeps {
32
+ readonly createStreamClient: (settings: WecomSettings, onMessage: (messageId: string, data: string) => void, onStopped: (reason: string) => void) => ManagedWecomStreamClient;
33
+ readonly sendMessage: (chatId: string, text: string) => Promise<void>;
34
+ /**
35
+ * Whether the live socket can currently send. The claim phase consults it so
36
+ * a transient disconnect (reconnect backoff) pauses delivery claims instead
37
+ * of claiming batches it can only settle unknown — the control plane only
38
+ * claims planned/partial deliveries, so each outage poll would otherwise take
39
+ * another batch out of automatic delivery.
40
+ */
41
+ readonly isConnected: () => boolean;
42
+ readonly lock: (directory: string, onCompromised: () => void) => Promise<() => Promise<void>>;
43
+ readonly now?: () => number;
44
+ readonly log?: (line: string) => void;
45
+ }
46
+ export interface ManagedWecomAdapterOptions {
47
+ readonly name: string;
48
+ readonly cwd: string;
49
+ readonly config: Readonly<Record<string, unknown>>;
50
+ readonly controlPlane: ManagedChannelControlPlane;
51
+ readonly deps: ManagedWecomAdapterDeps;
52
+ /** Off, the caller drives `tick()` itself (tests); on by default. */
53
+ readonly pollLoop?: boolean;
54
+ }
55
+ export declare function wecomSettings(config: Readonly<Record<string, unknown>>): WecomSettings;
56
+ export declare class ManagedWecomAdapter {
57
+ readonly settings: WecomSettings;
58
+ readonly policy: ManagedChannelPolicy;
59
+ private readonly store;
60
+ private readonly controlPlane;
61
+ private readonly deps;
62
+ private readonly log;
63
+ private readonly pollLoop;
64
+ private state?;
65
+ private stream?;
66
+ private releaseLock?;
67
+ private running;
68
+ private ownershipLost;
69
+ private displaced;
70
+ private loop?;
71
+ private abort?;
72
+ private registeredGeneration?;
73
+ private instanceStalled;
74
+ private loggedNoClaimSlot;
75
+ private lastDropCause?;
76
+ private loggedAcceptFailure;
77
+ private loggedRegistrationFailure;
78
+ constructor(options: ManagedWecomAdapterOptions);
79
+ get stateFile(): string;
80
+ get generation(): number | undefined;
81
+ connect(): Promise<void>;
82
+ disconnect(): Promise<void>;
83
+ /** One admission re-drive and one outbound pull, for callers that drive it. */
84
+ tick(): Promise<void>;
85
+ private onMessage;
86
+ private runLoop;
87
+ private senderAllowed;
88
+ private stageInbound;
89
+ private submit;
90
+ /**
91
+ * The stall exists to be lifted by the held claim's probe: when the last
92
+ * held claim leaves no probe remains, and a flag kept armed would gate every
93
+ * later tick. Whether the refusal streak survives depends on HOW the last
94
+ * held claim left: a fresh (non-replayed) admission proves the binding and
95
+ * resets the streak (submit() clears instanceRefusals before calling here);
96
+ * a per-message verdict drop, a policy drop, or a replayed answer leaves the
97
+ * streak standing, so the next instance-scoped refusal re-holds without a new
98
+ * first-occurrence drop. The caller passes which case it is so the resume line
99
+ * states the streak's actual fate rather than always claiming it stands.
100
+ */
101
+ private liftStallWhenNothingHeld;
102
+ private resubmitPending;
103
+ private isRegistrationRefusal;
104
+ private ensureRegistered;
105
+ private pullOutbox;
106
+ private send;
107
+ private reportOrphanedOutbound;
108
+ private persist;
109
+ private stop;
110
+ private release;
111
+ }
112
+ //# sourceMappingURL=managed-wecom-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"managed-wecom-adapter.d.ts","sourceRoot":"","sources":["../src/managed-wecom-adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,KAAK,EACV,oBAAoB,EAGpB,0BAA0B,EAC3B,MAAM,yBAAyB,CAAC;AAQjC,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAezD,6EAA6E;AAC7E,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,qBAAqB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