feat(zalouser): migrate runtime to native zca-js

This commit is contained in:
Peter Steinberger
2026-03-02 15:40:26 +00:00
parent db3d8d82c1
commit 174f2de447
15 changed files with 1822 additions and 1025 deletions

View File

@@ -5,7 +5,7 @@ import {
normalizeOptionalAccountId,
} from "openclaw/plugin-sdk/account-id";
import type { ResolvedZalouserAccount, ZalouserAccountConfig, ZalouserConfig } from "./types.js";
import { runZca, parseJsonOutput } from "./zca.js";
import { checkZaloAuthenticated, getZaloUserInfo } from "./zalo-js.js";
function listConfiguredAccountIds(cfg: OpenClawConfig): string[] {
const accounts = (cfg.channels?.zalouser as ZalouserConfig | undefined)?.accounts;
@@ -57,10 +57,13 @@ function mergeZalouserAccountConfig(cfg: OpenClawConfig, accountId: string): Zal
return { ...base, ...account };
}
function resolveZcaProfile(config: ZalouserAccountConfig, accountId: string): string {
function resolveProfile(config: ZalouserAccountConfig, accountId: string): string {
if (config.profile?.trim()) {
return config.profile.trim();
}
if (process.env.ZALOUSER_PROFILE?.trim()) {
return process.env.ZALOUSER_PROFILE.trim();
}
if (process.env.ZCA_PROFILE?.trim()) {
return process.env.ZCA_PROFILE.trim();
}
@@ -70,11 +73,6 @@ function resolveZcaProfile(config: ZalouserAccountConfig, accountId: string): st
return "default";
}
export async function checkZcaAuthenticated(profile: string): Promise<boolean> {
const result = await runZca(["auth", "status"], { profile, timeout: 5000 });
return result.ok;
}
export async function resolveZalouserAccount(params: {
cfg: OpenClawConfig;
accountId?: string | null;
@@ -85,8 +83,8 @@ export async function resolveZalouserAccount(params: {
const merged = mergeZalouserAccountConfig(params.cfg, accountId);
const accountEnabled = merged.enabled !== false;
const enabled = baseEnabled && accountEnabled;
const profile = resolveZcaProfile(merged, accountId);
const authenticated = await checkZcaAuthenticated(profile);
const profile = resolveProfile(merged, accountId);
const authenticated = await checkZaloAuthenticated(profile);
return {
accountId,
@@ -108,14 +106,14 @@ export function resolveZalouserAccountSync(params: {
const merged = mergeZalouserAccountConfig(params.cfg, accountId);
const accountEnabled = merged.enabled !== false;
const enabled = baseEnabled && accountEnabled;
const profile = resolveZcaProfile(merged, accountId);
const profile = resolveProfile(merged, accountId);
return {
accountId,
name: merged.name?.trim() || undefined,
enabled,
profile,
authenticated: false, // unknown without async check
authenticated: false,
config: merged,
};
}
@@ -133,11 +131,16 @@ export async function listEnabledZalouserAccounts(
export async function getZcaUserInfo(
profile: string,
): Promise<{ userId?: string; displayName?: string } | null> {
const result = await runZca(["me", "info", "-j"], { profile, timeout: 10000 });
if (!result.ok) {
const info = await getZaloUserInfo(profile);
if (!info) {
return null;
}
return parseJsonOutput<{ userId?: string; displayName?: string }>(result.stdout);
return {
userId: info.userId,
displayName: info.displayName,
};
}
export { checkZaloAuthenticated as checkZcaAuthenticated };
export type { ResolvedZalouserAccount } from "./types.js";