opencode-oncall 0.1.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.
- package/LICENSE +151 -0
- package/README.md +50 -0
- package/dist/common-settings-actions.d.ts +15 -0
- package/dist/common-settings-actions.js +48 -0
- package/dist/common-settings-store.d.ts +1 -0
- package/dist/common-settings-store.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/plugin-hooks.d.ts +51 -0
- package/dist/plugin-hooks.js +288 -0
- package/dist/plugin.d.ts +10 -0
- package/dist/plugin.js +115 -0
- package/dist/settings-store.d.ts +50 -0
- package/dist/settings-store.js +214 -0
- package/dist/store-paths.d.ts +16 -0
- package/dist/store-paths.js +61 -0
- package/dist/ui/wechat-menu.d.ts +26 -0
- package/dist/ui/wechat-menu.js +90 -0
- package/dist/wechat/bind-flow.d.ts +29 -0
- package/dist/wechat/bind-flow.js +207 -0
- package/dist/wechat/bridge.d.ts +136 -0
- package/dist/wechat/bridge.js +1059 -0
- package/dist/wechat/broker-client.d.ts +23 -0
- package/dist/wechat/broker-client.js +274 -0
- package/dist/wechat/broker-endpoint.d.ts +21 -0
- package/dist/wechat/broker-endpoint.js +78 -0
- package/dist/wechat/broker-entry.d.ts +123 -0
- package/dist/wechat/broker-entry.js +1321 -0
- package/dist/wechat/broker-launcher.d.ts +37 -0
- package/dist/wechat/broker-launcher.js +418 -0
- package/dist/wechat/broker-mutation-queue.d.ts +93 -0
- package/dist/wechat/broker-mutation-queue.js +126 -0
- package/dist/wechat/broker-server.d.ts +86 -0
- package/dist/wechat/broker-server.js +1340 -0
- package/dist/wechat/broker-state-store.d.ts +335 -0
- package/dist/wechat/broker-state-store.js +1964 -0
- package/dist/wechat/command-parser.d.ts +18 -0
- package/dist/wechat/command-parser.js +58 -0
- package/dist/wechat/compat/jiti-loader.d.ts +27 -0
- package/dist/wechat/compat/jiti-loader.js +118 -0
- package/dist/wechat/compat/openclaw-account-helpers.d.ts +29 -0
- package/dist/wechat/compat/openclaw-account-helpers.js +60 -0
- package/dist/wechat/compat/openclaw-bind-helpers.d.ts +29 -0
- package/dist/wechat/compat/openclaw-bind-helpers.js +169 -0
- package/dist/wechat/compat/openclaw-guided-smoke.d.ts +180 -0
- package/dist/wechat/compat/openclaw-guided-smoke.js +1134 -0
- package/dist/wechat/compat/openclaw-public-entry.d.ts +33 -0
- package/dist/wechat/compat/openclaw-public-entry.js +62 -0
- package/dist/wechat/compat/openclaw-public-helpers.d.ts +70 -0
- package/dist/wechat/compat/openclaw-public-helpers.js +68 -0
- package/dist/wechat/compat/openclaw-qr-gateway.d.ts +15 -0
- package/dist/wechat/compat/openclaw-qr-gateway.js +39 -0
- package/dist/wechat/compat/openclaw-smoke.d.ts +48 -0
- package/dist/wechat/compat/openclaw-smoke.js +100 -0
- package/dist/wechat/compat/openclaw-sync-buf.d.ts +24 -0
- package/dist/wechat/compat/openclaw-sync-buf.js +80 -0
- package/dist/wechat/compat/openclaw-updates-send.d.ts +47 -0
- package/dist/wechat/compat/openclaw-updates-send.js +38 -0
- package/dist/wechat/compat/qrcode-terminal-loader.d.ts +12 -0
- package/dist/wechat/compat/qrcode-terminal-loader.js +16 -0
- package/dist/wechat/compat/slash-guard.d.ts +11 -0
- package/dist/wechat/compat/slash-guard.js +24 -0
- package/dist/wechat/dead-letter-store.d.ts +48 -0
- package/dist/wechat/dead-letter-store.js +224 -0
- package/dist/wechat/debug-bundle-collector.d.ts +49 -0
- package/dist/wechat/debug-bundle-collector.js +580 -0
- package/dist/wechat/debug-bundle-flow.d.ts +37 -0
- package/dist/wechat/debug-bundle-flow.js +180 -0
- package/dist/wechat/debug-bundle-redaction.d.ts +14 -0
- package/dist/wechat/debug-bundle-redaction.js +339 -0
- package/dist/wechat/handle.d.ts +10 -0
- package/dist/wechat/handle.js +57 -0
- package/dist/wechat/ipc-auth.d.ts +6 -0
- package/dist/wechat/ipc-auth.js +39 -0
- package/dist/wechat/latest-account-state-store.d.ts +8 -0
- package/dist/wechat/latest-account-state-store.js +38 -0
- package/dist/wechat/notification-dispatcher.d.ts +34 -0
- package/dist/wechat/notification-dispatcher.js +266 -0
- package/dist/wechat/notification-format.d.ts +15 -0
- package/dist/wechat/notification-format.js +196 -0
- package/dist/wechat/notification-store.d.ts +72 -0
- package/dist/wechat/notification-store.js +807 -0
- package/dist/wechat/notification-types.d.ts +37 -0
- package/dist/wechat/notification-types.js +1 -0
- package/dist/wechat/openclaw-account-adapter.d.ts +30 -0
- package/dist/wechat/openclaw-account-adapter.js +60 -0
- package/dist/wechat/operator-store.d.ts +9 -0
- package/dist/wechat/operator-store.js +69 -0
- package/dist/wechat/protocol.d.ts +150 -0
- package/dist/wechat/protocol.js +197 -0
- package/dist/wechat/question-interaction.d.ts +24 -0
- package/dist/wechat/question-interaction.js +180 -0
- package/dist/wechat/request-store.d.ts +108 -0
- package/dist/wechat/request-store.js +669 -0
- package/dist/wechat/session-digest.d.ts +50 -0
- package/dist/wechat/session-digest.js +167 -0
- package/dist/wechat/state-paths.d.ts +26 -0
- package/dist/wechat/state-paths.js +92 -0
- package/dist/wechat/status-format.d.ts +26 -0
- package/dist/wechat/status-format.js +616 -0
- package/dist/wechat/token-store.d.ts +20 -0
- package/dist/wechat/token-store.js +193 -0
- package/dist/wechat/wechat-status-runtime.d.ts +89 -0
- package/dist/wechat/wechat-status-runtime.js +518 -0
- package/package.json +74 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
|
2
|
+
import { loadOpenClawWeixinBindHelpers } from "./compat/openclaw-bind-helpers.js";
|
|
3
|
+
import { loadQrCodeTerminal } from "./compat/qrcode-terminal-loader.js";
|
|
4
|
+
import { writeWechatLatestAccountState } from "./latest-account-state-store.js";
|
|
5
|
+
import { buildOpenClawMenuAccount } from "./openclaw-account-adapter.js";
|
|
6
|
+
import { bindOperator, readOperatorBinding, rebindOperator, resetOperatorBinding, } from "./operator-store.js";
|
|
7
|
+
const DEFAULT_QR_WAIT_TIMEOUT_MS = 480000;
|
|
8
|
+
function pickFirstNonEmptyString(...values) {
|
|
9
|
+
for (const value of values) {
|
|
10
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
function toErrorMessage(error) {
|
|
17
|
+
if (error instanceof Error && error.message.trim().length > 0) {
|
|
18
|
+
return error.message;
|
|
19
|
+
}
|
|
20
|
+
return String(error);
|
|
21
|
+
}
|
|
22
|
+
function pickQrTerminal(value) {
|
|
23
|
+
return pickFirstNonEmptyString(value?.qrTerminal);
|
|
24
|
+
}
|
|
25
|
+
function pickQrUrl(value) {
|
|
26
|
+
return pickFirstNonEmptyString(value?.qrDataUrl);
|
|
27
|
+
}
|
|
28
|
+
function isTimeoutWaitResult(value) {
|
|
29
|
+
return Boolean(value &&
|
|
30
|
+
typeof value === "object" &&
|
|
31
|
+
"status" in value &&
|
|
32
|
+
String(value.status) === "timeout");
|
|
33
|
+
}
|
|
34
|
+
async function rollbackBinding(action, previousOperatorBinding, persistOperatorRebinding, clearOperatorBinding) {
|
|
35
|
+
if (action === "wechat-rebind" && previousOperatorBinding) {
|
|
36
|
+
await persistOperatorRebinding(previousOperatorBinding).catch(() => { });
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
await clearOperatorBinding().catch(() => { });
|
|
40
|
+
}
|
|
41
|
+
function isSameOperatorBinding(left, right) {
|
|
42
|
+
if (!left || !right) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
return (left.wechatAccountId === right.wechatAccountId &&
|
|
46
|
+
left.userId === right.userId &&
|
|
47
|
+
left.boundAt === right.boundAt);
|
|
48
|
+
}
|
|
49
|
+
async function renderQrTerminalDefault(input) {
|
|
50
|
+
const qrcodeTerminal = loadQrCodeTerminal();
|
|
51
|
+
return await new Promise((resolve) => {
|
|
52
|
+
qrcodeTerminal.generate(input.value, { small: true }, (output) => {
|
|
53
|
+
resolve(typeof output === "string" && output.trim().length > 0
|
|
54
|
+
? output
|
|
55
|
+
: undefined);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
export async function runWechatBindFlow(input) {
|
|
60
|
+
const now = input.now ?? Date.now;
|
|
61
|
+
const loadPublicHelpers = input.loadPublicHelpers ?? loadOpenClawWeixinBindHelpers;
|
|
62
|
+
const persistOperatorBinding = input.bindOperator ?? bindOperator;
|
|
63
|
+
const persistOperatorRebinding = input.rebindOperator ?? rebindOperator;
|
|
64
|
+
const loadOperatorBinding = input.readOperatorBinding ?? readOperatorBinding;
|
|
65
|
+
const clearOperatorBinding = input.resetOperatorBinding ?? resetOperatorBinding;
|
|
66
|
+
const renderQrTerminal = input.renderQrTerminal ?? renderQrTerminalDefault;
|
|
67
|
+
const writeLine = input.writeLine ??
|
|
68
|
+
(async (line) => {
|
|
69
|
+
process.stdout.write(`${line}\n`);
|
|
70
|
+
});
|
|
71
|
+
try {
|
|
72
|
+
const helpers = await loadPublicHelpers();
|
|
73
|
+
const started = await Promise.resolve(helpers.qrGateway.loginWithQrStart({
|
|
74
|
+
source: "menu",
|
|
75
|
+
action: input.action,
|
|
76
|
+
}));
|
|
77
|
+
const qrTerminal = pickQrTerminal(started);
|
|
78
|
+
const qrUrl = pickQrUrl(started);
|
|
79
|
+
const qrStartMessage = pickFirstNonEmptyString(started?.message, started?.detail, started?.reason);
|
|
80
|
+
const sessionKey = pickFirstNonEmptyString(started?.sessionKey);
|
|
81
|
+
if (!sessionKey) {
|
|
82
|
+
throw new Error("missing sessionKey from qr start");
|
|
83
|
+
}
|
|
84
|
+
if (qrTerminal) {
|
|
85
|
+
await writeLine(qrTerminal);
|
|
86
|
+
}
|
|
87
|
+
else if (qrUrl) {
|
|
88
|
+
const renderedQr = await renderQrTerminal({ value: qrUrl }).catch(() => undefined);
|
|
89
|
+
if (renderedQr) {
|
|
90
|
+
await writeLine(renderedQr);
|
|
91
|
+
}
|
|
92
|
+
await writeLine(`QR URL fallback: ${qrUrl}`);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
throw new Error(qrStartMessage || "invalid qr login result: missing qr code or qr url");
|
|
96
|
+
}
|
|
97
|
+
const waited = await Promise.resolve(helpers.qrGateway.loginWithQrWait({
|
|
98
|
+
timeoutMs: DEFAULT_QR_WAIT_TIMEOUT_MS,
|
|
99
|
+
sessionKey,
|
|
100
|
+
}));
|
|
101
|
+
if (isTimeoutWaitResult(waited)) {
|
|
102
|
+
throw new Error("qr login timed out before completion");
|
|
103
|
+
}
|
|
104
|
+
if (waited &&
|
|
105
|
+
typeof waited === "object" &&
|
|
106
|
+
"connected" in waited &&
|
|
107
|
+
waited.connected === false) {
|
|
108
|
+
throw new Error("qr login did not complete");
|
|
109
|
+
}
|
|
110
|
+
const rawAccountId = pickFirstNonEmptyString(waited?.accountId);
|
|
111
|
+
if (!rawAccountId) {
|
|
112
|
+
throw new Error("missing accountId after qr login");
|
|
113
|
+
}
|
|
114
|
+
const accountId = normalizeAccountId(rawAccountId);
|
|
115
|
+
const boundAt = now();
|
|
116
|
+
const previousOperatorBinding = input.action === "wechat-rebind"
|
|
117
|
+
? await loadOperatorBinding()
|
|
118
|
+
: undefined;
|
|
119
|
+
const userIdFromWait = pickFirstNonEmptyString(waited?.userId);
|
|
120
|
+
let menuAccount;
|
|
121
|
+
let boundUserId = "";
|
|
122
|
+
const botToken = pickFirstNonEmptyString(waited?.botToken);
|
|
123
|
+
let shouldRollbackBinding = false;
|
|
124
|
+
let attemptedOperatorBinding;
|
|
125
|
+
try {
|
|
126
|
+
const menuAccountState = {
|
|
127
|
+
accountId,
|
|
128
|
+
token: "",
|
|
129
|
+
baseUrl: "https://ilinkai.weixin.qq.com",
|
|
130
|
+
};
|
|
131
|
+
menuAccount = await buildOpenClawMenuAccount({
|
|
132
|
+
latestAccountState: menuAccountState,
|
|
133
|
+
accountHelpers: helpers.accountHelpers,
|
|
134
|
+
});
|
|
135
|
+
const userId = pickFirstNonEmptyString(menuAccount?.userId, userIdFromWait);
|
|
136
|
+
if (!userId) {
|
|
137
|
+
throw new Error("missing userId after qr login");
|
|
138
|
+
}
|
|
139
|
+
boundUserId = userId;
|
|
140
|
+
attemptedOperatorBinding = {
|
|
141
|
+
wechatAccountId: accountId,
|
|
142
|
+
userId,
|
|
143
|
+
boundAt,
|
|
144
|
+
};
|
|
145
|
+
if (input.action === "wechat-rebind") {
|
|
146
|
+
shouldRollbackBinding = true;
|
|
147
|
+
await persistOperatorRebinding(attemptedOperatorBinding);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
shouldRollbackBinding = true;
|
|
151
|
+
await persistOperatorBinding(attemptedOperatorBinding);
|
|
152
|
+
}
|
|
153
|
+
const settings = await input.readCommonSettings();
|
|
154
|
+
const currentNotifications = settings.wechat?.notifications;
|
|
155
|
+
const notifications = {
|
|
156
|
+
enabled: currentNotifications?.enabled ?? true,
|
|
157
|
+
question: currentNotifications?.question ?? true,
|
|
158
|
+
permission: currentNotifications?.permission ?? true,
|
|
159
|
+
sessionError: currentNotifications?.sessionError ?? true,
|
|
160
|
+
retryError: currentNotifications?.retryError ?? true,
|
|
161
|
+
};
|
|
162
|
+
settings.wechat = {
|
|
163
|
+
...settings.wechat,
|
|
164
|
+
notifications,
|
|
165
|
+
primaryBinding: {
|
|
166
|
+
accountId,
|
|
167
|
+
userId,
|
|
168
|
+
name: menuAccount?.name,
|
|
169
|
+
enabled: menuAccount?.enabled,
|
|
170
|
+
configured: menuAccount?.configured,
|
|
171
|
+
boundAt,
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
await input.writeCommonSettings(settings);
|
|
175
|
+
if (botToken) {
|
|
176
|
+
await writeWechatLatestAccountState({
|
|
177
|
+
accountId,
|
|
178
|
+
token: botToken,
|
|
179
|
+
baseUrl: pickFirstNonEmptyString(waited?.baseUrl, menuAccountState.baseUrl) ?? "https://ilinkai.weixin.qq.com",
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
if (shouldRollbackBinding) {
|
|
185
|
+
const currentOperatorBinding = await loadOperatorBinding().catch(() => undefined);
|
|
186
|
+
if (isSameOperatorBinding(currentOperatorBinding, attemptedOperatorBinding)) {
|
|
187
|
+
await rollbackBinding(input.action, previousOperatorBinding, persistOperatorRebinding, clearOperatorBinding);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
accountId,
|
|
194
|
+
userId: boundUserId,
|
|
195
|
+
name: menuAccount?.name,
|
|
196
|
+
enabled: menuAccount?.enabled,
|
|
197
|
+
configured: menuAccount?.configured,
|
|
198
|
+
boundAt,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
if (input.action === "wechat-rebind") {
|
|
203
|
+
throw new Error(`wechat rebind failed: ${toErrorMessage(error)}`);
|
|
204
|
+
}
|
|
205
|
+
throw new Error(`wechat bind failed: ${toErrorMessage(error)}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { Message, Part, PermissionRequest, QuestionAnswer, QuestionRequest, Session, SessionStatus, Todo } from "@opencode-ai/sdk/v2";
|
|
2
|
+
import { connect } from "./broker-client.js";
|
|
3
|
+
import { connectOrSpawnBroker } from "./broker-launcher.js";
|
|
4
|
+
import { type SessionDigest } from "./session-digest.js";
|
|
5
|
+
import type { BrokerEnvelope, ReplyMutationResult, WechatNotificationCandidate } from "./protocol.js";
|
|
6
|
+
type SessionMessages = Array<{
|
|
7
|
+
info: Message;
|
|
8
|
+
parts: Part[];
|
|
9
|
+
}>;
|
|
10
|
+
type NotificationCandidateSnapshot = {
|
|
11
|
+
candidates: WechatNotificationCandidate[];
|
|
12
|
+
authoritative: boolean;
|
|
13
|
+
};
|
|
14
|
+
type SessionLite = Pick<Session, "id" | "title" | "directory" | "time"> & {
|
|
15
|
+
parentID?: string;
|
|
16
|
+
};
|
|
17
|
+
type SdkFieldsResult<T> = {
|
|
18
|
+
data: T | undefined;
|
|
19
|
+
error?: unknown;
|
|
20
|
+
request?: unknown;
|
|
21
|
+
response?: unknown;
|
|
22
|
+
};
|
|
23
|
+
type SdkReadResult<T> = T | SdkFieldsResult<T>;
|
|
24
|
+
type WechatBridgeClient = {
|
|
25
|
+
session: {
|
|
26
|
+
list: () => Promise<SdkReadResult<SessionLite[]>>;
|
|
27
|
+
status: () => Promise<SdkReadResult<Record<string, SessionStatus | undefined>>>;
|
|
28
|
+
todo: (parameters: {
|
|
29
|
+
sessionID: string;
|
|
30
|
+
} | string) => Promise<SdkReadResult<Todo[]>>;
|
|
31
|
+
messages: (parameters: {
|
|
32
|
+
sessionID: string;
|
|
33
|
+
limit?: number;
|
|
34
|
+
} | string) => Promise<SdkReadResult<SessionMessages>>;
|
|
35
|
+
reply?: (input: {
|
|
36
|
+
sessionID: string;
|
|
37
|
+
text: string;
|
|
38
|
+
}) => Promise<SdkReadResult<unknown>>;
|
|
39
|
+
};
|
|
40
|
+
question: {
|
|
41
|
+
list: () => Promise<SdkReadResult<QuestionRequest[]>>;
|
|
42
|
+
reply?: (input: {
|
|
43
|
+
requestID: string;
|
|
44
|
+
answers: QuestionAnswer[];
|
|
45
|
+
}) => Promise<SdkReadResult<unknown>>;
|
|
46
|
+
};
|
|
47
|
+
permission: {
|
|
48
|
+
list: () => Promise<SdkReadResult<PermissionRequest[]>>;
|
|
49
|
+
reply?: (input: {
|
|
50
|
+
requestID: string;
|
|
51
|
+
reply: "once" | "always" | "reject";
|
|
52
|
+
message?: string;
|
|
53
|
+
}) => Promise<SdkReadResult<unknown>>;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
export type InstanceUnavailableKind = "sessionStatus" | "questionList" | "permissionList";
|
|
57
|
+
export type WechatInstanceStatusSnapshot = {
|
|
58
|
+
instanceID: string;
|
|
59
|
+
instanceName: string;
|
|
60
|
+
pid: number;
|
|
61
|
+
projectName?: string;
|
|
62
|
+
directory: string;
|
|
63
|
+
collectedAt: number;
|
|
64
|
+
sessions: SessionDigest[];
|
|
65
|
+
unavailable?: InstanceUnavailableKind[];
|
|
66
|
+
};
|
|
67
|
+
export type WechatFallbackToast = {
|
|
68
|
+
wechatAccountId: string;
|
|
69
|
+
userId: string;
|
|
70
|
+
message: string;
|
|
71
|
+
reason: "deliveryFailed";
|
|
72
|
+
registrationEpoch?: string;
|
|
73
|
+
};
|
|
74
|
+
export type WechatBridgeInput = {
|
|
75
|
+
instanceID: string;
|
|
76
|
+
instanceName: string;
|
|
77
|
+
pid: number;
|
|
78
|
+
projectName?: string;
|
|
79
|
+
directory: string;
|
|
80
|
+
client: WechatBridgeClient;
|
|
81
|
+
liveReadTimeoutMs?: number;
|
|
82
|
+
getActiveSessionID?: () => string | undefined;
|
|
83
|
+
onDiagnosticEvent?: (event: WechatBridgeDiagnosticEvent) => Promise<void> | void;
|
|
84
|
+
onFallbackToast?: (payload: WechatFallbackToast) => Promise<void> | void;
|
|
85
|
+
};
|
|
86
|
+
export type WechatBridge = {
|
|
87
|
+
collectStatusSnapshot: () => Promise<WechatInstanceStatusSnapshot>;
|
|
88
|
+
collectNotificationCandidates: () => Promise<WechatNotificationCandidate[]>;
|
|
89
|
+
collectNotificationCandidateSnapshot?: () => Promise<NotificationCandidateSnapshot>;
|
|
90
|
+
resyncBrokerState?: (input?: {
|
|
91
|
+
reason?: "brokerReconnect" | "manual";
|
|
92
|
+
}) => Promise<WechatInstanceStatusSnapshot>;
|
|
93
|
+
handleBrokerEnvelope?: (envelope: BrokerEnvelope) => Promise<ReplyMutationResult | null>;
|
|
94
|
+
};
|
|
95
|
+
export type WechatBridgeLifecycleInput = {
|
|
96
|
+
client: WechatBridgeClient;
|
|
97
|
+
project?: {
|
|
98
|
+
id?: string;
|
|
99
|
+
name?: string;
|
|
100
|
+
};
|
|
101
|
+
directory?: string;
|
|
102
|
+
serverUrl?: URL;
|
|
103
|
+
initialBrokerPromise?: Promise<{
|
|
104
|
+
endpoint: string;
|
|
105
|
+
}>;
|
|
106
|
+
statusCollectionEnabled?: boolean;
|
|
107
|
+
heartbeatIntervalMs?: number;
|
|
108
|
+
getActiveSessionID?: () => string | undefined;
|
|
109
|
+
onFallbackToast?: (payload: WechatFallbackToast) => Promise<void> | void;
|
|
110
|
+
};
|
|
111
|
+
export type WechatBridgeLifecycle = {
|
|
112
|
+
close: () => Promise<void>;
|
|
113
|
+
};
|
|
114
|
+
type WechatBridgeLifecycleDeps = {
|
|
115
|
+
connectOrSpawnBrokerImpl?: typeof connectOrSpawnBroker;
|
|
116
|
+
connectImpl?: typeof connect;
|
|
117
|
+
setIntervalImpl?: typeof setInterval;
|
|
118
|
+
clearIntervalImpl?: typeof clearInterval;
|
|
119
|
+
};
|
|
120
|
+
type WechatBridgeDiagnosticEvent = {
|
|
121
|
+
type: "collectStatusCompleted";
|
|
122
|
+
instanceID: string;
|
|
123
|
+
durationMs: number;
|
|
124
|
+
sessionCount: number;
|
|
125
|
+
unavailable?: InstanceUnavailableKind[];
|
|
126
|
+
} | {
|
|
127
|
+
type: "bridgeResyncFailed";
|
|
128
|
+
code: "bridgeResyncFailed";
|
|
129
|
+
instanceID: string;
|
|
130
|
+
reason: "brokerReconnect" | "manual";
|
|
131
|
+
durationMs: number;
|
|
132
|
+
error: string;
|
|
133
|
+
};
|
|
134
|
+
export declare function createWechatBridge(input: WechatBridgeInput): WechatBridge;
|
|
135
|
+
export declare function createWechatBridgeLifecycle(input: WechatBridgeLifecycleInput, deps?: WechatBridgeLifecycleDeps): Promise<WechatBridgeLifecycle>;
|
|
136
|
+
export {};
|