chore: Run pnpm format:fix.

This commit is contained in:
cpojer
2026-01-31 21:13:13 +09:00
parent dcc2de15a6
commit 8cab78abbc
624 changed files with 10729 additions and 7514 deletions

View File

@@ -33,10 +33,7 @@ function resolveAccountConfig(
return accounts[accountId] as ZalouserAccountConfig | undefined;
}
function mergeZalouserAccountConfig(
cfg: OpenClawConfig,
accountId: string,
): ZalouserAccountConfig {
function mergeZalouserAccountConfig(cfg: OpenClawConfig, accountId: string): ZalouserAccountConfig {
const raw = (cfg.channels?.zalouser ?? {}) as ZalouserConfig;
const { accounts: _ignored, defaultAccount: _ignored2, ...base } = raw;
const account = resolveAccountConfig(cfg, accountId) ?? {};
@@ -60,7 +57,8 @@ export async function resolveZalouserAccount(params: {
accountId?: string | null;
}): Promise<ResolvedZalouserAccount> {
const accountId = normalizeAccountId(params.accountId);
const baseEnabled = (params.cfg.channels?.zalouser as ZalouserConfig | undefined)?.enabled !== false;
const baseEnabled =
(params.cfg.channels?.zalouser as ZalouserConfig | undefined)?.enabled !== false;
const merged = mergeZalouserAccountConfig(params.cfg, accountId);
const accountEnabled = merged.enabled !== false;
const enabled = baseEnabled && accountEnabled;
@@ -82,7 +80,8 @@ export function resolveZalouserAccountSync(params: {
accountId?: string | null;
}): ResolvedZalouserAccount {
const accountId = normalizeAccountId(params.accountId);
const baseEnabled = (params.cfg.channels?.zalouser as ZalouserConfig | undefined)?.enabled !== false;
const baseEnabled =
(params.cfg.channels?.zalouser as ZalouserConfig | undefined)?.enabled !== false;
const merged = mergeZalouserAccountConfig(params.cfg, accountId);
const accountEnabled = merged.enabled !== false;
const enabled = baseEnabled && accountEnabled;
@@ -103,12 +102,14 @@ export async function listEnabledZalouserAccounts(
): Promise<ResolvedZalouserAccount[]> {
const ids = listZalouserAccountIds(cfg);
const accounts = await Promise.all(
ids.map((accountId) => resolveZalouserAccount({ cfg, accountId }))
ids.map((accountId) => resolveZalouserAccount({ cfg, accountId })),
);
return accounts.filter((account) => account.enabled);
}
export async function getZcaUserInfo(profile: string): Promise<{ userId?: string; displayName?: string } | null> {
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) return null;
return parseJsonOutput<{ userId?: string; displayName?: string }>(result.stdout);

View File

@@ -91,8 +91,8 @@ function resolveZalouserGroupToolPolicy(
const groups = account.config.groups ?? {};
const groupId = params.groupId?.trim();
const groupChannel = params.groupChannel?.trim();
const candidates = [groupId, groupChannel, "*"].filter(
(value): value is string => Boolean(value),
const candidates = [groupId, groupChannel, "*"].filter((value): value is string =>
Boolean(value),
);
for (const key of candidates) {
const entry = groups[key];
@@ -111,9 +111,9 @@ export const zalouserDock: ChannelDock = {
outbound: { textChunkLimit: 2000 },
config: {
resolveAllowFrom: ({ cfg, accountId }) =>
(resolveZalouserAccountSync({ cfg: cfg as OpenClawConfig, accountId }).config.allowFrom ?? []).map(
(entry) => String(entry),
),
(
resolveZalouserAccountSync({ cfg: cfg as OpenClawConfig, accountId }).config.allowFrom ?? []
).map((entry) => String(entry)),
formatAllowFrom: ({ allowFrom }) =>
allowFrom
.map((entry) => String(entry).trim())
@@ -163,7 +163,15 @@ export const zalouserPlugin: ChannelPlugin<ResolvedZalouserAccount> = {
cfg: cfg as OpenClawConfig,
sectionKey: "zalouser",
accountId,
clearBaseFields: ["profile", "name", "dmPolicy", "allowFrom", "groupPolicy", "groups", "messagePrefix"],
clearBaseFields: [
"profile",
"name",
"dmPolicy",
"allowFrom",
"groupPolicy",
"groups",
"messagePrefix",
],
}),
isConfigured: async (account) => {
// Check if zca auth status is OK for this profile
@@ -180,9 +188,9 @@ export const zalouserPlugin: ChannelPlugin<ResolvedZalouserAccount> = {
configured: undefined,
}),
resolveAllowFrom: ({ cfg, accountId }) =>
(resolveZalouserAccountSync({ cfg: cfg as OpenClawConfig, accountId }).config.allowFrom ?? []).map(
(entry) => String(entry),
),
(
resolveZalouserAccountSync({ cfg: cfg as OpenClawConfig, accountId }).config.allowFrom ?? []
).map((entry) => String(entry)),
formatAllowFrom: ({ allowFrom }) =>
allowFrom
.map((entry) => String(entry).trim())
@@ -291,7 +299,10 @@ export const zalouserPlugin: ChannelPlugin<ResolvedZalouserAccount> = {
const ok = await checkZcaInstalled();
if (!ok) throw new Error("Missing dependency: `zca` not found in PATH");
const account = resolveZalouserAccountSync({ cfg: cfg as OpenClawConfig, accountId });
const result = await runZca(["me", "info", "-j"], { profile: account.profile, timeout: 10000 });
const result = await runZca(["me", "info", "-j"], {
profile: account.profile,
timeout: 10000,
});
if (!result.ok) {
runtime.error(result.stderr || "Failed to fetch profile");
return null;
@@ -309,9 +320,7 @@ export const zalouserPlugin: ChannelPlugin<ResolvedZalouserAccount> = {
const ok = await checkZcaInstalled();
if (!ok) throw new Error("Missing dependency: `zca` not found in PATH");
const account = resolveZalouserAccountSync({ cfg: cfg as OpenClawConfig, accountId });
const args = query?.trim()
? ["friend", "find", query.trim()]
: ["friend", "list", "-j"];
const args = query?.trim() ? ["friend", "find", query.trim()] : ["friend", "list", "-j"];
const result = await runZca(args, { profile: account.profile, timeout: 15000 });
if (!result.ok) {
throw new Error(result.stderr || "Failed to list peers");
@@ -333,7 +342,10 @@ export const zalouserPlugin: ChannelPlugin<ResolvedZalouserAccount> = {
const ok = await checkZcaInstalled();
if (!ok) throw new Error("Missing dependency: `zca` not found in PATH");
const account = resolveZalouserAccountSync({ cfg: cfg as OpenClawConfig, accountId });
const result = await runZca(["group", "list", "-j"], { profile: account.profile, timeout: 15000 });
const result = await runZca(["group", "list", "-j"], {
profile: account.profile,
timeout: 15000,
});
if (!result.ok) {
throw new Error(result.stderr || "Failed to list groups");
}
@@ -364,7 +376,9 @@ export const zalouserPlugin: ChannelPlugin<ResolvedZalouserAccount> = {
if (!result.ok) {
throw new Error(result.stderr || "Failed to list group members");
}
const parsed = parseJsonOutput<Array<Partial<ZcaFriend> & { userId?: string | number }>>(result.stdout);
const parsed = parseJsonOutput<Array<Partial<ZcaFriend> & { userId?: string | number }>>(
result.stdout,
);
const rows = Array.isArray(parsed)
? parsed
.map((m) => {
@@ -433,7 +447,8 @@ export const zalouserPlugin: ChannelPlugin<ResolvedZalouserAccount> = {
name: g.name ?? undefined,
}))
: [];
const best = matches.find((g) => g.name?.toLowerCase() === trimmed.toLowerCase()) ?? matches[0];
const best =
matches.find((g) => g.name?.toLowerCase() === trimmed.toLowerCase()) ?? matches[0];
results.push({
input,
resolved: Boolean(best?.id),
@@ -550,8 +565,7 @@ export const zalouserPlugin: ChannelPlugin<ResolvedZalouserAccount> = {
probe: snapshot.probe,
lastProbeAt: snapshot.lastProbeAt ?? null,
}),
probeAccount: async ({ account, timeoutMs }) =>
probeZalouser(account.profile, timeoutMs),
probeAccount: async ({ account, timeoutMs }) => probeZalouser(account.profile, timeoutMs),
buildAccountSnapshot: async ({ account, runtime }) => {
const zcaInstalled = await checkZcaInstalled();
const configured = zcaInstalled ? await checkZcaAuthenticated(account.profile) : false;
@@ -564,7 +578,7 @@ export const zalouserPlugin: ChannelPlugin<ResolvedZalouserAccount> = {
running: runtime?.running ?? false,
lastStartAt: runtime?.lastStartAt ?? null,
lastStopAt: runtime?.lastStopAt ?? null,
lastError: configured ? (runtime?.lastError ?? null) : runtime?.lastError ?? configError,
lastError: configured ? (runtime?.lastError ?? null) : (runtime?.lastError ?? configError),
lastInboundAt: runtime?.lastInboundAt ?? null,
lastOutboundAt: runtime?.lastOutboundAt ?? null,
dmPolicy: account.config.dmPolicy ?? "pairing",

View File

@@ -3,12 +3,7 @@ import type { ChildProcess } from "node:child_process";
import type { OpenClawConfig, MarkdownTableMode, RuntimeEnv } from "openclaw/plugin-sdk";
import { mergeAllowlist, summarizeMapping } from "openclaw/plugin-sdk";
import { sendMessageZalouser } from "./send.js";
import type {
ResolvedZalouserAccount,
ZcaFriend,
ZcaGroup,
ZcaMessage,
} from "./types.js";
import type { ResolvedZalouserAccount, ZcaFriend, ZcaGroup, ZcaMessage } from "./types.js";
import { getZalouserRuntime } from "./runtime.js";
import { parseJsonOutput, runZca, runZcaStreaming } from "./zca.js";
@@ -30,10 +25,7 @@ function normalizeZalouserEntry(entry: string): string {
return entry.replace(/^(zalouser|zlu):/i, "").trim();
}
function buildNameIndex<T>(
items: T[],
nameFn: (item: T) => string | undefined,
): Map<string, T[]> {
function buildNameIndex<T>(items: T[], nameFn: (item: T) => string | undefined): Map<string, T[]> {
const index = new Map<string, T[]>();
for (const item of items) {
const name = nameFn(item)?.trim().toLowerCase();
@@ -183,10 +175,7 @@ async function processMessage(
const dmPolicy = account.config.dmPolicy ?? "pairing";
const configAllowFrom = (account.config.allowFrom ?? []).map((v) => String(v));
const rawBody = content.trim();
const shouldComputeAuth = core.channel.commands.shouldComputeCommandAuthorized(
rawBody,
config,
);
const shouldComputeAuth = core.channel.commands.shouldComputeCommandAuthorized(rawBody, config);
const storeAllowFrom =
!isGroup && (dmPolicy !== "open" || shouldComputeAuth)
? await core.channel.pairing.readAllowFromStore("zalouser").catch(() => [])
@@ -197,7 +186,9 @@ async function processMessage(
const commandAuthorized = shouldComputeAuth
? core.channel.commands.resolveCommandAuthorizedFromAuthorizers({
useAccessGroups,
authorizers: [{ configured: effectiveAllowFrom.length > 0, allowed: senderAllowedForCommands }],
authorizers: [
{ configured: effectiveAllowFrom.length > 0, allowed: senderAllowedForCommands },
],
})
: undefined;
@@ -256,11 +247,17 @@ async function processMessage(
core.channel.commands.isControlCommandMessage(rawBody, config) &&
commandAuthorized !== true
) {
logVerbose(core, runtime, `zalouser: drop control command from unauthorized sender ${senderId}`);
logVerbose(
core,
runtime,
`zalouser: drop control command from unauthorized sender ${senderId}`,
);
return;
}
const peer = isGroup ? { kind: "group" as const, id: chatId } : { kind: "group" as const, id: senderId };
const peer = isGroup
? { kind: "group" as const, id: chatId }
: { kind: "group" as const, id: senderId };
const route = core.channel.routing.resolveAgentRoute({
cfg: config,
@@ -343,9 +340,7 @@ async function processMessage(
});
},
onError: (err, info) => {
runtime.error(
`[${account.accountId}] Zalouser ${info.kind} reply failed: ${String(err)}`,
);
runtime.error(`[${account.accountId}] Zalouser ${info.kind} reply failed: ${String(err)}`);
},
},
});

View File

@@ -28,9 +28,7 @@ function setZalouserDmPolicy(
dmPolicy: "pairing" | "allowlist" | "open" | "disabled",
): OpenClawConfig {
const allowFrom =
dmPolicy === "open"
? addWildcardAllowFrom(cfg.channels?.zalouser?.allowFrom)
: undefined;
dmPolicy === "open" ? addWildcardAllowFrom(cfg.channels?.zalouser?.allowFrom) : undefined;
return {
...cfg,
channels: {
@@ -239,10 +237,13 @@ async function resolveZalouserGroups(params: {
entries: string[];
}): Promise<Array<{ input: string; resolved: boolean; id?: string }>> {
const account = resolveZalouserAccountSync({ cfg: params.cfg, accountId: params.accountId });
const result = await runZca(["group", "list", "-j"], { profile: account.profile, timeout: 15000 });
const result = await runZca(["group", "list", "-j"], {
profile: account.profile,
timeout: 15000,
});
if (!result.ok) throw new Error(result.stderr || "Failed to list groups");
const groups = (parseJsonOutput<ZcaGroup[]>(result.stdout) ?? []).filter(
(group) => Boolean(group.groupId),
const groups = (parseJsonOutput<ZcaGroup[]>(result.stdout) ?? []).filter((group) =>
Boolean(group.groupId),
);
const byName = new Map<string, ZcaGroup[]>();
for (const group of groups) {
@@ -270,12 +271,13 @@ const dmPolicy: ChannelOnboardingDmPolicy = {
channel,
policyKey: "channels.zalouser.dmPolicy",
allowFromKey: "channels.zalouser.allowFrom",
getCurrent: (cfg) => ((cfg as OpenClawConfig).channels?.zalouser?.dmPolicy ?? "pairing") as "pairing",
getCurrent: (cfg) =>
((cfg as OpenClawConfig).channels?.zalouser?.dmPolicy ?? "pairing") as "pairing",
setPolicy: (cfg, policy) => setZalouserDmPolicy(cfg as OpenClawConfig, policy),
promptAllowFrom: async ({ cfg, prompter, accountId }) => {
const id =
accountId && normalizeAccountId(accountId)
? normalizeAccountId(accountId) ?? DEFAULT_ACCOUNT_ID
? (normalizeAccountId(accountId) ?? DEFAULT_ACCOUNT_ID)
: resolveDefaultZalouserAccountId(cfg as OpenClawConfig);
return promptZalouserAllowFrom({
cfg: cfg as OpenClawConfig,
@@ -307,7 +309,13 @@ export const zalouserOnboardingAdapter: ChannelOnboardingAdapter = {
quickstartScore: configured ? 1 : 15,
};
},
configure: async ({ cfg, prompter, accountOverrides, shouldPromptAccountIds, forceAllowFrom }) => {
configure: async ({
cfg,
prompter,
accountOverrides,
shouldPromptAccountIds,
forceAllowFrom,
}) => {
// Check zca is installed
const zcaInstalled = await checkZcaInstalled();
if (!zcaInstalled) {
@@ -325,9 +333,7 @@ export const zalouserOnboardingAdapter: ChannelOnboardingAdapter = {
const zalouserOverride = accountOverrides.zalouser?.trim();
const defaultAccountId = resolveDefaultZalouserAccountId(cfg as OpenClawConfig);
let accountId = zalouserOverride
? normalizeAccountId(zalouserOverride)
: defaultAccountId;
let accountId = zalouserOverride ? normalizeAccountId(zalouserOverride) : defaultAccountId;
if (shouldPromptAccountIds && !zalouserOverride) {
accountId = await promptAccountId({
@@ -364,10 +370,7 @@ export const zalouserOnboardingAdapter: ChannelOnboardingAdapter = {
});
if (!result.ok) {
await prompter.note(
`Login failed: ${result.stderr || "Unknown error"}`,
"Error",
);
await prompter.note(`Login failed: ${result.stderr || "Unknown error"}`, "Error");
} else {
const isNowAuth = await checkZcaAuthenticated(account.profile);
if (isNowAuth) {
@@ -454,10 +457,7 @@ export const zalouserOnboardingAdapter: ChannelOnboardingAdapter = {
const unresolved = resolved
.filter((entry) => !entry.resolved)
.map((entry) => entry.input);
keys = [
...resolvedIds,
...unresolved.map((entry) => entry.trim()).filter(Boolean),
];
keys = [...resolvedIds, ...unresolved.map((entry) => entry.trim()).filter(Boolean)];
if (resolvedIds.length > 0 || unresolved.length > 0) {
await prompter.note(
[

View File

@@ -16,17 +16,18 @@ function stringEnum<T extends readonly string[]>(
}
// Tool schema - avoiding Type.Union per tool schema guardrails
export const ZalouserToolSchema = Type.Object({
action: stringEnum(ACTIONS, { description: `Action to perform: ${ACTIONS.join(", ")}` }),
threadId: Type.Optional(
Type.String({ description: "Thread ID for messaging" }),
),
message: Type.Optional(Type.String({ description: "Message text" })),
isGroup: Type.Optional(Type.Boolean({ description: "Is group chat" })),
profile: Type.Optional(Type.String({ description: "Profile name" })),
query: Type.Optional(Type.String({ description: "Search query" })),
url: Type.Optional(Type.String({ description: "URL for media/link" })),
}, { additionalProperties: false });
export const ZalouserToolSchema = Type.Object(
{
action: stringEnum(ACTIONS, { description: `Action to perform: ${ACTIONS.join(", ")}` }),
threadId: Type.Optional(Type.String({ description: "Thread ID for messaging" })),
message: Type.Optional(Type.String({ description: "Message text" })),
isGroup: Type.Optional(Type.Boolean({ description: "Is group chat" })),
profile: Type.Optional(Type.String({ description: "Profile name" })),
query: Type.Optional(Type.String({ description: "Search query" })),
url: Type.Optional(Type.String({ description: "URL for media/link" })),
},
{ additionalProperties: false },
);
type ToolParams = {
action: (typeof ACTIONS)[number];
@@ -100,9 +101,7 @@ export async function executeZalouserTool(
}
case "friends": {
const args = params.query
? ["friend", "find", params.query]
: ["friend", "list", "-j"];
const args = params.query ? ["friend", "find", params.query] : ["friend", "list", "-j"];
const result = await runZca(args, { profile: params.profile });
if (!result.ok) {
throw new Error(result.stderr || "Failed to get friends");

View File

@@ -75,7 +75,10 @@ export type ZalouserAccountConfig = {
dmPolicy?: "pairing" | "allowlist" | "open" | "disabled";
allowFrom?: Array<string | number>;
groupPolicy?: "open" | "allowlist" | "disabled";
groups?: Record<string, { allow?: boolean; enabled?: boolean; tools?: { allow?: string[]; deny?: string[] } }>;
groups?: Record<
string,
{ allow?: boolean; enabled?: boolean; tools?: { allow?: string[]; deny?: string[] } }
>;
messagePrefix?: string;
};
@@ -87,7 +90,10 @@ export type ZalouserConfig = {
dmPolicy?: "pairing" | "allowlist" | "open" | "disabled";
allowFrom?: Array<string | number>;
groupPolicy?: "open" | "allowlist" | "disabled";
groups?: Record<string, { allow?: boolean; enabled?: boolean; tools?: { allow?: string[]; deny?: string[] } }>;
groups?: Record<
string,
{ allow?: boolean; enabled?: boolean; tools?: { allow?: string[]; deny?: string[] } }
>;
messagePrefix?: string;
accounts?: Record<string, ZalouserAccountConfig>;
};

View File

@@ -16,10 +16,7 @@ function buildArgs(args: string[], options?: ZcaRunOptions): string[] {
return result;
}
export async function runZca(
args: string[],
options?: ZcaRunOptions,
): Promise<ZcaResult> {
export async function runZca(args: string[], options?: ZcaRunOptions): Promise<ZcaResult> {
const fullArgs = buildArgs(args, options);
const timeout = options?.timeout ?? DEFAULT_TIMEOUT;
@@ -79,10 +76,7 @@ export async function runZca(
});
}
export function runZcaInteractive(
args: string[],
options?: ZcaRunOptions,
): Promise<ZcaResult> {
export function runZcaInteractive(args: string[], options?: ZcaRunOptions): Promise<ZcaResult> {
const fullArgs = buildArgs(args, options);
return new Promise((resolve) => {