/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 * @generated-id: b6490fc32db0
 */

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { ClosedEnum } from "../../types/enums.js";
import { smartUnion } from "../../types/smartUnion.js";
import {
  CompletionArgs,
  CompletionArgs$Outbound,
  CompletionArgs$outboundSchema,
} from "./completionargs.js";
import {
  ConversationInputs,
  ConversationInputs$Outbound,
  ConversationInputs$outboundSchema,
} from "./conversationinputs.js";
import {
  GuardrailConfig,
  GuardrailConfig$Outbound,
  GuardrailConfig$outboundSchema,
} from "./guardrailconfig.js";

export const ConversationRestartStreamRequestHandoffExecution = {
  Client: "client",
  Server: "server",
} as const;
export type ConversationRestartStreamRequestHandoffExecution = ClosedEnum<
  typeof ConversationRestartStreamRequestHandoffExecution
>;

/**
 * Specific version of the agent to use when restarting. If not provided, uses the current version.
 */
export type ConversationRestartStreamRequestAgentVersion = string | number;

/**
 * Request to restart a new conversation from a given entry in the conversation.
 */
export type ConversationRestartStreamRequest = {
  inputs?: ConversationInputs | undefined;
  stream?: true | undefined;
  /**
   * Whether to store the results into our servers or not.
   */
  store?: boolean | undefined;
  handoffExecution?:
    | ConversationRestartStreamRequestHandoffExecution
    | undefined;
  /**
   * White-listed arguments from the completion API
   */
  completionArgs?: CompletionArgs | undefined;
  guardrails?: Array<GuardrailConfig> | null | undefined;
  /**
   * Custom metadata for the conversation.
   */
  metadata?: { [k: string]: any } | null | undefined;
  fromEntryId: string;
  /**
   * Specific version of the agent to use when restarting. If not provided, uses the current version.
   */
  agentVersion?: string | number | null | undefined;
};

/** @internal */
export const ConversationRestartStreamRequestHandoffExecution$outboundSchema:
  z.ZodEnum<typeof ConversationRestartStreamRequestHandoffExecution> = z.enum(
    ConversationRestartStreamRequestHandoffExecution,
  );

/** @internal */
export type ConversationRestartStreamRequestAgentVersion$Outbound =
  | string
  | number;

/** @internal */
export const ConversationRestartStreamRequestAgentVersion$outboundSchema:
  z.ZodType<
    ConversationRestartStreamRequestAgentVersion$Outbound,
    ConversationRestartStreamRequestAgentVersion
  > = smartUnion([z.string(), z.int()]);

export function conversationRestartStreamRequestAgentVersionToJSON(
  conversationRestartStreamRequestAgentVersion:
    ConversationRestartStreamRequestAgentVersion,
): string {
  return JSON.stringify(
    ConversationRestartStreamRequestAgentVersion$outboundSchema.parse(
      conversationRestartStreamRequestAgentVersion,
    ),
  );
}

/** @internal */
export type ConversationRestartStreamRequest$Outbound = {
  inputs?: ConversationInputs$Outbound | undefined;
  stream: true;
  store: boolean;
  handoff_execution: string;
  completion_args?: CompletionArgs$Outbound | undefined;
  guardrails?: Array<GuardrailConfig$Outbound> | null | undefined;
  metadata?: { [k: string]: any } | null | undefined;
  from_entry_id: string;
  agent_version?: string | number | null | undefined;
};

/** @internal */
export const ConversationRestartStreamRequest$outboundSchema: z.ZodType<
  ConversationRestartStreamRequest$Outbound,
  ConversationRestartStreamRequest
> = z.object({
  inputs: ConversationInputs$outboundSchema.optional(),
  stream: z.literal(true).default(true as const),
  store: z.boolean().default(true),
  handoffExecution:
    ConversationRestartStreamRequestHandoffExecution$outboundSchema.default(
      "server",
    ),
  completionArgs: CompletionArgs$outboundSchema.optional(),
  guardrails: z.nullable(z.array(GuardrailConfig$outboundSchema)).optional(),
  metadata: z.nullable(z.record(z.string(), z.any())).optional(),
  fromEntryId: z.string(),
  agentVersion: z.nullable(smartUnion([z.string(), z.int()])).optional(),
}).transform((v) => {
  return remap$(v, {
    handoffExecution: "handoff_execution",
    completionArgs: "completion_args",
    fromEntryId: "from_entry_id",
    agentVersion: "agent_version",
  });
});

export function conversationRestartStreamRequestToJSON(
  conversationRestartStreamRequest: ConversationRestartStreamRequest,
): string {
  return JSON.stringify(
    ConversationRestartStreamRequest$outboundSchema.parse(
      conversationRestartStreamRequest,
    ),
  );
}
