interface BaseOperation { path: string; } interface AddOperation extends BaseOperation { op: "add"; value: T; } interface RemoveOperation extends BaseOperation { op: "remove"; } interface ReplaceOperation extends BaseOperation { op: "replace"; value: T; } interface MoveOperation extends BaseOperation { op: "move"; from: string; } interface CopyOperation extends BaseOperation { op: "copy"; from: string; } interface TestOperation extends BaseOperation { op: "test"; value: T; } interface GetOperation extends BaseOperation { op: "_get"; value: T; } type JsonPatchOperation = AddOperation | RemoveOperation | ReplaceOperation | MoveOperation | CopyOperation | TestOperation | GetOperation; export type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue; }; export interface StringAppendOperation { op: "string-append"; path: string; value: string; } export type Operation = JsonPatchOperation | StringAppendOperation; export interface StartMessage { type: "start"; workflowExecutionId?: string; workflowName: string; } export interface ComponentStartMessage { type: "component-start"; componentName: string; label?: string; componentId: string; } export interface ComponentEndMessage { type: "component-end"; componentName: string; label?: string; componentId: string; } export interface DataMessage { type: "data"; data: JsonValue; } export interface EventMessage { type: "event"; data: JsonValue; label: string; } export interface ObjectMessage { type: "object"; label: string; patches: Operation[]; isInitial?: boolean; } export interface ErrorMessage { type: "error"; error: string; } export interface EndMessage { type: "end"; } export interface ExternalToolMessage { type: "external-tool"; toolName: string; params: JsonValue; paramsSchema: unknown; resultSchema: unknown; nodeId: string; } export type WorkflowMessage = StartMessage | ComponentStartMessage | ComponentEndMessage | DataMessage | EventMessage | ObjectMessage | ErrorMessage | EndMessage | ExternalToolMessage; export type WorkflowMessageListener = (message: WorkflowMessage) => void; export type PublishableData = any; /** * Publish data to the workflow message stream. This is a low-level utility for putting arbitrary data on the stream. * * @param data - The data to publish. */ export declare function publishData(data: JsonValue): void; /** * Publish an event to the workflow message stream. Labels group events together, and generally all events within the same label should be related with the same type. * * @param label - The label of the event. * @param data - The data to publish. */ export declare function publishEvent(label: string, data: T): void; /** * Publish a state to the workflow message stream. A State represents a snapshot of an object that is updated over time. * This now uses JSON patches to efficiently send only the differences between states. * * @param label - The label of the state. * @param data - The data to publish. Can be any value that can be serialized to JSON . */ export declare function publishObject(label: string, data: T): void; /** * Generate optimized patches that use string-specific operations when beneficial. * Handles any JsonValue at the root, including string-append optimization for root strings. */ export declare function generateOptimizedPatches(oldData: PublishableData, newData: PublishableData): Operation[]; /** * Get a value from an object using a JSON pointer path (RFC 6901 compliant, supports arrays) */ export declare function getValueByJsonPath(obj: JsonValue, path: string): JsonValue | undefined; /** * Create a function that publishes an event to the workflow message stream with the given label. * * @param label - The label of the event. * @returns A function that publishes an event to the workflow message stream. */ export declare function createEventStream(label: string): (data: T) => void; /** * Create a function that publishes a state to the workflow message stream with the given label. * * @param label - The label of the state. * @returns A function that publishes a state to the workflow message stream. */ export declare function createObjectStream(label: string): (data: T) => void; /** * Clear stored state for a given label. This is useful when starting a new workflow execution. * * @param label - The label of the state to clear. */ export declare function clearObjectState(label: string): void; /** * Clear all stored object states. This is useful when starting a new workflow execution. */ export declare function clearAllObjectStates(): void; /** * Apply a JSON patch to reconstruct object state. This is useful for consumers who want to reconstruct the full object state from patches. * * @param patches - The JSON patch operations to apply. * @param currentState - The current state of the object (defaults to empty object). * @returns The new state after applying the patches. */ export declare function applyObjectPatches(patches: Operation[], currentState?: PublishableData): PublishableData; export {}; //# sourceMappingURL=workflow-state.d.ts.map