diff --git a/src/commands/onboard-non-interactive.provider-auth.test.ts b/src/commands/onboard-non-interactive.provider-auth.test.ts index abf8362d694..66050fe6f62 100644 --- a/src/commands/onboard-non-interactive.provider-auth.test.ts +++ b/src/commands/onboard-non-interactive.provider-auth.test.ts @@ -22,6 +22,7 @@ type OnboardEnv = { configPath: string; runtime: NonInteractiveRuntime; }; +type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise; const ensureWorkspaceAndSessionsMock = vi.hoisted(() => vi.fn(async (..._args: unknown[]) => {})); @@ -61,7 +62,7 @@ type ProviderAuthConfigSnapshot = { }; }; -function createZaiFetchMock(responses: Record): typeof fetch { +function createZaiFetchMock(responses: Record): FetchLike { return vi.fn(async (input, init) => { const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : ""; const parsedBody = @@ -77,12 +78,12 @@ function createZaiFetchMock(responses: Record): typeof fetch { headers: { "content-type": "application/json" }, }, ); - }) as typeof fetch; + }); } async function withZaiProbeFetch( responses: Record, - run: (fetchMock: typeof fetch) => Promise, + run: (fetchMock: FetchLike) => Promise, ): Promise { const originalVitest = process.env.VITEST; delete process.env.VITEST; diff --git a/src/infra/gaxios-fetch-compat.test.ts b/src/infra/gaxios-fetch-compat.test.ts index b3cbf68a1ab..7d4c0dd402a 100644 --- a/src/infra/gaxios-fetch-compat.test.ts +++ b/src/infra/gaxios-fetch-compat.test.ts @@ -3,6 +3,7 @@ import { ProxyAgent } from "undici"; import { afterEach, describe, expect, it, vi } from "vitest"; const TEST_GAXIOS_CONSTRUCTOR_OVERRIDE = "__OPENCLAW_TEST_GAXIOS_CONSTRUCTOR__"; +type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise; describe("gaxios fetch compat", () => { afterEach(() => { @@ -14,14 +15,14 @@ describe("gaxios fetch compat", () => { it("uses native fetch without defining window or importing node-fetch", async () => { type MockRequestConfig = RequestInit & { - fetchImplementation?: typeof fetch; + fetchImplementation?: FetchLike; responseType?: string; url: string; }; let MockGaxiosCtor!: new () => { request(config: MockRequestConfig): Promise<{ data: string } & object>; }; - const fetchMock = vi.fn(async () => { + const fetchMock = vi.fn(async () => { return new Response("ok", { headers: { "content-type": "text/plain" }, status: 200, @@ -64,14 +65,14 @@ describe("gaxios fetch compat", () => { it("falls back to a legacy window fetch shim when gaxios is unavailable", async () => { const originalWindowDescriptor = Object.getOwnPropertyDescriptor(globalThis, "window"); - vi.stubGlobal("fetch", vi.fn()); + vi.stubGlobal("fetch", vi.fn()); Reflect.deleteProperty(globalThis as object, "window"); (globalThis as Record)[TEST_GAXIOS_CONSTRUCTOR_OVERRIDE] = null; const { installGaxiosFetchCompat } = await import("./gaxios-fetch-compat.js"); try { await expect(installGaxiosFetchCompat()).resolves.toBeUndefined(); - expect((globalThis as { window?: { fetch?: typeof fetch } }).window?.fetch).toBe(fetch); + expect((globalThis as { window?: { fetch?: FetchLike } }).window?.fetch).toBe(fetch); await expect(installGaxiosFetchCompat()).resolves.toBeUndefined(); } finally { Reflect.deleteProperty(globalThis as object, "window"); @@ -82,7 +83,7 @@ describe("gaxios fetch compat", () => { }); it("translates proxy agents into undici dispatchers for native fetch", async () => { - const fetchMock = vi.fn(async () => { + const fetchMock = vi.fn(async () => { return new Response("ok", { headers: { "content-type": "text/plain" }, status: 200, diff --git a/src/infra/gaxios-fetch-compat.ts b/src/infra/gaxios-fetch-compat.ts index 6f9d34bf7af..0d5c0684090 100644 --- a/src/infra/gaxios-fetch-compat.ts +++ b/src/infra/gaxios-fetch-compat.ts @@ -7,12 +7,13 @@ import { Agent as UndiciAgent, ProxyAgent } from "undici"; type ProxyRule = RegExp | URL | string; type TlsCert = ConnectionOptions["cert"]; type TlsKey = ConnectionOptions["key"]; +type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise; type GaxiosFetchRequestInit = RequestInit & { agent?: unknown; cert?: TlsCert; dispatcher?: Dispatcher; - fetchImplementation?: typeof fetch; + fetchImplementation?: FetchLike; key?: TlsKey; noProxy?: ProxyRule[]; proxy?: string | URL; @@ -240,7 +241,9 @@ function installLegacyWindowFetchShim(): void { (globalThis as Record).window = { fetch: globalThis.fetch }; } -export function createGaxiosCompatFetch(baseFetch: typeof fetch = globalThis.fetch): typeof fetch { +export function createGaxiosCompatFetch( + baseFetch: FetchLike = globalThis.fetch.bind(globalThis), +): FetchLike { return async (input: RequestInfo | URL, init?: RequestInit): Promise => { const gaxiosInit = (init ?? {}) as GaxiosFetchRequestInit; const requestUrl = diff --git a/src/plugin-sdk-internal/setup.ts b/src/plugin-sdk-internal/setup.ts index 6caf9253e14..c035d40376a 100644 --- a/src/plugin-sdk-internal/setup.ts +++ b/src/plugin-sdk-internal/setup.ts @@ -1,4 +1,5 @@ export type { OpenClawConfig } from "../config/config.js"; +export type { DmPolicy } from "../config/types.js"; export type { WizardPrompter } from "../wizard/prompts.js"; export type { ChannelSetupAdapter } from "../channels/plugins/types.adapters.js"; export type { ChannelSetupDmPolicy } from "../channels/plugins/setup-wizard-types.js"; diff --git a/src/plugin-sdk/telegram.ts b/src/plugin-sdk/telegram.ts index 3e1275c1425..6551baffe87 100644 --- a/src/plugin-sdk/telegram.ts +++ b/src/plugin-sdk/telegram.ts @@ -2,6 +2,7 @@ export type { ChannelAccountSnapshot, ChannelGatewayContext, ChannelMessageActionAdapter, + ChannelPlugin, } from "../channels/plugins/types.js"; export type { OpenClawConfig } from "../config/config.js"; export type { PluginRuntime } from "../plugins/runtime/types.js";