test: fix clickclack lint failures

This commit is contained in:
Shakker
2026-05-09 15:43:23 +01:00
parent 5ab7a458ba
commit 14e9c064ee
4 changed files with 33 additions and 7 deletions

View File

@@ -139,7 +139,9 @@ export const clickClackPlugin: ChannelPlugin<ResolvedClickClackAccount> = create
}, },
resolveSessionConversation: ({ rawId }) => { resolveSessionConversation: ({ rawId }) => {
const parsed = parseClickClackTarget(rawId); const parsed = parseClickClackTarget(rawId);
if (parsed.kind === "dm") return null; if (parsed.kind === "dm") {
return null;
}
return { return {
id: parsed.id, id: parsed.id,
threadId: parsed.kind === "thread" ? parsed.id : undefined, threadId: parsed.kind === "thread" ? parsed.id : undefined,

View File

@@ -1,4 +1,5 @@
import type { ChannelGatewayContext } from "openclaw/plugin-sdk/channel-contract"; import type { ChannelGatewayContext } from "openclaw/plugin-sdk/channel-contract";
import type { RawData } from "ws";
import { resolveClickClackAccount } from "./accounts.js"; import { resolveClickClackAccount } from "./accounts.js";
import { createClickClackClient } from "./http-client.js"; import { createClickClackClient } from "./http-client.js";
import { handleClickClackInbound } from "./inbound.js"; import { handleClickClackInbound } from "./inbound.js";
@@ -20,7 +21,9 @@ async function resolveEventMessage(params: {
event: ClickClackEvent; event: ClickClackEvent;
}): Promise<ClickClackMessage | null> { }): Promise<ClickClackMessage | null> {
const messageId = payloadString(params.event, "message_id"); const messageId = payloadString(params.event, "message_id");
if (!messageId) return null; if (!messageId) {
return null;
}
const directConversationId = payloadString(params.event, "direct_conversation_id"); const directConversationId = payloadString(params.event, "direct_conversation_id");
if (directConversationId && typeof params.event.seq === "number") { if (directConversationId && typeof params.event.seq === "number") {
const messages = await params.client.directMessages( const messages = await params.client.directMessages(
@@ -32,7 +35,9 @@ async function resolveEventMessage(params: {
} }
if (params.event.type === "thread.reply_created") { if (params.event.type === "thread.reply_created") {
const rootId = payloadString(params.event, "root_message_id"); const rootId = payloadString(params.event, "root_message_id");
if (!rootId) return null; if (!rootId) {
return null;
}
const thread = await params.client.thread(rootId); const thread = await params.client.thread(rootId);
return thread.replies.find((message) => message.id === messageId) ?? null; return thread.replies.find((message) => message.id === messageId) ?? null;
} }
@@ -47,6 +52,19 @@ async function resolveEventMessage(params: {
return null; return null;
} }
function decodeSocketMessage(data: RawData): string {
if (typeof data === "string") {
return data;
}
if (Buffer.isBuffer(data)) {
return data.toString("utf8");
}
if (data instanceof ArrayBuffer) {
return Buffer.from(data).toString("utf8");
}
return Buffer.concat(data).toString("utf8");
}
async function processEvent(params: { async function processEvent(params: {
account: ResolvedClickClackAccount; account: ResolvedClickClackAccount;
config: CoreConfig; config: CoreConfig;
@@ -128,7 +146,7 @@ export async function startClickClackGatewayAccount(
ctx.abortSignal.addEventListener("abort", abort, { once: true }); ctx.abortSignal.addEventListener("abort", abort, { once: true });
socket.on("message", (data) => { socket.on("message", (data) => {
void (async () => { void (async () => {
const event = JSON.parse(String(data)) as ClickClackEvent; const event = JSON.parse(decodeSocketMessage(data)) as ClickClackEvent;
afterCursor = event.cursor || afterCursor; afterCursor = event.cursor || afterCursor;
await processEvent({ await processEvent({
account, account,

View File

@@ -113,7 +113,9 @@ export function createClickClackClient(options: ClientOptions) {
}, },
events: async (workspaceId: string, afterCursor?: string): Promise<ClickClackEvent[]> => { events: async (workspaceId: string, afterCursor?: string): Promise<ClickClackEvent[]> => {
const query = new URLSearchParams({ workspace_id: workspaceId }); const query = new URLSearchParams({ workspace_id: workspaceId });
if (afterCursor) query.set("after_cursor", afterCursor); if (afterCursor) {
query.set("after_cursor", afterCursor);
}
const data = await request<{ events: ClickClackEvent[] }>( const data = await request<{ events: ClickClackEvent[] }>(
`/api/realtime/events?${query.toString()}`, `/api/realtime/events?${query.toString()}`,
); );
@@ -123,7 +125,9 @@ export function createClickClackClient(options: ClientOptions) {
const url = new URL(`${baseUrl}/api/realtime/ws`); const url = new URL(`${baseUrl}/api/realtime/ws`);
url.protocol = url.protocol === "https:" ? "wss:" : "ws:"; url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
url.searchParams.set("workspace_id", workspaceId); url.searchParams.set("workspace_id", workspaceId);
if (afterCursor) url.searchParams.set("after_cursor", afterCursor); if (afterCursor) {
url.searchParams.set("after_cursor", afterCursor);
}
return new WebSocket(url, { return new WebSocket(url, {
headers: { headers: {
Authorization: `Bearer ${options.token}`, Authorization: `Bearer ${options.token}`,

View File

@@ -176,7 +176,9 @@ export async function handleClickClackInbound(params: {
payload && typeof payload === "object" && "text" in payload payload && typeof payload === "object" && "text" in payload
? ((payload as { text?: string }).text ?? "") ? ((payload as { text?: string }).text ?? "")
: ""; : "";
if (!text.trim()) return; if (!text.trim()) {
return;
}
await sendClickClackText({ await sendClickClackText({
cfg: params.config, cfg: params.config,
accountId: params.account.accountId, accountId: params.account.accountId,