110 lines
4.8 KiB
TypeScript
110 lines
4.8 KiB
TypeScript
/**
|
|
* Rendering pipeline interface and public API.
|
|
*
|
|
* ## Pipeline (3 steps)
|
|
*
|
|
* 1. **Resolve** — A source node (config, agent) implements `IRenderingSource`. Given a
|
|
* `IRenderingContext` (graph, source id, callbacks), it produces a `IResolveResult`:
|
|
* resolved string, which output type to use, and optional reasoning text.
|
|
*
|
|
* 2. **Render** — The output type (e.g. plantuml, markdown, wireframe) implements
|
|
* `IOutputTypeRenderer`. It turns the resolved string into HTML or SVG via `render()`.
|
|
* Config types in configTypes.ts are the built-in implementations.
|
|
*
|
|
* 3. **Display** — The Rendering node picks a view (image viewport vs markdown content)
|
|
* from `outputType` on the renderer and shows the result. Output menu items (e.g. Export)
|
|
* come from the source node descriptor's getOutputMenuContent (see NodeTypeDescriptor).
|
|
*
|
|
* ## Implementing a new source
|
|
* - Implement source rendering logic (resolve step) and set it on the node descriptor
|
|
* via .sourceRenderingLogic(). Optionally set .outputMenuContent() for the Output menu.
|
|
* - The descriptor is registered via registerNodeType(); source logic is registered automatically.
|
|
*
|
|
* ## Implementing a new output type
|
|
* - Add a config type (or equivalent) fulfilling `IOutputTypeRenderer`.
|
|
* - Register in CONFIG_TYPES and use `getConfigType(id)` in the resolve step.
|
|
*
|
|
* ## Shared helpers
|
|
* - templateRefs.ts: isReachable, resolveExtendsRef, getTemplateRefs (Nunjucks extends/include/import).
|
|
* Used by config resolve and the rendering node hook so template/reachability logic stays in one place.
|
|
*/
|
|
|
|
import type {
|
|
ConfigTypeId,
|
|
ConfigOutputType,
|
|
OutputMenuDescriptor,
|
|
OutputMenuItemDescriptor,
|
|
OutputMenuAction,
|
|
RenderOptions,
|
|
} from './configTypes'
|
|
import type {
|
|
SourceRenderingLogicContext,
|
|
ResolvedContentResult,
|
|
SourceRenderingLogic,
|
|
} from './sourceRenderingLogic'
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Contracts (interfaces)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/** Input to the resolve step: graph state and callbacks for the source to use. */
|
|
export type IRenderingContext = SourceRenderingLogicContext
|
|
|
|
/**
|
|
* Result of the resolve step. The source produces a resolved string and declares
|
|
* which output type (renderer) to use for the render step.
|
|
*/
|
|
export interface IResolveResult {
|
|
/** Resolved content (e.g. after Nunjucks, or agent output). */
|
|
resolved: string
|
|
/** Which output type will render this (e.g. 'plantuml', 'markdown'). */
|
|
outputTypeId: ConfigTypeId
|
|
/** Optional reasoning block for the UI (e.g. agent reasoning). */
|
|
reasoning?: string
|
|
}
|
|
|
|
/**
|
|
* Contract for a node type that can feed the Rendering node (config, agent, etc.).
|
|
* Set on the node descriptor via .sourceRenderingLogic(); output menu via .outputMenuContent().
|
|
*/
|
|
export interface IRenderingSource {
|
|
/** When to re-run: 'auto' on upstream changes, 'manual' only on Run. */
|
|
defaultUpdateMode: 'auto' | 'manual'
|
|
/** Resolve step: produce content and choose output type. */
|
|
getResolvedContent(context: IRenderingContext): Promise<IResolveResult>
|
|
}
|
|
|
|
/**
|
|
* Contract for an output type that turns resolved content into HTML/SVG.
|
|
* Config types (plantuml, markdown, wireframe) implement this.
|
|
*/
|
|
export interface IOutputTypeRenderer {
|
|
id: ConfigTypeId
|
|
/** How to display: 'image' (viewport) or 'html' (scrollable div). */
|
|
outputType: ConfigOutputType
|
|
/** Render resolved content to HTML or SVG string. */
|
|
render(content: string, options?: RenderOptions): Promise<string>
|
|
/** Optional: output menu items when this type is shown (e.g. Export). */
|
|
outputMenuDescriptor?: OutputMenuDescriptor
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Re-exports: source logic (resolve step)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export type { SourceRenderingLogic, ResolvedContentResult, SourceRenderingLogicContext }
|
|
export { registerSourceRenderingLogic, getSourceRenderingLogic } from './sourceRenderingLogic'
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Re-exports: output types (render step) and menu
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export type { ConfigTypeId, ConfigOutputType, OutputMenuDescriptor, OutputMenuItemDescriptor, OutputMenuAction, RenderOptions }
|
|
export { getConfigType, getConfigTypeId, getConfigContent, outputMenuActionRequiresSvg } from './configTypes'
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Re-exports: shared utils (pure helpers used by hook and views)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export { parseThinkSections, processSvgDisplay, stripTemplateSyntax } from './renderingUtils'
|