Code0 LogoCodeZero

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

DecoratorDescription
@IdentifierSets the unique runtime identifier
@NameSets the localised display name
@DescriptionSets a short localised description
@DocumentationSets long-form documentation text
@DisplayMessageSets the summary text shown in the flow UI
@AliasSets alternative search terms
@DeprecationMessageMarks the function as deprecated
@SignatureSets the TypeScript-like signature string
@DisplayIconSets the icon shown in the flow UI
@ParameterAdds a parameter definition
@DesignAttaches a visual design token
@ThrowsErrorMarks the function as capable of throwing a RuntimeError
@OmitRuntimeFunctionPrevents auto-generation of a public function definition

On this page