import { EngineServicesClient } from './client'; import { ProjectRecipes, CatalogEntry, RecipeKit } from './project-recipes'; /** * How a settings property says "this names something that EXISTS". Put it on * the property as `x-existing` inside {@link RecipeManifest.settingsSchema}: * the app resolves the candidates and renders a list — people pick, they * never type the name of a thing that exists. * * Resolving the candidates is the APP's job (the native application knows its * own types and levels). The kinds are stable so nothing changes for recipes * when a shared reader lands. */ export interface ExistingLookup { /** What kind of existing thing: 'document' | 'family-type' | 'level' | 'layer' | 'workset'… */ of: string; /** Where it exists: the target document, or the declared source. Default 'target'. */ from?: 'target' | 'source'; /** * Narrows the candidates: attribute equals value, against the attribute * names EXACTLY as the native application publishes them, no case * normalization. Prefer the stable machine fields over display names — * Revit's `Category` text is localized per install ("Armazón estructural"), * so a column filter is `{ CategoryId: '-2001330' }`, never * `{ Category: 'Columns' }`. */ where?: Record; } /** What a recipe declares about itself. Shown in catalogs, checked by apps. */ export interface RecipeManifest { /** Machine name, unique in a catalog: 'rhino-points-to-revit-columns'. */ name: string; /** The human name a list shows: 'Rhino points to Revit columns'. */ title?: string; /** The one sentence a non-programmer reads: what it converts into what. */ description: string; /** The long-form explanation an app renders, as markdown. */ doc?: string; /** The native application whose language it writes: 'revit', 'autocad'… */ to: string; /** The input kinds it understands: 'rhino-model', 'platform-elements', 'points', 'csv'… */ inputs: string[]; /** * What the native application offers as the input picker, when the input is * a thing of the project rather than inline data: another connected * document, or a project file (then `extensions` narrows the listing). * {@link Recipes.choices} lists the candidates; the picked one arrives as * `input` ({@link PickedSource}). */ source?: { kind: 'document'; source?: string; } | { kind: 'project-file'; extensions?: string[]; }; /** * JSON Schema for `settings`. Apps generate the settings form from it, so * anything that names an EXISTING thing (a family, a level) carries * `x-existing` ({@link ExistingLookup}) and renders as a list the app fills — * people pick, they never type names of things that exist. Free text is only * for what a person invents. */ settingsSchema?: Record; /** * The self-documentation an app renders: a "reads → writes" table whose rows * are RULES (not objects), so every run can fill it with real tallies. */ rules?: { reads: string; writes: string; }[]; } /** One thing this recipe made in the target before, as the target remembers it. */ export interface RecipeMade { /** The target's id of what was made (Revit's UniqueId). */ id: string; /** The fingerprint of what it was made from (`flow:print`): unchanged source, nothing to do. */ print?: string; } /** Everything a recipe's `run` gets to work with. */ export interface RecipeContext> { client: EngineServicesClient; projectId: string; /** The document the changes are for: its native application, its id and the version it is on, when the platform knows it. */ target: { source: string; docId?: string; version?: number; }; /** * What this recipe made in the target before: source key → what it made. * The native application keeps it with the document and hands it back, * filtered to what still exists there. Empty on a first run. */ made: ReadonlyMap; /** * The id of this run, minted before it: the changes' envelope * (`revitflow/op@2`) carries it inside. */ opId: string; /** The declared input: the picked source ({@link PickedSource}), ids, rows… */ input: unknown; settings: Settings; /** Says how far it is, for the native application's progress bar: a line, and a fraction 0..1 when known. */ progress: (says: string, fraction?: number) => void; /** The tools the built-ins are written with, for a project recipe's code (which imports nothing). */ kit?: RecipeKit; } /** What a recipe's `run` returns: the changes, ready to be written in the target. */ export interface RecipeResult { title: string; /** add | set | remove | mixed. */ verb: string; /** The changes, as a .frag (envelope `revitflow/op@2`), when the recipe builds one. */ payload?: Blob; /** How many changes it carries. */ targets?: number; /** Per-rule tallies matching `manifest.rules`, filled by the run. */ ruleTallies?: { read: number; written: number; }[]; } /** A recipe: its manifest plus the function that writes the changes. */ export interface Recipe> extends RecipeManifest { run(context: RecipeContext): Promise; } /** The project file or document a person picked as a recipe's source. */ export interface PickedSource { fileId: string; /** The file's name, extension included: what says its format. */ name: string; /** The document it is the native file of, when it is one: the folder the history is written to. */ folderId?: string; /** The storage version to read (its versionTag); the latest when absent. */ version?: string; } /** One candidate for a recipe's source, as {@link Recipes.choices} lists it. */ export interface RecipeChoice extends PickedSource { /** What the picker shows: the document's name. */ label: string; version: string; } /** * A recipe that has nothing to write: everything it would ask for is in the * target already, as the source has it. Not a failure: the native * application says «up to date». */ export declare class UpToDate extends Error { constructor(message: string); } /** * Turns a file of another format into a .frag that carries the platform's * records (`Element` / `Carried` on each item), the one form recipes read. */ export type RecordsImporter = (bytes: Uint8Array, name: string) => Promise; /** * A file's shapes as its own geometry and placements (the engine's `ifcShapes`): what a recipe needs to define a * family once per shape and place it many times. Z up, metres. The host that has the engine provides it. */ export interface SourceShapes { geometries: Map; elements: Map; } export type ShapesReader = (bytes: Uint8Array, name: string) => Promise; /** * The local recipe registry and runner. Reach it as `client.recipes`. */ export declare class Recipes { #private; private readonly client; /** The project's own recipes: list, save, versions, load (see project-recipes.ts). */ readonly project: ProjectRecipes; constructor(client: EngineServicesClient); /** * Says how this host turns files of one extension ('ifc') into records, so a * recipe can be pointed at the raw file and convert it as its first step. * The converter lives in the engine, which the SDK does not carry: the host * that has it provides it. */ provideImporter(extension: string, importer: RecordsImporter): void; /** Says how this host reads a file's shapes (its geometry, per element and per type), for recipes that make families. */ provideShapes(extension: string, reader: ShapesReader): void; /** The shapes reader provided for an extension, or undefined. */ shapesFor(extension: string): ShapesReader | undefined; /** The importer provided for an extension, or undefined. */ importerFor(extension: string): RecordsImporter | undefined; /** Registers a recipe. One per name; a second with the same name throws. */ register(recipe: Recipe): void; /** The registered recipes, optionally filtered by target application. */ list(filter?: { to?: string; input?: string; }): RecipeManifest[]; /** A registered recipe by name, or undefined. */ get(name: string): RecipeManifest | undefined; /** * Every recipe a project can use: the built-ins, always, and the project's own (each its latest * version), optionally only those that write one application. */ catalog(projectId: string, filter?: { to?: string; }): Promise; /** A recipe by name for a project: a built-in, or the project's own (its latest version unless named). */ resolve(name: string, projectId: string, version?: string): Promise<{ recipe: Recipe; origin: 'builtin' | 'project'; version?: string; }>; /** * The candidates for a recipe's source in a project, for the picker: the * documents whose native file has one of the declared extensions, each with * the version it is on now. A recipe with no declared source has none. */ choices(name: string, projectId: string): Promise; /** * Runs a recipe: the changes that make the target match its source, given * what it made there before. Throws {@link UpToDate} when there is nothing * to write. The caller (the native application's plugin) writes them. */ run(name: string, options: RecipeRunOptions): Promise; } /** The options of {@link Recipes.run}. */ export interface RecipeRunOptions> { projectId: string; /** The target document: its native application, and its id and version when the platform knows it. */ target: { source: string; docId?: string; version?: number; }; input?: unknown; settings?: S; /** What this recipe made in the target before (see {@link RecipeContext.made}). */ made?: ReadonlyMap; /** The run's id, when the caller wants to name it; minted otherwise. */ opId?: string; /** A project recipe's version to run; its latest when absent. Built-ins have none. */ recipeVersion?: string; progress?: (says: string, fraction?: number) => void; } /** Each file's latest storage version tag (newest by date, then by number). */ export declare function latestVersions(client: EngineServicesClient, fileIds: string[]): Promise>;