diff --git a/src/engine/executionEngineDecorators.ts b/src/engine/executionEngineDecorators.ts index 2f30004..58d9e65 100644 --- a/src/engine/executionEngineDecorators.ts +++ b/src/engine/executionEngineDecorators.ts @@ -58,10 +58,11 @@ export function engine(options?: { id: string }): ClassDecorator { /** * A method decorator that enables tracing for the decorated method. - * @param options - Trace options for the execution. - * @returns A decorator function. + * + * @param {TraceOptions, O> | TraceOptions, O>['trace']} [options] - Optional tracing options. + * @returns {Function} - A decorator function. */ -export function run(options?: TraceOptions, O>) { +export function run(options?: TraceOptions, O> | TraceOptions, O>['trace']) { return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) { // Store the original method const originalMethod = descriptor.value; diff --git a/src/trace/traceableExecution.spec.ts b/src/trace/traceableExecution.spec.ts index f266668..b7b2b1b 100644 --- a/src/trace/traceableExecution.spec.ts +++ b/src/trace/traceableExecution.spec.ts @@ -298,7 +298,7 @@ describe('TraceableExecution', () => { ]); // Get the ordered narratives and verify their content - const orderedNarratives = traceableExecution.getOrderedNarratives(); + const orderedNarratives = traceableExecution.getNarratives(); expect(orderedNarratives).toEqual([ 'Narrative 0', 'Narrative 0 with Result: InputParam', diff --git a/src/trace/traceableExecution.ts b/src/trace/traceableExecution.ts index 51b2b1f..42bb1e7 100644 --- a/src/trace/traceableExecution.ts +++ b/src/trace/traceableExecution.ts @@ -86,10 +86,17 @@ export class TraceableExecution { } } - initTrace(initialTrace: Trace) { + /** + * Initializes the trace with given initialTrace. + * + * @param {Trace} initialTrace - The initial trace to initialize: the nodes and edges. + * @return {TraceableExecution} - The traceable execution object after initialization. + */ + initTrace(initialTrace: Trace): TraceableExecution { this.nodes = (initialTrace?.filter((b) => b.group === 'nodes') as Array) ?? []; this.edges = (initialTrace?.filter((b) => b.group === 'edges') as Array) ?? []; this.narrativesForNonFoundNodes = {}; + return this; } /** @@ -302,10 +309,11 @@ export class TraceableExecution { } /** - * Gets an ordered array of narratives. - * @returns An array containing ordered narratives. + * Retrieves an ordered array of narratives. + * + * @returns {Array} An array that contains the ordered narratives. If no narratives are found, an empty array is returned. */ - getOrderedNarratives(): Array { + getNarratives(): Array { return this.nodes?.flatMap?.((n) => n.data?.narratives)?.filter((n) => !!n); }