import * as v from "valibot" import { notionDataSourcePageBridgeSchema } from "../dataSources/dataSourcePage.js" import type { CustomBlockErrorInfo } from "../errors.js" // The schema accepts any string code. The type lists known codes for // autocomplete, with an open string fallback for newer senders. export const customBlockQueryDataSourceErrorCodeSchema = v.string() export type CustomBlockQueryDataSourceErrorCode = | "query_data_source_failed" | "unknown_data_source_key" | "unmapped_data_source" | (string & {}) export type CustomBlockQueryDataSourceErrorInfo = CustomBlockErrorInfo export const customBlockQueryDataSourceErrorInfoSchema = v.object({ code: customBlockQueryDataSourceErrorCodeSchema, message: v.string(), isRetryable: v.boolean(), }) /** * Message sent by the host to the sandbox in response to a `queryDataSource` request. */ export const queryDataSourceResultMessageSchema = v.object({ type: v.literal("queryDataSourceResult"), requestId: v.string(), snapshotId: v.string(), items: v.array(notionDataSourcePageBridgeSchema), hasMore: v.boolean(), error: v.optional(customBlockQueryDataSourceErrorInfoSchema), }) export type QueryDataSourceResultMessage = v.InferOutput< typeof queryDataSourceResultMessageSchema >