Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

106 KB
Raw Blame
/**
 * Generated by orval v7.21.0 🍺
 * Do not edit manually.
 * agent_harness_service
 * OpenAPI spec version: 0.1.0
 */
import type {
  AgentActivityPage,
  AgentConversationsDto,
  AgentModeChoiceRequest,
  AgentModeChoiceResponse,
  AgentRepositoriesResponse,
  AgentRepositoryBranchesResponse,
  AgentSessionChangesPatchResponse,
  AgentSessionChangesResponse,
  AgentSessionFoldedLogResponse,
  AgentSessionLogResponse,
  AgentSessionQueueResponse,
  AgentSessionResponse,
  AiAdmissionErrorBody,
  AnswerToolApprovalRequest,
  AnswerToolApprovalResponse,
  AppConnectedRequest,
  AutoArchiveOverridesBody,
  AutoArchivePreferencesBody,
  CallConnectedTool,
  ClassifyInputRequest,
  ClassifyInputResponse,
  CodingPreferencesBody,
  ConnectedApp,
  ConnectedAppKind,
  ConnectedTool,
  ConnectedToolResult,
  ConnectedToolSearch,
  ConnectMcpServer,
  ConnectMcpServerResponse,
  ControlRequest,
  ControlResponse,
  CreateAgentSessionRequest,
  CreateAgentSessionResponse,
  CreateReview,
  DiscoverAgentCapabilitiesRequest,
  DiscoverAgentCapabilitiesResponse,
  DiscoverConnectorsResponse,
  DiscoveryRequest,
  EditQueuedActionRequest,
  ExecutionRecord,
  ExtractInputRequest,
  ExtractInputResponse,
  GetAgentSessionActivityParams,
  ListAgentRepositoryBranchesParams,
  LoadAgentModelsRequest,
  LoadAgentModelsResponse,
  PresentView,
  PreviewAgentSessionsRequest,
  PreviewAgentSessionsResponse,
  PullRequestSessionsResponse,
  PullRequestsSessionsResponse,
  PullRequestUrl,
  PullRequestUrls,
  RenameAgentSessionRequest,
  RetryAgentConversationTurnRequest,
  ReviewDecision,
  ReviewRecord,
  SandboxSizeBody,
  SearchConnectedAppToolsParams,
  SessionAutoArchiveResponse,
  SessionPullRequestsResponse,
  SetAgentSessionArchivedRequest,
  SharePermissionV2,
  StartFreshAgentConversationRequest,
  UnlinkAgentSessionPullRequestParams,
  UpdateSharePermissionRequestV2,
  WarmAgentSessionRequest,
  WarmAgentSessionResponse,
  WorkRegistrationResponse,
} from './schemas';

/**
 * @summary Read which triggers archive the caller's sessions by default.
 */
export type getAgentAutoArchivePreferencesResponse200 = {
  data: AutoArchivePreferencesBody;
  status: 200;
};

export type getAgentAutoArchivePreferencesResponse401 = {
  data: string;
  status: 401;
};

export type getAgentAutoArchivePreferencesResponse500 = {
  data: string;
  status: 500;
};

export type getAgentAutoArchivePreferencesResponseSuccess =
  getAgentAutoArchivePreferencesResponse200 & {
    headers: Headers;
  };
export type getAgentAutoArchivePreferencesResponseError = (
  | getAgentAutoArchivePreferencesResponse401
  | getAgentAutoArchivePreferencesResponse500
) & {
  headers: Headers;
};

export type getAgentAutoArchivePreferencesResponse =
  | getAgentAutoArchivePreferencesResponseSuccess
  | getAgentAutoArchivePreferencesResponseError;

export const getGetAgentAutoArchivePreferencesUrl = () => {
  return `/agent-auto-archive-preferences`;
};

export const getAgentAutoArchivePreferences = async (
  options?: RequestInit
): Promise<getAgentAutoArchivePreferencesResponse> => {
  const res = await fetch(getGetAgentAutoArchivePreferencesUrl(), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: getAgentAutoArchivePreferencesResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as getAgentAutoArchivePreferencesResponse;
};

/**
 * @summary Replace which triggers archive the caller's sessions by default.
 */
export type putAgentAutoArchivePreferencesResponse200 = {
  data: AutoArchivePreferencesBody;
  status: 200;
};

export type putAgentAutoArchivePreferencesResponse401 = {
  data: string;
  status: 401;
};

export type putAgentAutoArchivePreferencesResponse500 = {
  data: string;
  status: 500;
};

export type putAgentAutoArchivePreferencesResponseSuccess =
  putAgentAutoArchivePreferencesResponse200 & {
    headers: Headers;
  };
export type putAgentAutoArchivePreferencesResponseError = (
  | putAgentAutoArchivePreferencesResponse401
  | putAgentAutoArchivePreferencesResponse500
) & {
  headers: Headers;
};

export type putAgentAutoArchivePreferencesResponse =
  | putAgentAutoArchivePreferencesResponseSuccess
  | putAgentAutoArchivePreferencesResponseError;

export const getPutAgentAutoArchivePreferencesUrl = () => {
  return `/agent-auto-archive-preferences`;
};

export const putAgentAutoArchivePreferences = async (
  autoArchivePreferencesBody: AutoArchivePreferencesBody,
  options?: RequestInit
): Promise<putAgentAutoArchivePreferencesResponse> => {
  const res = await fetch(getPutAgentAutoArchivePreferencesUrl(), {
    ...options,
    method: 'PUT',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(autoArchivePreferencesBody),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: putAgentAutoArchivePreferencesResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as putAgentAutoArchivePreferencesResponse;
};

/**
 * @summary Probe one provider's ACP session configuration without persisting a session.
 */
export type discoverAgentCapabilitiesHandlerResponse200 = {
  data: DiscoverAgentCapabilitiesResponse;
  status: 200;
};

export type discoverAgentCapabilitiesHandlerResponse400 = {
  data: void;
  status: 400;
};

export type discoverAgentCapabilitiesHandlerResponse401 = {
  data: void;
  status: 401;
};

export type discoverAgentCapabilitiesHandlerResponse403 = {
  data: void;
  status: 403;
};

export type discoverAgentCapabilitiesHandlerResponse409 = {
  data: void;
  status: 409;
};

export type discoverAgentCapabilitiesHandlerResponse502 = {
  data: void;
  status: 502;
};

export type discoverAgentCapabilitiesHandlerResponse504 = {
  data: void;
  status: 504;
};

export type discoverAgentCapabilitiesHandlerResponseSuccess =
  discoverAgentCapabilitiesHandlerResponse200 & {
    headers: Headers;
  };
export type discoverAgentCapabilitiesHandlerResponseError = (
  | discoverAgentCapabilitiesHandlerResponse400
  | discoverAgentCapabilitiesHandlerResponse401
  | discoverAgentCapabilitiesHandlerResponse403
  | discoverAgentCapabilitiesHandlerResponse409
  | discoverAgentCapabilitiesHandlerResponse502
  | discoverAgentCapabilitiesHandlerResponse504
) & {
  headers: Headers;
};

export type discoverAgentCapabilitiesHandlerResponse =
  | discoverAgentCapabilitiesHandlerResponseSuccess
  | discoverAgentCapabilitiesHandlerResponseError;

export const getDiscoverAgentCapabilitiesHandlerUrl = () => {
  return `/agent-capabilities/discover`;
};

export const discoverAgentCapabilitiesHandler = async (
  discoverAgentCapabilitiesRequest: DiscoverAgentCapabilitiesRequest,
  options?: RequestInit
): Promise<discoverAgentCapabilitiesHandlerResponse> => {
  const res = await fetch(getDiscoverAgentCapabilitiesHandlerUrl(), {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(discoverAgentCapabilitiesRequest),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: discoverAgentCapabilitiesHandlerResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as discoverAgentCapabilitiesHandlerResponse;
};

/**
 * @summary Read what the caller's new coding sessions are told to do beyond their assignment.
 */
export type getAgentCodingPreferencesResponse200 = {
  data: CodingPreferencesBody;
  status: 200;
};

export type getAgentCodingPreferencesResponse401 = {
  data: string;
  status: 401;
};

export type getAgentCodingPreferencesResponse500 = {
  data: string;
  status: 500;
};

export type getAgentCodingPreferencesResponseSuccess =
  getAgentCodingPreferencesResponse200 & {
    headers: Headers;
  };
export type getAgentCodingPreferencesResponseError = (
  | getAgentCodingPreferencesResponse401
  | getAgentCodingPreferencesResponse500
) & {
  headers: Headers;
};

export type getAgentCodingPreferencesResponse =
  | getAgentCodingPreferencesResponseSuccess
  | getAgentCodingPreferencesResponseError;

export const getGetAgentCodingPreferencesUrl = () => {
  return `/agent-coding-preferences`;
};

export const getAgentCodingPreferences = async (
  options?: RequestInit
): Promise<getAgentCodingPreferencesResponse> => {
  const res = await fetch(getGetAgentCodingPreferencesUrl(), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: getAgentCodingPreferencesResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as getAgentCodingPreferencesResponse;
};

/**
 * @summary Replace the caller's coding preferences.
 */
export type putAgentCodingPreferencesResponse200 = {
  data: CodingPreferencesBody;
  status: 200;
};

export type putAgentCodingPreferencesResponse401 = {
  data: string;
  status: 401;
};

export type putAgentCodingPreferencesResponse500 = {
  data: string;
  status: 500;
};

export type putAgentCodingPreferencesResponseSuccess =
  putAgentCodingPreferencesResponse200 & {
    headers: Headers;
  };
export type putAgentCodingPreferencesResponseError = (
  | putAgentCodingPreferencesResponse401
  | putAgentCodingPreferencesResponse500
) & {
  headers: Headers;
};

export type putAgentCodingPreferencesResponse =
  | putAgentCodingPreferencesResponseSuccess
  | putAgentCodingPreferencesResponseError;

export const getPutAgentCodingPreferencesUrl = () => {
  return `/agent-coding-preferences`;
};

export const putAgentCodingPreferences = async (
  codingPreferencesBody: CodingPreferencesBody,
  options?: RequestInit
): Promise<putAgentCodingPreferencesResponse> => {
  const res = await fetch(getPutAgentCodingPreferencesUrl(), {
    ...options,
    method: 'PUT',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(codingPreferencesBody),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: putAgentCodingPreferencesResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as putAgentCodingPreferencesResponse;
};

/**
 * @summary The agent conversations in a channel the caller may see. Ordinary channels
and other people's conversations list none.
 */
export type listAgentConversationsResponse200 = {
  data: AgentConversationsDto;
  status: 200;
};

export type listAgentConversationsResponse503 = {
  data: void;
  status: 503;
};

export type listAgentConversationsResponseSuccess =
  listAgentConversationsResponse200 & {
    headers: Headers;
  };
export type listAgentConversationsResponseError =
  listAgentConversationsResponse503 & {
    headers: Headers;
  };

export type listAgentConversationsResponse =
  | listAgentConversationsResponseSuccess
  | listAgentConversationsResponseError;

export const getListAgentConversationsUrl = (channelId: string) => {
  return `/agent-conversations/${channelId}`;
};

export const listAgentConversations = async (
  channelId: string,
  options?: RequestInit
): Promise<listAgentConversationsResponse> => {
  const res = await fetch(getListAgentConversationsUrl(channelId), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: listAgentConversationsResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as listAgentConversationsResponse;
};

/**
 * @summary Start a fresh agent context, retaining the channel transcript.
 */
export type startFreshAgentConversationResponse204 = {
  data: void;
  status: 204;
};

export type startFreshAgentConversationResponse404 = {
  data: void;
  status: 404;
};

export type startFreshAgentConversationResponse409 = {
  data: void;
  status: 409;
};

export type startFreshAgentConversationResponse503 = {
  data: void;
  status: 503;
};

export type startFreshAgentConversationResponseSuccess =
  startFreshAgentConversationResponse204 & {
    headers: Headers;
  };
export type startFreshAgentConversationResponseError = (
  | startFreshAgentConversationResponse404
  | startFreshAgentConversationResponse409
  | startFreshAgentConversationResponse503
) & {
  headers: Headers;
};

export type startFreshAgentConversationResponse =
  | startFreshAgentConversationResponseSuccess
  | startFreshAgentConversationResponseError;

export const getStartFreshAgentConversationUrl = (
  channelId: string,
  botId: string
) => {
  return `/agent-conversations/${channelId}/${botId}/start-fresh`;
};

export const startFreshAgentConversation = async (
  channelId: string,
  botId: string,
  startFreshAgentConversationRequest: StartFreshAgentConversationRequest,
  options?: RequestInit
): Promise<startFreshAgentConversationResponse> => {
  const res = await fetch(getStartFreshAgentConversationUrl(channelId, botId), {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(startFreshAgentConversationRequest),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: startFreshAgentConversationResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as startFreshAgentConversationResponse;
};

/**
 * @summary Explicitly retry a failed message in the conversation's current session.
 */
export type retryAgentConversationTurnResponse204 = {
  data: void;
  status: 204;
};

export type retryAgentConversationTurnResponse404 = {
  data: void;
  status: 404;
};

export type retryAgentConversationTurnResponse409 = {
  data: void;
  status: 409;
};

export type retryAgentConversationTurnResponse503 = {
  data: void;
  status: 503;
};

export type retryAgentConversationTurnResponseSuccess =
  retryAgentConversationTurnResponse204 & {
    headers: Headers;
  };
export type retryAgentConversationTurnResponseError = (
  | retryAgentConversationTurnResponse404
  | retryAgentConversationTurnResponse409
  | retryAgentConversationTurnResponse503
) & {
  headers: Headers;
};

export type retryAgentConversationTurnResponse =
  | retryAgentConversationTurnResponseSuccess
  | retryAgentConversationTurnResponseError;

export const getRetryAgentConversationTurnUrl = (
  channelId: string,
  botId: string,
  source: string
) => {
  return `/agent-conversations/${channelId}/${botId}/turns/${source}/retry`;
};

export const retryAgentConversationTurn = async (
  channelId: string,
  botId: string,
  source: string,
  retryAgentConversationTurnRequest: RetryAgentConversationTurnRequest,
  options?: RequestInit
): Promise<retryAgentConversationTurnResponse> => {
  const res = await fetch(
    getRetryAgentConversationTurnUrl(channelId, botId, source),
    {
      ...options,
      method: 'POST',
      headers: { 'Content-Type': 'application/json', ...options?.headers },
      body: JSON.stringify(retryAgentConversationTurnRequest),
    }
  );

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: retryAgentConversationTurnResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as retryAgentConversationTurnResponse;
};

/**
 * @summary Choose whether a composer prompt goes to a chat or a coding agent.
 */
export type chooseAgentModeResponse200 = {
  data: AgentModeChoiceResponse;
  status: 200;
};

export type chooseAgentModeResponse400 = {
  data: void;
  status: 400;
};

export type chooseAgentModeResponse401 = {
  data: void;
  status: 401;
};

export type chooseAgentModeResponse402 = {
  data: void;
  status: 402;
};

export type chooseAgentModeResponse403 = {
  data: void;
  status: 403;
};

export type chooseAgentModeResponse503 = {
  data: void;
  status: 503;
};

export type chooseAgentModeResponseSuccess = chooseAgentModeResponse200 & {
  headers: Headers;
};
export type chooseAgentModeResponseError = (
  | chooseAgentModeResponse400
  | chooseAgentModeResponse401
  | chooseAgentModeResponse402
  | chooseAgentModeResponse403
  | chooseAgentModeResponse503
) & {
  headers: Headers;
};

export type chooseAgentModeResponse =
  | chooseAgentModeResponseSuccess
  | chooseAgentModeResponseError;

export const getChooseAgentModeUrl = () => {
  return `/agent-mode-choice`;
};

export const chooseAgentMode = async (
  agentModeChoiceRequest: AgentModeChoiceRequest,
  options?: RequestInit
): Promise<chooseAgentModeResponse> => {
  const res = await fetch(getChooseAgentModeUrl(), {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(agentModeChoiceRequest),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: chooseAgentModeResponse['data'] = body ? JSON.parse(body) : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as chooseAgentModeResponse;
};

/**
 * @summary Probe one provider's model catalog without creating an agent session.
 */
export type loadAgentModelsHandlerResponse200 = {
  data: LoadAgentModelsResponse;
  status: 200;
};

export type loadAgentModelsHandlerResponse400 = {
  data: void;
  status: 400;
};

export type loadAgentModelsHandlerResponse401 = {
  data: void;
  status: 401;
};

export type loadAgentModelsHandlerResponse403 = {
  data: void;
  status: 403;
};

export type loadAgentModelsHandlerResponse409 = {
  data: void;
  status: 409;
};

export type loadAgentModelsHandlerResponse502 = {
  data: void;
  status: 502;
};

export type loadAgentModelsHandlerResponse504 = {
  data: void;
  status: 504;
};

export type loadAgentModelsHandlerResponseSuccess =
  loadAgentModelsHandlerResponse200 & {
    headers: Headers;
  };
export type loadAgentModelsHandlerResponseError = (
  | loadAgentModelsHandlerResponse400
  | loadAgentModelsHandlerResponse401
  | loadAgentModelsHandlerResponse403
  | loadAgentModelsHandlerResponse409
  | loadAgentModelsHandlerResponse502
  | loadAgentModelsHandlerResponse504
) & {
  headers: Headers;
};

export type loadAgentModelsHandlerResponse =
  | loadAgentModelsHandlerResponseSuccess
  | loadAgentModelsHandlerResponseError;

export const getLoadAgentModelsHandlerUrl = () => {
  return `/agent-models/load`;
};

export const loadAgentModelsHandler = async (
  loadAgentModelsRequest: LoadAgentModelsRequest,
  options?: RequestInit
): Promise<loadAgentModelsHandlerResponse> => {
  const res = await fetch(getLoadAgentModelsHandlerUrl(), {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(loadAgentModelsRequest),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: loadAgentModelsHandlerResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as loadAgentModelsHandlerResponse;
};

/**
 * @summary List the GitHub repositories the caller can select for a coding session.
 */
export type listAgentRepositoriesResponse200 = {
  data: AgentRepositoriesResponse;
  status: 200;
};

export type listAgentRepositoriesResponse401 = {
  data: void;
  status: 401;
};

export type listAgentRepositoriesResponse502 = {
  data: void;
  status: 502;
};

export type listAgentRepositoriesResponseSuccess =
  listAgentRepositoriesResponse200 & {
    headers: Headers;
  };
export type listAgentRepositoriesResponseError = (
  | listAgentRepositoriesResponse401
  | listAgentRepositoriesResponse502
) & {
  headers: Headers;
};

export type listAgentRepositoriesResponse =
  | listAgentRepositoriesResponseSuccess
  | listAgentRepositoriesResponseError;

export const getListAgentRepositoriesUrl = () => {
  return `/agent-repositories`;
};

export const listAgentRepositories = async (
  options?: RequestInit
): Promise<listAgentRepositoriesResponse> => {
  const res = await fetch(getListAgentRepositoriesUrl(), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: listAgentRepositoriesResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as listAgentRepositoriesResponse;
};

/**
 * @summary List the branches on one repository the caller can start a session from.
 */
export type listAgentRepositoryBranchesResponse200 = {
  data: AgentRepositoryBranchesResponse;
  status: 200;
};

export type listAgentRepositoryBranchesResponse400 = {
  data: void;
  status: 400;
};

export type listAgentRepositoryBranchesResponse401 = {
  data: void;
  status: 401;
};

export type listAgentRepositoryBranchesResponse403 = {
  data: void;
  status: 403;
};

export type listAgentRepositoryBranchesResponse502 = {
  data: void;
  status: 502;
};

export type listAgentRepositoryBranchesResponseSuccess =
  listAgentRepositoryBranchesResponse200 & {
    headers: Headers;
  };
export type listAgentRepositoryBranchesResponseError = (
  | listAgentRepositoryBranchesResponse400
  | listAgentRepositoryBranchesResponse401
  | listAgentRepositoryBranchesResponse403
  | listAgentRepositoryBranchesResponse502
) & {
  headers: Headers;
};

export type listAgentRepositoryBranchesResponse =
  | listAgentRepositoryBranchesResponseSuccess
  | listAgentRepositoryBranchesResponseError;

export const getListAgentRepositoryBranchesUrl = (
  params: ListAgentRepositoryBranchesParams
) => {
  const normalizedParams = new URLSearchParams();

  Object.entries(params || {}).forEach(([key, value]) => {
    if (value !== undefined) {
      normalizedParams.append(key, value === null ? 'null' : value.toString());
    }
  });

  const stringifiedParams = normalizedParams.toString();

  return stringifiedParams.length > 0
    ? `/agent-repositories/branches?${stringifiedParams}`
    : `/agent-repositories/branches`;
};

export const listAgentRepositoryBranches = async (
  params: ListAgentRepositoryBranchesParams,
  options?: RequestInit
): Promise<listAgentRepositoryBranchesResponse> => {
  const res = await fetch(getListAgentRepositoryBranchesUrl(params), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: listAgentRepositoryBranchesResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as listAgentRepositoryBranchesResponse;
};

/**
 * @summary Read the caller's default sandbox size for new `@coder` sessions.
 */
export type getAgentSandboxSizeResponse200 = {
  data: SandboxSizeBody;
  status: 200;
};

export type getAgentSandboxSizeResponse401 = {
  data: string;
  status: 401;
};

export type getAgentSandboxSizeResponse500 = {
  data: string;
  status: 500;
};

export type getAgentSandboxSizeResponseSuccess =
  getAgentSandboxSizeResponse200 & {
    headers: Headers;
  };
export type getAgentSandboxSizeResponseError = (
  | getAgentSandboxSizeResponse401
  | getAgentSandboxSizeResponse500
) & {
  headers: Headers;
};

export type getAgentSandboxSizeResponse =
  | getAgentSandboxSizeResponseSuccess
  | getAgentSandboxSizeResponseError;

export const getGetAgentSandboxSizeUrl = () => {
  return `/agent-sandbox-size`;
};

export const getAgentSandboxSize = async (
  options?: RequestInit
): Promise<getAgentSandboxSizeResponse> => {
  const res = await fetch(getGetAgentSandboxSizeUrl(), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: getAgentSandboxSizeResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as getAgentSandboxSizeResponse;
};

/**
 * @summary Set the caller's default sandbox size for the next `@coder` mention.
 */
export type putAgentSandboxSizeResponse200 = {
  data: SandboxSizeBody;
  status: 200;
};

export type putAgentSandboxSizeResponse401 = {
  data: string;
  status: 401;
};

export type putAgentSandboxSizeResponse500 = {
  data: string;
  status: 500;
};

export type putAgentSandboxSizeResponseSuccess =
  putAgentSandboxSizeResponse200 & {
    headers: Headers;
  };
export type putAgentSandboxSizeResponseError = (
  | putAgentSandboxSizeResponse401
  | putAgentSandboxSizeResponse500
) & {
  headers: Headers;
};

export type putAgentSandboxSizeResponse =
  | putAgentSandboxSizeResponseSuccess
  | putAgentSandboxSizeResponseError;

export const getPutAgentSandboxSizeUrl = () => {
  return `/agent-sandbox-size`;
};

export const putAgentSandboxSize = async (
  sandboxSizeBody: SandboxSizeBody,
  options?: RequestInit
): Promise<putAgentSandboxSizeResponse> => {
  const res = await fetch(getPutAgentSandboxSizeUrl(), {
    ...options,
    method: 'PUT',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(sandboxSizeBody),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: putAgentSandboxSizeResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as putAgentSandboxSizeResponse;
};

/**
 * Nothing here tells the runtime where to dial: one connection per bot
carries every session it runs, so a runtime that has already dialed serves
this session too, and one that has not dials the gateway its own
configuration names. The triggering mention reaches the session as its
first prompt through the control endpoint.
 * @summary Open an agent session served by an external runtime.
 */
export type createAgentSessionResponse201 = {
  data: CreateAgentSessionResponse;
  status: 201;
};

export type createAgentSessionResponse401 = {
  data: string;
  status: 401;
};

export type createAgentSessionResponse402 = {
  data: AiAdmissionErrorBody;
  status: 402;
};

export type createAgentSessionResponse403 = {
  data: string;
  status: 403;
};

export type createAgentSessionResponse404 = {
  data: string;
  status: 404;
};

export type createAgentSessionResponse422 = {
  data: string;
  status: 422;
};

export type createAgentSessionResponse500 = {
  data: string;
  status: 500;
};

export type createAgentSessionResponse503 = {
  data: AiAdmissionErrorBody;
  status: 503;
};

export type createAgentSessionResponseSuccess =
  createAgentSessionResponse201 & {
    headers: Headers;
  };
export type createAgentSessionResponseError = (
  | createAgentSessionResponse401
  | createAgentSessionResponse402
  | createAgentSessionResponse403
  | createAgentSessionResponse404
  | createAgentSessionResponse422
  | createAgentSessionResponse500
  | createAgentSessionResponse503
) & {
  headers: Headers;
};

export type createAgentSessionResponse =
  | createAgentSessionResponseSuccess
  | createAgentSessionResponseError;

export const getCreateAgentSessionUrl = () => {
  return `/agent-sessions`;
};

export const createAgentSession = async (
  createAgentSessionRequest: CreateAgentSessionRequest,
  options?: RequestInit
): Promise<createAgentSessionResponse> => {
  const res = await fetch(getCreateAgentSessionUrl(), {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(createAgentSessionRequest),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: createAgentSessionResponse['data'] = body ? JSON.parse(body) : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as createAgentSessionResponse;
};

/**
 * @summary List the sessions associated with a pull request that the caller can view.
 */
export type agentSessionsForPullRequestResponse200 = {
  data: PullRequestSessionsResponse;
  status: 200;
};

export type agentSessionsForPullRequestResponse400 = {
  data: string;
  status: 400;
};

export type agentSessionsForPullRequestResponse401 = {
  data: string;
  status: 401;
};

export type agentSessionsForPullRequestResponse500 = {
  data: string;
  status: 500;
};

export type agentSessionsForPullRequestResponseSuccess =
  agentSessionsForPullRequestResponse200 & {
    headers: Headers;
  };
export type agentSessionsForPullRequestResponseError = (
  | agentSessionsForPullRequestResponse400
  | agentSessionsForPullRequestResponse401
  | agentSessionsForPullRequestResponse500
) & {
  headers: Headers;
};

export type agentSessionsForPullRequestResponse =
  | agentSessionsForPullRequestResponseSuccess
  | agentSessionsForPullRequestResponseError;

export const getAgentSessionsForPullRequestUrl = () => {
  return `/agent-sessions/by-pull-request`;
};

export const agentSessionsForPullRequest = async (
  pullRequestUrl: PullRequestUrl,
  options?: RequestInit
): Promise<agentSessionsForPullRequestResponse> => {
  const res = await fetch(getAgentSessionsForPullRequestUrl(), {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(pullRequestUrl),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: agentSessionsForPullRequestResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as agentSessionsForPullRequestResponse;
};

/**
 * @summary List the sessions associated with each of up to 100 pull requests that the caller can view,
with the thread each session was started from.
 */
export type agentSessionsForPullRequestsResponse200 = {
  data: PullRequestsSessionsResponse;
  status: 200;
};

export type agentSessionsForPullRequestsResponse400 = {
  data: string;
  status: 400;
};

export type agentSessionsForPullRequestsResponse401 = {
  data: string;
  status: 401;
};

export type agentSessionsForPullRequestsResponse500 = {
  data: string;
  status: 500;
};

export type agentSessionsForPullRequestsResponseSuccess =
  agentSessionsForPullRequestsResponse200 & {
    headers: Headers;
  };
export type agentSessionsForPullRequestsResponseError = (
  | agentSessionsForPullRequestsResponse400
  | agentSessionsForPullRequestsResponse401
  | agentSessionsForPullRequestsResponse500
) & {
  headers: Headers;
};

export type agentSessionsForPullRequestsResponse =
  | agentSessionsForPullRequestsResponseSuccess
  | agentSessionsForPullRequestsResponseError;

export const getAgentSessionsForPullRequestsUrl = () => {
  return `/agent-sessions/by-pull-requests`;
};

export const agentSessionsForPullRequests = async (
  pullRequestUrls: PullRequestUrls,
  options?: RequestInit
): Promise<agentSessionsForPullRequestsResponse> => {
  const res = await fetch(getAgentSessionsForPullRequestsUrl(), {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(pullRequestUrls),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: agentSessionsForPullRequestsResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as agentSessionsForPullRequestsResponse;
};

/**
 * No per-id access extractor: a chip has to render for a session the caller
cannot open, so access is answered per id in the body rather than
enforced on the request. The caller learns the fields a chip shows for
sessions they may view, and only existence for the rest.
 * @summary Preview a batch of agent sessions for rendering chips.
 */
export type previewAgentSessionsResponse200 = {
  data: PreviewAgentSessionsResponse;
  status: 200;
};

export type previewAgentSessionsResponse400 = {
  data: string;
  status: 400;
};

export type previewAgentSessionsResponse401 = {
  data: string;
  status: 401;
};

export type previewAgentSessionsResponse500 = {
  data: string;
  status: 500;
};

export type previewAgentSessionsResponseSuccess =
  previewAgentSessionsResponse200 & {
    headers: Headers;
  };
export type previewAgentSessionsResponseError = (
  | previewAgentSessionsResponse400
  | previewAgentSessionsResponse401
  | previewAgentSessionsResponse500
) & {
  headers: Headers;
};

export type previewAgentSessionsResponse =
  | previewAgentSessionsResponseSuccess
  | previewAgentSessionsResponseError;

export const getPreviewAgentSessionsUrl = () => {
  return `/agent-sessions/preview`;
};

export const previewAgentSessions = async (
  previewAgentSessionsRequest: PreviewAgentSessionsRequest,
  options?: RequestInit
): Promise<previewAgentSessionsResponse> => {
  const res = await fetch(getPreviewAgentSessionsUrl(), {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(previewAgentSessionsRequest),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: previewAgentSessionsResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as previewAgentSessionsResponse;
};

/**
 * @summary Prepare MCP connections without sending a prompt or creating a visible list row.
 */
export type warmAgentSessionHandlerResponse200 = {
  data: WarmAgentSessionResponse;
  status: 200;
};

export type warmAgentSessionHandlerResponseSuccess =
  warmAgentSessionHandlerResponse200 & {
    headers: Headers;
  };

export type warmAgentSessionHandlerResponse =
  warmAgentSessionHandlerResponseSuccess;

export const getWarmAgentSessionHandlerUrl = () => {
  return `/agent-sessions/warm`;
};

export const warmAgentSessionHandler = async (
  warmAgentSessionRequest: WarmAgentSessionRequest,
  options?: RequestInit
): Promise<warmAgentSessionHandlerResponse> => {
  const res = await fetch(getWarmAgentSessionHandlerUrl(), {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(warmAgentSessionRequest),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: warmAgentSessionHandlerResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as warmAgentSessionHandlerResponse;
};

/**
 * A caller holding no grant is answered 401; an id with no session behind it
at all is answered 404. They used to be the same answer, which left a
client that read a session before its create had landed unable to tell a
race it should retry from a refusal it should not.
 * @summary Get an agent session by id.
 */
export type getAgentSessionResponse200 = {
  data: AgentSessionResponse;
  status: 200;
};

export type getAgentSessionResponse401 = {
  data: string;
  status: 401;
};

export type getAgentSessionResponse403 = {
  data: string;
  status: 403;
};

export type getAgentSessionResponse404 = {
  data: string;
  status: 404;
};

export type getAgentSessionResponse500 = {
  data: string;
  status: 500;
};

export type getAgentSessionResponseSuccess = getAgentSessionResponse200 & {
  headers: Headers;
};
export type getAgentSessionResponseError = (
  | getAgentSessionResponse401
  | getAgentSessionResponse403
  | getAgentSessionResponse404
  | getAgentSessionResponse500
) & {
  headers: Headers;
};

export type getAgentSessionResponse =
  | getAgentSessionResponseSuccess
  | getAgentSessionResponseError;

export const getGetAgentSessionUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}`;
};

export const getAgentSession = async (
  sessionId: string,
  options?: RequestInit
): Promise<getAgentSessionResponse> => {
  const res = await fetch(getGetAgentSessionUrl(sessionId), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: getAgentSessionResponse['data'] = body ? JSON.parse(body) : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as getAgentSessionResponse;
};

/**
 * @summary Delete an agent session and its live resources.
 */
export type deleteAgentSessionResponse200 = {
  data: void;
  status: 200;
};

export type deleteAgentSessionResponse401 = {
  data: string;
  status: 401;
};

export type deleteAgentSessionResponse403 = {
  data: string;
  status: 403;
};

export type deleteAgentSessionResponse500 = {
  data: string;
  status: 500;
};

export type deleteAgentSessionResponseSuccess =
  deleteAgentSessionResponse200 & {
    headers: Headers;
  };
export type deleteAgentSessionResponseError = (
  | deleteAgentSessionResponse401
  | deleteAgentSessionResponse403
  | deleteAgentSessionResponse500
) & {
  headers: Headers;
};

export type deleteAgentSessionResponse =
  | deleteAgentSessionResponseSuccess
  | deleteAgentSessionResponseError;

export const getDeleteAgentSessionUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}`;
};

export const deleteAgentSession = async (
  sessionId: string,
  options?: RequestInit
): Promise<deleteAgentSessionResponse> => {
  const res = await fetch(getDeleteAgentSessionUrl(sessionId), {
    ...options,
    method: 'DELETE',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: deleteAgentSessionResponse['data'] = body ? JSON.parse(body) : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as deleteAgentSessionResponse;
};

/**
 * @summary Read activity using the same visibility capability as the session transcript.
 */
export type getAgentSessionActivityResponse200 = {
  data: AgentActivityPage;
  status: 200;
};

export type getAgentSessionActivityResponse400 = {
  data: void;
  status: 400;
};

export type getAgentSessionActivityResponse401 = {
  data: void;
  status: 401;
};

export type getAgentSessionActivityResponse403 = {
  data: void;
  status: 403;
};

export type getAgentSessionActivityResponseSuccess =
  getAgentSessionActivityResponse200 & {
    headers: Headers;
  };
export type getAgentSessionActivityResponseError = (
  | getAgentSessionActivityResponse400
  | getAgentSessionActivityResponse401
  | getAgentSessionActivityResponse403
) & {
  headers: Headers;
};

export type getAgentSessionActivityResponse =
  | getAgentSessionActivityResponseSuccess
  | getAgentSessionActivityResponseError;

export const getGetAgentSessionActivityUrl = (
  sessionId: string,
  params?: GetAgentSessionActivityParams
) => {
  const normalizedParams = new URLSearchParams();

  Object.entries(params || {}).forEach(([key, value]) => {
    if (value !== undefined) {
      normalizedParams.append(key, value === null ? 'null' : value.toString());
    }
  });

  const stringifiedParams = normalizedParams.toString();

  return stringifiedParams.length > 0
    ? `/agent-sessions/${sessionId}/activity?${stringifiedParams}`
    : `/agent-sessions/${sessionId}/activity`;
};

export const getAgentSessionActivity = async (
  sessionId: string,
  params?: GetAgentSessionActivityParams,
  options?: RequestInit
): Promise<getAgentSessionActivityResponse> => {
  const res = await fetch(getGetAgentSessionActivityUrl(sessionId, params), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: getAgentSessionActivityResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as getAgentSessionActivityResponse;
};

/**
 * The harness produces an `app.connected` system event, which the transcript
shows as no prompt; it starts a turn once the session is idle.
 * @summary Continue the session now that its owner connected an app it asked for.
 */
export type reportAgentSessionAppConnectedResponse202 = {
  data: void;
  status: 202;
};

export type reportAgentSessionAppConnectedResponse401 = {
  data: string;
  status: 401;
};

export type reportAgentSessionAppConnectedResponse403 = {
  data: string;
  status: 403;
};

export type reportAgentSessionAppConnectedResponse409 = {
  data: string;
  status: 409;
};

export type reportAgentSessionAppConnectedResponse422 = {
  data: string;
  status: 422;
};

export type reportAgentSessionAppConnectedResponse500 = {
  data: string;
  status: 500;
};

export type reportAgentSessionAppConnectedResponseSuccess =
  reportAgentSessionAppConnectedResponse202 & {
    headers: Headers;
  };
export type reportAgentSessionAppConnectedResponseError = (
  | reportAgentSessionAppConnectedResponse401
  | reportAgentSessionAppConnectedResponse403
  | reportAgentSessionAppConnectedResponse409
  | reportAgentSessionAppConnectedResponse422
  | reportAgentSessionAppConnectedResponse500
) & {
  headers: Headers;
};

export type reportAgentSessionAppConnectedResponse =
  | reportAgentSessionAppConnectedResponseSuccess
  | reportAgentSessionAppConnectedResponseError;

export const getReportAgentSessionAppConnectedUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/app-connections`;
};

export const reportAgentSessionAppConnected = async (
  sessionId: string,
  appConnectedRequest: AppConnectedRequest,
  options?: RequestInit
): Promise<reportAgentSessionAppConnectedResponse> => {
  const res = await fetch(getReportAgentSessionAppConnectedUrl(sessionId), {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(appConnectedRequest),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: reportAgentSessionAppConnectedResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as reportAgentSessionAppConnectedResponse;
};

/**
 * @summary Archive or unarchive an agent session.
 */
export type setAgentSessionArchivedResponse204 = {
  data: void;
  status: 204;
};

export type setAgentSessionArchivedResponse401 = {
  data: string;
  status: 401;
};

export type setAgentSessionArchivedResponse403 = {
  data: string;
  status: 403;
};

export type setAgentSessionArchivedResponse409 = {
  data: string;
  status: 409;
};

export type setAgentSessionArchivedResponse500 = {
  data: string;
  status: 500;
};

export type setAgentSessionArchivedResponseSuccess =
  setAgentSessionArchivedResponse204 & {
    headers: Headers;
  };
export type setAgentSessionArchivedResponseError = (
  | setAgentSessionArchivedResponse401
  | setAgentSessionArchivedResponse403
  | setAgentSessionArchivedResponse409
  | setAgentSessionArchivedResponse500
) & {
  headers: Headers;
};

export type setAgentSessionArchivedResponse =
  | setAgentSessionArchivedResponseSuccess
  | setAgentSessionArchivedResponseError;

export const getSetAgentSessionArchivedUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/archived`;
};

export const setAgentSessionArchived = async (
  sessionId: string,
  setAgentSessionArchivedRequest: SetAgentSessionArchivedRequest,
  options?: RequestInit
): Promise<setAgentSessionArchivedResponse> => {
  const res = await fetch(getSetAgentSessionArchivedUrl(sessionId), {
    ...options,
    method: 'PUT',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(setAgentSessionArchivedRequest),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: setAgentSessionArchivedResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as setAgentSessionArchivedResponse;
};

/**
 * @summary Read a session's auto-archive settings and whether a trigger archived it.
 */
export type getAgentSessionAutoArchiveResponse200 = {
  data: SessionAutoArchiveResponse;
  status: 200;
};

export type getAgentSessionAutoArchiveResponse401 = {
  data: string;
  status: 401;
};

export type getAgentSessionAutoArchiveResponse403 = {
  data: string;
  status: 403;
};

export type getAgentSessionAutoArchiveResponse500 = {
  data: string;
  status: 500;
};

export type getAgentSessionAutoArchiveResponseSuccess =
  getAgentSessionAutoArchiveResponse200 & {
    headers: Headers;
  };
export type getAgentSessionAutoArchiveResponseError = (
  | getAgentSessionAutoArchiveResponse401
  | getAgentSessionAutoArchiveResponse403
  | getAgentSessionAutoArchiveResponse500
) & {
  headers: Headers;
};

export type getAgentSessionAutoArchiveResponse =
  | getAgentSessionAutoArchiveResponseSuccess
  | getAgentSessionAutoArchiveResponseError;

export const getGetAgentSessionAutoArchiveUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/auto-archive`;
};

export const getAgentSessionAutoArchive = async (
  sessionId: string,
  options?: RequestInit
): Promise<getAgentSessionAutoArchiveResponse> => {
  const res = await fetch(getGetAgentSessionAutoArchiveUrl(sessionId), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: getAgentSessionAutoArchiveResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as getAgentSessionAutoArchiveResponse;
};

/**
 * @summary Replace a session's own auto-archive choices. Owner only.
 */
export type putAgentSessionAutoArchiveResponse200 = {
  data: AutoArchiveOverridesBody;
  status: 200;
};

export type putAgentSessionAutoArchiveResponse401 = {
  data: string;
  status: 401;
};

export type putAgentSessionAutoArchiveResponse403 = {
  data: string;
  status: 403;
};

export type putAgentSessionAutoArchiveResponse500 = {
  data: string;
  status: 500;
};

export type putAgentSessionAutoArchiveResponseSuccess =
  putAgentSessionAutoArchiveResponse200 & {
    headers: Headers;
  };
export type putAgentSessionAutoArchiveResponseError = (
  | putAgentSessionAutoArchiveResponse401
  | putAgentSessionAutoArchiveResponse403
  | putAgentSessionAutoArchiveResponse500
) & {
  headers: Headers;
};

export type putAgentSessionAutoArchiveResponse =
  | putAgentSessionAutoArchiveResponseSuccess
  | putAgentSessionAutoArchiveResponseError;

export const getPutAgentSessionAutoArchiveUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/auto-archive`;
};

export const putAgentSessionAutoArchive = async (
  sessionId: string,
  autoArchiveOverridesBody: AutoArchiveOverridesBody,
  options?: RequestInit
): Promise<putAgentSessionAutoArchiveResponse> => {
  const res = await fetch(getPutAgentSessionAutoArchiveUrl(sessionId), {
    ...options,
    method: 'PUT',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(autoArchiveOverridesBody),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: putAgentSessionAutoArchiveResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as putAgentSessionAutoArchiveResponse;
};

/**
 * @summary The latest captured changes of an agent session: the changed files with
statuses and line counts, and how the latest capture attempt went.
 */
export type getAgentSessionChangesResponse200 = {
  data: AgentSessionChangesResponse;
  status: 200;
};

export type getAgentSessionChangesResponse401 = {
  data: string;
  status: 401;
};

export type getAgentSessionChangesResponse403 = {
  data: string;
  status: 403;
};

export type getAgentSessionChangesResponse500 = {
  data: string;
  status: 500;
};

export type getAgentSessionChangesResponseSuccess =
  getAgentSessionChangesResponse200 & {
    headers: Headers;
  };
export type getAgentSessionChangesResponseError = (
  | getAgentSessionChangesResponse401
  | getAgentSessionChangesResponse403
  | getAgentSessionChangesResponse500
) & {
  headers: Headers;
};

export type getAgentSessionChangesResponse =
  | getAgentSessionChangesResponseSuccess
  | getAgentSessionChangesResponseError;

export const getGetAgentSessionChangesUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/changes`;
};

export const getAgentSessionChanges = async (
  sessionId: string,
  options?: RequestInit
): Promise<getAgentSessionChangesResponse> => {
  const res = await fetch(getGetAgentSessionChangesUrl(sessionId), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: getAgentSessionChangesResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as getAgentSessionChangesResponse;
};

/**
 * @summary The unified diff behind the session's latest changeset.
 */
export type getAgentSessionChangesPatchResponse200 = {
  data: AgentSessionChangesPatchResponse;
  status: 200;
};

export type getAgentSessionChangesPatchResponse401 = {
  data: string;
  status: 401;
};

export type getAgentSessionChangesPatchResponse403 = {
  data: string;
  status: 403;
};

export type getAgentSessionChangesPatchResponse404 = {
  data: string;
  status: 404;
};

export type getAgentSessionChangesPatchResponse500 = {
  data: string;
  status: 500;
};

export type getAgentSessionChangesPatchResponseSuccess =
  getAgentSessionChangesPatchResponse200 & {
    headers: Headers;
  };
export type getAgentSessionChangesPatchResponseError = (
  | getAgentSessionChangesPatchResponse401
  | getAgentSessionChangesPatchResponse403
  | getAgentSessionChangesPatchResponse404
  | getAgentSessionChangesPatchResponse500
) & {
  headers: Headers;
};

export type getAgentSessionChangesPatchResponse =
  | getAgentSessionChangesPatchResponseSuccess
  | getAgentSessionChangesPatchResponseError;

export const getGetAgentSessionChangesPatchUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/changes/patch`;
};

export const getAgentSessionChangesPatch = async (
  sessionId: string,
  options?: RequestInit
): Promise<getAgentSessionChangesPatchResponse> => {
  const res = await fetch(getGetAgentSessionChangesPatchUrl(sessionId), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: getAgentSessionChangesPatchResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as getAgentSessionChangesPatchResponse;
};

/**
 * @summary Capture the session's changes again now. Answers at once with the state
as it stands; the capture runs on and viewers are told when it lands.
 */
export type refreshAgentSessionChangesResponse202 = {
  data: AgentSessionChangesResponse;
  status: 202;
};

export type refreshAgentSessionChangesResponse401 = {
  data: string;
  status: 401;
};

export type refreshAgentSessionChangesResponse403 = {
  data: string;
  status: 403;
};

export type refreshAgentSessionChangesResponse500 = {
  data: string;
  status: 500;
};

export type refreshAgentSessionChangesResponseSuccess =
  refreshAgentSessionChangesResponse202 & {
    headers: Headers;
  };
export type refreshAgentSessionChangesResponseError = (
  | refreshAgentSessionChangesResponse401
  | refreshAgentSessionChangesResponse403
  | refreshAgentSessionChangesResponse500
) & {
  headers: Headers;
};

export type refreshAgentSessionChangesResponse =
  | refreshAgentSessionChangesResponseSuccess
  | refreshAgentSessionChangesResponseError;

export const getRefreshAgentSessionChangesUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/changes/refresh`;
};

export const refreshAgentSessionChanges = async (
  sessionId: string,
  options?: RequestInit
): Promise<refreshAgentSessionChangesResponse> => {
  const res = await fetch(getRefreshAgentSessionChangesUrl(sessionId), {
    ...options,
    method: 'POST',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: refreshAgentSessionChangesResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as refreshAgentSessionChangesResponse;
};

/**
 * @summary Fetch one execution only after the caller has obtained view access to its session.
 */
export type getCodeExecutionResponse200 = {
  data: ExecutionRecord;
  status: 200;
};

export type getCodeExecutionResponse401 = {
  data: void;
  status: 401;
};

export type getCodeExecutionResponse403 = {
  data: void;
  status: 403;
};

export type getCodeExecutionResponse404 = {
  data: void;
  status: 404;
};

export type getCodeExecutionResponse500 = {
  data: void;
  status: 500;
};

export type getCodeExecutionResponseSuccess = getCodeExecutionResponse200 & {
  headers: Headers;
};
export type getCodeExecutionResponseError = (
  | getCodeExecutionResponse401
  | getCodeExecutionResponse403
  | getCodeExecutionResponse404
  | getCodeExecutionResponse500
) & {
  headers: Headers;
};

export type getCodeExecutionResponse =
  | getCodeExecutionResponseSuccess
  | getCodeExecutionResponseError;

export const getGetCodeExecutionUrl = (
  sessionId: string,
  executionId: string
) => {
  return `/agent-sessions/${sessionId}/code-executions/${executionId}`;
};

export const getCodeExecution = async (
  sessionId: string,
  executionId: string,
  options?: RequestInit
): Promise<getCodeExecutionResponse> => {
  const res = await fetch(getGetCodeExecutionUrl(sessionId, executionId), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: getCodeExecutionResponse['data'] = body ? JSON.parse(body) : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as getCodeExecutionResponse;
};

/**
 * @summary List the connected apps and custom MCP servers the session's agent may use.
 */
export type listExecutionConnectedAppsResponse200 = {
  data: ConnectedApp[];
  status: 200;
};

export type listExecutionConnectedAppsResponse403 = {
  data: void;
  status: 403;
};

export type listExecutionConnectedAppsResponse404 = {
  data: void;
  status: 404;
};

export type listExecutionConnectedAppsResponseSuccess =
  listExecutionConnectedAppsResponse200 & {
    headers: Headers;
  };
export type listExecutionConnectedAppsResponseError = (
  | listExecutionConnectedAppsResponse403
  | listExecutionConnectedAppsResponse404
) & {
  headers: Headers;
};

export type listExecutionConnectedAppsResponse =
  | listExecutionConnectedAppsResponseSuccess
  | listExecutionConnectedAppsResponseError;

export const getListExecutionConnectedAppsUrl = (
  sessionId: string,
  executionId: string
) => {
  return `/agent-sessions/${sessionId}/code-executions/${executionId}/connected-apps`;
};

export const listExecutionConnectedApps = async (
  sessionId: string,
  executionId: string,
  options?: RequestInit
): Promise<listExecutionConnectedAppsResponse> => {
  const res = await fetch(
    getListExecutionConnectedAppsUrl(sessionId, executionId),
    {
      ...options,
      method: 'GET',
    }
  );

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: listExecutionConnectedAppsResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as listExecutionConnectedAppsResponse;
};

/**
 * @summary Search the connectable app catalog, or inspect one app's tools and connection status.
 */
export type discoverConnectedAppsResponse200 = {
  data: DiscoverConnectorsResponse;
  status: 200;
};

export type discoverConnectedAppsResponse400 = {
  data: void;
  status: 400;
};

export type discoverConnectedAppsResponse403 = {
  data: void;
  status: 403;
};

export type discoverConnectedAppsResponse404 = {
  data: void;
  status: 404;
};

export type discoverConnectedAppsResponseSuccess =
  discoverConnectedAppsResponse200 & {
    headers: Headers;
  };
export type discoverConnectedAppsResponseError = (
  | discoverConnectedAppsResponse400
  | discoverConnectedAppsResponse403
  | discoverConnectedAppsResponse404
) & {
  headers: Headers;
};

export type discoverConnectedAppsResponse =
  | discoverConnectedAppsResponseSuccess
  | discoverConnectedAppsResponseError;

export const getDiscoverConnectedAppsUrl = (
  sessionId: string,
  executionId: string
) => {
  return `/agent-sessions/${sessionId}/code-executions/${executionId}/connected-apps/discover`;
};

export const discoverConnectedApps = async (
  sessionId: string,
  executionId: string,
  discoveryRequest: DiscoveryRequest,
  options?: RequestInit
): Promise<discoverConnectedAppsResponse> => {
  const res = await fetch(getDiscoverConnectedAppsUrl(sessionId, executionId), {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(discoveryRequest),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: discoverConnectedAppsResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as discoverConnectedAppsResponse;
};

/**
 * @summary Add a custom MCP server to the execution account's connections.
 */
export type addConnectedMcpServerResponse200 = {
  data: ConnectMcpServerResponse;
  status: 200;
};

export type addConnectedMcpServerResponse400 = {
  data: void;
  status: 400;
};

export type addConnectedMcpServerResponse403 = {
  data: void;
  status: 403;
};

export type addConnectedMcpServerResponse404 = {
  data: void;
  status: 404;
};

export type addConnectedMcpServerResponseSuccess =
  addConnectedMcpServerResponse200 & {
    headers: Headers;
  };
export type addConnectedMcpServerResponseError = (
  | addConnectedMcpServerResponse400
  | addConnectedMcpServerResponse403
  | addConnectedMcpServerResponse404
) & {
  headers: Headers;
};

export type addConnectedMcpServerResponse =
  | addConnectedMcpServerResponseSuccess
  | addConnectedMcpServerResponseError;

export const getAddConnectedMcpServerUrl = (
  sessionId: string,
  executionId: string
) => {
  return `/agent-sessions/${sessionId}/code-executions/${executionId}/connected-apps/servers`;
};

export const addConnectedMcpServer = async (
  sessionId: string,
  executionId: string,
  connectMcpServer: ConnectMcpServer,
  options?: RequestInit
): Promise<addConnectedMcpServerResponse> => {
  const res = await fetch(getAddConnectedMcpServerUrl(sessionId, executionId), {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(connectMcpServer),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: addConnectedMcpServerResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as addConnectedMcpServerResponse;
};

/**
 * @summary Find tools across the agent's connected apps by keywords.
 */
export type searchConnectedAppToolsResponse200 = {
  data: ConnectedToolSearch;
  status: 200;
};

export type searchConnectedAppToolsResponse403 = {
  data: void;
  status: 403;
};

export type searchConnectedAppToolsResponse404 = {
  data: void;
  status: 404;
};

export type searchConnectedAppToolsResponseSuccess =
  searchConnectedAppToolsResponse200 & {
    headers: Headers;
  };
export type searchConnectedAppToolsResponseError = (
  | searchConnectedAppToolsResponse403
  | searchConnectedAppToolsResponse404
) & {
  headers: Headers;
};

export type searchConnectedAppToolsResponse =
  | searchConnectedAppToolsResponseSuccess
  | searchConnectedAppToolsResponseError;

export const getSearchConnectedAppToolsUrl = (
  sessionId: string,
  executionId: string,
  params: SearchConnectedAppToolsParams
) => {
  const normalizedParams = new URLSearchParams();

  Object.entries(params || {}).forEach(([key, value]) => {
    if (value !== undefined) {
      normalizedParams.append(key, value === null ? 'null' : value.toString());
    }
  });

  const stringifiedParams = normalizedParams.toString();

  return stringifiedParams.length > 0
    ? `/agent-sessions/${sessionId}/code-executions/${executionId}/connected-apps/tools?${stringifiedParams}`
    : `/agent-sessions/${sessionId}/code-executions/${executionId}/connected-apps/tools`;
};

export const searchConnectedAppTools = async (
  sessionId: string,
  executionId: string,
  params: SearchConnectedAppToolsParams,
  options?: RequestInit
): Promise<searchConnectedAppToolsResponse> => {
  const res = await fetch(
    getSearchConnectedAppToolsUrl(sessionId, executionId, params),
    {
      ...options,
      method: 'GET',
    }
  );

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: searchConnectedAppToolsResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as searchConnectedAppToolsResponse;
};

/**
 * @summary Call one tool of a connected app as the execution's account.
 */
export type callConnectedAppToolResponse200 = {
  data: ConnectedToolResult;
  status: 200;
};

export type callConnectedAppToolResponse400 = {
  data: void;
  status: 400;
};

export type callConnectedAppToolResponse403 = {
  data: void;
  status: 403;
};

export type callConnectedAppToolResponse404 = {
  data: void;
  status: 404;
};

export type callConnectedAppToolResponseSuccess =
  callConnectedAppToolResponse200 & {
    headers: Headers;
  };
export type callConnectedAppToolResponseError = (
  | callConnectedAppToolResponse400
  | callConnectedAppToolResponse403
  | callConnectedAppToolResponse404
) & {
  headers: Headers;
};

export type callConnectedAppToolResponse =
  | callConnectedAppToolResponseSuccess
  | callConnectedAppToolResponseError;

export const getCallConnectedAppToolUrl = (
  sessionId: string,
  executionId: string,
  kind: ConnectedAppKind,
  key: string
) => {
  return `/agent-sessions/${sessionId}/code-executions/${executionId}/connected-apps/${kind}/${key}/calls`;
};

export const callConnectedAppTool = async (
  sessionId: string,
  executionId: string,
  kind: ConnectedAppKind,
  key: string,
  callConnectedTool: CallConnectedTool,
  options?: RequestInit
): Promise<callConnectedAppToolResponse> => {
  const res = await fetch(
    getCallConnectedAppToolUrl(sessionId, executionId, kind, key),
    {
      ...options,
      method: 'POST',
      headers: { 'Content-Type': 'application/json', ...options?.headers },
      body: JSON.stringify(callConnectedTool),
    }
  );

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: callConnectedAppToolResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as callConnectedAppToolResponse;
};

/**
 * @summary List the tools one connected app serves.
 */
export type listConnectedAppToolsResponse200 = {
  data: ConnectedTool[];
  status: 200;
};

export type listConnectedAppToolsResponse403 = {
  data: void;
  status: 403;
};

export type listConnectedAppToolsResponse404 = {
  data: void;
  status: 404;
};

export type listConnectedAppToolsResponseSuccess =
  listConnectedAppToolsResponse200 & {
    headers: Headers;
  };
export type listConnectedAppToolsResponseError = (
  | listConnectedAppToolsResponse403
  | listConnectedAppToolsResponse404
) & {
  headers: Headers;
};

export type listConnectedAppToolsResponse =
  | listConnectedAppToolsResponseSuccess
  | listConnectedAppToolsResponseError;

export const getListConnectedAppToolsUrl = (
  sessionId: string,
  executionId: string,
  kind: ConnectedAppKind,
  key: string
) => {
  return `/agent-sessions/${sessionId}/code-executions/${executionId}/connected-apps/${kind}/${key}/tools`;
};

export const listConnectedAppTools = async (
  sessionId: string,
  executionId: string,
  kind: ConnectedAppKind,
  key: string,
  options?: RequestInit
): Promise<listConnectedAppToolsResponse> => {
  const res = await fetch(
    getListConnectedAppToolsUrl(sessionId, executionId, kind, key),
    {
      ...options,
      method: 'GET',
    }
  );

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: listConnectedAppToolsResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as listConnectedAppToolsResponse;
};

/**
 * @summary List blocks created during an execution, including interrupted executions.
 */
export type listExecutionReviewsResponse200 = {
  data: ReviewRecord[];
  status: 200;
};

export type listExecutionReviewsResponse403 = {
  data: void;
  status: 403;
};

export type listExecutionReviewsResponseSuccess =
  listExecutionReviewsResponse200 & {
    headers: Headers;
  };
export type listExecutionReviewsResponseError =
  listExecutionReviewsResponse403 & {
    headers: Headers;
  };

export type listExecutionReviewsResponse =
  | listExecutionReviewsResponseSuccess
  | listExecutionReviewsResponseError;

export const getListExecutionReviewsUrl = (
  sessionId: string,
  executionId: string
) => {
  return `/agent-sessions/${sessionId}/code-executions/${executionId}/reviews`;
};

export const listExecutionReviews = async (
  sessionId: string,
  executionId: string,
  options?: RequestInit
): Promise<listExecutionReviewsResponse> => {
  const res = await fetch(getListExecutionReviewsUrl(sessionId, executionId), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: listExecutionReviewsResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as listExecutionReviewsResponse;
};

/**
 * Edit access suffices: whoever can prompt the bot through its thread can
prompt it here.

A caller may name the action with `actionId`; the response echoes it.
Re-posting an id the session still holds queued or in flight reports that
action's status rather than accepting a duplicate.
 * @summary Perform a control operation on a live agent session.
 */
export type controlAgentSessionResponse200 = {
  data: ControlResponse;
  status: 200;
};

export type controlAgentSessionResponse401 = {
  data: string;
  status: 401;
};

export type controlAgentSessionResponse402 = {
  data: AiAdmissionErrorBody;
  status: 402;
};

export type controlAgentSessionResponse403 = {
  data: string;
  status: 403;
};

export type controlAgentSessionResponse422 = {
  data: string;
  status: 422;
};

export type controlAgentSessionResponse500 = {
  data: string;
  status: 500;
};

export type controlAgentSessionResponse503ApplicationJson = {
  data: AiAdmissionErrorBody;
  status: 503;
};

export type controlAgentSessionResponse503TextPlain = {
  data: string;
  status: 503;
};

export type controlAgentSessionResponseSuccess =
  controlAgentSessionResponse200 & {
    headers: Headers;
  };
export type controlAgentSessionResponseError = (
  | controlAgentSessionResponse401
  | controlAgentSessionResponse402
  | controlAgentSessionResponse403
  | controlAgentSessionResponse422
  | controlAgentSessionResponse500
  | controlAgentSessionResponse503ApplicationJson
  | controlAgentSessionResponse503TextPlain
) & {
  headers: Headers;
};

export type controlAgentSessionResponse =
  | controlAgentSessionResponseSuccess
  | controlAgentSessionResponseError;

export const getControlAgentSessionUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/control`;
};

export const controlAgentSession = async (
  sessionId: string,
  controlRequest: ControlRequest,
  options?: RequestInit
): Promise<controlAgentSessionResponse> => {
  const res = await fetch(getControlAgentSessionUrl(sessionId), {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(controlRequest),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: controlAgentSessionResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as controlAgentSessionResponse;
};

/**
 * Served unfolded from the latest successful load initialization, or the
beginning when no load succeeded. Consumers stage load attempts so failed
or interrupted replay does not become visible conversation content.

An unknown session is an error: the response has to name the session's
agent, and a session that never existed has none to name.
 * @summary The raw protocol log of one agent session.
 */
export type getAgentSessionLogResponse200 = {
  data: AgentSessionLogResponse;
  status: 200;
};

export type getAgentSessionLogResponse401 = {
  data: string;
  status: 401;
};

export type getAgentSessionLogResponse403 = {
  data: string;
  status: 403;
};

export type getAgentSessionLogResponse500 = {
  data: string;
  status: 500;
};

export type getAgentSessionLogResponseSuccess =
  getAgentSessionLogResponse200 & {
    headers: Headers;
  };
export type getAgentSessionLogResponseError = (
  | getAgentSessionLogResponse401
  | getAgentSessionLogResponse403
  | getAgentSessionLogResponse500
) & {
  headers: Headers;
};

export type getAgentSessionLogResponse =
  | getAgentSessionLogResponseSuccess
  | getAgentSessionLogResponseError;

export const getGetAgentSessionLogUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/log`;
};

export const getAgentSessionLog = async (
  sessionId: string,
  options?: RequestInit
): Promise<getAgentSessionLogResponse> => {
  const res = await fetch(getGetAgentSessionLogUrl(sessionId), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: getAgentSessionLogResponse['data'] = body ? JSON.parse(body) : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as getAgentSessionLogResponse;
};

/**
 * For readers that do not run the fold themselves, such as SDK programs and
agents reading another session's history.
 * @summary One agent session's history folded into renderable messages: the same
fold the web client runs over [`get_agent_session_log_handler`]'s frames.
 */
export type getAgentSessionFoldedLogResponse200 = {
  data: AgentSessionFoldedLogResponse;
  status: 200;
};

export type getAgentSessionFoldedLogResponse401 = {
  data: string;
  status: 401;
};

export type getAgentSessionFoldedLogResponse403 = {
  data: string;
  status: 403;
};

export type getAgentSessionFoldedLogResponse500 = {
  data: string;
  status: 500;
};

export type getAgentSessionFoldedLogResponseSuccess =
  getAgentSessionFoldedLogResponse200 & {
    headers: Headers;
  };
export type getAgentSessionFoldedLogResponseError = (
  | getAgentSessionFoldedLogResponse401
  | getAgentSessionFoldedLogResponse403
  | getAgentSessionFoldedLogResponse500
) & {
  headers: Headers;
};

export type getAgentSessionFoldedLogResponse =
  | getAgentSessionFoldedLogResponseSuccess
  | getAgentSessionFoldedLogResponseError;

export const getGetAgentSessionFoldedLogUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/log/folded`;
};

export const getAgentSessionFoldedLog = async (
  sessionId: string,
  options?: RequestInit
): Promise<getAgentSessionFoldedLogResponse> => {
  const res = await fetch(getGetAgentSessionFoldedLogUrl(sessionId), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: getAgentSessionFoldedLogResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as getAgentSessionFoldedLogResponse;
};

/**
 * @summary Rename an agent session.
 */
export type renameAgentSessionResponse204 = {
  data: void;
  status: 204;
};

export type renameAgentSessionResponse400 = {
  data: string;
  status: 400;
};

export type renameAgentSessionResponse401 = {
  data: string;
  status: 401;
};

export type renameAgentSessionResponse403 = {
  data: string;
  status: 403;
};

export type renameAgentSessionResponse409 = {
  data: string;
  status: 409;
};

export type renameAgentSessionResponse500 = {
  data: string;
  status: 500;
};

export type renameAgentSessionResponseSuccess =
  renameAgentSessionResponse204 & {
    headers: Headers;
  };
export type renameAgentSessionResponseError = (
  | renameAgentSessionResponse400
  | renameAgentSessionResponse401
  | renameAgentSessionResponse403
  | renameAgentSessionResponse409
  | renameAgentSessionResponse500
) & {
  headers: Headers;
};

export type renameAgentSessionResponse =
  | renameAgentSessionResponseSuccess
  | renameAgentSessionResponseError;

export const getRenameAgentSessionUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/name`;
};

export const renameAgentSession = async (
  sessionId: string,
  renameAgentSessionRequest: RenameAgentSessionRequest,
  options?: RequestInit
): Promise<renameAgentSessionResponse> => {
  const res = await fetch(getRenameAgentSessionUrl(sessionId), {
    ...options,
    method: 'PUT',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(renameAgentSessionRequest),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: renameAgentSessionResponse['data'] = body ? JSON.parse(body) : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as renameAgentSessionResponse;
};

/**
 * @summary Read sharing settings for a session the caller can view.
 */
export type getAgentSessionPermissionsResponse200 = {
  data: SharePermissionV2;
  status: 200;
};

export type getAgentSessionPermissionsResponse403 = {
  data: string;
  status: 403;
};

export type getAgentSessionPermissionsResponse500 = {
  data: string;
  status: 500;
};

export type getAgentSessionPermissionsResponseSuccess =
  getAgentSessionPermissionsResponse200 & {
    headers: Headers;
  };
export type getAgentSessionPermissionsResponseError = (
  | getAgentSessionPermissionsResponse403
  | getAgentSessionPermissionsResponse500
) & {
  headers: Headers;
};

export type getAgentSessionPermissionsResponse =
  | getAgentSessionPermissionsResponseSuccess
  | getAgentSessionPermissionsResponseError;

export const getGetAgentSessionPermissionsUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/permissions`;
};

export const getAgentSessionPermissions = async (
  sessionId: string,
  options?: RequestInit
): Promise<getAgentSessionPermissionsResponse> => {
  const res = await fetch(getGetAgentSessionPermissionsUrl(sessionId), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: getAgentSessionPermissionsResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as getAgentSessionPermissionsResponse;
};

/**
 * @summary Update link, channel, or team sharing after owner authorization.
 */
export type updateAgentSessionPermissionsResponse200 = {
  data: SharePermissionV2;
  status: 200;
};

export type updateAgentSessionPermissionsResponse400 = {
  data: string;
  status: 400;
};

export type updateAgentSessionPermissionsResponse403 = {
  data: string;
  status: 403;
};

export type updateAgentSessionPermissionsResponse409 = {
  data: string;
  status: 409;
};

export type updateAgentSessionPermissionsResponse500 = {
  data: string;
  status: 500;
};

export type updateAgentSessionPermissionsResponseSuccess =
  updateAgentSessionPermissionsResponse200 & {
    headers: Headers;
  };
export type updateAgentSessionPermissionsResponseError = (
  | updateAgentSessionPermissionsResponse400
  | updateAgentSessionPermissionsResponse403
  | updateAgentSessionPermissionsResponse409
  | updateAgentSessionPermissionsResponse500
) & {
  headers: Headers;
};

export type updateAgentSessionPermissionsResponse =
  | updateAgentSessionPermissionsResponseSuccess
  | updateAgentSessionPermissionsResponseError;

export const getUpdateAgentSessionPermissionsUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/permissions`;
};

export const updateAgentSessionPermissions = async (
  sessionId: string,
  updateSharePermissionRequestV2: UpdateSharePermissionRequestV2,
  options?: RequestInit
): Promise<updateAgentSessionPermissionsResponse> => {
  const res = await fetch(getUpdateAgentSessionPermissionsUrl(sessionId), {
    ...options,
    method: 'PATCH',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(updateSharePermissionRequestV2),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: updateAgentSessionPermissionsResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as updateAgentSessionPermissionsResponse;
};

/**
 * @summary List the pull requests associated with a session the caller can view.
 */
export type listAgentSessionPullRequestsResponse200 = {
  data: SessionPullRequestsResponse;
  status: 200;
};

export type listAgentSessionPullRequestsResponse401 = {
  data: string;
  status: 401;
};

export type listAgentSessionPullRequestsResponse403 = {
  data: string;
  status: 403;
};

export type listAgentSessionPullRequestsResponse500 = {
  data: string;
  status: 500;
};

export type listAgentSessionPullRequestsResponseSuccess =
  listAgentSessionPullRequestsResponse200 & {
    headers: Headers;
  };
export type listAgentSessionPullRequestsResponseError = (
  | listAgentSessionPullRequestsResponse401
  | listAgentSessionPullRequestsResponse403
  | listAgentSessionPullRequestsResponse500
) & {
  headers: Headers;
};

export type listAgentSessionPullRequestsResponse =
  | listAgentSessionPullRequestsResponseSuccess
  | listAgentSessionPullRequestsResponseError;

export const getListAgentSessionPullRequestsUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/pull-requests`;
};

export const listAgentSessionPullRequests = async (
  sessionId: string,
  options?: RequestInit
): Promise<listAgentSessionPullRequestsResponse> => {
  const res = await fetch(getListAgentSessionPullRequestsUrl(sessionId), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: listAgentSessionPullRequestsResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as listAgentSessionPullRequestsResponse;
};

/**
 * @summary Link a pull request to a session the caller can edit.
 */
export type linkAgentSessionPullRequestResponse204 = {
  data: void;
  status: 204;
};

export type linkAgentSessionPullRequestResponse400 = {
  data: string;
  status: 400;
};

export type linkAgentSessionPullRequestResponse401 = {
  data: string;
  status: 401;
};

export type linkAgentSessionPullRequestResponse403 = {
  data: string;
  status: 403;
};

export type linkAgentSessionPullRequestResponse500 = {
  data: string;
  status: 500;
};

export type linkAgentSessionPullRequestResponseSuccess =
  linkAgentSessionPullRequestResponse204 & {
    headers: Headers;
  };
export type linkAgentSessionPullRequestResponseError = (
  | linkAgentSessionPullRequestResponse400
  | linkAgentSessionPullRequestResponse401
  | linkAgentSessionPullRequestResponse403
  | linkAgentSessionPullRequestResponse500
) & {
  headers: Headers;
};

export type linkAgentSessionPullRequestResponse =
  | linkAgentSessionPullRequestResponseSuccess
  | linkAgentSessionPullRequestResponseError;

export const getLinkAgentSessionPullRequestUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/pull-requests`;
};

export const linkAgentSessionPullRequest = async (
  sessionId: string,
  pullRequestUrl: PullRequestUrl,
  options?: RequestInit
): Promise<linkAgentSessionPullRequestResponse> => {
  const res = await fetch(getLinkAgentSessionPullRequestUrl(sessionId), {
    ...options,
    method: 'PUT',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(pullRequestUrl),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: linkAgentSessionPullRequestResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as linkAgentSessionPullRequestResponse;
};

/**
 * @summary Unlink a pull request a person linked to a session the caller can edit. The pull request
the session's agent opened stays linked.
 */
export type unlinkAgentSessionPullRequestResponse204 = {
  data: void;
  status: 204;
};

export type unlinkAgentSessionPullRequestResponse400 = {
  data: string;
  status: 400;
};

export type unlinkAgentSessionPullRequestResponse401 = {
  data: string;
  status: 401;
};

export type unlinkAgentSessionPullRequestResponse403 = {
  data: string;
  status: 403;
};

export type unlinkAgentSessionPullRequestResponse500 = {
  data: string;
  status: 500;
};

export type unlinkAgentSessionPullRequestResponseSuccess =
  unlinkAgentSessionPullRequestResponse204 & {
    headers: Headers;
  };
export type unlinkAgentSessionPullRequestResponseError = (
  | unlinkAgentSessionPullRequestResponse400
  | unlinkAgentSessionPullRequestResponse401
  | unlinkAgentSessionPullRequestResponse403
  | unlinkAgentSessionPullRequestResponse500
) & {
  headers: Headers;
};

export type unlinkAgentSessionPullRequestResponse =
  | unlinkAgentSessionPullRequestResponseSuccess
  | unlinkAgentSessionPullRequestResponseError;

export const getUnlinkAgentSessionPullRequestUrl = (
  sessionId: string,
  params: UnlinkAgentSessionPullRequestParams
) => {
  const normalizedParams = new URLSearchParams();

  Object.entries(params || {}).forEach(([key, value]) => {
    if (value !== undefined) {
      normalizedParams.append(key, value === null ? 'null' : value.toString());
    }
  });

  const stringifiedParams = normalizedParams.toString();

  return stringifiedParams.length > 0
    ? `/agent-sessions/${sessionId}/pull-requests?${stringifiedParams}`
    : `/agent-sessions/${sessionId}/pull-requests`;
};

export const unlinkAgentSessionPullRequest = async (
  sessionId: string,
  params: UnlinkAgentSessionPullRequestParams,
  options?: RequestInit
): Promise<unlinkAgentSessionPullRequestResponse> => {
  const res = await fetch(
    getUnlinkAgentSessionPullRequestUrl(sessionId, params),
    {
      ...options,
      method: 'DELETE',
    }
  );

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: unlinkAgentSessionPullRequestResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as unlinkAgentSessionPullRequestResponse;
};

/**
 * @summary The actions waiting to dispatch in this session, oldest first.
 */
export type getAgentSessionQueueResponse200 = {
  data: AgentSessionQueueResponse;
  status: 200;
};

export type getAgentSessionQueueResponse401 = {
  data: string;
  status: 401;
};

export type getAgentSessionQueueResponse403 = {
  data: string;
  status: 403;
};

export type getAgentSessionQueueResponse500 = {
  data: string;
  status: 500;
};

export type getAgentSessionQueueResponseSuccess =
  getAgentSessionQueueResponse200 & {
    headers: Headers;
  };
export type getAgentSessionQueueResponseError = (
  | getAgentSessionQueueResponse401
  | getAgentSessionQueueResponse403
  | getAgentSessionQueueResponse500
) & {
  headers: Headers;
};

export type getAgentSessionQueueResponse =
  | getAgentSessionQueueResponseSuccess
  | getAgentSessionQueueResponseError;

export const getGetAgentSessionQueueUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/queue`;
};

export const getAgentSessionQueue = async (
  sessionId: string,
  options?: RequestInit
): Promise<getAgentSessionQueueResponse> => {
  const res = await fetch(getGetAgentSessionQueueUrl(sessionId), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: getAgentSessionQueueResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as getAgentSessionQueueResponse;
};

/**
 * @summary Replace a queued prompt's text before it dispatches.
 */
export type editQueuedActionResponse204 = {
  data: void;
  status: 204;
};

export type editQueuedActionResponse401 = {
  data: string;
  status: 401;
};

export type editQueuedActionResponse403 = {
  data: string;
  status: 403;
};

export type editQueuedActionResponse404 = {
  data: string;
  status: 404;
};

export type editQueuedActionResponse422 = {
  data: string;
  status: 422;
};

export type editQueuedActionResponse500 = {
  data: string;
  status: 500;
};

export type editQueuedActionResponseSuccess = editQueuedActionResponse204 & {
  headers: Headers;
};
export type editQueuedActionResponseError = (
  | editQueuedActionResponse401
  | editQueuedActionResponse403
  | editQueuedActionResponse404
  | editQueuedActionResponse422
  | editQueuedActionResponse500
) & {
  headers: Headers;
};

export type editQueuedActionResponse =
  | editQueuedActionResponseSuccess
  | editQueuedActionResponseError;

export const getEditQueuedActionUrl = (sessionId: string, actionId: string) => {
  return `/agent-sessions/${sessionId}/queue/${actionId}`;
};

export const editQueuedAction = async (
  sessionId: string,
  actionId: string,
  editQueuedActionRequest: EditQueuedActionRequest,
  options?: RequestInit
): Promise<editQueuedActionResponse> => {
  const res = await fetch(getEditQueuedActionUrl(sessionId, actionId), {
    ...options,
    method: 'PUT',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(editQueuedActionRequest),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: editQueuedActionResponse['data'] = body ? JSON.parse(body) : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as editQueuedActionResponse;
};

/**
 * @summary Remove a queued action before it dispatches. There is no un-sending: an
action that already went out answers 404.
 */
export type removeQueuedActionResponse204 = {
  data: void;
  status: 204;
};

export type removeQueuedActionResponse401 = {
  data: string;
  status: 401;
};

export type removeQueuedActionResponse403 = {
  data: string;
  status: 403;
};

export type removeQueuedActionResponse404 = {
  data: string;
  status: 404;
};

export type removeQueuedActionResponse500 = {
  data: string;
  status: 500;
};

export type removeQueuedActionResponseSuccess =
  removeQueuedActionResponse204 & {
    headers: Headers;
  };
export type removeQueuedActionResponseError = (
  | removeQueuedActionResponse401
  | removeQueuedActionResponse403
  | removeQueuedActionResponse404
  | removeQueuedActionResponse500
) & {
  headers: Headers;
};

export type removeQueuedActionResponse =
  | removeQueuedActionResponseSuccess
  | removeQueuedActionResponseError;

export const getRemoveQueuedActionUrl = (
  sessionId: string,
  actionId: string
) => {
  return `/agent-sessions/${sessionId}/queue/${actionId}`;
};

export const removeQueuedAction = async (
  sessionId: string,
  actionId: string,
  options?: RequestInit
): Promise<removeQueuedActionResponse> => {
  const res = await fetch(getRemoveQueuedActionUrl(sessionId, actionId), {
    ...options,
    method: 'DELETE',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: removeQueuedActionResponse['data'] = body ? JSON.parse(body) : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as removeQueuedActionResponse;
};

/**
 * @summary Run a queued action next. Moves it ahead of the rest of the queue and
cancels the turn in flight, so this entry dispatches when that turn ends.
 */
export type steerQueuedActionResponse204 = {
  data: void;
  status: 204;
};

export type steerQueuedActionResponse401 = {
  data: string;
  status: 401;
};

export type steerQueuedActionResponse403 = {
  data: string;
  status: 403;
};

export type steerQueuedActionResponse404 = {
  data: string;
  status: 404;
};

export type steerQueuedActionResponse500 = {
  data: string;
  status: 500;
};

export type steerQueuedActionResponseSuccess = steerQueuedActionResponse204 & {
  headers: Headers;
};
export type steerQueuedActionResponseError = (
  | steerQueuedActionResponse401
  | steerQueuedActionResponse403
  | steerQueuedActionResponse404
  | steerQueuedActionResponse500
) & {
  headers: Headers;
};

export type steerQueuedActionResponse =
  | steerQueuedActionResponseSuccess
  | steerQueuedActionResponseError;

export const getSteerQueuedActionUrl = (
  sessionId: string,
  actionId: string
) => {
  return `/agent-sessions/${sessionId}/queue/${actionId}/steer`;
};

export const steerQueuedAction = async (
  sessionId: string,
  actionId: string,
  options?: RequestInit
): Promise<steerQueuedActionResponse> => {
  const res = await fetch(getSteerQueuedActionUrl(sessionId, actionId), {
    ...options,
    method: 'POST',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: steerQueuedActionResponse['data'] = body ? JSON.parse(body) : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as steerQueuedActionResponse;
};

/**
 * @summary Persist a review without keeping the agent turn blocked.
 */
export type createSessionReviewResponse200 = {
  data: ReviewRecord;
  status: 200;
};

export type createSessionReviewResponse400 = {
  data: void;
  status: 400;
};

export type createSessionReviewResponse403 = {
  data: void;
  status: 403;
};

export type createSessionReviewResponseSuccess =
  createSessionReviewResponse200 & {
    headers: Headers;
  };
export type createSessionReviewResponseError = (
  | createSessionReviewResponse400
  | createSessionReviewResponse403
) & {
  headers: Headers;
};

export type createSessionReviewResponse =
  | createSessionReviewResponseSuccess
  | createSessionReviewResponseError;

export const getCreateSessionReviewUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/reviews`;
};

export const createSessionReview = async (
  sessionId: string,
  createReview: CreateReview,
  options?: RequestInit
): Promise<createSessionReviewResponse> => {
  const res = await fetch(getCreateSessionReviewUrl(sessionId), {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(createReview),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: createSessionReviewResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as createSessionReviewResponse;
};

/**
 * @summary Read a persisted interactive block.
 */
export type getSessionReviewResponse200 = {
  data: ReviewRecord;
  status: 200;
};

export type getSessionReviewResponse403 = {
  data: void;
  status: 403;
};

export type getSessionReviewResponse404 = {
  data: void;
  status: 404;
};

export type getSessionReviewResponseSuccess = getSessionReviewResponse200 & {
  headers: Headers;
};
export type getSessionReviewResponseError = (
  | getSessionReviewResponse403
  | getSessionReviewResponse404
) & {
  headers: Headers;
};

export type getSessionReviewResponse =
  | getSessionReviewResponseSuccess
  | getSessionReviewResponseError;

export const getGetSessionReviewUrl = (sessionId: string, reviewId: string) => {
  return `/agent-sessions/${sessionId}/reviews/${reviewId}`;
};

export const getSessionReview = async (
  sessionId: string,
  reviewId: string,
  options?: RequestInit
): Promise<getSessionReviewResponse> => {
  const res = await fetch(getGetSessionReviewUrl(sessionId, reviewId), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: getSessionReviewResponse['data'] = body ? JSON.parse(body) : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as getSessionReviewResponse;
};

/**
 * @summary Save edits or atomically claim the exact draft revision the user submitted.
 */
export type decideSessionReviewResponse200 = {
  data: ReviewRecord;
  status: 200;
};

export type decideSessionReviewResponse403 = {
  data: void;
  status: 403;
};

export type decideSessionReviewResponse409 = {
  data: void;
  status: 409;
};

export type decideSessionReviewResponseSuccess =
  decideSessionReviewResponse200 & {
    headers: Headers;
  };
export type decideSessionReviewResponseError = (
  | decideSessionReviewResponse403
  | decideSessionReviewResponse409
) & {
  headers: Headers;
};

export type decideSessionReviewResponse =
  | decideSessionReviewResponseSuccess
  | decideSessionReviewResponseError;

export const getDecideSessionReviewUrl = (
  sessionId: string,
  reviewId: string
) => {
  return `/agent-sessions/${sessionId}/reviews/${reviewId}`;
};

export const decideSessionReview = async (
  sessionId: string,
  reviewId: string,
  reviewDecision: ReviewDecision,
  options?: RequestInit
): Promise<decideSessionReviewResponse> => {
  const res = await fetch(getDecideSessionReviewUrl(sessionId, reviewId), {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(reviewDecision),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: decideSessionReviewResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as decideSessionReviewResponse;
};

/**
 * @summary Resize this session's sandbox and remember the size as the owner's default.
 */
export type putAgentSessionSandboxSizeResponse200 = {
  data: SandboxSizeBody;
  status: 200;
};

export type putAgentSessionSandboxSizeResponse401 = {
  data: string;
  status: 401;
};

export type putAgentSessionSandboxSizeResponse403 = {
  data: string;
  status: 403;
};

export type putAgentSessionSandboxSizeResponse500 = {
  data: string;
  status: 500;
};

export type putAgentSessionSandboxSizeResponseSuccess =
  putAgentSessionSandboxSizeResponse200 & {
    headers: Headers;
  };
export type putAgentSessionSandboxSizeResponseError = (
  | putAgentSessionSandboxSizeResponse401
  | putAgentSessionSandboxSizeResponse403
  | putAgentSessionSandboxSizeResponse500
) & {
  headers: Headers;
};

export type putAgentSessionSandboxSizeResponse =
  | putAgentSessionSandboxSizeResponseSuccess
  | putAgentSessionSandboxSizeResponseError;

export const getPutAgentSessionSandboxSizeUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/sandbox-size`;
};

export const putAgentSessionSandboxSize = async (
  sessionId: string,
  sandboxSizeBody: SandboxSizeBody,
  options?: RequestInit
): Promise<putAgentSessionSandboxSizeResponse> => {
  const res = await fetch(getPutAgentSessionSandboxSizeUrl(sessionId), {
    ...options,
    method: 'PUT',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(sandboxSizeBody),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: putAgentSessionSandboxSizeResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as putAgentSessionSandboxSizeResponse;
};

/**
 * @summary Answer a tool call the agent made in a turn somebody other than the
session's owner prompted. Approve and deny are the owner's; cancel is
anyone's with edit access.
 */
export type answerAgentSessionToolApprovalResponse200 = {
  data: AnswerToolApprovalResponse;
  status: 200;
};

export type answerAgentSessionToolApprovalResponse401 = {
  data: string;
  status: 401;
};

export type answerAgentSessionToolApprovalResponse403 = {
  data: string;
  status: 403;
};

export type answerAgentSessionToolApprovalResponse404 = {
  data: string;
  status: 404;
};

export type answerAgentSessionToolApprovalResponse409 = {
  data: string;
  status: 409;
};

export type answerAgentSessionToolApprovalResponse422 = {
  data: string;
  status: 422;
};

export type answerAgentSessionToolApprovalResponse500 = {
  data: string;
  status: 500;
};

export type answerAgentSessionToolApprovalResponseSuccess =
  answerAgentSessionToolApprovalResponse200 & {
    headers: Headers;
  };
export type answerAgentSessionToolApprovalResponseError = (
  | answerAgentSessionToolApprovalResponse401
  | answerAgentSessionToolApprovalResponse403
  | answerAgentSessionToolApprovalResponse404
  | answerAgentSessionToolApprovalResponse409
  | answerAgentSessionToolApprovalResponse422
  | answerAgentSessionToolApprovalResponse500
) & {
  headers: Headers;
};

export type answerAgentSessionToolApprovalResponse =
  | answerAgentSessionToolApprovalResponseSuccess
  | answerAgentSessionToolApprovalResponseError;

export const getAnswerAgentSessionToolApprovalUrl = (
  sessionId: string,
  approvalId: string
) => {
  return `/agent-sessions/${sessionId}/tool-approvals/${approvalId}`;
};

export const answerAgentSessionToolApproval = async (
  sessionId: string,
  approvalId: string,
  answerToolApprovalRequest: AnswerToolApprovalRequest,
  options?: RequestInit
): Promise<answerAgentSessionToolApprovalResponse> => {
  const res = await fetch(
    getAnswerAgentSessionToolApprovalUrl(sessionId, approvalId),
    {
      ...options,
      method: 'POST',
      headers: { 'Content-Type': 'application/json', ...options?.headers },
      body: JSON.stringify(answerToolApprovalRequest),
    }
  );

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: answerAgentSessionToolApprovalResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as answerAgentSessionToolApprovalResponse;
};

/**
 * @summary Present a view in the session: a review with nothing saved.
 */
export type presentSessionViewResponse204 = {
  data: void;
  status: 204;
};

export type presentSessionViewResponse400 = {
  data: void;
  status: 400;
};

export type presentSessionViewResponse403 = {
  data: void;
  status: 403;
};

export type presentSessionViewResponseSuccess =
  presentSessionViewResponse204 & {
    headers: Headers;
  };
export type presentSessionViewResponseError = (
  | presentSessionViewResponse400
  | presentSessionViewResponse403
) & {
  headers: Headers;
};

export type presentSessionViewResponse =
  | presentSessionViewResponseSuccess
  | presentSessionViewResponseError;

export const getPresentSessionViewUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/views`;
};

export const presentSessionView = async (
  sessionId: string,
  presentView: PresentView,
  options?: RequestInit
): Promise<presentSessionViewResponse> => {
  const res = await fetch(getPresentSessionViewUrl(sessionId), {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(presentView),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: presentSessionViewResponse['data'] = body ? JSON.parse(body) : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as presentSessionViewResponse;
};

/**
 * @summary Register a session as the caller's work. Requires edit access. Repeating returns the active
registration. Registering does not share the session: viewers who cannot open it do not see
it, so share it too.
 */
export type registerAgentSessionWorkResponse200 = {
  data: WorkRegistrationResponse;
  status: 200;
};

export type registerAgentSessionWorkResponse401 = {
  data: string;
  status: 401;
};

export type registerAgentSessionWorkResponse403 = {
  data: string;
  status: 403;
};

export type registerAgentSessionWorkResponse409 = {
  data: string;
  status: 409;
};

export type registerAgentSessionWorkResponse500 = {
  data: string;
  status: 500;
};

export type registerAgentSessionWorkResponseSuccess =
  registerAgentSessionWorkResponse200 & {
    headers: Headers;
  };
export type registerAgentSessionWorkResponseError = (
  | registerAgentSessionWorkResponse401
  | registerAgentSessionWorkResponse403
  | registerAgentSessionWorkResponse409
  | registerAgentSessionWorkResponse500
) & {
  headers: Headers;
};

export type registerAgentSessionWorkResponse =
  | registerAgentSessionWorkResponseSuccess
  | registerAgentSessionWorkResponseError;

export const getRegisterAgentSessionWorkUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/work-registration`;
};

export const registerAgentSessionWork = async (
  sessionId: string,
  options?: RequestInit
): Promise<registerAgentSessionWorkResponse> => {
  const res = await fetch(getRegisterAgentSessionWorkUrl(sessionId), {
    ...options,
    method: 'PUT',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: registerAgentSessionWorkResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as registerAgentSessionWorkResponse;
};

/**
 * @summary End the caller's own registration of a session. Repeating does nothing. It touches only the
caller's own row, so it needs no access to the session: losing access must not strand it.
 */
export type unregisterAgentSessionWorkResponse204 = {
  data: void;
  status: 204;
};

export type unregisterAgentSessionWorkResponse401 = {
  data: string;
  status: 401;
};

export type unregisterAgentSessionWorkResponse500 = {
  data: string;
  status: 500;
};

export type unregisterAgentSessionWorkResponseSuccess =
  unregisterAgentSessionWorkResponse204 & {
    headers: Headers;
  };
export type unregisterAgentSessionWorkResponseError = (
  | unregisterAgentSessionWorkResponse401
  | unregisterAgentSessionWorkResponse500
) & {
  headers: Headers;
};

export type unregisterAgentSessionWorkResponse =
  | unregisterAgentSessionWorkResponseSuccess
  | unregisterAgentSessionWorkResponseError;

export const getUnregisterAgentSessionWorkUrl = (sessionId: string) => {
  return `/agent-sessions/${sessionId}/work-registration`;
};

export const unregisterAgentSessionWork = async (
  sessionId: string,
  options?: RequestInit
): Promise<unregisterAgentSessionWorkResponse> => {
  const res = await fetch(getUnregisterAgentSessionWorkUrl(sessionId), {
    ...options,
    method: 'DELETE',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: unregisterAgentSessionWorkResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as unregisterAgentSessionWorkResponse;
};

/**
 * @summary List the caller's active registrations of sessions they can still view, newest first.
 */
export type listAgentWorkRegistrationsResponse200 = {
  data: WorkRegistrationResponse[];
  status: 200;
};

export type listAgentWorkRegistrationsResponse401 = {
  data: string;
  status: 401;
};

export type listAgentWorkRegistrationsResponse500 = {
  data: string;
  status: 500;
};

export type listAgentWorkRegistrationsResponseSuccess =
  listAgentWorkRegistrationsResponse200 & {
    headers: Headers;
  };
export type listAgentWorkRegistrationsResponseError = (
  | listAgentWorkRegistrationsResponse401
  | listAgentWorkRegistrationsResponse500
) & {
  headers: Headers;
};

export type listAgentWorkRegistrationsResponse =
  | listAgentWorkRegistrationsResponseSuccess
  | listAgentWorkRegistrationsResponseError;

export const getListAgentWorkRegistrationsUrl = () => {
  return `/agent-work-registrations`;
};

export const listAgentWorkRegistrations = async (
  options?: RequestInit
): Promise<listAgentWorkRegistrationsResponse> => {
  const res = await fetch(getListAgentWorkRegistrationsUrl(), {
    ...options,
    method: 'GET',
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: listAgentWorkRegistrationsResponse['data'] = body
    ? JSON.parse(body)
    : {};
  return {
    data,
    status: res.status,
    headers: res.headers,
  } as listAgentWorkRegistrationsResponse;
};

/**
 * @summary Classify a draft for the authenticated user.
 */
export type classifyResponse200 = {
  data: ClassifyInputResponse;
  status: 200;
};

export type classifyResponse400 = {
  data: void;
  status: 400;
};

export type classifyResponse401 = {
  data: void;
  status: 401;
};

export type classifyResponse402 = {
  data: void;
  status: 402;
};

export type classifyResponse503 = {
  data: void;
  status: 503;
};

export type classifyResponseSuccess = classifyResponse200 & {
  headers: Headers;
};
export type classifyResponseError = (
  | classifyResponse400
  | classifyResponse401
  | classifyResponse402
  | classifyResponse503
) & {
  headers: Headers;
};

export type classifyResponse = classifyResponseSuccess | classifyResponseError;

export const getClassifyUrl = () => {
  return `/universal_input/classify`;
};

export const classify = async (
  classifyInputRequest: ClassifyInputRequest,
  options?: RequestInit
): Promise<classifyResponse> => {
  const res = await fetch(getClassifyUrl(), {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(classifyInputRequest),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: classifyResponse['data'] = body ? JSON.parse(body) : {};
  return { data, status: res.status, headers: res.headers } as classifyResponse;
};

/**
 * @summary Extract editable fields for the authenticated user.
 */
export type extractResponse200 = {
  data: ExtractInputResponse;
  status: 200;
};

export type extractResponse400 = {
  data: void;
  status: 400;
};

export type extractResponse401 = {
  data: void;
  status: 401;
};

export type extractResponse402 = {
  data: void;
  status: 402;
};

export type extractResponse503 = {
  data: void;
  status: 503;
};

export type extractResponseSuccess = extractResponse200 & {
  headers: Headers;
};
export type extractResponseError = (
  | extractResponse400
  | extractResponse401
  | extractResponse402
  | extractResponse503
) & {
  headers: Headers;
};

export type extractResponse = extractResponseSuccess | extractResponseError;

export const getExtractUrl = () => {
  return `/universal_input/extract`;
};

export const extract = async (
  extractInputRequest: ExtractInputRequest,
  options?: RequestInit
): Promise<extractResponse> => {
  const res = await fetch(getExtractUrl(), {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(extractInputRequest),
  });

  const body = [204, 205, 304].includes(res.status) ? null : await res.text();

  const data: extractResponse['data'] = body ? JSON.parse(body) : {};
  return { data, status: res.status, headers: res.headers } as extractResponse;
};