{"version":3,"file":"settingsApi-B3dt1OLW.mjs","names":[],"sources":["../src/constants/settings.ts","../src/types/apiRoutes.ts","../src/services/settingsWire/index.ts","../src/services/settings/index.ts","../src/services/settingsApi/index.ts"],"sourcesContent":["export const KEY_SEPARATOR = '.';\n\n/** The repeatable query parameter naming which keys a read is about. */\nexport const KEY_QUERY_PARAM = 'key';\n\nexport const SELECTION_KEYS = {\n  preset: ['selection', 'preset'],\n  domains: ['selection', 'domains'],\n  profile: ['selection', 'profile'],\n} as const;\n","import { apiResponse, defineApiRoutes } from '@agimon-ai/po-core/web';\n\nimport { KEY_QUERY_PARAM } from '../constants/settings';\nimport type {\n  RepositorySettingsView,\n  SettingsConfigView,\n  SettingsImagesView,\n  SettingsPresetsView,\n  SettingsRepository,\n} from './settings';\n\n/**\n * This package's routes, as data.\n *\n * No scope and no base path. The build reads both off\n * `src/extensions/(backend)/api/settings/`, so the mount is stated once, by the\n * folder that creates it. `settings` is the host's own API: it answers at\n * `/api/settings` and `/api/workspaces/<id>/settings`, beside `/plugins` rather\n * than under it, and the client knows that from the base path alone.\n *\n * This is the one file the mount's dispatcher and, once the client crosses the\n * package boundary, the cockpit both read, so a path cannot move on one side\n * alone.\n */\nexport const routes = defineApiRoutes({\n  /** The mount itself: the selected keys and the hash of each file they came from. */\n  config: {\n    method: 'GET',\n    path: '/',\n    /** Repeatable. The page also sends `repoRoot`, which the mount ignores: it serves one repository. */\n    query: [KEY_QUERY_PARAM],\n    response: apiResponse<SettingsConfigView>(),\n  },\n  value: {\n    method: 'PUT',\n    path: '/value',\n    response: apiResponse<SettingsConfigView>(),\n  },\n  repositories: {\n    method: 'GET',\n    path: '/repositories',\n    response: apiResponse<{ repositories: readonly SettingsRepository[] }>(),\n  },\n  /** The workspace this mount was bound to; a global mount has none and answers 404. */\n  repository: {\n    method: 'GET',\n    path: '/repository',\n    response: apiResponse<RepositorySettingsView>(),\n  },\n  selection: {\n    method: 'PUT',\n    path: '/repository/selection',\n    response: apiResponse<RepositorySettingsView>(),\n  },\n  /** Pi's own image limits, served by the global mount only. */\n  images: {\n    method: 'GET',\n    path: '/images',\n    response: apiResponse<SettingsImagesView>(),\n  },\n  /** The same path as `images`; the method is the whole of the difference. */\n  saveImages: {\n    method: 'PUT',\n    path: '/images',\n    response: apiResponse<SettingsImagesView>(),\n  },\n  /** Effective host or workspace presets and the hashes needed to edit them. */\n  presets: {\n    method: 'GET',\n    path: '/presets',\n    response: apiResponse<SettingsPresetsView>(),\n  },\n  /** Sets `defaultPreset`; the method is the whole of the difference. */\n  savePresets: {\n    method: 'PUT',\n    path: '/presets',\n    response: apiResponse<SettingsPresetsView>(),\n  },\n  createPreset: {\n    method: 'PUT',\n    path: '/presets/create',\n    response: apiResponse<SettingsPresetsView>(),\n  },\n  renamePreset: {\n    method: 'PUT',\n    path: '/presets/rename',\n    response: apiResponse<SettingsPresetsView>(),\n  },\n  deletePreset: {\n    method: 'PUT',\n    path: '/presets/delete',\n    response: apiResponse<SettingsPresetsView>(),\n  },\n  addPresetLayer: {\n    method: 'PUT',\n    path: '/presets/add-layer',\n    response: apiResponse<SettingsPresetsView>(),\n  },\n  removePresetLayer: {\n    method: 'PUT',\n    path: '/presets/remove-layer',\n    response: apiResponse<SettingsPresetsView>(),\n  },\n});\n","/** Host settings wire serialization. */\n\nimport type {\n  RepositorySelectionValue,\n  RepositorySettingsView,\n  SettingsConfigView,\n  SettingsFileScope,\n  SettingsWireConfigView,\n  SettingsWireOrigin,\n} from '../../types/settings';\n\n/** Host settings wire serialization. */\nexport type SettingsWireValue<T extends string> = T;\n\n/** A repository view as the wire sends it, with each selection origin in wire spelling. */\nexport type RepositorySettingsWireView = Omit<RepositorySettingsView, 'selection'> & {\n  selection: {\n    [K in keyof RepositorySettingsView['selection']]: Omit<RepositorySettingsView['selection'][K], 'origin'> & {\n      origin: SettingsWireOrigin;\n    };\n  };\n};\n\n/** The host settings API uses host scope in both directions. */\nexport function settingsScopeToWire<T extends string>(value: T): SettingsWireValue<T> {\n  return value;\n}\n\n/** Only host and repository name files on this host. */\nexport function settingsScopeFromWire(value: unknown): SettingsFileScope | undefined {\n  return value === 'host' || value === 'repository' ? value : undefined;\n}\n\n/** Host settings wire serialization. */\nexport function settingsConfigViewToWire(view: SettingsConfigView): SettingsWireConfigView {\n  const values: SettingsWireConfigView['values'] = {};\n  for (const [key, entry] of Object.entries(view.values)) {\n    values[key] = {\n      ...(entry.value === undefined ? {} : { value: entry.value }),\n      origin: settingsScopeToWire(entry.origin),\n      scope: settingsScopeToWire(entry.scope),\n    };\n  }\n  return {\n    repoRoot: view.repoRoot,\n    values,\n    hashes: {\n      host: view.hashes.host,\n      repository: view.hashes.repository,\n    },\n  };\n}\n\nfunction selectionToWire<T>(value: RepositorySelectionValue<T>): Omit<RepositorySelectionValue<T>, 'origin'> & {\n  origin: SettingsWireOrigin;\n} {\n  return { ...value, origin: settingsScopeToWire(value.origin) };\n}\n\n/** The repository routes' response body, with selection origins in wire spelling. */\nexport function repositorySettingsViewToWire(view: RepositorySettingsView): RepositorySettingsWireView {\n  return {\n    ...view,\n    selection: {\n      preset: selectionToWire(view.selection.preset),\n      domains: selectionToWire(view.selection.domains),\n      profile: selectionToWire(view.selection.profile),\n    },\n  };\n}\n","import type { PoApiContext } from '@agimon-ai/po-core/packageApi';\nimport type { FileSystem } from '@agimon-ai/po-core/platform';\n\nimport { KEY_SEPARATOR, SELECTION_KEYS } from '../../constants/settings';\nimport type { PoConfigLayers } from '../../types/config';\nimport type {\n  RepositoryCatalogOption,\n  RepositorySelectionChanges,\n  RepositorySelectionWriteRequest,\n  RepositorySettingsView,\n  SettingsConfigView,\n  SettingsRepository,\n  SettingsFileScope,\n  SettingsOrigin,\n  SettingsValueView,\n  SettingsBatchWriteRequest,\n} from '../../types/settings';\nimport { globalPoConfigPath, readPoConfigLayers, repositoryPoConfigPath, type ConfigEnvironment } from '../config';\nimport { configScopeOf } from '../configPolicy';\nimport { defaultDomainsForPreset, loadDomainsAsync } from '../domains';\nimport { readPresetsConfig } from '../presetConfig';\nimport { loadProfilesAsync } from '../profiles';\nimport { settingsScopeFromWire } from '../settingsWire';\n\ntype SelectionKey = keyof typeof SELECTION_KEYS;\ntype IoContext = Parameters<FileSystem['readTextFile']>[1];\n\n/** The mount's admitted home and environment, so no reader falls back to the host's. */\nfunction readOptions(homeDirectory: string | undefined, environment: ConfigEnvironment) {\n  return { ...(homeDirectory === undefined ? {} : { homeDirectory }), environment };\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n  return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nexport function describe(error: unknown): string {\n  return error instanceof Error ? error.message : String(error);\n}\n\n/** The display form of a config value; a record has no single-line form, so it has none. */\nexport function displayValue(value: unknown): string | undefined {\n  if (typeof value === 'string') return value;\n  if (typeof value === 'number' || typeof value === 'boolean') return String(value);\n  if (Array.isArray(value)) return value.map((entry) => displayValue(entry) ?? '').join(', ');\n  return undefined;\n}\n\nexport function pathFor(\n  scope: SettingsFileScope,\n  repoRoot: string,\n  homeDirectory: string | undefined,\n  environment: ConfigEnvironment,\n): string {\n  return scope === 'repository' ? repositoryPoConfigPath(repoRoot) : globalPoConfigPath(homeDirectory, environment);\n}\n\nexport function parseWrite(body: unknown): SettingsBatchWriteRequest | undefined {\n  if (!isRecord(body)) return undefined;\n  const { repoRoot, expectedHash } = body;\n  const scope = settingsScopeFromWire(body.scope);\n  if (typeof repoRoot !== 'string' || scope === undefined) return undefined;\n  if (scope === 'repository' && repoRoot === '') return undefined;\n  if (typeof expectedHash !== 'string') return undefined;\n  const edits = body.edits === undefined ? [{ keyPath: body.keyPath, value: body.value }] : body.edits;\n  if (!Array.isArray(edits) || edits.length === 0 || edits.length > 100) return undefined;\n  const validated: Array<SettingsBatchWriteRequest['edits'][number]> = [];\n  for (const edit of edits) {\n    if (!isRecord(edit)) return undefined;\n    const { keyPath, value } = edit;\n    if (!Array.isArray(keyPath) || keyPath.length === 0 || keyPath.some((part) => typeof part !== 'string'))\n      return undefined;\n    if (value !== null && typeof value !== 'string' && (typeof value !== 'number' || !Number.isFinite(value)))\n      return undefined;\n    validated.push({ keyPath: keyPath as string[], value });\n  }\n  return { repoRoot, scope, expectedHash, edits: validated };\n}\n\nexport function configuredSelectionValue<T>(\n  layers: PoConfigLayers,\n  key: SelectionKey,\n  effective: T | undefined,\n): { effective?: T; repository?: T; origin: SettingsOrigin } {\n  const origin = layers.originOf(SELECTION_KEYS[key]);\n  return {\n    ...(effective === undefined ? {} : { effective }),\n    ...(origin === 'repository' && effective !== undefined ? { repository: effective } : {}),\n    origin,\n  };\n}\n\nexport async function repositorySettingsView(\n  fs: FileSystem,\n  repository: SettingsRepository,\n  homeDirectory: string | undefined,\n  environment: ConfigEnvironment,\n  io: IoContext,\n): Promise<RepositorySettingsView> {\n  const repoRoot = repository.path;\n  const options = readOptions(homeDirectory, environment);\n  const layers = await readPoConfigLayers(fs, repoRoot, io, options);\n  const presetsConfig = await readPresetsConfig(fs, repoRoot, io, options);\n  const domains = await loadDomainsAsync(fs, repoRoot, io, homeDirectory, environment);\n  const profiles = await loadProfilesAsync(fs, repoRoot, io, homeDirectory, environment);\n  const configured = layers.effective.selection;\n  const effectivePreset = configured?.preset ?? presetsConfig.defaultPreset;\n  const effectiveDomains = configured?.domains ?? defaultDomainsForPreset(effectivePreset, {}, domains.defaultDomains);\n  const presets: RepositoryCatalogOption[] = Object.entries(presetsConfig.preset)\n    .map(([name, definition]) => ({ name, description: definition.description, layers: definition.layers }))\n    .sort((left, right) => left.name.localeCompare(right.name));\n  const domainOptions: RepositoryCatalogOption[] = [\n    ...Object.entries(domains.domains).map(([name, definition]) => ({\n      name,\n      ...(definition.description ? { description: definition.description } : {}),\n    })),\n    ...Object.entries(domains.aliases).map(([name, expandsTo]) => ({\n      name,\n      description: `Alias for ${expandsTo.join(', ') || 'no domains'}.`,\n      expandsTo,\n    })),\n  ].sort((left, right) => left.name.localeCompare(right.name));\n\n  return {\n    repository,\n    hash: layers.repositoryFile.hash,\n    catalogs: {\n      presets,\n      domains: domainOptions,\n      profiles: profiles.map((profile) => ({ name: profile.name })),\n    },\n    selection: {\n      preset: configuredSelectionValue(layers, 'preset', effectivePreset),\n      domains: configuredSelectionValue(layers, 'domains', effectiveDomains),\n      profile: configuredSelectionValue(layers, 'profile', configured?.profile),\n    },\n  };\n}\n\nexport function parseSelectionChanges(value: unknown): RepositorySelectionChanges | undefined {\n  if (!isRecord(value)) return undefined;\n  const keys = Object.keys(value);\n  if (keys.length === 0 || keys.some((key) => !Object.hasOwn(SELECTION_KEYS, key))) return undefined;\n  const changes: RepositorySelectionChanges = {};\n  if (Object.hasOwn(value, 'preset')) {\n    if (value.preset !== null && (typeof value.preset !== 'string' || value.preset.trim() === '')) return undefined;\n    changes.preset = value.preset === null ? null : value.preset.trim();\n  }\n  if (Object.hasOwn(value, 'domains')) {\n    if (\n      value.domains !== null &&\n      (!Array.isArray(value.domains) || value.domains.some((name) => typeof name !== 'string' || name.trim() === ''))\n    ) {\n      return undefined;\n    }\n    changes.domains =\n      value.domains === null ? null : [...new Set((value.domains as string[]).map((name) => name.trim()))];\n  }\n  if (Object.hasOwn(value, 'profile')) {\n    if (value.profile !== null && (typeof value.profile !== 'string' || value.profile.trim() === '')) return undefined;\n    changes.profile = value.profile === null ? null : value.profile.trim();\n  }\n  return changes;\n}\n\nexport function parseSelectionWrite(value: unknown): RepositorySelectionWriteRequest | undefined {\n  if (!isRecord(value) || typeof value.repositoryId !== 'string' || typeof value.expectedHash !== 'string')\n    return undefined;\n  const changes = parseSelectionChanges(value.changes);\n  return changes === undefined\n    ? undefined\n    : { repositoryId: value.repositoryId, expectedHash: value.expectedHash, changes };\n}\n\nexport function validateSelectionChanges(\n  view: RepositorySettingsView,\n  changes: RepositorySelectionChanges,\n): string | undefined {\n  if (changes.preset !== undefined && changes.preset !== null) {\n    if (!view.catalogs.presets.some((mode) => mode.name === changes.preset)) {\n      return `Unknown preset '${changes.preset}'.`;\n    }\n  }\n  if (changes.domains !== undefined && changes.domains !== null) {\n    const known = new Set(view.catalogs.domains.map((domain) => domain.name));\n    const unknown = changes.domains.find((domain) => !known.has(domain));\n    if (unknown !== undefined) return `Unknown domain '${unknown}'.`;\n  }\n  if (changes.profile !== undefined && changes.profile !== null) {\n    if (!view.catalogs.profiles.some((profile) => profile.name === changes.profile)) {\n      return `Unknown profile '${changes.profile}'.`;\n    }\n  }\n  return undefined;\n}\n\nexport function selectionEdits(changes: RepositorySelectionChanges) {\n  return (Object.entries(changes) as Array<[SelectionKey, string | readonly string[] | null]>).map(([key, value]) => ({\n    keyPath: SELECTION_KEYS[key],\n    ...(value === null ? {} : { value }),\n  }));\n}\n\nexport async function configView(\n  fs: FileSystem,\n  context: PoApiContext,\n  keys: readonly string[],\n  io: IoContext,\n): Promise<SettingsConfigView> {\n  const root = context.scope === 'workspace' ? context.workspaceRoot : undefined;\n  const layers = await readPoConfigLayers(fs, root, io, readOptions(context.homeDirectory, context.environment ?? {}));\n  const values: Record<string, SettingsValueView> = {};\n  for (const key of keys) {\n    const keyPath = key.split(KEY_SEPARATOR);\n    const value = displayValue(layers.valueAt(keyPath));\n    values[key] = {\n      ...(value === undefined ? {} : { value }),\n      origin: layers.originOf(keyPath),\n      scope: configScopeOf(keyPath),\n    };\n  }\n  return {\n    repoRoot: root ?? '',\n    values,\n    hashes: {\n      host: layers.globalFile.hash,\n      repository: layers.repositoryFile.hash,\n    },\n  };\n}\n","import type { PoApi } from '@agimon-ai/po-core/packageApi';\nimport { BACKGROUND_CONTEXT, type FileSystem } from '@agimon-ai/po-core/platform';\n\nimport { KEY_QUERY_PARAM, KEY_SEPARATOR } from '../../constants/settings';\nimport { routes } from '../../types/apiRoutes';\nimport type {\n  PresetOperation,\n  PresetCreateRequest,\n  PresetLayerRequest,\n  PresetRenameRequest,\n  PresetWriteRequest,\n  SettingsRepository,\n} from '../../types/settings';\nimport { repositoryPoConfigPath } from '../config';\nimport { configScopeOf } from '../configPolicy';\nimport { writePoConfigValuesAsync } from '../configWriter';\nimport { DEFAULT_IMAGE_MAX_DIMENSION, MIN_IMAGE_MAX_DIMENSION } from '../imageSettings';\nimport { readPiImageSettings, savePiImageSettingsAsync } from '../piConfig';\nimport { readPresetsView, withSettingsWrite, writePreset } from '../presets';\nimport {\n  configView,\n  describe,\n  isRecord,\n  parseSelectionWrite,\n  parseWrite,\n  pathFor,\n  repositorySettingsView,\n  selectionEdits,\n  validateSelectionChanges,\n} from '../settings';\nimport { repositorySettingsViewToWire, settingsConfigViewToWire } from '../settingsWire';\n\n/** One declared route, as much of it as a comparison needs. */\ntype RouteSpec = { readonly method: string; readonly path: string };\n\n/**\n * Config handlers are bound to their mount. Request paths cannot choose a different repository.\n * Reads, writes and image settings all go through the host's FileSystem.\n */\nexport const createSettingsApi = (fs: FileSystem): PoApi => ({\n  basePath: 'settings',\n  start(context) {\n    if (context.scope === 'session') throw new Error('Configuration settings require a host or workspace mount.');\n    const { homeDirectory } = context;\n    const environment = context.environment ?? {};\n    const repository = (): SettingsRepository | undefined =>\n      context.scope === 'workspace' && context.workspaceId && context.workspaceRoot\n        ? {\n            id: context.workspaceId,\n            name: context.workspaceRoot.split('/').at(-1) ?? context.workspaceId,\n            path: context.workspaceRoot,\n            active: context.repositories?.().find((entry) => entry.id === context.workspaceId)?.active ?? false,\n          }\n        : undefined;\n    const io = BACKGROUND_CONTEXT;\n    const imageView = async () => ({\n      ...(await readPiImageSettings(fs, io, homeDirectory)),\n      minDimension: MIN_IMAGE_MAX_DIMENSION,\n      maxAllowedDimension: DEFAULT_IMAGE_MAX_DIMENSION,\n    });\n    let closed = false;\n    const dispatch = async (request: Request): Promise<Response> => {\n      if (closed) return Response.json({ error: 'Configuration mount is closed.' }, { status: 503 });\n      const url = new URL(request.url);\n      /**\n       * Whether this request addresses one declared route.\n       *\n       * The table owns both halves of the comparison, so the path this mount\n       * answers and the path the client asks for cannot drift apart: there is\n       * one spelling of each, in `src/types/apiRoutes`.\n       */\n      const addresses = (route: RouteSpec): boolean => url.pathname === route.path && request.method === route.method;\n      const currentRepository = repository();\n      if (addresses(routes.config))\n        return Response.json(\n          settingsConfigViewToWire(await configView(fs, context, url.searchParams.getAll(KEY_QUERY_PARAM), io)),\n        );\n      if (addresses(routes.repositories)) return Response.json({ repositories: context.repositories?.() ?? [] });\n      if (addresses(routes.repository)) {\n        return currentRepository\n          ? Response.json(\n              repositorySettingsViewToWire(\n                await repositorySettingsView(fs, currentRepository, homeDirectory, environment, io),\n              ),\n            )\n          : Response.json({ error: 'Choose a workspace.' }, { status: 404 });\n      }\n      // One path, two methods, so the branch is on the path the pair share.\n      if (url.pathname === routes.images.path && context.scope === 'host') {\n        if (request.method === routes.images.method) return Response.json(await imageView());\n        if (request.method === routes.saveImages.method) {\n          const body: unknown = await request.json();\n          if (\n            !isRecord(body) ||\n            (body.autoResize !== undefined && typeof body.autoResize !== 'boolean') ||\n            (body.maxDimension !== undefined &&\n              (typeof body.maxDimension !== 'number' || !Number.isFinite(body.maxDimension)))\n          )\n            return Response.json({ error: 'Invalid image settings.' }, { status: 400 });\n          await savePiImageSettingsAsync(\n            fs,\n            {\n              ...(typeof body.autoResize === 'boolean' ? { autoResize: body.autoResize } : {}),\n              ...(typeof body.maxDimension === 'number' ? { maxDimension: body.maxDimension } : {}),\n            },\n            io,\n            homeDirectory,\n          );\n          context.configurationChanged?.();\n          return Response.json(await imageView());\n        }\n      }\n      const presetOperations: readonly [RouteSpec, PresetOperation][] = [\n        [routes.savePresets, 'default'],\n        [routes.createPreset, 'create'],\n        [routes.renamePreset, 'rename'],\n        [routes.deletePreset, 'delete'],\n        [routes.addPresetLayer, 'add-layer'],\n        [routes.removePresetLayer, 'remove-layer'],\n      ];\n      const presetOperation = presetOperations.find(([route]) => addresses(route))?.[1];\n      if (addresses(routes.presets) || presetOperation) {\n        if (!homeDirectory) return Response.json({ error: 'Po has no home directory here.' }, { status: 503 });\n        const root = currentRepository?.path;\n        if (addresses(routes.presets))\n          return Response.json(await readPresetsView(fs, homeDirectory, environment, root));\n        const body: unknown = await request.json();\n        if (!isRecord(body) || typeof body.expectedHash !== 'string')\n          return Response.json({ error: 'A preset write needs the file hash it read.' }, { status: 400 });\n        const scope = currentRepository ? `workspace:${currentRepository.id}` : 'host';\n        if ((body.scope ?? (presetOperation === 'default' ? scope : undefined)) !== scope)\n          return Response.json({ error: 'The write targets a different mount.' }, { status: 403 });\n        if (presetOperation === 'add-layer' && Object.hasOwn(body, 'definition'))\n          return Response.json({ error: 'Layer definitions are server-owned.' }, { status: 400 });\n        const name = presetOperation === 'default' ? body.defaultPreset : body.name;\n        const defaultAdd = presetOperation === 'add-layer' && (name === undefined || name === '');\n        if (!defaultAdd && (typeof name !== 'string' || !name.trim()))\n          return Response.json({ error: 'Choose a preset.' }, { status: 400 });\n        if (\n          presetOperation === 'create' &&\n          ((body.description !== undefined && typeof body.description !== 'string') ||\n            (body.layers !== undefined &&\n              (!Array.isArray(body.layers) || body.layers.some((layer) => typeof layer !== 'string' || !layer.trim()))))\n        )\n          return Response.json({ error: 'A preset needs a text description and a layer list.' }, { status: 400 });\n        if (presetOperation === 'rename' && (typeof body.newName !== 'string' || !body.newName.trim()))\n          return Response.json({ error: 'Choose a new preset name.' }, { status: 400 });\n        if (\n          (presetOperation === 'add-layer' || presetOperation === 'remove-layer') &&\n          (typeof body.layer !== 'string' || !body.layer.trim())\n        )\n          return Response.json({ error: 'Choose a layer reference.' }, { status: 400 });\n        const input = {\n          ...body,\n          scope,\n          name: typeof name === 'string' ? name.trim() : '',\n          ...(typeof body.layer === 'string' ? { layer: body.layer.trim() } : {}),\n          ...(typeof body.newName === 'string' ? { newName: body.newName.trim() } : {}),\n          // The Plugins page asks only for a name; the presets file needs every preset described.\n          ...(presetOperation === 'create' && !(typeof body.description === 'string' && body.description.trim())\n            ? { description: 'Your own group of plugins.' }\n            : {}),\n        } as PresetWriteRequest | PresetCreateRequest | PresetRenameRequest | PresetLayerRequest;\n        const result = await writePreset(\n          fs,\n          homeDirectory,\n          environment,\n          presetOperation!,\n          input,\n          root,\n          context.repositories?.() ?? [],\n        );\n        if ('error' in result)\n          return result.conflict\n            ? Response.json({ error: result.error, hash: result.conflict.hash }, { status: 409 })\n            : Response.json(result, { status: 422 });\n        context.configurationChanged?.();\n        return Response.json(result);\n      }\n      if (addresses(routes.selection)) {\n        const body = parseSelectionWrite(await request.json());\n        if (!body)\n          return Response.json({ error: 'A selection write needs typed changes and a file hash.' }, { status: 400 });\n        if (!currentRepository || body.repositoryId !== currentRepository.id)\n          return Response.json({ error: 'Workspace not found in this mount.' }, { status: 404 });\n        const before = await repositorySettingsView(fs, currentRepository, homeDirectory, environment, io);\n        if (before.hash !== body.expectedHash)\n          return Response.json(\n            { error: 'The repository config changed since it was read.', hash: before.hash },\n            { status: 409 },\n          );\n        const invalid = validateSelectionChanges(before, body.changes);\n        if (invalid) return Response.json({ error: invalid }, { status: 422 });\n        await writePoConfigValuesAsync(\n          fs,\n          repositoryPoConfigPath(currentRepository.path),\n          selectionEdits(body.changes),\n          io,\n          { scope: 'repository' },\n        );\n        context.configurationChanged?.();\n        return Response.json(\n          repositorySettingsViewToWire(\n            await repositorySettingsView(fs, currentRepository, homeDirectory, environment, io),\n          ),\n        );\n      }\n      if (addresses(routes.value)) {\n        const input: unknown = await request.json();\n        if (typeof input === 'object' && input !== null && 'scope' in input && input.scope === 'global')\n          return Response.json(\n            { error: \"The 'global' scope was renamed to 'host'. Update this client.\" },\n            { status: 400 },\n          );\n        const body = parseWrite(input);\n        if (!body)\n          return Response.json({ error: 'A save requires a scope, key, value and file hash.' }, { status: 400 });\n        const scope = context.scope === 'host' ? 'host' : 'repository';\n        if (body.scope !== scope || (scope === 'repository' && body.repoRoot !== currentRepository?.path))\n          return Response.json({ error: 'The write targets a different mount.' }, { status: 403 });\n        if (\n          body.edits.some((edit) => {\n            const allowed = configScopeOf(edit.keyPath);\n            return allowed !== 'both' && allowed !== scope;\n          })\n        )\n          return Response.json({ error: 'This key cannot be set at this scope.' }, { status: 409 });\n        const before = await configView(fs, context, [], io);\n        if (before.hashes[scope] !== body.expectedHash)\n          return Response.json(\n            { error: 'The config changed since it was read.', hash: before.hashes[scope] },\n            { status: 409 },\n          );\n        const target = pathFor(scope, currentRepository?.path ?? '', homeDirectory, environment);\n        await writePoConfigValuesAsync(\n          fs,\n          target,\n          body.edits.map(({ keyPath, value }) => ({ keyPath, ...(value === null ? {} : { value }) })),\n          io,\n          { scope },\n        );\n        context.configurationChanged?.();\n        return Response.json(\n          settingsConfigViewToWire(\n            await configView(\n              fs,\n              context,\n              body.edits.map((edit) => edit.keyPath.join(KEY_SEPARATOR)),\n              io,\n            ),\n          ),\n        );\n      }\n      return Response.json({ error: 'Configuration route not found.' }, { status: 404 });\n    };\n    const guarded = async (request: Request): Promise<Response> => {\n      try {\n        return await dispatch(request);\n      } catch (error) {\n        return Response.json({ error: describe(error) }, { status: error instanceof SyntaxError ? 400 : 422 });\n      }\n    };\n    return {\n      fetch(request) {\n        if (request.method === 'GET' || request.method === 'HEAD') return guarded(request);\n        return withSettingsWrite(() => guarded(request));\n      },\n      close() {\n        closed = true;\n      },\n    };\n  },\n});\n"],"mappings":";;;;;;;;;;;;AAKA,MAAa,iBAAiB;CAC5B,QAAQ,CAAC,aAAa,QAAQ;CAC9B,SAAS,CAAC,aAAa,SAAS;CAChC,SAAS,CAAC,aAAa,SAAS;AAClC;;;;;;;;;;;;;;;;ACeA,MAAa,SAAS,gBAAgB;;CAEpC,QAAQ;EACN,QAAQ;EACR,MAAM;;EAEN,OAAO,CAAA,KAAgB;EACvB,UAAU,YAAgC;CAC5C;CACA,OAAO;EACL,QAAQ;EACR,MAAM;EACN,UAAU,YAAgC;CAC5C;CACA,cAAc;EACZ,QAAQ;EACR,MAAM;EACN,UAAU,YAA6D;CACzE;;CAEA,YAAY;EACV,QAAQ;EACR,MAAM;EACN,UAAU,YAAoC;CAChD;CACA,WAAW;EACT,QAAQ;EACR,MAAM;EACN,UAAU,YAAoC;CAChD;;CAEA,QAAQ;EACN,QAAQ;EACR,MAAM;EAC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