import * as Stream from "../Stream.ts"; import type * as AgUiSchema from "./AgUiSchema.ts"; import { IdGenerator } from "./IdGenerator.ts"; import * as Prompt from "./Prompt.ts"; import type * as Response from "./Response.ts"; /** * Converts the conversation in an AG-UI run input into a `Prompt`. * * **Details** * * - User and assistant messages keep their text. Assistant tool calls become * tool-call parts with their JSON arguments parsed. * - Each tool message becomes a tool message with one tool-result part, named * after the latest preceding assistant tool call with its id, since * providers may reuse call ids across turns. Content that is valid JSON is * parsed. A message with an `error` becomes a failed result carrying the * error text, and a message carrying the failure metadata that * {@link fromStreamParts} emits becomes a failed result carrying its content. * - User image, audio, video, and document parts with inline data or a valid * URL become file parts. * - Activity and reasoning messages, provider file handles, and tool messages * that answer no preceding tool call are dropped. * * **Gotchas** * * The whole conversation comes from the client. By default `system` and * `developer` messages and the input's `context` are dropped, so a browser * cannot replace the server's instructions. Set `trustClientInstructions` to * keep them: `system` and `developer` messages then become system messages in * place, and `context` becomes a leading system message. * * @stability experimental * @category converting * @since 4.1.0 */ export declare const toPrompt: (input: AgUiSchema.RunAgentInput, options?: { readonly trustClientInstructions?: boolean | undefined; }) => Prompt.Prompt; /** * Converts the parts streamed by `LanguageModel.streamText` into AG-UI events. * * **Details** * * - Each model round becomes a step named `step-1`, `step-2`, and so on. The * round's `finish` part closes the step. * - Text parts become `TEXT_MESSAGE_*` events from the `assistant` role, and * reasoning parts become a reasoning span holding one reasoning message. * - Streamed tool parameters become `TOOL_CALL_START`, `TOOL_CALL_ARGS`, and * `TOOL_CALL_END`. A tool call that arrives without streamed parameters * becomes the same sequence with its parameters as one JSON fragment. Tool * calls name the step's latest text message as their parent. * - Final tool results become `TOOL_CALL_RESULT` events with a fresh message * id from `IdGenerator`. Failed results carry * `{ "effect/ai": { isFailure: true } }` as metadata. * - An `error` part is logged and becomes a `RUN_ERROR` event with a generic * message. * - Preliminary tool results, approval requests, files, sources, and response * metadata are dropped. * * Failures of the input stream are kept. Use {@link withRunLifecycle} to open * and close the run and to report failures to the client. * * @see {@link withRunLifecycle} for wrapping the events in a run * * @stability experimental * @category converting * @since 4.1.0 */ export declare const fromStreamParts: (self: Stream.Stream) => Stream.Stream; /** * Wraps a stream of AG-UI events in the lifecycle of one run. * * **When to use** * * Use with {@link fromStreamParts} or with any hand-written event stream, so * clients always see a well-formed run. * * **Details** * * - `RUN_STARTED` is emitted first, with the run's ids and the protocol * version. `RUN_STARTED` events from the input stream are dropped. * - When the input stream ends, any text message, tool call, reasoning span, * step, or subagent it left open is closed, most recently opened first, and * `RUN_FINISHED` is emitted. Closing events keep the `subagentRunId` of the * event they close, steps are matched by name within each subagent, and a * subagent left running ends with a `SUBAGENT_ERROR`. * - A `RUN_FINISHED` from the input stream ends the run, after closing * anything left open, so a stream can report its own outcome. A `RUN_ERROR` * from the input stream also ends the run. * - When the input stream fails, the cause is logged and reported, and the run * ends with a `RUN_ERROR` whose message carries no error details. * Interruptions are not converted. * * **Gotchas** * * To send a specific error to the client, emit a `RUN_ERROR` event from the * input stream instead of failing it. * * @see {@link fromStreamParts} for producing events from a model response * * @stability experimental * @category combinators * @since 4.1.0 */ export declare const withRunLifecycle: (run: { readonly threadId: string; readonly runId: string; }) => (self: Stream.Stream) => Stream.Stream; //# sourceMappingURL=AgUi.d.ts.map