RuntimeFunction
The implementation layer for callable functions
A RuntimeFunction is a class with a run() method that Hercules calls when an execution request arrives from
Aquila. It is the implementation layer — all logic lives here.
import { Identifier, Signature, Name, OmitRuntimeFunction } from '@code0-tech/hercules';Overview
When action.registerRuntimeFunction() is called, Hercules automatically also registers a FunctionProps entry using
the same metadata. Apply @OmitRuntimeFunction to suppress this and register
the public definition manually via action.registerFunction().
The descriptor stored in action.runtimeFunctions is documented on the
RuntimeFunctionManager page.
RuntimeFunctionClass
type RuntimeFunctionClass<T extends RuntimeFunctionRunnable = RuntimeFunctionRunnable> =
new () => T;The constructor type accepted by action.registerRuntimeFunction().
Example
@Identifier('fibonacci_runtime')
@Signature('(n: number): number')
@OmitRuntimeFunction()
export class FibonacciRuntimeFunction {
run(context: FunctionContext, n: number): number {
if (n <= 1) return n;
return this.run(context, n - 1) + this.run(context, n - 2);
}
}Error Handling
Throw a RuntimeError to signal a recoverable error back to the platform:
import { RuntimeError } from '@code0-tech/hercules';
run(context: FunctionContext, input: string): string {
if (!input) throw new RuntimeError('INVALID_INPUT', 'Input must not be empty');
return input.toUpperCase();
}Mark the function with @ThrowsError so the platform knows to handle the error case.
Decorators
| Decorator | Description |
|---|---|
@Identifier | Sets the unique runtime identifier |
@Name | Sets the localised display name |
@Description | Sets a short localised description |
@Documentation | Sets long-form documentation text |
@DisplayMessage | Sets the summary text shown in the flow UI |
@Alias | Sets alternative search terms |
@DeprecationMessage | Marks the function as deprecated |
@Signature | Sets the TypeScript-like signature string |
@DisplayIcon | Sets the icon shown in the flow UI |
@Parameter | Adds a parameter definition |
@Design | Attaches a visual design token |
@ThrowsError | Marks the function as capable of throwing a RuntimeError |
@OmitRuntimeFunction | Prevents auto-generation of a public function definition |