import { z } from "zod/v4"; import { colineUiNodeSchema } from "../tree/tree"; import { toolInvokeCapabilitiesSchema } from "./tool-invoke"; /** * Wire payloads for surface rendering (plan §7.1, §9.3), carried inside * the protocol v2 envelope with `kind: "render.surface"`. * * One render kind covers every tree-tier surface: the app home, and a * file type's editor/preview/inline surfaces. Render contexts are * read-only by construction — the invocation token carries effect "read", * so a render handler that attempts a mutation fails at the capability * gate (plan §12.2). */ export const RENDER_SURFACE_KIND = "render.surface" as const; export const RENDER_SURFACES = ["home", "editor", "preview", "inline"] as const; export const renderSurfaceSchema = z.enum(RENDER_SURFACES); export type RenderSurface = z.infer; export const renderSurfacePayloadSchema = z.strictObject({ surface: renderSurfaceSchema, /** Present for file surfaces; absent for "home". */ file: z .strictObject({ fileId: z.string().min(1).max(200), name: z.string().max(300), typeKey: z.string().min(1).max(160), version: z.number().int().min(0), }) .optional(), /** The file's JSON document, for file surfaces on stored types. */ document: z.record(z.string(), z.unknown()).optional(), capabilities: toolInvokeCapabilitiesSchema, }); export type RenderSurfacePayload = z.infer; export const renderSurfaceResponseSchema = z.union([ z.strictObject({ result: z.strictObject({ tree: colineUiNodeSchema }) }), z.strictObject({ error: z.strictObject({ code: z.string().min(1).max(120), message: z.string().min(1).max(2000), }), }), ]); export type RenderSurfaceResponse = z.infer;