import * as v from "valibot" import type { CustomBlockErrorInfo } from "../errors.js" import { notionUserListSchema } from "../users/user.js" // The schema accepts any string code. The type lists known codes for // autocomplete, with an open string fallback for newer senders. export const customBlockListUsersErrorCodeSchema = v.string() export type CustomBlockListUsersErrorCode = "list_users_failed" | (string & {}) export type CustomBlockListUsersErrorInfo = CustomBlockErrorInfo export const customBlockListUsersErrorInfoSchema = v.object({ code: customBlockListUsersErrorCodeSchema, message: v.string(), isRetryable: v.boolean(), }) /** * Sandbox -> host: list users visible in the custom block's workspace. */ export const listUsersMessageSchema = v.object({ type: v.literal("listUsers"), requestId: v.string(), startCursor: v.optional(v.string()), pageSize: v.optional(v.number()), }) export type ListUsersMessage = v.InferOutput export const listUsersResultMessageSchema = v.variant("status", [ v.object({ type: v.literal("listUsersResult"), requestId: v.string(), status: v.literal("success"), list: notionUserListSchema, }), v.object({ type: v.literal("listUsersResult"), requestId: v.string(), status: v.literal("error"), error: customBlockListUsersErrorInfoSchema, }), ]) export type ListUsersResultMessage = v.InferOutput< typeof listUsersResultMessageSchema >