/** * Variable Service * Derives available template variables from connected upstream nodes' output schemas. * Used by the template editor for autocomplete suggestions. * * @module services/variableService */ import type { WorkflowNode, WorkflowEdge, VariableSchema, TemplateVariable, TemplateVariablesConfig, AuthProvider } from '../types/index.js'; /** * Options for deriving available variables. */ export interface GetAvailableVariablesOptions { /** * Filter to only include variables from specific input ports. * If not specified, all input ports with connections are used. * If specified as an empty array, no variables will be available. */ targetPortIds?: string[]; /** * Whether to include the port name as a prefix for variables. * When true, variables are named like `data.user` instead of just `user`. * When false (default), schema properties are unpacked as top-level variables. */ includePortName?: boolean; } /** * Derives available template variables from connected upstream nodes. * Variables are extracted from the output schemas of nodes connected to * the current node's input ports. * * @param node - The current node being configured * @param nodes - All nodes in the workflow * @param edges - All edges in the workflow * @param options - Optional configuration for filtering variables * @returns A VariableSchema containing all available variables * * @example * ```typescript * // Get variables from all connected ports * const variableSchema = getAvailableVariables(currentNode, allNodes, allEdges); * * // Get variables only from specific input ports * const filteredSchema = getAvailableVariables(currentNode, allNodes, allEdges, { * targetPortIds: ["data", "context"] * }); * ``` */ export declare function getAvailableVariables(node: WorkflowNode, nodes: WorkflowNode[], edges: WorkflowEdge[], options?: GetAvailableVariablesOptions): VariableSchema; /** * Gets the child variables for a given path in the variable schema. * Used for drilling down into nested objects and arrays. * * @param schema - The variable schema * @param path - The path to the parent variable (e.g., "user", "user.address") * @returns Array of child variables, or empty array if none found * * @example * ```typescript * // For path "user" with schema containing user.name, user.email, user.address * getChildVariables(schema, "user"); * // Returns: [{ name: "name", ... }, { name: "email", ... }, { name: "address", ... }] * * // For path "user.address" with schema containing city, country * getChildVariables(schema, "user.address"); * // Returns: [{ name: "city", ... }, { name: "country", ... }] * ``` */ export declare function getChildVariables(schema: VariableSchema, path: string): TemplateVariable[]; /** * Gets suggestions for array index access. * Returns common index options like [0], [1], [2], and [*] for all items. * * @param maxIndex - Maximum index to suggest (default: 2) * @returns Array of index suggestion strings */ export declare function getArrayIndexSuggestions(maxIndex?: number): string[]; /** * Checks if a variable at the given path is an array. * * @param schema - The variable schema * @param path - The path to check (e.g., "items", "user.orders") * @returns True if the variable is an array type */ export declare function isArrayVariable(schema: VariableSchema, path: string): boolean; /** * Checks if a variable at the given path has child properties. * * @param schema - The variable schema * @param path - The path to check * @returns True if the variable has children that can be drilled into */ export declare function hasChildren(schema: VariableSchema, path: string): boolean; /** * Merges two variable schemas together. * Variables from the primary schema take precedence over the secondary schema. * * @param primary - The primary variable schema (takes precedence) * @param secondary - The secondary variable schema * @returns A merged VariableSchema * * @example * ```typescript * const apiSchema = { variables: { apiKey: {...}, endpoint: {...} } }; * const staticSchema = { variables: { env: {...}, config: {...} } }; * const merged = mergeVariableSchemas(apiSchema, staticSchema); * // Result: { variables: { apiKey, endpoint, env, config } } * ``` */ export declare function mergeVariableSchemas(primary: VariableSchema, secondary: VariableSchema): VariableSchema; /** * Gets variable schema using the appropriate mode (API, schema-based, or hybrid). * This is the main orchestration function that determines how to fetch variables * based on the configuration. * * @param node - The current node being configured * @param nodes - All nodes in the workflow * @param edges - All edges in the workflow * @param config - Template variables configuration * @param workflowId - Optional workflow ID for API context * @param authProvider - Optional auth provider for API requests * @returns A promise that resolves to the variable schema * * @example * ```typescript * // Schema-based mode (existing behavior) * const config = { ports: ["data"], schema: {...} }; * const schema = await getVariableSchema(node, nodes, edges, config); * * // API mode * const config = { api: { endpoint: { url: "/api/variables/{workflowId}/{nodeId}" } } }; * const schema = await getVariableSchema(node, nodes, edges, config, workflowId, authProvider); * * // Hybrid mode (API + static schema) * const config = { * schema: {...}, * api: { endpoint: {...}, mergeWithSchema: true } * }; * const schema = await getVariableSchema(node, nodes, edges, config, workflowId, authProvider); * ``` */ export declare function getVariableSchema(node: WorkflowNode, nodes: WorkflowNode[], edges: WorkflowEdge[], config: TemplateVariablesConfig, workflowId?: string, authProvider?: AuthProvider): Promise;