import { z } from "zod";
import { badRequest, forbidden, HttpError, notFoundError } from "../errors";
import { branchSha, listRefs } from "../git/refs";
import { withStore } from "../git/store";
import type { GitStore } from "../git/store";
import { commitFileChanges } from "../git/web-commit";
import { limitBrowse, limitWrite } from "../limits";
import { MAX_POINTER_BYTES, parseLfsPointer } from "../lfs/pointer";
import { assertEditableChanges } from "./write-guard";
import { openPull } from "../pull-create";
import { publicUrl } from "../events/emit";
import { canWrite, editorSessionFromRequest, needsPullRequest } from "./session";
import type { EditorSession } from "./session";
import { editorFrameResponse } from "./frame";
export const EDITOR_API_PREFIX = "/api/editor/";
export const EDITOR_FRAME_PATH = "/editor-frame";
const MAX_TREE_ENTRIES = 5000;
const MAX_BLOB_BYTES = 1024 * 1024;
const MAX_CHANGES = 100;
const MAX_COMMIT_BYTES = 5 * 1024 * 1024;
const MAX_BODY_BYTES = MAX_COMMIT_BYTES * 2;
const MAX_PATCH_BRANCH_TRIES = 50;
const BINARY_SNIFF = 8000;
const decoder = new TextDecoder();
const encoder = new TextEncoder();
const CORS_HEADERS = {
"access-control-allow-origin": "*",
"access-control-allow-methods": "GET, POST, OPTIONS",
"access-control-allow-headers": "authorization, content-type",
"access-control-max-age": "600",
vary: "origin",
};
function json(body: unknown, status = 200): Response {
return Response.json(body, { status, headers: { ...CORS_HEADERS, "cache-control": "no-store" } });
}