/** * Replay-safe LangSmith run construction for workflow code, plus the pure * run-name builders shared by every interceptor. * * Inside the workflow isolate LangSmith's default `RunTree` is unsafe on two * counts that the workflow lifecycle overrides fix: * * 1. **Non-deterministic ids.** Its default random-tailed uuid7 would mint a * fresh id on every replay, flooding the backend with duplicates. * 2. **Network I/O on replay.** `postRun` / `patchRun` would re-POST runs on * every history replay. * * Internal: every export here is consumed only by sibling modules in this * package; none is reachable through a package entry point. * * @module * @internal */ import { RunTree, type RunTreeConfig } from 'langsmith/run_trees'; import type { LangSmithTraceContext } from './propagation'; import type { EmitterConfig, SerializedRun } from './sinks'; /** LangSmith run-type constants used for Temporal-operation runs. */ export declare const RUN_TYPE: { /** Workflow / child-workflow / scheduling / handler spans. */ readonly CHAIN: "chain"; /** Activity-body execution spans. */ readonly TOOL: "tool"; }; /** `StartWorkflow:` — client/parent-side workflow-start marker. */ export declare const startWorkflowRunName: (workflowType: string) => string; /** `RunWorkflow:` — the workflow-execution span (inbound). */ export declare const runWorkflowRunName: (workflowType: string) => string; /** `StartActivity:` — workflow-side activity-schedule marker. */ export declare const startActivityRunName: (activityType: string) => string; /** `RunActivity:` — the activity-execution span (activity inbound). */ export declare const runActivityRunName: (activityType: string) => string; /** `StartChildWorkflow:` — workflow-side child-start marker. */ export declare const startChildWorkflowRunName: (workflowType: string) => string; /** `StartNexusOperation:/` — workflow-side Nexus-start marker. */ export declare const startNexusOperationRunName: (service: string, operation: string) => string; /** `RunStartNexusOperationHandler:/` — Nexus start-handler span. */ export declare const runStartNexusHandlerRunName: (service: string, operation: string) => string; /** `RunCancelNexusOperationHandler:/` — Nexus cancel-handler span. */ export declare const runCancelNexusHandlerRunName: (service: string, operation: string) => string; /** `HandleSignal:` — inbound signal handler span. */ export declare const handleSignalRunName: (signalName: string) => string; /** `HandleQuery:` — inbound query handler span. */ export declare const handleQueryRunName: (queryName: string) => string; /** `HandleUpdate:` — inbound update handler span. */ export declare const handleUpdateRunName: (updateName: string) => string; /** `ValidateUpdate:` — inbound update validator span. */ export declare const validateUpdateRunName: (updateName: string) => string; /** `SignalWorkflow:` — client/outbound signal marker. */ export declare const signalWorkflowRunName: (signalName: string) => string; /** `SignalChildWorkflow:` — workflow-side signal-child marker. */ export declare const signalChildWorkflowRunName: (signalName: string) => string; /** `SignalExternalWorkflow:` — workflow-side signal-external marker. */ export declare const signalExternalWorkflowRunName: (signalName: string) => string; /** `SignalWithStartWorkflow:` — client signal-with-start marker. */ export declare const signalWithStartRunName: (workflowType: string) => string; /** `QueryWorkflow:` — client query marker. */ export declare const queryWorkflowRunName: (queryName: string) => string; /** `StartWorkflowUpdate:` — client update-start marker. */ export declare const startWorkflowUpdateRunName: (updateName: string) => string; /** `StartUpdateWithStartWorkflow:` — client update-with-start marker. */ export declare const startUpdateWithStartRunName: (workflowType: string) => string; type RunTreeMember = (this: any, ...args: any[]) => any; /** RunTree members to replace, each mapped to a function that builds the replacement from LangSmith's original. */ export interface RunTreeOverrides { statics: Record RunTreeMember>; methods: Record RunTreeMember>; } /** * Throw, naming each one, unless every member the overrides replace is a function. The Workflow bundle may carry a * different LangSmith copy than the Worker, so both check. */ export declare function requireRunTreeMembers(...overrides: RunTreeOverrides[]): void; /** Replace the overridden RunTree members, or none if any is missing. */ export declare function patchRunTree(overrides: RunTreeOverrides): void; /** Flatten a {@link RunTree} into the plain wire shape consumed by the Sink. */ export declare function serializeRun(run: RunTree): SerializedRun; /** * Render an error into the LangSmith `error` string, honoring Temporal's * benign-failure category. * * A `BENIGN`-category `ApplicationFailure` is an expected, non-alarming outcome * (e.g. a control-flow signal), so it leaves the run's `error` unset. All other * failures produce `": "`. */ export declare function describeError(err: unknown): string | undefined; /** Outputs of a plugin run that ends without an error. Plugin runs never record Temporal arguments or results. */ export declare function statusOutputs(status: 'ok' | 'cancelled' | 'continued_as_new'): Record; /** The `RunTree.end` arguments that close a plugin run. */ export type RunEnd = [outputs: Record | undefined, error: string | undefined]; /** The `RunTree.end` arguments for a plugin run whose operation threw `err`; cancellation isn't an error. */ export declare function thrownEnd(err: unknown): RunEnd; /** Run `fn`, then end and patch the already-posted `run` with an ok status, or with `endThrown` of what `fn` threw. */ export declare function wrapWithRun(run: RunTree, fn: () => Promise, endThrown?: (err: unknown) => RunEnd): Promise; export declare function isUntraced(run: RunTree): boolean; export declare function suppressRun(run: RunTree): void; /** * The trace context to propagate for `run`, or `undefined` when no LangSmith run exists to parent under: no run, a * run with no destination, or a run LangSmith won't trace (`tracingEnabled: false`). LangSmith turns tracing off for * a run built in an env it can't use, such as a client marker. */ export declare function runHeaders(run: RunTree | undefined): LangSmithTraceContext | undefined; /** * A run's destination: a LangSmith project, or an agent address (LangSmith's `RunTreeConfig.address`, in the * installed version's own form). */ export type Destination = Pick; /** * Reconstruct a propagated parent {@link RunTree} from a trace context; never throws. LangSmith's `RunTree.fromHeaders` * lets the context's destination outrank `fallback`, so `fallback` applies only when the context names none. */ export declare function runTreeFromContext(ctx: LangSmithTraceContext | undefined, fallback?: Destination): RunTree | undefined; interface RunTreeParams { name: string; runType: string; parent: RunTree | undefined; /** Merged over the plugin's metadata. */ metadata?: Record; } /** * Build an emitter-side {@link RunTree} (client / activity / Nexus); force-enables * tracing so nested body `traceable` runs emit — tracing gate is `isTracingEnabled()`. */ export declare function buildRunTree(config: EmitterConfig, params: RunTreeParams): RunTree; export {};