/// import { AsyncLocalStorage } from 'node:async_hooks'; import opentelemetry, { AttributeValue, Span, SpanOptions } from '@opentelemetry/api'; import { type ChronicleEvent } from './events.js'; import { ChronicleClient } from './client.js'; import { ChronicleRequestMetadata } from './types.js'; export declare const tracer: opentelemetry.Tracer; export interface StepOptions { /** The name of this step */ name: string; /** The type of this step, such as 'dag:node', 'model query', or similar */ type: string; tags?: string[]; info?: object; /** Record this as the input for the step. */ input?: unknown; /** Options for the OpenTelemetry span that will wrap this step. */ spanOptions?: SpanOptions; /** Override the parent OpenTelemetry span */ parentSpan?: opentelemetry.Context; /** Use this context as the parent for the step. This can be useful if the step's execution was delayed in * some way that makes it difficult to link to the parent run context, such as when running the step in a DAG, * based on some EventEmitter. */ parentRunContext?: RunContext; /** Use this Chronicle client instance for this step. */ chronicle?: ChronicleClient; /** Create a child Chronicle client with these metadata values. */ metadata?: ChronicleRequestMetadata; } /** Run a step of a workflow. This both adds a tracing span and starts a new step in the * workflow's event tracking. */ export declare function runStep(options: StepOptions, f: (ctx: RunContext, span: Span) => Promise): Promise; /** Run a function in a span, and record errors if they occur */ export declare function runInSpanWithParent(spanName: string, options: SpanOptions, parent: opentelemetry.Context | undefined, f: (span: Span) => Promise): Promise; /** Run a function in a span, and record errors if they occur */ export declare function runInSpan(spanName: string, options: SpanOptions, f: (span: Span) => Promise): Promise; export declare function addSpanEvent(span: Span, e: ChronicleEvent): void; export declare function toSpanAttributeValue(v: AttributeValue | object): AttributeValue; export declare function objectToSpanAttributeValues(o: object | null | undefined, prefix?: string): Record | undefined; export declare const asyncEventStorage: AsyncLocalStorage; export interface RunContext { /** The ID of this run */ runId: string; /** The ID of the current step */ stepId: string | undefined; /** The Chronicle client, which can be used for logging events and making LLM requests */ chronicle: ChronicleClient; /** Record additional information about the step that is only known after starting it. * Each call to `recordStepInfo will merge the argument with the arguments to previous calls.`*/ recordStepInfo: (o: object) => void; /** Retrieve any information recorded by `recordStepInfo` */ getRecordedStepInfo: () => object | undefined; /** Record additional information about the run that is only known after starting it. * Each call to `recordStepInfo will merge the argument with the arguments to previous calls.`*/ recordRunInfo: (o: object) => void; /** Record any information recorded by `recordRunInfo`. */ getRecordedRunInfo: () => object | undefined; /** Set the final status for the run to something other than the default of 'finished'. * This does not update the status right away; rather it customizes the status passed * to the `run:update` event after the run's function finishes. * * If you want to update the status of a run while it is running, you can send * your own `run:update` event to `chronicle.event()`. * */ setRunFinishStatus: (status: string) => void; } export declare function getEventContext(): RunContext | undefined; /** Options for starting a new run. Many of these options are designed for use when * restarting a previous run, as when a state machine was dormant and has received an * event. */ export interface RunOptions { /** Restore context with this existing run ID */ runId?: string; /** A Chronicle client. If omitted, the default client will be used */ chronicle?: ChronicleClient; /** Create a child Chronicle client with these metadata values. */ metadata?: ChronicleRequestMetadata; /** A name for this run */ name?: string; /** Description for this run */ description?: string; /** Tags for this run */ tags?: string[]; /** Input for this run. */ input?: unknown; /** Additional information about this run. */ info?: object; /** Customize the initial status of the run. The default value is 'started'. */ status?: string; /** The application name linked to the run. If ommited, the value from the Chronicle client * can be used instead. */ application?: string; /** The environment name linked to the run. If ommited, the value from the Chronicle client * can be used instead. */ environment?: string; /** Force the span for this run to have this parent. */ parentSpanContext?: opentelemetry.Context; } /** Run a workflow and initialize an event context, if one does not already exist. */ export declare function startRun(options: RunOptions, fn: (ctx: RunContext) => Promise): Promise<{ id: string; output: T; info: object | undefined; }>; export interface AsStepOptions { name?: string; type: string; tags?: string[]; info?: object; } /** Wrap a function so that it runs as a step. * * export const doIt = asStep(async doIt(input) => { * await callModel(input) * }) * */ export declare function asStep

(fn: (...args: P) => Promise, options?: AsStepOptions): (...args: P) => Promise; /** Explicitly provide an existing `RunContext`, for cases where the function is not causally linked to the run closely * enough for it to be retrieved through the normal AsyncLocalStorage mechanism. */ export declare function runWithContext(ctx: RunContext, fn: () => T): T; /** Record additional information about a step that is only known after starting it. * This data will be shallowly merged with existing step information. */ export declare function recordStepInfo(info: object): void; /** Record additional information about a run that is only known after starting it. * This data will be shallowly merged with existing run information. */ export declare function recordRunInfo(info: object): void; /** Set the status that will be written to the run when it finishes. */ export declare function setRunFinishStatus(state: string): void; /** Get the current Chronicle client from the event context, or the global client. */ export declare function chronicleClient(): ChronicleClient; //# sourceMappingURL=runs.d.ts.map