import type * as v from 'valibot'; /** * Properties shared by every enrichment-field variant. */ export type EnrichmentFieldBase = { /** Key written into the enrichment values object. */ key: string; /** Human label, derived from the key when no metadata is supplied. */ label: string; description?: string; /** Whether the schema marks this field optional. */ optional: boolean; }; /** * The variant-specific part of one enrichment field — the widget `type` * discriminant plus exactly the payload that widget carries. Mirrors the * `EnrichmentField` union in the skmtc-hub TypeSpec contract. * * There are deliberately NO standalone `module` / `schemaPath` widget * types: a component reference is only meaningful WITH the path that gives * it a type, so the pair is declared as one `moduleSelect` field. A * generator that uses the raw `moduleExport` / `schemaPath` schemas * standalone degrades to the generic object/array widgets. */ export type EnrichmentFieldShape = { type: 'text'; } | { type: 'textarea'; } | { type: 'toggle'; } | { type: 'select'; /** The selectable choices. */ options: string[]; } | { type: 'moduleSelect'; /** * The TS source of the contract a chosen module must satisfy for this * field (a single `export type XModule = …` the editor's matcher * checks candidates against). Always present: the module type is * explicit in the declaration (`lensInputModuleType` for the common * lens/input case), never an editor-side default. */ moduleType: string; } | { type: 'array'; /** Shape of each item. */ item: EnrichmentField; } | { type: 'object'; /** The nested object's fields. */ fields: EnrichmentField[]; }; /** * One node of a serialised enrichment-schema descriptor — the * form-renderable projection of a generator's enrichment schema, * discriminated on `type`. Recursive: `array` fields carry a single * `item` shape, `object` fields carry nested `fields`. */ export type EnrichmentField = EnrichmentFieldBase & EnrichmentFieldShape; /** The widget-type discriminant values of {@link EnrichmentField}. */ export type EnrichmentFieldType = EnrichmentField['type']; /** Which subject type a generator enriches — operations, webhooks, or models. */ export type SubjectType = 'operation' | 'model' | 'webhook'; /** * A generator's enrichment schema, projected for the CMS. The same * descriptor is what an agent would drive — the form UI is one * renderer of it. */ export type EnrichmentDescriptor = { generator: string; subjectType: SubjectType; /** * Whether this generator's entry declares variant support * (`supportsVariant: () => true`). The CMS reads it to decide whether to * offer the per-subject variant axis (add / rename / delete variants) above * the subject scope; `false` when the entry omits it. */ supportsVariant: boolean; fields: EnrichmentField[]; }; /** * Structural view of the data the walker needs from a generator entry. * Every entry returned by `toOasOperationEntry`, `toGqlOperationEntry`, * and `toModelEntry` satisfies this shape — the walker stays decoupled * from `GeneratorConfig` so callers can pass any entry-like object * (e.g. tests or programmatically authored generators). */ export type EnrichmentSource = { readonly id: string; readonly type: 'oasOperation' | 'gqlOperation' | 'model' | 'webhook'; readonly toEnrichmentSchema?: () => v.GenericSchema; /** * Whether the entry supports the variant axis. Required: every entry built by * `toOasOperationEntry` / `toGqlOperationEntry` / `toModelEntry` has it, * because the factory inserts a `() => false` default when the author omits * it — so by the time an entry reaches the descriptor the function always * exists. */ readonly supportsVariant: () => boolean; }; /** * Walk a Valibot object schema and return the projected list of * `EnrichmentField`s. A `v.optional(v.object({...}))` outer wrapper is * silently unwrapped; any non-object root yields an empty list; members that * unwrap to `v.undefined()` are omitted (see {@link isOmittedMember}). * * For a generator entry the schema is the three-scope **umbrella** composite * `v.object({ subject, generator, stack })` that `toEnrichmentSchema` returns, * so the top-level fields are the three scopes — each an `object` field whose * nested `fields` are that scope's own leaf. The walk discovers the scopes * structurally; it never names `subject` / `generator` / `stack`. A scope * declared `v.undefined()` (the no-enrichment marker) drops out, so a * subject-only generator yields just the `subject` scope and a fully empty * umbrella yields `[]`. * * Generally callers should prefer {@link toEnrichmentDescriptor}, which * takes a generator entry and fills in `generator` / `subjectType` * automatically. This lower-level entry point is useful in tests and * when only the field shape is needed. */ export declare const toEnrichmentFields: (schema: v.GenericSchema | undefined) => EnrichmentField[]; /** * Project a generator entry's enrichment schema into a serialisable * `EnrichmentDescriptor` the CMS can render as a form. The entry's * `id` becomes `descriptor.generator`; its `type` discriminator maps * to `subjectType` (`'oasOperation' | 'gqlOperation'` → `'operation'`; * `'webhook'` → `'webhook'`; `'model'` → `'model'`). If the entry has no * `toEnrichmentSchema`, or * declares the empty umbrella, the descriptor has an empty `fields` * array — the UI hides the section, matching the engine's "no * enrichments" behaviour. * * `toEnrichmentSchema` returns the three-scope umbrella composite * `v.object({ subject, generator, stack })`, so the descriptor's * top-level `fields` are the three scopes — each an `object` field whose * nested `fields` are that scope's own leaf (absent scopes drop out). The * `subject` scope describes one *variant*'s leaf shape; variant selection * sits above it in the editor UI, since the variant axis is core-owned. */ export declare const toEnrichmentDescriptor: (entry: EnrichmentSource) => EnrichmentDescriptor;