From 59cfff02f64e2ebf37f8a779d62881e489c95a87 Mon Sep 17 00:00:00 2001 From: cpojer Date: Sat, 31 Jan 2026 21:57:21 +0900 Subject: [PATCH] chore: Emit TypeScript declaration files so that we can type-check the extensions folder soon. --- src/discord/monitor/native-command.ts | 3 ++- src/gateway/test-helpers.mocks.ts | 6 +++--- src/line/bot.ts | 3 ++- src/line/webhook.ts | 9 +++++++-- src/slack/monitor.test-helpers.ts | 14 +++++++++++--- src/web/session.ts | 2 +- tsconfig.json | 1 + 7 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/discord/monitor/native-command.ts b/src/discord/monitor/native-command.ts index 227a48f03d..ab40850abb 100644 --- a/src/discord/monitor/native-command.ts +++ b/src/discord/monitor/native-command.ts @@ -418,7 +418,7 @@ export function createDiscordNativeCommand(params: { accountId: string; sessionPrefix: string; ephemeralDefault: boolean; -}) { +}): Command { const { command, cfg, discordConfig, accountId, sessionPrefix, ephemeralDefault } = params; const commandDefinition = findCommandByNativeName(command.name, "discord") ?? @@ -449,6 +449,7 @@ export function createDiscordNativeCommand(params: { }, ] satisfies CommandOptions) : undefined; + return new (class extends Command { name = command.name; description = command.description; diff --git a/src/gateway/test-helpers.mocks.ts b/src/gateway/test-helpers.mocks.ts index 4a339efcdd..8539d8e824 100644 --- a/src/gateway/test-helpers.mocks.ts +++ b/src/gateway/test-helpers.mocks.ts @@ -3,7 +3,7 @@ import fs from "node:fs/promises"; import fsSync from "node:fs"; import os from "node:os"; import path from "node:path"; -import { vi } from "vitest"; +import { Mock, vi } from "vitest"; import type { ChannelPlugin, ChannelOutboundAdapter } from "../channels/plugins/types.js"; import { applyPluginAutoEnable } from "../config/plugin-auto-enable.js"; @@ -199,8 +199,8 @@ export const setTestConfigRoot = (root: string) => { export const testTailnetIPv4 = hoisted.testTailnetIPv4; export const piSdkMock = hoisted.piSdkMock; export const cronIsolatedRun = hoisted.cronIsolatedRun; -export const agentCommand = hoisted.agentCommand; -export const getReplyFromConfig = hoisted.getReplyFromConfig; +export const agentCommand: Mock<() => void> = hoisted.agentCommand; +export const getReplyFromConfig: Mock<() => void> = hoisted.getReplyFromConfig; export const testState = { agentConfig: undefined as Record | undefined, diff --git a/src/line/bot.ts b/src/line/bot.ts index b14eecb23f..ecea6ef79f 100644 --- a/src/line/bot.ts +++ b/src/line/bot.ts @@ -1,4 +1,5 @@ import type { WebhookRequestBody } from "@line/bot-sdk"; +import type { Request, Response, NextFunction } from "express"; import type { OpenClawConfig } from "../config/config.js"; import { loadConfig } from "../config/config.js"; import { logVerbose } from "../globals.js"; @@ -71,7 +72,7 @@ export function createLineWebhookCallback( bot: LineBot, channelSecret: string, path = "/line/webhook", -) { +): { path: string; handler: (req: Request, res: Response, _next: NextFunction) => Promise } { const { handler } = startLineWebhook({ channelSecret, onEvents: bot.handleWebhook, diff --git a/src/line/webhook.ts b/src/line/webhook.ts index 10a3d7dbbb..74c0cfde17 100644 --- a/src/line/webhook.ts +++ b/src/line/webhook.ts @@ -31,7 +31,9 @@ function parseWebhookBody(req: Request, rawBody: string): WebhookRequestBody | n } } -export function createLineWebhookMiddleware(options: LineWebhookOptions) { +export function createLineWebhookMiddleware( + options: LineWebhookOptions, +): (req: Request, res: Response, _next: NextFunction) => Promise { const { channelSecret, onEvents, runtime } = options; return async (req: Request, res: Response, _next: NextFunction): Promise => { @@ -87,7 +89,10 @@ export interface StartLineWebhookOptions { path?: string; } -export function startLineWebhook(options: StartLineWebhookOptions) { +export function startLineWebhook(options: StartLineWebhookOptions): { + path: string; + handler: (req: Request, res: Response, _next: NextFunction) => Promise; +} { const path = options.path ?? "/line/webhook"; const middleware = createLineWebhookMiddleware({ channelSecret: options.channelSecret, diff --git a/src/slack/monitor.test-helpers.ts b/src/slack/monitor.test-helpers.ts index 8f81c27ded..b50f871a23 100644 --- a/src/slack/monitor.test-helpers.ts +++ b/src/slack/monitor.test-helpers.ts @@ -1,8 +1,16 @@ -import { vi } from "vitest"; +import { Mock, vi } from "vitest"; type SlackHandler = (args: unknown) => Promise; -const slackTestState = vi.hoisted(() => ({ +const slackTestState: { + config: Record; + sendMock: Mock<(...args: unknown[]) => Promise>; + replyMock: Mock<(...args: unknown[]) => unknown>; + updateLastRouteMock: Mock<(...args: unknown[]) => unknown>; + reactMock: Mock<(...args: unknown[]) => unknown>; + readAllowFromStoreMock: Mock<(...args: unknown[]) => Promise>; + upsertPairingRequestMock: Mock<(...args: unknown[]) => Promise>; +} = vi.hoisted(() => ({ config: {} as Record, sendMock: vi.fn(), replyMock: vi.fn(), @@ -12,7 +20,7 @@ const slackTestState = vi.hoisted(() => ({ upsertPairingRequestMock: vi.fn(), })); -export const getSlackTestState = () => slackTestState; +export const getSlackTestState: () => void = () => slackTestState; export const getSlackHandlers = () => ( diff --git a/src/web/session.ts b/src/web/session.ts index 44912158d7..ec601288a2 100644 --- a/src/web/session.ts +++ b/src/web/session.ts @@ -96,7 +96,7 @@ export async function createWaSocket( printQr: boolean, verbose: boolean, opts: { authDir?: string; onQr?: (qr: string) => void } = {}, -) { +): Promise> { const baseLogger = getChildLogger( { module: "baileys" }, { diff --git a/tsconfig.json b/tsconfig.json index f30d73a4b8..1c537b4059 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "moduleResolution": "NodeNext", "lib": ["DOM", "DOM.Iterable", "ES2023", "ScriptHost"], "noEmit": true, + "declaration": true, "noEmitOnError": true, "outDir": "dist", "resolveJsonModule": true,