import type { Message } from '@bufbuild/protobuf'; import type { GenMessage } from '@bufbuild/protobuf/codegenv2'; import type { ReportRequest, ReportRequestJson } from '../generated/sdk/v1alpha/sdk_pb'; import type { Report } from './report'; import type { ConsensusAggregation, PrimitiveTypes, UnwrapOptions } from './utils'; import type { SecretsProvider } from '.'; export type { ReportRequest, ReportRequestJson }; export type CallCapabilityParams = { capabilityId: string; method: string; payload: I; inputSchema: GenMessage; outputSchema: GenMessage; }; /** * Base runtime available in both DON and Node execution modes. * Provides core functionality for calling capabilities and logging. */ export interface BaseRuntime { config: C; callCapability(params: CallCapabilityParams): { result: () => O; }; now(): Date; log(message: string): void; } /** * Runtime for Node mode execution. */ export interface NodeRuntime extends BaseRuntime { readonly _isNodeRuntime: true; } /** * Runtime for DON mode execution. */ export interface Runtime extends BaseRuntime, SecretsProvider { /** * Executes a function in Node mode and aggregates results via consensus. * * @param fn - Function to execute in each node (receives NodeRuntime) * @param consensusAggregation - How to aggregate results across nodes * @param unwrapOptions - Optional unwrapping config for complex return types * @returns Wrapped function that returns aggregated result */ runInNodeMode(fn: (nodeRuntime: NodeRuntime, ...args: TArgs) => TOutput, consensusAggregation: ConsensusAggregation, unwrapOptions?: TOutput extends PrimitiveTypes ? never : UnwrapOptions): (...args: TArgs) => { result: () => TOutput; }; report(input: ReportRequest | ReportRequestJson): { result: () => Report; }; }