diff --git a/extensions/mattermost/src/mattermost/client.ts b/extensions/mattermost/src/mattermost/client.ts index e828b4fdb6a..977d019483c 100644 --- a/extensions/mattermost/src/mattermost/client.ts +++ b/extensions/mattermost/src/mattermost/client.ts @@ -1,4 +1,5 @@ import { fetchWithSsrFGuard } from "openclaw/plugin-sdk/infra-runtime"; +import { z } from "openclaw/plugin-sdk/zod"; export type MattermostClient = { baseUrl: string; @@ -25,17 +26,21 @@ export type MattermostChannel = { team_id?: string | null; }; -export type MattermostPost = { - id: string; - user_id?: string | null; - channel_id?: string | null; - message?: string | null; - file_ids?: string[] | null; - type?: string | null; - root_id?: string | null; - create_at?: number | null; - props?: Record | null; -}; +export const MattermostPostSchema = z + .object({ + id: z.string(), + user_id: z.string().nullable().optional(), + channel_id: z.string().nullable().optional(), + message: z.string().nullable().optional(), + file_ids: z.array(z.string()).nullable().optional(), + type: z.string().nullable().optional(), + root_id: z.string().nullable().optional(), + create_at: z.number().nullable().optional(), + props: z.record(z.string(), z.unknown()).nullable().optional(), + }) + .passthrough(); + +export type MattermostPost = z.infer; export type MattermostFileInfo = { id: string; diff --git a/extensions/mattermost/src/mattermost/monitor-websocket.ts b/extensions/mattermost/src/mattermost/monitor-websocket.ts index 5ab178bb82d..908e77fb5bb 100644 --- a/extensions/mattermost/src/mattermost/monitor-websocket.ts +++ b/extensions/mattermost/src/mattermost/monitor-websocket.ts @@ -1,8 +1,8 @@ import { safeParseJsonWithSchema, safeParseWithSchema } from "openclaw/plugin-sdk/extension-shared"; +import { z } from "openclaw/plugin-sdk/zod"; import WebSocket from "ws"; -import { z } from "zod"; import type { ChannelAccountSnapshot, RuntimeEnv } from "../runtime-api.js"; -import type { MattermostPost } from "./client.js"; +import { MattermostPostSchema, type MattermostPost } from "./client.js"; import { rawDataToString } from "./monitor-helpers.js"; export type MattermostEventPayload = { @@ -36,11 +36,6 @@ export type MattermostWebSocketLike = { export type MattermostWebSocketFactory = (url: string) => MattermostWebSocketLike; -const MattermostPostSchema = z.record( - z.string(), - z.unknown(), -) as unknown as z.ZodType; - const MattermostEventPayloadSchema = z.object({ event: z.string().optional(), data: z