import {
  _ as LifecycleJobContext,
  s as LifecycleCapability,
  v as LifecycleJobOutcome
} from "../../capability-runner-BiVUtjqC.js";
import {
  o as ChannelMessage,
  p as DeliveryResult
} from "../../channel-Bak_6zDP.js";
import {
  _ as TranscriptMessage,
  b as ChannelMessageSurface,
  c as InboundEvent,
  m as ResponseChunk
} from "../../protocol-CukuI73M.js";
import {
  a as HarnessSessions,
  d as SessionId,
  i as HarnessSession,
  t as AgentHarness
} from "../../harness-B6B9S3rb.js";
import { t as ChannelGateway } from "../../gateway-BFO6vRDn.js";
import {
  LanguageModel,
  StopCondition,
  Tool,
  ToolSet,
  UIMessage,
  UIMessageChunk
} from "ai";

//#region src/harness/ai-sdk/harness.d.ts
type AiSdkHarnessOptions<TOOLS extends ToolSet> = {
  model: LanguageModel;
  /**
   * Tools without `execute` run on the client of the participant whose
   * message started the turn; tools with `needsApproval` wait for an
   * approval from anyone.
   */
  tools?: TOOLS;
  system?: string /** Default: `stepCountIs(5)`. */;
  stopWhen?: StopCondition<
    NoInfer<TOOLS>
  > /** How often a running session's wake job checks in. Default: 30 s. */;
  heartbeatMs?: number;
};
/**
 * An agent harness around the AI SDK's `streamText`, hosted in a Durable
 * Object: sessions, their transcripts, and a queue of operations, all in the
 * object's storage. One operation runs at a time per session; a run is one
 * `streamText` call over the session's transcript.
 *
 * The AI SDK keeps no state of its own, so a run that an eviction cuts short
 * starts again from the saved transcript, and its unsaved output is lost.
 * Steering is not supported: `whenBusy: "steer"` queues like a follow-up.
 *
 * @experimental The API may change between releases.
 */
declare class AiSdkHarness<TOOLS extends ToolSet = ToolSet>
  extends LifecycleCapability
  implements AgentHarness
{
  #private;
  readonly sessions: HarnessSessions;
  constructor(options: AiSdkHarnessOptions<TOOLS>);
  onStart(): Promise<void>;
  onJob(context: LifecycleJobContext): Promise<LifecycleJobOutcome | void>;
  session(id?: SessionId): HarnessSession;
}
//#endregion
//#region src/harness/ai-sdk/send-message-tool.d.ts
type SendMessageTool = Tool<ChannelMessage, DeliveryResult>;
/** Model-facing options controlled by the caller creating the tool. */
type CreateSendMessageToolOptions = Pick<
  SendMessageTool,
  | "description"
  | "inputExamples"
  | "metadata"
  | "needsApproval"
  | "providerOptions"
  | "strict"
>;
/**
 * Adapt one Host-resolved surface to an AI SDK tool.
 *
 * The caller chooses the key used in its ToolSet and owns model-facing policy
 * such as the description, examples, metadata, and approval requirement.
 */
declare function createSendMessageTool(
  gateway: ChannelGateway,
  surface: ChannelMessageSurface,
  options?: CreateSendMessageToolOptions
): Tool<ChannelMessage, DeliveryResult>;
//#endregion
//#region src/harness/ai-sdk/turns.d.ts
type AiSdkConversionOptions = {
  /** The agent's tools. Those without `execute` run on a client. */ tools?: ToolSet /** Id of the participant whose client runs this message's client tools. */;
  owner?: string;
};
/**
 * Convert an AI SDK UI message stream into response chunks.
 *
 * An `error` or `abort` chunk makes the iteration throw once the stream
 * ends, so a failed or aborted generation never reads as a finished one, while the stream still
 * runs to its end and its `onEnd` sees the partial message.
 */
declare function toResponseChunks(
  stream: AsyncIterable<UIMessageChunk>,
  options?: AiSdkConversionOptions
): AsyncGenerator<ResponseChunk>;
/** Convert one AI SDK UI message chunk into a response chunk, if it has one. */
declare function toResponseChunk(
  chunk: UIMessageChunk,
  options: AiSdkConversionOptions
): ResponseChunk | undefined;
/**
 * Convert a response chunk into an AI SDK UI message chunk. Fields that only
 * Channels has, such as a tool call's `owner`, are dropped.
 */
declare function toUIMessageChunk(chunk: ResponseChunk): UIMessageChunk;
/** Convert a saved AI SDK UI message into a transcript message. */
declare function toTranscriptMessage(
  message: UIMessage,
  options?: AiSdkConversionOptions
): TranscriptMessage;
/** Convert a transcript message into an AI SDK UI message. */
declare function toUIMessage(message: TranscriptMessage): UIMessage;
/** Whether the message has a tool call waiting for a result or an approval. */
declare function awaitsInput(message: UIMessage): boolean;
/** A tool result or approval response, as an inbound event carries it. */
type ToolCallAnswer =
  | Pick<
      Extract<
        InboundEvent,
        {
          type: "tool-result";
        }
      >,
      "type" | "toolCallId" | "result"
    >
  | Pick<
      Extract<
        InboundEvent,
        {
          type: "approval-response";
        }
      >,
      "type" | "approvalId" | "approved" | "reason"
    >;
/**
 * Record a tool result or approval response on the tool call it answers.
 * Returns the updated message, or undefined when no call is waiting for it,
 * so the first answer wins.
 */
declare function answerToolCall(
  messages: readonly UIMessage[],
  event: ToolCallAnswer
): UIMessage | undefined;
//#endregion
export {
  AiSdkConversionOptions,
  AiSdkHarness,
  type AiSdkHarnessOptions,
  type CreateSendMessageToolOptions,
  ToolCallAnswer,
  answerToolCall,
  awaitsInput,
  createSendMessageTool,
  toResponseChunk,
  toResponseChunks,
  toTranscriptMessage,
  toUIMessage,
  toUIMessageChunk
};
//# sourceMappingURL=index.d.ts.map
