mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 00:48:27 +00:00
feat: multi-agent routing + multi-account providers
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { loadConfig } from "../../config/config.js";
|
||||
import { defaultRuntime } from "../../runtime.js";
|
||||
import { resolveWhatsAppAccount } from "../../web/accounts.js";
|
||||
import { startWebLoginWithQr, waitForWebLogin } from "../../web/login-qr.js";
|
||||
import { logoutWeb } from "../../web/session.js";
|
||||
import {
|
||||
@@ -25,7 +27,11 @@ export const webHandlers: GatewayRequestHandlers = {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await context.stopWhatsAppProvider();
|
||||
const accountId =
|
||||
typeof (params as { accountId?: unknown }).accountId === "string"
|
||||
? (params as { accountId?: string }).accountId
|
||||
: undefined;
|
||||
await context.stopWhatsAppProvider(accountId);
|
||||
const result = await startWebLoginWithQr({
|
||||
force: Boolean((params as { force?: boolean }).force),
|
||||
timeoutMs:
|
||||
@@ -33,6 +39,7 @@ export const webHandlers: GatewayRequestHandlers = {
|
||||
? (params as { timeoutMs?: number }).timeoutMs
|
||||
: undefined,
|
||||
verbose: Boolean((params as { verbose?: boolean }).verbose),
|
||||
accountId,
|
||||
});
|
||||
respond(true, result, undefined);
|
||||
} catch (err) {
|
||||
@@ -56,14 +63,19 @@ export const webHandlers: GatewayRequestHandlers = {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const accountId =
|
||||
typeof (params as { accountId?: unknown }).accountId === "string"
|
||||
? (params as { accountId?: string }).accountId
|
||||
: undefined;
|
||||
const result = await waitForWebLogin({
|
||||
timeoutMs:
|
||||
typeof (params as { timeoutMs?: unknown }).timeoutMs === "number"
|
||||
? (params as { timeoutMs?: number }).timeoutMs
|
||||
: undefined,
|
||||
accountId,
|
||||
});
|
||||
if (result.connected) {
|
||||
await context.startWhatsAppProvider();
|
||||
await context.startWhatsAppProvider(accountId);
|
||||
}
|
||||
respond(true, result, undefined);
|
||||
} catch (err) {
|
||||
@@ -74,11 +86,26 @@ export const webHandlers: GatewayRequestHandlers = {
|
||||
);
|
||||
}
|
||||
},
|
||||
"web.logout": async ({ respond, context }) => {
|
||||
"web.logout": async ({ params, respond, context }) => {
|
||||
try {
|
||||
await context.stopWhatsAppProvider();
|
||||
const cleared = await logoutWeb(defaultRuntime);
|
||||
context.markWhatsAppLoggedOut(cleared);
|
||||
const rawAccountId =
|
||||
params && typeof params === "object" && "accountId" in params
|
||||
? (params as { accountId?: unknown }).accountId
|
||||
: undefined;
|
||||
const accountId =
|
||||
typeof rawAccountId === "string" ? rawAccountId.trim() : "";
|
||||
const cfg = loadConfig();
|
||||
const account = resolveWhatsAppAccount({
|
||||
cfg,
|
||||
accountId: accountId || undefined,
|
||||
});
|
||||
await context.stopWhatsAppProvider(account.accountId);
|
||||
const cleared = await logoutWeb({
|
||||
authDir: account.authDir,
|
||||
isLegacyAuthDir: account.isLegacyAuthDir,
|
||||
runtime: defaultRuntime,
|
||||
});
|
||||
context.markWhatsAppLoggedOut(cleared, account.accountId);
|
||||
respond(true, { cleared }, undefined);
|
||||
} catch (err) {
|
||||
respond(
|
||||
|
||||
Reference in New Issue
Block a user