mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 00:59:48 +00:00
fix: resolve branch typecheck regressions
This commit is contained in:
@@ -432,7 +432,7 @@ function createToolWithScreenshotter(
|
||||
|
||||
function expectArtifactOnlyFileResult(
|
||||
screenshotter: DiffScreenshotter,
|
||||
result: { details?: Record<string, unknown> } | null | undefined,
|
||||
result: { details?: unknown } | null | undefined,
|
||||
) {
|
||||
expect(screenshotter.screenshotHtml).toHaveBeenCalledTimes(1);
|
||||
expect((result?.details as Record<string, unknown>).mode).toBe("file");
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { Mock } from "vitest";
|
||||
import { vi } from "vitest";
|
||||
|
||||
type MatrixBotSdkMockParams = {
|
||||
@@ -7,7 +8,26 @@ type MatrixBotSdkMockParams = {
|
||||
includeVerboseLogService?: boolean;
|
||||
};
|
||||
|
||||
export function createMatrixBotSdkMock(params: MatrixBotSdkMockParams = {}) {
|
||||
type MatrixBotSdkMock = {
|
||||
ConsoleLogger: new () => {
|
||||
trace: Mock<() => void>;
|
||||
debug: Mock<() => void>;
|
||||
info: Mock<() => void>;
|
||||
warn: Mock<() => void>;
|
||||
error: Mock<() => void>;
|
||||
};
|
||||
MatrixClient: unknown;
|
||||
LogService: {
|
||||
setLogger: Mock<() => void>;
|
||||
warn?: Mock<() => void>;
|
||||
info?: Mock<() => void>;
|
||||
debug?: Mock<() => void>;
|
||||
};
|
||||
SimpleFsStorageProvider: unknown;
|
||||
RustSdkCryptoStorageProvider: unknown;
|
||||
};
|
||||
|
||||
export function createMatrixBotSdkMock(params: MatrixBotSdkMockParams = {}): MatrixBotSdkMock {
|
||||
return {
|
||||
ConsoleLogger: class {
|
||||
trace = vi.fn();
|
||||
|
||||
@@ -2,9 +2,11 @@ import {
|
||||
buildSglangProvider,
|
||||
configureOpenAICompatibleSelfHostedProviderNonInteractive,
|
||||
emptyPluginConfigSchema,
|
||||
promptAndConfigureOpenAICompatibleSelfHostedProviderAuth,
|
||||
promptAndConfigureOpenAICompatibleSelfHostedProvider,
|
||||
type OpenClawPluginApi,
|
||||
type ProviderAuthContext,
|
||||
type ProviderAuthMethodNonInteractiveContext,
|
||||
type ProviderAuthResult,
|
||||
type ProviderDiscoveryContext,
|
||||
} from "openclaw/plugin-sdk/core";
|
||||
|
||||
@@ -28,8 +30,8 @@ const sglangPlugin = {
|
||||
label: "SGLang",
|
||||
hint: "Fast self-hosted OpenAI-compatible server",
|
||||
kind: "custom",
|
||||
run: (ctx) =>
|
||||
promptAndConfigureOpenAICompatibleSelfHostedProviderAuth({
|
||||
run: async (ctx: ProviderAuthContext): Promise<ProviderAuthResult> => {
|
||||
const result = await promptAndConfigureOpenAICompatibleSelfHostedProvider({
|
||||
cfg: ctx.config,
|
||||
prompter: ctx.prompter,
|
||||
providerId: PROVIDER_ID,
|
||||
@@ -37,7 +39,18 @@ const sglangPlugin = {
|
||||
defaultBaseUrl: DEFAULT_BASE_URL,
|
||||
defaultApiKeyEnvVar: "SGLANG_API_KEY",
|
||||
modelPlaceholder: "Qwen/Qwen3-8B",
|
||||
}),
|
||||
});
|
||||
return {
|
||||
profiles: [
|
||||
{
|
||||
profileId: result.profileId,
|
||||
credential: result.credential,
|
||||
},
|
||||
],
|
||||
configPatch: result.config,
|
||||
defaultModel: result.modelRef,
|
||||
};
|
||||
},
|
||||
runNonInteractive: async (ctx: ProviderAuthMethodNonInteractiveContext) =>
|
||||
configureOpenAICompatibleSelfHostedProviderNonInteractive({
|
||||
ctx,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { IncomingMessage, ServerResponse } from "node:http";
|
||||
import type { Mock } from "vitest";
|
||||
import { vi } from "vitest";
|
||||
|
||||
export type RegisteredRoute = {
|
||||
@@ -7,11 +8,13 @@ export type RegisteredRoute = {
|
||||
handler: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
||||
};
|
||||
|
||||
export const registerPluginHttpRouteMock = vi.fn<(params: RegisteredRoute) => () => void>(() =>
|
||||
vi.fn(),
|
||||
export const registerPluginHttpRouteMock: Mock<(params: RegisteredRoute) => () => void> = vi.fn(
|
||||
() => vi.fn(),
|
||||
);
|
||||
|
||||
export const dispatchReplyWithBufferedBlockDispatcher = vi.fn().mockResolvedValue({ counts: {} });
|
||||
export const dispatchReplyWithBufferedBlockDispatcher: Mock<
|
||||
() => Promise<{ counts: Record<string, number> }>
|
||||
> = vi.fn().mockResolvedValue({ counts: {} });
|
||||
|
||||
async function readRequestBodyWithLimitForTest(req: IncomingMessage): Promise<string> {
|
||||
return await new Promise<string>((resolve, reject) => {
|
||||
|
||||
@@ -85,12 +85,12 @@ type TelegramSendOptions = NonNullable<Parameters<TelegramSendFn>[2]>;
|
||||
|
||||
function buildTelegramSendOptions(params: {
|
||||
cfg: OpenClawConfig;
|
||||
mediaUrl?: string;
|
||||
mediaLocalRoots?: readonly string[];
|
||||
accountId?: string;
|
||||
replyToId?: string;
|
||||
threadId?: string;
|
||||
silent?: boolean;
|
||||
mediaUrl?: string | null;
|
||||
mediaLocalRoots?: readonly string[] | null;
|
||||
accountId?: string | null;
|
||||
replyToId?: string | null;
|
||||
threadId?: string | number | null;
|
||||
silent?: boolean | null;
|
||||
}): TelegramSendOptions {
|
||||
return {
|
||||
verbose: false,
|
||||
@@ -108,13 +108,13 @@ async function sendTelegramOutbound(params: {
|
||||
cfg: OpenClawConfig;
|
||||
to: string;
|
||||
text: string;
|
||||
mediaUrl?: string;
|
||||
mediaLocalRoots?: readonly string[];
|
||||
accountId?: string;
|
||||
mediaUrl?: string | null;
|
||||
mediaLocalRoots?: readonly string[] | null;
|
||||
accountId?: string | null;
|
||||
deps?: { sendTelegram?: TelegramSendFn };
|
||||
replyToId?: string;
|
||||
threadId?: string;
|
||||
silent?: boolean;
|
||||
replyToId?: string | null;
|
||||
threadId?: string | number | null;
|
||||
silent?: boolean | null;
|
||||
}) {
|
||||
const send =
|
||||
params.deps?.sendTelegram ?? getTelegramRuntime().channel.telegram.sendMessageTelegram;
|
||||
|
||||
@@ -154,8 +154,17 @@ function applyTlonSetupConfig(params: {
|
||||
}
|
||||
|
||||
type ResolvedTlonAccount = ReturnType<typeof resolveTlonAccount>;
|
||||
type ConfiguredTlonAccount = ResolvedTlonAccount & {
|
||||
ship: string;
|
||||
url: string;
|
||||
code: string;
|
||||
};
|
||||
|
||||
function resolveOutboundContext(params: { cfg: OpenClawConfig; accountId?: string; to: string }) {
|
||||
function resolveOutboundContext(params: {
|
||||
cfg: OpenClawConfig;
|
||||
accountId?: string | null;
|
||||
to: string;
|
||||
}) {
|
||||
const account = resolveTlonAccount(params.cfg, params.accountId ?? undefined);
|
||||
if (!account.configured || !account.ship || !account.url || !account.code) {
|
||||
throw new Error("Tlon account not configured");
|
||||
@@ -166,15 +175,15 @@ function resolveOutboundContext(params: { cfg: OpenClawConfig; accountId?: strin
|
||||
throw new Error(`Invalid Tlon target. Use ${formatTargetHint()}`);
|
||||
}
|
||||
|
||||
return { account, parsed };
|
||||
return { account: account as ConfiguredTlonAccount, parsed };
|
||||
}
|
||||
|
||||
function resolveReplyId(replyToId?: string, threadId?: string) {
|
||||
function resolveReplyId(replyToId?: string | null, threadId?: string | number | null) {
|
||||
return (replyToId ?? threadId) ? String(replyToId ?? threadId) : undefined;
|
||||
}
|
||||
|
||||
async function withHttpPokeAccountApi<T>(
|
||||
account: ResolvedTlonAccount & { ship: string; url: string; code: string },
|
||||
account: ConfiguredTlonAccount,
|
||||
run: (api: Awaited<ReturnType<typeof createHttpPokeApi>>) => Promise<T>,
|
||||
) {
|
||||
const api = await createHttpPokeApi({
|
||||
@@ -241,7 +250,7 @@ const tlonOutbound: ChannelOutboundAdapter = {
|
||||
shipUrl: account.url,
|
||||
shipName: account.ship.replace(/^~/, ""),
|
||||
verbose: false,
|
||||
getCode: async () => account.code!,
|
||||
getCode: async () => account.code,
|
||||
});
|
||||
|
||||
const uploadedUrl = mediaUrl ? await uploadImageFromUrl(mediaUrl) : undefined;
|
||||
|
||||
@@ -2,9 +2,11 @@ import {
|
||||
buildVllmProvider,
|
||||
configureOpenAICompatibleSelfHostedProviderNonInteractive,
|
||||
emptyPluginConfigSchema,
|
||||
promptAndConfigureOpenAICompatibleSelfHostedProviderAuth,
|
||||
promptAndConfigureOpenAICompatibleSelfHostedProvider,
|
||||
type OpenClawPluginApi,
|
||||
type ProviderAuthContext,
|
||||
type ProviderAuthMethodNonInteractiveContext,
|
||||
type ProviderAuthResult,
|
||||
type ProviderDiscoveryContext,
|
||||
} from "openclaw/plugin-sdk/core";
|
||||
|
||||
@@ -28,8 +30,8 @@ const vllmPlugin = {
|
||||
label: "vLLM",
|
||||
hint: "Local/self-hosted OpenAI-compatible server",
|
||||
kind: "custom",
|
||||
run: (ctx) =>
|
||||
promptAndConfigureOpenAICompatibleSelfHostedProviderAuth({
|
||||
run: async (ctx: ProviderAuthContext): Promise<ProviderAuthResult> => {
|
||||
const result = await promptAndConfigureOpenAICompatibleSelfHostedProvider({
|
||||
cfg: ctx.config,
|
||||
prompter: ctx.prompter,
|
||||
providerId: PROVIDER_ID,
|
||||
@@ -37,7 +39,18 @@ const vllmPlugin = {
|
||||
defaultBaseUrl: DEFAULT_BASE_URL,
|
||||
defaultApiKeyEnvVar: "VLLM_API_KEY",
|
||||
modelPlaceholder: "meta-llama/Meta-Llama-3-8B-Instruct",
|
||||
}),
|
||||
});
|
||||
return {
|
||||
profiles: [
|
||||
{
|
||||
profileId: result.profileId,
|
||||
credential: result.credential,
|
||||
},
|
||||
],
|
||||
configPatch: result.config,
|
||||
defaultModel: result.modelRef,
|
||||
};
|
||||
},
|
||||
runNonInteractive: async (ctx: ProviderAuthMethodNonInteractiveContext) =>
|
||||
configureOpenAICompatibleSelfHostedProviderNonInteractive({
|
||||
ctx,
|
||||
|
||||
@@ -230,7 +230,9 @@ const voiceCallPlugin = {
|
||||
const respondToCallMessageAction = async (params: {
|
||||
requestParams: GatewayRequestHandlerOptions["params"];
|
||||
respond: GatewayRequestHandlerOptions["respond"];
|
||||
action: (request: Awaited<ReturnType<typeof resolveCallMessageRequest>>) => Promise<{
|
||||
action: (
|
||||
request: Exclude<Awaited<ReturnType<typeof resolveCallMessageRequest>>, { error: string }>,
|
||||
) => Promise<{
|
||||
success: boolean;
|
||||
error?: string;
|
||||
transcript?: string;
|
||||
|
||||
@@ -27,6 +27,8 @@ export function createMockFollowupRun(
|
||||
enqueuedAt: Date.now(),
|
||||
originatingTo: "channel:C1",
|
||||
run: {
|
||||
agentId: "agent",
|
||||
agentDir: "/tmp/agent",
|
||||
sessionId: "session",
|
||||
sessionKey: "main",
|
||||
messageProvider: "whatsapp",
|
||||
@@ -34,7 +36,10 @@ export function createMockFollowupRun(
|
||||
sessionFile: "/tmp/session.jsonl",
|
||||
workspaceDir: "/tmp",
|
||||
config: {},
|
||||
skillsSnapshot: {},
|
||||
skillsSnapshot: {
|
||||
prompt: "",
|
||||
skills: [],
|
||||
},
|
||||
provider: "anthropic",
|
||||
model: "claude",
|
||||
thinkLevel: "low",
|
||||
|
||||
@@ -26,7 +26,9 @@ const routeState = vi.hoisted(() => ({
|
||||
}));
|
||||
|
||||
const chromeMcpMocks = vi.hoisted(() => ({
|
||||
evaluateChromeMcpScript: vi.fn(async () => true),
|
||||
evaluateChromeMcpScript: vi.fn(
|
||||
async (_params: { profileName: string; targetId: string; fn: string }) => true,
|
||||
),
|
||||
navigateChromeMcpPage: vi.fn(async ({ url }: { url: string }) => ({ url })),
|
||||
takeChromeMcpScreenshot: vi.fn(async () => Buffer.from("png")),
|
||||
takeChromeMcpSnapshot: vi.fn(async () => ({
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { vi } from "vitest";
|
||||
import type { MockFn } from "../../test-utils/vitest-mock-fn.js";
|
||||
|
||||
export const preflightDiscordMessageMock = vi.fn();
|
||||
export const processDiscordMessageMock = vi.fn();
|
||||
export const preflightDiscordMessageMock: MockFn = vi.fn();
|
||||
export const processDiscordMessageMock: MockFn = vi.fn();
|
||||
|
||||
vi.mock("./message-handler.preflight.js", () => ({
|
||||
preflightDiscordMessage: preflightDiscordMessageMock,
|
||||
|
||||
Reference in New Issue
Block a user