{"version":3,"file":"settings.cjs","names":[],"sources":["../../src/types/settings.ts"],"sourcesContent":["/**\n * The settings REST surface, as both halves see it.\n *\n * Settings are host routes rather than a package API because the page is not\n * scoped to a session: it names a repository instead, and a plugin's browser\n * code may not reach the hub's own client helpers. The host reads and writes\n * the config file on everyone's behalf and hands each contributed field the\n * result through props.\n */\nimport type { RepositorySettingsRepository } from '@agimon-ai/po-core/web';\n\nexport const SETTINGS_CONFIG_API_ROUTE = '/api/settings';\nexport const SETTINGS_VALUE_API_ROUTE = '/api/settings/value';\nexport const SETTINGS_REPOSITORIES_API_ROUTE = '/api/settings/repositories';\nexport const SETTINGS_MODELS_API_ROUTE = '/api/plugins/po/models';\nexport const SETTINGS_REPOSITORY_API_ROUTE = '/api/settings/repository';\nexport const SETTINGS_REPOSITORY_SELECTION_API_ROUTE = '/api/settings/repository/selection';\nexport const SETTINGS_IMAGES_API_ROUTE = '/api/settings/images';\nexport const SETTINGS_PRESETS_API_ROUTE = '/api/settings/presets';\n\n/**\n * The image limits, which live in Pi's settings.json rather than the Po\n * config, so they have their own route instead of a key path: Pi's own toggle\n * writes that file, and a machine should not end up with two answers to how\n * large an image reaches a model.\n */\nexport interface SettingsImagesView {\n  /** Off leaves every image at the size it arrived. */\n  autoResize: boolean;\n  /** Longest edge an image keeps once resizing is on. */\n  maxDimension: number;\n  /** The range the hub accepts; a value outside it is clamped rather than refused. */\n  minDimension: number;\n  maxAllowedDimension: number;\n}\n\nexport interface SettingsImagesWriteRequest {\n  autoResize?: boolean;\n  maxDimension?: number;\n}\n\n/** One layer a preset turns on, with the Po plugins (packages) it bundles. */\nexport interface SettingsPresetLayer {\n  name: string;\n  packages: string[];\n}\n\n/** One effective preset, with its layers in load order. */\nexport interface SettingsPreset {\n  name: string;\n  description: string;\n  layers: SettingsPresetLayer[];\n  /** True when this workspace definition replaces a host preset of the same name. */\n  overridesHost?: boolean;\n  /** True when a workspace reads this preset from the host file because it has none of its own. */\n  inherited?: boolean;\n}\n\n/** Settings > Presets: your presets, the default new sessions start with, and what every preset includes. */\nexport interface SettingsPresetsView {\n  defaultPreset: string;\n  presets: SettingsPreset[];\n  /** `default.packages`: loaded before any preset's layers. */\n  alwaysIncluded: string[];\n  /** sha256 of the mount's presets file, empty when absent. */\n  hash: string;\n  /** The host token, used when adding to an inherited host default. */\n  hostHash?: string;\n  /** The token an add to the default preset (`name: ''`) checks: the host file's when that default is inherited. */\n  defaultHash?: string;\n  file?: string;\n  writtenFile?: string;\n}\n\nexport interface SettingsPresetsWriteRequest {\n  scope?: PresetScope;\n  defaultPreset: string;\n  expectedHash: string;\n}\n/** Preset writes use the admitted workspace mount, never a caller-supplied path. */\nexport type PresetScope = 'host' | `workspace:${string}`;\n\nexport interface PresetWriteRequest {\n  scope: PresetScope;\n  expectedHash: string;\n  name: string;\n}\n\nexport interface PresetCreateRequest extends PresetWriteRequest {\n  description: string;\n  layers?: string[];\n}\n\nexport interface PresetRenameRequest extends PresetWriteRequest {\n  newName: string;\n}\n\n/** A caller-supplied curated definition. Existing layers are never modified. */\nexport interface PresetLayerDefinition {\n  packages?: Array<string | { name: string; optional?: boolean; config?: Record<string, unknown> }>;\n  extensions?: string[];\n  hookGroups?: string[];\n}\n\nexport interface PresetLayerRequest extends PresetWriteRequest {\n  /** Set name to an empty string to add to the scope's default preset. */\n  layer: string;\n  definition?: PresetLayerDefinition;\n}\n\nexport type PresetOperation = 'create' | 'rename' | 'delete' | 'default' | 'add-layer' | 'remove-layer';\n\nexport interface PresetReference {\n  file: string;\n  key: string;\n}\n\n/**\n * Which settings tier a read or write is about: `host` is this machine's config file and\n * `repository` the workspace's. `global` is reserved for the member tier: it has its own issuer\n * endpoint and never travels on the host settings API.\n */\nexport type SettingsScope = 'host' | 'repository' | 'global';\n\n/** The two config files the host settings API reads and writes. */\nexport type SettingsFileScope = Exclude<SettingsScope, 'global'>;\n\n/** Where the effective value came from, or that no file set it. */\nexport type SettingsOrigin = 'host' | 'repository' | 'default';\n\n/** Which scopes a key may be written at, as the merge policy decides. */\nexport type SettingsKeyScope = 'host' | 'repository' | 'both';\n\n/** Host settings wire values. */\nexport type SettingsWireScope = 'host' | 'repository';\nexport type SettingsWireOrigin = 'host' | 'repository' | 'default';\nexport type SettingsWireKeyScope = 'host' | 'repository' | 'both';\n\n/** One repository the picker offers. */\nexport type SettingsRepository = RepositorySettingsRepository;\n\n/** One model the machine can actually use, for a field declaring optionsFrom: 'models'. */\nexport interface SettingsModel {\n  /** `provider/model-id`, which is what the config file holds. */\n  value: string;\n  label: string;\n  group: string;\n}\n\n/** One key's current state, keyed by its dotted path. */\nexport interface SettingsValueView {\n  /** The effective value, stringified for display; absent when nothing set it. */\n  value?: string;\n  origin: SettingsOrigin;\n  /** Which scopes may hold this key. A field outside the chosen scope is read-only. */\n  scope: SettingsKeyScope;\n}\n\n/** What the read route answers with. */\nexport interface SettingsConfigView {\n  /** Empty when the page has no repository in view; the host half still applies. */\n  repoRoot: string;\n  /** Keyed by dotted key path, for every key the page asked about. */\n  values: Record<string, SettingsValueView>;\n  /** Per-scope file identity, so a write can prove which bytes it read. */\n  hashes: Record<SettingsFileScope, string>;\n}\n\n/** One key's state as the host settings API sends it. */\nexport interface SettingsWireValueView {\n  value?: string;\n  origin: SettingsWireOrigin;\n  scope: SettingsWireKeyScope;\n}\n\n/** Host settings wire values. */\nexport interface SettingsWireConfigView {\n  repoRoot: string;\n  values: Record<string, SettingsWireValueView>;\n  /** Host settings wire values. */\n  hashes: { host: string; repository: string };\n}\n\n/** What the write route takes. `value: null` clears the key at that scope. */\nexport interface SettingsWriteRequest {\n  /** Required for a repository write; ignored, and may be empty, for a host one. */\n  repoRoot: string;\n  scope: SettingsFileScope;\n  keyPath: readonly string[];\n  value: string | number | null;\n  /** The hash of the target file when the page read it. */\n  expectedHash: string;\n}\n\n/** One atomic save, validated as a whole before replacing the configuration file. */\nexport interface SettingsBatchWriteRequest {\n  repoRoot: string;\n  scope: SettingsFileScope;\n  edits: readonly Pick<SettingsWriteRequest, 'keyPath' | 'value'>[];\n  expectedHash: string;\n}\n\n/** A named option from one effective repository catalog. */\nexport interface RepositoryCatalogOption {\n  name: string;\n  description?: string;\n  /** Present for a domain alias, naming the entries it expands to. */\n  expandsTo?: readonly string[];\n  /** Present for a preset, naming its ordered layers. */\n  layers?: readonly string[];\n}\n\n/** One selection axis, keeping an inherited effective value apart from this repository's override. */\nexport interface RepositorySelectionValue<T> {\n  effective?: T;\n  repository?: T;\n  origin: SettingsOrigin;\n}\n\n/** The repository control plane's safe, non-secret catalog and selection view. */\nexport interface RepositorySettingsView {\n  repository: SettingsRepository;\n  hash: string;\n  catalogs: {\n    presets: readonly RepositoryCatalogOption[];\n    domains: readonly RepositoryCatalogOption[];\n    profiles: readonly RepositoryCatalogOption[];\n  };\n  selection: {\n    preset: RepositorySelectionValue<string>;\n    domains: RepositorySelectionValue<readonly string[]>;\n    profile: RepositorySelectionValue<string>;\n  };\n}\n\nexport interface RepositorySelectionChanges {\n  preset?: string | null;\n  domains?: readonly string[] | null;\n  profile?: string | null;\n}\n\n/** An optimistic, atomic write into one repository's selection defaults. */\nexport interface RepositorySelectionWriteRequest {\n  repositoryId: string;\n  expectedHash: string;\n  changes: RepositorySelectionChanges;\n}\n\n/** What a route reports when it refuses; the page shows `error` verbatim. */\nexport interface SettingsErrorView {\n  error: string;\n  /** Present when a preset cannot be renamed or deleted while referenced. */\n  references?: PresetReference[];\n  /** On a stale write, the hash the target file actually holds now. */\n  hash?: string;\n}\n"],"mappings":";AAWA,MAAa,4BAA4B;AACzC,MAAa,2BAA2B;AACxC,MAAa,kCAAkC;AAC/C,MAAa,4BAA4B;AACzC,MAAa,gCAAgC;AAC7C,MAAa,0CAA0C;AACvD,MAAa,4BAA4B;AACzC,MAAa,6BAA6B"}