import { validAnnotationWriteId } from './annotations-sync.ts'; // HTTP layer for Bun.serve. // // Designed for extension — Phase 3.6 adds /ui/:slug + /_bun_hmr by appending to // the route table without rewriting this module. The `fetch` export is the // top-level fall-through for paths Bun's `routes` field doesn't cover. import { createHash } from 'node:crypto'; import { existsSync, readFileSync, realpathSync, unlinkSync, watch } from 'node:fs'; import { basename, dirname, join, posix, relative, resolve, sep } from 'node:path'; // Ownership mutations live with the CLI on purpose — see /_api/sync/ownership. import { adoptToHub, detachToRepo, ownershipState } from '../../cli/lib/design-ownership.mjs'; import { cancelSignin, getClaudeAuthStatus, getInstallState, isSigninInFlight, startInstall, startSignin, } from './acp/login-state.ts'; import { probeAcpAvailabilityAuthed } from './acp/probe.ts'; import { activitySnapshot, runningChats } from './acp/running.ts'; import { chatTranscriptSeq, deleteChat, listChats, readChatMessages, writeChatMeta, } from './acp/transcript.ts'; import { type Api, ASSET_MAX_BYTES, ASSET_MAX_VIDEO_BYTES } from './api.ts'; import { ImportAssetError, importSvg, SVG_MAX_BYTES } from './bin/_import-asset.mjs'; import { ImportBrandError, importBrand } from './bin/_import-brand.mjs'; import { buildCanvasModule } from './canvas-build.ts'; import { buildCanvasSandboxed, buildStats } from './canvas-build-sandbox.ts'; import { canvasLibPath } from './canvas-lib-resolver.ts'; import { TranspileError } from './canvas-pipeline.ts'; import { createCloudEndpoints } from './cloud/endpoints.ts'; import type { AiActivity } from './collab/ai-activity.ts'; import type { Context } from './context.ts'; import { reloadConfig } from './context.ts'; import { buildDebugBundle } from './debug-bundle.ts'; import { probeSetupReadiness } from './design-setup-readiness.ts'; import { isScopeValidForFormat, scopeRefusalMessage } from './exporters/format-scopes.ts'; import { type Format, isFormat, isScope, type Scope } from './exporters/index.ts'; import { type ExportJobQueue, ExportQueueFullError } from './exporters/jobs.ts'; import type { ActiveJsonShape } from './exporters/scope.ts'; import { createFigmaEndpoints } from './figma/endpoints.ts'; import { generatedClipAnalysis } from './footage/schema.ts'; import { createFootageStore, FOOTAGE_MAX_BYTES } from './footage-store.ts'; import { type AudioMatch, type Candidate, rankMatches, sanitizeReuseText, } from './generation/audio-library.ts'; import { localizeGenAsset } from './generation/download.ts'; import { downloadGemmaModel, ffmpegAvailable, getOllamaModel, listGemmaModels, listScoutModels, mlxSetup, mlxVlmAvailable, OLLAMA_RECOMMENDED_MODEL, ollamaSetupOptions, ollamaStatus, pullOllamaModel, } from './generation/gemma-models.ts'; import { type GenerationJobQueue, GenerationQueueFullError } from './generation/jobs.ts'; import { configuredProviders, deleteProviderKey, getProviderKey, isConfigured, setProviderKey, } from './generation/keys.ts'; import { isKeyframeEngine, isTranscriptionProvider, readKeyframeEngine, readTranscriptionProvider, writeKeyframeEngine, writeTranscriptionProvider, } from './generation/prefs.ts'; import { createAdapter, getProviderDescriptor, hasProvider, listProviders, } from './generation/registry.ts'; import { validateGenRequest } from './generation/types.ts'; import { downloadWhisperModel, getWhisperModel, listWhisperModels, removeWhisperModel, resolveAutoEngine, whisperSetup, } from './generation/whisper-models.ts'; import { refuseCheckoutRewrite } from './git/accepted-guard.ts'; import { createGitEndpoints } from './git/endpoints.ts'; import { gitShowFile } from './git/service.ts'; import { createGitHubEndpoints } from './github/endpoints.ts'; import type { InspectRegistry } from './inspect.ts'; import { canvasSlug, writeLocator } from './locator.ts'; import { prepareManagedProject } from './managed-projects.ts'; import { BIN_DIR, DEV_SERVER_ROOT, MEDIA_DIR, STICKERS_DIR } from './paths.ts'; import { createPhotoStore, PHOTO_EDIT_MAX_BYTES } from './photo-store.ts'; import { probeReadiness } from './readiness.ts'; import { getRuntimeBundle, packageForSlug } from './runtime-bundle.ts'; import { currentSession } from './session-scope.ts'; import { sanitizeForLog } from './sync/cell-pairing.ts'; import { linkHub } from './sync/hub-link.ts'; import { isHubReadOnly } from './sync/hubs-config.ts'; import { isFirstAnchorMode, readSyncSettings, writeSyncSettings } from './sync/settings.ts'; import { listTrash, pruneTrash, restoreFromTrash } from './sync/trash.ts'; import { signInToWorkspace, workspaceDisclosure } from './sync/workspace-signin.ts'; import { readUiPrefs, type UiPrefs, writeUiPrefs } from './ui-prefs.ts'; import { loadWhatsNew, resolveMaudeVersion } from './whats-new.ts'; import { isWorkspaceMode, resolveRenderLane } from './workspace-mode.ts'; import { isLoopbackHost } from './ws.ts'; // Real disk install root — never the virtual `/$bunfs/root` of compiled bins. // See paths.ts for the resolution logic + Phase 19.1 / v0.18.1 rationale. const HERE = DEV_SERVER_ROOT; export const MIME: Record = { '.html': 'text/html; charset=utf-8', '.css': 'text/css; charset=utf-8', '.js': 'application/javascript; charset=utf-8', '.mjs': 'application/javascript; charset=utf-8', '.jsx': 'text/plain; charset=utf-8', '.ts': 'text/plain; charset=utf-8', '.tsx': 'text/plain; charset=utf-8', '.json': 'application/json; charset=utf-8', '.md': 'text/markdown; charset=utf-8', '.svg': 'image/svg+xml', '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.gif': 'image/gif', '.webp': 'image/webp', '.ico': 'image/x-icon', '.woff': 'font/woff', '.woff2': 'font/woff2', '.ttf': 'font/ttf', '.otf': 'font/otf', // DDR-148 — video/audio media referenced by a video-comp `