UNPKG

histoire

Version:

A fast story book powered by Vite

459 lines • 15.9 kB
import type { ReadResourceResult } from '@modelcontextprotocol/server'; import { z } from 'zod/v4'; import { mcpToolInputSchemas, mcpToolOutputSchemas } from '../protocol/tool-schema.js'; /** Maximum serialized DTO frame; binary resource frames have a separate bound. */ export declare const WORKER_METADATA_BYTES: number; /** Base64 expansion of one 4 MiB artifact, with a bounded envelope. */ export declare const WORKER_BINARY_BYTES: number; /** Fixed method registry; neither side accepts module names or arbitrary calls. */ export declare const workerMethods: { readonly getProject: 'histoire_get_project'; readonly listStories: 'histoire_list_stories'; readonly getStory: 'histoire_get_story'; readonly getDocs: 'histoire_get_docs'; readonly getSource: 'histoire_get_source'; readonly getPreview: 'histoire_get_preview'; readonly admitScreenshot: 'histoire_capture_screenshot'; readonly admitTests: 'histoire_run_tests'; readonly inspectVariant: 'histoire_inspect_variant'; readonly inspectDom: 'histoire_inspect_dom'; readonly inspectAccessibility: 'histoire_inspect_accessibility'; readonly runtimeDiagnostics: 'histoire_get_runtime_diagnostics'; readonly getOperation: 'histoire_get_operation'; readonly cancelOperation: 'histoire_cancel_operation'; }; /** Admission routing shared by worker discovery and its finite parent proxy. */ export declare const workerExecutionMethods: { readonly screenshot: 'admitScreenshot'; readonly tests: 'admitTests'; readonly 'inspect-variant': 'inspectVariant'; readonly 'inspect-dom': 'inspectDom'; readonly 'inspect-accessibility': 'inspectAccessibility'; readonly 'runtime-diagnostics': 'runtimeDiagnostics'; }; /** Finite worker method identity. */ export type WorkerMethod = keyof typeof workerMethods | 'readResource'; /** Public DTO for every finite dispatch result; project runtime types stay private. */ export type WorkerResultMap = { [Name in keyof typeof workerMethods]: Extract<z.infer<(typeof mcpToolOutputSchemas)[(typeof workerMethods)[Name]]>, { ok: true; }>['data']; } & { readResource: ReadResourceResult; }; /** Parsed strict input DTO for every finite dispatch method. */ export type WorkerInputMap = { [Name in keyof typeof workerMethods]: z.infer<(typeof mcpToolInputSchemas)[(typeof workerMethods)[Name]]>; } & { readResource: { uri: string; }; }; /** Finite parent messages. */ export declare const workerParentMessageSchema: z.ZodUnion<readonly [z.ZodObject<{ type: z.ZodLiteral<"request">; id: z.ZodString; method: z.ZodEnum<{ admitScreenshot: "admitScreenshot"; admitTests: "admitTests"; cancelOperation: "cancelOperation"; getDocs: "getDocs"; getOperation: "getOperation"; getPreview: "getPreview"; getProject: "getProject"; getSource: "getSource"; getStory: "getStory"; inspectAccessibility: "inspectAccessibility"; inspectDom: "inspectDom"; inspectVariant: "inspectVariant"; listStories: "listStories"; readResource: "readResource"; runtimeDiagnostics: "runtimeDiagnostics"; }>; input: z.ZodJSONSchema; readTool: z.ZodOptional<z.ZodEnum<{ histoire_get_docs: "histoire_get_docs"; histoire_get_preview: "histoire_get_preview"; histoire_get_project: "histoire_get_project"; histoire_get_source: "histoire_get_source"; histoire_get_story: "histoire_get_story"; histoire_list_stories: "histoire_list_stories"; }>>; }, z.core.$strict>, z.ZodObject<{ type: z.ZodLiteral<"client-name">; name: z.ZodString; }, z.core.$strict>, z.ZodObject<{ type: z.ZodLiteral<"cancel">; id: z.ZodString; }, z.core.$strict>, z.ZodObject<{ type: z.ZodLiteral<"shutdown">; }, z.core.$strict>]>; /** Finite child messages; method-specific result validation happens afterwards. */ export declare const workerChildMessageSchema: z.ZodUnion<readonly [z.ZodObject<{ type: z.ZodLiteral<"boot">; project: z.ZodObject<{ projectId: z.ZodString; epoch: z.ZodUUID; runtimeMode: z.ZodEnum<{ dev: "dev"; node: "node"; }>; buildId: z.ZodOptional<z.ZodString>; status: z.ZodEnum<{ closed: "closed"; failed: "failed"; ready: "ready"; restarting: "restarting"; starting: "starting"; }>; revision: z.ZodOptional<z.ZodString>; updating: z.ZodBoolean; title: z.ZodString; base: z.ZodString; routerMode: z.ZodEnum<{ hash: "hash"; history: "history"; }>; storyCount: z.ZodNumber; variantCount: z.ZodNumber; capabilities: z.ZodObject<{ catalog: z.ZodBoolean; content: z.ZodBoolean; previews: z.ZodBoolean; screenshots: z.ZodObject<{ available: z.ZodBoolean; reason: z.ZodOptional<z.ZodString>; }, z.core.$strict>; inspection: z.ZodOptional<z.ZodObject<{ available: z.ZodBoolean; reason: z.ZodOptional<z.ZodString>; }, z.core.$strict>>; tests: z.ZodObject<{ available: z.ZodBoolean; reason: z.ZodOptional<z.ZodString>; engine: z.ZodEnum<{ "built-preview": "built-preview"; "project-vitest": "project-vitest"; unavailable: "unavailable"; }>; }, z.core.$strict>; }, z.core.$strict>; diagnostics: z.ZodArray<z.ZodObject<{ filePath: z.ZodOptional<z.ZodString>; storyId: z.ZodOptional<z.ZodString>; code: z.ZodString; message: z.ZodString; }, z.core.$strict>>; diagnosticsTruncated: z.ZodOptional<z.ZodBoolean>; }, z.core.$strict>; executors: z.ZodObject<{ screenshot: z.ZodBoolean; tests: z.ZodBoolean; 'inspect-variant': z.ZodOptional<z.ZodBoolean>; 'inspect-dom': z.ZodOptional<z.ZodBoolean>; 'inspect-accessibility': z.ZodOptional<z.ZodBoolean>; 'runtime-diagnostics': z.ZodOptional<z.ZodBoolean>; }, z.core.$strict>; }, z.core.$strict>, z.ZodObject<{ type: z.ZodLiteral<"result">; id: z.ZodString; data: z.ZodJSONSchema; }, z.core.$strict>, z.ZodObject<{ type: z.ZodLiteral<"error">; id: z.ZodString; error: z.ZodObject<{ code: z.ZodEnum<{ ARTIFACT_NOT_FOUND: "ARTIFACT_NOT_FOUND"; BROWSER_UNAVAILABLE: "BROWSER_UNAVAILABLE"; CANCELLED: "CANCELLED"; CAPABILITY_UNAVAILABLE: "CAPABILITY_UNAVAILABLE"; COLLECTION_FAILED: "COLLECTION_FAILED"; CURSOR_EXPIRED: "CURSOR_EXPIRED"; DEPENDENCY_MISSING: "DEPENDENCY_MISSING"; DOCS_NOT_FOUND: "DOCS_NOT_FOUND"; INTERNAL_ERROR: "INTERNAL_ERROR"; INVALID_CURSOR: "INVALID_CURSOR"; INVALID_SELECTOR: "INVALID_SELECTOR"; OPERATION_NOT_FOUND: "OPERATION_NOT_FOUND"; PATH_OUTSIDE_ROOT: "PATH_OUTSIDE_ROOT"; PREVIEW_NOT_READY: "PREVIEW_NOT_READY"; PROJECT_CLOSED: "PROJECT_CLOSED"; PROJECT_RESTARTING: "PROJECT_RESTARTING"; PROJECT_STARTING: "PROJECT_STARTING"; QUEUE_FULL: "QUEUE_FULL"; REQUEST_KEY_CONFLICT: "REQUEST_KEY_CONFLICT"; RESULT_TOO_LARGE: "RESULT_TOO_LARGE"; SOURCE_UNAVAILABLE: "SOURCE_UNAVAILABLE"; STALE_REVISION: "STALE_REVISION"; STORY_AMBIGUOUS: "STORY_AMBIGUOUS"; STORY_NOT_FOUND: "STORY_NOT_FOUND"; TIMEOUT: "TIMEOUT"; VARIANT_NOT_FOUND: "VARIANT_NOT_FOUND"; }>; message: z.ZodString; retryable: z.ZodBoolean; details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>; }, z.core.$strict>; }, z.core.$strict>, z.ZodObject<{ type: z.ZodLiteral<"closed">; }, z.core.$strict>]>; /** Parsed parent message. */ export type WorkerParentMessage = z.infer<typeof workerParentMessageSchema>; /** Parsed child message. */ export type WorkerChildMessage = z.infer<typeof workerChildMessageSchema>; /** Reject oversized messages before schema traversal; never echo their contents. */ export declare function assertWorkerFrame(value: unknown, binary?: boolean): void; /** Only registered PNG resource results qualify for the larger frame budget. */ export declare function isWorkerBinaryResult(value: unknown): boolean; /** Parse exact method inputs using public contracts rather than duplicate DTOs. */ export declare function parseWorkerInput<T extends WorkerMethod>(method: T, input: unknown): WorkerInputMap[T]; /** Validate worker output before any DTO reaches an SDK callback. */ export declare function parseWorkerResult(method: WorkerMethod, data: unknown): { operationId: string; projectId: string; epoch: string; revision: string; kind: "inspect-accessibility" | "inspect-dom" | "inspect-variant" | "runtime-diagnostics" | "screenshot" | "tests"; state: "cancelled" | "cancelling" | "completed" | "failed" | "queued" | "running"; createdAt: string; startedAt?: string; finishedAt?: string; result?: { storyId: string; variantId: string; viewport: { width: number; height: number; }; truncated: boolean; inspection: "variant"; state: Record<string, z.JSONType>; propsAvailable: boolean; components: { name: string; index: number; props: { name: string; types?: string[]; required?: boolean; default?: z.JSONType; value?: z.JSONType; values?: z.JSONType[]; }[]; }[]; omittedValues: number; } | { storyId: string; variantId: string; viewport: { width: number; height: number; }; truncated: boolean; inspection: "dom"; matched: boolean; nodes: { index: number; parentIndex?: number; tag: string; attributes: Record<string, string>; text: string; rect: { x: number; y: number; width: number; height: number; }; styles: Record<string, string>; }[]; } | { storyId: string; variantId: string; viewport: { width: number; height: number; }; truncated: boolean; inspection: "accessibility"; matched: boolean; snapshot: string; totalCharacters: number; } | { storyId: string; variantId: string; viewport: { width: number; height: number; }; truncated: boolean; inspection: "diagnostics"; previewReady: boolean; readinessError?: string; entries: { kind: "console" | "http-error" | "page-error" | "request-failed"; level?: string; message: string; url?: string; status?: number; }[]; droppedCount: number; } | { storyId: string; variantId: string; width: number; height: number; mimeType: "image/png"; bytes: number; sha256: string; artifactUri: string; } | { storyId: string; variantId?: string; engine: "built-preview" | "project-vitest"; summary: import("@histoire/protocol").HistoireTestRunSummary; truncated: boolean; }; error?: { code: "ARTIFACT_NOT_FOUND" | "BROWSER_UNAVAILABLE" | "CANCELLED" | "CAPABILITY_UNAVAILABLE" | "COLLECTION_FAILED" | "CURSOR_EXPIRED" | "DEPENDENCY_MISSING" | "DOCS_NOT_FOUND" | "INTERNAL_ERROR" | "INVALID_CURSOR" | "INVALID_SELECTOR" | "OPERATION_NOT_FOUND" | "PATH_OUTSIDE_ROOT" | "PREVIEW_NOT_READY" | "PROJECT_CLOSED" | "PROJECT_RESTARTING" | "PROJECT_STARTING" | "QUEUE_FULL" | "REQUEST_KEY_CONFLICT" | "RESULT_TOO_LARGE" | "SOURCE_UNAVAILABLE" | "STALE_REVISION" | "STORY_AMBIGUOUS" | "STORY_NOT_FOUND" | "TIMEOUT" | "VARIANT_NOT_FOUND"; message: string; retryable: boolean; details?: Record<string, z.JSONType>; }; } | { contents: ({ uri: string; mimeType?: string; text: string; _meta?: Record<string, z.JSONType>; } | { uri: string; mimeType: "image/png"; blob: string; _meta?: Record<string, z.JSONType>; })[]; } | { projectId: string; epoch: string; runtimeMode: "dev" | "node"; buildId?: string; status: "closed" | "failed" | "ready" | "restarting" | "starting"; revision?: string; updating: boolean; title: string; base: string; routerMode: "hash" | "history"; storyCount: number; variantCount: number; capabilities: { catalog: boolean; content: boolean; previews: boolean; screenshots: { available: boolean; reason?: string; }; inspection?: { available: boolean; reason?: string; }; tests: { available: boolean; reason?: string; engine: "built-preview" | "project-vitest" | "unavailable"; }; }; diagnostics: { filePath?: string; storyId?: string; code: string; message: string; }[]; diagnosticsTruncated?: boolean; } | { projectId: string; revision: string; updating: boolean; items: { id: string; title: string; treePath: string[]; filePath: string; fileOrigin?: "external" | "generated" | "project"; supportPluginId: string; group?: string; docsOnly: boolean; variants: { id: string; title: string; }[]; docsAvailable: boolean; sourceAvailable: boolean; sourceKind: "file" | "unavailable" | "virtual"; }[]; nextCursor?: string; total: number; diagnostics: { filePath?: string; storyId?: string; code: string; message: string; }[]; diagnosticsTruncated: boolean; } | { projectId: string; revision: string; story: { id: string; title: string; treePath: string[]; filePath: string; fileOrigin?: "external" | "generated" | "project"; supportPluginId: string; group?: string; docsOnly: boolean; variants: { id: string; title: string; }[]; docsAvailable: boolean; sourceAvailable: boolean; sourceKind: "file" | "unavailable" | "virtual"; }; resources: { story: string; docs?: string; source?: string; }; } | { projectId: string; revision: string; storyId: string; text: string; offset: number; nextOffset?: number; totalCharacters: number; sha256: string; kind: "markdown" | "text"; filePath?: string; origin: "collected" | "sibling" | "standalone"; } | { projectId: string; revision: string; storyId: string; kind: "file" | "virtual"; filePath: string; text: string; startLine: number; endLine: number; totalLines: number; nextLine?: number; sha256: string; } | { projectId: string; revision: string; storyId: string; variantId: string; storyUrl: string; sandboxUrl: string; }; //# sourceMappingURL=worker-protocol.d.ts.map