{"version":3,"file":"catalogEntries.mjs","names":[],"sources":["../../../src/web/lib/catalogEntries.ts"],"sourcesContent":["import { t } from '@agimon-ai/po-core/web';\n\nimport type {\n  CatalogLayer,\n  ExternalPluginsView,\n  ExternalServerRow,\n  ExternalServerStatus,\n  InstallOperation,\n  McpCatalogWire,\n  PluginEntry,\n  PluginIconKey,\n  PluginScope,\n  PluginSetup,\n  PresetSummary,\n} from '../../types/plugins';\nimport type { SettingsPresetsView } from '../../types/settings';\n\nconst ICONS: ReadonlySet<string> = new Set<PluginIconKey>([\n  'image',\n  'calendar',\n  'users',\n  'globe',\n  'search',\n  'branch',\n  'palette',\n  'task',\n  'message',\n  'puzzle',\n  'smartphone',\n]);\nconst SETTLED: ReadonlySet<InstallOperation['state']> = new Set(['succeeded', 'failed', 'cancelled']);\n/** The download is done; what remains is joining the preset and loading the plugin. */\nconst FINISHING: ReadonlySet<InstallOperation['state']> = new Set(['committing', 'reconciling']);\n\n/** The id a Codex or Claude Code plugin takes on the Plugins page, apart from curated layer ids. */\nexport const externalId = (name: string): string => `ext:${name}`;\n\nfunction installOf(layer: CatalogLayer, operation: InstallOperation | undefined): PluginEntry['install'] {\n  if (operation !== undefined && !SETTLED.has(operation.state)) return 'installing';\n  if (operation?.state === 'failed') return 'failed';\n  return layer.installed ? 'installed' : 'available';\n}\n\n/**\n * Everything the catalog draws, from what the host reported. A curated layer that can be neither\n * installed nor used is left out rather than offered with a button that cannot work.\n */\nexport function catalogEntries(input: {\n  catalog: readonly CatalogLayer[];\n  presets: SettingsPresetsView | undefined;\n  external: ExternalPluginsView | undefined;\n  setups: Readonly<Record<string, PluginSetup>>;\n  installs: Readonly<Record<string, InstallOperation>>;\n}): PluginEntry[] {\n  const po = input.catalog\n    .filter((layer) => layer.installed || layer.installable || input.installs[layer.id] !== undefined)\n    .map((layer): PluginEntry => {\n      const inPresets = (input.presets?.presets ?? [])\n        .filter((preset) => preset.layers.some((entry) => entry.name === layer.id))\n        .map((preset) => preset.name);\n      return {\n        id: layer.id,\n        name: layer.name,\n        description: layer.description,\n        category: layer.category,\n        icon: ICONS.has(layer.icon) ? (layer.icon as PluginIconKey) : 'puzzle',\n        // Only an embedded image is drawn; anything else (a remote URL, say) is ignored.\n        ...(layer.logo?.startsWith('data:image/') ? { logo: layer.logo } : {}),\n        publisher: layer.publisher,\n        source: 'po',\n        install: installOf(layer, input.installs[layer.id]),\n        ...(FINISHING.has(input.installs[layer.id]?.state ?? 'queued') ? { finishing: true } : {}),\n        setup: input.setups[layer.id] ?? 'none',\n        inPresets,\n        ...(inPresets.length > 0 && !inPresets.includes(input.presets?.defaultPreset ?? '')\n          ? { outsideDefault: true }\n          : {}),\n      };\n    });\n  const external = (input.external?.plugins ?? []).map((plugin): PluginEntry => ({\n    id: externalId(plugin.name),\n    name: plugin.name,\n    description: plugin.description ?? '',\n    category: t('webDashboard.plugins.external.category', 'Codex and Claude'),\n    icon: 'puzzle',\n    publisher: plugin.origin.marketplace ?? t('webDashboard.plugins.external.addedByYou', 'Added by you'),\n    source: 'external',\n    install: 'installed',\n    setup: 'none',\n    inPresets: [],\n    // po-domain's `enabled` is the on/off switch: on inside its domains, or everywhere when it has none.\n    domains: !plugin.enabled ? [] : plugin.domains.length > 0 ? plugin.domains : 'everywhere',\n  }));\n  return [...po, ...external];\n}\n\nexport function presetSummaries(view: SettingsPresetsView | undefined): PresetSummary[] {\n  return (view?.presets ?? []).map((preset) => ({\n    name: preset.name,\n    description: preset.description,\n    pluginIds: preset.layers.map((layer) => layer.name),\n    isDefault: preset.name === view?.defaultPreset,\n    ...(preset.overridesHost === true ? { overridesHost: true } : {}),\n  }));\n}\n\nconst SERVER_STATUS: Readonly<Record<string, ExternalServerStatus>> = {\n  connected: 'connected',\n  degraded: 'connected',\n  'needs-auth': 'needs-sign-in',\n  failed: 'failed',\n};\n\n/**\n * A plugin's MCP servers as one workspace's catalog sees them; it lists every domain's plugin servers,\n * loaded there or not. A missing key comes first: signing in cannot help a server whose config still\n * has a hole in it.\n *\n * ponytail: matched by name, because the catalog does not say which plugin a server came from. A\n * workspace `.mcp.json` server of the same name wins there and shows here; add the source id to the\n * catalog if that confuses people.\n */\nexport function externalServerRows(names: readonly string[], catalog: McpCatalogWire | undefined): ExternalServerRow[] {\n  return names.map((name) => {\n    const server = catalog?.servers.find((candidate) => candidate.name === name);\n    if (server === undefined) return { name, status: 'not-checked', missingKeys: [] };\n    const missingKeys = server.missingSecrets ?? [];\n    const status = missingKeys.length > 0 ? 'needs-key' : (SERVER_STATUS[server.state] ?? 'not-checked');\n    return {\n      name,\n      ...(server.management?.kind === undefined ? {} : { kind: server.management.kind }),\n      ...(server.management?.target === undefined ? {} : { target: server.management.target }),\n      status,\n      missingKeys,\n      // A server missing its key fails to start; the missing key is the reason worth showing.\n      ...(server.error === undefined || status !== 'failed' ? {} : { error: server.error }),\n    };\n  });\n}\n\n/** \"Joins Everyday (host default)\" or \"Joins Writing (this workspace)\". */\nexport function destinationOf(view: SettingsPresetsView | undefined, scope: PluginScope): string {\n  const preset = view?.defaultPreset ?? t('webDashboard.plugins.destination.defaultPreset', 'your default preset');\n  // A workspace that inherits the host's default changes it at its source, so the line says so.\n  const onHost = scope.kind === 'host' || (view?.defaultHash !== undefined && view.defaultHash !== view.hash);\n  return onHost\n    ? t('webDashboard.plugins.destination.host', 'Joins {preset} (host default)', { preset })\n    : t('webDashboard.plugins.destination.workspace', 'Joins {preset} (this workspace)', { preset });\n}\n\n/** Status reads in a row that may fail before a client stops waiting on an install: the host restarted or is gone. */\nexport const INSTALL_LOST_AFTER = 8;\n\n/** Counts one failed status read of install `id`. True once the install is lost; its count then starts over. */\nexport function installReadLost(missed: Map<string, number>, id: string): boolean {\n  const count = (missed.get(id) ?? 0) + 1;\n  if (count < INSTALL_LOST_AFTER) {\n    missed.set(id, count);\n    return false;\n  }\n  missed.delete(id);\n  return true;\n}\n\n/** The free text search and category chips, applied the same way the stories do. */\nexport function filterEntries(\n  entries: readonly PluginEntry[],\n  query: string,\n  category: string,\n  all: string,\n  external: string,\n): PluginEntry[] {\n  const needle = query.trim().toLowerCase();\n  return entries.filter(\n    (entry) =>\n      (category === all || (category === external ? entry.source !== 'po' : entry.category === category)) &&\n      (needle === '' || `${entry.name} ${entry.description}`.toLowerCase().includes(needle)),\n  );\n}\n"],"mappings":";;AAiBA,MAAM,wBAA6B,IAAI,IAAmB;CACxD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,0BAAkD,IAAI,IAAI;CAAC;CAAa;CAAU;AAAW,CAAC;;AAEpG,MAAM,4BAAoD,IAAI,IAAI,CAAC,cAAc,aAAa,CAAC;;AAG/F,MAAa,cAAc,SAAyB,OAAO;AAE3D,SAAS,UAAU,OAAqB,WAAiE;CACvG,IAAI,cAAc,KAAA,KAAa,CAAC,QAAQ,IAAI,UAAU,KAAK,GAAG,OAAO;CACrE,IAAI,WAAW,UAAU,UAAU,OAAO;CAC1C,OAAO,MAAM,YAAY,cAAc;AACzC;;;;;AAMA,SAAgB,eAAe,OAMb;CAChB,MAAM,KAAK,MAAM,QACd,QAAQ,UAAU,MAAM,aAAa,MAAM,eAAe,MAAM,SAAS,MAAM,QAAQ,KAAA,CAAS,CAAC,CACjG,KAAK,UAAuB;EAC3B,MAAM,aAAa,MAAM,SAAS,WAAW,CAAC,EAAA,CAC3C,QAAQ,WAAW,OAAO,OAAO,MAAM,UAAU,MAAM,SAAS,MAAM,EAAE,CAAC,CAAC,CAC1E,KAAK,WAAW,OAAO,IAAI;EAC9B,OAAO;GACL,IAAI,MAAM;GACV,MAAM,MAAM;GACZ,aAAa,MAAM;GACnB,UAAU,MAAM;GAChB,MAAM,MAAM,IAAI,MAAM,IAAI,IAAK,MAAM,OAAyB;GAE9D,GAAI,MAAM,MAAM,WAAW,aAAa,IAAI,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;GACpE,WAAW,MAAM;GACjB,QAAQ;GACR,SAAS,UAAU,OAAO,MAAM,SAAS,MAAM,GA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