/** * Worker-side LangSmith emission, exposed as a Temporal {@link InjectedSinks}. * * @module */ import type { Client } from 'langsmith'; import { RunTree, type RunTreeConfig, type WriteReplica } from 'langsmith/run_trees'; import type { Logger } from '@temporalio/common'; import type { Sinks } from '@temporalio/workflow'; import type { InjectedSinks } from '@temporalio/worker'; import { type ReplicaRouting } from './routing'; /** Plain-JSON description of a LangSmith run crossing the isolate→worker boundary. */ export interface SerializedRun { id: string; trace_id: string; dotted_order: string; parent_run_id?: string; name: string; run_type: string; start_time: number; /** End time (epoch ms); present only on the update record. */ end_time?: number; inputs?: Record; outputs?: Record; /** Error string; non-null marks the run errored. */ error?: string; extra?: Record; tags?: string[]; project_name?: string; address?: RunTreeConfig['address']; replicas?: ReplicaRouting[]; distributedParentId?: string; events?: Record[]; } /** Runtime configuration shared by the client and activity interceptors. */ export interface EmitterConfig { /** The LangSmith client runs are emitted to. */ client: Client; /** When false, no Temporal-operation runs are emitted (propagation only). */ addTemporalRuns: boolean; /** Target LangSmith project. */ projectName?: string; address?: RunTreeConfig['address']; /** Full replica configuration is local to the client/worker process. */ replicas?: WriteReplica[]; /** Tags attached to every emitted run. */ tags?: string[]; /** Metadata merged into every emitted run. */ metadata?: Record; } /** The injected sink's wire name. Reserved-prefixed; allowlisted in `@temporalio/common`. */ export declare const LANGSMITH_SINK_NAME: "__temporal_langsmith"; /** The Temporal sink surface this plugin injects. */ export interface LangSmithSinks extends Sinks { [LANGSMITH_SINK_NAME]: { /** Emit a `createRun` for a newly started run. */ createRun(run: SerializedRun): void; /** Emit an `updateRun` (end / outputs / error / events) for a run. */ updateRun(run: SerializedRun, options?: Parameters[0]): void; }; } /** * Build the worker-side {@link InjectedSinks} routing serialized runs to a real LangSmith client, and a `drain` that * resolves once every queued write has reached the client. */ export declare function createLangSmithSinks(client: Client, replicas: WriteReplica[] | undefined, logger: Logger): { sinks: InjectedSinks; drain: () => Promise; };