import { ActivityDeltaEvent, ActivityMessage, ActivitySnapshotEvent, BaseEvent, CustomEvent, Message, MessagesSnapshotEvent, RawEvent, ReasoningEncryptedValueEvent, ReasoningEndEvent, ReasoningMessageContentEvent, ReasoningMessageEndEvent, ReasoningMessageStartEvent, ReasoningStartEvent, RunAgentInput, RunErrorEvent, RunFinishedEvent, RunStartedEvent, State, StateDeltaEvent, StateSnapshotEvent, StepFinishedEvent, StepStartedEvent, TextMessageContentEvent, TextMessageEndEvent, TextMessageStartEvent, ToolCall, ToolCallArgsEvent, ToolCallEndEvent, ToolCallResultEvent, ToolCallStartEvent } from "@ag-ui/core"; import { Observable } from "rxjs"; import { z } from "zod"; export * from "@ag-ui/core"; //#region src/agent/types.d.ts interface AgentConfig { agentId?: string; description?: string; threadId?: string; initialMessages?: Message[]; initialState?: State; debug?: boolean; } interface HttpAgentConfig extends AgentConfig { url: string; headers?: Record; } type RunAgentParameters = Partial>; //#endregion //#region src/legacy/types.d.ts declare const LegacyRuntimeProtocolEvent: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{ type: z.ZodLiteral<"TextMessageStart">; messageId: z.ZodString; parentMessageId: z.ZodOptional; role: z.ZodOptional; }, "strip", z.ZodTypeAny, { type: "TextMessageStart"; messageId: string; parentMessageId?: string | undefined; role?: string | undefined; }, { type: "TextMessageStart"; messageId: string; parentMessageId?: string | undefined; role?: string | undefined; }>, z.ZodObject<{ type: z.ZodLiteral<"TextMessageContent">; messageId: z.ZodString; content: z.ZodString; }, "strip", z.ZodTypeAny, { type: "TextMessageContent"; messageId: string; content: string; }, { type: "TextMessageContent"; messageId: string; content: string; }>, z.ZodObject<{ type: z.ZodLiteral<"TextMessageEnd">; messageId: z.ZodString; }, "strip", z.ZodTypeAny, { type: "TextMessageEnd"; messageId: string; }, { type: "TextMessageEnd"; messageId: string; }>, z.ZodObject<{ type: z.ZodLiteral<"ActionExecutionStart">; actionExecutionId: z.ZodString; actionName: z.ZodString; parentMessageId: z.ZodOptional; }, "strip", z.ZodTypeAny, { type: "ActionExecutionStart"; actionExecutionId: string; actionName: string; parentMessageId?: string | undefined; }, { type: "ActionExecutionStart"; actionExecutionId: string; actionName: string; parentMessageId?: string | undefined; }>, z.ZodObject<{ type: z.ZodLiteral<"ActionExecutionArgs">; actionExecutionId: z.ZodString; args: z.ZodString; }, "strip", z.ZodTypeAny, { type: "ActionExecutionArgs"; actionExecutionId: string; args: string; }, { type: "ActionExecutionArgs"; actionExecutionId: string; args: string; }>, z.ZodObject<{ type: z.ZodLiteral<"ActionExecutionEnd">; actionExecutionId: z.ZodString; }, "strip", z.ZodTypeAny, { type: "ActionExecutionEnd"; actionExecutionId: string; }, { type: "ActionExecutionEnd"; actionExecutionId: string; }>, z.ZodObject<{ type: z.ZodLiteral<"ActionExecutionResult">; actionName: z.ZodString; actionExecutionId: z.ZodString; result: z.ZodString; }, "strip", z.ZodTypeAny, { type: "ActionExecutionResult"; actionExecutionId: string; actionName: string; result: string; }, { type: "ActionExecutionResult"; actionExecutionId: string; actionName: string; result: string; }>, z.ZodObject<{ type: z.ZodLiteral<"AgentStateMessage">; threadId: z.ZodString; agentName: z.ZodString; nodeName: z.ZodString; runId: z.ZodString; active: z.ZodBoolean; role: z.ZodString; state: z.ZodString; running: z.ZodBoolean; }, "strip", z.ZodTypeAny, { type: "AgentStateMessage"; role: string; threadId: string; agentName: string; nodeName: string; runId: string; active: boolean; state: string; running: boolean; }, { type: "AgentStateMessage"; role: string; threadId: string; agentName: string; nodeName: string; runId: string; active: boolean; state: string; running: boolean; }>, z.ZodObject<{ type: z.ZodLiteral<"MetaEvent">; name: z.ZodEnum<["LangGraphInterruptEvent", "PredictState", "Exit"]>; value: z.ZodAny; }, "strip", z.ZodTypeAny, { type: "MetaEvent"; name: "LangGraphInterruptEvent" | "PredictState" | "Exit"; value?: any; }, { type: "MetaEvent"; name: "LangGraphInterruptEvent" | "PredictState" | "Exit"; value?: any; }>, z.ZodObject<{ type: z.ZodLiteral<"RunError">; message: z.ZodString; code: z.ZodOptional; }, "strip", z.ZodTypeAny, { type: "RunError"; message: string; code?: string | undefined; }, { type: "RunError"; message: string; code?: string | undefined; }>]>; type LegacyRuntimeProtocolEvent = z.infer; //#endregion //#region src/agent/subscriber.d.ts interface AgentStateMutation { messages?: Message[]; state?: State; stopPropagation?: boolean; } interface AgentSubscriberParams { messages: Message[]; state: State; agent: AbstractAgent; input: RunAgentInput; } type MaybePromise = T | Promise; interface AgentSubscriber { onRunInitialized?(params: AgentSubscriberParams): MaybePromise | void>; onRunFailed?(params: { error: Error; } & AgentSubscriberParams): MaybePromise | void>; onRunFinalized?(params: AgentSubscriberParams): MaybePromise | void>; onEvent?(params: { event: BaseEvent; } & AgentSubscriberParams): MaybePromise; onRunStartedEvent?(params: { event: RunStartedEvent; } & AgentSubscriberParams): MaybePromise; onRunFinishedEvent?(params: { event: RunFinishedEvent; result?: any; } & AgentSubscriberParams): MaybePromise; onRunErrorEvent?(params: { event: RunErrorEvent; } & AgentSubscriberParams): MaybePromise; onStepStartedEvent?(params: { event: StepStartedEvent; } & AgentSubscriberParams): MaybePromise; onStepFinishedEvent?(params: { event: StepFinishedEvent; } & AgentSubscriberParams): MaybePromise; onTextMessageStartEvent?(params: { event: TextMessageStartEvent; } & AgentSubscriberParams): MaybePromise; onTextMessageContentEvent?(params: { event: TextMessageContentEvent; textMessageBuffer: string; } & AgentSubscriberParams): MaybePromise; onTextMessageEndEvent?(params: { event: TextMessageEndEvent; textMessageBuffer: string; } & AgentSubscriberParams): MaybePromise; onToolCallStartEvent?(params: { event: ToolCallStartEvent; } & AgentSubscriberParams): MaybePromise; onToolCallArgsEvent?(params: { event: ToolCallArgsEvent; toolCallBuffer: string; toolCallName: string; partialToolCallArgs: Record; } & AgentSubscriberParams): MaybePromise; onToolCallEndEvent?(params: { event: ToolCallEndEvent; toolCallName: string; toolCallArgs: Record; } & AgentSubscriberParams): MaybePromise; onToolCallResultEvent?(params: { event: ToolCallResultEvent; } & AgentSubscriberParams): MaybePromise; onStateSnapshotEvent?(params: { event: StateSnapshotEvent; } & AgentSubscriberParams): MaybePromise; onStateDeltaEvent?(params: { event: StateDeltaEvent; } & AgentSubscriberParams): MaybePromise; onMessagesSnapshotEvent?(params: { event: MessagesSnapshotEvent; } & AgentSubscriberParams): MaybePromise; onActivitySnapshotEvent?(params: { event: ActivitySnapshotEvent; activityMessage?: ActivityMessage; existingMessage?: Message; } & AgentSubscriberParams): MaybePromise; onActivityDeltaEvent?(params: { event: ActivityDeltaEvent; activityMessage?: ActivityMessage; } & AgentSubscriberParams): MaybePromise; onRawEvent?(params: { event: RawEvent; } & AgentSubscriberParams): MaybePromise; onCustomEvent?(params: { event: CustomEvent; } & AgentSubscriberParams): MaybePromise; onReasoningStartEvent?(params: { event: ReasoningStartEvent; } & AgentSubscriberParams): MaybePromise; onReasoningMessageStartEvent?(params: { event: ReasoningMessageStartEvent; } & AgentSubscriberParams): MaybePromise; onReasoningMessageContentEvent?(params: { event: ReasoningMessageContentEvent; reasoningMessageBuffer: string; } & AgentSubscriberParams): MaybePromise; onReasoningMessageEndEvent?(params: { event: ReasoningMessageEndEvent; reasoningMessageBuffer: string; } & AgentSubscriberParams): MaybePromise; onReasoningEndEvent?(params: { event: ReasoningEndEvent; } & AgentSubscriberParams): MaybePromise; onReasoningEncryptedValueEvent?(params: { event: ReasoningEncryptedValueEvent; } & AgentSubscriberParams): MaybePromise; onMessagesChanged?(params: Omit & { input?: RunAgentInput; }): MaybePromise; onStateChanged?(params: Omit & { input?: RunAgentInput; }): MaybePromise; onNewMessage?(params: { message: Message; } & Omit & { input?: RunAgentInput; }): MaybePromise; onNewToolCall?(params: { toolCall: ToolCall; } & Omit & { input?: RunAgentInput; }): MaybePromise; } //#endregion //#region src/agent/http.d.ts interface RunHttpAgentConfig extends RunAgentParameters { abortController?: AbortController; } declare class HttpAgent extends AbstractAgent { url: string; headers: Record; abortController: AbortController; /** * Returns the fetch config for the http request. * Override this to customize the request. * * @returns The fetch config for the http request. */ protected requestInit(input: RunAgentInput): RequestInit; runAgent(parameters?: RunHttpAgentConfig, subscriber?: AgentSubscriber): Promise; abortRun(): void; constructor(config: HttpAgentConfig); run(input: RunAgentInput): Observable; clone(): HttpAgent; } //#endregion //#region src/middleware/middleware.d.ts type MiddlewareFunction = (input: RunAgentInput, next: AbstractAgent) => Observable; interface EventWithState { event: BaseEvent; messages: Message[]; state: any; } declare abstract class Middleware { abstract run(input: RunAgentInput, next: AbstractAgent): Observable; /** * Runs the next agent in the chain with automatic chunk transformation. */ protected runNext(input: RunAgentInput, next: AbstractAgent): Observable; /** * Runs the next agent and tracks state, providing current messages and state with each event. * The messages and state represent the state AFTER the event has been applied. */ protected runNextWithState(input: RunAgentInput, next: AbstractAgent): Observable; } declare class FunctionMiddleware extends Middleware { private fn; constructor(fn: MiddlewareFunction); run(input: RunAgentInput, next: AbstractAgent): Observable; } //#endregion //#region src/middleware/filter-tool-calls.d.ts type FilterToolCallsConfig = { allowedToolCalls: string[]; disallowedToolCalls?: never; } | { disallowedToolCalls: string[]; allowedToolCalls?: never; }; declare class FilterToolCallsMiddleware extends Middleware { private blockedToolCallIds; private readonly allowedTools?; private readonly disallowedTools?; constructor(config: FilterToolCallsConfig); run(input: RunAgentInput, next: AbstractAgent): Observable; private shouldFilterTool; } //#endregion //#region src/middleware/backward-compatibility-0-0-39.d.ts /** * Middleware placeholder that maintains compatibility with AG-UI 0.0.39 flows. * Currently it simply forwards all events to the next middleware/agent. */ declare class BackwardCompatibility_0_0_39 extends Middleware { run(input: RunAgentInput, next: AbstractAgent): Observable; } //#endregion //#region src/middleware/backward-compatibility-0-0-45.d.ts /** * Middleware that maps deprecated THINKING events to the new REASONING events. * * This ensures backward compatibility for agents that still emit legacy THINKING * events (THINKING_START, THINKING_END, THINKING_TEXT_MESSAGE_START, etc.) * by transforming them into the corresponding REASONING events. * * Event mapping: * - THINKING_START → REASONING_START * - THINKING_TEXT_MESSAGE_START → REASONING_MESSAGE_START * - THINKING_TEXT_MESSAGE_CONTENT → REASONING_MESSAGE_CONTENT * - THINKING_TEXT_MESSAGE_END → REASONING_MESSAGE_END * - THINKING_END → REASONING_END * */ declare class BackwardCompatibility_0_0_45 extends Middleware { private currentReasoningId; private currentMessageId; private warnAboutTransformation; run(input: RunAgentInput, next: AbstractAgent): Observable; private transformEvent; } //#endregion //#region src/agent/agent.d.ts interface RunAgentResult { result: any; newMessages: Message[]; } declare abstract class AbstractAgent { agentId?: string; description: string; threadId: string; messages: Message[]; state: State; debug: boolean; subscribers: AgentSubscriber[]; isRunning: boolean; private middlewares; private activeRunDetach$?; private activeRunCompletionPromise?; get maxVersion(): string; constructor({ agentId, description, threadId, initialMessages, initialState, debug }?: AgentConfig); subscribe(subscriber: AgentSubscriber): { unsubscribe: () => void; }; abstract run(input: RunAgentInput): Observable; use(...middlewares: (Middleware | MiddlewareFunction)[]): this; runAgent(parameters?: RunAgentParameters, subscriber?: AgentSubscriber): Promise; protected connect(input: RunAgentInput): Observable; connectAgent(parameters?: RunAgentParameters, subscriber?: AgentSubscriber): Promise; abortRun(): void; detachActiveRun(): Promise; protected apply(input: RunAgentInput, events$: Observable, subscribers: AgentSubscriber[]): Observable; protected processApplyEvents(input: RunAgentInput, events$: Observable, subscribers: AgentSubscriber[]): Observable; protected prepareRunAgentInput(parameters?: RunAgentParameters): RunAgentInput; protected onInitialize(input: RunAgentInput, subscribers: AgentSubscriber[]): Promise; protected onError(input: RunAgentInput, error: Error, subscribers: AgentSubscriber[]): Observable; protected onFinalize(input: RunAgentInput, subscribers: AgentSubscriber[]): Promise; clone(): any; addMessage(message: Message): void; addMessages(messages: Message[]): void; setMessages(messages: Message[]): void; setState(state: State): void; legacy_to_be_removed_runAgentBridged(config?: RunAgentParameters): Observable; } //#endregion //#region src/apply/default.d.ts declare const defaultApplyEvents: (input: RunAgentInput, events$: Observable, agent: AbstractAgent, subscribers: AgentSubscriber[]) => Observable; //#endregion //#region src/verify/verify.d.ts declare const verifyEvents: (debug: boolean) => (source$: Observable) => Observable; //#endregion //#region src/run/http-request.d.ts declare enum HttpEventType { HEADERS = "headers", DATA = "data" } interface HttpDataEvent { type: HttpEventType.DATA; data?: Uint8Array; } interface HttpHeadersEvent { type: HttpEventType.HEADERS; status: number; headers: Headers; } type HttpEvent = HttpDataEvent | HttpHeadersEvent; declare const runHttpRequest: (url: string, requestInit: RequestInit) => Observable; //#endregion //#region src/transform/http.d.ts /** * Transforms HTTP events into BaseEvents using the appropriate format parser based on content type. */ declare const transformHttpEventStream: (source$: Observable) => Observable; //#endregion //#region src/transform/sse.d.ts /** * Parses a stream of HTTP events into a stream of JSON objects using Server-Sent Events (SSE) format. * Strictly follows the SSE standard where: * - Events are separated by double newlines ('\n\n') * - Only 'data:' prefixed lines are processed * - Multi-line data events are supported and joined * - Non-data fields (event, id, retry) are ignored */ declare const parseSSEStream: (source$: Observable) => Observable; //#endregion //#region src/transform/proto.d.ts /** * Parses a stream of HTTP events into a stream of BaseEvent objects using Protocol Buffer format. * Each message is prefixed with a 4-byte length header (uint32 in big-endian format) * followed by the protocol buffer encoded message. */ declare const parseProtoStream: (source$: Observable) => Observable; //#endregion //#region src/legacy/convert.d.ts declare const convertToLegacyEvents: (threadId: string, runId: string, agentName: string) => (events$: Observable) => Observable; //#endregion //#region src/utils.d.ts declare const structuredClone_: (obj: T) => T; /** * Generate a random UUID v4 * Cross-platform compatible (Node.js, browsers, React Native) */ declare function randomUUID(): string; //#endregion //#region src/compact/compact.d.ts /** * Compacts streaming events by consolidating multiple deltas into single events. * For text messages: multiple content deltas become one concatenated delta. * For tool calls: multiple args deltas become one concatenated delta. * Events between related streaming events are reordered to keep streaming events together. * * @param events - Array of events to compact * @returns Compacted array of events */ declare function compactEvents(events: BaseEvent[]): BaseEvent[]; //#endregion //#region src/chunks/transform.d.ts declare const transformChunks: (debug: boolean) => (events$: Observable) => Observable; //#endregion export { AbstractAgent, type AgentConfig, type AgentStateMutation, type AgentSubscriber, type AgentSubscriberParams, BackwardCompatibility_0_0_39, BackwardCompatibility_0_0_45, FilterToolCallsMiddleware, FunctionMiddleware, HttpAgent, type HttpAgentConfig, Middleware, type MiddlewareFunction, type RunAgentParameters, type RunAgentResult, compactEvents, convertToLegacyEvents, defaultApplyEvents, parseProtoStream, parseSSEStream, randomUUID, runHttpRequest, structuredClone_, transformChunks, transformHttpEventStream, verifyEvents }; //# sourceMappingURL=index.d.mts.map